lm93.c
来自「linux 内核源代码」· C语言 代码 · 共 2,063 行 · 第 1/5 页
C
2,063 行
static SENSOR_DEVICE_ATTR(in15_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 14);static SENSOR_DEVICE_ATTR(in16_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 15);static ssize_t show_temp(struct device *dev, struct device_attribute *attr, char *buf){ int nr = (to_sensor_dev_attr(attr))->index; struct lm93_data *data = lm93_update_device(dev); return sprintf(buf,"%d\n",LM93_TEMP_FROM_REG(data->block2[nr]));}static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1);static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2);static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr, char *buf){ int nr = (to_sensor_dev_attr(attr))->index; struct lm93_data *data = lm93_update_device(dev); return sprintf(buf,"%d\n",LM93_TEMP_FROM_REG(data->temp_lim[nr].min));}static ssize_t store_temp_min(struct device *dev, struct device_attribute *attr, const char *buf, size_t count){ int nr = (to_sensor_dev_attr(attr))->index; struct i2c_client *client = to_i2c_client(dev); struct lm93_data *data = i2c_get_clientdata(client); long val = simple_strtol(buf, NULL, 10); mutex_lock(&data->update_lock); data->temp_lim[nr].min = LM93_TEMP_TO_REG(val); lm93_write_byte(client, LM93_REG_TEMP_MIN(nr), data->temp_lim[nr].min); mutex_unlock(&data->update_lock); return count;}static SENSOR_DEVICE_ATTR(temp1_min, S_IWUSR | S_IRUGO, show_temp_min, store_temp_min, 0);static SENSOR_DEVICE_ATTR(temp2_min, S_IWUSR | S_IRUGO, show_temp_min, store_temp_min, 1);static SENSOR_DEVICE_ATTR(temp3_min, S_IWUSR | S_IRUGO, show_temp_min, store_temp_min, 2);static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr, char *buf){ int nr = (to_sensor_dev_attr(attr))->index; struct lm93_data *data = lm93_update_device(dev); return sprintf(buf,"%d\n",LM93_TEMP_FROM_REG(data->temp_lim[nr].max));}static ssize_t store_temp_max(struct device *dev, struct device_attribute *attr, const char *buf, size_t count){ int nr = (to_sensor_dev_attr(attr))->index; struct i2c_client *client = to_i2c_client(dev); struct lm93_data *data = i2c_get_clientdata(client); long val = simple_strtol(buf, NULL, 10); mutex_lock(&data->update_lock); data->temp_lim[nr].max = LM93_TEMP_TO_REG(val); lm93_write_byte(client, LM93_REG_TEMP_MAX(nr), data->temp_lim[nr].max); mutex_unlock(&data->update_lock); return count;}static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max, store_temp_max, 0);static SENSOR_DEVICE_ATTR(temp2_max, S_IWUSR | S_IRUGO, show_temp_max, store_temp_max, 1);static SENSOR_DEVICE_ATTR(temp3_max, S_IWUSR | S_IRUGO, show_temp_max, store_temp_max, 2);static ssize_t show_temp_auto_base(struct device *dev, struct device_attribute *attr, char *buf){ int nr = (to_sensor_dev_attr(attr))->index; struct lm93_data *data = lm93_update_device(dev); return sprintf(buf,"%d\n",LM93_TEMP_FROM_REG(data->block10.base[nr]));}static ssize_t store_temp_auto_base(struct device *dev, struct device_attribute *attr, const char *buf, size_t count){ int nr = (to_sensor_dev_attr(attr))->index; struct i2c_client *client = to_i2c_client(dev); struct lm93_data *data = i2c_get_clientdata(client); long val = simple_strtol(buf, NULL, 10); mutex_lock(&data->update_lock); data->block10.base[nr] = LM93_TEMP_TO_REG(val); lm93_write_byte(client, LM93_REG_TEMP_BASE(nr), data->block10.base[nr]); mutex_unlock(&data->update_lock); return count;}static SENSOR_DEVICE_ATTR(temp1_auto_base, S_IWUSR | S_IRUGO, show_temp_auto_base, store_temp_auto_base, 0);static SENSOR_DEVICE_ATTR(temp2_auto_base, S_IWUSR | S_IRUGO, show_temp_auto_base, store_temp_auto_base, 1);static SENSOR_DEVICE_ATTR(temp3_auto_base, S_IWUSR | S_IRUGO, show_temp_auto_base, store_temp_auto_base, 2);static ssize_t show_temp_auto_boost(struct device *dev, struct device_attribute *attr,char *buf){ int nr = (to_sensor_dev_attr(attr))->index; struct lm93_data *data = lm93_update_device(dev); return sprintf(buf,"%d\n",LM93_TEMP_FROM_REG(data->boost[nr]));}static ssize_t store_temp_auto_boost(struct device *dev, struct device_attribute *attr, const char *buf, size_t count){ int nr = (to_sensor_dev_attr(attr))->index; struct i2c_client *client = to_i2c_client(dev); struct lm93_data *data = i2c_get_clientdata(client); long val = simple_strtol(buf, NULL, 10); mutex_lock(&data->update_lock); data->boost[nr] = LM93_TEMP_TO_REG(val); lm93_write_byte(client, LM93_REG_BOOST(nr), data->boost[nr]); mutex_unlock(&data->update_lock); return count;}static SENSOR_DEVICE_ATTR(temp1_auto_boost, S_IWUSR | S_IRUGO, show_temp_auto_boost, store_temp_auto_boost, 0);static SENSOR_DEVICE_ATTR(temp2_auto_boost, S_IWUSR | S_IRUGO, show_temp_auto_boost, store_temp_auto_boost, 1);static SENSOR_DEVICE_ATTR(temp3_auto_boost, S_IWUSR | S_IRUGO, show_temp_auto_boost, store_temp_auto_boost, 2);static ssize_t show_temp_auto_boost_hyst(struct device *dev, struct device_attribute *attr, char *buf){ int nr = (to_sensor_dev_attr(attr))->index; struct lm93_data *data = lm93_update_device(dev); int mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr); return sprintf(buf,"%d\n", LM93_AUTO_BOOST_HYST_FROM_REGS(data, nr, mode));}static ssize_t store_temp_auto_boost_hyst(struct device *dev, struct device_attribute *attr, const char *buf, size_t count){ int nr = (to_sensor_dev_attr(attr))->index; struct i2c_client *client = to_i2c_client(dev); struct lm93_data *data = i2c_get_clientdata(client); u32 val = simple_strtoul(buf, NULL, 10); mutex_lock(&data->update_lock); /* force 0.5C/bit mode */ data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); data->sfc2 |= ((nr < 2) ? 0x10 : 0x20); lm93_write_byte(client, LM93_REG_SFC2, data->sfc2); data->boost_hyst[nr/2] = LM93_AUTO_BOOST_HYST_TO_REG(data, val, nr, 1); lm93_write_byte(client, LM93_REG_BOOST_HYST(nr), data->boost_hyst[nr/2]); mutex_unlock(&data->update_lock); return count;}static SENSOR_DEVICE_ATTR(temp1_auto_boost_hyst, S_IWUSR | S_IRUGO, show_temp_auto_boost_hyst, store_temp_auto_boost_hyst, 0);static SENSOR_DEVICE_ATTR(temp2_auto_boost_hyst, S_IWUSR | S_IRUGO, show_temp_auto_boost_hyst, store_temp_auto_boost_hyst, 1);static SENSOR_DEVICE_ATTR(temp3_auto_boost_hyst, S_IWUSR | S_IRUGO, show_temp_auto_boost_hyst, store_temp_auto_boost_hyst, 2);static ssize_t show_temp_auto_offset(struct device *dev, struct device_attribute *attr, char *buf){ struct sensor_device_attribute_2 *s_attr = to_sensor_dev_attr_2(attr); int nr = s_attr->index; int ofs = s_attr->nr; struct lm93_data *data = lm93_update_device(dev); int mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr); return sprintf(buf,"%d\n", LM93_TEMP_AUTO_OFFSET_FROM_REG(data->block10.offset[ofs], nr,mode));}static ssize_t store_temp_auto_offset(struct device *dev, struct device_attribute *attr, const char *buf, size_t count){ struct sensor_device_attribute_2 *s_attr = to_sensor_dev_attr_2(attr); int nr = s_attr->index; int ofs = s_attr->nr; struct i2c_client *client = to_i2c_client(dev); struct lm93_data *data = i2c_get_clientdata(client); u32 val = simple_strtoul(buf, NULL, 10); mutex_lock(&data->update_lock); /* force 0.5C/bit mode */ data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); data->sfc2 |= ((nr < 2) ? 0x10 : 0x20); lm93_write_byte(client, LM93_REG_SFC2, data->sfc2); data->block10.offset[ofs] = LM93_TEMP_AUTO_OFFSET_TO_REG( data->block10.offset[ofs], val, nr, 1); lm93_write_byte(client, LM93_REG_TEMP_OFFSET(ofs), data->block10.offset[ofs]); mutex_unlock(&data->update_lock); return count;}static SENSOR_DEVICE_ATTR_2(temp1_auto_offset1, S_IWUSR | S_IRUGO, show_temp_auto_offset, store_temp_auto_offset, 0, 0);static SENSOR_DEVICE_ATTR_2(temp1_auto_offset2, S_IWUSR | S_IRUGO, show_temp_auto_offset, store_temp_auto_offset, 1, 0);static SENSOR_DEVICE_ATTR_2(temp1_auto_offset3, S_IWUSR | S_IRUGO, show_temp_auto_offset, store_temp_auto_offset, 2, 0);static SENSOR_DEVICE_ATTR_2(temp1_auto_offset4, S_IWUSR | S_IRUGO, show_temp_auto_offset, store_temp_auto_offset, 3, 0);static SENSOR_DEVICE_ATTR_2(temp1_auto_offset5, S_IWUSR | S_IRUGO, show_temp_auto_offset, store_temp_auto_offset, 4, 0);static SENSOR_DEVICE_ATTR_2(temp1_auto_offset6, S_IWUSR | S_IRUGO, show_temp_auto_offset, store_temp_auto_offset, 5, 0);static SENSOR_DEVICE_ATTR_2(temp1_auto_offset7, S_IWUSR | S_IRUGO, show_temp_auto_offset, store_temp_auto_offset, 6, 0);static SENSOR_DEVICE_ATTR_2(temp1_auto_offset8, S_IWUSR | S_IRUGO, show_temp_auto_offset, store_temp_auto_offset, 7, 0);static SENSOR_DEVICE_ATTR_2(temp1_auto_offset9, S_IWUSR | S_IRUGO, show_temp_auto_offset, store_temp_auto_offset, 8, 0);static SENSOR_DEVICE_ATTR_2(temp1_auto_offset10, S_IWUSR | S_IRUGO, show_temp_auto_offset, store_temp_auto_offset, 9, 0);static SENSOR_DEVICE_ATTR_2(temp1_auto_offset11, S_IWUSR | S_IRUGO, show_temp_auto_offset, store_temp_auto_offset, 10, 0);static SENSOR_DEVICE_ATTR_2(temp1_auto_offset12, S_IWUSR | S_IRUGO, show_temp_auto_offset, store_temp_auto_offset, 11, 0);static SENSOR_DEVICE_ATTR_2(temp2_auto_offset1, S_IWUSR | S_IRUGO, show_temp_auto_offset, store_temp_auto_offset, 0, 1);static SENSOR_DEVICE_ATTR_2(temp2_auto_offset2, S_IWUSR | S_IRUGO, show_temp_auto_offset, store_temp_auto_offset, 1, 1);static SENSOR_DEVICE_ATTR_2(temp2_auto_offset3, S_IWUSR | S_IRUGO, show_temp_auto_offset, store_temp_auto_offset, 2, 1);static SENSOR_DEVICE_ATTR_2(temp2_auto_offset4, S_IWUSR | S_IRUGO, show_temp_auto_offset, store_temp_auto_offset, 3, 1);static SENSOR_DEVICE_ATTR_2(temp2_auto_offset5, S_IWUSR | S_IRUGO, show_temp_auto_offset, store_temp_auto_offset, 4, 1);static SENSOR_DEVICE_ATTR_2(temp2_auto_offset6, S_IWUSR | S_IRUGO, show_temp_auto_offset, store_temp_auto_offset, 5, 1);static SENSOR_DEVICE_ATTR_2(temp2_auto_offset7, S_IWUSR | S_IRUGO, show_temp_auto_offset, store_temp_auto_offset, 6, 1);static SENSOR_DEVICE_ATTR_2(temp2_auto_offset8, S_IWUSR | S_IRUGO, show_temp_auto_offset, store_temp_auto_offset, 7, 1);static SENSOR_DEVICE_ATTR_2(temp2_auto_offset9, S_IWUSR | S_IRUGO, show_temp_auto_offset, store_temp_auto_offset, 8, 1);static SENSOR_DEVICE_ATTR_2(temp2_auto_offset10, S_IWUSR | S_IRUGO, show_temp_auto_offset, store_temp_auto_offset, 9, 1);static SENSOR_DEVICE_ATTR_2(temp2_auto_offset11, S_IWUSR | S_IRUGO, show_temp_auto_offset, store_temp_auto_offset, 10, 1);static SENSOR_DEVICE_ATTR_2(temp2_auto_offset12, S_IWUSR | S_IRUGO, show_temp_auto_offset, store_temp_auto_offset, 11, 1);static SENSOR_DEVICE_ATTR_2(temp3_auto_offset1, S_IWUSR | S_IRUGO, show_temp_auto_offset, store_temp_auto_offset, 0, 2);static SENSOR_DEVICE_ATTR_2(temp3_auto_offset2, S_IWUSR | S_IRUGO, show_temp_auto_offset, store_temp_auto_offset, 1, 2);static SENSOR_DEVICE_ATTR_2(temp3_auto_offset3, S_IWUSR | S_IRUGO, show_temp_auto_offset, store_temp_auto_offset, 2, 2);static SENSOR_DEVICE_ATTR_2(temp3_auto_offset4, S_IWUSR | S_IRUGO, show_temp_auto_offset, store_temp_auto_offset, 3, 2);static SENSOR_DEVICE_ATTR_2(temp3_auto_offset5, S_IWUSR | S_IRUGO, show_temp_auto_offset, store_temp_auto_offset, 4, 2);static SENSOR_DEVICE_ATTR_2(temp3_auto_offset6, S_IWUSR | S_IRUGO, show_temp_auto_offset, store_temp_auto_offset, 5, 2);static SENSOR_DEVICE_ATTR_2(temp3_auto_offset7, S_IWUSR | S_IRUGO, show_temp_auto_offset, store_temp_auto_offset, 6, 2);static SENSOR_DEVICE_ATTR_2(temp3_auto_offset8, S_IWUSR | S_IRUGO, show_temp_auto_offset, store_temp_auto_offset, 7, 2);static SENSOR_DEVICE_ATTR_2(temp3_auto_offset9, S_IWUSR | S_IRUGO, show_temp_auto_offset, store_temp_auto_offset, 8, 2);static SENSOR_DEVICE_ATTR_2(temp3_auto_offset10, S_IWUSR | S_IRUGO, show_temp_auto_offset, store_temp_auto_offset, 9, 2);static SENSOR_DEVICE_ATTR_2(temp3_auto_offset11, S_IWUSR | S_IRUGO, show_temp_auto_offset, store_temp_auto_offset, 10, 2);static SENSOR_DEVICE_ATTR_2(temp3_auto_offset12, S_IWUSR | S_IRUGO, show_temp_auto_offset, store_temp_auto_offset, 11, 2);static ssize_t show_temp_auto_pwm_min(struct device *dev, struct device_attribute *attr, char *buf){ int nr = (to_sensor_dev_attr(attr))->index; u8 reg, ctl4; struct lm93_data *data = lm93_update_device(dev); reg = data->auto_pwm_min_hyst[nr/2] >> 4 & 0x0f; ctl4 = data->block9[nr][LM93_PWM_CTL4]; return sprintf(buf,"%d\n",LM93_PWM_FROM_REG(reg, (ctl4 & 0x07) ? LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ));}static ssize_t store_temp_auto_pwm_min(struct device *dev, struct device_attribute *attr, const char *buf, size_t count){ int nr = (to_sensor_dev_attr(attr))->index; struct i2c_client *client = to_i2c_client(dev); struct lm93_data *data = i2c_get_clientdata(client); u32 val = simple_strtoul(buf, NULL, 10); u8 reg, ctl4; mutex_lock(&data->update_lock); reg = lm93_read_byte(client, LM93_REG_PWM_MIN_HYST(nr)); ctl4 = lm93_read_byte(client, LM93_REG_PWM_CTL(nr,LM93_PWM_CTL4)); reg = (reg & 0x0f) | LM93_PWM_TO_REG(val, (ctl4 & 0x07) ? LM93_PWM_MAP_LO_FREQ : LM93_PWM_MAP_HI_FREQ) << 4; data->auto_pwm_min_hyst[nr/2] = reg; lm93_write_byte(client, LM93_REG_PWM_MIN_HYST(nr), reg); mutex_unlock(&data->update_lock); return count;}static SENSOR_DEVICE_ATTR(temp1_auto_pwm_min, S_IWUSR | S_IRUGO, show_temp_auto_pwm_min, store_temp_auto_pwm_min, 0);static SENSOR_DEVICE_ATTR(temp2_auto_pwm_min, S_IWUSR | S_IRUGO, show_temp_auto_pwm_min, store_temp_auto_pwm_min, 1);static SENSOR_DEVICE_ATTR(temp3_auto_pwm_min, S_IWUSR | S_IRUGO, show_temp_auto_pwm_min, store_temp_auto_pwm_min, 2);static ssize_t show_temp_auto_offset_hyst(struct device *dev, struct device_attribute *attr, char *buf){ int nr = (to_sensor_dev_attr(attr))->index; struct lm93_data *data = lm93_update_device(dev); int mode = LM93_TEMP_OFFSET_MODE_FROM_REG(data->sfc2, nr); return sprintf(buf,"%d\n",LM93_TEMP_OFFSET_FROM_REG( data->auto_pwm_min_hyst[nr/2], mode));}static ssize_t store_temp_auto_offset_hyst(struct device *dev, struct device_attribute *attr, const char *buf, size_t count){ int nr = (to_sensor_dev_attr(attr))->index; struct i2c_client *client = to_i2c_client(dev); struct lm93_data *data = i2c_get_clientdata(client); u32 val = simple_strtoul(buf, NULL, 10); u8 reg; mutex_lock(&data->update_lock); /* force 0.5C/bit mode */ data->sfc2 = lm93_read_byte(client, LM93_REG_SFC2); data->sfc2 |= ((nr < 2) ? 0x10 : 0x20); lm93_write_byte(client, LM93_REG_SFC2, data->sfc2); reg = data->auto_pwm_min_hyst[nr/2]; reg = (reg & 0xf0) | (LM93_TEMP_OFFSET_TO_REG(val, 1) & 0x0f); data->auto_pwm_min_hyst[nr/2] = reg; lm93_write_byte(client, LM93_REG_PWM_MIN_HYST(nr), reg); mutex_unlock(&data->update_lock); return count;}static SENSOR_DEVICE_ATTR(temp1_auto_offset_hyst, S_IWUSR | S_IRUGO, show_temp_auto_offset_hyst, store_temp_auto_offset_hyst, 0);static SENSOR_DEVICE_ATTR(temp2_auto_offset_hyst, S_IWUSR | S_IRUGO, show_temp_auto_offset_hyst, store_temp_auto_offset_hyst, 1);static SENSOR_DEVICE_ATTR(temp3_auto_offset_hyst, S_IWUSR | S_IRUGO, show_temp_auto_offset_hyst, store_temp_auto_offset_hyst, 2);static ssize_t show_fan_input(struct device *dev, struct device_attribute *attr, char *buf){ struct sensor_device_attribute *s_attr = to_sensor_dev_attr(attr); int nr = s_attr->index; struct lm93_data *data = lm93_update_device(dev); return sprintf(buf,"%d\n",LM93_FAN_FROM_REG(data->block5[nr]));}static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan_input, NULL, 0);static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan_input, NULL, 1);static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan_input, NULL, 2);static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, show_fan_input, NULL, 3);static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr, char *buf){ int nr = (to_sensor_dev_attr(attr))->index; struct lm93_data *data = lm93_update_device(dev); return sprintf(buf,"%d\n",LM93_FAN_FROM_REG(data->block8[nr]));}static ssize_t store_fan_min(struct device *dev, struct device_attribute *attr, const char *buf, size_t count){ int nr = (to_sensor_dev_attr(attr))->index; struct i2c_client *client = to_i2c_client(dev); struct lm93_data *data = i2c_get_clientdata(client); u32 val = simple_strtoul(buf, NULL, 10); mutex_lock(&data->update_lock); data->block8[nr] = LM93_FAN_TO_REG(val);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?