aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2007-10-10 15:14:11 -0400
committerMark M. Hoffman <mhoffman@lightlink.com>2008-02-07 20:39:41 -0500
commit4e9527998f8673b1e3bb6f9645b9700e7973581e (patch)
treeb7c53d4e2756890103f75ed35d12a1d7dde3a4be /drivers/hwmon
parentbb081300326335594c273107fcd4e5bdad765ae7 (diff)
hwmon: (adm1025) Various cleanups
* Whitespace cleanups * Constify scaling constants * Fold long lines * Drop redundant initializations to 0 * Rename new_client to just client * Use sysfs_create_group() * Drop a useless comment Signed-off-by: Jean Delvare <khali@linux-fr.org> Signed-off-by: Mark M. Hoffman <mhoffman@lightlink.com>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/adm1025.c80
1 files changed, 36 insertions, 44 deletions
diff --git a/drivers/hwmon/adm1025.c b/drivers/hwmon/adm1025.c
index 92aaa98c1497..c7a365a9e405 100644
--- a/drivers/hwmon/adm1025.c
+++ b/drivers/hwmon/adm1025.c
@@ -75,7 +75,7 @@ I2C_CLIENT_INSMOD_2(adm1025, ne1619);
75 */ 75 */
76 76
77#define ADM1025_REG_MAN_ID 0x3E 77#define ADM1025_REG_MAN_ID 0x3E
78#define ADM1025_REG_CHIP_ID 0x3F 78#define ADM1025_REG_CHIP_ID 0x3F
79#define ADM1025_REG_CONFIG 0x40 79#define ADM1025_REG_CONFIG 0x40
80#define ADM1025_REG_STATUS1 0x41 80#define ADM1025_REG_STATUS1 0x41
81#define ADM1025_REG_STATUS2 0x42 81#define ADM1025_REG_STATUS2 0x42
@@ -93,7 +93,7 @@ I2C_CLIENT_INSMOD_2(adm1025, ne1619);
93 * The ADM1025 uses signed 8-bit values for temperatures. 93 * The ADM1025 uses signed 8-bit values for temperatures.
94 */ 94 */
95 95
96static int in_scale[6] = { 2500, 2250, 3300, 5000, 12000, 3300 }; 96static const int in_scale[6] = { 2500, 2250, 3300, 5000, 12000, 3300 };
97 97
98#define IN_FROM_REG(reg,scale) (((reg) * (scale) + 96) / 192) 98#define IN_FROM_REG(reg,scale) (((reg) * (scale) + 96) / 192)
99#define IN_TO_REG(val,scale) ((val) <= 0 ? 0 : \ 99#define IN_TO_REG(val,scale) ((val) <= 0 ? 0 : \
@@ -293,7 +293,8 @@ static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \
293set_temp(1); 293set_temp(1);
294set_temp(2); 294set_temp(2);
295 295
296static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) 296static ssize_t
297show_alarms(struct device *dev, struct device_attribute *attr, char *buf)
297{ 298{
298 struct adm1025_data *data = adm1025_update_device(dev); 299 struct adm1025_data *data = adm1025_update_device(dev);
299 return sprintf(buf, "%u\n", data->alarms); 300 return sprintf(buf, "%u\n", data->alarms);
@@ -317,19 +318,22 @@ static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 5);
317static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 4); 318static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 4);
318static SENSOR_DEVICE_ATTR(temp1_fault, S_IRUGO, show_alarm, NULL, 14); 319static SENSOR_DEVICE_ATTR(temp1_fault, S_IRUGO, show_alarm, NULL, 14);
319 320
320static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf) 321static ssize_t
322show_vid(struct device *dev, struct device_attribute *attr, char *buf)
321{ 323{
322 struct adm1025_data *data = adm1025_update_device(dev); 324 struct adm1025_data *data = adm1025_update_device(dev);
323 return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm)); 325 return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm));
324} 326}
325static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); 327static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
326 328
327static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char *buf) 329static ssize_t
330show_vrm(struct device *dev, struct device_attribute *attr, char *buf)
328{ 331{
329 struct adm1025_data *data = dev_get_drvdata(dev); 332 struct adm1025_data *data = dev_get_drvdata(dev);
330 return sprintf(buf, "%u\n", data->vrm); 333 return sprintf(buf, "%u\n", data->vrm);
331} 334}
332static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 335static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
336 const char *buf, size_t count)
333{ 337{
334 struct i2c_client *client = to_i2c_client(dev); 338 struct i2c_client *client = to_i2c_client(dev);
335 struct adm1025_data *data = i2c_get_clientdata(client); 339 struct adm1025_data *data = i2c_get_clientdata(client);
@@ -389,7 +393,7 @@ static const struct attribute_group adm1025_group = {
389 .attrs = adm1025_attributes, 393 .attrs = adm1025_attributes,
390}; 394};
391 395
392static struct attribute *adm1025_attributes_opt[] = { 396static struct attribute *adm1025_attributes_in4[] = {
393 &sensor_dev_attr_in4_input.dev_attr.attr, 397 &sensor_dev_attr_in4_input.dev_attr.attr,
394 &sensor_dev_attr_in4_min.dev_attr.attr, 398 &sensor_dev_attr_in4_min.dev_attr.attr,
395 &sensor_dev_attr_in4_max.dev_attr.attr, 399 &sensor_dev_attr_in4_max.dev_attr.attr,
@@ -397,8 +401,8 @@ static struct attribute *adm1025_attributes_opt[] = {
397 NULL 401 NULL
398}; 402};
399 403
400static const struct attribute_group adm1025_group_opt = { 404static const struct attribute_group adm1025_group_in4 = {
401 .attrs = adm1025_attributes_opt, 405 .attrs = adm1025_attributes_in4,
402}; 406};
403 407
404/* 408/*
@@ -407,7 +411,7 @@ static const struct attribute_group adm1025_group_opt = {
407 */ 411 */
408static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind) 412static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
409{ 413{
410 struct i2c_client *new_client; 414 struct i2c_client *client;
411 struct adm1025_data *data; 415 struct adm1025_data *data;
412 int err = 0; 416 int err = 0;
413 const char *name = ""; 417 const char *name = "";
@@ -421,14 +425,11 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
421 goto exit; 425 goto exit;
422 } 426 }
423 427
424 /* The common I2C client data is placed right before the 428 client = &data->client;
425 ADM1025-specific data. */ 429 i2c_set_clientdata(client, data);
426 new_client = &data->client; 430 client->addr = address;
427 i2c_set_clientdata(new_client, data); 431 client->adapter = adapter;
428 new_client->addr = address; 432 client->driver = &adm1025_driver;
429 new_client->adapter = adapter;
430 new_client->driver = &adm1025_driver;
431 new_client->flags = 0;
432 433
433 /* 434 /*
434 * Now we do the remaining detection. A negative kind means that 435 * Now we do the remaining detection. A negative kind means that
@@ -440,12 +441,12 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
440 * requested, so both the detection and the identification steps 441 * requested, so both the detection and the identification steps
441 * are skipped. 442 * are skipped.
442 */ 443 */
443 config = i2c_smbus_read_byte_data(new_client, ADM1025_REG_CONFIG); 444 config = i2c_smbus_read_byte_data(client, ADM1025_REG_CONFIG);
444 if (kind < 0) { /* detection */ 445 if (kind < 0) { /* detection */
445 if ((config & 0x80) != 0x00 446 if ((config & 0x80) != 0x00
446 || (i2c_smbus_read_byte_data(new_client, 447 || (i2c_smbus_read_byte_data(client,
447 ADM1025_REG_STATUS1) & 0xC0) != 0x00 448 ADM1025_REG_STATUS1) & 0xC0) != 0x00
448 || (i2c_smbus_read_byte_data(new_client, 449 || (i2c_smbus_read_byte_data(client,
449 ADM1025_REG_STATUS2) & 0xBC) != 0x00) { 450 ADM1025_REG_STATUS2) & 0xBC) != 0x00) {
450 dev_dbg(&adapter->dev, 451 dev_dbg(&adapter->dev,
451 "ADM1025 detection failed at 0x%02x.\n", 452 "ADM1025 detection failed at 0x%02x.\n",
@@ -457,11 +458,9 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
457 if (kind <= 0) { /* identification */ 458 if (kind <= 0) { /* identification */
458 u8 man_id, chip_id; 459 u8 man_id, chip_id;
459 460
460 man_id = i2c_smbus_read_byte_data(new_client, 461 man_id = i2c_smbus_read_byte_data(client, ADM1025_REG_MAN_ID);
461 ADM1025_REG_MAN_ID); 462 chip_id = i2c_smbus_read_byte_data(client, ADM1025_REG_CHIP_ID);
462 chip_id = i2c_smbus_read_byte_data(new_client, 463
463 ADM1025_REG_CHIP_ID);
464
465 if (man_id == 0x41) { /* Analog Devices */ 464 if (man_id == 0x41) { /* Analog Devices */
466 if ((chip_id & 0xF0) == 0x20) { /* ADM1025/ADM1025A */ 465 if ((chip_id & 0xF0) == 0x20) { /* ADM1025/ADM1025A */
467 kind = adm1025; 466 kind = adm1025;
@@ -489,35 +488,28 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
489 } 488 }
490 489
491 /* We can fill in the remaining client fields */ 490 /* We can fill in the remaining client fields */
492 strlcpy(new_client->name, name, I2C_NAME_SIZE); 491 strlcpy(client->name, name, I2C_NAME_SIZE);
493 data->valid = 0;
494 mutex_init(&data->update_lock); 492 mutex_init(&data->update_lock);
495 493
496 /* Tell the I2C layer a new client has arrived */ 494 /* Tell the I2C layer a new client has arrived */
497 if ((err = i2c_attach_client(new_client))) 495 if ((err = i2c_attach_client(client)))
498 goto exit_free; 496 goto exit_free;
499 497
500 /* Initialize the ADM1025 chip */ 498 /* Initialize the ADM1025 chip */
501 adm1025_init_client(new_client); 499 adm1025_init_client(client);
502 500
503 /* Register sysfs hooks */ 501 /* Register sysfs hooks */
504 if ((err = sysfs_create_group(&new_client->dev.kobj, &adm1025_group))) 502 if ((err = sysfs_create_group(&client->dev.kobj, &adm1025_group)))
505 goto exit_detach; 503 goto exit_detach;
506 504
507 /* Pin 11 is either in4 (+12V) or VID4 */ 505 /* Pin 11 is either in4 (+12V) or VID4 */
508 if (!(config & 0x20)) { 506 if (!(config & 0x20)) {
509 if ((err = device_create_file(&new_client->dev, 507 if ((err = sysfs_create_group(&client->dev.kobj,
510 &sensor_dev_attr_in4_input.dev_attr)) 508 &adm1025_group_in4)))
511 || (err = device_create_file(&new_client->dev,
512 &sensor_dev_attr_in4_min.dev_attr))
513 || (err = device_create_file(&new_client->dev,
514 &sensor_dev_attr_in4_max.dev_attr))
515 || (err = device_create_file(&new_client->dev,
516 &sensor_dev_attr_in4_alarm.dev_attr)))
517 goto exit_remove; 509 goto exit_remove;
518 } 510 }
519 511
520 data->hwmon_dev = hwmon_device_register(&new_client->dev); 512 data->hwmon_dev = hwmon_device_register(&client->dev);
521 if (IS_ERR(data->hwmon_dev)) { 513 if (IS_ERR(data->hwmon_dev)) {
522 err = PTR_ERR(data->hwmon_dev); 514 err = PTR_ERR(data->hwmon_dev);
523 goto exit_remove; 515 goto exit_remove;
@@ -526,10 +518,10 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
526 return 0; 518 return 0;
527 519
528exit_remove: 520exit_remove:
529 sysfs_remove_group(&new_client->dev.kobj, &adm1025_group); 521 sysfs_remove_group(&client->dev.kobj, &adm1025_group);
530 sysfs_remove_group(&new_client->dev.kobj, &adm1025_group_opt); 522 sysfs_remove_group(&client->dev.kobj, &adm1025_group_in4);
531exit_detach: 523exit_detach:
532 i2c_detach_client(new_client); 524 i2c_detach_client(client);
533exit_free: 525exit_free:
534 kfree(data); 526 kfree(data);
535exit: 527exit:
@@ -585,7 +577,7 @@ static int adm1025_detach_client(struct i2c_client *client)
585 577
586 hwmon_device_unregister(data->hwmon_dev); 578 hwmon_device_unregister(data->hwmon_dev);
587 sysfs_remove_group(&client->dev.kobj, &adm1025_group); 579 sysfs_remove_group(&client->dev.kobj, &adm1025_group);
588 sysfs_remove_group(&client->dev.kobj, &adm1025_group_opt); 580 sysfs_remove_group(&client->dev.kobj, &adm1025_group_in4);
589 581
590 if ((err = i2c_detach_client(client))) 582 if ((err = i2c_detach_client(client)))
591 return err; 583 return err;