tc6393xb.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862
  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. #include <linux/kernel.h>
  17. #include <linux/module.h>
  18. #include <linux/io.h>
  19. #include <linux/irq.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/clk.h>
  22. #include <linux/err.h>
  23. #include <linux/mfd/core.h>
  24. #include <linux/mfd/tmio.h>
  25. #include <linux/mfd/tc6393xb.h>
  26. #include <linux/gpio.h>
  27. #include <linux/slab.h>
  28. #define SCR_REVID 0x08 /* b Revision ID */
  29. #define SCR_ISR 0x50 /* b Interrupt Status */
  30. #define SCR_IMR 0x52 /* b Interrupt Mask */
  31. #define SCR_IRR 0x54 /* b Interrupt Routing */
  32. #define SCR_GPER 0x60 /* w GP Enable */
  33. #define SCR_GPI_SR(i) (0x64 + (i)) /* b3 GPI Status */
  34. #define SCR_GPI_IMR(i) (0x68 + (i)) /* b3 GPI INT Mask */
  35. #define SCR_GPI_EDER(i) (0x6c + (i)) /* b3 GPI Edge Detect Enable */
  36. #define SCR_GPI_LIR(i) (0x70 + (i)) /* b3 GPI Level Invert */
  37. #define SCR_GPO_DSR(i) (0x78 + (i)) /* b3 GPO Data Set */
  38. #define SCR_GPO_DOECR(i) (0x7c + (i)) /* b3 GPO Data OE Control */
  39. #define SCR_GP_IARCR(i) (0x80 + (i)) /* b3 GP Internal Active Register Control */
  40. #define SCR_GP_IARLCR(i) (0x84 + (i)) /* b3 GP INTERNAL Active Register Level Control */
  41. #define SCR_GPI_BCR(i) (0x88 + (i)) /* b3 GPI Buffer Control */
  42. #define SCR_GPA_IARCR 0x8c /* w GPa Internal Active Register Control */
  43. #define SCR_GPA_IARLCR 0x90 /* w GPa Internal Active Register Level Control */
  44. #define SCR_GPA_BCR 0x94 /* w GPa Buffer Control */
  45. #define SCR_CCR 0x98 /* w Clock Control */
  46. #define SCR_PLL2CR 0x9a /* w PLL2 Control */
  47. #define SCR_PLL1CR 0x9c /* l PLL1 Control */
  48. #define SCR_DIARCR 0xa0 /* b Device Internal Active Register Control */
  49. #define SCR_DBOCR 0xa1 /* b Device Buffer Off Control */
  50. #define SCR_FER 0xe0 /* b Function Enable */
  51. #define SCR_MCR 0xe4 /* w Mode Control */
  52. #define SCR_CONFIG 0xfc /* b Configuration Control */
  53. #define SCR_DEBUG 0xff /* b Debug */
  54. #define SCR_CCR_CK32K BIT(0)
  55. #define SCR_CCR_USBCK BIT(1)
  56. #define SCR_CCR_UNK1 BIT(4)
  57. #define SCR_CCR_MCLK_MASK (7 << 8)
  58. #define SCR_CCR_MCLK_OFF (0 << 8)
  59. #define SCR_CCR_MCLK_12 (1 << 8)
  60. #define SCR_CCR_MCLK_24 (2 << 8)
  61. #define SCR_CCR_MCLK_48 (3 << 8)
  62. #define SCR_CCR_HCLK_MASK (3 << 12)
  63. #define SCR_CCR_HCLK_24 (0 << 12)
  64. #define SCR_CCR_HCLK_48 (1 << 12)
  65. #define SCR_FER_USBEN BIT(0) /* USB host enable */
  66. #define SCR_FER_LCDCVEN BIT(1) /* polysilicon TFT enable */
  67. #define SCR_FER_SLCDEN BIT(2) /* SLCD enable */
  68. #define SCR_MCR_RDY_MASK (3 << 0)
  69. #define SCR_MCR_RDY_OPENDRAIN (0 << 0)
  70. #define SCR_MCR_RDY_TRISTATE (1 << 0)
  71. #define SCR_MCR_RDY_PUSHPULL (2 << 0)
  72. #define SCR_MCR_RDY_UNK BIT(2)
  73. #define SCR_MCR_RDY_EN BIT(3)
  74. #define SCR_MCR_INT_MASK (3 << 4)
  75. #define SCR_MCR_INT_OPENDRAIN (0 << 4)
  76. #define SCR_MCR_INT_TRISTATE (1 << 4)
  77. #define SCR_MCR_INT_PUSHPULL (2 << 4)
  78. #define SCR_MCR_INT_UNK BIT(6)
  79. #define SCR_MCR_INT_EN BIT(7)
  80. /* bits 8 - 16 are unknown */
  81. #define TC_GPIO_BIT(i) (1 << (i & 0x7))
  82. /*--------------------------------------------------------------------------*/
  83. struct tc6393xb {
  84. void __iomem *scr;
  85. struct gpio_chip gpio;
  86. struct clk *clk; /* 3,6 Mhz */
  87. spinlock_t lock; /* protects RMW cycles */
  88. struct {
  89. u8 fer;
  90. u16 ccr;
  91. u8 gpi_bcr[3];
  92. u8 gpo_dsr[3];
  93. u8 gpo_doecr[3];
  94. } suspend_state;
  95. struct resource rscr;
  96. struct resource *iomem;
  97. int irq;
  98. int irq_base;
  99. };
  100. enum {
  101. TC6393XB_CELL_NAND,
  102. TC6393XB_CELL_MMC,
  103. TC6393XB_CELL_OHCI,
  104. TC6393XB_CELL_FB,
  105. };
  106. /*--------------------------------------------------------------------------*/
  107. static int tc6393xb_nand_enable(struct platform_device *nand)
  108. {
  109. struct platform_device *dev = to_platform_device(nand->dev.parent);
  110. struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
  111. unsigned long flags;
  112. spin_lock_irqsave(&tc6393xb->lock, flags);
  113. /* SMD buffer on */
  114. dev_dbg(&dev->dev, "SMD buffer on\n");
  115. tmio_iowrite8(0xff, tc6393xb->scr + SCR_GPI_BCR(1));
  116. spin_unlock_irqrestore(&tc6393xb->lock, flags);
  117. return 0;
  118. }
  119. static struct resource __devinitdata tc6393xb_nand_resources[] = {
  120. {
  121. .start = 0x1000,
  122. .end = 0x1007,
  123. .flags = IORESOURCE_MEM,
  124. },
  125. {
  126. .start = 0x0100,
  127. .end = 0x01ff,
  128. .flags = IORESOURCE_MEM,
  129. },
  130. {
  131. .start = IRQ_TC6393_NAND,
  132. .end = IRQ_TC6393_NAND,
  133. .flags = IORESOURCE_IRQ,
  134. },
  135. };
  136. static struct resource tc6393xb_mmc_resources[] = {
  137. {
  138. .start = 0x800,
  139. .end = 0x9ff,
  140. .flags = IORESOURCE_MEM,
  141. },
  142. {
  143. .start = IRQ_TC6393_MMC,
  144. .end = IRQ_TC6393_MMC,
  145. .flags = IORESOURCE_IRQ,
  146. },
  147. };
  148. static const struct resource tc6393xb_ohci_resources[] = {
  149. {
  150. .start = 0x3000,
  151. .end = 0x31ff,
  152. .flags = IORESOURCE_MEM,
  153. },
  154. {
  155. .start = 0x0300,
  156. .end = 0x03ff,
  157. .flags = IORESOURCE_MEM,
  158. },
  159. {
  160. .start = 0x010000,
  161. .end = 0x017fff,
  162. .flags = IORESOURCE_MEM,
  163. },
  164. {
  165. .start = 0x018000,
  166. .end = 0x01ffff,
  167. .flags = IORESOURCE_MEM,
  168. },
  169. {
  170. .start = IRQ_TC6393_OHCI,
  171. .end = IRQ_TC6393_OHCI,
  172. .flags = IORESOURCE_IRQ,
  173. },
  174. };
  175. static struct resource __devinitdata tc6393xb_fb_resources[] = {
  176. {
  177. .start = 0x5000,
  178. .end = 0x51ff,
  179. .flags = IORESOURCE_MEM,
  180. },
  181. {
  182. .start = 0x0500,
  183. .end = 0x05ff,
  184. .flags = IORESOURCE_MEM,
  185. },
  186. {
  187. .start = 0x100000,
  188. .end = 0x1fffff,
  189. .flags = IORESOURCE_MEM,
  190. },
  191. {
  192. .start = IRQ_TC6393_FB,
  193. .end = IRQ_TC6393_FB,
  194. .flags = IORESOURCE_IRQ,
  195. },
  196. };
  197. static int tc6393xb_ohci_enable(struct platform_device *dev)
  198. {
  199. struct tc6393xb *tc6393xb = dev_get_drvdata(dev->dev.parent);
  200. unsigned long flags;
  201. u16 ccr;
  202. u8 fer;
  203. spin_lock_irqsave(&tc6393xb->lock, flags);
  204. ccr = tmio_ioread16(tc6393xb->scr + SCR_CCR);
  205. ccr |= SCR_CCR_USBCK;
  206. tmio_iowrite16(ccr, tc6393xb->scr + SCR_CCR);
  207. fer = tmio_ioread8(tc6393xb->scr + SCR_FER);
  208. fer |= SCR_FER_USBEN;
  209. tmio_iowrite8(fer, tc6393xb->scr + SCR_FER);
  210. spin_unlock_irqrestore(&tc6393xb->lock, flags);
  211. return 0;
  212. }
  213. static int tc6393xb_ohci_disable(struct platform_device *dev)
  214. {
  215. struct tc6393xb *tc6393xb = dev_get_drvdata(dev->dev.parent);
  216. unsigned long flags;
  217. u16 ccr;
  218. u8 fer;
  219. spin_lock_irqsave(&tc6393xb->lock, flags);
  220. fer = tmio_ioread8(tc6393xb->scr + SCR_FER);
  221. fer &= ~SCR_FER_USBEN;
  222. tmio_iowrite8(fer, tc6393xb->scr + SCR_FER);
  223. ccr = tmio_ioread16(tc6393xb->scr + SCR_CCR);
  224. ccr &= ~SCR_CCR_USBCK;
  225. tmio_iowrite16(ccr, tc6393xb->scr + SCR_CCR);
  226. spin_unlock_irqrestore(&tc6393xb->lock, flags);
  227. return 0;
  228. }
  229. static int tc6393xb_fb_enable(struct platform_device *dev)
  230. {
  231. struct tc6393xb *tc6393xb = dev_get_drvdata(dev->dev.parent);
  232. unsigned long flags;
  233. u16 ccr;
  234. spin_lock_irqsave(&tc6393xb->lock, flags);
  235. ccr = tmio_ioread16(tc6393xb->scr + SCR_CCR);
  236. ccr &= ~SCR_CCR_MCLK_MASK;
  237. ccr |= SCR_CCR_MCLK_48;
  238. tmio_iowrite16(ccr, tc6393xb->scr + SCR_CCR);
  239. spin_unlock_irqrestore(&tc6393xb->lock, flags);
  240. return 0;
  241. }
  242. static int tc6393xb_fb_disable(struct platform_device *dev)
  243. {
  244. struct tc6393xb *tc6393xb = dev_get_drvdata(dev->dev.parent);
  245. unsigned long flags;
  246. u16 ccr;
  247. spin_lock_irqsave(&tc6393xb->lock, flags);
  248. ccr = tmio_ioread16(tc6393xb->scr + SCR_CCR);
  249. ccr &= ~SCR_CCR_MCLK_MASK;
  250. ccr |= SCR_CCR_MCLK_OFF;
  251. tmio_iowrite16(ccr, tc6393xb->scr + SCR_CCR);
  252. spin_unlock_irqrestore(&tc6393xb->lock, flags);
  253. return 0;
  254. }
  255. int tc6393xb_lcd_set_power(struct platform_device *fb, bool on)
  256. {
  257. struct platform_device *dev = to_platform_device(fb->dev.parent);
  258. struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
  259. u8 fer;
  260. unsigned long flags;
  261. spin_lock_irqsave(&tc6393xb->lock, flags);
  262. fer = ioread8(tc6393xb->scr + SCR_FER);
  263. if (on)
  264. fer |= SCR_FER_SLCDEN;
  265. else
  266. fer &= ~SCR_FER_SLCDEN;
  267. iowrite8(fer, tc6393xb->scr + SCR_FER);
  268. spin_unlock_irqrestore(&tc6393xb->lock, flags);
  269. return 0;
  270. }
  271. EXPORT_SYMBOL(tc6393xb_lcd_set_power);
  272. int tc6393xb_lcd_mode(struct platform_device *fb,
  273. const struct fb_videomode *mode) {
  274. struct platform_device *dev = to_platform_device(fb->dev.parent);
  275. struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
  276. unsigned long flags;
  277. spin_lock_irqsave(&tc6393xb->lock, flags);
  278. iowrite16(mode->pixclock, tc6393xb->scr + SCR_PLL1CR + 0);
  279. iowrite16(mode->pixclock >> 16, tc6393xb->scr + SCR_PLL1CR + 2);
  280. spin_unlock_irqrestore(&tc6393xb->lock, flags);
  281. return 0;
  282. }
  283. EXPORT_SYMBOL(tc6393xb_lcd_mode);
  284. static int tc6393xb_mmc_enable(struct platform_device *mmc)
  285. {
  286. struct platform_device *dev = to_platform_device(mmc->dev.parent);
  287. struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
  288. tmio_core_mmc_enable(tc6393xb->scr + 0x200, 0,
  289. tc6393xb_mmc_resources[0].start & 0xfffe);
  290. return 0;
  291. }
  292. static int tc6393xb_mmc_resume(struct platform_device *mmc)
  293. {
  294. struct platform_device *dev = to_platform_device(mmc->dev.parent);
  295. struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
  296. tmio_core_mmc_resume(tc6393xb->scr + 0x200, 0,
  297. tc6393xb_mmc_resources[0].start & 0xfffe);
  298. return 0;
  299. }
  300. static void tc6393xb_mmc_pwr(struct platform_device *mmc, int state)
  301. {
  302. struct platform_device *dev = to_platform_device(mmc->dev.parent);
  303. struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
  304. tmio_core_mmc_pwr(tc6393xb->scr + 0x200, 0, state);
  305. }
  306. static void tc6393xb_mmc_clk_div(struct platform_device *mmc, int state)
  307. {
  308. struct platform_device *dev = to_platform_device(mmc->dev.parent);
  309. struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
  310. tmio_core_mmc_clk_div(tc6393xb->scr + 0x200, 0, state);
  311. }
  312. static struct tmio_mmc_data tc6393xb_mmc_data = {
  313. .hclk = 24000000,
  314. .set_pwr = tc6393xb_mmc_pwr,
  315. .set_clk_div = tc6393xb_mmc_clk_div,
  316. };
  317. static struct mfd_cell __devinitdata tc6393xb_cells[] = {
  318. [TC6393XB_CELL_NAND] = {
  319. .name = "tmio-nand",
  320. .enable = tc6393xb_nand_enable,
  321. .num_resources = ARRAY_SIZE(tc6393xb_nand_resources),
  322. .resources = tc6393xb_nand_resources,
  323. },
  324. [TC6393XB_CELL_MMC] = {
  325. .name = "tmio-mmc",
  326. .enable = tc6393xb_mmc_enable,
  327. .resume = tc6393xb_mmc_resume,
  328. .platform_data = &tc6393xb_mmc_data,
  329. .pdata_size = sizeof(tc6393xb_mmc_data),
  330. .num_resources = ARRAY_SIZE(tc6393xb_mmc_resources),
  331. .resources = tc6393xb_mmc_resources,
  332. },
  333. [TC6393XB_CELL_OHCI] = {
  334. .name = "tmio-ohci",
  335. .num_resources = ARRAY_SIZE(tc6393xb_ohci_resources),
  336. .resources = tc6393xb_ohci_resources,
  337. .enable = tc6393xb_ohci_enable,
  338. .suspend = tc6393xb_ohci_disable,
  339. .resume = tc6393xb_ohci_enable,
  340. .disable = tc6393xb_ohci_disable,
  341. },
  342. [TC6393XB_CELL_FB] = {
  343. .name = "tmio-fb",
  344. .num_resources = ARRAY_SIZE(tc6393xb_fb_resources),
  345. .resources = tc6393xb_fb_resources,
  346. .enable = tc6393xb_fb_enable,
  347. .suspend = tc6393xb_fb_disable,
  348. .resume = tc6393xb_fb_enable,
  349. .disable = tc6393xb_fb_disable,
  350. },
  351. };
  352. /*--------------------------------------------------------------------------*/
  353. static int tc6393xb_gpio_get(struct gpio_chip *chip,
  354. unsigned offset)
  355. {
  356. struct tc6393xb *tc6393xb = container_of(chip, struct tc6393xb, gpio);
  357. /* XXX: does dsr also represent inputs? */
  358. return tmio_ioread8(tc6393xb->scr + SCR_GPO_DSR(offset / 8))
  359. & TC_GPIO_BIT(offset);
  360. }
  361. static void __tc6393xb_gpio_set(struct gpio_chip *chip,
  362. unsigned offset, int value)
  363. {
  364. struct tc6393xb *tc6393xb = container_of(chip, struct tc6393xb, gpio);
  365. u8 dsr;
  366. dsr = tmio_ioread8(tc6393xb->scr + SCR_GPO_DSR(offset / 8));
  367. if (value)
  368. dsr |= TC_GPIO_BIT(offset);
  369. else
  370. dsr &= ~TC_GPIO_BIT(offset);
  371. tmio_iowrite8(dsr, tc6393xb->scr + SCR_GPO_DSR(offset / 8));
  372. }
  373. static void tc6393xb_gpio_set(struct gpio_chip *chip,
  374. unsigned offset, int value)
  375. {
  376. struct tc6393xb *tc6393xb = container_of(chip, struct tc6393xb, gpio);
  377. unsigned long flags;
  378. spin_lock_irqsave(&tc6393xb->lock, flags);
  379. __tc6393xb_gpio_set(chip, offset, value);
  380. spin_unlock_irqrestore(&tc6393xb->lock, flags);
  381. }
  382. static int tc6393xb_gpio_direction_input(struct gpio_chip *chip,
  383. unsigned offset)
  384. {
  385. struct tc6393xb *tc6393xb = container_of(chip, struct tc6393xb, gpio);
  386. unsigned long flags;
  387. u8 doecr;
  388. spin_lock_irqsave(&tc6393xb->lock, flags);
  389. doecr = tmio_ioread8(tc6393xb->scr + SCR_GPO_DOECR(offset / 8));
  390. doecr &= ~TC_GPIO_BIT(offset);
  391. tmio_iowrite8(doecr, tc6393xb->scr + SCR_GPO_DOECR(offset / 8));
  392. spin_unlock_irqrestore(&tc6393xb->lock, flags);
  393. return 0;
  394. }
  395. static int tc6393xb_gpio_direction_output(struct gpio_chip *chip,
  396. unsigned offset, int value)
  397. {
  398. struct tc6393xb *tc6393xb = container_of(chip, struct tc6393xb, gpio);
  399. unsigned long flags;
  400. u8 doecr;
  401. spin_lock_irqsave(&tc6393xb->lock, flags);
  402. __tc6393xb_gpio_set(chip, offset, value);
  403. doecr = tmio_ioread8(tc6393xb->scr + SCR_GPO_DOECR(offset / 8));
  404. doecr |= TC_GPIO_BIT(offset);
  405. tmio_iowrite8(doecr, tc6393xb->scr + SCR_GPO_DOECR(offset / 8));
  406. spin_unlock_irqrestore(&tc6393xb->lock, flags);
  407. return 0;
  408. }
  409. static int tc6393xb_register_gpio(struct tc6393xb *tc6393xb, int gpio_base)
  410. {
  411. tc6393xb->gpio.label = "tc6393xb";
  412. tc6393xb->gpio.base = gpio_base;
  413. tc6393xb->gpio.ngpio = 16;
  414. tc6393xb->gpio.set = tc6393xb_gpio_set;
  415. tc6393xb->gpio.get = tc6393xb_gpio_get;
  416. tc6393xb->gpio.direction_input = tc6393xb_gpio_direction_input;
  417. tc6393xb->gpio.direction_output = tc6393xb_gpio_direction_output;
  418. return gpiochip_add(&tc6393xb->gpio);
  419. }
  420. /*--------------------------------------------------------------------------*/
  421. static void
  422. tc6393xb_irq(unsigned int irq, struct irq_desc *desc)
  423. {
  424. struct tc6393xb *tc6393xb = irq_get_handler_data(irq);
  425. unsigned int isr;
  426. unsigned int i, irq_base;
  427. irq_base = tc6393xb->irq_base;
  428. while ((isr = tmio_ioread8(tc6393xb->scr + SCR_ISR) &
  429. ~tmio_ioread8(tc6393xb->scr + SCR_IMR)))
  430. for (i = 0; i < TC6393XB_NR_IRQS; i++) {
  431. if (isr & (1 << i))
  432. generic_handle_irq(irq_base + i);
  433. }
  434. }
  435. static void tc6393xb_irq_ack(struct irq_data *data)
  436. {
  437. }
  438. static void tc6393xb_irq_mask(struct irq_data *data)
  439. {
  440. struct tc6393xb *tc6393xb = irq_data_get_irq_chip_data(data);
  441. unsigned long flags;
  442. u8 imr;
  443. spin_lock_irqsave(&tc6393xb->lock, flags);
  444. imr = tmio_ioread8(tc6393xb->scr + SCR_IMR);
  445. imr |= 1 << (data->irq - tc6393xb->irq_base);
  446. tmio_iowrite8(imr, tc6393xb->scr + SCR_IMR);
  447. spin_unlock_irqrestore(&tc6393xb->lock, flags);
  448. }
  449. static void tc6393xb_irq_unmask(struct irq_data *data)
  450. {
  451. struct tc6393xb *tc6393xb = irq_data_get_irq_chip_data(data);
  452. unsigned long flags;
  453. u8 imr;
  454. spin_lock_irqsave(&tc6393xb->lock, flags);
  455. imr = tmio_ioread8(tc6393xb->scr + SCR_IMR);
  456. imr &= ~(1 << (data->irq - tc6393xb->irq_base));
  457. tmio_iowrite8(imr, tc6393xb->scr + SCR_IMR);
  458. spin_unlock_irqrestore(&tc6393xb->lock, flags);
  459. }
  460. static struct irq_chip tc6393xb_chip = {
  461. .name = "tc6393xb",
  462. .irq_ack = tc6393xb_irq_ack,
  463. .irq_mask = tc6393xb_irq_mask,
  464. .irq_unmask = tc6393xb_irq_unmask,
  465. };
  466. static void tc6393xb_attach_irq(struct platform_device *dev)
  467. {
  468. struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
  469. unsigned int irq, irq_base;
  470. irq_base = tc6393xb->irq_base;
  471. for (irq = irq_base; irq < irq_base + TC6393XB_NR_IRQS; irq++) {
  472. irq_set_chip_and_handler(irq, &tc6393xb_chip, handle_edge_irq);
  473. irq_set_chip_data(irq, tc6393xb);
  474. set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
  475. }
  476. irq_set_irq_type(tc6393xb->irq, IRQ_TYPE_EDGE_FALLING);
  477. irq_set_handler_data(tc6393xb->irq, tc6393xb);
  478. irq_set_chained_handler(tc6393xb->irq, tc6393xb_irq);
  479. }
  480. static void tc6393xb_detach_irq(struct platform_device *dev)
  481. {
  482. struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
  483. unsigned int irq, irq_base;
  484. irq_set_chained_handler(tc6393xb->irq, NULL);
  485. irq_set_handler_data(tc6393xb->irq, NULL);
  486. irq_base = tc6393xb->irq_base;
  487. for (irq = irq_base; irq < irq_base + TC6393XB_NR_IRQS; irq++) {
  488. set_irq_flags(irq, 0);
  489. irq_set_chip(irq, NULL);
  490. irq_set_chip_data(irq, NULL);
  491. }
  492. }
  493. /*--------------------------------------------------------------------------*/
  494. static int __devinit tc6393xb_probe(struct platform_device *dev)
  495. {
  496. struct tc6393xb_platform_data *tcpd = dev->dev.platform_data;
  497. struct tc6393xb *tc6393xb;
  498. struct resource *iomem, *rscr;
  499. int ret, temp;
  500. iomem = platform_get_resource(dev, IORESOURCE_MEM, 0);
  501. if (!iomem)
  502. return -EINVAL;
  503. tc6393xb = kzalloc(sizeof *tc6393xb, GFP_KERNEL);
  504. if (!tc6393xb) {
  505. ret = -ENOMEM;
  506. goto err_kzalloc;
  507. }
  508. spin_lock_init(&tc6393xb->lock);
  509. platform_set_drvdata(dev, tc6393xb);
  510. ret = platform_get_irq(dev, 0);
  511. if (ret >= 0)
  512. tc6393xb->irq = ret;
  513. else
  514. goto err_noirq;
  515. tc6393xb->iomem = iomem;
  516. tc6393xb->irq_base = tcpd->irq_base;
  517. tc6393xb->clk = clk_get(&dev->dev, "CLK_CK3P6MI");
  518. if (IS_ERR(tc6393xb->clk)) {
  519. ret = PTR_ERR(tc6393xb->clk);
  520. goto err_clk_get;
  521. }
  522. rscr = &tc6393xb->rscr;
  523. rscr->name = "tc6393xb-core";
  524. rscr->start = iomem->start;
  525. rscr->end = iomem->start + 0xff;
  526. rscr->flags = IORESOURCE_MEM;
  527. ret = request_resource(iomem, rscr);
  528. if (ret)
  529. goto err_request_scr;
  530. tc6393xb->scr = ioremap(rscr->start, resource_size(rscr));
  531. if (!tc6393xb->scr) {
  532. ret = -ENOMEM;
  533. goto err_ioremap;
  534. }
  535. ret = clk_enable(tc6393xb->clk);
  536. if (ret)
  537. goto err_clk_enable;
  538. ret = tcpd->enable(dev);
  539. if (ret)
  540. goto err_enable;
  541. iowrite8(0, tc6393xb->scr + SCR_FER);
  542. iowrite16(tcpd->scr_pll2cr, tc6393xb->scr + SCR_PLL2CR);
  543. iowrite16(SCR_CCR_UNK1 | SCR_CCR_HCLK_48,
  544. tc6393xb->scr + SCR_CCR);
  545. iowrite16(SCR_MCR_RDY_OPENDRAIN | SCR_MCR_RDY_UNK | SCR_MCR_RDY_EN |
  546. SCR_MCR_INT_OPENDRAIN | SCR_MCR_INT_UNK | SCR_MCR_INT_EN |
  547. BIT(15), tc6393xb->scr + SCR_MCR);
  548. iowrite16(tcpd->scr_gper, tc6393xb->scr + SCR_GPER);
  549. iowrite8(0, tc6393xb->scr + SCR_IRR);
  550. iowrite8(0xbf, tc6393xb->scr + SCR_IMR);
  551. printk(KERN_INFO "Toshiba tc6393xb revision %d at 0x%08lx, irq %d\n",
  552. tmio_ioread8(tc6393xb->scr + SCR_REVID),
  553. (unsigned long) iomem->start, tc6393xb->irq);
  554. tc6393xb->gpio.base = -1;
  555. if (tcpd->gpio_base >= 0) {
  556. ret = tc6393xb_register_gpio(tc6393xb, tcpd->gpio_base);
  557. if (ret)
  558. goto err_gpio_add;
  559. }
  560. tc6393xb_attach_irq(dev);
  561. if (tcpd->setup) {
  562. ret = tcpd->setup(dev);
  563. if (ret)
  564. goto err_setup;
  565. }
  566. tc6393xb_cells[TC6393XB_CELL_NAND].platform_data = tcpd->nand_data;
  567. tc6393xb_cells[TC6393XB_CELL_NAND].pdata_size =
  568. sizeof(*tcpd->nand_data);
  569. tc6393xb_cells[TC6393XB_CELL_FB].platform_data = tcpd->fb_data;
  570. tc6393xb_cells[TC6393XB_CELL_FB].pdata_size = sizeof(*tcpd->fb_data);
  571. ret = mfd_add_devices(&dev->dev, dev->id,
  572. tc6393xb_cells, ARRAY_SIZE(tc6393xb_cells),
  573. iomem, tcpd->irq_base);
  574. if (!ret)
  575. return 0;
  576. if (tcpd->teardown)
  577. tcpd->teardown(dev);
  578. err_setup:
  579. tc6393xb_detach_irq(dev);
  580. err_gpio_add:
  581. if (tc6393xb->gpio.base != -1)
  582. temp = gpiochip_remove(&tc6393xb->gpio);
  583. tcpd->disable(dev);
  584. err_enable:
  585. clk_disable(tc6393xb->clk);
  586. err_clk_enable:
  587. iounmap(tc6393xb->scr);
  588. err_ioremap:
  589. release_resource(&tc6393xb->rscr);
  590. err_request_scr:
  591. clk_put(tc6393xb->clk);
  592. err_noirq:
  593. err_clk_get:
  594. kfree(tc6393xb);
  595. err_kzalloc:
  596. return ret;
  597. }
  598. static int __devexit tc6393xb_remove(struct platform_device *dev)
  599. {
  600. struct tc6393xb_platform_data *tcpd = dev->dev.platform_data;
  601. struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
  602. int ret;
  603. mfd_remove_devices(&dev->dev);
  604. if (tcpd->teardown)
  605. tcpd->teardown(dev);
  606. tc6393xb_detach_irq(dev);
  607. if (tc6393xb->gpio.base != -1) {
  608. ret = gpiochip_remove(&tc6393xb->gpio);
  609. if (ret) {
  610. dev_err(&dev->dev, "Can't remove gpio chip: %d\n", ret);
  611. return ret;
  612. }
  613. }
  614. ret = tcpd->disable(dev);
  615. clk_disable(tc6393xb->clk);
  616. iounmap(tc6393xb->scr);
  617. release_resource(&tc6393xb->rscr);
  618. platform_set_drvdata(dev, NULL);
  619. clk_put(tc6393xb->clk);
  620. kfree(tc6393xb);
  621. return ret;
  622. }
  623. #ifdef CONFIG_PM
  624. static int tc6393xb_suspend(struct platform_device *dev, pm_message_t state)
  625. {
  626. struct tc6393xb_platform_data *tcpd = dev->dev.platform_data;
  627. struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
  628. int i, ret;
  629. tc6393xb->suspend_state.ccr = ioread16(tc6393xb->scr + SCR_CCR);
  630. tc6393xb->suspend_state.fer = ioread8(tc6393xb->scr + SCR_FER);
  631. for (i = 0; i < 3; i++) {
  632. tc6393xb->suspend_state.gpo_dsr[i] =
  633. ioread8(tc6393xb->scr + SCR_GPO_DSR(i));
  634. tc6393xb->suspend_state.gpo_doecr[i] =
  635. ioread8(tc6393xb->scr + SCR_GPO_DOECR(i));
  636. tc6393xb->suspend_state.gpi_bcr[i] =
  637. ioread8(tc6393xb->scr + SCR_GPI_BCR(i));
  638. }
  639. ret = tcpd->suspend(dev);
  640. clk_disable(tc6393xb->clk);
  641. return ret;
  642. }
  643. static int tc6393xb_resume(struct platform_device *dev)
  644. {
  645. struct tc6393xb_platform_data *tcpd = dev->dev.platform_data;
  646. struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
  647. int ret;
  648. int i;
  649. clk_enable(tc6393xb->clk);
  650. ret = tcpd->resume(dev);
  651. if (ret)
  652. return ret;
  653. if (!tcpd->resume_restore)
  654. return 0;
  655. iowrite8(tc6393xb->suspend_state.fer, tc6393xb->scr + SCR_FER);
  656. iowrite16(tcpd->scr_pll2cr, tc6393xb->scr + SCR_PLL2CR);
  657. iowrite16(tc6393xb->suspend_state.ccr, tc6393xb->scr + SCR_CCR);
  658. iowrite16(SCR_MCR_RDY_OPENDRAIN | SCR_MCR_RDY_UNK | SCR_MCR_RDY_EN |
  659. SCR_MCR_INT_OPENDRAIN | SCR_MCR_INT_UNK | SCR_MCR_INT_EN |
  660. BIT(15), tc6393xb->scr + SCR_MCR);
  661. iowrite16(tcpd->scr_gper, tc6393xb->scr + SCR_GPER);
  662. iowrite8(0, tc6393xb->scr + SCR_IRR);
  663. iowrite8(0xbf, tc6393xb->scr + SCR_IMR);
  664. for (i = 0; i < 3; i++) {
  665. iowrite8(tc6393xb->suspend_state.gpo_dsr[i],
  666. tc6393xb->scr + SCR_GPO_DSR(i));
  667. iowrite8(tc6393xb->suspend_state.gpo_doecr[i],
  668. tc6393xb->scr + SCR_GPO_DOECR(i));
  669. iowrite8(tc6393xb->suspend_state.gpi_bcr[i],
  670. tc6393xb->scr + SCR_GPI_BCR(i));
  671. }
  672. return 0;
  673. }
  674. #else
  675. #define tc6393xb_suspend NULL
  676. #define tc6393xb_resume NULL
  677. #endif
  678. static struct platform_driver tc6393xb_driver = {
  679. .probe = tc6393xb_probe,
  680. .remove = __devexit_p(tc6393xb_remove),
  681. .suspend = tc6393xb_suspend,
  682. .resume = tc6393xb_resume,
  683. .driver = {
  684. .name = "tc6393xb",
  685. .owner = THIS_MODULE,
  686. },
  687. };
  688. static int __init tc6393xb_init(void)
  689. {
  690. return platform_driver_register(&tc6393xb_driver);
  691. }
  692. static void __exit tc6393xb_exit(void)
  693. {
  694. platform_driver_unregister(&tc6393xb_driver);
  695. }
  696. subsys_initcall(tc6393xb_init);
  697. module_exit(tc6393xb_exit);
  698. MODULE_LICENSE("GPL v2");
  699. MODULE_AUTHOR("Ian Molton, Dmitry Baryshkov and Dirk Opfer");
  700. MODULE_DESCRIPTION("tc6393xb Toshiba Mobile IO Controller");
  701. MODULE_ALIAS("platform:tc6393xb");