nop-usb-xceiv.c 4.0 KB

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