Skip to content

Commit

Permalink
hwmon: (nct6775) Add read-only mode
Browse files Browse the repository at this point in the history
When enabled, all write bits are removed from the modes of all sysfs
attribute files.  This provides a bit of infrastructure for the
upcoming i2c version of this driver, which should generally avoid
writes to device registers so as not to interfere with simultaneous
use of the device via the LPC interface.

Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
Reviewed-by: Joel Stanley <joel@jms.id.au>
Link: https://lore.kernel.org/r/20220427010154.29749-5-zev@bewilderbeest.net
Tested-by: Oleksandr Natalenko <oleksandr@natalenko.name>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
  • Loading branch information
Zev Weiss authored and Guenter Roeck committed May 20, 2022
1 parent 3c7e493 commit bd2e82b
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions drivers/hwmon/nct6775.c
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,7 @@ struct nct6775_data {
u8 sio_reg_enable;

struct regmap *regmap;
bool read_only;
};

struct sensor_device_template {
Expand Down Expand Up @@ -1405,6 +1406,11 @@ struct sensor_template_group {
int base;
};

static inline umode_t nct6775_attr_mode(struct nct6775_data *data, struct attribute *attr)
{
return data->read_only ? (attr->mode & ~0222) : attr->mode;
}

static int nct6775_add_attr_group(struct nct6775_data *data, const struct attribute_group *group)
{
/* Need to leave a NULL terminator at the end of data->groups */
Expand Down Expand Up @@ -2371,7 +2377,7 @@ static umode_t nct6775_in_is_visible(struct kobject *kobj,
if (!(data->have_in & BIT(in)))
return 0;

return attr->mode;
return nct6775_attr_mode(data, attr);
}

SENSOR_TEMPLATE_2(in_input, "in%d_input", S_IRUGO, show_in_reg, NULL, 0, 0);
Expand Down Expand Up @@ -2607,7 +2613,7 @@ static umode_t nct6775_fan_is_visible(struct kobject *kobj,
if (nr == 5 && data->kind != nct6775)
return 0;

return attr->mode;
return nct6775_attr_mode(data, attr);
}

SENSOR_TEMPLATE(fan_input, "fan%d_input", S_IRUGO, show_fan, NULL, 0);
Expand Down Expand Up @@ -2834,7 +2840,7 @@ static umode_t nct6775_temp_is_visible(struct kobject *kobj,
if (nr > 7 && !(data->have_temp_fixed & BIT(temp)))
return 0;

return attr->mode;
return nct6775_attr_mode(data, attr);
}

SENSOR_TEMPLATE_2(temp_input, "temp%d_input", S_IRUGO, show_temp, NULL, 0, 0);
Expand Down Expand Up @@ -2908,7 +2914,7 @@ static umode_t nct6775_tsi_temp_is_visible(struct kobject *kobj, struct attribut
struct nct6775_data *data = dev_get_drvdata(dev);
int temp = index / 2;

return (data->have_tsi_temp & BIT(temp)) ? attr->mode : 0;
return (data->have_tsi_temp & BIT(temp)) ? nct6775_attr_mode(data, attr) : 0;
}

/*
Expand Down Expand Up @@ -3766,7 +3772,7 @@ static umode_t nct6775_pwm_is_visible(struct kobject *kobj,
if (api > data->auto_pwm_num)
return 0;
}
return attr->mode;
return nct6775_attr_mode(data, attr);
}

SENSOR_TEMPLATE_2(pwm_stop_time, "pwm%d_stop_time", S_IWUSR | S_IRUGO,
Expand Down Expand Up @@ -3961,7 +3967,7 @@ static umode_t nct6775_other_is_visible(struct kobject *kobj,
return 0;
}

return attr->mode;
return nct6775_attr_mode(data, attr);
}

/*
Expand Down

0 comments on commit bd2e82b

Please sign in to comment.