Lines Matching full:data

64 	struct ra_spi_data *data = dev->data;  in spi_cb()  local
68 spi_context_cs_control(&data->ctx, false); in spi_cb()
69 spi_context_complete(&data->ctx, dev, 0); in spi_cb()
77 spi_context_cs_control(&data->ctx, false); in spi_cb()
78 spi_context_complete(&data->ctx, dev, -EIO); in spi_cb()
87 struct ra_spi_data *data = dev->data; in ra_spi_b_configure() local
90 if (spi_context_configured(&data->ctx, config)) { in ra_spi_b_configure()
95 if (data->spi.open != 0) { in ra_spi_b_configure()
96 R_SPI_B_Close(&data->spi); in ra_spi_b_configure()
104 data->fsp_config.operating_mode = SPI_MODE_SLAVE; in ra_spi_b_configure()
106 data->fsp_config.operating_mode = SPI_MODE_MASTER; in ra_spi_b_configure()
110 data->fsp_config.clk_polarity = SPI_CLK_POLARITY_HIGH; in ra_spi_b_configure()
112 data->fsp_config.clk_polarity = SPI_CLK_POLARITY_LOW; in ra_spi_b_configure()
116 data->fsp_config.clk_phase = SPI_CLK_PHASE_EDGE_EVEN; in ra_spi_b_configure()
118 data->fsp_config.clk_phase = SPI_CLK_PHASE_EDGE_ODD; in ra_spi_b_configure()
122 data->fsp_config.bit_order = SPI_BIT_ORDER_LSB_FIRST; in ra_spi_b_configure()
124 data->fsp_config.bit_order = SPI_BIT_ORDER_MSB_FIRST; in ra_spi_b_configure()
129 data->fsp_config_extend.clock_source, in ra_spi_b_configure()
130 &data->fsp_config_extend.spck_div); in ra_spi_b_configure()
134 data->fsp_config_extend.spi_comm = SPI_B_COMMUNICATION_FULL_DUPLEX; in ra_spi_b_configure()
136 data->fsp_config_extend.spi_clksyn = SPI_B_SSL_MODE_CLK_SYN; in ra_spi_b_configure()
138 data->fsp_config_extend.spi_clksyn = SPI_B_SSL_MODE_SPI; in ra_spi_b_configure()
139 data->fsp_config_extend.ssl_select = SPI_B_SSL_SELECT_SSL0; in ra_spi_b_configure()
142 data->fsp_config.p_extend = &data->fsp_config_extend; in ra_spi_b_configure()
144 data->fsp_config.p_callback = spi_cb; in ra_spi_b_configure()
145 data->fsp_config.p_context = dev; in ra_spi_b_configure()
146 fsp_err = R_SPI_B_Open(&data->spi, &data->fsp_config); in ra_spi_b_configure()
151 data->ctx.config = config; in ra_spi_b_configure()
156 static bool ra_spi_b_transfer_ongoing(struct ra_spi_data *data) in ra_spi_b_transfer_ongoing() argument
159 return (spi_context_tx_on(&data->ctx) || spi_context_rx_on(&data->ctx)); in ra_spi_b_transfer_ongoing()
161 if (spi_context_total_tx_len(&data->ctx) < spi_context_total_rx_len(&data->ctx)) { in ra_spi_b_transfer_ongoing()
162 return (spi_context_tx_on(&data->ctx) || spi_context_rx_on(&data->ctx)); in ra_spi_b_transfer_ongoing()
164 return (spi_context_tx_on(&data->ctx) && spi_context_rx_on(&data->ctx)); in ra_spi_b_transfer_ongoing()
170 static int ra_spi_b_transceive_slave(struct ra_spi_data *data) in ra_spi_b_transceive_slave() argument
172 R_SPI_B0_Type *p_spi_reg = data->spi.p_regs; in ra_spi_b_transceive_slave()
174 if (p_spi_reg->SPSR_b.SPTEF && spi_context_tx_on(&data->ctx)) { in ra_spi_b_transceive_slave()
177 if (data->ctx.tx_buf != NULL) { in ra_spi_b_transceive_slave()
178 if (data->dfs > 2) { in ra_spi_b_transceive_slave()
179 tx = *(uint32_t *)(data->ctx.tx_buf); in ra_spi_b_transceive_slave()
180 } else if (data->dfs > 1) { in ra_spi_b_transceive_slave()
181 tx = *(uint16_t *)(data->ctx.tx_buf); in ra_spi_b_transceive_slave()
183 tx = *(uint8_t *)(data->ctx.tx_buf); in ra_spi_b_transceive_slave()
193 spi_context_update_tx(&data->ctx, data->dfs, 1); in ra_spi_b_transceive_slave()
198 if (p_spi_reg->SPSR_b.SPRF && spi_context_rx_buf_on(&data->ctx)) { in ra_spi_b_transceive_slave()
204 if (data->dfs > 2) { in ra_spi_b_transceive_slave()
205 UNALIGNED_PUT(rx, (uint32_t *)data->ctx.rx_buf); in ra_spi_b_transceive_slave()
206 } else if (data->dfs > 1) { in ra_spi_b_transceive_slave()
207 UNALIGNED_PUT(rx, (uint16_t *)data->ctx.rx_buf); in ra_spi_b_transceive_slave()
209 UNALIGNED_PUT(rx, (uint8_t *)data->ctx.rx_buf); in ra_spi_b_transceive_slave()
211 spi_context_update_rx(&data->ctx, data->dfs, 1); in ra_spi_b_transceive_slave()
217 static int ra_spi_b_transceive_master(struct ra_spi_data *data) in ra_spi_b_transceive_master() argument
219 R_SPI_B0_Type *p_spi_reg = data->spi.p_regs; in ra_spi_b_transceive_master()
224 if (spi_context_tx_buf_on(&data->ctx)) { in ra_spi_b_transceive_master()
225 if (data->dfs > 2) { in ra_spi_b_transceive_master()
226 tx = *(uint32_t *)(data->ctx.tx_buf); in ra_spi_b_transceive_master()
227 } else if (data->dfs > 1) { in ra_spi_b_transceive_master()
228 tx = *(uint16_t *)(data->ctx.tx_buf); in ra_spi_b_transceive_master()
230 tx = *(uint8_t *)(data->ctx.tx_buf); in ra_spi_b_transceive_master()
243 spi_context_update_tx(&data->ctx, data->dfs, 1); in ra_spi_b_transceive_master()
246 if (spi_context_rx_on(&data->ctx)) { in ra_spi_b_transceive_master()
252 if (data->dfs > 2) { in ra_spi_b_transceive_master()
253 UNALIGNED_PUT(rx, (uint32_t *)data->ctx.rx_buf); in ra_spi_b_transceive_master()
254 } else if (data->dfs > 1) { in ra_spi_b_transceive_master()
255 UNALIGNED_PUT(rx, (uint16_t *)data->ctx.rx_buf); in ra_spi_b_transceive_master()
257 UNALIGNED_PUT(rx, (uint8_t *)data->ctx.rx_buf); in ra_spi_b_transceive_master()
259 spi_context_update_rx(&data->ctx, data->dfs, 1); in ra_spi_b_transceive_master()
265 static int ra_spi_b_transceive_data(struct ra_spi_data *data) in ra_spi_b_transceive_data() argument
267 uint16_t operation = data->ctx.config->operation; in ra_spi_b_transceive_data()
270 ra_spi_b_transceive_master(data); in ra_spi_b_transceive_data()
272 ra_spi_b_transceive_slave(data); in ra_spi_b_transceive_data()
283 struct ra_spi_data *data = dev->data; in transceive() local
297 spi_context_lock(&data->ctx, asynchronous, cb, userdata, config); in transceive()
303 data->dfs = ((SPI_WORD_SIZE_GET(config->operation) - 1) / 8) + 1; in transceive()
304 p_spi_reg = data->spi.p_regs; in transceive()
306 spi_context_buffers_setup(&data->ctx, tx_bufs, rx_bufs, data->dfs); in transceive()
308 spi_context_cs_control(&data->ctx, true); in transceive()
312 (spi_bit_width_t)(SPI_WORD_SIZE_GET(data->ctx.config->operation) - 1); in transceive()
314 if (data->ctx.rx_len == 0) { in transceive()
315 data->data_len = spi_context_is_slave(&data->ctx) in transceive()
316 ? spi_context_total_tx_len(&data->ctx) in transceive()
317 : data->ctx.tx_len; in transceive()
318 } else if (data->ctx.tx_len == 0) { in transceive()
319 data->data_len = spi_context_is_slave(&data->ctx) in transceive()
320 ? spi_context_total_rx_len(&data->ctx) in transceive()
321 : data->ctx.rx_len; in transceive()
323 data->data_len = spi_context_is_slave(&data->ctx) in transceive()
324 ? MAX(spi_context_total_tx_len(&data->ctx), in transceive()
325 spi_context_total_rx_len(&data->ctx)) in transceive()
326 : MIN(data->ctx.tx_len, data->ctx.rx_len); in transceive()
329 if (data->ctx.rx_buf == NULL) { in transceive()
330 R_SPI_B_Write(&data->spi, data->ctx.tx_buf, data->data_len, spi_width); in transceive()
331 } else if (data->ctx.tx_buf == NULL) { in transceive()
332 R_SPI_B_Read(&data->spi, data->ctx.rx_buf, data->data_len, spi_width); in transceive()
334 R_SPI_B_WriteRead(&data->spi, data->ctx.tx_buf, data->ctx.rx_buf, data->data_len, in transceive()
337 ret = spi_context_wait_for_completion(&data->ctx); in transceive()
341 if (!spi_context_tx_on(&data->ctx)) { in transceive()
344 if (!spi_context_rx_on(&data->ctx)) { in transceive()
353 p_spi_reg->SPCMD0 |= (uint32_t)(SPI_WORD_SIZE_GET(data->ctx.config->operation) - 1) in transceive()
356 ra_spi_b_transceive_data(data); in transceive()
357 } while (ra_spi_b_transfer_ongoing(data)); in transceive()
367 if (spi_context_is_slave(&data->ctx) && !ret) { in transceive()
368 ret = data->ctx.recv_frames; in transceive()
373 spi_context_release(&data->ctx, ret); in transceive()
396 struct ra_spi_data *data = dev->data; in ra_spi_b_release() local
398 spi_context_unlock_unconditionally(&data->ctx); in ra_spi_b_release()
424 struct ra_spi_data *data = dev->data; in spi_b_ra_init() local
431 data->fsp_config_extend.clock_source = ra_spi_b_clock_name(config->clock_dev); in spi_b_ra_init()
439 ret = spi_context_cs_configure_all(&data->ctx); in spi_b_ra_init()
444 spi_context_unlock_unconditionally(&data->ctx); in spi_b_ra_init()
451 static void ra_spi_retransmit(struct ra_spi_data *data) in ra_spi_retransmit() argument
454 (spi_bit_width_t)(SPI_WORD_SIZE_GET(data->ctx.config->operation) - 1); in ra_spi_retransmit()
456 if (data->ctx.rx_len == 0) { in ra_spi_retransmit()
457 data->data_len = data->ctx.tx_len; in ra_spi_retransmit()
458 data->spi.p_tx_data = data->ctx.tx_buf; in ra_spi_retransmit()
459 data->spi.p_rx_data = NULL; in ra_spi_retransmit()
460 } else if (data->ctx.tx_len == 0) { in ra_spi_retransmit()
461 data->data_len = data->ctx.rx_len; in ra_spi_retransmit()
462 data->spi.p_tx_data = NULL; in ra_spi_retransmit()
463 data->spi.p_rx_data = data->ctx.rx_buf; in ra_spi_retransmit()
465 data->data_len = MIN(data->ctx.tx_len, data->ctx.rx_len); in ra_spi_retransmit()
466 data->spi.p_tx_data = data->ctx.tx_buf; in ra_spi_retransmit()
467 data->spi.p_rx_data = data->ctx.rx_buf; in ra_spi_retransmit()
470 data->spi.bit_width = spi_width; in ra_spi_retransmit()
471 data->spi.rx_count = 0; in ra_spi_retransmit()
472 data->spi.tx_count = 0; in ra_spi_retransmit()
473 data->spi.count = data->data_len; in ra_spi_retransmit()
486 if (data->spi.p_cfg->p_transfer_rx) { in ra_spi_retransmit()
488 data->spi.rx_count = data->data_len; in ra_spi_retransmit()
491 (transfer_instance_t *)data->spi.p_cfg->p_transfer_rx; in ra_spi_retransmit()
496 p_info->length = (uint16_t)data->data_len; in ra_spi_retransmit()
498 p_info->p_dest = data->ctx.rx_buf; in ra_spi_retransmit()
500 if (NULL == data->ctx.rx_buf) { in ra_spi_retransmit()
510 if (data->spi.p_cfg->p_transfer_tx) { in ra_spi_retransmit()
512 data->spi.tx_count = data->data_len; in ra_spi_retransmit()
515 (transfer_instance_t *)data->spi.p_cfg->p_transfer_tx; in ra_spi_retransmit()
520 p_info->length = (uint16_t)data->data_len; in ra_spi_retransmit()
522 p_info->p_src = data->ctx.tx_buf; in ra_spi_retransmit()
524 if (NULL == data->ctx.tx_buf) { in ra_spi_retransmit()
534 data->spi.p_regs->SPSRC = R_SPI_B0_SPSRC_SPTEFC_Msk; in ra_spi_retransmit()
543 struct ra_spi_data *data = dev->data; in ra_spi_rxi_isr()
546 if (spi_context_is_slave(&data->ctx) && data->spi.rx_count == data->spi.count) { in ra_spi_rxi_isr()
548 if (data->ctx.rx_buf != NULL && data->ctx.tx_buf != NULL) { in ra_spi_rxi_isr()
549 data->ctx.recv_frames = MIN(spi_context_total_tx_len(&data->ctx), in ra_spi_rxi_isr()
550 spi_context_total_rx_len(&data->ctx)); in ra_spi_rxi_isr()
551 } else if (data->ctx.tx_buf == NULL) { in ra_spi_rxi_isr()
552 data->ctx.recv_frames = data->data_len; in ra_spi_rxi_isr()
557 R_BSP_IrqDisable(data->fsp_config.tei_irq); in ra_spi_rxi_isr()
562 R_BSP_IrqDisable(data->fsp_config.txi_irq); in ra_spi_rxi_isr()
565 data->spi.p_regs->SPCR_b.SPE = 0; in ra_spi_rxi_isr()
568 R_BSP_IrqEnable(data->fsp_config.txi_irq); in ra_spi_rxi_isr()
570 spi_context_cs_control(&data->ctx, false); in ra_spi_rxi_isr()
571 spi_context_complete(&data->ctx, dev, 0); in ra_spi_rxi_isr()
584 struct ra_spi_data *data = dev->data; in ra_spi_tei_isr() local
586 if (data->spi.rx_count == data->spi.count) { in ra_spi_tei_isr()
587 spi_context_update_rx(&data->ctx, 1, data->data_len); in ra_spi_tei_isr()
589 if (data->spi.tx_count == data->spi.count) { in ra_spi_tei_isr()
590 spi_context_update_tx(&data->ctx, 1, data->data_len); in ra_spi_tei_isr()
592 if (ra_spi_b_transfer_ongoing(data)) { in ra_spi_tei_isr()
593 R_ICU->IELSR_b[data->fsp_config.tei_irq].IR = 0U; in ra_spi_tei_isr()
594 ra_spi_retransmit(data); in ra_spi_tei_isr()