dev-gpio-buttons.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 = kmalloc(nbuttons * sizeof(*p), GFP_KERNEL);
  25. if (!p)
  26. return;
  27. memcpy(p, buttons, nbuttons * sizeof(*p));
  28. pdev = platform_device_alloc("gpio-keys-polled", id);
  29. if (!pdev)
  30. goto err_free_buttons;
  31. memset(&pdata, 0, sizeof(pdata));
  32. pdata.poll_interval = poll_interval;
  33. pdata.nbuttons = nbuttons;
  34. pdata.buttons = p;
  35. err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
  36. if (err)
  37. goto err_put_pdev;
  38. err = platform_device_add(pdev);
  39. if (err)
  40. goto err_put_pdev;
  41. return;
  42. err_put_pdev:
  43. platform_device_put(pdev);
  44. err_free_buttons:
  45. kfree(p);
  46. }