Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing to Embedded Controller registers in Ubuntu 14.04

Tags:

linux

I have been trying to adjust the fan speed of my laptop, which I can achieve in Windows by setting the address 20 (0x14) of the EC to a value between 28 (0x1C) and 41 (0x29)

(I derive these numbers from this file: https://github.com/hirschmann/nbfc/blob/master/Configs/HP%20ENVY%20m6%20Sleekbook.xml)

When I do it in Windows it works correctly. So I'm trying to replicate it in Ubuntu 14.04. Below is what I tried:

  1. First of all I probed the ec_sys module by writing sudo modprobe ec_sys write_support=1 which made /sys/kernel/debug/ec/ec0/io available. It turns out that if I omit write_support=1 I receive a "Permission denied" error in the next step.
  2. I tried to run printf '\x1C' | sudo dd of="/sys/kernel/debug/ec/ec0/io" bs=1 seek=20 count=1 conv=notrunc so that I can write 0x1c (28) to the address 20 (0x14) of the EC and adjust the fan speed.
  3. I check if the aforementioned register is updated by typing sudo od -t x1 /sys/kernel/debug/ec/ec0/io, which then outputs:

    0000000 00 00 00 00 00 01 50 04 00 00 ff 10 00 33 13 05 0000020 00 19 24 19 1c 00 ff ff ff ff ff ff 00 00 00 00 ...

Now, it may appear that I was capable of updating the register, but it does not affect the fan speed. Furthermore, when I tried to write 41 (0x29) to the very same address later on, it did not change the value.

The config file (for which I provided a link above) says that the read register for fan speed is on the address 17 (0x11) so I'd expect that the contents of these two addresses to be the same (which was the case in Windows). However I observe that address 17 has the same value with address 19 instead. When I attempted at writing on that address, I could not make any changes. I am super confused.

like image 904
kubuzetto Avatar asked Apr 03 '15 22:04

kubuzetto


1 Answers

I edited the code above to make it more readable. I also removed the lm-sensors bit, making it manually assign the fan speed. Essentially this is what the code above does.

Note that I did not test the version below. My Envy m6 laptop died years ago (good riddance).

# Run as root
    
modprobe -r ec_sys
modprobe ec_sys write_support=1
    
# Path
ECIO_PATH=/sys/kernel/debug/ec/ec0/io
    
# Register offsets
ENABLE_WR=15
FAN_SPEED=20
    
# Values
WRITE_ENABLED="\015"
LOWEST_SPEED="\031"
HIGHEST_SPEED="\051"
    
# Define a function to write to EC
write_to_ec () {
    echo -n -e $2 | dd of=$ECIO_PATH bs=1 seek=$1 count=1 conv=notrunc
}
    
# Enable fan control
write_to_ec $ENABLE_WR $WRITE_ENABLED
    
# Adjust fan speed
write_to_ec $FAN_SPEED $HIGHEST_SPEED
like image 148
kubuzetto Avatar answered Oct 23 '22 18:10

kubuzetto