leds.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Driver for the LED found on the EBSA110 machine
  4. * Based on Versatile and RealView machine LED code
  5. *
  6. * Author: Bryan Wu <bryan.wu@canonical.com>
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/init.h>
  10. #include <linux/io.h>
  11. #include <linux/slab.h>
  12. #include <linux/leds.h>
  13. #include <asm/mach-types.h>
  14. #include "core.h"
  15. #if defined(CONFIG_NEW_LEDS) && defined(CONFIG_LEDS_CLASS)
  16. static void ebsa110_led_set(struct led_classdev *cdev,
  17. enum led_brightness b)
  18. {
  19. u8 reg = __raw_readb(SOFT_BASE);
  20. if (b != LED_OFF)
  21. reg |= 0x80;
  22. else
  23. reg &= ~0x80;
  24. __raw_writeb(reg, SOFT_BASE);
  25. }
  26. static enum led_brightness ebsa110_led_get(struct led_classdev *cdev)
  27. {
  28. u8 reg = __raw_readb(SOFT_BASE);
  29. return (reg & 0x80) ? LED_FULL : LED_OFF;
  30. }
  31. static int __init ebsa110_leds_init(void)
  32. {
  33. struct led_classdev *cdev;
  34. int ret;
  35. if (!machine_is_ebsa110())
  36. return -ENODEV;
  37. cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
  38. if (!cdev)
  39. return -ENOMEM;
  40. cdev->name = "ebsa110:0";
  41. cdev->brightness_set = ebsa110_led_set;
  42. cdev->brightness_get = ebsa110_led_get;
  43. cdev->default_trigger = "heartbeat";
  44. ret = led_classdev_register(NULL, cdev);
  45. if (ret < 0) {
  46. kfree(cdev);
  47. return ret;
  48. }
  49. return 0;
  50. }
  51. /*
  52. * Since we may have triggers on any subsystem, defer registration
  53. * until after subsystem_init.
  54. */
  55. fs_initcall(ebsa110_leds_init);
  56. #endif