leds-cobalt-raq.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. #include <linux/export.h>
  28. #define LED_WEB 0x04
  29. #define LED_POWER_OFF 0x08
  30. static void __iomem *led_port;
  31. static u8 led_value;
  32. static DEFINE_SPINLOCK(led_value_lock);
  33. static void raq_web_led_set(struct led_classdev *led_cdev,
  34. enum led_brightness brightness)
  35. {
  36. unsigned long flags;
  37. spin_lock_irqsave(&led_value_lock, flags);
  38. if (brightness)
  39. led_value |= LED_WEB;
  40. else
  41. led_value &= ~LED_WEB;
  42. writeb(led_value, led_port);
  43. spin_unlock_irqrestore(&led_value_lock, flags);
  44. }
  45. static struct led_classdev raq_web_led = {
  46. .name = "raq::web",
  47. .brightness_set = raq_web_led_set,
  48. };
  49. static void raq_power_off_led_set(struct led_classdev *led_cdev,
  50. enum led_brightness brightness)
  51. {
  52. unsigned long flags;
  53. spin_lock_irqsave(&led_value_lock, flags);
  54. if (brightness)
  55. led_value |= LED_POWER_OFF;
  56. else
  57. led_value &= ~LED_POWER_OFF;
  58. writeb(led_value, led_port);
  59. spin_unlock_irqrestore(&led_value_lock, flags);
  60. }
  61. static struct led_classdev raq_power_off_led = {
  62. .name = "raq::power-off",
  63. .brightness_set = raq_power_off_led_set,
  64. .default_trigger = "power-off",
  65. };
  66. static int cobalt_raq_led_probe(struct platform_device *pdev)
  67. {
  68. struct resource *res;
  69. int retval;
  70. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  71. if (!res)
  72. return -EBUSY;
  73. led_port = devm_ioremap(&pdev->dev, res->start, resource_size(res));
  74. if (!led_port)
  75. return -ENOMEM;
  76. retval = led_classdev_register(&pdev->dev, &raq_power_off_led);
  77. if (retval)
  78. goto err_null;
  79. retval = led_classdev_register(&pdev->dev, &raq_web_led);
  80. if (retval)
  81. goto err_unregister;
  82. return 0;
  83. err_unregister:
  84. led_classdev_unregister(&raq_power_off_led);
  85. err_null:
  86. led_port = NULL;
  87. return retval;
  88. }
  89. static struct platform_driver cobalt_raq_led_driver = {
  90. .probe = cobalt_raq_led_probe,
  91. .driver = {
  92. .name = "cobalt-raq-leds",
  93. },
  94. };
  95. static int __init cobalt_raq_led_init(void)
  96. {
  97. return platform_driver_register(&cobalt_raq_led_driver);
  98. }
  99. device_initcall(cobalt_raq_led_init);