* [PATCH 0/2] HID: apple: improvements for code readability
@ 2025-03-04 9:12 Aditya Garg
2025-03-04 9:13 ` [PATCH 1/2] HID: apple: move backlight report structs to other backlight structs Aditya Garg
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Aditya Garg @ 2025-03-04 9:12 UTC (permalink / raw)
To: Jiri Kosina, jkosina, Benjamin Tissoires, bentiss
Cc: Linux Kernel Mailing List, linux-input
Hi
This small patch series aims to improve the code readability in hid-apple.
The first patch moves the backlight report structs, that were incorrectly
placed between the translation tables, to other related backlight structs.
The second patch makes use of switch case statements for the ever
increasing lengthy device table for fn translation.
Aditya Garg (2):
HID: apple: move backlight report structs alongwith other backlight
structs
HID: apple: use switch case to set fn translation table
drivers/hid/hid-apple.c | 100 ++++++++++++++++++++++------------------
1 file changed, 54 insertions(+), 46 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] HID: apple: move backlight report structs to other backlight structs
2025-03-04 9:12 [PATCH 0/2] HID: apple: improvements for code readability Aditya Garg
@ 2025-03-04 9:13 ` Aditya Garg
2025-03-04 9:14 ` [PATCH 2/2] HID: apple: use switch case to set fn translation table Aditya Garg
2025-03-07 12:02 ` [PATCH 0/2] HID: apple: improvements for code readability Aditya Garg
2 siblings, 0 replies; 4+ messages in thread
From: Aditya Garg @ 2025-03-04 9:13 UTC (permalink / raw)
To: Jiri Kosina, jkosina, Benjamin Tissoires, bentiss
Cc: Linux Kernel Mailing List, linux-input
From: Aditya Garg <gargaditya08@live.com>
The apple_backlight_config_report and apple_backlight_set_report structs
were incorrectly placed between the translation tables. Fix this.
Signed-off-by: Aditya Garg <gargaditya08@live.com>
---
drivers/hid/hid-apple.c | 27 +++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)
diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
index 49812a76b..6fa4941b6 100644
--- a/drivers/hid/hid-apple.c
+++ b/drivers/hid/hid-apple.c
@@ -89,6 +89,19 @@ struct apple_sc_backlight {
struct hid_device *hdev;
};
+struct apple_backlight_config_report {
+ u8 report_id;
+ u8 version;
+ u16 backlight_off, backlight_on_min, backlight_on_max;
+};
+
+struct apple_backlight_set_report {
+ u8 report_id;
+ u8 version;
+ u16 backlight;
+ u16 rate;
+};
+
struct apple_magic_backlight {
struct led_classdev cdev;
struct hid_report *brightness;
@@ -152,20 +165,6 @@ static const struct apple_key_translation magic_keyboard_2015_fn_keys[] = {
{ }
};
-struct apple_backlight_config_report {
- u8 report_id;
- u8 version;
- u16 backlight_off, backlight_on_min, backlight_on_max;
-};
-
-struct apple_backlight_set_report {
- u8 report_id;
- u8 version;
- u16 backlight;
- u16 rate;
-};
-
-
static const struct apple_key_translation apple2021_fn_keys[] = {
{ KEY_BACKSPACE, KEY_DELETE },
{ KEY_ENTER, KEY_INSERT },
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/2] HID: apple: use switch case to set fn translation table
2025-03-04 9:12 [PATCH 0/2] HID: apple: improvements for code readability Aditya Garg
2025-03-04 9:13 ` [PATCH 1/2] HID: apple: move backlight report structs to other backlight structs Aditya Garg
@ 2025-03-04 9:14 ` Aditya Garg
2025-03-07 12:02 ` [PATCH 0/2] HID: apple: improvements for code readability Aditya Garg
2 siblings, 0 replies; 4+ messages in thread
From: Aditya Garg @ 2025-03-04 9:14 UTC (permalink / raw)
To: Jiri Kosina, jkosina, Benjamin Tissoires, bentiss
Cc: Linux Kernel Mailing List, linux-input
From: Aditya Garg <gargaditya08@live.com>
There has been a continuous increase in the number of devices requiring
hid-apple driver during the last few years. Moreover, unlike previous
releases, the PIDs of the newer devices released cannot be combined in a
specific range, thus filling up the if else if statements with individual
device IDs. For such large table, its now more suitable to use switch case
instead of if else if for improved readability.
Signed-off-by: Aditya Garg <gargaditya08@live.com>
---
drivers/hid/hid-apple.c | 73 +++++++++++++++++++++++------------------
1 file changed, 41 insertions(+), 32 deletions(-)
diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
index 6fa4941b6..fba0bb68b 100644
--- a/drivers/hid/hid-apple.c
+++ b/drivers/hid/hid-apple.c
@@ -459,42 +459,51 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
asc->fn_on = !!value;
if (real_fnmode) {
- if (hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI ||
- hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO ||
- hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS ||
- hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI ||
- hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO ||
- hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS ||
- hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI ||
- hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO ||
- hid->product == USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS)
+ switch (hid->product) {
+ case USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI:
+ case USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO:
+ case USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS:
+ case USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI:
+ case USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO:
+ case USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS:
+ case USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ANSI:
+ case USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO:
+ case USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_JIS:
table = magic_keyboard_alu_fn_keys;
- else if (hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2015 ||
- hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2015)
+ break;
+ case USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2015:
+ case USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2015:
table = magic_keyboard_2015_fn_keys;
- else if (hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021 ||
- hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2024 ||
- hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_FINGERPRINT_2021 ||
- hid->product == USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2021)
+ break;
+ case USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2021:
+ case USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_2024:
+ case USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_FINGERPRINT_2021:
+ case USB_DEVICE_ID_APPLE_MAGIC_KEYBOARD_NUMPAD_2021:
table = apple2021_fn_keys;
- else if (hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J132 ||
- hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J680 ||
- hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J213)
- table = macbookpro_no_esc_fn_keys;
- else if (hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J214K ||
- hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J223 ||
- hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J152F)
- table = macbookpro_dedicated_esc_fn_keys;
- else if (hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J140K ||
- hid->product == USB_DEVICE_ID_APPLE_WELLSPRINGT2_J230K)
- table = apple_fn_keys;
- else if (hid->product >= USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI &&
- hid->product <= USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS)
- table = macbookair_fn_keys;
- else if (hid->product < 0x21d || hid->product >= 0x300)
- table = powerbook_fn_keys;
- else
+ break;
+ case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J132:
+ case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J213:
+ case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J680:
+ table = macbookpro_no_esc_fn_keys;
+ break;
+ case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J152F:
+ case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J214K:
+ case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J223:
+ table = macbookpro_dedicated_esc_fn_keys;
+ break;
+ case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J140K:
+ case USB_DEVICE_ID_APPLE_WELLSPRINGT2_J230K:
table = apple_fn_keys;
+ break;
+ default:
+ if (hid->product >= USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI &&
+ hid->product <= USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS)
+ table = macbookair_fn_keys;
+ else if (hid->product < 0x21d || hid->product >= 0x300)
+ table = powerbook_fn_keys;
+ else
+ table = apple_fn_keys;
+ }
trans = apple_find_translation(table, code);
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 0/2] HID: apple: improvements for code readability
2025-03-04 9:12 [PATCH 0/2] HID: apple: improvements for code readability Aditya Garg
2025-03-04 9:13 ` [PATCH 1/2] HID: apple: move backlight report structs to other backlight structs Aditya Garg
2025-03-04 9:14 ` [PATCH 2/2] HID: apple: use switch case to set fn translation table Aditya Garg
@ 2025-03-07 12:02 ` Aditya Garg
2 siblings, 0 replies; 4+ messages in thread
From: Aditya Garg @ 2025-03-07 12:02 UTC (permalink / raw)
To: Jiri Kosina, jkosina, Benjamin Tissoires, bentiss
Cc: Linux Kernel Mailing List, linux-input
> On 4 Mar 2025, at 2:42 PM, Aditya Garg <gargaditya08@live.com> wrote:
>
> Hi
>
> This small patch series aims to improve the code readability in hid-apple.
>
> The first patch moves the backlight report structs, that were incorrectly
> placed between the translation tables, to other related backlight structs.
>
> The second patch makes use of switch case statements for the ever
> increasing lengthy device table for fn translation.
>
> Aditya Garg (2):
> HID: apple: move backlight report structs alongwith other backlight
> structs
> HID: apple: use switch case to set fn translation table
>
> drivers/hid/hid-apple.c | 100 ++++++++++++++++++++++------------------
> 1 file changed, 54 insertions(+), 46 deletions(-)
>
> --
> 2.43.0
>
A v2 with more patches has been sent here:
https://lore.kernel.org/linux-input/A4FBEA54-C7BA-4864-9C4E-E41933D81FB0@live.com/T/#t
There were conflicting patches sent upstream by another person, so its best to combine them in one series, making things easier for both of us.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-03-07 12:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-04 9:12 [PATCH 0/2] HID: apple: improvements for code readability Aditya Garg
2025-03-04 9:13 ` [PATCH 1/2] HID: apple: move backlight report structs to other backlight structs Aditya Garg
2025-03-04 9:14 ` [PATCH 2/2] HID: apple: use switch case to set fn translation table Aditya Garg
2025-03-07 12:02 ` [PATCH 0/2] HID: apple: improvements for code readability Aditya Garg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®