Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp925688pxu; Fri, 23 Oct 2020 17:35:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxRblc25uBSQmyImZ90RODcE7ByvD821XfrwLRFd/lM5oNKKw2sJi4HoryZUKZJlwvKxhGf X-Received: by 2002:a50:dac1:: with SMTP id s1mr4893712edj.74.1603499736308; Fri, 23 Oct 2020 17:35:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603499736; cv=none; d=google.com; s=arc-20160816; b=p68FmVVuGhvTk+oFBRp+noGV2lqZOMTn8rVmTVIonT54hb4eY3ICy2q3Vwd1cteiXL an2cJTPQaulPXugSJvT8okZqc7rbbuYflCsUb6ca7gmh20Io6MXVsW7dpd+odESPk/E3 68QOlz1m3fW50dqPxuWvzMr5dQxq875jOeWkEy3BRgGzfPdtUqrcV/+jqAeAAw7v3h8h n6VoVq/iIHyfeTRA3oSt1cVMQOVoTj3MgwVhlYyI49Zax52IP5TValFjpbiAxyIsqSpt Hmq0DB3qdoKmyIRD+FH+236L22zKU5gs0V2XTRUH1GE8WGkZ8vmrAx3l7pEYdVhKyx27 DHCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=OgG2cGSuxI7ea5daz1551HiYcFBT61V4iIj710jhN0I=; b=VDcaR5bT0cWFNP0a1xmRpTV52MSA6tGWNzy2CJlMj+bHtmyEVXfoCEg7Tprl3ZmOTl fKD/S8dqGxFKtVTBL77OPSty9ekEhR+PemlZ2i1qtAKOzRTL1vQrs6wK4ljFwwDuWI72 oR7A90gl5kNgDP20Q7OkFgnEj/p/LfVHYkBsMBYEgDKedtqmxfXpSpUiDnren4U7/PrM x4adtGnYeJbHaOi+1w522hFBFOrtBnIbTqtc1HX4ocrqGCWvPn4JBMhvaV3KOuWwfiBA 4ZPgeN7fBibEgtNe9QRIRFjA2n+N/XMHEMhRjlH8fvzAORsk1L8t/aJHNBqNCwbbN4+F ObrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=E0ZZgtQq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g3si1917452edu.80.2020.10.23.17.35.14; Fri, 23 Oct 2020 17:35:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=E0ZZgtQq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756822AbgJWVoe (ORCPT + 99 others); Fri, 23 Oct 2020 17:44:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756816AbgJWVod (ORCPT ); Fri, 23 Oct 2020 17:44:33 -0400 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 278FFC0613CE for ; Fri, 23 Oct 2020 14:44:32 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id j5so1709235plk.7 for ; Fri, 23 Oct 2020 14:44:32 -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=mPEZBsQHaqll76LqHeJU7Rs3+BvfNXxlHmmBk/HD6AAc7Aktfpg3C2sDurxKmh8X1A U21IwGiGA7WPgk3Sko89KMo6mJuc4I3rHevIVBcUqRB11YfiXIUxGrZ36omGE3Qiy9JW kVbrgpwtt9uM8hwjQpFz+bVjeDEMXkVnodOf9t7lYWzOTAeQ7VIe2+IB7lbhHmtBPBhy 5Z2cV8CK/dQRy7SOEnvVFL+OiidU8HdX3SNAtGeDlgOYJ9foG7R/uNN4eydxTKZKpiNI R9vQ93Xvncmw5IIeAGhbcrL0cWBvGy2dk1f35JdiV7ddkztqCh8KZ2EtdYQ9q7ujzzlr C2zQ== X-Gm-Message-State: AOAM530lBm6Je0UznUL8GdzXooOP669QDWPrHsHfLsr8bonhyfPlt7bq 4vn2nzzuoZRZc98FVezHRN70xGawjwUWSw== 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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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"); } /* ------------------------------------------------------------------------- */ -- 2.29.0.rc1.297.gfa9743e501-goog