Skip to content

Commit 4f58e6d

Browse files
Allan W. Nielsendavem330
authored andcommitted
net: phy: Cleanup the Edge-Rate feature in Microsemi PHYs.
Edge-Rate cleanup include the following: - Updated device tree bindings documentation for edge-rate - The edge-rate is now specified as a "slowdown", meaning that it is now being specified as positive values instead of negative (both documentation and implementation wise). - Only explicitly documented values for "vsc8531,vddmac" and "vsc8531,edge-slowdown" are accepted by the device driver. - Deleted include/dt-bindings/net/mscc-phy-vsc8531.h as it was not needed. - Read/validate devicetree settings in probe instead of init Signed-off-by: Allan W. Nielsen <allan.nielsen@microsemi.com> Signed-off-by: Raju Lakkaraju <raju.lakkaraju@microsemi.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent cf53b1d commit 4f58e6d

3 files changed

Lines changed: 90 additions & 117 deletions

File tree

‎Documentation/devicetree/bindings/net/mscc-phy-vsc8531.txt‎

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,51 @@ Required properties:
66
Documentation/devicetree/bindings/net/phy.txt
77

88
Optional properties:
9-
- vsc8531,vddmac : The vddmac in mV.
9+
- vsc8531,vddmac : The vddmac in mV. Allowed values is listed
10+
in the first row of Table 1 (below).
11+
This property is only used in combination
12+
with the 'edge-slowdown' property.
13+
Default value is 3300.
1014
- vsc8531,edge-slowdown : % the edge should be slowed down relative to
11-
the fastest possible edge time. Native sign
12-
need not enter.
15+
the fastest possible edge time.
1316
Edge rate sets the drive strength of the MAC
14-
interface output signals. Changing the drive
15-
strength will affect the edge rate of the output
16-
signal. The goal of this setting is to help
17-
reduce electrical emission (EMI) by being able
18-
to reprogram drive strength and in effect slow
19-
down the edge rate if desired. Table 1 shows the
20-
impact to the edge rate per VDDMAC supply for each
21-
drive strength setting.
22-
Ref: Table:1 - Edge rate change below.
23-
24-
Note: see dt-bindings/net/mscc-phy-vsc8531.h for applicable values
17+
interface output signals. Changing the
18+
drive strength will affect the edge rate of
19+
the output signal. The goal of this setting
20+
is to help reduce electrical emission (EMI)
21+
by being able to reprogram drive strength
22+
and in effect slow down the edge rate if
23+
desired.
24+
To adjust the edge-slowdown, the 'vddmac'
25+
must be specified. Table 1 lists the
26+
supported edge-slowdown values for a given
27+
'vddmac'.
28+
Default value is 0%.
29+
Ref: Table:1 - Edge rate change (below).
2530

2631
Table: 1 - Edge rate change
2732
----------------------------------------------------------------|
2833
| Edge Rate Change (VDDMAC) |
2934
| |
3035
| 3300 mV 2500 mV 1800 mV 1500 mV |
3136
|---------------------------------------------------------------|
32-
| Default Deafult Default Default |
37+
| 0% 0% 0% 0% |
3338
| (Fastest) (recommended) (recommended) |
3439
|---------------------------------------------------------------|
35-
| -2% -3% -5% -6% |
40+
| 2% 3% 5% 6% |
3641
|---------------------------------------------------------------|
37-
| -4% -6% -9% -14% |
42+
| 4% 6% 9% 14% |
3843
|---------------------------------------------------------------|
39-
| -7% -10% -16% -21% |
44+
| 7% 10% 16% 21% |
4045
|(recommended) (recommended) |
4146
|---------------------------------------------------------------|
42-
| -10% -14% -23% -29% |
47+
| 10% 14% 23% 29% |
4348
|---------------------------------------------------------------|
44-
| -17% -23% -35% -42% |
49+
| 17% 23% 35% 42% |
4550
|---------------------------------------------------------------|
46-
| -29% -37% -52% -58% |
51+
| 29% 37% 52% 58% |
4752
|---------------------------------------------------------------|
48-
| -53% -63% -76% -77% |
53+
| 53% 63% 76% 77% |
4954
| (slowest) |
5055
|---------------------------------------------------------------|
5156

@@ -54,5 +59,5 @@ Example:
5459
vsc8531_0: ethernet-phy@0 {
5560
compatible = "ethernet-phy-id0007.0570";
5661
vsc8531,vddmac = <3300>;
57-
vsc8531,edge-slowdown = <21>;
62+
vsc8531,edge-slowdown = <7>;
5863
};

‎drivers/net/phy/mscc.c‎

Lines changed: 62 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <linux/mii.h>
1313
#include <linux/phy.h>
1414
#include <linux/of.h>
15-
#include <dt-bindings/net/mscc-phy-vsc8531.h>
1615
#include <linux/netdevice.h>
1716

1817
enum rgmii_rx_clock_delay {
@@ -69,23 +68,29 @@ enum rgmii_rx_clock_delay {
6968
#define PHY_ID_VSC8531 0x00070570
7069
#define PHY_ID_VSC8541 0x00070770
7170

72-
struct edge_rate_table {
73-
u16 vddmac;
74-
int slowdown[MSCC_SLOWDOWN_MAX];
75-
};
71+
#define MSCC_VDDMAC_1500 1500
72+
#define MSCC_VDDMAC_1800 1800
73+
#define MSCC_VDDMAC_2500 2500
74+
#define MSCC_VDDMAC_3300 3300
7675

77-
struct edge_rate_table edge_table[MSCC_VDDMAC_MAX] = {
78-
{3300, { 0, -2, -4, -7, -10, -17, -29, -53} },
79-
{2500, { 0, -3, -6, -10, -14, -23, -37, -63} },
80-
{1800, { 0, -5, -9, -16, -23, -35, -52, -76} },
81-
{1500, { 0, -6, -14, -21, -29, -42, -58, -77} },
76+
struct vsc8531_private {
77+
int rate_magic;
8278
};
8379

84-
struct vsc8531_private {
85-
u8 edge_slowdown;
80+
#ifdef CONFIG_OF_MDIO
81+
struct vsc8531_edge_rate_table {
8682
u16 vddmac;
83+
u8 slowdown[8];
8784
};
8885

86+
static const struct vsc8531_edge_rate_table edge_table[] = {
87+
{MSCC_VDDMAC_3300, { 0, 2, 4, 7, 10, 17, 29, 53} },
88+
{MSCC_VDDMAC_2500, { 0, 3, 6, 10, 14, 23, 37, 63} },
89+
{MSCC_VDDMAC_1800, { 0, 5, 9, 16, 23, 35, 52, 76} },
90+
{MSCC_VDDMAC_1500, { 0, 6, 14, 21, 29, 42, 58, 77} },
91+
};
92+
#endif /* CONFIG_OF_MDIO */
93+
8994
static int vsc85xx_phy_page_set(struct phy_device *phydev, u8 page)
9095
{
9196
int rc;
@@ -205,29 +210,43 @@ static void vsc85xx_wol_get(struct phy_device *phydev,
205210
mutex_unlock(&phydev->lock);
206211
}
207212

208-
static u8 edge_rate_magic_get(u16 vddmac,
209-
int slowdown)
213+
#ifdef CONFIG_OF_MDIO
214+
static int vsc85xx_edge_rate_magic_get(struct phy_device *phydev)
210215
{
211-
int rc = (MSCC_SLOWDOWN_MAX - 1);
212-
u8 vdd;
213216
u8 sd;
217+
u16 vdd;
218+
int rc, i, j;
219+
struct device *dev = &phydev->mdio.dev;
220+
struct device_node *of_node = dev->of_node;
221+
u8 sd_array_size = ARRAY_SIZE(edge_table[0].slowdown);
214222

215-
for (vdd = 0; vdd < MSCC_VDDMAC_MAX; vdd++) {
216-
if (edge_table[vdd].vddmac == vddmac) {
217-
for (sd = 0; sd < MSCC_SLOWDOWN_MAX; sd++) {
218-
if (edge_table[vdd].slowdown[sd] <= slowdown) {
219-
rc = (MSCC_SLOWDOWN_MAX - sd - 1);
220-
break;
221-
}
222-
}
223-
}
224-
}
223+
if (!of_node)
224+
return -ENODEV;
225225

226-
return rc;
226+
rc = of_property_read_u16(of_node, "vsc8531,vddmac", &vdd);
227+
if (rc != 0)
228+
vdd = MSCC_VDDMAC_3300;
229+
230+
rc = of_property_read_u8(of_node, "vsc8531,edge-slowdown", &sd);
231+
if (rc != 0)
232+
sd = 0;
233+
234+
for (i = 0; i < ARRAY_SIZE(edge_table); i++)
235+
if (edge_table[i].vddmac == vdd)
236+
for (j = 0; j < sd_array_size; j++)
237+
if (edge_table[i].slowdown[j] == sd)
238+
return (sd_array_size - j - 1);
239+
240+
return -EINVAL;
241+
}
242+
#else
243+
static int vsc85xx_edge_rate_magic_get(struct phy_device *phydev)
244+
{
245+
return 0;
227246
}
247+
#endif /* CONFIG_OF_MDIO */
228248

229-
static int vsc85xx_edge_rate_cntl_set(struct phy_device *phydev,
230-
u8 edge_rate)
249+
static int vsc85xx_edge_rate_cntl_set(struct phy_device *phydev, u8 edge_rate)
231250
{
232251
int rc;
233252
u16 reg_val;
@@ -308,45 +327,10 @@ static int vsc85xx_default_config(struct phy_device *phydev)
308327
return rc;
309328
}
310329

311-
#ifdef CONFIG_OF_MDIO
312-
static int vsc8531_of_init(struct phy_device *phydev)
313-
{
314-
int rc;
315-
struct vsc8531_private *vsc8531 = phydev->priv;
316-
struct device *dev = &phydev->mdio.dev;
317-
struct device_node *of_node = dev->of_node;
318-
319-
if (!of_node)
320-
return -ENODEV;
321-
322-
rc = of_property_read_u16(of_node, "vsc8531,vddmac",
323-
&vsc8531->vddmac);
324-
if (rc == -EINVAL)
325-
vsc8531->vddmac = MSCC_VDDMAC_3300;
326-
rc = of_property_read_u8(of_node, "vsc8531,edge-slowdown",
327-
&vsc8531->edge_slowdown);
328-
if (rc == -EINVAL)
329-
vsc8531->edge_slowdown = 0;
330-
331-
rc = 0;
332-
return rc;
333-
}
334-
#else
335-
static int vsc8531_of_init(struct phy_device *phydev)
336-
{
337-
return 0;
338-
}
339-
#endif /* CONFIG_OF_MDIO */
340-
341330
static int vsc85xx_config_init(struct phy_device *phydev)
342331
{
343332
int rc;
344333
struct vsc8531_private *vsc8531 = phydev->priv;
345-
u8 edge_rate;
346-
347-
rc = vsc8531_of_init(phydev);
348-
if (rc)
349-
return rc;
350334

351335
rc = vsc85xx_default_config(phydev);
352336
if (rc)
@@ -356,9 +340,7 @@ static int vsc85xx_config_init(struct phy_device *phydev)
356340
if (rc)
357341
return rc;
358342

359-
edge_rate = edge_rate_magic_get(vsc8531->vddmac,
360-
-(int)vsc8531->edge_slowdown);
361-
rc = vsc85xx_edge_rate_cntl_set(phydev, edge_rate);
343+
rc = vsc85xx_edge_rate_cntl_set(phydev, vsc8531->rate_magic);
362344
if (rc)
363345
return rc;
364346

@@ -396,14 +378,21 @@ static int vsc85xx_config_intr(struct phy_device *phydev)
396378

397379
static int vsc85xx_probe(struct phy_device *phydev)
398380
{
381+
int rate_magic;
399382
struct vsc8531_private *vsc8531;
400383

384+
rate_magic = vsc85xx_edge_rate_magic_get(phydev);
385+
if (rate_magic < 0)
386+
return rate_magic;
387+
401388
vsc8531 = devm_kzalloc(&phydev->mdio.dev, sizeof(*vsc8531), GFP_KERNEL);
402389
if (!vsc8531)
403390
return -ENOMEM;
404391

405392
phydev->priv = vsc8531;
406393

394+
vsc8531->rate_magic = rate_magic;
395+
407396
return 0;
408397
}
409398

@@ -424,9 +413,9 @@ static struct phy_driver vsc85xx_driver[] = {
424413
.config_intr = &vsc85xx_config_intr,
425414
.suspend = &genphy_suspend,
426415
.resume = &genphy_resume,
427-
.probe = &vsc85xx_probe,
428-
.set_wol = &vsc85xx_wol_set,
429-
.get_wol = &vsc85xx_wol_get,
416+
.probe = &vsc85xx_probe,
417+
.set_wol = &vsc85xx_wol_set,
418+
.get_wol = &vsc85xx_wol_get,
430419
},
431420
{
432421
.phy_id = PHY_ID_VSC8541,
@@ -443,9 +432,9 @@ static struct phy_driver vsc85xx_driver[] = {
443432
.config_intr = &vsc85xx_config_intr,
444433
.suspend = &genphy_suspend,
445434
.resume = &genphy_resume,
446-
.probe = &vsc85xx_probe,
447-
.set_wol = &vsc85xx_wol_set,
448-
.get_wol = &vsc85xx_wol_get,
435+
.probe = &vsc85xx_probe,
436+
.set_wol = &vsc85xx_wol_set,
437+
.get_wol = &vsc85xx_wol_get,
449438
}
450439

451440
};

‎include/dt-bindings/net/mscc-phy-vsc8531.h‎

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)