mainboard/intel/avenuecity_crb: Update full IIO configuration
[coreboot2.git] / src / mainboard / getac / p470 / ec_oem.c
blobc810953bab4b50d54e506955aac5cad393effb3d
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <console/console.h>
4 #include <arch/io.h>
5 #include <delay.h>
6 #include <ec/acpi/ec.h>
7 #include <types.h>
9 #include "ec_oem.h"
11 enum cb_err send_ec_oem_command(u8 command)
13 int timeout;
15 timeout = 0x7ff;
16 while ((inb(EC_OEM_SC) & EC_IBF) && --timeout) {
17 udelay(10);
18 if ((timeout & 0xff) == 0)
19 printk(BIOS_SPEW, ".");
21 if (!timeout) {
22 printk(BIOS_DEBUG, "Timeout while sending OEM command 0x%02x to EC!\n",
23 command);
24 // return CB_ERR;
27 outb(command, EC_OEM_SC);
28 return CB_SUCCESS;
31 enum cb_err send_ec_oem_data(u8 data)
33 int timeout;
35 timeout = 0x7ff;
36 while ((inb(EC_OEM_SC) & EC_IBF) && --timeout) { // wait for IBF = 0
37 udelay(10);
38 if ((timeout & 0xff) == 0)
39 printk(BIOS_SPEW, ".");
41 if (!timeout) {
42 printk(BIOS_DEBUG, "Timeout while sending OEM data 0x%02x to EC!\n",
43 data);
44 // return CB_ERR;
47 outb(data, EC_OEM_DATA);
49 return CB_SUCCESS;
52 u8 recv_ec_oem_data(void)
54 int timeout;
55 u8 data;
57 timeout = 0x7fff;
58 while (--timeout) { // Wait for OBF = 1
59 if (inb(EC_OEM_SC) & EC_OBF) {
60 break;
62 udelay(10);
63 if ((timeout & 0xff) == 0)
64 printk(BIOS_SPEW, ".");
66 if (!timeout) {
67 printk(BIOS_DEBUG, "\nTimeout while receiving OEM data from EC!\n");
68 // return -1;
71 data = inb(EC_OEM_DATA);
72 // printk(BIOS_SPEW, "recv_ec_oem_data: 0x%02x\n", data);
74 return 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");
97 return ec_sc;