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 |
Grygorii Strashko | 20f7ea4 | 2019-11-18 23:04:44 +0200 | [diff] [blame] | 28 | #define DP83867_STRAP_STS2 0x006f |
Edgar E. Iglesias | 721aed7 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 29 | #define DP83867_RGMIIDCTL 0x0086 |
Mugunthan V N | 6463170 | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 30 | #define DP83867_IO_MUX_CFG 0x0170 |
Edgar E. Iglesias | 721aed7 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 31 | |
| 32 | #define DP83867_SW_RESET BIT(15) |
| 33 | #define DP83867_SW_RESTART BIT(14) |
| 34 | |
| 35 | /* MICR Interrupt bits */ |
| 36 | #define MII_DP83867_MICR_AN_ERR_INT_EN BIT(15) |
| 37 | #define MII_DP83867_MICR_SPEED_CHNG_INT_EN BIT(14) |
| 38 | #define MII_DP83867_MICR_DUP_MODE_CHNG_INT_EN BIT(13) |
| 39 | #define MII_DP83867_MICR_PAGE_RXD_INT_EN BIT(12) |
| 40 | #define MII_DP83867_MICR_AUTONEG_COMP_INT_EN BIT(11) |
| 41 | #define MII_DP83867_MICR_LINK_STS_CHNG_INT_EN BIT(10) |
| 42 | #define MII_DP83867_MICR_FALSE_CARRIER_INT_EN BIT(8) |
| 43 | #define MII_DP83867_MICR_SLEEP_MODE_CHNG_INT_EN BIT(4) |
| 44 | #define MII_DP83867_MICR_WOL_INT_EN BIT(3) |
| 45 | #define MII_DP83867_MICR_XGMII_ERR_INT_EN BIT(2) |
| 46 | #define MII_DP83867_MICR_POL_CHNG_INT_EN BIT(1) |
| 47 | #define MII_DP83867_MICR_JABBER_INT_EN BIT(0) |
| 48 | |
| 49 | /* RGMIICTL bits */ |
| 50 | #define DP83867_RGMII_TX_CLK_DELAY_EN BIT(1) |
| 51 | #define DP83867_RGMII_RX_CLK_DELAY_EN BIT(0) |
| 52 | |
Janine Hagemann | be71a74 | 2018-08-28 08:25:38 +0200 | [diff] [blame] | 53 | /* STRAP_STS1 bits */ |
| 54 | #define DP83867_STRAP_STS1_RESERVED BIT(11) |
| 55 | |
Grygorii Strashko | 20f7ea4 | 2019-11-18 23:04:44 +0200 | [diff] [blame] | 56 | /* STRAP_STS2 bits */ |
| 57 | #define DP83867_STRAP_STS2_CLK_SKEW_TX_MASK GENMASK(6, 4) |
| 58 | #define DP83867_STRAP_STS2_CLK_SKEW_TX_SHIFT 4 |
| 59 | #define DP83867_STRAP_STS2_CLK_SKEW_RX_MASK GENMASK(2, 0) |
| 60 | #define DP83867_STRAP_STS2_CLK_SKEW_RX_SHIFT 0 |
| 61 | #define DP83867_STRAP_STS2_CLK_SKEW_NONE BIT(2) |
| 62 | |
Edgar E. Iglesias | 721aed7 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 63 | /* PHY CTRL bits */ |
| 64 | #define DP83867_PHYCR_FIFO_DEPTH_SHIFT 14 |
Grygorii Strashko | 37d6265 | 2019-11-18 23:04:46 +0200 | [diff] [blame] | 65 | #define DP83867_PHYCR_FIFO_DEPTH_MASK GENMASK(15, 14) |
Janine Hagemann | be71a74 | 2018-08-28 08:25:38 +0200 | [diff] [blame] | 66 | #define DP83867_PHYCR_RESERVED_MASK BIT(11) |
Michal Simek | 0179063 | 2015-10-19 10:43:30 +0200 | [diff] [blame] | 67 | #define DP83867_MDI_CROSSOVER 5 |
Siva Durga Prasad Paladugu | 85b949f | 2016-03-25 12:53:43 +0530 | [diff] [blame] | 68 | #define DP83867_MDI_CROSSOVER_MDIX 2 |
| 69 | #define DP83867_PHYCTRL_SGMIIEN 0x0800 |
| 70 | #define DP83867_PHYCTRL_RXFIFO_SHIFT 12 |
| 71 | #define DP83867_PHYCTRL_TXFIFO_SHIFT 14 |
Edgar E. Iglesias | 721aed7 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 72 | |
| 73 | /* RGMIIDCTL bits */ |
Grygorii Strashko | 20f7ea4 | 2019-11-18 23:04:44 +0200 | [diff] [blame] | 74 | #define DP83867_RGMII_TX_CLK_DELAY_MAX 0xf |
Edgar E. Iglesias | 721aed7 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 75 | #define DP83867_RGMII_TX_CLK_DELAY_SHIFT 4 |
Grygorii Strashko | 20f7ea4 | 2019-11-18 23:04:44 +0200 | [diff] [blame] | 76 | #define DP83867_RGMII_RX_CLK_DELAY_MAX 0xf |
Edgar E. Iglesias | 721aed7 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 77 | |
Siva Durga Prasad Paladugu | 85b949f | 2016-03-25 12:53:43 +0530 | [diff] [blame] | 78 | /* CFG2 bits */ |
| 79 | #define MII_DP83867_CFG2_SPEEDOPT_10EN 0x0040 |
| 80 | #define MII_DP83867_CFG2_SGMII_AUTONEGEN 0x0080 |
| 81 | #define MII_DP83867_CFG2_SPEEDOPT_ENH 0x0100 |
| 82 | #define MII_DP83867_CFG2_SPEEDOPT_CNT 0x0800 |
| 83 | #define MII_DP83867_CFG2_SPEEDOPT_INTLOW 0x2000 |
| 84 | #define MII_DP83867_CFG2_MASK 0x003F |
| 85 | |
Dan Murphy | 085445c | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 86 | /* User setting - can be taken from DTS */ |
Dan Murphy | 085445c | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 87 | #define DEFAULT_FIFO_DEPTH DP83867_PHYCR_FIFO_DEPTH_4_B_NIB |
| 88 | |
Mugunthan V N | 6463170 | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 89 | /* IO_MUX_CFG bits */ |
| 90 | #define DP83867_IO_MUX_CFG_IO_IMPEDANCE_CTRL 0x1f |
| 91 | |
| 92 | #define DP83867_IO_MUX_CFG_IO_IMPEDANCE_MAX 0x0 |
| 93 | #define DP83867_IO_MUX_CFG_IO_IMPEDANCE_MIN 0x1f |
Grygorii Strashko | b3b9b12 | 2019-11-18 23:04:43 +0200 | [diff] [blame] | 94 | #define DP83867_IO_MUX_CFG_CLK_O_DISABLE BIT(6) |
Janine Hagemann | 0f347a0 | 2018-08-28 08:25:39 +0200 | [diff] [blame] | 95 | #define DP83867_IO_MUX_CFG_CLK_O_SEL_SHIFT 8 |
| 96 | #define DP83867_IO_MUX_CFG_CLK_O_SEL_MASK \ |
| 97 | GENMASK(0x1f, DP83867_IO_MUX_CFG_CLK_O_SEL_SHIFT) |
Mugunthan V N | 6463170 | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 98 | |
Janine Hagemann | fba725f | 2018-08-28 08:25:37 +0200 | [diff] [blame] | 99 | /* CFG4 bits */ |
| 100 | #define DP83867_CFG4_PORT_MIRROR_EN BIT(0) |
| 101 | |
| 102 | enum { |
| 103 | DP83867_PORT_MIRRORING_KEEP, |
| 104 | DP83867_PORT_MIRRORING_EN, |
| 105 | DP83867_PORT_MIRRORING_DIS, |
| 106 | }; |
| 107 | |
Dan Murphy | 085445c | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 108 | struct dp83867_private { |
Grygorii Strashko | 20f7ea4 | 2019-11-18 23:04:44 +0200 | [diff] [blame] | 109 | u32 rx_id_delay; |
| 110 | u32 tx_id_delay; |
Dan Murphy | 085445c | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 111 | int fifo_depth; |
Mugunthan V N | 6463170 | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 112 | int io_impedance; |
Murali Karicheri | 63d3192 | 2018-06-28 14:26:34 -0500 | [diff] [blame] | 113 | bool rxctrl_strap_quirk; |
Janine Hagemann | fba725f | 2018-08-28 08:25:37 +0200 | [diff] [blame] | 114 | int port_mirroring; |
Grygorii Strashko | b3b9b12 | 2019-11-18 23:04:43 +0200 | [diff] [blame] | 115 | bool set_clk_output; |
Trent Piepho | 2529dea | 2019-05-10 17:49:08 +0000 | [diff] [blame] | 116 | unsigned int clk_output_sel; |
Dan Murphy | 085445c | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 117 | }; |
| 118 | |
Janine Hagemann | fba725f | 2018-08-28 08:25:37 +0200 | [diff] [blame] | 119 | static int dp83867_config_port_mirroring(struct phy_device *phydev) |
| 120 | { |
| 121 | struct dp83867_private *dp83867 = |
| 122 | (struct dp83867_private *)phydev->priv; |
| 123 | u16 val; |
| 124 | |
Carlo Caione | 4c29dc1 | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 125 | val = phy_read_mmd(phydev, DP83867_DEVADDR, DP83867_CFG4); |
Janine Hagemann | fba725f | 2018-08-28 08:25:37 +0200 | [diff] [blame] | 126 | |
| 127 | if (dp83867->port_mirroring == DP83867_PORT_MIRRORING_EN) |
| 128 | val |= DP83867_CFG4_PORT_MIRROR_EN; |
| 129 | else |
| 130 | val &= ~DP83867_CFG4_PORT_MIRROR_EN; |
| 131 | |
Carlo Caione | 4c29dc1 | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 132 | phy_write_mmd(phydev, DP83867_DEVADDR, DP83867_CFG4, val); |
Janine Hagemann | fba725f | 2018-08-28 08:25:37 +0200 | [diff] [blame] | 133 | |
| 134 | return 0; |
| 135 | } |
| 136 | |
Dan Murphy | 085445c | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 137 | #if defined(CONFIG_DM_ETH) |
| 138 | /** |
| 139 | * dp83867_data_init - Convenience function for setting PHY specific data |
| 140 | * |
| 141 | * @phydev: the phy_device struct |
| 142 | */ |
| 143 | static int dp83867_of_init(struct phy_device *phydev) |
| 144 | { |
| 145 | struct dp83867_private *dp83867 = phydev->priv; |
Grygorii Strashko | b8d7ec7 | 2018-07-05 12:02:49 -0500 | [diff] [blame] | 146 | ofnode node; |
Grygorii Strashko | b3b9b12 | 2019-11-18 23:04:43 +0200 | [diff] [blame] | 147 | int ret; |
Janine Hagemann | 0f347a0 | 2018-08-28 08:25:39 +0200 | [diff] [blame] | 148 | |
Michal Simek | 6845b36 | 2019-03-16 12:43:17 +0100 | [diff] [blame] | 149 | node = phy_get_ofnode(phydev); |
| 150 | if (!ofnode_valid(node)) |
| 151 | return -EINVAL; |
| 152 | |
Grygorii Strashko | b3b9b12 | 2019-11-18 23:04:43 +0200 | [diff] [blame] | 153 | /* Optional configuration */ |
| 154 | ret = ofnode_read_u32(node, "ti,clk-output-sel", |
| 155 | &dp83867->clk_output_sel); |
| 156 | /* If not set, keep default */ |
| 157 | if (!ret) { |
| 158 | dp83867->set_clk_output = true; |
| 159 | /* Valid values are 0 to DP83867_CLK_O_SEL_REF_CLK or |
| 160 | * DP83867_CLK_O_SEL_OFF. |
| 161 | */ |
| 162 | if (dp83867->clk_output_sel > DP83867_CLK_O_SEL_REF_CLK && |
| 163 | dp83867->clk_output_sel != DP83867_CLK_O_SEL_OFF) { |
| 164 | pr_debug("ti,clk-output-sel value %u out of range\n", |
| 165 | dp83867->clk_output_sel); |
| 166 | return -EINVAL; |
| 167 | } |
| 168 | } |
Grygorii Strashko | b8d7ec7 | 2018-07-05 12:02:49 -0500 | [diff] [blame] | 169 | |
Grygorii Strashko | 3ab75cf | 2018-06-28 14:26:35 -0500 | [diff] [blame] | 170 | if (ofnode_read_bool(node, "ti,max-output-impedance")) |
Mugunthan V N | 6463170 | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 171 | dp83867->io_impedance = DP83867_IO_MUX_CFG_IO_IMPEDANCE_MAX; |
Grygorii Strashko | 3ab75cf | 2018-06-28 14:26:35 -0500 | [diff] [blame] | 172 | else if (ofnode_read_bool(node, "ti,min-output-impedance")) |
Mugunthan V N | 6463170 | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 173 | dp83867->io_impedance = DP83867_IO_MUX_CFG_IO_IMPEDANCE_MIN; |
| 174 | else |
| 175 | dp83867->io_impedance = -EINVAL; |
Dan Murphy | 085445c | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 176 | |
Grygorii Strashko | 3ab75cf | 2018-06-28 14:26:35 -0500 | [diff] [blame] | 177 | if (ofnode_read_bool(node, "ti,dp83867-rxctrl-strap-quirk")) |
Murali Karicheri | 63d3192 | 2018-06-28 14:26:34 -0500 | [diff] [blame] | 178 | dp83867->rxctrl_strap_quirk = true; |
Dan Murphy | 085445c | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 179 | |
Grygorii Strashko | 20f7ea4 | 2019-11-18 23:04:44 +0200 | [diff] [blame] | 180 | /* Existing behavior was to use default pin strapping delay in rgmii |
| 181 | * mode, but rgmii should have meant no delay. Warn existing users. |
| 182 | */ |
| 183 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII) { |
| 184 | u16 val = phy_read_mmd(phydev, DP83867_DEVADDR, |
| 185 | DP83867_STRAP_STS2); |
| 186 | u16 txskew = (val & DP83867_STRAP_STS2_CLK_SKEW_TX_MASK) >> |
| 187 | DP83867_STRAP_STS2_CLK_SKEW_TX_SHIFT; |
| 188 | u16 rxskew = (val & DP83867_STRAP_STS2_CLK_SKEW_RX_MASK) >> |
| 189 | DP83867_STRAP_STS2_CLK_SKEW_RX_SHIFT; |
| 190 | |
| 191 | if (txskew != DP83867_STRAP_STS2_CLK_SKEW_NONE || |
| 192 | rxskew != DP83867_STRAP_STS2_CLK_SKEW_NONE) |
| 193 | pr_warn("PHY has delays via pin strapping, but phy-mode = 'rgmii'\n" |
| 194 | "Should be 'rgmii-id' to use internal delays\n"); |
| 195 | } |
| 196 | |
| 197 | /* RX delay *must* be specified if internal delay of RX is used. */ |
| 198 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || |
| 199 | phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) { |
| 200 | ret = ofnode_read_u32(node, "ti,rx-internal-delay", |
| 201 | &dp83867->rx_id_delay); |
| 202 | if (ret) { |
| 203 | pr_debug("ti,rx-internal-delay must be specified\n"); |
| 204 | return ret; |
| 205 | } |
| 206 | if (dp83867->rx_id_delay > DP83867_RGMII_RX_CLK_DELAY_MAX) { |
| 207 | pr_debug("ti,rx-internal-delay value of %u out of range\n", |
| 208 | dp83867->rx_id_delay); |
| 209 | return -EINVAL; |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | /* TX delay *must* be specified if internal delay of RX is used. */ |
| 214 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || |
| 215 | phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) { |
| 216 | ret = ofnode_read_u32(node, "ti,tx-internal-delay", |
| 217 | &dp83867->tx_id_delay); |
| 218 | if (ret) { |
| 219 | debug("ti,tx-internal-delay must be specified\n"); |
| 220 | return ret; |
| 221 | } |
| 222 | if (dp83867->tx_id_delay > DP83867_RGMII_TX_CLK_DELAY_MAX) { |
| 223 | pr_debug("ti,tx-internal-delay value of %u out of range\n", |
| 224 | dp83867->tx_id_delay); |
| 225 | return -EINVAL; |
| 226 | } |
| 227 | } |
Dan Murphy | 085445c | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 228 | |
Grygorii Strashko | 3ab75cf | 2018-06-28 14:26:35 -0500 | [diff] [blame] | 229 | dp83867->fifo_depth = ofnode_read_u32_default(node, "ti,fifo-depth", |
Trent Piepho | c2df9b4 | 2019-05-09 19:41:51 +0000 | [diff] [blame] | 230 | DEFAULT_FIFO_DEPTH); |
Janine Hagemann | fba725f | 2018-08-28 08:25:37 +0200 | [diff] [blame] | 231 | if (ofnode_read_bool(node, "enet-phy-lane-swap")) |
| 232 | dp83867->port_mirroring = DP83867_PORT_MIRRORING_EN; |
| 233 | |
| 234 | if (ofnode_read_bool(node, "enet-phy-lane-no-swap")) |
| 235 | dp83867->port_mirroring = DP83867_PORT_MIRRORING_DIS; |
| 236 | |
Dan Murphy | 085445c | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 237 | return 0; |
| 238 | } |
| 239 | #else |
| 240 | static int dp83867_of_init(struct phy_device *phydev) |
| 241 | { |
| 242 | struct dp83867_private *dp83867 = phydev->priv; |
| 243 | |
Grygorii Strashko | 20f7ea4 | 2019-11-18 23:04:44 +0200 | [diff] [blame] | 244 | dp83867->rx_id_delay = DP83867_RGMIIDCTL_2_25_NS; |
| 245 | dp83867->tx_id_delay = DP83867_RGMIIDCTL_2_75_NS; |
Dan Murphy | 085445c | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 246 | dp83867->fifo_depth = DEFAULT_FIFO_DEPTH; |
Mugunthan V N | 6463170 | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 247 | dp83867->io_impedance = -EINVAL; |
Dan Murphy | 085445c | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 248 | |
| 249 | return 0; |
| 250 | } |
| 251 | #endif |
Edgar E. Iglesias | 721aed7 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 252 | |
| 253 | static int dp83867_config(struct phy_device *phydev) |
| 254 | { |
Dan Murphy | 085445c | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 255 | struct dp83867_private *dp83867; |
Siva Durga Prasad Paladugu | 85b949f | 2016-03-25 12:53:43 +0530 | [diff] [blame] | 256 | unsigned int val, delay, cfg2; |
Janine Hagemann | be71a74 | 2018-08-28 08:25:38 +0200 | [diff] [blame] | 257 | int ret, bs; |
Edgar E. Iglesias | 721aed7 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 258 | |
Grygorii Strashko | ee622f0 | 2019-11-18 23:04:41 +0200 | [diff] [blame] | 259 | dp83867 = (struct dp83867_private *)phydev->priv; |
Dan Murphy | 085445c | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 260 | |
Grygorii Strashko | ee622f0 | 2019-11-18 23:04:41 +0200 | [diff] [blame] | 261 | ret = dp83867_of_init(phydev); |
| 262 | if (ret) |
| 263 | return ret; |
Dan Murphy | 085445c | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 264 | |
Edgar E. Iglesias | 721aed7 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 265 | /* Restart the PHY. */ |
| 266 | val = phy_read(phydev, MDIO_DEVAD_NONE, DP83867_CTRL); |
| 267 | phy_write(phydev, MDIO_DEVAD_NONE, DP83867_CTRL, |
| 268 | val | DP83867_SW_RESTART); |
| 269 | |
Murali Karicheri | 63d3192 | 2018-06-28 14:26:34 -0500 | [diff] [blame] | 270 | /* Mode 1 or 2 workaround */ |
| 271 | if (dp83867->rxctrl_strap_quirk) { |
Carlo Caione | 4c29dc1 | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 272 | val = phy_read_mmd(phydev, DP83867_DEVADDR, |
| 273 | DP83867_CFG4); |
Murali Karicheri | 63d3192 | 2018-06-28 14:26:34 -0500 | [diff] [blame] | 274 | val &= ~BIT(7); |
Carlo Caione | 4c29dc1 | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 275 | phy_write_mmd(phydev, DP83867_DEVADDR, |
| 276 | DP83867_CFG4, val); |
Murali Karicheri | 63d3192 | 2018-06-28 14:26:34 -0500 | [diff] [blame] | 277 | } |
| 278 | |
Edgar E. Iglesias | 721aed7 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 279 | if (phy_interface_is_rgmii(phydev)) { |
Grygorii Strashko | 37d6265 | 2019-11-18 23:04:46 +0200 | [diff] [blame] | 280 | val = phy_read(phydev, MDIO_DEVAD_NONE, MII_DP83867_PHYCTRL); |
| 281 | if (val < 0) |
Dan Murphy | 085445c | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 282 | goto err_out; |
Grygorii Strashko | 37d6265 | 2019-11-18 23:04:46 +0200 | [diff] [blame] | 283 | val &= ~DP83867_PHYCR_FIFO_DEPTH_MASK; |
| 284 | val |= (dp83867->fifo_depth << DP83867_PHYCR_FIFO_DEPTH_SHIFT); |
Janine Hagemann | be71a74 | 2018-08-28 08:25:38 +0200 | [diff] [blame] | 285 | |
| 286 | /* The code below checks if "port mirroring" N/A MODE4 has been |
| 287 | * enabled during power on bootstrap. |
| 288 | * |
| 289 | * Such N/A mode enabled by mistake can put PHY IC in some |
| 290 | * internal testing mode and disable RGMII transmission. |
| 291 | * |
| 292 | * In this particular case one needs to check STRAP_STS1 |
| 293 | * register's bit 11 (marked as RESERVED). |
| 294 | */ |
| 295 | |
Grygorii Strashko | 37d6265 | 2019-11-18 23:04:46 +0200 | [diff] [blame] | 296 | bs = phy_read_mmd(phydev, DP83867_DEVADDR, DP83867_STRAP_STS1); |
| 297 | if (bs & DP83867_STRAP_STS1_RESERVED) |
Janine Hagemann | be71a74 | 2018-08-28 08:25:38 +0200 | [diff] [blame] | 298 | val &= ~DP83867_PHYCR_RESERVED_MASK; |
Janine Hagemann | be71a74 | 2018-08-28 08:25:38 +0200 | [diff] [blame] | 299 | |
Grygorii Strashko | 37d6265 | 2019-11-18 23:04:46 +0200 | [diff] [blame] | 300 | ret = phy_write(phydev, MDIO_DEVAD_NONE, |
| 301 | MII_DP83867_PHYCTRL, val); |
| 302 | |
| 303 | val = phy_read_mmd(phydev, DP83867_DEVADDR, |
| 304 | DP83867_RGMIICTL); |
| 305 | |
| 306 | val &= ~(DP83867_RGMII_TX_CLK_DELAY_EN | |
| 307 | DP83867_RGMII_RX_CLK_DELAY_EN); |
| 308 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) |
| 309 | val |= (DP83867_RGMII_TX_CLK_DELAY_EN | |
| 310 | DP83867_RGMII_RX_CLK_DELAY_EN); |
| 311 | |
| 312 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) |
| 313 | val |= DP83867_RGMII_TX_CLK_DELAY_EN; |
| 314 | |
| 315 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) |
| 316 | val |= DP83867_RGMII_RX_CLK_DELAY_EN; |
| 317 | |
| 318 | phy_write_mmd(phydev, DP83867_DEVADDR, DP83867_RGMIICTL, val); |
| 319 | |
| 320 | delay = (dp83867->rx_id_delay | |
| 321 | (dp83867->tx_id_delay << |
| 322 | DP83867_RGMII_TX_CLK_DELAY_SHIFT)); |
| 323 | |
| 324 | phy_write_mmd(phydev, DP83867_DEVADDR, |
| 325 | DP83867_RGMIIDCTL, delay); |
| 326 | } |
| 327 | |
| 328 | if (phy_interface_is_sgmii(phydev)) { |
Siva Durga Prasad Paladugu | 85b949f | 2016-03-25 12:53:43 +0530 | [diff] [blame] | 329 | phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, |
| 330 | (BMCR_ANENABLE | BMCR_FULLDPLX | BMCR_SPEED1000)); |
| 331 | |
| 332 | cfg2 = phy_read(phydev, phydev->addr, MII_DP83867_CFG2); |
| 333 | cfg2 &= MII_DP83867_CFG2_MASK; |
| 334 | cfg2 |= (MII_DP83867_CFG2_SPEEDOPT_10EN | |
| 335 | MII_DP83867_CFG2_SGMII_AUTONEGEN | |
| 336 | MII_DP83867_CFG2_SPEEDOPT_ENH | |
| 337 | MII_DP83867_CFG2_SPEEDOPT_CNT | |
| 338 | MII_DP83867_CFG2_SPEEDOPT_INTLOW); |
| 339 | phy_write(phydev, MDIO_DEVAD_NONE, MII_DP83867_CFG2, cfg2); |
| 340 | |
Carlo Caione | 4c29dc1 | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 341 | phy_write_mmd(phydev, DP83867_DEVADDR, |
| 342 | DP83867_RGMIICTL, 0x0); |
Siva Durga Prasad Paladugu | 85b949f | 2016-03-25 12:53:43 +0530 | [diff] [blame] | 343 | |
| 344 | phy_write(phydev, MDIO_DEVAD_NONE, MII_DP83867_PHYCTRL, |
| 345 | DP83867_PHYCTRL_SGMIIEN | |
| 346 | (DP83867_MDI_CROSSOVER_MDIX << |
| 347 | DP83867_MDI_CROSSOVER) | |
Dan Murphy | 085445c | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 348 | (dp83867->fifo_depth << DP83867_PHYCTRL_RXFIFO_SHIFT) | |
| 349 | (dp83867->fifo_depth << DP83867_PHYCTRL_TXFIFO_SHIFT)); |
Siva Durga Prasad Paladugu | 85b949f | 2016-03-25 12:53:43 +0530 | [diff] [blame] | 350 | phy_write(phydev, MDIO_DEVAD_NONE, MII_DP83867_BISCR, 0x0); |
Edgar E. Iglesias | 721aed7 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 351 | } |
| 352 | |
Grygorii Strashko | 253a5ff | 2019-11-18 23:04:45 +0200 | [diff] [blame] | 353 | if (dp83867->io_impedance >= 0) { |
| 354 | val = phy_read_mmd(phydev, |
| 355 | DP83867_DEVADDR, |
| 356 | DP83867_IO_MUX_CFG); |
| 357 | val &= ~DP83867_IO_MUX_CFG_IO_IMPEDANCE_CTRL; |
| 358 | val |= dp83867->io_impedance & |
| 359 | DP83867_IO_MUX_CFG_IO_IMPEDANCE_CTRL; |
| 360 | phy_write_mmd(phydev, DP83867_DEVADDR, |
| 361 | DP83867_IO_MUX_CFG, val); |
Edgar E. Iglesias | 721aed7 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 362 | } |
| 363 | |
Janine Hagemann | fba725f | 2018-08-28 08:25:37 +0200 | [diff] [blame] | 364 | if (dp83867->port_mirroring != DP83867_PORT_MIRRORING_KEEP) |
| 365 | dp83867_config_port_mirroring(phydev); |
| 366 | |
Grygorii Strashko | b3b9b12 | 2019-11-18 23:04:43 +0200 | [diff] [blame] | 367 | /* Clock output selection if muxing property is set */ |
| 368 | if (dp83867->set_clk_output) { |
| 369 | val = phy_read_mmd(phydev, DP83867_DEVADDR, |
| 370 | DP83867_IO_MUX_CFG); |
| 371 | |
| 372 | if (dp83867->clk_output_sel == DP83867_CLK_O_SEL_OFF) { |
| 373 | val |= DP83867_IO_MUX_CFG_CLK_O_DISABLE; |
| 374 | } else { |
| 375 | val &= ~(DP83867_IO_MUX_CFG_CLK_O_SEL_MASK | |
| 376 | DP83867_IO_MUX_CFG_CLK_O_DISABLE); |
| 377 | val |= dp83867->clk_output_sel << |
| 378 | DP83867_IO_MUX_CFG_CLK_O_SEL_SHIFT; |
| 379 | } |
| 380 | phy_write_mmd(phydev, DP83867_DEVADDR, |
| 381 | DP83867_IO_MUX_CFG, val); |
| 382 | } |
| 383 | |
Edgar E. Iglesias | 721aed7 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 384 | genphy_config_aneg(phydev); |
| 385 | return 0; |
Dan Murphy | 085445c | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 386 | |
| 387 | err_out: |
Dan Murphy | 085445c | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 388 | return ret; |
Edgar E. Iglesias | 721aed7 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 389 | } |
| 390 | |
Grygorii Strashko | ee622f0 | 2019-11-18 23:04:41 +0200 | [diff] [blame] | 391 | static int dp83867_probe(struct phy_device *phydev) |
| 392 | { |
| 393 | struct dp83867_private *dp83867; |
| 394 | |
| 395 | dp83867 = kzalloc(sizeof(*dp83867), GFP_KERNEL); |
| 396 | if (!dp83867) |
| 397 | return -ENOMEM; |
| 398 | |
| 399 | phydev->priv = dp83867; |
| 400 | return 0; |
| 401 | } |
| 402 | |
Edgar E. Iglesias | 721aed7 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 403 | static struct phy_driver DP83867_driver = { |
| 404 | .name = "TI DP83867", |
| 405 | .uid = 0x2000a231, |
| 406 | .mask = 0xfffffff0, |
| 407 | .features = PHY_GBIT_FEATURES, |
Grygorii Strashko | ee622f0 | 2019-11-18 23:04:41 +0200 | [diff] [blame] | 408 | .probe = dp83867_probe, |
Edgar E. Iglesias | 721aed7 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 409 | .config = &dp83867_config, |
| 410 | .startup = &genphy_startup, |
| 411 | .shutdown = &genphy_shutdown, |
| 412 | }; |
| 413 | |
| 414 | int phy_ti_init(void) |
| 415 | { |
| 416 | phy_register(&DP83867_driver); |
| 417 | return 0; |
| 418 | } |