qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Michel Pollet <buserror@gmail.com>
To: qemu-devel@nongnu.org
Cc: Michel Pollet <buserror@gmail.com>
Subject: [Qemu-devel] [PATCH 03/13] mxs/imx23: Add uart driver
Date: Wed, 11 Dec 2013 13:56:22 +0000	[thread overview]
Message-ID: <1386770192-19585-4-git-send-email-buserror@gmail.com> (raw)
In-Reply-To: <1386770192-19585-1-git-send-email-buserror@gmail.com>

Prototype driver for the mxs/imx23 uart IO block. This has no
real 'uart' functional code, apart from letting itself be
initialized by linux without generating a timeout error.

Signed-off-by: Michel Pollet <buserror@gmail.com>
---
 hw/char/Makefile.objs |   1 +
 hw/char/mxs_uart.c    | 146 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 147 insertions(+)
 create mode 100644 hw/char/mxs_uart.c

diff --git a/hw/char/Makefile.objs b/hw/char/Makefile.objs
index cbd6a00..8ea5670 100644
--- a/hw/char/Makefile.objs
+++ b/hw/char/Makefile.objs
@@ -19,6 +19,7 @@ common-obj-$(CONFIG_ETRAXFS) += etraxfs_ser.o
 common-obj-$(CONFIG_ISA_DEBUG) += debugcon.o
 common-obj-$(CONFIG_GRLIB) += grlib_apbuart.o
 common-obj-$(CONFIG_IMX) += imx_serial.o
+common-obj-$(CONFIG_MXS) += mxs_uart.o
 common-obj-$(CONFIG_LM32) += lm32_juart.o
 common-obj-$(CONFIG_LM32) += lm32_uart.o
 common-obj-$(CONFIG_MILKYMIST) += milkymist-uart.o
diff --git a/hw/char/mxs_uart.c b/hw/char/mxs_uart.c
new file mode 100644
index 0000000..79b2582
--- /dev/null
+++ b/hw/char/mxs_uart.c
@@ -0,0 +1,146 @@
+/*
+ * mxs_uart.c
+ *
+ * Copyright: Michel Pollet <buserror@gmail.com>
+ *
+ * QEMU Licence
+ */
+
+/*
+ * Work in progress ! Right now there's just enough so that linux driver
+ * will instantiate after a probe, there is no functional code.
+ */
+#include "hw/sysbus.h"
+#include "hw/arm/mxs.h"
+
+#define D(w) w
+
+enum {
+    UART_CTRL = 0x0,
+    UART_CTRL1 = 0x1,
+    UART_CTRL2 = 0x2,
+    UART_LINECTRL = 0x3,
+    UART_LINECTRL2 = 0x4,
+    UART_INTR = 0x5,
+    UART_APP_DATA = 0x6,
+    UART_APP_STAT = 0x7,
+    UART_APP_DEBUG = 0x8,
+    UART_APP_VERSION = 0x9,
+    UART_APP_AUTOBAUD = 0xa,
+
+    UART_MAX,
+};
+typedef struct mxs_uart_state {
+    SysBusDevice busdev;
+    MemoryRegion iomem;
+
+    uint32_t r[UART_MAX];
+
+    struct {
+        uint16_t b[16];
+        int w, r;
+    } fifo[2];
+    qemu_irq irq;
+    CharDriverState *chr;
+} mxs_uart_state;
+
+static uint64_t mxs_uart_read(
+        void *opaque, hwaddr offset, unsigned size)
+{
+    mxs_uart_state *s = (mxs_uart_state *) opaque;
+    uint32_t res = 0;
+
+    D(printf("%s %04x (%d) = ", __func__, (int)offset, size);)
+    switch (offset >> 4) {
+        case 0 ... UART_MAX:
+            res = s->r[offset >> 4];
+            break;
+        default:
+            qemu_log_mask(LOG_GUEST_ERROR,
+                    "%s: bad offset 0x%x\n", __func__, (int) offset);
+            break;
+    }
+    D(printf("%08x\n", res);)
+
+    return res;
+}
+
+static void mxs_uart_write(void *opaque, hwaddr offset,
+        uint64_t value, unsigned size)
+{
+    mxs_uart_state *s = (mxs_uart_state *) opaque;
+    uint32_t oldvalue = 0;
+
+    D(printf("%s %04x %08x(%d)\n", __func__, (int)offset, (int)value, size);)
+    switch (offset >> 4) {
+        case 0 ... UART_MAX:
+            mxs_write(&s->r[offset >> 4], offset, value, size);
+            break;
+        default:
+            qemu_log_mask(LOG_GUEST_ERROR,
+                    "%s: bad offset 0x%x\n", __func__, (int) offset);
+            break;
+    }
+    switch (offset >> 4) {
+        case UART_CTRL:
+            if ((oldvalue ^ s->r[UART_CTRL]) == 0x80000000
+                    && !(oldvalue & 0x80000000)) {
+                printf("%s reseting, anding clockgate\n", __func__);
+                s->r[UART_CTRL] |= 0x40000000;
+            }
+            break;
+    }
+}
+
+static void mxs_uart_set_irq(void *opaque, int irq, int level)
+{
+//    mxs_uart_state *s = (mxs_uart_state *)opaque;
+    printf("%s %3d = %d\n", __func__, irq, level);
+}
+
+static const MemoryRegionOps mxs_uart_ops = {
+    .read = mxs_uart_read,
+    .write = mxs_uart_write,
+    .endianness = DEVICE_NATIVE_ENDIAN,
+};
+
+
+static int mxs_uart_init(SysBusDevice *dev)
+{
+    mxs_uart_state *s = OBJECT_CHECK(mxs_uart_state, dev, "mxs_uart");
+    DeviceState *qdev = DEVICE(dev);
+
+    qdev_init_gpio_in(qdev, mxs_uart_set_irq, 32 * 3);
+    sysbus_init_irq(dev, &s->irq);
+    memory_region_init_io(&s->iomem, OBJECT(s), &mxs_uart_ops, s, "mxs_uart", 0x2000);
+    sysbus_init_mmio(dev, &s->iomem);
+
+    s->r[UART_CTRL] = 0xc0030000;
+    s->r[UART_CTRL2] = 0x00220180;
+    s->r[UART_APP_STAT] = 0x89f00000;
+    s->r[UART_APP_VERSION] = 0x03000000;
+    return 0;
+}
+
+
+static void mxs_uart_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *sdc = SYS_BUS_DEVICE_CLASS(klass);
+
+    sdc->init = mxs_uart_init;
+}
+
+static TypeInfo uart_info = {
+    .name          = "mxs_uart",
+    .parent        = TYPE_SYS_BUS_DEVICE,
+    .instance_size = sizeof(mxs_uart_state),
+    .class_init    = mxs_uart_class_init,
+};
+
+static void mxs_uart_register(void)
+{
+    type_register_static(&uart_info);
+}
+
+type_init(mxs_uart_register)
+
-- 
1.8.5.1

  parent reply	other threads:[~2013-12-11 13:49 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-11 13:56 [Qemu-devel] [PATCH 00/13] Freescale mxs/imx23 + Olimex Olinuxino support Michel Pollet
2013-12-11 13:56 ` [Qemu-devel] [PATCH 01/13] mxs/imx23: Add main header file Michel Pollet
2013-12-11 13:56 ` [Qemu-devel] [PATCH 02/13] mxs: Add CONFIG_MXS to the arm-softmmu config Michel Pollet
2014-01-06 15:08   ` Peter Maydell
2013-12-11 13:56 ` Michel Pollet [this message]
2014-01-06 15:19   ` [Qemu-devel] [PATCH 03/13] mxs/imx23: Add uart driver Peter Maydell
2014-01-11  7:39     ` Peter Crosthwaite
2013-12-11 13:56 ` [Qemu-devel] [PATCH 04/13] mxs/imx23: Add DMA driver Michel Pollet
2014-01-06 15:35   ` Peter Maydell
2014-01-10  0:52     ` Peter Crosthwaite
2014-01-10  0:54       ` Peter Crosthwaite
2014-01-10 10:55       ` Peter Maydell
2013-12-11 13:56 ` [Qemu-devel] [PATCH 05/13] mxs/imx23: Add the interrupt collector Michel Pollet
2014-01-06 15:41   ` Peter Maydell
2014-01-11  8:29   ` Peter Crosthwaite
2013-12-11 13:56 ` [Qemu-devel] [PATCH 06/13] mxs/imx23: Add digctl driver Michel Pollet
2014-01-06 15:46   ` Peter Maydell
2014-01-08 18:39     ` M P
2014-01-08 18:55       ` Peter Maydell
2014-01-11  8:44         ` Peter Crosthwaite
2014-01-11  8:39   ` Peter Crosthwaite
2013-12-11 13:56 ` [Qemu-devel] [PATCH 07/13] mxs/imx23: Implements the pin mux, GPIOs Michel Pollet
2014-01-06 15:52   ` Peter Maydell
2014-01-08 18:16     ` M P
2013-12-11 13:56 ` [Qemu-devel] [PATCH 08/13] mxs/imx23: Add SSP/SPI driver Michel Pollet
2014-01-11  9:08   ` Peter Crosthwaite
2013-12-11 13:56 ` [Qemu-devel] [PATCH 09/13] mxs/imx23: Add the RTC block Michel Pollet
2014-01-11  9:16   ` Peter Crosthwaite
2013-12-11 13:56 ` [Qemu-devel] [PATCH 10/13] mxs/imx23: Add the timers Michel Pollet
2013-12-11 13:56 ` [Qemu-devel] [PATCH 11/13] mxs/imx23: Add the USB driver Michel Pollet
2014-01-11  9:57   ` Peter Crosthwaite
2013-12-11 13:56 ` [Qemu-devel] [PATCH 12/13] mxs/imx23: Main core instantiation and minor IO blocks Michel Pollet
2013-12-11 13:56 ` [Qemu-devel] [PATCH 13/13] mxs/imx23: Adds support for an Olinuxino board Michel Pollet
2013-12-13 12:53 ` [Qemu-devel] [PATCH 00/13] Freescale mxs/imx23 + Olimex Olinuxino support M P
2013-12-13 13:29   ` Peter Maydell
2013-12-13 13:45     ` M P

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1386770192-19585-4-git-send-email-buserror@gmail.com \
    --to=buserror@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).