Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp828975ybf; Thu, 27 Feb 2020 00:12:13 -0800 (PST) X-Google-Smtp-Source: APXvYqzmG4YlzSKgvzYSMS5v3ypHKqpDBtU8ATbzpAHw/mFydl0FyF0GSUJmC4G6RQIH+kcinoPc X-Received: by 2002:aca:d484:: with SMTP id l126mr2271520oig.114.1582791133836; Thu, 27 Feb 2020 00:12:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582791133; cv=none; d=google.com; s=arc-20160816; b=ps8iNT+wUf7Y18+Rd6EwcZ3yi19LZB7GxfEGS7cIR11auxTWr1nF3mYTDF/AHNvO2K T1nDmIX1IvjTGuNWsV+cevgMM5zh+1J17+13BmDOh6pjq+6i31BPRis+XQK/Y09v/Utz q2UCcf8jgVz9z5r1ol6wb9fK7VUlshjSlKKdqnWlFfnj4/tgb3jeQcuBC7ACIUuEIWCe G3m5FRRDr8DdFDJh/c1wN+ArJzPWg/L0o6MVtkquM4DCAYeg5BHebYpsgdPQUON5u4DG stu0yIMV3Z4on7EEVZYAm9OGq6di9ruY75l+X8zIr9QWQv7t7gx1IBH7Z/JtsUhklTyQ YMrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=TF8dCS5VVIglwjvQyAQgRMpxU+3dZheGZ1YP2BrShZo=; b=E3bWeDH62BeaiKrAfUZCCpkAunR+ye6FrtFqcPY7xG2LZkXd21fQOjg+B+HmYT9bkm m+cVUDZMwuMv1A06/ptESXU0THE5M9xMiAOqqteIc7iHpJt6F7mLPRZCSxum8KQz/VqK sKHlMjPopDYs/W/19d7nyZJRVFUjjKyCTgN8L40yR+KmfO5Sg0w5yxKir3E/xyVQz0Aa wuxq8NUHbzv3PYEVCP4GGRNGhFV4CB0Lz+lhAwMSKBV1++yUCY/qvd9ymQSVMoxdUVju 6QvvXx/q/bADcaJB0C5L9a9RGyIBNXzjEk2Fn9V/HKBycNpFpOQYmxvsJEHl4euEz/9h E1JA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 18si719767oin.182.2020.02.27.00.12.02; Thu, 27 Feb 2020 00:12:13 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728488AbgB0ILw (ORCPT + 99 others); Thu, 27 Feb 2020 03:11:52 -0500 Received: from mga14.intel.com ([192.55.52.115]:30551 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728442AbgB0ILw (ORCPT ); Thu, 27 Feb 2020 03:11:52 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Feb 2020 00:11:51 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,491,1574150400"; d="scan'208";a="350623243" Received: from kuha.fi.intel.com ([10.237.72.53]) by fmsmga001.fm.intel.com with SMTP; 27 Feb 2020 00:11:49 -0800 Received: by kuha.fi.intel.com (sSMTP sendmail emulation); Thu, 27 Feb 2020 10:11:48 +0200 Date: Thu, 27 Feb 2020 10:11:48 +0200 From: Heikki Krogerus To: Badhri Jagan Sridharan Cc: Greg Kroah-Hartman , Guenter Roeck , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, pumahsu@google.com Subject: Re: [PATCH v4] usb: typec: Add sysfs node to show cc orientation Message-ID: <20200227081148.GA10532@kuha.fi.intel.com> References: <20200226195758.150477-1-badhri@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200226195758.150477-1-badhri@google.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 26, 2020 at 11:57:58AM -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 Reviewed-by: Heikki Krogerus > --- > 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 thanks, -- heikki