xref: /linux/drivers/gpu/drm/drm_panel_backlight_quirks.c (revision 21ef2d065ad3f0cfbf2ae51260bf962a9fa2c643)
1 // SPDX-License-Identifier: GPL-2.0
2 
3 #include <linux/array_size.h>
4 #include <linux/dmi.h>
5 #include <linux/export.h>
6 #include <linux/module.h>
7 #include <drm/drm_edid.h>
8 #include <drm/drm_utils.h>
9 
10 struct drm_panel_match {
11 	enum dmi_field field;
12 	const char * const value;
13 };
14 
15 struct drm_get_panel_backlight_quirk {
16 	struct drm_panel_match dmi_match;
17 	struct drm_panel_match dmi_match_other;
18 	struct drm_edid_ident ident;
19 	struct drm_panel_backlight_quirk quirk;
20 };
21 
22 static const struct drm_get_panel_backlight_quirk drm_panel_min_backlight_quirks[] = {
23 	/* Lenovo Legion 5 15ARH05, AUX backlight non-functional, force PWM */
24 	{
25 		.dmi_match.field = DMI_SYS_VENDOR,
26 		.dmi_match.value = "LENOVO",
27 		.dmi_match_other.field = DMI_PRODUCT_VERSION,
28 		.dmi_match_other.value = "Lenovo Legion 5 15ARH05",
29 		.ident.panel_id = drm_edid_encode_panel_id('B', 'O', 'E', 0x08df),
30 		.quirk = { .force_pwm = true, },
31 	},
32 	/* 13 inch matte panel */
33 	{
34 		.dmi_match.field = DMI_BOARD_VENDOR,
35 		.dmi_match.value = "Framework",
36 		.ident.panel_id = drm_edid_encode_panel_id('B', 'O', 'E', 0x0bca),
37 		.ident.name = "NE135FBM-N41",
38 		.quirk = { .min_brightness = 1, },
39 	},
40 	/* 13 inch glossy panel */
41 	{
42 		.dmi_match.field = DMI_BOARD_VENDOR,
43 		.dmi_match.value = "Framework",
44 		.ident.panel_id = drm_edid_encode_panel_id('B', 'O', 'E', 0x095f),
45 		.ident.name = "NE135FBM-N41",
46 		.quirk = { .min_brightness = 1, },
47 	},
48 	/* 13 inch 2.8k panel */
49 	{
50 		.dmi_match.field = DMI_BOARD_VENDOR,
51 		.dmi_match.value = "Framework",
52 		.ident.panel_id = drm_edid_encode_panel_id('B', 'O', 'E', 0x0cb4),
53 		.ident.name = "NE135A1M-NY1",
54 		.quirk = { .min_brightness = 1, },
55 	},
56 	/* Steam Deck models */
57 	{
58 		.dmi_match.field = DMI_SYS_VENDOR,
59 		.dmi_match.value = "Valve",
60 		.dmi_match_other.field = DMI_PRODUCT_NAME,
61 		.dmi_match_other.value = "Jupiter",
62 		.quirk = { .min_brightness = 1, },
63 	},
64 	{
65 		.dmi_match.field = DMI_SYS_VENDOR,
66 		.dmi_match.value = "Valve",
67 		.dmi_match_other.field = DMI_PRODUCT_NAME,
68 		.dmi_match_other.value = "Galileo",
69 		.quirk = { .min_brightness = 1, },
70 	},
71 	/* Have OLED Panels with brightness issue when last byte is 0/1 */
72 	{
73 		.dmi_match.field = DMI_SYS_VENDOR,
74 		.dmi_match.value = "AYANEO",
75 		.dmi_match_other.field = DMI_PRODUCT_NAME,
76 		.dmi_match_other.value = "AYANEO 3",
77 		.quirk = { .brightness_mask = 3, },
78 	},
79 	{
80 		.dmi_match.field = DMI_SYS_VENDOR,
81 		.dmi_match.value = "ZOTAC",
82 		.dmi_match_other.field = DMI_BOARD_NAME,
83 		.dmi_match_other.value = "G0A1W",
84 		.quirk = { .brightness_mask = 3, },
85 	},
86 	{
87 		.dmi_match.field = DMI_SYS_VENDOR,
88 		.dmi_match.value = "ZOTAC",
89 		.dmi_match_other.field = DMI_BOARD_NAME,
90 		.dmi_match_other.value = "G1A1W",
91 		.quirk = { .brightness_mask = 3, },
92 	},
93 	{
94 		.dmi_match.field = DMI_SYS_VENDOR,
95 		.dmi_match.value = "ONE-NETBOOK",
96 		.dmi_match_other.field = DMI_PRODUCT_NAME,
97 		.dmi_match_other.value = "ONEXPLAYER F1Pro",
98 		.quirk = { .brightness_mask = 3, },
99 	},
100 	{
101 		.dmi_match.field = DMI_SYS_VENDOR,
102 		.dmi_match.value = "ONE-NETBOOK",
103 		.dmi_match_other.field = DMI_PRODUCT_NAME,
104 		.dmi_match_other.value = "ONEXPLAYER F1 EVA-02",
105 		.quirk = { .brightness_mask = 3, },
106 	},
107 };
108 
109 static bool drm_panel_min_backlight_quirk_matches(
110 	const struct drm_get_panel_backlight_quirk *quirk,
111 	const struct drm_edid *edid)
112 {
113 	if (quirk->dmi_match.field &&
114 	    !dmi_match(quirk->dmi_match.field, quirk->dmi_match.value))
115 		return false;
116 
117 	if (quirk->dmi_match_other.field &&
118 	    !dmi_match(quirk->dmi_match_other.field,
119 		       quirk->dmi_match_other.value))
120 		return false;
121 
122 	if (quirk->ident.panel_id && !drm_edid_match(edid, &quirk->ident))
123 		return false;
124 
125 	return true;
126 }
127 
128 /**
129  * drm_get_panel_backlight_quirk - Get backlight quirks for a panel
130  * @edid: EDID of the panel to check
131  *
132  * This function checks for platform specific (e.g. DMI based) quirks
133  * providing info on the minimum backlight brightness for systems where this
134  * cannot be probed correctly from the hard-/firm-ware and other sources.
135  *
136  * Returns:
137  * a drm_panel_backlight_quirk struct if a quirk was found, otherwise an
138  * error pointer.
139  */
140 const struct drm_panel_backlight_quirk *
141 drm_get_panel_backlight_quirk(const struct drm_edid *edid)
142 {
143 	const struct drm_get_panel_backlight_quirk *quirk;
144 	size_t i;
145 
146 	if (!IS_ENABLED(CONFIG_DMI))
147 		return ERR_PTR(-ENODATA);
148 
149 	if (!edid)
150 		return ERR_PTR(-EINVAL);
151 
152 	for (i = 0; i < ARRAY_SIZE(drm_panel_min_backlight_quirks); i++) {
153 		quirk = &drm_panel_min_backlight_quirks[i];
154 
155 		if (drm_panel_min_backlight_quirk_matches(quirk, edid))
156 			return &quirk->quirk;
157 	}
158 
159 	return ERR_PTR(-ENODATA);
160 }
161 EXPORT_SYMBOL(drm_get_panel_backlight_quirk);
162 
163 MODULE_DESCRIPTION("Quirks for panel backlight overrides");
164 MODULE_LICENSE("GPL");
165