Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Allan W. Nielsen and committed by
David S. Miller
4f58e6dc cf53b1da

+92 -119
+28 -23
Documentation/devicetree/bindings/net/mscc-phy-vsc8531.txt
··· 6 6 Documentation/devicetree/bindings/net/phy.txt 7 7 8 8 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. 10 14 - 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. 13 16 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). 25 30 26 31 Table: 1 - Edge rate change 27 32 ----------------------------------------------------------------| ··· 34 29 | | 35 30 | 3300 mV 2500 mV 1800 mV 1500 mV | 36 31 |---------------------------------------------------------------| 37 - | Default Deafult Default Default | 32 + | 0% 0% 0% 0% | 38 33 | (Fastest) (recommended) (recommended) | 39 34 |---------------------------------------------------------------| 40 - | -2% -3% -5% -6% | 35 + | 2% 3% 5% 6% | 41 36 |---------------------------------------------------------------| 42 - | -4% -6% -9% -14% | 37 + | 4% 6% 9% 14% | 43 38 |---------------------------------------------------------------| 44 - | -7% -10% -16% -21% | 39 + | 7% 10% 16% 21% | 45 40 |(recommended) (recommended) | 46 41 |---------------------------------------------------------------| 47 - | -10% -14% -23% -29% | 42 + | 10% 14% 23% 29% | 48 43 |---------------------------------------------------------------| 49 - | -17% -23% -35% -42% | 44 + | 17% 23% 35% 42% | 50 45 |---------------------------------------------------------------| 51 - | -29% -37% -52% -58% | 46 + | 29% 37% 52% 58% | 52 47 |---------------------------------------------------------------| 53 - | -53% -63% -76% -77% | 48 + | 53% 63% 76% 77% | 54 49 | (slowest) | 55 50 |---------------------------------------------------------------| 56 51 ··· 59 54 vsc8531_0: ethernet-phy@0 { 60 55 compatible = "ethernet-phy-id0007.0570"; 61 56 vsc8531,vddmac = <3300>; 62 - vsc8531,edge-slowdown = <21>; 57 + vsc8531,edge-slowdown = <7>; 63 58 };
+64 -75
drivers/net/phy/mscc.c
··· 12 12 #include <linux/mii.h> 13 13 #include <linux/phy.h> 14 14 #include <linux/of.h> 15 - #include <dt-bindings/net/mscc-phy-vsc8531.h> 16 15 #include <linux/netdevice.h> 17 16 18 17 enum rgmii_rx_clock_delay { ··· 68 69 #define PHY_ID_VSC8531 0x00070570 69 70 #define PHY_ID_VSC8541 0x00070770 70 71 71 - struct edge_rate_table { 72 - u16 vddmac; 73 - int slowdown[MSCC_SLOWDOWN_MAX]; 74 - }; 75 - 76 - struct edge_rate_table edge_table[MSCC_VDDMAC_MAX] = { 77 - {3300, { 0, -2, -4, -7, -10, -17, -29, -53} }, 78 - {2500, { 0, -3, -6, -10, -14, -23, -37, -63} }, 79 - {1800, { 0, -5, -9, -16, -23, -35, -52, -76} }, 80 - {1500, { 0, -6, -14, -21, -29, -42, -58, -77} }, 81 - }; 72 + #define MSCC_VDDMAC_1500 1500 73 + #define MSCC_VDDMAC_1800 1800 74 + #define MSCC_VDDMAC_2500 2500 75 + #define MSCC_VDDMAC_3300 3300 82 76 83 77 struct vsc8531_private { 84 - u8 edge_slowdown; 85 - u16 vddmac; 78 + int rate_magic; 86 79 }; 80 + 81 + #ifdef CONFIG_OF_MDIO 82 + struct vsc8531_edge_rate_table { 83 + u16 vddmac; 84 + u8 slowdown[8]; 85 + }; 86 + 87 + static const struct vsc8531_edge_rate_table edge_table[] = { 88 + {MSCC_VDDMAC_3300, { 0, 2, 4, 7, 10, 17, 29, 53} }, 89 + {MSCC_VDDMAC_2500, { 0, 3, 6, 10, 14, 23, 37, 63} }, 90 + {MSCC_VDDMAC_1800, { 0, 5, 9, 16, 23, 35, 52, 76} }, 91 + {MSCC_VDDMAC_1500, { 0, 6, 14, 21, 29, 42, 58, 77} }, 92 + }; 93 + #endif /* CONFIG_OF_MDIO */ 87 94 88 95 static int vsc85xx_phy_page_set(struct phy_device *phydev, u8 page) 89 96 { ··· 210 205 mutex_unlock(&phydev->lock); 211 206 } 212 207 213 - static u8 edge_rate_magic_get(u16 vddmac, 214 - int slowdown) 208 + #ifdef CONFIG_OF_MDIO 209 + static int vsc85xx_edge_rate_magic_get(struct phy_device *phydev) 215 210 { 216 - int rc = (MSCC_SLOWDOWN_MAX - 1); 217 - u8 vdd; 218 211 u8 sd; 212 + u16 vdd; 213 + int rc, i, j; 214 + struct device *dev = &phydev->mdio.dev; 215 + struct device_node *of_node = dev->of_node; 216 + u8 sd_array_size = ARRAY_SIZE(edge_table[0].slowdown); 219 217 220 - for (vdd = 0; vdd < MSCC_VDDMAC_MAX; vdd++) { 221 - if (edge_table[vdd].vddmac == vddmac) { 222 - for (sd = 0; sd < MSCC_SLOWDOWN_MAX; sd++) { 223 - if (edge_table[vdd].slowdown[sd] <= slowdown) { 224 - rc = (MSCC_SLOWDOWN_MAX - sd - 1); 225 - break; 226 - } 227 - } 228 - } 229 - } 218 + if (!of_node) 219 + return -ENODEV; 230 220 231 - return rc; 221 + rc = of_property_read_u16(of_node, "vsc8531,vddmac", &vdd); 222 + if (rc != 0) 223 + vdd = MSCC_VDDMAC_3300; 224 + 225 + rc = of_property_read_u8(of_node, "vsc8531,edge-slowdown", &sd); 226 + if (rc != 0) 227 + sd = 0; 228 + 229 + for (i = 0; i < ARRAY_SIZE(edge_table); i++) 230 + if (edge_table[i].vddmac == vdd) 231 + for (j = 0; j < sd_array_size; j++) 232 + if (edge_table[i].slowdown[j] == sd) 233 + return (sd_array_size - j - 1); 234 + 235 + return -EINVAL; 232 236 } 237 + #else 238 + static int vsc85xx_edge_rate_magic_get(struct phy_device *phydev) 239 + { 240 + return 0; 241 + } 242 + #endif /* CONFIG_OF_MDIO */ 233 243 234 - static int vsc85xx_edge_rate_cntl_set(struct phy_device *phydev, 235 - u8 edge_rate) 244 + static int vsc85xx_edge_rate_cntl_set(struct phy_device *phydev, u8 edge_rate) 236 245 { 237 246 int rc; 238 247 u16 reg_val; ··· 327 308 return rc; 328 309 } 329 310 330 - #ifdef CONFIG_OF_MDIO 331 - static int vsc8531_of_init(struct phy_device *phydev) 332 - { 333 - int rc; 334 - struct vsc8531_private *vsc8531 = phydev->priv; 335 - struct device *dev = &phydev->mdio.dev; 336 - struct device_node *of_node = dev->of_node; 337 - 338 - if (!of_node) 339 - return -ENODEV; 340 - 341 - rc = of_property_read_u16(of_node, "vsc8531,vddmac", 342 - &vsc8531->vddmac); 343 - if (rc == -EINVAL) 344 - vsc8531->vddmac = MSCC_VDDMAC_3300; 345 - rc = of_property_read_u8(of_node, "vsc8531,edge-slowdown", 346 - &vsc8531->edge_slowdown); 347 - if (rc == -EINVAL) 348 - vsc8531->edge_slowdown = 0; 349 - 350 - rc = 0; 351 - return rc; 352 - } 353 - #else 354 - static int vsc8531_of_init(struct phy_device *phydev) 355 - { 356 - return 0; 357 - } 358 - #endif /* CONFIG_OF_MDIO */ 359 - 360 311 static int vsc85xx_config_init(struct phy_device *phydev) 361 312 { 362 313 int rc; 363 314 struct vsc8531_private *vsc8531 = phydev->priv; 364 - u8 edge_rate; 365 - 366 - rc = vsc8531_of_init(phydev); 367 - if (rc) 368 - return rc; 369 315 370 316 rc = vsc85xx_default_config(phydev); 371 317 if (rc) ··· 340 356 if (rc) 341 357 return rc; 342 358 343 - edge_rate = edge_rate_magic_get(vsc8531->vddmac, 344 - -(int)vsc8531->edge_slowdown); 345 - rc = vsc85xx_edge_rate_cntl_set(phydev, edge_rate); 359 + rc = vsc85xx_edge_rate_cntl_set(phydev, vsc8531->rate_magic); 346 360 if (rc) 347 361 return rc; 348 362 ··· 378 396 379 397 static int vsc85xx_probe(struct phy_device *phydev) 380 398 { 399 + int rate_magic; 381 400 struct vsc8531_private *vsc8531; 401 + 402 + rate_magic = vsc85xx_edge_rate_magic_get(phydev); 403 + if (rate_magic < 0) 404 + return rate_magic; 382 405 383 406 vsc8531 = devm_kzalloc(&phydev->mdio.dev, sizeof(*vsc8531), GFP_KERNEL); 384 407 if (!vsc8531) 385 408 return -ENOMEM; 386 409 387 410 phydev->priv = vsc8531; 411 + 412 + vsc8531->rate_magic = rate_magic; 388 413 389 414 return 0; 390 415 } ··· 413 424 .config_intr = &vsc85xx_config_intr, 414 425 .suspend = &genphy_suspend, 415 426 .resume = &genphy_resume, 416 - .probe = &vsc85xx_probe, 417 - .set_wol = &vsc85xx_wol_set, 418 - .get_wol = &vsc85xx_wol_get, 427 + .probe = &vsc85xx_probe, 428 + .set_wol = &vsc85xx_wol_set, 429 + .get_wol = &vsc85xx_wol_get, 419 430 }, 420 431 { 421 432 .phy_id = PHY_ID_VSC8541, ··· 432 443 .config_intr = &vsc85xx_config_intr, 433 444 .suspend = &genphy_suspend, 434 445 .resume = &genphy_resume, 435 - .probe = &vsc85xx_probe, 436 - .set_wol = &vsc85xx_wol_set, 437 - .get_wol = &vsc85xx_wol_get, 446 + .probe = &vsc85xx_probe, 447 + .set_wol = &vsc85xx_wol_set, 448 + .get_wol = &vsc85xx_wol_get, 438 449 } 439 450 440 451 };
-21
include/dt-bindings/net/mscc-phy-vsc8531.h
··· 1 - /* 2 - * Device Tree constants for Microsemi VSC8531 PHY 3 - * 4 - * Author: Nagaraju Lakkaraju 5 - * 6 - * License: Dual MIT/GPL 7 - * Copyright (c) 2016 Microsemi Corporation 8 - */ 9 - 10 - #ifndef _DT_BINDINGS_MSCC_VSC8531_H 11 - #define _DT_BINDINGS_MSCC_VSC8531_H 12 - 13 - /* MAC interface Edge rate control VDDMAC in milli Volts */ 14 - #define MSCC_VDDMAC_3300 3300 15 - #define MSCC_VDDMAC_2500 2500 16 - #define MSCC_VDDMAC_1800 1800 17 - #define MSCC_VDDMAC_1500 1500 18 - #define MSCC_VDDMAC_MAX 4 19 - #define MSCC_SLOWDOWN_MAX 8 20 - 21 - #endif