[PATCH v6 4/8] iio: adc: at91_adc: convert to device_property_*() APIs

Abdelnasser Hussein abdelnasserhussein11 at gmail.com
Thu Dec 3 09:30:08 PST 2026


Read the atmel,adc-* properties through device_property_*() in
at91_adc_probe() and at91_adc_probe_ts(), dropping the local
device_node.

Use a local struct device pointer and a propname variable, return the
actual property-read error with the property name in the message, and
replace the atmel,adc-use-res string comparison with
device_property_match_string().

With the of_* helpers gone, drop <linux/of.h> (<linux/platform_device.h>
already provides struct of_device_id).

Signed-off-by: Abdelnasser Hussein <abdelnasserhussein11 at gmail.com>
---
 drivers/iio/adc/at91_adc.c | 60 +++++++++++++++++++++++++++-------------------
 1 file changed, 35 insertions(+), 25 deletions(-)

diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
index 9439eef7b564..cbaad9473239 100644
--- a/drivers/iio/adc/at91_adc.c
+++ b/drivers/iio/adc/at91_adc.c
@@ -16,7 +16,6 @@
 #include <linux/jiffies.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
-#include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/property.h>
 #include <linux/sched.h>
@@ -798,13 +797,14 @@ static u32 calc_startup_ticks_9x5(u32 startup_time, u32 adc_clk_khz)
 	return ticks;
 }
 
-static int at91_adc_probe_dt_ts(struct device_node *node,
-	struct at91_adc_state *st, struct device *dev)
+static int at91_adc_probe_ts(struct device *dev, struct at91_adc_state *st)
 {
+	const char *propname;
 	int ret;
 	u32 prop;
 
-	ret = of_property_read_u32(node, "atmel,adc-ts-wires", &prop);
+	propname = "atmel,adc-ts-wires";
+	ret = device_property_read_u32(dev, propname, &prop);
 	if (ret) {
 		dev_info(dev, "ADC Touch screen is disabled.\n");
 		return 0;
@@ -822,15 +822,20 @@ static int at91_adc_probe_dt_ts(struct device_node *node,
 
 	if (!st->caps->has_tsmr)
 		return 0;
+
 	prop = 0;
-	of_property_read_u32(node, "atmel,adc-ts-pressure-threshold", &prop);
+	propname = "atmel,adc-ts-pressure-threshold";
+	ret = device_property_read_u32(dev, propname, &prop);
+	if (ret)
+		return dev_err_probe(dev, ret, "Missing %s property.\n", propname);
+
 	st->ts_pressure_threshold = prop;
-	if (st->ts_pressure_threshold) {
-		return 0;
-	} else {
+	if (!st->ts_pressure_threshold) {
 		dev_err(dev, "Invalid pressure threshold for the touchscreen\n");
 		return -EINVAL;
 	}
+
+	return 0;
 }
 
 static const struct iio_info at91_adc_info = {
@@ -998,12 +1003,12 @@ static void at91_ts_unregister(struct at91_adc_state *st)
 static int at91_adc_probe(struct platform_device *pdev)
 {
 	unsigned int prsc, mstrclk, ticks, adc_clk, adc_clk_khz, shtim;
-	struct device_node *node = pdev->dev.of_node;
+	struct device *dev = &pdev->dev;
+	const char *propname;
 	int ret;
 	struct iio_dev *idev;
 	struct at91_adc_state *st;
 	u32 reg, prop;
-	const char *s;
 
 	idev = devm_iio_device_alloc(&pdev->dev, sizeof(struct at91_adc_state));
 	if (!idev)
@@ -1015,33 +1020,38 @@ static int at91_adc_probe(struct platform_device *pdev)
 	if (!st->caps)
 		return -ENODATA;
 
-	st->use_external = of_property_read_bool(node, "atmel,adc-use-external-triggers");
+	propname = "atmel,adc-use-external-triggers";
+	st->use_external = device_property_read_bool(dev, propname);
 
-	if (of_property_read_u32(node, "atmel,adc-channels-used", &prop))
-		return dev_err_probe(&idev->dev, -EINVAL,
-				     "Missing adc-channels-used property in the DT.\n");
+	propname = "atmel,adc-channels-used";
+	ret = device_property_read_u32(dev, propname, &prop);
+	if (ret)
+		return dev_err_probe(dev, ret, "Missing %s property.\n", propname);
 	st->channels_mask = prop;
 
-	st->sleep_mode = of_property_read_bool(node, "atmel,adc-sleep-mode");
+	propname = "atmel,adc-sleep-mode";
+	st->sleep_mode = device_property_read_bool(dev, propname);
 
-	if (of_property_read_u32(node, "atmel,adc-startup-time", &prop))
-		return dev_err_probe(&idev->dev, -EINVAL,
-				     "Missing adc-startup-time property in the DT.\n");
+	propname = "atmel,adc-startup-time";
+	ret = device_property_read_u32(dev, propname, &prop);
+	if (ret)
+		return dev_err_probe(dev, ret, "Missing %s property.\n", propname);
 	st->startup_time = prop;
 
 	prop = 0;
-	of_property_read_u32(node, "atmel,adc-sample-hold-time", &prop);
+	propname = "atmel,adc-sample-hold-time";
+	device_property_read_u32(dev, propname, &prop);
 	st->sample_hold_time = prop;
 
-	if (of_property_read_u32(node, "atmel,adc-vref", &prop))
-		return dev_err_probe(&idev->dev, -EINVAL,
-				     "Missing adc-vref property in the DT.\n");
+	propname = "atmel,adc-vref";
+	ret = device_property_read_u32(dev, propname, &prop);
+	if (ret)
+		return dev_err_probe(dev, ret, "Missing %s property.\n", propname);
 	st->vref_mv = prop;
 
 	st->res = st->caps->high_res_bits;
 	if (st->caps->low_res_bits &&
-	    !of_property_read_string(node, "atmel,adc-use-res", &s)
-	    && !strcmp(s, "lowres"))
+	    device_property_match_string(dev, "atmel,adc-use-res", "lowres") >= 0)
 		st->res = st->caps->low_res_bits;
 
 	dev_info(&idev->dev, "Resolution used: %u bits\n", st->res);
@@ -1051,7 +1061,7 @@ static int at91_adc_probe(struct platform_device *pdev)
 
 	/* Check if touchscreen is supported. */
 	if (st->caps->has_ts) {
-		ret = at91_adc_probe_dt_ts(node, st, &idev->dev);
+		ret = at91_adc_probe_ts(dev, st);
 		if (ret)
 			return ret;
 	}

-- 
2.56.0




More information about the linux-arm-kernel mailing list