ci_hdrc_msm.c 2.9 KB

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