tc6393xb.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  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_ohci_suspend(struct platform_device *dev)
  230. {
  231. struct tc6393xb_platform_data *tcpd = dev_get_platdata(dev->dev.parent);
  232. /* We can't properly store/restore OHCI state, so fail here */
  233. if (tcpd->resume_restore)
  234. return -EBUSY;
  235. return tc6393xb_ohci_disable(dev);
  236. }
  237. static int tc6393xb_fb_enable(struct platform_device *dev)
  238. {
  239. struct tc6393xb *tc6393xb = dev_get_drvdata(dev->dev.parent);
  240. unsigned long flags;
  241. u16 ccr;
  242. spin_lock_irqsave(&tc6393xb->lock, flags);
  243. ccr = tmio_ioread16(tc6393xb->scr + SCR_CCR);
  244. ccr &= ~SCR_CCR_MCLK_MASK;
  245. ccr |= SCR_CCR_MCLK_48;
  246. tmio_iowrite16(ccr, tc6393xb->scr + SCR_CCR);
  247. spin_unlock_irqrestore(&tc6393xb->lock, flags);
  248. return 0;
  249. }
  250. static int tc6393xb_fb_disable(struct platform_device *dev)
  251. {
  252. struct tc6393xb *tc6393xb = dev_get_drvdata(dev->dev.parent);
  253. unsigned long flags;
  254. u16 ccr;
  255. spin_lock_irqsave(&tc6393xb->lock, flags);
  256. ccr = tmio_ioread16(tc6393xb->scr + SCR_CCR);
  257. ccr &= ~SCR_CCR_MCLK_MASK;
  258. ccr |= SCR_CCR_MCLK_OFF;
  259. tmio_iowrite16(ccr, tc6393xb->scr + SCR_CCR);
  260. spin_unlock_irqrestore(&tc6393xb->lock, flags);
  261. return 0;
  262. }
  263. int tc6393xb_lcd_set_power(struct platform_device *fb, bool on)
  264. {
  265. struct platform_device *dev = to_platform_device(fb->dev.parent);
  266. struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
  267. u8 fer;
  268. unsigned long flags;
  269. spin_lock_irqsave(&tc6393xb->lock, flags);
  270. fer = ioread8(tc6393xb->scr + SCR_FER);
  271. if (on)
  272. fer |= SCR_FER_SLCDEN;
  273. else
  274. fer &= ~SCR_FER_SLCDEN;
  275. iowrite8(fer, tc6393xb->scr + SCR_FER);
  276. spin_unlock_irqrestore(&tc6393xb->lock, flags);
  277. return 0;
  278. }
  279. EXPORT_SYMBOL(tc6393xb_lcd_set_power);
  280. int tc6393xb_lcd_mode(struct platform_device *fb,
  281. const struct fb_videomode *mode) {
  282. struct platform_device *dev = to_platform_device(fb->dev.parent);
  283. struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
  284. unsigned long flags;
  285. spin_lock_irqsave(&tc6393xb->lock, flags);
  286. iowrite16(mode->pixclock, tc6393xb->scr + SCR_PLL1CR + 0);
  287. iowrite16(mode->pixclock >> 16, tc6393xb->scr + SCR_PLL1CR + 2);
  288. spin_unlock_irqrestore(&tc6393xb->lock, flags);
  289. return 0;
  290. }
  291. EXPORT_SYMBOL(tc6393xb_lcd_mode);
  292. static int tc6393xb_mmc_enable(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_enable(tc6393xb->scr + 0x200, 0,
  297. tc6393xb_mmc_resources[0].start & 0xfffe);
  298. return 0;
  299. }
  300. static int tc6393xb_mmc_resume(struct platform_device *mmc)
  301. {
  302. struct platform_device *dev = to_platform_device(mmc->dev.parent);
  303. struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
  304. tmio_core_mmc_resume(tc6393xb->scr + 0x200, 0,
  305. tc6393xb_mmc_resources[0].start & 0xfffe);
  306. return 0;
  307. }
  308. static void tc6393xb_mmc_pwr(struct platform_device *mmc, int state)
  309. {
  310. struct platform_device *dev = to_platform_device(mmc->dev.parent);
  311. struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
  312. tmio_core_mmc_pwr(tc6393xb->scr + 0x200, 0, state);
  313. }
  314. static void tc6393xb_mmc_clk_div(struct platform_device *mmc, int state)
  315. {
  316. struct platform_device *dev = to_platform_device(mmc->dev.parent);
  317. struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
  318. tmio_core_mmc_clk_div(tc6393xb->scr + 0x200, 0, state);
  319. }
  320. static struct tmio_mmc_data tc6393xb_mmc_data = {
  321. .hclk = 24000000,
  322. .set_pwr = tc6393xb_mmc_pwr,
  323. .set_clk_div = tc6393xb_mmc_clk_div,
  324. };
  325. static struct mfd_cell __devinitdata tc6393xb_cells[] = {
  326. [TC6393XB_CELL_NAND] = {
  327. .name = "tmio-nand",
  328. .enable = tc6393xb_nand_enable,
  329. .num_resources = ARRAY_SIZE(tc6393xb_nand_resources),
  330. .resources = tc6393xb_nand_resources,
  331. },
  332. [TC6393XB_CELL_MMC] = {
  333. .name = "tmio-mmc",
  334. .enable = tc6393xb_mmc_enable,
  335. .resume = tc6393xb_mmc_resume,
  336. .platform_data = &tc6393xb_mmc_data,
  337. .pdata_size = sizeof(tc6393xb_mmc_data),
  338. .num_resources = ARRAY_SIZE(tc6393xb_mmc_resources),
  339. .resources = tc6393xb_mmc_resources,
  340. },
  341. [TC6393XB_CELL_OHCI] = {
  342. .name = "tmio-ohci",
  343. .num_resources = ARRAY_SIZE(tc6393xb_ohci_resources),
  344. .resources = tc6393xb_ohci_resources,
  345. .enable = tc6393xb_ohci_enable,
  346. .suspend = tc6393xb_ohci_suspend,
  347. .resume = tc6393xb_ohci_enable,
  348. .disable = tc6393xb_ohci_disable,
  349. },
  350. [TC6393XB_CELL_FB] = {
  351. .name = "tmio-fb",
  352. .num_resources = ARRAY_SIZE(tc6393xb_fb_resources),
  353. .resources = tc6393xb_fb_resources,
  354. .enable = tc6393xb_fb_enable,
  355. .suspend = tc6393xb_fb_disable,
  356. .resume = tc6393xb_fb_enable,
  357. .disable = tc6393xb_fb_disable,
  358. },
  359. };
  360. /*--------------------------------------------------------------------------*/
  361. static int tc6393xb_gpio_get(struct gpio_chip *chip,
  362. unsigned offset)
  363. {
  364. struct tc6393xb *tc6393xb = container_of(chip, struct tc6393xb, gpio);
  365. /* XXX: does dsr also represent inputs? */
  366. return tmio_ioread8(tc6393xb->scr + SCR_GPO_DSR(offset / 8))
  367. & TC_GPIO_BIT(offset);
  368. }
  369. static void __tc6393xb_gpio_set(struct gpio_chip *chip,
  370. unsigned offset, int value)
  371. {
  372. struct tc6393xb *tc6393xb = container_of(chip, struct tc6393xb, gpio);
  373. u8 dsr;
  374. dsr = tmio_ioread8(tc6393xb->scr + SCR_GPO_DSR(offset / 8));
  375. if (value)
  376. dsr |= TC_GPIO_BIT(offset);
  377. else
  378. dsr &= ~TC_GPIO_BIT(offset);
  379. tmio_iowrite8(dsr, tc6393xb->scr + SCR_GPO_DSR(offset / 8));
  380. }
  381. static void tc6393xb_gpio_set(struct gpio_chip *chip,
  382. unsigned offset, int value)
  383. {
  384. struct tc6393xb *tc6393xb = container_of(chip, struct tc6393xb, gpio);
  385. unsigned long flags;
  386. spin_lock_irqsave(&tc6393xb->lock, flags);
  387. __tc6393xb_gpio_set(chip, offset, value);
  388. spin_unlock_irqrestore(&tc6393xb->lock, flags);
  389. }
  390. static int tc6393xb_gpio_direction_input(struct gpio_chip *chip,
  391. unsigned offset)
  392. {
  393. struct tc6393xb *tc6393xb = container_of(chip, struct tc6393xb, gpio);
  394. unsigned long flags;
  395. u8 doecr;
  396. spin_lock_irqsave(&tc6393xb->lock, flags);
  397. doecr = tmio_ioread8(tc6393xb->scr + SCR_GPO_DOECR(offset / 8));
  398. doecr &= ~TC_GPIO_BIT(offset);
  399. tmio_iowrite8(doecr, tc6393xb->scr + SCR_GPO_DOECR(offset / 8));
  400. spin_unlock_irqrestore(&tc6393xb->lock, flags);
  401. return 0;
  402. }
  403. static int tc6393xb_gpio_direction_output(struct gpio_chip *chip,
  404. unsigned offset, int value)
  405. {
  406. struct tc6393xb *tc6393xb = container_of(chip, struct tc6393xb, gpio);
  407. unsigned long flags;
  408. u8 doecr;
  409. spin_lock_irqsave(&tc6393xb->lock, flags);
  410. __tc6393xb_gpio_set(chip, offset, value);
  411. doecr = tmio_ioread8(tc6393xb->scr + SCR_GPO_DOECR(offset / 8));
  412. doecr |= TC_GPIO_BIT(offset);
  413. tmio_iowrite8(doecr, tc6393xb->scr + SCR_GPO_DOECR(offset / 8));
  414. spin_unlock_irqrestore(&tc6393xb->lock, flags);
  415. return 0;
  416. }
  417. static int tc6393xb_register_gpio(struct tc6393xb *tc6393xb, int gpio_base)
  418. {
  419. tc6393xb->gpio.label = "tc6393xb";
  420. tc6393xb->gpio.base = gpio_base;
  421. tc6393xb->gpio.ngpio = 16;
  422. tc6393xb->gpio.set = tc6393xb_gpio_set;
  423. tc6393xb->gpio.get = tc6393xb_gpio_get;
  424. tc6393xb->gpio.direction_input = tc6393xb_gpio_direction_input;
  425. tc6393xb->gpio.direction_output = tc6393xb_gpio_direction_output;
  426. return gpiochip_add(&tc6393xb->gpio);
  427. }
  428. /*--------------------------------------------------------------------------*/
  429. static void
  430. tc6393xb_irq(unsigned int irq, struct irq_desc *desc)
  431. {
  432. struct tc6393xb *tc6393xb = irq_get_handler_data(irq);
  433. unsigned int isr;
  434. unsigned int i, irq_base;
  435. irq_base = tc6393xb->irq_base;
  436. while ((isr = tmio_ioread8(tc6393xb->scr + SCR_ISR) &
  437. ~tmio_ioread8(tc6393xb->scr + SCR_IMR)))
  438. for (i = 0; i < TC6393XB_NR_IRQS; i++) {
  439. if (isr & (1 << i))
  440. generic_handle_irq(irq_base + i);
  441. }
  442. }
  443. static void tc6393xb_irq_ack(struct irq_data *data)
  444. {
  445. }
  446. static void tc6393xb_irq_mask(struct irq_data *data)
  447. {
  448. struct tc6393xb *tc6393xb = irq_data_get_irq_chip_data(data);
  449. unsigned long flags;
  450. u8 imr;
  451. spin_lock_irqsave(&tc6393xb->lock, flags);
  452. imr = tmio_ioread8(tc6393xb->scr + SCR_IMR);
  453. imr |= 1 << (data->irq - tc6393xb->irq_base);
  454. tmio_iowrite8(imr, tc6393xb->scr + SCR_IMR);
  455. spin_unlock_irqrestore(&tc6393xb->lock, flags);
  456. }
  457. static void tc6393xb_irq_unmask(struct irq_data *data)
  458. {
  459. struct tc6393xb *tc6393xb = irq_data_get_irq_chip_data(data);
  460. unsigned long flags;
  461. u8 imr;
  462. spin_lock_irqsave(&tc6393xb->lock, flags);
  463. imr = tmio_ioread8(tc6393xb->scr + SCR_IMR);
  464. imr &= ~(1 << (data->irq - tc6393xb->irq_base));
  465. tmio_iowrite8(imr, tc6393xb->scr + SCR_IMR);
  466. spin_unlock_irqrestore(&tc6393xb->lock, flags);
  467. }
  468. static struct irq_chip tc6393xb_chip = {
  469. .name = "tc6393xb",
  470. .irq_ack = tc6393xb_irq_ack,
  471. .irq_mask = tc6393xb_irq_mask,
  472. .irq_unmask = tc6393xb_irq_unmask,
  473. };
  474. static void tc6393xb_attach_irq(struct platform_device *dev)
  475. {
  476. struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
  477. unsigned int irq, irq_base;
  478. irq_base = tc6393xb->irq_base;
  479. for (irq = irq_base; irq < irq_base + TC6393XB_NR_IRQS; irq++) {
  480. irq_set_chip_and_handler(irq, &tc6393xb_chip, handle_edge_irq);
  481. irq_set_chip_data(irq, tc6393xb);
  482. set_irq_flags(irq, IRQF_VALID | IRQF_PROBE);
  483. }
  484. irq_set_irq_type(tc6393xb->irq, IRQ_TYPE_EDGE_FALLING);
  485. irq_set_handler_data(tc6393xb->irq, tc6393xb);
  486. irq_set_chained_handler(tc6393xb->irq, tc6393xb_irq);
  487. }
  488. static void tc6393xb_detach_irq(struct platform_device *dev)
  489. {
  490. struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
  491. unsigned int irq, irq_base;
  492. irq_set_chained_handler(tc6393xb->irq, NULL);
  493. irq_set_handler_data(tc6393xb->irq, NULL);
  494. irq_base = tc6393xb->irq_base;
  495. for (irq = irq_base; irq < irq_base + TC6393XB_NR_IRQS; irq++) {
  496. set_irq_flags(irq, 0);
  497. irq_set_chip(irq, NULL);
  498. irq_set_chip_data(irq, NULL);
  499. }
  500. }
  501. /*--------------------------------------------------------------------------*/
  502. static int __devinit tc6393xb_probe(struct platform_device *dev)
  503. {
  504. struct tc6393xb_platform_data *tcpd = dev->dev.platform_data;
  505. struct tc6393xb *tc6393xb;
  506. struct resource *iomem, *rscr;
  507. int ret, temp;
  508. iomem = platform_get_resource(dev, IORESOURCE_MEM, 0);
  509. if (!iomem)
  510. return -EINVAL;
  511. tc6393xb = kzalloc(sizeof *tc6393xb, GFP_KERNEL);
  512. if (!tc6393xb) {
  513. ret = -ENOMEM;
  514. goto err_kzalloc;
  515. }
  516. spin_lock_init(&tc6393xb->lock);
  517. platform_set_drvdata(dev, tc6393xb);
  518. ret = platform_get_irq(dev, 0);
  519. if (ret >= 0)
  520. tc6393xb->irq = ret;
  521. else
  522. goto err_noirq;
  523. tc6393xb->iomem = iomem;
  524. tc6393xb->irq_base = tcpd->irq_base;
  525. tc6393xb->clk = clk_get(&dev->dev, "CLK_CK3P6MI");
  526. if (IS_ERR(tc6393xb->clk)) {
  527. ret = PTR_ERR(tc6393xb->clk);
  528. goto err_clk_get;
  529. }
  530. rscr = &tc6393xb->rscr;
  531. rscr->name = "tc6393xb-core";
  532. rscr->start = iomem->start;
  533. rscr->end = iomem->start + 0xff;
  534. rscr->flags = IORESOURCE_MEM;
  535. ret = request_resource(iomem, rscr);
  536. if (ret)
  537. goto err_request_scr;
  538. tc6393xb->scr = ioremap(rscr->start, resource_size(rscr));
  539. if (!tc6393xb->scr) {
  540. ret = -ENOMEM;
  541. goto err_ioremap;
  542. }
  543. ret = clk_enable(tc6393xb->clk);
  544. if (ret)
  545. goto err_clk_enable;
  546. ret = tcpd->enable(dev);
  547. if (ret)
  548. goto err_enable;
  549. iowrite8(0, tc6393xb->scr + SCR_FER);
  550. iowrite16(tcpd->scr_pll2cr, tc6393xb->scr + SCR_PLL2CR);
  551. iowrite16(SCR_CCR_UNK1 | SCR_CCR_HCLK_48,
  552. tc6393xb->scr + SCR_CCR);
  553. iowrite16(SCR_MCR_RDY_OPENDRAIN | SCR_MCR_RDY_UNK | SCR_MCR_RDY_EN |
  554. SCR_MCR_INT_OPENDRAIN | SCR_MCR_INT_UNK | SCR_MCR_INT_EN |
  555. BIT(15), tc6393xb->scr + SCR_MCR);
  556. iowrite16(tcpd->scr_gper, tc6393xb->scr + SCR_GPER);
  557. iowrite8(0, tc6393xb->scr + SCR_IRR);
  558. iowrite8(0xbf, tc6393xb->scr + SCR_IMR);
  559. printk(KERN_INFO "Toshiba tc6393xb revision %d at 0x%08lx, irq %d\n",
  560. tmio_ioread8(tc6393xb->scr + SCR_REVID),
  561. (unsigned long) iomem->start, tc6393xb->irq);
  562. tc6393xb->gpio.base = -1;
  563. if (tcpd->gpio_base >= 0) {
  564. ret = tc6393xb_register_gpio(tc6393xb, tcpd->gpio_base);
  565. if (ret)
  566. goto err_gpio_add;
  567. }
  568. tc6393xb_attach_irq(dev);
  569. if (tcpd->setup) {
  570. ret = tcpd->setup(dev);
  571. if (ret)
  572. goto err_setup;
  573. }
  574. tc6393xb_cells[TC6393XB_CELL_NAND].platform_data = tcpd->nand_data;
  575. tc6393xb_cells[TC6393XB_CELL_NAND].pdata_size =
  576. sizeof(*tcpd->nand_data);
  577. tc6393xb_cells[TC6393XB_CELL_FB].platform_data = tcpd->fb_data;
  578. tc6393xb_cells[TC6393XB_CELL_FB].pdata_size = sizeof(*tcpd->fb_data);
  579. ret = mfd_add_devices(&dev->dev, dev->id,
  580. tc6393xb_cells, ARRAY_SIZE(tc6393xb_cells),
  581. iomem, tcpd->irq_base);
  582. if (!ret)
  583. return 0;
  584. if (tcpd->teardown)
  585. tcpd->teardown(dev);
  586. err_setup:
  587. tc6393xb_detach_irq(dev);
  588. err_gpio_add:
  589. if (tc6393xb->gpio.base != -1)
  590. temp = gpiochip_remove(&tc6393xb->gpio);
  591. tcpd->disable(dev);
  592. err_enable:
  593. clk_disable(tc6393xb->clk);
  594. err_clk_enable:
  595. iounmap(tc6393xb->scr);
  596. err_ioremap:
  597. release_resource(&tc6393xb->rscr);
  598. err_request_scr:
  599. clk_put(tc6393xb->clk);
  600. err_noirq:
  601. err_clk_get:
  602. kfree(tc6393xb);
  603. err_kzalloc:
  604. return ret;
  605. }
  606. static int __devexit tc6393xb_remove(struct platform_device *dev)
  607. {
  608. struct tc6393xb_platform_data *tcpd = dev->dev.platform_data;
  609. struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
  610. int ret;
  611. mfd_remove_devices(&dev->dev);
  612. if (tcpd->teardown)
  613. tcpd->teardown(dev);
  614. tc6393xb_detach_irq(dev);
  615. if (tc6393xb->gpio.base != -1) {
  616. ret = gpiochip_remove(&tc6393xb->gpio);
  617. if (ret) {
  618. dev_err(&dev->dev, "Can't remove gpio chip: %d\n", ret);
  619. return ret;
  620. }
  621. }
  622. ret = tcpd->disable(dev);
  623. clk_disable(tc6393xb->clk);
  624. iounmap(tc6393xb->scr);
  625. release_resource(&tc6393xb->rscr);
  626. platform_set_drvdata(dev, NULL);
  627. clk_put(tc6393xb->clk);
  628. kfree(tc6393xb);
  629. return ret;
  630. }
  631. #ifdef CONFIG_PM
  632. static int tc6393xb_suspend(struct platform_device *dev, pm_message_t state)
  633. {
  634. struct tc6393xb_platform_data *tcpd = dev->dev.platform_data;
  635. struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
  636. int i, ret;
  637. tc6393xb->suspend_state.ccr = ioread16(tc6393xb->scr + SCR_CCR);
  638. tc6393xb->suspend_state.fer = ioread8(tc6393xb->scr + SCR_FER);
  639. for (i = 0; i < 3; i++) {
  640. tc6393xb->suspend_state.gpo_dsr[i] =
  641. ioread8(tc6393xb->scr + SCR_GPO_DSR(i));
  642. tc6393xb->suspend_state.gpo_doecr[i] =
  643. ioread8(tc6393xb->scr + SCR_GPO_DOECR(i));
  644. tc6393xb->suspend_state.gpi_bcr[i] =
  645. ioread8(tc6393xb->scr + SCR_GPI_BCR(i));
  646. }
  647. ret = tcpd->suspend(dev);
  648. clk_disable(tc6393xb->clk);
  649. return ret;
  650. }
  651. static int tc6393xb_resume(struct platform_device *dev)
  652. {
  653. struct tc6393xb_platform_data *tcpd = dev->dev.platform_data;
  654. struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
  655. int ret;
  656. int i;
  657. clk_enable(tc6393xb->clk);
  658. ret = tcpd->resume(dev);
  659. if (ret)
  660. return ret;
  661. if (!tcpd->resume_restore)
  662. return 0;
  663. iowrite8(tc6393xb->suspend_state.fer, tc6393xb->scr + SCR_FER);
  664. iowrite16(tcpd->scr_pll2cr, tc6393xb->scr + SCR_PLL2CR);
  665. iowrite16(tc6393xb->suspend_state.ccr, tc6393xb->scr + SCR_CCR);
  666. iowrite16(SCR_MCR_RDY_OPENDRAIN | SCR_MCR_RDY_UNK | SCR_MCR_RDY_EN |
  667. SCR_MCR_INT_OPENDRAIN | SCR_MCR_INT_UNK | SCR_MCR_INT_EN |
  668. BIT(15), tc6393xb->scr + SCR_MCR);
  669. iowrite16(tcpd->scr_gper, tc6393xb->scr + SCR_GPER);
  670. iowrite8(0, tc6393xb->scr + SCR_IRR);
  671. iowrite8(0xbf, tc6393xb->scr + SCR_IMR);
  672. for (i = 0; i < 3; i++) {
  673. iowrite8(tc6393xb->suspend_state.gpo_dsr[i],
  674. tc6393xb->scr + SCR_GPO_DSR(i));
  675. iowrite8(tc6393xb->suspend_state.gpo_doecr[i],
  676. tc6393xb->scr + SCR_GPO_DOECR(i));
  677. iowrite8(tc6393xb->suspend_state.gpi_bcr[i],
  678. tc6393xb->scr + SCR_GPI_BCR(i));
  679. }
  680. return 0;
  681. }
  682. #else
  683. #define tc6393xb_suspend NULL
  684. #define tc6393xb_resume NULL
  685. #endif
  686. static struct platform_driver tc6393xb_driver = {
  687. .probe = tc6393xb_probe,
  688. .remove = __devexit_p(tc6393xb_remove),
  689. .suspend = tc6393xb_suspend,
  690. .resume = tc6393xb_resume,
  691. .driver = {
  692. .name = "tc6393xb",
  693. .owner = THIS_MODULE,
  694. },
  695. };
  696. static int __init tc6393xb_init(void)
  697. {
  698. return platform_driver_register(&tc6393xb_driver);
  699. }
  700. static void __exit tc6393xb_exit(void)
  701. {
  702. platform_driver_unregister(&tc6393xb_driver);
  703. }
  704. subsys_initcall(tc6393xb_init);
  705. module_exit(tc6393xb_exit);
  706. MODULE_LICENSE("GPL v2");
  707. MODULE_AUTHOR("Ian Molton, Dmitry Baryshkov and Dirk Opfer");
  708. MODULE_DESCRIPTION("tc6393xb Toshiba Mobile IO Controller");
  709. MODULE_ALIAS("platform:tc6393xb");