Lines Matching +full:slave +full:- +full:mode
4 * SPDX-License-Identifier: Apache-2.0
37 #define SPI_CFG(dev) ((struct spi_b91_cfg *) ((dev)->config))
43 #define SPI_DATA(dev) ((struct spi_b91_data *) ((dev)->data))
54 pin = config->cs_pin[i]; in spi_b91_hw_cs_disable()
58 if (config->peripheral_id == PSPI_MODULE) { in spi_b91_hw_cs_disable()
85 /* check for correct slave id */ in spi_b91_config_cs()
86 if (config->slave >= CHIP_SELECT_COUNT) { in spi_b91_config_cs()
87 LOG_ERR("Slave %d not supported (max. %d)", config->slave, CHIP_SELECT_COUNT - 1); in spi_b91_config_cs()
94 cs_pin = b91_config->cs_pin[cs_id]; in spi_b91_config_cs()
96 /* if cs pin is not defined for the selected slave, return error */ in spi_b91_config_cs()
97 if ((cs_pin == 0) && (cs_id == config->slave)) { in spi_b91_config_cs()
98 LOG_ERR("cs%d-pin is not defined in device tree", config->slave); in spi_b91_config_cs()
103 if ((cs_pin != 0) && (cs_id != config->slave)) { in spi_b91_config_cs()
104 if (b91_config->peripheral_id == PSPI_MODULE) { in spi_b91_config_cs()
112 if ((cs_pin != 0) && (cs_id == config->slave)) { in spi_b91_config_cs()
113 if (b91_config->peripheral_id == PSPI_MODULE) { in spi_b91_config_cs()
132 const struct spi_buf *tx_buf = tx_bufs->buffers; in spi_b91_get_txrx_len()
133 const struct spi_buf *rx_buf = rx_bufs->buffers; in spi_b91_get_txrx_len()
136 for (int i = 0; i < tx_bufs->count; i++) { in spi_b91_get_txrx_len()
137 len_tx += tx_buf->len; in spi_b91_get_txrx_len()
142 for (int i = 0; i < rx_bufs->count; i++) { in spi_b91_get_txrx_len()
143 len_rx += rx_buf->len; in spi_b91_get_txrx_len()
158 tx = *(uint8_t *)(ctx->tx_buf); in spi_b91_tx()
181 *ctx->rx_buf = rx; in spi_b91_rx()
193 struct spi_context *ctx = &SPI_DATA(dev)->ctx; in spi_b91_txrx()
196 spi_set_transmode(cfg->peripheral_id, SPI_MODE_WRITE_AND_READ); in spi_b91_txrx()
197 spi_set_cmd(cfg->peripheral_id, 0); in spi_b91_txrx()
198 spi_tx_cnt(cfg->peripheral_id, len); in spi_b91_txrx()
199 spi_rx_cnt(cfg->peripheral_id, len); in spi_b91_txrx()
204 if (chunk_size > (len - i)) { in spi_b91_txrx()
205 chunk_size = len - i; in spi_b91_txrx()
209 spi_b91_tx(cfg->peripheral_id, ctx, chunk_size); in spi_b91_txrx()
214 spi_b91_rx(cfg->peripheral_id, ctx, chunk_size); in spi_b91_txrx()
217 spi_b91_rx(cfg->peripheral_id, ctx, chunk_size - 1); in spi_b91_txrx()
218 } else if ((len - i) > SPI_WR_RD_CHUNK_SIZE_MAX) { in spi_b91_txrx()
220 spi_b91_rx(cfg->peripheral_id, ctx, chunk_size); in spi_b91_txrx()
223 spi_b91_rx(cfg->peripheral_id, ctx, chunk_size + 1); in spi_b91_txrx()
227 BM_SET(reg_spi_fifo_state(cfg->peripheral_id), FLD_SPI_TXF_CLR); in spi_b91_txrx()
228 BM_SET(reg_spi_fifo_state(cfg->peripheral_id), FLD_SPI_RXF_CLR); in spi_b91_txrx()
232 while (spi_is_busy(cfg->peripheral_id)) { in spi_b91_txrx()
243 if (config->operation & SPI_HALF_DUPLEX) { in spi_b91_is_config_supported()
244 LOG_ERR("Half-duplex not supported"); in spi_b91_is_config_supported()
249 if (config->operation & SPI_MODE_LOOP) { in spi_b91_is_config_supported()
250 LOG_ERR("Loop back mode not supported"); in spi_b91_is_config_supported()
255 if (config->operation & SPI_TRANSFER_LSB) { in spi_b91_is_config_supported()
261 if (SPI_WORD_SIZE_GET(config->operation) != SPI_WORD_SIZE) { in spi_b91_is_config_supported()
267 if (config->operation & SPI_CS_ACTIVE_HIGH) { in spi_b91_is_config_supported()
274 if ((config->operation & SPI_LINES_MASK) == SPI_LINES_OCTAL) { in spi_b91_is_config_supported()
277 } else if (((config->operation & SPI_LINES_MASK) == in spi_b91_is_config_supported()
279 (b91_config->peripheral_id == PSPI_MODULE)) { in spi_b91_is_config_supported()
285 /* check for slave configuration */ in spi_b91_is_config_supported()
286 if (SPI_OP_MODE_GET(config->operation) == SPI_OP_MODE_SLAVE) { in spi_b91_is_config_supported()
287 LOG_ERR("SPI Slave is not implemented"); in spi_b91_is_config_supported()
288 return -ENOTSUP; in spi_b91_is_config_supported()
299 spi_mode_type_e mode = SPI_MODE0; in spi_b91_config() local
302 uint8_t clk_src = b91_config->peripheral_id == PSPI_MODULE ? sys_clk.pclk : sys_clk.hclk; in spi_b91_config()
306 return -ENOTSUP; in spi_b91_config()
309 /* config slave selection (CS): hw or sw */ in spi_b91_config()
311 return -ENOTSUP; in spi_b91_config()
314 /* get SPI mode */ in spi_b91_config()
315 if (((config->operation & SPI_MODE_CPHA) == 0) && in spi_b91_config()
316 ((config->operation & SPI_MODE_CPOL) == 0)) { in spi_b91_config()
317 mode = SPI_MODE0; in spi_b91_config()
318 } else if (((config->operation & SPI_MODE_CPHA) == 0) && in spi_b91_config()
319 ((config->operation & SPI_MODE_CPOL) == SPI_MODE_CPOL)) { in spi_b91_config()
320 mode = SPI_MODE1; in spi_b91_config()
321 } else if (((config->operation & SPI_MODE_CPHA) == SPI_MODE_CPHA) && in spi_b91_config()
322 ((config->operation & SPI_MODE_CPOL) == 0)) { in spi_b91_config()
323 mode = SPI_MODE2; in spi_b91_config()
324 } else if (((config->operation & SPI_MODE_CPHA) == SPI_MODE_CPHA) && in spi_b91_config()
325 ((config->operation & SPI_MODE_CPOL) == SPI_MODE_CPOL)) { in spi_b91_config()
326 mode = SPI_MODE3; in spi_b91_config()
330 spi_master_init(b91_config->peripheral_id, in spi_b91_config()
331 clk_src * 1000000 / (2 * config->frequency) - 1, mode); in spi_b91_config()
332 spi_master_config(b91_config->peripheral_id, SPI_NOMAL); in spi_b91_config()
336 uint32_t lines = config->operation & SPI_LINES_MASK; in spi_b91_config()
339 spi_set_io_mode(b91_config->peripheral_id, in spi_b91_config()
342 spi_set_io_mode(b91_config->peripheral_id, in spi_b91_config()
345 spi_set_io_mode(b91_config->peripheral_id, in spi_b91_config()
351 status = pinctrl_apply_state(b91_config->pcfg, PINCTRL_STATE_DEFAULT); in spi_b91_config()
358 b91_data->ctx.config = config; in spi_b91_config()
369 err = spi_context_cs_configure_all(&data->ctx); in spi_b91_init()
374 spi_context_unlock_unconditionally(&data->ctx); in spi_b91_init()
396 spi_context_lock(&data->ctx, false, NULL, NULL, config); in spi_b91_transceive()
397 spi_context_buffers_setup(&data->ctx, tx_bufs, rx_bufs, 1); in spi_b91_transceive()
401 spi_context_cs_control(&data->ctx, true); in spi_b91_transceive()
409 spi_context_cs_control(&data->ctx, false); in spi_b91_transceive()
413 status = spi_context_wait_for_completion(&data->ctx); in spi_b91_transceive()
414 spi_context_release(&data->ctx, status); in spi_b91_transceive()
435 return -ENOTSUP; in spi_b91_transceive_async()
445 if (!spi_context_configured(&data->ctx, config)) { in spi_b91_release()
446 return -EINVAL; in spi_b91_release()
449 spi_context_unlock_unconditionally(&data->ctx); in spi_b91_release()