@@ -102,14 +102,48 @@ static const struct regmap_config ina238_regmap_config = {
102102 .val_bits = 16 ,
103103};
104104
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+
105117struct ina238_data {
118+ const struct ina238_config * config ;
106119 struct i2c_client * client ;
107120 struct mutex config_lock ;
108121 struct regmap * regmap ;
109122 u32 rshunt ;
110123 int gain ;
111124};
112125
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+
113147static int ina238_read_reg24 (const struct i2c_client * client , u8 reg , u32 * val )
114148{
115149 u8 data [3 ];
@@ -536,14 +570,20 @@ static int ina238_probe(struct i2c_client *client)
536570 struct device * dev = & client -> dev ;
537571 struct device * hwmon_dev ;
538572 struct ina238_data * data ;
573+ enum ina238_ids chip ;
539574 int config ;
540575 int ret ;
541576
577+ chip = (uintptr_t )i2c_get_match_data (client );
578+
542579 data = devm_kzalloc (dev , sizeof (* data ), GFP_KERNEL );
543580 if (!data )
544581 return - ENOMEM ;
545582
546583 data -> client = client ;
584+ /* set the device type */
585+ data -> config = & ina238_config [chip ];
586+
547587 mutex_init (& data -> config_lock );
548588
549589 data -> regmap = devm_regmap_init_i2c (client , & ina238_regmap_config );
@@ -570,7 +610,7 @@ static int ina238_probe(struct i2c_client *client)
570610 }
571611
572612 /* Setup CONFIG register */
573- config = INA238_CONFIG_DEFAULT ;
613+ config = data -> config -> config_default ;
574614 if (data -> gain == 1 )
575615 config |= INA238_CONFIG_ADCRANGE ; /* ADCRANGE = 1 is /1 */
576616 ret = regmap_write (data -> regmap , INA238_CONFIG , config );
@@ -616,15 +656,22 @@ static int ina238_probe(struct i2c_client *client)
616656}
617657
618658static const struct i2c_device_id ina238_id [] = {
619- { "ina238" },
659+ { "ina237" , ina237 },
660+ { "ina238" , ina238 },
620661 { }
621662};
622663MODULE_DEVICE_TABLE (i2c , ina238_id );
623664
624665static 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+ { }
628675};
629676MODULE_DEVICE_TABLE (of , ina238_of_match );
630677
0 commit comments