123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745 |
- #define LOG_LEVEL CONFIG_SPI_LOG_LEVEL
- #include <logging/log.h>
- LOG_MODULE_REGISTER(spimt_acts);
- #include "spi_context.h"
- #include <errno.h>
- #include <device.h>
- #include <drivers/ipmsg.h>
- #include <drivers/spimt.h>
- #include <rbuf/rbuf_msg_sc.h>
- #include <soc.h>
- #include <board_cfg.h>
- #include <linker/linker-defs.h>
- #define SPIMT_CLOCK (4000000)
- #define SPI_BUF_LEN (128)
- #define SPI_MAX_BC (32*1024)
- #define SPI_DELAY (8)
- typedef struct {
- volatile uint32_t CTL;
- volatile uint32_t DMA_CTL;
- volatile uint32_t DMA_ADD;
- volatile uint32_t DMA_CNT;
- volatile uint32_t RESERVED[12];
- } SPIMT_AUTO_TASK_Type;
- typedef struct {
- volatile uint32_t CTL;
- volatile uint32_t NML_STA;
- volatile uint32_t NML_TXDAT;
- volatile uint32_t NML_RXDAT;
- volatile uint32_t NML_BC;
- volatile uint32_t AUTO_TASK_STAT;
- volatile uint32_t AUTO_TASK_IE;
- volatile uint32_t AUTO_TASK_IP;
- volatile uint32_t TASK_CS_DLY;
- volatile uint32_t TASK_CS_SEL;
- volatile uint32_t RESERVED[54];
- volatile SPIMT_AUTO_TASK_Type AUTO_TASK[8];
- volatile uint32_t RESERVED1[3904];
- } SPIMT_Type;
- typedef SPIMT_Type SPIMT_ARRAYType[1];
- #define SPIMT ((SPIMT_ARRAYType*) SPIMT0_REG_BASE)
- #define SPIMT_CTL_CS_SEL_Msk (0x40000UL)
- #define SPIMT_CTL_MODSEL_Msk (0x20000UL)
- #define SPIMT_CTL_MODE_SEL_Msk (0x10000UL)
- #define SPIMT_CTL_RXWR_SEL_Msk (0x4000UL)
- #define SPIMT_CTL_DELAY_Msk (0x3c00UL)
- #define SPIMT_CTL_3WIRE_Msk (0x80UL)
- #define SPIMT_CTL_REQ_Msk (0x40UL)
- #define SPIMT_CTL_TXFIFO_EN_Msk (0x20UL)
- #define SPIMT_CTL_RXFIFO_EN_Msk (0x10UL)
- #define SPIMT_CTL_SS_Msk (0x8UL)
- #define SPIMT_CTL_LOOP_Msk (0x4UL)
- #define SPIMT_CTL_WR_Msk (0x3UL)
- #define SPIMT_CTL_CS_SEL_Pos (18UL)
- #define SPIMT_CTL_DELAY_Pos (10UL)
- #define SPIMT_CTL_WR_Pos (0UL)
- #define SPIMT_NML_STA_BUSY_Msk (0x10UL)
- #define SPIMT_NML_STA_TXFU_Msk (0x8UL)
- #define SPIMT_NML_STA_TXEM_Msk (0x4UL)
- #define SPIMT_NML_STA_RXFU_Msk (0x2UL)
- #define SPIMT_NML_STA_RXEM_Msk (0x1UL)
- #define SPIMT_AUTO_TASK_IE_TSK0HFIE_Pos (8UL)
- #define SPIMT_AUTO_TASK_IE_TSK0TCIE_Pos (0UL)
- #define SPIMT_AUTO_TASK_IP_TSK0HFIP_Pos (8UL)
- #define SPIMT_AUTO_TASK_IP_TSK0TCIP_Pos (0UL)
- #define SPIMT_TASK_CS_SEL_TSK0CS_SEL_Pos (0UL)
- #define SPIMT_TASK_CS_SEL_TSK0CS_SEL_Msk (0x3UL)
- #define SPIMT_AUTO_TASK_CTL_SOFT_EN_Msk (0x80000000UL)
- #define SPIMT_AUTO_TASK_CTL_SOFT_ST_Msk (0x40000000UL)
- #define SPIMT_AUTO_TASK_DMA_CTL_DMARELD_Pos (1UL)
- #define SPIMT_AUTO_TASK_DMA_CTL_DMASTART_Msk (0x1UL)
- #define CMU_TIMERCLK(id) (CMU_TIMER0CLK + (id) * 4)
- #define T_CTL(id) (T0_CTL + (id) * 0x20)
- #define T_VAL(id) (T0_VAL + (id) * 0x20)
- struct acts_spimt_config {
- uint32_t ctl_reg;
- uint8_t bus_id;
- uint8_t clock_id;
- uint8_t reset_id;
- void (*irq_config_func)(void);
- };
- struct acts_spimt_data {
- struct spi_context ctx;
- spi_task_callback_t task_cb[SPI_TASK_NUM];
- void *task_cb_ctx[SPI_TASK_NUM];
- spi_task_t *task_attr[SPI_TASK_NUM];
- uint8_t *task_buf[SPI_TASK_NUM];
- uint32_t task_len[SPI_TASK_NUM];
- };
- #define DEV_CFG(dev) \
- ((const struct acts_spimt_config *const)(dev)->config)
- #define DEV_DATA(dev) \
- ((struct acts_spimt_data *const)(dev)->data)
- #if IS_ENABLED(CONFIG_SPIMT_0) || IS_ENABLED(CONFIG_SPIMT_1)
- static void spimt_auto_mode_set(int spi_dev)
- {
-
- SPIMT[spi_dev]->AUTO_TASK_IP = SPIMT[spi_dev]->AUTO_TASK_IP;
-
- SPIMT[spi_dev]->CTL |= SPIMT_CTL_MODSEL_Msk;
- }
- static void spimt_auto_mode_cancel(int spi_dev)
- {
-
- SPIMT[spi_dev]->CTL &= ~SPIMT_CTL_MODSEL_Msk;
- }
- static void spimt_cs_set_low(int spi_dev)
- {
-
- spimt_auto_mode_cancel(spi_dev);
-
- SPIMT[spi_dev]->CTL &= ~SPIMT_CTL_SS_Msk;
- }
- static void spimt_cs_set_high(int spi_dev)
- {
-
- SPIMT[spi_dev]->CTL |= SPIMT_CTL_SS_Msk;
-
- spimt_auto_mode_set(spi_dev);
- }
- static void spimt_cs_set(int spi_dev, int enable)
- {
- if (enable) {
- spimt_cs_set_low(spi_dev);
- } else {
- spimt_cs_set_high(spi_dev);
- }
- }
- static void spimt_cs_select(int spi_dev, int cs_num)
- {
- SPIMT[spi_dev]->CTL &= ~SPIMT_CTL_CS_SEL_Msk;
- SPIMT[spi_dev]->CTL |= (cs_num << SPIMT_CTL_CS_SEL_Pos);
- }
- static void spimt_read(int spi_dev, unsigned char *buf, unsigned int len)
- {
- int left = len;
- int rx_len = 0;
- int i;
-
- SPIMT[spi_dev]->NML_STA = SPIMT[spi_dev]->NML_STA;
- while (left) {
-
- rx_len = left > SPI_MAX_BC ? SPI_MAX_BC : left;
- left -= rx_len;
- SPIMT[spi_dev]->NML_BC = rx_len;
-
- SPIMT[spi_dev]->CTL |= (1 << SPIMT_CTL_WR_Pos);
-
- for (i = 0; i < rx_len; i++) {
- while(SPIMT[spi_dev]->NML_STA & SPIMT_NML_STA_RXEM_Msk);
- buf[i] = SPIMT[spi_dev]->NML_RXDAT;
- }
-
- SPIMT[spi_dev]->CTL &= ~SPIMT_CTL_WR_Msk;
- }
- }
- static void spimt_write(int spi_dev, unsigned char *buf, unsigned int len)
- {
- int i;
-
- SPIMT[spi_dev]->NML_STA = SPIMT[spi_dev]->NML_STA;
-
- SPIMT[spi_dev]->CTL |= (2 << SPIMT_CTL_WR_Pos);
-
- for (i = 0; i < len; i ++) {
- while (SPIMT[spi_dev]->NML_STA & SPIMT_NML_STA_TXFU_Msk);
- SPIMT[spi_dev]->NML_TXDAT = buf[i];
- }
-
- while(!(SPIMT[spi_dev]->NML_STA & SPIMT_NML_STA_TXEM_Msk));
-
- while(SPIMT[spi_dev]->NML_STA & SPIMT_NML_STA_BUSY_Msk);
-
- SPIMT[spi_dev]->CTL &= ~SPIMT_CTL_WR_Msk;
- }
- static void spimt_auto_task_config(int spi_dev, int task_id, const spi_task_t *task_attr, uint32_t addr)
- {
- uint8_t *pdata = (uint8_t *)&task_attr->ctl;
- volatile uint32_t ctl = *(volatile unsigned int*)pdata;
-
- SPIMT[spi_dev]->AUTO_TASK[task_id].DMA_ADD = addr;
- SPIMT[spi_dev]->AUTO_TASK[task_id].DMA_CNT = task_attr->dma.len;
- if (task_attr->dma.len > 0) {
- SPIMT[spi_dev]->AUTO_TASK[task_id].DMA_CTL = SPIMT_AUTO_TASK_DMA_CTL_DMASTART_Msk
- | (task_attr->dma.reload << SPIMT_AUTO_TASK_DMA_CTL_DMARELD_Pos);
- }
- if (task_attr->irq_type & SPI_TASK_IRQ_CMPLT) {
-
- SPIMT[spi_dev]->AUTO_TASK_IE |= 1 << (SPIMT_AUTO_TASK_IE_TSK0TCIE_Pos + task_id);
- } else {
-
- SPIMT[spi_dev]->AUTO_TASK_IE &= ~(1 << (SPIMT_AUTO_TASK_IE_TSK0TCIE_Pos + task_id));
- }
- if (task_attr->irq_type & SPI_TASK_IRQ_HALF_CMPLT) {
-
- SPIMT[spi_dev]->AUTO_TASK_IE |= 1 << (SPIMT_AUTO_TASK_IE_TSK0HFIE_Pos + task_id);
- } else {
-
- SPIMT[spi_dev]->AUTO_TASK_IE &= ~(1 << (SPIMT_AUTO_TASK_IE_TSK0HFIE_Pos + task_id));
- }
-
- SPIMT[spi_dev]->AUTO_TASK[task_id].CTL = (ctl & ~(SPIMT_AUTO_TASK_CTL_SOFT_EN_Msk | SPIMT_AUTO_TASK_CTL_SOFT_ST_Msk));
-
- SPIMT[spi_dev]->TASK_CS_SEL &= ~(SPIMT_TASK_CS_SEL_TSK0CS_SEL_Msk << (task_id * 2));
- SPIMT[spi_dev]->TASK_CS_SEL |= ((task_id / 4) << (task_id * 2));
- }
- static void spimt_auto_task_soft_start(int spi_dev, int task_id)
- {
-
- SPIMT[spi_dev]->AUTO_TASK[task_id].CTL |= (SPIMT_AUTO_TASK_CTL_SOFT_EN_Msk | SPIMT_AUTO_TASK_CTL_SOFT_ST_Msk);
- }
- static void spimt_auto_task_soft_stop(int spi_dev, int task_id)
- {
-
- SPIMT[spi_dev]->AUTO_TASK[task_id].CTL &= ~(SPIMT_AUTO_TASK_CTL_SOFT_EN_Msk | SPIMT_AUTO_TASK_CTL_SOFT_ST_Msk);
- }
- __sleepfunc static int spimt_auto_task_irq_get_pending(int spi_dev)
- {
- return SPIMT[spi_dev]->AUTO_TASK_IP & SPIMT[spi_dev]->AUTO_TASK_IE;
- }
- __sleepfunc static int spimt_auto_task_irq_mask(int task_id, int task_irq_type)
- {
- int irq_pending_mask = 0;
- switch (task_irq_type) {
- case SPI_TASK_IRQ_CMPLT:
- irq_pending_mask = 1 << (SPIMT_AUTO_TASK_IP_TSK0TCIP_Pos + task_id);
- break;
- case SPI_TASK_IRQ_HALF_CMPLT:
- irq_pending_mask = 1 << (SPIMT_AUTO_TASK_IP_TSK0HFIP_Pos + task_id);
- break;
- default:
- break;
- }
- return irq_pending_mask;
- }
- __sleepfunc static void spimt_auto_task_irq_clr_pending(int spi_dev, int task_id, int task_irq_type)
- {
- SPIMT[spi_dev]->AUTO_TASK_IP = spimt_auto_task_irq_mask(task_id, task_irq_type);
- }
- bool spimt_acts_transfer_ongoing(struct acts_spimt_data *data)
- {
- return spi_context_tx_on(&data->ctx) || spi_context_rx_on(&data->ctx);
- }
- static int spimt_acts_transfer_data(const struct acts_spimt_config *cfg, struct acts_spimt_data *data)
- {
- struct spi_context *ctx = &data->ctx;
- if ((ctx->tx_len > SPI_BUF_LEN) || (ctx->rx_len > SPI_BUF_LEN)) {
- LOG_ERR("buffer overflow");
- return -1;
- }
- LOG_DBG("tx_len %d, rx_len %d", ctx->tx_len, ctx->rx_len);
- if (ctx->tx_len) {
- spimt_write(cfg->bus_id, (uint8_t*)ctx->tx_buf, ctx->tx_len);
- spi_context_update_tx(ctx, 1, ctx->tx_len);
- }
- if (ctx->rx_len) {
- spimt_read(cfg->bus_id, (uint8_t*)ctx->rx_buf, ctx->rx_len);
- spi_context_update_rx(ctx, 1, ctx->rx_len);
- }
- return 0;
- }
- static int spimt_acts_configure(const struct acts_spimt_config *cfg,
- struct acts_spimt_data *spi,
- const struct spi_config *config)
- {
- if (spi_context_configured(&spi->ctx, config)) {
-
- return 0;
- }
-
- return 0;
- }
- static int transceive(const struct device *dev,
- const struct spi_config *config,
- const struct spi_buf_set *tx_bufs,
- const struct spi_buf_set *rx_bufs,
- bool asynchronous,
- struct k_poll_signal *signal)
- {
- const struct acts_spimt_config *cfg =DEV_CFG(dev);
- struct acts_spimt_data *data = DEV_DATA(dev);
- int ret;
- spi_context_lock(&data->ctx, asynchronous, signal);
-
- ret = spimt_acts_configure(cfg, data, config);
- if (ret) {
- goto out;
- }
-
- spi_context_buffers_setup(&data->ctx, tx_bufs, rx_bufs, 1);
-
- spimt_cs_set(cfg->bus_id, 1);
-
- do {
- ret = spimt_acts_transfer_data(cfg, data);
- } while (!ret && spimt_acts_transfer_ongoing(data));
-
- spimt_cs_set(cfg->bus_id, 0);
- out:
- spi_context_release(&data->ctx, ret);
- return ret;
- }
- static int spimt_acts_transceive(const struct device *dev,
- const struct spi_config *config,
- const struct spi_buf_set *tx_bufs,
- const struct spi_buf_set *rx_bufs)
- {
- return transceive(dev, config, tx_bufs, rx_bufs, false, NULL);
- }
- static int spimt_acts_release(const struct device *dev,
- const struct spi_config *config)
- {
- struct acts_spimt_data *data = dev->data;
- spi_context_unlock_unconditionally(&data->ctx);
- return 0;
- }
- static void spimt_acts_register_callback(const struct device *dev, int task_id,
- spi_task_callback_t cb, void *context)
- {
- struct acts_spimt_data *data = DEV_DATA(dev);
- data->task_cb[task_id] = cb;
- data->task_cb_ctx[task_id] = context;
- }
- static uint8_t* spimt_task_buf_start(struct acts_spimt_data *data,
- int task_id, uint32_t addr, uint16_t len, uint8_t rd)
- {
- rbuf_t *rbuf;
- uint8_t *sbuf;
- uint16_t slen;
-
- sbuf = data->task_buf[task_id];
-
- if ((sbuf != NULL) && (len > data->task_len[task_id])) {
-
- rbuf = RBUF_FR_BUF(sbuf);
- RB_MSG_FREE(rbuf);
- sbuf = NULL;
- }
-
- if (sbuf == NULL) {
- slen = (len < 16) ? 16 : len;
- rbuf = RB_MSG_ALLOC(slen);
- sbuf = (uint8_t*)RBUF_TO_BUF(rbuf);
- data->task_buf[task_id] = sbuf;
- data->task_len[task_id] = slen;
- }
-
- if (!rd && (addr != 0)) {
- memcpy(sbuf, (void*)addr, len);
- }
- return sbuf;
- }
- static uint8_t* spimt_task_buf_stop(struct acts_spimt_data *data,
- int task_id, uint32_t addr, uint32_t len, uint8_t rd)
- {
- uint8_t *sbuf;
- sbuf = data->task_buf[task_id];
-
- if (rd && (addr != 0)) {
- memcpy((void*)addr, sbuf, len);
- }
- return sbuf;
- }
- static int spimt_acts_task_start(const struct device *dev, int task_id,
- const spi_task_t *attr)
- {
- const struct acts_spimt_config *cfg =DEV_CFG(dev);
- struct acts_spimt_data *data = DEV_DATA(dev);
- uint8_t *buf;
-
- buf = spimt_task_buf_start(data, task_id, attr->dma.addr, attr->dma.len, attr->ctl.rwsel);
-
- data->task_attr[task_id] = (spi_task_t*)attr;
-
- spimt_auto_mode_set(cfg->bus_id);
-
- spimt_auto_task_config(cfg->bus_id, task_id, attr, (uint32_t)buf);
-
- if (!attr->ctl.soft) {
-
- ppi_trig_src_en(attr->trig.trig, 0);
-
- ppi_trig_src_clr_pending(attr->trig.trig);
-
- ppi_task_trig_config(attr->trig.chan, attr->trig.task, attr->trig.trig);
-
- ppi_trig_src_en(attr->trig.trig, attr->trig.en);
- if (attr->trig.en) {
- if (attr->trig.trig <= TIMER4) {
- sys_write32(0x1, CMU_TIMERCLK(attr->trig.trig));
- sys_write32(attr->trig.peri*1000, T_VAL(attr->trig.trig));
- sys_write32(0x24, T_CTL(attr->trig.trig));
- }
- }
- } else {
-
- spimt_auto_task_soft_start(cfg->bus_id, task_id);
- }
- return 0;
- }
- static int spimt_acts_task_stop(const struct device *dev, int task_id)
- {
- const struct acts_spimt_config *cfg =DEV_CFG(dev);
- struct acts_spimt_data *data = DEV_DATA(dev);
- const spi_task_t *attr = data->task_attr[task_id];
-
- if ((attr != NULL) && (!attr->ctl.soft)) {
- ppi_trig_src_en(attr->trig.trig, 0);
- if (attr->trig.trig <= TIMER4) {
- sys_write32(0x0, T_CTL(attr->trig.trig));
- }
- } else {
- spimt_auto_task_soft_stop(cfg->bus_id, task_id);
- }
-
- spimt_task_buf_stop(data, task_id, attr->dma.addr, attr->dma.len, attr->ctl.rwsel);
-
- data->task_attr[task_id] = NULL;
- return 0;
- }
- static int spimt_acts_cs_select(const struct device *dev, int cs_num)
- {
- const struct acts_spimt_config *cfg = DEV_CFG(dev);
- spimt_cs_select(cfg->bus_id, cs_num);
- return 0;
- }
- static const unsigned short spi_irq_list[2] = {
- SPI_TASK_IRQ_CMPLT,
- SPI_TASK_IRQ_HALF_CMPLT,
- };
- static void spimt_acts_isr(const struct device *dev)
- {
- const struct acts_spimt_config *cfg = DEV_CFG(dev);
- struct acts_spimt_data *data = DEV_DATA(dev);
- int task_id, irq_type, len;
- int pending = spimt_auto_task_irq_get_pending(cfg->bus_id);
- int pos = find_msb_set(pending) - 1;
- spi_task_callback_t cb;
- const spi_task_t *attr;
- uint8_t *buf;
- void *ctx;
- while (pos >= 0) {
- task_id = (pos % 8);
- irq_type = spi_irq_list[pos / 8];
- attr = data->task_attr[task_id];
-
- spimt_auto_task_irq_clr_pending(cfg->bus_id, task_id, irq_type);
-
- ppi_trig_src_clr_pending(SPIMT0_TASK0_CIP + attr->trig.task);
- if (!attr->ctl.soft) {
- ppi_trig_src_clr_pending(attr->trig.trig);
- if (attr->trig.trig <= TIMER4) {
-
- }
- }
-
- cb = data->task_cb[task_id];
- if (cb != NULL) {
-
- ctx = data->task_cb_ctx[task_id];
- buf = data->task_buf[task_id];
- len = attr->dma.len / 2;
- switch(irq_type) {
- case SPI_TASK_IRQ_CMPLT:
- buf += len;
- break;
- case SPI_TASK_IRQ_HALF_CMPLT:
- break;
- }
- cb(buf, len, ctx);
- }
-
- pending = spimt_auto_task_irq_get_pending(cfg->bus_id);
- pos = find_msb_set(pending) - 1;
- }
- }
- __sleepfunc uint8_t* spi_task_get_data(int bus_id, int task_id, int trig, int *plen)
- {
- int len = 0;
- uint8_t *buf = NULL;
- int pending = spimt_auto_task_irq_get_pending(bus_id);
-
- if (pending & spimt_auto_task_irq_mask(task_id, SPI_TASK_IRQ_HALF_CMPLT)) {
- spimt_auto_task_irq_clr_pending(bus_id, task_id, SPI_TASK_IRQ_HALF_CMPLT);
- len = SPIMT[bus_id]->AUTO_TASK[task_id].DMA_CNT / 2;
- buf = (uint8_t *)SPIMT[bus_id]->AUTO_TASK[task_id].DMA_ADD;
- } else if (pending & spimt_auto_task_irq_mask(task_id, SPI_TASK_IRQ_CMPLT)) {
- spimt_auto_task_irq_clr_pending(bus_id, task_id, SPI_TASK_IRQ_CMPLT);
- len = SPIMT[bus_id]->AUTO_TASK[task_id].DMA_CNT / 2;
- buf = (uint8_t *)SPIMT[bus_id]->AUTO_TASK[task_id].DMA_ADD + len;
- }
-
- if (buf) {
- ppi_trig_src_clr_pending(SPIMT0_TASK0_CIP+task_id);
- if (trig >= 0) {
- ppi_trig_src_clr_pending(trig);
- }
- }
- if (plen) {
- *plen = len;
- }
- return buf;
- }
- int spimt_acts_init(const struct device *dev)
- {
- const struct acts_spimt_config *cfg = DEV_CFG(dev);
- struct acts_spimt_data *data = DEV_DATA(dev);
-
- acts_clock_peripheral_enable(cfg->clock_id);
-
- acts_reset_peripheral(cfg->reset_id);
-
- clk_set_rate(cfg->clock_id, SPIMT_CLOCK);
-
- SPIMT[cfg->bus_id]->CTL = SPIMT_CTL_SS_Msk | (SPI_DELAY << SPIMT_CTL_DELAY_Pos)
- | SPIMT_CTL_RXFIFO_EN_Msk | SPIMT_CTL_TXFIFO_EN_Msk;
- spi_context_unlock_unconditionally(&data->ctx);
-
- cfg->irq_config_func();
- return 0;
- }
- static const struct spimt_driver_api spimt_acts_driver_api = {
- .spi_api = {
- .transceive = spimt_acts_transceive,
- .release = spimt_acts_release,
- },
- .register_callback = spimt_acts_register_callback,
- .task_start = spimt_acts_task_start,
- .task_stop = spimt_acts_task_stop,
- .cs_select = spimt_acts_cs_select,
- };
- #endif
- #define SPIMT_ACTS_DEFINE_CONFIG(n) \
- static const struct device DEVICE_NAME_GET(spimt##n##_acts); \
- \
- static void spimt##n##_acts_irq_config(void) \
- { \
- IRQ_CONNECT(IRQ_ID_SPI##n##MT, CONFIG_SPIMT_##n##_IRQ_PRI, \
- spimt_acts_isr, \
- DEVICE_GET(spimt##n##_acts), 0); \
- irq_enable(IRQ_ID_SPI##n##MT); \
- } \
- static const struct acts_spimt_config spimt##n##_acts_config = { \
- .ctl_reg = SPIMT##n##_REG_BASE,\
- .bus_id = n,\
- .clock_id = CLOCK_ID_SPIMT##n,\
- .reset_id = RESET_ID_SPIMT##n,\
- .irq_config_func = spimt##n##_acts_irq_config, \
- }
- #define SPIMT_ACTS_DEFINE_DATA(n) \
- static struct acts_spimt_data spimt##n##_acts_dev_data = { \
- SPI_CONTEXT_INIT_LOCK(spimt##n##_acts_dev_data, ctx), \
- SPI_CONTEXT_INIT_SYNC(spimt##n##_acts_dev_data, ctx), \
- }
- #define SPIMT_ACTS_DEVICE_INIT(n) \
- SPIMT_ACTS_DEFINE_CONFIG(n); \
- SPIMT_ACTS_DEFINE_DATA(n); \
- DEVICE_DEFINE(spimt##n##_acts, \
- CONFIG_SPIMT_##n##_NAME, \
- &spimt_acts_init, NULL, &spimt##n##_acts_dev_data, \
- &spimt##n##_acts_config, POST_KERNEL, \
- CONFIG_SPI_INIT_PRIORITY, &spimt_acts_driver_api);
- #if IS_ENABLED(CONFIG_SPIMT_0)
- SPIMT_ACTS_DEVICE_INIT(0)
- #endif
- #if IS_ENABLED(CONFIG_SPIMT_1)
- SPIMT_ACTS_DEVICE_INIT(1)
- #endif
|