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 | |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 76 | /* User setting - can be taken from DTS */ |
| 77 | #define DEFAULT_RX_ID_DELAY DP83867_RGMIIDCTL_2_25_NS |
| 78 | #define DEFAULT_TX_ID_DELAY DP83867_RGMIIDCTL_2_75_NS |
| 79 | #define DEFAULT_FIFO_DEPTH DP83867_PHYCR_FIFO_DEPTH_4_B_NIB |
| 80 | |
Mugunthan V N | 5b6b18e | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 81 | /* IO_MUX_CFG bits */ |
| 82 | #define DP83867_IO_MUX_CFG_IO_IMPEDANCE_CTRL 0x1f |
| 83 | |
| 84 | #define DP83867_IO_MUX_CFG_IO_IMPEDANCE_MAX 0x0 |
| 85 | #define DP83867_IO_MUX_CFG_IO_IMPEDANCE_MIN 0x1f |
Janine Hagemann | 1c2ba09 | 2018-08-28 08:25:39 +0200 | [diff] [blame] | 86 | #define DP83867_IO_MUX_CFG_CLK_O_SEL_SHIFT 8 |
| 87 | #define DP83867_IO_MUX_CFG_CLK_O_SEL_MASK \ |
| 88 | GENMASK(0x1f, DP83867_IO_MUX_CFG_CLK_O_SEL_SHIFT) |
Mugunthan V N | 5b6b18e | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 89 | |
Janine Hagemann | ed51bfc | 2018-08-28 08:25:37 +0200 | [diff] [blame] | 90 | /* CFG4 bits */ |
| 91 | #define DP83867_CFG4_PORT_MIRROR_EN BIT(0) |
| 92 | |
| 93 | enum { |
| 94 | DP83867_PORT_MIRRORING_KEEP, |
| 95 | DP83867_PORT_MIRRORING_EN, |
| 96 | DP83867_PORT_MIRRORING_DIS, |
| 97 | }; |
| 98 | |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 99 | struct dp83867_private { |
| 100 | int rx_id_delay; |
| 101 | int tx_id_delay; |
| 102 | int fifo_depth; |
Mugunthan V N | 5b6b18e | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 103 | int io_impedance; |
Murali Karicheri | 9b05076 | 2018-06-28 14:26:34 -0500 | [diff] [blame] | 104 | bool rxctrl_strap_quirk; |
Janine Hagemann | ed51bfc | 2018-08-28 08:25:37 +0200 | [diff] [blame] | 105 | int port_mirroring; |
Janine Hagemann | 1c2ba09 | 2018-08-28 08:25:39 +0200 | [diff] [blame] | 106 | int clk_output_sel; |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 107 | }; |
| 108 | |
Janine Hagemann | ed51bfc | 2018-08-28 08:25:37 +0200 | [diff] [blame] | 109 | static int dp83867_config_port_mirroring(struct phy_device *phydev) |
| 110 | { |
| 111 | struct dp83867_private *dp83867 = |
| 112 | (struct dp83867_private *)phydev->priv; |
| 113 | u16 val; |
| 114 | |
Carlo Caione | a8abcff | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 115 | val = phy_read_mmd(phydev, DP83867_DEVADDR, DP83867_CFG4); |
Janine Hagemann | ed51bfc | 2018-08-28 08:25:37 +0200 | [diff] [blame] | 116 | |
| 117 | if (dp83867->port_mirroring == DP83867_PORT_MIRRORING_EN) |
| 118 | val |= DP83867_CFG4_PORT_MIRROR_EN; |
| 119 | else |
| 120 | val &= ~DP83867_CFG4_PORT_MIRROR_EN; |
| 121 | |
Carlo Caione | a8abcff | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 122 | phy_write_mmd(phydev, DP83867_DEVADDR, DP83867_CFG4, val); |
Janine Hagemann | ed51bfc | 2018-08-28 08:25:37 +0200 | [diff] [blame] | 123 | |
| 124 | return 0; |
| 125 | } |
| 126 | |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 127 | #if defined(CONFIG_DM_ETH) |
| 128 | /** |
| 129 | * dp83867_data_init - Convenience function for setting PHY specific data |
| 130 | * |
| 131 | * @phydev: the phy_device struct |
| 132 | */ |
| 133 | static int dp83867_of_init(struct phy_device *phydev) |
| 134 | { |
| 135 | struct dp83867_private *dp83867 = phydev->priv; |
Grygorii Strashko | 00e2c24 | 2018-07-05 12:02:49 -0500 | [diff] [blame] | 136 | ofnode node; |
Janine Hagemann | 1c2ba09 | 2018-08-28 08:25:39 +0200 | [diff] [blame] | 137 | u16 val; |
| 138 | |
| 139 | /* Optional configuration */ |
| 140 | |
Michal Simek | 8e102a8 | 2019-03-16 12:43:17 +0100 | [diff] [blame^] | 141 | node = phy_get_ofnode(phydev); |
| 142 | if (!ofnode_valid(node)) |
| 143 | return -EINVAL; |
| 144 | |
Janine Hagemann | 1c2ba09 | 2018-08-28 08:25:39 +0200 | [diff] [blame] | 145 | /* |
| 146 | * Keep the default value if ti,clk-output-sel is not set |
| 147 | * or to high |
| 148 | */ |
| 149 | |
| 150 | dp83867->clk_output_sel = |
| 151 | ofnode_read_u32_default(node, "ti,clk-output-sel", |
| 152 | DP83867_CLK_O_SEL_REF_CLK); |
Grygorii Strashko | 00e2c24 | 2018-07-05 12:02:49 -0500 | [diff] [blame] | 153 | |
Grygorii Strashko | 9df3505 | 2018-06-28 14:26:35 -0500 | [diff] [blame] | 154 | if (ofnode_read_bool(node, "ti,max-output-impedance")) |
Mugunthan V N | 5b6b18e | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 155 | dp83867->io_impedance = DP83867_IO_MUX_CFG_IO_IMPEDANCE_MAX; |
Grygorii Strashko | 9df3505 | 2018-06-28 14:26:35 -0500 | [diff] [blame] | 156 | else if (ofnode_read_bool(node, "ti,min-output-impedance")) |
Mugunthan V N | 5b6b18e | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 157 | dp83867->io_impedance = DP83867_IO_MUX_CFG_IO_IMPEDANCE_MIN; |
| 158 | else |
| 159 | dp83867->io_impedance = -EINVAL; |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 160 | |
Grygorii Strashko | 9df3505 | 2018-06-28 14:26:35 -0500 | [diff] [blame] | 161 | if (ofnode_read_bool(node, "ti,dp83867-rxctrl-strap-quirk")) |
Murali Karicheri | 9b05076 | 2018-06-28 14:26:34 -0500 | [diff] [blame] | 162 | dp83867->rxctrl_strap_quirk = true; |
Grygorii Strashko | 9df3505 | 2018-06-28 14:26:35 -0500 | [diff] [blame] | 163 | dp83867->rx_id_delay = ofnode_read_u32_default(node, |
| 164 | "ti,rx-internal-delay", |
| 165 | -1); |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 166 | |
Grygorii Strashko | 9df3505 | 2018-06-28 14:26:35 -0500 | [diff] [blame] | 167 | dp83867->tx_id_delay = ofnode_read_u32_default(node, |
| 168 | "ti,tx-internal-delay", |
| 169 | -1); |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 170 | |
Grygorii Strashko | 9df3505 | 2018-06-28 14:26:35 -0500 | [diff] [blame] | 171 | dp83867->fifo_depth = ofnode_read_u32_default(node, "ti,fifo-depth", |
| 172 | -1); |
Janine Hagemann | ed51bfc | 2018-08-28 08:25:37 +0200 | [diff] [blame] | 173 | if (ofnode_read_bool(node, "enet-phy-lane-swap")) |
| 174 | dp83867->port_mirroring = DP83867_PORT_MIRRORING_EN; |
| 175 | |
| 176 | if (ofnode_read_bool(node, "enet-phy-lane-no-swap")) |
| 177 | dp83867->port_mirroring = DP83867_PORT_MIRRORING_DIS; |
| 178 | |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 179 | |
Janine Hagemann | 1c2ba09 | 2018-08-28 08:25:39 +0200 | [diff] [blame] | 180 | /* Clock output selection if muxing property is set */ |
| 181 | if (dp83867->clk_output_sel != DP83867_CLK_O_SEL_REF_CLK) { |
Carlo Caione | a8abcff | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 182 | val = phy_read_mmd(phydev, DP83867_DEVADDR, |
| 183 | DP83867_IO_MUX_CFG); |
Janine Hagemann | 1c2ba09 | 2018-08-28 08:25:39 +0200 | [diff] [blame] | 184 | val &= ~DP83867_IO_MUX_CFG_CLK_O_SEL_MASK; |
| 185 | val |= (dp83867->clk_output_sel << |
| 186 | DP83867_IO_MUX_CFG_CLK_O_SEL_SHIFT); |
Carlo Caione | a8abcff | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 187 | phy_write_mmd(phydev, DP83867_DEVADDR, |
| 188 | DP83867_IO_MUX_CFG, val); |
Janine Hagemann | 1c2ba09 | 2018-08-28 08:25:39 +0200 | [diff] [blame] | 189 | } |
| 190 | |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 191 | return 0; |
| 192 | } |
| 193 | #else |
| 194 | static int dp83867_of_init(struct phy_device *phydev) |
| 195 | { |
| 196 | struct dp83867_private *dp83867 = phydev->priv; |
| 197 | |
| 198 | dp83867->rx_id_delay = DEFAULT_RX_ID_DELAY; |
| 199 | dp83867->tx_id_delay = DEFAULT_TX_ID_DELAY; |
| 200 | dp83867->fifo_depth = DEFAULT_FIFO_DEPTH; |
Mugunthan V N | 5b6b18e | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 201 | dp83867->io_impedance = -EINVAL; |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 202 | |
| 203 | return 0; |
| 204 | } |
| 205 | #endif |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 206 | |
| 207 | static int dp83867_config(struct phy_device *phydev) |
| 208 | { |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 209 | struct dp83867_private *dp83867; |
Siva Durga Prasad Paladugu | 02c7be6 | 2016-03-25 12:53:43 +0530 | [diff] [blame] | 210 | unsigned int val, delay, cfg2; |
Janine Hagemann | b3dd2ed | 2018-08-28 08:25:38 +0200 | [diff] [blame] | 211 | int ret, bs; |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 212 | |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 213 | if (!phydev->priv) { |
| 214 | dp83867 = kzalloc(sizeof(*dp83867), GFP_KERNEL); |
| 215 | if (!dp83867) |
| 216 | return -ENOMEM; |
| 217 | |
| 218 | phydev->priv = dp83867; |
| 219 | ret = dp83867_of_init(phydev); |
| 220 | if (ret) |
| 221 | goto err_out; |
| 222 | } else { |
| 223 | dp83867 = (struct dp83867_private *)phydev->priv; |
| 224 | } |
| 225 | |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 226 | /* Restart the PHY. */ |
| 227 | val = phy_read(phydev, MDIO_DEVAD_NONE, DP83867_CTRL); |
| 228 | phy_write(phydev, MDIO_DEVAD_NONE, DP83867_CTRL, |
| 229 | val | DP83867_SW_RESTART); |
| 230 | |
Murali Karicheri | 9b05076 | 2018-06-28 14:26:34 -0500 | [diff] [blame] | 231 | /* Mode 1 or 2 workaround */ |
| 232 | if (dp83867->rxctrl_strap_quirk) { |
Carlo Caione | a8abcff | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 233 | val = phy_read_mmd(phydev, DP83867_DEVADDR, |
| 234 | DP83867_CFG4); |
Murali Karicheri | 9b05076 | 2018-06-28 14:26:34 -0500 | [diff] [blame] | 235 | val &= ~BIT(7); |
Carlo Caione | a8abcff | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 236 | phy_write_mmd(phydev, DP83867_DEVADDR, |
| 237 | DP83867_CFG4, val); |
Murali Karicheri | 9b05076 | 2018-06-28 14:26:34 -0500 | [diff] [blame] | 238 | } |
| 239 | |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 240 | if (phy_interface_is_rgmii(phydev)) { |
| 241 | ret = phy_write(phydev, MDIO_DEVAD_NONE, MII_DP83867_PHYCTRL, |
Michal Simek | f645915 | 2015-10-19 10:43:30 +0200 | [diff] [blame] | 242 | (DP83867_MDI_CROSSOVER_AUTO << DP83867_MDI_CROSSOVER) | |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 243 | (dp83867->fifo_depth << DP83867_PHYCR_FIFO_DEPTH_SHIFT)); |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 244 | if (ret) |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 245 | goto err_out; |
Janine Hagemann | b3dd2ed | 2018-08-28 08:25:38 +0200 | [diff] [blame] | 246 | |
| 247 | /* The code below checks if "port mirroring" N/A MODE4 has been |
| 248 | * enabled during power on bootstrap. |
| 249 | * |
| 250 | * Such N/A mode enabled by mistake can put PHY IC in some |
| 251 | * internal testing mode and disable RGMII transmission. |
| 252 | * |
| 253 | * In this particular case one needs to check STRAP_STS1 |
| 254 | * register's bit 11 (marked as RESERVED). |
| 255 | */ |
| 256 | |
Carlo Caione | a8abcff | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 257 | bs = phy_read_mmd(phydev, DP83867_DEVADDR, |
| 258 | DP83867_STRAP_STS1); |
Janine Hagemann | b3dd2ed | 2018-08-28 08:25:38 +0200 | [diff] [blame] | 259 | val = phy_read(phydev, MDIO_DEVAD_NONE, MII_DP83867_PHYCTRL); |
| 260 | if (bs & DP83867_STRAP_STS1_RESERVED) { |
| 261 | val &= ~DP83867_PHYCR_RESERVED_MASK; |
| 262 | phy_write(phydev, MDIO_DEVAD_NONE, MII_DP83867_PHYCTRL, |
| 263 | val); |
| 264 | } |
| 265 | |
Dan Murphy | 4f4e962 | 2016-05-02 15:46:02 -0500 | [diff] [blame] | 266 | } else if (phy_interface_is_sgmii(phydev)) { |
Siva Durga Prasad Paladugu | 02c7be6 | 2016-03-25 12:53:43 +0530 | [diff] [blame] | 267 | phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, |
| 268 | (BMCR_ANENABLE | BMCR_FULLDPLX | BMCR_SPEED1000)); |
| 269 | |
| 270 | cfg2 = phy_read(phydev, phydev->addr, MII_DP83867_CFG2); |
| 271 | cfg2 &= MII_DP83867_CFG2_MASK; |
| 272 | cfg2 |= (MII_DP83867_CFG2_SPEEDOPT_10EN | |
| 273 | MII_DP83867_CFG2_SGMII_AUTONEGEN | |
| 274 | MII_DP83867_CFG2_SPEEDOPT_ENH | |
| 275 | MII_DP83867_CFG2_SPEEDOPT_CNT | |
| 276 | MII_DP83867_CFG2_SPEEDOPT_INTLOW); |
| 277 | phy_write(phydev, MDIO_DEVAD_NONE, MII_DP83867_CFG2, cfg2); |
| 278 | |
Carlo Caione | a8abcff | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 279 | phy_write_mmd(phydev, DP83867_DEVADDR, |
| 280 | DP83867_RGMIICTL, 0x0); |
Siva Durga Prasad Paladugu | 02c7be6 | 2016-03-25 12:53:43 +0530 | [diff] [blame] | 281 | |
| 282 | phy_write(phydev, MDIO_DEVAD_NONE, MII_DP83867_PHYCTRL, |
| 283 | DP83867_PHYCTRL_SGMIIEN | |
| 284 | (DP83867_MDI_CROSSOVER_MDIX << |
| 285 | DP83867_MDI_CROSSOVER) | |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 286 | (dp83867->fifo_depth << DP83867_PHYCTRL_RXFIFO_SHIFT) | |
| 287 | (dp83867->fifo_depth << DP83867_PHYCTRL_TXFIFO_SHIFT)); |
Siva Durga Prasad Paladugu | 02c7be6 | 2016-03-25 12:53:43 +0530 | [diff] [blame] | 288 | phy_write(phydev, MDIO_DEVAD_NONE, MII_DP83867_BISCR, 0x0); |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 289 | } |
| 290 | |
Phil Edworthy | c611980 | 2016-12-09 10:46:02 +0000 | [diff] [blame] | 291 | if (phy_interface_is_rgmii(phydev)) { |
Carlo Caione | a8abcff | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 292 | val = phy_read_mmd(phydev, DP83867_DEVADDR, |
| 293 | DP83867_RGMIICTL); |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 294 | |
| 295 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) |
| 296 | val |= (DP83867_RGMII_TX_CLK_DELAY_EN | |
| 297 | DP83867_RGMII_RX_CLK_DELAY_EN); |
| 298 | |
| 299 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) |
| 300 | val |= DP83867_RGMII_TX_CLK_DELAY_EN; |
| 301 | |
| 302 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) |
| 303 | val |= DP83867_RGMII_RX_CLK_DELAY_EN; |
| 304 | |
Carlo Caione | a8abcff | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 305 | phy_write_mmd(phydev, DP83867_DEVADDR, |
| 306 | DP83867_RGMIICTL, val); |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 307 | |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 308 | delay = (dp83867->rx_id_delay | |
| 309 | (dp83867->tx_id_delay << DP83867_RGMII_TX_CLK_DELAY_SHIFT)); |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 310 | |
Carlo Caione | a8abcff | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 311 | phy_write_mmd(phydev, DP83867_DEVADDR, |
| 312 | DP83867_RGMIIDCTL, delay); |
Mugunthan V N | 5b6b18e | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 313 | |
| 314 | if (dp83867->io_impedance >= 0) { |
Carlo Caione | a8abcff | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 315 | val = phy_read_mmd(phydev, |
| 316 | DP83867_DEVADDR, |
| 317 | DP83867_IO_MUX_CFG); |
Mugunthan V N | 5b6b18e | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 318 | val &= ~DP83867_IO_MUX_CFG_IO_IMPEDANCE_CTRL; |
| 319 | val |= dp83867->io_impedance & |
| 320 | DP83867_IO_MUX_CFG_IO_IMPEDANCE_CTRL; |
Carlo Caione | a8abcff | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 321 | phy_write_mmd(phydev, DP83867_DEVADDR, |
| 322 | DP83867_IO_MUX_CFG, val); |
Mugunthan V N | 5b6b18e | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 323 | } |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 324 | } |
| 325 | |
Janine Hagemann | ed51bfc | 2018-08-28 08:25:37 +0200 | [diff] [blame] | 326 | if (dp83867->port_mirroring != DP83867_PORT_MIRRORING_KEEP) |
| 327 | dp83867_config_port_mirroring(phydev); |
| 328 | |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 329 | genphy_config_aneg(phydev); |
| 330 | return 0; |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 331 | |
| 332 | err_out: |
| 333 | kfree(dp83867); |
| 334 | return ret; |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | static struct phy_driver DP83867_driver = { |
| 338 | .name = "TI DP83867", |
| 339 | .uid = 0x2000a231, |
| 340 | .mask = 0xfffffff0, |
| 341 | .features = PHY_GBIT_FEATURES, |
| 342 | .config = &dp83867_config, |
| 343 | .startup = &genphy_startup, |
| 344 | .shutdown = &genphy_shutdown, |
| 345 | }; |
| 346 | |
| 347 | int phy_ti_init(void) |
| 348 | { |
| 349 | phy_register(&DP83867_driver); |
| 350 | return 0; |
| 351 | } |