Lines Matching +full:half +full:- +full:duplex
2 * SPDX-License-Identifier: Apache-2.0
41 * CPOL/CPHA = 0/0 --> SPI_MODE_0
42 * CPOL/CPHA = 0/1 --> SPI_MODE_1
43 * CPOL/CPHA = 1/0 --> SPI_MODE_2
44 * CPOL/CPHA = 1/1 --> SPI_MODE_3
57 struct spi_numaker_data *data = dev->data; in spi_numaker_configure()
58 const struct spi_numaker_config *dev_cfg = dev->config; in spi_numaker_configure()
61 if (spi_context_configured(&data->ctx, config)) { in spi_numaker_configure()
65 if (SPI_MODE_GET(config->operation) & SPI_MODE_LOOP) { in spi_numaker_configure()
67 return -ENOTSUP; in spi_numaker_configure()
70 if (SPI_OP_MODE_GET(config->operation) == SPI_OP_MODE_SLAVE) { in spi_numaker_configure()
72 return -ENOTSUP; in spi_numaker_configure()
76 SPI_ClearRxFIFO(dev_cfg->spi); in spi_numaker_configure()
77 SPI_ClearTxFIFO(dev_cfg->spi); in spi_numaker_configure()
79 if (SPI_MODE_GET(config->operation) & SPI_MODE_CPOL) { in spi_numaker_configure()
80 mode = (SPI_MODE_GET(config->operation) & SPI_MODE_CPHA) ? 3 : 2; in spi_numaker_configure()
82 mode = (SPI_MODE_GET(config->operation) & SPI_MODE_CPHA) ? 1 : 0; in spi_numaker_configure()
86 if (dev_cfg->is_qspi) { in spi_numaker_configure()
87 QSPI_Open((QSPI_T *)dev_cfg->spi, in spi_numaker_configure()
88 (SPI_OP_MODE_GET(config->operation) == SPI_OP_MODE_SLAVE) ? QSPI_SLAVE in spi_numaker_configure()
91 SPI_WORD_SIZE_GET(config->operation), config->frequency); in spi_numaker_configure()
93 SPI_Open(dev_cfg->spi, in spi_numaker_configure()
94 (SPI_OP_MODE_GET(config->operation) == SPI_OP_MODE_SLAVE) ? SPI_SLAVE in spi_numaker_configure()
97 SPI_WORD_SIZE_GET(config->operation), config->frequency); in spi_numaker_configure()
101 if ((config->operation) & SPI_TRANSFER_LSB) { in spi_numaker_configure()
102 SPI_SET_LSB_FIRST(dev_cfg->spi); in spi_numaker_configure()
104 SPI_SET_MSB_FIRST(dev_cfg->spi); in spi_numaker_configure()
107 /* full/half duplex */ in spi_numaker_configure()
108 if (config->operation & SPI_HALF_DUPLEX) { in spi_numaker_configure()
109 /* half duplex, which results in 3-wire usage */ in spi_numaker_configure()
110 SPI_ENABLE_3WIRE_MODE(dev_cfg->spi); in spi_numaker_configure()
112 /* full duplex */ in spi_numaker_configure()
113 SPI_DISABLE_3WIRE_MODE(dev_cfg->spi); in spi_numaker_configure()
117 if (config->operation & SPI_CS_ACTIVE_HIGH) { in spi_numaker_configure()
118 SPI_SET_SS_HIGH(dev_cfg->spi); in spi_numaker_configure()
120 SPI_SET_SS_LOW(dev_cfg->spi); in spi_numaker_configure()
124 * low-active. in spi_numaker_configure()
126 if (data->ctx.num_cs_gpios != 0) { in spi_numaker_configure()
127 SPI_EnableAutoSS(dev_cfg->spi, SPI_SS, SPI_SS_ACTIVE_LOW); in spi_numaker_configure()
129 SPI_DisableAutoSS(dev_cfg->spi); in spi_numaker_configure()
132 /* Be able to set TX/RX FIFO threshold, for ex: SPI_SetFIFO(dev_cfg->spi, 2, 2) */ in spi_numaker_configure()
134 data->ctx.config = config; in spi_numaker_configure()
141 struct spi_numaker_data *data = dev->data; in spi_numaker_txrx()
142 const struct spi_numaker_config *dev_cfg = dev->config; in spi_numaker_txrx()
143 struct spi_context *ctx = &data->ctx; in spi_numaker_txrx()
149 word_size = SPI_WORD_SIZE_GET(ctx->config->operation); in spi_numaker_txrx()
167 return -EIO; in spi_numaker_txrx()
170 LOG_DBG("%s -->word_size [%d]", __func__, word_size); in spi_numaker_txrx()
173 tx_frame = ((ctx->tx_buf == NULL) ? SPI_NUMAKER_TX_NOP in spi_numaker_txrx()
174 : UNALIGNED_GET((uint8_t *)(data->ctx.tx_buf))); in spi_numaker_txrx()
176 SPI_WRITE_TX(dev_cfg->spi, tx_frame); in spi_numaker_txrx()
180 time_out_cnt = SystemCoreClock; /* 1 second time-out */ in spi_numaker_txrx()
181 while (SPI_IS_BUSY(dev_cfg->spi)) { in spi_numaker_txrx()
182 if (--time_out_cnt == 0) { in spi_numaker_txrx()
183 LOG_ERR("Wait for SPI time-out"); in spi_numaker_txrx()
184 return -EIO; in spi_numaker_txrx()
188 LOG_DBG("%s --> TX [0x%x] done", __func__, tx_frame); in spi_numaker_txrx()
193 if (SPI_GET_RX_FIFO_COUNT(dev_cfg->spi) > 0) { in spi_numaker_txrx()
194 rx_frame = SPI_READ_RX(dev_cfg->spi); in spi_numaker_txrx()
195 if (ctx->rx_buf != NULL) { in spi_numaker_txrx()
196 UNALIGNED_PUT(rx_frame, (uint8_t *)data->ctx.rx_buf); in spi_numaker_txrx()
199 LOG_DBG("%s --> RX [0x%x] done", __func__, rx_frame); in spi_numaker_txrx()
203 LOG_DBG("%s --> exit", __func__); in spi_numaker_txrx()
210 return spi_context_tx_on(&data->ctx) || spi_context_rx_on(&data->ctx); in spi_numaker_remain_words()
217 struct spi_numaker_data *data = dev->data; in spi_numaker_transceive()
218 struct spi_context *ctx = &data->ctx; in spi_numaker_transceive()
219 const struct spi_numaker_config *dev_cfg = dev->config; in spi_numaker_transceive()
224 ctx->config = config; in spi_numaker_transceive()
231 SPI_ENABLE(dev_cfg->spi); in spi_numaker_transceive()
233 spi_context_buffers_setup(&data->ctx, tx_bufs, rx_bufs, 1); in spi_numaker_transceive()
237 spi_context_cs_control(&data->ctx, true); in spi_numaker_transceive()
250 spi_context_cs_control(&data->ctx, false); in spi_numaker_transceive()
252 SPI_DISABLE(dev_cfg->spi); in spi_numaker_transceive()
256 LOG_DBG("%s --> [%d]", __func__, ret); in spi_numaker_transceive()
262 struct spi_numaker_data *data = dev->data; in spi_numaker_release()
263 struct spi_context *ctx = &data->ctx; in spi_numaker_release()
266 return -EINVAL; in spi_numaker_release()
278 struct spi_numaker_data *data = dev->data; in spi_numaker_init()
279 const struct spi_numaker_config *dev_cfg = dev->config; in spi_numaker_init()
288 scc_subsys.pcc.clk_modidx = dev_cfg->clk_modidx; in spi_numaker_init()
289 scc_subsys.pcc.clk_src = dev_cfg->clk_src; in spi_numaker_init()
290 scc_subsys.pcc.clk_div = dev_cfg->clk_div; in spi_numaker_init()
293 err = clock_control_on(dev_cfg->clk_dev, (clock_control_subsys_t)&scc_subsys); in spi_numaker_init()
298 err = clock_control_configure(dev_cfg->clk_dev, (clock_control_subsys_t)&scc_subsys, NULL); in spi_numaker_init()
303 err = pinctrl_apply_state(dev_cfg->pincfg, PINCTRL_STATE_DEFAULT); in spi_numaker_init()
309 err = spi_context_cs_configure_all(&data->ctx); in spi_numaker_init()
314 spi_context_unlock_unconditionally(&data->ctx); in spi_numaker_init()
317 if (!device_is_ready(dev_cfg->reset.dev)) { in spi_numaker_init()
319 err = -ENODEV; in spi_numaker_init()
324 reset_line_toggle_dt(&dev_cfg->reset); in spi_numaker_init()