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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When hardware design introduces significant sensor data noise,
performance can be improved by adjusting register settings.

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

diff --git a/drivers/iio/proximity/hx9023s.c b/drivers/iio/proximity/hx9023s.c
index 8b9f84400e00..8f7995816545 100644
--- a/drivers/iio/proximity/hx9023s.c
+++ b/drivers/iio/proximity/hx9023s.c
@@ -582,6 +582,47 @@ 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 addr_val[512];
+	struct device *dev = regmap_get_device(data->regmap);
+	struct fwnode_handle *fwnode = dev_fwnode(dev);
+
+	ret = fwnode_property_count_u8(fwnode, "tyhx,performance-tuning");
+	if (ret < 2 || ret > 512) {
+		if (ret < 0) {
+			dev_err(dev, "Failed to get length of property\n");
+			return ret;
+		}
+		dev_err(dev, "The property requires between 2 and 512 elements\n");
+		return -EINVAL;
+	}
+
+	len = ret;
+	if (len % 2 != 0) {
+		dev_err(dev, "The property must contain an even number of elements\n");
+		return -EINVAL;
+	}
+
+	ret = fwnode_property_read_u8_array(fwnode, "tyhx,performance-tuning", addr_val, len);
+	if (ret < 0) {
+		dev_err(dev, "Failed to read property\n");
+		return ret;
+	}
+
+	for (i = 0; i < len; i += 2) {
+		ret = regmap_write(data->regmap, addr_val[i], addr_val[i + 1]);
+		if (ret) {
+			dev_err(dev, "Failed to write register\n");
+			return ret;
+		}
+	}
+
+	return ret;
+}
+
 static int hx9023s_property_get(struct hx9023s_data *data)
 {
 	struct device *dev = regmap_get_device(data->regmap);
@@ -1045,6 +1086,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





[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux