leds-hp-disk.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * leds-hp-disk.c - driver for HP "hard disk protection" LED
  3. *
  4. * Copyright (C) 2008 Pavel Machek
  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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <linux/kernel.h>
  21. #include <linux/init.h>
  22. #include <linux/dmi.h>
  23. #include <linux/module.h>
  24. #include <linux/types.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/input.h>
  28. #include <linux/kthread.h>
  29. #include <linux/leds.h>
  30. #include <acpi/acpi_drivers.h>
  31. #define DRIVER_NAME "leds-hp-disk"
  32. #define ACPI_MDPS_CLASS "led"
  33. /* For automatic insertion of the module */
  34. static struct acpi_device_id hpled_device_ids[] = {
  35. {"HPQ0004", 0}, /* HP Mobile Data Protection System PNP */
  36. {"", 0},
  37. };
  38. MODULE_DEVICE_TABLE(acpi, hpled_device_ids);
  39. struct acpi_hpled {
  40. struct acpi_device *device; /* The ACPI device */
  41. };
  42. static struct acpi_hpled adev;
  43. static acpi_status hpled_acpi_write(acpi_handle handle, int reg)
  44. {
  45. unsigned long long ret; /* Not used when writing */
  46. union acpi_object in_obj[1];
  47. struct acpi_object_list args = { 1, in_obj };
  48. in_obj[0].type = ACPI_TYPE_INTEGER;
  49. in_obj[0].integer.value = reg;
  50. return acpi_evaluate_integer(handle, "ALED", &args, &ret);
  51. }
  52. static void hpled_set(struct led_classdev *led_cdev,
  53. enum led_brightness value)
  54. {
  55. hpled_acpi_write(adev.device->handle, !!value);
  56. }
  57. static struct led_classdev hpled_led = {
  58. .name = "hp:red:hddprotection",
  59. .default_trigger = "heartbeat",
  60. .brightness_set = hpled_set,
  61. };
  62. #ifdef CONFIG_PM
  63. static int hpled_suspend(struct acpi_device *dev, pm_message_t state)
  64. {
  65. led_classdev_suspend(&hpled_led);
  66. return 0;
  67. }
  68. static int hpled_resume(struct acpi_device *dev)
  69. {
  70. led_classdev_resume(&hpled_led);
  71. return 0;
  72. }
  73. #else
  74. #define hpled_suspend NULL
  75. #define hpled_resume NULL
  76. #endif
  77. static int hpled_add(struct acpi_device *device)
  78. {
  79. int ret;
  80. if (!device)
  81. return -EINVAL;
  82. adev.device = device;
  83. strcpy(acpi_device_name(device), DRIVER_NAME);
  84. strcpy(acpi_device_class(device), ACPI_MDPS_CLASS);
  85. device->driver_data = &adev;
  86. ret = led_classdev_register(NULL, &hpled_led);
  87. return ret;
  88. }
  89. static int hpled_remove(struct acpi_device *device, int type)
  90. {
  91. if (!device)
  92. return -EINVAL;
  93. led_classdev_unregister(&hpled_led);
  94. return 0;
  95. }
  96. static struct acpi_driver leds_hp_driver = {
  97. .name = DRIVER_NAME,
  98. .class = ACPI_MDPS_CLASS,
  99. .ids = hpled_device_ids,
  100. .ops = {
  101. .add = hpled_add,
  102. .remove = hpled_remove,
  103. .suspend = hpled_suspend,
  104. .resume = hpled_resume,
  105. }
  106. };
  107. static int __init hpled_init_module(void)
  108. {
  109. int ret;
  110. if (acpi_disabled)
  111. return -ENODEV;
  112. ret = acpi_bus_register_driver(&leds_hp_driver);
  113. if (ret < 0)
  114. return ret;
  115. printk(KERN_INFO DRIVER_NAME " driver loaded.\n");
  116. return 0;
  117. }
  118. static void __exit hpled_exit_module(void)
  119. {
  120. acpi_bus_unregister_driver(&leds_hp_driver);
  121. }
  122. MODULE_DESCRIPTION("Driver for HP disk protection LED");
  123. MODULE_AUTHOR("Pavel Machek <pavel@suse.cz>");
  124. MODULE_LICENSE("GPL");
  125. module_init(hpled_init_module);
  126. module_exit(hpled_exit_module);