From patchwork Thu Jan 5 13:24:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pin-yen Lin X-Patchwork-Id: 639489 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2DDB7C54EBD for ; Thu, 5 Jan 2023 13:25:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233426AbjAENZ2 (ORCPT ); Thu, 5 Jan 2023 08:25:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234043AbjAENZV (ORCPT ); Thu, 5 Jan 2023 08:25:21 -0500 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66E9A392DA for ; Thu, 5 Jan 2023 05:25:20 -0800 (PST) Received: by mail-pj1-x1033.google.com with SMTP id n12so26947504pjp.1 for ; Thu, 05 Jan 2023 05:25:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1hqQOkKrItwHNX5v+5p8BbzfdB8bkg8Yca4jGeyjDgg=; b=ShnfgUSOXuCGjRuna6wTL6cMaiNo15jKbthJwNrqZDEoFWjV+y52Bky++fVGKWPNxm TSdKdMVhcW3JgNP8dNM2EKQqaSXZgCti2M+wYScNBPeL3ExWbgqWeNvI7nKzg+eh/rJv IZAWA8zf44oLxLGeGCLsIrMHdbHb/gXBWUTYs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1hqQOkKrItwHNX5v+5p8BbzfdB8bkg8Yca4jGeyjDgg=; b=AyRbMae378yobY7Au7OjGg5m3bsrE1POSH1TX4FAJgfIySGx1waN056U93Kg0jIYl9 x3Xmk9MoKwZKEuhspqxETAIe8AykkgU+/kH2dQxum3rFzBuOQcgZpNapJU+lBBhOxKuM j7+ysRQxlQHEZo/VuUXIF50Uilnb3cb8ep0EFf7cy+jza93eR73j3rirbqFaqOtHHXIb dt+MAG31W9P8nCld8S38wuLmF5vx8zXtiJL3sAArG+2ZsAwKk+GOJLJ/QKZSRXB801nQ hiCXBbULtJMNhQ0jehsi17RWj2dOXK8Bdh5Im46LbNv8SHt0khmoNTjtsjR9z9xjakSe b0UA== X-Gm-Message-State: AFqh2kobmOYURgB+xtymrJcP0M3QA3u5Pw+UhcR+zDHIKRN2ADR6M1a2 oXpq05LBiYDFzT5bENX7z5TO9A== X-Google-Smtp-Source: AMrXdXs2rSmGWZCqtd8p+t21jfexuxiaORDcdvHuQTqxS2qgF6MSOKcW+gdNFTSY78GsG4nyx34fPg== X-Received: by 2002:a17:90b:35d0:b0:225:f793:ab2d with SMTP id nb16-20020a17090b35d000b00225f793ab2dmr36398951pjb.46.1672925120095; Thu, 05 Jan 2023 05:25:20 -0800 (PST) Received: from treapking.tpe.corp.google.com ([2401:fa00:1:10:7a61:eb85:2e3:2bd0]) by smtp.gmail.com with ESMTPSA id gk22-20020a17090b119600b00225e670e4c7sm1372682pjb.35.2023.01.05.05.25.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jan 2023 05:25:19 -0800 (PST) From: Pin-yen Lin To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , David Airlie , Daniel Vetter , Rob Herring , Krzysztof Kozlowski , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J . Wysocki" , Prashant Malani , Benson Leung , Guenter Roeck Cc: =?utf-8?q?N=C3=ADcolas_F_=2E_R_=2E_A_=2E_Prado?= , Xin Ji , AngeloGioacchino Del Regno , Thomas Zimmermann , Hsin-Yi Wang , linux-kernel@vger.kernel.org, Allen Chen , linux-acpi@vger.kernel.org, Lyude Paul , dri-devel@lists.freedesktop.org, chrome-platform@lists.linux.dev, Pin-yen Lin , Javier Martinez Canillas , Marek Vasut , devicetree@vger.kernel.org, Stephen Boyd Subject: [PATCH v7 2/9] platform/chrome: cros_ec_typec: Purge blocking switch devlinks Date: Thu, 5 Jan 2023 21:24:50 +0800 Message-Id: <20230105132457.4125372-3-treapking@chromium.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog In-Reply-To: <20230105132457.4125372-1-treapking@chromium.org> References: <20230105132457.4125372-1-treapking@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Prashant Malani When using OF graph, the fw_devlink code will create links between the individual port driver (cros-ec-typec here) and the parent device for a Type-C switch (like mode-switch). Since the mode-switch will in turn have the usb-c-connector (i.e the child of the port driver) as a supplier, fw_devlink will not be able to resolve the cyclic dependency correctly. As a result, the mode-switch driver probe() never runs, so mode-switches are never registered. Because of that, the port driver probe constantly fails with -EPROBE_DEFER, because the Type-C connector class requires all switch devices to be registered prior to port registration. To break this deadlock and allow the mode-switch registration to occur, purge all the usb-c-connector nodes' absent suppliers. This eliminates the connector as a supplier for a switch and allows it to be probed. Signed-off-by: Prashant Malani Signed-off-by: Pin-yen Lin --- Changes in v7: - Fix the long comment lines Changes in v6: - New in v6 drivers/platform/chrome/cros_ec_typec.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c index 2a7ff14dc37e..30cf03c2e95d 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -382,6 +382,16 @@ static int cros_typec_init_ports(struct cros_typec_data *typec) return -EINVAL; } + /* + * OF graph may have set up some device links with switches, since + * connectors have their own compatible. Purge these to avoid a deadlock + * in switch probe (the switch mistakenly assumes the connector is a + * supplier). + */ + if (dev->of_node) + device_for_each_child_node(dev, fwnode) + fw_devlink_purge_absent_suppliers(fwnode); + /* DT uses "reg" to specify port number. */ port_prop = dev->of_node ? "reg" : "port-number"; device_for_each_child_node(dev, fwnode) { From patchwork Thu Jan 5 13:24:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pin-yen Lin X-Patchwork-Id: 639488 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 643FDC54E76 for ; Thu, 5 Jan 2023 13:26:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233363AbjAENZ7 (ORCPT ); Thu, 5 Jan 2023 08:25:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233674AbjAENZe (ORCPT ); Thu, 5 Jan 2023 08:25:34 -0500 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35403392CE for ; Thu, 5 Jan 2023 05:25:33 -0800 (PST) Received: by mail-pj1-x102c.google.com with SMTP id z9-20020a17090a468900b00226b6e7aeeaso2011564pjf.1 for ; Thu, 05 Jan 2023 05:25:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bqO6o8ZziGkIoOqjoSOzWXc91CpV6gR03ce64pYL0vM=; b=YcKvS+Lp0xVVZn/icmzAmy07hYJkl0Oy97nHOC/lY3pcQt+0deVNdyXj80mprqXVHo JXSuy529B9n57Jgb67pU45VqmzF+xKVFXBvZolr/V07B1wPzMCpQlVQzVvwCyb+HwVXj 5ukmVlTY1j56EYdU2w1gdVCaQfX7rxXJJWMFE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bqO6o8ZziGkIoOqjoSOzWXc91CpV6gR03ce64pYL0vM=; b=sOPvXF4buQv/00GKGz/Ru7YWr5PjBz3ti8oM6Bt0ISRrOPkHCksYiS0TIpK7QdMrze vEUy6hq1HBsz6ja1hAL8LUSS01F6xmyxZsagwd3HTmacR9L/Ta70uXLth74dGlTf6muP U0S1idjCzZi7GuRdCTgMfnJ+kC5p3C5cx/Bx2GNU0XPjsaR34Pd55Uq5FCCyOvFObZHG EAStgQgeeYBtAoTwWcI6NOJ+vZqEGHLAc7DOoA315YkJ/QcpcV5c4o/P0TSJ8Q08zOzf oIzXo81SIsbW3D4SZ2CIOPTz4M0s5zNW6fSwCaQAkls3/zMOxMP1q7J0Q6v8PUDRZpEo HOGw== X-Gm-Message-State: AFqh2kouUe/L4y3TL268CN/qA4OTZ2pt/WjO6XAb01VMaUtEBhBWOhYL NeR8/jvjvFtBtbopgBbZDJ99sw== X-Google-Smtp-Source: AMrXdXsTZ912ZfoZw5BCFpbbUQxnFTjLsLf/PBTkCVcY+h6lA8ALjaBDMaumoybWeZcPwt4nYVJb8w== X-Received: by 2002:a17:90b:698:b0:226:9982:70c9 with SMTP id m24-20020a17090b069800b00226998270c9mr10455808pjz.30.1672925132647; Thu, 05 Jan 2023 05:25:32 -0800 (PST) Received: from treapking.tpe.corp.google.com ([2401:fa00:1:10:7a61:eb85:2e3:2bd0]) by smtp.gmail.com with ESMTPSA id gk22-20020a17090b119600b00225e670e4c7sm1372682pjb.35.2023.01.05.05.25.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jan 2023 05:25:32 -0800 (PST) From: Pin-yen Lin To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , David Airlie , Daniel Vetter , Rob Herring , Krzysztof Kozlowski , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J . Wysocki" , Prashant Malani , Benson Leung , Guenter Roeck Cc: =?utf-8?q?N=C3=ADcolas_F_=2E_R_=2E_A_=2E_Prado?= , Xin Ji , AngeloGioacchino Del Regno , Thomas Zimmermann , Hsin-Yi Wang , linux-kernel@vger.kernel.org, Allen Chen , linux-acpi@vger.kernel.org, Lyude Paul , dri-devel@lists.freedesktop.org, chrome-platform@lists.linux.dev, Pin-yen Lin , Javier Martinez Canillas , Marek Vasut , devicetree@vger.kernel.org, Stephen Boyd Subject: [PATCH v7 4/9] dt-bindings: drm/bridge: anx7625: Add mode-switch support Date: Thu, 5 Jan 2023 21:24:52 +0800 Message-Id: <20230105132457.4125372-5-treapking@chromium.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog In-Reply-To: <20230105132457.4125372-1-treapking@chromium.org> References: <20230105132457.4125372-1-treapking@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Analogix 7625 can be used in systems to switch the DP traffic between two downstreams, which can be USB Type-C DisplayPort alternate mode lane or regular DisplayPort output ports. Update the binding to accommodate this usage by introducing a data-lanes and a mode-switch property on endpoints. Also include the link to the product brief in the bindings. Signed-off-by: Pin-yen Lin --- Changes in v7: - Fixed issues reported by dt_binding_check - Updated the schema and the example dts for data-lanes. - Changed to generic naming for the example dts node. Changes in v6: - Remove switches node and use endpoints and data-lanes property to describe the connections. .../display/bridge/analogix,anx7625.yaml | 101 +++++++++++++++++- 1 file changed, 98 insertions(+), 3 deletions(-) diff --git a/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml b/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml index 4590186c4a0b..536dbe8eaf60 100644 --- a/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml +++ b/Documentation/devicetree/bindings/display/bridge/analogix,anx7625.yaml @@ -12,7 +12,8 @@ maintainers: description: | The ANX7625 is an ultra-low power 4K Mobile HD Transmitter - designed for portable devices. + designed for portable devices. Product brief is available at + https://www.analogix.com/en/system/files/AA-002291-PB-6-ANX7625_ProductBrief.pdf properties: compatible: @@ -112,10 +113,50 @@ properties: data-lanes: true port@1: - $ref: /schemas/graph.yaml#/properties/port + $ref: /schemas/graph.yaml#/$defs/port-base description: Video port for panel or connector. + patternProperties: + "^endpoint@[01]$": + $ref: /schemas/graph.yaml#/$defs/endpoint-base + unevaluatedProperties: false + + properties: + reg: + maxItems: 1 + + remote-endpoint: true + + data-lanes: + oneOf: + - minItems: 1 + maxItems: 1 + items: + enum: [0, 1, 2, 3] + + - items: + - const: 0 + - const: 1 + + - items: + - const: 2 + - const: 3 + + - items: + - const: 0 + - const: 1 + - const: 2 + - const: 3 + + mode-switch: + type: boolean + description: Register this node as a Type-C mode switch or not. + + required: + - reg + - remote-endpoint + required: - port@0 - port@1 @@ -164,8 +205,12 @@ examples: }; mipi2dp_bridge_out: port@1 { + #address-cells = <1>; + #size-cells = <0>; + reg = <1>; - anx7625_out: endpoint { + anx7625_out: endpoint@0 { + reg = <0>; remote-endpoint = <&panel_in>; }; }; @@ -186,3 +231,53 @@ examples: }; }; }; + - | + i2c3 { + #address-cells = <1>; + #size-cells = <0>; + + encoder@58 { + compatible = "analogix,anx7625"; + reg = <0x58>; + pinctrl-names = "default"; + pinctrl-0 = <&anx7625_dp_pins>; + enable-gpios = <&pio 176 GPIO_ACTIVE_HIGH>; + reset-gpios = <&pio 177 GPIO_ACTIVE_HIGH>; + vdd10-supply = <&pp1100_dpbrdg>; + vdd18-supply = <&pp1800_dpbrdg_dx>; + vdd33-supply = <&pp3300_dpbrdg_dx>; + analogix,audio-enable; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + anx7625_dp_in: endpoint { + bus-type = <7>; + remote-endpoint = <&dpi_out>; + }; + }; + + port@1 { + #address-cells = <1>; + #size-cells = <0>; + + reg = <1>; + anx_typec0: endpoint@0 { + reg = <0>; + mode-switch; + data-lanes = <0 1>; + remote-endpoint = <&typec_port0>; + }; + anx_typec1: endpoint@1 { + reg = <1>; + mode-switch; + data-lanes = <2 3>; + remote-endpoint = <&typec_port1>; + }; + }; + }; + }; + }; From patchwork Thu Jan 5 13:24:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pin-yen Lin X-Patchwork-Id: 639487 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 07A6BC54EBF for ; Thu, 5 Jan 2023 13:26:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233756AbjAEN0D (ORCPT ); Thu, 5 Jan 2023 08:26:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233781AbjAENZr (ORCPT ); Thu, 5 Jan 2023 08:25:47 -0500 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED0CF392CD for ; Thu, 5 Jan 2023 05:25:45 -0800 (PST) Received: by mail-pj1-x1030.google.com with SMTP id h7-20020a17090aa88700b00225f3e4c992so2033825pjq.1 for ; Thu, 05 Jan 2023 05:25:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jwazAT3xSqlENEhA4Hb3uCHKQB6Uz2GRMq6wM/0+luw=; b=g/RgxtrwuPP6cH6ICV+A6rBkTivvevCaa+khZPHbYDr4YLDNIxnG7Z+qd973LPSR52 sD6v7xWHifD5y8A93/lBlXezvT3J/aF5uVyY29bbOxr/pQGGWHxEeGHJTk6TbYO9AFZC 0d3fF9cdnbRj3tX2ci2YwtFsUHxTS50KbBHYY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jwazAT3xSqlENEhA4Hb3uCHKQB6Uz2GRMq6wM/0+luw=; b=fb8JPFrvA9v8cZpm5Nhqils2c2BnrdfU00T1BL6Q4uidoLtff+cPaWF6B7eXhPU9Cz J5+NIznvcTQeAyeWQCd9brpFX92eCIcCssZXepjvg4AweMRMnRgT4bPHVRHAco4gEsE3 pB7pNuenhLr2j1EZ1Xfa5uATjAsH7Au5lZxYfjoZw9gWJWDuqgZLqeqWz7VKXVNlB830 52IBQ3aeW0FyJx6tza3ZVtw79BUVkTor2IxzquO7DQiB59ybPU3khZkoysModbeV4wZk aTuH3DC2r0RcfzOTHm4H8iq2419xSm/W5bi/C2kNVSe5IQeQUpnTC+W2MumLB+ppEq+2 CQBg== X-Gm-Message-State: AFqh2koDWKNqGxmpVuEBVI9e0fk21B9LwGdysvDz7LCm+uDNNaHTdqei yOC0y1HBU+iEKYxjCtB4RWWqjQ== X-Google-Smtp-Source: AMrXdXsauXU8ihD1CPxPhxZocim3FvOFINpzc1qf6ZPu2Mf9DY+6Aymp5YhOTJ947preLdJEkZv66g== X-Received: by 2002:a17:90b:3d0e:b0:226:59d6:e824 with SMTP id pt14-20020a17090b3d0e00b0022659d6e824mr20193681pjb.48.1672925145331; Thu, 05 Jan 2023 05:25:45 -0800 (PST) Received: from treapking.tpe.corp.google.com ([2401:fa00:1:10:7a61:eb85:2e3:2bd0]) by smtp.gmail.com with ESMTPSA id gk22-20020a17090b119600b00225e670e4c7sm1372682pjb.35.2023.01.05.05.25.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jan 2023 05:25:45 -0800 (PST) From: Pin-yen Lin To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , David Airlie , Daniel Vetter , Rob Herring , Krzysztof Kozlowski , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J . Wysocki" , Prashant Malani , Benson Leung , Guenter Roeck Cc: =?utf-8?q?N=C3=ADcolas_F_=2E_R_=2E_A_=2E_Prado?= , Xin Ji , AngeloGioacchino Del Regno , Thomas Zimmermann , Hsin-Yi Wang , linux-kernel@vger.kernel.org, Allen Chen , linux-acpi@vger.kernel.org, Lyude Paul , dri-devel@lists.freedesktop.org, chrome-platform@lists.linux.dev, Pin-yen Lin , Javier Martinez Canillas , Marek Vasut , devicetree@vger.kernel.org, Stephen Boyd Subject: [PATCH v7 6/9] drm/bridge: anx7625: Register Type C mode switches Date: Thu, 5 Jan 2023 21:24:54 +0800 Message-Id: <20230105132457.4125372-7-treapking@chromium.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog In-Reply-To: <20230105132457.4125372-1-treapking@chromium.org> References: <20230105132457.4125372-1-treapking@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Register USB Type-C mode switches when the "mode-switch" property and relevant port are available in Device Tree. Configure the crosspoint switch based on the entered alternate mode for a specific Type-C connector. Signed-off-by: Pin-yen Lin --- Changes in v7: - Fixed style issues in anx7625 driver - Removed DT property validation in anx7625 driver. - Extracted common codes to another commit. Changes in v6: - Squashed to a single patch drivers/gpu/drm/bridge/analogix/Kconfig | 1 + drivers/gpu/drm/bridge/analogix/anx7625.c | 88 +++++++++++++++++++++++ drivers/gpu/drm/bridge/analogix/anx7625.h | 13 ++++ 3 files changed, 102 insertions(+) diff --git a/drivers/gpu/drm/bridge/analogix/Kconfig b/drivers/gpu/drm/bridge/analogix/Kconfig index 173dada218ec..992b43ed1dd7 100644 --- a/drivers/gpu/drm/bridge/analogix/Kconfig +++ b/drivers/gpu/drm/bridge/analogix/Kconfig @@ -34,6 +34,7 @@ config DRM_ANALOGIX_ANX7625 tristate "Analogix Anx7625 MIPI to DP interface support" depends on DRM depends on OF + depends on TYPEC || TYPEC=n select DRM_DISPLAY_DP_HELPER select DRM_DISPLAY_HDCP_HELPER select DRM_DISPLAY_HELPER diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c b/drivers/gpu/drm/bridge/analogix/anx7625.c index 1cf242130b91..2bb504a8d789 100644 --- a/drivers/gpu/drm/bridge/analogix/anx7625.c +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include #include @@ -2572,6 +2574,86 @@ static void anx7625_runtime_disable(void *data) pm_runtime_disable(data); } +static void anx7625_set_crosspoint_switch(struct anx7625_data *ctx, + enum typec_orientation orientation) +{ + if (orientation == TYPEC_ORIENTATION_NORMAL) { + anx7625_reg_write(ctx, ctx->i2c.tcpc_client, TCPC_SWITCH_0, + SW_SEL1_SSRX_RX1 | SW_SEL1_DPTX0_RX2); + anx7625_reg_write(ctx, ctx->i2c.tcpc_client, TCPC_SWITCH_1, + SW_SEL2_SSTX_TX1 | SW_SEL2_DPTX1_TX2); + } else if (orientation == TYPEC_ORIENTATION_REVERSE) { + anx7625_reg_write(ctx, ctx->i2c.tcpc_client, TCPC_SWITCH_0, + SW_SEL1_SSRX_RX2 | SW_SEL1_DPTX0_RX1); + anx7625_reg_write(ctx, ctx->i2c.tcpc_client, TCPC_SWITCH_1, + SW_SEL2_SSTX_TX2 | SW_SEL2_DPTX1_TX1); + } +} + +static void anx7625_typec_two_ports_update(struct anx7625_data *ctx) +{ + struct drm_dp_typec_switch_desc switch_desc = ctx->switch_desc; + /* Check if both ports available and do nothing to retain the current one */ + if (switch_desc.typec_ports[0].dp_connected && switch_desc.typec_ports[1].dp_connected) + return; + + if (switch_desc.typec_ports[0].dp_connected) + anx7625_set_crosspoint_switch(ctx, TYPEC_ORIENTATION_NORMAL); + else if (switch_desc.typec_ports[1].dp_connected) + anx7625_set_crosspoint_switch(ctx, TYPEC_ORIENTATION_REVERSE); +} + +static int anx7625_typec_mux_set(struct typec_mux_dev *mux, + struct typec_mux_state *state) +{ + struct drm_dp_typec_port_data *port_data = typec_mux_get_drvdata(mux); + struct anx7625_data *ctx = (struct anx7625_data *) port_data->data; + struct device *dev = &ctx->client->dev; + struct drm_dp_typec_switch_desc switch_desc = ctx->switch_desc; + bool new_dp_connected, old_dp_connected; + + if (switch_desc.num_typec_switches == 1) + return 0; + + old_dp_connected = switch_desc.typec_ports[0].dp_connected || + switch_desc.typec_ports[1].dp_connected; + + port_data->dp_connected = state->alt && + state->alt->svid == USB_TYPEC_DP_SID && + state->alt->mode == USB_TYPEC_DP_MODE; + + dev_dbg(dev, "mux_set dp_connected: c0=%d, c1=%d\n", + switch_desc.typec_ports[0].dp_connected, switch_desc.typec_ports[1].dp_connected); + + new_dp_connected = switch_desc.typec_ports[0].dp_connected || + switch_desc.typec_ports[1].dp_connected; + + /* dp on, power on first */ + if (!old_dp_connected && new_dp_connected) + pm_runtime_get_sync(dev); + + anx7625_typec_two_ports_update(ctx); + + /* dp off, power off last */ + if (old_dp_connected && !new_dp_connected) + pm_runtime_put_sync(dev); + + return 0; +} + +static void anx7625_unregister_typec_switches(struct anx7625_data *ctx) +{ + drm_dp_unregister_typec_switches(&ctx->switch_desc); +} + +static int anx7625_register_typec_switches(struct device *dev, struct anx7625_data *ctx) +{ + struct device_node *port = of_graph_get_port_by_id(dev->of_node, 1); + + return drm_dp_register_typec_switches(dev, port, &ctx->switch_desc, + ctx, anx7625_typec_mux_set); +} + static int anx7625_i2c_probe(struct i2c_client *client) { struct anx7625_data *platform; @@ -2679,6 +2761,10 @@ static int anx7625_i2c_probe(struct i2c_client *client) if (platform->pdata.intp_irq) queue_work(platform->workqueue, &platform->work); + ret = anx7625_register_typec_switches(dev, platform); + if (ret && ret != -ENODEV) + dev_warn(dev, "Didn't register Type-C switches, err: %d\n", ret); + platform->bridge.funcs = &anx7625_bridge_funcs; platform->bridge.of_node = client->dev.of_node; if (!anx7625_of_panel_on_aux_bus(&client->dev)) @@ -2730,6 +2816,8 @@ static void anx7625_i2c_remove(struct i2c_client *client) drm_bridge_remove(&platform->bridge); + anx7625_unregister_typec_switches(platform); + if (platform->pdata.intp_irq) destroy_workqueue(platform->workqueue); diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.h b/drivers/gpu/drm/bridge/analogix/anx7625.h index 14f33d6be289..38abbd3d6b36 100644 --- a/drivers/gpu/drm/bridge/analogix/anx7625.h +++ b/drivers/gpu/drm/bridge/analogix/anx7625.h @@ -55,6 +55,18 @@ #define HPD_STATUS_CHANGE 0x80 #define HPD_STATUS 0x80 +#define TCPC_SWITCH_0 0xB4 +#define SW_SEL1_DPTX0_RX2 BIT(0) +#define SW_SEL1_DPTX0_RX1 BIT(1) +#define SW_SEL1_SSRX_RX2 BIT(4) +#define SW_SEL1_SSRX_RX1 BIT(5) + +#define TCPC_SWITCH_1 0xB5 +#define SW_SEL2_DPTX1_TX2 BIT(0) +#define SW_SEL2_DPTX1_TX1 BIT(1) +#define SW_SEL2_SSTX_TX2 BIT(4) +#define SW_SEL2_SSTX_TX1 BIT(5) + /******** END of I2C Address 0x58 ********/ /***************************************************************/ @@ -479,6 +491,7 @@ struct anx7625_data { struct drm_connector *connector; struct mipi_dsi_device *dsi; struct drm_dp_aux aux; + struct drm_dp_typec_switch_desc switch_desc; }; #endif /* __ANX7625_H__ */ From patchwork Thu Jan 5 13:24:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pin-yen Lin X-Patchwork-Id: 639486 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8BA47C54EBD for ; Thu, 5 Jan 2023 13:27:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233662AbjAEN0b (ORCPT ); Thu, 5 Jan 2023 08:26:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233797AbjAEN0C (ORCPT ); Thu, 5 Jan 2023 08:26:02 -0500 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A534E1BC for ; Thu, 5 Jan 2023 05:25:51 -0800 (PST) Received: by mail-pj1-x1034.google.com with SMTP id v23so39839018pju.3 for ; Thu, 05 Jan 2023 05:25:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Iwwp3U8ZO9l33wBPdYbUslPJS4OdAaqOipDsvKHUvw4=; b=NFmtJxruhfDGIscARXxUxMnJ8bIDMuz6GQyFZIJpUMR2vjBWuzVlo1Ntr6U0LjVom8 jNDEYi1Y1rKoBEpPcsjuNym42klClmWKmfb42EidVOf3/eE3lt8Bnzioy5yhIIV+BvO6 1wLN3JL8YsKkZ758whFfLrA/OYsJfIEyGxDUg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Iwwp3U8ZO9l33wBPdYbUslPJS4OdAaqOipDsvKHUvw4=; b=PRfjtA2CCo/YZzoJglYMpgmRlBj3gq9DF5H67f9CK2SssC1vbL8UZJ27LElcw7jFG2 yyDfkKH9sziC8VJClPpwu1dHESdZ3YaMi+jw6MZrfb2+o1ST0GQSxHdbAX89Lh3TjqsQ jW+6YlsEFQeCvRWM79avc+uswZliamg+NRWP86PuW96DuOzjjkkmqh5jdFmxf1cDL78P /aG/zX4zg0wNZHqrhpxPyLqFBExMSwWcRognIXtAK7byIPuBx9292higYFNYxtCmTLAu OoEiNndsGxVo5wVCvowTrpzeq6mEvAo4X+GhGhK5IZ2ThhnBErFt2t5AFYs0JxKt/37l uAgQ== X-Gm-Message-State: AFqh2konTrePIt5dVWrcKxPpGwlI6l+li0Ne9uzMm8CFTmchXZfZaUjt KAZMfQhjvHATHqkSY3TKhMHIEA== X-Google-Smtp-Source: AMrXdXsVgq9H0r6nMlqdgVJ8rT31POYJpyYs+lssnDycN2WN43sj16tzoY0ymo5PnPD/iwAfQxhzwg== X-Received: by 2002:a17:90b:3797:b0:226:3981:1ae3 with SMTP id mz23-20020a17090b379700b0022639811ae3mr24411009pjb.28.1672925151173; Thu, 05 Jan 2023 05:25:51 -0800 (PST) Received: from treapking.tpe.corp.google.com ([2401:fa00:1:10:7a61:eb85:2e3:2bd0]) by smtp.gmail.com with ESMTPSA id gk22-20020a17090b119600b00225e670e4c7sm1372682pjb.35.2023.01.05.05.25.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jan 2023 05:25:50 -0800 (PST) From: Pin-yen Lin To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , David Airlie , Daniel Vetter , Rob Herring , Krzysztof Kozlowski , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J . Wysocki" , Prashant Malani , Benson Leung , Guenter Roeck Cc: =?utf-8?q?N=C3=ADcolas_F_=2E_R_=2E_A_=2E_Prado?= , Xin Ji , AngeloGioacchino Del Regno , Thomas Zimmermann , Hsin-Yi Wang , linux-kernel@vger.kernel.org, Allen Chen , linux-acpi@vger.kernel.org, Lyude Paul , dri-devel@lists.freedesktop.org, chrome-platform@lists.linux.dev, Pin-yen Lin , Javier Martinez Canillas , Marek Vasut , devicetree@vger.kernel.org, Stephen Boyd Subject: [PATCH v7 7/9] dt/bindings: drm/bridge: it6505: Add mode-switch support Date: Thu, 5 Jan 2023 21:24:55 +0800 Message-Id: <20230105132457.4125372-8-treapking@chromium.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog In-Reply-To: <20230105132457.4125372-1-treapking@chromium.org> References: <20230105132457.4125372-1-treapking@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org ITE IT6505 can be used in systems to switch the DP traffic between two downstreams, which can be USB Type-C DisplayPort alternate mode lane or regular DisplayPort output ports. Update the binding to accommodate this usage by introducing a data-lanes and a mode-switch property on endpoints. Signed-off-by: Pin-yen Lin --- Changes in v7: - Fixed issues reported by dt_binding_check. - Updated the schema and the example dts for data-lanes. - Changed to generic naming for the example dts node. Changes in v6: - Remove switches node and use endpoints and data-lanes property to describe the connections. .../bindings/display/bridge/ite,it6505.yaml | 95 ++++++++++++++++--- 1 file changed, 84 insertions(+), 11 deletions(-) diff --git a/Documentation/devicetree/bindings/display/bridge/ite,it6505.yaml b/Documentation/devicetree/bindings/display/bridge/ite,it6505.yaml index b16a9d9127dd..1ee7cd0d2035 100644 --- a/Documentation/devicetree/bindings/display/bridge/ite,it6505.yaml +++ b/Documentation/devicetree/bindings/display/bridge/ite,it6505.yaml @@ -77,20 +77,45 @@ properties: unevaluatedProperties: false description: Video port for DP output - properties: - endpoint: + patternProperties: + "^endpoint@[01]$": $ref: /schemas/graph.yaml#/$defs/endpoint-base unevaluatedProperties: false properties: + reg: + maxItems: 1 + + remote-endpoint: true + data-lanes: - minItems: 1 - uniqueItems: true - items: - - enum: [ 0, 1 ] - - const: 1 - - const: 2 - - const: 3 + oneOf: + - minItems: 1 + maxItems: 1 + items: + enum: [0, 1, 2, 3] + + - items: + - const: 0 + - const: 1 + + - items: + - const: 2 + - const: 3 + + - items: + - const: 0 + - const: 1 + - const: 2 + - const: 3 + + mode-switch: + type: boolean + description: Register this node as a Type-C mode switch or not. + + required: + - reg + - remote-endpoint required: - port@0 @@ -102,7 +127,6 @@ required: - pwr18-supply - interrupts - reset-gpios - - extcon - ports additionalProperties: false @@ -139,8 +163,11 @@ examples: }; port@1 { + #address-cells = <1>; + #size-cells = <0>; reg = <1>; - it6505_out: endpoint { + it6505_out: endpoint@0 { + reg = <0>; remote-endpoint = <&dp_in>; data-lanes = <0 1>; }; @@ -148,3 +175,49 @@ examples: }; }; }; + - | + #include + + i2c3 { + #address-cells = <1>; + #size-cells = <0>; + + dp-bridge@5c { + compatible = "ite,it6505"; + interrupts = <8 IRQ_TYPE_LEVEL_LOW 8 0>; + reg = <0x5c>; + pinctrl-names = "default"; + pinctrl-0 = <&it6505_pins>; + ovdd-supply = <&mt6366_vsim2_reg>; + pwr18-supply = <&pp1800_dpbrdg_dx>; + reset-gpios = <&pio 177 0>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + port@0 { + reg = <0>; + it6505_dpi_in: endpoint { + remote-endpoint = <&dpi_out>; + }; + }; + port@1 { + #address-cells = <1>; + #size-cells = <0>; + reg = <1>; + ite_typec0: endpoint@0 { + reg = <0>; + mode-switch; + data-lanes = <0 1>; + remote-endpoint = <&typec_port0>; + }; + ite_typec1: endpoint@1 { + reg = <1>; + mode-switch; + data-lanes = <2 3>; + remote-endpoint = <&typec_port1>; + }; + }; + }; + }; + }; From patchwork Thu Jan 5 13:24:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pin-yen Lin X-Patchwork-Id: 639485 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6231AC3DA7A for ; Thu, 5 Jan 2023 13:27:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233781AbjAEN1B (ORCPT ); Thu, 5 Jan 2023 08:27:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233870AbjAEN0F (ORCPT ); Thu, 5 Jan 2023 08:26:05 -0500 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C843C37 for ; Thu, 5 Jan 2023 05:26:03 -0800 (PST) Received: by mail-pj1-x102c.google.com with SMTP id z4-20020a17090a170400b00226d331390cso905261pjd.5 for ; Thu, 05 Jan 2023 05:26:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fc4dD/OSI6AqbJN6YW1eI7+8gfamDs+/wg3E3xEDFpk=; b=ilDKqTMCwbDsM/lv+BsibAMEc7MfUxkjTAzYnzjGW2+rIv6FFQbbaXmBYJ7Eo/oa7s SyrbqLiZMOSyHLmInSxl0JwTdGvvxkuYV1siaWprQ9kU5KaeOfNdlwrir300ixSDzssE alY0xIq2WeyEPVosjG2SfMIOr9zkKgCD3UHwg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fc4dD/OSI6AqbJN6YW1eI7+8gfamDs+/wg3E3xEDFpk=; b=a+L5COkji90NYmvjGEk+uy69/8c5rVnMZY5bF9YREJRssqufrwN6Xbs5V7Iimqln1l nzEVHz7hSXvqliDae4bG6NDFWn08jQmFHB5wyeIWX0/7vd9VA2BneWtsCCiQ7TdPYiDU 66EJk3qp4zsH3hUWNHIwqsbZ/qgIeK3oO42yfLG2EIQoBZsPxdyiK9Bg/o5n+UKd1gE/ TN9Y40d4bP4DE6AQkgSpBjdWaxaTwaCC3+t+LByntaJKJzQL110KvHmk+wtQx4dAEpM5 8jUS1MRoxS042+MWuBBQOq/N1Z9dfaPw4oui+N5EjpYmr19KOe4erZUkWFmscpcrxErg NZSA== X-Gm-Message-State: AFqh2ko5RbTC3FZtgJgKsxUsFbZSoqVPXkBGMRF9iX8zs/y4vd9SOZH5 cwhB/hbV1B+pSqb5U3+Olq/bvQ== X-Google-Smtp-Source: AMrXdXuqaC7MI7vTBvMovZr57wepZh7B/ugct7iXMnFx/sRimRJd0yTpskFUwNzpcePam0sInKQhyw== X-Received: by 2002:a17:90b:a15:b0:226:23c7:bb39 with SMTP id gg21-20020a17090b0a1500b0022623c7bb39mr27981382pjb.44.1672925162905; Thu, 05 Jan 2023 05:26:02 -0800 (PST) Received: from treapking.tpe.corp.google.com ([2401:fa00:1:10:7a61:eb85:2e3:2bd0]) by smtp.gmail.com with ESMTPSA id gk22-20020a17090b119600b00225e670e4c7sm1372682pjb.35.2023.01.05.05.25.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jan 2023 05:26:02 -0800 (PST) From: Pin-yen Lin To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , David Airlie , Daniel Vetter , Rob Herring , Krzysztof Kozlowski , Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J . Wysocki" , Prashant Malani , Benson Leung , Guenter Roeck Cc: =?utf-8?q?N=C3=ADcolas_F_=2E_R_=2E_A_=2E_Prado?= , Xin Ji , AngeloGioacchino Del Regno , Thomas Zimmermann , Hsin-Yi Wang , linux-kernel@vger.kernel.org, Allen Chen , linux-acpi@vger.kernel.org, Lyude Paul , dri-devel@lists.freedesktop.org, chrome-platform@lists.linux.dev, Pin-yen Lin , Javier Martinez Canillas , Marek Vasut , devicetree@vger.kernel.org, Stephen Boyd Subject: [PATCH v7 9/9] drm/bridge: it6505: Register Type C mode switches Date: Thu, 5 Jan 2023 21:24:57 +0800 Message-Id: <20230105132457.4125372-10-treapking@chromium.org> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog In-Reply-To: <20230105132457.4125372-1-treapking@chromium.org> References: <20230105132457.4125372-1-treapking@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Register USB Type-C mode switches when the "mode-switch" property and relevant port are available in Device Tree. Configure the "lane_swap" state based on the entered alternate mode for a specific Type-C connector, which ends up updating the lane swap registers of the it6505 chip. Signed-off-by: Pin-yen Lin --- Changes in v7: - Fixed style issues in it6505 driver - Removed the redundant sleep in it6505 driver - Removed DT property validation in it6505 driver - Rebased to drm-misc-next - Extracted common codes to another commit Changes in v6: - Changed it6505_typec_mux_set callback function to accommodate with the latest drm-misc patches - Changed the driver implementation to accommodate with the new binding - Squashed to a single patch drivers/gpu/drm/bridge/Kconfig | 1 + drivers/gpu/drm/bridge/ite-it6505.c | 119 +++++++++++++++++++++++++++- 2 files changed, 116 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/bridge/Kconfig b/drivers/gpu/drm/bridge/Kconfig index 737578dd57ed..33803f581562 100644 --- a/drivers/gpu/drm/bridge/Kconfig +++ b/drivers/gpu/drm/bridge/Kconfig @@ -87,6 +87,7 @@ config DRM_FSL_LDB config DRM_ITE_IT6505 tristate "ITE IT6505 DisplayPort bridge" depends on OF + depends on TYPEC || TYPEC=n select DRM_DISPLAY_DP_HELPER select DRM_DISPLAY_HDCP_HELPER select DRM_DISPLAY_HELPER diff --git a/drivers/gpu/drm/bridge/ite-it6505.c b/drivers/gpu/drm/bridge/ite-it6505.c index 9cda2df21b88..d9be09e889e2 100644 --- a/drivers/gpu/drm/bridge/ite-it6505.c +++ b/drivers/gpu/drm/bridge/ite-it6505.c @@ -17,6 +17,8 @@ #include #include #include +#include +#include #include #include @@ -28,6 +30,7 @@ #include #include #include +#include #include #include @@ -455,6 +458,7 @@ struct it6505 { struct delayed_work delayed_audio; struct it6505_audio_data audio; struct dentry *debugfs; + struct drm_dp_typec_switch_desc switch_desc; /* it6505 driver hold option */ bool enable_drv_hold; @@ -3346,12 +3350,105 @@ static void it6505_shutdown(struct i2c_client *client) it6505_lane_off(it6505); } +static void it6505_typec_ports_update(struct it6505 *it6505) +{ + struct drm_dp_typec_switch_desc switch_desc = it6505->switch_desc; + + /* Check if both ports available and do nothing to retain the current one */ + if (switch_desc.typec_ports[0].dp_connected && switch_desc.typec_ports[1].dp_connected) + return; + + if (switch_desc.typec_ports[0].dp_connected) + it6505->lane_swap = false; + else if (switch_desc.typec_ports[1].dp_connected) + it6505->lane_swap = true; +} + +static int it6505_typec_mux_set(struct typec_mux_dev *mux, + struct typec_mux_state *state) +{ + struct drm_dp_typec_port_data *port_data = typec_mux_get_drvdata(mux); + struct it6505 *it6505 = (struct it6505 *) port_data->data; + struct device *dev = &it6505->client->dev; + struct drm_dp_typec_switch_desc switch_desc = it6505->switch_desc; + bool old_dp_connected, new_dp_connected; + + if (switch_desc.num_typec_switches == 1) + return 0; + + mutex_lock(&it6505->extcon_lock); + + old_dp_connected = switch_desc.typec_ports[0].dp_connected || + switch_desc.typec_ports[1].dp_connected; + + port_data->dp_connected = state->alt && + state->alt->svid == USB_TYPEC_DP_SID && + state->alt->mode == USB_TYPEC_DP_MODE; + + dev_dbg(dev, "mux_set dp_connected: c0=%d, c1=%d\n", + switch_desc.typec_ports[0].dp_connected, switch_desc.typec_ports[1].dp_connected); + + new_dp_connected = switch_desc.typec_ports[0].dp_connected || + switch_desc.typec_ports[1].dp_connected; + + if (it6505->enable_drv_hold) { + dev_dbg(dev, "enable driver hold\n"); + goto unlock; + } + + it6505_typec_ports_update(it6505); + + if (!old_dp_connected && new_dp_connected) { + int ret = pm_runtime_get_sync(dev); + + /* + * pm_runtime_force_suspend() disables runtime PM when the + * system enters suspend state. But on system resume, mux_set + * can be triggered before pm_runtime_force_resume() re-enables + * runtime PM. This makes the bridge stay powered off if the + * downstream display is connected when the system is suspended. + * Handling the error here to make sure the bridge is powered + * on, and leave the PM runtime usage count incremented so + * the future runtime PM calls is balanced. + */ + if (ret < 0) + it6505_poweron(it6505); + + complete_all(&it6505->extcon_completion); + } + + if (old_dp_connected && !new_dp_connected) { + reinit_completion(&it6505->extcon_completion); + pm_runtime_put_sync(dev); + if (it6505->bridge.dev) + drm_helper_hpd_irq_event(it6505->bridge.dev); + memset(it6505->dpcd, 0, sizeof(it6505->dpcd)); + } + +unlock: + mutex_unlock(&it6505->extcon_lock); + return 0; +} + +static void it6505_unregister_typec_switches(struct it6505 *it6505) +{ + drm_dp_unregister_typec_switches(&it6505->switch_desc); +} + +static int it6505_register_typec_switches(struct device *dev, struct it6505 *it6505) +{ + struct device_node *port = of_graph_get_port_by_id(dev->of_node, 1); + + return drm_dp_register_typec_switches(dev, port, &it6505->switch_desc, + it6505, it6505_typec_mux_set); +} + static int it6505_i2c_probe(struct i2c_client *client) { struct it6505 *it6505; struct device *dev = &client->dev; struct extcon_dev *extcon; - int err, intp_irq; + int err, intp_irq, ret; it6505 = devm_kzalloc(&client->dev, sizeof(*it6505), GFP_KERNEL); if (!it6505) @@ -3371,11 +3468,24 @@ static int it6505_i2c_probe(struct i2c_client *client) if (PTR_ERR(extcon) == -EPROBE_DEFER) return -EPROBE_DEFER; if (IS_ERR(extcon)) { - dev_err(dev, "can not get extcon device!"); - return PTR_ERR(extcon); + if (PTR_ERR(extcon) != -ENODEV) + dev_warn(dev, "Cannot get extcon device: %ld\n", + PTR_ERR(extcon)); + it6505->extcon = NULL; + } else { + it6505->extcon = extcon; } - it6505->extcon = extcon; + ret = it6505_register_typec_switches(dev, it6505); + if (ret) { + if (ret != -ENODEV) + dev_warn(dev, "Didn't register Type-C switches, err: %d\n", + ret); + if (!it6505->extcon) { + dev_err(dev, "Both extcon and typec-switch are not registered.\n"); + return -EINVAL; + } + } it6505->regmap = devm_regmap_init_i2c(client, &it6505_regmap_config); if (IS_ERR(it6505->regmap)) { @@ -3447,6 +3557,7 @@ static void it6505_i2c_remove(struct i2c_client *client) it6505_debugfs_remove(it6505); it6505_poweroff(it6505); it6505_remove_edid(it6505); + it6505_unregister_typec_switches(it6505); } static const struct i2c_device_id it6505_id[] = {