19
19
#include <linux/sysfs.h>
20
20
#include <linux/mutex.h>
21
21
#include <linux/regmap.h>
22
+ #include <linux/util_macros.h>
22
23
23
24
#define THERMAL_PID_REG 0xfd
24
25
#define THERMAL_SMSC_ID_REG 0xfe
@@ -333,6 +334,31 @@ static int emc1403_temp_read(struct thermal_data *data, u32 attr, int channel, l
333
334
return ret ;
334
335
}
335
336
337
+ static int emc1403_get_convrate (struct thermal_data * data , long * val )
338
+ {
339
+ unsigned int convrate ;
340
+ int ret ;
341
+
342
+ ret = regmap_read (data -> regmap , 0x04 , & convrate );
343
+ if (ret < 0 )
344
+ return ret ;
345
+ if (convrate > 10 )
346
+ convrate = 4 ;
347
+
348
+ * val = 16000 >> convrate ;
349
+ return 0 ;
350
+ }
351
+
352
+ static int emc1403_chip_read (struct thermal_data * data , u32 attr , long * val )
353
+ {
354
+ switch (attr ) {
355
+ case hwmon_chip_update_interval :
356
+ return emc1403_get_convrate (data , val );
357
+ default :
358
+ return - EOPNOTSUPP ;
359
+ }
360
+ }
361
+
336
362
static int emc1403_read (struct device * dev , enum hwmon_sensor_types type ,
337
363
u32 attr , int channel , long * val )
338
364
{
@@ -341,6 +367,8 @@ static int emc1403_read(struct device *dev, enum hwmon_sensor_types type,
341
367
switch (type ) {
342
368
case hwmon_temp :
343
369
return emc1403_temp_read (data , attr , channel , val );
370
+ case hwmon_chip :
371
+ return emc1403_chip_read (data , attr , val );
344
372
default :
345
373
return - EOPNOTSUPP ;
346
374
}
@@ -409,6 +437,30 @@ static int emc1403_temp_write(struct thermal_data *data, u32 attr, int channel,
409
437
}
410
438
}
411
439
440
+ /* Lookup table for temperature conversion times in msec */
441
+ static const u16 ina3221_conv_time [] = {
442
+ 16000 , 8000 , 4000 , 2000 , 1000 , 500 , 250 , 125 , 62 , 31 , 16
443
+ };
444
+
445
+ static int emc1403_set_convrate (struct thermal_data * data , unsigned int interval )
446
+ {
447
+ int convrate ;
448
+
449
+ convrate = find_closest_descending (interval , ina3221_conv_time ,
450
+ ARRAY_SIZE (ina3221_conv_time ));
451
+ return regmap_write (data -> regmap , 0x04 , convrate );
452
+ }
453
+
454
+ static int emc1403_chip_write (struct thermal_data * data , u32 attr , long val )
455
+ {
456
+ switch (attr ) {
457
+ case hwmon_chip_update_interval :
458
+ return emc1403_set_convrate (data , clamp_val (val , 0 , 100000 ));
459
+ default :
460
+ return - EOPNOTSUPP ;
461
+ }
462
+ }
463
+
412
464
static int emc1403_write (struct device * dev , enum hwmon_sensor_types type ,
413
465
u32 attr , int channel , long val )
414
466
{
@@ -417,6 +469,8 @@ static int emc1403_write(struct device *dev, enum hwmon_sensor_types type,
417
469
switch (type ) {
418
470
case hwmon_temp :
419
471
return emc1403_temp_write (data , attr , channel , val );
472
+ case hwmon_chip :
473
+ return emc1403_chip_write (data , attr , val );
420
474
default :
421
475
return - EOPNOTSUPP ;
422
476
}
@@ -453,18 +507,31 @@ static umode_t emc1403_temp_is_visible(const void *_data, u32 attr, int channel)
453
507
}
454
508
}
455
509
510
+ static umode_t emc1403_chip_is_visible (const void * _data , u32 attr )
511
+ {
512
+ switch (attr ) {
513
+ case hwmon_chip_update_interval :
514
+ return 0644 ;
515
+ default :
516
+ return 0 ;
517
+ }
518
+ }
519
+
456
520
static umode_t emc1403_is_visible (const void * data , enum hwmon_sensor_types type ,
457
521
u32 attr , int channel )
458
522
{
459
523
switch (type ) {
460
524
case hwmon_temp :
461
525
return emc1403_temp_is_visible (data , attr , channel );
526
+ case hwmon_chip :
527
+ return emc1403_chip_is_visible (data , attr );
462
528
default :
463
529
return 0 ;
464
530
}
465
531
}
466
532
467
533
static const struct hwmon_channel_info * const emc1403_info [] = {
534
+ HWMON_CHANNEL_INFO (chip , HWMON_C_UPDATE_INTERVAL ),
468
535
HWMON_CHANNEL_INFO (temp ,
469
536
HWMON_T_INPUT | HWMON_T_MIN | HWMON_T_MAX |
470
537
HWMON_T_CRIT | HWMON_T_MIN_HYST | HWMON_T_MAX_HYST |
0 commit comments