xref: /openbmc/qemu/include/hw/char/nrf51_uart.h (revision 09a274d8)
1 /*
2  * nRF51 SoC UART emulation
3  *
4  * Copyright (c) 2018 Julia Suvorova <jusual@mail.ru>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 or
8  * (at your option) any later version.
9  */
10 
11 #ifndef NRF51_UART_H
12 #define NRF51_UART_H
13 
14 #include "hw/sysbus.h"
15 #include "chardev/char-fe.h"
16 #include "hw/registerfields.h"
17 
18 #define UART_FIFO_LENGTH 6
19 #define UART_SIZE 0x1000
20 
21 #define TYPE_NRF51_UART "nrf51_soc.uart"
22 #define NRF51_UART(obj) OBJECT_CHECK(NRF51UARTState, (obj), TYPE_NRF51_UART)
23 
24 REG32(UART_STARTRX, 0x000)
25 REG32(UART_STOPRX, 0x004)
26 REG32(UART_STARTTX, 0x008)
27 REG32(UART_STOPTX, 0x00C)
28 REG32(UART_SUSPEND, 0x01C)
29 
30 REG32(UART_CTS, 0x100)
31 REG32(UART_NCTS, 0x104)
32 REG32(UART_RXDRDY, 0x108)
33 REG32(UART_TXDRDY, 0x11C)
34 REG32(UART_ERROR, 0x124)
35 REG32(UART_RXTO, 0x144)
36 
37 REG32(UART_INTEN, 0x300)
38     FIELD(UART_INTEN, CTS, 0, 1)
39     FIELD(UART_INTEN, NCTS, 1, 1)
40     FIELD(UART_INTEN, RXDRDY, 2, 1)
41     FIELD(UART_INTEN, TXDRDY, 7, 1)
42     FIELD(UART_INTEN, ERROR, 9, 1)
43     FIELD(UART_INTEN, RXTO, 17, 1)
44 REG32(UART_INTENSET, 0x304)
45 REG32(UART_INTENCLR, 0x308)
46 REG32(UART_ERRORSRC, 0x480)
47 REG32(UART_ENABLE, 0x500)
48 REG32(UART_PSELRTS, 0x508)
49 REG32(UART_PSELTXD, 0x50C)
50 REG32(UART_PSELCTS, 0x510)
51 REG32(UART_PSELRXD, 0x514)
52 REG32(UART_RXD, 0x518)
53 REG32(UART_TXD, 0x51C)
54 REG32(UART_BAUDRATE, 0x524)
55 REG32(UART_CONFIG, 0x56C)
56 
57 typedef struct NRF51UARTState {
58     SysBusDevice parent_obj;
59 
60     MemoryRegion iomem;
61     CharBackend chr;
62     qemu_irq irq;
63     guint watch_tag;
64 
65     uint8_t rx_fifo[UART_FIFO_LENGTH];
66     unsigned int rx_fifo_pos;
67     unsigned int rx_fifo_len;
68 
69     uint32_t reg[0x56C];
70 
71     bool rx_started;
72     bool tx_started;
73     bool pending_tx_byte;
74     bool enabled;
75 } NRF51UARTState;
76 
77 #endif
78