[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 9/16] S3C General Purpose IO
From: |
Vincent Sanders |
Subject: |
[Qemu-devel] [PATCH 9/16] S3C General Purpose IO |
Date: |
Thu, 23 Apr 2009 19:05:35 +0100 |
User-agent: |
Mutt/1.5.17+20080114 (2008-01-14) |
S3C GPIO support
Signed-off-by: Vincent Sanders <address@hidden>
---
s3c24xx_gpio.c | 190 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 190 insertions(+)
diff -urN qemusvnclean/hw/s3c24xx_gpio.c qemusvnpatches/hw/s3c24xx_gpio.c
--- qemusvnclean/hw/s3c24xx_gpio.c 1970-01-01 01:00:00.000000000 +0100
+++ qemusvnpatches/hw/s3c24xx_gpio.c 2009-04-23 17:07:45.000000000 +0100
@@ -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);
+}
--
Regards Vincent
http://www.kyllikki.org/
- [Qemu-devel] [PATCH 0/16] ARM Add S3C SOC core, drivers and boards, Vincent Sanders, 2009/04/23
- [Qemu-devel] [PATCH 1/16] ARM Add ARM 920T identifiers, Vincent Sanders, 2009/04/23
- [Qemu-devel] [PATCH 2/16] Add s3c SOC header, Vincent Sanders, 2009/04/23
- [Qemu-devel] [PATCH 3/16] S3C SDRAM memory controller Peripheral, Vincent Sanders, 2009/04/23
- [Qemu-devel] [PATCH 4/16] S3C irq controller, Vincent Sanders, 2009/04/23
- [Qemu-devel] [PATCH 05/16] S3C Clock controller peripheral, Vincent Sanders, 2009/04/23
- [Qemu-devel] [PATCH 7/16] S3C serial peripheral, Vincent Sanders, 2009/04/23
- [Qemu-devel] [PATCH 6/16] S3C Timers, Vincent Sanders, 2009/04/23
- [Qemu-devel] [PATCH 8/16] S3C Real Time Clock, Vincent Sanders, 2009/04/23
- [Qemu-devel] [PATCH 9/16] S3C General Purpose IO,
Vincent Sanders <=
- [Qemu-devel] [PATCH 10/16] S3C I2C peripheral, Vincent Sanders, 2009/04/23
- [Qemu-devel] [PATCH 11/16] S3C LCD display, Vincent Sanders, 2009/04/23
- [Qemu-devel] [PATCH 12/16] S3C NAND controller, Vincent Sanders, 2009/04/23
- [Qemu-devel] [PATCH 13/16] S3C2410 SOC implementation, Vincent Sanders, 2009/04/23
- [Qemu-devel] [PATCH 14/16] S3C2440 SOC impementation, Vincent Sanders, 2009/04/23
- [Qemu-devel] [PATCH 15/16] Add S3C SOC files to Makefile, Vincent Sanders, 2009/04/23
- [Qemu-devel] [PATCH 16/16] Add two boards which use S3C2410 SOC, Vincent Sanders, 2009/04/23