5656/* settings - depend on use case */
5757#define INA219_CONFIG_DEFAULT 0x399F /* PGA=8 */
5858#define INA226_CONFIG_DEFAULT 0x4527 /* averages=16 */
59+ #define INA260_CONFIG_DEFAULT 0x6527 /* averages=16 */
5960
6061/* worst case is 68.10 ms (~14.6Hz, ina219) */
6162#define INA2XX_CONVERSION_RATE 15
6263#define INA2XX_MAX_DELAY 69 /* worst case delay in ms */
6364
6465#define INA2XX_RSHUNT_DEFAULT 10000
66+ #define INA260_RSHUNT 2000
6567
6668/* bit mask for reading the averaging setting in the configuration register */
6769#define INA226_AVG_RD_MASK GENMASK(11, 9)
@@ -125,10 +127,12 @@ static const struct regmap_config ina2xx_regmap_config = {
125127 .writeable_reg = ina2xx_writeable_reg ,
126128};
127129
128- enum ina2xx_ids { ina219 , ina226 };
130+ enum ina2xx_ids { ina219 , ina226 , ina260 };
129131
130132struct ina2xx_config {
131133 u16 config_default ;
134+ bool has_alerts ; /* chip supports alerts and limits */
135+ bool has_ishunt ; /* chip has internal shunt resistor */
132136 int calibration_value ;
133137 int shunt_div ;
134138 int bus_voltage_shift ;
@@ -155,6 +159,8 @@ static const struct ina2xx_config ina2xx_config[] = {
155159 .bus_voltage_shift = 3 ,
156160 .bus_voltage_lsb = 4000 ,
157161 .power_lsb_factor = 20 ,
162+ .has_alerts = false,
163+ .has_ishunt = false,
158164 },
159165 [ina226 ] = {
160166 .config_default = INA226_CONFIG_DEFAULT ,
@@ -163,6 +169,17 @@ static const struct ina2xx_config ina2xx_config[] = {
163169 .bus_voltage_shift = 0 ,
164170 .bus_voltage_lsb = 1250 ,
165171 .power_lsb_factor = 25 ,
172+ .has_alerts = true,
173+ .has_ishunt = false,
174+ },
175+ [ina260 ] = {
176+ .config_default = INA260_CONFIG_DEFAULT ,
177+ .shunt_div = 400 ,
178+ .bus_voltage_shift = 0 ,
179+ .bus_voltage_lsb = 1250 ,
180+ .power_lsb_factor = 8 ,
181+ .has_alerts = true,
182+ .has_ishunt = true,
166183 },
167184};
168185
@@ -254,6 +271,15 @@ static int ina2xx_read_init(struct device *dev, int reg, long *val)
254271 unsigned int regval ;
255272 int ret , retry ;
256273
274+ if (data -> config -> has_ishunt ) {
275+ /* No calibration needed */
276+ ret = regmap_read (regmap , reg , & regval );
277+ if (ret < 0 )
278+ return ret ;
279+ * val = ina2xx_get_value (data , reg , regval );
280+ return 0 ;
281+ }
282+
257283 for (retry = 5 ; retry ; retry -- ) {
258284 ret = regmap_read (regmap , reg , & regval );
259285 if (ret < 0 )
@@ -682,7 +708,7 @@ static umode_t ina2xx_is_visible(const void *_data, enum hwmon_sensor_types type
682708 case hwmon_chip :
683709 switch (attr ) {
684710 case hwmon_chip_update_interval :
685- if (chip == ina226 )
711+ if (chip == ina226 || chip == ina260 )
686712 return 0644 ;
687713 break ;
688714 default :
@@ -791,7 +817,9 @@ static int ina2xx_init(struct device *dev, struct ina2xx_data *data)
791817 u32 shunt ;
792818 int ret ;
793819
794- if (device_property_read_u32 (dev , "shunt-resistor" , & shunt ) < 0 )
820+ if (data -> config -> has_ishunt )
821+ shunt = INA260_RSHUNT ;
822+ else if (device_property_read_u32 (dev , "shunt-resistor" , & shunt ) < 0 )
795823 shunt = INA2XX_RSHUNT_DEFAULT ;
796824
797825 ret = ina2xx_set_shunt (data , shunt );
@@ -811,6 +839,9 @@ static int ina2xx_init(struct device *dev, struct ina2xx_data *data)
811839 FIELD_PREP (INA226_ALERT_POLARITY , active_high ));
812840 }
813841
842+ if (data -> config -> has_ishunt )
843+ return 0 ;
844+
814845 /*
815846 * Calibration register is set to the best value, which eliminates
816847 * truncation errors on calculating current register in hardware.
@@ -856,7 +887,8 @@ static int ina2xx_probe(struct i2c_client *client)
856887
857888 hwmon_dev = devm_hwmon_device_register_with_info (dev , client -> name ,
858889 data , & ina2xx_chip_info ,
859- ina2xx_groups );
890+ data -> config -> has_ishunt ?
891+ NULL : ina2xx_groups );
860892 if (IS_ERR (hwmon_dev ))
861893 return PTR_ERR (hwmon_dev );
862894
@@ -872,6 +904,7 @@ static const struct i2c_device_id ina2xx_id[] = {
872904 { "ina226" , ina226 },
873905 { "ina230" , ina226 },
874906 { "ina231" , ina226 },
907+ { "ina260" , ina260 },
875908 { }
876909};
877910MODULE_DEVICE_TABLE (i2c , ina2xx_id );
@@ -897,6 +930,10 @@ static const struct of_device_id __maybe_unused ina2xx_of_match[] = {
897930 .compatible = "ti,ina231" ,
898931 .data = (void * )ina226
899932 },
933+ {
934+ .compatible = "ti,ina260" ,
935+ .data = (void * )ina260
936+ },
900937 { },
901938};
902939MODULE_DEVICE_TABLE (of , ina2xx_of_match );
0 commit comments