Skip to contentSkip to conversation

HID: hid-appletb-kbd: simplify logic used to switch between media and function keys on pressing fn key

PATCH Applied Aditya Garg 2 participants 6 messages Feb 17, 2025 – Feb 18, 2025 HID

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/3 HID: hid-appletb-kbd: simplify logic used to switch between media and function keys on pressing fn key

From: Aditya Garg <[email protected]>

This commit simplifies the logic in appletb_kbd_inp_event used for switching between the media and function keys on pressing the fn key.

We now also prevent touching the kbd->saved_mode variable in case the esc key only mode is chosen.

The following small fixes have also been done in this patch:

- A small comment style error has been fixed
- Fixed spelling in MODULE_DESCRIPTION
- I have added myself to MODULE_AUTHOR

---
 drivers/hid/hid-appletb-kbd.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/hid/hid-appletb-kbd.c +8 -7
index 38fc0e58c..e45cc3ac4 100644
@@ -236,13 +236,13 @@ static void appletb_kbd_inp_event(struct input_handle *handle, unsigned int type
 
 	reset_inactivity_timer(kbd);
 
-	if (type == EV_KEY && code == KEY_FN && appletb_tb_fn_toggle) {
+	if (type == EV_KEY && code == KEY_FN && appletb_tb_fn_toggle &&
+		(kbd->current_mode == APPLETB_KBD_MODE_SPCL ||
+		 kbd->current_mode == APPLETB_KBD_MODE_FN)) {
 		if (value == 1) {
 			kbd->saved_mode = kbd->current_mode;
-			if (kbd->current_mode == APPLETB_KBD_MODE_SPCL)
-				appletb_kbd_set_mode(kbd, APPLETB_KBD_MODE_FN);
-			else if (kbd->current_mode == APPLETB_KBD_MODE_FN)
-				appletb_kbd_set_mode(kbd, APPLETB_KBD_MODE_SPCL);
+			appletb_kbd_set_mode(kbd, kbd->current_mode == APPLETB_KBD_MODE_SPCL
+						? APPLETB_KBD_MODE_FN : APPLETB_KBD_MODE_SPCL);
 		} else if (value == 0) {
 			if (kbd->saved_mode != kbd->current_mode)
 				appletb_kbd_set_mode(kbd, kbd->saved_mode);
@@ -497,10 +497,11 @@ static struct hid_driver appletb_kbd_hid_driver = {
 };
 module_hid_driver(appletb_kbd_hid_driver);
 
-/* The backlight driver should be loaded before the keyboard driver is initialised*/
+/* The backlight driver should be loaded before the keyboard driver is initialised */
 MODULE_SOFTDEP("pre: hid_appletb_bl");
 
 MODULE_AUTHOR("Ronald Tschalär");
 MODULE_AUTHOR("Kerem Karabay <[email protected]>");
-MODULE_DESCRIPTION("MacBookPro Touch Bar Keyboard Mode Driver");
+MODULE_AUTHOR("Aditya Garg <[email protected]>");
+MODULE_DESCRIPTION("MacBook Pro Touch Bar Keyboard Mode driver");
 MODULE_LICENSE("GPL");
Signature · 1 line
2.43.0
#1 lore raw

PATCH v4 2/3 HID: hid-appletb-bl: fix incorrect error message for default brightness

From: Aditya Garg <[email protected]>

The error message responsible to show failure to set default backlight brightness incorrectly showed the intended brightness as off irrespective of what the user had set it. This patch intends to fix the same.

Also, a small typo in MODULE_DESCRIPTION has been fixed.

---
 drivers/hid/hid-appletb-bl.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/hid/hid-appletb-bl.c +3 -2
index 1a3dcd44b..bad2aead8 100644
@@ -145,7 +145,8 @@ static int appletb_bl_probe(struct hid_device *hdev, const struct hid_device_id
 		appletb_bl_brightness_map[(appletb_bl_def_brightness > 2) ? 2 : appletb_bl_def_brightness]);
 
 	if (ret) {
-		dev_err_probe(dev, ret, "Failed to set touch bar brightness to off\n");
+		dev_err_probe(dev, ret, "Failed to set default touch bar brightness to %d\n",
+			      appletb_bl_def_brightness);
 		goto close_hw;
 	}
 
@@ -199,5 +200,5 @@ module_hid_driver(appletb_bl_hid_driver);
 
 MODULE_AUTHOR("Ronald Tschalär");
 MODULE_AUTHOR("Kerem Karabay <[email protected]>");
-MODULE_DESCRIPTION("MacBookPro Touch Bar Backlight Driver");
+MODULE_DESCRIPTION("MacBook Pro Touch Bar Backlight driver");
 MODULE_LICENSE("GPL");
Signature · 1 line
2.43.0
#2 lore raw

PATCH v4 3/3 HID: appletb-kbd: Fix inconsistent indentation and pass -ENODEV to dev_err_probe

In reply to Aditya Garg

From: Aditya Garg <[email protected]>

The following warnings were flagged by the kernel test robot:

drivers/hid/hid-appletb-kbd.c:405 appletb_kbd_probe() warn: inconsistent indenting drivers/hid/hid-appletb-kbd.c:406 appletb_kbd_probe() warn: passing zero to 'dev_err_probe'

This patch aims at fixing those warnings.

Fixes 93a0fc489481 ("HID: hid-appletb-kbd: add support for automatic brightness control while using the touchbar")
---
 drivers/hid/hid-appletb-kbd.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/hid/hid-appletb-kbd.c +7 -7
index e45cc3ac4..d4b95aa3e 100644
@@ -402,13 +402,13 @@ static int appletb_kbd_probe(struct hid_device *hdev, const struct hid_device_id
 	}
 
 	kbd->backlight_dev = backlight_device_get_by_name("appletb_backlight");
-		if (!kbd->backlight_dev)
-			dev_err_probe(dev, ret, "Failed to get backlight device\n");
-		else {
-			backlight_device_set_brightness(kbd->backlight_dev, 2);
-			timer_setup(&kbd->inactivity_timer, appletb_inactivity_timer, 0);
-			mod_timer(&kbd->inactivity_timer, jiffies + msecs_to_jiffies(appletb_tb_dim_timeout * 1000));
-		}
+	if (!kbd->backlight_dev) {
+		dev_err_probe(dev, -ENODEV, "Failed to get backlight device\n");
+	} else {
+		backlight_device_set_brightness(kbd->backlight_dev, 2);
+		timer_setup(&kbd->inactivity_timer, appletb_inactivity_timer, 0);
+		mod_timer(&kbd->inactivity_timer, jiffies + msecs_to_jiffies(appletb_tb_dim_timeout * 1000));
+	}
 
 	kbd->inp_handler.event = appletb_kbd_inp_event;
 	kbd->inp_handler.connect = appletb_kbd_inp_connect;
Signature · 1 line
2.43.0
maintainer
#3 lore raw
In reply to Aditya Garg
Quoted 8 lines · Aditya Garg

From: Aditya Garg <[email protected]>

This commit simplifies the logic in appletb_kbd_inp_event used for switching between the media and function keys on pressing the fn key.

We now also prevent touching the kbd->saved_mode variable in case the esc key only mode is chosen.

Quoted 7 lines

The following small fixes have also been done in this patch:

- A small comment style error has been fixed
- Fixed spelling in MODULE_DESCRIPTION
- I have added myself to MODULE_AUTHOR

What a flood of patchseries :) I don't see any mentions on what are the v1->v2->v3->v4 changes, could you please document that?

Signature · 2 lines
Jiri Kosina
SUSE Labs
#4 lore raw

Hi Jiri

Quoted 14 lines · Jiri Kosina
Quoted 10 lines · Aditya Garg

From: Aditya Garg <[email protected]>

This commit simplifies the logic in appletb_kbd_inp_event used for switching between the media and function keys on pressing the fn key.

We now also prevent touching the kbd->saved_mode variable in case the esc key only mode is chosen.

The following small fixes have also been done in this patch:

Quoted 9 lines
Quoted 5 lines

- A small comment style error has been fixed
- Fixed spelling in MODULE_DESCRIPTION
- I have added myself to MODULE_AUTHOR

What a flood of patchseries :) I don't see any mentions on what are the v1->v2->v3->v4 changes, could you please document that?

Extremely sorry for nor giving a changelog. I’ll make sure it’s done next time.

V2: Spellings in MODULE_DESCRIPTION were also fixed.
V3: The 3/3 patch was added since the bug was flagged by kernel test robot
V4: Extra tabs were removed from 3/3 as reported by Dan Carpenter.

Quoted 3 lines
Signature · 2 lines
Jiri Kosina
SUSE Labs