From nobody Thu Apr 2 15:36:13 2026 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (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 DFCFC352FAB for ; Wed, 11 Feb 2026 09:27:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770802024; cv=none; b=pAF3j++VHdBJx1qzGtQwp+Mct7HUHryn6y1EBOZAQbHkv8LVqi8AT27608yP0Udw1Eap+B+rL8qcnmkwsmSStQOlq9PZ8csHjAe4T9Oa+i8c/d10qyVLeJIAZbH475AgIa8RvAT35qFfjIwOjpdRRCWxOpVw1aCRgZcxAxErzhs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770802024; c=relaxed/simple; bh=DV94qfuseFusxvplrx2dXCALRLvoc4n/H9HoevKpCmg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=GO4by24yvpGPdWYfS+U9XlWD3Ko5N1R47Xcyu8ioEOh6sRSTGPqwI3OxBdXnxbDBiaeff6wvy0JM3St+6V7ECJB+3MsBdHW1C0JxdDIqP7rTgRF8VFiVChPpKZZUgyZr6vRear1EPzMl21RNb4K8LeUeDq0abO+Q6vhCJPDnQbg= 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=Zg1LdEI3; arc=none smtp.client-ip=209.85.210.182 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="Zg1LdEI3" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-823081bb15fso2588868b3a.3 for ; Wed, 11 Feb 2026 01:27:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770802022; x=1771406822; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=fm/MONFw5M6s0zO7PFtVTe+6JODzeoau1y16cdgAyAg=; b=Zg1LdEI3qtCpKM2qOnfEoCz2Rb+L8b1ZM+hmAGjNK0wurCb5OGUr0JXGbFBkmmcC6P PFhvuvfVVZscqYAfCMllecgremzgaepNNhNfzxsgr+eP2pt5KnD6DHhXDr+WOaLrWP1O mOt+DOhdJYyHbFxwzsn+aCPVafRPV7v+9GpIRFkFDsprB9v+PpHGUqrgoUTg9d8vIxqR D+FQrm1dfu5nWTTQaXh7hJXxXh/nsIAFPC6sv3kZiEa7qOmuSwzoSGmmmvo+BrFPWOqw FILK7iz7uiqVvBByv1zPtaKoQCsXDCypk0t0X6d8n4ek4wAg3n5gnCAkPxr3Nrzy7Q8j SGOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770802022; x=1771406822; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=fm/MONFw5M6s0zO7PFtVTe+6JODzeoau1y16cdgAyAg=; b=AsclGaeY9y6WWFnWDAd16qym5bUfKPGSjqU0B7sed/b5Leh33j5tOAIUPqhzmThrfX wipui6O7g5znalODOX7Y9moHi4pE0JKtdEC7iazrM7Lk70hhr7TjI1SIsUFjuzR/zwL2 w6Ko4/Rk5oaQqTEanvOizQjqx+rGq5fEhS4e/ZrFdy9mLMxJna9qPlw8em8vBehGU31M xiwuAm1OVlzZBzrs4JwjlrgeK9ZJvFrqJQhqbuC/M84VKuyOYbEyzhnAAjb3l3uAFnG3 7rSxSFJlKaQMlOsgsu9VIj6luSam/fLyTz2bJDA4UAuZSkWxTeHZchPmL3kyzH+eI5MW W+cQ== X-Forwarded-Encrypted: i=1; AJvYcCU/y0EJvZeHMNjlB2hkvVmS/LUXf8DrS0/Z17026IKnIu6iwylJ740VqBbNmYN9oiKx2cCQBY6dM5fk5eE=@vger.kernel.org X-Gm-Message-State: AOJu0YyrQDG5meNmUL0phAwJzA9RycFexTQfMjBO3U2FQFe6lnWJDlxd mZuu/GF6glkt3/4XbZPW1THDneQzfmWVJz7LeW/fxzSoAUTM+CBiTsw= X-Gm-Gg: AZuq6aIs631/y7Zp7wuBbrR14tjX+/CGZoEzft0m7X02OTYMcO0G+N91eBOjMRn7Kvb NtI3PLiZ7nkEoUwFLMSqMG3Cg0fDyirGmXqrkTIMWUmCQ08hSFS9vfa5ISHM4Rzo9AByoxJQ+5f FmEVsh084Lu9LUaOHZx/aPT39PoJp8jSlwKeMRHpu+7uNnzjqZz7KfzKjOc7a/gHfbbvGBe2Jdx HP5PEDVJqZb+tiooEKfgyuDvkLa/PlNLL4jo7zqguhAUMxYpvz/vZsnIj/aYF1j7MwleS4jFG+/ dYR6dClO/OcHvLu/1p/YcZCK5xPl6Xce/NZw5hSo8sn3bwI7nhfwqpH/EXuOOpJtqlB47k/OWCW C+cUMEJVar5giP3orSSY38wqubKl3JRHz+acuPRgLjiCsxRZdu+M00l3FMf7/aFxhDgeeNG9jgi CDH2UT1xOKXFfAKvbZAhPti1Bww52+vhtwPFQksD8= X-Received: by 2002:a05:6a20:2203:b0:38e:5655:2897 with SMTP id adf61e73a8af0-3942e396d10mr2126675637.22.1770802022085; Wed, 11 Feb 2026 01:27:02 -0800 (PST) Received: from at-iMac.. ([2401:4900:8fee:b355:955a:194f:87e2:8df8]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c6e198185b3sm1427787a12.33.2026.02.11.01.26.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Feb 2026 01:27:01 -0800 (PST) From: Atharva Tiwari To: Cc: Atharva Tiwari , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3] apple-gmux: preserve brightness using EFI Date: Wed, 11 Feb 2026 14:56:38 +0530 Message-ID: <20260211092640.3231-1-atharvatiwarilinuxdev@gmail.com> X-Mailer: git-send-email 2.43.0 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" Make apple-gmux save the current backlight brightness to EFI on shutdown, so the brightness level is preserved across reboots. (tested on iMac20,1) Signed-off-by: Atharva Tiwari Reviewed-by: Hans de Goede --- v3: - Only save the brightness when it differs from the boot brightness. v2: - Used correct size for efi_data --- drivers/platform/x86/apple-gmux.c | 61 +++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/drivers/platform/x86/apple-gmux.c b/drivers/platform/x86/apple= -gmux.c index 1417e230edbd..08b9f48c11b8 100644 --- a/drivers/platform/x86/apple-gmux.c +++ b/drivers/platform/x86/apple-gmux.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include =20 @@ -78,6 +79,11 @@ struct apple_gmux_data { /* debugfs data */ u8 selected_port; struct dentry *debug_dentry; + + /* efi data */ + efi_status_t efi_status; + u32 efi_attr; + u16 efi_data; }; =20 static struct apple_gmux_data *apple_gmux_data; @@ -107,6 +113,9 @@ struct apple_gmux_config { =20 # define MMIO_GMUX_MAX_BRIGHTNESS 0xffff =20 +#define EFI_BRIGHTNESS_NAME L"backlight-level" +#define EFI_BRIGHTNESS_GUID EFI_GUID(0x7c436110, 0xab2a, 0x4bbb, 0xa8, 0x= 80, 0xfe, 0x41, 0x99, 0x5c, 0x9f, 0x82) + static u8 gmux_pio_read8(struct apple_gmux_data *gmux_data, int port) { return inb(gmux_data->iostart + port); @@ -751,6 +760,35 @@ static void gmux_fini_debugfs(struct apple_gmux_data *= gmux_data) debugfs_remove_recursive(gmux_data->debug_dentry); } =20 +#ifdef CONFIG_EFI +MODULE_IMPORT_NS("EFIVAR"); +static void gmux_init_efi(struct apple_gmux_data *gmux_data) +{ + unsigned long size =3D sizeof(gmux_data->efi_data); + + gmux_data->efi_status =3D EFI_UNSUPPORTED; + + if (!efi_rt_services_supported(EFI_RT_SUPPORTED_SET_VARIABLE)) + return; + + if (efivar_lock()) + return; + + gmux_data->efi_status =3D efivar_get_variable(EFI_BRIGHTNESS_NAME, &EFI_B= RIGHTNESS_GUID, + &gmux_data->efi_attr, &size, &gmux_data->efi_data); + + efivar_unlock(); +} + +#else /* CONFIG_EFI */ + +static void gmux_init_efi(struct apple_gmux_data *gmux_data) +{ + return; +} + +#endif /* CONFIG_EFI */ + static int gmux_suspend(struct device *dev) { struct pnp_dev *pnp =3D to_pnp_dev(dev); @@ -960,6 +998,8 @@ static int gmux_probe(struct pnp_dev *pnp, const struct= pnp_device_id *id) } =20 gmux_init_debugfs(gmux_data); + gmux_init_efi(gmux_data); + return 0; =20 err_register_handler: @@ -1012,6 +1052,26 @@ static void gmux_remove(struct pnp_dev *pnp) kfree(gmux_data); } =20 +static void gmux_shutdown(struct pnp_dev *pnp) +{ + struct apple_gmux_data *gmux_data =3D pnp_get_drvdata(pnp); + u16 brightness =3D (u16)gmux_get_brightness(gmux_data->bdev); + +#ifdef CONFIG_EFI + if (gmux_data->efi_status =3D=3D EFI_SUCCESS && gmux_data->efi_data !=3D = brightness) { + gmux_data->efi_status =3D efivar_set_variable(EFI_BRIGHTNESS_NAME, + &EFI_BRIGHTNESS_GUID, + gmux_data->efi_attr, + sizeof(brightness), + &brightness); + if (gmux_data->efi_status !=3D EFI_SUCCESS) + pr_info("Unable to save brightness: 0x%lx\n", gmux_data->efi_status); + } +#endif /* CONFIG_EFI */ + + gmux_remove(pnp); +} + static const struct pnp_device_id gmux_device_ids[] =3D { {GMUX_ACPI_HID, 0}, {"", 0} @@ -1026,6 +1086,7 @@ static struct pnp_driver gmux_pnp_driver =3D { .name =3D "apple-gmux", .probe =3D gmux_probe, .remove =3D gmux_remove, + .shutdown =3D gmux_shutdown, .id_table =3D gmux_device_ids, .driver =3D { .pm =3D &gmux_dev_pm_ops, --=20 2.43.0