From patchwork Tue Mar 1 02:26:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Won Chung X-Patchwork-Id: 547490 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1623C433F5 for ; Tue, 1 Mar 2022 02:26:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230140AbiCAC1L (ORCPT ); Mon, 28 Feb 2022 21:27:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230469AbiCAC1I (ORCPT ); Mon, 28 Feb 2022 21:27:08 -0500 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF16A1116D for ; Mon, 28 Feb 2022 18:26:28 -0800 (PST) Received: by mail-pg1-x549.google.com with SMTP id n188-20020a6340c5000000b003747606cb0dso7640278pga.6 for ; Mon, 28 Feb 2022 18:26:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc :content-transfer-encoding; bh=IyH14F+agd7W5xUCOqF8MHhvzX444waYtpTecHVWge8=; b=E4T6jfR2vKlUdEvn/QMIBFysWTfRWfiW0LpBXD08E1oAZR2ETPFwty2DkXh52NXwHJ xdZomPm6cmuuT0ovcrNdyGNQ7RdbmpJ8rdbYZ2dcFWVIdNiLbRKYx+DncjScSGbmW//6 N5bakFgZW0sQ4rvFzst7Q504kAQ3pXs+tBJT2bH6STSkmyCKvlfzLkrDZxfhwIqcOfOG SWwWatKwTXK6zpA4ne95wqyIOVby7CV5Ayv30NwyxQKoBVxnyYzhL3WBnf+Ef4mh4dXR LX6nBHpDGezRnO7pmfgtUgB0B7R/AWCFLhqkFMj5ssVF4em3Mx9NZmgpGZDxHikhs42U 911A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc :content-transfer-encoding; bh=IyH14F+agd7W5xUCOqF8MHhvzX444waYtpTecHVWge8=; b=ShA3Unt1XTkUyHiZhlFOHurzBat5uEwDii8bTX9QOIAsgAJcfNZxr87frmiuYHlQ6u 2b/ZaA2k1Trunc7pTYBE/6XstDMrdEBMPfJygO7jGg2BYhp5o10oUhS7o5uI5fSMMl+y jV0n3FLZxwHf5+sLtPMs/dbaws3nqpec/Y0DNP5xeGujyvBfReIwKLnSEYHn8IGjTMQ8 PnHYy7pzYZDN1P0aFkeyVSk2nSZXxBFDDX6BGXfUyMfc0tNQLw8zzt7Hu5ALdAscl1jo uIaZP46FUM+jJHE++Y3JE11FkUL7ZKSVdlG+Dp0JinydQ/zy+C3pGRFz1RcEGxJo+SAl RDyw== X-Gm-Message-State: AOAM531VOxF79Wuj/cHMP+s+2nRZL4S2Cu1KK7Mp3OOPkPO2578IMbnL 8ZiFRDGbIwWZbpv+rwf/NnWMQIiaQVeAkA== X-Google-Smtp-Source: ABdhPJxypJtr3ImAqxt0f0FeKm62AoisNyF+dqf+XW3ByIZHDHbGiBRt897FAZj3q+84CftFuObbB1WeseuHdQ== X-Received: from wonchungspecialist.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1440]) (user=wonchung job=sendgmr) by 2002:a17:902:860a:b0:14b:341e:5ffb with SMTP id f10-20020a170902860a00b0014b341e5ffbmr23087343plo.6.1646101588165; Mon, 28 Feb 2022 18:26:28 -0800 (PST) Date: Tue, 1 Mar 2022 02:26:25 +0000 Message-Id: <20220301022625.469446-1-wonchung@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v2] usb:typec: Add sysfs support for Type C connector's physical location From: Won Chung To: Heikki Krogerus , Greg Kroah-Hartman , "Rafael J . Wysocki" , Benson Leung , Prashant Malani , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Won Chung Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org When ACPI table includes _PLD field for a Type C connector, share _PLD values in its sysfs. _PLD stands for physical location of device. Currently without connector's location information, when there are multiple Type C ports, it is hard to distinguish which connector corresponds to which physical port 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 location 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 port are the following. - panel - vertical_position - horizontal_position - dock - lid Signed-off-by: Won Chung --- Changes in v2: - Use string for location. - Clarify get_pld() with naming and return type. Documentation/ABI/testing/sysfs-class-typec | 35 ++++++ drivers/usb/typec/class.c | 113 ++++++++++++++++++++ drivers/usb/typec/class.h | 3 + 3 files changed, 151 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-class-typec b/Documentation/ABI/testing/sysfs-class-typec index 75088ecad202..4497a5aeb063 100644 --- a/Documentation/ABI/testing/sysfs-class-typec +++ b/Documentation/ABI/testing/sysfs-class-typec @@ -141,6 +141,41 @@ Description: - "reverse": CC2 orientation - "unknown": Orientation cannot be determined. +What: /sys/class/typec//location/panel +Date: March 2022 +Contact: Won Chung +Description: + Describes which panel surface of the system’s housing the + port resides on. + +What: /sys/class/typec//location/vertical_position +Date: March 2022 +Contact: Won Chung +Description: + Describes vertical position of the port on the panel surface. + Valid values: upper, center, lower + +What: /sys/class/typec//location/horizontal_position +Date: March 2022 +Contact: Won Chung +Description: + Describes horizontal position of the port on the panel surface. + Valid values: left, center, right + +What: /sys/class/typec//location/dock +Date: March 2022 +Contact: Won Chung +Description: + Set as "yes" if the port resides in a docking station or a port + replicator, otherwise set as "no". + +What: /sys/class/typec//location/lid +Date: March 2022 +Contact: Won Chung +Description: + Set as "yes" if the port resides on the lid of laptop system, + otherwise set as "no". + USB Type-C partner devices (eg. /sys/class/typec/port0-partner/) What: /sys/class/typec/-partner/accessory_mode diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index 45a6f0c807cb..5a52cb6728ec 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -1579,8 +1579,101 @@ static const struct attribute_group typec_group = { .attrs = typec_attrs, }; +static const char * const typec_location_panel[] = { + "top", + "bottom", + "left", + "right", + "front", + "back", + "unknown", +}; + +static const char * const typec_location_vertical_position[] = { + "upper", "center", "lower" +}; + +static const char * const typec_location_horizontal_position[] = { + "left", "center", "right" +}; + +static ssize_t panel_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct typec_port *port = to_typec_port(dev); + + if (port->pld) + return sprintf(buf, "%s\n", + typec_location_panel[port->pld->panel]); + return 0; +}; +static DEVICE_ATTR_RO(panel); + +static ssize_t vertical_position_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct typec_port *port = to_typec_port(dev); + + if (port->pld) + return sprintf(buf, "%s\n", + typec_location_vertical_position[ + port->pld->vertical_position]); + return 0; +}; +static DEVICE_ATTR_RO(vertical_position); + +static ssize_t horizontal_position_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct typec_port *port = to_typec_port(dev); + + if (port->pld) + return sprintf(buf, "%s\n", + typec_location_horizontal_position[ + port->pld->horizontal_position]); + return 0; +}; +static DEVICE_ATTR_RO(horizontal_position); + +static ssize_t dock_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct typec_port *port = to_typec_port(dev); + + if (port->pld) + return sprintf(buf, "%s\n", port->pld->dock ? "yes" : "no"); + return 0; +}; +static DEVICE_ATTR_RO(dock); + +static ssize_t lid_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct typec_port *port = to_typec_port(dev); + + if (port->pld) + return sprintf(buf, "%s\n", port->pld->lid ? "yes" : "no"); + return 0; +}; +static DEVICE_ATTR_RO(lid); + +static struct attribute *typec_location_attrs[] = { + &dev_attr_panel.attr, + &dev_attr_vertical_position.attr, + &dev_attr_horizontal_position.attr, + &dev_attr_dock.attr, + &dev_attr_lid.attr, + NULL, +}; + +static const struct attribute_group typec_location_group = { + .name = "location", + .attrs = typec_location_attrs, +}; + static const struct attribute_group *typec_groups[] = { &typec_group, + &typec_location_group, NULL }; @@ -1614,6 +1707,24 @@ const struct device_type typec_port_dev_type = { .release = typec_release, }; +static struct acpi_pld_info *get_acpi_pld_info(struct device *dev) +{ +#if defined(CONFIG_ACPI) + struct acpi_pld_info *pld; + acpi_status status; + + if (!has_acpi_companion(dev)) + return NULL; + + status = acpi_get_physical_device_location(ACPI_HANDLE(dev), &pld); + if (ACPI_FAILURE(status)) + return NULL; + return pld; +#else + return NULL; +#endif +} + /* --------------------------------------- */ /* Driver callbacks to report role updates */ @@ -2073,6 +2184,8 @@ struct typec_port *typec_register_port(struct device *parent, return ERR_PTR(ret); } + port->pld = get_acpi_pld_info(&port->dev); + ret = device_add(&port->dev); if (ret) { dev_err(parent, "failed to register port (%d)\n", ret); diff --git a/drivers/usb/typec/class.h b/drivers/usb/typec/class.h index 0f1bd6d19d67..1b52633400c8 100644 --- a/drivers/usb/typec/class.h +++ b/drivers/usb/typec/class.h @@ -3,6 +3,7 @@ #ifndef __USB_TYPEC_CLASS__ #define __USB_TYPEC_CLASS__ +#include #include #include @@ -54,6 +55,8 @@ struct typec_port { const struct typec_capability *cap; const struct typec_operations *ops; + + struct acpi_pld_info *pld; }; #define to_typec_port(_dev_) container_of(_dev_, struct typec_port, dev)