blob: 30d41359cf2a668e3bc4ce76fa2ee1a5a1c3352c [file] [log] [blame]
Sven Schnelle7592e8b2011-01-27 11:43:03 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008-2009 coresystems GmbH
5 *
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.
10 *
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.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
19 * MA 02110-1301 USA
20 */
21
22#include <console/console.h>
23#include <arch/io.h>
24#include <delay.h>
25#include <ec/acpi/ec.h>
26#include "ec_oem.h"
27
28int send_ec_oem_command(u8 command)
29{
30 int timeout;
31
32 timeout = 0x7ff;
33 while ((inb(EC_OEM_SC) & EC_IBF) && --timeout) {
34 udelay(10);
35 if ((timeout & 0xff) == 0)
36 printk(BIOS_SPEW, ".");
37 }
38 if (!timeout) {
39 printk(BIOS_DEBUG, "Timeout while sending OEM command 0x%02x to EC!\n",
40 command);
41 // return -1;
42 }
43
44 outb(command, EC_OEM_SC);
45 return 0;
46}
47
48int send_ec_oem_data(u8 data)
49{
50 int timeout;
51
52 timeout = 0x7ff;
53 while ((inb(EC_OEM_SC) & EC_IBF) && --timeout) { // wait for IBF = 0
54 udelay(10);
55 if ((timeout & 0xff) == 0)
56 printk(BIOS_SPEW, ".");
57 }
58 if (!timeout) {
59 printk(BIOS_DEBUG, "Timeout while sending OEM data 0x%02x to EC!\n",
60 data);
61 // return -1;
62 }
63
64 outb(data, EC_OEM_DATA);
65
66 return 0;
67}
68
69int send_ec_oem_data_nowait(u8 data)
70{
71 outb(data, EC_OEM_DATA);
72
73 return 0;
74}
75
76u8 recv_ec_oem_data(void)
77{
78 int timeout;
79 u8 data;
80
81 timeout = 0x7fff;
82 while (--timeout) { // Wait for OBF = 1
83 if (inb(EC_OEM_SC) & EC_OBF) {
84 break;
85 }
86 udelay(10);
87 if ((timeout & 0xff) == 0)
88 printk(BIOS_SPEW, ".");
89 }
90 if (!timeout) {
91 printk(BIOS_DEBUG, "\nTimeout while receiving OEM data from EC!\n");
92 // return -1;
93 }
94
95 data = inb(EC_OEM_DATA);
96 // printk(BIOS_SPEW, "recv_ec_oem_data: 0x%02x\n", data);
97
98 return data;
99}
100
101u8 ec_oem_read(u8 addr)
102{
103 send_ec_oem_command(0x80);
104 send_ec_oem_data(addr);
105
106 return recv_ec_oem_data();
107}
108
109int ec_oem_write(u8 addr, u8 data)
110{
111 send_ec_oem_command(0x81);
112 send_ec_oem_data(addr);
113 return send_ec_oem_data(data);
114}
115
116int ec_oem_dump_status(void)
117{
118 u8 ec_sc = inb(EC_OEM_SC);
119 printk(BIOS_DEBUG, "Embedded Controller Status: ");
120 if (ec_sc & (1 << 6)) printk(BIOS_DEBUG, "SMI_EVT ");
121 if (ec_sc & (1 << 5)) printk(BIOS_DEBUG, "SCI_EVT ");
122 if (ec_sc & (1 << 4)) printk(BIOS_DEBUG, "BURST ");
123 if (ec_sc & (1 << 3)) printk(BIOS_DEBUG, "CMD ");
124 if (ec_sc & (1 << 1)) printk(BIOS_DEBUG, "IBF ");
125 if (ec_sc & (1 << 0)) printk(BIOS_DEBUG, "OBF ");
126 printk(BIOS_DEBUG, "\n");
127
128 return ec_sc;
129}
130