hwgpe.c 12 KB

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