tree: drop last paragraph of GPL copyright header
[coreboot.git] / src / mainboard / getac / p470 / ec_oem.c
blob874016779e5ec06f6ee1d79b734ddf819092b7ee
1 /*
2 * This file is part of the coreboot project.
4 * Copyright (C) 2008-2009 coresystems GmbH
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2 of
9 * the License.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
17 #include <console/console.h>
18 #include <arch/io.h>
19 #include <delay.h>
20 #include <ec/acpi/ec.h>
21 #include "ec_oem.h"
23 int send_ec_oem_command(u8 command)
25 int timeout;
27 timeout = 0x7ff;
28 while ((inb(EC_OEM_SC) & EC_IBF) && --timeout) {
29 udelay(10);
30 if ((timeout & 0xff) == 0)
31 printk(BIOS_SPEW, ".");
33 if (!timeout) {
34 printk(BIOS_DEBUG, "Timeout while sending OEM command 0x%02x to EC!\n",
35 command);
36 // return -1;
39 outb(command, EC_OEM_SC);
40 return 0;
43 int send_ec_oem_data(u8 data)
45 int timeout;
47 timeout = 0x7ff;
48 while ((inb(EC_OEM_SC) & EC_IBF) && --timeout) { // wait for IBF = 0
49 udelay(10);
50 if ((timeout & 0xff) == 0)
51 printk(BIOS_SPEW, ".");
53 if (!timeout) {
54 printk(BIOS_DEBUG, "Timeout while sending OEM data 0x%02x to EC!\n",
55 data);
56 // return -1;
59 outb(data, EC_OEM_DATA);
61 return 0;
64 int send_ec_oem_data_nowait(u8 data)
66 outb(data, EC_OEM_DATA);
68 return 0;
71 u8 recv_ec_oem_data(void)
73 int timeout;
74 u8 data;
76 timeout = 0x7fff;
77 while (--timeout) { // Wait for OBF = 1
78 if (inb(EC_OEM_SC) & EC_OBF) {
79 break;
81 udelay(10);
82 if ((timeout & 0xff) == 0)
83 printk(BIOS_SPEW, ".");
85 if (!timeout) {
86 printk(BIOS_DEBUG, "\nTimeout while receiving OEM data from EC!\n");
87 // return -1;
90 data = inb(EC_OEM_DATA);
91 // printk(BIOS_SPEW, "recv_ec_oem_data: 0x%02x\n", data);
93 return data;
96 u8 ec_oem_read(u8 addr)
98 send_ec_oem_command(0x80);
99 send_ec_oem_data(addr);
101 return recv_ec_oem_data();
104 int ec_oem_write(u8 addr, u8 data)
106 send_ec_oem_command(0x81);
107 send_ec_oem_data(addr);
108 return send_ec_oem_data(data);
111 int ec_oem_dump_status(void)
113 u8 ec_sc = inb(EC_OEM_SC);
114 printk(BIOS_DEBUG, "Embedded Controller Status: ");
115 if (ec_sc & (1 << 6)) printk(BIOS_DEBUG, "SMI_EVT ");
116 if (ec_sc & (1 << 5)) printk(BIOS_DEBUG, "SCI_EVT ");
117 if (ec_sc & (1 << 4)) printk(BIOS_DEBUG, "BURST ");
118 if (ec_sc & (1 << 3)) printk(BIOS_DEBUG, "CMD ");
119 if (ec_sc & (1 << 1)) printk(BIOS_DEBUG, "IBF ");
120 if (ec_sc & (1 << 0)) printk(BIOS_DEBUG, "OBF ");
121 printk(BIOS_DEBUG, "\n");
123 return ec_sc;