diff options
-rw-r--r-- | zephyr/program/nissa/CMakeLists.txt | 1 | ||||
-rw-r--r-- | zephyr/program/nissa/craask/cbi.dtsi | 26 | ||||
-rw-r--r-- | zephyr/program/nissa/craask/fan.dtsi | 38 | ||||
-rw-r--r-- | zephyr/program/nissa/craask/overlay.dtsi | 4 | ||||
-rw-r--r-- | zephyr/program/nissa/craask/project.overlay | 1 | ||||
-rw-r--r-- | zephyr/program/nissa/craask/src/fan.c | 37 |
6 files changed, 107 insertions, 0 deletions
diff --git a/zephyr/program/nissa/CMakeLists.txt b/zephyr/program/nissa/CMakeLists.txt index a982f89b56..c8610e488d 100644 --- a/zephyr/program/nissa/CMakeLists.txt +++ b/zephyr/program/nissa/CMakeLists.txt @@ -34,6 +34,7 @@ if(DEFINED CONFIG_BOARD_NEREID) endif() if(DEFINED CONFIG_BOARD_CRAASK) zephyr_library_sources( + "craask/src/fan.c" "craask/src/form_factor.c" "craask/src/keyboard.c" "craask/src/kb_backlight.c" diff --git a/zephyr/program/nissa/craask/cbi.dtsi b/zephyr/program/nissa/craask/cbi.dtsi index 203eace823..e329929227 100644 --- a/zephyr/program/nissa/craask/cbi.dtsi +++ b/zephyr/program/nissa/craask/cbi.dtsi @@ -52,6 +52,32 @@ value = <1>; }; }; + + /* + * FW_CONFIG field to enable fan or not. + */ + fan { + enum-name = "FW_FAN"; + start = <17>; + size = <1>; + + no-fan { + compatible = "cros-ec,cbi-fw-config-value"; + enum-name = "FW_FAN_NOT_PRESENT"; + value = <0>; + }; + fan-present { + compatible = "cros-ec,cbi-fw-config-value"; + enum-name = "FW_FAN_PRESENT"; + value = <1>; + /* + * Set as default so that unprovisioned + * configs will run the fan regardless. + */ + default; + }; + }; + /* * FW_CONFIG field to enable KB back light or not. */ diff --git a/zephyr/program/nissa/craask/fan.dtsi b/zephyr/program/nissa/craask/fan.dtsi new file mode 100644 index 0000000000..b94b0a018c --- /dev/null +++ b/zephyr/program/nissa/craask/fan.dtsi @@ -0,0 +1,38 @@ +/* Copyright 2022 The ChromiumOS Authors + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +/ { + fans { + compatible = "cros-ec,fans"; + fan_0 { + pwms = <&pwm5 5 PWM_KHZ(25) PWM_POLARITY_NORMAL>; + tach = <&tach2>; + rpm_min = <2500>; + rpm_start = <2500>; + rpm_max = <4100>; + enable_gpio = <&gpio_fan_enable>; + }; + }; +}; + +&pwm5_gpb7 { + drive-open-drain; +}; + +/* pwm for fan */ +&pwm5 { + status = "okay"; + pinctrl-0 = <&pwm5_gpb7>; + pinctrl-names = "default"; +}; + +/* Tachometer for fan speed measurement */ +&tach2 { + status = "okay"; + pinctrl-0 = <&ta2_1_in_gp73>; + pinctrl-names = "default"; + port = <NPCX_TACH_PORT_A>; /* port-A is selected */ + sample-clk = <NPCX_TACH_FREQ_LFCLK>; /* Use LFCLK as sampling clock */ + pulses-per-round = <2>; /* number of pulses per round of encoder */ +}; diff --git a/zephyr/program/nissa/craask/overlay.dtsi b/zephyr/program/nissa/craask/overlay.dtsi index 2607c10402..749317cbf5 100644 --- a/zephyr/program/nissa/craask/overlay.dtsi +++ b/zephyr/program/nissa/craask/overlay.dtsi @@ -120,6 +120,10 @@ gpios = <&gpiof 5 (GPIO_INPUT | GPIO_VOLTAGE_1P8)>; no-auto-init; }; + gpio_fan_enable: fan-enable { + gpios = <&gpio6 3 GPIO_OUTPUT>; + no-auto-init; + }; ec-i2c-sensor-scl { gpios = <&gpio9 0 (GPIO_INPUT | GPIO_VOLTAGE_1P8)>; }; diff --git a/zephyr/program/nissa/craask/project.overlay b/zephyr/program/nissa/craask/project.overlay index 9ca681d979..6107b6ef15 100644 --- a/zephyr/program/nissa/craask/project.overlay +++ b/zephyr/program/nissa/craask/project.overlay @@ -6,6 +6,7 @@ #include "../cbi.dtsi" #include "cbi.dtsi" +#include "fan.dtsi" #include "generated.dtsi" #include "keyboard.dtsi" #include "motionsense.dtsi" diff --git a/zephyr/program/nissa/craask/src/fan.c b/zephyr/program/nissa/craask/src/fan.c new file mode 100644 index 0000000000..c01ee3d752 --- /dev/null +++ b/zephyr/program/nissa/craask/src/fan.c @@ -0,0 +1,37 @@ +/* Copyright 2022 The ChromiumOS Authors + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#include "cros_cbi.h" +#include "fan.h" +#include "gpio/gpio.h" +#include "hooks.h" +#include "nissa_common.h" + +#include <zephyr/devicetree.h> +#include <zephyr/drivers/gpio.h> +#include <zephyr/logging/log.h> +LOG_MODULE_DECLARE(nissa, CONFIG_NISSA_LOG_LEVEL); + +static void fan_init(void) +{ + int ret; + uint32_t val; + /* + * Retrieve the fan config. + */ + ret = cros_cbi_get_fw_config(FW_FAN, &val); + if (ret != 0) { + LOG_ERR("Error retrieving CBI FW_CONFIG field %d", FW_FAN); + return; + } + if (val != FW_FAN_PRESENT) { + /* Disable the fan */ + fan_set_count(0); + } else { + /* Configure the fan enable GPIO */ + gpio_pin_configure_dt(GPIO_DT_FROM_NODELABEL(gpio_fan_enable), + GPIO_OUTPUT); + } +} +DECLARE_HOOK(HOOK_INIT, fan_init, HOOK_PRIO_POST_FIRST); |