All of lore.kernel.org
 help / color / mirror / Atom feed
From: Aaron Lu <aaron.lu@intel.com>
To: Danny Baumann <dannybaumann@web.de>
Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org,
	Zhang Rui <rui.zhang@intel.com>, Len Brown <lenb@kernel.org>
Subject: Re: [PATCH v2 3/3] ACPI video: Fix applying indexed initial brightness value.
Date: Mon, 18 Mar 2013 16:16:39 +0800	[thread overview]
Message-ID: <5146CD67.8070203@intel.com> (raw)
In-Reply-To: <1363342248-6496-3-git-send-email-dannybaumann@web.de>

On 03/15/2013 06:10 PM, Danny Baumann wrote:
> The value initially read via _BQC also needs to be offset by 2 to
> compensate for the first 2 special items in _BCL. Introduce a helper
> function that does the BQC-value-to-level conversion in order to not
> needlessly duplicate code.
> 
> Signed-off-by: Danny Baumann <dannybaumann@web.de>
> ---
>  drivers/acpi/video.c | 52 +++++++++++++++++++++++++++++++++-------------------
>  1 file changed, 33 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c
> index 5ef329a..8faea35 100644
> --- a/drivers/acpi/video.c
> +++ b/drivers/acpi/video.c
> @@ -450,6 +450,26 @@ static struct dmi_system_id video_dmi_table[] __initdata = {
>  	{}
>  };
>  
> +static unsigned long long
> +acpi_video_bqc_value_to_level(struct acpi_video_device *device,
> +			      unsigned long long bqc_value)
> +{
> +	unsigned long long level;
> +
> +	if (device->brightness->flags._BQC_use_index) {
> +		if (device->brightness->flags._BCL_reversed)
> +			bqc_value = device->brightness->count - 3 - bqc_value;
> +
> +		level = device->brightness->levels[bqc_value + 2];

I don't understand this, what does the +2 have to do here?
_BQC returned us an index, and then we should just convert it to level,
why +2?

The only explanation would be, for BIOS tables that return _BQC as
index, they are indexing from the 3rd entry. Is it the case? If so, I
think we need to put a comment here.

> +	} else {
> +		level = bqc_value;
> +	}
> +
> +	level += bqc_offset_aml_bug_workaround;
> +
> +	return level;
> +}
> +
>  static int
>  acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
>  					unsigned long long *level, int raw)
> @@ -472,14 +492,8 @@ acpi_video_device_lcd_get_level_current(struct acpi_video_device *device,
>  				return 0;
>  			}
>  
> -			if (device->brightness->flags._BQC_use_index) {
> -				if (device->brightness->flags._BCL_reversed)
> -					*level = device->brightness->count
> -								 - 3 - (*level);
> -				*level = device->brightness->levels[*level + 2];
> +			*level = acpi_video_bqc_value_to_level(device, *level);
>  
> -			}
> -			*level += bqc_offset_aml_bug_workaround;
>  			for (i = 2; i < device->brightness->count; i++)
>  				if (device->brightness->levels[i] == *level) {
>  					device->brightness->curr = *level;
> @@ -727,24 +741,24 @@ acpi_video_init_brightness(struct acpi_video_device *device)
>  
>  	br->flags._BQC_use_index = (level == max_level ? 0 : 1);
>  
> -	if (!br->flags._BQC_use_index) {
> -		/*
> -		 * Set the backlight to the initial state.
> -		 * On some buggy laptops, _BQC returns an uninitialized value
> -		 * when invoked for the first time, i.e. level_old is invalid.
> -		 * set the backlight to max_level in this case
> -		 */
> -		if (use_bios_initial_backlight) {

-------------------------------------------------------------------
> +	if (use_bios_initial_backlight) {
> +		if (!br->flags._BQC_use_index) {
> +			/*
> +			 * Set the backlight to the initial state.
> +			 * On some buggy laptops, _BQC returns an uninitialized
> +			 * value when invoked for the first time, i.e.
> +			 * level_old is invalid. Set the backlight to max_level
> +			 * in this case.
> +			 */
>  			for (i = 2; i < br->count; i++)
>  				if (level_old == br->levels[i]) {
>  					level = level_old;
>  					break;
>  				}
> +		} else {
> +			level = acpi_video_bqc_value_to_level(device,
> +							      level_old);

What about we convert the value to level first?

	if (use_bios_initial_backlight) {
		level = acpi_video_bqc_value_to_level(device, level_old);
		/*
		 * Set the backlight to the initial state.
		 * On some buggy laptops, _BQC returns an uninitialized
		 * value when invoked for the first time, i.e.
		 * level_old is invalid(no matter it is a level, or an
		 * index.) Set the backlight to max_level in this case.
		 */
		for (i = 2; i < br->count; i++)
			if (level == br->levels[i])
				break;
		if (i == br->count)
			level = max_level;
	}

Thanks,
Aaron

>  		}
> -	} else {
> -		if (br->flags._BCL_reversed)
> -			level_old = (br->count - 1) - level_old;
> -		level = br->levels[level_old];
>  	}
>  
>  set_level:
> 


  reply	other threads:[~2013-03-18  8:15 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-15 10:10 [PATCH v2 1/3] ACPI video: Fix brightness control initialization for some laptops Danny Baumann
2013-03-15 10:10 ` [PATCH v2 2/3] ACPI video: Make logic a little easier to understand Danny Baumann
2013-03-15 10:10 ` [PATCH v2 3/3] ACPI video: Fix applying indexed initial brightness value Danny Baumann
2013-03-18  8:16   ` Aaron Lu [this message]
2013-03-18  8:26     ` Danny Baumann
2013-03-18  8:34       ` Aaron Lu
2013-03-18  7:26 ` [PATCH v2 1/3] ACPI video: Fix brightness control initialization for some laptops Aaron Lu
2013-03-18  8:22   ` Danny Baumann
2013-03-18  8:31     ` Aaron Lu

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=5146CD67.8070203@intel.com \
    --to=aaron.lu@intel.com \
    --cc=dannybaumann@web.de \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rui.zhang@intel.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.