leds-wrap.c 3.2 KB

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