hwmon: (asb100) Various cleanups
* Drop history, it's incomplete and doesn't belong there * Drop unused version number * Drop trailing spaces * Coding style fixes * Fold long lines * Rename new_client to client * Drop redundant initializations to 0 Signed-off-by: Jean Delvare <khali@linux-fr.org> Acked-by: Hans de Goede <j.w.r.degoede@hhs.nl> Signed-off-by: Mark M. Hoffman <mhoffman@lightlink.com>
This commit is contained in:
committed by
Mark M. Hoffman
parent
8f74efe81d
commit
af22193151
@@ -47,12 +47,6 @@
|
|||||||
#include <linux/mutex.h>
|
#include <linux/mutex.h>
|
||||||
#include "lm75.h"
|
#include "lm75.h"
|
||||||
|
|
||||||
/*
|
|
||||||
HISTORY:
|
|
||||||
2003-12-29 1.0.0 Ported from lm_sensors project for kernel 2.6
|
|
||||||
*/
|
|
||||||
#define ASB100_VERSION "1.0.0"
|
|
||||||
|
|
||||||
/* I2C addresses to scan */
|
/* I2C addresses to scan */
|
||||||
static unsigned short normal_i2c[] = { 0x2d, I2C_CLIENT_END };
|
static unsigned short normal_i2c[] = { 0x2d, I2C_CLIENT_END };
|
||||||
|
|
||||||
@@ -502,7 +496,8 @@ sysfs_temp(3);
|
|||||||
sysfs_temp(4);
|
sysfs_temp(4);
|
||||||
|
|
||||||
/* VID */
|
/* VID */
|
||||||
static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf)
|
static ssize_t show_vid(struct device *dev, struct device_attribute *attr,
|
||||||
|
char *buf)
|
||||||
{
|
{
|
||||||
struct asb100_data *data = asb100_update_device(dev);
|
struct asb100_data *data = asb100_update_device(dev);
|
||||||
return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm));
|
return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm));
|
||||||
@@ -511,13 +506,15 @@ static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char
|
|||||||
static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
|
static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
|
||||||
|
|
||||||
/* VRM */
|
/* VRM */
|
||||||
static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char *buf)
|
static ssize_t show_vrm(struct device *dev, struct device_attribute *attr,
|
||||||
|
char *buf)
|
||||||
{
|
{
|
||||||
struct asb100_data *data = dev_get_drvdata(dev);
|
struct asb100_data *data = dev_get_drvdata(dev);
|
||||||
return sprintf(buf, "%d\n", data->vrm);
|
return sprintf(buf, "%d\n", data->vrm);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
|
static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
|
||||||
|
const char *buf, size_t count)
|
||||||
{
|
{
|
||||||
struct asb100_data *data = dev_get_drvdata(dev);
|
struct asb100_data *data = dev_get_drvdata(dev);
|
||||||
data->vrm = simple_strtoul(buf, NULL, 10);
|
data->vrm = simple_strtoul(buf, NULL, 10);
|
||||||
@@ -527,7 +524,8 @@ static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const
|
|||||||
/* Alarms */
|
/* Alarms */
|
||||||
static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm);
|
static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm);
|
||||||
|
|
||||||
static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf)
|
static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
|
||||||
|
char *buf)
|
||||||
{
|
{
|
||||||
struct asb100_data *data = asb100_update_device(dev);
|
struct asb100_data *data = asb100_update_device(dev);
|
||||||
return sprintf(buf, "%u\n", data->alarms);
|
return sprintf(buf, "%u\n", data->alarms);
|
||||||
@@ -536,13 +534,15 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, ch
|
|||||||
static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
|
static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
|
||||||
|
|
||||||
/* 1 PWM */
|
/* 1 PWM */
|
||||||
static ssize_t show_pwm1(struct device *dev, struct device_attribute *attr, char *buf)
|
static ssize_t show_pwm1(struct device *dev, struct device_attribute *attr,
|
||||||
|
char *buf)
|
||||||
{
|
{
|
||||||
struct asb100_data *data = asb100_update_device(dev);
|
struct asb100_data *data = asb100_update_device(dev);
|
||||||
return sprintf(buf, "%d\n", ASB100_PWM_FROM_REG(data->pwm & 0x0f));
|
return sprintf(buf, "%d\n", ASB100_PWM_FROM_REG(data->pwm & 0x0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t set_pwm1(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
|
static ssize_t set_pwm1(struct device *dev, struct device_attribute *attr,
|
||||||
|
const char *buf, size_t count)
|
||||||
{
|
{
|
||||||
struct i2c_client *client = to_i2c_client(dev);
|
struct i2c_client *client = to_i2c_client(dev);
|
||||||
struct asb100_data *data = i2c_get_clientdata(client);
|
struct asb100_data *data = i2c_get_clientdata(client);
|
||||||
@@ -556,14 +556,15 @@ static ssize_t set_pwm1(struct device *dev, struct device_attribute *attr, const
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t show_pwm_enable1(struct device *dev, struct device_attribute *attr, char *buf)
|
static ssize_t show_pwm_enable1(struct device *dev,
|
||||||
|
struct device_attribute *attr, char *buf)
|
||||||
{
|
{
|
||||||
struct asb100_data *data = asb100_update_device(dev);
|
struct asb100_data *data = asb100_update_device(dev);
|
||||||
return sprintf(buf, "%d\n", (data->pwm & 0x80) ? 1 : 0);
|
return sprintf(buf, "%d\n", (data->pwm & 0x80) ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t set_pwm_enable1(struct device *dev, struct device_attribute *attr, const char *buf,
|
static ssize_t set_pwm_enable1(struct device *dev,
|
||||||
size_t count)
|
struct device_attribute *attr, const char *buf, size_t count)
|
||||||
{
|
{
|
||||||
struct i2c_client *client = to_i2c_client(dev);
|
struct i2c_client *client = to_i2c_client(dev);
|
||||||
struct asb100_data *data = i2c_get_clientdata(client);
|
struct asb100_data *data = i2c_get_clientdata(client);
|
||||||
@@ -653,10 +654,10 @@ static int asb100_attach_adapter(struct i2c_adapter *adapter)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int asb100_detect_subclients(struct i2c_adapter *adapter, int address,
|
static int asb100_detect_subclients(struct i2c_adapter *adapter, int address,
|
||||||
int kind, struct i2c_client *new_client)
|
int kind, struct i2c_client *client)
|
||||||
{
|
{
|
||||||
int i, id, err;
|
int i, id, err;
|
||||||
struct asb100_data *data = i2c_get_clientdata(new_client);
|
struct asb100_data *data = i2c_get_clientdata(client);
|
||||||
|
|
||||||
data->lm75[0] = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
|
data->lm75[0] = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
|
||||||
if (!(data->lm75[0])) {
|
if (!(data->lm75[0])) {
|
||||||
@@ -676,26 +677,26 @@ static int asb100_detect_subclients(struct i2c_adapter *adapter, int address,
|
|||||||
for (i = 2; i <= 3; i++) {
|
for (i = 2; i <= 3; i++) {
|
||||||
if (force_subclients[i] < 0x48 ||
|
if (force_subclients[i] < 0x48 ||
|
||||||
force_subclients[i] > 0x4f) {
|
force_subclients[i] > 0x4f) {
|
||||||
dev_err(&new_client->dev, "invalid subclient "
|
dev_err(&client->dev, "invalid subclient "
|
||||||
"address %d; must be 0x48-0x4f\n",
|
"address %d; must be 0x48-0x4f\n",
|
||||||
force_subclients[i]);
|
force_subclients[i]);
|
||||||
err = -ENODEV;
|
err = -ENODEV;
|
||||||
goto ERROR_SC_2;
|
goto ERROR_SC_2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
asb100_write_value(new_client, ASB100_REG_I2C_SUBADDR,
|
asb100_write_value(client, ASB100_REG_I2C_SUBADDR,
|
||||||
(force_subclients[2] & 0x07) |
|
(force_subclients[2] & 0x07) |
|
||||||
((force_subclients[3] & 0x07) << 4));
|
((force_subclients[3] & 0x07) << 4));
|
||||||
data->lm75[0]->addr = force_subclients[2];
|
data->lm75[0]->addr = force_subclients[2];
|
||||||
data->lm75[1]->addr = force_subclients[3];
|
data->lm75[1]->addr = force_subclients[3];
|
||||||
} else {
|
} else {
|
||||||
int val = asb100_read_value(new_client, ASB100_REG_I2C_SUBADDR);
|
int val = asb100_read_value(client, ASB100_REG_I2C_SUBADDR);
|
||||||
data->lm75[0]->addr = 0x48 + (val & 0x07);
|
data->lm75[0]->addr = 0x48 + (val & 0x07);
|
||||||
data->lm75[1]->addr = 0x48 + ((val >> 4) & 0x07);
|
data->lm75[1]->addr = 0x48 + ((val >> 4) & 0x07);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->lm75[0]->addr == data->lm75[1]->addr) {
|
if (data->lm75[0]->addr == data->lm75[1]->addr) {
|
||||||
dev_err(&new_client->dev, "duplicate addresses 0x%x "
|
dev_err(&client->dev, "duplicate addresses 0x%x "
|
||||||
"for subclients\n", data->lm75[0]->addr);
|
"for subclients\n", data->lm75[0]->addr);
|
||||||
err = -ENODEV;
|
err = -ENODEV;
|
||||||
goto ERROR_SC_2;
|
goto ERROR_SC_2;
|
||||||
@@ -705,18 +706,17 @@ static int asb100_detect_subclients(struct i2c_adapter *adapter, int address,
|
|||||||
i2c_set_clientdata(data->lm75[i], NULL);
|
i2c_set_clientdata(data->lm75[i], NULL);
|
||||||
data->lm75[i]->adapter = adapter;
|
data->lm75[i]->adapter = adapter;
|
||||||
data->lm75[i]->driver = &asb100_driver;
|
data->lm75[i]->driver = &asb100_driver;
|
||||||
data->lm75[i]->flags = 0;
|
|
||||||
strlcpy(data->lm75[i]->name, "asb100 subclient", I2C_NAME_SIZE);
|
strlcpy(data->lm75[i]->name, "asb100 subclient", I2C_NAME_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = i2c_attach_client(data->lm75[0]))) {
|
if ((err = i2c_attach_client(data->lm75[0]))) {
|
||||||
dev_err(&new_client->dev, "subclient %d registration "
|
dev_err(&client->dev, "subclient %d registration "
|
||||||
"at address 0x%x failed.\n", i, data->lm75[0]->addr);
|
"at address 0x%x failed.\n", i, data->lm75[0]->addr);
|
||||||
goto ERROR_SC_2;
|
goto ERROR_SC_2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((err = i2c_attach_client(data->lm75[1]))) {
|
if ((err = i2c_attach_client(data->lm75[1]))) {
|
||||||
dev_err(&new_client->dev, "subclient %d registration "
|
dev_err(&client->dev, "subclient %d registration "
|
||||||
"at address 0x%x failed.\n", i, data->lm75[1]->addr);
|
"at address 0x%x failed.\n", i, data->lm75[1]->addr);
|
||||||
goto ERROR_SC_3;
|
goto ERROR_SC_3;
|
||||||
}
|
}
|
||||||
@@ -737,7 +737,7 @@ ERROR_SC_0:
|
|||||||
static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
|
static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
struct i2c_client *new_client;
|
struct i2c_client *client;
|
||||||
struct asb100_data *data;
|
struct asb100_data *data;
|
||||||
|
|
||||||
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
|
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
|
||||||
@@ -757,13 +757,12 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
|
|||||||
goto ERROR0;
|
goto ERROR0;
|
||||||
}
|
}
|
||||||
|
|
||||||
new_client = &data->client;
|
client = &data->client;
|
||||||
mutex_init(&data->lock);
|
mutex_init(&data->lock);
|
||||||
i2c_set_clientdata(new_client, data);
|
i2c_set_clientdata(client, data);
|
||||||
new_client->addr = address;
|
client->addr = address;
|
||||||
new_client->adapter = adapter;
|
client->adapter = adapter;
|
||||||
new_client->driver = &asb100_driver;
|
client->driver = &asb100_driver;
|
||||||
new_client->flags = 0;
|
|
||||||
|
|
||||||
/* Now, we do the remaining detection. */
|
/* Now, we do the remaining detection. */
|
||||||
|
|
||||||
@@ -773,8 +772,8 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
|
|||||||
bank. */
|
bank. */
|
||||||
if (kind < 0) {
|
if (kind < 0) {
|
||||||
|
|
||||||
int val1 = asb100_read_value(new_client, ASB100_REG_BANK);
|
int val1 = asb100_read_value(client, ASB100_REG_BANK);
|
||||||
int val2 = asb100_read_value(new_client, ASB100_REG_CHIPMAN);
|
int val2 = asb100_read_value(client, ASB100_REG_CHIPMAN);
|
||||||
|
|
||||||
/* If we're in bank 0 */
|
/* If we're in bank 0 */
|
||||||
if ((!(val1 & 0x07)) &&
|
if ((!(val1 & 0x07)) &&
|
||||||
@@ -792,19 +791,19 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
|
|||||||
|
|
||||||
/* We have either had a force parameter, or we have already detected
|
/* We have either had a force parameter, or we have already detected
|
||||||
Winbond. Put it now into bank 0 and Vendor ID High Byte */
|
Winbond. Put it now into bank 0 and Vendor ID High Byte */
|
||||||
asb100_write_value(new_client, ASB100_REG_BANK,
|
asb100_write_value(client, ASB100_REG_BANK,
|
||||||
(asb100_read_value(new_client, ASB100_REG_BANK) & 0x78) | 0x80);
|
(asb100_read_value(client, ASB100_REG_BANK) & 0x78) | 0x80);
|
||||||
|
|
||||||
/* Determine the chip type. */
|
/* Determine the chip type. */
|
||||||
if (kind <= 0) {
|
if (kind <= 0) {
|
||||||
int val1 = asb100_read_value(new_client, ASB100_REG_WCHIPID);
|
int val1 = asb100_read_value(client, ASB100_REG_WCHIPID);
|
||||||
int val2 = asb100_read_value(new_client, ASB100_REG_CHIPMAN);
|
int val2 = asb100_read_value(client, ASB100_REG_CHIPMAN);
|
||||||
|
|
||||||
if ((val1 == 0x31) && (val2 == 0x06))
|
if ((val1 == 0x31) && (val2 == 0x06))
|
||||||
kind = asb100;
|
kind = asb100;
|
||||||
else {
|
else {
|
||||||
if (kind == 0)
|
if (kind == 0)
|
||||||
dev_warn(&new_client->dev, "ignoring "
|
dev_warn(&client->dev, "ignoring "
|
||||||
"'force' parameter for unknown chip "
|
"'force' parameter for unknown chip "
|
||||||
"at adapter %d, address 0x%02x.\n",
|
"at adapter %d, address 0x%02x.\n",
|
||||||
i2c_adapter_id(adapter), address);
|
i2c_adapter_id(adapter), address);
|
||||||
@@ -814,34 +813,32 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Fill in remaining client fields and put it into the global list */
|
/* Fill in remaining client fields and put it into the global list */
|
||||||
strlcpy(new_client->name, "asb100", I2C_NAME_SIZE);
|
strlcpy(client->name, "asb100", I2C_NAME_SIZE);
|
||||||
data->type = kind;
|
data->type = kind;
|
||||||
|
|
||||||
data->valid = 0;
|
|
||||||
mutex_init(&data->update_lock);
|
mutex_init(&data->update_lock);
|
||||||
|
|
||||||
/* Tell the I2C layer a new client has arrived */
|
/* Tell the I2C layer a new client has arrived */
|
||||||
if ((err = i2c_attach_client(new_client)))
|
if ((err = i2c_attach_client(client)))
|
||||||
goto ERROR1;
|
goto ERROR1;
|
||||||
|
|
||||||
/* Attach secondary lm75 clients */
|
/* Attach secondary lm75 clients */
|
||||||
if ((err = asb100_detect_subclients(adapter, address, kind,
|
if ((err = asb100_detect_subclients(adapter, address, kind,
|
||||||
new_client)))
|
client)))
|
||||||
goto ERROR2;
|
goto ERROR2;
|
||||||
|
|
||||||
/* Initialize the chip */
|
/* Initialize the chip */
|
||||||
asb100_init_client(new_client);
|
asb100_init_client(client);
|
||||||
|
|
||||||
/* A few vars need to be filled upon startup */
|
/* A few vars need to be filled upon startup */
|
||||||
data->fan_min[0] = asb100_read_value(new_client, ASB100_REG_FAN_MIN(0));
|
data->fan_min[0] = asb100_read_value(client, ASB100_REG_FAN_MIN(0));
|
||||||
data->fan_min[1] = asb100_read_value(new_client, ASB100_REG_FAN_MIN(1));
|
data->fan_min[1] = asb100_read_value(client, ASB100_REG_FAN_MIN(1));
|
||||||
data->fan_min[2] = asb100_read_value(new_client, ASB100_REG_FAN_MIN(2));
|
data->fan_min[2] = asb100_read_value(client, ASB100_REG_FAN_MIN(2));
|
||||||
|
|
||||||
/* Register sysfs hooks */
|
/* Register sysfs hooks */
|
||||||
if ((err = sysfs_create_group(&new_client->dev.kobj, &asb100_group)))
|
if ((err = sysfs_create_group(&client->dev.kobj, &asb100_group)))
|
||||||
goto ERROR3;
|
goto ERROR3;
|
||||||
|
|
||||||
data->hwmon_dev = hwmon_device_register(&new_client->dev);
|
data->hwmon_dev = hwmon_device_register(&client->dev);
|
||||||
if (IS_ERR(data->hwmon_dev)) {
|
if (IS_ERR(data->hwmon_dev)) {
|
||||||
err = PTR_ERR(data->hwmon_dev);
|
err = PTR_ERR(data->hwmon_dev);
|
||||||
goto ERROR4;
|
goto ERROR4;
|
||||||
@@ -850,14 +847,14 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ERROR4:
|
ERROR4:
|
||||||
sysfs_remove_group(&new_client->dev.kobj, &asb100_group);
|
sysfs_remove_group(&client->dev.kobj, &asb100_group);
|
||||||
ERROR3:
|
ERROR3:
|
||||||
i2c_detach_client(data->lm75[1]);
|
i2c_detach_client(data->lm75[1]);
|
||||||
i2c_detach_client(data->lm75[0]);
|
i2c_detach_client(data->lm75[0]);
|
||||||
kfree(data->lm75[1]);
|
kfree(data->lm75[1]);
|
||||||
kfree(data->lm75[0]);
|
kfree(data->lm75[0]);
|
||||||
ERROR2:
|
ERROR2:
|
||||||
i2c_detach_client(new_client);
|
i2c_detach_client(client);
|
||||||
ERROR1:
|
ERROR1:
|
||||||
kfree(data);
|
kfree(data);
|
||||||
ERROR0:
|
ERROR0:
|
||||||
@@ -1075,4 +1072,3 @@ MODULE_LICENSE("GPL");
|
|||||||
|
|
||||||
module_init(asb100_init);
|
module_init(asb100_init);
|
||||||
module_exit(asb100_exit);
|
module_exit(asb100_exit);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user