ramips: properly setup the FEATURES variable
[openwrt.git] / target / linux / ramips / files-3.7 / arch / mips / ralink / common / dev-gpio-buttons.c
1 /*
2  *  Ralink SoC GPIO button support
3  *
4  *  Copyright (C) 2010 Gabor Juhos <juhosg@openwrt.org>
5  *
6  *  This program is free software; you can redistribute it and/or modify it
7  *  under the terms of the GNU General Public License version 2 as published
8  *  by the Free Software Foundation.
9  */
10
11 #include "linux/init.h"
12 #include <linux/platform_device.h>
13 #include <linux/slab.h>
14
15 #include <asm/mach-ralink/dev-gpio-buttons.h>
16
17 void __init ramips_register_gpio_buttons(int id,
18                                          unsigned poll_interval,
19                                          unsigned nbuttons,
20                                          struct gpio_keys_button *buttons)
21 {
22         struct platform_device *pdev;
23         struct gpio_keys_platform_data pdata;
24         struct gpio_keys_button *p;
25         int err;
26
27         p = kmalloc(nbuttons * sizeof(*p), GFP_KERNEL);
28         if (!p)
29                 return;
30
31         memcpy(p, buttons, nbuttons * sizeof(*p));
32
33         pdev = platform_device_alloc("gpio-keys-polled", id);
34         if (!pdev)
35                 goto err_free_buttons;
36
37         memset(&pdata, 0, sizeof(pdata));
38         pdata.poll_interval = poll_interval;
39         pdata.nbuttons = nbuttons;
40         pdata.buttons = p;
41
42         err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
43         if (err)
44                 goto err_put_pdev;
45
46         err = platform_device_add(pdev);
47         if (err)
48                 goto err_put_pdev;
49
50         return;
51
52 err_put_pdev:
53         platform_device_put(pdev);
54
55 err_free_buttons:
56         kfree(p);
57 }