From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj2-f43.google.com (mail-pj2-f43.google.com [74.125.227.171]) (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 97EDA501294 for ; Thu, 1 Oct 2026 13:37:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.227.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790861868; cv=none; b=N1k5oj6M47I3q9FqKJfugSoAvyT52ZJ/G3QKB8iRz+AqeMsZpWSZvXpszyGstQ/AgG4RqZhYoiw2dYoSUdYwV5DgjtMwVUg9/MsBUAJewqPxCS9iEDhXpmS0opSG3agz0g2m8Q7/YMciAwQ56A/CRTuHkFPagpvYng7n8qZME/U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790861868; c=relaxed/simple; bh=vdmQGK13R1oOEsmNWaFi3ZqjuaOs6wrd1xz21Izi3YA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Hc4IBLinmYPDt7/sM7hl8bzZVZ2HjImx+YtYg+69Lgz1MwyVd+mCTb3kyF/NLzdcnIUB8m9Zu2nZ6fo6zrVmCOxvr5VXpcgPsPqgo2HC8IgUPIiTArXNDPRjFd9Y8B06OXrAnZPyTTWB2bI81lVx4B1aSuN0jwz4lNVdOwiWAgw= 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=puzn+AwX; arc=none smtp.client-ip=74.125.227.171 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="puzn+AwX" Received: by mail-pj2-f43.google.com with SMTP id 98e67ed59e1d1-3a494638445so2396813a91.1 for ; Thu, 01 Oct 2026 06:37:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1790861866; x=1791466666; 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=z9v6/p4uU6f6A13FYDEwRoA3cSEnr9JJXUq7wBt1bpQ=; b=puzn+AwXLQe+vwxV3fl7oHVHF6qbpX/DZ77jW/urpWLie0xA+BfKf4Yb9W2PCgEscP RMRfutyAKS2kw84E5bLhy50/PAtpJ5zbOMKA+SuohGJtSTV+BvpkkAYUXIMAET6eZKri AdElh0hFgIJtWVSFhfUaCNNuOM57VpswmogNYWxw50X2HWqEoIAwd4+g1vlfCQ4213mB 5WtoBY09yjPUss2M9EAMnLrYb32XWOFeiMWMjUFJQfBL2lA37b343mkUO13TYnyWMytH IaMiIlBCMtBEcABl2wTg3TzbJD7KIVyhmsQC6poF2/JImUkJcXes91QMqOSlhcJRyymB QCFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790861866; x=1791466666; 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=z9v6/p4uU6f6A13FYDEwRoA3cSEnr9JJXUq7wBt1bpQ=; b=EoF/EJl/RyJnWY8M4bjaHrY3GNX8qWNwHcMfkiIi1dCzi5VgX+VSEFrDwdB/PKflJ7 dGnUpCW5fRdYxMUq3AsUUfqPOkQi+Ee3RTrEGWSr03zh2IR88VI19VxLksV9JrS3DhVi iOD7chT2FowCKbIS0qN5tGt6kf0fNSZHCaP2krB2PGprndwQURC2sdZkYxDre4T+UmFY J0dojkPEjqnQ4fLOk0BL2htw5ot0f8YuTYoyXBtXd4RpV/k7tJD162HwkMLdWeSqVWee 1s1XCHWg4vnFhDnu7M1tM01nqqueW1gZjVQMl42qbQbTtO8u3vZN7l8++WlJ0RXzUTea H0yw== X-Forwarded-Encrypted: i=1; AKwUvBzTFxbJdtOPJ1mBBp/rYkWhrJAAM2M6xumBf28vDiJYXX2y2x2AlE7JQ9AGPvJ4bLU0ENVp/baLYE4l1rI=@vger.kernel.org X-Gm-Message-State: AFq9FYK5XYeNXschKicBUsrn0Y2r+5T4BS8o424JeCsLnW3meHaiWAmF eE0/oH3ITqV2QJy0CRJ8E0bxMXdiLLXgtkot8e2rHbuweOxIwT3Fr+P9 X-Gm-Gg: AYBFou0vy9t8BSgJ0shD8hIlCCtQqpJv5H58WEwkRsPLutTcG0Sw8uv0KhrvhKZb2+4 H00JcuYkD3bBPbHS6bTTbRJhShUBFBofpAEJ8S8tinDNqcHLv1H5aDsGciAhcJEiZP205ZHSYrK s836zsg6IPsmISI6up5zd5anCLQYirPwjKUhA79afAlD2N40djm0q9Gzj48hHr2yAQ4bURP+ab5 erwhJ0iD6OUEfK7P0MQAr3G78M2NwHlIp+JtmWnmKb5qxUGUFVa8LrkNPgdVJptqVXMr3EvckF0 B/rcGDqFgX9e9iYlMNfI/yUr+HobtlJCYl/R7tnq549yZS9Gph3NGFzm42YVE6iehJ+O2g5k+4j YGonIO58uNd2qVazC2gGLCGWANXZQMc0ngGAqyFEvOPDWkL7eJhHBXUyEQIm9GpYWpNOG9t3f2k ifHEm9DozCQPbXiDzaARiuCL2FV2B4RRDdJtFBFcU4fPI/R5WMgqEARec1+dBVU7O0/VgCBwY= X-Received: by 2002:a17:90b:4b11:b0:3a0:c85a:e602 with SMTP id 98e67ed59e1d1-3a4d14eee80mr2748609a91.9.1790861865750; Thu, 01 Oct 2026 06:37:45 -0700 (PDT) Received: from qby-nixos-laptop ([20.89.137.63]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3a4f46b6bc6sm4715737a91.6.2026.10.01.06.37.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Oct 2026 06:37:45 -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 v9 5/5] platform/x86: bitland-mifs-wmi: Add per-machine ops table Date: Thu, 1 Oct 2026 21:37:05 +0800 Message-ID: <20261001133705.69244-6-qby140326@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261001133705.69244-1-qby140326@gmail.com> References: <20261001133705.69244-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 93a519b96189..c7dae6a6e0d2 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