/******************************************************************************1*2* Module Name: evxfevnt - External Interfaces, ACPI event disable/enable3*4*****************************************************************************/56/*7* Copyright (C) 2000 - 2011, Intel Corp.8* All rights reserved.9*10* Redistribution and use in source and binary forms, with or without11* modification, are permitted provided that the following conditions12* are met:13* 1. Redistributions of source code must retain the above copyright14* notice, this list of conditions, and the following disclaimer,15* without modification.16* 2. Redistributions in binary form must reproduce at minimum a disclaimer17* substantially similar to the "NO WARRANTY" disclaimer below18* ("Disclaimer") and any redistribution must be conditioned upon19* including a substantially similar Disclaimer requirement for further20* binary redistribution.21* 3. Neither the names of the above-listed copyright holders nor the names22* of any contributors may be used to endorse or promote products derived23* from this software without specific prior written permission.24*25* Alternatively, this software may be distributed under the terms of the26* GNU General Public License ("GPL") version 2 as published by the Free27* Software Foundation.28*29* NO WARRANTY30* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS31* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT32* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR33* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT34* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL35* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS36* 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) ARISING39* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE40* POSSIBILITY OF SUCH DAMAGES.41*/4243#include <acpi/acpi.h>44#include "accommon.h"45#include "actables.h"4647#define _COMPONENT ACPI_EVENTS48ACPI_MODULE_NAME("evxfevnt")4950/*******************************************************************************51*52* FUNCTION: acpi_enable53*54* PARAMETERS: None55*56* RETURN: Status57*58* DESCRIPTION: Transfers the system into ACPI mode.59*60******************************************************************************/6162acpi_status acpi_enable(void)63{64acpi_status status;65int retry;6667ACPI_FUNCTION_TRACE(acpi_enable);6869/* ACPI tables must be present */7071if (!acpi_tb_tables_loaded()) {72return_ACPI_STATUS(AE_NO_ACPI_TABLES);73}7475/* Check current mode */7677if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {78ACPI_DEBUG_PRINT((ACPI_DB_INIT,79"System is already in ACPI mode\n"));80return_ACPI_STATUS(AE_OK);81}8283/* Transition to ACPI mode */8485status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI);86if (ACPI_FAILURE(status)) {87ACPI_ERROR((AE_INFO,88"Could not transition to ACPI mode"));89return_ACPI_STATUS(status);90}9192/* Sanity check that transition succeeded */9394for (retry = 0; retry < 30000; ++retry) {95if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {96if (retry != 0)97ACPI_WARNING((AE_INFO,98"Platform took > %d00 usec to enter ACPI mode", retry));99return_ACPI_STATUS(AE_OK);100}101acpi_os_stall(100); /* 100 usec */102}103104ACPI_ERROR((AE_INFO, "Hardware did not enter ACPI mode"));105return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);106}107108ACPI_EXPORT_SYMBOL(acpi_enable)109110/*******************************************************************************111*112* FUNCTION: acpi_disable113*114* PARAMETERS: None115*116* RETURN: Status117*118* DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.119*120******************************************************************************/121acpi_status acpi_disable(void)122{123acpi_status status = AE_OK;124125ACPI_FUNCTION_TRACE(acpi_disable);126127if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {128ACPI_DEBUG_PRINT((ACPI_DB_INIT,129"System is already in legacy (non-ACPI) mode\n"));130} else {131/* Transition to LEGACY mode */132133status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);134135if (ACPI_FAILURE(status)) {136ACPI_ERROR((AE_INFO,137"Could not exit ACPI mode to legacy mode"));138return_ACPI_STATUS(status);139}140141ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));142}143144return_ACPI_STATUS(status);145}146147ACPI_EXPORT_SYMBOL(acpi_disable)148149/*******************************************************************************150*151* FUNCTION: acpi_enable_event152*153* PARAMETERS: Event - The fixed eventto be enabled154* Flags - Reserved155*156* RETURN: Status157*158* DESCRIPTION: Enable an ACPI event (fixed)159*160******************************************************************************/161acpi_status acpi_enable_event(u32 event, u32 flags)162{163acpi_status status = AE_OK;164u32 value;165166ACPI_FUNCTION_TRACE(acpi_enable_event);167168/* Decode the Fixed Event */169170if (event > ACPI_EVENT_MAX) {171return_ACPI_STATUS(AE_BAD_PARAMETER);172}173174/*175* Enable the requested fixed event (by writing a one to the enable176* register bit)177*/178status =179acpi_write_bit_register(acpi_gbl_fixed_event_info[event].180enable_register_id, ACPI_ENABLE_EVENT);181if (ACPI_FAILURE(status)) {182return_ACPI_STATUS(status);183}184185/* Make sure that the hardware responded */186187status =188acpi_read_bit_register(acpi_gbl_fixed_event_info[event].189enable_register_id, &value);190if (ACPI_FAILURE(status)) {191return_ACPI_STATUS(status);192}193194if (value != 1) {195ACPI_ERROR((AE_INFO,196"Could not enable %s event",197acpi_ut_get_event_name(event)));198return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);199}200201return_ACPI_STATUS(status);202}203204ACPI_EXPORT_SYMBOL(acpi_enable_event)205206/*******************************************************************************207*208* FUNCTION: acpi_disable_event209*210* PARAMETERS: Event - The fixed eventto be enabled211* Flags - Reserved212*213* RETURN: Status214*215* DESCRIPTION: Disable an ACPI event (fixed)216*217******************************************************************************/218acpi_status acpi_disable_event(u32 event, u32 flags)219{220acpi_status status = AE_OK;221u32 value;222223ACPI_FUNCTION_TRACE(acpi_disable_event);224225/* Decode the Fixed Event */226227if (event > ACPI_EVENT_MAX) {228return_ACPI_STATUS(AE_BAD_PARAMETER);229}230231/*232* Disable the requested fixed event (by writing a zero to the enable233* register bit)234*/235status =236acpi_write_bit_register(acpi_gbl_fixed_event_info[event].237enable_register_id, ACPI_DISABLE_EVENT);238if (ACPI_FAILURE(status)) {239return_ACPI_STATUS(status);240}241242status =243acpi_read_bit_register(acpi_gbl_fixed_event_info[event].244enable_register_id, &value);245if (ACPI_FAILURE(status)) {246return_ACPI_STATUS(status);247}248249if (value != 0) {250ACPI_ERROR((AE_INFO,251"Could not disable %s events",252acpi_ut_get_event_name(event)));253return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);254}255256return_ACPI_STATUS(status);257}258259ACPI_EXPORT_SYMBOL(acpi_disable_event)260261/*******************************************************************************262*263* FUNCTION: acpi_clear_event264*265* PARAMETERS: Event - The fixed event to be cleared266*267* RETURN: Status268*269* DESCRIPTION: Clear an ACPI event (fixed)270*271******************************************************************************/272acpi_status acpi_clear_event(u32 event)273{274acpi_status status = AE_OK;275276ACPI_FUNCTION_TRACE(acpi_clear_event);277278/* Decode the Fixed Event */279280if (event > ACPI_EVENT_MAX) {281return_ACPI_STATUS(AE_BAD_PARAMETER);282}283284/*285* Clear the requested fixed event (By writing a one to the status286* register bit)287*/288status =289acpi_write_bit_register(acpi_gbl_fixed_event_info[event].290status_register_id, ACPI_CLEAR_STATUS);291292return_ACPI_STATUS(status);293}294295ACPI_EXPORT_SYMBOL(acpi_clear_event)296297/*******************************************************************************298*299* FUNCTION: acpi_get_event_status300*301* PARAMETERS: Event - The fixed event302* event_status - Where the current status of the event will303* be returned304*305* RETURN: Status306*307* DESCRIPTION: Obtains and returns the current status of the event308*309******************************************************************************/310acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)311{312acpi_status status = AE_OK;313u32 value;314315ACPI_FUNCTION_TRACE(acpi_get_event_status);316317if (!event_status) {318return_ACPI_STATUS(AE_BAD_PARAMETER);319}320321/* Decode the Fixed Event */322323if (event > ACPI_EVENT_MAX) {324return_ACPI_STATUS(AE_BAD_PARAMETER);325}326327/* Get the status of the requested fixed event */328329status =330acpi_read_bit_register(acpi_gbl_fixed_event_info[event].331enable_register_id, &value);332if (ACPI_FAILURE(status))333return_ACPI_STATUS(status);334335*event_status = value;336337status =338acpi_read_bit_register(acpi_gbl_fixed_event_info[event].339status_register_id, &value);340if (ACPI_FAILURE(status))341return_ACPI_STATUS(status);342343if (value)344*event_status |= ACPI_EVENT_FLAG_SET;345346if (acpi_gbl_fixed_event_handlers[event].handler)347*event_status |= ACPI_EVENT_FLAG_HANDLE;348349return_ACPI_STATUS(status);350}351352ACPI_EXPORT_SYMBOL(acpi_get_event_status)353354355