summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIru Cai <mytbk920423@gmail.com>2018-01-25 21:44:09 +0800
committerPatrick Georgi <pgeorgi@google.com>2018-04-19 16:30:23 +0000
commit2e8f4ccfe636fcb0ccd62aee503aa2320c83b6ea (patch)
tree69269ce6522780b62393167ac2630f7f8341526b
parent51895d183861234db9500bd1ee33634776e91e93 (diff)
downloadcoreboot-2e8f4ccfe636fcb0ccd62aee503aa2320c83b6ea.tar.xz
ectool: Add an option to get and use EC ports from /proc/ioports
There are boards that don't use ports 0x62 and 0x66 for EC, e.g. Dell Latitude E6230 uses 0x930 and 0x934. Change-Id: Ie3005f5cd6e37206ef187267b0542efdeb26b3af Signed-off-by: Iru Cai <mytbk920423@gmail.com> Reviewed-on: https://review.coreboot.org/23430 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Nico Huber <nico.h@gmx.de>
-rw-r--r--util/autoport/log_maker.go2
-rw-r--r--util/ectool/ec.c49
-rw-r--r--util/ectool/ec.h4
-rw-r--r--util/ectool/ectool.c13
4 files changed, 54 insertions, 14 deletions
diff --git a/util/autoport/log_maker.go b/util/autoport/log_maker.go
index a62f8f6ea8..08b35d2195 100644
--- a/util/autoport/log_maker.go
+++ b/util/autoport/log_maker.go
@@ -94,7 +94,7 @@ func MakeLogs(outDir string) {
}
RunAndSave(outDir+"/inteltool.log", "../inteltool/inteltool", inteltoolArgs)
- RunAndSave(outDir+"/ectool.log", "../ectool/ectool", "-d")
+ RunAndSave(outDir+"/ectool.log", "../ectool/ectool", "-pd")
RunAndSave(outDir+"/superiotool.log", "../superiotool/superiotool", "-ade")
SysDir := "/sys/class/sound/card0/"
diff --git a/util/ectool/ec.c b/util/ectool/ec.c
index 53a53605f6..d6c20001d8 100644
--- a/util/ectool/ec.c
+++ b/util/ectool/ec.c
@@ -16,12 +16,16 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
#if !(defined __NetBSD__ || defined __OpenBSD__)
#include <sys/io.h>
#endif
#include "ec.h"
+static int ec_data = 0x62;
+static int ec_sc = 0x66;
+
#if defined __NetBSD__ || defined __OpenBSD__
#include <machine/sysarch.h>
static uint8_t inb(unsigned port)
@@ -45,7 +49,7 @@ int send_ec_command(uint8_t command)
int timeout;
timeout = 0x7ff;
- while ((inb(EC_SC) & EC_IBF) && --timeout) {
+ while ((inb(ec_sc) & EC_IBF) && --timeout) {
usleep(10);
if ((timeout & 0xff) == 0)
debug(".");
@@ -56,7 +60,7 @@ int send_ec_command(uint8_t command)
// return -1;
}
- outb(command, EC_SC);
+ outb(command, ec_sc);
return 0;
}
@@ -65,7 +69,7 @@ int send_ec_data(uint8_t data)
int timeout;
timeout = 0x7ff;
- while ((inb(EC_SC) & EC_IBF) && --timeout) { // wait for IBF = 0
+ while ((inb(ec_sc) & EC_IBF) && --timeout) { // wait for IBF = 0
usleep(10);
if ((timeout & 0xff) == 0)
debug(".");
@@ -75,14 +79,14 @@ int send_ec_data(uint8_t data)
// return -1;
}
- outb(data, EC_DATA);
+ outb(data, ec_data);
return 0;
}
int send_ec_data_nowait(uint8_t data)
{
- outb(data, EC_DATA);
+ outb(data, ec_data);
return 0;
}
@@ -94,9 +98,9 @@ uint8_t recv_ec_data(void)
timeout = 0x7fff;
while (--timeout) { // Wait for OBF = 1
- if (inb(EC_SC) & EC_OBF) {
+ if (inb(ec_sc) & EC_OBF)
break;
- }
+
usleep(10);
if ((timeout & 0xff) == 0)
debug(".");
@@ -106,7 +110,7 @@ uint8_t recv_ec_data(void)
// return -1;
}
- data = inb(EC_DATA);
+ data = inb(ec_data);
debug("recv_ec_data: 0x%02x\n", data);
return data;
@@ -165,3 +169,32 @@ uint8_t ec_query(void)
send_ec_command(QR_EC);
return recv_ec_data();
}
+
+int get_ec_ports(void)
+{
+ FILE *fp = fopen("/proc/ioports", "r");
+ int data = 0, cmd = 0;
+ char line[100];
+
+ if (fp == NULL)
+ return -1;
+
+ while (!feof(fp) && (data == 0 || cmd == 0)) {
+ fgets(line, sizeof(line), fp);
+ if (strstr(line, "EC data") != NULL)
+ data = strtol(line, NULL, 16);
+
+ if (strstr(line, "EC cmd") != NULL)
+ cmd = strtol(line, NULL, 16);
+ }
+
+ fclose(fp);
+ if (data != 0 && cmd != 0) {
+ debug("EC data = 0x%x, EC cmd = 0x%x\n", data, cmd);
+ ec_data = data;
+ ec_sc = cmd;
+ } else {
+ return -1;
+ }
+ return 0;
+}
diff --git a/util/ectool/ec.h b/util/ectool/ec.h
index 4f65f60d99..fd062356d0 100644
--- a/util/ectool/ec.h
+++ b/util/ectool/ec.h
@@ -16,9 +16,6 @@
#ifndef _EC_H
#define _EC_H
-#define EC_DATA 0x62
-#define EC_SC 0x66
-
/* EC_SC input */
#define EC_SMI_EVT (1 << 6) // 1: SMI event pending
#define EC_SCI_EVT (1 << 5) // 1: SCI event pending
@@ -47,4 +44,5 @@ uint8_t ec_ext_read(uint16_t addr);
int ec_ext_write(uint16_t addr, uint8_t data);
uint8_t ec_idx_read(uint16_t addr);
uint8_t ec_query(void);
+int get_ec_ports(void);
#endif
diff --git a/util/ectool/ectool.c b/util/ectool/ectool.c
index dcf17288f1..be5a899765 100644
--- a/util/ectool/ectool.c
+++ b/util/ectool/ectool.c
@@ -62,6 +62,7 @@ void print_usage(const char *name)
" -v | --version: print the version\n"
" -h | --help: print this help\n\n"
" -V | --verbose: print debug information\n"
+ " -p | --getports: get EC data & cmd ports from /proc/ioports\n"
" -d | --dump: print RAM\n"
" -i | --idx: print IDX RAM & RAM\n"
" -q | --query: print query byte\n"
@@ -71,7 +72,7 @@ void print_usage(const char *name)
exit(1);
}
-int verbose = 0, dump_idx = 0, dump_ram = 0, dump_query = 0;
+int verbose = 0, dump_idx = 0, dump_ram = 0, dump_query = 0, get_ports = 0;
int main(int argc, char *argv[])
{
@@ -85,10 +86,11 @@ int main(int argc, char *argv[])
{"verbose", 0, 0, 'V'},
{"idx", 0, 0, 'i'},
{"query", 0, 0, 'q'},
+ {"getports", 0, 0, 'p'},
{0, 0, 0, 0}
};
- while ((opt = getopt_long(argc, argv, "vh?Vidqw:z:",
+ while ((opt = getopt_long(argc, argv, "vh?Vidqpw:z:",
long_options, &option_index)) != EOF) {
switch (opt) {
case 'v':
@@ -114,6 +116,9 @@ int main(int argc, char *argv[])
case 'q':
dump_query = 1;
break;
+ case 'p':
+ get_ports = 1;
+ break;
case 'h':
case '?':
default:
@@ -123,6 +128,10 @@ int main(int argc, char *argv[])
}
}
+ if (get_ports && get_ec_ports() != 0)
+ fprintf(stderr, "Cannot get EC ports from /proc/ioports, "
+ "fallback to default.");
+
if (iopl(3)) {
printf("You need to be root.\n");
exit(1);