hwgpe.c 13 KB

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