From patchwork Sat Feb 3 16:52:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Ford X-Patchwork-Id: 196344 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp1109611dyc; Sat, 3 Feb 2024 09:00:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IERAprQ4CYdQGTjDf5idzu49qJyF/OvOxPig20ICx9Wa3DUmwBSrBEGp7LqCx8NYWIqYiyp X-Received: by 2002:a05:6e02:148:b0:363:c386:194a with SMTP id j8-20020a056e02014800b00363c386194amr314867ilr.25.1706979644595; Sat, 03 Feb 2024 09:00:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706979644; cv=pass; d=google.com; s=arc-20160816; b=xa/ZamI7Wex/HarLVlTHEJX8VIrc/VxBFOZMXAm5a+9MYd8tLgeYbRf9Rwe6lQCfQm ke9F6G70xmNfJQKtHL8KWVdll8VsOzZGCDVtpu5hRX9LdAPqjC5QnJmFF7B3ufv8A9vB s+9y1peo6cWXp1RGFgNSei8W4hppKULimwJ9wkXj883NAAt4jIdYAkqAGJ0TBfGOGmov zqfvPXmVZMNxZfmOwsJex+eXCcKN3UR6Yknhrpw9dedhkYvH+5eGrLDgYvu/OqNSUeer 5MewI7dBc7g32MDJ5kBhkm0nB7oDkdvZr16HHc1reNYKCuKkt5lHC+q+7NWbitwKYWXe lsAg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=nS1U6CsEeokUdAK6p14gWlLI/p7zyPtTy5BLbUv6Q3Y=; fh=mfynI14sXJiPp+eGebVv8mqObxnjsHTYY61vYPNz440=; b=QTtr1MOIJdkdNOhOCjMQ/IPb+b+33qjQ6n/9nOG0uvc/EqyoW1cJbd2P+RJbaPNw4K v0uVWxw4sv5RbP6Lzz6SY+u7UN81CHzaLqDexq87FVlPIqt6b9gweKDTCHh+GzRDGqBt UhYndDUrtSknFYrqYn4hZOU4lohT7NG99JBWTE/xFkTz+gYBkbv2WpYQqyVDGJQLUAfp va6irKIUfadQQYYgrUbgJ5jdLEDwUEM1lGTA1NBAyx+QuiELZM8ujXbmI8CXUkEZq9N4 nDVZHU5VSco1jUXzgQ33wJyn8n7D2xegIdvW9ImLpATjEsM21neGNbJL3RpxCPeCf4bz IOwA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Zx0BSMBc; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-51198-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51198-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com X-Forwarded-Encrypted: i=1; AJvYcCXfXjZ79t+z6QbNMZb8OHANKOdPC09q6yfcp58zeYo6evTkB77kXw+Mvz3nKqXhtJtrCwwGqlI7s/e6j3I+unNaZGqcVw== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id t16-20020a63f350000000b005dc071d13c7si875979pgj.273.2024.02.03.09.00.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 09:00:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51198-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Zx0BSMBc; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-51198-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51198-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 551A3B26C2F for ; Sat, 3 Feb 2024 16:56:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2750461664; Sat, 3 Feb 2024 16:54:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Zx0BSMBc" Received: from mail-io1-f43.google.com (mail-io1-f43.google.com [209.85.166.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E7D5B60DF1; Sat, 3 Feb 2024 16:54:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706979254; cv=none; b=H7U5j6mwMvRX1uW/A1iUMqeEfmgtLSaGpzyLOxEyJMoUsmaEYBufqcxEt5wR72VPCzbxpLgfdMh696jSHW1BAtGepI73U8UhXEDqt+CJLKGL7X+ZUhtjZFNDcp/BPFYjvqOaTQ+MwQUYejixuWbEyc0ND4JPHrSJuoEo4GnUePM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706979254; c=relaxed/simple; bh=59WPME9T5sG0PHCd9y+jVOtUD9XIM7BE9Xfgh15zm7Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RZukoQ72c6oDtii8Jk7cCufIdMzR/lew4Cavg+4j1l7CEMm4E6yWAh2EOsFKZ/wp9eYKmm7PPeRU9NIp+sOWWMWMs21NrVKOo35YOYmN31imG1zW2n/EgeJRFQALMqiqxJGMgu4nLSOLUynqz1E+8NFyii2gII4VDWfRR457xVg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Zx0BSMBc; arc=none smtp.client-ip=209.85.166.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-io1-f43.google.com with SMTP id ca18e2360f4ac-7bb5fda069bso155233939f.0; Sat, 03 Feb 2024 08:54:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706979252; x=1707584052; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nS1U6CsEeokUdAK6p14gWlLI/p7zyPtTy5BLbUv6Q3Y=; b=Zx0BSMBco4WarSUM/5MewXr0b3b4bCSQE+eF4PqgPAJl4rfbU5uci+VEPJzzsd0zyN n2zJPweFG2fTGyD1woPTD2fUIB6/bYZZ7jlBsTMru2TEu9JEb4sXcObApoOmvy7ZRla+ L1Yhtg+FKuu8c/2lkpv6khX+yaRzbAt1yWhLc0q1sW9dAModiEJNzfl+6m3EPdo337EO dnsu452owOfwwkziQJ1Zw5C54iniTaBUF+MZ02jKRCfqZX+4ioRaH+WMiOoHDG9TQEVn IsN9kjyEFZvkEjSbSj7XTcIIwS+OOuBvs3qoRKDR4Bs9aVvBURYjTHuN+t20rvQ0P57P dLHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706979252; x=1707584052; 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=nS1U6CsEeokUdAK6p14gWlLI/p7zyPtTy5BLbUv6Q3Y=; b=NXZySXrv5b8wdEa4h4zNH+1+B5+BCUQ+MX6ejx+AJnoOBZwSpzIETOEelW8lWeNZKW TQprdKF6OEFaRWFAPOHZjUN9976Q3js524Ej4cAtVxckNh8lUEXcXZ5GGeXaAOsjEesb VSHTYdxFsYj2kzAsxLA8X+QdRy0pIAKaubhMooGEg8PWGrwrvXjISw1gQvUvDgUz4ge+ g7AAU+SnKQ7X8jfh61IzB6HUoWFhpzzDKiS0+3NOr9mKgib3GNfx5Ubg34qNcj80R/W5 okLU42XXuXK48J1r5bSTg+A/Yj4O/HNXY5wNso+g8BVgbeCzBqqQ08hWlwmZ4ibCSmTU hSJA== X-Gm-Message-State: AOJu0YyV2hDMQm1FY0oUk0/jlJv20p1kiNLdm+VQPiVojwgt4Hf4O4b4 Xaz/RACubMVt9p77dw2Nw+ug1vrSmik+MQ0JHgYliYi5/qTe1pX2 X-Received: by 2002:a5e:dc43:0:b0:7bf:da4d:3477 with SMTP id s3-20020a5edc43000000b007bfda4d3477mr12909894iop.9.1706979251851; Sat, 03 Feb 2024 08:54:11 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCWtJ3htmPbVibzr6e+4lQlOltg/gjP51UEUwO3KrmFljhhl5pWMKK9VZbywdm8qKxEksEtRtyXaaABe21u/XY9kBnWNeb5ACbwKIezVpe0uAKNNmNZgOrvuPFe4/yko2uwZuaX9ZuRnZEI9ZIZ2doxFNAIAio5aIxeOUm+jS+3hSf6OEkxpi5vGiCS3HUdmWtdwYI13pfK/d2iOyC5IQ6z1dDC70AKp1GY/udpFYQgJg1u3dUh+a3S1VrO2f0mCa/9FoNbBOE6GFbK+/jpZdVPAm7X6Mt0ytgwUbVGQ//znjDMQjA/3BA5QFN4V8+C6Nb/G2uYtH3vZa3oT3hIcRGUzREv0DaqhJkpzarzCjD3iICg+QPOqF7r3eFHuZWgfSE2p/xBckhEuaN5fC/2dr8ljB1uNBxClNLEZHNlAVWJ8Xu1sToM550SOvB1bC1SEm3OXmqqq2QxAdWZv/Y/XCpRdt8+2vFj8t+OagQCXbFco6V+2BJoWnEyTC6bkx5OwE5IALra9l7gE8X4+wQscveFtdwVltDcGq8pH+cBIQAQH6PH/jo6Om/3gRdmX3o6Uq1EzRcNLuXjO4bZj1x5Ej+/IG+lkIakEzBlaMC9lW2ydCYDEV98g+V/tGaQEXPZSuTMJbsm8OuUYJWTee7ZADdRYIJuRlKbHE2qPUL5ZjFyBi0j9iagnpEjKj6MNIx6EBwe76JTUK78e5FcC2jwU4Q54jSi1z7cI1CRHoO+RoeGm5Ef9jnBy5YNhKoFGdZYVrL0A8pjzWmj1FJ07W1MGA8phDBWUgtV6E5kIZ+gyVMD/qCn0Q//t1mYVOFGBmzRNRJE4rb+xvOPafqyZyhj0z2F9ALYwuEX9685QpY1zJC364Gw614rVX/42vo/LBf5t39N/W9WHQQyfitVcqxh7Ee5YkoRC7ge7Bc2TcVKymG4AcEd29eO/Ad8rS+9wVeOR4/nSO1 AA2DxDnPtlcFS0Uyl6gXJ1pvSU98BPb9FuhJT+wtGQECFTYIRCCD3l7aUl7tb+dZIlTSWSRaTECmYXgD/n1twe3NLsnAHnOTOKcsN9mXTPv05Y6ZXEyah6i8LRal+ZShTupWEfcW69K7yX+6l1UNwMboVQ+Qr1kLob2n9LFgMYeF2OHD77j1eU8+rvNJN/WOPn1f2rSD4LS482dhwTTtipgjowm052XOo0JXXEAFIgVIkItlAFuEEbO3beWbvZfBhc5QiXYCsTzs0ovP+HtjWRQOFi3+w8u7msJPr1AFr9wDGdBlmumRUA9ku41IX9jThWYGI6u31VJ7sP9npKHlEJVMo= Received: from aford-System-Version.lan ([2601:447:d002:5be:d9b2:bb4f:5531:6aa9]) by smtp.gmail.com with ESMTPSA id t30-20020a05663836de00b00470b29b82b1sm1086256jau.154.2024.02.03.08.54.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 08:54:10 -0800 (PST) From: Adam Ford To: linux-arm-kernel@lists.infradead.org Cc: marex@denx.de, alexander.stein@ew.tq-group.com, frieder.schrempf@kontron.de, Lucas Stach , Luca Ceresoli , Richard Leitner , Laurent Pinchart , Fabio Estevam , Adam Ford , Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , David Airlie , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , NXP Linux Team , Philipp Zabel , Vinod Koul , Kishon Vijay Abraham I , Catalin Marinas , Will Deacon , Liu Ying , Ulf Hansson , dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-phy@lists.infradead.org, linux-pm@vger.kernel.org Subject: [PATCH V8 08/12] drm/bridge: imx: add driver for HDMI TX Parallel Video Interface Date: Sat, 3 Feb 2024 10:52:48 -0600 Message-ID: <20240203165307.7806-9-aford173@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240203165307.7806-1-aford173@gmail.com> References: <20240203165307.7806-1-aford173@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789897887719083792 X-GMAIL-MSGID: 1789897887719083792 From: Lucas Stach This IP block is found in the HDMI subsystem of the i.MX8MP SoC. It has a full timing generator and can switch between different video sources. On the i.MX8MP however the only supported source is the LCDIF. The block just needs to be powered up and told about the polarity of the video sync signals to act in bypass mode. Signed-off-by: Lucas Stach Reviewed-by: Luca Ceresoli (v7) Tested-by: Marek Vasut (v1) Tested-by: Luca Ceresoli (v7) Tested-by: Richard Leitner (v2) Tested-by: Frieder Schrempf (v2) Reviewed-by: Laurent Pinchart (v3) Reviewed-by: Luca Ceresoli Tested-by: Luca Ceresoli Tested-by: Fabio Estevam Signed-off-by: Adam Ford --- V8: No Change V7: Re-do some includes to address build issues after rebasing from Linux-next V6: No change. V5: I (Adam) tried to help move this along, so I took Lucas' patch and attempted to apply fixes based on feedback. I don't have all the history, so apologies for that. No changes from V4 to V5 --- drivers/gpu/drm/bridge/imx/Kconfig | 7 + drivers/gpu/drm/bridge/imx/Makefile | 1 + drivers/gpu/drm/bridge/imx/imx8mp-hdmi-pvi.c | 207 +++++++++++++++++++ 3 files changed, 215 insertions(+) create mode 100644 drivers/gpu/drm/bridge/imx/imx8mp-hdmi-pvi.c diff --git a/drivers/gpu/drm/bridge/imx/Kconfig b/drivers/gpu/drm/bridge/imx/Kconfig index 5a4f3d58501e..a4d13331e320 100644 --- a/drivers/gpu/drm/bridge/imx/Kconfig +++ b/drivers/gpu/drm/bridge/imx/Kconfig @@ -3,6 +3,13 @@ if ARCH_MXC || COMPILE_TEST config DRM_IMX_LDB_HELPER tristate +config DRM_IMX8MP_HDMI_PVI + tristate "Freescale i.MX8MP HDMI PVI bridge support" + depends on OF + help + Choose this to enable support for the internal HDMI TX Parallel + Video Interface found on the Freescale i.MX8MP SoC. + config DRM_IMX8QM_LDB tristate "Freescale i.MX8QM LVDS display bridge" depends on OF diff --git a/drivers/gpu/drm/bridge/imx/Makefile b/drivers/gpu/drm/bridge/imx/Makefile index 2b0c2e44aa1b..e2c2106509fa 100644 --- a/drivers/gpu/drm/bridge/imx/Makefile +++ b/drivers/gpu/drm/bridge/imx/Makefile @@ -1,4 +1,5 @@ obj-$(CONFIG_DRM_IMX_LDB_HELPER) += imx-ldb-helper.o +obj-$(CONFIG_DRM_IMX8MP_HDMI_PVI) += imx8mp-hdmi-pvi.o obj-$(CONFIG_DRM_IMX8QM_LDB) += imx8qm-ldb.o obj-$(CONFIG_DRM_IMX8QXP_LDB) += imx8qxp-ldb.o obj-$(CONFIG_DRM_IMX8QXP_PIXEL_COMBINER) += imx8qxp-pixel-combiner.o diff --git a/drivers/gpu/drm/bridge/imx/imx8mp-hdmi-pvi.c b/drivers/gpu/drm/bridge/imx/imx8mp-hdmi-pvi.c new file mode 100644 index 000000000000..a76b7669fe8a --- /dev/null +++ b/drivers/gpu/drm/bridge/imx/imx8mp-hdmi-pvi.c @@ -0,0 +1,207 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/* + * Copyright (C) 2022 Pengutronix, Lucas Stach + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define HTX_PVI_CTRL 0x0 +#define PVI_CTRL_OP_VSYNC_POL BIT(18) +#define PVI_CTRL_OP_HSYNC_POL BIT(17) +#define PVI_CTRL_OP_DE_POL BIT(16) +#define PVI_CTRL_INP_VSYNC_POL BIT(14) +#define PVI_CTRL_INP_HSYNC_POL BIT(13) +#define PVI_CTRL_INP_DE_POL BIT(12) +#define PVI_CTRL_MODE_MASK GENMASK(2, 1) +#define PVI_CTRL_MODE_LCDIF 2 +#define PVI_CTRL_EN BIT(0) + +struct imx8mp_hdmi_pvi { + struct drm_bridge bridge; + struct device *dev; + struct drm_bridge *next_bridge; + void __iomem *regs; +}; + +static inline struct imx8mp_hdmi_pvi * +to_imx8mp_hdmi_pvi(struct drm_bridge *bridge) +{ + return container_of(bridge, struct imx8mp_hdmi_pvi, bridge); +} + +static int imx8mp_hdmi_pvi_bridge_attach(struct drm_bridge *bridge, + enum drm_bridge_attach_flags flags) +{ + struct imx8mp_hdmi_pvi *pvi = to_imx8mp_hdmi_pvi(bridge); + + return drm_bridge_attach(bridge->encoder, pvi->next_bridge, + bridge, flags); +} + +static void imx8mp_hdmi_pvi_bridge_enable(struct drm_bridge *bridge, + struct drm_bridge_state *bridge_state) +{ + struct drm_atomic_state *state = bridge_state->base.state; + struct imx8mp_hdmi_pvi *pvi = to_imx8mp_hdmi_pvi(bridge); + struct drm_connector_state *conn_state; + const struct drm_display_mode *mode; + struct drm_crtc_state *crtc_state; + struct drm_connector *connector; + u32 bus_flags, val; + + connector = drm_atomic_get_new_connector_for_encoder(state, bridge->encoder); + conn_state = drm_atomic_get_new_connector_state(state, connector); + crtc_state = drm_atomic_get_new_crtc_state(state, conn_state->crtc); + + if (WARN_ON(pm_runtime_resume_and_get(pvi->dev))) + return; + + mode = &crtc_state->adjusted_mode; + + val = FIELD_PREP(PVI_CTRL_MODE_MASK, PVI_CTRL_MODE_LCDIF) | PVI_CTRL_EN; + + if (mode->flags & DRM_MODE_FLAG_PVSYNC) + val |= PVI_CTRL_OP_VSYNC_POL | PVI_CTRL_INP_VSYNC_POL; + + if (mode->flags & DRM_MODE_FLAG_PHSYNC) + val |= PVI_CTRL_OP_HSYNC_POL | PVI_CTRL_INP_HSYNC_POL; + + if (pvi->next_bridge->timings) + bus_flags = pvi->next_bridge->timings->input_bus_flags; + else if (bridge_state) + bus_flags = bridge_state->input_bus_cfg.flags; + + if (bus_flags & DRM_BUS_FLAG_DE_HIGH) + val |= PVI_CTRL_OP_DE_POL | PVI_CTRL_INP_DE_POL; + + writel(val, pvi->regs + HTX_PVI_CTRL); +} + +static void imx8mp_hdmi_pvi_bridge_disable(struct drm_bridge *bridge, + struct drm_bridge_state *bridge_state) +{ + struct imx8mp_hdmi_pvi *pvi = to_imx8mp_hdmi_pvi(bridge); + + writel(0x0, pvi->regs + HTX_PVI_CTRL); + + pm_runtime_put(pvi->dev); +} + +static u32 * +imx8mp_hdmi_pvi_bridge_get_input_bus_fmts(struct drm_bridge *bridge, + struct drm_bridge_state *bridge_state, + struct drm_crtc_state *crtc_state, + struct drm_connector_state *conn_state, + u32 output_fmt, + unsigned int *num_input_fmts) +{ + struct imx8mp_hdmi_pvi *pvi = to_imx8mp_hdmi_pvi(bridge); + struct drm_bridge *next_bridge = pvi->next_bridge; + struct drm_bridge_state *next_state; + + if (!next_bridge->funcs->atomic_get_input_bus_fmts) + return 0; + + next_state = drm_atomic_get_new_bridge_state(crtc_state->state, + next_bridge); + + return next_bridge->funcs->atomic_get_input_bus_fmts(next_bridge, + next_state, + crtc_state, + conn_state, + output_fmt, + num_input_fmts); +} + +static const struct drm_bridge_funcs imx_hdmi_pvi_bridge_funcs = { + .attach = imx8mp_hdmi_pvi_bridge_attach, + .atomic_enable = imx8mp_hdmi_pvi_bridge_enable, + .atomic_disable = imx8mp_hdmi_pvi_bridge_disable, + .atomic_get_input_bus_fmts = imx8mp_hdmi_pvi_bridge_get_input_bus_fmts, + .atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state, + .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state, + .atomic_reset = drm_atomic_helper_bridge_reset, +}; + +static int imx8mp_hdmi_pvi_probe(struct platform_device *pdev) +{ + struct device_node *remote; + struct imx8mp_hdmi_pvi *pvi; + + pvi = devm_kzalloc(&pdev->dev, sizeof(*pvi), GFP_KERNEL); + if (!pvi) + return -ENOMEM; + + platform_set_drvdata(pdev, pvi); + pvi->dev = &pdev->dev; + + pvi->regs = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(pvi->regs)) + return PTR_ERR(pvi->regs); + + /* Get the next bridge in the pipeline. */ + remote = of_graph_get_remote_node(pdev->dev.of_node, 1, -1); + if (!remote) + return -EINVAL; + + pvi->next_bridge = of_drm_find_bridge(remote); + of_node_put(remote); + + if (!pvi->next_bridge) + return dev_err_probe(&pdev->dev, -EPROBE_DEFER, + "could not find next bridge\n"); + + pm_runtime_enable(&pdev->dev); + + /* Register the bridge. */ + pvi->bridge.funcs = &imx_hdmi_pvi_bridge_funcs; + pvi->bridge.of_node = pdev->dev.of_node; + pvi->bridge.timings = pvi->next_bridge->timings; + + drm_bridge_add(&pvi->bridge); + + return 0; +} + +static int imx8mp_hdmi_pvi_remove(struct platform_device *pdev) +{ + struct imx8mp_hdmi_pvi *pvi = platform_get_drvdata(pdev); + + drm_bridge_remove(&pvi->bridge); + + pm_runtime_disable(&pdev->dev); + + return 0; +} + +static const struct of_device_id imx8mp_hdmi_pvi_match[] = { + { + .compatible = "fsl,imx8mp-hdmi-pvi", + }, { + /* sentinel */ + } +}; +MODULE_DEVICE_TABLE(of, imx8mp_hdmi_pvi_match); + +static struct platform_driver imx8mp_hdmi_pvi_driver = { + .probe = imx8mp_hdmi_pvi_probe, + .remove = imx8mp_hdmi_pvi_remove, + .driver = { + .name = "imx-hdmi-pvi", + .of_match_table = imx8mp_hdmi_pvi_match, + }, +}; +module_platform_driver(imx8mp_hdmi_pvi_driver); + +MODULE_DESCRIPTION("i.MX8MP HDMI TX Parallel Video Interface bridge driver"); +MODULE_LICENSE("GPL");