@@ -265,9 +265,7 @@ struct it87_data {
265265 u16 fan [5 ]; /* Register values, possibly combined */
266266 u16 fan_min [5 ]; /* Register values, possibly combined */
267267 u8 has_temp ; /* Bitfield, temp sensors enabled */
268- s8 temp [3 ]; /* Register value */
269- s8 temp_high [3 ]; /* Register value */
270- s8 temp_low [3 ]; /* Register value */
268+ s8 temp [3 ][3 ]; /* [nr][0]=temp, [1]=min, [2]=max */
271269 u8 sensor ; /* Register value */
272270 u8 fan_div [3 ]; /* Register encoding, shifted right */
273271 u8 vid ; /* Register encoding, combined */
@@ -545,79 +543,53 @@ show_in_offset(8);
545543
546544/* 3 temperatures */
547545static ssize_t show_temp (struct device * dev , struct device_attribute * attr ,
548- char * buf )
546+ char * buf )
549547{
550- struct sensor_device_attribute * sensor_attr = to_sensor_dev_attr (attr );
551- int nr = sensor_attr -> index ;
552-
548+ struct sensor_device_attribute_2 * sattr = to_sensor_dev_attr_2 (attr );
549+ int nr = sattr -> nr ;
550+ int index = sattr -> index ;
553551 struct it87_data * data = it87_update_device (dev );
554- return sprintf (buf , "%d\n" , TEMP_FROM_REG (data -> temp [nr ]));
555- }
556- static ssize_t show_temp_max (struct device * dev , struct device_attribute * attr ,
557- char * buf )
558- {
559- struct sensor_device_attribute * sensor_attr = to_sensor_dev_attr (attr );
560- int nr = sensor_attr -> index ;
561552
562- struct it87_data * data = it87_update_device (dev );
563- return sprintf (buf , "%d\n" , TEMP_FROM_REG (data -> temp_high [nr ]));
553+ return sprintf (buf , "%d\n" , TEMP_FROM_REG (data -> temp [nr ][index ]));
564554}
565- static ssize_t show_temp_min (struct device * dev , struct device_attribute * attr ,
566- char * buf )
567- {
568- struct sensor_device_attribute * sensor_attr = to_sensor_dev_attr (attr );
569- int nr = sensor_attr -> index ;
570555
571- struct it87_data * data = it87_update_device (dev );
572- return sprintf (buf , "%d\n" , TEMP_FROM_REG (data -> temp_low [nr ]));
573- }
574- static ssize_t set_temp_max (struct device * dev , struct device_attribute * attr ,
575- const char * buf , size_t count )
556+ static ssize_t set_temp (struct device * dev , struct device_attribute * attr ,
557+ const char * buf , size_t count )
576558{
577- struct sensor_device_attribute * sensor_attr = to_sensor_dev_attr (attr );
578- int nr = sensor_attr -> index ;
579-
580- struct it87_data * data = dev_get_drvdata (dev );
581- long val ;
582-
583- if (kstrtol (buf , 10 , & val ) < 0 )
584- return - EINVAL ;
585-
586- mutex_lock (& data -> update_lock );
587- data -> temp_high [nr ] = TEMP_TO_REG (val );
588- it87_write_value (data , IT87_REG_TEMP_HIGH (nr ), data -> temp_high [nr ]);
589- mutex_unlock (& data -> update_lock );
590- return count ;
591- }
592- static ssize_t set_temp_min (struct device * dev , struct device_attribute * attr ,
593- const char * buf , size_t count )
594- {
595- struct sensor_device_attribute * sensor_attr = to_sensor_dev_attr (attr );
596- int nr = sensor_attr -> index ;
597-
559+ struct sensor_device_attribute_2 * sattr = to_sensor_dev_attr_2 (attr );
560+ int nr = sattr -> nr ;
561+ int index = sattr -> index ;
598562 struct it87_data * data = dev_get_drvdata (dev );
599563 long val ;
600564
601565 if (kstrtol (buf , 10 , & val ) < 0 )
602566 return - EINVAL ;
603567
604568 mutex_lock (& data -> update_lock );
605- data -> temp_low [nr ] = TEMP_TO_REG (val );
606- it87_write_value (data , IT87_REG_TEMP_LOW (nr ), data -> temp_low [nr ]);
569+ data -> temp [nr ][index ] = TEMP_TO_REG (val );
570+ it87_write_value (data ,
571+ index == 1 ? IT87_REG_TEMP_LOW (nr )
572+ : IT87_REG_TEMP_HIGH (nr ),
573+ data -> temp [nr ][index ]);
607574 mutex_unlock (& data -> update_lock );
608575 return count ;
609576}
610- #define show_temp_offset (offset ) \
611- static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
612- show_temp, NULL, offset - 1); \
613- static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
614- show_temp_max, set_temp_max, offset - 1); \
615- static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
616- show_temp_min, set_temp_min, offset - 1);
617577
618- show_temp_offset (1 );
619- show_temp_offset (2 );
620- show_temp_offset (3 );
578+ static SENSOR_DEVICE_ATTR_2 (temp1_input , S_IRUGO , show_temp , NULL, 0 , 0 ) ;
579+ static SENSOR_DEVICE_ATTR_2 (temp1_min , S_IRUGO | S_IWUSR , show_temp , set_temp ,
580+ 0 , 1 ) ;
581+ static SENSOR_DEVICE_ATTR_2 (temp1_max , S_IRUGO | S_IWUSR , show_temp , set_temp ,
582+ 0 , 2 ) ;
583+ static SENSOR_DEVICE_ATTR_2 (temp2_input , S_IRUGO , show_temp , NULL, 1 , 0 ) ;
584+ static SENSOR_DEVICE_ATTR_2 (temp2_min , S_IRUGO | S_IWUSR , show_temp , set_temp ,
585+ 1 , 1 ) ;
586+ static SENSOR_DEVICE_ATTR_2 (temp2_max , S_IRUGO | S_IWUSR , show_temp , set_temp ,
587+ 1 , 2 ) ;
588+ static SENSOR_DEVICE_ATTR_2 (temp3_input , S_IRUGO , show_temp , NULL, 2 , 0 ) ;
589+ static SENSOR_DEVICE_ATTR_2 (temp3_min , S_IRUGO | S_IWUSR , show_temp , set_temp ,
590+ 2 , 1 ) ;
591+ static SENSOR_DEVICE_ATTR_2 (temp3_max , S_IRUGO | S_IWUSR , show_temp , set_temp ,
592+ 2 , 2 ) ;
621593
622594static ssize_t show_sensor (struct device * dev , struct device_attribute * attr ,
623595 char * buf )
@@ -2419,12 +2391,12 @@ static struct it87_data *it87_update_device(struct device *dev)
24192391 for (i = 0 ; i < 3 ; i ++ ) {
24202392 if (!(data -> has_temp & (1 << i )))
24212393 continue ;
2422- data -> temp [i ] =
2394+ data -> temp [i ][ 0 ] =
24232395 it87_read_value (data , IT87_REG_TEMP (i ));
2424- data -> temp_high [i ] =
2425- it87_read_value (data , IT87_REG_TEMP_HIGH (i ));
2426- data -> temp_low [i ] =
2396+ data -> temp [i ][1 ] =
24272397 it87_read_value (data , IT87_REG_TEMP_LOW (i ));
2398+ data -> temp [i ][2 ] =
2399+ it87_read_value (data , IT87_REG_TEMP_HIGH (i ));
24282400 }
24292401
24302402 /* Newer chips don't have clock dividers */
0 commit comments