Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp128236pxf; Wed, 10 Mar 2021 02:11:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJwEIGWrZTp7PIkH1sGGsMRspuTCEjsnwSqV/VRlgs5s8NRe9xO22cXcWFi6pfSRmyowJRdZ X-Received: by 2002:a17:906:b2c3:: with SMTP id cf3mr2725816ejb.133.1615371110685; Wed, 10 Mar 2021 02:11:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1615371110; cv=pass; d=google.com; s=arc-20160816; b=dUasynztlPhWQPrEGq6tHX8uhgPI0Pg5UawY53mBoq3zN/gcKDlP/ane2JiY1MRkxh HzZADKOLiDZQ5jIDFfPyrfzW81DQpSn1Ejv2b/LN9GAhC1XbDwX1pIDlFdBA/AF0HL+R 5RBDcjyiEs3W3tHIqsWynJBe8VJM8xkxWq4zp+8F9VOrobiusM9SsDeVdOHLc7ilWcYa LRRiP8SjwrRXNDqyGSGj0KLZvBKh0VxU4aWMKnNKitbL+AnTSRR2qmqmEFVL8hNFpqK3 KpLHcD44vKUKk8U4iUY7+U+tscmOdPrMZPIy0dUNER1lUQn99L474KWGmZqgZBseQ3bS K9mw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=VTRXMvqw8snGm/v9NKDTqWoYR/aaV7v7hHSjtr0IxxY=; b=o97tjMJEOTThcTpkYTI7M57gbJM/3EmQwNDm7w8oTDnSP4Dgf7KBV9xrGsvYmEJBuT jK59CrGuz4RnjRawzcfwVsvuONuorsR/X85VYebX0nqem3NhBaCCwQ4ee9nJYrE7BprO n6ThuayCgbLFKynT4vsLdSo84uNx3g0jLKdw6qLf2yn9xG/kFBJr2dfJQM3jprzmfHXN 9GXmBgkILJFOENMg02lhutOrn283yOQsfZSWRJUWG5JCseAwblSH64UiL4IeBORMTotP oXUywS5CQruTCrh09mEnII4SVbOcpgdPmA7BWNeMgNoA9b5mRrJcs08Aq221SLipzzTQ GWag== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=m7cY+oQ2; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m20si10802778ejc.530.2021.03.10.02.11.27; Wed, 10 Mar 2021 02:11:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=m7cY+oQ2; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232700AbhCJKKY (ORCPT + 99 others); Wed, 10 Mar 2021 05:10:24 -0500 Received: from mail-eopbgr140070.outbound.protection.outlook.com ([40.107.14.70]:19331 "EHLO EUR01-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232614AbhCJKKJ (ORCPT ); Wed, 10 Mar 2021 05:10:09 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FgsaUJwa94SyKykpxnDE9SrhXNNXham1oVSAA5AmQZt1PMSINc4gqq5voGgz/ONwQDgIBJqsVUg0bMzIhSSDO7SCUvQad/VegvAZtA8th3KpSJl/AtJdiOrFJns5lMJ6xP6vGgwO7db38WcryQzmrD06ZgdRt8IEiMzZOsoRubv38/yNQCC3aIwn6Bk2IhGsYW9BUrSdrESpHk5ZVYUkjG+UnjfYAZ4KyB5FWcVfcFVBaIPf3ovCksGwZcl2nhegwDkFhKPOIDipfeEr7yG6yRfC4SsQ7POX+OvOyyBIvwF/+mBgpy20mPJR2MKsWAABRlcl3IlfjlRLXWnRTSkZhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VTRXMvqw8snGm/v9NKDTqWoYR/aaV7v7hHSjtr0IxxY=; b=AN/BUOX24DXsxXjnxpmRc1Mk9SUtZRhh56g2GFmHT2IexFokitzOm12Bacg7fJdvyMOUs+ZAUFnsqgBFoZpNNDvj37qiscHC9ZLmmn+oXGIx+3e82Of2f7/1RFUwrSXgc6pLO2agFvxZjTPJ0V4d2iuhZqa2BWbtJ990mlJiEkyywgBAyTBWfQw9wJGmXTsNJezlYO3cAgmjWcUoNRKoWK5n3aivZQVuU4sGTHRXnL9vZb91gg7S/fVkR2J8XX/cW2DjyGYJir4lBhYNCbrOGlccJnIG7qUWJyUyzdWo051UAM6iDMbRJJKWkSl/yQS3erasz5azWWtPnmpknoBf7g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VTRXMvqw8snGm/v9NKDTqWoYR/aaV7v7hHSjtr0IxxY=; b=m7cY+oQ2sfvScdeqj+YtxWlWYbqBqSTXXY3ukwVM3ELU1UWjgnETkyFZJoCeglRDm2nnGC0rGzpmT+r48WACY8Qai1bYQbqsL4GjGQmQFlJK+TJteBQmXIYtE3lYmV5xo1q+F/zHm3tnzG2F/yZNQajb1SIlg6x2mjPIG+U5fb8= Authentication-Results: lists.freedesktop.org; dkim=none (message not signed) header.d=none;lists.freedesktop.org; dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB3983.eurprd04.prod.outlook.com (2603:10a6:803:4c::16) by VI1PR0402MB3952.eurprd04.prod.outlook.com (2603:10a6:803:1c::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.17; Wed, 10 Mar 2021 10:10:02 +0000 Received: from VI1PR04MB3983.eurprd04.prod.outlook.com ([fe80::2564:cacc:2da5:52d0]) by VI1PR04MB3983.eurprd04.prod.outlook.com ([fe80::2564:cacc:2da5:52d0%5]) with mapi id 15.20.3912.028; Wed, 10 Mar 2021 10:10:02 +0000 From: Liu Ying To: dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org Cc: airlied@linux.ie, daniel@ffwll.ch, robh+dt@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, mchehab@kernel.org, a.hajda@samsung.com, narmstrong@baylibre.com, Laurent.pinchart@ideasonboard.com, jonas@kwiboo.se, jernej.skrabec@siol.net, kishon@ti.com, vkoul@kernel.org, robert.foss@linaro.org, lee.jones@linaro.org Subject: [PATCH v5 10/14] drm/bridge: imx: Add LDB driver helper support Date: Wed, 10 Mar 2021 17:55:34 +0800 Message-Id: <1615370138-5673-11-git-send-email-victor.liu@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1615370138-5673-1-git-send-email-victor.liu@nxp.com> References: <1615370138-5673-1-git-send-email-victor.liu@nxp.com> Content-Type: text/plain X-Originating-IP: [119.31.174.66] X-ClientProxiedBy: HK2PR06CA0010.apcprd06.prod.outlook.com (2603:1096:202:2e::22) To VI1PR04MB3983.eurprd04.prod.outlook.com (2603:10a6:803:4c::16) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (119.31.174.66) by HK2PR06CA0010.apcprd06.prod.outlook.com (2603:1096:202:2e::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.3912.17 via Frontend Transport; Wed, 10 Mar 2021 10:09:56 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 0a66e8b1-5a35-4ca1-3e96-08d8e3acab57 X-MS-TrafficTypeDiagnostic: VI1PR0402MB3952: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: x16ocmeFU5h/W/vkeuSfw0kmbKbfJlMcGnJmtEQ5u5qYSnr2NfUJFdxjFnDLgYezL5qYyGNVyfUqn0X24XxRbr7PI+hF67sD4rO9OPgQCAwx8wAp1lfXxQ8bJIB5odm2UTiSCSTkRlleacB0rwI9wk3wzVtNN8t73aG2YFZ36aaoK4x3tSuJIk6XdySNO0K4g9h4N+8Vvo11AVOeRqMBjkO8WYB6zPkl0kA8Bk8V6Nz0BPNkd0sOmC4ET4Qf7uZQYPIHDqLUKP/Hnj/KDGdZCx7BN3bq6q1PX6HiYUbxIPwY7WzHMZNLqgAvXVfibu/jKMj23MkZWJ+yLYwL4pRgTdmxMQRzjLP118a2PhDTqrM0Iay+T4ofVVYDhg0f9SBmX1TNSsdLNdRmLlMMcPJYqGe240kac+WSQCPbTBWrcCXl+idJNCyQpBAlZDhvKQ+4v0EhRf5HZng/DgzLNV7JF5DQhfpKMntk5jYm8L94vNKFZIRbhSNmKtKr9vfu5/hbgBzPDBGbf9wNTPVSuMPiV9sIfov5cXCLpu1odgbW95aAyEH5D5/QNhh1frH1QdyqwHpQ40td1UMW3MRwgAmZOg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR04MB3983.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(346002)(39860400002)(376002)(396003)(136003)(478600001)(6666004)(2906002)(66476007)(66946007)(66556008)(956004)(7416002)(16526019)(2616005)(316002)(8936002)(5660300002)(26005)(6486002)(52116002)(6512007)(36756003)(86362001)(186003)(69590400012)(6506007)(8676002)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?jRJrQya36G8qF7D3XYjTMoCiQPcilmMY5ghsafNQPk1nmS2a5lrJaqJVcsA2?= =?us-ascii?Q?yjzufqMq3atAV1cvBFrU7nMSur04UCRixbPxy6tUg1kiqOOQN6AUfh/VIwlx?= =?us-ascii?Q?X1pqJGW+rBlKr7DKpHxhpIEfFpHv/B+bju4nDZyb8CgqavWP0COvMaKa0CZf?= =?us-ascii?Q?wt7b3LNU2Kip2hWLbWlgoPBLkyZDIIw+Px5G+eFxUtoBQmwpjSQ/0MbN6uO3?= =?us-ascii?Q?hcM5/XFKY4VZn6x3EoZHO+MZuIyL2CoWSQfGSgmGr3fyozmfV/MUC2AaqKCI?= =?us-ascii?Q?4pllnBIjPZu9HlA8if1ZfOuxazWD9JEgjrtTGq1igygRX5SN6lnqveFTsdlt?= =?us-ascii?Q?/H9XGgrue6LJpe/Uj+WVK//aSuiqh0UgHaq0FvXv0nJwIqJSAWmKJ5YgFyLt?= =?us-ascii?Q?ukOcRLklNC9qhseNE/EL0haAhrl9mRiEfIT3SXg8MKZpIUTml1vgJhqV+8yp?= =?us-ascii?Q?j+HNThYxx6R3/rqmHz/KG9Ud/28gRL0mYkSiWsHiKEsxB8M6/AeAbJoIYrg4?= =?us-ascii?Q?4hrhzmoi2cdrtRm/I8b0BUCjMpMEdKyaXnR2TbVeUZhWGqNBJE8FivIvQhr3?= =?us-ascii?Q?bao7mGFBdKJ/x8E+F2uXCvX11tsxjj3LyrCmSXYbW3I6MZuaD7y/abVnsQee?= =?us-ascii?Q?peN118DPUVm4qMg+MYbup7S1slUIubXLhK7c5ubMn9+8lhAG2ex6s6SR210D?= =?us-ascii?Q?pIUPAUdPps8Q6WH5vNpw7ZgLwomqRj9RwhJAWQqcRE74uW4tKszyc2PsU/Qe?= =?us-ascii?Q?5hII20yBRsRUD1egfQ5DCimWnMJi8cBjRKMFH4u/C/7uY0Ado+gMm8gPT0xS?= =?us-ascii?Q?vwIXNaLf+aXsdkXMXz0tWsDoNBolBnWYpPPfrjsy+ZepicmMVqXjpdfM+8/1?= =?us-ascii?Q?KDCIV80k+ayPY1oa2YIHDP8B7jmEtVRDVpxltBoDlBtDEz1Svaa6XeftlNpA?= =?us-ascii?Q?mK7Rsc/gzbGHJRH5IV7VwvsF+B/4EY8bIz4yqVavnfc1Wp0LvjhAE9zryCaR?= =?us-ascii?Q?7mQTZheTVOIdA/Fi1xy3/njW0lCIjCmNssu9vwAm4uEKS+m3LzNwpEvkdD6p?= =?us-ascii?Q?tJniDBwzPVNF5Q2ThliM7cGnO3MCtElkmOfPmZtBnySRS1Vj1TyMM+u6Bhah?= =?us-ascii?Q?DghkywE4xTFwmXzzXOejpk1MgzZBX3h++PiJfcu/tN5tbvEMLH6/MAi1/Lcu?= =?us-ascii?Q?l9BUmrD+Uj2+hk0378t7brGbY7IaTyETliVgRePDeWlNBoLujfY7zxSKVcIt?= =?us-ascii?Q?VnmSGS9a+sI62toNKVaWZlyzBdgmUBdD3VVY/XJSwuJdNBMWeLcJGR0FvmUJ?= =?us-ascii?Q?tuGavpIZfxu3xGDYYa3YTMQl?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0a66e8b1-5a35-4ca1-3e96-08d8e3acab57 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB3983.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Mar 2021 10:10:02.3555 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: wlCILLFrLRImKwc05wKeCK4C/sLSNE7O9XdAGl0kHmenWeYv9kMp1lDV74yadteUe6grPZJKBEU/VpG9CXMz6g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3952 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds a helper to support LDB drm bridge drivers for i.MX SoCs. Helper functions supported by this helper should implement common logics for all LDB modules embedded in i.MX SoCs. Signed-off-by: Liu Ying --- v4->v5: * Make imx-ldb-helper be a pure object to be linked with i.MX8qxp LDB bridge driver and i.MX8qm LDB bridge driver. (Robert) * Move 'imx_ldb_helper.h' to 'drivers/gpu/drm/bridge/imx/imx-ldb-helper.h'. (Robert) * s/__FSL_IMX_LDB__/__IMX_LDB_HELPER__/ for 'imx-ldb-helper.h'. v3->v4: * No change. v2->v3: * Call syscon_node_to_regmap() to get regmap instead of syscon_regmap_lookup_by_phandle(). v1->v2: * No change. drivers/gpu/drm/bridge/imx/imx-ldb-helper.c | 232 ++++++++++++++++++++++++++++ drivers/gpu/drm/bridge/imx/imx-ldb-helper.h | 98 ++++++++++++ 2 files changed, 330 insertions(+) create mode 100644 drivers/gpu/drm/bridge/imx/imx-ldb-helper.c create mode 100644 drivers/gpu/drm/bridge/imx/imx-ldb-helper.h diff --git a/drivers/gpu/drm/bridge/imx/imx-ldb-helper.c b/drivers/gpu/drm/bridge/imx/imx-ldb-helper.c new file mode 100644 index 00000000..d01c4ff9 --- /dev/null +++ b/drivers/gpu/drm/bridge/imx/imx-ldb-helper.c @@ -0,0 +1,232 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2012 Sascha Hauer, Pengutronix + * Copyright 2019,2020 NXP + */ + +#include +#include +#include + +#include +#include +#include + +#include "imx-ldb-helper.h" + +bool ldb_channel_is_single_link(struct ldb_channel *ldb_ch) +{ + return ldb_ch->link_type == LDB_CH_SINGLE_LINK; +} + +bool ldb_channel_is_split_link(struct ldb_channel *ldb_ch) +{ + return ldb_ch->link_type == LDB_CH_DUAL_LINK_EVEN_ODD_PIXELS || + ldb_ch->link_type == LDB_CH_DUAL_LINK_ODD_EVEN_PIXELS; +} + +int ldb_bridge_atomic_check_helper(struct drm_bridge *bridge, + struct drm_bridge_state *bridge_state, + struct drm_crtc_state *crtc_state, + struct drm_connector_state *conn_state) +{ + struct ldb_channel *ldb_ch = bridge->driver_private; + + ldb_ch->in_bus_format = bridge_state->input_bus_cfg.format; + ldb_ch->out_bus_format = bridge_state->output_bus_cfg.format; + + return 0; +} + +void ldb_bridge_mode_set_helper(struct drm_bridge *bridge, + const struct drm_display_mode *mode, + const struct drm_display_mode *adjusted_mode) +{ + struct ldb_channel *ldb_ch = bridge->driver_private; + struct ldb *ldb = ldb_ch->ldb; + bool is_split = ldb_channel_is_split_link(ldb_ch); + + if (is_split) + ldb->ldb_ctrl |= LDB_SPLIT_MODE_EN; + + switch (ldb_ch->out_bus_format) { + case MEDIA_BUS_FMT_RGB666_1X7X3_SPWG: + break; + case MEDIA_BUS_FMT_RGB888_1X7X4_SPWG: + if (ldb_ch->chno == 0 || is_split) + ldb->ldb_ctrl |= LDB_DATA_WIDTH_CH0_24; + if (ldb_ch->chno == 1 || is_split) + ldb->ldb_ctrl |= LDB_DATA_WIDTH_CH1_24; + break; + case MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA: + if (ldb_ch->chno == 0 || is_split) + ldb->ldb_ctrl |= LDB_DATA_WIDTH_CH0_24 | + LDB_BIT_MAP_CH0_JEIDA; + if (ldb_ch->chno == 1 || is_split) + ldb->ldb_ctrl |= LDB_DATA_WIDTH_CH1_24 | + LDB_BIT_MAP_CH1_JEIDA; + break; + } +} + +void ldb_bridge_enable_helper(struct drm_bridge *bridge) +{ + struct ldb_channel *ldb_ch = bridge->driver_private; + struct ldb *ldb = ldb_ch->ldb; + + /* + * Platform specific bridge drivers should set ldb_ctrl properly + * for the enablement, so just write the ctrl_reg here. + */ + regmap_write(ldb->regmap, ldb->ctrl_reg, ldb->ldb_ctrl); +} + +void ldb_bridge_disable_helper(struct drm_bridge *bridge) +{ + struct ldb_channel *ldb_ch = bridge->driver_private; + struct ldb *ldb = ldb_ch->ldb; + bool is_split = ldb_channel_is_split_link(ldb_ch); + + if (ldb_ch->chno == 0 || is_split) + ldb->ldb_ctrl &= ~LDB_CH0_MODE_EN_MASK; + if (ldb_ch->chno == 1 || is_split) + ldb->ldb_ctrl &= ~LDB_CH1_MODE_EN_MASK; + + regmap_write(ldb->regmap, ldb->ctrl_reg, ldb->ldb_ctrl); +} + +int ldb_bridge_attach_helper(struct drm_bridge *bridge, + enum drm_bridge_attach_flags flags) +{ + struct ldb_channel *ldb_ch = bridge->driver_private; + struct ldb *ldb = ldb_ch->ldb; + + if (!(flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR)) { + DRM_DEV_ERROR(ldb->dev, + "do not support creating a drm_connector\n"); + return -EINVAL; + } + + if (!bridge->encoder) { + DRM_DEV_ERROR(ldb->dev, "missing encoder\n"); + return -ENODEV; + } + + return drm_bridge_attach(bridge->encoder, + ldb_ch->next_bridge, bridge, + DRM_BRIDGE_ATTACH_NO_CONNECTOR); +} + +int ldb_init_helper(struct ldb *ldb) +{ + struct device *dev = ldb->dev; + struct device_node *np = dev->of_node; + struct device_node *child; + int ret; + u32 i; + + ldb->regmap = syscon_node_to_regmap(np->parent); + if (IS_ERR(ldb->regmap)) { + ret = PTR_ERR(ldb->regmap); + if (ret != -EPROBE_DEFER) + DRM_DEV_ERROR(dev, "failed to get regmap: %d\n", ret); + return ret; + } + + for_each_available_child_of_node(np, child) { + struct ldb_channel *ldb_ch; + + ret = of_property_read_u32(child, "reg", &i); + if (ret || i > MAX_LDB_CHAN_NUM - 1) { + ret = -EINVAL; + DRM_DEV_ERROR(dev, + "invalid channel node address: %u\n", i); + of_node_put(child); + return ret; + } + + ldb_ch = ldb->channel[i]; + ldb_ch->ldb = ldb; + ldb_ch->chno = i; + ldb_ch->is_available = true; + ldb_ch->np = child; + + ldb->available_ch_cnt++; + } + + return 0; +} + +int ldb_find_next_bridge_helper(struct ldb *ldb) +{ + struct device *dev = ldb->dev; + struct ldb_channel *ldb_ch; + int ret, i; + + for (i = 0; i < MAX_LDB_CHAN_NUM; i++) { + ldb_ch = ldb->channel[i]; + + if (!ldb_ch->is_available) + continue; + + ret = drm_of_find_panel_or_bridge(ldb_ch->np, 1, 0, + &ldb_ch->panel, + &ldb_ch->next_bridge); + if (ret) { + if (ret != -EPROBE_DEFER) + DRM_DEV_ERROR(dev, + "failed to find panel or bridge: %d\n", + ret); + return ret; + } + + if (ldb_ch->panel) { + ldb_ch->next_bridge = devm_drm_panel_bridge_add(dev, + ldb_ch->panel); + if (IS_ERR(ldb_ch->next_bridge)) { + ret = PTR_ERR(ldb_ch->next_bridge); + DRM_DEV_ERROR(dev, + "failed to add panel bridge: %d\n", + ret); + return ret; + } + } + } + + return 0; +} + +void ldb_add_bridge_helper(struct ldb *ldb, + const struct drm_bridge_funcs *bridge_funcs) +{ + struct ldb_channel *ldb_ch; + int i; + + for (i = 0; i < MAX_LDB_CHAN_NUM; i++) { + ldb_ch = ldb->channel[i]; + + if (!ldb_ch->is_available) + continue; + + ldb_ch->bridge.driver_private = ldb_ch; + ldb_ch->bridge.funcs = bridge_funcs; + ldb_ch->bridge.of_node = ldb_ch->np; + + drm_bridge_add(&ldb_ch->bridge); + } +} + +void ldb_remove_bridge_helper(struct ldb *ldb) +{ + struct ldb_channel *ldb_ch; + int i; + + for (i = 0; i < MAX_LDB_CHAN_NUM; i++) { + ldb_ch = ldb->channel[i]; + + if (!ldb_ch->is_available) + continue; + + drm_bridge_remove(&ldb_ch->bridge); + } +} diff --git a/drivers/gpu/drm/bridge/imx/imx-ldb-helper.h b/drivers/gpu/drm/bridge/imx/imx-ldb-helper.h new file mode 100644 index 00000000..748c378 --- /dev/null +++ b/drivers/gpu/drm/bridge/imx/imx-ldb-helper.h @@ -0,0 +1,98 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +/* + * Copyright 2019,2020 NXP + */ + +#ifndef __IMX_LDB_HELPER__ +#define __IMX_LDB_HELPER__ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#define LDB_CH0_MODE_EN_TO_DI0 (1 << 0) +#define LDB_CH0_MODE_EN_TO_DI1 (3 << 0) +#define LDB_CH0_MODE_EN_MASK (3 << 0) +#define LDB_CH1_MODE_EN_TO_DI0 (1 << 2) +#define LDB_CH1_MODE_EN_TO_DI1 (3 << 2) +#define LDB_CH1_MODE_EN_MASK (3 << 2) +#define LDB_SPLIT_MODE_EN (1 << 4) +#define LDB_DATA_WIDTH_CH0_24 (1 << 5) +#define LDB_BIT_MAP_CH0_JEIDA (1 << 6) +#define LDB_DATA_WIDTH_CH1_24 (1 << 7) +#define LDB_BIT_MAP_CH1_JEIDA (1 << 8) +#define LDB_DI0_VS_POL_ACT_LOW (1 << 9) +#define LDB_DI1_VS_POL_ACT_LOW (1 << 10) + +#define MAX_LDB_CHAN_NUM 2 + +enum ldb_channel_link_type { + LDB_CH_SINGLE_LINK, + LDB_CH_DUAL_LINK_EVEN_ODD_PIXELS, + LDB_CH_DUAL_LINK_ODD_EVEN_PIXELS, +}; + +struct ldb; + +struct ldb_channel { + struct ldb *ldb; + struct drm_bridge bridge; + struct drm_panel *panel; + struct drm_bridge *next_bridge; + struct device_node *np; + u32 chno; + bool is_available; + u32 in_bus_format; + u32 out_bus_format; + enum ldb_channel_link_type link_type; +}; + +struct ldb { + struct regmap *regmap; + struct device *dev; + struct ldb_channel *channel[MAX_LDB_CHAN_NUM]; + unsigned int ctrl_reg; + u32 ldb_ctrl; + unsigned int available_ch_cnt; +}; + +#define bridge_to_ldb_ch(b) container_of(b, struct ldb_channel, bridge) + +bool ldb_channel_is_single_link(struct ldb_channel *ldb_ch); +bool ldb_channel_is_split_link(struct ldb_channel *ldb_ch); + +int ldb_bridge_atomic_check_helper(struct drm_bridge *bridge, + struct drm_bridge_state *bridge_state, + struct drm_crtc_state *crtc_state, + struct drm_connector_state *conn_state); + +void ldb_bridge_mode_set_helper(struct drm_bridge *bridge, + const struct drm_display_mode *mode, + const struct drm_display_mode *adjusted_mode); + +void ldb_bridge_enable_helper(struct drm_bridge *bridge); + +void ldb_bridge_disable_helper(struct drm_bridge *bridge); + +int ldb_bridge_attach_helper(struct drm_bridge *bridge, + enum drm_bridge_attach_flags flags); + +int ldb_init_helper(struct ldb *ldb); + +int ldb_find_next_bridge_helper(struct ldb *ldb); + +void ldb_add_bridge_helper(struct ldb *ldb, + const struct drm_bridge_funcs *bridge_funcs); + +void ldb_remove_bridge_helper(struct ldb *ldb); + +#endif /* __IMX_LDB_HELPER__ */ -- 2.7.4