Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Toshiba TC6393XB SoC support |
| 3 | * |
| 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 |
| 8 | * |
| 9 | * Based on code written by Sharp/Lineo for 2.4 kernels |
| 10 | * Based on locomo.c |
| 11 | * |
| 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. |
| 15 | */ |
| 16 | |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/io.h> |
| 20 | #include <linux/irq.h> |
| 21 | #include <linux/platform_device.h> |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 22 | #include <linux/clk.h> |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 23 | #include <linux/err.h> |
Dmitry Baryshkov | f024ff1 | 2008-06-27 10:37:57 +0100 | [diff] [blame] | 24 | #include <linux/mfd/core.h> |
| 25 | #include <linux/mfd/tmio.h> |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 26 | #include <linux/mfd/tc6393xb.h> |
| 27 | #include <linux/gpio.h> |
| 28 | |
| 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 */ |
| 55 | |
| 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) |
| 67 | |
| 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 */ |
| 71 | |
| 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 */ |
| 85 | |
| 86 | #define TC_GPIO_BIT(i) (1 << (i & 0x7)) |
| 87 | |
| 88 | /*--------------------------------------------------------------------------*/ |
| 89 | |
| 90 | struct tc6393xb { |
| 91 | void __iomem *scr; |
| 92 | |
| 93 | struct gpio_chip gpio; |
| 94 | |
| 95 | struct clk *clk; /* 3,6 Mhz */ |
| 96 | |
| 97 | spinlock_t lock; /* protects RMW cycles */ |
| 98 | |
| 99 | struct { |
| 100 | u8 fer; |
| 101 | u16 ccr; |
| 102 | u8 gpi_bcr[3]; |
| 103 | u8 gpo_dsr[3]; |
| 104 | u8 gpo_doecr[3]; |
| 105 | } suspend_state; |
| 106 | |
| 107 | struct resource rscr; |
| 108 | struct resource *iomem; |
| 109 | int irq; |
| 110 | int irq_base; |
| 111 | }; |
| 112 | |
Dmitry Baryshkov | f024ff1 | 2008-06-27 10:37:57 +0100 | [diff] [blame] | 113 | enum { |
| 114 | TC6393XB_CELL_NAND, |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 115 | TC6393XB_CELL_MMC, |
Dmitry Baryshkov | 51a5562 | 2008-10-03 20:11:36 +0200 | [diff] [blame^] | 116 | TC6393XB_CELL_OHCI, |
Dmitry Baryshkov | f024ff1 | 2008-06-27 10:37:57 +0100 | [diff] [blame] | 117 | }; |
| 118 | |
| 119 | /*--------------------------------------------------------------------------*/ |
| 120 | |
| 121 | static int tc6393xb_nand_enable(struct platform_device *nand) |
| 122 | { |
| 123 | struct platform_device *dev = to_platform_device(nand->dev.parent); |
| 124 | struct tc6393xb *tc6393xb = platform_get_drvdata(dev); |
| 125 | unsigned long flags; |
| 126 | |
| 127 | spin_lock_irqsave(&tc6393xb->lock, flags); |
| 128 | |
| 129 | /* SMD buffer on */ |
| 130 | dev_dbg(&dev->dev, "SMD buffer on\n"); |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 131 | tmio_iowrite8(0xff, tc6393xb->scr + SCR_GPI_BCR(1)); |
Dmitry Baryshkov | f024ff1 | 2008-06-27 10:37:57 +0100 | [diff] [blame] | 132 | |
| 133 | spin_unlock_irqrestore(&tc6393xb->lock, flags); |
| 134 | |
| 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | static struct resource __devinitdata tc6393xb_nand_resources[] = { |
| 139 | { |
Dmitry Baryshkov | f024ff1 | 2008-06-27 10:37:57 +0100 | [diff] [blame] | 140 | .start = 0x1000, |
| 141 | .end = 0x1007, |
| 142 | .flags = IORESOURCE_MEM, |
| 143 | }, |
| 144 | { |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 145 | .start = 0x0100, |
| 146 | .end = 0x01ff, |
| 147 | .flags = IORESOURCE_MEM, |
| 148 | }, |
| 149 | { |
Dmitry Baryshkov | f024ff1 | 2008-06-27 10:37:57 +0100 | [diff] [blame] | 150 | .start = IRQ_TC6393_NAND, |
| 151 | .end = IRQ_TC6393_NAND, |
| 152 | .flags = IORESOURCE_IRQ, |
| 153 | }, |
| 154 | }; |
| 155 | |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 156 | static struct resource __devinitdata tc6393xb_mmc_resources[] = { |
| 157 | { |
| 158 | .start = 0x800, |
| 159 | .end = 0x9ff, |
| 160 | .flags = IORESOURCE_MEM, |
| 161 | }, |
| 162 | { |
| 163 | .start = 0x200, |
| 164 | .end = 0x2ff, |
| 165 | .flags = IORESOURCE_MEM, |
| 166 | }, |
| 167 | { |
| 168 | .start = IRQ_TC6393_MMC, |
| 169 | .end = IRQ_TC6393_MMC, |
| 170 | .flags = IORESOURCE_IRQ, |
| 171 | }, |
| 172 | }; |
| 173 | |
Dmitry Baryshkov | 51a5562 | 2008-10-03 20:11:36 +0200 | [diff] [blame^] | 174 | const static struct resource tc6393xb_ohci_resources[] = { |
| 175 | { |
| 176 | .start = 0x3000, |
| 177 | .end = 0x31ff, |
| 178 | .flags = IORESOURCE_MEM, |
| 179 | }, |
| 180 | { |
| 181 | .start = 0x0300, |
| 182 | .end = 0x03ff, |
| 183 | .flags = IORESOURCE_MEM, |
| 184 | }, |
| 185 | { |
| 186 | .start = 0x010000, |
| 187 | .end = 0x017fff, |
| 188 | .flags = IORESOURCE_MEM, |
| 189 | }, |
| 190 | { |
| 191 | .start = 0x018000, |
| 192 | .end = 0x01ffff, |
| 193 | .flags = IORESOURCE_MEM, |
| 194 | }, |
| 195 | { |
| 196 | .start = IRQ_TC6393_OHCI, |
| 197 | .end = IRQ_TC6393_OHCI, |
| 198 | .flags = IORESOURCE_IRQ, |
| 199 | }, |
| 200 | }; |
| 201 | |
| 202 | static int tc6393xb_ohci_enable(struct platform_device *dev) |
| 203 | { |
| 204 | struct tc6393xb *tc6393xb = dev_get_drvdata(dev->dev.parent); |
| 205 | unsigned long flags; |
| 206 | u16 ccr; |
| 207 | u8 fer; |
| 208 | |
| 209 | spin_lock_irqsave(&tc6393xb->lock, flags); |
| 210 | |
| 211 | ccr = tmio_ioread16(tc6393xb->scr + SCR_CCR); |
| 212 | ccr |= SCR_CCR_USBCK; |
| 213 | tmio_iowrite16(ccr, tc6393xb->scr + SCR_CCR); |
| 214 | |
| 215 | fer = tmio_ioread8(tc6393xb->scr + SCR_FER); |
| 216 | fer |= SCR_FER_USBEN; |
| 217 | tmio_iowrite8(fer, tc6393xb->scr + SCR_FER); |
| 218 | |
| 219 | spin_unlock_irqrestore(&tc6393xb->lock, flags); |
| 220 | |
| 221 | return 0; |
| 222 | } |
| 223 | |
| 224 | static int tc6393xb_ohci_disable(struct platform_device *dev) |
| 225 | { |
| 226 | struct tc6393xb *tc6393xb = dev_get_drvdata(dev->dev.parent); |
| 227 | unsigned long flags; |
| 228 | u16 ccr; |
| 229 | u8 fer; |
| 230 | |
| 231 | spin_lock_irqsave(&tc6393xb->lock, flags); |
| 232 | |
| 233 | fer = tmio_ioread8(tc6393xb->scr + SCR_FER); |
| 234 | fer &= ~SCR_FER_USBEN; |
| 235 | tmio_iowrite8(fer, tc6393xb->scr + SCR_FER); |
| 236 | |
| 237 | ccr = tmio_ioread16(tc6393xb->scr + SCR_CCR); |
| 238 | ccr &= ~SCR_CCR_USBCK; |
| 239 | tmio_iowrite16(ccr, tc6393xb->scr + SCR_CCR); |
| 240 | |
| 241 | spin_unlock_irqrestore(&tc6393xb->lock, flags); |
| 242 | |
| 243 | return 0; |
| 244 | } |
| 245 | |
Dmitry Baryshkov | f024ff1 | 2008-06-27 10:37:57 +0100 | [diff] [blame] | 246 | static struct mfd_cell __devinitdata tc6393xb_cells[] = { |
| 247 | [TC6393XB_CELL_NAND] = { |
| 248 | .name = "tmio-nand", |
| 249 | .enable = tc6393xb_nand_enable, |
| 250 | .num_resources = ARRAY_SIZE(tc6393xb_nand_resources), |
| 251 | .resources = tc6393xb_nand_resources, |
| 252 | }, |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 253 | [TC6393XB_CELL_MMC] = { |
| 254 | .name = "tmio-mmc", |
| 255 | .num_resources = ARRAY_SIZE(tc6393xb_mmc_resources), |
| 256 | .resources = tc6393xb_mmc_resources, |
| 257 | }, |
Dmitry Baryshkov | 51a5562 | 2008-10-03 20:11:36 +0200 | [diff] [blame^] | 258 | [TC6393XB_CELL_OHCI] = { |
| 259 | .name = "tmio-ohci", |
| 260 | .num_resources = ARRAY_SIZE(tc6393xb_ohci_resources), |
| 261 | .resources = tc6393xb_ohci_resources, |
| 262 | .enable = tc6393xb_ohci_enable, |
| 263 | .suspend = tc6393xb_ohci_disable, |
| 264 | .resume = tc6393xb_ohci_enable, |
| 265 | .disable = tc6393xb_ohci_disable, |
| 266 | }, |
Dmitry Baryshkov | f024ff1 | 2008-06-27 10:37:57 +0100 | [diff] [blame] | 267 | }; |
| 268 | |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 269 | /*--------------------------------------------------------------------------*/ |
| 270 | |
| 271 | static int tc6393xb_gpio_get(struct gpio_chip *chip, |
| 272 | unsigned offset) |
| 273 | { |
| 274 | struct tc6393xb *tc6393xb = container_of(chip, struct tc6393xb, gpio); |
| 275 | |
| 276 | /* XXX: does dsr also represent inputs? */ |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 277 | return tmio_ioread8(tc6393xb->scr + SCR_GPO_DSR(offset / 8)) |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 278 | & TC_GPIO_BIT(offset); |
| 279 | } |
| 280 | |
| 281 | static void __tc6393xb_gpio_set(struct gpio_chip *chip, |
| 282 | unsigned offset, int value) |
| 283 | { |
| 284 | struct tc6393xb *tc6393xb = container_of(chip, struct tc6393xb, gpio); |
| 285 | u8 dsr; |
| 286 | |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 287 | dsr = tmio_ioread8(tc6393xb->scr + SCR_GPO_DSR(offset / 8)); |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 288 | if (value) |
| 289 | dsr |= TC_GPIO_BIT(offset); |
| 290 | else |
| 291 | dsr &= ~TC_GPIO_BIT(offset); |
| 292 | |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 293 | tmio_iowrite8(dsr, tc6393xb->scr + SCR_GPO_DSR(offset / 8)); |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | static void tc6393xb_gpio_set(struct gpio_chip *chip, |
| 297 | unsigned offset, int value) |
| 298 | { |
| 299 | struct tc6393xb *tc6393xb = container_of(chip, struct tc6393xb, gpio); |
| 300 | unsigned long flags; |
| 301 | |
| 302 | spin_lock_irqsave(&tc6393xb->lock, flags); |
| 303 | |
| 304 | __tc6393xb_gpio_set(chip, offset, value); |
| 305 | |
| 306 | spin_unlock_irqrestore(&tc6393xb->lock, flags); |
| 307 | } |
| 308 | |
| 309 | static int tc6393xb_gpio_direction_input(struct gpio_chip *chip, |
| 310 | unsigned offset) |
| 311 | { |
| 312 | struct tc6393xb *tc6393xb = container_of(chip, struct tc6393xb, gpio); |
| 313 | unsigned long flags; |
| 314 | u8 doecr; |
| 315 | |
| 316 | spin_lock_irqsave(&tc6393xb->lock, flags); |
| 317 | |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 318 | doecr = tmio_ioread8(tc6393xb->scr + SCR_GPO_DOECR(offset / 8)); |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 319 | doecr &= ~TC_GPIO_BIT(offset); |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 320 | tmio_iowrite8(doecr, tc6393xb->scr + SCR_GPO_DOECR(offset / 8)); |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 321 | |
| 322 | spin_unlock_irqrestore(&tc6393xb->lock, flags); |
| 323 | |
| 324 | return 0; |
| 325 | } |
| 326 | |
| 327 | static int tc6393xb_gpio_direction_output(struct gpio_chip *chip, |
| 328 | unsigned offset, int value) |
| 329 | { |
| 330 | struct tc6393xb *tc6393xb = container_of(chip, struct tc6393xb, gpio); |
| 331 | unsigned long flags; |
| 332 | u8 doecr; |
| 333 | |
| 334 | spin_lock_irqsave(&tc6393xb->lock, flags); |
| 335 | |
| 336 | __tc6393xb_gpio_set(chip, offset, value); |
| 337 | |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 338 | doecr = tmio_ioread8(tc6393xb->scr + SCR_GPO_DOECR(offset / 8)); |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 339 | doecr |= TC_GPIO_BIT(offset); |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 340 | tmio_iowrite8(doecr, tc6393xb->scr + SCR_GPO_DOECR(offset / 8)); |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 341 | |
| 342 | spin_unlock_irqrestore(&tc6393xb->lock, flags); |
| 343 | |
| 344 | return 0; |
| 345 | } |
| 346 | |
| 347 | static int tc6393xb_register_gpio(struct tc6393xb *tc6393xb, int gpio_base) |
| 348 | { |
| 349 | tc6393xb->gpio.label = "tc6393xb"; |
| 350 | tc6393xb->gpio.base = gpio_base; |
| 351 | tc6393xb->gpio.ngpio = 16; |
| 352 | tc6393xb->gpio.set = tc6393xb_gpio_set; |
| 353 | tc6393xb->gpio.get = tc6393xb_gpio_get; |
| 354 | tc6393xb->gpio.direction_input = tc6393xb_gpio_direction_input; |
| 355 | tc6393xb->gpio.direction_output = tc6393xb_gpio_direction_output; |
| 356 | |
| 357 | return gpiochip_add(&tc6393xb->gpio); |
| 358 | } |
| 359 | |
| 360 | /*--------------------------------------------------------------------------*/ |
| 361 | |
| 362 | static void |
| 363 | tc6393xb_irq(unsigned int irq, struct irq_desc *desc) |
| 364 | { |
| 365 | struct tc6393xb *tc6393xb = get_irq_data(irq); |
| 366 | unsigned int isr; |
| 367 | unsigned int i, irq_base; |
| 368 | |
| 369 | irq_base = tc6393xb->irq_base; |
| 370 | |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 371 | while ((isr = tmio_ioread8(tc6393xb->scr + SCR_ISR) & |
| 372 | ~tmio_ioread8(tc6393xb->scr + SCR_IMR))) |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 373 | for (i = 0; i < TC6393XB_NR_IRQS; i++) { |
| 374 | if (isr & (1 << i)) |
| 375 | generic_handle_irq(irq_base + i); |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | static void tc6393xb_irq_ack(unsigned int irq) |
| 380 | { |
| 381 | } |
| 382 | |
| 383 | static void tc6393xb_irq_mask(unsigned int irq) |
| 384 | { |
| 385 | struct tc6393xb *tc6393xb = get_irq_chip_data(irq); |
| 386 | unsigned long flags; |
| 387 | u8 imr; |
| 388 | |
| 389 | spin_lock_irqsave(&tc6393xb->lock, flags); |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 390 | imr = tmio_ioread8(tc6393xb->scr + SCR_IMR); |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 391 | imr |= 1 << (irq - tc6393xb->irq_base); |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 392 | tmio_iowrite8(imr, tc6393xb->scr + SCR_IMR); |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 393 | spin_unlock_irqrestore(&tc6393xb->lock, flags); |
| 394 | } |
| 395 | |
| 396 | static void tc6393xb_irq_unmask(unsigned int irq) |
| 397 | { |
| 398 | struct tc6393xb *tc6393xb = get_irq_chip_data(irq); |
| 399 | unsigned long flags; |
| 400 | u8 imr; |
| 401 | |
| 402 | spin_lock_irqsave(&tc6393xb->lock, flags); |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 403 | imr = tmio_ioread8(tc6393xb->scr + SCR_IMR); |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 404 | imr &= ~(1 << (irq - tc6393xb->irq_base)); |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 405 | tmio_iowrite8(imr, tc6393xb->scr + SCR_IMR); |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 406 | spin_unlock_irqrestore(&tc6393xb->lock, flags); |
| 407 | } |
| 408 | |
| 409 | static struct irq_chip tc6393xb_chip = { |
| 410 | .name = "tc6393xb", |
| 411 | .ack = tc6393xb_irq_ack, |
| 412 | .mask = tc6393xb_irq_mask, |
| 413 | .unmask = tc6393xb_irq_unmask, |
| 414 | }; |
| 415 | |
| 416 | static void tc6393xb_attach_irq(struct platform_device *dev) |
| 417 | { |
| 418 | struct tc6393xb *tc6393xb = platform_get_drvdata(dev); |
| 419 | unsigned int irq, irq_base; |
| 420 | |
| 421 | irq_base = tc6393xb->irq_base; |
| 422 | |
| 423 | for (irq = irq_base; irq < irq_base + TC6393XB_NR_IRQS; irq++) { |
| 424 | set_irq_chip(irq, &tc6393xb_chip); |
| 425 | set_irq_chip_data(irq, tc6393xb); |
| 426 | set_irq_handler(irq, handle_edge_irq); |
| 427 | set_irq_flags(irq, IRQF_VALID | IRQF_PROBE); |
| 428 | } |
| 429 | |
Dmitry Baryshkov | 6cab486 | 2008-07-27 04:23:31 +0100 | [diff] [blame] | 430 | set_irq_type(tc6393xb->irq, IRQ_TYPE_EDGE_FALLING); |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 431 | set_irq_data(tc6393xb->irq, tc6393xb); |
| 432 | set_irq_chained_handler(tc6393xb->irq, tc6393xb_irq); |
| 433 | } |
| 434 | |
| 435 | static void tc6393xb_detach_irq(struct platform_device *dev) |
| 436 | { |
| 437 | struct tc6393xb *tc6393xb = platform_get_drvdata(dev); |
| 438 | unsigned int irq, irq_base; |
| 439 | |
| 440 | set_irq_chained_handler(tc6393xb->irq, NULL); |
| 441 | set_irq_data(tc6393xb->irq, NULL); |
| 442 | |
| 443 | irq_base = tc6393xb->irq_base; |
| 444 | |
| 445 | for (irq = irq_base; irq < irq_base + TC6393XB_NR_IRQS; irq++) { |
| 446 | set_irq_flags(irq, 0); |
| 447 | set_irq_chip(irq, NULL); |
| 448 | set_irq_chip_data(irq, NULL); |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | /*--------------------------------------------------------------------------*/ |
| 453 | |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 454 | static int __devinit tc6393xb_probe(struct platform_device *dev) |
| 455 | { |
| 456 | struct tc6393xb_platform_data *tcpd = dev->dev.platform_data; |
| 457 | struct tc6393xb *tc6393xb; |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 458 | struct resource *iomem, *rscr; |
| 459 | int ret, temp; |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 460 | |
| 461 | iomem = platform_get_resource(dev, IORESOURCE_MEM, 0); |
| 462 | if (!iomem) |
| 463 | return -EINVAL; |
| 464 | |
| 465 | tc6393xb = kzalloc(sizeof *tc6393xb, GFP_KERNEL); |
| 466 | if (!tc6393xb) { |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 467 | ret = -ENOMEM; |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 468 | goto err_kzalloc; |
| 469 | } |
| 470 | |
| 471 | spin_lock_init(&tc6393xb->lock); |
| 472 | |
| 473 | platform_set_drvdata(dev, tc6393xb); |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 474 | |
| 475 | ret = platform_get_irq(dev, 0); |
| 476 | if (ret >= 0) |
| 477 | tc6393xb->irq = ret; |
| 478 | else |
| 479 | goto err_noirq; |
| 480 | |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 481 | tc6393xb->iomem = iomem; |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 482 | tc6393xb->irq_base = tcpd->irq_base; |
| 483 | |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 484 | tc6393xb->clk = clk_get(&dev->dev, "CLK_CK3P6MI"); |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 485 | if (IS_ERR(tc6393xb->clk)) { |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 486 | ret = PTR_ERR(tc6393xb->clk); |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 487 | goto err_clk_get; |
| 488 | } |
| 489 | |
| 490 | rscr = &tc6393xb->rscr; |
| 491 | rscr->name = "tc6393xb-core"; |
| 492 | rscr->start = iomem->start; |
| 493 | rscr->end = iomem->start + 0xff; |
| 494 | rscr->flags = IORESOURCE_MEM; |
| 495 | |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 496 | ret = request_resource(iomem, rscr); |
| 497 | if (ret) |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 498 | goto err_request_scr; |
| 499 | |
| 500 | tc6393xb->scr = ioremap(rscr->start, rscr->end - rscr->start + 1); |
| 501 | if (!tc6393xb->scr) { |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 502 | ret = -ENOMEM; |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 503 | goto err_ioremap; |
| 504 | } |
| 505 | |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 506 | ret = clk_enable(tc6393xb->clk); |
| 507 | if (ret) |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 508 | goto err_clk_enable; |
| 509 | |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 510 | ret = tcpd->enable(dev); |
| 511 | if (ret) |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 512 | goto err_enable; |
| 513 | |
Dmitry Baryshkov | f98a0bd | 2008-09-24 23:46:10 +0200 | [diff] [blame] | 514 | iowrite8(0, tc6393xb->scr + SCR_FER); |
| 515 | iowrite16(tcpd->scr_pll2cr, tc6393xb->scr + SCR_PLL2CR); |
| 516 | iowrite16(SCR_CCR_UNK1 | SCR_CCR_HCLK_48, |
| 517 | tc6393xb->scr + SCR_CCR); |
| 518 | iowrite16(SCR_MCR_RDY_OPENDRAIN | SCR_MCR_RDY_UNK | SCR_MCR_RDY_EN | |
| 519 | SCR_MCR_INT_OPENDRAIN | SCR_MCR_INT_UNK | SCR_MCR_INT_EN | |
| 520 | BIT(15), tc6393xb->scr + SCR_MCR); |
| 521 | iowrite16(tcpd->scr_gper, tc6393xb->scr + SCR_GPER); |
| 522 | iowrite8(0, tc6393xb->scr + SCR_IRR); |
| 523 | iowrite8(0xbf, tc6393xb->scr + SCR_IMR); |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 524 | |
| 525 | printk(KERN_INFO "Toshiba tc6393xb revision %d at 0x%08lx, irq %d\n", |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 526 | tmio_ioread8(tc6393xb->scr + SCR_REVID), |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 527 | (unsigned long) iomem->start, tc6393xb->irq); |
| 528 | |
| 529 | tc6393xb->gpio.base = -1; |
| 530 | |
| 531 | if (tcpd->gpio_base >= 0) { |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 532 | ret = tc6393xb_register_gpio(tc6393xb, tcpd->gpio_base); |
| 533 | if (ret) |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 534 | goto err_gpio_add; |
| 535 | } |
| 536 | |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 537 | tc6393xb_attach_irq(dev); |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 538 | |
Dmitry Baryshkov | 1c1b6ff | 2008-09-24 23:36:23 +0200 | [diff] [blame] | 539 | if (tcpd->setup) { |
| 540 | ret = tcpd->setup(dev); |
| 541 | if (ret) |
| 542 | goto err_setup; |
| 543 | } |
| 544 | |
Dmitry Baryshkov | f024ff1 | 2008-06-27 10:37:57 +0100 | [diff] [blame] | 545 | tc6393xb_cells[TC6393XB_CELL_NAND].driver_data = tcpd->nand_data; |
Mike Rapoport | 56edb58 | 2008-07-29 01:23:32 +0200 | [diff] [blame] | 546 | tc6393xb_cells[TC6393XB_CELL_NAND].platform_data = |
| 547 | &tc6393xb_cells[TC6393XB_CELL_NAND]; |
| 548 | tc6393xb_cells[TC6393XB_CELL_NAND].data_size = |
| 549 | sizeof(tc6393xb_cells[TC6393XB_CELL_NAND]); |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 550 | tc6393xb_cells[TC6393XB_CELL_MMC].platform_data = |
| 551 | &tc6393xb_cells[TC6393XB_CELL_MMC]; |
| 552 | tc6393xb_cells[TC6393XB_CELL_MMC].data_size = |
| 553 | sizeof(tc6393xb_cells[TC6393XB_CELL_MMC]); |
Dmitry Baryshkov | f024ff1 | 2008-06-27 10:37:57 +0100 | [diff] [blame] | 554 | |
Dmitry Baryshkov | 51a5562 | 2008-10-03 20:11:36 +0200 | [diff] [blame^] | 555 | tc6393xb_cells[TC6393XB_CELL_OHCI].platform_data = |
| 556 | &tc6393xb_cells[TC6393XB_CELL_OHCI]; |
| 557 | tc6393xb_cells[TC6393XB_CELL_OHCI].data_size = |
| 558 | sizeof(tc6393xb_cells[TC6393XB_CELL_OHCI]); |
| 559 | |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 560 | |
| 561 | ret = mfd_add_devices(&dev->dev, dev->id, |
Dmitry Baryshkov | f024ff1 | 2008-06-27 10:37:57 +0100 | [diff] [blame] | 562 | tc6393xb_cells, ARRAY_SIZE(tc6393xb_cells), |
| 563 | iomem, tcpd->irq_base); |
| 564 | |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 565 | if (!ret) |
| 566 | return 0; |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 567 | |
Dmitry Baryshkov | 1c1b6ff | 2008-09-24 23:36:23 +0200 | [diff] [blame] | 568 | if (tcpd->teardown) |
| 569 | tcpd->teardown(dev); |
| 570 | |
| 571 | err_setup: |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 572 | tc6393xb_detach_irq(dev); |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 573 | |
| 574 | err_gpio_add: |
| 575 | if (tc6393xb->gpio.base != -1) |
| 576 | temp = gpiochip_remove(&tc6393xb->gpio); |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 577 | tcpd->disable(dev); |
| 578 | err_clk_enable: |
| 579 | clk_disable(tc6393xb->clk); |
| 580 | err_enable: |
| 581 | iounmap(tc6393xb->scr); |
| 582 | err_ioremap: |
| 583 | release_resource(&tc6393xb->rscr); |
| 584 | err_request_scr: |
| 585 | clk_put(tc6393xb->clk); |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 586 | err_noirq: |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 587 | err_clk_get: |
| 588 | kfree(tc6393xb); |
| 589 | err_kzalloc: |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 590 | return ret; |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | static int __devexit tc6393xb_remove(struct platform_device *dev) |
| 594 | { |
| 595 | struct tc6393xb_platform_data *tcpd = dev->dev.platform_data; |
| 596 | struct tc6393xb *tc6393xb = platform_get_drvdata(dev); |
| 597 | int ret; |
| 598 | |
Dmitry Baryshkov | 424f525 | 2008-07-29 01:30:26 +0200 | [diff] [blame] | 599 | mfd_remove_devices(&dev->dev); |
Dmitry Baryshkov | 1c1b6ff | 2008-09-24 23:36:23 +0200 | [diff] [blame] | 600 | |
| 601 | if (tcpd->teardown) |
| 602 | tcpd->teardown(dev); |
| 603 | |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 604 | tc6393xb_detach_irq(dev); |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 605 | |
| 606 | if (tc6393xb->gpio.base != -1) { |
| 607 | ret = gpiochip_remove(&tc6393xb->gpio); |
| 608 | if (ret) { |
| 609 | dev_err(&dev->dev, "Can't remove gpio chip: %d\n", ret); |
| 610 | return ret; |
| 611 | } |
| 612 | } |
| 613 | |
| 614 | ret = tcpd->disable(dev); |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 615 | clk_disable(tc6393xb->clk); |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 616 | iounmap(tc6393xb->scr); |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 617 | release_resource(&tc6393xb->rscr); |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 618 | platform_set_drvdata(dev, NULL); |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 619 | clk_put(tc6393xb->clk); |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 620 | kfree(tc6393xb); |
| 621 | |
| 622 | return ret; |
| 623 | } |
| 624 | |
| 625 | #ifdef CONFIG_PM |
| 626 | static int tc6393xb_suspend(struct platform_device *dev, pm_message_t state) |
| 627 | { |
| 628 | struct tc6393xb_platform_data *tcpd = dev->dev.platform_data; |
| 629 | struct tc6393xb *tc6393xb = platform_get_drvdata(dev); |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 630 | int i, ret; |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 631 | |
| 632 | tc6393xb->suspend_state.ccr = ioread16(tc6393xb->scr + SCR_CCR); |
| 633 | tc6393xb->suspend_state.fer = ioread8(tc6393xb->scr + SCR_FER); |
| 634 | |
| 635 | for (i = 0; i < 3; i++) { |
| 636 | tc6393xb->suspend_state.gpo_dsr[i] = |
| 637 | ioread8(tc6393xb->scr + SCR_GPO_DSR(i)); |
| 638 | tc6393xb->suspend_state.gpo_doecr[i] = |
| 639 | ioread8(tc6393xb->scr + SCR_GPO_DOECR(i)); |
| 640 | tc6393xb->suspend_state.gpi_bcr[i] = |
| 641 | ioread8(tc6393xb->scr + SCR_GPI_BCR(i)); |
| 642 | } |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 643 | ret = tcpd->suspend(dev); |
| 644 | clk_disable(tc6393xb->clk); |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 645 | |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 646 | return ret; |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | static int tc6393xb_resume(struct platform_device *dev) |
| 650 | { |
| 651 | struct tc6393xb_platform_data *tcpd = dev->dev.platform_data; |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 652 | struct tc6393xb *tc6393xb = platform_get_drvdata(dev); |
| 653 | int ret; |
Dmitry Baryshkov | f98a0bd | 2008-09-24 23:46:10 +0200 | [diff] [blame] | 654 | int i; |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 655 | |
| 656 | clk_enable(tc6393xb->clk); |
| 657 | |
| 658 | ret = tcpd->resume(dev); |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 659 | if (ret) |
| 660 | return ret; |
| 661 | |
Dmitry Baryshkov | f98a0bd | 2008-09-24 23:46:10 +0200 | [diff] [blame] | 662 | if (!tcpd->resume_restore) |
| 663 | return 0; |
| 664 | |
| 665 | iowrite8(tc6393xb->suspend_state.fer, tc6393xb->scr + SCR_FER); |
| 666 | iowrite16(tcpd->scr_pll2cr, tc6393xb->scr + SCR_PLL2CR); |
| 667 | iowrite16(tc6393xb->suspend_state.ccr, tc6393xb->scr + SCR_CCR); |
| 668 | iowrite16(SCR_MCR_RDY_OPENDRAIN | SCR_MCR_RDY_UNK | SCR_MCR_RDY_EN | |
| 669 | SCR_MCR_INT_OPENDRAIN | SCR_MCR_INT_UNK | SCR_MCR_INT_EN | |
| 670 | BIT(15), tc6393xb->scr + SCR_MCR); |
| 671 | iowrite16(tcpd->scr_gper, tc6393xb->scr + SCR_GPER); |
| 672 | iowrite8(0, tc6393xb->scr + SCR_IRR); |
| 673 | iowrite8(0xbf, tc6393xb->scr + SCR_IMR); |
| 674 | |
| 675 | for (i = 0; i < 3; i++) { |
| 676 | iowrite8(tc6393xb->suspend_state.gpo_dsr[i], |
| 677 | tc6393xb->scr + SCR_GPO_DSR(i)); |
| 678 | iowrite8(tc6393xb->suspend_state.gpo_doecr[i], |
| 679 | tc6393xb->scr + SCR_GPO_DOECR(i)); |
| 680 | iowrite8(tc6393xb->suspend_state.gpi_bcr[i], |
| 681 | tc6393xb->scr + SCR_GPI_BCR(i)); |
| 682 | } |
| 683 | |
| 684 | return 0; |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 685 | } |
| 686 | #else |
| 687 | #define tc6393xb_suspend NULL |
| 688 | #define tc6393xb_resume NULL |
| 689 | #endif |
| 690 | |
| 691 | static struct platform_driver tc6393xb_driver = { |
| 692 | .probe = tc6393xb_probe, |
| 693 | .remove = __devexit_p(tc6393xb_remove), |
| 694 | .suspend = tc6393xb_suspend, |
| 695 | .resume = tc6393xb_resume, |
| 696 | |
| 697 | .driver = { |
| 698 | .name = "tc6393xb", |
| 699 | .owner = THIS_MODULE, |
| 700 | }, |
| 701 | }; |
| 702 | |
| 703 | static int __init tc6393xb_init(void) |
| 704 | { |
| 705 | return platform_driver_register(&tc6393xb_driver); |
| 706 | } |
| 707 | |
| 708 | static void __exit tc6393xb_exit(void) |
| 709 | { |
| 710 | platform_driver_unregister(&tc6393xb_driver); |
| 711 | } |
| 712 | |
| 713 | subsys_initcall(tc6393xb_init); |
| 714 | module_exit(tc6393xb_exit); |
| 715 | |
Ian Molton | 25d6cbd8 | 2008-08-10 23:32:07 +0200 | [diff] [blame] | 716 | MODULE_LICENSE("GPL v2"); |
Dmitry Baryshkov | d631594 | 2008-06-22 12:01:58 +0100 | [diff] [blame] | 717 | MODULE_AUTHOR("Ian Molton, Dmitry Baryshkov and Dirk Opfer"); |
| 718 | MODULE_DESCRIPTION("tc6393xb Toshiba Mobile IO Controller"); |
| 719 | MODULE_ALIAS("platform:tc6393xb"); |