106-phy-add-h3-usbphys.patch 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. From 317c5224795b41a08ba8c08573d74ba95096faa5 Mon Sep 17 00:00:00 2001
  2. From: Reinder de Haan <patchesrdh@mveas.com>
  3. Date: Fri, 11 Dec 2015 16:32:18 +0100
  4. Subject: [PATCH] phy-sun4i-usb: Add support for the host usb-phys found on the
  5. H3 SoC
  6. Note this commit only adds support for phys 1-3, phy 0, the otg phy, is
  7. not yet (fully) supported after this commit.
  8. Signed-off-by: Reinder de Haan <patchesrdh@mveas.com>
  9. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  10. Acked-by: Rob Herring <robh@kernel.org>
  11. Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>
  12. ---
  13. .../devicetree/bindings/phy/sun4i-usb-phy.txt | 1 +
  14. drivers/phy/phy-sun4i-usb.c | 41 +++++++++++++++++-----
  15. 2 files changed, 33 insertions(+), 9 deletions(-)
  16. --- a/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
  17. +++ b/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
  18. @@ -9,6 +9,7 @@ Required properties:
  19. * allwinner,sun7i-a20-usb-phy
  20. * allwinner,sun8i-a23-usb-phy
  21. * allwinner,sun8i-a33-usb-phy
  22. + * allwinner,sun8i-h3-usb-phy
  23. - reg : a list of offset + length pairs
  24. - reg-names :
  25. * "phy_ctrl"
  26. --- a/drivers/phy/phy-sun4i-usb.c
  27. +++ b/drivers/phy/phy-sun4i-usb.c
  28. @@ -47,6 +47,9 @@
  29. #define REG_PHYBIST 0x08
  30. #define REG_PHYTUNE 0x0c
  31. #define REG_PHYCTL_A33 0x10
  32. +#define REG_PHY_UNK_H3 0x20
  33. +
  34. +#define REG_PMU_UNK_H3 0x10
  35. #define PHYCTL_DATA BIT(7)
  36. @@ -80,7 +83,7 @@
  37. #define PHY_DISCON_TH_SEL 0x2a
  38. #define PHY_SQUELCH_DETECT 0x3c
  39. -#define MAX_PHYS 3
  40. +#define MAX_PHYS 4
  41. /*
  42. * Note do not raise the debounce time, we must report Vusb high within 100ms
  43. @@ -92,6 +95,7 @@
  44. enum sun4i_usb_phy_type {
  45. sun4i_a10_phy,
  46. sun8i_a33_phy,
  47. + sun8i_h3_phy,
  48. };
  49. struct sun4i_usb_phy_cfg {
  50. @@ -239,6 +243,7 @@ static int sun4i_usb_phy_init(struct phy
  51. struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
  52. struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
  53. int ret;
  54. + u32 val;
  55. ret = clk_prepare_enable(phy->clk);
  56. if (ret)
  57. @@ -250,16 +255,26 @@ static int sun4i_usb_phy_init(struct phy
  58. return ret;
  59. }
  60. - /* Enable USB 45 Ohm resistor calibration */
  61. - if (phy->index == 0)
  62. - sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN, 0x01, 1);
  63. -
  64. - /* Adjust PHY's magnitude and rate */
  65. - sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, 0x14, 5);
  66. -
  67. - /* Disconnect threshold adjustment */
  68. - sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL,
  69. - data->cfg->disc_thresh, 2);
  70. + if (data->cfg->type == sun8i_h3_phy) {
  71. + if (phy->index == 0) {
  72. + val = readl(data->base + REG_PHY_UNK_H3);
  73. + writel(val & ~1, data->base + REG_PHY_UNK_H3);
  74. + }
  75. +
  76. + val = readl(phy->pmu + REG_PMU_UNK_H3);
  77. + writel(val & ~2, phy->pmu + REG_PMU_UNK_H3);
  78. + } else {
  79. + /* Enable USB 45 Ohm resistor calibration */
  80. + if (phy->index == 0)
  81. + sun4i_usb_phy_write(phy, PHY_RES45_CAL_EN, 0x01, 1);
  82. +
  83. + /* Adjust PHY's magnitude and rate */
  84. + sun4i_usb_phy_write(phy, PHY_TX_AMPLITUDE_TUNE, 0x14, 5);
  85. +
  86. + /* Disconnect threshold adjustment */
  87. + sun4i_usb_phy_write(phy, PHY_DISCON_TH_SEL,
  88. + data->cfg->disc_thresh, 2);
  89. + }
  90. sun4i_usb_phy_passby(phy, 1);
  91. @@ -726,6 +741,13 @@ static const struct sun4i_usb_phy_cfg su
  92. .dedicated_clocks = true,
  93. };
  94. +static const struct sun4i_usb_phy_cfg sun8i_h3_cfg = {
  95. + .num_phys = 4,
  96. + .type = sun8i_h3_phy,
  97. + .disc_thresh = 3,
  98. + .dedicated_clocks = true,
  99. +};
  100. +
  101. static const struct of_device_id sun4i_usb_phy_of_match[] = {
  102. { .compatible = "allwinner,sun4i-a10-usb-phy", .data = &sun4i_a10_cfg },
  103. { .compatible = "allwinner,sun5i-a13-usb-phy", .data = &sun5i_a13_cfg },
  104. @@ -733,6 +755,7 @@ static const struct of_device_id sun4i_u
  105. { .compatible = "allwinner,sun7i-a20-usb-phy", .data = &sun7i_a20_cfg },
  106. { .compatible = "allwinner,sun8i-a23-usb-phy", .data = &sun8i_a23_cfg },
  107. { .compatible = "allwinner,sun8i-a33-usb-phy", .data = &sun8i_a33_cfg },
  108. + { .compatible = "allwinner,sun8i-h3-usb-phy", .data = &sun8i_h3_cfg },
  109. { },
  110. };
  111. MODULE_DEVICE_TABLE(of, sun4i_usb_phy_of_match);