ux500.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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/err.h>
  26. #include <linux/io.h>
  27. #include <linux/platform_device.h>
  28. #include "musb_core.h"
  29. struct ux500_glue {
  30. struct device *dev;
  31. struct platform_device *musb;
  32. struct clk *clk;
  33. };
  34. #define glue_to_musb(g) platform_get_drvdata(g->musb)
  35. static int ux500_musb_init(struct musb *musb)
  36. {
  37. musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
  38. if (IS_ERR_OR_NULL(musb->xceiv)) {
  39. pr_err("HS USB OTG: no transceiver configured\n");
  40. return -ENODEV;
  41. }
  42. return 0;
  43. }
  44. static int ux500_musb_exit(struct musb *musb)
  45. {
  46. usb_put_phy(musb->xceiv);
  47. return 0;
  48. }
  49. static const struct musb_platform_ops ux500_ops = {
  50. .init = ux500_musb_init,
  51. .exit = ux500_musb_exit,
  52. };
  53. static int __devinit ux500_probe(struct platform_device *pdev)
  54. {
  55. struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data;
  56. struct platform_device *musb;
  57. struct ux500_glue *glue;
  58. struct clk *clk;
  59. int musbid;
  60. int ret = -ENOMEM;
  61. glue = kzalloc(sizeof(*glue), GFP_KERNEL);
  62. if (!glue) {
  63. dev_err(&pdev->dev, "failed to allocate glue context\n");
  64. goto err0;
  65. }
  66. /* get the musb id */
  67. musbid = musb_get_id(&pdev->dev, GFP_KERNEL);
  68. if (musbid < 0) {
  69. dev_err(&pdev->dev, "failed to allocate musb id\n");
  70. ret = -ENOMEM;
  71. goto err1;
  72. }
  73. musb = platform_device_alloc("musb-hdrc", musbid);
  74. if (!musb) {
  75. dev_err(&pdev->dev, "failed to allocate musb device\n");
  76. goto err2;
  77. }
  78. clk = clk_get(&pdev->dev, "usb");
  79. if (IS_ERR(clk)) {
  80. dev_err(&pdev->dev, "failed to get clock\n");
  81. ret = PTR_ERR(clk);
  82. goto err3;
  83. }
  84. ret = clk_enable(clk);
  85. if (ret) {
  86. dev_err(&pdev->dev, "failed to enable clock\n");
  87. goto err4;
  88. }
  89. musb->id = musbid;
  90. musb->dev.parent = &pdev->dev;
  91. musb->dev.dma_mask = pdev->dev.dma_mask;
  92. musb->dev.coherent_dma_mask = pdev->dev.coherent_dma_mask;
  93. glue->dev = &pdev->dev;
  94. glue->musb = musb;
  95. glue->clk = clk;
  96. pdata->platform_ops = &ux500_ops;
  97. platform_set_drvdata(pdev, glue);
  98. ret = platform_device_add_resources(musb, pdev->resource,
  99. pdev->num_resources);
  100. if (ret) {
  101. dev_err(&pdev->dev, "failed to add resources\n");
  102. goto err5;
  103. }
  104. ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
  105. if (ret) {
  106. dev_err(&pdev->dev, "failed to add platform_data\n");
  107. goto err5;
  108. }
  109. ret = platform_device_add(musb);
  110. if (ret) {
  111. dev_err(&pdev->dev, "failed to register musb device\n");
  112. goto err5;
  113. }
  114. return 0;
  115. err5:
  116. clk_disable(clk);
  117. err4:
  118. clk_put(clk);
  119. err3:
  120. platform_device_put(musb);
  121. err2:
  122. musb_put_id(&pdev->dev, musbid);
  123. err1:
  124. kfree(glue);
  125. err0:
  126. return ret;
  127. }
  128. static int __devexit ux500_remove(struct platform_device *pdev)
  129. {
  130. struct ux500_glue *glue = platform_get_drvdata(pdev);
  131. musb_put_id(&pdev->dev, glue->musb->id);
  132. platform_device_del(glue->musb);
  133. platform_device_put(glue->musb);
  134. clk_disable(glue->clk);
  135. clk_put(glue->clk);
  136. kfree(glue);
  137. return 0;
  138. }
  139. #ifdef CONFIG_PM
  140. static int ux500_suspend(struct device *dev)
  141. {
  142. struct ux500_glue *glue = dev_get_drvdata(dev);
  143. struct musb *musb = glue_to_musb(glue);
  144. usb_phy_set_suspend(musb->xceiv, 1);
  145. clk_disable(glue->clk);
  146. return 0;
  147. }
  148. static int ux500_resume(struct device *dev)
  149. {
  150. struct ux500_glue *glue = dev_get_drvdata(dev);
  151. struct musb *musb = glue_to_musb(glue);
  152. int ret;
  153. ret = clk_enable(glue->clk);
  154. if (ret) {
  155. dev_err(dev, "failed to enable clock\n");
  156. return ret;
  157. }
  158. usb_phy_set_suspend(musb->xceiv, 0);
  159. return 0;
  160. }
  161. static const struct dev_pm_ops ux500_pm_ops = {
  162. .suspend = ux500_suspend,
  163. .resume = ux500_resume,
  164. };
  165. #define DEV_PM_OPS (&ux500_pm_ops)
  166. #else
  167. #define DEV_PM_OPS NULL
  168. #endif
  169. static struct platform_driver ux500_driver = {
  170. .probe = ux500_probe,
  171. .remove = __devexit_p(ux500_remove),
  172. .driver = {
  173. .name = "musb-ux500",
  174. .pm = DEV_PM_OPS,
  175. },
  176. };
  177. MODULE_DESCRIPTION("UX500 MUSB Glue Layer");
  178. MODULE_AUTHOR("Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>");
  179. MODULE_LICENSE("GPL v2");
  180. static int __init ux500_init(void)
  181. {
  182. return platform_driver_register(&ux500_driver);
  183. }
  184. module_init(ux500_init);
  185. static void __exit ux500_exit(void)
  186. {
  187. platform_driver_unregister(&ux500_driver);
  188. }
  189. module_exit(ux500_exit);