tc6387xb.c 5.6 KB

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