7
7
8
8
#include <linux/module.h>
9
9
#include <linux/init.h>
10
+ #include <linux/interrupt.h>
10
11
#include <linux/slab.h>
11
12
#include <linux/jiffies.h>
12
13
#include <linux/i2c.h>
24
25
25
26
enum lm75_type { /* keep sorted in alphabetical order */
26
27
adt75 ,
28
+ as6200 ,
27
29
at30ts74 ,
28
30
ds1775 ,
29
31
ds75 ,
@@ -54,6 +56,7 @@ enum lm75_type { /* keep sorted in alphabetical order */
54
56
55
57
/**
56
58
* struct lm75_params - lm75 configuration parameters.
59
+ * @config_reg_16bits: Configure register size is 2 bytes.
57
60
* @set_mask: Bits to set in configuration register when configuring
58
61
* the chip.
59
62
* @clr_mask: Bits to clear in configuration register when configuring
@@ -74,17 +77,20 @@ enum lm75_type { /* keep sorted in alphabetical order */
74
77
* @sample_times: All the possible sample times to be set. Mandatory if
75
78
* num_sample_times is larger than 1. If set, number of
76
79
* entries must match num_sample_times.
80
+ * @alarm: Alarm bit is supported.
77
81
*/
78
82
79
83
struct lm75_params {
80
- u8 set_mask ;
81
- u8 clr_mask ;
84
+ bool config_reg_16bits ;
85
+ u16 set_mask ;
86
+ u16 clr_mask ;
82
87
u8 default_resolution ;
83
88
u8 resolution_limits ;
84
89
const u8 * resolutions ;
85
90
unsigned int default_sample_time ;
86
91
u8 num_sample_times ;
87
92
const unsigned int * sample_times ;
93
+ bool alarm ;
88
94
};
89
95
90
96
/* Addresses scanned */
@@ -103,8 +109,8 @@ struct lm75_data {
103
109
struct i2c_client * client ;
104
110
struct regmap * regmap ;
105
111
struct regulator * vs ;
106
- u8 orig_conf ;
107
- u8 current_conf ;
112
+ u16 orig_conf ;
113
+ u16 current_conf ;
108
114
u8 resolution ; /* In bits, 9 to 16 */
109
115
unsigned int sample_time ; /* In ms */
110
116
enum lm75_type kind ;
@@ -127,6 +133,15 @@ static const struct lm75_params device_params[] = {
127
133
.default_resolution = 12 ,
128
134
.default_sample_time = MSEC_PER_SEC / 10 ,
129
135
},
136
+ [as6200 ] = {
137
+ .config_reg_16bits = true,
138
+ .set_mask = 0x94C0 , /* 8 sample/s, 4 CF, positive polarity */
139
+ .default_resolution = 12 ,
140
+ .default_sample_time = 125 ,
141
+ .num_sample_times = 4 ,
142
+ .sample_times = (unsigned int []){ 125 , 250 , 1000 , 4000 },
143
+ .alarm = true,
144
+ },
130
145
[at30ts74 ] = {
131
146
.set_mask = 3 << 5 , /* 12-bit mode*/
132
147
.default_resolution = 12 ,
@@ -316,27 +331,51 @@ static inline long lm75_reg_to_mc(s16 temp, u8 resolution)
316
331
return ((temp >> (16 - resolution )) * 1000 ) >> (resolution - 8 );
317
332
}
318
333
319
- static int lm75_write_config (struct lm75_data * data , u8 set_mask ,
320
- u8 clr_mask )
334
+ static int lm75_write_config (struct lm75_data * data , u16 set_mask ,
335
+ u16 clr_mask )
321
336
{
322
- u8 value ;
337
+ unsigned int value ;
323
338
324
- clr_mask |= LM75_SHUTDOWN ;
339
+ clr_mask |= LM75_SHUTDOWN << ( 8 * data -> params -> config_reg_16bits ) ;
325
340
value = data -> current_conf & ~clr_mask ;
326
341
value |= set_mask ;
327
342
328
343
if (data -> current_conf != value ) {
329
344
s32 err ;
330
-
331
- err = i2c_smbus_write_byte_data (data -> client , LM75_REG_CONF ,
332
- value );
345
+ if (data -> params -> config_reg_16bits )
346
+ err = regmap_write (data -> regmap , LM75_REG_CONF , value );
347
+ else
348
+ err = i2c_smbus_write_byte_data (data -> client ,
349
+ LM75_REG_CONF ,
350
+ value );
333
351
if (err )
334
352
return err ;
335
353
data -> current_conf = value ;
336
354
}
337
355
return 0 ;
338
356
}
339
357
358
+ static int lm75_read_config (struct lm75_data * data )
359
+ {
360
+ int ret ;
361
+ unsigned int status ;
362
+
363
+ if (data -> params -> config_reg_16bits ) {
364
+ ret = regmap_read (data -> regmap , LM75_REG_CONF , & status );
365
+ return ret ? ret : status ;
366
+ }
367
+
368
+ return i2c_smbus_read_byte_data (data -> client , LM75_REG_CONF );
369
+ }
370
+
371
+ static irqreturn_t lm75_alarm_handler (int irq , void * private )
372
+ {
373
+ struct device * hwmon_dev = private ;
374
+
375
+ hwmon_notify_event (hwmon_dev , hwmon_temp , hwmon_temp_alarm , 0 );
376
+ return IRQ_HANDLED ;
377
+ }
378
+
340
379
static int lm75_read (struct device * dev , enum hwmon_sensor_types type ,
341
380
u32 attr , int channel , long * val )
342
381
{
@@ -365,14 +404,27 @@ static int lm75_read(struct device *dev, enum hwmon_sensor_types type,
365
404
case hwmon_temp_max_hyst :
366
405
reg = LM75_REG_HYST ;
367
406
break ;
407
+ case hwmon_temp_alarm :
408
+ reg = LM75_REG_CONF ;
409
+ break ;
368
410
default :
369
411
return - EINVAL ;
370
412
}
371
413
err = regmap_read (data -> regmap , reg , & regval );
372
414
if (err < 0 )
373
415
return err ;
374
416
375
- * val = lm75_reg_to_mc (regval , data -> resolution );
417
+ if (attr == hwmon_temp_alarm ) {
418
+ switch (data -> kind ) {
419
+ case as6200 :
420
+ * val = (regval >> 5 ) & 0x1 ;
421
+ break ;
422
+ default :
423
+ return - EINVAL ;
424
+ }
425
+ } else {
426
+ * val = lm75_reg_to_mc (regval , data -> resolution );
427
+ }
376
428
break ;
377
429
default :
378
430
return - EINVAL ;
@@ -435,6 +487,7 @@ static int lm75_update_interval(struct device *dev, long val)
435
487
data -> resolution = data -> params -> resolutions [index ];
436
488
break ;
437
489
case tmp112 :
490
+ case as6200 :
438
491
err = regmap_read (data -> regmap , LM75_REG_CONF , & reg );
439
492
if (err < 0 )
440
493
return err ;
@@ -502,6 +555,10 @@ static umode_t lm75_is_visible(const void *data, enum hwmon_sensor_types type,
502
555
case hwmon_temp_max :
503
556
case hwmon_temp_max_hyst :
504
557
return 0644 ;
558
+ case hwmon_temp_alarm :
559
+ if (config_data -> params -> alarm )
560
+ return 0444 ;
561
+ break ;
505
562
}
506
563
break ;
507
564
default :
@@ -514,7 +571,8 @@ static const struct hwmon_channel_info * const lm75_info[] = {
514
571
HWMON_CHANNEL_INFO (chip ,
515
572
HWMON_C_REGISTER_TZ | HWMON_C_UPDATE_INTERVAL ),
516
573
HWMON_CHANNEL_INFO (temp ,
517
- HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_MAX_HYST ),
574
+ HWMON_T_INPUT | HWMON_T_MAX | HWMON_T_MAX_HYST |
575
+ HWMON_T_ALARM ),
518
576
NULL
519
577
};
520
578
@@ -622,7 +680,7 @@ static int lm75_probe(struct i2c_client *client)
622
680
return err ;
623
681
624
682
/* Cache original configuration */
625
- status = i2c_smbus_read_byte_data ( client , LM75_REG_CONF );
683
+ status = lm75_read_config ( data );
626
684
if (status < 0 ) {
627
685
dev_dbg (dev , "Can't read config? %d\n" , status );
628
686
return status ;
@@ -645,13 +703,31 @@ static int lm75_probe(struct i2c_client *client)
645
703
if (IS_ERR (hwmon_dev ))
646
704
return PTR_ERR (hwmon_dev );
647
705
706
+ if (client -> irq ) {
707
+ if (data -> params -> alarm ) {
708
+ err = devm_request_threaded_irq (dev ,
709
+ client -> irq ,
710
+ NULL ,
711
+ & lm75_alarm_handler ,
712
+ IRQF_ONESHOT ,
713
+ client -> name ,
714
+ hwmon_dev );
715
+ if (err )
716
+ return err ;
717
+ } else {
718
+ /* alarm is only supported for chips with alarm bit */
719
+ dev_err (dev , "alarm interrupt is not supported\n" );
720
+ }
721
+ }
722
+
648
723
dev_info (dev , "%s: sensor '%s'\n" , dev_name (hwmon_dev ), client -> name );
649
724
650
725
return 0 ;
651
726
}
652
727
653
728
static const struct i2c_device_id lm75_ids [] = {
654
729
{ "adt75" , adt75 , },
730
+ { "as6200" , as6200 , },
655
731
{ "at30ts74" , at30ts74 , },
656
732
{ "ds1775" , ds1775 , },
657
733
{ "ds75" , ds75 , },
@@ -688,6 +764,10 @@ static const struct of_device_id __maybe_unused lm75_of_match[] = {
688
764
.compatible = "adi,adt75" ,
689
765
.data = (void * )adt75
690
766
},
767
+ {
768
+ .compatible = "ams,as6200" ,
769
+ .data = (void * )as6200
770
+ },
691
771
{
692
772
.compatible = "atmel,at30ts74" ,
693
773
.data = (void * )at30ts74
0 commit comments