dell-laptop: Fix keyboard led max_brightness property for Dell Latitude E6410
PATCH 1/1 dell-laptop: Fix keyboard led max_brightness property for Dell Latitude E6410
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.
---
Hi! I have not tested this patch yet, but I'm sending it, so other people including Gabriel can test or review it.
If you have better idea how to call that quirk variable, then fell free to rename it. I'm not happy with "kbd_led_num_of_levels_instead_of_last_index" but I have nothing better in my mind.
--- drivers/platform/x86/dell-laptop.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-)
drivers/platform/x86/dell-laptop.c +23 -2
@@ -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, + }, { } };
@@ -1216,8 +1230,15 @@ static int kbd_get_info(struct kbd_info *info)static unsigned int kbd_get_max_level (void ) { -if (kbd_info.levels !=0 ) -return kbd_info.levels; +u8 levels = kbd_info.levels; + +if (quirks && quirks->kbd_led_num_of_levels_instead_of_last_index) { +if (levels >1 ) +return levels -1 ; + }else { +if (levels >0 ) +return levels; + }if (kbd_mode_levels_count >0 )return kbd_mode_levels_count -1 ;return 0 ;
Signature · 1 line
1.7.9.5
Quoted 3 lines · Pali Rohár
This machine reports number of keyboard backlight led levels, instead of value of the last led level index. Therefore
max_brightnessproperly needs to be subtracted by 1 to match ledmax_brightnessAPI.
Which field is behaving differently?
If I'm understanding this correctly:
Since the max level is something we test for once at runtime, it seems to me a cleaner fix would be to check for this quirk in kbd_get_info() and set kbd_info.levels accordingly. The rest of the driver logic would then remain unchanged.
The idea being to translate what the platform firmware reports into what the driver already understands, instead of giving the levels fields of the structure multiple meanings.
Signature · 2 lines
Darren Hart VMware Open Source Technology Center
Quoted 5 lines · On Monday 16 October 2017 14:48:37 Darren Hart wrote:
Quoted 3 lines · Pali Rohár
This machine reports number of keyboard backlight led levels, instead of value of the last led level index. Therefore
max_brightnessproperly needs to be subtracted by 1 to match ledmax_brightnessAPI.
Quoted 8 lines
Which field is behaving differently?
If I'm understanding this correctly:
Since the max level is something we test for once at runtime, it seems to me a cleaner fix would be to check for this quirk in
kbd_get_info()and set kbd_info.levels accordingly. The rest of the driver logic would then remain unchanged.
Great, this is a good idea. I would send a new patch in a few minutes.
Quoted 3 lines
The idea being to translate what the platform firmware reports into what the driver already understands, instead of giving the levels fields of the structure multiple meanings.
Signature · 2 lines
Pali Rohár [email protected]
PATCH v2 1/1 dell-laptop: Fix keyboard led max_brightness property for Dell Latitude E6410
In reply to Pali RohárThis 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.
---
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(+)
drivers/platform/x86/dell-laptop.c +17 -0
@@ -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 ))
Signature · 1 line
1.7.9.5
Quoted 9 lines · Pali Rohár
This machine reports number of keyboard backlight led levels, instead of value of the last led level index. Therefore
max_brightnessproperly needs to be subtracted by 1 to match ledmax_brightnessAPI.Signed-off-by Pali Rohár <[email protected]>Reported-by Gabriel M. Elder <[email protected]>+ 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;
?
drivers/platform/x86/dell-laptop.c static int kbd_get_info(struct kbd_info *info) · line 1218
Quoted 2 lines
drivers/platform/x86/dell-laptop.c +2
-0+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)
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 9 lines · On Wednesday 18 October 2017 22:09:41 Andy Shevchenko wrote:
Quoted 7 lines · Pali Rohár
This machine reports number of keyboard backlight led levels, instead of value of the last led level index. Therefore
max_brightnessproperly needs to be subtracted by 1 to match ledmax_brightnessAPI.Signed-off-by Pali Rohár <[email protected]>Reported-by Gabriel M. Elder <[email protected]>
Quoted 5 lines
Quoted 1 line
+ 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.
Quoted 5 lines
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.
Quoted 2 lines
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.
Quoted 15 lines
/* Comment what is this for */
#defineQUIRK_KBD_LED_USE_LEVELS0unsigned long quirks;
?
drivers/platform/x86/dell-laptop.c static int kbd_get_info(struct kbd_info *info) · line 1218
Quoted 2 lines
drivers/platform/x86/dell-laptop.c +2
-0+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)
Signature · 2 lines
Pali Rohár [email protected]
Quoted 10 lines · Pali Rohár
This machine reports number of keyboard backlight led levels, instead of value of the last led level index. Therefore
max_brightnessproperly needs to be subtracted by 1 to match ledmax_brightnessAPI.Signed-off-by Pali Rohár <[email protected]>Reported-by Gabriel M. Elder <[email protected]>---
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 line 52
Quoted 13 lines
--- drivers/platform/x86/dell-laptop.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)drivers/platform/x86/dell-laptop.c +1
-0@@ -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.
Quoted 44 lines
drivers/platform/x86/dell-laptop.c +16
-0int 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 ))Signature · 1 line
1.7.9.5
Signature · 2 lines
Darren Hart VMware Open Source Technology Center
PATCH v3 1/1 dell-laptop: Fix keyboard led max_brightness property for Dell Latitude E6410
In reply to Pali RohárThis 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.
---
Changes since v2:
* Rename quirk entry to kbd_led_levels_off_1
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(+)
drivers/platform/x86/dell-laptop.c +17 -0
@@ -49,6 +49,7 @@struct quirk_entry {u8 touchpad_led; +u8 kbd_led_levels_off_1;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_levels_off_1 = 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_levels_off_1 && info->levels) + info->levels--; +if (units &BIT (0 )) info->seconds = (buffer->output[3 ] >>0 ) &0xFF ;if (units &BIT (1 ))
Signature · 1 line
1.7.9.5
Quoted 21 lines · Pali Rohár
This machine reports number of keyboard backlight led levels, instead of value of the last led level index. Therefore
max_brightnessproperly needs to be subtracted by 1 to match ledmax_brightnessAPI.Signed-off-by Pali Rohár <[email protected]>Reported-by Gabriel M. Elder <[email protected]>---
Changes since v2:
* Rename quirk entry tokbd_led_levels_off_1
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(+)drivers/platform/x86/dell-laptop.c +0
-0
drivers/platform/x86/dell-laptop.c line 52
Quoted 4 lines
drivers/platform/x86/dell-laptop.c +1
-0@@ -49,6 +49,7 @@struct quirk_entry {u8 touchpad_led; +u8 kbd_led_levels_off_1;
I believe you and Andy agreed to use a boolean type here?
Signature · 2 lines
Darren Hart VMware Open Source Technology Center
Quoted 23 lines · On Thursday 02 November 2017 18:18:43 Darren Hart wrote:
Quoted 22 lines · Pali Rohár
This machine reports number of keyboard backlight led levels, instead of value of the last led level index. Therefore
max_brightnessproperly needs to be subtracted by 1 to match ledmax_brightnessAPI.Signed-off-by Pali Rohár <[email protected]>Reported-by Gabriel M. Elder <[email protected]>---
Changes since v2:
* Rename quirk entry tokbd_led_levels_off_1
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(+)drivers/platform/x86/dell-laptop.c +0
-0@@ -49,6 +49,7 @@
Quoted 5 lines
drivers/platform/x86/dell-laptop.c line 52
Quoted 3 lines
drivers/platform/x86/dell-laptop.c +1
-0struct quirk_entry {u8 touchpad_led; +u8 kbd_led_levels_off_1;I believe you and Andy agreed to use a boolean type here?
I'm going to fix this and other entries to boolean type in another patch.
Signature · 2 lines
Pali Rohár [email protected]
Darren Hart
AppliedQuoted 7 lines · Pali Rohár
This machine reports number of keyboard backlight led levels, instead of value of the last led level index. Therefore
max_brightnessproperly needs to be subtracted by 1 to match ledmax_brightnessAPI.Signed-off-by Pali Rohár <[email protected]>Reported-by Gabriel M. Elder <[email protected]>
Queued, thanks Pali (sorry for the delay).
Signature · 2 lines
Darren Hart VMware Open Source Technology Center