hwgpe.c 14 KB

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