[PATCH v4 2/3] iio: adc: at91_adc: use local struct device pointer in probe
From: Abdelnasser Hussein
Date: Tue Nov 17 2026 - 09:06:01 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.As a
result, messages previously logged against the IIO device are now
printed using the platform device being probed.
switch devm_iio_device_alloc() to use sizeof(*st) instead of
spelling out the full private structure type.
Signed-off-by: Abdelnasser Hussein <abdelnasserhussein11@xxxxxxxxx>
---
drivers/iio/adc/at91_adc.c | 46 +++++++++++++++++++-------------------
1 file changed, 23 insertions(+), 23 deletions(-)
diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
index c7fc06214c05..0553a08b8d24 100644
--- a/drivers/iio/adc/at91_adc.c
+++ b/drivers/iio/adc/at91_adc.c
@@ -987,32 +987,33 @@ 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;
+ struct device_node *node = dev->of_node;
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 = of_device_get_match_data(&pdev->dev);
+ st->caps = of_device_get_match_data(dev);
st->use_external = of_property_read_bool(node, "atmel,adc-use-external-triggers");
if (of_property_read_u32(node, "atmel,adc-channels-used", &prop))
- return dev_err_probe(&idev->dev, -EINVAL,
+ return dev_err_probe(dev, -EINVAL,
"Missing adc-channels-used property in the DT.\n");
st->channels_mask = prop;
st->sleep_mode = of_property_read_bool(node, "atmel,adc-sleep-mode");
if (of_property_read_u32(node, "atmel,adc-startup-time", &prop))
- return dev_err_probe(&idev->dev, -EINVAL,
+ return dev_err_probe(dev, -EINVAL,
"Missing adc-startup-time property in the DT.\n");
st->startup_time = prop;
@@ -1021,7 +1022,7 @@ static int at91_adc_probe(struct platform_device *pdev)
st->sample_hold_time = prop;
if (of_property_read_u32(node, "atmel,adc-vref", &prop))
- return dev_err_probe(&idev->dev, -EINVAL,
+ return dev_err_probe(dev, -EINVAL,
"Missing adc-vref property in the DT.\n");
st->vref_mv = prop;
@@ -1031,21 +1032,21 @@ static int at91_adc_probe(struct platform_device *pdev)
&& !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_dt_ts(node, st, &idev->dev);
+ ret = at91_adc_probe_dt_ts(node, st, dev);
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;
@@ -1064,25 +1065,25 @@ 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 dev_err_probe(&pdev->dev, ret,
+ return dev_err_probe(dev, ret,
"Failed to allocate IRQ.\n");
- 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");
/*
@@ -1094,13 +1095,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);
@@ -1127,7 +1128,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);
@@ -1141,8 +1142,7 @@ 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,
- "Couldn't initialize the buffer.\n");
+ return dev_err_probe(dev, ret, "Couldn't initialize the buffer.\n");
ret = at91_adc_trigger_init(idev);
if (ret < 0) {
--
2.56.0