Linux Audio

Check our new training course

Embedded Linux training

Mar 31-Apr 8, 2025
Register
Loading...
v5.9
  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
 21 * which driver should handle the backlight.
 
 22 *
 23 * If CONFIG_ACPI_VIDEO is neither set as "compiled in" (y) nor as a module (m)
 24 * this file will not be compiled and acpi_video_get_backlight_type() will
 25 * always return acpi_backlight_vendor.
 26 */
 27
 28#include <linux/export.h>
 29#include <linux/acpi.h>
 
 30#include <linux/backlight.h>
 31#include <linux/dmi.h>
 32#include <linux/module.h>
 33#include <linux/pci.h>
 
 
 34#include <linux/types.h>
 35#include <linux/workqueue.h>
 36#include <acpi/video.h>
 37
 38ACPI_MODULE_NAME("video");
 39#define _COMPONENT		ACPI_VIDEO_COMPONENT
 40
 41void acpi_video_unregister_backlight(void);
 42
 43static bool backlight_notifier_registered;
 44static struct notifier_block backlight_nb;
 45static struct work_struct backlight_notify_work;
 46
 47static enum acpi_backlight_type acpi_backlight_cmdline = acpi_backlight_undef;
 48static enum acpi_backlight_type acpi_backlight_dmi = acpi_backlight_undef;
 49
 50static void acpi_video_parse_cmdline(void)
 51{
 52	if (!strcmp("vendor", acpi_video_backlight_string))
 53		acpi_backlight_cmdline = acpi_backlight_vendor;
 54	if (!strcmp("video", acpi_video_backlight_string))
 55		acpi_backlight_cmdline = acpi_backlight_video;
 56	if (!strcmp("native", acpi_video_backlight_string))
 57		acpi_backlight_cmdline = acpi_backlight_native;
 
 
 
 
 
 
 58	if (!strcmp("none", acpi_video_backlight_string))
 59		acpi_backlight_cmdline = acpi_backlight_none;
 60}
 61
 62static acpi_status
 63find_video(acpi_handle handle, u32 lvl, void *context, void **rv)
 64{
 
 65	long *cap = context;
 66	struct pci_dev *dev;
 67	struct acpi_device *acpi_dev;
 68
 69	static const struct acpi_device_id video_ids[] = {
 70		{ACPI_VIDEO_HID, 0},
 71		{"", 0},
 72	};
 73	if (acpi_bus_get_device(handle, &acpi_dev))
 74		return AE_OK;
 75
 76	if (!acpi_match_device_ids(acpi_dev, video_ids)) {
 77		dev = acpi_get_pci_dev(handle);
 78		if (!dev)
 79			return AE_OK;
 80		pci_dev_put(dev);
 81		*cap |= acpi_is_video_device(handle);
 82	}
 83	return AE_OK;
 84}
 85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 86/* Force to use vendor driver when the ACPI device is known to be
 87 * buggy */
 88static int video_detect_force_vendor(const struct dmi_system_id *d)
 89{
 90	acpi_backlight_dmi = acpi_backlight_vendor;
 91	return 0;
 92}
 93
 94static int video_detect_force_video(const struct dmi_system_id *d)
 95{
 96	acpi_backlight_dmi = acpi_backlight_video;
 97	return 0;
 98}
 99
100static int video_detect_force_native(const struct dmi_system_id *d)
101{
102	acpi_backlight_dmi = acpi_backlight_native;
103	return 0;
104}
105
106static int video_detect_force_none(const struct dmi_system_id *d)
107{
108	acpi_backlight_dmi = acpi_backlight_none;
 
 
 
 
109	return 0;
110}
111
112static const struct dmi_system_id video_detect_dmi_table[] = {
113	/* On Samsung X360, the BIOS will set a flag (VDRV) if generic
114	 * ACPI backlight device is used. This flag will definitively break
115	 * the backlight interface (even the vendor interface) until next
116	 * reboot. It's why we should prevent video.ko from being used here
117	 * and we can't rely on a later call to acpi_video_unregister().
118	 */
119	{
 
120	 .callback = video_detect_force_vendor,
121	 .ident = "X360",
122	 .matches = {
123		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
124		DMI_MATCH(DMI_PRODUCT_NAME, "X360"),
125		DMI_MATCH(DMI_BOARD_NAME, "X360"),
126		},
127	},
128	{
129	.callback = video_detect_force_vendor,
130	.ident = "Asus UL30VT",
131	.matches = {
132		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
133		DMI_MATCH(DMI_PRODUCT_NAME, "UL30VT"),
134		},
135	},
136	{
137	.callback = video_detect_force_vendor,
138	.ident = "Asus UL30A",
139	.matches = {
140		DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
141		DMI_MATCH(DMI_PRODUCT_NAME, "UL30A"),
142		},
143	},
144	{
145	.callback = video_detect_force_vendor,
146	.ident = "Sony VPCEH3U1E",
147	.matches = {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148		DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
149		DMI_MATCH(DMI_PRODUCT_NAME, "VPCEH3U1E"),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150		},
151	},
152
153	/*
154	 * These models have a working acpi_video backlight control, and using
155	 * native backlight causes a regression where backlight does not work
156	 * when userspace is not handling brightness key events. Disable
157	 * native_backlight on these to fix this:
158	 * https://bugzilla.kernel.org/show_bug.cgi?id=81691
159	 */
160	{
161	 .callback = video_detect_force_video,
162	 .ident = "ThinkPad T420",
163	 .matches = {
164		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
165		DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T420"),
166		},
167	},
168	{
169	 .callback = video_detect_force_video,
170	 .ident = "ThinkPad T520",
171	 .matches = {
172		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
173		DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T520"),
174		},
175	},
176	{
177	 .callback = video_detect_force_video,
178	 .ident = "ThinkPad X201s",
179	 .matches = {
180		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
181		DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X201s"),
182		},
183	},
184        {
185         .callback = video_detect_force_video,
186         .ident = "ThinkPad X201T",
187         .matches = {
188                DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
189                DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X201T"),
190                },
191        },
192
193	/* The native backlight controls do not work on some older machines */
194	{
195	 /* https://bugs.freedesktop.org/show_bug.cgi?id=81515 */
196	 .callback = video_detect_force_video,
197	 .ident = "HP ENVY 15 Notebook",
198	 .matches = {
199		DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
200		DMI_MATCH(DMI_PRODUCT_NAME, "HP ENVY 15 Notebook PC"),
201		},
202	},
203	{
204	 .callback = video_detect_force_video,
205	 .ident = "SAMSUNG 870Z5E/880Z5E/680Z5E",
206	 .matches = {
207		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
208		DMI_MATCH(DMI_PRODUCT_NAME, "870Z5E/880Z5E/680Z5E"),
209		},
210	},
211	{
212	 .callback = video_detect_force_video,
213	 .ident = "SAMSUNG 370R4E/370R4V/370R5E/3570RE/370R5V",
214	 .matches = {
215		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
216		DMI_MATCH(DMI_PRODUCT_NAME,
217			  "370R4E/370R4V/370R5E/3570RE/370R5V"),
218		},
219	},
220	{
221	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1186097 */
222	 .callback = video_detect_force_video,
223	 .ident = "SAMSUNG 3570R/370R/470R/450R/510R/4450RV",
224	 .matches = {
225		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
226		DMI_MATCH(DMI_PRODUCT_NAME,
227			  "3570R/370R/470R/450R/510R/4450RV"),
228		},
229	},
230	{
231	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1557060 */
232	 .callback = video_detect_force_video,
233	 .ident = "SAMSUNG 670Z5E",
234	 .matches = {
235		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
236		DMI_MATCH(DMI_PRODUCT_NAME, "670Z5E"),
237		},
238	},
239	{
240	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1094948 */
241	 .callback = video_detect_force_video,
242	 .ident = "SAMSUNG 730U3E/740U3E",
243	 .matches = {
244		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
245		DMI_MATCH(DMI_PRODUCT_NAME, "730U3E/740U3E"),
246		},
247	},
248	{
249	 /* https://bugs.freedesktop.org/show_bug.cgi?id=87286 */
250	 .callback = video_detect_force_video,
251	 .ident = "SAMSUNG 900X3C/900X3D/900X3E/900X4C/900X4D",
252	 .matches = {
253		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
254		DMI_MATCH(DMI_PRODUCT_NAME,
255			  "900X3C/900X3D/900X3E/900X4C/900X4D"),
256		},
257	},
258	{
259	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1272633 */
260	 .callback = video_detect_force_video,
261	 .ident = "Dell XPS14 L421X",
262	 .matches = {
263		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
264		DMI_MATCH(DMI_PRODUCT_NAME, "XPS L421X"),
265		},
266	},
267	{
268	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1163574 */
269	 .callback = video_detect_force_video,
270	 .ident = "Dell XPS15 L521X",
271	 .matches = {
272		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
273		DMI_MATCH(DMI_PRODUCT_NAME, "XPS L521X"),
274		},
275	},
276	{
277	 /* https://bugzilla.kernel.org/show_bug.cgi?id=108971 */
278	 .callback = video_detect_force_video,
279	 .ident = "SAMSUNG 530U4E/540U4E",
280	 .matches = {
281		DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
282		DMI_MATCH(DMI_PRODUCT_NAME, "530U4E/540U4E"),
283		},
284	},
 
 
 
 
 
 
 
 
 
285
286	/* Non win8 machines which need native backlight nevertheless */
287	{
288	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1201530 */
289	 .callback = video_detect_force_native,
290	 .ident = "Lenovo Ideapad S405",
291	 .matches = {
292		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
293		DMI_MATCH(DMI_BOARD_NAME, "Lenovo IdeaPad S405"),
294		},
295	},
296	{
 
 
 
 
 
 
 
 
 
297	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1187004 */
298	 .callback = video_detect_force_native,
299	 .ident = "Lenovo Ideapad Z570",
300	 .matches = {
301		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
302		DMI_MATCH(DMI_PRODUCT_NAME, "102434U"),
303		},
304	},
305	{
306	 .callback = video_detect_force_native,
307	 .ident = "Lenovo E41-25",
308	 .matches = {
309		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
310		DMI_MATCH(DMI_PRODUCT_NAME, "81FS"),
311		},
312	},
313	{
314	 .callback = video_detect_force_native,
315	 .ident = "Lenovo E41-45",
316	 .matches = {
317		DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
318		DMI_MATCH(DMI_PRODUCT_NAME, "82BK"),
319		},
320	},
321	{
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
322	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1217249 */
323	 .callback = video_detect_force_native,
324	 .ident = "Apple MacBook Pro 12,1",
325	 .matches = {
326		DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
327		DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro12,1"),
328		},
329	},
330	{
331	 .callback = video_detect_force_native,
332	 .ident = "Dell Vostro V131",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
333	 .matches = {
334		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
335		DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V131"),
336		},
337	},
338	{
339	 /* https://bugzilla.redhat.com/show_bug.cgi?id=1123661 */
340	 .callback = video_detect_force_native,
341	 .ident = "Dell XPS 17 L702X",
342	 .matches = {
343		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
344		DMI_MATCH(DMI_PRODUCT_NAME, "Dell System XPS L702X"),
345		},
346	},
347	{
348	 .callback = video_detect_force_native,
349	 .ident = "Dell Precision 7510",
350	 .matches = {
351		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
352		DMI_MATCH(DMI_PRODUCT_NAME, "Precision 7510"),
353		},
354	},
355	{
356	 .callback = video_detect_force_native,
357	 .ident = "Acer Aspire 5738z",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
358	 .matches = {
359		DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
360		DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5738"),
361		DMI_MATCH(DMI_BOARD_NAME, "JV50"),
362		},
363	},
364	{
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
365	 /* https://bugzilla.kernel.org/show_bug.cgi?id=207835 */
366	 .callback = video_detect_force_native,
367	 .ident = "Acer TravelMate 5735Z",
368	 .matches = {
369		DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
370		DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 5735Z"),
371		DMI_MATCH(DMI_BOARD_NAME, "BA51_MV"),
372		},
373	},
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
374
375	/*
376	 * Desktops which falsely report a backlight and which our heuristics
377	 * for this do not catch.
 
378	 */
379	{
380	 .callback = video_detect_force_none,
381	 .ident = "Dell OptiPlex 9020M",
 
 
 
 
 
 
 
 
 
 
382	 .matches = {
383		DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
384		DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex 9020M"),
385		},
386	},
 
 
 
 
 
 
387	{
388	 .callback = video_detect_force_none,
389	 .ident = "MSI MS-7721",
390	 .matches = {
391		DMI_MATCH(DMI_SYS_VENDOR, "MSI"),
392		DMI_MATCH(DMI_PRODUCT_NAME, "MS-7721"),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
393		},
394	},
395	{ },
396};
397
398/* This uses a workqueue to avoid various locking ordering issues */
399static void acpi_video_backlight_notify_work(struct work_struct *work)
400{
401	if (acpi_video_get_backlight_type() != acpi_backlight_video)
402		acpi_video_unregister_backlight();
403}
404
405static int acpi_video_backlight_notify(struct notifier_block *nb,
406				       unsigned long val, void *bd)
 
 
 
 
407{
408	struct backlight_device *backlight = bd;
409
410	/* A raw bl registering may change video -> native */
411	if (backlight->props.type == BACKLIGHT_RAW &&
412	    val == BACKLIGHT_REGISTERED)
413		schedule_work(&backlight_notify_work);
414
415	return NOTIFY_OK;
416}
417
418/*
419 * Determine which type of backlight interface to use on this system,
420 * First check cmdline, then dmi quirks, then do autodetect.
421 *
422 * The autodetect order is:
423 * 1) Is the acpi-video backlight interface supported ->
424 *  no, use a vendor interface
425 * 2) Is this a win8 "ready" BIOS and do we have a native interface ->
426 *  yes, use a native interface
427 * 3) Else use the acpi-video interface
428 *
429 * Arguably the native on win8 check should be done first, but that would
430 * be a behavior change, which may causes issues.
431 */
432enum acpi_backlight_type acpi_video_get_backlight_type(void)
433{
434	static DEFINE_MUTEX(init_mutex);
 
 
 
 
435	static bool init_done;
436	static long video_caps;
437
438	/* Parse cmdline, dmi and acpi only once */
439	mutex_lock(&init_mutex);
440	if (!init_done) {
441		acpi_video_parse_cmdline();
442		dmi_check_system(video_detect_dmi_table);
443		acpi_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
444				    ACPI_UINT32_MAX, find_video, NULL,
445				    &video_caps, NULL);
446		INIT_WORK(&backlight_notify_work,
447			  acpi_video_backlight_notify_work);
448		backlight_nb.notifier_call = acpi_video_backlight_notify;
449		backlight_nb.priority = 0;
450		if (backlight_register_notifier(&backlight_nb) == 0)
451			backlight_notifier_registered = true;
452		init_done = true;
453	}
 
 
454	mutex_unlock(&init_mutex);
455
 
 
 
 
 
 
 
456	if (acpi_backlight_cmdline != acpi_backlight_undef)
457		return acpi_backlight_cmdline;
458
 
459	if (acpi_backlight_dmi != acpi_backlight_undef)
460		return acpi_backlight_dmi;
461
462	if (!(video_caps & ACPI_VIDEO_BACKLIGHT))
463		return acpi_backlight_vendor;
464
465	if (acpi_osi_is_win8() && backlight_device_get_by_type(BACKLIGHT_RAW))
466		return acpi_backlight_native;
 
 
 
 
 
 
 
 
 
 
 
 
467
468	return acpi_backlight_video;
469}
470EXPORT_SYMBOL(acpi_video_get_backlight_type);
471
472/*
473 * Set the preferred backlight interface type based on DMI info.
474 * This function allows DMI blacklists to be implemented by external
475 * platform drivers instead of putting a big blacklist in video_detect.c
476 */
477void acpi_video_set_dmi_backlight_type(enum acpi_backlight_type type)
478{
479	acpi_backlight_dmi = type;
480	/* Remove acpi-video backlight interface if it is no longer desired */
481	if (acpi_video_get_backlight_type() != acpi_backlight_video)
482		acpi_video_unregister_backlight();
483}
484EXPORT_SYMBOL(acpi_video_set_dmi_backlight_type);
 
 
 
 
 
 
 
485
486void __exit acpi_video_detect_exit(void)
487{
488	if (backlight_notifier_registered)
489		backlight_unregister_notifier(&backlight_nb);
490}
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);