drivers/spi: Do not reconfigure at every transaction

If the configuration is already installed, there will no need to
reconfigure the controller all over again.

This was missing for mcux_dspi, mcux_lspi, sam and sam0.

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
Tomasz Bursztyka 2018-11-12 15:54:02 +01:00 committed by Maureen Helm
commit 27195895b1
4 changed files with 28 additions and 5 deletions

View file

@ -128,6 +128,11 @@ static int spi_mcux_configure(struct device *dev,
u32_t clock_freq;
u32_t word_size;
if (spi_context_configured(&data->ctx, spi_cfg)) {
/* This configuration is already in use */
return 0;
}
DSPI_MasterGetDefaultConfig(&master_config);
if (spi_cfg->slave > FSL_FEATURE_DSPI_CHIP_SELECT_COUNT) {

View file

@ -131,6 +131,11 @@ static int spi_mcux_configure(struct device *dev,
u32_t clock_freq;
u32_t word_size;
if (spi_context_configured(&data->ctx, spi_cfg)) {
/* This configuration is already in use */
return 0;
}
LPSPI_MasterGetDefaultConfig(&master_config);
if (spi_cfg->slave > CHIP_SELECT_COUNT) {

View file

@ -50,10 +50,15 @@ static int spi_sam_configure(struct device *dev,
const struct spi_config *config)
{
const struct spi_sam_config *cfg = dev->config->config_info;
struct spi_sam_data *data = dev->driver_data;
Spi *regs = cfg->regs;
u32_t spi_mr = 0, spi_csr = 0;
int div;
if (spi_context_configured(&data->ctx, config)) {
return 0;
}
if (SPI_OP_MODE_GET(config->operation) != SPI_OP_MODE_MASTER) {
/* Slave mode is not implemented. */
return -ENOTSUP;
@ -95,6 +100,10 @@ static int spi_sam_configure(struct device *dev,
regs->SPI_CSR[config->slave] = spi_csr;
regs->SPI_CR = SPI_CR_SPIEN; /* Enable SPI */
spi_context_cs_configure(&data->ctx);
data->ctx.config = config;
return 0;
}
@ -362,8 +371,6 @@ static int spi_sam_transceive(struct device *dev,
goto done;
}
data->ctx.config = config;
spi_context_cs_configure(&data->ctx);
spi_context_cs_control(&data->ctx, true);
/* This driver special cases the common send only, receive
@ -504,4 +511,3 @@ SPI_SAM_DEVICE_INIT(0);
#if DT_SPI_1_BASE_ADDRESS
SPI_SAM_DEVICE_INIT(1);
#endif

View file

@ -46,11 +46,16 @@ static int spi_sam0_configure(struct device *dev,
const struct spi_config *config)
{
const struct spi_sam0_config *cfg = dev->config->config_info;
struct spi_sam0_data *data = dev->driver_data;
SercomSpi *regs = cfg->regs;
SERCOM_SPI_CTRLA_Type ctrla = {.reg = 0};
SERCOM_SPI_CTRLB_Type ctrlb = {.reg = 0};
int div;
if (spi_context_configured(&data->ctx, config)) {
return 0;
}
if (SPI_OP_MODE_GET(config->operation) != SPI_OP_MODE_MASTER) {
/* Slave mode is not implemented. */
return -ENOTSUP;
@ -106,6 +111,10 @@ static int spi_sam0_configure(struct device *dev,
wait_synchronization(regs);
}
spi_context_cs_configure(&data->ctx);
data->ctx.config = config;
return 0;
}
@ -370,8 +379,6 @@ static int spi_sam0_transceive(struct device *dev,
goto done;
}
data->ctx.config = config;
spi_context_cs_configure(&data->ctx);
spi_context_cs_control(&data->ctx, true);
/* This driver special cases the common send only, receive