All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Fuwei Xie <12313607@mail.sustech.edu.cn>
Cc: "Hans de Goede" <hansg@kernel.org>,
	platform-driver-x86@vger.kernel.org,
	LKML <linux-kernel@vger.kernel.org>,
	"Eren Özen" <erenozen@protonmail.com>,
	"Zheng Shuyang" <yhshzh0@gmail.com>
Subject: Re: [PATCH v4 2/5] platform/x86: huawei-wmi: bind the Huawei method device
Date: Tue, 1 Dec 2026 12:57:37 +0200 (EET)	[thread overview]
Message-ID: <1a1e7f60-2bdd-3423-787c-6c6fa601b157@linux.intel.com> (raw)
In-Reply-To: <F4EE7D34C4C37A5E+20261130101218.243426-3-12313607@mail.sustech.edu.cn>

On Mon, 30 Nov 2026, Fuwei Xie wrote:

> Bind the method GUID on the WMI bus and give its platform device the
> bound wdev for method calls. Unregister the platform device before the
> method driver releases the binding. Keep the platform sysfs location
> and the input-only path on machines without the method GUID.
> 
> Allocate platform state on probe and unwind previously registered
> input handlers if a later input device fails to register.
> 
> Signed-off-by: Fuwei Xie <12313607@mail.sustech.edu.cn>
> ---
>  drivers/platform/x86/huawei-wmi.c | 109 ++++++++++++++++++++----------
>  1 file changed, 75 insertions(+), 34 deletions(-)
> 
> diff --git a/drivers/platform/x86/huawei-wmi.c b/drivers/platform/x86/huawei-wmi.c
> index 559731d15..690bd0abc 100644
> --- a/drivers/platform/x86/huawei-wmi.c
> +++ b/drivers/platform/x86/huawei-wmi.c
> @@ -60,6 +60,7 @@ struct huawei_wmi_debug {
>  };
>  
>  struct huawei_wmi {
> +	struct wmi_device *wdev;
>  	bool battery_available;
>  	bool fn_lock_available;
>  
> @@ -156,7 +157,7 @@ static int huawei_wmi_call(struct huawei_wmi *huawei,
>  	acpi_status status;
>  
>  	mutex_lock(&huawei->wmi_lock);
> -	status = wmi_evaluate_method(HWMI_METHOD_GUID, 0, 1, in, out);
> +	status = wmidev_evaluate_method(huawei->wdev, 0, 1, in, out);
>  	mutex_unlock(&huawei->wmi_lock);
>  	if (ACPI_FAILURE(status)) {
>  		dev_err(huawei->dev, "Failed to evaluate wmi method\n");
> @@ -880,25 +881,36 @@ static const struct wmi_device_id huawei_wmi_events_id_table[] = {
>  
>  static int huawei_wmi_probe(struct platform_device *pdev)
>  {
> -	const struct wmi_device_id *guid = huawei_wmi_events_id_table;
> +	const struct wmi_device_id *guid;
> +	struct wmi_device **method = dev_get_platdata(&pdev->dev);
>  	int err;
>  
> +	huawei_wmi = devm_kzalloc(&pdev->dev, sizeof(*huawei_wmi), GFP_KERNEL);
> +	if (!huawei_wmi)
> +		return -ENOMEM;
> +
> +	huawei_wmi->wdev = method ? *method : NULL;
>  	platform_set_drvdata(pdev, huawei_wmi);
>  	huawei_wmi->dev = &pdev->dev;
>  
> -	while (*guid->guid_string) {
> -		if (wmi_has_guid(guid->guid_string)) {
> -			err = huawei_wmi_input_setup(&pdev->dev, guid->guid_string);
> -			if (err) {
> -				dev_err(&pdev->dev, "Failed to setup input on %s\n", guid->guid_string);
> -				return err;
> -			}
> -		}
> +	for (guid = huawei_wmi_events_id_table; *guid->guid_string; guid++) {
> +		if (!wmi_has_guid(guid->guid_string))
> +			continue;
>  
> -		guid++;
> +		err = huawei_wmi_input_setup(&pdev->dev, guid->guid_string);
> +		if (!err)
> +			continue;
> +
> +		dev_err(&pdev->dev, "Failed to setup input on %s\n", guid->guid_string);
> +		while (guid != huawei_wmi_events_id_table) {
> +			guid--;
> +			if (wmi_has_guid(guid->guid_string))
> +				huawei_wmi_input_exit(&pdev->dev, guid->guid_string);
> +		}
> +		return err;
>  	}
>  
> -	if (wmi_has_guid(HWMI_METHOD_GUID)) {
> +	if (huawei_wmi->wdev) {
>  		mutex_init(&huawei_wmi->wmi_lock);
>  
>  		huawei_wmi_leds_setup(&pdev->dev);
> @@ -921,7 +933,7 @@ static void huawei_wmi_remove(struct platform_device *pdev)
>  		guid++;
>  	}
>  
> -	if (wmi_has_guid(HWMI_METHOD_GUID)) {
> +	if (huawei_wmi->wdev) {
>  		huawei_wmi_debugfs_exit(&pdev->dev);
>  		huawei_wmi_battery_exit(&pdev->dev);
>  		huawei_wmi_fn_lock_exit(&pdev->dev);
> @@ -936,14 +948,46 @@ static struct platform_driver huawei_wmi_driver = {
>  	.remove = huawei_wmi_remove,
>  };
>  
> -static __init int huawei_wmi_init(void)
> +/*
> + * Keep the platform device and its existing userspace paths on both
> + * method-capable and older event-only machines.
> + */
> +static struct platform_device *legacy_pdev;
> +
> +static int huawei_wmi_method_probe(struct wmi_device *wdev, const void *context)
>  {
>  	struct platform_device *pdev;
> -	int err;
>  
> -	huawei_wmi = kzalloc_obj(struct huawei_wmi);
> -	if (!huawei_wmi)
> -		return -ENOMEM;
> +	pdev = platform_device_register_data(NULL, "huawei-wmi", PLATFORM_DEVID_NONE,
> +					     &wdev, sizeof(wdev));
> +	if (IS_ERR(pdev))
> +		return PTR_ERR(pdev);
> +
> +	dev_set_drvdata(&wdev->dev, pdev);
> +	return 0;
> +}
> +
> +static void huawei_wmi_method_remove(struct wmi_device *wdev)
> +{
> +	platform_device_unregister(dev_get_drvdata(&wdev->dev));
> +}
> +
> +static const struct wmi_device_id huawei_wmi_method_ids[] = {
> +	{ HWMI_METHOD_GUID },
> +	{ }
> +};
> +MODULE_DEVICE_TABLE(wmi, huawei_wmi_method_ids);
> +
> +static struct wmi_driver huawei_wmi_method_driver = {
> +	.driver.name = "huawei-wmi-method",
> +	.id_table = huawei_wmi_method_ids,
> +	.probe = huawei_wmi_method_probe,
> +	.remove = huawei_wmi_method_remove,
> +};
> +
> +static __init int huawei_wmi_init(void)
> +{
> +	int err;
>  
>  	quirks = &quirk_unknown;
>  	dmi_check_system(huawei_quirks);
> @@ -954,37 +998,34 @@ static __init int huawei_wmi_init(void)
>  
>  	err = platform_driver_register(&huawei_wmi_driver);
>  	if (err)
> -		goto pdrv_err;
> +		return err;
>  
> -	pdev = platform_device_register_simple("huawei-wmi", PLATFORM_DEVID_NONE, NULL, 0);
> -	if (IS_ERR(pdev)) {
> -		err = PTR_ERR(pdev);
> -		goto pdev_err;
> +	if (wmi_has_guid(HWMI_METHOD_GUID)) {
> +		err = wmi_driver_register(&huawei_wmi_method_driver);
> +	} else {
> +		legacy_pdev = platform_device_register_simple("huawei-wmi", PLATFORM_DEVID_NONE,
> +							      NULL, 0);
> +		err = PTR_ERR_OR_ZERO(legacy_pdev);
>  	}
> +	if (err)
> +		platform_driver_unregister(&huawei_wmi_driver);

The old rollback path was better than this.

Armin, is this legacy_pdev approach what is supposed to be used?

> -	return 0;
> -
> -pdev_err:
> -	platform_driver_unregister(&huawei_wmi_driver);
> -pdrv_err:
> -	kfree(huawei_wmi);
>  	return err;
>  }
>  
>  static __exit void huawei_wmi_exit(void)
>  {
> -	struct platform_device *pdev = to_platform_device(huawei_wmi->dev);
> +	if (legacy_pdev)
> +		platform_device_unregister(legacy_pdev);
> +	else
> +		wmi_driver_unregister(&huawei_wmi_method_driver);
>  
> -	platform_device_unregister(pdev);
>  	platform_driver_unregister(&huawei_wmi_driver);
> -
> -	kfree(huawei_wmi);
>  }
>  
>  module_init(huawei_wmi_init);
>  module_exit(huawei_wmi_exit);
>  
> -MODULE_ALIAS("wmi:"HWMI_METHOD_GUID);
>  MODULE_DEVICE_TABLE(wmi, huawei_wmi_events_id_table);
>  MODULE_AUTHOR("Ayman Bagabas <ayman.bagabas@gmail.com>");
>  MODULE_DESCRIPTION("Huawei WMI laptop extras driver");
> 

-- 
 i.


  reply	other threads:[~2026-12-01 10:57 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20261130101218.243426-1-12313607@mail.sustech.edu.cn>
2026-11-30 10:12 ` [PATCH v4 1/5] platform/x86: huawei-wmi: scope method responses to each call Fuwei Xie
2026-12-01 10:40   ` Ilpo Järvinen
2026-11-30 10:12 ` [PATCH v4 2/5] platform/x86: huawei-wmi: bind the Huawei method device Fuwei Xie
2026-12-01 10:57   ` Ilpo Järvinen [this message]
2026-11-30 10:12 ` [PATCH v4 3/5] platform/x86: huawei-wmi: use the sized WMI method interface Fuwei Xie
2026-12-01 11:09   ` Ilpo Järvinen
2026-11-30 10:12 ` [PATCH v4 4/5] platform/x86: huawei-wmi: expose native firmware power profiles Fuwei Xie
2026-11-30 10:12 ` [PATCH v4 5/5] platform/x86: huawei-wmi: bind hotkeys and key data on the WMI bus Fuwei Xie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1a1e7f60-2bdd-3423-787c-6c6fa601b157@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=12313607@mail.sustech.edu.cn \
    --cc=erenozen@protonmail.com \
    --cc=hansg@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=yhshzh0@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.