Set fan speed associated with trigger temperature

VIM4
Ubuntu 22.04.1 LTS              
Linux 5.4.125

Hi All,

Linux newb here, so apologies in advance.

I’m trying to edit the fan speeds associated with each trigger temperature. These are currently defined in khadas-mcu.c:

#define MCU_FAN_SPEED_LOW_V2            0x32
#define MCU_FAN_SPEED_MID_V2            0x48
#define MCU_FAN_SPEED_HIGH_V2           0x64

It seems it would be ideal to expose the fan speeds in an analogous way to how trigger temperatures were exposed as writable files within /sys/class/fan (see GitHub issue), e.g. with files like speed_low, speed_mid, and speed_high. This would allow a user to define a basic fan curve. However, from what I gather, I’d need to edit khadas-mcu.c and rebuild the kernel (please correct me if I’m wrong), which is currently out of my depth.

I have been able to get the MCU to change the fan speed directly over i2c, e.g. with the following:

$bash
fan.sh off
i2cset -f -y 6 0x18 0x8a 0x16    # 0x16 = 22% duty

In sum, I’d be generally interested in hearing ideas as to how to implement a basic fan curve. If exposing the speeds as writable files in /sys/class/fan does seem to be a reasonable approach, I’d be interested in learning how to accomplish this (and/or to see this added as a feature).

Thanks!