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:
parent
fb4cb3a878
commit
27195895b1
4 changed files with 28 additions and 5 deletions
|
@ -128,6 +128,11 @@ static int spi_mcux_configure(struct device *dev,
|
||||||
u32_t clock_freq;
|
u32_t clock_freq;
|
||||||
u32_t word_size;
|
u32_t word_size;
|
||||||
|
|
||||||
|
if (spi_context_configured(&data->ctx, spi_cfg)) {
|
||||||
|
/* This configuration is already in use */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
DSPI_MasterGetDefaultConfig(&master_config);
|
DSPI_MasterGetDefaultConfig(&master_config);
|
||||||
|
|
||||||
if (spi_cfg->slave > FSL_FEATURE_DSPI_CHIP_SELECT_COUNT) {
|
if (spi_cfg->slave > FSL_FEATURE_DSPI_CHIP_SELECT_COUNT) {
|
||||||
|
|
|
@ -131,6 +131,11 @@ static int spi_mcux_configure(struct device *dev,
|
||||||
u32_t clock_freq;
|
u32_t clock_freq;
|
||||||
u32_t word_size;
|
u32_t word_size;
|
||||||
|
|
||||||
|
if (spi_context_configured(&data->ctx, spi_cfg)) {
|
||||||
|
/* This configuration is already in use */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
LPSPI_MasterGetDefaultConfig(&master_config);
|
LPSPI_MasterGetDefaultConfig(&master_config);
|
||||||
|
|
||||||
if (spi_cfg->slave > CHIP_SELECT_COUNT) {
|
if (spi_cfg->slave > CHIP_SELECT_COUNT) {
|
||||||
|
|
|
@ -50,10 +50,15 @@ static int spi_sam_configure(struct device *dev,
|
||||||
const struct spi_config *config)
|
const struct spi_config *config)
|
||||||
{
|
{
|
||||||
const struct spi_sam_config *cfg = dev->config->config_info;
|
const struct spi_sam_config *cfg = dev->config->config_info;
|
||||||
|
struct spi_sam_data *data = dev->driver_data;
|
||||||
Spi *regs = cfg->regs;
|
Spi *regs = cfg->regs;
|
||||||
u32_t spi_mr = 0, spi_csr = 0;
|
u32_t spi_mr = 0, spi_csr = 0;
|
||||||
int div;
|
int div;
|
||||||
|
|
||||||
|
if (spi_context_configured(&data->ctx, config)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (SPI_OP_MODE_GET(config->operation) != SPI_OP_MODE_MASTER) {
|
if (SPI_OP_MODE_GET(config->operation) != SPI_OP_MODE_MASTER) {
|
||||||
/* Slave mode is not implemented. */
|
/* Slave mode is not implemented. */
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
|
@ -95,6 +100,10 @@ static int spi_sam_configure(struct device *dev,
|
||||||
regs->SPI_CSR[config->slave] = spi_csr;
|
regs->SPI_CSR[config->slave] = spi_csr;
|
||||||
regs->SPI_CR = SPI_CR_SPIEN; /* Enable SPI */
|
regs->SPI_CR = SPI_CR_SPIEN; /* Enable SPI */
|
||||||
|
|
||||||
|
spi_context_cs_configure(&data->ctx);
|
||||||
|
|
||||||
|
data->ctx.config = config;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -362,8 +371,6 @@ static int spi_sam_transceive(struct device *dev,
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
data->ctx.config = config;
|
|
||||||
spi_context_cs_configure(&data->ctx);
|
|
||||||
spi_context_cs_control(&data->ctx, true);
|
spi_context_cs_control(&data->ctx, true);
|
||||||
|
|
||||||
/* This driver special cases the common send only, receive
|
/* This driver special cases the common send only, receive
|
||||||
|
@ -504,4 +511,3 @@ SPI_SAM_DEVICE_INIT(0);
|
||||||
#if DT_SPI_1_BASE_ADDRESS
|
#if DT_SPI_1_BASE_ADDRESS
|
||||||
SPI_SAM_DEVICE_INIT(1);
|
SPI_SAM_DEVICE_INIT(1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -46,11 +46,16 @@ static int spi_sam0_configure(struct device *dev,
|
||||||
const struct spi_config *config)
|
const struct spi_config *config)
|
||||||
{
|
{
|
||||||
const struct spi_sam0_config *cfg = dev->config->config_info;
|
const struct spi_sam0_config *cfg = dev->config->config_info;
|
||||||
|
struct spi_sam0_data *data = dev->driver_data;
|
||||||
SercomSpi *regs = cfg->regs;
|
SercomSpi *regs = cfg->regs;
|
||||||
SERCOM_SPI_CTRLA_Type ctrla = {.reg = 0};
|
SERCOM_SPI_CTRLA_Type ctrla = {.reg = 0};
|
||||||
SERCOM_SPI_CTRLB_Type ctrlb = {.reg = 0};
|
SERCOM_SPI_CTRLB_Type ctrlb = {.reg = 0};
|
||||||
int div;
|
int div;
|
||||||
|
|
||||||
|
if (spi_context_configured(&data->ctx, config)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (SPI_OP_MODE_GET(config->operation) != SPI_OP_MODE_MASTER) {
|
if (SPI_OP_MODE_GET(config->operation) != SPI_OP_MODE_MASTER) {
|
||||||
/* Slave mode is not implemented. */
|
/* Slave mode is not implemented. */
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
|
@ -106,6 +111,10 @@ static int spi_sam0_configure(struct device *dev,
|
||||||
wait_synchronization(regs);
|
wait_synchronization(regs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
spi_context_cs_configure(&data->ctx);
|
||||||
|
|
||||||
|
data->ctx.config = config;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -370,8 +379,6 @@ static int spi_sam0_transceive(struct device *dev,
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
data->ctx.config = config;
|
|
||||||
spi_context_cs_configure(&data->ctx);
|
|
||||||
spi_context_cs_control(&data->ctx, true);
|
spi_context_cs_control(&data->ctx, true);
|
||||||
|
|
||||||
/* This driver special cases the common send only, receive
|
/* This driver special cases the common send only, receive
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue