From 0880db23b98500c704422fcbfaf5ac9d85c20c0f Mon Sep 17 00:00:00 2001 From: Andrew Lunn Date: Sat, 8 Jul 2017 18:51:42 -0500 Subject: [PATCH] Add support for MDIO busses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Marvell Ethernet PHYs can contain a temperature sensor, which the kernel exports as an HWMON device. The PHY is on an MDIO bus. Add support for this bus types to libsensors. The sensor is then displayed by sensors(1): socaipsbus02100000ethernet02188000mdioswitch0mdio01-mdio-1 Adapter: MDIO adapter temp1: +54.0°C (crit = +100.0°C) Signed-off-by: Andrew Lunn --- lib/access.c | 2 ++ lib/data.c | 5 +++++ lib/sensors.conf.5 | 5 +++-- lib/sensors.h | 1 + lib/sysfs.c | 6 ++++++ 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/access.c b/lib/access.c index 2adeed44..f63634ec 100644 --- a/lib/access.c +++ b/lib/access.c @@ -367,6 +367,8 @@ const char *sensors_get_adapter_name(const sensors_bus_id *bus) HID buses have a name nor where to find it. */ case SENSORS_BUS_TYPE_HID: return "HID adapter"; + case SENSORS_BUS_TYPE_MDIO: + return "MDIO adapter"; } /* bus types with several instances */ diff --git a/lib/data.c b/lib/data.c index 69f86466..937709f2 100644 --- a/lib/data.c +++ b/lib/data.c @@ -123,6 +123,8 @@ int sensors_parse_chip_name(const char *name, sensors_chip_name *res) res->bus.type = SENSORS_BUS_TYPE_ACPI; else if (!strncmp(name, "hid", dash - name)) res->bus.type = SENSORS_BUS_TYPE_HID; + else if (!strncmp(name, "mdio", dash - name)) + res->bus.type = SENSORS_BUS_TYPE_MDIO; else goto ERROR; name = dash + 1; @@ -193,6 +195,9 @@ int sensors_snprintf_chip_name(char *str, size_t size, case SENSORS_BUS_TYPE_HID: return snprintf(str, size, "%s-hid-%hd-%x", chip->prefix, chip->bus.nr, chip->addr); + case SENSORS_BUS_TYPE_MDIO: + return snprintf(str, size, "%s-mdio-%x", chip->prefix, + chip->addr); } return -SENSORS_ERR_CHIP_NAME; diff --git a/lib/sensors.conf.5 b/lib/sensors.conf.5 index dbf1ba21..d8695239 100644 --- a/lib/sensors.conf.5 +++ b/lib/sensors.conf.5 @@ -86,9 +86,10 @@ The name of the bus is either .IR isa , .IR pci , .IR virtual , -.I spi-* -or +.I spi-*, .I i2c-N +or +.I mdio with .I N being a bus number as bound with a diff --git a/lib/sensors.h b/lib/sensors.h index ed2d9a80..4c4b60ab 100644 --- a/lib/sensors.h +++ b/lib/sensors.h @@ -44,6 +44,7 @@ #define SENSORS_BUS_TYPE_VIRTUAL 4 #define SENSORS_BUS_TYPE_ACPI 5 #define SENSORS_BUS_TYPE_HID 6 +#define SENSORS_BUS_TYPE_MDIO 7 #define SENSORS_BUS_NR_ANY (-1) #define SENSORS_BUS_NR_IGNORE (-2) diff --git a/lib/sysfs.c b/lib/sysfs.c index f44a88de..dcc6af5a 100644 --- a/lib/sysfs.c +++ b/lib/sysfs.c @@ -717,6 +717,12 @@ static int sensors_read_one_sysfs_chip(const char *dev_path, /* As of kernel 2.6.32, the hid device names don't look good */ entry.chip.bus.nr = bus; entry.chip.addr = id; + } else + if (subsys && !strcmp(subsys, "mdio_bus")) { + if (sscanf(dev_name, "%*[^:]:%d", &entry.chip.addr) != 1) + entry.chip.addr = 0; + entry.chip.bus.type = SENSORS_BUS_TYPE_MDIO; + entry.chip.bus.nr = 0; } else { /* Ignore unknown device */ err = 0;