blob: 26bef5fb656e7de75f7a6006993761f21df09439 [file] [log] [blame]
developerd6051f22022-08-03 17:09:50 +08001diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
2index e0f724a..1f74ff2 100644
3--- a/drivers/net/phy/Kconfig
4+++ b/drivers/net/phy/Kconfig
5@@ -511,6 +511,12 @@ config MARVELL_10G_PHY
6 ---help---
7 Support for the Marvell Alaska MV88X3310 and compatible PHYs.
8
9+config MAXLINEAR_GPHY
10+ tristate "Maxlinear Ethernet PHYs"
11+ help
12+ Support for the Maxlinear GPY115, GPY211, GPY212, GPY215,
13+ GPY241, GPY245 PHYs.
14+
15 config MESON_GXL_PHY
16 tristate "Amlogic Meson GXL Internal PHY"
17 depends on ARCH_MESON || COMPILE_TEST
18diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile
19index e3c411f..7b44a98 100644
20--- a/drivers/net/phy/Makefile
21+++ b/drivers/net/phy/Makefile
22@@ -94,6 +94,7 @@ obj-$(CONFIG_LSI_ET1011C_PHY) += et1011c.o
23 obj-$(CONFIG_LXT_PHY) += lxt.o
24 obj-$(CONFIG_MARVELL_PHY) += marvell.o
25 obj-$(CONFIG_MARVELL_10G_PHY) += marvell10g.o
26+obj-$(CONFIG_MAXLINEAR_GPHY) += mxl-gpy.o
27 obj-$(CONFIG_MEDIATEK_GE_PHY) += mediatek-ge.o
28 obj-$(CONFIG_MESON_GXL_PHY) += meson-gxl.o
29 obj-$(CONFIG_MICREL_KS8995MA) += spi_ks8995.o
30diff --git a/drivers/net/phy/mxl-gpy.c b/drivers/net/phy/mxl-gpy.c
31new file mode 100644
32index 0000000..7304278
33--- /dev/null
34+++ b/drivers/net/phy/mxl-gpy.c
developer24e6e2f2022-09-20 15:14:43 +080035@@ -0,0 +1,738 @@
developerd6051f22022-08-03 17:09:50 +080036+// SPDX-License-Identifier: GPL-2.0+
37+/* Copyright (C) 2021 Maxlinear Corporation
38+ * Copyright (C) 2020 Intel Corporation
39+ *
40+ * Drivers for Maxlinear Ethernet GPY
41+ *
42+ */
43+
44+#include <linux/module.h>
45+#include <linux/bitfield.h>
46+#include <linux/phy.h>
47+#include <linux/netdevice.h>
48+
49+/* PHY ID */
50+#define PHY_ID_GPYx15B_MASK 0xFFFFFFFC
51+#define PHY_ID_GPY21xB_MASK 0xFFFFFFF9
52+#define PHY_ID_GPY2xx 0x67C9DC00
53+#define PHY_ID_GPY115B 0x67C9DF00
54+#define PHY_ID_GPY115C 0x67C9DF10
55+#define PHY_ID_GPY211B 0x67C9DE08
56+#define PHY_ID_GPY211C 0x67C9DE10
57+#define PHY_ID_GPY212B 0x67C9DE09
58+#define PHY_ID_GPY212C 0x67C9DE20
59+#define PHY_ID_GPY215B 0x67C9DF04
60+#define PHY_ID_GPY215C 0x67C9DF20
61+#define PHY_ID_GPY241B 0x67C9DE40
62+#define PHY_ID_GPY241BM 0x67C9DE80
63+#define PHY_ID_GPY245B 0x67C9DEC0
64+
65+#define PHY_MIISTAT 0x18 /* MII state */
66+#define PHY_IMASK 0x19 /* interrupt mask */
67+#define PHY_ISTAT 0x1A /* interrupt status */
68+#define PHY_FWV 0x1E /* firmware version */
69+
70+#define PHY_MIISTAT_SPD_MASK GENMASK(2, 0)
71+#define PHY_MIISTAT_DPX BIT(3)
72+#define PHY_MIISTAT_LS BIT(10)
73+
74+#define PHY_MIISTAT_SPD_10 0
75+#define PHY_MIISTAT_SPD_100 1
76+#define PHY_MIISTAT_SPD_1000 2
77+#define PHY_MIISTAT_SPD_2500 4
78+
79+#define PHY_IMASK_WOL BIT(15) /* Wake-on-LAN */
80+#define PHY_IMASK_ANC BIT(10) /* Auto-Neg complete */
81+#define PHY_IMASK_ADSC BIT(5) /* Link auto-downspeed detect */
82+#define PHY_IMASK_DXMC BIT(2) /* Duplex mode change */
83+#define PHY_IMASK_LSPC BIT(1) /* Link speed change */
84+#define PHY_IMASK_LSTC BIT(0) /* Link state change */
85+#define PHY_IMASK_MASK (PHY_IMASK_LSTC | \
86+ PHY_IMASK_LSPC | \
87+ PHY_IMASK_DXMC | \
88+ PHY_IMASK_ADSC | \
89+ PHY_IMASK_ANC)
90+
91+#define PHY_FWV_REL_MASK BIT(15)
92+#define PHY_FWV_TYPE_MASK GENMASK(11, 8)
93+#define PHY_FWV_MINOR_MASK GENMASK(7, 0)
94+
95+/* SGMII */
96+#define VSPEC1_SGMII_CTRL 0x08
97+#define VSPEC1_SGMII_CTRL_ANEN BIT(12) /* Aneg enable */
98+#define VSPEC1_SGMII_CTRL_ANRS BIT(9) /* Restart Aneg */
99+#define VSPEC1_SGMII_ANEN_ANRS (VSPEC1_SGMII_CTRL_ANEN | \
100+ VSPEC1_SGMII_CTRL_ANRS)
101+
102+/* WoL */
103+#define VPSPEC2_WOL_CTL 0x0E06
104+#define VPSPEC2_WOL_AD01 0x0E08
105+#define VPSPEC2_WOL_AD23 0x0E09
106+#define VPSPEC2_WOL_AD45 0x0E0A
107+#define WOL_EN BIT(0)
108+
109+static const struct {
110+ int type;
111+ int minor;
112+} ver_need_sgmii_reaneg[] = {
113+ {7, 0x6D},
114+ {8, 0x6D},
115+ {9, 0x73},
116+};
117+
118+static int gpy_config_init(struct phy_device *phydev)
119+{
120+ int ret;
121+
122+ /* Mask all interrupts */
123+ ret = phy_write(phydev, PHY_IMASK, 0);
124+ if (ret)
125+ return ret;
126+
127+ /* Clear all pending interrupts */
128+ ret = phy_read(phydev, PHY_ISTAT);
129+ return ret < 0 ? ret : 0;
130+}
131+
132+static int gpy_probe(struct phy_device *phydev)
133+{
134+ int ret;
135+
136+ /* Show GPY PHY FW version in dmesg */
137+ ret = phy_read(phydev, PHY_FWV);
138+ if (ret < 0)
139+ return ret;
140+
141+ phydev_info(phydev, "Firmware Version: 0x%04X (%s)\n", ret,
142+ (ret & PHY_FWV_REL_MASK) ? "release" : "test");
143+
144+ return 0;
145+}
146+
147+static bool gpy_sgmii_need_reaneg(struct phy_device *phydev)
148+{
149+ int fw_ver, fw_type, fw_minor;
150+ size_t i;
151+
152+ fw_ver = phy_read(phydev, PHY_FWV);
153+ if (fw_ver < 0)
154+ return true;
155+
156+ fw_type = FIELD_GET(PHY_FWV_TYPE_MASK, fw_ver);
157+ fw_minor = FIELD_GET(PHY_FWV_MINOR_MASK, fw_ver);
158+
159+ for (i = 0; i < ARRAY_SIZE(ver_need_sgmii_reaneg); i++) {
160+ if (fw_type != ver_need_sgmii_reaneg[i].type)
161+ continue;
162+ if (fw_minor < ver_need_sgmii_reaneg[i].minor)
163+ return true;
164+ break;
165+ }
166+
167+ return false;
168+}
169+
170+static bool gpy_2500basex_chk(struct phy_device *phydev)
171+{
172+ int ret;
173+
174+ ret = phy_read(phydev, PHY_MIISTAT);
175+ if (ret < 0) {
176+ phydev_err(phydev, "Error: MDIO register access failed: %d\n",
177+ ret);
178+ return false;
179+ }
180+
181+ if (!(ret & PHY_MIISTAT_LS) ||
182+ FIELD_GET(PHY_MIISTAT_SPD_MASK, ret) != PHY_MIISTAT_SPD_2500)
183+ return false;
184+
185+ phydev->speed = SPEED_2500;
186+ phydev->interface = PHY_INTERFACE_MODE_2500BASEX;
187+ phy_modify_mmd(phydev, MDIO_MMD_VEND1, VSPEC1_SGMII_CTRL,
188+ VSPEC1_SGMII_CTRL_ANEN, 0);
189+ return true;
190+}
191+
192+static bool gpy_sgmii_aneg_en(struct phy_device *phydev)
193+{
194+ int ret;
195+
196+ ret = phy_read_mmd(phydev, MDIO_MMD_VEND1, VSPEC1_SGMII_CTRL);
197+ if (ret < 0) {
198+ phydev_err(phydev, "Error: MMD register access failed: %d\n",
199+ ret);
200+ return true;
201+ }
202+
203+ return (ret & VSPEC1_SGMII_CTRL_ANEN) ? true : false;
204+}
205+
206+static int gpy_config_aneg(struct phy_device *phydev)
207+{
208+ bool changed = false;
209+ u32 adv;
210+ int ret;
211+
212+ if (phydev->autoneg == AUTONEG_DISABLE) {
213+ /* Configure half duplex with genphy_setup_forced,
214+ * because genphy_c45_pma_setup_forced does not support.
215+ */
216+ return phydev->duplex != DUPLEX_FULL
217+ ? genphy_setup_forced(phydev)
218+ : genphy_c45_pma_setup_forced(phydev);
219+ }
220+
221+ ret = genphy_c45_an_config_aneg(phydev);
222+ if (ret < 0)
223+ return ret;
224+ if (ret > 0)
225+ changed = true;
226+
227+ adv = linkmode_adv_to_mii_ctrl1000_t(phydev->advertising);
228+ ret = phy_modify_changed(phydev, MII_CTRL1000,
229+ ADVERTISE_1000FULL | ADVERTISE_1000HALF,
230+ adv);
231+ if (ret < 0)
232+ return ret;
233+ if (ret > 0)
234+ changed = true;
235+
236+ ret = genphy_c45_check_and_restart_aneg(phydev, changed);
237+ if (ret < 0)
238+ return ret;
239+
240+ if (phydev->interface == PHY_INTERFACE_MODE_USXGMII ||
241+ phydev->interface == PHY_INTERFACE_MODE_INTERNAL)
242+ return 0;
243+
244+ /* No need to trigger re-ANEG if link speed is 2.5G or SGMII ANEG is
245+ * disabled.
246+ */
247+ if (!gpy_sgmii_need_reaneg(phydev) || gpy_2500basex_chk(phydev) ||
248+ !gpy_sgmii_aneg_en(phydev))
249+ return 0;
250+
251+ /* There is a design constraint in GPY2xx device where SGMII AN is
252+ * only triggered when there is change of speed. If, PHY link
253+ * partner`s speed is still same even after PHY TPI is down and up
254+ * again, SGMII AN is not triggered and hence no new in-band message
255+ * from GPY to MAC side SGMII.
256+ * This could cause an issue during power up, when PHY is up prior to
257+ * MAC. At this condition, once MAC side SGMII is up, MAC side SGMII
258+ * wouldn`t receive new in-band message from GPY with correct link
259+ * status, speed and duplex info.
260+ *
261+ * 1) If PHY is already up and TPI link status is still down (such as
262+ * hard reboot), TPI link status is polled for 4 seconds before
263+ * retriggerring SGMII AN.
264+ * 2) If PHY is already up and TPI link status is also up (such as soft
265+ * reboot), polling of TPI link status is not needed and SGMII AN is
266+ * immediately retriggered.
267+ * 3) Other conditions such as PHY is down, speed change etc, skip
268+ * retriggering SGMII AN. Note: in case of speed change, GPY FW will
269+ * initiate SGMII AN.
270+ */
271+
272+ if (phydev->state != PHY_UP)
273+ return 0;
274+
275+ ret = phy_read_poll_timeout(phydev, MII_BMSR, ret, ret & BMSR_LSTATUS,
276+ 20000, 4000000, false);
277+ if (ret == -ETIMEDOUT)
278+ return 0;
279+ else if (ret < 0)
280+ return ret;
281+
282+ /* Trigger SGMII AN. */
283+ return phy_modify_mmd(phydev, MDIO_MMD_VEND1, VSPEC1_SGMII_CTRL,
284+ VSPEC1_SGMII_CTRL_ANRS, VSPEC1_SGMII_CTRL_ANRS);
285+}
286+
287+static void gpy_update_interface(struct phy_device *phydev)
288+{
289+ int ret;
290+
291+ /* Interface mode is fixed for USXGMII and integrated PHY */
292+ if (phydev->interface == PHY_INTERFACE_MODE_USXGMII ||
293+ phydev->interface == PHY_INTERFACE_MODE_INTERNAL)
294+ return;
295+
296+ /* Automatically switch SERDES interface between SGMII and 2500-BaseX
297+ * according to speed. Disable ANEG in 2500-BaseX mode.
298+ */
299+ switch (phydev->speed) {
300+ case SPEED_2500:
301+ phydev->interface = PHY_INTERFACE_MODE_2500BASEX;
302+ ret = phy_modify_mmd(phydev, MDIO_MMD_VEND1, VSPEC1_SGMII_CTRL,
developer24e6e2f2022-09-20 15:14:43 +0800303+ VSPEC1_SGMII_CTRL_ANEN, 0);
developerd6051f22022-08-03 17:09:50 +0800304+ if (ret < 0)
305+ phydev_err(phydev,
306+ "Error: Disable of SGMII ANEG failed: %d\n",
307+ ret);
308+ break;
309+ case SPEED_1000:
310+ case SPEED_100:
311+ case SPEED_10:
312+ phydev->interface = PHY_INTERFACE_MODE_SGMII;
313+ if (gpy_sgmii_aneg_en(phydev))
314+ break;
315+ /* Enable and restart SGMII ANEG for 10/100/1000Mbps link speed
316+ * if ANEG is disabled (in 2500-BaseX mode).
317+ */
318+ ret = phy_modify_mmd(phydev, MDIO_MMD_VEND1, VSPEC1_SGMII_CTRL,
developer24e6e2f2022-09-20 15:14:43 +0800319+ VSPEC1_SGMII_ANEN_ANRS,
developerd6051f22022-08-03 17:09:50 +0800320+ VSPEC1_SGMII_ANEN_ANRS);
321+ if (ret < 0)
322+ phydev_err(phydev,
323+ "Error: Enable of SGMII ANEG failed: %d\n",
324+ ret);
325+ break;
326+ }
327+}
328+
329+static int gpy_read_status(struct phy_device *phydev)
330+{
331+ int ret;
332+
333+ ret = genphy_update_link(phydev);
334+ if (ret)
335+ return ret;
336+
337+ phydev->speed = SPEED_UNKNOWN;
338+ phydev->duplex = DUPLEX_UNKNOWN;
339+ phydev->pause = 0;
340+ phydev->asym_pause = 0;
341+
342+ if (phydev->autoneg == AUTONEG_ENABLE && phydev->autoneg_complete) {
343+ ret = genphy_c45_read_lpa(phydev);
344+ if (ret < 0)
345+ return ret;
346+
347+ /* Read the link partner's 1G advertisement */
348+ ret = phy_read(phydev, MII_STAT1000);
349+ if (ret < 0)
350+ return ret;
351+ mii_stat1000_mod_linkmode_lpa_t(phydev->lp_advertising, ret);
352+ } else if (phydev->autoneg == AUTONEG_DISABLE) {
353+ linkmode_zero(phydev->lp_advertising);
354+ }
355+
356+ ret = phy_read(phydev, PHY_MIISTAT);
357+ if (ret < 0)
358+ return ret;
359+
360+ phydev->link = (ret & PHY_MIISTAT_LS) ? 1 : 0;
361+ phydev->duplex = (ret & PHY_MIISTAT_DPX) ? DUPLEX_FULL : DUPLEX_HALF;
362+ switch (FIELD_GET(PHY_MIISTAT_SPD_MASK, ret)) {
363+ case PHY_MIISTAT_SPD_10:
364+ phydev->speed = SPEED_10;
365+ break;
366+ case PHY_MIISTAT_SPD_100:
367+ phydev->speed = SPEED_100;
368+ break;
369+ case PHY_MIISTAT_SPD_1000:
370+ phydev->speed = SPEED_1000;
371+ break;
372+ case PHY_MIISTAT_SPD_2500:
373+ phydev->speed = SPEED_2500;
374+ break;
375+ }
376+
377+ if (phydev->link)
378+ gpy_update_interface(phydev);
379+
380+ return 0;
381+}
382+
383+static int gpy_config_intr(struct phy_device *phydev)
384+{
385+ u16 mask = 0;
386+
387+ if (phydev->interrupts == PHY_INTERRUPT_ENABLED)
388+ mask = PHY_IMASK_MASK;
389+
390+ return phy_write(phydev, PHY_IMASK, mask);
391+}
392+
393+static int gpy_handle_interrupt(struct phy_device *phydev)
394+{
395+ int reg;
396+
397+ reg = phy_read(phydev, PHY_ISTAT);
398+ if (reg < 0)
399+ return -1;
400+
401+ if (!(reg & PHY_IMASK_MASK))
402+ return -1;
403+
404+ phy_queue_state_machine(phydev, 0);
405+
406+ return 0;
407+}
408+
409+static int gpy_set_wol(struct phy_device *phydev,
410+ struct ethtool_wolinfo *wol)
411+{
412+ struct net_device *attach_dev = phydev->attached_dev;
413+ int ret;
414+
415+ if (wol->wolopts & WAKE_MAGIC) {
416+ /* MAC address - Byte0:Byte1:Byte2:Byte3:Byte4:Byte5
417+ * VPSPEC2_WOL_AD45 = Byte0:Byte1
418+ * VPSPEC2_WOL_AD23 = Byte2:Byte3
419+ * VPSPEC2_WOL_AD01 = Byte4:Byte5
420+ */
421+ ret = phy_set_bits_mmd(phydev, MDIO_MMD_VEND2,
422+ VPSPEC2_WOL_AD45,
423+ ((attach_dev->dev_addr[0] << 8) |
424+ attach_dev->dev_addr[1]));
425+ if (ret < 0)
426+ return ret;
427+
428+ ret = phy_set_bits_mmd(phydev, MDIO_MMD_VEND2,
429+ VPSPEC2_WOL_AD23,
430+ ((attach_dev->dev_addr[2] << 8) |
431+ attach_dev->dev_addr[3]));
432+ if (ret < 0)
433+ return ret;
434+
435+ ret = phy_set_bits_mmd(phydev, MDIO_MMD_VEND2,
436+ VPSPEC2_WOL_AD01,
437+ ((attach_dev->dev_addr[4] << 8) |
438+ attach_dev->dev_addr[5]));
439+ if (ret < 0)
440+ return ret;
441+
442+ /* Enable the WOL interrupt */
443+ ret = phy_write(phydev, PHY_IMASK, PHY_IMASK_WOL);
444+ if (ret < 0)
445+ return ret;
446+
447+ /* Enable magic packet matching */
448+ ret = phy_set_bits_mmd(phydev, MDIO_MMD_VEND2,
449+ VPSPEC2_WOL_CTL,
450+ WOL_EN);
451+ if (ret < 0)
452+ return ret;
453+
454+ /* Clear the interrupt status register.
455+ * Only WoL is enabled so clear all.
456+ */
457+ ret = phy_read(phydev, PHY_ISTAT);
458+ if (ret < 0)
459+ return ret;
460+ } else {
461+ /* Disable magic packet matching */
462+ ret = phy_clear_bits_mmd(phydev, MDIO_MMD_VEND2,
463+ VPSPEC2_WOL_CTL,
464+ WOL_EN);
465+ if (ret < 0)
466+ return ret;
467+ }
468+
469+ if (wol->wolopts & WAKE_PHY) {
470+ /* Enable the link state change interrupt */
471+ ret = phy_set_bits(phydev, PHY_IMASK, PHY_IMASK_LSTC);
472+ if (ret < 0)
473+ return ret;
474+
475+ /* Clear the interrupt status register */
476+ ret = phy_read(phydev, PHY_ISTAT);
477+ if (ret < 0)
478+ return ret;
479+
480+ if (ret & (PHY_IMASK_MASK & ~PHY_IMASK_LSTC))
481+ phy_queue_state_machine(phydev, 0);
482+
483+ return 0;
484+ }
485+
486+ /* Disable the link state change interrupt */
487+ return phy_clear_bits(phydev, PHY_IMASK, PHY_IMASK_LSTC);
488+}
489+
490+static void gpy_get_wol(struct phy_device *phydev,
491+ struct ethtool_wolinfo *wol)
492+{
493+ int ret;
494+
495+ wol->supported = WAKE_MAGIC | WAKE_PHY;
496+ wol->wolopts = 0;
497+
498+ ret = phy_read_mmd(phydev, MDIO_MMD_VEND2, VPSPEC2_WOL_CTL);
499+ if (ret & WOL_EN)
500+ wol->wolopts |= WAKE_MAGIC;
501+
502+ ret = phy_read(phydev, PHY_IMASK);
503+ if (ret & PHY_IMASK_LSTC)
504+ wol->wolopts |= WAKE_PHY;
505+}
506+
507+static int gpy_loopback(struct phy_device *phydev, bool enable)
508+{
509+ int ret;
510+
511+ ret = phy_modify(phydev, MII_BMCR, BMCR_LOOPBACK,
512+ enable ? BMCR_LOOPBACK : 0);
513+ if (!ret) {
514+ /* It takes some time for PHY device to switch
515+ * into/out-of loopback mode.
516+ */
517+ msleep(100);
518+ }
519+
520+ return ret;
521+}
522+
523+static int gpy115_loopback(struct phy_device *phydev, bool enable)
524+{
525+ int ret;
526+ int fw_minor;
527+
528+ if (enable)
529+ return gpy_loopback(phydev, enable);
530+
531+ ret = phy_read(phydev, PHY_FWV);
532+ if (ret < 0)
533+ return ret;
534+
535+ fw_minor = FIELD_GET(PHY_FWV_MINOR_MASK, ret);
536+ if (fw_minor > 0x0076)
537+ return gpy_loopback(phydev, 0);
538+
539+ return genphy_soft_reset(phydev);
540+}
541+
542+static struct phy_driver gpy_drivers[] = {
543+ {
544+ PHY_ID_MATCH_MODEL(PHY_ID_GPY2xx),
545+ .name = "Maxlinear Ethernet GPY2xx",
546+ .get_features = genphy_c45_pma_read_abilities,
547+ .config_init = gpy_config_init,
548+ .probe = gpy_probe,
549+ .suspend = genphy_suspend,
550+ .resume = genphy_resume,
551+ .config_aneg = gpy_config_aneg,
552+ .aneg_done = genphy_c45_aneg_done,
553+ .read_status = gpy_read_status,
554+ .config_intr = gpy_config_intr,
555+ .handle_interrupt = gpy_handle_interrupt,
556+ .set_wol = gpy_set_wol,
557+ .get_wol = gpy_get_wol,
558+ .set_loopback = gpy_loopback,
559+ },
560+ {
561+ .phy_id = PHY_ID_GPY115B,
562+ .phy_id_mask = PHY_ID_GPYx15B_MASK,
563+ .name = "Maxlinear Ethernet GPY115B",
564+ .get_features = genphy_c45_pma_read_abilities,
565+ .config_init = gpy_config_init,
566+ .probe = gpy_probe,
567+ .suspend = genphy_suspend,
568+ .resume = genphy_resume,
569+ .config_aneg = gpy_config_aneg,
570+ .aneg_done = genphy_c45_aneg_done,
571+ .read_status = gpy_read_status,
572+ .config_intr = gpy_config_intr,
573+ .handle_interrupt = gpy_handle_interrupt,
574+ .set_wol = gpy_set_wol,
575+ .get_wol = gpy_get_wol,
576+ .set_loopback = gpy115_loopback,
577+ },
578+ {
579+ PHY_ID_MATCH_MODEL(PHY_ID_GPY115C),
580+ .name = "Maxlinear Ethernet GPY115C",
581+ .get_features = genphy_c45_pma_read_abilities,
582+ .config_init = gpy_config_init,
583+ .probe = gpy_probe,
584+ .suspend = genphy_suspend,
585+ .resume = genphy_resume,
586+ .config_aneg = gpy_config_aneg,
587+ .aneg_done = genphy_c45_aneg_done,
588+ .read_status = gpy_read_status,
589+ .config_intr = gpy_config_intr,
590+ .handle_interrupt = gpy_handle_interrupt,
591+ .set_wol = gpy_set_wol,
592+ .get_wol = gpy_get_wol,
593+ .set_loopback = gpy115_loopback,
594+ },
595+ {
596+ .phy_id = PHY_ID_GPY211B,
597+ .phy_id_mask = PHY_ID_GPY21xB_MASK,
598+ .name = "Maxlinear Ethernet GPY211B",
599+ .get_features = genphy_c45_pma_read_abilities,
600+ .config_init = gpy_config_init,
601+ .probe = gpy_probe,
602+ .suspend = genphy_suspend,
603+ .resume = genphy_resume,
604+ .config_aneg = gpy_config_aneg,
605+ .aneg_done = genphy_c45_aneg_done,
606+ .read_status = gpy_read_status,
607+ .config_intr = gpy_config_intr,
608+ .handle_interrupt = gpy_handle_interrupt,
609+ .set_wol = gpy_set_wol,
610+ .get_wol = gpy_get_wol,
611+ .set_loopback = gpy_loopback,
612+ },
613+ {
614+ PHY_ID_MATCH_MODEL(PHY_ID_GPY211C),
615+ .name = "Maxlinear Ethernet GPY211C",
616+ .get_features = genphy_c45_pma_read_abilities,
617+ .config_init = gpy_config_init,
618+ .probe = gpy_probe,
619+ .suspend = genphy_suspend,
620+ .resume = genphy_resume,
621+ .config_aneg = gpy_config_aneg,
622+ .aneg_done = genphy_c45_aneg_done,
623+ .read_status = gpy_read_status,
624+ .config_intr = gpy_config_intr,
625+ .handle_interrupt = gpy_handle_interrupt,
626+ .set_wol = gpy_set_wol,
627+ .get_wol = gpy_get_wol,
628+ .set_loopback = gpy_loopback,
629+ },
630+ {
631+ .phy_id = PHY_ID_GPY212B,
632+ .phy_id_mask = PHY_ID_GPY21xB_MASK,
633+ .name = "Maxlinear Ethernet GPY212B",
634+ .get_features = genphy_c45_pma_read_abilities,
635+ .config_init = gpy_config_init,
636+ .probe = gpy_probe,
637+ .suspend = genphy_suspend,
638+ .resume = genphy_resume,
639+ .config_aneg = gpy_config_aneg,
640+ .aneg_done = genphy_c45_aneg_done,
641+ .read_status = gpy_read_status,
642+ .config_intr = gpy_config_intr,
643+ .handle_interrupt = gpy_handle_interrupt,
644+ .set_wol = gpy_set_wol,
645+ .get_wol = gpy_get_wol,
646+ .set_loopback = gpy_loopback,
647+ },
648+ {
649+ PHY_ID_MATCH_MODEL(PHY_ID_GPY212C),
650+ .name = "Maxlinear Ethernet GPY212C",
651+ .get_features = genphy_c45_pma_read_abilities,
652+ .config_init = gpy_config_init,
653+ .probe = gpy_probe,
654+ .suspend = genphy_suspend,
655+ .resume = genphy_resume,
656+ .config_aneg = gpy_config_aneg,
657+ .aneg_done = genphy_c45_aneg_done,
658+ .read_status = gpy_read_status,
659+ .config_intr = gpy_config_intr,
660+ .handle_interrupt = gpy_handle_interrupt,
661+ .set_wol = gpy_set_wol,
662+ .get_wol = gpy_get_wol,
663+ .set_loopback = gpy_loopback,
664+ },
665+ {
666+ .phy_id = PHY_ID_GPY215B,
667+ .phy_id_mask = PHY_ID_GPYx15B_MASK,
668+ .name = "Maxlinear Ethernet GPY215B",
669+ .get_features = genphy_c45_pma_read_abilities,
670+ .config_init = gpy_config_init,
671+ .probe = gpy_probe,
672+ .suspend = genphy_suspend,
673+ .resume = genphy_resume,
674+ .config_aneg = gpy_config_aneg,
675+ .aneg_done = genphy_c45_aneg_done,
676+ .read_status = gpy_read_status,
677+ .config_intr = gpy_config_intr,
678+ .handle_interrupt = gpy_handle_interrupt,
679+ .set_wol = gpy_set_wol,
680+ .get_wol = gpy_get_wol,
681+ .set_loopback = gpy_loopback,
682+ },
683+ {
684+ PHY_ID_MATCH_MODEL(PHY_ID_GPY215C),
685+ .name = "Maxlinear Ethernet GPY215C",
686+ .get_features = genphy_c45_pma_read_abilities,
687+ .config_init = gpy_config_init,
688+ .probe = gpy_probe,
689+ .suspend = genphy_suspend,
690+ .resume = genphy_resume,
691+ .config_aneg = gpy_config_aneg,
692+ .aneg_done = genphy_c45_aneg_done,
693+ .read_status = gpy_read_status,
694+ .config_intr = gpy_config_intr,
695+ .handle_interrupt = gpy_handle_interrupt,
696+ .set_wol = gpy_set_wol,
697+ .get_wol = gpy_get_wol,
698+ .set_loopback = gpy_loopback,
699+ },
700+ {
701+ PHY_ID_MATCH_MODEL(PHY_ID_GPY241B),
702+ .name = "Maxlinear Ethernet GPY241B",
703+ .get_features = genphy_c45_pma_read_abilities,
704+ .config_init = gpy_config_init,
705+ .probe = gpy_probe,
706+ .suspend = genphy_suspend,
707+ .resume = genphy_resume,
708+ .config_aneg = gpy_config_aneg,
709+ .aneg_done = genphy_c45_aneg_done,
710+ .read_status = gpy_read_status,
711+ .config_intr = gpy_config_intr,
712+ .handle_interrupt = gpy_handle_interrupt,
713+ .set_wol = gpy_set_wol,
714+ .get_wol = gpy_get_wol,
715+ .set_loopback = gpy_loopback,
716+ },
717+ {
718+ PHY_ID_MATCH_MODEL(PHY_ID_GPY241BM),
719+ .name = "Maxlinear Ethernet GPY241BM",
720+ .get_features = genphy_c45_pma_read_abilities,
721+ .config_init = gpy_config_init,
722+ .probe = gpy_probe,
723+ .suspend = genphy_suspend,
724+ .resume = genphy_resume,
725+ .config_aneg = gpy_config_aneg,
726+ .aneg_done = genphy_c45_aneg_done,
727+ .read_status = gpy_read_status,
728+ .config_intr = gpy_config_intr,
729+ .handle_interrupt = gpy_handle_interrupt,
730+ .set_wol = gpy_set_wol,
731+ .get_wol = gpy_get_wol,
732+ .set_loopback = gpy_loopback,
733+ },
734+ {
735+ PHY_ID_MATCH_MODEL(PHY_ID_GPY245B),
736+ .name = "Maxlinear Ethernet GPY245B",
737+ .get_features = genphy_c45_pma_read_abilities,
738+ .config_init = gpy_config_init,
739+ .probe = gpy_probe,
740+ .suspend = genphy_suspend,
741+ .resume = genphy_resume,
742+ .config_aneg = gpy_config_aneg,
743+ .aneg_done = genphy_c45_aneg_done,
744+ .read_status = gpy_read_status,
745+ .config_intr = gpy_config_intr,
746+ .handle_interrupt = gpy_handle_interrupt,
747+ .set_wol = gpy_set_wol,
748+ .get_wol = gpy_get_wol,
749+ .set_loopback = gpy_loopback,
750+ },
751+};
752+module_phy_driver(gpy_drivers);
753+
754+static struct mdio_device_id __maybe_unused gpy_tbl[] = {
755+ {PHY_ID_MATCH_MODEL(PHY_ID_GPY2xx)},
756+ {PHY_ID_GPY115B, PHY_ID_GPYx15B_MASK},
757+ {PHY_ID_MATCH_MODEL(PHY_ID_GPY115C)},
758+ {PHY_ID_GPY211B, PHY_ID_GPY21xB_MASK},
759+ {PHY_ID_MATCH_MODEL(PHY_ID_GPY211C)},
760+ {PHY_ID_GPY212B, PHY_ID_GPY21xB_MASK},
761+ {PHY_ID_MATCH_MODEL(PHY_ID_GPY212C)},
762+ {PHY_ID_GPY215B, PHY_ID_GPYx15B_MASK},
763+ {PHY_ID_MATCH_MODEL(PHY_ID_GPY215C)},
764+ {PHY_ID_MATCH_MODEL(PHY_ID_GPY241B)},
765+ {PHY_ID_MATCH_MODEL(PHY_ID_GPY241BM)},
766+ {PHY_ID_MATCH_MODEL(PHY_ID_GPY245B)},
767+ { }
768+};
769+MODULE_DEVICE_TABLE(mdio, gpy_tbl);
770+
771+MODULE_DESCRIPTION("Maxlinear Ethernet GPY Driver");
772+MODULE_AUTHOR("Xu Liang");
773+MODULE_LICENSE("GPL");
developerd6051f22022-08-03 17:09:50 +0800774diff --git a/include/linux/phy.h b/include/linux/phy.h
775index 19444cd..34bdd16 100644
776--- a/include/linux/phy.h
777+++ b/include/linux/phy.h
778@@ -21,6 +21,7 @@
779 #include <linux/timer.h>
780 #include <linux/workqueue.h>
781 #include <linux/mod_devicetable.h>
782+#include <linux/iopoll.h>
783
784 #include <linux/atomic.h>
785
786@@ -711,6 +712,18 @@ static inline int phy_read(struct phy_device *phydev, u32 regnum)
787 return mdiobus_read(phydev->mdio.bus, phydev->mdio.addr, regnum);
788 }
789
790+#define phy_read_poll_timeout(phydev, regnum, val, cond, sleep_us, \
791+ timeout_us, sleep_before_read) \
792+({ \
793+ int __ret = read_poll_timeout(phy_read, val, (cond) || val < 0, \
794+ sleep_us, timeout_us, sleep_before_read, phydev, regnum); \
795+ if (val < 0) \
796+ __ret = val; \
797+ if (__ret) \
798+ phydev_err(phydev, "%s failed: %d\n", __func__, __ret); \
799+ __ret; \
800+})
801+
802 /**
803 * __phy_read - convenience function for reading a given PHY register
804 * @phydev: the phy_device struct