platform-driver-x86.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luke Jones <luke@ljones.dev>
To: hdegoede@redhat.com
Cc: markgross@kernel.org, platform-driver-x86@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 6/6] asus-wmi: Add support for dGPU-only mode
Date: Mon, 08 Aug 2022 20:38:33 +1200	[thread overview]
Message-ID: <90GAGR.D69M1ZE8ZLC21@ljones.dev> (raw)
In-Reply-To: <20220808030420.8633-7-luke@ljones.dev>

It appears I have included the wrong dgpu-only patch. This one has 
mistakes in it and early testing...

I will include the fixed one in the next version after review.

Kind regards,
Luke.

On Mon, Aug 8 2022 at 15:04:20 +1200, Luke D. Jones <luke@ljones.dev> 
wrote:
> Adds support for a dGPU-only mode on some laptops where when enabled
> the boot GPU is the dGPU, and the iGPU is not visible.
> 
> Signed-off-by: Luke D. Jones <luke@ljones.dev>
> ---
>  .../ABI/testing/sysfs-platform-asus-wmi       |  9 ++
>  drivers/platform/x86/asus-wmi.c               | 92 
> +++++++++++++++++++
>  include/linux/platform_data/x86/asus-wmi.h    |  3 +
>  3 files changed, 104 insertions(+)
> 
> diff --git a/Documentation/ABI/testing/sysfs-platform-asus-wmi 
> b/Documentation/ABI/testing/sysfs-platform-asus-wmi
> index 66b262476d92..93d111a65313 100644
> --- a/Documentation/ABI/testing/sysfs-platform-asus-wmi
> +++ b/Documentation/ABI/testing/sysfs-platform-asus-wmi
> @@ -77,6 +77,15 @@ Description:
>  			* 0 - Disable,
>  			* 1 - Enable,
> 
> +What:		/sys/devices/platform/<platform>/dgpu_only
> +Date:		Aug 2022
> +KernelVersion:	6.0
> +Contact:	"Luke Jones" <luke@ljones.dev>
> +Description:
> +		Set the dGPU to be the only GPU available:
> +			* 0 - Disable,
> +			* 1 - Enable,
> +
>  What:		/sys/devices/platform/<platform>/panel_od
>  Date:		Aug 2022
>  KernelVersion:	5.17
> diff --git a/drivers/platform/x86/asus-wmi.c 
> b/drivers/platform/x86/asus-wmi.c
> index b9e5d87e3e18..840299828512 100644
> --- a/drivers/platform/x86/asus-wmi.c
> +++ b/drivers/platform/x86/asus-wmi.c
> @@ -246,6 +246,9 @@ struct asus_wmi {
>  	bool dgpu_disable_available;
>  	bool dgpu_disable;
> 
> +	bool dgpu_only_available;
> +	bool dgpu_only;
> +
>  	bool keyboard_rgb_state_available;
>  	bool keyboard_rgb_mode_available;
>  	struct keyboard_rgb_led keyboard_rgb_mode;
> @@ -750,6 +753,87 @@ static ssize_t egpu_enable_store(struct device 
> *dev,
> 
>  static DEVICE_ATTR_RW(egpu_enable);
> 
> +/* dedicated GPU only 
> *********************************************************/
> +static int dgpu_only_check_present(struct asus_wmi *asus)
> +{
> +	u32 result;
> +	int err;
> +
> +	asus->dgpu_only_available = false;
> +
> +	err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_DGPU, &result);
> +	if (err) {
> +		if (err == -ENODEV)
> +			return 0;
> +		return err;
> +	}
> +
> +	if (result & ASUS_WMI_DSTS_PRESENCE_BIT) {
> +		asus->dgpu_only_available = true;
> +		asus->dgpu_only = result & ASUS_WMI_DSTS_STATUS_BIT;
> +	}
> +
> +	return 0;
> +}
> +
> +static int dgpu_only_write(struct asus_wmi *asus)
> +{
> +	u32 retval;
> +	u8 value;
> +	int err;
> +
> +	/* Don't rely on type conversion */
> +	value = asus->dgpu_only ? 1 : 0;
> +
> +	err = asus_wmi_set_devstate(ASUS_WMI_DEVID_DGPU, value, &retval);
> +	if (err) {
> +		pr_warn("Failed to set dGPU-only mode: %d\n", err);
> +		return err;
> +	}
> +
> +	if (retval > 1) {
> +		pr_warn("Failed to set dGPU-only mode (retval): 0x%x\n", retval);
> +		return -EIO;
> +	}
> +
> +	sysfs_notify(&asus->platform_device->dev.kobj, NULL, "dgpu_only");
> +
> +	return 0;
> +}
> +
> +static ssize_t dgpu_only_show(struct device *dev,
> +				   struct device_attribute *attr, char *buf)
> +{
> +	struct asus_wmi *asus = dev_get_drvdata(dev);
> +	u8 mode = asus->dgpu_only;
> +
> +	return sysfs_emit(buf, "%d\n", mode);
> +}
> +
> +static ssize_t dgpu_only_store(struct device *dev,
> +				    struct device_attribute *attr,
> +				    const char *buf, size_t count)
> +{
> +	bool enable;
> +	int result;
> +
> +	struct asus_wmi *asus = dev_get_drvdata(dev);
> +
> +	result = kstrtobool(buf, &enable);
> +	if (result)
> +		return result;
> +
> +	asus->dgpu_only = enable;
> +
> +	result = dgpu_only_write(asus);
> +	if (result)
> +		return result;
> +
> +	return count;
> +}
> +
> +static DEVICE_ATTR_RW(dgpu_only);
> +
>  /* TUF Laptop Keyboard RGB Modes 
> **********************************************/
>  static int keyboard_rgb_mode_check_present(struct asus_wmi *asus)
>  {
> @@ -3473,6 +3557,7 @@ static struct attribute *platform_attributes[] 
> = {
>  	&dev_attr_touchpad.attr,
>  	&dev_attr_egpu_enable.attr,
>  	&dev_attr_dgpu_disable.attr,
> +	&dev_attr_dgpu_only.attr,
>  	&dev_attr_keyboard_rgb_mode.attr,
>  	&dev_attr_keyboard_rgb_mode_index.attr,
>  	&dev_attr_keyboard_rgb_state.attr,
> @@ -3507,6 +3592,8 @@ static umode_t asus_sysfs_is_visible(struct 
> kobject *kobj,
>  		ok = asus->egpu_enable_available;
>  	else if (attr == &dev_attr_dgpu_disable.attr)
>  		ok = asus->dgpu_disable_available;
> +	else if (attr == &dev_attr_dgpu_only.attr)
> +		ok = asus->dgpu_only_available;
>  	else if (attr == &dev_attr_keyboard_rgb_mode.attr)
>  		ok = asus->keyboard_rgb_mode_available;
>  	else if (attr == &dev_attr_keyboard_rgb_mode_index.attr)
> @@ -3784,6 +3871,10 @@ static int asus_wmi_add(struct platform_device 
> *pdev)
>  	if (err)
>  		goto fail_dgpu_disable;
> 
> +	err = dgpu_only_check_present(asus);
> +	if (err)
> +		goto fail_dgpu_only;
> +
>  	err = keyboard_rgb_mode_check_present(asus);
>  	if (err)
>  		goto fail_keyboard_rgb_mode;
> @@ -3906,6 +3997,7 @@ static int asus_wmi_add(struct platform_device 
> *pdev)
>  fail_fan_boost_mode:
>  fail_egpu_enable:
>  fail_dgpu_disable:
> +fail_dgpu_only:
>  fail_keyboard_rgb_mode:
>  fail_keyboard_rgb_state:
>  fail_platform:
> diff --git a/include/linux/platform_data/x86/asus-wmi.h 
> b/include/linux/platform_data/x86/asus-wmi.h
> index b5c966798ef8..76b0756a0666 100644
> --- a/include/linux/platform_data/x86/asus-wmi.h
> +++ b/include/linux/platform_data/x86/asus-wmi.h
> @@ -98,6 +98,9 @@
>  /* dgpu on/off */
>  #define ASUS_WMI_DEVID_DGPU		0x00090020
> 
> +/* Dedicated GPU only. When active the dGPU will be the only visible 
> GPU */
> +#define ASUS_WMI_DEVID_DEDICATED	0x00090016
> +
>  /* TUF laptop RGB control */
>  #define ASUS_WMI_DEVID_TUF_RGB_MODE	0x00100056
>  /* TUF laptop RGB state control */
> --
> 2.37.1
> 



  reply	other threads:[~2022-08-08  8:39 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-08  3:04 [PATCH v2 0/6] asus-wmi: Add support for RGB keyboards Luke D. Jones
2022-08-08  3:04 ` [PATCH v2 1/6] asus-wmi: Implement TUF laptop keyboard RGB control Luke D. Jones
2022-08-08  3:04 ` [PATCH v2 2/6] asus-wmi: Implement TUF laptop keyboard LED modes Luke D. Jones
2022-08-08 16:01   ` Andy Shevchenko
2022-08-08 21:43     ` Luke Jones
2022-08-09  7:20       ` Andy Shevchenko
2022-08-08  3:04 ` [PATCH v2 3/6] asus-wmi: Implement TUF laptop keyboard power states Luke D. Jones
2022-08-08 16:08   ` Andy Shevchenko
2022-08-08 23:27     ` Luke Jones
2022-08-09  8:29       ` Andy Shevchenko
2022-08-09 22:25         ` Luke Jones
2022-08-08  3:04 ` [PATCH v2 4/6] asus-wmi: Document previously added attributes Luke D. Jones
2022-08-08 16:11   ` Andy Shevchenko
2022-08-08  3:04 ` [PATCH v2 5/6] asus-wmi: Convert all attr-show to use sysfs_emit Luke D. Jones
2022-08-08 16:13   ` Andy Shevchenko
2022-08-08  3:04 ` [PATCH v2 6/6] asus-wmi: Add support for dGPU-only mode Luke D. Jones
2022-08-08  8:38   ` Luke Jones [this message]
2022-08-08 15:44   ` Andy Shevchenko
2022-08-08  3:26 ` [PATCH v2 0/6] asus-wmi: Add support for RGB keyboards Luke Jones

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=90GAGR.D69M1ZE8ZLC21@ljones.dev \
    --to=luke@ljones.dev \
    --cc=hdegoede@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=markgross@kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).