2 * TI OMAP processors UART emulation.
4 * Copyright (C) 2006-2008 Andrzej Zaborowski <balrog@zabor.org>
5 * Copyright (C) 2007-2009 Nokia Corporation
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 or
10 * (at your option) version 3 of the License.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include "qemu/osdep.h"
21 #include "chardev/char.h"
22 #include "hw/arm/omap.h"
23 #include "hw/char/serial.h"
24 #include "exec/address-spaces.h"
30 SerialMM
*serial
; /* TODO */
31 struct omap_target_agent_s
*ta
;
44 void omap_uart_reset(struct omap_uart_s
*s
)
53 struct omap_uart_s
*omap_uart_init(hwaddr base
,
54 qemu_irq irq
, omap_clk fclk
, omap_clk iclk
,
55 qemu_irq txdma
, qemu_irq rxdma
,
56 const char *label
, Chardev
*chr
)
58 struct omap_uart_s
*s
= g_new0(struct omap_uart_s
, 1);
63 s
->serial
= serial_mm_init(get_system_memory(), base
, 2, irq
,
64 omap_clk_getrate(fclk
) / 16,
65 chr
?: qemu_chr_new(label
, "null", NULL
),
66 DEVICE_NATIVE_ENDIAN
);
70 static uint64_t omap_uart_read(void *opaque
, hwaddr addr
, unsigned size
)
72 struct omap_uart_s
*s
= opaque
;
75 return omap_badwidth_read8(opaque
, addr
);
87 case 0x48: /* EBLR (OMAP2) */
89 case 0x4C: /* OSC_12M_SEL (OMAP1) */
93 case 0x54: /* SYSC (OMAP2) */
95 case 0x58: /* SYSS (OMAP2) */
97 case 0x5c: /* WER (OMAP2) */
99 case 0x60: /* CFPS (OMAP2) */
107 static void omap_uart_write(void *opaque
, hwaddr addr
,
108 uint64_t value
, unsigned size
)
110 struct omap_uart_s
*s
= opaque
;
113 omap_badwidth_write8(opaque
, addr
, value
);
118 case 0x20: /* MDR1 */
119 s
->mdr
[0] = value
& 0x7f;
121 case 0x24: /* MDR2 */
122 s
->mdr
[1] = value
& 0xff;
125 s
->scr
= value
& 0xff;
127 case 0x48: /* EBLR (OMAP2) */
128 s
->eblr
= value
& 0xff;
130 case 0x4C: /* OSC_12M_SEL (OMAP1) */
131 s
->clksel
= value
& 1;
135 case 0x58: /* SYSS (OMAP2) */
138 case 0x54: /* SYSC (OMAP2) */
139 s
->syscontrol
= value
& 0x1d;
144 case 0x5c: /* WER (OMAP2) */
145 s
->wkup
= value
& 0x7f;
147 case 0x60: /* CFPS (OMAP2) */
148 s
->cfps
= value
& 0xff;
155 static const MemoryRegionOps omap_uart_ops
= {
156 .read
= omap_uart_read
,
157 .write
= omap_uart_write
,
158 .endianness
= DEVICE_NATIVE_ENDIAN
,
161 struct omap_uart_s
*omap2_uart_init(MemoryRegion
*sysmem
,
162 struct omap_target_agent_s
*ta
,
163 qemu_irq irq
, omap_clk fclk
, omap_clk iclk
,
164 qemu_irq txdma
, qemu_irq rxdma
,
165 const char *label
, Chardev
*chr
)
167 hwaddr base
= omap_l4_attach(ta
, 0, NULL
);
168 struct omap_uart_s
*s
= omap_uart_init(base
, irq
,
169 fclk
, iclk
, txdma
, rxdma
, label
, chr
);
171 memory_region_init_io(&s
->iomem
, NULL
, &omap_uart_ops
, s
, "omap.uart", 0x100);
175 memory_region_add_subregion(sysmem
, base
+ 0x20, &s
->iomem
);