From patchwork Thu May 4 00:28:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Puthikorn Voravootivat X-Patchwork-Id: 9710657 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0C40A60385 for ; Thu, 4 May 2017 00:29:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F299528648 for ; Thu, 4 May 2017 00:28:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E782D2867A; Thu, 4 May 2017 00:28:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A09E228648 for ; Thu, 4 May 2017 00:28:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AD9066E3DC; Thu, 4 May 2017 00:28:53 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-pf0-x236.google.com (mail-pf0-x236.google.com [IPv6:2607:f8b0:400e:c00::236]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5FD296E3CE for ; Thu, 4 May 2017 00:28:51 +0000 (UTC) Received: by mail-pf0-x236.google.com with SMTP id v14so2486947pfd.2 for ; Wed, 03 May 2017 17:28:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=qTULV2DDWcNBFJq7OuD4Fl0kkk5a04tjTsZQSnuvjQM=; b=aGZUL/Uynll245HptvvRFKp6l1yuN6BdiARh07Q0a2skFB4Ng46hnlBq6Kd4ScwjRp k5trCV7ig3a6bxoBWQ+oRUZK992PugNlKjX3vWbAiI9WsgoadRR6TM8sXo9/J+fz/4UA GZzXJjW0ja0vOxq05AqFFkHkNXDqAZkgYkNbwG+t5M5ZEDr/e47h3T2mmdXMexNSMBBe jvhZOg+FSn7Dp0ySGd6qBGOF5RwOByRZxnuvff+Ya0kmQqOK/Rgt+mzkZJhXsSzjVR+l l04/i20L8w3cfTqKRBD1uYITfo9EwtFOb+neJVe92wCyLDbDH5AVkSXg18naBosLrfn5 26Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=qTULV2DDWcNBFJq7OuD4Fl0kkk5a04tjTsZQSnuvjQM=; b=q0YPcfEZ80K/vIOPTg0wY8qY/5ebyVfn89dHNKwXc+oV4VJOvHfNNH0LB/+bf5vfB7 rH6Gt44TW8T0dWFET3jaGrLqv5I3ZpLlv72tdB45StWslILBsQGfUoSji/0nmzQ4cEyD WUT3Dmb0pduc8wZqXLf1MMzdC6geU8gLlQPWke5UlD4ZuiZpcrw0yCwRLgCCTiIiQZzj UNp/RyCPHnkgZ+PoDyZfui+TYYS6lCfGT0zAbVCaFij0xu/+weFB1aChaH2ds/1/VNx6 VQhqXzyfu3RJ7EVlC09ml39R4/Vgh5LtaSfzADkosjFTLkpPjxYFswryQ+Mf9seJ0hJt Yjsw== X-Gm-Message-State: AN3rC/4sblYGfXmRga551EvRyOSVUgDssURjNb/B4fWKKtRkDGssc33X kmDBEDv7ZvxG20RM X-Received: by 10.99.109.9 with SMTP id i9mr16348958pgc.56.1493857730867; Wed, 03 May 2017 17:28:50 -0700 (PDT) Received: from puthik2.mtv.corp.google.com ([172.22.64.53]) by smtp.gmail.com with ESMTPSA id c90sm457478pfk.96.2017.05.03.17.28.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 May 2017 17:28:49 -0700 (PDT) Received: by puthik2.mtv.corp.google.com (Postfix, from userid 218808) id 55AE911F8E8; Wed, 3 May 2017 17:28:46 -0700 (PDT) From: Puthikorn Voravootivat To: intel-gfx@lists.freedesktop.org Date: Wed, 3 May 2017 17:28:33 -0700 Message-Id: <20170504002836.120988-7-puthik@chromium.org> X-Mailer: git-send-email 2.13.0.rc1.294.g07d810a77f-goog In-Reply-To: <20170504002836.120988-1-puthik@chromium.org> References: <20170504002836.120988-1-puthik@chromium.org> Cc: dri-devel@lists.freedesktop.org, Puthikorn Voravootivat , Dhinakaran Pandiyan Subject: [Intel-gfx] [PATCH v5 6/9] drm/i915: Support dynamic backlight via DPCD register X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP This patch enables dynamic backlight by default for eDP panel that supports this feature via DPCD register and set minimum / maximum brightness to 0% and 100% of the normal brightness. Signed-off-by: Puthikorn Voravootivat --- drivers/gpu/drm/i915/intel_dp_aux_backlight.c | 39 ++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/i915/intel_dp_aux_backlight.c b/drivers/gpu/drm/i915/intel_dp_aux_backlight.c index 5ef3ade7c40e..7d323af96636 100644 --- a/drivers/gpu/drm/i915/intel_dp_aux_backlight.c +++ b/drivers/gpu/drm/i915/intel_dp_aux_backlight.c @@ -97,10 +97,27 @@ intel_dp_aux_set_backlight(struct intel_connector *connector, u32 level) } } +/* + * Set minimum / maximum dynamic brightness percentage. This value is expressed + * as the percentage of normal brightness in 5% increments. + */ +static void +intel_dp_aux_set_dynamic_backlight_percent(struct intel_dp *intel_dp, + u32 min, u32 max) +{ + u8 dbc[] = { DIV_ROUND_CLOSEST(min, 5), DIV_ROUND_CLOSEST(max, 5) }; + + if (drm_dp_dpcd_write(&intel_dp->aux, DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, + dbc, sizeof(dbc) < 0)) { + DRM_DEBUG_KMS("Failed to write aux DBC brightness level\n"); + } +} + static void intel_dp_aux_enable_backlight(struct intel_connector *connector) { struct intel_dp *intel_dp = enc_to_intel_dp(&connector->encoder->base); uint8_t dpcd_buf = 0; + uint8_t new_dpcd_buf = 0; uint8_t edp_backlight_mode = 0; if (drm_dp_dpcd_readb(&intel_dp->aux, @@ -110,18 +127,15 @@ static void intel_dp_aux_enable_backlight(struct intel_connector *connector) return; } + new_dpcd_buf = dpcd_buf; edp_backlight_mode = dpcd_buf & DP_EDP_BACKLIGHT_CONTROL_MODE_MASK; switch (edp_backlight_mode) { case DP_EDP_BACKLIGHT_CONTROL_MODE_PWM: case DP_EDP_BACKLIGHT_CONTROL_MODE_PRESET: case DP_EDP_BACKLIGHT_CONTROL_MODE_PRODUCT: - dpcd_buf &= ~DP_EDP_BACKLIGHT_CONTROL_MODE_MASK; - dpcd_buf |= DP_EDP_BACKLIGHT_CONTROL_MODE_DPCD; - if (drm_dp_dpcd_writeb(&intel_dp->aux, - DP_EDP_BACKLIGHT_MODE_SET_REGISTER, dpcd_buf) < 0) { - DRM_DEBUG_KMS("Failed to write aux backlight mode\n"); - } + new_dpcd_buf &= ~DP_EDP_BACKLIGHT_CONTROL_MODE_MASK; + new_dpcd_buf |= DP_EDP_BACKLIGHT_CONTROL_MODE_DPCD; break; /* Do nothing when it is already DPCD mode */ @@ -130,6 +144,19 @@ static void intel_dp_aux_enable_backlight(struct intel_connector *connector) break; } + if (intel_dp->edp_dpcd[2] & DP_EDP_DYNAMIC_BACKLIGHT_CAP) { + new_dpcd_buf |= DP_EDP_DYNAMIC_BACKLIGHT_ENABLE; + intel_dp_aux_set_dynamic_backlight_percent(intel_dp, 0, 100); + DRM_DEBUG_KMS("Enable dynamic brightness.\n"); + } + + if (new_dpcd_buf != dpcd_buf) { + if (drm_dp_dpcd_writeb(&intel_dp->aux, + DP_EDP_BACKLIGHT_MODE_SET_REGISTER, new_dpcd_buf) < 0) { + DRM_DEBUG_KMS("Failed to write aux backlight mode\n"); + } + } + set_aux_backlight_enable(intel_dp, true); }