Florian Fainelli | b560a58 | 2014-02-13 16:08:45 -0800 | [diff] [blame] | 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 | |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/phy.h> |
| 14 | #include <linux/delay.h> |
Arun Parameswaran | a1cba56 | 2015-10-06 12:25:48 -0700 | [diff] [blame] | 15 | #include "bcm-phy-lib.h" |
Florian Fainelli | b560a58 | 2014-02-13 16:08:45 -0800 | [diff] [blame] | 16 | #include <linux/bitops.h> |
| 17 | #include <linux/brcmphy.h> |
Florian Fainelli | b8f9a02 | 2014-08-22 18:55:45 -0700 | [diff] [blame] | 18 | #include <linux/mdio.h> |
Florian Fainelli | b560a58 | 2014-02-13 16:08:45 -0800 | [diff] [blame] | 19 | |
| 20 | /* Broadcom BCM7xxx internal PHY registers */ |
Florian Fainelli | b560a58 | 2014-02-13 16:08:45 -0800 | [diff] [blame] | 21 | |
| 22 | /* 40nm only register definitions */ |
| 23 | #define MII_BCM7XXX_100TX_AUX_CTL 0x10 |
| 24 | #define MII_BCM7XXX_100TX_FALSE_CAR 0x13 |
| 25 | #define MII_BCM7XXX_100TX_DISC 0x14 |
| 26 | #define MII_BCM7XXX_AUX_MODE 0x1d |
Florian Fainelli | 3ccc305 | 2016-02-06 13:09:36 -0800 | [diff] [blame] | 27 | #define MII_BCM7XXX_64CLK_MDIO BIT(12) |
Florian Fainelli | b560a58 | 2014-02-13 16:08:45 -0800 | [diff] [blame] | 28 | #define MII_BCM7XXX_TEST 0x1f |
| 29 | #define MII_BCM7XXX_SHD_MODE_2 BIT(2) |
| 30 | |
Florian Fainelli | a3622f2 | 2014-03-24 16:36:47 -0700 | [diff] [blame] | 31 | /* 28nm only register definitions */ |
| 32 | #define MISC_ADDR(base, channel) base, channel |
| 33 | |
| 34 | #define DSP_TAP10 MISC_ADDR(0x0a, 0) |
| 35 | #define PLL_PLLCTRL_1 MISC_ADDR(0x32, 1) |
| 36 | #define PLL_PLLCTRL_2 MISC_ADDR(0x32, 2) |
| 37 | #define PLL_PLLCTRL_4 MISC_ADDR(0x33, 0) |
| 38 | |
| 39 | #define AFE_RXCONFIG_0 MISC_ADDR(0x38, 0) |
| 40 | #define AFE_RXCONFIG_1 MISC_ADDR(0x38, 1) |
Florian Fainelli | a490631 | 2014-11-11 14:55:13 -0800 | [diff] [blame] | 41 | #define AFE_RXCONFIG_2 MISC_ADDR(0x38, 2) |
Florian Fainelli | a3622f2 | 2014-03-24 16:36:47 -0700 | [diff] [blame] | 42 | #define AFE_RX_LP_COUNTER MISC_ADDR(0x38, 3) |
| 43 | #define AFE_TX_CONFIG MISC_ADDR(0x39, 0) |
Florian Fainelli | a490631 | 2014-11-11 14:55:13 -0800 | [diff] [blame] | 44 | #define AFE_VDCA_ICTRL_0 MISC_ADDR(0x39, 1) |
| 45 | #define AFE_VDAC_OTHERS_0 MISC_ADDR(0x39, 3) |
Florian Fainelli | a3622f2 | 2014-03-24 16:36:47 -0700 | [diff] [blame] | 46 | #define AFE_HPF_TRIM_OTHERS MISC_ADDR(0x3a, 0) |
| 47 | |
Florian Fainelli | 9c41f2b | 2014-11-11 14:55:12 -0800 | [diff] [blame] | 48 | static void r_rc_cal_reset(struct phy_device *phydev) |
| 49 | { |
| 50 | /* Reset R_CAL/RC_CAL Engine */ |
Arun Parameswaran | a1cba56 | 2015-10-06 12:25:48 -0700 | [diff] [blame] | 51 | bcm_phy_write_exp(phydev, 0x00b0, 0x0010); |
Florian Fainelli | 9c41f2b | 2014-11-11 14:55:12 -0800 | [diff] [blame] | 52 | |
| 53 | /* Disable Reset R_AL/RC_CAL Engine */ |
Arun Parameswaran | a1cba56 | 2015-10-06 12:25:48 -0700 | [diff] [blame] | 54 | bcm_phy_write_exp(phydev, 0x00b0, 0x0000); |
Florian Fainelli | 9c41f2b | 2014-11-11 14:55:12 -0800 | [diff] [blame] | 55 | } |
| 56 | |
Florian Fainelli | 2a9df74 | 2014-11-11 14:55:11 -0800 | [diff] [blame] | 57 | static int bcm7xxx_28nm_b0_afe_config_init(struct phy_device *phydev) |
Florian Fainelli | b560a58 | 2014-02-13 16:08:45 -0800 | [diff] [blame] | 58 | { |
Florian Fainelli | b560a58 | 2014-02-13 16:08:45 -0800 | [diff] [blame] | 59 | /* Increase VCO range to prevent unlocking problem of PLL at low |
| 60 | * temp |
| 61 | */ |
Arun Parameswaran | a1cba56 | 2015-10-06 12:25:48 -0700 | [diff] [blame] | 62 | bcm_phy_write_misc(phydev, PLL_PLLCTRL_1, 0x0048); |
Florian Fainelli | b560a58 | 2014-02-13 16:08:45 -0800 | [diff] [blame] | 63 | |
| 64 | /* Change Ki to 011 */ |
Arun Parameswaran | a1cba56 | 2015-10-06 12:25:48 -0700 | [diff] [blame] | 65 | bcm_phy_write_misc(phydev, PLL_PLLCTRL_2, 0x021b); |
Florian Fainelli | b560a58 | 2014-02-13 16:08:45 -0800 | [diff] [blame] | 66 | |
| 67 | /* Disable loading of TVCO buffer to bandgap, set bandgap trim |
| 68 | * to 111 |
| 69 | */ |
Arun Parameswaran | a1cba56 | 2015-10-06 12:25:48 -0700 | [diff] [blame] | 70 | bcm_phy_write_misc(phydev, PLL_PLLCTRL_4, 0x0e20); |
Florian Fainelli | b560a58 | 2014-02-13 16:08:45 -0800 | [diff] [blame] | 71 | |
| 72 | /* Adjust bias current trim by -3 */ |
Arun Parameswaran | a1cba56 | 2015-10-06 12:25:48 -0700 | [diff] [blame] | 73 | bcm_phy_write_misc(phydev, DSP_TAP10, 0x690b); |
Florian Fainelli | b560a58 | 2014-02-13 16:08:45 -0800 | [diff] [blame] | 74 | |
| 75 | /* Switch to CORE_BASE1E */ |
Arun Parameswaran | 9200c27 | 2015-10-06 12:25:50 -0700 | [diff] [blame] | 76 | phy_write(phydev, MII_BRCM_CORE_BASE1E, 0xd); |
Florian Fainelli | b560a58 | 2014-02-13 16:08:45 -0800 | [diff] [blame] | 77 | |
Florian Fainelli | 9c41f2b | 2014-11-11 14:55:12 -0800 | [diff] [blame] | 78 | r_rc_cal_reset(phydev); |
Florian Fainelli | b560a58 | 2014-02-13 16:08:45 -0800 | [diff] [blame] | 79 | |
Florian Fainelli | 9918542 | 2014-03-24 16:36:48 -0700 | [diff] [blame] | 80 | /* write AFE_RXCONFIG_0 */ |
Arun Parameswaran | a1cba56 | 2015-10-06 12:25:48 -0700 | [diff] [blame] | 81 | bcm_phy_write_misc(phydev, AFE_RXCONFIG_0, 0xeb19); |
Florian Fainelli | 9918542 | 2014-03-24 16:36:48 -0700 | [diff] [blame] | 82 | |
| 83 | /* write AFE_RXCONFIG_1 */ |
Arun Parameswaran | a1cba56 | 2015-10-06 12:25:48 -0700 | [diff] [blame] | 84 | bcm_phy_write_misc(phydev, AFE_RXCONFIG_1, 0x9a3f); |
Florian Fainelli | 9918542 | 2014-03-24 16:36:48 -0700 | [diff] [blame] | 85 | |
| 86 | /* write AFE_RX_LP_COUNTER */ |
Arun Parameswaran | a1cba56 | 2015-10-06 12:25:48 -0700 | [diff] [blame] | 87 | bcm_phy_write_misc(phydev, AFE_RX_LP_COUNTER, 0x7fc0); |
Florian Fainelli | 9918542 | 2014-03-24 16:36:48 -0700 | [diff] [blame] | 88 | |
| 89 | /* write AFE_HPF_TRIM_OTHERS */ |
Arun Parameswaran | a1cba56 | 2015-10-06 12:25:48 -0700 | [diff] [blame] | 90 | bcm_phy_write_misc(phydev, AFE_HPF_TRIM_OTHERS, 0x000b); |
Florian Fainelli | 9918542 | 2014-03-24 16:36:48 -0700 | [diff] [blame] | 91 | |
| 92 | /* write AFTE_TX_CONFIG */ |
Arun Parameswaran | a1cba56 | 2015-10-06 12:25:48 -0700 | [diff] [blame] | 93 | bcm_phy_write_misc(phydev, AFE_TX_CONFIG, 0x0800); |
Florian Fainelli | 9918542 | 2014-03-24 16:36:48 -0700 | [diff] [blame] | 94 | |
Florian Fainelli | b560a58 | 2014-02-13 16:08:45 -0800 | [diff] [blame] | 95 | return 0; |
| 96 | } |
| 97 | |
Florian Fainelli | a490631 | 2014-11-11 14:55:13 -0800 | [diff] [blame] | 98 | static int bcm7xxx_28nm_d0_afe_config_init(struct phy_device *phydev) |
| 99 | { |
| 100 | /* AFE_RXCONFIG_0 */ |
Arun Parameswaran | a1cba56 | 2015-10-06 12:25:48 -0700 | [diff] [blame] | 101 | bcm_phy_write_misc(phydev, AFE_RXCONFIG_0, 0xeb15); |
Florian Fainelli | a490631 | 2014-11-11 14:55:13 -0800 | [diff] [blame] | 102 | |
| 103 | /* AFE_RXCONFIG_1 */ |
Arun Parameswaran | a1cba56 | 2015-10-06 12:25:48 -0700 | [diff] [blame] | 104 | bcm_phy_write_misc(phydev, AFE_RXCONFIG_1, 0x9b2f); |
Florian Fainelli | a490631 | 2014-11-11 14:55:13 -0800 | [diff] [blame] | 105 | |
| 106 | /* AFE_RXCONFIG_2, set rCal offset for HT=0 code and LT=-2 code */ |
Arun Parameswaran | a1cba56 | 2015-10-06 12:25:48 -0700 | [diff] [blame] | 107 | bcm_phy_write_misc(phydev, AFE_RXCONFIG_2, 0x2003); |
Florian Fainelli | a490631 | 2014-11-11 14:55:13 -0800 | [diff] [blame] | 108 | |
| 109 | /* AFE_RX_LP_COUNTER, set RX bandwidth to maximum */ |
Arun Parameswaran | a1cba56 | 2015-10-06 12:25:48 -0700 | [diff] [blame] | 110 | bcm_phy_write_misc(phydev, AFE_RX_LP_COUNTER, 0x7fc0); |
Florian Fainelli | a490631 | 2014-11-11 14:55:13 -0800 | [diff] [blame] | 111 | |
Florian Fainelli | 6da8253 | 2015-06-08 11:05:20 -0700 | [diff] [blame] | 112 | /* AFE_TX_CONFIG, set 100BT Cfeed=011 to improve rise/fall time */ |
Arun Parameswaran | a1cba56 | 2015-10-06 12:25:48 -0700 | [diff] [blame] | 113 | bcm_phy_write_misc(phydev, AFE_TX_CONFIG, 0x431); |
Florian Fainelli | a490631 | 2014-11-11 14:55:13 -0800 | [diff] [blame] | 114 | |
| 115 | /* AFE_VDCA_ICTRL_0, set Iq=1101 instead of 0111 for AB symmetry */ |
Arun Parameswaran | a1cba56 | 2015-10-06 12:25:48 -0700 | [diff] [blame] | 116 | bcm_phy_write_misc(phydev, AFE_VDCA_ICTRL_0, 0xa7da); |
Florian Fainelli | a490631 | 2014-11-11 14:55:13 -0800 | [diff] [blame] | 117 | |
| 118 | /* AFE_VDAC_OTHERS_0, set 1000BT Cidac=010 for all ports */ |
Arun Parameswaran | a1cba56 | 2015-10-06 12:25:48 -0700 | [diff] [blame] | 119 | bcm_phy_write_misc(phydev, AFE_VDAC_OTHERS_0, 0xa020); |
Florian Fainelli | a490631 | 2014-11-11 14:55:13 -0800 | [diff] [blame] | 120 | |
| 121 | /* AFE_HPF_TRIM_OTHERS, set 100Tx/10BT to -4.5% swing and set rCal |
| 122 | * offset for HT=0 code |
| 123 | */ |
Arun Parameswaran | a1cba56 | 2015-10-06 12:25:48 -0700 | [diff] [blame] | 124 | bcm_phy_write_misc(phydev, AFE_HPF_TRIM_OTHERS, 0x00e3); |
Florian Fainelli | a490631 | 2014-11-11 14:55:13 -0800 | [diff] [blame] | 125 | |
| 126 | /* CORE_BASE1E, force trim to overwrite and set I_ext trim to 0000 */ |
Arun Parameswaran | 9200c27 | 2015-10-06 12:25:50 -0700 | [diff] [blame] | 127 | phy_write(phydev, MII_BRCM_CORE_BASE1E, 0x0010); |
Florian Fainelli | a490631 | 2014-11-11 14:55:13 -0800 | [diff] [blame] | 128 | |
| 129 | /* DSP_TAP10, adjust bias current trim (+0% swing, +0 tick) */ |
Arun Parameswaran | a1cba56 | 2015-10-06 12:25:48 -0700 | [diff] [blame] | 130 | bcm_phy_write_misc(phydev, DSP_TAP10, 0x011b); |
Florian Fainelli | a490631 | 2014-11-11 14:55:13 -0800 | [diff] [blame] | 131 | |
| 132 | /* Reset R_CAL/RC_CAL engine */ |
| 133 | r_rc_cal_reset(phydev); |
| 134 | |
| 135 | return 0; |
| 136 | } |
| 137 | |
Florian Fainelli | 0c2fdc2 | 2014-11-11 14:55:14 -0800 | [diff] [blame] | 138 | static int bcm7xxx_28nm_e0_plus_afe_config_init(struct phy_device *phydev) |
| 139 | { |
| 140 | /* AFE_RXCONFIG_1, provide more margin for INL/DNL measurement */ |
Arun Parameswaran | a1cba56 | 2015-10-06 12:25:48 -0700 | [diff] [blame] | 141 | bcm_phy_write_misc(phydev, AFE_RXCONFIG_1, 0x9b2f); |
Florian Fainelli | 0c2fdc2 | 2014-11-11 14:55:14 -0800 | [diff] [blame] | 142 | |
Florian Fainelli | 6da8253 | 2015-06-08 11:05:20 -0700 | [diff] [blame] | 143 | /* AFE_TX_CONFIG, set 100BT Cfeed=011 to improve rise/fall time */ |
Arun Parameswaran | a1cba56 | 2015-10-06 12:25:48 -0700 | [diff] [blame] | 144 | bcm_phy_write_misc(phydev, AFE_TX_CONFIG, 0x431); |
Florian Fainelli | 6da8253 | 2015-06-08 11:05:20 -0700 | [diff] [blame] | 145 | |
Florian Fainelli | 0c2fdc2 | 2014-11-11 14:55:14 -0800 | [diff] [blame] | 146 | /* AFE_VDCA_ICTRL_0, set Iq=1101 instead of 0111 for AB symmetry */ |
Arun Parameswaran | a1cba56 | 2015-10-06 12:25:48 -0700 | [diff] [blame] | 147 | bcm_phy_write_misc(phydev, AFE_VDCA_ICTRL_0, 0xa7da); |
Florian Fainelli | 0c2fdc2 | 2014-11-11 14:55:14 -0800 | [diff] [blame] | 148 | |
| 149 | /* AFE_HPF_TRIM_OTHERS, set 100Tx/10BT to -4.5% swing and set rCal |
| 150 | * offset for HT=0 code |
| 151 | */ |
Arun Parameswaran | a1cba56 | 2015-10-06 12:25:48 -0700 | [diff] [blame] | 152 | bcm_phy_write_misc(phydev, AFE_HPF_TRIM_OTHERS, 0x00e3); |
Florian Fainelli | 0c2fdc2 | 2014-11-11 14:55:14 -0800 | [diff] [blame] | 153 | |
| 154 | /* CORE_BASE1E, force trim to overwrite and set I_ext trim to 0000 */ |
Arun Parameswaran | 9200c27 | 2015-10-06 12:25:50 -0700 | [diff] [blame] | 155 | phy_write(phydev, MII_BRCM_CORE_BASE1E, 0x0010); |
Florian Fainelli | 0c2fdc2 | 2014-11-11 14:55:14 -0800 | [diff] [blame] | 156 | |
| 157 | /* DSP_TAP10, adjust bias current trim (+0% swing, +0 tick) */ |
Arun Parameswaran | a1cba56 | 2015-10-06 12:25:48 -0700 | [diff] [blame] | 158 | bcm_phy_write_misc(phydev, DSP_TAP10, 0x011b); |
Florian Fainelli | 0c2fdc2 | 2014-11-11 14:55:14 -0800 | [diff] [blame] | 159 | |
| 160 | /* Reset R_CAL/RC_CAL engine */ |
| 161 | r_rc_cal_reset(phydev); |
| 162 | |
| 163 | return 0; |
| 164 | } |
| 165 | |
Florian Fainelli | b560a58 | 2014-02-13 16:08:45 -0800 | [diff] [blame] | 166 | static int bcm7xxx_28nm_config_init(struct phy_device *phydev) |
| 167 | { |
Florian Fainelli | d8ebfed | 2014-09-19 13:07:56 -0700 | [diff] [blame] | 168 | u8 rev = PHY_BRCM_7XXX_REV(phydev->dev_flags); |
| 169 | u8 patch = PHY_BRCM_7XXX_PATCH(phydev->dev_flags); |
Florian Fainelli | db88816 | 2016-11-22 11:40:57 -0800 | [diff] [blame^] | 170 | u8 count; |
Florian Fainelli | d8ebfed | 2014-09-19 13:07:56 -0700 | [diff] [blame] | 171 | int ret = 0; |
Florian Fainelli | b560a58 | 2014-02-13 16:08:45 -0800 | [diff] [blame] | 172 | |
Florian Fainelli | 6ec259c | 2014-11-11 14:55:10 -0800 | [diff] [blame] | 173 | pr_info_once("%s: %s PHY revision: 0x%02x, patch: %d\n", |
Andrew Lunn | 84eff6d | 2016-01-06 20:11:10 +0100 | [diff] [blame] | 174 | phydev_name(phydev), phydev->drv->name, rev, patch); |
Florian Fainelli | b560a58 | 2014-02-13 16:08:45 -0800 | [diff] [blame] | 175 | |
Florian Fainelli | 8e346e1 | 2015-06-26 10:39:04 -0700 | [diff] [blame] | 176 | /* Dummy read to a register to workaround an issue upon reset where the |
| 177 | * internal inverter may not allow the first MDIO transaction to pass |
| 178 | * the MDIO management controller and make us return 0xffff for such |
| 179 | * reads. |
| 180 | */ |
| 181 | phy_read(phydev, MII_BMSR); |
| 182 | |
Florian Fainelli | d8ebfed | 2014-09-19 13:07:56 -0700 | [diff] [blame] | 183 | switch (rev) { |
Florian Fainelli | d8ebfed | 2014-09-19 13:07:56 -0700 | [diff] [blame] | 184 | case 0xb0: |
Florian Fainelli | 2a9df74 | 2014-11-11 14:55:11 -0800 | [diff] [blame] | 185 | ret = bcm7xxx_28nm_b0_afe_config_init(phydev); |
Florian Fainelli | d8ebfed | 2014-09-19 13:07:56 -0700 | [diff] [blame] | 186 | break; |
Florian Fainelli | a490631 | 2014-11-11 14:55:13 -0800 | [diff] [blame] | 187 | case 0xd0: |
| 188 | ret = bcm7xxx_28nm_d0_afe_config_init(phydev); |
| 189 | break; |
Florian Fainelli | 0c2fdc2 | 2014-11-11 14:55:14 -0800 | [diff] [blame] | 190 | case 0xe0: |
| 191 | case 0xf0: |
Florian Fainelli | 60efff0 | 2014-12-03 09:57:00 -0800 | [diff] [blame] | 192 | /* Rev G0 introduces a roll over */ |
| 193 | case 0x10: |
Florian Fainelli | 0c2fdc2 | 2014-11-11 14:55:14 -0800 | [diff] [blame] | 194 | ret = bcm7xxx_28nm_e0_plus_afe_config_init(phydev); |
| 195 | break; |
Florian Fainelli | d8ebfed | 2014-09-19 13:07:56 -0700 | [diff] [blame] | 196 | default: |
Florian Fainelli | d8ebfed | 2014-09-19 13:07:56 -0700 | [diff] [blame] | 197 | break; |
| 198 | } |
| 199 | |
Florian Fainelli | 9df54dd | 2014-08-22 18:55:41 -0700 | [diff] [blame] | 200 | if (ret) |
| 201 | return ret; |
| 202 | |
Florian Fainelli | db88816 | 2016-11-22 11:40:57 -0800 | [diff] [blame^] | 203 | ret = bcm_phy_downshift_get(phydev, &count); |
| 204 | if (ret) |
| 205 | return ret; |
| 206 | |
| 207 | /* Only enable EEE if Wirespeed/downshift is disabled */ |
| 208 | ret = bcm_phy_set_eee(phydev, count == DOWNSHIFT_DEV_DISABLE); |
Florian Fainelli | b8f9a02 | 2014-08-22 18:55:45 -0700 | [diff] [blame] | 209 | if (ret) |
| 210 | return ret; |
| 211 | |
Arun Parameswaran | a1cba56 | 2015-10-06 12:25:48 -0700 | [diff] [blame] | 212 | return bcm_phy_enable_apd(phydev, true); |
Florian Fainelli | b560a58 | 2014-02-13 16:08:45 -0800 | [diff] [blame] | 213 | } |
| 214 | |
Florian Fainelli | 4fd14e0 | 2014-08-14 16:52:52 -0700 | [diff] [blame] | 215 | static int bcm7xxx_28nm_resume(struct phy_device *phydev) |
| 216 | { |
| 217 | int ret; |
| 218 | |
| 219 | /* Re-apply workarounds coming out suspend/resume */ |
| 220 | ret = bcm7xxx_28nm_config_init(phydev); |
| 221 | if (ret) |
| 222 | return ret; |
| 223 | |
| 224 | /* 28nm Gigabit PHYs come out of reset without any half-duplex |
| 225 | * or "hub" compliant advertised mode, fix that. This does not |
| 226 | * cause any problems with the PHY library since genphy_config_aneg() |
| 227 | * gracefully handles auto-negotiated and forced modes. |
| 228 | */ |
| 229 | return genphy_config_aneg(phydev); |
| 230 | } |
| 231 | |
Florian Fainelli | b560a58 | 2014-02-13 16:08:45 -0800 | [diff] [blame] | 232 | static int phy_set_clr_bits(struct phy_device *dev, int location, |
| 233 | int set_mask, int clr_mask) |
| 234 | { |
| 235 | int v, ret; |
| 236 | |
| 237 | v = phy_read(dev, location); |
| 238 | if (v < 0) |
| 239 | return v; |
| 240 | |
| 241 | v &= ~clr_mask; |
| 242 | v |= set_mask; |
| 243 | |
| 244 | ret = phy_write(dev, location, v); |
| 245 | if (ret < 0) |
| 246 | return ret; |
| 247 | |
| 248 | return v; |
| 249 | } |
| 250 | |
| 251 | static int bcm7xxx_config_init(struct phy_device *phydev) |
| 252 | { |
| 253 | int ret; |
| 254 | |
| 255 | /* Enable 64 clock MDIO */ |
Florian Fainelli | 3ccc305 | 2016-02-06 13:09:36 -0800 | [diff] [blame] | 256 | phy_write(phydev, MII_BCM7XXX_AUX_MODE, MII_BCM7XXX_64CLK_MDIO); |
Florian Fainelli | b560a58 | 2014-02-13 16:08:45 -0800 | [diff] [blame] | 257 | phy_read(phydev, MII_BCM7XXX_AUX_MODE); |
| 258 | |
Florian Fainelli | b560a58 | 2014-02-13 16:08:45 -0800 | [diff] [blame] | 259 | /* set shadow mode 2 */ |
| 260 | ret = phy_set_clr_bits(phydev, MII_BCM7XXX_TEST, |
| 261 | MII_BCM7XXX_SHD_MODE_2, MII_BCM7XXX_SHD_MODE_2); |
| 262 | if (ret < 0) |
| 263 | return ret; |
| 264 | |
| 265 | /* set iddq_clkbias */ |
| 266 | phy_write(phydev, MII_BCM7XXX_100TX_DISC, 0x0F00); |
| 267 | udelay(10); |
| 268 | |
| 269 | /* reset iddq_clkbias */ |
| 270 | phy_write(phydev, MII_BCM7XXX_100TX_DISC, 0x0C00); |
| 271 | |
| 272 | phy_write(phydev, MII_BCM7XXX_100TX_FALSE_CAR, 0x7555); |
| 273 | |
| 274 | /* reset shadow mode 2 */ |
Florian Fainelli | 50d8998 | 2016-02-06 12:58:48 -0800 | [diff] [blame] | 275 | ret = phy_set_clr_bits(phydev, MII_BCM7XXX_TEST, 0, MII_BCM7XXX_SHD_MODE_2); |
Florian Fainelli | b560a58 | 2014-02-13 16:08:45 -0800 | [diff] [blame] | 276 | if (ret < 0) |
| 277 | return ret; |
| 278 | |
| 279 | return 0; |
| 280 | } |
| 281 | |
| 282 | /* Workaround for putting the PHY in IDDQ mode, required |
Florian Fainelli | 82c084f | 2014-08-14 16:52:53 -0700 | [diff] [blame] | 283 | * for all BCM7XXX 40nm and 65nm PHYs |
Florian Fainelli | b560a58 | 2014-02-13 16:08:45 -0800 | [diff] [blame] | 284 | */ |
| 285 | static int bcm7xxx_suspend(struct phy_device *phydev) |
| 286 | { |
| 287 | int ret; |
| 288 | const struct bcm7xxx_regs { |
| 289 | int reg; |
| 290 | u16 value; |
| 291 | } bcm7xxx_suspend_cfg[] = { |
| 292 | { MII_BCM7XXX_TEST, 0x008b }, |
| 293 | { MII_BCM7XXX_100TX_AUX_CTL, 0x01c0 }, |
| 294 | { MII_BCM7XXX_100TX_DISC, 0x7000 }, |
| 295 | { MII_BCM7XXX_TEST, 0x000f }, |
| 296 | { MII_BCM7XXX_100TX_AUX_CTL, 0x20d0 }, |
| 297 | { MII_BCM7XXX_TEST, 0x000b }, |
| 298 | }; |
| 299 | unsigned int i; |
| 300 | |
| 301 | for (i = 0; i < ARRAY_SIZE(bcm7xxx_suspend_cfg); i++) { |
| 302 | ret = phy_write(phydev, |
| 303 | bcm7xxx_suspend_cfg[i].reg, |
| 304 | bcm7xxx_suspend_cfg[i].value); |
| 305 | if (ret) |
| 306 | return ret; |
| 307 | } |
| 308 | |
| 309 | return 0; |
| 310 | } |
| 311 | |
Florian Fainelli | db88816 | 2016-11-22 11:40:57 -0800 | [diff] [blame^] | 312 | static int bcm7xxx_28nm_get_tunable(struct phy_device *phydev, |
| 313 | struct ethtool_tunable *tuna, |
| 314 | void *data) |
| 315 | { |
| 316 | switch (tuna->id) { |
| 317 | case ETHTOOL_PHY_DOWNSHIFT: |
| 318 | return bcm_phy_downshift_get(phydev, (u8 *)data); |
| 319 | default: |
| 320 | return -EOPNOTSUPP; |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | static int bcm7xxx_28nm_set_tunable(struct phy_device *phydev, |
| 325 | struct ethtool_tunable *tuna, |
| 326 | const void *data) |
| 327 | { |
| 328 | u8 count = *(u8 *)data; |
| 329 | int ret; |
| 330 | |
| 331 | switch (tuna->id) { |
| 332 | case ETHTOOL_PHY_DOWNSHIFT: |
| 333 | ret = bcm_phy_downshift_set(phydev, count); |
| 334 | break; |
| 335 | default: |
| 336 | return -EOPNOTSUPP; |
| 337 | } |
| 338 | |
| 339 | if (ret) |
| 340 | return ret; |
| 341 | |
| 342 | /* Disable EEE advertisment since this prevents the PHY |
| 343 | * from successfully linking up, trigger auto-negotiation restart |
| 344 | * to let the MAC decide what to do. |
| 345 | */ |
| 346 | ret = bcm_phy_set_eee(phydev, count == DOWNSHIFT_DEV_DISABLE); |
| 347 | if (ret) |
| 348 | return ret; |
| 349 | |
| 350 | return genphy_restart_aneg(phydev); |
| 351 | } |
| 352 | |
Florian Fainelli | 153df3c | 2014-08-26 13:15:24 -0700 | [diff] [blame] | 353 | #define BCM7XXX_28NM_GPHY(_oui, _name) \ |
| 354 | { \ |
| 355 | .phy_id = (_oui), \ |
| 356 | .phy_id_mask = 0xfffffff0, \ |
| 357 | .name = _name, \ |
| 358 | .features = PHY_GBIT_FEATURES | \ |
| 359 | SUPPORTED_Pause | SUPPORTED_Asym_Pause, \ |
| 360 | .flags = PHY_IS_INTERNAL, \ |
Florian Fainelli | 2a9df74 | 2014-11-11 14:55:11 -0800 | [diff] [blame] | 361 | .config_init = bcm7xxx_28nm_config_init, \ |
Florian Fainelli | 153df3c | 2014-08-26 13:15:24 -0700 | [diff] [blame] | 362 | .config_aneg = genphy_config_aneg, \ |
| 363 | .read_status = genphy_read_status, \ |
| 364 | .resume = bcm7xxx_28nm_resume, \ |
Florian Fainelli | db88816 | 2016-11-22 11:40:57 -0800 | [diff] [blame^] | 365 | .get_tunable = bcm7xxx_28nm_get_tunable, \ |
| 366 | .set_tunable = bcm7xxx_28nm_set_tunable, \ |
Florian Fainelli | 153df3c | 2014-08-26 13:15:24 -0700 | [diff] [blame] | 367 | } |
| 368 | |
Florian Fainelli | 3125c08 | 2016-02-06 13:09:37 -0800 | [diff] [blame] | 369 | #define BCM7XXX_40NM_EPHY(_oui, _name) \ |
| 370 | { \ |
| 371 | .phy_id = (_oui), \ |
| 372 | .phy_id_mask = 0xfffffff0, \ |
| 373 | .name = _name, \ |
| 374 | .features = PHY_BASIC_FEATURES | \ |
| 375 | SUPPORTED_Pause | SUPPORTED_Asym_Pause, \ |
| 376 | .flags = PHY_IS_INTERNAL, \ |
| 377 | .config_init = bcm7xxx_config_init, \ |
| 378 | .config_aneg = genphy_config_aneg, \ |
| 379 | .read_status = genphy_read_status, \ |
| 380 | .suspend = bcm7xxx_suspend, \ |
| 381 | .resume = bcm7xxx_config_init, \ |
| 382 | } |
| 383 | |
Florian Fainelli | b560a58 | 2014-02-13 16:08:45 -0800 | [diff] [blame] | 384 | static struct phy_driver bcm7xxx_driver[] = { |
Florian Fainelli | 430ad68 | 2014-08-26 13:15:27 -0700 | [diff] [blame] | 385 | BCM7XXX_28NM_GPHY(PHY_ID_BCM7250, "Broadcom BCM7250"), |
| 386 | BCM7XXX_28NM_GPHY(PHY_ID_BCM7364, "Broadcom BCM7364"), |
Florian Fainelli | 153df3c | 2014-08-26 13:15:24 -0700 | [diff] [blame] | 387 | BCM7XXX_28NM_GPHY(PHY_ID_BCM7366, "Broadcom BCM7366"), |
| 388 | BCM7XXX_28NM_GPHY(PHY_ID_BCM7439, "Broadcom BCM7439"), |
Florian Fainelli | 59e33c2 | 2015-03-09 15:44:13 -0700 | [diff] [blame] | 389 | BCM7XXX_28NM_GPHY(PHY_ID_BCM7439_2, "Broadcom BCM7439 (2)"), |
Florian Fainelli | 153df3c | 2014-08-26 13:15:24 -0700 | [diff] [blame] | 390 | BCM7XXX_28NM_GPHY(PHY_ID_BCM7445, "Broadcom BCM7445"), |
Jaedon Shin | 4cef191 | 2016-03-25 12:46:54 +0900 | [diff] [blame] | 391 | BCM7XXX_40NM_EPHY(PHY_ID_BCM7346, "Broadcom BCM7346"), |
| 392 | BCM7XXX_40NM_EPHY(PHY_ID_BCM7362, "Broadcom BCM7362"), |
Florian Fainelli | 3125c08 | 2016-02-06 13:09:37 -0800 | [diff] [blame] | 393 | BCM7XXX_40NM_EPHY(PHY_ID_BCM7425, "Broadcom BCM7425"), |
| 394 | BCM7XXX_40NM_EPHY(PHY_ID_BCM7429, "Broadcom BCM7429"), |
| 395 | BCM7XXX_40NM_EPHY(PHY_ID_BCM7435, "Broadcom BCM7435"), |
David S. Miller | b633353 | 2016-02-23 00:09:14 -0500 | [diff] [blame] | 396 | }; |
Florian Fainelli | b560a58 | 2014-02-13 16:08:45 -0800 | [diff] [blame] | 397 | |
| 398 | static struct mdio_device_id __maybe_unused bcm7xxx_tbl[] = { |
Florian Fainelli | 430ad68 | 2014-08-26 13:15:27 -0700 | [diff] [blame] | 399 | { PHY_ID_BCM7250, 0xfffffff0, }, |
| 400 | { PHY_ID_BCM7364, 0xfffffff0, }, |
Florian Fainelli | b560a58 | 2014-02-13 16:08:45 -0800 | [diff] [blame] | 401 | { PHY_ID_BCM7366, 0xfffffff0, }, |
Jaedon Shin | 4cef191 | 2016-03-25 12:46:54 +0900 | [diff] [blame] | 402 | { PHY_ID_BCM7346, 0xfffffff0, }, |
| 403 | { PHY_ID_BCM7362, 0xfffffff0, }, |
Petri Gynther | d068b02 | 2014-10-01 11:58:02 -0700 | [diff] [blame] | 404 | { PHY_ID_BCM7425, 0xfffffff0, }, |
| 405 | { PHY_ID_BCM7429, 0xfffffff0, }, |
Florian Fainelli | b560a58 | 2014-02-13 16:08:45 -0800 | [diff] [blame] | 406 | { PHY_ID_BCM7439, 0xfffffff0, }, |
Florian Fainelli | 9458cea | 2015-11-24 15:30:21 -0800 | [diff] [blame] | 407 | { PHY_ID_BCM7435, 0xfffffff0, }, |
Florian Fainelli | b560a58 | 2014-02-13 16:08:45 -0800 | [diff] [blame] | 408 | { PHY_ID_BCM7445, 0xfffffff0, }, |
Florian Fainelli | b560a58 | 2014-02-13 16:08:45 -0800 | [diff] [blame] | 409 | { } |
| 410 | }; |
| 411 | |
Johan Hovold | 50fd715 | 2014-11-11 19:45:59 +0100 | [diff] [blame] | 412 | module_phy_driver(bcm7xxx_driver); |
Florian Fainelli | b560a58 | 2014-02-13 16:08:45 -0800 | [diff] [blame] | 413 | |
| 414 | MODULE_DEVICE_TABLE(mdio, bcm7xxx_tbl); |
| 415 | |
| 416 | MODULE_DESCRIPTION("Broadcom BCM7xxx internal PHY driver"); |
| 417 | MODULE_LICENSE("GPL"); |
| 418 | MODULE_AUTHOR("Broadcom Corporation"); |