From patchwork Fri Oct 23 21:43:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashant Malani X-Patchwork-Id: 297210 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1FB0CC388F9 for ; Fri, 23 Oct 2020 21:44:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9831B20857 for ; Fri, 23 Oct 2020 21:44:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Ioxm4k6I" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756805AbgJWVn7 (ORCPT ); Fri, 23 Oct 2020 17:43:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753135AbgJWVn7 (ORCPT ); Fri, 23 Oct 2020 17:43:59 -0400 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D43FC0613CE for ; Fri, 23 Oct 2020 14:43:59 -0700 (PDT) Received: by mail-pg1-x531.google.com with SMTP id n16so2338232pgv.13 for ; Fri, 23 Oct 2020 14:43:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=j8WfHBe1he2P6vHiEzCoXjELjhHqzR0SChORwDmTyBw=; b=Ioxm4k6IQEOK0IvA9CoL5I/Aim+DbS+TqDr9g55yRJIodJ87hC+4+UNpQY4kHVr8tt OBaXP46HwL7cBlOhlSyF9GOYv7fdo+K3NsQUgdIVjbiljF4guuN8CoCXyduDCRiKybw3 pXhx3aEiDjZYwhT+qKooNVcDZDJKB5M7bttHg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=j8WfHBe1he2P6vHiEzCoXjELjhHqzR0SChORwDmTyBw=; b=A4vTOZT8+hhPbMEDmIMLcj+5JNAaOzTumZ4WpAMVvvL/BITnbyGRwfHbEkyIMMSRNJ 16evZ9xC/2A1Xq12Uo+3xDbzBbghAi32WNgWhvjLIysnWhQ39Bo1YrKhGQyzcNsh3CYd IsaNMeTJMpe4DsbPllu5Bpmm7PptPL0vvNkPUTZ5e8lNlxRnJQ7zHyUEy7PyIgV63RBb aR0Waus8cbS04XdtcF+dgGmF3Yym1c52KnQOEYdpBjR6IZZVA3ZwmmrrTZRRVZ9KDLe5 kjitzF4yeYm1FBLMs4DiHkvoVy0Nk11p4bQhMnxZfjgIjFJIBqwrI0khT3r3yY92Zg5J ygqg== X-Gm-Message-State: AOAM5318ZXJIQ8xrV3InH+fheJW5iP6pbHptQ3DIG1N79hOGUBVyn19e hmvn0PxKi81aChcSEtf8t0bAiHqUf8JfdA== X-Google-Smtp-Source: ABdhPJxMtbdEGCDCPndeZC3NtuvPFx4B+/a4IKK8Y9iDM7CyDEOVp/yG7zfhSQLReUgP+re6nM2/GA== X-Received: by 2002:a65:4bcb:: with SMTP id p11mr3533960pgr.253.1603489438336; Fri, 23 Oct 2020 14:43:58 -0700 (PDT) Received: from pmalani2.mtv.corp.google.com ([2620:15c:202:201:a28c:fdff:fef0:49dd]) by smtp.gmail.com with ESMTPSA id j8sm3167338pfr.121.2020.10.23.14.43.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Oct 2020 14:43:56 -0700 (PDT) From: Prashant Malani To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, gregkh@linuxfoundation.org Cc: Prashant Malani , Heikki Krogerus Subject: [PATCH v3 1/2] usb: typec: Consolidate syfs ABI documentation Date: Fri, 23 Oct 2020 14:43:26 -0700 Message-Id: <20201023214328.1262883-1-pmalani@chromium.org> X-Mailer: git-send-email 2.29.0.rc1.297.gfa9743e501-goog MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Both partner and cable have identity VDOs. These are listed separately in the Documentation/ABI/testing/sysfs-class-typec. Factor these out into a common location to avoid the duplication. Signed-off-by: Prashant Malani Acked-by: Heikki Krogerus --- Patch first introduced in v3. Documentation/ABI/testing/sysfs-class-typec | 59 ++++++--------------- 1 file changed, 17 insertions(+), 42 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-class-typec b/Documentation/ABI/testing/sysfs-class-typec index b834671522d6..0f839fd022f1 100644 --- a/Documentation/ABI/testing/sysfs-class-typec +++ b/Documentation/ABI/testing/sysfs-class-typec @@ -134,42 +134,6 @@ Description: Shows if the partner supports USB Power Delivery communication: Valid values: yes, no -What: /sys/class/typec/-partner>/identity/ -Date: April 2017 -Contact: Heikki Krogerus -Description: - This directory appears only if the port device driver is capable - of showing the result of Discover Identity USB power delivery - command. That will not always be possible even when USB power - delivery is supported, for example when USB power delivery - communication for the port is mostly handled in firmware. If the - directory exists, it will have an attribute file for every VDO - in Discover Identity command result. - -What: /sys/class/typec/-partner/identity/id_header -Date: April 2017 -Contact: Heikki Krogerus -Description: - ID Header VDO part of Discover Identity command result. The - value will show 0 until Discover Identity command result becomes - available. The value can be polled. - -What: /sys/class/typec/-partner/identity/cert_stat -Date: April 2017 -Contact: Heikki Krogerus -Description: - Cert Stat VDO part of Discover Identity command result. The - value will show 0 until Discover Identity command result becomes - available. The value can be polled. - -What: /sys/class/typec/-partner/identity/product -Date: April 2017 -Contact: Heikki Krogerus -Description: - Product VDO part of Discover Identity command result. The value - will show 0 until Discover Identity command result becomes - available. The value can be polled. - USB Type-C cable devices (eg. /sys/class/typec/port0-cable/) @@ -196,17 +160,28 @@ Description: - type-c - captive -What: /sys/class/typec/-cable/identity/ + +USB Type-C partner/cable Power Delivery Identity objects + +NOTE: The following attributes will be applicable to both +partner (e.g /sys/class/typec/port0-partner/) and +cable (e.g /sys/class/typec/port0-cable/) devices. Consequently, the example file +paths below are prefixed with "/sys/class/typec/-{partner|cable}/" to +reflect this. + +What: /sys/class/typec/-{partner|cable}/identity/ Date: April 2017 Contact: Heikki Krogerus Description: This directory appears only if the port device driver is capable of showing the result of Discover Identity USB power delivery command. That will not always be possible even when USB power - delivery is supported. If the directory exists, it will have an - attribute for every VDO returned by Discover Identity command. + delivery is supported, for example when USB power delivery + communication for the port is mostly handled in firmware. If the + directory exists, it will have an attribute file for every VDO + in Discover Identity command result. -What: /sys/class/typec/-cable/identity/id_header +What: /sys/class/typec/-{partner|cable}/identity/id_header Date: April 2017 Contact: Heikki Krogerus Description: @@ -214,7 +189,7 @@ Description: value will show 0 until Discover Identity command result becomes available. The value can be polled. -What: /sys/class/typec/-cable/identity/cert_stat +What: /sys/class/typec/-{partner|cable}/identity/cert_stat Date: April 2017 Contact: Heikki Krogerus Description: @@ -222,7 +197,7 @@ Description: value will show 0 until Discover Identity command result becomes available. The value can be polled. -What: /sys/class/typec/-cable/identity/product +What: /sys/class/typec/-{partner|cable}/identity/product Date: April 2017 Contact: Heikki Krogerus Description: From patchwork Fri Oct 23 21:43:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashant Malani X-Patchwork-Id: 287447 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19B6CC388F9 for ; Fri, 23 Oct 2020 21:44:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A3BC720857 for ; Fri, 23 Oct 2020 21:44:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="E0ZZgtQq" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756818AbgJWVob (ORCPT ); Fri, 23 Oct 2020 17:44:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756816AbgJWVob (ORCPT ); Fri, 23 Oct 2020 17:44:31 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75745C0613CE for ; Fri, 23 Oct 2020 14:44:31 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id o9so1699965plx.10 for ; Fri, 23 Oct 2020 14:44:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OgG2cGSuxI7ea5daz1551HiYcFBT61V4iIj710jhN0I=; b=E0ZZgtQqIuU5Eu+Gzpgp2TpPQqm1KKLr/1uXfjE0U7UK601Irv+sl6b3Nr8PcjLhwc GUGpSGMA2kdBNbc8m5ksM9L0k+zkvGIPUSMqgyXwNHfLzvgoMwtR06Ux0Vwgu+1qCDRf Hbt9i+FCR32Bx80rVlDC29mD/G9w67PY2Idyw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OgG2cGSuxI7ea5daz1551HiYcFBT61V4iIj710jhN0I=; b=X6uipdstGAalngiopit0wknFc94YD5rDd8j724LBEDq8itn65Z7Ch4ZqTSC94pk1jQ SRJrLIClpsLOXkuNyeDGQ3WS/da4f806ECrKmR6QD8824Wzydc5HN4fNFfqqDeLWn+Eg HcgrHsj2qeUvrIYL84YTpp4kSRnt8/2XGEScvlopNidbs4jKpt1fl0Z1Bo80LNWI6LBB YCacAiLUQ1kKa1A0sCOKY04lCwjE3oCw+7AhCg8uYCS2kustS+eYDU5SAINIFtrZH6WX L7W6R8B+l1vpl77OxRhLjQdptunTPlf6FVnaW9XZQ2sGHcZRWd95Nxnj5YSHAmO5g6po 9OVw== X-Gm-Message-State: AOAM530Co04Rz7F7kimSxA4/C8EFh0R1pfBUzQLQtBjQsaZRWd7o1cXX yKeG90dVQNTqVJP9oDlh8VHVpw== X-Google-Smtp-Source: ABdhPJw+CkVchg93BnA/tfTFgbR/AhlF0j+e1r8rg+XOIzaKeyNLYg80hlXgbhPsLje8SomihdWAvg== X-Received: by 2002:a17:902:76c5:b029:d3:db7d:7d85 with SMTP id j5-20020a17090276c5b02900d3db7d7d85mr4376730plt.24.1603489470987; Fri, 23 Oct 2020 14:44:30 -0700 (PDT) Received: from pmalani2.mtv.corp.google.com ([2620:15c:202:201:a28c:fdff:fef0:49dd]) by smtp.gmail.com with ESMTPSA id j8sm3167338pfr.121.2020.10.23.14.44.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Oct 2020 14:44:29 -0700 (PDT) From: Prashant Malani To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, gregkh@linuxfoundation.org Cc: Prashant Malani , Benson Leung , Heikki Krogerus Subject: [PATCH v3 2/2] usb: typec: Expose Product Type VDOs via sysfs Date: Fri, 23 Oct 2020 14:43:28 -0700 Message-Id: <20201023214328.1262883-2-pmalani@chromium.org> X-Mailer: git-send-email 2.29.0.rc1.297.gfa9743e501-goog In-Reply-To: <20201023214328.1262883-1-pmalani@chromium.org> References: <20201023214328.1262883-1-pmalani@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org A PD-capable device can return up to 3 Product Type VDOs as part of its DiscoverIdentity Response (USB PD Spec, Rev 3.0, Version 2.0, Section 6.4.4.3.1). Add sysfs attributes to expose these to userspace. Cc: Benson Leung Cc: Heikki Krogerus Signed-off-by: Prashant Malani --- Changes in v3: - Split each product type VDO into a separate attribute. - Changed sprintf() to sysfs_emit(). - Changed ABI documentation based on consolidation of identity VDO descriptions in the previous patch (1/2). Changes in v2: - Added sysfs_notify() call for the attribute. - Added description for the attribute in Documentation/ABI/testing/sysfs-class-typec. Documentation/ABI/testing/sysfs-class-typec | 24 +++++++++++++++ drivers/usb/typec/class.c | 33 +++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-class-typec b/Documentation/ABI/testing/sysfs-class-typec index 0f839fd022f1..0ac144bc5927 100644 --- a/Documentation/ABI/testing/sysfs-class-typec +++ b/Documentation/ABI/testing/sysfs-class-typec @@ -205,6 +205,30 @@ Description: will show 0 until Discover Identity command result becomes available. The value can be polled. +What: /sys/class/typec/-{partner|cable}/identity/product_type_vdo1 +Date: October 2020 +Contact: Prashant Malani +Description: + 1st Product Type VDO of Discover Identity command result. + The value will show 0 until Discover Identity command result becomes + available and a valid Product Type VDO is returned. + +What: /sys/class/typec/-{partner|cable}/identity/product_type_vdo2 +Date: October 2020 +Contact: Prashant Malani +Description: + 2nd Product Type VDO of Discover Identity command result. + The value will show 0 until Discover Identity command result becomes + available and a valid Product Type VDO is returned. + +What: /sys/class/typec/-{partner|cable}/identity/product_type_vdo3 +Date: October 2020 +Contact: Prashant Malani +Description: + 3rd Product Type VDO of Discover Identity command result. + The value will show 0 until Discover Identity command result becomes + available and a valid Product Type VDO is returned. + USB Type-C port alternate mode devices. diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index 35eec707cb51..a2c88594b044 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -122,10 +122,40 @@ static ssize_t product_show(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR_RO(product); +static ssize_t product_type_vdo1_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct usb_pd_identity *id = get_pd_identity(dev); + + return sysfs_emit(buf, "0x%08x\n", id->vdo[0]); +} +static DEVICE_ATTR_RO(product_type_vdo1); + +static ssize_t product_type_vdo2_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct usb_pd_identity *id = get_pd_identity(dev); + + return sysfs_emit(buf, "0x%08x\n", id->vdo[1]); +} +static DEVICE_ATTR_RO(product_type_vdo2); + +static ssize_t product_type_vdo3_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct usb_pd_identity *id = get_pd_identity(dev); + + return sysfs_emit(buf, "0x%08x\n", id->vdo[2]); +} +static DEVICE_ATTR_RO(product_type_vdo3); + static struct attribute *usb_pd_id_attrs[] = { &dev_attr_id_header.attr, &dev_attr_cert_stat.attr, &dev_attr_product.attr, + &dev_attr_product_type_vdo1.attr, + &dev_attr_product_type_vdo2.attr, + &dev_attr_product_type_vdo3.attr, NULL }; @@ -144,6 +174,9 @@ static void typec_report_identity(struct device *dev) sysfs_notify(&dev->kobj, "identity", "id_header"); sysfs_notify(&dev->kobj, "identity", "cert_stat"); sysfs_notify(&dev->kobj, "identity", "product"); + sysfs_notify(&dev->kobj, "identity", "product_type_vdo1"); + sysfs_notify(&dev->kobj, "identity", "product_type_vdo2"); + sysfs_notify(&dev->kobj, "identity", "product_type_vdo3"); } /* ------------------------------------------------------------------------- */