Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ltc4215/ltc4245: Discard obsolete detect methods

There is no point in implementing a detect callback for the LTC4215
and LTC4245, as these devices can't be detected. It was there solely
to handle "force" module parameters to instantiate devices, but now
we have a better sysfs interface that can do the same.

So we can get rid of the ugly module parameters and the detect
callbacks. This shrinks the binary module sizes by 36% and 46%,
respectively.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: Ira W. Snyder <iws@ovro.caltech.edu>

+18 -174
+4 -3
Documentation/hwmon/ltc4215
··· 22 22 ----------- 23 23 24 24 This driver does not probe for LTC4215 devices, due to the fact that some 25 - of the possible addresses are unfriendly to probing. You will need to use 26 - the "force" parameter to tell the driver where to find the device. 25 + of the possible addresses are unfriendly to probing. You will have to 26 + instantiate the devices explicitly. 27 27 28 28 Example: the following will load the driver for an LTC4215 at address 0x44 29 29 on I2C bus #0: 30 - $ modprobe ltc4215 force=0,0x44 30 + $ modprobe ltc4215 31 + $ echo ltc4215 0x44 > /sys/bus/i2c/devices/i2c-0/new_device 31 32 32 33 33 34 Sysfs entries
+4 -3
Documentation/hwmon/ltc4245
··· 23 23 ----------- 24 24 25 25 This driver does not probe for LTC4245 devices, due to the fact that some 26 - of the possible addresses are unfriendly to probing. You will need to use 27 - the "force" parameter to tell the driver where to find the device. 26 + of the possible addresses are unfriendly to probing. You will have to 27 + instantiate the devices explicitly. 28 28 29 29 Example: the following will load the driver for an LTC4245 at address 0x23 30 30 on I2C bus #1: 31 - $ modprobe ltc4245 force=1,0x23 31 + $ modprobe ltc4245 32 + $ echo ltc4245 0x23 > /sys/bus/i2c/devices/i2c-1/new_device 32 33 33 34 34 35 Sysfs entries
+5 -42
drivers/hwmon/ltc4215.c
··· 20 20 #include <linux/hwmon.h> 21 21 #include <linux/hwmon-sysfs.h> 22 22 23 - static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; 24 - 25 - /* Insmod parameters */ 26 - I2C_CLIENT_INSMOD_1(ltc4215); 27 - 28 23 /* Here are names of the chip's registers (a.k.a. commands) */ 29 24 enum ltc4215_cmd { 30 25 LTC4215_CONTROL = 0x00, /* rw */ ··· 241 246 static int ltc4215_probe(struct i2c_client *client, 242 247 const struct i2c_device_id *id) 243 248 { 249 + struct i2c_adapter *adapter = client->adapter; 244 250 struct ltc4215_data *data; 245 251 int ret; 252 + 253 + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 254 + return -ENODEV; 246 255 247 256 data = kzalloc(sizeof(*data), GFP_KERNEL); 248 257 if (!data) { ··· 293 294 return 0; 294 295 } 295 296 296 - static int ltc4215_detect(struct i2c_client *client, 297 - int kind, 298 - struct i2c_board_info *info) 299 - { 300 - struct i2c_adapter *adapter = client->adapter; 301 - 302 - if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 303 - return -ENODEV; 304 - 305 - if (kind < 0) { /* probed detection - check the chip type */ 306 - s32 v; /* 8 bits from the chip, or -ERRNO */ 307 - 308 - /* 309 - * Register 0x01 bit b7 is reserved, expect 0 310 - * Register 0x03 bit b6 and b7 are reserved, expect 0 311 - */ 312 - v = i2c_smbus_read_byte_data(client, LTC4215_ALERT); 313 - if (v < 0 || (v & (1 << 7)) != 0) 314 - return -ENODEV; 315 - 316 - v = i2c_smbus_read_byte_data(client, LTC4215_FAULT); 317 - if (v < 0 || (v & ((1 << 6) | (1 << 7))) != 0) 318 - return -ENODEV; 319 - } 320 - 321 - strlcpy(info->type, "ltc4215", I2C_NAME_SIZE); 322 - dev_info(&adapter->dev, "ltc4215 %s at address 0x%02x\n", 323 - kind < 0 ? "probed" : "forced", 324 - client->addr); 325 - 326 - return 0; 327 - } 328 - 329 297 static const struct i2c_device_id ltc4215_id[] = { 330 - { "ltc4215", ltc4215 }, 298 + { "ltc4215", 0 }, 331 299 { } 332 300 }; 333 301 MODULE_DEVICE_TABLE(i2c, ltc4215_id); 334 302 335 303 /* This is the driver that will be inserted */ 336 304 static struct i2c_driver ltc4215_driver = { 337 - .class = I2C_CLASS_HWMON, 338 305 .driver = { 339 306 .name = "ltc4215", 340 307 }, 341 308 .probe = ltc4215_probe, 342 309 .remove = ltc4215_remove, 343 310 .id_table = ltc4215_id, 344 - .detect = ltc4215_detect, 345 - .address_data = &addr_data, 346 311 }; 347 312 348 313 static int __init ltc4215_init(void)
+5 -126
drivers/hwmon/ltc4245.c
··· 22 22 #include <linux/hwmon.h> 23 23 #include <linux/hwmon-sysfs.h> 24 24 25 - /* Valid addresses are 0x20 - 0x3f 26 - * 27 - * For now, we do not probe, since some of these addresses 28 - * are known to be unfriendly to probing */ 29 - static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; 30 - 31 - /* Insmod parameters */ 32 - I2C_CLIENT_INSMOD_1(ltc4245); 33 - 34 25 /* Here are names of the chip's registers (a.k.a. commands) */ 35 26 enum ltc4245_cmd { 36 27 LTC4245_STATUS = 0x00, /* readonly */ ··· 360 369 static int ltc4245_probe(struct i2c_client *client, 361 370 const struct i2c_device_id *id) 362 371 { 372 + struct i2c_adapter *adapter = client->adapter; 363 373 struct ltc4245_data *data; 364 374 int ret; 375 + 376 + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 377 + return -ENODEV; 365 378 366 379 data = kzalloc(sizeof(*data), GFP_KERNEL); 367 380 if (!data) { ··· 413 418 return 0; 414 419 } 415 420 416 - /* Check that some bits in a control register appear at all possible 417 - * locations without changing value 418 - * 419 - * @client: the i2c client to use 420 - * @reg: the register to read 421 - * @bits: the bits to check (0xff checks all bits, 422 - * 0x03 checks only the last two bits) 423 - * 424 - * return -ERRNO if the register read failed 425 - * return -ENODEV if the register value doesn't stay constant at all 426 - * possible addresses 427 - * 428 - * return 0 for success 429 - */ 430 - static int ltc4245_check_control_reg(struct i2c_client *client, u8 reg, u8 bits) 431 - { 432 - int i; 433 - s32 v, voff1, voff2; 434 - 435 - /* Read register and check for error */ 436 - v = i2c_smbus_read_byte_data(client, reg); 437 - if (v < 0) 438 - return v; 439 - 440 - v &= bits; 441 - 442 - for (i = 0x00; i < 0xff; i += 0x20) { 443 - 444 - voff1 = i2c_smbus_read_byte_data(client, reg + i); 445 - if (voff1 < 0) 446 - return voff1; 447 - 448 - voff2 = i2c_smbus_read_byte_data(client, reg + i + 0x08); 449 - if (voff2 < 0) 450 - return voff2; 451 - 452 - voff1 &= bits; 453 - voff2 &= bits; 454 - 455 - if (v != voff1 || v != voff2) 456 - return -ENODEV; 457 - } 458 - 459 - return 0; 460 - } 461 - 462 - static int ltc4245_detect(struct i2c_client *client, 463 - int kind, 464 - struct i2c_board_info *info) 465 - { 466 - struct i2c_adapter *adapter = client->adapter; 467 - 468 - if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 469 - return -ENODEV; 470 - 471 - if (kind < 0) { /* probed detection - check the chip type */ 472 - s32 v; /* 8 bits from the chip, or -ERRNO */ 473 - 474 - /* Chip registers 0x00-0x07 are control registers 475 - * Chip registers 0x10-0x1f are data registers 476 - * 477 - * Address bits b7-b5 are ignored. This makes the chip "repeat" 478 - * in steps of 0x20. Any control registers should appear with 479 - * the same values across all duplicated addresses. 480 - * 481 - * Register 0x02 bit b2 is reserved, expect 0 482 - * Register 0x07 bits b7 to b4 are reserved, expect 0 483 - * 484 - * Registers 0x01, 0x02 are control registers and should not 485 - * change on their own. 486 - * 487 - * Register 0x06 bits b6 and b7 are control bits, and should 488 - * not change on their own. 489 - * 490 - * Register 0x07 bits b3 to b0 are control bits, and should 491 - * not change on their own. 492 - */ 493 - 494 - /* read register 0x02 reserved bit, expect 0 */ 495 - v = i2c_smbus_read_byte_data(client, LTC4245_CONTROL); 496 - if (v < 0 || (v & 0x04) != 0) 497 - return -ENODEV; 498 - 499 - /* read register 0x07 reserved bits, expect 0 */ 500 - v = i2c_smbus_read_byte_data(client, LTC4245_ADCADR); 501 - if (v < 0 || (v & 0xf0) != 0) 502 - return -ENODEV; 503 - 504 - /* check that the alert register appears at all locations */ 505 - if (ltc4245_check_control_reg(client, LTC4245_ALERT, 0xff)) 506 - return -ENODEV; 507 - 508 - /* check that the control register appears at all locations */ 509 - if (ltc4245_check_control_reg(client, LTC4245_CONTROL, 0xff)) 510 - return -ENODEV; 511 - 512 - /* check that register 0x06 bits b6 and b7 stay constant */ 513 - if (ltc4245_check_control_reg(client, LTC4245_GPIO, 0xc0)) 514 - return -ENODEV; 515 - 516 - /* check that register 0x07 bits b3-b0 stay constant */ 517 - if (ltc4245_check_control_reg(client, LTC4245_ADCADR, 0x0f)) 518 - return -ENODEV; 519 - } 520 - 521 - strlcpy(info->type, "ltc4245", I2C_NAME_SIZE); 522 - dev_info(&adapter->dev, "ltc4245 %s at address 0x%02x\n", 523 - kind < 0 ? "probed" : "forced", 524 - client->addr); 525 - 526 - return 0; 527 - } 528 - 529 421 static const struct i2c_device_id ltc4245_id[] = { 530 - { "ltc4245", ltc4245 }, 422 + { "ltc4245", 0 }, 531 423 { } 532 424 }; 533 425 MODULE_DEVICE_TABLE(i2c, ltc4245_id); 534 426 535 427 /* This is the driver that will be inserted */ 536 428 static struct i2c_driver ltc4245_driver = { 537 - .class = I2C_CLASS_HWMON, 538 429 .driver = { 539 430 .name = "ltc4245", 540 431 }, 541 432 .probe = ltc4245_probe, 542 433 .remove = ltc4245_remove, 543 434 .id_table = ltc4245_id, 544 - .detect = ltc4245_detect, 545 - .address_data = &addr_data, 546 435 }; 547 436 548 437 static int __init ltc4245_init(void)