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 debug("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 debug("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 debug("\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(RD_EC);
107 return recv_ec_data();
110 uint8_t ec_ext_read(uint16_t addr)
112 send_ec_command(WR_EC);
114 send_ec_data(addr & 0xff);
115 send_ec_command(RX_EC);
116 send_ec_data(addr >> 8);
118 return recv_ec_data();
121 int ec_ext_write(uint16_t addr, uint8_t data)
123 send_ec_command(WR_EC);
125 send_ec_data(addr & 0xff);
126 send_ec_command(WX_EC);
127 send_ec_data(addr >> 8);
129 return send_ec_data(data);
132 int ec_write(uint8_t addr, uint8_t data)
134 send_ec_command(WR_EC);
137 return send_ec_data(data);
140 uint8_t ec_idx_read(uint16_t addr)
142 uint16_t lpc_idx = 0x380;
144 outb(addr & 0xff, lpc_idx + 2);
145 outb(addr >> 8, lpc_idx + 1);
147 return inb(lpc_idx + 3);