2010-05-31 19:54:23 +04:00
|
|
|
/*
|
|
|
|
* TI OMAP processors UART emulation.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006-2008 Andrzej Zaborowski <balrog@zabor.org>
|
|
|
|
* Copyright (C) 2007-2009 Nokia Corporation
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 or
|
|
|
|
* (at your option) version 3 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2016-01-26 21:17:28 +03:00
|
|
|
#include "qemu/osdep.h"
|
2017-01-26 16:19:46 +03:00
|
|
|
#include "chardev/char.h"
|
2013-02-05 20:06:20 +04:00
|
|
|
#include "hw/arm/omap.h"
|
|
|
|
#include "hw/char/serial.h"
|
2012-12-17 21:19:49 +04:00
|
|
|
#include "exec/address-spaces.h"
|
2010-05-31 19:54:23 +04:00
|
|
|
|
|
|
|
/* UARTs */
|
|
|
|
struct omap_uart_s {
|
2011-11-22 17:06:46 +04:00
|
|
|
MemoryRegion iomem;
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr base;
|
2019-10-23 18:50:06 +03:00
|
|
|
SerialMM *serial; /* TODO */
|
2010-05-31 19:54:23 +04:00
|
|
|
struct omap_target_agent_s *ta;
|
|
|
|
omap_clk fclk;
|
|
|
|
qemu_irq irq;
|
|
|
|
|
|
|
|
uint8_t eblr;
|
|
|
|
uint8_t syscontrol;
|
|
|
|
uint8_t wkup;
|
|
|
|
uint8_t cfps;
|
|
|
|
uint8_t mdr[2];
|
|
|
|
uint8_t scr;
|
|
|
|
uint8_t clksel;
|
|
|
|
};
|
|
|
|
|
|
|
|
void omap_uart_reset(struct omap_uart_s *s)
|
|
|
|
{
|
|
|
|
s->eblr = 0x00;
|
|
|
|
s->syscontrol = 0;
|
|
|
|
s->wkup = 0x3f;
|
|
|
|
s->cfps = 0x69;
|
|
|
|
s->clksel = 0;
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
struct omap_uart_s *omap_uart_init(hwaddr base,
|
2010-05-31 19:54:23 +04:00
|
|
|
qemu_irq irq, omap_clk fclk, omap_clk iclk,
|
2010-08-08 16:09:26 +04:00
|
|
|
qemu_irq txdma, qemu_irq rxdma,
|
2016-12-07 16:20:22 +03:00
|
|
|
const char *label, Chardev *chr)
|
2010-05-31 19:54:23 +04:00
|
|
|
{
|
arm: Use g_new() & friends where that makes obvious sense
g_new(T, n) is neater than g_malloc(sizeof(T) * n). It's also safer,
for two reasons. One, it catches multiplication overflowing size_t.
Two, it returns T * rather than void *, which lets the compiler catch
more type errors.
This commit only touches allocations with size arguments of the form
sizeof(T).
Coccinelle semantic patch:
@@
type T;
@@
-g_malloc(sizeof(T))
+g_new(T, 1)
@@
type T;
@@
-g_try_malloc(sizeof(T))
+g_try_new(T, 1)
@@
type T;
@@
-g_malloc0(sizeof(T))
+g_new0(T, 1)
@@
type T;
@@
-g_try_malloc0(sizeof(T))
+g_try_new0(T, 1)
@@
type T;
expression n;
@@
-g_malloc(sizeof(T) * (n))
+g_new(T, n)
@@
type T;
expression n;
@@
-g_try_malloc(sizeof(T) * (n))
+g_try_new(T, n)
@@
type T;
expression n;
@@
-g_malloc0(sizeof(T) * (n))
+g_new0(T, n)
@@
type T;
expression n;
@@
-g_try_malloc0(sizeof(T) * (n))
+g_try_new0(T, n)
@@
type T;
expression p, n;
@@
-g_realloc(p, sizeof(T) * (n))
+g_renew(T, p, n)
@@
type T;
expression p, n;
@@
-g_try_realloc(p, sizeof(T) * (n))
+g_try_renew(T, p, n)
@@
type T;
expression n;
@@
-(T *)g_new(T, n)
+g_new(T, n)
@@
type T;
expression n;
@@
-(T *)g_new0(T, n)
+g_new0(T, n)
@@
type T;
expression p, n;
@@
-(T *)g_renew(T, p, n)
+g_renew(T, p, n)
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 1440524394-15640-1-git-send-email-armbru@redhat.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
2015-09-07 12:39:27 +03:00
|
|
|
struct omap_uart_s *s = g_new0(struct omap_uart_s, 1);
|
2010-05-31 19:54:23 +04:00
|
|
|
|
|
|
|
s->base = base;
|
|
|
|
s->fclk = fclk;
|
|
|
|
s->irq = irq;
|
2011-08-12 03:07:16 +04:00
|
|
|
s->serial = serial_mm_init(get_system_memory(), base, 2, irq,
|
|
|
|
omap_clk_getrate(fclk)/16,
|
2019-02-13 16:18:13 +03:00
|
|
|
chr ?: qemu_chr_new(label, "null", NULL),
|
2011-08-12 03:07:14 +04:00
|
|
|
DEVICE_NATIVE_ENDIAN);
|
2010-05-31 19:54:23 +04:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2023-01-09 17:02:55 +03:00
|
|
|
static uint64_t omap_uart_read(void *opaque, hwaddr addr, unsigned size)
|
2010-05-31 19:54:23 +04:00
|
|
|
{
|
2023-01-09 17:02:55 +03:00
|
|
|
struct omap_uart_s *s = opaque;
|
2010-05-31 19:54:23 +04:00
|
|
|
|
2011-11-22 17:06:46 +04:00
|
|
|
if (size == 4) {
|
|
|
|
return omap_badwidth_read8(opaque, addr);
|
|
|
|
}
|
|
|
|
|
2010-05-31 19:54:23 +04:00
|
|
|
switch (addr) {
|
|
|
|
case 0x20: /* MDR1 */
|
|
|
|
return s->mdr[0];
|
|
|
|
case 0x24: /* MDR2 */
|
|
|
|
return s->mdr[1];
|
|
|
|
case 0x40: /* SCR */
|
|
|
|
return s->scr;
|
|
|
|
case 0x44: /* SSR */
|
|
|
|
return 0x0;
|
|
|
|
case 0x48: /* EBLR (OMAP2) */
|
|
|
|
return s->eblr;
|
|
|
|
case 0x4C: /* OSC_12M_SEL (OMAP1) */
|
|
|
|
return s->clksel;
|
|
|
|
case 0x50: /* MVR */
|
|
|
|
return 0x30;
|
|
|
|
case 0x54: /* SYSC (OMAP2) */
|
|
|
|
return s->syscontrol;
|
|
|
|
case 0x58: /* SYSS (OMAP2) */
|
|
|
|
return 1;
|
|
|
|
case 0x5c: /* WER (OMAP2) */
|
|
|
|
return s->wkup;
|
|
|
|
case 0x60: /* CFPS (OMAP2) */
|
|
|
|
return s->cfps;
|
|
|
|
}
|
|
|
|
|
|
|
|
OMAP_BAD_REG(addr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-23 14:30:10 +04:00
|
|
|
static void omap_uart_write(void *opaque, hwaddr addr,
|
2011-11-22 17:06:46 +04:00
|
|
|
uint64_t value, unsigned size)
|
2010-05-31 19:54:23 +04:00
|
|
|
{
|
2023-01-09 17:02:55 +03:00
|
|
|
struct omap_uart_s *s = opaque;
|
2010-05-31 19:54:23 +04:00
|
|
|
|
2011-11-22 17:06:46 +04:00
|
|
|
if (size == 4) {
|
2015-03-08 21:21:13 +03:00
|
|
|
omap_badwidth_write8(opaque, addr, value);
|
|
|
|
return;
|
2011-11-22 17:06:46 +04:00
|
|
|
}
|
|
|
|
|
2010-05-31 19:54:23 +04:00
|
|
|
switch (addr) {
|
|
|
|
case 0x20: /* MDR1 */
|
|
|
|
s->mdr[0] = value & 0x7f;
|
|
|
|
break;
|
|
|
|
case 0x24: /* MDR2 */
|
|
|
|
s->mdr[1] = value & 0xff;
|
|
|
|
break;
|
|
|
|
case 0x40: /* SCR */
|
|
|
|
s->scr = value & 0xff;
|
|
|
|
break;
|
|
|
|
case 0x48: /* EBLR (OMAP2) */
|
|
|
|
s->eblr = value & 0xff;
|
|
|
|
break;
|
|
|
|
case 0x4C: /* OSC_12M_SEL (OMAP1) */
|
|
|
|
s->clksel = value & 1;
|
|
|
|
break;
|
|
|
|
case 0x44: /* SSR */
|
|
|
|
case 0x50: /* MVR */
|
|
|
|
case 0x58: /* SYSS (OMAP2) */
|
|
|
|
OMAP_RO_REG(addr);
|
|
|
|
break;
|
|
|
|
case 0x54: /* SYSC (OMAP2) */
|
|
|
|
s->syscontrol = value & 0x1d;
|
|
|
|
if (value & 2)
|
|
|
|
omap_uart_reset(s);
|
|
|
|
break;
|
|
|
|
case 0x5c: /* WER (OMAP2) */
|
|
|
|
s->wkup = value & 0x7f;
|
|
|
|
break;
|
|
|
|
case 0x60: /* CFPS (OMAP2) */
|
|
|
|
s->cfps = value & 0xff;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
OMAP_BAD_REG(addr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-22 17:06:46 +04:00
|
|
|
static const MemoryRegionOps omap_uart_ops = {
|
|
|
|
.read = omap_uart_read,
|
|
|
|
.write = omap_uart_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2010-05-31 19:54:23 +04:00
|
|
|
};
|
|
|
|
|
2011-11-22 17:06:46 +04:00
|
|
|
struct omap_uart_s *omap2_uart_init(MemoryRegion *sysmem,
|
|
|
|
struct omap_target_agent_s *ta,
|
2010-05-31 19:54:23 +04:00
|
|
|
qemu_irq irq, omap_clk fclk, omap_clk iclk,
|
2010-08-08 16:09:26 +04:00
|
|
|
qemu_irq txdma, qemu_irq rxdma,
|
2016-12-07 16:20:22 +03:00
|
|
|
const char *label, Chardev *chr)
|
2010-05-31 19:54:23 +04:00
|
|
|
{
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr base = omap_l4_attach(ta, 0, NULL);
|
2010-05-31 19:54:23 +04:00
|
|
|
struct omap_uart_s *s = omap_uart_init(base, irq,
|
2010-08-08 16:09:26 +04:00
|
|
|
fclk, iclk, txdma, rxdma, label, chr);
|
2011-11-22 17:06:46 +04:00
|
|
|
|
2013-06-06 13:41:28 +04:00
|
|
|
memory_region_init_io(&s->iomem, NULL, &omap_uart_ops, s, "omap.uart", 0x100);
|
2010-05-31 19:54:23 +04:00
|
|
|
|
|
|
|
s->ta = ta;
|
|
|
|
|
2011-11-22 17:06:46 +04:00
|
|
|
memory_region_add_subregion(sysmem, base + 0x20, &s->iomem);
|
2010-05-31 19:54:23 +04:00
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2016-12-07 16:20:22 +03:00
|
|
|
void omap_uart_attach(struct omap_uart_s *s, Chardev *chr)
|
2010-05-31 19:54:23 +04:00
|
|
|
{
|
|
|
|
/* TODO: Should reuse or destroy current s->serial */
|
2011-08-12 03:07:16 +04:00
|
|
|
s->serial = serial_mm_init(get_system_memory(), s->base, 2, s->irq,
|
2010-05-31 19:54:23 +04:00
|
|
|
omap_clk_getrate(s->fclk) / 16,
|
2019-02-13 16:18:13 +03:00
|
|
|
chr ?: qemu_chr_new("null", "null", NULL),
|
2011-08-12 03:07:14 +04:00
|
|
|
DEVICE_NATIVE_ENDIAN);
|
2010-05-31 19:54:23 +04:00
|
|
|
}
|