Lines Matching full:data

60 	struct ra_spi_data *data = dev->data;  in spi_cb()  local
64 spi_context_cs_control(&data->ctx, false); in spi_cb()
65 spi_context_complete(&data->ctx, dev, 0); in spi_cb()
73 spi_context_cs_control(&data->ctx, false); in spi_cb()
74 spi_context_complete(&data->ctx, dev, -EIO); in spi_cb()
83 struct ra_spi_data *data = dev->data; in ra_spi_configure() local
86 if (spi_context_configured(&data->ctx, config)) { in ra_spi_configure()
91 if (data->spi.open != 0) { in ra_spi_configure()
92 R_SPI_Close(&data->spi); in ra_spi_configure()
100 data->fsp_config.operating_mode = SPI_MODE_SLAVE; in ra_spi_configure()
102 data->fsp_config.operating_mode = SPI_MODE_MASTER; in ra_spi_configure()
106 data->fsp_config.clk_polarity = SPI_CLK_POLARITY_HIGH; in ra_spi_configure()
108 data->fsp_config.clk_polarity = SPI_CLK_POLARITY_LOW; in ra_spi_configure()
112 data->fsp_config.clk_phase = SPI_CLK_PHASE_EDGE_EVEN; in ra_spi_configure()
114 if (data->fsp_config.operating_mode == SPI_MODE_MASTER) { in ra_spi_configure()
115 data->fsp_config.clk_phase = SPI_CLK_PHASE_EDGE_ODD; in ra_spi_configure()
123 data->fsp_config.bit_order = SPI_BIT_ORDER_LSB_FIRST; in ra_spi_configure()
125 data->fsp_config.bit_order = SPI_BIT_ORDER_MSB_FIRST; in ra_spi_configure()
129 data->fsp_config_extend.ssl_polarity = SPI_SSLP_HIGH; in ra_spi_configure()
131 data->fsp_config_extend.ssl_polarity = SPI_SSLP_LOW; in ra_spi_configure()
137 &data->fsp_config_extend.spck_div); in ra_spi_configure()
144 data->fsp_config_extend.spi_comm = SPI_COMMUNICATION_FULL_DUPLEX; in ra_spi_configure()
146 data->fsp_config_extend.spi_clksyn = SPI_SSL_MODE_CLK_SYN; in ra_spi_configure()
148 data->fsp_config_extend.spi_clksyn = SPI_SSL_MODE_SPI; in ra_spi_configure()
149 data->fsp_config_extend.ssl_select = SPI_SSL_SELECT_SSL0; in ra_spi_configure()
152 data->fsp_config.p_extend = &data->fsp_config_extend; in ra_spi_configure()
154 data->fsp_config.p_callback = spi_cb; in ra_spi_configure()
155 data->fsp_config.p_context = dev; in ra_spi_configure()
156 fsp_err = R_SPI_Open(&data->spi, &data->fsp_config); in ra_spi_configure()
161 data->ctx.config = config; in ra_spi_configure()
166 static bool ra_spi_transfer_ongoing(struct ra_spi_data *data) in ra_spi_transfer_ongoing() argument
169 return (spi_context_tx_on(&data->ctx) || spi_context_rx_on(&data->ctx)); in ra_spi_transfer_ongoing()
171 if (spi_context_total_tx_len(&data->ctx) < spi_context_total_rx_len(&data->ctx)) { in ra_spi_transfer_ongoing()
172 return (spi_context_tx_on(&data->ctx) || spi_context_rx_on(&data->ctx)); in ra_spi_transfer_ongoing()
174 return (spi_context_tx_on(&data->ctx) && spi_context_rx_on(&data->ctx)); in ra_spi_transfer_ongoing()
180 static int ra_spi_transceive_slave(struct ra_spi_data *data) in ra_spi_transceive_slave() argument
182 R_SPI0_Type *p_spi_reg = data->spi.p_regs; in ra_spi_transceive_slave()
184 (spi_bit_width_t)(SPI_WORD_SIZE_GET(data->ctx.config->operation) - 1); in ra_spi_transceive_slave()
186 if (p_spi_reg->SPSR_b.SPTEF && spi_context_tx_buf_on(&data->ctx)) { in ra_spi_transceive_slave()
189 if (data->ctx.tx_buf != NULL) { in ra_spi_transceive_slave()
190 if (data->dfs > 2) { in ra_spi_transceive_slave()
191 tx = *(uint32_t *)(data->ctx.tx_buf); in ra_spi_transceive_slave()
192 } else if (data->dfs > 1) { in ra_spi_transceive_slave()
193 tx = *(uint16_t *)(data->ctx.tx_buf); in ra_spi_transceive_slave()
195 tx = *(uint8_t *)(data->ctx.tx_buf); in ra_spi_transceive_slave()
201 /* Update data register */ in ra_spi_transceive_slave()
210 spi_context_update_tx(&data->ctx, data->dfs, 1); in ra_spi_transceive_slave()
215 if (p_spi_reg->SPSR_b.SPRF && spi_context_rx_buf_on(&data->ctx)) { in ra_spi_transceive_slave()
218 /* Update RX data */ in ra_spi_transceive_slave()
227 if (data->dfs > 2) { in ra_spi_transceive_slave()
228 UNALIGNED_PUT(rx, (uint32_t *)data->ctx.rx_buf); in ra_spi_transceive_slave()
229 } else if (data->dfs > 1) { in ra_spi_transceive_slave()
230 UNALIGNED_PUT(rx, (uint16_t *)data->ctx.rx_buf); in ra_spi_transceive_slave()
232 UNALIGNED_PUT(rx, (uint8_t *)data->ctx.rx_buf); in ra_spi_transceive_slave()
234 spi_context_update_rx(&data->ctx, data->dfs, 1); in ra_spi_transceive_slave()
240 static int ra_spi_transceive_master(struct ra_spi_data *data) in ra_spi_transceive_master() argument
242 R_SPI0_Type *p_spi_reg = data->spi.p_regs; in ra_spi_transceive_master()
244 (spi_bit_width_t)(SPI_WORD_SIZE_GET(data->ctx.config->operation) - 1); in ra_spi_transceive_master()
249 if (spi_context_tx_buf_on(&data->ctx)) { in ra_spi_transceive_master()
250 if (data->dfs > 2) { in ra_spi_transceive_master()
251 tx = *(uint32_t *)(data->ctx.tx_buf); in ra_spi_transceive_master()
252 } else if (data->dfs > 1) { in ra_spi_transceive_master()
253 tx = *(uint16_t *)(data->ctx.tx_buf); in ra_spi_transceive_master()
255 tx = *(uint8_t *)(data->ctx.tx_buf); in ra_spi_transceive_master()
264 /* Update data register */ in ra_spi_transceive_master()
273 spi_context_update_tx(&data->ctx, data->dfs, 1); in ra_spi_transceive_master()
279 /* Update RX data */ in ra_spi_transceive_master()
288 if (spi_context_rx_buf_on(&data->ctx)) { in ra_spi_transceive_master()
289 if (data->dfs > 2) { in ra_spi_transceive_master()
290 UNALIGNED_PUT(rx, (uint32_t *)data->ctx.rx_buf); in ra_spi_transceive_master()
291 } else if (data->dfs > 1) { in ra_spi_transceive_master()
292 UNALIGNED_PUT(rx, (uint16_t *)data->ctx.rx_buf); in ra_spi_transceive_master()
294 UNALIGNED_PUT(rx, (uint8_t *)data->ctx.rx_buf); in ra_spi_transceive_master()
297 spi_context_update_rx(&data->ctx, data->dfs, 1); in ra_spi_transceive_master()
303 static int ra_spi_transceive_data(struct ra_spi_data *data) in ra_spi_transceive_data() argument
306 uint16_t operation = data->ctx.config->operation; in ra_spi_transceive_data()
309 ra_spi_transceive_master(data); in ra_spi_transceive_data()
311 ra_spi_transceive_slave(data); in ra_spi_transceive_data()
322 struct ra_spi_data *data = dev->data; in transceive() local
336 spi_context_lock(&data->ctx, asynchronous, cb, userdata, config); in transceive()
342 data->dfs = ((SPI_WORD_SIZE_GET(config->operation) - 1) / 8) + 1; in transceive()
343 p_spi_reg = data->spi.p_regs; in transceive()
345 (spi_bit_width_t)(SPI_WORD_SIZE_GET(data->ctx.config->operation) - 1); in transceive()
347 spi_context_buffers_setup(&data->ctx, tx_bufs, rx_bufs, data->dfs); in transceive()
349 spi_context_cs_control(&data->ctx, true); in transceive()
352 if (data->ctx.rx_len == 0) { in transceive()
353 data->data_len = spi_context_is_slave(&data->ctx) in transceive()
354 ? spi_context_total_tx_len(&data->ctx) in transceive()
355 : data->ctx.tx_len; in transceive()
356 } else if (data->ctx.tx_len == 0) { in transceive()
357 data->data_len = spi_context_is_slave(&data->ctx) in transceive()
358 ? spi_context_total_rx_len(&data->ctx) in transceive()
359 : data->ctx.rx_len; in transceive()
361 data->data_len = spi_context_is_slave(&data->ctx) in transceive()
362 ? MAX(spi_context_total_tx_len(&data->ctx), in transceive()
363 spi_context_total_rx_len(&data->ctx)) in transceive()
364 : MIN(data->ctx.tx_len, data->ctx.rx_len); in transceive()
367 if (data->ctx.rx_buf == NULL) { in transceive()
368 R_SPI_Write(&data->spi, data->ctx.tx_buf, data->data_len, spi_width); in transceive()
369 } else if (data->ctx.tx_buf == NULL) { in transceive()
370 R_SPI_Read(&data->spi, data->ctx.rx_buf, data->data_len, spi_width); in transceive()
372 R_SPI_WriteRead(&data->spi, data->ctx.tx_buf, data->ctx.rx_buf, data->data_len, in transceive()
376 ret = spi_context_wait_for_completion(&data->ctx); in transceive()
380 if (!spi_context_tx_on(&data->ctx)) { in transceive()
383 if (!spi_context_rx_on(&data->ctx)) { in transceive()
390 /* Configure Word access to data register. */ in transceive()
397 /* Configure Half-Word access to data register. */ in transceive()
401 /* Configure data length based on the selected bit width . */ in transceive()
414 ra_spi_transceive_data(data); in transceive()
415 } while (ra_spi_transfer_ongoing(data)); in transceive()
423 spi_context_cs_control(&data->ctx, false); in transceive()
424 spi_context_complete(&data->ctx, dev, 0); in transceive()
427 if (spi_context_is_slave(&data->ctx) && !ret) { in transceive()
428 ret = data->ctx.recv_frames; in transceive()
433 spi_context_release(&data->ctx, ret); in transceive()
456 struct ra_spi_data *data = dev->data; in ra_spi_release() local
458 spi_context_unlock_unconditionally(&data->ctx); in ra_spi_release()
472 struct ra_spi_data *data = dev->data; in spi_ra_init() local
481 ret = spi_context_cs_configure_all(&data->ctx); in spi_ra_init()
486 spi_context_unlock_unconditionally(&data->ctx); in spi_ra_init()
493 static void ra_spi_retransmit(struct ra_spi_data *data) in ra_spi_retransmit() argument
496 (spi_bit_width_t)(SPI_WORD_SIZE_GET(data->ctx.config->operation) - 1); in ra_spi_retransmit()
498 if (data->ctx.rx_len == 0) { in ra_spi_retransmit()
499 data->data_len = data->ctx.tx_len; in ra_spi_retransmit()
500 data->spi.p_tx_data = data->ctx.tx_buf; in ra_spi_retransmit()
501 data->spi.p_rx_data = NULL; in ra_spi_retransmit()
502 } else if (data->ctx.tx_len == 0) { in ra_spi_retransmit()
503 data->data_len = data->ctx.rx_len; in ra_spi_retransmit()
504 data->spi.p_tx_data = NULL; in ra_spi_retransmit()
505 data->spi.p_rx_data = data->ctx.rx_buf; in ra_spi_retransmit()
507 data->data_len = MIN(data->ctx.tx_len, data->ctx.rx_len); in ra_spi_retransmit()
508 data->spi.p_tx_data = data->ctx.tx_buf; in ra_spi_retransmit()
509 data->spi.p_rx_data = data->ctx.rx_buf; in ra_spi_retransmit()
512 data->spi.bit_width = spi_width; in ra_spi_retransmit()
513 data->spi.rx_count = 0; in ra_spi_retransmit()
514 data->spi.tx_count = 0; in ra_spi_retransmit()
515 data->spi.count = data->data_len; in ra_spi_retransmit()
529 if (data->spi.p_cfg->p_transfer_rx) { in ra_spi_retransmit()
531 data->spi.rx_count = data->data_len; in ra_spi_retransmit()
534 (transfer_instance_t *)data->spi.p_cfg->p_transfer_rx; in ra_spi_retransmit()
539 p_info->length = (uint16_t)data->data_len; in ra_spi_retransmit()
541 p_info->p_dest = data->ctx.rx_buf; in ra_spi_retransmit()
543 if (NULL == data->ctx.rx_buf) { in ra_spi_retransmit()
553 if (data->spi.p_cfg->p_transfer_tx) { in ra_spi_retransmit()
555 data->spi.tx_count = data->data_len; in ra_spi_retransmit()
558 (transfer_instance_t *)data->spi.p_cfg->p_transfer_tx; in ra_spi_retransmit()
563 p_info->length = (uint16_t)data->data_len; in ra_spi_retransmit()
565 p_info->p_src = data->ctx.tx_buf; in ra_spi_retransmit()
567 if (NULL == data->ctx.tx_buf) { in ra_spi_retransmit()
573 R_SPI0_Type *p_spi_reg = data->spi.p_regs; in ra_spi_retransmit()
590 struct ra_spi_data *data = dev->data; in ra_spi_rxi_isr()
594 if (spi_context_is_slave(&data->ctx) && data->spi.rx_count == data->spi.count) { in ra_spi_rxi_isr()
595 if (data->ctx.rx_buf != NULL && data->ctx.tx_buf != NULL) { in ra_spi_rxi_isr()
596 data->ctx.recv_frames = MIN(spi_context_total_tx_len(&data->ctx), in ra_spi_rxi_isr()
597 spi_context_total_rx_len(&data->ctx)); in ra_spi_rxi_isr()
598 } else if (data->ctx.tx_buf == NULL) { in ra_spi_rxi_isr()
599 data->ctx.recv_frames = data->data_len; in ra_spi_rxi_isr()
601 R_BSP_IrqDisable(data->fsp_config.tei_irq); in ra_spi_rxi_isr()
606 R_BSP_IrqDisable(data->fsp_config.txi_irq); in ra_spi_rxi_isr()
609 data->spi.p_regs->SPCR_b.SPE = 0; in ra_spi_rxi_isr()
612 R_BSP_IrqEnable(data->fsp_config.txi_irq); in ra_spi_rxi_isr()
614 spi_context_cs_control(&data->ctx, false); in ra_spi_rxi_isr()
615 spi_context_complete(&data->ctx, dev, 0); in ra_spi_rxi_isr()
629 struct ra_spi_data *data = dev->data; in ra_spi_tei_isr() local
630 R_SPI0_Type *p_spi_reg = data->spi.p_regs; in ra_spi_tei_isr()
632 if (data->spi.rx_count == data->spi.count) { in ra_spi_tei_isr()
633 spi_context_update_rx(&data->ctx, 1, data->data_len); in ra_spi_tei_isr()
635 if (data->spi.tx_count == data->spi.count) { in ra_spi_tei_isr()
636 spi_context_update_tx(&data->ctx, 1, data->data_len); in ra_spi_tei_isr()
639 if (ra_spi_transfer_ongoing(data)) { in ra_spi_tei_isr()
640 R_BSP_IrqDisable(data->spi.p_cfg->txi_irq); in ra_spi_tei_isr()
646 R_BSP_IrqEnable(data->spi.p_cfg->txi_irq); in ra_spi_tei_isr()
653 R_ICU->IELSR_b[data->fsp_config.tei_irq].IR = 0U; in ra_spi_tei_isr()
654 ra_spi_retransmit(data); in ra_spi_tei_isr()