drivers: spi: nrfx: factorise spi_context_lock()

spi_context_lock() & spi_context_release() are called in transceive()
function for a better readability.

Signed-off-by: Ismael Fillonneau <ismael.fillonneau@stimio.fr>
This commit is contained in:
Ismael Fillonneau 2020-01-02 15:41:09 +01:00 committed by Johan Hedberg
commit 84a0b32210
3 changed files with 21 additions and 15 deletions

View file

@ -172,11 +172,15 @@ static void transfer_next_chunk(struct device *dev)
static int transceive(struct device *dev, static int transceive(struct device *dev,
const struct spi_config *spi_cfg, const struct spi_config *spi_cfg,
const struct spi_buf_set *tx_bufs, const struct spi_buf_set *tx_bufs,
const struct spi_buf_set *rx_bufs) const struct spi_buf_set *rx_bufs,
bool asynchronous,
struct k_poll_signal *signal)
{ {
struct spi_nrfx_data *dev_data = get_dev_data(dev); struct spi_nrfx_data *dev_data = get_dev_data(dev);
int error; int error;
spi_context_lock(&dev_data->ctx, asynchronous, signal);
error = configure(dev, spi_cfg); error = configure(dev, spi_cfg);
if (error == 0) { if (error == 0) {
dev_data->busy = true; dev_data->busy = true;
@ -199,8 +203,7 @@ static int spi_nrfx_transceive(struct device *dev,
const struct spi_buf_set *tx_bufs, const struct spi_buf_set *tx_bufs,
const struct spi_buf_set *rx_bufs) const struct spi_buf_set *rx_bufs)
{ {
spi_context_lock(&get_dev_data(dev)->ctx, false, NULL); return transceive(dev, spi_cfg, tx_bufs, rx_bufs, false, NULL);
return transceive(dev, spi_cfg, tx_bufs, rx_bufs);
} }
#ifdef CONFIG_SPI_ASYNC #ifdef CONFIG_SPI_ASYNC
@ -210,8 +213,7 @@ static int spi_nrfx_transceive_async(struct device *dev,
const struct spi_buf_set *rx_bufs, const struct spi_buf_set *rx_bufs,
struct k_poll_signal *async) struct k_poll_signal *async)
{ {
spi_context_lock(&get_dev_data(dev)->ctx, true, async); return transceive(dev, spi_cfg, tx_bufs, rx_bufs, true, async);
return transceive(dev, spi_cfg, tx_bufs, rx_bufs);
} }
#endif /* CONFIG_SPI_ASYNC */ #endif /* CONFIG_SPI_ASYNC */

View file

@ -211,11 +211,15 @@ static void transfer_next_chunk(struct device *dev)
static int transceive(struct device *dev, static int transceive(struct device *dev,
const struct spi_config *spi_cfg, const struct spi_config *spi_cfg,
const struct spi_buf_set *tx_bufs, const struct spi_buf_set *tx_bufs,
const struct spi_buf_set *rx_bufs) const struct spi_buf_set *rx_bufs,
bool asynchronous,
struct k_poll_signal *signal)
{ {
struct spi_nrfx_data *dev_data = get_dev_data(dev); struct spi_nrfx_data *dev_data = get_dev_data(dev);
int error; int error;
spi_context_lock(&dev_data->ctx, asynchronous, signal);
error = configure(dev, spi_cfg); error = configure(dev, spi_cfg);
if (error == 0) { if (error == 0) {
dev_data->busy = true; dev_data->busy = true;
@ -238,8 +242,7 @@ static int spi_nrfx_transceive(struct device *dev,
const struct spi_buf_set *tx_bufs, const struct spi_buf_set *tx_bufs,
const struct spi_buf_set *rx_bufs) const struct spi_buf_set *rx_bufs)
{ {
spi_context_lock(&get_dev_data(dev)->ctx, false, NULL); return transceive(dev, spi_cfg, tx_bufs, rx_bufs, false, NULL);
return transceive(dev, spi_cfg, tx_bufs, rx_bufs);
} }
#ifdef CONFIG_SPI_ASYNC #ifdef CONFIG_SPI_ASYNC
@ -249,8 +252,7 @@ static int spi_nrfx_transceive_async(struct device *dev,
const struct spi_buf_set *rx_bufs, const struct spi_buf_set *rx_bufs,
struct k_poll_signal *async) struct k_poll_signal *async)
{ {
spi_context_lock(&get_dev_data(dev)->ctx, true, async); return transceive(dev, spi_cfg, tx_bufs, rx_bufs, true, async);
return transceive(dev, spi_cfg, tx_bufs, rx_bufs);
} }
#endif /* CONFIG_SPI_ASYNC */ #endif /* CONFIG_SPI_ASYNC */

View file

@ -144,11 +144,15 @@ static void prepare_for_transfer(struct device *dev)
static int transceive(struct device *dev, static int transceive(struct device *dev,
const struct spi_config *spi_cfg, const struct spi_config *spi_cfg,
const struct spi_buf_set *tx_bufs, const struct spi_buf_set *tx_bufs,
const struct spi_buf_set *rx_bufs) const struct spi_buf_set *rx_bufs,
bool asynchronous,
struct k_poll_signal *signal)
{ {
struct spi_nrfx_data *dev_data = get_dev_data(dev); struct spi_nrfx_data *dev_data = get_dev_data(dev);
int error; int error;
spi_context_lock(&dev_data->ctx, asynchronous, signal);
error = configure(dev, spi_cfg); error = configure(dev, spi_cfg);
if (error != 0) { if (error != 0) {
/* Invalid configuration. */ /* Invalid configuration. */
@ -178,8 +182,7 @@ static int spi_nrfx_transceive(struct device *dev,
const struct spi_buf_set *tx_bufs, const struct spi_buf_set *tx_bufs,
const struct spi_buf_set *rx_bufs) const struct spi_buf_set *rx_bufs)
{ {
spi_context_lock(&get_dev_data(dev)->ctx, false, NULL); return transceive(dev, spi_cfg, tx_bufs, rx_bufs, false, NULL);
return transceive(dev, spi_cfg, tx_bufs, rx_bufs);
} }
#ifdef CONFIG_SPI_ASYNC #ifdef CONFIG_SPI_ASYNC
@ -189,8 +192,7 @@ static int spi_nrfx_transceive_async(struct device *dev,
const struct spi_buf_set *rx_bufs, const struct spi_buf_set *rx_bufs,
struct k_poll_signal *async) struct k_poll_signal *async)
{ {
spi_context_lock(&get_dev_data(dev)->ctx, true, async); return transceive(dev, spi_cfg, tx_bufs, rx_bufs, true, async);
return transceive(dev, spi_cfg, tx_bufs, rx_bufs);
} }
#endif /* CONFIG_SPI_ASYNC */ #endif /* CONFIG_SPI_ASYNC */