Lines Matching +full:rs485 +full:- +full:mode

2  * Copyright 2017,2021,2023-2024 NXP
5 * SPDX-License-Identifier: Apache-2.0
133 struct mcux_lpuart_data *data = dev->data; in mcux_lpuart_pm_policy_state_lock_get()
135 if (!data->pm_state_lock_on) { in mcux_lpuart_pm_policy_state_lock_get()
136 data->pm_state_lock_on = true; in mcux_lpuart_pm_policy_state_lock_get()
143 struct mcux_lpuart_data *data = dev->data; in mcux_lpuart_pm_policy_state_lock_put()
145 if (data->pm_state_lock_on) { in mcux_lpuart_pm_policy_state_lock_put()
146 data->pm_state_lock_on = false; in mcux_lpuart_pm_policy_state_lock_put()
154 const struct mcux_lpuart_config *config = dev->config; in mcux_lpuart_poll_in()
155 uint32_t flags = LPUART_GetStatusFlags(config->base); in mcux_lpuart_poll_in()
156 int ret = -1; in mcux_lpuart_poll_in()
159 *c = LPUART_ReadByte(config->base); in mcux_lpuart_poll_in()
168 const struct mcux_lpuart_config *config = dev->config; in mcux_lpuart_poll_out()
171 struct mcux_lpuart_data *data = dev->data; in mcux_lpuart_poll_out()
174 while (!(LPUART_GetStatusFlags(config->base) in mcux_lpuart_poll_out()
181 * We must keep the part from entering lower power mode until the in mcux_lpuart_poll_out()
186 if (!data->tx_poll_stream_on && !data->tx_int_stream_on) { in mcux_lpuart_poll_out()
187 data->tx_poll_stream_on = true; in mcux_lpuart_poll_out()
190 LPUART_EnableInterrupts(config->base, in mcux_lpuart_poll_out()
196 LPUART_WriteByte(config->base, c); in mcux_lpuart_poll_out()
202 const struct mcux_lpuart_config *config = dev->config; in mcux_lpuart_err_check()
203 uint32_t flags = LPUART_GetStatusFlags(config->base); in mcux_lpuart_err_check()
222 LPUART_ClearStatusFlags(config->base, kLPUART_RxOverrunFlag | in mcux_lpuart_err_check()
235 const struct mcux_lpuart_config *config = dev->config; in mcux_lpuart_fifo_fill()
238 while ((len - num_tx > 0) && in mcux_lpuart_fifo_fill()
239 (LPUART_GetStatusFlags(config->base) in mcux_lpuart_fifo_fill()
242 LPUART_WriteByte(config->base, tx_data[num_tx++]); in mcux_lpuart_fifo_fill()
250 const struct mcux_lpuart_config *config = dev->config; in mcux_lpuart_fifo_read()
253 while ((len - num_rx > 0) && in mcux_lpuart_fifo_read()
254 (LPUART_GetStatusFlags(config->base) in mcux_lpuart_fifo_read()
257 rx_data[num_rx++] = LPUART_ReadByte(config->base); in mcux_lpuart_fifo_read()
265 const struct mcux_lpuart_config *config = dev->config; in mcux_lpuart_irq_tx_enable()
268 struct mcux_lpuart_data *data = dev->data; in mcux_lpuart_irq_tx_enable()
274 data->tx_poll_stream_on = false; in mcux_lpuart_irq_tx_enable()
275 data->tx_int_stream_on = true; in mcux_lpuart_irq_tx_enable()
277 LPUART_DisableInterrupts(config->base, in mcux_lpuart_irq_tx_enable()
282 LPUART_EnableInterrupts(config->base, mask); in mcux_lpuart_irq_tx_enable()
290 const struct mcux_lpuart_config *config = dev->config; in mcux_lpuart_irq_tx_disable()
293 struct mcux_lpuart_data *data = dev->data; in mcux_lpuart_irq_tx_disable()
299 LPUART_DisableInterrupts(config->base, mask); in mcux_lpuart_irq_tx_disable()
301 data->tx_int_stream_on = false; in mcux_lpuart_irq_tx_disable()
313 const struct mcux_lpuart_config *config = dev->config; in mcux_lpuart_irq_tx_complete()
314 uint32_t flags = LPUART_GetStatusFlags(config->base); in mcux_lpuart_irq_tx_complete()
321 const struct mcux_lpuart_config *config = dev->config; in mcux_lpuart_irq_tx_ready()
323 uint32_t flags = LPUART_GetStatusFlags(config->base); in mcux_lpuart_irq_tx_ready()
325 return (LPUART_GetEnabledInterrupts(config->base) & mask) in mcux_lpuart_irq_tx_ready()
331 const struct mcux_lpuart_config *config = dev->config; in mcux_lpuart_irq_rx_enable()
334 LPUART_EnableInterrupts(config->base, mask); in mcux_lpuart_irq_rx_enable()
339 const struct mcux_lpuart_config *config = dev->config; in mcux_lpuart_irq_rx_disable()
342 LPUART_DisableInterrupts(config->base, mask); in mcux_lpuart_irq_rx_disable()
347 const struct mcux_lpuart_config *config = dev->config; in mcux_lpuart_irq_rx_full()
348 uint32_t flags = LPUART_GetStatusFlags(config->base); in mcux_lpuart_irq_rx_full()
355 const struct mcux_lpuart_config *config = dev->config; in mcux_lpuart_irq_rx_pending()
358 return (LPUART_GetEnabledInterrupts(config->base) & mask) in mcux_lpuart_irq_rx_pending()
364 const struct mcux_lpuart_config *config = dev->config; in mcux_lpuart_irq_err_enable()
369 LPUART_EnableInterrupts(config->base, mask); in mcux_lpuart_irq_err_enable()
374 const struct mcux_lpuart_config *config = dev->config; in mcux_lpuart_irq_err_disable()
379 LPUART_DisableInterrupts(config->base, mask); in mcux_lpuart_irq_err_disable()
397 struct mcux_lpuart_data *data = dev->data; in mcux_lpuart_irq_callback_set()
400 if (data->api_type == LPUART_ASYNC) { in mcux_lpuart_irq_callback_set()
405 data->callback = cb; in mcux_lpuart_irq_callback_set()
406 data->cb_data = cb_data; in mcux_lpuart_irq_callback_set()
409 data->async.user_callback = NULL; in mcux_lpuart_irq_callback_set()
410 data->async.user_data = NULL; in mcux_lpuart_irq_callback_set()
411 data->api_type = LPUART_IRQ_DRIVEN; in mcux_lpuart_irq_callback_set()
429 const struct mcux_lpuart_data *data = dev->data; in async_user_callback()
431 if (data->async.user_callback) { in async_user_callback()
432 data->async.user_callback(dev, evt, data->async.user_data); in async_user_callback()
438 struct mcux_lpuart_data *data = dev->data; in async_evt_tx_done()
440 (void)k_work_cancel_delayable(&data->async.tx_dma_params.timeout_work); in async_evt_tx_done()
442 LOG_DBG("TX done: %d", data->async.tx_dma_params.buf_len); in async_evt_tx_done()
445 .data.tx.buf = data->async.tx_dma_params.buf, in async_evt_tx_done()
446 .data.tx.len = data->async.tx_dma_params.buf_len in async_evt_tx_done()
450 data->async.tx_dma_params.buf = NULL; in async_evt_tx_done()
451 data->async.tx_dma_params.buf_len = 0U; in async_evt_tx_done()
458 struct mcux_lpuart_data *data = dev->data; in async_evt_rx_rdy()
459 struct mcux_lpuart_rx_dma_params *dma_params = &data->async.rx_dma_params; in async_evt_rx_rdy()
463 .data.rx.buf = dma_params->buf, in async_evt_rx_rdy()
464 .data.rx.len = dma_params->counter - dma_params->offset, in async_evt_rx_rdy()
465 .data.rx.offset = dma_params->offset in async_evt_rx_rdy()
472 dma_params->offset = dma_params->counter; in async_evt_rx_rdy()
491 struct mcux_lpuart_data *data = (struct mcux_lpuart_data *)dev->data; in async_evt_rx_buf_release()
494 .data.rx_buf.buf = data->async.rx_dma_params.buf, in async_evt_rx_buf_release()
498 data->async.rx_dma_params.buf = NULL; in async_evt_rx_buf_release()
499 data->async.rx_dma_params.buf_len = 0U; in async_evt_rx_buf_release()
500 data->async.rx_dma_params.offset = 0U; in async_evt_rx_buf_release()
501 data->async.rx_dma_params.counter = 0U; in async_evt_rx_buf_release()
507 struct mcux_lpuart_data *data = dev->data; in mcux_lpuart_async_rx_flush()
508 const struct mcux_lpuart_config *config = dev->config; in mcux_lpuart_async_rx_flush()
510 const int get_status_result = dma_get_status(config->rx_dma_config.dma_dev, in mcux_lpuart_async_rx_flush()
511 config->rx_dma_config.dma_channel, in mcux_lpuart_async_rx_flush()
515 const size_t rx_rcv_len = data->async.rx_dma_params.buf_len - in mcux_lpuart_async_rx_flush()
518 if (rx_rcv_len > data->async.rx_dma_params.counter && status.pending_length) { in mcux_lpuart_async_rx_flush()
519 data->async.rx_dma_params.counter = rx_rcv_len; in mcux_lpuart_async_rx_flush()
522 LPUART_ClearStatusFlags(config->base, kLPUART_RxOverrunFlag); in mcux_lpuart_async_rx_flush()
531 const struct mcux_lpuart_config *config = dev->config; in mcux_lpuart_rx_disable()
532 struct mcux_lpuart_data *data = (struct mcux_lpuart_data *)dev->data; in mcux_lpuart_rx_disable()
533 LPUART_Type *lpuart = config->base; in mcux_lpuart_rx_disable()
537 (void)k_work_cancel_delayable(&data->async.rx_dma_params.timeout_work); in mcux_lpuart_rx_disable()
543 if (!data->async.rx_dma_params.buf) { in mcux_lpuart_rx_disable()
548 if (data->async.next_rx_buffer != NULL) { in mcux_lpuart_rx_disable()
549 data->async.rx_dma_params.buf = data->async.next_rx_buffer; in mcux_lpuart_rx_disable()
550 data->async.rx_dma_params.buf_len = data->async.next_rx_buffer_len; in mcux_lpuart_rx_disable()
551 data->async.next_rx_buffer = NULL; in mcux_lpuart_rx_disable()
552 data->async.next_rx_buffer_len = 0; in mcux_lpuart_rx_disable()
557 const int ret = dma_stop(config->rx_dma_config.dma_dev, in mcux_lpuart_rx_disable()
558 config->rx_dma_config.dma_channel); in mcux_lpuart_rx_disable()
575 struct mcux_lpuart_data *data = (struct mcux_lpuart_data *)dev->data; in prepare_rx_dma_block_config()
576 const struct mcux_lpuart_config *config = dev->config; in prepare_rx_dma_block_config()
577 LPUART_Type *lpuart = config->base; in prepare_rx_dma_block_config()
578 struct mcux_lpuart_rx_dma_params *rx_dma_params = &data->async.rx_dma_params; in prepare_rx_dma_block_config()
580 assert(rx_dma_params->buf != NULL); in prepare_rx_dma_block_config()
581 assert(rx_dma_params->buf_len > 0); in prepare_rx_dma_block_config()
583 struct dma_block_config *head_block_config = &rx_dma_params->active_dma_block; in prepare_rx_dma_block_config()
585 head_block_config->dest_address = (uint32_t)rx_dma_params->buf; in prepare_rx_dma_block_config()
586 head_block_config->source_address = LPUART_GetDataRegisterAddress(lpuart); in prepare_rx_dma_block_config()
587 head_block_config->block_size = rx_dma_params->buf_len; in prepare_rx_dma_block_config()
588 head_block_config->dest_scatter_en = true; in prepare_rx_dma_block_config()
596 int ret = dma_config(config->rx_dma_config.dma_dev, in configure_and_start_rx_dma()
597 config->rx_dma_config.dma_channel, in configure_and_start_rx_dma()
598 (struct dma_config *)&config->rx_dma_config.dma_cfg); in configure_and_start_rx_dma()
604 ret = dma_start(config->rx_dma_config.dma_dev, config->rx_dma_config.dma_channel); in configure_and_start_rx_dma()
607 config->rx_dma_config.dma_channel, in configure_and_start_rx_dma()
616 struct mcux_lpuart_data *data = (struct mcux_lpuart_data *)dev->data; in uart_mcux_lpuart_dma_replace_rx_buffer()
617 const struct mcux_lpuart_config *config = dev->config; in uart_mcux_lpuart_dma_replace_rx_buffer()
618 LPUART_Type *lpuart = config->base; in uart_mcux_lpuart_dma_replace_rx_buffer()
620 LOG_DBG("Replacing RX buffer, new length: %d", data->async.next_rx_buffer_len); in uart_mcux_lpuart_dma_replace_rx_buffer()
622 assert(data->async.next_rx_buffer != NULL); in uart_mcux_lpuart_dma_replace_rx_buffer()
623 assert(data->async.next_rx_buffer_len != 0U); in uart_mcux_lpuart_dma_replace_rx_buffer()
626 dma_reload(config->rx_dma_config.dma_dev, config->rx_dma_config.dma_channel, in uart_mcux_lpuart_dma_replace_rx_buffer()
628 (uint32_t)data->async.next_rx_buffer, data->async.next_rx_buffer_len); in uart_mcux_lpuart_dma_replace_rx_buffer()
641 const struct mcux_lpuart_config *config = dev->config; in dma_callback()
642 LPUART_Type *lpuart = config->base; in dma_callback()
643 struct mcux_lpuart_data *data = (struct mcux_lpuart_data *)dev->data; in dma_callback()
661 if (channel == config->tx_dma_config.dma_channel) { in dma_callback()
665 } else if (channel == config->rx_dma_config.dma_channel) { in dma_callback()
667 struct mcux_lpuart_rx_dma_params *rx_dma_params = &data->async.rx_dma_params; in dma_callback()
670 rx_dma_params->counter = rx_dma_params->buf_len; in dma_callback()
673 (uint32_t)rx_dma_params->buf, in dma_callback()
674 (uint32_t)data->async.next_rx_buffer); in dma_callback()
679 rx_dma_params->buf = data->async.next_rx_buffer; in dma_callback()
680 rx_dma_params->buf_len = data->async.next_rx_buffer_len; in dma_callback()
681 data->async.next_rx_buffer = NULL; in dma_callback()
682 data->async.next_rx_buffer_len = 0U; in dma_callback()
685 if (rx_dma_params->buf != NULL && rx_dma_params->buf_len > 0) { in dma_callback()
703 struct mcux_lpuart_data *data = dev->data; in mcux_lpuart_callback_set()
706 if (data->api_type == LPUART_IRQ_DRIVEN) { in mcux_lpuart_callback_set()
708 return -ENOTSUP; in mcux_lpuart_callback_set()
712 data->async.user_callback = callback; in mcux_lpuart_callback_set()
713 data->async.user_data = user_data; in mcux_lpuart_callback_set()
716 data->callback = NULL; in mcux_lpuart_callback_set()
717 data->cb_data = NULL; in mcux_lpuart_callback_set()
718 data->api_type = LPUART_ASYNC; in mcux_lpuart_callback_set()
727 struct mcux_lpuart_data *data = dev->data; in mcux_lpuart_tx()
728 const struct mcux_lpuart_config *config = dev->config; in mcux_lpuart_tx()
729 LPUART_Type *lpuart = config->base; in mcux_lpuart_tx()
735 const int get_status_result = dma_get_status(config->tx_dma_config.dma_dev, in mcux_lpuart_tx()
736 config->tx_dma_config.dma_channel, in mcux_lpuart_tx()
742 return get_status_result < 0 ? get_status_result : -EBUSY; in mcux_lpuart_tx()
749 data->async.tx_dma_params.buf = buf; in mcux_lpuart_tx()
750 data->async.tx_dma_params.buf_len = len; in mcux_lpuart_tx()
751 data->async.tx_dma_params.active_dma_block.source_address = (uint32_t)buf; in mcux_lpuart_tx()
752 data->async.tx_dma_params.active_dma_block.dest_address = in mcux_lpuart_tx()
754 data->async.tx_dma_params.active_dma_block.block_size = len; in mcux_lpuart_tx()
755 data->async.tx_dma_params.active_dma_block.next_block = NULL; in mcux_lpuart_tx()
757 ret = dma_config(config->tx_dma_config.dma_dev, in mcux_lpuart_tx()
758 config->tx_dma_config.dma_channel, in mcux_lpuart_tx()
759 (struct dma_config *)&config->tx_dma_config.dma_cfg); in mcux_lpuart_tx()
762 LOG_DBG("Starting UART DMA TX Ch %u", config->tx_dma_config.dma_channel); in mcux_lpuart_tx()
764 ret = dma_start(config->tx_dma_config.dma_dev, in mcux_lpuart_tx()
765 config->tx_dma_config.dma_channel); in mcux_lpuart_tx()
769 config->tx_dma_config.dma_channel); in mcux_lpuart_tx()
771 async_timer_start(&data->async.tx_dma_params.timeout_work, timeout_us); in mcux_lpuart_tx()
781 struct mcux_lpuart_data *data = dev->data; in mcux_lpuart_tx_abort()
782 const struct mcux_lpuart_config *config = dev->config; in mcux_lpuart_tx_abort()
783 LPUART_Type *lpuart = config->base; in mcux_lpuart_tx_abort()
786 (void)k_work_cancel_delayable(&data->async.tx_dma_params.timeout_work); in mcux_lpuart_tx_abort()
788 const int get_status_result = dma_get_status(config->tx_dma_config.dma_dev, in mcux_lpuart_tx_abort()
789 config->tx_dma_config.dma_channel, in mcux_lpuart_tx_abort()
797 data->async.tx_dma_params.buf_len - status.pending_length : 0; in mcux_lpuart_tx_abort()
799 const int ret = dma_stop(config->tx_dma_config.dma_dev, config->tx_dma_config.dma_channel); in mcux_lpuart_tx_abort()
804 .data.tx.buf = data->async.tx_dma_params.buf, in mcux_lpuart_tx_abort()
816 struct mcux_lpuart_data *data = dev->data; in mcux_lpuart_rx_enable()
817 const struct mcux_lpuart_config *config = dev->config; in mcux_lpuart_rx_enable()
818 LPUART_Type *lpuart = config->base; in mcux_lpuart_rx_enable()
820 struct mcux_lpuart_rx_dma_params *rx_dma_params = &data->async.rx_dma_params; in mcux_lpuart_rx_enable()
824 const int get_status_result = dma_get_status(config->rx_dma_config.dma_dev, in mcux_lpuart_rx_enable()
825 config->rx_dma_config.dma_channel, in mcux_lpuart_rx_enable()
831 return get_status_result < 0 ? get_status_result : -EBUSY; in mcux_lpuart_rx_enable()
834 rx_dma_params->timeout_us = timeout_us; in mcux_lpuart_rx_enable()
835 rx_dma_params->buf = buf; in mcux_lpuart_rx_enable()
836 rx_dma_params->buf_len = len; in mcux_lpuart_rx_enable()
837 data->async.next_rx_buffer = NULL; in mcux_lpuart_rx_enable()
838 data->async.next_rx_buffer_len = 0U; in mcux_lpuart_rx_enable()
840 LPUART_EnableInterrupts(config->base, kLPUART_IdleLineInterruptEnable); in mcux_lpuart_rx_enable()
848 LPUART_ClearStatusFlags(config->base, kLPUART_RxOverrunFlag | kLPUART_ParityErrorFlag | in mcux_lpuart_rx_enable()
858 struct mcux_lpuart_data *data = dev->data; in mcux_lpuart_rx_buf_rsp()
862 assert(data->async.next_rx_buffer == NULL); in mcux_lpuart_rx_buf_rsp()
863 assert(data->async.next_rx_buffer_len == 0); in mcux_lpuart_rx_buf_rsp()
864 data->async.next_rx_buffer = buf; in mcux_lpuart_rx_buf_rsp()
865 data->async.next_rx_buffer_len = len; in mcux_lpuart_rx_buf_rsp()
880 const struct device *dev = async_data->uart_dev; in mcux_lpuart_async_rx_timeout()
895 const struct device *dev = async_data->uart_dev; in mcux_lpuart_async_tx_timeout()
910 if (data->callback) { in mcux_lpuart_irq_driven_isr()
911 data->callback(dev, data->cb_data); in mcux_lpuart_irq_driven_isr()
915 LPUART_ClearStatusFlags(config->base, kLPUART_RxOverrunFlag); in mcux_lpuart_irq_driven_isr()
925 async_timer_start(&data->async.rx_dma_params.timeout_work, in mcux_lpuart_async_isr()
926 data->async.rx_dma_params.timeout_us); in mcux_lpuart_async_isr()
927 LPUART_ClearStatusFlags(config->base, kLPUART_IdleLineFlag); in mcux_lpuart_async_isr()
931 LPUART_ClearStatusFlags(config->base, kLPUART_RxOverrunFlag); in mcux_lpuart_async_isr()
938 struct mcux_lpuart_data *data = dev->data; in mcux_lpuart_isr()
939 const struct mcux_lpuart_config *config = dev->config; in mcux_lpuart_isr()
940 const uint32_t status = LPUART_GetStatusFlags(config->base); in mcux_lpuart_isr()
945 if (data->tx_poll_stream_on) { in mcux_lpuart_isr()
947 LPUART_DisableInterrupts(config->base, in mcux_lpuart_isr()
949 data->tx_poll_stream_on = false; in mcux_lpuart_isr()
956 if (data->api_type == LPUART_IRQ_DRIVEN) { in mcux_lpuart_isr()
958 } else if (data->api_type == LPUART_ASYNC) { in mcux_lpuart_isr()
973 switch (cfg->parity) { in mcux_lpuart_configure_basic()
975 uart_config->parityMode = kLPUART_ParityDisabled; in mcux_lpuart_configure_basic()
978 uart_config->parityMode = kLPUART_ParityOdd; in mcux_lpuart_configure_basic()
981 uart_config->parityMode = kLPUART_ParityEven; in mcux_lpuart_configure_basic()
984 return -ENOTSUP; in mcux_lpuart_configure_basic()
987 switch (cfg->data_bits) { in mcux_lpuart_configure_basic()
991 uart_config->dataBitsCount = kLPUART_SevenDataBits; in mcux_lpuart_configure_basic()
995 uart_config->dataBitsCount = kLPUART_EightDataBits; in mcux_lpuart_configure_basic()
998 return -ENOTSUP; in mcux_lpuart_configure_basic()
1003 switch (cfg->stop_bits) { in mcux_lpuart_configure_basic()
1005 uart_config->stopBitCount = kLPUART_OneStopBit; in mcux_lpuart_configure_basic()
1008 uart_config->stopBitCount = kLPUART_TwoStopBit; in mcux_lpuart_configure_basic()
1011 return -ENOTSUP; in mcux_lpuart_configure_basic()
1017 switch (cfg->flow_ctrl) { in mcux_lpuart_configure_basic()
1020 uart_config->enableTxCTS = false; in mcux_lpuart_configure_basic()
1021 uart_config->enableRxRTS = false; in mcux_lpuart_configure_basic()
1024 uart_config->enableTxCTS = true; in mcux_lpuart_configure_basic()
1025 uart_config->enableRxRTS = true; in mcux_lpuart_configure_basic()
1028 return -ENOTSUP; in mcux_lpuart_configure_basic()
1032 uart_config->baudRate_Bps = cfg->baudrate; in mcux_lpuart_configure_basic()
1033 uart_config->enableRx = true; in mcux_lpuart_configure_basic()
1034 /* Tx will be enabled manually after set tx-rts */ in mcux_lpuart_configure_basic()
1035 uart_config->enableTx = false; in mcux_lpuart_configure_basic()
1043 const struct mcux_lpuart_config *config = dev->config; in mcux_lpuart_configure_async()
1044 struct mcux_lpuart_data *data = dev->data; in mcux_lpuart_configure_async()
1050 ret = mcux_lpuart_configure_basic(dev, &data->uart_config, &uart_config); in mcux_lpuart_configure_async()
1057 data->async.next_rx_buffer = NULL; in mcux_lpuart_configure_async()
1058 data->async.next_rx_buffer_len = 0; in mcux_lpuart_configure_async()
1059 data->async.uart_dev = dev; in mcux_lpuart_configure_async()
1060 k_work_init_delayable(&data->async.rx_dma_params.timeout_work, in mcux_lpuart_configure_async()
1062 k_work_init_delayable(&data->async.tx_dma_params.timeout_work, in mcux_lpuart_configure_async()
1070 while (LPUART_GetRxFifoCount(config->base) > 0) { in mcux_lpuart_configure_async()
1071 LPUART_ReadByte(config->base); in mcux_lpuart_configure_async()
1080 const struct mcux_lpuart_config *config = dev->config; in mcux_lpuart_configure_init()
1081 struct mcux_lpuart_data *data = dev->data; in mcux_lpuart_configure_init()
1086 if (!device_is_ready(config->clock_dev)) { in mcux_lpuart_configure_init()
1087 return -ENODEV; in mcux_lpuart_configure_init()
1090 if (clock_control_get_rate(config->clock_dev, config->clock_subsys, in mcux_lpuart_configure_init()
1092 return -EINVAL; in mcux_lpuart_configure_init()
1102 LPUART_Init(config->base, &uart_config, clock_freq); in mcux_lpuart_configure_init()
1106 if (cfg->flow_ctrl == UART_CFG_FLOW_CTRL_RS485) { in mcux_lpuart_configure_init()
1107 /* Set the LPUART into RS485 mode (tx driver enable using RTS) */ in mcux_lpuart_configure_init()
1108 config->base->MODIR |= LPUART_MODIR_TXRTSE(true); in mcux_lpuart_configure_init()
1109 if (!config->rs485_de_active_low) { in mcux_lpuart_configure_init()
1110 config->base->MODIR |= LPUART_MODIR_TXRTSPOL(1); in mcux_lpuart_configure_init()
1116 config->base->CTRL |= LPUART_CTRL_TE(true); in mcux_lpuart_configure_init()
1119 if (config->loopback_en) { in mcux_lpuart_configure_init()
1120 /* Set the LPUART into loopback mode */ in mcux_lpuart_configure_init()
1121 config->base->CTRL |= LPUART_CTRL_LOOPS_MASK; in mcux_lpuart_configure_init()
1122 config->base->CTRL &= ~LPUART_CTRL_RSRC_MASK; in mcux_lpuart_configure_init()
1123 } else if (config->single_wire) { in mcux_lpuart_configure_init()
1124 /* Enable the single wire / half-duplex mode, only possible when in mcux_lpuart_configure_init()
1126 * the UART firing an interrupt during mode switch in mcux_lpuart_configure_init()
1130 config->base->CTRL |= (LPUART_CTRL_LOOPS_MASK | LPUART_CTRL_RSRC_MASK); in mcux_lpuart_configure_init()
1134 /* Only invert TX in full-duplex mode */ in mcux_lpuart_configure_init()
1135 if (config->tx_invert) { in mcux_lpuart_configure_init()
1136 config->base->CTRL |= LPUART_CTRL_TXINV(1); in mcux_lpuart_configure_init()
1142 if (config->rx_invert) { in mcux_lpuart_configure_init()
1143 config->base->STAT |= LPUART_STAT_RXINV(1); in mcux_lpuart_configure_init()
1148 data->uart_config = *cfg; in mcux_lpuart_configure_init()
1156 struct mcux_lpuart_data *data = dev->data; in mcux_lpuart_config_get()
1157 *cfg = data->uart_config; in mcux_lpuart_config_get()
1164 const struct mcux_lpuart_config *config = dev->config; in mcux_lpuart_configure()
1166 /* Make sure that RSRC is de-asserted otherwise deinit will hang. */ in mcux_lpuart_configure()
1167 config->base->CTRL &= ~LPUART_CTRL_RSRC_MASK; in mcux_lpuart_configure()
1170 LPUART_Deinit(config->base); in mcux_lpuart_configure()
1186 const struct mcux_lpuart_config *config = dev->config; in mcux_lpuart_init()
1187 struct mcux_lpuart_data *data = dev->data; in mcux_lpuart_init()
1188 struct uart_config *uart_api_config = &data->uart_config; in mcux_lpuart_init()
1191 uart_api_config->baudrate = config->baud_rate; in mcux_lpuart_init()
1192 uart_api_config->parity = config->parity; in mcux_lpuart_init()
1193 uart_api_config->stop_bits = UART_CFG_STOP_BITS_1; in mcux_lpuart_init()
1194 uart_api_config->data_bits = UART_CFG_DATA_BITS_8; in mcux_lpuart_init()
1195 uart_api_config->flow_ctrl = config->flow_ctrl; in mcux_lpuart_init()
1199 if (config->flow_ctrl) { in mcux_lpuart_init()
1202 err = pinctrl_lookup_state(config->pincfg, PINCTRL_STATE_FLOWCONTROL, &state); in mcux_lpuart_init()
1204 err = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT); in mcux_lpuart_init()
1207 err = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT); in mcux_lpuart_init()
1218 nxp_lp_flexcomm_setirqhandler(config->parent_dev, dev, in mcux_lpuart_init()
1222 config->irq_config_func(dev); in mcux_lpuart_init()
1225 data->api_type = LPUART_NONE; in mcux_lpuart_init()
1230 data->pm_state_lock_on = false; in mcux_lpuart_init()
1231 data->tx_poll_stream_on = false; in mcux_lpuart_init()
1232 data->tx_int_stream_on = false; in mcux_lpuart_init()