drivers/spi: Remove legacy API support from mcux dspi driver
Now that MCR20A supports the new API, legacy support from mcux dspi driver can be safely removed. Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
parent
b62b12eef8
commit
09dd5e9b22
3 changed files with 3 additions and 255 deletions
|
@ -5,8 +5,8 @@ else()
|
|||
zephyr_sources_ifdef(CONFIG_SPI_DW spi_dw.c)
|
||||
zephyr_sources_ifdef(CONFIG_SPI_INTEL spi_intel.c)
|
||||
zephyr_sources_ifdef(CONFIG_SPI_STM32 spi_ll_stm32.c)
|
||||
zephyr_sources_ifdef(CONFIG_SPI_MCUX_DSPI spi_mcux_dspi.c)
|
||||
zephyr_sources_ifdef(CONFIG_SPI_SAM0 spi_sam0.c)
|
||||
endif()
|
||||
|
||||
zephyr_sources_ifdef(CONFIG_SPI_MCUX_DSPI spi_mcux_dspi.c)
|
||||
zephyr_sources_ifdef(CONFIG_USERSPACE spi_handlers.c)
|
||||
|
|
|
@ -290,8 +290,6 @@ config SPI_5_OP_MODES
|
|||
|
||||
if SPI_LEGACY_API
|
||||
|
||||
source "drivers/spi/Kconfig.mcux_dspi"
|
||||
|
||||
source "drivers/spi/Kconfig.nrf5_legacy"
|
||||
|
||||
endif # SPI_LEGACY_API
|
||||
|
@ -309,12 +307,12 @@ config SPI_INTEL
|
|||
|
||||
source "drivers/spi/Kconfig.stm32"
|
||||
|
||||
endif # !SPI_LEGACY_API
|
||||
|
||||
source "drivers/spi/Kconfig.dw"
|
||||
|
||||
source "drivers/spi/Kconfig.mcux_dspi"
|
||||
|
||||
source "drivers/spi/Kconfig.sam0"
|
||||
|
||||
endif # !SPI_LEGACY_API
|
||||
|
||||
endif # SPI
|
||||
|
|
|
@ -14,244 +14,20 @@
|
|||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SPI_LEVEL
|
||||
#include <logging/sys_log.h>
|
||||
|
||||
#ifndef CONFIG_SPI_LEGACY_API
|
||||
#include "spi_context.h"
|
||||
#endif
|
||||
|
||||
struct spi_mcux_config {
|
||||
SPI_Type *base;
|
||||
clock_name_t clock_source;
|
||||
void (*irq_config_func)(struct device *dev);
|
||||
#ifdef CONFIG_SPI_LEGACY_API
|
||||
struct spi_config default_cfg;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct spi_mcux_data {
|
||||
dspi_master_handle_t handle;
|
||||
#ifdef CONFIG_SPI_LEGACY_API
|
||||
struct k_sem sync;
|
||||
status_t callback_status;
|
||||
u32_t slave;
|
||||
#else
|
||||
struct spi_context ctx;
|
||||
size_t transfer_len;
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef CONFIG_SPI_LEGACY_API
|
||||
|
||||
static void spi_mcux_master_transfer_callback(SPI_Type *base,
|
||||
dspi_master_handle_t *handle, status_t status, void *userData)
|
||||
{
|
||||
struct device *dev = userData;
|
||||
struct spi_mcux_data *data = dev->driver_data;
|
||||
|
||||
data->callback_status = status;
|
||||
k_sem_give(&data->sync);
|
||||
}
|
||||
|
||||
static int spi_mcux_configure(struct device *dev, struct spi_config *spi_config)
|
||||
{
|
||||
const struct spi_mcux_config *config = dev->config->config_info;
|
||||
struct spi_mcux_data *data = dev->driver_data;
|
||||
SPI_Type *base = config->base;
|
||||
dspi_master_config_t master_config;
|
||||
u32_t flags = spi_config->config;
|
||||
u32_t clock_freq;
|
||||
u32_t word_size;
|
||||
|
||||
DSPI_MasterGetDefaultConfig(&master_config);
|
||||
|
||||
word_size = SPI_WORD_SIZE_GET(flags);
|
||||
if (word_size > FSL_FEATURE_DSPI_MAX_DATA_WIDTH) {
|
||||
SYS_LOG_ERR("Word size %d is greater than %d",
|
||||
word_size, FSL_FEATURE_DSPI_MAX_DATA_WIDTH);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
master_config.ctarConfig.bitsPerFrame = word_size;
|
||||
|
||||
master_config.ctarConfig.cpol = (flags & SPI_MODE_CPOL)
|
||||
? kDSPI_ClockPolarityActiveLow
|
||||
: kDSPI_ClockPolarityActiveHigh;
|
||||
|
||||
master_config.ctarConfig.cpha = (flags & SPI_MODE_CPHA)
|
||||
? kDSPI_ClockPhaseSecondEdge
|
||||
: kDSPI_ClockPhaseFirstEdge;
|
||||
|
||||
master_config.ctarConfig.direction = (flags & SPI_TRANSFER_LSB)
|
||||
? kDSPI_LsbFirst
|
||||
: kDSPI_MsbFirst;
|
||||
|
||||
master_config.ctarConfig.baudRate = spi_config->max_sys_freq;
|
||||
|
||||
SYS_LOG_DBG("word size = %d, baud rate = %d",
|
||||
word_size, spi_config->max_sys_freq);
|
||||
|
||||
clock_freq = CLOCK_GetFreq(config->clock_source);
|
||||
if (!clock_freq) {
|
||||
SYS_LOG_ERR("Got frequency of 0");
|
||||
return -EINVAL;
|
||||
}
|
||||
DSPI_MasterInit(base, &master_config, clock_freq);
|
||||
|
||||
DSPI_MasterTransferCreateHandle(base, &data->handle,
|
||||
spi_mcux_master_transfer_callback, dev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int spi_mcux_slave_select(struct device *dev, u32_t slave)
|
||||
{
|
||||
struct spi_mcux_data *data = dev->driver_data;
|
||||
|
||||
if (slave > FSL_FEATURE_DSPI_CHIP_SELECT_COUNT) {
|
||||
SYS_LOG_ERR("Slave %d is greater than %d",
|
||||
slave, FSL_FEATURE_DSPI_CHIP_SELECT_COUNT);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
data->slave = slave;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int spi_mcux_transceive(struct device *dev,
|
||||
const void *tx_buf, u32_t tx_buf_len,
|
||||
void *rx_buf, u32_t rx_buf_len)
|
||||
{
|
||||
const struct spi_mcux_config *config = dev->config->config_info;
|
||||
struct spi_mcux_data *data = dev->driver_data;
|
||||
SPI_Type *base = config->base;
|
||||
u8_t buf[CONFIG_SPI_MCUX_BUF_SIZE];
|
||||
dspi_transfer_t transfer;
|
||||
status_t status;
|
||||
|
||||
/* Initialize the transfer descriptor */
|
||||
|
||||
SYS_LOG_DBG("tx_buf_len = %d, rx_buf_len = %d, local buf len = %d",
|
||||
tx_buf_len, rx_buf_len, sizeof(buf));
|
||||
|
||||
if (tx_buf_len == rx_buf_len) {
|
||||
/* The tx and rx buffers are the same length, so we can use
|
||||
* them directly.
|
||||
*/
|
||||
transfer.txData = (u8_t *)tx_buf;
|
||||
transfer.rxData = rx_buf;
|
||||
transfer.dataSize = rx_buf_len;
|
||||
SYS_LOG_DBG("Using tx and rx buffers directly");
|
||||
} else if (tx_buf_len == 0) {
|
||||
/* The tx buffer length is zero, so this is a one-way spi read
|
||||
* operation.
|
||||
*/
|
||||
transfer.txData = NULL;
|
||||
transfer.rxData = rx_buf;
|
||||
transfer.dataSize = rx_buf_len;
|
||||
SYS_LOG_DBG("Using rx buffer directly, tx buffer is null");
|
||||
} else if (rx_buf_len == 0) {
|
||||
/* The rx buffer length is zero, so this is a one-way spi write
|
||||
* operation.
|
||||
*/
|
||||
transfer.txData = (u8_t *)tx_buf;
|
||||
transfer.rxData = NULL;
|
||||
transfer.dataSize = tx_buf_len;
|
||||
SYS_LOG_DBG("Using tx buffer directly, rx buffer is null");
|
||||
} else if ((tx_buf_len < rx_buf_len) && (rx_buf_len <= sizeof(buf))) {
|
||||
/* The tx buffer is shorter than the rx buffer, so copy the tx
|
||||
* buffer to the longer local buffer.
|
||||
*/
|
||||
transfer.txData = buf;
|
||||
transfer.rxData = rx_buf;
|
||||
transfer.dataSize = rx_buf_len;
|
||||
memcpy(buf, tx_buf, tx_buf_len);
|
||||
memset(&buf[tx_buf_len], CONFIG_SPI_MCUX_DUMMY_CHAR,
|
||||
rx_buf_len - tx_buf_len);
|
||||
SYS_LOG_DBG("Using local buffer for tx");
|
||||
} else if ((rx_buf_len < tx_buf_len) && (tx_buf_len <= sizeof(buf))) {
|
||||
/* The rx buffer is shorter than the tx buffer, so use the
|
||||
* longer local buffer for rx. After the transfer is complete,
|
||||
* we'll need to copy the local buffer back to the rx buffer.
|
||||
*/
|
||||
transfer.txData = (u8_t *)tx_buf;
|
||||
transfer.rxData = buf;
|
||||
transfer.dataSize = tx_buf_len;
|
||||
SYS_LOG_DBG("Using local buffer for rx");
|
||||
} else {
|
||||
SYS_LOG_ERR("Local buffer too small for transfer");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
transfer.configFlags = kDSPI_MasterCtar0 | kDSPI_MasterPcsContinuous |
|
||||
(data->slave << DSPI_MASTER_PCS_SHIFT);
|
||||
|
||||
/* Start the transfer */
|
||||
status = DSPI_MasterTransferNonBlocking(base, &data->handle, &transfer);
|
||||
|
||||
/* Return an error if the transfer didn't start successfully e.g., if
|
||||
* the bus was busy
|
||||
*/
|
||||
if (status != kStatus_Success) {
|
||||
SYS_LOG_ERR("Transfer could not start");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
/* Wait for the transfer to complete */
|
||||
k_sem_take(&data->sync, K_FOREVER);
|
||||
|
||||
/* Return an error if the transfer didn't complete successfully. */
|
||||
if (data->callback_status != kStatus_Success) {
|
||||
SYS_LOG_ERR("Transfer could not complete");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
/* Copy the local buffer back to the rx buffer. */
|
||||
if ((rx_buf_len < tx_buf_len) && (tx_buf_len <= sizeof(buf))) {
|
||||
memcpy(rx_buf, buf, rx_buf_len);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void spi_mcux_isr(void *arg)
|
||||
{
|
||||
struct device *dev = (struct device *)arg;
|
||||
const struct spi_mcux_config *config = dev->config->config_info;
|
||||
struct spi_mcux_data *data = dev->driver_data;
|
||||
SPI_Type *base = config->base;
|
||||
|
||||
DSPI_MasterTransferHandleIRQ(base, &data->handle);
|
||||
}
|
||||
|
||||
static int spi_mcux_init(struct device *dev)
|
||||
{
|
||||
const struct spi_mcux_config *config = dev->config->config_info;
|
||||
struct spi_mcux_data *data = dev->driver_data;
|
||||
struct spi_config *spi_config;
|
||||
int error;
|
||||
|
||||
k_sem_init(&data->sync, 0, UINT_MAX);
|
||||
|
||||
spi_config = (struct spi_config *)&config->default_cfg;
|
||||
error = spi_mcux_configure(dev, spi_config);
|
||||
if (error) {
|
||||
SYS_LOG_ERR("Could not configure");
|
||||
return error;
|
||||
}
|
||||
|
||||
config->irq_config_func(dev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct spi_driver_api spi_mcux_driver_api = {
|
||||
.configure = spi_mcux_configure,
|
||||
.slave_select = spi_mcux_slave_select,
|
||||
.transceive = spi_mcux_transceive,
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
static void spi_mcux_transfer_next_packet(struct device *dev)
|
||||
{
|
||||
const struct spi_mcux_config *config = dev->config->config_info;
|
||||
|
@ -480,8 +256,6 @@ static const struct spi_driver_api spi_mcux_driver_api = {
|
|||
.release = spi_mcux_release,
|
||||
};
|
||||
|
||||
#endif /* CONFIG_SPI_LEGACY_API */
|
||||
|
||||
#ifdef CONFIG_SPI_0
|
||||
static void spi_mcux_config_func_0(struct device *dev);
|
||||
|
||||
|
@ -489,19 +263,11 @@ static const struct spi_mcux_config spi_mcux_config_0 = {
|
|||
.base = DSPI0,
|
||||
.clock_source = DSPI0_CLK_SRC,
|
||||
.irq_config_func = spi_mcux_config_func_0,
|
||||
#ifdef CONFIG_SPI_LEGACY_API
|
||||
.default_cfg = {
|
||||
.config = CONFIG_SPI_0_DEFAULT_CFG,
|
||||
.max_sys_freq = CONFIG_SPI_0_DEFAULT_BAUD_RATE,
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
static struct spi_mcux_data spi_mcux_data_0 = {
|
||||
#ifndef CONFIG_SPI_LEGACY_API
|
||||
SPI_CONTEXT_INIT_LOCK(spi_mcux_data_0, ctx),
|
||||
SPI_CONTEXT_INIT_SYNC(spi_mcux_data_0, ctx),
|
||||
#endif
|
||||
};
|
||||
|
||||
DEVICE_AND_API_INIT(spi_mcux_0, CONFIG_SPI_0_NAME, &spi_mcux_init,
|
||||
|
@ -525,19 +291,11 @@ static const struct spi_mcux_config spi_mcux_config_1 = {
|
|||
.base = DSPI1,
|
||||
.clock_source = DSPI1_CLK_SRC,
|
||||
.irq_config_func = spi_mcux_config_func_1,
|
||||
#ifdef CONFIG_SPI_LEGACY_API
|
||||
.default_cfg = {
|
||||
.config = CONFIG_SPI_1_DEFAULT_CFG,
|
||||
.max_sys_freq = CONFIG_SPI_1_DEFAULT_BAUD_RATE,
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
static struct spi_mcux_data spi_mcux_data_1 = {
|
||||
#ifndef CONFIG_SPI_LEGACY_API
|
||||
SPI_CONTEXT_INIT_LOCK(spi_mcux_data_1, ctx),
|
||||
SPI_CONTEXT_INIT_SYNC(spi_mcux_data_1, ctx),
|
||||
#endif
|
||||
};
|
||||
|
||||
DEVICE_AND_API_INIT(spi_mcux_1, CONFIG_SPI_1_NAME, &spi_mcux_init,
|
||||
|
@ -561,19 +319,11 @@ static const struct spi_mcux_config spi_mcux_config_2 = {
|
|||
.base = DSPI2,
|
||||
.clock_source = DSPI2_CLK_SRC,
|
||||
.irq_config_func = spi_mcux_config_func_2,
|
||||
#ifdef CONFIG_SPI_LEGACY_API
|
||||
.default_cfg = {
|
||||
.config = CONFIG_SPI_2_DEFAULT_CFG,
|
||||
.max_sys_freq = CONFIG_SPI_2_DEFAULT_BAUD_RATE,
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
static struct spi_mcux_data spi_mcux_data_2 = {
|
||||
#ifndef CONFIG_SPI_LEGACY_API
|
||||
SPI_CONTEXT_INIT_LOCK(spi_mcux_data_2, ctx),
|
||||
SPI_CONTEXT_INIT_SYNC(spi_mcux_data_2, ctx),
|
||||
#endif
|
||||
};
|
||||
|
||||
DEVICE_AND_API_INIT(spi_mcux_2, CONFIG_SPI_2_NAME, &spi_mcux_init,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue