evxfevnt.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. /******************************************************************************
  2. *
  3. * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2011, 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 <linux/export.h>
  43. #include <acpi/acpi.h>
  44. #include "accommon.h"
  45. #include "actables.h"
  46. #define _COMPONENT ACPI_EVENTS
  47. ACPI_MODULE_NAME("evxfevnt")
  48. /*******************************************************************************
  49. *
  50. * FUNCTION: acpi_enable
  51. *
  52. * PARAMETERS: None
  53. *
  54. * RETURN: Status
  55. *
  56. * DESCRIPTION: Transfers the system into ACPI mode.
  57. *
  58. ******************************************************************************/
  59. acpi_status acpi_enable(void)
  60. {
  61. acpi_status status;
  62. int retry;
  63. ACPI_FUNCTION_TRACE(acpi_enable);
  64. /* ACPI tables must be present */
  65. if (!acpi_tb_tables_loaded()) {
  66. return_ACPI_STATUS(AE_NO_ACPI_TABLES);
  67. }
  68. /* Check current mode */
  69. if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
  70. ACPI_DEBUG_PRINT((ACPI_DB_INIT,
  71. "System is already in ACPI mode\n"));
  72. return_ACPI_STATUS(AE_OK);
  73. }
  74. /* Transition to ACPI mode */
  75. status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI);
  76. if (ACPI_FAILURE(status)) {
  77. ACPI_ERROR((AE_INFO,
  78. "Could not transition to ACPI mode"));
  79. return_ACPI_STATUS(status);
  80. }
  81. /* Sanity check that transition succeeded */
  82. for (retry = 0; retry < 30000; ++retry) {
  83. if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
  84. if (retry != 0)
  85. ACPI_WARNING((AE_INFO,
  86. "Platform took > %d00 usec to enter ACPI mode", retry));
  87. return_ACPI_STATUS(AE_OK);
  88. }
  89. acpi_os_stall(100); /* 100 usec */
  90. }
  91. ACPI_ERROR((AE_INFO, "Hardware did not enter ACPI mode"));
  92. return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
  93. }
  94. ACPI_EXPORT_SYMBOL(acpi_enable)
  95. /*******************************************************************************
  96. *
  97. * FUNCTION: acpi_disable
  98. *
  99. * PARAMETERS: None
  100. *
  101. * RETURN: Status
  102. *
  103. * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
  104. *
  105. ******************************************************************************/
  106. acpi_status acpi_disable(void)
  107. {
  108. acpi_status status = AE_OK;
  109. ACPI_FUNCTION_TRACE(acpi_disable);
  110. if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
  111. ACPI_DEBUG_PRINT((ACPI_DB_INIT,
  112. "System is already in legacy (non-ACPI) mode\n"));
  113. } else {
  114. /* Transition to LEGACY mode */
  115. status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
  116. if (ACPI_FAILURE(status)) {
  117. ACPI_ERROR((AE_INFO,
  118. "Could not exit ACPI mode to legacy mode"));
  119. return_ACPI_STATUS(status);
  120. }
  121. ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
  122. }
  123. return_ACPI_STATUS(status);
  124. }
  125. ACPI_EXPORT_SYMBOL(acpi_disable)
  126. /*******************************************************************************
  127. *
  128. * FUNCTION: acpi_enable_event
  129. *
  130. * PARAMETERS: Event - The fixed eventto be enabled
  131. * Flags - Reserved
  132. *
  133. * RETURN: Status
  134. *
  135. * DESCRIPTION: Enable an ACPI event (fixed)
  136. *
  137. ******************************************************************************/
  138. acpi_status acpi_enable_event(u32 event, u32 flags)
  139. {
  140. acpi_status status = AE_OK;
  141. u32 value;
  142. ACPI_FUNCTION_TRACE(acpi_enable_event);
  143. /* Decode the Fixed Event */
  144. if (event > ACPI_EVENT_MAX) {
  145. return_ACPI_STATUS(AE_BAD_PARAMETER);
  146. }
  147. /*
  148. * Enable the requested fixed event (by writing a one to the enable
  149. * register bit)
  150. */
  151. status =
  152. acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
  153. enable_register_id, ACPI_ENABLE_EVENT);
  154. if (ACPI_FAILURE(status)) {
  155. return_ACPI_STATUS(status);
  156. }
  157. /* Make sure that the hardware responded */
  158. status =
  159. acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
  160. enable_register_id, &value);
  161. if (ACPI_FAILURE(status)) {
  162. return_ACPI_STATUS(status);
  163. }
  164. if (value != 1) {
  165. ACPI_ERROR((AE_INFO,
  166. "Could not enable %s event",
  167. acpi_ut_get_event_name(event)));
  168. return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
  169. }
  170. return_ACPI_STATUS(status);
  171. }
  172. ACPI_EXPORT_SYMBOL(acpi_enable_event)
  173. /*******************************************************************************
  174. *
  175. * FUNCTION: acpi_disable_event
  176. *
  177. * PARAMETERS: Event - The fixed eventto be enabled
  178. * Flags - Reserved
  179. *
  180. * RETURN: Status
  181. *
  182. * DESCRIPTION: Disable an ACPI event (fixed)
  183. *
  184. ******************************************************************************/
  185. acpi_status acpi_disable_event(u32 event, u32 flags)
  186. {
  187. acpi_status status = AE_OK;
  188. u32 value;
  189. ACPI_FUNCTION_TRACE(acpi_disable_event);
  190. /* Decode the Fixed Event */
  191. if (event > ACPI_EVENT_MAX) {
  192. return_ACPI_STATUS(AE_BAD_PARAMETER);
  193. }
  194. /*
  195. * Disable the requested fixed event (by writing a zero to the enable
  196. * register bit)
  197. */
  198. status =
  199. acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
  200. enable_register_id, ACPI_DISABLE_EVENT);
  201. if (ACPI_FAILURE(status)) {
  202. return_ACPI_STATUS(status);
  203. }
  204. status =
  205. acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
  206. enable_register_id, &value);
  207. if (ACPI_FAILURE(status)) {
  208. return_ACPI_STATUS(status);
  209. }
  210. if (value != 0) {
  211. ACPI_ERROR((AE_INFO,
  212. "Could not disable %s events",
  213. acpi_ut_get_event_name(event)));
  214. return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
  215. }
  216. return_ACPI_STATUS(status);
  217. }
  218. ACPI_EXPORT_SYMBOL(acpi_disable_event)
  219. /*******************************************************************************
  220. *
  221. * FUNCTION: acpi_clear_event
  222. *
  223. * PARAMETERS: Event - The fixed event to be cleared
  224. *
  225. * RETURN: Status
  226. *
  227. * DESCRIPTION: Clear an ACPI event (fixed)
  228. *
  229. ******************************************************************************/
  230. acpi_status acpi_clear_event(u32 event)
  231. {
  232. acpi_status status = AE_OK;
  233. ACPI_FUNCTION_TRACE(acpi_clear_event);
  234. /* Decode the Fixed Event */
  235. if (event > ACPI_EVENT_MAX) {
  236. return_ACPI_STATUS(AE_BAD_PARAMETER);
  237. }
  238. /*
  239. * Clear the requested fixed event (By writing a one to the status
  240. * register bit)
  241. */
  242. status =
  243. acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
  244. status_register_id, ACPI_CLEAR_STATUS);
  245. return_ACPI_STATUS(status);
  246. }
  247. ACPI_EXPORT_SYMBOL(acpi_clear_event)
  248. /*******************************************************************************
  249. *
  250. * FUNCTION: acpi_get_event_status
  251. *
  252. * PARAMETERS: Event - The fixed event
  253. * event_status - Where the current status of the event will
  254. * be returned
  255. *
  256. * RETURN: Status
  257. *
  258. * DESCRIPTION: Obtains and returns the current status of the event
  259. *
  260. ******************************************************************************/
  261. acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
  262. {
  263. acpi_status status = AE_OK;
  264. u32 value;
  265. ACPI_FUNCTION_TRACE(acpi_get_event_status);
  266. if (!event_status) {
  267. return_ACPI_STATUS(AE_BAD_PARAMETER);
  268. }
  269. /* Decode the Fixed Event */
  270. if (event > ACPI_EVENT_MAX) {
  271. return_ACPI_STATUS(AE_BAD_PARAMETER);
  272. }
  273. /* Get the status of the requested fixed event */
  274. status =
  275. acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
  276. enable_register_id, &value);
  277. if (ACPI_FAILURE(status))
  278. return_ACPI_STATUS(status);
  279. *event_status = value;
  280. status =
  281. acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
  282. status_register_id, &value);
  283. if (ACPI_FAILURE(status))
  284. return_ACPI_STATUS(status);
  285. if (value)
  286. *event_status |= ACPI_EVENT_FLAG_SET;
  287. if (acpi_gbl_fixed_event_handlers[event].handler)
  288. *event_status |= ACPI_EVENT_FLAG_HANDLE;
  289. return_ACPI_STATUS(status);
  290. }
  291. ACPI_EXPORT_SYMBOL(acpi_get_event_status)