2 * TI OMAP processors UART emulation.
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-char.h"
23 /* We use pc-style serial ports. */
25 #include "exec-memory.h"
30 target_phys_addr_t base;
31 SerialState *serial; /* TODO */
32 struct omap_target_agent_s *ta;
45 void omap_uart_reset(struct omap_uart_s *s)
54 struct omap_uart_s *omap_uart_init(target_phys_addr_t base,
55 qemu_irq irq, omap_clk fclk, omap_clk iclk,
56 qemu_irq txdma, qemu_irq rxdma,
57 const char *label, CharDriverState *chr)
59 struct omap_uart_s *s = (struct omap_uart_s *)
60 g_malloc0(sizeof(struct omap_uart_s));
65 s->serial = serial_mm_init(get_system_memory(), base, 2, irq,
66 omap_clk_getrate(fclk)/16,
67 chr ?: qemu_chr_new(label, "null", NULL),
68 DEVICE_NATIVE_ENDIAN);
72 static uint64_t omap_uart_read(void *opaque, target_phys_addr_t addr,
75 struct omap_uart_s *s = (struct omap_uart_s *) opaque;
78 return omap_badwidth_read8(opaque, addr);
90 case 0x48: /* EBLR (OMAP2) */
92 case 0x4C: /* OSC_12M_SEL (OMAP1) */
96 case 0x54: /* SYSC (OMAP2) */
98 case 0x58: /* SYSS (OMAP2) */
100 case 0x5c: /* WER (OMAP2) */
102 case 0x60: /* CFPS (OMAP2) */
110 static void omap_uart_write(void *opaque, target_phys_addr_t addr,
111 uint64_t value, unsigned size)
113 struct omap_uart_s *s = (struct omap_uart_s *) opaque;
116 return omap_badwidth_write8(opaque, addr, value);
120 case 0x20: /* MDR1 */
121 s->mdr[0] = value & 0x7f;
123 case 0x24: /* MDR2 */
124 s->mdr[1] = value & 0xff;
127 s->scr = value & 0xff;
129 case 0x48: /* EBLR (OMAP2) */
130 s->eblr = value & 0xff;
132 case 0x4C: /* OSC_12M_SEL (OMAP1) */
133 s->clksel = value & 1;
137 case 0x58: /* SYSS (OMAP2) */
140 case 0x54: /* SYSC (OMAP2) */
141 s->syscontrol = value & 0x1d;
145 case 0x5c: /* WER (OMAP2) */
146 s->wkup = value & 0x7f;
148 case 0x60: /* CFPS (OMAP2) */
149 s->cfps = value & 0xff;
156 static const MemoryRegionOps omap_uart_ops = {
157 .read = omap_uart_read,
158 .write = omap_uart_write,
159 .endianness = DEVICE_NATIVE_ENDIAN,
162 struct omap_uart_s *omap2_uart_init(MemoryRegion *sysmem,
163 struct omap_target_agent_s *ta,
164 qemu_irq irq, omap_clk fclk, omap_clk iclk,
165 qemu_irq txdma, qemu_irq rxdma,
166 const char *label, CharDriverState *chr)
168 target_phys_addr_t base = omap_l4_attach(ta, 0, NULL);
169 struct omap_uart_s *s = omap_uart_init(base, irq,
170 fclk, iclk, txdma, rxdma, label, chr);
172 memory_region_init_io(&s->iomem, &omap_uart_ops, s, "omap.uart", 0x100);
176 memory_region_add_subregion(sysmem, base + 0x20, &s->iomem);
181 void omap_uart_attach(struct omap_uart_s *s, CharDriverState *chr)
183 /* TODO: Should reuse or destroy current s->serial */
184 s->serial = serial_mm_init(get_system_memory(), s->base, 2, s->irq,
185 omap_clk_getrate(s->fclk) / 16,
186 chr ?: qemu_chr_new("null", "null", NULL),
187 DEVICE_NATIVE_ENDIAN);