hwgpe.c 13 KB

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