Lines Matching +full:phase +full:- +full:shift
5 * SPDX-License-Identifier: Apache-2.0
42 const struct spi_mcux_flexio_config *config = dev->config; in spi_mcux_transfer_next_packet()
43 struct spi_mcux_flexio_data *data = dev->data; in spi_mcux_transfer_next_packet()
44 struct spi_context *ctx = &data->ctx; in spi_mcux_transfer_next_packet()
48 if ((ctx->tx_len == 0) && (ctx->rx_len == 0)) { in spi_mcux_transfer_next_packet()
50 spi_context_cs_control(&data->ctx, false); in spi_mcux_transfer_next_packet()
51 spi_context_complete(&data->ctx, dev, 0); in spi_mcux_transfer_next_packet()
55 transfer.flags = kFLEXIO_SPI_csContinuous | data->transfer_flags; in spi_mcux_transfer_next_packet()
57 if (ctx->tx_len == 0) { in spi_mcux_transfer_next_packet()
60 transfer.rxData = ctx->rx_buf; in spi_mcux_transfer_next_packet()
61 transfer.dataSize = ctx->rx_len; in spi_mcux_transfer_next_packet()
62 } else if (ctx->rx_len == 0) { in spi_mcux_transfer_next_packet()
64 transfer.txData = (uint8_t *) ctx->tx_buf; in spi_mcux_transfer_next_packet()
66 transfer.dataSize = ctx->tx_len; in spi_mcux_transfer_next_packet()
67 } else if (ctx->tx_len == ctx->rx_len) { in spi_mcux_transfer_next_packet()
69 transfer.txData = (uint8_t *) ctx->tx_buf; in spi_mcux_transfer_next_packet()
70 transfer.rxData = ctx->rx_buf; in spi_mcux_transfer_next_packet()
71 transfer.dataSize = ctx->tx_len; in spi_mcux_transfer_next_packet()
72 } else if (ctx->tx_len > ctx->rx_len) { in spi_mcux_transfer_next_packet()
77 transfer.txData = (uint8_t *) ctx->tx_buf; in spi_mcux_transfer_next_packet()
78 transfer.rxData = ctx->rx_buf; in spi_mcux_transfer_next_packet()
79 transfer.dataSize = ctx->rx_len; in spi_mcux_transfer_next_packet()
85 transfer.txData = (uint8_t *) ctx->tx_buf; in spi_mcux_transfer_next_packet()
86 transfer.rxData = ctx->rx_buf; in spi_mcux_transfer_next_packet()
87 transfer.dataSize = ctx->tx_len; in spi_mcux_transfer_next_packet()
90 data->transfer_len = transfer.dataSize; in spi_mcux_transfer_next_packet()
92 status = FLEXIO_SPI_MasterTransferNonBlocking(config->flexio_spi, &data->handle, in spi_mcux_transfer_next_packet()
102 const struct spi_mcux_flexio_config *config = dev->config; in spi_mcux_flexio_isr()
103 struct spi_mcux_flexio_data *data = dev->data; in spi_mcux_flexio_isr()
107 WAIT_FOR((0U == (FLEXIO_SPI_GetStatusFlags(config->flexio_spi) in spi_mcux_flexio_isr()
110 FLEXIO_SPI_MasterTransferHandleIRQ(config->flexio_spi, &data->handle); in spi_mcux_flexio_isr()
120 spi_context_update_tx(&data->ctx, 1, data->transfer_len); in spi_mcux_master_transfer_callback()
121 spi_context_update_rx(&data->ctx, 1, data->transfer_len); in spi_mcux_master_transfer_callback()
123 spi_mcux_transfer_next_packet(data->dev); in spi_mcux_master_transfer_callback()
143 ctrlReg = base->flexioBase->CTRL; in spi_flexio_master_init()
146 ctrlReg |= (FLEXIO_CTRL_DBGE(masterConfig->enableInDebug) | in spi_flexio_master_init()
147 FLEXIO_CTRL_FASTACC(masterConfig->enableFastAccess) | in spi_flexio_master_init()
148 FLEXIO_CTRL_FLEXEN(masterConfig->enableMaster)); in spi_flexio_master_init()
149 if (!masterConfig->enableInDoze) { in spi_flexio_master_init()
153 base->flexioBase->CTRL = ctrlReg; in spi_flexio_master_init()
157 shifterConfig.timerSelect = base->timerIndex[0]; in spi_flexio_master_init()
159 shifterConfig.pinSelect = base->SDOPinIndex; in spi_flexio_master_init()
163 if (masterConfig->phase == kFLEXIO_SPI_ClockPhaseFirstEdge) { in spi_flexio_master_init()
173 FLEXIO_SetShifterConfig(base->flexioBase, base->shifterIndex[0], &shifterConfig); in spi_flexio_master_init()
176 shifterConfig.timerSelect = base->timerIndex[0]; in spi_flexio_master_init()
178 shifterConfig.pinSelect = base->SDIPinIndex; in spi_flexio_master_init()
184 if (masterConfig->phase == kFLEXIO_SPI_ClockPhaseFirstEdge) { in spi_flexio_master_init()
190 FLEXIO_SetShifterConfig(base->flexioBase, base->shifterIndex[1], &shifterConfig); in spi_flexio_master_init()
193 timerConfig.triggerSelect = FLEXIO_TIMER_TRIGGER_SEL_SHIFTnSTAT(base->shifterIndex[0]); in spi_flexio_master_init()
197 timerConfig.pinSelect = base->SCKPinIndex; in spi_flexio_master_init()
207 /* Low 8-bits are used to configure baudrate. */ in spi_flexio_master_init()
208 timerDiv = (uint16_t)(srcClock_Hz / masterConfig->baudRate_Bps); in spi_flexio_master_init()
209 timerDiv = timerDiv / 2U - 1U; in spi_flexio_master_init()
210 /* High 8-bits are used to configure shift clock edges(transfer width). */ in spi_flexio_master_init()
211 timerCmp = ((uint16_t)masterConfig->dataMode * 2U - 1U) << 8U; in spi_flexio_master_init()
216 FLEXIO_SetTimerConfig(base->flexioBase, base->timerIndex[0], &timerConfig); in spi_flexio_master_init()
222 const struct spi_mcux_flexio_config *config = dev->config; in spi_mcux_flexio_configure()
223 struct spi_mcux_flexio_data *data = dev->data; in spi_mcux_flexio_configure()
229 if (spi_context_configured(&data->ctx, spi_cfg)) { in spi_mcux_flexio_configure()
234 if (spi_cfg->operation & SPI_HALF_DUPLEX) { in spi_mcux_flexio_configure()
235 LOG_ERR("Half-duplex not supported"); in spi_mcux_flexio_configure()
236 return -ENOTSUP; in spi_mcux_flexio_configure()
239 if (SPI_OP_MODE_GET(spi_cfg->operation) != SPI_OP_MODE_MASTER) { in spi_mcux_flexio_configure()
241 return -ENOTSUP; in spi_mcux_flexio_configure()
246 word_size = SPI_WORD_SIZE_GET(spi_cfg->operation); in spi_mcux_flexio_configure()
249 return -EINVAL; in spi_mcux_flexio_configure()
253 if (spi_cfg->operation & SPI_TRANSFER_LSB) { in spi_mcux_flexio_configure()
255 data->transfer_flags = kFLEXIO_SPI_8bitLsb; in spi_mcux_flexio_configure()
257 data->transfer_flags = kFLEXIO_SPI_16bitLsb; in spi_mcux_flexio_configure()
259 data->transfer_flags = kFLEXIO_SPI_32bitLsb; in spi_mcux_flexio_configure()
263 data->transfer_flags = kFLEXIO_SPI_8bitMsb; in spi_mcux_flexio_configure()
265 data->transfer_flags = kFLEXIO_SPI_16bitMsb; in spi_mcux_flexio_configure()
267 data->transfer_flags = kFLEXIO_SPI_32bitMsb; in spi_mcux_flexio_configure()
271 if (nxp_flexio_get_rate(config->flexio_dev, &clock_freq)) { in spi_mcux_flexio_configure()
272 return -EINVAL; in spi_mcux_flexio_configure()
275 master_config.phase = in spi_mcux_flexio_configure()
276 (SPI_MODE_GET(spi_cfg->operation) & SPI_MODE_CPHA) in spi_mcux_flexio_configure()
280 master_config.baudRate_Bps = spi_cfg->frequency; in spi_mcux_flexio_configure()
281 spi_flexio_master_init(config->flexio_spi, &master_config, in spi_mcux_flexio_configure()
282 (SPI_MODE_GET(spi_cfg->operation) & SPI_MODE_CPOL), clock_freq); in spi_mcux_flexio_configure()
284 FLEXIO_SPI_MasterTransferCreateHandle(config->flexio_spi, &data->handle, in spi_mcux_flexio_configure()
289 data->ctx.config = spi_cfg; in spi_mcux_flexio_configure()
303 const struct spi_mcux_flexio_config *config = dev->config; in transceive()
304 struct spi_mcux_flexio_data *data = dev->data; in transceive()
307 spi_context_lock(&data->ctx, asynchronous, cb, userdata, spi_cfg); in transceive()
309 nxp_flexio_lock(config->flexio_dev); in transceive()
311 nxp_flexio_unlock(config->flexio_dev); in transceive()
316 spi_context_buffers_setup(&data->ctx, tx_bufs, rx_bufs, 1); in transceive()
318 spi_context_cs_control(&data->ctx, true); in transceive()
320 nxp_flexio_lock(config->flexio_dev); in transceive()
321 nxp_flexio_irq_disable(config->flexio_dev); in transceive()
325 nxp_flexio_irq_enable(config->flexio_dev); in transceive()
326 nxp_flexio_unlock(config->flexio_dev); in transceive()
328 ret = spi_context_wait_for_completion(&data->ctx); in transceive()
330 spi_context_release(&data->ctx, ret); in transceive()
358 struct spi_mcux_flexio_data *data = dev->data; in spi_mcux_release()
360 spi_context_unlock_unconditionally(&data->ctx); in spi_mcux_release()
367 const struct spi_mcux_flexio_config *config = dev->config; in spi_mcux_init()
368 struct spi_mcux_flexio_data *data = dev->data; in spi_mcux_init()
371 err = nxp_flexio_child_attach(config->flexio_dev, config->child); in spi_mcux_init()
376 err = spi_context_cs_configure_all(&data->ctx); in spi_mcux_init()
381 spi_context_unlock_unconditionally(&data->ctx); in spi_mcux_init()
383 data->dev = dev; in spi_mcux_init()
387 err = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT); in spi_mcux_init()
392 spi_context_unlock_unconditionally(&data->ctx); in spi_mcux_init()