ARM: tegra: cardhu: add pm267 to kbc int keys
[linux-2.6.git] / arch / arm / mach-tegra / board-cardhu-kbc.c
index 9b077b3..16e83bb 100644 (file)
@@ -25,6 +25,8 @@
 #include <linux/device.h>
 #include <linux/gpio.h>
 #include <linux/gpio_keys.h>
+#include <linux/mfd/tps6591x.h>
+#include <linux/mfd/max77663-core.h>
 #include <linux/gpio_scrollwheel.h>
 
 #include <mach/irqs.h>
 #include "board-cardhu.h"
 
 #include "gpio-names.h"
+#include "devices.h"
 
-#ifdef CONFIG_KEYBOARD_TEGRA
-#ifdef CONFIG_INPUT_ALPS_GPIO_SCROLLWHEEL
-#define CARDHU_ROW_COUNT       3
-#define CARDHU_COL_COUNT       2
-#else
-#define CARDHU_ROW_COUNT       4
-#define CARDHU_COL_COUNT       6
-#endif
+#define CARDHU_PM269_ROW_COUNT 2
+#define CARDHU_PM269_COL_COUNT 4
+
+static const u32 kbd_keymap[] = {
+       KEY(0, 0, KEY_POWER),
+       KEY(0, 1, KEY_RESERVED),
+       KEY(0, 2, KEY_VOLUMEUP),
+       KEY(0, 3, KEY_VOLUMEDOWN),
 
-#ifdef CONFIG_INPUT_ALPS_GPIO_SCROLLWHEEL
-static int plain_kbd_keycode[] = {
-       KEY_POWER,      KEY_RESERVED,
-       KEY_HOME,       KEY_BACK,
-       KEY_RESERVED,   KEY_RESERVED,
+       KEY(1, 0, KEY_HOME),
+       KEY(1, 1, KEY_MENU),
+       KEY(1, 2, KEY_BACK),
+       KEY(1, 3, KEY_SEARCH),
 };
-#else
-static int plain_kbd_keycode[] = {
-       KEY_POWER,      KEY_RESERVED,   KEY_RESERVED,   KEY_RESERVED,
-                       KEY_RESERVED,   KEY_RESERVED,   KEY_RESERVED,
-       KEY_HOME,       KEY_BACK,       KEY_RESERVED,   KEY_RESERVED,
-                       KEY_RESERVED,   KEY_RESERVED,   KEY_RESERVED,
-       KEY_CAMERA,     KEY_CAMERA,     KEY_RESERVED,   KEY_RESERVED,
-                       KEY_RESERVED,   KEY_RESERVED,   KEY_RESERVED,
-       KEY_VOLUMEDOWN, KEY_VOLUMEUP,   KEY_RESERVED,   KEY_RESERVED,
-                       KEY_RESERVED,   KEY_RESERVED,   KEY_PAUSE,
-       KEY_END,        KEY_BACK,       KEY_RESERVED,   KEY_RESERVED,
-                       KEY_RESERVED,   KEY_PLAY,       KEY_PHONE,
+static const struct matrix_keymap_data keymap_data = {
+       .keymap  = kbd_keymap,
+       .keymap_size    = ARRAY_SIZE(kbd_keymap),
 };
-#endif
+
 static struct tegra_kbc_wake_key cardhu_wake_cfg[] = {
        [0] = {
                .row = 0,
@@ -73,39 +66,16 @@ static struct tegra_kbc_wake_key cardhu_wake_cfg[] = {
 };
 
 static struct tegra_kbc_platform_data cardhu_kbc_platform_data = {
-       .debounce_cnt = 20,
-       .repeat_cnt = 50 * 32,
-       .scan_timeout_cnt = 3000 * 32,
-       .plain_keycode = plain_kbd_keycode,
-       .fn_keycode = NULL,
-       .is_filter_keys = false,
-       .is_wake_on_any_key = false,
-       .wake_key_cnt = 1,
+       .debounce_cnt = 20 * 32, /* 20ms debounce time */
+       .repeat_cnt = 1,
+       .scan_count = 30,
+       .wakeup = true,
+       .keymap_data = &keymap_data,
+       .wake_cnt = 1,
        .wake_cfg = &cardhu_wake_cfg[0],
-};
-
-static struct resource cardhu_kbc_resources[] = {
-       [0] = {
-               .start = TEGRA_KBC_BASE,
-               .end   = TEGRA_KBC_BASE + TEGRA_KBC_SIZE - 1,
-               .flags = IORESOURCE_MEM,
-       },
-       [1] = {
-               .start = INT_KBC,
-               .end   = INT_KBC,
-               .flags = IORESOURCE_IRQ,
-       },
-};
-
-
-struct platform_device cardhu_kbc_device = {
-       .name = "tegra-kbc",
-       .id = -1,
-       .dev = {
-               .platform_data = &cardhu_kbc_platform_data,
-       },
-       .resource = cardhu_kbc_resources,
-       .num_resources = ARRAY_SIZE(cardhu_kbc_resources),
+#ifdef CONFIG_ANDROID
+       .disable_ev_rep = true,
+#endif
 };
 
 int __init cardhu_kbc_init(void)
@@ -120,86 +90,27 @@ int __init cardhu_kbc_init(void)
                return 0;
 
        pr_info("Registering tegra-kbc\n");
-        /* Setup the pin configuration information. */
-       for (i = 0; i < KBC_MAX_GPIO; i++) {
-               data->pin_cfg[i].num = 0;
-               data->pin_cfg[i].pin_type = kbc_pin_unused;
-       }
-       for (i = 0; i < CARDHU_ROW_COUNT; i++) {
+       tegra_kbc_device.dev.platform_data = &cardhu_kbc_platform_data;
+
+       for (i = 0; i < CARDHU_PM269_ROW_COUNT; i++) {
                data->pin_cfg[i].num = i;
-               data->pin_cfg[i].pin_type = kbc_pin_row;
+               data->pin_cfg[i].is_row = true;
+               data->pin_cfg[i].en = true;
        }
-
-       for (i = 0; i < CARDHU_COL_COUNT; i++) {
-               data->pin_cfg[i + CARDHU_ROW_COUNT].num = i;
-               data->pin_cfg[i + CARDHU_ROW_COUNT].pin_type = kbc_pin_col;
+       for (i = 0; i < CARDHU_PM269_COL_COUNT; i++) {
+               data->pin_cfg[i + KBC_PIN_GPIO_16].num = i;
+               data->pin_cfg[i + KBC_PIN_GPIO_16].en = true;
        }
-       platform_device_register(&cardhu_kbc_device);
-       return 0;
-}
-#else
-int __init cardhu_kbc_init(void)
-{
-}
-#endif
 
-#ifdef CONFIG_INPUT_ALPS_GPIO_SCROLLWHEEL
-#define GPIO_SCROLL(_pinaction, _gpio, _desc)          \
-{                                                      \
-       .pinaction = GPIO_SCROLLWHEEL_PIN_##_pinaction, \
-       .gpio = TEGRA_GPIO_##_gpio,                     \
-       .desc = _desc,                                  \
-       .active_low = 1,                                \
-       .debounce_interval = 2,                         \
-}
-
-static struct gpio_scrollwheel_button scroll_keys[] = {
-       [0] = GPIO_SCROLL(ONOFF, PR3, "sw_onoff"),
-       [1] = GPIO_SCROLL(PRESS, PQ5, "sw_press"),
-       [2] = GPIO_SCROLL(ROT1, PQ3, "sw_rot1"),
-       [3] = GPIO_SCROLL(ROT2, PQ4, "sw_rot2"),
-};
-
-static struct gpio_scrollwheel_platform_data cardhu_scroll_platform_data = {
-       .buttons = scroll_keys,
-       .nbuttons = ARRAY_SIZE(scroll_keys),
-};
-
-static struct platform_device cardhu_scroll_device = {
-       .name   = "alps-gpio-scrollwheel",
-       .id     = 0,
-       .dev    = {
-               .platform_data = &cardhu_scroll_platform_data,
-       },
-};
-
-int __init cardhu_scroll_init(void)
-{
-       int i;
-       struct board_info board_info;
-
-       tegra_get_board_info(&board_info);
-       if ((board_info.board_id == BOARD_E1198) ||
-               (board_info.board_id == BOARD_E1291))
-               return 0;
-
-       pr_info("Registering alps scroll wheel\n");
-
-       /* Setting pins to gpio mode */
-       for (i = 0; i < ARRAY_SIZE(scroll_keys); i++)
-               tegra_gpio_enable(scroll_keys[i].gpio);
-
-       platform_device_register(&cardhu_scroll_device);
+       platform_device_register(&tegra_kbc_device);
        return 0;
 }
-#else
+
 int __init cardhu_scroll_init(void)
 {
        return 0;
 }
-#endif
 
-#ifdef CONFIG_KEYBOARD_GPIO
 #define GPIO_KEY(_id, _gpio, _iswake)          \
        {                                       \
                .code = _id,                    \
@@ -211,7 +122,18 @@ int __init cardhu_scroll_init(void)
                .debounce_interval = 10,        \
        }
 
-static struct gpio_keys_button cardhu_keys[] = {
+#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),
        [2] = GPIO_KEY(KEY_MENU, PQ2, 0),
@@ -219,63 +141,162 @@ static struct gpio_keys_button cardhu_keys[] = {
        [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_pdata = {
+       .buttons        = cardhu_keys_e1198,
+       .nbuttons       = ARRAY_SIZE(cardhu_keys_e1198),
+};
+
+static struct platform_device cardhu_keys_e1198_device = {
+       .name   = "gpio-keys",
+       .id     = 0,
+       .dev    = {
+               .platform_data  = &cardhu_keys_e1198_pdata,
+       },
+};
+
+static struct gpio_keys_button cardhu_keys_e1291[] = {
+       [0] = GPIO_KEY(KEY_VOLUMEDOWN, PR0, 0),
+       [1] = GPIO_KEY(KEY_VOLUMEUP, PR1, 0),
+       [2] = GPIO_KEY(KEY_HOME, PR2, 0),
+       [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[] = {
+       [0] = GPIO_KEY(KEY_VOLUMEDOWN, PR0, 0),
+       [1] = GPIO_KEY(KEY_VOLUMEUP, PR1, 0),
+       [2] = GPIO_KEY(KEY_HOME, PQ2, 0),
+       [3] = GPIO_KEY(KEY_SEARCH, PQ3, 0),
+       [4] = GPIO_KEY(KEY_BACK, PQ0, 0),
+       [5] = GPIO_KEY(KEY_MENU, PQ1, 0),
+       [6] = GPIO_KEY(KEY_RESERVED, PV0, 1),
+       [7] = GPIO_IKEY(KEY_POWER, TPS6591X_IRQ_BASE + TPS6591X_INT_PWRON, 1, 100),
+};
+
+static struct gpio_keys_platform_data cardhu_keys_e1291_pdata = {
+       .buttons        = cardhu_keys_e1291,
+       .nbuttons       = ARRAY_SIZE(cardhu_keys_e1291),
+};
+
+static struct platform_device cardhu_keys_e1291_device = {
+       .name   = "gpio-keys",
+       .id     = 0,
+       .dev    = {
+               .platform_data  = &cardhu_keys_e1291_pdata,
+       },
+};
+
+static struct gpio_keys_button cardhu_int_keys[] = {
+       [0] = GPIO_IKEY(KEY_POWER, TPS6591X_IRQ_BASE + TPS6591X_INT_PWRON, 1, 100),
 };
 
-static struct gpio_keys_platform_data cardhu_keys_platform_data = {
-       .buttons        = cardhu_keys,
-       .nbuttons       = ARRAY_SIZE(cardhu_keys),
+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 platform_device cardhu_keys_device = {
+static struct gpio_keys_button cardhu_pm299_int_keys[] = {
+       [0] = GPIO_KEY(KEY_POWER, PV0, 1),
+};
+
+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   = "gpio-keys",
        .id     = 0,
        .dev    = {
-               .platform_data  = &cardhu_keys_platform_data,
+               .platform_data  = &cardhu_int_keys_pdata,
        },
 };
 
 int __init cardhu_keys_init(void)
 {
        int i;
-       int ret;
        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) ||
-               (board_info.board_id == BOARD_E1291)))
+               (board_info.board_id == BOARD_E1291) ||
+               (board_info.board_id == BOARD_E1186) ||
+               (board_info.board_id == BOARD_E1257) ||
+               (board_info.board_id == BOARD_PM305) ||
+               (board_info.board_id == BOARD_PM311) ||
+               (board_info.board_id == BOARD_PM267) ||
+               (board_info.board_id == BOARD_PM269)))
                return 0;
 
        pr_info("Registering gpio keys\n");
 
-       /* Set KB_ROW2 to 0 for capcitive switch to be in scan mode */
        if (board_info.board_id == BOARD_E1291) {
-               ret = gpio_request(TEGRA_GPIO_PR2, "cap_sw_sl_scan");
-               if (ret < 0) {
-                       pr_err("%s: gpio_request failed #%d\n",
-                                       __func__, TEGRA_GPIO_PR2);
-                       return ret;
+               if (board_info.fab >= BOARD_FAB_A04) {
+                       cardhu_keys_e1291_pdata.buttons =
+                                       cardhu_keys_e1291_a04;
+                       cardhu_keys_e1291_pdata.nbuttons =
+                                       ARRAY_SIZE(cardhu_keys_e1291_a04);
                }
-               ret = gpio_direction_output(TEGRA_GPIO_PR2, 0);
-               if (ret < 0) {
-                       pr_err("%s: gpio_direction_output failed #%d\n",
-                                       __func__, TEGRA_GPIO_PR2);
-                       gpio_free(TEGRA_GPIO_PR2);
-                       return ret;
+
+               /* Enable gpio mode for other pins */
+               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);
+                       }
                }
 
-               tegra_gpio_enable(TEGRA_GPIO_PR2);
+               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++) {
+                       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);
        }
 
-       /* Enable gpio mode for other pins */
-       for (i = 0; i < ARRAY_SIZE(cardhu_keys); i++)
-               tegra_gpio_enable(cardhu_keys[i].gpio);
+       /* Register on-key through pmu interrupt */
+       tegra_get_pmu_board_info(&pmu_board_info);
 
-       platform_device_register(&cardhu_keys_device);
-       return 0;
-}
-#else
-int __init cardhu_keys_init(void)
-{
+       if (pmu_board_info.board_id == BOARD_PMU_PM298) {
+               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.buttons = cardhu_pm299_int_keys;
+               cardhu_int_keys_pdata.nbuttons =
+                                       ARRAY_SIZE(cardhu_pm299_int_keys);
+       }
+
+       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) ||
+               (board_info.board_id == BOARD_PM267) ||
+               (board_info.board_id == BOARD_PM269)) {
+               if (get_tegra_image_type() == rck_image)
+                       cardhu_int_keys[0].code = KEY_ENTER;
+               platform_device_register(&cardhu_int_keys_device);
+       }
        return 0;
 }
-#endif