evxfevnt.c 9.5 KB

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