47
47
#define MAX31827_M_DGR_TO_16_BIT (x ) (((x) << 4) / 1000)
48
48
#define MAX31827_DEVICE_ENABLE (x ) ((x) ? 0xA : 0x0)
49
49
50
- enum chips { max31827 = 1 , max31828 , max31829 };
51
-
52
50
enum max31827_cnv {
53
51
MAX31827_CNV_1_DIV_64_HZ = 1 ,
54
52
MAX31827_CNV_1_DIV_32_HZ ,
@@ -90,6 +88,13 @@ static const u16 max31827_conv_times[] = {
90
88
[MAX31827_RES_12_BIT ] = MAX31827_12_BIT_CNV_TIME ,
91
89
};
92
90
91
+ struct max31827_state ;
92
+
93
+ struct max31827_chip_info {
94
+ u32 alarm_pol_default : 1 ;
95
+ u32 fault_q_default ;
96
+ };
97
+
93
98
struct max31827_state {
94
99
/*
95
100
* Prevent simultaneous access to the i2c client.
@@ -99,6 +104,7 @@ struct max31827_state {
99
104
bool enable ;
100
105
unsigned int resolution ;
101
106
unsigned int update_interval ;
107
+ const struct max31827_chip_info * chip_info ;
102
108
};
103
109
104
110
static const struct regmap_config max31827_regmap = {
@@ -485,21 +491,12 @@ static struct attribute *max31827_attrs[] = {
485
491
};
486
492
ATTRIBUTE_GROUPS (max31827 );
487
493
488
- static const struct i2c_device_id max31827_i2c_ids [] = {
489
- { "max31827" , max31827 },
490
- { "max31828" , max31828 },
491
- { "max31829" , max31829 },
492
- { }
493
- };
494
- MODULE_DEVICE_TABLE (i2c , max31827_i2c_ids );
495
-
496
494
static int max31827_init_client (struct max31827_state * st ,
497
495
struct device * dev )
498
496
{
499
497
struct fwnode_handle * fwnode ;
500
498
unsigned int res = 0 ;
501
499
u32 data , lsb_idx ;
502
- enum chips type ;
503
500
bool prop ;
504
501
int ret ;
505
502
@@ -516,8 +513,6 @@ static int max31827_init_client(struct max31827_state *st,
516
513
prop = fwnode_property_read_bool (fwnode , "adi,timeout-enable" );
517
514
res |= FIELD_PREP (MAX31827_CONFIGURATION_TIMEOUT_MASK , !prop );
518
515
519
- type = (enum chips )(uintptr_t )device_get_match_data (dev );
520
-
521
516
if (fwnode_property_present (fwnode , "adi,alarm-pol" )) {
522
517
ret = fwnode_property_read_u32 (fwnode , "adi,alarm-pol" , & data );
523
518
if (ret )
@@ -528,19 +523,8 @@ static int max31827_init_client(struct max31827_state *st,
528
523
/*
529
524
* Set default value.
530
525
*/
531
- switch (type ) {
532
- case max31827 :
533
- case max31828 :
534
- res |= FIELD_PREP (MAX31827_CONFIGURATION_ALRM_POL_MASK ,
535
- MAX31827_ALRM_POL_LOW );
536
- break ;
537
- case max31829 :
538
- res |= FIELD_PREP (MAX31827_CONFIGURATION_ALRM_POL_MASK ,
539
- MAX31827_ALRM_POL_HIGH );
540
- break ;
541
- default :
542
- return - EOPNOTSUPP ;
543
- }
526
+ res |= FIELD_PREP (MAX31827_CONFIGURATION_ALRM_POL_MASK ,
527
+ st -> chip_info -> alarm_pol_default );
544
528
}
545
529
546
530
if (fwnode_property_present (fwnode , "adi,fault-q" )) {
@@ -564,19 +548,8 @@ static int max31827_init_client(struct max31827_state *st,
564
548
/*
565
549
* Set default value.
566
550
*/
567
- switch (type ) {
568
- case max31827 :
569
- res |= FIELD_PREP (MAX31827_CONFIGURATION_FLT_Q_MASK ,
570
- MAX31827_FLT_Q_1 );
571
- break ;
572
- case max31828 :
573
- case max31829 :
574
- res |= FIELD_PREP (MAX31827_CONFIGURATION_FLT_Q_MASK ,
575
- MAX31827_FLT_Q_4 );
576
- break ;
577
- default :
578
- return - EOPNOTSUPP ;
579
- }
551
+ res |= FIELD_PREP (MAX31827_CONFIGURATION_FLT_Q_MASK ,
552
+ st -> chip_info -> fault_q_default );
580
553
}
581
554
582
555
return regmap_write (st -> regmap , MAX31827_CONFIGURATION_REG , res );
@@ -597,7 +570,7 @@ static const struct hwmon_ops max31827_hwmon_ops = {
597
570
.write = max31827_write ,
598
571
};
599
572
600
- static const struct hwmon_chip_info max31827_chip_info = {
573
+ static const struct hwmon_chip_info max31827_hwmon_chip_info = {
601
574
.ops = & max31827_hwmon_ops ,
602
575
.info = max31827_info ,
603
576
};
@@ -616,6 +589,8 @@ static int max31827_probe(struct i2c_client *client)
616
589
if (!st )
617
590
return - ENOMEM ;
618
591
592
+ st -> chip_info = (struct max31827_chip_info * )(uintptr_t )device_get_match_data (dev );
593
+
619
594
mutex_init (& st -> lock );
620
595
621
596
st -> regmap = devm_regmap_init_i2c (client , & max31827_regmap );
@@ -632,24 +607,47 @@ static int max31827_probe(struct i2c_client *client)
632
607
return err ;
633
608
634
609
hwmon_dev = devm_hwmon_device_register_with_info (dev , client -> name , st ,
635
- & max31827_chip_info ,
610
+ & max31827_hwmon_chip_info ,
636
611
max31827_groups );
637
612
638
613
return PTR_ERR_OR_ZERO (hwmon_dev );
639
614
}
640
615
616
+ static const struct max31827_chip_info max31827 = {
617
+ .alarm_pol_default = MAX31827_ALRM_POL_LOW ,
618
+ .fault_q_default = MAX31827_FLT_Q_1 ,
619
+ };
620
+
621
+ static const struct max31827_chip_info max31828 = {
622
+ .alarm_pol_default = MAX31827_ALRM_POL_LOW ,
623
+ .fault_q_default = MAX31827_FLT_Q_4 ,
624
+ };
625
+
626
+ static const struct max31827_chip_info max31829 = {
627
+ .alarm_pol_default = MAX31827_ALRM_POL_HIGH ,
628
+ .fault_q_default = MAX31827_FLT_Q_4 ,
629
+ };
630
+
631
+ static const struct i2c_device_id max31827_i2c_ids [] = {
632
+ { "max31827" , (kernel_ulong_t )& max31827 },
633
+ { "max31828" , (kernel_ulong_t )& max31828 },
634
+ { "max31829" , (kernel_ulong_t )& max31829 },
635
+ { }
636
+ };
637
+ MODULE_DEVICE_TABLE (i2c , max31827_i2c_ids );
638
+
641
639
static const struct of_device_id max31827_of_match [] = {
642
640
{
643
641
.compatible = "adi,max31827" ,
644
- .data = (void * )max31827
642
+ .data = (void * )& max31827
645
643
},
646
644
{
647
645
.compatible = "adi,max31828" ,
648
- .data = (void * )max31828
646
+ .data = (void * )& max31828
649
647
},
650
648
{
651
649
.compatible = "adi,max31829" ,
652
- .data = (void * )max31829
650
+ .data = (void * )& max31829
653
651
},
654
652
{ }
655
653
};
@@ -666,6 +664,7 @@ static struct i2c_driver max31827_driver = {
666
664
};
667
665
module_i2c_driver (max31827_driver );
668
666
667
+ MODULE_AUTHOR ("John Erasmus Mari Geronimo <johnerasmusmari.geronimo@analog.com>" );
669
668
MODULE_AUTHOR ("Daniel Matyas <daniel.matyas@analog.com>" );
670
669
MODULE_DESCRIPTION ("Maxim MAX31827 low-power temperature switch driver" );
671
670
MODULE_LICENSE ("GPL" );
0 commit comments