ux500.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. glue->dev = &pdev->dev;
  82. glue->musb = musb;
  83. glue->clk = clk;
  84. pdata->platform_ops = &ux500_ops;
  85. platform_set_drvdata(pdev, glue);
  86. ret = platform_device_add_resources(musb, pdev->resource,
  87. pdev->num_resources);
  88. if (ret) {
  89. dev_err(&pdev->dev, "failed to add resources\n");
  90. goto err4;
  91. }
  92. ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
  93. if (ret) {
  94. dev_err(&pdev->dev, "failed to add platform_data\n");
  95. goto err4;
  96. }
  97. ret = platform_device_add(musb);
  98. if (ret) {
  99. dev_err(&pdev->dev, "failed to register musb device\n");
  100. goto err4;
  101. }
  102. return 0;
  103. err4:
  104. clk_disable(clk);
  105. err3:
  106. clk_put(clk);
  107. err2:
  108. platform_device_put(musb);
  109. err1:
  110. kfree(glue);
  111. err0:
  112. return ret;
  113. }
  114. static int __exit ux500_remove(struct platform_device *pdev)
  115. {
  116. struct ux500_glue *glue = platform_get_drvdata(pdev);
  117. platform_device_del(glue->musb);
  118. platform_device_put(glue->musb);
  119. clk_disable(glue->clk);
  120. clk_put(glue->clk);
  121. kfree(glue);
  122. return 0;
  123. }
  124. #ifdef CONFIG_PM
  125. static int ux500_suspend(struct device *dev)
  126. {
  127. struct ux500_glue *glue = dev_get_drvdata(dev);
  128. struct musb *musb = glue_to_musb(glue);
  129. otg_set_suspend(musb->xceiv, 1);
  130. clk_disable(glue->clk);
  131. return 0;
  132. }
  133. static int ux500_resume(struct device *dev)
  134. {
  135. struct ux500_glue *glue = dev_get_drvdata(dev);
  136. struct musb *musb = glue_to_musb(glue);
  137. int ret;
  138. ret = clk_enable(glue->clk);
  139. if (ret) {
  140. dev_err(dev, "failed to enable clock\n");
  141. return ret;
  142. }
  143. otg_set_suspend(musb->xceiv, 0);
  144. return 0;
  145. }
  146. static const struct dev_pm_ops ux500_pm_ops = {
  147. .suspend = ux500_suspend,
  148. .resume = ux500_resume,
  149. };
  150. #define DEV_PM_OPS (&ux500_pm_ops)
  151. #else
  152. #define DEV_PM_OPS NULL
  153. #endif
  154. static struct platform_driver ux500_driver = {
  155. .remove = __exit_p(ux500_remove),
  156. .driver = {
  157. .name = "musb-ux500",
  158. .pm = DEV_PM_OPS,
  159. },
  160. };
  161. MODULE_DESCRIPTION("UX500 MUSB Glue Layer");
  162. MODULE_AUTHOR("Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>");
  163. MODULE_LICENSE("GPL v2");
  164. static int __init ux500_init(void)
  165. {
  166. return platform_driver_probe(&ux500_driver, ux500_probe);
  167. }
  168. subsys_initcall(ux500_init);
  169. static void __exit ux500_exit(void)
  170. {
  171. platform_driver_unregister(&ux500_driver);
  172. }
  173. module_exit(ux500_exit);