mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-03 00:54:09 +08:00
hwmon: (max6639) Use multi-byte regmap operations
Use multi-byte regmap operations where possible to reduce code size and the need for mutex protection. No functional changes. Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
This commit is contained in:
parent
ad231314b6
commit
21a93a9e31
@ -88,25 +88,16 @@ struct max6639_data {
|
|||||||
|
|
||||||
static int max6639_temp_read_input(struct device *dev, int channel, long *temp)
|
static int max6639_temp_read_input(struct device *dev, int channel, long *temp)
|
||||||
{
|
{
|
||||||
|
u32 regs[2] = { MAX6639_REG_TEMP_EXT(channel), MAX6639_REG_TEMP(channel) };
|
||||||
struct max6639_data *data = dev_get_drvdata(dev);
|
struct max6639_data *data = dev_get_drvdata(dev);
|
||||||
unsigned int val;
|
u8 regvals[2];
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
/*
|
res = regmap_multi_reg_read(data->regmap, regs, regvals, 2);
|
||||||
* Lock isn't needed as MAX6639_REG_TEMP wpnt change for at least 250ms after reading
|
|
||||||
* MAX6639_REG_TEMP_EXT
|
|
||||||
*/
|
|
||||||
res = regmap_read(data->regmap, MAX6639_REG_TEMP_EXT(channel), &val);
|
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
*temp = val >> 5;
|
*temp = ((regvals[0] >> 5) | (regvals[1] << 3)) * 125;
|
||||||
res = regmap_read(data->regmap, MAX6639_REG_TEMP(channel), &val);
|
|
||||||
if (res < 0)
|
|
||||||
return res;
|
|
||||||
|
|
||||||
*temp |= val << 3;
|
|
||||||
*temp *= 125;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -290,8 +281,10 @@ static umode_t max6639_fan_is_visible(const void *_data, u32 attr, int channel)
|
|||||||
static int max6639_read_pwm(struct device *dev, u32 attr, int channel,
|
static int max6639_read_pwm(struct device *dev, u32 attr, int channel,
|
||||||
long *pwm_val)
|
long *pwm_val)
|
||||||
{
|
{
|
||||||
|
u32 regs[2] = { MAX6639_REG_FAN_CONFIG3(channel), MAX6639_REG_GCONFIG };
|
||||||
struct max6639_data *data = dev_get_drvdata(dev);
|
struct max6639_data *data = dev_get_drvdata(dev);
|
||||||
unsigned int val;
|
unsigned int val;
|
||||||
|
u8 regvals[2];
|
||||||
int res;
|
int res;
|
||||||
u8 i;
|
u8 i;
|
||||||
|
|
||||||
@ -303,26 +296,13 @@ static int max6639_read_pwm(struct device *dev, u32 attr, int channel,
|
|||||||
*pwm_val = val * 255 / 120;
|
*pwm_val = val * 255 / 120;
|
||||||
return 0;
|
return 0;
|
||||||
case hwmon_pwm_freq:
|
case hwmon_pwm_freq:
|
||||||
mutex_lock(&data->update_lock);
|
res = regmap_multi_reg_read(data->regmap, regs, regvals, 2);
|
||||||
res = regmap_read(data->regmap, MAX6639_REG_FAN_CONFIG3(channel), &val);
|
if (res < 0)
|
||||||
if (res < 0) {
|
|
||||||
mutex_unlock(&data->update_lock);
|
|
||||||
return res;
|
return res;
|
||||||
}
|
i = regvals[0] & MAX6639_FAN_CONFIG3_FREQ_MASK;
|
||||||
i = val & MAX6639_FAN_CONFIG3_FREQ_MASK;
|
if (regvals[1] & MAX6639_GCONFIG_PWM_FREQ_HI)
|
||||||
|
|
||||||
res = regmap_read(data->regmap, MAX6639_REG_GCONFIG, &val);
|
|
||||||
if (res < 0) {
|
|
||||||
mutex_unlock(&data->update_lock);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (val & MAX6639_GCONFIG_PWM_FREQ_HI)
|
|
||||||
i |= 0x4;
|
i |= 0x4;
|
||||||
i &= 0x7;
|
|
||||||
*pwm_val = freq_table[i];
|
*pwm_val = freq_table[i];
|
||||||
|
|
||||||
mutex_unlock(&data->update_lock);
|
|
||||||
return 0;
|
return 0;
|
||||||
default:
|
default:
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
|
Loading…
Reference in New Issue
Block a user