leds-cobalt-qube.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright 2006 - Florian Fainelli <florian@openwrt.org>
  3. *
  4. * Control the Cobalt Qube/RaQ front LED
  5. */
  6. #include <linux/io.h>
  7. #include <linux/ioport.h>
  8. #include <linux/leds.h>
  9. #include <linux/module.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/types.h>
  12. #define LED_FRONT_LEFT 0x01
  13. #define LED_FRONT_RIGHT 0x02
  14. static void __iomem *led_port;
  15. static u8 led_value;
  16. static void qube_front_led_set(struct led_classdev *led_cdev,
  17. enum led_brightness brightness)
  18. {
  19. if (brightness)
  20. led_value = LED_FRONT_LEFT | LED_FRONT_RIGHT;
  21. else
  22. led_value = ~(LED_FRONT_LEFT | LED_FRONT_RIGHT);
  23. writeb(led_value, led_port);
  24. }
  25. static struct led_classdev qube_front_led = {
  26. .name = "qube::front",
  27. .brightness = LED_FULL,
  28. .brightness_set = qube_front_led_set,
  29. .default_trigger = "default-on",
  30. };
  31. static int cobalt_qube_led_probe(struct platform_device *pdev)
  32. {
  33. struct resource *res;
  34. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  35. if (!res)
  36. return -EBUSY;
  37. led_port = devm_ioremap(&pdev->dev, res->start, resource_size(res));
  38. if (!led_port)
  39. return -ENOMEM;
  40. led_value = LED_FRONT_LEFT | LED_FRONT_RIGHT;
  41. writeb(led_value, led_port);
  42. return devm_led_classdev_register(&pdev->dev, &qube_front_led);
  43. }
  44. static struct platform_driver cobalt_qube_led_driver = {
  45. .probe = cobalt_qube_led_probe,
  46. .driver = {
  47. .name = "cobalt-qube-leds",
  48. },
  49. };
  50. module_platform_driver(cobalt_qube_led_driver);
  51. MODULE_LICENSE("GPL");
  52. MODULE_DESCRIPTION("Front LED support for Cobalt Server");
  53. MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>");
  54. MODULE_ALIAS("platform:cobalt-qube-leds");