ci13xxx_msm.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* Copyright (c) 2010, Code Aurora Forum. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, write to the Free Software
  14. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. * 02110-1301, USA.
  16. *
  17. */
  18. #include <linux/module.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/pm_runtime.h>
  21. #include <linux/usb/msm_hsusb_hw.h>
  22. #include <linux/usb/ulpi.h>
  23. #include "ci13xxx_udc.c"
  24. #define MSM_USB_BASE (udc->regs)
  25. static irqreturn_t msm_udc_irq(int irq, void *data)
  26. {
  27. return udc_irq();
  28. }
  29. static void ci13xxx_msm_notify_event(struct ci13xxx *udc, unsigned event)
  30. {
  31. struct device *dev = udc->gadget.dev.parent;
  32. int val;
  33. switch (event) {
  34. case CI13XXX_CONTROLLER_RESET_EVENT:
  35. dev_dbg(dev, "CI13XXX_CONTROLLER_RESET_EVENT received\n");
  36. writel(0, USB_AHBBURST);
  37. writel(0, USB_AHBMODE);
  38. break;
  39. case CI13XXX_CONTROLLER_STOPPED_EVENT:
  40. dev_dbg(dev, "CI13XXX_CONTROLLER_STOPPED_EVENT received\n");
  41. /*
  42. * Put the transceiver in non-driving mode. Otherwise host
  43. * may not detect soft-disconnection.
  44. */
  45. val = otg_io_read(udc->transceiver, ULPI_FUNC_CTRL);
  46. val &= ~ULPI_FUNC_CTRL_OPMODE_MASK;
  47. val |= ULPI_FUNC_CTRL_OPMODE_NONDRIVING;
  48. otg_io_write(udc->transceiver, val, ULPI_FUNC_CTRL);
  49. break;
  50. default:
  51. dev_dbg(dev, "unknown ci13xxx_udc event\n");
  52. break;
  53. }
  54. }
  55. static struct ci13xxx_udc_driver ci13xxx_msm_udc_driver = {
  56. .name = "ci13xxx_msm",
  57. .flags = CI13XXX_REGS_SHARED |
  58. CI13XXX_REQUIRE_TRANSCEIVER |
  59. CI13XXX_PULLUP_ON_VBUS |
  60. CI13XXX_DISABLE_STREAMING,
  61. .notify_event = ci13xxx_msm_notify_event,
  62. };
  63. static int ci13xxx_msm_probe(struct platform_device *pdev)
  64. {
  65. struct resource *res;
  66. void __iomem *regs;
  67. int irq;
  68. int ret;
  69. dev_dbg(&pdev->dev, "ci13xxx_msm_probe\n");
  70. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  71. if (!res) {
  72. dev_err(&pdev->dev, "failed to get platform resource mem\n");
  73. return -ENXIO;
  74. }
  75. regs = ioremap(res->start, resource_size(res));
  76. if (!regs) {
  77. dev_err(&pdev->dev, "ioremap failed\n");
  78. return -ENOMEM;
  79. }
  80. ret = udc_probe(&ci13xxx_msm_udc_driver, &pdev->dev, regs);
  81. if (ret < 0) {
  82. dev_err(&pdev->dev, "udc_probe failed\n");
  83. goto iounmap;
  84. }
  85. irq = platform_get_irq(pdev, 0);
  86. if (irq < 0) {
  87. dev_err(&pdev->dev, "IRQ not found\n");
  88. ret = -ENXIO;
  89. goto udc_remove;
  90. }
  91. ret = request_irq(irq, msm_udc_irq, IRQF_SHARED, pdev->name, pdev);
  92. if (ret < 0) {
  93. dev_err(&pdev->dev, "request_irq failed\n");
  94. goto udc_remove;
  95. }
  96. pm_runtime_no_callbacks(&pdev->dev);
  97. pm_runtime_enable(&pdev->dev);
  98. return 0;
  99. udc_remove:
  100. udc_remove();
  101. iounmap:
  102. iounmap(regs);
  103. return ret;
  104. }
  105. static struct platform_driver ci13xxx_msm_driver = {
  106. .probe = ci13xxx_msm_probe,
  107. .driver = { .name = "msm_hsusb", },
  108. };
  109. static int __init ci13xxx_msm_init(void)
  110. {
  111. return platform_driver_register(&ci13xxx_msm_driver);
  112. }
  113. module_init(ci13xxx_msm_init);