-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'net-phy-realtek-add-hwmon-support'
Heiner Kallweit says: ==================== net: phy: realtek: add hwmon support This adds hwmon support for the temperature sensor on RTL822x. It's available on the standalone versions of the PHY's, and on the internal PHY's of RTL8125B(P)/RTL8125D/RTL8126. ==================== Link: https://patch.msgid.link/7319d8f9-2d6f-4522-92e8-a8a4990042fb@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
- Loading branch information
Showing
7 changed files
with
128 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# SPDX-License-Identifier: GPL-2.0-only | ||
config REALTEK_PHY | ||
tristate "Realtek PHYs" | ||
help | ||
Currently supports RTL821x/RTL822x and fast ethernet PHYs | ||
|
||
config REALTEK_PHY_HWMON | ||
def_bool REALTEK_PHY && HWMON | ||
depends on !(REALTEK_PHY=y && HWMON=m) | ||
help | ||
Optional hwmon support for the temperature sensor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# SPDX-License-Identifier: GPL-2.0 | ||
realtek-y += realtek_main.o | ||
realtek-$(CONFIG_REALTEK_PHY_HWMON) += realtek_hwmon.o | ||
obj-$(CONFIG_REALTEK_PHY) += realtek.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
|
||
#ifndef REALTEK_H | ||
#define REALTEK_H | ||
|
||
#include <linux/phy.h> | ||
|
||
int rtl822x_hwmon_init(struct phy_device *phydev); | ||
|
||
#endif /* REALTEK_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// SPDX-License-Identifier: GPL-2.0+ | ||
/* | ||
* HWMON support for Realtek PHY's | ||
* | ||
* Author: Heiner Kallweit <hkallweit1@gmail.com> | ||
*/ | ||
|
||
#include <linux/hwmon.h> | ||
#include <linux/phy.h> | ||
|
||
#include "realtek.h" | ||
|
||
#define RTL822X_VND2_TSALRM 0xa662 | ||
#define RTL822X_VND2_TSRR 0xbd84 | ||
#define RTL822X_VND2_TSSR 0xb54c | ||
|
||
static int rtl822x_hwmon_get_temp(int raw) | ||
{ | ||
if (raw >= 512) | ||
raw -= 1024; | ||
|
||
return 1000 * raw / 2; | ||
} | ||
|
||
static int rtl822x_hwmon_read(struct device *dev, enum hwmon_sensor_types type, | ||
u32 attr, int channel, long *val) | ||
{ | ||
struct phy_device *phydev = dev_get_drvdata(dev); | ||
int raw; | ||
|
||
switch (attr) { | ||
case hwmon_temp_input: | ||
raw = phy_read_mmd(phydev, MDIO_MMD_VEND2, RTL822X_VND2_TSRR) & 0x3ff; | ||
*val = rtl822x_hwmon_get_temp(raw); | ||
break; | ||
case hwmon_temp_max: | ||
/* Chip reduces speed to 1G if threshold is exceeded */ | ||
raw = phy_read_mmd(phydev, MDIO_MMD_VEND2, RTL822X_VND2_TSSR) >> 6; | ||
*val = rtl822x_hwmon_get_temp(raw); | ||
break; | ||
default: | ||
return -EINVAL; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
static const struct hwmon_ops rtl822x_hwmon_ops = { | ||
.visible = 0444, | ||
.read = rtl822x_hwmon_read, | ||
}; | ||
|
||
static const struct hwmon_channel_info * const rtl822x_hwmon_info[] = { | ||
HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT | HWMON_T_MAX), | ||
NULL | ||
}; | ||
|
||
static const struct hwmon_chip_info rtl822x_hwmon_chip_info = { | ||
.ops = &rtl822x_hwmon_ops, | ||
.info = rtl822x_hwmon_info, | ||
}; | ||
|
||
int rtl822x_hwmon_init(struct phy_device *phydev) | ||
{ | ||
struct device *hwdev, *dev = &phydev->mdio.dev; | ||
const char *name; | ||
|
||
/* Ensure over-temp alarm is reset. */ | ||
phy_clear_bits_mmd(phydev, MDIO_MMD_VEND2, RTL822X_VND2_TSALRM, 3); | ||
|
||
name = devm_hwmon_sanitize_name(dev, dev_name(dev)); | ||
if (IS_ERR(name)) | ||
return PTR_ERR(name); | ||
|
||
hwdev = devm_hwmon_device_register_with_info(dev, name, phydev, | ||
&rtl822x_hwmon_chip_info, | ||
NULL); | ||
return PTR_ERR_OR_ZERO(hwdev); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters