Skip to content

Instantly share code, notes, and snippets.

@CounterPillow
Last active June 17, 2021 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CounterPillow/34cd7355eb625093e4350c349d2618ea to your computer and use it in GitHub Desktop.
Save CounterPillow/34cd7355eb625093e4350c349d2618ea to your computer and use it in GitHub Desktop.
diff --git a/arch/arm64/boot/dts/rockchip/rk3328-rock64.dts b/arch/arm64/boot/dts/rockchip/rk3328-rock64.dts
index 3bef1f39b..87e1c2dd1 100644
--- a/arch/arm64/boot/dts/rockchip/rk3328-rock64.dts
+++ b/arch/arm64/boot/dts/rockchip/rk3328-rock64.dts
@@ -19,6 +19,36 @@ chosen {
stdout-path = "serial2:1500000n8";
};
+ gpio_fan_cool: gpio_fan {
+ #cooling-cells = <2>;
+ compatible = "gpio-fan";
+ gpios = <
+ &gpio0 RK_PA0 GPIO_ACTIVE_LOW
+ &gpio3 RK_PA4 GPIO_ACTIVE_LOW
+ &gpio3 RK_PA5 GPIO_ACTIVE_LOW
+ &gpio3 RK_PA6 GPIO_ACTIVE_LOW
+ >;
+ gpio-fan,speed-map = <
+ 0 0
+ 333 1
+ 666 2
+ 1000 3
+ 1333 4
+ 1666 5
+ 2000 6
+ 2333 7
+ 2666 8
+ 3000 9
+ 3333 10
+ 3666 11
+ 4000 12
+ 4333 13
+ 4666 14
+ 5000 15
+ >;
+ status = "okay";
+ };
+
gmac_clkin: external-gmac-clock {
compatible = "fixed-clock";
clock-frequency = <125000000>;
@@ -108,6 +138,34 @@ spdif_dit: spdif-dit {
};
};
+&soc_thermal {
+ trips {
+ fan_point0: fan-point0 {
+ temperature = <40000>;
+ hysteresis = <2000>;
+ type = "active";
+ };
+ fan_point1: fan-point1 {
+ temperature = <45000>;
+ hysteresis = <2000>;
+ type = "active";
+ };
+ };
+
+ cooling-maps {
+ map1 {
+ trip = <&fan_point1>;
+ cooling-device =
+ <&gpio_fan_cool 3 15>;
+ };
+ map2 {
+ trip = <&fan_point0>;
+ cooling-device =
+ <&gpio_fan_cool 0 0>;
+ };
+ };
+};
+
&analog_sound {
status = "okay";
};
void setup() {
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(14, OUTPUT);
}
void loop() {
// pwm every 25 kHz
// 40000 ns = 40 microseconds
int val = 0;
val |= int(digitalRead(4) == 0);
val |= int(digitalRead(5) == 0) << 1;
val |= int(digitalRead(6) == 0) << 2;
val |= int(digitalRead(7) == 0) << 3;
softPWM(14, float(val) / float(0b1111));
}
void softPWM(int pin, float dutycycle) {
int ontime = int(dutycycle * 40.0 + 0.5);
int offtime = 40 - ontime;
if(ontime > 0) {
digitalWrite(pin, HIGH);
delayMicroseconds(ontime);
}
if(offtime > 0) {
digitalWrite(pin, LOW);
delayMicroseconds(offtime);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment