Linux IIO development
 help / color / mirror / Atom feed
From: Yasin Lee <yasin.lee.x@gmail.com>
To: Jonathan Cameron <jic23@kernel.org>,
	 Lars-Peter Clausen <lars@metafoo.de>,
	Rob Herring <robh@kernel.org>,
	 Krzysztof Kozlowski <krzk+dt@kernel.org>,
	 Conor Dooley <conor+dt@kernel.org>
Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	 linux-kernel@vger.kernel.org, Yasin Lee <yasin.lee.x@gmail.com>
Subject: [PATCH 2/2] iio: proximity: hx9023s: Add performance tuning function
Date: Mon, 23 Sep 2024 09:16:11 +0800	[thread overview]
Message-ID: <20240923-add-performance-tuning-configuration-v1-2-587220c8aece@gmail.com> (raw)
In-Reply-To: <20240923-add-performance-tuning-configuration-v1-0-587220c8aece@gmail.com>

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


      parent reply	other threads:[~2024-09-23  1:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-23  1:16 [PATCH 0/2] iio: proximity: hx9023s: Add performance tuning function Yasin Lee
2024-09-23  1:16 ` [PATCH 1/2] dt-bindings: iio: tyhx,hx9023s: Add performance tuning configuration Yasin Lee
2024-09-24 21:59   ` Rob Herring
2024-09-25 16:38     ` Yasin Lee
2024-09-23  1:16 ` Yasin Lee [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240923-add-performance-tuning-configuration-v1-2-587220c8aece@gmail.com \
    --to=yasin.lee.x@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jic23@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox