hwgpe.c 13 KB

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