3 * Toshiba T7L66XB core mfd support
5 * Copyright (c) 2005, 2007, 2008 Ian Molton
6 * Copyright (c) 2008 Dmitry Baryshkov
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
14 * Supported in this driver:
16 * SM/NAND flash controller
18 * As yet not supported
19 * GPIO interface (on NAND pins)
21 * TFT 'interface converter'
22 * PCMCIA interface logic
25 #include <linux/kernel.h>
26 #include <linux/module.h>
28 #include <linux/irq.h>
29 #include <linux/platform_device.h>
30 #include <linux/mfd/core.h>
31 #include <linux/mfd/tmio.h>
32 #include <linux/mfd/t7l66xb.h>
39 #define SCR_REVID 0x08 /* b Revision ID */
40 #define SCR_IMR 0x42 /* b Interrupt Mask */
41 #define SCR_DEV_CTL 0xe0 /* b Device control */
42 #define SCR_ISR 0xe1 /* b Interrupt Status */
43 #define SCR_GPO_OC 0xf0 /* b GPO output control */
44 #define SCR_GPO_OS 0xf1 /* b GPO output enable */
45 #define SCR_GPI_S 0xf2 /* w GPI status */
46 #define SCR_APDC 0xf8 /* b Active pullup down ctrl */
48 #define SCR_DEV_CTL_USB BIT(0) /* USB enable */
49 #define SCR_DEV_CTL_MMC BIT(1) /* MMC enable */
51 /*--------------------------------------------------------------------------*/
55 /* Lock to protect registers requiring read/modify/write ops. */
63 /*--------------------------------------------------------------------------*/
65 static int t7l66xb_mmc_enable(struct platform_device
*mmc
)
67 struct platform_device
*dev
= to_platform_device(mmc
->dev
.parent
);
68 struct t7l66xb_platform_data
*pdata
= dev
->dev
.platform_data
;
69 struct t7l66xb
*t7l66xb
= platform_get_drvdata(dev
);
73 if (pdata
->enable_clk32k
)
74 pdata
->enable_clk32k(dev
);
76 spin_lock_irqsave(&t7l66xb
->lock
, flags
);
78 dev_ctl
= tmio_ioread8(t7l66xb
->scr
+ SCR_DEV_CTL
);
79 dev_ctl
|= SCR_DEV_CTL_MMC
;
80 tmio_iowrite8(dev_ctl
, t7l66xb
->scr
+ SCR_DEV_CTL
);
82 spin_unlock_irqrestore(&t7l66xb
->lock
, flags
);
87 static int t7l66xb_mmc_disable(struct platform_device
*mmc
)
89 struct platform_device
*dev
= to_platform_device(mmc
->dev
.parent
);
90 struct t7l66xb_platform_data
*pdata
= dev
->dev
.platform_data
;
91 struct t7l66xb
*t7l66xb
= platform_get_drvdata(dev
);
95 spin_lock_irqsave(&t7l66xb
->lock
, flags
);
97 dev_ctl
= tmio_ioread8(t7l66xb
->scr
+ SCR_DEV_CTL
);
98 dev_ctl
&= ~SCR_DEV_CTL_MMC
;
99 tmio_iowrite8(dev_ctl
, t7l66xb
->scr
+ SCR_DEV_CTL
);
101 spin_unlock_irqrestore(&t7l66xb
->lock
, flags
);
103 if (pdata
->disable_clk32k
)
104 pdata
->disable_clk32k(dev
);
109 /*--------------------------------------------------------------------------*/
111 const static struct resource t7l66xb_mmc_resources
[] = {
115 .flags
= IORESOURCE_MEM
,
120 .flags
= IORESOURCE_MEM
,
123 .start
= IRQ_T7L66XB_MMC
,
124 .end
= IRQ_T7L66XB_MMC
,
125 .flags
= IORESOURCE_IRQ
,
129 const static struct resource t7l66xb_nand_resources
[] = {
133 .flags
= IORESOURCE_MEM
,
138 .flags
= IORESOURCE_MEM
,
141 .start
= IRQ_T7L66XB_NAND
,
142 .end
= IRQ_T7L66XB_NAND
,
143 .flags
= IORESOURCE_IRQ
,
147 static struct mfd_cell t7l66xb_cells
[] = {
148 [T7L66XB_CELL_MMC
] = {
150 .enable
= t7l66xb_mmc_enable
,
151 .disable
= t7l66xb_mmc_disable
,
152 .num_resources
= ARRAY_SIZE(t7l66xb_mmc_resources
),
153 .resources
= t7l66xb_mmc_resources
,
155 [T7L66XB_CELL_NAND
] = {
157 .num_resources
= ARRAY_SIZE(t7l66xb_nand_resources
),
158 .resources
= t7l66xb_nand_resources
,
162 /*--------------------------------------------------------------------------*/
164 /* Handle the T7L66XB interrupt mux */
165 static void t7l66xb_irq(unsigned int irq
, struct irq_desc
*desc
)
167 struct t7l66xb
*t7l66xb
= get_irq_data(irq
);
169 unsigned int i
, irq_base
;
171 irq_base
= t7l66xb
->irq_base
;
173 while ((isr
= tmio_ioread8(t7l66xb
->scr
+ SCR_ISR
) &
174 ~tmio_ioread8(t7l66xb
->scr
+ SCR_IMR
)))
175 for (i
= 0; i
< T7L66XB_NR_IRQS
; i
++)
177 generic_handle_irq(irq_base
+ i
);
180 static void t7l66xb_irq_mask(unsigned int irq
)
182 struct t7l66xb
*t7l66xb
= get_irq_chip_data(irq
);
186 spin_lock_irqsave(&t7l66xb
->lock
, flags
);
187 imr
= tmio_ioread8(t7l66xb
->scr
+ SCR_IMR
);
188 imr
|= 1 << (irq
- t7l66xb
->irq_base
);
189 tmio_iowrite8(imr
, t7l66xb
->scr
+ SCR_IMR
);
190 spin_unlock_irqrestore(&t7l66xb
->lock
, flags
);
193 static void t7l66xb_irq_unmask(unsigned int irq
)
195 struct t7l66xb
*t7l66xb
= get_irq_chip_data(irq
);
199 spin_lock_irqsave(&t7l66xb
->lock
, flags
);
200 imr
= tmio_ioread8(t7l66xb
->scr
+ SCR_IMR
);
201 imr
&= ~(1 << (irq
- t7l66xb
->irq_base
));
202 tmio_iowrite8(imr
, t7l66xb
->scr
+ SCR_IMR
);
203 spin_unlock_irqrestore(&t7l66xb
->lock
, flags
);
206 static struct irq_chip t7l66xb_chip
= {
208 .ack
= t7l66xb_irq_mask
,
209 .mask
= t7l66xb_irq_mask
,
210 .unmask
= t7l66xb_irq_unmask
,
213 /*--------------------------------------------------------------------------*/
215 /* Install the IRQ handler */
216 static void t7l66xb_attach_irq(struct platform_device
*dev
)
218 struct t7l66xb
*t7l66xb
= platform_get_drvdata(dev
);
219 unsigned int irq
, irq_base
;
221 irq_base
= t7l66xb
->irq_base
;
223 for (irq
= irq_base
; irq
< irq_base
+ T7L66XB_NR_IRQS
; irq
++) {
224 set_irq_chip(irq
, &t7l66xb_chip
);
225 set_irq_chip_data(irq
, t7l66xb
);
226 set_irq_handler(irq
, handle_level_irq
);
228 set_irq_flags(irq
, IRQF_VALID
| IRQF_PROBE
);
232 set_irq_type(t7l66xb
->irq
, IRQ_TYPE_EDGE_FALLING
);
233 set_irq_data(t7l66xb
->irq
, t7l66xb
);
234 set_irq_chained_handler(t7l66xb
->irq
, t7l66xb_irq
);
237 static void t7l66xb_detach_irq(struct platform_device
*dev
)
239 struct t7l66xb
*t7l66xb
= platform_get_drvdata(dev
);
240 unsigned int irq
, irq_base
;
242 irq_base
= t7l66xb
->irq_base
;
244 set_irq_chained_handler(t7l66xb
->irq
, NULL
);
245 set_irq_data(t7l66xb
->irq
, NULL
);
247 for (irq
= irq_base
; irq
< irq_base
+ T7L66XB_NR_IRQS
; irq
++) {
249 set_irq_flags(irq
, 0);
251 set_irq_chip(irq
, NULL
);
252 set_irq_chip_data(irq
, NULL
);
256 /*--------------------------------------------------------------------------*/
259 static int t7l66xb_suspend(struct platform_device
*dev
, pm_message_t state
)
261 struct t7l66xb_platform_data
*pdata
= dev
->dev
.platform_data
;
263 if (pdata
&& pdata
->suspend
)
269 static int t7l66xb_resume(struct platform_device
*dev
)
271 struct t7l66xb_platform_data
*pdata
= dev
->dev
.platform_data
;
273 if (pdata
&& pdata
->resume
)
279 #define t7l66xb_suspend NULL
280 #define t7l66xb_resume NULL
283 /*--------------------------------------------------------------------------*/
285 static int t7l66xb_probe(struct platform_device
*dev
)
287 struct t7l66xb_platform_data
*pdata
= dev
->dev
.platform_data
;
288 struct t7l66xb
*t7l66xb
;
289 struct resource
*iomem
, *rscr
;
292 iomem
= platform_get_resource(dev
, IORESOURCE_MEM
, 0);
296 t7l66xb
= kzalloc(sizeof *t7l66xb
, GFP_KERNEL
);
300 spin_lock_init(&t7l66xb
->lock
);
302 platform_set_drvdata(dev
, t7l66xb
);
304 ret
= platform_get_irq(dev
, 0);
310 t7l66xb
->irq_base
= pdata
->irq_base
;
312 rscr
= &t7l66xb
->rscr
;
313 rscr
->name
= "t7l66xb-core";
314 rscr
->start
= iomem
->start
;
315 rscr
->end
= iomem
->start
+ 0xff;
316 rscr
->flags
= IORESOURCE_MEM
;
318 ret
= request_resource(iomem
, rscr
);
320 goto err_request_scr
;
322 t7l66xb
->scr
= ioremap(rscr
->start
, rscr
->end
- rscr
->start
+ 1);
328 if (pdata
&& pdata
->enable
)
331 /* Mask all interrupts */
332 tmio_iowrite8(0xbf, t7l66xb
->scr
+ SCR_IMR
);
334 printk(KERN_INFO
"%s rev %d @ 0x%08lx, irq %d\n",
335 dev
->name
, tmio_ioread8(t7l66xb
->scr
+ SCR_REVID
),
336 (unsigned long)iomem
->start
, t7l66xb
->irq
);
338 t7l66xb_attach_irq(dev
);
340 t7l66xb_cells
[T7L66XB_CELL_NAND
].driver_data
= pdata
->nand_data
;
341 t7l66xb_cells
[T7L66XB_CELL_NAND
].platform_data
=
342 &t7l66xb_cells
[T7L66XB_CELL_NAND
];
343 t7l66xb_cells
[T7L66XB_CELL_NAND
].data_size
=
344 sizeof(t7l66xb_cells
[T7L66XB_CELL_NAND
]);
346 t7l66xb_cells
[T7L66XB_CELL_MMC
].platform_data
=
347 &t7l66xb_cells
[T7L66XB_CELL_MMC
];
348 t7l66xb_cells
[T7L66XB_CELL_MMC
].data_size
=
349 sizeof(t7l66xb_cells
[T7L66XB_CELL_MMC
]);
351 ret
= mfd_add_devices(&dev
->dev
, dev
->id
,
352 t7l66xb_cells
, ARRAY_SIZE(t7l66xb_cells
),
353 iomem
, t7l66xb
->irq_base
);
358 t7l66xb_detach_irq(dev
);
359 iounmap(t7l66xb
->scr
);
361 release_resource(&t7l66xb
->rscr
);
368 static int t7l66xb_remove(struct platform_device
*dev
)
370 struct t7l66xb_platform_data
*pdata
= dev
->dev
.platform_data
;
371 struct t7l66xb
*t7l66xb
= platform_get_drvdata(dev
);
374 ret
= pdata
->disable(dev
);
376 t7l66xb_detach_irq(dev
);
377 iounmap(t7l66xb
->scr
);
378 release_resource(&t7l66xb
->rscr
);
379 mfd_remove_devices(&dev
->dev
);
380 platform_set_drvdata(dev
, NULL
);
387 static struct platform_driver t7l66xb_platform_driver
= {
390 .owner
= THIS_MODULE
,
392 .suspend
= t7l66xb_suspend
,
393 .resume
= t7l66xb_resume
,
394 .probe
= t7l66xb_probe
,
395 .remove
= t7l66xb_remove
,
398 /*--------------------------------------------------------------------------*/
400 static int __init
t7l66xb_init(void)
404 retval
= platform_driver_register(&t7l66xb_platform_driver
);
408 static void __exit
t7l66xb_exit(void)
410 platform_driver_unregister(&t7l66xb_platform_driver
);
413 module_init(t7l66xb_init
);
414 module_exit(t7l66xb_exit
);
416 MODULE_DESCRIPTION("Toshiba T7L66XB core driver");
417 MODULE_LICENSE("GPL v2");
418 MODULE_AUTHOR("Ian Molton");
419 MODULE_ALIAS("platform:t7l66xb");