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
29 #define debug(x...) if (verbose) printf(x)
31 int send_ec_command(uint8_t command
)
36 while ((inb(EC_SC
) & EC_IBF
) && --timeout
) {
38 if ((timeout
& 0xff) == 0)
42 debug("Timeout while sending command 0x%02x to EC!\n",
51 int send_ec_data(uint8_t data
)
56 while ((inb(EC_SC
) & EC_IBF
) && --timeout
) { // wait for IBF = 0
58 if ((timeout
& 0xff) == 0)
62 debug("Timeout while sending data 0x%02x to EC!\n", data
);
71 int send_ec_data_nowait(uint8_t data
)
78 uint8_t recv_ec_data(void)
84 while (--timeout
) { // Wait for OBF = 1
85 if (inb(EC_SC
) & EC_OBF
) {
89 if ((timeout
& 0xff) == 0)
93 debug("\nTimeout while receiving data from EC!\n");
98 debug("recv_ec_data: 0x%02x\n", data
);
103 uint8_t ec_read(uint8_t addr
)
105 send_ec_command(RD_EC
);
108 return recv_ec_data();
111 uint8_t ec_ext_read(uint16_t addr
)
113 send_ec_command(WR_EC
);
115 send_ec_data(addr
& 0xff);
116 send_ec_command(RX_EC
);
117 send_ec_data(addr
>> 8);
119 return recv_ec_data();
122 int ec_ext_write(uint16_t addr
, uint8_t data
)
124 send_ec_command(WR_EC
);
126 send_ec_data(addr
& 0xff);
127 send_ec_command(WX_EC
);
128 send_ec_data(addr
>> 8);
130 return send_ec_data(data
);
133 int ec_write(uint8_t addr
, uint8_t data
)
135 send_ec_command(WR_EC
);
138 return send_ec_data(data
);
141 uint8_t ec_idx_read(uint16_t addr
)
143 uint16_t lpc_idx
= 0x380;
145 outb(addr
& 0xff, lpc_idx
+ 2);
146 outb(addr
>> 8, lpc_idx
+ 1);
148 return inb(lpc_idx
+ 3);
151 uint8_t ec_query(void)
153 send_ec_command(QR_EC
);
154 return recv_ec_data();