Skip to content

Commit 4081c82

Browse files
groeckLucasH-rp
authored andcommitted
70fb84a upstream merge
hwmon: (ina2xx) Add support for INA260 INA260 is similar to other chips of the series, except it has an internal shunt resistor. The calibration register is therefore not present. Also, the current register address was changed, though that does not matter for the driver since the shunt voltage register (which is now the current register) value is already used to read the current. Cc: Loic Guegan <[email protected]> Reviewed-by: Tzung-Bi Shih <[email protected]> Signed-off-by: Guenter Roeck <[email protected]>
1 parent b1b490b commit 4081c82

File tree

3 files changed

+62
-11
lines changed

3 files changed

+62
-11
lines changed

Documentation/hwmon/ina2xx.rst

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ Supported chips:
5353

5454
https://www.ti.com/
5555

56+
* Texas Instruments INA260
57+
58+
Prefix: 'ina260'
59+
60+
Addresses: I2C 0x40 - 0x4f
61+
62+
Datasheet: Publicly available at the Texas Instruments website
63+
64+
https://www.ti.com/
65+
5666
Author: Lothar Felten <[email protected]>
5767

5868
Description
@@ -72,6 +82,9 @@ INA230 and INA231 are high or low side current shunt and power monitors
7282
with an I2C interface. The chips monitor both a shunt voltage drop and
7383
bus supply voltage.
7484

85+
INA260 is a high or low side current and power monitor with integrated shunt
86+
resistor.
87+
7588
The shunt value in micro-ohms can be set via platform data or device tree at
7689
compile-time or via the shunt_resistor attribute in sysfs at run-time. Please
7790
refer to the Documentation/devicetree/bindings/hwmon/ti,ina2xx.yaml for bindings
@@ -87,16 +100,16 @@ The actual programmed interval may vary from the desired value.
87100
General sysfs entries
88101
---------------------
89102

90-
======================= ===============================
103+
======================= ===============================================
91104
in0_input Shunt voltage(mV) channel
92105
in1_input Bus voltage(mV) channel
93106
curr1_input Current(mA) measurement channel
94107
power1_input Power(uW) measurement channel
95-
shunt_resistor Shunt resistance(uOhm) channel
96-
======================= ===============================
108+
shunt_resistor Shunt resistance(uOhm) channel (not for ina260)
109+
======================= ===============================================
97110

98-
Sysfs entries for ina226, ina230 and ina231 only
99-
------------------------------------------------
111+
Additional sysfs entries for ina226, ina230, ina231, and ina260
112+
---------------------------------------------------------------
100113

101114
======================= ====================================================
102115
curr1_lcrit Critical low current

drivers/hwmon/Kconfig

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,11 +2167,12 @@ config SENSORS_INA2XX
21672167
select REGMAP_I2C
21682168
help
21692169
If you say yes here you get support for INA219, INA220, INA226,
2170-
INA230, and INA231 power monitor chips.
2170+
INA230, INA231, and INA260 power monitor chips.
21712171

21722172
The INA2xx driver is configured for the default configuration of
21732173
the part as described in the datasheet.
2174-
Default value for Rshunt is 10 mOhms.
2174+
Default value for Rshunt is 10 mOhms except for INA260 which has an
2175+
internal 2 mOhm shunt resistor.
21752176
This driver can also be built as a module. If so, the module
21762177
will be called ina2xx.
21772178

drivers/hwmon/ina2xx.c

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,14 @@
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

130132
struct 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
};
877910
MODULE_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
};
902939
MODULE_DEVICE_TABLE(of, ina2xx_of_match);

0 commit comments

Comments
 (0)