leds-net48xx.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * LEDs driver for Soekris net48xx
  3. *
  4. * Copyright (C) 2006 Chris Boot <bootc@bootc.net>
  5. *
  6. * Based on leds-ams-delta.c
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/leds.h>
  16. #include <linux/err.h>
  17. #include <linux/io.h>
  18. #include <linux/nsc_gpio.h>
  19. #include <linux/scx200_gpio.h>
  20. #include <linux/module.h>
  21. #define DRVNAME "net48xx-led"
  22. #define NET48XX_ERROR_LED_GPIO 20
  23. static struct platform_device *pdev;
  24. static void net48xx_error_led_set(struct led_classdev *led_cdev,
  25. enum led_brightness value)
  26. {
  27. scx200_gpio_ops.gpio_set(NET48XX_ERROR_LED_GPIO, value ? 1 : 0);
  28. }
  29. static struct led_classdev net48xx_error_led = {
  30. .name = "net48xx::error",
  31. .brightness_set = net48xx_error_led_set,
  32. .flags = LED_CORE_SUSPENDRESUME,
  33. };
  34. static int net48xx_led_probe(struct platform_device *pdev)
  35. {
  36. return devm_led_classdev_register(&pdev->dev, &net48xx_error_led);
  37. }
  38. static struct platform_driver net48xx_led_driver = {
  39. .probe = net48xx_led_probe,
  40. .driver = {
  41. .name = DRVNAME,
  42. },
  43. };
  44. static int __init net48xx_led_init(void)
  45. {
  46. int ret;
  47. /* small hack, but scx200_gpio doesn't set .dev if the probe fails */
  48. if (!scx200_gpio_ops.dev) {
  49. ret = -ENODEV;
  50. goto out;
  51. }
  52. ret = platform_driver_register(&net48xx_led_driver);
  53. if (ret < 0)
  54. goto out;
  55. pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
  56. if (IS_ERR(pdev)) {
  57. ret = PTR_ERR(pdev);
  58. platform_driver_unregister(&net48xx_led_driver);
  59. goto out;
  60. }
  61. out:
  62. return ret;
  63. }
  64. static void __exit net48xx_led_exit(void)
  65. {
  66. platform_device_unregister(pdev);
  67. platform_driver_unregister(&net48xx_led_driver);
  68. }
  69. module_init(net48xx_led_init);
  70. module_exit(net48xx_led_exit);
  71. MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
  72. MODULE_DESCRIPTION("Soekris net48xx LED driver");
  73. MODULE_LICENSE("GPL");