Take a look at our
ThinkPads.com HOME PAGE
For those who might want to contribute to the blog, start here: Editors Alley Topic
Then contact Bill with a Private Message

X210/X2100 embedded controller fixes (was: X210 EC datasheet/better brightness control)

Old(er) Thinkpads with New(er) Intestines: X62/T50/T70/X210/X330 etc.
Message
Author
vladisslav2011
Posts: 30
Joined: Fri Oct 12, 2018 6:33 am
Location: Velikiye Luki, Pskov, Russia

Re: X210 EC datasheet/better brightness control?

#31 Post by vladisslav2011 » Sun Jun 23, 2019 12:22 pm

verynice wrote:
Tue May 28, 2019 8:22 am
Can you share your kernel config and other powersave options?
As I can't manage to get less than 6.9 W
The kenel is almost stock ubuntu 5.0.0-16-generic installed from binary DEB package as shipped with ubuntu 18.04. It performs well enough, so I did not bother configuring and compiling custom kernel. The only modification is patched i915 driver (see later).
$ uname -a
Linux x210 5.0.0-16-generic #17~18.04.1-Ubuntu SMP Mon May 20 14:00:27 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

Command line, tlp config, little service to disable gpe spam from EC (I have not patched it yet), tlp is patched to reduce number of wakeups:

Code: Select all

$ cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-5.0.0-16-generic root=UUID=e4923acd-7930-4418-b6ea-af256a4e1b59 ro drm.vblankoffdelay=1 i915.enable_psr=1 r8168.aspm=1 r8168.eee_enable=1 r8168.hwoptimize=1 r8168.debug=0 i915.enable_guc=-1 ath9k.btcoex_enable=0 ath9k.ps_enable=1 ath9k.blink=1 ath9k.bt_ant_diversity=1 pti=off spectre_v2=off l1tf=off nospec_store_bypass_disable no_stf_barrier

$ grep -vE '^#' /etc/default/tlp |grep -vE '^$'
TLP_ENABLE=1
TLP_DEFAULT_MODE=AC
TLP_PERSISTENT_DEFAULT=0
DISK_IDLE_SECS_ON_AC=0
DISK_IDLE_SECS_ON_BAT=2
MAX_LOST_WORK_SECS_ON_AC=15
MAX_LOST_WORK_SECS_ON_BAT=60
CPU_SCALING_GOVERNOR_ON_AC=performance
CPU_SCALING_GOVERNOR_ON_BAT=powersave
CPU_HWP_ON_AC=performance
CPU_HWP_ON_BAT=power
CPU_BOOST_ON_AC=1
CPU_BOOST_ON_BAT=0
SCHED_POWERSAVE_ON_AC=0
SCHED_POWERSAVE_ON_BAT=1
NMI_WATCHDOG=0
ENERGY_PERF_POLICY_ON_AC=powersave
ENERGY_PERF_POLICY_ON_BAT=powersave
DISK_DEVICES="sda"
DISK_APM_LEVEL_ON_AC="1"
DISK_APM_LEVEL_ON_BAT="1"
SATA_LINKPWR_ON_AC="min_power"
SATA_LINKPWR_ON_BAT="min_power"
AHCI_RUNTIME_PM_ON_AC=auto
AHCI_RUNTIME_PM_ON_BAT=auto
AHCI_RUNTIME_PM_TIMEOUT=15
PCIE_ASPM_ON_AC=powersupersave
PCIE_ASPM_ON_BAT=powersupersave
RADEON_POWER_PROFILE_ON_AC=high
RADEON_POWER_PROFILE_ON_BAT=low
RADEON_DPM_STATE_ON_AC=performance
RADEON_DPM_STATE_ON_BAT=battery
RADEON_DPM_PERF_LEVEL_ON_AC=auto
RADEON_DPM_PERF_LEVEL_ON_BAT=auto
WIFI_PWR_ON_AC=on
WIFI_PWR_ON_BAT=on
WOL_DISABLE=N
SOUND_POWER_SAVE_ON_AC=1
SOUND_POWER_SAVE_ON_BAT=1
SOUND_POWER_SAVE_CONTROLLER=Y
BAY_POWEROFF_ON_AC=0
BAY_POWEROFF_ON_BAT=0
BAY_DEVICE="sr0"
RUNTIME_PM_ON_AC=on
RUNTIME_PM_ON_BAT=auto
USB_AUTOSUSPEND=1
USB_BLACKLIST="1d50:6089"
USB_BLACKLIST_BTUSB=0
USB_BLACKLIST_PHONE=0
USB_BLACKLIST_PRINTER=1
USB_BLACKLIST_WWAN=1
RESTORE_DEVICE_STATE_ON_STARTUP=0

$ cat /etc/systemd/system/acpi-int.service 
[Unit]
Description=Don't [censored] with interrupts
After=network.target
[Service]
ExecStart=/bin/bash -c 'echo mask >/sys/firmware/acpi/interrupts/gpe4F'
Type=oneshot
[Install]
WantedBy=multi-user.target

$ head -n 11 /usr/sbin/tlp
#!/bin/sh
# tlp - adjust power settings
#
# Copyright (c) 2018 Thomas Koch <linrunner at gmx.net>
# This software is licensed under the GPL v2 or later.

# --- Constants
readonly LIBDIR="/usr/share/tlp"
readonly LIBS="tlp-functions tlp-rf-func"

[ j"$1" = jauto -a -f /tmp/tlpst ] && diff /sys/class/power_supply/ADP0/online /tmp/tlpst >/dev/null && exit 0 || cat /sys/class/power_supply/ADP0/online >/tmp/tlpst

I'm using r8168 driver with aspm support. NetworkManager is required to maintain low power consumption after suspend/resume without reloading r8168 module.
I'm using Samsung SSD 970 EVO 500GB and no SATA HDD/SSD.
The LCD is 2880x1920 BOE NV126A1M-N52. It supports PSR, but timings (@60Hz refresh rate) are not supported by i915 driver. However force-enabling PSR works with this panel. The patch (cleaned up a bit by L29Ah) is here:

Code: Select all

diff --git a/drivers/gpu/drm/i915/intel_psr.c b/drivers/gpu/drm/i915/intel_psr.c
index 84a0fb981561..53c811241979 100644
--- a/drivers/gpu/drm/i915/intel_psr.c
+++ b/drivers/gpu/drm/i915/intel_psr.c
@@ -625,9 +625,8 @@ void intel_psr_compute_config(struct intel_dp *intel_dp,
 
 	if (intel_usecs_to_scanlines(adjusted_mode, psr_setup_time) >
 	    adjusted_mode->crtc_vtotal - adjusted_mode->crtc_vdisplay - 1) {
-		DRM_DEBUG_KMS("PSR condition failed: PSR setup time (%d us) too long\n",
+		DRM_DEBUG_KMS("PSR condition failed: PSR setup time (%d us) too long, proceeding anyway\n",
 			      psr_setup_time);
-		return;
 	}
 
 	crtc_state->has_psr = true;
This config allows to reach ~3W power consumption (minimal brightness and offline mode, reading PDFs).
https://i.imgur.com/WMAaenO.png https://i.imgur.com/OkPTVfZ.png

verynice
Posts: 41
Joined: Wed May 22, 2019 1:59 pm
Location: Moscow, Russia

Re: X210 EC datasheet/better brightness control?

#32 Post by verynice » Wed Jul 24, 2019 3:45 pm

Is there anyone who can be of help?
I need a rom file with me option disabled.
As far as i can understand, when I flashed https://github.com/harrykipper/x210
(either of those roms)
it had me option enabled, and my stock bios had it disabled.
Now I can't disable it in bios settings.
So, if anyone could provide a dump this would help me a lot.

L29Ah
Sophomore Member
Posts: 180
Joined: Fri Sep 06, 2013 2:25 pm
Location: Montenegro

Re: X210 EC datasheet/better brightness control?

#33 Post by L29Ah » Wed Jul 24, 2019 4:17 pm

verynice wrote:
Wed Jul 24, 2019 3:45 pm
Is there anyone who can be of help?
I need a rom file with me option disabled.
As far as i can understand, when I flashed https://github.com/harrykipper/x210
(either of those roms)
it had me option enabled, and my stock bios had it disabled.
Now I can't disable it in bios settings.
So, if anyone could provide a dump this would help me a lot.
Can't you just wipe your ME firmware for sure with me_cleaner?
51nb X210 with community EC mod, me_cleaner and recelled 99W*h battery; X230 with coreboot, me_cleaner and nitrocaster's FHD mod as a backup; R500 for guests; T60 just for the looks.

verynice
Posts: 41
Joined: Wed May 22, 2019 1:59 pm
Location: Moscow, Russia

Re: X210 EC datasheet/better brightness control?

#34 Post by verynice » Thu Jul 25, 2019 2:21 am

L29Ah wrote:
Wed Jul 24, 2019 4:17 pm
verynice wrote:
Wed Jul 24, 2019 3:45 pm
Is there anyone who can be of help?
I need a rom file with me option disabled.
As far as i can understand, when I flashed https://github.com/harrykipper/x210
(either of those roms)
it had me option enabled, and my stock bios had it disabled.
Now I can't disable it in bios settings.
So, if anyone could provide a dump this would help me a lot.
Can't you just wipe your ME firmware for sure with me_cleaner?
Short answer:NO.

Long answer:
I could and it's possible that this would remove
the preinit hang,
but it's a bad idea to remove ME in general.
ME inits the MRC cache and some other timings,
so this can induce some problems later.
I'd like to test the ME->off->on first

L29Ah
Sophomore Member
Posts: 180
Joined: Fri Sep 06, 2013 2:25 pm
Location: Montenegro

Re: X210 EC datasheet/better brightness control?

#35 Post by L29Ah » Thu Jul 25, 2019 7:26 am

verynice wrote:
Thu Jul 25, 2019 2:21 am
L29Ah wrote:
Wed Jul 24, 2019 4:17 pm


Can't you just wipe your ME firmware for sure with me_cleaner?
Short answer:NO.

Long answer:
I could and it's possible that this would remove
the preinit hang,
but it's a bad idea to remove ME in general.
ME inits the MRC cache and some other timings,
so this can induce some problems later.
I'd like to test the ME->off->on first
I think me_cleaner leaves the hardware init code in place on the modern MEs, no?
51nb X210 with community EC mod, me_cleaner and recelled 99W*h battery; X230 with coreboot, me_cleaner and nitrocaster's FHD mod as a backup; R500 for guests; T60 just for the looks.

mjg59
Posts: 40
Joined: Sat Aug 21, 2004 7:53 am

Re: X210 EC datasheet/better brightness control?

#36 Post by mjg59 » Sat Jul 27, 2019 4:07 pm

harryK wrote:
Sun Jun 16, 2019 7:29 am
Ok, the solution to the battery conundrum lies in the Linux kernel sources:

in drivers/acpi/battery.c
On Lenovo Thinkpad models from 2010 and 2011, the power unit switches between mWh and mAh depending on whether the system is running on battery or not. When mAh is the unit, most reported values are incorrect and need to be adjusted by 10000/design_voltage. Verified on x201, t410, 410s, and x220. Pre-2010 and 2012 models appear to always report in mWh and are thus unaffected (tested with t42, t61, t500, x200, x300, and x230). Also, in mid-2012 Lenovo issued a BIOS update for the 2011 models that fixes the issue (tested on x220 with a post-1.29 BIOS), but as of Nov. 2012, no such update is available for the 2010 models.
The EC of the X210 follows the same behaviour of 2010/2011 Thinkpads, but obviously the kernel code that fixes it only kicks in on actual Thinkpads. This is why we see skewed values on the X210. A quick rough patch that fixes everything is here:

https://github.com/harrykipper/x210/blo ... -fix.patch
I think there's actually an easier solution to this - ACPI allows the EC to report either mAH or mWH data to the host, and the figures the EC is providing look more like mWH, but the ACPI tables claim that it's mAH. I'll try fixing that up in the firmware ACPI code.

mjg59
Posts: 40
Joined: Sat Aug 21, 2004 7:53 am

Re: X210 EC datasheet/better brightness control?

#37 Post by mjg59 » Sat Jul 27, 2019 4:21 pm

Ok, https://github.com/mjg59/coreboot/commi ... d837051263 works for me - energy_full_design matches the expected value.

flyingfishfinger
Junior Member
Junior Member
Posts: 404
Joined: Sun Nov 18, 2012 5:42 pm
Location: San Francisco Bay Area

Re: X210 EC datasheet/better brightness control?

#38 Post by flyingfishfinger » Sun Jul 28, 2019 12:29 am

Nice!

Random q, why is this in the applesmc branch? For that matter, which branch have you merged harryk's latest changes into, as indicated in the other thread?

R

harryK
Sophomore Member
Posts: 172
Joined: Fri Jun 13, 2014 6:28 pm
Location: Glasgow, Scotland

Re: X210 EC datasheet/better brightness control?

#39 Post by harryK » Sun Jul 28, 2019 2:17 am

mjg59 wrote:
Sat Jul 27, 2019 4:21 pm
Ok, https://github.com/mjg59/coreboot/commi ... d837051263 works for me - energy_full_design matches the expected value.
Awesome! ACPI is definitely where the issue should be dealt with.
However I have a feeling that changing mah to mwh is not enough. Now power consumption appears to be underestimated. UPower reports energy-rate as low as 2.5W idle (2500000 in /sys/class/power_supply/BAT/power_now).

While I'd love to see such a low power consumption, that is unrealistic on this machine. And in fact the battery appears to be discharging at a much faster pace than reported...
With the previous acpi code and the kernel fix I was seeing 3.5/3.8W idle rates, more consistent with the actual discharge pace of the battery. Probably power_now still has to be treated as mAh? That changes when the power cord is attached, though...

mjg59
Posts: 40
Joined: Sat Aug 21, 2004 7:53 am

Re: X210 EC datasheet/better brightness control?

#40 Post by mjg59 » Sun Jul 28, 2019 12:16 pm

flyingfishfinger wrote:
Sun Jul 28, 2019 12:29 am
Nice!

Random q, why is this in the applesmc branch? For that matter, which branch have you merged harryk's latest changes into, as indicated in the other thread?

R
Oh, just because that's the one I'm running. It includes Harry's changes, but so does x210_test.

mjg59
Posts: 40
Joined: Sat Aug 21, 2004 7:53 am

Re: X210 EC datasheet/better brightness control?

#41 Post by mjg59 » Sun Jul 28, 2019 12:21 pm

harryK wrote:
Sun Jul 28, 2019 2:17 am
mjg59 wrote:
Sat Jul 27, 2019 4:21 pm
Ok, https://github.com/mjg59/coreboot/commi ... d837051263 works for me - energy_full_design matches the expected value.
Awesome! ACPI is definitely where the issue should be dealt with.
However I have a feeling that changing mah to mwh is not enough. Now power consumption appears to be underestimated. UPower reports energy-rate as low as 2.5W idle (2500000 in /sys/class/power_supply/BAT/power_now).

While I'd love to see such a low power consumption, that is unrealistic on this machine. And in fact the battery appears to be discharging at a much faster pace than reported...
With the previous acpi code and the kernel fix I was seeing 3.5/3.8W idle rates, more consistent with the actual discharge pace of the battery. Probably power_now still has to be treated as mAh? That changes when the power cord is attached, though...
Hm. Let me dig into that further - there's no way (in the spec) for something to report one variable in mA and one in mW. I'll try to figure out what the EC is actually doing here. The values being provided by the EC are definitely consistent across AC/battery power (there's no difference in the raw register value), so it's not behaving the way the original X201 EC did. Are you able to provide the output from ectool and the nominal design capacity (in mAH and WH) of your battery?

mjg59
Posts: 40
Joined: Sat Aug 21, 2004 7:53 am

Re: X210 EC datasheet/better brightness control?

#42 Post by mjg59 » Sun Jul 28, 2019 12:38 pm

Huh. Ok, the command the EC is sending is definitely the one to retrieve current, but… oh bother. Right. There are some commands that always return information in mA, and this is one. Other commands return something that depends on the unit set in the battery config. I'd bet that the battery is configured to return information in Watts, so all the other fields come back this way.

harryK
Sophomore Member
Posts: 172
Joined: Fri Jun 13, 2014 6:28 pm
Location: Glasgow, Scotland

Re: X210 EC datasheet/better brightness control?

#43 Post by harryK » Sun Jul 28, 2019 12:46 pm

If you still need the info, I'm using a 4 cell battery, rated 14.4V (the small battery has a higher voltage than the larger ones, that's why the discrepancies are more visible here). Design capacity is 2000 mAh / 28.8 Wh. Current full capacity is 1268 mAh / 18.2 Wh

ectool -d says the following when on AC (this is the modified EC by vladisslav2011)

Code: Select all

EC RAM:

00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
50: 2e b3 0d 04 49 90 00 00 00 00 00 00 00 00 02 00 
60: 40 0b 22 07 40 38 24 00 12 00 2a 01 26 06 bd 3e 
70: 41 38 43 00 00 00 65 00 00 00 00 00 00 00 00 00 
80: b3 b3 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
and this when on battery power

Code: Select all

00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
50: 2d b3 03 04 49 90 00 00 00 00 00 00 00 00 01 00 
60: 40 0b 22 07 40 38 24 00 12 00 c2 01 22 06 b6 3d 
70: 41 38 43 00 00 00 65 00 00 00 00 00 00 00 00 00 
80: b3 b3 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

mjg59
Posts: 40
Joined: Sat Aug 21, 2004 7:53 am

Re: X210 EC datasheet/better brightness control?

#44 Post by mjg59 » Sun Jul 28, 2019 1:04 pm

Ok, can you try with https://github.com/mjg59/coreboot/commi ... 9b6ab3e3f5 instead of the original patch? The values here look plausible to me, but the 14.4V is going to result in your power_now value going up a *lot* (your battery is actually reporting that it's discharging at 16.1V - I'd be interested to see whether the values seem more realistic multiplied by that or by the design voltage.

(Edited with corrected link)

harryK
Sophomore Member
Posts: 172
Joined: Fri Jun 13, 2014 6:28 pm
Location: Glasgow, Scotland

Re: X210 EC datasheet/better brightness control?

#45 Post by harryK » Sun Jul 28, 2019 1:09 pm

mjg59 wrote:
Sun Jul 28, 2019 1:04 pm
Ok, can you try with https://github.com/mjg59/coreboot/commi ... 9b6ab3e3f5 instead of the original patch? The values here look plausible to me, but the 14.4V is going to result in your power_now value going up a *lot* (your battery is actually reporting that it's discharging at 16.1V - I'd be interested to see whether the values seem more realistic multiplied by that or by the design voltage.

(Edited with corrected link)

I'll try in a minute. Voltage changes slightly quite frequently, don't know if that's normal or not. Now I see

/sys/class/power_supply/BAT/voltage_min_design
14400000
/sys/class/power_supply/BAT/voltage_now
15501000

harryK
Sophomore Member
Posts: 172
Joined: Fri Jun 13, 2014 6:28 pm
Location: Glasgow, Scotland

Re: X210 EC datasheet/better brightness control?

#46 Post by harryK » Sun Jul 28, 2019 2:03 pm

mjg59 wrote:
Sun Jul 28, 2019 1:04 pm
Ok, can you try with https://github.com/mjg59/coreboot/commi ... 9b6ab3e3f5 instead of the original patch? The values here look plausible to me, but the 14.4V is going to result in your power_now value going up a *lot* (your battery is actually reporting that it's discharging at 16.1V - I'd be interested to see whether the values seem more realistic multiplied by that or by the design voltage.

(Edited with corrected link)
Ok. power_now never went below 4W idle this time. Can't say which one is more realistic between this and what I see with the original battery.asl + kernel fix, as the difference isn't that huge. Wishful thinking wants me to prefer the latter.. :-D

power attached

Code: Select all

EC RAM:

00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
50: 2b b3 0d 04 49 90 00 00 00 00 00 00 00 00 02 00 
60: 40 0b 22 07 40 38 24 00 12 00 12 01 a6 05 06 3e 
70: 41 38 43 00 00 00 65 00 00 00 00 00 00 00 00 00 
80: b3 b3 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
power attached again

Code: Select all

EC RAM:

00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
50: 2a b3 0d 04 49 90 00 00 00 00 00 00 00 00 02 00 
60: 40 0b 22 07 40 38 24 00 12 00 80 07 ff 04 e5 40 
70: 41 38 43 00 00 00 65 00 00 00 00 00 00 00 00 00 
80: b3 b3 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
d0: 00 00 e5 00 00 00 00 00 00 00 00 00 00 00 00 00 
e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
batt:

Code: Select all

EC RAM:

00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
50: 27 b3 03 04 49 90 00 00 00 00 00 00 00 00 01 00 
60: 40 0b 22 07 40 38 24 00 12 00 52 01 65 05 b4 3c 
70: 41 38 43 00 00 00 65 00 00 00 00 00 00 00 00 00 
80: b3 b3 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
batt again:

Code: Select all

00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
50: 2a b3 03 04 49 90 00 00 00 00 00 00 00 00 01 00 
60: 40 0b 22 07 40 38 24 00 12 00 d2 02 11 05 9b 3b 
70: 41 38 43 00 00 00 65 00 00 00 00 00 00 00 00 00 
80: b3 b3 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

harryK
Sophomore Member
Posts: 172
Joined: Fri Jun 13, 2014 6:28 pm
Location: Glasgow, Scotland

Re: X210 EC datasheet/better brightness control?

#47 Post by harryK » Mon Jul 29, 2019 10:46 am

mjg59 wrote:
Sun Jul 28, 2019 1:04 pm
Ok, can you try with https://github.com/mjg59/coreboot/commi ... 9b6ab3e3f5 instead of the original patch? The values here look plausible to me, but the 14.4V is going to result in your power_now value going up a *lot* (your battery is actually reporting that it's discharging at 16.1V - I'd be interested to see whether the values seem more realistic multiplied by that or by the design voltage.

(Edited with corrected link)
I think I've nailed it :-D
https://github.com/mjg59/coreboot/commi ... t-34483711

mjg59
Posts: 40
Joined: Sat Aug 21, 2004 7:53 am

Re: X210 EC datasheet/better brightness control?

#48 Post by mjg59 » Mon Jul 29, 2019 1:39 pm

Hmm, I'm not sure - the value here is coming directly from the battery without being interpreted by the EC, so that would depend on the battery reporting broken units. Which certainly isn't impossible, but the numbers you're seeing with my patch are much closer to the numbers I see with a 9-cell battery, while your earlier numbers were somewhat smaller. I've got a smaller battery somewhere, I'll try that and see if things are consistent.

harryK
Sophomore Member
Posts: 172
Joined: Fri Jun 13, 2014 6:28 pm
Location: Glasgow, Scotland

Re: X210 EC datasheet/better brightness control?

#49 Post by harryK » Mon Jul 29, 2019 2:29 pm

mjg59 wrote:
Mon Jul 29, 2019 1:39 pm
Hmm, I'm not sure - the value here is coming directly from the battery without being interpreted by the EC, so that would depend on the battery reporting broken units. Which certainly isn't impossible, but the numbers you're seeing with my patch are much closer to the numbers I see with a 9-cell battery, while your earlier numbers were somewhat smaller. I've got a smaller battery somewhere, I'll try that and see if things are consistent.
Ehe, you're right. It was a load of crap. :-)

So far I see the more realistic numbers with the original battery.ast + the kernel fix.

Also, with your battery.ast acpi reports

Code: Select all

acpi -i 
Battery 0: design capacity 1922 mAh, last full capacity 1219 mAh = 63%
with the original battery.ast + kernel fix i have the correct value

Code: Select all

Battery 0: design capacity 2000 mAh, last full capacity 1268 mAh = 63%
without the fix:

Code: Select all

Battery 0: design capacity 2880 mAh, last full capacity 1826 mAh = 63%
You are right that the X210 ec doesn't change between mW and mA, contrary to what happened with the X201 ec, however the adjustment from the kernel fix only kicks in when the values are reported in mAh, so it corrects everything that comes from the X210 ec and all seems good.

mjg59
Posts: 40
Joined: Sat Aug 21, 2004 7:53 am

Re: X210 EC datasheet/better brightness control?

#50 Post by mjg59 » Tue Jul 30, 2019 5:08 pm

In non-battery news, I've managed to get the EC to send reports for other hotkeys - I'm still trying to figure out a couple of details to ensure it sends the correct ones, and I'm a touch delayed because I forgot to fix up the checksum before reflashing so now I need to dig out my dediprog.

mjg59
Posts: 40
Joined: Sat Aug 21, 2004 7:53 am

Re: X210 EC datasheet/better brightness control?

#51 Post by mjg59 » Tue Jul 30, 2019 5:09 pm

(Also it's really simple to get the other hotkeys to send stuff, so I have no idea why the original code doesn't…)

harryK
Sophomore Member
Posts: 172
Joined: Fri Jun 13, 2014 6:28 pm
Location: Glasgow, Scotland

Re: X210 EC datasheet/better brightness control?

#52 Post by harryK » Wed Jul 31, 2019 7:23 am

In the meantime I think I've fixed the battery (this time for real). See this https://github.com/harrykipper/coreboot ... 3f6de5bd95

In the end we don't get mWh, what we get is broken mAh (as documented in the kernel). Adjusting 'capacity', 'full charge capacity', 'capacity of warning' and 'battery remaining capacity' by 10000 / design_voltage as the kernel does we get the accurate capacities and power draw.

I get

Code: Select all

Battery 0: design capacity 2000 mAh, last full capacity 1256 mAh = 62% 
/sys/class/power_supply/BAT/charge_full_design  
2000000

and all the other values are correct.

flyingfishfinger
Junior Member
Junior Member
Posts: 404
Joined: Sun Nov 18, 2012 5:42 pm
Location: San Francisco Bay Area

Re: X210 EC datasheet/better brightness control?

#53 Post by flyingfishfinger » Wed Jul 31, 2019 10:38 am

Since these changes for battery stuff are being made in the EC, would they affect Windows battery reporting?

R

harryK
Sophomore Member
Posts: 172
Joined: Fri Jun 13, 2014 6:28 pm
Location: Glasgow, Scotland

Re: X210 EC datasheet/better brightness control?

#54 Post by harryK » Wed Jul 31, 2019 10:47 am

flyingfishfinger wrote:
Wed Jul 31, 2019 10:38 am
Since these changes for battery stuff are being made in the EC, would they affect Windows battery reporting?

R
These changes are being made in coreboot, so they would affect Windows only if it was running under coreboot, not the stock bios. But I guess this type of stuff could also be implemented one level up, into the EC.

flyingfishfinger
Junior Member
Junior Member
Posts: 404
Joined: Sun Nov 18, 2012 5:42 pm
Location: San Francisco Bay Area

Re: X210 EC datasheet/better brightness control?

#55 Post by flyingfishfinger » Wed Jul 31, 2019 11:04 am

Right, of course. My bad.

I got thrown off by Matthew's last post about the hotkeys in the EC and that we're not actually in the coreboot thread.

I plan to run Ubuntu / Win 10 dual boot on coreboot, so I'm curious what the effects would be

R

verynice
Posts: 41
Joined: Wed May 22, 2019 1:59 pm
Location: Moscow, Russia

Re: X210 EC datasheet/better brightness control?

#56 Post by verynice » Wed Jul 31, 2019 12:45 pm

flyingfishfinger wrote:
Wed Jul 31, 2019 11:04 am
Right, of course. My bad.

I got thrown off by Matthew's last post about the hotkeys in the EC and that we're not actually in the coreboot thread.

I plan to run Ubuntu / Win 10 dual boot on coreboot, so I'm curious what the effects would be

R
One remark, I haven't been able to boot W10 with TianoCore payload. I only got W10 working with SeaBIOS.
So, if you can, try SeaBIOS first.

flyingfishfinger
Junior Member
Junior Member
Posts: 404
Joined: Sun Nov 18, 2012 5:42 pm
Location: San Francisco Bay Area

Re: X210 EC datasheet/better brightness control?

#57 Post by flyingfishfinger » Wed Jul 31, 2019 1:03 pm

verynice wrote:
Wed Jul 31, 2019 12:45 pm
One remark, I haven't been able to boot W10 with TianoCore payload. I only got W10 working with SeaBIOS.
So, if you can, try SeaBIOS first.
That's the plan, AFAIK SeaBIOS is also the only way to select and execute multiple payloads. Although that does seem a very roundabout way to boot Linux.

I'm guessing that also implies I'd have to reinstall my Win10 in BIOS mode, I currently have a UEFI installation...

R

xytech
Posts: 31
Joined: Tue Jun 11, 2019 4:17 am
Location: Singapore

Re: X210 EC datasheet/better brightness control?

#58 Post by xytech » Thu Aug 01, 2019 5:08 am

mjg59 wrote:(Also it's really simple to get the other hotkeys to send stuff, so I have no idea why the original code doesn't…)
I could be pulling nothing out of thin air, but during the short interaction I had with the company doing the design, they don't seem to be the best at writing software. They're great at designing the circuits and motherboard though. I could also be wrong and it could actually be Hope who designed and written part of the board and firmware.

Sent from my SM-G965F using Tapatalk


L29Ah
Sophomore Member
Posts: 180
Joined: Fri Sep 06, 2013 2:25 pm
Location: Montenegro

Re: X210 EC datasheet/better brightness control?

#59 Post by L29Ah » Mon Aug 05, 2019 11:09 pm

xytech wrote:
Thu Aug 01, 2019 5:08 am
They're great at designing the circuits and motherboard though.
I can't call a diode on the battery power input and the lack of the keyboard drain hole on the MB great.
51nb X210 with community EC mod, me_cleaner and recelled 99W*h battery; X230 with coreboot, me_cleaner and nitrocaster's FHD mod as a backup; R500 for guests; T60 just for the looks.

vladisslav2011
Posts: 30
Joined: Fri Oct 12, 2018 6:33 am
Location: Velikiye Luki, Pskov, Russia

Re: X210 EC datasheet/better brightness control?

#60 Post by vladisslav2011 » Sun Sep 01, 2019 3:24 pm

L29Ah wrote:
Mon Aug 05, 2019 11:09 pm
I can't call a diode on the battery power input...great.
What diode are people talking about. There should not be any diodes in the battery discharge path. If it will be here, then it should be 10A rated and have a heatsink as the laptop drains about 6-7A when CPU is at full turbo, full brightness, hdd and 2 SSD's busy. And with USB devices attached it can drain even more. I don't see anything like such large diode at the PCB...
There may be some little diode (like 1n4148), that is used to power the charger IC when on battery. That's normal. Many laptops have such diodes according to chargers datasheets.

And some good news to everyone (some "not so good" news too):
I have looked at the EC firmware one more time and got interesting results
1. (bugfix) Correct reporting of battery charging status: charged when on AC and current is zero
2. (bugfix) Correct battery charge reporting: always report actual charge
3. (improvement) GPE spam removed. Emit "battery changed" acpi event only when battery is changed (stopped/started charge, stopped started discharge, battery inserted/removed)
4. (improvement) Never emit acpi "temperature changed" event as it does not look like anything uses it so far. The fan PWM is controlled by EC itself, so the fan is still operating correctly.
5. (improvement) Increase backlight PWM frequency to ~920 Hz. Should be enough for everyone.
6. (improvement) Enable thinkvantage button
7. (bugfix) EC debugging through PM interface is now working.
8. (bugfix) Use correct keycodes for "7" and "Enter" keys, so blender is now usable with internal keyboard.
9. (bugfix) Prevent fan from rotating at full speed at low temperature for short periods of time.
10. (patch) ec_sys driver patch to access the EC RAM and GPIO through debugfs.
11. Some keyboard controller (messy) and gpio (incomplete) documentation created.
12. EC boot ROM added to Ghidra project
http://wdfiles.ru/eq21
http://wdfiles.ru/eq22
http://wdfiles.ru/eq1J
https://pastebin.com/rFD8vReJ
https://pastebin.com/J8F0yeue

It is possible to patch the EC firmware online. Full CR16 memory space is available through /sys/kernel/debug/ec/ec0/ram.
To chage keyboard mapping find memory location via spreadsheet, read it to verify (!), then write desired value.
For example, to assign some key to Fn+F2 combination find location at Fn keys sheet (0x29F3A), read it

Code: Select all

# dd if=/sys/kernel/debug/ec/ec0/ram bs=1 count=1 skip=$[0x29F3A] 2>/dev/null|hexdump -C
00000000  00                                                |.|
00000001
And assign a code from "set 2 ref" or "specials" sheets. Assign WWW-search key for example

Code: Select all

# echo -ne "\x38" |dd of=/sys/kernel/debug/ec/ec0/ram bs=1 count=1 seek=$[0x29F3A]
It should be possible to swap Ctrl and FN too by swapping values at 0x00029eae and 0x00021e3a, but I have not tested it
Changes will survive reboot and even power off when connected to AC. To make the EC boot from SPI flash, power the laptop off, disconnect AC adapter and wait about 15 seconds. The battery may be left connected.

Current GPIO state may be queried via /sys/kernel/debug/ec/ec0/gpio.
To drive GPO low, write GPIO number to /sys/kernel/debug/ec/ec0/gpio in binary:
Turn thinkllight off

Code: Select all

echo -ne "\x47" >/sys/kernel/debug/ec/ec0/gpio
To drive GPO high, or it's number with 0x08 and write resulting number to /sys/kernel/debug/ec/ec0/gpio in binary:
Turn thinkllight on

Code: Select all

echo -ne "\x4f" >/sys/kernel/debug/ec/ec0/gpio
WARNING: Writing arbitrary values to EC RAM and messing with EC GPIOs may damage your laptop. Althrough chips should survive drive contention, it is still possible to make them latch by turning power supplies in wrong order. Latched up chips will heat to critical temperature quickly and will draw excessive currents exceeding absolute maximum ratings. Think twice before writing anything to EC RAM/GPIOs.

And some bad news:
1. UART Sin pin is used to switch touchpad power, so no interactive debugging via UART, only debug messages.
2. I have not figured out, which GPIO controls the LCD's power line (+3.3V). Maybe it is tied directly to +3.3V power plane without dedicated switch. So, it is not possible to cut power consumption by 1.6W when the display is in DPMS Off state.

Update:
I've tried swapping FN and Ctrl and found a bug. Swapped Ctrl did not flush scancode buffer until another key was pressed, and sometimes sticks in pressed state. And Ctrl+wheel was not possible too.
Fixed via nasty hack (jumping from one function to another. More spaghetti!)
Links to Ghidra project and patched binary updated.

Bugs to fix:
Trackpoint event noise on resume which prevents USB/Bluetooth mice from working correctly after resume.

Post Reply
  • Similar Topics
    Replies
    Views
    Last post

Return to “51nb and other modded Thinkpads”

Who is online

Users browsing this forum: No registered users and 43 guests