broadcom.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947
  1. /*
  2. * drivers/net/phy/broadcom.c
  3. *
  4. * Broadcom BCM5411, BCM5421 and BCM5461 Gigabit Ethernet
  5. * transceivers.
  6. *
  7. * Copyright (c) 2006 Maciej W. Rozycki
  8. *
  9. * Inspired by code written by Amy Fong.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * as published by the Free Software Foundation; either version
  14. * 2 of the License, or (at your option) any later version.
  15. */
  16. #include <linux/module.h>
  17. #include <linux/phy.h>
  18. #include <linux/brcmphy.h>
  19. #define BRCM_PHY_MODEL(phydev) \
  20. ((phydev)->drv->phy_id & (phydev)->drv->phy_id_mask)
  21. #define BRCM_PHY_REV(phydev) \
  22. ((phydev)->drv->phy_id & ~((phydev)->drv->phy_id_mask))
  23. #define MII_BCM54XX_ECR 0x10 /* BCM54xx extended control register */
  24. #define MII_BCM54XX_ECR_IM 0x1000 /* Interrupt mask */
  25. #define MII_BCM54XX_ECR_IF 0x0800 /* Interrupt force */
  26. #define MII_BCM54XX_ESR 0x11 /* BCM54xx extended status register */
  27. #define MII_BCM54XX_ESR_IS 0x1000 /* Interrupt status */
  28. #define MII_BCM54XX_EXP_DATA 0x15 /* Expansion register data */
  29. #define MII_BCM54XX_EXP_SEL 0x17 /* Expansion register select */
  30. #define MII_BCM54XX_EXP_SEL_SSD 0x0e00 /* Secondary SerDes select */
  31. #define MII_BCM54XX_EXP_SEL_ER 0x0f00 /* Expansion register select */
  32. #define MII_BCM54XX_AUX_CTL 0x18 /* Auxiliary control register */
  33. #define MII_BCM54XX_ISR 0x1a /* BCM54xx interrupt status register */
  34. #define MII_BCM54XX_IMR 0x1b /* BCM54xx interrupt mask register */
  35. #define MII_BCM54XX_INT_CRCERR 0x0001 /* CRC error */
  36. #define MII_BCM54XX_INT_LINK 0x0002 /* Link status changed */
  37. #define MII_BCM54XX_INT_SPEED 0x0004 /* Link speed change */
  38. #define MII_BCM54XX_INT_DUPLEX 0x0008 /* Duplex mode changed */
  39. #define MII_BCM54XX_INT_LRS 0x0010 /* Local receiver status changed */
  40. #define MII_BCM54XX_INT_RRS 0x0020 /* Remote receiver status changed */
  41. #define MII_BCM54XX_INT_SSERR 0x0040 /* Scrambler synchronization error */
  42. #define MII_BCM54XX_INT_UHCD 0x0080 /* Unsupported HCD negotiated */
  43. #define MII_BCM54XX_INT_NHCD 0x0100 /* No HCD */
  44. #define MII_BCM54XX_INT_NHCDL 0x0200 /* No HCD link */
  45. #define MII_BCM54XX_INT_ANPR 0x0400 /* Auto-negotiation page received */
  46. #define MII_BCM54XX_INT_LC 0x0800 /* All counters below 128 */
  47. #define MII_BCM54XX_INT_HC 0x1000 /* Counter above 32768 */
  48. #define MII_BCM54XX_INT_MDIX 0x2000 /* MDIX status change */
  49. #define MII_BCM54XX_INT_PSERR 0x4000 /* Pair swap error */
  50. #define MII_BCM54XX_SHD 0x1c /* 0x1c shadow registers */
  51. #define MII_BCM54XX_SHD_WRITE 0x8000
  52. #define MII_BCM54XX_SHD_VAL(x) ((x & 0x1f) << 10)
  53. #define MII_BCM54XX_SHD_DATA(x) ((x & 0x3ff) << 0)
  54. /*
  55. * AUXILIARY CONTROL SHADOW ACCESS REGISTERS. (PHY REG 0x18)
  56. */
  57. #define MII_BCM54XX_AUXCTL_SHDWSEL_AUXCTL 0x0000
  58. #define MII_BCM54XX_AUXCTL_ACTL_TX_6DB 0x0400
  59. #define MII_BCM54XX_AUXCTL_ACTL_SMDSP_ENA 0x0800
  60. #define MII_BCM54XX_AUXCTL_MISC_WREN 0x8000
  61. #define MII_BCM54XX_AUXCTL_MISC_FORCE_AMDIX 0x0200
  62. #define MII_BCM54XX_AUXCTL_MISC_RDSEL_MISC 0x7000
  63. #define MII_BCM54XX_AUXCTL_SHDWSEL_MISC 0x0007
  64. #define MII_BCM54XX_AUXCTL_SHDWSEL_AUXCTL 0x0000
  65. /*
  66. * Broadcom LED source encodings. These are used in BCM5461, BCM5481,
  67. * BCM5482, and possibly some others.
  68. */
  69. #define BCM_LED_SRC_LINKSPD1 0x0
  70. #define BCM_LED_SRC_LINKSPD2 0x1
  71. #define BCM_LED_SRC_XMITLED 0x2
  72. #define BCM_LED_SRC_ACTIVITYLED 0x3
  73. #define BCM_LED_SRC_FDXLED 0x4
  74. #define BCM_LED_SRC_SLAVE 0x5
  75. #define BCM_LED_SRC_INTR 0x6
  76. #define BCM_LED_SRC_QUALITY 0x7
  77. #define BCM_LED_SRC_RCVLED 0x8
  78. #define BCM_LED_SRC_MULTICOLOR1 0xa
  79. #define BCM_LED_SRC_OPENSHORT 0xb
  80. #define BCM_LED_SRC_OFF 0xe /* Tied high */
  81. #define BCM_LED_SRC_ON 0xf /* Tied low */
  82. /*
  83. * BCM5482: Shadow registers
  84. * Shadow values go into bits [14:10] of register 0x1c to select a shadow
  85. * register to access.
  86. */
  87. /* 00101: Spare Control Register 3 */
  88. #define BCM54XX_SHD_SCR3 0x05
  89. #define BCM54XX_SHD_SCR3_DEF_CLK125 0x0001
  90. #define BCM54XX_SHD_SCR3_DLLAPD_DIS 0x0002
  91. #define BCM54XX_SHD_SCR3_TRDDAPD 0x0004
  92. /* 01010: Auto Power-Down */
  93. #define BCM54XX_SHD_APD 0x0a
  94. #define BCM54XX_SHD_APD_EN 0x0020
  95. #define BCM5482_SHD_LEDS1 0x0d /* 01101: LED Selector 1 */
  96. /* LED3 / ~LINKSPD[2] selector */
  97. #define BCM5482_SHD_LEDS1_LED3(src) ((src & 0xf) << 4)
  98. /* LED1 / ~LINKSPD[1] selector */
  99. #define BCM5482_SHD_LEDS1_LED1(src) ((src & 0xf) << 0)
  100. #define BCM54XX_SHD_RGMII_MODE 0x0b /* 01011: RGMII Mode Selector */
  101. #define BCM5482_SHD_SSD 0x14 /* 10100: Secondary SerDes control */
  102. #define BCM5482_SHD_SSD_LEDM 0x0008 /* SSD LED Mode enable */
  103. #define BCM5482_SHD_SSD_EN 0x0001 /* SSD enable */
  104. #define BCM5482_SHD_MODE 0x1f /* 11111: Mode Control Register */
  105. #define BCM5482_SHD_MODE_1000BX 0x0001 /* Enable 1000BASE-X registers */
  106. /*
  107. * EXPANSION SHADOW ACCESS REGISTERS. (PHY REG 0x15, 0x16, and 0x17)
  108. */
  109. #define MII_BCM54XX_EXP_AADJ1CH0 0x001f
  110. #define MII_BCM54XX_EXP_AADJ1CH0_SWP_ABCD_OEN 0x0200
  111. #define MII_BCM54XX_EXP_AADJ1CH0_SWSEL_THPF 0x0100
  112. #define MII_BCM54XX_EXP_AADJ1CH3 0x601f
  113. #define MII_BCM54XX_EXP_AADJ1CH3_ADCCKADJ 0x0002
  114. #define MII_BCM54XX_EXP_EXP08 0x0F08
  115. #define MII_BCM54XX_EXP_EXP08_RJCT_2MHZ 0x0001
  116. #define MII_BCM54XX_EXP_EXP08_EARLY_DAC_WAKE 0x0200
  117. #define MII_BCM54XX_EXP_EXP75 0x0f75
  118. #define MII_BCM54XX_EXP_EXP75_VDACCTRL 0x003c
  119. #define MII_BCM54XX_EXP_EXP75_CM_OSC 0x0001
  120. #define MII_BCM54XX_EXP_EXP96 0x0f96
  121. #define MII_BCM54XX_EXP_EXP96_MYST 0x0010
  122. #define MII_BCM54XX_EXP_EXP97 0x0f97
  123. #define MII_BCM54XX_EXP_EXP97_MYST 0x0c0c
  124. /*
  125. * BCM5482: Secondary SerDes registers
  126. */
  127. #define BCM5482_SSD_1000BX_CTL 0x00 /* 1000BASE-X Control */
  128. #define BCM5482_SSD_1000BX_CTL_PWRDOWN 0x0800 /* Power-down SSD */
  129. #define BCM5482_SSD_SGMII_SLAVE 0x15 /* SGMII Slave Register */
  130. #define BCM5482_SSD_SGMII_SLAVE_EN 0x0002 /* Slave mode enable */
  131. #define BCM5482_SSD_SGMII_SLAVE_AD 0x0001 /* Slave auto-detection */
  132. /*****************************************************************************/
  133. /* Fast Ethernet Transceiver definitions. */
  134. /*****************************************************************************/
  135. #define MII_BRCM_FET_INTREG 0x1a /* Interrupt register */
  136. #define MII_BRCM_FET_IR_MASK 0x0100 /* Mask all interrupts */
  137. #define MII_BRCM_FET_IR_LINK_EN 0x0200 /* Link status change enable */
  138. #define MII_BRCM_FET_IR_SPEED_EN 0x0400 /* Link speed change enable */
  139. #define MII_BRCM_FET_IR_DUPLEX_EN 0x0800 /* Duplex mode change enable */
  140. #define MII_BRCM_FET_IR_ENABLE 0x4000 /* Interrupt enable */
  141. #define MII_BRCM_FET_BRCMTEST 0x1f /* Brcm test register */
  142. #define MII_BRCM_FET_BT_SRE 0x0080 /* Shadow register enable */
  143. /*** Shadow register definitions ***/
  144. #define MII_BRCM_FET_SHDW_MISCCTRL 0x10 /* Shadow misc ctrl */
  145. #define MII_BRCM_FET_SHDW_MC_FAME 0x4000 /* Force Auto MDIX enable */
  146. #define MII_BRCM_FET_SHDW_AUXMODE4 0x1a /* Auxiliary mode 4 */
  147. #define MII_BRCM_FET_SHDW_AM4_LED_MASK 0x0003
  148. #define MII_BRCM_FET_SHDW_AM4_LED_MODE1 0x0001
  149. #define MII_BRCM_FET_SHDW_AUXSTAT2 0x1b /* Auxiliary status 2 */
  150. #define MII_BRCM_FET_SHDW_AS2_APDE 0x0020 /* Auto power down enable */
  151. MODULE_DESCRIPTION("Broadcom PHY driver");
  152. MODULE_AUTHOR("Maciej W. Rozycki");
  153. MODULE_LICENSE("GPL");
  154. /*
  155. * Indirect register access functions for the 1000BASE-T/100BASE-TX/10BASE-T
  156. * 0x1c shadow registers.
  157. */
  158. static int bcm54xx_shadow_read(struct phy_device *phydev, u16 shadow)
  159. {
  160. phy_write(phydev, MII_BCM54XX_SHD, MII_BCM54XX_SHD_VAL(shadow));
  161. return MII_BCM54XX_SHD_DATA(phy_read(phydev, MII_BCM54XX_SHD));
  162. }
  163. static int bcm54xx_shadow_write(struct phy_device *phydev, u16 shadow, u16 val)
  164. {
  165. return phy_write(phydev, MII_BCM54XX_SHD,
  166. MII_BCM54XX_SHD_WRITE |
  167. MII_BCM54XX_SHD_VAL(shadow) |
  168. MII_BCM54XX_SHD_DATA(val));
  169. }
  170. /* Indirect register access functions for the Expansion Registers */
  171. static int bcm54xx_exp_read(struct phy_device *phydev, u16 regnum)
  172. {
  173. int val;
  174. val = phy_write(phydev, MII_BCM54XX_EXP_SEL, regnum);
  175. if (val < 0)
  176. return val;
  177. val = phy_read(phydev, MII_BCM54XX_EXP_DATA);
  178. /* Restore default value. It's O.K. if this write fails. */
  179. phy_write(phydev, MII_BCM54XX_EXP_SEL, 0);
  180. return val;
  181. }
  182. static int bcm54xx_exp_write(struct phy_device *phydev, u16 regnum, u16 val)
  183. {
  184. int ret;
  185. ret = phy_write(phydev, MII_BCM54XX_EXP_SEL, regnum);
  186. if (ret < 0)
  187. return ret;
  188. ret = phy_write(phydev, MII_BCM54XX_EXP_DATA, val);
  189. /* Restore default value. It's O.K. if this write fails. */
  190. phy_write(phydev, MII_BCM54XX_EXP_SEL, 0);
  191. return ret;
  192. }
  193. static int bcm54xx_auxctl_write(struct phy_device *phydev, u16 regnum, u16 val)
  194. {
  195. return phy_write(phydev, MII_BCM54XX_AUX_CTL, regnum | val);
  196. }
  197. /* Needs SMDSP clock enabled via bcm54xx_phydsp_config() */
  198. static int bcm50610_a0_workaround(struct phy_device *phydev)
  199. {
  200. int err;
  201. err = bcm54xx_exp_write(phydev, MII_BCM54XX_EXP_AADJ1CH0,
  202. MII_BCM54XX_EXP_AADJ1CH0_SWP_ABCD_OEN |
  203. MII_BCM54XX_EXP_AADJ1CH0_SWSEL_THPF);
  204. if (err < 0)
  205. return err;
  206. err = bcm54xx_exp_write(phydev, MII_BCM54XX_EXP_AADJ1CH3,
  207. MII_BCM54XX_EXP_AADJ1CH3_ADCCKADJ);
  208. if (err < 0)
  209. return err;
  210. err = bcm54xx_exp_write(phydev, MII_BCM54XX_EXP_EXP75,
  211. MII_BCM54XX_EXP_EXP75_VDACCTRL);
  212. if (err < 0)
  213. return err;
  214. err = bcm54xx_exp_write(phydev, MII_BCM54XX_EXP_EXP96,
  215. MII_BCM54XX_EXP_EXP96_MYST);
  216. if (err < 0)
  217. return err;
  218. err = bcm54xx_exp_write(phydev, MII_BCM54XX_EXP_EXP97,
  219. MII_BCM54XX_EXP_EXP97_MYST);
  220. return err;
  221. }
  222. static int bcm54xx_phydsp_config(struct phy_device *phydev)
  223. {
  224. int err, err2;
  225. /* Enable the SMDSP clock */
  226. err = bcm54xx_auxctl_write(phydev,
  227. MII_BCM54XX_AUXCTL_SHDWSEL_AUXCTL,
  228. MII_BCM54XX_AUXCTL_ACTL_SMDSP_ENA |
  229. MII_BCM54XX_AUXCTL_ACTL_TX_6DB);
  230. if (err < 0)
  231. return err;
  232. if (BRCM_PHY_MODEL(phydev) == PHY_ID_BCM50610 ||
  233. BRCM_PHY_MODEL(phydev) == PHY_ID_BCM50610M) {
  234. /* Clear bit 9 to fix a phy interop issue. */
  235. err = bcm54xx_exp_write(phydev, MII_BCM54XX_EXP_EXP08,
  236. MII_BCM54XX_EXP_EXP08_RJCT_2MHZ);
  237. if (err < 0)
  238. goto error;
  239. if (phydev->drv->phy_id == PHY_ID_BCM50610) {
  240. err = bcm50610_a0_workaround(phydev);
  241. if (err < 0)
  242. goto error;
  243. }
  244. }
  245. if (BRCM_PHY_MODEL(phydev) == PHY_ID_BCM57780) {
  246. int val;
  247. val = bcm54xx_exp_read(phydev, MII_BCM54XX_EXP_EXP75);
  248. if (val < 0)
  249. goto error;
  250. val |= MII_BCM54XX_EXP_EXP75_CM_OSC;
  251. err = bcm54xx_exp_write(phydev, MII_BCM54XX_EXP_EXP75, val);
  252. }
  253. error:
  254. /* Disable the SMDSP clock */
  255. err2 = bcm54xx_auxctl_write(phydev,
  256. MII_BCM54XX_AUXCTL_SHDWSEL_AUXCTL,
  257. MII_BCM54XX_AUXCTL_ACTL_TX_6DB);
  258. /* Return the first error reported. */
  259. return err ? err : err2;
  260. }
  261. static void bcm54xx_adjust_rxrefclk(struct phy_device *phydev)
  262. {
  263. u32 orig;
  264. int val;
  265. bool clk125en = true;
  266. /* Abort if we are using an untested phy. */
  267. if (BRCM_PHY_MODEL(phydev) != PHY_ID_BCM57780 &&
  268. BRCM_PHY_MODEL(phydev) != PHY_ID_BCM50610 &&
  269. BRCM_PHY_MODEL(phydev) != PHY_ID_BCM50610M)
  270. return;
  271. val = bcm54xx_shadow_read(phydev, BCM54XX_SHD_SCR3);
  272. if (val < 0)
  273. return;
  274. orig = val;
  275. if ((BRCM_PHY_MODEL(phydev) == PHY_ID_BCM50610 ||
  276. BRCM_PHY_MODEL(phydev) == PHY_ID_BCM50610M) &&
  277. BRCM_PHY_REV(phydev) >= 0x3) {
  278. /*
  279. * Here, bit 0 _disables_ CLK125 when set.
  280. * This bit is set by default.
  281. */
  282. clk125en = false;
  283. } else {
  284. if (phydev->dev_flags & PHY_BRCM_RX_REFCLK_UNUSED) {
  285. /* Here, bit 0 _enables_ CLK125 when set */
  286. val &= ~BCM54XX_SHD_SCR3_DEF_CLK125;
  287. clk125en = false;
  288. }
  289. }
  290. if (!clk125en || (phydev->dev_flags & PHY_BRCM_AUTO_PWRDWN_ENABLE))
  291. val &= ~BCM54XX_SHD_SCR3_DLLAPD_DIS;
  292. else
  293. val |= BCM54XX_SHD_SCR3_DLLAPD_DIS;
  294. if (phydev->dev_flags & PHY_BRCM_DIS_TXCRXC_NOENRGY)
  295. val |= BCM54XX_SHD_SCR3_TRDDAPD;
  296. if (orig != val)
  297. bcm54xx_shadow_write(phydev, BCM54XX_SHD_SCR3, val);
  298. val = bcm54xx_shadow_read(phydev, BCM54XX_SHD_APD);
  299. if (val < 0)
  300. return;
  301. orig = val;
  302. if (!clk125en || (phydev->dev_flags & PHY_BRCM_AUTO_PWRDWN_ENABLE))
  303. val |= BCM54XX_SHD_APD_EN;
  304. else
  305. val &= ~BCM54XX_SHD_APD_EN;
  306. if (orig != val)
  307. bcm54xx_shadow_write(phydev, BCM54XX_SHD_APD, val);
  308. }
  309. static int bcm54xx_config_init(struct phy_device *phydev)
  310. {
  311. int reg, err;
  312. reg = phy_read(phydev, MII_BCM54XX_ECR);
  313. if (reg < 0)
  314. return reg;
  315. /* Mask interrupts globally. */
  316. reg |= MII_BCM54XX_ECR_IM;
  317. err = phy_write(phydev, MII_BCM54XX_ECR, reg);
  318. if (err < 0)
  319. return err;
  320. /* Unmask events we are interested in. */
  321. reg = ~(MII_BCM54XX_INT_DUPLEX |
  322. MII_BCM54XX_INT_SPEED |
  323. MII_BCM54XX_INT_LINK);
  324. err = phy_write(phydev, MII_BCM54XX_IMR, reg);
  325. if (err < 0)
  326. return err;
  327. if ((BRCM_PHY_MODEL(phydev) == PHY_ID_BCM50610 ||
  328. BRCM_PHY_MODEL(phydev) == PHY_ID_BCM50610M) &&
  329. (phydev->dev_flags & PHY_BRCM_CLEAR_RGMII_MODE))
  330. bcm54xx_shadow_write(phydev, BCM54XX_SHD_RGMII_MODE, 0);
  331. if ((phydev->dev_flags & PHY_BRCM_RX_REFCLK_UNUSED) ||
  332. (phydev->dev_flags & PHY_BRCM_DIS_TXCRXC_NOENRGY) ||
  333. (phydev->dev_flags & PHY_BRCM_AUTO_PWRDWN_ENABLE))
  334. bcm54xx_adjust_rxrefclk(phydev);
  335. bcm54xx_phydsp_config(phydev);
  336. return 0;
  337. }
  338. static int bcm5482_config_init(struct phy_device *phydev)
  339. {
  340. int err, reg;
  341. err = bcm54xx_config_init(phydev);
  342. if (phydev->dev_flags & PHY_BCM_FLAGS_MODE_1000BX) {
  343. /*
  344. * Enable secondary SerDes and its use as an LED source
  345. */
  346. reg = bcm54xx_shadow_read(phydev, BCM5482_SHD_SSD);
  347. bcm54xx_shadow_write(phydev, BCM5482_SHD_SSD,
  348. reg |
  349. BCM5482_SHD_SSD_LEDM |
  350. BCM5482_SHD_SSD_EN);
  351. /*
  352. * Enable SGMII slave mode and auto-detection
  353. */
  354. reg = BCM5482_SSD_SGMII_SLAVE | MII_BCM54XX_EXP_SEL_SSD;
  355. err = bcm54xx_exp_read(phydev, reg);
  356. if (err < 0)
  357. return err;
  358. err = bcm54xx_exp_write(phydev, reg, err |
  359. BCM5482_SSD_SGMII_SLAVE_EN |
  360. BCM5482_SSD_SGMII_SLAVE_AD);
  361. if (err < 0)
  362. return err;
  363. /*
  364. * Disable secondary SerDes powerdown
  365. */
  366. reg = BCM5482_SSD_1000BX_CTL | MII_BCM54XX_EXP_SEL_SSD;
  367. err = bcm54xx_exp_read(phydev, reg);
  368. if (err < 0)
  369. return err;
  370. err = bcm54xx_exp_write(phydev, reg,
  371. err & ~BCM5482_SSD_1000BX_CTL_PWRDOWN);
  372. if (err < 0)
  373. return err;
  374. /*
  375. * Select 1000BASE-X register set (primary SerDes)
  376. */
  377. reg = bcm54xx_shadow_read(phydev, BCM5482_SHD_MODE);
  378. bcm54xx_shadow_write(phydev, BCM5482_SHD_MODE,
  379. reg | BCM5482_SHD_MODE_1000BX);
  380. /*
  381. * LED1=ACTIVITYLED, LED3=LINKSPD[2]
  382. * (Use LED1 as secondary SerDes ACTIVITY LED)
  383. */
  384. bcm54xx_shadow_write(phydev, BCM5482_SHD_LEDS1,
  385. BCM5482_SHD_LEDS1_LED1(BCM_LED_SRC_ACTIVITYLED) |
  386. BCM5482_SHD_LEDS1_LED3(BCM_LED_SRC_LINKSPD2));
  387. /*
  388. * Auto-negotiation doesn't seem to work quite right
  389. * in this mode, so we disable it and force it to the
  390. * right speed/duplex setting. Only 'link status'
  391. * is important.
  392. */
  393. phydev->autoneg = AUTONEG_DISABLE;
  394. phydev->speed = SPEED_1000;
  395. phydev->duplex = DUPLEX_FULL;
  396. }
  397. return err;
  398. }
  399. static int bcm5482_read_status(struct phy_device *phydev)
  400. {
  401. int err;
  402. err = genphy_read_status(phydev);
  403. if (phydev->dev_flags & PHY_BCM_FLAGS_MODE_1000BX) {
  404. /*
  405. * Only link status matters for 1000Base-X mode, so force
  406. * 1000 Mbit/s full-duplex status
  407. */
  408. if (phydev->link) {
  409. phydev->speed = SPEED_1000;
  410. phydev->duplex = DUPLEX_FULL;
  411. }
  412. }
  413. return err;
  414. }
  415. static int bcm54xx_ack_interrupt(struct phy_device *phydev)
  416. {
  417. int reg;
  418. /* Clear pending interrupts. */
  419. reg = phy_read(phydev, MII_BCM54XX_ISR);
  420. if (reg < 0)
  421. return reg;
  422. return 0;
  423. }
  424. static int bcm54xx_config_intr(struct phy_device *phydev)
  425. {
  426. int reg, err;
  427. reg = phy_read(phydev, MII_BCM54XX_ECR);
  428. if (reg < 0)
  429. return reg;
  430. if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
  431. reg &= ~MII_BCM54XX_ECR_IM;
  432. else
  433. reg |= MII_BCM54XX_ECR_IM;
  434. err = phy_write(phydev, MII_BCM54XX_ECR, reg);
  435. return err;
  436. }
  437. static int bcm5481_config_aneg(struct phy_device *phydev)
  438. {
  439. int ret;
  440. /* Aneg firsly. */
  441. ret = genphy_config_aneg(phydev);
  442. /* Then we can set up the delay. */
  443. if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) {
  444. u16 reg;
  445. /*
  446. * There is no BCM5481 specification available, so down
  447. * here is everything we know about "register 0x18". This
  448. * at least helps BCM5481 to successfully receive packets
  449. * on MPC8360E-RDK board. Peter Barada <peterb@logicpd.com>
  450. * says: "This sets delay between the RXD and RXC signals
  451. * instead of using trace lengths to achieve timing".
  452. */
  453. /* Set RDX clk delay. */
  454. reg = 0x7 | (0x7 << 12);
  455. phy_write(phydev, 0x18, reg);
  456. reg = phy_read(phydev, 0x18);
  457. /* Set RDX-RXC skew. */
  458. reg |= (1 << 8);
  459. /* Write bits 14:0. */
  460. reg |= (1 << 15);
  461. phy_write(phydev, 0x18, reg);
  462. }
  463. return ret;
  464. }
  465. static int brcm_phy_setbits(struct phy_device *phydev, int reg, int set)
  466. {
  467. int val;
  468. val = phy_read(phydev, reg);
  469. if (val < 0)
  470. return val;
  471. return phy_write(phydev, reg, val | set);
  472. }
  473. static int brcm_fet_config_init(struct phy_device *phydev)
  474. {
  475. int reg, err, err2, brcmtest;
  476. /* Reset the PHY to bring it to a known state. */
  477. err = phy_write(phydev, MII_BMCR, BMCR_RESET);
  478. if (err < 0)
  479. return err;
  480. reg = phy_read(phydev, MII_BRCM_FET_INTREG);
  481. if (reg < 0)
  482. return reg;
  483. /* Unmask events we are interested in and mask interrupts globally. */
  484. reg = MII_BRCM_FET_IR_DUPLEX_EN |
  485. MII_BRCM_FET_IR_SPEED_EN |
  486. MII_BRCM_FET_IR_LINK_EN |
  487. MII_BRCM_FET_IR_ENABLE |
  488. MII_BRCM_FET_IR_MASK;
  489. err = phy_write(phydev, MII_BRCM_FET_INTREG, reg);
  490. if (err < 0)
  491. return err;
  492. /* Enable shadow register access */
  493. brcmtest = phy_read(phydev, MII_BRCM_FET_BRCMTEST);
  494. if (brcmtest < 0)
  495. return brcmtest;
  496. reg = brcmtest | MII_BRCM_FET_BT_SRE;
  497. err = phy_write(phydev, MII_BRCM_FET_BRCMTEST, reg);
  498. if (err < 0)
  499. return err;
  500. /* Set the LED mode */
  501. reg = phy_read(phydev, MII_BRCM_FET_SHDW_AUXMODE4);
  502. if (reg < 0) {
  503. err = reg;
  504. goto done;
  505. }
  506. reg &= ~MII_BRCM_FET_SHDW_AM4_LED_MASK;
  507. reg |= MII_BRCM_FET_SHDW_AM4_LED_MODE1;
  508. err = phy_write(phydev, MII_BRCM_FET_SHDW_AUXMODE4, reg);
  509. if (err < 0)
  510. goto done;
  511. /* Enable auto MDIX */
  512. err = brcm_phy_setbits(phydev, MII_BRCM_FET_SHDW_MISCCTRL,
  513. MII_BRCM_FET_SHDW_MC_FAME);
  514. if (err < 0)
  515. goto done;
  516. if (phydev->dev_flags & PHY_BRCM_AUTO_PWRDWN_ENABLE) {
  517. /* Enable auto power down */
  518. err = brcm_phy_setbits(phydev, MII_BRCM_FET_SHDW_AUXSTAT2,
  519. MII_BRCM_FET_SHDW_AS2_APDE);
  520. }
  521. done:
  522. /* Disable shadow register access */
  523. err2 = phy_write(phydev, MII_BRCM_FET_BRCMTEST, brcmtest);
  524. if (!err)
  525. err = err2;
  526. return err;
  527. }
  528. static int brcm_fet_ack_interrupt(struct phy_device *phydev)
  529. {
  530. int reg;
  531. /* Clear pending interrupts. */
  532. reg = phy_read(phydev, MII_BRCM_FET_INTREG);
  533. if (reg < 0)
  534. return reg;
  535. return 0;
  536. }
  537. static int brcm_fet_config_intr(struct phy_device *phydev)
  538. {
  539. int reg, err;
  540. reg = phy_read(phydev, MII_BRCM_FET_INTREG);
  541. if (reg < 0)
  542. return reg;
  543. if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
  544. reg &= ~MII_BRCM_FET_IR_MASK;
  545. else
  546. reg |= MII_BRCM_FET_IR_MASK;
  547. err = phy_write(phydev, MII_BRCM_FET_INTREG, reg);
  548. return err;
  549. }
  550. static struct phy_driver bcm5411_driver = {
  551. .phy_id = PHY_ID_BCM5411,
  552. .phy_id_mask = 0xfffffff0,
  553. .name = "Broadcom BCM5411",
  554. .features = PHY_GBIT_FEATURES |
  555. SUPPORTED_Pause | SUPPORTED_Asym_Pause,
  556. .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
  557. .config_init = bcm54xx_config_init,
  558. .config_aneg = genphy_config_aneg,
  559. .read_status = genphy_read_status,
  560. .ack_interrupt = bcm54xx_ack_interrupt,
  561. .config_intr = bcm54xx_config_intr,
  562. .driver = { .owner = THIS_MODULE },
  563. };
  564. static struct phy_driver bcm5421_driver = {
  565. .phy_id = PHY_ID_BCM5421,
  566. .phy_id_mask = 0xfffffff0,
  567. .name = "Broadcom BCM5421",
  568. .features = PHY_GBIT_FEATURES |
  569. SUPPORTED_Pause | SUPPORTED_Asym_Pause,
  570. .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
  571. .config_init = bcm54xx_config_init,
  572. .config_aneg = genphy_config_aneg,
  573. .read_status = genphy_read_status,
  574. .ack_interrupt = bcm54xx_ack_interrupt,
  575. .config_intr = bcm54xx_config_intr,
  576. .driver = { .owner = THIS_MODULE },
  577. };
  578. static struct phy_driver bcm5461_driver = {
  579. .phy_id = PHY_ID_BCM5461,
  580. .phy_id_mask = 0xfffffff0,
  581. .name = "Broadcom BCM5461",
  582. .features = PHY_GBIT_FEATURES |
  583. SUPPORTED_Pause | SUPPORTED_Asym_Pause,
  584. .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
  585. .config_init = bcm54xx_config_init,
  586. .config_aneg = genphy_config_aneg,
  587. .read_status = genphy_read_status,
  588. .ack_interrupt = bcm54xx_ack_interrupt,
  589. .config_intr = bcm54xx_config_intr,
  590. .driver = { .owner = THIS_MODULE },
  591. };
  592. static struct phy_driver bcm5464_driver = {
  593. .phy_id = PHY_ID_BCM5464,
  594. .phy_id_mask = 0xfffffff0,
  595. .name = "Broadcom BCM5464",
  596. .features = PHY_GBIT_FEATURES |
  597. SUPPORTED_Pause | SUPPORTED_Asym_Pause,
  598. .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
  599. .config_init = bcm54xx_config_init,
  600. .config_aneg = genphy_config_aneg,
  601. .read_status = genphy_read_status,
  602. .ack_interrupt = bcm54xx_ack_interrupt,
  603. .config_intr = bcm54xx_config_intr,
  604. .driver = { .owner = THIS_MODULE },
  605. };
  606. static struct phy_driver bcm5481_driver = {
  607. .phy_id = PHY_ID_BCM5481,
  608. .phy_id_mask = 0xfffffff0,
  609. .name = "Broadcom BCM5481",
  610. .features = PHY_GBIT_FEATURES |
  611. SUPPORTED_Pause | SUPPORTED_Asym_Pause,
  612. .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
  613. .config_init = bcm54xx_config_init,
  614. .config_aneg = bcm5481_config_aneg,
  615. .read_status = genphy_read_status,
  616. .ack_interrupt = bcm54xx_ack_interrupt,
  617. .config_intr = bcm54xx_config_intr,
  618. .driver = { .owner = THIS_MODULE },
  619. };
  620. static struct phy_driver bcm5482_driver = {
  621. .phy_id = PHY_ID_BCM5482,
  622. .phy_id_mask = 0xfffffff0,
  623. .name = "Broadcom BCM5482",
  624. .features = PHY_GBIT_FEATURES |
  625. SUPPORTED_Pause | SUPPORTED_Asym_Pause,
  626. .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
  627. .config_init = bcm5482_config_init,
  628. .config_aneg = genphy_config_aneg,
  629. .read_status = bcm5482_read_status,
  630. .ack_interrupt = bcm54xx_ack_interrupt,
  631. .config_intr = bcm54xx_config_intr,
  632. .driver = { .owner = THIS_MODULE },
  633. };
  634. static struct phy_driver bcm50610_driver = {
  635. .phy_id = PHY_ID_BCM50610,
  636. .phy_id_mask = 0xfffffff0,
  637. .name = "Broadcom BCM50610",
  638. .features = PHY_GBIT_FEATURES |
  639. SUPPORTED_Pause | SUPPORTED_Asym_Pause,
  640. .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
  641. .config_init = bcm54xx_config_init,
  642. .config_aneg = genphy_config_aneg,
  643. .read_status = genphy_read_status,
  644. .ack_interrupt = bcm54xx_ack_interrupt,
  645. .config_intr = bcm54xx_config_intr,
  646. .driver = { .owner = THIS_MODULE },
  647. };
  648. static struct phy_driver bcm50610m_driver = {
  649. .phy_id = PHY_ID_BCM50610M,
  650. .phy_id_mask = 0xfffffff0,
  651. .name = "Broadcom BCM50610M",
  652. .features = PHY_GBIT_FEATURES |
  653. SUPPORTED_Pause | SUPPORTED_Asym_Pause,
  654. .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
  655. .config_init = bcm54xx_config_init,
  656. .config_aneg = genphy_config_aneg,
  657. .read_status = genphy_read_status,
  658. .ack_interrupt = bcm54xx_ack_interrupt,
  659. .config_intr = bcm54xx_config_intr,
  660. .driver = { .owner = THIS_MODULE },
  661. };
  662. static struct phy_driver bcm57780_driver = {
  663. .phy_id = PHY_ID_BCM57780,
  664. .phy_id_mask = 0xfffffff0,
  665. .name = "Broadcom BCM57780",
  666. .features = PHY_GBIT_FEATURES |
  667. SUPPORTED_Pause | SUPPORTED_Asym_Pause,
  668. .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
  669. .config_init = bcm54xx_config_init,
  670. .config_aneg = genphy_config_aneg,
  671. .read_status = genphy_read_status,
  672. .ack_interrupt = bcm54xx_ack_interrupt,
  673. .config_intr = bcm54xx_config_intr,
  674. .driver = { .owner = THIS_MODULE },
  675. };
  676. static struct phy_driver bcmac131_driver = {
  677. .phy_id = PHY_ID_BCMAC131,
  678. .phy_id_mask = 0xfffffff0,
  679. .name = "Broadcom BCMAC131",
  680. .features = PHY_BASIC_FEATURES |
  681. SUPPORTED_Pause | SUPPORTED_Asym_Pause,
  682. .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
  683. .config_init = brcm_fet_config_init,
  684. .config_aneg = genphy_config_aneg,
  685. .read_status = genphy_read_status,
  686. .ack_interrupt = brcm_fet_ack_interrupt,
  687. .config_intr = brcm_fet_config_intr,
  688. .driver = { .owner = THIS_MODULE },
  689. };
  690. static struct phy_driver bcm5241_driver = {
  691. .phy_id = PHY_ID_BCM5241,
  692. .phy_id_mask = 0xfffffff0,
  693. .name = "Broadcom BCM5241",
  694. .features = PHY_BASIC_FEATURES |
  695. SUPPORTED_Pause | SUPPORTED_Asym_Pause,
  696. .flags = PHY_HAS_MAGICANEG | PHY_HAS_INTERRUPT,
  697. .config_init = brcm_fet_config_init,
  698. .config_aneg = genphy_config_aneg,
  699. .read_status = genphy_read_status,
  700. .ack_interrupt = brcm_fet_ack_interrupt,
  701. .config_intr = brcm_fet_config_intr,
  702. .driver = { .owner = THIS_MODULE },
  703. };
  704. static int __init broadcom_init(void)
  705. {
  706. int ret;
  707. ret = phy_driver_register(&bcm5411_driver);
  708. if (ret)
  709. goto out_5411;
  710. ret = phy_driver_register(&bcm5421_driver);
  711. if (ret)
  712. goto out_5421;
  713. ret = phy_driver_register(&bcm5461_driver);
  714. if (ret)
  715. goto out_5461;
  716. ret = phy_driver_register(&bcm5464_driver);
  717. if (ret)
  718. goto out_5464;
  719. ret = phy_driver_register(&bcm5481_driver);
  720. if (ret)
  721. goto out_5481;
  722. ret = phy_driver_register(&bcm5482_driver);
  723. if (ret)
  724. goto out_5482;
  725. ret = phy_driver_register(&bcm50610_driver);
  726. if (ret)
  727. goto out_50610;
  728. ret = phy_driver_register(&bcm50610m_driver);
  729. if (ret)
  730. goto out_50610m;
  731. ret = phy_driver_register(&bcm57780_driver);
  732. if (ret)
  733. goto out_57780;
  734. ret = phy_driver_register(&bcmac131_driver);
  735. if (ret)
  736. goto out_ac131;
  737. ret = phy_driver_register(&bcm5241_driver);
  738. if (ret)
  739. goto out_5241;
  740. return ret;
  741. out_5241:
  742. phy_driver_unregister(&bcmac131_driver);
  743. out_ac131:
  744. phy_driver_unregister(&bcm57780_driver);
  745. out_57780:
  746. phy_driver_unregister(&bcm50610m_driver);
  747. out_50610m:
  748. phy_driver_unregister(&bcm50610_driver);
  749. out_50610:
  750. phy_driver_unregister(&bcm5482_driver);
  751. out_5482:
  752. phy_driver_unregister(&bcm5481_driver);
  753. out_5481:
  754. phy_driver_unregister(&bcm5464_driver);
  755. out_5464:
  756. phy_driver_unregister(&bcm5461_driver);
  757. out_5461:
  758. phy_driver_unregister(&bcm5421_driver);
  759. out_5421:
  760. phy_driver_unregister(&bcm5411_driver);
  761. out_5411:
  762. return ret;
  763. }
  764. static void __exit broadcom_exit(void)
  765. {
  766. phy_driver_unregister(&bcm5241_driver);
  767. phy_driver_unregister(&bcmac131_driver);
  768. phy_driver_unregister(&bcm57780_driver);
  769. phy_driver_unregister(&bcm50610m_driver);
  770. phy_driver_unregister(&bcm50610_driver);
  771. phy_driver_unregister(&bcm5482_driver);
  772. phy_driver_unregister(&bcm5481_driver);
  773. phy_driver_unregister(&bcm5464_driver);
  774. phy_driver_unregister(&bcm5461_driver);
  775. phy_driver_unregister(&bcm5421_driver);
  776. phy_driver_unregister(&bcm5411_driver);
  777. }
  778. module_init(broadcom_init);
  779. module_exit(broadcom_exit);
  780. static struct mdio_device_id __maybe_unused broadcom_tbl[] = {
  781. { PHY_ID_BCM5411, 0xfffffff0 },
  782. { PHY_ID_BCM5421, 0xfffffff0 },
  783. { PHY_ID_BCM5461, 0xfffffff0 },
  784. { PHY_ID_BCM5464, 0xfffffff0 },
  785. { PHY_ID_BCM5481, 0xfffffff0 },
  786. { PHY_ID_BCM5482, 0xfffffff0 },
  787. { PHY_ID_BCM50610, 0xfffffff0 },
  788. { PHY_ID_BCM50610M, 0xfffffff0 },
  789. { PHY_ID_BCM57780, 0xfffffff0 },
  790. { PHY_ID_BCMAC131, 0xfffffff0 },
  791. { PHY_ID_BCM5241, 0xfffffff0 },
  792. { }
  793. };
  794. MODULE_DEVICE_TABLE(mdio, broadcom_tbl);