Commit 6d6006b8 authored by Jean Delvare's avatar Jean Delvare Committed by Mark M. Hoffman

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: default avatarJean Delvare <khali@linux-fr.org>
Signed-off-by: default avatarMark M. Hoffman <mhoffman@lightlink.com>
parent 38a1f0e9
......@@ -36,18 +36,18 @@
#define ADM1031_REG_PWM (0x22)
#define ADM1031_REG_FAN_MIN(nr) (0x10 + (nr))
#define ADM1031_REG_TEMP_MAX(nr) (0x14 + 4*(nr))
#define ADM1031_REG_TEMP_MIN(nr) (0x15 + 4*(nr))
#define ADM1031_REG_TEMP_CRIT(nr) (0x16 + 4*(nr))
#define ADM1031_REG_TEMP_MAX(nr) (0x14 + 4 * (nr))
#define ADM1031_REG_TEMP_MIN(nr) (0x15 + 4 * (nr))
#define ADM1031_REG_TEMP_CRIT(nr) (0x16 + 4 * (nr))
#define ADM1031_REG_TEMP(nr) (0xa + (nr))
#define ADM1031_REG_TEMP(nr) (0x0a + (nr))
#define ADM1031_REG_AUTO_TEMP(nr) (0x24 + (nr))
#define ADM1031_REG_STATUS(nr) (0x2 + (nr))
#define ADM1031_REG_CONF1 0x0
#define ADM1031_REG_CONF2 0x1
#define ADM1031_REG_EXT_TEMP 0x6
#define ADM1031_REG_CONF1 0x00
#define ADM1031_REG_CONF2 0x01
#define ADM1031_REG_EXT_TEMP 0x06
#define ADM1031_CONF1_MONITOR_ENABLE 0x01 /* Monitoring enable */
#define ADM1031_CONF1_PWM_INVERT 0x08 /* PWM Invert */
......@@ -78,7 +78,7 @@ struct adm1031_data {
/* The chan_select_table contains the possible configurations for
* auto fan control.
*/
auto_chan_table_t *chan_select_table;
const auto_chan_table_t *chan_select_table;
u16 alarm;
u8 conf1;
u8 conf2;
......@@ -186,20 +186,20 @@ static int AUTO_TEMP_MAX_TO_REG(int val, int reg, int pwm)
* MSb is the auto fan control enable bit, so the four first entries
* in the table disables auto fan control when both bitfields are zero.
*/
static auto_chan_table_t auto_channel_select_table_adm1031 = {
{0, 0}, {0, 0}, {0, 0}, {0, 0},
{2 /*0b010 */ , 4 /*0b100 */ },
{2 /*0b010 */ , 2 /*0b010 */ },
{4 /*0b100 */ , 4 /*0b100 */ },
{7 /*0b111 */ , 7 /*0b111 */ },
static const auto_chan_table_t auto_channel_select_table_adm1031 = {
{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
{ 2 /* 0b010 */ , 4 /* 0b100 */ },
{ 2 /* 0b010 */ , 2 /* 0b010 */ },
{ 4 /* 0b100 */ , 4 /* 0b100 */ },
{ 7 /* 0b111 */ , 7 /* 0b111 */ },
};
static auto_chan_table_t auto_channel_select_table_adm1030 = {
{0, 0}, {0, 0}, {0, 0}, {0, 0},
{2 /*0b10 */ , 0},
{0xff /*invalid */ , 0},
{0xff /*invalid */ , 0},
{3 /*0b11 */ , 0},
static const auto_chan_table_t auto_channel_select_table_adm1030 = {
{ 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
{ 2 /* 0b10 */ , 0 },
{ 0xff /* invalid */ , 0 },
{ 0xff /* invalid */ , 0 },
{ 3 /* 0b11 */ , 0 },
};
/* That function checks if a bitfield is valid and returns the other bitfield
......@@ -228,8 +228,8 @@ get_fan_auto_nearest(struct adm1031_data *data,
break;
} else if (val == (*data->chan_select_table)[i][chan] &&
first_match == -1) {
/* Save the first match in case of an exact match has not been
* found
/* Save the first match in case of an exact match has
* not been found
*/
first_match = i;
}
......@@ -269,7 +269,8 @@ set_fan_auto_channel(struct device *dev, const char *buf, size_t count, int nr)
mutex_unlock(&data->update_lock);
return ret;
}
if (((data->conf1 = FAN_CHAN_TO_REG(reg, data->conf1)) & ADM1031_CONF1_AUTO_MODE) ^
data->conf1 = FAN_CHAN_TO_REG(reg, data->conf1);
if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) ^
(old_fan_mode & ADM1031_CONF1_AUTO_MODE)) {
if (data->conf1 & ADM1031_CONF1_AUTO_MODE){
/* Switch to Auto Fan Mode
......@@ -550,9 +551,8 @@ set_fan_div(struct device *dev, const char *buf, size_t count, int nr)
/* Write the new clock divider and fan min */
old_div = FAN_DIV_FROM_REG(data->fan_div[nr]);
data->fan_div[nr] = (tmp & 0xC0) | (0x3f & data->fan_div[nr]);
new_min = data->fan_min[nr] * old_div /
FAN_DIV_FROM_REG(data->fan_div[nr]);
data->fan_div[nr] = tmp | (0x3f & data->fan_div[nr]);
new_min = data->fan_min[nr] * old_div / val;
data->fan_min[nr] = new_min > 0xff ? 0xff : new_min;
adm1031_write_value(client, ADM1031_REG_FAN_DIV(nr),
......@@ -796,7 +796,7 @@ static const struct attribute_group adm1031_group_opt = {
/* This function is called by i2c_probe */
static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind)
{
struct i2c_client *new_client;
struct i2c_client *client;
struct adm1031_data *data;
int err = 0;
const char *name = "";
......@@ -809,17 +809,16 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind)
goto exit;
}
new_client = &data->client;
i2c_set_clientdata(new_client, data);
new_client->addr = address;
new_client->adapter = adapter;
new_client->driver = &adm1031_driver;
new_client->flags = 0;
client = &data->client;
i2c_set_clientdata(client, data);
client->addr = address;
client->adapter = adapter;
client->driver = &adm1031_driver;
if (kind < 0) {
int id, co;
id = i2c_smbus_read_byte_data(new_client, 0x3d);
co = i2c_smbus_read_byte_data(new_client, 0x3e);
id = i2c_smbus_read_byte_data(client, 0x3d);
co = i2c_smbus_read_byte_data(client, 0x3e);
if (!((id == 0x31 || id == 0x30) && co == 0x41))
goto exit_free;
......@@ -840,28 +839,27 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind)
}
data->chip_type = kind;
strlcpy(new_client->name, name, I2C_NAME_SIZE);
data->valid = 0;
strlcpy(client->name, name, I2C_NAME_SIZE);
mutex_init(&data->update_lock);
/* Tell the I2C layer a new client has arrived */
if ((err = i2c_attach_client(new_client)))
if ((err = i2c_attach_client(client)))
goto exit_free;
/* Initialize the ADM1031 chip */
adm1031_init_client(new_client);
adm1031_init_client(client);
/* Register sysfs hooks */
if ((err = sysfs_create_group(&new_client->dev.kobj, &adm1031_group)))
if ((err = sysfs_create_group(&client->dev.kobj, &adm1031_group)))
goto exit_detach;
if (kind == adm1031) {
if ((err = sysfs_create_group(&new_client->dev.kobj,
if ((err = sysfs_create_group(&client->dev.kobj,
&adm1031_group_opt)))
goto exit_remove;
}
data->hwmon_dev = hwmon_device_register(&new_client->dev);
data->hwmon_dev = hwmon_device_register(&client->dev);
if (IS_ERR(data->hwmon_dev)) {
err = PTR_ERR(data->hwmon_dev);
goto exit_remove;
......@@ -870,10 +868,10 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind)
return 0;
exit_remove:
sysfs_remove_group(&new_client->dev.kobj, &adm1031_group);
sysfs_remove_group(&new_client->dev.kobj, &adm1031_group_opt);
sysfs_remove_group(&client->dev.kobj, &adm1031_group);
sysfs_remove_group(&client->dev.kobj, &adm1031_group_opt);
exit_detach:
i2c_detach_client(new_client);
i2c_detach_client(client);
exit_free:
kfree(data);
exit:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment