ar71xx: move gpio-buttons support into a spearate file
[librecmc/librecmc.git] / target / linux / ar71xx / files / arch / mips / ar71xx / dev-gpio-buttons.c
1 /*
2  *  Atheros AR71xx GPIO button support
3  *
4  *  Copyright (C) 2008-2009 Gabor Juhos <juhosg@openwrt.org>
5  *  Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
6  *
7  *  This program is free software; you can redistribute it and/or modify it
8  *  under the terms of the GNU General Public License version 2 as published
9  *  by the Free Software Foundation.
10  */
11
12 #include "linux/init.h"
13 #include <linux/platform_device.h>
14
15 #include "dev-gpio-buttons.h"
16
17 void __init ar71xx_add_device_gpio_buttons(int id,
18                                            unsigned poll_interval,
19                                            unsigned nbuttons,
20                                            struct gpio_button *buttons)
21 {
22         struct platform_device *pdev;
23         struct gpio_buttons_platform_data pdata;
24         struct gpio_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-buttons", 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
47         err = platform_device_add(pdev);
48         if (err)
49                 goto err_put_pdev;
50
51         return;
52
53 err_put_pdev:
54         platform_device_put(pdev);
55
56 err_free_buttons:
57         kfree(p);
58 }