hwmon: it87: describe per-chip temperature resources
Subsystems (3)
PATCH v3 1/5 hwmon: it87: describe per-chip temperature resources
Add per-chip temp limit/offset/map counts and wire the driver to use them.
This keeps existing chips on the previous defaults while allowing newer chips to advertise larger resources.
--- drivers/hwmon/it87.c | 51 +++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 13 deletions(-)
drivers/hwmon/it87.c +38 -13
@@ -54,6 +54,7 @@#include <linux/hwmon-vid.h> #include <linux/err.h> #include <linux/mutex.h> +#include <linux/minmax.h> #include <linux/sysfs.h> #include <linux/string.h> #include <linux/dmi.h>
@@ -279,8 +280,9 @@ static const u8 IT87_REG_AUTO_BASE[] = { 0x60, 0x68, 0x70, 0x78, 0xa0, 0xa8 };#define NUM_VIN ARRAY_SIZE(IT87_REG_VIN)#define NUM_VIN_LIMIT 8#define NUM_TEMP 6 -#define NUM_TEMP_OFFSET ARRAY_SIZE(IT87_REG_TEMP_OFFSET) -#define NUM_TEMP_LIMIT 3 +#define IT87_TEMP_OFFSET_MAX ARRAY_SIZE(IT87_REG_TEMP_OFFSET) +#define IT87_TEMP_LIMIT_DEFAULT 3 +#define IT87_TEMP_MAP_DEFAULT 3#define NUM_FAN ARRAY_SIZE(IT87_REG_FAN)#define NUM_FAN_DIV 3#define NUM_PWM ARRAY_SIZE(IT87_REG_PWM)
@@ -290,6 +292,9 @@ struct it87_devices {const char *name;const char *const model;u32 features; +u8 num_temp_limit; +u8 num_temp_offset; +u8 num_temp_map;u8 peci_mask;u8 old_peci_mask;u8 smbus_bitmap;/* SMBus enable bits in extra config register */
@@ -578,6 +583,9 @@ struct it87_data {int sioaddr;enum chips type;u32 features; +u8 num_temp_limit; +u8 num_temp_offset; +u8 num_temp_map;u8 peci_mask;u8 old_peci_mask;
@@ -926,12 +934,13 @@ static struct it87_data *it87_update_device(struct device *dev) data->temp[i][0 ] =it87_read_value (data,IT87_REG_TEMP (i)); -if (has_temp_offset (data) && i <NUM_TEMP_OFFSET ) +if (has_temp_offset (data) && + i < data->num_temp_offset) data->temp[i][3 ] =it87_read_value (data,IT87_REG_TEMP_OFFSET [i]); -if (i >=NUM_TEMP_LIMIT ) +if (i >= data->num_temp_limit)continue ; data->temp[i][1] =
@@ -1679,16 +1688,18 @@ static ssize_t show_pwm_temp_map(struct device *dev,struct sensor_device_attribute *sensor_attr =to_sensor_dev_attr (attr);struct it87_data *data =it87_update_device (dev);int nr = sensor_attr->index; +u8 num_map;int map;if (IS_ERR (data))return PTR_ERR (data); + num_map = data->num_temp_map ?:IT87_TEMP_MAP_DEFAULT ; map = data->pwm_temp_map[nr]; -if (map >=3 ) +if (map >= num_map) map =0 ;/* Should never happen */ -if (nr >=3 )/* pwm channels 3..6 map to temp4..6 */ - map +=3 ; +if (nr >= num_map)/* pwm channels 3..6 map to temp4..6 */ + map += num_map;return sprintf (buf,"%d\n" , (int )BIT (map)); }
@@ -1700,6 +1711,7 @@ static ssize_t set_pwm_temp_map(struct device *dev,struct sensor_device_attribute *sensor_attr =to_sensor_dev_attr (attr);struct it87_data *data =dev_get_drvdata (dev);int nr = sensor_attr->index; +u8 num_map = data->num_temp_map ?:IT87_TEMP_MAP_DEFAULT ;long val;int err;u8 reg;
@@ -1707,8 +1719,8 @@ static ssize_t set_pwm_temp_map(struct device *dev,if (kstrtol (buf,10 , &val) <0 )return -EINVAL ; -if (nr >=3 ) - val -=3 ; +if (nr >= num_map) + val -= num_map;switch (val) {case BIT (0 ):
@@ -3206,7 +3218,7 @@ static void it87_check_limit_regs(struct it87_data *data)if (reg ==0xff )it87_write_value (data,IT87_REG_VIN_MIN (i),0 ); } -for (i =0 ; i <NUM_TEMP_LIMIT ; i++) { +for (i =0 ; i < data->num_temp_limit; i++) { reg =it87_read_value (data,IT87_REG_TEMP_HIGH (i));if (reg ==0xff )it87_write_value (data,IT87_REG_TEMP_HIGH (i),127 );
@@ -3399,6 +3411,7 @@ static int it87_probe(struct platform_device *pdev)struct resource *res;struct device *dev = &pdev->dev;struct it87_sio_data *sio_data =dev_get_platdata (dev); +const struct it87_devices *chip;int enable_pwm_interface;struct device *hwmon_dev;int err;
@@ -3421,9 +3434,21 @@ static int it87_probe(struct platform_device *pdev) data->type = sio_data->type; data->smbus_bitmap = sio_data->smbus_bitmap; data->ec_special_config = sio_data->ec_special_config; - data->features = it87_devices[sio_data->type].features; - data->peci_mask = it87_devices[sio_data->type].peci_mask; - data->old_peci_mask = it87_devices[sio_data->type].old_peci_mask; + chip = &it87_devices[sio_data->type]; + data->features = chip->features; + data->peci_mask = chip->peci_mask; + data->old_peci_mask = chip->old_peci_mask; + data->num_temp_limit = chip->num_temp_limit ? + chip->num_temp_limit :IT87_TEMP_LIMIT_DEFAULT ; +if (chip->num_temp_offset) + data->num_temp_offset =min (chip->num_temp_offset, + (u8 )IT87_TEMP_OFFSET_MAX ); +else if (has_temp_offset (data)) + data->num_temp_offset =IT87_TEMP_OFFSET_MAX ; +else + data->num_temp_offset =0 ; + data->num_temp_map = chip->num_temp_map ? + chip->num_temp_map :IT87_TEMP_MAP_DEFAULT ;/* * IT8705F Datasheet 0.4.1, 3h == Version G. * IT8712F Datasheet 0.9.1, section 8.3.5 indicates 8h == Version J.
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH v3 2/5 hwmon: it87: prepare for extended PWM temp maps
Introduce helper logic for PWM-to-temperature mappings so newer register layouts can be supported without affecting legacy chips.
--- drivers/hwmon/it87.c | 178 ++++++++++++++++++++++++++++++++----------- 1 file changed, 133 insertions(+), 45 deletions(-)
drivers/hwmon/it87.c +133 -45
@@ -251,6 +251,7 @@ static const u8 IT87_REG_TEMP_OFFSET[] = { 0x56, 0x57, 0x59 };#define IT87_REG_FAN_MAIN_CTRL 0x13#define IT87_REG_FAN_CTL 0x14static const u8 IT87_REG_PWM [] = {0x15 ,0x16 ,0x17 ,0x7f ,0xa7 ,0xaf }; +static const u8 IT87_REG_PWM_8665 [] = {0x15 ,0x16 ,0x17 ,0x1e ,0x1f ,0x92 };static const u8 IT87_REG_PWM_DUTY [] = {0x63 ,0x6b ,0x73 ,0x7b ,0xa3 ,0xab };static const u8 IT87_REG_VIN [] = {0x20 ,0x21 ,0x22 ,0x23 ,0x24 ,0x25 ,0x26 ,
@@ -283,6 +284,7 @@ static const u8 IT87_REG_AUTO_BASE[] = { 0x60, 0x68, 0x70, 0x78, 0xa0, 0xa8 };#define IT87_TEMP_OFFSET_MAX ARRAY_SIZE(IT87_REG_TEMP_OFFSET)#define IT87_TEMP_LIMIT_DEFAULT 3#define IT87_TEMP_MAP_DEFAULT 3 +#define IT87_PWM_OLD_NUM_TEMP 3#define NUM_FAN ARRAY_SIZE(IT87_REG_FAN)#define NUM_FAN_DIV 3#define NUM_PWM ARRAY_SIZE(IT87_REG_PWM)
@@ -331,6 +333,7 @@ struct it87_devices {#define FEAT_FOUR_PWM BIT(21)/* Supports four fan controls */ #define FEAT_FOUR_TEMP BIT(22)#define FEAT_FANCTL_ONOFF BIT(23)/* chip has FAN_CTL ON/OFF */ +#define FEAT_NEW_TEMPMAP BIT(24)/* PWM uses extended temp map */ static const struct it87_devices it87_devices[] = { [it87] = {
@@ -554,6 +557,7 @@ static const struct it87_devices it87_devices[] = {#define has_scaling (data) ((data)->features & (FEAT_12MV_ADC | \ FEAT_10_9MV_ADC))#define has_fanctl_onoff (data) ((data)->features & FEAT_FANCTL_ONOFF) +#define has_new_tempmap (data) ((data)->features & FEAT_NEW_TEMPMAP)struct it87_sio_data {int sioaddr;
@@ -632,7 +636,9 @@ struct it87_data {u8 has_pwm;/* Bitfield, pwm control enabled */ u8 pwm_ctrl[NUM_PWM ];/* Register value */ u8 pwm_duty[NUM_PWM ];/* Manual PWM value set by user */ -u8 pwm_temp_map[NUM_PWM ];/* PWM to temp. chan. mapping (bits 1-0) */ +u8 pwm_temp_map[NUM_PWM ];/* PWM to temp. chan. mapping */ +u8 pwm_temp_map_mask; +u8 pwm_temp_map_shift;/* Automatic fan speed control registers */ u8 auto_pwm[NUM_AUTO_PWM ][4 ];/* [nr][3] is hard-coded */
@@ -714,6 +720,72 @@ static int pwm_from_reg(const struct it87_data *data, u8 reg)return (reg &0x7f ) <<1 ; } +static inline u8 pwm_temp_map_get (const struct it87_data *data,u8 ctrl) +{ +return (ctrl >> data->pwm_temp_map_shift) & + data->pwm_temp_map_mask; +} + +static inline u8 pwm_temp_map_set (const struct it87_data *data,u8 ctrl, +u8 map) +{ + ctrl &= ~(data->pwm_temp_map_mask << data->pwm_temp_map_shift); +return ctrl | ((map & data->pwm_temp_map_mask) + << data->pwm_temp_map_shift); +} + +static inline u8 pwm_num_temp_map (const struct it87_data *data) +{ +return data->num_temp_map ? data->num_temp_map : +IT87_TEMP_MAP_DEFAULT ; +} + +static unsigned int pwm_temp_channel (const struct it87_data *data, +int nr,u8 map) +{ +if (has_new_tempmap (data)) { +u8 num =pwm_num_temp_map (data); + +if (map >= num) + map =0 ; +return map; + } + +if (map >=IT87_PWM_OLD_NUM_TEMP ) + map =0 ; + +if (nr >=IT87_PWM_OLD_NUM_TEMP ) + map +=IT87_PWM_OLD_NUM_TEMP ; + +return map; +} + +static int pwm_temp_map_from_channel (const struct it87_data *data,int nr, +unsigned int channel,u8 *map) +{ +if (has_new_tempmap (data)) { +u8 num =pwm_num_temp_map (data); + +if (channel >= num) +return -EINVAL ; + *map = channel; +return 0 ; + } + +if (nr >=IT87_PWM_OLD_NUM_TEMP ) { +if (channel <IT87_PWM_OLD_NUM_TEMP || + channel >=2 *IT87_PWM_OLD_NUM_TEMP ) +return -EINVAL ; + channel -=IT87_PWM_OLD_NUM_TEMP ; + }else { +if (channel >=IT87_PWM_OLD_NUM_TEMP ) +return -EINVAL ; + } + + *map = channel; +return 0 ; +} +static int DIV_TO_REG (int val) {int answer =0 ;
@@ -725,6 +797,14 @@ static int DIV_TO_REG(int val)#define DIV_FROM_REG (val) BIT(val) +static inline u16 it87_reg_pwm (const struct it87_data *data,int nr) +{ +if (data->type == it8613 || data->type == it8622) +return IT87_REG_PWM_8665 [nr]; + +return IT87_REG_PWM [nr]; +} +/* * PWM base frequencies. The frequency has to be divided by either 128 or 256, * depending on the chip type, to calculate the actual PWM frequency.
@@ -805,14 +885,22 @@ static void it87_write_value(struct it87_data *data, u8 reg, u8 value)static void it87_update_pwm_ctrl (struct it87_data *data,int nr) { - data->pwm_ctrl[nr] =it87_read_value (data,IT87_REG_PWM [nr]); + data->pwm_ctrl[nr] =it87_read_value (data,it87_reg_pwm (data, nr));if (has_newer_autopwm (data)) { - data->pwm_temp_map[nr] = data->pwm_ctrl[nr] &0x03 ; + data->pwm_temp_map[nr] = +pwm_temp_map_get (data, data->pwm_ctrl[nr]); +if (has_new_tempmap (data) && + data->pwm_temp_map[nr] >=pwm_num_temp_map (data)) + data->pwm_temp_map[nr] =0 ; data->pwm_duty[nr] =it87_read_value (data,IT87_REG_PWM_DUTY [nr]); }else {if (data->pwm_ctrl[nr] &0x80 )/* Automatic mode */ - data->pwm_temp_map[nr] = data->pwm_ctrl[nr] &0x03 ; + data->pwm_temp_map[nr] = +pwm_temp_map_get (data, data->pwm_ctrl[nr]); +if (has_new_tempmap (data) && + data->pwm_temp_map[nr] >=pwm_num_temp_map (data)) + data->pwm_temp_map[nr] =0 ;else /* Manual mode */ data->pwm_duty[nr] = data->pwm_ctrl[nr] &0x7f ; }
@@ -1543,6 +1631,8 @@ static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr,if (err)return err; +it87_update_pwm_ctrl (data, nr); +if (val ==0 ) {if (nr <3 &&has_fanctl_onoff (data)) {int tmp;
@@ -1562,27 +1652,30 @@ static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr, data->pwm_duty[nr]);/* and set manual mode */ if (has_newer_autopwm (data)) { - ctrl = (data->pwm_ctrl[nr] &0x7c ) | - data->pwm_temp_map[nr]; + ctrl =pwm_temp_map_set (data, + data->pwm_ctrl[nr] & + ~0x80 , + data->pwm_temp_map[nr]); }else { ctrl = data->pwm_duty[nr]; } data->pwm_ctrl[nr] = ctrl; -it87_write_value (data,IT87_REG_PWM [nr], ctrl); +it87_write_value (data,it87_reg_pwm (data, nr), ctrl); } }else {u8 ctrl;if (has_newer_autopwm (data)) { - ctrl = (data->pwm_ctrl[nr] &0x7c ) | - data->pwm_temp_map[nr]; + ctrl =pwm_temp_map_set (data, + data->pwm_ctrl[nr] & ~0x80 , + data->pwm_temp_map[nr]);if (val !=1 ) ctrl |=0x80 ; }else { ctrl = (val ==1 ? data->pwm_duty[nr] :0x80 ); } data->pwm_ctrl[nr] = ctrl; -it87_write_value (data,IT87_REG_PWM [nr], ctrl); +it87_write_value (data,it87_reg_pwm (data, nr), ctrl);if (has_fanctl_onoff (data) && nr <3 ) {/* set SmartGuardian mode */
@@ -1633,7 +1726,7 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,*/ if (!(data->pwm_ctrl[nr] &0x80 )) { data->pwm_ctrl[nr] = data->pwm_duty[nr]; -it87_write_value (data,IT87_REG_PWM [nr], +it87_write_value (data,it87_reg_pwm (data, nr), data->pwm_ctrl[nr]); } }
@@ -1688,20 +1781,14 @@ static ssize_t show_pwm_temp_map(struct device *dev,struct sensor_device_attribute *sensor_attr =to_sensor_dev_attr (attr);struct it87_data *data =it87_update_device (dev);int nr = sensor_attr->index; -u8 num_map; -int map; +unsigned int channel;if (IS_ERR (data))return PTR_ERR (data); - num_map = data->num_temp_map ?:IT87_TEMP_MAP_DEFAULT ; - map = data->pwm_temp_map[nr]; -if (map >= num_map) - map =0 ;/* Should never happen */ -if (nr >= num_map)/* pwm channels 3..6 map to temp4..6 */ - map += num_map; + channel =pwm_temp_channel (data, nr, data->pwm_temp_map[nr]); -return sprintf (buf,"%d\n" , (int )BIT (map)); +return sprintf (buf,"%d\n" , (int )BIT (channel)); } static ssize_t set_pwm_temp_map(struct device *dev,
@@ -1711,45 +1798,34 @@ static ssize_t set_pwm_temp_map(struct device *dev,struct sensor_device_attribute *sensor_attr =to_sensor_dev_attr (attr);struct it87_data *data =dev_get_drvdata (dev);int nr = sensor_attr->index; -u8 num_map = data->num_temp_map ?:IT87_TEMP_MAP_DEFAULT ;long val;int err; -u8 reg; +unsigned int channel; +u8 map; -if (kstrtol (buf,10 , &val) <0 ) +if (kstrtol (buf,10 , &val) <0 || val <=0 || !is_power_of_2 (val))return -EINVAL ; -if (nr >= num_map) - val -= num_map; - -switch (val) { -case BIT (0 ): - reg =0x00 ; -break ; -case BIT (1 ): - reg =0x01 ; -break ; -case BIT (2 ): - reg =0x02 ; -break ; -default : + channel =__ffs (val); +if (pwm_temp_map_from_channel (data, nr, channel, &map))return -EINVAL ; - } err =it87_lock (data);if (err)return err;it87_update_pwm_ctrl (data, nr); - data->pwm_temp_map[nr] = reg; + data->pwm_temp_map[nr] = map;/* * If we are in automatic mode, write the temp mapping immediately; * otherwise, just store it for later use. */ if (data->pwm_ctrl[nr] &0x80 ) { - data->pwm_ctrl[nr] = (data->pwm_ctrl[nr] &0xfc ) | - data->pwm_temp_map[nr]; -it87_write_value (data,IT87_REG_PWM [nr], data->pwm_ctrl[nr]); + data->pwm_ctrl[nr] =pwm_temp_map_set (data, + data->pwm_ctrl[nr], + data->pwm_temp_map[nr]); +it87_write_value (data,it87_reg_pwm (data, nr), + data->pwm_ctrl[nr]); }it87_unlock (data);return count;
@@ -3300,7 +3376,10 @@ static void it87_init_device(struct platform_device *pdev)* manual duty cycle. */ for (i =0 ; i <NUM_AUTO_PWM ; i++) { - data->pwm_temp_map[i] = i; +if (has_new_tempmap (data)) + data->pwm_temp_map[i] =0 ; +else + data->pwm_temp_map[i] = i %IT87_PWM_OLD_NUM_TEMP ; data->pwm_duty[i] =0x7f ;/* Full speed */ data->auto_pwm[i][3 ] =0x7f ;/* Full speed, hard-coded */ }
@@ -3372,7 +3451,8 @@ static int it87_check_pwm(struct device *dev)for (i =0 ; i <ARRAY_SIZE (pwm); i++) pwm[i] =it87_read_value (data, -IT87_REG_PWM [i]); +it87_reg_pwm (data, + i));/* * If any fan is in automatic pwm mode, the polarity
@@ -3387,7 +3467,8 @@ static int it87_check_pwm(struct device *dev) tmp | 0x87);for (i =0 ; i <3 ; i++)it87_write_value (data, -IT87_REG_PWM [i], +it87_reg_pwm (data, + i),0x7f & ~pwm[i]);return 1 ; }
@@ -3449,6 +3530,13 @@ static int it87_probe(struct platform_device *pdev) data->num_temp_offset =0 ; data->num_temp_map = chip->num_temp_map ? chip->num_temp_map :IT87_TEMP_MAP_DEFAULT ; +if (has_new_tempmap (data)) { + data->pwm_temp_map_mask =0x07 ; + data->pwm_temp_map_shift =3 ; + }else { + data->pwm_temp_map_mask =0x03 ; + data->pwm_temp_map_shift =0 ; + }/* * IT8705F Datasheet 0.4.1, 3h == Version G. * IT8712F Datasheet 0.9.1, section 8.3.5 indicates 8h == Version J.
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH v3 3/5 hwmon: it87: expose additional temperature limits
In reply to benoit.massonExpose extra temp min/max/offset/type/alarm attributes when a chip reports more than three temperature resources.
--- drivers/hwmon/it87.c | 60 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 6 deletions(-)
drivers/hwmon/it87.c +54 -6
@@ -1258,8 +1258,26 @@ static SENSOR_DEVICE_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp, set_temp, static SENSOR_DEVICE_ATTR_2(temp3_offset, S_IRUGO | S_IWUSR, show_temp, set_temp, 2, 3); static SENSOR_DEVICE_ATTR_2(temp4_input, S_IRUGO, show_temp, NULL, 3, 0); +static SENSOR_DEVICE_ATTR_2(temp4_min, S_IRUGO | S_IWUSR, show_temp, set_temp, + 3, 1); +static SENSOR_DEVICE_ATTR_2(temp4_max, S_IRUGO | S_IWUSR, show_temp, set_temp, + 3, 2); +static SENSOR_DEVICE_ATTR_2(temp4_offset, S_IRUGO | S_IWUSR, show_temp, + set_temp, 3, 3); static SENSOR_DEVICE_ATTR_2(temp5_input, S_IRUGO, show_temp, NULL, 4, 0); +static SENSOR_DEVICE_ATTR_2(temp5_min, S_IRUGO | S_IWUSR, show_temp, set_temp, + 4, 1); +static SENSOR_DEVICE_ATTR_2(temp5_max, S_IRUGO | S_IWUSR, show_temp, set_temp, + 4, 2); +static SENSOR_DEVICE_ATTR_2(temp5_offset, S_IRUGO | S_IWUSR, show_temp, + set_temp, 4, 3); static SENSOR_DEVICE_ATTR_2(temp6_input, S_IRUGO, show_temp, NULL, 5, 0); +static SENSOR_DEVICE_ATTR_2(temp6_min, S_IRUGO | S_IWUSR, show_temp, set_temp, + 5, 1); +static SENSOR_DEVICE_ATTR_2(temp6_max, S_IRUGO | S_IWUSR, show_temp, set_temp, + 5, 2); +static SENSOR_DEVICE_ATTR_2(temp6_offset, S_IRUGO | S_IWUSR, show_temp, + set_temp, 5, 3);static int get_temp_type (struct it87_data *data,int index) {
@@ -1385,6 +1403,12 @@ static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO | S_IWUSR, show_temp_type, set_temp_type, 1); static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR, show_temp_type, set_temp_type, 2); +static SENSOR_DEVICE_ATTR(temp4_type, S_IRUGO | S_IWUSR, show_temp_type, + set_temp_type, 3); +static SENSOR_DEVICE_ATTR(temp5_type, S_IRUGO | S_IWUSR, show_temp_type, + set_temp_type, 4); +static SENSOR_DEVICE_ATTR(temp6_type, S_IRUGO | S_IWUSR, show_temp_type, + set_temp_type, 5);/* 6 Fans */
@@ -2214,6 +2238,9 @@ static SENSOR_DEVICE_ATTR(fan6_alarm, S_IRUGO, show_alarm, NULL, 7); static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 16); static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 17); static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 18); +static SENSOR_DEVICE_ATTR(temp4_alarm, S_IRUGO, show_alarm, NULL, 19); +static SENSOR_DEVICE_ATTR(temp5_alarm, S_IRUGO, show_alarm, NULL, 20); +static SENSOR_DEVICE_ATTR(temp6_alarm, S_IRUGO, show_alarm, NULL, 21); static SENSOR_DEVICE_ATTR(intrusion0_alarm, S_IRUGO | S_IWUSR, show_alarm, clear_intrusion, 4);
@@ -2274,6 +2301,9 @@ static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR, show_beep, set_beep, 2); static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO, show_beep, NULL, 2); static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO, show_beep, NULL, 2); +static SENSOR_DEVICE_ATTR(temp4_beep, S_IRUGO, show_beep, NULL, 2); +static SENSOR_DEVICE_ATTR(temp5_beep, S_IRUGO, show_beep, NULL, 2); +static SENSOR_DEVICE_ATTR(temp6_beep, S_IRUGO, show_beep, NULL, 2);static ssize_t vrm_show (struct device *dev,struct device_attribute *attr,char *buf)
@@ -2436,21 +2466,19 @@ static umode_t it87_temp_is_visible(struct kobject *kobj,int i = index /7 ;/* temperature index */ int a = index %7 ;/* attribute index */ -if (index >=21 ) { - i = index -21 +3 ; - a =0 ; - } -if (!(data->has_temp &BIT (i)))return 0 ; +if (a && i >= data->num_temp_limit) +return 0 ; +if (a ==3 ) {if (get_temp_type (data, i) ==0 )return 0 ;return attr->mode; } -if (a ==5 && !has_temp_offset (data)) +if (a ==5 && i >= data->num_temp_offset)return 0 ;if (a ==6 && !data->has_beep)
@@ -2485,8 +2513,28 @@ static struct attribute *it87_attributes_temp[] = { &sensor_dev_attr_temp3_beep.dev_attr.attr, &sensor_dev_attr_temp4_input.dev_attr.attr,/* 21 */ + &sensor_dev_attr_temp4_max.dev_attr.attr, + &sensor_dev_attr_temp4_min.dev_attr.attr, + &sensor_dev_attr_temp4_type.dev_attr.attr, + &sensor_dev_attr_temp4_alarm.dev_attr.attr, + &sensor_dev_attr_temp4_offset.dev_attr.attr, + &sensor_dev_attr_temp4_beep.dev_attr.attr, + &sensor_dev_attr_temp5_input.dev_attr.attr, + &sensor_dev_attr_temp5_max.dev_attr.attr, + &sensor_dev_attr_temp5_min.dev_attr.attr, + &sensor_dev_attr_temp5_type.dev_attr.attr, + &sensor_dev_attr_temp5_alarm.dev_attr.attr, + &sensor_dev_attr_temp5_offset.dev_attr.attr, + &sensor_dev_attr_temp5_beep.dev_attr.attr, + &sensor_dev_attr_temp6_input.dev_attr.attr, + &sensor_dev_attr_temp6_max.dev_attr.attr, + &sensor_dev_attr_temp6_min.dev_attr.attr, + &sensor_dev_attr_temp6_type.dev_attr.attr, + &sensor_dev_attr_temp6_alarm.dev_attr.attr, + &sensor_dev_attr_temp6_offset.dev_attr.attr, + &sensor_dev_attr_temp6_beep.dev_attr.attr,NULL };
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH v3 4/5 hwmon: it87: add IT8613E identification
In reply to benoit.massonTeach the Super I/O probe path to recognize IT8613E and advertise its model name in the supported device list.
--- drivers/hwmon/it87.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/hwmon/it87.c +10 -1
@@ -35,6 +35,7 @@* IT8790E Super I/O chip w/LPC interface * IT8792E Super I/O chip w/LPC interface * IT87952E Super I/O chip w/LPC interface +* IT8613E Super I/O chip w/LPC interface * Sis950 A clone of the IT8705F * * Copyright (C) 2001 Chris Gauthron
@@ -65,7 +66,7 @@enum chips { it87, it8712, it8716, it8718, it8720, it8721, it8728, it8732, it8771, it8772, it8781, it8782, it8783, it8786, it8790, - it8792, it8603, it8620, it8622, it8628, it87952 }; + it8792, it8603, it8613, it8620, it8622, it8628, it87952 };static struct platform_device *it87_pdev[2 ];
@@ -159,6 +160,7 @@ static inline void superio_exit(int ioreg, bool noexit)#define IT8786E_DEVID 0x8786#define IT8790E_DEVID 0x8790#define IT8603E_DEVID 0x8603 +#define IT8613E_DEVID 0x8613#define IT8620E_DEVID 0x8620#define IT8622E_DEVID 0x8622#define IT8623E_DEVID 0x8623
@@ -482,6 +484,10 @@ static const struct it87_devices it87_devices[] = { | FEAT_AVCC3 | FEAT_PWM_FREQ2, .peci_mask = 0x07, }, + [it8613] = { + .name = "it8613", + .model = "IT8613E", + }, [it8620] = { .name = "it8620", .model = "IT8620E",
@@ -2912,6 +2918,9 @@ static int __init it87_find(int sioaddr, unsigned short *address,case IT8623E_DEVID : sio_data->type = it8603;break ; +case IT8613E_DEVID : + sio_data->type = it8613; +break ;case IT8620E_DEVID : sio_data->type = it8620;break ;
Signature · 1 line
2.50.1 (Apple Git-155)
PATCH v3 5/5 hwmon: it87: add IT8613E configuration
In reply to benoit.massonAdd IT8613E feature flags, resource counts, ADC scaling, and GPIO quirk handling, then document the chip in the hwmon guide.
--- Documentation/hwmon/it87.rst | 8 ++++++ drivers/hwmon/it87.c | 52 +++++++++++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 1 deletion(-)
Documentation/hwmon/it87.rst +8 -0
@@ -11,6 +11,14 @@ Supported chips: Datasheet: Not publicly available + * IT8613E + + Prefix: 'it8613' + + Addresses scanned: from Super I/O config space (8 I/O ports) + + Datasheet: Not publicly available + * IT8620E Prefix: 'it8620'
drivers/hwmon/it87.c +51 -1
88 lines not on this page · raw message
Signature · 1 line
2.50.1 (Apple Git-155)
Guenter Roeck
maintainerQuoted 24 lines · benoit.masson
Add per-chip temp limit/offset/map counts and wire the driver to use them.
This keeps existing chips on the previous defaults while allowing newer chips to advertise larger resources.
Signed-off-by benoit.masson <[email protected]>--- drivers/hwmon/it87.c | 51 +++++++++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 13 deletions(-)drivers/hwmon/it87.c +1
-0@@ -54,6 +54,7 @@#include <linux/hwmon-vid.h> #include <linux/err.h> #include <linux/mutex.h> +#include <linux/minmax.h> #include <linux/sysfs.h> #include <linux/string.h> #include <linux/dmi.h>
drivers/hwmon/it87.c static const u8 IT87_REG_AUTO_BASE[] = { 0x60, 0x68, 0x70, 0x78, 0xa0, 0xa8 }; · line 285
Quoted 8 lines
drivers/hwmon/it87.c +3
-2@@ -279,8 +280,9 @@ static const u8 IT87_REG_AUTO_BASE[] = { 0x60, 0x68, 0x70, 0x78, 0xa0, 0xa8 };#define NUM_VIN ARRAY_SIZE(IT87_REG_VIN)#define NUM_VIN_LIMIT 8#define NUM_TEMP 6 -#define NUM_TEMP_OFFSET ARRAY_SIZE(IT87_REG_TEMP_OFFSET) -#define NUM_TEMP_LIMIT 3 +#define IT87_TEMP_OFFSET_MAX ARRAY_SIZE(IT87_REG_TEMP_OFFSET) +#define IT87_TEMP_LIMIT_DEFAULT 3 +#define IT87_TEMP_MAP_DEFAULT 3
Adding IT87_ prefixes here is unnecessary and inconsistent.
_DEFAULT defines are unnecessary. num_temp_limit, num_temp_offset, and num_temp_map should be added to all configuration entries. With this, FEAT_TEMP_OFFSET and has_temp_offset() are unnecessary and can be dropped since support is implicit with num_temp_offset > 0.
Quoted 109 lines
drivers/hwmon/it87.c +24
-11#define NUM_FAN ARRAY_SIZE(IT87_REG_FAN)#define NUM_FAN_DIV 3#define NUM_PWM ARRAY_SIZE(IT87_REG_PWM)@@ -290,6 +292,9 @@ struct it87_devices {const char *name;const char *const model;u32 features; +u8 num_temp_limit; +u8 num_temp_offset; +u8 num_temp_map;u8 peci_mask;u8 old_peci_mask;u8 smbus_bitmap;/* SMBus enable bits in extra config register */ @@ -578,6 +583,9 @@ struct it87_data {int sioaddr;enum chips type;u32 features; +u8 num_temp_limit; +u8 num_temp_offset; +u8 num_temp_map;u8 peci_mask;u8 old_peci_mask;@@ -926,12 +934,13 @@ static struct it87_data *it87_update_device(struct device *dev) data->temp[i][0 ] =it87_read_value (data,IT87_REG_TEMP (i)); -if (has_temp_offset (data) && i <NUM_TEMP_OFFSET ) +if (has_temp_offset (data) && + i < data->num_temp_offset) data->temp[i][3 ] =it87_read_value (data,IT87_REG_TEMP_OFFSET [i]); -if (i >=NUM_TEMP_LIMIT ) +if (i >= data->num_temp_limit)continue ; data->temp[i][1] =@@ -1679,16 +1688,18 @@ static ssize_t show_pwm_temp_map(struct device *dev,struct sensor_device_attribute *sensor_attr =to_sensor_dev_attr (attr);struct it87_data *data =it87_update_device (dev);int nr = sensor_attr->index; +u8 num_map;int map;if (IS_ERR (data))return PTR_ERR (data); + num_map = data->num_temp_map ?:IT87_TEMP_MAP_DEFAULT ; map = data->pwm_temp_map[nr]; -if (map >=3 ) +if (map >= num_map) map =0 ;/* Should never happen */ -if (nr >=3 )/* pwm channels 3..6 map to temp4..6 */ - map +=3 ; +if (nr >= num_map)/* pwm channels 3..6 map to temp4..6 */ + map += num_map;return sprintf (buf,"%d\n" , (int )BIT (map)); }@@ -1700,6 +1711,7 @@ static ssize_t set_pwm_temp_map(struct device *dev,struct sensor_device_attribute *sensor_attr =to_sensor_dev_attr (attr);struct it87_data *data =dev_get_drvdata (dev);int nr = sensor_attr->index; +u8 num_map = data->num_temp_map ?:IT87_TEMP_MAP_DEFAULT ;long val;int err;u8 reg;@@ -1707,8 +1719,8 @@ static ssize_t set_pwm_temp_map(struct device *dev,if (kstrtol (buf,10 , &val) <0 )return -EINVAL ; -if (nr >=3 ) - val -=3 ; +if (nr >= num_map) + val -= num_map;switch (val) {case BIT (0 ):@@ -3206,7 +3218,7 @@ static void it87_check_limit_regs(struct it87_data *data)if (reg ==0xff )it87_write_value (data,IT87_REG_VIN_MIN (i),0 ); } -for (i =0 ; i <NUM_TEMP_LIMIT ; i++) { +for (i =0 ; i < data->num_temp_limit; i++) { reg =it87_read_value (data,IT87_REG_TEMP_HIGH (i));if (reg ==0xff )it87_write_value (data,IT87_REG_TEMP_HIGH (i),127 );@@ -3399,6 +3411,7 @@ static int it87_probe(struct platform_device *pdev)struct resource *res;struct device *dev = &pdev->dev;struct it87_sio_data *sio_data =dev_get_platdata (dev); +const struct it87_devices *chip;int enable_pwm_interface;struct device *hwmon_dev;int err;@@ -3421,9 +3434,21 @@ static int it87_probe(struct platform_device *pdev) data->type = sio_data->type; data->smbus_bitmap = sio_data->smbus_bitmap; data->ec_special_config = sio_data->ec_special_config; - data->features = it87_devices[sio_data->type].features; - data->peci_mask = it87_devices[sio_data->type].peci_mask; - data->old_peci_mask = it87_devices[sio_data->type].old_peci_mask; + chip = &it87_devices[sio_data->type]; + data->features = chip->features; + data->peci_mask = chip->peci_mask; + data->old_peci_mask = chip->old_peci_mask; + data->num_temp_limit = chip->num_temp_limit ?
drivers/hwmon/it87.c static int it87_probe(struct platform_device *pdev) · line 3451
Quoted 10 lines
drivers/hwmon/it87.c +10
-0+ chip->num_temp_limit : IT87_TEMP_LIMIT_DEFAULT; +if (chip->num_temp_offset) + data->num_temp_offset =min (chip->num_temp_offset, + (u8 )IT87_TEMP_OFFSET_MAX ); +else if (has_temp_offset (data)) + data->num_temp_offset =IT87_TEMP_OFFSET_MAX ; +else + data->num_temp_offset =0 ; + data->num_temp_map = chip->num_temp_map ? + chip->num_temp_map :IT87_TEMP_MAP_DEFAULT ;
Runtime checks of build parameters are unacceptable and, again, all fields should be initialized correctly in the configuration data. That is what it is for. Runtime updates such as the above are both unnecessary and unacceptable. num_temp_limit, num_temp_map and num_temp_offset are available in the configuration data. Enter the data there and use it.
Thanks,
Guenter
Guenter Roeck
maintainerRe: [PATCH v3 2/5] hwmon: it87: prepare for extended PWM temp maps
In reply to benoit.massonQuoted 129 lines · benoit.masson
Introduce helper logic for PWM-to-temperature mappings so newer register layouts can be supported without affecting legacy chips.
Signed-off-by benoit.masson <[email protected]>--- drivers/hwmon/it87.c | 178 ++++++++++++++++++++++++++++++++----------- 1 file changed, 133 insertions(+), 45 deletions(-)drivers/hwmon/it87.c +73
-1@@ -251,6 +251,7 @@ static const u8 IT87_REG_TEMP_OFFSET[] = { 0x56, 0x57, 0x59 };#define IT87_REG_FAN_MAIN_CTRL 0x13#define IT87_REG_FAN_CTL 0x14static const u8 IT87_REG_PWM [] = {0x15 ,0x16 ,0x17 ,0x7f ,0xa7 ,0xaf }; +static const u8 IT87_REG_PWM_8665 [] = {0x15 ,0x16 ,0x17 ,0x1e ,0x1f ,0x92 };static const u8 IT87_REG_PWM_DUTY [] = {0x63 ,0x6b ,0x73 ,0x7b ,0xa3 ,0xab };static const u8 IT87_REG_VIN [] = {0x20 ,0x21 ,0x22 ,0x23 ,0x24 ,0x25 ,0x26 ,@@ -283,6 +284,7 @@ static const u8 IT87_REG_AUTO_BASE[] = { 0x60, 0x68, 0x70, 0x78, 0xa0, 0xa8 };#define IT87_TEMP_OFFSET_MAX ARRAY_SIZE(IT87_REG_TEMP_OFFSET)#define IT87_TEMP_LIMIT_DEFAULT 3#define IT87_TEMP_MAP_DEFAULT 3 +#define IT87_PWM_OLD_NUM_TEMP 3#define NUM_FAN ARRAY_SIZE(IT87_REG_FAN)#define NUM_FAN_DIV 3#define NUM_PWM ARRAY_SIZE(IT87_REG_PWM)@@ -331,6 +333,7 @@ struct it87_devices {#define FEAT_FOUR_PWM BIT(21)/* Supports four fan controls */ #define FEAT_FOUR_TEMP BIT(22)#define FEAT_FANCTL_ONOFF BIT(23)/* chip has FAN_CTL ON/OFF */ +#define FEAT_NEW_TEMPMAP BIT(24)/* PWM uses extended temp map */ static const struct it87_devices it87_devices[] = { [it87] = {@@ -554,6 +557,7 @@ static const struct it87_devices it87_devices[] = {#define has_scaling (data) ((data)->features & (FEAT_12MV_ADC | \ FEAT_10_9MV_ADC))#define has_fanctl_onoff (data) ((data)->features & FEAT_FANCTL_ONOFF) +#define has_new_tempmap (data) ((data)->features & FEAT_NEW_TEMPMAP)struct it87_sio_data {int sioaddr;@@ -632,7 +636,9 @@ struct it87_data {u8 has_pwm;/* Bitfield, pwm control enabled */ u8 pwm_ctrl[NUM_PWM ];/* Register value */ u8 pwm_duty[NUM_PWM ];/* Manual PWM value set by user */ -u8 pwm_temp_map[NUM_PWM ];/* PWM to temp. chan. mapping (bits 1-0) */ +u8 pwm_temp_map[NUM_PWM ];/* PWM to temp. chan. mapping */ +u8 pwm_temp_map_mask; +u8 pwm_temp_map_shift;/* Automatic fan speed control registers */ u8 auto_pwm[NUM_AUTO_PWM ][4 ];/* [nr][3] is hard-coded */ @@ -714,6 +720,72 @@ static int pwm_from_reg(const struct it87_data *data, u8 reg)return (reg &0x7f ) <<1 ; } +static inline u8 pwm_temp_map_get (const struct it87_data *data,u8 ctrl) +{ +return (ctrl >> data->pwm_temp_map_shift) & + data->pwm_temp_map_mask; +} + +static inline u8 pwm_temp_map_set (const struct it87_data *data,u8 ctrl, +u8 map) +{ + ctrl &= ~(data->pwm_temp_map_mask << data->pwm_temp_map_shift); +return ctrl | ((map & data->pwm_temp_map_mask) + << data->pwm_temp_map_shift); +} + +static inline u8 pwm_num_temp_map (const struct it87_data *data) +{ +return data->num_temp_map ? data->num_temp_map : +IT87_TEMP_MAP_DEFAULT ; +} + +static unsigned int pwm_temp_channel (const struct it87_data *data, +int nr,u8 map) +{ +if (has_new_tempmap (data)) { +u8 num =pwm_num_temp_map (data); + +if (map >= num) + map =0 ; +return map; + } + +if (map >=IT87_PWM_OLD_NUM_TEMP ) + map =0 ; + +if (nr >=IT87_PWM_OLD_NUM_TEMP ) + map +=IT87_PWM_OLD_NUM_TEMP ; + +return map; +} + +static int pwm_temp_map_from_channel (const struct it87_data *data,int nr, +unsigned int channel,u8 *map) +{ +if (has_new_tempmap (data)) { +u8 num =pwm_num_temp_map (data); + +if (channel >= num) +return -EINVAL ; + *map = channel; +return 0 ; + } + +if (nr >=IT87_PWM_OLD_NUM_TEMP ) { +if (channel <IT87_PWM_OLD_NUM_TEMP || + channel >=2 *IT87_PWM_OLD_NUM_TEMP ) +return -EINVAL ; + channel -=IT87_PWM_OLD_NUM_TEMP ; + }else { +if (channel >=IT87_PWM_OLD_NUM_TEMP ) +return -EINVAL ; + } + + *map = channel; +return 0 ; +} +static int DIV_TO_REG (int val) {int answer =0 ;
drivers/hwmon/it87.c static int DIV_TO_REG(int val) · line 802
Quoted 6 lines
drivers/hwmon/it87.c +3
-0@@ -725,6 +797,14 @@ static int DIV_TO_REG(int val)#define DIV_FROM_REG (val) BIT(val) +static inline u16 it87_reg_pwm (const struct it87_data *data,int nr) +{ +if (data->type == it8613 || data->type == it8622)
Did you try to compile this patch ? I guess not, because I get
drivers/hwmon/it87.c: In function ‘it87_reg_pwm’:drivers/hwmon/it87.c:802:27: error: ‘it8613’ undeclared (first use in this function); did you mean ‘it8603’?
802 | if (data->type == it8613 || data->type == it8622)
| ^~~~~~
| it8603drivers/hwmon/it87.c:802:27: note: each undeclared identifier is reported only once for each function it appears in
The code should use register pointers in struct it87_data to avoid such problems and the need for runtime type checks.
Guenter