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 |
Grygorii Strashko | 5b2742c | 2019-11-18 23:04:44 +0200 | [diff] [blame^] | 28 | #define DP83867_STRAP_STS2 0x006f |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 29 | #define DP83867_RGMIIDCTL 0x0086 |
Mugunthan V N | 5b6b18e | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 30 | #define DP83867_IO_MUX_CFG 0x0170 |
Edgar E. Iglesias | 8d3ce68 | 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 | b3dd2ed | 2018-08-28 08:25:38 +0200 | [diff] [blame] | 53 | /* STRAP_STS1 bits */ |
| 54 | #define DP83867_STRAP_STS1_RESERVED BIT(11) |
| 55 | |
Grygorii Strashko | 5b2742c | 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 | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 63 | /* PHY CTRL bits */ |
| 64 | #define DP83867_PHYCR_FIFO_DEPTH_SHIFT 14 |
Janine Hagemann | b3dd2ed | 2018-08-28 08:25:38 +0200 | [diff] [blame] | 65 | #define DP83867_PHYCR_RESERVED_MASK BIT(11) |
Michal Simek | f645915 | 2015-10-19 10:43:30 +0200 | [diff] [blame] | 66 | #define DP83867_MDI_CROSSOVER 5 |
| 67 | #define DP83867_MDI_CROSSOVER_AUTO 2 |
Siva Durga Prasad Paladugu | 02c7be6 | 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 | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 72 | |
| 73 | /* RGMIIDCTL bits */ |
Grygorii Strashko | 5b2742c | 2019-11-18 23:04:44 +0200 | [diff] [blame^] | 74 | #define DP83867_RGMII_TX_CLK_DELAY_MAX 0xf |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 75 | #define DP83867_RGMII_TX_CLK_DELAY_SHIFT 4 |
Grygorii Strashko | 5b2742c | 2019-11-18 23:04:44 +0200 | [diff] [blame^] | 76 | #define DP83867_RGMII_RX_CLK_DELAY_MAX 0xf |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 77 | |
Siva Durga Prasad Paladugu | 02c7be6 | 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 | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 86 | /* User setting - can be taken from DTS */ |
Dan Murphy | 83fbd0a | 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 | 5b6b18e | 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 | 1c35b57 | 2019-11-18 23:04:43 +0200 | [diff] [blame] | 94 | #define DP83867_IO_MUX_CFG_CLK_O_DISABLE BIT(6) |
Janine Hagemann | 1c2ba09 | 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 | 5b6b18e | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 98 | |
Janine Hagemann | ed51bfc | 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 | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 108 | struct dp83867_private { |
Grygorii Strashko | 5b2742c | 2019-11-18 23:04:44 +0200 | [diff] [blame^] | 109 | u32 rx_id_delay; |
| 110 | u32 tx_id_delay; |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 111 | int fifo_depth; |
Mugunthan V N | 5b6b18e | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 112 | int io_impedance; |
Murali Karicheri | 9b05076 | 2018-06-28 14:26:34 -0500 | [diff] [blame] | 113 | bool rxctrl_strap_quirk; |
Janine Hagemann | ed51bfc | 2018-08-28 08:25:37 +0200 | [diff] [blame] | 114 | int port_mirroring; |
Grygorii Strashko | 1c35b57 | 2019-11-18 23:04:43 +0200 | [diff] [blame] | 115 | bool set_clk_output; |
Trent Piepho | b0a86e5 | 2019-05-10 17:49:08 +0000 | [diff] [blame] | 116 | unsigned int clk_output_sel; |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 117 | }; |
| 118 | |
Janine Hagemann | ed51bfc | 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 | a8abcff | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 125 | val = phy_read_mmd(phydev, DP83867_DEVADDR, DP83867_CFG4); |
Janine Hagemann | ed51bfc | 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 | a8abcff | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 132 | phy_write_mmd(phydev, DP83867_DEVADDR, DP83867_CFG4, val); |
Janine Hagemann | ed51bfc | 2018-08-28 08:25:37 +0200 | [diff] [blame] | 133 | |
| 134 | return 0; |
| 135 | } |
| 136 | |
Dan Murphy | 83fbd0a | 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 | 00e2c24 | 2018-07-05 12:02:49 -0500 | [diff] [blame] | 146 | ofnode node; |
Grygorii Strashko | 1c35b57 | 2019-11-18 23:04:43 +0200 | [diff] [blame] | 147 | int ret; |
Janine Hagemann | 1c2ba09 | 2018-08-28 08:25:39 +0200 | [diff] [blame] | 148 | |
Michal Simek | 8e102a8 | 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 | 1c35b57 | 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 | 00e2c24 | 2018-07-05 12:02:49 -0500 | [diff] [blame] | 169 | |
Grygorii Strashko | 9df3505 | 2018-06-28 14:26:35 -0500 | [diff] [blame] | 170 | if (ofnode_read_bool(node, "ti,max-output-impedance")) |
Mugunthan V N | 5b6b18e | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 171 | dp83867->io_impedance = DP83867_IO_MUX_CFG_IO_IMPEDANCE_MAX; |
Grygorii Strashko | 9df3505 | 2018-06-28 14:26:35 -0500 | [diff] [blame] | 172 | else if (ofnode_read_bool(node, "ti,min-output-impedance")) |
Mugunthan V N | 5b6b18e | 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 | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 176 | |
Grygorii Strashko | 9df3505 | 2018-06-28 14:26:35 -0500 | [diff] [blame] | 177 | if (ofnode_read_bool(node, "ti,dp83867-rxctrl-strap-quirk")) |
Murali Karicheri | 9b05076 | 2018-06-28 14:26:34 -0500 | [diff] [blame] | 178 | dp83867->rxctrl_strap_quirk = true; |
Grygorii Strashko | 5b2742c | 2019-11-18 23:04:44 +0200 | [diff] [blame^] | 179 | |
| 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; |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 190 | |
Grygorii Strashko | 5b2742c | 2019-11-18 23:04:44 +0200 | [diff] [blame^] | 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 | 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->fifo_depth = ofnode_read_u32_default(node, "ti,fifo-depth", |
Trent Piepho | 19d7aee | 2019-05-09 19:41:51 +0000 | [diff] [blame] | 230 | DEFAULT_FIFO_DEPTH); |
Janine Hagemann | ed51bfc | 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 | 83fbd0a | 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 | 5b2742c | 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 | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 246 | dp83867->fifo_depth = DEFAULT_FIFO_DEPTH; |
Mugunthan V N | 5b6b18e | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 247 | dp83867->io_impedance = -EINVAL; |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 248 | |
| 249 | return 0; |
| 250 | } |
| 251 | #endif |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 252 | |
| 253 | static int dp83867_config(struct phy_device *phydev) |
| 254 | { |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 255 | struct dp83867_private *dp83867; |
Siva Durga Prasad Paladugu | 02c7be6 | 2016-03-25 12:53:43 +0530 | [diff] [blame] | 256 | unsigned int val, delay, cfg2; |
Janine Hagemann | b3dd2ed | 2018-08-28 08:25:38 +0200 | [diff] [blame] | 257 | int ret, bs; |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 258 | |
Grygorii Strashko | 1d8b552 | 2019-11-18 23:04:41 +0200 | [diff] [blame] | 259 | dp83867 = (struct dp83867_private *)phydev->priv; |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 260 | |
Grygorii Strashko | 1d8b552 | 2019-11-18 23:04:41 +0200 | [diff] [blame] | 261 | ret = dp83867_of_init(phydev); |
| 262 | if (ret) |
| 263 | return ret; |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 264 | |
Edgar E. Iglesias | 8d3ce68 | 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 | 9b05076 | 2018-06-28 14:26:34 -0500 | [diff] [blame] | 270 | /* Mode 1 or 2 workaround */ |
| 271 | if (dp83867->rxctrl_strap_quirk) { |
Carlo Caione | a8abcff | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 272 | val = phy_read_mmd(phydev, DP83867_DEVADDR, |
| 273 | DP83867_CFG4); |
Murali Karicheri | 9b05076 | 2018-06-28 14:26:34 -0500 | [diff] [blame] | 274 | val &= ~BIT(7); |
Carlo Caione | a8abcff | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 275 | phy_write_mmd(phydev, DP83867_DEVADDR, |
| 276 | DP83867_CFG4, val); |
Murali Karicheri | 9b05076 | 2018-06-28 14:26:34 -0500 | [diff] [blame] | 277 | } |
| 278 | |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 279 | if (phy_interface_is_rgmii(phydev)) { |
| 280 | ret = phy_write(phydev, MDIO_DEVAD_NONE, MII_DP83867_PHYCTRL, |
Michal Simek | f645915 | 2015-10-19 10:43:30 +0200 | [diff] [blame] | 281 | (DP83867_MDI_CROSSOVER_AUTO << DP83867_MDI_CROSSOVER) | |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 282 | (dp83867->fifo_depth << DP83867_PHYCR_FIFO_DEPTH_SHIFT)); |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 283 | if (ret) |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 284 | goto err_out; |
Janine Hagemann | b3dd2ed | 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 | |
Carlo Caione | a8abcff | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 296 | bs = phy_read_mmd(phydev, DP83867_DEVADDR, |
| 297 | DP83867_STRAP_STS1); |
Janine Hagemann | b3dd2ed | 2018-08-28 08:25:38 +0200 | [diff] [blame] | 298 | val = phy_read(phydev, MDIO_DEVAD_NONE, MII_DP83867_PHYCTRL); |
| 299 | if (bs & DP83867_STRAP_STS1_RESERVED) { |
| 300 | val &= ~DP83867_PHYCR_RESERVED_MASK; |
| 301 | phy_write(phydev, MDIO_DEVAD_NONE, MII_DP83867_PHYCTRL, |
| 302 | val); |
| 303 | } |
| 304 | |
Dan Murphy | 4f4e962 | 2016-05-02 15:46:02 -0500 | [diff] [blame] | 305 | } else if (phy_interface_is_sgmii(phydev)) { |
Siva Durga Prasad Paladugu | 02c7be6 | 2016-03-25 12:53:43 +0530 | [diff] [blame] | 306 | phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR, |
| 307 | (BMCR_ANENABLE | BMCR_FULLDPLX | BMCR_SPEED1000)); |
| 308 | |
| 309 | cfg2 = phy_read(phydev, phydev->addr, MII_DP83867_CFG2); |
| 310 | cfg2 &= MII_DP83867_CFG2_MASK; |
| 311 | cfg2 |= (MII_DP83867_CFG2_SPEEDOPT_10EN | |
| 312 | MII_DP83867_CFG2_SGMII_AUTONEGEN | |
| 313 | MII_DP83867_CFG2_SPEEDOPT_ENH | |
| 314 | MII_DP83867_CFG2_SPEEDOPT_CNT | |
| 315 | MII_DP83867_CFG2_SPEEDOPT_INTLOW); |
| 316 | phy_write(phydev, MDIO_DEVAD_NONE, MII_DP83867_CFG2, cfg2); |
| 317 | |
Carlo Caione | a8abcff | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 318 | phy_write_mmd(phydev, DP83867_DEVADDR, |
| 319 | DP83867_RGMIICTL, 0x0); |
Siva Durga Prasad Paladugu | 02c7be6 | 2016-03-25 12:53:43 +0530 | [diff] [blame] | 320 | |
| 321 | phy_write(phydev, MDIO_DEVAD_NONE, MII_DP83867_PHYCTRL, |
| 322 | DP83867_PHYCTRL_SGMIIEN | |
| 323 | (DP83867_MDI_CROSSOVER_MDIX << |
| 324 | DP83867_MDI_CROSSOVER) | |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 325 | (dp83867->fifo_depth << DP83867_PHYCTRL_RXFIFO_SHIFT) | |
| 326 | (dp83867->fifo_depth << DP83867_PHYCTRL_TXFIFO_SHIFT)); |
Siva Durga Prasad Paladugu | 02c7be6 | 2016-03-25 12:53:43 +0530 | [diff] [blame] | 327 | phy_write(phydev, MDIO_DEVAD_NONE, MII_DP83867_BISCR, 0x0); |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 328 | } |
| 329 | |
Phil Edworthy | c611980 | 2016-12-09 10:46:02 +0000 | [diff] [blame] | 330 | if (phy_interface_is_rgmii(phydev)) { |
Carlo Caione | a8abcff | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 331 | val = phy_read_mmd(phydev, DP83867_DEVADDR, |
| 332 | DP83867_RGMIICTL); |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 333 | |
Grygorii Strashko | 5b2742c | 2019-11-18 23:04:44 +0200 | [diff] [blame^] | 334 | val &= ~(DP83867_RGMII_TX_CLK_DELAY_EN | |
| 335 | DP83867_RGMII_RX_CLK_DELAY_EN); |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 336 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID) |
| 337 | val |= (DP83867_RGMII_TX_CLK_DELAY_EN | |
| 338 | DP83867_RGMII_RX_CLK_DELAY_EN); |
| 339 | |
| 340 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) |
| 341 | val |= DP83867_RGMII_TX_CLK_DELAY_EN; |
| 342 | |
| 343 | if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) |
| 344 | val |= DP83867_RGMII_RX_CLK_DELAY_EN; |
| 345 | |
Carlo Caione | a8abcff | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 346 | phy_write_mmd(phydev, DP83867_DEVADDR, |
| 347 | DP83867_RGMIICTL, val); |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 348 | |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 349 | delay = (dp83867->rx_id_delay | |
| 350 | (dp83867->tx_id_delay << DP83867_RGMII_TX_CLK_DELAY_SHIFT)); |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 351 | |
Carlo Caione | a8abcff | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 352 | phy_write_mmd(phydev, DP83867_DEVADDR, |
| 353 | DP83867_RGMIIDCTL, delay); |
Mugunthan V N | 5b6b18e | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 354 | |
| 355 | if (dp83867->io_impedance >= 0) { |
Carlo Caione | a8abcff | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 356 | val = phy_read_mmd(phydev, |
| 357 | DP83867_DEVADDR, |
| 358 | DP83867_IO_MUX_CFG); |
Mugunthan V N | 5b6b18e | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 359 | val &= ~DP83867_IO_MUX_CFG_IO_IMPEDANCE_CTRL; |
| 360 | val |= dp83867->io_impedance & |
| 361 | DP83867_IO_MUX_CFG_IO_IMPEDANCE_CTRL; |
Carlo Caione | a8abcff | 2019-02-08 17:25:07 +0000 | [diff] [blame] | 362 | phy_write_mmd(phydev, DP83867_DEVADDR, |
| 363 | DP83867_IO_MUX_CFG, val); |
Mugunthan V N | 5b6b18e | 2017-01-24 11:15:40 -0600 | [diff] [blame] | 364 | } |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 365 | } |
| 366 | |
Janine Hagemann | ed51bfc | 2018-08-28 08:25:37 +0200 | [diff] [blame] | 367 | if (dp83867->port_mirroring != DP83867_PORT_MIRRORING_KEEP) |
| 368 | dp83867_config_port_mirroring(phydev); |
| 369 | |
Grygorii Strashko | 1c35b57 | 2019-11-18 23:04:43 +0200 | [diff] [blame] | 370 | /* Clock output selection if muxing property is set */ |
| 371 | if (dp83867->set_clk_output) { |
| 372 | val = phy_read_mmd(phydev, DP83867_DEVADDR, |
| 373 | DP83867_IO_MUX_CFG); |
| 374 | |
| 375 | if (dp83867->clk_output_sel == DP83867_CLK_O_SEL_OFF) { |
| 376 | val |= DP83867_IO_MUX_CFG_CLK_O_DISABLE; |
| 377 | } else { |
| 378 | val &= ~(DP83867_IO_MUX_CFG_CLK_O_SEL_MASK | |
| 379 | DP83867_IO_MUX_CFG_CLK_O_DISABLE); |
| 380 | val |= dp83867->clk_output_sel << |
| 381 | DP83867_IO_MUX_CFG_CLK_O_SEL_SHIFT; |
| 382 | } |
| 383 | phy_write_mmd(phydev, DP83867_DEVADDR, |
| 384 | DP83867_IO_MUX_CFG, val); |
| 385 | } |
| 386 | |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 387 | genphy_config_aneg(phydev); |
| 388 | return 0; |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 389 | |
| 390 | err_out: |
Dan Murphy | 83fbd0a | 2016-05-02 15:45:59 -0500 | [diff] [blame] | 391 | return ret; |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 392 | } |
| 393 | |
Grygorii Strashko | 1d8b552 | 2019-11-18 23:04:41 +0200 | [diff] [blame] | 394 | static int dp83867_probe(struct phy_device *phydev) |
| 395 | { |
| 396 | struct dp83867_private *dp83867; |
| 397 | |
| 398 | dp83867 = kzalloc(sizeof(*dp83867), GFP_KERNEL); |
| 399 | if (!dp83867) |
| 400 | return -ENOMEM; |
| 401 | |
| 402 | phydev->priv = dp83867; |
| 403 | return 0; |
| 404 | } |
| 405 | |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 406 | static struct phy_driver DP83867_driver = { |
| 407 | .name = "TI DP83867", |
| 408 | .uid = 0x2000a231, |
| 409 | .mask = 0xfffffff0, |
| 410 | .features = PHY_GBIT_FEATURES, |
Grygorii Strashko | 1d8b552 | 2019-11-18 23:04:41 +0200 | [diff] [blame] | 411 | .probe = dp83867_probe, |
Edgar E. Iglesias | 8d3ce68 | 2015-09-25 23:46:08 -0700 | [diff] [blame] | 412 | .config = &dp83867_config, |
| 413 | .startup = &genphy_startup, |
| 414 | .shutdown = &genphy_shutdown, |
| 415 | }; |
| 416 | |
| 417 | int phy_ti_init(void) |
| 418 | { |
| 419 | phy_register(&DP83867_driver); |
| 420 | return 0; |
| 421 | } |