bcm7xxx.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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_BCM7XXX_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. phydev_name(phydev), 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_BCM7XXX_64CLK_MDIO);
  194. phy_read(phydev, MII_BCM7XXX_AUX_MODE);
  195. /* set shadow mode 2 */
  196. ret = phy_set_clr_bits(phydev, MII_BCM7XXX_TEST,
  197. MII_BCM7XXX_SHD_MODE_2, MII_BCM7XXX_SHD_MODE_2);
  198. if (ret < 0)
  199. return ret;
  200. /* set iddq_clkbias */
  201. phy_write(phydev, MII_BCM7XXX_100TX_DISC, 0x0F00);
  202. udelay(10);
  203. /* reset iddq_clkbias */
  204. phy_write(phydev, MII_BCM7XXX_100TX_DISC, 0x0C00);
  205. phy_write(phydev, MII_BCM7XXX_100TX_FALSE_CAR, 0x7555);
  206. /* reset shadow mode 2 */
  207. ret = phy_set_clr_bits(phydev, MII_BCM7XXX_TEST, 0, MII_BCM7XXX_SHD_MODE_2);
  208. if (ret < 0)
  209. return ret;
  210. return 0;
  211. }
  212. /* Workaround for putting the PHY in IDDQ mode, required
  213. * for all BCM7XXX 40nm and 65nm PHYs
  214. */
  215. static int bcm7xxx_suspend(struct phy_device *phydev)
  216. {
  217. int ret;
  218. const struct bcm7xxx_regs {
  219. int reg;
  220. u16 value;
  221. } bcm7xxx_suspend_cfg[] = {
  222. { MII_BCM7XXX_TEST, 0x008b },
  223. { MII_BCM7XXX_100TX_AUX_CTL, 0x01c0 },
  224. { MII_BCM7XXX_100TX_DISC, 0x7000 },
  225. { MII_BCM7XXX_TEST, 0x000f },
  226. { MII_BCM7XXX_100TX_AUX_CTL, 0x20d0 },
  227. { MII_BCM7XXX_TEST, 0x000b },
  228. };
  229. unsigned int i;
  230. for (i = 0; i < ARRAY_SIZE(bcm7xxx_suspend_cfg); i++) {
  231. ret = phy_write(phydev,
  232. bcm7xxx_suspend_cfg[i].reg,
  233. bcm7xxx_suspend_cfg[i].value);
  234. if (ret)
  235. return ret;
  236. }
  237. return 0;
  238. }
  239. #define BCM7XXX_28NM_GPHY(_oui, _name) \
  240. { \
  241. .phy_id = (_oui), \
  242. .phy_id_mask = 0xfffffff0, \
  243. .name = _name, \
  244. .features = PHY_GBIT_FEATURES | \
  245. SUPPORTED_Pause | SUPPORTED_Asym_Pause, \
  246. .flags = PHY_IS_INTERNAL, \
  247. .config_init = bcm7xxx_28nm_config_init, \
  248. .config_aneg = genphy_config_aneg, \
  249. .read_status = genphy_read_status, \
  250. .resume = bcm7xxx_28nm_resume, \
  251. }
  252. #define BCM7XXX_40NM_EPHY(_oui, _name) \
  253. { \
  254. .phy_id = (_oui), \
  255. .phy_id_mask = 0xfffffff0, \
  256. .name = _name, \
  257. .features = PHY_BASIC_FEATURES | \
  258. SUPPORTED_Pause | SUPPORTED_Asym_Pause, \
  259. .flags = PHY_IS_INTERNAL, \
  260. .config_init = bcm7xxx_config_init, \
  261. .config_aneg = genphy_config_aneg, \
  262. .read_status = genphy_read_status, \
  263. .suspend = bcm7xxx_suspend, \
  264. .resume = bcm7xxx_config_init, \
  265. }
  266. static struct phy_driver bcm7xxx_driver[] = {
  267. BCM7XXX_28NM_GPHY(PHY_ID_BCM7250, "Broadcom BCM7250"),
  268. BCM7XXX_28NM_GPHY(PHY_ID_BCM7364, "Broadcom BCM7364"),
  269. BCM7XXX_28NM_GPHY(PHY_ID_BCM7366, "Broadcom BCM7366"),
  270. BCM7XXX_28NM_GPHY(PHY_ID_BCM7439, "Broadcom BCM7439"),
  271. BCM7XXX_28NM_GPHY(PHY_ID_BCM7439_2, "Broadcom BCM7439 (2)"),
  272. BCM7XXX_28NM_GPHY(PHY_ID_BCM7445, "Broadcom BCM7445"),
  273. BCM7XXX_40NM_EPHY(PHY_ID_BCM7346, "Broadcom BCM7346"),
  274. BCM7XXX_40NM_EPHY(PHY_ID_BCM7362, "Broadcom BCM7362"),
  275. BCM7XXX_40NM_EPHY(PHY_ID_BCM7425, "Broadcom BCM7425"),
  276. BCM7XXX_40NM_EPHY(PHY_ID_BCM7429, "Broadcom BCM7429"),
  277. BCM7XXX_40NM_EPHY(PHY_ID_BCM7435, "Broadcom BCM7435"),
  278. };
  279. static struct mdio_device_id __maybe_unused bcm7xxx_tbl[] = {
  280. { PHY_ID_BCM7250, 0xfffffff0, },
  281. { PHY_ID_BCM7364, 0xfffffff0, },
  282. { PHY_ID_BCM7366, 0xfffffff0, },
  283. { PHY_ID_BCM7346, 0xfffffff0, },
  284. { PHY_ID_BCM7362, 0xfffffff0, },
  285. { PHY_ID_BCM7425, 0xfffffff0, },
  286. { PHY_ID_BCM7429, 0xfffffff0, },
  287. { PHY_ID_BCM7439, 0xfffffff0, },
  288. { PHY_ID_BCM7435, 0xfffffff0, },
  289. { PHY_ID_BCM7445, 0xfffffff0, },
  290. { }
  291. };
  292. module_phy_driver(bcm7xxx_driver);
  293. MODULE_DEVICE_TABLE(mdio, bcm7xxx_tbl);
  294. MODULE_DESCRIPTION("Broadcom BCM7xxx internal PHY driver");
  295. MODULE_LICENSE("GPL");
  296. MODULE_AUTHOR("Broadcom Corporation");