bcm7xxx.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. /*
  2. * Broadcom BCM7xxx internal transceivers support.
  3. *
  4. * Copyright (C) 2014, Broadcom Corporation
  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. /* 40nm 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_BCM7XX_64CLK_MDIO BIT(12)
  25. #define MII_BCM7XXX_TEST 0x1f
  26. #define MII_BCM7XXX_SHD_MODE_2 BIT(2)
  27. /* 28nm only register definitions */
  28. #define MISC_ADDR(base, channel) base, channel
  29. #define DSP_TAP10 MISC_ADDR(0x0a, 0)
  30. #define PLL_PLLCTRL_1 MISC_ADDR(0x32, 1)
  31. #define PLL_PLLCTRL_2 MISC_ADDR(0x32, 2)
  32. #define PLL_PLLCTRL_4 MISC_ADDR(0x33, 0)
  33. #define AFE_RXCONFIG_0 MISC_ADDR(0x38, 0)
  34. #define AFE_RXCONFIG_1 MISC_ADDR(0x38, 1)
  35. #define AFE_RXCONFIG_2 MISC_ADDR(0x38, 2)
  36. #define AFE_RX_LP_COUNTER MISC_ADDR(0x38, 3)
  37. #define AFE_TX_CONFIG MISC_ADDR(0x39, 0)
  38. #define AFE_VDCA_ICTRL_0 MISC_ADDR(0x39, 1)
  39. #define AFE_VDAC_OTHERS_0 MISC_ADDR(0x39, 3)
  40. #define AFE_HPF_TRIM_OTHERS MISC_ADDR(0x3a, 0)
  41. static void r_rc_cal_reset(struct phy_device *phydev)
  42. {
  43. /* Reset R_CAL/RC_CAL Engine */
  44. bcm_phy_write_exp_sel(phydev, 0x00b0, 0x0010);
  45. /* Disable Reset R_AL/RC_CAL Engine */
  46. bcm_phy_write_exp_sel(phydev, 0x00b0, 0x0000);
  47. }
  48. static int bcm7xxx_28nm_b0_afe_config_init(struct phy_device *phydev)
  49. {
  50. /* Increase VCO range to prevent unlocking problem of PLL at low
  51. * temp
  52. */
  53. bcm_phy_write_misc(phydev, PLL_PLLCTRL_1, 0x0048);
  54. /* Change Ki to 011 */
  55. bcm_phy_write_misc(phydev, PLL_PLLCTRL_2, 0x021b);
  56. /* Disable loading of TVCO buffer to bandgap, set bandgap trim
  57. * to 111
  58. */
  59. bcm_phy_write_misc(phydev, PLL_PLLCTRL_4, 0x0e20);
  60. /* Adjust bias current trim by -3 */
  61. bcm_phy_write_misc(phydev, DSP_TAP10, 0x690b);
  62. /* Switch to CORE_BASE1E */
  63. phy_write(phydev, MII_BRCM_CORE_BASE1E, 0xd);
  64. r_rc_cal_reset(phydev);
  65. /* write AFE_RXCONFIG_0 */
  66. bcm_phy_write_misc(phydev, AFE_RXCONFIG_0, 0xeb19);
  67. /* write AFE_RXCONFIG_1 */
  68. bcm_phy_write_misc(phydev, AFE_RXCONFIG_1, 0x9a3f);
  69. /* write AFE_RX_LP_COUNTER */
  70. bcm_phy_write_misc(phydev, AFE_RX_LP_COUNTER, 0x7fc0);
  71. /* write AFE_HPF_TRIM_OTHERS */
  72. bcm_phy_write_misc(phydev, AFE_HPF_TRIM_OTHERS, 0x000b);
  73. /* write AFTE_TX_CONFIG */
  74. bcm_phy_write_misc(phydev, AFE_TX_CONFIG, 0x0800);
  75. return 0;
  76. }
  77. static int bcm7xxx_28nm_d0_afe_config_init(struct phy_device *phydev)
  78. {
  79. /* AFE_RXCONFIG_0 */
  80. bcm_phy_write_misc(phydev, AFE_RXCONFIG_0, 0xeb15);
  81. /* AFE_RXCONFIG_1 */
  82. bcm_phy_write_misc(phydev, AFE_RXCONFIG_1, 0x9b2f);
  83. /* AFE_RXCONFIG_2, set rCal offset for HT=0 code and LT=-2 code */
  84. bcm_phy_write_misc(phydev, AFE_RXCONFIG_2, 0x2003);
  85. /* AFE_RX_LP_COUNTER, set RX bandwidth to maximum */
  86. bcm_phy_write_misc(phydev, AFE_RX_LP_COUNTER, 0x7fc0);
  87. /* AFE_TX_CONFIG, set 100BT Cfeed=011 to improve rise/fall time */
  88. bcm_phy_write_misc(phydev, AFE_TX_CONFIG, 0x431);
  89. /* AFE_VDCA_ICTRL_0, set Iq=1101 instead of 0111 for AB symmetry */
  90. bcm_phy_write_misc(phydev, AFE_VDCA_ICTRL_0, 0xa7da);
  91. /* AFE_VDAC_OTHERS_0, set 1000BT Cidac=010 for all ports */
  92. bcm_phy_write_misc(phydev, AFE_VDAC_OTHERS_0, 0xa020);
  93. /* AFE_HPF_TRIM_OTHERS, set 100Tx/10BT to -4.5% swing and set rCal
  94. * offset for HT=0 code
  95. */
  96. bcm_phy_write_misc(phydev, AFE_HPF_TRIM_OTHERS, 0x00e3);
  97. /* CORE_BASE1E, force trim to overwrite and set I_ext trim to 0000 */
  98. phy_write(phydev, MII_BRCM_CORE_BASE1E, 0x0010);
  99. /* DSP_TAP10, adjust bias current trim (+0% swing, +0 tick) */
  100. bcm_phy_write_misc(phydev, DSP_TAP10, 0x011b);
  101. /* Reset R_CAL/RC_CAL engine */
  102. r_rc_cal_reset(phydev);
  103. return 0;
  104. }
  105. static int bcm7xxx_28nm_e0_plus_afe_config_init(struct phy_device *phydev)
  106. {
  107. /* AFE_RXCONFIG_1, provide more margin for INL/DNL measurement */
  108. bcm_phy_write_misc(phydev, AFE_RXCONFIG_1, 0x9b2f);
  109. /* AFE_TX_CONFIG, set 100BT Cfeed=011 to improve rise/fall time */
  110. bcm_phy_write_misc(phydev, AFE_TX_CONFIG, 0x431);
  111. /* AFE_VDCA_ICTRL_0, set Iq=1101 instead of 0111 for AB symmetry */
  112. bcm_phy_write_misc(phydev, AFE_VDCA_ICTRL_0, 0xa7da);
  113. /* AFE_HPF_TRIM_OTHERS, set 100Tx/10BT to -4.5% swing and set rCal
  114. * offset for HT=0 code
  115. */
  116. bcm_phy_write_misc(phydev, AFE_HPF_TRIM_OTHERS, 0x00e3);
  117. /* CORE_BASE1E, force trim to overwrite and set I_ext trim to 0000 */
  118. phy_write(phydev, MII_BRCM_CORE_BASE1E, 0x0010);
  119. /* DSP_TAP10, adjust bias current trim (+0% swing, +0 tick) */
  120. bcm_phy_write_misc(phydev, DSP_TAP10, 0x011b);
  121. /* Reset R_CAL/RC_CAL engine */
  122. r_rc_cal_reset(phydev);
  123. return 0;
  124. }
  125. static int bcm7xxx_28nm_config_init(struct phy_device *phydev)
  126. {
  127. u8 rev = PHY_BRCM_7XXX_REV(phydev->dev_flags);
  128. u8 patch = PHY_BRCM_7XXX_PATCH(phydev->dev_flags);
  129. int ret = 0;
  130. pr_info_once("%s: %s PHY revision: 0x%02x, patch: %d\n",
  131. dev_name(&phydev->dev), phydev->drv->name, rev, patch);
  132. /* Dummy read to a register to workaround an issue upon reset where the
  133. * internal inverter may not allow the first MDIO transaction to pass
  134. * the MDIO management controller and make us return 0xffff for such
  135. * reads.
  136. */
  137. phy_read(phydev, MII_BMSR);
  138. switch (rev) {
  139. case 0xb0:
  140. ret = bcm7xxx_28nm_b0_afe_config_init(phydev);
  141. break;
  142. case 0xd0:
  143. ret = bcm7xxx_28nm_d0_afe_config_init(phydev);
  144. break;
  145. case 0xe0:
  146. case 0xf0:
  147. /* Rev G0 introduces a roll over */
  148. case 0x10:
  149. ret = bcm7xxx_28nm_e0_plus_afe_config_init(phydev);
  150. break;
  151. default:
  152. break;
  153. }
  154. if (ret)
  155. return ret;
  156. ret = bcm_phy_enable_eee(phydev);
  157. if (ret)
  158. return ret;
  159. return bcm_phy_enable_apd(phydev, true);
  160. }
  161. static int bcm7xxx_28nm_resume(struct phy_device *phydev)
  162. {
  163. int ret;
  164. /* Re-apply workarounds coming out suspend/resume */
  165. ret = bcm7xxx_28nm_config_init(phydev);
  166. if (ret)
  167. return ret;
  168. /* 28nm Gigabit PHYs come out of reset without any half-duplex
  169. * or "hub" compliant advertised mode, fix that. This does not
  170. * cause any problems with the PHY library since genphy_config_aneg()
  171. * gracefully handles auto-negotiated and forced modes.
  172. */
  173. return genphy_config_aneg(phydev);
  174. }
  175. static int phy_set_clr_bits(struct phy_device *dev, int location,
  176. int set_mask, int clr_mask)
  177. {
  178. int v, ret;
  179. v = phy_read(dev, location);
  180. if (v < 0)
  181. return v;
  182. v &= ~clr_mask;
  183. v |= set_mask;
  184. ret = phy_write(dev, location, v);
  185. if (ret < 0)
  186. return ret;
  187. return v;
  188. }
  189. static int bcm7xxx_config_init(struct phy_device *phydev)
  190. {
  191. int ret;
  192. /* Enable 64 clock MDIO */
  193. phy_write(phydev, MII_BCM7XXX_AUX_MODE, MII_BCM7XX_64CLK_MDIO);
  194. phy_read(phydev, MII_BCM7XXX_AUX_MODE);
  195. /* Workaround only required for 100Mbits/sec capable PHYs */
  196. if (phydev->supported & PHY_GBIT_FEATURES)
  197. return 0;
  198. /* set shadow mode 2 */
  199. ret = phy_set_clr_bits(phydev, MII_BCM7XXX_TEST,
  200. MII_BCM7XXX_SHD_MODE_2, MII_BCM7XXX_SHD_MODE_2);
  201. if (ret < 0)
  202. return ret;
  203. /* set iddq_clkbias */
  204. phy_write(phydev, MII_BCM7XXX_100TX_DISC, 0x0F00);
  205. udelay(10);
  206. /* reset iddq_clkbias */
  207. phy_write(phydev, MII_BCM7XXX_100TX_DISC, 0x0C00);
  208. phy_write(phydev, MII_BCM7XXX_100TX_FALSE_CAR, 0x7555);
  209. /* reset shadow mode 2 */
  210. ret = phy_set_clr_bits(phydev, MII_BCM7XXX_TEST, MII_BCM7XXX_SHD_MODE_2, 0);
  211. if (ret < 0)
  212. return ret;
  213. return 0;
  214. }
  215. /* Workaround for putting the PHY in IDDQ mode, required
  216. * for all BCM7XXX 40nm and 65nm PHYs
  217. */
  218. static int bcm7xxx_suspend(struct phy_device *phydev)
  219. {
  220. int ret;
  221. const struct bcm7xxx_regs {
  222. int reg;
  223. u16 value;
  224. } bcm7xxx_suspend_cfg[] = {
  225. { MII_BCM7XXX_TEST, 0x008b },
  226. { MII_BCM7XXX_100TX_AUX_CTL, 0x01c0 },
  227. { MII_BCM7XXX_100TX_DISC, 0x7000 },
  228. { MII_BCM7XXX_TEST, 0x000f },
  229. { MII_BCM7XXX_100TX_AUX_CTL, 0x20d0 },
  230. { MII_BCM7XXX_TEST, 0x000b },
  231. };
  232. unsigned int i;
  233. for (i = 0; i < ARRAY_SIZE(bcm7xxx_suspend_cfg); i++) {
  234. ret = phy_write(phydev,
  235. bcm7xxx_suspend_cfg[i].reg,
  236. bcm7xxx_suspend_cfg[i].value);
  237. if (ret)
  238. return ret;
  239. }
  240. return 0;
  241. }
  242. static int bcm7xxx_dummy_config_init(struct phy_device *phydev)
  243. {
  244. return 0;
  245. }
  246. #define BCM7XXX_28NM_GPHY(_oui, _name) \
  247. { \
  248. .phy_id = (_oui), \
  249. .phy_id_mask = 0xfffffff0, \
  250. .name = _name, \
  251. .features = PHY_GBIT_FEATURES | \
  252. SUPPORTED_Pause | SUPPORTED_Asym_Pause, \
  253. .flags = PHY_IS_INTERNAL, \
  254. .config_init = bcm7xxx_28nm_config_init, \
  255. .config_aneg = genphy_config_aneg, \
  256. .read_status = genphy_read_status, \
  257. .resume = bcm7xxx_28nm_resume, \
  258. .driver = { .owner = THIS_MODULE }, \
  259. }
  260. static struct phy_driver bcm7xxx_driver[] = {
  261. BCM7XXX_28NM_GPHY(PHY_ID_BCM7250, "Broadcom BCM7250"),
  262. BCM7XXX_28NM_GPHY(PHY_ID_BCM7364, "Broadcom BCM7364"),
  263. BCM7XXX_28NM_GPHY(PHY_ID_BCM7366, "Broadcom BCM7366"),
  264. BCM7XXX_28NM_GPHY(PHY_ID_BCM7439, "Broadcom BCM7439"),
  265. BCM7XXX_28NM_GPHY(PHY_ID_BCM7439_2, "Broadcom BCM7439 (2)"),
  266. BCM7XXX_28NM_GPHY(PHY_ID_BCM7445, "Broadcom BCM7445"),
  267. {
  268. .phy_id = PHY_ID_BCM7425,
  269. .phy_id_mask = 0xfffffff0,
  270. .name = "Broadcom BCM7425",
  271. .features = PHY_GBIT_FEATURES |
  272. SUPPORTED_Pause | SUPPORTED_Asym_Pause,
  273. .flags = PHY_IS_INTERNAL,
  274. .config_init = bcm7xxx_config_init,
  275. .config_aneg = genphy_config_aneg,
  276. .read_status = genphy_read_status,
  277. .suspend = bcm7xxx_suspend,
  278. .resume = bcm7xxx_config_init,
  279. .driver = { .owner = THIS_MODULE },
  280. }, {
  281. .phy_id = PHY_ID_BCM7429,
  282. .phy_id_mask = 0xfffffff0,
  283. .name = "Broadcom BCM7429",
  284. .features = PHY_GBIT_FEATURES |
  285. SUPPORTED_Pause | SUPPORTED_Asym_Pause,
  286. .flags = PHY_IS_INTERNAL,
  287. .config_init = bcm7xxx_config_init,
  288. .config_aneg = genphy_config_aneg,
  289. .read_status = genphy_read_status,
  290. .suspend = bcm7xxx_suspend,
  291. .resume = bcm7xxx_config_init,
  292. .driver = { .owner = THIS_MODULE },
  293. }, {
  294. .phy_id = PHY_BCM_OUI_4,
  295. .phy_id_mask = 0xffff0000,
  296. .name = "Broadcom BCM7XXX 40nm",
  297. .features = PHY_GBIT_FEATURES |
  298. SUPPORTED_Pause | SUPPORTED_Asym_Pause,
  299. .flags = PHY_IS_INTERNAL,
  300. .config_init = bcm7xxx_config_init,
  301. .config_aneg = genphy_config_aneg,
  302. .read_status = genphy_read_status,
  303. .suspend = bcm7xxx_suspend,
  304. .resume = bcm7xxx_config_init,
  305. .driver = { .owner = THIS_MODULE },
  306. }, {
  307. .phy_id = PHY_BCM_OUI_5,
  308. .phy_id_mask = 0xffffff00,
  309. .name = "Broadcom BCM7XXX 65nm",
  310. .features = PHY_BASIC_FEATURES |
  311. SUPPORTED_Pause | SUPPORTED_Asym_Pause,
  312. .flags = PHY_IS_INTERNAL,
  313. .config_init = bcm7xxx_dummy_config_init,
  314. .config_aneg = genphy_config_aneg,
  315. .read_status = genphy_read_status,
  316. .suspend = bcm7xxx_suspend,
  317. .resume = bcm7xxx_config_init,
  318. .driver = { .owner = THIS_MODULE },
  319. } };
  320. static struct mdio_device_id __maybe_unused bcm7xxx_tbl[] = {
  321. { PHY_ID_BCM7250, 0xfffffff0, },
  322. { PHY_ID_BCM7364, 0xfffffff0, },
  323. { PHY_ID_BCM7366, 0xfffffff0, },
  324. { PHY_ID_BCM7425, 0xfffffff0, },
  325. { PHY_ID_BCM7429, 0xfffffff0, },
  326. { PHY_ID_BCM7439, 0xfffffff0, },
  327. { PHY_ID_BCM7445, 0xfffffff0, },
  328. { PHY_BCM_OUI_4, 0xffff0000 },
  329. { PHY_BCM_OUI_5, 0xffffff00 },
  330. { }
  331. };
  332. module_phy_driver(bcm7xxx_driver);
  333. MODULE_DEVICE_TABLE(mdio, bcm7xxx_tbl);
  334. MODULE_DESCRIPTION("Broadcom BCM7xxx internal PHY driver");
  335. MODULE_LICENSE("GPL");
  336. MODULE_AUTHOR("Broadcom Corporation");