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