cm_sbs.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or (at
  7. * your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  17. *
  18. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  19. */
  20. #include <linux/kernel.h>
  21. #include <linux/module.h>
  22. #include <linux/init.h>
  23. #include <linux/acpi.h>
  24. #include <linux/types.h>
  25. #include <linux/proc_fs.h>
  26. #include <linux/seq_file.h>
  27. #include <acpi/acpi_bus.h>
  28. #include <acpi/acpi_drivers.h>
  29. #include <acpi/acmacros.h>
  30. #include <acpi/actypes.h>
  31. #include <acpi/acutils.h>
  32. ACPI_MODULE_NAME("cm_sbs")
  33. #define ACPI_AC_CLASS "ac_adapter"
  34. #define ACPI_BATTERY_CLASS "battery"
  35. #define ACPI_SBS_COMPONENT 0x00080000
  36. #define _COMPONENT ACPI_SBS_COMPONENT
  37. static struct proc_dir_entry *acpi_ac_dir;
  38. static struct proc_dir_entry *acpi_battery_dir;
  39. static struct semaphore cm_sbs_sem;
  40. static int lock_ac_dir_cnt = 0;
  41. static int lock_battery_dir_cnt = 0;
  42. struct proc_dir_entry *acpi_lock_ac_dir(void)
  43. {
  44. down(&cm_sbs_sem);
  45. if (!acpi_ac_dir) {
  46. acpi_ac_dir = proc_mkdir(ACPI_AC_CLASS, acpi_root_dir);
  47. }
  48. if (acpi_ac_dir) {
  49. lock_ac_dir_cnt++;
  50. } else {
  51. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  52. "Cannot create %s\n", ACPI_AC_CLASS));
  53. }
  54. up(&cm_sbs_sem);
  55. return acpi_ac_dir;
  56. }
  57. EXPORT_SYMBOL(acpi_lock_ac_dir);
  58. void acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir_param)
  59. {
  60. down(&cm_sbs_sem);
  61. if (acpi_ac_dir_param) {
  62. lock_ac_dir_cnt--;
  63. }
  64. if (lock_ac_dir_cnt == 0 && acpi_ac_dir_param && acpi_ac_dir) {
  65. remove_proc_entry(ACPI_AC_CLASS, acpi_root_dir);
  66. acpi_ac_dir = 0;
  67. }
  68. up(&cm_sbs_sem);
  69. }
  70. EXPORT_SYMBOL(acpi_unlock_ac_dir);
  71. struct proc_dir_entry *acpi_lock_battery_dir(void)
  72. {
  73. down(&cm_sbs_sem);
  74. if (!acpi_battery_dir) {
  75. acpi_battery_dir =
  76. proc_mkdir(ACPI_BATTERY_CLASS, acpi_root_dir);
  77. }
  78. if (acpi_battery_dir) {
  79. lock_battery_dir_cnt++;
  80. } else {
  81. ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
  82. "Cannot create %s\n", ACPI_BATTERY_CLASS));
  83. }
  84. up(&cm_sbs_sem);
  85. return acpi_battery_dir;
  86. }
  87. EXPORT_SYMBOL(acpi_lock_battery_dir);
  88. void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir_param)
  89. {
  90. down(&cm_sbs_sem);
  91. if (acpi_battery_dir_param) {
  92. lock_battery_dir_cnt--;
  93. }
  94. if (lock_battery_dir_cnt == 0 && acpi_battery_dir_param
  95. && acpi_battery_dir) {
  96. remove_proc_entry(ACPI_BATTERY_CLASS, acpi_root_dir);
  97. acpi_battery_dir = 0;
  98. }
  99. up(&cm_sbs_sem);
  100. return;
  101. }
  102. EXPORT_SYMBOL(acpi_unlock_battery_dir);
  103. static int __init acpi_cm_sbs_init(void)
  104. {
  105. if (acpi_disabled)
  106. return 0;
  107. init_MUTEX(&cm_sbs_sem);
  108. return 0;
  109. }
  110. subsys_initcall(acpi_cm_sbs_init);