Lines Matching +full:spi +full:- +full:clock +full:- +full:mode +full:- +full:cpha
4 * SPDX-License-Identifier: Apache-2.0
16 #include <zephyr/drivers/spi.h>
17 #include <zephyr/drivers/spi/rtio.h>
42 .clock = CLOCK_USART(DT_INST_PROP(n, peripheral_id)),
46 : -1)
50 : -1)
55 : -1)
61 : -1)
68 : -1)
76 : -1)
81 .clock = CLOCK_USART((USART_TypeDef *)DT_INST_REG_ADDR(id)),
99 CMU_Clock_TypeDef clock; member
120 const struct spi_gecko_config *gecko_config = dev->config; in spi_config()
121 struct spi_gecko_data *data = dev->data; in spi_config()
122 mem_addr_t ctrl_reg = (mem_addr_t)&gecko_config->base->CTRL; in spi_config()
128 err = clock_control_get_rate(gecko_config->clock_dev, in spi_config()
129 (clock_control_subsys_t)&gecko_config->clock_cfg, in spi_config()
134 /* Max supported SPI frequency is half the source clock */ in spi_config()
137 spi_frequency = CMU_ClockFreqGet(gecko_config->clock) / 2; in spi_config()
140 if (config->operation & SPI_HALF_DUPLEX) { in spi_config()
141 LOG_ERR("Half-duplex not supported"); in spi_config()
142 return -ENOTSUP; in spi_config()
145 if (SPI_WORD_SIZE_GET(config->operation) != SPI_WORD_SIZE) { in spi_config()
147 return -ENOTSUP; in spi_config()
150 if (config->operation & SPI_CS_ACTIVE_HIGH) { in spi_config()
157 (config->operation & SPI_LINES_MASK) != SPI_LINES_SINGLE) { in spi_config()
158 LOG_ERR("Only supports single mode"); in spi_config()
159 return -ENOTSUP; in spi_config()
162 if (config->operation & SPI_TRANSFER_LSB) { in spi_config()
168 if (config->operation & SPI_OP_MODE_SLAVE) { in spi_config()
169 LOG_ERR("Slave mode not supported"); in spi_config()
170 return -ENOTSUP; in spi_config()
177 if (gecko_config->clock_frequency > spi_frequency) { in spi_config()
178 LOG_ERR("SPI clock-frequency too high"); in spi_config()
179 return -EINVAL; in spi_config()
181 spi_frequency = MIN(gecko_config->clock_frequency, spi_frequency); in spi_config()
182 if (config->frequency) { in spi_config()
183 spi_frequency = MIN(config->frequency, spi_frequency); in spi_config()
185 USART_BaudrateSyncSet(gecko_config->base, 0, spi_frequency); in spi_config()
188 if (config->operation & SPI_MODE_LOOP) { in spi_config()
189 gecko_config->base->CTRL |= USART_CTRL_LOOPBK; in spi_config()
191 gecko_config->base->CTRL &= ~USART_CTRL_LOOPBK; in spi_config()
195 if (config->operation & SPI_MODE_CPOL) { in spi_config()
196 gecko_config->base->CTRL |= USART_CTRL_CLKPOL; in spi_config()
198 gecko_config->base->CTRL &= ~USART_CTRL_CLKPOL; in spi_config()
201 /* Set CPHA */ in spi_config()
202 if (config->operation & SPI_MODE_CPHA) { in spi_config()
203 gecko_config->base->CTRL |= USART_CTRL_CLKPHA; in spi_config()
205 gecko_config->base->CTRL &= ~USART_CTRL_CLKPHA; in spi_config()
209 gecko_config->base->FRAME = usartDatabits8 in spi_config()
214 data->ctx.config = config; in spi_config()
225 while (!(usart->STATUS & USART_STATUS_TXC)) { in spi_gecko_send()
232 return (uint8_t)usart->RXDATA; in spi_gecko_recv()
237 return spi_context_tx_on(&data->ctx) || spi_context_rx_on(&data->ctx); in spi_gecko_transfer_ongoing()
244 if (spi_context_tx_buf_on(&data->ctx)) { in spi_gecko_next_tx()
245 tx_frame = UNALIGNED_GET((uint8_t *)(data->ctx.tx_buf)); in spi_gecko_next_tx()
259 spi_context_update_tx(&data->ctx, 1, 1); in spi_gecko_shift_frames()
263 if (spi_context_rx_buf_on(&data->ctx)) { in spi_gecko_shift_frames()
264 UNALIGNED_PUT(rx_frame, (uint8_t *)data->ctx.rx_buf); in spi_gecko_shift_frames()
266 spi_context_update_rx(&data->ctx, 1, 1); in spi_gecko_shift_frames()
275 struct spi_gecko_data *data = dev->data; in spi_gecko_xfer()
276 struct spi_context *ctx = &data->ctx; in spi_gecko_xfer()
277 const struct spi_gecko_config *gecko_config = dev->config; in spi_gecko_xfer()
282 ret = spi_gecko_shift_frames(gecko_config->base, data); in spi_gecko_xfer()
292 const struct spi_gecko_config *config = dev->config; in spi_gecko_init_pins()
294 GPIO_PinModeSet(config->pin_rx.port, config->pin_rx.pin, in spi_gecko_init_pins()
295 config->pin_rx.mode, config->pin_rx.out); in spi_gecko_init_pins()
296 GPIO_PinModeSet(config->pin_tx.port, config->pin_tx.pin, in spi_gecko_init_pins()
297 config->pin_tx.mode, config->pin_tx.out); in spi_gecko_init_pins()
298 GPIO_PinModeSet(config->pin_clk.port, config->pin_clk.pin, in spi_gecko_init_pins()
299 config->pin_clk.mode, config->pin_clk.out); in spi_gecko_init_pins()
302 config->base->ROUTEPEN = 0; in spi_gecko_init_pins()
304 config->base->ROUTELOC0 = in spi_gecko_init_pins()
305 (config->loc_tx << _USART_ROUTELOC0_TXLOC_SHIFT) | in spi_gecko_init_pins()
306 (config->loc_rx << _USART_ROUTELOC0_RXLOC_SHIFT) | in spi_gecko_init_pins()
307 (config->loc_clk << _USART_ROUTELOC0_CLKLOC_SHIFT); in spi_gecko_init_pins()
309 config->base->ROUTELOC1 = _USART_ROUTELOC1_RESETVALUE; in spi_gecko_init_pins()
311 config->base->ROUTEPEN = USART_ROUTEPEN_RXPEN | USART_ROUTEPEN_TXPEN | in spi_gecko_init_pins()
322 const struct spi_gecko_config *config = dev->config; in spi_gecko_init()
323 struct spi_gecko_data *data = dev->data; in spi_gecko_init()
326 /* The peripheral and gpio clock are already enabled from soc and gpio in spi_gecko_init()
342 /* Enable USART clock */ in spi_gecko_init()
344 err = clock_control_on(config->clock_dev, (clock_control_subsys_t)&config->clock_cfg); in spi_gecko_init()
349 CMU_ClockEnable(config->clock, true); in spi_gecko_init()
353 USART_InitSync(config->base, &usartInit); in spi_gecko_init()
356 err = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT); in spi_gecko_init()
365 err = spi_context_cs_configure_all(&data->ctx); in spi_gecko_init()
371 config->base->CMD = (uint32_t) usartEnable; in spi_gecko_init()
373 spi_context_unlock_unconditionally(&data->ctx); in spi_gecko_init()
383 struct spi_gecko_data *data = dev->data; in spi_gecko_transceive()
387 spi_context_lock(&data->ctx, false, NULL, NULL, config); in spi_gecko_transceive()
391 spi_context_release(&data->ctx, ret); in spi_gecko_transceive()
395 spi_context_buffers_setup(&data->ctx, tx_bufs, rx_bufs, 1); in spi_gecko_transceive()
398 spi_context_release(&data->ctx, ret); in spi_gecko_transceive()
410 return -ENOTSUP; in spi_gecko_transceive_async()
417 struct spi_gecko_data *data = dev->data; in spi_gecko_release()
419 spi_context_unlock_unconditionally(&data->ctx); in spi_gecko_release()
425 static DEVICE_API(spi, spi_gecko_api) = {