Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp3120259pxm; Mon, 28 Feb 2022 12:27:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJw+Pfp+8U3bfR3QR+VMeiT1u2TTVD7p6ZV4k2hIS7Hh4lqj+jeuNBSecSwmmjjC3zx4E4YP X-Received: by 2002:a17:903:120e:b0:151:71e4:dadf with SMTP id l14-20020a170903120e00b0015171e4dadfmr3609231plh.48.1646080033253; Mon, 28 Feb 2022 12:27:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646080033; cv=none; d=google.com; s=arc-20160816; b=DTUocUOsk85mipq2udJ2XlopPF8MvrBxiGzE6RfGMULfOtKFMIaHMzBbRqMjEmR5e0 mMNK/aiqOjEExGsSFHg7NWZKgFoXMCbqOIyHL/5tjNDTeFt1E2PbtUcY42Pkz/ZrtY21 9BjrQFKxtNhAkqGwuG0dT1Nk8PvjG0jJJQ65ATZazT5dbohrxebO3MfJJjmzS9+holNw NBOeGMlnDF2JYB24/qE7/fB+PRyxRl8rEIj714t1Hca7AHsWqMIb92uGidWLO/PlgGOU jo0iA9vS61tTThBWzf2cqqmZiYi0jpZfCSG0yuLAtfle9UmYZOZT5yPEFCyxO6pKkncK AgeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:from:subject :mime-version:message-id:date:dkim-signature; bh=o/agACgJ9p2D2Sf7n3omy9IGAy/5Dg0bQ6zDKzz3oek=; b=H5YsAac3kgmYmzmPInShqpvNnqFB4LdvUrMWJvOkViDwN0U98BYdf4BlzIHZiwhS2n HwT4MSXxUXc6pJT5JEkuHfpbFM+Rr17kUOo8cBe1KS0Zx1NUOBOpg26rNnUgzLYmxpUt g0asdq6u/tAsRCZMGatceZPOWkeRBVEv0wclvgIckEgKCQxcGwFlDTNpi+kAPURT7UAh HzXk0Zhi59hK5AiL2uLSay9+Gc8g5QW3Yw7V9YiQhYN4ReLMpWYzJK/2L2bTcHMCYsF+ Wmio5eqdJXW+ocg4rli2zlwxT832iwFcoL5uE/i6UEYFwuSBIayvh70Qc1pf54bmA1Bb hidg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=sGiVz9m8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id 207-20020a6217d8000000b004e0e933d5a3si10760656pfx.223.2022.02.28.12.27.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 12:27:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=sGiVz9m8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 869471F0804; Mon, 28 Feb 2022 11:44:53 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229509AbiB1THe (ORCPT + 99 others); Mon, 28 Feb 2022 14:07:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229458AbiB1THd (ORCPT ); Mon, 28 Feb 2022 14:07:33 -0500 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33AEAB189C for ; Mon, 28 Feb 2022 11:06:54 -0800 (PST) Received: by mail-pg1-x54a.google.com with SMTP id n63-20020a632742000000b00378b20298a2so1771117pgn.22 for ; Mon, 28 Feb 2022 11:06:54 -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=o/agACgJ9p2D2Sf7n3omy9IGAy/5Dg0bQ6zDKzz3oek=; b=sGiVz9m8sT5ze1LctY0q5FaRAOLS/76JAbjZVzYDCVh6r7z7j+l9scY7ZE1HDSoboD b9L7y3nC7hrhChSeGOcQ0V5rnQG+A2wPVqEAVjc9j4nX71CcdoMJWZ7YQV+pCcZB4jk1 kaRireYFNfq4h5HvJ5jdlEIl9b5D7kWRlw0eEm31R10ZgSRbuIaCS4ErkYT4YNykfkyE wm3L73idQjP8J4O+63QT7LwdZpaT7SIg2cCW69L3ReZ8Xr6XfhggW9oX+dBQzhRs7zdt QNZXPaUoR5fdPceXWdhJSx098cJjO+rzEXY2XeIhu/qGiVJv4vSA3Qc6+fxNhjxeaJUy L7Gw== 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=o/agACgJ9p2D2Sf7n3omy9IGAy/5Dg0bQ6zDKzz3oek=; b=JrzfjJ5gt9bpDXNRkGpsxpZ1SgwWfaEU/CjxQCTXbzfHHJV0kTE5RbKNg8YIG+1ymD Tliz+lRBW03ysnA8F2pGTrUvz6EN46CI3BEJjITIKX7b5dfOqbN3p8PGO9B1KYURMqj2 kkhfv8GFMOpmxR+Xnz1SnETLfub4YRRN5RI+W80EUNZSNmpesyf/GBBgyi2CaeD+39nc 9K37ekmYnx1ORuvHo9kiBIQi5Zsm2bRRzKasTWkUNpp6my7B2bQDcQDtBocpN64UYudp 0n6l9Qjc8spaaFiSRLIMhgMOWiizVT3MKUE4NUjrUJDRBnFXqqjOy0zBWSqUK40o+tUZ Xbrg== X-Gm-Message-State: AOAM532KD9JBH7LlpD729F/i/7uO3vQYVmrMTjneiT1AB0SAMchADlPq ID9sYYe58ZX/ktov9lgtr67b/x3kEtiyyA== X-Received: from wonchungspecialist.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1440]) (user=wonchung job=sendgmr) by 2002:a17:90a:2e04:b0:1bc:a5db:bcdb with SMTP id q4-20020a17090a2e0400b001bca5dbbcdbmr18258335pjd.116.1646075213654; Mon, 28 Feb 2022 11:06:53 -0800 (PST) Date: Mon, 28 Feb 2022 19:06:49 +0000 Message-Id: <20220228190649.362070-1-wonchung@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH] 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 - horizontal_position - vertical_position - dock - lid Signed-off-by: Won Chung --- Documentation/ABI/testing/sysfs-class-typec | 43 +++++++++++++++++ drivers/usb/typec/class.c | 52 +++++++++++++++++++++ drivers/usb/typec/class.h | 3 ++ 3 files changed, 98 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-class-typec b/Documentation/AB= I/testing/sysfs-class-typec index 75088ecad202..2879bc6e6ad2 100644 --- a/Documentation/ABI/testing/sysfs-class-typec +++ b/Documentation/ABI/testing/sysfs-class-typec @@ -141,6 +141,49 @@ Description: - "reverse": CC2 orientation - "unknown": Orientation cannot be determined. =20 +What: /sys/class/typec//location/panel +Date: February 2022 +Contact: Won Chung +Description: + Describes which panel surface of the system=E2=80=99s housing the + Type C port resides on: + 0 - Top + 1 - Bottom + 2 - Left + 3 - Right + 4 - Front + 5 - Back + 6 - Unknown (Vertical Position and Horizontal Position will be + ignored) + +What: /sys/class/typec//location/vertical_position +Date: February 2022 +Contact: Won Chung +Description: + 0 - Upper + 1 - Center + 2 - Lower + +What: /sys/class/typec//location/horizontal_position +Date: Feb, 2022 +Contact: Won Chung +Description: + 0 - Left + 1 - Center + 2 - Right + +What: /sys/class/typec//location/dock +Date: Feb, 2022 +Contact: Won Chung +Description: + Set if the port resides in a docking station or a port replicator. + +What: /sys/class/typec//location/lid +Date: Feb, 2022 +Contact: Won Chung +Description: + Set if the port resides on the lid of laptop system. + USB Type-C partner devices (eg. /sys/class/typec/port0-partner/) =20 What: /sys/class/typec/-partner/accessory_mode diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index 45a6f0c807cb..43b23c221f95 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -1579,8 +1579,40 @@ static const struct attribute_group typec_group =3D = { .attrs =3D typec_attrs, }; =20 +#define DEV_ATTR_LOCATION_PROP(prop) \ + static ssize_t prop##_show(struct device *dev, struct device_attribute *a= ttr, \ + char *buf) \ + { \ + struct typec_port *port =3D to_typec_port(dev); \ + if (port->pld) \ + return sprintf(buf, "%u\n", port->pld->prop); \ + return 0; \ + }; \ +static DEVICE_ATTR_RO(prop) + +DEV_ATTR_LOCATION_PROP(panel); +DEV_ATTR_LOCATION_PROP(vertical_position); +DEV_ATTR_LOCATION_PROP(horizontal_position); +DEV_ATTR_LOCATION_PROP(dock); +DEV_ATTR_LOCATION_PROP(lid); + +static struct attribute *typec_location_attrs[] =3D { + &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 =3D { + .name =3D "location", + .attrs =3D typec_location_attrs, +}; + static const struct attribute_group *typec_groups[] =3D { &typec_group, + &typec_location_group, NULL }; =20 @@ -1614,6 +1646,24 @@ const struct device_type typec_port_dev_type =3D { .release =3D typec_release, }; =20 +void *get_pld(struct device *dev) +{ +#ifdef CONFIG_ACPI + struct acpi_pld_info *pld; + acpi_status status; + + if (!has_acpi_companion(dev)) + return NULL; + + status =3D 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 */ =20 @@ -2073,6 +2123,8 @@ struct typec_port *typec_register_port(struct device = *parent, return ERR_PTR(ret); } =20 + port->pld =3D get_pld(&port->dev); + ret =3D 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__ =20 +#include #include #include =20 @@ -54,6 +55,8 @@ struct typec_port { =20 const struct typec_capability *cap; const struct typec_operations *ops; + + struct acpi_pld_info *pld; }; =20 #define to_typec_port(_dev_) container_of(_dev_, struct typec_port, dev) --=20 2.35.1.574.g5d30c73bfb-goog