From nobody Sun May 24 19:34:44 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E13A338A71E; Fri, 22 May 2026 07:03:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779433389; cv=none; b=PEJ/zEfrPJkpIv7/LW79JSIhBX7XHwNFxOZQl9q6wNlOZw/iTA/+HvNRRpffGTtXv3Db13opqMDmQ6WH/Ek1tph8o1qw/fp8px8cnWX8Uo9l+NPizGL1NuqLZXVVHGbOLYMq+NJwSjr0cRNceVFbopGUdsNj6H6BaAUPiHSCjzU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779433389; c=relaxed/simple; bh=yYcqTTeh6agzNk5FRYqH8kRI870V92dxNcpUpTnbx8U=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=B4KEGV7mnUiLoI6pCar0Xwy17I1abpdYTio2RxAoUajZQKxV8CFwCWU3hvONs0/nNasZN81+u32bYiuOhtRGFjKvkmipU90sFGgUsNESeQ300eqAUfbri3uH4z0YpZ9h5v9gP6SdsdcLkUFPtoNCHm3gSqHYkazHfKFr9DAKs2c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Qeqx3BEM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Qeqx3BEM" Received: by smtp.kernel.org (Postfix) with ESMTPS id 962D3C2BCB9; Fri, 22 May 2026 07:03:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1779433388; bh=yYcqTTeh6agzNk5FRYqH8kRI870V92dxNcpUpTnbx8U=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Qeqx3BEMJfI9FnRQU/6JfIdyOeM4HNPq2kQTbggLAwahGxBrjMgzrFVmMi/WweVt1 Aa5i+vAcuTzzg++TkYsaLqHXOfqB9jkabwFc2cjggNlq/WYLQdANK2NR0dZBm/xWSP YqN+XCLyGkSpNyC3ICuiT4gwpu+akqfeQ9Z1b9yvlMG3vFHWhQP0zaad5xSrrT2AAB vQaFWibJQQlIjjNdnEpDQpxMjgfkaMI0aKpAovzALOo/5ZuZSwaL72Z1/BFrrTr5vY Si/jp7YHBVmwihTfqQQ3alFmJJkxH4c36q3Y1KIQAibUHcTS+VT5+0P98RKROqQBkp x16UVIvn69ZSQ== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7EAF9CD5BB3; Fri, 22 May 2026 07:03:08 +0000 (UTC) From: Ferdinand Schwenk via B4 Relay Date: Fri, 22 May 2026 09:03:03 +0200 Subject: [PATCH 1/2] hwmon: ina238: add support for samples and update_interval Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260522-hwmon-ina238-add-samples-update-interval-v1-1-e1acfceb447e@advastore.com> References: <20260522-hwmon-ina238-add-samples-update-interval-v1-0-e1acfceb447e@advastore.com> In-Reply-To: <20260522-hwmon-ina238-add-samples-update-interval-v1-0-e1acfceb447e@advastore.com> To: Guenter Roeck Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, Ferdinand Schwenk , richard.leitner@linux.dev X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1779433387; l=10169; i=ferdinand.schwenk@advastore.com; h=from:subject:message-id; bh=qOCT87r9tkiUVpMP5kBu46CuXo6I/BDPAkV57Ut6MtU=; b=r0G+5dH0VCYRwtI897BhMRL1keVU3Q0UDr+LHERotYudalQcVLnkZDVyQbK3jzCILUMNuvL+9 r2VvSdjpogdAz+cwMPb3dbLmJUpWQX3uC1OGlYaSac8uFutc8tIrmMS X-Developer-Key: i=ferdinand.schwenk@advastore.com; a=ed25519; pk=HyA9NdHJ7NystP+1SyuWJeyXNH2EO4A09FXli9mfs9Q= X-Endpoint-Received: by B4 Relay for ferdinand.schwenk@advastore.com/default with auth_id=788 X-Original-From: Ferdinand Schwenk Reply-To: ferdinand.schwenk@advastore.com From: Ferdinand Schwenk The INA238 ADC_CONFIG register (address 0x1) exposes three conversion time fields (VBUSCT, VSHCT, VTCT) and an averaging count field (AVG) that allow tuning measurement bandwidth and noise rejection. Expose these as the standard hwmon chip-level attributes: chip/samples - R/W averaging count (1, 4, 16, 64, 128, 256, 512, 1024) chip/update_interval - R/W total conversion cycle time in ms Reading update_interval returns the sum of the current VBUSCT, VSHCT and VTCT conversion times. Writing it distributes the desired period equally across all three fields by selecting the closest supported conversion time for each, taking the current averaging count into account. The SQ52206 (Silergy) uses the same register layout but different absolute conversion time values (e.g. 66 us instead of 50 us at index 0). A per-chip conversion-time lookup table is introduced in struct ina238_config so that the same read/write helpers work correctly for all variants: ina228, ina237, ina238, ina700, ina780 (all using ina238_conv_time[]) and sq52206 (sq52206_conv_time[]). The ADC_CONFIG register value is cached in struct ina238_data (adc_config) so that read-modify-write updates can be performed without an extra register read on every write. Signed-off-by: Ferdinand Schwenk --- drivers/hwmon/ina238.c | 131 +++++++++++++++++++++++++++++++++++++++++++++= +++- 1 file changed, 129 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/ina238.c b/drivers/hwmon/ina238.c index ff67b03189f7..7bc18e5445b2 100644 --- a/drivers/hwmon/ina238.c +++ b/drivers/hwmon/ina238.c @@ -15,6 +15,7 @@ #include #include #include +#include =20 /* INA238 register definitions */ #define INA238_CONFIG 0x0 @@ -49,6 +50,17 @@ #define INA238_DIAG_ALERT_BUSUL BIT(3) #define INA238_DIAG_ALERT_POL BIT(2) =20 +/* INA238_ADC_CONFIG register field masks and shifts */ +#define INA238_ADC_CONFIG_MODE_MASK GENMASK(15, 12) +#define INA238_ADC_CONFIG_VBUSCT_SHIFT 9 +#define INA238_ADC_CONFIG_VBUSCT_MASK GENMASK(11, 9) +#define INA238_ADC_CONFIG_VSHCT_SHIFT 6 +#define INA238_ADC_CONFIG_VSHCT_MASK GENMASK(8, 6) +#define INA238_ADC_CONFIG_VTCT_SHIFT 3 +#define INA238_ADC_CONFIG_VTCT_MASK GENMASK(5, 3) +#define INA238_ADC_CONFIG_AVG_SHIFT 0 +#define INA238_ADC_CONFIG_AVG_MASK GENMASK(2, 0) + #define INA238_REGISTERS 0x20 =20 #define INA238_RSHUNT_DEFAULT 2500 /* uOhm */ @@ -101,6 +113,21 @@ static const struct regmap_config ina238_regmap_config= =3D { .val_bits =3D 16, }; =20 +/* Lookup table for conversion times in usec for INA238 family */ +static const u16 ina238_conv_time[] =3D { + 50, 84, 150, 280, 540, 1052, 2074, 4120, +}; + +/* Lookup table for conversion times in usec for SQ52206 */ +static const u16 sq52206_conv_time[] =3D { + 66, 118, 310, 566, 1070, 2090, 4140, 8230, +}; + +/* Lookup table for number of samples used in averaging mode */ +static const int ina238_avg_samples[] =3D { + 1, 4, 16, 64, 128, 256, 512, 1024, +}; + enum ina238_ids { ina228, ina237, ina238, ina700, ina780, sq52206 }; =20 struct ina238_config { @@ -112,6 +139,7 @@ struct ina238_config { u32 power_calculate_factor; /* fixed parameter for power calculation, fro= m datasheet */ u32 bus_voltage_lsb; /* bus voltage LSB, in nV */ int current_lsb; /* current LSB, in uA */ + const u16 *conv_time; /* conversion time lookup table */ }; =20 struct ina238_data { @@ -124,6 +152,7 @@ struct ina238_data { int current_lsb; /* current LSB, in uA */ int power_lsb; /* power LSB, in uW */ int energy_lsb; /* energy LSB, in uJ */ + u16 adc_config; /* cached ADC_CONFIG register value */ }; =20 static const struct ina238_config ina238_config[] =3D { @@ -135,6 +164,7 @@ static const struct ina238_config ina238_config[] =3D { .config_default =3D INA238_CONFIG_DEFAULT, .bus_voltage_lsb =3D INA238_BUS_VOLTAGE_LSB, .temp_resolution =3D 16, + .conv_time =3D ina238_conv_time, }, [ina237] =3D { .has_20bit_voltage_current =3D false, @@ -144,6 +174,7 @@ static const struct ina238_config ina238_config[] =3D { .config_default =3D INA238_CONFIG_DEFAULT, .bus_voltage_lsb =3D INA238_BUS_VOLTAGE_LSB, .temp_resolution =3D 12, + .conv_time =3D ina238_conv_time, }, [ina238] =3D { .has_20bit_voltage_current =3D false, @@ -153,6 +184,7 @@ static const struct ina238_config ina238_config[] =3D { .config_default =3D INA238_CONFIG_DEFAULT, .bus_voltage_lsb =3D INA238_BUS_VOLTAGE_LSB, .temp_resolution =3D 12, + .conv_time =3D ina238_conv_time, }, [ina700] =3D { .has_20bit_voltage_current =3D false, @@ -163,6 +195,7 @@ static const struct ina238_config ina238_config[] =3D { .bus_voltage_lsb =3D INA238_BUS_VOLTAGE_LSB, .temp_resolution =3D 12, .current_lsb =3D 480, + .conv_time =3D ina238_conv_time, }, [ina780] =3D { .has_20bit_voltage_current =3D false, @@ -173,6 +206,7 @@ static const struct ina238_config ina238_config[] =3D { .bus_voltage_lsb =3D INA238_BUS_VOLTAGE_LSB, .temp_resolution =3D 12, .current_lsb =3D 2400, + .conv_time =3D ina238_conv_time, }, [sq52206] =3D { .has_20bit_voltage_current =3D false, @@ -182,6 +216,7 @@ static const struct ina238_config ina238_config[] =3D { .config_default =3D SQ52206_CONFIG_DEFAULT, .bus_voltage_lsb =3D SQ52206_BUS_VOLTAGE_LSB, .temp_resolution =3D 16, + .conv_time =3D sq52206_conv_time, }, }; =20 @@ -261,6 +296,83 @@ static int ina228_read_voltage(struct ina238_data *dat= a, int channel, long *val) return 0; } =20 +/* Converting ADC_CONFIG register value to update_interval in usec */ +static inline u32 ina238_reg_to_interval_us(struct ina238_data *data) +{ + const u16 *ct =3D data->config->conv_time; + u32 vbusct =3D ct[(data->adc_config & INA238_ADC_CONFIG_VBUSCT_MASK) >> + INA238_ADC_CONFIG_VBUSCT_SHIFT]; + u32 vshct =3D ct[(data->adc_config & INA238_ADC_CONFIG_VSHCT_MASK) >> + INA238_ADC_CONFIG_VSHCT_SHIFT]; + u32 vtct =3D ct[(data->adc_config & INA238_ADC_CONFIG_VTCT_MASK) >> + INA238_ADC_CONFIG_VTCT_SHIFT]; + + return vbusct + vshct + vtct; +} + +/* Converting update_interval in msec to a single conversion time in usec = */ +static inline u32 ina238_interval_ms_to_conv_time(long interval) +{ + /* 3 equal conversion times (VBUSCT, VSHCT, VTCT) cover all measurement t= ypes */ + return DIV_ROUND_CLOSEST(interval * 1000, 3); +} + +static int ina238_read_chip(struct device *dev, u32 attr, long *val) +{ + struct ina238_data *data =3D dev_get_drvdata(dev); + + switch (attr) { + case hwmon_chip_samples: + *val =3D ina238_avg_samples[(data->adc_config & INA238_ADC_CONFIG_AVG_MA= SK) >> + INA238_ADC_CONFIG_AVG_SHIFT]; + return 0; + case hwmon_chip_update_interval: + /* Return in msec */ + *val =3D DIV_ROUND_CLOSEST(ina238_reg_to_interval_us(data), 1000); + return 0; + default: + return -EOPNOTSUPP; + } +} + +static int ina238_write_chip(struct device *dev, u32 attr, long val) +{ + struct ina238_data *data =3D dev_get_drvdata(dev); + u16 adc_config; + int idx, ret; + + switch (attr) { + case hwmon_chip_samples: + idx =3D find_closest(val, ina238_avg_samples, + ARRAY_SIZE(ina238_avg_samples)); + adc_config =3D (data->adc_config & ~INA238_ADC_CONFIG_AVG_MASK) | + (idx << INA238_ADC_CONFIG_AVG_SHIFT); + ret =3D regmap_write(data->regmap, INA238_ADC_CONFIG, adc_config); + if (ret) + return ret; + data->adc_config =3D adc_config; + return 0; + case hwmon_chip_update_interval: + val =3D ina238_interval_ms_to_conv_time(val); + idx =3D find_closest(val, data->config->conv_time, + ARRAY_SIZE(ina238_conv_time)); + adc_config =3D (data->adc_config & + ~(INA238_ADC_CONFIG_VBUSCT_MASK | + INA238_ADC_CONFIG_VSHCT_MASK | + INA238_ADC_CONFIG_VTCT_MASK)) | + ((u16)idx << INA238_ADC_CONFIG_VBUSCT_SHIFT) | + ((u16)idx << INA238_ADC_CONFIG_VSHCT_SHIFT) | + ((u16)idx << INA238_ADC_CONFIG_VTCT_SHIFT); + ret =3D regmap_write(data->regmap, INA238_ADC_CONFIG, adc_config); + if (ret) + return ret; + data->adc_config =3D adc_config; + return 0; + default: + return -EOPNOTSUPP; + } +} + static int ina238_read_in(struct device *dev, u32 attr, int channel, long *val) { @@ -587,6 +699,8 @@ static int ina238_read(struct device *dev, enum hwmon_s= ensor_types type, u32 attr, int channel, long *val) { switch (type) { + case hwmon_chip: + return ina238_read_chip(dev, attr, val); case hwmon_in: return ina238_read_in(dev, attr, channel, val); case hwmon_curr: @@ -607,6 +721,8 @@ static int ina238_write(struct device *dev, enum hwmon_= sensor_types type, u32 attr, int channel, long val) { switch (type) { + case hwmon_chip: + return ina238_write_chip(dev, attr, val); case hwmon_in: return ina238_write_in(dev, attr, channel, val); case hwmon_curr: @@ -629,6 +745,14 @@ static umode_t ina238_is_visible(const void *drvdata, bool has_energy =3D data->config->has_energy; =20 switch (type) { + case hwmon_chip: + switch (attr) { + case hwmon_chip_samples: + case hwmon_chip_update_interval: + return 0644; + default: + return 0; + } case hwmon_in: switch (attr) { case hwmon_in_input: @@ -692,6 +816,9 @@ static umode_t ina238_is_visible(const void *drvdata, HWMON_I_MIN | HWMON_I_MIN_ALARM) =20 static const struct hwmon_channel_info * const ina238_info[] =3D { + HWMON_CHANNEL_INFO(chip, + HWMON_C_SAMPLES, + HWMON_C_UPDATE_INTERVAL), HWMON_CHANNEL_INFO(in, /* 0: shunt voltage */ INA238_HWMON_IN_CONFIG, @@ -798,8 +925,8 @@ static int ina238_probe(struct i2c_client *client) } =20 /* Setup ADC_CONFIG register */ - ret =3D regmap_write(data->regmap, INA238_ADC_CONFIG, - INA238_ADC_CONFIG_DEFAULT); + data->adc_config =3D INA238_ADC_CONFIG_DEFAULT; + ret =3D regmap_write(data->regmap, INA238_ADC_CONFIG, data->adc_config); if (ret < 0) { dev_err(dev, "error configuring the device: %d\n", ret); return -ENODEV; --=20 2.54.0 From nobody Sun May 24 19:34:44 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E142A38AC75; Fri, 22 May 2026 07:03:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779433389; cv=none; b=NUpvxdSUlcWMJmjWtopl6pz07CW5Ye3k8nbldaHZdXN1kD9K6YumEwhm+sDlHAD1NOdad7FeltC3tmiIDr89zcrqd+Po/NVMYuLFR3ISrEbhhUzpZa+tkrhph083PpGCgEcXbt56ZpBxy0czoBE0OR4fuAWDe12hcZ9M5LV9Z+s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779433389; c=relaxed/simple; bh=H36JfpufFMHguvvVvERm/Q6MLHijFXaHhlkriMQbcqs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mVjMHDz2wKjGn6MDJAYJgfi6CJaLLwNlx3yFB+9xUWk1RO9odoDO9x6II2E+ty7fJrDgLn4Ztt8oUAwcv0T//70W170W4K6eoh13Gm7JTLAesy4Fc+Bx0LvaJlbdPzp6kBOjz4acLlxeW7AEu117ectcRCqBu9vpIFRu0/2R6cU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=b6pJzy5i; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="b6pJzy5i" Received: by smtp.kernel.org (Postfix) with ESMTPS id 995B0C2BCB8; Fri, 22 May 2026 07:03:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1779433388; bh=H36JfpufFMHguvvVvERm/Q6MLHijFXaHhlkriMQbcqs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=b6pJzy5iBMzsRC+khrRAwjN3Xn/DT8Ed3CCq/2Tw+mAmHONsvFwxYxKmEDuH3QdHw 7FAYcR5ryHDNcD7NXdX+Q1RnvXq8l953fsczBpHnsGCtlVq+lf2K3DAq1PKvzv1JZI kFFlIUGP9splJqGPeODYV8Z2U08eVlvMTDQmTHNLw/Z5NjhPYxCUnFcUIFYgLDfdHq 9ruvvrcqU8MZB06fq/XzHahZkmv5j+ZOePfrXnJjaum7a++vV5XZVeCwWowjLJoGky Z3CHsAB2JASJoT6CzG3SwfUhCDqzn8SebJI9aRviybogiuPTJJOTlB15o6AOCwZqI2 D+ndFMaUR8xAA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8C02ACD4F5B; Fri, 22 May 2026 07:03:08 +0000 (UTC) From: Ferdinand Schwenk via B4 Relay Date: Fri, 22 May 2026 09:03:04 +0200 Subject: [PATCH 2/2] hwmon: ina238: use microseconds for update_interval Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260522-hwmon-ina238-add-samples-update-interval-v1-2-e1acfceb447e@advastore.com> References: <20260522-hwmon-ina238-add-samples-update-interval-v1-0-e1acfceb447e@advastore.com> In-Reply-To: <20260522-hwmon-ina238-add-samples-update-interval-v1-0-e1acfceb447e@advastore.com> To: Guenter Roeck Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, Ferdinand Schwenk , richard.leitner@linux.dev X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1779433387; l=2579; i=ferdinand.schwenk@advastore.com; h=from:subject:message-id; bh=KeLuR0DMJGXjRXZhPZZdfG5JTrn6BSTR1NGiLJba5h0=; b=58JhpNE8ZcsEFAY2pQ2npS/aRIX7Nz5LWfQ7pjRbRXeVJQLAqAPz03EMPSDzGnTB1f3CcQ7UO mTcfZpza7sMBZUaMfc/1EGT0cYey6sj08ATGffT/fqt1a54h+nhYCLQ X-Developer-Key: i=ferdinand.schwenk@advastore.com; a=ed25519; pk=HyA9NdHJ7NystP+1SyuWJeyXNH2EO4A09FXli9mfs9Q= X-Endpoint-Received: by B4 Relay for ferdinand.schwenk@advastore.com/default with auth_id=788 X-Original-From: Ferdinand Schwenk Reply-To: ferdinand.schwenk@advastore.com From: Ferdinand Schwenk The INA238 family supports conversion times as low as 50 us. The standard hwmon sysfs ABI unit for update_interval is milliseconds, which causes sub-millisecond conversion times to round to zero and makes fine-grained control impossible. Change the unit of chip/update_interval from milliseconds to microseconds so that all eight conversion-time steps (50, 84, 150, 280, 540, 1052, 2074, 4120 us for INA238 and 66, 118, 310, 566, 1070, 2090, 4140, 8230 us for SQ52206) are accessible without loss of precision. Signed-off-by: Ferdinand Schwenk --- drivers/hwmon/ina238.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/drivers/hwmon/ina238.c b/drivers/hwmon/ina238.c index 7bc18e5445b2..db0c0b5344d6 100644 --- a/drivers/hwmon/ina238.c +++ b/drivers/hwmon/ina238.c @@ -310,11 +310,14 @@ static inline u32 ina238_reg_to_interval_us(struct in= a238_data *data) return vbusct + vshct + vtct; } =20 -/* Converting update_interval in msec to a single conversion time in usec = */ -static inline u32 ina238_interval_ms_to_conv_time(long interval) +/* Converting update_interval in usec to a single conversion time in usec. + * update_interval represents the raw ADC cycle time (VBUSCT + VSHCT + VTC= T), + * independent of averaging. Since all three fields are always set equal, + * the target per-field conversion time is simply interval / 3. + */ +static inline u32 ina238_interval_us_to_conv_time(long interval) { - /* 3 equal conversion times (VBUSCT, VSHCT, VTCT) cover all measurement t= ypes */ - return DIV_ROUND_CLOSEST(interval * 1000, 3); + return DIV_ROUND_CLOSEST(interval, 3); } =20 static int ina238_read_chip(struct device *dev, u32 attr, long *val) @@ -327,8 +330,8 @@ static int ina238_read_chip(struct device *dev, u32 att= r, long *val) INA238_ADC_CONFIG_AVG_SHIFT]; return 0; case hwmon_chip_update_interval: - /* Return in msec */ - *val =3D DIV_ROUND_CLOSEST(ina238_reg_to_interval_us(data), 1000); + /* Return in usec */ + *val =3D ina238_reg_to_interval_us(data); return 0; default: return -EOPNOTSUPP; @@ -353,7 +356,7 @@ static int ina238_write_chip(struct device *dev, u32 at= tr, long val) data->adc_config =3D adc_config; return 0; case hwmon_chip_update_interval: - val =3D ina238_interval_ms_to_conv_time(val); + val =3D ina238_interval_us_to_conv_time(val); idx =3D find_closest(val, data->config->conv_time, ARRAY_SIZE(ina238_conv_time)); adc_config =3D (data->adc_config & --=20 2.54.0