Lines Matching +full:cs +full:- +full:mode

4  * SPDX-License-Identifier: Apache-2.0
38 #define SPI_CFG(dev) ((struct spi_b91_cfg *) ((dev)->config))
44 #define SPI_DATA(dev) ((struct spi_b91_data *) ((dev)->data))
47 /* disable hardware cs flow control */
52 /* loop through all cs pins (cs0..cs2) */ in spi_b91_hw_cs_disable()
54 /* get CS pin defined in device tree */ in spi_b91_hw_cs_disable()
55 pin = config->cs_pin[i]; in spi_b91_hw_cs_disable()
57 /* if CS pin is defined in device tree */ in spi_b91_hw_cs_disable()
59 if (config->peripheral_id == PSPI_MODULE) { in spi_b91_hw_cs_disable()
60 /* disable CS pin for PSPI */ in spi_b91_hw_cs_disable()
63 /* disable CS pin for MSPI */ in spi_b91_hw_cs_disable()
70 /* config cs flow control: hardware or software */
79 /* disable all hardware CS pins */ in spi_b91_config_cs()
87 if (config->slave >= CHIP_SELECT_COUNT) { in spi_b91_config_cs()
88 LOG_ERR("Slave %d not supported (max. %d)", config->slave, CHIP_SELECT_COUNT - 1); in spi_b91_config_cs()
92 /* loop through all cs pins: cs0, cs1 and cs2 */ in spi_b91_config_cs()
94 /* get cs pin defined in device tree */ in spi_b91_config_cs()
95 cs_pin = b91_config->cs_pin[cs_id]; in spi_b91_config_cs()
97 /* if cs pin is not defined for the selected slave, return error */ in spi_b91_config_cs()
98 if ((cs_pin == 0) && (cs_id == config->slave)) { in spi_b91_config_cs()
99 LOG_ERR("cs%d-pin is not defined in device tree", config->slave); in spi_b91_config_cs()
103 /* disable cs pin if it is defined and is not requested */ in spi_b91_config_cs()
104 if ((cs_pin != 0) && (cs_id != config->slave)) { in spi_b91_config_cs()
105 if (b91_config->peripheral_id == PSPI_MODULE) { in spi_b91_config_cs()
112 /* enable cs pin if it is defined and is requested */ in spi_b91_config_cs()
113 if ((cs_pin != 0) && (cs_id == config->slave)) { in spi_b91_config_cs()
114 if (b91_config->peripheral_id == PSPI_MODULE) { in spi_b91_config_cs()
133 const struct spi_buf *tx_buf = tx_bufs->buffers; in spi_b91_get_txrx_len()
134 const struct spi_buf *rx_buf = rx_bufs->buffers; in spi_b91_get_txrx_len()
137 for (int i = 0; i < tx_bufs->count; i++) { in spi_b91_get_txrx_len()
138 len_tx += tx_buf->len; in spi_b91_get_txrx_len()
143 for (int i = 0; i < rx_bufs->count; i++) { in spi_b91_get_txrx_len()
144 len_rx += rx_buf->len; in spi_b91_get_txrx_len()
159 tx = *(uint8_t *)(ctx->tx_buf); in spi_b91_tx()
182 *ctx->rx_buf = rx; in spi_b91_rx()
194 struct spi_context *ctx = &SPI_DATA(dev)->ctx; in spi_b91_txrx()
197 spi_set_transmode(cfg->peripheral_id, SPI_MODE_WRITE_AND_READ); in spi_b91_txrx()
198 spi_set_cmd(cfg->peripheral_id, 0); in spi_b91_txrx()
199 spi_tx_cnt(cfg->peripheral_id, len); in spi_b91_txrx()
200 spi_rx_cnt(cfg->peripheral_id, len); in spi_b91_txrx()
205 if (chunk_size > (len - i)) { in spi_b91_txrx()
206 chunk_size = len - i; in spi_b91_txrx()
210 spi_b91_tx(cfg->peripheral_id, ctx, chunk_size); in spi_b91_txrx()
215 spi_b91_rx(cfg->peripheral_id, ctx, chunk_size); in spi_b91_txrx()
218 spi_b91_rx(cfg->peripheral_id, ctx, chunk_size - 1); in spi_b91_txrx()
219 } else if ((len - i) > SPI_WR_RD_CHUNK_SIZE_MAX) { in spi_b91_txrx()
221 spi_b91_rx(cfg->peripheral_id, ctx, chunk_size); in spi_b91_txrx()
224 spi_b91_rx(cfg->peripheral_id, ctx, chunk_size + 1); in spi_b91_txrx()
228 BM_SET(reg_spi_fifo_state(cfg->peripheral_id), FLD_SPI_TXF_CLR); in spi_b91_txrx()
229 BM_SET(reg_spi_fifo_state(cfg->peripheral_id), FLD_SPI_RXF_CLR); in spi_b91_txrx()
233 while (spi_is_busy(cfg->peripheral_id)) { in spi_b91_txrx()
244 if (config->operation & SPI_HALF_DUPLEX) { in spi_b91_is_config_supported()
245 LOG_ERR("Half-duplex not supported"); in spi_b91_is_config_supported()
250 if (config->operation & SPI_MODE_LOOP) { in spi_b91_is_config_supported()
251 LOG_ERR("Loop back mode not supported"); in spi_b91_is_config_supported()
256 if (config->operation & SPI_TRANSFER_LSB) { in spi_b91_is_config_supported()
262 if (SPI_WORD_SIZE_GET(config->operation) != SPI_WORD_SIZE) { in spi_b91_is_config_supported()
267 /* check for CS active high */ in spi_b91_is_config_supported()
268 if (config->operation & SPI_CS_ACTIVE_HIGH) { in spi_b91_is_config_supported()
269 LOG_ERR("CS active high not supported for HW flow control"); in spi_b91_is_config_supported()
275 if ((config->operation & SPI_LINES_MASK) == SPI_LINES_OCTAL) { in spi_b91_is_config_supported()
278 } else if (((config->operation & SPI_LINES_MASK) == in spi_b91_is_config_supported()
280 (b91_config->peripheral_id == PSPI_MODULE)) { in spi_b91_is_config_supported()
287 if (SPI_OP_MODE_GET(config->operation) == SPI_OP_MODE_SLAVE) { in spi_b91_is_config_supported()
289 return -ENOTSUP; in spi_b91_is_config_supported()
300 spi_mode_type_e mode = SPI_MODE0; in spi_b91_config() local
303 uint8_t clk_src = b91_config->peripheral_id == PSPI_MODULE ? sys_clk.pclk : sys_clk.hclk; in spi_b91_config()
307 return -ENOTSUP; in spi_b91_config()
310 /* config slave selection (CS): hw or sw */ in spi_b91_config()
312 return -ENOTSUP; in spi_b91_config()
315 /* get SPI mode */ in spi_b91_config()
316 if (((config->operation & SPI_MODE_CPHA) == 0) && in spi_b91_config()
317 ((config->operation & SPI_MODE_CPOL) == 0)) { in spi_b91_config()
318 mode = SPI_MODE0; in spi_b91_config()
319 } else if (((config->operation & SPI_MODE_CPHA) == 0) && in spi_b91_config()
320 ((config->operation & SPI_MODE_CPOL) == SPI_MODE_CPOL)) { in spi_b91_config()
321 mode = SPI_MODE1; in spi_b91_config()
322 } else if (((config->operation & SPI_MODE_CPHA) == SPI_MODE_CPHA) && in spi_b91_config()
323 ((config->operation & SPI_MODE_CPOL) == 0)) { in spi_b91_config()
324 mode = SPI_MODE2; in spi_b91_config()
325 } else if (((config->operation & SPI_MODE_CPHA) == SPI_MODE_CPHA) && in spi_b91_config()
326 ((config->operation & SPI_MODE_CPOL) == SPI_MODE_CPOL)) { in spi_b91_config()
327 mode = SPI_MODE3; in spi_b91_config()
331 spi_master_init(b91_config->peripheral_id, in spi_b91_config()
332 clk_src * 1000000 / (2 * config->frequency) - 1, mode); in spi_b91_config()
333 spi_master_config(b91_config->peripheral_id, SPI_NOMAL); in spi_b91_config()
337 uint32_t lines = config->operation & SPI_LINES_MASK; in spi_b91_config()
340 spi_set_io_mode(b91_config->peripheral_id, in spi_b91_config()
343 spi_set_io_mode(b91_config->peripheral_id, in spi_b91_config()
346 spi_set_io_mode(b91_config->peripheral_id, in spi_b91_config()
352 status = pinctrl_apply_state(b91_config->pcfg, PINCTRL_STATE_DEFAULT); in spi_b91_config()
359 b91_data->ctx.config = config; in spi_b91_config()
370 err = spi_context_cs_configure_all(&data->ctx); in spi_b91_init()
375 spi_context_unlock_unconditionally(&data->ctx); in spi_b91_init()
397 spi_context_lock(&data->ctx, false, NULL, NULL, config); in spi_b91_transceive()
398 spi_context_buffers_setup(&data->ctx, tx_bufs, rx_bufs, 1); in spi_b91_transceive()
400 /* if cs is defined: software cs control, set active true */ in spi_b91_transceive()
402 spi_context_cs_control(&data->ctx, true); in spi_b91_transceive()
408 /* if cs is defined: software cs control, set active false */ in spi_b91_transceive()
410 spi_context_cs_control(&data->ctx, false); in spi_b91_transceive()
414 status = spi_context_wait_for_completion(&data->ctx); in spi_b91_transceive()
415 spi_context_release(&data->ctx, status); in spi_b91_transceive()
436 return -ENOTSUP; in spi_b91_transceive_async()
446 if (!spi_context_configured(&data->ctx, config)) { in spi_b91_release()
447 return -EINVAL; in spi_b91_release()
450 spi_context_unlock_unconditionally(&data->ctx); in spi_b91_release()