qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 09/15] Peripheral driver for S3C SOC general purpose


From: Vincent Sanders
Subject: [Qemu-devel] [PATCH 09/15] Peripheral driver for S3C SOC general purpose I/O
Date: Wed, 6 May 2009 09:44:48 +0100

Signed-off-by: Vincent Sanders <address@hidden>
---
 Makefile.target   |    2 +-
 hw/s3c24xx_gpio.c |  190 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 191 insertions(+), 1 deletions(-)
 create mode 100644 hw/s3c24xx_gpio.c

diff --git a/Makefile.target b/Makefile.target
index 02bb9f1..d869171 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -675,7 +675,7 @@ OBJS+= nseries.o blizzard.o onenand.o vga.o cbus.o 
tusb6010.o usb-musb.o
 OBJS+= mst_fpga.o mainstone.o
 OBJS+= musicpal.o pflash_cfi02.o
 OBJS+= s3c24xx_memc.o s3c24xx_irq.o s3c24xx_clkcon.o s3c24xx_timers.o
-OBJS+= s3c24xx_serial.o s3c24xx_rtc.o
+OBJS+= s3c24xx_serial.o s3c24xx_rtc.o s3c24xx_gpio.o
 OBJS+= framebuffer.o
 CPPFLAGS += -DHAS_AUDIO
 endif
diff --git a/hw/s3c24xx_gpio.c b/hw/s3c24xx_gpio.c
new file mode 100644
index 0000000..372cfed
--- /dev/null
+++ b/hw/s3c24xx_gpio.c
@@ -0,0 +1,190 @@
+/* hw/s3c24xx_gpio.c
+ *
+ * Samsung S3C24XX GPIO emulation (mostly for E-INT)
+ *
+ * Copyright 2006, 2007 Daniel Silverstone and Vincent Sanders
+ *
+ * This file is under the terms of the GNU General Public
+ * License Version 2
+ */
+
+#include "hw.h"
+#include "s3c24xx.h"
+
+#define S3C_GPIO_GPECON (0x40)
+#define S3C_GPIO_GPEDAT (0x44)
+#define S3C_GPIO_GPEUP (0x48)
+
+#define S3C_GPIO_EINT_MASK (0xA4)
+#define S3C_GPIO_EINT_PEND (0xA8)
+#define S3C_GPIO_GSTATUS0 (0xAC)
+#define S3C_GPIO_GSTATUS1 (0xB0)
+#define S3C_GPIO_GSTATUS2 (0xB4)
+#define S3C_GPIO_GSTATUS3 (0xB8)
+#define S3C_GPIO_GSTATUS4 (0xBC)
+
+
+#define GPRN(r) (r>>2)
+#define GPR(P) soc->gpio_reg[P>>2]
+
+static void
+s3c24xx_gpio_propogate_eint(S3CState *soc)
+{
+    uint32_t ints, i;
+
+    ints = GPR(S3C_GPIO_EINT_PEND) & ~GPR(S3C_GPIO_EINT_MASK);
+
+    /* EINT0 - EINT3 are INT0 - INT3 */
+    for (i=0; i < 4; ++i)
+        qemu_set_irq(soc->irqs[i], (ints&(1<<i))?1:0);
+
+    /* EINT4 - EINT7 are INT4 */
+    qemu_set_irq(soc->irqs[4], (ints & 0xf0)?1:0);
+
+    /* EINT8 - EINT23 are INT5 */
+    qemu_set_irq(soc->irqs[5], (ints & 0x00ffff00)?1:0);
+}
+
+static uint32_t
+gpio_con_to_mask(uint32_t con)
+{
+    uint32_t mask = 0x0;
+    int bit;
+
+    for (bit = 0; bit < 16; bit++) {
+        if (((con >> (bit*2)) & 0x3) == 0x01)
+            mask |= 1 << bit;
+    }
+
+    return mask;
+}
+
+static void
+s3c24xx_gpio_write_f(void *opaque, target_phys_addr_t addr_, uint32_t value)
+{
+    S3CState *soc = (S3CState *)opaque;
+    int addr = (addr_ >> 2) & 0x3f;
+
+    if (addr < 0 || addr > 47)
+        addr = 47;
+
+    if (addr == (S3C_GPIO_EINT_MASK>>2))
+        value &= ~0xf; /* cannot mask EINT0-EINT3 */
+
+    if (addr == (S3C_GPIO_EINT_PEND>>2)) {
+        soc->gpio_reg[addr] &= ~value;
+    } else {
+        if (addr < (0x80/4) && (addr_ & 0xf) == 0x04) {
+            uint32_t mask = gpio_con_to_mask(soc->gpio_reg[addr-1]);
+
+            value &= mask;
+
+            soc->gpio_reg[addr] &= ~mask;
+            soc->gpio_reg[addr] |= value;
+        } else
+            soc->gpio_reg[addr] = value;
+    }
+
+    if ((addr == (S3C_GPIO_EINT_MASK)>>2) ||
+        (addr == (S3C_GPIO_EINT_PEND)>>2)) {
+        /* A write to the EINT regs leads us to determine the interrupts to
+         * propagate
+         */
+        s3c24xx_gpio_propogate_eint(soc);
+    }
+}
+
+static uint32_t
+s3c24xx_gpio_read_f(void *opaque, target_phys_addr_t addr_)
+{
+    S3CState *soc = (S3CState *)opaque;
+    uint32_t addr = (addr_ >> 2);
+    uint32_t ret;
+
+    if (addr > GPRN(S3C_GPIO_GSTATUS4))
+        addr = GPRN(S3C_GPIO_GSTATUS4);
+
+    ret = soc->gpio_reg[addr];
+
+    if (addr == GPRN(S3C_GPIO_GPEDAT)) {
+        /* IIC pins are special function pins on GPE14 and GPE15. If GPE is is
+         * in input mode make the IIC lines appear to be pulled high. This is
+         * neccissary because OS i2c drivers use this to ensure the I2C bus is
+         * clear.
+         */
+        if ((GPR(S3C_GPIO_GPECON) & (3<<28)) == 0)
+            ret |= 1 << 14;
+
+        if ((GPR(S3C_GPIO_GPECON) & (3<<30)) == 0)
+            ret |= 1 << 15;
+    }
+
+    return ret;
+}
+
+
+static CPUReadMemoryFunc *s3c24xx_gpio_read[] = {
+    &s3c24xx_gpio_read_f,
+    &s3c24xx_gpio_read_f,
+    &s3c24xx_gpio_read_f,
+};
+
+static CPUWriteMemoryFunc *s3c24xx_gpio_write[] = {
+    &s3c24xx_gpio_write_f,
+    &s3c24xx_gpio_write_f,
+    &s3c24xx_gpio_write_f,
+};
+
+static void
+s3c24xx_gpio_irq_handler(void *opaque, int n, int level)
+{
+    S3CState *soc = (S3CState *)opaque;
+    if (level)
+        GPR(S3C_GPIO_EINT_PEND) |= (1<<n);
+
+    s3c24xx_gpio_propogate_eint(soc);
+}
+
+void
+s3c24xx_gpio_init(S3CState *soc, target_phys_addr_t base_addr, uint32_t cpu_id)
+{
+    /* Samsung S3C24XX GPIO
+     *
+     * The primary operation here is the ID register and IRQs
+     */
+    int tag = cpu_register_io_memory(0, s3c24xx_gpio_read, s3c24xx_gpio_write, 
soc);
+    cpu_register_physical_memory(base_addr, 47 * 4, tag);
+
+    GPR(0x00) = 0x7fffff;
+    GPR(0x10) = 0;
+    GPR(0x18) = 0;
+    GPR(0x20) = 0;
+    GPR(0x28) = 0;
+    GPR(0x30) = 0;
+    GPR(0x34) = 0xfefc;
+    GPR(0x38) = 0xf000;
+    GPR(0x40) = 0;
+    GPR(0x48) = 0;
+    GPR(0x50) = 0;
+    GPR(0x58) = 0;
+    GPR(0x60) = 0;
+    GPR(0x68) = 0xf800;
+    GPR(0x70) = 0;
+    GPR(0x78) = 0;
+    GPR(0x80) = 0x10330;
+    GPR(0x84) = 0;
+    GPR(0x88) = 0;
+    GPR(0x8C) = 0;
+    GPR(0x90) = 0;
+    GPR(0x9C) = 0;
+    GPR(0xA0) = 0;
+    GPR(0xA4) = 0xfffff0;
+    GPR(0xA8) = 0;
+    GPR(S3C_GPIO_GSTATUS1) = cpu_id;
+    GPR(S3C_GPIO_GSTATUS2) = 1;
+    GPR(S3C_GPIO_GSTATUS3) = 0;
+    GPR(S3C_GPIO_GSTATUS4) = 0;
+
+    /* EINTs 0-23 -- Only 24, not 48 because EINTs are not level */
+    soc->eirqs = qemu_allocate_irqs(s3c24xx_gpio_irq_handler, soc, 24);
+}
-- 
1.5.4.3





reply via email to

[Prev in Thread] Current Thread [Next in Thread]