diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2014-08-06 02:55:36 +0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-08-06 02:55:36 +0400 |
commit | 161d2e0a195292a8a67b0f5c48e12a9984f75dac (patch) | |
tree | 4f3c516ab41737b1e51a58ca3d5f8cca421ae949 /drivers/hwmon/w83l786ng.c | |
parent | c489d98c8c81a898cfed6bec193cca2006f956aa (diff) | |
parent | fce9626cd93abaf1ef21b361f8a0fa493cc855b2 (diff) | |
download | linux-161d2e0a195292a8a67b0f5c48e12a9984f75dac.tar.xz |
Merge tag 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging
Pull hwmon updates from Guenter Roeck:
"Notable changes:
- Heiko Schocher provided a driver for TI TMP103.
- Kamil Debski provided a driver for pwm-controlled fans.
- Neelesh Gupta provided a driver for power, fan rpm, voltage and
temperature reporting on powerpc/powernv systems.
- Scott Kanowitz provided a driver supporting Lattice's POWR1220
power manager IC.
- Richard Zhu provided a pmbus front-end driver for TPS40422.
- Frans Klaver added support for TMP112 to the lm75 driver.
- Johannes Pointner added support for EPCOS B57330V2103 to the
ntc_thermistor driver.
- Guenter Roeck added support for TMP441 and TMP442 to the tmp421
driver.
- Axel Lin converted several drivers to the new hwmon API (36 of
them, if I counted correctly), and cleaned up many of the drivers
along the way.
There are also a number of patches fixing bugs discovered while
testing Axel's changes"
* tag 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging: (88 commits)
hwmon: (g762) Use of_property_read_u32 at appropriate place
hwmon: (sis5595) Prevent overflow problem when writing large limits
hwmon: (gpio-fan) Prevent overflow problem when writing large limits
hwmon: (ibmpowernv) Use of_property_read_u32 at appropriate place
hwmon: (lm85) Convert to devm_hwmon_device_register_with_groups
hwmon: (lm85) Avoid forward declaration
hwmon: (lm78) Convert to devm_hwmon_device_register_with_groups
hwmon: (max6697) Use of_property_read_bool at appropriate places
hwmon: (pwm-fan) Make SENSORS_PWM_FAN depend on OF
hwmon: (pwm-fan) Remove duplicate dev_set_drvdata call
hwmon: (nct6775) Remove num_attr_groups from struct nct6775_data
hwmon: (nct6775) Update module description and Kconfig for NCT6106D and NCT6791D
hwmon: (adt7411) Convert to devm_hwmon_device_register_with_groups
hwmon: (g762) Convert to hwmon_device_register_with_groups
hwmon: (emc2103) Convert to devm_hwmon_device_register_with_groups
hwmon: (smsc47m1) Avoid forward declaration
hwmon: (smsc47m192) Convert to devm_hwmon_device_register_with_groups
hwmon: (smsc47m192) Avoid forward declaration
hwmon: (max1668) Make max1668_addr_list array const
hwmon: (max6639) Make normal_i2c array const
...
Diffstat (limited to 'drivers/hwmon/w83l786ng.c')
-rw-r--r-- | drivers/hwmon/w83l786ng.c | 289 |
1 files changed, 126 insertions, 163 deletions
diff --git a/drivers/hwmon/w83l786ng.c b/drivers/hwmon/w83l786ng.c index 32487c19cbfc..330299613d38 100644 --- a/drivers/hwmon/w83l786ng.c +++ b/drivers/hwmon/w83l786ng.c @@ -124,7 +124,7 @@ DIV_TO_REG(long val) } struct w83l786ng_data { - struct device *hwmon_dev; + struct i2c_client *client; struct mutex update_lock; char valid; /* !=0 if following fields are valid */ unsigned long last_updated; /* In jiffies */ @@ -148,32 +148,6 @@ struct w83l786ng_data { u8 tolerance[2]; }; -static int w83l786ng_probe(struct i2c_client *client, - const struct i2c_device_id *id); -static int w83l786ng_detect(struct i2c_client *client, - struct i2c_board_info *info); -static int w83l786ng_remove(struct i2c_client *client); -static void w83l786ng_init_client(struct i2c_client *client); -static struct w83l786ng_data *w83l786ng_update_device(struct device *dev); - -static const struct i2c_device_id w83l786ng_id[] = { - { "w83l786ng", 0 }, - { } -}; -MODULE_DEVICE_TABLE(i2c, w83l786ng_id); - -static struct i2c_driver w83l786ng_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "w83l786ng", - }, - .probe = w83l786ng_probe, - .remove = w83l786ng_remove, - .id_table = w83l786ng_id, - .detect = w83l786ng_detect, - .address_list = normal_i2c, -}; - static u8 w83l786ng_read_value(struct i2c_client *client, u8 reg) { @@ -186,6 +160,77 @@ w83l786ng_write_value(struct i2c_client *client, u8 reg, u8 value) return i2c_smbus_write_byte_data(client, reg, value); } +static struct w83l786ng_data *w83l786ng_update_device(struct device *dev) +{ + struct w83l786ng_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; + int i, j; + u8 reg_tmp, pwmcfg; + + mutex_lock(&data->update_lock); + if (time_after(jiffies, data->last_updated + HZ + HZ / 2) + || !data->valid) { + dev_dbg(&client->dev, "Updating w83l786ng data.\n"); + + /* Update the voltages measured value and limits */ + for (i = 0; i < 3; i++) { + data->in[i] = w83l786ng_read_value(client, + W83L786NG_REG_IN(i)); + data->in_min[i] = w83l786ng_read_value(client, + W83L786NG_REG_IN_MIN(i)); + data->in_max[i] = w83l786ng_read_value(client, + W83L786NG_REG_IN_MAX(i)); + } + + /* Update the fan counts and limits */ + for (i = 0; i < 2; i++) { + data->fan[i] = w83l786ng_read_value(client, + W83L786NG_REG_FAN(i)); + data->fan_min[i] = w83l786ng_read_value(client, + W83L786NG_REG_FAN_MIN(i)); + } + + /* Update the fan divisor */ + reg_tmp = w83l786ng_read_value(client, W83L786NG_REG_FAN_DIV); + data->fan_div[0] = reg_tmp & 0x07; + data->fan_div[1] = (reg_tmp >> 4) & 0x07; + + pwmcfg = w83l786ng_read_value(client, W83L786NG_REG_FAN_CFG); + for (i = 0; i < 2; i++) { + data->pwm_mode[i] = + ((pwmcfg >> W83L786NG_PWM_MODE_SHIFT[i]) & 1) + ? 0 : 1; + data->pwm_enable[i] = + ((pwmcfg >> W83L786NG_PWM_ENABLE_SHIFT[i]) & 3) + 1; + data->pwm[i] = + (w83l786ng_read_value(client, W83L786NG_REG_PWM[i]) + & 0x0f) * 0x11; + } + + + /* Update the temperature sensors */ + for (i = 0; i < 2; i++) { + for (j = 0; j < 3; j++) { + data->temp[i][j] = w83l786ng_read_value(client, + W83L786NG_REG_TEMP[i][j]); + } + } + + /* Update Smart Fan I/II tolerance */ + reg_tmp = w83l786ng_read_value(client, W83L786NG_REG_TOLERANCE); + data->tolerance[0] = reg_tmp & 0x0f; + data->tolerance[1] = (reg_tmp >> 4) & 0x0f; + + data->last_updated = jiffies; + data->valid = 1; + + } + + mutex_unlock(&data->update_lock); + + return data; +} + /* following are the sysfs callback functions */ #define show_in_reg(reg) \ static ssize_t \ @@ -207,8 +252,8 @@ store_in_##reg(struct device *dev, struct device_attribute *attr, \ const char *buf, size_t count) \ { \ int nr = to_sensor_dev_attr(attr)->index; \ - struct i2c_client *client = to_i2c_client(dev); \ - struct w83l786ng_data *data = i2c_get_clientdata(client); \ + struct w83l786ng_data *data = dev_get_drvdata(dev); \ + struct i2c_client *client = data->client; \ unsigned long val; \ int err = kstrtoul(buf, 10, &val); \ if (err) \ @@ -260,8 +305,8 @@ store_fan_min(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { int nr = to_sensor_dev_attr(attr)->index; - struct i2c_client *client = to_i2c_client(dev); - struct w83l786ng_data *data = i2c_get_clientdata(client); + struct w83l786ng_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; unsigned long val; int err; @@ -298,8 +343,8 @@ store_fan_div(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { int nr = to_sensor_dev_attr(attr)->index; - struct i2c_client *client = to_i2c_client(dev); - struct w83l786ng_data *data = i2c_get_clientdata(client); + struct w83l786ng_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; unsigned long min; u8 tmp_fan_div; @@ -389,8 +434,8 @@ store_temp(struct device *dev, struct device_attribute *attr, to_sensor_dev_attr_2(attr); int nr = sensor_attr->nr; int index = sensor_attr->index; - struct i2c_client *client = to_i2c_client(dev); - struct w83l786ng_data *data = i2c_get_clientdata(client); + struct w83l786ng_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; long val; int err; @@ -444,8 +489,8 @@ store_pwm_mode(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { int nr = to_sensor_dev_attr(attr)->index; - struct i2c_client *client = to_i2c_client(dev); - struct w83l786ng_data *data = i2c_get_clientdata(client); + struct w83l786ng_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; u8 reg; unsigned long val; int err; @@ -472,8 +517,8 @@ store_pwm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { int nr = to_sensor_dev_attr(attr)->index; - struct i2c_client *client = to_i2c_client(dev); - struct w83l786ng_data *data = i2c_get_clientdata(client); + struct w83l786ng_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; unsigned long val; int err; @@ -496,8 +541,8 @@ store_pwm_enable(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { int nr = to_sensor_dev_attr(attr)->index; - struct i2c_client *client = to_i2c_client(dev); - struct w83l786ng_data *data = i2c_get_clientdata(client); + struct w83l786ng_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; u8 reg; unsigned long val; int err; @@ -552,8 +597,8 @@ store_tolerance(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { int nr = to_sensor_dev_attr(attr)->index; - struct i2c_client *client = to_i2c_client(dev); - struct w83l786ng_data *data = i2c_get_clientdata(client); + struct w83l786ng_data *data = dev_get_drvdata(dev); + struct i2c_client *client = data->client; u8 tol_tmp, tol_mask; unsigned long val; int err; @@ -608,7 +653,7 @@ static struct sensor_device_attribute sda_tolerance[] = { #define TOLERANCE_UNIT_ATTRS(X) \ &sda_tolerance[X].dev_attr.attr -static struct attribute *w83l786ng_attributes[] = { +static struct attribute *w83l786ng_attrs[] = { IN_UNIT_ATTRS(0), IN_UNIT_ATTRS(1), IN_UNIT_ATTRS(2), @@ -623,9 +668,7 @@ static struct attribute *w83l786ng_attributes[] = { NULL }; -static const struct attribute_group w83l786ng_group = { - .attrs = w83l786ng_attributes, -}; +ATTRIBUTE_GROUPS(w83l786ng); static int w83l786ng_detect(struct i2c_client *client, struct i2c_board_info *info) @@ -662,20 +705,33 @@ w83l786ng_detect(struct i2c_client *client, struct i2c_board_info *info) return 0; } +static void w83l786ng_init_client(struct i2c_client *client) +{ + u8 tmp; + + if (reset) + w83l786ng_write_value(client, W83L786NG_REG_CONFIG, 0x80); + + /* Start monitoring */ + tmp = w83l786ng_read_value(client, W83L786NG_REG_CONFIG); + if (!(tmp & 0x01)) + w83l786ng_write_value(client, W83L786NG_REG_CONFIG, tmp | 0x01); +} + static int w83l786ng_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct device *dev = &client->dev; struct w83l786ng_data *data; - int i, err = 0; + struct device *hwmon_dev; + int i; u8 reg_tmp; - data = devm_kzalloc(&client->dev, sizeof(struct w83l786ng_data), - GFP_KERNEL); + data = devm_kzalloc(dev, sizeof(struct w83l786ng_data), GFP_KERNEL); if (!data) return -ENOMEM; - i2c_set_clientdata(client, data); + data->client = client; mutex_init(&data->update_lock); /* Initialize the chip */ @@ -692,121 +748,28 @@ w83l786ng_probe(struct i2c_client *client, const struct i2c_device_id *id) data->fan_div[0] = reg_tmp & 0x07; data->fan_div[1] = (reg_tmp >> 4) & 0x07; - /* Register sysfs hooks */ - err = sysfs_create_group(&client->dev.kobj, &w83l786ng_group); - if (err) - goto exit_remove; - - data->hwmon_dev = hwmon_device_register(dev); - if (IS_ERR(data->hwmon_dev)) { - err = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - return 0; - - /* Unregister sysfs hooks */ - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &w83l786ng_group); - return err; -} - -static int -w83l786ng_remove(struct i2c_client *client) -{ - struct w83l786ng_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &w83l786ng_group); - - return 0; + hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, + data, + w83l786ng_groups); + return PTR_ERR_OR_ZERO(hwmon_dev); } -static void -w83l786ng_init_client(struct i2c_client *client) -{ - u8 tmp; - - if (reset) - w83l786ng_write_value(client, W83L786NG_REG_CONFIG, 0x80); - - /* Start monitoring */ - tmp = w83l786ng_read_value(client, W83L786NG_REG_CONFIG); - if (!(tmp & 0x01)) - w83l786ng_write_value(client, W83L786NG_REG_CONFIG, tmp | 0x01); -} - -static struct w83l786ng_data *w83l786ng_update_device(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct w83l786ng_data *data = i2c_get_clientdata(client); - int i, j; - u8 reg_tmp, pwmcfg; - - mutex_lock(&data->update_lock); - if (time_after(jiffies, data->last_updated + HZ + HZ / 2) - || !data->valid) { - dev_dbg(&client->dev, "Updating w83l786ng data.\n"); - - /* Update the voltages measured value and limits */ - for (i = 0; i < 3; i++) { - data->in[i] = w83l786ng_read_value(client, - W83L786NG_REG_IN(i)); - data->in_min[i] = w83l786ng_read_value(client, - W83L786NG_REG_IN_MIN(i)); - data->in_max[i] = w83l786ng_read_value(client, - W83L786NG_REG_IN_MAX(i)); - } - - /* Update the fan counts and limits */ - for (i = 0; i < 2; i++) { - data->fan[i] = w83l786ng_read_value(client, - W83L786NG_REG_FAN(i)); - data->fan_min[i] = w83l786ng_read_value(client, - W83L786NG_REG_FAN_MIN(i)); - } - - /* Update the fan divisor */ - reg_tmp = w83l786ng_read_value(client, W83L786NG_REG_FAN_DIV); - data->fan_div[0] = reg_tmp & 0x07; - data->fan_div[1] = (reg_tmp >> 4) & 0x07; - - pwmcfg = w83l786ng_read_value(client, W83L786NG_REG_FAN_CFG); - for (i = 0; i < 2; i++) { - data->pwm_mode[i] = - ((pwmcfg >> W83L786NG_PWM_MODE_SHIFT[i]) & 1) - ? 0 : 1; - data->pwm_enable[i] = - ((pwmcfg >> W83L786NG_PWM_ENABLE_SHIFT[i]) & 3) + 1; - data->pwm[i] = - (w83l786ng_read_value(client, W83L786NG_REG_PWM[i]) - & 0x0f) * 0x11; - } - - - /* Update the temperature sensors */ - for (i = 0; i < 2; i++) { - for (j = 0; j < 3; j++) { - data->temp[i][j] = w83l786ng_read_value(client, - W83L786NG_REG_TEMP[i][j]); - } - } - - /* Update Smart Fan I/II tolerance */ - reg_tmp = w83l786ng_read_value(client, W83L786NG_REG_TOLERANCE); - data->tolerance[0] = reg_tmp & 0x0f; - data->tolerance[1] = (reg_tmp >> 4) & 0x0f; - - data->last_updated = jiffies; - data->valid = 1; - - } - - mutex_unlock(&data->update_lock); +static const struct i2c_device_id w83l786ng_id[] = { + { "w83l786ng", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, w83l786ng_id); - return data; -} +static struct i2c_driver w83l786ng_driver = { + .class = I2C_CLASS_HWMON, + .driver = { + .name = "w83l786ng", + }, + .probe = w83l786ng_probe, + .id_table = w83l786ng_id, + .detect = w83l786ng_detect, + .address_list = normal_i2c, +}; module_i2c_driver(w83l786ng_driver); |