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.
17 #include <console/console.h>
20 #include <ec/acpi/ec.h>
23 int send_ec_oem_command(u8 command
)
28 while ((inb(EC_OEM_SC
) & EC_IBF
) && --timeout
) {
30 if ((timeout
& 0xff) == 0)
31 printk(BIOS_SPEW
, ".");
34 printk(BIOS_DEBUG
, "Timeout while sending OEM command 0x%02x to EC!\n",
39 outb(command
, EC_OEM_SC
);
43 int send_ec_oem_data(u8 data
)
48 while ((inb(EC_OEM_SC
) & EC_IBF
) && --timeout
) { // wait for IBF = 0
50 if ((timeout
& 0xff) == 0)
51 printk(BIOS_SPEW
, ".");
54 printk(BIOS_DEBUG
, "Timeout while sending OEM data 0x%02x to EC!\n",
59 outb(data
, EC_OEM_DATA
);
64 int send_ec_oem_data_nowait(u8 data
)
66 outb(data
, EC_OEM_DATA
);
71 u8
recv_ec_oem_data(void)
77 while (--timeout
) { // Wait for OBF = 1
78 if (inb(EC_OEM_SC
) & EC_OBF
) {
82 if ((timeout
& 0xff) == 0)
83 printk(BIOS_SPEW
, ".");
86 printk(BIOS_DEBUG
, "\nTimeout while receiving OEM data from EC!\n");
90 data
= inb(EC_OEM_DATA
);
91 // printk(BIOS_SPEW, "recv_ec_oem_data: 0x%02x\n", data);
96 u8
ec_oem_read(u8 addr
)
98 send_ec_oem_command(0x80);
99 send_ec_oem_data(addr
);
101 return recv_ec_oem_data();
104 int ec_oem_write(u8 addr
, u8 data
)
106 send_ec_oem_command(0x81);
107 send_ec_oem_data(addr
);
108 return send_ec_oem_data(data
);
111 int ec_oem_dump_status(void)
113 u8 ec_sc
= inb(EC_OEM_SC
);
114 printk(BIOS_DEBUG
, "Embedded Controller Status: ");
115 if (ec_sc
& (1 << 6)) printk(BIOS_DEBUG
, "SMI_EVT ");
116 if (ec_sc
& (1 << 5)) printk(BIOS_DEBUG
, "SCI_EVT ");
117 if (ec_sc
& (1 << 4)) printk(BIOS_DEBUG
, "BURST ");
118 if (ec_sc
& (1 << 3)) printk(BIOS_DEBUG
, "CMD ");
119 if (ec_sc
& (1 << 1)) printk(BIOS_DEBUG
, "IBF ");
120 if (ec_sc
& (1 << 0)) printk(BIOS_DEBUG
, "OBF ");
121 printk(BIOS_DEBUG
, "\n");