Dan Murphy | 2a10154 | 2015-06-02 09:34:37 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Driver for the Texas Instruments DP83867 PHY |
| 3 | * |
| 4 | * Copyright (C) 2015 Texas Instruments Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | */ |
| 15 | |
| 16 | #include <linux/ethtool.h> |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/mii.h> |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/of.h> |
| 21 | #include <linux/phy.h> |
| 22 | |
| 23 | #include <dt-bindings/net/ti-dp83867.h> |
| 24 | |
| 25 | #define DP83867_PHY_ID 0x2000a231 |
| 26 | #define DP83867_DEVADDR 0x1f |
| 27 | |
| 28 | #define MII_DP83867_PHYCTRL 0x10 |
| 29 | #define MII_DP83867_MICR 0x12 |
| 30 | #define MII_DP83867_ISR 0x13 |
| 31 | #define DP83867_CTRL 0x1f |
Grygorii Strashko | 5ca7d1c | 2017-01-05 14:48:07 -0600 | [diff] [blame] | 32 | #define DP83867_CFG3 0x1e |
Dan Murphy | 2a10154 | 2015-06-02 09:34:37 -0500 | [diff] [blame] | 33 | |
| 34 | /* Extended Registers */ |
Lukasz Majewski | fc6d39c | 2017-02-07 06:20:23 +0100 | [diff] [blame] | 35 | #define DP83867_CFG4 0x0031 |
Dan Murphy | 2a10154 | 2015-06-02 09:34:37 -0500 | [diff] [blame] | 36 | #define DP83867_RGMIICTL 0x0032 |
Lukasz Majewski | ac6e058 | 2017-02-07 06:20:24 +0100 | [diff] [blame] | 37 | #define DP83867_STRAP_STS1 0x006E |
Dan Murphy | 2a10154 | 2015-06-02 09:34:37 -0500 | [diff] [blame] | 38 | #define DP83867_RGMIIDCTL 0x0086 |
Mugunthan V N | ed838fe | 2016-10-18 16:50:18 +0530 | [diff] [blame] | 39 | #define DP83867_IO_MUX_CFG 0x0170 |
Dan Murphy | 2a10154 | 2015-06-02 09:34:37 -0500 | [diff] [blame] | 40 | |
| 41 | #define DP83867_SW_RESET BIT(15) |
| 42 | #define DP83867_SW_RESTART BIT(14) |
| 43 | |
| 44 | /* MICR Interrupt bits */ |
| 45 | #define MII_DP83867_MICR_AN_ERR_INT_EN BIT(15) |
| 46 | #define MII_DP83867_MICR_SPEED_CHNG_INT_EN BIT(14) |
| 47 | #define MII_DP83867_MICR_DUP_MODE_CHNG_INT_EN BIT(13) |
| 48 | #define MII_DP83867_MICR_PAGE_RXD_INT_EN BIT(12) |
| 49 | #define MII_DP83867_MICR_AUTONEG_COMP_INT_EN BIT(11) |
| 50 | #define MII_DP83867_MICR_LINK_STS_CHNG_INT_EN BIT(10) |
| 51 | #define MII_DP83867_MICR_FALSE_CARRIER_INT_EN BIT(8) |
| 52 | #define MII_DP83867_MICR_SLEEP_MODE_CHNG_INT_EN BIT(4) |
| 53 | #define MII_DP83867_MICR_WOL_INT_EN BIT(3) |
| 54 | #define MII_DP83867_MICR_XGMII_ERR_INT_EN BIT(2) |
| 55 | #define MII_DP83867_MICR_POL_CHNG_INT_EN BIT(1) |
| 56 | #define MII_DP83867_MICR_JABBER_INT_EN BIT(0) |
| 57 | |
| 58 | /* RGMIICTL bits */ |
| 59 | #define DP83867_RGMII_TX_CLK_DELAY_EN BIT(1) |
| 60 | #define DP83867_RGMII_RX_CLK_DELAY_EN BIT(0) |
| 61 | |
Lukasz Majewski | ac6e058 | 2017-02-07 06:20:24 +0100 | [diff] [blame] | 62 | /* STRAP_STS1 bits */ |
| 63 | #define DP83867_STRAP_STS1_RESERVED BIT(11) |
| 64 | |
Dan Murphy | 2a10154 | 2015-06-02 09:34:37 -0500 | [diff] [blame] | 65 | /* PHY CTRL bits */ |
| 66 | #define DP83867_PHYCR_FIFO_DEPTH_SHIFT 14 |
Stefan Hauser | b291c41 | 2016-07-01 22:35:03 +0200 | [diff] [blame] | 67 | #define DP83867_PHYCR_FIFO_DEPTH_MASK (3 << 14) |
Lukasz Majewski | ac6e058 | 2017-02-07 06:20:24 +0100 | [diff] [blame] | 68 | #define DP83867_PHYCR_RESERVED_MASK BIT(11) |
Dan Murphy | 2a10154 | 2015-06-02 09:34:37 -0500 | [diff] [blame] | 69 | |
| 70 | /* RGMIIDCTL bits */ |
| 71 | #define DP83867_RGMII_TX_CLK_DELAY_SHIFT 4 |
| 72 | |
Mugunthan V N | ed838fe | 2016-10-18 16:50:18 +0530 | [diff] [blame] | 73 | /* IO_MUX_CFG bits */ |
| 74 | #define DP83867_IO_MUX_CFG_IO_IMPEDANCE_CTRL 0x1f |
| 75 | |
| 76 | #define DP83867_IO_MUX_CFG_IO_IMPEDANCE_MAX 0x0 |
| 77 | #define DP83867_IO_MUX_CFG_IO_IMPEDANCE_MIN 0x1f |
Wadim Egorov | 9708fb6 | 2018-02-14 17:07:11 +0100 | [diff] [blame^] | 78 | #define DP83867_IO_MUX_CFG_CLK_O_SEL_MASK (0x1f << 8) |
| 79 | #define DP83867_IO_MUX_CFG_CLK_O_SEL_SHIFT 8 |
Mugunthan V N | ed838fe | 2016-10-18 16:50:18 +0530 | [diff] [blame] | 80 | |
Lukasz Majewski | fc6d39c | 2017-02-07 06:20:23 +0100 | [diff] [blame] | 81 | /* CFG4 bits */ |
| 82 | #define DP83867_CFG4_PORT_MIRROR_EN BIT(0) |
| 83 | |
| 84 | enum { |
| 85 | DP83867_PORT_MIRROING_KEEP, |
| 86 | DP83867_PORT_MIRROING_EN, |
| 87 | DP83867_PORT_MIRROING_DIS, |
| 88 | }; |
| 89 | |
Dan Murphy | 2a10154 | 2015-06-02 09:34:37 -0500 | [diff] [blame] | 90 | struct dp83867_private { |
| 91 | int rx_id_delay; |
| 92 | int tx_id_delay; |
| 93 | int fifo_depth; |
Mugunthan V N | ed838fe | 2016-10-18 16:50:18 +0530 | [diff] [blame] | 94 | int io_impedance; |
Lukasz Majewski | fc6d39c | 2017-02-07 06:20:23 +0100 | [diff] [blame] | 95 | int port_mirroring; |
Murali Karicheri | 3714447 | 2017-07-04 16:23:24 +0530 | [diff] [blame] | 96 | bool rxctrl_strap_quirk; |
Wadim Egorov | 9708fb6 | 2018-02-14 17:07:11 +0100 | [diff] [blame^] | 97 | int clk_output_sel; |
Dan Murphy | 2a10154 | 2015-06-02 09:34:37 -0500 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | static int dp83867_ack_interrupt(struct phy_device *phydev) |
| 101 | { |
| 102 | int err = phy_read(phydev, MII_DP83867_ISR); |
| 103 | |
| 104 | if (err < 0) |
| 105 | return err; |
| 106 | |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | static int dp83867_config_intr(struct phy_device *phydev) |
| 111 | { |
| 112 | int micr_status; |
| 113 | |
| 114 | if (phydev->interrupts == PHY_INTERRUPT_ENABLED) { |
| 115 | micr_status = phy_read(phydev, MII_DP83867_MICR); |
| 116 | if (micr_status < 0) |
| 117 | return micr_status; |
| 118 | |
| 119 | micr_status |= |
| 120 | (MII_DP83867_MICR_AN_ERR_INT_EN | |
| 121 | MII_DP83867_MICR_SPEED_CHNG_INT_EN | |
Grygorii Strashko | 5ca7d1c | 2017-01-05 14:48:07 -0600 | [diff] [blame] | 122 | MII_DP83867_MICR_AUTONEG_COMP_INT_EN | |
| 123 | MII_DP83867_MICR_LINK_STS_CHNG_INT_EN | |
Dan Murphy | 2a10154 | 2015-06-02 09:34:37 -0500 | [diff] [blame] | 124 | MII_DP83867_MICR_DUP_MODE_CHNG_INT_EN | |
| 125 | MII_DP83867_MICR_SLEEP_MODE_CHNG_INT_EN); |
| 126 | |
| 127 | return phy_write(phydev, MII_DP83867_MICR, micr_status); |
| 128 | } |
| 129 | |
| 130 | micr_status = 0x0; |
| 131 | return phy_write(phydev, MII_DP83867_MICR, micr_status); |
| 132 | } |
| 133 | |
Lukasz Majewski | fc6d39c | 2017-02-07 06:20:23 +0100 | [diff] [blame] | 134 | static int dp83867_config_port_mirroring(struct phy_device *phydev) |
| 135 | { |
| 136 | struct dp83867_private *dp83867 = |
| 137 | (struct dp83867_private *)phydev->priv; |
| 138 | u16 val; |
| 139 | |
Russell King | a6d99fc | 2017-03-21 16:36:53 +0000 | [diff] [blame] | 140 | val = phy_read_mmd(phydev, DP83867_DEVADDR, DP83867_CFG4); |
Lukasz Majewski | fc6d39c | 2017-02-07 06:20:23 +0100 | [diff] [blame] | 141 | |
| 142 | if (dp83867->port_mirroring == DP83867_PORT_MIRROING_EN) |
| 143 | val |= DP83867_CFG4_PORT_MIRROR_EN; |
| 144 | else |
| 145 | val &= ~DP83867_CFG4_PORT_MIRROR_EN; |
| 146 | |
Russell King | a6d99fc | 2017-03-21 16:36:53 +0000 | [diff] [blame] | 147 | phy_write_mmd(phydev, DP83867_DEVADDR, DP83867_CFG4, val); |
Lukasz Majewski | fc6d39c | 2017-02-07 06:20:23 +0100 | [diff] [blame] | 148 | |
| 149 | return 0; |
| 150 | } |
| 151 | |
Dan Murphy | 2a10154 | 2015-06-02 09:34:37 -0500 | [diff] [blame] | 152 | #ifdef CONFIG_OF_MDIO |
| 153 | static int dp83867_of_init(struct phy_device *phydev) |
| 154 | { |
| 155 | struct dp83867_private *dp83867 = phydev->priv; |
Andrew Lunn | e5a03bf | 2016-01-06 20:11:16 +0100 | [diff] [blame] | 156 | struct device *dev = &phydev->mdio.dev; |
Dan Murphy | 2a10154 | 2015-06-02 09:34:37 -0500 | [diff] [blame] | 157 | struct device_node *of_node = dev->of_node; |
| 158 | int ret; |
| 159 | |
Andrew Lunn | 7bf9ae0 | 2015-12-07 04:38:58 +0100 | [diff] [blame] | 160 | if (!of_node) |
Dan Murphy | 2a10154 | 2015-06-02 09:34:37 -0500 | [diff] [blame] | 161 | return -ENODEV; |
| 162 | |
Mugunthan V N | ed838fe | 2016-10-18 16:50:18 +0530 | [diff] [blame] | 163 | dp83867->io_impedance = -EINVAL; |
| 164 | |
| 165 | /* Optional configuration */ |
Wadim Egorov | 9708fb6 | 2018-02-14 17:07:11 +0100 | [diff] [blame^] | 166 | ret = of_property_read_u32(of_node, "ti,clk-output-sel", |
| 167 | &dp83867->clk_output_sel); |
| 168 | if (ret || dp83867->clk_output_sel > DP83867_CLK_O_SEL_REF_CLK) |
| 169 | /* Keep the default value if ti,clk-output-sel is not set |
| 170 | * or too high |
| 171 | */ |
| 172 | dp83867->clk_output_sel = DP83867_CLK_O_SEL_REF_CLK; |
| 173 | |
Mugunthan V N | ed838fe | 2016-10-18 16:50:18 +0530 | [diff] [blame] | 174 | if (of_property_read_bool(of_node, "ti,max-output-impedance")) |
| 175 | dp83867->io_impedance = DP83867_IO_MUX_CFG_IO_IMPEDANCE_MAX; |
| 176 | else if (of_property_read_bool(of_node, "ti,min-output-impedance")) |
| 177 | dp83867->io_impedance = DP83867_IO_MUX_CFG_IO_IMPEDANCE_MIN; |
| 178 | |
Murali Karicheri | 3714447 | 2017-07-04 16:23:24 +0530 | [diff] [blame] | 179 | dp83867->rxctrl_strap_quirk = of_property_read_bool(of_node, |
| 180 | "ti,dp83867-rxctrl-strap-quirk"); |
| 181 | |
Dan Murphy | ac7ba51 | 2015-06-08 14:30:55 -0500 | [diff] [blame] | 182 | ret = of_property_read_u32(of_node, "ti,rx-internal-delay", |
Dan Murphy | 2a10154 | 2015-06-02 09:34:37 -0500 | [diff] [blame] | 183 | &dp83867->rx_id_delay); |
Karicheri, Muralidharan | 34c55cf | 2017-01-13 09:32:34 -0500 | [diff] [blame] | 184 | if (ret && |
| 185 | (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || |
| 186 | phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID)) |
Dan Murphy | 2a10154 | 2015-06-02 09:34:37 -0500 | [diff] [blame] | 187 | return ret; |
| 188 | |
Dan Murphy | ac7ba51 | 2015-06-08 14:30:55 -0500 | [diff] [blame] | 189 | ret = of_property_read_u32(of_node, "ti,tx-internal-delay", |
Dan Murphy | 2a10154 | 2015-06-02 09:34:37 -0500 | [diff] [blame] | 190 | &dp83867->tx_id_delay); |
Karicheri, Muralidharan | 34c55cf | 2017-01-13 09:32:34 -0500 | [diff] [blame] | 191 | if (ret && |
| 192 | (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || |
| 193 | phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)) |
Dan Murphy | 2a10154 | 2015-06-02 09:34:37 -0500 | [diff] [blame] | 194 | return ret; |
| 195 | |
Lukasz Majewski | fc6d39c | 2017-02-07 06:20:23 +0100 | [diff] [blame] | 196 | if (of_property_read_bool(of_node, "enet-phy-lane-swap")) |
| 197 | dp83867->port_mirroring = DP83867_PORT_MIRROING_EN; |
| 198 | |
| 199 | if (of_property_read_bool(of_node, "enet-phy-lane-no-swap")) |
| 200 | dp83867->port_mirroring = DP83867_PORT_MIRROING_DIS; |
| 201 | |
Wu Fengguang | 9267135 | 2015-07-24 14:16:10 +0800 | [diff] [blame] | 202 | return of_property_read_u32(of_node, "ti,fifo-depth", |
Dan Murphy | 2a10154 | 2015-06-02 09:34:37 -0500 | [diff] [blame] | 203 | &dp83867->fifo_depth); |
Dan Murphy | 2a10154 | 2015-06-02 09:34:37 -0500 | [diff] [blame] | 204 | } |
| 205 | #else |
| 206 | static int dp83867_of_init(struct phy_device *phydev) |
| 207 | { |
| 208 | return 0; |
| 209 | } |
| 210 | #endif /* CONFIG_OF_MDIO */ |
| 211 | |
| 212 | static int dp83867_config_init(struct phy_device *phydev) |
| 213 | { |
| 214 | struct dp83867_private *dp83867; |
Lukasz Majewski | ac6e058 | 2017-02-07 06:20:24 +0100 | [diff] [blame] | 215 | int ret, val, bs; |
Stefan Hauser | b291c41 | 2016-07-01 22:35:03 +0200 | [diff] [blame] | 216 | u16 delay; |
Dan Murphy | 2a10154 | 2015-06-02 09:34:37 -0500 | [diff] [blame] | 217 | |
| 218 | if (!phydev->priv) { |
Andrew Lunn | e5a03bf | 2016-01-06 20:11:16 +0100 | [diff] [blame] | 219 | dp83867 = devm_kzalloc(&phydev->mdio.dev, sizeof(*dp83867), |
Dan Murphy | 2a10154 | 2015-06-02 09:34:37 -0500 | [diff] [blame] | 220 | GFP_KERNEL); |
| 221 | if (!dp83867) |
| 222 | return -ENOMEM; |
| 223 | |
| 224 | phydev->priv = dp83867; |
| 225 | ret = dp83867_of_init(phydev); |
| 226 | if (ret) |
| 227 | return ret; |
| 228 | } else { |
| 229 | dp83867 = (struct dp83867_private *)phydev->priv; |
| 230 | } |
| 231 | |
Murali Karicheri | 3714447 | 2017-07-04 16:23:24 +0530 | [diff] [blame] | 232 | /* RX_DV/RX_CTRL strapped in mode 1 or mode 2 workaround */ |
| 233 | if (dp83867->rxctrl_strap_quirk) { |
| 234 | val = phy_read_mmd(phydev, DP83867_DEVADDR, DP83867_CFG4); |
| 235 | val &= ~BIT(7); |
| 236 | phy_write_mmd(phydev, DP83867_DEVADDR, DP83867_CFG4, val); |
| 237 | } |
| 238 | |
Dan Murphy | 2a10154 | 2015-06-02 09:34:37 -0500 | [diff] [blame] | 239 | if (phy_interface_is_rgmii(phydev)) { |
Stefan Hauser | b291c41 | 2016-07-01 22:35:03 +0200 | [diff] [blame] | 240 | val = phy_read(phydev, MII_DP83867_PHYCTRL); |
| 241 | if (val < 0) |
| 242 | return val; |
| 243 | val &= ~DP83867_PHYCR_FIFO_DEPTH_MASK; |
| 244 | val |= (dp83867->fifo_depth << DP83867_PHYCR_FIFO_DEPTH_SHIFT); |
Lukasz Majewski | ac6e058 | 2017-02-07 06:20:24 +0100 | [diff] [blame] | 245 | |
| 246 | /* The code below checks if "port mirroring" N/A MODE4 has been |
| 247 | * enabled during power on bootstrap. |
| 248 | * |
| 249 | * Such N/A mode enabled by mistake can put PHY IC in some |
| 250 | * internal testing mode and disable RGMII transmission. |
| 251 | * |
| 252 | * In this particular case one needs to check STRAP_STS1 |
| 253 | * register's bit 11 (marked as RESERVED). |
| 254 | */ |
| 255 | |
Russell King | a6d99fc | 2017-03-21 16:36:53 +0000 | [diff] [blame] | 256 | bs = phy_read_mmd(phydev, DP83867_DEVADDR, DP83867_STRAP_STS1); |
Lukasz Majewski | ac6e058 | 2017-02-07 06:20:24 +0100 | [diff] [blame] | 257 | if (bs & DP83867_STRAP_STS1_RESERVED) |
| 258 | val &= ~DP83867_PHYCR_RESERVED_MASK; |
| 259 | |
Stefan Hauser | b291c41 | 2016-07-01 22:35:03 +0200 | [diff] [blame] | 260 | ret = phy_write(phydev, MII_DP83867_PHYCTRL, val); |
Dan Murphy | 2a10154 | 2015-06-02 09:34:37 -0500 | [diff] [blame] | 261 | if (ret) |
| 262 | return ret; |
| 263 | } |
| 264 | |
Dan Murphy | a46fa26 | 2015-07-21 12:06:45 -0500 | [diff] [blame] | 265 | if ((phydev->interface >= PHY_INTERFACE_MODE_RGMII_ID) && |
Dan Murphy | 2a10154 | 2015-06-02 09:34:37 -0500 | [diff] [blame] | 266 | (phydev->interface <= PHY_INTERFACE_MODE_RGMII_RXID)) { |
Russell King | a6d99fc | 2017-03-21 16:36:53 +0000 | [diff] [blame] | 267 | val = phy_read_mmd(phydev, DP83867_DEVADDR, DP83867_RGMIICTL); |
Dan Murphy | 2a10154 | 2015-06-02 09:34:37 -0500 | [diff] [blame] | 268 | |
| 269 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) |
| 270 | val |= (DP83867_RGMII_TX_CLK_DELAY_EN | DP83867_RGMII_RX_CLK_DELAY_EN); |
| 271 | |
| 272 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) |
| 273 | val |= DP83867_RGMII_TX_CLK_DELAY_EN; |
| 274 | |
| 275 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) |
| 276 | val |= DP83867_RGMII_RX_CLK_DELAY_EN; |
| 277 | |
Russell King | a6d99fc | 2017-03-21 16:36:53 +0000 | [diff] [blame] | 278 | phy_write_mmd(phydev, DP83867_DEVADDR, DP83867_RGMIICTL, val); |
Dan Murphy | 2a10154 | 2015-06-02 09:34:37 -0500 | [diff] [blame] | 279 | |
| 280 | delay = (dp83867->rx_id_delay | |
| 281 | (dp83867->tx_id_delay << DP83867_RGMII_TX_CLK_DELAY_SHIFT)); |
| 282 | |
Russell King | a6d99fc | 2017-03-21 16:36:53 +0000 | [diff] [blame] | 283 | phy_write_mmd(phydev, DP83867_DEVADDR, DP83867_RGMIIDCTL, |
| 284 | delay); |
Mugunthan V N | ed838fe | 2016-10-18 16:50:18 +0530 | [diff] [blame] | 285 | |
| 286 | if (dp83867->io_impedance >= 0) { |
Russell King | a6d99fc | 2017-03-21 16:36:53 +0000 | [diff] [blame] | 287 | val = phy_read_mmd(phydev, DP83867_DEVADDR, |
| 288 | DP83867_IO_MUX_CFG); |
Mugunthan V N | ed838fe | 2016-10-18 16:50:18 +0530 | [diff] [blame] | 289 | |
| 290 | val &= ~DP83867_IO_MUX_CFG_IO_IMPEDANCE_CTRL; |
| 291 | val |= dp83867->io_impedance & |
| 292 | DP83867_IO_MUX_CFG_IO_IMPEDANCE_CTRL; |
| 293 | |
Russell King | a6d99fc | 2017-03-21 16:36:53 +0000 | [diff] [blame] | 294 | phy_write_mmd(phydev, DP83867_DEVADDR, |
| 295 | DP83867_IO_MUX_CFG, val); |
Mugunthan V N | ed838fe | 2016-10-18 16:50:18 +0530 | [diff] [blame] | 296 | } |
Dan Murphy | 2a10154 | 2015-06-02 09:34:37 -0500 | [diff] [blame] | 297 | } |
| 298 | |
Grygorii Strashko | 5ca7d1c | 2017-01-05 14:48:07 -0600 | [diff] [blame] | 299 | /* Enable Interrupt output INT_OE in CFG3 register */ |
| 300 | if (phy_interrupt_is_valid(phydev)) { |
| 301 | val = phy_read(phydev, DP83867_CFG3); |
| 302 | val |= BIT(7); |
| 303 | phy_write(phydev, DP83867_CFG3, val); |
| 304 | } |
| 305 | |
Lukasz Majewski | fc6d39c | 2017-02-07 06:20:23 +0100 | [diff] [blame] | 306 | if (dp83867->port_mirroring != DP83867_PORT_MIRROING_KEEP) |
| 307 | dp83867_config_port_mirroring(phydev); |
| 308 | |
Wadim Egorov | 9708fb6 | 2018-02-14 17:07:11 +0100 | [diff] [blame^] | 309 | /* Clock output selection if muxing property is set */ |
| 310 | if (dp83867->clk_output_sel != DP83867_CLK_O_SEL_REF_CLK) { |
| 311 | val = phy_read_mmd(phydev, DP83867_DEVADDR, DP83867_IO_MUX_CFG); |
| 312 | val &= ~DP83867_IO_MUX_CFG_CLK_O_SEL_MASK; |
| 313 | val |= (dp83867->clk_output_sel << DP83867_IO_MUX_CFG_CLK_O_SEL_SHIFT); |
| 314 | phy_write_mmd(phydev, DP83867_DEVADDR, DP83867_IO_MUX_CFG, val); |
| 315 | } |
| 316 | |
Dan Murphy | 2a10154 | 2015-06-02 09:34:37 -0500 | [diff] [blame] | 317 | return 0; |
| 318 | } |
| 319 | |
| 320 | static int dp83867_phy_reset(struct phy_device *phydev) |
| 321 | { |
| 322 | int err; |
| 323 | |
| 324 | err = phy_write(phydev, DP83867_CTRL, DP83867_SW_RESET); |
| 325 | if (err < 0) |
| 326 | return err; |
| 327 | |
| 328 | return dp83867_config_init(phydev); |
| 329 | } |
| 330 | |
| 331 | static struct phy_driver dp83867_driver[] = { |
| 332 | { |
| 333 | .phy_id = DP83867_PHY_ID, |
| 334 | .phy_id_mask = 0xfffffff0, |
| 335 | .name = "TI DP83867", |
| 336 | .features = PHY_GBIT_FEATURES, |
| 337 | .flags = PHY_HAS_INTERRUPT, |
| 338 | |
| 339 | .config_init = dp83867_config_init, |
| 340 | .soft_reset = dp83867_phy_reset, |
| 341 | |
| 342 | /* IRQ related */ |
| 343 | .ack_interrupt = dp83867_ack_interrupt, |
| 344 | .config_intr = dp83867_config_intr, |
| 345 | |
Dan Murphy | 2a10154 | 2015-06-02 09:34:37 -0500 | [diff] [blame] | 346 | .suspend = genphy_suspend, |
| 347 | .resume = genphy_resume, |
Dan Murphy | 2a10154 | 2015-06-02 09:34:37 -0500 | [diff] [blame] | 348 | }, |
| 349 | }; |
| 350 | module_phy_driver(dp83867_driver); |
| 351 | |
| 352 | static struct mdio_device_id __maybe_unused dp83867_tbl[] = { |
| 353 | { DP83867_PHY_ID, 0xfffffff0 }, |
| 354 | { } |
| 355 | }; |
| 356 | |
| 357 | MODULE_DEVICE_TABLE(mdio, dp83867_tbl); |
| 358 | |
| 359 | MODULE_DESCRIPTION("Texas Instruments DP83867 PHY driver"); |
| 360 | MODULE_AUTHOR("Dan Murphy <dmurphy@ti.com"); |
| 361 | MODULE_LICENSE("GPL"); |