platform/x86: apple-gmux: Add acpi_video_get_backlight_type() check
PATCH 1/1 platform/x86: apple-gmux: Add acpi_video_get_backlight_type() check
Make apple-gmux backlight registration honor the acpi_backlight=... kernel commandline option which is used to select the backlight control method on x86/ACPI devices.
Reported-and-tested-by Aditya Garg <[email protected]>
Link https://lore.kernel.org/platform-driver-x86/BM1PR01MB0931B467250831916F7C55B3B8A59@BM1PR01MB0931.INDPRD01.PROD.OUTLOOK.COM/ open here
Signed-off-by Hans de Goede <[email protected]>
--- drivers/platform/x86/apple-gmux.c | 59 +++++++++++++++++-------------- 1 file changed, 33 insertions(+), 26 deletions(-)
drivers/platform/x86/apple-gmux.c +33 -26
@@ -23,6 +23,7 @@#include <linux/pci.h> #include <linux/vga_switcheroo.h> #include <linux/debugfs.h> +#include <acpi/video.h> #include <asm/io.h> /**
@@ -783,6 +784,7 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)struct backlight_properties props;struct backlight_device *bdev;u8 ver_major, ver_minor, ver_release; +bool register_bdev = true;int ret = -ENXIO ;acpi_status status;unsigned long long gpe;
@@ -859,33 +861,38 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id) props.type =BACKLIGHT_PLATFORM ; props.max_brightness =gmux_read32 (gmux_data,GMUX_PORT_MAX_BRIGHTNESS ); -/* -* Currently it's assumed that the maximum brightness is less than -* 2^24 for compatibility with old gmux versions. Cap the max -* brightness at this value, but print a warning if the hardware -* reports something higher so that it can be fixed. -*/ -if (WARN_ON (props.max_brightness >GMUX_MAX_BRIGHTNESS )) - props.max_brightness =GMUX_MAX_BRIGHTNESS ; - - bdev =backlight_device_register ("gmux_backlight" , &pnp->dev, - gmux_data, &gmux_bl_ops, &props); -if (IS_ERR (bdev)) { - ret =PTR_ERR (bdev); - goto err_unmap; - } - - gmux_data->bdev = bdev; - bdev->props.brightness =gmux_get_brightness (bdev); -backlight_update_status (bdev); +#if IS_REACHABLE (CONFIG_ACPI_VIDEO ) + register_bdev =acpi_video_get_backlight_type () == acpi_backlight_apple_gmux; +#endif +if (register_bdev) { +/* +* Currently it's assumed that the maximum brightness is less than +* 2^24 for compatibility with old gmux versions. Cap the max +* brightness at this value, but print a warning if the hardware +* reports something higher so that it can be fixed. +*/ +if (WARN_ON (props.max_brightness >GMUX_MAX_BRIGHTNESS )) + props.max_brightness =GMUX_MAX_BRIGHTNESS ; + + bdev =backlight_device_register ("gmux_backlight" , &pnp->dev, + gmux_data, &gmux_bl_ops, &props); +if (IS_ERR (bdev)) { + ret =PTR_ERR (bdev); + goto err_unmap; + } -/* -* The backlight situation on Macs is complicated. If the gmux is -* present it's the best choice, because it always works for -* backlight control and supports more levels than other options. -* Disable the other backlight choices. -*/ -apple_bl_unregister (); + gmux_data->bdev = bdev; + bdev->props.brightness =gmux_get_brightness (bdev); +backlight_update_status (bdev); + +/* +* The backlight situation on Macs is complicated. If the gmux is +* present it's the best choice, because it always works for +* backlight control and supports more levels than other options. +* Disable the other backlight choices. +*/ +apple_bl_unregister (); + } gmux_data->power_state =VGA_SWITCHEROO_ON ;
Signature · 1 line
2.39.1
Hi,
Quoted 7 lines · Hans de Goede
Make apple-gmux backlight registration honor the acpi_backlight=... kernel commandline option which is used to select the backlight control method on x86/ACPI devices.
I've added this to my review-hans (soon to be for-next) branch now.
Regards,
Hans
Quoted 89 lines
--- drivers/platform/x86/apple-gmux.c | 59 +++++++++++++++++-------------- 1 file changed, 33 insertions(+), 26 deletions(-)drivers/platform/x86/apple-gmux.c +33
-26@@ -23,6 +23,7 @@#include <linux/pci.h> #include <linux/vga_switcheroo.h> #include <linux/debugfs.h> +#include <acpi/video.h> #include <asm/io.h> /** @@ -783,6 +784,7 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)struct backlight_properties props;struct backlight_device *bdev;u8 ver_major, ver_minor, ver_release; +bool register_bdev = true;int ret = -ENXIO ;acpi_status status;unsigned long long gpe;@@ -859,33 +861,38 @@ static int gmux_probe(struct pnp_dev *pnp, const struct pnp_device_id *id) props.type =BACKLIGHT_PLATFORM ; props.max_brightness =gmux_read32 (gmux_data,GMUX_PORT_MAX_BRIGHTNESS ); -/* -* Currently it's assumed that the maximum brightness is less than -* 2^24 for compatibility with old gmux versions. Cap the max -* brightness at this value, but print a warning if the hardware -* reports something higher so that it can be fixed. -*/ -if (WARN_ON (props.max_brightness >GMUX_MAX_BRIGHTNESS )) - props.max_brightness =GMUX_MAX_BRIGHTNESS ; - - bdev =backlight_device_register ("gmux_backlight" , &pnp->dev, - gmux_data, &gmux_bl_ops, &props); -if (IS_ERR (bdev)) { - ret =PTR_ERR (bdev); - goto err_unmap; - } - - gmux_data->bdev = bdev; - bdev->props.brightness =gmux_get_brightness (bdev); -backlight_update_status (bdev); +#if IS_REACHABLE (CONFIG_ACPI_VIDEO ) + register_bdev =acpi_video_get_backlight_type () == acpi_backlight_apple_gmux; +#endif +if (register_bdev) { +/* +* Currently it's assumed that the maximum brightness is less than +* 2^24 for compatibility with old gmux versions. Cap the max +* brightness at this value, but print a warning if the hardware +* reports something higher so that it can be fixed. +*/ +if (WARN_ON (props.max_brightness >GMUX_MAX_BRIGHTNESS )) + props.max_brightness =GMUX_MAX_BRIGHTNESS ; + + bdev =backlight_device_register ("gmux_backlight" , &pnp->dev, + gmux_data, &gmux_bl_ops, &props); +if (IS_ERR (bdev)) { + ret =PTR_ERR (bdev); + goto err_unmap; + } -/* -* The backlight situation on Macs is complicated. If the gmux is -* present it's the best choice, because it always works for -* backlight control and supports more levels than other options. -* Disable the other backlight choices. -*/ -apple_bl_unregister (); + gmux_data->bdev = bdev; + bdev->props.brightness =gmux_get_brightness (bdev); +backlight_update_status (bdev); + +/* +* The backlight situation on Macs is complicated. If the gmux is +* present it's the best choice, because it always works for +* backlight control and supports more levels than other options. +* Disable the other backlight choices. +*/ +apple_bl_unregister (); + } gmux_data->power_state =VGA_SWITCHEROO_ON ;