hwmon: (ina2xx) Add support for has_alerts configuration flag
Subsystems (2)
Guenter Roeck
maintainerPATCH 1/2 hwmon: (ina2xx) Add support for has_alerts configuration flag
Add configuration flag indicating if the chip supports alerts and limits to prepare for adding INA260 support.
--- drivers/hwmon/ina2xx.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/hwmon/ina2xx.c +11 -7
@@ -129,6 +129,7 @@ enum ina2xx_ids { ina219, ina226 };struct ina2xx_config {u16 config_default; +bool has_alerts;/* chip supports alerts and limits */ int calibration_value;int shunt_div;int bus_voltage_shift;
@@ -155,6 +156,7 @@ static const struct ina2xx_config ina2xx_config[] = { .bus_voltage_shift = 3, .bus_voltage_lsb = 4000, .power_lsb_factor = 20, + .has_alerts = false, }, [ina226] = { .config_default = INA226_CONFIG_DEFAULT,
@@ -163,6 +165,7 @@ static const struct ina2xx_config ina2xx_config[] = { .bus_voltage_shift = 0, .bus_voltage_lsb = 1250, .power_lsb_factor = 25, + .has_alerts = true, }, };
@@ -624,6 +627,7 @@ static umode_t ina2xx_is_visible(const void *_data, enum hwmon_sensor_types type u32 attr, int channel) {const struct ina2xx_data *data = _data; +bool has_alerts = data->config->has_alerts;enum ina2xx_ids chip = data->chip;switch (type) {
@@ -633,12 +637,12 @@ static umode_t ina2xx_is_visible(const void *_data, enum hwmon_sensor_types typereturn 0444 ;case hwmon_in_lcrit:case hwmon_in_crit: -if (chip == ina226) +if (has_alerts)return 0644 ;break ;case hwmon_in_lcrit_alarm:case hwmon_in_crit_alarm: -if (chip == ina226) +if (has_alerts)return 0444 ;break ;default :
@@ -651,12 +655,12 @@ static umode_t ina2xx_is_visible(const void *_data, enum hwmon_sensor_types typereturn 0444 ;case hwmon_curr_lcrit:case hwmon_curr_crit: -if (chip == ina226) +if (has_alerts)return 0644 ;break ;case hwmon_curr_lcrit_alarm:case hwmon_curr_crit_alarm: -if (chip == ina226) +if (has_alerts)return 0444 ;break ;default :
@@ -668,11 +672,11 @@ static umode_t ina2xx_is_visible(const void *_data, enum hwmon_sensor_types typecase hwmon_power_input:return 0444 ;case hwmon_power_crit: -if (chip == ina226) +if (has_alerts)return 0644 ;break ;case hwmon_power_crit_alarm: -if (chip == ina226) +if (has_alerts)return 0444 ;break ;default :
@@ -802,7 +806,7 @@ static int ina2xx_init(struct device *dev, struct ina2xx_data *data)if (ret <0 )return ret; -if (data->chip == ina226) { +if (data->config->has_alerts) {bool active_high =device_property_read_bool (dev,"ti,alert-polarity-active-high" ); regmap_update_bits(regmap, INA226_MASK_ENABLE,
Signature · 1 line
2.45.2
Guenter Roeck
maintainerPATCH 2/2 hwmon: (ina260) 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.
--- Documentation/hwmon/ina2xx.rst | 23 +++++++++++++++---- drivers/hwmon/Kconfig | 5 ++-- drivers/hwmon/ina2xx.c | 42 ++++++++++++++++++++++++++++++---- 3 files changed, 59 insertions(+), 11 deletions(-)
Documentation/hwmon/ina2xx.rst +18 -5
@@ -53,6 +53,16 @@ Supported chips: https://www.ti.com/ + * Texas Instruments INA260 + + Prefix: 'ina260' + + Addresses: I2C 0x40 - 0x4f + + Datasheet: Publicly available at the Texas Instruments website + + https://www.ti.com/ + Author: Lothar Felten <[email protected]> Description
@@ -72,6 +82,9 @@ INA230 and INA231 are high or low side current shunt and power monitors with an I2C interface. The chips monitor both a shunt voltage drop and bus supply voltage. +INA260 is a high or low side current and power monitor with integrated shunt +resistor. + The shunt value in micro-ohms can be set via platform data or device tree at compile-time or via the shunt_resistor attribute in sysfs at run-time. Please 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. General sysfs entries --------------------- -======================= =============================== +======================= =============================================== in0_input Shunt voltage(mV) channel in1_input Bus voltage(mV) channel curr1_input Current(mA) measurement channel power1_input Power(uW) measurement channel -shunt_resistor Shunt resistance(uOhm) channel -======================= =============================== +shunt_resistor Shunt resistance(uOhm) channel (not for ina260) +======================= =============================================== -Sysfs entries for ina226, ina230 and ina231 only ------------------------------------------------- +Additional sysfs entries for ina226, ina230, ina231, and ina260 +--------------------------------------------------------------- ======================= ==================================================== curr1_lcrit Critical low current
drivers/hwmon/Kconfig +3 -2
@@ -2162,11 +2162,12 @@ config SENSORS_INA2XX select REGMAP_I2C help If you say yes here you get support for INA219, INA220, INA226, - INA230, and INA231 power monitor chips. + INA230, INA231, and INA260 power monitor chips. The INA2xx driver is configured for the default configuration of the part as described in the datasheet. - Default value for Rshunt is 10 mOhms. + Default value for Rshunt is 10 mOhms except for INA260 which has an + internal 2 mOhm shunt resistor. This driver can also be built as a module. If so, the module will be called ina2xx.
drivers/hwmon/ina2xx.c +38 -4
118 lines not on this page · raw message
Signature · 1 line
2.45.2
Quoted 4 lines · Guenter Roeck
Add configuration flag indicating if the chip supports alerts and limits to prepare for adding INA260 support.
Signed-off-by Guenter Roeck <[email protected]>
drivers/hwmon/ina2xx.c static const struct ina2xx_config ina2xx_config[] = { · line 159
Quoted 5 lines
drivers/hwmon/ina2xx.c +1
-0@@ -155,6 +156,7 @@ static const struct ina2xx_config ina2xx_config[] = { .bus_voltage_shift = 3, .bus_voltage_lsb = 4000, .power_lsb_factor = 20, + .has_alerts = false,
No strong preference: or just don't set it.
Re: [PATCH 2/2] hwmon: (ina260) Add support for INA260
In reply to Guenter RoeckQuoted 8 lines · Guenter Roeck
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]>Signed-off-by Guenter Roeck <[email protected]>
drivers/hwmon/ina2xx.c static const struct ina2xx_config ina2xx_config[] = { · line 173
Quoted 13 lines
drivers/hwmon/ina2xx.c +2
-0@@ -157,6 +160,7 @@ static const struct ina2xx_config ina2xx_config[] = { .bus_voltage_lsb = 4000, .power_lsb_factor = 20, .has_alerts = false, + .has_ishunt = false, }, [ina226] = { .config_default = INA226_CONFIG_DEFAULT,@@ -166,6 +170,16 @@ static const struct ina2xx_config ina2xx_config[] = { .bus_voltage_lsb = 1250, .power_lsb_factor = 25, .has_alerts = true, + .has_ishunt = false,
No strong preference: or just don't set them.
Guenter Roeck
maintainerQuoted 8 lines · Tzung-Bi Shih
Quoted 4 lines · Guenter Roeck
Add configuration flag indicating if the chip supports alerts and limits to prepare for adding INA260 support.
Signed-off-by Guenter Roeck <[email protected]>Reviewed-by Tzung-Bi Shih <[email protected]>
Quoted 7 lines
drivers/hwmon/ina2xx.c static const struct ina2xx_config ina2xx_config[] = { · line 159
Quoted 5 lines
drivers/hwmon/ina2xx.c +1
-0@@ -155,6 +156,7 @@ static const struct ina2xx_config ina2xx_config[] = { .bus_voltage_shift = 3, .bus_voltage_lsb = 4000, .power_lsb_factor = 20, + .has_alerts = false,No strong preference: or just don't set it.
In situations like this I prefer to explicitly set the value to indicate that it wasn't forgotten.
Thanks a lot for the reviews!
Guenter