[coreboot] Fwd: Question about new_resource()

Sven Schnelle svens at stackframe.org
Sun Jan 30 13:54:14 CET 2011


Hi Myles,

sorry to bother you directly, but Peter suggested to send the question
below to you directly, you may have an answer :)

Regards,

Sven.

-------- Original Message --------
Subject: [coreboot] Question about new_resource()
Date: Thu, 27 Jan 2011 18:38:55 +0100
From: Sven Schnelle <svens at stackframe.org>
Organization: private
To: coreboot at coreboot.org

Hi List,

while  adding support for the Lenovo PMH7 Embedded Controller,
i was wondering about the index parameter for new_resource().
>From looking at the coreboot source, it looks like it is an
arbitrary number, depending on the device type for which the
resource is allocated. What would be the corect number to use
for an EC? Or should we add a new index for such devices?

I'm attaching the pmh7 diff to this mail, i have chosen 0x77
as a temporary number.

Thanks,

Sven

Index: ec/lenovo/Kconfig
===================================================================
--- ec/lenovo/Kconfig	(revision 0)
+++ ec/lenovo/Kconfig	(revision 0)
@@ -0,0 +1 @@
+source src/ec/lenovo/pmh7/Kconfig
Index: ec/lenovo/Makefile.inc
===================================================================
--- ec/lenovo/Makefile.inc	(revision 0)
+++ ec/lenovo/Makefile.inc	(revision 0)
@@ -0,0 +1 @@
+subdirs-$(CONFIG_EC_LENOVO_PMH7) += pmh7
Index: ec/lenovo/pmh7/Kconfig
===================================================================
--- ec/lenovo/pmh7/Kconfig	(revision 0)
+++ ec/lenovo/pmh7/Kconfig	(revision 0)
@@ -0,0 +1,2 @@
+config EC_LENOVO_PMH7
+	bool
Index: ec/lenovo/pmh7/pmh7.h
===================================================================
--- ec/lenovo/pmh7/pmh7.h	(revision 0)
+++ ec/lenovo/pmh7/pmh7.h	(revision 0)
@@ -0,0 +1,13 @@
+#ifndef EC_LENOVO_PMH7_H
+#define EC_LENOVO_PMH7_H
+
+#define EC_LENOVO_PMH7_BASE 0x15e0
+#define EC_LENOVO_PMH7_ADDR (EC_LENOVO_PMH7_BASE + 0x0c)
+#define EC_LENOVO_PMH7_DATA (EC_LENOVO_PMH7_BASE + 0x0e)
+
+void pmh7_register_set_bit(int reg, int bit);
+void pmh7_register_clear_bit(int reg, int bit);
+char pmh7_register_read(int reg);
+void pmh7_register_write(int reg, int val);
+
+#endif
Index: ec/lenovo/pmh7/Makefile.inc
===================================================================
--- ec/lenovo/pmh7/Makefile.inc	(revision 0)
+++ ec/lenovo/pmh7/Makefile.inc	(revision 0)
@@ -0,0 +1 @@
+driver-y += pmh7.c
Index: ec/lenovo/pmh7/pmh7.c
===================================================================
--- ec/lenovo/pmh7/pmh7.c	(revision 0)
+++ ec/lenovo/pmh7/pmh7.c	(revision 0)
@@ -0,0 +1,56 @@
+#include <arch/io.h>
+#include <console/console.h>
+#include <device/device.h>
+#include <device/pnp.h>
+#include <stdlib.h>
+
+#include "pmh7.h"
+
+void pmh7_register_set_bit(int reg, int bit)
+{
+	char val;
+
+	outb(reg, EC_LENOVO_PMH7_ADDR);
+	val = inb(EC_LENOVO_PMH7_DATA);
+	outb(reg, EC_LENOVO_PMH7_ADDR);
+	outb(val | (1 << bit), EC_LENOVO_PMH7_DATA);
+}
+
+void pmh7_register_clear_bit(int reg, int bit)
+{
+	char val;
+
+	outb(reg, EC_LENOVO_PMH7_ADDR);
+	val = inb(EC_LENOVO_PMH7_DATA);
+	outb(reg, EC_LENOVO_PMH7_ADDR);
+	outb(val &= ~(1 << bit), EC_LENOVO_PMH7_DATA);
+}
+
+char pmh7_register_read(int reg)
+{
+	outb(reg, EC_LENOVO_PMH7_ADDR);
+	return inb(EC_LENOVO_PMH7_DATA);
+}
+
+void pmh7_register_write(int reg, int val)
+{
+	outb(reg, EC_LENOVO_PMH7_ADDR);
+	outb(val, EC_LENOVO_PMH7_DATA);
+}
+
+static void enable_dev(device_t dev)
+{
+	struct resource *resource;
+	resource = new_resource(dev, 0x77);
+	resource->flags = IORESOURCE_IO | IORESOURCE_FIXED;
+	resource->base = EC_LENOVO_PMH7_BASE;
+	resource->size = 16;
+	resource->align = 5;
+	resource->gran = 5;
+
+}
+
+struct chip_operations ec_lenovo_pmh7_ops = {
+	CHIP_NAME("Lenovo Power Management Hardware Hub 7")
+	.enable_dev = enable_dev,
+};

-- 
coreboot mailing list: coreboot at coreboot.org
http://www.coreboot.org/mailman/listinfo/coreboot




More information about the coreboot mailing list