leds-wrap.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * LEDs driver for PCEngines WRAP
  3. *
  4. * Copyright (C) 2006 Kristian Kielhofner <kris@krisk.org>
  5. *
  6. * Based on leds-net48xx.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/scx200_gpio.h>
  19. #include <linux/module.h>
  20. #define DRVNAME "wrap-led"
  21. #define WRAP_POWER_LED_GPIO 2
  22. #define WRAP_ERROR_LED_GPIO 3
  23. #define WRAP_EXTRA_LED_GPIO 18
  24. static struct platform_device *pdev;
  25. static void wrap_power_led_set(struct led_classdev *led_cdev,
  26. enum led_brightness value)
  27. {
  28. if (value)
  29. scx200_gpio_set_low(WRAP_POWER_LED_GPIO);
  30. else
  31. scx200_gpio_set_high(WRAP_POWER_LED_GPIO);
  32. }
  33. static void wrap_error_led_set(struct led_classdev *led_cdev,
  34. enum led_brightness value)
  35. {
  36. if (value)
  37. scx200_gpio_set_low(WRAP_ERROR_LED_GPIO);
  38. else
  39. scx200_gpio_set_high(WRAP_ERROR_LED_GPIO);
  40. }
  41. static void wrap_extra_led_set(struct led_classdev *led_cdev,
  42. enum led_brightness value)
  43. {
  44. if (value)
  45. scx200_gpio_set_low(WRAP_EXTRA_LED_GPIO);
  46. else
  47. scx200_gpio_set_high(WRAP_EXTRA_LED_GPIO);
  48. }
  49. static struct led_classdev wrap_power_led = {
  50. .name = "wrap::power",
  51. .brightness_set = wrap_power_led_set,
  52. .default_trigger = "default-on",
  53. .flags = LED_CORE_SUSPENDRESUME,
  54. };
  55. static struct led_classdev wrap_error_led = {
  56. .name = "wrap::error",
  57. .brightness_set = wrap_error_led_set,
  58. .flags = LED_CORE_SUSPENDRESUME,
  59. };
  60. static struct led_classdev wrap_extra_led = {
  61. .name = "wrap::extra",
  62. .brightness_set = wrap_extra_led_set,
  63. .flags = LED_CORE_SUSPENDRESUME,
  64. };
  65. static int wrap_led_probe(struct platform_device *pdev)
  66. {
  67. int ret;
  68. ret = devm_led_classdev_register(&pdev->dev, &wrap_power_led);
  69. if (ret < 0)
  70. return ret;
  71. ret = devm_led_classdev_register(&pdev->dev, &wrap_error_led);
  72. if (ret < 0)
  73. return ret;
  74. return devm_led_classdev_register(&pdev->dev, &wrap_extra_led);
  75. }
  76. static struct platform_driver wrap_led_driver = {
  77. .probe = wrap_led_probe,
  78. .driver = {
  79. .name = DRVNAME,
  80. },
  81. };
  82. static int __init wrap_led_init(void)
  83. {
  84. int ret;
  85. if (!scx200_gpio_present()) {
  86. ret = -ENODEV;
  87. goto out;
  88. }
  89. ret = platform_driver_register(&wrap_led_driver);
  90. if (ret < 0)
  91. goto out;
  92. pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
  93. if (IS_ERR(pdev)) {
  94. ret = PTR_ERR(pdev);
  95. platform_driver_unregister(&wrap_led_driver);
  96. goto out;
  97. }
  98. out:
  99. return ret;
  100. }
  101. static void __exit wrap_led_exit(void)
  102. {
  103. platform_device_unregister(pdev);
  104. platform_driver_unregister(&wrap_led_driver);
  105. }
  106. module_init(wrap_led_init);
  107. module_exit(wrap_led_exit);
  108. MODULE_AUTHOR("Kristian Kielhofner <kris@krisk.org>");
  109. MODULE_DESCRIPTION("PCEngines WRAP LED driver");
  110. MODULE_LICENSE("GPL");