From patchwork Wed Feb 7 14:58:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heikki Krogerus X-Patchwork-Id: 198074 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2463164dyb; Wed, 7 Feb 2024 11:39:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IHPwhbnpYUO8q1qkbdHCLJEWHf8qRgZmNcBc9zjevWSS8if3Fr+lpmhS/I2mteaUPp/auJh X-Received: by 2002:a17:902:7406:b0:1d8:ed67:c360 with SMTP id g6-20020a170902740600b001d8ed67c360mr5328254pll.65.1707334762640; Wed, 07 Feb 2024 11:39:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707334762; cv=pass; d=google.com; s=arc-20160816; b=mvU+WtgzEl2hKXDFoaCXAd6ymnk63gyqvhqw0Ze3kT4Mv3R/Y+/eH/HApiStmcnCDH 9p0iUpkps4o43eU6aSbqTxHs6NCotrg6/jWZQwfjnX+jTuo2uMkRZY7iJorMuq8MWWYh YVGo8Kohlbejp0Q+HAQjQkQfhWhf5wUwclLezG1UxRA5lO+zlbfzKdJ2/0POVZXuP0pc qJ4ROEwSfabOzjICjMmWV2A/qMpPboUvfSrmolQp1Fx+XibYmSWK8hFY9kS1cBBuT1xF CkptAVYfwU4ftkwR6UQzpe6MyoUk0gWPiMYUmLQPsXUtAmXDbyJjaXYJnHPtx0exYXvw IV/w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Id1kXEmgbvhsjNsRFfcvA9HSMtMImcLL5ffkY+gRtuQ=; fh=WqSKLVXm8Ly3BeHQ5QqD0HvLtQKmKhg2CGdzS6xen7A=; b=zvwQYN5ppBecXTL7LyDJPnHDdZAMd9xginWd+cauT3k9Q56xNGP7XE4eF4yAkQBp51 uKfauFaawo16Ugod0JD+4bJ4+af4v3GY9eyaB1mRFdDChMcQRzMO6bFL1I3vrzyt+irK dydML4pROurViyClIQJruZW/DdjSkc2akcA3oc6fmvAmCLpefAPPTay8IfcRCkn/nRrV XwdLIVM61Lmxl7uhhL9RQGI9X5wwyqZKH4el/0opBtha3W7hcIhhpm0OH1hydPGYuirC tOZiiVnGSKlQA01d6zAGu46blrcCfgZxHVMGzb7DlnIkPqCd3PA9xPHnNZR+0gUIx/7e 0y8A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BUvUlMmO; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-56681-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56681-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCWWhl2IboJQVmPDFAGUId9nBC1Mo3g1z2Rl0RHKNtJDnvSsOYhdqt//wCfhUODB7FYdFbXiW+eUYr/ZbrES44aoFMzV3g== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id y3-20020a17090322c300b001d94544ed1esi2442788plg.410.2024.02.07.11.39.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 11:39:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56681-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BUvUlMmO; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-56681-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56681-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 1F8C6292AD2 for ; Wed, 7 Feb 2024 14:59:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5D4A87FBBF; Wed, 7 Feb 2024 14:59:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="BUvUlMmO" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 112B67E576; Wed, 7 Feb 2024 14:59:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707317953; cv=none; b=WiwxlTSm81N6DjtyKwosH81q+4YzDiLE2+fhi6iKYzMkhaykvSyC4zttjGtQ5p3r9c7VkjRaL6+4h2sRFI0Hj7Ust3L68utFT7MRwNVool8PX94XrlBbykUjT8zsx/B2TJozSwhBGXCnQrGGAUxY5rapndkURwjG3i5xt2j7knc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707317953; c=relaxed/simple; bh=GPXSlwYiixoQscrKQneXqLxQNPyv7GTgiXwdLZGez6A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VqlqhQpxlQOzyFjD70MXxbC4fx3xy0u3J4UuuoOqJCZOzZc2IFsuRDXBlNDZfTr0aARdTzdlqLh99TrXT7oyQciCiOBY41TU83Qjc/3TCwe6mMZvthVoUIoUmDgSTn1nTusH5HT+29gzTAhSuXH3IA32HcFQkpHYhCzHKxys4cU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=BUvUlMmO; arc=none smtp.client-ip=198.175.65.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707317952; x=1738853952; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GPXSlwYiixoQscrKQneXqLxQNPyv7GTgiXwdLZGez6A=; b=BUvUlMmOt24xf90VsWCgb03ED9T/6K7zu5Q53Il5IdCM9nVXczOJgg8T mpvzTDwjttvNNKFt9JaRebxkbgbQwZp8jZi9/viSN0OoEUnwWn3AqBB6E FFQPzTjL7UZm+To2go2hOcH+TrldtfUA6pf7X3BAy+8OWFu1MdVvk3XuN 1j+cC2/7q5/CexQi7XOU6DGvA4QkNomci1WxAMP7PHGH7TFQerRaZB9lU RpLFHbH4QBSBoOKnPNttfquFtlHHHEvbqeY1foaAx4di95VqkddsEL7OJ xFKjmEXdiY06QTLXMkZBIEMjUrsGry01AemapDe8hO6zGrPxqg6aYKr1m A==; X-IronPort-AV: E=McAfee;i="6600,9927,10977"; a="1155027" X-IronPort-AV: E=Sophos;i="6.05,251,1701158400"; d="scan'208";a="1155027" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Feb 2024 06:59:11 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10977"; a="933799197" X-IronPort-AV: E=Sophos;i="6.05,251,1701158400"; d="scan'208";a="933799197" Received: from black.fi.intel.com (HELO black.fi.intel.com.) ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 07 Feb 2024 06:58:56 -0800 From: Heikki Krogerus To: Prashant Malani , Greg Kroah-Hartman Cc: Benson Leung , Tzung-Bi Shih , Guenter Roeck , Emilie Roberts , "Nyman, Mathias" , "Regupathy, Rajaram" , "Radjacoumar, Shyam Sundar" , Samuel Jacob , linux-usb@vger.kernel.org, chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org, Uday Bhat Subject: [PATCH 1/2] usb: roles: Link the switch to its connector Date: Wed, 7 Feb 2024 16:58:50 +0200 Message-ID: <20240207145851.1603237-2-heikki.krogerus@linux.intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240207145851.1603237-1-heikki.krogerus@linux.intel.com> References: <20240207145851.1603237-1-heikki.krogerus@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790270256201928784 X-GMAIL-MSGID: 1790270256201928784 This is probable useful information to have in user space in general, but it's primarily needed for the xHCI DbC (Debug Capability). When xHCI DbC is being used, the USB port needs to be muxed to the xHCI even in device role. In xHCI DbC mode, the xHCI is the USB device controller. Tested-by: Uday Bhat Signed-off-by: Heikki Krogerus --- .../ABI/testing/sysfs-class-usb_role | 6 +++ drivers/usb/roles/class.c | 40 ++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-class-usb_role b/Documentation/ABI/testing/sysfs-class-usb_role index 3b810a425a52..9fab3f06679e 100644 --- a/Documentation/ABI/testing/sysfs-class-usb_role +++ b/Documentation/ABI/testing/sysfs-class-usb_role @@ -19,3 +19,9 @@ Description: - none - host - device + +What: /sys/class/usb_role//connector +Date: Feb 2024 +Contact: Heikki Krogerus +Description: + Optional symlink to the USB Type-C connector. diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c index ae41578bd014..4ad03c93c17f 100644 --- a/drivers/usb/roles/class.c +++ b/drivers/usb/roles/class.c @@ -7,6 +7,7 @@ * Hans de Goede */ +#include #include #include #include @@ -34,6 +35,32 @@ struct usb_role_switch { #define to_role_switch(d) container_of(d, struct usb_role_switch, dev) +static int connector_bind(struct device *dev, struct device *connector, void *data) +{ + int ret; + + ret = sysfs_create_link(&dev->kobj, &connector->kobj, "connector"); + if (ret) + return ret; + + ret = sysfs_create_link(&connector->kobj, &dev->kobj, "usb-role-switch"); + if (ret) + sysfs_remove_link(&dev->kobj, "connector"); + + return ret; +} + +static void connector_unbind(struct device *dev, struct device *connector, void *data) +{ + sysfs_remove_link(&connector->kobj, "usb-role-switch"); + sysfs_remove_link(&dev->kobj, "connector"); +} + +static const struct component_ops connector_ops = { + .bind = connector_bind, + .unbind = connector_unbind, +}; + /** * usb_role_switch_set_role - Set USB role for a switch * @sw: USB role switch @@ -352,6 +379,12 @@ usb_role_switch_register(struct device *parent, return ERR_PTR(ret); } + if (dev_fwnode(&sw->dev)) { + ret = component_add(&sw->dev, &connector_ops); + if (ret) + dev_warn(&sw->dev, "failed to add component\n"); + } + /* TODO: Symlinks for the host port and the device controller. */ return sw; @@ -366,8 +399,11 @@ EXPORT_SYMBOL_GPL(usb_role_switch_register); */ void usb_role_switch_unregister(struct usb_role_switch *sw) { - if (!IS_ERR_OR_NULL(sw)) - device_unregister(&sw->dev); + if (IS_ERR_OR_NULL(sw)) + return; + if (dev_fwnode(&sw->dev)) + component_del(&sw->dev, &connector_ops); + device_unregister(&sw->dev); } EXPORT_SYMBOL_GPL(usb_role_switch_unregister);