summaryrefslogtreecommitdiff
path: root/drivers/iio/proximity/sx9324.c
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2022-04-30 01:01:42 +0300
committerJonathan Cameron <Jonathan.Cameron@huawei.com>2022-06-14 13:53:11 +0300
commit71783b07aa0b3a17be3dc4599e81426ad6dd6555 (patch)
tree5a9725319f89dcc0808c0a38a923e59aa8d0a292 /drivers/iio/proximity/sx9324.c
parent67ac843324a569810dc6736e26bfdc362cdc8e24 (diff)
downloadlinux-71783b07aa0b3a17be3dc4599e81426ad6dd6555.tar.xz
iio: sx9324: Add Setting for internal analog gain
Based on device tree setting, set the internal analog gain. Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-by: Stephen Boyd <swboyd@chromium.org> Link: https://lore.kernel.org/r/20220429220144.1476049-9-gwendal@chromium.org Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Diffstat (limited to 'drivers/iio/proximity/sx9324.c')
-rw-r--r--drivers/iio/proximity/sx9324.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/drivers/iio/proximity/sx9324.c b/drivers/iio/proximity/sx9324.c
index 926a0da5915c..7f367f63e362 100644
--- a/drivers/iio/proximity/sx9324.c
+++ b/drivers/iio/proximity/sx9324.c
@@ -79,6 +79,7 @@
#define SX9324_REG_AFE_CTRL8_RESFILTIN_4KOHM 0x02
#define SX9324_REG_AFE_CTRL8_RESFILTIN_MASK GENMASK(3, 0)
#define SX9324_REG_AFE_CTRL9 0x2d
+#define SX9324_REG_AFE_CTRL9_AGAIN_MASK GENMASK(3, 0)
#define SX9324_REG_AFE_CTRL9_AGAIN_1 0x08
#define SX9324_REG_PROX_CTRL0 0x30
@@ -941,6 +942,27 @@ sx9324_get_default_reg(struct device *dev, int idx,
raw / 2000);
break;
+ case SX9324_REG_AFE_CTRL9:
+ ret = device_property_read_u32(dev,
+ "semtech,input-analog-gain", &raw);
+ if (ret)
+ break;
+ /*
+ * The analog gain has the following setting:
+ * +---------+----------------+----------------+
+ * | dt(raw) | physical value | register value |
+ * +---------+----------------+----------------+
+ * | 0 | x1.247 | 6 |
+ * | 1 | x1 | 8 |
+ * | 2 | x0.768 | 11 |
+ * | 3 | x0.552 | 15 |
+ * +---------+----------------+----------------+
+ */
+ reg_def->def &= ~SX9324_REG_AFE_CTRL9_AGAIN_MASK;
+ reg_def->def |= FIELD_PREP(SX9324_REG_AFE_CTRL9_AGAIN_MASK,
+ 6 + raw * (raw + 3) / 2);
+ break;
+
case SX9324_REG_ADV_CTRL5:
ret = device_property_read_u32(dev, "semtech,startup-sensor",
&start);