nop-usb-xceiv.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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/slab.h>
  33. struct nop_usb_xceiv {
  34. struct usb_phy phy;
  35. struct device *dev;
  36. };
  37. static struct platform_device *pd;
  38. void usb_nop_xceiv_register(void)
  39. {
  40. if (pd)
  41. return;
  42. pd = platform_device_register_simple("nop_usb_xceiv", -1, NULL, 0);
  43. if (!pd) {
  44. printk(KERN_ERR "Unable to register usb nop transceiver\n");
  45. return;
  46. }
  47. }
  48. EXPORT_SYMBOL(usb_nop_xceiv_register);
  49. void usb_nop_xceiv_unregister(void)
  50. {
  51. platform_device_unregister(pd);
  52. pd = NULL;
  53. }
  54. EXPORT_SYMBOL(usb_nop_xceiv_unregister);
  55. static int nop_set_suspend(struct usb_phy *x, int suspend)
  56. {
  57. return 0;
  58. }
  59. static int nop_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget)
  60. {
  61. if (!otg)
  62. return -ENODEV;
  63. if (!gadget) {
  64. otg->gadget = NULL;
  65. return -ENODEV;
  66. }
  67. otg->gadget = gadget;
  68. otg->phy->state = OTG_STATE_B_IDLE;
  69. return 0;
  70. }
  71. static int nop_set_host(struct usb_otg *otg, struct usb_bus *host)
  72. {
  73. if (!otg)
  74. return -ENODEV;
  75. if (!host) {
  76. otg->host = NULL;
  77. return -ENODEV;
  78. }
  79. otg->host = host;
  80. return 0;
  81. }
  82. static int __devinit nop_usb_xceiv_probe(struct platform_device *pdev)
  83. {
  84. struct nop_usb_xceiv *nop;
  85. int err;
  86. nop = kzalloc(sizeof *nop, GFP_KERNEL);
  87. if (!nop)
  88. return -ENOMEM;
  89. nop->phy.otg = kzalloc(sizeof *nop->phy.otg, GFP_KERNEL);
  90. if (!nop->phy.otg) {
  91. kfree(nop);
  92. return -ENOMEM;
  93. }
  94. nop->dev = &pdev->dev;
  95. nop->phy.dev = nop->dev;
  96. nop->phy.label = "nop-xceiv";
  97. nop->phy.set_suspend = nop_set_suspend;
  98. nop->phy.state = OTG_STATE_UNDEFINED;
  99. nop->phy.otg->phy = &nop->phy;
  100. nop->phy.otg->set_host = nop_set_host;
  101. nop->phy.otg->set_peripheral = nop_set_peripheral;
  102. err = usb_set_transceiver(&nop->phy);
  103. if (err) {
  104. dev_err(&pdev->dev, "can't register transceiver, err: %d\n",
  105. err);
  106. goto exit;
  107. }
  108. platform_set_drvdata(pdev, nop);
  109. ATOMIC_INIT_NOTIFIER_HEAD(&nop->phy.notifier);
  110. return 0;
  111. exit:
  112. kfree(nop->phy.otg);
  113. kfree(nop);
  114. return err;
  115. }
  116. static int __devexit nop_usb_xceiv_remove(struct platform_device *pdev)
  117. {
  118. struct nop_usb_xceiv *nop = platform_get_drvdata(pdev);
  119. usb_set_transceiver(NULL);
  120. platform_set_drvdata(pdev, NULL);
  121. kfree(nop->phy.otg);
  122. kfree(nop);
  123. return 0;
  124. }
  125. static struct platform_driver nop_usb_xceiv_driver = {
  126. .probe = nop_usb_xceiv_probe,
  127. .remove = __devexit_p(nop_usb_xceiv_remove),
  128. .driver = {
  129. .name = "nop_usb_xceiv",
  130. .owner = THIS_MODULE,
  131. },
  132. };
  133. static int __init nop_usb_xceiv_init(void)
  134. {
  135. return platform_driver_register(&nop_usb_xceiv_driver);
  136. }
  137. subsys_initcall(nop_usb_xceiv_init);
  138. static void __exit nop_usb_xceiv_exit(void)
  139. {
  140. platform_driver_unregister(&nop_usb_xceiv_driver);
  141. }
  142. module_exit(nop_usb_xceiv_exit);
  143. MODULE_ALIAS("platform:nop_usb_xceiv");
  144. MODULE_AUTHOR("Texas Instruments Inc");
  145. MODULE_DESCRIPTION("NOP USB Transceiver driver");
  146. MODULE_LICENSE("GPL");