2 * This file is part of the coreboot 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
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
21 #include <console/console.h>
22 #include <device/device.h>
29 static const int ec_cmd_reg
= EC_SC
;
30 static const int ec_data_reg
= EC_DATA
;
34 static int ec_cmd_reg
= EC_SC
;
35 static int ec_data_reg
= EC_DATA
;
39 int send_ec_command(u8 command
)
44 while ((inb(ec_cmd_reg
) & EC_IBF
) && --timeout
) {
46 if ((timeout
& 0xff) == 0)
47 printk(BIOS_SPEW
, ".");
50 printk(BIOS_DEBUG
, "Timeout while sending command 0x%02x to EC!\n",
57 outb(command
, ec_cmd_reg
);
61 int send_ec_data(u8 data
)
66 while ((inb(ec_cmd_reg
) & EC_IBF
) && --timeout
) { // wait for IBF = 0
68 if ((timeout
& 0xff) == 0)
69 printk(BIOS_SPEW
, ".");
72 printk(BIOS_DEBUG
, "Timeout while sending data 0x%02x to EC!\n",
79 outb(data
, ec_data_reg
);
84 int send_ec_data_nowait(u8 data
)
86 outb(data
, ec_data_reg
);
97 while (--timeout
) { // Wait for OBF = 1
98 if (inb(ec_cmd_reg
) & EC_OBF
) {
102 if ((timeout
& 0xff) == 0)
103 printk(BIOS_SPEW
, ".");
106 printk(BIOS_DEBUG
, "\nTimeout while receiving data from EC!\n");
112 data
= inb(ec_data_reg
);
113 printk(BIOS_SPEW
, "recv_ec_data: 0x%02x\n", data
);
120 send_ec_command(0x80);
123 return recv_ec_data();
126 int ec_write(u8 addr
, u8 data
)
128 send_ec_command(0x81);
130 return send_ec_data(data
);
135 send_ec_command(0x84);
136 return recv_ec_data();
139 void ec_set_bit(u8 addr
, u8 bit
)
141 ec_write(addr
, ec_read(addr
) | (1 << bit
));
144 void ec_clr_bit(u8 addr
, u8 bit
)
146 ec_write(addr
, ec_read(addr
) & ~(1 << bit
));
151 void ec_set_ports(u16 cmd_reg
, u16 data_reg
)
153 ec_cmd_reg
= cmd_reg
;
154 ec_data_reg
= data_reg
;
159 #if !defined(__SMM__) && !defined(__PRE_RAM__)
160 struct chip_operations ec_acpi_ops
= {
161 CHIP_NAME("ACPI Embedded Controller")