xref: /openbmc/qemu/include/hw/char/cadence_uart.h (revision 8e6fe6b8)
1 /*
2  * Device model for Cadence UART
3  *
4  * Copyright (c) 2010 Xilinx Inc.
5  * Copyright (c) 2012 Peter A.G. Crosthwaite (peter.crosthwaite@petalogix.com)
6  * Copyright (c) 2012 PetaLogix Pty Ltd.
7  * Written by Haibing Ma
8  *            M.Habib
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version
13  * 2 of the License, or (at your option) any later version.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef CADENCE_UART_H
20 #define CADENCE_UART_H
21 
22 #include "hw/sysbus.h"
23 #include "chardev/char-fe.h"
24 #include "qemu/timer.h"
25 
26 #define CADENCE_UART_RX_FIFO_SIZE           16
27 #define CADENCE_UART_TX_FIFO_SIZE           16
28 
29 #define CADENCE_UART_R_MAX (0x48/4)
30 
31 #define TYPE_CADENCE_UART "cadence_uart"
32 #define CADENCE_UART(obj) OBJECT_CHECK(CadenceUARTState, (obj), \
33                                        TYPE_CADENCE_UART)
34 
35 typedef struct {
36     /*< private >*/
37     SysBusDevice parent_obj;
38 
39     /*< public >*/
40     MemoryRegion iomem;
41     uint32_t r[CADENCE_UART_R_MAX];
42     uint8_t rx_fifo[CADENCE_UART_RX_FIFO_SIZE];
43     uint8_t tx_fifo[CADENCE_UART_TX_FIFO_SIZE];
44     uint32_t rx_wpos;
45     uint32_t rx_count;
46     uint32_t tx_count;
47     uint64_t char_tx_time;
48     CharBackend chr;
49     qemu_irq irq;
50     QEMUTimer *fifo_trigger_handle;
51 } CadenceUARTState;
52 
53 static inline DeviceState *cadence_uart_create(hwaddr addr,
54                                         qemu_irq irq,
55                                         Chardev *chr)
56 {
57     DeviceState *dev;
58     SysBusDevice *s;
59 
60     dev = qdev_create(NULL, TYPE_CADENCE_UART);
61     s = SYS_BUS_DEVICE(dev);
62     qdev_prop_set_chr(dev, "chardev", chr);
63     qdev_init_nofail(dev);
64     sysbus_mmio_map(s, 0, addr);
65     sysbus_connect_irq(s, 0, irq);
66 
67     return dev;
68 }
69 
70 #endif
71