geerlingguy / pi-router

Raspberry Pi-based OpenWRT router config for 4G/5G Waveshare Dual Ethernet board.
103 stars 8 forks source link

Get PWM control of Waveshare Fan-4010-PWM-12V in OpenWRT #3

Closed geerlingguy closed 1 year ago

geerlingguy commented 2 years ago

The official wiki suggests using the cm4io-fan library to control fan speeds. But I should note that at least Raspberry Pi OS now includes an i2c-fan overlay.

The question is, how could I get any of this stuff compiled into OpenWRT? Has anyone gotten OpenWRT working with the EMC2301?

It's not a requirement but that PWM fan is a bit buzzy/loud at full blast. It doesn't need to be that fast most of the time (if not ever), as just a light amount of air is enough to keep everything nice and cool indoors at least.

geerlingguy commented 2 years ago

It looks like @shayne got some stuff going in his OpenWRT fork: https://gist.github.com/shayne/eb047f6fb163705d0dcfaa498af4e5de

Would like to find a way to make those changes more maintainable, though... and break out just the changes required for EMC2301 support!

shayne commented 2 years ago

I added the emc2301 support via a patch that includes an overlay.

I can look at making it an OpenWRT kernel module package. Once that's upstream it could be pulled down from the package manager.

For now I can separate the emc2301 stuff into its own patch so it's as easy as a git apply. What do you think?

geerlingguy commented 2 years ago

@shayne - Oh, wow, that would be perfect! Separating the EMC2301 into its own diff would be a great first step — I could quickly rebuild my config and see if it 'just works' out of the box.

shayne commented 2 years ago

OK give this patch a try and let me know! https://gist.github.com/shayne/bc9f3778b53134d3274f9794eba4f874

# from top level directory
$ git apply <name-of-patch>
$ make -j $(nproc) defconfig download clean world V=s

NOTE: You might get kernel prompt that two sound devices are unconfigured... if so, just hit enter and it'll continue.

    # CONFIG_SND_SOC_AD193X_I2C is not set
    # CONFIG_SND_SOC_AD193X_SPI is not set
rjocoleman commented 2 years ago

this works well for me on the openwrt-22.03 branch (for kernel 5.10) with /boot/config.txt including:

dtparam=i2c_vc=on
dtoverlay=i2c_csi_dsi
dtoverlay=cm4io-fan,minrpm=1000,maxrpm=5000
shayne commented 2 years ago

I should be able to include the config.txt additions in the patch

stale[bot] commented 1 year ago

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark issues as stale.

stale[bot] commented 1 year ago

This issue has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details.

Alex-Joe-Lee commented 1 year ago

this works well for me on the openwrt-22.03 branch (for kernel 5.10) with /boot/config.txt including:

dtparam=i2c_vc=on
dtoverlay=i2c_csi_dsi
dtoverlay=cm4io-fan,minrpm=1000,maxrpm=5000

Could you share your image to me? thank you

kneave commented 1 year ago

@shayne, I don't suppose you were able to create a package for the EMC2301 in then end were you please? I've been trying to get a build working with your patch and I can get the fan working but the wifi is proving a nightmare! I've already a working build so if there's a way to apply your patch to it, it would be ideal. I've tried to understand how to do it myself but this is a bit deep in to the kernel and I'm out of my depth.

shayne commented 1 year ago

I'm sorry I don't have an easy answer for you. The EMC2301 work didn't produce a package. Instead, it built support into the kernel and added overlays for fan support. It sounds like you had the fan working at one point, but the wifi wasn't working.

What are you running now where the wifi works but not the fan?

kneave commented 1 year ago

Hi Shayne, no worries and thanks for the patch in the first place! I think the biggest issue was I didn't select the right packages for the WiFi adapters and as it was a custom build I couldn't install kernel modules using opkg. I'm currently rebuilding with your patch in place but I've selected the "build all kernel packages" option to mitigate this.

I think I'm getting my head around how to build and set up OpenWRT, there's quite the learning curve but I hope I'm passed the worst of it now.

shayne commented 1 year ago

You can install packages using opkg install and the --force-depends flag. If your custom build is a simple patch, the likelihood of binary compatibility is high. At least, I had good luck back when I was hacking on things.

kneave commented 1 year ago

Amazing, I'll give that a go. Thanks again!

Edit: I couldn't get the --force-depends to work but finally tracked down the wifi issue. I needed kmod-mt76 rather than kmod-mt76x2u that I was using. All sorted, and now without the soul sucking fan noise!

Thanks again @shayne and @geerlingguy!