Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp228732ybf; Wed, 26 Feb 2020 12:00:35 -0800 (PST) X-Google-Smtp-Source: APXvYqyoDDkbcQQ7EbpqkR1OyJOKSilDxBrNjfw28B1Ok9eRyfMHNByN7cQWgenA0pKmbspR+atF X-Received: by 2002:a9d:443:: with SMTP id 61mr287443otc.357.1582747234920; Wed, 26 Feb 2020 12:00:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582747234; cv=none; d=google.com; s=arc-20160816; b=T3UGG1294fYNzw5kEU3wL6QASKY2hIz2fbfAsgp14YJCCElXfUp71Nu1d34SKsb66g tUuiyAel2sQP0qzDVZZrTVtevzU+wr0x/5EW5BKIIIwv1bRzfOyB4W939O4msi05PWwE TtdxoPuALFET7P6OrjAmOiI8wyzG9trIAotq2QeGuRKZMviOFZ6Kl33IwGFBw/lro+vK ZjQBV+fz89q8t26LMMyauYbLMdgxHog0kTf0x/89m/L3yZMooDAHMTttiW2HVUtQd8VP 15zhT2t1fApD6GXOjwlGT4QmTXxaR/borJgnI6TUnIRVDeIUeFWMS4XGNmovjBLU3lTM weVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=RiyxAO8fOvzKXN143+bw+JynZU//eF4zHR9EjbKKDdA=; b=VEKnqwlGunpVgb+BABdvtp0IWYVpDGoxZ6688J54cx4Nk7fKGTQtk5vzzKUYQ6/Ybf PpzuvnjXe+My0XJcTcRJStJiIkIgMX1nO/2Lm5M1ujtMIHdOA9fPbyE5vaUzy9ABkTPW YqZTZZIGDZ2p8XCZbYkqzQAsj4u0sZW258g/U2cprTBt5+JXEvt8GUm0tFGPchzH3qTR bYApN/o90nmzSFscUDzKYi4WG6hDKH2Z1cKYrmaZPufeHRSklRPMG7o9s4Jk+UnuprGj +6kcjOWt/583eBKp+vzR0F+LKtgr22hZytmUUxKwXoO5VWQ25GhdXT/fyjsX+jVMcEF/ 5dPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Zd+gzvc9; 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 j74si353687otj.246.2020.02.26.12.00.21; Wed, 26 Feb 2020 12:00:34 -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=Zd+gzvc9; 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 S1727338AbgBZT7a (ORCPT + 99 others); Wed, 26 Feb 2020 14:59:30 -0500 Received: from mail-vk1-f193.google.com ([209.85.221.193]:44744 "EHLO mail-vk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727244AbgBZT7a (ORCPT ); Wed, 26 Feb 2020 14:59:30 -0500 Received: by mail-vk1-f193.google.com with SMTP id x62so37191vkg.11 for ; Wed, 26 Feb 2020 11:59:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=RiyxAO8fOvzKXN143+bw+JynZU//eF4zHR9EjbKKDdA=; b=Zd+gzvc9OlxkHjdueJS9iD5Ab/3XcwVlIZ9+kZPT4Fuda9RaSkhdCV1ikvJdDLcwLs 1RLJeIhfiH7nn4cDUuglZgibYUfCgO8OFw1xwfZLJbghSYsuMUDKO/TCgJcOnjcrieUq lNW1/aNGcvvP6OvJhESnVCJB0iZAf5jIYMFn4sGiAtVThp/bmnQxB5QGsmChtsAPzI14 U/dXUh1RZgdn5BTEf4KmZh1/g7kG21kL3uygkFxCtJ/fQ4CZ0oGq02kkWFoO3wgYzymt nPZ2zBGA95Zt6XcuC5HnsyURcJP1sZRcuDDD/E7ksHSXBYLZmA/dgdkun/MhbholonCQ o6IA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=RiyxAO8fOvzKXN143+bw+JynZU//eF4zHR9EjbKKDdA=; b=juGFNMftmOjTqvKWW2yXRwwkU5JPcHdEsCi5v/mKiYa4vje8o1G2O0osUvSv8z9XEU CQoT3D0V7n/+RLgWgHzHITuZXFPumWI3ySz3ZAHgcwGF+nzOLOZpZ4UWUKk2Hn+bxru9 Wm9X7nk3k1dzo5D8vy6nPfH+MkKUvB/OwZs0mRgsMQA00sCk1PdyYWxfo1Vop6YmLmyy d60rCyWGI1nIGVSxUewtnjMpr/EXWlUcOo4w4HIVcN3FG+fktr1QxdJSIvOV/gfpPhfo vpBYvGYYnf/sxeqB24juGw/w3ehSzodx00w82/jHAiPuuIA6BUXfTSMJXpBnPLccon2g F+Yg== X-Gm-Message-State: APjAAAVrfWYhzLjF7U8nOf/iyoYYSHjclDxZsZFMBnpr+sPe/t0BeA3b dRRBhbSuZBmOtbEW7RnfBRGBieJv9rKbFrBCgQFk1ukl X-Received: by 2002:ac5:c807:: with SMTP id y7mr550790vkl.92.1582747168397; Wed, 26 Feb 2020 11:59:28 -0800 (PST) MIME-Version: 1.0 References: <20200226182517.49214-1-badhri@google.com> <20200226183157.GA16309@roeck-us.net> In-Reply-To: <20200226183157.GA16309@roeck-us.net> From: Badhri Jagan Sridharan Date: Wed, 26 Feb 2020 11:58:52 -0800 Message-ID: Subject: Re: [PATCH v3] usb: typec: Add sysfs node to show cc orientation To: Guenter Roeck Cc: Heikki Krogerus , Greg Kroah-Hartman , USB , LKML , Puma Hsu 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 Thanks Geunter ! Sure ! Updated the patch. On Wed, Feb 26, 2020 at 10:32 AM Guenter Roeck wrote: > > On Wed, Feb 26, 2020 at 10:25:17AM -0800, Badhri Jagan Sridharan wrote: > > 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: > > 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 | 27 +++++++++++++++++++++ > > drivers/usb/typec/tcpm/tcpm.c | 1 + > > include/linux/usb/typec.h | 1 + > > 4 files changed, 38 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..2524f1571e425 100644 > > --- a/drivers/usb/typec/class.c > > +++ b/drivers/usb/typec/class.c > > @@ -1244,6 +1244,26 @@ 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_NONE: > > + return sprintf(buf, "%s\n", "unknown"); > > + case TYPEC_ORIENTATION_NORMAL: > > + return sprintf(buf, "%s\n", "normal"); > > + case TYPEC_ORIENTATION_REVERSE: > > + return sprintf(buf, "%s\n", "reverse"); > > + default: > > + return sprintf(buf, "%s\n", "unknown"); > > TYPEC_ORIENTATION_NONE and default can be handled in a single case statement. > > > + } > > +} > > +static DEVICE_ATTR_RO(orientation); > > + > > static struct attribute *typec_attrs[] = { > > &dev_attr_data_role.attr, > > &dev_attr_power_operation_mode.attr, > > @@ -1254,6 +1274,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 +1304,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 +1518,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 > >