Skip to content

Commit 3619bf7

Browse files
DimitriFedrauNipaLocal
authored andcommitted
net: phy: Add helper for getting tx amplitude gain
Add helper which returns the tx amplitude gain defined in device tree. 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]> Signed-off-by: NipaLocal <nipa@local>
1 parent 3dcad22 commit 3619bf7

File tree

2 files changed

+39
-18
lines changed

2 files changed

+39
-18
lines changed

drivers/net/phy/phy_device.c

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3096,19 +3096,12 @@ void phy_get_pause(struct phy_device *phydev, bool *tx_pause, bool *rx_pause)
30963096
EXPORT_SYMBOL(phy_get_pause);
30973097

30983098
#if IS_ENABLED(CONFIG_OF_MDIO)
3099-
static int phy_get_int_delay_property(struct device *dev, const char *name)
3099+
static int phy_get_u32_property(struct device *dev, const char *name, u32 *val)
31003100
{
3101-
s32 int_delay;
3102-
int ret;
3103-
3104-
ret = device_property_read_u32(dev, name, &int_delay);
3105-
if (ret)
3106-
return ret;
3107-
3108-
return int_delay;
3101+
return device_property_read_u32(dev, name, val);
31093102
}
31103103
#else
3111-
static int phy_get_int_delay_property(struct device *dev, const char *name)
3104+
static int phy_get_u32_property(struct device *dev, const char *name, u32 *val)
31123105
{
31133106
return -EINVAL;
31143107
}
@@ -3133,12 +3126,12 @@ static int phy_get_int_delay_property(struct device *dev, const char *name)
31333126
s32 phy_get_internal_delay(struct phy_device *phydev, struct device *dev,
31343127
const int *delay_values, int size, bool is_rx)
31353128
{
3136-
s32 delay;
3137-
int i;
3129+
int i, ret;
3130+
u32 delay;
31383131

31393132
if (is_rx) {
3140-
delay = phy_get_int_delay_property(dev, "rx-internal-delay-ps");
3141-
if (delay < 0 && size == 0) {
3133+
ret = phy_get_u32_property(dev, "rx-internal-delay-ps", &delay);
3134+
if (ret < 0 && size == 0) {
31423135
if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
31433136
phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID)
31443137
return 1;
@@ -3147,8 +3140,8 @@ s32 phy_get_internal_delay(struct phy_device *phydev, struct device *dev,
31473140
}
31483141

31493142
} else {
3150-
delay = phy_get_int_delay_property(dev, "tx-internal-delay-ps");
3151-
if (delay < 0 && size == 0) {
3143+
ret = phy_get_u32_property(dev, "tx-internal-delay-ps", &delay);
3144+
if (ret < 0 && size == 0) {
31523145
if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID ||
31533146
phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID)
31543147
return 1;
@@ -3157,8 +3150,8 @@ s32 phy_get_internal_delay(struct phy_device *phydev, struct device *dev,
31573150
}
31583151
}
31593152

3160-
if (delay < 0)
3161-
return delay;
3153+
if (ret < 0)
3154+
return ret;
31623155

31633156
if (size == 0)
31643157
return delay;
@@ -3193,6 +3186,30 @@ s32 phy_get_internal_delay(struct phy_device *phydev, struct device *dev,
31933186
}
31943187
EXPORT_SYMBOL(phy_get_internal_delay);
31953188

3189+
/**
3190+
* phy_get_tx_amplitude_gain - stores tx amplitude gain in @val
3191+
* @phydev: phy_device struct
3192+
* @dev: pointer to the devices device struct
3193+
* @linkmode: linkmode for which the tx amplitude gain should be retrieved
3194+
* @val: tx amplitude gain
3195+
*
3196+
* Returns: 0 on success, < 0 on failure
3197+
*/
3198+
int phy_get_tx_amplitude_gain(struct phy_device *phydev, struct device *dev,
3199+
enum ethtool_link_mode_bit_indices linkmode,
3200+
u32 *val)
3201+
{
3202+
switch (linkmode) {
3203+
case ETHTOOL_LINK_MODE_100baseT_Full_BIT:
3204+
return phy_get_u32_property(dev,
3205+
"tx-amplitude-100base-tx-percent",
3206+
val);
3207+
default:
3208+
return -EINVAL;
3209+
}
3210+
}
3211+
EXPORT_SYMBOL_GPL(phy_get_tx_amplitude_gain);
3212+
31963213
static int phy_led_set_brightness(struct led_classdev *led_cdev,
31973214
enum led_brightness value)
31983215
{

include/linux/phy.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2097,6 +2097,10 @@ void phy_get_pause(struct phy_device *phydev, bool *tx_pause, bool *rx_pause);
20972097
s32 phy_get_internal_delay(struct phy_device *phydev, struct device *dev,
20982098
const int *delay_values, int size, bool is_rx);
20992099

2100+
int phy_get_tx_amplitude_gain(struct phy_device *phydev, struct device *dev,
2101+
enum ethtool_link_mode_bit_indices linkmode,
2102+
u32 *val);
2103+
21002104
void phy_resolve_pause(unsigned long *local_adv, unsigned long *partner_adv,
21012105
bool *tx_pause, bool *rx_pause);
21022106

0 commit comments

Comments
 (0)