[coreboot-gerrit] Patch set updated for coreboot: ec/lenovo/h8: Add USB Always On
Nicola Corna (nicola@corna.info)
gerrit at coreboot.org
Tue Nov 8 12:47:33 CET 2016
Nicola Corna (nicola at corna.info) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/17252
-gerrit
commit 130cc61d023c0f5bfe8bc27664c9283c4c14241c
Author: Nicola Corna <nicola at corna.info>
Date: Sat Nov 5 16:06:59 2016 +0100
ec/lenovo/h8: Add USB Always On
USB AO is the internal name for the dedicated charging port on
ThinkPads when in S3 or lower.
AOEN (bit 0) is internal name for enabling this feature while AOCF
(bits 2 and 3) is the configuration field. According to Peter Stuge,
AOCF can be configured in this way:
00 => AC S3 S4 S4 USB on, battery S3 USB on, battery S4 S5 off
11 => AC S3 S4 S4 USB on, battery S3 S4 S5 USB off
10, 01 => equivalent to 00
This commit also adds a new configuration field in the CMOS of the
X220 and the X201 to activate this feature. It probably can be also
added to all the ThinkPads that support this functionality.
With this functionality USB devices are able to negotiate full power
from the dedicated port (usually the yellow one) even in S3.
Tested on a X201 and X220 with an Android smartphone: with this
feature enabled it shows "Charging" when connected during S3, without
it it shows "Charging slowly" (or it doesn't charge at all on the
X201).
For some reasons the "AC only" mode doesn't work, so it has been
disabled and left in place for future fixes.
Change-Id: Ie1269a4357e2fbd608ad8b7b8262275914730f6e
Signed-off-by: Nicola Corna <nicola at corna.info>
---
src/ec/lenovo/h8/Makefile.inc | 1 +
src/ec/lenovo/h8/h8.c | 4 ++-
src/ec/lenovo/h8/h8.h | 4 +++
src/ec/lenovo/h8/smm.c | 45 ++++++++++++++++++++++++++++++++++
src/ec/lenovo/h8/smm.h | 16 ++++++++++++
src/mainboard/lenovo/x201/cmos.default | 1 +
src/mainboard/lenovo/x201/cmos.layout | 6 +++--
src/mainboard/lenovo/x201/smihandler.c | 4 +++
src/mainboard/lenovo/x220/cmos.default | 1 +
src/mainboard/lenovo/x220/cmos.layout | 5 +++-
src/mainboard/lenovo/x220/smihandler.c | 4 +++
11 files changed, 87 insertions(+), 4 deletions(-)
diff --git a/src/ec/lenovo/h8/Makefile.inc b/src/ec/lenovo/h8/Makefile.inc
index 4829e7b..da9cee1 100644
--- a/src/ec/lenovo/h8/Makefile.inc
+++ b/src/ec/lenovo/h8/Makefile.inc
@@ -1,5 +1,6 @@
ifeq ($(CONFIG_EC_LENOVO_H8),y)
ramstage-y += h8.c
+smm-y += smm.c
endif
diff --git a/src/ec/lenovo/h8/h8.c b/src/ec/lenovo/h8/h8.c
index 703acad..fe76735 100644
--- a/src/ec/lenovo/h8/h8.c
+++ b/src/ec/lenovo/h8/h8.c
@@ -288,7 +288,7 @@ static void h8_enable(struct device *dev)
ec_write(H8_CONFIG2, conf->config2);
ec_write(H8_CONFIG3, conf->config3);
- if (!acpi_is_wakeup_s3())
+ //if (!acpi_is_wakeup_s3())
h8_configure(conf);
/* silence sounds in queue */
@@ -313,6 +313,8 @@ static void h8_enable(struct device *dev)
ec_write(0x1f, conf->eventf_enable);
ec_write(H8_FAN_CONTROL, H8_FAN_CONTROL_AUTO);
+ ec_write(H8_USB_ALWAYS_ON, ec_read(H8_USB_ALWAYS_ON) &
+ ~H8_USB_ALWAYS_ON_ENABLE);
h8_trackpoint_enable(1);
h8_usb_power_enable(1);
diff --git a/src/ec/lenovo/h8/h8.h b/src/ec/lenovo/h8/h8.h
index d3803c0..c9d50e8 100644
--- a/src/ec/lenovo/h8/h8.h
+++ b/src/ec/lenovo/h8/h8.h
@@ -64,6 +64,10 @@ void h8_mainboard_init_dock (void);
#define H8_LED_CONTROL_ON 0x80
#define H8_LED_CONTROL_BLINK 0xc0
+#define H8_USB_ALWAYS_ON 0x0d
+#define H8_USB_ALWAYS_ON_ENABLE 0x01
+#define H8_USB_ALWAYS_ON_AC_ONLY 0x0c
+
#define H8_LED_CONTROL_POWER_LED 0x00
#define H8_LED_CONTROL_BAT0_LED 0x01
#define H8_LED_CONTROL_BAT1_LED 0x02
diff --git a/src/ec/lenovo/h8/smm.c b/src/ec/lenovo/h8/smm.c
new file mode 100644
index 0000000..42bad03
--- /dev/null
+++ b/src/ec/lenovo/h8/smm.c
@@ -0,0 +1,45 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2016 Nicola Corna <nicola at corna.info>
+ *
+ * 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 <ec/lenovo/h8/h8.h>
+#include <ec/acpi/ec.h>
+#include <pc80/mc146818rtc.h>
+
+#include "smm.h"
+
+void h8_usb_always_on(void)
+{
+ u8 val;
+ u8 reg;
+
+ if (get_option(&val, "usb_always_on") != CB_SUCCESS)
+ val = 0;
+
+ reg = ec_read(H8_USB_ALWAYS_ON);
+
+ switch (val) {
+ case 1:
+ reg &= ~H8_USB_ALWAYS_ON_AC_ONLY;
+ reg |= H8_USB_ALWAYS_ON_ENABLE;
+ break;
+ case 2:
+ reg |= H8_USB_ALWAYS_ON_AC_ONLY | H8_USB_ALWAYS_ON_ENABLE;
+ break;
+ default:
+ break;
+ }
+
+ ec_write(H8_USB_ALWAYS_ON, reg);
+}
diff --git a/src/ec/lenovo/h8/smm.h b/src/ec/lenovo/h8/smm.h
new file mode 100644
index 0000000..3142906
--- /dev/null
+++ b/src/ec/lenovo/h8/smm.h
@@ -0,0 +1,16 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2016 Nicola Corna <nicola at corna.info>
+ *
+ * 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.
+ */
+
+void h8_usb_always_on(void);
diff --git a/src/mainboard/lenovo/x201/cmos.default b/src/mainboard/lenovo/x201/cmos.default
index 50d17ae..9f1e31d 100644
--- a/src/mainboard/lenovo/x201/cmos.default
+++ b/src/mainboard/lenovo/x201/cmos.default
@@ -15,3 +15,4 @@ sticky_fn=Disable
power_management_beeps=Enable
low_battery_beep=Enable
sata_mode=AHCI
+usb_always_on=Disable
diff --git a/src/mainboard/lenovo/x201/cmos.layout b/src/mainboard/lenovo/x201/cmos.layout
index 2a91eb7..12f559d 100644
--- a/src/mainboard/lenovo/x201/cmos.layout
+++ b/src/mainboard/lenovo/x201/cmos.layout
@@ -70,8 +70,7 @@ entries
419 1 e 1 power_management_beeps
420 1 e 1 low_battery_beep
421 1 e 9 sata_mode
-
-#422 2 r 0 unused
+422 2 e 11 usb_always_on
# coreboot config options: northbridge
424 3 e 10 gfx_uma_size
@@ -123,6 +122,9 @@ enumerations
10 3 128M
10 5 96M
10 6 160M
+12 0 Disable
+12 1 AC and battery
+#12 2 AC only
# -----------------------------------------------------------------
checksums
diff --git a/src/mainboard/lenovo/x201/smihandler.c b/src/mainboard/lenovo/x201/smihandler.c
index 591a521..538ca00 100644
--- a/src/mainboard/lenovo/x201/smihandler.c
+++ b/src/mainboard/lenovo/x201/smihandler.c
@@ -2,6 +2,7 @@
* This file is part of the coreboot project.
*
* Copyright (C) 2008-2009 coresystems GmbH
+ * Copyright (C) 2016 Nicola Corna <nicola at corna.info>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -25,6 +26,7 @@
#include <ec/acpi/ec.h>
#include <pc80/mc146818rtc.h>
#include <ec/lenovo/h8/h8.h>
+#include <ec/lenovo/h8/smm.h>
#include <delay.h>
#include "dock.h"
#include "smi.h"
@@ -178,6 +180,8 @@ int mainboard_smi_apmc(u8 data)
void mainboard_smi_sleep(u8 slp_typ)
{
+ h8_usb_always_on();
+
if (slp_typ == 3) {
u8 ec_wake = ec_read(0x32);
/* If EC wake events are enabled, enable wake on EC WAKE GPE. */
diff --git a/src/mainboard/lenovo/x220/cmos.default b/src/mainboard/lenovo/x220/cmos.default
index 1b8e212..91331ab 100644
--- a/src/mainboard/lenovo/x220/cmos.default
+++ b/src/mainboard/lenovo/x220/cmos.default
@@ -10,6 +10,7 @@ wwan=Enable
wlan=Enable
touchpad=Enable
sata_mode=AHCI
+usb_always_on=Disable
fn_ctrl_swap=Disable
sticky_fn=Disable
trackpoint=Enable
diff --git a/src/mainboard/lenovo/x220/cmos.layout b/src/mainboard/lenovo/x220/cmos.layout
index 143ee80..88b18d6 100644
--- a/src/mainboard/lenovo/x220/cmos.layout
+++ b/src/mainboard/lenovo/x220/cmos.layout
@@ -69,7 +69,7 @@ entries
418 1 e 1 sticky_fn
419 1 e 1 power_management_beeps
421 1 e 9 sata_mode
-#422 2 r 1 unused
+422 2 e 12 usb_always_on
# coreboot config options: cpu
424 1 e 2 hyper_threading
@@ -134,6 +134,9 @@ enumerations
11 4 160M
11 5 192M
11 6 224M
+12 0 Disable
+12 1 AC and battery
+#12 2 AC only
# -----------------------------------------------------------------
checksums
diff --git a/src/mainboard/lenovo/x220/smihandler.c b/src/mainboard/lenovo/x220/smihandler.c
index 08554c9..a98cd82 100644
--- a/src/mainboard/lenovo/x220/smihandler.c
+++ b/src/mainboard/lenovo/x220/smihandler.c
@@ -3,6 +3,7 @@
*
* Copyright (C) 2008-2009 coresystems GmbH
* Copyright (C) 2014 Vladimir Serbinenko
+ * Copyright (C) 2016 Nicola Corna <nicola at corna.info>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -21,6 +22,7 @@
#include <ec/acpi/ec.h>
#include <pc80/mc146818rtc.h>
#include <ec/lenovo/h8/h8.h>
+#include <ec/lenovo/h8/smm.h>
#include <delay.h>
#include <southbridge/intel/bd82x6x/nvs.h>
#include <southbridge/intel/bd82x6x/pch.h>
@@ -133,6 +135,8 @@ int mainboard_smi_apmc(u8 data)
void mainboard_smi_sleep(u8 slp_typ)
{
+ h8_usb_always_on();
+
if (slp_typ == 3) {
u8 ec_wake = ec_read(0x32);
/* If EC wake events are enabled, enable wake on EC WAKE GPE. */
More information about the coreboot-gerrit
mailing list