| 269 | | /* OK, this is no detection. I know. It will do for now, though. */ |
| 270 | | err = 0; |
| 271 | | |
| 272 | | /* Make sure we aren't probing the ISA bus!! */ |
| 273 | | if (i2c_is_isa_adapter(adapter)) return 0; |
| 274 | | |
| 275 | | for (address = 0x20; (! err) && (address <= 0x2f); address ++) { |
| 276 | | |
| 277 | | /* Later on, we will keep a list of registered addresses for each |
| 278 | | adapter, and check whether they are used here */ |
| 279 | | |
| 280 | | if (smbus_read_byte_data(adapter,address,LM80_REG_CONFIG) < 0) |
| 281 | | continue; |
| 282 | | |
| 283 | | /* Real detection code goes here */ |
| 284 | | |
| 285 | | printk("lm80.o: LM80 detected\n"); |
| | 282 | /* Make sure we aren't probing the ISA bus!! This is just a safety check |
| | 283 | at this moment; sensors_detect really won't call us. */ |
| | 284 | #ifdef DEBUG |
| | 285 | if (i2c_is_isa_adapter(adapter)) { |
| | 286 | printk("lm80.o: lm80_detect called for an ISA bus adapter?!?\n"); |
| | 287 | return 0; |
| | 288 | } |
| | 289 | #endif |
| | 290 | |
| | 291 | /* Here, we have to do the address registration check for the I2C bus. |
| | 292 | But that is not yet implemented. */ |
| | 293 | |
| | 294 | /* OK. For now, we presume we have a valid client. We now create the |
| | 295 | client structure, even though we cannot fill it completely yet. |
| | 296 | But it allows us to access lm80_{read,write}_value. */ |
| | 297 | if (! (new_client = kmalloc(sizeof(struct i2c_client) + |
| | 298 | sizeof(struct lm80_data), |
| | 299 | GFP_KERNEL))) { |
| | 300 | err = -ENOMEM; |
| | 301 | goto ERROR0; |
| | 302 | } |
| | 303 | |
| | 304 | data = (struct lm80_data *) (((struct i2c_client *) new_client) + 1); |
| | 305 | new_client->addr = address; |
| | 306 | new_client->data = data; |
| | 307 | new_client->adapter = adapter; |
| | 308 | new_client->driver = &lm80_driver; |
| | 309 | |
| | 310 | /* Now, we do the remaining detection. It is lousy. */ |
| | 311 | if (lm80_read_value(new_client,LM80_REG_ALARM2) & 0xc0) |
| | 312 | goto ERROR1; |
| | 313 | for (i = 0x2a; i <= 0x3d; i++) { |
| | 314 | cur = smbus_read_byte_data(adapter,address,i); |
| | 315 | if ((smbus_read_byte_data(adapter,address,i+0x40) != cur) || |
| | 316 | (smbus_read_byte_data(adapter,address,i+0x80) != cur) || |
| | 317 | (smbus_read_byte_data(adapter,address,i+0xc0) != cur)) |
| | 318 | goto ERROR1; |
| | 319 | } |
| | 320 | |
| | 321 | /* Determine the chip type - only one kind supported! */ |
| | 322 | if (kind <= 0) |
| | 323 | kind = lm80; |
| | 324 | |
| | 325 | if (kind == lm80) { |
| 288 | | |
| 289 | | |
| 290 | | /* Allocate space for a new client structure. To counter memory |
| 291 | | fragmentation somewhat, we only do one kmalloc. */ |
| 292 | | if (! (new_client = kmalloc(sizeof(struct i2c_client) + |
| 293 | | sizeof(struct lm80_data), |
| 294 | | GFP_KERNEL))) { |
| 295 | | err = -ENOMEM; |
| 296 | | continue; |
| 297 | | } |
| 298 | | |
| 299 | | /* Fill the new client structure with data */ |
| 300 | | new_client->data = (struct lm80_data *) (new_client + 1); |
| 301 | | new_client->addr = address; |
| 302 | | strcpy(new_client->name,client_name); |
| 303 | | if ((err = lm80_new_client(adapter,new_client))) |
| 304 | | goto ERROR2; |
| 305 | | |
| 306 | | /* Tell i2c-core a new client has arrived */ |
| 307 | | if ((err = i2c_attach_client(new_client))) |
| 308 | | goto ERROR3; |
| 309 | | |
| 310 | | /* Register a new directory entry with module sensors */ |
| 311 | | if ((err = sensors_register_entry(new_client,type_name, |
| 312 | | lm80_dir_table_template)) < 0) |
| 313 | | goto ERROR4; |
| 314 | | ((struct lm80_data *) (new_client->data))->sysctl_id = err; |
| 315 | | err = 0; |
| 316 | | |
| 317 | | /* Initialize the LM80 chip */ |
| 318 | | lm80_init_client(new_client); |
| 319 | | continue; |
| | 328 | } else { |
| | 329 | #ifdef DEBUG |
| | 330 | printk("lm80.o: Internal error: unknown kind (%d)?!?",kind); |
| | 331 | #endif |
| | 332 | goto ERROR1; |
| | 333 | } |
| | 334 | |
| | 335 | /* Fill in the remaining client fields and put it into the global list */ |
| | 336 | strcpy(new_client->name,client_name); |
| | 337 | |
| | 338 | /* Find a place in our global list */ |
| | 339 | for (i = 0; i < MAX_LM80_NR; i++) |
| | 340 | if (! lm80_list[i]) |
| | 341 | break; |
| | 342 | if (i == MAX_LM80_NR) { |
| | 343 | err = -ENOMEM; |
| | 344 | printk("lm80.o: No empty slots left, recompile and heighten " |
| | 345 | "MAX_LM80_NR!\n"); |
| | 346 | goto ERROR2; |
| | 347 | } |
| | 348 | lm80_list[i] = new_client; |
| | 349 | new_client->id = i; |
| | 350 | data->valid = 0; |
| | 351 | data->update_lock = MUTEX; |
| | 352 | |
| | 353 | /* Tell the I2C layer a new client has arrived */ |
| | 354 | if ((err = i2c_attach_client(new_client))) |
| | 355 | goto ERROR3; |
| | 356 | |
| | 357 | /* Register a new directory entry with module sensors */ |
| | 358 | if ((i = sensors_register_entry(new_client,type_name, |
| | 359 | lm80_dir_table_template)) < 0) { |
| | 360 | err = i; |
| | 361 | goto ERROR4; |
| | 362 | } |
| | 363 | data->sysctl_id = i; |
| | 364 | |
| | 365 | lm80_init_client(new_client); |
| | 366 | return 0; |
| 353 | | } |
| 354 | | |
| 355 | | |
| 356 | | /* Find a free slot, and initialize most of the fields */ |
| 357 | | int lm80_new_client(struct i2c_adapter *adapter, |
| 358 | | struct i2c_client *new_client) |
| 359 | | { |
| 360 | | int i; |
| 361 | | struct lm80_data *data; |
| 362 | | |
| 363 | | /* First, seek out an empty slot */ |
| 364 | | for(i = 0; i < MAX_LM80_NR; i++) |
| 365 | | if (! lm80_list[i]) |
| 366 | | break; |
| 367 | | if (i == MAX_LM80_NR) { |
| 368 | | printk("lm80.o: No empty slots left, recompile and heighten " |
| 369 | | "MAX_LM80_NR!\n"); |
| 370 | | return -ENOMEM; |
| 371 | | } |
| 372 | | |
| 373 | | lm80_list[i] = new_client; |
| 374 | | new_client->id = i; |
| 375 | | new_client->adapter = adapter; |
| 376 | | new_client->driver = &lm80_driver; |
| 377 | | data = new_client->data; |
| 378 | | data->valid = 0; |
| 379 | | data->update_lock = MUTEX; |
| 380 | | return 0; |
| 381 | | } |
| 382 | | |
| 383 | | /* Inverse of lm80_new_client */ |
| 384 | | void lm80_remove_client(struct i2c_client *client) |
| 385 | | { |
| 386 | | int i; |
| 387 | | for (i = 0; i < MAX_LM80_NR; i++) |
| 388 | | if (client == lm80_list[i]) |
| 389 | | lm80_list[i] = NULL; |