diff options
author | Grant Coady <grant_lkml@dodo.com.au> | 2005-09-16 15:32:55 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2005-10-28 17:02:05 -0400 |
commit | 205cf13e0b57500e2cc6442effa991c1a63f4db7 (patch) | |
tree | 8519455083b045e270e0513646a76d351567b3bb /drivers/hwmon | |
parent | 84860bf0644d7c45afe7ddbd30731c3e3c371fae (diff) |
[PATCH] hwmon: adm9240 driver update - cleanups
hwmon: adm9240 update 1/2: cleanups:
o remove i2c read/write wrapper interface as it does nothing,
o change kmalloc + memset to kzalloc
Signed-off-by: Grant Coady <gcoady@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/adm9240.c | 92 |
1 files changed, 44 insertions, 48 deletions
diff --git a/drivers/hwmon/adm9240.c b/drivers/hwmon/adm9240.c index bc7faef162f7..ecef342e5fa3 100644 --- a/drivers/hwmon/adm9240.c +++ b/drivers/hwmon/adm9240.c | |||
@@ -170,17 +170,6 @@ struct adm9240_data { | |||
170 | u8 vrm; /* -- vrm set on startup, no accessor */ | 170 | u8 vrm; /* -- vrm set on startup, no accessor */ |
171 | }; | 171 | }; |
172 | 172 | ||
173 | /* i2c byte read/write interface */ | ||
174 | static int adm9240_read_value(struct i2c_client *client, u8 reg) | ||
175 | { | ||
176 | return i2c_smbus_read_byte_data(client, reg); | ||
177 | } | ||
178 | |||
179 | static int adm9240_write_value(struct i2c_client *client, u8 reg, u8 value) | ||
180 | { | ||
181 | return i2c_smbus_write_byte_data(client, reg, value); | ||
182 | } | ||
183 | |||
184 | /*** sysfs accessors ***/ | 173 | /*** sysfs accessors ***/ |
185 | 174 | ||
186 | /* temperature */ | 175 | /* temperature */ |
@@ -207,7 +196,7 @@ static ssize_t set_##value(struct device *dev, \ | |||
207 | \ | 196 | \ |
208 | down(&data->update_lock); \ | 197 | down(&data->update_lock); \ |
209 | data->value = TEMP_TO_REG(temp); \ | 198 | data->value = TEMP_TO_REG(temp); \ |
210 | adm9240_write_value(client, reg, data->value); \ | 199 | i2c_smbus_write_byte_data(client, reg, data->value); \ |
211 | up(&data->update_lock); \ | 200 | up(&data->update_lock); \ |
212 | return count; \ | 201 | return count; \ |
213 | } | 202 | } |
@@ -249,7 +238,8 @@ static ssize_t set_in_min(struct device *dev, const char *buf, | |||
249 | 238 | ||
250 | down(&data->update_lock); | 239 | down(&data->update_lock); |
251 | data->in_min[nr] = IN_TO_REG(val, nr); | 240 | data->in_min[nr] = IN_TO_REG(val, nr); |
252 | adm9240_write_value(client, ADM9240_REG_IN_MIN(nr), data->in_min[nr]); | 241 | i2c_smbus_write_byte_data(client, ADM9240_REG_IN_MIN(nr), |
242 | data->in_min[nr]); | ||
253 | up(&data->update_lock); | 243 | up(&data->update_lock); |
254 | return count; | 244 | return count; |
255 | } | 245 | } |
@@ -263,7 +253,8 @@ static ssize_t set_in_max(struct device *dev, const char *buf, | |||
263 | 253 | ||
264 | down(&data->update_lock); | 254 | down(&data->update_lock); |
265 | data->in_max[nr] = IN_TO_REG(val, nr); | 255 | data->in_max[nr] = IN_TO_REG(val, nr); |
266 | adm9240_write_value(client, ADM9240_REG_IN_MAX(nr), data->in_max[nr]); | 256 | i2c_smbus_write_byte_data(client, ADM9240_REG_IN_MAX(nr), |
257 | data->in_max[nr]); | ||
267 | up(&data->update_lock); | 258 | up(&data->update_lock); |
268 | return count; | 259 | return count; |
269 | } | 260 | } |
@@ -341,11 +332,11 @@ static void adm9240_write_fan_div(struct i2c_client *client, int nr, | |||
341 | { | 332 | { |
342 | u8 reg, old, shift = (nr + 2) * 2; | 333 | u8 reg, old, shift = (nr + 2) * 2; |
343 | 334 | ||
344 | reg = adm9240_read_value(client, ADM9240_REG_VID_FAN_DIV); | 335 | reg = i2c_smbus_read_byte_data(client, ADM9240_REG_VID_FAN_DIV); |
345 | old = (reg >> shift) & 3; | 336 | old = (reg >> shift) & 3; |
346 | reg &= ~(3 << shift); | 337 | reg &= ~(3 << shift); |
347 | reg |= (fan_div << shift); | 338 | reg |= (fan_div << shift); |
348 | adm9240_write_value(client, ADM9240_REG_VID_FAN_DIV, reg); | 339 | i2c_smbus_write_byte_data(client, ADM9240_REG_VID_FAN_DIV, reg); |
349 | dev_dbg(&client->dev, "fan%d clock divider changed from %u " | 340 | dev_dbg(&client->dev, "fan%d clock divider changed from %u " |
350 | "to %u\n", nr + 1, 1 << old, 1 << fan_div); | 341 | "to %u\n", nr + 1, 1 << old, 1 << fan_div); |
351 | } | 342 | } |
@@ -406,7 +397,7 @@ static ssize_t set_fan_min(struct device *dev, const char *buf, | |||
406 | data->fan_div[nr] = new_div; | 397 | data->fan_div[nr] = new_div; |
407 | adm9240_write_fan_div(client, nr, new_div); | 398 | adm9240_write_fan_div(client, nr, new_div); |
408 | } | 399 | } |
409 | adm9240_write_value(client, ADM9240_REG_FAN_MIN(nr), | 400 | i2c_smbus_write_byte_data(client, ADM9240_REG_FAN_MIN(nr), |
410 | data->fan_min[nr]); | 401 | data->fan_min[nr]); |
411 | 402 | ||
412 | up(&data->update_lock); | 403 | up(&data->update_lock); |
@@ -479,7 +470,7 @@ static ssize_t set_aout(struct device *dev, struct device_attribute *attr, const | |||
479 | 470 | ||
480 | down(&data->update_lock); | 471 | down(&data->update_lock); |
481 | data->aout = AOUT_TO_REG(val); | 472 | data->aout = AOUT_TO_REG(val); |
482 | adm9240_write_value(client, ADM9240_REG_ANALOG_OUT, data->aout); | 473 | i2c_smbus_write_byte_data(client, ADM9240_REG_ANALOG_OUT, data->aout); |
483 | up(&data->update_lock); | 474 | up(&data->update_lock); |
484 | return count; | 475 | return count; |
485 | } | 476 | } |
@@ -492,7 +483,8 @@ static ssize_t chassis_clear(struct device *dev, struct device_attribute *attr, | |||
492 | unsigned long val = simple_strtol(buf, NULL, 10); | 483 | unsigned long val = simple_strtol(buf, NULL, 10); |
493 | 484 | ||
494 | if (val == 1) { | 485 | if (val == 1) { |
495 | adm9240_write_value(client, ADM9240_REG_CHASSIS_CLEAR, 0x80); | 486 | i2c_smbus_write_byte_data(client, |
487 | ADM9240_REG_CHASSIS_CLEAR, 0x80); | ||
496 | dev_dbg(&client->dev, "chassis intrusion latch cleared\n"); | 488 | dev_dbg(&client->dev, "chassis intrusion latch cleared\n"); |
497 | } | 489 | } |
498 | return count; | 490 | return count; |
@@ -513,11 +505,10 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind) | |||
513 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 505 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
514 | goto exit; | 506 | goto exit; |
515 | 507 | ||
516 | if (!(data = kmalloc(sizeof(struct adm9240_data), GFP_KERNEL))) { | 508 | if (!(data = kzalloc(sizeof(*data), GFP_KERNEL))) { |
517 | err = -ENOMEM; | 509 | err = -ENOMEM; |
518 | goto exit; | 510 | goto exit; |
519 | } | 511 | } |
520 | memset(data, 0, sizeof(struct adm9240_data)); | ||
521 | 512 | ||
522 | new_client = &data->client; | 513 | new_client = &data->client; |
523 | i2c_set_clientdata(new_client, data); | 514 | i2c_set_clientdata(new_client, data); |
@@ -533,7 +524,7 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind) | |||
533 | if (kind < 0) { | 524 | if (kind < 0) { |
534 | 525 | ||
535 | /* verify chip: reg address should match i2c address */ | 526 | /* verify chip: reg address should match i2c address */ |
536 | if (adm9240_read_value(new_client, ADM9240_REG_I2C_ADDR) | 527 | if (i2c_smbus_read_byte_data(new_client, ADM9240_REG_I2C_ADDR) |
537 | != address) { | 528 | != address) { |
538 | dev_err(&adapter->dev, "detect fail: address match, " | 529 | dev_err(&adapter->dev, "detect fail: address match, " |
539 | "0x%02x\n", address); | 530 | "0x%02x\n", address); |
@@ -541,8 +532,8 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind) | |||
541 | } | 532 | } |
542 | 533 | ||
543 | /* check known chip manufacturer */ | 534 | /* check known chip manufacturer */ |
544 | man_id = adm9240_read_value(new_client, ADM9240_REG_MAN_ID); | 535 | man_id = i2c_smbus_read_byte_data(new_client, |
545 | 536 | ADM9240_REG_MAN_ID); | |
546 | if (man_id == 0x23) { | 537 | if (man_id == 0x23) { |
547 | kind = adm9240; | 538 | kind = adm9240; |
548 | } else if (man_id == 0xda) { | 539 | } else if (man_id == 0xda) { |
@@ -556,7 +547,8 @@ static int adm9240_detect(struct i2c_adapter *adapter, int address, int kind) | |||
556 | } | 547 | } |
557 | 548 | ||
558 | /* successful detect, print chip info */ | 549 | /* successful detect, print chip info */ |
559 | die_rev = adm9240_read_value(new_client, ADM9240_REG_DIE_REV); | 550 | die_rev = i2c_smbus_read_byte_data(new_client, |
551 | ADM9240_REG_DIE_REV); | ||
560 | dev_info(&adapter->dev, "found %s revision %u\n", | 552 | dev_info(&adapter->dev, "found %s revision %u\n", |
561 | man_id == 0x23 ? "ADM9240" : | 553 | man_id == 0x23 ? "ADM9240" : |
562 | man_id == 0xda ? "DS1780" : "LM81", die_rev); | 554 | man_id == 0xda ? "DS1780" : "LM81", die_rev); |
@@ -654,8 +646,8 @@ static int adm9240_detach_client(struct i2c_client *client) | |||
654 | static void adm9240_init_client(struct i2c_client *client) | 646 | static void adm9240_init_client(struct i2c_client *client) |
655 | { | 647 | { |
656 | struct adm9240_data *data = i2c_get_clientdata(client); | 648 | struct adm9240_data *data = i2c_get_clientdata(client); |
657 | u8 conf = adm9240_read_value(client, ADM9240_REG_CONFIG); | 649 | u8 conf = i2c_smbus_read_byte_data(client, ADM9240_REG_CONFIG); |
658 | u8 mode = adm9240_read_value(client, ADM9240_REG_TEMP_CONF) & 3; | 650 | u8 mode = i2c_smbus_read_byte_data(client, ADM9240_REG_TEMP_CONF) & 3; |
659 | 651 | ||
660 | data->vrm = vid_which_vrm(); /* need this to report vid as mV */ | 652 | data->vrm = vid_which_vrm(); /* need this to report vid as mV */ |
661 | 653 | ||
@@ -672,18 +664,22 @@ static void adm9240_init_client(struct i2c_client *client) | |||
672 | 664 | ||
673 | for (i = 0; i < 6; i++) | 665 | for (i = 0; i < 6; i++) |
674 | { | 666 | { |
675 | adm9240_write_value(client, | 667 | i2c_smbus_write_byte_data(client, |
676 | ADM9240_REG_IN_MIN(i), 0); | 668 | ADM9240_REG_IN_MIN(i), 0); |
677 | adm9240_write_value(client, | 669 | i2c_smbus_write_byte_data(client, |
678 | ADM9240_REG_IN_MAX(i), 255); | 670 | ADM9240_REG_IN_MAX(i), 255); |
679 | } | 671 | } |
680 | adm9240_write_value(client, ADM9240_REG_FAN_MIN(0), 255); | 672 | i2c_smbus_write_byte_data(client, |
681 | adm9240_write_value(client, ADM9240_REG_FAN_MIN(1), 255); | 673 | ADM9240_REG_FAN_MIN(0), 255); |
682 | adm9240_write_value(client, ADM9240_REG_TEMP_HIGH, 127); | 674 | i2c_smbus_write_byte_data(client, |
683 | adm9240_write_value(client, ADM9240_REG_TEMP_HYST, 127); | 675 | ADM9240_REG_FAN_MIN(1), 255); |
676 | i2c_smbus_write_byte_data(client, | ||
677 | ADM9240_REG_TEMP_HIGH, 127); | ||
678 | i2c_smbus_write_byte_data(client, | ||
679 | ADM9240_REG_TEMP_HYST, 127); | ||
684 | 680 | ||
685 | /* start measurement cycle */ | 681 | /* start measurement cycle */ |
686 | adm9240_write_value(client, ADM9240_REG_CONFIG, 1); | 682 | i2c_smbus_write_byte_data(client, ADM9240_REG_CONFIG, 1); |
687 | 683 | ||
688 | dev_info(&client->dev, "cold start: config was 0x%02x " | 684 | dev_info(&client->dev, "cold start: config was 0x%02x " |
689 | "mode %u\n", conf, mode); | 685 | "mode %u\n", conf, mode); |
@@ -704,25 +700,25 @@ static struct adm9240_data *adm9240_update_device(struct device *dev) | |||
704 | 700 | ||
705 | for (i = 0; i < 6; i++) /* read voltages */ | 701 | for (i = 0; i < 6; i++) /* read voltages */ |
706 | { | 702 | { |
707 | data->in[i] = adm9240_read_value(client, | 703 | data->in[i] = i2c_smbus_read_byte_data(client, |
708 | ADM9240_REG_IN(i)); | 704 | ADM9240_REG_IN(i)); |
709 | } | 705 | } |
710 | data->alarms = adm9240_read_value(client, | 706 | data->alarms = i2c_smbus_read_byte_data(client, |
711 | ADM9240_REG_INT(0)) | | 707 | ADM9240_REG_INT(0)) | |
712 | adm9240_read_value(client, | 708 | i2c_smbus_read_byte_data(client, |
713 | ADM9240_REG_INT(1)) << 8; | 709 | ADM9240_REG_INT(1)) << 8; |
714 | 710 | ||
715 | /* read temperature: assume temperature changes less than | 711 | /* read temperature: assume temperature changes less than |
716 | * 0.5'C per two measurement cycles thus ignore possible | 712 | * 0.5'C per two measurement cycles thus ignore possible |
717 | * but unlikely aliasing error on lsb reading. --Grant */ | 713 | * but unlikely aliasing error on lsb reading. --Grant */ |
718 | data->temp = ((adm9240_read_value(client, | 714 | data->temp = ((i2c_smbus_read_byte_data(client, |
719 | ADM9240_REG_TEMP) << 8) | | 715 | ADM9240_REG_TEMP) << 8) | |
720 | adm9240_read_value(client, | 716 | i2c_smbus_read_byte_data(client, |
721 | ADM9240_REG_TEMP_CONF)) / 128; | 717 | ADM9240_REG_TEMP_CONF)) / 128; |
722 | 718 | ||
723 | for (i = 0; i < 2; i++) /* read fans */ | 719 | for (i = 0; i < 2; i++) /* read fans */ |
724 | { | 720 | { |
725 | data->fan[i] = adm9240_read_value(client, | 721 | data->fan[i] = i2c_smbus_read_byte_data(client, |
726 | ADM9240_REG_FAN(i)); | 722 | ADM9240_REG_FAN(i)); |
727 | 723 | ||
728 | /* adjust fan clock divider on overflow */ | 724 | /* adjust fan clock divider on overflow */ |
@@ -747,30 +743,30 @@ static struct adm9240_data *adm9240_update_device(struct device *dev) | |||
747 | 743 | ||
748 | for (i = 0; i < 6; i++) | 744 | for (i = 0; i < 6; i++) |
749 | { | 745 | { |
750 | data->in_min[i] = adm9240_read_value(client, | 746 | data->in_min[i] = i2c_smbus_read_byte_data(client, |
751 | ADM9240_REG_IN_MIN(i)); | 747 | ADM9240_REG_IN_MIN(i)); |
752 | data->in_max[i] = adm9240_read_value(client, | 748 | data->in_max[i] = i2c_smbus_read_byte_data(client, |
753 | ADM9240_REG_IN_MAX(i)); | 749 | ADM9240_REG_IN_MAX(i)); |
754 | } | 750 | } |
755 | for (i = 0; i < 2; i++) | 751 | for (i = 0; i < 2; i++) |
756 | { | 752 | { |
757 | data->fan_min[i] = adm9240_read_value(client, | 753 | data->fan_min[i] = i2c_smbus_read_byte_data(client, |
758 | ADM9240_REG_FAN_MIN(i)); | 754 | ADM9240_REG_FAN_MIN(i)); |
759 | } | 755 | } |
760 | data->temp_high = adm9240_read_value(client, | 756 | data->temp_high = i2c_smbus_read_byte_data(client, |
761 | ADM9240_REG_TEMP_HIGH); | 757 | ADM9240_REG_TEMP_HIGH); |
762 | data->temp_hyst = adm9240_read_value(client, | 758 | data->temp_hyst = i2c_smbus_read_byte_data(client, |
763 | ADM9240_REG_TEMP_HYST); | 759 | ADM9240_REG_TEMP_HYST); |
764 | 760 | ||
765 | /* read fan divs and 5-bit VID */ | 761 | /* read fan divs and 5-bit VID */ |
766 | i = adm9240_read_value(client, ADM9240_REG_VID_FAN_DIV); | 762 | i = i2c_smbus_read_byte_data(client, ADM9240_REG_VID_FAN_DIV); |
767 | data->fan_div[0] = (i >> 4) & 3; | 763 | data->fan_div[0] = (i >> 4) & 3; |
768 | data->fan_div[1] = (i >> 6) & 3; | 764 | data->fan_div[1] = (i >> 6) & 3; |
769 | data->vid = i & 0x0f; | 765 | data->vid = i & 0x0f; |
770 | data->vid |= (adm9240_read_value(client, | 766 | data->vid |= (i2c_smbus_read_byte_data(client, |
771 | ADM9240_REG_VID4) & 1) << 4; | 767 | ADM9240_REG_VID4) & 1) << 4; |
772 | /* read analog out */ | 768 | /* read analog out */ |
773 | data->aout = adm9240_read_value(client, | 769 | data->aout = i2c_smbus_read_byte_data(client, |
774 | ADM9240_REG_ANALOG_OUT); | 770 | ADM9240_REG_ANALOG_OUT); |
775 | 771 | ||
776 | data->last_updated_config = jiffies; | 772 | data->last_updated_config = jiffies; |