Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp8364793ybl; Thu, 16 Jan 2020 15:25:08 -0800 (PST) X-Google-Smtp-Source: APXvYqzOIE3u8KxAnMU8/WscnukzXRrZdTdl6Wn/h6goCsDeCqWQgy6pFh9syavBVVkQck0FNvR1 X-Received: by 2002:aca:d4c1:: with SMTP id l184mr1333265oig.172.1579217108207; Thu, 16 Jan 2020 15:25:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579217108; cv=none; d=google.com; s=arc-20160816; b=Lhd5C4Wj+XZ5eOp56czEMsOOALgq3uz8Zfw2Bft8mS8fu4etWfdrjA7C53/D4Lq1Iy womemzOHDk15bKQ6fWqW4YJiBNh0h97YM52B0qLmHySOz9pLnD5PJFtSack3qwdaAhlK 4XIJ0K0qIISm8BY1qA2VcxotAMfIdiRnI1ROS+WAMSpSwVC/W+fx31lYp2y0qf2KgGR1 uxCRokhe1h5ln/f6I1D+F6G9h2VhAE39WGH62tsebOkKmwqx95U9lFPsWrlUgP75Ud96 Z7itsahMAouo+tr7Ik9V86jRsXpzSFVq6ox9qYCu/x39LIeg9GBKo6Vem7+FpilLv41I 2T1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3CVLaakfxRzdFH7zrwhN9w61T/zDrE+8CRjo+khT3XY=; b=jbMzM5Y6NHx/YWDJi7r4Zsmk5CCcGFOJzXjZtD7AuwgVVqVt1Fp/MqWEn5EAoPjOlR L913wjoYFs6y2jN7cLT0rCcRx9AFE9/nfE3gsUH63d1c0MU+m+u1rOauEJ/2Y9hRDvvc Tsiso/4+DtwG+tq4jdXJ2hMCw7Mb6rToWz8P8m++ILULFxo+k4O9p7/+NSWA5wn5jDmj auIaRQL5DiH4+X0pAJi6n2RMHlFXHCQQdI+tf8qWaLDWhhaU/8NlijigNU6UFMpA+W9w LfApAR3Zz+EtUmof33i1AuEQD5mQt5XbTvwH01+/FMonRGOBy9MQsSfH6Q9bRsJcW1aM q1Vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LhTMwzvf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id a5si12948846oie.17.2020.01.16.15.24.55; Thu, 16 Jan 2020 15:25:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=LhTMwzvf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S2388604AbgAPVQz (ORCPT + 99 others); Thu, 16 Jan 2020 16:16:55 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:53965 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388584AbgAPVQy (ORCPT ); Thu, 16 Jan 2020 16:16:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579209413; 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=3CVLaakfxRzdFH7zrwhN9w61T/zDrE+8CRjo+khT3XY=; b=LhTMwzvfy5it6D3fFHgJTeo8zGjz748hnvuegVry+7Lr/ttQFwdcRGAf4UeFaPuxWCyTQw OvpzupqCyeQlG97h6ws642J7wrCYojwQb/WjRuwwM93ShINqpGskBr/O9SSKh5+bXWDmwM IUVsI/ntNcJlgHPZc8TodTHsUA9/IDs= 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-110-WUW8PizsPBu4_kQ5fg9ZDw-1; Thu, 16 Jan 2020 16:16:50 -0500 X-MC-Unique: WUW8PizsPBu4_kQ5fg9ZDw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 016F463C78; Thu, 16 Jan 2020 21:16:48 +0000 (UTC) Received: from malachite.bss.redhat.com (dhcp-10-20-1-90.bss.redhat.com [10.20.1.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id A508060C84; Thu, 16 Jan 2020 21:16:46 +0000 (UTC) From: Lyude Paul To: intel-gfx@lists.freedesktop.org Cc: dri-devel@lists.freedesktop.org, AceLan Kao , Perry Yuan , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , David Airlie , Daniel Vetter , Chris Wilson , =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= , Lee Shawn C , linux-kernel@vger.kernel.org Subject: [PATCH v3 2/5] drm/i915: Assume 100% brightness when not in DPCD control mode Date: Thu, 16 Jan 2020 16:16:09 -0500 Message-Id: <20200116211623.53799-3-lyude@redhat.com> In-Reply-To: <20200116211623.53799-1-lyude@redhat.com> References: <20200116211623.53799-1-lyude@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently we always determine the initial panel brightness level by simply reading the value from DP_EDP_BACKLIGHT_BRIGHTNESS_MSB/LSB. This seems wrong though, because if the panel is not currently in DPCD control mode there's not really any reason why there would be any brightness value programmed in the first place. This appears to be the case on the Lenovo ThinkPad X1 Extreme 2nd Generation, where the default value in these registers is always 0 on boot despite the fact the panel runs at max brightness by default. Getting the initial brightness value correct here is important as well, since the panel on this laptop doesn't behave well if it's ever put into DPCD control mode while the brightness level is programmed to 0. So, let's fix this by checking what the current backlight control mode is before reading the brightness level. If it's in DPCD control mode, we return the programmed brightness level. Otherwise we assume 100% brightness and return the highest possible brightness level. This also prevents us from accidentally programming a brightness level of 0. This is one of the many fixes that gets backlight controls working on the ThinkPad X1 Extreme 2nd Generation with optional 4K AMOLED screen. Changes since v1: * s/DP_EDP_DISPLAY_CONTROL_REGISTER/DP_EDP_BACKLIGHT_MODE_SET_REGISTER/ - Jani Tested-by: AceLan Kao Tested-by: Perry Yuan Signed-off-by: Lyude Paul Signed-off-by: Jani Nikula --- .../drm/i915/display/intel_dp_aux_backlight.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c b/driv= ers/gpu/drm/i915/display/intel_dp_aux_backlight.c index 345eed641455..5d4db5f8a165 100644 --- a/drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c +++ b/drivers/gpu/drm/i915/display/intel_dp_aux_backlight.c @@ -59,8 +59,25 @@ static u32 intel_dp_aux_get_backlight(struct intel_con= nector *connector) { struct intel_dp *intel_dp =3D enc_to_intel_dp(connector->encoder); u8 read_val[2] =3D { 0x0 }; + u8 mode_reg; u16 level =3D 0; =20 + if (drm_dp_dpcd_readb(&intel_dp->aux, + DP_EDP_BACKLIGHT_MODE_SET_REGISTER, + &mode_reg) !=3D 1) { + DRM_DEBUG_KMS("Failed to read the DPCD register 0x%x\n", + DP_EDP_BACKLIGHT_MODE_SET_REGISTER); + return 0; + } + + /* + * If we're not in DPCD control mode yet, the programmed brightness + * value is meaningless and we should assume max brightness + */ + if ((mode_reg & DP_EDP_BACKLIGHT_CONTROL_MODE_MASK) !=3D + DP_EDP_BACKLIGHT_CONTROL_MODE_DPCD) + return connector->panel.backlight.max; + if (drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_BACKLIGHT_BRIGHTNESS_MSB, &read_val, sizeof(read_val)) < 0) { DRM_DEBUG_KMS("Failed to read DPCD register 0x%x\n", --=20 2.24.1