From patchwork Wed Aug 13 16:56:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Samuel Ortiz X-Patchwork-Id: 4720011 Return-Path: X-Original-To: patchwork-linux-acpi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C5B4C9F377 for ; Wed, 13 Aug 2014 17:00:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A115F201D3 for ; Wed, 13 Aug 2014 17:00:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BF9B5201C0 for ; Wed, 13 Aug 2014 17:00:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753519AbaHMRAA (ORCPT ); Wed, 13 Aug 2014 13:00:00 -0400 Received: from mga11.intel.com ([192.55.52.93]:30393 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752829AbaHMRAA (ORCPT ); Wed, 13 Aug 2014 13:00:00 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP; 13 Aug 2014 09:59:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.01,857,1400050800"; d="scan'208";a="576202039" Received: from unknown (HELO zurbaran) ([10.237.24.32]) by fmsmga001.fm.intel.com with ESMTP; 13 Aug 2014 09:59:58 -0700 From: Samuel Ortiz To: rjw@rjwysocki.net Cc: linux-acpi@vger.kernel.org, Faouaz TENOUTIT Subject: [PATCH v3 2/2] ACPI: Export PLD (Physical Location of Device) Date: Wed, 13 Aug 2014 18:56:41 +0200 Message-Id: <1407949001-6567-2-git-send-email-sameo@linux.intel.com> X-Mailer: git-send-email 2.0.0 In-Reply-To: <1407949001-6567-1-git-send-email-sameo@linux.intel.com> References: <1407949001-6567-1-git-send-email-sameo@linux.intel.com> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Faouaz TENOUTIT This patch exports a sysfs directory with ACPI _PLD information: $ ls -l /sys/bus/acpi/devices/ACPI-DEV/pld -r--r--r-- root root 4096 2014-05-30 08:39 panel -r--r--r-- root root 4096 2014-05-30 08:39 revision -r--r--r-- root root 4096 2014-05-30 08:39 rotation -r--r--r-- root root 4096 2014-05-30 08:39 shape This information can be used by user applications to: - Determine which specific connector or device input mechanism may be used for a given task. - Describes which panel surface of the system's housing the device connection point resides on (Front, Back, ...) More information about these _PLD fields can be found here: Documentation/ABI/testing/sysfs-bus-acpi Signed-off-by: Faouaz TENOUTIT Acked-by: Samuel Ortiz Acked-by: Andrew J Ross --- Documentation/ABI/testing/sysfs-bus-acpi | 60 ++++++++++++++++++++++++++++++++ drivers/acpi/scan.c | 53 ++++++++++++++++++++++++---- 2 files changed, 107 insertions(+), 6 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-bus-acpi b/Documentation/ABI/testing/sysfs-bus-acpi index 7fa9cbc..be58159 100644 --- a/Documentation/ABI/testing/sysfs-bus-acpi +++ b/Documentation/ABI/testing/sysfs-bus-acpi @@ -56,3 +56,63 @@ Description: Writing 1 to this attribute will trigger hot removal of this device object. This file exists for every device object that has _EJ0 method. + +What: /sys/bus/acpi/devices/.../pld +Date: August 2014 +Contact: Faouaz Tenoutit +Description: + This optional directory provides description of the physical + location, orientation and position of external devices. + It is for example used to describe how camera sensors are + physically mounted and allows user space software to rotate + images accordingly. + +What: /sys/bus/acpi/devices/.../pld/revision +Date: August 2014 +Contact: Faouaz Tenoutit +Description: + The current Revision is 0x2 + +What: /sys/bus/acpi/devices/.../pld/panel +Date: August 2014 +Contact: Faouaz Tenoutit +Description: + Describes which panel surface of the system's housing the device + connection point resides on: + 0 Top + 1 Bottom + 2 Left + 3 Right + 4 Front + 5 Back + 6 Unknown + +What: /sys/bus/acpi/devices/.../pld/shape +Date: August 2014 +Contact: Faouaz Tenoutit +Description: + Describes the shape of the device connection point: + 0 Round + 1 Oval + 2 Square + 3 Vertical Rectangle + 4 Horizontal Rectangle + 5 Vertical Trapezoid + 6 Horizontal Trapezoid + 7 Unknown - Shape rendered as a Rectangle with dotted lines + 8 Chamfered + +What: /sys/bus/acpi/devices/.../pld/rotation +Date: August 2014 +Contact: Faouaz Tenoutit +Description: + Rotates the Shape clockwise in 45 degree steps around its + origin where: + 0 0° + 1 45° + 2 90° + 3 135° + 4 180° + 5 225° + 6 270° + 7 315° diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index 2ca42d5..4f2b91b 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c @@ -686,6 +686,36 @@ static ssize_t status_show(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR_RO(status); +#define ACPI_SYSFS_PLD_PROP(prop) \ +static ssize_t prop##_show(struct device *dev, \ + struct device_attribute *attr, \ + char *buf) { \ + struct acpi_device *acpi_dev = to_acpi_device(dev); \ + return sprintf(buf, "%d\n", acpi_dev->pld->prop); \ +}; \ +static DEVICE_ATTR_RO(prop) + +/* + * sysfs PLD parameters + */ +ACPI_SYSFS_PLD_PROP(revision); +ACPI_SYSFS_PLD_PROP(panel); +ACPI_SYSFS_PLD_PROP(shape); +ACPI_SYSFS_PLD_PROP(rotation); + +static struct attribute *acpi_pld_attrs[] = { + &dev_attr_revision.attr, + &dev_attr_panel.attr, + &dev_attr_shape.attr, + &dev_attr_rotation.attr, + NULL, +}; + +static const struct attribute_group acpi_pld_attr_group = { + .name = "pld", + .attrs = acpi_pld_attrs, +}; + static int acpi_device_setup_files(struct acpi_device *dev) { struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL}; @@ -768,11 +798,20 @@ static int acpi_device_setup_files(struct acpi_device *dev) } /* - * If device has _PLD, initialize the 'pld' struct + * If device has _PLD, 'pld' directory is created */ - if (acpi_has_method(dev->handle, "_PLD")) - acpi_get_physical_device_location(dev->handle, - &dev->pld); + if (acpi_has_method(dev->handle, "_PLD")) { + status = acpi_get_physical_device_location(dev->handle, + &dev->pld); + if (ACPI_SUCCESS(status)) { + result = sysfs_create_group(&dev->dev.kobj, + &acpi_pld_attr_group); + if (result) { + ACPI_FREE(dev->pld); + dev->pld = NULL; + } + } + } end: return result; @@ -815,10 +854,12 @@ static void acpi_device_remove_files(struct acpi_device *dev) device_remove_file(&dev->dev, &dev_attr_path); /* - * If device has _PLD, free 'pld' struct + * If device has _PLD, remove 'pld' directory */ - if (dev->pld) + if (dev->pld) { + sysfs_remove_group(&dev->dev.kobj, &acpi_pld_attr_group); ACPI_FREE(dev->pld); + } } /* -------------------------------------------------------------------------- ACPI Bus operations