mirror of
https://github.com/torvalds/linux.git
synced 2026-07-28 18:21:24 +02:00
iio: adc: ingenic-adc: use guard()() and scoped_guard() to handle synchronisation
Replace mutex_lock() and mutex_unlock() calls with guard()() in functions ingenic_adc_set_adcmd(), ingenic_adc_set_config(), ingenic_adc_enable(), ingenic_adc_capture(), and with scoped_guard() in function ingenic_adc_read_chan_info_raw(). This removes the need to call the unlock function, as the lock is automatically released when the function return or the scope exits for any other case. 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>
This commit is contained in:
parent
7ea43bebc7
commit
a42fea8596
|
|
@ -7,6 +7,8 @@
|
|||
*/
|
||||
|
||||
#include <dt-bindings/iio/adc/ingenic,adc.h>
|
||||
|
||||
#include <linux/cleanup.h>
|
||||
#include <linux/clk.h>
|
||||
#include <linux/iio/buffer.h>
|
||||
#include <linux/iio/iio.h>
|
||||
|
|
@ -115,7 +117,7 @@ static void ingenic_adc_set_adcmd(struct iio_dev *iio_dev, unsigned long mask)
|
|||
{
|
||||
struct ingenic_adc *adc = iio_priv(iio_dev);
|
||||
|
||||
mutex_lock(&adc->lock);
|
||||
guard(mutex)(&adc->lock);
|
||||
|
||||
/* Init ADCMD */
|
||||
readl(adc->base + JZ_ADC_REG_ADCMD);
|
||||
|
|
@ -162,8 +164,6 @@ static void ingenic_adc_set_adcmd(struct iio_dev *iio_dev, unsigned long mask)
|
|||
|
||||
/* We're done */
|
||||
writel(0, adc->base + JZ_ADC_REG_ADCMD);
|
||||
|
||||
mutex_unlock(&adc->lock);
|
||||
}
|
||||
|
||||
static void ingenic_adc_set_config(struct ingenic_adc *adc,
|
||||
|
|
@ -172,13 +172,11 @@ static void ingenic_adc_set_config(struct ingenic_adc *adc,
|
|||
{
|
||||
uint32_t cfg;
|
||||
|
||||
mutex_lock(&adc->lock);
|
||||
guard(mutex)(&adc->lock);
|
||||
|
||||
cfg = readl(adc->base + JZ_ADC_REG_CFG) & ~mask;
|
||||
cfg |= val;
|
||||
writel(cfg, adc->base + JZ_ADC_REG_CFG);
|
||||
|
||||
mutex_unlock(&adc->lock);
|
||||
}
|
||||
|
||||
static void __ingenic_adc_enable(struct ingenic_adc *adc, int engine,
|
||||
|
|
@ -200,9 +198,8 @@ static void ingenic_adc_enable(struct ingenic_adc *adc,
|
|||
int engine,
|
||||
bool enabled)
|
||||
{
|
||||
mutex_lock(&adc->lock);
|
||||
guard(mutex)(&adc->lock);
|
||||
__ingenic_adc_enable(adc, engine, enabled);
|
||||
mutex_unlock(&adc->lock);
|
||||
}
|
||||
|
||||
static int ingenic_adc_capture(struct ingenic_adc *adc,
|
||||
|
|
@ -217,7 +214,7 @@ static int ingenic_adc_capture(struct ingenic_adc *adc,
|
|||
* probably due to the switch of VREF. We must keep the lock here to
|
||||
* avoid races with the buffer enable/disable functions.
|
||||
*/
|
||||
mutex_lock(&adc->lock);
|
||||
guard(mutex)(&adc->lock);
|
||||
cfg = readl(adc->base + JZ_ADC_REG_CFG);
|
||||
writel(cfg & ~JZ_ADC_REG_CFG_CMD_SEL, adc->base + JZ_ADC_REG_CFG);
|
||||
|
||||
|
|
@ -228,7 +225,6 @@ static int ingenic_adc_capture(struct ingenic_adc *adc,
|
|||
__ingenic_adc_enable(adc, engine, false);
|
||||
|
||||
writel(cfg, adc->base + JZ_ADC_REG_CFG);
|
||||
mutex_unlock(&adc->lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -681,9 +677,8 @@ static int ingenic_adc_read_chan_info_raw(struct iio_dev *iio_dev,
|
|||
}
|
||||
|
||||
/* We cannot sample the aux channels in parallel. */
|
||||
mutex_lock(&adc->aux_lock);
|
||||
ret = __ingenic_adc_read_chan(adc, chan, val);
|
||||
mutex_unlock(&adc->aux_lock);
|
||||
scoped_guard(mutex, &adc->aux_lock)
|
||||
ret = __ingenic_adc_read_chan(adc, chan, val);
|
||||
|
||||
clk_disable(adc->clk);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user