ux500.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*
  2. * Copyright (C) 2010 ST-Ericsson AB
  3. * Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>
  4. *
  5. * Based on omap2430.c
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #include <linux/module.h>
  22. #include <linux/kernel.h>
  23. #include <linux/init.h>
  24. #include <linux/clk.h>
  25. #include <linux/io.h>
  26. #include <linux/platform_device.h>
  27. #include "musb_core.h"
  28. struct ux500_glue {
  29. struct device *dev;
  30. struct platform_device *musb;
  31. struct clk *clk;
  32. };
  33. #define glue_to_musb(g) platform_get_drvdata(g->musb)
  34. static int ux500_musb_init(struct musb *musb)
  35. {
  36. musb->xceiv = otg_get_transceiver();
  37. if (!musb->xceiv) {
  38. pr_err("HS USB OTG: no transceiver configured\n");
  39. return -ENODEV;
  40. }
  41. return 0;
  42. }
  43. static int ux500_musb_exit(struct musb *musb)
  44. {
  45. otg_put_transceiver(musb->xceiv);
  46. return 0;
  47. }
  48. static const struct musb_platform_ops ux500_ops = {
  49. .init = ux500_musb_init,
  50. .exit = ux500_musb_exit,
  51. };
  52. static int __init ux500_probe(struct platform_device *pdev)
  53. {
  54. struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data;
  55. struct platform_device *musb;
  56. struct ux500_glue *glue;
  57. struct clk *clk;
  58. int ret = -ENOMEM;
  59. glue = kzalloc(sizeof(*glue), GFP_KERNEL);
  60. if (!glue) {
  61. dev_err(&pdev->dev, "failed to allocate glue context\n");
  62. goto err0;
  63. }
  64. musb = platform_device_alloc("musb-hdrc", -1);
  65. if (!musb) {
  66. dev_err(&pdev->dev, "failed to allocate musb device\n");
  67. goto err1;
  68. }
  69. clk = clk_get(&pdev->dev, "usb");
  70. if (IS_ERR(clk)) {
  71. dev_err(&pdev->dev, "failed to get clock\n");
  72. ret = PTR_ERR(clk);
  73. goto err2;
  74. }
  75. ret = clk_enable(clk);
  76. if (ret) {
  77. dev_err(&pdev->dev, "failed to enable clock\n");
  78. goto err3;
  79. }
  80. musb->dev.parent = &pdev->dev;
  81. musb->dev.dma_mask = pdev->dev.dma_mask;
  82. musb->dev.coherent_dma_mask = pdev->dev.coherent_dma_mask;
  83. glue->dev = &pdev->dev;
  84. glue->musb = musb;
  85. glue->clk = clk;
  86. pdata->platform_ops = &ux500_ops;
  87. platform_set_drvdata(pdev, glue);
  88. ret = platform_device_add_resources(musb, pdev->resource,
  89. pdev->num_resources);
  90. if (ret) {
  91. dev_err(&pdev->dev, "failed to add resources\n");
  92. goto err4;
  93. }
  94. ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
  95. if (ret) {
  96. dev_err(&pdev->dev, "failed to add platform_data\n");
  97. goto err4;
  98. }
  99. ret = platform_device_add(musb);
  100. if (ret) {
  101. dev_err(&pdev->dev, "failed to register musb device\n");
  102. goto err4;
  103. }
  104. return 0;
  105. err4:
  106. clk_disable(clk);
  107. err3:
  108. clk_put(clk);
  109. err2:
  110. platform_device_put(musb);
  111. err1:
  112. kfree(glue);
  113. err0:
  114. return ret;
  115. }
  116. static int __exit ux500_remove(struct platform_device *pdev)
  117. {
  118. struct ux500_glue *glue = platform_get_drvdata(pdev);
  119. platform_device_del(glue->musb);
  120. platform_device_put(glue->musb);
  121. clk_disable(glue->clk);
  122. clk_put(glue->clk);
  123. kfree(glue);
  124. return 0;
  125. }
  126. #ifdef CONFIG_PM
  127. static int ux500_suspend(struct device *dev)
  128. {
  129. struct ux500_glue *glue = dev_get_drvdata(dev);
  130. struct musb *musb = glue_to_musb(glue);
  131. otg_set_suspend(musb->xceiv, 1);
  132. clk_disable(glue->clk);
  133. return 0;
  134. }
  135. static int ux500_resume(struct device *dev)
  136. {
  137. struct ux500_glue *glue = dev_get_drvdata(dev);
  138. struct musb *musb = glue_to_musb(glue);
  139. int ret;
  140. ret = clk_enable(glue->clk);
  141. if (ret) {
  142. dev_err(dev, "failed to enable clock\n");
  143. return ret;
  144. }
  145. otg_set_suspend(musb->xceiv, 0);
  146. return 0;
  147. }
  148. static const struct dev_pm_ops ux500_pm_ops = {
  149. .suspend = ux500_suspend,
  150. .resume = ux500_resume,
  151. };
  152. #define DEV_PM_OPS (&ux500_pm_ops)
  153. #else
  154. #define DEV_PM_OPS NULL
  155. #endif
  156. static struct platform_driver ux500_driver = {
  157. .remove = __exit_p(ux500_remove),
  158. .driver = {
  159. .name = "musb-ux500",
  160. .pm = DEV_PM_OPS,
  161. },
  162. };
  163. MODULE_DESCRIPTION("UX500 MUSB Glue Layer");
  164. MODULE_AUTHOR("Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>");
  165. MODULE_LICENSE("GPL v2");
  166. static int __init ux500_init(void)
  167. {
  168. return platform_driver_probe(&ux500_driver, ux500_probe);
  169. }
  170. subsys_initcall(ux500_init);
  171. static void __exit ux500_exit(void)
  172. {
  173. platform_driver_unregister(&ux500_driver);
  174. }
  175. module_exit(ux500_exit);