leds-locomo.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * linux/drivers/leds/leds-locomo.c
  3. *
  4. * Copyright (C) 2005 John Lenz <lenz@cs.wisc.edu>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/init.h>
  12. #include <linux/module.h>
  13. #include <linux/device.h>
  14. #include <linux/leds.h>
  15. #include <mach/hardware.h>
  16. #include <asm/hardware/locomo.h>
  17. static void locomoled_brightness_set(struct led_classdev *led_cdev,
  18. enum led_brightness value, int offset)
  19. {
  20. struct locomo_dev *locomo_dev = LOCOMO_DEV(led_cdev->dev->parent);
  21. unsigned long flags;
  22. local_irq_save(flags);
  23. if (value)
  24. locomo_writel(LOCOMO_LPT_TOFH, locomo_dev->mapbase + offset);
  25. else
  26. locomo_writel(LOCOMO_LPT_TOFL, locomo_dev->mapbase + offset);
  27. local_irq_restore(flags);
  28. }
  29. static void locomoled_brightness_set0(struct led_classdev *led_cdev,
  30. enum led_brightness value)
  31. {
  32. locomoled_brightness_set(led_cdev, value, LOCOMO_LPT0);
  33. }
  34. static void locomoled_brightness_set1(struct led_classdev *led_cdev,
  35. enum led_brightness value)
  36. {
  37. locomoled_brightness_set(led_cdev, value, LOCOMO_LPT1);
  38. }
  39. static struct led_classdev locomo_led0 = {
  40. .name = "locomo:amber:charge",
  41. .default_trigger = "main-battery-charging",
  42. .brightness_set = locomoled_brightness_set0,
  43. };
  44. static struct led_classdev locomo_led1 = {
  45. .name = "locomo:green:mail",
  46. .default_trigger = "nand-disk",
  47. .brightness_set = locomoled_brightness_set1,
  48. };
  49. static int locomoled_probe(struct locomo_dev *ldev)
  50. {
  51. int ret;
  52. ret = devm_led_classdev_register(&ldev->dev, &locomo_led0);
  53. if (ret < 0)
  54. return ret;
  55. return devm_led_classdev_register(&ldev->dev, &locomo_led1);
  56. }
  57. static struct locomo_driver locomoled_driver = {
  58. .drv = {
  59. .name = "locomoled"
  60. },
  61. .devid = LOCOMO_DEVID_LED,
  62. .probe = locomoled_probe,
  63. };
  64. static int __init locomoled_init(void)
  65. {
  66. return locomo_driver_register(&locomoled_driver);
  67. }
  68. module_init(locomoled_init);
  69. MODULE_AUTHOR("John Lenz <lenz@cs.wisc.edu>");
  70. MODULE_DESCRIPTION("Locomo LED driver");
  71. MODULE_LICENSE("GPL");