From mboxrd@z Thu Jan 1 00:00:00 1970 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 90F9CC83F26 for ; Thu, 24 Jul 2025 09:50:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E4D3310E917; Thu, 24 Jul 2025 09:50:28 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="DI+WEhdc"; dkim-atps=neutral Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0041610E914 for ; Thu, 24 Jul 2025 09:50:26 +0000 (UTC) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id 2286C601DE; Thu, 24 Jul 2025 09:50:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C77AEC4CEF4; Thu, 24 Jul 2025 09:50:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1753350625; bh=aAWDBlkY+gH35bX083Tsc9S0NiwEW6cV9EEvBuzhrAg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=DI+WEhdcOE0W0Jm5G4k//z5/3G2oA0dhWKD0vfvVPDqYfCbrMcDdl4blnwb7a1NmB gOxYFnBQkKZw8LW41x9wWHOMhTZ/59NKgD5EXS7Vo6/hRh5D1zAjlCEa4NYCttxluM f/nAQzz/mj013fowzTb8NDoFWAyAeBY9mbDgjbotXDB6GZcSebH2o+KBSIAt0c3f05 qnvXRYHuPs+vTVXVzjwbfh87UItGw9JqDMbohH0rmwJV0ssziBV2PBX6pNlmxvEGvy mUtcvUxCCVDfEweHJnamze1Kvx9/HxSNQlmzqIXmRhgFMB9zfV+v2ZmFb6TRfQ+Rl/ VfhrXicAqH4QA== Received: from johan by xi.lan with local (Exim 4.98.2) (envelope-from ) id 1uesai-000000006aw-2ZCe; Thu, 24 Jul 2025 11:50:20 +0200 Date: Thu, 24 Jul 2025 11:50:20 +0200 From: Johan Hovold To: Neil Armstrong Cc: Dmitry Baryshkov , Christopher Obbard , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Rui Miguel Silva , Abel Vesa Subject: Re: [PATCH v6] drm/dp: clamp PWM bit count to advertised MIN and MAX capabilities Message-ID: References: <20250330-wip-obbardc-qcom-t14s-oled-panel-brightness-v6-1-84ad1cd1078a@linaro.org> <6612cd14-8353-4d3a-a248-5d32e0d3ca23@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Thu, Jul 24, 2025 at 11:42:38AM +0200, Neil Armstrong wrote: > On 24/07/2025 11:32, Dmitry Baryshkov wrote: > > On Thu, 24 Jul 2025 at 12:08, wrote: > >> On 20/05/2025 10:06, Johan Hovold wrote: > >>> On Fri, Apr 04, 2025 at 02:24:32PM +0100, Christopher Obbard wrote: > >>>> On Fri, 4 Apr 2025 at 09:54, Johan Hovold wrote: > >>>>> On Fri, Apr 04, 2025 at 08:54:29AM +0100, Christopher Obbard wrote: > >>>>>> On Mon, 31 Mar 2025 at 09:33, Johan Hovold wrote: > >>>>>>>> + /* > >>>>>>>> + * Per VESA eDP Spec v1.4b, section 3.3.10.2: > >>>>>>>> + * If DP_EDP_PWMGEN_BIT_COUNT is less than DP_EDP_PWMGEN_BIT_COUNT_CAP_MIN, > >>>>>>>> + * the sink must use the MIN value as the effective PWM bit count. > >>>>>>>> + * Clamp the reported value to the [MIN, MAX] capability range to ensure > >>>>>>>> + * correct brightness scaling on compliant eDP panels. > >>>>>>>> + */ > >>>>>>>> + pn = clamp(pn, pn_min, pn_max); > >>>>>>> > >>>>>>> You never make sure that pn_min <= pn_max so you could end up with > >>>>>>> pn < pn_min on broken hardware here. Not sure if it's something you need > >>>>>>> to worry about at this point. > >> > >> I'm trying to figure out what would be the behavior in this case ? > >> > >> - Warn ? > >> - pn_max = pn_min ? > >> - use BIT_COUNT as-is and ignore MIN/MAX ? > >> - pm_max = max(pn_min, pn_max); pm_min = min(pn_min, pn_max); ? > >> - reverse clamp? clamp(pn, pn_max, pn_min); ? > >> - generic clamp? clamp(pn, min(pn_min, pn_max), max(pn_min, pn_max)); ? > > > > Per the standard, the min >= 1 and max >= min. We don't need to bother > > about anything here. > > Yeah, I agree. But I think a: > if (likely(pn_min <= pn_max)) > is simple and doesn't cost much... > >> Or just bail out ? Yeah, just bail out. If we ever run into broken hardware like this, we can determine some workaround then. Johan