Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4425434pxu; Wed, 9 Dec 2020 17:27:37 -0800 (PST) X-Google-Smtp-Source: ABdhPJy+gW4km1Jo9Vt6vC3hSgEWJewd0MezpKJklD3Xc5Q0dNRsW+rUPe3wdSiR33+BFrPhMWhd X-Received: by 2002:a50:9dc9:: with SMTP id l9mr4511567edk.377.1607563656790; Wed, 09 Dec 2020 17:27:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607563656; cv=none; d=google.com; s=arc-20160816; b=m6ESj6YuRVGn1IjyhhjQsSIfdMzjlqvYICKQnoFxXXe+Xxhy2FkVSSs9R39YF8TWJo Da+uQJU8dJqhl4cXjebjJYdQmq44XWq1ne7SJ7g4Yl4EFqXCYRP3ebGQR61hJR/+1Mpd PlOa07vJtxTpai4eDVcl+veZ2gSrlb5NasWbvAkGdpKPcIlRAQcxHNJNO/FE3KAr869b qeZFNu0dbCjNjAQYtX1OFR/t6ejRB88ZJFRyKmPojOCN7iQsozSU2w+M07elWTSe5zCn Jt0IVood+CpJXrph5uNWrE9QDQW42PUucIzAOX1KW6gHOOw0fZNC7Kt6vrHccOwGUiGA TrUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=izfsIhHmU1saCi345RQPFQ8A7inERVV3bSh1Rw0Vsk0=; b=g42MG3wBdGPubXA/yIQwGqL1rLyLukheJt3d3LfOqEGxSaki4uxWhm5wuO/VanxWkw Q3XYQJ6dcs5zMJMkWLIDE1K1igMCc8s2EmpXnxwZej916rvbirHtktCMnT58fLnpp/vj tK8rtSge1BUAmRarkyjJPaoZttYCA9yV8GO/eUydGDakaf1LvdrGujIhAuIqMxb0ibZh IFe4wNY5tsM/CaXqqLfq48P6R/YhWv6o/H/gMtUdlewy4JE8npzHfRtMHC9aCTaSSILb 2RUEH9oyPsSXz6pZnmoQfwvgAsPA4uBYI3hSmXLVUBRf4sTYPeG2T4kUYlVYhn1WusKc zuLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gbdFI2C5; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id oi22si1891030ejb.631.2020.12.09.17.27.14; Wed, 09 Dec 2020 17:27:36 -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=@redhat.com header.s=mimecast20190719 header.b=gbdFI2C5; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732389AbgLJBYV (ORCPT + 99 others); Wed, 9 Dec 2020 20:24:21 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:59053 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732271AbgLJBXn (ORCPT ); Wed, 9 Dec 2020 20:23:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607563336; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=izfsIhHmU1saCi345RQPFQ8A7inERVV3bSh1Rw0Vsk0=; b=gbdFI2C5i9AyBF5taw/kS+v4zAbAQ8pKeAN5jijgVqVAwNLx3uPW0ArF1Mfi9e/Vwt+bsr 3ayxld17MRffduUJugStMR5IH2EyC5aQioMNxvTpYwP6lztTUqdxHBhGuyRDH9tgAJMCPJ o3kmf4r0xl6EOoQmJkiUY4BbYRjhBIo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-582-Rt5UTp4oOW6VuiIZI_PcNA-1; Wed, 09 Dec 2020 20:22:11 -0500 X-MC-Unique: Rt5UTp4oOW6VuiIZI_PcNA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 81BC0612A5; Thu, 10 Dec 2020 01:22:08 +0000 (UTC) Received: from Whitewolf.redhat.com (ovpn-113-246.rdu2.redhat.com [10.10.113.246]) by smtp.corp.redhat.com (Postfix) with ESMTP id CAC6E1007625; Thu, 10 Dec 2020 01:22:05 +0000 (UTC) From: Lyude Paul To: dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, intel-gfx@lists.freedesktop.org Cc: Jani Nikula , Dave Airlie , greg.depoire@gmail.com, Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , David Airlie , Daniel Vetter , =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= , Imre Deak , =?UTF-8?q?Jos=C3=A9=20Roberto=20de=20Souza?= , Manasi Navare , Sean Paul , Lucas De Marchi , Juha-Pekka Heikkila , Dave Airlie , linux-kernel@vger.kernel.org (open list) Subject: [RFC 3/5] drm/i915/dp: Remove redundant AUX backlight frequency calculations Date: Wed, 9 Dec 2020 20:21:41 -0500 Message-Id: <20201210012143.729402-4-lyude@redhat.com> In-Reply-To: <20201210012143.729402-1-lyude@redhat.com> References: <20201210012143.729402-1-lyude@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Noticed this while moving all of the VESA backlight code in i915 over to DRM helpers: it would appear that we calculate the frequency value we want to write to DP_EDP_BACKLIGHT_FREQ_SET twice even though this value never actually changes during runtime. So, let's simplify things by just caching this value in intel_panel.backlight, and re-writing it as-needed. Signed-off-by: Lyude Paul Cc: Jani Nikula Cc: Dave Airlie Cc: greg.depoire@gmail.com --- .../drm/i915/display/intel_display_types.h | 1 + .../drm/i915/display/intel_dp_aux_backlight.c | 64 ++++++------------- 2 files changed, 19 insertions(+), 46 deletions(-) diff --git a/drivers/gpu/drm/i915/display/intel_display_types.h b/drivers/gpu/drm/i915/display/intel_display_types.h index 5bc5bfbc4551..133c9cb742a7 100644 --- a/drivers/gpu/drm/i915/display/intel_display_types.h +++ b/drivers/gpu/drm/i915/display/intel_display_types.h @@ -259,6 +259,7 @@ struct intel_panel { /* DPCD backlight */ u8 pwmgen_bit_count; + u8 pwm_freq_pre_divider; struct backlight_device *device; diff --git a/drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c b/drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c index 4fd536801b14..94ce5ca1affa 100644 --- a/drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c +++ b/drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c @@ -129,50 +129,6 @@ intel_dp_aux_set_backlight(const struct drm_connector_state *conn_state, u32 lev } } -/* - * Set PWM Frequency divider to match desired frequency in vbt. - * The PWM Frequency is calculated as 27Mhz / (F x P). - * - Where F = PWM Frequency Pre-Divider value programmed by field 7:0 of the - * EDP_BACKLIGHT_FREQ_SET register (DPCD Address 00728h) - * - Where P = 2^Pn, where Pn is the value programmed by field 4:0 of the - * EDP_PWMGEN_BIT_COUNT register (DPCD Address 00724h) - */ -static bool intel_dp_aux_set_pwm_freq(struct intel_connector *connector) -{ - struct drm_i915_private *dev_priv = to_i915(connector->base.dev); - struct intel_dp *intel_dp = intel_attached_dp(connector); - const u8 pn = connector->panel.backlight.pwmgen_bit_count; - int freq, fxp, f, fxp_actual, fxp_min, fxp_max; - - freq = dev_priv->vbt.backlight.pwm_freq_hz; - if (!freq) { - drm_dbg_kms(&dev_priv->drm, - "Use panel default backlight frequency\n"); - return false; - } - - fxp = DIV_ROUND_CLOSEST(KHz(DP_EDP_BACKLIGHT_FREQ_BASE_KHZ), freq); - f = clamp(DIV_ROUND_CLOSEST(fxp, 1 << pn), 1, 255); - fxp_actual = f << pn; - - /* Ensure frequency is within 25% of desired value */ - fxp_min = DIV_ROUND_CLOSEST(fxp * 3, 4); - fxp_max = DIV_ROUND_CLOSEST(fxp * 5, 4); - - if (fxp_min > fxp_actual || fxp_actual > fxp_max) { - drm_dbg_kms(&dev_priv->drm, "Actual frequency out of range\n"); - return false; - } - - if (drm_dp_dpcd_writeb(&intel_dp->aux, - DP_EDP_BACKLIGHT_FREQ_SET, (u8) f) < 0) { - drm_dbg_kms(&dev_priv->drm, - "Failed to write aux backlight freq\n"); - return false; - } - return true; -} - static void intel_dp_aux_enable_backlight(const struct intel_crtc_state *crtc_state, const struct drm_connector_state *conn_state) { @@ -213,9 +169,13 @@ static void intel_dp_aux_enable_backlight(const struct intel_crtc_state *crtc_st break; } - if (intel_dp->edp_dpcd[2] & DP_EDP_BACKLIGHT_FREQ_AUX_SET_CAP) - if (intel_dp_aux_set_pwm_freq(connector)) + if (panel->backlight.pwm_freq_pre_divider) { + if (drm_dp_dpcd_writeb(&intel_dp->aux, DP_EDP_BACKLIGHT_FREQ_SET, + panel->backlight.pwm_freq_pre_divider) == 1) new_dpcd_buf |= DP_EDP_BACKLIGHT_FREQ_AUX_SET_ENABLE; + else + drm_dbg_kms(&i915->drm, "Failed to write aux backlight frequency\n"); + } if (new_dpcd_buf != dpcd_buf) { if (drm_dp_dpcd_writeb(&intel_dp->aux, @@ -236,6 +196,14 @@ static void intel_dp_aux_disable_backlight(const struct drm_connector_state *old false); } +/* + * Compute PWM frequency divider value based off the frequency provided to us by the vbt. + * The PWM Frequency is calculated as 27Mhz / (F x P). + * - Where F = PWM Frequency Pre-Divider value programmed by field 7:0 of the + * EDP_BACKLIGHT_FREQ_SET register (DPCD Address 00728h) + * - Where P = 2^Pn, where Pn is the value programmed by field 4:0 of the + * EDP_PWMGEN_BIT_COUNT register (DPCD Address 00724h) + */ static u32 intel_dp_aux_calc_max_backlight(struct intel_connector *connector) { struct drm_i915_private *i915 = to_i915(connector->base.dev); @@ -287,8 +255,10 @@ static u32 intel_dp_aux_calc_max_backlight(struct intel_connector *connector) pn_min &= DP_EDP_PWMGEN_BIT_COUNT_MASK; pn_max &= DP_EDP_PWMGEN_BIT_COUNT_MASK; + /* Ensure frequency is within 25% of desired value */ fxp_min = DIV_ROUND_CLOSEST(fxp * 3, 4); fxp_max = DIV_ROUND_CLOSEST(fxp * 5, 4); + if (fxp_min < (1 << pn_min) || (255 << pn_max) < fxp_max) { drm_dbg_kms(&i915->drm, "VBT defined backlight frequency out of range\n"); @@ -309,7 +279,9 @@ static u32 intel_dp_aux_calc_max_backlight(struct intel_connector *connector) "Failed to write aux pwmgen bit count\n"); return max_backlight; } + panel->backlight.pwmgen_bit_count = pn; + panel->backlight.pwm_freq_pre_divider = f; max_backlight = (1 << pn) - 1; -- 2.28.0