Skip to contentSkip to conversation

sh: SuperH KEYSC keypad support

PATCH In review Magnus Damm 2 participants 6 messages Feb 29, 2008

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover sh: SuperH KEYSC keypad support

These patches add support for keypads attached to the SuperH KEYSC block.

[PATCH 01/03] sh: SuperH KEYSC platform driver
[PATCH 02/03] sh: SuperH KEYSC support for MigoR [PATCH 03/03] sh: SuperH KEYSC support for Solution Engine 7722

---

Please note that the board patches need the header file provided by the first patch to compile. So maybe this is suitable for -mm? If it is better to merge the driver in some subsystem tree then I'll just resend the board code to the linux-sh list during late -rc1 merge.

 arch/sh/boards/renesas/migor/setup.c |   56 ++++++
 arch/sh/boards/se/7722/setup.c       |   41 ++++
 drivers/input/keyboard/Kconfig       |    9 +
 drivers/input/keyboard/Makefile      |    1 
 drivers/input/keyboard/sh_keysc.c    |  281 ++++++++++++++++++++++++++++++++++
 include/asm-sh/se7722.h              |    2 
 include/asm-sh/sh_keysc.h            |   13 +
 7 files changed, 402 insertions(+), 1 deletion(-)
#1 lore raw

PATCH 1/3 sh: SuperH KEYSC platform driver

This patch adds a platform driver for the SuperH KEYSC block. The driver expects to get mode, timing information and keypad layout from the board code as platform data. The board code is resonsible for pin configuration.

Both sh7343 and sh7722 should be supported, but only the sh7722 processor has been tested so far. SH_KEYSC_MODE_3 is yet to be tested.

---

 drivers/input/keyboard/Kconfig    |    9 +
 drivers/input/keyboard/Makefile   |    1 
 drivers/input/keyboard/sh_keysc.c |  281 +++++++++++++++++++++++++++++++++++++
 include/asm-sh/sh_keysc.h         |   13 +
 4 files changed, 304 insertions(+)
drivers/input/keyboard/Kconfig +9 -0
@@ -314,4 +314,13 @@ config KEYBOARD_BFIN
 	  To compile this driver as a module, choose M here: the
 	  module will be called bf54x-keys.
 
+config KEYBOARD_SH_KEYSC
+	tristate "SuperH KEYSC keypad support"
+	depends on SUPERH
+	help
+	  Say Y here if you want to use a keypad attached to the KEYSC block
+	  on SuperH processors such as sh7722 and sh7343.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called sh_keysc.
 endif
drivers/input/keyboard/Makefile +1 -0
@@ -26,3 +26,4 @@ obj-$(CONFIG_KEYBOARD_HP6XX)		+= jornada
 obj-$(CONFIG_KEYBOARD_HP7XX)		+= jornada720_kbd.o
 obj-$(CONFIG_KEYBOARD_MAPLE)		+= maple_keyb.o
 obj-$(CONFIG_KEYBOARD_BFIN)		+= bf54x-keys.o
+obj-$(CONFIG_KEYBOARD_SH_KEYSC)		+= sh_keysc.o
drivers/input/keyboard/sh_keysc.c new file +281 -0

281 lines not on this page · raw message

include/asm-sh/sh_keysc.h new file +13 -0
@@ -0,0 +1,13 @@
+#ifndef __ASM_KEYSC_H__
+#define __ASM_KEYSC_H__
+
+#define SH_KEYSC_MAXKEYS 30
+
+struct sh_keysc_info {
+	enum { SH_KEYSC_MODE_1, SH_KEYSC_MODE_2, SH_KEYSC_MODE_3 } mode;
+	int scan_timing; /* 0 -> 7, see KYCR1, SCN[2:0] */
+	int delay;
+	int keycodes[SH_KEYSC_MAXKEYS];
+};
+
+#endif /* __ASM_KEYSC_H__ */
#2 lore raw

Re: [PATCH 01/03] sh: SuperH KEYSC platform driver

Quoted 10 lines · On Fri, 29 Feb 2008 19:48:56 +0900 Magnus Damm <[email protected]> wrote:

This patch adds a platform driver for the SuperH KEYSC block. The driver expects to get mode, timing information and keypad layout from the board code as platform data. The board code is resonsible for pin configuration.

Both sh7343 and sh7722 should be supported, but only the sh7722 processor has been tested so far. SH_KEYSC_MODE_3 is yet to be tested.

...

+#define res_size(res) ((res)->end - (res)->start + 1)

- buggy macro references its argument more than once
- could be implemented in C
- perhaps should be implemented in <linux/ioport.h>

drivers/input/keyboard/sh_keysc.c line 186

Quoted 1 line
drivers/input/keyboard/sh_keysc.c new file +1 -0
+	input->phys = "sh-keysc-keys/input0";

Is the "/" in here safe? I trust we don't try to create a sysfs/procfs/whatever file based off this string.

#3 lore raw

PATCH 2/3 sh: SuperH KEYSC keypad data for MigoR

In reply to Magnus Damm

This patch adds KEYSC platform data for the sh7722 MigoR board.

---

 arch/sh/boards/renesas/migor/setup.c |   56 +++++++++++++++++++++++++++++++++-
 1 file changed, 55 insertions(+), 1 deletion(-)
arch/sh/boards/renesas/migor/setup.c +55 -1
@@ -10,8 +10,10 @@
 #include <linux/init.h>
 #include <linux/platform_device.h>
 #include <linux/interrupt.h>
+#include <linux/input.h>
 #include <asm/machvec.h>
 #include <asm/io.h>
+#include <asm/sh_keysc.h>
 
 /* Address     IRQ  Size  Bus  Description
  * 0x00000000       64MB  16   NOR Flash (SP29PL256N)
@@ -40,8 +42,43 @@ static struct platform_device smc91x_eth
 	.resource       = smc91x_eth_resources,
 };
 
+static struct sh_keysc_info sh_keysc_info = {
+	.mode = SH_KEYSC_MODE_2, /* KEYOUT0->4, KEYIN1->5 */
+	.scan_timing = 3,
+	.delay = 5,
+	.keycodes = {
+		0, KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT, KEY_ENTER,
+		0, KEY_F, KEY_C, KEY_D,	KEY_H, KEY_1,
+		0, KEY_2, KEY_3, KEY_4,	KEY_5, KEY_6,
+		0, KEY_7, KEY_8, KEY_9, KEY_S, KEY_0,
+		0, KEY_P, KEY_STOP, KEY_REWIND, KEY_PLAY, KEY_FASTFORWARD,
+	},
+};
+
+static struct resource sh_keysc_resources[] = {
+	[0] = {
+		.start  = 0x044b0000,
+		.end    = 0x044b000f,
+		.flags  = IORESOURCE_MEM,
+	},
+	[1] = {
+		.start  = 79,
+		.flags  = IORESOURCE_IRQ,
+	},
+};
+
+static struct platform_device sh_keysc_device = {
+	.name           = "sh_keysc",
+	.num_resources  = ARRAY_SIZE(sh_keysc_resources),
+	.resource       = sh_keysc_resources,
+	.dev	= {
+		.platform_data	= &sh_keysc_info,
+	},
+};
+
 static struct platform_device *migor_devices[] __initdata = {
 	&smc91x_eth_device,
+	&sh_keysc_device,
 };
 
 static int __init migor_devices_setup(void)
@@ -50,9 +87,26 @@ static int __init migor_devices_setup(vo
 }
 __initcall(migor_devices_setup);
 
+#define PORT_PJCR       0xA4050110UL
+#define PORT_PSELA      0xA405014EUL
+#define PORT_PYCR       0xA405014AUL
+#define PORT_PZCR       0xA405014CUL
+#define PORT_HIZCRA     0xA4050158UL
+#define PORT_HIZCRC     0xA405015CUL
+#define MSTPCR2         0xA4150038UL
+
 static void __init migor_setup(char **cmdline_p)
 {
-	ctrl_outw(0x1000, 0xa4050110); /* Enable IRQ0 in PJCR */
+	/* SMC91C111 - Enable IRQ0 */
+	ctrl_outw(ctrl_inw(PORT_PJCR) & ~0x0003, PORT_PJCR);
+
+	/* KEYSC */
+	ctrl_outw(ctrl_inw(PORT_PYCR) & ~0x0fff, PORT_PYCR);
+	ctrl_outw(ctrl_inw(PORT_PZCR) & ~0x0ff0, PORT_PZCR);
+	ctrl_outw(ctrl_inw(PORT_PSELA) & ~0x4100, PORT_PSELA);
+	ctrl_outw(ctrl_inw(PORT_HIZCRA) & ~0x4000, PORT_HIZCRA);
+	ctrl_outw(ctrl_inw(PORT_HIZCRC) & ~0xc000, PORT_HIZCRC);
+	ctrl_outl(ctrl_inl(MSTPCR2) & ~0x00004000, MSTPCR2);
 }
 
 static struct sh_machine_vector mv_migor __initmv = {
#4 lore raw

PATCH 3/3 sh: SuperH KEYSC keypad data for Solution Engine 7722

In reply to Magnus Damm

This patch adds KEYSC platform data for the Solution Engine 7722 board.

---

 arch/sh/boards/se/7722/setup.c |   41 ++++++++++++++++++++++++++++++++++++++++
 include/asm-sh/se7722.h        |    2 +
 2 files changed, 43 insertions(+)
arch/sh/boards/se/7722/setup.c +41 -0
@@ -13,10 +13,12 @@
 #include <linux/init.h>
 #include <linux/platform_device.h>
 #include <linux/ata_platform.h>
+#include <linux/input.h>
 #include <asm/machvec.h>
 #include <asm/se7722.h>
 #include <asm/io.h>
 #include <asm/heartbeat.h>
+#include <asm/sh_keysc.h>
 
 /* Heartbeat */
 static struct heartbeat_data heartbeat_data = {
@@ -92,10 +94,47 @@ static struct platform_device cf_ide_dev
 	.resource       = cf_ide_resources,
 };
 
+static struct sh_keysc_info sh_keysc_info = {
+	.mode = SH_KEYSC_MODE_1, /* KEYOUT0->5, KEYIN0->4 */
+	.scan_timing = 3,
+	.delay = 5,
+	.keycodes = { /* SW1 -> SW30 */
+		KEY_A, KEY_B, KEY_C, KEY_D, KEY_E,
+		KEY_F, KEY_G, KEY_H, KEY_I, KEY_J,
+		KEY_K, KEY_L, KEY_M, KEY_N, KEY_O,
+		KEY_P, KEY_Q, KEY_R, KEY_S, KEY_T,
+		KEY_U, KEY_V, KEY_W, KEY_X, KEY_Y,
+		KEY_Z,
+		KEY_HOME, KEY_SLEEP, KEY_WAKEUP, KEY_COFFEE, /* life */
+	},
+};
+
+static struct resource sh_keysc_resources[] = {
+	[0] = {
+		.start  = 0x044b0000,
+		.end    = 0x044b000f,
+		.flags  = IORESOURCE_MEM,
+	},
+	[1] = {
+		.start  = 79,
+		.flags  = IORESOURCE_IRQ,
+	},
+};
+
+static struct platform_device sh_keysc_device = {
+	.name           = "sh_keysc",
+	.num_resources  = ARRAY_SIZE(sh_keysc_resources),
+	.resource       = sh_keysc_resources,
+	.dev	= {
+		.platform_data	= &sh_keysc_info,
+	},
+};
+
 static struct platform_device *se7722_devices[] __initdata = {
 	&heartbeat_device,
 	&smc91x_eth_device,
 	&cf_ide_device,
+	&sh_keysc_device,
 };
 
 static int __init se7722_devices_setup(void)
@@ -136,6 +175,8 @@ static void __init se7722_setup(char **c
 	ctrl_outw(0x0A10, PORT_PSELA); /* BS,SHHID2 */
 	ctrl_outw(0x0000, PORT_PYCR);
 	ctrl_outw(0x0000, PORT_PZCR);
+	ctrl_outw(ctrl_inw(PORT_HIZCRA) & ~0x4000, PORT_HIZCRA);
+	ctrl_outw(ctrl_inw(PORT_HIZCRC) & ~0xc000, PORT_HIZCRC);
 }
 
 /*
include/asm-sh/se7722.h +2 -0
@@ -77,6 +77,8 @@
 #define PORT_PSELA      0xA405014EUL
 #define PORT_PYCR       0xA405014AUL
 #define PORT_PZCR       0xA405014CUL
+#define PORT_HIZCRA     0xA4050158UL
+#define PORT_HIZCRC     0xA405015CUL
 
 /* IRQ */
 #define IRQ0_IRQ        32
#5 lore raw
In reply to Magnus Damm
Quoted 11 lines · On Fri, 29 Feb 2008 19:48:47 +0900 Magnus Damm <[email protected]> wrote:

These patches add support for keypads attached to the SuperH KEYSC block.

[PATCH 01/03] sh: SuperH KEYSC platform driver
[PATCH 02/03] sh: SuperH KEYSC support for MigoR [PATCH 03/03] sh: SuperH KEYSC support for Solution Engine 7722

---

Please note that the board patches need the header file provided by the first patch to compile. So maybe this is suitable for -mm?

The diffstat looks pretty tame to me - this could be merged via either git-input or git-sh. Probably the latter.

Quoted 2 lines

If it is better to merge the driver in some subsystem tree then I'll just resend the board code to the linux-sh list during late -rc1 merge.

That would be a bad time to send it. We should get patches into the subsystem trees (and linux-next and -mm!) prior to the 2.6.x release. A subsystem maintainer who receives feature work during the 2.6.x merge window could/shouidl/would schedule it for 2.6.x+1.

Quoted 8 lines
 arch/sh/boards/renesas/migor/setup.c |   56 ++++++
 arch/sh/boards/se/7722/setup.c       |   41 ++++
 drivers/input/keyboard/Kconfig       |    9 +
 drivers/input/keyboard/Makefile      |    1 
 drivers/input/keyboard/sh_keysc.c    |  281 ++++++++++++++++++++++++++++++++++
 include/asm-sh/se7722.h              |    2 
 include/asm-sh/sh_keysc.h            |   13 +
 7 files changed, 402 insertions(+), 1 deletion(-)