diff options
Diffstat (limited to 'drivers/hwmon/adt7411.c')
| -rw-r--r-- | drivers/hwmon/adt7411.c | 126 |
1 files changed, 38 insertions, 88 deletions
diff --git a/drivers/hwmon/adt7411.c b/drivers/hwmon/adt7411.c index b939f8a115ba..b9991a69e6c6 100644 --- a/drivers/hwmon/adt7411.c +++ b/drivers/hwmon/adt7411.c @@ -1,12 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0-only /* * Driver for the ADT7411 (I2C/SPI 8 channel 10 bit ADC & temperature-sensor) * * Copyright (C) 2008, 2010 Pengutronix * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * * TODO: SPI, use power-down mode for suspend?, interrupt handling? */ @@ -14,7 +11,6 @@ #include <linux/module.h> #include <linux/init.h> #include <linux/err.h> -#include <linux/mutex.h> #include <linux/jiffies.h> #include <linux/i2c.h> #include <linux/hwmon.h> @@ -102,8 +98,6 @@ static const u8 adt7411_in_alarm_bits[] = { }; struct adt7411_data { - struct mutex device_lock; /* for "atomic" device accesses */ - struct mutex update_lock; unsigned long next_update; long vref_cached; struct i2c_client *client; @@ -113,55 +107,41 @@ struct adt7411_data { /* * When reading a register containing (up to 4) lsb, all associated * msb-registers get locked by the hardware. After _one_ of those msb is read, - * _all_ are unlocked. In order to use this locking correctly, reading lsb/msb - * is protected here with a mutex, too. + * _all_ are unlocked. */ static int adt7411_read_10_bit(struct i2c_client *client, u8 lsb_reg, - u8 msb_reg, u8 lsb_shift) + u8 msb_reg, u8 lsb_shift) { - struct adt7411_data *data = i2c_get_clientdata(client); int val, tmp; - mutex_lock(&data->device_lock); - val = i2c_smbus_read_byte_data(client, lsb_reg); if (val < 0) - goto exit_unlock; + return val; tmp = (val >> lsb_shift) & 3; val = i2c_smbus_read_byte_data(client, msb_reg); + if (val < 0) + return val; - if (val >= 0) - val = (val << 2) | tmp; - - exit_unlock: - mutex_unlock(&data->device_lock); - + val = (val << 2) | tmp; return val; } static int adt7411_modify_bit(struct i2c_client *client, u8 reg, u8 bit, - bool flag) + bool flag) { - struct adt7411_data *data = i2c_get_clientdata(client); int ret, val; - mutex_lock(&data->device_lock); - ret = i2c_smbus_read_byte_data(client, reg); if (ret < 0) - goto exit_unlock; + return ret; if (flag) val = ret | bit; else val = ret & ~bit; - ret = i2c_smbus_write_byte_data(client, reg, val); - - exit_unlock: - mutex_unlock(&data->device_lock); - return ret; + return i2c_smbus_write_byte_data(client, reg, val); } static ssize_t adt7411_show_bit(struct device *dev, @@ -189,12 +169,11 @@ static ssize_t adt7411_set_bit(struct device *dev, if (ret || flag > 1) return -EINVAL; + hwmon_lock(dev); ret = adt7411_modify_bit(client, s_attr2->index, s_attr2->nr, flag); - /* force update */ - mutex_lock(&data->update_lock); data->next_update = jiffies; - mutex_unlock(&data->update_lock); + hwmon_unlock(dev); return ret < 0 ? ret : count; } @@ -297,10 +276,9 @@ static int adt7411_read_in_chan(struct device *dev, u32 attr, int channel, int reg, lsb_reg, lsb_shift; int nr = channel - 1; - mutex_lock(&data->update_lock); ret = adt7411_update_vref(dev); if (ret < 0) - goto exit_unlock; + return ret; switch (attr) { case hwmon_in_input: @@ -310,7 +288,7 @@ static int adt7411_read_in_chan(struct device *dev, u32 attr, int channel, ADT7411_REG_EXT_TEMP_AIN1_MSB + nr, lsb_shift); if (ret < 0) - goto exit_unlock; + return ret; *val = ret * data->vref_cached / 1024; ret = 0; break; @@ -321,7 +299,7 @@ static int adt7411_read_in_chan(struct device *dev, u32 attr, int channel, : ADT7411_REG_IN_HIGH(channel); ret = i2c_smbus_read_byte_data(client, reg); if (ret < 0) - goto exit_unlock; + return ret; *val = ret * data->vref_cached / 256; ret = 0; break; @@ -332,8 +310,6 @@ static int adt7411_read_in_chan(struct device *dev, u32 attr, int channel, ret = -EOPNOTSUPP; break; } - exit_unlock: - mutex_unlock(&data->update_lock); return ret; } @@ -460,10 +436,9 @@ static int adt7411_write_in_chan(struct device *dev, u32 attr, int channel, struct i2c_client *client = data->client; int ret, reg; - mutex_lock(&data->update_lock); ret = adt7411_update_vref(dev); if (ret < 0) - goto exit_unlock; + return ret; val = clamp_val(val, 0, 255 * data->vref_cached / 256); val = DIV_ROUND_CLOSEST(val * 256, data->vref_cached); @@ -475,13 +450,10 @@ static int adt7411_write_in_chan(struct device *dev, u32 attr, int channel, reg = ADT7411_REG_IN_HIGH(channel); break; default: - ret = -EOPNOTSUPP; - goto exit_unlock; + return -EOPNOTSUPP; } ret = i2c_smbus_write_byte_data(client, reg, val); - exit_unlock: - mutex_unlock(&data->update_lock); return ret; } @@ -593,7 +565,7 @@ static int adt7411_detect(struct i2c_client *client, return -ENODEV; } - strlcpy(info->type, "adt7411", I2C_NAME_SIZE); + strscpy(info->type, "adt7411", I2C_NAME_SIZE); return 0; } @@ -639,40 +611,22 @@ static int adt7411_init_device(struct adt7411_data *data) return i2c_smbus_write_byte_data(data->client, ADT7411_REG_CFG1, val); } -static const u32 adt7411_in_config[] = { - HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, - HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, - HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, - HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, - HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, - HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, - HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, - HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, - HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, - 0 -}; - -static const struct hwmon_channel_info adt7411_in = { - .type = hwmon_in, - .config = adt7411_in_config, -}; - -static const u32 adt7411_temp_config[] = { - HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MIN_ALARM | - HWMON_T_MAX | HWMON_T_MAX_ALARM, - HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MIN_ALARM | - HWMON_T_MAX | HWMON_T_MAX_ALARM | HWMON_T_FAULT, - 0 -}; - -static const struct hwmon_channel_info adt7411_temp = { - .type = hwmon_temp, - .config = adt7411_temp_config, -}; - -static const struct hwmon_channel_info *adt7411_info[] = { - &adt7411_in, - &adt7411_temp, +static const struct hwmon_channel_info * const adt7411_info[] = { + HWMON_CHANNEL_INFO(in, + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM, + HWMON_I_INPUT | HWMON_I_MIN | HWMON_I_MAX | HWMON_I_ALARM), + HWMON_CHANNEL_INFO(temp, + HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MIN_ALARM | + HWMON_T_MAX | HWMON_T_MAX_ALARM, + HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MIN_ALARM | + HWMON_T_MAX | HWMON_T_MAX_ALARM | HWMON_T_FAULT), NULL }; @@ -687,8 +641,7 @@ static const struct hwmon_chip_info adt7411_chip_info = { .info = adt7411_info, }; -static int adt7411_probe(struct i2c_client *client, - const struct i2c_device_id *id) +static int adt7411_probe(struct i2c_client *client) { struct device *dev = &client->dev; struct adt7411_data *data; @@ -701,8 +654,6 @@ static int adt7411_probe(struct i2c_client *client, i2c_set_clientdata(client, data); data->client = client; - mutex_init(&data->device_lock); - mutex_init(&data->update_lock); ret = adt7411_init_device(data); if (ret < 0) @@ -719,7 +670,7 @@ static int adt7411_probe(struct i2c_client *client, } static const struct i2c_device_id adt7411_id[] = { - { "adt7411", 0 }, + { "adt7411" }, { } }; MODULE_DEVICE_TABLE(i2c, adt7411_id); @@ -728,7 +679,7 @@ static struct i2c_driver adt7411_driver = { .driver = { .name = "adt7411", }, - .probe = adt7411_probe, + .probe = adt7411_probe, .id_table = adt7411_id, .detect = adt7411_detect, .address_list = normal_i2c, @@ -737,7 +688,6 @@ static struct i2c_driver adt7411_driver = { module_i2c_driver(adt7411_driver); -MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de> and " - "Wolfram Sang <w.sang@pengutronix.de>"); +MODULE_AUTHOR("Sascha Hauer, Wolfram Sang <kernel@pengutronix.de>"); MODULE_DESCRIPTION("ADT7411 driver"); MODULE_LICENSE("GPL v2"); |
