078-0003-net-phy-cherry-pick-Broadcom-drivers-updates-from-v4.patch 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
  2. Subject: [PATCH] net: phy: cherry-pick Broadcom drivers updates from v4.10
  3. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
  4. ---
  5. --- a/drivers/net/phy/broadcom.c
  6. +++ b/drivers/net/phy/broadcom.c
  7. @@ -18,7 +18,7 @@
  8. #include <linux/module.h>
  9. #include <linux/phy.h>
  10. #include <linux/brcmphy.h>
  11. -
  12. +#include <linux/of.h>
  13. #define BRCM_PHY_MODEL(phydev) \
  14. ((phydev)->drv->phy_id & (phydev)->drv->phy_id_mask)
  15. @@ -30,9 +30,32 @@ MODULE_DESCRIPTION("Broadcom PHY driver"
  16. MODULE_AUTHOR("Maciej W. Rozycki");
  17. MODULE_LICENSE("GPL");
  18. -static int bcm54xx_auxctl_write(struct phy_device *phydev, u16 regnum, u16 val)
  19. +static int bcm54810_config(struct phy_device *phydev)
  20. {
  21. - return phy_write(phydev, MII_BCM54XX_AUX_CTL, regnum | val);
  22. + int rc, val;
  23. +
  24. + val = bcm_phy_read_exp(phydev, BCM54810_EXP_BROADREACH_LRE_MISC_CTL);
  25. + val &= ~BCM54810_EXP_BROADREACH_LRE_MISC_CTL_EN;
  26. + rc = bcm_phy_write_exp(phydev, BCM54810_EXP_BROADREACH_LRE_MISC_CTL,
  27. + val);
  28. + if (rc < 0)
  29. + return rc;
  30. +
  31. + val = bcm54xx_auxctl_read(phydev, MII_BCM54XX_AUXCTL_SHDWSEL_MISC);
  32. + val &= ~MII_BCM54XX_AUXCTL_SHDWSEL_MISC_RGMII_SKEW_EN;
  33. + val |= MII_BCM54XX_AUXCTL_MISC_WREN;
  34. + rc = bcm54xx_auxctl_write(phydev, MII_BCM54XX_AUXCTL_SHDWSEL_MISC,
  35. + val);
  36. + if (rc < 0)
  37. + return rc;
  38. +
  39. + val = bcm_phy_read_shadow(phydev, BCM54810_SHD_CLK_CTL);
  40. + val &= ~BCM54810_SHD_CLK_CTL_GTXCLK_EN;
  41. + rc = bcm_phy_write_shadow(phydev, BCM54810_SHD_CLK_CTL, val);
  42. + if (rc < 0)
  43. + return rc;
  44. +
  45. + return 0;
  46. }
  47. /* Needs SMDSP clock enabled via bcm54xx_phydsp_config() */
  48. @@ -207,6 +230,12 @@ static int bcm54xx_config_init(struct ph
  49. (phydev->dev_flags & PHY_BRCM_AUTO_PWRDWN_ENABLE))
  50. bcm54xx_adjust_rxrefclk(phydev);
  51. + if (BRCM_PHY_MODEL(phydev) == PHY_ID_BCM54810) {
  52. + err = bcm54810_config(phydev);
  53. + if (err)
  54. + return err;
  55. + }
  56. +
  57. bcm54xx_phydsp_config(phydev);
  58. return 0;
  59. @@ -304,6 +333,7 @@ static int bcm5482_read_status(struct ph
  60. static int bcm5481_config_aneg(struct phy_device *phydev)
  61. {
  62. + struct device_node *np = phydev->dev.of_node;
  63. int ret;
  64. /* Aneg firsly. */
  65. @@ -334,6 +364,49 @@ static int bcm5481_config_aneg(struct ph
  66. phy_write(phydev, 0x18, reg);
  67. }
  68. + if (of_property_read_bool(np, "enet-phy-lane-swap")) {
  69. + /* Lane Swap - Undocumented register...magic! */
  70. + ret = bcm_phy_write_exp(phydev, MII_BCM54XX_EXP_SEL_ER + 0x9,
  71. + 0x11B);
  72. + if (ret < 0)
  73. + return ret;
  74. + }
  75. +
  76. + return ret;
  77. +}
  78. +
  79. +static int bcm54612e_config_aneg(struct phy_device *phydev)
  80. +{
  81. + int ret;
  82. +
  83. + /* First, auto-negotiate. */
  84. + ret = genphy_config_aneg(phydev);
  85. +
  86. + /* Clear TX internal delay unless requested. */
  87. + if ((phydev->interface != PHY_INTERFACE_MODE_RGMII_ID) &&
  88. + (phydev->interface != PHY_INTERFACE_MODE_RGMII_TXID)) {
  89. + /* Disable TXD to GTXCLK clock delay (default set) */
  90. + /* Bit 9 is the only field in shadow register 00011 */
  91. + bcm_phy_write_shadow(phydev, 0x03, 0);
  92. + }
  93. +
  94. + /* Clear RX internal delay unless requested. */
  95. + if ((phydev->interface != PHY_INTERFACE_MODE_RGMII_ID) &&
  96. + (phydev->interface != PHY_INTERFACE_MODE_RGMII_RXID)) {
  97. + u16 reg;
  98. +
  99. + /* Errata: reads require filling in the write selector field */
  100. + bcm54xx_auxctl_write(phydev, MII_BCM54XX_AUXCTL_SHDWSEL_MISC,
  101. + MII_BCM54XX_AUXCTL_MISC_RDSEL_MISC);
  102. + reg = phy_read(phydev, MII_BCM54XX_AUX_CTL);
  103. + /* Disable RXD to RXC delay (default set) */
  104. + reg &= ~MII_BCM54XX_AUXCTL_MISC_RXD_RXC_SKEW;
  105. + /* Clear shadow selector field */
  106. + reg &= ~MII_BCM54XX_AUXCTL_SHDWSEL_MASK;
  107. + bcm54xx_auxctl_write(phydev, MII_BCM54XX_AUXCTL_SHDWSEL_MISC,
  108. + MII_BCM54XX_AUXCTL_MISC_WREN | reg);
  109. + }
  110. +
  111. return ret;
  112. }
  113. @@ -488,6 +561,19 @@ static struct phy_driver broadcom_driver
  114. .config_intr = bcm_phy_config_intr,
  115. .driver = { .owner = THIS_MODULE },
  116. }, {
  117. + .phy_id = PHY_ID_BCM54612E,
  118. + .phy_id_mask = 0xfffffff0,
  119. + .name = "Broadcom BCM54612E",
  120. + .features = PHY_GBIT_FEATURES |
  121. + SUPPORTED_Pause | SUPPORTED_Asym_Pause,
  122. + .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
  123. + .config_init = bcm54xx_config_init,
  124. + .config_aneg = bcm54612e_config_aneg,
  125. + .read_status = genphy_read_status,
  126. + .ack_interrupt = bcm_phy_ack_intr,
  127. + .config_intr = bcm_phy_config_intr,
  128. + .driver = { .owner = THIS_MODULE },
  129. +}, {
  130. .phy_id = PHY_ID_BCM54616S,
  131. .phy_id_mask = 0xfffffff0,
  132. .name = "Broadcom BCM54616S",
  133. @@ -527,6 +613,19 @@ static struct phy_driver broadcom_driver
  134. .config_intr = bcm_phy_config_intr,
  135. .driver = { .owner = THIS_MODULE },
  136. }, {
  137. + .phy_id = PHY_ID_BCM54810,
  138. + .phy_id_mask = 0xfffffff0,
  139. + .name = "Broadcom BCM54810",
  140. + .features = PHY_GBIT_FEATURES |
  141. + SUPPORTED_Pause | SUPPORTED_Asym_Pause,
  142. + .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
  143. + .config_init = bcm54xx_config_init,
  144. + .config_aneg = bcm5481_config_aneg,
  145. + .read_status = genphy_read_status,
  146. + .ack_interrupt = bcm_phy_ack_intr,
  147. + .config_intr = bcm_phy_config_intr,
  148. + .driver = { .owner = THIS_MODULE },
  149. +}, {
  150. .phy_id = PHY_ID_BCM5482,
  151. .phy_id_mask = 0xfffffff0,
  152. .name = "Broadcom BCM5482",
  153. @@ -612,9 +711,11 @@ static struct mdio_device_id __maybe_unu
  154. { PHY_ID_BCM5411, 0xfffffff0 },
  155. { PHY_ID_BCM5421, 0xfffffff0 },
  156. { PHY_ID_BCM5461, 0xfffffff0 },
  157. + { PHY_ID_BCM54612E, 0xfffffff0 },
  158. { PHY_ID_BCM54616S, 0xfffffff0 },
  159. { PHY_ID_BCM5464, 0xfffffff0 },
  160. { PHY_ID_BCM5481, 0xfffffff0 },
  161. + { PHY_ID_BCM54810, 0xfffffff0 },
  162. { PHY_ID_BCM5482, 0xfffffff0 },
  163. { PHY_ID_BCM50610, 0xfffffff0 },
  164. { PHY_ID_BCM50610M, 0xfffffff0 },
  165. --- a/include/linux/brcmphy.h
  166. +++ b/include/linux/brcmphy.h
  167. @@ -13,11 +13,13 @@
  168. #define PHY_ID_BCM5241 0x0143bc30
  169. #define PHY_ID_BCMAC131 0x0143bc70
  170. #define PHY_ID_BCM5481 0x0143bca0
  171. +#define PHY_ID_BCM54810 0x03625d00
  172. #define PHY_ID_BCM5482 0x0143bcb0
  173. #define PHY_ID_BCM5411 0x00206070
  174. #define PHY_ID_BCM5421 0x002060e0
  175. #define PHY_ID_BCM5464 0x002060b0
  176. #define PHY_ID_BCM5461 0x002060c0
  177. +#define PHY_ID_BCM54612E 0x03625e60
  178. #define PHY_ID_BCM54616S 0x03625d10
  179. #define PHY_ID_BCM57780 0x03625d90
  180. @@ -52,6 +54,7 @@
  181. #define PHY_BRCM_EXT_IBND_TX_ENABLE 0x00002000
  182. #define PHY_BRCM_CLEAR_RGMII_MODE 0x00004000
  183. #define PHY_BRCM_DIS_TXCRXC_NOENRGY 0x00008000
  184. +
  185. /* Broadcom BCM7xxx specific workarounds */
  186. #define PHY_BRCM_7XXX_REV(x) (((x) >> 8) & 0xff)
  187. #define PHY_BRCM_7XXX_PATCH(x) ((x) & 0xff)
  188. @@ -102,11 +105,14 @@
  189. #define MII_BCM54XX_AUXCTL_ACTL_SMDSP_ENA 0x0800
  190. #define MII_BCM54XX_AUXCTL_MISC_WREN 0x8000
  191. +#define MII_BCM54XX_AUXCTL_MISC_RXD_RXC_SKEW 0x0100
  192. #define MII_BCM54XX_AUXCTL_MISC_FORCE_AMDIX 0x0200
  193. #define MII_BCM54XX_AUXCTL_MISC_RDSEL_MISC 0x7000
  194. #define MII_BCM54XX_AUXCTL_SHDWSEL_MISC 0x0007
  195. +#define MII_BCM54XX_AUXCTL_SHDWSEL_READ_SHIFT 12
  196. +#define MII_BCM54XX_AUXCTL_SHDWSEL_MISC_RGMII_SKEW_EN (1 << 8)
  197. -#define MII_BCM54XX_AUXCTL_SHDWSEL_AUXCTL 0x0000
  198. +#define MII_BCM54XX_AUXCTL_SHDWSEL_MASK 0x0007
  199. /*
  200. * Broadcom LED source encodings. These are used in BCM5461, BCM5481,
  201. @@ -186,6 +192,12 @@
  202. #define BCM5482_SSD_SGMII_SLAVE_EN 0x0002 /* Slave mode enable */
  203. #define BCM5482_SSD_SGMII_SLAVE_AD 0x0001 /* Slave auto-detection */
  204. +/* BCM54810 Registers */
  205. +#define BCM54810_EXP_BROADREACH_LRE_MISC_CTL (MII_BCM54XX_EXP_SEL_ER + 0x90)
  206. +#define BCM54810_EXP_BROADREACH_LRE_MISC_CTL_EN (1 << 0)
  207. +#define BCM54810_SHD_CLK_CTL 0x3
  208. +#define BCM54810_SHD_CLK_CTL_GTXCLK_EN (1 << 9)
  209. +
  210. /*****************************************************************************/
  211. /* Fast Ethernet Transceiver definitions. */
  212. --- a/drivers/net/phy/Kconfig
  213. +++ b/drivers/net/phy/Kconfig
  214. @@ -77,7 +77,7 @@ config BROADCOM_PHY
  215. select BCM_NET_PHYLIB
  216. ---help---
  217. Currently supports the BCM5411, BCM5421, BCM5461, BCM54616S, BCM5464,
  218. - BCM5481 and BCM5482 PHYs.
  219. + BCM5481, BCM54810 and BCM5482 PHYs.
  220. config BCM_CYGNUS_PHY
  221. tristate "Drivers for Broadcom Cygnus SoC internal PHY"
  222. --- a/drivers/net/phy/bcm-phy-lib.c
  223. +++ b/drivers/net/phy/bcm-phy-lib.c
  224. @@ -50,6 +50,23 @@ int bcm_phy_read_exp(struct phy_device *
  225. }
  226. EXPORT_SYMBOL_GPL(bcm_phy_read_exp);
  227. +int bcm54xx_auxctl_read(struct phy_device *phydev, u16 regnum)
  228. +{
  229. + /* The register must be written to both the Shadow Register Select and
  230. + * the Shadow Read Register Selector
  231. + */
  232. + phy_write(phydev, MII_BCM54XX_AUX_CTL, regnum |
  233. + regnum << MII_BCM54XX_AUXCTL_SHDWSEL_READ_SHIFT);
  234. + return phy_read(phydev, MII_BCM54XX_AUX_CTL);
  235. +}
  236. +EXPORT_SYMBOL_GPL(bcm54xx_auxctl_read);
  237. +
  238. +int bcm54xx_auxctl_write(struct phy_device *phydev, u16 regnum, u16 val)
  239. +{
  240. + return phy_write(phydev, MII_BCM54XX_AUX_CTL, regnum | val);
  241. +}
  242. +EXPORT_SYMBOL(bcm54xx_auxctl_write);
  243. +
  244. int bcm_phy_write_misc(struct phy_device *phydev,
  245. u16 reg, u16 chl, u16 val)
  246. {
  247. --- a/drivers/net/phy/bcm-phy-lib.h
  248. +++ b/drivers/net/phy/bcm-phy-lib.h
  249. @@ -26,6 +26,9 @@ static inline int bcm_phy_write_exp_sel(
  250. return bcm_phy_write_exp(phydev, reg | MII_BCM54XX_EXP_SEL_ER, val);
  251. }
  252. +int bcm54xx_auxctl_write(struct phy_device *phydev, u16 regnum, u16 val);
  253. +int bcm54xx_auxctl_read(struct phy_device *phydev, u16 regnum);
  254. +
  255. int bcm_phy_write_misc(struct phy_device *phydev,
  256. u16 reg, u16 chl, u16 value);
  257. int bcm_phy_read_misc(struct phy_device *phydev,