loki: Enable Gamepad wakeup
[linux-3.10.git] / arch / arm / mach-tegra / board-loki-kbc.c
1 /*
2  * arch/arm/mach-tegra/board-loki-kbc.c
3  * Keys configuration for Nvidia tegra4 loki platform.
4  *
5  * Copyright (c) 2012-2013, NVIDIA CORPORATION.  All rights reserved.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19  * 02111-1307, USA
20  */
21
22 #include <linux/kernel.h>
23 #include <linux/platform_device.h>
24 #include <linux/input.h>
25 #include <linux/io.h>
26 #include <linux/input/tegra_kbc.h>
27 #include <linux/gpio.h>
28 #include <linux/gpio_keys.h>
29 #include <linux/mfd/palmas.h>
30
31 #include "tegra-board-id.h"
32 #include "board.h"
33 #include "board-loki.h"
34 #include "devices.h"
35 #include "iomap.h"
36 #include "wakeups-t12x.h"
37
38
39 #define GPIO_KEY(_id, _gpio, _iswake)           \
40         {                                       \
41                 .code = _id,                    \
42                 .gpio = TEGRA_GPIO_##_gpio,     \
43                 .active_low = 1,                \
44                 .desc = #_id,                   \
45                 .type = EV_KEY,                 \
46                 .wakeup = _iswake,              \
47                 .debounce_interval = 10,        \
48         }
49
50 #define GPIO_IKEY(_id, _irq, _iswake, _deb)     \
51         {                                       \
52                 .code = _id,                    \
53                 .gpio = -1,                     \
54                 .irq = _irq,                    \
55                 .desc = #_id,                   \
56                 .type = EV_KEY,                 \
57                 .wakeup = _iswake,              \
58                 .debounce_interval = _deb,      \
59         }
60
61 #define PMC_WAKE_STATUS         0x14
62 #define TEGRA_WAKE_PWR_INT      (1UL << 18)
63 #define PMC_WAKE2_STATUS        0x168
64
65 static int loki_wakeup_key(void);
66
67 static struct gpio_keys_button loki_int_keys[] = {
68         [0] = GPIO_KEY(KEY_POWER, PQ0, 1),
69         [1] = {
70                 .code = SW_LID,
71                 .gpio = TEGRA_GPIO_HALL,
72                 .irq = -1,
73                 .type = EV_SW,
74                 .desc = "Hall Effect Sensor",
75                 .active_low = 1,
76                 .wakeup = 1,
77                 .debounce_interval = 0,
78         },
79         [2] = {
80                 .code = KEY_WAKEUP,
81                 .gpio = TEGRA_GPIO_PS6,
82                 .irq = -1,
83                 .type = EV_KEY,
84                 .desc = "Gamepad",
85                 .active_low = 1,
86                 .wakeup = 1,
87                 .debounce_interval = 0,
88         },
89 };
90
91 static struct gpio_keys_platform_data loki_int_keys_pdata = {
92         .buttons        = loki_int_keys,
93         .nbuttons       = ARRAY_SIZE(loki_int_keys),
94         .wakeup_key     = loki_wakeup_key,
95 };
96
97 static struct platform_device loki_int_keys_device = {
98         .name   = "gpio-keys",
99         .id     = 0,
100         .dev    = {
101                 .platform_data  = &loki_int_keys_pdata,
102         },
103 };
104
105 static int loki_wakeup_key(void)
106 {
107         int wakeup_key;
108         u32 status;
109         status = readl(IO_ADDRESS(TEGRA_PMC_BASE) + PMC_WAKE_STATUS)
110                 | (u64)readl(IO_ADDRESS(TEGRA_PMC_BASE)
111                 + PMC_WAKE2_STATUS) << 32;
112
113         if (status & TEGRA_WAKE_GPIO_PQ0)
114                 wakeup_key = KEY_POWER;
115         else if (status & (1UL << TEGRA_WAKE_GPIO_PS0))
116                 wakeup_key = SW_LID;
117         else if (status & (1UL << TEGRA_WAKE_GPIO_PS6))
118                 wakeup_key = KEY_WAKEUP;
119         else
120                 wakeup_key = -1;
121
122         return wakeup_key;
123 }
124
125 int __init loki_kbc_init(void)
126 {
127         struct board_info board_info;
128         int ret;
129
130         tegra_get_board_info(&board_info);
131         pr_info("Boardid:SKU = 0x%04x:0x%04x\n",
132                         board_info.board_id, board_info.sku);
133
134         ret = platform_device_register(&loki_int_keys_device);
135         return ret;
136 }