hwgpe.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  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. /* Local prototypes */
  47. static acpi_status
  48. acpi_hw_enable_wakeup_gpe_block (
  49. struct acpi_gpe_xrupt_info *gpe_xrupt_info,
  50. struct acpi_gpe_block_info *gpe_block);
  51. /******************************************************************************
  52. *
  53. * FUNCTION: acpi_hw_write_gpe_enable_reg
  54. *
  55. * PARAMETERS: gpe_event_info - Info block for the GPE to be enabled
  56. *
  57. * RETURN: Status
  58. *
  59. * DESCRIPTION: Write a GPE enable register. Note: The bit for this GPE must
  60. * already be cleared or set in the parent register
  61. * enable_for_run mask.
  62. *
  63. ******************************************************************************/
  64. acpi_status
  65. acpi_hw_write_gpe_enable_reg (
  66. struct acpi_gpe_event_info *gpe_event_info)
  67. {
  68. struct acpi_gpe_register_info *gpe_register_info;
  69. acpi_status status;
  70. ACPI_FUNCTION_ENTRY ();
  71. /* Get the info block for the entire GPE register */
  72. gpe_register_info = gpe_event_info->register_info;
  73. if (!gpe_register_info) {
  74. return (AE_NOT_EXIST);
  75. }
  76. /* Write the entire GPE (runtime) enable register */
  77. status = acpi_hw_low_level_write (8, gpe_register_info->enable_for_run,
  78. &gpe_register_info->enable_address);
  79. return (status);
  80. }
  81. /******************************************************************************
  82. *
  83. * FUNCTION: acpi_hw_clear_gpe
  84. *
  85. * PARAMETERS: gpe_event_info - Info block for the GPE to be cleared
  86. *
  87. * RETURN: Status
  88. *
  89. * DESCRIPTION: Clear the status bit for a single GPE.
  90. *
  91. ******************************************************************************/
  92. acpi_status
  93. acpi_hw_clear_gpe (
  94. struct acpi_gpe_event_info *gpe_event_info)
  95. {
  96. acpi_status status;
  97. ACPI_FUNCTION_ENTRY ();
  98. /*
  99. * Write a one to the appropriate bit in the status register to
  100. * clear this GPE.
  101. */
  102. status = acpi_hw_low_level_write (8, gpe_event_info->register_bit,
  103. &gpe_event_info->register_info->status_address);
  104. return (status);
  105. }
  106. /******************************************************************************
  107. *
  108. * FUNCTION: acpi_hw_get_gpe_status
  109. *
  110. * PARAMETERS: gpe_event_info - Info block for the GPE to queried
  111. * event_status - Where the GPE status is returned
  112. *
  113. * RETURN: Status
  114. *
  115. * DESCRIPTION: Return the status of a single GPE.
  116. *
  117. ******************************************************************************/
  118. #ifdef ACPI_FUTURE_USAGE
  119. acpi_status
  120. acpi_hw_get_gpe_status (
  121. struct acpi_gpe_event_info *gpe_event_info,
  122. acpi_event_status *event_status)
  123. {
  124. u32 in_byte;
  125. u8 register_bit;
  126. struct acpi_gpe_register_info *gpe_register_info;
  127. acpi_status status;
  128. acpi_event_status local_event_status = 0;
  129. ACPI_FUNCTION_ENTRY ();
  130. if (!event_status) {
  131. return (AE_BAD_PARAMETER);
  132. }
  133. /* Get the info block for the entire GPE register */
  134. gpe_register_info = gpe_event_info->register_info;
  135. /* Get the register bitmask for this GPE */
  136. register_bit = gpe_event_info->register_bit;
  137. /* GPE currently enabled? (enabled for runtime?) */
  138. if (register_bit & gpe_register_info->enable_for_run) {
  139. local_event_status |= ACPI_EVENT_FLAG_ENABLED;
  140. }
  141. /* GPE enabled for wake? */
  142. if (register_bit & gpe_register_info->enable_for_wake) {
  143. local_event_status |= ACPI_EVENT_FLAG_WAKE_ENABLED;
  144. }
  145. /* GPE currently active (status bit == 1)? */
  146. status = acpi_hw_low_level_read (8, &in_byte, &gpe_register_info->status_address);
  147. if (ACPI_FAILURE (status)) {
  148. goto unlock_and_exit;
  149. }
  150. if (register_bit & in_byte) {
  151. local_event_status |= ACPI_EVENT_FLAG_SET;
  152. }
  153. /* Set return value */
  154. (*event_status) = local_event_status;
  155. unlock_and_exit:
  156. return (status);
  157. }
  158. #endif /* ACPI_FUTURE_USAGE */
  159. /******************************************************************************
  160. *
  161. * FUNCTION: acpi_hw_disable_gpe_block
  162. *
  163. * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
  164. * gpe_block - Gpe Block info
  165. *
  166. * RETURN: Status
  167. *
  168. * DESCRIPTION: Disable all GPEs within a single GPE block
  169. *
  170. ******************************************************************************/
  171. acpi_status
  172. acpi_hw_disable_gpe_block (
  173. struct acpi_gpe_xrupt_info *gpe_xrupt_info,
  174. struct acpi_gpe_block_info *gpe_block)
  175. {
  176. u32 i;
  177. acpi_status status;
  178. /* Examine each GPE Register within the block */
  179. for (i = 0; i < gpe_block->register_count; i++) {
  180. /* Disable all GPEs in this register */
  181. status = acpi_hw_low_level_write (8, 0x00,
  182. &gpe_block->register_info[i].enable_address);
  183. if (ACPI_FAILURE (status)) {
  184. return (status);
  185. }
  186. }
  187. return (AE_OK);
  188. }
  189. /******************************************************************************
  190. *
  191. * FUNCTION: acpi_hw_clear_gpe_block
  192. *
  193. * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
  194. * gpe_block - Gpe Block info
  195. *
  196. * RETURN: Status
  197. *
  198. * DESCRIPTION: Clear status bits for all GPEs within a single GPE block
  199. *
  200. ******************************************************************************/
  201. acpi_status
  202. acpi_hw_clear_gpe_block (
  203. struct acpi_gpe_xrupt_info *gpe_xrupt_info,
  204. struct acpi_gpe_block_info *gpe_block)
  205. {
  206. u32 i;
  207. acpi_status status;
  208. /* Examine each GPE Register within the block */
  209. for (i = 0; i < gpe_block->register_count; i++) {
  210. /* Clear status on all GPEs in this register */
  211. status = acpi_hw_low_level_write (8, 0xFF,
  212. &gpe_block->register_info[i].status_address);
  213. if (ACPI_FAILURE (status)) {
  214. return (status);
  215. }
  216. }
  217. return (AE_OK);
  218. }
  219. /******************************************************************************
  220. *
  221. * FUNCTION: acpi_hw_enable_runtime_gpe_block
  222. *
  223. * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
  224. * gpe_block - Gpe Block info
  225. *
  226. * RETURN: Status
  227. *
  228. * DESCRIPTION: Enable all "runtime" GPEs within a single GPE block. Includes
  229. * combination wake/run GPEs.
  230. *
  231. ******************************************************************************/
  232. acpi_status
  233. acpi_hw_enable_runtime_gpe_block (
  234. struct acpi_gpe_xrupt_info *gpe_xrupt_info,
  235. struct acpi_gpe_block_info *gpe_block)
  236. {
  237. u32 i;
  238. acpi_status status;
  239. /* NOTE: assumes that all GPEs are currently disabled */
  240. /* Examine each GPE Register within the block */
  241. for (i = 0; i < gpe_block->register_count; i++) {
  242. if (!gpe_block->register_info[i].enable_for_run) {
  243. continue;
  244. }
  245. /* Enable all "runtime" GPEs in this register */
  246. status = acpi_hw_low_level_write (8, gpe_block->register_info[i].enable_for_run,
  247. &gpe_block->register_info[i].enable_address);
  248. if (ACPI_FAILURE (status)) {
  249. return (status);
  250. }
  251. }
  252. return (AE_OK);
  253. }
  254. /******************************************************************************
  255. *
  256. * FUNCTION: acpi_hw_enable_wakeup_gpe_block
  257. *
  258. * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
  259. * gpe_block - Gpe Block info
  260. *
  261. * RETURN: Status
  262. *
  263. * DESCRIPTION: Enable all "wake" GPEs within a single GPE block. Includes
  264. * combination wake/run GPEs.
  265. *
  266. ******************************************************************************/
  267. static acpi_status
  268. acpi_hw_enable_wakeup_gpe_block (
  269. struct acpi_gpe_xrupt_info *gpe_xrupt_info,
  270. struct acpi_gpe_block_info *gpe_block)
  271. {
  272. u32 i;
  273. acpi_status status;
  274. /* Examine each GPE Register within the block */
  275. for (i = 0; i < gpe_block->register_count; i++) {
  276. if (!gpe_block->register_info[i].enable_for_wake) {
  277. continue;
  278. }
  279. /* Enable all "wake" GPEs in this register */
  280. status = acpi_hw_low_level_write (8,
  281. gpe_block->register_info[i].enable_for_wake,
  282. &gpe_block->register_info[i].enable_address);
  283. if (ACPI_FAILURE (status)) {
  284. return (status);
  285. }
  286. }
  287. return (AE_OK);
  288. }
  289. /******************************************************************************
  290. *
  291. * FUNCTION: acpi_hw_disable_all_gpes
  292. *
  293. * PARAMETERS: Flags - ACPI_NOT_ISR or ACPI_ISR
  294. *
  295. * RETURN: Status
  296. *
  297. * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
  298. *
  299. ******************************************************************************/
  300. acpi_status
  301. acpi_hw_disable_all_gpes (
  302. u32 flags)
  303. {
  304. acpi_status status;
  305. ACPI_FUNCTION_TRACE ("hw_disable_all_gpes");
  306. status = acpi_ev_walk_gpe_list (acpi_hw_disable_gpe_block, flags);
  307. status = acpi_ev_walk_gpe_list (acpi_hw_clear_gpe_block, flags);
  308. return_ACPI_STATUS (status);
  309. }
  310. /******************************************************************************
  311. *
  312. * FUNCTION: acpi_hw_enable_all_runtime_gpes
  313. *
  314. * PARAMETERS: Flags - ACPI_NOT_ISR or ACPI_ISR
  315. *
  316. * RETURN: Status
  317. *
  318. * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
  319. *
  320. ******************************************************************************/
  321. acpi_status
  322. acpi_hw_enable_all_runtime_gpes (
  323. u32 flags)
  324. {
  325. acpi_status status;
  326. ACPI_FUNCTION_TRACE ("hw_enable_all_runtime_gpes");
  327. status = acpi_ev_walk_gpe_list (acpi_hw_enable_runtime_gpe_block, flags);
  328. return_ACPI_STATUS (status);
  329. }
  330. /******************************************************************************
  331. *
  332. * FUNCTION: acpi_hw_enable_all_wakeup_gpes
  333. *
  334. * PARAMETERS: Flags - ACPI_NOT_ISR or ACPI_ISR
  335. *
  336. * RETURN: Status
  337. *
  338. * DESCRIPTION: Enable all "wakeup" GPEs, in all GPE blocks
  339. *
  340. ******************************************************************************/
  341. acpi_status
  342. acpi_hw_enable_all_wakeup_gpes (
  343. u32 flags)
  344. {
  345. acpi_status status;
  346. ACPI_FUNCTION_TRACE ("hw_enable_all_wakeup_gpes");
  347. status = acpi_ev_walk_gpe_list (acpi_hw_enable_wakeup_gpe_block, flags);
  348. return_ACPI_STATUS (status);
  349. }