leds-cobalt-raq.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * LEDs driver for the Cobalt Raq series.
  3. *
  4. * Copyright (C) 2007 Yoichi Yuasa <yuasa@linux-mips.org>
  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 as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <linux/init.h>
  21. #include <linux/io.h>
  22. #include <linux/ioport.h>
  23. #include <linux/leds.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/spinlock.h>
  26. #include <linux/types.h>
  27. #define LED_WEB 0x04
  28. #define LED_POWER_OFF 0x08
  29. static void __iomem *led_port;
  30. static u8 led_value;
  31. static DEFINE_SPINLOCK(led_value_lock);
  32. static void raq_web_led_set(struct led_classdev *led_cdev,
  33. enum led_brightness brightness)
  34. {
  35. unsigned long flags;
  36. spin_lock_irqsave(&led_value_lock, flags);
  37. if (brightness)
  38. led_value |= LED_WEB;
  39. else
  40. led_value &= ~LED_WEB;
  41. writeb(led_value, led_port);
  42. spin_unlock_irqrestore(&led_value_lock, flags);
  43. }
  44. static struct led_classdev raq_web_led = {
  45. .name = "raq::web",
  46. .brightness_set = raq_web_led_set,
  47. };
  48. static void raq_power_off_led_set(struct led_classdev *led_cdev,
  49. enum led_brightness brightness)
  50. {
  51. unsigned long flags;
  52. spin_lock_irqsave(&led_value_lock, flags);
  53. if (brightness)
  54. led_value |= LED_POWER_OFF;
  55. else
  56. led_value &= ~LED_POWER_OFF;
  57. writeb(led_value, led_port);
  58. spin_unlock_irqrestore(&led_value_lock, flags);
  59. }
  60. static struct led_classdev raq_power_off_led = {
  61. .name = "raq::power-off",
  62. .brightness_set = raq_power_off_led_set,
  63. .default_trigger = "power-off",
  64. };
  65. static int __devinit cobalt_raq_led_probe(struct platform_device *pdev)
  66. {
  67. struct resource *res;
  68. int retval;
  69. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  70. if (!res)
  71. return -EBUSY;
  72. led_port = ioremap(res->start, resource_size(res));
  73. if (!led_port)
  74. return -ENOMEM;
  75. retval = led_classdev_register(&pdev->dev, &raq_power_off_led);
  76. if (retval)
  77. goto err_iounmap;
  78. retval = led_classdev_register(&pdev->dev, &raq_web_led);
  79. if (retval)
  80. goto err_unregister;
  81. return 0;
  82. err_unregister:
  83. led_classdev_unregister(&raq_power_off_led);
  84. err_iounmap:
  85. iounmap(led_port);
  86. led_port = NULL;
  87. return retval;
  88. }
  89. static int __devexit cobalt_raq_led_remove(struct platform_device *pdev)
  90. {
  91. led_classdev_unregister(&raq_power_off_led);
  92. led_classdev_unregister(&raq_web_led);
  93. if (led_port) {
  94. iounmap(led_port);
  95. led_port = NULL;
  96. }
  97. return 0;
  98. }
  99. static struct platform_driver cobalt_raq_led_driver = {
  100. .probe = cobalt_raq_led_probe,
  101. .remove = __devexit_p(cobalt_raq_led_remove),
  102. .driver = {
  103. .name = "cobalt-raq-leds",
  104. .owner = THIS_MODULE,
  105. },
  106. };
  107. static int __init cobalt_raq_led_init(void)
  108. {
  109. return platform_driver_register(&cobalt_raq_led_driver);
  110. }
  111. module_init(cobalt_raq_led_init);