input: twl4030_keypad driver
Subsystems (2)
From: David Brownell <[email protected]>
Driver for the twl4030 family keypad controller. This controller supports a key matrix of up to 8 rows by 8 columns. Board init code passes a description of the key matrix to the driver.
---
This is what's in the current OMAP tree, with two changes:
(a) includes a pending patch to remove OMAP-isms; (b) rename to remove another OMAP-ism.
drivers/input/keyboard/Kconfig | 11 drivers/input/keyboard/Makefile | 1 drivers/input/keyboard/twl4030_keypad.c | 489 ++++++++++++++++++++++++++++++ include/linux/i2c/twl4030.h | 9 4 files changed, 509 insertions(+), 1 deletion(-)
drivers/input/keyboard/Kconfig +11 -0
@@ -259,6 +259,17 @@ config KEYBOARD_OMAP To compile this driver as a module, choose M here: the module will be called omap-keypad. +config KEYBOARD_TWL4030 + tristate "TI TWL4030/TWL5030/TPS659x0 keypad support" + depends on TWL4030_CORE + help + Say Y here if your board use the keypad controller on + TWL4030 family chips. It's safe to say enable this + even on boards that don't use the keypad controller. + + To compile this driver as a module, choose M here: the + module will be called twl4030_keypad. + config KEYBOARD_PXA27x tristate "PXA27x/PXA3xx keypad support" depends on PXA27x || PXA3xx
drivers/input/keyboard/Makefile +1 -0
@@ -28,3 +28,4 @@ obj-$(CONFIG_KEYBOARD_HP7XX) += jornada obj-$(CONFIG_KEYBOARD_MAPLE) += maple_keyb.o obj-$(CONFIG_KEYBOARD_BFIN) += bf54x-keys.o obj-$(CONFIG_KEYBOARD_SH_KEYSC) += sh_keysc.o +obj-$(CONFIG_KEYBOARD_TWL4030) += twl4030_keypad.o
drivers/input/keyboard/twl4030_keypad.c new file +489 -0
489 lines not on this page · raw message
include/linux/i2c/twl4030.h +8 -1
@@ -255,11 +255,18 @@ struct twl4030_madc_platform_data {int irq_line; }; +/* Boards have uniqe mappings of {col, row} --> keycode. +* Column and row are 4 bits, but range only from 0..7; +* a PERSISTENT_KEY is "always on" and never reported. +*/ +#define KEY_PERSISTENT 0x00800000 +#define KEY (col, row, keycode) (((col) << 28) | ((row) << 24) | (keycode)) +#define PERSISTENT_KEY (c, r) KEY(c, r, KEY_PERSISTENT) +struct twl4030_keypad_data {int rows;int cols;int *keymap; -int irq;unsigned int keymapsize;unsigned int rep:1 ; };
Hi David,
Quoted 38 lines
drivers/input/keyboard/twl4030_keypad.c new file +38
-0+ +static void twl4030_kp_scan (struct twl4030_keypad *kp,int release_all) +{ +u16 new_state[MAX_ROWS ]; +int col, row; + +if (release_all) +memset (new_state,0 ,sizeof (new_state)); +else { +/* check for any changes */ +int ret =twl4030_read_kp_matrix_state (kp, new_state); + +if (ret <0 )/* panic ... */ +return ; +if (twl4030_is_in_ghost_state (kp, new_state)) +return ; + } + +/* check for changes and print those */ +for (row =0 ; row < kp->n_rows; row++) { +int changed = new_state[row] ^ kp->kp_state[row]; + +if (!changed) +continue ; + +for (col =0 ; col < kp->n_cols; col++) { +int key; + +if (!(changed & (1 << col))) +continue ; + +dev_dbg (kp->dbg_dev,"key [%d:%d] %s\n" , row, col, + (new_state[row] & (1 << col)) ? +"press" :"release" ); + + key =twl4030_find_key (kp, col, row); +if (key <0 ) + dev_warn(kp->dbg_dev,
drivers/input/keyboard/twl4030_keypad.c line 262
Quoted 10 lines
drivers/input/keyboard/twl4030_keypad.c new file +10
-0+"Spurious key event %d-%d\n" , + col, row); + else if (key & KEY_PERSISTENT) + continue; + else + input_report_key(kp->input, key, + new_state[row] & (1 << col)); + } + kp->kp_state[row] = new_state[row]; + }
where do I find input_sync(...) being called?
Quoted 16 lines
drivers/input/keyboard/twl4030_keypad.c new file +16
-0+ +/* +* Registers keypad device with input subsystem +* and configures TWL4030 keypad registers +*/ +static int __devinit twl4030_kp_probe (struct platform_device *pdev) +{ +u8 reg; +int i; +int ret =0 ; +struct twl4030_keypad *kp; +struct twl4030_keypad_data *pdata = pdev->dev.platform_data; + + kp =kzalloc (sizeof (*kp),GFP_KERNEL ); +if (!kp) +return -ENOMEM ;
drivers/input/keyboard/twl4030_keypad.c line 319
Quoted 10 lines
drivers/input/keyboard/twl4030_keypad.c new file +10
-0+ +if (!pdata->rows || !pdata->cols || !pdata->keymap) { +dev_err (&pdev->dev,"No rows, cols or keymap from pdata\n" ); +kfree (kp); +return -EINVAL ; + } + +/* ASSERT: cols <= 8, rows <= 8 */ + +dev_set_drvdata (&pdev->dev, kp);
How about platform_set_drvdata ??
Quoted 8 lines
drivers/input/keyboard/twl4030_keypad.c new file +8
-0+ +/* Get the debug Device */ + kp->dbg_dev = &pdev->dev; + + kp->input =input_allocate_device (); +if (!kp->input) { +kfree (kp); +return -ENOMEM ;
drivers/input/keyboard/twl4030_keypad.c line 337
Quoted 10 lines
drivers/input/keyboard/twl4030_keypad.c new file +10
-0+ } + + kp->keymap = pdata->keymap; + kp->keymapsize = pdata->keymapsize; + kp->n_rows = pdata->rows; + kp->n_cols = pdata->cols; + kp->irq =platform_get_irq (pdev,0 ); + +/* setup input device */ +set_bit (EV_KEY , kp->input->evbit);
__set_bit please.
drivers/input/keyboard/twl4030_keypad.c line 345
Quoted 8 lines
drivers/input/keyboard/twl4030_keypad.c new file +8
-0+ +/* Enable auto repeat feature of Linux input subsystem */ +if (pdata->rep) +set_bit (EV_REP , kp->input->evbit); + +for (i =0 ; i < kp->keymapsize; i++) +set_bit (kp->keymap[i] &KEYNUM_MASK , + kp->input->keybit);
Ditto.
Quoted 19 lines
drivers/input/keyboard/twl4030_keypad.c new file +19
-0+ + kp->input->name ="TWL4030 Keypad" ; + kp->input->phys ="twl4030_keypad/input0" ; + kp->input->dev.parent = &pdev->dev; + + kp->input->id.bustype =BUS_HOST ; + kp->input->id.vendor =0x0001 ; + kp->input->id.product =0x0001 ; + kp->input->id.version =0x0003 ; + + kp->input->keycode = kp->keymap; + kp->input->keycodesize =sizeof (unsigned int ); + kp->input->keycodemax = kp->keymapsize; + + ret =input_register_device (kp->input); +if (ret <0 ) { +dev_err (kp->dbg_dev, +"Unable to register twl4030 keypad device\n" ); + goto err2;
drivers/input/keyboard/twl4030_keypad.c line 424
Quoted 10 lines
drivers/input/keyboard/twl4030_keypad.c new file +9
-0+ } + +/* +* This ISR will always execute in kernel thread context because of +* the need to access the TWL4030 over the I2C bus. +* +* NOTE: we assume this host is wired to TWL4040 INT1, not INT2 ... +*/ + ret =request_irq (kp->irq, do_kp_irq,0 , pdev->name, kp);
How about adding IRQF_SAMPLE_RANDOME here ??
Quoted 9 lines
drivers/input/keyboard/twl4030_keypad.c new file +9
-0+if (ret <0 ) { +dev_info (kp->dbg_dev,"request_irq failed for irq no=%d\n" , + kp->irq); + goto err3; + }else { +/* Enable KP and TO interrupts now. */ + reg = (u8 ) ~(KEYP_IMR1_KP |KEYP_IMR1_TO ); + ret =twl4030_kpwrite_u8 (kp, reg,KEYP_IMR1 ); +if (ret <0 )
drivers/input/keyboard/twl4030_keypad.c line 443
Quoted 10 lines
drivers/input/keyboard/twl4030_keypad.c new file +10
-0+ goto err5; + } + +return ret; +err5: +/* mask all events - we don't care about the result */ + (void )twl4030_kpwrite_u8 (kp,0xff ,KEYP_IMR1 ); +free_irq (kp->irq,NULL ); +err3: +input_unregister_device (kp->input);
No free_device after input_unregister_device. Add kp->input = NULL above.
drivers/input/keyboard/twl4030_keypad.c line 452
Quoted 9 lines
drivers/input/keyboard/twl4030_keypad.c new file +9
-0+err2: +input_free_device (kp->input); + +return -ENODEV ; +} + +static int __devexit twl4030_kp_remove(struct platform_device *pdev) +{ +struct twl4030_keypad *kp =dev_get_drvdata (&pdev->dev);
platform_get_drvdata ?
Signature · 3 lines
---Trilok Soni http://triloksoni.wordpress.com http://www.linkedin.com/in/triloksoni
Hi,
Quoted 15 lines · Trilok Soni
Quoted 15 lines
(quoted diff) +15
-0+ +static void twl4030_kp_scan(struct twl4030_keypad *kp, int release_all) +{ + u16 new_state[MAX_ROWS]; + int col, row; + + ... + + key = twl4030_find_key(kp, col, row); + if (key < 0) + dev_warn(kp->dbg_dev, + "Spurious key event %d-%d\n", + col, row); + else if (key & KEY_PERSISTENT) + continue;
Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+ else + input_report_key(kp->input, key, + new_state[row] & (1 << col)); + } + kp->kp_state[row] = new_state[row]; + }where do I find
input_sync(...)being called?
Yeah, I was wondering about that too. The code obviously works without it ... I'll add that call anyway.
Quoted 4 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ + dev_set_drvdata(&pdev->dev, kp);How about
platform_set_drvdata??
Those calls are exactly equivalent, although you're right that platform_* versions are preferred. Either is correct.
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ /* setup input device */ + set_bit(EV_KEY, kp->input->evbit);
__set_bitplease.
Quoted 10 lines
Review
Quoted 8 lines
(quoted diff) +8
-0+ + /* Enable auto repeat feature of Linux input subsystem */ + if (pdata->rep) + set_bit(EV_REP, kp->input->evbit); + + for (i = 0; i < kp->keymapsize; i++) + set_bit(kp->keymap[i] & KEYNUM_MASK, + kp->input->keybit);Ditto.
The practical difference there being that __set_bit() is a bit less costly (space and time), being non-atomic; there is no semantic difference. Either is correct.
Quoted 9 lines
Review
Quoted 7 lines
(quoted diff) +7
-0+ /* + * This ISR will always execute in kernel thread context because of + * the need to access the TWL4030 over the I2C bus. + * + * NOTE: we assume this host is wired to TWL4040 INT1, not INT2 ... + */ + ret = request_irq(kp->irq, do_kp_irq, 0, pdev->name, kp);How about adding
IRQF_SAMPLE_RANDOMEhere ??
Input system does that automagically; it should not be sampled twice.
Quoted 11 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+err5: + /* mask all events - we don't care about the result */ + (void) twl4030_kpwrite_u8(kp, 0xff, KEYP_IMR1); + free_irq(kp->irq, NULL); +err3: + input_unregister_device(kp->input);No
free_deviceafterinput_unregister_device. Addkp->input= NULL above.Quoted 2 lines
(quoted diff) +2
-0+err2: + input_free_device(kp->input);
and kfree(kp) was missing too ...
I'll merge the following with any other feedback.
- Dave
--- drivers/input/keyboard/twl4030_keypad.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/input/keyboard/twl4030_keypad.c +8 -6
@@ -260,6 +260,7 @@ static void twl4030_kp_scan(struct twl40 } kp->kp_state[row] = new_state[row]; } +input_sync (kp->input); }/*
@@ -316,7 +317,7 @@ static int __devinit twl4030_kp_probe(st/* ASSERT: cols <= 8, rows <= 8 */ -dev_set_drvdata (&pdev->dev, kp); +platform_set_drvdata (pdev, kp);/* Get the debug Device */ kp->dbg_dev = &pdev->dev;
@@ -334,14 +335,14 @@ static int __devinit twl4030_kp_probe(st kp->irq =platform_get_irq (pdev,0 );/* setup input device */ -set_bit (EV_KEY , kp->input->evbit); +__set_bit (EV_KEY , kp->input->evbit);/* Enable auto repeat feature of Linux input subsystem */ if (pdata->rep) -set_bit (EV_REP , kp->input->evbit); +__set_bit (EV_REP , kp->input->evbit);for (i =0 ; i < kp->keymapsize; i++) -set_bit (kp->keymap[i] &KEYNUM_MASK , +__set_bit (kp->keymap[i] &KEYNUM_MASK , kp->input->keybit); kp->input->name ="TWL4030 Keypad" ;
@@ -441,15 +442,16 @@ err5:free_irq (kp->irq,NULL ); err3:input_unregister_device (kp->input); + kp->input =NULL ; err2:input_free_device (kp->input); - +kfree (kp);return -ENODEV ; } static int __devexit twl4030_kp_remove(struct platform_device *pdev) { -struct twl4030_keypad *kp =dev_get_drvdata (&pdev->dev); +struct twl4030_keypad *kp =platform_get_drvdata (pdev);free_irq (kp->irq, kp);input_unregister_device (kp->input);
Trilok Soni
Reviewed-byHi David,
Quoted 55 lines · David Brownell
Hi,
--- drivers/input/keyboard/twl4030_keypad.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)drivers/input/keyboard/twl4030_keypad.c +7
-5@@ -260,6 +260,7 @@ static void twl4030_kp_scan(struct twl40 } kp->kp_state[row] = new_state[row]; } +input_sync (kp->input); }/* @@ -316,7 +317,7 @@ static int __devinit twl4030_kp_probe(st/* ASSERT: cols <= 8, rows <= 8 */ -dev_set_drvdata (&pdev->dev, kp); +platform_set_drvdata (pdev, kp);/* Get the debug Device */ kp->dbg_dev = &pdev->dev;@@ -334,14 +335,14 @@ static int __devinit twl4030_kp_probe(st kp->irq =platform_get_irq (pdev,0 );/* setup input device */ -set_bit (EV_KEY , kp->input->evbit); +__set_bit (EV_KEY , kp->input->evbit);/* Enable auto repeat feature of Linux input subsystem */ if (pdata->rep) -set_bit (EV_REP , kp->input->evbit); +__set_bit (EV_REP , kp->input->evbit);for (i =0 ; i < kp->keymapsize; i++) -set_bit (kp->keymap[i] &KEYNUM_MASK , +__set_bit (kp->keymap[i] &KEYNUM_MASK , kp->input->keybit); kp->input->name ="TWL4030 Keypad" ;@@ -441,15 +442,16 @@ err5:free_irq (kp->irq,NULL ); err3:input_unregister_device (kp->input); + kp->input =NULL ; err2:input_free_device (kp->input); - +kfree (kp);
drivers/input/keyboard/twl4030_keypad.c err5: · line 457
Quoted 10 lines
drivers/input/keyboard/twl4030_keypad.c +1
-1return -ENODEV ; } static int __devexit twl4030_kp_remove(struct platform_device *pdev) { -struct twl4030_keypad *kp =dev_get_drvdata (&pdev->dev); +struct twl4030_keypad *kp =platform_get_drvdata (pdev);free_irq (kp->irq, kp);input_unregister_device (kp->input);
Thanks for making changes:
Signature · 3 lines
---Trilok Soni http://triloksoni.wordpress.com http://www.linkedin.com/in/triloksoni
Quoted 6 lines · David Brownell
Driver for the twl4030 family keypad controller. This controller supports a key matrix of up to 8 rows by 8 columns. Board init code passes a description of the key matrix to the driver.
Signed-off-by David Brownell <[email protected]>---
[SNIP]
include/linux/i2c/twl4030.h struct twl4030_madc_platform_data { · line 263
Quoted 12 lines
include/linux/i2c/twl4030.h +6
-0@@ -255,11 +255,18 @@ struct twl4030_madc_platform_data {int irq_line; }; +/* Boards have uniqe mappings of {col, row} --> keycode. +* Column and row are 4 bits, but range only from 0..7; +* a PERSISTENT_KEY is "always on" and never reported. +*/ +#define KEY_PERSISTENT 0x00800000 +#define KEY (col, row, keycode) (((col) << 28) | ((row) << 24) |
(keycode))
The same KEY macro is defined in:
arch/arm/mach-pxa/include/mach/pxa27x_keypad.harch/arm/plat-omap/include/mach/keypad.h
I also have a keypad driver for the ep93xx that uses the same macro.
Shouldn't/couldn't this be generalized and added to the include/linux/input.h file? Allowing 4-bits for row/col gives a maximum key matrix of 16x16 keys which should be enough for just about anything.
Regards,
Hartley
Quoted 8 lines · hartleys
include/linux/i2c/twl4030.h struct twl4030_madc_platform_data {
Quoted 6 lines
include/linux/i2c/twl4030.h +6
-0+/* Boards have uniqe mappings of {col, row} --> keycode. +* Column and row are 4 bits, but range only from 0..7; +* a PERSISTENT_KEY is "always on" and never reported. +*/ +#define KEY_PERSISTENT 0x00800000 +#define KEY (col, row, keycode) (((col) << 28) | ((row) << 24) |(keycode))
Quoted 4 lines
The same KEY macro is defined in:
arch/arm/mach-pxa/include/mach/pxa27x_keypad.harch/arm/plat-omap/include/mach/keypad.h
I copied it from the OMAP version as part of removing needless OMAP dependencies from this driver.
Quoted 5 lines
I also have a keypad driver for the ep93xx that uses the same macro.
Shouldn't/couldn't this be generalized and added to the
include/linux/input.hfile? Allowing 4-bits for row/col gives a maximum key matrix of 16x16 keys which should be enough for just about anything.
Makes sense. But that's not what this patch is about, and I also think the KEY prefix is probably too generic.
I'd support an overall cleanup patch that fixes
all those things at once.
- Dave
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 9 lines · David Brownell
Quoted 8 lines · hartleys
Review
Quoted 6 lines
(quoted diff) +6
-0+/* Boards have uniqe mappings of {col, row} --> keycode. + * Column and row are 4 bits, but range only from 0..7; + * a PERSISTENT_KEY is "always on" and never reported. + */ +#define KEY_PERSISTENT 0x00800000 #define KEY(col, +row, keycode) (((col) << 28) | ((row) << 24) |(keycode))
Quoted 7 lines
Quoted 4 lines
The same KEY macro is defined in:
arch/arm/mach-pxa/include/mach/pxa27x_keypad.harch/arm/plat-omap/include/mach/keypad.hI copied it from the OMAP version as part of removing needless OMAP dependencies from this driver.
Makes sense.
Quoted 9 lines
Quoted 6 lines
I also have a keypad driver for the ep93xx that uses the same macro.
Shouldn't/couldn't this be generalized and added to the
include/linux/input.hfile? Allowing 4-bits for row/col gives a maximum key matrix of 16x16 keys which should be enough for just about anything.Makes sense. But that's not what this patch is about, and I also think the KEY prefix is probably too generic.
Understand. Just noticed the common macro and wondered if something should be done to generalize it.
Quoted 1 line
I'd support an overall cleanup patch that fixes all those things at once.
How's this for a starting point? I'm willing to create a cleanup patch for all the mach-omap1, mach-omap2, and mach-pxa users.
---
include/linux/input.h +8 -0
@@ -598,6 +598,14 @@ struct input_absinfo {#define KEY_CNT (KEY_MAX+1)/* +* Macro to pack the row/col of a key on a matrix keypad and it's associated +* KEY_* code into into an array. 4 bits are used for both the row and column +* allowing for up to a 16x16 keypad. The row (_r) and column (_c) are +* interchangable depending on a keypad drivers usage. +*/ +#define MATRIX_KEY (_r, _c, _v) (((_r) << 28) | ((_c) << 24) | (_v)) + +/* * Relative axes */
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 6 lines · hartleys
Quoted 1 line
I'd support an overall cleanup patch that fixes all those things at once.
How's this for a starting point? I'm willing to create a cleanup patch for all the mach-omap1, mach-omap2, and mach-pxa users.
Signed-off-by H Hartley Sweeten <[email protected]>
I think none of the twl4030 keypad users are in mainline, so far...
My first reaction to this is that it's a bit incomplete. It replaces only the KEY() macro in the $SUBJECT patch:
- There are two more public ones (for board files):
* KEY_PERSISTENT flags row/column values to ignore
* PERSISTENT_KEY (sigh) generates a row/col entry with such a marking (instead of a keycode)
- Plus two driver-internal ones:
* ROWCOL_MASK to strip R/C from KEY()
* KEYCODE_MASK to stip the keycode from a KEY()
If there is going to be something reusable across the whole input subsystem (for drivers that don't need fancy stuff), it should really address the whole problem...
- Dave
Quoted 18 lines
---
include/linux/input.h +0
-0@@ -598,6 +598,14 @@ struct input_absinfo { #define KEY_CNT (KEY_MAX+1)
/*
+ * Macro to pack the row/col of a key on a matrix keypad and it's associated
+ * KEY_* code into into an array. 4 bits are used for both the row and column
+ * allowing for up to a 16x16 keypad. The row (_r) and column (_c) are
+ * interchangable depending on a keypad drivers usage.
+ */include/linux/input.h +3
-0+#define MATRIX_KEY (_r, _c, _v) (((_r) << 28) | ((_c) << 24) | (_v)) + +/*
Quoted 4 lines
* Relative axes
*/
--
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