From nobody Sun Feb 8 04:11:57 2026 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E53CB2D5957 for ; Fri, 6 Feb 2026 12:57:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770382632; cv=none; b=qNhk/CswODh7/l9+oZMAfuOv/vpSNa+uau+mypikaEvnSO8odlucLFNzTEbfefKSsI0PHH3N6P2eB7FMipg2B6RWntRAzx8pJKBQuWn0vIJqytUhG2jTjLVnEFlKseuHv51wGJgVJnT8TXENsVvcfdl84ikmCwM9wRYYS4Xl8O8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770382632; c=relaxed/simple; bh=kPU1oBukxMqix0koJHcd3VsVzH9ya8xnAlosPcBArvI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BbhYMoozpsXrZGIhE1oeZtqmNFwpuXd6VDJ4uPD2ZiZ1rPrA1CGHzJO7pI7d+yKMDIdDrjCXNfdr5Czzc+Kc59PHIq3u5OHjdb5EwrsTP7ooU9/4bV61kAxmrIHLu9KZIZaaH17O/bBKQ6st1q8FagSmXoQCTb8vLR8dwr5S54s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=NJ3kS5bX; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NJ3kS5bX" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-2a09757004cso18327565ad.3 for ; Fri, 06 Feb 2026 04:57:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770382631; x=1770987431; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IoKTueZpXQx3gpN23ycBzI2bHPCHbPRI2wSorpiDz6Q=; b=NJ3kS5bX97a2RutqDdSY0DnIeuiHI9hhqnYAglQ3yi5bBtQIhsp1wX/vvb1FO6cfNf Fst3Mvkd5GGGhGMltn7qqDEfLtA6/M4uajanTJuIy5OacJR8hkRS551JIsR0aDkKKfF6 Rgl9Csg5SEWakaFCUf2Fpt84HT5s+MtFbOINUB918o0Qd51zmSSC6aJ6LSD3xhY75q0A rzBnYktnmIxvu+rZtj745YChVjaCcNsifiP6ODxVrordDaPFQL8xDBX3ZosbHViypgMs stgqa/apiVqQw662mHU2FmZq/6tNSdY/t/btz/8ZIvyb48D/9vX8DDH/6bugIYl3VBCF OWow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770382631; x=1770987431; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=IoKTueZpXQx3gpN23ycBzI2bHPCHbPRI2wSorpiDz6Q=; b=rZt/2YN4yTbt82QwPjRW31EweM7gvQqePdYH3o3i27sEaHDRZA2BsaDRQ8bA7XFzlI iUTmS5CSxo/fD5WjnWk5RQgszWOpMANJ1VoRFx8E+8hGH0gPiTa7a1iTLwRhZ83UTHKE NVW6by+Z5KTvd7hw8jVphAqGs4qF/Uw3Y0J+8MdYVkExaUyVa2Gu1P2fWpqFQSkxCqSa xXKj3luB8oGXmClkaKZP6LgxkrxIEU8wKzF+DNT69IZUJPx4OJXowx3KQJMz39D3kJ5A t9R9V0rqf9qyUxDok0Kwlvxuxt+GRdHxpG1ZZ9bUnxJtTA214zeB+VwArj2L09A/2aAO bpYg== X-Forwarded-Encrypted: i=1; AJvYcCXpbaqB1FJkJWz5h2MCVAYoAGUUDgiSJ1zzY571jB5z+y/otPoNI8p6BT0599ZbFEj5EYNtxsoL6udKtMw=@vger.kernel.org X-Gm-Message-State: AOJu0YyRxNbeuv85/i16geZq1Lr96QwutlW01DJFurFr3JTFIb1IK6eC ILSX5zEd1hl2ljmGZ0rvlDGkUF2sgOdnkgZgsiF8TG3dswwjIjIXwXY= X-Gm-Gg: AZuq6aITa0QHH0pphEdmm4tMf2P8CUuYO4v95BvXLFTXUk1a8kGY2osjZgRuyVmDPoh g/o4p5+gBiMcTkwt4IC8Kofa9nlj2wkLXD9Ok3/8Nn4cjZRgvJbXvZ5UZAFGT4+BPs0sMMWiNgu NW3aARUlp+DYyM3MOt1HwP62FTXpww82K6ZErrpEHnsILH6sX/4iZsVlviT5Zt/qQxrO8OrDQC7 djQUOkfurIS0tvYcomvCi/dlAMnKaHUrWG2JIe1Fbx4jrJHxwoW0NMa6BevMp/McsSwYMKRjtqZ WMkwgTuhJmpGctvn/hNxQK6Tsbk6WPhASy0CUdJ1uedBofD0NXu/EZ4i3niUulD8LJi11/St0O1 n1K4fR8CeW+kmdRtEaSnku26H1efkGWENSxe0SPwt/teoMWcxGlExFx394vnpZJpYTjWRGJ6ysi tOqLroIP9mo2eXDOs= X-Received: by 2002:a17:903:1b2e:b0:2a9:32c7:92db with SMTP id d9443c01a7336-2a951971b6fmr26541095ad.61.1770382631199; Fri, 06 Feb 2026 04:57:11 -0800 (PST) Received: from at.. ([171.61.167.190]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a951a636aasm23336005ad.12.2026.02.06.04.57.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Feb 2026 04:57:10 -0800 (PST) From: Atharva Tiwari To: Cc: Lukas Wunner , Atharva Tiwari , Ard Biesheuvel , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org, platform-driver-x86@vger.kernel.org Subject: [PATCH 1/2] efi: Save Brightness using EFI on Macs Date: Fri, 6 Feb 2026 12:56:21 +0000 Message-ID: <20260206125641.12983-2-atharvatiwarilinuxdev@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260206125641.12983-1-atharvatiwarilinuxdev@gmail.com> References: <20260206125641.12983-1-atharvatiwarilinuxdev@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. We use delayed work instead of a shutdown callback, as it still applies the brightness even during forced shutdowns and at 0% battery. (tested on iMac20,1) Suggested-by: Lukas Wunner Signed-off-by: Atharva Tiwari --- drivers/firmware/efi/Kconfig | 10 ++ drivers/firmware/efi/Makefile | 1 + drivers/firmware/efi/apple-brightness.c | 91 +++++++++++++++++++ .../linux/platform_data/apple-brightness.h | 21 +++++ 4 files changed, 123 insertions(+) create mode 100644 drivers/firmware/efi/apple-brightness.c create mode 100644 include/linux/platform_data/apple-brightness.h diff --git a/drivers/firmware/efi/Kconfig b/drivers/firmware/efi/Kconfig index 29e0729299f5..dd0a9c9a772a 100644 --- a/drivers/firmware/efi/Kconfig +++ b/drivers/firmware/efi/Kconfig @@ -167,6 +167,16 @@ config APPLE_PROPERTIES =20 If unsure, say Y if you have a Mac. Otherwise N. =20 +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 shutdows. 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 diff --git a/drivers/firmware/efi/Makefile b/drivers/firmware/efi/Makefile index 8efbcf699e4f..1f5705cc87a2 100644 --- a/drivers/firmware/efi/Makefile +++ b/drivers/firmware/efi/Makefile @@ -26,6 +26,7 @@ obj-$(CONFIG_EFI_BOOTLOADER_CONTROL) +=3D efibc.o obj-$(CONFIG_EFI_TEST) +=3D test/ obj-$(CONFIG_EFI_DEV_PATH_PARSER) +=3D dev-path-parser.o obj-$(CONFIG_APPLE_PROPERTIES) +=3D apple-properties.o +obj-$(CONFIG_APPLE_BRIGHTNESS) +=3D apple-brightness.o obj-$(CONFIG_EFI_RCI2_TABLE) +=3D rci2-table.o obj-$(CONFIG_EFI_EMBEDDED_FIRMWARE) +=3D embedded-firmware.o obj-$(CONFIG_LOAD_UEFI_KEYS) +=3D mokvar-table.o diff --git a/drivers/firmware/efi/apple-brightness.c b/drivers/firmware/efi= /apple-brightness.c new file mode 100644 index 000000000000..c32e365dc511 --- /dev/null +++ b/drivers/firmware/efi/apple-brightness.c @@ -0,0 +1,91 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * apple-brightness.c - EFI brightness saver on Macs + * Copyright (C) 2026 Atharva Tiwari + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include + +static DEFINE_MUTEX(apple_brightness_mutex); +static struct delayed_work apple_brightness_work; + +static u32 efi_attr; +static u16 last_saved_level; + +static int (*get_brightness)(struct backlight_device *bl); +static struct backlight_device *bl_dev; + +static void apple_brightness_workfn(struct work_struct *work) +{ + u16 level; + efi_status_t status; + + mutex_lock(&apple_brightness_mutex); + + level =3D (u16)get_brightness(bl_dev); + + if (level =3D=3D last_saved_level) + goto out; + + status =3D efivar_set_variable(APPLE_BRIGHTNESS_NAME, &APPLE_BRIGHTNESS_G= UID, + efi_attr, sizeof(level), &level); + if (status !=3D EFI_SUCCESS) + pr_debug("Unable to set brightness: 0x%lx\n", status); + else + last_saved_level =3D level; + +out: + mutex_unlock(&apple_brightness_mutex); + + mod_delayed_work(system_wq, &apple_brightness_work, + msecs_to_jiffies(APPLE_BRIGHTNESS_POLL)); +} + +int apple_brightness_probe(struct backlight_device *bl, + int (*get_brightnessfn)(struct backlight_device *bl)) +{ + efi_status_t status; + unsigned long size =3D sizeof(last_saved_level); + int ret; + + guard(mutex)(&apple_brightness_mutex); + + bl_dev =3D bl; + get_brightness =3D get_brightnessfn; + + if (!efi_rt_services_supported(EFI_RT_SUPPORTED_SET_VARIABLE)) + return -ENODEV; + + ret =3D efivar_lock(); + if (ret) + return ret; + + status =3D efivar_get_variable(APPLE_BRIGHTNESS_NAME, &APPLE_BRIGHTNESS_G= UID, + &efi_attr, &size, &last_saved_level); + + efivar_unlock(); + + if (status !=3D EFI_SUCCESS) + return -ENODEV; + + bl_dev =3D bl; + get_brightness =3D get_brightnessfn; + + INIT_DELAYED_WORK(&apple_brightness_work, apple_brightness_workfn); + mod_delayed_work(system_wq, &apple_brightness_work, + msecs_to_jiffies(APPLE_BRIGHTNESS_POLL)); + + return 0; +} +EXPORT_SYMBOL(apple_brightness_probe); + +MODULE_AUTHOR("Atharva Tiwari "); +MODULE_DESCRIPTION("EFI Brightness saver for Macs"); +MODULE_LICENSE("Dual MIT/GPL"); diff --git a/include/linux/platform_data/apple-brightness.h b/include/linux= /platform_data/apple-brightness.h new file mode 100644 index 000000000000..4cf5e2d346cb --- /dev/null +++ b/include/linux/platform_data/apple-brightness.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ +/* + * apple-brightness.h - EFI brightness saver for Macs + * Copyright (C) 2026 Atharva Tiwari + */ + +#ifndef _APPLE_BL_H_ +#define _APPLE_BL_H_ + +#include +#include + +#define APPLE_BRIGHTNESS_NAME L"backlight-level" +#define APPLE_BRIGHTNESS_GUID EFI_GUID(0x7c436110, 0xab2a, 0x4bb= b, 0xa8, 0x80, 0xfe, 0x41, 0x99, 0x5c, 0x9f, 0x82) + +#define APPLE_BRIGHTNESS_POLL 300 + +int apple_brightness_probe(struct backlight_device *bl, + int (*get_brightnessfn)(struct backlight_device *bl)); + +#endif /* _APPLE_BL_H */ --=20 2.43.0