phy-berlin-usb.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. * Copyright (C) 2014 Marvell Technology Group Ltd.
  3. *
  4. * Antoine Tenart <antoine.tenart@free-electrons.com>
  5. * Jisheng Zhang <jszhang@marvell.com>
  6. *
  7. * This file is licensed under the terms of the GNU General Public
  8. * License version 2. This program is licensed "as is" without any
  9. * warranty of any kind, whether express or implied.
  10. */
  11. #include <linux/gpio.h>
  12. #include <linux/io.h>
  13. #include <linux/module.h>
  14. #include <linux/of_device.h>
  15. #include <linux/of_gpio.h>
  16. #include <linux/phy/phy.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/reset.h>
  19. #define USB_PHY_PLL 0x04
  20. #define USB_PHY_PLL_CONTROL 0x08
  21. #define USB_PHY_TX_CTRL0 0x10
  22. #define USB_PHY_TX_CTRL1 0x14
  23. #define USB_PHY_TX_CTRL2 0x18
  24. #define USB_PHY_RX_CTRL 0x20
  25. #define USB_PHY_ANALOG 0x34
  26. /* USB_PHY_PLL */
  27. #define CLK_REF_DIV(x) ((x) << 4)
  28. #define FEEDBACK_CLK_DIV(x) ((x) << 8)
  29. /* USB_PHY_PLL_CONTROL */
  30. #define CLK_STABLE BIT(0)
  31. #define PLL_CTRL_PIN BIT(1)
  32. #define PLL_CTRL_REG BIT(2)
  33. #define PLL_ON BIT(3)
  34. #define PHASE_OFF_TOL_125 (0x0 << 5)
  35. #define PHASE_OFF_TOL_250 BIT(5)
  36. #define KVC0_CALIB (0x0 << 9)
  37. #define KVC0_REG_CTRL BIT(9)
  38. #define KVC0_HIGH (0x0 << 10)
  39. #define KVC0_LOW (0x3 << 10)
  40. #define CLK_BLK_EN BIT(13)
  41. /* USB_PHY_TX_CTRL0 */
  42. #define EXT_HS_RCAL_EN BIT(3)
  43. #define EXT_FS_RCAL_EN BIT(4)
  44. #define IMPCAL_VTH_DIV(x) ((x) << 5)
  45. #define EXT_RS_RCAL_DIV(x) ((x) << 8)
  46. #define EXT_FS_RCAL_DIV(x) ((x) << 12)
  47. /* USB_PHY_TX_CTRL1 */
  48. #define TX_VDD15_14 (0x0 << 4)
  49. #define TX_VDD15_15 BIT(4)
  50. #define TX_VDD15_16 (0x2 << 4)
  51. #define TX_VDD15_17 (0x3 << 4)
  52. #define TX_VDD12_VDD (0x0 << 6)
  53. #define TX_VDD12_11 BIT(6)
  54. #define TX_VDD12_12 (0x2 << 6)
  55. #define TX_VDD12_13 (0x3 << 6)
  56. #define LOW_VDD_EN BIT(8)
  57. #define TX_OUT_AMP(x) ((x) << 9)
  58. /* USB_PHY_TX_CTRL2 */
  59. #define TX_CHAN_CTRL_REG(x) ((x) << 0)
  60. #define DRV_SLEWRATE(x) ((x) << 4)
  61. #define IMP_CAL_FS_HS_DLY_0 (0x0 << 6)
  62. #define IMP_CAL_FS_HS_DLY_1 BIT(6)
  63. #define IMP_CAL_FS_HS_DLY_2 (0x2 << 6)
  64. #define IMP_CAL_FS_HS_DLY_3 (0x3 << 6)
  65. #define FS_DRV_EN_MASK(x) ((x) << 8)
  66. #define HS_DRV_EN_MASK(x) ((x) << 12)
  67. /* USB_PHY_RX_CTRL */
  68. #define PHASE_FREEZE_DLY_2_CL (0x0 << 0)
  69. #define PHASE_FREEZE_DLY_4_CL BIT(0)
  70. #define ACK_LENGTH_8_CL (0x0 << 2)
  71. #define ACK_LENGTH_12_CL BIT(2)
  72. #define ACK_LENGTH_16_CL (0x2 << 2)
  73. #define ACK_LENGTH_20_CL (0x3 << 2)
  74. #define SQ_LENGTH_3 (0x0 << 4)
  75. #define SQ_LENGTH_6 BIT(4)
  76. #define SQ_LENGTH_9 (0x2 << 4)
  77. #define SQ_LENGTH_12 (0x3 << 4)
  78. #define DISCON_THRESHOLD_260 (0x0 << 6)
  79. #define DISCON_THRESHOLD_270 BIT(6)
  80. #define DISCON_THRESHOLD_280 (0x2 << 6)
  81. #define DISCON_THRESHOLD_290 (0x3 << 6)
  82. #define SQ_THRESHOLD(x) ((x) << 8)
  83. #define LPF_COEF(x) ((x) << 12)
  84. #define INTPL_CUR_10 (0x0 << 14)
  85. #define INTPL_CUR_20 BIT(14)
  86. #define INTPL_CUR_30 (0x2 << 14)
  87. #define INTPL_CUR_40 (0x3 << 14)
  88. /* USB_PHY_ANALOG */
  89. #define ANA_PWR_UP BIT(1)
  90. #define ANA_PWR_DOWN BIT(2)
  91. #define V2I_VCO_RATIO(x) ((x) << 7)
  92. #define R_ROTATE_90 (0x0 << 10)
  93. #define R_ROTATE_0 BIT(10)
  94. #define MODE_TEST_EN BIT(11)
  95. #define ANA_TEST_DC_CTRL(x) ((x) << 12)
  96. static const u32 phy_berlin_pll_dividers[] = {
  97. /* Berlin 2 */
  98. CLK_REF_DIV(0x6) | FEEDBACK_CLK_DIV(0x55),
  99. /* Berlin 2CD/Q */
  100. CLK_REF_DIV(0xc) | FEEDBACK_CLK_DIV(0x54),
  101. };
  102. struct phy_berlin_usb_priv {
  103. void __iomem *base;
  104. struct reset_control *rst_ctrl;
  105. u32 pll_divider;
  106. };
  107. static int phy_berlin_usb_power_on(struct phy *phy)
  108. {
  109. struct phy_berlin_usb_priv *priv = phy_get_drvdata(phy);
  110. reset_control_reset(priv->rst_ctrl);
  111. writel(priv->pll_divider,
  112. priv->base + USB_PHY_PLL);
  113. writel(CLK_STABLE | PLL_CTRL_REG | PHASE_OFF_TOL_250 | KVC0_REG_CTRL |
  114. CLK_BLK_EN, priv->base + USB_PHY_PLL_CONTROL);
  115. writel(V2I_VCO_RATIO(0x5) | R_ROTATE_0 | ANA_TEST_DC_CTRL(0x5),
  116. priv->base + USB_PHY_ANALOG);
  117. writel(PHASE_FREEZE_DLY_4_CL | ACK_LENGTH_16_CL | SQ_LENGTH_12 |
  118. DISCON_THRESHOLD_260 | SQ_THRESHOLD(0xa) | LPF_COEF(0x2) |
  119. INTPL_CUR_30, priv->base + USB_PHY_RX_CTRL);
  120. writel(TX_VDD12_13 | TX_OUT_AMP(0x3), priv->base + USB_PHY_TX_CTRL1);
  121. writel(EXT_HS_RCAL_EN | IMPCAL_VTH_DIV(0x3) | EXT_RS_RCAL_DIV(0x4),
  122. priv->base + USB_PHY_TX_CTRL0);
  123. writel(EXT_HS_RCAL_EN | IMPCAL_VTH_DIV(0x3) | EXT_RS_RCAL_DIV(0x4) |
  124. EXT_FS_RCAL_DIV(0x2), priv->base + USB_PHY_TX_CTRL0);
  125. writel(EXT_HS_RCAL_EN | IMPCAL_VTH_DIV(0x3) | EXT_RS_RCAL_DIV(0x4),
  126. priv->base + USB_PHY_TX_CTRL0);
  127. writel(TX_CHAN_CTRL_REG(0xf) | DRV_SLEWRATE(0x3) | IMP_CAL_FS_HS_DLY_3 |
  128. FS_DRV_EN_MASK(0xd), priv->base + USB_PHY_TX_CTRL2);
  129. return 0;
  130. }
  131. static const struct phy_ops phy_berlin_usb_ops = {
  132. .power_on = phy_berlin_usb_power_on,
  133. .owner = THIS_MODULE,
  134. };
  135. static const struct of_device_id phy_berlin_usb_of_match[] = {
  136. {
  137. .compatible = "marvell,berlin2-usb-phy",
  138. .data = &phy_berlin_pll_dividers[0],
  139. },
  140. {
  141. .compatible = "marvell,berlin2cd-usb-phy",
  142. .data = &phy_berlin_pll_dividers[1],
  143. },
  144. { },
  145. };
  146. MODULE_DEVICE_TABLE(of, phy_berlin_usb_of_match);
  147. static int phy_berlin_usb_probe(struct platform_device *pdev)
  148. {
  149. const struct of_device_id *match =
  150. of_match_device(phy_berlin_usb_of_match, &pdev->dev);
  151. struct phy_berlin_usb_priv *priv;
  152. struct resource *res;
  153. struct phy *phy;
  154. struct phy_provider *phy_provider;
  155. priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
  156. if (!priv)
  157. return -ENOMEM;
  158. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  159. priv->base = devm_ioremap_resource(&pdev->dev, res);
  160. if (IS_ERR(priv->base))
  161. return PTR_ERR(priv->base);
  162. priv->rst_ctrl = devm_reset_control_get(&pdev->dev, NULL);
  163. if (IS_ERR(priv->rst_ctrl))
  164. return PTR_ERR(priv->rst_ctrl);
  165. priv->pll_divider = *((u32 *)match->data);
  166. phy = devm_phy_create(&pdev->dev, NULL, &phy_berlin_usb_ops);
  167. if (IS_ERR(phy)) {
  168. dev_err(&pdev->dev, "failed to create PHY\n");
  169. return PTR_ERR(phy);
  170. }
  171. platform_set_drvdata(pdev, priv);
  172. phy_set_drvdata(phy, priv);
  173. phy_provider =
  174. devm_of_phy_provider_register(&pdev->dev, of_phy_simple_xlate);
  175. return PTR_ERR_OR_ZERO(phy_provider);
  176. }
  177. static struct platform_driver phy_berlin_usb_driver = {
  178. .probe = phy_berlin_usb_probe,
  179. .driver = {
  180. .name = "phy-berlin-usb",
  181. .of_match_table = phy_berlin_usb_of_match,
  182. },
  183. };
  184. module_platform_driver(phy_berlin_usb_driver);
  185. MODULE_AUTHOR("Antoine Tenart <antoine.tenart@free-electrons.com>");
  186. MODULE_DESCRIPTION("Marvell Berlin PHY driver for USB");
  187. MODULE_LICENSE("GPL");