mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-17 13:58:46 +00:00
hwmon: (adm9240) Create functions for updating measure and config
Split the body of adm9240_update_device() into two helper functions adm9240_update_measure() and adm9240_update_config(). Although neither of the new helpers returns an error yet lay the groundwork for propagating failures through to the sysfs readers. Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz> Link: https://lore.kernel.org/r/20200924085102.15219-3-chris.packham@alliedtelesis.co.nz Signed-off-by: Guenter Roeck <linux@roeck-us.net>
This commit is contained in:
parent
10d097737d
commit
6a8cdd1464
@ -158,18 +158,11 @@ static void adm9240_write_fan_div(struct i2c_client *client, int nr,
|
||||
nr + 1, 1 << old, 1 << fan_div);
|
||||
}
|
||||
|
||||
static struct adm9240_data *adm9240_update_device(struct device *dev)
|
||||
static int adm9240_update_measure(struct adm9240_data *data)
|
||||
{
|
||||
struct adm9240_data *data = dev_get_drvdata(dev);
|
||||
struct i2c_client *client = data->client;
|
||||
int i;
|
||||
|
||||
mutex_lock(&data->update_lock);
|
||||
|
||||
/* minimum measurement cycle: 1.75 seconds */
|
||||
if (time_after(jiffies, data->last_updated_measure + (HZ * 7 / 4))
|
||||
|| !data->valid) {
|
||||
|
||||
for (i = 0; i < 6; i++) { /* read voltages */
|
||||
data->in[i] = i2c_smbus_read_byte_data(client,
|
||||
ADM9240_REG_IN(i));
|
||||
@ -206,12 +199,14 @@ static struct adm9240_data *adm9240_update_device(struct device *dev)
|
||||
data->fan_min[i] /= 2;
|
||||
}
|
||||
}
|
||||
data->last_updated_measure = jiffies;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* minimum config reading cycle: 300 seconds */
|
||||
if (time_after(jiffies, data->last_updated_config + (HZ * 300))
|
||||
|| !data->valid) {
|
||||
static int adm9240_update_config(struct adm9240_data *data)
|
||||
{
|
||||
struct i2c_client *client = data->client;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 6; i++) {
|
||||
data->in_min[i] = i2c_smbus_read_byte_data(client,
|
||||
@ -239,6 +234,37 @@ static struct adm9240_data *adm9240_update_device(struct device *dev)
|
||||
data->aout = i2c_smbus_read_byte_data(client,
|
||||
ADM9240_REG_ANALOG_OUT);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct adm9240_data *adm9240_update_device(struct device *dev)
|
||||
{
|
||||
struct adm9240_data *data = dev_get_drvdata(dev);
|
||||
int err;
|
||||
|
||||
mutex_lock(&data->update_lock);
|
||||
|
||||
/* minimum measurement cycle: 1.75 seconds */
|
||||
if (time_after(jiffies, data->last_updated_measure + (HZ * 7 / 4))
|
||||
|| !data->valid) {
|
||||
err = adm9240_update_measure(data);
|
||||
if (err < 0) {
|
||||
data->valid = 0;
|
||||
mutex_unlock(&data->update_lock);
|
||||
return ERR_PTR(err);
|
||||
}
|
||||
data->last_updated_measure = jiffies;
|
||||
}
|
||||
|
||||
/* minimum config reading cycle: 300 seconds */
|
||||
if (time_after(jiffies, data->last_updated_config + (HZ * 300))
|
||||
|| !data->valid) {
|
||||
err = adm9240_update_config(data);
|
||||
if (err < 0) {
|
||||
data->valid = 0;
|
||||
mutex_unlock(&data->update_lock);
|
||||
return ERR_PTR(err);
|
||||
}
|
||||
data->last_updated_config = jiffies;
|
||||
data->valid = 1;
|
||||
}
|
||||
@ -253,6 +279,10 @@ static ssize_t temp1_input_show(struct device *dev,
|
||||
struct device_attribute *dummy, char *buf)
|
||||
{
|
||||
struct adm9240_data *data = adm9240_update_device(dev);
|
||||
|
||||
if (IS_ERR(data))
|
||||
return PTR_ERR(data);
|
||||
|
||||
return sprintf(buf, "%d\n", data->temp / 128 * 500); /* 9-bit value */
|
||||
}
|
||||
|
||||
@ -261,6 +291,10 @@ static ssize_t max_show(struct device *dev, struct device_attribute *devattr,
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
|
||||
struct adm9240_data *data = adm9240_update_device(dev);
|
||||
|
||||
if (IS_ERR(data))
|
||||
return PTR_ERR(data);
|
||||
|
||||
return sprintf(buf, "%d\n", data->temp_max[attr->index] * 1000);
|
||||
}
|
||||
|
||||
@ -295,6 +329,10 @@ static ssize_t in_show(struct device *dev, struct device_attribute *devattr,
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
|
||||
struct adm9240_data *data = adm9240_update_device(dev);
|
||||
|
||||
if (IS_ERR(data))
|
||||
return PTR_ERR(data);
|
||||
|
||||
return sprintf(buf, "%d\n", IN_FROM_REG(data->in[attr->index],
|
||||
attr->index));
|
||||
}
|
||||
@ -304,6 +342,10 @@ static ssize_t in_min_show(struct device *dev,
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
|
||||
struct adm9240_data *data = adm9240_update_device(dev);
|
||||
|
||||
if (IS_ERR(data))
|
||||
return PTR_ERR(data);
|
||||
|
||||
return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[attr->index],
|
||||
attr->index));
|
||||
}
|
||||
@ -313,6 +355,10 @@ static ssize_t in_max_show(struct device *dev,
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
|
||||
struct adm9240_data *data = adm9240_update_device(dev);
|
||||
|
||||
if (IS_ERR(data))
|
||||
return PTR_ERR(data);
|
||||
|
||||
return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[attr->index],
|
||||
attr->index));
|
||||
}
|
||||
@ -386,6 +432,10 @@ static ssize_t fan_show(struct device *dev, struct device_attribute *devattr,
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
|
||||
struct adm9240_data *data = adm9240_update_device(dev);
|
||||
|
||||
if (IS_ERR(data))
|
||||
return PTR_ERR(data);
|
||||
|
||||
return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[attr->index],
|
||||
1 << data->fan_div[attr->index]));
|
||||
}
|
||||
@ -395,6 +445,10 @@ static ssize_t fan_min_show(struct device *dev,
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
|
||||
struct adm9240_data *data = adm9240_update_device(dev);
|
||||
|
||||
if (IS_ERR(data))
|
||||
return PTR_ERR(data);
|
||||
|
||||
return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[attr->index],
|
||||
1 << data->fan_div[attr->index]));
|
||||
}
|
||||
@ -404,6 +458,10 @@ static ssize_t fan_div_show(struct device *dev,
|
||||
{
|
||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
|
||||
struct adm9240_data *data = adm9240_update_device(dev);
|
||||
|
||||
if (IS_ERR(data))
|
||||
return PTR_ERR(data);
|
||||
|
||||
return sprintf(buf, "%d\n", 1 << data->fan_div[attr->index]);
|
||||
}
|
||||
|
||||
@ -490,6 +548,10 @@ static ssize_t alarms_show(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
struct adm9240_data *data = adm9240_update_device(dev);
|
||||
|
||||
if (IS_ERR(data))
|
||||
return PTR_ERR(data);
|
||||
|
||||
return sprintf(buf, "%u\n", data->alarms);
|
||||
}
|
||||
static DEVICE_ATTR_RO(alarms);
|
||||
@ -499,6 +561,10 @@ static ssize_t alarm_show(struct device *dev, struct device_attribute *attr,
|
||||
{
|
||||
int bitnr = to_sensor_dev_attr(attr)->index;
|
||||
struct adm9240_data *data = adm9240_update_device(dev);
|
||||
|
||||
if (IS_ERR(data))
|
||||
return PTR_ERR(data);
|
||||
|
||||
return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
|
||||
}
|
||||
static SENSOR_DEVICE_ATTR_RO(in0_alarm, alarm, 0);
|
||||
@ -516,6 +582,10 @@ static ssize_t cpu0_vid_show(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
struct adm9240_data *data = adm9240_update_device(dev);
|
||||
|
||||
if (IS_ERR(data))
|
||||
return PTR_ERR(data);
|
||||
|
||||
return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm));
|
||||
}
|
||||
static DEVICE_ATTR_RO(cpu0_vid);
|
||||
@ -525,6 +595,10 @@ static ssize_t aout_output_show(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
struct adm9240_data *data = adm9240_update_device(dev);
|
||||
|
||||
if (IS_ERR(data))
|
||||
return PTR_ERR(data);
|
||||
|
||||
return sprintf(buf, "%d\n", AOUT_FROM_REG(data->aout));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user