X-Git-Url: http://ftp.safe.ca/?a=blobdiff_plain;f=drivers%2Fhwmon%2Flm80.c;h=f72120d08c4ced3f377181a9a5b020f3d9353255;hb=170a34605c14a90df5f4a78e0b4ca643be6ef8ba;hp=dbf8df3862503e9093e3c5e69863279851aca333;hpb=943b0830cebe4711354945ed3cb44e84152aaca0;p=safe%2Fjmp%2Flinux-2.6 diff --git a/drivers/hwmon/lm80.c b/drivers/hwmon/lm80.c index dbf8df3..f72120d 100644 --- a/drivers/hwmon/lm80.c +++ b/drivers/hwmon/lm80.c @@ -26,17 +26,16 @@ #include #include #include -#include #include #include +#include /* Addresses to scan */ static unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END }; -static unsigned int normal_isa[] = { I2C_CLIENT_ISA_END }; /* Insmod parameters */ -SENSORS_INSMOD_1(lm80); +I2C_CLIENT_INSMOD_1(lm80); /* Many LM80 constants specified below */ @@ -110,7 +109,7 @@ static inline long TEMP_FROM_REG(u16 temp) struct lm80_data { struct i2c_client client; struct class_device *class_dev; - struct semaphore update_lock; + struct mutex update_lock; char valid; /* !=0 if following fields are valid */ unsigned long last_updated; /* In jiffies */ @@ -145,10 +144,10 @@ static int lm80_write_value(struct i2c_client *client, u8 reg, u8 value); */ static struct i2c_driver lm80_driver = { - .owner = THIS_MODULE, - .name = "lm80", + .driver = { + .name = "lm80", + }, .id = I2C_DRIVERID_LM80, - .flags = I2C_DF_NOTIFY, .attach_adapter = lm80_attach_adapter, .detach_client = lm80_detach_client, }; @@ -193,10 +192,10 @@ static ssize_t set_in_##suffix(struct device *dev, struct device_attribute *attr struct lm80_data *data = i2c_get_clientdata(client); \ long val = simple_strtol(buf, NULL, 10); \ \ - down(&data->update_lock);\ + mutex_lock(&data->update_lock);\ data->value = IN_TO_REG(val); \ lm80_write_value(client, reg, data->value); \ - up(&data->update_lock);\ + mutex_unlock(&data->update_lock);\ return count; \ } set_in(min0, in_min[0], LM80_REG_IN_MIN(0)); @@ -243,10 +242,10 @@ static ssize_t set_fan_##suffix(struct device *dev, struct device_attribute *att struct lm80_data *data = i2c_get_clientdata(client); \ long val = simple_strtoul(buf, NULL, 10); \ \ - down(&data->update_lock);\ + mutex_lock(&data->update_lock);\ data->value = FAN_TO_REG(val, DIV_FROM_REG(data->div)); \ lm80_write_value(client, reg, data->value); \ - up(&data->update_lock);\ + mutex_unlock(&data->update_lock);\ return count; \ } set_fan(min1, fan_min[0], LM80_REG_FAN_MIN(1), fan_div[0]); @@ -265,7 +264,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, u8 reg; /* Save fan_min */ - down(&data->update_lock); + mutex_lock(&data->update_lock); min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])); @@ -277,7 +276,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, default: dev_err(&client->dev, "fan_div value %ld not " "supported. Choose one of 1, 2, 4 or 8!\n", val); - up(&data->update_lock); + mutex_unlock(&data->update_lock); return -EINVAL; } @@ -288,7 +287,7 @@ static ssize_t set_fan_div(struct device *dev, const char *buf, /* Restore fan_min */ data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); lm80_write_value(client, LM80_REG_FAN_MIN(nr + 1), data->fan_min[nr]); - up(&data->update_lock); + mutex_unlock(&data->update_lock); return count; } @@ -327,10 +326,10 @@ static ssize_t set_temp_##suffix(struct device *dev, struct device_attribute *at struct lm80_data *data = i2c_get_clientdata(client); \ long val = simple_strtoul(buf, NULL, 10); \ \ - down(&data->update_lock); \ + mutex_lock(&data->update_lock); \ data->value = TEMP_LIMIT_TO_REG(val); \ lm80_write_value(client, reg, data->value); \ - up(&data->update_lock); \ + mutex_unlock(&data->update_lock); \ return count; \ } set_temp(hot_max, temp_hot_max, LM80_REG_TEMP_HOT_MAX); @@ -392,10 +391,10 @@ static int lm80_attach_adapter(struct i2c_adapter *adapter) { if (!(adapter->class & I2C_CLASS_HWMON)) return 0; - return i2c_detect(adapter, &addr_data, lm80_detect); + return i2c_probe(adapter, &addr_data, lm80_detect); } -int lm80_detect(struct i2c_adapter *adapter, int address, int kind) +static int lm80_detect(struct i2c_adapter *adapter, int address, int kind) { int i, cur; struct i2c_client *new_client; @@ -409,11 +408,10 @@ int lm80_detect(struct i2c_adapter *adapter, int address, int kind) /* OK. For now, we presume we have a valid client. We now create the client structure, even though we cannot fill it completely yet. But it allows us to access lm80_{read,write}_value. */ - if (!(data = kmalloc(sizeof(struct lm80_data), GFP_KERNEL))) { + if (!(data = kzalloc(sizeof(struct lm80_data), GFP_KERNEL))) { err = -ENOMEM; goto exit; } - memset(data, 0, sizeof(struct lm80_data)); new_client = &data->client; i2c_set_clientdata(new_client, data); @@ -440,7 +438,7 @@ int lm80_detect(struct i2c_adapter *adapter, int address, int kind) /* Fill in the remaining client fields and put it into the global list */ strlcpy(new_client->name, name, I2C_NAME_SIZE); data->valid = 0; - init_MUTEX(&data->update_lock); + mutex_init(&data->update_lock); /* Tell the I2C layer a new client has arrived */ if ((err = i2c_attach_client(new_client))) @@ -511,11 +509,8 @@ static int lm80_detach_client(struct i2c_client *client) hwmon_device_unregister(data->class_dev); - if ((err = i2c_detach_client(client))) { - dev_err(&client->dev, "Client deregistration failed, " - "client not detached.\n"); + if ((err = i2c_detach_client(client))) return err; - } kfree(data); return 0; @@ -551,7 +546,7 @@ static struct lm80_data *lm80_update_device(struct device *dev) struct lm80_data *data = i2c_get_clientdata(client); int i; - down(&data->update_lock); + mutex_lock(&data->update_lock); if (time_after(jiffies, data->last_updated + 2 * HZ) || !data->valid) { dev_dbg(&client->dev, "Starting lm80 update\n"); @@ -591,7 +586,7 @@ static struct lm80_data *lm80_update_device(struct device *dev) data->valid = 1; } - up(&data->update_lock); + mutex_unlock(&data->update_lock); return data; }