Patchwork [2/3] ec/acpi: make ACPI register pair configurable

login
register
about
Submitter Sven Schnelle
Date 2011-03-12 00:18:06
Message ID <1299889087-3174-2-git-send-email-svens@stackframe.org>
Download mbox | patch
Permalink /patch/2774/
State Accepted
Commit r6442
Headers show

Comments

Stefan Reinauer - 2011-03-11 23:42:49
* Sven Schnelle <svens@stackframe.org> [110312 01:18]:
> Signed-off-by: Sven Schnelle <svens@stackframe.org>
> ---
>  src/ec/acpi/ec.c |   23 ++++++++++++++++-------
>  src/ec/acpi/ec.h |    1 +
>  2 files changed, 17 insertions(+), 7 deletions(-)

I wonder if you want two sets of access functions, like on the Getac
P470 instead of changing the base address on the fly.
Sven Schnelle - 2011-03-12 00:18:06
Signed-off-by: Sven Schnelle <svens@stackframe.org>
---
 src/ec/acpi/ec.c |   23 ++++++++++++++++-------
 src/ec/acpi/ec.h |    1 +
 2 files changed, 17 insertions(+), 7 deletions(-)
Sven Schnelle - 2011-03-12 08:23:55
Stefan Reinauer <stefan.reinauer@coreboot.org> writes:

> * Sven Schnelle <svens@stackframe.org> [110312 01:18]:
>> Signed-off-by: Sven Schnelle <svens@stackframe.org>
>> ---
>>  src/ec/acpi/ec.c |   23 ++++++++++++++++-------
>>  src/ec/acpi/ec.h |    1 +
>>  2 files changed, 17 insertions(+), 7 deletions(-)
>
> I wonder if you want two sets of access functions, like on the Getac
> P470 instead of changing the base address on the fly.

I like the Adress configuration more. Accessing the 0x1600/0x1604
register pair works the same way as the 0x62/0x66 pair, so i dont
like to copy all the accessor function just because the base address
changed. And the performance impact of looking up the addresses instead
of having it as a literal in the outb asembler instruction is probably
negligible.

Sven.
Stefan Reinauer - 2011-03-13 22:48:01
* Sven Schnelle <svens@stackframe.org> [110312 09:23]:
> Stefan Reinauer <stefan.reinauer@coreboot.org> writes:
> 
> > * Sven Schnelle <svens@stackframe.org> [110312 01:18]:
> >> Signed-off-by: Sven Schnelle <svens@stackframe.org>
> >> ---
> >>  src/ec/acpi/ec.c |   23 ++++++++++++++++-------
> >>  src/ec/acpi/ec.h |    1 +
> >>  2 files changed, 17 insertions(+), 7 deletions(-)

Acked-by: Stefan Reinauer <stefan.reinauer@coreboot.org>

Patch

diff --git a/src/ec/acpi/ec.c b/src/ec/acpi/ec.c
index e353260..1d4ffb8 100644
--- a/src/ec/acpi/ec.c
+++ b/src/ec/acpi/ec.c
@@ -25,12 +25,15 @@ 
 #include <delay.h>
 #include "ec.h"
 
+static int ec_cmd_reg = EC_SC;
+static int ec_data_reg = EC_DATA;
+
 int send_ec_command(u8 command)
 {
 	int timeout;
 
 	timeout = 0x7ff;
-	while ((inb(EC_SC) & EC_IBF) && --timeout) {
+	while ((inb(ec_cmd_reg) & EC_IBF) && --timeout) {
 		udelay(10);
 		if ((timeout & 0xff) == 0)
 			printk(BIOS_SPEW, ".");
@@ -41,7 +44,7 @@  int send_ec_command(u8 command)
 		// return -1;
 	}
 
-	outb(command, EC_SC);
+	outb(command, ec_cmd_reg);
 	return 0;
 }
 
@@ -50,7 +53,7 @@  int send_ec_data(u8 data)
 	int timeout;
 
 	timeout = 0x7ff;
-	while ((inb(EC_SC) & EC_IBF) && --timeout) { // wait for IBF = 0
+	while ((inb(ec_cmd_reg) & EC_IBF) && --timeout) { // wait for IBF = 0
 		udelay(10);
 		if ((timeout & 0xff) == 0)
 			printk(BIOS_SPEW, ".");
@@ -61,14 +64,14 @@  int send_ec_data(u8 data)
 		// return -1;
 	}
 
-	outb(data, EC_DATA);
+	outb(data, ec_data_reg);
 
 	return 0;
 }
 
 int send_ec_data_nowait(u8 data)
 {
-	outb(data, EC_DATA);
+	outb(data, ec_data_reg);
 
 	return 0;
 }
@@ -80,7 +83,7 @@  u8 recv_ec_data(void)
 
 	timeout = 0x7fff;
 	while (--timeout) { // Wait for OBF = 1
-		if (inb(EC_SC) & EC_OBF) {
+		if (inb(ec_cmd_reg) & EC_OBF) {
 			break;
 		}
 		udelay(10);
@@ -92,7 +95,7 @@  u8 recv_ec_data(void)
 		// return -1;
 	}
 
-	data = inb(EC_DATA);
+	data = inb(ec_data_reg);
 	printk(BIOS_DEBUG, "recv_ec_data: 0x%02x\n", data);
 
 	return data;
@@ -123,6 +126,12 @@  void ec_clr_bit(u8 addr, u8 bit)
 	ec_write(addr, ec_read(addr) &  ~(1 << bit));
 }
 
+void ec_set_ports(u16 cmd_reg, u16 data_reg)
+{
+	ec_cmd_reg = cmd_reg;
+	ec_data_reg = data_reg;
+}
+
 struct chip_operations ec_acpi_ops = {
 	CHIP_NAME("ACPI Embedded Controller")
 };
diff --git a/src/ec/acpi/ec.h b/src/ec/acpi/ec.h
index cabbfea..b5a1197 100644
--- a/src/ec/acpi/ec.h
+++ b/src/ec/acpi/ec.h
@@ -46,6 +46,7 @@  u8 ec_read(u8 addr);
 int ec_write(u8 addr, u8 data);
 void ec_set_bit(u8 addr, u8 bit);
 void ec_clr_bit(u8 addr, u8 bit);
+void ec_set_ports(u16 cmd_reg, u16 data_reg);
 
 #endif