1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <console/console.h>
6 #include <ec/acpi/ec.h>
11 enum cb_err
send_ec_oem_command(u8 command
)
16 while ((inb(EC_OEM_SC
) & EC_IBF
) && --timeout
) {
18 if ((timeout
& 0xff) == 0)
19 printk(BIOS_SPEW
, ".");
22 printk(BIOS_DEBUG
, "Timeout while sending OEM command 0x%02x to EC!\n",
27 outb(command
, EC_OEM_SC
);
31 enum cb_err
send_ec_oem_data(u8 data
)
36 while ((inb(EC_OEM_SC
) & EC_IBF
) && --timeout
) { // wait for IBF = 0
38 if ((timeout
& 0xff) == 0)
39 printk(BIOS_SPEW
, ".");
42 printk(BIOS_DEBUG
, "Timeout while sending OEM data 0x%02x to EC!\n",
47 outb(data
, EC_OEM_DATA
);
52 u8
recv_ec_oem_data(void)
58 while (--timeout
) { // Wait for OBF = 1
59 if (inb(EC_OEM_SC
) & EC_OBF
) {
63 if ((timeout
& 0xff) == 0)
64 printk(BIOS_SPEW
, ".");
67 printk(BIOS_DEBUG
, "\nTimeout while receiving OEM data from EC!\n");
71 data
= inb(EC_OEM_DATA
);
72 // printk(BIOS_SPEW, "recv_ec_oem_data: 0x%02x\n", data);
77 u8
ec_oem_read(u8 addr
)
79 send_ec_oem_command(0x80);
80 send_ec_oem_data(addr
);
82 return recv_ec_oem_data();
85 int ec_oem_dump_status(void)
87 u8 ec_sc
= inb(EC_OEM_SC
);
88 printk(BIOS_DEBUG
, "Embedded Controller Status: ");
89 if (ec_sc
& (1 << 6)) printk(BIOS_DEBUG
, "SMI_EVT ");
90 if (ec_sc
& (1 << 5)) printk(BIOS_DEBUG
, "SCI_EVT ");
91 if (ec_sc
& (1 << 4)) printk(BIOS_DEBUG
, "BURST ");
92 if (ec_sc
& (1 << 3)) printk(BIOS_DEBUG
, "CMD ");
93 if (ec_sc
& (1 << 1)) printk(BIOS_DEBUG
, "IBF ");
94 if (ec_sc
& (1 << 0)) printk(BIOS_DEBUG
, "OBF ");
95 printk(BIOS_DEBUG
, "\n");