Changeset 4687

Show
Ignore:
Timestamp:
08/19/07 17:04:29 (1 year ago)
Author:
khali
Message:

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.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lm-sensors/branches/lm-sensors-3.0.0/lib/access.c

    r4686 r4687  
    327327        /* bus types with several instances */ 
    328328        for (i = 0; i < sensors_proc_bus_count; i++) 
    329                 if (sensors_proc_bus[i].number == bus->nr) 
     329                if (sensors_proc_bus[i].bus.type == bus->type && 
     330                    sensors_proc_bus[i].bus.nr == bus->nr) 
    330331                        return sensors_proc_bus[i].adapter; 
    331332        return NULL; 
  • lm-sensors/branches/lm-sensors-3.0.0/lib/conf-parse.y

    r4465 r4687  
    9595  sensors_chip_name_list chips; 
    9696  sensors_expr *expr; 
    97   int bus; 
     97  sensors_bus_id bus; 
    9898  sensors_chip_name chip; 
    9999  int line; 
     
    119119%type <chips> chip_name_list 
    120120%type <expr> expression 
    121 %type <bus> i2cbus_name 
     121%type <bus> bus_id 
    122122%type <name> adapter_name 
    123123%type <name> function_name 
     
    142142; 
    143143 
    144 bus_statement:    BUS i2cbus_name adapter_name 
     144bus_statement:    BUS bus_id adapter_name 
    145145                  { sensors_bus new_el; 
    146146                    new_el.lineno = $1; 
    147                     new_el.number = $2; 
     147                   new_el.bus = $2; 
    148148                    new_el.adapter = $3; 
    149149                    bus_add_el(&new_el); 
     
    288288; 
    289289 
    290 i2cbus_name:    NAME 
    291                   { int res = sensors_parse_i2cbus_name($1,&$$); 
     290bus_id:                 NAME 
     291                  { int res = sensors_parse_bus_id($1,&$$); 
    292292                    free($1); 
    293293                    if (res) { 
    294                       sensors_yyerror("Parse error in i2c bus name"); 
     294                      sensors_yyerror("Parse error in bus id"); 
    295295                      YYERROR; 
    296296                    } 
  • lm-sensors/branches/lm-sensors-3.0.0/lib/data.c

    r4686 r4687  
    168168} 
    169169 
    170 int sensors_parse_i2cbus_name(const char *name, int *res) 
     170int sensors_parse_bus_id(const char *name, sensors_bus_id *bus) 
    171171{ 
    172172        char *endptr; 
     
    176176        } 
    177177        name += 4; 
    178         *res = strtoul(name, &endptr, 10); 
    179         if (*name == '\0' || *endptr != '\0' || *res < 0) 
     178        bus->type = SENSORS_BUS_TYPE_I2C; 
     179        bus->nr = strtoul(name, &endptr, 10); 
     180        if (*name == '\0' || *endptr != '\0' || bus->nr < 0) 
    180181                return -SENSORS_ERR_BUS_NAME; 
    181182        return 0; 
     
    186187        int i, j; 
    187188        for (i = 0; i < sensors_config_busses_count; i++) 
    188                 if (name->bus.type == SENSORS_BUS_TYPE_I2C && 
    189                     sensors_config_busses[i].number == name->bus.nr) 
     189                if (sensors_config_busses[i].bus.type == name->bus.type && 
     190                    sensors_config_busses[i].bus.nr == name->bus.nr) 
    190191                        break; 
    191192 
    192193        if (i == sensors_config_busses_count) { 
    193                 sensors_parse_error("Undeclared i2c bus referenced", lineno); 
     194                sensors_parse_error("Undeclared bus id referenced", lineno); 
    194195                name->bus.nr = sensors_proc_bus_count; 
    195196                return -SENSORS_ERR_BUS_NAME; 
     
    200201                if (!strcmp(sensors_config_busses[i].adapter, 
    201202                            sensors_proc_bus[j].adapter)) { 
    202                         name->bus.nr = sensors_proc_bus[j].number; 
     203                        name->bus.nr = sensors_proc_bus[j].bus.nr; 
    203204                        return 0; 
    204205                } 
  • lm-sensors/branches/lm-sensors-3.0.0/lib/data.h

    r4545 r4687  
    111111} sensors_chip; 
    112112 
    113 /* Config file bus declaration: the i2c bus number, combined with adapter 
     113/* Config file bus declaration: the bus type and number, combined with adapter 
    114114   name */ 
    115115typedef struct sensors_bus { 
    116   int number
     116  sensors_bus_id bus
    117117  char *adapter; 
    118118  int lineno; 
     
    176176 
    177177 
    178 /* Parse an i2c bus name into its components. Returns 0 on succes, a value from 
     178/* Parse a bus id into its components. Returns 0 on succes, a value from 
    179179   error.h on failure. */ 
    180 int sensors_parse_i2cbus_name(const char *name, int *res); 
     180int sensors_parse_bus_id(const char *name, sensors_bus_id *bus); 
    181181 
    182182#endif /* def LIB_SENSORS_DATA_H */ 
  • lm-sensors/branches/lm-sensors-3.0.0/lib/sysfs.c

    r4686 r4687  
    381381                        continue; 
    382382 
    383                 if (sscanf(clsdev->name, "i2c-%d", &entry.number) != 1 || 
    384                     entry.number == 9191) /* legacy ISA */ 
     383                if (sscanf(clsdev->name, "i2c-%hd", &entry.bus.nr) != 1 || 
     384                    entry.bus.nr == 9191) /* legacy ISA */ 
    385385                        continue; 
     386                entry.bus.type = SENSORS_BUS_TYPE_I2C; 
    386387 
    387388                /* NB: attr->value[attr->len-1] == '\n'; chop that off */