From nobody Wed Oct 8 00:42:31 2025 Received: from lelvem-ot01.ext.ti.com (lelvem-ot01.ext.ti.com [198.47.23.234]) (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 E27272EF9D4 for ; Fri, 4 Jul 2025 09:49:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.47.23.234 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751622567; cv=none; b=AeGbjoBVw11Wb2xvyFph2Cigf5F9YzSiYUHpCXfsrjuDVdn7+MdUWBiVzIGthP3/J0PGC25qSSR8xXafo4F03Y6AT6CALsrTbD9NeOtDxtDuupsPEOJeGofp+dRi9UkW5/h2ynfsWKj9kaqAUWI31z8tLDRA4QvdXvuXikKEUOs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751622567; c=relaxed/simple; bh=zUwgdQIAQfDMzwxQNeGaYILbEVJvebERnRCIoK8Glq4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nD0zdwqOyfbg59cpMLqpGiSmjdeEpTKg7m/8pOkcPr4Ft/4K4ica5zhlY5NqViC46HKDJqG1NRYwbtzAMpGItYCXib8HugB5JVcK30zD+G7nyRLQkY5t0Xcd0CTXP5aMzi0pIhUfckaNDHIIz5lQY8GRUQJIJ9HcdMsv2+Mn1uI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com; spf=pass smtp.mailfrom=ti.com; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b=leamL8Qe; arc=none smtp.client-ip=198.47.23.234 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ti.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ti.com header.i=@ti.com header.b="leamL8Qe" Received: from lelvem-sh01.itg.ti.com ([10.180.77.71]) by lelvem-ot01.ext.ti.com (8.15.2/8.15.2) with ESMTP id 5649muYO3796351; Fri, 4 Jul 2025 04:48:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1751622536; bh=HbTVn6tkYbDgC9EZaGjIw5d7xDPKAYM9WUBwjYYGi/Q=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=leamL8QeePwRT3rhkR7pWw9sE8QdPnQl9VBNqhh86b0kosTxxyZ/iZ65s6N2Dl3j+ DGtpAfQytrAwzc3w8s4apBYiZ+aJNdFNBcmTrrqaId6kknxowGeiAuJO6eJrJ21kjo yl8HrNA8MgfdYQF224Moy4kE1KJt8GDrGxtUALG8= Received: from DLEE112.ent.ti.com (dlee112.ent.ti.com [157.170.170.23]) by lelvem-sh01.itg.ti.com (8.18.1/8.18.1) with ESMTPS id 5649muSv3273935 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA256 bits=128 verify=FAIL); Fri, 4 Jul 2025 04:48:56 -0500 Received: from DLEE113.ent.ti.com (157.170.170.24) by DLEE112.ent.ti.com (157.170.170.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.55; Fri, 4 Jul 2025 04:48:56 -0500 Received: from lelvem-mr05.itg.ti.com (10.180.75.9) by DLEE113.ent.ti.com (157.170.170.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.55 via Frontend Transport; Fri, 4 Jul 2025 04:48:56 -0500 Received: from localhost (jayesh-hp-z2-tower-g5-workstation.dhcp.ti.com [172.24.227.166]) by lelvem-mr05.itg.ti.com (8.18.1/8.18.1) with ESMTP id 5649mtrX2774067; Fri, 4 Jul 2025 04:48:56 -0500 From: Jayesh Choudhary To: , , , , , , , CC: , , , Subject: [PATCH v4 2/3] drm/tidss: Remove max_pclk_khz from tidss display features Date: Fri, 4 Jul 2025 15:18:50 +0530 Message-ID: <20250704094851.182131-3-j-choudhary@ti.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250704094851.182131-1-j-choudhary@ti.com> References: <20250704094851.182131-1-j-choudhary@ti.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea Content-Type: text/plain; charset="utf-8" TIDSS hardware by itself does not have variable max_pclk for each VP. The maximum pixel clock is determined by the limiting factor between the functional clock and the PLL (parent to the VP/pixel clock). The limitation that has been modeled till now comes from the clock (PLL can only be programmed to a particular max value). Instead of putting it as a constant field in dispc_features, we can query the DM to see if requested clock can be set or not and use it in "mode_valid()". Replace constant "max_pclk_khz" in dispc_features with "curr_max_pclk" in tidss_device structure which would be modified in runtime. In mode_valid() call, check if a best frequency match for mode clock can be found or not using "clk_round_rate()". Based on that, propagate "cur_max_pclk" and query DM again only if the requested mode clock is greater than cur_max_pclk. (As the preferred display mode is usually the max resolution, driver ends up checking the highest clock the first time itself which is used in subsequent checks) Since TIDSS display controller provides clock tolerance of 5%, we use this while checking the curr_max_pclk. Also, move up "dispc_pclk_diff()" before it is called. This will make the existing compatibles reusable if DSS features are same across two SoCs with the only difference being the pixel clock. Fixes: 7246e0929945 ("drm/tidss: Add OLDI bridge support") Reviewed-by: Devarsh Thakkar Signed-off-by: Jayesh Choudhary --- drivers/gpu/drm/tidss/tidss_dispc.c | 77 +++++++++++------------------ drivers/gpu/drm/tidss/tidss_dispc.h | 1 - drivers/gpu/drm/tidss/tidss_drv.h | 5 ++ 3 files changed, 34 insertions(+), 49 deletions(-) diff --git a/drivers/gpu/drm/tidss/tidss_dispc.c b/drivers/gpu/drm/tidss/ti= dss_dispc.c index 3f6cff2ab1b2..fb59a6a0f86a 100644 --- a/drivers/gpu/drm/tidss/tidss_dispc.c +++ b/drivers/gpu/drm/tidss/tidss_dispc.c @@ -58,10 +58,6 @@ static const u16 tidss_k2g_common_regs[DISPC_COMMON_REG_= TABLE_LEN] =3D { const struct dispc_features dispc_k2g_feats =3D { .min_pclk_khz =3D 4375, =20 - .max_pclk_khz =3D { - [DISPC_VP_DPI] =3D 150000, - }, - /* * XXX According TRM the RGB input buffer width up to 2560 should * work on 3 taps, but in practice it only works up to 1280. @@ -144,11 +140,6 @@ static const u16 tidss_am65x_common_regs[DISPC_COMMON_= REG_TABLE_LEN] =3D { }; =20 const struct dispc_features dispc_am65x_feats =3D { - .max_pclk_khz =3D { - [DISPC_VP_DPI] =3D 165000, - [DISPC_VP_OLDI_AM65X] =3D 165000, - }, - .scaling =3D { .in_width_max_5tap_rgb =3D 1280, .in_width_max_3tap_rgb =3D 2560, @@ -244,11 +235,6 @@ static const u16 tidss_j721e_common_regs[DISPC_COMMON_= REG_TABLE_LEN] =3D { }; =20 const struct dispc_features dispc_j721e_feats =3D { - .max_pclk_khz =3D { - [DISPC_VP_DPI] =3D 170000, - [DISPC_VP_INTERNAL] =3D 600000, - }, - .scaling =3D { .in_width_max_5tap_rgb =3D 2048, .in_width_max_3tap_rgb =3D 4096, @@ -315,11 +301,6 @@ const struct dispc_features dispc_j721e_feats =3D { }; =20 const struct dispc_features dispc_am625_feats =3D { - .max_pclk_khz =3D { - [DISPC_VP_DPI] =3D 165000, - [DISPC_VP_INTERNAL] =3D 170000, - }, - .scaling =3D { .in_width_max_5tap_rgb =3D 1280, .in_width_max_3tap_rgb =3D 2560, @@ -376,15 +357,6 @@ const struct dispc_features dispc_am625_feats =3D { }; =20 const struct dispc_features dispc_am62a7_feats =3D { - /* - * if the code reaches dispc_mode_valid with VP1, - * it should return MODE_BAD. - */ - .max_pclk_khz =3D { - [DISPC_VP_TIED_OFF] =3D 0, - [DISPC_VP_DPI] =3D 165000, - }, - .scaling =3D { .in_width_max_5tap_rgb =3D 1280, .in_width_max_3tap_rgb =3D 2560, @@ -441,10 +413,6 @@ const struct dispc_features dispc_am62a7_feats =3D { }; =20 const struct dispc_features dispc_am62l_feats =3D { - .max_pclk_khz =3D { - [DISPC_VP_DPI] =3D 165000, - }, - .subrev =3D DISPC_AM62L, =20 .common =3D "common", @@ -1347,25 +1315,49 @@ static void dispc_vp_set_default_color(struct dispc= _device *dispc, DISPC_OVR_DEFAULT_COLOR2, (v >> 32) & 0xffff); } =20 +/* + * Calculate the percentage difference between the requested pixel clock r= ate + * and the effective rate resulting from calculating the clock divider val= ue. + */ +unsigned int dispc_pclk_diff(unsigned long rate, unsigned long real_rate) +{ + int r =3D rate / 100, rr =3D real_rate / 100; + + return (unsigned int)(abs(((rr - r) * 100) / r)); +} + +static int check_pixel_clock(struct dispc_device *dispc, + u32 hw_videoport, unsigned long clock) +{ + if (clock > dispc->tidss->curr_max_pclk[hw_videoport] && + !dispc->tidss->is_oldi_vp[hw_videoport]) { + unsigned long round_clock =3D clk_round_rate(dispc->vp_clk[hw_videoport]= , clock); + + if (dispc_pclk_diff(clock, round_clock) > 5) + return -EINVAL; + + dispc->tidss->curr_max_pclk[hw_videoport] =3D round_clock; + } + + return 0; +} + enum drm_mode_status dispc_vp_mode_valid(struct dispc_device *dispc, u32 hw_videoport, const struct drm_display_mode *mode) { u32 hsw, hfp, hbp, vsw, vfp, vbp; enum dispc_vp_bus_type bus_type; - int max_pclk; =20 bus_type =3D dispc->feat->vp_bus_type[hw_videoport]; =20 - max_pclk =3D dispc->feat->max_pclk_khz[bus_type]; - - if (WARN_ON(max_pclk =3D=3D 0)) + if (WARN_ON(bus_type =3D=3D DISPC_VP_TIED_OFF)) return MODE_BAD; =20 if (mode->clock < dispc->feat->min_pclk_khz) return MODE_CLOCK_LOW; =20 - if (mode->clock > max_pclk) + if (check_pixel_clock(dispc, hw_videoport, mode->clock * 1000)) return MODE_CLOCK_HIGH; =20 if (mode->hdisplay > 4096) @@ -1437,17 +1429,6 @@ void dispc_vp_disable_clk(struct dispc_device *dispc= , u32 hw_videoport) clk_disable_unprepare(dispc->vp_clk[hw_videoport]); } =20 -/* - * Calculate the percentage difference between the requested pixel clock r= ate - * and the effective rate resulting from calculating the clock divider val= ue. - */ -unsigned int dispc_pclk_diff(unsigned long rate, unsigned long real_rate) -{ - int r =3D rate / 100, rr =3D real_rate / 100; - - return (unsigned int)(abs(((rr - r) * 100) / r)); -} - int dispc_vp_set_clk_rate(struct dispc_device *dispc, u32 hw_videoport, unsigned long rate) { diff --git a/drivers/gpu/drm/tidss/tidss_dispc.h b/drivers/gpu/drm/tidss/ti= dss_dispc.h index 60c1b400eb89..fbfe6e304ac8 100644 --- a/drivers/gpu/drm/tidss/tidss_dispc.h +++ b/drivers/gpu/drm/tidss/tidss_dispc.h @@ -78,7 +78,6 @@ enum dispc_dss_subrevision { =20 struct dispc_features { int min_pclk_khz; - int max_pclk_khz[DISPC_VP_MAX_BUS_TYPE]; =20 struct dispc_features_scaling scaling; =20 diff --git a/drivers/gpu/drm/tidss/tidss_drv.h b/drivers/gpu/drm/tidss/tids= s_drv.h index 82beaaceadb3..5cf21d5f56f2 100644 --- a/drivers/gpu/drm/tidss/tidss_drv.h +++ b/drivers/gpu/drm/tidss/tidss_drv.h @@ -25,6 +25,11 @@ struct tidss_device { const struct dispc_features *feat; struct dispc_device *dispc; bool is_oldi_vp[TIDSS_MAX_PORTS]; + /* + * stores highest pixel clock value found to be valid while checking + * supported modes for connected display + */ + unsigned long curr_max_pclk[TIDSS_MAX_PORTS]; =20 =20 unsigned int num_crtcs; --=20 2.34.1