ux500.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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 ret = -ENOMEM;
  60. glue = kzalloc(sizeof(*glue), GFP_KERNEL);
  61. if (!glue) {
  62. dev_err(&pdev->dev, "failed to allocate glue context\n");
  63. goto err0;
  64. }
  65. musb = platform_device_alloc("musb-hdrc", -1);
  66. if (!musb) {
  67. dev_err(&pdev->dev, "failed to allocate musb device\n");
  68. goto err1;
  69. }
  70. clk = clk_get(&pdev->dev, "usb");
  71. if (IS_ERR(clk)) {
  72. dev_err(&pdev->dev, "failed to get clock\n");
  73. ret = PTR_ERR(clk);
  74. goto err2;
  75. }
  76. ret = clk_enable(clk);
  77. if (ret) {
  78. dev_err(&pdev->dev, "failed to enable clock\n");
  79. goto err3;
  80. }
  81. musb->dev.parent = &pdev->dev;
  82. musb->dev.dma_mask = pdev->dev.dma_mask;
  83. musb->dev.coherent_dma_mask = pdev->dev.coherent_dma_mask;
  84. glue->dev = &pdev->dev;
  85. glue->musb = musb;
  86. glue->clk = clk;
  87. pdata->platform_ops = &ux500_ops;
  88. platform_set_drvdata(pdev, glue);
  89. ret = platform_device_add_resources(musb, pdev->resource,
  90. pdev->num_resources);
  91. if (ret) {
  92. dev_err(&pdev->dev, "failed to add resources\n");
  93. goto err4;
  94. }
  95. ret = platform_device_add_data(musb, pdata, sizeof(*pdata));
  96. if (ret) {
  97. dev_err(&pdev->dev, "failed to add platform_data\n");
  98. goto err4;
  99. }
  100. ret = platform_device_add(musb);
  101. if (ret) {
  102. dev_err(&pdev->dev, "failed to register musb device\n");
  103. goto err4;
  104. }
  105. return 0;
  106. err4:
  107. clk_disable(clk);
  108. err3:
  109. clk_put(clk);
  110. err2:
  111. platform_device_put(musb);
  112. err1:
  113. kfree(glue);
  114. err0:
  115. return ret;
  116. }
  117. static int __devexit ux500_remove(struct platform_device *pdev)
  118. {
  119. struct ux500_glue *glue = platform_get_drvdata(pdev);
  120. platform_device_del(glue->musb);
  121. platform_device_put(glue->musb);
  122. clk_disable(glue->clk);
  123. clk_put(glue->clk);
  124. kfree(glue);
  125. return 0;
  126. }
  127. #ifdef CONFIG_PM
  128. static int ux500_suspend(struct device *dev)
  129. {
  130. struct ux500_glue *glue = dev_get_drvdata(dev);
  131. struct musb *musb = glue_to_musb(glue);
  132. usb_phy_set_suspend(musb->xceiv, 1);
  133. clk_disable(glue->clk);
  134. return 0;
  135. }
  136. static int ux500_resume(struct device *dev)
  137. {
  138. struct ux500_glue *glue = dev_get_drvdata(dev);
  139. struct musb *musb = glue_to_musb(glue);
  140. int ret;
  141. ret = clk_enable(glue->clk);
  142. if (ret) {
  143. dev_err(dev, "failed to enable clock\n");
  144. return ret;
  145. }
  146. usb_phy_set_suspend(musb->xceiv, 0);
  147. return 0;
  148. }
  149. static const struct dev_pm_ops ux500_pm_ops = {
  150. .suspend = ux500_suspend,
  151. .resume = ux500_resume,
  152. };
  153. #define DEV_PM_OPS (&ux500_pm_ops)
  154. #else
  155. #define DEV_PM_OPS NULL
  156. #endif
  157. static struct platform_driver ux500_driver = {
  158. .probe = ux500_probe,
  159. .remove = __devexit_p(ux500_remove),
  160. .driver = {
  161. .name = "musb-ux500",
  162. .pm = DEV_PM_OPS,
  163. },
  164. };
  165. MODULE_DESCRIPTION("UX500 MUSB Glue Layer");
  166. MODULE_AUTHOR("Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>");
  167. MODULE_LICENSE("GPL v2");
  168. static int __init ux500_init(void)
  169. {
  170. return platform_driver_register(&ux500_driver);
  171. }
  172. module_init(ux500_init);
  173. static void __exit ux500_exit(void)
  174. {
  175. platform_driver_unregister(&ux500_driver);
  176. }
  177. module_exit(ux500_exit);