driver core: Add sysfs support for physical location of a device
PATCH v2 1/1 driver core: Add sysfs support for physical location of a device
When ACPI table includes _PLD fields for a device, create a new directory (physical_location) in sysfs to share _PLD fields.
Currently without PLD information, when there are multiple of same devices, it is hard to distinguish which device corresponds to which physical device at which location. For example, when there are two Type C connectors, it is hard to find out which connector corresponds to the Type C port on the left panel versus the Type C port on the right panel. With PLD information provided, we can determine which specific device at which location is doing what.
_PLD output includes much more fields, but only generic fields are added and exposed to sysfs, so that non-ACPI devices can also support it in the future. The minimal generic fields needed for locating a device are the following.
- panel
- vertical_position
- horizontal_position
- dock
- lid
--- .../testing/sysfs-devices-physical_location | 42 ++++++ drivers/base/core.c | 139 ++++++++++++++++++ include/linux/device.h | 73 +++++++++ 3 files changed, 254 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-devices-physical_location
Documentation/ABI/testing/sysfs-devices-physical_location new file +42 -0
@@ -0,0 +1,42 @@ +What: /sys/devices/.../physical_location +Date: March 2022 +Contact: Won Chung <[email protected]> +Description: + This directory contains information on physical location of + the device connection point with respect to the system's + housing. + +What: /sys/devices/.../physical_location/panel +Date: March 2022 +Contact: Won Chung <[email protected]> +Description: + Describes which panel surface of the system’s housing the + device connection point resides on. + +What: /sys/devices/.../physical_location/vertical_position +Date: March 2022 +Contact: Won Chung <[email protected]> +Description: + Describes vertical position of the device connection point on + the panel surface. + +What: /sys/devices/.../physical_location/horizontal_position +Date: March 2022 +Contact: Won Chung <[email protected]> +Description: + Describes horizontal position of the device connection point on + the panel surface. + +What: /sys/devices/.../physical_location/dock +Date: March 2022 +Contact: Won Chung <[email protected]> +Description: + "Yes" if the device connection point resides in a docking + station or a port replicator. "No" otherwise. + +What: /sys/devices/.../physical_location/lid +Date: March 2022 +Contact: Won Chung <[email protected]> +Description: + "Yes" if the device connection point resides on the lid of + laptop system. "No" otherwise.
drivers/base/core.c +139 -0
153 lines not on this page · raw message
include/linux/device.h +73 -0
91 lines not on this page · raw message
Signature · 1 line
2.35.1.616.g0bdcbb4464-goog
Greg Kroah-Hartman
maintainerQuoted 5 lines · Won Chung
Documentation/ABI/testing/sysfs-devices-physical_location new file +2
-0@@ -0,0 +1,42 @@ +What: /sys/devices/.../physical_location +Date: March 2022
Documentation/ABI/testing/sysfs-devices-physical_location line 12
Quoted 10 lines
Documentation/ABI/testing/sysfs-devices-physical_location new file +10
-0+Contact: Won Chung <[email protected]> +Description: + This directory contains information on physical location of + the device connection point with respect to the system's + housing. + +What: /sys/devices/.../physical_location/panel +Date: March 2022 +Contact: Won Chung <[email protected]> +Description:
Use tabs everywhere please, stop mixing spaces and tabs in the same file :(
Quoted 18 lines
Documentation/ABI/testing/sysfs-devices-physical_location new file +18
-0+static ssize_t panel_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + const char *panel; + + switch (dev->location.panel) { + case DEVICE_PANEL_TOP: + panel = "top"; + break; + case DEVICE_PANEL_BOTTOM: + panel = "bottom"; + break; + case DEVICE_PANEL_LEFT: + panel = "left"; + break; + case DEVICE_PANEL_RIGHT: + panel = "right"; + break;
Documentation/ABI/testing/sysfs-devices-physical_location line 40
Quoted 10 lines
Documentation/ABI/testing/sysfs-devices-physical_location new file +10
-0+ case DEVICE_PANEL_FRONT: + panel = "front"; + break; + case DEVICE_PANEL_BACK: + panel = "back"; + break; + default: + panel = "unknown"; + } + return sprintf(buf, "%s\n", panel);
Always use sysfs_emit() for new sysfs files.
thanks,
greg k-h