From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (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 A722137BE86 for ; Sun, 16 Aug 2026 00:12:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786839157; cv=none; b=HUaYxKSEZo7j63KItSQOwx5Kf+BIOkMixK/gbCUbL/63Kkq4r17uJOzSbkyUJ/efDbDqUVQnBbPsG7ishib0gqnf+Kwdi7+IICRhD2xN3ojSEIyW/BpVmmaXZ3TGsbRZCS4oeVUiyg0JvtgQqDATtBJU2PUGDbFqa+MIMqr274w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786839157; c=relaxed/simple; bh=rz/N6YjVafxuJ7l7ui4YPxX1PJNihBUbWeyPN273N3g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QILZgAG0mP9YmKbbW1Z/ENbBztQBpXzwPSR7WynPn+V8+c9FWZ3xXF8B0bq4OWBQhghzwv4z/nRjiMh/gUF2HwDYJ/VheJuTOyuqP4PZtkQ2JUPL6/Vm3m8HcWmFzoFs2FlnZg0vSgiYa7gJfHwqo+qv4TARKLIArPVSs5922zY= 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=kcN9nv6N; arc=none smtp.client-ip=209.85.216.49 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="kcN9nv6N" Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-39266382df6so1828770a91.3 for ; Sat, 15 Aug 2026 17:12:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786839151; x=1787443951; 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=ZSkR9tIKiTyiThY12Ko2HUffdRvYZARmMC0w+0N9FPw=; b=kcN9nv6Nn0QIR8cCWmAdp7ovFgAsBNsWJhs7SAxmxsKlj82RjoI5Hvk1kSWaNiwjXX ixg5uQSbfMsgqL59GG1r8Bj51qwtQW03Xlj/lfaHIxdANIhXOkTC0Oi/A5Enq8/mynbG 3Pj6pFVqYG9f4l+H+lJW0NoiMfUxIHWbcrqWXD0EXLdAC4PUe0seD/ReuEw29hkzGDkj J80+XLPjJrWNsHepV3ja1w95+5NZTrNRNeWdjmHpqCPXxAg70OpCefGZkbRTesSvX/jY s0QCs9aOXKdVviTx6C9t63w08tfVd+t+Pk1Cf0+LCSQaW9XmNeSHRdLceq6coCqEODFl 1QZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786839151; x=1787443951; 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=ZSkR9tIKiTyiThY12Ko2HUffdRvYZARmMC0w+0N9FPw=; b=d3D8eJovPIhBs4SMdthtgJsjqqrCtPumUUFjSc20K9l/Q1MsqSO3hzxVKwuHfD2Hfi Q2F6FU1AnpSyDJiqLcsQjiijESZNUPycYqB4/morzBkhjKULO9ksFZTE/PBmMRWDOKbI XSz6qS7Ykmpbk41RNgks07AG8yLikvR2DGCdZjmLourtqZL/k3HGlHLQujEw+51SVWSw gNZ3O43X0+7nQ66c9CcZQQ5igxKsuasiKi5wkXl5z7BlMUKyAjwGSMaaN0oak3Gw2cxe /9Sli83+G9K8uDLtvOvv24eBvy7bB2W9RJYRfnVs6karc8gX2QgmVKXyj8ilFh7C2HoX cQ9w== X-Forwarded-Encrypted: i=1; AHgh+Rq9TbXF9GIn1yPP1H8MLYvFcyEKgzW8SDnt/0QfAqw7ytILIPKucaX4Rbp5Lf0OE0FxduNbYC/D7d+hCFw=@vger.kernel.org X-Gm-Message-State: AOJu0Ywu2KYvi83ao5V+CoE4q4Jb3WFOo11Xl2umGwLlVL5+zNnt69y0 G45icfqVIzQbJnTMjiz4CmKxVjXH95SJ0mDyjclKAm0fN4nKQpJCZzBSTJ3MZvh9 X-Gm-Gg: AR+sD10YjOLud5HBu0iS8owVh6JSLu9aXU2uVr2ZSGh3UAHdrQtApCKmOeGWrneZUiu V9sCPmVwjZc3Jr+gRCdDox6v7kFyqaIOgieK0hLRVv/cbFYcx+h3jkdnb9Liws/kULWfHPdaxlz ZgoStmtQdnWr/Gp3URCVrt/faiH+7oDyBgCbcuWIRm/wC7aRsqgGpippxGqLmEiaXBh6YLUX0JM WrDtH+a/RbpVFxB6xiRWqcmqYhRkQERzPMwEgERw6S4WowaDY6r3C9gJ5gTNDQPiIP+93LNGXGQ WGKVMVs31XS52i1TOhjH4QUYw4oC6TFQD9V3I8bQg0toi6BdUpcHWeLEY7rBoFGoBoun5zQIlk+ YzKasuIfZvrHXFCIybYqwM5JbcBv2sALBV+nGckyYBnpmpvq3n9mA57a4A7dxuxfXsry3i8oYQS KAN3J6TwW3oRYIUotpuHPmTOiZlVkId8d/dTo= X-Received: by 2002:a17:90b:2248:b0:392:c80b:8eff with SMTP id 98e67ed59e1d1-3933b87a743mr15027563a91.11.1786839150806; Sat, 15 Aug 2026 17:12:30 -0700 (PDT) Received: from qby-laptop ([2a13:edc0:18:16f::a]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-394ea96c87bsm7409320a91.4.2026.08.15.17.12.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Aug 2026 17:12:30 -0700 (PDT) From: Mingyou Chen To: qby140326@gmail.com Cc: W_Armin@gmx.de, foxido@foxido.dev, hansg@kernel.org, ilpo.jarvinen@linux.intel.com, linux-kernel@vger.kernel.org, nika@nikableh.moe, platform-driver-x86@vger.kernel.org, vlku.milos.fun@gmail.com, i@rsplwe.com, wolf109909@outlook.com Subject: [PATCH v4 5/6] platform/x86: bitland-mifs-wmi: Add per-machine ops table Date: Sun, 16 Aug 2026 08:11:28 +0800 Message-ID: <20260816001129.16998-6-qby140326@gmail.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260816001129.16998-1-qby140326@gmail.com> References: <20260816001129.16998-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 | 89 +++++++++++++++++++------ 1 file changed, 67 insertions(+), 22 deletions(-) diff --git a/drivers/platform/x86/bitland-mifs-wmi.c b/drivers/platform/x86/bitland-mifs-wmi.c index 81dad2b65f4f..17792d8b7c29 100644 --- a/drivers/platform/x86/bitland-mifs-wmi.c +++ b/drivers/platform/x86/bitland-mifs-wmi.c @@ -78,6 +78,46 @@ 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, +}; + enum bitland_mifs_event_id { WMI_EVENT_RESERVED_1 = 1, WMI_EVENT_RESERVED_2 = 2, @@ -163,6 +203,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; }; @@ -193,6 +234,7 @@ 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 = { .reserved1 = 0, .operation = WMI_METHOD_GET, @@ -200,32 +242,29 @@ static int laptop_profile_get(struct device *dev, .function = 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 = WMI_METHOD_GET, @@ -252,6 +291,7 @@ 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 = { .reserved1 = 0, .operation = WMI_METHOD_SET, @@ -259,42 +299,46 @@ static int laptop_profile_set(struct device *dev, .function = 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; } @@ -717,6 +761,7 @@ static int bitland_mifs_wmi_probe(struct wmi_device *wdev, const void *context) return -ENOMEM; drv_data->wdev = wdev; + drv_data->ops = &bitland_ops; ret = devm_mutex_init(&wdev->dev, &drv_data->lock); if (ret) -- 2.55.0