leds-cobalt-qube.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * Copyright 2006 - Florian Fainelli <florian@openwrt.org>
  3. *
  4. * Control the Cobalt Qube/RaQ front LED
  5. */
  6. #include <linux/init.h>
  7. #include <linux/io.h>
  8. #include <linux/ioport.h>
  9. #include <linux/leds.h>
  10. #include <linux/module.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/types.h>
  13. #define LED_FRONT_LEFT 0x01
  14. #define LED_FRONT_RIGHT 0x02
  15. static void __iomem *led_port;
  16. static u8 led_value;
  17. static void qube_front_led_set(struct led_classdev *led_cdev,
  18. enum led_brightness brightness)
  19. {
  20. if (brightness)
  21. led_value = LED_FRONT_LEFT | LED_FRONT_RIGHT;
  22. else
  23. led_value = ~(LED_FRONT_LEFT | LED_FRONT_RIGHT);
  24. writeb(led_value, led_port);
  25. }
  26. static struct led_classdev qube_front_led = {
  27. .name = "qube::front",
  28. .brightness = LED_FULL,
  29. .brightness_set = qube_front_led_set,
  30. .default_trigger = "default-on",
  31. };
  32. static int __devinit cobalt_qube_led_probe(struct platform_device *pdev)
  33. {
  34. struct resource *res;
  35. int retval;
  36. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  37. if (!res)
  38. return -EBUSY;
  39. led_port = ioremap(res->start, resource_size(res));
  40. if (!led_port)
  41. return -ENOMEM;
  42. led_value = LED_FRONT_LEFT | LED_FRONT_RIGHT;
  43. writeb(led_value, led_port);
  44. retval = led_classdev_register(&pdev->dev, &qube_front_led);
  45. if (retval)
  46. goto err_iounmap;
  47. return 0;
  48. err_iounmap:
  49. iounmap(led_port);
  50. led_port = NULL;
  51. return retval;
  52. }
  53. static int __devexit cobalt_qube_led_remove(struct platform_device *pdev)
  54. {
  55. led_classdev_unregister(&qube_front_led);
  56. if (led_port) {
  57. iounmap(led_port);
  58. led_port = NULL;
  59. }
  60. return 0;
  61. }
  62. /* work with hotplug and coldplug */
  63. MODULE_ALIAS("platform:cobalt-qube-leds");
  64. static struct platform_driver cobalt_qube_led_driver = {
  65. .probe = cobalt_qube_led_probe,
  66. .remove = __devexit_p(cobalt_qube_led_remove),
  67. .driver = {
  68. .name = "cobalt-qube-leds",
  69. .owner = THIS_MODULE,
  70. },
  71. };
  72. static int __init cobalt_qube_led_init(void)
  73. {
  74. return platform_driver_register(&cobalt_qube_led_driver);
  75. }
  76. static void __exit cobalt_qube_led_exit(void)
  77. {
  78. platform_driver_unregister(&cobalt_qube_led_driver);
  79. }
  80. module_init(cobalt_qube_led_init);
  81. module_exit(cobalt_qube_led_exit);
  82. MODULE_LICENSE("GPL");
  83. MODULE_DESCRIPTION("Front LED support for Cobalt Server");
  84. MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>");