dev-gpio-buttons.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Atheros AR71XX/AR724X/AR913X GPIO button support
  3. *
  4. * Copyright (C) 2008-2010 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. #include "linux/init.h"
  12. #include "linux/slab.h"
  13. #include <linux/platform_device.h>
  14. #include "dev-gpio-buttons.h"
  15. void __init ath79_register_gpio_keys_polled(int id,
  16. unsigned poll_interval,
  17. unsigned nbuttons,
  18. struct gpio_keys_button *buttons)
  19. {
  20. struct platform_device *pdev;
  21. struct gpio_keys_platform_data pdata;
  22. struct gpio_keys_button *p;
  23. int err;
  24. p = kmemdup(buttons, nbuttons * sizeof(*p), GFP_KERNEL);
  25. if (!p)
  26. return;
  27. pdev = platform_device_alloc("gpio-keys-polled", id);
  28. if (!pdev)
  29. goto err_free_buttons;
  30. memset(&pdata, 0, sizeof(pdata));
  31. pdata.poll_interval = poll_interval;
  32. pdata.nbuttons = nbuttons;
  33. pdata.buttons = p;
  34. err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
  35. if (err)
  36. goto err_put_pdev;
  37. err = platform_device_add(pdev);
  38. if (err)
  39. goto err_put_pdev;
  40. return;
  41. err_put_pdev:
  42. platform_device_put(pdev);
  43. err_free_buttons:
  44. kfree(p);
  45. }