Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 54C9C3D3322 for ; Mon, 15 Jun 2026 09:10:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781514656; cv=none; b=Me22MW1JTFyxoMApJP0i6M73tfMBbvBFw+WXo27KbS7t/ylMAXwXKuSJjHivsqVyb494SV8WPGYJ0nU30++OycCnNbC8/1SHzy1A/vsfYk/L+eUQlUdRGX4aodoMIb8vN12LnAJJOKwA0zk9FPKXZrcPtN7rocT5o7XBb888mHM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781514656; c=relaxed/simple; bh=YRqUCuedX9QmoiKQab0FrUThvedGKPvm9O6Q6vpfgcU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V2q4rPEEWp9RvX5yzbeNQaOLejnVKEEAVqxuAd9jtfmgxL3cue3xiGzKMJwdcU7U1H2gCAKUSuvWd25wdjcjwor9k/1Sl2sZvT1VbVipoSpYxdfv+/VLpr0Yts+ngrfHCcmOmBbDpvPsqSnVUjniR68YFiXu+Px1gbyICQrZyuo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=jHVExh6f; arc=none smtp.client-ip=209.85.210.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jHVExh6f" Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-842848fd613so2742404b3a.3 for ; Mon, 15 Jun 2026 02:10:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781514655; x=1782119455; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nYZnvAhWpc+vRxV3SQnSY4A4kKdtMLWyv3TfVkWRy70=; b=jHVExh6fPQzxMoPVh49em/Qi107uCf/uAAY06R+C8JmgAOKaHqIR+hgNjmenteZc1k GVqYJXhNc+WRtt0I/5EDTuGID1EcjjEjEcMPrqFyLCqeKWInnNt4dyE6sfBLMzGao947 5RdEqCrI77PtJT8eccYIZa/ZIReJ7Yjz2d+P1X/80gr5N8VbP8j7Ezwe9WlO63qH9SU/ PZ46SCzNXNIn7KJhPBkCGI+VCvqMi2kQgmg1AyXj3Ri9cvdqMzAw/52Ogmxx33tBoTlk Ja7nCSngFeksobLzagnrJCKr9bE12NT2orDFFtnUqgJeWJrbZ/lxPjtO8NInuxW/8AS9 4UxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781514655; x=1782119455; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=nYZnvAhWpc+vRxV3SQnSY4A4kKdtMLWyv3TfVkWRy70=; b=bKbARE1n2U9qUD2Q/J8HFyPsTVk7Z7RMRFbgHU/G3f14vas/c5mLfUJiR9JXn9lynV UUfd3JEfwm8jlaFEgBOj7xkiHT4pkKPqq3URicHF5XLgsXB02X0T1NrhYoh6E46S9dUb s/p4mjyo4fMJiWKkXU0/qyd0Htj+VqCPWZoXN+0DyRGWPXqcODXKOKIjggoy9sFcX/Fy RDSOo34pNqeV8iQ8wDuPg9GqTOSG6MacscVt8IkeDQ13gnEWKrprY/xPDMWUV2uvkUSc 7E+VsX+9sgLc3CsZrfA3BZCgj0VUDwegOZQNNFdzmGjEERecd/lZ1YYIlw5J0YGS5WNE zu2g== X-Gm-Message-State: AOJu0YxXg+PKJTVxkeZDByz/KrUbcDmSMwLKmY/GwuqQ0/zEYG2rQEI/ ohl+oqTqPYdnx70SnWUxH15Cyq4PZgwvbna4M6Ar1gn84Q7ZaDDx4dFt X-Gm-Gg: Acq92OE0t2Ptf16BCXoWd/iDKK4eTqnGq/mc8ZrcMpQkH19FehfoUD0AOw7mpoMbVpO 6R6DlVrnKrKAE//3naC5qA95Ma4N6ip7jVpc9AMXF8TSHC7RCYaalqyFSckXcQ06Viw6l1g/fp9 49bfqsu5Ljz6Ek3mRuyDp1SyggffqiOLIRtskSULVKjYVUanvhH9XXZfL3xoxbXG1x7SPi+aB0q Aeqiu67MloknXJHU6RjV6tPE75kt5Zps50iqhw3BVhIV+xsE3hOf3sbrLCMMz9hvNICjIkS0hLr nLsZqse9z3FTj7nykAdO5V6AH2VAwkFixbllxIda/ncyx+ySCu3cqWBIv1JOsWFEbHhIqxL/yuX Sw/YAObZ79XrSYQ72iAiwUWnZ+DOp+70+bmI5ChVlgAKK5rrxmVVqXBn6nTcylySzHW0m0TcbYL 9Q/3nMS/vBCLo21RMS+32qHmMrCPPxfKJcTs0= X-Received: by 2002:a05:6a00:4146:b0:82f:1b1b:e166 with SMTP id d2e1a72fcca58-8434d0aeb79mr18828446b3a.33.1781514654519; Mon, 15 Jun 2026 02:10:54 -0700 (PDT) Received: from pico-cachyos ([2401:4900:1c39:172b:de82:f342:993b:860a]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8434b00d4c7sm9392459b3a.40.2026.06.15.02.10.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jun 2026 02:10:53 -0700 (PDT) From: Radhey Kalra To: platform-driver-x86@vger.kernel.org Cc: linux-kernel@vger.kernel.org, hansg@kernel.org, ilpo.jarvinen@linux.intel.com, krishna.chomal108@gmail.com Subject: [PATCH v10 2/3] platform/x86: hp-wmi: Drive fan control from board data Date: Mon, 15 Jun 2026 14:40:33 +0530 Message-ID: <20260615091034.987029-3-radheykalra901@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260615091034.987029-1-radheykalra901@gmail.com> References: <20260615091034.987029-1-radheykalra901@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Use the board-specific .driver_data to describe fan-control support and fan-speed read callbacks. Existing boards keep the same Victus fan-control path, but the hwmon code no longer hardcodes that decision through is_victus_s_thermal_profile(). No functional changes intended. Signed-off-by: Radhey Kalra --- drivers/platform/x86/hp/hp-wmi.c | 79 ++++++++++++++++++++++++++------ 1 file changed, 64 insertions(+), 15 deletions(-) diff --git a/drivers/platform/x86/hp/hp-wmi.c b/drivers/platform/x86/hp/hp-wmi.c index ee8375d28..11de5c70c 100644 --- a/drivers/platform/x86/hp/hp-wmi.c +++ b/drivers/platform/x86/hp/hp-wmi.c @@ -133,24 +133,41 @@ static const struct thermal_profile_params omen_v1_no_ec_thermal_params = { .ec_tp_offset = HP_NO_THERMAL_PROFILE_OFFSET, }; +struct hp_wmi_fan_profile_params { + int (*get_fan_speed)(int fan); + bool fan_table; +}; + struct hp_wmi_board_params { const struct thermal_profile_params *thermal_profile; + const struct hp_wmi_fan_profile_params *fan_profile; +}; + +static int hp_wmi_get_fan_speed_victus_s(int fan); + +static const struct hp_wmi_fan_profile_params victus_s_fan_profile_params = { + .get_fan_speed = hp_wmi_get_fan_speed_victus_s, + .fan_table = true, }; static const struct hp_wmi_board_params victus_s_board_params = { .thermal_profile = &victus_s_thermal_params, + .fan_profile = &victus_s_fan_profile_params, }; static const struct hp_wmi_board_params omen_v1_board_params = { .thermal_profile = &omen_v1_thermal_params, + .fan_profile = &victus_s_fan_profile_params, }; static const struct hp_wmi_board_params omen_v1_legacy_board_params = { .thermal_profile = &omen_v1_legacy_thermal_params, + .fan_profile = &victus_s_fan_profile_params, }; static const struct hp_wmi_board_params omen_v1_no_ec_board_params = { .thermal_profile = &omen_v1_no_ec_thermal_params, + .fan_profile = &victus_s_fan_profile_params, }; static const struct hp_wmi_board_params *active_board_params; @@ -1813,6 +1830,38 @@ static bool is_victus_s_thermal_profile(void) return is_victus_s_board; } +static const struct hp_wmi_fan_profile_params *hp_wmi_fan_profile(void) +{ + if (!active_board_params) + return NULL; + + return active_board_params->fan_profile; +} + +static bool hp_wmi_fan_control_supported(void) +{ + const struct hp_wmi_fan_profile_params *params = hp_wmi_fan_profile(); + + return params && params->get_fan_speed; +} + +static bool hp_wmi_fan_table_supported(void) +{ + const struct hp_wmi_fan_profile_params *params = hp_wmi_fan_profile(); + + return params && params->fan_table; +} + +static int hp_wmi_get_active_fan_speed(int fan) +{ + const struct hp_wmi_fan_profile_params *params = hp_wmi_fan_profile(); + + if (!params || !params->get_fan_speed) + return -EOPNOTSUPP; + + return params->get_fan_speed(fan); +} + static int victus_s_gpu_thermal_profile_get(bool *ctgp_enable, bool *ppab_enable, u8 *dstate, @@ -2432,7 +2481,7 @@ static int hp_wmi_apply_fan_settings(struct hp_wmi_hwmon_priv *priv) switch (priv->mode) { case PWM_MODE_MAX: - if (is_victus_s_thermal_profile()) { + if (hp_wmi_fan_control_supported()) { ret = hp_wmi_get_fan_count_userdefine_trigger(); if (ret < 0) return ret; @@ -2444,7 +2493,7 @@ static int hp_wmi_apply_fan_settings(struct hp_wmi_hwmon_priv *priv) secs_to_jiffies(KEEP_ALIVE_DELAY_SECS)); return 0; case PWM_MODE_MANUAL: - if (!is_victus_s_thermal_profile()) + if (!hp_wmi_fan_control_supported()) return -EOPNOTSUPP; ret = hp_wmi_fan_speed_set(priv, pwm_to_rpm(priv->pwm, priv)); if (ret < 0) @@ -2453,7 +2502,7 @@ static int hp_wmi_apply_fan_settings(struct hp_wmi_hwmon_priv *priv) secs_to_jiffies(KEEP_ALIVE_DELAY_SECS)); return 0; case PWM_MODE_AUTO: - if (is_victus_s_thermal_profile()) { + if (hp_wmi_fan_control_supported()) { ret = hp_wmi_get_fan_count_userdefine_trigger(); if (ret < 0) return ret; @@ -2477,12 +2526,12 @@ static umode_t hp_wmi_hwmon_is_visible(const void *data, { switch (type) { case hwmon_pwm: - if (attr == hwmon_pwm_input && !is_victus_s_thermal_profile()) + if (attr == hwmon_pwm_input && !hp_wmi_fan_control_supported()) return 0; return 0644; case hwmon_fan: - if (is_victus_s_thermal_profile()) { - if (hp_wmi_get_fan_speed_victus_s(channel) >= 0) + if (hp_wmi_fan_control_supported()) { + if (hp_wmi_get_active_fan_speed(channel) >= 0) return 0444; } else { if (hp_wmi_get_fan_speed(channel) >= 0) @@ -2506,8 +2555,8 @@ static int hp_wmi_hwmon_read(struct device *dev, enum hwmon_sensor_types type, priv = dev_get_drvdata(dev); switch (type) { case hwmon_fan: - if (is_victus_s_thermal_profile()) - ret = hp_wmi_get_fan_speed_victus_s(channel); + if (hp_wmi_fan_control_supported()) + ret = hp_wmi_get_active_fan_speed(channel); else ret = hp_wmi_get_fan_speed(channel); if (ret < 0) @@ -2516,10 +2565,10 @@ static int hp_wmi_hwmon_read(struct device *dev, enum hwmon_sensor_types type, return 0; case hwmon_pwm: if (attr == hwmon_pwm_input) { - if (!is_victus_s_thermal_profile()) + if (!hp_wmi_fan_control_supported()) return -EOPNOTSUPP; - rpm = hp_wmi_get_fan_speed_victus_s(channel); + rpm = hp_wmi_get_active_fan_speed(channel); if (rpm < 0) return rpm; *val = rpm_to_pwm(rpm / 100, priv); @@ -2553,7 +2602,7 @@ static int hp_wmi_hwmon_write(struct device *dev, enum hwmon_sensor_types type, switch (type) { case hwmon_pwm: if (attr == hwmon_pwm_input) { - if (!is_victus_s_thermal_profile()) + if (!hp_wmi_fan_control_supported()) return -EOPNOTSUPP; /* PWM input is invalid when not in manual mode */ if (priv->mode != PWM_MODE_MANUAL) @@ -2570,13 +2619,13 @@ static int hp_wmi_hwmon_write(struct device *dev, enum hwmon_sensor_types type, priv->mode = PWM_MODE_MAX; return hp_wmi_apply_fan_settings(priv); case PWM_MODE_MANUAL: - if (!is_victus_s_thermal_profile()) + if (!hp_wmi_fan_control_supported()) return -EOPNOTSUPP; /* * When switching to manual mode, set fan speed to * current RPM values to ensure a smooth transition. */ - rpm = hp_wmi_get_fan_speed_victus_s(channel); + rpm = hp_wmi_get_active_fan_speed(channel); if (rpm < 0) return rpm; priv->pwm = rpm_to_pwm(rpm / 100, priv); @@ -2642,8 +2691,8 @@ static int hp_wmi_setup_fan_settings(struct hp_wmi_hwmon_priv *priv) /* Default behaviour on hwmon init is automatic mode */ priv->mode = PWM_MODE_AUTO; - /* Bypass all non-Victus S devices */ - if (!is_victus_s_thermal_profile()) + /* Bypass devices without fan control support. */ + if (!hp_wmi_fan_table_supported()) return 0; ret = hp_wmi_perform_query(HPWMI_VICTUS_S_GET_FAN_TABLE_QUERY, -- 2.54.0