mirror of
https://github.com/torvalds/linux.git
synced 2024-11-22 20:22:09 +00:00
iio: adc: ad7944: use devm_spi_optimize_message()
Use new devm_spi_optimize_message() helper to simplify repeated code in the ad7944 driver. Signed-off-by: David Lechner <dlechner@baylibre.com> Link: https://patch.msgid.link/20240624-devm_spi_optimize_message-v3-2-912138c27b66@baylibre.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
parent
4f291b3016
commit
340fa834ae
@ -134,18 +134,12 @@ AD7944_DEFINE_CHIP_INFO(ad7985, ad7944, 16, 0);
|
||||
/* fully differential */
|
||||
AD7944_DEFINE_CHIP_INFO(ad7986, ad7986, 18, 1);
|
||||
|
||||
static void ad7944_unoptimize_msg(void *msg)
|
||||
{
|
||||
spi_unoptimize_message(msg);
|
||||
}
|
||||
|
||||
static int ad7944_3wire_cs_mode_init_msg(struct device *dev, struct ad7944_adc *adc,
|
||||
const struct iio_chan_spec *chan)
|
||||
{
|
||||
unsigned int t_conv_ns = adc->always_turbo ? adc->timing_spec->turbo_conv_ns
|
||||
: adc->timing_spec->conv_ns;
|
||||
struct spi_transfer *xfers = adc->xfers;
|
||||
int ret;
|
||||
|
||||
/*
|
||||
* NB: can get better performance from some SPI controllers if we use
|
||||
@ -175,11 +169,7 @@ static int ad7944_3wire_cs_mode_init_msg(struct device *dev, struct ad7944_adc *
|
||||
|
||||
spi_message_init_with_transfers(&adc->msg, xfers, 3);
|
||||
|
||||
ret = spi_optimize_message(adc->spi, &adc->msg);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
return devm_add_action_or_reset(dev, ad7944_unoptimize_msg, &adc->msg);
|
||||
return devm_spi_optimize_message(dev, adc->spi, &adc->msg);
|
||||
}
|
||||
|
||||
static int ad7944_4wire_mode_init_msg(struct device *dev, struct ad7944_adc *adc,
|
||||
@ -188,7 +178,6 @@ static int ad7944_4wire_mode_init_msg(struct device *dev, struct ad7944_adc *adc
|
||||
unsigned int t_conv_ns = adc->always_turbo ? adc->timing_spec->turbo_conv_ns
|
||||
: adc->timing_spec->conv_ns;
|
||||
struct spi_transfer *xfers = adc->xfers;
|
||||
int ret;
|
||||
|
||||
/*
|
||||
* NB: can get better performance from some SPI controllers if we use
|
||||
@ -209,11 +198,7 @@ static int ad7944_4wire_mode_init_msg(struct device *dev, struct ad7944_adc *adc
|
||||
|
||||
spi_message_init_with_transfers(&adc->msg, xfers, 2);
|
||||
|
||||
ret = spi_optimize_message(adc->spi, &adc->msg);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
return devm_add_action_or_reset(dev, ad7944_unoptimize_msg, &adc->msg);
|
||||
return devm_spi_optimize_message(dev, adc->spi, &adc->msg);
|
||||
}
|
||||
|
||||
static int ad7944_chain_mode_init_msg(struct device *dev, struct ad7944_adc *adc,
|
||||
@ -221,7 +206,6 @@ static int ad7944_chain_mode_init_msg(struct device *dev, struct ad7944_adc *adc
|
||||
u32 n_chain_dev)
|
||||
{
|
||||
struct spi_transfer *xfers = adc->xfers;
|
||||
int ret;
|
||||
|
||||
/*
|
||||
* NB: SCLK has to be low before we toggle CS to avoid triggering the
|
||||
@ -249,11 +233,7 @@ static int ad7944_chain_mode_init_msg(struct device *dev, struct ad7944_adc *adc
|
||||
|
||||
spi_message_init_with_transfers(&adc->msg, xfers, 2);
|
||||
|
||||
ret = spi_optimize_message(adc->spi, &adc->msg);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
return devm_add_action_or_reset(dev, ad7944_unoptimize_msg, &adc->msg);
|
||||
return devm_spi_optimize_message(dev, adc->spi, &adc->msg);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user