ARM: tegra: cardhu/Kai: Use gpio_keys driver for int key
Laxman Dewangan [Mon, 26 Mar 2012 14:00:40 +0000 (19:00 +0530)]
gpio_keys driver support for the key which can generates only
interrupt and not mapped to any gpio functionality.
Using this feature to support the onkey which generates interrupt
only when key is pressed.

Change-Id: I502a45a1c510b92f4114ded713f7706b7a2c85d3
Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Reviewed-on: http://git-master/r/92460
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Bitan Biswas <bbiswas@nvidia.com>

arch/arm/mach-tegra/board-cardhu-kbc.c
arch/arm/mach-tegra/board-kai-kbc.c

index 9f4716a..3bf0a3b 100644 (file)
@@ -27,7 +27,6 @@
 #include <linux/gpio_keys.h>
 #include <linux/mfd/tps6591x.h>
 #include <linux/mfd/max77663-core.h>
-#include <linux/interrupt_keys.h>
 #include <linux/gpio_scrollwheel.h>
 
 #include <mach/irqs.h>
@@ -123,6 +122,17 @@ int __init cardhu_scroll_init(void)
                .debounce_interval = 10,        \
        }
 
+#define GPIO_IKEY(_id, _irq, _iswake, _deb)    \
+       {                                       \
+               .code = _id,                    \
+               .gpio = -1,                     \
+               .irq = _irq,                    \
+               .desc = #_id,                   \
+               .type = EV_KEY,                 \
+               .wakeup = _iswake,              \
+               .debounce_interval = _deb,      \
+       }
+
 static struct gpio_keys_button cardhu_keys_e1198[] = {
        [0] = GPIO_KEY(KEY_HOME, PQ0, 0),
        [1] = GPIO_KEY(KEY_BACK, PQ1, 0),
@@ -131,9 +141,10 @@ static struct gpio_keys_button cardhu_keys_e1198[] = {
        [4] = GPIO_KEY(KEY_VOLUMEUP, PR0, 0),
        [5] = GPIO_KEY(KEY_VOLUMEDOWN, PR1, 0),
        [6] = GPIO_KEY(KEY_POWER, PV0, 1),
+       [7] = GPIO_IKEY(KEY_POWER, TPS6591X_IRQ_BASE + TPS6591X_INT_PWRON, 1, 100),
 };
 
-static struct gpio_keys_platform_data cardhu_keys_e1198_platform_data = {
+static struct gpio_keys_platform_data cardhu_keys_e1198_pdata = {
        .buttons        = cardhu_keys_e1198,
        .nbuttons       = ARRAY_SIZE(cardhu_keys_e1198),
 };
@@ -142,7 +153,7 @@ static struct platform_device cardhu_keys_e1198_device = {
        .name   = "gpio-keys",
        .id     = 0,
        .dev    = {
-               .platform_data  = &cardhu_keys_e1198_platform_data,
+               .platform_data  = &cardhu_keys_e1198_pdata,
        },
 };
 
@@ -153,6 +164,7 @@ static struct gpio_keys_button cardhu_keys_e1291[] = {
        [3] = GPIO_KEY(KEY_SEARCH, PQ3, 0),
        [4] = GPIO_KEY(KEY_BACK, PQ0, 0),
        [5] = GPIO_KEY(KEY_MENU, PQ1, 0),
+       [6] = GPIO_IKEY(KEY_POWER, TPS6591X_IRQ_BASE + TPS6591X_INT_PWRON, 1, 100),
 };
 
 static struct gpio_keys_button cardhu_keys_e1291_a04[] = {
@@ -162,9 +174,10 @@ static struct gpio_keys_button cardhu_keys_e1291_a04[] = {
        [3] = GPIO_KEY(KEY_SEARCH, PQ3, 0),
        [4] = GPIO_KEY(KEY_BACK, PQ0, 0),
        [5] = GPIO_KEY(KEY_MENU, PQ1, 0),
+       [6] = GPIO_IKEY(KEY_POWER, TPS6591X_IRQ_BASE + TPS6591X_INT_PWRON, 1, 100),
 };
 
-static struct gpio_keys_platform_data cardhu_keys_e1291_platform_data = {
+static struct gpio_keys_platform_data cardhu_keys_e1291_pdata = {
        .buttons        = cardhu_keys_e1291,
        .nbuttons       = ARRAY_SIZE(cardhu_keys_e1291),
 };
@@ -173,40 +186,30 @@ static struct platform_device cardhu_keys_e1291_device = {
        .name   = "gpio-keys",
        .id     = 0,
        .dev    = {
-               .platform_data  = &cardhu_keys_e1291_platform_data,
+               .platform_data  = &cardhu_keys_e1291_pdata,
        },
 };
 
-#define INT_KEY(_id, _irq, _iswake, _deb_int)  \
-       {                                       \
-               .code = _id,                    \
-               .irq = _irq,                    \
-               .active_low = 1,                \
-               .desc = #_id,                   \
-               .type = EV_KEY,                 \
-               .wakeup = _iswake,              \
-               .debounce_interval = _deb_int,  \
-       }
-static struct interrupt_keys_button cardhu_int_keys[] = {
-       [0] = INT_KEY(KEY_POWER, TPS6591X_IRQ_BASE + TPS6591X_INT_PWRON, 1, 100),
+static struct gpio_keys_button cardhu_int_keys[] = {
+       [0] = GPIO_IKEY(KEY_POWER, TPS6591X_IRQ_BASE + TPS6591X_INT_PWRON, 1, 100),
 };
 
-static struct interrupt_keys_button cardhu_pm298_int_keys[] = {
-       [0] = INT_KEY(KEY_POWER, MAX77663_IRQ_BASE + MAX77663_IRQ_ONOFF_EN0_FALLING, 1, 100),
-       [1] = INT_KEY(KEY_POWER, MAX77663_IRQ_BASE + MAX77663_IRQ_ONOFF_EN0_1SEC, 1, 3000),
+static struct gpio_keys_button cardhu_pm298_int_keys[] = {
+       [0] = GPIO_IKEY(KEY_POWER, MAX77663_IRQ_BASE + MAX77663_IRQ_ONOFF_EN0_FALLING, 1, 100),
+       [1] = GPIO_IKEY(KEY_POWER, MAX77663_IRQ_BASE + MAX77663_IRQ_ONOFF_EN0_1SEC, 1, 3000),
 };
 
-static struct interrupt_keys_button cardhu_pm299_int_keys[] = {
-       [0] = INT_KEY(KEY_POWER, RICOH583_IRQ_BASE + RICOH583_IRQ_ONKEY, 1, 100),
+static struct gpio_keys_button cardhu_pm299_int_keys[] = {
+       [0] = GPIO_IKEY(KEY_POWER, RICOH583_IRQ_BASE + RICOH583_IRQ_ONKEY, 1, 100),
 };
 
-static struct interrupt_keys_platform_data cardhu_int_keys_pdata = {
-       .int_buttons    = cardhu_int_keys,
+static struct gpio_keys_platform_data cardhu_int_keys_pdata = {
+       .buttons        = cardhu_int_keys,
        .nbuttons       = ARRAY_SIZE(cardhu_int_keys),
 };
 
 static struct platform_device cardhu_int_keys_device = {
-       .name   = "interrupt-keys",
+       .name   = "gpio-keys",
        .id     = 0,
        .dev    = {
                .platform_data  = &cardhu_int_keys_pdata,
@@ -218,6 +221,7 @@ int __init cardhu_keys_init(void)
        int i;
        struct board_info board_info;
        struct board_info pmu_board_info;
+       int gpio_nr;
 
        tegra_get_board_info(&board_info);
        if (!((board_info.board_id == BOARD_E1198) ||
@@ -232,24 +236,37 @@ int __init cardhu_keys_init(void)
        pr_info("Registering gpio keys\n");
 
        if (board_info.board_id == BOARD_E1291) {
-
                if (board_info.fab >= BOARD_FAB_A04) {
-                       cardhu_keys_e1291_platform_data.buttons =
+                       cardhu_keys_e1291_pdata.buttons =
                                        cardhu_keys_e1291_a04;
-                       cardhu_keys_e1291_platform_data.nbuttons =
+                       cardhu_keys_e1291_pdata.nbuttons =
                                        ARRAY_SIZE(cardhu_keys_e1291_a04);
                }
 
                /* Enable gpio mode for other pins */
-               for (i = 0; i < cardhu_keys_e1291_platform_data.nbuttons; i++)
-                       tegra_gpio_enable(cardhu_keys_e1291_platform_data.
-                                               buttons[i].gpio);
+               for (i = 0; i < cardhu_keys_e1291_pdata.nbuttons; i++) {
+                       gpio_nr = cardhu_keys_e1291_pdata.buttons[i].gpio;
+                       if (gpio_nr < 0) {
+                               if (get_tegra_image_type() == rck_image)
+                                       cardhu_keys_e1291_pdata.buttons[i].code
+                                                       = KEY_ENTER;
+                       } else {
+                               tegra_gpio_enable(gpio_nr);
+                       }
+               }
 
                platform_device_register(&cardhu_keys_e1291_device);
        } else if (board_info.board_id == BOARD_E1198) {
                /* For E1198 */
-               for (i = 0; i < ARRAY_SIZE(cardhu_keys_e1198); i++)
-                       tegra_gpio_enable(cardhu_keys_e1198[i].gpio);
+               for (i = 0; i < ARRAY_SIZE(cardhu_keys_e1198); i++) {
+                       gpio_nr = cardhu_keys_e1198[i].gpio;
+                       if (gpio_nr < 0) {
+                               if (get_tegra_image_type() == rck_image)
+                                       cardhu_keys_e1198[i].code = KEY_ENTER;
+                       } else {
+                               tegra_gpio_enable(gpio_nr);
+                       }
+               }
 
                platform_device_register(&cardhu_keys_e1198_device);
        }
@@ -258,20 +275,18 @@ int __init cardhu_keys_init(void)
        tegra_get_pmu_board_info(&pmu_board_info);
 
        if (pmu_board_info.board_id == BOARD_PMU_PM298) {
-               cardhu_int_keys_pdata.int_buttons = cardhu_pm298_int_keys;
+               cardhu_int_keys_pdata.buttons = cardhu_pm298_int_keys;
                cardhu_int_keys_pdata.nbuttons =
                                        ARRAY_SIZE(cardhu_pm298_int_keys);
        }
 
        if (pmu_board_info.board_id == BOARD_PMU_PM299) {
-               cardhu_int_keys_pdata.int_buttons = cardhu_pm299_int_keys;
+               cardhu_int_keys_pdata.buttons = cardhu_pm299_int_keys;
                cardhu_int_keys_pdata.nbuttons =
                                        ARRAY_SIZE(cardhu_pm299_int_keys);
        }
 
-       if ((board_info.board_id == BOARD_E1291) ||
-               (board_info.board_id == BOARD_E1198) ||
-               (board_info.board_id == BOARD_E1257) ||
+       if ((board_info.board_id == BOARD_E1257) ||
                (board_info.board_id == BOARD_E1186) ||
                (board_info.board_id == BOARD_PM305) ||
                (board_info.board_id == BOARD_PM311) ||
index d62fc2f..5c52864 100644 (file)
@@ -26,7 +26,6 @@
 #include <linux/gpio.h>
 #include <linux/gpio_keys.h>
 #include <linux/mfd/max77663-core.h>
-#include <linux/interrupt_keys.h>
 #include <linux/gpio_scrollwheel.h>
 
 #include <mach/irqs.h>
                .debounce_interval = 10,        \
        }
 
+#define GPIO_IKEY(_id, _irq, _iswake, _deb)    \
+       {                                       \
+               .code = _id,                    \
+               .gpio = -1,                     \
+               .irq = _irq,                    \
+               .desc = #_id,                   \
+               .type = EV_KEY,                 \
+               .wakeup = _iswake,              \
+               .debounce_interval = _deb,      \
+       }
+
 static struct gpio_keys_button kai_keys[] = {
        [0] = GPIO_KEY(KEY_MENU, PR2, 0),
        [1] = GPIO_KEY(KEY_BACK, PQ1, 0),
@@ -57,6 +67,8 @@ static struct gpio_keys_button kai_keys[] = {
        [3] = GPIO_KEY(KEY_SEARCH, PQ3, 0),
        [4] = GPIO_KEY(KEY_VOLUMEUP, PR1, 0),
        [5] = GPIO_KEY(KEY_VOLUMEDOWN, PR0, 0),
+       [6] = GPIO_IKEY(KEY_POWER, MAX77663_IRQ_BASE + MAX77663_IRQ_ONOFF_EN0_FALLING, 1, 100),
+       [7] = GPIO_IKEY(KEY_POWER, MAX77663_IRQ_BASE + MAX77663_IRQ_ONOFF_EN0_1SEC, 1, 3000),
 };
 
 static struct gpio_keys_platform_data kai_keys_platform_data = {
@@ -72,34 +84,6 @@ static struct platform_device kai_keys_device = {
        },
 };
 
-#define INT_KEY(_id, _irq, _iswake, _deb_int)  \
-       {                                       \
-               .code = _id,                    \
-               .irq = _irq,                    \
-               .active_low = 1,                \
-               .desc = #_id,                   \
-               .type = EV_KEY,                 \
-               .wakeup = _iswake,              \
-               .debounce_interval = _deb_int,  \
-       }
-static struct interrupt_keys_button kai_int_keys[] = {
-       [0] = INT_KEY(KEY_POWER, MAX77663_IRQ_BASE + MAX77663_IRQ_ONOFF_EN0_FALLING, 0, 100),
-       [1] = INT_KEY(KEY_POWER, MAX77663_IRQ_BASE + MAX77663_IRQ_ONOFF_EN0_1SEC, 0, 3000),
-};
-
-static struct interrupt_keys_platform_data kai_int_keys_pdata = {
-       .int_buttons    = kai_int_keys,
-       .nbuttons       = ARRAY_SIZE(kai_int_keys),
-};
-
-static struct platform_device kai_int_keys_device = {
-       .name   = "interrupt-keys",
-       .id     = 0,
-       .dev    = {
-               .platform_data  = &kai_int_keys_pdata,
-       },
-};
-
 int __init kai_keys_init(void)
 {
        int i;
@@ -107,12 +91,13 @@ int __init kai_keys_init(void)
        pr_info("Registering gpio keys\n");
 
        /* Enable gpio mode for other pins */
-       for (i = 0; i < kai_keys_platform_data.nbuttons; i++)
-               tegra_gpio_enable(kai_keys_platform_data.
-                                       buttons[i].gpio);
+       for (i = 0; i < kai_keys_platform_data.nbuttons; i++) {
+               if (kai_keys_platform_data.buttons[i].gpio < 0)
+                       continue;
+               tegra_gpio_enable(kai_keys_platform_data.buttons[i].gpio);
+       }
 
        platform_device_register(&kai_keys_device);
-       platform_device_register(&kai_int_keys_device);
 
        return 0;
 }