tc6387xb.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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_get_platdata(&dev->dev);
  46. if (pdata && pdata->suspend)
  47. pdata->suspend(dev);
  48. clk_disable_unprepare(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_get_platdata(&dev->dev);
  55. clk_prepare_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_prepare_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_unprepare(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 const 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 tc6387xb_probe(struct platform_device *dev)
  113. {
  114. struct tc6387xb_platform_data *pdata = dev_get_platdata(&dev->dev);
  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. 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, resource_size(rscr));
  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. dev_info(&dev->dev, "Toshiba tc6387xb initialised\n");
  153. ret = mfd_add_devices(&dev->dev, dev->id, tc6387xb_cells,
  154. ARRAY_SIZE(tc6387xb_cells), iomem, irq, NULL);
  155. if (!ret)
  156. return 0;
  157. iounmap(tc6387xb->scr);
  158. err_ioremap:
  159. release_resource(&tc6387xb->rscr);
  160. err_resource:
  161. clk_put(clk32k);
  162. err_no_clk:
  163. err_no_irq:
  164. kfree(tc6387xb);
  165. return ret;
  166. }
  167. static int tc6387xb_remove(struct platform_device *dev)
  168. {
  169. struct tc6387xb *tc6387xb = platform_get_drvdata(dev);
  170. mfd_remove_devices(&dev->dev);
  171. iounmap(tc6387xb->scr);
  172. release_resource(&tc6387xb->rscr);
  173. clk_disable_unprepare(tc6387xb->clk32k);
  174. clk_put(tc6387xb->clk32k);
  175. kfree(tc6387xb);
  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. module_platform_driver(tc6387xb_platform_driver);
  188. MODULE_DESCRIPTION("Toshiba TC6387XB core driver");
  189. MODULE_LICENSE("GPL v2");
  190. MODULE_AUTHOR("Ian Molton");
  191. MODULE_ALIAS("platform:tc6387xb");