2 * Toshiba TC6393XB SoC support
4 * Copyright(c) 2005-2006 Chris Humbert
5 * Copyright(c) 2005 Dirk Opfer
6 * Copyright(c) 2005 Ian Molton <spyro@f2s.com>
7 * Copyright(c) 2007 Dmitry Baryshkov
9 * Based on code written by Sharp/Lineo for 2.4 kernels
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
17 #include <linux/kernel.h>
18 #include <linux/module.h>
20 #include <linux/irq.h>
21 #include <linux/platform_device.h>
22 #include <linux/clk.h>
23 #include <linux/err.h>
24 #include <linux/mfd/core.h>
25 #include <linux/mfd/tmio.h>
26 #include <linux/mfd/tc6393xb.h>
27 #include <linux/gpio.h>
29 #define SCR_REVID 0x08 /* b Revision ID */
30 #define SCR_ISR 0x50 /* b Interrupt Status */
31 #define SCR_IMR 0x52 /* b Interrupt Mask */
32 #define SCR_IRR 0x54 /* b Interrupt Routing */
33 #define SCR_GPER 0x60 /* w GP Enable */
34 #define SCR_GPI_SR(i) (0x64 + (i)) /* b3 GPI Status */
35 #define SCR_GPI_IMR(i) (0x68 + (i)) /* b3 GPI INT Mask */
36 #define SCR_GPI_EDER(i) (0x6c + (i)) /* b3 GPI Edge Detect Enable */
37 #define SCR_GPI_LIR(i) (0x70 + (i)) /* b3 GPI Level Invert */
38 #define SCR_GPO_DSR(i) (0x78 + (i)) /* b3 GPO Data Set */
39 #define SCR_GPO_DOECR(i) (0x7c + (i)) /* b3 GPO Data OE Control */
40 #define SCR_GP_IARCR(i) (0x80 + (i)) /* b3 GP Internal Active Register Control */
41 #define SCR_GP_IARLCR(i) (0x84 + (i)) /* b3 GP INTERNAL Active Register Level Control */
42 #define SCR_GPI_BCR(i) (0x88 + (i)) /* b3 GPI Buffer Control */
43 #define SCR_GPA_IARCR 0x8c /* w GPa Internal Active Register Control */
44 #define SCR_GPA_IARLCR 0x90 /* w GPa Internal Active Register Level Control */
45 #define SCR_GPA_BCR 0x94 /* w GPa Buffer Control */
46 #define SCR_CCR 0x98 /* w Clock Control */
47 #define SCR_PLL2CR 0x9a /* w PLL2 Control */
48 #define SCR_PLL1CR 0x9c /* l PLL1 Control */
49 #define SCR_DIARCR 0xa0 /* b Device Internal Active Register Control */
50 #define SCR_DBOCR 0xa1 /* b Device Buffer Off Control */
51 #define SCR_FER 0xe0 /* b Function Enable */
52 #define SCR_MCR 0xe4 /* w Mode Control */
53 #define SCR_CONFIG 0xfc /* b Configuration Control */
54 #define SCR_DEBUG 0xff /* b Debug */
56 #define SCR_CCR_CK32K BIT(0)
57 #define SCR_CCR_USBCK BIT(1)
58 #define SCR_CCR_UNK1 BIT(4)
59 #define SCR_CCR_MCLK_MASK (7 << 8)
60 #define SCR_CCR_MCLK_OFF (0 << 8)
61 #define SCR_CCR_MCLK_12 (1 << 8)
62 #define SCR_CCR_MCLK_24 (2 << 8)
63 #define SCR_CCR_MCLK_48 (3 << 8)
64 #define SCR_CCR_HCLK_MASK (3 << 12)
65 #define SCR_CCR_HCLK_24 (0 << 12)
66 #define SCR_CCR_HCLK_48 (1 << 12)
68 #define SCR_FER_USBEN BIT(0) /* USB host enable */
69 #define SCR_FER_LCDCVEN BIT(1) /* polysilicon TFT enable */
70 #define SCR_FER_SLCDEN BIT(2) /* SLCD enable */
72 #define SCR_MCR_RDY_MASK (3 << 0)
73 #define SCR_MCR_RDY_OPENDRAIN (0 << 0)
74 #define SCR_MCR_RDY_TRISTATE (1 << 0)
75 #define SCR_MCR_RDY_PUSHPULL (2 << 0)
76 #define SCR_MCR_RDY_UNK BIT(2)
77 #define SCR_MCR_RDY_EN BIT(3)
78 #define SCR_MCR_INT_MASK (3 << 4)
79 #define SCR_MCR_INT_OPENDRAIN (0 << 4)
80 #define SCR_MCR_INT_TRISTATE (1 << 4)
81 #define SCR_MCR_INT_PUSHPULL (2 << 4)
82 #define SCR_MCR_INT_UNK BIT(6)
83 #define SCR_MCR_INT_EN BIT(7)
84 /* bits 8 - 16 are unknown */
86 #define TC_GPIO_BIT(i) (1 << (i & 0x7))
88 /*--------------------------------------------------------------------------*/
93 struct gpio_chip gpio
;
95 struct clk
*clk
; /* 3,6 Mhz */
97 spinlock_t lock
; /* protects RMW cycles */
107 struct resource rscr
;
108 struct resource
*iomem
;
120 /*--------------------------------------------------------------------------*/
122 static int tc6393xb_nand_enable(struct platform_device
*nand
)
124 struct platform_device
*dev
= to_platform_device(nand
->dev
.parent
);
125 struct tc6393xb
*tc6393xb
= platform_get_drvdata(dev
);
128 spin_lock_irqsave(&tc6393xb
->lock
, flags
);
131 dev_dbg(&dev
->dev
, "SMD buffer on\n");
132 tmio_iowrite8(0xff, tc6393xb
->scr
+ SCR_GPI_BCR(1));
134 spin_unlock_irqrestore(&tc6393xb
->lock
, flags
);
139 static struct resource __devinitdata tc6393xb_nand_resources
[] = {
143 .flags
= IORESOURCE_MEM
,
148 .flags
= IORESOURCE_MEM
,
151 .start
= IRQ_TC6393_NAND
,
152 .end
= IRQ_TC6393_NAND
,
153 .flags
= IORESOURCE_IRQ
,
157 static struct resource __devinitdata tc6393xb_mmc_resources
[] = {
161 .flags
= IORESOURCE_MEM
,
166 .flags
= IORESOURCE_MEM
,
169 .start
= IRQ_TC6393_MMC
,
170 .end
= IRQ_TC6393_MMC
,
171 .flags
= IORESOURCE_IRQ
,
175 static const struct resource tc6393xb_ohci_resources
[] = {
179 .flags
= IORESOURCE_MEM
,
184 .flags
= IORESOURCE_MEM
,
189 .flags
= IORESOURCE_MEM
,
194 .flags
= IORESOURCE_MEM
,
197 .start
= IRQ_TC6393_OHCI
,
198 .end
= IRQ_TC6393_OHCI
,
199 .flags
= IORESOURCE_IRQ
,
203 static struct resource __devinitdata tc6393xb_fb_resources
[] = {
207 .flags
= IORESOURCE_MEM
,
212 .flags
= IORESOURCE_MEM
,
217 .flags
= IORESOURCE_MEM
,
220 .start
= IRQ_TC6393_FB
,
221 .end
= IRQ_TC6393_FB
,
222 .flags
= IORESOURCE_IRQ
,
226 static int tc6393xb_ohci_enable(struct platform_device
*dev
)
228 struct tc6393xb
*tc6393xb
= dev_get_drvdata(dev
->dev
.parent
);
233 spin_lock_irqsave(&tc6393xb
->lock
, flags
);
235 ccr
= tmio_ioread16(tc6393xb
->scr
+ SCR_CCR
);
236 ccr
|= SCR_CCR_USBCK
;
237 tmio_iowrite16(ccr
, tc6393xb
->scr
+ SCR_CCR
);
239 fer
= tmio_ioread8(tc6393xb
->scr
+ SCR_FER
);
240 fer
|= SCR_FER_USBEN
;
241 tmio_iowrite8(fer
, tc6393xb
->scr
+ SCR_FER
);
243 spin_unlock_irqrestore(&tc6393xb
->lock
, flags
);
248 static int tc6393xb_ohci_disable(struct platform_device
*dev
)
250 struct tc6393xb
*tc6393xb
= dev_get_drvdata(dev
->dev
.parent
);
255 spin_lock_irqsave(&tc6393xb
->lock
, flags
);
257 fer
= tmio_ioread8(tc6393xb
->scr
+ SCR_FER
);
258 fer
&= ~SCR_FER_USBEN
;
259 tmio_iowrite8(fer
, tc6393xb
->scr
+ SCR_FER
);
261 ccr
= tmio_ioread16(tc6393xb
->scr
+ SCR_CCR
);
262 ccr
&= ~SCR_CCR_USBCK
;
263 tmio_iowrite16(ccr
, tc6393xb
->scr
+ SCR_CCR
);
265 spin_unlock_irqrestore(&tc6393xb
->lock
, flags
);
270 static int tc6393xb_fb_enable(struct platform_device
*dev
)
272 struct tc6393xb
*tc6393xb
= dev_get_drvdata(dev
->dev
.parent
);
276 spin_lock_irqsave(&tc6393xb
->lock
, flags
);
278 ccr
= tmio_ioread16(tc6393xb
->scr
+ SCR_CCR
);
279 ccr
&= ~SCR_CCR_MCLK_MASK
;
280 ccr
|= SCR_CCR_MCLK_48
;
281 tmio_iowrite16(ccr
, tc6393xb
->scr
+ SCR_CCR
);
283 spin_unlock_irqrestore(&tc6393xb
->lock
, flags
);
288 static int tc6393xb_fb_disable(struct platform_device
*dev
)
290 struct tc6393xb
*tc6393xb
= dev_get_drvdata(dev
->dev
.parent
);
294 spin_lock_irqsave(&tc6393xb
->lock
, flags
);
296 ccr
= tmio_ioread16(tc6393xb
->scr
+ SCR_CCR
);
297 ccr
&= ~SCR_CCR_MCLK_MASK
;
298 ccr
|= SCR_CCR_MCLK_OFF
;
299 tmio_iowrite16(ccr
, tc6393xb
->scr
+ SCR_CCR
);
301 spin_unlock_irqrestore(&tc6393xb
->lock
, flags
);
306 int tc6393xb_lcd_set_power(struct platform_device
*fb
, bool on
)
308 struct platform_device
*dev
= to_platform_device(fb
->dev
.parent
);
309 struct tc6393xb
*tc6393xb
= platform_get_drvdata(dev
);
313 spin_lock_irqsave(&tc6393xb
->lock
, flags
);
315 fer
= ioread8(tc6393xb
->scr
+ SCR_FER
);
317 fer
|= SCR_FER_SLCDEN
;
319 fer
&= ~SCR_FER_SLCDEN
;
320 iowrite8(fer
, tc6393xb
->scr
+ SCR_FER
);
322 spin_unlock_irqrestore(&tc6393xb
->lock
, flags
);
326 EXPORT_SYMBOL(tc6393xb_lcd_set_power
);
328 int tc6393xb_lcd_mode(struct platform_device
*fb
,
329 const struct fb_videomode
*mode
) {
330 struct platform_device
*dev
= to_platform_device(fb
->dev
.parent
);
331 struct tc6393xb
*tc6393xb
= platform_get_drvdata(dev
);
334 spin_lock_irqsave(&tc6393xb
->lock
, flags
);
336 iowrite16(mode
->pixclock
, tc6393xb
->scr
+ SCR_PLL1CR
+ 0);
337 iowrite16(mode
->pixclock
>> 16, tc6393xb
->scr
+ SCR_PLL1CR
+ 2);
339 spin_unlock_irqrestore(&tc6393xb
->lock
, flags
);
343 EXPORT_SYMBOL(tc6393xb_lcd_mode
);
345 static struct mfd_cell __devinitdata tc6393xb_cells
[] = {
346 [TC6393XB_CELL_NAND
] = {
348 .enable
= tc6393xb_nand_enable
,
349 .num_resources
= ARRAY_SIZE(tc6393xb_nand_resources
),
350 .resources
= tc6393xb_nand_resources
,
352 [TC6393XB_CELL_MMC
] = {
354 .num_resources
= ARRAY_SIZE(tc6393xb_mmc_resources
),
355 .resources
= tc6393xb_mmc_resources
,
357 [TC6393XB_CELL_OHCI
] = {
359 .num_resources
= ARRAY_SIZE(tc6393xb_ohci_resources
),
360 .resources
= tc6393xb_ohci_resources
,
361 .enable
= tc6393xb_ohci_enable
,
362 .suspend
= tc6393xb_ohci_disable
,
363 .resume
= tc6393xb_ohci_enable
,
364 .disable
= tc6393xb_ohci_disable
,
366 [TC6393XB_CELL_FB
] = {
368 .num_resources
= ARRAY_SIZE(tc6393xb_fb_resources
),
369 .resources
= tc6393xb_fb_resources
,
370 .enable
= tc6393xb_fb_enable
,
371 .suspend
= tc6393xb_fb_disable
,
372 .resume
= tc6393xb_fb_enable
,
373 .disable
= tc6393xb_fb_disable
,
377 /*--------------------------------------------------------------------------*/
379 static int tc6393xb_gpio_get(struct gpio_chip
*chip
,
382 struct tc6393xb
*tc6393xb
= container_of(chip
, struct tc6393xb
, gpio
);
384 /* XXX: does dsr also represent inputs? */
385 return tmio_ioread8(tc6393xb
->scr
+ SCR_GPO_DSR(offset
/ 8))
386 & TC_GPIO_BIT(offset
);
389 static void __tc6393xb_gpio_set(struct gpio_chip
*chip
,
390 unsigned offset
, int value
)
392 struct tc6393xb
*tc6393xb
= container_of(chip
, struct tc6393xb
, gpio
);
395 dsr
= tmio_ioread8(tc6393xb
->scr
+ SCR_GPO_DSR(offset
/ 8));
397 dsr
|= TC_GPIO_BIT(offset
);
399 dsr
&= ~TC_GPIO_BIT(offset
);
401 tmio_iowrite8(dsr
, tc6393xb
->scr
+ SCR_GPO_DSR(offset
/ 8));
404 static void tc6393xb_gpio_set(struct gpio_chip
*chip
,
405 unsigned offset
, int value
)
407 struct tc6393xb
*tc6393xb
= container_of(chip
, struct tc6393xb
, gpio
);
410 spin_lock_irqsave(&tc6393xb
->lock
, flags
);
412 __tc6393xb_gpio_set(chip
, offset
, value
);
414 spin_unlock_irqrestore(&tc6393xb
->lock
, flags
);
417 static int tc6393xb_gpio_direction_input(struct gpio_chip
*chip
,
420 struct tc6393xb
*tc6393xb
= container_of(chip
, struct tc6393xb
, gpio
);
424 spin_lock_irqsave(&tc6393xb
->lock
, flags
);
426 doecr
= tmio_ioread8(tc6393xb
->scr
+ SCR_GPO_DOECR(offset
/ 8));
427 doecr
&= ~TC_GPIO_BIT(offset
);
428 tmio_iowrite8(doecr
, tc6393xb
->scr
+ SCR_GPO_DOECR(offset
/ 8));
430 spin_unlock_irqrestore(&tc6393xb
->lock
, flags
);
435 static int tc6393xb_gpio_direction_output(struct gpio_chip
*chip
,
436 unsigned offset
, int value
)
438 struct tc6393xb
*tc6393xb
= container_of(chip
, struct tc6393xb
, gpio
);
442 spin_lock_irqsave(&tc6393xb
->lock
, flags
);
444 __tc6393xb_gpio_set(chip
, offset
, value
);
446 doecr
= tmio_ioread8(tc6393xb
->scr
+ SCR_GPO_DOECR(offset
/ 8));
447 doecr
|= TC_GPIO_BIT(offset
);
448 tmio_iowrite8(doecr
, tc6393xb
->scr
+ SCR_GPO_DOECR(offset
/ 8));
450 spin_unlock_irqrestore(&tc6393xb
->lock
, flags
);
455 static int tc6393xb_register_gpio(struct tc6393xb
*tc6393xb
, int gpio_base
)
457 tc6393xb
->gpio
.label
= "tc6393xb";
458 tc6393xb
->gpio
.base
= gpio_base
;
459 tc6393xb
->gpio
.ngpio
= 16;
460 tc6393xb
->gpio
.set
= tc6393xb_gpio_set
;
461 tc6393xb
->gpio
.get
= tc6393xb_gpio_get
;
462 tc6393xb
->gpio
.direction_input
= tc6393xb_gpio_direction_input
;
463 tc6393xb
->gpio
.direction_output
= tc6393xb_gpio_direction_output
;
465 return gpiochip_add(&tc6393xb
->gpio
);
468 /*--------------------------------------------------------------------------*/
471 tc6393xb_irq(unsigned int irq
, struct irq_desc
*desc
)
473 struct tc6393xb
*tc6393xb
= get_irq_data(irq
);
475 unsigned int i
, irq_base
;
477 irq_base
= tc6393xb
->irq_base
;
479 while ((isr
= tmio_ioread8(tc6393xb
->scr
+ SCR_ISR
) &
480 ~tmio_ioread8(tc6393xb
->scr
+ SCR_IMR
)))
481 for (i
= 0; i
< TC6393XB_NR_IRQS
; i
++) {
483 generic_handle_irq(irq_base
+ i
);
487 static void tc6393xb_irq_ack(unsigned int irq
)
491 static void tc6393xb_irq_mask(unsigned int irq
)
493 struct tc6393xb
*tc6393xb
= get_irq_chip_data(irq
);
497 spin_lock_irqsave(&tc6393xb
->lock
, flags
);
498 imr
= tmio_ioread8(tc6393xb
->scr
+ SCR_IMR
);
499 imr
|= 1 << (irq
- tc6393xb
->irq_base
);
500 tmio_iowrite8(imr
, tc6393xb
->scr
+ SCR_IMR
);
501 spin_unlock_irqrestore(&tc6393xb
->lock
, flags
);
504 static void tc6393xb_irq_unmask(unsigned int irq
)
506 struct tc6393xb
*tc6393xb
= get_irq_chip_data(irq
);
510 spin_lock_irqsave(&tc6393xb
->lock
, flags
);
511 imr
= tmio_ioread8(tc6393xb
->scr
+ SCR_IMR
);
512 imr
&= ~(1 << (irq
- tc6393xb
->irq_base
));
513 tmio_iowrite8(imr
, tc6393xb
->scr
+ SCR_IMR
);
514 spin_unlock_irqrestore(&tc6393xb
->lock
, flags
);
517 static struct irq_chip tc6393xb_chip
= {
519 .ack
= tc6393xb_irq_ack
,
520 .mask
= tc6393xb_irq_mask
,
521 .unmask
= tc6393xb_irq_unmask
,
524 static void tc6393xb_attach_irq(struct platform_device
*dev
)
526 struct tc6393xb
*tc6393xb
= platform_get_drvdata(dev
);
527 unsigned int irq
, irq_base
;
529 irq_base
= tc6393xb
->irq_base
;
531 for (irq
= irq_base
; irq
< irq_base
+ TC6393XB_NR_IRQS
; irq
++) {
532 set_irq_chip(irq
, &tc6393xb_chip
);
533 set_irq_chip_data(irq
, tc6393xb
);
534 set_irq_handler(irq
, handle_edge_irq
);
535 set_irq_flags(irq
, IRQF_VALID
| IRQF_PROBE
);
538 set_irq_type(tc6393xb
->irq
, IRQ_TYPE_EDGE_FALLING
);
539 set_irq_data(tc6393xb
->irq
, tc6393xb
);
540 set_irq_chained_handler(tc6393xb
->irq
, tc6393xb_irq
);
543 static void tc6393xb_detach_irq(struct platform_device
*dev
)
545 struct tc6393xb
*tc6393xb
= platform_get_drvdata(dev
);
546 unsigned int irq
, irq_base
;
548 set_irq_chained_handler(tc6393xb
->irq
, NULL
);
549 set_irq_data(tc6393xb
->irq
, NULL
);
551 irq_base
= tc6393xb
->irq_base
;
553 for (irq
= irq_base
; irq
< irq_base
+ TC6393XB_NR_IRQS
; irq
++) {
554 set_irq_flags(irq
, 0);
555 set_irq_chip(irq
, NULL
);
556 set_irq_chip_data(irq
, NULL
);
560 /*--------------------------------------------------------------------------*/
562 static int __devinit
tc6393xb_probe(struct platform_device
*dev
)
564 struct tc6393xb_platform_data
*tcpd
= dev
->dev
.platform_data
;
565 struct tc6393xb
*tc6393xb
;
566 struct resource
*iomem
, *rscr
;
569 iomem
= platform_get_resource(dev
, IORESOURCE_MEM
, 0);
573 tc6393xb
= kzalloc(sizeof *tc6393xb
, GFP_KERNEL
);
579 spin_lock_init(&tc6393xb
->lock
);
581 platform_set_drvdata(dev
, tc6393xb
);
583 ret
= platform_get_irq(dev
, 0);
589 tc6393xb
->iomem
= iomem
;
590 tc6393xb
->irq_base
= tcpd
->irq_base
;
592 tc6393xb
->clk
= clk_get(&dev
->dev
, "CLK_CK3P6MI");
593 if (IS_ERR(tc6393xb
->clk
)) {
594 ret
= PTR_ERR(tc6393xb
->clk
);
598 rscr
= &tc6393xb
->rscr
;
599 rscr
->name
= "tc6393xb-core";
600 rscr
->start
= iomem
->start
;
601 rscr
->end
= iomem
->start
+ 0xff;
602 rscr
->flags
= IORESOURCE_MEM
;
604 ret
= request_resource(iomem
, rscr
);
606 goto err_request_scr
;
608 tc6393xb
->scr
= ioremap(rscr
->start
, rscr
->end
- rscr
->start
+ 1);
609 if (!tc6393xb
->scr
) {
614 ret
= clk_enable(tc6393xb
->clk
);
618 ret
= tcpd
->enable(dev
);
622 iowrite8(0, tc6393xb
->scr
+ SCR_FER
);
623 iowrite16(tcpd
->scr_pll2cr
, tc6393xb
->scr
+ SCR_PLL2CR
);
624 iowrite16(SCR_CCR_UNK1
| SCR_CCR_HCLK_48
,
625 tc6393xb
->scr
+ SCR_CCR
);
626 iowrite16(SCR_MCR_RDY_OPENDRAIN
| SCR_MCR_RDY_UNK
| SCR_MCR_RDY_EN
|
627 SCR_MCR_INT_OPENDRAIN
| SCR_MCR_INT_UNK
| SCR_MCR_INT_EN
|
628 BIT(15), tc6393xb
->scr
+ SCR_MCR
);
629 iowrite16(tcpd
->scr_gper
, tc6393xb
->scr
+ SCR_GPER
);
630 iowrite8(0, tc6393xb
->scr
+ SCR_IRR
);
631 iowrite8(0xbf, tc6393xb
->scr
+ SCR_IMR
);
633 printk(KERN_INFO
"Toshiba tc6393xb revision %d at 0x%08lx, irq %d\n",
634 tmio_ioread8(tc6393xb
->scr
+ SCR_REVID
),
635 (unsigned long) iomem
->start
, tc6393xb
->irq
);
637 tc6393xb
->gpio
.base
= -1;
639 if (tcpd
->gpio_base
>= 0) {
640 ret
= tc6393xb_register_gpio(tc6393xb
, tcpd
->gpio_base
);
645 tc6393xb_attach_irq(dev
);
648 ret
= tcpd
->setup(dev
);
653 tc6393xb_cells
[TC6393XB_CELL_NAND
].driver_data
= tcpd
->nand_data
;
654 tc6393xb_cells
[TC6393XB_CELL_NAND
].platform_data
=
655 &tc6393xb_cells
[TC6393XB_CELL_NAND
];
656 tc6393xb_cells
[TC6393XB_CELL_NAND
].data_size
=
657 sizeof(tc6393xb_cells
[TC6393XB_CELL_NAND
]);
659 tc6393xb_cells
[TC6393XB_CELL_MMC
].platform_data
=
660 &tc6393xb_cells
[TC6393XB_CELL_MMC
];
661 tc6393xb_cells
[TC6393XB_CELL_MMC
].data_size
=
662 sizeof(tc6393xb_cells
[TC6393XB_CELL_MMC
]);
664 tc6393xb_cells
[TC6393XB_CELL_OHCI
].platform_data
=
665 &tc6393xb_cells
[TC6393XB_CELL_OHCI
];
666 tc6393xb_cells
[TC6393XB_CELL_OHCI
].data_size
=
667 sizeof(tc6393xb_cells
[TC6393XB_CELL_OHCI
]);
669 tc6393xb_cells
[TC6393XB_CELL_FB
].driver_data
= tcpd
->fb_data
;
670 tc6393xb_cells
[TC6393XB_CELL_FB
].platform_data
=
671 &tc6393xb_cells
[TC6393XB_CELL_FB
];
672 tc6393xb_cells
[TC6393XB_CELL_FB
].data_size
=
673 sizeof(tc6393xb_cells
[TC6393XB_CELL_FB
]);
675 ret
= mfd_add_devices(&dev
->dev
, dev
->id
,
676 tc6393xb_cells
, ARRAY_SIZE(tc6393xb_cells
),
677 iomem
, tcpd
->irq_base
);
686 tc6393xb_detach_irq(dev
);
689 if (tc6393xb
->gpio
.base
!= -1)
690 temp
= gpiochip_remove(&tc6393xb
->gpio
);
693 clk_disable(tc6393xb
->clk
);
695 iounmap(tc6393xb
->scr
);
697 release_resource(&tc6393xb
->rscr
);
699 clk_put(tc6393xb
->clk
);
707 static int __devexit
tc6393xb_remove(struct platform_device
*dev
)
709 struct tc6393xb_platform_data
*tcpd
= dev
->dev
.platform_data
;
710 struct tc6393xb
*tc6393xb
= platform_get_drvdata(dev
);
713 mfd_remove_devices(&dev
->dev
);
718 tc6393xb_detach_irq(dev
);
720 if (tc6393xb
->gpio
.base
!= -1) {
721 ret
= gpiochip_remove(&tc6393xb
->gpio
);
723 dev_err(&dev
->dev
, "Can't remove gpio chip: %d\n", ret
);
728 ret
= tcpd
->disable(dev
);
729 clk_disable(tc6393xb
->clk
);
730 iounmap(tc6393xb
->scr
);
731 release_resource(&tc6393xb
->rscr
);
732 platform_set_drvdata(dev
, NULL
);
733 clk_put(tc6393xb
->clk
);
740 static int tc6393xb_suspend(struct platform_device
*dev
, pm_message_t state
)
742 struct tc6393xb_platform_data
*tcpd
= dev
->dev
.platform_data
;
743 struct tc6393xb
*tc6393xb
= platform_get_drvdata(dev
);
746 tc6393xb
->suspend_state
.ccr
= ioread16(tc6393xb
->scr
+ SCR_CCR
);
747 tc6393xb
->suspend_state
.fer
= ioread8(tc6393xb
->scr
+ SCR_FER
);
749 for (i
= 0; i
< 3; i
++) {
750 tc6393xb
->suspend_state
.gpo_dsr
[i
] =
751 ioread8(tc6393xb
->scr
+ SCR_GPO_DSR(i
));
752 tc6393xb
->suspend_state
.gpo_doecr
[i
] =
753 ioread8(tc6393xb
->scr
+ SCR_GPO_DOECR(i
));
754 tc6393xb
->suspend_state
.gpi_bcr
[i
] =
755 ioread8(tc6393xb
->scr
+ SCR_GPI_BCR(i
));
757 ret
= tcpd
->suspend(dev
);
758 clk_disable(tc6393xb
->clk
);
763 static int tc6393xb_resume(struct platform_device
*dev
)
765 struct tc6393xb_platform_data
*tcpd
= dev
->dev
.platform_data
;
766 struct tc6393xb
*tc6393xb
= platform_get_drvdata(dev
);
770 clk_enable(tc6393xb
->clk
);
772 ret
= tcpd
->resume(dev
);
776 if (!tcpd
->resume_restore
)
779 iowrite8(tc6393xb
->suspend_state
.fer
, tc6393xb
->scr
+ SCR_FER
);
780 iowrite16(tcpd
->scr_pll2cr
, tc6393xb
->scr
+ SCR_PLL2CR
);
781 iowrite16(tc6393xb
->suspend_state
.ccr
, tc6393xb
->scr
+ SCR_CCR
);
782 iowrite16(SCR_MCR_RDY_OPENDRAIN
| SCR_MCR_RDY_UNK
| SCR_MCR_RDY_EN
|
783 SCR_MCR_INT_OPENDRAIN
| SCR_MCR_INT_UNK
| SCR_MCR_INT_EN
|
784 BIT(15), tc6393xb
->scr
+ SCR_MCR
);
785 iowrite16(tcpd
->scr_gper
, tc6393xb
->scr
+ SCR_GPER
);
786 iowrite8(0, tc6393xb
->scr
+ SCR_IRR
);
787 iowrite8(0xbf, tc6393xb
->scr
+ SCR_IMR
);
789 for (i
= 0; i
< 3; i
++) {
790 iowrite8(tc6393xb
->suspend_state
.gpo_dsr
[i
],
791 tc6393xb
->scr
+ SCR_GPO_DSR(i
));
792 iowrite8(tc6393xb
->suspend_state
.gpo_doecr
[i
],
793 tc6393xb
->scr
+ SCR_GPO_DOECR(i
));
794 iowrite8(tc6393xb
->suspend_state
.gpi_bcr
[i
],
795 tc6393xb
->scr
+ SCR_GPI_BCR(i
));
801 #define tc6393xb_suspend NULL
802 #define tc6393xb_resume NULL
805 static struct platform_driver tc6393xb_driver
= {
806 .probe
= tc6393xb_probe
,
807 .remove
= __devexit_p(tc6393xb_remove
),
808 .suspend
= tc6393xb_suspend
,
809 .resume
= tc6393xb_resume
,
813 .owner
= THIS_MODULE
,
817 static int __init
tc6393xb_init(void)
819 return platform_driver_register(&tc6393xb_driver
);
822 static void __exit
tc6393xb_exit(void)
824 platform_driver_unregister(&tc6393xb_driver
);
827 subsys_initcall(tc6393xb_init
);
828 module_exit(tc6393xb_exit
);
830 MODULE_LICENSE("GPL v2");
831 MODULE_AUTHOR("Ian Molton, Dmitry Baryshkov and Dirk Opfer");
832 MODULE_DESCRIPTION("tc6393xb Toshiba Mobile IO Controller");
833 MODULE_ALIAS("platform:tc6393xb");