From patchwork Sat Oct 12 07:35:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Ying X-Patchwork-Id: 13833854 Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2048.outbound.protection.outlook.com [40.107.105.48]) (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 6B99F145B27 for ; Sat, 12 Oct 2024 07:37:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.105.48 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728718644; cv=fail; b=YS7JYWNwP5+3jyL9YT1dhow42y6Nfktomg5rL5WUg3X/riaHSrq2SmZC3fCd+7VrRZZ3uGOfiPWC0Pl790b/bnAgsSkk1gatdMHa8KnUrCbSY+O9lN4tI/281nG5TBdzJgwecUyPK2dSCwuIO+OolGO/WSU3n6O8pcYNlo6FycA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728718644; c=relaxed/simple; bh=gKk2lxQZArdHKEple0E+2aUqxy1zK1fYvhoZFTHvYhw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=GfsCpJ/s0h/wlYtEzFfPHZeNELlsHyMHruGh4/RfttgbI2AehUrbfqE22Nmwy4LwVfDJS5aXdBtsyAbsyQH3wce3elNU1/BfYN64vw+BzNUK3VffLR4v8mSsplmzeh0M8qigGai/CJocOJngN0oVn/xggzgZcWH6OgBd7JWnEyI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=DGtVcclc; arc=fail smtp.client-ip=40.107.105.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="DGtVcclc" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=GcxCbNRjohnwrhlg7NbyvRer3I4RqFcJ+6kvvITLO4MOU8ooIZ4/PxviOuYfxZwJvkMXlzzN8WnVYKZlALwqHEN9+pfXv7H+pgW44zNLBrE3Za0ZSvRU+XES1zaNT3IgbKpDSZi7Ioolx1TYZSVW+JjcIiHsHvI1QAs220uY4Ihyf9TgB1vdFNojcU6+tBih8Pb9uomCogc+5IiyD0axKkLXLFDe+HzjZ4eDH0NNIIU9YCsFBt4jGN3/VTPqhJg1gtGvEUyLRMGS1PhUAgjM0CFxe9nQL/VKSFHu8guD2ZQZg81bi7cRLjQXduV6hpcTHOd7jg4spp3ifZMPP02vhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=txhMIYL2GZzyI1GvUUGUsBaJujCliB8cy+8lF5hstFg=; b=BByyd8RtWyyv7NEzC5q8ZL24+GNziHVRv15L+Afs1+oCZWzLNlmDl9IA0ZCapFpQHwYSlOTIoY3E2s9cIdyzk8ZWt9altl2+f8dRdvNwZd5e9L3p2vtJYkIoL40bV8//HnSCNkS/h/xs6bi/0AZe5n7A0aB5sJqGp989FT+Z+a0B7ilMWCIWPGioR25p8nVaStT7LVOUSX5hx9ZB8RTtqtpM2JAwSj4qQLgs6ZrNs3XqnMVaBRnn1zLZG2PX6j6A+84jDJQUm8C2Oe1q6AJTkpFYKt0tTMSCBZS6zo8KgPunzUndi+1khZHno9jpKW85kam5PrQ3P19X2DQTtv9FAQ== 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=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=txhMIYL2GZzyI1GvUUGUsBaJujCliB8cy+8lF5hstFg=; b=DGtVcclc6dAF5lvWQBYsiIqXf3QSVG+W7PTk5Mbe2FP4zeGMVaX7ADoTH4scUkkDPifaiAPgReuV/bx4gsJvIiTDyLhqbtJrd0PAEXUG28cNly089hvw82zSfKKEfLIly6WsKvjzYCRqSkRljaUUbKIH1JO+SK8LrKKuHIdNIr4zqlCW3LvWJZU/fPb9XKc5jfDPX5v1q3MnIfGVPE3dF8IyaMzvBA+N3UkxFyUoLfQnUSX+ispcNJ3BMAMVSAk0Dox8l3iJEmlIQKs4bzL5TOrPJCM+kXqyoakIfg+nurPzw3ZurcjLFog9p1YhYzk760ZfQ3Ye7skJt2XW/wBV5A== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM7PR04MB7046.eurprd04.prod.outlook.com (2603:10a6:20b:113::22) by DB8PR04MB6986.eurprd04.prod.outlook.com (2603:10a6:10:116::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.22; Sat, 12 Oct 2024 07:37:19 +0000 Received: from AM7PR04MB7046.eurprd04.prod.outlook.com ([fe80::d1ce:ea15:6648:6f90]) by AM7PR04MB7046.eurprd04.prod.outlook.com ([fe80::d1ce:ea15:6648:6f90%4]) with mapi id 15.20.8048.020; Sat, 12 Oct 2024 07:37:19 +0000 From: Liu Ying To: dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org Cc: andrzej.hajda@intel.com, neil.armstrong@linaro.org, rfoss@kernel.org, Laurent.pinchart@ideasonboard.com, jonas@kwiboo.se, jernej.skrabec@gmail.com, airlied@gmail.com, simona@ffwll.ch, maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, catalin.marinas@arm.com, will@kernel.org, quic_bjorande@quicinc.com, geert+renesas@glider.be, dmitry.baryshkov@linaro.org, arnd@arndb.de, nfraprado@collabora.com, o.rempel@pengutronix.de, y.moog@phytec.de, marex@denx.de, isaac.scott@ideasonboard.com, biju.das.jz@bp.renesas.com Subject: [PATCH v2 4/9] drm/bridge: fsl-ldb: Use clk_round_rate() to validate "ldb" clock rate Date: Sat, 12 Oct 2024 15:35:38 +0800 Message-Id: <20241012073543.1388069-5-victor.liu@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241012073543.1388069-1-victor.liu@nxp.com> References: <20241012073543.1388069-1-victor.liu@nxp.com> X-ClientProxiedBy: SI2PR01CA0051.apcprd01.prod.exchangelabs.com (2603:1096:4:193::6) To AM7PR04MB7046.eurprd04.prod.outlook.com (2603:10a6:20b:113::22) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM7PR04MB7046:EE_|DB8PR04MB6986:EE_ X-MS-Office365-Filtering-Correlation-Id: 1f13943c-2a24-4651-97b6-08dcea90b3d7 X-LD-Processed: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|7416014|376014|366016|52116014|38350700014; X-Microsoft-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szmWCKwrUpebX0XIdPjPkl3r4mhX15GLVj8swARyz69FgwlOgwUAtKyIEvzEkdrw7rjHY0vwI/pLG8NK+3k7t964kYt8GDQEe+xlqgfYE3WGOidjhgMfucULh9XsKDDwTZuM4sowj2/hT4iANT1Ov34SIH5bGt4hEsPOKTcUX9eVe/BYoj9EzS3bsMHeWjAcetVGQiZfZD8BbcyCHfDyFoGz4VXAA/CglurXBA0KF144v60bzDaO+7I0prYQtsJqmch50jYoM4dJqu6hi8ZYpx5CYDs2UVvA4w== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM7PR04MB7046.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(7416014)(376014)(366016)(52116014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: iMLaCIMEgWuCCASN1l7tDI8/8DLlezfml81MpJRZbI/ZVdkaXyw+6ejLs8DM4nAR0mfq6BdQzmAk3c4uRsErvy3TCVLUUxrJsNfjTRblNJz58LhVeL+WycRBlFfLpdVHrM5n2WUALs/wWWfy+vSeFNnaLemUcT0Li0vWuigqecux1JxeWRnCWi4d+8W+vKz7Eb8/moZ0YsItzvDIIG+ovnImf6Y8NiQ4go8z2yU8RbSBFj7vrFEZ8Z2/Y1x0mZ9Qlij1WJUW5El9fpmZ5Dt7Fzvp8uAPhWQW5Tgw78uzg9mWGgYxN9MQm5pLy/fGmoNhsJqvCYxqvdB0nxGDqPbALsJwnERnicqAdX6N4tsZ06oZ7Ae3CXiW+ZWn9XdK/Q+BU4XQXswvwK+h+/McvpkaUBK3968cTkDQ1ulA7aBmzgG9QBf2T4A5xjCTMYUe9NCvJ5G+aOCDC5E8bbbTZyZIhDura4PmGBuyDM21ST/QIn0ZxBFGqr+urNPg1sbGWKqRIZCSX7IzOwh1EXOq+tyytvA5HtE9YGAASxFH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change-CrossTenant-Network-Message-Id: 1f13943c-2a24-4651-97b6-08dcea90b3d7 X-MS-Exchange-CrossTenant-AuthSource: AM7PR04MB7046.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Oct 2024 07:37:19.5858 (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: ZQdYeNYZrGRKRh+CoU7p9SQ6bmJvYrq7llft412JhBFYfAg+wlJry92QY+pFSIrBlChxPmhVZ04mKr4IhwyqEQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR04MB6986 Multiple display modes could be read from a display device's EDID. Use clk_round_rate() to validate the "ldb" clock rate for each mode in drm_bridge_funcs::mode_valid() to filter unsupported modes out. Also, since this driver doesn't directly reference pixel clock, use clk_round_rate() to validate the pixel clock rate against the "ldb" clock if the "ldb" clock and the pixel clock are sibling in clock tree. This is not done in display controller driver because drm_crtc_helper_funcs::mode_valid() may not decide to do the validation or not if multiple encoders are connected to the CRTC, e.g., i.MX93 LCDIF may connect with MIPI DSI controller, LDB and parallel display output simultaneously. Signed-off-by: Liu Ying --- v2: * Add more comments in fsl-ldb.c and commit message about pixel clock rate validation. (Maxime) drivers/gpu/drm/bridge/fsl-ldb.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/gpu/drm/bridge/fsl-ldb.c b/drivers/gpu/drm/bridge/fsl-ldb.c index b559f3e0bef6..77afc169f0d3 100644 --- a/drivers/gpu/drm/bridge/fsl-ldb.c +++ b/drivers/gpu/drm/bridge/fsl-ldb.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -64,6 +65,7 @@ struct fsl_ldb_devdata { u32 lvds_ctrl; bool lvds_en_bit; bool single_ctrl_reg; + bool ldb_clk_pixel_clk_sibling; }; static const struct fsl_ldb_devdata fsl_ldb_devdata[] = { @@ -74,11 +76,13 @@ static const struct fsl_ldb_devdata fsl_ldb_devdata[] = { [IMX8MP_LDB] = { .ldb_ctrl = 0x5c, .lvds_ctrl = 0x128, + .ldb_clk_pixel_clk_sibling = true, }, [IMX93_LDB] = { .ldb_ctrl = 0x20, .lvds_ctrl = 0x24, .lvds_en_bit = true, + .ldb_clk_pixel_clk_sibling = true, }, }; @@ -269,11 +273,31 @@ fsl_ldb_mode_valid(struct drm_bridge *bridge, const struct drm_display_info *info, const struct drm_display_mode *mode) { + unsigned long link_freq, pclk_rate, rounded_pclk_rate; struct fsl_ldb *fsl_ldb = to_fsl_ldb(bridge); if (mode->clock > (fsl_ldb_is_dual(fsl_ldb) ? 160000 : 80000)) return MODE_CLOCK_HIGH; + /* Validate "ldb" clock rate. */ + link_freq = fsl_ldb_link_frequency(fsl_ldb, mode->clock); + if (link_freq != clk_round_rate(fsl_ldb->clk, link_freq)) + return MODE_NOCLOCK; + + /* + * Since this driver doesn't directly reference pixel clock and + * display controller driver cannot validate pixel clock due to + * multiple types of encoders connected, use "ldb" clock to + * validate pixel clock rate, if the two clocks are sibling. + */ + if (fsl_ldb->devdata->ldb_clk_pixel_clk_sibling) { + pclk_rate = mode->clock * HZ_PER_KHZ; + + rounded_pclk_rate = clk_round_rate(fsl_ldb->clk, pclk_rate); + if (rounded_pclk_rate != pclk_rate) + return MODE_NOCLOCK; + } + return MODE_OK; }