Skip to contentSkip to conversation

Blackfin BF54x Input Keypad controller driver

PATCH In review Bryan Wu 2 participants 2 messages Oct 4, 2007 – Oct 9, 2007

Subsystems (2)
lore
Share & tools
lore

Bryan Wu

author
#0 lore raw

PATCH 1/1 Blackfin BF54x Input Keypad controller driver

From: Michael Hennerich <[email protected]> Blackfin BF54x Input Keypad controller driver:

[try #2] Changelog:
- Coding style issue fixes
- using a temp variable for bf54x_kpad->input
- Other updates according to Dmitry's review

---
 drivers/input/keyboard/Kconfig               |    9 +
 drivers/input/keyboard/Makefile              |    2 +-
 drivers/input/keyboard/bf54x-keys.c          |  387 ++++++++++++++++++++++++++
 include/asm-blackfin/mach-bf548/bf54x_keys.h |   17 ++
 4 files changed, 414 insertions(+), 1 deletions(-)
 create mode 100644 drivers/input/keyboard/bf54x-keys.c
 create mode 100644 include/asm-blackfin/mach-bf548/bf54x_keys.h
drivers/input/keyboard/Kconfig +9 -0
index c97d5eb..2136a9e 100644
@@ -253,4 +253,13 @@ config KEYBOARD_GPIO
 	  To compile this driver as a module, choose M here: the
 	  module will be called gpio-keys.
 
+config KEYBOARD_BFIN
+	tristate "Blackfin BF54x keypad support"
+	depends on (BF54x)
+	help
+	  Say Y here if you want to use the BF54x keypad.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called bf54x-keypad.
+	  
 endif
drivers/input/keyboard/Makefile +1 -1
index 28d211b..3123277 100644
@@ -21,4 +21,4 @@ obj-$(CONFIG_KEYBOARD_OMAP)		+= omap-keypad.o
 obj-$(CONFIG_KEYBOARD_PXA27x)		+= pxa27x_keyboard.o
 obj-$(CONFIG_KEYBOARD_AAED2000)		+= aaed2000_kbd.o
 obj-$(CONFIG_KEYBOARD_GPIO)		+= gpio_keys.o
-
+obj-$(CONFIG_KEYBOARD_BFIN)		+= bf54x-keys.o
drivers/input/keyboard/bf54x-keys.c new file +387 -0

387 lines not on this page · raw message

include/asm-blackfin/mach-bf548/bf54x_keys.h new file +17 -0
new file mode 100644
index 0000000..a872a2f
@@ -0,0 +1,17 @@
+#ifndef _BFIN_KPAD_H
+#define _BFIN_KPAD_H
+
+struct bfin_kpad_platform_data {
+	int rows;
+	int cols;
+	int *keymap;
+	unsigned short keymapsize;
+	unsigned short repeat;
+	u32 debounce_time;	/* in ns */
+	u32 coldrive_time;	/* in ns */
+	u32 keyup_test_interval; /* in ms */
+};
+
+#define KEYVAL(col, row, val) (((1 << col) << 24) | ((1 << row) << 16) | (val))
+
+#endif
Signature · 1 line
1.5.2
maintainer
#1 lore raw

Hi Bryan,

Quoted 8 lines · Bryan Wu

From: Michael Hennerich <[email protected]> Blackfin BF54x Input Keypad controller driver:

[try #2] Changelog:
- Coding style issue fixes
- using a temp variable for bf54x_kpad->input
- Other updates according to Dmitry's review

I would like to ask you for a couple of additional changes:

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+static u16 per_rows[] = {

Change to "const" perhaps?

drivers/input/keyboard/bf54x-keys.c line 67

Quoted 12 lines
drivers/input/keyboard/bf54x-keys.c new file +12 -0
+       P_KEY_ROW7,
+       P_KEY_ROW6,
+       P_KEY_ROW5,
+       P_KEY_ROW4,
+       P_KEY_ROW3,
+       P_KEY_ROW2,
+       P_KEY_ROW1,
+       P_KEY_ROW0,
+       0
+};
+
+static u16 per_cols[] = {

Same here.

Quoted 8 lines
drivers/input/keyboard/bf54x-keys.c new file +8 -0
+       P_KEY_COL7,
+       P_KEY_COL6,
+       P_KEY_COL5,
+       P_KEY_COL4,
+       P_KEY_COL3,
+       P_KEY_COL2,
+       P_KEY_COL1,
+       P_KEY_COL0,

drivers/input/keyboard/bf54x-keys.c line 155

Quoted 10 lines
drivers/input/keyboard/bf54x-keys.c new file +10 -0
+       0
+};
+
+
+       if (bfin_kpad_get_keypressed(bf54x_kpad)) {
+               disable_irq(bf54x_kpad->irq);
+               bf54x_kpad->lastkey = key;
+               bf54x_kpad->timer.expires = jiffies
+                                       + bf54x_kpad->keyup_test_jiffies;
+               add_timer(&bf54x_kpad->timer);

mod_timer()?

drivers/input/keyboard/bf54x-keys.c line 266

Quoted 2 lines
drivers/input/keyboard/bf54x-keys.c new file +2 -0
+
+       input->keycode = pdata->keymap;

Please consider allocating memory for keycode so that platfrom data can be kept constant.

drivers/input/keyboard/bf54x-keys.c line 275

Quoted 9 lines
drivers/input/keyboard/bf54x-keys.c new file +9 -0
+       input->keycodesize = sizeof(unsigned short);
+       input->keycodemax = pdata->keymapsize;
+
+       /* setup input device */
+       set_bit(EV_KEY, input->evbit);
+
+       if (pdata->repeat)
+               set_bit(EV_REP, input->evbit);
+

__set_bit() should suffice here and above.

Quoted 9 lines
drivers/input/keyboard/bf54x-keys.c new file +9 -0
+       for (i = 0; i < pdata->keymapsize; i++)
+               __set_bit(pdata->keymap[i] & KEY_MAX, input->keybit);
+
+       __clear_bit(KEY_RESERVED, input->keybit);
+
+       error = input_register_device(input);
+
+       if (error) {
+               printk(KERN_ERR DRV_NAME

drivers/input/keyboard/bf54x-keys.c line 294

Quoted 10 lines
drivers/input/keyboard/bf54x-keys.c new file +10 -0
+                       ": Unable to register input device (%d)\n", error);
+               goto out4;
+       }
+
+       /* Init Keypad Key Up/Release test timer */
+
+       init_timer(&bf54x_kpad->timer);
+       bf54x_kpad->timer.function = bfin_kpad_timer;
+       bf54x_kpad->timer.data = (unsigned long) pdev;
+

setup_timer()?

Quoted 44 lines
drivers/input/keyboard/bf54x-keys.c new file +44 -0
+
+       bfin_write_KPAD_PRESCALE(bfin_kpad_get_prescale(TIME_SCALE));
+
+       bfin_write_KPAD_CTL((((pdata->cols - 1) << 13) & KPAD_COLEN) |
+                               (((pdata->rows - 1) << 10) & KPAD_ROWEN) |
+                               (2 & KPAD_IRQMODE));
+
+
+       bfin_write_KPAD_CTL(bfin_read_KPAD_CTL() | KPAD_EN);
+
+       printk(KERN_ERR DRV_NAME
+               ": Blackfin BF54x Keypad registered IRQ %d\n", bf54x_kpad->irq);
+
+       return 0;
+
+
+out4:
+       input_free_device(input);
+out3:
+       free_irq(bf54x_kpad->irq, pdev);
+out2:
+       peripheral_free_list(&per_cols[MAX_RC - pdata->cols]);
+out1:
+       peripheral_free_list(&per_rows[MAX_RC - pdata->rows]);
+out:
+       kfree(bf54x_kpad);
+       platform_set_drvdata(pdev, NULL);
+
+       return error;
+}
+
+static int __devexit bfin_kpad_remove(struct platform_device *pdev)
+{
+       struct bfin_kpad_platform_data *pdata = pdev->dev.platform_data;
+       struct bf54x_kpad *bf54x_kpad = platform_get_drvdata(pdev);
+
+
+       del_timer_sync(&bf54x_kpad->timer);
+       free_irq(bf54x_kpad->irq, pdev);
+
+       peripheral_free_list(&per_rows[MAX_RC - pdata->rows]);
+       peripheral_free_list(&per_cols[MAX_RC - pdata->cols]);
+
+       input_unregister_device(bf54x_kpad->input);

drivers/input/keyboard/bf54x-keys.c line 348

Quoted 10 lines
drivers/input/keyboard/bf54x-keys.c new file +10 -0
+
+       kfree(bf54x_kpad);
+       platform_set_drvdata(pdev, NULL);
+
+       return 0;
+}
+
+#ifdef CONFIG_PM
+static int bfin_kpad_suspend(struct platform_device *pdev, pm_message_t state)
+{

Do you need these empty functions? At least stop timer here.

Thanks!

Oh, one more thing - do not access input->private directly - it is going away - use input_set_drvdata() and input_get_drvdata().

Signature · 1 line
Dmitry