1 // SPDX-License-Identifier: GPL-2.0
3 * Device physical location support
5 * Author: Won Chung <wonchung@google.com>
8 #include <linux/acpi.h>
9 #include <linux/sysfs.h>
11 #include "physical_location.h"
13 bool dev_add_physical_location(struct device *dev)
15 struct acpi_pld_info *pld;
18 if (!has_acpi_companion(dev))
21 status = acpi_get_physical_device_location(ACPI_HANDLE(dev), &pld);
22 if (ACPI_FAILURE(status))
25 dev->physical_location =
26 kzalloc(sizeof(*dev->physical_location), GFP_KERNEL);
27 if (!dev->physical_location)
29 dev->physical_location->panel = pld->panel;
30 dev->physical_location->vertical_position = pld->vertical_position;
31 dev->physical_location->horizontal_position = pld->horizontal_position;
32 dev->physical_location->dock = pld->dock;
33 dev->physical_location->lid = pld->lid;
39 static ssize_t panel_show(struct device *dev, struct device_attribute *attr,
44 switch (dev->physical_location->panel) {
45 case DEVICE_PANEL_TOP:
48 case DEVICE_PANEL_BOTTOM:
51 case DEVICE_PANEL_LEFT:
54 case DEVICE_PANEL_RIGHT:
57 case DEVICE_PANEL_FRONT:
60 case DEVICE_PANEL_BACK:
66 return sysfs_emit(buf, "%s\n", panel);
68 static DEVICE_ATTR_RO(panel);
70 static ssize_t vertical_position_show(struct device *dev,
71 struct device_attribute *attr, char *buf)
73 const char *vertical_position;
75 switch (dev->physical_location->vertical_position) {
76 case DEVICE_VERT_POS_UPPER:
77 vertical_position = "upper";
79 case DEVICE_VERT_POS_CENTER:
80 vertical_position = "center";
82 case DEVICE_VERT_POS_LOWER:
83 vertical_position = "lower";
86 vertical_position = "unknown";
88 return sysfs_emit(buf, "%s\n", vertical_position);
90 static DEVICE_ATTR_RO(vertical_position);
92 static ssize_t horizontal_position_show(struct device *dev,
93 struct device_attribute *attr, char *buf)
95 const char *horizontal_position;
97 switch (dev->physical_location->horizontal_position) {
98 case DEVICE_HORI_POS_LEFT:
99 horizontal_position = "left";
101 case DEVICE_HORI_POS_CENTER:
102 horizontal_position = "center";
104 case DEVICE_HORI_POS_RIGHT:
105 horizontal_position = "right";
108 horizontal_position = "unknown";
110 return sysfs_emit(buf, "%s\n", horizontal_position);
112 static DEVICE_ATTR_RO(horizontal_position);
114 static ssize_t dock_show(struct device *dev, struct device_attribute *attr,
117 return sysfs_emit(buf, "%s\n",
118 dev->physical_location->dock ? "yes" : "no");
120 static DEVICE_ATTR_RO(dock);
122 static ssize_t lid_show(struct device *dev, struct device_attribute *attr,
125 return sysfs_emit(buf, "%s\n",
126 dev->physical_location->lid ? "yes" : "no");
128 static DEVICE_ATTR_RO(lid);
130 static struct attribute *dev_attr_physical_location[] = {
131 &dev_attr_panel.attr,
132 &dev_attr_vertical_position.attr,
133 &dev_attr_horizontal_position.attr,
139 const struct attribute_group dev_attr_physical_location_group = {
140 .name = "physical_location",
141 .attrs = dev_attr_physical_location,