From 4a1cb1f2eaad297220007ba28a592e2fc2310126 Mon Sep 17 00:00:00 2001 From: CTCaer Date: Sun, 8 May 2022 05:07:38 +0300 Subject: [PATCH] bdk: fan: add Hoag and Aula SKUs support Now that what was hanging Aula is found (using PWM with its clock disabled), add full support for fan control on both SKUs. --- bdk/thermal/fan.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/bdk/thermal/fan.c b/bdk/thermal/fan.c index 9e7a65e..019fd60 100644 --- a/bdk/thermal/fan.c +++ b/bdk/thermal/fan.c @@ -18,8 +18,11 @@ #include #include +#include +#include #include #include +#include #include #include #include @@ -37,19 +40,26 @@ void set_fan_duty(u32 duty) curr_duty = duty; - //! TODO: Add HOAG/AULA support. - u32 hw_type = fuse_read_hw_type(); - if (hw_type != FUSE_NX_HW_TYPE_ICOSA && - hw_type != FUSE_NX_HW_TYPE_IOWA) - return; - if (!fan_init) { // Fan tachometer. - PINMUX_AUX(PINMUX_AUX_CAM1_PWDN) = PINMUX_TRISTATE | PINMUX_INPUT_ENABLE | PINMUX_PULL_UP | 1; + u32 pull_resistor = hw_get_chip_id() == GP_HIDREV_MAJOR_T210 ? PINMUX_PULL_UP : 0; + PINMUX_AUX(PINMUX_AUX_CAM1_PWDN) = PINMUX_TRISTATE | PINMUX_INPUT_ENABLE | pull_resistor | 1; gpio_config(GPIO_PORT_S, GPIO_PIN_7, GPIO_MODE_GPIO); gpio_output_enable(GPIO_PORT_S, GPIO_PIN_7, GPIO_OUTPUT_DISABLE); + // Enable PWM if disabled. + if (fuse_read_hw_type() == FUSE_NX_HW_TYPE_AULA) + { + // Ease the stress to APB. + bpmp_freq_t prev_fid = bpmp_clk_rate_set(BPMP_CLK_NORMAL); + + clock_enable_pwm(); + + // Restore OC. + bpmp_clk_rate_set(prev_fid); + } + PWM(PWM_CONTROLLER_PWM_CSR_1) = PWM_CSR_EN | (0x100 << 16); // Max PWM to disable fan. PINMUX_AUX(PINMUX_AUX_LCD_GPIO2) = 1; // Set source to PWM1.