blob: d435cc1e6c549d76502cb71abd9958bed6f4d386 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -07002/*
3 * TI PHY drivers
4 *
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -07005 */
6#include <common.h>
Simon Glass0f2af882020-05-10 11:40:05 -06007#include <log.h>
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -07008#include <phy.h>
Simon Glassd66c5f72020-02-03 07:36:15 -07009#include <dm/devres.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060010#include <linux/bitops.h>
Dan Murphy83fbd0a2016-05-02 15:45:59 -050011#include <linux/compat.h>
12#include <malloc.h>
13
Dan Murphy83fbd0a2016-05-02 15:45:59 -050014#include <dm.h>
15#include <dt-bindings/net/ti-dp83867.h>
16
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -070017
18/* TI DP83867 */
19#define DP83867_DEVADDR 0x1f
20
21#define MII_DP83867_PHYCTRL 0x10
22#define MII_DP83867_MICR 0x12
Siva Durga Prasad Paladugu02c7be62016-03-25 12:53:43 +053023#define MII_DP83867_CFG2 0x14
24#define MII_DP83867_BISCR 0x16
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -070025#define DP83867_CTRL 0x1f
26
27/* Extended Registers */
Murali Karicheri9b050762018-06-28 14:26:34 -050028#define DP83867_CFG4 0x0031
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -070029#define DP83867_RGMIICTL 0x0032
Janine Hagemannb3dd2ed2018-08-28 08:25:38 +020030#define DP83867_STRAP_STS1 0x006E
Grygorii Strashko5b2742c2019-11-18 23:04:44 +020031#define DP83867_STRAP_STS2 0x006f
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -070032#define DP83867_RGMIIDCTL 0x0086
Mugunthan V N5b6b18e2017-01-24 11:15:40 -060033#define DP83867_IO_MUX_CFG 0x0170
Michal Simeka3a34702020-02-18 13:51:02 +010034#define DP83867_SGMIICTL 0x00D3
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -070035
36#define DP83867_SW_RESET BIT(15)
37#define DP83867_SW_RESTART BIT(14)
38
39/* MICR Interrupt bits */
40#define MII_DP83867_MICR_AN_ERR_INT_EN BIT(15)
41#define MII_DP83867_MICR_SPEED_CHNG_INT_EN BIT(14)
42#define MII_DP83867_MICR_DUP_MODE_CHNG_INT_EN BIT(13)
43#define MII_DP83867_MICR_PAGE_RXD_INT_EN BIT(12)
44#define MII_DP83867_MICR_AUTONEG_COMP_INT_EN BIT(11)
45#define MII_DP83867_MICR_LINK_STS_CHNG_INT_EN BIT(10)
46#define MII_DP83867_MICR_FALSE_CARRIER_INT_EN BIT(8)
47#define MII_DP83867_MICR_SLEEP_MODE_CHNG_INT_EN BIT(4)
48#define MII_DP83867_MICR_WOL_INT_EN BIT(3)
49#define MII_DP83867_MICR_XGMII_ERR_INT_EN BIT(2)
50#define MII_DP83867_MICR_POL_CHNG_INT_EN BIT(1)
51#define MII_DP83867_MICR_JABBER_INT_EN BIT(0)
52
53/* RGMIICTL bits */
54#define DP83867_RGMII_TX_CLK_DELAY_EN BIT(1)
55#define DP83867_RGMII_RX_CLK_DELAY_EN BIT(0)
56
Janine Hagemannb3dd2ed2018-08-28 08:25:38 +020057/* STRAP_STS1 bits */
58#define DP83867_STRAP_STS1_RESERVED BIT(11)
59
Grygorii Strashko5b2742c2019-11-18 23:04:44 +020060/* STRAP_STS2 bits */
61#define DP83867_STRAP_STS2_CLK_SKEW_TX_MASK GENMASK(6, 4)
62#define DP83867_STRAP_STS2_CLK_SKEW_TX_SHIFT 4
63#define DP83867_STRAP_STS2_CLK_SKEW_RX_MASK GENMASK(2, 0)
64#define DP83867_STRAP_STS2_CLK_SKEW_RX_SHIFT 0
65#define DP83867_STRAP_STS2_CLK_SKEW_NONE BIT(2)
66
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -070067/* PHY CTRL bits */
68#define DP83867_PHYCR_FIFO_DEPTH_SHIFT 14
Grygorii Strashko78492a22019-11-18 23:04:46 +020069#define DP83867_PHYCR_FIFO_DEPTH_MASK GENMASK(15, 14)
Janine Hagemannb3dd2ed2018-08-28 08:25:38 +020070#define DP83867_PHYCR_RESERVED_MASK BIT(11)
Michal Simekc7f95ed2020-02-06 15:59:23 +010071#define DP83867_PHYCR_FORCE_LINK_GOOD BIT(10)
Michal Simekf6459152015-10-19 10:43:30 +020072#define DP83867_MDI_CROSSOVER 5
Siva Durga Prasad Paladugu02c7be62016-03-25 12:53:43 +053073#define DP83867_MDI_CROSSOVER_MDIX 2
74#define DP83867_PHYCTRL_SGMIIEN 0x0800
75#define DP83867_PHYCTRL_RXFIFO_SHIFT 12
76#define DP83867_PHYCTRL_TXFIFO_SHIFT 14
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -070077
78/* RGMIIDCTL bits */
Grygorii Strashko5b2742c2019-11-18 23:04:44 +020079#define DP83867_RGMII_TX_CLK_DELAY_MAX 0xf
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -070080#define DP83867_RGMII_TX_CLK_DELAY_SHIFT 4
Grygorii Strashko5b2742c2019-11-18 23:04:44 +020081#define DP83867_RGMII_RX_CLK_DELAY_MAX 0xf
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -070082
Siva Durga Prasad Paladugu02c7be62016-03-25 12:53:43 +053083/* CFG2 bits */
84#define MII_DP83867_CFG2_SPEEDOPT_10EN 0x0040
85#define MII_DP83867_CFG2_SGMII_AUTONEGEN 0x0080
86#define MII_DP83867_CFG2_SPEEDOPT_ENH 0x0100
87#define MII_DP83867_CFG2_SPEEDOPT_CNT 0x0800
88#define MII_DP83867_CFG2_SPEEDOPT_INTLOW 0x2000
89#define MII_DP83867_CFG2_MASK 0x003F
90
Dan Murphy83fbd0a2016-05-02 15:45:59 -050091/* User setting - can be taken from DTS */
Dan Murphy83fbd0a2016-05-02 15:45:59 -050092#define DEFAULT_FIFO_DEPTH DP83867_PHYCR_FIFO_DEPTH_4_B_NIB
93
Mugunthan V N5b6b18e2017-01-24 11:15:40 -060094/* IO_MUX_CFG bits */
95#define DP83867_IO_MUX_CFG_IO_IMPEDANCE_CTRL 0x1f
96
97#define DP83867_IO_MUX_CFG_IO_IMPEDANCE_MAX 0x0
98#define DP83867_IO_MUX_CFG_IO_IMPEDANCE_MIN 0x1f
Grygorii Strashko1c35b572019-11-18 23:04:43 +020099#define DP83867_IO_MUX_CFG_CLK_O_DISABLE BIT(6)
Janine Hagemann1c2ba092018-08-28 08:25:39 +0200100#define DP83867_IO_MUX_CFG_CLK_O_SEL_SHIFT 8
101#define DP83867_IO_MUX_CFG_CLK_O_SEL_MASK \
102 GENMASK(0x1f, DP83867_IO_MUX_CFG_CLK_O_SEL_SHIFT)
Mugunthan V N5b6b18e2017-01-24 11:15:40 -0600103
Janine Hagemanned51bfc2018-08-28 08:25:37 +0200104/* CFG4 bits */
105#define DP83867_CFG4_PORT_MIRROR_EN BIT(0)
106
Michal Simeka3a34702020-02-18 13:51:02 +0100107/* SGMIICTL bits */
108#define DP83867_SGMII_TYPE BIT(14)
109
Janine Hagemanned51bfc2018-08-28 08:25:37 +0200110enum {
111 DP83867_PORT_MIRRORING_KEEP,
112 DP83867_PORT_MIRRORING_EN,
113 DP83867_PORT_MIRRORING_DIS,
114};
115
Dan Murphy83fbd0a2016-05-02 15:45:59 -0500116struct dp83867_private {
Grygorii Strashko5b2742c2019-11-18 23:04:44 +0200117 u32 rx_id_delay;
118 u32 tx_id_delay;
Dan Murphy83fbd0a2016-05-02 15:45:59 -0500119 int fifo_depth;
Mugunthan V N5b6b18e2017-01-24 11:15:40 -0600120 int io_impedance;
Murali Karicheri9b050762018-06-28 14:26:34 -0500121 bool rxctrl_strap_quirk;
Janine Hagemanned51bfc2018-08-28 08:25:37 +0200122 int port_mirroring;
Grygorii Strashko1c35b572019-11-18 23:04:43 +0200123 bool set_clk_output;
Trent Piephob0a86e52019-05-10 17:49:08 +0000124 unsigned int clk_output_sel;
Michal Simeka3a34702020-02-18 13:51:02 +0100125 bool sgmii_ref_clk_en;
Dan Murphy83fbd0a2016-05-02 15:45:59 -0500126};
127
Janine Hagemanned51bfc2018-08-28 08:25:37 +0200128static int dp83867_config_port_mirroring(struct phy_device *phydev)
129{
130 struct dp83867_private *dp83867 =
131 (struct dp83867_private *)phydev->priv;
132 u16 val;
133
Carlo Caionea8abcff2019-02-08 17:25:07 +0000134 val = phy_read_mmd(phydev, DP83867_DEVADDR, DP83867_CFG4);
Janine Hagemanned51bfc2018-08-28 08:25:37 +0200135
136 if (dp83867->port_mirroring == DP83867_PORT_MIRRORING_EN)
137 val |= DP83867_CFG4_PORT_MIRROR_EN;
138 else
139 val &= ~DP83867_CFG4_PORT_MIRROR_EN;
140
Carlo Caionea8abcff2019-02-08 17:25:07 +0000141 phy_write_mmd(phydev, DP83867_DEVADDR, DP83867_CFG4, val);
Janine Hagemanned51bfc2018-08-28 08:25:37 +0200142
143 return 0;
144}
145
Dan Murphy83fbd0a2016-05-02 15:45:59 -0500146#if defined(CONFIG_DM_ETH)
147/**
148 * dp83867_data_init - Convenience function for setting PHY specific data
149 *
150 * @phydev: the phy_device struct
151 */
152static int dp83867_of_init(struct phy_device *phydev)
153{
154 struct dp83867_private *dp83867 = phydev->priv;
Grygorii Strashko00e2c242018-07-05 12:02:49 -0500155 ofnode node;
Grygorii Strashko1c35b572019-11-18 23:04:43 +0200156 int ret;
Janine Hagemann1c2ba092018-08-28 08:25:39 +0200157
Michal Simek8e102a82019-03-16 12:43:17 +0100158 node = phy_get_ofnode(phydev);
159 if (!ofnode_valid(node))
160 return -EINVAL;
161
Grygorii Strashko1c35b572019-11-18 23:04:43 +0200162 /* Optional configuration */
163 ret = ofnode_read_u32(node, "ti,clk-output-sel",
164 &dp83867->clk_output_sel);
165 /* If not set, keep default */
166 if (!ret) {
167 dp83867->set_clk_output = true;
168 /* Valid values are 0 to DP83867_CLK_O_SEL_REF_CLK or
169 * DP83867_CLK_O_SEL_OFF.
170 */
171 if (dp83867->clk_output_sel > DP83867_CLK_O_SEL_REF_CLK &&
172 dp83867->clk_output_sel != DP83867_CLK_O_SEL_OFF) {
173 pr_debug("ti,clk-output-sel value %u out of range\n",
174 dp83867->clk_output_sel);
175 return -EINVAL;
176 }
177 }
Grygorii Strashko00e2c242018-07-05 12:02:49 -0500178
Grygorii Strashko9df35052018-06-28 14:26:35 -0500179 if (ofnode_read_bool(node, "ti,max-output-impedance"))
Mugunthan V N5b6b18e2017-01-24 11:15:40 -0600180 dp83867->io_impedance = DP83867_IO_MUX_CFG_IO_IMPEDANCE_MAX;
Grygorii Strashko9df35052018-06-28 14:26:35 -0500181 else if (ofnode_read_bool(node, "ti,min-output-impedance"))
Mugunthan V N5b6b18e2017-01-24 11:15:40 -0600182 dp83867->io_impedance = DP83867_IO_MUX_CFG_IO_IMPEDANCE_MIN;
183 else
184 dp83867->io_impedance = -EINVAL;
Dan Murphy83fbd0a2016-05-02 15:45:59 -0500185
Grygorii Strashko9df35052018-06-28 14:26:35 -0500186 if (ofnode_read_bool(node, "ti,dp83867-rxctrl-strap-quirk"))
Murali Karicheri9b050762018-06-28 14:26:34 -0500187 dp83867->rxctrl_strap_quirk = true;
Grygorii Strashko5b2742c2019-11-18 23:04:44 +0200188
189 /* Existing behavior was to use default pin strapping delay in rgmii
190 * mode, but rgmii should have meant no delay. Warn existing users.
191 */
192 if (phydev->interface == PHY_INTERFACE_MODE_RGMII) {
193 u16 val = phy_read_mmd(phydev, DP83867_DEVADDR,
194 DP83867_STRAP_STS2);
195 u16 txskew = (val & DP83867_STRAP_STS2_CLK_SKEW_TX_MASK) >>
196 DP83867_STRAP_STS2_CLK_SKEW_TX_SHIFT;
197 u16 rxskew = (val & DP83867_STRAP_STS2_CLK_SKEW_RX_MASK) >>
198 DP83867_STRAP_STS2_CLK_SKEW_RX_SHIFT;
Dan Murphy83fbd0a2016-05-02 15:45:59 -0500199
Grygorii Strashko5b2742c2019-11-18 23:04:44 +0200200 if (txskew != DP83867_STRAP_STS2_CLK_SKEW_NONE ||
201 rxskew != DP83867_STRAP_STS2_CLK_SKEW_NONE)
202 pr_warn("PHY has delays via pin strapping, but phy-mode = 'rgmii'\n"
203 "Should be 'rgmii-id' to use internal delays\n");
204 }
205
206 /* RX delay *must* be specified if internal delay of RX is used. */
207 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
208 phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) {
209 ret = ofnode_read_u32(node, "ti,rx-internal-delay",
210 &dp83867->rx_id_delay);
211 if (ret) {
212 pr_debug("ti,rx-internal-delay must be specified\n");
213 return ret;
214 }
215 if (dp83867->rx_id_delay > DP83867_RGMII_RX_CLK_DELAY_MAX) {
216 pr_debug("ti,rx-internal-delay value of %u out of range\n",
217 dp83867->rx_id_delay);
218 return -EINVAL;
219 }
220 }
221
222 /* TX delay *must* be specified if internal delay of RX is used. */
223 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
224 phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) {
225 ret = ofnode_read_u32(node, "ti,tx-internal-delay",
226 &dp83867->tx_id_delay);
227 if (ret) {
228 debug("ti,tx-internal-delay must be specified\n");
229 return ret;
230 }
231 if (dp83867->tx_id_delay > DP83867_RGMII_TX_CLK_DELAY_MAX) {
232 pr_debug("ti,tx-internal-delay value of %u out of range\n",
233 dp83867->tx_id_delay);
234 return -EINVAL;
235 }
236 }
Dan Murphy83fbd0a2016-05-02 15:45:59 -0500237
Grygorii Strashko9df35052018-06-28 14:26:35 -0500238 dp83867->fifo_depth = ofnode_read_u32_default(node, "ti,fifo-depth",
Trent Piepho19d7aee2019-05-09 19:41:51 +0000239 DEFAULT_FIFO_DEPTH);
Janine Hagemanned51bfc2018-08-28 08:25:37 +0200240 if (ofnode_read_bool(node, "enet-phy-lane-swap"))
241 dp83867->port_mirroring = DP83867_PORT_MIRRORING_EN;
242
243 if (ofnode_read_bool(node, "enet-phy-lane-no-swap"))
244 dp83867->port_mirroring = DP83867_PORT_MIRRORING_DIS;
245
Michal Simeka3a34702020-02-18 13:51:02 +0100246 if (ofnode_read_bool(node, "ti,sgmii-ref-clock-output-enable"))
247 dp83867->sgmii_ref_clk_en = true;
248
Dan Murphy83fbd0a2016-05-02 15:45:59 -0500249 return 0;
250}
251#else
252static int dp83867_of_init(struct phy_device *phydev)
253{
254 struct dp83867_private *dp83867 = phydev->priv;
255
Grygorii Strashko5b2742c2019-11-18 23:04:44 +0200256 dp83867->rx_id_delay = DP83867_RGMIIDCTL_2_25_NS;
257 dp83867->tx_id_delay = DP83867_RGMIIDCTL_2_75_NS;
Dan Murphy83fbd0a2016-05-02 15:45:59 -0500258 dp83867->fifo_depth = DEFAULT_FIFO_DEPTH;
Mugunthan V N5b6b18e2017-01-24 11:15:40 -0600259 dp83867->io_impedance = -EINVAL;
Dan Murphy83fbd0a2016-05-02 15:45:59 -0500260
261 return 0;
262}
263#endif
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -0700264
265static int dp83867_config(struct phy_device *phydev)
266{
Dan Murphy83fbd0a2016-05-02 15:45:59 -0500267 struct dp83867_private *dp83867;
Siva Durga Prasad Paladugu02c7be62016-03-25 12:53:43 +0530268 unsigned int val, delay, cfg2;
Janine Hagemannb3dd2ed2018-08-28 08:25:38 +0200269 int ret, bs;
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -0700270
Grygorii Strashko1d8b5522019-11-18 23:04:41 +0200271 dp83867 = (struct dp83867_private *)phydev->priv;
Dan Murphy83fbd0a2016-05-02 15:45:59 -0500272
Grygorii Strashko1d8b5522019-11-18 23:04:41 +0200273 ret = dp83867_of_init(phydev);
274 if (ret)
275 return ret;
Dan Murphy83fbd0a2016-05-02 15:45:59 -0500276
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -0700277 /* Restart the PHY. */
278 val = phy_read(phydev, MDIO_DEVAD_NONE, DP83867_CTRL);
279 phy_write(phydev, MDIO_DEVAD_NONE, DP83867_CTRL,
280 val | DP83867_SW_RESTART);
281
Murali Karicheri9b050762018-06-28 14:26:34 -0500282 /* Mode 1 or 2 workaround */
283 if (dp83867->rxctrl_strap_quirk) {
Carlo Caionea8abcff2019-02-08 17:25:07 +0000284 val = phy_read_mmd(phydev, DP83867_DEVADDR,
285 DP83867_CFG4);
Murali Karicheri9b050762018-06-28 14:26:34 -0500286 val &= ~BIT(7);
Carlo Caionea8abcff2019-02-08 17:25:07 +0000287 phy_write_mmd(phydev, DP83867_DEVADDR,
288 DP83867_CFG4, val);
Murali Karicheri9b050762018-06-28 14:26:34 -0500289 }
290
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -0700291 if (phy_interface_is_rgmii(phydev)) {
Grygorii Strashko78492a22019-11-18 23:04:46 +0200292 val = phy_read(phydev, MDIO_DEVAD_NONE, MII_DP83867_PHYCTRL);
293 if (val < 0)
Dan Murphy83fbd0a2016-05-02 15:45:59 -0500294 goto err_out;
Grygorii Strashko78492a22019-11-18 23:04:46 +0200295 val &= ~DP83867_PHYCR_FIFO_DEPTH_MASK;
296 val |= (dp83867->fifo_depth << DP83867_PHYCR_FIFO_DEPTH_SHIFT);
Janine Hagemannb3dd2ed2018-08-28 08:25:38 +0200297
Michal Simekc7f95ed2020-02-06 15:59:23 +0100298 /* Do not force link good */
299 val &= ~DP83867_PHYCR_FORCE_LINK_GOOD;
300
Janine Hagemannb3dd2ed2018-08-28 08:25:38 +0200301 /* The code below checks if "port mirroring" N/A MODE4 has been
302 * enabled during power on bootstrap.
303 *
304 * Such N/A mode enabled by mistake can put PHY IC in some
305 * internal testing mode and disable RGMII transmission.
306 *
307 * In this particular case one needs to check STRAP_STS1
308 * register's bit 11 (marked as RESERVED).
309 */
310
Grygorii Strashko78492a22019-11-18 23:04:46 +0200311 bs = phy_read_mmd(phydev, DP83867_DEVADDR, DP83867_STRAP_STS1);
312 if (bs & DP83867_STRAP_STS1_RESERVED)
Janine Hagemannb3dd2ed2018-08-28 08:25:38 +0200313 val &= ~DP83867_PHYCR_RESERVED_MASK;
Grygorii Strashko78492a22019-11-18 23:04:46 +0200314
315 ret = phy_write(phydev, MDIO_DEVAD_NONE,
316 MII_DP83867_PHYCTRL, val);
317
318 val = phy_read_mmd(phydev, DP83867_DEVADDR,
319 DP83867_RGMIICTL);
320
321 val &= ~(DP83867_RGMII_TX_CLK_DELAY_EN |
322 DP83867_RGMII_RX_CLK_DELAY_EN);
323 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID)
324 val |= (DP83867_RGMII_TX_CLK_DELAY_EN |
325 DP83867_RGMII_RX_CLK_DELAY_EN);
326
327 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
328 val |= DP83867_RGMII_TX_CLK_DELAY_EN;
329
330 if (phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID)
331 val |= DP83867_RGMII_RX_CLK_DELAY_EN;
332
333 phy_write_mmd(phydev, DP83867_DEVADDR, DP83867_RGMIICTL, val);
334
335 delay = (dp83867->rx_id_delay |
336 (dp83867->tx_id_delay <<
337 DP83867_RGMII_TX_CLK_DELAY_SHIFT));
338
339 phy_write_mmd(phydev, DP83867_DEVADDR,
340 DP83867_RGMIIDCTL, delay);
341 }
Janine Hagemannb3dd2ed2018-08-28 08:25:38 +0200342
Grygorii Strashko78492a22019-11-18 23:04:46 +0200343 if (phy_interface_is_sgmii(phydev)) {
Michal Simeka3a34702020-02-18 13:51:02 +0100344 if (dp83867->sgmii_ref_clk_en)
345 phy_write_mmd(phydev, DP83867_DEVADDR, DP83867_SGMIICTL,
346 DP83867_SGMII_TYPE);
347
Siva Durga Prasad Paladugu02c7be62016-03-25 12:53:43 +0530348 phy_write(phydev, MDIO_DEVAD_NONE, MII_BMCR,
349 (BMCR_ANENABLE | BMCR_FULLDPLX | BMCR_SPEED1000));
350
351 cfg2 = phy_read(phydev, phydev->addr, MII_DP83867_CFG2);
352 cfg2 &= MII_DP83867_CFG2_MASK;
353 cfg2 |= (MII_DP83867_CFG2_SPEEDOPT_10EN |
354 MII_DP83867_CFG2_SGMII_AUTONEGEN |
355 MII_DP83867_CFG2_SPEEDOPT_ENH |
356 MII_DP83867_CFG2_SPEEDOPT_CNT |
357 MII_DP83867_CFG2_SPEEDOPT_INTLOW);
358 phy_write(phydev, MDIO_DEVAD_NONE, MII_DP83867_CFG2, cfg2);
359
Carlo Caionea8abcff2019-02-08 17:25:07 +0000360 phy_write_mmd(phydev, DP83867_DEVADDR,
361 DP83867_RGMIICTL, 0x0);
Siva Durga Prasad Paladugu02c7be62016-03-25 12:53:43 +0530362
363 phy_write(phydev, MDIO_DEVAD_NONE, MII_DP83867_PHYCTRL,
364 DP83867_PHYCTRL_SGMIIEN |
365 (DP83867_MDI_CROSSOVER_MDIX <<
366 DP83867_MDI_CROSSOVER) |
Dan Murphy83fbd0a2016-05-02 15:45:59 -0500367 (dp83867->fifo_depth << DP83867_PHYCTRL_RXFIFO_SHIFT) |
368 (dp83867->fifo_depth << DP83867_PHYCTRL_TXFIFO_SHIFT));
Siva Durga Prasad Paladugu02c7be62016-03-25 12:53:43 +0530369 phy_write(phydev, MDIO_DEVAD_NONE, MII_DP83867_BISCR, 0x0);
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -0700370 }
371
Grygorii Strashko38432512019-11-18 23:04:45 +0200372 if (dp83867->io_impedance >= 0) {
373 val = phy_read_mmd(phydev,
374 DP83867_DEVADDR,
375 DP83867_IO_MUX_CFG);
376 val &= ~DP83867_IO_MUX_CFG_IO_IMPEDANCE_CTRL;
377 val |= dp83867->io_impedance &
378 DP83867_IO_MUX_CFG_IO_IMPEDANCE_CTRL;
379 phy_write_mmd(phydev, DP83867_DEVADDR,
380 DP83867_IO_MUX_CFG, val);
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -0700381 }
382
Janine Hagemanned51bfc2018-08-28 08:25:37 +0200383 if (dp83867->port_mirroring != DP83867_PORT_MIRRORING_KEEP)
384 dp83867_config_port_mirroring(phydev);
385
Grygorii Strashko1c35b572019-11-18 23:04:43 +0200386 /* Clock output selection if muxing property is set */
387 if (dp83867->set_clk_output) {
388 val = phy_read_mmd(phydev, DP83867_DEVADDR,
389 DP83867_IO_MUX_CFG);
390
391 if (dp83867->clk_output_sel == DP83867_CLK_O_SEL_OFF) {
392 val |= DP83867_IO_MUX_CFG_CLK_O_DISABLE;
393 } else {
394 val &= ~(DP83867_IO_MUX_CFG_CLK_O_SEL_MASK |
395 DP83867_IO_MUX_CFG_CLK_O_DISABLE);
396 val |= dp83867->clk_output_sel <<
397 DP83867_IO_MUX_CFG_CLK_O_SEL_SHIFT;
398 }
399 phy_write_mmd(phydev, DP83867_DEVADDR,
400 DP83867_IO_MUX_CFG, val);
401 }
402
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -0700403 genphy_config_aneg(phydev);
404 return 0;
Dan Murphy83fbd0a2016-05-02 15:45:59 -0500405
406err_out:
Dan Murphy83fbd0a2016-05-02 15:45:59 -0500407 return ret;
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -0700408}
409
Grygorii Strashko1d8b5522019-11-18 23:04:41 +0200410static int dp83867_probe(struct phy_device *phydev)
411{
412 struct dp83867_private *dp83867;
413
414 dp83867 = kzalloc(sizeof(*dp83867), GFP_KERNEL);
415 if (!dp83867)
416 return -ENOMEM;
417
418 phydev->priv = dp83867;
419 return 0;
420}
421
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -0700422static struct phy_driver DP83867_driver = {
423 .name = "TI DP83867",
424 .uid = 0x2000a231,
425 .mask = 0xfffffff0,
426 .features = PHY_GBIT_FEATURES,
Grygorii Strashko1d8b5522019-11-18 23:04:41 +0200427 .probe = dp83867_probe,
Edgar E. Iglesias8d3ce682015-09-25 23:46:08 -0700428 .config = &dp83867_config,
429 .startup = &genphy_startup,
430 .shutdown = &genphy_shutdown,
431};
432
433int phy_ti_init(void)
434{
435 phy_register(&DP83867_driver);
436 return 0;
437}