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,17 @@ 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
+ static const struct max31827_chip_info max31827 ;
93
+ static const struct max31827_chip_info max31828 ;
94
+ static const struct max31827_chip_info max31829 ;
95
+ static const struct max31827_chip_info max31875 ;
96
+
97
+ struct max31827_chip_info {
98
+ u8 alarm_pol_default ;
99
+ u32 fault_q_default ;
100
+ };
101
+
93
102
struct max31827_state {
94
103
/*
95
104
* Prevent simultaneous access to the i2c client.
@@ -99,6 +108,7 @@ struct max31827_state {
99
108
bool enable ;
100
109
unsigned int resolution ;
101
110
unsigned int update_interval ;
111
+ const struct max31827_chip_info * chip_info ;
102
112
};
103
113
104
114
static const struct regmap_config max31827_regmap = {
@@ -486,9 +496,9 @@ static struct attribute *max31827_attrs[] = {
486
496
ATTRIBUTE_GROUPS (max31827 );
487
497
488
498
static const struct i2c_device_id max31827_i2c_ids [] = {
489
- { "max31827" , max31827 },
490
- { "max31828" , max31828 },
491
- { "max31829" , max31829 },
499
+ { "max31827" , ( kernel_ulong_t ) & max31827 },
500
+ { "max31828" , ( kernel_ulong_t ) & max31828 },
501
+ { "max31829" , ( kernel_ulong_t ) & max31829 },
492
502
{ }
493
503
};
494
504
MODULE_DEVICE_TABLE (i2c , max31827_i2c_ids );
@@ -499,7 +509,6 @@ static int max31827_init_client(struct max31827_state *st,
499
509
struct fwnode_handle * fwnode ;
500
510
unsigned int res = 0 ;
501
511
u32 data , lsb_idx ;
502
- enum chips type ;
503
512
bool prop ;
504
513
int ret ;
505
514
@@ -516,8 +525,6 @@ static int max31827_init_client(struct max31827_state *st,
516
525
prop = fwnode_property_read_bool (fwnode , "adi,timeout-enable" );
517
526
res |= FIELD_PREP (MAX31827_CONFIGURATION_TIMEOUT_MASK , !prop );
518
527
519
- type = (enum chips )(uintptr_t )device_get_match_data (dev );
520
-
521
528
if (fwnode_property_present (fwnode , "adi,alarm-pol" )) {
522
529
ret = fwnode_property_read_u32 (fwnode , "adi,alarm-pol" , & data );
523
530
if (ret )
@@ -528,19 +535,8 @@ static int max31827_init_client(struct max31827_state *st,
528
535
/*
529
536
* Set default value.
530
537
*/
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
- }
538
+ res |= FIELD_PREP (MAX31827_CONFIGURATION_ALRM_POL_MASK ,
539
+ st -> chip_info -> alarm_pol_default );
544
540
}
545
541
546
542
if (fwnode_property_present (fwnode , "adi,fault-q" )) {
@@ -564,19 +560,8 @@ static int max31827_init_client(struct max31827_state *st,
564
560
/*
565
561
* Set default value.
566
562
*/
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
- }
563
+ res |= FIELD_PREP (MAX31827_CONFIGURATION_FLT_Q_MASK ,
564
+ st -> chip_info -> fault_q_default );
580
565
}
581
566
582
567
return regmap_write (st -> regmap , MAX31827_CONFIGURATION_REG , res );
@@ -597,11 +582,26 @@ static const struct hwmon_ops max31827_hwmon_ops = {
597
582
.write = max31827_write ,
598
583
};
599
584
600
- static const struct hwmon_chip_info max31827_chip_info = {
585
+ static const struct hwmon_chip_info max31827_hwmon_chip_info = {
601
586
.ops = & max31827_hwmon_ops ,
602
587
.info = max31827_info ,
603
588
};
604
589
590
+ static const struct max31827_chip_info max31827 = {
591
+ .alarm_pol_default = MAX31827_ALRM_POL_LOW ,
592
+ .fault_q_default = MAX31827_FLT_Q_1 ,
593
+ };
594
+
595
+ static const struct max31827_chip_info max31828 = {
596
+ .alarm_pol_default = MAX31827_ALRM_POL_LOW ,
597
+ .fault_q_default = MAX31827_FLT_Q_4 ,
598
+ };
599
+
600
+ static const struct max31827_chip_info max31829 = {
601
+ .alarm_pol_default = MAX31827_ALRM_POL_HIGH ,
602
+ .fault_q_default = MAX31827_FLT_Q_4 ,
603
+ };
604
+
605
605
static int max31827_probe (struct i2c_client * client )
606
606
{
607
607
struct device * dev = & client -> dev ;
@@ -616,6 +616,10 @@ static int max31827_probe(struct i2c_client *client)
616
616
if (!st )
617
617
return - ENOMEM ;
618
618
619
+ st -> chip_info = device_get_match_data (dev );
620
+ if (!st -> chip_info )
621
+ return - ENODEV ;
622
+
619
623
mutex_init (& st -> lock );
620
624
621
625
st -> regmap = devm_regmap_init_i2c (client , & max31827_regmap );
@@ -632,7 +636,7 @@ static int max31827_probe(struct i2c_client *client)
632
636
return err ;
633
637
634
638
hwmon_dev = devm_hwmon_device_register_with_info (dev , client -> name , st ,
635
- & max31827_chip_info ,
639
+ & max31827_hwmon_chip_info ,
636
640
max31827_groups );
637
641
638
642
return PTR_ERR_OR_ZERO (hwmon_dev );
@@ -641,15 +645,15 @@ static int max31827_probe(struct i2c_client *client)
641
645
static const struct of_device_id max31827_of_match [] = {
642
646
{
643
647
.compatible = "adi,max31827" ,
644
- .data = ( void * ) max31827
648
+ .data = & max31827
645
649
},
646
650
{
647
651
.compatible = "adi,max31828" ,
648
- .data = ( void * ) max31828
652
+ .data = & max31828
649
653
},
650
654
{
651
655
.compatible = "adi,max31829" ,
652
- .data = ( void * ) max31829
656
+ .data = & max31829
653
657
},
654
658
{ }
655
659
};
@@ -666,6 +670,7 @@ static struct i2c_driver max31827_driver = {
666
670
};
667
671
module_i2c_driver (max31827_driver );
668
672
673
+ MODULE_AUTHOR ("John Erasmus Mari Geronimo <johnerasmusmari.geronimo@analog.com>" );
669
674
MODULE_AUTHOR ("Daniel Matyas <daniel.matyas@analog.com>" );
670
675
MODULE_DESCRIPTION ("Maxim MAX31827 low-power temperature switch driver" );
671
676
MODULE_LICENSE ("GPL" );
0 commit comments