* Add devicetree support to gpio-keys driver
@ 2014-02-14 15:38 Sascha Hauer
2014-02-14 15:38 ` [PATCH 1/4] input: Add BB_ prefix to KEY_ defines Sascha Hauer
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Sascha Hauer @ 2014-02-14 15:38 UTC (permalink / raw)
To: barebox
This adds devicetree support for the gpio-keys driver and the necessary
prerequisites.
Sascha
----------------------------------------------------------------
Sascha Hauer (4):
input: Add BB_ prefix to KEY_ defines
input: gpio-keys: separate internal data from platform_data
input: Add keycode to barebox key translation table
input: gpio-keys: Add devicetree probe support
arch/arm/boards/archosg9/board.c | 6 +-
arch/arm/boards/at91sam9261ek/init.c | 6 +-
arch/arm/boards/at91sam9m10g45ek/init.c | 14 +--
arch/arm/boards/at91sam9m10ihd/init.c | 2 +-
arch/arm/boards/usb-a926x/init.c | 8 +-
commands/edit.c | 18 ++--
common/menu.c | 18 ++--
drivers/input/Makefile | 1 +
drivers/input/gpio_keys.c | 156 ++++++++++++++++++++++++++------
drivers/input/keymap.c | 136 ++++++++++++++++++++++++++++
drivers/input/qt1070.c | 4 +-
include/gpio_keys.h | 7 --
include/input/keyboard.h | 10 ++
include/readkey.h | 34 +++----
lib/readkey.c | 36 ++++----
lib/readline.c | 26 +++---
16 files changed, 360 insertions(+), 122 deletions(-)
create mode 100644 drivers/input/keymap.c
create mode 100644 include/input/keyboard.h
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/4] input: Add BB_ prefix to KEY_ defines
2014-02-14 15:38 Add devicetree support to gpio-keys driver Sascha Hauer
@ 2014-02-14 15:38 ` Sascha Hauer
2014-02-14 15:38 ` [PATCH 2/4] input: gpio-keys: separate internal data from platform_data Sascha Hauer
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2014-02-14 15:38 UTC (permalink / raw)
To: barebox
Our KEY_ defines conflict with the standard Linux KEY_ defines, so
add a BB_ prefix to them.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/arm/boards/archosg9/board.c | 6 +++---
arch/arm/boards/at91sam9261ek/init.c | 6 +++---
arch/arm/boards/at91sam9m10g45ek/init.c | 14 ++++++-------
arch/arm/boards/at91sam9m10ihd/init.c | 2 +-
arch/arm/boards/usb-a926x/init.c | 8 ++++----
commands/edit.c | 18 ++++++++---------
| 18 ++++++++---------
drivers/input/qt1070.c | 4 ++--
include/readkey.h | 34 +++++++++++++++----------------
lib/readkey.c | 36 ++++++++++++++++-----------------
lib/readline.c | 26 ++++++++++++------------
11 files changed, 86 insertions(+), 86 deletions(-)
diff --git a/arch/arm/boards/archosg9/board.c b/arch/arm/boards/archosg9/board.c
index 6a12180..114c34e 100644
--- a/arch/arm/boards/archosg9/board.c
+++ b/arch/arm/boards/archosg9/board.c
@@ -56,11 +56,11 @@ static struct i2c_board_info i2c_devices[] = {
};
#if defined(CONFIG_KEYBOARD_TWL6030) && defined(CONFIG_KEYBOARD_GPIO)
static struct twl6030_pwrbtn_platform_data pwrbtn_data = {
- .code = KEY_ENTER
+ .code = BB_KEY_ENTER
};
static struct gpio_keys_button keys[] = {
- { .code = KEY_UP , .gpio = 43, .active_low = 1 },
- { .code = KEY_DOWN, .gpio = 44, .active_low = 1 },
+ { .code = BB_KEY_UP , .gpio = 43, .active_low = 1 },
+ { .code = BB_KEY_DOWN, .gpio = 44, .active_low = 1 },
};
static struct gpio_keys_platform_data gk_data = {
.buttons = keys,
diff --git a/arch/arm/boards/at91sam9261ek/init.c b/arch/arm/boards/at91sam9261ek/init.c
index c1d4d9d..9ebc16a 100644
--- a/arch/arm/boards/at91sam9261ek/init.c
+++ b/arch/arm/boards/at91sam9261ek/init.c
@@ -234,13 +234,13 @@ static void ek_add_device_lcdc(void) {}
#ifdef CONFIG_KEYBOARD_GPIO
struct gpio_keys_button keys[] = {
{
- .code = KEY_UP,
+ .code = BB_KEY_UP,
.gpio = AT91_PIN_PA26,
}, {
- .code = KEY_DOWN,
+ .code = BB_KEY_DOWN,
.gpio = AT91_PIN_PA25,
}, {
- .code = KEY_ENTER,
+ .code = BB_KEY_ENTER,
.gpio = AT91_PIN_PA24,
},
};
diff --git a/arch/arm/boards/at91sam9m10g45ek/init.c b/arch/arm/boards/at91sam9m10g45ek/init.c
index 34abe05..6503ebb 100644
--- a/arch/arm/boards/at91sam9m10g45ek/init.c
+++ b/arch/arm/boards/at91sam9m10g45ek/init.c
@@ -182,25 +182,25 @@ static void ek_device_add_leds(void) {}
#ifdef CONFIG_KEYBOARD_GPIO
struct gpio_keys_button keys[] = {
{
- .code = KEY_HOME,
+ .code = BB_KEY_HOME,
.gpio = AT91_PIN_PB6,
}, {
- .code = KEY_RETURN,
+ .code = BB_KEY_RETURN,
.gpio = AT91_PIN_PB7,
}, {
- .code = KEY_LEFT,
+ .code = BB_KEY_LEFT,
.gpio = AT91_PIN_PB14,
}, {
- .code = KEY_RIGHT,
+ .code = BB_KEY_RIGHT,
.gpio = AT91_PIN_PB15,
}, {
- .code = KEY_UP,
+ .code = BB_KEY_UP,
.gpio = AT91_PIN_PB16,
}, {
- .code = KEY_DOWN,
+ .code = BB_KEY_DOWN,
.gpio = AT91_PIN_PB17,
}, {
- .code = KEY_RETURN,
+ .code = BB_KEY_RETURN,
.gpio = AT91_PIN_PB18,
},
};
diff --git a/arch/arm/boards/at91sam9m10ihd/init.c b/arch/arm/boards/at91sam9m10ihd/init.c
index 61d7f9d..fc37af4 100644
--- a/arch/arm/boards/at91sam9m10ihd/init.c
+++ b/arch/arm/boards/at91sam9m10ihd/init.c
@@ -110,7 +110,7 @@ static void ek_add_device_mci(void) {}
struct qt1070_platform_data qt1070_pdata = {
.irq_pin = AT91_PIN_PB19,
- .code = { KEY_ENTER, KEY_ENTER, KEY_UP, KEY_DOWN, },
+ .code = { BB_KEY_ENTER, BB_KEY_ENTER, BB_KEY_UP, BB_KEY_DOWN, },
.nb_code = 4,
};
diff --git a/arch/arm/boards/usb-a926x/init.c b/arch/arm/boards/usb-a926x/init.c
index 2d4408b..4a28af0 100644
--- a/arch/arm/boards/usb-a926x/init.c
+++ b/arch/arm/boards/usb-a926x/init.c
@@ -339,16 +339,16 @@ struct gpio_led dab_mmx_leds[] = {
#ifdef CONFIG_KEYBOARD_GPIO
struct gpio_keys_button keys[] = {
{
- .code = KEY_UP,
+ .code = BB_KEY_UP,
.gpio = AT91_PIN_PB25,
}, {
- .code = KEY_HOME,
+ .code = BB_KEY_HOME,
.gpio = AT91_PIN_PB13,
}, {
- .code = KEY_DOWN,
+ .code = BB_KEY_DOWN,
.gpio = AT91_PIN_PA26,
}, {
- .code = KEY_ENTER,
+ .code = BB_KEY_ENTER,
.gpio = AT91_PIN_PC9,
},
};
diff --git a/commands/edit.c b/commands/edit.c
index 295d0a7..6764e84 100644
--- a/commands/edit.c
+++ b/commands/edit.c
@@ -456,7 +456,7 @@ static int do_edit(int argc, char *argv[])
c = read_key();
switch (c) {
- case KEY_UP:
+ case BB_KEY_UP:
if (!curline->prev)
continue;
@@ -464,7 +464,7 @@ static int do_edit(int argc, char *argv[])
cursy--;
textx = setpos(curline->data, linepos);
break;
- case KEY_DOWN:
+ case BB_KEY_DOWN:
if (!curline->next)
continue;
@@ -472,19 +472,19 @@ static int do_edit(int argc, char *argv[])
cursy++;
textx = setpos(curline->data, linepos);
break;
- case KEY_RIGHT:
+ case BB_KEY_RIGHT:
textx++;
break;
- case KEY_LEFT:
+ case BB_KEY_LEFT:
textx--;
break;
- case KEY_HOME:
+ case BB_KEY_HOME:
textx = 0;
break;
- case KEY_END:
+ case BB_KEY_END:
textx = curlen;
break;
- case KEY_PAGEUP:
+ case BB_KEY_PAGEUP:
for (i = 0; i < screenheight - 1; i++) {
if (!curline->prev)
break;
@@ -493,7 +493,7 @@ static int do_edit(int argc, char *argv[])
}
textx = setpos(curline->data, linepos);
break;
- case KEY_PAGEDOWN:
+ case BB_KEY_PAGEDOWN:
for (i = 0; i < screenheight - 1; i++) {
if (!curline->next)
break;
@@ -502,7 +502,7 @@ static int do_edit(int argc, char *argv[])
}
textx = setpos(curline->data, linepos);
break;
- case KEY_DEL:
+ case BB_KEY_DEL:
if (textx == curlen) {
if (curline->next)
merge_line(curline);
--git a/common/menu.c b/common/menu.c
index ef56190..4cefadb 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -303,7 +303,7 @@ int menu_show(struct menu *m)
int repaint = 0;
if (m->auto_select >= 0)
- ch = KEY_RETURN;
+ ch = BB_KEY_RETURN;
else
ch = read_key();
@@ -327,7 +327,7 @@ int menu_show(struct menu *m)
}
break;
}
- case KEY_UP:
+ case BB_KEY_UP:
m->selected = list_entry(m->selected->list.prev, struct menu_entry,
list);
if (&(m->selected->list) == &(m->entries)) {
@@ -336,7 +336,7 @@ int menu_show(struct menu *m)
}
repaint = 1;
break;
- case KEY_DOWN:
+ case BB_KEY_DOWN:
m->selected = list_entry(m->selected->list.next, struct menu_entry,
list);
if (&(m->selected->list) == &(m->entries)) {
@@ -353,11 +353,11 @@ int menu_show(struct menu *m)
m->selected->action(m, m->selected);
repaint = 1;
break;
- case KEY_ENTER:
- if (ch_previous == KEY_RETURN)
+ case BB_KEY_ENTER:
+ if (ch_previous == BB_KEY_RETURN)
break;
- case KEY_RETURN:
- if (ch_previous == KEY_ENTER)
+ case BB_KEY_RETURN:
+ if (ch_previous == BB_KEY_ENTER)
break;
clear();
gotoXY(1,1);
@@ -368,11 +368,11 @@ int menu_show(struct menu *m)
else
print_menu(m);
break;
- case KEY_HOME:
+ case BB_KEY_HOME:
m->selected = list_first_entry(&m->entries, struct menu_entry, list);
repaint = 1;
break;
- case KEY_END:
+ case BB_KEY_END:
m->selected = list_last_entry(&m->entries, struct menu_entry, list);
repaint = 1;
break;
diff --git a/drivers/input/qt1070.c b/drivers/input/qt1070.c
index 7b72965..1ee868d 100644
--- a/drivers/input/qt1070.c
+++ b/drivers/input/qt1070.c
@@ -32,8 +32,8 @@
#define QT1070_RESET_TIME 255
static int default_code[QT1070_NB_BUTTONS] = {
- KEY_ENTER, KEY_HOME, KEY_UP, KEY_DOWN,
- KEY_RIGHT, KEY_LEFT, KEY_CLEAR_SCREEN };
+ BB_KEY_ENTER, BB_KEY_HOME, BB_KEY_UP, BB_KEY_DOWN,
+ BB_KEY_RIGHT, BB_KEY_LEFT, BB_KEY_CLEAR_SCREEN };
struct qt1070_data {
int code[QT1070_NB_BUTTONS];
diff --git a/include/readkey.h b/include/readkey.h
index 2793f3f..8398ec2 100644
--- a/include/readkey.h
+++ b/include/readkey.h
@@ -4,25 +4,25 @@
#define CTL_CH(c) ((c) - 'a' + 1)
/* Ascii keys */
-#define KEY_ENTER '\n'
-#define KEY_RETURN '\r'
+#define BB_KEY_ENTER '\n'
+#define BB_KEY_RETURN '\r'
/* Misc. non-Ascii keys */
-#define KEY_UP CTL_CH('p') /* cursor key Up */
-#define KEY_DOWN CTL_CH('n') /* cursor key Down */
-#define KEY_RIGHT CTL_CH('f') /* Cursor Key Right */
-#define KEY_LEFT CTL_CH('b') /* cursor key Left */
-#define KEY_HOME CTL_CH('a') /* Cursor Key Home */
-#define KEY_ERASE_TO_EOL CTL_CH('k')
-#define KEY_REFRESH_TO_EOL CTL_CH('e')
-#define KEY_ERASE_LINE CTL_CH('x')
-#define KEY_INSERT CTL_CH('o')
-#define KEY_CLEAR_SCREEN CTL_CH('l')
-#define KEY_DEL7 127
-#define KEY_END 133 /* Cursor Key End */
-#define KEY_PAGEUP 135 /* Cursor Key Page Up */
-#define KEY_PAGEDOWN 136 /* Cursor Key Page Down */
-#define KEY_DEL 137 /* Cursor Key Del */
+#define BB_KEY_UP CTL_CH('p') /* cursor key Up */
+#define BB_KEY_DOWN CTL_CH('n') /* cursor key Down */
+#define BB_KEY_RIGHT CTL_CH('f') /* Cursor Key Right */
+#define BB_KEY_LEFT CTL_CH('b') /* cursor key Left */
+#define BB_KEY_HOME CTL_CH('a') /* Cursor Key Home */
+#define BB_KEY_ERASE_TO_EOL CTL_CH('k')
+#define BB_KEY_REFRESH_TO_EOL CTL_CH('e')
+#define BB_KEY_ERASE_LINE CTL_CH('x')
+#define BB_KEY_INSERT CTL_CH('o')
+#define BB_KEY_CLEAR_SCREEN CTL_CH('l')
+#define BB_KEY_DEL7 127
+#define BB_KEY_END 133 /* Cursor Key End */
+#define BB_KEY_PAGEUP 135 /* Cursor Key Page Up */
+#define BB_KEY_PAGEDOWN 136 /* Cursor Key Page Down */
+#define BB_KEY_DEL 137 /* Cursor Key Del */
#define ANSI_CLEAR_SCREEN "\e[2J\e[;H"
diff --git a/lib/readkey.c b/lib/readkey.c
index 89cc154..7b38110 100644
--- a/lib/readkey.c
+++ b/lib/readkey.c
@@ -29,24 +29,24 @@ struct esc_cmds {
};
static const struct esc_cmds esccmds[] = {
- {"OA", KEY_UP}, // cursor key Up
- {"OB", KEY_DOWN}, // cursor key Down
- {"OC", KEY_RIGHT}, // Cursor Key Right
- {"OD", KEY_LEFT}, // cursor key Left
- {"OH", KEY_HOME}, // Cursor Key Home
- {"OF", KEY_END}, // Cursor Key End
- {"[A", KEY_UP}, // cursor key Up
- {"[B", KEY_DOWN}, // cursor key Down
- {"[C", KEY_RIGHT}, // Cursor Key Right
- {"[D", KEY_LEFT}, // cursor key Left
- {"[H", KEY_HOME}, // Cursor Key Home
- {"[F", KEY_END}, // Cursor Key End
- {"[1~", KEY_HOME}, // Cursor Key Home
- {"[2~", KEY_INSERT}, // Cursor Key Insert
- {"[3~", KEY_DEL}, // Cursor Key Delete
- {"[4~", KEY_END}, // Cursor Key End
- {"[5~", KEY_PAGEUP}, // Cursor Key Page Up
- {"[6~", KEY_PAGEDOWN},// Cursor Key Page Down
+ {"OA", BB_KEY_UP}, // cursor key Up
+ {"OB", BB_KEY_DOWN}, // cursor key Down
+ {"OC", BB_KEY_RIGHT}, // Cursor Key Right
+ {"OD", BB_KEY_LEFT}, // cursor key Left
+ {"OH", BB_KEY_HOME}, // Cursor Key Home
+ {"OF", BB_KEY_END}, // Cursor Key End
+ {"[A", BB_KEY_UP}, // cursor key Up
+ {"[B", BB_KEY_DOWN}, // cursor key Down
+ {"[C", BB_KEY_RIGHT}, // Cursor Key Right
+ {"[D", BB_KEY_LEFT}, // cursor key Left
+ {"[H", BB_KEY_HOME}, // Cursor Key Home
+ {"[F", BB_KEY_END}, // Cursor Key End
+ {"[1~", BB_KEY_HOME}, // Cursor Key Home
+ {"[2~", BB_KEY_INSERT}, // Cursor Key Insert
+ {"[3~", BB_KEY_DEL}, // Cursor Key Delete
+ {"[4~", BB_KEY_END}, // Cursor Key End
+ {"[5~", BB_KEY_PAGEUP}, // Cursor Key Page Up
+ {"[6~", BB_KEY_PAGEDOWN},// Cursor Key Page Down
};
int read_key(void)
diff --git a/lib/readline.c b/lib/readline.c
index 6afc491..240a131 100644
--- a/lib/readline.c
+++ b/lib/readline.c
@@ -233,19 +233,19 @@ int readline(const char *prompt, char *buf, int len)
#endif
break;
- case KEY_HOME:
+ case BB_KEY_HOME:
BEGINNING_OF_LINE();
break;
case CTL_CH('c'): /* ^C - break */
*buf = 0; /* discard input */
return -1;
- case KEY_RIGHT:
+ case BB_KEY_RIGHT:
if (num < eol_num) {
getcmd_putch(buf[num]);
num++;
}
break;
- case KEY_LEFT:
+ case BB_KEY_LEFT:
if (num) {
getcmd_putch(CTL_BACKSPACE);
num--;
@@ -266,28 +266,28 @@ int readline(const char *prompt, char *buf, int len)
eol_num--;
}
break;
- case KEY_ERASE_TO_EOL:
+ case BB_KEY_ERASE_TO_EOL:
ERASE_TO_EOL();
break;
- case KEY_REFRESH_TO_EOL:
- case KEY_END:
+ case BB_KEY_REFRESH_TO_EOL:
+ case BB_KEY_END:
REFRESH_TO_EOL();
break;
- case KEY_INSERT:
+ case BB_KEY_INSERT:
insert = !insert;
break;
- case KEY_ERASE_LINE:
+ case BB_KEY_ERASE_LINE:
BEGINNING_OF_LINE();
ERASE_TO_EOL();
break;
case DEL:
- case KEY_DEL7:
+ case BB_KEY_DEL7:
case 8:
if (num) {
DO_BACKSPACE();
}
break;
- case KEY_DEL:
+ case BB_KEY_DEL:
if (num < eol_num) {
wlen = eol_num - num;
memmove(buf + num, buf + num + 1, wlen);
@@ -299,12 +299,12 @@ int readline(const char *prompt, char *buf, int len)
eol_num--;
}
break;
- case KEY_UP:
- case KEY_DOWN:
+ case BB_KEY_UP:
+ case BB_KEY_DOWN:
{
char * hline;
- if (ichar == KEY_UP)
+ if (ichar == BB_KEY_UP)
hline = hist_prev();
else
hline = hist_next();
--
1.8.5.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/4] input: gpio-keys: separate internal data from platform_data
2014-02-14 15:38 Add devicetree support to gpio-keys driver Sascha Hauer
2014-02-14 15:38 ` [PATCH 1/4] input: Add BB_ prefix to KEY_ defines Sascha Hauer
@ 2014-02-14 15:38 ` Sascha Hauer
2014-02-14 15:38 ` [PATCH 3/4] input: Add keycode to barebox key translation table Sascha Hauer
2014-02-14 15:38 ` [PATCH 4/4] input: gpio-keys: Add devicetree probe support Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2014-02-14 15:38 UTC (permalink / raw)
To: barebox
Do not abuse platform data for internal driver data, instead
use a separate struct for that.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/input/gpio_keys.c | 80 +++++++++++++++++++++++++++++++++--------------
include/gpio_keys.h | 7 -----
2 files changed, 57 insertions(+), 30 deletions(-)
diff --git a/drivers/input/gpio_keys.c b/drivers/input/gpio_keys.c
index 18a29f0..418158f 100644
--- a/drivers/input/gpio_keys.c
+++ b/drivers/input/gpio_keys.c
@@ -12,31 +12,52 @@
#include <poller.h>
#include <gpio.h>
-static inline struct gpio_keys_platform_data *
+struct gpio_key {
+ int code;
+
+ int gpio;
+ int active_low;
+
+ int previous_state;
+};
+
+struct gpio_keys {
+ struct gpio_key *buttons;
+ int nbuttons;
+
+ /* optional */
+ int fifo_size;
+
+ struct kfifo *recv_fifo;
+ struct poller_struct poller;
+ struct console_device cdev;
+};
+
+static inline struct gpio_keys *
poller_to_gk_pdata(struct poller_struct *poller)
{
- return container_of(poller, struct gpio_keys_platform_data, poller);
+ return container_of(poller, struct gpio_keys, poller);
}
-static inline struct gpio_keys_platform_data *
+static inline struct gpio_keys *
cdev_to_gk_pdata(struct console_device *cdev)
{
- return container_of(cdev, struct gpio_keys_platform_data, cdev);
+ return container_of(cdev, struct gpio_keys, cdev);
}
static void gpio_key_poller(struct poller_struct *poller)
{
- struct gpio_keys_platform_data *pdata = poller_to_gk_pdata(poller);
- struct gpio_keys_button *gb;
+ struct gpio_keys *gk = poller_to_gk_pdata(poller);
+ struct gpio_key *gb;
int i, val;
- for (i = 0; i < pdata->nbuttons; i++) {
+ for (i = 0; i < gk->nbuttons; i++) {
- gb = &pdata->buttons[i];
+ gb = &gk->buttons[i];
val = gpio_get_value(gb->gpio);
if (val != gb->previous_state && val != gb->active_low) {
- kfifo_put(pdata->recv_fifo, (u_char*)&gb->code, sizeof(int));
+ kfifo_put(gk->recv_fifo, (u_char*)&gb->code, sizeof(int));
debug("pressed gpio(%d) as %d\n", gb->gpio, gb->code);
}
gb->previous_state = val;
@@ -45,17 +66,17 @@ static void gpio_key_poller(struct poller_struct *poller)
static int gpio_keys_tstc(struct console_device *cdev)
{
- struct gpio_keys_platform_data *pdata = cdev_to_gk_pdata(cdev);
+ struct gpio_keys *gk = cdev_to_gk_pdata(cdev);
- return (kfifo_len(pdata->recv_fifo) == 0) ? 0 : 1;
+ return (kfifo_len(gk->recv_fifo) == 0) ? 0 : 1;
}
static int gpio_keys_getc(struct console_device *cdev)
{
int code = 0;
- struct gpio_keys_platform_data *pdata = cdev_to_gk_pdata(cdev);
+ struct gpio_keys *gk = cdev_to_gk_pdata(cdev);
- kfifo_get(pdata->recv_fifo, (u_char*)&code, sizeof(int));
+ kfifo_get(gk->recv_fifo, (u_char*)&code, sizeof(int));
return code;
}
@@ -64,6 +85,7 @@ static int __init gpio_keys_probe(struct device_d *dev)
int ret, i, gpio;
struct gpio_keys_platform_data *pdata;
struct console_device *cdev;
+ struct gpio_keys *gk;
pdata = dev->platform_data;
@@ -73,34 +95,46 @@ static int __init gpio_keys_probe(struct device_d *dev)
return -ENODEV;
}
- if (!pdata->fifo_size)
- pdata->fifo_size = 50;
+ gk = xzalloc(sizeof(*gk));
+
+ gk->fifo_size = 50;
+
+ if (pdata->fifo_size)
+ gk->fifo_size = pdata->fifo_size;
- pdata->recv_fifo = kfifo_alloc(pdata->fifo_size);
+ gk->recv_fifo = kfifo_alloc(pdata->fifo_size);
+
+ gk->buttons = xzalloc(pdata->nbuttons * sizeof(*gk->buttons));
+ gk->nbuttons = pdata->nbuttons;
+
+ for (i = 0; i < gk->nbuttons; i++) {
+ gk->buttons[i].gpio = pdata->buttons[i].gpio;
+ gk->buttons[i].code = pdata->buttons[i].code;
+ gk->buttons[i].active_low = pdata->buttons[i].active_low;
+ }
for (i = 0; i < pdata->nbuttons; i++) {
- gpio = pdata->buttons[i].gpio;
+ gpio = gk->buttons[i].gpio;
ret = gpio_request(gpio, "gpio_keys");
if (ret) {
pr_err("gpio_keys: (%d) can not be requested\n", gpio);
return ret;
}
gpio_direction_input(gpio);
- pdata->buttons[i].previous_state =
- pdata->buttons[i].active_low;
+ gk->buttons[i].previous_state = gk->buttons[i].active_low;
}
- pdata->poller.func = gpio_key_poller;
+ gk->poller.func = gpio_key_poller;
- cdev = &pdata->cdev;
+ cdev = &gk->cdev;
dev->type_data = cdev;
cdev->dev = dev;
cdev->tstc = gpio_keys_tstc;
cdev->getc = gpio_keys_getc;
- console_register(&pdata->cdev);
+ console_register(&gk->cdev);
- return poller_register(&pdata->poller);
+ return poller_register(&gk->poller);
}
static struct driver_d gpio_keys_driver = {
diff --git a/include/gpio_keys.h b/include/gpio_keys.h
index fc548fa..f4a22e1 100644
--- a/include/gpio_keys.h
+++ b/include/gpio_keys.h
@@ -10,9 +10,6 @@ struct gpio_keys_button {
int gpio;
int active_low;
-
- /* internal */
- int previous_state;
};
struct gpio_keys_platform_data {
@@ -21,10 +18,6 @@ struct gpio_keys_platform_data {
/* optional */
int fifo_size;
-
- struct kfifo *recv_fifo;
- struct poller_struct poller;
- struct console_device cdev;
};
#endif
--
1.8.5.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 3/4] input: Add keycode to barebox key translation table
2014-02-14 15:38 Add devicetree support to gpio-keys driver Sascha Hauer
2014-02-14 15:38 ` [PATCH 1/4] input: Add BB_ prefix to KEY_ defines Sascha Hauer
2014-02-14 15:38 ` [PATCH 2/4] input: gpio-keys: separate internal data from platform_data Sascha Hauer
@ 2014-02-14 15:38 ` Sascha Hauer
2014-02-14 15:38 ` [PATCH 4/4] input: gpio-keys: Add devicetree probe support Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2014-02-14 15:38 UTC (permalink / raw)
To: barebox
Devicetrees specify the keyboard codes for the gpio-keys
driver, so add a table to translate them into something
barebox can use.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/input/Makefile | 1 +
drivers/input/keymap.c | 136 +++++++++++++++++++++++++++++++++++++++++++++++
include/input/keyboard.h | 10 ++++
3 files changed, 147 insertions(+)
create mode 100644 drivers/input/keymap.c
create mode 100644 include/input/keyboard.h
diff --git a/drivers/input/Makefile b/drivers/input/Makefile
index b9bcc82..2143336 100644
--- a/drivers/input/Makefile
+++ b/drivers/input/Makefile
@@ -2,3 +2,4 @@ obj-$(CONFIG_KEYBOARD_GPIO) += gpio_keys.o
obj-$(CONFIG_KEYBOARD_TWL6030) += twl6030_pwrbtn.o
obj-$(CONFIG_KEYBOARD_IMX_KEYPAD) += imx_keypad.o
obj-$(CONFIG_KEYBOARD_QT1070) += qt1070.o
+obj-y += keymap.o
diff --git a/drivers/input/keymap.c b/drivers/input/keymap.c
new file mode 100644
index 0000000..b9fd6a2
--- /dev/null
+++ b/drivers/input/keymap.c
@@ -0,0 +1,136 @@
+#include <linux/types.h>
+#include <input/keyboard.h>
+
+#include <dt-bindings/input/input.h>
+#include <readkey.h>
+
+uint8_t keycode_bb_keys[NR_KEYS] = {
+ [KEY_RESERVED] = 0xff,
+ [KEY_ESC] = 0x1b,
+ [KEY_1] = '1',
+ [KEY_2] = '2',
+ [KEY_3] = '3',
+ [KEY_4] = '4',
+ [KEY_5] = '5',
+ [KEY_6] = '6',
+ [KEY_7] = '7',
+ [KEY_8] = '8',
+ [KEY_9] = '9',
+ [KEY_0] = '0',
+ [KEY_MINUS] = '-',
+ [KEY_EQUAL] = '=',
+ [KEY_BACKSPACE] = 0xff,
+ [KEY_TAB] = '\t',
+ [KEY_Q] = 'q',
+ [KEY_W] = 'w',
+ [KEY_E] = 'e',
+ [KEY_R] = 'r',
+ [KEY_T] = 't',
+ [KEY_Y] = 'y',
+ [KEY_U] = 'u',
+ [KEY_I] = 'i',
+ [KEY_O] = 'o',
+ [KEY_P] = 'p',
+ [KEY_LEFTBRACE] = '(',
+ [KEY_RIGHTBRACE] = ')',
+ [KEY_ENTER] = '\n',
+ [KEY_LEFTCTRL] = 0xff,
+ [KEY_A] = 'a',
+ [KEY_S] = 's',
+ [KEY_D] = 'd',
+ [KEY_F] = 'f',
+ [KEY_G] = 'g',
+ [KEY_H] = 'h',
+ [KEY_J] = 'j',
+ [KEY_K] = 'k',
+ [KEY_L] = 'l',
+ [KEY_SEMICOLON] = ';',
+ [KEY_APOSTROPHE] = 0xff,
+ [KEY_GRAVE] = '^',
+ [KEY_LEFTSHIFT] = 0xff,
+ [KEY_BACKSLASH] = 0xff,
+ [KEY_Z] = 'z',
+ [KEY_X] = 'x',
+ [KEY_C] = 'c',
+ [KEY_V] = 'v',
+ [KEY_B] = 'b',
+ [KEY_N] = 'n',
+ [KEY_M] = 'm',
+ [KEY_COMMA] = ',',
+ [KEY_DOT] = '.',
+ [KEY_SLASH] = '/',
+ [KEY_RIGHTSHIFT] = 0xff,
+ [KEY_KPASTERISK] = 0xff,
+ [KEY_LEFTALT] = 0xff,
+ [KEY_SPACE] = ' ',
+ [KEY_CAPSLOCK] = 0xff,
+ [KEY_F1] = 0xff,
+ [KEY_F2] = 0xff,
+ [KEY_F3] = 0xff,
+ [KEY_F4] = 0xff,
+ [KEY_F5] = 0xff,
+ [KEY_F6] = 0xff,
+ [KEY_F7] = 0xff,
+ [KEY_F8] = 0xff,
+ [KEY_F9] = 0xff,
+ [KEY_F10] = 0xff,
+ [KEY_NUMLOCK] = 0xff,
+ [KEY_SCROLLLOCK] = 0xff,
+ [KEY_KP7] = 0xff,
+ [KEY_KP8] = 0xff,
+ [KEY_KP9] = 0xff,
+ [KEY_KPMINUS] = 0xff,
+ [KEY_KP4] = 0xff,
+ [KEY_KP5] = 0xff,
+ [KEY_KP6] = 0xff,
+ [KEY_KPPLUS] = 0xff,
+ [KEY_KP1] = 0xff,
+ [KEY_KP2] = 0xff,
+ [KEY_KP3] = 0xff,
+ [KEY_KP0] = 0xff,
+ [KEY_KPDOT] = 0xff,
+ [KEY_ZENKAKUHANKAKU] = 0xff,
+ [KEY_102ND] = 0xff,
+ [KEY_F11] = 0xff,
+ [KEY_F12] = 0xff,
+ [KEY_RO] = 0xff,
+ [KEY_KATAKANA] = 0xff,
+ [KEY_HIRAGANA] = 0xff,
+ [KEY_HENKAN] = 0xff,
+ [KEY_KATAKANAHIRAGANA] =0xff,
+ [KEY_MUHENKAN] = 0xff,
+ [KEY_KPJPCOMMA] = 0xff,
+ [KEY_KPENTER] = 0xff,
+ [KEY_RIGHTCTRL] = 0xff,
+ [KEY_KPSLASH] = 0xff,
+ [KEY_SYSRQ] = 0xff,
+ [KEY_RIGHTALT] = 0xff,
+ [KEY_LINEFEED] = 0xff,
+ [KEY_HOME] = 0xff,
+ [KEY_UP] = BB_KEY_UP,
+ [KEY_PAGEUP] = BB_KEY_PAGEUP,
+ [KEY_LEFT] = BB_KEY_LEFT,
+ [KEY_RIGHT] = BB_KEY_RIGHT,
+ [KEY_END] = BB_KEY_END,
+ [KEY_DOWN] = BB_KEY_DOWN,
+ [KEY_PAGEDOWN] = BB_KEY_PAGEDOWN,
+ [KEY_INSERT] = BB_KEY_INSERT,
+ [KEY_DELETE] = BB_KEY_DEL7,
+ [KEY_MACRO] = 0xff,
+ [KEY_MUTE] = 0xff,
+ [KEY_VOLUMEDOWN] = 0xff,
+ [KEY_VOLUMEUP] = 0xff,
+ [KEY_POWER] = 0xff,
+ [KEY_KPEQUAL] = 0xff,
+ [KEY_KPPLUSMINUS] = 0xff,
+ [KEY_PAUSE] = 0xff,
+ [KEY_SCALE] = 0xff,
+ [KEY_KPCOMMA] = 0xff,
+ [KEY_HANGEUL] = 0xff,
+ [KEY_HANGUEL] = KEY_HANGEUL,
+ [KEY_HANJA] = 0xff,
+ [KEY_YEN] = 0xff,
+ [KEY_LEFTMETA] = 0xff,
+ [KEY_RIGHTMETA] = 0xff,
+ [KEY_COMPOSE] = 0xff,
+};
diff --git a/include/input/keyboard.h b/include/input/keyboard.h
new file mode 100644
index 0000000..dd04690
--- /dev/null
+++ b/include/input/keyboard.h
@@ -0,0 +1,10 @@
+#ifndef __INPUT_KEYBOARD_H
+#define __INPUT_KEYBOARD_H
+
+#include <linux/types.h>
+
+#define NR_KEYS 256
+
+extern uint8_t keycode_bb_keys[NR_KEYS];
+
+#endif
--
1.8.5.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 4/4] input: gpio-keys: Add devicetree probe support
2014-02-14 15:38 Add devicetree support to gpio-keys driver Sascha Hauer
` (2 preceding siblings ...)
2014-02-14 15:38 ` [PATCH 3/4] input: Add keycode to barebox key translation table Sascha Hauer
@ 2014-02-14 15:38 ` Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2014-02-14 15:38 UTC (permalink / raw)
To: barebox
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/input/gpio_keys.c | 90 ++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 77 insertions(+), 13 deletions(-)
diff --git a/drivers/input/gpio_keys.c b/drivers/input/gpio_keys.c
index 418158f..9486b9a 100644
--- a/drivers/input/gpio_keys.c
+++ b/drivers/input/gpio_keys.c
@@ -11,6 +11,8 @@
#include <gpio_keys.h>
#include <poller.h>
#include <gpio.h>
+#include <of_gpio.h>
+#include <input/keyboard.h>
struct gpio_key {
int code;
@@ -31,6 +33,8 @@ struct gpio_keys {
struct kfifo *recv_fifo;
struct poller_struct poller;
struct console_device cdev;
+
+ int use_keycodes;
};
static inline struct gpio_keys *
@@ -77,33 +81,29 @@ static int gpio_keys_getc(struct console_device *cdev)
struct gpio_keys *gk = cdev_to_gk_pdata(cdev);
kfifo_get(gk->recv_fifo, (u_char*)&code, sizeof(int));
- return code;
+
+ if (IS_ENABLED(CONFIG_OFDEVICE) && gk->use_keycodes)
+ return keycode_bb_keys[code];
+ else
+ return code;
}
-static int __init gpio_keys_probe(struct device_d *dev)
+static int gpio_keys_probe_pdata(struct gpio_keys *gk, struct device_d *dev)
{
- int ret, i, gpio;
struct gpio_keys_platform_data *pdata;
- struct console_device *cdev;
- struct gpio_keys *gk;
+ int i;
pdata = dev->platform_data;
if (!pdata) {
/* small (so we copy it) but critical! */
- pr_err("missing platform_data\n");
+ dev_err(dev, "missing platform_data\n");
return -ENODEV;
}
- gk = xzalloc(sizeof(*gk));
-
- gk->fifo_size = 50;
-
if (pdata->fifo_size)
gk->fifo_size = pdata->fifo_size;
- gk->recv_fifo = kfifo_alloc(pdata->fifo_size);
-
gk->buttons = xzalloc(pdata->nbuttons * sizeof(*gk->buttons));
gk->nbuttons = pdata->nbuttons;
@@ -113,7 +113,65 @@ static int __init gpio_keys_probe(struct device_d *dev)
gk->buttons[i].active_low = pdata->buttons[i].active_low;
}
- for (i = 0; i < pdata->nbuttons; i++) {
+ return 0;
+}
+
+static int gpio_keys_probe_dt(struct gpio_keys *gk, struct device_d *dev)
+{
+ struct device_node *npkey, *np = dev->device_node;
+ int i = 0, ret;
+
+ if (!IS_ENABLED(CONFIG_OFDEVICE))
+ return -ENODEV;
+
+ gk->nbuttons = of_get_child_count(np);
+ gk->buttons = xzalloc(gk->nbuttons * sizeof(*gk->buttons));
+
+ for_each_child_of_node(np, npkey) {
+ enum of_gpio_flags gpioflags;
+ uint32_t keycode;
+
+ gk->buttons[i].gpio = of_get_named_gpio_flags(npkey, "gpios", 0, &gpioflags);
+ if (gk->buttons[i].gpio < 0)
+ return gk->buttons[i].gpio;
+
+ if (gpioflags & OF_GPIO_ACTIVE_LOW)
+ gk->buttons[i].active_low = 1;
+
+ ret = of_property_read_u32(npkey, "linux,code", &keycode);
+ if (ret)
+ return ret;
+
+ gk->buttons[i].code = keycode;
+
+ i++;
+ }
+
+ gk->use_keycodes = 1;
+
+ return 0;
+}
+
+static int __init gpio_keys_probe(struct device_d *dev)
+{
+ int ret, i, gpio;
+ struct console_device *cdev;
+ struct gpio_keys *gk;
+
+ gk = xzalloc(sizeof(*gk));
+ gk->fifo_size = 50;
+
+ if (dev->device_node)
+ ret = gpio_keys_probe_dt(gk, dev);
+ else
+ ret = gpio_keys_probe_pdata(gk, dev);
+
+ if (ret)
+ return ret;
+
+ gk->recv_fifo = kfifo_alloc(gk->fifo_size);
+
+ for (i = 0; i < gk->nbuttons; i++) {
gpio = gk->buttons[i].gpio;
ret = gpio_request(gpio, "gpio_keys");
if (ret) {
@@ -137,8 +195,14 @@ static int __init gpio_keys_probe(struct device_d *dev)
return poller_register(&gk->poller);
}
+static struct of_device_id key_gpio_of_ids[] = {
+ { .compatible = "gpio-keys", },
+ { }
+};
+
static struct driver_d gpio_keys_driver = {
.name = "gpio_keys",
.probe = gpio_keys_probe,
+ .of_compatible = DRV_OF_COMPAT(key_gpio_of_ids),
};
device_platform_driver(gpio_keys_driver);
--
1.8.5.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-02-14 15:39 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-14 15:38 Add devicetree support to gpio-keys driver Sascha Hauer
2014-02-14 15:38 ` [PATCH 1/4] input: Add BB_ prefix to KEY_ defines Sascha Hauer
2014-02-14 15:38 ` [PATCH 2/4] input: gpio-keys: separate internal data from platform_data Sascha Hauer
2014-02-14 15:38 ` [PATCH 3/4] input: Add keycode to barebox key translation table Sascha Hauer
2014-02-14 15:38 ` [PATCH 4/4] input: gpio-keys: Add devicetree probe support Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox