Lines Matching +full:uart +full:- +full:dev
2 * Copyright (c) 2017 Jean-Paul Etienne <fractalclone@gmail.com>
4 * SPDX-License-Identifier: Apache-2.0
8 * @brief UART driver for the SiFive Freedom Processor
15 #include <zephyr/drivers/uart.h>
71 #define DEV_UART(dev) \ argument
73 ((const struct uart_sifive_device_config * const)(dev)->config)->port)
80 * @param dev UART device struct
83 static void uart_sifive_poll_out(const struct device *dev, in uart_sifive_poll_out() argument
86 volatile struct uart_sifive_regs_t *uart = DEV_UART(dev); in uart_sifive_poll_out() local
89 while (uart->tx & TXDATA_FULL) { in uart_sifive_poll_out()
92 uart->tx = (int)c; in uart_sifive_poll_out()
98 * @param dev UART device struct
101 * @return 0 if a character arrived, -1 if the input buffer if empty.
103 static int uart_sifive_poll_in(const struct device *dev, unsigned char *c) in uart_sifive_poll_in() argument
105 volatile struct uart_sifive_regs_t *uart = DEV_UART(dev); in uart_sifive_poll_in() local
106 uint32_t val = uart->rx; in uart_sifive_poll_in()
109 return -1; in uart_sifive_poll_in()
122 * @param dev UART device struct
128 static int uart_sifive_fifo_fill(const struct device *dev, in uart_sifive_fifo_fill() argument
132 volatile struct uart_sifive_regs_t *uart = DEV_UART(dev); in uart_sifive_fifo_fill() local
135 for (i = 0; i < size && !(uart->tx & TXDATA_FULL); i++) { in uart_sifive_fifo_fill()
136 uart->tx = (int)tx_data[i]; in uart_sifive_fifo_fill()
145 * @param dev UART device struct
151 static int uart_sifive_fifo_read(const struct device *dev, in uart_sifive_fifo_read() argument
155 volatile struct uart_sifive_regs_t *uart = DEV_UART(dev); in uart_sifive_fifo_read() local
160 val = uart->rx; in uart_sifive_fifo_read()
175 * @param dev UART device struct
177 static void uart_sifive_irq_tx_enable(const struct device *dev) in uart_sifive_irq_tx_enable() argument
179 volatile struct uart_sifive_regs_t *uart = DEV_UART(dev); in uart_sifive_irq_tx_enable() local
181 uart->ie |= IE_TXWM; in uart_sifive_irq_tx_enable()
187 * @param dev UART device struct
189 static void uart_sifive_irq_tx_disable(const struct device *dev) in uart_sifive_irq_tx_disable() argument
191 volatile struct uart_sifive_regs_t *uart = DEV_UART(dev); in uart_sifive_irq_tx_disable() local
193 uart->ie &= ~IE_TXWM; in uart_sifive_irq_tx_disable()
199 * @param dev UART device struct
203 static int uart_sifive_irq_tx_ready(const struct device *dev) in uart_sifive_irq_tx_ready() argument
205 volatile struct uart_sifive_regs_t *uart = DEV_UART(dev); in uart_sifive_irq_tx_ready() local
207 return !!(uart->ip & IE_TXWM); in uart_sifive_irq_tx_ready()
213 * @param dev UART device struct
217 static int uart_sifive_irq_tx_complete(const struct device *dev) in uart_sifive_irq_tx_complete() argument
219 volatile struct uart_sifive_regs_t *uart = DEV_UART(dev); in uart_sifive_irq_tx_complete() local
225 return !(uart->tx & TXDATA_FULL); in uart_sifive_irq_tx_complete()
231 * @param dev UART device struct
233 static void uart_sifive_irq_rx_enable(const struct device *dev) in uart_sifive_irq_rx_enable() argument
235 volatile struct uart_sifive_regs_t *uart = DEV_UART(dev); in uart_sifive_irq_rx_enable() local
237 uart->ie |= IE_RXWM; in uart_sifive_irq_rx_enable()
243 * @param dev UART device struct
245 static void uart_sifive_irq_rx_disable(const struct device *dev) in uart_sifive_irq_rx_disable() argument
247 volatile struct uart_sifive_regs_t *uart = DEV_UART(dev); in uart_sifive_irq_rx_disable() local
249 uart->ie &= ~IE_RXWM; in uart_sifive_irq_rx_disable()
255 * @param dev UART device struct
259 static int uart_sifive_irq_rx_ready(const struct device *dev) in uart_sifive_irq_rx_ready() argument
261 volatile struct uart_sifive_regs_t *uart = DEV_UART(dev); in uart_sifive_irq_rx_ready() local
263 return !!(uart->ip & IE_RXWM); in uart_sifive_irq_rx_ready()
267 static void uart_sifive_irq_err_enable(const struct device *dev) in uart_sifive_irq_err_enable() argument
269 ARG_UNUSED(dev); in uart_sifive_irq_err_enable()
272 static void uart_sifive_irq_err_disable(const struct device *dev) in uart_sifive_irq_err_disable() argument
274 ARG_UNUSED(dev); in uart_sifive_irq_err_disable()
280 * @param dev UART device struct
284 static int uart_sifive_irq_is_pending(const struct device *dev) in uart_sifive_irq_is_pending() argument
286 volatile struct uart_sifive_regs_t *uart = DEV_UART(dev); in uart_sifive_irq_is_pending() local
288 return !!(uart->ip & (IE_RXWM | IE_TXWM)); in uart_sifive_irq_is_pending()
291 static int uart_sifive_irq_update(const struct device *dev) in uart_sifive_irq_update() argument
299 * @param dev UART device struct
302 static void uart_sifive_irq_callback_set(const struct device *dev, in uart_sifive_irq_callback_set() argument
306 struct uart_sifive_data *data = dev->data; in uart_sifive_irq_callback_set()
308 data->callback = cb; in uart_sifive_irq_callback_set()
309 data->cb_data = cb_data; in uart_sifive_irq_callback_set()
312 static void uart_sifive_irq_handler(const struct device *dev) in uart_sifive_irq_handler() argument
314 struct uart_sifive_data *data = dev->data; in uart_sifive_irq_handler()
316 if (data->callback) { in uart_sifive_irq_handler()
317 data->callback(dev, data->cb_data); in uart_sifive_irq_handler()
324 static int uart_sifive_init(const struct device *dev) in uart_sifive_init() argument
326 const struct uart_sifive_device_config * const cfg = dev->config; in uart_sifive_init()
327 volatile struct uart_sifive_regs_t *uart = DEV_UART(dev); in uart_sifive_init() local
333 uart->txctrl = TXCTRL_TXEN | CTRL_CNT(cfg->txcnt_irq); in uart_sifive_init()
334 uart->rxctrl = RXCTRL_RXEN | CTRL_CNT(cfg->rxcnt_irq); in uart_sifive_init()
337 uart->div = cfg->sys_clk_freq / cfg->baud_rate - 1; in uart_sifive_init()
340 /* Ensure that uart IRQ is disabled initially */ in uart_sifive_init()
341 uart->ie = 0U; in uart_sifive_init()
344 cfg->cfg_func(); in uart_sifive_init()
348 ret = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT); in uart_sifive_init()
357 static DEVICE_API(uart, uart_sifive_driver_api) = {