2 * This file is part of the ectool project.
4 * Copyright (C) 2008-2009 coresystems GmbH
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 #define debug(x...) if (verbose) printf(x)
30 int send_ec_command(uint8_t command)
35 while ((inb(EC_SC) & EC_IBF) && --timeout) {
37 if ((timeout & 0xff) == 0)
41 printf("Timeout while sending command 0x%02x to EC!\n",
50 int send_ec_data(uint8_t data)
55 while ((inb(EC_SC) & EC_IBF) && --timeout) { // wait for IBF = 0
57 if ((timeout & 0xff) == 0)
61 printf("Timeout while sending data 0x%02x to EC!\n", data);
70 int send_ec_data_nowait(uint8_t data)
77 uint8_t recv_ec_data(void)
83 while (--timeout) { // Wait for OBF = 1
84 if (inb(EC_SC) & EC_OBF) {
88 if ((timeout & 0xff) == 0)
92 printf("\nTimeout while receiving data from EC!\n");
97 debug("recv_ec_data: 0x%02x\n", data);
102 uint8_t ec_read(uint8_t addr)
104 send_ec_command(0x80);
107 return recv_ec_data();
110 int ec_write(uint8_t addr, uint8_t data)
112 send_ec_command(0x81);
115 return send_ec_data(data);