[BPI-R4] CPU fan setup

Thank you. Looking forward to my fan working

Last question(I hope). I downloaded your source. Thanks for that. When I try to build it attempts to redownload package files, which I’m assuming will overwrite your patched files. Anyway to prevent this?

It should not download any files that already exists in the dl folder, except if it is a newer version, or if it is missing.

All you have to do is:

Download the source code and extract it

./scripts/feeds update -a

./scripts/feeds install -a

Either use my defconfig (save it as .config) or use make menuconfig

make -j$(nproc)

Do NOT use make distclean, as it will delete the dl folder!

That’s what I was doing, it was trying to update arm-trusted-firmware. I thought I had to prevent that because that’s where your patch was(earlier you mentioned to edit files in the dl folder and patch so I thought you had patched that file). Building now. Thank you.

You are awesome. Fan is spinning perfectly. before it was staying around 60C, now right around 42C

1 Like

Yes, this worked well for me - steps to repro my results:

git clone https://git.openwrt.org/openwrt/openwrt.git
cd openwrt/

./scripts/feeds update -a
./scripts/feeds install -a

curl "https://downloads.openwrt.org/snapshots/targets/mediatek/filogic/config.buildinfo" > .config
make menuconfig # only changed: `Target Profile: Bananapi BPi-R4`
make defconfig

make -j $(nproc) toolchain/{clean,install}
### Executed in   34.42 mins

printf '
&fan {
\tpwms = <&pwm 0 50000 0>;
\tstatus = "okay";
};

&pwm {
\t//pinctrl-names = "default";
\t//pinctrl-0 = <&pwm_pins>;
\tstatus = "okay";
};
' >> target/linux/mediatek/files-6.1/arch/arm64/boot/dts/mediatek/mt7988a-bananapi-bpi-r4.dts

printf '--- build_dir/target-aarch64_cortex-a53_musl/linux-mediatek_filogic/linux-6.1.82/drivers/pwm/pwm-mediatek.c\t2024-03-25 17:50:57.303847248 -0700
+++ build_dir/target-aarch64_cortex-a53_musl/linux-mediatek_filogic/linux-6.1.82/drivers/pwm/pwm-mediatek.c\t2024-03-25 17:54:04.349927891 -0700
@@ -60,7 +60,7 @@
 };
 
 static const unsigned int pwm_mediatek_reg_offset[] = {
-\t0x0010, 0x0050, 0x0090, 0x00d0, 0x0110, 0x0150, 0x0190, 0x0220
+\t0x0080, 0x00c0, 0x0100, 0x0140, 0x0180, 0x01c0, 0x0200, 0x0240
 };
 
 static inline struct pwm_mediatek_chip *
@@ -281,77 +281,14 @@
 \treturn 0;
 }
 
-static const struct pwm_mediatek_of_data mt2712_pwm_data = {
+static const struct pwm_mediatek_of_data mt7988_pwm_data = {
 \t.num_pwms = 8,
 \t.pwm45_fixup = false,
 \t.has_ck_26m_sel = false,
 };
 
-static const struct pwm_mediatek_of_data mt6795_pwm_data = {
-\t.num_pwms = 7,
-\t.pwm45_fixup = false,
-\t.has_ck_26m_sel = false,
-};
-
-static const struct pwm_mediatek_of_data mt7622_pwm_data = {
-\t.num_pwms = 6,
-\t.pwm45_fixup = false,
-\t.has_ck_26m_sel = true,
-};
-
-static const struct pwm_mediatek_of_data mt7623_pwm_data = {
-\t.num_pwms = 5,
-\t.pwm45_fixup = true,
-\t.has_ck_26m_sel = false,
-};
-
-static const struct pwm_mediatek_of_data mt7628_pwm_data = {
-\t.num_pwms = 4,
-\t.pwm45_fixup = true,
-\t.has_ck_26m_sel = false,
-};
-
-static const struct pwm_mediatek_of_data mt7629_pwm_data = {
-\t.num_pwms = 1,
-\t.pwm45_fixup = false,
-\t.has_ck_26m_sel = false,
-};
-
-static const struct pwm_mediatek_of_data mt8183_pwm_data = {
-\t.num_pwms = 4,
-\t.pwm45_fixup = false,
-\t.has_ck_26m_sel = true,
-};
-
-static const struct pwm_mediatek_of_data mt8365_pwm_data = {
-\t.num_pwms = 3,
-\t.pwm45_fixup = false,
-\t.has_ck_26m_sel = true,
-};
-
-static const struct pwm_mediatek_of_data mt7986_pwm_data = {
-\t.num_pwms = 2,
-\t.pwm45_fixup = false,
-\t.has_ck_26m_sel = true,
-};
-
-static const struct pwm_mediatek_of_data mt8516_pwm_data = {
-\t.num_pwms = 5,
-\t.pwm45_fixup = false,
-\t.has_ck_26m_sel = true,
-};
-
 static const struct of_device_id pwm_mediatek_of_match[] = {
-\t{ .compatible = "mediatek,mt2712-pwm", .data = &mt2712_pwm_data },
-\t{ .compatible = "mediatek,mt6795-pwm", .data = &mt6795_pwm_data },
-\t{ .compatible = "mediatek,mt7622-pwm", .data = &mt7622_pwm_data },
-\t{ .compatible = "mediatek,mt7623-pwm", .data = &mt7623_pwm_data },
-\t{ .compatible = "mediatek,mt7628-pwm", .data = &mt7628_pwm_data },
-\t{ .compatible = "mediatek,mt7629-pwm", .data = &mt7629_pwm_data },
-\t{ .compatible = "mediatek,mt7986-pwm", .data = &mt7986_pwm_data },
-\t{ .compatible = "mediatek,mt8183-pwm", .data = &mt8183_pwm_data },
-\t{ .compatible = "mediatek,mt8365-pwm", .data = &mt8365_pwm_data },
-\t{ .compatible = "mediatek,mt8516-pwm", .data = &mt8516_pwm_data },
+\t{ .compatible = "mediatek,mt7988-pwm", .data = &mt7988_pwm_data },
 \t{ },
 };
 MODULE_DEVICE_TABLE(of, pwm_mediatek_of_match);
' > /tmp/pwm-mediatek.c.patch

make -j $(nproc) target/linux/{prereq,clean,download,prepare}
patch build_dir/target-aarch64_cortex-a53_musl/linux-mediatek_filogic/linux-6.1.82/drivers/pwm/pwm-mediatek.c < /tmp/pwm-mediatek.c.patch
make -j $(nproc) target/linux/compile
### Executed in  342.24 secs

# ensure `.vermagic` value matches, so `opkg` works with snapshot packages:
find build_dir/ -name .vermagic -exec cat {} \;
curl -s "https://downloads.openwrt.org/snapshots/targets/mediatek/filogic/openwrt-mediatek-filogic.manifest" \
    | sed -n 's/^kernel - .\+\(-\|~\)\([a-f0-9]\+\)\(-r[0-9]\+\)\?$/\2/p'

# customize package selection in resultant image (default packages can be retrieved from https://firmware-selector.openwrt.org/?version=SNAPSHOT&target=mediatek%2Ffilogic&id=bananapi_bpi-r4 ):
printf '
CONFIG_PACKAGE_...=y
' >> .config

make defconfig

# save customized `.config` for later builds:
./scripts/diffconfig.sh | awk '!seen[$0]++' > diffconfig
mv diffconfig .config

# customize files:
mkdir -p files/
#...

# customize first run image configuration:
printf $'#!/bin/sh

# fill in with `uci set ...` values from `uci show`

' > files/etc/uci-defaults/99-custom
chmod 0644 files/etc/uci-defaults/99-custom

# expand config:
make defconfig

# download stage:
make -j $(nproc) download
### Executed in   36.62 secs

# build:
make -j $(nproc) world
### Executed in  664.17 secs

Fan is working well - thanks, @Hypnotize

1 Like

With these changes applied, 2x SFP DAC cables @ 10gbit, bonded using 802.3ad, a Quectel RM510Q-GL, and an AsiaRF AW7916-AED serving @ 6GHz + 2.4GHz: cat /sys/class/thermal/thermal_zone0/temp:

49822

Was easily into the 70+C range previously (and more when using SFP+ 10gbit modules; DAC helps a lot there though)

Several users have asked me in dm’s on IRC if I can make a cleaned up image without UPNP, QoS and all of the unnecessary serial drivers, so here it is, if anyone here wants it too: :slight_smile:

openwrt-mediatek-filogic-bananapi_bpi-r4-r25683-d4a40827ba-sdcard.img.gz

2 Likes

Has anyone submitted a PR to the OpenWRT repo for this change yet? Would be nice if we didn’t need a forked/custom-patched version for the fan to work.

I don’t think they will approve the pwm-mediatek.c patch, since it removes support for all the other mediatek PWM devices. I do have one for the 6.6 kernel, that they might approve though.

just bring the pwm driver to mainline-state (6.8) and add the enabling in board dts…i wait for my r4 fan i ordered on aliexpress

What do you mean with mainline-state (6.8)? Do you know how I can submit patches to OpenWrt?

Thank you for making me smile :slightly_smiling_face:.

https://wiki.fw-web.de/doku.php?id=en:start

I found that very strange (in a nice way), that you found out, how to get the PWM fan run and how to make your own image. And than this question :upside_down_face:.

The reason why I found out how to do that myself is because I used to work with modifying drivers and hardware for a part of the Norwegian government, so I know how to debug, read and modify code - but not how to write for example new drivers, and how to submit patches, since everything I did was kept and used internally in the county.

Current linux version is 6.8 (or 6.9-rcX):

https://kernel.org/

Took me 10 seconds: [OpenWrt Wiki] Submitting patches

I’m not familar with openwrt build/patch system,but you should orient on mainline…either adding all parches done on mainline (git log v6.1…v6.8 – drivers/pwm/pwm-mediatek.c) or just add the file itself.

Btw. My moderator state is unrelated to this

The best practice would be to first submit the needed changes to mainline Linux and then backport them to OpenWrt Linux 6.1 and Linux 6.6. Backporting should be done by exporting the relevant commits from mainline Linux using git format-patch ... and adding them as patches to OpenWrt in target/linux/mediatek/patches-*. Patches should be named having the first Linux release they are part of in their filename – that makes future maintenance much easier as we will know when to remove them.

Adding the file itself (ie. overwriting the existing file from Linux) or doing a single dirty patch just bringing the driver to the same level as in Linux git HEAD is not acceptable.

2 Likes

Hi,

many thanks, I just installed your version and I can confirm my pwm fan works: now I must to learn how to set trip points.

1 Like

@Alexago, a quick tldr:

https://www.kernel.org/doc/Documentation/thermal/sysfs-api.txt

cat /sys/class/thermal/thermal_zone0/temp # read current temp

42678

Thermal zone types:

cat /sys/class/thermal/thermal_zone0/trip_point_0_type

critical

cat /sys/class/thermal/thermal_zone0/trip_point_1_type

hot

cat /sys/class/thermal/thermal_zone0/trip_point_2_type

active

cat /sys/class/thermal/thermal_zone0/trip_point_3_type

active

cat /sys/class/thermal/thermal_zone0/trip_point_4_type

active

Stock settings (currently):

cat /sys/class/thermal/thermal_zone0/trip_point_0_temp

125000

cat /sys/class/thermal/thermal_zone0/trip_point_1_temp

120000

cat /sys/class/thermal/thermal_zone0/trip_point_2_temp

115000

cat /sys/class/thermal/thermal_zone0/trip_point_3_temp

85000

cat /sys/class/thermal/thermal_zone0/trip_point_4_temp

40000

Updating:

echo 40000 > /sys/class/thermal/thermal_zone0/trip_point_1_temp # override echo 120000 > /sys/class/thermal/thermal_zone0/trip_point_1_temp # set to default

echo 35000 > /sys/class/thermal/thermal_zone0/trip_point_2_temp # override echo 115000 > /sys/class/thermal/thermal_zone0/trip_point_2_temp # set to default

echo 32000 > /sys/class/thermal/thermal_zone0/trip_point_3_temp # override echo 85000 > /sys/class/thermal/thermal_zone0/trip_point_3_temp # set to default

echo 30000 > /sys/class/thermal/thermal_zone0/trip_point_4_temp # override echo 40000 > /sys/class/thermal/thermal_zone0/trip_point_4_temp # set to default

I’ve heard that overriding the values via echoing to the sysfs path will persist on reboot, but have not confirmed; it may need to be set via an rc.local or sysctl.conf manner

1 Like

No, that is not true (at least not on this board).

Sorry for just disappearing / not answering.

My grandmother has gotten bowel cancer and is going into surgery tomorrow, so I have helped her a lot and haven’t had time to write here.

I don’t have time to try to submit patches to either the kernel or OpenWrt for the next few weeks either - can someone else here please do it for me ? :slight_smile: