qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [Patch 1/2][PXA27x] initial keypad support
@ 2007-12-12  1:46 Armin
  2007-12-12  5:05 ` andrzej zaborowski
  0 siblings, 1 reply; 3+ messages in thread
From: Armin @ 2007-12-12  1:46 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 303 bytes --]

Hello,

Please consider this for inclusion
Here is an attempt to add PXA27x keypad support. It currently only 
supports the matrix type interface. It still needs direct and 
mulitswitch support added.

Just wanted to get something out there for folks to pound on.

Comment and feedback welcome.

-Armin

[-- Attachment #2: pxa27x_kpad.patch --]
[-- Type: text/x-patch, Size: 11520 bytes --]

Index: qemu/hw/pxa.h
===================================================================
--- qemu.orig/hw/pxa.h
+++ qemu/hw/pxa.h
@@ -13,6 +13,7 @@
 # define PXA2XX_PIC_SSP3	0
 # define PXA2XX_PIC_USBH2	2
 # define PXA2XX_PIC_USBH1	3
+# define PXA2XX_PIC_KEYPAD	4
 # define PXA2XX_PIC_PWRI2C	6
 # define PXA25X_PIC_HWUART	7
 # define PXA27X_PIC_OST_4_11	7
@@ -61,6 +62,52 @@
 # define PXA2XX_INTERNAL_BASE	0x5c000000
 # define PXA2XX_INTERNAL_SIZE	0x40000
 
+/* Keypad defines */
+#define KPC_AS          (0x1 << 30)  /* Automatic Scan bit */
+#define KPC_ASACT       (0x1 << 29)  /* Automatic Scan on Activity */
+#define KPC_MI          (0x1 << 22)  /* Matrix interrupt bit */
+#define KPC_IMKP        (0x1 << 21)  /* Ignore Multiple Key Press */
+#define KPC_MS7         (0x1 << 20)  /* Matrix scan line 7 */
+#define KPC_MS6         (0x1 << 19)  /* Matrix scan line 6 */
+#define KPC_MS5         (0x1 << 18)  /* Matrix scan line 5 */
+#define KPC_MS4         (0x1 << 17)  /* Matrix scan line 4 */
+#define KPC_MS3         (0x1 << 16)  /* Matrix scan line 3 */
+#define KPC_MS2         (0x1 << 15)  /* Matrix scan line 2 */
+#define KPC_MS1         (0x1 << 14)  /* Matrix scan line 1 */
+#define KPC_MS0         (0x1 << 13)  /* Matrix scan line 0 */
+#define KPC_ME          (0x1 << 12)  /* Matrix Keypad Enable */
+#define KPC_MIE         (0x1 << 11)  /* Matrix Interrupt Enable */
+#define KPC_DK_DEB_SEL  (0x1 <<  9)  /* Direct Keypad Debounce Select */
+#define KPC_DI          (0x1 <<  5)  /* Direct key interrupt bit */
+#define KPC_RE_ZERO_DEB (0x1 <<  4)  /* Rotary Encoder Zero Debounce */
+#define KPC_REE1        (0x1 <<  3)  /* Rotary Encoder1 Enable */
+#define KPC_REE0        (0x1 <<  2)  /* Rotary Encoder0 Enable */
+#define KPC_DE          (0x1 <<  1)  /* Direct Keypad Enable */
+#define KPC_DIE         (0x1 <<  0)  /* Direct Keypad interrupt Enable */
+
+#define KPDK_DKP        (0x1 << 31)
+#define KPDK_DK7        (0x1 <<  7)
+#define KPDK_DK6        (0x1 <<  6)
+#define KPDK_DK5        (0x1 <<  5)
+#define KPDK_DK4        (0x1 <<  4)
+#define KPDK_DK3        (0x1 <<  3)
+#define KPDK_DK2        (0x1 <<  2)
+#define KPDK_DK1        (0x1 <<  1)
+#define KPDK_DK0        (0x1 <<  0)
+
+#define KPREC_OF1       (0x1 << 31)
+#define kPREC_UF1       (0x1 << 30)
+#define KPREC_OF0       (0x1 << 15)
+#define KPREC_UF0       (0x1 << 14)
+
+#define KPMK_MKP        (0x1 << 31)
+#define KPAS_SO         (0x1 << 31)
+#define KPASMKPx_SO     (0x1 << 31)
+
+
+#define KPASMKPx_MKC(row, col)  (1 << (row + 16 * (col % 2)))
+
+
 /* pxa2xx_pic.c */
 qemu_irq *pxa2xx_pic_init(target_phys_addr_t base, CPUState *env);
 
@@ -120,6 +167,13 @@ i2c_bus *pxa2xx_i2c_bus(struct pxa2xx_i2
 struct pxa2xx_i2s_s;
 struct pxa2xx_fir_s;
 
+/* pxa2xx_kpad.c */
+struct pxa2xx_keypad_s;
+struct pxa2xx_keypad_s *pxa27x_keypad_init(target_phys_addr_t base,
+				qemu_irq irq);
+void pxa27_register_keyboard(struct pxa2xx_keypad_s *kp, int **keymap, int
+size);
+
 struct pxa2xx_state_s {
     CPUState *env;
     qemu_irq *pic;
@@ -133,6 +187,7 @@ struct pxa2xx_state_s {
     struct pxa2xx_pcmcia_s *pcmcia[2];
     struct pxa2xx_i2s_s *i2s;
     struct pxa2xx_fir_s *fir;
+    struct pxa2xx_keypad_s *kp;
 
     /* Power management */
     target_phys_addr_t pm_base;
@@ -200,6 +255,25 @@ struct pxa2xx_i2s_s {
     uint32_t fifo[16];
 };
 
+#define PXAKBD_MAXROW       8
+#define PXAKBD_MAXCOL       8
+
+struct pxa2xx_keypad_s{
+    target_phys_addr_t base;
+    qemu_irq irq;
+	int keymap[PXAKBD_MAXCOL][PXAKBD_MAXROW];
+    uint32_t    kpc;
+    uint32_t    kpdk;
+    uint32_t    kprec;
+    uint32_t    kpmk;
+    uint32_t    kpas;
+    uint32_t    kpasmkp0;
+    uint32_t    kpasmkp1;
+    uint32_t    kpasmkp2;
+    uint32_t    kpasmkp3;
+    uint32_t    kpkdi;
+};
+
 # define PA_FMT			"0x%08lx"
 # define REG_FMT		"0x" TARGET_FMT_plx
 
Index: qemu/hw/pxa2xx.c
===================================================================
--- qemu.orig/hw/pxa2xx.c
+++ qemu/hw/pxa2xx.c
@@ -2156,6 +2156,7 @@ struct pxa2xx_state_s *pxa270_init(unsig
     /* GPIO1 resets the processor */
     /* The handler can be overridden by board-specific code */
     pxa2xx_gpio_out_set(s->gpio, 1, s->reset);
+	s->kp = pxa27x_keypad_init(0x41500000, s->pic[PXA2XX_PIC_KEYPAD]);
     return s;
 }
 
Index: qemu/hw/pxa2xx_keypad.c
===================================================================
--- /dev/null
+++ qemu/hw/pxa2xx_keypad.c
@@ -0,0 +1,257 @@
+/*
+ * Intel PXA27X Keypad Controller emulation.
+ *
+ * Copyright (c) 2007
+ * Written by Armin Kuster <akuster@kama-aina.net> or
+ *			  			<akuster@mvista.com>
+ *
+ * This code is licensed under the GPLv2.
+ */
+
+#include "hw.h"
+#include "pxa.h"
+#include "console.h"
+
+/*
+ * Keypad
+ */
+#define KPC         0x00    /* Keypad Interface Control register */
+#define KPDK        0x08    /* Keypad Interface Direct Key register */
+#define KPREC       0x10    /* Keypad Interface Rotary Encoder register */
+#define KPMK        0x18    /* Keypad Interface Matrix Key register */
+#define KPAS        0x20    /* Keypad Interface Automatic Scan register */
+#define KPASMKP0    0x28    /* Keypad Interface Automatic Scan Multiple
+                                Key Presser register 0 */
+#define KPASMKP1    0x30    /* Keypad Interface Automatic Scan Multiple
+                                Key Presser register 1 */
+#define KPASMKP2    0x38    /* Keypad Interface Automatic Scan Multiple
+                                Key Presser register 2 */
+#define KPASMKP3    0x40    /* Keypad Interface Automatic Scan Multiple
+                                Key Presser register 3 */
+#define KPKDI       0x48    /* Keypad Interface Key Debounce Interval
+                                register */
+
+static void pxa27x_keyboard_event (struct  pxa2xx_keypad_s *kp, int keycode)
+{
+ 	int row, col,rel;
+
+	if(!(kp->kpc & KPC_ME)) /* skip if not enabled */
+		return;
+
+	if( kp->kpc & KPC_AS || kp->kpc & KPC_ASACT){
+		if(kp->kpc & KPC_AS)
+			kp->kpc &= ~(KPC_AS);
+	rel = (keycode & 0x80) ? 1 : 0; /* key release from qemu */
+	keycode &= ~(0x80); /* strip qemu key release bit */
+	for (col = 0; col < PXAKBD_MAXCOL; col++) {
+		for (row = 0; row < PXAKBD_MAXROW; row++) {
+			if (kp->keymap[col][row] == keycode) {
+				switch (col) {
+					case 0:
+					case 1:
+						if(rel)
+							kp->kpasmkp0 = ~(0xffffffff);
+						else
+							kp->kpasmkp0 |= KPASMKPx_MKC(row,col);
+					break;
+					case 2:
+					case 3:
+						if(rel)
+							kp->kpasmkp1 = ~(0xffffffff);
+						else
+							kp->kpasmkp1 |= KPASMKPx_MKC(row,col);
+					break;
+					case 4:
+					case 5:
+						if(rel)
+							kp->kpasmkp2 = ~(0xffffffff);
+						else
+							kp->kpasmkp2 |= KPASMKPx_MKC(row,col);
+					break;
+					case 6:
+					case 7:
+						if(rel)
+							kp->kpasmkp3 = ~(0xffffffff);
+						else
+							kp->kpasmkp3 |= KPASMKPx_MKC(row,col);
+					break;
+				} /* switch */
+				kp->kpc &= ~KPC_AS; /* clear scan bit */
+				goto out;
+			} /* key match */
+		} /* row */
+	} /* col */
+	} /* scan enable */
+	return;
+
+out:
+	if(kp->kpc & KPC_MIE){
+		kp->kpc |= KPC_MI;
+		qemu_irq_raise(kp->irq);
+	}
+	return;
+}
+
+static uint32_t pxa2xx_keypad_read(void *opaque, target_phys_addr_t offset)
+{
+    struct pxa2xx_keypad_s *s = (struct pxa2xx_keypad_s *) opaque;
+    offset -= s->base;
+
+    switch (offset) {
+	case KPC:
+		qemu_irq_lower(s->irq);
+		return s->kpc;
+		break;
+	case KPDK:
+		return s->kpdk;
+		break;
+	case KPREC:
+		return s->kprec;
+		break;
+	case KPMK:
+		return s->kpmk;
+		break;
+	case KPAS:
+		return s->kpas;
+		break;
+	case KPASMKP0:
+		return s->kpasmkp0;
+		break;
+	case KPASMKP1:
+		return s->kpasmkp1;
+		break;
+	case KPASMKP2:
+		return s->kpasmkp2;
+		break;
+	case KPASMKP3:
+		return s->kpasmkp3;
+		break;
+	case KPKDI:
+		return s->kpkdi;
+		break;
+    default:
+        cpu_abort(cpu_single_env, "%s: Bad offset " REG_FMT "\n",
+                        __FUNCTION__, offset);
+    }
+
+    return 0;
+}
+
+static void pxa2xx_keypad_write(void *opaque,
+                target_phys_addr_t offset, uint32_t value)
+{
+    struct pxa2xx_keypad_s *s = (struct pxa2xx_keypad_s *) opaque;
+    offset -= s->base;
+
+    switch (offset) {
+	case KPC:
+		s->kpc = value;
+		break;
+	case KPDK:
+		s->kpdk = value;
+		break;
+	case KPREC:
+		s->kprec = value;
+		break;
+	case KPMK:
+		s->kpmk = value;
+		break;
+	case KPAS:
+		s->kpas = value;
+		break;
+	case KPASMKP0:
+		s->kpasmkp0 = value;
+		break;
+	case KPASMKP1:
+		s->kpasmkp1 = value;
+		break;
+	case KPASMKP2:
+		s->kpasmkp2 = value;
+		break;
+	case KPASMKP3:
+		s->kpasmkp3 = value;
+		break;
+	case KPKDI:
+		s->kpkdi = value;
+		break;
+
+    default:
+        cpu_abort(cpu_single_env, "%s: Bad offset " REG_FMT "\n",
+                        __FUNCTION__, offset);
+    }
+}
+
+static CPUReadMemoryFunc *pxa2xx_keypad_readfn[] = {
+    pxa2xx_keypad_read,
+    pxa2xx_keypad_read,
+    pxa2xx_keypad_read
+};
+
+static CPUWriteMemoryFunc *pxa2xx_keypad_writefn[] = {
+    pxa2xx_keypad_write,
+    pxa2xx_keypad_write,
+    pxa2xx_keypad_write
+};
+
+static void pxa2xx_keypad_save(QEMUFile *f, void *opaque)
+{
+    struct pxa2xx_keypad_s *s = (struct pxa2xx_keypad_s *) opaque;
+
+    qemu_put_be32s(f, &s->kpc);
+    qemu_put_be32s(f, &s->kpdk);
+    qemu_put_be32s(f, &s->kprec);
+    qemu_put_be32s(f, &s->kpmk);
+    qemu_put_be32s(f, &s->kpas);
+    qemu_put_be32s(f, &s->kpasmkp0);
+    qemu_put_be32s(f, &s->kpasmkp1);
+    qemu_put_be32s(f, &s->kpasmkp2);
+    qemu_put_be32s(f, &s->kpasmkp3);
+    qemu_put_be32s(f, &s->kpkdi);
+
+}
+
+static int pxa2xx_keypad_load(QEMUFile *f, void *opaque, int version_id)
+{
+    struct pxa2xx_keypad_s *s = (struct pxa2xx_keypad_s *) opaque;
+
+    qemu_get_be32s(f, &s->kpc);
+    qemu_get_be32s(f, &s->kpdk);
+    qemu_get_be32s(f, &s->kprec);
+    qemu_get_be32s(f, &s->kpmk);
+    qemu_get_be32s(f, &s->kpas);
+    qemu_get_be32s(f, &s->kpasmkp0);
+    qemu_get_be32s(f, &s->kpasmkp1);
+    qemu_get_be32s(f, &s->kpasmkp2);
+    qemu_get_be32s(f, &s->kpasmkp3);
+    qemu_get_be32s(f, &s->kpkdi);
+
+    return 0;
+}
+
+struct pxa2xx_keypad_s *pxa27x_keypad_init(target_phys_addr_t base,
+		qemu_irq irq)
+{
+    int iomemtype;
+    struct pxa2xx_keypad_s *s;
+
+    s = (struct pxa2xx_keypad_s *) qemu_mallocz(sizeof(struct pxa2xx_keypad_s));
+    s->base = base;
+    s->irq = irq;
+
+    iomemtype = cpu_register_io_memory(0, pxa2xx_keypad_readfn,
+                    pxa2xx_keypad_writefn, s);
+    cpu_register_physical_memory(base, 0x00100000, iomemtype);
+
+    register_savevm("pxa2xx_keypad", 0, 0,
+                    pxa2xx_keypad_save, pxa2xx_keypad_load, s);
+
+    return s;
+}
+
+void pxa27_register_keyboard(struct pxa2xx_keypad_s *kp, int **keymap, int
+size)
+{
+	memcpy(kp->keymap, keymap, size);
+	qemu_add_kbd_event_handler((QEMUPutKBDEvent *) pxa27x_keyboard_event, kp);
+}
+
Index: qemu/Makefile.target
===================================================================
--- qemu.orig/Makefile.target
+++ qemu/Makefile.target
@@ -494,7 +494,7 @@ VL_OBJS+= armv7m.o armv7m_nvic.o stellar
 VL_OBJS+= pl061.o
 VL_OBJS+= arm-semi.o
 VL_OBJS+= pxa2xx.o pxa2xx_pic.o pxa2xx_gpio.o pxa2xx_timer.o pxa2xx_dma.o
-VL_OBJS+= pxa2xx_lcd.o pxa2xx_mmci.o pxa2xx_pcmcia.o
+VL_OBJS+= pxa2xx_lcd.o pxa2xx_mmci.o pxa2xx_pcmcia.o pxa2xx_keypad.o
 VL_OBJS+= pflash_cfi01.o gumstix.o
 VL_OBJS+= spitz.o ide.o serial.o nand.o ecc.o
 VL_OBJS+= omap.o omap_lcdc.o omap1_clk.o omap_mmc.o omap_i2c.o

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [Patch 1/2][PXA27x] initial keypad support
  2007-12-12  1:46 [Qemu-devel] [Patch 1/2][PXA27x] initial keypad support Armin
@ 2007-12-12  5:05 ` andrzej zaborowski
  2007-12-13  2:47   ` Armin
  0 siblings, 1 reply; 3+ messages in thread
From: andrzej zaborowski @ 2007-12-12  5:05 UTC (permalink / raw)
  To: qemu-devel

Hi,

On 12/12/2007, Armin <akuster@kama-aina.net> wrote:
> Here is an attempt to add PXA27x keypad support. It currently only
> supports the matrix type interface. It still needs direct and
> mulitswitch support added.
>
> Just wanted to get something out there for folks to pound on.
>
> Comment and feedback welcome.

Here are some comments:

* Several bits in KPC and KPREC should be reset on read. The IRQ
should be reset when it becomes masked in KPC, and potentially
asserted when it becomes unmasked.

* It's wasteful to go through all keys in the 8x8 matrix on every
event. It can be avoided easily by mapping qemu keycode to matrix
position, rather than position to keycode, for example the PalmT|E
matrix keypad does that.

* Please convert the indentation in the file to use spaces, before
considering for inclusion.

* The bit definitions and pxa2xx_keypad_s struct are local to the
keypad module so they shouldn't be in the header file exposed to the
whole world.

* Please set a copyright owner.

Regarding mainstone keypad patch:

* Probably not worth to stick the keymap in a file of its own since it
is not shared between different machines - it's an integral part of
mainstone.

Thanks,
Andrew

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [Patch 1/2][PXA27x] initial keypad support
  2007-12-12  5:05 ` andrzej zaborowski
@ 2007-12-13  2:47   ` Armin
  0 siblings, 0 replies; 3+ messages in thread
From: Armin @ 2007-12-13  2:47 UTC (permalink / raw)
  To: qemu-devel

andrzej zaborowski wrote:
> Hi,
>
> On 12/12/2007, Armin <akuster@kama-aina.net> wrote:
>   
>> Here is an attempt to add PXA27x keypad support. It currently only
>> supports the matrix type interface. It still needs direct and
>> mulitswitch support added.
>>
>> Just wanted to get something out there for folks to pound on.
>>
>> Comment and feedback welcome.
>>     
>
> Here are some comments:
>
> * Several bits in KPC and KPREC should be reset on read. The IRQ
> should be reset when it becomes masked in KPC, and potentially
> asserted when it becomes unmasked.
>   
Done, I think I got the reset on read .
The MI and DI interrupt bits are set after a scan has completed and  
then the IRQ is asserted. I think I got it.
> * It's wasteful to go through all keys in the 8x8 matrix on every
> event. It can be avoided easily by mapping qemu keycode to matrix
> position, rather than position to keycode, for example the PalmT|E
> matrix keypad does that.
>   
Yeah, that was a bit overkill ; )
> * Please convert the indentation in the file to use spaces, before
> considering for inclusion.
>
>   
sure thing
> * The bit definitions and pxa2xx_keypad_s struct are local to the
> keypad module so they shouldn't be in the header file exposed to the
> whole world.
>   
Ok.
> * Please set a copyright owner.
>   
Ok.
> Regarding mainstone keypad patch:
>
> * Probably not worth to stick the keymap in a file of its own since it
> is not shared between different machines - it's an integral part of
> mainstone.
>   
Done

Thanks for the feedback.

New patches to follow.

-Armin

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-12-13  2:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-12  1:46 [Qemu-devel] [Patch 1/2][PXA27x] initial keypad support Armin
2007-12-12  5:05 ` andrzej zaborowski
2007-12-13  2:47   ` Armin

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).