5856b59751183314f01b5687d89d755487dc2c38
[openwrt/staging/wigyori.git] /
1 From f932a6dc8bae0dae9645b5b1b4c65aed8a8acb2a Mon Sep 17 00:00:00 2001
2 From: Christian Marangi <ansuelsmth@gmail.com>
3 Date: Fri, 8 Dec 2023 15:51:58 +0100
4 Subject: [PATCH 11/13] net: phy: at803x: move at8031 functions in dedicated
5 section
6
7 Move at8031 functions in dedicated section with dedicated at8031
8 parse_dt and probe.
9
10 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
11 Signed-off-by: David S. Miller <davem@davemloft.net>
12 ---
13 drivers/net/phy/at803x.c | 266 +++++++++++++++++++--------------------
14 1 file changed, 133 insertions(+), 133 deletions(-)
15
16 --- a/drivers/net/phy/at803x.c
17 +++ b/drivers/net/phy/at803x.c
18 @@ -583,139 +583,6 @@ static int at803x_resume(struct phy_devi
19 return phy_modify(phydev, MII_BMCR, BMCR_PDOWN | BMCR_ISOLATE, 0);
20 }
21
22 -static int at8031_rgmii_reg_set_voltage_sel(struct regulator_dev *rdev,
23 - unsigned int selector)
24 -{
25 - struct phy_device *phydev = rdev_get_drvdata(rdev);
26 -
27 - if (selector)
28 - return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F,
29 - 0, AT803X_DEBUG_RGMII_1V8);
30 - else
31 - return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F,
32 - AT803X_DEBUG_RGMII_1V8, 0);
33 -}
34 -
35 -static int at8031_rgmii_reg_get_voltage_sel(struct regulator_dev *rdev)
36 -{
37 - struct phy_device *phydev = rdev_get_drvdata(rdev);
38 - int val;
39 -
40 - val = at803x_debug_reg_read(phydev, AT803X_DEBUG_REG_1F);
41 - if (val < 0)
42 - return val;
43 -
44 - return (val & AT803X_DEBUG_RGMII_1V8) ? 1 : 0;
45 -}
46 -
47 -static const struct regulator_ops vddio_regulator_ops = {
48 - .list_voltage = regulator_list_voltage_table,
49 - .set_voltage_sel = at8031_rgmii_reg_set_voltage_sel,
50 - .get_voltage_sel = at8031_rgmii_reg_get_voltage_sel,
51 -};
52 -
53 -static const unsigned int vddio_voltage_table[] = {
54 - 1500000,
55 - 1800000,
56 -};
57 -
58 -static const struct regulator_desc vddio_desc = {
59 - .name = "vddio",
60 - .of_match = of_match_ptr("vddio-regulator"),
61 - .n_voltages = ARRAY_SIZE(vddio_voltage_table),
62 - .volt_table = vddio_voltage_table,
63 - .ops = &vddio_regulator_ops,
64 - .type = REGULATOR_VOLTAGE,
65 - .owner = THIS_MODULE,
66 -};
67 -
68 -static const struct regulator_ops vddh_regulator_ops = {
69 -};
70 -
71 -static const struct regulator_desc vddh_desc = {
72 - .name = "vddh",
73 - .of_match = of_match_ptr("vddh-regulator"),
74 - .n_voltages = 1,
75 - .fixed_uV = 2500000,
76 - .ops = &vddh_regulator_ops,
77 - .type = REGULATOR_VOLTAGE,
78 - .owner = THIS_MODULE,
79 -};
80 -
81 -static int at8031_register_regulators(struct phy_device *phydev)
82 -{
83 - struct at803x_priv *priv = phydev->priv;
84 - struct device *dev = &phydev->mdio.dev;
85 - struct regulator_config config = { };
86 -
87 - config.dev = dev;
88 - config.driver_data = phydev;
89 -
90 - priv->vddio_rdev = devm_regulator_register(dev, &vddio_desc, &config);
91 - if (IS_ERR(priv->vddio_rdev)) {
92 - phydev_err(phydev, "failed to register VDDIO regulator\n");
93 - return PTR_ERR(priv->vddio_rdev);
94 - }
95 -
96 - priv->vddh_rdev = devm_regulator_register(dev, &vddh_desc, &config);
97 - if (IS_ERR(priv->vddh_rdev)) {
98 - phydev_err(phydev, "failed to register VDDH regulator\n");
99 - return PTR_ERR(priv->vddh_rdev);
100 - }
101 -
102 - return 0;
103 -}
104 -
105 -static int at8031_sfp_insert(void *upstream, const struct sfp_eeprom_id *id)
106 -{
107 - struct phy_device *phydev = upstream;
108 - __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_support);
109 - __ETHTOOL_DECLARE_LINK_MODE_MASK(sfp_support);
110 - DECLARE_PHY_INTERFACE_MASK(interfaces);
111 - phy_interface_t iface;
112 -
113 - linkmode_zero(phy_support);
114 - phylink_set(phy_support, 1000baseX_Full);
115 - phylink_set(phy_support, 1000baseT_Full);
116 - phylink_set(phy_support, Autoneg);
117 - phylink_set(phy_support, Pause);
118 - phylink_set(phy_support, Asym_Pause);
119 -
120 - linkmode_zero(sfp_support);
121 - sfp_parse_support(phydev->sfp_bus, id, sfp_support, interfaces);
122 - /* Some modules support 10G modes as well as others we support.
123 - * Mask out non-supported modes so the correct interface is picked.
124 - */
125 - linkmode_and(sfp_support, phy_support, sfp_support);
126 -
127 - if (linkmode_empty(sfp_support)) {
128 - dev_err(&phydev->mdio.dev, "incompatible SFP module inserted\n");
129 - return -EINVAL;
130 - }
131 -
132 - iface = sfp_select_interface(phydev->sfp_bus, sfp_support);
133 -
134 - /* Only 1000Base-X is supported by AR8031/8033 as the downstream SerDes
135 - * interface for use with SFP modules.
136 - * However, some copper modules detected as having a preferred SGMII
137 - * interface do default to and function in 1000Base-X mode, so just
138 - * print a warning and allow such modules, as they may have some chance
139 - * of working.
140 - */
141 - if (iface == PHY_INTERFACE_MODE_SGMII)
142 - dev_warn(&phydev->mdio.dev, "module may not function if 1000Base-X not supported\n");
143 - else if (iface != PHY_INTERFACE_MODE_1000BASEX)
144 - return -EINVAL;
145 -
146 - return 0;
147 -}
148 -
149 -static const struct sfp_upstream_ops at8031_sfp_ops = {
150 - .attach = phy_sfp_attach,
151 - .detach = phy_sfp_detach,
152 - .module_insert = at8031_sfp_insert,
153 -};
154 -
155 static int at803x_parse_dt(struct phy_device *phydev)
156 {
157 struct device_node *node = phydev->mdio.dev.of_node;
158 @@ -1498,6 +1365,139 @@ static int at803x_cable_test_start(struc
159 return 0;
160 }
161
162 +static int at8031_rgmii_reg_set_voltage_sel(struct regulator_dev *rdev,
163 + unsigned int selector)
164 +{
165 + struct phy_device *phydev = rdev_get_drvdata(rdev);
166 +
167 + if (selector)
168 + return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F,
169 + 0, AT803X_DEBUG_RGMII_1V8);
170 + else
171 + return at803x_debug_reg_mask(phydev, AT803X_DEBUG_REG_1F,
172 + AT803X_DEBUG_RGMII_1V8, 0);
173 +}
174 +
175 +static int at8031_rgmii_reg_get_voltage_sel(struct regulator_dev *rdev)
176 +{
177 + struct phy_device *phydev = rdev_get_drvdata(rdev);
178 + int val;
179 +
180 + val = at803x_debug_reg_read(phydev, AT803X_DEBUG_REG_1F);
181 + if (val < 0)
182 + return val;
183 +
184 + return (val & AT803X_DEBUG_RGMII_1V8) ? 1 : 0;
185 +}
186 +
187 +static const struct regulator_ops vddio_regulator_ops = {
188 + .list_voltage = regulator_list_voltage_table,
189 + .set_voltage_sel = at8031_rgmii_reg_set_voltage_sel,
190 + .get_voltage_sel = at8031_rgmii_reg_get_voltage_sel,
191 +};
192 +
193 +static const unsigned int vddio_voltage_table[] = {
194 + 1500000,
195 + 1800000,
196 +};
197 +
198 +static const struct regulator_desc vddio_desc = {
199 + .name = "vddio",
200 + .of_match = of_match_ptr("vddio-regulator"),
201 + .n_voltages = ARRAY_SIZE(vddio_voltage_table),
202 + .volt_table = vddio_voltage_table,
203 + .ops = &vddio_regulator_ops,
204 + .type = REGULATOR_VOLTAGE,
205 + .owner = THIS_MODULE,
206 +};
207 +
208 +static const struct regulator_ops vddh_regulator_ops = {
209 +};
210 +
211 +static const struct regulator_desc vddh_desc = {
212 + .name = "vddh",
213 + .of_match = of_match_ptr("vddh-regulator"),
214 + .n_voltages = 1,
215 + .fixed_uV = 2500000,
216 + .ops = &vddh_regulator_ops,
217 + .type = REGULATOR_VOLTAGE,
218 + .owner = THIS_MODULE,
219 +};
220 +
221 +static int at8031_register_regulators(struct phy_device *phydev)
222 +{
223 + struct at803x_priv *priv = phydev->priv;
224 + struct device *dev = &phydev->mdio.dev;
225 + struct regulator_config config = { };
226 +
227 + config.dev = dev;
228 + config.driver_data = phydev;
229 +
230 + priv->vddio_rdev = devm_regulator_register(dev, &vddio_desc, &config);
231 + if (IS_ERR(priv->vddio_rdev)) {
232 + phydev_err(phydev, "failed to register VDDIO regulator\n");
233 + return PTR_ERR(priv->vddio_rdev);
234 + }
235 +
236 + priv->vddh_rdev = devm_regulator_register(dev, &vddh_desc, &config);
237 + if (IS_ERR(priv->vddh_rdev)) {
238 + phydev_err(phydev, "failed to register VDDH regulator\n");
239 + return PTR_ERR(priv->vddh_rdev);
240 + }
241 +
242 + return 0;
243 +}
244 +
245 +static int at8031_sfp_insert(void *upstream, const struct sfp_eeprom_id *id)
246 +{
247 + struct phy_device *phydev = upstream;
248 + __ETHTOOL_DECLARE_LINK_MODE_MASK(phy_support);
249 + __ETHTOOL_DECLARE_LINK_MODE_MASK(sfp_support);
250 + DECLARE_PHY_INTERFACE_MASK(interfaces);
251 + phy_interface_t iface;
252 +
253 + linkmode_zero(phy_support);
254 + phylink_set(phy_support, 1000baseX_Full);
255 + phylink_set(phy_support, 1000baseT_Full);
256 + phylink_set(phy_support, Autoneg);
257 + phylink_set(phy_support, Pause);
258 + phylink_set(phy_support, Asym_Pause);
259 +
260 + linkmode_zero(sfp_support);
261 + sfp_parse_support(phydev->sfp_bus, id, sfp_support, interfaces);
262 + /* Some modules support 10G modes as well as others we support.
263 + * Mask out non-supported modes so the correct interface is picked.
264 + */
265 + linkmode_and(sfp_support, phy_support, sfp_support);
266 +
267 + if (linkmode_empty(sfp_support)) {
268 + dev_err(&phydev->mdio.dev, "incompatible SFP module inserted\n");
269 + return -EINVAL;
270 + }
271 +
272 + iface = sfp_select_interface(phydev->sfp_bus, sfp_support);
273 +
274 + /* Only 1000Base-X is supported by AR8031/8033 as the downstream SerDes
275 + * interface for use with SFP modules.
276 + * However, some copper modules detected as having a preferred SGMII
277 + * interface do default to and function in 1000Base-X mode, so just
278 + * print a warning and allow such modules, as they may have some chance
279 + * of working.
280 + */
281 + if (iface == PHY_INTERFACE_MODE_SGMII)
282 + dev_warn(&phydev->mdio.dev, "module may not function if 1000Base-X not supported\n");
283 + else if (iface != PHY_INTERFACE_MODE_1000BASEX)
284 + return -EINVAL;
285 +
286 + return 0;
287 +}
288 +
289 +static const struct sfp_upstream_ops at8031_sfp_ops = {
290 + .attach = phy_sfp_attach,
291 + .detach = phy_sfp_detach,
292 + .module_insert = at8031_sfp_insert,
293 +};
294 +
295 static int at8031_parse_dt(struct phy_device *phydev)
296 {
297 struct device_node *node = phydev->mdio.dev.of_node;