hwgpe.c 11 KB

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