device_create_file(&client->dev, &dev_attr_beep_mask); \
} while (0)
-/* w83697hf only has two fans */
static ssize_t
show_fan_div_reg(struct device *dev, char *buf, int nr)
{
(long) DIV_FROM_REG(data->fan_div[nr - 1]));
}
-/* w83697hf only has two fans */
static ssize_t
-store_fan_div_reg(struct device *dev, const char *buf, size_t count, int nr)
+store_regs_fan_div_1(struct device *dev, const char *buf, size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct w83781d_data *data = i2c_get_clientdata(client);
- u32 val, old, old2, old3 = 0;
+ u32 reg;
- val = simple_strtoul(buf, NULL, 10);
- old = w83781d_read_value(client, W83781D_REG_VID_FANDIV);
+ data->fan_div[0] = DIV_TO_REG(simple_strtoul(buf, NULL, 10),
+ data->type);
- data->fan_div[nr - 1] = DIV_TO_REG(val, data->type);
+ reg = w83781d_read_value(client, W83781D_REG_VID_FANDIV) & 0xcf;
+ reg |= (data->fan_div[0] & 0x03) << 4;
+ w83781d_write_value(client, W83781D_REG_VID_FANDIV, reg);
/* w83781d and as99127f don't have extended divisor bits */
- if ((data->type != w83781d) && data->type != as99127f) {
- old3 = w83781d_read_value(client, W83781D_REG_VBAT);
+ if (data->type != w83781d && data->type != as99127f) {
+ reg = w83781d_read_value(client, W83781D_REG_VBAT) & 0xdf;
+ reg |= (data->fan_div[0] & 0x04) << 3;
+ w83781d_write_value(client, W83781D_REG_VBAT, reg);
}
- if (nr >= 3 && data->type != w83697hf) {
- old2 = w83781d_read_value(client, W83781D_REG_PIN);
- old2 = (old2 & 0x3f) | ((data->fan_div[2] & 0x03) << 6);
- w83781d_write_value(client, W83781D_REG_PIN, old2);
- if ((data->type != w83781d) && (data->type != as99127f)) {
- old3 = (old3 & 0x7f) | ((data->fan_div[2] & 0x04) << 5);
- }
- }
- if (nr >= 2) {
- old = (old & 0x3f) | ((data->fan_div[1] & 0x03) << 6);
+ return count;
+}
- if ((data->type != w83781d) && (data->type != as99127f)) {
- old3 = (old3 & 0xbf) | ((data->fan_div[1] & 0x04) << 4);
- }
+static ssize_t
+store_regs_fan_div_2(struct device *dev, const char *buf, size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct w83781d_data *data = i2c_get_clientdata(client);
+ u32 reg;
+
+ data->fan_div[1] = DIV_TO_REG(simple_strtoul(buf, NULL, 10),
+ data->type);
+
+ reg = w83781d_read_value(client, W83781D_REG_VID_FANDIV) & 0x3f;
+ reg |= (data->fan_div[1] & 0x03) << 6;
+ w83781d_write_value(client, W83781D_REG_VID_FANDIV, reg);
+
+ /* w83781d and as99127f don't have extended divisor bits */
+ if (data->type != w83781d && data->type != as99127f) {
+ reg = w83781d_read_value(client, W83781D_REG_VBAT) & 0xbf;
+ reg |= (data->fan_div[1] & 0x04) << 4;
+ w83781d_write_value(client, W83781D_REG_VBAT, reg);
}
- if (nr >= 1) {
- old = (old & 0xcf) | ((data->fan_div[0] & 0x03) << 4);
- w83781d_write_value(client, W83781D_REG_VID_FANDIV, old);
- if ((data->type != w83781d) && (data->type != as99127f)) {
- old3 = (old3 & 0xdf) | ((data->fan_div[0] & 0x04) << 3);
- w83781d_write_value(client, W83781D_REG_VBAT, old3);
- }
+ return count;
+}
+
+static ssize_t
+store_regs_fan_div_3(struct device *dev, const char *buf, size_t count)
+{
+ struct i2c_client *client = to_i2c_client(dev);
+ struct w83781d_data *data = i2c_get_clientdata(client);
+ u32 reg;
+
+ data->fan_div[2] = DIV_TO_REG(simple_strtoul(buf, NULL, 10),
+ data->type);
+
+ reg = w83781d_read_value(client, W83781D_REG_PIN) & 0x3f;
+ reg |= (data->fan_div[2] & 0x03) << 6;
+ w83781d_write_value(client, W83781D_REG_PIN, reg);
+
+ /* w83781d and as99127f don't have extended divisor bits */
+ if (data->type != w83781d && data->type != as99127f) {
+ reg = w83781d_read_value(client, W83781D_REG_VBAT) & 0x7f;
+ reg |= (data->fan_div[2] & 0x04) << 5;
+ w83781d_write_value(client, W83781D_REG_VBAT, reg);
}
return count;
{ \
return show_fan_div_reg(dev, buf, offset); \
} \
-static ssize_t store_regs_fan_div_##offset (struct device *dev, const char *buf, size_t count) \
-{ \
- return store_fan_div_reg(dev, buf, count, offset); \
-} \
static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, show_regs_fan_div_##offset, store_regs_fan_div_##offset)
sysfs_fan_div(1);