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

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