Linux Audio

Check our new training course

Loading...
v6.13.7
   1/*
   2 *  Copyright (C) 2015       Red Hat Inc.
   3 *                           Hans de Goede <hdegoede@redhat.com>
   4 *  Copyright (C) 2008       SuSE Linux Products GmbH
   5 *                           Thomas Renninger <trenn@suse.de>
   6 *
   7 *  May be copied or modified under the terms of the GNU General Public License
   8 *
   9 * video_detect.c:
  10 * After PCI devices are glued with ACPI devices
  11 * acpi_get_pci_dev() can be called to identify ACPI graphics
  12 * devices for which a real graphics card is plugged in
  13 *
  14 * Depending on whether ACPI graphics extensions (cmp. ACPI spec Appendix B)
  15 * are available, video.ko should be used to handle the device.
  16 *
  17 * Otherwise vendor specific drivers like thinkpad_acpi, asus-laptop,
  18 * sony_acpi,... can take care about backlight brightness.
  19 *
  20 * Backlight drivers can use acpi_video_get_backlight_type() to determine which
  21 * driver should handle the backlight. RAW/GPU-driver backlight drivers must
  22 * use the acpi_video_backlight_use_native() helper for this.
  23 *
  24 * If CONFIG_ACPI_VIDEO is neither set as "compiled in" (y) nor as a module (m)
  25 * this file will not be compiled and acpi_video_get_backlight_type() will
  26 * always return acpi_backlight_vendor.
  27 */
  28
  29#include <linux/export.h>
  30#include <linux/acpi.h>
  31#include <linux/apple-gmux.h>
  32#include <linux/backlight.h>
  33#include <linux/dmi.h>
  34#include <linux/module.h>
  35#include <linux/pci.h>
  36#include <linux/platform_data/x86/nvidia-wmi-ec-backlight.h>
  37#include <linux/pnp.h>
  38#include <linux/types.h>
  39#include <linux/workqueue.h>
  40#include <acpi/video.h>
  41
  42static enum acpi_backlight_type acpi_backlight_cmdline = acpi_backlight_undef;
  43static enum acpi_backlight_type acpi_backlight_dmi = acpi_backlight_undef;
  44
  45static void acpi_video_parse_cmdline(void)
  46{
  47	if (!strcmp("vendor", acpi_video_backlight_string))
  48		acpi_backlight_cmdline = acpi_backlight_vendor;
  49	if (!strcmp("video", acpi_video_backlight_string))
  50		acpi_backlight_cmdline = acpi_backlight_video;
  51	if (!strcmp("native", acpi_video_backlight_string))
  52		acpi_backlight_cmdline = acpi_backlight_native;
  53	if (!strcmp("nvidia_wmi_ec", acpi_video_backlight_string))
  54		acpi_backlight_cmdline = acpi_backlight_nvidia_wmi_ec;
  55	if (!strcmp("apple_gmux", acpi_video_backlight_string))
  56		acpi_backlight_cmdline = acpi_backlight_apple_gmux;
  57	if (!strcmp("dell_uart", acpi_video_backlight_string))
  58		acpi_backlight_cmdline = acpi_backlight_dell_uart;
  59	if (!strcmp("none", acpi_video_backlight_string))
  60		acpi_backlight_cmdline = acpi_backlight_none;
  61}
  62
  63static acpi_status
  64find_video(acpi_handle handle, u32 lvl, void *context, void **rv)
  65{
  66	struct acpi_device *acpi_dev = acpi_fetch_acpi_dev(handle);
  67	long *cap = context;
  68	struct pci_dev *dev;
  69
  70	static const struct acpi_device_id video_ids[] = {
  71		{ACPI_VIDEO_HID, 0},
  72		{"", 0},
  73	};
  74
  75	if (acpi_dev && !acpi_match_device_ids(acpi_dev, video_ids)) {
  76		dev = acpi_get_pci_dev(handle);
  77		if (!dev)
  78			return AE_OK;
  79		pci_dev_put(dev);
  80		*cap |= acpi_is_video_device(handle);
  81	}
  82	return AE_OK;
  83}
  84
  85/* This depends on ACPI_WMI which is X86 only */
  86#ifdef CONFIG_X86
  87static bool nvidia_wmi_ec_supported(void)
  88{
  89	struct wmi_brightness_args args = {
  90		.mode = WMI_BRIGHTNESS_MODE_GET,
  91		.val = 0,
  92		.ret = 0,
  93	};
  94	struct acpi_buffer buf = { (acpi_size)sizeof(args), &args };
  95	acpi_status status;
  96
  97	status = wmi_evaluate_method(WMI_BRIGHTNESS_GUID, 0,
  98				     WMI_BRIGHTNESS_METHOD_SOURCE, &buf, &buf);
  99	if (ACPI_FAILURE(status))
 100		return false;
 101
 102	/*
 103	 * If brightness is handled by the EC then nvidia-wmi-ec-backlight
 104	 * should be used, else the GPU driver(s) should be used.
 105	 */
 106	return args.ret == WMI_BRIGHTNESS_SOURCE_EC;
 107}
 108#else
 109static bool nvidia_wmi_ec_supported(void)
 110{
 111	return false;
 112}
 113#endif
 114
 115/* Force to use vendor driver when the ACPI device is known to be
 116 * buggy */
 117static int video_detect_force_vendor(const struct dmi_system_id *d)
 118{
 119	acpi_backlight_dmi = acpi_backlight_vendor;
 120	return 0;
 121}
 122
 123static int video_detect_force_video(const struct dmi_system_id *d)
 124{
 125	acpi_backlight_dmi = acpi_backlight_video;
 126	return 0;
 127}
 128
 129static int video_detect_force_native(const struct dmi_system_id *d)
 130{
 131	acpi_backlight_dmi = acpi_backlight_native;
 132	return 0;
 133}
 134
 135static int video_detect_portege_r100(const struct dmi_system_id *d)
 136{
 137	struct pci_dev *dev;
 138	/* Search for Trident CyberBlade XP4m32 to confirm Portégé R100 */
 139	dev = pci_get_device(PCI_VENDOR_ID_TRIDENT, 0x2100, NULL);
 140	if (dev)
 141		acpi_backlight_dmi = acpi_backlight_vendor;
 142	return 0;
 143}
 144
 145static const struct dmi_system_id video_detect_dmi_table[] = {
 146	/*
 147	 * Models which should use the vendor backlight interface,
 148	 * because of broken ACPI video backlight control.
 149	 */
 150	{
 151	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1128309 */
 152	 .callback = video_detect_force_vendor,
 153	 /* Acer KAV80 */
 154	 .matches = {
 155		DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 156		DMI_MATCH(DMI_PRODUCT_NAME, "KAV80"),
 157		},
 158	},
 159	{
 160	 .callback = video_detect_force_vendor,
 161	 /* Asus UL30VT */
 162	 .matches = {
 163		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
 164		DMI_MATCH(DMI_PRODUCT_NAME, "UL30VT"),
 165		},
 166	},
 167	{
 168	 .callback = video_detect_force_vendor,
 169	 /* Asus UL30A */
 170	 .matches = {
 171		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
 172		DMI_MATCH(DMI_PRODUCT_NAME, "UL30A"),
 173		},
 174	},
 175	{
 176	 .callback = video_detect_force_vendor,
 177	 /* Asus X55U */
 178	 .matches = {
 179		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
 180		DMI_MATCH(DMI_PRODUCT_NAME, "X55U"),
 181		},
 182	},
 183	{
 184	 /* https://bugs.launchpad.net/bugs/1000146 */
 185	 .callback = video_detect_force_vendor,
 186	 /* Asus X101CH */
 187	 .matches = {
 188		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
 189		DMI_MATCH(DMI_PRODUCT_NAME, "X101CH"),
 190		},
 191	},
 192	{
 193	 .callback = video_detect_force_vendor,
 194	 /* Asus X401U */
 195	 .matches = {
 196		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
 197		DMI_MATCH(DMI_PRODUCT_NAME, "X401U"),
 198		},
 199	},
 200	{
 201	 .callback = video_detect_force_vendor,
 202	 /* Asus X501U */
 203	 .matches = {
 204		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
 205		DMI_MATCH(DMI_PRODUCT_NAME, "X501U"),
 206		},
 207	},
 208	{
 209	 /* https://bugs.launchpad.net/bugs/1000146 */
 210	 .callback = video_detect_force_vendor,
 211	 /* Asus 1015CX */
 212	 .matches = {
 213		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
 214		DMI_MATCH(DMI_PRODUCT_NAME, "1015CX"),
 215		},
 216	},
 217	{
 218	 .callback = video_detect_force_vendor,
 219	 /* Samsung N150/N210/N220 */
 220	 .matches = {
 221		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
 222		DMI_MATCH(DMI_PRODUCT_NAME, "N150/N210/N220"),
 223		DMI_MATCH(DMI_BOARD_NAME, "N150/N210/N220"),
 224		},
 225	},
 226	{
 227	 .callback = video_detect_force_vendor,
 228	 /* Samsung NF110/NF210/NF310 */
 229	 .matches = {
 230		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
 231		DMI_MATCH(DMI_PRODUCT_NAME, "NF110/NF210/NF310"),
 232		DMI_MATCH(DMI_BOARD_NAME, "NF110/NF210/NF310"),
 233		},
 234	},
 235	{
 236	 .callback = video_detect_force_vendor,
 237	 /* Samsung NC210 */
 238	 .matches = {
 239		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
 240		DMI_MATCH(DMI_PRODUCT_NAME, "NC210/NC110"),
 241		DMI_MATCH(DMI_BOARD_NAME, "NC210/NC110"),
 242		},
 243	},
 244
 245	/*
 246	 * Models which should use the vendor backlight interface,
 247	 * because of broken native backlight control.
 248	 */
 249	{
 250	 .callback = video_detect_force_vendor,
 251	 /* Sony Vaio PCG-FRV35 */
 252	 .matches = {
 253		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
 254		DMI_MATCH(DMI_PRODUCT_NAME, "PCG-FRV35"),
 255		},
 256	},
 257	{
 258	 .callback = video_detect_force_vendor,
 259	 /* Panasonic Toughbook CF-18 */
 260	 .matches = {
 261		DMI_MATCH(DMI_SYS_VENDOR, "Matsushita Electric Industrial"),
 262		DMI_MATCH(DMI_PRODUCT_NAME, "CF-18"),
 263		},
 264	},
 265
 266	/*
 267	 * Toshiba models with Transflective display, these need to use
 268	 * the toshiba_acpi vendor driver for proper Transflective handling.
 269	 */
 270	{
 271	 .callback = video_detect_force_vendor,
 272	 .matches = {
 273		DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
 274		DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE R500"),
 275		},
 276	},
 277	{
 278	 .callback = video_detect_force_vendor,
 279	 .matches = {
 280		DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
 281		DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE R600"),
 282		},
 283	},
 284
 285	/*
 286	 * Toshiba Portégé R100 has working both acpi_video and toshiba_acpi
 287	 * vendor driver. But none of them gets activated as it has a VGA with
 288	 * no kernel driver (Trident CyberBlade XP4m32).
 289	 * The DMI strings are generic so check for the VGA chip in callback.
 290	 */
 291	{
 292	 .callback = video_detect_portege_r100,
 293	 .matches = {
 294		DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
 295		DMI_MATCH(DMI_PRODUCT_NAME, "Portable PC"),
 296		DMI_MATCH(DMI_PRODUCT_VERSION, "Version 1.0"),
 297		DMI_MATCH(DMI_BOARD_NAME, "Portable PC")
 298		},
 299	},
 300
 301	/*
 302	 * Models which need acpi_video backlight control where the GPU drivers
 303	 * do not call acpi_video_register_backlight() because no internal panel
 304	 * is detected. Typically these are all-in-ones (monitors with builtin
 305	 * PC) where the panel connection shows up as regular DP instead of eDP.
 306	 */
 307	{
 308	 .callback = video_detect_force_video,
 309	 /* Apple iMac14,1 */
 310	 .matches = {
 311		DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
 312		DMI_MATCH(DMI_PRODUCT_NAME, "iMac14,1"),
 313		},
 314	},
 315	{
 316	 .callback = video_detect_force_video,
 317	 /* Apple iMac14,2 */
 318	 .matches = {
 319		DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
 320		DMI_MATCH(DMI_PRODUCT_NAME, "iMac14,2"),
 321		},
 322	},
 323
 324	/*
 325	 * These models have a working acpi_video backlight control, and using
 326	 * native backlight causes a regression where backlight does not work
 327	 * when userspace is not handling brightness key events. Disable
 328	 * native_backlight on these to fix this:
 329	 * https://bugzilla.kernel.org/show_bug.cgi?id=81691
 330	 */
 331	{
 332	 .callback = video_detect_force_video,
 333	 /* ThinkPad T420 */
 334	 .matches = {
 335		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
 336		DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T420"),
 337		},
 338	},
 339	{
 340	 .callback = video_detect_force_video,
 341	 /* ThinkPad T520 */
 342	 .matches = {
 343		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
 344		DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T520"),
 345		},
 346	},
 347	{
 348	 .callback = video_detect_force_video,
 349	 /* ThinkPad X201s */
 350	 .matches = {
 351		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
 352		DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X201s"),
 353		},
 354	},
 355	{
 356	 .callback = video_detect_force_video,
 357	 /* ThinkPad X201T */
 358	 .matches = {
 359		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
 360		DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X201T"),
 361		},
 362	},
 363
 364	/* The native backlight controls do not work on some older machines */
 365	{
 366	 /* https://bugs.freedesktop.org/show_bug.cgi?id=81515 */
 367	 .callback = video_detect_force_video,
 368	 /* HP ENVY 15 Notebook */
 369	 .matches = {
 370		DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
 371		DMI_MATCH(DMI_PRODUCT_NAME, "HP ENVY 15 Notebook PC"),
 372		},
 373	},
 374	{
 375	 .callback = video_detect_force_video,
 376	 /* SAMSUNG 870Z5E/880Z5E/680Z5E */
 377	 .matches = {
 378		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
 379		DMI_MATCH(DMI_PRODUCT_NAME, "870Z5E/880Z5E/680Z5E"),
 380		},
 381	},
 382	{
 383	 .callback = video_detect_force_video,
 384	 /* SAMSUNG 370R4E/370R4V/370R5E/3570RE/370R5V */
 385	 .matches = {
 386		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
 387		DMI_MATCH(DMI_PRODUCT_NAME,
 388			  "370R4E/370R4V/370R5E/3570RE/370R5V"),
 389		},
 390	},
 391	{
 392	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1186097 */
 393	 .callback = video_detect_force_video,
 394	 /* SAMSUNG 3570R/370R/470R/450R/510R/4450RV */
 395	 .matches = {
 396		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
 397		DMI_MATCH(DMI_PRODUCT_NAME,
 398			  "3570R/370R/470R/450R/510R/4450RV"),
 399		},
 400	},
 401	{
 402	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1557060 */
 403	 .callback = video_detect_force_video,
 404	 /* SAMSUNG 670Z5E */
 405	 .matches = {
 406		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
 407		DMI_MATCH(DMI_PRODUCT_NAME, "670Z5E"),
 408		},
 409	},
 410	{
 411	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1094948 */
 412	 .callback = video_detect_force_video,
 413	 /* SAMSUNG 730U3E/740U3E */
 414	 .matches = {
 415		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
 416		DMI_MATCH(DMI_PRODUCT_NAME, "730U3E/740U3E"),
 417		},
 418	},
 419	{
 420	 /* https://bugs.freedesktop.org/show_bug.cgi?id=87286 */
 421	 .callback = video_detect_force_video,
 422	 /* SAMSUNG 900X3C/900X3D/900X3E/900X4C/900X4D */
 423	 .matches = {
 424		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
 425		DMI_MATCH(DMI_PRODUCT_NAME,
 426			  "900X3C/900X3D/900X3E/900X4C/900X4D"),
 427		},
 428	},
 429	{
 430	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1272633 */
 431	 .callback = video_detect_force_video,
 432	 /* Dell XPS14 L421X */
 433	 .matches = {
 434		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
 435		DMI_MATCH(DMI_PRODUCT_NAME, "XPS L421X"),
 436		},
 437	},
 438	{
 439	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1163574 */
 440	 .callback = video_detect_force_video,
 441	 /* Dell XPS15 L521X */
 442	 .matches = {
 443		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
 444		DMI_MATCH(DMI_PRODUCT_NAME, "XPS L521X"),
 445		},
 446	},
 447	{
 448	 /* https://bugzilla.kernel.org/show_bug.cgi?id=108971 */
 449	 .callback = video_detect_force_video,
 450	 /* SAMSUNG 530U4E/540U4E */
 451	 .matches = {
 452		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
 453		DMI_MATCH(DMI_PRODUCT_NAME, "530U4E/540U4E"),
 454		},
 455	},
 456	{
 457	 /* https://bugs.launchpad.net/bugs/1894667 */
 458	 .callback = video_detect_force_video,
 459	 /* HP 635 Notebook */
 460	 .matches = {
 461		DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
 462		DMI_MATCH(DMI_PRODUCT_NAME, "HP 635 Notebook PC"),
 463		},
 464	},
 465
 466	/* Non win8 machines which need native backlight nevertheless */
 467	{
 468	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1201530 */
 469	 .callback = video_detect_force_native,
 470	 /* Lenovo Ideapad S405 */
 471	 .matches = {
 472		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
 473		DMI_MATCH(DMI_BOARD_NAME, "Lenovo IdeaPad S405"),
 474		},
 475	},
 476	{
 477	 /* https://bugzilla.suse.com/show_bug.cgi?id=1208724 */
 478	 .callback = video_detect_force_native,
 479	 /* Lenovo Ideapad Z470 */
 480	 .matches = {
 481		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
 482		DMI_MATCH(DMI_PRODUCT_VERSION, "IdeaPad Z470"),
 483		},
 484	},
 485	{
 486	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1187004 */
 487	 .callback = video_detect_force_native,
 488	 /* Lenovo Ideapad Z570 */
 489	 .matches = {
 490		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
 491		DMI_MATCH(DMI_PRODUCT_VERSION, "Ideapad Z570"),
 492		},
 493	},
 494	{
 495	 .callback = video_detect_force_native,
 496	 /* Lenovo E41-25 */
 497	 .matches = {
 498		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
 499		DMI_MATCH(DMI_PRODUCT_NAME, "81FS"),
 500		},
 501	},
 502	{
 503	 .callback = video_detect_force_native,
 504	 /* Lenovo E41-45 */
 505	 .matches = {
 506		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
 507		DMI_MATCH(DMI_PRODUCT_NAME, "82BK"),
 508		},
 509	},
 510	{
 511	 .callback = video_detect_force_native,
 512	 /* Lenovo Slim 7 16ARH7 */
 513	 .matches = {
 514		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
 515		DMI_MATCH(DMI_PRODUCT_NAME, "82UX"),
 516		},
 517	},
 518	{
 519	 .callback = video_detect_force_native,
 520	 /* Lenovo ThinkPad X131e (3371 AMD version) */
 521	 .matches = {
 522		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
 523		DMI_MATCH(DMI_PRODUCT_NAME, "3371"),
 524		},
 525	},
 526	{
 527	 .callback = video_detect_force_native,
 528	 /* Apple iMac11,3 */
 529	 .matches = {
 530		DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
 531		DMI_MATCH(DMI_PRODUCT_NAME, "iMac11,3"),
 532		},
 533	},
 534	{
 535	 /* https://gitlab.freedesktop.org/drm/amd/-/issues/1838 */
 536	 .callback = video_detect_force_native,
 537	 /* Apple iMac12,1 */
 538	 .matches = {
 539		DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
 540		DMI_MATCH(DMI_PRODUCT_NAME, "iMac12,1"),
 541		},
 542	},
 543	{
 544	 /* https://gitlab.freedesktop.org/drm/amd/-/issues/2753 */
 545	 .callback = video_detect_force_native,
 546	 /* Apple iMac12,2 */
 547	 .matches = {
 548		DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
 549		DMI_MATCH(DMI_PRODUCT_NAME, "iMac12,2"),
 550		},
 551	},
 552	{
 553	 .callback = video_detect_force_native,
 554	 /* Apple MacBook Air 7,2 */
 555	 .matches = {
 556		DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
 557		DMI_MATCH(DMI_PRODUCT_NAME, "MacBookAir7,2"),
 558		},
 559	},
 560	{
 561	 .callback = video_detect_force_native,
 562	 /* Apple MacBook Air 9,1 */
 563	 .matches = {
 564		DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
 565		DMI_MATCH(DMI_PRODUCT_NAME, "MacBookAir9,1"),
 566		},
 567	},
 568	{
 569	 .callback = video_detect_force_native,
 570	 /* Apple MacBook Pro 9,2 */
 571	 .matches = {
 572		DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
 573		DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro9,2"),
 574		},
 575	},
 576	{
 577	 .callback = video_detect_force_native,
 578	 /* Apple MacBook Pro 11,2 */
 579	 .matches = {
 580		DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
 581		DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro11,2"),
 582		},
 583	},
 584	{
 585	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1217249 */
 586	 .callback = video_detect_force_native,
 587	 /* Apple MacBook Pro 12,1 */
 588	 .matches = {
 589		DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
 590		DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro12,1"),
 591		},
 592	},
 593	{
 594	 .callback = video_detect_force_native,
 595	 /* Apple MacBook Pro 16,2 */
 596	 .matches = {
 597		DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
 598		DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro16,2"),
 599		},
 600	},
 601	{
 602	 .callback = video_detect_force_native,
 603	 /* Dell Inspiron N4010 */
 604	 .matches = {
 605		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
 606		DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron N4010"),
 607		},
 608	},
 609	{
 610	 .callback = video_detect_force_native,
 611	 /* Dell Vostro V131 */
 612	 .matches = {
 613		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
 614		DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V131"),
 615		},
 616	},
 617	{
 618	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1123661 */
 619	 .callback = video_detect_force_native,
 620	 /* Dell XPS 17 L702X */
 621	 .matches = {
 622		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
 623		DMI_MATCH(DMI_PRODUCT_NAME, "Dell System XPS L702X"),
 624		},
 625	},
 626	{
 627	 .callback = video_detect_force_native,
 628	 /* Dell Precision 7510 */
 629	 .matches = {
 630		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
 631		DMI_MATCH(DMI_PRODUCT_NAME, "Precision 7510"),
 632		},
 633	},
 634	{
 635	 .callback = video_detect_force_native,
 636	 /* Dell Studio 1569 */
 637	 .matches = {
 638		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
 639		DMI_MATCH(DMI_PRODUCT_NAME, "Studio 1569"),
 640		},
 641	},
 642	{
 643	 .callback = video_detect_force_native,
 644	 /* Acer Aspire 3830TG */
 645	 .matches = {
 646		DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 647		DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3830TG"),
 648		},
 649	},
 650	{
 651	 .callback = video_detect_force_native,
 652	 /* Acer Aspire 4810T */
 653	 .matches = {
 654		DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 655		DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 4810T"),
 656		},
 657	},
 658	{
 659	 .callback = video_detect_force_native,
 660	 /* Acer Aspire 5738z */
 661	 .matches = {
 662		DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 663		DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5738"),
 664		DMI_MATCH(DMI_BOARD_NAME, "JV50"),
 665		},
 666	},
 667	{
 668	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1012674 */
 669	 .callback = video_detect_force_native,
 670	 /* Acer Aspire 5741 */
 671	 .matches = {
 672		DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
 673		DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5741"),
 674		},
 675	},
 676	{
 677	 /* https://bugzilla.kernel.org/show_bug.cgi?id=42993 */
 678	 .callback = video_detect_force_native,
 679	 /* Acer Aspire 5750 */
 680	 .matches = {
 681		DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
 682		DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5750"),
 683		},
 684	},
 685	{
 686	 /* https://bugzilla.kernel.org/show_bug.cgi?id=42833 */
 687	 .callback = video_detect_force_native,
 688	 /* Acer Extensa 5235 */
 689	 .matches = {
 690		DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
 691		DMI_MATCH(DMI_PRODUCT_NAME, "Extensa 5235"),
 692		},
 693	},
 694	{
 695	 .callback = video_detect_force_native,
 696	 /* Acer TravelMate 4750 */
 697	 .matches = {
 698		DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
 699		DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4750"),
 700		},
 701	},
 702	{
 703	 /* https://bugzilla.kernel.org/show_bug.cgi?id=207835 */
 704	 .callback = video_detect_force_native,
 705	 /* Acer TravelMate 5735Z */
 706	 .matches = {
 707		DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
 708		DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 5735Z"),
 709		DMI_MATCH(DMI_BOARD_NAME, "BA51_MV"),
 710		},
 711	},
 712	{
 713	 /* https://bugzilla.kernel.org/show_bug.cgi?id=36322 */
 714	 .callback = video_detect_force_native,
 715	 /* Acer TravelMate 5760 */
 716	 .matches = {
 717		DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
 718		DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 5760"),
 719		},
 720	},
 721	{
 722	 .callback = video_detect_force_native,
 723	 /* ASUSTeK COMPUTER INC. GA401 */
 724	 .matches = {
 725		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
 726		DMI_MATCH(DMI_PRODUCT_NAME, "GA401"),
 727		},
 728	},
 729	{
 730	 .callback = video_detect_force_native,
 731	 /* ASUSTeK COMPUTER INC. GA502 */
 732	 .matches = {
 733		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
 734		DMI_MATCH(DMI_PRODUCT_NAME, "GA502"),
 735		},
 736	},
 737	{
 738	 .callback = video_detect_force_native,
 739	 /* ASUSTeK COMPUTER INC. GA503 */
 740	 .matches = {
 741		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
 742		DMI_MATCH(DMI_PRODUCT_NAME, "GA503"),
 743		},
 744	},
 745	{
 746	 .callback = video_detect_force_native,
 747	 /* Asus U46E */
 748	 .matches = {
 749		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
 750		DMI_MATCH(DMI_PRODUCT_NAME, "U46E"),
 751		},
 752	},
 753	{
 754	 .callback = video_detect_force_native,
 755	 /* Asus UX303UB */
 756	 .matches = {
 757		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
 758		DMI_MATCH(DMI_PRODUCT_NAME, "UX303UB"),
 759		},
 760	},
 761	{
 762	 .callback = video_detect_force_native,
 763	 /* HP EliteBook 8460p */
 764	 .matches = {
 765		DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
 766		DMI_MATCH(DMI_PRODUCT_NAME, "HP EliteBook 8460p"),
 767		},
 768	},
 769	{
 770	 .callback = video_detect_force_native,
 771	 /* HP Pavilion g6-1d80nr / B4U19UA */
 772	 .matches = {
 773		DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
 774		DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion g6 Notebook PC"),
 775		DMI_MATCH(DMI_PRODUCT_SKU, "B4U19UA"),
 776		},
 777	},
 778	{
 779	 .callback = video_detect_force_native,
 780	 /* Samsung N150P */
 781	 .matches = {
 782		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
 783		DMI_MATCH(DMI_PRODUCT_NAME, "N150P"),
 784		DMI_MATCH(DMI_BOARD_NAME, "N150P"),
 785		},
 786	},
 787	{
 788	 .callback = video_detect_force_native,
 789	 /* Samsung N145P/N250P/N260P */
 790	 .matches = {
 791		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
 792		DMI_MATCH(DMI_PRODUCT_NAME, "N145P/N250P/N260P"),
 793		DMI_MATCH(DMI_BOARD_NAME, "N145P/N250P/N260P"),
 794		},
 795	},
 796	{
 797	 .callback = video_detect_force_native,
 798	 /* Samsung N250P */
 799	 .matches = {
 800		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
 801		DMI_MATCH(DMI_PRODUCT_NAME, "N250P"),
 802		DMI_MATCH(DMI_BOARD_NAME, "N250P"),
 803		},
 804	},
 805	{
 806	 /* https://bugzilla.kernel.org/show_bug.cgi?id=202401 */
 807	 .callback = video_detect_force_native,
 808	 /* Sony Vaio VPCEH3U1E */
 809	 .matches = {
 810		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
 811		DMI_MATCH(DMI_PRODUCT_NAME, "VPCEH3U1E"),
 812		},
 813	},
 814	{
 815	 .callback = video_detect_force_native,
 816	 /* Sony Vaio VPCY11S1E */
 817	 .matches = {
 818		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
 819		DMI_MATCH(DMI_PRODUCT_NAME, "VPCY11S1E"),
 820		},
 821	},
 822
 823	/*
 824	 * These Toshibas have a broken acpi-video interface for brightness
 825	 * control. They also have an issue where the panel is off after
 826	 * suspend until a special firmware call is made to turn it back
 827	 * on. This is handled by the toshiba_acpi kernel module, so that
 828	 * module must be enabled for these models to work correctly.
 829	 */
 830	{
 831	 /* https://bugzilla.kernel.org/show_bug.cgi?id=21012 */
 832	 .callback = video_detect_force_native,
 833	 /* Toshiba Portégé R700 */
 834	 .matches = {
 835		DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
 836		DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE R700"),
 837		},
 838	},
 839	{
 840	 /* Portégé: https://bugs.freedesktop.org/show_bug.cgi?id=82634 */
 841	 /* Satellite: https://bugzilla.kernel.org/show_bug.cgi?id=21012 */
 842	 .callback = video_detect_force_native,
 843	 /* Toshiba Satellite/Portégé R830 */
 844	 .matches = {
 845		DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
 846		DMI_MATCH(DMI_PRODUCT_NAME, "R830"),
 847		},
 848	},
 849	{
 850	 .callback = video_detect_force_native,
 851	 /* Toshiba Satellite/Portégé Z830 */
 852	 .matches = {
 853		DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
 854		DMI_MATCH(DMI_PRODUCT_NAME, "Z830"),
 855		},
 856	},
 857
 858	/*
 859	 * Dell AIO (All in Ones) which advertise an UART attached backlight
 860	 * controller board in their ACPI tables (and may even have one), but
 861	 * which need native backlight control nevertheless.
 862	 */
 863	{
 864	 /* https://github.com/zabbly/linux/issues/26 */
 865	 .callback = video_detect_force_native,
 866	 /* Dell OptiPlex 5480 AIO */
 867	 .matches = {
 868		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
 869		DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 5480 AIO"),
 870		},
 871	},
 872	{
 873	 /* https://bugzilla.redhat.com/show_bug.cgi?id=2303936 */
 874	 .callback = video_detect_force_native,
 875	 /* Dell OptiPlex 7760 AIO */
 876	 .matches = {
 877		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
 878		DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 7760 AIO"),
 879		},
 880	},
 881
 882	/*
 883	 * Models which have nvidia-ec-wmi support, but should not use it.
 884	 * Note this indicates a likely firmware bug on these models and should
 885	 * be revisited if/when Linux gets support for dynamic mux mode.
 886	 */
 887	{
 888	 .callback = video_detect_force_native,
 889	 /* Dell G15 5515 */
 890	 .matches = {
 891		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
 892		DMI_MATCH(DMI_PRODUCT_NAME, "Dell G15 5515"),
 893		},
 894	},
 895	{
 896	 .callback = video_detect_force_native,
 897	 .matches = {
 898		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
 899		DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 15 3535"),
 900		},
 901	},
 902
 903	/*
 904	 * x86 android tablets which directly control the backlight through
 905	 * an external backlight controller, typically TI's LP8557.
 906	 * The backlight is directly controlled by the lp855x driver on these.
 907	 * This setup means that neither i915's native nor acpi_video backlight
 908	 * control works. Add a "vendor" quirk to disable both. Note these
 909	 * devices do not use vendor control in the typical meaning of
 910	 * vendor specific SMBIOS or ACPI calls being used.
 911	 */
 912	{
 913	 .callback = video_detect_force_vendor,
 914	 /* Lenovo Yoga Book X90F / X90L */
 915	 .matches = {
 916		DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
 917		DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "CHERRYVIEW D1 PLATFORM"),
 918		DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "YETI-11"),
 919		},
 920	},
 921	{
 922	 .callback = video_detect_force_vendor,
 923	 /*
 924	  * Lenovo Yoga Tablet 2 830F/L or 1050F/L (The 8" and 10"
 925	  * Lenovo Yoga Tablet 2 use the same mainboard)
 926	  */
 927	 .matches = {
 928		DMI_MATCH(DMI_SYS_VENDOR, "Intel Corp."),
 929		DMI_MATCH(DMI_PRODUCT_NAME, "VALLEYVIEW C0 PLATFORM"),
 930		DMI_MATCH(DMI_BOARD_NAME, "BYT-T FFD8"),
 931		/* Partial match on beginning of BIOS version */
 932		DMI_MATCH(DMI_BIOS_VERSION, "BLADE_21"),
 933		},
 934	},
 935	{
 936	 .callback = video_detect_force_vendor,
 937	 /* Lenovo Yoga Tab 3 Pro YT3-X90F */
 938	 .matches = {
 939		DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
 
 940		DMI_MATCH(DMI_PRODUCT_VERSION, "Blade3-10A-001"),
 941		},
 942	},
 943	{
 944	 .callback = video_detect_force_vendor,
 945	 /* Xiaomi Mi Pad 2 */
 946	 .matches = {
 947		DMI_MATCH(DMI_SYS_VENDOR, "Xiaomi Inc"),
 948		DMI_MATCH(DMI_PRODUCT_NAME, "Mipad2"),
 949		},
 950	},
 951	{ },
 952};
 953
 954static bool google_cros_ec_present(void)
 955{
 956	return acpi_dev_found("GOOG0004") || acpi_dev_found("GOOG000C");
 957}
 958
 959/*
 960 * Windows 8 and newer no longer use the ACPI video interface, so it often
 961 * does not work. So on win8+ systems prefer native brightness control.
 962 * Chromebooks should always prefer native backlight control.
 963 */
 964static bool prefer_native_over_acpi_video(void)
 965{
 966	return acpi_osi_is_win8() || google_cros_ec_present();
 967}
 968
 969/*
 970 * Determine which type of backlight interface to use on this system,
 971 * First check cmdline, then dmi quirks, then do autodetect.
 972 */
 973enum acpi_backlight_type __acpi_video_get_backlight_type(bool native, bool *auto_detect)
 974{
 975	static DEFINE_MUTEX(init_mutex);
 976	static bool nvidia_wmi_ec_present;
 977	static bool apple_gmux_present;
 978	static bool dell_uart_present;
 979	static bool native_available;
 980	static bool init_done;
 981	static long video_caps;
 982
 983	/* Parse cmdline, dmi and acpi only once */
 984	mutex_lock(&init_mutex);
 985	if (!init_done) {
 986		acpi_video_parse_cmdline();
 987		dmi_check_system(video_detect_dmi_table);
 988		acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
 989				    ACPI_UINT32_MAX, find_video, NULL,
 990				    &video_caps, NULL);
 991		nvidia_wmi_ec_present = nvidia_wmi_ec_supported();
 992		apple_gmux_present = apple_gmux_detect(NULL, NULL);
 993		dell_uart_present = acpi_dev_present("DELL0501", NULL, -1);
 994		init_done = true;
 995	}
 996	if (native)
 997		native_available = true;
 998	mutex_unlock(&init_mutex);
 999
1000	if (auto_detect)
1001		*auto_detect = false;
1002
1003	/*
1004	 * The below heuristics / detection steps are in order of descending
1005	 * presedence. The commandline takes presedence over anything else.
1006	 */
1007	if (acpi_backlight_cmdline != acpi_backlight_undef)
1008		return acpi_backlight_cmdline;
1009
1010	/* DMI quirks override any autodetection. */
1011	if (acpi_backlight_dmi != acpi_backlight_undef)
1012		return acpi_backlight_dmi;
1013
1014	if (auto_detect)
1015		*auto_detect = true;
1016
1017	/* Special cases such as nvidia_wmi_ec and apple gmux. */
1018	if (nvidia_wmi_ec_present)
1019		return acpi_backlight_nvidia_wmi_ec;
1020
1021	if (apple_gmux_present)
1022		return acpi_backlight_apple_gmux;
1023
1024	if (dell_uart_present)
1025		return acpi_backlight_dell_uart;
1026
1027	/* Use ACPI video if available, except when native should be preferred. */
1028	if ((video_caps & ACPI_VIDEO_BACKLIGHT) &&
1029	     !(native_available && prefer_native_over_acpi_video()))
1030		return acpi_backlight_video;
1031
1032	/* Use native if available */
1033	if (native_available)
1034		return acpi_backlight_native;
1035
1036	/*
1037	 * The vendor specific BIOS interfaces are only necessary for
1038	 * laptops from before ~2008.
1039	 *
1040	 * For laptops from ~2008 till ~2023 this point is never reached
1041	 * because on those (video_caps & ACPI_VIDEO_BACKLIGHT) above is true.
1042	 *
1043	 * Laptops from after ~2023 no longer support ACPI_VIDEO_BACKLIGHT,
1044	 * if this point is reached on those, this likely means that
1045	 * the GPU kms driver which sets native_available has not loaded yet.
1046	 *
1047	 * Returning acpi_backlight_vendor in this case is known to sometimes
1048	 * cause a non working vendor specific /sys/class/backlight device to
1049	 * get registered.
1050	 *
1051	 * Return acpi_backlight_none on laptops with ACPI tables written
1052	 * for Windows 8 (laptops from after ~2012) to avoid this problem.
1053	 */
1054	if (acpi_osi_is_win8())
1055		return acpi_backlight_none;
1056
1057	/* No ACPI video/native (old hw), use vendor specific fw methods. */
1058	return acpi_backlight_vendor;
1059}
1060EXPORT_SYMBOL(__acpi_video_get_backlight_type);
v6.9.4
  1/*
  2 *  Copyright (C) 2015       Red Hat Inc.
  3 *                           Hans de Goede <hdegoede@redhat.com>
  4 *  Copyright (C) 2008       SuSE Linux Products GmbH
  5 *                           Thomas Renninger <trenn@suse.de>
  6 *
  7 *  May be copied or modified under the terms of the GNU General Public License
  8 *
  9 * video_detect.c:
 10 * After PCI devices are glued with ACPI devices
 11 * acpi_get_pci_dev() can be called to identify ACPI graphics
 12 * devices for which a real graphics card is plugged in
 13 *
 14 * Depending on whether ACPI graphics extensions (cmp. ACPI spec Appendix B)
 15 * are available, video.ko should be used to handle the device.
 16 *
 17 * Otherwise vendor specific drivers like thinkpad_acpi, asus-laptop,
 18 * sony_acpi,... can take care about backlight brightness.
 19 *
 20 * Backlight drivers can use acpi_video_get_backlight_type() to determine which
 21 * driver should handle the backlight. RAW/GPU-driver backlight drivers must
 22 * use the acpi_video_backlight_use_native() helper for this.
 23 *
 24 * If CONFIG_ACPI_VIDEO is neither set as "compiled in" (y) nor as a module (m)
 25 * this file will not be compiled and acpi_video_get_backlight_type() will
 26 * always return acpi_backlight_vendor.
 27 */
 28
 29#include <linux/export.h>
 30#include <linux/acpi.h>
 31#include <linux/apple-gmux.h>
 32#include <linux/backlight.h>
 33#include <linux/dmi.h>
 34#include <linux/module.h>
 35#include <linux/pci.h>
 36#include <linux/platform_data/x86/nvidia-wmi-ec-backlight.h>
 37#include <linux/pnp.h>
 38#include <linux/types.h>
 39#include <linux/workqueue.h>
 40#include <acpi/video.h>
 41
 42static enum acpi_backlight_type acpi_backlight_cmdline = acpi_backlight_undef;
 43static enum acpi_backlight_type acpi_backlight_dmi = acpi_backlight_undef;
 44
 45static void acpi_video_parse_cmdline(void)
 46{
 47	if (!strcmp("vendor", acpi_video_backlight_string))
 48		acpi_backlight_cmdline = acpi_backlight_vendor;
 49	if (!strcmp("video", acpi_video_backlight_string))
 50		acpi_backlight_cmdline = acpi_backlight_video;
 51	if (!strcmp("native", acpi_video_backlight_string))
 52		acpi_backlight_cmdline = acpi_backlight_native;
 53	if (!strcmp("nvidia_wmi_ec", acpi_video_backlight_string))
 54		acpi_backlight_cmdline = acpi_backlight_nvidia_wmi_ec;
 55	if (!strcmp("apple_gmux", acpi_video_backlight_string))
 56		acpi_backlight_cmdline = acpi_backlight_apple_gmux;
 
 
 57	if (!strcmp("none", acpi_video_backlight_string))
 58		acpi_backlight_cmdline = acpi_backlight_none;
 59}
 60
 61static acpi_status
 62find_video(acpi_handle handle, u32 lvl, void *context, void **rv)
 63{
 64	struct acpi_device *acpi_dev = acpi_fetch_acpi_dev(handle);
 65	long *cap = context;
 66	struct pci_dev *dev;
 67
 68	static const struct acpi_device_id video_ids[] = {
 69		{ACPI_VIDEO_HID, 0},
 70		{"", 0},
 71	};
 72
 73	if (acpi_dev && !acpi_match_device_ids(acpi_dev, video_ids)) {
 74		dev = acpi_get_pci_dev(handle);
 75		if (!dev)
 76			return AE_OK;
 77		pci_dev_put(dev);
 78		*cap |= acpi_is_video_device(handle);
 79	}
 80	return AE_OK;
 81}
 82
 83/* This depends on ACPI_WMI which is X86 only */
 84#ifdef CONFIG_X86
 85static bool nvidia_wmi_ec_supported(void)
 86{
 87	struct wmi_brightness_args args = {
 88		.mode = WMI_BRIGHTNESS_MODE_GET,
 89		.val = 0,
 90		.ret = 0,
 91	};
 92	struct acpi_buffer buf = { (acpi_size)sizeof(args), &args };
 93	acpi_status status;
 94
 95	status = wmi_evaluate_method(WMI_BRIGHTNESS_GUID, 0,
 96				     WMI_BRIGHTNESS_METHOD_SOURCE, &buf, &buf);
 97	if (ACPI_FAILURE(status))
 98		return false;
 99
100	/*
101	 * If brightness is handled by the EC then nvidia-wmi-ec-backlight
102	 * should be used, else the GPU driver(s) should be used.
103	 */
104	return args.ret == WMI_BRIGHTNESS_SOURCE_EC;
105}
106#else
107static bool nvidia_wmi_ec_supported(void)
108{
109	return false;
110}
111#endif
112
113/* Force to use vendor driver when the ACPI device is known to be
114 * buggy */
115static int video_detect_force_vendor(const struct dmi_system_id *d)
116{
117	acpi_backlight_dmi = acpi_backlight_vendor;
118	return 0;
119}
120
121static int video_detect_force_video(const struct dmi_system_id *d)
122{
123	acpi_backlight_dmi = acpi_backlight_video;
124	return 0;
125}
126
127static int video_detect_force_native(const struct dmi_system_id *d)
128{
129	acpi_backlight_dmi = acpi_backlight_native;
130	return 0;
131}
132
133static int video_detect_portege_r100(const struct dmi_system_id *d)
134{
135	struct pci_dev *dev;
136	/* Search for Trident CyberBlade XP4m32 to confirm Portégé R100 */
137	dev = pci_get_device(PCI_VENDOR_ID_TRIDENT, 0x2100, NULL);
138	if (dev)
139		acpi_backlight_dmi = acpi_backlight_vendor;
140	return 0;
141}
142
143static const struct dmi_system_id video_detect_dmi_table[] = {
144	/*
145	 * Models which should use the vendor backlight interface,
146	 * because of broken ACPI video backlight control.
147	 */
148	{
149	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1128309 */
150	 .callback = video_detect_force_vendor,
151	 /* Acer KAV80 */
152	 .matches = {
153		DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
154		DMI_MATCH(DMI_PRODUCT_NAME, "KAV80"),
155		},
156	},
157	{
158	 .callback = video_detect_force_vendor,
159	 /* Asus UL30VT */
160	 .matches = {
161		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
162		DMI_MATCH(DMI_PRODUCT_NAME, "UL30VT"),
163		},
164	},
165	{
166	 .callback = video_detect_force_vendor,
167	 /* Asus UL30A */
168	 .matches = {
169		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
170		DMI_MATCH(DMI_PRODUCT_NAME, "UL30A"),
171		},
172	},
173	{
174	 .callback = video_detect_force_vendor,
175	 /* Asus X55U */
176	 .matches = {
177		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
178		DMI_MATCH(DMI_PRODUCT_NAME, "X55U"),
179		},
180	},
181	{
182	 /* https://bugs.launchpad.net/bugs/1000146 */
183	 .callback = video_detect_force_vendor,
184	 /* Asus X101CH */
185	 .matches = {
186		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
187		DMI_MATCH(DMI_PRODUCT_NAME, "X101CH"),
188		},
189	},
190	{
191	 .callback = video_detect_force_vendor,
192	 /* Asus X401U */
193	 .matches = {
194		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
195		DMI_MATCH(DMI_PRODUCT_NAME, "X401U"),
196		},
197	},
198	{
199	 .callback = video_detect_force_vendor,
200	 /* Asus X501U */
201	 .matches = {
202		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
203		DMI_MATCH(DMI_PRODUCT_NAME, "X501U"),
204		},
205	},
206	{
207	 /* https://bugs.launchpad.net/bugs/1000146 */
208	 .callback = video_detect_force_vendor,
209	 /* Asus 1015CX */
210	 .matches = {
211		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
212		DMI_MATCH(DMI_PRODUCT_NAME, "1015CX"),
213		},
214	},
215	{
216	 .callback = video_detect_force_vendor,
217	 /* Samsung N150/N210/N220 */
218	 .matches = {
219		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
220		DMI_MATCH(DMI_PRODUCT_NAME, "N150/N210/N220"),
221		DMI_MATCH(DMI_BOARD_NAME, "N150/N210/N220"),
222		},
223	},
224	{
225	 .callback = video_detect_force_vendor,
226	 /* Samsung NF110/NF210/NF310 */
227	 .matches = {
228		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
229		DMI_MATCH(DMI_PRODUCT_NAME, "NF110/NF210/NF310"),
230		DMI_MATCH(DMI_BOARD_NAME, "NF110/NF210/NF310"),
231		},
232	},
233	{
234	 .callback = video_detect_force_vendor,
235	 /* Samsung NC210 */
236	 .matches = {
237		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
238		DMI_MATCH(DMI_PRODUCT_NAME, "NC210/NC110"),
239		DMI_MATCH(DMI_BOARD_NAME, "NC210/NC110"),
240		},
241	},
242
243	/*
244	 * Models which should use the vendor backlight interface,
245	 * because of broken native backlight control.
246	 */
247	{
248	 .callback = video_detect_force_vendor,
249	 /* Sony Vaio PCG-FRV35 */
250	 .matches = {
251		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
252		DMI_MATCH(DMI_PRODUCT_NAME, "PCG-FRV35"),
253		},
254	},
 
 
 
 
 
 
 
 
255
256	/*
257	 * Toshiba models with Transflective display, these need to use
258	 * the toshiba_acpi vendor driver for proper Transflective handling.
259	 */
260	{
261	 .callback = video_detect_force_vendor,
262	 .matches = {
263		DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
264		DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE R500"),
265		},
266	},
267	{
268	 .callback = video_detect_force_vendor,
269	 .matches = {
270		DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
271		DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE R600"),
272		},
273	},
274
275	/*
276	 * Toshiba Portégé R100 has working both acpi_video and toshiba_acpi
277	 * vendor driver. But none of them gets activated as it has a VGA with
278	 * no kernel driver (Trident CyberBlade XP4m32).
279	 * The DMI strings are generic so check for the VGA chip in callback.
280	 */
281	{
282	 .callback = video_detect_portege_r100,
283	 .matches = {
284		DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
285		DMI_MATCH(DMI_PRODUCT_NAME, "Portable PC"),
286		DMI_MATCH(DMI_PRODUCT_VERSION, "Version 1.0"),
287		DMI_MATCH(DMI_BOARD_NAME, "Portable PC")
288		},
289	},
290
291	/*
292	 * Models which need acpi_video backlight control where the GPU drivers
293	 * do not call acpi_video_register_backlight() because no internal panel
294	 * is detected. Typically these are all-in-ones (monitors with builtin
295	 * PC) where the panel connection shows up as regular DP instead of eDP.
296	 */
297	{
298	 .callback = video_detect_force_video,
299	 /* Apple iMac14,1 */
300	 .matches = {
301		DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
302		DMI_MATCH(DMI_PRODUCT_NAME, "iMac14,1"),
303		},
304	},
305	{
306	 .callback = video_detect_force_video,
307	 /* Apple iMac14,2 */
308	 .matches = {
309		DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
310		DMI_MATCH(DMI_PRODUCT_NAME, "iMac14,2"),
311		},
312	},
313
314	/*
315	 * These models have a working acpi_video backlight control, and using
316	 * native backlight causes a regression where backlight does not work
317	 * when userspace is not handling brightness key events. Disable
318	 * native_backlight on these to fix this:
319	 * https://bugzilla.kernel.org/show_bug.cgi?id=81691
320	 */
321	{
322	 .callback = video_detect_force_video,
323	 /* ThinkPad T420 */
324	 .matches = {
325		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
326		DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T420"),
327		},
328	},
329	{
330	 .callback = video_detect_force_video,
331	 /* ThinkPad T520 */
332	 .matches = {
333		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
334		DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T520"),
335		},
336	},
337	{
338	 .callback = video_detect_force_video,
339	 /* ThinkPad X201s */
340	 .matches = {
341		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
342		DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X201s"),
343		},
344	},
345	{
346	 .callback = video_detect_force_video,
347	 /* ThinkPad X201T */
348	 .matches = {
349		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
350		DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X201T"),
351		},
352	},
353
354	/* The native backlight controls do not work on some older machines */
355	{
356	 /* https://bugs.freedesktop.org/show_bug.cgi?id=81515 */
357	 .callback = video_detect_force_video,
358	 /* HP ENVY 15 Notebook */
359	 .matches = {
360		DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
361		DMI_MATCH(DMI_PRODUCT_NAME, "HP ENVY 15 Notebook PC"),
362		},
363	},
364	{
365	 .callback = video_detect_force_video,
366	 /* SAMSUNG 870Z5E/880Z5E/680Z5E */
367	 .matches = {
368		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
369		DMI_MATCH(DMI_PRODUCT_NAME, "870Z5E/880Z5E/680Z5E"),
370		},
371	},
372	{
373	 .callback = video_detect_force_video,
374	 /* SAMSUNG 370R4E/370R4V/370R5E/3570RE/370R5V */
375	 .matches = {
376		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
377		DMI_MATCH(DMI_PRODUCT_NAME,
378			  "370R4E/370R4V/370R5E/3570RE/370R5V"),
379		},
380	},
381	{
382	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1186097 */
383	 .callback = video_detect_force_video,
384	 /* SAMSUNG 3570R/370R/470R/450R/510R/4450RV */
385	 .matches = {
386		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
387		DMI_MATCH(DMI_PRODUCT_NAME,
388			  "3570R/370R/470R/450R/510R/4450RV"),
389		},
390	},
391	{
392	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1557060 */
393	 .callback = video_detect_force_video,
394	 /* SAMSUNG 670Z5E */
395	 .matches = {
396		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
397		DMI_MATCH(DMI_PRODUCT_NAME, "670Z5E"),
398		},
399	},
400	{
401	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1094948 */
402	 .callback = video_detect_force_video,
403	 /* SAMSUNG 730U3E/740U3E */
404	 .matches = {
405		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
406		DMI_MATCH(DMI_PRODUCT_NAME, "730U3E/740U3E"),
407		},
408	},
409	{
410	 /* https://bugs.freedesktop.org/show_bug.cgi?id=87286 */
411	 .callback = video_detect_force_video,
412	 /* SAMSUNG 900X3C/900X3D/900X3E/900X4C/900X4D */
413	 .matches = {
414		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
415		DMI_MATCH(DMI_PRODUCT_NAME,
416			  "900X3C/900X3D/900X3E/900X4C/900X4D"),
417		},
418	},
419	{
420	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1272633 */
421	 .callback = video_detect_force_video,
422	 /* Dell XPS14 L421X */
423	 .matches = {
424		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
425		DMI_MATCH(DMI_PRODUCT_NAME, "XPS L421X"),
426		},
427	},
428	{
429	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1163574 */
430	 .callback = video_detect_force_video,
431	 /* Dell XPS15 L521X */
432	 .matches = {
433		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
434		DMI_MATCH(DMI_PRODUCT_NAME, "XPS L521X"),
435		},
436	},
437	{
438	 /* https://bugzilla.kernel.org/show_bug.cgi?id=108971 */
439	 .callback = video_detect_force_video,
440	 /* SAMSUNG 530U4E/540U4E */
441	 .matches = {
442		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
443		DMI_MATCH(DMI_PRODUCT_NAME, "530U4E/540U4E"),
444		},
445	},
446	{
447	 /* https://bugs.launchpad.net/bugs/1894667 */
448	 .callback = video_detect_force_video,
449	 /* HP 635 Notebook */
450	 .matches = {
451		DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
452		DMI_MATCH(DMI_PRODUCT_NAME, "HP 635 Notebook PC"),
453		},
454	},
455
456	/* Non win8 machines which need native backlight nevertheless */
457	{
458	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1201530 */
459	 .callback = video_detect_force_native,
460	 /* Lenovo Ideapad S405 */
461	 .matches = {
462		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
463		DMI_MATCH(DMI_BOARD_NAME, "Lenovo IdeaPad S405"),
464		},
465	},
466	{
467	 /* https://bugzilla.suse.com/show_bug.cgi?id=1208724 */
468	 .callback = video_detect_force_native,
469	 /* Lenovo Ideapad Z470 */
470	 .matches = {
471		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
472		DMI_MATCH(DMI_PRODUCT_VERSION, "IdeaPad Z470"),
473		},
474	},
475	{
476	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1187004 */
477	 .callback = video_detect_force_native,
478	 /* Lenovo Ideapad Z570 */
479	 .matches = {
480		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
481		DMI_MATCH(DMI_PRODUCT_VERSION, "Ideapad Z570"),
482		},
483	},
484	{
485	 .callback = video_detect_force_native,
486	 /* Lenovo E41-25 */
487	 .matches = {
488		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
489		DMI_MATCH(DMI_PRODUCT_NAME, "81FS"),
490		},
491	},
492	{
493	 .callback = video_detect_force_native,
494	 /* Lenovo E41-45 */
495	 .matches = {
496		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
497		DMI_MATCH(DMI_PRODUCT_NAME, "82BK"),
498		},
499	},
500	{
501	 .callback = video_detect_force_native,
 
 
 
 
 
 
 
 
502	 /* Lenovo ThinkPad X131e (3371 AMD version) */
503	 .matches = {
504		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
505		DMI_MATCH(DMI_PRODUCT_NAME, "3371"),
506		},
507	},
508	{
509	 .callback = video_detect_force_native,
510	 /* Apple iMac11,3 */
511	 .matches = {
512		DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
513		DMI_MATCH(DMI_PRODUCT_NAME, "iMac11,3"),
514		},
515	},
516	{
517	 /* https://gitlab.freedesktop.org/drm/amd/-/issues/1838 */
518	 .callback = video_detect_force_native,
519	 /* Apple iMac12,1 */
520	 .matches = {
521		DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
522		DMI_MATCH(DMI_PRODUCT_NAME, "iMac12,1"),
523		},
524	},
525	{
526	 /* https://gitlab.freedesktop.org/drm/amd/-/issues/2753 */
527	 .callback = video_detect_force_native,
528	 /* Apple iMac12,2 */
529	 .matches = {
530		DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
531		DMI_MATCH(DMI_PRODUCT_NAME, "iMac12,2"),
532		},
533	},
534	{
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
535	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1217249 */
536	 .callback = video_detect_force_native,
537	 /* Apple MacBook Pro 12,1 */
538	 .matches = {
539		DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
540		DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro12,1"),
541		},
542	},
543	{
544	 .callback = video_detect_force_native,
 
 
 
 
 
 
 
 
545	 /* Dell Inspiron N4010 */
546	 .matches = {
547		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
548		DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron N4010"),
549		},
550	},
551	{
552	 .callback = video_detect_force_native,
553	 /* Dell Vostro V131 */
554	 .matches = {
555		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
556		DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V131"),
557		},
558	},
559	{
560	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1123661 */
561	 .callback = video_detect_force_native,
562	 /* Dell XPS 17 L702X */
563	 .matches = {
564		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
565		DMI_MATCH(DMI_PRODUCT_NAME, "Dell System XPS L702X"),
566		},
567	},
568	{
569	 .callback = video_detect_force_native,
570	 /* Dell Precision 7510 */
571	 .matches = {
572		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
573		DMI_MATCH(DMI_PRODUCT_NAME, "Precision 7510"),
574		},
575	},
576	{
577	 .callback = video_detect_force_native,
578	 /* Dell Studio 1569 */
579	 .matches = {
580		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
581		DMI_MATCH(DMI_PRODUCT_NAME, "Studio 1569"),
582		},
583	},
584	{
585	 .callback = video_detect_force_native,
586	 /* Acer Aspire 3830TG */
587	 .matches = {
588		DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
589		DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3830TG"),
590		},
591	},
592	{
593	 .callback = video_detect_force_native,
594	 /* Acer Aspire 4810T */
595	 .matches = {
596		DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
597		DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 4810T"),
598		},
599	},
600	{
601	 .callback = video_detect_force_native,
602	 /* Acer Aspire 5738z */
603	 .matches = {
604		DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
605		DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5738"),
606		DMI_MATCH(DMI_BOARD_NAME, "JV50"),
607		},
608	},
609	{
610	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1012674 */
611	 .callback = video_detect_force_native,
612	 /* Acer Aspire 5741 */
613	 .matches = {
614		DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
615		DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5741"),
616		},
617	},
618	{
619	 /* https://bugzilla.kernel.org/show_bug.cgi?id=42993 */
620	 .callback = video_detect_force_native,
621	 /* Acer Aspire 5750 */
622	 .matches = {
623		DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
624		DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5750"),
625		},
626	},
627	{
628	 /* https://bugzilla.kernel.org/show_bug.cgi?id=42833 */
629	 .callback = video_detect_force_native,
630	 /* Acer Extensa 5235 */
631	 .matches = {
632		DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
633		DMI_MATCH(DMI_PRODUCT_NAME, "Extensa 5235"),
634		},
635	},
636	{
637	 .callback = video_detect_force_native,
638	 /* Acer TravelMate 4750 */
639	 .matches = {
640		DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
641		DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4750"),
642		},
643	},
644	{
645	 /* https://bugzilla.kernel.org/show_bug.cgi?id=207835 */
646	 .callback = video_detect_force_native,
647	 /* Acer TravelMate 5735Z */
648	 .matches = {
649		DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
650		DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 5735Z"),
651		DMI_MATCH(DMI_BOARD_NAME, "BA51_MV"),
652		},
653	},
654	{
655	 /* https://bugzilla.kernel.org/show_bug.cgi?id=36322 */
656	 .callback = video_detect_force_native,
657	 /* Acer TravelMate 5760 */
658	 .matches = {
659		DMI_MATCH(DMI_BOARD_VENDOR, "Acer"),
660		DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 5760"),
661		},
662	},
663	{
664	 .callback = video_detect_force_native,
665	 /* ASUSTeK COMPUTER INC. GA401 */
666	 .matches = {
667		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
668		DMI_MATCH(DMI_PRODUCT_NAME, "GA401"),
669		},
670	},
671	{
672	 .callback = video_detect_force_native,
673	 /* ASUSTeK COMPUTER INC. GA502 */
674	 .matches = {
675		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
676		DMI_MATCH(DMI_PRODUCT_NAME, "GA502"),
677		},
678	},
679	{
680	 .callback = video_detect_force_native,
681	 /* ASUSTeK COMPUTER INC. GA503 */
682	 .matches = {
683		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
684		DMI_MATCH(DMI_PRODUCT_NAME, "GA503"),
685		},
686	},
687	{
688	 .callback = video_detect_force_native,
689	 /* Asus U46E */
690	 .matches = {
691		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
692		DMI_MATCH(DMI_PRODUCT_NAME, "U46E"),
693		},
694	},
695	{
696	 .callback = video_detect_force_native,
697	 /* Asus UX303UB */
698	 .matches = {
699		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
700		DMI_MATCH(DMI_PRODUCT_NAME, "UX303UB"),
701		},
702	},
703	{
704	 .callback = video_detect_force_native,
705	 /* HP EliteBook 8460p */
706	 .matches = {
707		DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
708		DMI_MATCH(DMI_PRODUCT_NAME, "HP EliteBook 8460p"),
709		},
710	},
711	{
712	 .callback = video_detect_force_native,
713	 /* HP Pavilion g6-1d80nr / B4U19UA */
714	 .matches = {
715		DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
716		DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion g6 Notebook PC"),
717		DMI_MATCH(DMI_PRODUCT_SKU, "B4U19UA"),
718		},
719	},
720	{
721	 .callback = video_detect_force_native,
722	 /* Samsung N150P */
723	 .matches = {
724		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
725		DMI_MATCH(DMI_PRODUCT_NAME, "N150P"),
726		DMI_MATCH(DMI_BOARD_NAME, "N150P"),
727		},
728	},
729	{
730	 .callback = video_detect_force_native,
731	 /* Samsung N145P/N250P/N260P */
732	 .matches = {
733		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
734		DMI_MATCH(DMI_PRODUCT_NAME, "N145P/N250P/N260P"),
735		DMI_MATCH(DMI_BOARD_NAME, "N145P/N250P/N260P"),
736		},
737	},
738	{
739	 .callback = video_detect_force_native,
740	 /* Samsung N250P */
741	 .matches = {
742		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
743		DMI_MATCH(DMI_PRODUCT_NAME, "N250P"),
744		DMI_MATCH(DMI_BOARD_NAME, "N250P"),
745		},
746	},
747	{
748	 /* https://bugzilla.kernel.org/show_bug.cgi?id=202401 */
749	 .callback = video_detect_force_native,
750	 /* Sony Vaio VPCEH3U1E */
751	 .matches = {
752		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
753		DMI_MATCH(DMI_PRODUCT_NAME, "VPCEH3U1E"),
754		},
755	},
756	{
757	 .callback = video_detect_force_native,
758	 /* Sony Vaio VPCY11S1E */
759	 .matches = {
760		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
761		DMI_MATCH(DMI_PRODUCT_NAME, "VPCY11S1E"),
762		},
763	},
764
765	/*
766	 * These Toshibas have a broken acpi-video interface for brightness
767	 * control. They also have an issue where the panel is off after
768	 * suspend until a special firmware call is made to turn it back
769	 * on. This is handled by the toshiba_acpi kernel module, so that
770	 * module must be enabled for these models to work correctly.
771	 */
772	{
773	 /* https://bugzilla.kernel.org/show_bug.cgi?id=21012 */
774	 .callback = video_detect_force_native,
775	 /* Toshiba Portégé R700 */
776	 .matches = {
777		DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
778		DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE R700"),
779		},
780	},
781	{
782	 /* Portégé: https://bugs.freedesktop.org/show_bug.cgi?id=82634 */
783	 /* Satellite: https://bugzilla.kernel.org/show_bug.cgi?id=21012 */
784	 .callback = video_detect_force_native,
785	 /* Toshiba Satellite/Portégé R830 */
786	 .matches = {
787		DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
788		DMI_MATCH(DMI_PRODUCT_NAME, "R830"),
789		},
790	},
791	{
792	 .callback = video_detect_force_native,
793	 /* Toshiba Satellite/Portégé Z830 */
794	 .matches = {
795		DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
796		DMI_MATCH(DMI_PRODUCT_NAME, "Z830"),
797		},
798	},
799
800	/*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
801	 * Models which have nvidia-ec-wmi support, but should not use it.
802	 * Note this indicates a likely firmware bug on these models and should
803	 * be revisited if/when Linux gets support for dynamic mux mode.
804	 */
805	{
806	 .callback = video_detect_force_native,
807	 /* Dell G15 5515 */
808	 .matches = {
809		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
810		DMI_MATCH(DMI_PRODUCT_NAME, "Dell G15 5515"),
811		},
812	},
813	{
814	 .callback = video_detect_force_native,
815	 .matches = {
816		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
817		DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 15 3535"),
818		},
819	},
820
821	/*
822	 * x86 android tablets which directly control the backlight through
823	 * an external backlight controller, typically TI's LP8557.
824	 * The backlight is directly controlled by the lp855x driver on these.
825	 * This setup means that neither i915's native nor acpi_video backlight
826	 * control works. Add a "vendor" quirk to disable both. Note these
827	 * devices do not use vendor control in the typical meaning of
828	 * vendor specific SMBIOS or ACPI calls being used.
829	 */
830	{
831	 .callback = video_detect_force_vendor,
832	 /* Lenovo Yoga Book X90F / X90L */
833	 .matches = {
834		DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
835		DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "CHERRYVIEW D1 PLATFORM"),
836		DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "YETI-11"),
837		},
838	},
839	{
840	 .callback = video_detect_force_vendor,
841	 /*
842	  * Lenovo Yoga Tablet 2 830F/L or 1050F/L (The 8" and 10"
843	  * Lenovo Yoga Tablet 2 use the same mainboard)
844	  */
845	 .matches = {
846		DMI_MATCH(DMI_SYS_VENDOR, "Intel Corp."),
847		DMI_MATCH(DMI_PRODUCT_NAME, "VALLEYVIEW C0 PLATFORM"),
848		DMI_MATCH(DMI_BOARD_NAME, "BYT-T FFD8"),
849		/* Partial match on beginning of BIOS version */
850		DMI_MATCH(DMI_BIOS_VERSION, "BLADE_21"),
851		},
852	},
853	{
854	 .callback = video_detect_force_vendor,
855	 /* Lenovo Yoga Tab 3 Pro YT3-X90F */
856	 .matches = {
857		DMI_MATCH(DMI_SYS_VENDOR, "Intel Corporation"),
858		DMI_MATCH(DMI_PRODUCT_NAME, "CHERRYVIEW D1 PLATFORM"),
859		DMI_MATCH(DMI_PRODUCT_VERSION, "Blade3-10A-001"),
860		},
861	},
862	{
863	 .callback = video_detect_force_vendor,
864	 /* Xiaomi Mi Pad 2 */
865	 .matches = {
866		DMI_MATCH(DMI_SYS_VENDOR, "Xiaomi Inc"),
867		DMI_MATCH(DMI_PRODUCT_NAME, "Mipad2"),
868		},
869	},
870	{ },
871};
872
873static bool google_cros_ec_present(void)
874{
875	return acpi_dev_found("GOOG0004") || acpi_dev_found("GOOG000C");
876}
877
878/*
879 * Windows 8 and newer no longer use the ACPI video interface, so it often
880 * does not work. So on win8+ systems prefer native brightness control.
881 * Chromebooks should always prefer native backlight control.
882 */
883static bool prefer_native_over_acpi_video(void)
884{
885	return acpi_osi_is_win8() || google_cros_ec_present();
886}
887
888/*
889 * Determine which type of backlight interface to use on this system,
890 * First check cmdline, then dmi quirks, then do autodetect.
891 */
892enum acpi_backlight_type __acpi_video_get_backlight_type(bool native, bool *auto_detect)
893{
894	static DEFINE_MUTEX(init_mutex);
895	static bool nvidia_wmi_ec_present;
896	static bool apple_gmux_present;
 
897	static bool native_available;
898	static bool init_done;
899	static long video_caps;
900
901	/* Parse cmdline, dmi and acpi only once */
902	mutex_lock(&init_mutex);
903	if (!init_done) {
904		acpi_video_parse_cmdline();
905		dmi_check_system(video_detect_dmi_table);
906		acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
907				    ACPI_UINT32_MAX, find_video, NULL,
908				    &video_caps, NULL);
909		nvidia_wmi_ec_present = nvidia_wmi_ec_supported();
910		apple_gmux_present = apple_gmux_detect(NULL, NULL);
 
911		init_done = true;
912	}
913	if (native)
914		native_available = true;
915	mutex_unlock(&init_mutex);
916
917	if (auto_detect)
918		*auto_detect = false;
919
920	/*
921	 * The below heuristics / detection steps are in order of descending
922	 * presedence. The commandline takes presedence over anything else.
923	 */
924	if (acpi_backlight_cmdline != acpi_backlight_undef)
925		return acpi_backlight_cmdline;
926
927	/* DMI quirks override any autodetection. */
928	if (acpi_backlight_dmi != acpi_backlight_undef)
929		return acpi_backlight_dmi;
930
931	if (auto_detect)
932		*auto_detect = true;
933
934	/* Special cases such as nvidia_wmi_ec and apple gmux. */
935	if (nvidia_wmi_ec_present)
936		return acpi_backlight_nvidia_wmi_ec;
937
938	if (apple_gmux_present)
939		return acpi_backlight_apple_gmux;
 
 
 
940
941	/* Use ACPI video if available, except when native should be preferred. */
942	if ((video_caps & ACPI_VIDEO_BACKLIGHT) &&
943	     !(native_available && prefer_native_over_acpi_video()))
944		return acpi_backlight_video;
945
946	/* Use native if available */
947	if (native_available)
948		return acpi_backlight_native;
949
950	/*
951	 * The vendor specific BIOS interfaces are only necessary for
952	 * laptops from before ~2008.
953	 *
954	 * For laptops from ~2008 till ~2023 this point is never reached
955	 * because on those (video_caps & ACPI_VIDEO_BACKLIGHT) above is true.
956	 *
957	 * Laptops from after ~2023 no longer support ACPI_VIDEO_BACKLIGHT,
958	 * if this point is reached on those, this likely means that
959	 * the GPU kms driver which sets native_available has not loaded yet.
960	 *
961	 * Returning acpi_backlight_vendor in this case is known to sometimes
962	 * cause a non working vendor specific /sys/class/backlight device to
963	 * get registered.
964	 *
965	 * Return acpi_backlight_none on laptops with ACPI tables written
966	 * for Windows 8 (laptops from after ~2012) to avoid this problem.
967	 */
968	if (acpi_osi_is_win8())
969		return acpi_backlight_none;
970
971	/* No ACPI video/native (old hw), use vendor specific fw methods. */
972	return acpi_backlight_vendor;
973}
974EXPORT_SYMBOL(__acpi_video_get_backlight_type);