All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ACPI: device_sysfs: Add sysfs support for _PLD
@ 2022-01-26 23:58 Won Chung
  2022-01-27 20:37 ` Benson Leung
  0 siblings, 1 reply; 2+ messages in thread
From: Won Chung @ 2022-01-26 23:58 UTC (permalink / raw)
  To: Rafael J . Wysocki, Len Brown, Benson Leung, Prashant Malani,
	linux-acpi, linux-kernel
  Cc: Won Chung

When ACPI table includes _PLD fields for a device, create a new file
(pld) in sysfs to share _PLD fields.

Signed-off-by: Won Chung <wonchung@google.com>
---
 drivers/acpi/device_sysfs.c | 42 +++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/drivers/acpi/device_sysfs.c b/drivers/acpi/device_sysfs.c
index d5d6403ba07b..8d4df5fb1c45 100644
--- a/drivers/acpi/device_sysfs.c
+++ b/drivers/acpi/device_sysfs.c
@@ -509,6 +509,40 @@ static ssize_t status_show(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR_RO(status);
 
+static ssize_t pld_show(struct device *dev, struct device_attribute *attr,
+			char *buf)
+{
+	struct acpi_device *acpi_dev = to_acpi_device(dev);
+	acpi_status status;
+	struct acpi_pld_info *pld;
+
+	status = acpi_get_physical_device_location(acpi_dev->handle, &pld);
+	if (ACPI_FAILURE(status))
+		return -ENODEV;
+
+	return sprintf(buf, "GROUP_TOKEN=%u\n"
+		"GROUP_POSITION=%u\n"
+		"USER_VISIBLE=%u\n"
+		"DOCK=%u\n"
+		"BAY=%u\n"
+		"LID=%u\n"
+		"PANEL=%u\n"
+		"HORIZONTAL_POSITION=%u\n"
+		"VERTICAL_POSITION=%u\n"
+		"SHAPE=%u\n",
+		pld->group_token,
+		pld->group_position,
+		pld->user_visible,
+		pld->dock,
+		pld->bay,
+		pld->lid,
+		pld->panel,
+		pld->horizontal_position,
+		pld->vertical_position,
+		pld->shape);
+}
+static DEVICE_ATTR_RO(pld);
+
 /**
  * acpi_device_setup_files - Create sysfs attributes of an ACPI device.
  * @dev: ACPI device object.
@@ -595,6 +629,12 @@ int acpi_device_setup_files(struct acpi_device *dev)
 						    &dev_attr_real_power_state);
 	}
 
+	if (acpi_has_method(dev->handle, "_PLD")) {
+		result = device_create_file(&dev->dev, &dev_attr_pld);
+		if (result)
+			goto end;
+	}
+
 	acpi_expose_nondev_subnodes(&dev->dev.kobj, &dev->data);
 
 end:
@@ -645,4 +685,6 @@ void acpi_device_remove_files(struct acpi_device *dev)
 		device_remove_file(&dev->dev, &dev_attr_status);
 	if (dev->handle)
 		device_remove_file(&dev->dev, &dev_attr_path);
+	if (acpi_has_method(dev->handle, "_PLD"))
+		device_remove_file(&dev->dev, &dev_attr_pld);
 }
-- 
2.35.0.rc0.227.g00780c9af4-goog


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ACPI: device_sysfs: Add sysfs support for _PLD
  2022-01-26 23:58 [PATCH] ACPI: device_sysfs: Add sysfs support for _PLD Won Chung
@ 2022-01-27 20:37 ` Benson Leung
  0 siblings, 0 replies; 2+ messages in thread
From: Benson Leung @ 2022-01-27 20:37 UTC (permalink / raw)
  To: Won Chung
  Cc: Rafael J . Wysocki, Len Brown, Benson Leung, Prashant Malani,
	linux-acpi, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2705 bytes --]

Hi Won,

On Wed, Jan 26, 2022 at 11:58:07PM +0000, Won Chung wrote:
> When ACPI table includes _PLD fields for a device, create a new file
> (pld) in sysfs to share _PLD fields.

If you're adding a new attribute, you should also update the Documentation
file here: Documentation/ABI/testing/sysfs-bus-acpi

Thanks,
Benson


> 
> Signed-off-by: Won Chung <wonchung@google.com>
> ---
>  drivers/acpi/device_sysfs.c | 42 +++++++++++++++++++++++++++++++++++++
>  1 file changed, 42 insertions(+)
> 
> diff --git a/drivers/acpi/device_sysfs.c b/drivers/acpi/device_sysfs.c
> index d5d6403ba07b..8d4df5fb1c45 100644
> --- a/drivers/acpi/device_sysfs.c
> +++ b/drivers/acpi/device_sysfs.c
> @@ -509,6 +509,40 @@ static ssize_t status_show(struct device *dev, struct device_attribute *attr,
>  }
>  static DEVICE_ATTR_RO(status);
>  
> +static ssize_t pld_show(struct device *dev, struct device_attribute *attr,
> +			char *buf)
> +{
> +	struct acpi_device *acpi_dev = to_acpi_device(dev);
> +	acpi_status status;
> +	struct acpi_pld_info *pld;
> +
> +	status = acpi_get_physical_device_location(acpi_dev->handle, &pld);
> +	if (ACPI_FAILURE(status))
> +		return -ENODEV;
> +
> +	return sprintf(buf, "GROUP_TOKEN=%u\n"
> +		"GROUP_POSITION=%u\n"
> +		"USER_VISIBLE=%u\n"
> +		"DOCK=%u\n"
> +		"BAY=%u\n"
> +		"LID=%u\n"
> +		"PANEL=%u\n"
> +		"HORIZONTAL_POSITION=%u\n"
> +		"VERTICAL_POSITION=%u\n"
> +		"SHAPE=%u\n",
> +		pld->group_token,
> +		pld->group_position,
> +		pld->user_visible,
> +		pld->dock,
> +		pld->bay,
> +		pld->lid,
> +		pld->panel,
> +		pld->horizontal_position,
> +		pld->vertical_position,
> +		pld->shape);
> +}
> +static DEVICE_ATTR_RO(pld);
> +
>  /**
>   * acpi_device_setup_files - Create sysfs attributes of an ACPI device.
>   * @dev: ACPI device object.
> @@ -595,6 +629,12 @@ int acpi_device_setup_files(struct acpi_device *dev)
>  						    &dev_attr_real_power_state);
>  	}
>  
> +	if (acpi_has_method(dev->handle, "_PLD")) {
> +		result = device_create_file(&dev->dev, &dev_attr_pld);
> +		if (result)
> +			goto end;
> +	}
> +
>  	acpi_expose_nondev_subnodes(&dev->dev.kobj, &dev->data);
>  
>  end:
> @@ -645,4 +685,6 @@ void acpi_device_remove_files(struct acpi_device *dev)
>  		device_remove_file(&dev->dev, &dev_attr_status);
>  	if (dev->handle)
>  		device_remove_file(&dev->dev, &dev_attr_path);
> +	if (acpi_has_method(dev->handle, "_PLD"))
> +		device_remove_file(&dev->dev, &dev_attr_pld);
>  }
> -- 
> 2.35.0.rc0.227.g00780c9af4-goog
> 

-- 
Benson Leung
Staff Software Engineer
Chrome OS Kernel
Google Inc.
bleung@google.com
Chromium OS Project
bleung@chromium.org

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-27 20:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-26 23:58 [PATCH] ACPI: device_sysfs: Add sysfs support for _PLD Won Chung
2022-01-27 20:37 ` Benson Leung

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.