nop-usb-xceiv.c 3.9 KB

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