2 * This file is part of the coreboot project.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; version 2 of
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.
16 #include <console/console.h>
19 #include <ec/acpi/ec.h>
22 int send_ec_oem_command(u8 command
)
27 while ((inb(EC_OEM_SC
) & EC_IBF
) && --timeout
) {
29 if ((timeout
& 0xff) == 0)
30 printk(BIOS_SPEW
, ".");
33 printk(BIOS_DEBUG
, "Timeout while sending OEM command 0x%02x to EC!\n",
38 outb(command
, EC_OEM_SC
);
42 int send_ec_oem_data(u8 data
)
47 while ((inb(EC_OEM_SC
) & EC_IBF
) && --timeout
) { // wait for IBF = 0
49 if ((timeout
& 0xff) == 0)
50 printk(BIOS_SPEW
, ".");
53 printk(BIOS_DEBUG
, "Timeout while sending OEM data 0x%02x to EC!\n",
58 outb(data
, EC_OEM_DATA
);
63 int send_ec_oem_data_nowait(u8 data
)
65 outb(data
, EC_OEM_DATA
);
70 u8
recv_ec_oem_data(void)
76 while (--timeout
) { // Wait for OBF = 1
77 if (inb(EC_OEM_SC
) & EC_OBF
) {
81 if ((timeout
& 0xff) == 0)
82 printk(BIOS_SPEW
, ".");
85 printk(BIOS_DEBUG
, "\nTimeout while receiving OEM data from EC!\n");
89 data
= inb(EC_OEM_DATA
);
90 // printk(BIOS_SPEW, "recv_ec_oem_data: 0x%02x\n", data);
95 u8
ec_oem_read(u8 addr
)
97 send_ec_oem_command(0x80);
98 send_ec_oem_data(addr
);
100 return recv_ec_oem_data();
103 int ec_oem_write(u8 addr
, u8 data
)
105 send_ec_oem_command(0x81);
106 send_ec_oem_data(addr
);
107 return send_ec_oem_data(data
);
110 int ec_oem_dump_status(void)
112 u8 ec_sc
= inb(EC_OEM_SC
);
113 printk(BIOS_DEBUG
, "Embedded Controller Status: ");
114 if (ec_sc
& (1 << 6)) printk(BIOS_DEBUG
, "SMI_EVT ");
115 if (ec_sc
& (1 << 5)) printk(BIOS_DEBUG
, "SCI_EVT ");
116 if (ec_sc
& (1 << 4)) printk(BIOS_DEBUG
, "BURST ");
117 if (ec_sc
& (1 << 3)) printk(BIOS_DEBUG
, "CMD ");
118 if (ec_sc
& (1 << 1)) printk(BIOS_DEBUG
, "IBF ");
119 if (ec_sc
& (1 << 0)) printk(BIOS_DEBUG
, "OBF ");
120 printk(BIOS_DEBUG
, "\n");