[PATCH v5 5/8] iio: adc: at91_adc: use local struct device pointer in probe

From: Abdelnasser Hussein

Date: Mon Nov 23 2026 - 02:02:02 EST


Introduce a local struct device pointer in at91_adc_probe() and use it
in place of &pdev->dev and &idev->dev throughout the function.

Also switch devm_iio_device_alloc() to use sizeof(*st) instead of
spelling out the full private structure type.

This is a preparatory cleanup to reduce the diff noise of the upcoming
conversion to device-managed resources.

As a result, messages previously logged against the IIO device are now
printed using the platform device being probed.

Signed-off-by: Abdelnasser Hussein <abdelnasserhussein11@xxxxxxxxx>
---
drivers/iio/adc/at91_adc.c | 61 +++++++++++++++++++-------------------
1 file changed, 30 insertions(+), 31 deletions(-)

diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
index b6e6fa77c782..3d9ae99a2ce6 100644
--- a/drivers/iio/adc/at91_adc.c
+++ b/drivers/iio/adc/at91_adc.c
@@ -989,68 +989,67 @@ 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 *dev = &pdev->dev;
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));
+ idev = devm_iio_device_alloc(dev, sizeof(*st));
if (!idev)
return -ENOMEM;

st = iio_priv(idev);

- st->caps = device_get_match_data(&pdev->dev);
+ st->caps = device_get_match_data(dev);
if (!st->caps)
return -ENODEV;

- st->use_external = device_property_read_bool(&pdev->dev,
- "atmel,adc-use-external-triggers");
+ st->use_external = device_property_read_bool(dev, "atmel,adc-use-external-triggers");

- if (device_property_read_u32(&pdev->dev, "atmel,adc-channels-used", &prop))
- return dev_err_probe(&idev->dev, -EINVAL,
+ if (device_property_read_u32(dev, "atmel,adc-channels-used", &prop))
+ return dev_err_probe(dev, -EINVAL,
"Missing adc-channels-used property.\n");
st->channels_mask = prop;

- st->sleep_mode = device_property_read_bool(&pdev->dev,
- "atmel,adc-sleep-mode");
+ st->sleep_mode = device_property_read_bool(dev, "atmel,adc-sleep-mode");

- if (device_property_read_u32(&pdev->dev, "atmel,adc-startup-time", &prop))
- return dev_err_probe(&idev->dev, -EINVAL,
+ if (device_property_read_u32(dev, "atmel,adc-startup-time", &prop))
+ return dev_err_probe(dev, -EINVAL,
"Missing adc-startup-time property.\n");
st->startup_time = prop;

prop = 0;
- device_property_read_u32(&pdev->dev, "atmel,adc-sample-hold-time", &prop);
+ device_property_read_u32(dev, "atmel,adc-sample-hold-time", &prop);
st->sample_hold_time = prop;

- if (device_property_read_u32(&pdev->dev, "atmel,adc-vref", &prop))
- return dev_err_probe(&idev->dev, -EINVAL,
+ if (device_property_read_u32(dev, "atmel,adc-vref", &prop))
+ return dev_err_probe(dev, -EINVAL,
"Missing adc-vref property.\n");
st->vref_mv = prop;

st->res = st->caps->high_res_bits;
if (st->caps->low_res_bits &&
- !device_property_read_string(&pdev->dev, "atmel,adc-use-res", &s)
+ !device_property_read_string(dev, "atmel,adc-use-res", &s)
&& !strcmp(s, "lowres"))
st->res = st->caps->low_res_bits;

- dev_info(&idev->dev, "Resolution used: %u bits\n", st->res);
+ dev_info(dev, "Resolution used: %u bits\n", st->res);

st->registers = &st->caps->registers;
st->num_channels = st->caps->num_channels;

/* Check if touchscreen is supported. */
if (st->caps->has_ts) {
- ret = at91_adc_probe_ts(&pdev->dev, st);
+ ret = at91_adc_probe_ts(dev, st);
if (ret)
return ret;
}

platform_set_drvdata(pdev, idev);

- idev->name = dev_name(&pdev->dev);
+ idev->name = dev_name(dev);
idev->modes = INDIO_DIRECT_MODE;
idev->info = &at91_adc_info;

@@ -1069,24 +1068,24 @@ static int at91_adc_probe(struct platform_device *pdev)
at91_adc_writel(st, AT91_ADC_IDR, 0xFFFFFFFF);

if (st->caps->has_tsmr)
- ret = devm_request_irq(&pdev->dev, st->irq,
+ ret = devm_request_irq(dev, st->irq,
at91_adc_9x5_interrupt, 0,
- pdev->dev.driver->name, idev);
+ dev->driver->name, idev);
else
- ret = devm_request_irq(&pdev->dev, st->irq,
+ ret = devm_request_irq(dev, st->irq,
at91_adc_rl_interrupt, 0,
- pdev->dev.driver->name, idev);
+ dev->driver->name, idev);
if (ret)
return ret;

- st->clk = devm_clk_get_enabled(&pdev->dev, "adc_clk");
+ st->clk = devm_clk_get_enabled(dev, "adc_clk");
if (IS_ERR(st->clk))
- return dev_err_probe(&pdev->dev, PTR_ERR(st->clk),
+ return dev_err_probe(dev, PTR_ERR(st->clk),
"Could not prepare or enable the clock.\n");

- st->adc_clk = devm_clk_get_enabled(&pdev->dev, "adc_op_clk");
+ st->adc_clk = devm_clk_get_enabled(dev, "adc_op_clk");
if (IS_ERR(st->adc_clk))
- return dev_err_probe(&pdev->dev, PTR_ERR(st->adc_clk),
+ return dev_err_probe(dev, PTR_ERR(st->adc_clk),
"Could not prepare or enable the ADC clock.\n");

/*
@@ -1098,13 +1097,13 @@ static int at91_adc_probe(struct platform_device *pdev)
adc_clk = clk_get_rate(st->adc_clk);
adc_clk_khz = adc_clk / 1000;

- dev_dbg(&pdev->dev, "Master clock is set as: %d Hz, adc_clk should set as: %d Hz\n",
+ dev_dbg(dev, "Master clock is set as: %d Hz, adc_clk should set as: %d Hz\n",
mstrclk, adc_clk);

prsc = (mstrclk / (2 * adc_clk)) - 1;

if (!st->startup_time)
- return dev_err_probe(&pdev->dev, -EINVAL,
+ return dev_err_probe(dev, -EINVAL,
"No startup time available.\n");
ticks = (*st->caps->calc_startup_ticks)(st->startup_time, adc_clk_khz);

@@ -1131,7 +1130,7 @@ static int at91_adc_probe(struct platform_device *pdev)
/* Setup the ADC channels available on the board */
ret = at91_adc_channel_init(idev);
if (ret < 0)
- return dev_err_probe(&pdev->dev, ret,
+ return dev_err_probe(dev, ret,
"Couldn't initialize the channels.\n");

init_waitqueue_head(&st->wq_data_avail);
@@ -1145,12 +1144,12 @@ static int at91_adc_probe(struct platform_device *pdev)
if (!st->touchscreen_type) {
ret = at91_adc_buffer_init(idev);
if (ret < 0)
- return dev_err_probe(&pdev->dev, ret,
+ return dev_err_probe(dev, ret,
"Couldn't initialize the buffer.\n");

ret = at91_adc_trigger_init(idev);
if (ret < 0) {
- dev_err(&pdev->dev, "Couldn't setup the triggers.\n");
+ dev_err(dev, "Couldn't setup the triggers.\n");
at91_adc_buffer_remove(idev);
return ret;
}
@@ -1164,7 +1163,7 @@ static int at91_adc_probe(struct platform_device *pdev)

ret = iio_device_register(idev);
if (ret < 0) {
- dev_err(&pdev->dev, "Couldn't register the device.\n");
+ dev_err(dev, "Couldn't register the device.\n");
goto error_iio_device_register;
}

--
2.56.0