blob: 552592bb44edc91e375e0393a55d504fad065b64 [file] [log] [blame]
Andy Fleming60ca78b2011-04-07 21:56:05 -05001/*
2 * Micrel PHY drivers
3 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Andy Fleming60ca78b2011-04-07 21:56:05 -05005 *
6 * Copyright 2010-2011 Freescale Semiconductor, Inc.
7 * author Andy Fleming
David Andreyf0d83c42013-02-06 22:18:37 +01008 * (C) 2012 NetModule AG, David Andrey, added KSZ9031
Andy Fleming60ca78b2011-04-07 21:56:05 -05009 */
Troy Kisky80b6b092012-02-07 14:08:48 +000010#include <config.h>
11#include <common.h>
Marek Vasut1005ce52015-12-05 17:41:58 +010012#include <dm.h>
13#include <errno.h>
14#include <fdtdec.h>
Troy Kisky80b6b092012-02-07 14:08:48 +000015#include <micrel.h>
Andy Fleming60ca78b2011-04-07 21:56:05 -050016#include <phy.h>
17
Marek Vasut1005ce52015-12-05 17:41:58 +010018DECLARE_GLOBAL_DATA_PTR;
19
Andy Fleming60ca78b2011-04-07 21:56:05 -050020static struct phy_driver KSZ804_driver = {
21 .name = "Micrel KSZ804",
22 .uid = 0x221510,
23 .mask = 0xfffff0,
24 .features = PHY_BASIC_FEATURES,
25 .config = &genphy_config,
26 .startup = &genphy_startup,
27 .shutdown = &genphy_shutdown,
28};
29
Alexandre Messier94bde102016-01-22 14:06:33 -050030#define MII_KSZPHY_OMSO 0x16
31#define KSZPHY_OMSO_B_CAST_OFF (1 << 9)
32
33static int ksz_genconfig_bcastoff(struct phy_device *phydev)
34{
35 int ret;
36
37 ret = phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZPHY_OMSO);
38 if (ret < 0)
39 return ret;
40
41 ret = phy_write(phydev, MDIO_DEVAD_NONE, MII_KSZPHY_OMSO,
42 ret | KSZPHY_OMSO_B_CAST_OFF);
43 if (ret < 0)
44 return ret;
45
46 return genphy_config(phydev);
47}
48
Sylvain Lemieuxbd8d3002015-09-09 16:29:51 -040049static struct phy_driver KSZ8031_driver = {
50 .name = "Micrel KSZ8021/KSZ8031",
51 .uid = 0x221550,
52 .mask = 0xfffff0,
53 .features = PHY_BASIC_FEATURES,
Alexandre Messier94bde102016-01-22 14:06:33 -050054 .config = &ksz_genconfig_bcastoff,
Sylvain Lemieuxbd8d3002015-09-09 16:29:51 -040055 .startup = &genphy_startup,
56 .shutdown = &genphy_shutdown,
57};
58
Sylvain Rochet23e9d5c2015-10-07 22:54:22 +020059/**
60 * KSZ8051
61 */
62#define MII_KSZ8051_PHY_OMSO 0x16
63#define MII_KSZ8051_PHY_OMSO_NAND_TREE_ON (1 << 5)
64
65static int ksz8051_config(struct phy_device *phydev)
66{
67 unsigned val;
68
69 /* Disable NAND-tree */
70 val = phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZ8051_PHY_OMSO);
71 val &= ~MII_KSZ8051_PHY_OMSO_NAND_TREE_ON;
72 phy_write(phydev, MDIO_DEVAD_NONE, MII_KSZ8051_PHY_OMSO, val);
73
74 return genphy_config(phydev);
75}
76
77static struct phy_driver KSZ8051_driver = {
78 .name = "Micrel KSZ8051",
79 .uid = 0x221550,
80 .mask = 0xfffff0,
81 .features = PHY_BASIC_FEATURES,
82 .config = &ksz8051_config,
83 .startup = &genphy_startup,
84 .shutdown = &genphy_shutdown,
85};
86
Luca Elleroadeb9ea2015-03-24 11:32:24 +010087static struct phy_driver KSZ8081_driver = {
88 .name = "Micrel KSZ8081",
89 .uid = 0x221560,
90 .mask = 0xfffff0,
91 .features = PHY_BASIC_FEATURES,
Alexandre Messier94bde102016-01-22 14:06:33 -050092 .config = &ksz_genconfig_bcastoff,
Luca Elleroadeb9ea2015-03-24 11:32:24 +010093 .startup = &genphy_startup,
94 .shutdown = &genphy_shutdown,
95};
96
Philippe De Muyter2616b212014-02-19 17:21:59 +010097/**
98 * KSZ8895
99 */
100
101static unsigned short smireg_to_phy(unsigned short reg)
102{
103 return ((reg & 0xc0) >> 3) + 0x06 + ((reg & 0x20) >> 5);
104}
105
106static unsigned short smireg_to_reg(unsigned short reg)
107{
108 return reg & 0x1F;
109}
110
111static void ksz8895_write_smireg(struct phy_device *phydev, int smireg, int val)
112{
113 phydev->bus->write(phydev->bus, smireg_to_phy(smireg), MDIO_DEVAD_NONE,
114 smireg_to_reg(smireg), val);
115}
116
117#if 0
118static int ksz8895_read_smireg(struct phy_device *phydev, int smireg)
119{
120 return phydev->bus->read(phydev->bus, smireg_to_phy(smireg),
121 MDIO_DEVAD_NONE, smireg_to_reg(smireg));
122}
123#endif
124
125int ksz8895_config(struct phy_device *phydev)
126{
127 /* we are connected directly to the switch without
128 * dedicated PHY. SCONF1 == 001 */
129 phydev->link = 1;
130 phydev->duplex = DUPLEX_FULL;
131 phydev->speed = SPEED_100;
132
133 /* Force the switch to start */
134 ksz8895_write_smireg(phydev, 1, 1);
135
136 return 0;
137}
138
139static int ksz8895_startup(struct phy_device *phydev)
140{
141 return 0;
142}
143
144static struct phy_driver ksz8895_driver = {
145 .name = "Micrel KSZ8895/KSZ8864",
146 .uid = 0x221450,
147 .mask = 0xffffe1,
148 .features = PHY_BASIC_FEATURES,
149 .config = &ksz8895_config,
150 .startup = &ksz8895_startup,
151 .shutdown = &genphy_shutdown,
152};
153
Troy Kiskyb4fd97f2012-06-28 08:00:28 +0000154#ifndef CONFIG_PHY_MICREL_KSZ9021
155/*
156 * I can't believe Micrel used the exact same part number
Pavel Machek5f022112014-09-09 14:26:51 +0200157 * for the KSZ9021. Shame Micrel, Shame!
Troy Kiskyb4fd97f2012-06-28 08:00:28 +0000158 */
Vladimir Zapolskiya4baa582011-12-06 02:47:57 +0000159static struct phy_driver KS8721_driver = {
160 .name = "Micrel KS8721BL",
161 .uid = 0x221610,
162 .mask = 0xfffff0,
163 .features = PHY_BASIC_FEATURES,
164 .config = &genphy_config,
165 .startup = &genphy_startup,
166 .shutdown = &genphy_shutdown,
167};
Troy Kiskyb4fd97f2012-06-28 08:00:28 +0000168#endif
Vladimir Zapolskiya4baa582011-12-06 02:47:57 +0000169
David Andreyf0d83c42013-02-06 22:18:37 +0100170
Pavel Machek5f022112014-09-09 14:26:51 +0200171/*
David Andreyf0d83c42013-02-06 22:18:37 +0100172 * KSZ9021 - KSZ9031 common
173 */
174
175#define MII_KSZ90xx_PHY_CTL 0x1f
176#define MIIM_KSZ90xx_PHYCTL_1000 (1 << 6)
177#define MIIM_KSZ90xx_PHYCTL_100 (1 << 5)
178#define MIIM_KSZ90xx_PHYCTL_10 (1 << 4)
179#define MIIM_KSZ90xx_PHYCTL_DUPLEX (1 << 3)
180
181static int ksz90xx_startup(struct phy_device *phydev)
182{
183 unsigned phy_ctl;
Michal Simek5ff89662016-05-18 12:46:12 +0200184 int ret;
185
186 ret = genphy_update_link(phydev);
187 if (ret)
188 return ret;
189
David Andreyf0d83c42013-02-06 22:18:37 +0100190 phy_ctl = phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZ90xx_PHY_CTL);
191
192 if (phy_ctl & MIIM_KSZ90xx_PHYCTL_DUPLEX)
193 phydev->duplex = DUPLEX_FULL;
194 else
195 phydev->duplex = DUPLEX_HALF;
196
197 if (phy_ctl & MIIM_KSZ90xx_PHYCTL_1000)
198 phydev->speed = SPEED_1000;
199 else if (phy_ctl & MIIM_KSZ90xx_PHYCTL_100)
200 phydev->speed = SPEED_100;
201 else if (phy_ctl & MIIM_KSZ90xx_PHYCTL_10)
202 phydev->speed = SPEED_10;
203 return 0;
204}
David Andreyf0d83c42013-02-06 22:18:37 +0100205
Marek Vasut1005ce52015-12-05 17:41:58 +0100206/* Common OF config bits for KSZ9021 and KSZ9031 */
207#if defined(CONFIG_PHY_MICREL_KSZ9021) || defined(CONFIG_PHY_MICREL_KSZ9031)
208#ifdef CONFIG_DM_ETH
209struct ksz90x1_reg_field {
210 const char *name;
211 const u8 size; /* Size of the bitfield, in bits */
212 const u8 off; /* Offset from bit 0 */
213 const u8 dflt; /* Default value */
214};
215
216struct ksz90x1_ofcfg {
217 const u16 reg;
218 const u16 devad;
219 const struct ksz90x1_reg_field *grp;
220 const u16 grpsz;
221};
222
223static const struct ksz90x1_reg_field ksz90x1_rxd_grp[] = {
224 { "rxd0-skew-ps", 4, 0, 0x7 }, { "rxd1-skew-ps", 4, 4, 0x7 },
225 { "rxd2-skew-ps", 4, 8, 0x7 }, { "rxd3-skew-ps", 4, 12, 0x7 }
226};
227
228static const struct ksz90x1_reg_field ksz90x1_txd_grp[] = {
229 { "txd0-skew-ps", 4, 0, 0x7 }, { "txd1-skew-ps", 4, 4, 0x7 },
230 { "txd2-skew-ps", 4, 8, 0x7 }, { "txd3-skew-ps", 4, 12, 0x7 },
231};
232
233static int ksz90x1_of_config_group(struct phy_device *phydev,
234 struct ksz90x1_ofcfg *ofcfg)
235{
236 struct udevice *dev = phydev->dev;
237 struct phy_driver *drv = phydev->drv;
Dinh Nguyen826df7a2016-01-27 15:46:00 -0600238 const int ps_to_regval = 60;
Marek Vasut1005ce52015-12-05 17:41:58 +0100239 int val[4];
240 int i, changed = 0, offset, max;
241 u16 regval = 0;
242
243 if (!drv || !drv->writeext)
244 return -EOPNOTSUPP;
245
246 for (i = 0; i < ofcfg->grpsz; i++) {
Simon Glassdd79d6e2017-01-17 16:52:55 -0700247 val[i] = fdtdec_get_uint(gd->fdt_blob, dev_of_offset(dev),
Marek Vasut1005ce52015-12-05 17:41:58 +0100248 ofcfg->grp[i].name, -1);
249 offset = ofcfg->grp[i].off;
250 if (val[i] == -1) {
251 /* Default register value for KSZ9021 */
252 regval |= ofcfg->grp[i].dflt << offset;
253 } else {
254 changed = 1; /* Value was changed in OF */
255 /* Calculate the register value and fix corner cases */
256 if (val[i] > ps_to_regval * 0xf) {
257 max = (1 << ofcfg->grp[i].size) - 1;
258 regval |= max << offset;
259 } else {
260 regval |= (val[i] / ps_to_regval) << offset;
261 }
262 }
263 }
264
265 if (!changed)
266 return 0;
267
268 return drv->writeext(phydev, 0, ofcfg->devad, ofcfg->reg, regval);
269}
270#endif
271#endif
272
Pavel Machek5f022112014-09-09 14:26:51 +0200273#ifdef CONFIG_PHY_MICREL_KSZ9021
David Andreyf0d83c42013-02-06 22:18:37 +0100274/*
275 * KSZ9021
276 */
277
278/* PHY Registers */
Troy Kisky80b6b092012-02-07 14:08:48 +0000279#define MII_KSZ9021_EXTENDED_CTRL 0x0b
280#define MII_KSZ9021_EXTENDED_DATAW 0x0c
281#define MII_KSZ9021_EXTENDED_DATAR 0x0d
Troy Kisky80b6b092012-02-07 14:08:48 +0000282
283#define CTRL1000_PREFER_MASTER (1 << 10)
284#define CTRL1000_CONFIG_MASTER (1 << 11)
285#define CTRL1000_MANUAL_CONFIG (1 << 12)
286
Mugunthan V Ncbd7daa2016-02-02 15:51:32 +0530287#if defined(CONFIG_DM_ETH) && (defined(CONFIG_PHY_MICREL_KSZ9021) || \
288 defined(CONFIG_PHY_MICREL_KSZ9031))
Marek Vasut1005ce52015-12-05 17:41:58 +0100289static const struct ksz90x1_reg_field ksz9021_clk_grp[] = {
290 { "txen-skew-ps", 4, 0, 0x7 }, { "txc-skew-ps", 4, 4, 0x7 },
291 { "rxdv-skew-ps", 4, 8, 0x7 }, { "rxc-skew-ps", 4, 12, 0x7 },
292};
293
294static int ksz9021_of_config(struct phy_device *phydev)
295{
296 struct ksz90x1_ofcfg ofcfg[] = {
297 { MII_KSZ9021_EXT_RGMII_RX_DATA_SKEW, 0, ksz90x1_rxd_grp, 4 },
298 { MII_KSZ9021_EXT_RGMII_TX_DATA_SKEW, 0, ksz90x1_txd_grp, 4 },
299 { MII_KSZ9021_EXT_RGMII_CLOCK_SKEW, 0, ksz9021_clk_grp, 4 },
300 };
301 int i, ret = 0;
302
Marek Vasut0c766302016-11-14 15:08:42 +0100303 for (i = 0; i < ARRAY_SIZE(ofcfg); i++) {
Marek Vasut1005ce52015-12-05 17:41:58 +0100304 ret = ksz90x1_of_config_group(phydev, &(ofcfg[i]));
305 if (ret)
306 return ret;
Marek Vasut0c766302016-11-14 15:08:42 +0100307 }
Marek Vasut1005ce52015-12-05 17:41:58 +0100308
309 return 0;
310}
311#else
312static int ksz9021_of_config(struct phy_device *phydev)
313{
314 return 0;
315}
316#endif
317
Troy Kisky80b6b092012-02-07 14:08:48 +0000318int ksz9021_phy_extended_write(struct phy_device *phydev, int regnum, u16 val)
319{
320 /* extended registers */
321 phy_write(phydev, MDIO_DEVAD_NONE,
322 MII_KSZ9021_EXTENDED_CTRL, regnum | 0x8000);
323 return phy_write(phydev, MDIO_DEVAD_NONE,
324 MII_KSZ9021_EXTENDED_DATAW, val);
325}
326
327int ksz9021_phy_extended_read(struct phy_device *phydev, int regnum)
328{
329 /* extended registers */
330 phy_write(phydev, MDIO_DEVAD_NONE, MII_KSZ9021_EXTENDED_CTRL, regnum);
331 return phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZ9021_EXTENDED_DATAR);
332}
333
Stefano Babica8aa2992013-09-02 15:42:31 +0200334
335static int ksz9021_phy_extread(struct phy_device *phydev, int addr, int devaddr,
336 int regnum)
337{
338 return ksz9021_phy_extended_read(phydev, regnum);
339}
340
341static int ksz9021_phy_extwrite(struct phy_device *phydev, int addr,
342 int devaddr, int regnum, u16 val)
343{
344 return ksz9021_phy_extended_write(phydev, regnum, val);
345}
346
Troy Kisky80b6b092012-02-07 14:08:48 +0000347/* Micrel ksz9021 */
348static int ksz9021_config(struct phy_device *phydev)
349{
350 unsigned ctrl1000 = 0;
351 const unsigned master = CTRL1000_PREFER_MASTER |
352 CTRL1000_CONFIG_MASTER | CTRL1000_MANUAL_CONFIG;
353 unsigned features = phydev->drv->features;
Marek Vasut1005ce52015-12-05 17:41:58 +0100354 int ret;
355
356 ret = ksz9021_of_config(phydev);
357 if (ret)
358 return ret;
Troy Kisky80b6b092012-02-07 14:08:48 +0000359
360 if (getenv("disable_giga"))
361 features &= ~(SUPPORTED_1000baseT_Half |
362 SUPPORTED_1000baseT_Full);
363 /* force master mode for 1000BaseT due to chip errata */
364 if (features & SUPPORTED_1000baseT_Half)
365 ctrl1000 |= ADVERTISE_1000HALF | master;
366 if (features & SUPPORTED_1000baseT_Full)
367 ctrl1000 |= ADVERTISE_1000FULL | master;
Alexandru Gagniuc757bb672017-07-07 11:36:57 -0700368 phydev->advertising = features;
369 phydev->supported = features;
Troy Kisky80b6b092012-02-07 14:08:48 +0000370 phy_write(phydev, MDIO_DEVAD_NONE, MII_CTRL1000, ctrl1000);
371 genphy_config_aneg(phydev);
372 genphy_restart_aneg(phydev);
373 return 0;
374}
375
Troy Kisky80b6b092012-02-07 14:08:48 +0000376static struct phy_driver ksz9021_driver = {
377 .name = "Micrel ksz9021",
378 .uid = 0x221610,
379 .mask = 0xfffff0,
380 .features = PHY_GBIT_FEATURES,
381 .config = &ksz9021_config,
David Andreyf0d83c42013-02-06 22:18:37 +0100382 .startup = &ksz90xx_startup,
Troy Kisky80b6b092012-02-07 14:08:48 +0000383 .shutdown = &genphy_shutdown,
Stefano Babica8aa2992013-09-02 15:42:31 +0200384 .writeext = &ksz9021_phy_extwrite,
385 .readext = &ksz9021_phy_extread,
Troy Kisky80b6b092012-02-07 14:08:48 +0000386};
Troy Kiskyb4fd97f2012-06-28 08:00:28 +0000387#endif
Troy Kisky80b6b092012-02-07 14:08:48 +0000388
SARTRE Leoeaf68ac2013-04-30 16:57:25 +0200389/**
David Andreyf0d83c42013-02-06 22:18:37 +0100390 * KSZ9031
391 */
SARTRE Leoeaf68ac2013-04-30 16:57:25 +0200392/* PHY Registers */
393#define MII_KSZ9031_MMD_ACCES_CTRL 0x0d
394#define MII_KSZ9031_MMD_REG_DATA 0x0e
395
Mugunthan V Ncbd7daa2016-02-02 15:51:32 +0530396#if defined(CONFIG_DM_ETH) && (defined(CONFIG_PHY_MICREL_KSZ9021) || \
397 defined(CONFIG_PHY_MICREL_KSZ9031))
Marek Vasut1005ce52015-12-05 17:41:58 +0100398static const struct ksz90x1_reg_field ksz9031_ctl_grp[] =
399 { { "txen-skew-ps", 4, 0, 0x7 }, { "rxdv-skew-ps", 4, 4, 0x7 } };
400static const struct ksz90x1_reg_field ksz9031_clk_grp[] =
401 { { "rxc-skew-ps", 5, 0, 0xf }, { "txc-skew-ps", 5, 5, 0xf } };
402
403static int ksz9031_of_config(struct phy_device *phydev)
404{
405 struct ksz90x1_ofcfg ofcfg[] = {
406 { MII_KSZ9031_EXT_RGMII_CTRL_SIG_SKEW, 2, ksz9031_ctl_grp, 2 },
407 { MII_KSZ9031_EXT_RGMII_RX_DATA_SKEW, 2, ksz90x1_rxd_grp, 4 },
408 { MII_KSZ9031_EXT_RGMII_TX_DATA_SKEW, 2, ksz90x1_txd_grp, 4 },
409 { MII_KSZ9031_EXT_RGMII_CLOCK_SKEW, 2, ksz9031_clk_grp, 2 },
410 };
411 int i, ret = 0;
412
Marek Vasut0c766302016-11-14 15:08:42 +0100413 for (i = 0; i < ARRAY_SIZE(ofcfg); i++) {
Marek Vasut1005ce52015-12-05 17:41:58 +0100414 ret = ksz90x1_of_config_group(phydev, &(ofcfg[i]));
415 if (ret)
416 return ret;
Marek Vasut0c766302016-11-14 15:08:42 +0100417 }
Marek Vasut1005ce52015-12-05 17:41:58 +0100418
419 return 0;
420}
Ash Charles3f55bb62016-10-21 17:31:33 -0400421
422static int ksz9031_center_flp_timing(struct phy_device *phydev)
423{
424 struct phy_driver *drv = phydev->drv;
425 int ret = 0;
426
427 if (!drv || !drv->writeext)
428 return -EOPNOTSUPP;
429
430 ret = drv->writeext(phydev, 0, 0, MII_KSZ9031_FLP_BURST_TX_LO, 0x1A80);
431 if (ret)
432 return ret;
433
434 ret = drv->writeext(phydev, 0, 0, MII_KSZ9031_FLP_BURST_TX_HI, 0x6);
435 return ret;
436}
Marek Vasut1005ce52015-12-05 17:41:58 +0100437#else
438static int ksz9031_of_config(struct phy_device *phydev)
439{
440 return 0;
441}
Ash Charles3f55bb62016-10-21 17:31:33 -0400442static int ksz9031_center_flp_timing(struct phy_device *phydev)
443{
444 return 0;
445}
Marek Vasut1005ce52015-12-05 17:41:58 +0100446#endif
447
SARTRE Leoeaf68ac2013-04-30 16:57:25 +0200448/* Accessors to extended registers*/
449int ksz9031_phy_extended_write(struct phy_device *phydev,
450 int devaddr, int regnum, u16 mode, u16 val)
451{
452 /*select register addr for mmd*/
453 phy_write(phydev, MDIO_DEVAD_NONE,
454 MII_KSZ9031_MMD_ACCES_CTRL, devaddr);
455 /*select register for mmd*/
456 phy_write(phydev, MDIO_DEVAD_NONE,
457 MII_KSZ9031_MMD_REG_DATA, regnum);
458 /*setup mode*/
459 phy_write(phydev, MDIO_DEVAD_NONE,
460 MII_KSZ9031_MMD_ACCES_CTRL, (mode | devaddr));
461 /*write the value*/
462 return phy_write(phydev, MDIO_DEVAD_NONE,
463 MII_KSZ9031_MMD_REG_DATA, val);
464}
465
466int ksz9031_phy_extended_read(struct phy_device *phydev, int devaddr,
467 int regnum, u16 mode)
468{
469 phy_write(phydev, MDIO_DEVAD_NONE,
470 MII_KSZ9031_MMD_ACCES_CTRL, devaddr);
471 phy_write(phydev, MDIO_DEVAD_NONE,
472 MII_KSZ9031_MMD_REG_DATA, regnum);
473 phy_write(phydev, MDIO_DEVAD_NONE,
474 MII_KSZ9031_MMD_ACCES_CTRL, (devaddr | mode));
475 return phy_read(phydev, MDIO_DEVAD_NONE, MII_KSZ9031_MMD_REG_DATA);
476}
477
Stefano Babica8aa2992013-09-02 15:42:31 +0200478static int ksz9031_phy_extread(struct phy_device *phydev, int addr, int devaddr,
479 int regnum)
480{
481 return ksz9031_phy_extended_read(phydev, devaddr, regnum,
482 MII_KSZ9031_MOD_DATA_NO_POST_INC);
Alexandru Gagniuc757bb672017-07-07 11:36:57 -0700483}
Stefano Babica8aa2992013-09-02 15:42:31 +0200484
485static int ksz9031_phy_extwrite(struct phy_device *phydev, int addr,
486 int devaddr, int regnum, u16 val)
487{
488 return ksz9031_phy_extended_write(phydev, devaddr, regnum,
489 MII_KSZ9031_MOD_DATA_POST_INC_RW, val);
Alexandru Gagniuc757bb672017-07-07 11:36:57 -0700490}
Stefano Babica8aa2992013-09-02 15:42:31 +0200491
Marek Vasut1005ce52015-12-05 17:41:58 +0100492static int ksz9031_config(struct phy_device *phydev)
493{
494 int ret;
495 ret = ksz9031_of_config(phydev);
496 if (ret)
497 return ret;
Ash Charles3f55bb62016-10-21 17:31:33 -0400498 ret = ksz9031_center_flp_timing(phydev);
499 if (ret)
500 return ret;
Marek Vasut1005ce52015-12-05 17:41:58 +0100501 return genphy_config(phydev);
502}
Stefano Babica8aa2992013-09-02 15:42:31 +0200503
David Andreyf0d83c42013-02-06 22:18:37 +0100504static struct phy_driver ksz9031_driver = {
505 .name = "Micrel ksz9031",
506 .uid = 0x221620,
Stefano Babicd9e36ad2013-09-02 15:42:29 +0200507 .mask = 0xfffff0,
David Andreyf0d83c42013-02-06 22:18:37 +0100508 .features = PHY_GBIT_FEATURES,
Marek Vasut1005ce52015-12-05 17:41:58 +0100509 .config = &ksz9031_config,
David Andreyf0d83c42013-02-06 22:18:37 +0100510 .startup = &ksz90xx_startup,
511 .shutdown = &genphy_shutdown,
Stefano Babica8aa2992013-09-02 15:42:31 +0200512 .writeext = &ksz9031_phy_extwrite,
513 .readext = &ksz9031_phy_extread,
David Andreyf0d83c42013-02-06 22:18:37 +0100514};
515
Alexey Firago73823fa2016-05-26 16:28:44 +0300516int ksz886x_config(struct phy_device *phydev)
517{
518 /* we are connected directly to the switch without
519 * dedicated PHY. */
520 phydev->link = 1;
521 phydev->duplex = DUPLEX_FULL;
522 phydev->speed = SPEED_100;
523 return 0;
524}
525
526static int ksz886x_startup(struct phy_device *phydev)
527{
528 return 0;
529}
530
531static struct phy_driver ksz886x_driver = {
532 .name = "Micrel KSZ886x Switch",
533 .uid = 0x00221430,
534 .mask = 0xfffff0,
535 .features = PHY_BASIC_FEATURES,
536 .config = &ksz886x_config,
537 .startup = &ksz886x_startup,
538 .shutdown = &genphy_shutdown,
539};
540
Alexandru Gagniuc757bb672017-07-07 11:36:57 -0700541int phy_micrel_ksz8xxx_init(void)
Andy Fleming60ca78b2011-04-07 21:56:05 -0500542{
543 phy_register(&KSZ804_driver);
Sylvain Lemieuxbd8d3002015-09-09 16:29:51 -0400544 phy_register(&KSZ8031_driver);
Sylvain Rochet23e9d5c2015-10-07 22:54:22 +0200545 phy_register(&KSZ8051_driver);
Luca Elleroadeb9ea2015-03-24 11:32:24 +0100546 phy_register(&KSZ8081_driver);
Troy Kiskyb4fd97f2012-06-28 08:00:28 +0000547#ifdef CONFIG_PHY_MICREL_KSZ9021
Troy Kisky80b6b092012-02-07 14:08:48 +0000548 phy_register(&ksz9021_driver);
Troy Kiskyb4fd97f2012-06-28 08:00:28 +0000549#else
550 phy_register(&KS8721_driver);
551#endif
David Andreyf0d83c42013-02-06 22:18:37 +0100552 phy_register(&ksz9031_driver);
Philippe De Muyter2616b212014-02-19 17:21:59 +0100553 phy_register(&ksz8895_driver);
Alexey Firago73823fa2016-05-26 16:28:44 +0300554 phy_register(&ksz886x_driver);
Andy Fleming60ca78b2011-04-07 21:56:05 -0500555 return 0;
556}