Lines Matching +full:uart +full:- +full:dev
1 /* uart_xlnx_ps.c - Xilinx Zynq family serial driver */
6 * SPDX-License-Identifier: Apache-2.0
16 * Before individual UART port can be used, uart_xlnx_ps_init() has to be
19 * - the following macro for the number of bytes between register addresses:
33 #include <zephyr/drivers/uart.h>
42 * Comp. Xilinx Zynq-7000 Technical Reference Manual (ug585), chap. B.33
45 /* Register offsets within the UART device's register space */
167 * @brief Disables the UART's RX and TX function.
170 * UART's Command Register, thus disabling the operation of the UART.
173 * bits, which are set when enabling the UART, are cleared.
176 * of the UART are modified at run-time.
178 * @param reg_base Base address of the respective UART's register space.
191 * @brief Enables the UART's RX and TX function.
194 * UART's Command Register, thus enabling the operation of the UART.
197 * bits, which are set when disabling the UART, are cleared.
200 * of the UART are being modified at run-time.
202 * @param reg_base Base address of the respective UART's register space.
218 * determine the prescaler applied to the clock driving the UART, based on
222 * registers is described in the Zynq-7000 TRM, chapter 19.2.3 'Baud Rate
225 * @param dev UART device struct
228 static void set_baudrate(const struct device *dev, uint32_t baud_rate) in set_baudrate() argument
230 const struct uart_xlnx_ps_dev_config *dev_cfg = dev->config; in set_baudrate()
231 uint32_t baud = dev_cfg->baud_rate; in set_baudrate()
232 uint32_t clk_freq = dev_cfg->sys_clk_freq; in set_baudrate()
233 uintptr_t reg_base = DEVICE_MMIO_GET(dev); in set_baudrate()
253 bauderr = baud - tmpbaud; in set_baudrate()
255 bauderr = tmpbaud - baud; in set_baudrate()
264 * -> This function is always called from a context in which in set_baudrate()
274 * @brief Initialize individual UART port
278 * @param dev UART device struct
282 static int uart_xlnx_ps_init(const struct device *dev) in uart_xlnx_ps_init() argument
284 const struct uart_xlnx_ps_dev_config *dev_cfg = dev->config; in uart_xlnx_ps_init()
290 DEVICE_MMIO_MAP(dev, K_MEM_CACHE_NONE); in uart_xlnx_ps_init()
291 uintptr_t reg_base = DEVICE_MMIO_GET(dev); in uart_xlnx_ps_init()
297 err = pinctrl_apply_state(dev_cfg->pincfg, PINCTRL_STATE_DEFAULT); in uart_xlnx_ps_init()
318 set_baudrate(dev, dev_cfg->baud_rate); in uart_xlnx_ps_init()
326 dev_cfg->irq_config_func(dev); in uart_xlnx_ps_init()
338 * @param dev UART device struct
341 * @return 0 if a character arrived, -1 if the input buffer if empty.
343 static int uart_xlnx_ps_poll_in(const struct device *dev, unsigned char *c) in uart_xlnx_ps_poll_in() argument
345 uintptr_t reg_base = DEVICE_MMIO_GET(dev); in uart_xlnx_ps_poll_in()
352 return -1; in uart_xlnx_ps_poll_in()
365 * @param dev UART device struct
370 static void uart_xlnx_ps_poll_out(const struct device *dev, unsigned char c) in uart_xlnx_ps_poll_out() argument
372 uintptr_t reg_base = DEVICE_MMIO_GET(dev); in uart_xlnx_ps_poll_out()
391 * framework for the configuration of the UART's parity setting
446 * framework for the configuration of the UART's stop bit setting
496 * framework for the configuration of the UART's data bit setting
547 * framework for the configuration of the UART's flow control
587 * @brief Configures the UART device at run-time.
589 * Configures the UART device at run-time according to the
592 * @param dev UART device struct
598 static int uart_xlnx_ps_configure(const struct device *dev, in uart_xlnx_ps_configure() argument
602 (struct uart_xlnx_ps_dev_config *)dev->config; in uart_xlnx_ps_configure()
604 uintptr_t reg_base = DEVICE_MMIO_GET(dev); in uart_xlnx_ps_configure()
612 /* Mask out all items that might be re-configured */ in uart_xlnx_ps_configure()
619 if ((!uart_xlnx_ps_cfg2ll_parity(&mode_reg, cfg->parity)) || in uart_xlnx_ps_configure()
620 (!uart_xlnx_ps_cfg2ll_stopbits(&mode_reg, cfg->stop_bits)) || in uart_xlnx_ps_configure()
621 (!uart_xlnx_ps_cfg2ll_databits(&mode_reg, cfg->data_bits)) || in uart_xlnx_ps_configure()
622 (!uart_xlnx_ps_cfg2ll_hwctrl(&modemcr_reg, cfg->flow_ctrl))) { in uart_xlnx_ps_configure()
623 return -ENOTSUP; in uart_xlnx_ps_configure()
630 set_baudrate(dev, cfg->baudrate); in uart_xlnx_ps_configure()
631 dev_cfg->baud_rate = cfg->baudrate; in uart_xlnx_ps_configure()
637 /* Re-enable the controller */ in uart_xlnx_ps_configure()
648 * Converts a bit mask representing the UART's parity setting within
649 * the UART's Mode Register into a value of an enumeration type provided
650 * by the UART driver API.
655 * @return The current parity setting mapped to the UART driver API's
664 * 000b : even -> reset value in uart_xlnx_ps_ll2cfg_parity()
690 * Converts a bit mask representing the UART's stop bit setting within
691 * the UART's Mode Register into a value of an enumeration type provided
692 * by the UART driver API.
697 * @return The current stop bit setting mapped to the UART driver API's
706 * 00b : 1 stop bit -> reset value in uart_xlnx_ps_ll2cfg_stopbits()
727 * Converts a bit mask representing the UART's data bit setting within
728 * the UART's Mode Register into a value of an enumeration type provided
729 * by the UART driver API.
734 * @return The current data bit setting mapped to the UART driver API's
743 * 0xb : 8 data bits -> reset value in uart_xlnx_ps_ll2cfg_databits()
763 * Converts a bit mask representing the UART's flow control setting within
764 * the UART's Modem Control Register into a value of an enumeration type
765 * provided by the UART driver API.
770 * @return The current flow control setting mapped to the UART driver API's
779 * 0b : no flow control -> reset value in uart_xlnx_ps_ll2cfg_hwctrl()
793 * @brief Returns the current configuration of the UART at run-time.
795 * Returns the current configuration of the UART at run-time by obtaining
796 * the current configuration from the UART's Mode and Modem Control Registers
799 * @param dev UART device struct
805 static int uart_xlnx_ps_config_get(const struct device *dev, in uart_xlnx_ps_config_get() argument
808 const struct uart_xlnx_ps_dev_config *dev_cfg = dev->config; in uart_xlnx_ps_config_get()
809 uintptr_t reg_base = DEVICE_MMIO_GET(dev); in uart_xlnx_ps_config_get()
812 * Read the Mode & Modem control registers - they contain in uart_xlnx_ps_config_get()
820 cfg->baudrate = dev_cfg->baud_rate; in uart_xlnx_ps_config_get()
821 cfg->parity = uart_xlnx_ps_ll2cfg_parity(mode_reg); in uart_xlnx_ps_config_get()
822 cfg->stop_bits = uart_xlnx_ps_ll2cfg_stopbits(mode_reg); in uart_xlnx_ps_config_get()
823 cfg->data_bits = uart_xlnx_ps_ll2cfg_databits(mode_reg); in uart_xlnx_ps_config_get()
824 cfg->flow_ctrl = uart_xlnx_ps_ll2cfg_hwctrl(modemcr_reg); in uart_xlnx_ps_config_get()
835 * @param dev UART device struct
841 static int uart_xlnx_ps_fifo_fill(const struct device *dev, in uart_xlnx_ps_fifo_fill() argument
845 uintptr_t reg_base = DEVICE_MMIO_GET(dev); in uart_xlnx_ps_fifo_fill()
849 while (size--) { in uart_xlnx_ps_fifo_fill()
862 * @param dev UART device struct
868 static int uart_xlnx_ps_fifo_read(const struct device *dev, uint8_t *rx_data, in uart_xlnx_ps_fifo_read() argument
871 uintptr_t reg_base = DEVICE_MMIO_GET(dev); in uart_xlnx_ps_fifo_read()
888 * @param dev UART device struct
890 static void uart_xlnx_ps_irq_tx_enable(const struct device *dev) in uart_xlnx_ps_irq_tx_enable() argument
892 uintptr_t reg_base = DEVICE_MMIO_GET(dev); in uart_xlnx_ps_irq_tx_enable()
902 * @param dev UART device struct
904 static void uart_xlnx_ps_irq_tx_disable(const struct device *dev) in uart_xlnx_ps_irq_tx_disable() argument
906 uintptr_t reg_base = DEVICE_MMIO_GET(dev); in uart_xlnx_ps_irq_tx_disable()
916 * @param dev UART device struct
920 static int uart_xlnx_ps_irq_tx_ready(const struct device *dev) in uart_xlnx_ps_irq_tx_ready() argument
922 uintptr_t reg_base = DEVICE_MMIO_GET(dev); in uart_xlnx_ps_irq_tx_ready()
935 * @param dev UART device struct
939 static int uart_xlnx_ps_irq_tx_complete(const struct device *dev) in uart_xlnx_ps_irq_tx_complete() argument
941 uintptr_t reg_base = DEVICE_MMIO_GET(dev); in uart_xlnx_ps_irq_tx_complete()
954 * @param dev UART device struct
956 static void uart_xlnx_ps_irq_rx_enable(const struct device *dev) in uart_xlnx_ps_irq_rx_enable() argument
958 uintptr_t reg_base = DEVICE_MMIO_GET(dev); in uart_xlnx_ps_irq_rx_enable()
966 * @param dev UART device struct
968 static void uart_xlnx_ps_irq_rx_disable(const struct device *dev) in uart_xlnx_ps_irq_rx_disable() argument
970 uintptr_t reg_base = DEVICE_MMIO_GET(dev); in uart_xlnx_ps_irq_rx_disable()
978 * @param dev UART device struct
982 static int uart_xlnx_ps_irq_rx_ready(const struct device *dev) in uart_xlnx_ps_irq_rx_ready() argument
984 uintptr_t reg_base = DEVICE_MMIO_GET(dev); in uart_xlnx_ps_irq_rx_ready()
998 * @param dev UART device struct
1000 static void uart_xlnx_ps_irq_err_enable(const struct device *dev) in uart_xlnx_ps_irq_err_enable() argument
1002 uintptr_t reg_base = DEVICE_MMIO_GET(dev); in uart_xlnx_ps_irq_err_enable()
1016 * @param dev UART device struct
1020 static void uart_xlnx_ps_irq_err_disable(const struct device *dev) in uart_xlnx_ps_irq_err_disable() argument
1022 uintptr_t reg_base = DEVICE_MMIO_GET(dev); in uart_xlnx_ps_irq_err_disable()
1036 * @param dev UART device struct
1040 static int uart_xlnx_ps_irq_is_pending(const struct device *dev) in uart_xlnx_ps_irq_is_pending() argument
1042 uintptr_t reg_base = DEVICE_MMIO_GET(dev); in uart_xlnx_ps_irq_is_pending()
1056 * @param dev UART device struct
1060 static int uart_xlnx_ps_irq_update(const struct device *dev) in uart_xlnx_ps_irq_update() argument
1062 ARG_UNUSED(dev); in uart_xlnx_ps_irq_update()
1069 * @param dev UART device struct
1072 static void uart_xlnx_ps_irq_callback_set(const struct device *dev, in uart_xlnx_ps_irq_callback_set() argument
1076 struct uart_xlnx_ps_dev_data_t *dev_data = dev->data; in uart_xlnx_ps_irq_callback_set()
1078 dev_data->user_cb = cb; in uart_xlnx_ps_irq_callback_set()
1079 dev_data->user_data = cb_data; in uart_xlnx_ps_irq_callback_set()
1089 static void uart_xlnx_ps_isr(const struct device *dev) in uart_xlnx_ps_isr() argument
1091 const struct uart_xlnx_ps_dev_data_t *data = dev->data; in uart_xlnx_ps_isr()
1093 if (data->user_cb) { in uart_xlnx_ps_isr()
1094 data->user_cb(dev, data->user_data); in uart_xlnx_ps_isr()
1099 static DEVICE_API(uart, uart_xlnx_ps_driver_api) = {
1130 static void uart_xlnx_ps_irq_config_##port(const struct device *dev) \