Skip to contentSkip to conversation

PXA: PXA27x Matrix keypad driver

PATCH Superseded Vasily Khoruzhick 2 participants 11 messages Jan 13, 2012

Subsystems (2)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/4 PXA: PXA27x Matrix keypad driver

From: Marek Vasut <[email protected]>

[vasily: adapted Marek's old version for newer u-boot,
fixed multiple keypresses handling]
---
v2: use struct-based access to regs, minor cleanup
v3: fix multiple keypresses handling, minor cleanup

 arch/arm/include/asm/arch-pxa/pxa-regs.h    |   52 -----
 arch/arm/include/asm/arch-pxa/regs-keypad.h |   84 ++++++++
 drivers/input/Makefile                      |    2 +
 drivers/input/pxa27x-mkp.c                  |  301 +++++++++++++++++++++++++++
 4 files changed, 387 insertions(+), 52 deletions(-)
 create mode 100644 arch/arm/include/asm/arch-pxa/regs-keypad.h
 create mode 100644 drivers/input/pxa27x-mkp.c
arch/arm/include/asm/arch-pxa/pxa-regs.h +0 -52
index b81b42c..d562658 100644
@@ -2567,58 +2567,6 @@ typedef void		(*ExcpHndlr) (void) ;
 #define OVL2C1_O2EN	(1<<31)		/* Enable bit for Overlay 2 */
 #define CCR_CEN		(1<<31)		/* Enable bit for Cursor */
 
-/* Keypad controller */
-
-#define KPC		0x41500000 /* Keypad Interface Control register */
-#define KPDK		0x41500008 /* Keypad Interface Direct Key register */
-#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 KPKDI		0x41500048 /* Keypad Interface Key Debounce Interval register */
-
-#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 Key Debounce select */
-#define KPC_DI		(0x1 <<	 5)  /* Direct key interrupt bit */
-#define KPC_DEE0	(0x1 <<	 2)  /* Rotary Encoder 0 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 GPIO113_BIT	(1 << 17)/* GPIO113 in GPSR, GPCR, bit 17 */
 #define PSLR		0x40F00034
 #define PSTR		0x40F00038  /* Power Manager Standby Configuration Reg */
arch/arm/include/asm/arch-pxa/regs-keypad.h new file +84 -0

84 lines not on this page · raw message

drivers/input/Makefile +2 -0
index 1f4dad3..792d29d 100644
@@ -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))
drivers/input/pxa27x-mkp.c new file +301 -0

301 lines not on this page · raw message

Signature · 1 line
1.7.8.3
#1 lore raw

PATCH v3 2/4 zipitz2: enable pxa27x_mkp driver

---
v2: remove usbtty stuff from EXTRA_ENV_SETTINGS
v3: shift+backspace should produce backspace code

 include/configs/zipitz2.h |   82 ++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 77 insertions(+), 5 deletions(-)
include/configs/zipitz2.h +77 -5
index 26204af..76054af 100644
@@ -80,6 +80,12 @@
 #define	CONFIG_CMD_MMC
 #define	CONFIG_CMD_SPI
 
+#define	CONFIG_EXTRA_ENV_SETTINGS					\
+	"stdout=lcd\0"							\
+	"stdin=pxa27x-mkp\0"						\
+	"stderr=lcd\0"							\
+	""
+#define	CONFIG_KEYBOARD
 /*
  * MMC Card Configuration
  */
@@ -206,15 +212,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', '\b', '\\', 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 +294,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 +306,7 @@ unsigned char zipitz2_spi_read(void);
 /*
  * Clock settings
  */
-#define CONFIG_SYS_CKEN		0x00511220
+#define CONFIG_SYS_CKEN		0x00591220
 #define CONFIG_SYS_CCCR		0x00000190
 
 /*
Signature · 1 line
1.7.8.3
#2 lore raw

PATCH v3 3/4 zipitz2: use pxa_mmc_gen as MMC driver

In reply to Vasily Khoruzhick

---
v2: mmcinfo is necessary to scan card for partitions
v3: replace mmcinfo with mmc rescan

 board/zipitz2/zipitz2.c   |    8 ++++++++
 include/configs/zipitz2.h |   14 ++++++++------
 2 files changed, 16 insertions(+), 6 deletions(-)
board/zipitz2/zipitz2.c +8 -0
index b093c2f..4075fb6 100644
@@ -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 {
include/configs/zipitz2.h +8 -6
index 76054af..4f48d9b 100644
@@ -44,11 +44,12 @@
 #define	CONFIG_SYS_MALLOC_LEN		(128*1024)
 #define	CONFIG_ARCH_CPU_INIT
 
-#define	CONFIG_BOOTCOMMAND						\
-	"if mmc init && fatload mmc 0 0xa0000000 uboot.script ; then "	\
-		"source 0xa0000000; "					\
-	"else "								\
-		"bootm 0x60000; "					\
+#define	CONFIG_BOOTCOMMAND						   \
+	"if mmc rescan 0 && ext2load mmc 0 0xa0000000 boot/uboot.script ;" \
+	"then "								   \
+		"source 0xa0000000; "					   \
+	"else "								   \
+		"bootm 0x60000; "					   \
 	"fi; "
 #define	CONFIG_BOOTARGS							\
 	"console=tty0 console=ttyS2,115200 fbcon=rotate:3"
@@ -91,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
Signature · 1 line
1.7.8.3
#3 lore raw

PATCH v3 3/4 zipitz2: use pxa_mmc_gen as MMC driver

Quoted 33 lines

---
v2: mmcinfo is necessary to scan card for partitions
v3: replace mmcinfo with mmc rescan

 board/zipitz2/zipitz2.c   |    8 ++++++++
 include/configs/zipitz2.h |   14 ++++++++------
 2 files changed, 16 insertions(+), 6 deletions(-)
board/zipitz2/zipitz2.c +8 -0
index b093c2f..4075fb6 100644
@@ -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 {
include/configs/zipitz2.h +0 -0
index 76054af..4f48d9b 100644

include/configs/zipitz2.h line 47

Quoted 4 lines
include/configs/zipitz2.h +0 -1
@@ -44,11 +44,12 @@
 #define	CONFIG_SYS_MALLOC_LEN		(128*1024)
 #define	CONFIG_ARCH_CPU_INIT
 
-#define	CONFIG_BOOTCOMMAND						

\

include/configs/zipitz2.h

Quoted 5 lines
include/configs/zipitz2.h +1 -4
-	"if mmc init && fatload mmc 0 0xa0000000 uboot.script ; then "	\
-		"source 0xa0000000; "					\
-	"else "								\
-		"bootm 0x60000; "					\
+#define	CONFIG_BOOTCOMMAND						   

\

include/configs/zipitz2.h line 48

Quoted 1 line
include/configs/zipitz2.h +1 -0
+	"if mmc rescan 0 && ext2load mmc 0 0xa0000000 boot/uboot.script ;" \

Why "mmc rescan 0" ?

include/configs/zipitz2.h

Quoted 6 lines
include/configs/zipitz2.h +4 -0
+	"then "								   \
+		"source 0xa0000000; "					   \
+	"else "								   \
+		"bootm 0x60000; "					   \
 	"fi; "
 #define	CONFIG_BOOTARGS							

\

Quoted 11 lines
include/configs/zipitz2.h +2 -1
 	"console=tty0 console=ttyS2,115200 fbcon=rotate:3"
@@ -91,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
#4 lore raw

PATCH v3 3/4 zipitz2: use pxa_mmc_gen as MMC driver

Quoted 3 lines · Marek Vasut

include/configs/zipitz2.h line 48

Quoted 1 line
include/configs/zipitz2.h +1 -0
+	"if mmc rescan 0 && ext2load mmc 0 0xa0000000 boot/uboot.script ;" \

Why "mmc rescan 0" ?

Because otherwise it does nothing to detect card and scan for partitions? 0 is mmc device index.

Regards
Vasily

#5 lore raw

PATCH v3 3/4 zipitz2: use pxa_mmc_gen as MMC driver

Quoted 7 lines · Marek Vasut
Quoted 3 lines

include/configs/zipitz2.h line 48

Quoted 1 line
include/configs/zipitz2.h +1 -0
+	"if mmc rescan 0 && ext2load mmc 0 0xa0000000 boot/uboot.script ;" \

Why "mmc rescan 0" ?

Because otherwise it does nothing to detect card and scan for partitions? 0 is mmc device index.

I see ... so mmc rescan takes such a parameter. Ok, but I can't find any evidence of it in the source code ... hmmmmmm.

Quoted 3 lines

Regards
Vasily

#6 lore raw

PATCH v3 4/4 zipitz2: fix boot issue introduced by PXA low level init rework

In reply to Vasily Khoruzhick

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

---
v2: no changes
v3: introduce PHYS_SRAM, use it for SYS_INIT_SP_ADDR calculation

 include/configs/zipitz2.h |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
include/configs/zipitz2.h +7 -1
index 4f48d9b..8add384 100644
@@ -170,6 +170,12 @@ unsigned char zipitz2_spi_read(void);
 #endif
 
 /*
+ * SRAM Map
+ */
+#define	PHYS_SRAM			0x5c000000	/* SRAM Bank #1 */
+#define	PHYS_SRAM_SIZE			0x00040000	/* 256k */
+
+/*
  * DRAM Map
  */
 #define	CONFIG_NR_DRAM_BANKS		1		/* We have 1 bank of DRAM */
@@ -185,7 +191,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		(GENERATED_GBL_DATA_SIZE + PHYS_SRAM + 2048)
 
 /*
  * NOR FLASH
Signature · 1 line
1.7.8.3
Applied
#7 lore raw

PATCH v3 4/4 zipitz2: fix boot issue introduced by PXA low level init rework

Quoted 17 lines

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

---
v2: no changes
v3: introduce PHYS_SRAM, use it for SYS_INIT_SP_ADDR calculation

 include/configs/zipitz2.h |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
include/configs/zipitz2.h +0 -0
index 4f48d9b..8add384 100644

include/configs/zipitz2.h unsigned char zipitz2_spi_read(void); · line 175

Quoted 6 lines
include/configs/zipitz2.h +3 -0
@@ -170,6 +170,12 @@ unsigned char zipitz2_spi_read(void);
 #endif
 
 /*
+ * SRAM Map
+ */
+#define	PHYS_SRAM			0x5c000000	/* SRAM Bank #1 

*/

include/configs/zipitz2.h unsigned char zipitz2_spi_read(void);

Quoted 6 lines
include/configs/zipitz2.h +3 -0
+#define	PHYS_SRAM_SIZE			0x00040000	/* 256k */
+
+/*
  * DRAM Map
  */
 #define	CONFIG_NR_DRAM_BANKS		1		/* We have 1 

bank of DRAM */

include/configs/zipitz2.h unsigned char zipitz2_spi_read(void); · line 188

Quoted 5 lines
include/configs/zipitz2.h +0 -1
@@ -185,7 +191,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 +

Quoted 1 line

2048) +#define CONFIG_SYS_INIT_SP_ADDR (GENERATED_GBL_DATA_SIZE

+

Quoted 4 lines

PHYS_SRAM + 2048)

/*
* NOR FLASH

Applied

#8 lore raw

PATCH v3 1/4 PXA: PXA27x Matrix keypad driver

In reply to Vasily Khoruzhick
Quoted 24 lines

From: Marek Vasut <[email protected]>

[vasily: adapted Marek's old version for newer u-boot,
fixed multiple keypresses handling]
---
v2: use struct-based access to regs, minor cleanup
v3: fix multiple keypresses handling, minor cleanup

 arch/arm/include/asm/arch-pxa/pxa-regs.h    |   52 -----
 arch/arm/include/asm/arch-pxa/regs-keypad.h |   84 ++++++++
 drivers/input/Makefile                      |    2 +
 drivers/input/pxa27x-mkp.c                  |  301
+++++++++++++++++++++++++++ 4 files changed, 387 insertions(+), 52
deletions(-)
 create mode 100644 arch/arm/include/asm/arch-pxa/regs-keypad.h
 create mode 100644 drivers/input/pxa27x-mkp.c
(quoted diff) +0 -0

b/arch/arm/include/asm/arch-pxa/pxa-regs.h index b81b42c..d562658 100644

arch/arm/include/asm/arch-pxa/pxa-regs.h typedef void (*ExcpHndlr) (void) ; · line 2574

Quoted 8 lines
arch/arm/include/asm/arch-pxa/pxa-regs.h +0 -5
@@ -2567,58 +2567,6 @@ typedef void		(*ExcpHndlr) (void) ;
 #define OVL2C1_O2EN	(1<<31)		/* Enable bit for Overlay 2 */
 #define CCR_CEN		(1<<31)		/* Enable bit for Cursor */
 
-/* Keypad controller */
-
-#define KPC		0x41500000 /* Keypad Interface Control register */
-#define KPDK		0x41500008 /* Keypad Interface Direct Key register */
-#define KPREC		0x41500010 /* Keypad Intefcace Rotary Encoder 

register */

arch/arm/include/asm/arch-pxa/pxa-regs.h typedef void (*ExcpHndlr) (void) ; · line 2576

Quoted 2 lines
arch/arm/include/asm/arch-pxa/pxa-regs.h +0 -2
-#define KPMK		0x41500018 /* Keypad Intefcace Matrix Key register */
-#define KPAS		0x41500020 /* Keypad Interface Automatic Scan register 

*/

Quoted 7 lines
arch/arm/include/asm/arch-pxa/pxa-regs.h +0 -1
-#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
KPKDI 0x41500048 /* Keypad Interface Key Debounce Interval register */

-

Quoted 9 lines
arch/arm/include/asm/arch-pxa/pxa-regs.h +0 -9
-#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 */

arch/arm/include/asm/arch-pxa/pxa-regs.h typedef void (*ExcpHndlr) (void) ;

Quoted 10 lines
arch/arm/include/asm/arch-pxa/pxa-regs.h +0 -10
-#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 Key Debounce select */
-#define KPC_DI		(0x1 <<	 5)  /* Direct key interrupt bit */
-#define KPC_DEE0	(0x1 <<	 2)  /* Rotary Encoder 0 Enable */
-#define KPC_DE		(0x1 <<	 1)  /* Direct Keypad Enable */
-#define KPC_DIE		(0x1 <<	 0)  /* Direct Keypad interrupt Enable 

*/

Quoted 13 lines
arch/arm/include/asm/arch-pxa/pxa-regs.h +0 -13
-
-#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)

arch/arm/include/asm/arch-pxa/pxa-regs.h typedef void (*ExcpHndlr) (void) ;

Quoted 10 lines
arch/arm/include/asm/arch-pxa/pxa-regs.h +0 -7
-#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 GPIO113_BIT	(1 << 17)/* GPIO113 in GPSR, GPCR, bit 17 */
 #define PSLR		0x40F00034
 #define PSTR		0x40F00038  /* Power Manager Standby Configuration Reg 

*/

Quoted 59 lines
(quoted diff) +0 -0

b/arch/arm/include/asm/arch-pxa/regs-keypad.h new file mode 100644 index 0000000..f13da56

arch/arm/include/asm/arch-pxa/regs-keypad.h new file +53 -0
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2012 Vasily Khoruzhick <[email protected]>
+ *
+ * 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
+ */
+
+#ifndef __REGS_KEYPAD_H__
+#define __REGS_KEYPAD_H__
+
+#define KEYPAD_BASE	0x41500000
+
+struct kpasmkp_regs {
+	uint32_t	kpasmkpx;
+	uint32_t	reserved;
+};
+
+struct pxa_keypad_regs {
+	uint32_t		kpc;
+	uint32_t		reserved_1;
+	uint32_t		kpdk;
+	uint32_t		reserved_2;
+	uint32_t		kprec;
+	uint32_t		reserved_3;
+	uint32_t		kpmk;
+	uint32_t		reserved_4;
+	uint32_t		kpas;
+	uint32_t		reserved_5;
+	struct kpasmkp_regs	kpasmkp[4];
+	uint32_t		kpkdi;
+};
+
+#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 */

arch/arm/include/asm/arch-pxa/regs-keypad.h line 63

Quoted 10 lines
arch/arm/include/asm/arch-pxa/regs-keypad.h new file +10 -0
+#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 Key Debounce select */
+#define KPC_DI		(0x1 <<	 5)  /* Direct key interrupt bit */
+#define KPC_DEE0	(0x1 <<	 2)  /* Rotary Encoder 0 Enable */
+#define KPC_DE		(0x1 <<	 1)  /* Direct Keypad Enable */
+#define KPC_DIE		(0x1 <<	 0)  /* Direct Keypad interrupt Enable 

*/

arch/arm/include/asm/arch-pxa/regs-keypad.h line 73

Quoted 10 lines
arch/arm/include/asm/arch-pxa/regs-keypad.h new file +10 -0
+
+#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)

Drop those two spaces here

Quoted 66 lines
arch/arm/include/asm/arch-pxa/regs-keypad.h new file +11 -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)
+
+#endif
drivers/input/Makefile +2 -0
index 1f4dad3..792d29d 100644
@@ -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))
drivers/input/pxa27x-mkp.c new file +36 -0
new file mode 100644
index 0000000..013b6fe
@@ -0,0 +1,301 @@
+/*
+ * PXA27x matrix keypad controller driver
+ *
+ * Copyright (C) 2010 Marek Vasut <[email protected]>
+ * Copyright (C) 2012 Vasily Khoruzhick <[email protected]>
+ *
+ * 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/regs-keypad.h>
+#include <asm/io.h>
+
+#define	DEVNAME		"pxa27x-mkp"
+
+struct {
+	char	row;
+	char	col;
+	char	key;

drivers/input/pxa27x-mkp.c line 46

Quoted 10 lines
drivers/input/pxa27x-mkp.c new file +10 -0
+	char	shift;
+	char	alt;
+	char	ctrl;
+} keymap[] = {
+	CONFIG_PXA27X_MKP_KEYMAP,
+};
+
+static unsigned char queue[64] = {0};
+static int queue_len;
+static struct pxa_keypad_regs *regs;

You can as well assign it here.

Quoted 82 lines
drivers/input/pxa27x-mkp.c new file +82 -0
+
+/* autorepeat stuff */
+static int last_key_row = 0xff, last_key_col = 0xff;
+static char key_counter;
+
+/* number of key scans before autorepeat kicks in */
+#ifndef CONFIG_PXA27X_KEY_REPEAT_FIRST
+#define	CONFIG_PXA27X_KEY_REPEAT_FIRST	12
+#endif
+#ifndef CONFIG_PXA27X_KEY_REPEAT_NEXT
+#define	CONFIG_PXA27X_KEY_REPEAT_NEXT	2
+#endif
+
+/* 100 milliseconds (in wait cycles below it's 100 x 10uS waits) */
+#define PXA_KEYPAD_TIMEOUT	10000
+
+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 int kbd_lookup(int row, int col, int mod)
+{
+	int i = 0;
+	char key = 0xff;
+
+	while (!(keymap[i].col == 0xff && keymap[i].row == 0xff)) {
+		if (keymap[i].row != row || keymap[i].col != col) {
+			i++;
+			continue;
+		}
+		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) {
+			i++;
+			continue;
+		}
+
+		if (row != last_key_row || col != last_key_col) {
+			queue[queue_len++] = key;
+			last_key_row = row;
+			last_key_col = col;
+			key_counter = 0;
+		} else /* same key as before */
+			if (key_counter < CONFIG_PXA27X_KEY_REPEAT_FIRST) {
+				/* ignore key press */
+				key_counter++;
+			} else {
+				/* ok, autorepeat */
+				queue[queue_len++] = key;
+				key_counter = CONFIG_PXA27X_KEY_REPEAT_FIRST
+					- CONFIG_PXA27X_KEY_REPEAT_NEXT;
+			}

drivers/input/pxa27x-mkp.c line 138

Quoted 10 lines
drivers/input/pxa27x-mkp.c new file +10 -0
+		i++;
+	}
+	return key;
+}
+
+static int scan_keys(int scan_modif, uint32_t kpasmkp[4])
+{
+	uint32_t reg = 0;
+	int col, row;
+	static int mod = MOD_NONE;

Are you sure you know what you're doing using all those static vars all around?

Quoted 15 lines
drivers/input/pxa27x-mkp.c new file +15 -0
+	int key;
+	for (col = 0; col < 8; col += 2) {
+		reg = kpasmkp[col >> 1];
+		for (row = 0; row < 8; row++) {
+			if (reg & (1 << row)) {
+				if (scan_modif) {
+					mod = kbd_get_mdf(row, col);
+					if (mod != MOD_NONE)
+						return mod;
+				} else {
+					key = kbd_lookup(row, col, mod);
+					if (key != 0xff)
+						return key;
+				}
+			}

drivers/input/pxa27x-mkp.c line 163

Quoted 10 lines
drivers/input/pxa27x-mkp.c new file +10 -0
+			if ((reg >> 16) & (1 << row)) {
+				if (scan_modif) {
+					mod = kbd_get_mdf(row, col + 1);
+					if (mod != MOD_NONE)
+						return mod;
+				} else {
+					key = kbd_lookup(row, col + 1, mod);
+					if (key != 0xff)
+						return key;
+				}

Can you do some elegant solution of this code duplication?

drivers/input/pxa27x-mkp.c line 108

Quoted 3 lines
drivers/input/pxa27x-mkp.c new file +3 -0
+			}
+		}
+	}

Newline

Quoted 14 lines
drivers/input/pxa27x-mkp.c new file +14 -0
+	if (scan_modif)
+		return MOD_NONE;
+	else
+		return 0xff;
+}
+
+static void kbd_read(void)
+{
+	uint32_t reg;
+	int col, row, i, have_new_key = 0;
+	int numkeys;
+	int mod = MOD_NONE;
+	unsigned int timeout = PXA_KEYPAD_TIMEOUT;
+	static uint32_t kpasmkp_old[4];

drivers/input/pxa27x-mkp.c line 190

Quoted 10 lines
drivers/input/pxa27x-mkp.c new file +10 -0
+	uint32_t kpasmkp[4], kpasmkp_diff[4];
+
+	/* start one automatic scan */
+	writel(readl(&regs->kpc) | KPC_AS, &regs->kpc);
+
+	/* wait for scan to finish */
+	while (timeout--) {
+		if (!(readl(&regs->kpc) & KPC_AS))
+			break;
+		udelay(10);

Use WATCHDOG_RESET()

Quoted 54 lines
drivers/input/pxa27x-mkp.c new file +54 -0
+	}
+
+	if (!timeout)
+		return;
+
+	numkeys = (readl(&regs->kpas) >> 26) & 0x1f;
+	switch (numkeys) {
+	case 0:
+		/* no key pressed, clear autorepeat counter */
+		key_counter = 0;
+		last_key_row = last_key_col = 0xff;
+		for (i = 0; i < ARRAY_SIZE(kpasmkp); i++)
+			kpasmkp[i] = 0;
+		break;
+	case 1:
+		reg = readl(&regs->kpas) & 0xff;
+		col = reg & 0x0f;
+		row = reg >> 4;
+		for (i = 0; i < ARRAY_SIZE(kpasmkp); i++)
+			kpasmkp[i] = 0;
+		kpasmkp[col >> 1] |= (1 << (row + 16 * (col % 2)));
+
+		break;
+	default:
+		for (i = 0; i < ARRAY_SIZE(kpasmkp); i++) {
+			timeout = PXA_KEYPAD_TIMEOUT;
+			while (timeout--) {
+				kpasmkp[i] = readl(&regs->kpasmkp[i].kpasmkpx);
+				if (!(kpasmkp[i] & KPASMKPx_SO))
+					break;
+				udelay(10);
+			}
+			if (!timeout)
+				kpasmkp[i] = 0;
+		}
+		break;
+	}
+
+	/* Find new keypress */
+	for (i = 0; i < ARRAY_SIZE(kpasmkp); i++) {
+		kpasmkp_diff[i] = (kpasmkp_old[i] ^ kpasmkp[i]) &
+			kpasmkp[i];
+		if (kpasmkp_diff[i])
+			have_new_key = 1;
+		kpasmkp_old[i] = kpasmkp[i];
+	}
+
+	if (!numkeys)
+		return;
+
+	/* Scan for modifiers */
+	mod = scan_keys(1, kpasmkp);
+	if (!have_new_key) {
+		/* Check if old key is still pressed */

drivers/input/pxa27x-mkp.c line 254

Quoted 10 lines
drivers/input/pxa27x-mkp.c new file +10 -0
+		if (kpasmkp[last_key_col >> 1] &
+		   (1 << (last_key_row + 16 * (last_key_col % 2))))
+			kbd_lookup(last_key_row, last_key_col, mod);
+		serial_printf("No new key\n");
+
+	} else {
+		key_counter = 0;
+		last_key_row = last_key_col = 0xff;
+		scan_keys(0, kpasmkp_diff);
+		serial_printf("New key\n");

What's this dammit? And above too! Use debug() if you need it.

Quoted 19 lines
drivers/input/pxa27x-mkp.c new file +19 -0
+	}
+}
+
+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)

drivers/input/pxa27x-mkp.c line 283

Quoted 10 lines
drivers/input/pxa27x-mkp.c new file +10 -0
+		kbd_read();
+	return queue_len;
+}
+
+int drv_keyboard_init(void)
+{
+	int error = 0;
+	struct stdio_dev kbddev;
+
+	regs = (struct pxa_keypad_regs *)KEYPAD_BASE;

See above

Quoted 4 lines
drivers/input/pxa27x-mkp.c new file +4 -0
+	queue_len = 0;
+
+	writel((CONFIG_PXA27X_MKP_MKP_ROWS << 26) |
+		(CONFIG_PXA27X_MKP_MKP_COLS << 23) |

drivers/input/pxa27x-mkp.c line 297

Quoted 10 lines
drivers/input/pxa27x-mkp.c new file +10 -0
+		(0xff << 13) | KPC_ME, &regs->kpc);
+	writel(CONFIG_PXA27X_MKP_DEBOUNCE, &regs->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 ;

Drop spaces before semicolon

Quoted 4 lines
drivers/input/pxa27x-mkp.c new file +4 -0
+
+	error = stdio_register(&kbddev);
+	return error;
+}
#9 lore raw

PATCH v3 1/4 PXA: PXA27x Matrix keypad driver

Quoted 4 lines · Marek Vasut

arch/arm/include/asm/arch-pxa/regs-keypad.h line 73

Quoted 2 lines
arch/arm/include/asm/arch-pxa/regs-keypad.h new file +2 -0
+#define KPDK_DK1	(0x1 <<	 1)
+#define KPDK_DK0	(0x1 <<	 0)

Drop those two spaces here

Two spaces? It's tabs! Btw, it's for good looking formatting and it was taken from pxa-regs.h. I'd like to preserve it like it is.

Quoted 5 lines

drivers/input/pxa27x-mkp.c line 46

Quoted 3 lines
drivers/input/pxa27x-mkp.c new file +3 -0
+static unsigned char queue[64] = {0};
+static int queue_len;
+static struct pxa_keypad_regs *regs;

You can as well assign it here.

Ok

Quoted 7 lines

drivers/input/pxa27x-mkp.c line 138

Quoted 5 lines
drivers/input/pxa27x-mkp.c new file +5 -0
+static int scan_keys(int scan_modif, uint32_t kpasmkp[4])
+{
+	uint32_t reg = 0;
+	int col, row;
+	static int mod = MOD_NONE;

Are you sure you know what you're doing using all those static vars all around?

I'm sure I know what I'm doing, right here it preserves modifier between two function calls, i.e. scan_keys(1, ...); scan_keys(0, ...);

Quoted 4 lines
Quoted 4 lines
drivers/input/pxa27x-mkp.c new file +4 -0
+			if ((reg >> 16) & (1 << row)) {
+				if (scan_modif) {
+					mod = kbd_get_mdf(row, col + 1);
+					if (mod != MOD_NONE)
Quoted 8 lines

drivers/input/pxa27x-mkp.c line 163

Quoted 6 lines
drivers/input/pxa27x-mkp.c new file +6 -0
+						return mod;
+				} else {
+					key = kbd_lookup(row, col + 1, mod);
+					if (key != 0xff)
+						return key;
+				}

Can you do some elegant solution of this code duplication?

Ok

Quoted 5 lines

drivers/input/pxa27x-mkp.c line 108

Quoted 3 lines
drivers/input/pxa27x-mkp.c new file +3 -0
+			}
+		}
+	}

Newline

Ok

Quoted 7 lines

drivers/input/pxa27x-mkp.c line 190

Quoted 5 lines
drivers/input/pxa27x-mkp.c new file +5 -0
+	/* wait for scan to finish */
+	while (timeout--) {
+		if (!(readl(&regs->kpc) & KPC_AS))
+			break;
+		udelay(10);

Use WATCHDOG_RESET()

Why the heck you want to reset here? It's not fatal. We can handle this timeout gracefully, without resetting and messing up all the stuff.

Quoted 7 lines

drivers/input/pxa27x-mkp.c line 254

Quoted 5 lines
drivers/input/pxa27x-mkp.c new file +5 -0
+	} else {
+		key_counter = 0;
+		last_key_row = last_key_col = 0xff;
+		scan_keys(0, kpasmkp_diff);
+		serial_printf("New key\n");

What's this dammit? And above too! Use debug() if you need it.

Sorry, left it occasionally.

Quoted 4 lines

drivers/input/pxa27x-mkp.c line 297

Quoted 2 lines
drivers/input/pxa27x-mkp.c new file +2 -0
+	kbddev.getc = kbd_getc ;
+	kbddev.tstc = kbd_testc ;

Drop spaces before semicolon

Ok

Thanks for review!

Regards,
Vasily

#10 lore raw

PATCH v3 1/4 PXA: PXA27x Matrix keypad driver

Quoted 8 lines · Marek Vasut
Quoted 4 lines

arch/arm/include/asm/arch-pxa/regs-keypad.h line 73

Quoted 2 lines
arch/arm/include/asm/arch-pxa/regs-keypad.h new file +2 -0
+#define KPDK_DK1	(0x1 <<	 1)
+#define KPDK_DK0	(0x1 <<	 0)

Drop those two spaces here

Two spaces? It's tabs! Btw, it's for good looking formatting and it was taken from pxa-regs.h. I'd like to preserve it like it is.

Then change it to space ... (1 <<[TAB]3) is even weirder. And on my side, it still looks like two spaces.

Quoted 52 lines
Quoted 6 lines

drivers/input/pxa27x-mkp.c line 46

Quoted 4 lines
drivers/input/pxa27x-mkp.c new file +3 -0
+static unsigned char queue[64] = {0};
+static int queue_len;
+static struct pxa_keypad_regs *regs;

You can as well assign it here.

Ok

Quoted 8 lines

drivers/input/pxa27x-mkp.c line 138

Quoted 5 lines
drivers/input/pxa27x-mkp.c new file +5 -0
+static int scan_keys(int scan_modif, uint32_t kpasmkp[4])
+{
+	uint32_t reg = 0;
+	int col, row;
+	static int mod = MOD_NONE;

Are you sure you know what you're doing using all those static vars all around?

I'm sure I know what I'm doing, right here it preserves modifier between two function calls, i.e. scan_keys(1, ...); scan_keys(0, ...);

Quoted 4 lines
Quoted 4 lines
drivers/input/pxa27x-mkp.c new file +4 -0
+			if ((reg >> 16) & (1 << row)) {
+				if (scan_modif) {
+					mod = kbd_get_mdf(row, col + 1);
+					if (mod != MOD_NONE)
Quoted 8 lines

drivers/input/pxa27x-mkp.c line 163

Quoted 6 lines
drivers/input/pxa27x-mkp.c new file +6 -0
+						return mod;
+				} else {
+					key = kbd_lookup(row, col + 1, mod);
+					if (key != 0xff)
+						return key;
+				}

Can you do some elegant solution of this code duplication?

Ok

Quoted 5 lines

drivers/input/pxa27x-mkp.c line 108

Quoted 3 lines
drivers/input/pxa27x-mkp.c new file +3 -0
+			}
+		}
+	}

Newline

Ok

Quoted 7 lines

drivers/input/pxa27x-mkp.c line 190

Quoted 5 lines
drivers/input/pxa27x-mkp.c new file +5 -0
+	/* wait for scan to finish */
+	while (timeout--) {
+		if (!(readl(&regs->kpc) & KPC_AS))
+			break;
+		udelay(10);

Use WATCHDOG_RESET()

Quoted 2 lines

Why the heck you want to reset here? It's not fatal. We can handle this timeout gracefully, without resetting and messing up all the stuff.

WATCHDOG_RESET() reloads the WDT ...

Quoted 22 lines
Quoted 8 lines

drivers/input/pxa27x-mkp.c line 254

Quoted 6 lines
drivers/input/pxa27x-mkp.c new file +5 -0
+	} else {
+		key_counter = 0;
+		last_key_row = last_key_col = 0xff;
+		scan_keys(0, kpasmkp_diff);
+		serial_printf("New key\n");

What's this dammit? And above too! Use debug() if you need it.

Sorry, left it occasionally.

Quoted 4 lines

drivers/input/pxa27x-mkp.c line 297

Quoted 2 lines
drivers/input/pxa27x-mkp.c new file +2 -0
+	kbddev.getc = kbd_getc ;
+	kbddev.tstc = kbd_testc ;

Drop spaces before semicolon

Ok

Thanks for review!

Regards,
Vasily