171-musb-add-support-for-a31.patch 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. From 132e23775779cc895c37f7883c33a60a1a8a7cdd Mon Sep 17 00:00:00 2001
  2. From: Hans de Goede <hdegoede@redhat.com>
  3. Date: Wed, 8 Jul 2015 16:41:39 +0200
  4. Subject: [PATCH] usb: musb: sunxi: Add support for musb controller in A31 SoC
  5. The A31 SoC uses the same musb controller as found in earlier SoCs, but it
  6. is hooked up slightly different. Its SRAM is private and no longer controlled
  7. through the SRAM controller, and its reset is controlled via a separate
  8. reset controller. This commit adds support for this setup.
  9. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  10. Signed-off-by: Felipe Balbi <balbi@ti.com>
  11. ---
  12. .../bindings/usb/allwinner,sun4i-a10-musb.txt | 3 +-
  13. drivers/usb/musb/sunxi.c | 50 +++++++++++++++++++---
  14. 2 files changed, 46 insertions(+), 7 deletions(-)
  15. --- a/Documentation/devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt
  16. +++ b/Documentation/devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt
  17. @@ -2,9 +2,10 @@ Allwinner sun4i A10 musb DRC/OTG control
  18. -------------------------------------------
  19. Required properties:
  20. - - compatible : "allwinner,sun4i-a10-musb"
  21. + - compatible : "allwinner,sun4i-a10-musb" or "allwinner,sun6i-a31-musb"
  22. - reg : mmio address range of the musb controller
  23. - clocks : clock specifier for the musb controller ahb gate clock
  24. + - reset : reset specifier for the ahb reset (A31 and newer only)
  25. - interrupts : interrupt to which the musb controller is connected
  26. - interrupt-names : must be "mc"
  27. - phys : phy specifier for the otg phy
  28. --- a/drivers/usb/musb/sunxi.c
  29. +++ b/drivers/usb/musb/sunxi.c
  30. @@ -26,6 +26,7 @@
  31. #include <linux/of.h>
  32. #include <linux/phy/phy-sun4i-usb.h>
  33. #include <linux/platform_device.h>
  34. +#include <linux/reset.h>
  35. #include <linux/soc/sunxi/sunxi_sram.h>
  36. #include <linux/usb/musb.h>
  37. #include <linux/usb/of.h>
  38. @@ -70,6 +71,8 @@
  39. #define SUNXI_MUSB_FL_HOSTMODE_PEND 2
  40. #define SUNXI_MUSB_FL_VBUS_ON 3
  41. #define SUNXI_MUSB_FL_PHY_ON 4
  42. +#define SUNXI_MUSB_FL_HAS_SRAM 5
  43. +#define SUNXI_MUSB_FL_HAS_RESET 6
  44. /* Our read/write methods need access and do not get passed in a musb ref :| */
  45. static struct musb *sunxi_musb;
  46. @@ -78,6 +81,7 @@ struct sunxi_glue {
  47. struct device *dev;
  48. struct platform_device *musb;
  49. struct clk *clk;
  50. + struct reset_control *rst;
  51. struct phy *phy;
  52. struct platform_device *usb_phy;
  53. struct usb_phy *xceiv;
  54. @@ -229,14 +233,22 @@ static int sunxi_musb_init(struct musb *
  55. musb->phy = glue->phy;
  56. musb->xceiv = glue->xceiv;
  57. - ret = sunxi_sram_claim(musb->controller->parent);
  58. - if (ret)
  59. - return ret;
  60. + if (test_bit(SUNXI_MUSB_FL_HAS_SRAM, &glue->flags)) {
  61. + ret = sunxi_sram_claim(musb->controller->parent);
  62. + if (ret)
  63. + return ret;
  64. + }
  65. ret = clk_prepare_enable(glue->clk);
  66. if (ret)
  67. goto error_sram_release;
  68. + if (test_bit(SUNXI_MUSB_FL_HAS_RESET, &glue->flags)) {
  69. + ret = reset_control_deassert(glue->rst);
  70. + if (ret)
  71. + goto error_clk_disable;
  72. + }
  73. +
  74. writeb(SUNXI_MUSB_VEND0_PIO_MODE, musb->mregs + SUNXI_MUSB_VEND0);
  75. /* Register notifier before calling phy_init() */
  76. @@ -244,7 +256,7 @@ static int sunxi_musb_init(struct musb *
  77. ret = extcon_register_notifier(glue->extcon, EXTCON_USB_HOST,
  78. &glue->host_nb);
  79. if (ret)
  80. - goto error_clk_disable;
  81. + goto error_reset_assert;
  82. }
  83. ret = phy_init(glue->phy);
  84. @@ -273,10 +285,14 @@ error_unregister_notifier:
  85. if (musb->port_mode == MUSB_PORT_MODE_DUAL_ROLE)
  86. extcon_unregister_notifier(glue->extcon, EXTCON_USB_HOST,
  87. &glue->host_nb);
  88. +error_reset_assert:
  89. + if (test_bit(SUNXI_MUSB_FL_HAS_RESET, &glue->flags))
  90. + reset_control_assert(glue->rst);
  91. error_clk_disable:
  92. clk_disable_unprepare(glue->clk);
  93. error_sram_release:
  94. - sunxi_sram_release(musb->controller->parent);
  95. + if (test_bit(SUNXI_MUSB_FL_HAS_SRAM, &glue->flags))
  96. + sunxi_sram_release(musb->controller->parent);
  97. return ret;
  98. }
  99. @@ -296,8 +312,12 @@ static int sunxi_musb_exit(struct musb *
  100. extcon_unregister_notifier(glue->extcon, EXTCON_USB_HOST,
  101. &glue->host_nb);
  102. + if (test_bit(SUNXI_MUSB_FL_HAS_RESET, &glue->flags))
  103. + reset_control_assert(glue->rst);
  104. +
  105. clk_disable_unprepare(glue->clk);
  106. - sunxi_sram_release(musb->controller->parent);
  107. + if (test_bit(SUNXI_MUSB_FL_HAS_SRAM, &glue->flags))
  108. + sunxi_sram_release(musb->controller->parent);
  109. return 0;
  110. }
  111. @@ -617,6 +637,12 @@ static int sunxi_musb_probe(struct platf
  112. INIT_WORK(&glue->work, sunxi_musb_work);
  113. glue->host_nb.notifier_call = sunxi_musb_host_notifier;
  114. + if (of_device_is_compatible(np, "allwinner,sun4i-a10-musb"))
  115. + set_bit(SUNXI_MUSB_FL_HAS_SRAM, &glue->flags);
  116. +
  117. + if (of_device_is_compatible(np, "allwinner,sun6i-a31-musb"))
  118. + set_bit(SUNXI_MUSB_FL_HAS_RESET, &glue->flags);
  119. +
  120. glue->clk = devm_clk_get(&pdev->dev, NULL);
  121. if (IS_ERR(glue->clk)) {
  122. dev_err(&pdev->dev, "Error getting clock: %ld\n",
  123. @@ -624,6 +650,17 @@ static int sunxi_musb_probe(struct platf
  124. return PTR_ERR(glue->clk);
  125. }
  126. + if (test_bit(SUNXI_MUSB_FL_HAS_RESET, &glue->flags)) {
  127. + glue->rst = devm_reset_control_get(&pdev->dev, NULL);
  128. + if (IS_ERR(glue->rst)) {
  129. + if (PTR_ERR(glue->rst) == -EPROBE_DEFER)
  130. + return -EPROBE_DEFER;
  131. + dev_err(&pdev->dev, "Error getting reset %ld\n",
  132. + PTR_ERR(glue->rst));
  133. + return PTR_ERR(glue->rst);
  134. + }
  135. + }
  136. +
  137. glue->phy = devm_phy_get(&pdev->dev, "usb");
  138. if (IS_ERR(glue->phy)) {
  139. if (PTR_ERR(glue->phy) == -EPROBE_DEFER)
  140. @@ -685,6 +722,7 @@ static int sunxi_musb_remove(struct plat
  141. static const struct of_device_id sunxi_musb_match[] = {
  142. { .compatible = "allwinner,sun4i-a10-musb", },
  143. + { .compatible = "allwinner,sun6i-a31-musb", },
  144. {}
  145. };