mainboard/[g-p]*: Remove copyright notices
[coreboot.git] / src / mainboard / getac / p470 / ec_oem.c
blob344374b358a6e77d89b0ccd44b96447091141ac8
1 /*
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
8 * the License.
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>
17 #include <arch/io.h>
18 #include <delay.h>
19 #include <ec/acpi/ec.h>
20 #include "ec_oem.h"
22 int send_ec_oem_command(u8 command)
24 int timeout;
26 timeout = 0x7ff;
27 while ((inb(EC_OEM_SC) & EC_IBF) && --timeout) {
28 udelay(10);
29 if ((timeout & 0xff) == 0)
30 printk(BIOS_SPEW, ".");
32 if (!timeout) {
33 printk(BIOS_DEBUG, "Timeout while sending OEM command 0x%02x to EC!\n",
34 command);
35 // return -1;
38 outb(command, EC_OEM_SC);
39 return 0;
42 int send_ec_oem_data(u8 data)
44 int timeout;
46 timeout = 0x7ff;
47 while ((inb(EC_OEM_SC) & EC_IBF) && --timeout) { // wait for IBF = 0
48 udelay(10);
49 if ((timeout & 0xff) == 0)
50 printk(BIOS_SPEW, ".");
52 if (!timeout) {
53 printk(BIOS_DEBUG, "Timeout while sending OEM data 0x%02x to EC!\n",
54 data);
55 // return -1;
58 outb(data, EC_OEM_DATA);
60 return 0;
63 int send_ec_oem_data_nowait(u8 data)
65 outb(data, EC_OEM_DATA);
67 return 0;
70 u8 recv_ec_oem_data(void)
72 int timeout;
73 u8 data;
75 timeout = 0x7fff;
76 while (--timeout) { // Wait for OBF = 1
77 if (inb(EC_OEM_SC) & EC_OBF) {
78 break;
80 udelay(10);
81 if ((timeout & 0xff) == 0)
82 printk(BIOS_SPEW, ".");
84 if (!timeout) {
85 printk(BIOS_DEBUG, "\nTimeout while receiving OEM data from EC!\n");
86 // return -1;
89 data = inb(EC_OEM_DATA);
90 // printk(BIOS_SPEW, "recv_ec_oem_data: 0x%02x\n", data);
92 return 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");
122 return ec_sc;