2 * This file is part of the coreboot project.
4 * Copyright (C) 2011 The Chromium OS Authors. All rights reserved.
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
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., 51 Franklin St, Fifth Floor, Boston,
22 #include <console/console.h>
23 #include <device/device.h>
29 static u16 ec_cmd_reg = 0;
30 static u16 ec_data_reg = 0;
32 static inline u8 __ec_read(u8 addr)
34 outb(addr, ec_cmd_reg);
35 return inb(ec_data_reg);
38 static inline void __ec_write(u8 addr, u8 data)
40 outb(addr, ec_cmd_reg);
41 outb(data, ec_data_reg);
44 static int ec_ready(void)
46 u16 timeout = EC_TIMEOUT;
48 if (!ec_cmd_reg || !ec_data_reg) {
49 printk(BIOS_DEBUG, "Invalid ports: cmd=0x%x data=0x%x\n",
50 ec_cmd_reg, ec_data_reg);
54 while (__ec_read(EC_MAILBOX_COMMAND) != 0 && --timeout) {
56 if ((timeout & 0xff) == 0)
57 printk(BIOS_SPEW, ".");
60 printk(BIOS_DEBUG, "Timeout waiting for EC to be ready.\n");
66 int send_ec_command(u8 command)
70 __ec_write(EC_MAILBOX_COMMAND, command);
74 int send_ec_command_data(u8 command, u8 data)
78 __ec_write(EC_MAILBOX_DATA, data);
79 __ec_write(EC_MAILBOX_COMMAND, command);
83 u8 read_ec_command_byte(u8 command)
85 send_ec_command(command);
86 return __ec_read(EC_MAILBOX_DATA);
91 if (send_ec_command_data(EC_RAM_READ, addr) < 0)
93 return __ec_read(EC_MAILBOX_DATA);
96 int ec_write(u8 addr, u8 data)
100 __ec_write(EC_MAILBOX_DATA, addr);
101 __ec_write(EC_MAILBOX_DATA_H, data);
102 __ec_write(EC_MAILBOX_COMMAND, EC_RAM_WRITE);
106 void ec_set_bit(u8 addr, u8 bit)
108 ec_write(addr, ec_read(addr) | (1 << bit));
111 void ec_clr_bit(u8 addr, u8 bit)
113 ec_write(addr, ec_read(addr) & ~(1 << bit));
116 void ec_set_ports(u16 cmd_reg, u16 data_reg)
118 ec_cmd_reg = cmd_reg;
119 ec_data_reg = data_reg;
122 static void mec1308_enable(device_t dev)
124 struct ec_smsc_mec1308_config *conf = dev->chip_info;
126 if (conf->mailbox_port) {
127 ec_cmd_reg = conf->mailbox_port;
128 ec_data_reg = conf->mailbox_port + 1;
132 struct chip_operations ec_smsc_mec1308_ops = {
133 CHIP_NAME("SMSC MEC1308 EC Mailbox Interface")
134 .enable_dev = mec1308_enable