1
0

734-net-phy-at803x-allow-to-configure-via-pdata.patch 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. From: Gabor Juhos <juhosg@openwrt.org>
  2. Subject: net: phy: allow to configure AR803x PHYs via platform data
  3. Add a patch for the at803x phy driver, in order to be able
  4. to configure some register settings via platform data.
  5. Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
  6. ---
  7. drivers/net/phy/at803x.c | 56 ++++++++++++++++++++++++++++++++
  8. include/linux/platform_data/phy-at803x.h | 11 +++++++
  9. 2 files changed, 67 insertions(+)
  10. create mode 100644 include/linux/platform_data/phy-at803x.h
  11. --- a/drivers/net/phy/at803x.c
  12. +++ b/drivers/net/phy/at803x.c
  13. @@ -12,12 +12,14 @@
  14. */
  15. #include <linux/phy.h>
  16. +#include <linux/mdio.h>
  17. #include <linux/module.h>
  18. #include <linux/string.h>
  19. #include <linux/netdevice.h>
  20. #include <linux/etherdevice.h>
  21. #include <linux/of_gpio.h>
  22. #include <linux/gpio/consumer.h>
  23. +#include <linux/platform_data/phy-at803x.h>
  24. #define AT803X_INTR_ENABLE 0x12
  25. #define AT803X_INTR_ENABLE_AUTONEG_ERR BIT(15)
  26. @@ -45,6 +47,11 @@
  27. #define AT803X_REG_CHIP_CONFIG 0x1f
  28. #define AT803X_BT_BX_REG_SEL 0x8000
  29. +#define AT803X_PCS_SMART_EEE_CTRL3 0x805D
  30. +#define AT803X_SMART_EEE_CTRL3_LPI_TX_DELAY_SEL_MASK 0x3
  31. +#define AT803X_SMART_EEE_CTRL3_LPI_TX_DELAY_SEL_SHIFT 12
  32. +#define AT803X_SMART_EEE_CTRL3_LPI_EN BIT(8)
  33. +
  34. #define AT803X_DEBUG_ADDR 0x1D
  35. #define AT803X_DEBUG_DATA 0x1E
  36. @@ -74,6 +81,7 @@ MODULE_LICENSE("GPL");
  37. struct at803x_priv {
  38. bool phy_reset:1;
  39. struct gpio_desc *gpiod_reset;
  40. + int prev_speed;
  41. };
  42. struct at803x_context {
  43. @@ -274,8 +282,16 @@ does_not_require_reset_workaround:
  44. return 0;
  45. }
  46. +static void at803x_disable_smarteee(struct phy_device *phydev)
  47. +{
  48. + phy_write_mmd(phydev, MDIO_MMD_PCS, AT803X_PCS_SMART_EEE_CTRL3,
  49. + 1 << AT803X_SMART_EEE_CTRL3_LPI_TX_DELAY_SEL_SHIFT);
  50. + phy_write_mmd(phydev, MDIO_MMD_AN, MDIO_AN_EEE_ADV, 0);
  51. +}
  52. +
  53. static int at803x_config_init(struct phy_device *phydev)
  54. {
  55. + struct at803x_platform_data *pdata;
  56. int ret;
  57. ret = genphy_config_init(phydev);
  58. @@ -296,6 +312,26 @@ static int at803x_config_init(struct phy
  59. return ret;
  60. }
  61. + pdata = dev_get_platdata(&phydev->mdio.dev);
  62. + if (pdata) {
  63. + if (pdata->disable_smarteee)
  64. + at803x_disable_smarteee(phydev);
  65. +
  66. + if (pdata->enable_rgmii_rx_delay)
  67. + at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_0, 0,
  68. + AT803X_DEBUG_RX_CLK_DLY_EN);
  69. + else
  70. + at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_0,
  71. + AT803X_DEBUG_RX_CLK_DLY_EN, 0);
  72. +
  73. + if (pdata->enable_rgmii_tx_delay)
  74. + at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_5, 0,
  75. + AT803X_DEBUG_TX_CLK_DLY_EN);
  76. + else
  77. + at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_5,
  78. + AT803X_DEBUG_TX_CLK_DLY_EN, 0);
  79. + }
  80. +
  81. return 0;
  82. }
  83. @@ -333,6 +369,8 @@ static int at803x_config_intr(struct phy
  84. static void at803x_link_change_notify(struct phy_device *phydev)
  85. {
  86. struct at803x_priv *priv = phydev->priv;
  87. + struct at803x_platform_data *pdata;
  88. + pdata = dev_get_platdata(&phydev->mdio.dev);
  89. /*
  90. * Conduct a hardware reset for AT8030/2 every time a link loss is
  91. @@ -361,6 +399,24 @@ static void at803x_link_change_notify(st
  92. } else {
  93. priv->phy_reset = false;
  94. }
  95. + if (pdata && pdata->fixup_rgmii_tx_delay &&
  96. + phydev->speed != priv->prev_speed) {
  97. + switch (phydev->speed) {
  98. + case SPEED_10:
  99. + case SPEED_100:
  100. + at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_5, 0,
  101. + AT803X_DEBUG_TX_CLK_DLY_EN);
  102. + break;
  103. + case SPEED_1000:
  104. + at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_5,
  105. + AT803X_DEBUG_TX_CLK_DLY_EN, 0);
  106. + break;
  107. + default:
  108. + break;
  109. + }
  110. +
  111. + priv->prev_speed = phydev->speed;
  112. + }
  113. }
  114. static int at803x_aneg_done(struct phy_device *phydev)
  115. --- /dev/null
  116. +++ b/include/linux/platform_data/phy-at803x.h
  117. @@ -0,0 +1,11 @@
  118. +#ifndef _PHY_AT803X_PDATA_H
  119. +#define _PHY_AT803X_PDATA_H
  120. +
  121. +struct at803x_platform_data {
  122. + int disable_smarteee:1;
  123. + int enable_rgmii_tx_delay:1;
  124. + int enable_rgmii_rx_delay:1;
  125. + int fixup_rgmii_tx_delay:1;
  126. +};
  127. +
  128. +#endif /* _PHY_AT803X_PDATA_H */