There are several PWM controlled cooling fans avaliable for the Raspberry Pis prior to the Pi 5, that are connected via the Pi's GPIO header. Examples are the Argon mini-fan, HighPi Pro Fan or ...
The main breanch is the next generation which uses the V2.2 lingpiod and is written in C++. (See https://github.com/HankB/GPIOD_Debian_Raspberry_Pi/tree/main/60 ...