hwmon: (adm1031) Various cleanups

* Rename new_client to client
* Drop redundant initializations to 0
* Drop trailing space
* Other whitespace cleanups
* Split/fold a few long lines
* Constify static data
* Optimizations in set_fan_div()

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Mark M. Hoffman <mhoffman@lightlink.com>

authored by

Jean Delvare and committed by
Mark M. Hoffman
6d6006b8 38a1f0e9

+62 -64
+62 -64
drivers/hwmon/adm1031.c
··· 5 5 Supports adm1030 / adm1031 6 6 Copyright (C) 2004 Alexandre d'Alton <alex@alexdalton.org> 7 7 Reworked by Jean Delvare <khali@linux-fr.org> 8 - 8 + 9 9 This program is free software; you can redistribute it and/or modify 10 10 it under the terms of the GNU General Public License as published by 11 11 the Free Software Foundation; either version 2 of the License, or ··· 32 32 33 33 /* Following macros takes channel parameter starting from 0 to 2 */ 34 34 #define ADM1031_REG_FAN_SPEED(nr) (0x08 + (nr)) 35 - #define ADM1031_REG_FAN_DIV(nr) (0x20 + (nr)) 35 + #define ADM1031_REG_FAN_DIV(nr) (0x20 + (nr)) 36 36 #define ADM1031_REG_PWM (0x22) 37 37 #define ADM1031_REG_FAN_MIN(nr) (0x10 + (nr)) 38 38 39 - #define ADM1031_REG_TEMP_MAX(nr) (0x14 + 4*(nr)) 40 - #define ADM1031_REG_TEMP_MIN(nr) (0x15 + 4*(nr)) 41 - #define ADM1031_REG_TEMP_CRIT(nr) (0x16 + 4*(nr)) 39 + #define ADM1031_REG_TEMP_MAX(nr) (0x14 + 4 * (nr)) 40 + #define ADM1031_REG_TEMP_MIN(nr) (0x15 + 4 * (nr)) 41 + #define ADM1031_REG_TEMP_CRIT(nr) (0x16 + 4 * (nr)) 42 42 43 - #define ADM1031_REG_TEMP(nr) (0xa + (nr)) 43 + #define ADM1031_REG_TEMP(nr) (0x0a + (nr)) 44 44 #define ADM1031_REG_AUTO_TEMP(nr) (0x24 + (nr)) 45 45 46 46 #define ADM1031_REG_STATUS(nr) (0x2 + (nr)) 47 47 48 - #define ADM1031_REG_CONF1 0x0 49 - #define ADM1031_REG_CONF2 0x1 50 - #define ADM1031_REG_EXT_TEMP 0x6 48 + #define ADM1031_REG_CONF1 0x00 49 + #define ADM1031_REG_CONF2 0x01 50 + #define ADM1031_REG_EXT_TEMP 0x06 51 51 52 52 #define ADM1031_CONF1_MONITOR_ENABLE 0x01 /* Monitoring enable */ 53 53 #define ADM1031_CONF1_PWM_INVERT 0x08 /* PWM Invert */ ··· 78 78 /* The chan_select_table contains the possible configurations for 79 79 * auto fan control. 80 80 */ 81 - auto_chan_table_t *chan_select_table; 81 + const auto_chan_table_t *chan_select_table; 82 82 u16 alarm; 83 83 u8 conf1; 84 84 u8 conf2; ··· 181 181 #define GET_FAN_AUTO_BITFIELD(data, idx) \ 182 182 (*(data)->chan_select_table)[FAN_CHAN_FROM_REG((data)->conf1)][idx%2] 183 183 184 - /* The tables below contains the possible values for the auto fan 184 + /* The tables below contains the possible values for the auto fan 185 185 * control bitfields. the index in the table is the register value. 186 186 * MSb is the auto fan control enable bit, so the four first entries 187 187 * in the table disables auto fan control when both bitfields are zero. 188 188 */ 189 - static auto_chan_table_t auto_channel_select_table_adm1031 = { 190 - {0, 0}, {0, 0}, {0, 0}, {0, 0}, 191 - {2 /*0b010 */ , 4 /*0b100 */ }, 192 - {2 /*0b010 */ , 2 /*0b010 */ }, 193 - {4 /*0b100 */ , 4 /*0b100 */ }, 194 - {7 /*0b111 */ , 7 /*0b111 */ }, 189 + static const auto_chan_table_t auto_channel_select_table_adm1031 = { 190 + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 191 + { 2 /* 0b010 */ , 4 /* 0b100 */ }, 192 + { 2 /* 0b010 */ , 2 /* 0b010 */ }, 193 + { 4 /* 0b100 */ , 4 /* 0b100 */ }, 194 + { 7 /* 0b111 */ , 7 /* 0b111 */ }, 195 195 }; 196 196 197 - static auto_chan_table_t auto_channel_select_table_adm1030 = { 198 - {0, 0}, {0, 0}, {0, 0}, {0, 0}, 199 - {2 /*0b10 */ , 0}, 200 - {0xff /*invalid */ , 0}, 201 - {0xff /*invalid */ , 0}, 202 - {3 /*0b11 */ , 0}, 197 + static const auto_chan_table_t auto_channel_select_table_adm1030 = { 198 + { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 }, 199 + { 2 /* 0b10 */ , 0 }, 200 + { 0xff /* invalid */ , 0 }, 201 + { 0xff /* invalid */ , 0 }, 202 + { 3 /* 0b11 */ , 0 }, 203 203 }; 204 204 205 205 /* That function checks if a bitfield is valid and returns the other bitfield ··· 228 228 break; 229 229 } else if (val == (*data->chan_select_table)[i][chan] && 230 230 first_match == -1) { 231 - /* Save the first match in case of an exact match has not been 232 - * found 231 + /* Save the first match in case of an exact match has 232 + * not been found 233 233 */ 234 234 first_match = i; 235 235 } ··· 264 264 old_fan_mode = data->conf1; 265 265 266 266 mutex_lock(&data->update_lock); 267 - 267 + 268 268 if ((ret = get_fan_auto_nearest(data, nr, val, data->conf1, &reg))) { 269 269 mutex_unlock(&data->update_lock); 270 270 return ret; 271 271 } 272 - if (((data->conf1 = FAN_CHAN_TO_REG(reg, data->conf1)) & ADM1031_CONF1_AUTO_MODE) ^ 272 + data->conf1 = FAN_CHAN_TO_REG(reg, data->conf1); 273 + if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) ^ 273 274 (old_fan_mode & ADM1031_CONF1_AUTO_MODE)) { 274 275 if (data->conf1 & ADM1031_CONF1_AUTO_MODE){ 275 - /* Switch to Auto Fan Mode 276 - * Save PWM registers 276 + /* Switch to Auto Fan Mode 277 + * Save PWM registers 277 278 * Set PWM registers to 33% Both */ 278 279 data->old_pwm[0] = data->pwm[0]; 279 280 data->old_pwm[1] = data->pwm[1]; ··· 284 283 data->pwm[0] = data->old_pwm[0]; 285 284 data->pwm[1] = data->old_pwm[1]; 286 285 /* Restore PWM registers */ 287 - adm1031_write_value(client, ADM1031_REG_PWM, 286 + adm1031_write_value(client, ADM1031_REG_PWM, 288 287 data->pwm[0] | (data->pwm[1] << 4)); 289 288 } 290 289 } ··· 315 314 static ssize_t show_auto_temp_off(struct device *dev, char *buf, int nr) 316 315 { 317 316 struct adm1031_data *data = adm1031_update_device(dev); 318 - return sprintf(buf, "%d\n", 317 + return sprintf(buf, "%d\n", 319 318 AUTO_TEMP_OFF_FROM_REG(data->auto_temp[nr])); 320 319 } 321 320 static ssize_t show_auto_temp_min(struct device *dev, char *buf, int nr) ··· 408 407 int reg; 409 408 410 409 mutex_lock(&data->update_lock); 411 - if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) && 410 + if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) && 412 411 (((val>>4) & 0xf) != 5)) { 413 412 /* In automatic mode, the only PWM accepted is 33% */ 414 413 mutex_unlock(&data->update_lock); ··· 472 471 AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[0]) 473 472 || data->temp[1] >= 474 473 AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[1]) 475 - || (data->chip_type == adm1031 474 + || (data->chip_type == adm1031 476 475 && data->temp[2] >= 477 476 AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[2])); 478 477 break; ··· 515 514 516 515 mutex_lock(&data->update_lock); 517 516 if (val) { 518 - data->fan_min[nr] = 517 + data->fan_min[nr] = 519 518 FAN_TO_REG(val, FAN_DIV_FROM_REG(data->fan_div[nr])); 520 519 } else { 521 520 data->fan_min[nr] = 0xff; ··· 536 535 537 536 tmp = val == 8 ? 0xc0 : 538 537 val == 4 ? 0x80 : 539 - val == 2 ? 0x40 : 540 - val == 1 ? 0x00 : 538 + val == 2 ? 0x40 : 539 + val == 1 ? 0x00 : 541 540 0xff; 542 541 if (tmp == 0xff) 543 542 return -EINVAL; 544 - 543 + 545 544 mutex_lock(&data->update_lock); 546 545 /* Get fresh readings */ 547 546 data->fan_div[nr] = adm1031_read_value(client, ··· 551 550 552 551 /* Write the new clock divider and fan min */ 553 552 old_div = FAN_DIV_FROM_REG(data->fan_div[nr]); 554 - data->fan_div[nr] = (tmp & 0xC0) | (0x3f & data->fan_div[nr]); 555 - new_min = data->fan_min[nr] * old_div / 556 - FAN_DIV_FROM_REG(data->fan_div[nr]); 553 + data->fan_div[nr] = tmp | (0x3f & data->fan_div[nr]); 554 + new_min = data->fan_min[nr] * old_div / val; 557 555 data->fan_min[nr] = new_min > 0xff ? 0xff : new_min; 558 556 559 - adm1031_write_value(client, ADM1031_REG_FAN_DIV(nr), 557 + adm1031_write_value(client, ADM1031_REG_FAN_DIV(nr), 560 558 data->fan_div[nr]); 561 - adm1031_write_value(client, ADM1031_REG_FAN_MIN(nr), 559 + adm1031_write_value(client, ADM1031_REG_FAN_MIN(nr), 562 560 data->fan_min[nr]); 563 561 564 562 /* Invalidate the cache: fan speed is no longer valid */ ··· 796 796 /* This function is called by i2c_probe */ 797 797 static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind) 798 798 { 799 - struct i2c_client *new_client; 799 + struct i2c_client *client; 800 800 struct adm1031_data *data; 801 801 int err = 0; 802 802 const char *name = ""; ··· 809 809 goto exit; 810 810 } 811 811 812 - new_client = &data->client; 813 - i2c_set_clientdata(new_client, data); 814 - new_client->addr = address; 815 - new_client->adapter = adapter; 816 - new_client->driver = &adm1031_driver; 817 - new_client->flags = 0; 812 + client = &data->client; 813 + i2c_set_clientdata(client, data); 814 + client->addr = address; 815 + client->adapter = adapter; 816 + client->driver = &adm1031_driver; 818 817 819 818 if (kind < 0) { 820 819 int id, co; 821 - id = i2c_smbus_read_byte_data(new_client, 0x3d); 822 - co = i2c_smbus_read_byte_data(new_client, 0x3e); 820 + id = i2c_smbus_read_byte_data(client, 0x3d); 821 + co = i2c_smbus_read_byte_data(client, 0x3e); 823 822 824 823 if (!((id == 0x31 || id == 0x30) && co == 0x41)) 825 824 goto exit_free; ··· 839 840 } 840 841 data->chip_type = kind; 841 842 842 - strlcpy(new_client->name, name, I2C_NAME_SIZE); 843 - data->valid = 0; 843 + strlcpy(client->name, name, I2C_NAME_SIZE); 844 844 mutex_init(&data->update_lock); 845 845 846 846 /* Tell the I2C layer a new client has arrived */ 847 - if ((err = i2c_attach_client(new_client))) 847 + if ((err = i2c_attach_client(client))) 848 848 goto exit_free; 849 849 850 850 /* Initialize the ADM1031 chip */ 851 - adm1031_init_client(new_client); 851 + adm1031_init_client(client); 852 852 853 853 /* Register sysfs hooks */ 854 - if ((err = sysfs_create_group(&new_client->dev.kobj, &adm1031_group))) 854 + if ((err = sysfs_create_group(&client->dev.kobj, &adm1031_group))) 855 855 goto exit_detach; 856 856 857 857 if (kind == adm1031) { 858 - if ((err = sysfs_create_group(&new_client->dev.kobj, 858 + if ((err = sysfs_create_group(&client->dev.kobj, 859 859 &adm1031_group_opt))) 860 860 goto exit_remove; 861 861 } 862 862 863 - data->hwmon_dev = hwmon_device_register(&new_client->dev); 863 + data->hwmon_dev = hwmon_device_register(&client->dev); 864 864 if (IS_ERR(data->hwmon_dev)) { 865 865 err = PTR_ERR(data->hwmon_dev); 866 866 goto exit_remove; ··· 868 870 return 0; 869 871 870 872 exit_remove: 871 - sysfs_remove_group(&new_client->dev.kobj, &adm1031_group); 872 - sysfs_remove_group(&new_client->dev.kobj, &adm1031_group_opt); 873 + sysfs_remove_group(&client->dev.kobj, &adm1031_group); 874 + sysfs_remove_group(&client->dev.kobj, &adm1031_group_opt); 873 875 exit_detach: 874 - i2c_detach_client(new_client); 876 + i2c_detach_client(client); 875 877 exit_free: 876 878 kfree(data); 877 879 exit: ··· 903 905 if (data->chip_type == adm1031) { 904 906 mask |= (ADM1031_CONF2_PWM2_ENABLE | 905 907 ADM1031_CONF2_TACH2_ENABLE); 906 - } 908 + } 907 909 /* Initialize the ADM1031 chip (enables fan speed reading ) */ 908 910 read_val = adm1031_read_value(client, ADM1031_REG_CONF2); 909 911 if ((read_val | mask) != read_val) { ··· 982 984 if (data->chip_type == adm1030) { 983 985 data->alarm &= 0xc0ff; 984 986 } 985 - 987 + 986 988 for (chan=0; chan<(data->chip_type == adm1030 ? 1 : 2); chan++) { 987 989 data->fan_div[chan] = 988 990 adm1031_read_value(client, ADM1031_REG_FAN_DIV(chan)); ··· 991 993 data->fan[chan] = 992 994 adm1031_read_value(client, ADM1031_REG_FAN_SPEED(chan)); 993 995 data->pwm[chan] = 994 - 0xf & (adm1031_read_value(client, ADM1031_REG_PWM) >> 996 + 0xf & (adm1031_read_value(client, ADM1031_REG_PWM) >> 995 997 (4*chan)); 996 998 } 997 999 data->last_updated = jiffies;