leds-wrap.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 <asm/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 = led_classdev_register(&pdev->dev, &wrap_power_led);
  69. if (ret < 0)
  70. return ret;
  71. ret = led_classdev_register(&pdev->dev, &wrap_error_led);
  72. if (ret < 0)
  73. goto err1;
  74. ret = led_classdev_register(&pdev->dev, &wrap_extra_led);
  75. if (ret < 0)
  76. goto err2;
  77. return ret;
  78. err2:
  79. led_classdev_unregister(&wrap_error_led);
  80. err1:
  81. led_classdev_unregister(&wrap_power_led);
  82. return ret;
  83. }
  84. static int wrap_led_remove(struct platform_device *pdev)
  85. {
  86. led_classdev_unregister(&wrap_power_led);
  87. led_classdev_unregister(&wrap_error_led);
  88. led_classdev_unregister(&wrap_extra_led);
  89. return 0;
  90. }
  91. static struct platform_driver wrap_led_driver = {
  92. .probe = wrap_led_probe,
  93. .remove = wrap_led_remove,
  94. .driver = {
  95. .name = DRVNAME,
  96. .owner = THIS_MODULE,
  97. },
  98. };
  99. static int __init wrap_led_init(void)
  100. {
  101. int ret;
  102. if (!scx200_gpio_present()) {
  103. ret = -ENODEV;
  104. goto out;
  105. }
  106. ret = platform_driver_register(&wrap_led_driver);
  107. if (ret < 0)
  108. goto out;
  109. pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
  110. if (IS_ERR(pdev)) {
  111. ret = PTR_ERR(pdev);
  112. platform_driver_unregister(&wrap_led_driver);
  113. goto out;
  114. }
  115. out:
  116. return ret;
  117. }
  118. static void __exit wrap_led_exit(void)
  119. {
  120. platform_device_unregister(pdev);
  121. platform_driver_unregister(&wrap_led_driver);
  122. }
  123. module_init(wrap_led_init);
  124. module_exit(wrap_led_exit);
  125. MODULE_AUTHOR("Kristian Kielhofner <kris@krisk.org>");
  126. MODULE_DESCRIPTION("PCEngines WRAP LED driver");
  127. MODULE_LICENSE("GPL");