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