Remove address from GPLv2 headers
[coreboot.git] / src / ec / acpi / ec.c
blob6bd470722d26b141ae6fd7baf5fa7f8c91f50813
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.
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.
21 #include <console/console.h>
22 #include <device/device.h>
23 #include <arch/io.h>
24 #include <delay.h>
25 #include "ec.h"
27 #ifdef __PRE_RAM__
29 static const int ec_cmd_reg = EC_SC;
30 static const int ec_data_reg = EC_DATA;
32 #else
34 static int ec_cmd_reg = EC_SC;
35 static int ec_data_reg = EC_DATA;
37 #endif
39 int send_ec_command(u8 command)
41 int timeout;
43 timeout = 0x7ff;
44 while ((inb(ec_cmd_reg) & EC_IBF) && --timeout) {
45 udelay(10);
46 if ((timeout & 0xff) == 0)
47 printk(BIOS_SPEW, ".");
49 if (!timeout) {
50 printk(BIOS_DEBUG, "Timeout while sending command 0x%02x to EC!\n",
51 command);
52 // return -1;
55 udelay(10);
57 outb(command, ec_cmd_reg);
58 return 0;
61 int send_ec_data(u8 data)
63 int timeout;
65 timeout = 0x7ff;
66 while ((inb(ec_cmd_reg) & EC_IBF) && --timeout) { // wait for IBF = 0
67 udelay(10);
68 if ((timeout & 0xff) == 0)
69 printk(BIOS_SPEW, ".");
71 if (!timeout) {
72 printk(BIOS_DEBUG, "Timeout while sending data 0x%02x to EC!\n",
73 data);
74 // return -1;
77 udelay(10);
79 outb(data, ec_data_reg);
81 return 0;
84 int send_ec_data_nowait(u8 data)
86 outb(data, ec_data_reg);
88 return 0;
91 u8 recv_ec_data(void)
93 int timeout;
94 u8 data;
96 timeout = 0x7fff;
97 while (--timeout) { // Wait for OBF = 1
98 if (inb(ec_cmd_reg) & EC_OBF) {
99 break;
101 udelay(10);
102 if ((timeout & 0xff) == 0)
103 printk(BIOS_SPEW, ".");
105 if (!timeout) {
106 printk(BIOS_DEBUG, "\nTimeout while receiving data from EC!\n");
107 // return -1;
110 udelay(10);
112 data = inb(ec_data_reg);
113 printk(BIOS_SPEW, "recv_ec_data: 0x%02x\n", data);
115 return data;
118 u8 ec_read(u8 addr)
120 send_ec_command(0x80);
121 send_ec_data(addr);
123 return recv_ec_data();
126 int ec_write(u8 addr, u8 data)
128 send_ec_command(0x81);
129 send_ec_data(addr);
130 return send_ec_data(data);
133 u8 ec_query(void)
135 send_ec_command(0x84);
136 return recv_ec_data();
139 void ec_set_bit(u8 addr, u8 bit)
141 ec_write(addr, ec_read(addr) | (1 << bit));
144 void ec_clr_bit(u8 addr, u8 bit)
146 ec_write(addr, ec_read(addr) & ~(1 << bit));
149 #ifndef __PRE_RAM__
151 void ec_set_ports(u16 cmd_reg, u16 data_reg)
153 ec_cmd_reg = cmd_reg;
154 ec_data_reg = data_reg;
157 #endif
159 #if !defined(__SMM__) && !defined(__PRE_RAM__)
160 struct chip_operations ec_acpi_ops = {
161 CHIP_NAME("ACPI Embedded Controller")
163 #endif