Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 | /***************************************************************************** * * Module Name: ectransx.c * $Revision: 24 $ * *****************************************************************************/ /* * Copyright (C) 2000, 2001 Andrew Grover * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <acpi.h> #include "ec.h" #define _COMPONENT ACPI_EC MODULE_NAME ("ectransx") /**************************************************************************** * * FUNCTION: ec_io_wait * * PARAMETERS: * * RETURN: * * DESCRIPTION: * ****************************************************************************/ acpi_status ec_io_wait ( EC_CONTEXT *ec, EC_EVENT wait_event) { EC_STATUS ec_status = 0; u32 i = 100; if (!ec || ((wait_event != EC_EVENT_OUTPUT_BUFFER_FULL) && (wait_event != EC_EVENT_INPUT_BUFFER_EMPTY))) { return(AE_BAD_PARAMETER); } /* * Wait for Event: * --------------- * Poll the EC status register waiting for the event to occur. * Note that we'll wait a maximum of 1ms in 10us chunks. */ switch (wait_event) { case EC_EVENT_OUTPUT_BUFFER_FULL: do { acpi_os_read_port(ec->status_port, &ec_status, 8); if (ec_status & EC_FLAG_OUTPUT_BUFFER) { return(AE_OK); } acpi_os_stall(10); } while (--i>0); break; case EC_EVENT_INPUT_BUFFER_EMPTY: do { acpi_os_read_port(ec->status_port, &ec_status, 8); if (!(ec_status & EC_FLAG_INPUT_BUFFER)) { return(AE_OK); } acpi_os_stall(10); } while (--i>0); break; } return(AE_TIME); } /**************************************************************************** * * FUNCTION: ec_io_read * * PARAMETERS: * * RETURN: * * DESCRIPTION: * ****************************************************************************/ acpi_status ec_io_read ( EC_CONTEXT *ec, ACPI_IO_ADDRESS io_port, u8 *data, EC_EVENT wait_event) { acpi_status status = AE_OK; if (!ec || !data) { return(AE_BAD_PARAMETER); } acpi_os_read_port(io_port, (u32*) data, 8); if (wait_event) { status = ec_io_wait(ec, wait_event); } return(status); } /**************************************************************************** * * FUNCTION: ec_io_write * * PARAMETERS: * * RETURN: * * DESCRIPTION: * ****************************************************************************/ acpi_status ec_io_write ( EC_CONTEXT *ec, ACPI_IO_ADDRESS io_port, u8 data, EC_EVENT wait_event) { acpi_status status = AE_OK; if (!ec) { return(AE_BAD_PARAMETER); } acpi_os_write_port(io_port, data, 8); if (wait_event) { status = ec_io_wait(ec, wait_event); } return(status); } /**************************************************************************** * * FUNCTION: ec_read * * PARAMETERS: * * RETURN: * * DESCRIPTION: * ****************************************************************************/ acpi_status ec_read ( EC_CONTEXT *ec, u8 address, u8 *data) { acpi_status status = AE_OK; FUNCTION_TRACE("ec_read"); if (!ec || !data) { return_ACPI_STATUS(AE_BAD_PARAMETER); } if (ec->use_global_lock) { status = acpi_acquire_global_lock(); if (ACPI_FAILURE(status)) { ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "Could not acquire Global Lock\n")); return_ACPI_STATUS(status); } } status = ec_io_write(ec, ec->command_port, EC_COMMAND_READ, EC_EVENT_INPUT_BUFFER_EMPTY); if (ACPI_FAILURE(status)) { ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "Unable to send 'read command' to EC.\n")); return_ACPI_STATUS(status); } status = ec_io_write(ec, ec->data_port, address, EC_EVENT_OUTPUT_BUFFER_FULL); if (ACPI_FAILURE(status)) { ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "Unable to send 'read address' to EC.\n")); return_ACPI_STATUS(status); } status = ec_io_read(ec, ec->data_port, data, EC_EVENT_NONE); if (ec->use_global_lock) { acpi_release_global_lock(); } ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Read data [%02x] from address [%02x] on ec [%02x].\n", (*data), address, ec->device_handle)); return_ACPI_STATUS(status); } /**************************************************************************** * * FUNCTION: ec_write * * PARAMETERS: * * RETURN: * * DESCRIPTION: * ****************************************************************************/ acpi_status ec_write ( EC_CONTEXT *ec, u8 address, u8 data) { acpi_status status = AE_OK; FUNCTION_TRACE("ec_write"); if (!ec) return_ACPI_STATUS(AE_BAD_PARAMETER); if (ec->use_global_lock) { status = acpi_acquire_global_lock(); if (ACPI_FAILURE(status)) { ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "Could not acquire Global Lock\n")); return_ACPI_STATUS(status); } } status = ec_io_write(ec, ec->command_port, EC_COMMAND_WRITE, EC_EVENT_INPUT_BUFFER_EMPTY); if (ACPI_FAILURE(status)) { ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "Unable to send 'write command' to EC.\n")); return_ACPI_STATUS(status); } status = ec_io_write(ec, ec->data_port, address, EC_EVENT_INPUT_BUFFER_EMPTY); if (ACPI_FAILURE(status)) { ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "Unable to send 'write address' to EC.\n")); return_ACPI_STATUS(status); } status = ec_io_write(ec, ec->data_port, data, EC_EVENT_INPUT_BUFFER_EMPTY); if (ACPI_FAILURE(status)) { ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "Unable to send 'write data' to EC.\n")); return_ACPI_STATUS(status); } if (ec->use_global_lock) { acpi_release_global_lock(); } ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Wrote data [%02x] to address [%02x] on ec [%02x].\n", data, address, ec->device_handle)); return_ACPI_STATUS(status); } /**************************************************************************** * * FUNCTION: ec_transaction * * PARAMETERS: * * RETURN: * * DESCRIPTION: * ****************************************************************************/ acpi_status ec_transaction ( EC_CONTEXT *ec, EC_REQUEST *request) { acpi_status status = AE_OK; FUNCTION_TRACE("ec_transaction"); if (!ec || !request) { return_ACPI_STATUS(AE_BAD_PARAMETER); } /* * Obtain mutex to serialize all EC transactions. */ status = acpi_os_wait_semaphore(ec->mutex, 1, EC_DEFAULT_TIMEOUT); if (ACPI_FAILURE(status)) { return_ACPI_STATUS(status); } /* * Perform the transaction. */ switch (request->command) { case EC_COMMAND_READ: status = ec_read(ec, request->address, &(request->data)); break; case EC_COMMAND_WRITE: status = ec_write(ec, request->address, request->data); break; default: status = AE_SUPPORT; break; } /* * Signal the mutex to indicate transaction completion. */ acpi_os_signal_semaphore(ec->mutex, 1); return_ACPI_STATUS(status); } |