@@ -102,14 +102,48 @@ static const struct regmap_config ina238_regmap_config = {
102
102
.val_bits = 16 ,
103
103
};
104
104
105
+ enum ina238_ids { ina238 , ina237 };
106
+
107
+ struct ina238_config {
108
+ bool has_power_highest ; /* chip detection power peak */
109
+ bool has_energy ; /* chip detection energy */
110
+ u8 temp_shift ; /* fixed parameters for temp calculate */
111
+ u32 power_calculate_factor ; /* fixed parameters for power calculate */
112
+ u16 config_default ; /* Power-on default state */
113
+ int bus_voltage_lsb ; /* use for temperature calculate, uV/lsb */
114
+ int temp_lsb ; /* use for temperature calculate */
115
+ };
116
+
105
117
struct ina238_data {
118
+ const struct ina238_config * config ;
106
119
struct i2c_client * client ;
107
120
struct mutex config_lock ;
108
121
struct regmap * regmap ;
109
122
u32 rshunt ;
110
123
int gain ;
111
124
};
112
125
126
+ static const struct ina238_config ina238_config [] = {
127
+ [ina238 ] = {
128
+ .has_energy = false,
129
+ .has_power_highest = false,
130
+ .temp_shift = 4 ,
131
+ .power_calculate_factor = 20 ,
132
+ .config_default = INA238_CONFIG_DEFAULT ,
133
+ .bus_voltage_lsb = INA238_BUS_VOLTAGE_LSB ,
134
+ .temp_lsb = INA238_DIE_TEMP_LSB ,
135
+ },
136
+ [ina237 ] = {
137
+ .has_energy = false,
138
+ .has_power_highest = false,
139
+ .temp_shift = 4 ,
140
+ .power_calculate_factor = 20 ,
141
+ .config_default = INA238_CONFIG_DEFAULT ,
142
+ .bus_voltage_lsb = INA238_BUS_VOLTAGE_LSB ,
143
+ .temp_lsb = INA238_DIE_TEMP_LSB ,
144
+ },
145
+ };
146
+
113
147
static int ina238_read_reg24 (const struct i2c_client * client , u8 reg , u32 * val )
114
148
{
115
149
u8 data [3 ];
@@ -536,14 +570,20 @@ static int ina238_probe(struct i2c_client *client)
536
570
struct device * dev = & client -> dev ;
537
571
struct device * hwmon_dev ;
538
572
struct ina238_data * data ;
573
+ enum ina238_ids chip ;
539
574
int config ;
540
575
int ret ;
541
576
577
+ chip = (uintptr_t )i2c_get_match_data (client );
578
+
542
579
data = devm_kzalloc (dev , sizeof (* data ), GFP_KERNEL );
543
580
if (!data )
544
581
return - ENOMEM ;
545
582
546
583
data -> client = client ;
584
+ /* set the device type */
585
+ data -> config = & ina238_config [chip ];
586
+
547
587
mutex_init (& data -> config_lock );
548
588
549
589
data -> regmap = devm_regmap_init_i2c (client , & ina238_regmap_config );
@@ -570,7 +610,7 @@ static int ina238_probe(struct i2c_client *client)
570
610
}
571
611
572
612
/* Setup CONFIG register */
573
- config = INA238_CONFIG_DEFAULT ;
613
+ config = data -> config -> config_default ;
574
614
if (data -> gain == 1 )
575
615
config |= INA238_CONFIG_ADCRANGE ; /* ADCRANGE = 1 is /1 */
576
616
ret = regmap_write (data -> regmap , INA238_CONFIG , config );
@@ -616,15 +656,22 @@ static int ina238_probe(struct i2c_client *client)
616
656
}
617
657
618
658
static const struct i2c_device_id ina238_id [] = {
619
- { "ina238" },
659
+ { "ina237" , ina237 },
660
+ { "ina238" , ina238 },
620
661
{ }
621
662
};
622
663
MODULE_DEVICE_TABLE (i2c , ina238_id );
623
664
624
665
static const struct of_device_id __maybe_unused ina238_of_match [] = {
625
- { .compatible = "ti,ina237" },
626
- { .compatible = "ti,ina238" },
627
- { },
666
+ {
667
+ .compatible = "ti,ina237" ,
668
+ .data = (void * )ina237
669
+ },
670
+ {
671
+ .compatible = "ti,ina238" ,
672
+ .data = (void * )ina238
673
+ },
674
+ { }
628
675
};
629
676
MODULE_DEVICE_TABLE (of , ina238_of_match );
630
677
0 commit comments