dev-leds-gpio.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Atheros AR71XX/AR724X/AR913X common GPIO LEDs 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-leds-gpio.h"
  15. void __init ath79_register_leds_gpio(int id,
  16. unsigned num_leds,
  17. struct gpio_led *leds)
  18. {
  19. struct platform_device *pdev;
  20. struct gpio_led_platform_data pdata;
  21. struct gpio_led *p;
  22. int err;
  23. p = kmemdup(leds, num_leds * sizeof(*p), GFP_KERNEL);
  24. if (!p)
  25. return;
  26. pdev = platform_device_alloc("leds-gpio", id);
  27. if (!pdev)
  28. goto err_free_leds;
  29. memset(&pdata, 0, sizeof(pdata));
  30. pdata.num_leds = num_leds;
  31. pdata.leds = p;
  32. err = platform_device_add_data(pdev, &pdata, sizeof(pdata));
  33. if (err)
  34. goto err_put_pdev;
  35. err = platform_device_add(pdev);
  36. if (err)
  37. goto err_put_pdev;
  38. return;
  39. err_put_pdev:
  40. platform_device_put(pdev);
  41. err_free_leds:
  42. kfree(p);
  43. }