net: phy: at803x: cleanup
Subsystems (3)
v3 cover net: phy: at803x: cleanup
The intention of this big series is to try to cleanup the big at803x PHY driver.
It currently have 3 different family of PHY in it. at803x, qca83xx and qca808x.
The current codebase required lots of cleanup and reworking to make the split possible as currently there is a greater use of adding special function matching the phy_id.
This has been reworked to make the function actually generic and make the change only in more specific one. The result is the addition of micro additional function but that is for good as it massively simplify splitting the driver later.
Consider that this is all in preparation for the addition of qca807x PHY driver that will also uso some of the functions of at803x.
Subsequent series will come with the actual PHY split and other required cleanup. This is only to start the process with minor changes.
Changes v3:
- Add Reviewed-by tag from Andrew
- Split patch 10 (at8031 rename) to rename and move Changes v2:
- Drop split part due to series too big
- Split changes even more
- Fix problem pointed out by Russell (flawed reworked function logic)
- Add Reviewed-by tag from Andrew
- Minor rework to prevent further code duplication for cdt
Christian Marangi (13):
net: phy: at803x: fix passing the wrong reference for config_intr
net: phy: at803x: move disable WOL to specific at8031 probe
net: phy: at803x: raname hw_stats functions to qca83xx specific name
net: phy: at803x: move qca83xx specific check in dedicated functions
net: phy: at803x: move specific DT option for at8031 to specific probe
net: phy: at803x: move specific at8031 probe mode check to dedicated
probe
net: phy: at803x: move specific at8031 config_init to dedicated
function
net: phy: at803x: move specific at8031 WOL bits to dedicated function
net: phy: at803x: move specific at8031 config_intr to dedicated
function
net: phy: at803x: make at8031 related DT functions name more specific
net: phy: at803x: move at8031 functions in dedicated section
net: phy: at803x: move at8035 specific DT parse to dedicated probe
net: phy: at803x: drop specific PHY ID check from cable test functions
drivers/net/phy/at803x.c | 777 +++++++++++++++++++++------------------ 1 file changed, 428 insertions(+), 349 deletions(-)
Signature · 1 line
2.40.1
PATCH v3 1/13 net: phy: at803x: fix passing the wrong reference for config_intr
Fix passing the wrong reference for config_initr on passing the function pointer, drop the wrong & from at803x_config_intr in the PHY struct.
--- drivers/net/phy/at803x.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/phy/at803x.c +3 -3
@@ -2104,7 +2104,7 @@ static struct phy_driver at803x_driver[] = { .write_page = at803x_write_page, .get_features = at803x_get_features, .read_status = at803x_read_status, - .config_intr = &at803x_config_intr, + .config_intr = at803x_config_intr, .handle_interrupt = at803x_handle_interrupt, .get_tunable = at803x_get_tunable, .set_tunable = at803x_set_tunable,
@@ -2134,7 +2134,7 @@ static struct phy_driver at803x_driver[] = { .resume = at803x_resume, .flags = PHY_POLL_CABLE_TEST,/* PHY_BASIC_FEATURES */ - .config_intr = &at803x_config_intr, + .config_intr = at803x_config_intr, .handle_interrupt = at803x_handle_interrupt, .cable_test_start = at803x_cable_test_start, .cable_test_get_status = at803x_cable_test_get_status,
@@ -2150,7 +2150,7 @@ static struct phy_driver at803x_driver[] = { .resume = at803x_resume, .flags = PHY_POLL_CABLE_TEST,/* PHY_BASIC_FEATURES */ - .config_intr = &at803x_config_intr, + .config_intr = at803x_config_intr, .handle_interrupt = at803x_handle_interrupt, .cable_test_start = at803x_cable_test_start, .cable_test_get_status = at803x_cable_test_get_status,
Signature · 1 line
2.40.1
PATCH v3 2/13 net: phy: at803x: move disable WOL to specific at8031 probe
In reply to Christian MarangiMove the WOL disable call to specific at8031 probe to make at803x_probe more generic and drop extra check for PHY ID.
Keep the same previous behaviour by first calling at803x_probe and then disabling WOL.
--- drivers/net/phy/at803x.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-)
drivers/net/phy/at803x.c +19 -10
@@ -886,15 +886,6 @@ static int at803x_probe(struct phy_device *phydev) priv->is_fiber = true;break ; } - -/* Disable WoL in 1588 register which is enabled -* by default -*/ - ret =phy_modify_mmd (phydev,MDIO_MMD_PCS , -AT803X_PHY_MMD3_WOL_CTRL , -AT803X_WOL_EN ,0 ); -if (ret) -return ret; }return 0 ;
@@ -1591,6 +1582,24 @@ static int at803x_cable_test_start(struct phy_device *phydev)return 0 ; } +static int at8031_probe (struct phy_device *phydev) +{ +int ret; + + ret =at803x_probe (phydev); +if (ret) +return ret; + +/* Disable WoL in 1588 register which is enabled +* by default +*/ + ret =phy_modify_mmd (phydev,MDIO_MMD_PCS , +AT803X_PHY_MMD3_WOL_CTRL , +AT803X_WOL_EN ,0 ); + +return ret; +} +static int qca83xx_config_init (struct phy_device *phydev) {u8 switch_revision;
@@ -2092,7 +2101,7 @@ static struct phy_driver at803x_driver[] = {PHY_ID_MATCH_EXACT (ATH8031_PHY_ID ), .name = "Qualcomm Atheros AR8031/AR8033", .flags = PHY_POLL_CABLE_TEST, - .probe = at803x_probe, + .probe = at8031_probe, .config_init = at803x_config_init, .config_aneg = at803x_config_aneg, .soft_reset = genphy_soft_reset,
Signature · 1 line
2.40.1
Russell King (Oracle)
reviewerRe: [net-next PATCH v3 02/13] net: phy: at803x: move disable WOL to specific at8031 probe
Quoted 42 lines · Christian Marangi
Move the WOL disable call to specific at8031 probe to make
at803x_probemore generic and drop extra check for PHY ID.Keep the same previous behaviour by first calling
at803x_probeand then disabling WOL.Signed-off-by Christian Marangi <[email protected]>Reviewed-by Andrew Lunn <[email protected]>--- drivers/net/phy/at803x.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-)drivers/net/phy/at803x.c +6
-9@@ -886,15 +886,6 @@ static int at803x_probe(struct phy_device *phydev) priv->is_fiber = true;break ; } - -/* Disable WoL in 1588 register which is enabled -* by default -*/ - ret =phy_modify_mmd (phydev,MDIO_MMD_PCS , -AT803X_PHY_MMD3_WOL_CTRL , -AT803X_WOL_EN ,0 ); -if (ret) -return ret; }return 0 ;@@ -1591,6 +1582,24 @@ static int at803x_cable_test_start(struct phy_device *phydev)return 0 ; } +static int at8031_probe (struct phy_device *phydev) +{ +int ret; + + ret =at803x_probe (phydev); +if (ret)
drivers/net/phy/at803x.c static int at803x_cable_test_start(struct phy_device *phydev) · line 1600
Quoted 10 lines
drivers/net/phy/at803x.c +10
-0+return ret; + +/* Disable WoL in 1588 register which is enabled +* by default +*/ + ret =phy_modify_mmd (phydev,MDIO_MMD_PCS , +AT803X_PHY_MMD3_WOL_CTRL , +AT803X_WOL_EN ,0 ); + +return ret;
return phy_modify_mmd(...) ?
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
PATCH v3 3/13 net: phy: at803x: raname hw_stats functions to qca83xx specific name
In reply to Christian MarangiThe function and the struct related to hw_stats were specific to qca83xx PHY but were called following the convention in the driver of calling everything with at803x prefix.
To better organize the code, rename these function a more specific name to better describe that they are specific to 83xx PHY family.
--- drivers/net/phy/at803x.c | 44 ++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-)
drivers/net/phy/at803x.c +22 -22
@@ -295,7 +295,7 @@ struct at803x_hw_stat {enum stat_access_type access_type; }; -static struct at803x_hw_stat at803x_hw_stats[] = { +static struct at803x_hw_stat qca83xx_hw_stats[] = { {"phy_idle_errors" ,0xa ,GENMASK (7 ,0 ),PHY }, {"phy_receive_errors" ,0x15 ,GENMASK (15 ,0 ),PHY }, {"eee_wake_errors" ,0x16 ,GENMASK (15 ,0 ),MMD },
@@ -311,7 +311,7 @@ struct at803x_priv {bool is_1000basex;struct regulator_dev *vddio_rdev;struct regulator_dev *vddh_rdev; -u64 stats[ARRAY_SIZE (at803x_hw_stats)]; +u64 stats[ARRAY_SIZE (qca83xx_hw_stats)]; };struct at803x_context {
@@ -529,24 +529,24 @@ static void at803x_get_wol(struct phy_device *phydev, wol->wolopts |=WAKE_MAGIC ; } -static int at803x_get_sset_count (struct phy_device *phydev) +static int qca83xx_get_sset_count (struct phy_device *phydev) { -return ARRAY_SIZE (at803x_hw_stats); +return ARRAY_SIZE (qca83xx_hw_stats); } -static void at803x_get_strings (struct phy_device *phydev,u8 *data) +static void qca83xx_get_strings (struct phy_device *phydev,u8 *data) {int i; -for (i =0 ; i <ARRAY_SIZE (at803x_hw_stats); i++) { +for (i =0 ; i <ARRAY_SIZE (qca83xx_hw_stats); i++) {strscpy (data + i *ETH_GSTRING_LEN , - at803x_hw_stats[i].string,ETH_GSTRING_LEN ); + qca83xx_hw_stats[i].string,ETH_GSTRING_LEN ); } } -static u64 at803x_get_stat (struct phy_device *phydev,int i) +static u64 qca83xx_get_stat (struct phy_device *phydev,int i) { -struct at803x_hw_stat stat = at803x_hw_stats[i]; +struct at803x_hw_stat stat = qca83xx_hw_stats[i];struct at803x_priv *priv = phydev->priv;int val;u64 ret;
@@ -567,13 +567,13 @@ static u64 at803x_get_stat(struct phy_device *phydev, int i)return ret; } -static void at803x_get_stats (struct phy_device *phydev, -struct ethtool_stats *stats,u64 *data) +static void qca83xx_get_stats (struct phy_device *phydev, +struct ethtool_stats *stats,u64 *data) {int i; -for (i =0 ; i <ARRAY_SIZE (at803x_hw_stats); i++) - data[i] =at803x_get_stat (phydev, i); +for (i =0 ; i <ARRAY_SIZE (qca83xx_hw_stats); i++) + data[i] =qca83xx_get_stat (phydev, i); }static int at803x_suspend (struct phy_device *phydev)
@@ -2177,9 +2177,9 @@ static struct phy_driver at803x_driver[] = { .flags = PHY_IS_INTERNAL, .config_init = qca83xx_config_init, .soft_reset = genphy_soft_reset, - .get_sset_count = at803x_get_sset_count, - .get_strings = at803x_get_strings, - .get_stats = at803x_get_stats, + .get_sset_count = qca83xx_get_sset_count, + .get_strings = qca83xx_get_strings, + .get_stats = qca83xx_get_stats, .suspend = qca83xx_suspend, .resume = qca83xx_resume, }, {
@@ -2193,9 +2193,9 @@ static struct phy_driver at803x_driver[] = { .flags = PHY_IS_INTERNAL, .config_init = qca83xx_config_init, .soft_reset = genphy_soft_reset, - .get_sset_count = at803x_get_sset_count, - .get_strings = at803x_get_strings, - .get_stats = at803x_get_stats, + .get_sset_count = qca83xx_get_sset_count, + .get_strings = qca83xx_get_strings, + .get_stats = qca83xx_get_stats, .suspend = qca83xx_suspend, .resume = qca83xx_resume, }, {
@@ -2209,9 +2209,9 @@ static struct phy_driver at803x_driver[] = { .flags = PHY_IS_INTERNAL, .config_init = qca83xx_config_init, .soft_reset = genphy_soft_reset, - .get_sset_count = at803x_get_sset_count, - .get_strings = at803x_get_strings, - .get_stats = at803x_get_stats, + .get_sset_count = qca83xx_get_sset_count, + .get_strings = qca83xx_get_strings, + .get_stats = qca83xx_get_stats, .suspend = qca83xx_suspend, .resume = qca83xx_resume, }, {
Signature · 1 line
2.40.1
PATCH v3 4/13 net: phy: at803x: move qca83xx specific check in dedicated functions
In reply to Christian MarangiRework qca83xx specific check to dedicated function to tidy things up and drop useless phy_id check.
Also drop an useless link_change_notify for QCA8337 as it did nothing an returned early.
--- drivers/net/phy/at803x.c | 68 ++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 31 deletions(-)
drivers/net/phy/at803x.c +37 -31
@@ -1625,27 +1625,26 @@ static int qca83xx_config_init(struct phy_device *phydev)break ; } +/* Following original QCA sourcecode set port to prefer master */ +phy_set_bits (phydev,MII_CTRL1000 ,CTL1000_PREFER_MASTER ); + +return 0 ; +} + +static int qca8327_config_init (struct phy_device *phydev) +{/* QCA8327 require DAC amplitude adjustment for 100m set to +6%. * Disable on init and enable only with 100m speed following * qca original source code. */ -if (phydev->drv->phy_id ==QCA8327_A_PHY_ID || - phydev->drv->phy_id ==QCA8327_B_PHY_ID ) -at803x_debug_reg_mask (phydev,AT803X_DEBUG_ANALOG_TEST_CTRL , -QCA8327_DEBUG_MANU_CTRL_EN ,0 ); +at803x_debug_reg_mask (phydev,AT803X_DEBUG_ANALOG_TEST_CTRL , +QCA8327_DEBUG_MANU_CTRL_EN ,0 ); -/* Following original QCA sourcecode set port to prefer master */ -phy_set_bits (phydev,MII_CTRL1000 ,CTL1000_PREFER_MASTER ); - -return 0 ; +return qca83xx_config_init (phydev); }static void qca83xx_link_change_notify (struct phy_device *phydev) { -/* QCA8337 doesn't require DAC Amplitude adjustement */ -if (phydev->drv->phy_id ==QCA8337_PHY_ID ) -return ; -/* Set DAC Amplitude adjustment to +6% for 100m on link running */ if (phydev->state ==PHY_RUNNING ) {if (phydev->speed ==SPEED_100 )
@@ -1688,19 +1687,6 @@ static int qca83xx_resume(struct phy_device *phydev)static int qca83xx_suspend (struct phy_device *phydev) { -u16 mask =0 ; - -/* Only QCA8337 support actual suspend. -* QCA8327 cause port unreliability when phy suspend -* is set. -*/ -if (phydev->drv->phy_id ==QCA8337_PHY_ID ) { -genphy_suspend (phydev); - }else { - mask |= ~(BMCR_SPEED1000 |BMCR_FULLDPLX ); -phy_modify (phydev,MII_BMCR , mask,0 ); - } -at803x_debug_reg_mask (phydev,AT803X_DEBUG_REG_GREEN ,AT803X_DEBUG_GATE_CLK_IN1000 ,0 );
@@ -1711,6 +1697,27 @@ static int qca83xx_suspend(struct phy_device *phydev)return 0 ; } +static int qca8337_suspend (struct phy_device *phydev) +{ +/* Only QCA8337 support actual suspend. */ +genphy_suspend (phydev); + +return qca83xx_suspend (phydev); +} + +static int qca8327_suspend (struct phy_device *phydev) +{ +u16 mask =0 ; + +/* QCA8327 cause port unreliability when phy suspend +* is set. +*/ + mask |= ~(BMCR_SPEED1000 |BMCR_FULLDPLX ); +phy_modify (phydev,MII_BMCR , mask,0 ); + +return qca83xx_suspend (phydev); +} +static int qca808x_phy_fast_retrain_config (struct phy_device *phydev) {int ret;
@@ -2172,7 +2179,6 @@ static struct phy_driver at803x_driver[] = { .phy_id_mask = QCA8K_PHY_ID_MASK, .name = "Qualcomm Atheros 8337 internal PHY",/* PHY_GBIT_FEATURES */ - .link_change_notify = qca83xx_link_change_notify, .probe = at803x_probe, .flags = PHY_IS_INTERNAL, .config_init = qca83xx_config_init,
@@ -2180,7 +2186,7 @@ static struct phy_driver at803x_driver[] = { .get_sset_count = qca83xx_get_sset_count, .get_strings = qca83xx_get_strings, .get_stats = qca83xx_get_stats, - .suspend = qca83xx_suspend, + .suspend = qca8337_suspend, .resume = qca83xx_resume, }, {/* QCA8327-A from switch QCA8327-AL1A */
@@ -2191,12 +2197,12 @@ static struct phy_driver at803x_driver[] = { .link_change_notify = qca83xx_link_change_notify, .probe = at803x_probe, .flags = PHY_IS_INTERNAL, - .config_init = qca83xx_config_init, + .config_init = qca8327_config_init, .soft_reset = genphy_soft_reset, .get_sset_count = qca83xx_get_sset_count, .get_strings = qca83xx_get_strings, .get_stats = qca83xx_get_stats, - .suspend = qca83xx_suspend, + .suspend = qca8327_suspend, .resume = qca83xx_resume, }, {/* QCA8327-B from switch QCA8327-BL1A */
@@ -2207,12 +2213,12 @@ static struct phy_driver at803x_driver[] = { .link_change_notify = qca83xx_link_change_notify, .probe = at803x_probe, .flags = PHY_IS_INTERNAL, - .config_init = qca83xx_config_init, + .config_init = qca8327_config_init, .soft_reset = genphy_soft_reset, .get_sset_count = qca83xx_get_sset_count, .get_strings = qca83xx_get_strings, .get_stats = qca83xx_get_stats, - .suspend = qca83xx_suspend, + .suspend = qca8327_suspend, .resume = qca83xx_resume, }, {/* Qualcomm QCA8081 */
Signature · 1 line
2.40.1
PATCH v3 5/13 net: phy: at803x: move specific DT option for at8031 to specific probe
In reply to Christian MarangiMove specific DT options for at8031 to specific probe to tidy things up and make at803x_parse_dt more generic.
--- drivers/net/phy/at803x.c | 55 ++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 24 deletions(-)
drivers/net/phy/at803x.c +31 -24
@@ -825,30 +825,6 @@ static int at803x_parse_dt(struct phy_device *phydev) } } -/* Only supported on AR8031/AR8033, the AR8030/AR8035 use strapping -* options. -*/ -if (phydev->drv->phy_id ==ATH8031_PHY_ID ) { -if (of_property_read_bool (node,"qca,keep-pll-enabled" )) - priv->flags |=AT803X_KEEP_PLL_ENABLED ; - - ret =at8031_register_regulators (phydev); -if (ret <0 ) -return ret; - - ret =devm_regulator_get_enable_optional (&phydev->mdio.dev, -"vddio" ); -if (ret) { -phydev_err (phydev,"failed to get VDDIO regulator\n" ); -return ret; - } - -/* Only AR8031/8033 support 1000Base-X for SFP modules */ - ret =phy_sfp_probe (phydev, &at803x_sfp_ops); -if (ret <0 ) -return ret; - } -return 0 ; }
@@ -1582,6 +1558,30 @@ static int at803x_cable_test_start(struct phy_device *phydev)return 0 ; } +static int at8031_parse_dt (struct phy_device *phydev) +{ +struct device_node *node = phydev->mdio.dev.of_node; +struct at803x_priv *priv = phydev->priv; +int ret; + +if (of_property_read_bool (node,"qca,keep-pll-enabled" )) + priv->flags |=AT803X_KEEP_PLL_ENABLED ; + + ret =at8031_register_regulators (phydev); +if (ret <0 ) +return ret; + + ret =devm_regulator_get_enable_optional (&phydev->mdio.dev, +"vddio" ); +if (ret) { +phydev_err (phydev,"failed to get VDDIO regulator\n" ); +return ret; + } + +/* Only AR8031/8033 support 1000Base-X for SFP modules */ +return phy_sfp_probe (phydev, &at803x_sfp_ops); +} +static int at8031_probe (struct phy_device *phydev) {int ret;
@@ -1590,6 +1590,13 @@ static int at8031_probe(struct phy_device *phydev)if (ret)return ret; +/* Only supported on AR8031/AR8033, the AR8030/AR8035 use strapping +* options. +*/ + ret =at8031_parse_dt (phydev); +if (ret) +return ret; +/* Disable WoL in 1588 register which is enabled * by default */
Signature · 1 line
2.40.1
PATCH v3 6/13 net: phy: at803x: move specific at8031 probe mode check to dedicated probe
In reply to Christian MarangiMove specific at8031 probe mode check to dedicated probe to make at803x_probe more generic and keep code tidy.
--- drivers/net/phy/at803x.c | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-)
drivers/net/phy/at803x.c +19 -20
@@ -844,26 +844,6 @@ static int at803x_probe(struct phy_device *phydev)if (ret)return ret; -if (phydev->drv->phy_id ==ATH8031_PHY_ID ) { -int ccr =phy_read (phydev,AT803X_REG_CHIP_CONFIG ); -int mode_cfg; - -if (ccr <0 ) -return ccr; - mode_cfg = ccr &AT803X_MODE_CFG_MASK ; - -switch (mode_cfg) { -case AT803X_MODE_CFG_BX1000_RGMII_50OHM : -case AT803X_MODE_CFG_BX1000_RGMII_75OHM : - priv->is_1000basex = true; - fallthrough; -case AT803X_MODE_CFG_FX100_RGMII_50OHM : -case AT803X_MODE_CFG_FX100_RGMII_75OHM : - priv->is_fiber = true; -break ; - } - } -return 0 ; }
@@ -1584,6 +1564,9 @@ static int at8031_parse_dt(struct phy_device *phydev)static int at8031_probe (struct phy_device *phydev) { +struct at803x_priv *priv = phydev->priv; +int mode_cfg; +int ccr;int ret; ret =at803x_probe (phydev);
@@ -1597,6 +1580,22 @@ static int at8031_probe(struct phy_device *phydev)if (ret)return ret; + ccr =phy_read (phydev,AT803X_REG_CHIP_CONFIG ); +if (ccr <0 ) +return ccr; + mode_cfg = ccr &AT803X_MODE_CFG_MASK ; + +switch (mode_cfg) { +case AT803X_MODE_CFG_BX1000_RGMII_50OHM : +case AT803X_MODE_CFG_BX1000_RGMII_75OHM : + priv->is_1000basex = true; + fallthrough; +case AT803X_MODE_CFG_FX100_RGMII_50OHM : +case AT803X_MODE_CFG_FX100_RGMII_75OHM : + priv->is_fiber = true; +break ; + } +/* Disable WoL in 1588 register which is enabled * by default */
Signature · 1 line
2.40.1
PATCH v3 7/13 net: phy: at803x: move specific at8031 config_init to dedicated function
In reply to Christian MarangiMove specific at8031 config_init to dedicated function to make at803x_config_init more generic and tidy things up.
--- drivers/net/phy/at803x.c | 45 ++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 20 deletions(-)
drivers/net/phy/at803x.c +25 -20
@@ -951,27 +951,8 @@ static int at803x_hibernation_mode_config(struct phy_device *phydev)static int at803x_config_init (struct phy_device *phydev) { -struct at803x_priv *priv = phydev->priv;int ret; -if (phydev->drv->phy_id ==ATH8031_PHY_ID ) { -/* Some bootloaders leave the fiber page selected. -* Switch to the appropriate page (fiber or copper), as otherwise we -* read the PHY capabilities from the wrong page. -*/ -phy_lock_mdio_bus (phydev); - ret =at803x_write_page (phydev, - priv->is_fiber ?AT803X_PAGE_FIBER : -AT803X_PAGE_COPPER ); -phy_unlock_mdio_bus (phydev); -if (ret) -return ret; - - ret =at8031_pll_config (phydev); -if (ret <0 ) -return ret; - } -/* The RX and TX delay default is: * after HW reset: RX delay enabled and TX delay disabled * after SW reset: RX delay enabled, while TX delay retains the
@@ -1606,6 +1587,30 @@ static int at8031_probe(struct phy_device *phydev)return ret; } +static int at8031_config_init (struct phy_device *phydev) +{ +struct at803x_priv *priv = phydev->priv; +int ret; + +/* Some bootloaders leave the fiber page selected. +* Switch to the appropriate page (fiber or copper), as otherwise we +* read the PHY capabilities from the wrong page. +*/ +phy_lock_mdio_bus (phydev); + ret =at803x_write_page (phydev, + priv->is_fiber ?AT803X_PAGE_FIBER : +AT803X_PAGE_COPPER ); +phy_unlock_mdio_bus (phydev); +if (ret) +return ret; + + ret =at8031_pll_config (phydev); +if (ret <0 ) +return ret; + +return at803x_config_init (phydev); +} +static int qca83xx_config_init (struct phy_device *phydev) {u8 switch_revision;
@@ -2115,7 +2120,7 @@ static struct phy_driver at803x_driver[] = { .name = "Qualcomm Atheros AR8031/AR8033", .flags = PHY_POLL_CABLE_TEST, .probe = at8031_probe, - .config_init = at803x_config_init, + .config_init = at8031_config_init, .config_aneg = at803x_config_aneg, .soft_reset = genphy_soft_reset, .set_wol = at803x_set_wol,
Signature · 1 line
2.40.1
PATCH v3 8/13 net: phy: at803x: move specific at8031 WOL bits to dedicated function
In reply to Christian MarangiMove specific at8031 WOL enable/disable to dedicated function to make at803x_set_wol more generic.
This is needed in preparation for PHY driver split as qca8081 share the same function to toggle WOL settings.
In this new implementation WOL module in at8031 is enabled after the generic interrupt is setup. This should not cause any problem as the WOL_INT has a separate implementation and only relay on MAC bits.
--- drivers/net/phy/at803x.c | 42 ++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 17 deletions(-)
drivers/net/phy/at803x.c +25 -17
@@ -466,27 +466,11 @@ static int at803x_set_wol(struct phy_device *phydev,phy_write_mmd (phydev,MDIO_MMD_PCS , offsets[i], mac[(i *2 ) +1 ] | (mac[(i *2 )] <<8 )); -/* Enable WOL function for 1588 */ -if (phydev->drv->phy_id ==ATH8031_PHY_ID ) { - ret =phy_modify_mmd (phydev,MDIO_MMD_PCS , -AT803X_PHY_MMD3_WOL_CTRL , -0 ,AT803X_WOL_EN ); -if (ret) -return ret; - }/* Enable WOL interrupt */ ret =phy_modify (phydev,AT803X_INTR_ENABLE ,0 ,AT803X_INTR_ENABLE_WOL );if (ret)return ret; }else { -/* Disable WoL function for 1588 */ -if (phydev->drv->phy_id ==ATH8031_PHY_ID ) { - ret =phy_modify_mmd (phydev,MDIO_MMD_PCS , -AT803X_PHY_MMD3_WOL_CTRL , -AT803X_WOL_EN ,0 ); -if (ret) -return ret; - }/* Disable WOL interrupt */ ret =phy_modify (phydev,AT803X_INTR_ENABLE ,AT803X_INTR_ENABLE_WOL ,0 );if (ret)
@@ -1611,6 +1595,30 @@ static int at8031_config_init(struct phy_device *phydev)return at803x_config_init (phydev); } +static int at8031_set_wol (struct phy_device *phydev, +struct ethtool_wolinfo *wol) +{ +int ret; + +/* First setup MAC address and enable WOL interrupt */ + ret =at803x_set_wol (phydev, wol); +if (ret) +return ret; + +if (wol->wolopts &WAKE_MAGIC ) +/* Enable WOL function for 1588 */ + ret =phy_modify_mmd (phydev,MDIO_MMD_PCS , +AT803X_PHY_MMD3_WOL_CTRL , +0 ,AT803X_WOL_EN ); +else +/* Disable WoL function for 1588 */ + ret =phy_modify_mmd (phydev,MDIO_MMD_PCS , +AT803X_PHY_MMD3_WOL_CTRL , +AT803X_WOL_EN ,0 ); + +return ret; +} +static int qca83xx_config_init (struct phy_device *phydev) {u8 switch_revision;
@@ -2123,7 +2131,7 @@ static struct phy_driver at803x_driver[] = { .config_init = at8031_config_init, .config_aneg = at803x_config_aneg, .soft_reset = genphy_soft_reset, - .set_wol = at803x_set_wol, + .set_wol = at8031_set_wol, .get_wol = at803x_get_wol, .suspend = at803x_suspend, .resume = at803x_resume,
Signature · 1 line
2.40.1
PATCH v3 9/13 net: phy: at803x: move specific at8031 config_intr to dedicated function
In reply to Christian MarangiMove specific at8031 config_intr bits to dedicated function to make at803x_config_initr more generic.
This is needed in preparation for PHY driver split as qca8081 share the same function to setup interrupts.
--- drivers/net/phy/at803x.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-)
drivers/net/phy/at803x.c +24 -6
@@ -990,7 +990,6 @@ static int at803x_ack_interrupt(struct phy_device *phydev)static int at803x_config_intr (struct phy_device *phydev) { -struct at803x_priv *priv = phydev->priv;int err;int value;
@@ -1007,10 +1006,6 @@ static int at803x_config_intr(struct phy_device *phydev) value |=AT803X_INTR_ENABLE_DUPLEX_CHANGED ; value |=AT803X_INTR_ENABLE_LINK_FAIL ; value |=AT803X_INTR_ENABLE_LINK_SUCCESS ; -if (priv->is_fiber) { - value |=AT803X_INTR_ENABLE_LINK_FAIL_BX ; - value |=AT803X_INTR_ENABLE_LINK_SUCCESS_BX ; - } err =phy_write (phydev,AT803X_INTR_ENABLE , value); }else {
@@ -1619,6 +1614,29 @@ static int at8031_set_wol(struct phy_device *phydev,return ret; } +static int at8031_config_intr (struct phy_device *phydev) +{ +struct at803x_priv *priv = phydev->priv; +int err, value =0 ; + +if (phydev->interrupts ==PHY_INTERRUPT_ENABLED && + priv->is_fiber) { +/* Clear any pending interrupts */ + err =at803x_ack_interrupt (phydev); +if (err) +return err; + + value |=AT803X_INTR_ENABLE_LINK_FAIL_BX ; + value |=AT803X_INTR_ENABLE_LINK_SUCCESS_BX ; + + err =phy_set_bits (phydev,AT803X_INTR_ENABLE , value); +if (err) +return err; + } + +return at803x_config_intr (phydev); +} +static int qca83xx_config_init (struct phy_device *phydev) {u8 switch_revision;
@@ -2139,7 +2157,7 @@ static struct phy_driver at803x_driver[] = { .write_page = at803x_write_page, .get_features = at803x_get_features, .read_status = at803x_read_status, - .config_intr = at803x_config_intr, + .config_intr = at8031_config_intr, .handle_interrupt = at803x_handle_interrupt, .get_tunable = at803x_get_tunable, .set_tunable = at803x_set_tunable,
Signature · 1 line
2.40.1
PATCH v3 10/13 net: phy: at803x: make at8031 related DT functions name more specific
In reply to Christian MarangiRename at8031 related DT function name to a more specific name referencing they are only related to at8031 and not to the generic at803x PHY family.
--- drivers/net/phy/at803x.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/net/phy/at803x.c +8 -8
@@ -583,7 +583,7 @@ static int at803x_resume(struct phy_device *phydev)return phy_modify (phydev,MII_BMCR ,BMCR_PDOWN |BMCR_ISOLATE ,0 ); } -static int at803x_rgmii_reg_set_voltage_sel (struct regulator_dev *rdev, +static int at8031_rgmii_reg_set_voltage_sel (struct regulator_dev *rdev,unsigned int selector) {struct phy_device *phydev =rdev_get_drvdata (rdev);
@@ -596,7 +596,7 @@ static int at803x_rgmii_reg_set_voltage_sel(struct regulator_dev *rdev, AT803X_DEBUG_RGMII_1V8, 0); } -static int at803x_rgmii_reg_get_voltage_sel (struct regulator_dev *rdev) +static int at8031_rgmii_reg_get_voltage_sel (struct regulator_dev *rdev) {struct phy_device *phydev =rdev_get_drvdata (rdev);int val;
@@ -610,8 +610,8 @@ static int at803x_rgmii_reg_get_voltage_sel(struct regulator_dev *rdev)static const struct regulator_ops vddio_regulator_ops = { .list_voltage = regulator_list_voltage_table, - .set_voltage_sel = at803x_rgmii_reg_set_voltage_sel, - .get_voltage_sel = at803x_rgmii_reg_get_voltage_sel, + .set_voltage_sel = at8031_rgmii_reg_set_voltage_sel, + .get_voltage_sel = at8031_rgmii_reg_get_voltage_sel, };static const unsigned int vddio_voltage_table[] = {
@@ -666,7 +666,7 @@ static int at8031_register_regulators(struct phy_device *phydev)return 0 ; } -static int at803x_sfp_insert (void *upstream,const struct sfp_eeprom_id *id) +static int at8031_sfp_insert (void *upstream,const struct sfp_eeprom_id *id) {struct phy_device *phydev = upstream;__ETHTOOL_DECLARE_LINK_MODE_MASK (phy_support);
@@ -710,10 +710,10 @@ static int at803x_sfp_insert(void *upstream, const struct sfp_eeprom_id *id)return 0 ; } -static const struct sfp_upstream_ops at803x_sfp_ops = { +static const struct sfp_upstream_ops at8031_sfp_ops = { .attach = phy_sfp_attach, .detach = phy_sfp_detach, - .module_insert = at803x_sfp_insert, + .module_insert = at8031_sfp_insert, };static int at803x_parse_dt (struct phy_device *phydev)
@@ -1519,7 +1519,7 @@ static int at8031_parse_dt(struct phy_device *phydev) }/* Only AR8031/8033 support 1000Base-X for SFP modules */ -return phy_sfp_probe (phydev, &at803x_sfp_ops); +return phy_sfp_probe (phydev, &at8031_sfp_ops); }static int at8031_probe (struct phy_device *phydev)
Signature · 1 line
2.40.1
PATCH v3 11/13 net: phy: at803x: move at8031 functions in dedicated section
In reply to Christian MarangiMove at8031 functions in dedicated section with dedicated at8031 parse_dt and probe.
--- drivers/net/phy/at803x.c | 266 +++++++++++++++++++-------------------- 1 file changed, 133 insertions(+), 133 deletions(-)
drivers/net/phy/at803x.c +133 -133
@@ -583,139 +583,6 @@ static int at803x_resume(struct phy_device *phydev)return phy_modify (phydev,MII_BMCR ,BMCR_PDOWN |BMCR_ISOLATE ,0 ); } -static int at8031_rgmii_reg_set_voltage_sel (struct regulator_dev *rdev, -unsigned int selector) -{ -struct phy_device *phydev =rdev_get_drvdata (rdev); - -if (selector) -return at803x_debug_reg_mask (phydev,AT803X_DEBUG_REG_1F , -0 ,AT803X_DEBUG_RGMII_1V8 ); -else -return at803x_debug_reg_mask (phydev,AT803X_DEBUG_REG_1F , -AT803X_DEBUG_RGMII_1V8 ,0 ); -} - -static int at8031_rgmii_reg_get_voltage_sel (struct regulator_dev *rdev) -{ -struct phy_device *phydev =rdev_get_drvdata (rdev); -int val; - - val =at803x_debug_reg_read (phydev,AT803X_DEBUG_REG_1F ); -if (val <0 ) -return val; - -return (val &AT803X_DEBUG_RGMII_1V8 ) ?1 :0 ; -} - -static const struct regulator_ops vddio_regulator_ops = { - .list_voltage = regulator_list_voltage_table, - .set_voltage_sel = at8031_rgmii_reg_set_voltage_sel, - .get_voltage_sel = at8031_rgmii_reg_get_voltage_sel, -}; - -static const unsigned int vddio_voltage_table[] = { -1500000 , -1800000 , -}; - -static const struct regulator_desc vddio_desc = { - .name ="vddio" , - .of_match =of_match_ptr ("vddio-regulator" ), - .n_voltages =ARRAY_SIZE (vddio_voltage_table), - .volt_table = vddio_voltage_table, - .ops = &vddio_regulator_ops, - .type =REGULATOR_VOLTAGE , - .owner =THIS_MODULE , -}; - -static const struct regulator_ops vddh_regulator_ops = { -}; - -static const struct regulator_desc vddh_desc = { - .name ="vddh" , - .of_match =of_match_ptr ("vddh-regulator" ), - .n_voltages =1 , - .fixed_uV =2500000 , - .ops = &vddh_regulator_ops, - .type =REGULATOR_VOLTAGE , - .owner =THIS_MODULE , -}; - -static int at8031_register_regulators (struct phy_device *phydev) -{ -struct at803x_priv *priv = phydev->priv; -struct device *dev = &phydev->mdio.dev; -struct regulator_config config = { }; - - config.dev = dev; - config.driver_data = phydev; - - priv->vddio_rdev =devm_regulator_register (dev, &vddio_desc, &config); -if (IS_ERR (priv->vddio_rdev)) { -phydev_err (phydev,"failed to register VDDIO regulator\n" ); -return PTR_ERR (priv->vddio_rdev); - } - - priv->vddh_rdev =devm_regulator_register (dev, &vddh_desc, &config); -if (IS_ERR (priv->vddh_rdev)) { -phydev_err (phydev,"failed to register VDDH regulator\n" ); -return PTR_ERR (priv->vddh_rdev); - } - -return 0 ; -} - -static int at8031_sfp_insert (void *upstream,const struct sfp_eeprom_id *id) -{ -struct phy_device *phydev = upstream; -__ETHTOOL_DECLARE_LINK_MODE_MASK (phy_support); -__ETHTOOL_DECLARE_LINK_MODE_MASK (sfp_support); -DECLARE_PHY_INTERFACE_MASK (interfaces); -phy_interface_t iface; - -linkmode_zero (phy_support); - phylink_set(phy_support, 1000baseX_Full); - phylink_set(phy_support, 1000baseT_Full); -phylink_set (phy_support, Autoneg); -phylink_set (phy_support, Pause); -phylink_set (phy_support, Asym_Pause); - -linkmode_zero (sfp_support); -sfp_parse_support (phydev->sfp_bus, id, sfp_support, interfaces); -/* Some modules support 10G modes as well as others we support. -* Mask out non-supported modes so the correct interface is picked. -*/ -linkmode_and (sfp_support, phy_support, sfp_support); - -if (linkmode_empty (sfp_support)) { -dev_err (&phydev->mdio.dev,"incompatible SFP module inserted\n" ); -return -EINVAL ; - } - - iface =sfp_select_interface (phydev->sfp_bus, sfp_support); - -/* Only 1000Base-X is supported by AR8031/8033 as the downstream SerDes -* interface for use with SFP modules. -* However, some copper modules detected as having a preferred SGMII -* interface do default to and function in 1000Base-X mode, so just -* print a warning and allow such modules, as they may have some chance -* of working. -*/ -if (iface ==PHY_INTERFACE_MODE_SGMII ) -dev_warn (&phydev->mdio.dev,"module may not function if 1000Base-X not supported\n" ); -else if (iface !=PHY_INTERFACE_MODE_1000BASEX ) -return -EINVAL ; - -return 0 ; -} - -static const struct sfp_upstream_ops at8031_sfp_ops = { - .attach = phy_sfp_attach, - .detach = phy_sfp_detach, - .module_insert = at8031_sfp_insert, -}; -static int at803x_parse_dt (struct phy_device *phydev) {struct device_node *node = phydev->mdio.dev.of_node;
@@ -1498,6 +1365,139 @@ static int at803x_cable_test_start(struct phy_device *phydev)return 0 ; } +static int at8031_rgmii_reg_set_voltage_sel (struct regulator_dev *rdev, +unsigned int selector) +{ +struct phy_device *phydev =rdev_get_drvdata (rdev); + +if (selector) +return at803x_debug_reg_mask (phydev,AT803X_DEBUG_REG_1F , +0 ,AT803X_DEBUG_RGMII_1V8 ); +else +return at803x_debug_reg_mask (phydev,AT803X_DEBUG_REG_1F , +AT803X_DEBUG_RGMII_1V8 ,0 ); +} + +static int at8031_rgmii_reg_get_voltage_sel (struct regulator_dev *rdev) +{ +struct phy_device *phydev =rdev_get_drvdata (rdev); +int val; + + val =at803x_debug_reg_read (phydev,AT803X_DEBUG_REG_1F ); +if (val <0 ) +return val; + +return (val &AT803X_DEBUG_RGMII_1V8 ) ?1 :0 ; +} + +static const struct regulator_ops vddio_regulator_ops = { + .list_voltage = regulator_list_voltage_table, + .set_voltage_sel = at8031_rgmii_reg_set_voltage_sel, + .get_voltage_sel = at8031_rgmii_reg_get_voltage_sel, +}; + +static const unsigned int vddio_voltage_table[] = { +1500000 , +1800000 , +}; + +static const struct regulator_desc vddio_desc = { + .name ="vddio" , + .of_match =of_match_ptr ("vddio-regulator" ), + .n_voltages =ARRAY_SIZE (vddio_voltage_table), + .volt_table = vddio_voltage_table, + .ops = &vddio_regulator_ops, + .type =REGULATOR_VOLTAGE , + .owner =THIS_MODULE , +}; + +static const struct regulator_ops vddh_regulator_ops = { +}; + +static const struct regulator_desc vddh_desc = { + .name ="vddh" , + .of_match =of_match_ptr ("vddh-regulator" ), + .n_voltages =1 , + .fixed_uV =2500000 , + .ops = &vddh_regulator_ops, + .type =REGULATOR_VOLTAGE , + .owner =THIS_MODULE , +}; + +static int at8031_register_regulators (struct phy_device *phydev) +{ +struct at803x_priv *priv = phydev->priv; +struct device *dev = &phydev->mdio.dev; +struct regulator_config config = { }; + + config.dev = dev; + config.driver_data = phydev; + + priv->vddio_rdev =devm_regulator_register (dev, &vddio_desc, &config); +if (IS_ERR (priv->vddio_rdev)) { +phydev_err (phydev,"failed to register VDDIO regulator\n" ); +return PTR_ERR (priv->vddio_rdev); + } + + priv->vddh_rdev =devm_regulator_register (dev, &vddh_desc, &config); +if (IS_ERR (priv->vddh_rdev)) { +phydev_err (phydev,"failed to register VDDH regulator\n" ); +return PTR_ERR (priv->vddh_rdev); + } + +return 0 ; +} + +static int at8031_sfp_insert (void *upstream,const struct sfp_eeprom_id *id) +{ +struct phy_device *phydev = upstream; +__ETHTOOL_DECLARE_LINK_MODE_MASK (phy_support); +__ETHTOOL_DECLARE_LINK_MODE_MASK (sfp_support); +DECLARE_PHY_INTERFACE_MASK (interfaces); +phy_interface_t iface; + +linkmode_zero (phy_support); + phylink_set(phy_support, 1000baseX_Full); + phylink_set(phy_support, 1000baseT_Full); +phylink_set (phy_support, Autoneg); +phylink_set (phy_support, Pause); +phylink_set (phy_support, Asym_Pause); + +linkmode_zero (sfp_support); +sfp_parse_support (phydev->sfp_bus, id, sfp_support, interfaces); +/* Some modules support 10G modes as well as others we support. +* Mask out non-supported modes so the correct interface is picked. +*/ +linkmode_and (sfp_support, phy_support, sfp_support); + +if (linkmode_empty (sfp_support)) { +dev_err (&phydev->mdio.dev,"incompatible SFP module inserted\n" ); +return -EINVAL ; + } + + iface =sfp_select_interface (phydev->sfp_bus, sfp_support); + +/* Only 1000Base-X is supported by AR8031/8033 as the downstream SerDes +* interface for use with SFP modules. +* However, some copper modules detected as having a preferred SGMII +* interface do default to and function in 1000Base-X mode, so just +* print a warning and allow such modules, as they may have some chance +* of working. +*/ +if (iface ==PHY_INTERFACE_MODE_SGMII ) +dev_warn (&phydev->mdio.dev,"module may not function if 1000Base-X not supported\n" ); +else if (iface !=PHY_INTERFACE_MODE_1000BASEX ) +return -EINVAL ; + +return 0 ; +} + +static const struct sfp_upstream_ops at8031_sfp_ops = { + .attach = phy_sfp_attach, + .detach = phy_sfp_detach, + .module_insert = at8031_sfp_insert, +}; +static int at8031_parse_dt (struct phy_device *phydev) {struct device_node *node = phydev->mdio.dev.of_node;
Signature · 1 line
2.40.1
PATCH v3 12/13 net: phy: at803x: move at8035 specific DT parse to dedicated probe
In reply to Christian MarangiMove at8035 specific DT parse for clock out frequency to dedicated probe to make at803x probe function more generic.
This is to tidy code and no behaviour change are intended.
Detection logic is changed, we check if the clk 25m mask is set and if it's not zero, we assume the qca,clk-out-frequency property is set.
The property is checked in the generic at803x_parse_dt called by at803x_probe.
--- drivers/net/phy/at803x.c | 60 +++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 19 deletions(-)
drivers/net/phy/at803x.c +41 -19
@@ -638,23 +638,6 @@ static int at803x_parse_dt(struct phy_device *phydev) priv->clk_25m_reg |=FIELD_PREP (AT803X_CLK_OUT_MASK , sel); priv->clk_25m_mask |=AT803X_CLK_OUT_MASK ; - -/* Fixup for the AR8030/AR8035. This chip has another mask and -* doesn't support the DSP reference. Eg. the lowest bit of the -* mask. The upper two bits select the same frequencies. Mask -* the lowest bit here. -* -* Warning: -* There was no datasheet for the AR8030 available so this is -* just a guess. But the AR8035 is listed as pin compatible -* to the AR8030 so there might be a good chance it works on -* the AR8030 too. -*/ -if (phydev->drv->phy_id ==ATH8030_PHY_ID || - phydev->drv->phy_id ==ATH8035_PHY_ID ) { - priv->clk_25m_reg &=AT8035_CLK_OUT_MASK ; - priv->clk_25m_mask &=AT8035_CLK_OUT_MASK ; - } } ret =of_property_read_u32 (node,"qca,clk-out-strength" , &strength);
@@ -1637,6 +1620,45 @@ static int at8031_config_intr(struct phy_device *phydev)return at803x_config_intr (phydev); } +static int at8035_parse_dt (struct phy_device *phydev) +{ +struct at803x_priv *priv = phydev->priv; + +/* Mask is set by the generic at803x_parse_dt +* if property is set. Assume property is set +* with the mask not zero. +*/ +if (priv->clk_25m_mask) { +/* Fixup for the AR8030/AR8035. This chip has another mask and +* doesn't support the DSP reference. Eg. the lowest bit of the +* mask. The upper two bits select the same frequencies. Mask +* the lowest bit here. +* +* Warning: +* There was no datasheet for the AR8030 available so this is +* just a guess. But the AR8035 is listed as pin compatible +* to the AR8030 so there might be a good chance it works on +* the AR8030 too. +*/ + priv->clk_25m_reg &=AT8035_CLK_OUT_MASK ; + priv->clk_25m_mask &=AT8035_CLK_OUT_MASK ; + } + +return 0 ; +} + +/* AR8030 and AR8035 shared the same special mask for clk_25m */ +static int at8035_probe (struct phy_device *phydev) +{ +int ret; + + ret =at803x_probe (phydev); +if (ret) +return ret; + +return at8035_parse_dt (phydev); +} +static int qca83xx_config_init (struct phy_device *phydev) {u8 switch_revision;
@@ -2109,7 +2131,7 @@ static struct phy_driver at803x_driver[] = {PHY_ID_MATCH_EXACT (ATH8035_PHY_ID ), .name = "Qualcomm Atheros AR8035", .flags = PHY_POLL_CABLE_TEST, - .probe = at803x_probe, + .probe = at8035_probe, .config_aneg = at803x_config_aneg, .config_init = at803x_config_init, .soft_reset = genphy_soft_reset,
@@ -2130,7 +2152,7 @@ static struct phy_driver at803x_driver[] = { .phy_id = ATH8030_PHY_ID, .name = "Qualcomm Atheros AR8030", .phy_id_mask = AT8030_PHY_ID_MASK, - .probe = at803x_probe, + .probe = at8035_probe, .config_init = at803x_config_init, .link_change_notify = at803x_link_change_notify, .set_wol = at803x_set_wol,
Signature · 1 line
2.40.1
PATCH v3 13/13 net: phy: at803x: drop specific PHY ID check from cable test functions
In reply to Christian MarangiDrop specific PHY ID check for cable test functions for at803x. This is done to make functions more generic. While at it better describe what the functions does by using more symbolic function names.
PHYs that requires to set additional reg are moved to specific function calling the more generic one.
cdt_start and cdt_wait_for_completion are changed to take an additional arg to pass specific values specific to the PHY.
--- drivers/net/phy/at803x.c | 95 +++++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 45 deletions(-)
drivers/net/phy/at803x.c +50 -45
@@ -1222,31 +1222,16 @@ static int at803x_cdt_fault_length(u16 status)return (dt *824 ) /10 ; } -static int at803x_cdt_start (struct phy_device *phydev,int pair) +static int at803x_cdt_start (struct phy_device *phydev, +u32 cdt_start) { -u16 cdt; - -/* qca8081 takes the different bit 15 to enable CDT test */ -if (phydev->drv->phy_id ==QCA8081_PHY_ID ) - cdt =QCA808X_CDT_ENABLE_TEST | -QCA808X_CDT_LENGTH_UNIT | -QCA808X_CDT_INTER_CHECK_DIS ; -else - cdt =FIELD_PREP (AT803X_CDT_MDI_PAIR_MASK , pair) | -AT803X_CDT_ENABLE_TEST ; - -return phy_write (phydev,AT803X_CDT , cdt); +return phy_write (phydev,AT803X_CDT , cdt_start); } -static int at803x_cdt_wait_for_completion (struct phy_device *phydev) +static int at803x_cdt_wait_for_completion (struct phy_device *phydev, +u32 cdt_en) {int val, ret; -u16 cdt_en; - -if (phydev->drv->phy_id ==QCA8081_PHY_ID ) - cdt_en =QCA808X_CDT_ENABLE_TEST ; -else - cdt_en =AT803X_CDT_ENABLE_TEST ;/* One test run takes about 25ms */ ret = phy_read_poll_timeout(phydev, AT803X_CDT, val,
@@ -1266,11 +1251,13 @@ static int at803x_cable_test_one_pair(struct phy_device *phydev, int pair) };int ret, val; - ret =at803x_cdt_start (phydev, pair); + val =FIELD_PREP (AT803X_CDT_MDI_PAIR_MASK , pair) | +AT803X_CDT_ENABLE_TEST ; + ret =at803x_cdt_start (phydev, val);if (ret)return ret; - ret =at803x_cdt_wait_for_completion (phydev); + ret =at803x_cdt_wait_for_completion (phydev,AT803X_CDT_ENABLE_TEST );if (ret)return ret;
@@ -1292,19 +1279,11 @@ static int at803x_cable_test_one_pair(struct phy_device *phydev, int pair) }static int at803x_cable_test_get_status (struct phy_device *phydev, -bool *finished) +bool *finished,unsigned long pair_mask) { -unsigned long pair_mask;int retries =20 ;int pair, ret; -if (phydev->phy_id ==ATH9331_PHY_ID || - phydev->phy_id ==ATH8032_PHY_ID || - phydev->phy_id ==QCA9561_PHY_ID ) - pair_mask =0x3 ; -else - pair_mask =0xf ; - *finished = false;/* According to the datasheet the CDT can be performed when
@@ -1331,7 +1310,7 @@ static int at803x_cable_test_get_status(struct phy_device *phydev,return 0 ; } -static int at803x_cable_test_start (struct phy_device *phydev) +static void at803x_cable_test_autoneg (struct phy_device *phydev) {/* Enable auto-negotiation, but advertise no capabilities, no link * will be established. A restart of the auto-negotiation is not
@@ -1339,11 +1318,11 @@ static int at803x_cable_test_start(struct phy_device *phydev)*/ phy_write (phydev,MII_BMCR ,BMCR_ANENABLE );phy_write (phydev,MII_ADVERTISE ,ADVERTISE_CSMA ); -if (phydev->phy_id !=ATH9331_PHY_ID && - phydev->phy_id !=ATH8032_PHY_ID && - phydev->phy_id !=QCA9561_PHY_ID ) -phy_write (phydev,MII_CTRL1000 ,0 ); +} +static int at803x_cable_test_start (struct phy_device *phydev) +{ +at803x_cable_test_autoneg (phydev);/* we do all the (time consuming) work later */ return 0 ; }
@@ -1620,6 +1599,29 @@ static int at8031_config_intr(struct phy_device *phydev)return at803x_config_intr (phydev); } +/* AR8031 and AR8035 share the same cable test get status reg */ +static int at8031_cable_test_get_status (struct phy_device *phydev, +bool *finished) +{ +return at803x_cable_test_get_status (phydev, finished,0xf ); +} + +/* AR8031 and AR8035 share the same cable test start logic */ +static int at8031_cable_test_start (struct phy_device *phydev) +{ +at803x_cable_test_autoneg (phydev); +phy_write (phydev,MII_CTRL1000 ,0 ); +/* we do all the (time consuming) work later */ +return 0 ; +} + +/* AR8032, AR9331 and QCA9561 share the same cable test get status reg */ +static int at8032_cable_test_get_status (struct phy_device *phydev, +bool *finished) +{ +return at803x_cable_test_get_status (phydev, finished,0x3 ); +} +static int at8035_parse_dt (struct phy_device *phydev) {struct at803x_priv *priv = phydev->priv;
@@ -2043,11 +2045,14 @@ static int qca808x_cable_test_get_status(struct phy_device *phydev, bool *finish *finished = false; - ret =at803x_cdt_start (phydev,0 ); + val =QCA808X_CDT_ENABLE_TEST | +QCA808X_CDT_LENGTH_UNIT | +QCA808X_CDT_INTER_CHECK_DIS ; + ret =at803x_cdt_start (phydev, val);if (ret)return ret; - ret =at803x_cdt_wait_for_completion (phydev); + ret =at803x_cdt_wait_for_completion (phydev,QCA808X_CDT_ENABLE_TEST );if (ret)return ret;
@@ -2145,8 +2150,8 @@ static struct phy_driver at803x_driver[] = { .handle_interrupt = at803x_handle_interrupt, .get_tunable = at803x_get_tunable, .set_tunable = at803x_set_tunable, - .cable_test_start = at803x_cable_test_start, - .cable_test_get_status = at803x_cable_test_get_status, + .cable_test_start = at8031_cable_test_start, + .cable_test_get_status = at8031_cable_test_get_status, }, {/* Qualcomm Atheros AR8030 */ .phy_id = ATH8030_PHY_ID,
@@ -2183,8 +2188,8 @@ static struct phy_driver at803x_driver[] = { .handle_interrupt = at803x_handle_interrupt, .get_tunable = at803x_get_tunable, .set_tunable = at803x_set_tunable, - .cable_test_start = at803x_cable_test_start, - .cable_test_get_status = at803x_cable_test_get_status, + .cable_test_start = at8031_cable_test_start, + .cable_test_get_status = at8031_cable_test_get_status, }, {/* Qualcomm Atheros AR8032 */ PHY_ID_MATCH_EXACT(ATH8032_PHY_ID),
@@ -2199,7 +2204,7 @@ static struct phy_driver at803x_driver[] = { .config_intr = at803x_config_intr, .handle_interrupt = at803x_handle_interrupt, .cable_test_start = at803x_cable_test_start, - .cable_test_get_status = at803x_cable_test_get_status, + .cable_test_get_status = at8032_cable_test_get_status, }, {/* ATHEROS AR9331 */ PHY_ID_MATCH_EXACT(ATH9331_PHY_ID),
@@ -2212,7 +2217,7 @@ static struct phy_driver at803x_driver[] = { .config_intr = at803x_config_intr, .handle_interrupt = at803x_handle_interrupt, .cable_test_start = at803x_cable_test_start, - .cable_test_get_status = at803x_cable_test_get_status, + .cable_test_get_status = at8032_cable_test_get_status, .read_status = at803x_read_status, .soft_reset = genphy_soft_reset, .config_aneg = at803x_config_aneg,
@@ -2228,7 +2233,7 @@ static struct phy_driver at803x_driver[] = { .config_intr = at803x_config_intr, .handle_interrupt = at803x_handle_interrupt, .cable_test_start = at803x_cable_test_start, - .cable_test_get_status = at803x_cable_test_get_status, + .cable_test_get_status = at8032_cable_test_get_status, .read_status = at803x_read_status, .soft_reset = genphy_soft_reset, .config_aneg = at803x_config_aneg,
Signature · 1 line
2.40.1