From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pz2-f40.google.com (mail-pz2-f40.google.com [74.125.228.40]) (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 8BAD4349CE7 for ; Thu, 1 Oct 2026 00:23:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.228.40 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790814209; cv=none; b=p1aEtQG9eB0OJ0vD8uHNuA0rAeBwQy6iSa+WihTZt47mWul60IiikePmJA08rFNbMNS6zXZj8grhSDWGIsVq9uMj1grDLEehvKqDhJvA26uUldnru3Bajb9J3N6WZweS0oogr0PFeZvPqg6bb7QKCK2kSJW6Cz9VLT6sRbQwni4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790814209; c=relaxed/simple; bh=bfsR+N3eKVurOKlSCy7ABiYbzmUmeCFH1XKVJvIertA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jINNkdAJArBuRut/SqCNKn9epJKCIXMAPKeClhgRa0NdHr/cWyyOKq3ONikELe+GYuJAmm6LuqSoo6uFJzYzAaPuZ+h3YqhIizaWVWCW1kOZSfC/RXeCOGo9OvSOqeukOojasSeDUIaGncLVp6V8/ReW+qjeVlVWrCFCk28NYoI= 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=NO9Og9tM; arc=none smtp.client-ip=74.125.228.40 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="NO9Og9tM" Received: by mail-pz2-f40.google.com with SMTP id 41be03b00d2f7-cc74520b20bso1572731a12.1 for ; Wed, 30 Sep 2026 17:23:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790814207; x=1791419007; 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:content-type; bh=65QKTQg8dRKIi14/Dno/8l0Vcqg3fe6R3Gb8iOYuUTE=; b=NO9Og9tM7ZPOXekfjvEpffxYi1MsJQbUgEVVMPHfjiyulNYkEE4Y7Ai6vuZIExm/KA ls3WhU3AwmVofpPrYT91AtQWn4maXTFP31/AGgmQxicCn7sTZmKQ8ffPul1Isjy6RKqL lBevTX+JtSUeKhzgGlx1FLISQb1RV9TYUYCW0gnb2+02j38ob10ZKmZumd+v5H+00Ykn y5B6c2DtAsQC6CsI7R4yy8Ue/cKmkNoSn3ygzoyo2yqXNSpoaqHzbE3ezN+0/k7btUbG u5jBofkRItxW2wnHCiB40yMIKL4YdeaMSLEXC7P18yOiIrFSqPmRORMJPjeqCXVvbjns inuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790814207; x=1791419007; 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:content-type; bh=65QKTQg8dRKIi14/Dno/8l0Vcqg3fe6R3Gb8iOYuUTE=; b=uNN3j+jOGc99GKvM+t3v5ID6B9jA0SdlZUP38Z6LHvhmL/ETPIjkD1zpu0MT2QQyQd Q2mpAy6qbedJaM/UYYZJeeCvoE5OS4zDpQoVlnBoKAugFCDjBtxxpexIaGp/L92raFye 7xto6HZNG69gLJ4s7/+PseFGMk7ZhHmJ77h6LAitheSsav7Lfag4ViOEYpKJ9zMghKo/ z960TrVPCqcblO3kvjNgwMHGp2vu8HKVORRgdWoQstCW83OSrukVVJnNGWEAi/Ih7ev2 E8zGASweyj8SplBDRMTs8A/mX8ExEH/SADb0shpBVovL67wInDJ5WxIPRiPV2SD+i4jE 18QA== X-Forwarded-Encrypted: i=1; AKwUvBwGyVKxGjedM/s8A4ZIhpSs4lxTH39WWDAbcvl07udrbmUI3LIqQ/rVnTfew7OI3zPrfTx9ykXjB/rwmo0=@vger.kernel.org X-Gm-Message-State: AFuF++nAlnMjgLTD3hQRVerj5qc/qO5VuZ9eNJIbO+HK3mQfmDV7a++E Sto+D1VO+AJ7Z/DBtmt21ckgNgr/NyOfT5aOo7E7ri0bAtrfeu2Tlj4L X-Gm-Gg: AYBFou0U7JFDXbsVyXPaVY1R8f+r7+nGgabvYcHfsPukBTU/uhuchyt/CD6AsGpnuun NwAn1i8R1BzX+njQ9VML/WjjfDyOahwDwXPFsikLjUXzjeTFGOunr3WyXwto2bZEdmONDSBR2Sh PsE6m/nblcRdVWGHIsKPPhZ4qAAq9YTtZrwH2lURt1IYLnLBicoN2gdMVfA9hB4ZfHwbhUi2LXb BCuGiTqqA4Jw/AFJB/Inw7mlwIcVRDcgT5Kd1DjMPNfkEnVFYb3MKelBISD8ye35PJzD4YOZoD5 V8V71ftukewnJ+cxTuTvCtyTQRS5Gv7y+H884sng5sR7/qol3TRLLZyieNpIteEAxfm0zDV4bej uerjVyC1F/0/tsYFK63SaooirXyi+u+FMMUBXmaT4rRN4FRBnQb4t4tlRJ9e4hGvsJXltOtJVf1 iTT6Oz9A0KOvopDX9hYcG2YP6h8XzatXkciME22mawpIIk11W5hag7 X-Received: by 2002:a05:6a21:b97:b0:3dd:85a8:4c51 with SMTP id adf61e73a8af0-3deac909fdcmr682589637.21.1790814206699; Wed, 30 Sep 2026 17:23:26 -0700 (PDT) Received: from qby-nixos-laptop ([2a13:edc0:18:16f::a]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-88818deef3esm247601b3a.29.2026.09.30.17.23.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Sep 2026 17:23:26 -0700 (PDT) From: Mingyou Chen To: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Hans de Goede , Ilya Gladyshev Cc: KentoNion , platform-driver-x86@vger.kernel.org, ted eric , Armin Wolf , linux-kernel@vger.kernel.org, Chris Taraszka , Matias Civadda , =?UTF-8?q?=E9=AB=98=20=E4=BF=8A=E6=96=87?= , powerfullz , =?UTF-8?q?=E5=AD=99=20=E8=AA=89=E9=93=AD?= , =?UTF-8?q?Milo=C5=A1=20Vlku?= , Rsplwe , Bozhen Peng , Anton Karasev , Mingyou Chen Subject: [PATCH v7 5/5] platform/x86: bitland-mifs-wmi: Add per-machine ops table Date: Thu, 1 Oct 2026 00:22:39 +0000 Message-ID: <20261001002239.31461-6-qby140326@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261001002239.31461-1-qby140326@gmail.com> References: <20261001002239.31461-1-qby140326@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 The MIFS WMI interface is shared by several Bitland ODM laptops which differ in the layout of the performance mode values of WMI_FN_SYSTEM_PER_MODE and in the capability checks. Introduce a machine ops table to support multiple machine families without sprinkling model checks over the driver: struct bitland_mifs_ops { const char *name; const struct bitland_profile_mode_map *mode_map; int (*check_performance_capability)( struct bitland_mifs_wmi_data *data); bool has_full_speed; }; The default ops instance keeps the current Bitland behavior, so this change is a pure refactor without any functional changes. Signed-off-by: Mingyou Chen --- drivers/platform/x86/bitland-mifs-wmi.c | 108 +++++++++++++++++++----- 1 file changed, 86 insertions(+), 22 deletions(-) diff --git a/drivers/platform/x86/bitland-mifs-wmi.c b/drivers/platform/x86/bitland-mifs-wmi.c index e28df14d4b8a..69d4ce7316b0 100644 --- a/drivers/platform/x86/bitland-mifs-wmi.c +++ b/drivers/platform/x86/bitland-mifs-wmi.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -84,6 +85,50 @@ enum bitland_mifs_power_profile { WMI_PP_FULL_SPEED = 3, }; +struct bitland_mifs_wmi_data; + +/* + * Value layout of WMI_FN_SYSTEM_PER_MODE. + */ +struct bitland_profile_mode_map { + u8 balanced; + u8 performance; + u8 quiet; + u8 full_speed; +}; + +static const struct bitland_profile_mode_map bitland_mode_map = { + .balanced = WMI_PP_BALANCED, + .performance = WMI_PP_PERFORMANCE, + .quiet = WMI_PP_QUIET, + .full_speed = WMI_PP_FULL_SPEED, +}; + +static int bitland_pp_check_capability(struct bitland_mifs_wmi_data *data); + +/* + * Machine-specific operations. The MIFS WMI interface is shared by + * several Bitland ODM laptops which differ in the layout of the + * performance mode values and in the capability checks. + */ +struct bitland_mifs_ops { + const char *name; + const struct bitland_profile_mode_map *mode_map; + int (*check_performance_capability)(struct bitland_mifs_wmi_data *data); + bool has_full_speed; +}; + +static const struct bitland_mifs_ops bitland_ops = { + .name = "Bitland", + .mode_map = &bitland_mode_map, + .check_performance_capability = bitland_pp_check_capability, + .has_full_speed = true, +}; + +static const struct dmi_system_id bitland_mifs_dmi_table[] = { + {} +}; + enum bitland_mifs_event_id { WMI_EVENT_SWITCHVIDEOMODE = 1, WMI_EVENT_SELECTIVE_SCREENSHOT = 2, @@ -166,6 +211,7 @@ struct bitland_mifs_wmi_data { struct input_dev *input_dev; struct device *hwmon_dev; struct device *pp_dev; + const struct bitland_mifs_ops *ops; enum platform_profile_option saved_profile; }; @@ -208,37 +254,35 @@ static int laptop_profile_get(struct device *dev, enum platform_profile_option *profile) { struct bitland_mifs_wmi_data *data = dev_get_drvdata(dev); + const struct bitland_profile_mode_map *map = data->ops->mode_map; struct bitland_mifs_input input = { .operation = cpu_to_le16(WMI_METHOD_GET), .function = cpu_to_le16(WMI_FN_SYSTEM_PER_MODE), }; struct bitland_mifs_output result; + u8 mode; int ret; ret = bitland_mifs_wmi_call(data, &input, &result); if (ret) return ret; - switch (result.data[0]) { - case WMI_PP_BALANCED: + mode = result.data[0]; + if (mode == map->quiet) + *profile = PLATFORM_PROFILE_LOW_POWER; + else if (mode == map->balanced) *profile = PLATFORM_PROFILE_BALANCED; - break; - case WMI_PP_PERFORMANCE: + else if (mode == map->performance) *profile = PLATFORM_PROFILE_BALANCED_PERFORMANCE; - break; - case WMI_PP_QUIET: - *profile = PLATFORM_PROFILE_LOW_POWER; - break; - case WMI_PP_FULL_SPEED: + else if (mode == map->full_speed) *profile = PLATFORM_PROFILE_PERFORMANCE; - break; - default: + else return -EINVAL; - } + return 0; } -static int bitland_check_performance_capability(struct bitland_mifs_wmi_data *data) +static int bitland_pp_check_capability(struct bitland_mifs_wmi_data *data) { struct bitland_mifs_input input = { .operation = cpu_to_le16(WMI_METHOD_GET), @@ -269,47 +313,52 @@ static int laptop_profile_set(struct device *dev, enum platform_profile_option profile) { struct bitland_mifs_wmi_data *data = dev_get_drvdata(dev); + const struct bitland_profile_mode_map *map = data->ops->mode_map; struct bitland_mifs_input input = { .operation = cpu_to_le16(WMI_METHOD_SET), .function = cpu_to_le16(WMI_FN_SYSTEM_PER_MODE), }; int ret; - u8 val; + u8 mode; switch (profile) { case PLATFORM_PROFILE_LOW_POWER: - val = WMI_PP_QUIET; + mode = map->quiet; break; case PLATFORM_PROFILE_BALANCED: - val = WMI_PP_BALANCED; + mode = map->balanced; break; case PLATFORM_PROFILE_BALANCED_PERFORMANCE: - ret = bitland_check_performance_capability(data); + ret = data->ops->check_performance_capability(data); if (ret) return ret; - val = WMI_PP_PERFORMANCE; + mode = map->performance; break; case PLATFORM_PROFILE_PERFORMANCE: - ret = bitland_check_performance_capability(data); + ret = data->ops->check_performance_capability(data); if (ret) return ret; - val = WMI_PP_FULL_SPEED; + mode = map->full_speed; break; default: return -EOPNOTSUPP; } - input.payload[0] = val; + input.payload[0] = mode; return bitland_mifs_wmi_call(data, &input, NULL); } static int platform_profile_probe(void *drvdata, unsigned long *choices) { + struct bitland_mifs_wmi_data *data = drvdata; + set_bit(PLATFORM_PROFILE_LOW_POWER, choices); set_bit(PLATFORM_PROFILE_BALANCED, choices); set_bit(PLATFORM_PROFILE_BALANCED_PERFORMANCE, choices); - set_bit(PLATFORM_PROFILE_PERFORMANCE, choices); + + if (data->ops->has_full_speed) + set_bit(PLATFORM_PROFILE_PERFORMANCE, choices); return 0; } @@ -708,6 +757,19 @@ static int bitland_notifier_callback(struct notifier_block *nb, return NOTIFY_OK; } +static void bitland_detect_ops(struct bitland_mifs_wmi_data *data) +{ + const struct dmi_system_id *id; + + id = dmi_first_match(bitland_mifs_dmi_table); + if (id) + data->ops = id->driver_data; + else + data->ops = &bitland_ops; + + dev_dbg(&data->wdev->dev, "Detected machine ops: %s\n", data->ops->name); +} + static int bitland_mifs_wmi_probe(struct wmi_device *wdev, const void *context) { struct bitland_mifs_wmi_data *drv_data; @@ -732,6 +794,8 @@ static int bitland_mifs_wmi_probe(struct wmi_device *wdev, const void *context) dev_set_drvdata(&wdev->dev, drv_data); + bitland_detect_ops(drv_data); + if (dev_type == BITLAND_WMI_EVENT) { /* Register input device for hotkeys */ drv_data->input_dev = devm_input_allocate_device(&wdev->dev); -- 2.55.0