[PATCH 2/2] iio: proximity: hx9023s: Add performance tuning function

Yasin Lee posted 2 patches 2 months, 1 week ago
There is a newer version of this series
[PATCH 2/2] iio: proximity: hx9023s: Add performance tuning function
Posted by Yasin Lee 2 months, 1 week ago
When hardware design introduces significant sensor data noise,
performance can be improved by adjusting register settings.

Signed-off-by: Yasin Lee <yasin.lee.x@gmail.com>
---
 drivers/iio/proximity/hx9023s.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/drivers/iio/proximity/hx9023s.c b/drivers/iio/proximity/hx9023s.c
index 8b9f84400e00..963da240c9b9 100644
--- a/drivers/iio/proximity/hx9023s.c
+++ b/drivers/iio/proximity/hx9023s.c
@@ -582,6 +582,39 @@ static int hx9023s_ch_en(struct hx9023s_data *data, u8 ch_id, bool en)
 	return regmap_write(data->regmap, HX9023S_CH_NUM_CFG, data->ch_en_stat);
 }
 
+static int hx9023s_performance_tuning(struct hx9023s_data *data)
+{
+	int ret;
+	u32 i, len;
+	u8 *reg_init;
+	u8 reg, val;
+	struct device *dev = regmap_get_device(data->regmap);
+	struct fwnode_handle *fwnode = dev_fwnode(dev);
+
+	ret = fwnode_property_read_u8_array(fwnode, "tyhx,performance-tuning", NULL, 0);
+	if (ret < 0)
+		return ret;
+
+	len = ret;
+	reg_init = devm_kmalloc(dev, len, GFP_KERNEL);
+	if (!reg_init)
+		return -ENOMEM;
+
+	ret = fwnode_property_read_u8_array(fwnode, "tyhx,performance-tuning", reg_init, len);
+	if (ret < 0)
+		return ret;
+
+	for (i = 0; i < len; i += 2) {
+		reg = reg_init[i];
+		val = reg_init[i + 1];
+		ret = regmap_write(data->regmap, reg, val);
+		if (ret)
+			return ret;
+	}
+
+	return ret;
+}
+
 static int hx9023s_property_get(struct hx9023s_data *data)
 {
 	struct device *dev = regmap_get_device(data->regmap);
@@ -1045,6 +1078,10 @@ static int hx9023s_probe(struct i2c_client *client)
 	if (ret)
 		return dev_err_probe(dev, ret, "channel config failed\n");
 
+	ret = hx9023s_performance_tuning(data);
+	if (ret)
+		dev_warn(dev, "performance tuning not configured\n");
+
 	ret = regcache_sync(data->regmap);
 	if (ret)
 		return dev_err_probe(dev, ret, "regcache sync failed\n");

-- 
2.43.0