gpio-nct5104d: fix compilation with kernel 6.6
[openwrt/openwrt.git] / target / linux / generic / backport-6.1 / 715-01-v6.2-net-fman-memac-Add-serdes-support.patch
1 From affa013f494486079c3c5ad2d00cebc41a3d7445 Mon Sep 17 00:00:00 2001
2 From: Sean Anderson <sean.anderson@seco.com>
3 Date: Mon, 17 Oct 2022 16:22:36 -0400
4 Subject: [PATCH 01/21] net: fman: memac: Add serdes support
5
6 This adds support for using a serdes which has to be configured. This is
7 primarly in preparation for phylink conversion, which will then change the
8 serdes mode dynamically.
9
10 Signed-off-by: Sean Anderson <sean.anderson@seco.com>
11 Signed-off-by: David S. Miller <davem@davemloft.net>
12 ---
13 .../net/ethernet/freescale/fman/fman_memac.c | 49 ++++++++++++++++++-
14 1 file changed, 47 insertions(+), 2 deletions(-)
15
16 --- a/drivers/net/ethernet/freescale/fman/fman_memac.c
17 +++ b/drivers/net/ethernet/freescale/fman/fman_memac.c
18 @@ -13,6 +13,7 @@
19 #include <linux/io.h>
20 #include <linux/phy.h>
21 #include <linux/phy_fixed.h>
22 +#include <linux/phy/phy.h>
23 #include <linux/of_mdio.h>
24
25 /* PCS registers */
26 @@ -324,6 +325,7 @@ struct fman_mac {
27 void *fm;
28 struct fman_rev_info fm_rev_info;
29 bool basex_if;
30 + struct phy *serdes;
31 struct phy_device *pcsphy;
32 bool allmulti_enabled;
33 };
34 @@ -1203,17 +1205,56 @@ int memac_initialization(struct mac_devi
35 }
36 }
37
38 + memac->serdes = devm_of_phy_get(mac_dev->dev, mac_node, "serdes");
39 + err = PTR_ERR(memac->serdes);
40 + if (err == -ENODEV || err == -ENOSYS) {
41 + dev_dbg(mac_dev->dev, "could not get (optional) serdes\n");
42 + memac->serdes = NULL;
43 + } else if (IS_ERR(memac->serdes)) {
44 + dev_err_probe(mac_dev->dev, err, "could not get serdes\n");
45 + goto _return_fm_mac_free;
46 + } else {
47 + err = phy_init(memac->serdes);
48 + if (err) {
49 + dev_err_probe(mac_dev->dev, err,
50 + "could not initialize serdes\n");
51 + goto _return_fm_mac_free;
52 + }
53 +
54 + err = phy_power_on(memac->serdes);
55 + if (err) {
56 + dev_err_probe(mac_dev->dev, err,
57 + "could not power on serdes\n");
58 + goto _return_phy_exit;
59 + }
60 +
61 + if (memac->phy_if == PHY_INTERFACE_MODE_SGMII ||
62 + memac->phy_if == PHY_INTERFACE_MODE_1000BASEX ||
63 + memac->phy_if == PHY_INTERFACE_MODE_2500BASEX ||
64 + memac->phy_if == PHY_INTERFACE_MODE_QSGMII ||
65 + memac->phy_if == PHY_INTERFACE_MODE_XGMII) {
66 + err = phy_set_mode_ext(memac->serdes, PHY_MODE_ETHERNET,
67 + memac->phy_if);
68 + if (err) {
69 + dev_err_probe(mac_dev->dev, err,
70 + "could not set serdes mode to %s\n",
71 + phy_modes(memac->phy_if));
72 + goto _return_phy_power_off;
73 + }
74 + }
75 + }
76 +
77 if (!mac_dev->phy_node && of_phy_is_fixed_link(mac_node)) {
78 struct phy_device *phy;
79
80 err = of_phy_register_fixed_link(mac_node);
81 if (err)
82 - goto _return_fm_mac_free;
83 + goto _return_phy_power_off;
84
85 fixed_link = kzalloc(sizeof(*fixed_link), GFP_KERNEL);
86 if (!fixed_link) {
87 err = -ENOMEM;
88 - goto _return_fm_mac_free;
89 + goto _return_phy_power_off;
90 }
91
92 mac_dev->phy_node = of_node_get(mac_node);
93 @@ -1242,6 +1283,10 @@ int memac_initialization(struct mac_devi
94
95 goto _return;
96
97 +_return_phy_power_off:
98 + phy_power_off(memac->serdes);
99 +_return_phy_exit:
100 + phy_exit(memac->serdes);
101 _return_fixed_link_free:
102 kfree(fixed_link);
103 _return_fm_mac_free: