cm_sbs.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/module.h>
  18. #include <linux/init.h>
  19. #include <linux/acpi.h>
  20. #include <linux/types.h>
  21. #include <linux/proc_fs.h>
  22. #include <linux/seq_file.h>
  23. #include <acpi/acpi_bus.h>
  24. #include <acpi/acpi_drivers.h>
  25. #define PREFIX "ACPI: "
  26. ACPI_MODULE_NAME("cm_sbs");
  27. #define ACPI_AC_CLASS "ac_adapter"
  28. #define ACPI_BATTERY_CLASS "battery"
  29. #define _COMPONENT ACPI_SBS_COMPONENT
  30. static struct proc_dir_entry *acpi_ac_dir;
  31. static struct proc_dir_entry *acpi_battery_dir;
  32. static DEFINE_MUTEX(cm_sbs_mutex);
  33. static int lock_ac_dir_cnt;
  34. static int lock_battery_dir_cnt;
  35. struct proc_dir_entry *acpi_lock_ac_dir(void)
  36. {
  37. mutex_lock(&cm_sbs_mutex);
  38. if (!acpi_ac_dir)
  39. acpi_ac_dir = proc_mkdir(ACPI_AC_CLASS, acpi_root_dir);
  40. if (acpi_ac_dir) {
  41. lock_ac_dir_cnt++;
  42. } else {
  43. printk(KERN_ERR PREFIX
  44. "Cannot create %s\n", ACPI_AC_CLASS);
  45. }
  46. mutex_unlock(&cm_sbs_mutex);
  47. return acpi_ac_dir;
  48. }
  49. EXPORT_SYMBOL(acpi_lock_ac_dir);
  50. void acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir_param)
  51. {
  52. mutex_lock(&cm_sbs_mutex);
  53. if (acpi_ac_dir_param)
  54. lock_ac_dir_cnt--;
  55. if (lock_ac_dir_cnt == 0 && acpi_ac_dir_param && acpi_ac_dir) {
  56. remove_proc_entry(ACPI_AC_CLASS, acpi_root_dir);
  57. acpi_ac_dir = NULL;
  58. }
  59. mutex_unlock(&cm_sbs_mutex);
  60. }
  61. EXPORT_SYMBOL(acpi_unlock_ac_dir);
  62. struct proc_dir_entry *acpi_lock_battery_dir(void)
  63. {
  64. mutex_lock(&cm_sbs_mutex);
  65. if (!acpi_battery_dir) {
  66. acpi_battery_dir =
  67. proc_mkdir(ACPI_BATTERY_CLASS, acpi_root_dir);
  68. }
  69. if (acpi_battery_dir) {
  70. lock_battery_dir_cnt++;
  71. } else {
  72. printk(KERN_ERR PREFIX
  73. "Cannot create %s\n", ACPI_BATTERY_CLASS);
  74. }
  75. mutex_unlock(&cm_sbs_mutex);
  76. return acpi_battery_dir;
  77. }
  78. EXPORT_SYMBOL(acpi_lock_battery_dir);
  79. void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir_param)
  80. {
  81. mutex_lock(&cm_sbs_mutex);
  82. if (acpi_battery_dir_param)
  83. lock_battery_dir_cnt--;
  84. if (lock_battery_dir_cnt == 0 && acpi_battery_dir_param
  85. && acpi_battery_dir) {
  86. remove_proc_entry(ACPI_BATTERY_CLASS, acpi_root_dir);
  87. acpi_battery_dir = NULL;
  88. }
  89. mutex_unlock(&cm_sbs_mutex);
  90. return;
  91. }
  92. EXPORT_SYMBOL(acpi_unlock_battery_dir);