public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 1/4] PXA: PXA27x Matrix keypad driver
@ 2012-01-09 13:01 Vasily Khoruzhick
  2012-01-09 13:01 ` [U-Boot] [PATCH 2/4] zipitz2: enable pxa27x_mkp driver Vasily Khoruzhick
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Vasily Khoruzhick @ 2012-01-09 13:01 UTC (permalink / raw)
  To: u-boot

From: Marek Vasut <marek.vasut@gmail.com>

Signed-off-by: Marek Vasut <marek.vasut@gmail.com>
Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
[vasily: adapted Marek's old version for newer u-boot]
---
 arch/arm/include/asm/arch-pxa/pxa-regs.h |    6 +-
 drivers/input/Makefile                   |    2 +
 drivers/input/pxa27x-mkp.c               |  229 ++++++++++++++++++++++++++++++
 3 files changed, 233 insertions(+), 4 deletions(-)
 create mode 100644 drivers/input/pxa27x-mkp.c

diff --git a/arch/arm/include/asm/arch-pxa/pxa-regs.h b/arch/arm/include/asm/arch-pxa/pxa-regs.h
index b81b42c..2886905 100644
--- a/arch/arm/include/asm/arch-pxa/pxa-regs.h
+++ b/arch/arm/include/asm/arch-pxa/pxa-regs.h
@@ -2574,10 +2574,8 @@ typedef void		(*ExcpHndlr) (void) ;
 #define KPREC		0x41500010 /* Keypad Intefcace Rotary Encoder register */
 #define KPMK		0x41500018 /* Keypad Intefcace Matrix Key register */
 #define KPAS		0x41500020 /* Keypad Interface Automatic Scan register */
-#define KPASMKP0	0x41500028 /* Keypad Interface Automatic Scan Multiple Key Presser register 0 */
-#define KPASMKP1	0x41500030 /* Keypad Interface Automatic Scan Multiple Key Presser register 1 */
-#define KPASMKP2	0x41500038 /* Keypad Interface Automatic Scan Multiple Key Presser register 2 */
-#define KPASMKP3	0x41500040 /* Keypad Interface Automatic Scan Multiple Key Presser register 3 */
+#define KPASMKP(x)	(0x41500028 + ((x) << 3)) /* Keypad Interface Automatic Scan
+						     Multiple Key Presser registers */
 #define KPKDI		0x41500048 /* Keypad Interface Key Debounce Interval register */
 
 #define KPC_AS		(0x1 << 30)  /* Automatic Scan bit */
diff --git a/drivers/input/Makefile b/drivers/input/Makefile
index 1f4dad3..792d29d 100644
--- a/drivers/input/Makefile
+++ b/drivers/input/Makefile
@@ -31,6 +31,8 @@ COBJS-y += keyboard.o pc_keyb.o
 COBJS-$(CONFIG_PS2MULT) += ps2mult.o ps2ser.o
 endif
 
+COBJS-$(CONFIG_PXA27X_MKP) += pxa27x-mkp.o
+
 COBJS	:= $(COBJS-y)
 SRCS	:= $(COBJS:.o=.c)
 OBJS	:= $(addprefix $(obj),$(COBJS))
diff --git a/drivers/input/pxa27x-mkp.c b/drivers/input/pxa27x-mkp.c
new file mode 100644
index 0000000..cf59496
--- /dev/null
+++ b/drivers/input/pxa27x-mkp.c
@@ -0,0 +1,229 @@
+/*
+ * PXA27x matrix keypad controller driver
+ *
+ * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * 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 of
+ * the License, or (at your option) any later version.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <stdio_dev.h>
+#include <asm/arch/pxa-regs.h>
+#include <asm/io.h>
+
+#define	DEVNAME		"pxa27x-mkp"
+
+struct {
+	char	row;
+	char	col;
+	char	key;
+	char	shift;
+	char	alt;
+	char	ctrl;
+} keymap[] = {
+	CONFIG_PXA27X_MKP_KEYMAP,
+};
+
+static unsigned char queue[64] = {0};
+static int queue_len;
+
+/* autorepeat stuff */
+static unsigned char last_key = 0xff;
+static char key_counter;
+
+/* number of key scans before autorepeat kicks in */
+#define	KEY_REPEAT_FIRST	12
+#define	KEY_REPEAT_NEXT		2
+
+enum {
+	MOD_NONE,
+	MOD_SHIFT,
+	MOD_ALT,
+	MOD_CTRL,
+};
+
+static int kbd_get_mdf(int row, int col)
+{
+	char mod_shift[2] = CONFIG_PXA27X_MKP_MOD_SHIFT;
+	char mod_alt[2] = CONFIG_PXA27X_MKP_MOD_ALT;
+	char mod_ctrl[2] = CONFIG_PXA27X_MKP_MOD_CTRL;
+
+	if (mod_shift[0] == row && mod_shift[1] == col)
+		return MOD_SHIFT;
+	if (mod_alt[0] == row && mod_alt[1] == col)
+		return MOD_ALT;
+	if (mod_ctrl[0] == row && mod_ctrl[1] == col)
+		return MOD_CTRL;
+	return MOD_NONE;
+}
+
+static void kbd_lookup(int row, int col, int mod)
+{
+	int i = 0;
+
+	while (!(keymap[i].col == 0xff && keymap[i].row == 0xff)) {
+		if (keymap[i].row == row && keymap[i].col == col) {
+			static char key = 0xff;
+			switch (mod) {
+			case MOD_NONE:
+				key = keymap[i].key;
+				break;
+			case MOD_SHIFT:
+				key = keymap[i].shift;
+				break;
+			case MOD_ALT:
+				key = keymap[i].alt;
+				break;
+			case MOD_CTRL:
+				key = keymap[i].ctrl;
+				break;
+			}
+			if (key != 0xff) {
+				if (key != last_key) {
+					queue[queue_len++] = key;
+					last_key = key;
+					key_counter = 0;
+				} else /* same key as before */
+					if (key_counter < KEY_REPEAT_FIRST) {
+						/* ignore key press */
+						key_counter++;
+					} else {
+						/* ok, autorepeat */
+						queue[queue_len++] = key;
+						key_counter = KEY_REPEAT_FIRST
+							- KEY_REPEAT_NEXT;
+					}
+			}
+		}
+		i++;
+	}
+}
+
+static void scan_keys(int modif)
+{
+	uint32_t reg;
+	int col, row;
+	int mod = MOD_NONE;
+	for (col = 0; col < 8; col += 2) {
+		while ((reg = readl(KPASMKP(col >> 1))) & KPASMKPx_SO);
+		for (row = 0; row < 8; row++) {
+			if (reg & (1 << row)) {
+				if (modif) {
+					mod = kbd_get_mdf(row, col);
+					if (mod != MOD_NONE)
+						return;
+				} else
+					kbd_lookup(row, col, mod);
+			}
+			if ((reg >> 16) & (1 << row)) {
+				if (modif) {
+					mod = kbd_get_mdf(row, col + 1);
+					if (mod != MOD_NONE)
+						return;
+				} else
+					kbd_lookup(row, col + 1, mod);
+			}
+		}
+	}
+}
+
+static void kbd_read(void)
+{
+	uint32_t reg;
+	int col, row;
+	int modif = 0;
+	int numkeys;
+	int mod = MOD_NONE;
+	writel(readl(KPC) | KPC_AS, KPC); /* start one automatic scan */
+	while (readl(KPC) & KPC_AS); /* wait for scan to finish */
+
+	numkeys = (readl(KPAS) >> 26) & 0x1f;
+	switch (numkeys) {
+	case 0:
+		/* no key pressed, clear autorepeat counter */
+		last_key = 0xff;
+		key_counter = 0;
+		break;
+	case 1:
+		reg = readl(KPAS) & 0xff;
+		col = reg & 0x0f;
+		row = reg >> 4;
+		if (kbd_get_mdf(row, col) != MOD_NONE) {
+			/* modifier only */
+			last_key = 0xff;
+			/* no real key, clear autorepeat counter */
+			key_counter = 0;
+		} else
+			kbd_lookup(row, col, mod);
+		break;
+	default:
+		/* multiple keys pressed, check KPASMKPx registers */
+		/* First scan for modifiers */
+		scan_keys(1);
+		/* Second for other keys */
+		scan_keys(0);
+		break;
+	}
+}
+
+static int kbd_getc(void)
+{
+	if (!queue_len) {
+		kbd_read();
+		udelay(CONFIG_PXA27X_MKP_DELAY);
+	}
+
+	if (queue_len)
+		return queue[--queue_len];
+	else
+		return 0;
+}
+
+static int kbd_testc(void)
+{
+	if (!queue_len)
+		kbd_read();
+	return queue_len;
+}
+
+int drv_keyboard_init(void)
+{
+	int error = 0;
+	struct stdio_dev kbddev;
+	if (!keymap)
+		return -1;
+
+	queue_len = 0;
+
+	writel((CONFIG_PXA27X_MKP_MKP_ROWS << 26) |
+		(CONFIG_PXA27X_MKP_MKP_COLS << 23) |
+		(0xff << 13) | KPC_ME, KPC);
+	writel(CONFIG_PXA27X_MKP_DEBOUNCE, KPKDI);
+
+	memset(&kbddev, 0, sizeof(kbddev));
+	strcpy(kbddev.name, DEVNAME);
+	kbddev.flags =  DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM;
+	kbddev.putc = NULL ;
+	kbddev.puts = NULL ;
+	kbddev.getc = kbd_getc ;
+	kbddev.tstc = kbd_testc ;
+
+	error = stdio_register(&kbddev);
+	return error;
+}
-- 
1.7.8.3

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

* [U-Boot] [PATCH 2/4] zipitz2: enable pxa27x_mkp driver
  2012-01-09 13:01 [U-Boot] [PATCH 1/4] PXA: PXA27x Matrix keypad driver Vasily Khoruzhick
@ 2012-01-09 13:01 ` Vasily Khoruzhick
  2012-01-09 13:13   ` Marek Vasut
  2012-01-09 13:01 ` [U-Boot] [PATCH 3/4] zipitz2: use pxa_mmc_gen as MMC driver Vasily Khoruzhick
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Vasily Khoruzhick @ 2012-01-09 13:01 UTC (permalink / raw)
  To: u-boot

Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
---
 include/configs/zipitz2.h |   83 ++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 78 insertions(+), 5 deletions(-)

diff --git a/include/configs/zipitz2.h b/include/configs/zipitz2.h
index 26204af..5560bef 100644
--- a/include/configs/zipitz2.h
+++ b/include/configs/zipitz2.h
@@ -80,6 +80,13 @@
 #define	CONFIG_CMD_MMC
 #define	CONFIG_CMD_SPI
 
+#define	CONFIG_EXTRA_ENV_SETTINGS					\
+	"stdout=lcd\0"						\
+	"stdin=pxa27x-mkp\0"						\
+	"stderr=lcd\0"							\
+	"usbtty=cdc_acm\0"						\
+	""
+#define	CONFIG_KEYBOARD
 /*
  * MMC Card Configuration
  */
@@ -206,15 +213,81 @@ unsigned char zipitz2_spi_read(void);
 #define CONFIG_SYS_FLASH_PROTECTION
 
 /*
+ * Matrix keypad
+ */
+#ifdef	CONFIG_KEYBOARD
+#define	CONFIG_PXA27X_MKP
+
+#define	CONFIG_PXA27X_MKP_MKP_COLS	7
+#define	CONFIG_PXA27X_MKP_MKP_ROWS	6
+
+#define	CONFIG_PXA27X_MKP_DEBOUNCE	30
+#define	CONFIG_PXA27X_MKP_DELAY		30000
+
+#define	CONFIG_PXA27X_MKP_MOD_SHIFT	{5, 3}
+#define	CONFIG_PXA27X_MKP_MOD_ALT	{5, 2}
+#define	CONFIG_PXA27X_MKP_MOD_CTRL	{5, 4}
+
+#define	CONFIG_PXA27X_MKP_KEYMAP		\
+	{ 1, 1, 'q', 'Q', '1', 0xff },		\
+	{ 2, 1, 'i', 'I', '8', 0xff },		\
+	{ 3, 1, 'g', 'G', '\"', 0xff },		\
+	{ 4, 1, 'x', 'X', '/', 0xff },		\
+	{ 5, 1, '\r', 0xff, 0xff, 0xff },	\
+	{ 6, 1, '-', 0xff, 0xff, 0xff },	\
+	\
+	{ 1, 2, 'w', 'W', '2', 0xff },		\
+	{ 2, 2, 'o', 'O', '9', 0xff },		\
+	{ 3, 2, 'h', 'H', '\'', 0xff },		\
+	{ 4, 2, 'c', 'C', '+', 0xff },		\
+	\
+	{ 1, 3, 'e', 'E', '3', 0xff },		\
+	{ 2, 3, 'p', 'P', '0', 0xff },		\
+	{ 3, 3, 'j', 'J', '[', 0xff },		\
+	{ 4, 3, 'v', 'V', '*', 0xff },		\
+	\
+	{ 0, 4, '\e', 0xff, '|', 0xff },	\
+	{ 1, 4, 'r', 'R', '4', 0xff },		\
+	{ 2, 4, 'a', 'A', '$', 0xff },		\
+	{ 3, 4, 'k', 'K', ']', 0xff },		\
+	{ 4, 4, 'b', 'B', '=', 0xff },		\
+						\
+	{ 0, 5, '\t', 0xff, 0xff, 0xff },	\
+	{ 1, 5, 't', 'T', '5', 0xff },		\
+	{ 2, 5, 's', 'S', '#', 0xff },		\
+	{ 3, 5, 'l', 'L', '-', 0xff },		\
+	{ 4, 5, 'n', 'N', '_', 0xff },		\
+	{ 5, 5, ' ', 0xff, 0xff, 0xff },	\
+	\
+	{ 1, 6, 'y', 'Y', '6', 0xff },		\
+	{ 2, 6, 'd', 'D', '&', 0xff },		\
+	{ 3, 6, '\b', 0xff, '\\', 0xff },	\
+	{ 4, 6, 'm', 'M', '?', 0xff },		\
+	{ 5, 6, ',', '(', '<', '{' },	\
+						\
+	{ 1, 7, 'u', 'U', '7', 0xff },		\
+	{ 2, 7, 'f', 'F', '@', 0xff },		\
+	{ 3, 7, 'z', 'Z', '!', 0xff },		\
+	{ 4, 7, ';', '~', ':', 0xff },		\
+	{ 5, 7, '.', ')', '>', '}' },	\
+						\
+	{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }
+
+#define	CONFIG_SYS_CONSOLE_ENV_OVERWRITE
+#define	CONFIG_SYS_CONSOLE_IS_IN_ENV
+
+#endif
+
+/*
  * GPIO settings
  */
 #define CONFIG_SYS_GAFR0_L_VAL	0x02000140
-#define CONFIG_SYS_GAFR0_U_VAL	0x59188000
-#define CONFIG_SYS_GAFR1_L_VAL	0x63900002
+#define CONFIG_SYS_GAFR0_U_VAL	0x59188005
+#define CONFIG_SYS_GAFR1_L_VAL	0x639420a2
 #define CONFIG_SYS_GAFR1_U_VAL	0xaaa03950
 #define CONFIG_SYS_GAFR2_L_VAL	0x0aaaaaaa
 #define CONFIG_SYS_GAFR2_U_VAL	0x29000308
-#define CONFIG_SYS_GAFR3_L_VAL	0x54000000
+#define CONFIG_SYS_GAFR3_L_VAL	0x56aa9500
 #define CONFIG_SYS_GAFR3_U_VAL	0x000000d5
 #define CONFIG_SYS_GPCR0_VAL	0x00000000
 #define CONFIG_SYS_GPCR1_VAL	0x00000020
@@ -222,7 +295,7 @@ unsigned char zipitz2_spi_read(void);
 #define CONFIG_SYS_GPCR3_VAL	0x00000000
 #define CONFIG_SYS_GPDR0_VAL	0xdafcee00
 #define CONFIG_SYS_GPDR1_VAL	0xffa3aaab
-#define CONFIG_SYS_GPDR2_VAL	0x8fe9ffff
+#define CONFIG_SYS_GPDR2_VAL	0x8fe1ffff
 #define CONFIG_SYS_GPDR3_VAL	0x001b1f8a
 #define CONFIG_SYS_GPSR0_VAL	0x06080400
 #define CONFIG_SYS_GPSR1_VAL	0x007f0000
@@ -234,7 +307,7 @@ unsigned char zipitz2_spi_read(void);
 /*
  * Clock settings
  */
-#define CONFIG_SYS_CKEN		0x00511220
+#define CONFIG_SYS_CKEN		0x00591220
 #define CONFIG_SYS_CCCR		0x00000190
 
 /*
-- 
1.7.8.3

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

* [U-Boot] [PATCH 3/4] zipitz2: use pxa_mmc_gen as MMC driver
  2012-01-09 13:01 [U-Boot] [PATCH 1/4] PXA: PXA27x Matrix keypad driver Vasily Khoruzhick
  2012-01-09 13:01 ` [U-Boot] [PATCH 2/4] zipitz2: enable pxa27x_mkp driver Vasily Khoruzhick
@ 2012-01-09 13:01 ` Vasily Khoruzhick
  2012-01-09 13:13   ` Marek Vasut
  2012-01-09 13:01 ` [U-Boot] [PATCH 4/4] zipitz2: fix boot issue introduced by PXA low level init rework Vasily Khoruzhick
  2012-01-09 13:12 ` [U-Boot] [PATCH 1/4] PXA: PXA27x Matrix keypad driver Marek Vasut
  3 siblings, 1 reply; 8+ messages in thread
From: Vasily Khoruzhick @ 2012-01-09 13:01 UTC (permalink / raw)
  To: u-boot

Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
---
 board/zipitz2/zipitz2.c   |    8 ++++++++
 include/configs/zipitz2.h |    5 +++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/board/zipitz2/zipitz2.c b/board/zipitz2/zipitz2.c
index b093c2f..4075fb6 100644
--- a/board/zipitz2/zipitz2.c
+++ b/board/zipitz2/zipitz2.c
@@ -79,6 +79,14 @@ void dram_init_banksize(void)
 	gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
 }
 
+#ifdef	CONFIG_CMD_MMC
+int board_mmc_init(bd_t *bis)
+{
+	pxa_mmc_register(0);
+	return 0;
+}
+#endif
+
 #ifdef	CONFIG_CMD_SPI
 
 struct {
diff --git a/include/configs/zipitz2.h b/include/configs/zipitz2.h
index 5560bef..8c48d01 100644
--- a/include/configs/zipitz2.h
+++ b/include/configs/zipitz2.h
@@ -45,7 +45,7 @@
 #define	CONFIG_ARCH_CPU_INIT
 
 #define	CONFIG_BOOTCOMMAND						\
-	"if mmc init && fatload mmc 0 0xa0000000 uboot.script ; then "	\
+	"if ext2load mmc 0 0xa0000000 boot/uboot.script ; then "	\
 		"source 0xa0000000; "					\
 	"else "								\
 		"bootm 0x60000; "					\
@@ -92,7 +92,8 @@
  */
 #ifdef	CONFIG_CMD_MMC
 #define	CONFIG_MMC
-#define	CONFIG_PXA_MMC
+#define	CONFIG_GENERIC_MMC
+#define	CONFIG_PXA_MMC_GENERIC
 #define	CONFIG_SYS_MMC_BASE		0xF0000000
 #define	CONFIG_CMD_FAT
 #define CONFIG_CMD_EXT2
-- 
1.7.8.3

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

* [U-Boot] [PATCH 4/4] zipitz2: fix boot issue introduced by PXA low level init rework
  2012-01-09 13:01 [U-Boot] [PATCH 1/4] PXA: PXA27x Matrix keypad driver Vasily Khoruzhick
  2012-01-09 13:01 ` [U-Boot] [PATCH 2/4] zipitz2: enable pxa27x_mkp driver Vasily Khoruzhick
  2012-01-09 13:01 ` [U-Boot] [PATCH 3/4] zipitz2: use pxa_mmc_gen as MMC driver Vasily Khoruzhick
@ 2012-01-09 13:01 ` Vasily Khoruzhick
  2012-01-09 13:14   ` Marek Vasut
  2012-01-09 13:12 ` [U-Boot] [PATCH 1/4] PXA: PXA27x Matrix keypad driver Marek Vasut
  3 siblings, 1 reply; 8+ messages in thread
From: Vasily Khoruzhick @ 2012-01-09 13:01 UTC (permalink / raw)
  To: u-boot

CONFIG_SYS_INIT_SP_ADDR points to RAM, but it's used before
DRAM controller init. Fix it by setting CONFIG_SYS_INIT_SP_ADDR
to SRAM

Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
---
 include/configs/zipitz2.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/include/configs/zipitz2.h b/include/configs/zipitz2.h
index 8c48d01..aefe2ee 100644
--- a/include/configs/zipitz2.h
+++ b/include/configs/zipitz2.h
@@ -185,7 +185,7 @@ unsigned char zipitz2_spi_read(void);
 #define	CONFIG_SYS_LOAD_ADDR		CONFIG_SYS_DRAM_BASE
 
 #define CONFIG_SYS_SDRAM_BASE		PHYS_SDRAM_1
-#define	CONFIG_SYS_INIT_SP_ADDR		(GENERATED_GBL_DATA_SIZE + PHYS_SDRAM_1 + 2048)
+#define	CONFIG_SYS_INIT_SP_ADDR		0x5c038000
 
 /*
  * NOR FLASH
-- 
1.7.8.3

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

* [U-Boot] [PATCH 1/4] PXA: PXA27x Matrix keypad driver
  2012-01-09 13:01 [U-Boot] [PATCH 1/4] PXA: PXA27x Matrix keypad driver Vasily Khoruzhick
                   ` (2 preceding siblings ...)
  2012-01-09 13:01 ` [U-Boot] [PATCH 4/4] zipitz2: fix boot issue introduced by PXA low level init rework Vasily Khoruzhick
@ 2012-01-09 13:12 ` Marek Vasut
  3 siblings, 0 replies; 8+ messages in thread
From: Marek Vasut @ 2012-01-09 13:12 UTC (permalink / raw)
  To: u-boot

> From: Marek Vasut <marek.vasut@gmail.com>
> 
> Signed-off-by: Marek Vasut <marek.vasut@gmail.com>
> Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
> [vasily: adapted Marek's old version for newer u-boot]
> ---
>  arch/arm/include/asm/arch-pxa/pxa-regs.h |    6 +-
>  drivers/input/Makefile                   |    2 +
>  drivers/input/pxa27x-mkp.c               |  229
> ++++++++++++++++++++++++++++++ 3 files changed, 233 insertions(+), 4
> deletions(-)
>  create mode 100644 drivers/input/pxa27x-mkp.c
> 
> diff --git a/arch/arm/include/asm/arch-pxa/pxa-regs.h
> b/arch/arm/include/asm/arch-pxa/pxa-regs.h index b81b42c..2886905 100644
> --- a/arch/arm/include/asm/arch-pxa/pxa-regs.h
> +++ b/arch/arm/include/asm/arch-pxa/pxa-regs.h
> @@ -2574,10 +2574,8 @@ typedef void		(*ExcpHndlr) (void) ;
>  #define KPREC		0x41500010 /* Keypad Intefcace Rotary Encoder 
register */
>  #define KPMK		0x41500018 /* Keypad Intefcace Matrix Key register */
>  #define KPAS		0x41500020 /* Keypad Interface Automatic Scan register 
*/
> -#define KPASMKP0	0x41500028 /* Keypad Interface Automatic Scan Multiple
> Key Presser register 0 */ -#define KPASMKP1	0x41500030 /* Keypad Interface
> Automatic Scan Multiple Key Presser register 1 */ -#define
> KPASMKP2	0x41500038 /* Keypad Interface Automatic Scan Multiple Key
> Presser register 2 */ -#define KPASMKP3	0x41500040 /* Keypad Interface
> Automatic Scan Multiple Key Presser register 3 */ +#define
> KPASMKP(x)	(0x41500028 + ((x) << 3)) /* Keypad Interface Automatic Scan
> +						     Multiple Key Presser 
registers */
>  #define KPKDI		0x41500048 /* Keypad Interface Key Debounce 
Interval
> register */
> 
>  #define KPC_AS		(0x1 << 30)  /* Automatic Scan bit */

NAK, use struct based access.

> diff --git a/drivers/input/Makefile b/drivers/input/Makefile
> index 1f4dad3..792d29d 100644
> --- a/drivers/input/Makefile
> +++ b/drivers/input/Makefile
> @@ -31,6 +31,8 @@ COBJS-y += keyboard.o pc_keyb.o
>  COBJS-$(CONFIG_PS2MULT) += ps2mult.o ps2ser.o
>  endif
> 
> +COBJS-$(CONFIG_PXA27X_MKP) += pxa27x-mkp.o
> +
>  COBJS	:= $(COBJS-y)
>  SRCS	:= $(COBJS:.o=.c)
>  OBJS	:= $(addprefix $(obj),$(COBJS))
> diff --git a/drivers/input/pxa27x-mkp.c b/drivers/input/pxa27x-mkp.c
> new file mode 100644
> index 0000000..cf59496
> --- /dev/null
> +++ b/drivers/input/pxa27x-mkp.c
> @@ -0,0 +1,229 @@
> +/*
> + * PXA27x matrix keypad controller driver
> + *
> + * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com>
> + *
> + * See file CREDITS for list of people who contributed to this
> + * project.
> + *
> + * 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 of
> + * the License, or (at your option) any later version.
> + *
> + * 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, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
> + * MA 02111-1307 USA
> + */
> +
> +#include <common.h>
> +#include <stdio_dev.h>
> +#include <asm/arch/pxa-regs.h>
> +#include <asm/io.h>
> +
> +#define	DEVNAME		"pxa27x-mkp"
> +
> +struct {
> +	char	row;
> +	char	col;
> +	char	key;
> +	char	shift;
> +	char	alt;
> +	char	ctrl;
> +} keymap[] = {
> +	CONFIG_PXA27X_MKP_KEYMAP,
> +};
> +
> +static unsigned char queue[64] = {0};
> +static int queue_len;
> +
> +/* autorepeat stuff */
> +static unsigned char last_key = 0xff;
> +static char key_counter;
> +
> +/* number of key scans before autorepeat kicks in */
> +#define	KEY_REPEAT_FIRST	12
> +#define	KEY_REPEAT_NEXT		2

Make this configurable
> +
> +enum {
> +	MOD_NONE,
> +	MOD_SHIFT,
> +	MOD_ALT,
> +	MOD_CTRL,
> +};
> +
> +static int kbd_get_mdf(int row, int col)
> +{
> +	char mod_shift[2] = CONFIG_PXA27X_MKP_MOD_SHIFT;
> +	char mod_alt[2] = CONFIG_PXA27X_MKP_MOD_ALT;
> +	char mod_ctrl[2] = CONFIG_PXA27X_MKP_MOD_CTRL;
> +
> +	if (mod_shift[0] == row && mod_shift[1] == col)
> +		return MOD_SHIFT;
> +	if (mod_alt[0] == row && mod_alt[1] == col)
> +		return MOD_ALT;
> +	if (mod_ctrl[0] == row && mod_ctrl[1] == col)
> +		return MOD_CTRL;
> +	return MOD_NONE;
> +}
> +
> +static void kbd_lookup(int row, int col, int mod)
> +{
> +	int i = 0;
> +
> +	while (!(keymap[i].col == 0xff && keymap[i].row == 0xff)) {
> +		if (keymap[i].row == row && keymap[i].col == col) {
> +			static char key = 0xff;

Don't declare this here

> +			switch (mod) {
> +			case MOD_NONE:
> +				key = keymap[i].key;
> +				break;
> +			case MOD_SHIFT:
> +				key = keymap[i].shift;
> +				break;
> +			case MOD_ALT:
> +				key = keymap[i].alt;
> +				break;
> +			case MOD_CTRL:
> +				key = keymap[i].ctrl;
> +				break;
> +			}

if (key == 0xff)
 continue;

Shift the rest of the stuff to the left by one tab.

> +			if (key != 0xff) {
> +				if (key != last_key) {
> +					queue[queue_len++] = key;
> +					last_key = key;
> +					key_counter = 0;
> +				} else /* same key as before */
> +					if (key_counter < KEY_REPEAT_FIRST) {
> +						/* ignore key press */
> +						key_counter++;
> +					} else {
> +						/* ok, autorepeat */
> +						queue[queue_len++] = key;
> +						key_counter = KEY_REPEAT_FIRST
> +							- KEY_REPEAT_NEXT;
> +					}
> +			}
> +		}
> +		i++;
> +	}
> +}
> +
> +static void scan_keys(int modif)
> +{
> +	uint32_t reg;
> +	int col, row;
> +	int mod = MOD_NONE;
> +	for (col = 0; col < 8; col += 2) {
> +		while ((reg = readl(KPASMKP(col >> 1))) & KPASMKPx_SO);

; on new line

> +		for (row = 0; row < 8; row++) {
> +			if (reg & (1 << row)) {
> +				if (modif) {
> +					mod = kbd_get_mdf(row, col);
> +					if (mod != MOD_NONE)
> +						return;
> +				} else
> +					kbd_lookup(row, col, mod);
> +			}
> +			if ((reg >> 16) & (1 << row)) {
> +				if (modif) {
> +					mod = kbd_get_mdf(row, col + 1);
> +					if (mod != MOD_NONE)
> +						return;
> +				} else
> +					kbd_lookup(row, col + 1, mod);
> +			}
> +		}
> +	}
> +}
> +
> +static void kbd_read(void)
> +{
> +	uint32_t reg;
> +	int col, row;
> +	int modif = 0;
> +	int numkeys;
> +	int mod = MOD_NONE;
> +	writel(readl(KPC) | KPC_AS, KPC); /* start one automatic scan */
> +	while (readl(KPC) & KPC_AS); /* wait for scan to finish */
> +
> +	numkeys = (readl(KPAS) >> 26) & 0x1f;
> +	switch (numkeys) {
> +	case 0:
> +		/* no key pressed, clear autorepeat counter */
> +		last_key = 0xff;
> +		key_counter = 0;
> +		break;
> +	case 1:
> +		reg = readl(KPAS) & 0xff;
> +		col = reg & 0x0f;
> +		row = reg >> 4;
> +		if (kbd_get_mdf(row, col) != MOD_NONE) {
> +			/* modifier only */
> +			last_key = 0xff;
> +			/* no real key, clear autorepeat counter */
> +			key_counter = 0;
> +		} else
> +			kbd_lookup(row, col, mod);
> +		break;
> +	default:
> +		/* multiple keys pressed, check KPASMKPx registers */
> +		/* First scan for modifiers */
> +		scan_keys(1);
> +		/* Second for other keys */
> +		scan_keys(0);
> +		break;
> +	}
> +}
> +
> +static int kbd_getc(void)
> +{
> +	if (!queue_len) {
> +		kbd_read();
> +		udelay(CONFIG_PXA27X_MKP_DELAY);
> +	}
> +
> +	if (queue_len)
> +		return queue[--queue_len];
> +	else
> +		return 0;
> +}
> +
> +static int kbd_testc(void)
> +{
> +	if (!queue_len)
> +		kbd_read();
> +	return queue_len;
> +}
> +
> +int drv_keyboard_init(void)
> +{
> +	int error = 0;
> +	struct stdio_dev kbddev;
> +	if (!keymap)
> +		return -1;
> +
> +	queue_len = 0;
> +
> +	writel((CONFIG_PXA27X_MKP_MKP_ROWS << 26) |
> +		(CONFIG_PXA27X_MKP_MKP_COLS << 23) |
> +		(0xff << 13) | KPC_ME, KPC);
> +	writel(CONFIG_PXA27X_MKP_DEBOUNCE, KPKDI);
> +
> +	memset(&kbddev, 0, sizeof(kbddev));
> +	strcpy(kbddev.name, DEVNAME);
> +	kbddev.flags =  DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM;
> +	kbddev.putc = NULL ;
> +	kbddev.puts = NULL ;
> +	kbddev.getc = kbd_getc ;
> +	kbddev.tstc = kbd_testc ;
> +
> +	error = stdio_register(&kbddev);
> +	return error;
> +}

This really needs cleanup. I'm somewhat ashamed I hacked together such a code :)

M

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

* [U-Boot] [PATCH 2/4] zipitz2: enable pxa27x_mkp driver
  2012-01-09 13:01 ` [U-Boot] [PATCH 2/4] zipitz2: enable pxa27x_mkp driver Vasily Khoruzhick
@ 2012-01-09 13:13   ` Marek Vasut
  0 siblings, 0 replies; 8+ messages in thread
From: Marek Vasut @ 2012-01-09 13:13 UTC (permalink / raw)
  To: u-boot

> Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
> ---
>  include/configs/zipitz2.h |   83
> ++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 78
> insertions(+), 5 deletions(-)
> 
> diff --git a/include/configs/zipitz2.h b/include/configs/zipitz2.h
> index 26204af..5560bef 100644
> --- a/include/configs/zipitz2.h
> +++ b/include/configs/zipitz2.h
> @@ -80,6 +80,13 @@
>  #define	CONFIG_CMD_MMC
>  #define	CONFIG_CMD_SPI
> 
> +#define	CONFIG_EXTRA_ENV_SETTINGS					
\
> +	"stdout=lcd\0"						\
> +	"stdin=pxa27x-mkp\0"						\
> +	"stderr=lcd\0"							\
> +	"usbtty=cdc_acm\0"						\

What's this "cdc_acm" stuff doing here?

> +	""
> +#define	CONFIG_KEYBOARD
>  /*
>   * MMC Card Configuration
>   */
> @@ -206,15 +213,81 @@ unsigned char zipitz2_spi_read(void);
>  #define CONFIG_SYS_FLASH_PROTECTION
> 
>  /*
> + * Matrix keypad
> + */
> +#ifdef	CONFIG_KEYBOARD
> +#define	CONFIG_PXA27X_MKP
> +
> +#define	CONFIG_PXA27X_MKP_MKP_COLS	7
> +#define	CONFIG_PXA27X_MKP_MKP_ROWS	6
> +
> +#define	CONFIG_PXA27X_MKP_DEBOUNCE	30
> +#define	CONFIG_PXA27X_MKP_DELAY		30000
> +
> +#define	CONFIG_PXA27X_MKP_MOD_SHIFT	{5, 3}
> +#define	CONFIG_PXA27X_MKP_MOD_ALT	{5, 2}
> +#define	CONFIG_PXA27X_MKP_MOD_CTRL	{5, 4}
> +
> +#define	CONFIG_PXA27X_MKP_KEYMAP		\
> +	{ 1, 1, 'q', 'Q', '1', 0xff },		\
> +	{ 2, 1, 'i', 'I', '8', 0xff },		\
> +	{ 3, 1, 'g', 'G', '\"', 0xff },		\
> +	{ 4, 1, 'x', 'X', '/', 0xff },		\
> +	{ 5, 1, '\r', 0xff, 0xff, 0xff },	\
> +	{ 6, 1, '-', 0xff, 0xff, 0xff },	\
> +	\
> +	{ 1, 2, 'w', 'W', '2', 0xff },		\
> +	{ 2, 2, 'o', 'O', '9', 0xff },		\
> +	{ 3, 2, 'h', 'H', '\'', 0xff },		\
> +	{ 4, 2, 'c', 'C', '+', 0xff },		\
> +	\
> +	{ 1, 3, 'e', 'E', '3', 0xff },		\
> +	{ 2, 3, 'p', 'P', '0', 0xff },		\
> +	{ 3, 3, 'j', 'J', '[', 0xff },		\
> +	{ 4, 3, 'v', 'V', '*', 0xff },		\
> +	\
> +	{ 0, 4, '\e', 0xff, '|', 0xff },	\
> +	{ 1, 4, 'r', 'R', '4', 0xff },		\
> +	{ 2, 4, 'a', 'A', '$', 0xff },		\
> +	{ 3, 4, 'k', 'K', ']', 0xff },		\
> +	{ 4, 4, 'b', 'B', '=', 0xff },		\
> +						\
> +	{ 0, 5, '\t', 0xff, 0xff, 0xff },	\
> +	{ 1, 5, 't', 'T', '5', 0xff },		\
> +	{ 2, 5, 's', 'S', '#', 0xff },		\
> +	{ 3, 5, 'l', 'L', '-', 0xff },		\
> +	{ 4, 5, 'n', 'N', '_', 0xff },		\
> +	{ 5, 5, ' ', 0xff, 0xff, 0xff },	\
> +	\
> +	{ 1, 6, 'y', 'Y', '6', 0xff },		\
> +	{ 2, 6, 'd', 'D', '&', 0xff },		\
> +	{ 3, 6, '\b', 0xff, '\\', 0xff },	\
> +	{ 4, 6, 'm', 'M', '?', 0xff },		\
> +	{ 5, 6, ',', '(', '<', '{' },	\
> +						\
> +	{ 1, 7, 'u', 'U', '7', 0xff },		\
> +	{ 2, 7, 'f', 'F', '@', 0xff },		\
> +	{ 3, 7, 'z', 'Z', '!', 0xff },		\
> +	{ 4, 7, ';', '~', ':', 0xff },		\
> +	{ 5, 7, '.', ')', '>', '}' },	\
> +						\
> +	{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }

Eerie ... let's see what the others think

> +
> +#define	CONFIG_SYS_CONSOLE_ENV_OVERWRITE
> +#define	CONFIG_SYS_CONSOLE_IS_IN_ENV
> +
> +#endif
> +
> +/*
>   * GPIO settings
>   */
>  #define CONFIG_SYS_GAFR0_L_VAL	0x02000140
> -#define CONFIG_SYS_GAFR0_U_VAL	0x59188000
> -#define CONFIG_SYS_GAFR1_L_VAL	0x63900002
> +#define CONFIG_SYS_GAFR0_U_VAL	0x59188005
> +#define CONFIG_SYS_GAFR1_L_VAL	0x639420a2
>  #define CONFIG_SYS_GAFR1_U_VAL	0xaaa03950
>  #define CONFIG_SYS_GAFR2_L_VAL	0x0aaaaaaa
>  #define CONFIG_SYS_GAFR2_U_VAL	0x29000308
> -#define CONFIG_SYS_GAFR3_L_VAL	0x54000000
> +#define CONFIG_SYS_GAFR3_L_VAL	0x56aa9500
>  #define CONFIG_SYS_GAFR3_U_VAL	0x000000d5
>  #define CONFIG_SYS_GPCR0_VAL	0x00000000
>  #define CONFIG_SYS_GPCR1_VAL	0x00000020
> @@ -222,7 +295,7 @@ unsigned char zipitz2_spi_read(void);
>  #define CONFIG_SYS_GPCR3_VAL	0x00000000
>  #define CONFIG_SYS_GPDR0_VAL	0xdafcee00
>  #define CONFIG_SYS_GPDR1_VAL	0xffa3aaab
> -#define CONFIG_SYS_GPDR2_VAL	0x8fe9ffff
> +#define CONFIG_SYS_GPDR2_VAL	0x8fe1ffff
>  #define CONFIG_SYS_GPDR3_VAL	0x001b1f8a
>  #define CONFIG_SYS_GPSR0_VAL	0x06080400
>  #define CONFIG_SYS_GPSR1_VAL	0x007f0000
> @@ -234,7 +307,7 @@ unsigned char zipitz2_spi_read(void);
>  /*
>   * Clock settings
>   */
> -#define CONFIG_SYS_CKEN		0x00511220
> +#define CONFIG_SYS_CKEN		0x00591220
>  #define CONFIG_SYS_CCCR		0x00000190
> 
>  /*

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

* [U-Boot] [PATCH 3/4] zipitz2: use pxa_mmc_gen as MMC driver
  2012-01-09 13:01 ` [U-Boot] [PATCH 3/4] zipitz2: use pxa_mmc_gen as MMC driver Vasily Khoruzhick
@ 2012-01-09 13:13   ` Marek Vasut
  0 siblings, 0 replies; 8+ messages in thread
From: Marek Vasut @ 2012-01-09 13:13 UTC (permalink / raw)
  To: u-boot

> Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
> ---
>  board/zipitz2/zipitz2.c   |    8 ++++++++
>  include/configs/zipitz2.h |    5 +++--
>  2 files changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/board/zipitz2/zipitz2.c b/board/zipitz2/zipitz2.c
> index b093c2f..4075fb6 100644
> --- a/board/zipitz2/zipitz2.c
> +++ b/board/zipitz2/zipitz2.c
> @@ -79,6 +79,14 @@ void dram_init_banksize(void)
>  	gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
>  }
> 
> +#ifdef	CONFIG_CMD_MMC
> +int board_mmc_init(bd_t *bis)
> +{
> +	pxa_mmc_register(0);
> +	return 0;
> +}
> +#endif
> +
>  #ifdef	CONFIG_CMD_SPI
> 
>  struct {
> diff --git a/include/configs/zipitz2.h b/include/configs/zipitz2.h
> index 5560bef..8c48d01 100644
> --- a/include/configs/zipitz2.h
> +++ b/include/configs/zipitz2.h
> @@ -45,7 +45,7 @@
>  #define	CONFIG_ARCH_CPU_INIT
> 
>  #define	CONFIG_BOOTCOMMAND						
\
> -	"if mmc init && fatload mmc 0 0xa0000000 uboot.script ; then "	\
> +	"if ext2load mmc 0 0xa0000000 boot/uboot.script ; then "	\
>  		"source 0xa0000000; "					\

Aren't you missing "mmc rescan" or something ?

>  	"else "								\
>  		"bootm 0x60000; "					\
> @@ -92,7 +92,8 @@
>   */
>  #ifdef	CONFIG_CMD_MMC
>  #define	CONFIG_MMC
> -#define	CONFIG_PXA_MMC
> +#define	CONFIG_GENERIC_MMC
> +#define	CONFIG_PXA_MMC_GENERIC
>  #define	CONFIG_SYS_MMC_BASE		0xF0000000
>  #define	CONFIG_CMD_FAT
>  #define CONFIG_CMD_EXT2

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

* [U-Boot] [PATCH 4/4] zipitz2: fix boot issue introduced by PXA low level init rework
  2012-01-09 13:01 ` [U-Boot] [PATCH 4/4] zipitz2: fix boot issue introduced by PXA low level init rework Vasily Khoruzhick
@ 2012-01-09 13:14   ` Marek Vasut
  0 siblings, 0 replies; 8+ messages in thread
From: Marek Vasut @ 2012-01-09 13:14 UTC (permalink / raw)
  To: u-boot

> CONFIG_SYS_INIT_SP_ADDR points to RAM, but it's used before
> DRAM controller init. Fix it by setting CONFIG_SYS_INIT_SP_ADDR
> to SRAM
> 
> Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
> ---
>  include/configs/zipitz2.h |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/include/configs/zipitz2.h b/include/configs/zipitz2.h
> index 8c48d01..aefe2ee 100644
> --- a/include/configs/zipitz2.h
> +++ b/include/configs/zipitz2.h
> @@ -185,7 +185,7 @@ unsigned char zipitz2_spi_read(void);
>  #define	CONFIG_SYS_LOAD_ADDR		CONFIG_SYS_DRAM_BASE
> 
>  #define CONFIG_SYS_SDRAM_BASE		PHYS_SDRAM_1
> -#define	CONFIG_SYS_INIT_SP_ADDR		(GENERATED_GBL_DATA_SIZE + 
PHYS_SDRAM_1 +
> 2048) +#define	CONFIG_SYS_INIT_SP_ADDR		0x5c038000

You might as well only change PHYS_SDRAM1_SIZE to PHYS_SRAM_SIZE and don't 
invent arbitrary addresses?

M
> 
>  /*
>   * NOR FLASH

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

end of thread, other threads:[~2012-01-09 13:14 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-09 13:01 [U-Boot] [PATCH 1/4] PXA: PXA27x Matrix keypad driver Vasily Khoruzhick
2012-01-09 13:01 ` [U-Boot] [PATCH 2/4] zipitz2: enable pxa27x_mkp driver Vasily Khoruzhick
2012-01-09 13:13   ` Marek Vasut
2012-01-09 13:01 ` [U-Boot] [PATCH 3/4] zipitz2: use pxa_mmc_gen as MMC driver Vasily Khoruzhick
2012-01-09 13:13   ` Marek Vasut
2012-01-09 13:01 ` [U-Boot] [PATCH 4/4] zipitz2: fix boot issue introduced by PXA low level init rework Vasily Khoruzhick
2012-01-09 13:14   ` Marek Vasut
2012-01-09 13:12 ` [U-Boot] [PATCH 1/4] PXA: PXA27x Matrix keypad driver Marek Vasut

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox