public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Jani Nikula <jani.nikula@intel.com>
To: imre.deak@intel.com
Cc: intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH 10/13] drm/i915: gather backlight information at setup
Date: Thu, 14 Nov 2013 07:19:22 +0200	[thread overview]
Message-ID: <87zjp77e79.fsf@intel.com> (raw)
In-Reply-To: <1384362099.25182.85.camel@intelbox>

On Wed, 13 Nov 2013, Imre Deak <imre.deak@intel.com> wrote:
> On Fri, 2013-11-08 at 16:49 +0200, Jani Nikula wrote:
>> Prepare for being able to use the information at enable.
>> 
>> Signed-off-by: Jani Nikula <jani.nikula@intel.com>
>> ---
>>  drivers/gpu/drm/i915/intel_drv.h   |    2 ++
>>  drivers/gpu/drm/i915/intel_panel.c |   68 +++++++++++++++++++++++++++++-------
>>  2 files changed, 58 insertions(+), 12 deletions(-)
>> 
>> diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
>> index 7384a7b..6f2bc82 100644
>> --- a/drivers/gpu/drm/i915/intel_drv.h
>> +++ b/drivers/gpu/drm/i915/intel_drv.h
>> @@ -163,6 +163,8 @@ struct intel_panel {
>>  		u32 level;
>>  		u32 max;
>>  		bool enabled;
>> +		bool combination_mode;	/* gen 2/4 only */
>> +		bool active_low_pwm;
>>  		struct backlight_device *device;
>>  	} backlight;
>>  };
>> diff --git a/drivers/gpu/drm/i915/intel_panel.c b/drivers/gpu/drm/i915/intel_panel.c
>> index 3dd9f57d..0e8f0a3 100644
>> --- a/drivers/gpu/drm/i915/intel_panel.c
>> +++ b/drivers/gpu/drm/i915/intel_panel.c
>> @@ -490,13 +490,14 @@ static u32 i9xx_get_backlight(struct intel_connector *connector)
>>  {
>>  	struct drm_device *dev = connector->base.dev;
>>  	struct drm_i915_private *dev_priv = dev->dev_private;
>> +	struct intel_panel *panel = &connector->panel;
>>  	u32 val;
>>  
>>  	val = I915_READ(BLC_PWM_CTL) & BACKLIGHT_DUTY_CYCLE_MASK;
>>  	if (INTEL_INFO(dev)->gen < 4)
>>  		val >>= 1;
>>  
>> -	if (is_backlight_combination_mode(dev)) {
>> +	if (panel->backlight.combination_mode) {
>>  		u8 lbpc;
>>  
>>  		pci_read_config_byte(dev->pdev, PCI_LBPC, &lbpc);
>> @@ -558,7 +559,7 @@ static void i9xx_set_backlight(struct intel_connector *connector, u32 level)
>>  
>>  	WARN_ON(panel->backlight.max == 0);
>>  
>> -	if (is_backlight_combination_mode(dev)) {
>> +	if (panel->backlight.combination_mode) {
>>  		u8 lbpc;
>>  
>>  		lbpc = level * 0xfe / panel->backlight.max + 1;
>> @@ -966,46 +967,84 @@ static void intel_backlight_device_unregister(struct intel_connector *connector)
>>   */
>>  static int pch_setup_backlight(struct intel_connector *connector)
>>  {
>> +	struct drm_device *dev = connector->base.dev;
>> +	struct drm_i915_private *dev_priv = dev->dev_private;
>>  	struct intel_panel *panel = &connector->panel;
>> -	u32 val;
>> +	u32 cpu_ctl2, pch_ctl1, pch_ctl2, val;
>>  
>> -	panel->backlight.max = pch_get_max_backlight(connector);
>> +	pch_ctl1 = I915_READ(BLC_PWM_PCH_CTL1);
>> +	panel->backlight.active_low_pwm = pch_ctl1 & BLM_PCH_POLARITY;
>> +
>> +	pch_ctl2 = I915_READ(BLC_PWM_PCH_CTL2);
>> +	panel->backlight.max = pch_ctl2 >> 16;
>>  	if (!panel->backlight.max)
>>  		return -ENODEV;
>>  
>>  	val = pch_get_backlight(connector);
>>  	panel->backlight.level = intel_panel_compute_brightness(connector, val);
>>  
>> +	cpu_ctl2 = I915_READ(BLC_PWM_CPU_CTL2);
>> +	panel->backlight.enabled = (cpu_ctl2 & BLM_PWM_ENABLE) &&
>> +		(pch_ctl1 & BLM_PCH_PWM_ENABLE) && panel->backlight.level != 0;
>
> Don't we need to check here for QUIRK_NO_PCH_PWM_ENABLE?

Up front, I think the quirk is bogus, and it breaks machines.

Even if *we* don't set BLM_PCH_PWM_ENABLE on quirked machines, we just
expect the BIOS to have done it. So for checking whether the backlight
is enabled, this should be accurate.

BR,
Jani.


>
> --Imre
>
>> +
>>  	return 0;
>>  }
>>  
>>  static int i9xx_setup_backlight(struct intel_connector *connector)
>>  {
>> +	struct drm_device *dev = connector->base.dev;
>> +	struct drm_i915_private *dev_priv = dev->dev_private;
>>  	struct intel_panel *panel = &connector->panel;
>> -	u32 val;
>> +	u32 ctl, val;
>> +
>> +	ctl = I915_READ(BLC_PWM_CTL);
>> +
>> +	if (IS_GEN2(dev))
>> +		panel->backlight.combination_mode = ctl & BLM_LEGACY_MODE;
>> +
>> +	if (IS_PINEVIEW(dev))
>> +		panel->backlight.active_low_pwm = ctl & BLM_POLARITY_PNV;
>> +
>> +	panel->backlight.max = ctl >> 17;
>> +	if (panel->backlight.combination_mode)
>> +		panel->backlight.max *= 0xff;
>>  
>> -	panel->backlight.max = i9xx_get_max_backlight(connector);
>>  	if (!panel->backlight.max)
>>  		return -ENODEV;
>>  
>>  	val = i9xx_get_backlight(connector);
>>  	panel->backlight.level = intel_panel_compute_brightness(connector, val);
>>  
>> +	panel->backlight.enabled = panel->backlight.level != 0;
>> +
>>  	return 0;
>>  }
>>  
>>  static int i965_setup_backlight(struct intel_connector *connector)
>>  {
>> +	struct drm_device *dev = connector->base.dev;
>> +	struct drm_i915_private *dev_priv = dev->dev_private;
>>  	struct intel_panel *panel = &connector->panel;
>> -	u32 val;
>> +	u32 ctl, ctl2, val;
>> +
>> +	ctl2 = I915_READ(BLC_PWM_CTL2);
>> +	panel->backlight.combination_mode = ctl2 & BLM_COMBINATION_MODE;
>> +	panel->backlight.active_low_pwm = ctl2 & BLM_POLARITY_I965;
>> +
>> +	ctl = I915_READ(BLC_PWM_CTL);
>> +	panel->backlight.max = ctl >> 16;
>> +	if (panel->backlight.combination_mode)
>> +		panel->backlight.max *= 0xff;
>>  
>> -	panel->backlight.max = i965_get_max_backlight(connector);
>>  	if (!panel->backlight.max)
>>  		return -ENODEV;
>>  
>>  	val = i9xx_get_backlight(connector);
>>  	panel->backlight.level = intel_panel_compute_brightness(connector, val);
>>  
>> +	panel->backlight.enabled = (ctl2 & BLM_PWM_ENABLE) &&
>> +		panel->backlight.level != 0;
>> +
>>  	return 0;
>>  }
>>  
>> @@ -1015,7 +1054,7 @@ static int vlv_setup_backlight(struct intel_connector *connector)
>>  	struct drm_i915_private *dev_priv = dev->dev_private;
>>  	struct intel_panel *panel = &connector->panel;
>>  	enum pipe pipe;
>> -	u32 val;
>> +	u32 ctl, ctl2, val;
>>  
>>  	for_each_pipe(pipe) {
>>  		u32 cur_val = I915_READ(VLV_BLC_PWM_CTL(pipe));
>> @@ -1029,13 +1068,20 @@ static int vlv_setup_backlight(struct intel_connector *connector)
>>  			   cur_val);
>>  	}
>>  
>> -	panel->backlight.max = _vlv_get_max_backlight(dev, PIPE_A);
>> +	ctl2 = I915_READ(VLV_BLC_PWM_CTL2(PIPE_A));
>> +	panel->backlight.active_low_pwm = ctl2 & BLM_POLARITY_I965;
>> +
>> +	ctl = I915_READ(VLV_BLC_PWM_CTL(PIPE_A));
>> +	panel->backlight.max = ctl >> 16;
>>  	if (!panel->backlight.max)
>>  		return -ENODEV;
>>  
>>  	val = _vlv_get_backlight(dev, PIPE_A);
>>  	panel->backlight.level = intel_panel_compute_brightness(connector, val);
>>  
>> +	panel->backlight.enabled = (ctl2 & BLM_PWM_ENABLE) &&
>> +		panel->backlight.level != 0;
>> +
>>  	return 0;
>>  }
>>  
>> @@ -1059,8 +1105,6 @@ int intel_panel_setup_backlight(struct drm_connector *connector)
>>  		return ret;
>>  	}
>>  
>> -	panel->backlight.enabled = panel->backlight.level != 0;
>> -
>>  	intel_backlight_device_register(intel_connector);
>>  
>>  	panel->backlight.present = true;
>

-- 
Jani Nikula, Intel Open Source Technology Center

  reply	other threads:[~2013-11-14  5:22 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-08 14:48 [PATCH 00/13] drm/i915: backlight rewrite Jani Nikula
2013-11-08 14:48 ` [PATCH 01/13] drm/i915: clean up backlight conditional build Jani Nikula
2013-11-12 21:23   ` Imre Deak
2013-11-08 14:48 ` [PATCH 02/13] drm/i915: make backlight info per-connector Jani Nikula
2013-11-12 21:29   ` Imre Deak
2013-11-08 14:48 ` [PATCH 03/13] drm/i915: make asle notifications update backlight on all connectors Jani Nikula
2013-11-12 21:29   ` Imre Deak
2013-11-08 14:48 ` [PATCH 04/13] drm/i915: handle backlight through chip specific functions Jani Nikula
2013-11-12 21:36   ` Imre Deak
2013-11-12 23:19     ` Daniel Vetter
2013-11-08 14:48 ` [PATCH 05/13] drm/i915: fix gen2-gen3 backlight set Jani Nikula
2013-11-12 22:00   ` Imre Deak
2013-11-13  8:27     ` Jani Nikula
2013-11-13  9:04       ` Daniel Vetter
2013-11-13  9:12       ` Imre Deak
2013-11-08 14:48 ` [PATCH 06/13] drm/i915: vlv does not have pipe field in backlight registers Jani Nikula
2013-11-12 22:00   ` Imre Deak
2013-11-08 14:48 ` [PATCH 07/13] drm/i915: move backlight level setting in enable/disable to hooks Jani Nikula
2013-11-12 22:01   ` Imre Deak
2013-11-08 14:49 ` [PATCH 08/13] drm/i915: use the initialized backlight max value instead of reading it Jani Nikula
2013-11-12 22:42   ` Imre Deak
2013-11-13  8:39     ` Jani Nikula
2013-11-13  9:12       ` Daniel Vetter
2013-11-08 14:49 ` [PATCH 09/13] drm/i915: debug print on backlight register Jani Nikula
2013-11-12 22:48   ` Imre Deak
2013-11-13 10:22     ` Daniel Vetter
2013-11-08 14:49 ` [PATCH 10/13] drm/i915: gather backlight information at setup Jani Nikula
2013-11-13 17:01   ` Imre Deak
2013-11-14  5:19     ` Jani Nikula [this message]
2013-11-14  8:22       ` Imre Deak
2013-11-08 14:49 ` [PATCH 11/13] drm/i915: do full backlight setup at enable time Jani Nikula
2013-11-13 17:53   ` Imre Deak
2013-11-14  5:43     ` Jani Nikula
2013-11-14  8:27       ` Daniel Vetter
2013-11-14  8:28       ` Imre Deak
2013-11-14 10:13   ` [PATCH v2 " Jani Nikula
2013-11-14 10:46     ` Imre Deak
2013-11-14 10:14   ` [PATCH 11.5/13] drm/i915: remove QUIRK_NO_PCH_PWM_ENABLE Jani Nikula
2013-11-14 10:50     ` Imre Deak
2013-11-08 14:49 ` [PATCH 12/13] drm/i915: nuke get max backlight functions Jani Nikula
2013-11-13 17:54   ` Imre Deak
2013-11-08 14:49 ` [PATCH 13/13] drm/i915: do not save/restore backlight registers Jani Nikula
2013-11-12 23:25   ` Daniel Vetter
2013-11-13  8:40     ` Jani Nikula
2013-11-13 10:56     ` [PATCH v2] drm/i915: do not save/restore backlight registers in KMS Jani Nikula
2013-11-13 18:05       ` Imre Deak
2013-11-14 11:22         ` Daniel Vetter
2013-11-11  8:36 ` [PATCH 00/13] drm/i915: backlight rewrite Jani Nikula
2013-11-12 21:22 ` Imre Deak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zjp77e79.fsf@intel.com \
    --to=jani.nikula@intel.com \
    --cc=imre.deak@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox