From d7bd4eb003f5b6a13943418ae0ac53248a2e34d2 Mon Sep 17 00:00:00 2001 From: Stefan Reinauer Date: Mon, 11 Feb 2013 11:11:36 -0800 Subject: Add support for "Butterfly" Chromebook We're happy to announce coreboot support for the "Butterfly" Chromebook, a.k.a HP Pavilion Chromebook. More information at: http://www.google.com/intl/en/chrome/devices/hp-pavilion-chromebook.html This commit also includes support for the ENE KB3940Q embedded controller running on Quanta's firmware. Change-Id: I194f847a94005218ec04eeba091c3257ac459510 Signed-off-by: Stefan Reinauer Reviewed-on: http://review.coreboot.org/2359 Reviewed-by: Duncan Laurie Tested-by: build bot (Jenkins) --- src/ec/quanta/ene_kb3940q/ec.c | 188 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 188 insertions(+) create mode 100644 src/ec/quanta/ene_kb3940q/ec.c (limited to 'src/ec/quanta/ene_kb3940q/ec.c') diff --git a/src/ec/quanta/ene_kb3940q/ec.c b/src/ec/quanta/ene_kb3940q/ec.c new file mode 100644 index 0000000000..1ef971244f --- /dev/null +++ b/src/ec/quanta/ene_kb3940q/ec.c @@ -0,0 +1,188 @@ +/* + * This file is part of the coreboot project. + * + * Copyright (C) 2012 The Chromium OS Authors. All rights reserved. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; version 2 of + * the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, + * MA 02110-1301 USA + */ + +#ifndef __PRE_RAM__ + +#include +#include +#include +#include +#include +#include +#include +#include "ec.h" +#include "chip.h" + +/* kbc helper functions from drivers/pc80/keyboard.c */ +static int ec_input_buffer_empty(u8 status_port) +{ + u32 timeout; + for(timeout = KBC_TIMEOUT_IN_MS; timeout && (inb(status_port) & KBD_IBF); + timeout--) { + mdelay(1); + } + + if (!timeout) { + printk(BIOS_WARNING, "Unexpected EC/KBD input buffer full\n"); + } + return !!timeout; +} + + +static int ec_output_buffer_full(u8 status_port) +{ + u32 timeout; + for(timeout = KBC_TIMEOUT_IN_MS; timeout && ((inb(status_port) + & KBD_OBF) == 0); timeout--) { + mdelay(1); + } + + if (!timeout) { + printk(BIOS_INFO, "EC/KBD output buffer result timeout\n"); + } + return !!timeout; +} + + + +/* The ENE 60/64 EC registers are the same command/status IB/OB KBC pair. + * Check status from 64 port before each command. + * + * Ex. Get panel ID command C43/D77 + * Check IBF empty. Then Write 0x43(CMD) to 0x64 Port + * Check IBF empty. Then Write 0x77(DATA) to 0x60 Port + * Check OBF set. Then Get Data(0x03:panel ID) from 0x60 + * Different commands return may or may not respond and may have multiple + * bytes. Keep it simple for now + */ + +u8 ec_kbc_read_ob(void) +{ + if (!ec_output_buffer_full(KBD_STATUS)) return 0; + return inb(KBD_DATA); +} + +void ec_kbc_write_cmd(u8 cmd) +{ + if (!ec_input_buffer_empty(KBD_STATUS)) return; + outb(cmd, KBD_COMMAND); +} + +void ec_kbc_write_ib(u8 data) +{ + if (!ec_input_buffer_empty(KBD_STATUS)) return; + outb(data, KBD_DATA); +} + +/* EC Host Control Protocol routines */ +u8 ec_read_ob(void) +{ + if (!ec_output_buffer_full(EC_SC)) return 0; + return inb(EC_DATA); +} + +void ec_write_cmd(u8 cmd) +{ + if (!ec_input_buffer_empty(EC_SC)) return; + outb(cmd, EC_COMMAND); +} + +void ec_write_ib(u8 data) +{ + if (!ec_input_buffer_empty(EC_SC)) return; + outb(data, EC_DATA); +} + +/* + * These functions are for accessing the ENE932 device RAM space + */ +u8 ec_mem_read(u8 addr) +{ + ec_write_cmd(EC_CMD_READ_RAM); + ec_write_ib(addr); + return ec_read_ob(); +} + +void ec_mem_write(u8 addr, u8 data) +{ + ec_write_cmd(EC_CMD_WRITE_RAM); + ec_write_ib(addr); + ec_write_ib(data); + return; +} + +#ifndef __SMM__ +static void ene_kb3940q_log_events(void) +{ +#if CONFIG_ELOG + u8 reason = ec_mem_read(EC_SHUTDOWN_REASON); + if (reason) + elog_add_event_byte(ELOG_TYPE_EC_SHUTDOWN, reason); +#endif +} + +static void ene_kb3940q_init(device_t dev) +{ + struct ec_quanta_ene_kb3940q_config *conf = dev->chip_info; + + if (!dev->enabled) + return; + + printk(BIOS_DEBUG, "Quanta EnE KB3940Q: Initializing keyboard.\n"); + pc_keyboard_init(&conf->keyboard); + + ene_kb3940q_log_events(); +} + + +static void ene_kb3940q_read_resources(device_t dev) +{ + /* This function avoids an error on serial console. */ +} + + +static void ene_kb3940q_enable_resources(device_t dev) +{ + /* This function avoids an error on serial console. */ +} + +static struct device_operations ops = { + .init = ene_kb3940q_init, + .read_resources = ene_kb3940q_read_resources, + .enable_resources = ene_kb3940q_enable_resources +}; + +static struct pnp_info pnp_dev_info[] = { + { &ops, 0, 0, { 0, 0 }, } +}; + +static void enable_dev(device_t dev) +{ + pnp_enable_devices(dev, &pnp_ops, ARRAY_SIZE(pnp_dev_info), + pnp_dev_info); +} + +struct chip_operations ec_quanta_ene_kb3940q_ops = { + CHIP_NAME("QUANTA EnE KB3940Q EC") + .enable_dev = enable_dev +}; +#endif /* ! __SMM__ */ +#endif /* ! __PRE_RAM__ */ -- cgit v1.2.3