Debian Codegraph @

src/mainboard/getac/p470/ec_oem.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <console/console.h>
4 #include <arch/io.h>
5 #include <delay.h>
6 #include <ec/acpi/ec.h>
7 #include <types.h>
8
9 #include "ec_oem.h"
10
11 enum cb_err send_ec_oem_command(u8 command)
12 {
13 int timeout;
14
15 timeout = 0x7ff;
16 while ((inb(EC_OEM_SC) & EC_IBF) && --timeout) {
17 udelay(10);
18 if ((timeout & 0xff) == 0)
19 printk(BIOS_SPEW, ".");
20 }
21 if (!timeout) {
22 printk(BIOS_DEBUG, "Timeout while sending OEM command 0x%02x to EC!\n",
23 command);
24 // return CB_ERR;
25 }
26
27 outb(command, EC_OEM_SC);
28 return CB_SUCCESS;
29 }
30
31 enum cb_err send_ec_oem_data(u8 data)
32 {
33 int timeout;
34
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, ".");
40 }
41 if (!timeout) {
42 printk(BIOS_DEBUG, "Timeout while sending OEM data 0x%02x to EC!\n",
43 data);
44 // return CB_ERR;
45 }
46
47 outb(data, EC_OEM_DATA);
48
49 return CB_SUCCESS;
50 }
51
52 u8 recv_ec_oem_data(void)
53 {
54 int timeout;
55 u8 data;
56
57 timeout = 0x7fff;
58 while (--timeout) { // Wait for OBF = 1
59 if (inb(EC_OEM_SC) & EC_OBF) {
60 break;
61 }
62 udelay(10);
63 if ((timeout & 0xff) == 0)
64 printk(BIOS_SPEW, ".");
65 }
66 if (!timeout) {
67 printk(BIOS_DEBUG, "\nTimeout while receiving OEM data from EC!\n");
68 // return -1;
69 }
70
71 data = inb(EC_OEM_DATA);
72 // printk(BIOS_SPEW, "recv_ec_oem_data: 0x%02x\n", data);
73
74 return data;
75 }
76
77 u8 ec_oem_read(u8 addr)
78 {
79 send_ec_oem_command(0x80);
80 send_ec_oem_data(addr);
81
82 return recv_ec_oem_data();
83 }
84
85 int ec_oem_dump_status(void)
86 {
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");
96
97 return ec_sc;
98 }