tc6393xb.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864
  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/driver.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 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 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 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 = gpiochip_get_data(chip);
  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 = gpiochip_get_data(chip);
  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 = gpiochip_get_data(chip);
  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 = gpiochip_get_data(chip);
  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 = gpiochip_get_data(chip);
  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_data(&tc6393xb->gpio, tc6393xb);
  427. }
  428. /*--------------------------------------------------------------------------*/
  429. static void tc6393xb_irq(struct irq_desc *desc)
  430. {
  431. struct tc6393xb *tc6393xb = irq_desc_get_handler_data(desc);
  432. unsigned int isr;
  433. unsigned int i, irq_base;
  434. irq_base = tc6393xb->irq_base;
  435. while ((isr = tmio_ioread8(tc6393xb->scr + SCR_ISR) &
  436. ~tmio_ioread8(tc6393xb->scr + SCR_IMR)))
  437. for (i = 0; i < TC6393XB_NR_IRQS; i++) {
  438. if (isr & (1 << i))
  439. generic_handle_irq(irq_base + i);
  440. }
  441. }
  442. static void tc6393xb_irq_ack(struct irq_data *data)
  443. {
  444. }
  445. static void tc6393xb_irq_mask(struct irq_data *data)
  446. {
  447. struct tc6393xb *tc6393xb = irq_data_get_irq_chip_data(data);
  448. unsigned long flags;
  449. u8 imr;
  450. spin_lock_irqsave(&tc6393xb->lock, flags);
  451. imr = tmio_ioread8(tc6393xb->scr + SCR_IMR);
  452. imr |= 1 << (data->irq - tc6393xb->irq_base);
  453. tmio_iowrite8(imr, tc6393xb->scr + SCR_IMR);
  454. spin_unlock_irqrestore(&tc6393xb->lock, flags);
  455. }
  456. static void tc6393xb_irq_unmask(struct irq_data *data)
  457. {
  458. struct tc6393xb *tc6393xb = irq_data_get_irq_chip_data(data);
  459. unsigned long flags;
  460. u8 imr;
  461. spin_lock_irqsave(&tc6393xb->lock, flags);
  462. imr = tmio_ioread8(tc6393xb->scr + SCR_IMR);
  463. imr &= ~(1 << (data->irq - tc6393xb->irq_base));
  464. tmio_iowrite8(imr, tc6393xb->scr + SCR_IMR);
  465. spin_unlock_irqrestore(&tc6393xb->lock, flags);
  466. }
  467. static struct irq_chip tc6393xb_chip = {
  468. .name = "tc6393xb",
  469. .irq_ack = tc6393xb_irq_ack,
  470. .irq_mask = tc6393xb_irq_mask,
  471. .irq_unmask = tc6393xb_irq_unmask,
  472. };
  473. static void tc6393xb_attach_irq(struct platform_device *dev)
  474. {
  475. struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
  476. unsigned int irq, irq_base;
  477. irq_base = tc6393xb->irq_base;
  478. for (irq = irq_base; irq < irq_base + TC6393XB_NR_IRQS; irq++) {
  479. irq_set_chip_and_handler(irq, &tc6393xb_chip, handle_edge_irq);
  480. irq_set_chip_data(irq, tc6393xb);
  481. irq_clear_status_flags(irq, IRQ_NOREQUEST | IRQ_NOPROBE);
  482. }
  483. irq_set_irq_type(tc6393xb->irq, IRQ_TYPE_EDGE_FALLING);
  484. irq_set_chained_handler_and_data(tc6393xb->irq, tc6393xb_irq,
  485. tc6393xb);
  486. }
  487. static void tc6393xb_detach_irq(struct platform_device *dev)
  488. {
  489. struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
  490. unsigned int irq, irq_base;
  491. irq_set_chained_handler_and_data(tc6393xb->irq, NULL, NULL);
  492. irq_base = tc6393xb->irq_base;
  493. for (irq = irq_base; irq < irq_base + TC6393XB_NR_IRQS; irq++) {
  494. irq_set_status_flags(irq, IRQ_NOREQUEST | IRQ_NOPROBE);
  495. irq_set_chip(irq, NULL);
  496. irq_set_chip_data(irq, NULL);
  497. }
  498. }
  499. /*--------------------------------------------------------------------------*/
  500. static int tc6393xb_probe(struct platform_device *dev)
  501. {
  502. struct tc6393xb_platform_data *tcpd = dev_get_platdata(&dev->dev);
  503. struct tc6393xb *tc6393xb;
  504. struct resource *iomem, *rscr;
  505. int ret;
  506. iomem = platform_get_resource(dev, IORESOURCE_MEM, 0);
  507. if (!iomem)
  508. return -EINVAL;
  509. tc6393xb = kzalloc(sizeof *tc6393xb, GFP_KERNEL);
  510. if (!tc6393xb) {
  511. ret = -ENOMEM;
  512. goto err_kzalloc;
  513. }
  514. spin_lock_init(&tc6393xb->lock);
  515. platform_set_drvdata(dev, tc6393xb);
  516. ret = platform_get_irq(dev, 0);
  517. if (ret >= 0)
  518. tc6393xb->irq = ret;
  519. else
  520. goto err_noirq;
  521. tc6393xb->iomem = iomem;
  522. tc6393xb->irq_base = tcpd->irq_base;
  523. tc6393xb->clk = clk_get(&dev->dev, "CLK_CK3P6MI");
  524. if (IS_ERR(tc6393xb->clk)) {
  525. ret = PTR_ERR(tc6393xb->clk);
  526. goto err_clk_get;
  527. }
  528. rscr = &tc6393xb->rscr;
  529. rscr->name = "tc6393xb-core";
  530. rscr->start = iomem->start;
  531. rscr->end = iomem->start + 0xff;
  532. rscr->flags = IORESOURCE_MEM;
  533. ret = request_resource(iomem, rscr);
  534. if (ret)
  535. goto err_request_scr;
  536. tc6393xb->scr = ioremap(rscr->start, resource_size(rscr));
  537. if (!tc6393xb->scr) {
  538. ret = -ENOMEM;
  539. goto err_ioremap;
  540. }
  541. ret = clk_prepare_enable(tc6393xb->clk);
  542. if (ret)
  543. goto err_clk_enable;
  544. ret = tcpd->enable(dev);
  545. if (ret)
  546. goto err_enable;
  547. iowrite8(0, tc6393xb->scr + SCR_FER);
  548. iowrite16(tcpd->scr_pll2cr, tc6393xb->scr + SCR_PLL2CR);
  549. iowrite16(SCR_CCR_UNK1 | SCR_CCR_HCLK_48,
  550. tc6393xb->scr + SCR_CCR);
  551. iowrite16(SCR_MCR_RDY_OPENDRAIN | SCR_MCR_RDY_UNK | SCR_MCR_RDY_EN |
  552. SCR_MCR_INT_OPENDRAIN | SCR_MCR_INT_UNK | SCR_MCR_INT_EN |
  553. BIT(15), tc6393xb->scr + SCR_MCR);
  554. iowrite16(tcpd->scr_gper, tc6393xb->scr + SCR_GPER);
  555. iowrite8(0, tc6393xb->scr + SCR_IRR);
  556. iowrite8(0xbf, tc6393xb->scr + SCR_IMR);
  557. printk(KERN_INFO "Toshiba tc6393xb revision %d at 0x%08lx, irq %d\n",
  558. tmio_ioread8(tc6393xb->scr + SCR_REVID),
  559. (unsigned long) iomem->start, tc6393xb->irq);
  560. tc6393xb->gpio.base = -1;
  561. if (tcpd->gpio_base >= 0) {
  562. ret = tc6393xb_register_gpio(tc6393xb, tcpd->gpio_base);
  563. if (ret)
  564. goto err_gpio_add;
  565. }
  566. tc6393xb_attach_irq(dev);
  567. if (tcpd->setup) {
  568. ret = tcpd->setup(dev);
  569. if (ret)
  570. goto err_setup;
  571. }
  572. tc6393xb_cells[TC6393XB_CELL_NAND].platform_data = tcpd->nand_data;
  573. tc6393xb_cells[TC6393XB_CELL_NAND].pdata_size =
  574. sizeof(*tcpd->nand_data);
  575. tc6393xb_cells[TC6393XB_CELL_FB].platform_data = tcpd->fb_data;
  576. tc6393xb_cells[TC6393XB_CELL_FB].pdata_size = sizeof(*tcpd->fb_data);
  577. ret = mfd_add_devices(&dev->dev, dev->id,
  578. tc6393xb_cells, ARRAY_SIZE(tc6393xb_cells),
  579. iomem, tcpd->irq_base, NULL);
  580. if (!ret)
  581. return 0;
  582. if (tcpd->teardown)
  583. tcpd->teardown(dev);
  584. err_setup:
  585. tc6393xb_detach_irq(dev);
  586. err_gpio_add:
  587. if (tc6393xb->gpio.base != -1)
  588. gpiochip_remove(&tc6393xb->gpio);
  589. tcpd->disable(dev);
  590. err_enable:
  591. clk_disable_unprepare(tc6393xb->clk);
  592. err_clk_enable:
  593. iounmap(tc6393xb->scr);
  594. err_ioremap:
  595. release_resource(&tc6393xb->rscr);
  596. err_request_scr:
  597. clk_put(tc6393xb->clk);
  598. err_noirq:
  599. err_clk_get:
  600. kfree(tc6393xb);
  601. err_kzalloc:
  602. return ret;
  603. }
  604. static int tc6393xb_remove(struct platform_device *dev)
  605. {
  606. struct tc6393xb_platform_data *tcpd = dev_get_platdata(&dev->dev);
  607. struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
  608. int ret;
  609. mfd_remove_devices(&dev->dev);
  610. if (tcpd->teardown)
  611. tcpd->teardown(dev);
  612. tc6393xb_detach_irq(dev);
  613. if (tc6393xb->gpio.base != -1)
  614. gpiochip_remove(&tc6393xb->gpio);
  615. ret = tcpd->disable(dev);
  616. clk_disable_unprepare(tc6393xb->clk);
  617. iounmap(tc6393xb->scr);
  618. release_resource(&tc6393xb->rscr);
  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_get_platdata(&dev->dev);
  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_unprepare(tc6393xb->clk);
  641. return ret;
  642. }
  643. static int tc6393xb_resume(struct platform_device *dev)
  644. {
  645. struct tc6393xb_platform_data *tcpd = dev_get_platdata(&dev->dev);
  646. struct tc6393xb *tc6393xb = platform_get_drvdata(dev);
  647. int ret;
  648. int i;
  649. clk_prepare_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 = tc6393xb_remove,
  681. .suspend = tc6393xb_suspend,
  682. .resume = tc6393xb_resume,
  683. .driver = {
  684. .name = "tc6393xb",
  685. },
  686. };
  687. static int __init tc6393xb_init(void)
  688. {
  689. return platform_driver_register(&tc6393xb_driver);
  690. }
  691. static void __exit tc6393xb_exit(void)
  692. {
  693. platform_driver_unregister(&tc6393xb_driver);
  694. }
  695. subsys_initcall(tc6393xb_init);
  696. module_exit(tc6393xb_exit);
  697. MODULE_LICENSE("GPL v2");
  698. MODULE_AUTHOR("Ian Molton, Dmitry Baryshkov and Dirk Opfer");
  699. MODULE_DESCRIPTION("tc6393xb Toshiba Mobile IO Controller");
  700. MODULE_ALIAS("platform:tc6393xb");