[coreboot-gerrit] Change in coreboot[master]: [WIP] ec: add support for KBC1126 in HP laptops

Iru Cai (Code Review) gerrit at coreboot.org
Sun Apr 2 06:14:25 CEST 2017


Iru Cai has uploaded a new change for review. ( https://review.coreboot.org/19072 )

Change subject: [WIP] ec: add support for KBC1126 in HP laptops
......................................................................

[WIP] ec: add support for KBC1126 in HP laptops

- let the coreboot build system insert the two blobs to the coreboot image
- fan control support (only works on hp/2760p)

Change-Id: I6b16eb7e26303eda740f52d667dedb7cc04b4ef0
Signed-off-by: Iru Cai <mytbk920423 at gmail.com>
---
A src/ec/hp/kbc1126/Kconfig
A src/ec/hp/kbc1126/Makefile.inc
A src/ec/hp/kbc1126/ec.c
A src/ec/hp/kbc1126/ec.h
4 files changed, 253 insertions(+), 0 deletions(-)


  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/72/19072/1

diff --git a/src/ec/hp/kbc1126/Kconfig b/src/ec/hp/kbc1126/Kconfig
new file mode 100644
index 0000000..823d4e1
--- /dev/null
+++ b/src/ec/hp/kbc1126/Kconfig
@@ -0,0 +1,69 @@
+##
+## This file is part of the coreboot project.
+##
+## Copyright (C) 2017 Iru Cai
+##
+## 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.
+##
+
+config EC_HP_KBC1126
+	bool
+	help
+	Interface to SMSC KBC1126 embedded controller in HP laptops.
+
+if EC_HP_KBC1126
+
+config RESERVED_SPACE_BEFORE_RESET_VECTOR
+	hex
+	default 0x8f0
+
+config KBC1126_FIRMWARE
+	bool "Add firmware images for KBC1126 firmware"
+	depends on EC_HP_KBC1126
+	help
+		Select this option to add the two firmware blobs for KBC1126.
+		You need these two blobs to power on your machine.
+
+config KBC1126_FW1
+    string "KBC1126 firmware #1 path and filename"
+    depends on KBC1126_FIRMWARE
+    default "fw1.bin"
+    help
+      The path and filename of the file to use as KBC1126 firmware #1.
+
+config KBC1126_FW1_OFFSET
+	string "KBC1126 firmware #1 offset"
+	depends on KBC1126_FIRMWARE
+	default "-0x900"
+	help
+	  The offset of KBC1126 firmware #1.
+	  If this value is negative, the absolute value of it means
+	  the distance to the end of file.
+	  If unsure, keep the default value -0x900 because the space
+	  starting at this position is reserved by default to place this blob.
+
+config KBC1126_FW2
+    string "KBC1126 filename #2 path and filename"
+    depends on KBC1126_FIRMWARE
+    default "fw2.bin"
+    help
+      The path and filename of the file to use as KBC1126 firmware #2.
+
+config KBC1126_FW2_OFFSET
+	string "KBC1126 firmware #2 offset"
+	depends on KBC1126_FIRMWARE
+	default "-0x300000"
+	help
+	  The offset of KBC1126 firmware #2.
+	  If this value is negative, the absolute value of it means
+	  the distance to the end of file.
+	  You should place KBC1126 firmware #2 (about 64K) outside of CBFS.
+
+endif
diff --git a/src/ec/hp/kbc1126/Makefile.inc b/src/ec/hp/kbc1126/Makefile.inc
new file mode 100644
index 0000000..5ae38c1
--- /dev/null
+++ b/src/ec/hp/kbc1126/Makefile.inc
@@ -0,0 +1,36 @@
+##
+## This file is part of the coreboot project.
+##
+## Copyright (C) 2017 Iru Cai
+##
+## 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.
+##
+
+ifeq ($(CONFIG_EC_HP_KBC1126),y)
+
+KBC1126_EC_INSERT:=$(top)/util/kbc1126/kbc1126_ec_insert
+
+ifeq ($(CONFIG_KBC1126_FIRMWARE),y)
+INTERMEDIATE+=kbc1126_ec_insert
+endif
+
+kbc1126_ec_insert: $(obj)/coreboot.pre
+	printf "    Building kbc1126_ec_insert.\n"
+	$(MAKE) -C util/kbc1126
+	printf "    KBC1126    Inserting KBC1126 firmware blobs.\n"
+	$(KBC1126_EC_INSERT) $(obj)/coreboot.pre \
+		$(CONFIG_KBC1126_FW1) $(CONFIG_KBC1126_FW2) \
+		$(CONFIG_KBC1126_FW1_OFFSET) $(CONFIG_KBC1126_FW2_OFFSET)
+
+PHONY+=kbc1126_ec_insert
+
+ramstage-y += ec.c
+
+endif
diff --git a/src/ec/hp/kbc1126/ec.c b/src/ec/hp/kbc1126/ec.c
new file mode 100644
index 0000000..8627e67
--- /dev/null
+++ b/src/ec/hp/kbc1126/ec.c
@@ -0,0 +1,124 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2009 coresystems GmbH
+ * Copyright (C) 2017 Iru Cai
+ *
+ * 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.
+ */
+
+#include <arch/io.h>
+#include <console/console.h>
+#include <device/device.h>
+#include <delay.h>
+
+#include "ec.h"
+
+#define KBD_DATA	0x60
+#define KBD_SC		0x64
+
+#define   KBD_IBF	(1 << 1) /* 1: input buffer full (data ready for ec) */
+#define   KBD_OBF	(1 << 0) /* 1: output buffer full (data ready for host) */
+
+static int send_kbd_command(u8 command)
+{
+	int timeout;
+
+	timeout = 0x7ff;
+	while ((inb(KBD_SC) & KBD_IBF) && --timeout) {
+		udelay(10);
+		if ((timeout & 0xff) == 0)
+			printk(BIOS_SPEW, ".");
+	}
+	if (!timeout) {
+		printk(BIOS_DEBUG, "Timeout while sending command 0x%02x to EC!\n",
+				command);
+		return -1;
+	}
+
+	outb(command, KBD_SC);
+	return 0;
+}
+
+static int send_kbd_data(u8 data)
+{
+	int timeout;
+
+	timeout = 0x7ff;
+	while ((inb(KBD_SC) & KBD_IBF) && --timeout) { /* wait for IBF = 0 */
+		udelay(10);
+		if ((timeout & 0xff) == 0)
+			printk(BIOS_SPEW, ".");
+	}
+	if (!timeout) {
+		printk(BIOS_DEBUG, "Timeout while sending data 0x%02x to EC!\n",
+				data);
+		return -1;
+	}
+
+	outb(data, KBD_DATA);
+	return 0;
+}
+
+#if 0
+static u8 recv_kbd_data(void)
+{
+	int timeout;
+	u8 data;
+
+	timeout = 0x7fff;
+	while (--timeout) { /* Wait for OBF = 1 */
+		if (inb(KBD_SC) & KBD_OBF) {
+			break;
+		}
+		udelay(10);
+		if ((timeout & 0xff) == 0)
+			printk(BIOS_SPEW, ".");
+	}
+	if (!timeout) {
+		printk(BIOS_DEBUG, "\nTimeout while receiving data from EC!\n");
+	}
+
+	data = inb(KBD_DATA);
+	return data;
+}
+#endif
+
+void kbc1126_thermalinit(u8 cmd)
+{
+	if (send_kbd_command(cmd)<0)
+		goto fail;
+
+	if (send_kbd_data(0x27)<0)
+		goto fail;
+
+	if (send_kbd_data(0x01)<0)
+		goto fail;
+
+	/*
+	 * TODO: The following is not needed for fan control,
+	 * but it's found in OEM firmware
+	 */
+
+	if (send_kbd_command(cmd)<0)
+		goto fail;
+
+	if (send_kbd_data(0xd5)<0)
+		goto fail;
+
+	if (send_kbd_data(0xff)<0)
+		goto fail;
+
+	return;
+fail:
+	printk(BIOS_DEBUG, "Fail to init EC\n");
+	return;
+}
diff --git a/src/ec/hp/kbc1126/ec.h b/src/ec/hp/kbc1126/ec.h
new file mode 100644
index 0000000..55003ca
--- /dev/null
+++ b/src/ec/hp/kbc1126/ec.h
@@ -0,0 +1,24 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2017 Iru Cai
+ *
+ * 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.
+ *
+ */
+
+#ifndef _EC_HP_KBC1126_EC_H
+
+void kbc1126_thermalinit(u8 cmd);
+
+#define _EC_HP_KBC1126_EC_H
+
+
+#endif /* _EC_HP_KBC1126_EC_H */

-- 
To view, visit https://review.coreboot.org/19072
To unsubscribe, visit https://review.coreboot.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6b16eb7e26303eda740f52d667dedb7cc04b4ef0
Gerrit-PatchSet: 1
Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Owner: Iru Cai <mytbk920423 at gmail.com>



More information about the coreboot-gerrit mailing list