Exploring the Embedded Controller

I’m getting this error on FW 13 Intel 13th gen, is there any way to fix this? I couldn’t figure it out… Just FYI I’m on BIOS 3.05 (recently released)

❯ sudo ectool chargecontrol
ERROR: Old EC doesn't support GET.

  Usage: chargecontrol
    Get current settings.
  Usage: chargecontrol normal|idle|discharge
    Set charge mode (and disable battery sustainer).
  Usage: chargecontrol normal <lower> <upper>
    Enable battery sustainer. <lower> and <upper> are battery SoC
    between which EC tries to keep the battery level.

❯ sudo ectool chargecontrol normal 20 80
ERROR: Old EC doesn't support sustainer.

  Usage: chargecontrol
    Get current settings.
  Usage: chargecontrol normal|idle|discharge
    Set charge mode (and disable battery sustainer).
  Usage: chargecontrol normal <lower> <upper>
    Enable battery sustainer. <lower> and <upper> are battery SoC
    between which EC tries to keep the battery level.

I may be mistaken, but I think those commands are only functional on the AMD platform’s EC, which uses a new architecture.

1 Like

I just built mainline v6.10 and Dustin’s patches are already present -

commit c8f460d991df
Author: Dustin L. Howett <dustin@howett.net>
Date:   Tue Apr 2 19:47:13 2024 -0500

    platform/chrome: cros_ec_lpc: add quirks for the Framework Laptop (AMD)
    
    The original Framework Laptop 13 platform (Intel 11th, 12th, and 13th
    Generation at this time) uses a Microchip embedded controller in a
    standard configuration.
    
    The newer devices in this product line--Framework Laptop 13 and 16 (AMD
    Ryzen)--use a NPCX embedded controller. However, they deviate from the
    configuration of ChromeOS platforms built with the NPCX EC.
    
    * The MMIO region for EC memory begins at port 0xE00 rather than the
      expected 0x900.
    
    cros_ec_lpc's quirks system is used to address this issue.
    
    Signed-off-by: Dustin L. Howett <dustin@howett.net>
    Reviewed-by: Thomas Weißschuh <linux@weissschuh.net>
    Tested-by: Thomas Weißschuh <linux@weissschuh.net>
    Tested-by: Mario Limonciello <superm1@gmail.com>
    Link: https://lore.kernel.org/r/20240403004713.130365-5-dustin@howett.net
    Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>

M       drivers/platform/chrome/cros_ec_lpc.c
  • My FW 16 hibernates and recovers ok with power cable plugged in

  • But if I then unplug the power and use zoom-client (a snap in debian bookworm) to connect to a meeting it freezes for a about 3-5s then goes black screen and after a while reboots. Strangely the ectool console shows no sign of the reboot that I can see - https://paste.debian.net/1323605/

1 Like

I didn’t realize it had made it into 6.10. Thanks!

1 Like

@DHowett I could not find anything about the ectool. How would I install it?

You need to build it from the source code. [later: I was mistaken. Binaries are available. See @deLemere’s post under this one.] There are links to Dustin’s ectool web pages (for crude instructions) and his git repo in this thread. I’ve not actually built it myself (although I understand the process).

I’ve been following this thread for a couple of years. The tool’s capability, build process and compatibility gotchas are explored in a lot of detail. If you’re thinking of building it yourself, grab a beverage and start reading from the first post.

If you summarise your system (FW model, distro and kernel version) someone who’s built it for a similar system might be willing to help you avoid any of the bumps they found in the road.

Dino

edit: corrected a misunderstanding for future readers.

3 Likes

You can download here:

3 Likes

I apologize if this is already answered in this thread. I tried searching for “flash RW” or “write RW” and came up empty handed. I’d like to build a new version of the lotus EC and write it to my RW slot. My primary interest is fixing the bug where the CPU gets stuck throttled at low MHz after being plugged in and waking. Unfortunately, with the console commands disabled and the read to memmap only taking a single byte means I can’t get a read out of EC_MEMMAP_POWER_SLIDE (0x151). Same issue with enabling safety_pwr_logging since that requires a console command. I figure a custom build can log the right data for my debugging and allow me to hopefully figure out where the bug is that is getting me stuck in a throttled state (or at least allow me to send a command to unstick things).

Is there good documentation as to how to build a local branch and flash it to RW (plus how to get back when it inevitably goes wrong :slight_smile: ).

Btw, for anyone wanting to use Github search to find things, I forked the Framework/EmbeddedController repo and made a branch with the current lotus EC code as the default branch. That makes it so searching the repo in Github searches that branch instead of the hx20-hx30 branch. I made a new branch instead of using the lotus-zephyr because I didn’t realize that was already at the correct commit

Is it possible to make another key (eg caps lock) act as the fn key?

I was successfully able to map caps to other keys (like esc) but not fn.

Here’s what I tried so far:

  • get matrix position of caps and fn from fw matrix (4,4 and 2,2)
  • ask ectool what the scancode is for fn using these instructions (it’s apparently 00FF ie 255)
  • use the command ectool raw 0x3E0C d1,d1,b4,b4,w255 (found here) (the b4,b4 is the matrix position of caps and the w255 is scancode for fn)

It didn’t work. (My caps-lock key then made an equal sign and caused my touchpad to stop working.) Then after a bit of research I found out that the fn key probably doesn’t even have a scancode?

But I was given hope by this comment:

What am I missing?

One tiny mistake I made: it’s wFF not W255 … I don’t know why I assumed decimal number format.

So the actual command to remap the Caps-lock key to fn is:
ectool raw 0x3E0C d1,d1,b4,b4,w255
(and to reverse it: ectool raw 0x3E0C d1,d1,b4,b4,w58 back to normal)

3 Likes

in Fedora 41, kernel 6.11 the keyboard backlight brightness is exposed through /sys/class/leds/chromeos::kbd_backlight/brightness and can be changed with the command

echo 40 > /sys/class/leds/chromeos::kbd_backlight/brightness

This example will set the brightness of the keyboard backlight at 40%

It is also visible in and can be changed with Gnome settings.
Screenshot From 2024-11-08 12-35-16

But in contrast to my Thinkpad, no osd (on screen display indicator) appears when changing the keyboard backlight with the keyboard (fn + space). And, after changing the keyboard brightness with these keys, it does no longer correspond with Gnome settings.

Can someone tell me what is needed to fix this, how to enable the osd when changing the keyboard backlight with the fn+space keys.

Thanks a lot.

meijero

Unfortunately the EC does not emit notifications when the keys are pressed.
So the driver can not notify gnome.

Perhaps a potential solution is for the Gnome app to periodically poll the EC /sys/class/leds/... for the current state while the app is open. Maybe once per second.

I am not familiar with what is available in the EC API/ABI or Gnome programming but it may be a direction to investigate.

If you close and re-open the Gnome settings app does it show the current state as set by the keyboard input? That may show that the app looks at the settings when started. If it stays out of sync then it may indicate that the app sets but never looks at the state for the keyboard backlight.

However, the value in /sys/class/leds/chromeos::kbd_backlight/brightness
is changed when pressing fn+space. Can this change not be used to trigger a notification? Or is it perhaps possible to modify the EC firmware? (I am not a developer, I am only a Linux user.)

No. The kernel only reads this from the EC when triggered by userspace.
Gnome could/should reread it before evaluating its own hotkeys.
This will not fix the UI but make the gnome shortcuts usable.

1 Like

For my understanding, I use Linux only, but is there an osd in Windows when fn+space are pressed?

No idea, I only use Linux, too.

But I specifically looked for an notification mechanism in the EC and didn’t find anything.
So I doubt Windows can provide this.

The EC handling Fn+Space is a Framework specific addition to the EC. On real Chromebooks this seems to be all handled in the OS, so no notification is necessary in the first place.

I have a patch for this here (only for azalea/Ryzen 7040 series, but should be relatively easy to adapt): azalea: forward keyboard brightness hotkey to OS · leo60228/EmbeddedController@0053830 · GitHub

I considered sending a PR upstream, but decided that the OSD popup was not worth the regression in functionality when in the firmware menu/etc.

1 Like

The .most compatible mechanism would be a new key code that notifies the OS that something has changed and it can then reread the value from sysfs.