ramips: merge slab patch
[lede.git] / target / linux / ramips / files / 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_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 }