From patchwork Fri Aug 9 15:34:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Ceresoli X-Patchwork-Id: 1971009 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=gm1 header.b=kBnVrdyS; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.199.223; helo=ny.mirrors.kernel.org; envelope-from=linux-i2c+bounces-5266-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [147.75.199.223]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WgSgG454dz1ybT for ; Sat, 10 Aug 2024 01:36:10 +1000 (AEST) 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 891B31C210BB for ; Fri, 9 Aug 2024 15:36:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C16481990AD; Fri, 9 Aug 2024 15:35:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="kBnVrdyS" X-Original-To: linux-i2c@vger.kernel.org Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) (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 F1B851946B4; Fri, 9 Aug 2024 15:35:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723217750; cv=none; b=n5ZaZ+T68d58XjYsILr0QOfxxHfrT6UfymKPbpIyWWrjWo6c7rdXLmpyy58qCAkDTNMip6YvKmQdWN41WtHQRWFGR1eQwAru8qQQ64g1ikJODaQf0kfDGtRRKMzQyNtZLJp59alDCIUyjiWWD7kFvaUTUckraGc5yBbJjGfQRIY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723217750; c=relaxed/simple; bh=o6dgNOKYU74041asjbprr2JrK5YuUCBQl05htOSjzYs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=glmH8J6oTODZRUX0S1lIvynvUgZTauQh6SmA0pkueVgvBRkkc6xb+ZcEeHV7RswkKB1nTZY8HrGxIZ97i2TvF+kCulvDTRZ67MAhfEvQ9B6Gllc92P/hzB3oGTrGjpZvQPgj4qkCycbQvh5v4K9K/tSlnH7vGT21aCalmOCtjbI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=kBnVrdyS; arc=none smtp.client-ip=217.70.183.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id 22D53C0007; Fri, 9 Aug 2024 15:35:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1723217740; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cIB6901iakrh1Q8oAZbEEGOafb0xS1CIIIl4i1JxX/8=; b=kBnVrdySCVMo3XCQPoMWUfssZitZ9G7bBA8KyOYntxHJKOHww7U27H69+MmTbjkVFkYUrJ aD1XjLt/mTV6Fmzk3xZ59ba/KB4ilZtBucK0izgosH3dW/ASTl6qG0RZW7zQPIqe4nnjeT SRA8zUX+PkcbK+XyhDvBGBJpulMffk/iFzXD8PD6GWNab9ebeRDVak39Lt2pJuj7/UAAVt VY34a//NfFn80r62IFb3KYjcFiPWPUIDaG+m3cCWp/4VfzsbgkJ1Z7EroCMhRL/xiJ0A2O owO4N8le7R0tvGFdl9Jhot9R3njVaz6DLES5JVzsd9+59wxsehmz72wzuvWyyA== From: Luca Ceresoli Date: Fri, 09 Aug 2024 17:34:49 +0200 Subject: [PATCH v3 1/7] dt-bindings: connector: add GE SUNH hotplug addon connector Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240809-hotplug-drm-bridge-v3-1-b4c178380bc9@bootlin.com> References: <20240809-hotplug-drm-bridge-v3-0-b4c178380bc9@bootlin.com> In-Reply-To: <20240809-hotplug-drm-bridge-v3-0-b4c178380bc9@bootlin.com> To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Derek Kiernan , Dragan Cvetic , Arnd Bergmann , Greg Kroah-Hartman , Saravana Kannan , Wolfram Sang , "Rafael J. Wysocki" Cc: Paul Kocialkowski , =?utf-8?q?Herv=C3=A9_Codina?= , Thomas Petazzoni , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-i2c@vger.kernel.org, Paul Kocialkowski , Luca Ceresoli X-Mailer: b4 0.14.0 X-GND-Sasl: luca.ceresoli@bootlin.com Add bindings for the GE SUNH add-on connector. This is a physical, hot-pluggable connector that allows to attach and detach at runtime an add-on adding peripherals on non-discoverable busses. Signed-off-by: Luca Ceresoli --- Changed in v3: - change the layout to only add subnodes, not properties - add the 'nobus-devices' node description to hold devices not on any bus - add 'i2c-*' nodes for the I2C busses, using a i2c-parent phandle - and the 'dsi' node for the DSI bus - move the entire port@1 node to the overlay (not only the remote-endpoint property) - remove the overlay examples (Overlays in examples are not supported) - add more clarifying descriptions and comments for examples - some rewording This patch was added in v2. --- .../connector/ge,sunh-addon-connector.yaml | 185 +++++++++++++++++++++ MAINTAINERS | 5 + 2 files changed, 190 insertions(+) diff --git a/Documentation/devicetree/bindings/connector/ge,sunh-addon-connector.yaml b/Documentation/devicetree/bindings/connector/ge,sunh-addon-connector.yaml new file mode 100644 index 000000000000..2a0b4e0fd089 --- /dev/null +++ b/Documentation/devicetree/bindings/connector/ge,sunh-addon-connector.yaml @@ -0,0 +1,185 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/connector/ge,sunh-addon-connector.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: GE SUNH hotplug add-on connector + +maintainers: + - Luca Ceresoli + +description: + Represent the physical connector present on GE SUNH devices that allows + to attach and detach at runtime an add-on adding peripherals on + non-discoverable busses. Peripherals on the add-on include I2C sensors + and a video bridge controlled via I2C. + + The connector has status GPIOs to notify the connection status to the CPU + and a reset GPIO to allow the CPU to reset all the peripherals on the + add-on. It also has I2C busses and a 4-lane MIPI DSI bus. + + Different add-on models can be connected, each having different + peripherals. For this reason each add-on has a model ID stored in a + non-volatile memory, which is accessed in the same way on all add-ons. + + Add-on removal can happen at any moment under user control and without + prior notice to the CPU, making all of its components not usable + anymore. Later on, the same or a different add-on model can be connected. + +properties: + compatible: + const: ge,sunh-addon-connector + + reset-gpios: + description: An output GPIO to reset the peripherals on the add-on. + maxItems: 1 + + plugged-gpios: + description: An input GPIO that is asserted if and only if an add-on is + physically connected. + maxItems: 1 + + powergood-gpios: + description: An input GPIO that is asserted if and only if power rails + on the add-on are stable. + maxItems: 1 + + nobus-devices: + description: + A container for devices not accessible via any data bus. Common use + cases include fixed and GPIO regulators, simple video panels and LED + or GPIO backlight devices. When not hot-pluggable, nodes such devices + are children of the root node. + + This node should not be present in the connector description in the + base device tree. It should be added by overlays along with a subnode + per device. + + type: object + additionalProperties: false + + dsi: + type: object + additionalProperties: false + + properties: + ports: + $ref: /schemas/graph.yaml#/properties/ports + + description: + OF graph bindings modeling the MIPI DSI bus across the connector. The + connector splits the video pipeline in a fixed part and a removable + part. + + The fixed part of the video pipeline includes all components up to + the display controller and 0 or more bridges. The removable part + includes any bridges and any other components up to the panel. + + properties: + port@0: + $ref: /schemas/graph.yaml#/properties/port + description: + The last point of the non-removable part of the MIPI DSI bus + line. The remote-endpoint sub-node must point to the last + non-removable video component of the video pipeline. + + port@1: + $ref: /schemas/graph.yaml#/properties/port + description: + The first point of the removable part of the MIPI DSI bus + line. The remote-endpoint sub-node must point to the first + video pipeline component on the add-on. As it describes the + hot-pluggable hardware, the endpoint node cannot be filled + until an add-on is detected, so this node needs to be added + by a device tree overlay at runtime. + + required: + - port@0 + # port@1 is added by the overlay for any add-on using the DSI lines + + required: + - ports + +patternProperties: + '^i2c-(dbat|gp|btp)$': + description: + An I2C bus that goes through the connector. The adapter (and possibly + some clients) are on the fixed side. Add-ons that have any clients on + this bus have to be added by the add-on overlay, inside this node. + + $ref: /schemas/i2c/i2c-controller.yaml# + unevaluatedProperties: false + type: object + + properties: + i2c-parent: + $ref: /schemas/types.yaml#/definitions/phandle + description: + Phandle pointing to the I2C bus controller on the fixed side that + drives this bus + +required: + - compatible + - i2c-dbat + - i2c-gp + - i2c-btp + - dsi + +unevaluatedProperties: false + +examples: + # This is the description of the connector as it should appear in the + # main DTS describing the "main" board up to the connector. This is + # supposed to be used together with the overlays in the two following + # examples. The addon_connector and hotplug_conn_dsi_out labels are + # referenced by the overlays in those examples. + - | + / { + #include + + addon_connector: addon-connector { + compatible = "ge,sunh-addon-connector"; + reset-gpios = <&gpio1 1 GPIO_ACTIVE_LOW>; + plugged-gpios = <&gpio1 2 GPIO_ACTIVE_LOW>; + powergood-gpios = <&gpio1 3 GPIO_ACTIVE_HIGH>; + + i2c-dbat { + i2c-parent = <&i2c5_ch2>; + #address-cells = <1>; + #size-cells = <0>; + // device subnodes to be added by overlays + }; + + i2c-gp { + i2c-parent = <&i2c4>; + #address-cells = <1>; + #size-cells = <0>; + // device subnodes to be added by overlays + }; + + i2c-btp { + i2c-parent = <&i2c3>; + #address-cells = <1>; + #size-cells = <0>; + // device subnodes to be added by overlays + }; + + dsi { + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + + endpoint { + remote-endpoint = <&previous_bridge_out>; + }; + }; + + // port@1 to be added by overlay + }; + }; + }; + }; diff --git a/MAINTAINERS b/MAINTAINERS index 42decde38320..9e902db825d7 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -10254,6 +10254,11 @@ S: Maintained F: Documentation/devicetree/bindings/iio/pressure/honeywell,mprls0025pa.yaml F: drivers/iio/pressure/mprls0025pa* +HOTPLUG CONNECTOR FOR GE SUNH ADDONS +M: Luca Ceresoli +S: Maintained +F: Documentation/devicetree/bindings/connector/ge,sunh-addon-connector.yaml + HP BIOSCFG DRIVER M: Jorge Lopez L: platform-driver-x86@vger.kernel.org From patchwork Fri Aug 9 15:34:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Ceresoli X-Patchwork-Id: 1971010 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=gm1 header.b=S2Inyd01; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:4601:e00::3; helo=am.mirrors.kernel.org; envelope-from=linux-i2c+bounces-5267-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from am.mirrors.kernel.org (am.mirrors.kernel.org [IPv6:2604:1380:4601:e00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WgSgj4zH8z1ybT for ; Sat, 10 Aug 2024 01:36:33 +1000 (AEST) 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 3084C1F22993 for ; Fri, 9 Aug 2024 15:36:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 58BD01991B5; Fri, 9 Aug 2024 15:35:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="S2Inyd01" X-Original-To: linux-i2c@vger.kernel.org Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) (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 BEF89198E84; Fri, 9 Aug 2024 15:35:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723217752; cv=none; b=CdtP+v8FI6WwnZefuy5pBIPxXZ2lQ77nQsZNatM+V0Fn4PnQ1c3cL/nEjAOtiBq7LIixyo36cF5+JSt+eRQ79YKKpZeM9/jlPW+ibSzKFK2r2+mWrJPepDpEMs1jvejkZCQ+1QsBpyKkgTG2HGz3KuqqtH0zyks6jQn5DpZc2kQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723217752; c=relaxed/simple; bh=MLOaxPEP3Zqbbf/WvgKa4cI7Ix3Cs4Kcr+9he5X7UMg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ov88V5c3lvWBGcVMU7J07Qj+vPQvekkQ6qUSOyZ767REXkZh+U3rb1KNT/5ONU6MfV7Jp2LR0UT4EJj0MdC6xjLQO0nSZuyHpuvJLWTfCm65sD7+2ziH/HFH+ipDWV+lwtWzHGeMAMcZpr1Ly1mZHOSEiRq4vCfzedCOpV6UpHA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=S2Inyd01; arc=none smtp.client-ip=217.70.183.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id 74A4EC0002; Fri, 9 Aug 2024 15:35:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1723217742; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=g23z6Hbo0SgdTOHbizvWXJiLCoM2XaylyRrnPRhOxGk=; b=S2Inyd01LRcPT1SHqYsJclO17CgYAuRLfxLPQrCp5GuYFF04jFjYmEldcLmyByturxKLhT Yq43FbKjiRdqFKKSc8fzoyQyoTByUB3GKq51hX2ENHnKThHH7TuCHkqDyg71r/My5EiKIy N1iHpFgsUpyfnI/rvBwEs4hTpiU8M7Z2owWRjsa8kijxDr50c/8/iE4e5qowZfwZ5h1UJ5 ClJL3veSaT2b1Hm0zO0vReYlOMwSrhH6F7DoIUv6JO2c0k3O2r4jfXQ/rPIGc3cQKAO7h+ kkvuH39HjiYP6quUz7LRLnAJmfFi+qTnASW8kK4cbvj2dsgpO/KE6zHT6XFgmA== From: Luca Ceresoli Date: Fri, 09 Aug 2024 17:34:50 +0200 Subject: [PATCH v3 2/7] drm/bridge: add bridge notifier to be notified of bridge addition and removal Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240809-hotplug-drm-bridge-v3-2-b4c178380bc9@bootlin.com> References: <20240809-hotplug-drm-bridge-v3-0-b4c178380bc9@bootlin.com> In-Reply-To: <20240809-hotplug-drm-bridge-v3-0-b4c178380bc9@bootlin.com> To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Derek Kiernan , Dragan Cvetic , Arnd Bergmann , Greg Kroah-Hartman , Saravana Kannan , Wolfram Sang , "Rafael J. Wysocki" Cc: Paul Kocialkowski , =?utf-8?q?Herv=C3=A9_Codina?= , Thomas Petazzoni , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-i2c@vger.kernel.org, Paul Kocialkowski , Luca Ceresoli X-Mailer: b4 0.14.0 X-GND-Sasl: luca.ceresoli@bootlin.com From: Paul Kocialkowski In preparation for allowing bridges to be added to and removed from a DRM card without destroying the whole card, add a DRM bridge notifier. Notified events are addition and removal to/from the global bridge list. Co-developed-by: Luca Ceresoli Signed-off-by: Luca Ceresoli Signed-off-by: Paul Kocialkowski --- Changes in v3: none Changes in v2: none --- drivers/gpu/drm/drm_bridge.c | 35 +++++++++++++++++++++++++++++++++++ include/drm/drm_bridge.h | 19 +++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/drivers/gpu/drm/drm_bridge.c b/drivers/gpu/drm/drm_bridge.c index d44f055dbe3e..0728a4e0cbfd 100644 --- a/drivers/gpu/drm/drm_bridge.c +++ b/drivers/gpu/drm/drm_bridge.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -197,6 +198,36 @@ static DEFINE_MUTEX(bridge_lock); static LIST_HEAD(bridge_list); +static BLOCKING_NOTIFIER_HEAD(bridge_notifier); + +/** + * drm_bridge_notifier_register - add a DRM bridge notifier + * @nb: the notifier block to be registered + * + * The notifier block will be notified of events defined in + * &drm_bridge_notifier_event + */ +int drm_bridge_notifier_register(struct notifier_block *nb) +{ + return blocking_notifier_chain_register(&bridge_notifier, nb); +} +EXPORT_SYMBOL(drm_bridge_notifier_register); + +/** + * drm_bridge_notifier_unregister - remove a DRM bridge notifier + * @nb: the notifier block to be unregistered + */ +int drm_bridge_notifier_unregister(struct notifier_block *nb) +{ + return blocking_notifier_chain_unregister(&bridge_notifier, nb); +} +EXPORT_SYMBOL(drm_bridge_notifier_unregister); + +static void drm_bridge_notifier_notify(unsigned long event, + struct drm_bridge *bridge) +{ + blocking_notifier_call_chain(&bridge_notifier, event, bridge); +} /** * drm_bridge_add - add the given bridge to the global bridge list @@ -210,6 +241,8 @@ void drm_bridge_add(struct drm_bridge *bridge) mutex_lock(&bridge_lock); list_add_tail(&bridge->list, &bridge_list); mutex_unlock(&bridge_lock); + + drm_bridge_notifier_notify(DRM_BRIDGE_NOTIFY_ADD, bridge); } EXPORT_SYMBOL(drm_bridge_add); @@ -243,6 +276,8 @@ EXPORT_SYMBOL(devm_drm_bridge_add); */ void drm_bridge_remove(struct drm_bridge *bridge) { + drm_bridge_notifier_notify(DRM_BRIDGE_NOTIFY_REMOVE, bridge); + mutex_lock(&bridge_lock); list_del_init(&bridge->list); mutex_unlock(&bridge_lock); diff --git a/include/drm/drm_bridge.h b/include/drm/drm_bridge.h index 75019d16be64..3748c1011307 100644 --- a/include/drm/drm_bridge.h +++ b/include/drm/drm_bridge.h @@ -43,6 +43,22 @@ struct drm_panel; struct edid; struct i2c_adapter; +/** + * enum drm_bridge_notifier_event - DRM bridge events + */ +enum drm_bridge_notifier_event { + /** + * @DRM_BRIDGE_NOTIFY_ADD: A bridge has just been added to the + * global bridge list. See drm_bridge_add(). + */ + DRM_BRIDGE_NOTIFY_ADD, + /** + * @DRM_BRIDGE_NOTIFY_REMOVE: A bridge is about to be removed from + * the global bridge list. See drm_bridge_remove(). + */ + DRM_BRIDGE_NOTIFY_REMOVE, +}; + /** * enum drm_bridge_attach_flags - Flags for &drm_bridge_funcs.attach */ @@ -862,6 +878,9 @@ drm_priv_to_bridge(struct drm_private_obj *priv) return container_of(priv, struct drm_bridge, base); } +int drm_bridge_notifier_register(struct notifier_block *nb); +int drm_bridge_notifier_unregister(struct notifier_block *nb); + void drm_bridge_add(struct drm_bridge *bridge); int devm_drm_bridge_add(struct device *dev, struct drm_bridge *bridge); void drm_bridge_remove(struct drm_bridge *bridge); From patchwork Fri Aug 9 15:34:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Ceresoli X-Patchwork-Id: 1971007 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=gm1 header.b=GVeTBtmv; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45d1:ec00::1; helo=ny.mirrors.kernel.org; envelope-from=linux-i2c+bounces-5265-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [IPv6:2604:1380:45d1:ec00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WgSg41N2Jz1ybT for ; Sat, 10 Aug 2024 01:36:00 +1000 (AEST) 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 3A3CE1C20F4B for ; Fri, 9 Aug 2024 15:35:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7A19D198E70; Fri, 9 Aug 2024 15:35:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="GVeTBtmv" X-Original-To: linux-i2c@vger.kernel.org Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) (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 B2F4E17552; Fri, 9 Aug 2024 15:35:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723217749; cv=none; b=nBDgvVC9tQuLvS1J92sqzxcUZdbECoD1j4q83DWovjld8ooTBRqVYom7nW5nBvnxnjJorA+Tz6qrW/CB43GNP6+oa0ZnS1emj33BTcfPOrEVyEMCqpotT3y1fM1wHsY5orVUWtxL9bkKEfvkg3pzeAb8t817yRcEeS/zkL0irxA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723217749; c=relaxed/simple; bh=tbi2GjX0sVPxeekko6WyWU769v76iroU9gpWVQtjZyo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jsZp88HGKe3YRl6V3M/S5PN/8pCkRAersKQThJwTgq+IvU9Dgh+zkvZmjbo9WGIv4HVHz9VqHQ58pWwwt0HbfMDbcJWi3Wt9BlO2lNJLfQETTlEqnd9WcpFC8x64Y7ye+xqZuYG0K6eKFR+Zy2gDSfLXODkR+8zBbtPuZP7upb0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=GVeTBtmv; arc=none smtp.client-ip=217.70.183.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id C76CFC0008; Fri, 9 Aug 2024 15:35:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1723217745; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zXfD1uIHQ08PVRbHD3ejH9ya7NUdvN1EDBI59inSFEs=; b=GVeTBtmva2pQ6cW8+vsqX1j6REQCjU2/HhSlW19/YcRgk8oKUHbUp+6jOwEcK0jPcatxeS zXQ1P//3trfX/mWnKp/Sqg1DOHUUDSX7Z5sOtLukQRgFTOTuw+GFenCzaNSUuoE+6HyZ8C Y+2hMsLCe6C3b7Qde26rEMsfu4dN13Xn2csE61uKDShoX5fsy9s+UZq1spd9GtIEz+oSwj fO+6t5PKd4brBVwZymLQRL7zuIPoScfTkQJfYIkKUjEsBT+pEgzZ7fLbJhRi4ZbkhlZvkN k3RGLAGo7+tor8VKbIuKs5G+iJxamBOLKh71Yfp2tf62P0JVykbViNFO3/d8Mg== From: Luca Ceresoli Date: Fri, 09 Aug 2024 17:34:51 +0200 Subject: [PATCH v3 3/7] drm/encoder: add drm_encoder_cleanup_from() Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240809-hotplug-drm-bridge-v3-3-b4c178380bc9@bootlin.com> References: <20240809-hotplug-drm-bridge-v3-0-b4c178380bc9@bootlin.com> In-Reply-To: <20240809-hotplug-drm-bridge-v3-0-b4c178380bc9@bootlin.com> To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Derek Kiernan , Dragan Cvetic , Arnd Bergmann , Greg Kroah-Hartman , Saravana Kannan , Wolfram Sang , "Rafael J. Wysocki" Cc: Paul Kocialkowski , =?utf-8?q?Herv=C3=A9_Codina?= , Thomas Petazzoni , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-i2c@vger.kernel.org, Paul Kocialkowski , Luca Ceresoli X-Mailer: b4 0.14.0 X-GND-Sasl: luca.ceresoli@bootlin.com Supporting hardware whose final part of the DRM pipeline can be physically removed requires the ability to detach all bridges from a given point to the end of the pipeline. Introduce a variant of drm_encoder_cleanup() for this. Signed-off-by: Luca Ceresoli --- Changes in v3: none Changed in v2: - fix a typo in a comment --- drivers/gpu/drm/drm_encoder.c | 21 +++++++++++++++++++++ include/drm/drm_encoder.h | 1 + 2 files changed, 22 insertions(+) diff --git a/drivers/gpu/drm/drm_encoder.c b/drivers/gpu/drm/drm_encoder.c index 8f2bc6a28482..472dfbefe296 100644 --- a/drivers/gpu/drm/drm_encoder.c +++ b/drivers/gpu/drm/drm_encoder.c @@ -207,6 +207,27 @@ void drm_encoder_cleanup(struct drm_encoder *encoder) } EXPORT_SYMBOL(drm_encoder_cleanup); +/** + * drm_encoder_cleanup_from - remove a given bridge and all the following + * @encoder: encoder whole list of bridges shall be pruned + * @bridge: first bridge to remove + * + * Removes from an encoder all the bridges starting with a given bridge + * and until the end of the chain. + * + * This should not be used in "normal" DRM pipelines. It is only useful for + * devices whose final part of the DRM chain can be physically removed and + * later reconnected (possibly with different hardware). + */ +void drm_encoder_cleanup_from(struct drm_encoder *encoder, struct drm_bridge *bridge) +{ + struct drm_bridge *next; + + list_for_each_entry_safe_from(bridge, next, &encoder->bridge_chain, chain_node) + drm_bridge_detach(bridge); +} +EXPORT_SYMBOL(drm_encoder_cleanup_from); + static void drmm_encoder_alloc_release(struct drm_device *dev, void *ptr) { struct drm_encoder *encoder = ptr; diff --git a/include/drm/drm_encoder.h b/include/drm/drm_encoder.h index 977a9381c8ba..bafcabb24267 100644 --- a/include/drm/drm_encoder.h +++ b/include/drm/drm_encoder.h @@ -320,6 +320,7 @@ static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev, } void drm_encoder_cleanup(struct drm_encoder *encoder); +void drm_encoder_cleanup_from(struct drm_encoder *encoder, struct drm_bridge *bridge); /** * drm_for_each_encoder_mask - iterate over encoders specified by bitmask From patchwork Fri Aug 9 15:34:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Ceresoli X-Patchwork-Id: 1971011 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=gm1 header.b=j4Ok7JzE; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45d1:ec00::1; helo=ny.mirrors.kernel.org; envelope-from=linux-i2c+bounces-5268-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [IPv6:2604:1380:45d1:ec00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WgSgq4dkDz1ybT for ; Sat, 10 Aug 2024 01:36:39 +1000 (AEST) 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id CA3D91C21EC0 for ; Fri, 9 Aug 2024 15:36:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B9E3E1991CF; Fri, 9 Aug 2024 15:35:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="j4Ok7JzE" X-Original-To: linux-i2c@vger.kernel.org Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) (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 F1BA4198A2B; Fri, 9 Aug 2024 15:35:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723217752; cv=none; b=Pt2agxc6bwZq+bnfMcCdfRRShDUniT+/wSjUKpBFK9Dh/rspsfMSuftaYAjeU4+gIvH52ylmPkN10MTRF+kov6PCxpOXCc2Bjqr29QEJqAb0vguDU8KYrCWrxFK1pmy6/F7wxc9Z0oAkeeY87nO6jJJs8stZvTNV0NLp4dMLDtE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723217752; c=relaxed/simple; bh=mG1CCOvQ96sKMwPd1/WdpcK/ewW4H0i+voEdeaEU5Es=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hh+RBmm34lMLVfnsgUjLxt7Y0gQYzIIphJtPyK/wwsi/YPnLzDQJMZUiWwu1m+QoS187wiNpb6/3Lvv58+dYCv/lNw9cmIMf0O4a3OTJm6rg/of+pVTnOqS3JiSW/AiUg/m46giipoJMmNCyzywv2w76tr6SeZg3o/K7GD6DHgk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=j4Ok7JzE; arc=none smtp.client-ip=217.70.183.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id 3529DC0005; Fri, 9 Aug 2024 15:35:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1723217747; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GbxTcxyQlbQzFsnyJhuYmfBvEFD6BW1++uPwWub47Xw=; b=j4Ok7JzE7Bug/sBrTyO1KBhjxABgQO/v5E//lr+DbF/5g0P1EX4OCcEEiZd+0V7HN7GU5u jIFpPv5pLDT32q6eQYBsXtRYUVatxgVXWWK/talOWPsanHIAS4TY73bQ5v9zEL/uq+n/oG U8+XW75L3+1sBz0tlBPzq48SBAl7gPCWeDWqy1L+TO/fQFeXjAATupJ0NJYM3NVOGwxT8V wjlfmd1MYtOWojjEHVhTLxZ6PTCUYQAL1GVR2J96AMC4+KwZlkz7iNeYn8N6IVtlDKrhEX x7oUjqeVGfNlE0OFWzJXf43/MzPqI9Mq23vjalAjL1NUmstrrfMOFHxSsPMxmA== From: Luca Ceresoli Date: Fri, 09 Aug 2024 17:34:52 +0200 Subject: [PATCH v3 4/7] drm/bridge: hotplug-bridge: add driver to support hot-pluggable DSI bridges Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240809-hotplug-drm-bridge-v3-4-b4c178380bc9@bootlin.com> References: <20240809-hotplug-drm-bridge-v3-0-b4c178380bc9@bootlin.com> In-Reply-To: <20240809-hotplug-drm-bridge-v3-0-b4c178380bc9@bootlin.com> To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Derek Kiernan , Dragan Cvetic , Arnd Bergmann , Greg Kroah-Hartman , Saravana Kannan , Wolfram Sang , "Rafael J. Wysocki" Cc: Paul Kocialkowski , =?utf-8?q?Herv=C3=A9_Codina?= , Thomas Petazzoni , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-i2c@vger.kernel.org, Paul Kocialkowski , Luca Ceresoli X-Mailer: b4 0.14.0 X-GND-Sasl: luca.ceresoli@bootlin.com This driver implements the point of a DRM pipeline where a connector allows removal of all the following bridges up to the panel. The DRM subsystem currently allows hotplug of the monitor but not preceding components. However there are embedded devices where the "tail" of the DRM pipeline, including one or more bridges, can be physically removed: .------------------------. | DISPLAY CONTROLLER | | .---------. .------. | | | ENCODER |<--| CRTC | | | '---------' '------' | '------|-----------------' | | HOTPLUG V CONNECTOR .---------. .--. .-. .---------. .-------. | 0 to N | | _| _| | | 1 to N | | | | BRIDGES |--DSI-->||_ |_ |--DSI-->| BRIDGES |--LVDS-->| PANEL | | | | | | | | | | | '---------' '--' '-' '---------' '-------' [--- fixed components --] [----------- removable add-on -----------] This driver supports such a device, where the final segment of a MIPI DSI bus, including one or more bridges, can be physically disconnected and reconnected at runtime, possibly with a different model. The add-on supported by this driver has a MIPI DSI bus traversing the hotplug connector and a DSI to LVDS bridge and an LVDS panel on the add-on. Hovever it is designed to be as far as possible generic and extendable to other busses that have no native hotplug and model ID discovery. This driver does not itself add and remove the bridges or panel on the add-on: this needs to be done by other means, and in this implementation it is done by device tree overlay runtime insertion and removal. The hotplug-bridge gets notified of hot-plugging by the DRM bridge notifier callbacks after they get added or before they get removed. The hotplug-bridge role is to implement the "hot-pluggable connector" in the bridge chain. In this position, what the hotplug-bridge should ideally do is: * communicate with the previous component (bridge or encoder) so that it believes it always has a connected bridge following it and the DRM card is always present * be notified of the addition and removal of the following bridge and attach/detach to/from it * communicate with the following bridge so that it will attach and detach using the normal procedure (as if the entire pipeline were being created or destroyed, not only the tail) * instantiate two DRM connectors (similarly to what the DisplayPort MST code does): - a DSI connector representing the video lines of the hotplug connector; the status is always "disconnected" (no panel is ever attached directly to it) - an LSVD connector representing the classic connection to the panel; this gets added/removed whenever the add-on gets connected/disconnected; the status is always "connected" as the panel is always connected when the add-on is However some aspects make it a bit more complex than that. Most notably: * the next bridge can be probed and removed at any moment and all probing sequences need to be handled * the DSI host/device registration process, which adds to the DRM bridge attach process, makes the initial card registration tricky * the need to register and deregister the following bridges at runtime without tearing down the whole DRM card prevents using some of the functions that are normally recommended * the automatic mechanism to call the appropriate .get_modes operation (typically provided by the panel bridge) cannot work as the panel can disappear and reappear as a different model, so an ad-hoc lookup is needed The code handling these and other tricky aspects is accurately documented by comments in the code. Co-developed-by: Paul Kocialkowski Signed-off-by: Paul Kocialkowski Signed-off-by: Luca Ceresoli --- Changed in v3: - dynamically add/remove the LVDS connector on hot(un)plug - take the firmware node normally via dev->of_node instead of using device_set_node(); this makes code more self-contained and generic - minor rewordings and cleanups Changed in v2: - change to be a platform device instantiated from the connector driver instead of a self-standing OF driver - add missing error handling for devm_drm_bridge_add() - various cleanups and style improvements --- MAINTAINERS | 5 + drivers/gpu/drm/bridge/Kconfig | 15 + drivers/gpu/drm/bridge/Makefile | 1 + drivers/gpu/drm/bridge/hotplug-bridge.c | 665 ++++++++++++++++++++++++++++++++ 4 files changed, 686 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 9e902db825d7..d571aa049ce1 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -7004,6 +7004,11 @@ T: git https://gitlab.freedesktop.org/drm/misc/kernel.git F: Documentation/devicetree/bindings/display/panel/himax,hx8394.yaml F: drivers/gpu/drm/panel/panel-himax-hx8394.c +DRM DRIVER FOR HOTPLUG VIDEO CONNECTOR BRIDGE +M: Luca Ceresoli +S: Maintained +F: drivers/gpu/drm/bridge/hotplug-bridge.c + DRM DRIVER FOR HX8357D PANELS S: Orphan T: git https://gitlab.freedesktop.org/drm/misc/kernel.git diff --git a/drivers/gpu/drm/bridge/Kconfig b/drivers/gpu/drm/bridge/Kconfig index c621be1a99a8..1c0b350d9b2d 100644 --- a/drivers/gpu/drm/bridge/Kconfig +++ b/drivers/gpu/drm/bridge/Kconfig @@ -90,6 +90,21 @@ config DRM_FSL_LDB help Support for i.MX8MP DPI-to-LVDS on-SoC encoder. +config DRM_HOTPLUG_BRIDGE + tristate "Hotplug DRM bridge support" + depends on OF + select DRM_PANEL_BRIDGE + select DRM_MIPI_DSI + select DRM_KMS_HELPER + help + Driver for a DRM bridge representing a physical connector that + splits a DRM pipeline into a fixed part and a physically + removable part. The fixed part includes up to the encoder and + zero or more bridges. The removable part includes any following + bridges up to the connector and panel and can be physically + removed and connected at runtime, possibly with different + components. + config DRM_ITE_IT6505 tristate "ITE IT6505 DisplayPort bridge" depends on OF diff --git a/drivers/gpu/drm/bridge/Makefile b/drivers/gpu/drm/bridge/Makefile index 7df87b582dca..58f59e5a543a 100644 --- a/drivers/gpu/drm/bridge/Makefile +++ b/drivers/gpu/drm/bridge/Makefile @@ -6,6 +6,7 @@ obj-$(CONFIG_DRM_CHRONTEL_CH7033) += chrontel-ch7033.o obj-$(CONFIG_DRM_CROS_EC_ANX7688) += cros-ec-anx7688.o obj-$(CONFIG_DRM_DISPLAY_CONNECTOR) += display-connector.o obj-$(CONFIG_DRM_FSL_LDB) += fsl-ldb.o +obj-$(CONFIG_DRM_HOTPLUG_BRIDGE) += hotplug-bridge.o obj-$(CONFIG_DRM_ITE_IT6505) += ite-it6505.o obj-$(CONFIG_DRM_LONTIUM_LT8912B) += lontium-lt8912b.o obj-$(CONFIG_DRM_LONTIUM_LT9211) += lontium-lt9211.o diff --git a/drivers/gpu/drm/bridge/hotplug-bridge.c b/drivers/gpu/drm/bridge/hotplug-bridge.c new file mode 100644 index 000000000000..b58f39ab315f --- /dev/null +++ b/drivers/gpu/drm/bridge/hotplug-bridge.c @@ -0,0 +1,665 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * A DRM bridge representing the split point between a fixed part of the + * DRM pipeline and a physically removable part. The fixed part includes up + * to the encoder and zero or more bridges. Insertion and removal of the + * "downstream" components happens via device driver probe/removal. + * + * Copyright (C) 2024, GE HealthCare + * + * Authors: + * Luca Ceresoli + * Paul Kocialkowski + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +/* + * Internal hotplug-bridge data. + * + * We have two 'struct drm_connector' here: + * - fixconn represents the DSI video lines on the hotplug connector where + * the removable part attaches. It is thus always instantiated. + * - dynconn represents the LVDS videl lines where the panel is attached. + * It is part of the removable part of the video pipeline and as such is + * added and removed dynamically based on when the downstream devices + * appear and disappear. + */ +struct hotplug_bridge { + struct device *dev; + + /* Local bridge */ + struct drm_bridge bridge; + + /* Always-present connector (where the removal part will connect to) */ + struct drm_connector *fixconn; + + /* Downstream bridge (next in the chain) */ + struct drm_bridge *next_bridge; + struct mutex next_bridge_mutex; + + /* Pointer to the last bridge exposing OP_MODES */ + struct drm_bridge *bridge_modes; + + /* The "tail" connector that gets added/removed at runtime */ + struct drm_connector dynconn; + + /* Local DSI host, for the downstream DSI device to attach to */ + struct mipi_dsi_host dsi_host; + /* Local DSI device, attached to the upstream DSI host */ + struct mipi_dsi_device *dsi_dev; + /* Upstream DSI host (the actual DSI controller) */ + struct mipi_dsi_host *prev_dsi_host; + + struct work_struct hpd_work; + struct notifier_block drm_bridge_nb; +}; + +static struct hotplug_bridge *hotplug_bridge_from_drm_bridge(struct drm_bridge *bridge) +{ + return container_of(bridge, struct hotplug_bridge, bridge); +} + +/* -------------------------------------------------------------------------- + * dynconn implementation + */ +static struct hotplug_bridge *hotplug_bridge_from_dynconn(struct drm_connector *conn) +{ + return container_of(conn, struct hotplug_bridge, dynconn); +} + +static int hotplug_bridge_dynconn_get_modes(struct drm_connector *connector) +{ + struct hotplug_bridge *hpb = hotplug_bridge_from_dynconn(connector); + + if (hpb->bridge_modes) + return hpb->bridge_modes->funcs->get_modes(hpb->bridge_modes, connector); + + return 0; +} + +static const struct drm_connector_helper_funcs hotplug_bridge_dynconn_connector_helper_funcs = { + .get_modes = hotplug_bridge_dynconn_get_modes, +}; + +static void hotplug_bridge_dynconn_destroy(struct drm_connector *connector) +{ + struct hotplug_bridge *hpb = hotplug_bridge_from_dynconn(connector); + + drm_connector_unregister(&hpb->dynconn); + drm_connector_cleanup(&hpb->dynconn); + hpb->bridge_modes = NULL; +} + +static const struct drm_connector_funcs dynconn_funcs = { + .destroy = hotplug_bridge_dynconn_destroy, + .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, + .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, + .fill_modes = drm_helper_probe_single_connector_modes, +}; + +/* + * In non-removable pipelines using a "bridge connector", + * drm_bridge_connector_init() stores in the bridge_connector a pointer to + * the last bridge having OP_MODES (typically the panel bridge), so the + * .get_modes op will automatically be called on that bridge (it also takes + * pointers to other bridges which we don't care about). The "bridge + * connector" is too restrictive for our use case so we cannot use it. But + * we need a pointer to the modes-providing bridge, so we need to replicate + * that bit of its logic. + */ +static void hotplug_bridge_dynconn_find_bridge(struct hotplug_bridge *hpb) +{ + struct drm_bridge *bridge; + + if (WARN_ON(!hpb->next_bridge || !hpb->bridge.encoder)) + return; + + drm_for_each_bridge_in_chain(hpb->bridge.encoder, bridge) + if (bridge->ops & DRM_BRIDGE_OP_MODES) + hpb->bridge_modes = bridge; +} + +static int hotplug_bridge_dynconn_add(struct hotplug_bridge *hpb) +{ + int err; + + err = drm_connector_init(hpb->bridge.dev, &hpb->dynconn, &dynconn_funcs, + DRM_MODE_CONNECTOR_LVDS); + if (err) + return err; + + drm_atomic_helper_connector_reset(&hpb->dynconn); + + drm_connector_helper_add(&hpb->dynconn, + &hotplug_bridge_dynconn_connector_helper_funcs); + + drm_connector_attach_encoder(&hpb->dynconn, hpb->bridge.encoder); + if (err) + goto err_cleanup; + + hotplug_bridge_dynconn_find_bridge(hpb); + + err = drm_connector_register(&hpb->dynconn); + if (err) + goto err_cleanup; + + return 0; + +err_cleanup: + drm_connector_cleanup(&hpb->dynconn); + hpb->bridge_modes = NULL; + return err; +} + +/* ----------------------------------------------------------------------- */ + +/* + * Attach the remote bridge to the encoder and to the next bridge in the + * chain, if possible. For this to succeed, we need to know: + * + * - the encoder, which is set at the first drm_bridge_attach() time + * - the next bridge, which is obtained via a notifier whenever the next + * bridge is (re)probed, or at probe time in case it was probed before us + * + * In order to handle different execution sequences, this function can be + * called from multiple places and needs to check all the prerequisites + * every time, and it will act only if both are met. + * + * Must be called with hpb->next_bridge_mutex held. + * + * Returns 0 if the encoder was attached successfully, -ENODEV if any of + * the two prerequisites above is not met (no encoder or no next bridge), + * the error returned by drm_bridge_attach() otherwise. + */ +static int hotplug_bridge_attach_to_encoder_chain(struct hotplug_bridge *hpb) +{ + int ret; + + if (!hpb->next_bridge || !hpb->bridge.encoder) + return -ENODEV; + + ret = drm_bridge_attach(hpb->bridge.encoder, hpb->next_bridge, &hpb->bridge, + DRM_BRIDGE_ATTACH_NO_CONNECTOR); + if (ret) + return dev_err_probe(hpb->dev, ret, "drm_bridge_attach failed\n"); + + dev_dbg(hpb->dev, "attached to encoder chain\n"); + + return 0; +} + +/* + * Stop the video pipeline and detach next_bridge. + * + * Must be called with hpb->next_bridge_mutex held. + */ +static void hotplug_bridge_detach_from_encoder_chain(struct hotplug_bridge *hpb) +{ + WARN_ON_ONCE(!hpb->next_bridge); + + dev_dbg(hpb->dev, "detaching from encoder chain\n"); + + drm_atomic_helper_shutdown(hpb->bridge.dev); + + drm_encoder_cleanup_from(hpb->bridge.encoder, hpb->next_bridge); +} + +static void hotplug_bridge_grab(struct hotplug_bridge *hpb) +{ + struct device *dev = hpb->dev; + struct drm_bridge *bridge; + struct drm_panel *panel; + int err; + + mutex_lock(&hpb->next_bridge_mutex); + + if (hpb->next_bridge) + goto out_unlock; + + /* + * This is supposed to be replaced by devm_drm_of_get_bridge(), but + * that is a devm_, and we need to remove the panel bridge also on + * next_bridge disconnect. + */ + err = drm_of_find_panel_or_bridge(dev->of_node, 1, 0, &panel, &bridge); + if (err) + goto out_unlock; + + /* Convert the remote panel to a bridge */ + if (panel) + bridge = drm_panel_bridge_add(panel); + if (IS_ERR(bridge)) + goto out_unlock; + + hpb->next_bridge = bridge; + + dev_dbg(dev, "grabbed next bridge (%pOFn)\n", hpb->next_bridge->of_node); + + hpb->bridge.pre_enable_prev_first = hpb->next_bridge->pre_enable_prev_first; + + err = hotplug_bridge_attach_to_encoder_chain(hpb); + if (err) + goto err_panel_bridge_remove; + + err = hotplug_bridge_dynconn_add(hpb); + if (err) + goto err_detach_from_encoder_chain; + + queue_work(system_wq, &hpb->hpd_work); + goto out_unlock; + +err_detach_from_encoder_chain: + hotplug_bridge_detach_from_encoder_chain(hpb); +err_panel_bridge_remove: + drm_panel_bridge_remove(hpb->next_bridge); + hpb->next_bridge = NULL; +out_unlock: + mutex_unlock(&hpb->next_bridge_mutex); +} + +/* + * Detach from the next bridge and remove the panel bridge, either on + * release or when the downstream bridge is being removed. + * + * Can be called in these ways: + * + * - bridge_being_removed is NULL: detach unconditionally + * (this is useful on .remove() to teardown everything) + * - bridge_being_removed == hpb->next_bridge: detach + * (the downstream bridge is being removed) + * - bridge_being_removed != hpb->next_bridge: do nothing + * (the bridge being removed is not the downstream bridge) + * + * In all cases, does nothing when there is no downstream bridge. + */ +static void hotplug_bridge_release(struct hotplug_bridge *hpb, + struct drm_bridge *bridge_being_removed) +{ + mutex_lock(&hpb->next_bridge_mutex); + + if (!hpb->next_bridge) + goto out; + + if (bridge_being_removed && bridge_being_removed != hpb->next_bridge) + goto out; + + hotplug_bridge_dynconn_destroy(&hpb->dynconn); + + dev_dbg(hpb->dev, "releasing next bridge (%pOFn)\n", hpb->next_bridge->of_node); + + hotplug_bridge_detach_from_encoder_chain(hpb); + + /* + * This will check that the bridge actually belongs to panel-bridge + * before doing anything with it, so we can safely always call it. + */ + drm_panel_bridge_remove(hpb->next_bridge); + hpb->next_bridge = NULL; + + queue_work(system_wq, &hpb->hpd_work); + +out: + mutex_unlock(&hpb->next_bridge_mutex); +} + +static int hotplug_bridge_notifier_call(struct notifier_block *nb, + unsigned long event, void *private) +{ + struct hotplug_bridge *hpb = container_of(nb, struct hotplug_bridge, drm_bridge_nb); + struct drm_bridge *bridge = private; + + switch (event) { + case DRM_BRIDGE_NOTIFY_ADD: + hotplug_bridge_grab(hpb); + break; + case DRM_BRIDGE_NOTIFY_REMOVE: + hotplug_bridge_release(hpb, bridge); + break; + } + + return NOTIFY_DONE; +} + +static int hotplug_bridge_attach(struct drm_bridge *bridge, + enum drm_bridge_attach_flags flags) +{ + struct hotplug_bridge *hpb = hotplug_bridge_from_drm_bridge(bridge); + struct device *dev = hpb->dev; + struct drm_connector *connector; + struct drm_encoder *encoder = hpb->bridge.encoder; + int err; + + /* Encoder was not yet provided to our bridge */ + if (!encoder) + return -ENODEV; + + /* Connector was already created */ + if (hpb->fixconn) + return dev_err_probe(dev, -EBUSY, "connector already created\n"); + + connector = drm_bridge_connector_init(bridge->dev, encoder); + if (IS_ERR(connector)) + return dev_err_probe(dev, PTR_ERR(connector), "failed to initialize connector\n"); + + drm_connector_attach_encoder(connector, encoder); + + hpb->fixconn = connector; + + drm_connector_register(connector); + + mutex_lock(&hpb->next_bridge_mutex); + err = hotplug_bridge_attach_to_encoder_chain(hpb); + mutex_unlock(&hpb->next_bridge_mutex); + + /* -ENODEV is acceptable, in case next_bridge is not yet known */ + if (err == -ENODEV) + err = 0; + + return err; +} + +static void hotplug_bridge_detach(struct drm_bridge *bridge) +{ + struct hotplug_bridge *hpb = hotplug_bridge_from_drm_bridge(bridge); + + mutex_lock(&hpb->next_bridge_mutex); + hotplug_bridge_detach_from_encoder_chain(hpb); + mutex_unlock(&hpb->next_bridge_mutex); + + if (hpb->fixconn) { + drm_connector_unregister(hpb->fixconn); + drm_connector_cleanup(hpb->fixconn); + hpb->fixconn = NULL; + } +} + +/* + * The fixed connector is never attached to a panel, so it should always be + * reported as disconnected. + */ +static enum drm_connector_status hotplug_bridge_detect(struct drm_bridge *bridge) +{ + return connector_status_disconnected; +} + +static void hotplug_bridge_hpd_work_func(struct work_struct *work) +{ + struct hotplug_bridge *hpb = container_of(work, struct hotplug_bridge, hpd_work); + + if (hpb->bridge.dev) + drm_helper_hpd_irq_event(hpb->bridge.dev); +} + +static const struct drm_bridge_funcs hotplug_bridge_funcs = { + .attach = hotplug_bridge_attach, + .detach = hotplug_bridge_detach, + .detect = hotplug_bridge_detect, +}; + +static int hotplug_bridge_dsi_detach(struct mipi_dsi_host *host, + struct mipi_dsi_device *device_remote) +{ + struct hotplug_bridge *hpb = dev_get_drvdata(host->dev); + + if (!hpb->dsi_dev) + return -ENODEV; + + mipi_dsi_detach(hpb->dsi_dev); + mipi_dsi_device_unregister(hpb->dsi_dev); + hpb->dsi_dev = NULL; + + return 0; +} + +/* + * Attach the local DSI device to the upstream DSI host, possibly with a + * "null" format. + * + * In "normal" bridges this function should be _only_ used as the .attach + * callback of hotplug_bridge_dsi_ops. But "normal" bridges have their + * downstream DSI device always connected, which we don't. When booting + * without anything connected downstream, our upstream bridge could be not + * even calling drm_bridge_add() until we do attach ourselves as a DSI + * device, preventing the whole DRM card from being instantiated. + * + * In order to always have a DRM card after boot, we do call this same + * function while probing in order to attach as a DSI device to the DSI + * master. However during probe we don't know the bus format yet. It would + * be nice to be able to update the format afterwards when a downstream DSI + * device is attaching to our local host, but there is no callback for + * that. To overcome this limitation, this function can be called in two + * ways: + * + * - during probe, to make the upstream bridge happy, when there is no + * next_dsi_dev yet and thus the lanes/format/etc are unknown + * - as the mipi_dsi_host_ops.attach callback proper, as soon as the + * next_dsi_dev is known + * + * The resulting call sequence is: + * + * 1. hotplug_bridge_dsi_attach() called by hotplug_bridge_probe() with + * next_dsi_dev == NULL: we attach to the host but with a fake format + * so the DRM card can be populated. hpb->dsi_dev becomes non-NULL. + * 2. hotplug_bridge_dsi_attach() called as .attach callback from a + * downstream device when it becomes available: we need to detach in + * order to re-attach with the format of the device. hpb->dsi_dev + * is found non-NULL, then reused so it will be non-NULL again. + * 3. hotplug_bridge_dsi_detach() called as the .detach callback by a + * downstream device: cleans up everything normally. hpb->dsi_dev goes + * from non-NULL to NULL. + * 4. hotplug_bridge_dsi_attach() called by a downstream device: attaches + * normally to the upstream DSI host. hpb->dsi_dev goes from NULL to + * non-NULL. + * + * Steps 3 and 4 are the "normal" attach/detach steps as on "normal" + * bridges. + * + * Steps 1 and 2 happen only the first time, steps 3 and 4 will happen + * every time the downstream bridge disconnects and reconnects. + */ +static int hotplug_bridge_dsi_attach(struct mipi_dsi_host *host, + struct mipi_dsi_device *next_dsi_dev) +{ + struct device *dev = host->dev; + struct hotplug_bridge *hpb = dev_get_drvdata(dev); + struct mipi_dsi_device *dsi_dev; + const struct mipi_dsi_device_info dsi_info = { + .type = "hotplug-bridge", + .channel = 0, + .node = NULL, + }; + int err; + + /* + * Step 2 only (first time we are called for an actual device + * attaching): clean up the fake attach done at step 1 + */ + if (hpb->dsi_dev) + hotplug_bridge_dsi_detach(&hpb->dsi_host, NULL); + + /* Register a local DSI device with the remote DSI host */ + dsi_dev = mipi_dsi_device_register_full(hpb->prev_dsi_host, + &dsi_info); + if (IS_ERR(dsi_dev)) + return PTR_ERR(dsi_dev); + + /* At step 1 we have no downstream device to get the format from */ + if (next_dsi_dev) { + dsi_dev->channel = next_dsi_dev->channel; + dsi_dev->lanes = next_dsi_dev->lanes; + dsi_dev->format = next_dsi_dev->format; + dsi_dev->mode_flags = next_dsi_dev->mode_flags; + } + + /* Attach our local DSI device to the remote DSI host */ + err = mipi_dsi_attach(dsi_dev); + if (err) { + mipi_dsi_device_unregister(dsi_dev); + return dev_err_probe(dev, err, "failed to attach hotplug dsi device to host\n"); + } + + hpb->dsi_dev = dsi_dev; + + return 0; +} + +/* + * Propagate mipi_dsi_device_transfer() to the upstream DSI host. + * + * Reimplements identically the minimal needed part of + * mipi_dsi_device_transfer(), including the -ENOSYS return value. + */ +static ssize_t hotplug_bridge_dsi_transfer(struct mipi_dsi_host *host, + const struct mipi_dsi_msg *msg) +{ + struct hotplug_bridge *hpb = dev_get_drvdata(host->dev); + const struct mipi_dsi_host_ops *ops; + + if (!hpb->dsi_dev) + return -ENODEV; + + ops = hpb->dsi_dev->host->ops; + + if (!ops || !ops->transfer) + return -ENOSYS; + + return ops->transfer(hpb->dsi_dev->host, msg); +} + +static const struct mipi_dsi_host_ops hotplug_bridge_dsi_ops = { + .attach = hotplug_bridge_dsi_attach, + .detach = hotplug_bridge_dsi_detach, + .transfer = hotplug_bridge_dsi_transfer, +}; + +/* + * Find the upstream DSI host and register our downstream-facing DSI host. + */ +static int hotplug_bridge_dsi_setup(struct hotplug_bridge *hpb) +{ + struct device *dev = hpb->dev; + struct device_node *endpoint; + struct device_node *node; + + endpoint = of_graph_get_endpoint_by_regs(dev->of_node, 0, -1); + node = of_graph_get_remote_port_parent(endpoint); + + hpb->prev_dsi_host = of_find_mipi_dsi_host_by_node(node); + + of_node_put(node); + of_node_put(endpoint); + + if (!hpb->prev_dsi_host) + return -EPROBE_DEFER; + + hpb->dsi_host.dev = dev; + hpb->dsi_host.ops = &hotplug_bridge_dsi_ops; + + return mipi_dsi_host_register(&hpb->dsi_host); +} + +static void hotplug_bridge_dsi_cleanup(struct hotplug_bridge *hpb) +{ + mipi_dsi_host_unregister(&hpb->dsi_host); +} + +static int hotplug_bridge_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct hotplug_bridge *hpb; + struct drm_bridge *bridge; + int err; + + hpb = devm_kzalloc(dev, sizeof(*hpb), GFP_KERNEL); + if (!hpb) + return -ENOMEM; + + hpb->dev = dev; + + mutex_init(&hpb->next_bridge_mutex); + INIT_WORK(&hpb->hpd_work, hotplug_bridge_hpd_work_func); + + hpb->drm_bridge_nb.notifier_call = hotplug_bridge_notifier_call; + + err = hotplug_bridge_dsi_setup(hpb); + if (err) + return dev_err_probe(dev, err, "failed to setup DSI\n"); + + bridge = &hpb->bridge; + bridge->of_node = dev->of_node; + bridge->funcs = &hotplug_bridge_funcs; + bridge->type = DRM_MODE_CONNECTOR_DSI; + bridge->ops |= DRM_BRIDGE_OP_DETECT | DRM_BRIDGE_OP_HPD; + + platform_set_drvdata(pdev, hpb); + + err = devm_drm_bridge_add(dev, bridge); + if (err) { + dev_err_probe(dev, err, "failed adding bridge\n"); + goto err_dsi_cleanup; + } + + err = hotplug_bridge_dsi_attach(&hpb->dsi_host, NULL); + if (err) { + dev_err_probe(dev, err, "failed first attach to upstream DSI host\n"); + goto err_dsi_cleanup; + } + + /* To be notified when the next bridge appears... */ + drm_bridge_notifier_register(&hpb->drm_bridge_nb); + + /* ...but also check now, in case the next bridge was probed earlier */ + hotplug_bridge_grab(hpb); + + return 0; + +err_dsi_cleanup: + hotplug_bridge_dsi_cleanup(hpb); + return err; +} + +static void hotplug_bridge_remove(struct platform_device *pdev) +{ + struct hotplug_bridge *hpb = platform_get_drvdata(pdev); + + cancel_work_sync(&hpb->hpd_work); + + drm_bridge_notifier_unregister(&hpb->drm_bridge_nb); + + hotplug_bridge_release(hpb, NULL); + + hotplug_bridge_dsi_cleanup(hpb); +} + +static const struct platform_device_id hotplug_bridge_platform_ids[] = { + { .name = "hotplug-dsi-bridge" }, + {}, +}; +MODULE_DEVICE_TABLE(platform, hotplug_bridge_platform_ids); + +static struct platform_driver hotplug_bridge_driver = { + .probe = hotplug_bridge_probe, + .remove_new = hotplug_bridge_remove, + .id_table = hotplug_bridge_platform_ids, + .driver = { + .name = "hotplug-drm-bridge", + }, +}; + +module_platform_driver(hotplug_bridge_driver); + +MODULE_AUTHOR("Luca Ceresoli "); +MODULE_AUTHOR("Paul Kocialkowski "); +MODULE_DESCRIPTION("Hotplug DRM Bridge"); +MODULE_LICENSE("GPL"); From patchwork Fri Aug 9 15:34:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Ceresoli X-Patchwork-Id: 1971012 X-Patchwork-Delegate: wolfram@the-dreams.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=gm1 header.b=PwN7z2ND; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45e3:2400::1; helo=sv.mirrors.kernel.org; envelope-from=linux-i2c+bounces-5269-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [IPv6:2604:1380:45e3:2400::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WgSh74w3Pz1ybT for ; Sat, 10 Aug 2024 01:36:55 +1000 (AEST) 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 625C4288060 for ; Fri, 9 Aug 2024 15:36:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E60A0199242; Fri, 9 Aug 2024 15:35:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="PwN7z2ND" X-Original-To: linux-i2c@vger.kernel.org Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) (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 3335F1990C8; Fri, 9 Aug 2024 15:35:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723217753; cv=none; b=PjlyjiDJBbd3FxNrCLfn92vQktKQp0Fc7N+TDZk2+sXCLFFEdx5qV9aFb8bvPHLhlAxWTqM6alhpRgGtjbc2a7nuwISBe8me2A2oCsB0Z4El1WyZkbyy0tRtZgnIz2DrT73OsUZV+C3E20cDciMzoT5V9iGzbf8wyyt8BWWt6OQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723217753; c=relaxed/simple; bh=ocZMV2xaZRwRSyqtwNwFF9qp0Jusuc2WJaJIXWvecIM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SOdpqqJ9pLHXybJjD5ffoUwWwN2puM6zgYS7KavsLhypCTbJJBNhnRXrXJZQnFzNdDJVBFB8ON0Fg51sQ62eqKiZsiDvpRBdQplVc6bT+GT+HIjk1umx9AAhsiIb6Gi1laqIfjKpIiKsGextvVAjubYUOx/Sox43mF32B8QFd+g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=PwN7z2ND; arc=none smtp.client-ip=217.70.183.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id 8BF92C000A; Fri, 9 Aug 2024 15:35:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1723217749; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oSQ+hacy88j78to52wbL7L51YRPgyCpJ1CVB9WAt+iY=; b=PwN7z2NDVooO8+EOZkmmb7r2By95CHEx0lIPTHWFkZT15kwQ/Sh3ESOqF+esRpAp4r2LJn c8nqf5CpSU0HEBixhpsuj3U4wAltnbyxEseZkQP38gdsuiDqjBjxJFDQFqYOxq++ZvTDgf dY+Hl7fTwIgri5qWHvqRlXc94Sx+D6bu2/v5OYp1pjsG1qAgPmQpezT+dHLp7bvt3K/pFZ ChTgDzIoD3wViziS6UI5kp+hn9O09BXdHNq8PKWBEvX2Za+ZpkOJ3L+VCvX2q4rt0te/61 pNT93dnokQIPhHNYklbNmPMtUOqEnN8bE0rokyuj4biUFajOXaVijBAnk7SADQ== From: Luca Ceresoli Date: Fri, 09 Aug 2024 17:34:53 +0200 Subject: [PATCH v3 5/7] i2c: i2c-core-of: follow i2c-parent phandle to probe devices from added nodes Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240809-hotplug-drm-bridge-v3-5-b4c178380bc9@bootlin.com> References: <20240809-hotplug-drm-bridge-v3-0-b4c178380bc9@bootlin.com> In-Reply-To: <20240809-hotplug-drm-bridge-v3-0-b4c178380bc9@bootlin.com> To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Derek Kiernan , Dragan Cvetic , Arnd Bergmann , Greg Kroah-Hartman , Saravana Kannan , Wolfram Sang , "Rafael J. Wysocki" Cc: Paul Kocialkowski , =?utf-8?q?Herv=C3=A9_Codina?= , Thomas Petazzoni , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-i2c@vger.kernel.org, Paul Kocialkowski , Luca Ceresoli X-Mailer: b4 0.14.0 X-GND-Sasl: luca.ceresoli@bootlin.com When device tree nodes are added, the I2C core tries to probe client devices based on the classic DT structure: i2c@abcd0000 { some-client@42 { compatible = "xyz,blah"; ... }; }; However for hotplug connectors described via device tree overlays there is additional level of indirection, which is needed to decouple the overlay and the base tree: --- base device tree --- i2c1: i2c@abcd0000 { compatible = "xyz,i2c-ctrl"; ... }; i2c5: i2c@cafe0000 { compatible = "xyz,i2c-ctrl"; ... }; connector { i2c-ctrl { i2c-parent = <&i2c1>; #address-cells = <1>; #size-cells = <0>; }; i2c-sensors { i2c-parent = <&i2c5>; #address-cells = <1>; #size-cells = <0>; }; }; --- device tree overlay --- ... // This node will overlay on the i2c-ctrl node of the base tree i2c-ctrl { eeprom@50 { compatible = "atmel,24c64"; ... }; }; ... --- resulting device tree --- i2c1: i2c@abcd0000 { compatible = "xyz,i2c-ctrl"; ... }; i2c5: i2c@cafe0000 { compatible = "xyz,i2c-ctrl"; ... }; connector { i2c-ctrl { i2c-parent = <&i2c1>; #address-cells = <1>; #size-cells = <0>; eeprom@50 { ompatible = "atmel,24c64"; ... }; }; i2c-sensors { i2c-parent = <&i2c5>; #address-cells = <1>; #size-cells = <0>; }; }; Here i2c-ctrl (same goes for i2c-sensors) represent the part of I2C bus that is on the hot-pluggable add-on. On hot-plugging it will physically connect to the I2C adapter on the base board. Let's call the 'i2c-ctrl' node an "extension node". In order to decouple the overlay from the base tree, the I2C adapter (i2c@abcd0000) and the extension node (i2c-ctrl) are separate nodes. Rightfully, only the former will probe into an I2C adapter, and it will do that perhaps during boot, long before overlay insertion. The extension node won't probe into an I2C adapter or any other device or bus, so its subnodes ('eeprom@50') won't be interpreted as I2C clients by current I2C core code. However it has an 'i2c-parent' phandle to point to the corresponding I2C adapter node. This tells those nodes are I2C clients of the adapter in that other node. Extend the i2c-core-of code to look for the adapter via the 'i2c-parent' phandle when the regular adapter lookup does not find one. This allows all clients to be probed: both those on the base board (described in the base device tree) and those on the add-on and described by an overlay. Signed-off-by: Luca Ceresoli --- Note: while this patch works for normal hotplug and unplug, it has some weaknesses too, due to the implementation being in a OF change notifier. Two cases come to mind: 1. In the base device tree there must be _no_ nodes under the "extension node" (i2c-ctrl), or they won't be picked up as they are not dynamically added. 2. In case the I2C adapter is unbound and rebound, or it probes after overlay insertion, it will miss the OF notifier events and so it won't find the devices in the extension node. The first case is not a limiting factor: fixed I2C devices should just stay under the good old I2C adapter node. The second case is a limiting factor, even though not happening in "normal" use cases. I cannot see any solution without making the adapter aware of the "bus extensions" it has, so on its probe it can always go look for any devices there. Taking into account the case of multiple connectors each having an extension of the same bus, this may look as follows in device tree: --- base device tree --- i2c1: i2c@abcd0000 { compatible = "xyz,i2c-ctrl"; ... i2c-bus-extensions = <&i2c_ctrl_conn0, &i2c_ctrl_conn1>; }; connector@0 { i2c_ctrl_conn0: i2c-ctrl { i2c-parent = <&i2c1>; #address-cells = <1>; #size-cells = <0>; }; }; connector@1 { i2c_ctrl_conn1: i2c-ctrl { i2c-parent = <&i2c1>; #address-cells = <1>; #size-cells = <0>; }; }; I'd love to have some feedback and opinions about the basic idea before digging into the details of this additional step. --- This patch first appeared in v3. --- drivers/i2c/i2c-core-of.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/i2c/i2c-core-of.c b/drivers/i2c/i2c-core-of.c index a6c407d36800..71c559539a13 100644 --- a/drivers/i2c/i2c-core-of.c +++ b/drivers/i2c/i2c-core-of.c @@ -170,6 +170,15 @@ static int of_i2c_notify(struct notifier_block *nb, unsigned long action, switch (of_reconfig_get_state_change(action, rd)) { case OF_RECONFIG_CHANGE_ADD: adap = of_find_i2c_adapter_by_node(rd->dn->parent); + if (adap == NULL) { + struct device_node *i2c_bus; + + i2c_bus = of_parse_phandle(rd->dn->parent, "i2c-parent", 0); + if (i2c_bus) { + adap = of_find_i2c_adapter_by_node(i2c_bus); + of_node_put(i2c_bus); + } + } if (adap == NULL) return NOTIFY_OK; /* not for us */ From patchwork Fri Aug 9 15:34:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Ceresoli X-Patchwork-Id: 1971014 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=gm1 header.b=eZUBojbX; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=139.178.88.99; helo=sv.mirrors.kernel.org; envelope-from=linux-i2c+bounces-5270-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org [139.178.88.99]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WgShq1ZJzz1ybT for ; Sat, 10 Aug 2024 01:37:31 +1000 (AEST) 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 00635287D7D for ; Fri, 9 Aug 2024 15:37:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D2450199E89; Fri, 9 Aug 2024 15:35:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="eZUBojbX" X-Original-To: linux-i2c@vger.kernel.org Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) (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 AD578199235; Fri, 9 Aug 2024 15:35:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723217756; cv=none; b=jnuAbRBQcpfRo2mjhURPhGCclnS7Hy3Vvgh7sbCwBFZM2vofOzZSBXVcL6cB50lxcZ6cqsyKIbLU63YJHEtK8MdVNJ1MVJcK/fnsoozgHUHBrQwh4O4C5+Mku+sDJC/KnTeIHToSWbRipJhMmJY8rowsovBoToTniwDBjLFh3P4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723217756; c=relaxed/simple; bh=KXjPZpEMNcIKlrj2B9sOj/LJHhNVjUUwvWpVdLHfwkU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RJnlqnrZN8N067YoY90OfZkQJBc1rvwyh2qGLZSVGkJFus2iPxSnC42rxopVeNDEZmJCTidZfVHGWvXfDGUkYtTkn/S7d5RQElU6FiYhwwPg2cV6h/TPfUziu0Z6jSVd2HU3Gy+WlROdTI8Tir2JHBA+kF/hJvOBqjJULcPeS4M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=eZUBojbX; arc=none smtp.client-ip=217.70.183.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id F2416C0003; Fri, 9 Aug 2024 15:35:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1723217752; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=87u1F3vInAoGSkUVnnAJ6Y7ZAKf3WW2041g2D7fY4cg=; b=eZUBojbXR3bFPl2hSVL2g4KcsIaTDhv8GfcoawMqxBtGQ3MAN+NAaoMLiDv8zJ6JOAyLPm FBI7D7g8EWRBAXxmG6dzs7mEiSmd/kwCPbIRMR6dmOJxs1tkfCKm+jC1PYUystPh7jOvnO /lIQelynWhTdAEYCJdG+iHrrZIorW3UPfP7CkKxwoB6WY0v2QEXwaxUdXn1R2yL9C1hcvk 1teW/YNp4moenDg5czjPAWkQE0sfD2LucUa7LrpMZi/M9oouAaELA//jIspfOSsE3hpIBG 2+opqu49+lJJqSUM0sKF2Uf6943u5Gma7dV1kmUTS5L7e7Zh5CLKDI2G05CklA== From: Luca Ceresoli Date: Fri, 09 Aug 2024 17:34:54 +0200 Subject: [PATCH v3 6/7] misc: add ge-addon-connector driver Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240809-hotplug-drm-bridge-v3-6-b4c178380bc9@bootlin.com> References: <20240809-hotplug-drm-bridge-v3-0-b4c178380bc9@bootlin.com> In-Reply-To: <20240809-hotplug-drm-bridge-v3-0-b4c178380bc9@bootlin.com> To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Derek Kiernan , Dragan Cvetic , Arnd Bergmann , Greg Kroah-Hartman , Saravana Kannan , Wolfram Sang , "Rafael J. Wysocki" Cc: Paul Kocialkowski , =?utf-8?q?Herv=C3=A9_Codina?= , Thomas Petazzoni , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-i2c@vger.kernel.org, Paul Kocialkowski , Luca Ceresoli X-Mailer: b4 0.14.0 X-GND-Sasl: luca.ceresoli@bootlin.com Add a driver to support the runtime hot-pluggable add-on connector on the GE SUNH device. This connector allows connecting and disconnecting an add-on to/from the main device to augment its features. Connection and disconnection can happen at runtime at any moment without notice. Different add-on models can be connected, and each has an EEPROM with a model identifier at a fixed address. The add-on hardware is added and removed using device tree overlay loading and unloading. Co-developed-by: Herve Codina Signed-off-by: Herve Codina Signed-off-by: Luca Ceresoli --- Changed in v3: - update to the new overlay representation that now does not include the target node; instead the target node is the connector node itself and is now passed by the connector driver to of_overlay_fdt_apply(), so the overlay is now decoupled from the base device tree - update to explicitely probe devices not reachable by the CPU on any physical bus (which probe as platform devices) which are now inside a 'nobus-devices' subnode of the connector node - change how the DRM bridge is populated to use the new device tree representation, having the video ports inside the 'dsi' node **NOTE** this specific change opens up a question about the .of_node_reused flag: setting it to true might be wrong now as the bridge will be handed the 'dsi' subnode of the connector node; however not setting it to true prevents the hotplug bridge module autoloading due to the alias string changing from "platform:hotplug-dsi-bridge" to "of:NdsiT(null)". - remove dev_info() and uninformative dev_dbg() calls - Kconfig: use 'depends on' instead of 'select' - Kconfig: improve help text and add module name This patch first appeared in v2. --- MAINTAINERS | 1 + drivers/misc/Kconfig | 18 ++ drivers/misc/Makefile | 1 + drivers/misc/ge-sunh-connector.c | 523 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 543 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index d571aa049ce1..021dfa961f3f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -10262,6 +10262,7 @@ F: drivers/iio/pressure/mprls0025pa* HOTPLUG CONNECTOR FOR GE SUNH ADDONS M: Luca Ceresoli S: Maintained +F: drivers/misc/ge-sunh-connector.c F: Documentation/devicetree/bindings/connector/ge,sunh-addon-connector.yaml HP BIOSCFG DRIVER diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index 41c3d2821a78..8e4cc81b0ec9 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -600,6 +600,24 @@ config MARVELL_CN10K_DPI To compile this driver as a module, choose M here: the module will be called mrvl_cn10k_dpi. +config GE_SUNH_CONNECTOR + tristate "GE SUNH hotplug add-on connector" + depends on OF_OVERLAY + depends on NVMEM + depends on DRM_HOTPLUG_BRIDGE + select FW_LOADER + help + Driver for the runtime hot-pluggable add-on connector on the GE + SUNH device. This connector allows connecting an add-on to the + main device to augment its features, and to later disconnect + it. Connection and disconnection can be done at runtime at any + moment without notice. Different add-on models can be connected, + and each has an EEPROM with a model identifier at a fixed + address. + + To compile this driver as a module, choose M here. + The module will be called ge-sunh-connector. + source "drivers/misc/c2port/Kconfig" source "drivers/misc/eeprom/Kconfig" source "drivers/misc/cb710/Kconfig" diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index c2f990862d2b..69747b048046 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -70,4 +70,5 @@ obj-$(CONFIG_TPS6594_ESM) += tps6594-esm.o obj-$(CONFIG_TPS6594_PFSM) += tps6594-pfsm.o obj-$(CONFIG_NSM) += nsm.o obj-$(CONFIG_MARVELL_CN10K_DPI) += mrvl_cn10k_dpi.o +obj-$(CONFIG_GE_SUNH_CONNECTOR) += ge-sunh-connector.o obj-y += keba/ diff --git a/drivers/misc/ge-sunh-connector.c b/drivers/misc/ge-sunh-connector.c new file mode 100644 index 000000000000..50c9e35a60e3 --- /dev/null +++ b/drivers/misc/ge-sunh-connector.c @@ -0,0 +1,523 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * GE SUNH hotplug add-on connector + * + * Driver for the runtime hot-pluggable add-on connector on the GE SUNH + * device. Add-on connection is detected via GPIOs (+ a debugfs + * trigger). On connection, a "base" DT overlay is added that describes + * enough to reach the NVMEM cell with the model ID. Based on the ID, an + * add-on-specific overlay is loaded on top to describe everything else. + * + * Copyright (C) 2024, GE HealthCare + * + * Authors: + * Luca Ceresoli + * Herve Codina + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +enum sunh_conn_overlay_level { + SUNH_CONN_OVERLAY_BASE, + SUNH_CONN_OVERLAY_ADDON, + SUNH_CONN_OVERLAY_N_LEVELS +}; + +#define SUNH_CONN_N_STATUS_GPIOS 2 +static const char * const sunh_conn_status_gpio_name[SUNH_CONN_N_STATUS_GPIOS] = { + "plugged", "powergood" +}; + +struct sunh_conn { + struct device *dev; + struct gpio_desc *reset_gpio; + struct gpio_desc *status_gpio[SUNH_CONN_N_STATUS_GPIOS]; + + bool plugged; + int ovcs_id[SUNH_CONN_OVERLAY_N_LEVELS]; + struct mutex ovl_mutex; // serialize overlay code + struct notifier_block nvmem_nb; + struct work_struct nvmem_notifier_work; + + struct platform_device *hpb_pdev; + struct dentry *debugfs_root; +}; + +/* + * Populate all platform devices that are not on any bus. + * + * Populate devices without any I/O access from the CPU, (e.g. fixed + * regulators and gpio regulators). In the normal case of a device tree + * without runtime-loaded overlays these are direct children of the root + * node and as such they are populated as a special case. + * + * Within the hotplug connector they need to be at a deeper level of the + * tree. Moreover they are "segregated" in the "nobus-devices" node which + * allows to avoid trying of_platform_default_populate() on other kind of + * nodes. + * + * No need to depopulate them in this driver: of_platform_notify() will do + * that on overlay removal. + * + * In case a generalized framework for OF_based hotplug connector drivers + * will exist in the future, this function is definitely meant for the + * framework. + */ +static int sunh_conn_populate_nobus_devices(struct sunh_conn *conn) +{ + struct device_node *nobus_devs_dn; + int err; + + nobus_devs_dn = of_get_child_by_name(conn->dev->of_node, "nobus-devices"); + if (!nobus_devs_dn) + return 0; + + err = of_platform_default_populate(nobus_devs_dn, NULL, conn->dev); + if (err) + dev_err(conn->dev, "Failed to populate nobus devices\n"); + + of_node_put(nobus_devs_dn); + return err; +} + +static int sunh_conn_insert_overlay(struct sunh_conn *conn, + enum sunh_conn_overlay_level level, + const char *filename) +{ + const struct firmware *fw; + int err; + + err = request_firmware(&fw, filename, conn->dev); + if (err) + return dev_err_probe(conn->dev, err, "Error requesting overlay %s", filename); + + dev_dbg(conn->dev, "insert overlay %d: %s", level, filename); + err = of_overlay_fdt_apply(fw->data, fw->size, &conn->ovcs_id[level], conn->dev->of_node); + if (err) + dev_err_probe(conn->dev, err, "Failed to apply overlay %s\n", filename); + else + err = sunh_conn_populate_nobus_devices(conn); + + if (err) { + int err2; + + /* changeset may be partially applied */ + err2 = of_overlay_remove(&conn->ovcs_id[level]); + if (err2 < 0) + dev_err_probe(conn->dev, err2, + "Failed to remove failed overlay %s\n", filename); + } + + release_firmware(fw); + + return err; +} + +static int sunh_conn_load_base_overlay(struct sunh_conn *conn) +{ + int err = 0; + + mutex_lock(&conn->ovl_mutex); + + if (conn->ovcs_id[0] != 0) { + dev_dbg(conn->dev, "base overlay already loaded\n"); + goto out_unlock; + } + + err = sunh_conn_insert_overlay(conn, 0, "imx8mp-sundv1-addon-base.dtbo"); + +out_unlock: + mutex_unlock(&conn->ovl_mutex); + return err; +} + +static int sunh_conn_load_addon_overlay(struct sunh_conn *conn) +{ + u8 addon_id; + const char *filename; + int err; + + mutex_lock(&conn->ovl_mutex); + + if (conn->ovcs_id[0] == 0) { + dev_dbg(conn->dev, "base overlay not loaded\n"); + err = -EINVAL; + goto out_unlock; + } + + if (conn->ovcs_id[1] != 0) { + dev_dbg(conn->dev, "addon overlay already loaded\n"); + err = -EEXIST; + goto out_unlock; + } + + err = nvmem_cell_read_u8(conn->dev, "id", &addon_id); + if (err) + goto out_unlock; + + dev_dbg(conn->dev, "Found add-on ID %d\n", addon_id); + + switch (addon_id) { + case 23: + filename = "imx8mp-sundv1-addon-13.dtbo"; + break; + case 24: + filename = "imx8mp-sundv1-addon-15.dtbo"; + break; + case 25: + filename = "imx8mp-sundv1-addon-18.dtbo"; + break; + default: + dev_warn(conn->dev, "Unknown add-on ID %d\n", addon_id); + err = -ENODEV; + goto out_unlock; + } + + err = sunh_conn_insert_overlay(conn, 1, filename); + +out_unlock: + mutex_unlock(&conn->ovl_mutex); + return err; +} + +static void sunh_conn_unload_overlays(struct sunh_conn *conn) +{ + int level = SUNH_CONN_OVERLAY_N_LEVELS; + int err; + + mutex_lock(&conn->ovl_mutex); + while (level) { + level--; + + if (conn->ovcs_id[level] == 0) + continue; + + dev_dbg(conn->dev, "remove overlay %d (ovcs id %d)", + level, conn->ovcs_id[level]); + + err = of_overlay_remove(&conn->ovcs_id[level]); + if (err) + dev_err_probe(conn->dev, err, "Failed to remove overlay %d\n", level); + } + mutex_unlock(&conn->ovl_mutex); +} + +static void sunh_conn_reset(struct sunh_conn *conn, bool keep_reset) +{ + gpiod_set_value_cansleep(conn->reset_gpio, 1); + + if (keep_reset) + return; + + mdelay(10); + gpiod_set_value_cansleep(conn->reset_gpio, 0); + mdelay(10); +} + +static int sunh_conn_detach(struct sunh_conn *conn) +{ + /* Cancel any pending NVMEM notification jobs */ + cancel_work_sync(&conn->nvmem_notifier_work); + + /* Unload previouly loaded overlays */ + sunh_conn_unload_overlays(conn); + + /* Set reset signal to have it set on next plug */ + sunh_conn_reset(conn, true); + + return 0; +} + +static int sunh_conn_attach(struct sunh_conn *conn) +{ + int err; + + /* Reset the plugged board in order to start from a stable state */ + sunh_conn_reset(conn, false); + + err = sunh_conn_load_base_overlay(conn); + if (err) + goto err; + + /* + * -EPROBE_DEFER can be due to NVMEM cell not yet available, so + * don't give up, an NVMEM event could arrive later + */ + err = sunh_conn_load_addon_overlay(conn); + if (err && err != -EPROBE_DEFER) + goto err; + + return 0; + +err: + sunh_conn_detach(conn); + return err; +} + +static int sunh_conn_handle_event(struct sunh_conn *conn, bool plugged) +{ + int err; + + if (plugged == conn->plugged) + return 0; + + dev_dbg(conn->dev, "%s\n", plugged ? "connected" : "disconnected"); + + err = (plugged ? + sunh_conn_attach(conn) : + sunh_conn_detach(conn)); + + conn->plugged = plugged; + + return err; +} + +/* + * Return the current status of the connector as reported by the hardware. + * + * Returns: + * - 0 if not connected (any of the existing status GPIOs not asserted) or + * no status GPIOs exist + * - 1 if connected in a stable manner (all status GPIOs are asserted) + * - a negative error code in case reading the GPIOs fail + */ +static int sunh_conn_get_connector_status(struct sunh_conn *conn) +{ + int status = 0; + int i; + + for (i = 0; i < SUNH_CONN_N_STATUS_GPIOS; i++) { + int val; + + if (!conn->status_gpio[i]) + continue; + + val = gpiod_get_value_cansleep(conn->status_gpio[i]); + + if (val < 0) { + dev_err(conn->dev, "Error reading %s GPIO (%d)\n", + sunh_conn_status_gpio_name[i], val); + return val; + } + + if (val == 0) { + dev_dbg(conn->dev, "%s GPIO deasserted\n", + sunh_conn_status_gpio_name[i]); + return 0; + } + + status = 1; + } + + return status; +} + +static irqreturn_t sunh_conn_gpio_irq(int irq, void *data) +{ + struct sunh_conn *conn = data; + int conn_status; + + conn_status = sunh_conn_get_connector_status(conn); + if (conn_status >= 0) + sunh_conn_handle_event(conn, conn_status); + + return IRQ_HANDLED; +} + +static int plugged_read(void *dat, u64 *val) +{ + struct sunh_conn *conn = dat; + + *val = conn->plugged; + + return 0; +} + +static int plugged_write(void *dat, u64 val) +{ + struct sunh_conn *conn = dat; + + if (val > 1) + return -EINVAL; + + return sunh_conn_handle_event(conn, val); +} + +DEFINE_DEBUGFS_ATTRIBUTE(plugged_fops, plugged_read, plugged_write, "%lld\n"); + +static void sunh_conn_nvmem_notifier_work(struct work_struct *work) +{ + struct sunh_conn *conn = container_of(work, struct sunh_conn, nvmem_notifier_work); + + sunh_conn_load_addon_overlay(conn); +} + +static int sunh_conn_nvmem_notifier(struct notifier_block *nb, unsigned long action, void *arg) +{ + struct sunh_conn *conn = container_of(nb, struct sunh_conn, nvmem_nb); + + if (action == NVMEM_CELL_ADD) + queue_work(system_power_efficient_wq, &conn->nvmem_notifier_work); + + return NOTIFY_OK; +} + +static int sunh_conn_register_drm_bridge(struct sunh_conn *conn) +{ + struct device *dev = conn->dev; + struct device_node *dsi_np; + + dsi_np = of_get_child_by_name(dev->of_node, "dsi"); + if (!dsi_np) + return dev_err_probe(dev, -ENOENT, "dsi node not found"); + + const struct platform_device_info hpb_info = { + .parent = dev, + .fwnode = of_fwnode_handle(dsi_np), + .of_node_reused = true, + .name = "hotplug-dsi-bridge", + .id = PLATFORM_DEVID_NONE, + }; + + conn->hpb_pdev = platform_device_register_full(&hpb_info); + of_node_put(dsi_np); // platform core gets/puts the device node + if (IS_ERR(conn->hpb_pdev)) + return dev_err_probe(dev, PTR_ERR(conn->hpb_pdev), + "Error registering DRM bridge\n"); + + return 0; +} + +static void sunh_conn_unregister_drm_bridge(struct sunh_conn *conn) +{ + platform_device_unregister(conn->hpb_pdev); +} + +static int sunh_conn_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct sunh_conn *conn; + int conn_status; + int err; + int i; + + /* Cannot load overlay from filesystem before rootfs is mounted */ + if (system_state < SYSTEM_RUNNING) + return -EPROBE_DEFER; + + conn = devm_kzalloc(dev, sizeof(*conn), GFP_KERNEL); + if (!conn) + return -ENOMEM; + + platform_set_drvdata(pdev, conn); + conn->dev = dev; + + mutex_init(&conn->ovl_mutex); + INIT_WORK(&conn->nvmem_notifier_work, sunh_conn_nvmem_notifier_work); + + conn->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(conn->reset_gpio)) + return dev_err_probe(dev, PTR_ERR(conn->reset_gpio), + "Error getting reset GPIO\n"); + + for (i = 0; i < SUNH_CONN_N_STATUS_GPIOS; i++) { + conn->status_gpio[i] = + devm_gpiod_get_optional(dev, sunh_conn_status_gpio_name[i], GPIOD_IN); + if (IS_ERR(conn->status_gpio[i])) + return dev_err_probe(dev, PTR_ERR(conn->status_gpio[i]), + "Error getting %s GPIO\n", + sunh_conn_status_gpio_name[i]); + } + + err = sunh_conn_register_drm_bridge(conn); + if (err) + return err; + + conn->nvmem_nb.notifier_call = sunh_conn_nvmem_notifier; + err = nvmem_register_notifier(&conn->nvmem_nb); + if (err) { + dev_err_probe(dev, err, "Error registering NVMEM notifier\n"); + goto err_unregister_drm_bridge; + } + + for (i = 0; i < SUNH_CONN_N_STATUS_GPIOS; i++) { + if (conn->status_gpio[i]) { + err = devm_request_threaded_irq(dev, gpiod_to_irq(conn->status_gpio[i]), + NULL, sunh_conn_gpio_irq, + IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | + IRQF_ONESHOT, + dev_name(dev), conn); + if (err) { + dev_err_probe(dev, err, "Error getting %s GPIO IRQ\n", + sunh_conn_status_gpio_name[i]); + goto err_nvmem_unregister_notifier; + } + } + } + + conn_status = sunh_conn_get_connector_status(conn); + if (conn_status < 0) { + err = conn_status; + goto err_nvmem_unregister_notifier; + } + + /* Ensure initial state is known and overlay loaded if plugged */ + sunh_conn_handle_event(conn, conn_status); + + conn->debugfs_root = debugfs_create_dir(dev_name(dev), NULL); + debugfs_create_file("plugged", 0644, conn->debugfs_root, conn, &plugged_fops); + + return 0; + +err_nvmem_unregister_notifier: + nvmem_unregister_notifier(&conn->nvmem_nb); + cancel_work_sync(&conn->nvmem_notifier_work); +err_unregister_drm_bridge: + sunh_conn_unregister_drm_bridge(conn); + return err; +} + +static void sunh_conn_remove(struct platform_device *pdev) +{ + struct sunh_conn *conn = platform_get_drvdata(pdev); + + debugfs_remove(conn->debugfs_root); + sunh_conn_detach(conn); + + nvmem_unregister_notifier(&conn->nvmem_nb); + cancel_work_sync(&conn->nvmem_notifier_work); + + sunh_conn_unregister_drm_bridge(conn); +} + +static const struct of_device_id sunh_conn_dt_ids[] = { + { .compatible = "ge,sunh-addon-connector" }, + {} +}; +MODULE_DEVICE_TABLE(of, sunh_conn_dt_ids); + +static struct platform_driver sunh_conn_driver = { + .driver = { + .name = "sunh-addon-connector", + .of_match_table = sunh_conn_dt_ids, + }, + .probe = sunh_conn_probe, + .remove_new = sunh_conn_remove, +}; +module_platform_driver(sunh_conn_driver); + +MODULE_AUTHOR("Luca Ceresoli "); +MODULE_AUTHOR("Herve Codina "); +MODULE_DESCRIPTION("GE SUNH hotplug add-on connector"); +MODULE_LICENSE("GPL"); From patchwork Fri Aug 9 15:34:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Ceresoli X-Patchwork-Id: 1971015 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=gm1 header.b=eyhlheKI; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:40f1:3f00::1; helo=sy.mirrors.kernel.org; envelope-from=linux-i2c+bounces-5271-incoming=patchwork.ozlabs.org@vger.kernel.org; receiver=patchwork.ozlabs.org) Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org [IPv6:2604:1380:40f1:3f00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WgSj42Gl7z1yfC for ; Sat, 10 Aug 2024 01:37:44 +1000 (AEST) 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id A658EB21251 for ; Fri, 9 Aug 2024 15:37:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EDF0B199EA4; Fri, 9 Aug 2024 15:35:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="eyhlheKI" X-Original-To: linux-i2c@vger.kernel.org Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) (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 10DC71993B8; Fri, 9 Aug 2024 15:35:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723217758; cv=none; b=NtFYfzqsSfgCwcj6+d7t3qdGhtY+c+7etIuP72A7I1iApW+kV+IE98dwsN8rfCoNeKLtZORZpYRShSgb02N7YCi975Sv+jejyjyvV8ImhTwKWZ/ORuINEqnS8NWPVzq5M4izDAFL/m7XwPfoJ3TiLq+q8gheBuH5Bg/++O/RflI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723217758; c=relaxed/simple; bh=dNQcWdd/iWzRjVBCAWZe/Q7hHpy7CLXUD0gtLgIAXgM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=p6pc7wI29pXiXKUgfZAjKh0I+uN72tMF6zXiexQva+NJaHtRUKQnSKtQCHsmLKPqcXTL9UgEPill1+x1gj/Md4SBrmbdfrtvVDTqlIhs8U1nIAXwUD28iV+RbXgnmNDryQSrm8oxzM/UN086CAAFSZcGuf8NjFjULZglIQ2TXgc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=eyhlheKI; arc=none smtp.client-ip=217.70.183.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id 572D9C0004; Fri, 9 Aug 2024 15:35:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1723217754; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3wLpKWsQiF7y/LUYEs8/Wz7zA91+yoPEauv87bwPtjw=; b=eyhlheKIoL4c/nXLZKH975JXaGstp08K+gwzBLwtVhPf1GfUp3B5cKb3Cjz+aO9RdBXJYA hv9LIGidU6ddiMdOTEEsDuSxB0xcWMhGJM5f9yA++tAeVnZNgbXX+NSHd+EI54XC+uxiY9 8zOw4p4iulf0ZZ+1Evw2hPhHy7DKqKSnECscWGkCw+m0bL/q1/lac7/qtxm4mAa1ky6du4 VMzTbnU5IGQ16UJyl8lg76TGb+c5pp16ydcOtrlV8geGarkDYE1o/TjHG3GTMFXwDhYm8+ AAh32vtzsVcnTVf4mYOawpFoc2675FeaIKBalPWfnmq1fA2+Z1qVKdfWhAazAQ== From: Luca Ceresoli Date: Fri, 09 Aug 2024 17:34:55 +0200 Subject: [PATCH DO NOT APPLY v3 7/7] driver core: do not unblock consumers any drivers found Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240809-hotplug-drm-bridge-v3-7-b4c178380bc9@bootlin.com> References: <20240809-hotplug-drm-bridge-v3-0-b4c178380bc9@bootlin.com> In-Reply-To: <20240809-hotplug-drm-bridge-v3-0-b4c178380bc9@bootlin.com> To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Derek Kiernan , Dragan Cvetic , Arnd Bergmann , Greg Kroah-Hartman , Saravana Kannan , Wolfram Sang , "Rafael J. Wysocki" Cc: Paul Kocialkowski , =?utf-8?q?Herv=C3=A9_Codina?= , Thomas Petazzoni , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-i2c@vger.kernel.org, Paul Kocialkowski , Luca Ceresoli X-Mailer: b4 0.14.0 X-GND-Sasl: luca.ceresoli@bootlin.com Quick summary: I have investigated a problem for a long time, I have a pretty good understanding, I tried various fixes but none except this is working. The goal of this patch is to discuss the problem to converge to the best solution. --------------------------------- Symptoms --------------------------------- The problem appeared while testing the v3 addon connector driver that is part of this seres, and which is based on device tree overlays. Note the symptom happens often, but not always. Changes to logging is a typical way to make it appear/disappear, so it appears as time sensitive. The relevant DT overlay snippet is: / { fragment@0 { target-path = ""; __overlay__ { nobus-devices { // nodes in here are populated as platform devices reg_addon_3v3_lcd: regulator-addon-3v3-lcd { compatible = "regulator-fixed"; regulator-name = "3V3_LCD_ADDON"; gpios = <...>; }; addon_panel_dsi_lvds: panel-dsi-lvds { compatible = "..."; power-supply = <®_addon_3v3_lcd>; }; }; }; }; }; So the regulator is a supplier to the panel. Nothing special here, except we are in an overlay. The overlay gets applied and all devices work correctly. Troubles start appearing in the form of two messages on overlay removal, in this order: * WARNING: CPU: 1 PID: 189 at drivers/regulator/core.c:5856 regulator_unregister+0x1ec/0x208 This is issued during removal of the 3V3_LCD_ADDON regulator because rdev->open_count is 1, while it should be 0. This is because the panel still hasn't closed the regulator. * Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000 Call trace: regulator_lock_recursive+0x5c/0x200 regulator_lock_dependent+0xc0/0x140 regulator_enable+0x44/0x98 panel_simple_resume+0x38/0x108 [panel_simple] pm_generic_runtime_resume+0x34/0x58 __rpm_callback+0x50/0x1f0 rpm_callback+0x70/0x88 rpm_resume+0x49c/0x678 __pm_runtime_resume+0x54/0xa0 device_release_driver_internal+0xd4/0x240 device_release_driver+0x20/0x38 bus_remove_device+0xd4/0x120 device_del+0x154/0x388 This happens while the panel driver is being removed and the devm infra tries to close the regulator which is already gone. Both errors have the same origin: the regulator driver is removed before the panel driver. --------------------------------- Problem analysis --------------------------------- My analysis showed that the problem originates from devlink manipulation during overlay insertion, but shows its effects on removal. This is the sequence of events: * During overlay insertion: 1. the devlink code creates a devlink (A) with: supplier = regulator-addon-3v3-lcd consumer = panel-dsi-lvds flags = DL_FLAG_INFERRED (+ possibly others) because it has been inferred from firmware data 2. soon after, devlink A is relaxed and then dropped - does not happen always, based on timing - see below for details 3. the regulator-addon-3v3-lcd regulator gets probed as a platform device - the probe function for regulator-addon-3v3-lcd is reg_fixed_voltage_probe(), which calls devm_regulator_register() to register a single new regulator class device for the voltage output - regulator_register() does, among others: - instantiate a new regulator class device (3V3_LCD_ADDON), with parent = regulator-addon-3v3-lcd - adds a devlink (B) with: supplier = 3V3_LCD_ADDON consumer = panel-dsi-lvds At this point we have these devices and devlinks: .---------------------------. | regulator-addon-3v3-lcd | | regulator platform device | supplier consumer | (struct device) |<--------- devlink A -------------. '---------------------------' (inferred) | ^ V | .-----------------. | parent | panel-dsi-lvds | | | (struct device) | | '-----------------' .---------------------------. ^ | 3V3_LCD_ADDON | supplier consumer | | regulator class device |<--------- devlink B -------------' | (struct device) | (created by '---------------------------' regulator core) Depending on whether step 2 happens or not, devlink A will be still present or not during overlay removal. When step 2 happens and devlink A gets dropped (which happens to me almost always), the removal code calls: -> device_release_driver(dev = regulator-addon-3v3-lcd) -> device_release_driver_internal() -> __device_release_driver() -> if (device_links_busy()) // see below { device_links_unbind_consumers(dev = regulator-addon-3v3-lcd) -> for each consumer for which 'dev' is a supplier: { device_release_driver_internal(dev = panel-dsi-lvds) } } The logic is pretty clear: before removing a device that is a supplier to other devices (regulator-addon-3v3-lcd), use devlink to find all consumers (panel-dsi-lvds) and remove them first, recursively. However in case devlink A had been initially dropped, there is no devlink between the two devices. The regulator removal will just proceed, and the regulator device gets removed before its consumer. Note devlink B is not at all within this removal phase. device_links_busy() looks at the platform device (regulator-addon-3v3-lcd), and it has no way to know about the class device (3V3_LCD_ADDON). Assuming the whole device_links_busy() / device_links_unbind_consumers() logic is correct, let's move to why devlink A gets dropped. --------------------------------- Why the devlink is dropped --------------------------------- It all starts in the device_add() for regulator-addon-3v3-lcd: /* * If all driver registration is done and a newly added device doesn't * match with any driver, don't block its consumers from probing in * case the consumer device is able to operate without this supplier. */ if (dev->fwnode && fw_devlink_drv_reg_done && !dev->can_match) fw_devlink_unblock_consumers(dev); The three conditions in the if() mean: 1. this device comes from firmware -> always true in my case (device tree) 2. this global flag is set via the deferred_probe_timeout_work as soon as for 10 consecutive seconds there is no new driver being probed; it is never cleared 3. no driver has been matched with this device so far (IOW the probe function of the driver for this device has never been called, regardless of the return value) If all condtions apply, fw_devlink_unblock_consumers() will (after some checks) call fw_devlink_relax_link() on every link to consumers and "relax" it. Relaxing means setting link flags to DL_FLAG_MANAGED | FW_DEVLINK_FLAGS_PERMISSIVE. Soon later, device_links_driver_bound() will take devlinks with these flags and drop them. I was unable to understand in full detail the flag manipulation logic happening in the devlink code. However I think the high-level logic here can be expressed as: if a devlink was inferred from firmware and its supplier device did not probe after a while (*) because no potential driver was found, then maybe that devlink was wrong or it is enforcing a supplier that is optional for the consumer: let's drop the link and see whether the (formerly devlink consumer) device can now probe. (*) "after a while" is implemented by the fw_devlink_drv_reg_done flag, which typically gets set way less than a minute after boot Basically fw_devlink_drv_reg_done flag splits the probing in two phases. In phase 1 we try to probe all inferred suppliers before probing consumers. Then we set fw_devlink_drv_reg_done and relax+drop the "dangling" inferred devlinks. Then in phase 2 we try to probe without inferred devlinks. This is to see if we can probe more devices due to incorrectly inferred devlinks or missing drivers for optional suppliers. Overlays however can be loaded at any time, even a long time after booting. This is totally normal when used for a hotplug connector, where the devices get physically connected by the user. This implies the fw_devlink_drv_reg_done flag is found already set when probing overlay devices. And so, conditions 1 and 2 above are always set in the overlay case. So we are left with condition 3 only. Again I haven't done a full analysis here, but it is perfectly fine that a driver is not immediately present when adding a new device. It can just have not yet been matched, possibly because a driver module is in process of being loaded from storage. I think there is a race here: on one side the driver becoming available and matched and the device to probe, on the other side the fw_devlink_unblock_consumers() logic to relax and drop inferred devlinks. If the device probes first, the link won't be dropped. --------------------------------- Same problem without DT overlays? --------------------------------- Based on the above, I suspect the exact same problem exists even without any overlay usage. Indeed, the conditions might exist in other corner cases. One example is a device whose driver is a module and is not loaded during boot: e.g. it is not on the root filesystem, it is being developed and the programmer sends the driver via SSH to a tmpfs to load and test it. As said, this is a matter of corner cases, but still possible. Note that no problem should happen to natively removable devices such as USB, because condition 1 defuses the whole if() above for devices not described in firmware. --------------------------------- Fixes I have tried (not working) --------------------------------- I tried a couple approaches based on devlink to fix this issue. One was augmenting the regulator core code to add a new devlink between the regulator platform device (regulator-addon-3v3-lcd) and the regulator class device (3V3_LCD_ADDON), to create a chain for device_links_busy() to follow. The devlink is created and persists until removal time. However it does not enforce the correct ordering: device_links_busy() ignores it because the link status is always "dormant". The reason appears to be that the "regulator output device" is a struct device but never has a driver. Recently Saravana pointed out that: > device links don't work correctly for "class" type devices (https://lore.kernel.org/all/CAGETcx-ioF=jTbyQMeD2fsYKz8q5vw_TWYWS9m8H5=pCo5KFYA@mail.gmail.com/) which is possibly related. I tried a variant: change the devlink already created by _regulator_get() to use the regulator platform device (regulator-addon-3v3-lcd) instead of the regulator class device (3V3_LCD_ADDON) as the supplier. That would make devlink B have the same endpoints as devlink A. However this did not work due to the link state staying "not tracked" and thus again being ignored by device_links_busy(). I haven't managed to find out the flag manipulations that would make it work. --------------------------------- Conclusions --------------------------------- The current logic is clearly OK for "typical" current use cases (not counting corner cases), but unsuitable for hotplugged devices described by firmware. The question is: do we have an underlying assumption that was valid so far but is wrong when overlays are added? One possible answer is: dropping inferred devlinks is wrong. Generally speaking, inferred devlinks are sometimes useless but don't hurt, so there is no need to drop them. This is what this patch changes. However I realize there is a use case for dropping inferred devlink: optional suppliers that prevent consumer probing until they are dropped. Indeed, inferring devlinks from firmware data can create links that prevent some device to probe. For this reason my first attempts have been to add or change the devlinks that subsystem code creates. So a more sophisticated idea is that after phase 1 we try to probe all not-probed-yet consumers ignoring the relaxed devlinks, instead of removing them. This would allow the same amount of devices to be probed using the same amount of optional suppliers, but leaving the inferred devlinks in place because they might be useful later on. And then of course there are the above solutions I failed to get working, which might be the right way but need some directions for me to have them working. I am very open to more answers and suggestions. Best regards, Luca Signed-off-by: Luca Ceresoli --- This patch first appeared in v3. --- drivers/base/core.c | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/drivers/base/core.c b/drivers/base/core.c index 5c4eebcd198b..024f189fa0a0 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -1875,19 +1875,6 @@ void __init wait_for_init_devices_probe(void) fw_devlink_best_effort = false; } -static void fw_devlink_unblock_consumers(struct device *dev) -{ - struct device_link *link; - - if (!fw_devlink_flags || fw_devlink_is_permissive()) - return; - - device_links_write_lock(); - list_for_each_entry(link, &dev->links.consumers, s_node) - fw_devlink_relax_link(link); - device_links_write_unlock(); -} - #define get_dev_from_fwnode(fwnode) get_device((fwnode)->dev) static bool fwnode_init_without_drv(struct fwnode_handle *fwnode) @@ -3679,14 +3666,6 @@ int device_add(struct device *dev) bus_probe_device(dev); - /* - * If all driver registration is done and a newly added device doesn't - * match with any driver, don't block its consumers from probing in - * case the consumer device is able to operate without this supplier. - */ - if (dev->fwnode && fw_devlink_drv_reg_done && !dev->can_match) - fw_devlink_unblock_consumers(dev); - if (parent) klist_add_tail(&dev->p->knode_parent, &parent->p->klist_children);