mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-10-24 12:04:33 +00:00
Support more bus types (part 2 of 2). Originally libsensors was very
i2c-centric. Make it more neutral so that we can cleanly support additional bus types such as SPI or One-Wire. This second part updates sensors_bus to use sensors_bus_id. Thanks to Mark M. Hoffman for showing me how the configuration file parser could be modified to support that change. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4687 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
1 parent
7ee15371df
commit
a74addb5d4
5 files changed
+24
-21
No files matched your search
+2
-1
@@ -326,7 +326,8 @@ const char *sensors_get_adapter_name(const sensors_bus_id *bus)
|
||||
|
||||
/* bus types with several instances */
|
||||
for (i = 0; i < sensors_proc_bus_count; i++)
|
||||
if (sensors_proc_bus[i].number == bus->nr)
|
||||
if (sensors_proc_bus[i].bus.type == bus->type &&
|
||||
sensors_proc_bus[i].bus.nr == bus->nr)
|
||||
return sensors_proc_bus[i].adapter;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
+7
-7
@@ -94,7 +94,7 @@ static sensors_chip *current_chip = NULL;
|
||||
void *nothing;
|
||||
sensors_chip_name_list chips;
|
||||
sensors_expr *expr;
|
||||
int bus;
|
||||
sensors_bus_id bus;
|
||||
sensors_chip_name chip;
|
||||
int line;
|
||||
}
|
||||
@@ -118,7 +118,7 @@ static sensors_chip *current_chip = NULL;
|
||||
|
||||
%type <chips> chip_name_list
|
||||
%type <expr> expression
|
||||
%type <bus> i2cbus_name
|
||||
%type <bus> bus_id
|
||||
%type <name> adapter_name
|
||||
%type <name> function_name
|
||||
%type <name> string
|
||||
@@ -141,10 +141,10 @@ line: bus_statement EOL
|
||||
| error EOL
|
||||
;
|
||||
|
||||
bus_statement: BUS i2cbus_name adapter_name
|
||||
bus_statement: BUS bus_id adapter_name
|
||||
{ sensors_bus new_el;
|
||||
new_el.lineno = $1;
|
||||
new_el.number = $2;
|
||||
new_el.bus = $2;
|
||||
new_el.adapter = $3;
|
||||
bus_add_el(&new_el);
|
||||
}
|
||||
@@ -287,11 +287,11 @@ expression: FLOAT
|
||||
}
|
||||
;
|
||||
|
||||
i2cbus_name: NAME
|
||||
{ int res = sensors_parse_i2cbus_name($1,&$$);
|
||||
bus_id: NAME
|
||||
{ int res = sensors_parse_bus_id($1,&$$);
|
||||
free($1);
|
||||
if (res) {
|
||||
sensors_yyerror("Parse error in i2c bus name");
|
||||
sensors_yyerror("Parse error in bus id");
|
||||
YYERROR;
|
||||
}
|
||||
}
|
||||
|
||||
+8
-7
@@ -167,7 +167,7 @@ int sensors_snprintf_chip_name(char *str, size_t size,
|
||||
return -SENSORS_ERR_CHIP_NAME;
|
||||
}
|
||||
|
||||
int sensors_parse_i2cbus_name(const char *name, int *res)
|
||||
int sensors_parse_bus_id(const char *name, sensors_bus_id *bus)
|
||||
{
|
||||
char *endptr;
|
||||
|
||||
@@ -175,8 +175,9 @@ int sensors_parse_i2cbus_name(const char *name, int *res)
|
||||
return -SENSORS_ERR_BUS_NAME;
|
||||
}
|
||||
name += 4;
|
||||
*res = strtoul(name, &endptr, 10);
|
||||
if (*name == '\0' || *endptr != '\0' || *res < 0)
|
||||
bus->type = SENSORS_BUS_TYPE_I2C;
|
||||
bus->nr = strtoul(name, &endptr, 10);
|
||||
if (*name == '\0' || *endptr != '\0' || bus->nr < 0)
|
||||
return -SENSORS_ERR_BUS_NAME;
|
||||
return 0;
|
||||
}
|
||||
@@ -185,12 +186,12 @@ int sensors_substitute_chip(sensors_chip_name *name, int lineno)
|
||||
{
|
||||
int i, j;
|
||||
for (i = 0; i < sensors_config_busses_count; i++)
|
||||
if (name->bus.type == SENSORS_BUS_TYPE_I2C &&
|
||||
sensors_config_busses[i].number == name->bus.nr)
|
||||
if (sensors_config_busses[i].bus.type == name->bus.type &&
|
||||
sensors_config_busses[i].bus.nr == name->bus.nr)
|
||||
break;
|
||||
|
||||
if (i == sensors_config_busses_count) {
|
||||
sensors_parse_error("Undeclared i2c bus referenced", lineno);
|
||||
sensors_parse_error("Undeclared bus id referenced", lineno);
|
||||
name->bus.nr = sensors_proc_bus_count;
|
||||
return -SENSORS_ERR_BUS_NAME;
|
||||
}
|
||||
@@ -199,7 +200,7 @@ int sensors_substitute_chip(sensors_chip_name *name, int lineno)
|
||||
for (j = 0; j < sensors_proc_bus_count; j++) {
|
||||
if (!strcmp(sensors_config_busses[i].adapter,
|
||||
sensors_proc_bus[j].adapter)) {
|
||||
name->bus.nr = sensors_proc_bus[j].number;
|
||||
name->bus.nr = sensors_proc_bus[j].bus.nr;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -110,10 +110,10 @@ typedef struct sensors_chip {
|
||||
int lineno;
|
||||
} sensors_chip;
|
||||
|
||||
/* Config file bus declaration: the i2c bus number, combined with adapter
|
||||
/* Config file bus declaration: the bus type and number, combined with adapter
|
||||
name */
|
||||
typedef struct sensors_bus {
|
||||
int number;
|
||||
sensors_bus_id bus;
|
||||
char *adapter;
|
||||
int lineno;
|
||||
} sensors_bus;
|
||||
@@ -175,8 +175,8 @@ extern int sensors_proc_bus_max;
|
||||
int sensors_substitute_busses(void);
|
||||
|
||||
|
||||
/* Parse an i2c bus name into its components. Returns 0 on succes, a value from
|
||||
/* Parse a bus id into its components. Returns 0 on succes, a value from
|
||||
error.h on failure. */
|
||||
int sensors_parse_i2cbus_name(const char *name, int *res);
|
||||
int sensors_parse_bus_id(const char *name, sensors_bus_id *bus);
|
||||
|
||||
#endif /* def LIB_SENSORS_DATA_H */
|
||||
+3
-2
@@ -380,9 +380,10 @@ int sensors_read_sysfs_bus(void)
|
||||
(attr = sysfs_get_device_attr(dev, "name"))))
|
||||
continue;
|
||||
|
||||
if (sscanf(clsdev->name, "i2c-%d", &entry.number) != 1 ||
|
||||
entry.number == 9191) /* legacy ISA */
|
||||
if (sscanf(clsdev->name, "i2c-%hd", &entry.bus.nr) != 1 ||
|
||||
entry.bus.nr == 9191) /* legacy ISA */
|
||||
continue;
|
||||
entry.bus.type = SENSORS_BUS_TYPE_I2C;
|
||||
|
||||
/* NB: attr->value[attr->len-1] == '\n'; chop that off */
|
||||
entry.adapter = strndup(attr->value, attr->len - 1);
|
||||
|
||||
Reference in new issue
Block a user