GNU Linux-libre 4.14.290-gnu1
[releases.git] / arch / x86 / platform / intel-mid / device_libs / platform_gpio_keys.c
1 /*
2  * platform_gpio_keys.c: gpio_keys platform data initialization file
3  *
4  * (C) Copyright 2013 Intel Corporation
5  * Author: Sathyanarayanan Kuppuswamy <sathyanarayanan.kuppuswamy@intel.com>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; version 2
10  * of the License.
11  */
12
13 #include <linux/input.h>
14 #include <linux/init.h>
15 #include <linux/kernel.h>
16 #include <linux/gpio.h>
17 #include <linux/gpio_keys.h>
18 #include <linux/platform_device.h>
19 #include <asm/intel-mid.h>
20
21 #define DEVICE_NAME "gpio-keys"
22
23 /*
24  * we will search these buttons in SFI GPIO table (by name)
25  * and register them dynamically. Please add all possible
26  * buttons here, we will shrink them if no GPIO found.
27  */
28 static struct gpio_keys_button gpio_button[] = {
29         {KEY_POWER,             -1, 1, "power_btn",     EV_KEY, 0, 3000},
30         {KEY_PROG1,             -1, 1, "prog_btn1",     EV_KEY, 0, 20},
31         {KEY_PROG2,             -1, 1, "prog_btn2",     EV_KEY, 0, 20},
32         {SW_LID,                -1, 1, "lid_switch",    EV_SW,  0, 20},
33         {KEY_VOLUMEUP,          -1, 1, "vol_up",        EV_KEY, 0, 20},
34         {KEY_VOLUMEDOWN,        -1, 1, "vol_down",      EV_KEY, 0, 20},
35         {KEY_MUTE,              -1, 1, "mute_enable",   EV_KEY, 0, 20},
36         {KEY_VOLUMEUP,          -1, 1, "volume_up",     EV_KEY, 0, 20},
37         {KEY_VOLUMEDOWN,        -1, 1, "volume_down",   EV_KEY, 0, 20},
38         {KEY_CAMERA,            -1, 1, "camera_full",   EV_KEY, 0, 20},
39         {KEY_CAMERA_FOCUS,      -1, 1, "camera_half",   EV_KEY, 0, 20},
40         {SW_KEYPAD_SLIDE,       -1, 1, "MagSw1",        EV_SW,  0, 20},
41         {SW_KEYPAD_SLIDE,       -1, 1, "MagSw2",        EV_SW,  0, 20},
42 };
43
44 static struct gpio_keys_platform_data gpio_keys = {
45         .buttons        = gpio_button,
46         .rep            = 1,
47         .nbuttons       = -1, /* will fill it after search */
48 };
49
50 static struct platform_device pb_device = {
51         .name           = DEVICE_NAME,
52         .id             = -1,
53         .dev            = {
54                 .platform_data  = &gpio_keys,
55         },
56 };
57
58 /*
59  * Shrink the non-existent buttons, register the gpio button
60  * device if there is some
61  */
62 static int __init pb_keys_init(void)
63 {
64         struct gpio_keys_button *gb = gpio_button;
65         int i, num, good = 0;
66
67         num = sizeof(gpio_button) / sizeof(struct gpio_keys_button);
68         for (i = 0; i < num; i++) {
69                 gb[i].gpio = get_gpio_by_name(gb[i].desc);
70                 pr_debug("info[%2d]: name = %s, gpio = %d\n", i, gb[i].desc,
71                                         gb[i].gpio);
72                 if (gb[i].gpio < 0)
73                         continue;
74
75                 if (i != good)
76                         gb[good] = gb[i];
77                 good++;
78         }
79
80         if (good) {
81                 gpio_keys.nbuttons = good;
82                 return platform_device_register(&pb_device);
83         }
84         return 0;
85 }
86 late_initcall(pb_keys_init);