Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Toshiba T7L66XB core mfd support |
| 4 | * |
| 5 | * Copyright (c) 2005, 2007, 2008 Ian Molton |
| 6 | * Copyright (c) 2008 Dmitry Baryshkov |
| 7 | * |
| 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. |
| 11 | * |
| 12 | * T7L66 features: |
| 13 | * |
| 14 | * Supported in this driver: |
| 15 | * SD/MMC |
| 16 | * SM/NAND flash controller |
| 17 | * |
| 18 | * As yet not supported |
| 19 | * GPIO interface (on NAND pins) |
| 20 | * Serial interface |
| 21 | * TFT 'interface converter' |
| 22 | * PCMCIA interface logic |
| 23 | */ |
| 24 | |
| 25 | #include <linux/kernel.h> |
| 26 | #include <linux/module.h> |
Ian Molton | 7acb706 | 2008-10-09 20:06:09 +0200 | [diff] [blame] | 27 | #include <linux/err.h> |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 28 | #include <linux/io.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 29 | #include <linux/slab.h> |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 30 | #include <linux/irq.h> |
Ian Molton | 7acb706 | 2008-10-09 20:06:09 +0200 | [diff] [blame] | 31 | #include <linux/clk.h> |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 32 | #include <linux/platform_device.h> |
| 33 | #include <linux/mfd/core.h> |
| 34 | #include <linux/mfd/tmio.h> |
| 35 | #include <linux/mfd/t7l66xb.h> |
| 36 | |
| 37 | enum { |
| 38 | T7L66XB_CELL_NAND, |
| 39 | T7L66XB_CELL_MMC, |
| 40 | }; |
| 41 | |
Ian Molton | 64e8867 | 2010-01-06 13:51:48 +0100 | [diff] [blame] | 42 | static const struct resource t7l66xb_mmc_resources[] = { |
| 43 | { |
| 44 | .start = 0x800, |
| 45 | .end = 0x9ff, |
| 46 | .flags = IORESOURCE_MEM, |
| 47 | }, |
| 48 | { |
| 49 | .start = IRQ_T7L66XB_MMC, |
| 50 | .end = IRQ_T7L66XB_MMC, |
| 51 | .flags = IORESOURCE_IRQ, |
| 52 | }, |
| 53 | }; |
| 54 | |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 55 | #define SCR_REVID 0x08 /* b Revision ID */ |
| 56 | #define SCR_IMR 0x42 /* b Interrupt Mask */ |
| 57 | #define SCR_DEV_CTL 0xe0 /* b Device control */ |
| 58 | #define SCR_ISR 0xe1 /* b Interrupt Status */ |
| 59 | #define SCR_GPO_OC 0xf0 /* b GPO output control */ |
| 60 | #define SCR_GPO_OS 0xf1 /* b GPO output enable */ |
| 61 | #define SCR_GPI_S 0xf2 /* w GPI status */ |
| 62 | #define SCR_APDC 0xf8 /* b Active pullup down ctrl */ |
| 63 | |
| 64 | #define SCR_DEV_CTL_USB BIT(0) /* USB enable */ |
| 65 | #define SCR_DEV_CTL_MMC BIT(1) /* MMC enable */ |
| 66 | |
| 67 | /*--------------------------------------------------------------------------*/ |
| 68 | |
| 69 | struct t7l66xb { |
| 70 | void __iomem *scr; |
| 71 | /* Lock to protect registers requiring read/modify/write ops. */ |
| 72 | spinlock_t lock; |
| 73 | |
| 74 | struct resource rscr; |
Ian Molton | 7acb706 | 2008-10-09 20:06:09 +0200 | [diff] [blame] | 75 | struct clk *clk48m; |
| 76 | struct clk *clk32k; |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 77 | int irq; |
| 78 | int irq_base; |
| 79 | }; |
| 80 | |
| 81 | /*--------------------------------------------------------------------------*/ |
| 82 | |
| 83 | static int t7l66xb_mmc_enable(struct platform_device *mmc) |
| 84 | { |
| 85 | struct platform_device *dev = to_platform_device(mmc->dev.parent); |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 86 | struct t7l66xb *t7l66xb = platform_get_drvdata(dev); |
| 87 | unsigned long flags; |
| 88 | u8 dev_ctl; |
| 89 | |
Ian Molton | 7acb706 | 2008-10-09 20:06:09 +0200 | [diff] [blame] | 90 | clk_enable(t7l66xb->clk32k); |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 91 | |
| 92 | spin_lock_irqsave(&t7l66xb->lock, flags); |
| 93 | |
| 94 | dev_ctl = tmio_ioread8(t7l66xb->scr + SCR_DEV_CTL); |
| 95 | dev_ctl |= SCR_DEV_CTL_MMC; |
| 96 | tmio_iowrite8(dev_ctl, t7l66xb->scr + SCR_DEV_CTL); |
| 97 | |
| 98 | spin_unlock_irqrestore(&t7l66xb->lock, flags); |
| 99 | |
Ian Molton | 64e8867 | 2010-01-06 13:51:48 +0100 | [diff] [blame] | 100 | tmio_core_mmc_enable(t7l66xb->scr + 0x200, 0, |
| 101 | t7l66xb_mmc_resources[0].start & 0xfffe); |
| 102 | |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | static int t7l66xb_mmc_disable(struct platform_device *mmc) |
| 107 | { |
| 108 | struct platform_device *dev = to_platform_device(mmc->dev.parent); |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 109 | struct t7l66xb *t7l66xb = platform_get_drvdata(dev); |
| 110 | unsigned long flags; |
| 111 | u8 dev_ctl; |
| 112 | |
| 113 | spin_lock_irqsave(&t7l66xb->lock, flags); |
| 114 | |
| 115 | dev_ctl = tmio_ioread8(t7l66xb->scr + SCR_DEV_CTL); |
| 116 | dev_ctl &= ~SCR_DEV_CTL_MMC; |
| 117 | tmio_iowrite8(dev_ctl, t7l66xb->scr + SCR_DEV_CTL); |
| 118 | |
| 119 | spin_unlock_irqrestore(&t7l66xb->lock, flags); |
| 120 | |
Ian Molton | 7acb706 | 2008-10-09 20:06:09 +0200 | [diff] [blame] | 121 | clk_disable(t7l66xb->clk32k); |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 122 | |
| 123 | return 0; |
| 124 | } |
| 125 | |
Ian Molton | 64e8867 | 2010-01-06 13:51:48 +0100 | [diff] [blame] | 126 | static void t7l66xb_mmc_pwr(struct platform_device *mmc, int state) |
| 127 | { |
| 128 | struct platform_device *dev = to_platform_device(mmc->dev.parent); |
| 129 | struct t7l66xb *t7l66xb = platform_get_drvdata(dev); |
| 130 | |
| 131 | tmio_core_mmc_pwr(t7l66xb->scr + 0x200, 0, state); |
| 132 | } |
| 133 | |
| 134 | static void t7l66xb_mmc_clk_div(struct platform_device *mmc, int state) |
| 135 | { |
| 136 | struct platform_device *dev = to_platform_device(mmc->dev.parent); |
| 137 | struct t7l66xb *t7l66xb = platform_get_drvdata(dev); |
| 138 | |
| 139 | tmio_core_mmc_clk_div(t7l66xb->scr + 0x200, 0, state); |
| 140 | } |
| 141 | |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 142 | /*--------------------------------------------------------------------------*/ |
| 143 | |
Samuel Ortiz | 4d3792e | 2009-06-15 15:43:31 +0200 | [diff] [blame] | 144 | static struct tmio_mmc_data t7166xb_mmc_data = { |
Philipp Zabel | f0e46cc | 2009-06-04 20:12:31 +0200 | [diff] [blame] | 145 | .hclk = 24000000, |
Ian Molton | 64e8867 | 2010-01-06 13:51:48 +0100 | [diff] [blame] | 146 | .set_pwr = t7l66xb_mmc_pwr, |
| 147 | .set_clk_div = t7l66xb_mmc_clk_div, |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 148 | }; |
| 149 | |
Tobias Klauser | 3446d4b | 2009-02-17 10:11:42 +0100 | [diff] [blame] | 150 | static const struct resource t7l66xb_nand_resources[] = { |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 151 | { |
| 152 | .start = 0xc00, |
| 153 | .end = 0xc07, |
| 154 | .flags = IORESOURCE_MEM, |
| 155 | }, |
| 156 | { |
| 157 | .start = 0x0100, |
| 158 | .end = 0x01ff, |
| 159 | .flags = IORESOURCE_MEM, |
| 160 | }, |
| 161 | { |
| 162 | .start = IRQ_T7L66XB_NAND, |
| 163 | .end = IRQ_T7L66XB_NAND, |
| 164 | .flags = IORESOURCE_IRQ, |
| 165 | }, |
| 166 | }; |
| 167 | |
| 168 | static struct mfd_cell t7l66xb_cells[] = { |
| 169 | [T7L66XB_CELL_MMC] = { |
| 170 | .name = "tmio-mmc", |
| 171 | .enable = t7l66xb_mmc_enable, |
| 172 | .disable = t7l66xb_mmc_disable, |
Andres Salomon | 4f95bf4 | 2011-02-17 19:07:29 -0800 | [diff] [blame] | 173 | .mfd_data = &t7166xb_mmc_data, |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 174 | .num_resources = ARRAY_SIZE(t7l66xb_mmc_resources), |
| 175 | .resources = t7l66xb_mmc_resources, |
| 176 | }, |
| 177 | [T7L66XB_CELL_NAND] = { |
| 178 | .name = "tmio-nand", |
| 179 | .num_resources = ARRAY_SIZE(t7l66xb_nand_resources), |
| 180 | .resources = t7l66xb_nand_resources, |
| 181 | }, |
| 182 | }; |
| 183 | |
| 184 | /*--------------------------------------------------------------------------*/ |
| 185 | |
| 186 | /* Handle the T7L66XB interrupt mux */ |
| 187 | static void t7l66xb_irq(unsigned int irq, struct irq_desc *desc) |
| 188 | { |
Thomas Gleixner | d5bb122 | 2011-03-25 11:12:32 +0000 | [diff] [blame] | 189 | struct t7l66xb *t7l66xb = irq_get_handler_data(irq); |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 190 | unsigned int isr; |
| 191 | unsigned int i, irq_base; |
| 192 | |
| 193 | irq_base = t7l66xb->irq_base; |
| 194 | |
| 195 | while ((isr = tmio_ioread8(t7l66xb->scr + SCR_ISR) & |
| 196 | ~tmio_ioread8(t7l66xb->scr + SCR_IMR))) |
| 197 | for (i = 0; i < T7L66XB_NR_IRQS; i++) |
| 198 | if (isr & (1 << i)) |
| 199 | generic_handle_irq(irq_base + i); |
| 200 | } |
| 201 | |
Mark Brown | a4e7fea | 2010-12-12 12:18:58 +0000 | [diff] [blame] | 202 | static void t7l66xb_irq_mask(struct irq_data *data) |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 203 | { |
Mark Brown | a4e7fea | 2010-12-12 12:18:58 +0000 | [diff] [blame] | 204 | struct t7l66xb *t7l66xb = irq_data_get_irq_chip_data(data); |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 205 | unsigned long flags; |
| 206 | u8 imr; |
| 207 | |
| 208 | spin_lock_irqsave(&t7l66xb->lock, flags); |
| 209 | imr = tmio_ioread8(t7l66xb->scr + SCR_IMR); |
Mark Brown | a4e7fea | 2010-12-12 12:18:58 +0000 | [diff] [blame] | 210 | imr |= 1 << (data->irq - t7l66xb->irq_base); |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 211 | tmio_iowrite8(imr, t7l66xb->scr + SCR_IMR); |
| 212 | spin_unlock_irqrestore(&t7l66xb->lock, flags); |
| 213 | } |
| 214 | |
Mark Brown | a4e7fea | 2010-12-12 12:18:58 +0000 | [diff] [blame] | 215 | static void t7l66xb_irq_unmask(struct irq_data *data) |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 216 | { |
Mark Brown | a4e7fea | 2010-12-12 12:18:58 +0000 | [diff] [blame] | 217 | struct t7l66xb *t7l66xb = irq_data_get_irq_chip_data(data); |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 218 | unsigned long flags; |
| 219 | u8 imr; |
| 220 | |
| 221 | spin_lock_irqsave(&t7l66xb->lock, flags); |
| 222 | imr = tmio_ioread8(t7l66xb->scr + SCR_IMR); |
Mark Brown | a4e7fea | 2010-12-12 12:18:58 +0000 | [diff] [blame] | 223 | imr &= ~(1 << (data->irq - t7l66xb->irq_base)); |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 224 | tmio_iowrite8(imr, t7l66xb->scr + SCR_IMR); |
| 225 | spin_unlock_irqrestore(&t7l66xb->lock, flags); |
| 226 | } |
| 227 | |
| 228 | static struct irq_chip t7l66xb_chip = { |
Mark Brown | a4e7fea | 2010-12-12 12:18:58 +0000 | [diff] [blame] | 229 | .name = "t7l66xb", |
| 230 | .irq_ack = t7l66xb_irq_mask, |
| 231 | .irq_mask = t7l66xb_irq_mask, |
| 232 | .irq_unmask = t7l66xb_irq_unmask, |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 233 | }; |
| 234 | |
| 235 | /*--------------------------------------------------------------------------*/ |
| 236 | |
| 237 | /* Install the IRQ handler */ |
| 238 | static void t7l66xb_attach_irq(struct platform_device *dev) |
| 239 | { |
| 240 | struct t7l66xb *t7l66xb = platform_get_drvdata(dev); |
| 241 | unsigned int irq, irq_base; |
| 242 | |
| 243 | irq_base = t7l66xb->irq_base; |
| 244 | |
| 245 | for (irq = irq_base; irq < irq_base + T7L66XB_NR_IRQS; irq++) { |
Thomas Gleixner | d6f7ce9f | 2011-03-25 11:12:35 +0000 | [diff] [blame] | 246 | irq_set_chip_and_handler(irq, &t7l66xb_chip, handle_level_irq); |
Thomas Gleixner | d5bb122 | 2011-03-25 11:12:32 +0000 | [diff] [blame] | 247 | irq_set_chip_data(irq, t7l66xb); |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 248 | #ifdef CONFIG_ARM |
| 249 | set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); |
| 250 | #endif |
| 251 | } |
| 252 | |
Thomas Gleixner | d5bb122 | 2011-03-25 11:12:32 +0000 | [diff] [blame] | 253 | irq_set_irq_type(t7l66xb->irq, IRQ_TYPE_EDGE_FALLING); |
| 254 | irq_set_handler_data(t7l66xb->irq, t7l66xb); |
| 255 | irq_set_chained_handler(t7l66xb->irq, t7l66xb_irq); |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | static void t7l66xb_detach_irq(struct platform_device *dev) |
| 259 | { |
| 260 | struct t7l66xb *t7l66xb = platform_get_drvdata(dev); |
| 261 | unsigned int irq, irq_base; |
| 262 | |
| 263 | irq_base = t7l66xb->irq_base; |
| 264 | |
Thomas Gleixner | d5bb122 | 2011-03-25 11:12:32 +0000 | [diff] [blame] | 265 | irq_set_chained_handler(t7l66xb->irq, NULL); |
| 266 | irq_set_handler_data(t7l66xb->irq, NULL); |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 267 | |
| 268 | for (irq = irq_base; irq < irq_base + T7L66XB_NR_IRQS; irq++) { |
| 269 | #ifdef CONFIG_ARM |
| 270 | set_irq_flags(irq, 0); |
| 271 | #endif |
Thomas Gleixner | d5bb122 | 2011-03-25 11:12:32 +0000 | [diff] [blame] | 272 | irq_set_chip(irq, NULL); |
| 273 | irq_set_chip_data(irq, NULL); |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 274 | } |
| 275 | } |
| 276 | |
| 277 | /*--------------------------------------------------------------------------*/ |
| 278 | |
| 279 | #ifdef CONFIG_PM |
| 280 | static int t7l66xb_suspend(struct platform_device *dev, pm_message_t state) |
| 281 | { |
Ian Molton | 7acb706 | 2008-10-09 20:06:09 +0200 | [diff] [blame] | 282 | struct t7l66xb *t7l66xb = platform_get_drvdata(dev); |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 283 | struct t7l66xb_platform_data *pdata = dev->dev.platform_data; |
| 284 | |
| 285 | if (pdata && pdata->suspend) |
| 286 | pdata->suspend(dev); |
Ian Molton | 7acb706 | 2008-10-09 20:06:09 +0200 | [diff] [blame] | 287 | clk_disable(t7l66xb->clk48m); |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 288 | |
| 289 | return 0; |
| 290 | } |
| 291 | |
| 292 | static int t7l66xb_resume(struct platform_device *dev) |
| 293 | { |
Ian Molton | 7acb706 | 2008-10-09 20:06:09 +0200 | [diff] [blame] | 294 | struct t7l66xb *t7l66xb = platform_get_drvdata(dev); |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 295 | struct t7l66xb_platform_data *pdata = dev->dev.platform_data; |
| 296 | |
Ian Molton | 7acb706 | 2008-10-09 20:06:09 +0200 | [diff] [blame] | 297 | clk_enable(t7l66xb->clk48m); |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 298 | if (pdata && pdata->resume) |
| 299 | pdata->resume(dev); |
| 300 | |
Ian Molton | 64e8867 | 2010-01-06 13:51:48 +0100 | [diff] [blame] | 301 | tmio_core_mmc_enable(t7l66xb->scr + 0x200, 0, |
| 302 | t7l66xb_mmc_resources[0].start & 0xfffe); |
| 303 | |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 304 | return 0; |
| 305 | } |
| 306 | #else |
| 307 | #define t7l66xb_suspend NULL |
| 308 | #define t7l66xb_resume NULL |
| 309 | #endif |
| 310 | |
| 311 | /*--------------------------------------------------------------------------*/ |
| 312 | |
| 313 | static int t7l66xb_probe(struct platform_device *dev) |
| 314 | { |
| 315 | struct t7l66xb_platform_data *pdata = dev->dev.platform_data; |
| 316 | struct t7l66xb *t7l66xb; |
| 317 | struct resource *iomem, *rscr; |
| 318 | int ret; |
| 319 | |
Samuel Ortiz | 9ad285d | 2010-03-19 12:46:28 +0100 | [diff] [blame] | 320 | if (pdata == NULL) |
| 321 | return -EINVAL; |
| 322 | |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 323 | iomem = platform_get_resource(dev, IORESOURCE_MEM, 0); |
| 324 | if (!iomem) |
| 325 | return -EINVAL; |
| 326 | |
| 327 | t7l66xb = kzalloc(sizeof *t7l66xb, GFP_KERNEL); |
| 328 | if (!t7l66xb) |
| 329 | return -ENOMEM; |
| 330 | |
| 331 | spin_lock_init(&t7l66xb->lock); |
| 332 | |
| 333 | platform_set_drvdata(dev, t7l66xb); |
| 334 | |
| 335 | ret = platform_get_irq(dev, 0); |
| 336 | if (ret >= 0) |
| 337 | t7l66xb->irq = ret; |
| 338 | else |
| 339 | goto err_noirq; |
| 340 | |
| 341 | t7l66xb->irq_base = pdata->irq_base; |
| 342 | |
Ian Molton | 7acb706 | 2008-10-09 20:06:09 +0200 | [diff] [blame] | 343 | t7l66xb->clk32k = clk_get(&dev->dev, "CLK_CK32K"); |
| 344 | if (IS_ERR(t7l66xb->clk32k)) { |
| 345 | ret = PTR_ERR(t7l66xb->clk32k); |
| 346 | goto err_clk32k_get; |
| 347 | } |
| 348 | |
| 349 | t7l66xb->clk48m = clk_get(&dev->dev, "CLK_CK48M"); |
| 350 | if (IS_ERR(t7l66xb->clk48m)) { |
| 351 | ret = PTR_ERR(t7l66xb->clk48m); |
Ian Molton | 7acb706 | 2008-10-09 20:06:09 +0200 | [diff] [blame] | 352 | goto err_clk48m_get; |
| 353 | } |
| 354 | |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 355 | rscr = &t7l66xb->rscr; |
| 356 | rscr->name = "t7l66xb-core"; |
| 357 | rscr->start = iomem->start; |
| 358 | rscr->end = iomem->start + 0xff; |
| 359 | rscr->flags = IORESOURCE_MEM; |
| 360 | |
| 361 | ret = request_resource(iomem, rscr); |
| 362 | if (ret) |
| 363 | goto err_request_scr; |
| 364 | |
H Hartley Sweeten | c02e6a5 | 2010-01-05 19:58:34 +0100 | [diff] [blame] | 365 | t7l66xb->scr = ioremap(rscr->start, resource_size(rscr)); |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 366 | if (!t7l66xb->scr) { |
| 367 | ret = -ENOMEM; |
| 368 | goto err_ioremap; |
| 369 | } |
| 370 | |
Ian Molton | 7acb706 | 2008-10-09 20:06:09 +0200 | [diff] [blame] | 371 | clk_enable(t7l66xb->clk48m); |
| 372 | |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 373 | if (pdata && pdata->enable) |
| 374 | pdata->enable(dev); |
| 375 | |
| 376 | /* Mask all interrupts */ |
| 377 | tmio_iowrite8(0xbf, t7l66xb->scr + SCR_IMR); |
| 378 | |
| 379 | printk(KERN_INFO "%s rev %d @ 0x%08lx, irq %d\n", |
| 380 | dev->name, tmio_ioread8(t7l66xb->scr + SCR_REVID), |
| 381 | (unsigned long)iomem->start, t7l66xb->irq); |
| 382 | |
| 383 | t7l66xb_attach_irq(dev); |
| 384 | |
Andres Salomon | d9d01f4 | 2011-02-17 19:07:30 -0800 | [diff] [blame] | 385 | t7l66xb_cells[T7L66XB_CELL_NAND].mfd_data = pdata->nand_data; |
Ian Molton | 8a4fbe0 | 2008-08-04 18:06:18 +0200 | [diff] [blame] | 386 | |
Samuel Ortiz | 56bf2bd | 2008-08-01 00:16:13 +0200 | [diff] [blame] | 387 | ret = mfd_add_devices(&dev->dev, dev->id, |
| 388 | t7l66xb_cells, ARRAY_SIZE(t7l66xb_cells), |
| 389 | iomem, t7l66xb->irq_base); |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 390 | |
| 391 | if (!ret) |
| 392 | return 0; |
| 393 | |
| 394 | t7l66xb_detach_irq(dev); |
| 395 | iounmap(t7l66xb->scr); |
| 396 | err_ioremap: |
| 397 | release_resource(&t7l66xb->rscr); |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 398 | err_request_scr: |
Ian Molton | 7acb706 | 2008-10-09 20:06:09 +0200 | [diff] [blame] | 399 | clk_put(t7l66xb->clk48m); |
| 400 | err_clk48m_get: |
| 401 | clk_put(t7l66xb->clk32k); |
| 402 | err_clk32k_get: |
| 403 | err_noirq: |
Julia Lawall | 0e820ab | 2009-12-22 21:31:43 +0100 | [diff] [blame] | 404 | kfree(t7l66xb); |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 405 | return ret; |
| 406 | } |
| 407 | |
| 408 | static int t7l66xb_remove(struct platform_device *dev) |
| 409 | { |
| 410 | struct t7l66xb_platform_data *pdata = dev->dev.platform_data; |
| 411 | struct t7l66xb *t7l66xb = platform_get_drvdata(dev); |
| 412 | int ret; |
| 413 | |
| 414 | ret = pdata->disable(dev); |
Ian Molton | 7acb706 | 2008-10-09 20:06:09 +0200 | [diff] [blame] | 415 | clk_disable(t7l66xb->clk48m); |
| 416 | clk_put(t7l66xb->clk48m); |
Axel Lin | d2d272a | 2010-07-01 17:43:50 +0800 | [diff] [blame] | 417 | clk_disable(t7l66xb->clk32k); |
| 418 | clk_put(t7l66xb->clk32k); |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 419 | t7l66xb_detach_irq(dev); |
| 420 | iounmap(t7l66xb->scr); |
| 421 | release_resource(&t7l66xb->rscr); |
Samuel Ortiz | 56bf2bd | 2008-08-01 00:16:13 +0200 | [diff] [blame] | 422 | mfd_remove_devices(&dev->dev); |
Ian Molton | 1f19201 | 2008-07-15 15:09:43 +0100 | [diff] [blame] | 423 | platform_set_drvdata(dev, NULL); |
| 424 | kfree(t7l66xb); |
| 425 | |
| 426 | return ret; |
| 427 | |
| 428 | } |
| 429 | |
| 430 | static struct platform_driver t7l66xb_platform_driver = { |
| 431 | .driver = { |
| 432 | .name = "t7l66xb", |
| 433 | .owner = THIS_MODULE, |
| 434 | }, |
| 435 | .suspend = t7l66xb_suspend, |
| 436 | .resume = t7l66xb_resume, |
| 437 | .probe = t7l66xb_probe, |
| 438 | .remove = t7l66xb_remove, |
| 439 | }; |
| 440 | |
| 441 | /*--------------------------------------------------------------------------*/ |
| 442 | |
| 443 | static int __init t7l66xb_init(void) |
| 444 | { |
| 445 | int retval = 0; |
| 446 | |
| 447 | retval = platform_driver_register(&t7l66xb_platform_driver); |
| 448 | return retval; |
| 449 | } |
| 450 | |
| 451 | static void __exit t7l66xb_exit(void) |
| 452 | { |
| 453 | platform_driver_unregister(&t7l66xb_platform_driver); |
| 454 | } |
| 455 | |
| 456 | module_init(t7l66xb_init); |
| 457 | module_exit(t7l66xb_exit); |
| 458 | |
| 459 | MODULE_DESCRIPTION("Toshiba T7L66XB core driver"); |
| 460 | MODULE_LICENSE("GPL v2"); |
| 461 | MODULE_AUTHOR("Ian Molton"); |
| 462 | MODULE_ALIAS("platform:t7l66xb"); |