via-pmu-led.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * via-pmu LED class device
  3. *
  4. * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
  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, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  14. * NON INFRINGEMENT. See the GNU General Public License for more
  15. * details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. */
  22. #include <linux/types.h>
  23. #include <linux/kernel.h>
  24. #include <linux/device.h>
  25. #include <linux/leds.h>
  26. #include <linux/adb.h>
  27. #include <linux/pmu.h>
  28. #include <asm/prom.h>
  29. static spinlock_t pmu_blink_lock;
  30. static struct adb_request pmu_blink_req;
  31. /* -1: no change, 0: request off, 1: request on */
  32. static int requested_change;
  33. static void pmu_req_done(struct adb_request * req)
  34. {
  35. unsigned long flags;
  36. spin_lock_irqsave(&pmu_blink_lock, flags);
  37. /* if someone requested a change in the meantime
  38. * (we only see the last one which is fine)
  39. * then apply it now */
  40. if (requested_change != -1 && !pmu_sys_suspended)
  41. pmu_request(&pmu_blink_req, NULL, 4, 0xee, 4, 0, requested_change);
  42. /* reset requested change */
  43. requested_change = -1;
  44. spin_unlock_irqrestore(&pmu_blink_lock, flags);
  45. }
  46. static void pmu_led_set(struct led_classdev *led_cdev,
  47. enum led_brightness brightness)
  48. {
  49. unsigned long flags;
  50. spin_lock_irqsave(&pmu_blink_lock, flags);
  51. switch (brightness) {
  52. case LED_OFF:
  53. requested_change = 0;
  54. break;
  55. case LED_FULL:
  56. requested_change = 1;
  57. break;
  58. default:
  59. goto out;
  60. break;
  61. }
  62. /* if request isn't done, then don't do anything */
  63. if (pmu_blink_req.complete && !pmu_sys_suspended)
  64. pmu_request(&pmu_blink_req, NULL, 4, 0xee, 4, 0, requested_change);
  65. out:
  66. spin_unlock_irqrestore(&pmu_blink_lock, flags);
  67. }
  68. static struct led_classdev pmu_led = {
  69. .name = "pmu-led::front",
  70. #ifdef CONFIG_ADB_PMU_LED_IDE
  71. .default_trigger = "ide-disk",
  72. #endif
  73. .brightness_set = pmu_led_set,
  74. };
  75. static int __init via_pmu_led_init(void)
  76. {
  77. struct device_node *dt;
  78. const char *model;
  79. /* only do this on keylargo based models */
  80. if (pmu_get_model() != PMU_KEYLARGO_BASED)
  81. return -ENODEV;
  82. dt = of_find_node_by_path("/");
  83. if (dt == NULL)
  84. return -ENODEV;
  85. model = of_get_property(dt, "model", NULL);
  86. if (model == NULL) {
  87. of_node_put(dt);
  88. return -ENODEV;
  89. }
  90. if (strncmp(model, "PowerBook", strlen("PowerBook")) != 0 &&
  91. strncmp(model, "iBook", strlen("iBook")) != 0 &&
  92. strcmp(model, "PowerMac7,2") != 0 &&
  93. strcmp(model, "PowerMac7,3") != 0) {
  94. of_node_put(dt);
  95. /* ignore */
  96. return -ENODEV;
  97. }
  98. of_node_put(dt);
  99. spin_lock_init(&pmu_blink_lock);
  100. /* no outstanding req */
  101. pmu_blink_req.complete = 1;
  102. pmu_blink_req.done = pmu_req_done;
  103. return led_classdev_register(NULL, &pmu_led);
  104. }
  105. late_initcall(via_pmu_led_init);