[SOLVED W/PATCHES] Fan support for RK3399 rockpro64

  • [EDIT: PATCHES TO FIX THIS ARE BELOW]



    Hello,


    Just burned libreelec-rk3399.arm-9.0-nightly-20190201-974f4cb-rockpro64.img.gz

    And it's perfect.

    I just can't get my 2-pin PWM fan enabled.


    ayufan's debian had a sys class object 'hwmon0' which I could echo '255' into and start the fan, but no such device tree object has been initialized in this build.


    I don't have the appropriate cables to re-wire my fan from being a 2-pin molex fan header in order to stick it into the GPIO header.


    Can someone add hwmon0 or any possible way to control PWM fan on the 2-pin fan header to the image?


    I wouldn't even mind building my own image if I have to, but I need to be shown how that works, I guess.

    Edited once, last by fosf0r ().

  • Ok, I even setup the build system and compiled my own working image from scratch.

    But I am having a really hard time getting a pwm-fan entry to work; I think I am not doing the syntax right.


    Can someone provide a diff to rk3399-rockpro64.dts that sets up pwm-fan properly ?


    I thought it would just be like:

    Code
    1. fan0: pwm-fan {
    2. compatible = "pwm-fan";
    3. cooling-min-state = <0>;
    4. cooling-max-state = <3>;
    5. #cooling-cells = <2>;
    6. pwms = <&pwm1 0 10000 0>;
    7. cooling-levels = <0 102 170 230>;
    8. };

    But I get syntax errors while parsing the tree, when it tries to compile it to dtb.

  • I'm no device tree expert but...

    I've been playing with the Temps and Fan control on my RK3399 ODROID N1, here is what I have extra in the .dts


    You will need a patch like linux-0009-pwn-fan-enable-rk339-rockpro64.patch and save into this directory:


    LibreELEC.tv/projects/Rockchip/patches/linux/rockchip-4.4/


    hastebin


    I also changed the Kernel config:

    LibreELEC.tv/projects/Rockchip/devices/RK3399/linux/rockchip-4.4/linux.aarch64.conf

    Change the Thermal section to:


    hastebin


    This also has to be enabled:

    Code
    1. # CONFIG_PMBUS is not set
    2. CONFIG_SENSORS_PWM_FAN=y
    3. # CONFIG_SENSORS_SHT15 is not set


    Issues I'm facing is the Fan run's 24/7 even with extra Hardkernel device tree trip points & cooling maps in the rk3399.dtsi

    I do get an nice cool SoC tho idling at 32 C


    More research & tweaking needs to be done.





    Other info for reference:

    rockchip-thermal.txt


    RK_VIRTUAL_THERMAL


    is needed in the Kernel config if you do NOT have a TSADC (rk3399's do have a TSADC)


    https://github.com/rockchip-linux/kernel/blob/release-4.4/drivers/thermal/kconfig#l215

  • Thanks for your help, I got it working.

    Mainly I was missing: CONFIG_SENSORS_PWM_FAN=y


    Then I also had to patch pwm-fan.c because it was unable to compile.

    I downloaded the patched pwm-fan.c from this:

    UPSTREAM: hwmon: pwm-fan: Use pwm_get_args() where appropriate · ayufan-rock64/[email protected] · GitHub

    Then I diff'd it against the one included with LibreELEC and made a .patch and that made it compile + work properly.


    I will be making some patches to submit soon.

  • Ah yes that pwm-get_args patch - forgot I had that one as well - already.


    HINT: if you put .patch after the commit Hash - Github with auto generate a patch for you... for quick testing.

    eg from the above link....


    356102c69b4ec19058847147f790cac0b3406fd9.patch


    Also works for GitHub Pull Requests containing multiple commits...

    eg:


    3288.patch



    Managed finally to get the Trip points & Cooling back into the actual N1 device tree and successfully compiling now.


    There is this interesting thread:


    Eliminating the crazy (fan) chirp


    And you can play around with the Fan with this patch:


    hastebin




    I'm also testing Overclocking a RK3399 N1:


    Exploring CPU Voltage & undervolting


    hastebin

  • At full load, my system runs at 101 F / roughly 38.3 C

    n i c e


    Here are the necessary 4 things get pwm-fan for rk3399-rockpro64.


    EDIT: You have to have already setup the build system per the wiki:

    Compile [LibreELEC.wiki]

    These edits are to be done to your build system (not from within LibreELEC).


    (A)

    1. nano ~/LibreELEC.tv/projects/Rockchip/devices/RK3399/linux/rockchip-4.4/linux.aarch64.conf
    2. Add this line: CONFIG_SENSORS_PWM_FAN=y


    (B)

    Create file: ~/LibreELEC.tv/projects/Rockchip/patches/linux/rockchip-4.4/linux-8000-rockpro64-pwm-fan.patch


    (C)

    Create file: ~/LibreELEC.tv/projects/Rockchip/patches/linux/rockchip-4.4/linux-8001-rockpro64-fan0.patch


    (D)

    Now you have to activate the fan.

    I didn't use thermal maps in the DTS (do it yourself) or anything smart/automated, because I just wanted my fan running 100% of the time, so I do the following in LibreELEC's autostart.sh :

    Code
    1. echo 255 > /sys/class/hwmon/hwmon0/pwm1

    Edited 3 times, last by fosf0r: (Setup cooling-levels to be real PWM duty cycles, 0%, 50%, 75%, 100% ().

  • fosf0r

    Changed the title of the thread from “Fan support for RK3399 rockpro64” to “[SOLVED W/PATCHES] Fan support for RK3399 rockpro64”.
  • Could someone from the LE team push the pwm-fan.c fix upstream and enable pwm sensors by default in the kernel options going forward, etc ?

  • Hi fosf0r

    "(A)

    1. nano ~ / LibreELEC.tv / projeler / Rockchip / cihazlar / RK3399 / linux / rockchip-4.4 / linux.aarch64.conf [/ tt] "

    I am getting such an error: [ Directory '/storage/LibreELEC.tv/projects/Rockchip/devices/RK3399/linux/rockchip-4.4' does not exist ]

  • So sorry, I wasn't very clear.


    The fixes have to be done to the build system outside of LibreELEC (not within LibreELEC), which you can setup by following the guide on the wiki:
    Compile [LibreELEC.wiki]


    Once you have "~/LibreELEC.tv" folder on your build system, then you will make the changes above.

  • I did it with SSH Console and got this error.

    My 10-day experience in Linux is not enough to make these arrangements. (I haven't used Linux before)

    I am trying to understand English writings with google translate.

    Result: I'll wait for a compilation of fan running.

    Thanks for your answer and your help.

  • Yes, building LibreELEC is an "intermediate" task.

    It is not easy when you are still new to Linux.


    I am new to GitHub, and new to contributing patches, so I don't know how to submit patches yet, but I will learn soon.


    I will eventually try to submit the patch, but I need to clean it up and integrate it with LibreELEC's existing patches.

    ( I'm pretty sure that I have to integrate the DTS bits directly into LibreELEC.tv/projects/Rockchip/patches/linux/rockchip-4.4/linux-0005-dts.patch )


    I'll update this thread with the results if I am able to get the patch submitted.

  • Hello fosf0r, thank you for the patches you posted. I am having difficulty with my build after adding them. I get the following error when I attempt to run the make image command:

    Code
    1. APPLY PATCH (project - rockchip-4.4) projects/Rockchip/patches/linux/rockchip-4.4/linux-8000-rockpro64-pwm-fan.patch
    2. patching file drivers/hwmon/pwm-fan.c
    3. Hunk #1 FAILED at 40.
    4. Hunk #2 FAILED at 215.
    5. Hunk #3 FAILED at 233.
    6. Hunk #4 FAILED at 303.
    7. 4 out of 4 hunks FAILED -- saving rejects to file drivers/hwmon/pwm-fan.c.rej
    8. FAILURE: scripts/build linux:host has failed!
    9. [063/247] [FAIL] build linux:host


    I have attached the full stderr and stdout logs for the failed thread referenced in my build error for further information.


    Any suggestions or information would be greatly appreciated.

    Files

    • stderr.txt

      (279 Byte, downloaded 29 times, last: )
    • stdout.txt

      (20.9 kB, downloaded 30 times, last: )
  • Oh, is it at a different branch now?

    I was using 9.0-devel, now I see yours says 9.1-devel.


    Either, build using:

    Release 9.0.0: Merge pull request #3280 from MilhouseVH/le90_settings_pr120 · LibreELEC/LibreELEC.tv · GitHub


    Or, someone has to look at pwm-fan.c vs the diff and see why it's not applying (maybe someone upstreamed the fix already and my patch is now redundant?)


    It will be a while before I have a chance to rebuild my ELEC kit so I'm not going to be able to fix that patch myself yet.

  • Ok, I was able to get to it faster than I thought.


    I cloned 9.1-dev, then added the two patch files, and it worked without any changes.

    Perhaps your patch files contain extra characters or linefeed/carriage return symbols from when you copied it.


    I have attached the patches as actual files.

    But this board wouldn't let me keep the extension as .patch, so you probably should rename these to .patch


    ( I was able to build the entire image, but I can't test it at all yet. I presume it works, don't see why it wouldn't. )


    linux-8000-pwm-fan.txt

    linux-8001-dts-pwm.txt

  • how do I install this patch, can you help?

  • Until the patch is upstreamed, you will have to make your own build system and add it.


    Read all of this before beginning:

    https://libreelec.wiki/compile


    1) Install Ubuntu 16.04.x (LTS) server


    Do everything from here on out as non-root.


    2) sudo apt update && sudo apt upgrade


    3) sudo apt install gcc make git unzip wget xz-utils


    4) Clone the LibreELEC github:

    Code
    1. cd ~
    2. git clone https://github.com/LibreELEC/LibreELEC.tv.git
    3. cd ~/LibreELEC.tv


    5) Build the whole system once, without my patches, to make sure your build system is working:

    Code
    1. PROJECT=Rockchip DEVICE=RK3399 ARCH=arm UBOOT_SYSTEM=rockpro64 make image


    6) Download and copy the two patch files into ~/LibreELEC.tv/projects/Rockchip/patches/linux/rockchip-4.4/

    * linux-8000-pwm-fan.txt

    * linux-8001-dts-pwm.txt


    7) Build it again now that the patch files are in:

    Code
    1. PROJECT=Rockchip DEVICE=RK3399 ARCH=arm UBOOT_SYSTEM=rockpro64 scripts/clean linux
    2. PROJECT=Rockchip DEVICE=RK3399 ARCH=arm UBOOT_SYSTEM=rockpro64 make image