From 5524486161de68e48508331590ec9cf3c7f22434 Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Sun, 19 Aug 2007 15:07:05 +0000 Subject: [PATCH] Add support for hardware monitoring chips on SPI buses. SPI bus statements in the configuration file are not yet supported, as SPI buses don't have a name attribute yet, it's not possible to identify them and thus no substitution is possible. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4689 7894878c-1315-0410-8ee3-d5d059ff63e0 --- CHANGES | 1 + lib/access.c | 4 ++++ lib/data.c | 12 +++++++++--- lib/sensors.h | 1 + lib/sysfs.c | 4 ++++ 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index b2e4c197..8b67a2a0 100644 --- a/CHANGES +++ b/CHANGES @@ -23,6 +23,7 @@ SVN HEAD Drop support for dummy type New function sensors_snprintf_chip_name() Drop support for dashes in chip names + Add support for devices on SPI adapters Makefile: Drop the package and version targets Man page sensors.conf.5: Update the chip statement section Programs doc/*: Delete, obsolete diff --git a/lib/access.c b/lib/access.c index 0e7ba06c..245177cc 100644 --- a/lib/access.c +++ b/lib/access.c @@ -322,6 +322,10 @@ const char *sensors_get_adapter_name(const sensors_bus_id *bus) return "ISA adapter"; case SENSORS_BUS_TYPE_PCI: return "PCI adapter"; + /* SPI should not be here, but for now SPI adapters have no name + so we don't have any custom string to return. */ + case SENSORS_BUS_TYPE_SPI: + return "SPI adapter"; } /* bus types with several instances */ diff --git a/lib/data.c b/lib/data.c index 2bae021f..6e0dbc9d 100644 --- a/lib/data.c +++ b/lib/data.c @@ -106,15 +106,18 @@ int sensors_parse_chip_name(const char *name, sensors_chip_name *res) res->bus.type = SENSORS_BUS_TYPE_ISA; else if (!strncmp(name, "pci", dash - name)) res->bus.type = SENSORS_BUS_TYPE_PCI; + else if (!strncmp(name, "spi", dash - name)) + res->bus.type = SENSORS_BUS_TYPE_SPI; else goto ERROR; name = dash + 1; - /* Some bus types (i2c) have an additional bus number. For these, the - next part is either a "*" (any bus of that type) or a decimal - number. */ + /* Some bus types (i2c, spi) have an additional bus number. + For these, the next part is either a "*" (any bus of that type) + or a decimal number. */ switch (res->bus.type) { case SENSORS_BUS_TYPE_I2C: + case SENSORS_BUS_TYPE_SPI: if (!strncmp(name, "*-", 2)) { res->bus.nr = SENSORS_BUS_NR_ANY; name += 2; @@ -162,6 +165,9 @@ int sensors_snprintf_chip_name(char *str, size_t size, case SENSORS_BUS_TYPE_I2C: return snprintf(str, size, "%s-i2c-%hd-%02x", chip->prefix, chip->bus.nr, chip->addr); + case SENSORS_BUS_TYPE_SPI: + return snprintf(str, size, "%s-spi-%hd-%x", chip->prefix, + chip->bus.nr, chip->addr); } return -SENSORS_ERR_CHIP_NAME; diff --git a/lib/sensors.h b/lib/sensors.h index a2350cac..f44c9430 100644 --- a/lib/sensors.h +++ b/lib/sensors.h @@ -33,6 +33,7 @@ #define SENSORS_BUS_TYPE_I2C 0 #define SENSORS_BUS_TYPE_ISA 1 #define SENSORS_BUS_TYPE_PCI 2 +#define SENSORS_BUS_TYPE_SPI 3 #define SENSORS_BUS_NR_ANY (-1) #define SENSORS_BUS_NR_IGNORE (-2) diff --git a/lib/sysfs.c b/lib/sysfs.c index e6544b73..9ee2dfd8 100644 --- a/lib/sysfs.c +++ b/lib/sysfs.c @@ -252,6 +252,10 @@ static int sensors_read_one_sysfs_chip(struct sysfs_device *dev) sysfs_close_attribute(bus_attr); } } + } else if (sscanf(dev->name, "spi%hd.%d", &entry.chip.bus.nr, + &entry.chip.addr) == 2) { + /* SPI */ + entry.chip.bus.type = SENSORS_BUS_TYPE_SPI; } else if (sscanf(dev->name, "%*[a-z0-9_].%d", &entry.chip.addr) == 1) { /* must be new ISA (platform driver) */ entry.chip.bus.type = SENSORS_BUS_TYPE_ISA;