xref: /netbsd-src/sys/external/bsd/drm2/dist/drm/drm_panel_orientation_quirks.c (revision 41ec02673d281bbb3d38e6c78504ce6e30c228c1)
1 /*	$NetBSD: drm_panel_orientation_quirks.c,v 1.2 2021/12/18 23:44:57 riastradh Exp $	*/
2 
3 /* SPDX-License-Identifier: MIT */
4 /*
5  * drm_panel_orientation_quirks.c -- Quirks for non-normal panel orientation
6  *
7  * Copyright (C) 2017 Hans de Goede <hdegoede@redhat.com>
8  *
9  * Note the quirks in this file are shared with fbdev/efifb and as such
10  * must not depend on other drm code.
11  */
12 
13 #include <sys/cdefs.h>
14 __KERNEL_RCSID(0, "$NetBSD: drm_panel_orientation_quirks.c,v 1.2 2021/12/18 23:44:57 riastradh Exp $");
15 
16 #include <linux/dmi.h>
17 #include <linux/module.h>
18 #include <drm/drm_connector.h>
19 #include <drm/drm_utils.h>
20 
21 #ifdef CONFIG_DMI
22 
23 /*
24  * Some x86 clamshell design devices use portrait tablet screens and a display
25  * engine which cannot rotate in hardware, so we need to rotate the fbcon to
26  * compensate. Unfortunately these (cheap) devices also typically have quite
27  * generic DMI data, so we match on a combination of DMI data, screen resolution
28  * and a list of known BIOS dates to avoid false positives.
29  */
30 
31 struct drm_dmi_panel_orientation_data {
32 	int width;
33 	int height;
34 	const char * const *bios_dates;
35 	int orientation;
36 };
37 
38 static const struct drm_dmi_panel_orientation_data acer_s1003 = {
39 	.width = 800,
40 	.height = 1280,
41 	.orientation = DRM_MODE_PANEL_ORIENTATION_RIGHT_UP,
42 };
43 
44 static const struct drm_dmi_panel_orientation_data asus_t100ha = {
45 	.width = 800,
46 	.height = 1280,
47 	.orientation = DRM_MODE_PANEL_ORIENTATION_LEFT_UP,
48 };
49 
50 static const struct drm_dmi_panel_orientation_data gpd_micropc = {
51 	.width = 720,
52 	.height = 1280,
53 	.bios_dates = (const char * const []){ "04/26/2019",
54 		NULL },
55 	.orientation = DRM_MODE_PANEL_ORIENTATION_RIGHT_UP,
56 };
57 
58 static const struct drm_dmi_panel_orientation_data gpd_pocket = {
59 	.width = 1200,
60 	.height = 1920,
61 	.bios_dates = (const char * const []){ "05/26/2017", "06/28/2017",
62 		"07/05/2017", "08/07/2017", NULL },
63 	.orientation = DRM_MODE_PANEL_ORIENTATION_RIGHT_UP,
64 };
65 
66 static const struct drm_dmi_panel_orientation_data gpd_pocket2 = {
67 	.width = 1200,
68 	.height = 1920,
69 	.bios_dates = (const char * const []){ "06/28/2018", "08/28/2018",
70 		"12/07/2018", NULL },
71 	.orientation = DRM_MODE_PANEL_ORIENTATION_RIGHT_UP,
72 };
73 
74 static const struct drm_dmi_panel_orientation_data gpd_win = {
75 	.width = 720,
76 	.height = 1280,
77 	.bios_dates = (const char * const []){
78 		"10/25/2016", "11/18/2016", "12/23/2016", "12/26/2016",
79 		"02/21/2017", "03/20/2017", "05/25/2017", NULL },
80 	.orientation = DRM_MODE_PANEL_ORIENTATION_RIGHT_UP,
81 };
82 
83 static const struct drm_dmi_panel_orientation_data gpd_win2 = {
84 	.width = 720,
85 	.height = 1280,
86 	.bios_dates = (const char * const []){
87 		"12/07/2017", "05/24/2018", "06/29/2018", NULL },
88 	.orientation = DRM_MODE_PANEL_ORIENTATION_RIGHT_UP,
89 };
90 
91 static const struct drm_dmi_panel_orientation_data itworks_tw891 = {
92 	.width = 800,
93 	.height = 1280,
94 	.bios_dates = (const char * const []){ "10/16/2015", NULL },
95 	.orientation = DRM_MODE_PANEL_ORIENTATION_RIGHT_UP,
96 };
97 
98 static const struct drm_dmi_panel_orientation_data lcd720x1280_rightside_up = {
99 	.width = 720,
100 	.height = 1280,
101 	.orientation = DRM_MODE_PANEL_ORIENTATION_RIGHT_UP,
102 };
103 
104 static const struct drm_dmi_panel_orientation_data lcd800x1280_rightside_up = {
105 	.width = 800,
106 	.height = 1280,
107 	.orientation = DRM_MODE_PANEL_ORIENTATION_RIGHT_UP,
108 };
109 
110 static const struct drm_dmi_panel_orientation_data lcd1200x1920_rightside_up = {
111 	.width = 1200,
112 	.height = 1920,
113 	.orientation = DRM_MODE_PANEL_ORIENTATION_RIGHT_UP,
114 };
115 
116 static const struct dmi_system_id orientation_data[] = {
117 	{	/* Acer One 10 (S1003) */
118 		.matches = {
119 		  DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Acer"),
120 		  DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "One S1003"),
121 		},
122 		.driver_data = (void *)&acer_s1003,
123 	}, {	/* Asus T100HA */
124 		.matches = {
125 		  DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
126 		  DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100HAN"),
127 		},
128 		.driver_data = (void *)&asus_t100ha,
129 	}, {	/* GPD MicroPC (generic strings, also match on bios date) */
130 		.matches = {
131 		  DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Default string"),
132 		  DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Default string"),
133 		  DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Default string"),
134 		  DMI_EXACT_MATCH(DMI_BOARD_NAME, "Default string"),
135 		},
136 		.driver_data = (void *)&gpd_micropc,
137 	}, {	/* GPD MicroPC (later BIOS versions with proper DMI strings) */
138 		.matches = {
139 		  DMI_EXACT_MATCH(DMI_SYS_VENDOR, "GPD"),
140 		  DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "MicroPC"),
141 		},
142 		.driver_data = (void *)&lcd720x1280_rightside_up,
143 	}, {	/*
144 		 * GPD Pocket, note that the the DMI data is less generic then
145 		 * it seems, devices with a board-vendor of "AMI Corporation"
146 		 * are quite rare, as are devices which have both board- *and*
147 		 * product-id set to "Default String"
148 		 */
149 		.matches = {
150 		  DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
151 		  DMI_EXACT_MATCH(DMI_BOARD_NAME, "Default string"),
152 		  DMI_EXACT_MATCH(DMI_BOARD_SERIAL, "Default string"),
153 		  DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Default string"),
154 		},
155 		.driver_data = (void *)&gpd_pocket,
156 	}, {	/* GPD Pocket 2 (generic strings, also match on bios date) */
157 		.matches = {
158 		  DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Default string"),
159 		  DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Default string"),
160 		  DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Default string"),
161 		  DMI_EXACT_MATCH(DMI_BOARD_NAME, "Default string"),
162 		},
163 		.driver_data = (void *)&gpd_pocket2,
164 	}, {	/* GPD Win (same note on DMI match as GPD Pocket) */
165 		.matches = {
166 		  DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
167 		  DMI_EXACT_MATCH(DMI_BOARD_NAME, "Default string"),
168 		  DMI_EXACT_MATCH(DMI_BOARD_SERIAL, "Default string"),
169 		  DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Default string"),
170 		},
171 		.driver_data = (void *)&gpd_win,
172 	}, {	/* GPD Win 2 (too generic strings, also match on bios date) */
173 		.matches = {
174 		  DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Default string"),
175 		  DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Default string"),
176 		  DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Default string"),
177 		  DMI_EXACT_MATCH(DMI_BOARD_NAME, "Default string"),
178 		},
179 		.driver_data = (void *)&gpd_win2,
180 	}, {	/* I.T.Works TW891 */
181 		.matches = {
182 		  DMI_EXACT_MATCH(DMI_SYS_VENDOR, "To be filled by O.E.M."),
183 		  DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TW891"),
184 		  DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "To be filled by O.E.M."),
185 		  DMI_EXACT_MATCH(DMI_BOARD_NAME, "TW891"),
186 		},
187 		.driver_data = (void *)&itworks_tw891,
188 	}, {	/*
189 		 * Lenovo Ideapad Miix 310 laptop, only some production batches
190 		 * have a portrait screen, the resolution checks makes the quirk
191 		 * apply only to those batches.
192 		 */
193 		.matches = {
194 		  DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"),
195 		  DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "80SG"),
196 		  DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "MIIX 310-10ICR"),
197 		},
198 		.driver_data = (void *)&lcd800x1280_rightside_up,
199 	}, {	/* Lenovo Ideapad Miix 320 */
200 		.matches = {
201 		  DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"),
202 		  DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "80XF"),
203 		  DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "Lenovo MIIX 320-10ICR"),
204 		},
205 		.driver_data = (void *)&lcd800x1280_rightside_up,
206 	}, {	/* Lenovo Ideapad D330 */
207 		.matches = {
208 		  DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"),
209 		  DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "81H3"),
210 		  DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "Lenovo ideapad D330-10IGM"),
211 		},
212 		.driver_data = (void *)&lcd1200x1920_rightside_up,
213 	}, {	/* VIOS LTH17 */
214 		.matches = {
215 		  DMI_EXACT_MATCH(DMI_SYS_VENDOR, "VIOS"),
216 		  DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "LTH17"),
217 		},
218 		.driver_data = (void *)&lcd800x1280_rightside_up,
219 	},
220 	{}
221 };
222 
223 /**
224  * drm_get_panel_orientation_quirk - Check for panel orientation quirks
225  * @width: width in pixels of the panel
226  * @height: height in pixels of the panel
227  *
228  * This function checks for platform specific (e.g. DMI based) quirks
229  * providing info on panel_orientation for systems where this cannot be
230  * probed from the hard-/firm-ware. To avoid false-positive this function
231  * takes the panel resolution as argument and checks that against the
232  * resolution expected by the quirk-table entry.
233  *
234  * Note this function is also used outside of the drm-subsys, by for example
235  * the efifb code. Because of this this function gets compiled into its own
236  * kernel-module when built as a module.
237  *
238  * Returns:
239  * A DRM_MODE_PANEL_ORIENTATION_* value if there is a quirk for this system,
240  * or DRM_MODE_PANEL_ORIENTATION_UNKNOWN if there is no quirk.
241  */
drm_get_panel_orientation_quirk(int width,int height)242 int drm_get_panel_orientation_quirk(int width, int height)
243 {
244 	const struct dmi_system_id *match;
245 	const struct drm_dmi_panel_orientation_data *data;
246 	const char *bios_date;
247 	int i;
248 
249 	for (match = dmi_first_match(orientation_data);
250 	     match;
251 	     match = dmi_first_match(match + 1)) {
252 		data = match->driver_data;
253 
254 		if (data->width != width ||
255 		    data->height != height)
256 			continue;
257 
258 		if (!data->bios_dates)
259 			return data->orientation;
260 
261 		bios_date = dmi_get_system_info(DMI_BIOS_DATE);
262 		if (!bios_date)
263 			continue;
264 
265 		i = match_string(data->bios_dates, -1, bios_date);
266 		if (i >= 0)
267 			return data->orientation;
268 	}
269 
270 	return DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
271 }
272 EXPORT_SYMBOL(drm_get_panel_orientation_quirk);
273 
274 #else
275 
276 /* There are no quirks for non x86 devices yet */
drm_get_panel_orientation_quirk(int width,int height)277 int drm_get_panel_orientation_quirk(int width, int height)
278 {
279 	return DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
280 }
281 EXPORT_SYMBOL(drm_get_panel_orientation_quirk);
282 
283 #endif
284 
285 MODULE_LICENSE("Dual MIT/GPL");
286