Skip to content

Commit 7ea43be

Browse files
Felipe Ribeiro de Souzajic23
authored andcommitted
iio: adc: ingenic-adc: refactor ingenic_adc_read_chan_info_raw()
Extract the sample logic from ingenic_adc_read_chan_info_raw() into a new helper function __ingenic_adc_read_chan() to improve code readability and modularity. The helper handles the mutex-protected section for sampling channels, while the main function manages mutex and clock enabling/disabling. Signed-off-by: Felipe Ribeiro de Souza <felipers@ime.usp.br> Co-developed-by: Lucas Ivars Cadima Ciziks <lucas@ciziks.com> Signed-off-by: Lucas Ivars Cadima Ciziks <lucas@ciziks.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
1 parent a3c9f67 commit 7ea43be

1 file changed

Lines changed: 24 additions & 16 deletions

File tree

drivers/iio/adc/ingenic-adc.c

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -627,22 +627,12 @@ static int ingenic_adc_read_avail(struct iio_dev *iio_dev,
627627
}
628628
}
629629

630-
static int ingenic_adc_read_chan_info_raw(struct iio_dev *iio_dev,
631-
struct iio_chan_spec const *chan,
632-
int *val)
630+
static int __ingenic_adc_read_chan(struct ingenic_adc *adc,
631+
struct iio_chan_spec const *chan,
632+
int *val)
633633
{
634634
int cmd, ret, engine = (chan->channel == INGENIC_ADC_BATTERY);
635-
struct ingenic_adc *adc = iio_priv(iio_dev);
636-
637-
ret = clk_enable(adc->clk);
638-
if (ret) {
639-
dev_err(iio_dev->dev.parent, "Failed to enable clock: %d\n",
640-
ret);
641-
return ret;
642-
}
643635

644-
/* We cannot sample the aux channels in parallel. */
645-
mutex_lock(&adc->aux_lock);
646636
if (adc->soc_data->has_aux_md && engine == 0) {
647637
switch (chan->channel) {
648638
case INGENIC_ADC_AUX0:
@@ -661,7 +651,7 @@ static int ingenic_adc_read_chan_info_raw(struct iio_dev *iio_dev,
661651

662652
ret = ingenic_adc_capture(adc, engine);
663653
if (ret)
664-
goto out;
654+
return ret;
665655

666656
switch (chan->channel) {
667657
case INGENIC_ADC_AUX0:
@@ -674,9 +664,27 @@ static int ingenic_adc_read_chan_info_raw(struct iio_dev *iio_dev,
674664
break;
675665
}
676666

677-
ret = IIO_VAL_INT;
678-
out:
667+
return IIO_VAL_INT;
668+
}
669+
670+
static int ingenic_adc_read_chan_info_raw(struct iio_dev *iio_dev,
671+
struct iio_chan_spec const *chan,
672+
int *val)
673+
{
674+
struct ingenic_adc *adc = iio_priv(iio_dev);
675+
int ret;
676+
677+
ret = clk_enable(adc->clk);
678+
if (ret) {
679+
dev_err(iio_dev->dev.parent, "Failed to enable clock: %d\n", ret);
680+
return ret;
681+
}
682+
683+
/* We cannot sample the aux channels in parallel. */
684+
mutex_lock(&adc->aux_lock);
685+
ret = __ingenic_adc_read_chan(adc, chan, val);
679686
mutex_unlock(&adc->aux_lock);
687+
680688
clk_disable(adc->clk);
681689

682690
return ret;

0 commit comments

Comments
 (0)