From patchwork Wed Nov 25 08:49:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashant Malani X-Patchwork-Id: 11930623 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=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,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 E70A8C56201 for ; Wed, 25 Nov 2020 08:49:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 83130208C3 for ; Wed, 25 Nov 2020 08:49:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="frWQrn9p" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726788AbgKYItV (ORCPT ); Wed, 25 Nov 2020 03:49:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725921AbgKYItV (ORCPT ); Wed, 25 Nov 2020 03:49:21 -0500 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6719CC0613D4 for ; Wed, 25 Nov 2020 00:49:19 -0800 (PST) Received: by mail-pf1-x443.google.com with SMTP id q10so1695967pfn.0 for ; Wed, 25 Nov 2020 00:49:19 -0800 (PST) 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=nFwhSlS+Pvo/ma1TQw3B7yiFr0R2qAwmXx/iKMM6vms=; b=frWQrn9pB0jVThrEPqb3eSmYoAF/DmAkevYHE/b7Kb/MtEMwg1wEoyUVPvDzVdkC7S awjLFmy08lOwdUKcSB+RSaSRR3V1etU592zZ2lQlCCMiwE8qRBnv8yXfdWi121+Dn8Uo UK5w1RYog3/O+B/byNkYgyltobyOUOKSijY0o= 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=nFwhSlS+Pvo/ma1TQw3B7yiFr0R2qAwmXx/iKMM6vms=; b=AVYJB+nj8AD5/+oUCbYvUs3EEVOuPRbmE1uhNYWZF8pcGV6SEB2M5Ip0sF9RXOW35B rTrFtUqmMVbKY46hiwFk/Jfp8BEhtvTaPYbKeAp7n2GfLpTiwti7r1JY8AM2kHoUiz4G SlM2BShvX7A6mVoTPruPyLEOfb/ftNv6iONgpvbMXTyxCmxwXfzJIkZU7/fzxQBll+vE vytrXu5lJZAATc6WwezT1Lab+wVUrcTcyoUSC8h0WB1O2rLq5m/j4luMQwNdI2wP1eAu eOuziPCgrncxc1OjlW8ltEiLK2P7esxUsUyJ4TYUYARdtPe3lfStF+hfErqFlQgSsVXI gSKQ== X-Gm-Message-State: AOAM533GVuhSyP2kO/QgVh9JFpfNSciwmKEo7lO5RwXSQKbpxeeF1bYq myE5uSFqt0XRNII2qoq4hyReTg== X-Google-Smtp-Source: ABdhPJx+iqGZOhgaw4SyQsTcTvCYlAyqdoKyfeekSxIq7yqnD+XM7aGa51oCMv9CwhVXGSCgT3rE7A== X-Received: by 2002:a63:575a:: with SMTP id h26mr2270634pgm.228.1606294158950; Wed, 25 Nov 2020 00:49:18 -0800 (PST) Received: from pmalani2.mtv.corp.google.com ([2620:15c:202:201:a28c:fdff:fef0:49dd]) by smtp.gmail.com with ESMTPSA id x30sm1554565pgc.86.2020.11.25.00.49.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Nov 2020 00:49:18 -0800 (PST) From: Prashant Malani To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, gregkh@linuxfoundation.org, heikki.krogerus@linux.intel.com Cc: bleung@chromium.org, Prashant Malani Subject: [PATCH v5 1/2] usb: typec: Consolidate sysfs ABI documentation Date: Wed, 25 Nov 2020 00:49:09 -0800 Message-Id: <20201125084911.1077462-1-pmalani@chromium.org> X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-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 --- Changes in v5: - Corrected the email address in the Acked-by tag. Changes in v4: - Rebased on top of the usb-next tree. - Added Acked-by tag from pevious version's review. - Corrected a typo ('syfs' -> 'sysfs') in the subject line. 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 4eccb343fc7b..88ffc14d4cd2 100644 --- a/Documentation/ABI/testing/sysfs-class-typec +++ b/Documentation/ABI/testing/sysfs-class-typec @@ -147,42 +147,6 @@ Description: during Power Delivery discovery. This file remains hidden until a value greater than or equal to 0 is set by Type C port driver. -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/) @@ -219,17 +183,28 @@ Description: This file remains hidden until a value greater than or equal to 0 is set by Type C port driver. -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: @@ -237,7 +212,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: @@ -245,7 +220,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 Wed Nov 25 08:49:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashant Malani X-Patchwork-Id: 11930625 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=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,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 29131C5519F for ; Wed, 25 Nov 2020 08:50:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CAFB420637 for ; Wed, 25 Nov 2020 08:50:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="kYBbA8lp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727102AbgKYItq (ORCPT ); Wed, 25 Nov 2020 03:49:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726114AbgKYItp (ORCPT ); Wed, 25 Nov 2020 03:49:45 -0500 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E3B7C0613D4 for ; Wed, 25 Nov 2020 00:49:33 -0800 (PST) Received: by mail-pf1-x42f.google.com with SMTP id s21so1633884pfu.13 for ; Wed, 25 Nov 2020 00:49:33 -0800 (PST) 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=N2uwajG3CxRUDHB7vBWCIv/Ki2W9TnG3exx+vXLzSoo=; b=kYBbA8lp6mxajAikjU6kMO65tlbWy7UktZtUnCGR6blskKlku9P8QUyIA/cA7Dio1p tp9ktDi2JNreA8gPZxhc8VsZeSYHzBjFULix//m3lKHd1StJ4waE82yY2gnd0oluD/0B 2a/2uSRbUmFsqrjcj7NBzs099KTFX3xN6A1EY= 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=N2uwajG3CxRUDHB7vBWCIv/Ki2W9TnG3exx+vXLzSoo=; b=HtV8qgV9A+8/jIxa9obbobxZmyqHg/56HHLEQKavhcT+//s7vs098M04H0BILS+xQ6 aiDLvxJmfJ8hzINWhYJDRgMJqSZsDBmvNl3vf8zmFN925GObL0LQl+xbKs7H2ZuuO2r+ EKXHsE21qD+XkB3b/zBCxsh+LjP+g3bBhtZy7OAUxMkkGb/6jPywqqAaNMf5YJ7sc4Ti 7YwUn6YKFTsdyq/DO/ufiFdRJ4+nrH4mbuXb+IEff1LR8Bx1Kr/ZgjncMSwCJPRJV4iy c1SXY/6O6VV6ml5Rh6O1igbyTT4X8PV4PZh/AgyAxSCjTy4En3zsuzVKy1NLEP2RU4jc BrHA== X-Gm-Message-State: AOAM531B9mR93FCppDgkFmAw13Mt4fhy/20620YmWQZrYstRFgZhOM2M RAVT0keG+/Q8esCWyUgHN2FGYA== X-Google-Smtp-Source: ABdhPJyrpuVK5ePMHRJfRGDGX76gEoJyMmbZpv/GCtDsR15xASFOiZhJ0WcCFGEiN8gF27zDd9+Bxg== X-Received: by 2002:a17:90a:6287:: with SMTP id d7mr2868356pjj.80.1606294172684; Wed, 25 Nov 2020 00:49:32 -0800 (PST) Received: from pmalani2.mtv.corp.google.com ([2620:15c:202:201:a28c:fdff:fef0:49dd]) by smtp.gmail.com with ESMTPSA id x30sm1554565pgc.86.2020.11.25.00.49.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Nov 2020 00:49:32 -0800 (PST) From: Prashant Malani To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, gregkh@linuxfoundation.org, heikki.krogerus@linux.intel.com Cc: bleung@chromium.org, Prashant Malani Subject: [PATCH v5 2/2] usb: typec: Expose Product Type VDOs via sysfs Date: Wed, 25 Nov 2020 00:49:11 -0800 Message-Id: <20201125084911.1077462-2-pmalani@chromium.org> X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog In-Reply-To: <20201125084911.1077462-1-pmalani@chromium.org> References: <20201125084911.1077462-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 Reviewed-by: Heikki Krogerus --- Changes in v5: - No changes. Changes in v4: - Added Reviewed-by tag from v3's review. - Rebased on top of usb-next + Patch 1/2 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 88ffc14d4cd2..619c4c67432b 100644 --- a/Documentation/ABI/testing/sysfs-class-typec +++ b/Documentation/ABI/testing/sysfs-class-typec @@ -228,6 +228,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 cb1362187a7c..df4478baf95b 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -124,10 +124,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 }; @@ -146,6 +176,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"); } /* ------------------------------------------------------------------------- */