temp revert rk change
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-tegra / board-stingray-keypad.c
1 /*
2  * arch/arm/mach-tegra/board-stingray-keypad.c
3  *
4  * Copyright (C) 2010 Google, Inc.
5  *
6  * This software is licensed under the terms of the GNU General Public
7  * License version 2, as published by the Free Software Foundation, and
8  * may be copied, distributed, and modified under those terms.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  */
16
17 #include <linux/platform_device.h>
18 #include <linux/input.h>
19 #include <linux/keyreset.h>
20 #include <linux/gpio_event.h>
21 #include <linux/gpio.h>
22 #include <asm/mach-types.h>
23
24 #include "board-stingray.h"
25 #include "gpio-names.h"
26
27 static unsigned int stingray_row_gpios[] = {
28         TEGRA_GPIO_PR0,
29         TEGRA_GPIO_PR1
30 };
31 static unsigned int stingray_col_gpios[] = {
32         TEGRA_GPIO_PQ0
33 };
34
35 #define KEYMAP_INDEX(col, row) ((col)*ARRAY_SIZE(stingray_row_gpios) + (row))
36
37 static const unsigned short stingray_p3_keymap[ARRAY_SIZE(stingray_col_gpios) *
38                                              ARRAY_SIZE(stingray_row_gpios)] = {
39         [KEYMAP_INDEX(0, 0)] = KEY_VOLUMEUP,
40         [KEYMAP_INDEX(0, 1)] = KEY_VOLUMEDOWN
41 };
42
43 static struct gpio_event_matrix_info stingray_keypad_matrix_info = {
44         .info.func = gpio_event_matrix_func,
45         .keymap = stingray_p3_keymap,
46         .output_gpios = stingray_col_gpios,
47         .input_gpios = stingray_row_gpios,
48         .noutputs = ARRAY_SIZE(stingray_col_gpios),
49         .ninputs = ARRAY_SIZE(stingray_row_gpios),
50         .settle_time.tv.nsec = 40 * NSEC_PER_USEC,
51         .poll_time.tv.nsec = 20 * NSEC_PER_MSEC,
52         .flags = GPIOKPF_LEVEL_TRIGGERED_IRQ | GPIOKPF_REMOVE_PHANTOM_KEYS |
53                  GPIOKPF_PRINT_UNMAPPED_KEYS /*| GPIOKPF_PRINT_MAPPED_KEYS*/
54 };
55
56 static struct gpio_event_direct_entry stingray_keypad_switch_map[] = {
57 };
58
59 static struct gpio_event_input_info stingray_keypad_switch_info = {
60         .info.func = gpio_event_input_func,
61         .flags = 0,
62         .type = EV_SW,
63         .keymap = stingray_keypad_switch_map,
64         .keymap_size = ARRAY_SIZE(stingray_keypad_switch_map)
65 };
66
67 static struct gpio_event_info *stingray_keypad_info[] = {
68         &stingray_keypad_matrix_info.info,
69         &stingray_keypad_switch_info.info,
70 };
71
72 static struct gpio_event_platform_data stingray_keypad_data = {
73         .name = "stingray-keypad",
74         .info = stingray_keypad_info,
75         .info_count = ARRAY_SIZE(stingray_keypad_info)
76 };
77
78 static struct platform_device stingray_keypad_device = {
79         .name = GPIO_EVENT_DEV_NAME,
80         .id = 0,
81         .dev            = {
82                 .platform_data  = &stingray_keypad_data,
83         },
84 };
85
86 int stingray_log_reset(void)
87 {
88         pr_warn("Hard reset buttons pushed\n");
89         return 0;
90 }
91
92 static struct keyreset_platform_data stingray_reset_keys_pdata = {
93         .reset_fn = stingray_log_reset,
94         .keys_down = {
95                 KEY_END,
96                 KEY_VOLUMEUP,
97                 0
98         },
99 };
100
101 struct platform_device stingray_keyreset_device = {
102         .name   = KEYRESET_NAME,
103         .dev    = {
104                 .platform_data = &stingray_reset_keys_pdata,
105         },
106 };
107
108
109 int __init stingray_keypad_init(void)
110 {
111         tegra_gpio_enable(TEGRA_GPIO_PR0);
112         tegra_gpio_enable(TEGRA_GPIO_PR1);
113         tegra_gpio_enable(TEGRA_GPIO_PQ0);
114         platform_device_register(&stingray_keyreset_device);
115         return platform_device_register(&stingray_keypad_device);
116 }