Changeset 3541
- Timestamp:
- 05/28/01 00:40:53 (12 years ago)
- Location:
- i2c/trunk/kernel
- Files:
-
- 2 modified
-
i2c-proc.c (modified) (31 diffs)
-
i2c-proc.h (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
i2c/trunk/kernel/i2c-proc.c
r3540 r3541 47 47 #endif 48 48 49 static int sensors_create_name(char **name, const char *prefix,49 static int i2c_create_name(char **name, const char *prefix, 50 50 struct i2c_adapter *adapter, int addr); 51 static int sensors_parse_reals(int *nrels, void *buffer, int bufsize,51 static int i2c_parse_reals(int *nrels, void *buffer, int bufsize, 52 52 long *results, int magnitude); 53 static int sensors_write_reals(int nrels, void *buffer, int *bufsize,53 static int i2c_write_reals(int nrels, void *buffer, int *bufsize, 54 54 long *results, int magnitude); 55 static int sensors_proc_chips(ctl_table * ctl, int write,55 static int i2c_proc_chips(ctl_table * ctl, int write, 56 56 struct file *filp, void *buffer, 57 57 size_t * lenp); 58 static int sensors_sysctl_chips(ctl_table * table, int *name, int nlen,58 static int i2c_sysctl_chips(ctl_table * table, int *name, int nlen, 59 59 void *oldval, size_t * oldlenp, 60 60 void *newval, size_t newlen, … … 64 64 65 65 #define SENSORS_ENTRY_MAX 20 66 static struct ctl_table_header * sensors_entries[SENSORS_ENTRY_MAX];67 68 static struct i2c_client * sensors_clients[SENSORS_ENTRY_MAX];69 static unsigned short sensors_inodes[SENSORS_ENTRY_MAX];66 static struct ctl_table_header *i2c_entries[SENSORS_ENTRY_MAX]; 67 68 static struct i2c_client *i2c_clients[SENSORS_ENTRY_MAX]; 69 static unsigned short i2c_inodes[SENSORS_ENTRY_MAX]; 70 70 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1) 71 static void sensors_fill_inode(struct inode *inode, int fill);72 static void sensors_dir_fill_inode(struct inode *inode, int fill);71 static void i2c_fill_inode(struct inode *inode, int fill); 72 static void i2c_dir_fill_inode(struct inode *inode, int fill); 73 73 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1) */ 74 74 … … 82 82 }; 83 83 84 static ctl_table sensors_proc_dev_sensors[] = {85 {SENSORS_CHIPS, "chips", NULL, 0, 0644, NULL, & sensors_proc_chips,86 & sensors_sysctl_chips},84 static ctl_table i2c_proc_dev_sensors[] = { 85 {SENSORS_CHIPS, "chips", NULL, 0, 0644, NULL, &i2c_proc_chips, 86 &i2c_sysctl_chips}, 87 87 {0} 88 88 }; 89 89 90 static ctl_table sensors_proc_dev[] = {91 {DEV_SENSORS, "sensors", NULL, 0, 0555, sensors_proc_dev_sensors},90 static ctl_table i2c_proc_dev[] = { 91 {DEV_SENSORS, "sensors", NULL, 0, 0555, i2c_proc_dev_sensors}, 92 92 {0}, 93 93 }; 94 94 95 95 96 static ctl_table sensors_proc[] = {97 {CTL_DEV, "dev", NULL, 0, 0555, sensors_proc_dev},96 static ctl_table i2c_proc[] = { 97 {CTL_DEV, "dev", NULL, 0, 0555, i2c_proc_dev}, 98 98 {0} 99 99 }; 100 100 101 101 102 static struct ctl_table_header * sensors_proc_header;103 static int sensors_initialized;102 static struct ctl_table_header *i2c_proc_header; 103 static int i2c_initialized; 104 104 105 105 /* This returns a nice name for a new directory; for example lm78-isa-0310 … … 107 107 a LM75 chip on the third i2c bus at address 0x4e). 108 108 name is allocated first. */ 109 int sensors_create_name(char **name, const char *prefix,109 int i2c_create_name(char **name, const char *prefix, 110 110 struct i2c_adapter *adapter, int addr) 111 111 { … … 135 135 kernels before 2.3.13; define it to NULL in that case. We will not use it 136 136 for anything older than 2.3.27 anyway. */ 137 int sensors_register_entry(struct i2c_client *client, const char *prefix,137 int i2c_register_entry(struct i2c_client *client, const char *prefix, 138 138 ctl_table * ctl_template, 139 139 struct module *controlling_mod) … … 144 144 struct ctl_table_header *new_header; 145 145 146 if ((res = sensors_create_name(&name, prefix, client->adapter,146 if ((res = i2c_create_name(&name, prefix, client->adapter, 147 147 client->addr))) return res; 148 148 149 149 for (id = 0; id < SENSORS_ENTRY_MAX; id++) 150 if (! sensors_entries[id]) {150 if (!i2c_entries[id]) { 151 151 break; 152 152 } … … 182 182 } 183 183 184 sensors_entries[id - 256] = new_header;185 186 sensors_clients[id - 256] = client;184 i2c_entries[id - 256] = new_header; 185 186 i2c_clients[id - 256] = client; 187 187 #ifdef DEBUG 188 188 if (!new_header || !new_header->ctl_table || … … 195 195 } 196 196 #endif /* DEBUG */ 197 sensors_inodes[id - 256] =197 i2c_inodes[id - 256] = 198 198 new_header->ctl_table->child->child->de->low_ino; 199 199 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,27)) … … 201 201 #else 202 202 new_header->ctl_table->child->child->de->fill_inode = 203 & sensors_dir_fill_inode;203 &i2c_dir_fill_inode; 204 204 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,27)) */ 205 205 … … 207 207 } 208 208 209 void sensors_deregister_entry(int id)209 void i2c_deregister_entry(int id) 210 210 { 211 211 ctl_table *table; 212 212 char *temp; 213 213 id -= 256; 214 if ( sensors_entries[id]) {215 table = sensors_entries[id]->ctl_table;216 unregister_sysctl_table( sensors_entries[id]);214 if (i2c_entries[id]) { 215 table = i2c_entries[id]->ctl_table; 216 unregister_sysctl_table(i2c_entries[id]); 217 217 /* 2-step kfree needed to keep gcc happy about const points */ 218 218 (const char *) temp = table[4].procname; 219 219 kfree(temp); 220 220 kfree(table); 221 sensors_entries[id] = NULL;222 sensors_clients[id] = NULL;221 i2c_entries[id] = NULL; 222 i2c_clients[id] = NULL; 223 223 } 224 224 } … … 226 226 /* Monitor access for /proc/sys/dev/sensors; make unloading i2c-proc.o 227 227 impossible if some process still uses it or some file in it */ 228 void sensors_fill_inode(struct inode *inode, int fill)228 void i2c_fill_inode(struct inode *inode, int fill) 229 229 { 230 230 if (fill) … … 237 237 the corresponding module impossible if some process still uses it or 238 238 some file in it */ 239 void sensors_dir_fill_inode(struct inode *inode, int fill)239 void i2c_dir_fill_inode(struct inode *inode, int fill) 240 240 { 241 241 int i; … … 250 250 251 251 for (i = 0; i < SENSORS_ENTRY_MAX; i++) 252 if ( sensors_clients[i]253 && ( sensors_inodes[i] == inode->i_ino)) break;252 if (i2c_clients[i] 253 && (i2c_inodes[i] == inode->i_ino)) break; 254 254 #ifdef DEBUG 255 255 if (i == SENSORS_ENTRY_MAX) { … … 260 260 } 261 261 #endif /* def DEBUG */ 262 client = sensors_clients[i];262 client = i2c_clients[i]; 263 263 if (fill) 264 264 client->driver->inc_use(client); … … 267 267 } 268 268 269 int sensors_proc_chips(ctl_table * ctl, int write, struct file *filp,269 int i2c_proc_chips(ctl_table * ctl, int write, struct file *filp, 270 270 void *buffer, size_t * lenp) 271 271 { … … 287 287 curbufsize = 0; 288 288 for (i = 0; i < SENSORS_ENTRY_MAX; i++) 289 if ( sensors_entries[i]) {289 if (i2c_entries[i]) { 290 290 client_tbl = 291 sensors_entries[i]->ctl_table->child->child;291 i2c_entries[i]->ctl_table->child->child; 292 292 buflen = 293 293 sprintf(BUF, "%d\t%s\n", client_tbl->ctl_name, … … 305 305 } 306 306 307 int sensors_sysctl_chips(ctl_table * table, int *name, int nlen,307 int i2c_sysctl_chips(ctl_table * table, int *name, int nlen, 308 308 void *oldval, size_t * oldlenp, void *newval, 309 309 size_t newlen, void **context) 310 310 { 311 struct sensors_chips_data data;311 struct i2c_chips_data data; 312 312 int i, oldlen, nrels, maxels,ret=0; 313 313 struct ctl_table *client_tbl; … … 315 315 if (oldval && oldlenp && !((ret = get_user(oldlen, oldlenp))) && 316 316 oldlen) { 317 maxels = oldlen / sizeof(struct sensors_chips_data);317 maxels = oldlen / sizeof(struct i2c_chips_data); 318 318 nrels = 0; 319 319 for (i = 0; (i < SENSORS_ENTRY_MAX) && (nrels < maxels); 320 320 i++) 321 if ( sensors_entries[i]) {321 if (i2c_entries[i]) { 322 322 client_tbl = 323 sensors_entries[i]->ctl_table->child->323 i2c_entries[i]->ctl_table->child-> 324 324 child; 325 325 data.sysctl_id = client_tbl->ctl_name; … … 327 327 if(copy_to_user(oldval, &data, 328 328 sizeof(struct 329 sensors_chips_data)))329 i2c_chips_data))) 330 330 return -EFAULT; 331 331 (char *) oldval += 332 sizeof(struct sensors_chips_data);332 sizeof(struct i2c_chips_data); 333 333 nrels++; 334 334 } 335 oldlen = nrels * sizeof(struct sensors_chips_data);335 oldlen = nrels * sizeof(struct i2c_chips_data); 336 336 if(put_user(oldlen, oldlenp)) 337 337 return -EFAULT; … … 358 358 In all cases, client points to the client we wish to interact with, 359 359 and ctl_name is the SYSCTL id of the file we are accessing. */ 360 int sensors_proc_real(ctl_table * ctl, int write, struct file *filp,360 int i2c_proc_real(ctl_table * ctl, int write, struct file *filp, 361 361 void *buffer, size_t * lenp) 362 362 { … … 364 364 int mag, nrels = MAX_RESULTS; 365 365 long results[MAX_RESULTS]; 366 sensors_real_callback callback = ctl->extra1;366 i2c_real_callback callback = ctl->extra1; 367 367 struct i2c_client *client = ctl->extra2; 368 368 int res; … … 383 383 if (write) { 384 384 /* Read the complete input into results, converting to longs */ 385 res = sensors_parse_reals(&nrels, buffer, *lenp, results, mag);385 res = i2c_parse_reals(&nrels, buffer, *lenp, results, mag); 386 386 if (res) 387 387 return res; … … 402 402 403 403 /* And write them to buffer, converting to reals */ 404 res = sensors_write_reals(nrels, buffer, lenp, results, mag);404 res = i2c_write_reals(nrels, buffer, lenp, results, mag); 405 405 if (res) 406 406 return res; … … 410 410 } 411 411 412 /* This function is equivalent to sensors_proc_real, only it interacts with412 /* This function is equivalent to i2c_proc_real, only it interacts with 413 413 the sysctl(2) syscall, and returns no reals, but integers */ 414 int sensors_sysctl_real(ctl_table * table, int *name, int nlen,414 int i2c_sysctl_real(ctl_table * table, int *name, int nlen, 415 415 void *oldval, size_t * oldlenp, void *newval, 416 416 size_t newlen, void **context) … … 418 418 long results[MAX_RESULTS]; 419 419 int oldlen, nrels = MAX_RESULTS,ret=0; 420 sensors_real_callback callback = table->extra1;420 i2c_real_callback callback = table->extra1; 421 421 struct i2c_client *client = table->extra2; 422 422 … … 467 467 hidden bugs in it, even leading to crashes and things! 468 468 */ 469 int sensors_parse_reals(int *nrels, void *buffer, int bufsize,469 int i2c_parse_reals(int *nrels, void *buffer, int bufsize, 470 470 long *results, int magnitude) 471 471 { … … 568 568 } 569 569 570 int sensors_write_reals(int nrels, void *buffer, int *bufsize,570 int i2c_write_reals(int nrels, void *buffer, int *bufsize, 571 571 long *results, int magnitude) 572 572 { … … 641 641 642 642 /* Very inefficient for ISA detects, and won't work for 10-bit addresses! */ 643 int sensors_detect(struct i2c_adapter *adapter,644 struct sensors_address_data *address_data,645 sensors_found_addr_proc * found_proc)643 int i2c_detect(struct i2c_adapter *adapter, 644 struct i2c_address_data *address_data, 645 i2c_found_addr_proc * found_proc) 646 646 { 647 647 int addr, i, found, j, err; 648 struct sensors_force_data *this_force;648 struct i2c_force_data *this_force; 649 649 int is_isa = i2c_is_isa_adapter(adapter); 650 650 int adapter_id = … … 860 860 { 861 861 printk("i2c-proc.o version %s (%s)\n", LM_VERSION, LM_DATE); 862 sensors_initialized = 0;862 i2c_initialized = 0; 863 863 if (! 864 ( sensors_proc_header =865 register_sysctl_table( sensors_proc, 0))) return -ENOMEM;864 (i2c_proc_header = 865 register_sysctl_table(i2c_proc, 0))) return -ENOMEM; 866 866 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,1)) 867 sensors_proc_header->ctl_table->child->de->owner = THIS_MODULE;867 i2c_proc_header->ctl_table->child->de->owner = THIS_MODULE; 868 868 #else 869 sensors_proc_header->ctl_table->child->de->fill_inode =870 & sensors_fill_inode;869 i2c_proc_header->ctl_table->child->de->fill_inode = 870 &i2c_fill_inode; 871 871 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,1)) */ 872 sensors_initialized++;872 i2c_initialized++; 873 873 return 0; 874 874 } 875 875 876 EXPORT_SYMBOL( sensors_deregister_entry);877 EXPORT_SYMBOL( sensors_detect);878 EXPORT_SYMBOL( sensors_proc_real);879 EXPORT_SYMBOL( sensors_register_entry);880 EXPORT_SYMBOL( sensors_sysctl_real);876 EXPORT_SYMBOL(i2c_deregister_entry); 877 EXPORT_SYMBOL(i2c_detect); 878 EXPORT_SYMBOL(i2c_proc_real); 879 EXPORT_SYMBOL(i2c_register_entry); 880 EXPORT_SYMBOL(i2c_sysctl_real); 881 881 882 882 #ifdef MODULE … … 885 885 MODULE_DESCRIPTION("i2c-proc driver"); 886 886 887 int sensors_cleanup(void)888 { 889 if ( sensors_initialized >= 1) {890 unregister_sysctl_table( sensors_proc_header);891 sensors_initialized--;887 int i2c_cleanup(void) 888 { 889 if (i2c_initialized >= 1) { 890 unregister_sysctl_table(i2c_proc_header); 891 i2c_initialized--; 892 892 } 893 893 return 0; … … 901 901 int cleanup_module(void) 902 902 { 903 return sensors_cleanup();903 return i2c_cleanup(); 904 904 } 905 905 -
i2c/trunk/kernel/i2c-proc.h
r3527 r3541 30 30 31 31 /* The type of callback functions used in sensors_{proc,sysctl}_real */ 32 typedef void (* sensors_real_callback) (struct i2c_client * client,32 typedef void (*i2c_real_callback) (struct i2c_client * client, 33 33 int operation, int ctl_name, 34 34 int *nrels_mag, long *results); … … 56 56 In all cases, client points to the client we wish to interact with, 57 57 and ctl_name is the SYSCTL id of the file we are accessing. */ 58 extern int sensors_sysctl_real(ctl_table * table, int *name, int nlen,58 extern int i2c_sysctl_real(ctl_table * table, int *name, int nlen, 59 59 void *oldval, size_t * oldlenp, 60 60 void *newval, size_t newlen, 61 61 void **context); 62 extern int sensors_proc_real(ctl_table * ctl, int write, struct file *filp,62 extern int i2c_proc_real(ctl_table * ctl, int write, struct file *filp, 63 63 void *buffer, size_t * lenp); 64 64 … … 72 72 If any driver wants subdirectories within the newly created directory, 73 73 these functions must be updated! */ 74 extern int sensors_register_entry(struct i2c_client *client,74 extern int i2c_register_entry(struct i2c_client *client, 75 75 const char *prefix, 76 76 ctl_table * ctl_template, 77 77 struct module *controlling_mod); 78 78 79 extern void sensors_deregister_entry(int id);79 extern void i2c_deregister_entry(int id); 80 80 81 81 … … 92 92 kind: The kind of chip. 0 equals any chip. 93 93 */ 94 struct sensors_force_data {94 struct i2c_force_data { 95 95 unsigned short *force; 96 96 unsigned short kind; … … 136 136 the force field is NULL. 137 137 */ 138 struct sensors_address_data {138 struct i2c_address_data { 139 139 unsigned short *normal_i2c; 140 140 unsigned short *normal_i2c_range; … … 145 145 unsigned short *ignore; 146 146 unsigned short *ignore_range; 147 struct sensors_force_data *forces;147 struct i2c_force_data *forces; 148 148 }; 149 149 … … 210 210 "List of adapter,start-addr,end-addr triples not to " \ 211 211 "scan"); \ 212 static struct sensors_address_data addr_data = \212 static struct i2c_address_data addr_data = \ 213 213 {normal_i2c, normal_i2c_range, \ 214 214 normal_isa, normal_isa_range, \ … … 226 226 "List of adapter,address pairs to boldly assume " \ 227 227 "to be present"); \ 228 static struct sensors_force_data forces[] = {{force,any_chip},{NULL}}; \228 static struct i2c_force_data forces[] = {{force,any_chip},{NULL}}; \ 229 229 SENSORS_INSMOD 230 230 … … 235 235 "to be present"); \ 236 236 SENSORS_MODULE_PARM_FORCE(chip1); \ 237 static struct sensors_force_data forces[] = {{force,any_chip},\237 static struct i2c_force_data forces[] = {{force,any_chip},\ 238 238 {force_ ## chip1,chip1}, \ 239 239 {NULL}}; \ … … 247 247 SENSORS_MODULE_PARM_FORCE(chip1); \ 248 248 SENSORS_MODULE_PARM_FORCE(chip2); \ 249 static struct sensors_force_data forces[] = {{force,any_chip}, \249 static struct i2c_force_data forces[] = {{force,any_chip}, \ 250 250 {force_ ## chip1,chip1}, \ 251 251 {force_ ## chip2,chip2}, \ … … 261 261 SENSORS_MODULE_PARM_FORCE(chip2); \ 262 262 SENSORS_MODULE_PARM_FORCE(chip3); \ 263 static struct sensors_force_data forces[] = {{force,any_chip}, \263 static struct i2c_force_data forces[] = {{force,any_chip}, \ 264 264 {force_ ## chip1,chip1}, \ 265 265 {force_ ## chip2,chip2}, \ … … 277 277 SENSORS_MODULE_PARM_FORCE(chip3); \ 278 278 SENSORS_MODULE_PARM_FORCE(chip4); \ 279 static struct sensors_force_data forces[] = {{force,any_chip}, \279 static struct i2c_force_data forces[] = {{force,any_chip}, \ 280 280 {force_ ## chip1,chip1}, \ 281 281 {force_ ## chip2,chip2}, \ … … 295 295 SENSORS_MODULE_PARM_FORCE(chip4); \ 296 296 SENSORS_MODULE_PARM_FORCE(chip5); \ 297 static struct sensors_force_data forces[] = {{force,any_chip}, \297 static struct i2c_force_data forces[] = {{force,any_chip}, \ 298 298 {force_ ## chip1,chip1}, \ 299 299 {force_ ## chip2,chip2}, \ … … 315 315 SENSORS_MODULE_PARM_FORCE(chip5); \ 316 316 SENSORS_MODULE_PARM_FORCE(chip6); \ 317 static struct sensors_force_data forces[] = {{force,any_chip}, \317 static struct i2c_force_data forces[] = {{force,any_chip}, \ 318 318 {force_ ## chip1,chip1}, \ 319 319 {force_ ## chip2,chip2}, \ … … 337 337 SENSORS_MODULE_PARM_FORCE(chip6); \ 338 338 SENSORS_MODULE_PARM_FORCE(chip7); \ 339 static struct sensors_force_data forces[] = {{force,any_chip}, \339 static struct i2c_force_data forces[] = {{force,any_chip}, \ 340 340 {force_ ## chip1,chip1}, \ 341 341 {force_ ## chip2,chip2}, \ … … 348 348 SENSORS_INSMOD 349 349 350 typedef int sensors_found_addr_proc(struct i2c_adapter *adapter,350 typedef int i2c_found_addr_proc(struct i2c_adapter *adapter, 351 351 int addr, unsigned short flags, 352 352 int kind); 353 353 354 /* Detect function. It it terates over all possible addresses itself. For354 /* Detect function. It iterates over all possible addresses itself. For 355 355 SMBus addresses, it will only call found_proc if some client is connected 356 356 to the SMBus (unless a 'force' matched); for ISA detections, this is not 357 357 done. */ 358 extern int sensors_detect(struct i2c_adapter *adapter,359 struct sensors_address_data *address_data,360 sensors_found_addr_proc * found_proc);358 extern int i2c_detect(struct i2c_adapter *adapter, 359 struct i2c_address_data *address_data, 360 i2c_found_addr_proc * found_proc); 361 361 362 362 … … 388 388 389 389 #define SENSORS_CHIPS 1 390 struct sensors_chips_data {390 struct i2c_chips_data { 391 391 int sysctl_id; 392 392 char name[SENSORS_PREFIX_MAX + 13];
