Skip to content

Commit

Permalink
Add support for MDIO busses
Browse files Browse the repository at this point in the history
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 <andrew@lunn.ch>
  • Loading branch information
lunn authored and groeck committed Jul 9, 2017
1 parent 0d5ccf6 commit 0880db2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/access.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
5 changes: 5 additions & 0 deletions lib/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions lib/sensors.conf.5
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/sensors.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 6 additions & 0 deletions lib/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0880db2

Please sign in to comment.