Lines Matching +full:fifo +full:- +full:read +full:- +full:threshold

2  * SPDX-License-Identifier: Apache-2.0
42 * CPOL/CPHA = 0/0 --> SPI_MODE_0
43 * CPOL/CPHA = 0/1 --> SPI_MODE_1
44 * CPOL/CPHA = 1/0 --> SPI_MODE_2
45 * CPOL/CPHA = 1/1 --> SPI_MODE_3
58 struct spi_numaker_data *data = dev->data; in spi_numaker_configure()
59 const struct spi_numaker_config *dev_cfg = dev->config; in spi_numaker_configure()
62 if (spi_context_configured(&data->ctx, config)) { in spi_numaker_configure()
66 if (SPI_MODE_GET(config->operation) & SPI_MODE_LOOP) { in spi_numaker_configure()
68 return -ENOTSUP; in spi_numaker_configure()
71 if (SPI_OP_MODE_GET(config->operation) == SPI_OP_MODE_SLAVE) { in spi_numaker_configure()
73 return -ENOTSUP; in spi_numaker_configure()
76 /* Clear FIFO */ in spi_numaker_configure()
77 SPI_ClearRxFIFO(dev_cfg->spi); in spi_numaker_configure()
78 SPI_ClearTxFIFO(dev_cfg->spi); in spi_numaker_configure()
80 if (SPI_MODE_GET(config->operation) & SPI_MODE_CPOL) { in spi_numaker_configure()
81 mode = (SPI_MODE_GET(config->operation) & SPI_MODE_CPHA) ? 3 : 2; in spi_numaker_configure()
83 mode = (SPI_MODE_GET(config->operation) & SPI_MODE_CPHA) ? 1 : 0; in spi_numaker_configure()
87 if (dev_cfg->is_qspi) { in spi_numaker_configure()
88 QSPI_Open((QSPI_T *)dev_cfg->spi, in spi_numaker_configure()
89 (SPI_OP_MODE_GET(config->operation) == SPI_OP_MODE_SLAVE) ? QSPI_SLAVE in spi_numaker_configure()
92 SPI_WORD_SIZE_GET(config->operation), config->frequency); in spi_numaker_configure()
94 SPI_Open(dev_cfg->spi, in spi_numaker_configure()
95 (SPI_OP_MODE_GET(config->operation) == SPI_OP_MODE_SLAVE) ? SPI_SLAVE in spi_numaker_configure()
98 SPI_WORD_SIZE_GET(config->operation), config->frequency); in spi_numaker_configure()
102 if ((config->operation) & SPI_TRANSFER_LSB) { in spi_numaker_configure()
103 SPI_SET_LSB_FIRST(dev_cfg->spi); in spi_numaker_configure()
105 SPI_SET_MSB_FIRST(dev_cfg->spi); in spi_numaker_configure()
109 if (config->operation & SPI_HALF_DUPLEX) { in spi_numaker_configure()
110 /* half duplex, which results in 3-wire usage */ in spi_numaker_configure()
111 SPI_ENABLE_3WIRE_MODE(dev_cfg->spi); in spi_numaker_configure()
114 SPI_DISABLE_3WIRE_MODE(dev_cfg->spi); in spi_numaker_configure()
118 if (config->operation & SPI_CS_ACTIVE_HIGH) { in spi_numaker_configure()
119 SPI_SET_SS_HIGH(dev_cfg->spi); in spi_numaker_configure()
121 SPI_SET_SS_LOW(dev_cfg->spi); in spi_numaker_configure()
125 * low-active. in spi_numaker_configure()
127 if (data->ctx.num_cs_gpios != 0) { in spi_numaker_configure()
128 SPI_EnableAutoSS(dev_cfg->spi, SPI_SS, SPI_SS_ACTIVE_LOW); in spi_numaker_configure()
130 SPI_DisableAutoSS(dev_cfg->spi); in spi_numaker_configure()
133 /* Be able to set TX/RX FIFO threshold, for ex: SPI_SetFIFO(dev_cfg->spi, 2, 2) */ in spi_numaker_configure()
135 data->ctx.config = config; in spi_numaker_configure()
142 struct spi_numaker_data *data = dev->data; in spi_numaker_txrx()
143 const struct spi_numaker_config *dev_cfg = dev->config; in spi_numaker_txrx()
144 struct spi_context *ctx = &data->ctx; in spi_numaker_txrx()
150 word_size = SPI_WORD_SIZE_GET(ctx->config->operation); in spi_numaker_txrx()
168 return -EIO; in spi_numaker_txrx()
171 LOG_DBG("%s -->word_size [%d]", __func__, word_size); in spi_numaker_txrx()
174 tx_frame = ((ctx->tx_buf == NULL) ? SPI_NUMAKER_TX_NOP in spi_numaker_txrx()
175 : UNALIGNED_GET((uint8_t *)(data->ctx.tx_buf))); in spi_numaker_txrx()
177 SPI_WRITE_TX(dev_cfg->spi, tx_frame); in spi_numaker_txrx()
181 time_out_cnt = SystemCoreClock; /* 1 second time-out */ in spi_numaker_txrx()
182 while (SPI_IS_BUSY(dev_cfg->spi)) { in spi_numaker_txrx()
183 if (--time_out_cnt == 0) { in spi_numaker_txrx()
184 LOG_ERR("Wait for SPI time-out"); in spi_numaker_txrx()
185 return -EIO; in spi_numaker_txrx()
189 LOG_DBG("%s --> TX [0x%x] done", __func__, tx_frame); in spi_numaker_txrx()
192 SPI_WRITE_TX(dev_cfg->spi, 0x00U); in spi_numaker_txrx()
193 time_out_cnt = SystemCoreClock; /* 1 second time-out */ in spi_numaker_txrx()
194 while (SPI_IS_BUSY(dev_cfg->spi)) { in spi_numaker_txrx()
195 if (--time_out_cnt == 0) { in spi_numaker_txrx()
196 LOG_ERR("Wait for SPI time-out"); in spi_numaker_txrx()
197 return -EIO; in spi_numaker_txrx()
202 /* Read received data */ in spi_numaker_txrx()
204 if (SPI_GET_RX_FIFO_COUNT(dev_cfg->spi) > 0) { in spi_numaker_txrx()
205 rx_frame = SPI_READ_RX(dev_cfg->spi); in spi_numaker_txrx()
206 if (ctx->rx_buf != NULL) { in spi_numaker_txrx()
207 UNALIGNED_PUT(rx_frame, (uint8_t *)data->ctx.rx_buf); in spi_numaker_txrx()
210 LOG_DBG("%s --> RX [0x%x] done", __func__, rx_frame); in spi_numaker_txrx()
214 LOG_DBG("%s --> exit", __func__); in spi_numaker_txrx()
221 return spi_context_tx_on(&data->ctx) || spi_context_rx_on(&data->ctx); in spi_numaker_remain_words()
228 struct spi_numaker_data *data = dev->data; in spi_numaker_transceive()
229 struct spi_context *ctx = &data->ctx; in spi_numaker_transceive()
230 const struct spi_numaker_config *dev_cfg = dev->config; in spi_numaker_transceive()
235 ctx->config = config; in spi_numaker_transceive()
242 SPI_ENABLE(dev_cfg->spi); in spi_numaker_transceive()
244 spi_context_buffers_setup(&data->ctx, tx_bufs, rx_bufs, 1); in spi_numaker_transceive()
248 spi_context_cs_control(&data->ctx, true); in spi_numaker_transceive()
261 spi_context_cs_control(&data->ctx, false); in spi_numaker_transceive()
263 SPI_DISABLE(dev_cfg->spi); in spi_numaker_transceive()
267 LOG_DBG("%s --> [%d]", __func__, ret); in spi_numaker_transceive()
273 struct spi_numaker_data *data = dev->data; in spi_numaker_release()
274 struct spi_context *ctx = &data->ctx; in spi_numaker_release()
277 return -EINVAL; in spi_numaker_release()
294 struct spi_numaker_data *data = dev->data; in spi_numaker_init()
295 const struct spi_numaker_config *dev_cfg = dev->config; in spi_numaker_init()
304 scc_subsys.pcc.clk_modidx = dev_cfg->clk_modidx; in spi_numaker_init()
305 scc_subsys.pcc.clk_src = dev_cfg->clk_src; in spi_numaker_init()
306 scc_subsys.pcc.clk_div = dev_cfg->clk_div; in spi_numaker_init()
309 err = clock_control_on(dev_cfg->clk_dev, (clock_control_subsys_t)&scc_subsys); in spi_numaker_init()
314 err = clock_control_configure(dev_cfg->clk_dev, (clock_control_subsys_t)&scc_subsys, NULL); in spi_numaker_init()
319 err = pinctrl_apply_state(dev_cfg->pincfg, PINCTRL_STATE_DEFAULT); in spi_numaker_init()
325 err = spi_context_cs_configure_all(&data->ctx); in spi_numaker_init()
330 spi_context_unlock_unconditionally(&data->ctx); in spi_numaker_init()
333 if (!device_is_ready(dev_cfg->reset.dev)) { in spi_numaker_init()
335 err = -ENODEV; in spi_numaker_init()
340 reset_line_toggle_dt(&dev_cfg->reset); in spi_numaker_init()