tc6387xb.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. #ifdef CONFIG_PM
  23. static int tc6387xb_suspend(struct platform_device *dev, pm_message_t state)
  24. {
  25. struct clk *clk32k = platform_get_drvdata(dev);
  26. struct tc6387xb_platform_data *pdata = dev->dev.platform_data;
  27. if (pdata && pdata->suspend)
  28. pdata->suspend(dev);
  29. clk_disable(clk32k);
  30. return 0;
  31. }
  32. static int tc6387xb_resume(struct platform_device *dev)
  33. {
  34. struct clk *clk32k = platform_get_drvdata(dev);
  35. struct tc6387xb_platform_data *pdata = dev->dev.platform_data;
  36. clk_enable(clk32k);
  37. if (pdata && pdata->resume)
  38. pdata->resume(dev);
  39. return 0;
  40. }
  41. #else
  42. #define tc6387xb_suspend NULL
  43. #define tc6387xb_resume NULL
  44. #endif
  45. /*--------------------------------------------------------------------------*/
  46. static int tc6387xb_mmc_enable(struct platform_device *mmc)
  47. {
  48. struct platform_device *dev = to_platform_device(mmc->dev.parent);
  49. struct clk *clk32k = platform_get_drvdata(dev);
  50. clk_enable(clk32k);
  51. return 0;
  52. }
  53. static int tc6387xb_mmc_disable(struct platform_device *mmc)
  54. {
  55. struct platform_device *dev = to_platform_device(mmc->dev.parent);
  56. struct clk *clk32k = platform_get_drvdata(dev);
  57. clk_disable(clk32k);
  58. return 0;
  59. }
  60. /*--------------------------------------------------------------------------*/
  61. static struct resource tc6387xb_mmc_resources[] = {
  62. {
  63. .start = 0x800,
  64. .end = 0x9ff,
  65. .flags = IORESOURCE_MEM,
  66. },
  67. {
  68. .start = 0x200,
  69. .end = 0x2ff,
  70. .flags = IORESOURCE_MEM,
  71. },
  72. {
  73. .start = 0,
  74. .end = 0,
  75. .flags = IORESOURCE_IRQ,
  76. },
  77. };
  78. static struct mfd_cell tc6387xb_cells[] = {
  79. [TC6387XB_CELL_MMC] = {
  80. .name = "tmio-mmc",
  81. .enable = tc6387xb_mmc_enable,
  82. .disable = tc6387xb_mmc_disable,
  83. .num_resources = ARRAY_SIZE(tc6387xb_mmc_resources),
  84. .resources = tc6387xb_mmc_resources,
  85. },
  86. };
  87. static int tc6387xb_probe(struct platform_device *dev)
  88. {
  89. struct tc6387xb_platform_data *pdata = dev->dev.platform_data;
  90. struct resource *iomem;
  91. struct clk *clk32k;
  92. int irq, ret;
  93. iomem = platform_get_resource(dev, IORESOURCE_MEM, 0);
  94. if (!iomem) {
  95. return -EINVAL;
  96. }
  97. ret = platform_get_irq(dev, 0);
  98. if (ret >= 0)
  99. irq = ret;
  100. else
  101. goto err_resource;
  102. clk32k = clk_get(&dev->dev, "CLK_CK32K");
  103. if (IS_ERR(clk32k)) {
  104. ret = PTR_ERR(clk32k);
  105. goto err_resource;
  106. }
  107. platform_set_drvdata(dev, clk32k);
  108. if (pdata && pdata->enable)
  109. pdata->enable(dev);
  110. printk(KERN_INFO "Toshiba tc6387xb initialised\n");
  111. tc6387xb_cells[TC6387XB_CELL_MMC].platform_data =
  112. &tc6387xb_cells[TC6387XB_CELL_MMC];
  113. tc6387xb_cells[TC6387XB_CELL_MMC].data_size =
  114. sizeof(tc6387xb_cells[TC6387XB_CELL_MMC]);
  115. ret = mfd_add_devices(&dev->dev, dev->id, tc6387xb_cells,
  116. ARRAY_SIZE(tc6387xb_cells), iomem, irq);
  117. if (!ret)
  118. return 0;
  119. clk_put(clk32k);
  120. err_resource:
  121. return ret;
  122. }
  123. static int tc6387xb_remove(struct platform_device *dev)
  124. {
  125. struct clk *clk32k = platform_get_drvdata(dev);
  126. mfd_remove_devices(&dev->dev);
  127. clk_disable(clk32k);
  128. clk_put(clk32k);
  129. platform_set_drvdata(dev, NULL);
  130. return 0;
  131. }
  132. static struct platform_driver tc6387xb_platform_driver = {
  133. .driver = {
  134. .name = "tc6387xb",
  135. },
  136. .probe = tc6387xb_probe,
  137. .remove = tc6387xb_remove,
  138. .suspend = tc6387xb_suspend,
  139. .resume = tc6387xb_resume,
  140. };
  141. static int __init tc6387xb_init(void)
  142. {
  143. return platform_driver_register(&tc6387xb_platform_driver);
  144. }
  145. static void __exit tc6387xb_exit(void)
  146. {
  147. platform_driver_unregister(&tc6387xb_platform_driver);
  148. }
  149. module_init(tc6387xb_init);
  150. module_exit(tc6387xb_exit);
  151. MODULE_DESCRIPTION("Toshiba TC6387XB core driver");
  152. MODULE_LICENSE("GPL v2");
  153. MODULE_AUTHOR("Ian Molton");
  154. MODULE_ALIAS("platform:tc6387xb");