ci_hdrc_msm.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. #include <linux/module.h>
  8. #include <linux/platform_device.h>
  9. #include <linux/pm_runtime.h>
  10. #include <linux/usb/msm_hsusb_hw.h>
  11. #include <linux/usb/ulpi.h>
  12. #include <linux/usb/gadget.h>
  13. #include <linux/usb/chipidea.h>
  14. #include "ci.h"
  15. #define MSM_USB_BASE (ci->hw_bank.abs)
  16. static void ci_hdrc_msm_notify_event(struct ci_hdrc *ci, unsigned event)
  17. {
  18. struct device *dev = ci->gadget.dev.parent;
  19. int val;
  20. switch (event) {
  21. case CI_HDRC_CONTROLLER_RESET_EVENT:
  22. dev_dbg(dev, "CI_HDRC_CONTROLLER_RESET_EVENT received\n");
  23. writel(0, USB_AHBBURST);
  24. writel(0, USB_AHBMODE);
  25. break;
  26. case CI_HDRC_CONTROLLER_STOPPED_EVENT:
  27. dev_dbg(dev, "CI_HDRC_CONTROLLER_STOPPED_EVENT received\n");
  28. /*
  29. * Put the transceiver in non-driving mode. Otherwise host
  30. * may not detect soft-disconnection.
  31. */
  32. val = usb_phy_io_read(ci->transceiver, ULPI_FUNC_CTRL);
  33. val &= ~ULPI_FUNC_CTRL_OPMODE_MASK;
  34. val |= ULPI_FUNC_CTRL_OPMODE_NONDRIVING;
  35. usb_phy_io_write(ci->transceiver, val, ULPI_FUNC_CTRL);
  36. break;
  37. default:
  38. dev_dbg(dev, "unknown ci_hdrc event\n");
  39. break;
  40. }
  41. }
  42. static struct ci_hdrc_platform_data ci_hdrc_msm_platdata = {
  43. .name = "ci_hdrc_msm",
  44. .capoffset = DEF_CAPOFFSET,
  45. .flags = CI_HDRC_REGS_SHARED |
  46. CI_HDRC_REQUIRE_TRANSCEIVER |
  47. CI_HDRC_DISABLE_STREAMING,
  48. .notify_event = ci_hdrc_msm_notify_event,
  49. };
  50. static int ci_hdrc_msm_probe(struct platform_device *pdev)
  51. {
  52. struct platform_device *plat_ci;
  53. struct usb_phy *phy;
  54. dev_dbg(&pdev->dev, "ci_hdrc_msm_probe\n");
  55. /*
  56. * OTG(PHY) driver takes care of PHY initialization, clock management,
  57. * powering up VBUS, mapping of registers address space and power
  58. * management.
  59. */
  60. phy = devm_usb_get_phy_by_phandle(&pdev->dev, "usb-phy", 0);
  61. if (IS_ERR(phy))
  62. return PTR_ERR(phy);
  63. ci_hdrc_msm_platdata.phy = phy;
  64. plat_ci = ci_hdrc_add_device(&pdev->dev,
  65. pdev->resource, pdev->num_resources,
  66. &ci_hdrc_msm_platdata);
  67. if (IS_ERR(plat_ci)) {
  68. dev_err(&pdev->dev, "ci_hdrc_add_device failed!\n");
  69. return PTR_ERR(plat_ci);
  70. }
  71. platform_set_drvdata(pdev, plat_ci);
  72. pm_runtime_no_callbacks(&pdev->dev);
  73. pm_runtime_enable(&pdev->dev);
  74. return 0;
  75. }
  76. static int ci_hdrc_msm_remove(struct platform_device *pdev)
  77. {
  78. struct platform_device *plat_ci = platform_get_drvdata(pdev);
  79. pm_runtime_disable(&pdev->dev);
  80. ci_hdrc_remove_device(plat_ci);
  81. return 0;
  82. }
  83. static const struct of_device_id msm_ci_dt_match[] = {
  84. { .compatible = "qcom,ci-hdrc", },
  85. { }
  86. };
  87. MODULE_DEVICE_TABLE(of, msm_ci_dt_match);
  88. static struct platform_driver ci_hdrc_msm_driver = {
  89. .probe = ci_hdrc_msm_probe,
  90. .remove = ci_hdrc_msm_remove,
  91. .driver = {
  92. .name = "msm_hsusb",
  93. .of_match_table = msm_ci_dt_match,
  94. },
  95. };
  96. module_platform_driver(ci_hdrc_msm_driver);
  97. MODULE_ALIAS("platform:msm_hsusb");
  98. MODULE_ALIAS("platform:ci13xxx_msm");
  99. MODULE_LICENSE("GPL v2");