tc6387xb.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /*
  2. * Toshiba TC6387XB support
  3. * Copyright (c) 2005 Ian Molton
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * This file contains TC6387XB base support.
  10. *
  11. */
  12. #include <linux/module.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/clk.h>
  15. #include <linux/err.h>
  16. #include <linux/mfd/core.h>
  17. #include <linux/mfd/tmio.h>
  18. #include <linux/mfd/tc6387xb.h>
  19. #include <linux/slab.h>
  20. enum {
  21. TC6387XB_CELL_MMC,
  22. };
  23. struct tc6387xb {
  24. void __iomem *scr;
  25. struct clk *clk32k;
  26. struct resource rscr;
  27. };
  28. static struct resource tc6387xb_mmc_resources[] = {
  29. {
  30. .start = 0x800,
  31. .end = 0x9ff,
  32. .flags = IORESOURCE_MEM,
  33. },
  34. {
  35. .start = 0,
  36. .end = 0,
  37. .flags = IORESOURCE_IRQ,
  38. },
  39. };
  40. /*--------------------------------------------------------------------------*/
  41. #ifdef CONFIG_PM
  42. static int tc6387xb_suspend(struct platform_device *dev, pm_message_t state)
  43. {
  44. struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
  45. struct tc6387xb_platform_data *pdata = dev->dev.platform_data;
  46. if (pdata && pdata->suspend)
  47. pdata->suspend(dev);
  48. clk_disable(tc6387xb->clk32k);
  49. return 0;
  50. }
  51. static int tc6387xb_resume(struct platform_device *dev)
  52. {
  53. struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
  54. struct tc6387xb_platform_data *pdata = dev->dev.platform_data;
  55. clk_enable(tc6387xb->clk32k);
  56. if (pdata && pdata->resume)
  57. pdata->resume(dev);
  58. tmio_core_mmc_resume(tc6387xb->scr + 0x200, 0,
  59. tc6387xb_mmc_resources[0].start & 0xfffe);
  60. return 0;
  61. }
  62. #else
  63. #define tc6387xb_suspend NULL
  64. #define tc6387xb_resume NULL
  65. #endif
  66. /*--------------------------------------------------------------------------*/
  67. static void tc6387xb_mmc_pwr(struct platform_device *mmc, int state)
  68. {
  69. struct platform_device *dev = to_platform_device(mmc->dev.parent);
  70. struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
  71. tmio_core_mmc_pwr(tc6387xb->scr + 0x200, 0, state);
  72. }
  73. static void tc6387xb_mmc_clk_div(struct platform_device *mmc, int state)
  74. {
  75. struct platform_device *dev = to_platform_device(mmc->dev.parent);
  76. struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
  77. tmio_core_mmc_clk_div(tc6387xb->scr + 0x200, 0, state);
  78. }
  79. static int tc6387xb_mmc_enable(struct platform_device *mmc)
  80. {
  81. struct platform_device *dev = to_platform_device(mmc->dev.parent);
  82. struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
  83. clk_enable(tc6387xb->clk32k);
  84. tmio_core_mmc_enable(tc6387xb->scr + 0x200, 0,
  85. tc6387xb_mmc_resources[0].start & 0xfffe);
  86. return 0;
  87. }
  88. static int tc6387xb_mmc_disable(struct platform_device *mmc)
  89. {
  90. struct platform_device *dev = to_platform_device(mmc->dev.parent);
  91. struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
  92. clk_disable(tc6387xb->clk32k);
  93. return 0;
  94. }
  95. static struct tmio_mmc_data tc6387xb_mmc_data = {
  96. .hclk = 24000000,
  97. .set_pwr = tc6387xb_mmc_pwr,
  98. .set_clk_div = tc6387xb_mmc_clk_div,
  99. };
  100. /*--------------------------------------------------------------------------*/
  101. static struct mfd_cell tc6387xb_cells[] = {
  102. [TC6387XB_CELL_MMC] = {
  103. .name = "tmio-mmc",
  104. .enable = tc6387xb_mmc_enable,
  105. .disable = tc6387xb_mmc_disable,
  106. .driver_data = &tc6387xb_mmc_data,
  107. .num_resources = ARRAY_SIZE(tc6387xb_mmc_resources),
  108. .resources = tc6387xb_mmc_resources,
  109. },
  110. };
  111. static int __devinit tc6387xb_probe(struct platform_device *dev)
  112. {
  113. struct tc6387xb_platform_data *pdata = dev->dev.platform_data;
  114. struct resource *iomem, *rscr;
  115. struct clk *clk32k;
  116. struct tc6387xb *tc6387xb;
  117. int irq, ret;
  118. iomem = platform_get_resource(dev, IORESOURCE_MEM, 0);
  119. if (!iomem) {
  120. return -EINVAL;
  121. }
  122. tc6387xb = kzalloc(sizeof *tc6387xb, GFP_KERNEL);
  123. if (!tc6387xb)
  124. return -ENOMEM;
  125. ret = platform_get_irq(dev, 0);
  126. if (ret >= 0)
  127. irq = ret;
  128. else
  129. goto err_no_irq;
  130. clk32k = clk_get(&dev->dev, "CLK_CK32K");
  131. if (IS_ERR(clk32k)) {
  132. ret = PTR_ERR(clk32k);
  133. goto err_no_clk;
  134. }
  135. rscr = &tc6387xb->rscr;
  136. rscr->name = "tc6387xb-core";
  137. rscr->start = iomem->start;
  138. rscr->end = iomem->start + 0xff;
  139. rscr->flags = IORESOURCE_MEM;
  140. ret = request_resource(iomem, rscr);
  141. if (ret)
  142. goto err_resource;
  143. tc6387xb->scr = ioremap(rscr->start, rscr->end - rscr->start + 1);
  144. if (!tc6387xb->scr) {
  145. ret = -ENOMEM;
  146. goto err_ioremap;
  147. }
  148. tc6387xb->clk32k = clk32k;
  149. platform_set_drvdata(dev, tc6387xb);
  150. if (pdata && pdata->enable)
  151. pdata->enable(dev);
  152. printk(KERN_INFO "Toshiba tc6387xb initialised\n");
  153. tc6387xb_cells[TC6387XB_CELL_MMC].platform_data =
  154. &tc6387xb_cells[TC6387XB_CELL_MMC];
  155. tc6387xb_cells[TC6387XB_CELL_MMC].data_size =
  156. sizeof(tc6387xb_cells[TC6387XB_CELL_MMC]);
  157. ret = mfd_add_devices(&dev->dev, dev->id, tc6387xb_cells,
  158. ARRAY_SIZE(tc6387xb_cells), iomem, irq);
  159. if (!ret)
  160. return 0;
  161. iounmap(tc6387xb->scr);
  162. err_ioremap:
  163. release_resource(&tc6387xb->rscr);
  164. err_resource:
  165. clk_put(clk32k);
  166. err_no_clk:
  167. err_no_irq:
  168. kfree(tc6387xb);
  169. return ret;
  170. }
  171. static int __devexit tc6387xb_remove(struct platform_device *dev)
  172. {
  173. struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
  174. mfd_remove_devices(&dev->dev);
  175. iounmap(tc6387xb->scr);
  176. release_resource(&tc6387xb->rscr);
  177. clk_disable(tc6387xb->clk32k);
  178. clk_put(tc6387xb->clk32k);
  179. platform_set_drvdata(dev, NULL);
  180. kfree(tc6387xb);
  181. return 0;
  182. }
  183. static struct platform_driver tc6387xb_platform_driver = {
  184. .driver = {
  185. .name = "tc6387xb",
  186. },
  187. .probe = tc6387xb_probe,
  188. .remove = __devexit_p(tc6387xb_remove),
  189. .suspend = tc6387xb_suspend,
  190. .resume = tc6387xb_resume,
  191. };
  192. static int __init tc6387xb_init(void)
  193. {
  194. return platform_driver_register(&tc6387xb_platform_driver);
  195. }
  196. static void __exit tc6387xb_exit(void)
  197. {
  198. platform_driver_unregister(&tc6387xb_platform_driver);
  199. }
  200. module_init(tc6387xb_init);
  201. module_exit(tc6387xb_exit);
  202. MODULE_DESCRIPTION("Toshiba TC6387XB core driver");
  203. MODULE_LICENSE("GPL v2");
  204. MODULE_AUTHOR("Ian Molton");
  205. MODULE_ALIAS("platform:tc6387xb");