tc6387xb.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. .platform_data = &tc6387xb_mmc_data,
  107. .pdata_size = sizeof(tc6387xb_mmc_data),
  108. .num_resources = ARRAY_SIZE(tc6387xb_mmc_resources),
  109. .resources = tc6387xb_mmc_resources,
  110. },
  111. };
  112. static int __devinit tc6387xb_probe(struct platform_device *dev)
  113. {
  114. struct tc6387xb_platform_data *pdata = dev->dev.platform_data;
  115. struct resource *iomem, *rscr;
  116. struct clk *clk32k;
  117. struct tc6387xb *tc6387xb;
  118. int irq, ret;
  119. iomem = platform_get_resource(dev, IORESOURCE_MEM, 0);
  120. if (!iomem) {
  121. return -EINVAL;
  122. }
  123. tc6387xb = kzalloc(sizeof *tc6387xb, GFP_KERNEL);
  124. if (!tc6387xb)
  125. return -ENOMEM;
  126. ret = platform_get_irq(dev, 0);
  127. if (ret >= 0)
  128. irq = ret;
  129. else
  130. goto err_no_irq;
  131. clk32k = clk_get(&dev->dev, "CLK_CK32K");
  132. if (IS_ERR(clk32k)) {
  133. ret = PTR_ERR(clk32k);
  134. goto err_no_clk;
  135. }
  136. rscr = &tc6387xb->rscr;
  137. rscr->name = "tc6387xb-core";
  138. rscr->start = iomem->start;
  139. rscr->end = iomem->start + 0xff;
  140. rscr->flags = IORESOURCE_MEM;
  141. ret = request_resource(iomem, rscr);
  142. if (ret)
  143. goto err_resource;
  144. tc6387xb->scr = ioremap(rscr->start, rscr->end - rscr->start + 1);
  145. if (!tc6387xb->scr) {
  146. ret = -ENOMEM;
  147. goto err_ioremap;
  148. }
  149. tc6387xb->clk32k = clk32k;
  150. platform_set_drvdata(dev, tc6387xb);
  151. if (pdata && pdata->enable)
  152. pdata->enable(dev);
  153. printk(KERN_INFO "Toshiba tc6387xb initialised\n");
  154. ret = mfd_add_devices(&dev->dev, dev->id, tc6387xb_cells,
  155. ARRAY_SIZE(tc6387xb_cells), iomem, irq);
  156. if (!ret)
  157. return 0;
  158. iounmap(tc6387xb->scr);
  159. err_ioremap:
  160. release_resource(&tc6387xb->rscr);
  161. err_resource:
  162. clk_put(clk32k);
  163. err_no_clk:
  164. err_no_irq:
  165. kfree(tc6387xb);
  166. return ret;
  167. }
  168. static int __devexit tc6387xb_remove(struct platform_device *dev)
  169. {
  170. struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
  171. mfd_remove_devices(&dev->dev);
  172. iounmap(tc6387xb->scr);
  173. release_resource(&tc6387xb->rscr);
  174. clk_disable(tc6387xb->clk32k);
  175. clk_put(tc6387xb->clk32k);
  176. platform_set_drvdata(dev, NULL);
  177. kfree(tc6387xb);
  178. return 0;
  179. }
  180. static struct platform_driver tc6387xb_platform_driver = {
  181. .driver = {
  182. .name = "tc6387xb",
  183. },
  184. .probe = tc6387xb_probe,
  185. .remove = __devexit_p(tc6387xb_remove),
  186. .suspend = tc6387xb_suspend,
  187. .resume = tc6387xb_resume,
  188. };
  189. static int __init tc6387xb_init(void)
  190. {
  191. return platform_driver_register(&tc6387xb_platform_driver);
  192. }
  193. static void __exit tc6387xb_exit(void)
  194. {
  195. platform_driver_unregister(&tc6387xb_platform_driver);
  196. }
  197. module_init(tc6387xb_init);
  198. module_exit(tc6387xb_exit);
  199. MODULE_DESCRIPTION("Toshiba TC6387XB core driver");
  200. MODULE_LICENSE("GPL v2");
  201. MODULE_AUTHOR("Ian Molton");
  202. MODULE_ALIAS("platform:tc6387xb");