1 /*****************************************************************************
3 * Module Name: ecspace.c
6 *****************************************************************************/
9 * Copyright (C) 2000, 2001 Andrew Grover
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #define _COMPONENT ACPI_EC
31 MODULE_NAME ("ecspace")
34 /****************************************************************************
36 * FUNCTION: ec_space_setup
44 ****************************************************************************/
48 acpi_handle region_handle,
50 void *handler_context,
51 void **return_context)
54 * The EC object is in the handler context and is needed
55 * when calling the ec_space_handler.
57 *return_context = handler_context;
63 /****************************************************************************
65 * FUNCTION: ec_space_handler
67 * PARAMETERS: function - Read or Write operation
68 * address - Where in the space to read or write
69 * bit_width - Field width in bits (should be 8)
70 * value - Pointer to in or out value
71 * context - context pointer
75 * DESCRIPTION: Handler for the Embedded Controller (EC) address space
78 ****************************************************************************/
83 ACPI_PHYSICAL_ADDRESS address,
86 void *handler_context,
89 acpi_status status = AE_OK;
90 EC_CONTEXT *ec = NULL;
91 EC_REQUEST ec_request;
93 FUNCTION_TRACE("ec_space_handler");
95 if (address > 0xFF || bit_width != 8 || !value || !handler_context) {
96 return_ACPI_STATUS(AE_BAD_PARAMETER);
99 ec = (EC_CONTEXT*)handler_context;
103 case ACPI_READ_ADR_SPACE:
104 ec_request.command = EC_COMMAND_READ;
105 ec_request.address = address;
109 case ACPI_WRITE_ADR_SPACE:
110 ec_request.command = EC_COMMAND_WRITE;
111 ec_request.address = address;
112 ec_request.data = (u8)(*value);
116 ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "Received request with invalid function [%X].\n", function));
117 return_ACPI_STATUS(AE_BAD_PARAMETER);
122 * Perform the Transaction.
124 status = ec_transaction(ec, &ec_request);
125 if (ACPI_SUCCESS(status)) {
126 (*value) = (u32)ec_request.data;
129 return_ACPI_STATUS(status);
133 /****************************************************************************
135 * FUNCTION: ec_install_space_handler
143 ****************************************************************************/
146 ec_install_space_handler (
149 acpi_status status = AE_OK;
151 FUNCTION_TRACE("ec_install_space_handler");
154 return_ACPI_STATUS(AE_BAD_PARAMETER);
157 status = acpi_install_address_space_handler (ec->acpi_handle,
158 ACPI_ADR_SPACE_EC, &ec_space_handler, &ec_space_setup, ec);
160 return_ACPI_STATUS(status);
164 /****************************************************************************
166 * FUNCTION: ec_remove_space_handler
174 ****************************************************************************/
177 ec_remove_space_handler (
180 acpi_status status = AE_OK;
182 FUNCTION_TRACE("ec_remove_space_handler");
185 return_ACPI_STATUS(AE_BAD_PARAMETER);
188 status = acpi_remove_address_space_handler(ec->acpi_handle,
189 ACPI_ADR_SPACE_EC, &ec_space_handler);
191 return_ACPI_STATUS(status);