DzubyBB's post in BananaPi M5 PWM was marked as the answer
Ok, i'm managed to do this using pwm on pin gpiox-5, overlay :
/dts-v1/;
/plugin/;
/ {
compatible = "amlogic,a311d\0amlogic,g12a\0amlogic,g12b\0amlogic,sm1";
fragment@0 {
target = <&pwm_cd>;
__overlay__ {
status = "okay";
pinctrl-0 = <&pwm_c_x5_pins>;
pinctrl-names = "default";
};
};
fragment@1 {
target-path = "/";
__overlay__ {
fan0: pwm-fan {
compatible = "pwm-fan";
pwms = <&pwm_cd 0 40000 0>; /* 25kHz frequency (40000ns period) */
cooling-min-state = <0>;
cooling-max-state = <4>;
#cooling-cells = <2>;
cooling-levels = <26 52 102 153 204>; /* 10%, 20%, 40%, 60%, 80% duty cycles (out of 255) */
};
};
};
fragment@2 {
target = <&cpu_thermal>;
__overlay__ {
polling-delay = <1000>; /* 1 second polling */
trips {
cpu_fan_low: cpu-fan-low {
temperature = <35000>; /* 35°C */
hysteresis = <2000>; /* 2°C */
type = "active";
};
cpu_fan_mid1: cpu-fan-mid1 {
temperature = <40000>; /* 40°C */
hysteresis = <2000>;
type = "active";
};
cpu_fan_mid2: cpu-fan-mid2 {
temperature = <45000>; /* 45°C */
hysteresis = <2000>;
type = "active";
};
cpu_fan_mid3: cpu-fan-mid3 {
temperature = <50000>; /* 50°C */
hysteresis = <2000>;
type = "active";
};
cpu_fan_high: cpu-fan-high {
temperature = <55000>; /* 55°C */
hysteresis = <2000>;
type = "active";
};
};
cooling-maps {
map0 {
trip = <&cpu_fan_low>;
cooling-device = <&fan0 0 0>; /* 10% speed */
};
map1 {
trip = <&cpu_fan_mid1>;
cooling-device = <&fan0 1 1>; /* 20% speed */
};
map2 {
trip = <&cpu_fan_mid2>;
cooling-device = <&fan0 2 2>; /* 40% speed */
};
map3 {
trip = <&cpu_fan_mid3>;
cooling-device = <&fan0 3 3>; /* 60% speed */
};
map4 {
trip = <&cpu_fan_high>;
cooling-device = <&fan0 4 4>; /* 80% speed */
};
};
};
};
};
It has 5 levels of fan speed (10%, 20%, 40%, 60%, 80%) that depends on cpu temperature