Changeset 338
- Timestamp:
- 03/23/99 22:53:28 (14 years ago)
- Location:
- lm-sensors/trunk/kernel
- Files:
-
- 3 modified
-
chips/lm75.c (modified) (7 diffs)
-
chips/lm78.c (modified) (2 diffs)
-
sensors.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lm-sensors/trunk/kernel/chips/lm75.c
r283 r338 27 27 #include "version.h" 28 28 29 /* Addresses to scan */ 30 static unsigned short normal_i2c[] = {SENSORS_I2C_END}; 31 static unsigned short normal_i2c_range[] = {0x48,0x4f,SENSORS_I2C_END}; 32 static unsigned int normal_isa[] = {SENSORS_ISA_END}; 33 static unsigned int normal_isa_range[] = {SENSORS_ISA_END}; 34 35 /* Insmod parameters */ 36 SENSORS_INSMOD_1(lm75); 37 29 38 /* Many LM75 constants specified below */ 30 39 … … 62 71 static int lm75_cleanup(void); 63 72 static int lm75_attach_adapter(struct i2c_adapter *adapter); 73 static int lm75_detect(struct i2c_adapter *adapter, int address, int kind); 74 static void lm75_init_client(struct i2c_client *client); 64 75 static int lm75_detach_client(struct i2c_client *client); 65 76 static int lm75_command(struct i2c_client *client, unsigned int cmd, … … 101 112 static int lm75_initialized = 0; 102 113 103 /* I choose here for semi-static LM7 8allocation. Complete dynamic114 /* I choose here for semi-static LM75 allocation. Complete dynamic 104 115 allocation could also be used; the code needed for this would probably 105 116 take more memory than the datastructure takes now. */ 106 #define MAX_LM75_NR 8117 #define MAX_LM75_NR 16 107 118 static struct i2c_client *lm75_list[MAX_LM75_NR]; 108 119 … … 110 121 int lm75_attach_adapter(struct i2c_adapter *adapter) 111 122 { 112 int address,err,i; 123 return sensors_detect(adapter,&addr_data,lm75_detect); 124 } 125 126 /* This function is called by sensors_detect */ 127 int lm75_detect(struct i2c_adapter *adapter, int address, int kind) 128 { 129 int i,cur,conf,hyst,os; 113 130 struct i2c_client *new_client; 114 131 struct lm75_data *data; 115 116 err = 0; 117 /* Make sure we aren't probing the ISA bus!! */ 118 if (i2c_is_isa_adapter(adapter)) return 0; 119 120 /* OK, this is no detection. I know. It will do for now, though. */ 121 122 /* Set err only if a global error would make registering other clients 123 impossible too (like out-of-memory). */ 124 for (address = 0x48; (! err) && (address <= 0x4f); address ++) { 125 126 /* Later on, we will keep a list of registered addresses for each 127 adapter, and check whether they are used here */ 132 int err=0; 133 const char *type_name,*client_name; 134 135 /* Make sure we aren't probing the ISA bus!! This is just a safety check 136 at this moment; sensors_detect really won't call us. */ 137 #ifdef DEBUG 138 if (i2c_is_isa_adapter(adapter)) { 139 printk("lm75.o: lm75_detect called for an ISA bus adapter?!?\n"); 140 return 0; 141 } 142 #endif 143 144 /* Here, we have to do the address registration check for the I2C bus. 145 But that is not yet implemented. */ 146 147 /* OK. For now, we presume we have a valid client. We now create the 148 client structure, even though we cannot fill it completely yet. 149 But it allows us to access lm75_{read,write}_value. */ 150 if (! (new_client = kmalloc(sizeof(struct i2c_client) + 151 sizeof(struct lm75_data), 152 GFP_KERNEL))) { 153 err = -ENOMEM; 154 goto ERROR0; 155 } 156 157 data = (struct lm75_data *) (((struct i2c_client *) new_client) + 1); 158 new_client->addr = address; 159 new_client->data = data; 160 new_client->adapter = adapter; 161 new_client->driver = &lm75_driver; 162 163 /* Now, we do the remaining detection. It is lousy. */ 164 cur = smbus_read_word_data(adapter,address,0); 165 conf = smbus_read_byte_data(adapter,address,1); 166 hyst = smbus_read_word_data(adapter,address,2); 167 os = smbus_read_word_data(adapter,address,3); 168 if ((hyst & 0x7f00) || (os & 0x7f00) || (cur & 0x7f00)) 169 goto ERROR1; 170 for (i = 0; i <= 0x1f; i++) 171 if ((smbus_read_byte_data(adapter,address,i*8+1) != conf) || 172 (smbus_read_word_data(adapter,address,i*8+2) != hyst) || 173 (smbus_read_word_data(adapter,address,i*8+3) != os)) 174 goto ERROR1; 175 176 /* Determine the chip type - only one kind supported! */ 177 if (kind <= 0) 178 kind = lm75; 179 180 if (kind == lm75) { 181 type_name = "lm75"; 182 client_name = "LM75 chip"; 183 } else { 184 #ifdef DEBUG 185 printk("lm75.o: Internal error: unknown kind (%d)?!?",kind); 186 #endif 187 goto ERROR1; 188 } 189 190 /* Fill in the remaining client fields and put it into the global list */ 191 strcpy(new_client->name,client_name); 192 193 /* Find a place in our global list */ 194 for (i = 0; i < MAX_LM75_NR; i++) 195 if (! lm75_list[i]) 196 break; 197 if (i == MAX_LM75_NR) { 198 err = -ENOMEM; 199 printk("lm75.o: No empty slots left, recompile and heighten " 200 "MAX_LM75_NR!\n"); 201 goto ERROR2; 202 } 203 lm75_list[i] = new_client; 204 new_client->id = i; 205 data->valid = 0; 206 data->update_lock = MUTEX; 128 207 129 if (smbus_read_byte_data(adapter,address,LM75_REG_CONF) < 0) 130 continue; 131 132 /* Real detection code goes here */ 133 134 /* Allocate space for a new client structure */ 135 if (! (new_client = kmalloc(sizeof(struct i2c_client) + 136 sizeof(struct lm75_data), 137 GFP_KERNEL))) { 138 err = -ENOMEM; 139 continue; 140 } 141 142 /* Find a place in our global list */ 143 for (i = 0; i < MAX_LM75_NR; i++) 144 if (! lm75_list[i]) 145 break; 146 if (i == MAX_LM75_NR) { 147 err = -ENOMEM; 148 printk("lm75.o: No empty slots left, recompile and heighten " 149 "MAX_LM75_NR!\n"); 150 goto ERROR1; 151 } 152 lm75_list[i] = new_client; 153 154 /* Fill the new client structure with data */ 155 data = (struct lm75_data *) (new_client + 1); 156 new_client->data = data; 157 new_client->id = i; 158 new_client->addr = address; 159 new_client->adapter = adapter; 160 new_client->driver = &lm75_driver; 161 strcpy(new_client->name,"LM75 chip"); 162 data->valid = 0; 163 data->update_lock = MUTEX; 164 165 /* Tell i2c-core a new client has arrived */ 166 if ((err = i2c_attach_client(new_client))) 167 goto ERROR2; 168 169 /* Register a new directory entry with module sensors */ 170 if ((err = sensors_register_entry(new_client,"lm75", 171 lm75_dir_table_template)) < 0) 172 goto ERROR3; 173 data->sysctl_id = err; 174 err = 0; 175 176 /* Initialize the LM75 chip */ 177 lm75_write_value(new_client,LM75_REG_TEMP_OS, 178 TEMP_TO_REG(LM75_INIT_TEMP_OS)); 179 lm75_write_value(new_client,LM75_REG_TEMP_HYST, 180 TEMP_TO_REG(LM75_INIT_TEMP_HYST)); 181 lm75_write_value(new_client,LM75_REG_CONF,0); 182 183 continue; 208 /* Tell the I2C layer a new client has arrived */ 209 if ((err = i2c_attach_client(new_client))) 210 goto ERROR3; 211 212 /* Register a new directory entry with module sensors */ 213 if ((i = sensors_register_entry(new_client,type_name, 214 lm75_dir_table_template)) < 0) { 215 err = i; 216 goto ERROR4; 217 } 218 data->sysctl_id = i; 219 220 lm75_init_client((struct i2c_client *) new_client); 221 return 0; 222 184 223 /* OK, this is not exactly good programming practice, usually. But it is 185 224 very code-efficient in this case. */ 186 225 226 ERROR4: 227 i2c_detach_client(new_client); 187 228 ERROR3: 188 i2c_detach_client(new_client); 229 for (i = 0; i < MAX_LM75_NR; i++) 230 if (new_client == lm75_list[i]) 231 lm75_list[i] = NULL; 189 232 ERROR2: 190 lm75_list[i] = NULL;191 233 ERROR1: 192 kfree(new_client);193 } 234 kfree(new_client); 235 ERROR0: 194 236 return err; 195 237 } … … 198 240 { 199 241 int err,i; 242 243 sensors_deregister_entry(((struct lm75_data *)(client->data))->sysctl_id); 244 245 if ((err = i2c_detach_client(client))) { 246 printk("lm75.o: Client deregistration failed, client not detached.\n"); 247 return err; 248 } 249 200 250 for (i = 0; i < MAX_LM75_NR; i++) 201 251 if (client == lm75_list[i]) … … 205 255 return -ENOENT; 206 256 } 207 208 sensors_deregister_entry(((struct lm75_data *)(client->data))->sysctl_id);209 210 if ((err = i2c_detach_client(client))) {211 printk("lm75.o: Client deregistration failed, client not detached.\n");212 return err;213 }214 215 257 lm75_list[i] = NULL; 258 216 259 kfree(client); 260 217 261 return 0; 218 262 } … … 267 311 return smbus_write_word_data(client->adapter,client->addr,reg, 268 312 swap_bytes(value)); 313 } 314 315 void lm75_init_client(struct i2c_client *client) 316 { 317 /* Initialize the LM75 chip */ 318 lm75_write_value(client,LM75_REG_TEMP_OS, 319 TEMP_TO_REG(LM75_INIT_TEMP_OS)); 320 lm75_write_value(client,LM75_REG_TEMP_HYST, 321 TEMP_TO_REG(LM75_INIT_TEMP_HYST)); 322 lm75_write_value(client,LM75_REG_CONF,0); 269 323 } 270 324 -
lm-sensors/trunk/kernel/chips/lm78.c
r333 r338 308 308 int is_isa = i2c_is_isa_adapter(adapter); 309 309 310 311 if (kind < 0) {312 310 /* We need address registration for the I2C bus too. That is not yet 313 311 implemented. */ 312 if (is_isa) { 313 if (check_region(address,LM78_EXTENT)) 314 goto ERROR0; 315 } 316 317 /* Probe whether there is anything available on this address. Already 318 done for SMBus clients */ 319 if (kind < 0) { 314 320 if (is_isa) { 315 321 … … 394 400 type_name = "lm79"; 395 401 client_name = "LM79 chip"; 396 } else 402 } else { 403 #ifdef DEBUG 404 printk("lm78.o: Internal error: unknown kind (%d)?!?",kind); 405 #endif 397 406 goto ERROR1; 407 } 398 408 399 409 /* Reserve the ISA region */ -
lm-sensors/trunk/kernel/sensors.c
r335 r338 608 608 ((this_force->force[j] == SENSORS_ANY_I2C_BUS) && !is_isa)) && 609 609 (addr == this_force->force[j+1])) { 610 #ifdef DEBUG 611 printk("sensors.o: found force parameter for adapter %d, addr %04x\n", 612 adapter_id,addr); 613 #endif 610 614 if ((err = found_proc(adapter,addr,this_force->kind))) 611 615 return err; … … 625 629 ((address_data->ignore[i] == SENSORS_ANY_I2C_BUS) && !is_isa)) && 626 630 (addr == address_data->ignore[i+1])) { 631 #ifdef DEBUG 632 printk("sensors.o: found ignore parameter for adapter %d, " 633 "addr %04x\n", adapter_id,addr); 634 #endif 627 635 found = 1; 628 636 } … … 634 642 ((address_data->ignore_range[i]==SENSORS_ANY_I2C_BUS) & !is_isa)) && 635 643 (addr >= address_data->ignore_range[i+1]) && 636 (addr <= address_data->ignore_range[i+2])) 644 (addr <= address_data->ignore_range[i+2])) { 645 #ifdef DEBUG 646 printk("sensors.o: found ignore_range parameter for adapter %d, " 647 "addr %04x\n", adapter_id,addr); 648 #endif 637 649 found = 1; 650 } 638 651 } 639 652 if (found) … … 647 660 i += 1) { 648 661 if (addr == address_data->normal_isa[i]) { 662 #ifdef DEBUG 663 printk("sensors.o: found normal isa entry for adapter %d, " 664 "addr %04x\n", adapter_id,addr); 665 #endif 649 666 found = 1; 667 } 650 668 } 651 669 for (i = 0; 652 670 !found && (address_data->normal_isa_range[i] != SENSORS_ISA_END); 653 671 i += 3) { 654 if ((addr >= address_data->normal_isa_range[i]) && 655 (addr <= address_data->normal_isa_range[i+1]) && 656 ((addr - address_data->normal_isa_range[i]) % 657 address_data->normal_isa_range[i+2] == 0)); 672 if ((addr >= address_data->normal_isa_range[i]) && 673 (addr <= address_data->normal_isa_range[i+1]) && 674 ((addr - address_data->normal_isa_range[i]) % 675 address_data->normal_isa_range[i+2] == 0)) { 676 #ifdef DEBUG 677 printk("sensors.o: found normal isa_range entry for adapter %d, " 678 "addr %04x", adapter_id,addr); 679 #endif 658 680 found = 1; 659 681 } … … 665 687 if (addr == address_data->normal_i2c[i]) { 666 688 found = 1; 689 #ifdef DEBUG 690 printk("sensors.o: found normal i2c entry for adapter %d, " 691 "addr %02x", adapter_id,addr); 692 #endif 693 } 667 694 } 668 695 for (i = 0; … … 670 697 i += 2) { 671 698 if ((addr >= address_data->normal_i2c_range[i]) && 672 (addr <= address_data->normal_i2c_range[i+1])) 699 (addr <= address_data->normal_i2c_range[i+1])) { 700 #ifdef DEBUG 701 printk("sensors.o: found normal i2c_range entry for adapter %d, " 702 "addr %04x\n", adapter_id,addr); 703 #endif 673 704 found = 1; 674 705 } … … 682 713 ((address_data->probe[i] == SENSORS_ANY_I2C_BUS) & !is_isa)) && 683 714 (addr == address_data->probe[i+1])) { 715 #ifdef DEBUG 716 printk("sensors.o: found probe parameter for adapter %d, " 717 "addr %04x\n", adapter_id,addr); 718 #endif 684 719 found = 1; 685 720 } 721 } 686 722 for (i = 0; 687 723 !found && (address_data->probe_range[i] != SENSORS_I2C_END); … … 690 726 ((address_data->probe_range[i] == SENSORS_ANY_I2C_BUS) & !is_isa)) && 691 727 (addr >= address_data->probe_range[i+1]) && 692 (addr <= address_data->probe_range[i+2])) 728 (addr <= address_data->probe_range[i+2])) { 693 729 found = 1; 730 #ifdef DEBUG 731 printk("sensors.o: found probe_range parameter for adapter %d, " 732 "addr %04x\n", adapter_id,addr); 733 #endif 694 734 } 695 735 }
