nop-usb-xceiv.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * drivers/usb/otg/nop-usb-xceiv.c
  3. *
  4. * NOP USB transceiver for all USB transceiver which are either built-in
  5. * into USB IP or which are mostly autonomous.
  6. *
  7. * Copyright (C) 2009 Texas Instruments Inc
  8. * Author: Ajay Kumar Gupta <ajay.gupta@ti.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. *
  24. * Current status:
  25. * This provides a "nop" transceiver for PHYs which are
  26. * autonomous such as isp1504, isp1707, etc.
  27. */
  28. #include <linux/module.h>
  29. #include <linux/platform_device.h>
  30. #include <linux/dma-mapping.h>
  31. #include <linux/usb/otg.h>
  32. #include <linux/usb/nop-usb-xceiv.h>
  33. #include <linux/slab.h>
  34. struct nop_usb_xceiv {
  35. struct usb_phy phy;
  36. struct device *dev;
  37. };
  38. static struct platform_device *pd;
  39. void usb_nop_xceiv_register(void)
  40. {
  41. if (pd)
  42. return;
  43. pd = platform_device_register_simple("nop_usb_xceiv", -1, NULL, 0);
  44. if (!pd) {
  45. printk(KERN_ERR "Unable to register usb nop transceiver\n");
  46. return;
  47. }
  48. }
  49. EXPORT_SYMBOL(usb_nop_xceiv_register);
  50. void usb_nop_xceiv_unregister(void)
  51. {
  52. platform_device_unregister(pd);
  53. pd = NULL;
  54. }
  55. EXPORT_SYMBOL(usb_nop_xceiv_unregister);
  56. static int nop_set_suspend(struct usb_phy *x, int suspend)
  57. {
  58. return 0;
  59. }
  60. static int nop_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget)
  61. {
  62. if (!otg)
  63. return -ENODEV;
  64. if (!gadget) {
  65. otg->gadget = NULL;
  66. return -ENODEV;
  67. }
  68. otg->gadget = gadget;
  69. otg->phy->state = OTG_STATE_B_IDLE;
  70. return 0;
  71. }
  72. static int nop_set_host(struct usb_otg *otg, struct usb_bus *host)
  73. {
  74. if (!otg)
  75. return -ENODEV;
  76. if (!host) {
  77. otg->host = NULL;
  78. return -ENODEV;
  79. }
  80. otg->host = host;
  81. return 0;
  82. }
  83. static int nop_usb_xceiv_probe(struct platform_device *pdev)
  84. {
  85. struct nop_usb_xceiv_platform_data *pdata = pdev->dev.platform_data;
  86. struct nop_usb_xceiv *nop;
  87. enum usb_phy_type type = USB_PHY_TYPE_USB2;
  88. int err;
  89. nop = kzalloc(sizeof *nop, GFP_KERNEL);
  90. if (!nop)
  91. return -ENOMEM;
  92. nop->phy.otg = kzalloc(sizeof *nop->phy.otg, GFP_KERNEL);
  93. if (!nop->phy.otg) {
  94. kfree(nop);
  95. return -ENOMEM;
  96. }
  97. if (pdata)
  98. type = pdata->type;
  99. nop->dev = &pdev->dev;
  100. nop->phy.dev = nop->dev;
  101. nop->phy.label = "nop-xceiv";
  102. nop->phy.set_suspend = nop_set_suspend;
  103. nop->phy.state = OTG_STATE_UNDEFINED;
  104. nop->phy.otg->phy = &nop->phy;
  105. nop->phy.otg->set_host = nop_set_host;
  106. nop->phy.otg->set_peripheral = nop_set_peripheral;
  107. err = usb_add_phy(&nop->phy, type);
  108. if (err) {
  109. dev_err(&pdev->dev, "can't register transceiver, err: %d\n",
  110. err);
  111. goto exit;
  112. }
  113. platform_set_drvdata(pdev, nop);
  114. ATOMIC_INIT_NOTIFIER_HEAD(&nop->phy.notifier);
  115. return 0;
  116. exit:
  117. kfree(nop->phy.otg);
  118. kfree(nop);
  119. return err;
  120. }
  121. static int nop_usb_xceiv_remove(struct platform_device *pdev)
  122. {
  123. struct nop_usb_xceiv *nop = platform_get_drvdata(pdev);
  124. usb_remove_phy(&nop->phy);
  125. platform_set_drvdata(pdev, NULL);
  126. kfree(nop->phy.otg);
  127. kfree(nop);
  128. return 0;
  129. }
  130. static struct platform_driver nop_usb_xceiv_driver = {
  131. .probe = nop_usb_xceiv_probe,
  132. .remove = nop_usb_xceiv_remove,
  133. .driver = {
  134. .name = "nop_usb_xceiv",
  135. .owner = THIS_MODULE,
  136. },
  137. };
  138. static int __init nop_usb_xceiv_init(void)
  139. {
  140. return platform_driver_register(&nop_usb_xceiv_driver);
  141. }
  142. subsys_initcall(nop_usb_xceiv_init);
  143. static void __exit nop_usb_xceiv_exit(void)
  144. {
  145. platform_driver_unregister(&nop_usb_xceiv_driver);
  146. }
  147. module_exit(nop_usb_xceiv_exit);
  148. MODULE_ALIAS("platform:nop_usb_xceiv");
  149. MODULE_AUTHOR("Texas Instruments Inc");
  150. MODULE_DESCRIPTION("NOP USB Transceiver driver");
  151. MODULE_LICENSE("GPL");