Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Edgar E. Iglesias | 721aed7 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 2 | /* |
| 3 | * TI PHY drivers |
| 4 | * |
Edgar E. Iglesias | 721aed7 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 5 | */ |
| 6 | #include <common.h> |
| 7 | #include <phy.h> |
Dan Murphy | 085445c | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 8 | #include <linux/compat.h> |
| 9 | #include <malloc.h> |
| 10 | |
Dan Murphy | 085445c | 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 | 721aed7 | 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 | 85b949f | 2016-03-25 12:53:43 +0530 | [diff] [blame] | 20 | #define MII_DP83867_CFG2 0x14 |
| 21 | #define MII_DP83867_BISCR 0x16 |
Edgar E. Iglesias | 721aed7 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 22 | #define DP83867_CTRL 0x1f |
| 23 | |
| 24 | /* Extended Registers */ |
Murali Karicheri | 63d3192 | 2018-06-28 14:26:34 -0500 | [diff] [blame] | 25 | #define DP83867_CFG4 0x0031 |
Edgar E. Iglesias | 721aed7 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 26 | #define DP83867_RGMIICTL 0x0032 |
Janine Hagemann | be71a74 | 2018-08-28 08:25:38 +0200 | [diff] [blame] | 27 | #define DP83867_STRAP_STS1 0x006E |
Edgar E. Iglesias | 721aed7 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 28 | #define DP83867_RGMIIDCTL 0x0086 |
Mugunthan V N | 6463170 | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 29 | #define DP83867_IO_MUX_CFG 0x0170 |
Edgar E. Iglesias | 721aed7 | 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 | be71a74 | 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 | 721aed7 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 55 | /* PHY CTRL bits */ |
| 56 | #define DP83867_PHYCR_FIFO_DEPTH_SHIFT 14 |
Janine Hagemann | be71a74 | 2018-08-28 08:25:38 +0200 | [diff] [blame] | 57 | #define DP83867_PHYCR_RESERVED_MASK BIT(11) |
Michal Simek | 0179063 | 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 | 85b949f | 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 | 721aed7 | 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 | 85b949f | 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 | 085445c | 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 | 6463170 | 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 | 0f347a0 | 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 | 6463170 | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 89 | |
Janine Hagemann | fba725f | 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 | 085445c | 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 | 6463170 | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 103 | int io_impedance; |
Murali Karicheri | 63d3192 | 2018-06-28 14:26:34 -0500 | [diff] [blame] | 104 | bool rxctrl_strap_quirk; |
Janine Hagemann | fba725f | 2018-08-28 08:25:37 +0200 | [diff] [blame] | 105 | int port_mirroring; |
Trent Piepho | 2529dea | 2019-05-10 17:49:08 +0000 | [diff] [blame] | 106 | unsigned int clk_output_sel; |
Dan Murphy | 085445c | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 107 | }; |
| 108 | |
Janine Hagemann | fba725f | 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 | 4c29dc1 | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 115 | val = phy_read_mmd(phydev, DP83867_DEVADDR, DP83867_CFG4); |
Janine Hagemann | fba725f | 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 | 4c29dc1 | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 122 | phy_write_mmd(phydev, DP83867_DEVADDR, DP83867_CFG4, val); |
Janine Hagemann | fba725f | 2018-08-28 08:25:37 +0200 | [diff] [blame] | 123 | |
| 124 | return 0; |
| 125 | } |
| 126 | |
Dan Murphy | 085445c | 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 | b8d7ec7 | 2018-07-05 12:02:49 -0500 | [diff] [blame] | 136 | ofnode node; |
Janine Hagemann | 0f347a0 | 2018-08-28 08:25:39 +0200 | [diff] [blame] | 137 | u16 val; |
| 138 | |
Michal Simek | 6845b36 | 2019-03-16 12:43:17 +0100 | [diff] [blame] | 139 | node = phy_get_ofnode(phydev); |
| 140 | if (!ofnode_valid(node)) |
| 141 | return -EINVAL; |
| 142 | |
Trent Piepho | 2529dea | 2019-05-10 17:49:08 +0000 | [diff] [blame] | 143 | /* Keep the default value if ti,clk-output-sel is not set */ |
Janine Hagemann | 0f347a0 | 2018-08-28 08:25:39 +0200 | [diff] [blame] | 144 | dp83867->clk_output_sel = |
| 145 | ofnode_read_u32_default(node, "ti,clk-output-sel", |
| 146 | DP83867_CLK_O_SEL_REF_CLK); |
Grygorii Strashko | b8d7ec7 | 2018-07-05 12:02:49 -0500 | [diff] [blame] | 147 | |
Grygorii Strashko | 3ab75cf | 2018-06-28 14:26:35 -0500 | [diff] [blame] | 148 | if (ofnode_read_bool(node, "ti,max-output-impedance")) |
Mugunthan V N | 6463170 | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 149 | dp83867->io_impedance = DP83867_IO_MUX_CFG_IO_IMPEDANCE_MAX; |
Grygorii Strashko | 3ab75cf | 2018-06-28 14:26:35 -0500 | [diff] [blame] | 150 | else if (ofnode_read_bool(node, "ti,min-output-impedance")) |
Mugunthan V N | 6463170 | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 151 | dp83867->io_impedance = DP83867_IO_MUX_CFG_IO_IMPEDANCE_MIN; |
| 152 | else |
| 153 | dp83867->io_impedance = -EINVAL; |
Dan Murphy | 085445c | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 154 | |
Grygorii Strashko | 3ab75cf | 2018-06-28 14:26:35 -0500 | [diff] [blame] | 155 | if (ofnode_read_bool(node, "ti,dp83867-rxctrl-strap-quirk")) |
Murali Karicheri | 63d3192 | 2018-06-28 14:26:34 -0500 | [diff] [blame] | 156 | dp83867->rxctrl_strap_quirk = true; |
Grygorii Strashko | 3ab75cf | 2018-06-28 14:26:35 -0500 | [diff] [blame] | 157 | dp83867->rx_id_delay = ofnode_read_u32_default(node, |
| 158 | "ti,rx-internal-delay", |
Trent Piepho | c2df9b4 | 2019-05-09 19:41:51 +0000 | [diff] [blame] | 159 | DEFAULT_RX_ID_DELAY); |
Dan Murphy | 085445c | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 160 | |
Grygorii Strashko | 3ab75cf | 2018-06-28 14:26:35 -0500 | [diff] [blame] | 161 | dp83867->tx_id_delay = ofnode_read_u32_default(node, |
| 162 | "ti,tx-internal-delay", |
Trent Piepho | c2df9b4 | 2019-05-09 19:41:51 +0000 | [diff] [blame] | 163 | DEFAULT_TX_ID_DELAY); |
Dan Murphy | 085445c | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 164 | |
Grygorii Strashko | 3ab75cf | 2018-06-28 14:26:35 -0500 | [diff] [blame] | 165 | dp83867->fifo_depth = ofnode_read_u32_default(node, "ti,fifo-depth", |
Trent Piepho | c2df9b4 | 2019-05-09 19:41:51 +0000 | [diff] [blame] | 166 | DEFAULT_FIFO_DEPTH); |
Janine Hagemann | fba725f | 2018-08-28 08:25:37 +0200 | [diff] [blame] | 167 | if (ofnode_read_bool(node, "enet-phy-lane-swap")) |
| 168 | dp83867->port_mirroring = DP83867_PORT_MIRRORING_EN; |
| 169 | |
| 170 | if (ofnode_read_bool(node, "enet-phy-lane-no-swap")) |
| 171 | dp83867->port_mirroring = DP83867_PORT_MIRRORING_DIS; |
| 172 | |
Dan Murphy | 085445c | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 173 | |
Janine Hagemann | 0f347a0 | 2018-08-28 08:25:39 +0200 | [diff] [blame] | 174 | /* Clock output selection if muxing property is set */ |
| 175 | if (dp83867->clk_output_sel != DP83867_CLK_O_SEL_REF_CLK) { |
Carlo Caione | 4c29dc1 | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 176 | val = phy_read_mmd(phydev, DP83867_DEVADDR, |
| 177 | DP83867_IO_MUX_CFG); |
Janine Hagemann | 0f347a0 | 2018-08-28 08:25:39 +0200 | [diff] [blame] | 178 | val &= ~DP83867_IO_MUX_CFG_CLK_O_SEL_MASK; |
| 179 | val |= (dp83867->clk_output_sel << |
| 180 | DP83867_IO_MUX_CFG_CLK_O_SEL_SHIFT); |
Carlo Caione | 4c29dc1 | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 181 | phy_write_mmd(phydev, DP83867_DEVADDR, |
| 182 | DP83867_IO_MUX_CFG, val); |
Janine Hagemann | 0f347a0 | 2018-08-28 08:25:39 +0200 | [diff] [blame] | 183 | } |
| 184 | |
Dan Murphy | 085445c | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 185 | return 0; |
| 186 | } |
| 187 | #else |
| 188 | static int dp83867_of_init(struct phy_device *phydev) |
| 189 | { |
| 190 | struct dp83867_private *dp83867 = phydev->priv; |
| 191 | |
| 192 | dp83867->rx_id_delay = DEFAULT_RX_ID_DELAY; |
| 193 | dp83867->tx_id_delay = DEFAULT_TX_ID_DELAY; |
| 194 | dp83867->fifo_depth = DEFAULT_FIFO_DEPTH; |
Mugunthan V N | 6463170 | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 195 | dp83867->io_impedance = -EINVAL; |
Dan Murphy | 085445c | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 196 | |
| 197 | return 0; |
| 198 | } |
| 199 | #endif |
Edgar E. Iglesias | 721aed7 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 200 | |
| 201 | static int dp83867_config(struct phy_device *phydev) |
| 202 | { |
Dan Murphy | 085445c | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 203 | struct dp83867_private *dp83867; |
Siva Durga Prasad Paladugu | 85b949f | 2016-03-25 12:53:43 +0530 | [diff] [blame] | 204 | unsigned int val, delay, cfg2; |
Janine Hagemann | be71a74 | 2018-08-28 08:25:38 +0200 | [diff] [blame] | 205 | int ret, bs; |
Edgar E. Iglesias | 721aed7 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 206 | |
Dan Murphy | 085445c | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 207 | if (!phydev->priv) { |
| 208 | dp83867 = kzalloc(sizeof(*dp83867), GFP_KERNEL); |
| 209 | if (!dp83867) |
| 210 | return -ENOMEM; |
| 211 | |
| 212 | phydev->priv = dp83867; |
| 213 | ret = dp83867_of_init(phydev); |
| 214 | if (ret) |
| 215 | goto err_out; |
| 216 | } else { |
| 217 | dp83867 = (struct dp83867_private *)phydev->priv; |
| 218 | } |
| 219 | |
Edgar E. Iglesias | 721aed7 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 220 | /* Restart the PHY. */ |
| 221 | val = phy_read(phydev, MDIO_DEVAD_NONE, DP83867_CTRL); |
| 222 | phy_write(phydev, MDIO_DEVAD_NONE, DP83867_CTRL, |
| 223 | val | DP83867_SW_RESTART); |
| 224 | |
Murali Karicheri | 63d3192 | 2018-06-28 14:26:34 -0500 | [diff] [blame] | 225 | /* Mode 1 or 2 workaround */ |
| 226 | if (dp83867->rxctrl_strap_quirk) { |
Carlo Caione | 4c29dc1 | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 227 | val = phy_read_mmd(phydev, DP83867_DEVADDR, |
| 228 | DP83867_CFG4); |
Murali Karicheri | 63d3192 | 2018-06-28 14:26:34 -0500 | [diff] [blame] | 229 | val &= ~BIT(7); |
Carlo Caione | 4c29dc1 | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 230 | phy_write_mmd(phydev, DP83867_DEVADDR, |
| 231 | DP83867_CFG4, val); |
Murali Karicheri | 63d3192 | 2018-06-28 14:26:34 -0500 | [diff] [blame] | 232 | } |
| 233 | |
Edgar E. Iglesias | 721aed7 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 234 | if (phy_interface_is_rgmii(phydev)) { |
| 235 | ret = phy_write(phydev, MDIO_DEVAD_NONE, MII_DP83867_PHYCTRL, |
Michal Simek | 0179063 | 2015-10-19 10:43:30 +0200 | [diff] [blame] | 236 | (DP83867_MDI_CROSSOVER_AUTO << DP83867_MDI_CROSSOVER) | |
Dan Murphy | 085445c | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 237 | (dp83867->fifo_depth << DP83867_PHYCR_FIFO_DEPTH_SHIFT)); |
Edgar E. Iglesias | 721aed7 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 238 | if (ret) |
Dan Murphy | 085445c | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 239 | goto err_out; |
Janine Hagemann | be71a74 | 2018-08-28 08:25:38 +0200 | [diff] [blame] | 240 | |
| 241 | /* The code below checks if "port mirroring" N/A MODE4 has been |
| 242 | * enabled during power on bootstrap. |
| 243 | * |
| 244 | * Such N/A mode enabled by mistake can put PHY IC in some |
| 245 | * internal testing mode and disable RGMII transmission. |
| 246 | * |
| 247 | * In this particular case one needs to check STRAP_STS1 |
| 248 | * register's bit 11 (marked as RESERVED). |
| 249 | */ |
| 250 | |
Carlo Caione | 4c29dc1 | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 251 | bs = phy_read_mmd(phydev, DP83867_DEVADDR, |
| 252 | DP83867_STRAP_STS1); |
Janine Hagemann | be71a74 | 2018-08-28 08:25:38 +0200 | [diff] [blame] | 253 | val = phy_read(phydev, MDIO_DEVAD_NONE, MII_DP83867_PHYCTRL); |
| 254 | if (bs & DP83867_STRAP_STS1_RESERVED) { |
| 255 | val &= ~DP83867_PHYCR_RESERVED_MASK; |
| 256 | phy_write(phydev, MDIO_DEVAD_NONE, MII_DP83867_PHYCTRL, |
| 257 | val); |
| 258 | } |
| 259 | |
Dan Murphy | 0a71cd7 | 2016-05-02 15:46:02 -0500 | [diff] [blame] | 260 | } else if (phy_interface_is_sgmii(phydev)) { |
Siva Durga Prasad Paladugu | 85b949f | 2016-03-25 12:53:43 +0530 | [diff] [blame] | 261 | phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, |
| 262 | (BMCR_ANENABLE | BMCR_FULLDPLX | BMCR_SPEED1000)); |
| 263 | |
| 264 | cfg2 = phy_read(phydev, phydev->addr, MII_DP83867_CFG2); |
| 265 | cfg2 &= MII_DP83867_CFG2_MASK; |
| 266 | cfg2 |= (MII_DP83867_CFG2_SPEEDOPT_10EN | |
| 267 | MII_DP83867_CFG2_SGMII_AUTONEGEN | |
| 268 | MII_DP83867_CFG2_SPEEDOPT_ENH | |
| 269 | MII_DP83867_CFG2_SPEEDOPT_CNT | |
| 270 | MII_DP83867_CFG2_SPEEDOPT_INTLOW); |
| 271 | phy_write(phydev, MDIO_DEVAD_NONE, MII_DP83867_CFG2, cfg2); |
| 272 | |
Carlo Caione | 4c29dc1 | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 273 | phy_write_mmd(phydev, DP83867_DEVADDR, |
| 274 | DP83867_RGMIICTL, 0x0); |
Siva Durga Prasad Paladugu | 85b949f | 2016-03-25 12:53:43 +0530 | [diff] [blame] | 275 | |
| 276 | phy_write(phydev, MDIO_DEVAD_NONE, MII_DP83867_PHYCTRL, |
| 277 | DP83867_PHYCTRL_SGMIIEN | |
| 278 | (DP83867_MDI_CROSSOVER_MDIX << |
| 279 | DP83867_MDI_CROSSOVER) | |
Dan Murphy | 085445c | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 280 | (dp83867->fifo_depth << DP83867_PHYCTRL_RXFIFO_SHIFT) | |
| 281 | (dp83867->fifo_depth << DP83867_PHYCTRL_TXFIFO_SHIFT)); |
Siva Durga Prasad Paladugu | 85b949f | 2016-03-25 12:53:43 +0530 | [diff] [blame] | 282 | phy_write(phydev, MDIO_DEVAD_NONE, MII_DP83867_BISCR, 0x0); |
Edgar E. Iglesias | 721aed7 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Phil Edworthy | 8abdead | 2016-12-09 10:46:02 +0000 | [diff] [blame] | 285 | if (phy_interface_is_rgmii(phydev)) { |
Carlo Caione | 4c29dc1 | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 286 | val = phy_read_mmd(phydev, DP83867_DEVADDR, |
| 287 | DP83867_RGMIICTL); |
Edgar E. Iglesias | 721aed7 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 288 | |
| 289 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) |
| 290 | val |= (DP83867_RGMII_TX_CLK_DELAY_EN | |
| 291 | DP83867_RGMII_RX_CLK_DELAY_EN); |
| 292 | |
| 293 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) |
| 294 | val |= DP83867_RGMII_TX_CLK_DELAY_EN; |
| 295 | |
| 296 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) |
| 297 | val |= DP83867_RGMII_RX_CLK_DELAY_EN; |
| 298 | |
Carlo Caione | 4c29dc1 | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 299 | phy_write_mmd(phydev, DP83867_DEVADDR, |
| 300 | DP83867_RGMIICTL, val); |
Edgar E. Iglesias | 721aed7 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 301 | |
Dan Murphy | 085445c | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 302 | delay = (dp83867->rx_id_delay | |
| 303 | (dp83867->tx_id_delay << DP83867_RGMII_TX_CLK_DELAY_SHIFT)); |
Edgar E. Iglesias | 721aed7 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 304 | |
Carlo Caione | 4c29dc1 | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 305 | phy_write_mmd(phydev, DP83867_DEVADDR, |
| 306 | DP83867_RGMIIDCTL, delay); |
Mugunthan V N | 6463170 | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 307 | |
| 308 | if (dp83867->io_impedance >= 0) { |
Carlo Caione | 4c29dc1 | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 309 | val = phy_read_mmd(phydev, |
| 310 | DP83867_DEVADDR, |
| 311 | DP83867_IO_MUX_CFG); |
Mugunthan V N | 6463170 | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 312 | val &= ~DP83867_IO_MUX_CFG_IO_IMPEDANCE_CTRL; |
| 313 | val |= dp83867->io_impedance & |
| 314 | DP83867_IO_MUX_CFG_IO_IMPEDANCE_CTRL; |
Carlo Caione | 4c29dc1 | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 315 | phy_write_mmd(phydev, DP83867_DEVADDR, |
| 316 | DP83867_IO_MUX_CFG, val); |
Mugunthan V N | 6463170 | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 317 | } |
Edgar E. Iglesias | 721aed7 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 318 | } |
| 319 | |
Janine Hagemann | fba725f | 2018-08-28 08:25:37 +0200 | [diff] [blame] | 320 | if (dp83867->port_mirroring != DP83867_PORT_MIRRORING_KEEP) |
| 321 | dp83867_config_port_mirroring(phydev); |
| 322 | |
Edgar E. Iglesias | 721aed7 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 323 | genphy_config_aneg(phydev); |
| 324 | return 0; |
Dan Murphy | 085445c | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 325 | |
| 326 | err_out: |
| 327 | kfree(dp83867); |
| 328 | return ret; |
Edgar E. Iglesias | 721aed7 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | static struct phy_driver DP83867_driver = { |
| 332 | .name = "TI DP83867", |
| 333 | .uid = 0x2000a231, |
| 334 | .mask = 0xfffffff0, |
| 335 | .features = PHY_GBIT_FEATURES, |
| 336 | .config = &dp83867_config, |
| 337 | .startup = &genphy_startup, |
| 338 | .shutdown = &genphy_shutdown, |
| 339 | }; |
| 340 | |
| 341 | int phy_ti_init(void) |
| 342 | { |
| 343 | phy_register(&DP83867_driver); |
| 344 | return 0; |
| 345 | } |