dev-leds-gpio.c 1.2 KB

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