bcm7xxx.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. /*
  2. * Broadcom BCM7xxx internal transceivers support.
  3. *
  4. * Copyright (C) 2014-2017 Broadcom
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/phy.h>
  13. #include <linux/delay.h>
  14. #include "bcm-phy-lib.h"
  15. #include <linux/bitops.h>
  16. #include <linux/brcmphy.h>
  17. #include <linux/mdio.h>
  18. /* Broadcom BCM7xxx internal PHY registers */
  19. /* EPHY only register definitions */
  20. #define MII_BCM7XXX_100TX_AUX_CTL 0x10
  21. #define MII_BCM7XXX_100TX_FALSE_CAR 0x13
  22. #define MII_BCM7XXX_100TX_DISC 0x14
  23. #define MII_BCM7XXX_AUX_MODE 0x1d
  24. #define MII_BCM7XXX_64CLK_MDIO BIT(12)
  25. #define MII_BCM7XXX_TEST 0x1f
  26. #define MII_BCM7XXX_SHD_MODE_2 BIT(2)
  27. #define MII_BCM7XXX_SHD_2_ADDR_CTRL 0xe
  28. #define MII_BCM7XXX_SHD_2_CTRL_STAT 0xf
  29. #define MII_BCM7XXX_SHD_2_BIAS_TRIM 0x1a
  30. #define MII_BCM7XXX_SHD_3_AN_EEE_ADV 0x3
  31. #define MII_BCM7XXX_SHD_3_PCS_CTRL_2 0x6
  32. #define MII_BCM7XXX_PCS_CTRL_2_DEF 0x4400
  33. #define MII_BCM7XXX_SHD_3_AN_STAT 0xb
  34. #define MII_BCM7XXX_AN_NULL_MSG_EN BIT(0)
  35. #define MII_BCM7XXX_AN_EEE_EN BIT(1)
  36. #define MII_BCM7XXX_SHD_3_EEE_THRESH 0xe
  37. #define MII_BCM7XXX_EEE_THRESH_DEF 0x50
  38. #define MII_BCM7XXX_SHD_3_TL4 0x23
  39. #define MII_BCM7XXX_TL4_RST_MSK (BIT(2) | BIT(1))
  40. /* 28nm only register definitions */
  41. #define MISC_ADDR(base, channel) base, channel
  42. #define DSP_TAP10 MISC_ADDR(0x0a, 0)
  43. #define PLL_PLLCTRL_1 MISC_ADDR(0x32, 1)
  44. #define PLL_PLLCTRL_2 MISC_ADDR(0x32, 2)
  45. #define PLL_PLLCTRL_4 MISC_ADDR(0x33, 0)
  46. #define AFE_RXCONFIG_0 MISC_ADDR(0x38, 0)
  47. #define AFE_RXCONFIG_1 MISC_ADDR(0x38, 1)
  48. #define AFE_RXCONFIG_2 MISC_ADDR(0x38, 2)
  49. #define AFE_RX_LP_COUNTER MISC_ADDR(0x38, 3)
  50. #define AFE_TX_CONFIG MISC_ADDR(0x39, 0)
  51. #define AFE_VDCA_ICTRL_0 MISC_ADDR(0x39, 1)
  52. #define AFE_VDAC_OTHERS_0 MISC_ADDR(0x39, 3)
  53. #define AFE_HPF_TRIM_OTHERS MISC_ADDR(0x3a, 0)
  54. struct bcm7xxx_phy_priv {
  55. u64 *stats;
  56. };
  57. static void r_rc_cal_reset(struct phy_device *phydev)
  58. {
  59. /* Reset R_CAL/RC_CAL Engine */
  60. bcm_phy_write_exp_sel(phydev, 0x00b0, 0x0010);
  61. /* Disable Reset R_AL/RC_CAL Engine */
  62. bcm_phy_write_exp_sel(phydev, 0x00b0, 0x0000);
  63. }
  64. static int bcm7xxx_28nm_b0_afe_config_init(struct phy_device *phydev)
  65. {
  66. /* Increase VCO range to prevent unlocking problem of PLL at low
  67. * temp
  68. */
  69. bcm_phy_write_misc(phydev, PLL_PLLCTRL_1, 0x0048);
  70. /* Change Ki to 011 */
  71. bcm_phy_write_misc(phydev, PLL_PLLCTRL_2, 0x021b);
  72. /* Disable loading of TVCO buffer to bandgap, set bandgap trim
  73. * to 111
  74. */
  75. bcm_phy_write_misc(phydev, PLL_PLLCTRL_4, 0x0e20);
  76. /* Adjust bias current trim by -3 */
  77. bcm_phy_write_misc(phydev, DSP_TAP10, 0x690b);
  78. /* Switch to CORE_BASE1E */
  79. phy_write(phydev, MII_BRCM_CORE_BASE1E, 0xd);
  80. r_rc_cal_reset(phydev);
  81. /* write AFE_RXCONFIG_0 */
  82. bcm_phy_write_misc(phydev, AFE_RXCONFIG_0, 0xeb19);
  83. /* write AFE_RXCONFIG_1 */
  84. bcm_phy_write_misc(phydev, AFE_RXCONFIG_1, 0x9a3f);
  85. /* write AFE_RX_LP_COUNTER */
  86. bcm_phy_write_misc(phydev, AFE_RX_LP_COUNTER, 0x7fc0);
  87. /* write AFE_HPF_TRIM_OTHERS */
  88. bcm_phy_write_misc(phydev, AFE_HPF_TRIM_OTHERS, 0x000b);
  89. /* write AFTE_TX_CONFIG */
  90. bcm_phy_write_misc(phydev, AFE_TX_CONFIG, 0x0800);
  91. return 0;
  92. }
  93. static int bcm7xxx_28nm_d0_afe_config_init(struct phy_device *phydev)
  94. {
  95. /* AFE_RXCONFIG_0 */
  96. bcm_phy_write_misc(phydev, AFE_RXCONFIG_0, 0xeb15);
  97. /* AFE_RXCONFIG_1 */
  98. bcm_phy_write_misc(phydev, AFE_RXCONFIG_1, 0x9b2f);
  99. /* AFE_RXCONFIG_2, set rCal offset for HT=0 code and LT=-2 code */
  100. bcm_phy_write_misc(phydev, AFE_RXCONFIG_2, 0x2003);
  101. /* AFE_RX_LP_COUNTER, set RX bandwidth to maximum */
  102. bcm_phy_write_misc(phydev, AFE_RX_LP_COUNTER, 0x7fc0);
  103. /* AFE_TX_CONFIG, set 100BT Cfeed=011 to improve rise/fall time */
  104. bcm_phy_write_misc(phydev, AFE_TX_CONFIG, 0x431);
  105. /* AFE_VDCA_ICTRL_0, set Iq=1101 instead of 0111 for AB symmetry */
  106. bcm_phy_write_misc(phydev, AFE_VDCA_ICTRL_0, 0xa7da);
  107. /* AFE_VDAC_OTHERS_0, set 1000BT Cidac=010 for all ports */
  108. bcm_phy_write_misc(phydev, AFE_VDAC_OTHERS_0, 0xa020);
  109. /* AFE_HPF_TRIM_OTHERS, set 100Tx/10BT to -4.5% swing and set rCal
  110. * offset for HT=0 code
  111. */
  112. bcm_phy_write_misc(phydev, AFE_HPF_TRIM_OTHERS, 0x00e3);
  113. /* CORE_BASE1E, force trim to overwrite and set I_ext trim to 0000 */
  114. phy_write(phydev, MII_BRCM_CORE_BASE1E, 0x0010);
  115. /* DSP_TAP10, adjust bias current trim (+0% swing, +0 tick) */
  116. bcm_phy_write_misc(phydev, DSP_TAP10, 0x011b);
  117. /* Reset R_CAL/RC_CAL engine */
  118. r_rc_cal_reset(phydev);
  119. return 0;
  120. }
  121. static int bcm7xxx_28nm_e0_plus_afe_config_init(struct phy_device *phydev)
  122. {
  123. /* AFE_RXCONFIG_1, provide more margin for INL/DNL measurement */
  124. bcm_phy_write_misc(phydev, AFE_RXCONFIG_1, 0x9b2f);
  125. /* AFE_TX_CONFIG, set 100BT Cfeed=011 to improve rise/fall time */
  126. bcm_phy_write_misc(phydev, AFE_TX_CONFIG, 0x431);
  127. /* AFE_VDCA_ICTRL_0, set Iq=1101 instead of 0111 for AB symmetry */
  128. bcm_phy_write_misc(phydev, AFE_VDCA_ICTRL_0, 0xa7da);
  129. /* AFE_HPF_TRIM_OTHERS, set 100Tx/10BT to -4.5% swing and set rCal
  130. * offset for HT=0 code
  131. */
  132. bcm_phy_write_misc(phydev, AFE_HPF_TRIM_OTHERS, 0x00e3);
  133. /* CORE_BASE1E, force trim to overwrite and set I_ext trim to 0000 */
  134. phy_write(phydev, MII_BRCM_CORE_BASE1E, 0x0010);
  135. /* DSP_TAP10, adjust bias current trim (+0% swing, +0 tick) */
  136. bcm_phy_write_misc(phydev, DSP_TAP10, 0x011b);
  137. /* Reset R_CAL/RC_CAL engine */
  138. r_rc_cal_reset(phydev);
  139. return 0;
  140. }
  141. static int bcm7xxx_28nm_a0_patch_afe_config_init(struct phy_device *phydev)
  142. {
  143. /* +1 RC_CAL codes for RL centering for both LT and HT conditions */
  144. bcm_phy_write_misc(phydev, AFE_RXCONFIG_2, 0xd003);
  145. /* Cut master bias current by 2% to compensate for RC_CAL offset */
  146. bcm_phy_write_misc(phydev, DSP_TAP10, 0x791b);
  147. /* Improve hybrid leakage */
  148. bcm_phy_write_misc(phydev, AFE_HPF_TRIM_OTHERS, 0x10e3);
  149. /* Change rx_on_tune 8 to 0xf */
  150. bcm_phy_write_misc(phydev, 0x21, 0x2, 0x87f6);
  151. /* Change 100Tx EEE bandwidth */
  152. bcm_phy_write_misc(phydev, 0x22, 0x2, 0x017d);
  153. /* Enable ffe zero detection for Vitesse interoperability */
  154. bcm_phy_write_misc(phydev, 0x26, 0x2, 0x0015);
  155. r_rc_cal_reset(phydev);
  156. return 0;
  157. }
  158. static int bcm7xxx_28nm_config_init(struct phy_device *phydev)
  159. {
  160. u8 rev = PHY_BRCM_7XXX_REV(phydev->dev_flags);
  161. u8 patch = PHY_BRCM_7XXX_PATCH(phydev->dev_flags);
  162. u8 count;
  163. int ret = 0;
  164. /* Newer devices have moved the revision information back into a
  165. * standard location in MII_PHYS_ID[23]
  166. */
  167. if (rev == 0)
  168. rev = phydev->phy_id & ~phydev->drv->phy_id_mask;
  169. pr_info_once("%s: %s PHY revision: 0x%02x, patch: %d\n",
  170. phydev_name(phydev), phydev->drv->name, rev, patch);
  171. /* Dummy read to a register to workaround an issue upon reset where the
  172. * internal inverter may not allow the first MDIO transaction to pass
  173. * the MDIO management controller and make us return 0xffff for such
  174. * reads.
  175. */
  176. phy_read(phydev, MII_BMSR);
  177. switch (rev) {
  178. case 0xa0:
  179. case 0xb0:
  180. ret = bcm7xxx_28nm_b0_afe_config_init(phydev);
  181. break;
  182. case 0xd0:
  183. ret = bcm7xxx_28nm_d0_afe_config_init(phydev);
  184. break;
  185. case 0xe0:
  186. case 0xf0:
  187. /* Rev G0 introduces a roll over */
  188. case 0x10:
  189. ret = bcm7xxx_28nm_e0_plus_afe_config_init(phydev);
  190. break;
  191. case 0x01:
  192. ret = bcm7xxx_28nm_a0_patch_afe_config_init(phydev);
  193. break;
  194. default:
  195. break;
  196. }
  197. if (ret)
  198. return ret;
  199. ret = bcm_phy_downshift_get(phydev, &count);
  200. if (ret)
  201. return ret;
  202. /* Only enable EEE if Wirespeed/downshift is disabled */
  203. ret = bcm_phy_set_eee(phydev, count == DOWNSHIFT_DEV_DISABLE);
  204. if (ret)
  205. return ret;
  206. return bcm_phy_enable_apd(phydev, true);
  207. }
  208. static int bcm7xxx_28nm_resume(struct phy_device *phydev)
  209. {
  210. int ret;
  211. /* Re-apply workarounds coming out suspend/resume */
  212. ret = bcm7xxx_28nm_config_init(phydev);
  213. if (ret)
  214. return ret;
  215. /* 28nm Gigabit PHYs come out of reset without any half-duplex
  216. * or "hub" compliant advertised mode, fix that. This does not
  217. * cause any problems with the PHY library since genphy_config_aneg()
  218. * gracefully handles auto-negotiated and forced modes.
  219. */
  220. return genphy_config_aneg(phydev);
  221. }
  222. static int phy_set_clr_bits(struct phy_device *dev, int location,
  223. int set_mask, int clr_mask)
  224. {
  225. int v, ret;
  226. v = phy_read(dev, location);
  227. if (v < 0)
  228. return v;
  229. v &= ~clr_mask;
  230. v |= set_mask;
  231. ret = phy_write(dev, location, v);
  232. if (ret < 0)
  233. return ret;
  234. return v;
  235. }
  236. static int bcm7xxx_28nm_ephy_01_afe_config_init(struct phy_device *phydev)
  237. {
  238. int ret;
  239. /* set shadow mode 2 */
  240. ret = phy_set_clr_bits(phydev, MII_BCM7XXX_TEST,
  241. MII_BCM7XXX_SHD_MODE_2, 0);
  242. if (ret < 0)
  243. return ret;
  244. /* Set current trim values INT_trim = -1, Ext_trim =0 */
  245. ret = phy_write(phydev, MII_BCM7XXX_SHD_2_BIAS_TRIM, 0x3BE0);
  246. if (ret < 0)
  247. goto reset_shadow_mode;
  248. /* Cal reset */
  249. ret = phy_write(phydev, MII_BCM7XXX_SHD_2_ADDR_CTRL,
  250. MII_BCM7XXX_SHD_3_TL4);
  251. if (ret < 0)
  252. goto reset_shadow_mode;
  253. ret = phy_set_clr_bits(phydev, MII_BCM7XXX_SHD_2_CTRL_STAT,
  254. MII_BCM7XXX_TL4_RST_MSK, 0);
  255. if (ret < 0)
  256. goto reset_shadow_mode;
  257. /* Cal reset disable */
  258. ret = phy_write(phydev, MII_BCM7XXX_SHD_2_ADDR_CTRL,
  259. MII_BCM7XXX_SHD_3_TL4);
  260. if (ret < 0)
  261. goto reset_shadow_mode;
  262. ret = phy_set_clr_bits(phydev, MII_BCM7XXX_SHD_2_CTRL_STAT,
  263. 0, MII_BCM7XXX_TL4_RST_MSK);
  264. if (ret < 0)
  265. goto reset_shadow_mode;
  266. reset_shadow_mode:
  267. /* reset shadow mode 2 */
  268. ret = phy_set_clr_bits(phydev, MII_BCM7XXX_TEST, 0,
  269. MII_BCM7XXX_SHD_MODE_2);
  270. if (ret < 0)
  271. return ret;
  272. return 0;
  273. }
  274. /* The 28nm EPHY does not support Clause 45 (MMD) used by bcm-phy-lib */
  275. static int bcm7xxx_28nm_ephy_apd_enable(struct phy_device *phydev)
  276. {
  277. int ret;
  278. /* set shadow mode 1 */
  279. ret = phy_set_clr_bits(phydev, MII_BRCM_FET_BRCMTEST,
  280. MII_BRCM_FET_BT_SRE, 0);
  281. if (ret < 0)
  282. return ret;
  283. /* Enable auto-power down */
  284. ret = phy_set_clr_bits(phydev, MII_BRCM_FET_SHDW_AUXSTAT2,
  285. MII_BRCM_FET_SHDW_AS2_APDE, 0);
  286. if (ret < 0)
  287. return ret;
  288. /* reset shadow mode 1 */
  289. ret = phy_set_clr_bits(phydev, MII_BRCM_FET_BRCMTEST, 0,
  290. MII_BRCM_FET_BT_SRE);
  291. if (ret < 0)
  292. return ret;
  293. return 0;
  294. }
  295. static int bcm7xxx_28nm_ephy_eee_enable(struct phy_device *phydev)
  296. {
  297. int ret;
  298. /* set shadow mode 2 */
  299. ret = phy_set_clr_bits(phydev, MII_BCM7XXX_TEST,
  300. MII_BCM7XXX_SHD_MODE_2, 0);
  301. if (ret < 0)
  302. return ret;
  303. /* Advertise supported modes */
  304. ret = phy_write(phydev, MII_BCM7XXX_SHD_2_ADDR_CTRL,
  305. MII_BCM7XXX_SHD_3_AN_EEE_ADV);
  306. if (ret < 0)
  307. goto reset_shadow_mode;
  308. ret = phy_write(phydev, MII_BCM7XXX_SHD_2_CTRL_STAT,
  309. MDIO_EEE_100TX);
  310. if (ret < 0)
  311. goto reset_shadow_mode;
  312. /* Restore Defaults */
  313. ret = phy_write(phydev, MII_BCM7XXX_SHD_2_ADDR_CTRL,
  314. MII_BCM7XXX_SHD_3_PCS_CTRL_2);
  315. if (ret < 0)
  316. goto reset_shadow_mode;
  317. ret = phy_write(phydev, MII_BCM7XXX_SHD_2_CTRL_STAT,
  318. MII_BCM7XXX_PCS_CTRL_2_DEF);
  319. if (ret < 0)
  320. goto reset_shadow_mode;
  321. ret = phy_write(phydev, MII_BCM7XXX_SHD_2_ADDR_CTRL,
  322. MII_BCM7XXX_SHD_3_EEE_THRESH);
  323. if (ret < 0)
  324. goto reset_shadow_mode;
  325. ret = phy_write(phydev, MII_BCM7XXX_SHD_2_CTRL_STAT,
  326. MII_BCM7XXX_EEE_THRESH_DEF);
  327. if (ret < 0)
  328. goto reset_shadow_mode;
  329. /* Enable EEE autonegotiation */
  330. ret = phy_write(phydev, MII_BCM7XXX_SHD_2_ADDR_CTRL,
  331. MII_BCM7XXX_SHD_3_AN_STAT);
  332. if (ret < 0)
  333. goto reset_shadow_mode;
  334. ret = phy_write(phydev, MII_BCM7XXX_SHD_2_CTRL_STAT,
  335. (MII_BCM7XXX_AN_NULL_MSG_EN | MII_BCM7XXX_AN_EEE_EN));
  336. if (ret < 0)
  337. goto reset_shadow_mode;
  338. reset_shadow_mode:
  339. /* reset shadow mode 2 */
  340. ret = phy_set_clr_bits(phydev, MII_BCM7XXX_TEST, 0,
  341. MII_BCM7XXX_SHD_MODE_2);
  342. if (ret < 0)
  343. return ret;
  344. /* Restart autoneg */
  345. phy_write(phydev, MII_BMCR,
  346. (BMCR_SPEED100 | BMCR_ANENABLE | BMCR_ANRESTART));
  347. return 0;
  348. }
  349. static int bcm7xxx_28nm_ephy_config_init(struct phy_device *phydev)
  350. {
  351. u8 rev = phydev->phy_id & ~phydev->drv->phy_id_mask;
  352. int ret = 0;
  353. pr_info_once("%s: %s PHY revision: 0x%02x\n",
  354. phydev_name(phydev), phydev->drv->name, rev);
  355. /* Dummy read to a register to workaround a possible issue upon reset
  356. * where the internal inverter may not allow the first MDIO transaction
  357. * to pass the MDIO management controller and make us return 0xffff for
  358. * such reads.
  359. */
  360. phy_read(phydev, MII_BMSR);
  361. /* Apply AFE software work-around if necessary */
  362. if (rev == 0x01) {
  363. ret = bcm7xxx_28nm_ephy_01_afe_config_init(phydev);
  364. if (ret)
  365. return ret;
  366. }
  367. ret = bcm7xxx_28nm_ephy_eee_enable(phydev);
  368. if (ret)
  369. return ret;
  370. return bcm7xxx_28nm_ephy_apd_enable(phydev);
  371. }
  372. static int bcm7xxx_28nm_ephy_resume(struct phy_device *phydev)
  373. {
  374. int ret;
  375. /* Re-apply workarounds coming out suspend/resume */
  376. ret = bcm7xxx_28nm_ephy_config_init(phydev);
  377. if (ret)
  378. return ret;
  379. return genphy_config_aneg(phydev);
  380. }
  381. static int bcm7xxx_config_init(struct phy_device *phydev)
  382. {
  383. int ret;
  384. /* Enable 64 clock MDIO */
  385. phy_write(phydev, MII_BCM7XXX_AUX_MODE, MII_BCM7XXX_64CLK_MDIO);
  386. phy_read(phydev, MII_BCM7XXX_AUX_MODE);
  387. /* set shadow mode 2 */
  388. ret = phy_set_clr_bits(phydev, MII_BCM7XXX_TEST,
  389. MII_BCM7XXX_SHD_MODE_2, MII_BCM7XXX_SHD_MODE_2);
  390. if (ret < 0)
  391. return ret;
  392. /* set iddq_clkbias */
  393. phy_write(phydev, MII_BCM7XXX_100TX_DISC, 0x0F00);
  394. udelay(10);
  395. /* reset iddq_clkbias */
  396. phy_write(phydev, MII_BCM7XXX_100TX_DISC, 0x0C00);
  397. phy_write(phydev, MII_BCM7XXX_100TX_FALSE_CAR, 0x7555);
  398. /* reset shadow mode 2 */
  399. ret = phy_set_clr_bits(phydev, MII_BCM7XXX_TEST, 0, MII_BCM7XXX_SHD_MODE_2);
  400. if (ret < 0)
  401. return ret;
  402. return 0;
  403. }
  404. /* Workaround for putting the PHY in IDDQ mode, required
  405. * for all BCM7XXX 40nm and 65nm PHYs
  406. */
  407. static int bcm7xxx_suspend(struct phy_device *phydev)
  408. {
  409. int ret;
  410. static const struct bcm7xxx_regs {
  411. int reg;
  412. u16 value;
  413. } bcm7xxx_suspend_cfg[] = {
  414. { MII_BCM7XXX_TEST, 0x008b },
  415. { MII_BCM7XXX_100TX_AUX_CTL, 0x01c0 },
  416. { MII_BCM7XXX_100TX_DISC, 0x7000 },
  417. { MII_BCM7XXX_TEST, 0x000f },
  418. { MII_BCM7XXX_100TX_AUX_CTL, 0x20d0 },
  419. { MII_BCM7XXX_TEST, 0x000b },
  420. };
  421. unsigned int i;
  422. for (i = 0; i < ARRAY_SIZE(bcm7xxx_suspend_cfg); i++) {
  423. ret = phy_write(phydev,
  424. bcm7xxx_suspend_cfg[i].reg,
  425. bcm7xxx_suspend_cfg[i].value);
  426. if (ret)
  427. return ret;
  428. }
  429. return 0;
  430. }
  431. static int bcm7xxx_28nm_get_tunable(struct phy_device *phydev,
  432. struct ethtool_tunable *tuna,
  433. void *data)
  434. {
  435. switch (tuna->id) {
  436. case ETHTOOL_PHY_DOWNSHIFT:
  437. return bcm_phy_downshift_get(phydev, (u8 *)data);
  438. default:
  439. return -EOPNOTSUPP;
  440. }
  441. }
  442. static int bcm7xxx_28nm_set_tunable(struct phy_device *phydev,
  443. struct ethtool_tunable *tuna,
  444. const void *data)
  445. {
  446. u8 count = *(u8 *)data;
  447. int ret;
  448. switch (tuna->id) {
  449. case ETHTOOL_PHY_DOWNSHIFT:
  450. ret = bcm_phy_downshift_set(phydev, count);
  451. break;
  452. default:
  453. return -EOPNOTSUPP;
  454. }
  455. if (ret)
  456. return ret;
  457. /* Disable EEE advertisement since this prevents the PHY
  458. * from successfully linking up, trigger auto-negotiation restart
  459. * to let the MAC decide what to do.
  460. */
  461. ret = bcm_phy_set_eee(phydev, count == DOWNSHIFT_DEV_DISABLE);
  462. if (ret)
  463. return ret;
  464. return genphy_restart_aneg(phydev);
  465. }
  466. static void bcm7xxx_28nm_get_phy_stats(struct phy_device *phydev,
  467. struct ethtool_stats *stats, u64 *data)
  468. {
  469. struct bcm7xxx_phy_priv *priv = phydev->priv;
  470. bcm_phy_get_stats(phydev, priv->stats, stats, data);
  471. }
  472. static int bcm7xxx_28nm_probe(struct phy_device *phydev)
  473. {
  474. struct bcm7xxx_phy_priv *priv;
  475. priv = devm_kzalloc(&phydev->mdio.dev, sizeof(*priv), GFP_KERNEL);
  476. if (!priv)
  477. return -ENOMEM;
  478. phydev->priv = priv;
  479. priv->stats = devm_kcalloc(&phydev->mdio.dev,
  480. bcm_phy_get_sset_count(phydev), sizeof(u64),
  481. GFP_KERNEL);
  482. if (!priv->stats)
  483. return -ENOMEM;
  484. return 0;
  485. }
  486. #define BCM7XXX_28NM_GPHY(_oui, _name) \
  487. { \
  488. .phy_id = (_oui), \
  489. .phy_id_mask = 0xfffffff0, \
  490. .name = _name, \
  491. .features = PHY_GBIT_FEATURES, \
  492. .flags = PHY_IS_INTERNAL, \
  493. .config_init = bcm7xxx_28nm_config_init, \
  494. .resume = bcm7xxx_28nm_resume, \
  495. .get_tunable = bcm7xxx_28nm_get_tunable, \
  496. .set_tunable = bcm7xxx_28nm_set_tunable, \
  497. .get_sset_count = bcm_phy_get_sset_count, \
  498. .get_strings = bcm_phy_get_strings, \
  499. .get_stats = bcm7xxx_28nm_get_phy_stats, \
  500. .probe = bcm7xxx_28nm_probe, \
  501. }
  502. #define BCM7XXX_28NM_EPHY(_oui, _name) \
  503. { \
  504. .phy_id = (_oui), \
  505. .phy_id_mask = 0xfffffff0, \
  506. .name = _name, \
  507. .features = PHY_BASIC_FEATURES, \
  508. .flags = PHY_IS_INTERNAL, \
  509. .config_init = bcm7xxx_28nm_ephy_config_init, \
  510. .resume = bcm7xxx_28nm_ephy_resume, \
  511. .get_sset_count = bcm_phy_get_sset_count, \
  512. .get_strings = bcm_phy_get_strings, \
  513. .get_stats = bcm7xxx_28nm_get_phy_stats, \
  514. .probe = bcm7xxx_28nm_probe, \
  515. }
  516. #define BCM7XXX_40NM_EPHY(_oui, _name) \
  517. { \
  518. .phy_id = (_oui), \
  519. .phy_id_mask = 0xfffffff0, \
  520. .name = _name, \
  521. .features = PHY_BASIC_FEATURES, \
  522. .flags = PHY_IS_INTERNAL, \
  523. .soft_reset = genphy_soft_reset, \
  524. .config_init = bcm7xxx_config_init, \
  525. .suspend = bcm7xxx_suspend, \
  526. .resume = bcm7xxx_config_init, \
  527. }
  528. static struct phy_driver bcm7xxx_driver[] = {
  529. BCM7XXX_28NM_GPHY(PHY_ID_BCM7250, "Broadcom BCM7250"),
  530. BCM7XXX_28NM_EPHY(PHY_ID_BCM7260, "Broadcom BCM7260"),
  531. BCM7XXX_28NM_EPHY(PHY_ID_BCM7268, "Broadcom BCM7268"),
  532. BCM7XXX_28NM_EPHY(PHY_ID_BCM7271, "Broadcom BCM7271"),
  533. BCM7XXX_28NM_GPHY(PHY_ID_BCM7278, "Broadcom BCM7278"),
  534. BCM7XXX_28NM_GPHY(PHY_ID_BCM7364, "Broadcom BCM7364"),
  535. BCM7XXX_28NM_GPHY(PHY_ID_BCM7366, "Broadcom BCM7366"),
  536. BCM7XXX_28NM_GPHY(PHY_ID_BCM74371, "Broadcom BCM74371"),
  537. BCM7XXX_28NM_GPHY(PHY_ID_BCM7439, "Broadcom BCM7439"),
  538. BCM7XXX_28NM_GPHY(PHY_ID_BCM7439_2, "Broadcom BCM7439 (2)"),
  539. BCM7XXX_28NM_GPHY(PHY_ID_BCM7445, "Broadcom BCM7445"),
  540. BCM7XXX_28NM_GPHY(PHY_ID_BCM_OMEGA, "Broadcom Omega Combo GPHY"),
  541. BCM7XXX_40NM_EPHY(PHY_ID_BCM7346, "Broadcom BCM7346"),
  542. BCM7XXX_40NM_EPHY(PHY_ID_BCM7362, "Broadcom BCM7362"),
  543. BCM7XXX_40NM_EPHY(PHY_ID_BCM7425, "Broadcom BCM7425"),
  544. BCM7XXX_40NM_EPHY(PHY_ID_BCM7429, "Broadcom BCM7429"),
  545. BCM7XXX_40NM_EPHY(PHY_ID_BCM7435, "Broadcom BCM7435"),
  546. };
  547. static struct mdio_device_id __maybe_unused bcm7xxx_tbl[] = {
  548. { PHY_ID_BCM7250, 0xfffffff0, },
  549. { PHY_ID_BCM7260, 0xfffffff0, },
  550. { PHY_ID_BCM7268, 0xfffffff0, },
  551. { PHY_ID_BCM7271, 0xfffffff0, },
  552. { PHY_ID_BCM7278, 0xfffffff0, },
  553. { PHY_ID_BCM7364, 0xfffffff0, },
  554. { PHY_ID_BCM7366, 0xfffffff0, },
  555. { PHY_ID_BCM7346, 0xfffffff0, },
  556. { PHY_ID_BCM7362, 0xfffffff0, },
  557. { PHY_ID_BCM7425, 0xfffffff0, },
  558. { PHY_ID_BCM7429, 0xfffffff0, },
  559. { PHY_ID_BCM74371, 0xfffffff0, },
  560. { PHY_ID_BCM7439, 0xfffffff0, },
  561. { PHY_ID_BCM7435, 0xfffffff0, },
  562. { PHY_ID_BCM7445, 0xfffffff0, },
  563. { }
  564. };
  565. module_phy_driver(bcm7xxx_driver);
  566. MODULE_DEVICE_TABLE(mdio, bcm7xxx_tbl);
  567. MODULE_DESCRIPTION("Broadcom BCM7xxx internal PHY driver");
  568. MODULE_LICENSE("GPL");
  569. MODULE_AUTHOR("Broadcom Corporation");