Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 2 | /* |
| 3 | * TI PHY drivers |
| 4 | * |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 5 | */ |
| 6 | #include <common.h> |
| 7 | #include <phy.h> |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 8 | #include <linux/compat.h> |
| 9 | #include <malloc.h> |
| 10 | |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 11 | #include <dm.h> |
| 12 | #include <dt-bindings/net/ti-dp83867.h> |
| 13 | |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 14 | |
| 15 | /* TI DP83867 */ |
| 16 | #define DP83867_DEVADDR 0x1f |
| 17 | |
| 18 | #define MII_DP83867_PHYCTRL 0x10 |
| 19 | #define MII_DP83867_MICR 0x12 |
Siva Durga Prasad Paladugu | 02c7be6 | 2016-03-25 12:53:43 +0530 | [diff] [blame] | 20 | #define MII_DP83867_CFG2 0x14 |
| 21 | #define MII_DP83867_BISCR 0x16 |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 22 | #define DP83867_CTRL 0x1f |
| 23 | |
| 24 | /* Extended Registers */ |
Murali Karicheri | 9b05076 | 2018-06-28 14:26:34 -0500 | [diff] [blame] | 25 | #define DP83867_CFG4 0x0031 |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 26 | #define DP83867_RGMIICTL 0x0032 |
Janine Hagemann | b3dd2ed | 2018-08-28 08:25:38 +0200 | [diff] [blame^] | 27 | #define DP83867_STRAP_STS1 0x006E |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 28 | #define DP83867_RGMIIDCTL 0x0086 |
Mugunthan V N | 5b6b18e | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 29 | #define DP83867_IO_MUX_CFG 0x0170 |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 30 | |
| 31 | #define DP83867_SW_RESET BIT(15) |
| 32 | #define DP83867_SW_RESTART BIT(14) |
| 33 | |
| 34 | /* MICR Interrupt bits */ |
| 35 | #define MII_DP83867_MICR_AN_ERR_INT_EN BIT(15) |
| 36 | #define MII_DP83867_MICR_SPEED_CHNG_INT_EN BIT(14) |
| 37 | #define MII_DP83867_MICR_DUP_MODE_CHNG_INT_EN BIT(13) |
| 38 | #define MII_DP83867_MICR_PAGE_RXD_INT_EN BIT(12) |
| 39 | #define MII_DP83867_MICR_AUTONEG_COMP_INT_EN BIT(11) |
| 40 | #define MII_DP83867_MICR_LINK_STS_CHNG_INT_EN BIT(10) |
| 41 | #define MII_DP83867_MICR_FALSE_CARRIER_INT_EN BIT(8) |
| 42 | #define MII_DP83867_MICR_SLEEP_MODE_CHNG_INT_EN BIT(4) |
| 43 | #define MII_DP83867_MICR_WOL_INT_EN BIT(3) |
| 44 | #define MII_DP83867_MICR_XGMII_ERR_INT_EN BIT(2) |
| 45 | #define MII_DP83867_MICR_POL_CHNG_INT_EN BIT(1) |
| 46 | #define MII_DP83867_MICR_JABBER_INT_EN BIT(0) |
| 47 | |
| 48 | /* RGMIICTL bits */ |
| 49 | #define DP83867_RGMII_TX_CLK_DELAY_EN BIT(1) |
| 50 | #define DP83867_RGMII_RX_CLK_DELAY_EN BIT(0) |
| 51 | |
Janine Hagemann | b3dd2ed | 2018-08-28 08:25:38 +0200 | [diff] [blame^] | 52 | /* STRAP_STS1 bits */ |
| 53 | #define DP83867_STRAP_STS1_RESERVED BIT(11) |
| 54 | |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 55 | /* PHY CTRL bits */ |
| 56 | #define DP83867_PHYCR_FIFO_DEPTH_SHIFT 14 |
Janine Hagemann | b3dd2ed | 2018-08-28 08:25:38 +0200 | [diff] [blame^] | 57 | #define DP83867_PHYCR_RESERVED_MASK BIT(11) |
Michal Simek | f645915 | 2015-10-19 10:43:30 +0200 | [diff] [blame] | 58 | #define DP83867_MDI_CROSSOVER 5 |
| 59 | #define DP83867_MDI_CROSSOVER_AUTO 2 |
Siva Durga Prasad Paladugu | 02c7be6 | 2016-03-25 12:53:43 +0530 | [diff] [blame] | 60 | #define DP83867_MDI_CROSSOVER_MDIX 2 |
| 61 | #define DP83867_PHYCTRL_SGMIIEN 0x0800 |
| 62 | #define DP83867_PHYCTRL_RXFIFO_SHIFT 12 |
| 63 | #define DP83867_PHYCTRL_TXFIFO_SHIFT 14 |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 64 | |
| 65 | /* RGMIIDCTL bits */ |
| 66 | #define DP83867_RGMII_TX_CLK_DELAY_SHIFT 4 |
| 67 | |
Siva Durga Prasad Paladugu | 02c7be6 | 2016-03-25 12:53:43 +0530 | [diff] [blame] | 68 | /* CFG2 bits */ |
| 69 | #define MII_DP83867_CFG2_SPEEDOPT_10EN 0x0040 |
| 70 | #define MII_DP83867_CFG2_SGMII_AUTONEGEN 0x0080 |
| 71 | #define MII_DP83867_CFG2_SPEEDOPT_ENH 0x0100 |
| 72 | #define MII_DP83867_CFG2_SPEEDOPT_CNT 0x0800 |
| 73 | #define MII_DP83867_CFG2_SPEEDOPT_INTLOW 0x2000 |
| 74 | #define MII_DP83867_CFG2_MASK 0x003F |
| 75 | |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 76 | #define MII_MMD_CTRL 0x0d /* MMD Access Control Register */ |
| 77 | #define MII_MMD_DATA 0x0e /* MMD Access Data Register */ |
| 78 | |
| 79 | /* MMD Access Control register fields */ |
| 80 | #define MII_MMD_CTRL_DEVAD_MASK 0x1f /* Mask MMD DEVAD*/ |
| 81 | #define MII_MMD_CTRL_ADDR 0x0000 /* Address */ |
| 82 | #define MII_MMD_CTRL_NOINCR 0x4000 /* no post increment */ |
| 83 | #define MII_MMD_CTRL_INCR_RDWT 0x8000 /* post increment on reads & writes */ |
| 84 | #define MII_MMD_CTRL_INCR_ON_WT 0xC000 /* post increment on writes only */ |
| 85 | |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 86 | /* User setting - can be taken from DTS */ |
| 87 | #define DEFAULT_RX_ID_DELAY DP83867_RGMIIDCTL_2_25_NS |
| 88 | #define DEFAULT_TX_ID_DELAY DP83867_RGMIIDCTL_2_75_NS |
| 89 | #define DEFAULT_FIFO_DEPTH DP83867_PHYCR_FIFO_DEPTH_4_B_NIB |
| 90 | |
Mugunthan V N | 5b6b18e | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 91 | /* IO_MUX_CFG bits */ |
| 92 | #define DP83867_IO_MUX_CFG_IO_IMPEDANCE_CTRL 0x1f |
| 93 | |
| 94 | #define DP83867_IO_MUX_CFG_IO_IMPEDANCE_MAX 0x0 |
| 95 | #define DP83867_IO_MUX_CFG_IO_IMPEDANCE_MIN 0x1f |
| 96 | |
Janine Hagemann | ed51bfc | 2018-08-28 08:25:37 +0200 | [diff] [blame] | 97 | /* CFG4 bits */ |
| 98 | #define DP83867_CFG4_PORT_MIRROR_EN BIT(0) |
| 99 | |
| 100 | enum { |
| 101 | DP83867_PORT_MIRRORING_KEEP, |
| 102 | DP83867_PORT_MIRRORING_EN, |
| 103 | DP83867_PORT_MIRRORING_DIS, |
| 104 | }; |
| 105 | |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 106 | struct dp83867_private { |
| 107 | int rx_id_delay; |
| 108 | int tx_id_delay; |
| 109 | int fifo_depth; |
Mugunthan V N | 5b6b18e | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 110 | int io_impedance; |
Murali Karicheri | 9b05076 | 2018-06-28 14:26:34 -0500 | [diff] [blame] | 111 | bool rxctrl_strap_quirk; |
Janine Hagemann | ed51bfc | 2018-08-28 08:25:37 +0200 | [diff] [blame] | 112 | int port_mirroring; |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 113 | }; |
| 114 | |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 115 | /** |
| 116 | * phy_read_mmd_indirect - reads data from the MMD registers |
| 117 | * @phydev: The PHY device bus |
| 118 | * @prtad: MMD Address |
| 119 | * @devad: MMD DEVAD |
| 120 | * @addr: PHY address on the MII bus |
| 121 | * |
| 122 | * Description: it reads data from the MMD registers (clause 22 to access to |
| 123 | * clause 45) of the specified phy address. |
| 124 | * To read these registers we have: |
| 125 | * 1) Write reg 13 // DEVAD |
| 126 | * 2) Write reg 14 // MMD Address |
| 127 | * 3) Write reg 13 // MMD Data Command for MMD DEVAD |
| 128 | * 3) Read reg 14 // Read MMD data |
| 129 | */ |
| 130 | int phy_read_mmd_indirect(struct phy_device *phydev, int prtad, |
| 131 | int devad, int addr) |
| 132 | { |
| 133 | int value = -1; |
| 134 | |
| 135 | /* Write the desired MMD Devad */ |
| 136 | phy_write(phydev, addr, MII_MMD_CTRL, devad); |
| 137 | |
| 138 | /* Write the desired MMD register address */ |
| 139 | phy_write(phydev, addr, MII_MMD_DATA, prtad); |
| 140 | |
| 141 | /* Select the Function : DATA with no post increment */ |
| 142 | phy_write(phydev, addr, MII_MMD_CTRL, (devad | MII_MMD_CTRL_NOINCR)); |
| 143 | |
| 144 | /* Read the content of the MMD's selected register */ |
| 145 | value = phy_read(phydev, addr, MII_MMD_DATA); |
| 146 | return value; |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * phy_write_mmd_indirect - writes data to the MMD registers |
| 151 | * @phydev: The PHY device |
| 152 | * @prtad: MMD Address |
| 153 | * @devad: MMD DEVAD |
| 154 | * @addr: PHY address on the MII bus |
| 155 | * @data: data to write in the MMD register |
| 156 | * |
| 157 | * Description: Write data from the MMD registers of the specified |
| 158 | * phy address. |
| 159 | * To write these registers we have: |
| 160 | * 1) Write reg 13 // DEVAD |
| 161 | * 2) Write reg 14 // MMD Address |
| 162 | * 3) Write reg 13 // MMD Data Command for MMD DEVAD |
| 163 | * 3) Write reg 14 // Write MMD data |
| 164 | */ |
| 165 | void phy_write_mmd_indirect(struct phy_device *phydev, int prtad, |
| 166 | int devad, int addr, u32 data) |
| 167 | { |
| 168 | /* Write the desired MMD Devad */ |
| 169 | phy_write(phydev, addr, MII_MMD_CTRL, devad); |
| 170 | |
| 171 | /* Write the desired MMD register address */ |
| 172 | phy_write(phydev, addr, MII_MMD_DATA, prtad); |
| 173 | |
| 174 | /* Select the Function : DATA with no post increment */ |
| 175 | phy_write(phydev, addr, MII_MMD_CTRL, (devad | MII_MMD_CTRL_NOINCR)); |
| 176 | |
| 177 | /* Write the data into MMD's selected register */ |
| 178 | phy_write(phydev, addr, MII_MMD_DATA, data); |
| 179 | } |
| 180 | |
Janine Hagemann | ed51bfc | 2018-08-28 08:25:37 +0200 | [diff] [blame] | 181 | static int dp83867_config_port_mirroring(struct phy_device *phydev) |
| 182 | { |
| 183 | struct dp83867_private *dp83867 = |
| 184 | (struct dp83867_private *)phydev->priv; |
| 185 | u16 val; |
| 186 | |
| 187 | val = phy_read_mmd_indirect(phydev, DP83867_CFG4, DP83867_DEVADDR, |
| 188 | phydev->addr); |
| 189 | |
| 190 | if (dp83867->port_mirroring == DP83867_PORT_MIRRORING_EN) |
| 191 | val |= DP83867_CFG4_PORT_MIRROR_EN; |
| 192 | else |
| 193 | val &= ~DP83867_CFG4_PORT_MIRROR_EN; |
| 194 | |
| 195 | phy_write_mmd_indirect(phydev, DP83867_CFG4, DP83867_DEVADDR, |
| 196 | phydev->addr, val); |
| 197 | |
| 198 | return 0; |
| 199 | } |
| 200 | |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 201 | #if defined(CONFIG_DM_ETH) |
| 202 | /** |
| 203 | * dp83867_data_init - Convenience function for setting PHY specific data |
| 204 | * |
| 205 | * @phydev: the phy_device struct |
| 206 | */ |
| 207 | static int dp83867_of_init(struct phy_device *phydev) |
| 208 | { |
| 209 | struct dp83867_private *dp83867 = phydev->priv; |
Grygorii Strashko | 00e2c24 | 2018-07-05 12:02:49 -0500 | [diff] [blame] | 210 | ofnode node; |
| 211 | |
| 212 | node = phy_get_ofnode(phydev); |
| 213 | if (!ofnode_valid(node)) |
| 214 | return -EINVAL; |
Mugunthan V N | 5b6b18e | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 215 | |
Grygorii Strashko | 9df3505 | 2018-06-28 14:26:35 -0500 | [diff] [blame] | 216 | if (ofnode_read_bool(node, "ti,max-output-impedance")) |
Mugunthan V N | 5b6b18e | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 217 | dp83867->io_impedance = DP83867_IO_MUX_CFG_IO_IMPEDANCE_MAX; |
Grygorii Strashko | 9df3505 | 2018-06-28 14:26:35 -0500 | [diff] [blame] | 218 | else if (ofnode_read_bool(node, "ti,min-output-impedance")) |
Mugunthan V N | 5b6b18e | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 219 | dp83867->io_impedance = DP83867_IO_MUX_CFG_IO_IMPEDANCE_MIN; |
| 220 | else |
| 221 | dp83867->io_impedance = -EINVAL; |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 222 | |
Grygorii Strashko | 9df3505 | 2018-06-28 14:26:35 -0500 | [diff] [blame] | 223 | if (ofnode_read_bool(node, "ti,dp83867-rxctrl-strap-quirk")) |
Murali Karicheri | 9b05076 | 2018-06-28 14:26:34 -0500 | [diff] [blame] | 224 | dp83867->rxctrl_strap_quirk = true; |
Grygorii Strashko | 9df3505 | 2018-06-28 14:26:35 -0500 | [diff] [blame] | 225 | dp83867->rx_id_delay = ofnode_read_u32_default(node, |
| 226 | "ti,rx-internal-delay", |
| 227 | -1); |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 228 | |
Grygorii Strashko | 9df3505 | 2018-06-28 14:26:35 -0500 | [diff] [blame] | 229 | dp83867->tx_id_delay = ofnode_read_u32_default(node, |
| 230 | "ti,tx-internal-delay", |
| 231 | -1); |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 232 | |
Grygorii Strashko | 9df3505 | 2018-06-28 14:26:35 -0500 | [diff] [blame] | 233 | dp83867->fifo_depth = ofnode_read_u32_default(node, "ti,fifo-depth", |
| 234 | -1); |
Janine Hagemann | ed51bfc | 2018-08-28 08:25:37 +0200 | [diff] [blame] | 235 | if (ofnode_read_bool(node, "enet-phy-lane-swap")) |
| 236 | dp83867->port_mirroring = DP83867_PORT_MIRRORING_EN; |
| 237 | |
| 238 | if (ofnode_read_bool(node, "enet-phy-lane-no-swap")) |
| 239 | dp83867->port_mirroring = DP83867_PORT_MIRRORING_DIS; |
| 240 | |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 241 | |
| 242 | return 0; |
| 243 | } |
| 244 | #else |
| 245 | static int dp83867_of_init(struct phy_device *phydev) |
| 246 | { |
| 247 | struct dp83867_private *dp83867 = phydev->priv; |
| 248 | |
| 249 | dp83867->rx_id_delay = DEFAULT_RX_ID_DELAY; |
| 250 | dp83867->tx_id_delay = DEFAULT_TX_ID_DELAY; |
| 251 | dp83867->fifo_depth = DEFAULT_FIFO_DEPTH; |
Mugunthan V N | 5b6b18e | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 252 | dp83867->io_impedance = -EINVAL; |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 253 | |
| 254 | return 0; |
| 255 | } |
| 256 | #endif |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 257 | |
| 258 | static int dp83867_config(struct phy_device *phydev) |
| 259 | { |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 260 | struct dp83867_private *dp83867; |
Siva Durga Prasad Paladugu | 02c7be6 | 2016-03-25 12:53:43 +0530 | [diff] [blame] | 261 | unsigned int val, delay, cfg2; |
Janine Hagemann | b3dd2ed | 2018-08-28 08:25:38 +0200 | [diff] [blame^] | 262 | int ret, bs; |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 263 | |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 264 | if (!phydev->priv) { |
| 265 | dp83867 = kzalloc(sizeof(*dp83867), GFP_KERNEL); |
| 266 | if (!dp83867) |
| 267 | return -ENOMEM; |
| 268 | |
| 269 | phydev->priv = dp83867; |
| 270 | ret = dp83867_of_init(phydev); |
| 271 | if (ret) |
| 272 | goto err_out; |
| 273 | } else { |
| 274 | dp83867 = (struct dp83867_private *)phydev->priv; |
| 275 | } |
| 276 | |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 277 | /* Restart the PHY. */ |
| 278 | val = phy_read(phydev, MDIO_DEVAD_NONE, DP83867_CTRL); |
| 279 | phy_write(phydev, MDIO_DEVAD_NONE, DP83867_CTRL, |
| 280 | val | DP83867_SW_RESTART); |
| 281 | |
Murali Karicheri | 9b05076 | 2018-06-28 14:26:34 -0500 | [diff] [blame] | 282 | /* Mode 1 or 2 workaround */ |
| 283 | if (dp83867->rxctrl_strap_quirk) { |
| 284 | val = phy_read_mmd_indirect(phydev, DP83867_CFG4, |
| 285 | DP83867_DEVADDR, phydev->addr); |
| 286 | val &= ~BIT(7); |
| 287 | phy_write_mmd_indirect(phydev, DP83867_CFG4, |
| 288 | DP83867_DEVADDR, phydev->addr, val); |
| 289 | } |
| 290 | |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 291 | if (phy_interface_is_rgmii(phydev)) { |
| 292 | ret = phy_write(phydev, MDIO_DEVAD_NONE, MII_DP83867_PHYCTRL, |
Michal Simek | f645915 | 2015-10-19 10:43:30 +0200 | [diff] [blame] | 293 | (DP83867_MDI_CROSSOVER_AUTO << DP83867_MDI_CROSSOVER) | |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 294 | (dp83867->fifo_depth << DP83867_PHYCR_FIFO_DEPTH_SHIFT)); |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 295 | if (ret) |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 296 | goto err_out; |
Janine Hagemann | b3dd2ed | 2018-08-28 08:25:38 +0200 | [diff] [blame^] | 297 | |
| 298 | /* The code below checks if "port mirroring" N/A MODE4 has been |
| 299 | * enabled during power on bootstrap. |
| 300 | * |
| 301 | * Such N/A mode enabled by mistake can put PHY IC in some |
| 302 | * internal testing mode and disable RGMII transmission. |
| 303 | * |
| 304 | * In this particular case one needs to check STRAP_STS1 |
| 305 | * register's bit 11 (marked as RESERVED). |
| 306 | */ |
| 307 | |
| 308 | bs = phy_read_mmd_indirect(phydev, DP83867_STRAP_STS1, |
| 309 | DP83867_DEVADDR, phydev->addr); |
| 310 | val = phy_read(phydev, MDIO_DEVAD_NONE, MII_DP83867_PHYCTRL); |
| 311 | if (bs & DP83867_STRAP_STS1_RESERVED) { |
| 312 | val &= ~DP83867_PHYCR_RESERVED_MASK; |
| 313 | phy_write(phydev, MDIO_DEVAD_NONE, MII_DP83867_PHYCTRL, |
| 314 | val); |
| 315 | } |
| 316 | |
Dan Murphy | 4f4e962 | 2016-05-02 15:46:02 -0500 | [diff] [blame] | 317 | } else if (phy_interface_is_sgmii(phydev)) { |
Siva Durga Prasad Paladugu | 02c7be6 | 2016-03-25 12:53:43 +0530 | [diff] [blame] | 318 | phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, |
| 319 | (BMCR_ANENABLE | BMCR_FULLDPLX | BMCR_SPEED1000)); |
| 320 | |
| 321 | cfg2 = phy_read(phydev, phydev->addr, MII_DP83867_CFG2); |
| 322 | cfg2 &= MII_DP83867_CFG2_MASK; |
| 323 | cfg2 |= (MII_DP83867_CFG2_SPEEDOPT_10EN | |
| 324 | MII_DP83867_CFG2_SGMII_AUTONEGEN | |
| 325 | MII_DP83867_CFG2_SPEEDOPT_ENH | |
| 326 | MII_DP83867_CFG2_SPEEDOPT_CNT | |
| 327 | MII_DP83867_CFG2_SPEEDOPT_INTLOW); |
| 328 | phy_write(phydev, MDIO_DEVAD_NONE, MII_DP83867_CFG2, cfg2); |
| 329 | |
| 330 | phy_write_mmd_indirect(phydev, DP83867_RGMIICTL, |
| 331 | DP83867_DEVADDR, phydev->addr, 0x0); |
| 332 | |
| 333 | phy_write(phydev, MDIO_DEVAD_NONE, MII_DP83867_PHYCTRL, |
| 334 | DP83867_PHYCTRL_SGMIIEN | |
| 335 | (DP83867_MDI_CROSSOVER_MDIX << |
| 336 | DP83867_MDI_CROSSOVER) | |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 337 | (dp83867->fifo_depth << DP83867_PHYCTRL_RXFIFO_SHIFT) | |
| 338 | (dp83867->fifo_depth << DP83867_PHYCTRL_TXFIFO_SHIFT)); |
Siva Durga Prasad Paladugu | 02c7be6 | 2016-03-25 12:53:43 +0530 | [diff] [blame] | 339 | phy_write(phydev, MDIO_DEVAD_NONE, MII_DP83867_BISCR, 0x0); |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 340 | } |
| 341 | |
Phil Edworthy | c611980 | 2016-12-09 10:46:02 +0000 | [diff] [blame] | 342 | if (phy_interface_is_rgmii(phydev)) { |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 343 | val = phy_read_mmd_indirect(phydev, DP83867_RGMIICTL, |
| 344 | DP83867_DEVADDR, phydev->addr); |
| 345 | |
| 346 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) |
| 347 | val |= (DP83867_RGMII_TX_CLK_DELAY_EN | |
| 348 | DP83867_RGMII_RX_CLK_DELAY_EN); |
| 349 | |
| 350 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) |
| 351 | val |= DP83867_RGMII_TX_CLK_DELAY_EN; |
| 352 | |
| 353 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) |
| 354 | val |= DP83867_RGMII_RX_CLK_DELAY_EN; |
| 355 | |
| 356 | phy_write_mmd_indirect(phydev, DP83867_RGMIICTL, |
| 357 | DP83867_DEVADDR, phydev->addr, val); |
| 358 | |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 359 | delay = (dp83867->rx_id_delay | |
| 360 | (dp83867->tx_id_delay << DP83867_RGMII_TX_CLK_DELAY_SHIFT)); |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 361 | |
| 362 | phy_write_mmd_indirect(phydev, DP83867_RGMIIDCTL, |
| 363 | DP83867_DEVADDR, phydev->addr, delay); |
Mugunthan V N | 5b6b18e | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 364 | |
| 365 | if (dp83867->io_impedance >= 0) { |
| 366 | val = phy_read_mmd_indirect(phydev, |
| 367 | DP83867_IO_MUX_CFG, |
| 368 | DP83867_DEVADDR, |
| 369 | phydev->addr); |
| 370 | val &= ~DP83867_IO_MUX_CFG_IO_IMPEDANCE_CTRL; |
| 371 | val |= dp83867->io_impedance & |
| 372 | DP83867_IO_MUX_CFG_IO_IMPEDANCE_CTRL; |
| 373 | phy_write_mmd_indirect(phydev, DP83867_IO_MUX_CFG, |
| 374 | DP83867_DEVADDR, phydev->addr, |
| 375 | val); |
| 376 | } |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 377 | } |
| 378 | |
Janine Hagemann | ed51bfc | 2018-08-28 08:25:37 +0200 | [diff] [blame] | 379 | if (dp83867->port_mirroring != DP83867_PORT_MIRRORING_KEEP) |
| 380 | dp83867_config_port_mirroring(phydev); |
| 381 | |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 382 | genphy_config_aneg(phydev); |
| 383 | return 0; |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 384 | |
| 385 | err_out: |
| 386 | kfree(dp83867); |
| 387 | return ret; |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | static struct phy_driver DP83867_driver = { |
| 391 | .name = "TI DP83867", |
| 392 | .uid = 0x2000a231, |
| 393 | .mask = 0xfffffff0, |
| 394 | .features = PHY_GBIT_FEATURES, |
| 395 | .config = &dp83867_config, |
| 396 | .startup = &genphy_startup, |
| 397 | .shutdown = &genphy_shutdown, |
| 398 | }; |
| 399 | |
| 400 | int phy_ti_init(void) |
| 401 | { |
| 402 | phy_register(&DP83867_driver); |
| 403 | return 0; |
| 404 | } |