]> git.karo-electronics.de Git - linux-beck.git/commitdiff
Input: matrix-keypad - add function to build device keymap
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Wed, 26 Aug 2009 02:24:13 +0000 (19:24 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Fri, 28 Aug 2009 05:05:39 +0000 (22:05 -0700)
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
drivers/input/keyboard/matrix_keypad.c
drivers/input/keyboard/w90p910_keypad.c
include/linux/input/matrix_keypad.h

index 541b981ff0752d2a3bfeb991ad1bf866d236aa61..91cfe51702657573fb1519bc59d5f0e42c476ddc 100644 (file)
@@ -319,7 +319,6 @@ static int __devinit matrix_keypad_probe(struct platform_device *pdev)
        struct input_dev *input_dev;
        unsigned short *keycodes;
        unsigned int row_shift;
-       int i;
        int err;
 
        pdata = pdev->dev.platform_data;
@@ -363,18 +362,10 @@ static int __devinit matrix_keypad_probe(struct platform_device *pdev)
 
        input_dev->keycode      = keycodes;
        input_dev->keycodesize  = sizeof(*keycodes);
-       input_dev->keycodemax   = pdata->num_row_gpios << keypad->row_shift;
-
-       for (i = 0; i < keymap_data->keymap_size; i++) {
-               unsigned int key = keymap_data->keymap[i];
-               unsigned int row = KEY_ROW(key);
-               unsigned int col = KEY_COL(key);
-               unsigned short code = KEY_VAL(key);
+       input_dev->keycodemax   = pdata->num_row_gpios << row_shift;
 
-               keycodes[MATRIX_SCAN_CODE(row, col, row_shift)] = code;
-               __set_bit(code, input_dev->keybit);
-       }
-       __clear_bit(KEY_RESERVED, input_dev->keybit);
+       matrix_keypad_build_keymap(keymap_data, row_shift,
+                                  input_dev->keycode, input_dev->keybit);
 
        input_set_capability(input_dev, EV_MSC, MSC_SCAN);
        input_set_drvdata(input_dev, keypad);
index b8598ae124ee9dcbf1cdd609396c0af303dba486..2d03dd0f9e07dd61d3101add75b6854f3e062e7a 100644 (file)
@@ -126,7 +126,6 @@ static int __devinit w90p910_keypad_probe(struct platform_device *pdev)
        struct resource *res;
        int irq;
        int error;
-       int i;
 
        if (!pdata) {
                dev_err(&pdev->dev, "no platform data defined\n");
@@ -197,19 +196,8 @@ static int __devinit w90p910_keypad_probe(struct platform_device *pdev)
        input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
        input_set_capability(input_dev, EV_MSC, MSC_SCAN);
 
-       for (i = 0; i < keymap_data->keymap_size; i++) {
-               unsigned int key = keymap_data->keymap[i];
-               unsigned int row = KEY_ROW(key);
-               unsigned int col = KEY_COL(key);
-               unsigned short keycode = KEY_VAL(key);
-               unsigned int scancode = MATRIX_SCAN_CODE(row, col,
-                                                        W90P910_ROW_SHIFT);
-
-               keypad->keymap[scancode] = keycode;
-               __set_bit(keycode, input_dev->keybit);
-       }
-       __clear_bit(KEY_RESERVED, input_dev->keybit);
-
+       matrix_keypad_build_keymap(keymap_data, W90P910_ROW_SHIFT,
+                                  input_dev->keycode, input_dev->keybit);
 
        error = request_irq(keypad->irq, w90p910_keypad_irq_handler,
                            IRQF_DISABLED, pdev->name, keypad);
index 15d5903af2dd143ddc26abd34a38977fe986d729..b3cd42d50e16ca723666762fd482e82c157d7f94 100644 (file)
@@ -63,4 +63,36 @@ struct matrix_keypad_platform_data {
        bool            wakeup;
 };
 
+/**
+ * matrix_keypad_build_keymap - convert platform keymap into matrix keymap
+ * @keymap_data: keymap supplied by the platform code
+ * @row_shift: number of bits to shift row value by to advance to the next
+ * line in the keymap
+ * @keymap: expanded version of keymap that is suitable for use by
+ * matrix keyboad driver
+ * @keybit: pointer to bitmap of keys supported by input device
+ *
+ * This function converts platform keymap (encoded with KEY() macro) into
+ * an array of keycodes that is suitable for using in a standard matrix
+ * keyboard driver that uses row and col as indices.
+ */
+static inline void
+matrix_keypad_build_keymap(const struct matrix_keymap_data *keymap_data,
+                          unsigned int row_shift,
+                          unsigned short *keymap, unsigned long *keybit)
+{
+       int i;
+
+       for (i = 0; i < keymap_data->keymap_size; i++) {
+               unsigned int key = keymap_data->keymap[i];
+               unsigned int row = KEY_ROW(key);
+               unsigned int col = KEY_COL(key);
+               unsigned short code = KEY_VAL(key);
+
+               keymap[MATRIX_SCAN_CODE(row, col, row_shift)] = code;
+               __set_bit(code, keybit);
+       }
+       __clear_bit(KEY_RESERVED, keybit);
+}
+
 #endif /* _MATRIX_KEYPAD_H */