Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1904132ybl; Tue, 3 Dec 2019 14:44:40 -0800 (PST) X-Google-Smtp-Source: APXvYqyEgils8qi5xIfC6aMvAlsuXJoXwJJ/V78di9rEBPPFsRXxMEvFExUrJjTbVHP437TRRNXL X-Received: by 2002:a9d:7394:: with SMTP id j20mr177925otk.273.1575413080793; Tue, 03 Dec 2019 14:44:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575413080; cv=none; d=google.com; s=arc-20160816; b=n1aIwcrx3gq0j6dD8OtWERvy/aaC1AyvMrx/x2pHXO79YtrDIpHyPNVMtQwhE77z8y NmMQQjt0v9ppZSBVQp4XVo5HP6Bqcz4W5PXHltaHMPXTZSMCAl+zN6xokv9xgBpnj2aQ IwPdyL6mZbpwFZPDTZQ1wQXc2R6jIRQIhJBbMrFat7YdQp60zV3JpEGHlake/4ysd7Lm 3mkC0RfT2T+VYZczh99YTrnbnR1gB2olwXmExZiy5QXC1orghdxfYc0PFMULjD32Xl6J jeOv9JBaZHKWwQn5jXgNUVYncvyoxDBuRJD/ok42k1QD/92TrdD+tMtcZhVQiAqEoS5B H4ZQ== 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=+sDgbMqjO9PDnPDuImNP6HXuoqamT1anUKE/7ClETRA=; b=uYMEnGCahj04OKTQY4n4MO+e8a6cXXs3tf5iEnAkRv3ZQsAkbhh9PMnAjrJIa2OBe6 Qtsu/6VlV4RY338+2S24veQx6I5PfQSx2Brl5z8Cs71AN1/hIRIbMtr2spxDe22Nehx/ HC0KbQgQKrx3OkSp4C5Ha1oWyEpk6wmF3coGpI510Pp2GmgM2jZWTJabB6c/8uVz8Tqv uMxQG5EOpSI6doLQfcmYPuLLQ4p3n218kSmdPX02xKujQRppGLe2LUi2/CTrDVtu4wSX lUM28Mb/NDycmJ1igU54jc/3sWKiMcFaJqB8mubtrOSDAhZWuCRY9YviwC2ikhCXVvgd NtTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=X+aA1rBT; 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 y24si1966259oih.24.2019.12.03.14.44.29; Tue, 03 Dec 2019 14:44:40 -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=X+aA1rBT; 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 S1728739AbfLCWm6 (ORCPT + 99 others); Tue, 3 Dec 2019 17:42:58 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:43421 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728707AbfLCWmv (ORCPT ); Tue, 3 Dec 2019 17:42:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575412970; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+sDgbMqjO9PDnPDuImNP6HXuoqamT1anUKE/7ClETRA=; b=X+aA1rBTY+q2Jy+07ak2Fz1rKtZA7h/F/ulyQxVdO2wXNEoS/gv2WFTau2n2tlu0s4dOuK 6GUzweMwmDHRC62i64oM9BQncJzVe55dlqE+bTJwZE1IJm+WFNCJGJ2mAwtpVZO80sG8o6 N4QumWRd+pcvxp+jcCIukrDOOwjnGbQ= 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-216-4k8qimMGOBeQPasm2opFyw-1; Tue, 03 Dec 2019 17:42:49 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 411EA800D54; Tue, 3 Dec 2019 22:42:47 +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 6637F5DA32; Tue, 3 Dec 2019 22:42:43 +0000 (UTC) From: Lyude Paul To: intel-gfx@lists.freedesktop.org Cc: Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , David Airlie , Daniel Vetter , Chris Wilson , =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= , Lee Shawn C , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] drm/i915: Assume 100% brightness when not in DPCD control mode Date: Tue, 3 Dec 2019 17:42:35 -0500 Message-Id: <20191203224236.230930-1-lyude@redhat.com> In-Reply-To: <87tv6hinv1.fsf@intel.com> References: <87tv6hinv1.fsf@intel.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: 4k8qimMGOBeQPasm2opFyw-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=US-ASCII 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 Signed-off-by: Lyude Paul --- .../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/driver= s/gpu/drm/i915/display/intel_dp_aux_backlight.c index fad470553cf9..4d467e7d29eb 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_conne= ctor *connector) { =09struct intel_dp *intel_dp =3D enc_to_intel_dp(&connector->encoder->base= ); =09u8 read_val[2] =3D { 0x0 }; +=09u8 mode_reg; =09u16 level =3D 0; =20 +=09if (drm_dp_dpcd_readb(&intel_dp->aux, +=09=09=09 DP_EDP_BACKLIGHT_MODE_SET_REGISTER, +=09=09=09 &mode_reg) !=3D 1) { +=09=09DRM_DEBUG_KMS("Failed to read the DPCD register 0x%x\n", +=09=09=09 DP_EDP_BACKLIGHT_MODE_SET_REGISTER); +=09=09return 0; +=09} + +=09/* +=09 * If we're not in DPCD control mode yet, the programmed brightness +=09 * value is meaningless and we should assume max brightness +=09 */ +=09if ((mode_reg & DP_EDP_BACKLIGHT_CONTROL_MODE_MASK) !=3D +=09 DP_EDP_BACKLIGHT_CONTROL_MODE_DPCD) +=09=09return connector->panel.backlight.max; + =09if (drm_dp_dpcd_read(&intel_dp->aux, DP_EDP_BACKLIGHT_BRIGHTNESS_MSB, =09=09=09 &read_val, sizeof(read_val)) < 0) { =09=09DRM_DEBUG_KMS("Failed to read DPCD register 0x%x\n", --=20 2.23.0