Changeset 4686
- Timestamp:
- 08/19/07 17:03:50 (1 year ago)
- Files:
-
- lm-sensors/branches/lm-sensors-3.0.0/lib/access.c (modified) (4 diffs)
- lm-sensors/branches/lm-sensors-3.0.0/lib/data.c (modified) (8 diffs)
- lm-sensors/branches/lm-sensors-3.0.0/lib/sensors.h (modified) (4 diffs)
- lm-sensors/branches/lm-sensors-3.0.0/lib/sysfs.c (modified) (3 diffs)
- lm-sensors/branches/lm-sensors-3.0.0/prog/sensord/args.c (modified) (1 diff)
- lm-sensors/branches/lm-sensors-3.0.0/prog/sensors/main.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
lm-sensors/branches/lm-sensors-3.0.0/lib/access.c
r4676 r4686 2 2 access.c - Part of libsensors, a Linux library for reading sensor data. 3 3 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> 4 Copyright (C) 2007 Jean Delvare <khali@linux-fr.org> 4 5 5 6 This program is free software; you can redistribute it and/or modify … … 42 43 return 0; 43 44 44 if ((chip1->bus != SENSORS_CHIP_NAME_BUS_ANY) && 45 (chip2->bus != SENSORS_CHIP_NAME_BUS_ANY) && 46 (chip1->bus != chip2->bus)) { 47 48 if ((chip1->bus == SENSORS_CHIP_NAME_BUS_ISA) || 49 (chip2->bus == SENSORS_CHIP_NAME_BUS_ISA)) 50 return 0; 51 52 if ((chip1->bus == SENSORS_CHIP_NAME_BUS_PCI) || 53 (chip2->bus == SENSORS_CHIP_NAME_BUS_PCI)) 54 return 0; 55 56 if ((chip1->bus != SENSORS_CHIP_NAME_BUS_ANY_I2C) && 57 (chip2->bus != SENSORS_CHIP_NAME_BUS_ANY_I2C)) 58 return 0; 59 } 45 if ((chip1->bus.type != SENSORS_BUS_TYPE_ANY) && 46 (chip2->bus.type != SENSORS_BUS_TYPE_ANY) && 47 (chip1->bus.type != chip2->bus.type)) 48 return 0; 49 50 if ((chip1->bus.nr != SENSORS_BUS_NR_ANY) && 51 (chip2->bus.nr != SENSORS_BUS_NR_ANY) && 52 (chip1->bus.nr != chip2->bus.nr)) 53 return 0; 60 54 61 55 if ((chip1->addr != chip2->addr) && … … 137 131 { 138 132 if ((chip->prefix == SENSORS_CHIP_NAME_PREFIX_ANY) || 139 (chip->bus == SENSORS_CHIP_NAME_BUS_ANY) ||140 (chip->bus == SENSORS_CHIP_NAME_BUS_ANY_I2C) ||133 (chip->bus.type == SENSORS_BUS_TYPE_ANY) || 134 (chip->bus.nr == SENSORS_BUS_NR_ANY) || 141 135 (chip->addr == SENSORS_CHIP_NAME_ADDR_ANY)) 142 136 return 1; … … 319 313 } 320 314 321 const char *sensors_get_adapter_name( int bus_nr)315 const char *sensors_get_adapter_name(const sensors_bus_id *bus) 322 316 { 323 317 int i; 324 318 325 if (bus_nr == SENSORS_CHIP_NAME_BUS_ISA) 319 /* bus types with a single instance */ 320 switch (bus->type) { 321 case SENSORS_BUS_TYPE_ISA: 326 322 return "ISA adapter"; 327 if (bus_nr == SENSORS_CHIP_NAME_BUS_PCI)323 case SENSORS_BUS_TYPE_PCI: 328 324 return "PCI adapter"; 325 } 326 327 /* bus types with several instances */ 329 328 for (i = 0; i < sensors_proc_bus_count; i++) 330 if (sensors_proc_bus[i].number == bus _nr)329 if (sensors_proc_bus[i].number == bus->nr) 331 330 return sensors_proc_bus[i].adapter; 332 331 return NULL; lm-sensors/branches/lm-sensors-3.0.0/lib/data.c
r4678 r4686 93 93 type and an address. */ 94 94 if (!strcmp(name, "*")) { 95 res->bus = SENSORS_CHIP_NAME_BUS_ANY; 95 res->bus.type = SENSORS_BUS_TYPE_ANY; 96 res->bus.nr = SENSORS_BUS_NR_ANY; 96 97 res->addr = SENSORS_CHIP_NAME_ADDR_ANY; 97 98 return 0; … … 101 102 goto ERROR; 102 103 if (!strncmp(name, "i2c", dash - name)) 103 res->bus = SENSORS_CHIP_NAME_BUS_ANY_I2C;104 res->bus.type = SENSORS_BUS_TYPE_I2C; 104 105 else if (!strncmp(name, "isa", dash - name)) 105 res->bus = SENSORS_CHIP_NAME_BUS_ISA;106 res->bus.type = SENSORS_BUS_TYPE_ISA; 106 107 else if (!strncmp(name, "pci", dash - name)) 107 res->bus = SENSORS_CHIP_NAME_BUS_PCI;108 res->bus.type = SENSORS_BUS_TYPE_PCI; 108 109 else 109 110 goto ERROR; … … 113 114 next part is either a "*" (any bus of that type) or a decimal 114 115 number. */ 115 switch (res->bus ) {116 case SENSORS_ CHIP_NAME_BUS_ANY_I2C:116 switch (res->bus.type) { 117 case SENSORS_BUS_TYPE_I2C: 117 118 if (!strncmp(name, "*-", 2)) { 119 res->bus.nr = SENSORS_BUS_NR_ANY; 118 120 name += 2; 119 121 break; 120 122 } 121 123 122 res->bus = strtoul(name, &dash, 10);123 if (*name == '\0' || *dash != '-' || res->bus < 0)124 res->bus.nr = strtoul(name, &dash, 10); 125 if (*name == '\0' || *dash != '-' || res->bus.nr < 0) 124 126 goto ERROR; 125 127 name = dash + 1; 128 break; 129 default: 130 res->bus.nr = SENSORS_BUS_NR_ANY; 126 131 } 127 132 … … 148 153 return -SENSORS_ERR_WILDCARDS; 149 154 150 switch (chip->bus ) {151 case SENSORS_ CHIP_NAME_BUS_ISA:155 switch (chip->bus.type) { 156 case SENSORS_BUS_TYPE_ISA: 152 157 return snprintf(str, size, "%s-isa-%04x", chip->prefix, 153 158 chip->addr); 154 case SENSORS_ CHIP_NAME_BUS_PCI:159 case SENSORS_BUS_TYPE_PCI: 155 160 return snprintf(str, size, "%s-pci-%04x", chip->prefix, 156 161 chip->addr); 157 default: 158 return snprintf(str, size, "%s-i2c-%d-%02x", chip->prefix, 159 chip->bus, chip->addr); 160 } 162 case SENSORS_BUS_TYPE_I2C: 163 return snprintf(str, size, "%s-i2c-%hd-%02x", chip->prefix, 164 chip->bus.nr, chip->addr); 165 } 166 167 return -SENSORS_ERR_CHIP_NAME; 161 168 } 162 169 … … 179 186 int i, j; 180 187 for (i = 0; i < sensors_config_busses_count; i++) 181 if (sensors_config_busses[i].number == name->bus) 188 if (name->bus.type == SENSORS_BUS_TYPE_I2C && 189 sensors_config_busses[i].number == name->bus.nr) 182 190 break; 183 191 184 192 if (i == sensors_config_busses_count) { 185 193 sensors_parse_error("Undeclared i2c bus referenced", lineno); 186 name->bus = sensors_proc_bus_count;194 name->bus.nr = sensors_proc_bus_count; 187 195 return -SENSORS_ERR_BUS_NAME; 188 196 } … … 192 200 if (!strcmp(sensors_config_busses[i].adapter, 193 201 sensors_proc_bus[j].adapter)) { 194 name->bus = sensors_proc_bus[j].number;202 name->bus.nr = sensors_proc_bus[j].number; 195 203 return 0; 196 204 } … … 199 207 /* We did not find anything. sensors_proc_bus_count is not 200 208 a valid bus number, so it will never be matched. Good. */ 201 name->bus = sensors_proc_bus_count;209 name->bus.nr = sensors_proc_bus_count; 202 210 return 0; 203 211 } … … 212 220 lineno = sensors_config_chips[i].lineno; 213 221 chips = &sensors_config_chips[i].chips; 214 for (j = 0; j < chips->fits_count; j++) 215 if (chips->fits[j].bus != SENSORS_CHIP_NAME_BUS_ISA && 216 chips->fits[j].bus != SENSORS_CHIP_NAME_BUS_PCI && 217 chips->fits[j].bus != SENSORS_CHIP_NAME_BUS_ANY && 218 chips->fits[j].bus != SENSORS_CHIP_NAME_BUS_ANY_I2C) 219 if ((err = sensors_substitute_chip(chips->fits+j, 220 lineno))) 221 res = err; 222 for (j = 0; j < chips->fits_count; j++) { 223 /* We can only substitute if a specific bus number 224 is given. */ 225 if (chips->fits[j].bus.nr == SENSORS_BUS_NR_ANY) 226 continue; 227 228 err = sensors_substitute_chip(&chips->fits[j], lineno); 229 if (err) 230 res = err; 231 } 222 232 } 223 233 return res; lm-sensors/branches/lm-sensors-3.0.0/lib/sensors.h
r4684 r4686 2 2 sensors.h - Part of libsensors, a Linux library for reading sensor data. 3 3 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> 4 Copyright (C) 2007 Jean Delvare <khali@linux-fr.org> 4 5 5 6 This program is free software; you can redistribute it and/or modify … … 27 28 28 29 #define SENSORS_CHIP_NAME_PREFIX_ANY NULL 29 #define SENSORS_CHIP_NAME_BUS_ISA -130 #define SENSORS_CHIP_NAME_BUS_ANY -231 #define SENSORS_CHIP_NAME_BUS_ANY_I2C -332 #define SENSORS_CHIP_NAME_BUS_PCI -533 30 #define SENSORS_CHIP_NAME_ADDR_ANY -1 31 32 #define SENSORS_BUS_TYPE_ANY (-1) 33 #define SENSORS_BUS_TYPE_I2C 0 34 #define SENSORS_BUS_TYPE_ISA 1 35 #define SENSORS_BUS_TYPE_PCI 2 36 #define SENSORS_BUS_NR_ANY (-1) 34 37 35 38 #ifdef __cplusplus … … 39 42 extern const char *libsensors_version; 40 43 44 typedef struct sensors_bus_id { 45 short type; 46 short nr; 47 } sensors_bus_id; 48 41 49 /* A chip name is encoded in this structure */ 42 50 typedef struct sensors_chip_name { 43 51 char *prefix; 44 intbus;52 sensors_bus_id bus; 45 53 int addr; 46 54 char *path; … … 71 79 const sensors_chip_name *chip2); 72 80 73 /* This function returns the adapter name of a bus number,81 /* This function returns the adapter name of a bus, 74 82 as used within the sensors_chip_name structure. If it could not be found, 75 83 it returns NULL */ 76 const char *sensors_get_adapter_name( int bus_nr);84 const char *sensors_get_adapter_name(const sensors_bus_id *bus); 77 85 78 86 /* Look up the label which belongs to this chip. Note that chip should not lm-sensors/branches/lm-sensors-3.0.0/lib/sysfs.c
r4674 r4686 227 227 sensors_fatal_error(__FUNCTION__, "out of memory"); 228 228 229 if (sscanf(dev->name, "% d-%x", &entry.chip.bus, &entry.chip.addr) == 2) {229 if (sscanf(dev->name, "%hd-%x", &entry.chip.bus.nr, &entry.chip.addr) == 2) { 230 230 /* find out if legacy ISA or not */ 231 if (entry.chip.bus == 9191) 232 entry.chip.bus = SENSORS_CHIP_NAME_BUS_ISA; 233 else { 231 if (entry.chip.bus.nr == 9191) { 232 entry.chip.bus.type = SENSORS_BUS_TYPE_ISA; 233 entry.chip.bus.nr = 0; 234 } else { 235 entry.chip.bus.type = SENSORS_BUS_TYPE_I2C; 234 236 snprintf(bus_path, sizeof(bus_path), 235 237 "%s/class/i2c-adapter/i2c-%d/device/name", 236 sensors_sysfs_mount, entry.chip.bus );238 sensors_sysfs_mount, entry.chip.bus.nr); 237 239 238 240 if ((bus_attr = sysfs_open_attribute(bus_path))) { … … 243 245 244 246 if (bus_attr->value 245 && !strncmp(bus_attr->value, "ISA ", 4)) 246 entry.chip.bus = SENSORS_CHIP_NAME_BUS_ISA; 247 && !strncmp(bus_attr->value, "ISA ", 4)) { 248 entry.chip.bus.type = SENSORS_BUS_TYPE_ISA; 249 entry.chip.bus.nr = 0; 250 } 247 251 248 252 sysfs_close_attribute(bus_attr); … … 251 255 } else if (sscanf(dev->name, "%*[a-z0-9_].%d", &entry.chip.addr) == 1) { 252 256 /* must be new ISA (platform driver) */ 253 entry.chip.bus = SENSORS_CHIP_NAME_BUS_ISA; 257 entry.chip.bus.type = SENSORS_BUS_TYPE_ISA; 258 entry.chip.bus.nr = 0; 254 259 } else if (sscanf(dev->name, "%x:%x:%x.%x", &domain, &bus, &slot, &fn) == 4) { 255 260 /* PCI */ 256 261 entry.chip.addr = (domain << 16) + (bus << 8) + (slot << 3) + fn; 257 entry.chip.bus = SENSORS_CHIP_NAME_BUS_PCI; 262 entry.chip.bus.type = SENSORS_BUS_TYPE_PCI; 263 entry.chip.bus.nr = 0; 258 264 } else 259 265 goto exit_free; lm-sensors/branches/lm-sensors-3.0.0/prog/sensord/args.c
r2503 r4686 289 289 if (optind == argc) { 290 290 chipNames[0].prefix = SENSORS_CHIP_NAME_PREFIX_ANY; 291 chipNames[0].bus = SENSORS_CHIP_NAME_BUS_ANY; 291 chipNames[0].bus.type = SENSORS_BUS_TYPE_ANY; 292 chipNames[0].bus.nr = SENSORS_BUS_NR_ANY; 292 293 chipNames[0].addr = SENSORS_CHIP_NAME_ADDR_ANY; 293 294 numChipNames = 1; lm-sensors/branches/lm-sensors-3.0.0/prog/sensors/main.c
r4681 r4686 210 210 if (optind == argc) { 211 211 chips[0].prefix = SENSORS_CHIP_NAME_PREFIX_ANY; 212 chips[0].bus = SENSORS_CHIP_NAME_BUS_ANY; 212 chips[0].bus.type = SENSORS_BUS_TYPE_ANY; 213 chips[0].bus.nr = SENSORS_BUS_NR_ANY; 213 214 chips[0].addr = SENSORS_CHIP_NAME_ADDR_ANY; 214 215 chips_count = 1; … … 311 312 printf("%s\n",sprintf_chip_name(name)); 312 313 if (!hide_adapter) { 313 const char *adap = sensors_get_adapter_name( name->bus);314 const char *adap = sensors_get_adapter_name(&name->bus); 314 315 if (adap) 315 316 printf("Adapter: %s\n", adap); 316 317 else 317 fprintf(stderr, "Can't get adapter name for bus %d\n", name->bus);318 fprintf(stderr, "Can't get adapter name\n"); 318 319 } 319 320 if (do_unknown)
