blob: d93711bf41b0dc3c6ab67e38300697f37ada05b8 [file] [log] [blame]
Rafał Miłeckief1e3e72014-01-14 12:36:29 +01001#include "bcm47xx_private.h"
2
3#include <linux/input.h>
4#include <linux/gpio_keys.h>
5#include <linux/interrupt.h>
6#include <linux/ssb/ssb_embedded.h>
7#include <bcm47xx_board.h>
8#include <bcm47xx.h>
9
10/**************************************************
11 * Database
12 **************************************************/
13
14static const struct gpio_keys_button
15bcm47xx_buttons_netgear_wndr4500_v1[] __initconst = {
16 {
17 .code = KEY_WPS_BUTTON,
18 .gpio = 4,
19 .active_low = 1,
20 },
21 {
22 .code = KEY_RFKILL,
23 .gpio = 5,
24 .active_low = 1,
25 },
26 {
27 .code = KEY_RESTART,
28 .gpio = 6,
29 .active_low = 1,
30 },
31};
32
33/**************************************************
34 * Init
35 **************************************************/
36
37static struct gpio_keys_platform_data bcm47xx_button_pdata;
38
39static struct platform_device bcm47xx_buttons_gpio_keys = {
40 .name = "gpio-keys",
41 .dev = {
42 .platform_data = &bcm47xx_button_pdata,
43 }
44};
45
46/* Copy data from __initconst */
47static int __init bcm47xx_buttons_copy(const struct gpio_keys_button *buttons,
48 size_t nbuttons)
49{
50 size_t size = nbuttons * sizeof(*buttons);
51
52 bcm47xx_button_pdata.buttons = kmalloc(size, GFP_KERNEL);
53 if (!bcm47xx_button_pdata.buttons)
54 return -ENOMEM;
55 memcpy(bcm47xx_button_pdata.buttons, buttons, size);
56 bcm47xx_button_pdata.nbuttons = nbuttons;
57
58 return 0;
59}
60
61#define bcm47xx_copy_bdata(dev_buttons) \
62 bcm47xx_buttons_copy(dev_buttons, ARRAY_SIZE(dev_buttons));
63
64int __init bcm47xx_buttons_register(void)
65{
66 enum bcm47xx_board board = bcm47xx_board_get();
67 int err;
68
69#ifdef CONFIG_BCM47XX_SSB
70 if (bcm47xx_bus_type == BCM47XX_BUS_TYPE_SSB) {
71 pr_debug("Buttons on SSB are not supported yet.\n");
72 return -ENOTSUPP;
73 }
74#endif
75
76 switch (board) {
77 case BCM47XX_BOARD_NETGEAR_WNDR4500V1:
78 err = bcm47xx_copy_bdata(bcm47xx_buttons_netgear_wndr4500_v1);
79 break;
80 default:
81 pr_debug("No buttons configuration found for this device\n");
82 return -ENOTSUPP;
83 }
84
85 if (err)
86 return -ENOMEM;
87
88 err = platform_device_register(&bcm47xx_buttons_gpio_keys);
89 if (err) {
90 pr_err("Failed to register platform device: %d\n", err);
91 return err;
92 }
93
94 return 0;
95}