w83627hf.c
来自「linux 内核源代码」· C语言 代码 · 共 1,707 行 · 第 1/4 页
C
1,707 行
data->in_min[nr] = IN_TO_REG(val); w83627hf_write_value(data, W83781D_REG_IN_MIN(nr), data->in_min[nr]); mutex_unlock(&data->update_lock); return count;}static ssize_tstore_in_max(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count){ int nr = to_sensor_dev_attr(devattr)->index; struct w83627hf_data *data = dev_get_drvdata(dev); long val = simple_strtol(buf, NULL, 10); mutex_lock(&data->update_lock); data->in_max[nr] = IN_TO_REG(val); w83627hf_write_value(data, W83781D_REG_IN_MAX(nr), data->in_max[nr]); mutex_unlock(&data->update_lock); return count;}#define sysfs_vin_decl(offset) \static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \ show_in_input, NULL, offset); \static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO|S_IWUSR, \ show_in_min, store_in_min, offset); \static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO|S_IWUSR, \ show_in_max, store_in_max, offset);sysfs_vin_decl(1);sysfs_vin_decl(2);sysfs_vin_decl(3);sysfs_vin_decl(4);sysfs_vin_decl(5);sysfs_vin_decl(6);sysfs_vin_decl(7);sysfs_vin_decl(8);/* use a different set of functions for in0 */static ssize_t show_in_0(struct w83627hf_data *data, char *buf, u8 reg){ long in0; if ((data->vrm_ovt & 0x01) && (w83627thf == data->type || w83637hf == data->type || w83687thf == data->type)) /* use VRM9 calculation */ in0 = (long)((reg * 488 + 70000 + 50) / 100); else /* use VRM8 (standard) calculation */ in0 = (long)IN_FROM_REG(reg); return sprintf(buf,"%ld\n", in0);}static ssize_t show_regs_in_0(struct device *dev, struct device_attribute *attr, char *buf){ struct w83627hf_data *data = w83627hf_update_device(dev); return show_in_0(data, buf, data->in[0]);}static ssize_t show_regs_in_min0(struct device *dev, struct device_attribute *attr, char *buf){ struct w83627hf_data *data = w83627hf_update_device(dev); return show_in_0(data, buf, data->in_min[0]);}static ssize_t show_regs_in_max0(struct device *dev, struct device_attribute *attr, char *buf){ struct w83627hf_data *data = w83627hf_update_device(dev); return show_in_0(data, buf, data->in_max[0]);}static ssize_t store_regs_in_min0(struct device *dev, struct device_attribute *attr, const char *buf, size_t count){ struct w83627hf_data *data = dev_get_drvdata(dev); u32 val; val = simple_strtoul(buf, NULL, 10); mutex_lock(&data->update_lock); if ((data->vrm_ovt & 0x01) && (w83627thf == data->type || w83637hf == data->type || w83687thf == data->type)) /* use VRM9 calculation */ data->in_min[0] = SENSORS_LIMIT(((val * 100) - 70000 + 244) / 488, 0, 255); else /* use VRM8 (standard) calculation */ data->in_min[0] = IN_TO_REG(val); w83627hf_write_value(data, W83781D_REG_IN_MIN(0), data->in_min[0]); mutex_unlock(&data->update_lock); return count;}static ssize_t store_regs_in_max0(struct device *dev, struct device_attribute *attr, const char *buf, size_t count){ struct w83627hf_data *data = dev_get_drvdata(dev); u32 val; val = simple_strtoul(buf, NULL, 10); mutex_lock(&data->update_lock); if ((data->vrm_ovt & 0x01) && (w83627thf == data->type || w83637hf == data->type || w83687thf == data->type)) /* use VRM9 calculation */ data->in_max[0] = SENSORS_LIMIT(((val * 100) - 70000 + 244) / 488, 0, 255); else /* use VRM8 (standard) calculation */ data->in_max[0] = IN_TO_REG(val); w83627hf_write_value(data, W83781D_REG_IN_MAX(0), data->in_max[0]); mutex_unlock(&data->update_lock); return count;}static DEVICE_ATTR(in0_input, S_IRUGO, show_regs_in_0, NULL);static DEVICE_ATTR(in0_min, S_IRUGO | S_IWUSR, show_regs_in_min0, store_regs_in_min0);static DEVICE_ATTR(in0_max, S_IRUGO | S_IWUSR, show_regs_in_max0, store_regs_in_max0);static ssize_tshow_fan_input(struct device *dev, struct device_attribute *devattr, char *buf){ int nr = to_sensor_dev_attr(devattr)->index; struct w83627hf_data *data = w83627hf_update_device(dev); return sprintf(buf, "%ld\n", FAN_FROM_REG(data->fan[nr], (long)DIV_FROM_REG(data->fan_div[nr])));}static ssize_tshow_fan_min(struct device *dev, struct device_attribute *devattr, char *buf){ int nr = to_sensor_dev_attr(devattr)->index; struct w83627hf_data *data = w83627hf_update_device(dev); return sprintf(buf, "%ld\n", FAN_FROM_REG(data->fan_min[nr], (long)DIV_FROM_REG(data->fan_div[nr])));}static ssize_tstore_fan_min(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count){ int nr = to_sensor_dev_attr(devattr)->index; struct w83627hf_data *data = dev_get_drvdata(dev); u32 val = simple_strtoul(buf, NULL, 10); mutex_lock(&data->update_lock); data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); w83627hf_write_value(data, W83627HF_REG_FAN_MIN(nr), data->fan_min[nr]); mutex_unlock(&data->update_lock); return count;}#define sysfs_fan_decl(offset) \static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ show_fan_input, NULL, offset - 1); \static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ show_fan_min, store_fan_min, offset - 1);sysfs_fan_decl(1);sysfs_fan_decl(2);sysfs_fan_decl(3);static ssize_tshow_temp(struct device *dev, struct device_attribute *devattr, char *buf){ int nr = to_sensor_dev_attr(devattr)->index; struct w83627hf_data *data = w83627hf_update_device(dev); u16 tmp = data->temp[nr]; return sprintf(buf, "%ld\n", (nr) ? (long) LM75_TEMP_FROM_REG(tmp) : (long) TEMP_FROM_REG(tmp));}static ssize_tshow_temp_max(struct device *dev, struct device_attribute *devattr, char *buf){ int nr = to_sensor_dev_attr(devattr)->index; struct w83627hf_data *data = w83627hf_update_device(dev); u16 tmp = data->temp_max[nr]; return sprintf(buf, "%ld\n", (nr) ? (long) LM75_TEMP_FROM_REG(tmp) : (long) TEMP_FROM_REG(tmp));}static ssize_tshow_temp_max_hyst(struct device *dev, struct device_attribute *devattr, char *buf){ int nr = to_sensor_dev_attr(devattr)->index; struct w83627hf_data *data = w83627hf_update_device(dev); u16 tmp = data->temp_max_hyst[nr]; return sprintf(buf, "%ld\n", (nr) ? (long) LM75_TEMP_FROM_REG(tmp) : (long) TEMP_FROM_REG(tmp));}static ssize_tstore_temp_max(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count){ int nr = to_sensor_dev_attr(devattr)->index; struct w83627hf_data *data = dev_get_drvdata(dev); long val = simple_strtol(buf, NULL, 10); u16 tmp = (nr) ? LM75_TEMP_TO_REG(val) : TEMP_TO_REG(val); mutex_lock(&data->update_lock); data->temp_max[nr] = tmp; w83627hf_write_value(data, w83627hf_reg_temp_over[nr], tmp); mutex_unlock(&data->update_lock); return count;}static ssize_tstore_temp_max_hyst(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count){ int nr = to_sensor_dev_attr(devattr)->index; struct w83627hf_data *data = dev_get_drvdata(dev); long val = simple_strtol(buf, NULL, 10); u16 tmp = (nr) ? LM75_TEMP_TO_REG(val) : TEMP_TO_REG(val); mutex_lock(&data->update_lock); data->temp_max_hyst[nr] = tmp; w83627hf_write_value(data, w83627hf_reg_temp_hyst[nr], tmp); mutex_unlock(&data->update_lock); return count;}#define sysfs_temp_decl(offset) \static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ show_temp, NULL, offset - 1); \static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO|S_IWUSR, \ show_temp_max, store_temp_max, offset - 1); \static SENSOR_DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO|S_IWUSR, \ show_temp_max_hyst, store_temp_max_hyst, offset - 1);sysfs_temp_decl(1);sysfs_temp_decl(2);sysfs_temp_decl(3);static ssize_tshow_vid_reg(struct device *dev, struct device_attribute *attr, char *buf){ struct w83627hf_data *data = w83627hf_update_device(dev); return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));}static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);static ssize_tshow_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf){ struct w83627hf_data *data = dev_get_drvdata(dev); return sprintf(buf, "%ld\n", (long) data->vrm);}static ssize_tstore_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count){ struct w83627hf_data *data = dev_get_drvdata(dev); u32 val; val = simple_strtoul(buf, NULL, 10); data->vrm = val; return count;}static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);static ssize_tshow_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf){ struct w83627hf_data *data = w83627hf_update_device(dev); return sprintf(buf, "%ld\n", (long) data->alarms);}static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);#define show_beep_reg(REG, reg) \static ssize_t show_beep_##reg (struct device *dev, struct device_attribute *attr, char *buf) \{ \ struct w83627hf_data *data = w83627hf_update_device(dev); \ return sprintf(buf,"%ld\n", \ (long)BEEP_##REG##_FROM_REG(data->beep_##reg)); \}show_beep_reg(ENABLE, enable)show_beep_reg(MASK, mask)#define BEEP_ENABLE 0 /* Store beep_enable */#define BEEP_MASK 1 /* Store beep_mask */static ssize_tstore_beep_reg(struct device *dev, const char *buf, size_t count, int update_mask){ struct w83627hf_data *data = dev_get_drvdata(dev); u32 val, val2; val = simple_strtoul(buf, NULL, 10); mutex_lock(&data->update_lock); if (update_mask == BEEP_MASK) { /* We are storing beep_mask */ data->beep_mask = BEEP_MASK_TO_REG(val); w83627hf_write_value(data, W83781D_REG_BEEP_INTS1, data->beep_mask & 0xff); w83627hf_write_value(data, W83781D_REG_BEEP_INTS3, ((data->beep_mask) >> 16) & 0xff); val2 = (data->beep_mask >> 8) & 0x7f; } else { /* We are storing beep_enable */ val2 = w83627hf_read_value(data, W83781D_REG_BEEP_INTS2) & 0x7f; data->beep_enable = BEEP_ENABLE_TO_REG(val); } w83627hf_write_value(data, W83781D_REG_BEEP_INTS2, val2 | data->beep_enable << 7); mutex_unlock(&data->update_lock); return count;}#define sysfs_beep(REG, reg) \static ssize_t show_regs_beep_##reg (struct device *dev, struct device_attribute *attr, char *buf) \{ \ return show_beep_##reg(dev, attr, buf); \} \static ssize_t \store_regs_beep_##reg (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \{ \ return store_beep_reg(dev, buf, count, BEEP_##REG); \} \static DEVICE_ATTR(beep_##reg, S_IRUGO | S_IWUSR, \ show_regs_beep_##reg, store_regs_beep_##reg);sysfs_beep(ENABLE, enable);sysfs_beep(MASK, mask);static ssize_tshow_fan_div(struct device *dev, struct device_attribute *devattr, char *buf){ int nr = to_sensor_dev_attr(devattr)->index; struct w83627hf_data *data = w83627hf_update_device(dev); return sprintf(buf, "%ld\n", (long) DIV_FROM_REG(data->fan_div[nr]));}/* Note: we save and restore the fan minimum here, because its value is determined in part by the fan divisor. This follows the principle of least surprise; the user doesn't expect the fan minimum to change just because the divisor changed. */static ssize_tstore_fan_div(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count){ int nr = to_sensor_dev_attr(devattr)->index; struct w83627hf_data *data = dev_get_drvdata(dev); unsigned long min; u8 reg; unsigned long val = simple_strtoul(buf, NULL, 10); mutex_lock(&data->update_lock); /* Save fan_min */ min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])); data->fan_div[nr] = DIV_TO_REG(val); reg = (w83627hf_read_value(data, nr==2 ? W83781D_REG_PIN : W83781D_REG_VID_FANDIV) & (nr==0 ? 0xcf : 0x3f)) | ((data->fan_div[nr] & 0x03) << (nr==0 ? 4 : 6)); w83627hf_write_value(data, nr==2 ? W83781D_REG_PIN : W83781D_REG_VID_FANDIV, reg); reg = (w83627hf_read_value(data, W83781D_REG_VBAT) & ~(1 << (5 + nr))) | ((data->fan_div[nr] & 0x04) << (3 + nr)); w83627hf_write_value(data, W83781D_REG_VBAT, reg); /* Restore fan_min */ data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); w83627hf_write_value(data, W83627HF_REG_FAN_MIN(nr), data->fan_min[nr]); mutex_unlock(&data->update_lock); return count;}static SENSOR_DEVICE_ATTR(fan1_div, S_IRUGO|S_IWUSR, show_fan_div, store_fan_div, 0);static SENSOR_DEVICE_ATTR(fan2_div, S_IRUGO|S_IWUSR, show_fan_div, store_fan_div, 1);static SENSOR_DEVICE_ATTR(fan3_div, S_IRUGO|S_IWUSR, show_fan_div, store_fan_div, 2);static ssize_tshow_pwm(struct device *dev, struct device_attribute *devattr, char *buf){ int nr = to_sensor_dev_attr(devattr)->index; struct w83627hf_data *data = w83627hf_update_device(dev); return sprintf(buf, "%ld\n", (long) data->pwm[nr]);}static ssize_tstore_pwm(struct device *dev, struct device_attribute *devattr, const char *buf, size_t count){ int nr = to_sensor_dev_attr(devattr)->index; struct w83627hf_data *data = dev_get_drvdata(dev); u32 val = simple_strtoul(buf, NULL, 10); mutex_lock(&data->update_lock); if (data->type == w83627thf) { /* bits 0-3 are reserved in 627THF */ data->pwm[nr] = PWM_TO_REG(val) & 0xf0; w83627hf_write_value(data, W836X7HF_REG_PWM(data->type, nr), data->pwm[nr] |
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?