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