Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp7136739ybp; Wed, 16 Oct 2019 04:27:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqxvBYqDdnKt95zw3f+6UCs5sh/lQXcR/kpjjzJS4Zc7VeBYHm1HqAu+HiDqXJLrSznUYKFT X-Received: by 2002:a05:6402:1804:: with SMTP id g4mr38818668edy.266.1571225227155; Wed, 16 Oct 2019 04:27:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571225227; cv=none; d=google.com; s=arc-20160816; b=Tg46e2msA/R2FacXFZQTMXRCQcDK5yuRlk/BoY6aljuMo9dmQ3999thz7DNIWJZoFL 5UtL0HRKRDscdkyjX+XnZqjCLQmYShvq0yY2lGXFn06j6i2wqeb9D2yjLQN/NBUDimmv 4JeQwB8GfzhQskaqb9AIemcz4u8tz1v9bNRUY5MBm6iDXAE3PHlOKiOgNs4rvPaE5DMT 6g4glm9DWQzJXrIIM7ikeNAvi3YeVO3FrGH4b8/dDs5R3YMvFFZcgaDRDyN3sA3LcOKp 8lPoilY1Q1uWC2YZO3YmfmDtN5wuWMgvx5S7rqaQMht3h5rffLAe7/MiFdv8o3oXaazg zvkw== 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=3r2fWGxvgUo0Yo2JWFT9X062NRVoB/qS/ldqIiIuY8s=; b=D0+SFSAKhe+CRZUkwzbJjPHZBTjiNShcElhlBaHh12zmjUuM1pL+U8UwH/skE5xVeO SL1emG4keRvxUdZeStlQvca6L6oLwGM4a/z3XQzJor07+qUmps1acEEH5bECu2LrFHCo I3gWS9fYJF8mDJE/iMihqFPw/fuqtb1oPhwszCyV8kA6BrxEXoG/qPXaE62NKNtx3tnO PDkPuvcQNSNNnzeySlM/oImqMIZeDhxxlXqotB/3n44X7kS/bwtkWRGhcEsuIf7qR866 Qk4vsW5/bMP3QxhOJ3hzTRZvF5XJBmCNZubUTa9KxTu5eKXN1er975/sjytZljVtgJyY TIdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="KT9pcH/Y"; 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 a3si15614958edr.20.2019.10.16.04.26.42; Wed, 16 Oct 2019 04:27:07 -0700 (PDT) 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="KT9pcH/Y"; 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 S1732783AbfJPDnX (ORCPT + 99 others); Tue, 15 Oct 2019 23:43:23 -0400 Received: from mail-pl1-f201.google.com ([209.85.214.201]:38167 "EHLO mail-pl1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726491AbfJPDnX (ORCPT ); Tue, 15 Oct 2019 23:43:23 -0400 Received: by mail-pl1-f201.google.com with SMTP id g7so13388924plo.5 for ; Tue, 15 Oct 2019 20:43:21 -0700 (PDT) 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=3r2fWGxvgUo0Yo2JWFT9X062NRVoB/qS/ldqIiIuY8s=; b=KT9pcH/Y/FaK79bj33Qplyav4SbvcU1eXOx+WWEi8c9T7Gt8wzPnGCoIFGeytCNgeU It/vKDY57qKVstZ0RcnIdE9xUZ+p7B3NuT+v1wF6M7ogvTbTqg5Xu3+ZVBcS3aFfpt5F yqWgjKQvjeJIdB2NUGY1Id1Ernfk+37C5wqfoPpqM2s3dWKP4LCv6ucy/wr8lNzztO2Y oJQyTKA7R0zy60+QoMOMsWOz5QD7S53OXekL/0Xb3BlSlG72IueBnAOUlBN6J4njWg/i Yi8O7/0xoMl4noa2Kb94yamYqvf7e9QV13Kby15xQ7u9JQCa76gxrplIL9bNT0J6uHHY T0EQ== 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=3r2fWGxvgUo0Yo2JWFT9X062NRVoB/qS/ldqIiIuY8s=; b=e3kx6yCGd/5FS0zhNFi9GoMon8LLwgUWZsxHayV+bYA9AkzQRZ8BgTMmw8oWIzIasx 81M0Cd81+JDXvOzqtnR0IaW90VHK4Pn4Uwxx8LFTnnT5UNYsm0EZf9SHiV7FNbWfuozQ ODT1LsWWERcgoKhfX86tyWI63K3j5qiTkUdB9uZ/QjIe9zSMICYsVneIvQNUtPnNTuS5 q/hXR/UyJEf+DDb3H2xew3/KKFXFLPC8rRUBWhe2vbdg2/k+Bq7/WNDErKOKPRYgAOff unIKDXw65nVDEVOLOxmpirSAAeQt3WQE8SVOXHv1D6spAgqgZfywEwQEb8cXqxUZBGkm tj/Q== X-Gm-Message-State: APjAAAXa8V+FoWuTZf020Y1nQqHlv2IMxJEk8U70ssx8Y4EkaEI+rGi1 qlImx43xayTD66OUo1PU2jiHvS+47HOJ X-Received: by 2002:a63:d916:: with SMTP id r22mr42503950pgg.46.1571197400669; Tue, 15 Oct 2019 20:43:20 -0700 (PDT) Date: Wed, 16 Oct 2019 11:43:14 +0800 Message-Id: <20191016034314.231363-1-pumahsu@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.23.0.700.g56cf767bdb-goog Subject: [PATCH] usb: typec: Add sysfs node to show cc orientation From: pumahsu To: heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org Cc: badhri@google.com, kyletso@google.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, pumahsu 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 the Type-C cc orientation so that user space can get this information. Signed-off-by: pumahsu --- Documentation/ABI/testing/sysfs-class-typec | 7 +++++++ drivers/usb/typec/class.c | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-class-typec b/Documentation/ABI/testing/sysfs-class-typec index d7647b258c3c..419f952c991d 100644 --- a/Documentation/ABI/testing/sysfs-class-typec +++ b/Documentation/ABI/testing/sysfs-class-typec @@ -108,6 +108,13 @@ Contact: Heikki Krogerus Description: Revision number of the supported USB Type-C specification. +What: /sys/class/typec//cc_orientation +Date: September 2019 +Contact: Puma Hsu +Description: + Indicates which cc orientation is active now, or 0 when + nothing is connected. + 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 7d8805d9bf37..00edae63da8e 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -1238,6 +1238,16 @@ static ssize_t usb_power_delivery_revision_show(struct device *dev, } static DEVICE_ATTR_RO(usb_power_delivery_revision); +static ssize_t cc_orientation_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct typec_port *p = to_typec_port(dev); + + return sprintf(buf, "%d\n", typec_get_orientation(p)); +} +static DEVICE_ATTR_RO(cc_orientation); + static struct attribute *typec_attrs[] = { &dev_attr_data_role.attr, &dev_attr_power_operation_mode.attr, @@ -1248,6 +1258,7 @@ static struct attribute *typec_attrs[] = { &dev_attr_usb_typec_revision.attr, &dev_attr_vconn_source.attr, &dev_attr_port_type.attr, + &dev_attr_cc_orientation.attr, NULL, }; ATTRIBUTE_GROUPS(typec); -- 2.23.0.700.g56cf767bdb-goog