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:
parent
4a1bb71694
commit
84a0b32210
3 changed files with 21 additions and 15 deletions
|
@ -172,11 +172,15 @@ static void transfer_next_chunk(struct device *dev)
|
|||
static int transceive(struct device *dev,
|
||||
const struct spi_config *spi_cfg,
|
||||
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);
|
||||
int error;
|
||||
|
||||
spi_context_lock(&dev_data->ctx, asynchronous, signal);
|
||||
|
||||
error = configure(dev, spi_cfg);
|
||||
if (error == 0) {
|
||||
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 *rx_bufs)
|
||||
{
|
||||
spi_context_lock(&get_dev_data(dev)->ctx, false, NULL);
|
||||
return transceive(dev, spi_cfg, tx_bufs, rx_bufs);
|
||||
return transceive(dev, spi_cfg, tx_bufs, rx_bufs, false, NULL);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SPI_ASYNC
|
||||
|
@ -210,8 +213,7 @@ static int spi_nrfx_transceive_async(struct device *dev,
|
|||
const struct spi_buf_set *rx_bufs,
|
||||
struct k_poll_signal *async)
|
||||
{
|
||||
spi_context_lock(&get_dev_data(dev)->ctx, true, async);
|
||||
return transceive(dev, spi_cfg, tx_bufs, rx_bufs);
|
||||
return transceive(dev, spi_cfg, tx_bufs, rx_bufs, true, async);
|
||||
}
|
||||
#endif /* CONFIG_SPI_ASYNC */
|
||||
|
||||
|
|
|
@ -211,11 +211,15 @@ static void transfer_next_chunk(struct device *dev)
|
|||
static int transceive(struct device *dev,
|
||||
const struct spi_config *spi_cfg,
|
||||
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);
|
||||
int error;
|
||||
|
||||
spi_context_lock(&dev_data->ctx, asynchronous, signal);
|
||||
|
||||
error = configure(dev, spi_cfg);
|
||||
if (error == 0) {
|
||||
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 *rx_bufs)
|
||||
{
|
||||
spi_context_lock(&get_dev_data(dev)->ctx, false, NULL);
|
||||
return transceive(dev, spi_cfg, tx_bufs, rx_bufs);
|
||||
return transceive(dev, spi_cfg, tx_bufs, rx_bufs, false, NULL);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SPI_ASYNC
|
||||
|
@ -249,8 +252,7 @@ static int spi_nrfx_transceive_async(struct device *dev,
|
|||
const struct spi_buf_set *rx_bufs,
|
||||
struct k_poll_signal *async)
|
||||
{
|
||||
spi_context_lock(&get_dev_data(dev)->ctx, true, async);
|
||||
return transceive(dev, spi_cfg, tx_bufs, rx_bufs);
|
||||
return transceive(dev, spi_cfg, tx_bufs, rx_bufs, true, async);
|
||||
}
|
||||
#endif /* CONFIG_SPI_ASYNC */
|
||||
|
||||
|
|
|
@ -144,11 +144,15 @@ static void prepare_for_transfer(struct device *dev)
|
|||
static int transceive(struct device *dev,
|
||||
const struct spi_config *spi_cfg,
|
||||
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);
|
||||
int error;
|
||||
|
||||
spi_context_lock(&dev_data->ctx, asynchronous, signal);
|
||||
|
||||
error = configure(dev, spi_cfg);
|
||||
if (error != 0) {
|
||||
/* 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 *rx_bufs)
|
||||
{
|
||||
spi_context_lock(&get_dev_data(dev)->ctx, false, NULL);
|
||||
return transceive(dev, spi_cfg, tx_bufs, rx_bufs);
|
||||
return transceive(dev, spi_cfg, tx_bufs, rx_bufs, false, NULL);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SPI_ASYNC
|
||||
|
@ -189,8 +192,7 @@ static int spi_nrfx_transceive_async(struct device *dev,
|
|||
const struct spi_buf_set *rx_bufs,
|
||||
struct k_poll_signal *async)
|
||||
{
|
||||
spi_context_lock(&get_dev_data(dev)->ctx, true, async);
|
||||
return transceive(dev, spi_cfg, tx_bufs, rx_bufs);
|
||||
return transceive(dev, spi_cfg, tx_bufs, rx_bufs, true, async);
|
||||
}
|
||||
#endif /* CONFIG_SPI_ASYNC */
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue