mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Antoniu Miclaus <antoniu.miclaus@analog.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Michael Hennerich <michael.hennerich@analog.com>,
	Antoniu Miclaus <antoniu.miclaus@analog.com>,
	<linux-input@vger.kernel.org>, <devicetree@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Subject: [PATCH v2 2/3] input: touchscreen: ad7877: add dt support
Date: Mon, 2 Sep 2024 11:24:32 +0300	[thread overview]
Message-ID: <20240902082707.4325-2-antoniu.miclaus@analog.com> (raw)
In-Reply-To: <20240902082707.4325-1-antoniu.miclaus@analog.com>

Add devicetree support within the driver.

Make the old platform data approach optional.

Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
---
new in v2.
 drivers/input/touchscreen/ad7877.c | 68 +++++++++++++++++++++++++++++-
 1 file changed, 66 insertions(+), 2 deletions(-)

diff --git a/drivers/input/touchscreen/ad7877.c b/drivers/input/touchscreen/ad7877.c
index 7886454a19c6..3fa38043b561 100644
--- a/drivers/input/touchscreen/ad7877.c
+++ b/drivers/input/touchscreen/ad7877.c
@@ -27,6 +27,7 @@
 #include <linux/input.h>
 #include <linux/interrupt.h>
 #include <linux/pm.h>
+#include <linux/property.h>
 #include <linux/slab.h>
 #include <linux/spi/spi.h>
 #include <linux/spi/ad7877.h>
@@ -667,6 +668,68 @@ static void ad7877_setup_ts_def_msg(struct spi_device *spi, struct ad7877 *ts)
 	}
 }
 
+static struct ad7877_platform_data *ad7877_parse_props(struct device *dev)
+{
+	struct ad7877_platform_data *pdata;
+	u32 value, average;
+
+	pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
+	if (!pdata)
+		return ERR_PTR(-ENOMEM);
+
+	pdata->model = (uintptr_t)device_get_match_data(dev);
+
+	device_property_read_u8(dev, "adi,stopacq-polarity",
+				&pdata->stopacq_polarity);
+	device_property_read_u8(dev, "adi,first-conv-delay",
+				&pdata->first_conversion_delay);
+	device_property_read_u8(dev, "adi,pen-down-acc-interval",
+				&pdata->pen_down_acc_interval);
+	device_property_read_u8(dev, "adi,acquisition-time",
+				&pdata->acquisition_time);
+
+	device_property_read_u16(dev, "adi,vref-delay-usecs",
+				 &pdata->vref_delay_usecs);
+
+	device_property_read_u32(dev, "touchscreen-x-plate-ohms", &value);
+	pdata->x_plate_ohms = (u16)value;
+	device_property_read_u32(dev, "touchscreen-y-plate-ohms", &value);
+	pdata->y_plate_ohms = (u16)value;
+	device_property_read_u32(dev, "touchscreen-min-x", &value);
+	pdata->x_min = (u16)value;
+	device_property_read_u32(dev, "touchscreen-min-y", &value);
+	pdata->y_min = (u16)value;
+	device_property_read_u32(dev, "touchscreen-max-x", &value);
+	pdata->x_max = (u16)value;
+	device_property_read_u32(dev, "touchscreen-max-y", &value);
+	pdata->y_max = (u16)value;
+	device_property_read_u32(dev, "touchscreen-max-pressure", &value);
+	pdata->pressure_max = (u16)value;
+	device_property_read_u32(dev, "touchscreen-min-pressure", &value);
+	pdata->pressure_min = (u16)value;
+	device_property_read_u32(dev, "touchscreen-average-samples", &average);
+	switch (average) {
+	case 1:
+		pdata->averaging = 0;
+		break;
+	case 4:
+		pdata->averaging = 1;
+		break;
+	case 8:
+		pdata->averaging = 2;
+		break;
+	case 16:
+		pdata->averaging = 3;
+		break;
+	default:
+		dev_err(dev,
+			"touchscreen-average-samples must be 1, 4, 8, or 16\n");
+		return ERR_PTR(-EINVAL);
+	}
+
+	return pdata;
+}
+
 static int ad7877_probe(struct spi_device *spi)
 {
 	struct ad7877			*ts;
@@ -681,8 +744,9 @@ static int ad7877_probe(struct spi_device *spi)
 	}
 
 	if (!pdata) {
-		dev_dbg(&spi->dev, "no platform data?\n");
-		return -ENODEV;
+		pdata = ad7877_parse_props(&spi->dev);
+		if (IS_ERR(pdata))
+			return PTR_ERR(pdata);
 	}
 
 	/* don't exceed max specified SPI CLK frequency */
-- 
2.46.0


  reply	other threads:[~2024-09-02  8:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-02  8:24 [PATCH v2 1/3] input: touchscreem: ad7877: add match table Antoniu Miclaus
2024-09-02  8:24 ` Antoniu Miclaus [this message]
2024-09-03 18:50   ` [PATCH v2 2/3] input: touchscreen: ad7877: add dt support Dmitry Torokhov
2024-09-02  8:24 ` [PATCH v2 3/3] dt-bindings: touchscreen: ad7877: add bindings Antoniu Miclaus
2024-09-02 11:52   ` Krzysztof Kozlowski

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=20240902082707.4325-2-antoniu.miclaus@analog.com \
    --to=antoniu.miclaus@analog.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael.hennerich@analog.com \
    --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

all inboxes | Powered by JetHome®