diff mbox

[v2] dell-laptop: Fix keyboard led max_brightness property for Dell Latitude E6410

Message ID 1508349961-15051-1-git-send-email-pali.rohar@gmail.com (mailing list archive)
State Superseded, archived
Delegated to: Darren Hart
Headers show

Commit Message

Pali Rohár Oct. 18, 2017, 6:06 p.m. UTC
This machine reports number of keyboard backlight led levels, instead of
value of the last led level index. Therefore max_brightness properly needs
to be subtracted by 1 to match led max_brightness API.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
Reported-by: Gabriel M. Elder <gabriel@tekgnowsys.com>
Link: https://bugzilla.kernel.org/show_bug.cgi?id=196913
---
Changes since v1:
* Update kbd_info.levels at initialization time based on quirk
---
 drivers/platform/x86/dell-laptop.c |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Comments

Andy Shevchenko Oct. 18, 2017, 7:09 p.m. UTC | #1
On Wed, Oct 18, 2017 at 9:06 PM, Pali Rohár <pali.rohar@gmail.com> wrote:
> This machine reports number of keyboard backlight led levels, instead of
> value of the last led level index. Therefore max_brightness properly needs
> to be subtracted by 1 to match led max_brightness API.
>
> Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
> Reported-by: Gabriel M. Elder <gabriel@tekgnowsys.com>
> Link: https://bugzilla.kernel.org/show_bug.cgi?id=196913

> +       u8 kbd_led_num_of_levels_instead_of_last_index;

Sorry for last minute review comments.

First of all, can it be just boolean?

Naming... Yes, too hard as always was, is and will be.

What about just

kbd_led_use_levels?

Also, does it make sense to create a quirks as an unsigned long and
put there corresponding bits with definitions?

/* Comment what is this for */
#define QUIRK_KBD_LED_USE_LEVELS   0

unsigned long quirks;

?

> +       if (quirks && quirks->kbd_led_num_of_levels_instead_of_last_index && info->levels)
> +               info->levels--;

With last suggestion if becomes something like

if (quirks & BIT(QUIRK_KBD_LED_USE_LEVELS) && info->levels)
Pali Rohár Oct. 18, 2017, 7:14 p.m. UTC | #2
On Wednesday 18 October 2017 22:09:41 Andy Shevchenko wrote:
> On Wed, Oct 18, 2017 at 9:06 PM, Pali Rohár <pali.rohar@gmail.com> wrote:
> > This machine reports number of keyboard backlight led levels, instead of
> > value of the last led level index. Therefore max_brightness properly needs
> > to be subtracted by 1 to match led max_brightness API.
> >
> > Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
> > Reported-by: Gabriel M. Elder <gabriel@tekgnowsys.com>
> > Link: https://bugzilla.kernel.org/show_bug.cgi?id=196913
> 
> > +       u8 kbd_led_num_of_levels_instead_of_last_index;
> 
> Sorry for last minute review comments.
> 
> First of all, can it be just boolean?

Yes, touchpad_led and needs_kbd_timeouts are booleans too.

> Naming... Yes, too hard as always was, is and will be.
> 
> What about just
> 
> kbd_led_use_levels?

If you code:

  if (quirks->kbd_led_use_levels)
    info->levels--;

Then I think it does not help reader what that quirk represent.

> Also, does it make sense to create a quirks as an unsigned long and
> put there corresponding bits with definitions?

Problem is that part of quirk structure is variable length array
kbd_timeouts. So one unsigned long does not help.

> /* Comment what is this for */
> #define QUIRK_KBD_LED_USE_LEVELS   0
> 
> unsigned long quirks;
> 
> ?
> 
> > +       if (quirks && quirks->kbd_led_num_of_levels_instead_of_last_index && info->levels)
> > +               info->levels--;
> 
> With last suggestion if becomes something like
> 
> if (quirks & BIT(QUIRK_KBD_LED_USE_LEVELS) && info->levels)
> 
>
Darren Hart Oct. 18, 2017, 8 p.m. UTC | #3
On Wed, Oct 18, 2017 at 08:06:01PM +0200, Pali Rohár wrote:
> This machine reports number of keyboard backlight led levels, instead of
> value of the last led level index. Therefore max_brightness properly needs
> to be subtracted by 1 to match led max_brightness API.
> 
> Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
> Reported-by: Gabriel M. Elder <gabriel@tekgnowsys.com>
> Link: https://bugzilla.kernel.org/show_bug.cgi?id=196913
> ---
> Changes since v1:
> * Update kbd_info.levels at initialization time based on quirk

This looks much cleaner IMO, thanks.

> ---
>  drivers/platform/x86/dell-laptop.c |   17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> diff --git a/drivers/platform/x86/dell-laptop.c b/drivers/platform/x86/dell-laptop.c
> index f42159f..3f9be8a 100644
> --- a/drivers/platform/x86/dell-laptop.c
> +++ b/drivers/platform/x86/dell-laptop.c
> @@ -49,6 +49,7 @@
>  
>  struct quirk_entry {
>  	u8 touchpad_led;
> +	u8 kbd_led_num_of_levels_instead_of_last_index;

OK, I forgot to comment on this one :-)

A name should be descriptive, but that's just too much. So let's use something
shorter, and add a comment if one is really needed to explain what it is.
Something like:

u8 kbd_led_reports_num_levels is shorter, but still awfully long.

u8 kbd_led_num_levels  is shorter, but obviously looks like it should be the
levels value instead of a bool. So the above is probably best.


>  
>  	int needs_kbd_timeouts;
>  	/*
> @@ -79,6 +80,10 @@ static int __init dmi_matched(const struct dmi_system_id *dmi)
>  	.kbd_timeouts = { 0, 5, 15, 60, 5 * 60, 15 * 60, -1 },
>  };
>  
> +static struct quirk_entry quirk_dell_latitude_e6410 = {
> +	.kbd_led_num_of_levels_instead_of_last_index = 1,
> +};
> +
>  static struct platform_driver platform_driver = {
>  	.driver = {
>  		.name = "dell-laptop",
> @@ -280,6 +285,15 @@ static int __init dmi_matched(const struct dmi_system_id *dmi)
>  		},
>  		.driver_data = &quirk_dell_xps13_9333,
>  	},
> +	{
> +		.callback = dmi_matched,
> +		.ident = "Dell Latitude E6410",
> +		.matches = {
> +			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
> +			DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6410"),
> +		},
> +		.driver_data = &quirk_dell_latitude_e6410,
> +	},
>  	{ }
>  };
>  
> @@ -1200,6 +1214,9 @@ static int kbd_get_info(struct kbd_info *info)
>  	units = (buffer->output[2] >> 8) & 0xFF;
>  	info->levels = (buffer->output[2] >> 16) & 0xFF;
>  
> +	if (quirks && quirks->kbd_led_num_of_levels_instead_of_last_index && info->levels)
> +		info->levels--;
> +
>  	if (units & BIT(0))
>  		info->seconds = (buffer->output[3] >> 0) & 0xFF;
>  	if (units & BIT(1))
> -- 
> 1.7.9.5
> 
>
diff mbox

Patch

diff --git a/drivers/platform/x86/dell-laptop.c b/drivers/platform/x86/dell-laptop.c
index f42159f..3f9be8a 100644
--- a/drivers/platform/x86/dell-laptop.c
+++ b/drivers/platform/x86/dell-laptop.c
@@ -49,6 +49,7 @@ 
 
 struct quirk_entry {
 	u8 touchpad_led;
+	u8 kbd_led_num_of_levels_instead_of_last_index;
 
 	int needs_kbd_timeouts;
 	/*
@@ -79,6 +80,10 @@  static int __init dmi_matched(const struct dmi_system_id *dmi)
 	.kbd_timeouts = { 0, 5, 15, 60, 5 * 60, 15 * 60, -1 },
 };
 
+static struct quirk_entry quirk_dell_latitude_e6410 = {
+	.kbd_led_num_of_levels_instead_of_last_index = 1,
+};
+
 static struct platform_driver platform_driver = {
 	.driver = {
 		.name = "dell-laptop",
@@ -280,6 +285,15 @@  static int __init dmi_matched(const struct dmi_system_id *dmi)
 		},
 		.driver_data = &quirk_dell_xps13_9333,
 	},
+	{
+		.callback = dmi_matched,
+		.ident = "Dell Latitude E6410",
+		.matches = {
+			DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
+			DMI_MATCH(DMI_PRODUCT_NAME, "Latitude E6410"),
+		},
+		.driver_data = &quirk_dell_latitude_e6410,
+	},
 	{ }
 };
 
@@ -1200,6 +1214,9 @@  static int kbd_get_info(struct kbd_info *info)
 	units = (buffer->output[2] >> 8) & 0xFF;
 	info->levels = (buffer->output[2] >> 16) & 0xFF;
 
+	if (quirks && quirks->kbd_led_num_of_levels_instead_of_last_index && info->levels)
+		info->levels--;
+
 	if (units & BIT(0))
 		info->seconds = (buffer->output[3] >> 0) & 0xFF;
 	if (units & BIT(1))