From patchwork Sat Feb 10 07:09:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 771770 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4936D33CFD for ; Sat, 10 Feb 2024 07:09:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707548987; cv=none; b=TTgwaMT/+9PCjgNkqRwBKg4/P/5sc/xruVfGHh7m84pT6pCoAiLwzHQ8yBbcDBPHeteFGdihNGFes+CL37t+7eBvidrnEWVU7E7o1sFWYtj62z00P3023Z8+s1MhKu8V/zgoUGxbTnSyprMDlUArMFOFJfwg6WrzIVHZIcgBWyw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707548987; c=relaxed/simple; bh=PeDZQIpv2F0nTTHxmAelufZ+9YaQdvo2eTiG/pHOI/0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KSe9Sz4nE+fk8FGGcvqkw0GRSDBfdLrNbYs2nOSP8QRYLUsHZRp7Nyrjzz1MH/Er+FjLsHFr6Dk0YHRPpRmXE8qY2qhZtWW7NSEfXXfATAiMP0Vl9zNjdVqVKG65eQVCnsMxNx/y3Ev5AesAuAWtM7Is4gjSOqUnkWavHWJh8NE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=V8Rpmmbt; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="V8Rpmmbt" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1d918008b99so13127605ad.3 for ; Fri, 09 Feb 2024 23:09:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1707548985; x=1708153785; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UENrcY9RF89XEYAUM3UR0Kbw3cAWGOtKrrlH+rPz1Os=; b=V8RpmmbtVgxWHoxqOFc7tENIuYkwazXzg4eidDuBlO8Cq9PtVTk96TkMHZNBHr8LlV bEP7G12qkPEmZbzH81YOLuf7qRWq/RQLZpIAQu33wcQq415kvWxBySIQ4uFLKsybJsL9 e2COkiut7CVrcyNLBGYULG5RSOideCB1ks9Kk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707548985; x=1708153785; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UENrcY9RF89XEYAUM3UR0Kbw3cAWGOtKrrlH+rPz1Os=; b=qS44OzYFEZG6wQ8mhV6N9SQYPrfH8sHKo0MaYqLenghlJYY2c3ixe/dNHh1PQ2qlrL MchLAIIxAWgcI/lnr4OdvdE0jX8dghzEp+tk2eo0XcYqT4nyyrrhWlaYbPHWhgRKAk7R o0sUwvN+7dZjL8Vc8FJcoBwwOSxAbTz3EVNxnrjMvFuZfltKOWUc4Am70AEM0uKdcL96 WWKVuehUGtp2iXcrhAi3KAT0XhhE72mYiL3RAUDIdhRQ78+29GCQfKUjrNr4yZlGXO7O qM0YfLcnbbl6IGf5p30qc9il//84mTQBhdBzvES+rnKoaw6ibIezJ6x5mQYpURcUbYOI /Bow== X-Gm-Message-State: AOJu0Yy41Fr0YGJ3aPyG/F9HyvZqesyE5lzZQms5/ol12oWwRj4aly8m xnx/d8RJvRcth8+OL86qyf2npaKbuhVSUW9uYxcmybL3h0ExYPCV6VMvjBcZQw== X-Google-Smtp-Source: AGHT+IGeYAK8ekxYXXY78qIHAecfdEKLr4g2+PQLKllAtw8+dhESn/vcq+039wpruZ/mWbRUYcdc5Q== X-Received: by 2002:a17:903:58b:b0:1d9:b789:b1bd with SMTP id jv11-20020a170903058b00b001d9b789b1bdmr1490617plb.9.1707548984724; Fri, 09 Feb 2024 23:09:44 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCW8sDzfMYBYjxyemsK+fiduXCKeElhlPm2IA15iWaQTyosgIv3SXegARx/7gWwIoNMf/OYJ1E5L5O5Yb2b2cIysWnO1oBD1SfE/Xesyq0bvl9Qttr51I2bt9ClXYAhX3IXr8h4Hu9CW6OoRfdlMa2TibWpE7LcBN1K8yo7rWf7F8oEzsK7wzzFq8ZitQ252uzLEjAaf+53MhwjFdA1ZyhuS8wLGDgnSyuia6hk1G3N/eEipCDs89DaebviqoHKBjDRZHKPc3zKsHGXtXUZUiqWOIKZLxWz89I6rUigdeA3U8/KzF/uxgWGJgOMP5mj52kafxMePldEjGbWkyKShGLNqo7W47/Z/OE8vsmZt8/drrEqhpc97BRAuzJ0UEJ+6JdgF89TFwnsdyCGgr29sP1qQcsFwW9SU6tKWO36qSqLHbn5pCKLzla/cJafZwaHTtTm2gWe9W6TnaLjptpvJDvFXaSttVVWHj7K67Uou9dL/lbB0Q+WtVQK/o8teLN2FjNT7QQlI Received: from localhost (175.199.125.34.bc.googleusercontent.com. [34.125.199.175]) by smtp.gmail.com with UTF8SMTPSA id d4-20020a170903230400b001d90a67e10bsm2489560plh.109.2024.02.09.23.09.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 09 Feb 2024 23:09:44 -0800 (PST) From: Stephen Boyd To: chrome-platform@lists.linux.dev Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-msm@vger.kernel.org, Douglas Anderson , Pin-yen Lin , Greg Kroah-Hartman , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Matthias Kaehlcke , linux-usb@vger.kernel.org, maciek swiech Subject: [PATCH 03/22] dt-bindings: usb: Add downstream facing ports to realtek binding Date: Fri, 9 Feb 2024 23:09:14 -0800 Message-ID: <20240210070934.2549994-4-swboyd@chromium.org> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog In-Reply-To: <20240210070934.2549994-1-swboyd@chromium.org> References: <20240210070934.2549994-1-swboyd@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add a graph with 4 output endpoints to this hub binding to support the scenario where a downstream facing port is connected to a device that isn't a connector or a USB device with a VID:PID. This will be used to connect downstream facing ports to USB type-c switches so the USB superspeed and high speed lanes can be put onto USB connectors. Cc: Greg Kroah-Hartman Cc: Rob Herring Cc: Krzysztof Kozlowski Cc: Conor Dooley Cc: Matthias Kaehlcke Cc: Cc: Cc: Pin-yen Lin Cc: maciek swiech Signed-off-by: Stephen Boyd --- .../bindings/usb/realtek,rts5411.yaml | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/Documentation/devicetree/bindings/usb/realtek,rts5411.yaml b/Documentation/devicetree/bindings/usb/realtek,rts5411.yaml index f0784d2e86da..5480a31698be 100644 --- a/Documentation/devicetree/bindings/usb/realtek,rts5411.yaml +++ b/Documentation/devicetree/bindings/usb/realtek,rts5411.yaml @@ -21,6 +21,12 @@ properties: reg: true + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + vdd-supply: description: phandle to the regulator that provides power to the hub. @@ -30,6 +36,36 @@ properties: description: phandle to the peer hub on the controller. + ports: + $ref: /schemas/graph.yaml#/properties/ports + + properties: + port@1: + $ref: /schemas/graph.yaml#/properties/port + description: + 1st downstream facing USB port + + port@2: + $ref: /schemas/graph.yaml#/properties/port + description: + 2nd downstream facing USB port + + port@3: + $ref: /schemas/graph.yaml#/properties/port + description: + 3rd downstream facing USB port + + port@4: + $ref: /schemas/graph.yaml#/properties/port + description: + 4th downstream facing USB port + +patternProperties: + "^.*@[1-4]$": + description: The hard wired USB devices + type: object + $ref: /schemas/usb/usb-device.yaml + required: - peer-hub - compatible @@ -50,6 +86,11 @@ examples: reg = <1>; vdd-supply = <&pp3300_hub>; peer-hub = <&hub_3_0>; + /* USB 2.0 device on port 2 */ + device@2 { + compatible = "usb123,4567"; + reg = <2>; + }; }; /* 3.0 hub on port 2 */ @@ -58,5 +99,14 @@ examples: reg = <2>; vdd-supply = <&pp3300_hub>; peer-hub = <&hub_2_0>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + port@0 { + reg = <0>; + remote-endpoint = <&usb_a0_ss>; + }; + }; }; }; From patchwork Sat Feb 10 07:09:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 772016 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AAE75364A8 for ; Sat, 10 Feb 2024 07:09:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707548988; cv=none; b=QF6WWnVxaTd+BcMi1u1z1zrrmQ2KyBL+r+hmWMqsLLQ8HvTyeyaZkPlMyPIHLEY/uDStiKTOL8BLWt2i5SwKwqq1NHHfQj9apz0vGexIqe+YKHtKty6u5ymuz6VKeM+anONDjRRmVORP34p/pvR/vfmFgT9Bs/Wmkd9C7jUbQdM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707548988; c=relaxed/simple; bh=W4vZ4x3CP8SVyUrgLk7eS968yXX65ZHvPF7MpQkPKkM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mY4OITogNCFXseEAr2oXP9wKhmBou3BwGMGbzNI9jsKiwz5KNFZIPEe4LcOpAgYBL3r+12Ca9qz4ZT+zz/Z0/rkPNYQHHGcQQQuUEehtUFytZveBQPnVwjkYfjI1nWkDCbkNHKT9ZGFo2oWVVku26ng+RrBlrBKfQcmLAsTaFtw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=TyjwoXwY; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="TyjwoXwY" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1d73066880eso15192815ad.3 for ; Fri, 09 Feb 2024 23:09:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1707548986; x=1708153786; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fkD+zP+NWB9AGWV79+gv+/kfpMf3rGsHXh6c/wyG7zI=; b=TyjwoXwYgnd5orU7V6QnnN2OS9KYbnGH+gVPPF7XRwWQuAc1FxMfwBXZBSJlJqNOLt c/11weyUy7oAyNbewcfYDqSTc2Jm+hMKYn2qePF8ny7grKTi1ws/OLrkYKrm0mIKkoKF CTY+ov395mLQWmuFmGG5A/cd5od+1l16RwWwI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707548986; x=1708153786; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fkD+zP+NWB9AGWV79+gv+/kfpMf3rGsHXh6c/wyG7zI=; b=nyxULyIgbGGFfBRfxqWox7quj0SHeiUp39htfdGkV4Rp9eidCfPbRswhsYj7o/dydT G97XV5La6G0pBLBM7b2E/3W7Oyais5YC/3pgq3N8DOrCcIR739WgG5DuFNom2gAIpXGH QM/3rP7ahLO9kiXcLs8mPOqQacG2pbiF+Y3Hg1YCsspNywroRohxmkz2mX1niiU3j8xQ dfqRHEGYVSSSWoAkn7Z+RorLruBYE9MSSKcUMir2QYb6NXagp07dP8gHA4h157JZK44p FRfvmarQshuakdurOLTmtReKTxUomBmZ2Tag7Y2xg7McgirW98ls6B28sCUU2uL+93vF OcOg== X-Gm-Message-State: AOJu0Yx+ZL6jwx1fTLFxojvZcgQQJC9gYweqevFwdFenWgeyaE18Sndm XF10CfA9XlbK5o0O0AbtS+GaKs/JxGKn8mGAEE1Hh3HlnI6S1sk0D+J0ro889A== X-Google-Smtp-Source: AGHT+IE/c8pAa5MU1KCu70BaKjPYC9gLrHaGU87OjcL/070j/D4osq6hs+au4elV+2dq4cOgocJ5RA== X-Received: by 2002:a17:902:be14:b0:1d9:a609:dd7e with SMTP id r20-20020a170902be1400b001d9a609dd7emr1710601pls.55.1707548986273; Fri, 09 Feb 2024 23:09:46 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWI/ch18h9Q0LqkhYI9qvNSPXFKaQ+zZTw5iEWVutGXC3kUt5cSlLojPVIjctJzLIWli2TuZoulZ+xv5+4F5cm7BXzU7J5caPmQUVkQv44C6fgnze1u2LBEoJf8sgUoniTVtWZLh4LZvZ8AJIM0I7jYhvtvTaaRqt3PeoJmmTByxWzuN7Ik8fhGlYmoSGsGpd5UHFVZ9L0sCnLiMBuFuKlczas0/e64Cxru+iSkN39jwppcmC1t0TpWb8QRmt0LqsNfljAZTuKdWjvhzbz2EhmN/NRUdJVChHtcwqwPFitd97FaAVr1uzBS7oqnZruWzoFzq9fZSmAWd+ZAMD5jmNYZCDrPho+8AiRsCrSChYF0TsCKV8fj15RoxF6c8Rql53xnKG6zFvg2TN2LT5wAkXlr7HPGiA0ZcDk= Received: from localhost (175.199.125.34.bc.googleusercontent.com. [34.125.199.175]) by smtp.gmail.com with UTF8SMTPSA id s7-20020a170903320700b001d9b749d281sm2493240plh.53.2024.02.09.23.09.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 09 Feb 2024 23:09:45 -0800 (PST) From: Stephen Boyd To: chrome-platform@lists.linux.dev Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-msm@vger.kernel.org, Douglas Anderson , Pin-yen Lin , Greg Kroah-Hartman , Matthias Kaehlcke , linux-usb@vger.kernel.org, maciek swiech Subject: [PATCH 04/22] usb: core: Set connect_type of ports based on DT node Date: Fri, 9 Feb 2024 23:09:15 -0800 Message-ID: <20240210070934.2549994-5-swboyd@chromium.org> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog In-Reply-To: <20240210070934.2549994-1-swboyd@chromium.org> References: <20240210070934.2549994-1-swboyd@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When a USB hub is described in DT, such as any device that matches the onboard-hub driver, the connect_type is set to "unknown" or USB_PORT_CONNECT_TYPE_UNKNOWN. This makes any device plugged into that USB port report their 'removable' device attribute as "unknown". Improve the connect_type attribute for ports, and in turn the removable attribute for USB devices, by looking for child devices with a reg property or an OF graph when the device is described in DT. If the graph exists, endpoints that are connected to a remote node must be something like a usb-{a,b,c}-connector compatible node, or an intermediate node like a redriver, and not a hardwired USB device on the board. Set the connect_type to USB_PORT_CONNECT_TYPE_HOT_PLUG in this case because the device is going to be plugged in. Set the connect_type to USB_PORT_CONNECT_TYPE_HARD_WIRED if there's a child node for the port like 'device@2' for port2. Set the connect_type to USB_PORT_NOT_USED if there isn't an endpoint or child node corresponding to the port number. To make sure things don't change, only set the port to not used if there are child nodes. This way an onboard hub connect_type doesn't change until ports are added or child nodes are added to describe hardwired devices. It's assumed that all ports or no ports will be described for a device. Cc: Greg Kroah-Hartman Cc: Matthias Kaehlcke Cc: Cc: Cc: Pin-yen Lin Cc: maciek swiech Signed-off-by: Stephen Boyd --- drivers/usb/core/port.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c index c628c1abc907..622b8ada157c 100644 --- a/drivers/usb/core/port.c +++ b/drivers/usb/core/port.c @@ -9,6 +9,8 @@ #include #include +#include +#include #include #include @@ -696,7 +698,10 @@ int usb_hub_create_port_device(struct usb_hub *hub, int port1) { struct usb_port *port_dev; struct usb_device *hdev = hub->hdev; + struct device_node *np, *child, *ep, *remote_np, *port_np; int retval; + enum usb_port_connect_type connect_type = USB_PORT_CONNECT_TYPE_UNKNOWN; + u32 reg; port_dev = kzalloc(sizeof(*port_dev), GFP_KERNEL); if (!port_dev) @@ -708,6 +713,38 @@ int usb_hub_create_port_device(struct usb_hub *hub, int port1) return -ENOMEM; } + np = hdev->dev.of_node; + /* Only set connect_type if binding has ports/hardwired devices. */ + if (of_get_child_count(np)) + connect_type = USB_PORT_NOT_USED; + + /* Hotplug ports are connected and available in the OF graph. */ + if (of_graph_is_present(np)) { + port_np = of_graph_get_port_by_id(np, port1); + if (port_np) { + ep = of_graph_get_endpoint_by_regs(np, port1, -1); + if (ep) { + remote_np = of_graph_get_remote_port_parent(ep); + of_node_put(ep); + if (of_device_is_available(remote_np)) + connect_type = USB_PORT_CONNECT_TYPE_HOT_PLUG; + of_node_put(remote_np); + } + } + of_node_put(port_np); + } + + /* + * Hard-wired ports are child nodes with a reg property corresponding + * to the port number. + */ + for_each_available_child_of_node(np, child) { + if (!of_property_read_u32(child, "reg", ®) && reg == port1) + connect_type = USB_PORT_CONNECT_TYPE_HARD_WIRED; + } + + port_dev->connect_type = connect_type; + hub->ports[port1 - 1] = port_dev; port_dev->portnum = port1; set_bit(port1, hub->power_bits); From patchwork Sat Feb 10 07:09:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 771769 Received: from mail-ot1-f50.google.com (mail-ot1-f50.google.com [209.85.210.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D478F38F94 for ; Sat, 10 Feb 2024 07:09:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707548995; cv=none; b=du/0Utu9nWfdHDXEnHnin69j/nbHkv7jBwFadNvdXlh0gzApgiS1RbjXQc3xagPp7siDLhwemSXTdp/P8D4nCOmiWPKczPXddbvUF9gpcZ2PcEp1g1i1fTNU4aP1WD33tMAtgjq7YtJ+akLtY5ra8o8LxEkHtPd+fk1onbjqzKA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707548995; c=relaxed/simple; bh=Mzv0e8b5maH+R5VJl6DotCRRWAOOTWYpXPhTaIdR8Cs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bPa+xCSmQxmRwYtOrjVeNK2kgiFX3ytv5PL0c6LDJ7ZBjqgE6KzxA6TYMww0Rc1j0DsQwOrBWkrizRGY3R9sQdjnVjx7A/CmmeTUEECTmNwVpZ6ZLChO+k7xMhCy6ib+WyPZWy1LEc/4q7Kf3DvgFNTxlaykQMzzKKzvOUdeBzo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=jz/ArCb7; arc=none smtp.client-ip=209.85.210.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="jz/ArCb7" Received: by mail-ot1-f50.google.com with SMTP id 46e09a7af769-6e2d49ec431so338099a34.2 for ; Fri, 09 Feb 2024 23:09:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1707548992; x=1708153792; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3zER2Ilw0QhxMBzy8PRis9D7e+HIgnB5hYCQzM4YYso=; b=jz/ArCb7aEf0XnTaxG1zjmhkLoFwyxZZaMLIe+xtmyAQQnbAY24szJImOrWBYYXqYQ s2fWTnNfG1703YCto5g2pF4m5/7itmj/NfS1smC/ix2iJ008hcD/8TM2hqOmKGEIhwLU e9tJQTKxexhottbvJNZsp8nD7CmBkB87TuaME= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707548992; x=1708153792; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3zER2Ilw0QhxMBzy8PRis9D7e+HIgnB5hYCQzM4YYso=; b=F7UXzWl7cgmdIyUzJsbaEvEJI1GY57qB4mrr+BYf4alQvnEIn3RRUNq7qqDKfh8iu2 JjT2tTBRMJCE54bpEtnLlzhAl3kBCJtYsCdBKKlv0iCsOq0x99dL8SYlRUECrNYeYx7P YkudtZKEuP0PMo+pjOUvHDXbtoq5Z4NU8suAkKPhZn9tQZz9oDw2xJ8H8z37uUKydUF3 Up5J2w5LYSZW6VScCE4t2UyXcqzfIRoN4zuGgi05o0COLE8cIhKJmoQVs5ry5jnBhAF8 2qJ+YGdFnzSdNuCWrQ7p9CPNVY6/+hBAwJFN2okPuWlJD/SY8pyl7dp5S8zucZjV44KM r0yw== X-Forwarded-Encrypted: i=1; AJvYcCUI8S02tz9mHLtr4+a3uLJ/0u7So1j9Aye0zYggEj7qbbkKD31OkTHd+pDyWylkHkci8ERJF98bl6BDGdV0MFMoEpupX2vgEhU0 X-Gm-Message-State: AOJu0Yx/LQfiwy2HMHxuHvL23qZn6Wfe8jqWKTbt+L9dmovZ91l+iJSm d34MefmNbrQqP8CRSOV2wYvl6onGgZMcxQIPNsvpkcBiIf53z/jINlHPkr4B4w== X-Google-Smtp-Source: AGHT+IGycCUB3DMpwmXjgXOSlrrSzr1olN6zo2Ub4XCvqi0LH8LyLdUzUKkoFY+1tflxHElqI+m7OA== X-Received: by 2002:a9d:76d6:0:b0:6dd:dd86:ad81 with SMTP id p22-20020a9d76d6000000b006dddd86ad81mr1490798otl.14.1707548992033; Fri, 09 Feb 2024 23:09:52 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWItJfkduQ4ZlMb/4WI7wMAHcsdDlwLJlkD/syq6yJf1sHeXjYYBIe/frbmiy2XGR50jAWFjh9GanqxX17f+9vt7lUWBccaf/pksRS1ZUnaOkGP4dsQwnsx4zPGeqe43Z6C2X4iWLb/Q42Ko20wMp5+d7KTL4cQ0T9VPc0Z0x02Q6Dx+CIG4ziunVGuwntKCgGgDiMcyfUKwU01vEtnRrfZLHGsZYtXzK1umwuiFrXDznvJZnpN1VFqnk5qw9F5CIHJXQ1cNUpESF9mPy5SkuKua+aAdxO81ycYVQ5ClhPOQzHr0mfcZyUwh1ey7EDduqAuq8v/zJkwd3HDl1vSknkzlzPO7ws3fFF/Y2v5CZTUXwtR5EqYwwhLJWXoBzwaCdlC/28MFNSXvMPPPRS7GI0YN9O/JgHHx4MIJV0YthaE583CCVMKPD+5cQolzSPifOhy/9eGQxmb6hzwiZvi6CIRfuQj0SobOxZPh36DEJ68I7dl368YlcYb8kCiQAG7fmsAbs7ru8zRdnRsnNg1IU3FltumjwDbfwJBAj2zz0JksLQHKZL5Co94BVGmDzEL63lWOxFLaBnGEPWOW3aYiRUfa8JGVlNmH2cAikNC+tptaFMse3Aqg5sDg8eq1nQur7Ss0h+xuFfTmw3DIvxVR35+3g983eWVTucCBMlQeVx9fuGCIEgJ4+4zhcPsG3j/oVi1hhfegECRwMJ0NePewQjjHsJnyBsiGvmWFdp4RQfFg/wj6T7sZdPV0KdSPX93F2ZbOok58pOGEzxthPwChtL+GP4mm0ENWmjuf8+xS6KNk/rlaETSsg3C5saKLtn8j9epQEnkJQ== Received: from localhost (175.199.125.34.bc.googleusercontent.com. [34.125.199.175]) by smtp.gmail.com with UTF8SMTPSA id y30-20020a63b51e000000b005dc5289c4edsm2717207pge.64.2024.02.09.23.09.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 09 Feb 2024 23:09:51 -0800 (PST) From: Stephen Boyd To: chrome-platform@lists.linux.dev Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-msm@vger.kernel.org, Douglas Anderson , Pin-yen Lin , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , Vinod Koul , "Rafael J. Wysocki" , Mika Westerberg , Alexandre Belloni , Ivan Orlov , Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-usb@vger.kernel.org, linux-acpi@vger.kernel.org Subject: [PATCH 07/22] device property: Add remote endpoint to devcon matcher Date: Fri, 9 Feb 2024 23:09:18 -0800 Message-ID: <20240210070934.2549994-8-swboyd@chromium.org> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog In-Reply-To: <20240210070934.2549994-1-swboyd@chromium.org> References: <20240210070934.2549994-1-swboyd@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When a single DT node has a graph connected to more than one usb-c-connector node we can't differentiate which typec switch registered for the device is associated with the USB connector because the devcon matcher code assumes a 1:1 relationship between remote node and typec switch. Furthermore, we don't have a #typec-switch-cells property so there can only be one node per typec switch. Support multiple USB typec switches exposed by one node by passing the remote endpoint node in addition to the remote node to the devcon matcher function (devcon_match_fn_t). With this change, typec switch drivers can register switches with the device node pointer for a graph endpoint so that they can support more than one typec switch if necessary. Either way, a DT property like 'mode-switch' is always in the graph's parent node and not in the endpoint node. Cc: Andy Shevchenko Cc: Daniel Scally Cc: Heikki Krogerus Cc: Sakari Ailus Cc: Greg Kroah-Hartman Cc: Vinod Koul Cc: "Rafael J. Wysocki" Cc: Mika Westerberg Cc: Alexandre Belloni Cc: Ivan Orlov Cc: Rob Herring Cc: Krzysztof Kozlowski Cc: Conor Dooley Cc: Cc: Cc: Cc: Pin-yen Lin Signed-off-by: Stephen Boyd --- drivers/base/property.c | 7 +++++-- drivers/usb/roles/class.c | 4 ++-- drivers/usb/typec/mux.c | 8 ++++++++ drivers/usb/typec/retimer.c | 7 ++++++- include/linux/property.h | 5 +++-- 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/drivers/base/property.c b/drivers/base/property.c index 8c40abed7852..cae81ed4e298 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -1289,6 +1289,7 @@ static unsigned int fwnode_graph_devcon_matches(const struct fwnode_handle *fwno { struct fwnode_handle *node; struct fwnode_handle *ep; + struct fwnode_handle *remote_ep; unsigned int count = 0; void *ret; @@ -1304,7 +1305,9 @@ static unsigned int fwnode_graph_devcon_matches(const struct fwnode_handle *fwno continue; } - ret = match(node, con_id, data); + remote_ep = fwnode_graph_get_remote_endpoint(ep); + ret = match(node, remote_ep, con_id, data); + fwnode_handle_put(remote_ep); fwnode_handle_put(node); if (ret) { if (matches) @@ -1334,7 +1337,7 @@ static unsigned int fwnode_devcon_matches(const struct fwnode_handle *fwnode, if (IS_ERR(node)) break; - ret = match(node, NULL, data); + ret = match(node, NULL, NULL, data); fwnode_handle_put(node); if (ret) { if (matches) diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c index ae41578bd014..9a0ef5fa0a19 100644 --- a/drivers/usb/roles/class.c +++ b/drivers/usb/roles/class.c @@ -89,8 +89,8 @@ enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw) } EXPORT_SYMBOL_GPL(usb_role_switch_get_role); -static void *usb_role_switch_match(const struct fwnode_handle *fwnode, const char *id, - void *data) +static void *usb_role_switch_match(const struct fwnode_handle *fwnode, const struct fwnode_handle *endpoint, + const char *id, void *data) { struct device *dev; diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c index 80dd91938d96..3eabd0d62f47 100644 --- a/drivers/usb/typec/mux.c +++ b/drivers/usb/typec/mux.c @@ -33,6 +33,7 @@ static int switch_fwnode_match(struct device *dev, const void *fwnode) } static void *typec_switch_match(const struct fwnode_handle *fwnode, + const struct fwnode_handle *endpoint, const char *id, void *data) { struct device *dev; @@ -55,6 +56,9 @@ static void *typec_switch_match(const struct fwnode_handle *fwnode, */ dev = class_find_device(&typec_mux_class, NULL, fwnode, switch_fwnode_match); + if (!dev) + dev = class_find_device(&typec_mux_class, NULL, endpoint, + switch_fwnode_match); return dev ? to_typec_switch_dev(dev) : ERR_PTR(-EPROBE_DEFER); } @@ -263,6 +267,7 @@ static int mux_fwnode_match(struct device *dev, const void *fwnode) } static void *typec_mux_match(const struct fwnode_handle *fwnode, + const struct fwnode_handle *endpoint, const char *id, void *data) { struct device *dev; @@ -280,6 +285,9 @@ static void *typec_mux_match(const struct fwnode_handle *fwnode, dev = class_find_device(&typec_mux_class, NULL, fwnode, mux_fwnode_match); + if (!dev) + dev = class_find_device(&typec_mux_class, NULL, endpoint, + mux_fwnode_match); return dev ? to_typec_mux_dev(dev) : ERR_PTR(-EPROBE_DEFER); } diff --git a/drivers/usb/typec/retimer.c b/drivers/usb/typec/retimer.c index 4a7d1b5c4d86..eb74abee6619 100644 --- a/drivers/usb/typec/retimer.c +++ b/drivers/usb/typec/retimer.c @@ -22,7 +22,9 @@ static int retimer_fwnode_match(struct device *dev, const void *fwnode) return is_typec_retimer(dev) && device_match_fwnode(dev, fwnode); } -static void *typec_retimer_match(const struct fwnode_handle *fwnode, const char *id, void *data) +static void *typec_retimer_match(const struct fwnode_handle *fwnode, + const struct fwnode_handle *endpoint, + const char *id, void *data) { struct device *dev; @@ -31,6 +33,9 @@ static void *typec_retimer_match(const struct fwnode_handle *fwnode, const char dev = class_find_device(&retimer_class, NULL, fwnode, retimer_fwnode_match); + if (!dev) + dev = class_find_device(&retimer_class, NULL, endpoint, + retimer_fwnode_match); return dev ? to_typec_retimer(dev) : ERR_PTR(-EPROBE_DEFER); } diff --git a/include/linux/property.h b/include/linux/property.h index 9f2585d705a8..0f20df1f0a49 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -455,8 +455,9 @@ unsigned int fwnode_graph_get_endpoint_count(const struct fwnode_handle *fwnode, int fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode, struct fwnode_endpoint *endpoint); -typedef void *(*devcon_match_fn_t)(const struct fwnode_handle *fwnode, const char *id, - void *data); +typedef void *(*devcon_match_fn_t)(const struct fwnode_handle *fwnode, + const struct fwnode_handle *endpoint, + const char *id, void *data); void *fwnode_connection_find_match(const struct fwnode_handle *fwnode, const char *con_id, void *data,