Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp227815ybf; Wed, 26 Feb 2020 11:59:30 -0800 (PST) X-Google-Smtp-Source: APXvYqx918tQoOV6w/Hynu7WUc6fWv0JhzyFkkzzclzwQ8LpnxtPVKraHqUnbJbZPAX9NyM2NLa4 X-Received: by 2002:a05:6830:160c:: with SMTP id g12mr390456otr.82.1582747169849; Wed, 26 Feb 2020 11:59:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582747169; cv=none; d=google.com; s=arc-20160816; b=J/JdEc4qwYDV/2BN8LqOA5knmujlgp6vWq+hgnuBR8N9XaJjpHrMLhvdJiu0PWQTGY KpQOs0MzxTk7fimXkBW3mseBKPMbdRG6NvXRxm7Ic1lRSadDCnWyca1IlWV/+dalwTLV SPPSgWsUKDrl9DkOXr5EfVMvUgq40xLgOXb7S/91PFWBjeT6UIOqy4JNMhOmBJV7CzOU r+RYf4OjDIzuPOEyXNm+soAFmjRLRCp3xbTIkh3ggsj7fypeFMyf5Ul5u1JsxakVV/jP vDyOK1RULicWWONgiLedX0SrC6azg37F2VUXSCfLkC07erwbAraV84wguFTNVntoERLf 0sKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature; bh=uBP/KRP6rlyKjQn7L8H9HcQSgolfyiucEDippWsO4eE=; b=W28NLfU9HpyTOcnpPmfY2ofvN+uMVuSykYDQIy2qKPN2Rf88jK7AlZsJbZNzIcvrPT 7dafKpv+Vi8ltPKXUiy8e0ZYXfCznh42WrvXo2BQVSp+ebxFQ29WbDJwVDUFlO2Jmj9k H+cHYGqDT4MgEENd99vQYpsc23UjBQLbgRrPkDgonT8PuKFP6aFNgvGQemfqQJ+QNxFE IBnxSgI5veHi4i+HCLriA7nApKRl8f9IdS858jtPJVw8wCCYaP1oQCAoEtB8NaSysiLH QvWMaQBej2WHGYS994Lewb5/dEssrNXjTvlpZ2s3ije6+C48KjAB9wY+bAt5iuNS0dAq D85g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=rkPO2X4Q; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v18si261247otq.209.2020.02.26.11.59.18; Wed, 26 Feb 2020 11:59:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=rkPO2X4Q; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727401AbgBZT6E (ORCPT + 99 others); Wed, 26 Feb 2020 14:58:04 -0500 Received: from mail-pf1-f202.google.com ([209.85.210.202]:40667 "EHLO mail-pf1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727305AbgBZT6E (ORCPT ); Wed, 26 Feb 2020 14:58:04 -0500 Received: by mail-pf1-f202.google.com with SMTP id d127so181275pfa.7 for ; Wed, 26 Feb 2020 11:58:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=uBP/KRP6rlyKjQn7L8H9HcQSgolfyiucEDippWsO4eE=; b=rkPO2X4QhTS952uAkPex2S5r5tAJpmHcz81YiXrId7HP0hA2NHPL7zSXNUGT5gjEEs Q0nbydl955FLy/ASnAbu3X2Ek4plX+3nJA2sFnPcefjvCTWokstwpsQguQLpVXeIAoJi mM4xvV9BO0GuFpkKAs7OwbRYvsKLzRcC9UPibt2A8oqI5zoOdD3bK402TsXm32eypCsJ 5PN20zWpj2OCvuPQqAhjxsLpzaQvlapXZAnMB2Y52As8BQm2GvWl6DpeNu2SUTjrjYHL YG/Bm/AeUFPXTPKSi0eCnk8qD8nKwURwEHa/o3xVEP0kDlqVFWS8uVPzwTu/cclIlKGc C+og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=uBP/KRP6rlyKjQn7L8H9HcQSgolfyiucEDippWsO4eE=; b=ZH/H2PS1tBXrtNy23CiPQoii0c/FBIUZb1vwK+DuNc3uAnWdB//lw8HK6zfrM/qUNt 9oGfOkJr5H2rJZ1tbOpr6rOovnAbrM/BySYX3k5Xdm+68rjamJ21qi7oeMxGUUFoi4MO Xfb9kpb6ErLXoyd+z5l+Pd/lzESIeeiggVL8pxQ+DH/1vrX5mRcpNmPkUYQBR0qxCMfZ IC/v5VIk9n01RyDvVEiZPVSIp5rt6VWn8HljeXtd86tvixlFNlriRPMycBDpTcLg9ZOv xfWCOWtS3iL67R31n1gWWkq8WyUia+zWdD/dyoNgz2BnViFs7IWWvSq4fmvDzHoCWYVN hgoA== X-Gm-Message-State: APjAAAUMZ0STC+PhoPgDPsae2548zzQTLAmSDEAZr5Drn08tXA3rOQUY pELVXmatMWDWjiALUQY0yxJoa1C8WoM= X-Received: by 2002:a63:f50e:: with SMTP id w14mr444621pgh.363.1582747082882; Wed, 26 Feb 2020 11:58:02 -0800 (PST) Date: Wed, 26 Feb 2020 11:57:58 -0800 Message-Id: <20200226195758.150477-1-badhri@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog Subject: [PATCH v4] usb: typec: Add sysfs node to show cc orientation From: Badhri Jagan Sridharan To: Heikki Krogerus , Greg Kroah-Hartman , Guenter Roeck Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, pumahsu@google.com, Badhri Jagan Sridharan Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Export Type-C orientation information when available. - "normal": CC1 orientation - "reverse": CC2 orientation - "unknown": Orientation cannot be determined. Signed-off-by: Badhri Jagan Sridharan --- Version history: V4: - Greg's suggestion of Minor refractor to handle TYPEC_ORIENTATION_NONE and default in the same case. V3: - Heikki's suggestion to us .is_visible callback. unsigned int orientation_aware:1 has been introduced to make support of this attribute optional for drivers such as UCSI - Guenter's suggestion to rename to "orientation". - Heikki's suggestion to stick with string values instead of exposing it as integer values. --- Documentation/ABI/testing/sysfs-class-typec | 9 +++++++ drivers/usb/typec/class.c | 26 +++++++++++++++++++++ drivers/usb/typec/tcpm/tcpm.c | 1 + include/linux/usb/typec.h | 1 + 4 files changed, 37 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-class-typec b/Documentation/ABI/testing/sysfs-class-typec index 0c2eb26fdc06b..b834671522d6f 100644 --- a/Documentation/ABI/testing/sysfs-class-typec +++ b/Documentation/ABI/testing/sysfs-class-typec @@ -108,6 +108,15 @@ Contact: Heikki Krogerus Description: Revision number of the supported USB Type-C specification. +What: /sys/class/typec//orientation +Date: February 2020 +Contact: Badhri Jagan Sridharan +Description: + Indicates the active orientation of the Type-C connector. + Valid values: + - "normal": CC1 orientation + - "reverse": CC2 orientation + - "unknown": Orientation cannot be determined. USB Type-C partner devices (eg. /sys/class/typec/port0-partner/) diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index 12be5bb6d32ca..bf97c31d0bba1 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -1244,6 +1244,25 @@ static ssize_t usb_power_delivery_revision_show(struct device *dev, } static DEVICE_ATTR_RO(usb_power_delivery_revision); +static ssize_t orientation_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct typec_port *p = to_typec_port(dev); + enum typec_orientation orientation = typec_get_orientation(p); + + switch (orientation) { + case TYPEC_ORIENTATION_NORMAL: + return sprintf(buf, "%s\n", "normal"); + case TYPEC_ORIENTATION_REVERSE: + return sprintf(buf, "%s\n", "reverse"); + case TYPEC_ORIENTATION_NONE: + default: + return sprintf(buf, "%s\n", "unknown"); + } +} +static DEVICE_ATTR_RO(orientation); + static struct attribute *typec_attrs[] = { &dev_attr_data_role.attr, &dev_attr_power_operation_mode.attr, @@ -1254,6 +1273,7 @@ static struct attribute *typec_attrs[] = { &dev_attr_usb_typec_revision.attr, &dev_attr_vconn_source.attr, &dev_attr_port_type.attr, + &dev_attr_orientation.attr, NULL, }; @@ -1283,6 +1303,10 @@ static umode_t typec_attr_is_visible(struct kobject *kobj, return 0; if (port->cap->type != TYPEC_PORT_DRP) return 0444; + } else if (attr == &dev_attr_orientation.attr) { + if (port->cap->orientation_aware) + return 0444; + return 0; } return attr->mode; @@ -1493,6 +1517,8 @@ int typec_set_orientation(struct typec_port *port, } port->orientation = orientation; + sysfs_notify(&port->dev.kobj, NULL, "orientation"); + kobject_uevent(&port->dev.kobj, KOBJ_CHANGE); return 0; } diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index 78077c234ef27..bc0032a6b9a14 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -4742,6 +4742,7 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc) port->typec_caps.pd_revision = 0x0300; /* USB-PD spec release 3.0 */ port->typec_caps.driver_data = port; port->typec_caps.ops = &tcpm_ops; + port->typec_caps.orientation_aware = 1; port->partner_desc.identity = &port->partner_ident; port->port_type = port->typec_caps.type; diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h index 44d28387ced48..b00a2642a9cd6 100644 --- a/include/linux/usb/typec.h +++ b/include/linux/usb/typec.h @@ -211,6 +211,7 @@ struct typec_capability { u16 pd_revision; /* 0300H = "3.0" */ int prefer_role; enum typec_accessory accessory[TYPEC_MAX_ACCESSORY]; + unsigned int orientation_aware:1; struct fwnode_handle *fwnode; void *driver_data; -- 2.25.0.265.gbab2e86ba0-goog