Skip to contentSkip to conversation

Save Brightness on Macs

PATCH In review Atharva Tiwari 3 participants 7 messages Mar 16 – May 21

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

v4 cover Save Brightness on Macs

Currently, when a Mac is rebooted, the display brightness does not reflect the level used during the previous boot. Instead, the brightness is reset to the value last stored by macOS, causing the system to ignore any changes made since that time.

We fix this by writing the brightness value to efivar 'backlight-level' at shutdown only, when it is changed since the last boot.

Changes in v4:
- Fixed build error, when apple-gmux is compiled without apple-brightness.
- Fix grammatical errors.
Changes in v3:
- Fixed a bug, in which apple_brightness_shutdown is still called on non-supported devices.
Changes in v2:
- Saved the brightness only when it is different than the previous boot.

Link to v3:
https://lore.kernel.org/all/[email protected]/
Link to v2:
https://lore.kernel.org/all/[email protected]/
Link to v1:
https://lore.kernel.org/all/[email protected]/

Atharva Tiwari (2):
efi: Save Brightness using EFI on Macs platform/apple-gmux: use apple_brightness to save brightness to EFI

 drivers/firmware/efi/Kconfig                  | 10 +++
 drivers/firmware/efi/Makefile                 |  1 +
 drivers/firmware/efi/apple-brightness.c       | 67 +++++++++++++++++++
 drivers/platform/x86/apple-gmux.c             | 21 ++++++
 .../linux/platform_data/apple-brightness.h    | 20 ++++++
 5 files changed, 119 insertions(+)
 create mode 100644 drivers/firmware/efi/apple-brightness.c
 create mode 100644 include/linux/platform_data/apple-brightness.h
Signature · 1 line
2.43.0
#1 lore raw

PATCH v4 1/2 efi: Save Brightness using EFI on Macs

Currently when a Mac reboots, the brightness is not the same as the previous boot instead its the same as the last time the Mac booted macOS.

We can fix this issue by saving the brightness level to the efivar backlight-level.

(tested on iMac20,1)

---
 drivers/firmware/efi/Kconfig                  | 10 +++
 drivers/firmware/efi/Makefile                 |  1 +
 drivers/firmware/efi/apple-brightness.c       | 67 +++++++++++++++++++
 .../linux/platform_data/apple-brightness.h    | 20 ++++++
 4 files changed, 98 insertions(+)
 create mode 100644 drivers/firmware/efi/apple-brightness.c
 create mode 100644 include/linux/platform_data/apple-brightness.h
drivers/firmware/efi/Kconfig +10 -0
index 29e0729299f5..243499a5d7b7 100644
@@ -167,6 +167,16 @@ config APPLE_PROPERTIES
 
 	  If unsure, say Y if you have a Mac.  Otherwise N.
 
+config APPLE_BRIGHTNESS
+	bool "Apple Backlight control for EFI"
+	depends on X86
+	help
+	  This will save the brightness level to EFI, so brightness
+	  level is preserved across reboots and shutdowns. allowing
+	  for improved support of Apple hardware.
+
+	  If unsure, say Y if you have a Mac, otherwise N.
+
 config RESET_ATTACK_MITIGATION
 	bool "Reset memory attack mitigation"
 	depends on EFI_STUB
drivers/firmware/efi/Makefile +1 -0
index 8efbcf699e4f..1f5705cc87a2 100644
@@ -26,6 +26,7 @@ obj-$(CONFIG_EFI_BOOTLOADER_CONTROL)	+= efibc.o
 obj-$(CONFIG_EFI_TEST)			+= test/
 obj-$(CONFIG_EFI_DEV_PATH_PARSER)	+= dev-path-parser.o
 obj-$(CONFIG_APPLE_PROPERTIES)		+= apple-properties.o
+obj-$(CONFIG_APPLE_BRIGHTNESS)		+= apple-brightness.o
 obj-$(CONFIG_EFI_RCI2_TABLE)		+= rci2-table.o
 obj-$(CONFIG_EFI_EMBEDDED_FIRMWARE)	+= embedded-firmware.o
 obj-$(CONFIG_LOAD_UEFI_KEYS)		+= mokvar-table.o
drivers/firmware/efi/apple-brightness.c new file +67 -0

67 lines not on this page · raw message

include/linux/platform_data/apple-brightness.h new file +20 -0
new file mode 100644
index 000000000000..54e3f3f8aa1c
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: GPL-2.0-only OR MIT */
+/*
+ * apple-brightness.h - EFI brightness saver for Macs
+ * Copyright (C) 2026 Atharva Tiwari <[email protected]>
+ */
+
+#ifndef _APPLE_BL_H_
+#define _APPLE_BL_H_
+
+#include <linux/backlight.h>
+#include <linux/efi.h>
+
+#define APPLE_BRIGHTNESS_NAME           L"backlight-level"
+#define APPLE_BRIGHTNESS_GUID           EFI_GUID(0x7c436110, 0xab2a, 0x4bbb, 0xa8, 0x80, 0xfe, 0x41, 0x99, 0x5c, 0x9f, 0x82)
+
+int apple_brightness_probe(struct backlight_device *bl,
+	int (*get_brightnessfn)(struct backlight_device *bl));
+
+void apple_brightness_shutdown(void);
+#endif /* _APPLE_BL_H */
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH v4 1/2] efi: Save Brightness using EFI on Macs

Quoted 15 lines · Atharva Tiwari

Currently when a Mac reboots, the brightness is not the same as the previous boot instead its the same as the last time the Mac booted macOS.

We can fix this issue by saving the brightness level to the efivar backlight-level.

(tested on iMac20,1)

Quoted 8 lines

---

drivers/firmware/efi/Kconfig                  | 10 +++
drivers/firmware/efi/Makefile                 |  1 +
drivers/firmware/efi/apple-brightness.c       | 67 +++++++++++++++++++
.../linux/platform_data/apple-brightness.h    | 20 ++++++
4 files changed, 98 insertions(+)

create mode 100644 drivers/firmware/efi/apple-brightness.c create mode 100644 include/linux/platform_data/apple-brightness.h

I tested this patch on a MacBookPro16,1, which is a T2 Intel Mac, and the behaviour is very weird:

1. macOS will never respect any brightness set by Linux
2. The Max brightness set by macOS is not the max brightness on Linux. I get these values on Linux:

aditya@MacBook:~$ efivar -p -n '7c436110-ab2a-4bbb-a880-fe41995c9f82-backlight-level'
GUID: 7c436110-ab2a-4bbb-a880-fe41995c9f82
Name: "backlight-level"
Attributes:
	Non-Volatile
	Boot Service Access
	Runtime Service Access
Value:
00000000  f1 02                                             |..              |
aditya@MacBook:~$ cat /sys/class/backlight/gmux_backlight/brightness
48238

3. I set the Max brightness on Linux, and restarted. I get this:

aditya@MacBook:~$ efivar -p -n '7c436110-ab2a-4bbb-a880-fe41995c9f82-backlight-level'
GUID: 7c436110-ab2a-4bbb-a880-fe41995c9f82
Name: "backlight-level"
Attributes:
	Non-Volatile
	Boot Service Access
	Runtime Service Access
Value:
00000000  7a ff                                             |z.              |
aditya@MacBook:~$ cat /sys/class/backlight/gmux_backlight/brightness
65402

4. Finally, any attempt to reduce the brightness seems worthless as unless booted back to macOS, Linux always boots at max brightness, but the nvram variable is changed successfully:

aditya@MacBook:~$ efivar -p -n '7c436110-ab2a-4bbb-a880-fe41995c9f82-backlight-level'
GUID: 7c436110-ab2a-4bbb-a880-fe41995c9f82
Name: "backlight-level"
Attributes:
	Non-Volatile
	Boot Service Access
	Runtime Service Access
Value:
00000000  eb 41                                             |.A              |
aditya@MacBook:~$ cat /sys/class/backlight/gmux_backlight/brightness
65402

Overall, it’s very inconsistent. Also, I’ve noticed Windows doesn't mess around with efivars, rather stores the brightness locally and implements it on every boot, something which systemd should do on Linux.

#3 lore raw

Re: [PATCH v4 1/2] efi: Save Brightness using EFI on Macs

Quoted 70 lines · Aditya Garg
Quoted 15 lines · Atharva Tiwari

Currently when a Mac reboots, the brightness is not the same as the previous boot instead its the same as the last time the Mac booted macOS.

We can fix this issue by saving the brightness level to the efivar backlight-level.

(tested on iMac20,1)

Quoted 8 lines

---

drivers/firmware/efi/Kconfig                  | 10 +++
drivers/firmware/efi/Makefile                 |  1 +
drivers/firmware/efi/apple-brightness.c       | 67 +++++++++++++++++++
.../linux/platform_data/apple-brightness.h    | 20 ++++++
4 files changed, 98 insertions(+)

create mode 100644 drivers/firmware/efi/apple-brightness.c create mode 100644 include/linux/platform_data/apple-brightness.h

I tested this patch on a MacBookPro16,1, which is a T2 Intel Mac, and the behaviour is very weird:

1. macOS will never respect any brightness set by Linux
2. The Max brightness set by macOS is not the max brightness on Linux. I get these values on Linux:

aditya@MacBook:~$ efivar -p -n '7c436110-ab2a-4bbb-a880-fe41995c9f82-backlight-level'
GUID: 7c436110-ab2a-4bbb-a880-fe41995c9f82
Name: "backlight-level"
Attributes:
	Non-Volatile
	Boot Service Access
	Runtime Service Access
Value:
00000000  f1 02                                             |..              |
aditya@MacBook:~$ cat /sys/class/backlight/gmux_backlight/brightness
48238

3. I set the Max brightness on Linux, and restarted. I get this:

aditya@MacBook:~$ efivar -p -n '7c436110-ab2a-4bbb-a880-fe41995c9f82-backlight-level'
GUID: 7c436110-ab2a-4bbb-a880-fe41995c9f82
Name: "backlight-level"
Attributes:
	Non-Volatile
	Boot Service Access
	Runtime Service Access
Value:
00000000  7a ff                                             |z.              |
aditya@MacBook:~$ cat /sys/class/backlight/gmux_backlight/brightness
65402

4. Finally, any attempt to reduce the brightness seems worthless as unless booted back to macOS, Linux always boots at max brightness, but the nvram variable is changed successfully:

aditya@MacBook:~$ efivar -p -n '7c436110-ab2a-4bbb-a880-fe41995c9f82-backlight-level'
GUID: 7c436110-ab2a-4bbb-a880-fe41995c9f82
Name: "backlight-level"
Attributes:
	Non-Volatile
	Boot Service Access
	Runtime Service Access
Value:
00000000  eb 41                                             |.A              |
Quoted 7 lines
aditya@MacBook:~$ cat /sys/class/backlight/gmux_backlight/brightness
65402

Overall, it’s very inconsistent. Also, I’ve noticed Windows doesn't mess around with efivars, rather stores the brightness locally and implements it on every boot, something which systemd should do on Linux.

I've done another test as well:

1. I booted into macOS, and set a normal brightness, not too low, not too high.
2. I booted back to Linux. The brightness was consistent. These are the values:

aditya@MacBook:~$ efivar -p -n '7c436110-ab2a-4bbb-a880-fe41995c9f82-backlight-level'
GUID: 7c436110-ab2a-4bbb-a880-fe41995c9f82
Name: "backlight-level"
Attributes:
	Non-Volatile
	Boot Service Access
	Runtime Service Access
Value:
00000000  92 00                                             |.. 
    |
aditya@MacBook:~$ cat /sys/class/backlight/gmux_backlight/brightness
7792

This is the journalctl of that boot: https://termbin.com/p0vf

3. I slightly modified the brightness and restarted. Upon a restart, the brightness was max again:

aditya@MacBook:~$ efivar -p -n '7c436110-ab2a-4bbb-a880-fe41995c9f82-backlight-level'
GUID: 7c436110-ab2a-4bbb-a880-fe41995c9f82
Name: "backlight-level"
Attributes:
	Non-Volatile
	Boot Service Access
	Runtime Service Access
Value:
00000000  51 3a                                             |Q: 
    |
aditya@MacBook:~$ cat /sys/class/backlight/gmux_backlight/brightness
63589

This is the journalctl of that boot: https://termbin.com/1z9r

maintainer
#4 lore raw

Re: [PATCH v4 1/2] efi: Save Brightness using EFI on Macs

In reply to Atharva Tiwari
Quoted 2 lines · Atharva Tiwari

Currently when a Mac reboots, the brightness is not the same as the previous boot instead its the same as the last time the

When a Mac reboots, it does not preserve the brightness from the previous boot, instead ...

It might be worth to expand that to mention what brightness you're talking about here and in the Kconfig description.

Quoted 3 lines

Mac booted macOS.

We can fix this issue by saving the brightness level to the efivar

Please use imperative tone. Do not use "I" (nor "We" nor "This patch").

Quoted 20 lines

backlight-level.

(tested on iMac20,1)

---
 drivers/firmware/efi/Kconfig                  | 10 +++
 drivers/firmware/efi/Makefile                 |  1 +
 drivers/firmware/efi/apple-brightness.c       | 67 +++++++++++++++++++
 .../linux/platform_data/apple-brightness.h    | 20 ++++++
 4 files changed, 98 insertions(+)
 create mode 100644 drivers/firmware/efi/apple-brightness.c
 create mode 100644 include/linux/platform_data/apple-brightness.h
drivers/firmware/efi/Kconfig +0 -0
index 29e0729299f5..243499a5d7b7 100644

drivers/firmware/efi/Kconfig config APPLE_PROPERTIES · line 172

Quoted 6 lines
drivers/firmware/efi/Kconfig +3 -0
@@ -167,6 +167,16 @@ config APPLE_PROPERTIES
 
 	  If unsure, say Y if you have a Mac.  Otherwise N.
 
+config APPLE_BRIGHTNESS
+	bool "Apple Backlight control for EFI"
+	depends on X86

Doesn't the build fail if CONFIG_EFI is not set?

drivers/firmware/efi/Kconfig config APPLE_PROPERTIES · line 175

Quoted 3 lines
drivers/firmware/efi/Kconfig +3 -0
+	help
+	  This will save the brightness level to EFI, so brightness
+	  level is preserved across reboots and shutdowns. allowing

English sounds broken because of that period.

Quoted 45 lines
drivers/firmware/efi/Kconfig +4 -0
+	  for improved support of Apple hardware.
+
+	  If unsure, say Y if you have a Mac, otherwise N.
+
 config RESET_ATTACK_MITIGATION
 	bool "Reset memory attack mitigation"
 	depends on EFI_STUB
drivers/firmware/efi/Makefile +1 -0
index 8efbcf699e4f..1f5705cc87a2 100644
@@ -26,6 +26,7 @@ obj-$(CONFIG_EFI_BOOTLOADER_CONTROL)	+= efibc.o
 obj-$(CONFIG_EFI_TEST)			+= test/
 obj-$(CONFIG_EFI_DEV_PATH_PARSER)	+= dev-path-parser.o
 obj-$(CONFIG_APPLE_PROPERTIES)		+= apple-properties.o
+obj-$(CONFIG_APPLE_BRIGHTNESS)		+= apple-brightness.o
 obj-$(CONFIG_EFI_RCI2_TABLE)		+= rci2-table.o
 obj-$(CONFIG_EFI_EMBEDDED_FIRMWARE)	+= embedded-firmware.o
 obj-$(CONFIG_LOAD_UEFI_KEYS)		+= mokvar-table.o
drivers/firmware/efi/apple-brightness.c new file +20 -0
new file mode 100644
index 000000000000..b060861b0795
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: GPL-2.0-only OR MIT
+/*
+ * apple-brightness.c - EFI brightness saver on Macs
+ * Copyright (C) 2026 Atharva Tiwari <[email protected]>
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/backlight.h>
+#include <linux/efi.h>
+#include <linux/platform_data/apple-brightness.h>
+
+static u32 efi_attr;
+static u16 last_saved_level;
+
+static int (*get_brightness)(struct backlight_device *bl);
+static struct backlight_device *bl_dev;
+
+void apple_brightness_shutdown(void)
+{

drivers/firmware/efi/apple-brightness.c line 30

Quoted 10 lines
drivers/firmware/efi/apple-brightness.c new file +10 -0
+	u16 level;
+	efi_status_t status;
+
+	level = (u16)get_brightness(bl_dev);
+
+	if (level == last_saved_level)
+		return;
+
+	status = efivar_set_variable(APPLE_BRIGHTNESS_NAME, &APPLE_BRIGHTNESS_GUID,
+				efi_attr, sizeof(level), &level);

Align to (

drivers/firmware/efi/apple-brightness.c line 32

Quoted 2 lines
drivers/firmware/efi/apple-brightness.c new file +2 -0
+	if (status != EFI_SUCCESS)
+		pr_debug("Unable to set brightness: 0x%lx\n", status);

Add include.

drivers/firmware/efi/apple-brightness.c line 34

Quoted 2 lines
drivers/firmware/efi/apple-brightness.c new file +2 -0
+}
+EXPORT_SYMBOL(apple_brightness_shutdown);

Please put exports to a namespace.

Also, these look very much _GPL exports as you're passing get_brightnessfn around.

Quoted 10 lines
drivers/firmware/efi/apple-brightness.c new file +10 -0
+
+int apple_brightness_probe(struct backlight_device *bl,
+	int (*get_brightnessfn)(struct backlight_device *bl))
+{
+	efi_status_t status;
+	unsigned long size = sizeof(last_saved_level);
+	int ret;
+
+	bl_dev = bl;
+	get_brightness = get_brightnessfn;

drivers/firmware/efi/apple-brightness.c line 54

Quoted 10 lines
drivers/firmware/efi/apple-brightness.c new file +10 -0
+
+	if (!efi_rt_services_supported(EFI_RT_SUPPORTED_SET_VARIABLE))
+		return -ENODEV;
+
+	ret = efivar_lock();
+	if (ret)
+		return ret;
+
+	status = efivar_get_variable(APPLE_BRIGHTNESS_NAME, &APPLE_BRIGHTNESS_GUID,
+				&efi_attr, &size, &last_saved_level);

Align to (

Quoted 19 lines
drivers/firmware/efi/apple-brightness.c new file +13 -0
+
+	efivar_unlock();
+
+	if (status != EFI_SUCCESS)
+		return -ENODEV;
+
+	return 0;
+}
+EXPORT_SYMBOL(apple_brightness_probe);
+
+MODULE_AUTHOR("Atharva Tiwari <[email protected]>");
+MODULE_DESCRIPTION("EFI Brightness saver for Macs");
+MODULE_LICENSE("Dual MIT/GPL");
include/linux/platform_data/apple-brightness.h new file +0 -0
new file mode 100644
index 000000000000..54e3f3f8aa1c

include/linux/platform_data/apple-brightness.h line 10

Quoted 10 lines
include/linux/platform_data/apple-brightness.h new file +10 -0
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: GPL-2.0-only OR MIT */
+/*
+ * apple-brightness.h - EFI brightness saver for Macs
+ * Copyright (C) 2026 Atharva Tiwari <[email protected]>
+ */
+
+#ifndef _APPLE_BL_H_
+#define _APPLE_BL_H_
+
+#include <linux/backlight.h>

This can be replaced with just forward declaration of:

struct backlight_device;

include/linux/platform_data/apple-brightness.h line 17

Quoted 7 lines
include/linux/platform_data/apple-brightness.h new file +7 -0
+#include <linux/efi.h>
+
+#define APPLE_BRIGHTNESS_NAME           L"backlight-level"
+#define APPLE_BRIGHTNESS_GUID           EFI_GUID(0x7c436110, 0xab2a, 0x4bbb, 0xa8, 0x80, 0xfe, 0x41, 0x99, 0x5c, 0x9f, 0x82)
+
+int apple_brightness_probe(struct backlight_device *bl,
+	int (*get_brightnessfn)(struct backlight_device *bl));

Align to (

Quoted 4 lines
include/linux/platform_data/apple-brightness.h new file +3 -0
+
+void apple_brightness_shutdown(void);
+#endif /* _APPLE_BL_H */
Signature · 1 line
 i.
#5 lore raw

PATCH v4 2/2 platform/apple-gmux: use apple_brightness to save brightness to EFI

In reply to Atharva Tiwari

use apple_brightness to save brightness to EFI.

(tested on iMac20,1)

---
 drivers/platform/x86/apple-gmux.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
drivers/platform/x86/apple-gmux.c +21 -0
index 1417e230edbd..cab3122c1a86 100644
@@ -22,6 +22,7 @@
 #include <linux/pci.h>
 #include <linux/vga_switcheroo.h>
 #include <linux/debugfs.h>
+#include <linux/platform_data/apple-brightness.h>
 #include <acpi/video.h>
 #include <asm/io.h>
 
@@ -78,6 +79,8 @@ struct apple_gmux_data {
 	/* debugfs data */
 	u8 selected_port;
 	struct dentry *debug_dentry;
+
+	bool save_efi;
 };
 
 static struct apple_gmux_data *apple_gmux_data;
@@ -960,6 +963,13 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
 	}
 
 	gmux_init_debugfs(gmux_data);
+	if (IS_ENABLED(CONFIG_APPLE_BRIGHTNESS)) {
+		ret = apple_brightness_probe(gmux_data->bdev, &gmux_get_brightness);
+		if (ret)
+			pr_warn("Unable to Enable EFI brightness save: %d\n", ret);
+		else
+			gmux_data->save_efi = true;
+	}
 	return 0;
 
 err_register_handler:
@@ -1012,6 +1022,16 @@ static void gmux_remove(struct pnp_dev *pnp)
 	kfree(gmux_data);
 }
 
+static void gmux_shutdown(struct pnp_dev *pnp)
+{
+	struct apple_gmux_data *gmux_data = pnp_get_drvdata(pnp);
+
+	if (IS_ENABLED(CONFIG_APPLE_BRIGHTNESS) && gmux_data->save_efi)
+		apple_brightness_shutdown();
+
+	gmux_remove(pnp);
+}
+
 static const struct pnp_device_id gmux_device_ids[] = {
 	{GMUX_ACPI_HID, 0},
 	{"", 0}
@@ -1026,6 +1046,7 @@ static struct pnp_driver gmux_pnp_driver = {
 	.name		= "apple-gmux",
 	.probe		= gmux_probe,
 	.remove		= gmux_remove,
+	.shutdown	= gmux_shutdown,
 	.id_table	= gmux_device_ids,
 	.driver		= {
 			.pm = &gmux_dev_pm_ops,
Signature · 1 line
2.43.0
maintainer
#6 lore raw

Re: [PATCH v4 2/2] platform/apple-gmux: use apple_brightness to save brightness to EFI

Quoted 1 line · Atharva Tiwari

use apple_brightness to save brightness to EFI.

Please capitalize changelog text properly.

Quoted 30 lines

(tested on iMac20,1)

---
 drivers/platform/x86/apple-gmux.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
drivers/platform/x86/apple-gmux.c +3 -0
index 1417e230edbd..cab3122c1a86 100644
@@ -22,6 +22,7 @@
 #include <linux/pci.h>
 #include <linux/vga_switcheroo.h>
 #include <linux/debugfs.h>
+#include <linux/platform_data/apple-brightness.h>
 #include <acpi/video.h>
 #include <asm/io.h>
 
@@ -78,6 +79,8 @@ struct apple_gmux_data {
 	/* debugfs data */
 	u8 selected_port;
 	struct dentry *debug_dentry;
+
+	bool save_efi;
 };
 
 static struct apple_gmux_data *apple_gmux_data;

drivers/platform/x86/apple-gmux.c static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id) · line 969

Quoted 7 lines
drivers/platform/x86/apple-gmux.c +4 -0
@@ -960,6 +963,13 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
 	}
 
 	gmux_init_debugfs(gmux_data);
+	if (IS_ENABLED(CONFIG_APPLE_BRIGHTNESS)) {
+		ret = apple_brightness_probe(gmux_data->bdev, &gmux_get_brightness);
+		if (ret)
+			pr_warn("Unable to Enable EFI brightness save: %d\n", ret);

Include for pr_warn() is missing from this file.

Quoted 32 lines
drivers/platform/x86/apple-gmux.c +14 -0
+		else
+			gmux_data->save_efi = true;
+	}
 	return 0;
 
 err_register_handler:
@@ -1012,6 +1022,16 @@ static void gmux_remove(struct pnp_dev *pnp)
 	kfree(gmux_data);
 }
 
+static void gmux_shutdown(struct pnp_dev *pnp)
+{
+	struct apple_gmux_data *gmux_data = pnp_get_drvdata(pnp);
+
+	if (IS_ENABLED(CONFIG_APPLE_BRIGHTNESS) && gmux_data->save_efi)
+		apple_brightness_shutdown();
+
+	gmux_remove(pnp);
+}
+
 static const struct pnp_device_id gmux_device_ids[] = {
 	{GMUX_ACPI_HID, 0},
 	{"", 0}
@@ -1026,6 +1046,7 @@ static struct pnp_driver gmux_pnp_driver = {
 	.name		= "apple-gmux",
 	.probe		= gmux_probe,
 	.remove		= gmux_remove,
+	.shutdown	= gmux_shutdown,
 	.id_table	= gmux_device_ids,
 	.driver		= {
 			.pm = &gmux_dev_pm_ops,
Signature · 1 line
 i.