hwgpe.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. /******************************************************************************
  2. *
  3. * Module Name: hwgpe - Low level GPE enable/disable/clear functions
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2005, R. Byron Moore
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #include <acpi/acpi.h>
  43. #include <acpi/acevents.h>
  44. #define _COMPONENT ACPI_HARDWARE
  45. ACPI_MODULE_NAME ("hwgpe")
  46. /******************************************************************************
  47. *
  48. * FUNCTION: acpi_hw_write_gpe_enable_reg
  49. *
  50. * PARAMETERS: gpe_event_info - Info block for the GPE to be enabled
  51. *
  52. * RETURN: Status
  53. *
  54. * DESCRIPTION: Write a GPE enable register. Note: The bit for this GPE must
  55. * already be cleared or set in the parent register
  56. * enable_for_run mask.
  57. *
  58. ******************************************************************************/
  59. acpi_status
  60. acpi_hw_write_gpe_enable_reg (
  61. struct acpi_gpe_event_info *gpe_event_info)
  62. {
  63. struct acpi_gpe_register_info *gpe_register_info;
  64. acpi_status status;
  65. ACPI_FUNCTION_ENTRY ();
  66. /* Get the info block for the entire GPE register */
  67. gpe_register_info = gpe_event_info->register_info;
  68. if (!gpe_register_info) {
  69. return (AE_NOT_EXIST);
  70. }
  71. /* Write the entire GPE (runtime) enable register */
  72. status = acpi_hw_low_level_write (8, gpe_register_info->enable_for_run,
  73. &gpe_register_info->enable_address);
  74. return (status);
  75. }
  76. /******************************************************************************
  77. *
  78. * FUNCTION: acpi_hw_clear_gpe
  79. *
  80. * PARAMETERS: gpe_event_info - Info block for the GPE to be cleared
  81. *
  82. * RETURN: Status
  83. *
  84. * DESCRIPTION: Clear the status bit for a single GPE.
  85. *
  86. ******************************************************************************/
  87. acpi_status
  88. acpi_hw_clear_gpe (
  89. struct acpi_gpe_event_info *gpe_event_info)
  90. {
  91. acpi_status status;
  92. ACPI_FUNCTION_ENTRY ();
  93. /*
  94. * Write a one to the appropriate bit in the status register to
  95. * clear this GPE.
  96. */
  97. status = acpi_hw_low_level_write (8, gpe_event_info->register_bit,
  98. &gpe_event_info->register_info->status_address);
  99. return (status);
  100. }
  101. /******************************************************************************
  102. *
  103. * FUNCTION: acpi_hw_get_gpe_status
  104. *
  105. * PARAMETERS: gpe_event_info - Info block for the GPE to queried
  106. * event_status - Where the GPE status is returned
  107. *
  108. * RETURN: Status
  109. *
  110. * DESCRIPTION: Return the status of a single GPE.
  111. *
  112. ******************************************************************************/
  113. #ifdef ACPI_FUTURE_USAGE
  114. acpi_status
  115. acpi_hw_get_gpe_status (
  116. struct acpi_gpe_event_info *gpe_event_info,
  117. acpi_event_status *event_status)
  118. {
  119. u32 in_byte;
  120. u8 register_bit;
  121. struct acpi_gpe_register_info *gpe_register_info;
  122. acpi_status status;
  123. acpi_event_status local_event_status = 0;
  124. ACPI_FUNCTION_ENTRY ();
  125. if (!event_status) {
  126. return (AE_BAD_PARAMETER);
  127. }
  128. /* Get the info block for the entire GPE register */
  129. gpe_register_info = gpe_event_info->register_info;
  130. /* Get the register bitmask for this GPE */
  131. register_bit = gpe_event_info->register_bit;
  132. /* GPE currently enabled? (enabled for runtime?) */
  133. if (register_bit & gpe_register_info->enable_for_run) {
  134. local_event_status |= ACPI_EVENT_FLAG_ENABLED;
  135. }
  136. /* GPE enabled for wake? */
  137. if (register_bit & gpe_register_info->enable_for_wake) {
  138. local_event_status |= ACPI_EVENT_FLAG_WAKE_ENABLED;
  139. }
  140. /* GPE currently active (status bit == 1)? */
  141. status = acpi_hw_low_level_read (8, &in_byte, &gpe_register_info->status_address);
  142. if (ACPI_FAILURE (status)) {
  143. goto unlock_and_exit;
  144. }
  145. if (register_bit & in_byte) {
  146. local_event_status |= ACPI_EVENT_FLAG_SET;
  147. }
  148. /* Set return value */
  149. (*event_status) = local_event_status;
  150. unlock_and_exit:
  151. return (status);
  152. }
  153. #endif /* ACPI_FUTURE_USAGE */
  154. /******************************************************************************
  155. *
  156. * FUNCTION: acpi_hw_disable_gpe_block
  157. *
  158. * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
  159. * gpe_block - Gpe Block info
  160. *
  161. * RETURN: Status
  162. *
  163. * DESCRIPTION: Disable all GPEs within a GPE block
  164. *
  165. ******************************************************************************/
  166. acpi_status
  167. acpi_hw_disable_gpe_block (
  168. struct acpi_gpe_xrupt_info *gpe_xrupt_info,
  169. struct acpi_gpe_block_info *gpe_block)
  170. {
  171. u32 i;
  172. acpi_status status;
  173. /* Examine each GPE Register within the block */
  174. for (i = 0; i < gpe_block->register_count; i++) {
  175. /* Disable all GPEs in this register */
  176. status = acpi_hw_low_level_write (8, 0x00,
  177. &gpe_block->register_info[i].enable_address);
  178. if (ACPI_FAILURE (status)) {
  179. return (status);
  180. }
  181. }
  182. return (AE_OK);
  183. }
  184. /******************************************************************************
  185. *
  186. * FUNCTION: acpi_hw_clear_gpe_block
  187. *
  188. * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
  189. * gpe_block - Gpe Block info
  190. *
  191. * RETURN: Status
  192. *
  193. * DESCRIPTION: Clear status bits for all GPEs within a GPE block
  194. *
  195. ******************************************************************************/
  196. acpi_status
  197. acpi_hw_clear_gpe_block (
  198. struct acpi_gpe_xrupt_info *gpe_xrupt_info,
  199. struct acpi_gpe_block_info *gpe_block)
  200. {
  201. u32 i;
  202. acpi_status status;
  203. /* Examine each GPE Register within the block */
  204. for (i = 0; i < gpe_block->register_count; i++) {
  205. /* Clear status on all GPEs in this register */
  206. status = acpi_hw_low_level_write (8, 0xFF,
  207. &gpe_block->register_info[i].status_address);
  208. if (ACPI_FAILURE (status)) {
  209. return (status);
  210. }
  211. }
  212. return (AE_OK);
  213. }
  214. /******************************************************************************
  215. *
  216. * FUNCTION: acpi_hw_enable_runtime_gpe_block
  217. *
  218. * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
  219. * gpe_block - Gpe Block info
  220. *
  221. * RETURN: Status
  222. *
  223. * DESCRIPTION: Enable all "runtime" GPEs within a GPE block. (Includes
  224. * combination wake/run GPEs.)
  225. *
  226. ******************************************************************************/
  227. acpi_status
  228. acpi_hw_enable_runtime_gpe_block (
  229. struct acpi_gpe_xrupt_info *gpe_xrupt_info,
  230. struct acpi_gpe_block_info *gpe_block)
  231. {
  232. u32 i;
  233. acpi_status status;
  234. /* NOTE: assumes that all GPEs are currently disabled */
  235. /* Examine each GPE Register within the block */
  236. for (i = 0; i < gpe_block->register_count; i++) {
  237. if (!gpe_block->register_info[i].enable_for_run) {
  238. continue;
  239. }
  240. /* Enable all "runtime" GPEs in this register */
  241. status = acpi_hw_low_level_write (8, gpe_block->register_info[i].enable_for_run,
  242. &gpe_block->register_info[i].enable_address);
  243. if (ACPI_FAILURE (status)) {
  244. return (status);
  245. }
  246. }
  247. return (AE_OK);
  248. }
  249. /******************************************************************************
  250. *
  251. * FUNCTION: acpi_hw_enable_wakeup_gpe_block
  252. *
  253. * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
  254. * gpe_block - Gpe Block info
  255. *
  256. * RETURN: Status
  257. *
  258. * DESCRIPTION: Enable all "wake" GPEs within a GPE block. (Includes
  259. * combination wake/run GPEs.)
  260. *
  261. ******************************************************************************/
  262. acpi_status
  263. acpi_hw_enable_wakeup_gpe_block (
  264. struct acpi_gpe_xrupt_info *gpe_xrupt_info,
  265. struct acpi_gpe_block_info *gpe_block)
  266. {
  267. u32 i;
  268. acpi_status status;
  269. /* Examine each GPE Register within the block */
  270. for (i = 0; i < gpe_block->register_count; i++) {
  271. if (!gpe_block->register_info[i].enable_for_wake) {
  272. continue;
  273. }
  274. /* Enable all "wake" GPEs in this register */
  275. status = acpi_hw_low_level_write (8, gpe_block->register_info[i].enable_for_wake,
  276. &gpe_block->register_info[i].enable_address);
  277. if (ACPI_FAILURE (status)) {
  278. return (status);
  279. }
  280. }
  281. return (AE_OK);
  282. }
  283. /******************************************************************************
  284. *
  285. * FUNCTION: acpi_hw_disable_all_gpes
  286. *
  287. * PARAMETERS: Flags - ACPI_NOT_ISR or ACPI_ISR
  288. *
  289. * RETURN: Status
  290. *
  291. * DESCRIPTION: Disable and clear all GPEs
  292. *
  293. ******************************************************************************/
  294. acpi_status
  295. acpi_hw_disable_all_gpes (
  296. u32 flags)
  297. {
  298. acpi_status status;
  299. ACPI_FUNCTION_TRACE ("hw_disable_all_gpes");
  300. status = acpi_ev_walk_gpe_list (acpi_hw_disable_gpe_block, flags);
  301. status = acpi_ev_walk_gpe_list (acpi_hw_clear_gpe_block, flags);
  302. return_ACPI_STATUS (status);
  303. }
  304. /******************************************************************************
  305. *
  306. * FUNCTION: acpi_hw_enable_all_runtime_gpes
  307. *
  308. * PARAMETERS: Flags - ACPI_NOT_ISR or ACPI_ISR
  309. *
  310. * RETURN: Status
  311. *
  312. * DESCRIPTION: Enable all GPEs of the given type
  313. *
  314. ******************************************************************************/
  315. acpi_status
  316. acpi_hw_enable_all_runtime_gpes (
  317. u32 flags)
  318. {
  319. acpi_status status;
  320. ACPI_FUNCTION_TRACE ("hw_enable_all_runtime_gpes");
  321. status = acpi_ev_walk_gpe_list (acpi_hw_enable_runtime_gpe_block, flags);
  322. return_ACPI_STATUS (status);
  323. }
  324. /******************************************************************************
  325. *
  326. * FUNCTION: acpi_hw_enable_all_wakeup_gpes
  327. *
  328. * PARAMETERS: Flags - ACPI_NOT_ISR or ACPI_ISR
  329. *
  330. * RETURN: Status
  331. *
  332. * DESCRIPTION: Enable all GPEs of the given type
  333. *
  334. ******************************************************************************/
  335. acpi_status
  336. acpi_hw_enable_all_wakeup_gpes (
  337. u32 flags)
  338. {
  339. acpi_status status;
  340. ACPI_FUNCTION_TRACE ("hw_enable_all_wakeup_gpes");
  341. status = acpi_ev_walk_gpe_list (acpi_hw_enable_wakeup_gpe_block, flags);
  342. return_ACPI_STATUS (status);
  343. }