[PATCH v2 1/4] iio: proximity: aw96103: report negative proximity diff values

From: Arnav Kapoor

Date: Sat Nov 28 2026 - 06:52:08 EST


The DIFF registers hold a signed S21.10 fixed-point value (Awinic's own
aw_sar driver documents the diff data format as S21.10), which goes
negative when the measured capacitance drops below the baseline.
aw96103_get_diff_raw() divides it as a u32, so a diff of -1 (0xfffffc00)
is reported as 4194303 instead of -1.

Convert the value to int before the division instead of after it, and
declare it as unsigned int, the type regmap_read() takes.

Fixes: 07b241262dca ("iio: proximity: aw96103: Add support for aw96103/aw96105 proximity sensor")
Signed-off-by: Arnav Kapoor <kapoorarnav43@xxxxxxxxx>
---
drivers/iio/proximity/aw96103.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/proximity/aw96103.c b/drivers/iio/proximity/aw96103.c
index e3ab55170b6c..483b3bf18d19 100644
--- a/drivers/iio/proximity/aw96103.c
+++ b/drivers/iio/proximity/aw96103.c
@@ -261,14 +261,14 @@ static const struct regmap_config aw96103_regmap_confg = {
static int aw96103_get_diff_raw(struct aw96103 *aw96103, unsigned int chan,
int *buf)
{
- u32 data;
+ unsigned int data;
int ret;

ret = regmap_read(aw96103->regmap,
AW96103_REG_DIFF_CH0 + chan * 4, &data);
if (ret)
return ret;
- *buf = (int)(data / AW_DATA_PROCESS_FACTOR);
+ *buf = (int)data / AW_DATA_PROCESS_FACTOR;

return 0;
}
--
2.53.0