Skip to contentSkip to conversation

Add support for TCA6416 based Keypad driver.

PATCH Superseded Sriramakrishnan 4 participants 10 messages Feb 25, 2010 – Mar 5, 2010

Subsystems (5)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Add support for TCA6416 based Keypad driver.

AM3517 EVM with APPS board includes keys interfaced to TCA6416 IO expander. User keys are connected as GPIO lines to TCA6416 IO expander. Unlike the case with generic gpio-keypad driver individual keys do not generate an interrupt event. Hence we implement a simple keypad driver(based on gpio-keys) that registers as direct I2C client.

The implementation has been tested on AM3517 EVM with the driver tested in polling mode.

Sriramakrishnan (3):
TCA6416 keypad : Implement keypad driver for keys interfaced to

    TCA6416

AM3517 EVM : Enable TCA6416 keypad
AM3517: Board hookup for TCA6416 keypad driver.

 arch/arm/configs/am3517_evm_defconfig   |   15 ++-
 arch/arm/mach-omap2/board-am3517evm.c   |   48 ++++-
 drivers/input/keyboard/Kconfig          |   17 ++
 drivers/input/keyboard/Makefile         |    1 +
 drivers/input/keyboard/tca6416-keypad.c |  355 +++++++++++++++++++++++++++++++
 include/linux/tca6416_keypad.h          |   30 +++
 6 files changed, 460 insertions(+), 6 deletions(-)
 create mode 100755 drivers/input/keyboard/tca6416-keypad.c
 create mode 100755 include/linux/tca6416_keypad.h
#1 lore raw

PATCH 1/3 TCA6416 keypad : Implement keypad driver for keys interfaced to TCA6416

This patch implements a simple Keypad driver that functions as an I2C client. It handles key press events for keys connected to TCA6416 I2C based IO expander.

---
 drivers/input/keyboard/Kconfig          |   17 ++
 drivers/input/keyboard/Makefile         |    1 +
 drivers/input/keyboard/tca6416-keypad.c |  355 +++++++++++++++++++++++++++++++
 include/linux/tca6416_keypad.h          |   30 +++
 4 files changed, 403 insertions(+), 0 deletions(-)
 create mode 100755 drivers/input/keyboard/tca6416-keypad.c
 create mode 100755 include/linux/tca6416_keypad.h
drivers/input/keyboard/Kconfig +17 -0
index 02c836e..c2cd31b 100644
@@ -190,6 +190,23 @@ config KEYBOARD_GPIO
 	  To compile this driver as a module, choose M here: the
 	  module will be called gpio_keys.
 
+config KEYBOARD_TCA6416
+	tristate "TCA6416 Keypad Support"
+	depends on I2C
+	help
+	  This driver implements basic keypad functionality
+	  for keys connected through TCA6416 IO expander
+
+	  Say Y here if your device has keys connected to
+	  TCA6416 IO expander. Your board-specific setup logic
+	  must also provide pin-mask details(of which TCA6416 pins
+	  are used for keypad).
+
+	  If enabled the complete TCA6416 device will be managed through
+	  this driver(precludes gpio interface for remaining pins on
+	  TCA6416)
+
+
 config KEYBOARD_MATRIX
 	tristate "GPIO driven matrix keypad support"
 	depends on GENERIC_GPIO
drivers/input/keyboard/Makefile +1 -0
index 78654ef..0f1ad54 100644
@@ -15,6 +15,7 @@ obj-$(CONFIG_KEYBOARD_CORGI)		+= corgikbd.o
 obj-$(CONFIG_KEYBOARD_DAVINCI)		+= davinci_keyscan.o
 obj-$(CONFIG_KEYBOARD_EP93XX)		+= ep93xx_keypad.o
 obj-$(CONFIG_KEYBOARD_GPIO)		+= gpio_keys.o
+obj-$(CONFIG_KEYBOARD_TCA6416)		+= tca6416-keypad.o
 obj-$(CONFIG_KEYBOARD_HIL)		+= hil_kbd.o
 obj-$(CONFIG_KEYBOARD_HIL_OLD)		+= hilkbd.o
 obj-$(CONFIG_KEYBOARD_HP6XX)		+= jornada680_kbd.o
drivers/input/keyboard/tca6416-keypad.c new file +355 -0

355 lines not on this page · raw message

include/linux/tca6416_keypad.h new file +30 -0
new file mode 100755
index 0000000..e996176
@@ -0,0 +1,30 @@
+/*
+ * tca6416 keypad platform support
+ *
+ * Copyright (C) 2010 Texas Instruments
+ *
+ * Author: Sriramakrishnan <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _TCA6416_KEYS_H
+#define _TCA6416_KEYS_H
+
+#include <linux/gpio_keys.h>
+#include <linux/types.h>
+
+struct tca6416_keys_platform_data {
+	struct gpio_keys_button *buttons;
+	int nbuttons;
+	unsigned int rep:1;	/* enable input subsystem auto repeat */
+	uint16_t pinmask;
+	uint16_t invert;
+	int irqnum;
+	int irq_is_gpio;
+	int use_polling;	/* use polling if Interrupt is not connected*/
+};
+
+#endif
Signature · 1 line
1.6.2.4
#2 lore raw

PATCH 2/3 AM3517 EVM : Enable TCA6416 keypad

Update kernel configuration for AM3517EVM to include support for TCA6416 keypad.

---
 arch/arm/configs/am3517_evm_defconfig |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)
arch/arm/configs/am3517_evm_defconfig +14 -1
index 04a804b..439ba7f 100644
@@ -539,7 +539,20 @@ CONFIG_INPUT_EVDEV=y
 #
 # Input Device Drivers
 #
-# CONFIG_INPUT_KEYBOARD is not set
+CONFIG_INPUT_KEYBOARD=y
+# CONFIG_KEYBOARD_ADP5588 is not set
+CONFIG_KEYBOARD_ATKBD=y
+# CONFIG_QT2160 is not set
+# CONFIG_KEYBOARD_LKKBD is not set
+# CONFIG_KEYBOARD_GPIO is not set
+CONFIG_KEYBOARD_TCA6416=y
+# CONFIG_KEYBOARD_MATRIX is not set
+# CONFIG_KEYBOARD_MAX7359 is not set
+# CONFIG_KEYBOARD_NEWTON is not set
+# CONFIG_KEYBOARD_OPENCORES is not set
+# CONFIG_KEYBOARD_STOWAWAY is not set
+# CONFIG_KEYBOARD_SUNKBD is not set
+# CONFIG_KEYBOARD_XTKBD is not set
 # CONFIG_INPUT_MOUSE is not set
 # CONFIG_INPUT_JOYSTICK is not set
 # CONFIG_INPUT_TABLET is not set
Signature · 1 line
1.6.2.4
#3 lore raw

PATCH 3/3 AM3517: Board hookup for TCA6416 keypad driver.

Add board specific hookup for TCA6416 keypad driver.

---
This patch depends on "AM3517EVM : correct typo - tca6416 mispelt as tca6516" patch submitted earlier.
[1] http://marc.info/?l=linux-omap&m=126709475619102&w=2

 arch/arm/mach-omap2/board-am3517evm.c |   48 +++++++++++++++++++++++++++++---
 1 files changed, 43 insertions(+), 5 deletions(-)
arch/arm/mach-omap2/board-am3517evm.c +43 -5
index b336adc..a8228b7 100644
@@ -20,7 +20,10 @@
 #include <linux/init.h>
 #include <linux/platform_device.h>
 #include <linux/gpio.h>
+#include <linux/i2c.h>
 #include <linux/i2c/pca953x.h>
+#include <linux/input.h>
+#include <linux/tca6416_keypad.h>
 
 #include <mach/hardware.h>
 #include <mach/am35xx.h>
@@ -88,16 +91,51 @@ static struct i2c_board_info __initdata am3517evm_tca6416_info_0[] = {
 };
 
 /* Mounted on UI Card */
-static struct pca953x_platform_data am3517evm_ui_gpio_expander_info_1 = {
+/* IO expander at address 0x20 on UI card will be managed by Keypad driver */
+
+static struct pca953x_platform_data am3517evm_ui_gpio_expander_info_2 = {
 	.gpio_base	= OMAP_MAX_GPIO_LINES + 16,
 };
-static struct pca953x_platform_data am3517evm_ui_gpio_expander_info_2 = {
-	.gpio_base	= OMAP_MAX_GPIO_LINES + 32,
+
+/*Keypad Initialization */
+#define KEYPAD_PIN_MASK                0xFFC0
+
+#define KEYPAD_BUTTON(ev_type, ev_code, act_low, descr) \
+{                                                               \
+	.type           = ev_type,                              \
+	.code           = ev_code,                              \
+	.active_low     = act_low,                              \
+	.desc           = "btn " descr,                         \
+}
+
+#define KEYPAD_BUTTON_LOW(event_code, description)      \
+	KEYPAD_BUTTON(EV_KEY, event_code, 1, description)
+
+static struct gpio_keys_button am3517_gpio_keys[] = {
+	KEYPAD_BUTTON_LOW(KEY_DOWN, "down"),
+	KEYPAD_BUTTON_LOW(KEY_UP, "up"),
+	KEYPAD_BUTTON_LOW(KEY_MENU, "menu"),
+	KEYPAD_BUTTON_LOW(KEY_MODE, "mode"),
+	KEYPAD_BUTTON_LOW(KEY_LEFTSHIFT, "shift"),
+	KEYPAD_BUTTON_LOW(KEY_REWIND, "rewind"),
+	KEYPAD_BUTTON_LOW(KEY_FORWARD, "forward"),
+	KEYPAD_BUTTON_LOW(KEY_STOP, "stop"),
+	KEYPAD_BUTTON_LOW(KEY_PLAY, "play"),
+	KEYPAD_BUTTON_LOW(KEY_RECORD, "rec"),
 };
+
+static struct tca6416_keys_platform_data am3517evm_tca6416_keys_info = {
+	.buttons        = am3517_gpio_keys,
+	.nbuttons       = ARRAY_SIZE(am3517_gpio_keys),
+	.rep            = 0,
+	.use_polling    = 1,
+	.pinmask        = KEYPAD_PIN_MASK,
+};
+
 static struct i2c_board_info __initdata am3517evm_ui_tca6416_info[] = {
 	{
-		I2C_BOARD_INFO("tca6416", 0x20),
-		.platform_data = &am3517evm_ui_gpio_expander_info_1,
+		I2C_BOARD_INFO("tca6416-keys", 0x20),
+		.platform_data = &am3517evm_tca6416_keys_info,
 	},
 	{
 		I2C_BOARD_INFO("tca6416", 0x21),
Signature · 1 line
1.6.2.4
#4 lore raw

Re: [PATCH 1/3] TCA6416 keypad : Implement keypad driver for keys interfaced to TCA6416

In reply to Sriramakrishnan

Hi,

Quoted 3 lines · Sriramakrishnan

This patch implements a simple Keypad driver that functions as an I2C client. It handles key press events for keys connected to TCA6416 I2C based IO expander.

what's wrong with gpio-keys ??

Quoted 1 line

+ * Implementation based on drivers/input/keyboard/gpio_keys.c

I see,

shouldn't you instead provide a gpiolib driver for tca6416 and use the generic gpio_keys driver ??

drivers/input/keyboard/tca6416-keypad.c line 246

Quoted 1 line
drivers/input/keyboard/tca6416-keypad.c new file +1 -0
+	if (!chip->use_polling) {

IMO, you should only use polling if the irq line isn't connected.

drivers/input/keyboard/tca6416-keypad.c line 248

Quoted 2 lines
drivers/input/keyboard/tca6416-keypad.c new file +2 -0
+		if (pdata->irq_is_gpio)
+			chip->irqnum = gpio_to_irq(pdata->irqnum);

you can pass the irq number via i2c_board_info. Use it.

drivers/input/keyboard/tca6416-keypad.c line 252

Quoted 4 lines
drivers/input/keyboard/tca6416-keypad.c new file +4 -0
+		else
+			chip->irqnum = pdata->irqnum;
+
+		ret = request_irq(chip->irqnum, tca6416_keys_isr,

it's an i2c driver!!! this should be request_threaded_irq()

Signature · 1 line
balbi
maintainer
#5 lore raw

Re: [PATCH 1/3] TCA6416 keypad : Implement keypad driver for keys interfaced to TCA6416

Quoted 7 lines · Felipe Balbi

Hi,

Quoted 3 lines · Sriramakrishnan

This patch implements a simple Keypad driver that functions as an I2C client. It handles key press events for keys connected to TCA6416 I2C based IO expander.

Quoted 9 lines

what's wrong with gpio-keys ??

Quoted 1 line

+ * Implementation based on drivers/input/keyboard/gpio_keys.c

I see,

shouldn't you instead provide a gpiolib driver for tca6416 and use the generic gpio_keys driver ??

Right. The fact that the driver precludes all otehr gpios from being used is a major drawback.

Quoted 9 lines

drivers/input/keyboard/tca6416-keypad.c line 246

Quoted 1 line
drivers/input/keyboard/tca6416-keypad.c new file +1 -0
+	if (!chip->use_polling) {

IMO, you should only use polling if the irq line isn't connected.

drivers/input/keyboard/tca6416-keypad.c line 248

Quoted 2 lines
drivers/input/keyboard/tca6416-keypad.c new file +2 -0
+		if (pdata->irq_is_gpio)
+			chip->irqnum = gpio_to_irq(pdata->irqnum);

you can pass the irq number via i2c_board_info. Use it.

Quoted 7 lines

drivers/input/keyboard/tca6416-keypad.c line 252

Quoted 4 lines
drivers/input/keyboard/tca6416-keypad.c new file +4 -0
+		else
+			chip->irqnum = pdata->irqnum;
+
+		ret = request_irq(chip->irqnum, tca6416_keys_isr,

it's an i2c driver!!! this should be request_threaded_irq()

Threaded IRQ probably does not fit well when you want to support both interrupt and polling in the same driver...

Signature · 1 line
Dmitry
#6 lore raw

RE: [PATCH 1/3] TCA6416 keypad : Implement keypad driver for keys interfaced to TCA6416

Quoted 22 lines

-----Original Message-----
From: Dmitry Torokhov [mailto:[email protected]]
Sent: Friday, February 26, 2010 1:58 PM
To: Felipe Balbi
Cc: Govindarajan, Sriramakrishnan; [email protected]; linux- [email protected]
Subject: Re: [PATCH 1/3] TCA6416 keypad : Implement keypad driver for keys interfaced to TCA6416

Quoted 11 lines · Felipe Balbi

Hi,

Quoted 3 lines · Sriramakrishnan

This patch implements a simple Keypad driver that functions as an I2C client. It handles key press events for keys connected to TCA6416 I2C based IO expander.

what's wrong with gpio-keys ??

Quoted 1 line

+ * Implementation based on drivers/input/keyboard/gpio_keys.c

Quoted 8 lines
Quoted 5 lines

I see,

shouldn't you instead provide a gpiolib driver for tca6416 and use the generic gpio_keys driver ??

Right. The fact that the driver precludes all otehr gpios from being used is a major drawback.

[Sriram] gpio_keys implementation assumes that every key can generate an interrupt to the processor and also the state machine to process events will handle each line individually. Imagine if 16 keys are connected to the TCA controller and you have to query(assume it is polling, interrupt mode not possible - as you have single interrupt line to the processor for event on any of the 16 input lines) 16 lines individually over i2c bus - the associated overhead is too high. Instead this implementation handles the necessary book-keeping in one simple function (get status of all 16 lines in one read transaction). Building on a GPIO implementation and using gpio-keys above will be both clumsy and incur runtime overhead as against a direct keypad driver.

More often(as on AM3517EVM) the keypad keys are not mixed with other GPIO keys. The initial implementation includes key_mask to identify the keys to be used for keypad and the others are logically not modified. Hence the implementation can be extended if need arises to overcome this restriction.

Quoted 19 lines
Quoted 11 lines

drivers/input/keyboard/tca6416-keypad.c line 246

Quoted 3 lines
drivers/input/keyboard/tca6416-keypad.c new file +1 -0
+	if (!chip->use_polling) {

IMO, you should only use polling if the irq line isn't connected.

drivers/input/keyboard/tca6416-keypad.c line 248

Quoted 2 lines
drivers/input/keyboard/tca6416-keypad.c new file +2 -0
+		if (pdata->irq_is_gpio)
+			chip->irqnum = gpio_to_irq(pdata->irqnum);

you can pass the irq number via i2c_board_info. Use it.

Quoted 7 lines

drivers/input/keyboard/tca6416-keypad.c line 252

Quoted 4 lines
drivers/input/keyboard/tca6416-keypad.c new file +4 -0
+		else
+			chip->irqnum = pdata->irqnum;
+
+		ret = request_irq(chip->irqnum, tca6416_keys_isr,

it's an i2c driver!!! this should be request_threaded_irq()

Quoted 2 lines

Threaded IRQ probably does not fit well when you want to support both interrupt and polling in the same driver...

[Sriram] All the core logic (including I2C transactions) is implemented through a work queue implementation. The ISR is slim and only schedules the work queue. This also enables the implementation to be easily adaptable for both interrupt/polled mode.

maintainer
#7 lore raw

Re: [PATCH 1/3] TCA6416 keypad : Implement keypad driver for keys interfaced to TCA6416

Quoted 44 lines · Sriramakrishnan
Quoted 22 lines

-----Original Message-----
From: Dmitry Torokhov [mailto:[email protected]]
Sent: Friday, February 26, 2010 1:58 PM
To: Felipe Balbi
Cc: Govindarajan, Sriramakrishnan; [email protected]; linux- [email protected]
Subject: Re: [PATCH 1/3] TCA6416 keypad : Implement keypad driver for keys interfaced to TCA6416

Quoted 11 lines · Felipe Balbi

Hi,

Quoted 3 lines · Sriramakrishnan

This patch implements a simple Keypad driver that functions as an I2C client. It handles key press events for keys connected to TCA6416 I2C based IO expander.

what's wrong with gpio-keys ??

Quoted 1 line

+ * Implementation based on drivers/input/keyboard/gpio_keys.c

Quoted 8 lines
Quoted 5 lines

I see,

shouldn't you instead provide a gpiolib driver for tca6416 and use the generic gpio_keys driver ??

Right. The fact that the driver precludes all otehr gpios from being used is a major drawback.

[Sriram] gpio_keys implementation assumes that every key can generate an interrupt to the processor and also the state machine to process events will handle each line individually. Imagine if 16 keys are connected to the TCA controller and you have to query(assume it is polling, interrupt mode not possible - as you have single interrupt line to the processor for event on any of the 16 input lines) 16 lines individually over i2c bus - the associated overhead is too high. Instead this implementation handles the necessary book-keeping in one simple function (get status of all 16 lines in one read transaction). Building on a GPIO implementation and using gpio-keys above will be both clumsy and incur runtime overhead as against a direct keypad driver.

Quoted 5 lines

More often(as on AM3517EVM) the keypad keys are not mixed with other GPIO keys. The initial implementation includes key_mask to identify the keys to be used for keypad and the others are logically not modified. Hence the implementation can be extended if need arises to overcome this restriction.

In this case you should not build on gpio_keys at all but select some other keyboard as an example that smply uses keytable with set of keycodes, single interrupt, etc. The overhead of all gpio_keys data structures is not needed here.

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines

drivers/input/keyboard/tca6416-keypad.c line 246

Quoted 3 lines
drivers/input/keyboard/tca6416-keypad.c new file +1 -0
+	if (!chip->use_polling) {

IMO, you should only use polling if the irq line isn't connected.

drivers/input/keyboard/tca6416-keypad.c line 248

Quoted 2 lines
drivers/input/keyboard/tca6416-keypad.c new file +2 -0
+		if (pdata->irq_is_gpio)
+			chip->irqnum = gpio_to_irq(pdata->irqnum);

you can pass the irq number via i2c_board_info. Use it.

drivers/input/keyboard/tca6416-keypad.c line 252

Quoted 4 lines
drivers/input/keyboard/tca6416-keypad.c new file +4 -0
+		else
+			chip->irqnum = pdata->irqnum;
+
+		ret = request_irq(chip->irqnum, tca6416_keys_isr,

it's an i2c driver!!! this should be request_threaded_irq()

Quoted 8 lines
Quoted 2 lines

Threaded IRQ probably does not fit well when you want to support both interrupt and polling in the same driver...

[Sriram] All the core logic (including I2C transactions) is implemented through a work queue implementation. The ISR is slim and only schedules the work queue. This also enables the implementation to be easily adaptable for both interrupt/polled mode.

Fair enough but you need to ensure that you do not leave irq unbalances (in regards to enable/disable) when you using workqueue and disabling interrupt in the ISR.

Signature · 1 line
Dmitry
#9 lore raw

Re: [PATCH 1/3] TCA6416 keypad : Implement keypad driver for keys interfaced to TCA6416

In reply to Sriramakrishnan

Hi,

Quoted 4 lines

+
+       chip = kzalloc(sizeof(struct tca6416_keypad_chip), GFP_KERNEL);
+       if (chip == NULL)
+               return -ENOMEM;

Check for i2c functionality support ?

Quoted 10 lines

+               ret = request_irq(chip->irqnum, tca6416_keys_isr,
+                               IRQF_SHARED | IRQF_TRIGGER_FALLING ,
+                               "tca6416-keypad", chip);
+               if (ret) {
+                       dev_dbg(&client->dev,
+                               "Unable to claim irq %d; error %d\n",
+                               chip->irqnum, ret);
+                       goto fail3;
+               }
+               disable_irq(chip->irqnum);

The error path needs to free_irq() in case of any failure after this, for an interrupt based driver.

Thanks,
Anirudh
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#8 lore raw

RE: [PATCH 1/3] TCA6416 keypad : Implement keypad driver for keys interfaced to TCA6416

In reply to Dmitry Torokhov
Quoted 9 lines

-----Original Message-----
From: Dmitry Torokhov [mailto:[email protected]]
Sent: Saturday, February 27, 2010 2:30 PM
To: Govindarajan, Sriramakrishnan
Cc: Felipe Balbi; [email protected]; [email protected]
Subject: Re: [PATCH 1/3] TCA6416 keypad : Implement keypad driver for keys interfaced to TCA6416

---snip---

Quoted 29 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

I see,

shouldn't you instead provide a gpiolib driver for tca6416 and use

the

Quoted 19 lines
Quoted 5 lines
Quoted 2 lines

generic gpio_keys driver ??

Right. The fact that the driver precludes all otehr gpios from being used is a major drawback.

[Sriram] gpio_keys implementation assumes that every key can generate an interrupt to the processor and also the state machine to process events will handle each line individually. Imagine if 16 keys are connected to the TCA controller and you have to query(assume it is polling, interrupt mode not possible - as you have single interrupt line to the processor for event on any of the 16 input lines) 16 lines individually over i2c bus - the associated overhead is too high. Instead this implementation handles the necessary book-keeping in one simple function (get status of all 16 lines in one read transaction). Building on a GPIO implementation and using gpio-keys above will be both clumsy and incur runtime overhead as against a direct keypad driver.

Quoted 5 lines

More often(as on AM3517EVM) the keypad keys are not mixed with other GPIO keys. The initial implementation includes key_mask to identify the keys to be used for keypad and the others are logically not modified. Hence the implementation can be extended if need arises to overcome this restriction.

Quoted 5 lines

In this case you should not build on gpio_keys at all but select some other keyboard as an example that smply uses keytable with set of keycodes, single interrupt, etc. The overhead of all gpio_keys data structures is not needed here.

[Sriram] I am working on cleaning up the driver to use a simpler book keeping structure(move away from gpio_keys). Will post the reworked patch shortly.

---snip ---

Quoted 10 lines
Quoted 6 lines

[Sriram] All the core logic (including I2C transactions) is implemented through a work queue implementation. The ISR is slim and only schedules the work queue. This also enables the implementation to be easily adaptable for both interrupt/polled mode.

Fair enough but you need to ensure that you do not leave irq unbalances (in regards to enable/disable) when you using workqueue and disabling interrupt in the ISR.

[Sriram] Will ensure that this is addressed appropriately (including cleanup on error conditions).

---
Sriram