cm_sbs.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. #define PREFIX "ACPI: "
  30. ACPI_MODULE_NAME("cm_sbs");
  31. #define ACPI_AC_CLASS "ac_adapter"
  32. #define ACPI_BATTERY_CLASS "battery"
  33. #define _COMPONENT ACPI_SBS_COMPONENT
  34. static struct proc_dir_entry *acpi_ac_dir;
  35. static struct proc_dir_entry *acpi_battery_dir;
  36. static DEFINE_MUTEX(cm_sbs_mutex);
  37. static int lock_ac_dir_cnt;
  38. static int lock_battery_dir_cnt;
  39. struct proc_dir_entry *acpi_lock_ac_dir(void)
  40. {
  41. mutex_lock(&cm_sbs_mutex);
  42. if (!acpi_ac_dir)
  43. acpi_ac_dir = proc_mkdir(ACPI_AC_CLASS, acpi_root_dir);
  44. if (acpi_ac_dir) {
  45. lock_ac_dir_cnt++;
  46. } else {
  47. printk(KERN_ERR PREFIX
  48. "Cannot create %s\n", ACPI_AC_CLASS);
  49. }
  50. mutex_unlock(&cm_sbs_mutex);
  51. return acpi_ac_dir;
  52. }
  53. EXPORT_SYMBOL(acpi_lock_ac_dir);
  54. void acpi_unlock_ac_dir(struct proc_dir_entry *acpi_ac_dir_param)
  55. {
  56. mutex_lock(&cm_sbs_mutex);
  57. if (acpi_ac_dir_param)
  58. lock_ac_dir_cnt--;
  59. if (lock_ac_dir_cnt == 0 && acpi_ac_dir_param && acpi_ac_dir) {
  60. remove_proc_entry(ACPI_AC_CLASS, acpi_root_dir);
  61. acpi_ac_dir = NULL;
  62. }
  63. mutex_unlock(&cm_sbs_mutex);
  64. }
  65. EXPORT_SYMBOL(acpi_unlock_ac_dir);
  66. struct proc_dir_entry *acpi_lock_battery_dir(void)
  67. {
  68. mutex_lock(&cm_sbs_mutex);
  69. if (!acpi_battery_dir) {
  70. acpi_battery_dir =
  71. proc_mkdir(ACPI_BATTERY_CLASS, acpi_root_dir);
  72. }
  73. if (acpi_battery_dir) {
  74. lock_battery_dir_cnt++;
  75. } else {
  76. printk(KERN_ERR PREFIX
  77. "Cannot create %s\n", ACPI_BATTERY_CLASS);
  78. }
  79. mutex_unlock(&cm_sbs_mutex);
  80. return acpi_battery_dir;
  81. }
  82. EXPORT_SYMBOL(acpi_lock_battery_dir);
  83. void acpi_unlock_battery_dir(struct proc_dir_entry *acpi_battery_dir_param)
  84. {
  85. mutex_lock(&cm_sbs_mutex);
  86. if (acpi_battery_dir_param)
  87. lock_battery_dir_cnt--;
  88. if (lock_battery_dir_cnt == 0 && acpi_battery_dir_param
  89. && acpi_battery_dir) {
  90. remove_proc_entry(ACPI_BATTERY_CLASS, acpi_root_dir);
  91. acpi_battery_dir = NULL;
  92. }
  93. mutex_unlock(&cm_sbs_mutex);
  94. return;
  95. }
  96. EXPORT_SYMBOL(acpi_unlock_battery_dir);