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