Skip to content

Commit 4f3735e

Browse files
DimitriFedraukuba-moo
authored andcommitted
net: phy: dp83822: Add support for changing the transmit amplitude voltage
Add support for changing the transmit amplitude voltage in 100BASE-TX mode. Modifying it can be necessary to compensate losses on the PCB and connector, so the voltages measured on the RJ45 pins are conforming. Signed-off-by: Dimitri Fedrau <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 961ee5a commit 4f3735e

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

drivers/net/phy/dp83822.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#define MII_DP83822_RCSR 0x17
3232
#define MII_DP83822_RESET_CTRL 0x1f
3333
#define MII_DP83822_MLEDCR 0x25
34+
#define MII_DP83822_LDCTRL 0x403
3435
#define MII_DP83822_LEDCFG1 0x460
3536
#define MII_DP83822_IOCTRL1 0x462
3637
#define MII_DP83822_IOCTRL2 0x463
@@ -123,6 +124,9 @@
123124
#define DP83822_IOCTRL1_GPIO1_CTRL GENMASK(2, 0)
124125
#define DP83822_IOCTRL1_GPIO1_CTRL_LED_1 BIT(0)
125126

127+
/* LDCTRL bits */
128+
#define DP83822_100BASE_TX_LINE_DRIVER_SWING GENMASK(7, 4)
129+
126130
/* IOCTRL2 bits */
127131
#define DP83822_IOCTRL2_GPIO2_CLK_SRC GENMASK(6, 4)
128132
#define DP83822_IOCTRL2_GPIO2_CTRL GENMASK(2, 0)
@@ -197,6 +201,7 @@ struct dp83822_private {
197201
bool set_gpio2_clk_out;
198202
u32 gpio2_clk_out;
199203
bool led_pin_enable[DP83822_MAX_LED_PINS];
204+
int tx_amplitude_100base_tx_index;
200205
};
201206

202207
static int dp83822_config_wol(struct phy_device *phydev,
@@ -522,6 +527,12 @@ static int dp83822_config_init(struct phy_device *phydev)
522527
FIELD_PREP(DP83822_IOCTRL2_GPIO2_CLK_SRC,
523528
dp83822->gpio2_clk_out));
524529

530+
if (dp83822->tx_amplitude_100base_tx_index >= 0)
531+
phy_modify_mmd(phydev, MDIO_MMD_VEND2, MII_DP83822_LDCTRL,
532+
DP83822_100BASE_TX_LINE_DRIVER_SWING,
533+
FIELD_PREP(DP83822_100BASE_TX_LINE_DRIVER_SWING,
534+
dp83822->tx_amplitude_100base_tx_index));
535+
525536
err = dp83822_config_init_leds(phydev);
526537
if (err)
527538
return err;
@@ -720,6 +731,11 @@ static int dp83822_phy_reset(struct phy_device *phydev)
720731
}
721732

722733
#ifdef CONFIG_OF_MDIO
734+
static const u32 tx_amplitude_100base_tx_gain[] = {
735+
80, 82, 83, 85, 87, 88, 90, 92,
736+
93, 95, 97, 98, 100, 102, 103, 105,
737+
};
738+
723739
static int dp83822_of_init_leds(struct phy_device *phydev)
724740
{
725741
struct device_node *node = phydev->mdio.dev.of_node;
@@ -780,6 +796,8 @@ static int dp83822_of_init(struct phy_device *phydev)
780796
struct dp83822_private *dp83822 = phydev->priv;
781797
struct device *dev = &phydev->mdio.dev;
782798
const char *of_val;
799+
int i, ret;
800+
u32 val;
783801

784802
/* Signal detection for the PHY is only enabled if the FX_EN and the
785803
* SD_EN pins are strapped. Signal detection can only enabled if FX_EN
@@ -815,6 +833,26 @@ static int dp83822_of_init(struct phy_device *phydev)
815833
dp83822->set_gpio2_clk_out = true;
816834
}
817835

836+
dp83822->tx_amplitude_100base_tx_index = -1;
837+
ret = phy_get_tx_amplitude_gain(phydev, dev,
838+
ETHTOOL_LINK_MODE_100baseT_Full_BIT,
839+
&val);
840+
if (!ret) {
841+
for (i = 0; i < ARRAY_SIZE(tx_amplitude_100base_tx_gain); i++) {
842+
if (tx_amplitude_100base_tx_gain[i] == val) {
843+
dp83822->tx_amplitude_100base_tx_index = i;
844+
break;
845+
}
846+
}
847+
848+
if (dp83822->tx_amplitude_100base_tx_index < 0) {
849+
phydev_err(phydev,
850+
"Invalid value for tx-amplitude-100base-tx-percent property (%u)\n",
851+
val);
852+
return -EINVAL;
853+
}
854+
}
855+
818856
return dp83822_of_init_leds(phydev);
819857
}
820858

0 commit comments

Comments
 (0)