Skip to contentSkip to conversation

Apple Magic Keyboard Backlight

PATCH In review Orlando Chamberlain 3 participants 6 messages Feb 20, 2023 – Mar 11, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v5 cover Apple Magic Keyboard Backlight

This patchseries adds support for the internal keyboard backlight of Macs with Apple's "Magic" keyboard (MacBookPro16,* and MacBookAir9,1), and also documents what names should be used for keyboard backlight leds in Documentation/leds/well-known-leds.txt.

v4->v5:
- use <tab><space><space> for help in Kconfig
- prepend "hid-" to filename in MAINTAINERS

v3->v4:
- collect reviews from Andy and Thomas
- remove now unused hdev member of apple_magic_backlight

v2->v3:
- remove unneeded header inclusion
- use s32 for report value type
- remove unneeded null check
- don't set drvdata as its never used
- prepend "hid-" to module name

v1->v2:
- drop unneeded remove function
- combine set functions
- add missing header inclusions
- avoid char as argument in favour of u8
- handful of style/formatting fixes
- use standard led name ":white:kbd_backlight"
- rename USAGE_MAGIC_BL to HID_USAGE_MAGIC_BL
- New patch documenting preferred keyboard backlight names

v1: https://lore.kernel.org/linux-input/[email protected]/
v2: https://lore.kernel.org/linux-input/[email protected]/
v3: https://lore.kernel.org/linux-input/[email protected]/
v4: https://lore.kernel.org/linux-input/[email protected]/

Orlando Chamberlain (2):
Documentation: leds: standardise keyboard backlight led names
HID: hid-apple-magic-backlight: Add driver for keyboard backlight on
internal Magic Keyboards

 Documentation/leds/well-known-leds.txt  |   8 ++
 MAINTAINERS                             |   6 ++
 drivers/hid/Kconfig                     |  13 +++
 drivers/hid/Makefile                    |   1 +
 drivers/hid/hid-apple-magic-backlight.c | 120 ++++++++++++++++++++++++
 5 files changed, 148 insertions(+)
 create mode 100644 drivers/hid/hid-apple-magic-backlight.c
Signature · 1 line
2.39.2
#1 lore raw

PATCH v5 1/2 Documentation: leds: standardise keyboard backlight led names

Advice use of either "input*:*:kbd_backlight" or ":*:kbd_backlight". We don't want people using vendor or product name (e.g. "smc", "apple", "asus") as this information is available from sysfs anyway, and it made the folder names inconsistent.

---
 Documentation/leds/well-known-leds.txt | 8 ++++++++
 1 file changed, 8 insertions(+)
Documentation/leds/well-known-leds.txt +8 -0
index 2160382c86be..4e5429fce4d8 100644
@@ -44,6 +44,14 @@ Legacy: "lp5523:kb{1,2,3,4,5,6}" (Nokia N900)
 
 Frontlight/backlight of main keyboard.
 
+Good: ":*:kbd_backlight"
+Good: "input*:*:kbd_backlight"
+Legacy: "*:*:kbd_backlight"
+
+Many drivers have the vendor or product name as the first field of the led name,
+this makes names inconsistent and is redundant as that information is already in
+sysfs.
+
 Legacy: "button-backlight" (Motorola Droid 4)
 
 Some phones have touch buttons below screen; it is different from main
Signature · 1 line
2.39.2
#2 lore raw

PATCH v5 2/2 HID: hid-apple-magic-backlight: Add driver for keyboard backlight on internal Magic Keyboards

In reply to Orlando Chamberlain

This driver adds support for the keyboard backlight on Intel T2 Macs with internal Magic Keyboards (MacBookPro16,x and MacBookAir9,1)

---
v4->v5:
- use <tab><space><space> for help in Kconfig
- prepend "hid-" to filename in MAINTAINERS

 MAINTAINERS                             |   6 ++
 drivers/hid/Kconfig                     |  13 +++
 drivers/hid/Makefile                    |   1 +
 drivers/hid/hid-apple-magic-backlight.c | 120 ++++++++++++++++++++++++
 4 files changed, 140 insertions(+)
 create mode 100644 drivers/hid/hid-apple-magic-backlight.c
MAINTAINERS +6 -0
index 6a47510d1592..e004217a12eb 100644
@@ -9201,6 +9201,12 @@ F:	include/linux/pm.h
 F:	include/linux/suspend.h
 F:	kernel/power/
 
+HID APPLE MAGIC BACKLIGHT DRIVER
+M:	Orlando Chamberlain <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/hid/hid-apple-magic-backlight.c
+
 HID CORE LAYER
 M:	Jiri Kosina <[email protected]>
 M:	Benjamin Tissoires <[email protected]>
drivers/hid/Kconfig +13 -0
index e2a5d30c8895..226210c6293c 100644
@@ -130,6 +130,19 @@ config HID_APPLE
 	Say Y here if you want support for keyboards of	Apple iBooks, PowerBooks,
 	MacBooks, MacBook Pros and Apple Aluminum.
 
+config HID_APPLE_MAGIC_BACKLIGHT
+	tristate "Apple Magic Keyboard Backlight"
+	depends on USB_HID
+	depends on LEDS_CLASS
+	depends on NEW_LEDS
+	help
+	  Say Y here if you want support for the keyboard backlight on Macs with
+	  the magic keyboard (MacBookPro16,x and MacBookAir9,1). Note that this
+	  driver is not for external magic keyboards.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called hid-apple-magic-backlight.
+
 config HID_APPLEIR
 	tristate "Apple infrared receiver"
 	depends on (USB_HID)
drivers/hid/Makefile +1 -0
index e8014c1a2f8b..dc8df002bc86 100644
@@ -26,6 +26,7 @@ obj-$(CONFIG_HID_ACCUTOUCH)	+= hid-accutouch.o
 obj-$(CONFIG_HID_ALPS)		+= hid-alps.o
 obj-$(CONFIG_HID_ACRUX)		+= hid-axff.o
 obj-$(CONFIG_HID_APPLE)		+= hid-apple.o
+obj-$(CONFIG_HID_APPLE_MAGIC_BACKLIGHT)	+= hid-apple-magic-backlight.o
 obj-$(CONFIG_HID_APPLEIR)	+= hid-appleir.o
 obj-$(CONFIG_HID_CREATIVE_SB0540)	+= hid-creative-sb0540.o
 obj-$(CONFIG_HID_ASUS)		+= hid-asus.o
drivers/hid/hid-apple-magic-backlight.c new file +120 -0

120 lines not on this page · raw message

Signature · 1 line
2.39.2
maintainer
#3 lore raw
In reply to Orlando Chamberlain
Quoted 40 lines · Orlando Chamberlain

This patchseries adds support for the internal keyboard backlight of Macs with Apple's "Magic" keyboard (MacBookPro16,* and MacBookAir9,1), and also documents what names should be used for keyboard backlight leds in Documentation/leds/well-known-leds.txt.

v4->v5:
- use <tab><space><space> for help in Kconfig
- prepend "hid-" to filename in MAINTAINERS

v3->v4:
- collect reviews from Andy and Thomas
- remove now unused hdev member of apple_magic_backlight

v2->v3:
- remove unneeded header inclusion
- use s32 for report value type
- remove unneeded null check
- don't set drvdata as its never used
- prepend "hid-" to module name

v1->v2:
- drop unneeded remove function
- combine set functions
- add missing header inclusions
- avoid char as argument in favour of u8
- handful of style/formatting fixes
- use standard led name ":white:kbd_backlight"
- rename USAGE_MAGIC_BL to HID_USAGE_MAGIC_BL
- New patch documenting preferred keyboard backlight names

v1: https://lore.kernel.org/linux-input/[email protected]/
v2: https://lore.kernel.org/linux-input/[email protected]/
v3: https://lore.kernel.org/linux-input/[email protected]/
v4: https://lore.kernel.org/linux-input/[email protected]/

Orlando Chamberlain (2):
Documentation: leds: standardise keyboard backlight led names
HID: hid-apple-magic-backlight: Add driver for keyboard backlight on
internal Magic Keyboards

Quoted 7 lines
 Documentation/leds/well-known-leds.txt  |   8 ++
 MAINTAINERS                             |   6 ++
 drivers/hid/Kconfig                     |  13 +++
 drivers/hid/Makefile                    |   1 +
 drivers/hid/hid-apple-magic-backlight.c | 120 ++++++++++++++++++++++++
 5 files changed, 148 insertions(+)
 create mode 100644 drivers/hid/hid-apple-magic-backlight.c

Hi,

thanks for creating the support for backlight.

Is there any reason why not to fold all this into existing hid-apple? I don't think we need separate driver for the backlist, separated from the rest of hid-apple support.

Thanks,

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

Hi,

thanks for creating the support for backlight.

Is there any reason why not to fold all this into existing hid-apple? I don't think we need separate driver for the backlist, separated from the rest of hid-apple support.

Thanks,

Signature · 2 lines
Jiri Kosina
SUSE Labs

As far as I know, hid-apple manages the keyboards and trackpads on Macs.

The magic backlight is managed by the touchbar on T2 Macs, so if you wanna integrate the driver in some other one, then it should be the to-be-upstreamed touchbar driver.

But when we did that, the MacBook Air 2020, the model which has magic backlight, but no touchbar faced issues. lsusb interestingly shows presence of touch bar backlight even on this model, but backlight is registered at the 0th interface on Air, and 1st interface on the Pros. So, the co-author, Kerem Karabay suggested using a separate driver.

Although, the authors may give more detailed reason for the same.

#5 lore raw
In reply to Jiri Kosina
Quoted 54 lines · On Fri, 10 Mar 2023 15:36:34 +0100 (CET) Jiri Kosina <[email protected]> wrote:
Quoted 44 lines · Orlando Chamberlain

This patchseries adds support for the internal keyboard backlight of Macs with Apple's "Magic" keyboard (MacBookPro16,* and MacBookAir9,1), and also documents what names should be used for keyboard backlight leds in Documentation/leds/well-known-leds.txt.

v4->v5:
- use <tab><space><space> for help in Kconfig
- prepend "hid-" to filename in MAINTAINERS

v3->v4:
- collect reviews from Andy and Thomas
- remove now unused hdev member of apple_magic_backlight

v2->v3:
- remove unneeded header inclusion
- use s32 for report value type
- remove unneeded null check
- don't set drvdata as its never used
- prepend "hid-" to module name

v1->v2:
- drop unneeded remove function
- combine set functions
- add missing header inclusions
- avoid char as argument in favour of u8
- handful of style/formatting fixes
- use standard led name ":white:kbd_backlight"
- rename USAGE_MAGIC_BL to HID_USAGE_MAGIC_BL
- New patch documenting preferred keyboard backlight names

v1:
https://lore.kernel.org/linux-input/[email protected]/
v2:
https://lore.kernel.org/linux-input/[email protected]/
v3:
https://lore.kernel.org/linux-input/[email protected]/
v4:
https://lore.kernel.org/linux-input/[email protected]/

Orlando Chamberlain (2):
Documentation: leds: standardise keyboard backlight led names
HID: hid-apple-magic-backlight: Add driver for keyboard backlight
on internal Magic Keyboards

Quoted 7 lines
 Documentation/leds/well-known-leds.txt  |   8 ++
 MAINTAINERS                             |   6 ++
 drivers/hid/Kconfig                     |  13 +++
 drivers/hid/Makefile                    |   1 +
 drivers/hid/hid-apple-magic-backlight.c | 120
++++++++++++++++++++++++ 5 files changed, 148 insertions(+)
 create mode 100644 drivers/hid/hid-apple-magic-backlight.c  
Quoted 7 lines

Hi,

thanks for creating the support for backlight.

Is there any reason why not to fold all this into existing hid-apple? I don't think we need separate driver for the backlist, separated from the rest of hid-apple support.

Hi Jiri,

I think we can do that if we modify hid-apple to support usb endpoints with only the keyboard backlight and no keyboard, assuming it doesn't prevent the (not upstream) touchbar driver from using the touchbar backlight interface (and I don't think it will, given hid-apple lets a different driver bind to the trackpad interface of the keyboard/trackpad usb device).

Quoted 3 lines

Thanks,