tc6387xb.c 3.6 KB

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