Skip to content

Commit b627e3b

Browse files
commodojic23
authored andcommitted
staging: iio: ad9834: convert to device-managed functions in probe
This change converts the driver to use device-managed functions in the probe function. For the clock and regulator disable, some devm_add_action_or_reset() calls are required, and then devm_iio_device_register() function can be used register the IIO device. The final aim here would be for IIO to export only the device-managed functions of it's API. That's a long way to go and this a small step in that direction. Signed-off-by: Alexandru Ardelean <aardelean@deviqon.com> Link: https://lore.kernel.org/r/20210310095131.47476-1-aardelean@deviqon.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 70da641 commit b627e3b

File tree

1 file changed

+31
-36
lines changed

1 file changed

+31
-36
lines changed

drivers/staging/iio/frequency/ad9834.c

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
/**
5757
* struct ad9834_state - driver instance specific data
5858
* @spi: spi_device
59-
* @reg: supply regulator
6059
* @mclk: external master clock
6160
* @control: cached control word
6261
* @xfer: default spi transfer
@@ -70,7 +69,6 @@
7069

7170
struct ad9834_state {
7271
struct spi_device *spi;
73-
struct regulator *reg;
7472
struct clk *mclk;
7573
unsigned short control;
7674
unsigned short devid;
@@ -390,6 +388,20 @@ static const struct iio_info ad9833_info = {
390388
.attrs = &ad9833_attribute_group,
391389
};
392390

391+
static void ad9834_disable_reg(void *data)
392+
{
393+
struct regulator *reg = data;
394+
395+
regulator_disable(reg);
396+
}
397+
398+
static void ad9834_disable_clk(void *data)
399+
{
400+
struct clk *clk = data;
401+
402+
clk_disable_unprepare(clk);
403+
}
404+
393405
static int ad9834_probe(struct spi_device *spi)
394406
{
395407
struct ad9834_state *st;
@@ -407,29 +419,35 @@ static int ad9834_probe(struct spi_device *spi)
407419
return ret;
408420
}
409421

422+
ret = devm_add_action_or_reset(&spi->dev, ad9834_disable_reg, reg);
423+
if (ret)
424+
return ret;
425+
410426
indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
411427
if (!indio_dev) {
412428
ret = -ENOMEM;
413-
goto error_disable_reg;
429+
return ret;
414430
}
415-
spi_set_drvdata(spi, indio_dev);
416431
st = iio_priv(indio_dev);
417432
mutex_init(&st->lock);
418433
st->mclk = devm_clk_get(&spi->dev, NULL);
419434
if (IS_ERR(st->mclk)) {
420435
ret = PTR_ERR(st->mclk);
421-
goto error_disable_reg;
436+
return ret;
422437
}
423438

424439
ret = clk_prepare_enable(st->mclk);
425440
if (ret) {
426441
dev_err(&spi->dev, "Failed to enable master clock\n");
427-
goto error_disable_reg;
442+
return ret;
428443
}
429444

445+
ret = devm_add_action_or_reset(&spi->dev, ad9834_disable_clk, st->mclk);
446+
if (ret)
447+
return ret;
448+
430449
st->spi = spi;
431450
st->devid = spi_get_device_id(spi)->driver_data;
432-
st->reg = reg;
433451
indio_dev->name = spi_get_device_id(spi)->name;
434452
switch (st->devid) {
435453
case ID_AD9833:
@@ -470,48 +488,26 @@ static int ad9834_probe(struct spi_device *spi)
470488
ret = spi_sync(st->spi, &st->msg);
471489
if (ret) {
472490
dev_err(&spi->dev, "device init failed\n");
473-
goto error_clock_unprepare;
491+
return ret;
474492
}
475493

476494
ret = ad9834_write_frequency(st, AD9834_REG_FREQ0, 1000000);
477495
if (ret)
478-
goto error_clock_unprepare;
496+
return ret;
479497

480498
ret = ad9834_write_frequency(st, AD9834_REG_FREQ1, 5000000);
481499
if (ret)
482-
goto error_clock_unprepare;
500+
return ret;
483501

484502
ret = ad9834_write_phase(st, AD9834_REG_PHASE0, 512);
485503
if (ret)
486-
goto error_clock_unprepare;
504+
return ret;
487505

488506
ret = ad9834_write_phase(st, AD9834_REG_PHASE1, 1024);
489507
if (ret)
490-
goto error_clock_unprepare;
491-
492-
ret = iio_device_register(indio_dev);
493-
if (ret)
494-
goto error_clock_unprepare;
495-
496-
return 0;
497-
error_clock_unprepare:
498-
clk_disable_unprepare(st->mclk);
499-
error_disable_reg:
500-
regulator_disable(reg);
501-
502-
return ret;
503-
}
504-
505-
static int ad9834_remove(struct spi_device *spi)
506-
{
507-
struct iio_dev *indio_dev = spi_get_drvdata(spi);
508-
struct ad9834_state *st = iio_priv(indio_dev);
509-
510-
iio_device_unregister(indio_dev);
511-
clk_disable_unprepare(st->mclk);
512-
regulator_disable(st->reg);
508+
return ret;
513509

514-
return 0;
510+
return devm_iio_device_register(&spi->dev, indio_dev);
515511
}
516512

517513
static const struct spi_device_id ad9834_id[] = {
@@ -539,7 +535,6 @@ static struct spi_driver ad9834_driver = {
539535
.of_match_table = ad9834_of_match
540536
},
541537
.probe = ad9834_probe,
542-
.remove = ad9834_remove,
543538
.id_table = ad9834_id,
544539
};
545540
module_spi_driver(ad9834_driver);

0 commit comments

Comments
 (0)