GNU Linux-libre 4.14.290-gnu1
[releases.git] / drivers / video / fbdev / core / fbcon_dmi_quirks.c
1 /*
2  *  fbcon_dmi_quirks.c -- DMI based quirk detection for fbcon
3  *
4  *      Copyright (C) 2017 Hans de Goede <hdegoede@redhat.com>
5  *
6  *  This file is subject to the terms and conditions of the GNU General Public
7  *  License.  See the file COPYING in the main directory of this archive for
8  *  more details.
9  */
10
11 #include <linux/dmi.h>
12 #include <linux/fb.h>
13 #include <linux/kernel.h>
14 #include "fbcon.h"
15
16 /*
17  * Some x86 clamshell design devices use portrait tablet screens and a display
18  * engine which cannot rotate in hardware, so we need to rotate the fbcon to
19  * compensate. Unfortunately these (cheap) devices also typically have quite
20  * generic DMI data, so we match on a combination of DMI data, screen resolution
21  * and a list of known BIOS dates to avoid false positives.
22  */
23
24 struct fbcon_dmi_rotate_data {
25         int width;
26         int height;
27         const char * const *bios_dates;
28         int rotate;
29 };
30
31 static const struct fbcon_dmi_rotate_data rotate_data_asus_t100ha = {
32         .width = 800,
33         .height = 1280,
34         .rotate = FB_ROTATE_CCW,
35 };
36
37 static const struct fbcon_dmi_rotate_data rotate_data_gpd_pocket = {
38         .width = 1200,
39         .height = 1920,
40         .bios_dates = (const char * const []){ "05/26/2017", "06/28/2017",
41                 "07/05/2017", "08/07/2017", NULL },
42         .rotate = FB_ROTATE_CW,
43 };
44
45 static const struct fbcon_dmi_rotate_data rotate_data_gpd_win = {
46         .width = 720,
47         .height = 1280,
48         .bios_dates = (const char * const []){
49                 "10/25/2016", "11/18/2016", "12/23/2016", "12/26/2016",
50                 "02/21/2017", "03/20/2017", "05/25/2017", NULL },
51         .rotate = FB_ROTATE_CW,
52 };
53
54 static const struct fbcon_dmi_rotate_data rotate_data_itworks_tw891 = {
55         .width = 800,
56         .height = 1280,
57         .bios_dates = (const char * const []){ "10/16/2015", NULL },
58         .rotate = FB_ROTATE_CW,
59 };
60
61 static const struct fbcon_dmi_rotate_data rotate_data_vios_lth17 = {
62         .width = 800,
63         .height = 1280,
64         .rotate = FB_ROTATE_CW,
65 };
66
67 static const struct dmi_system_id rotate_data[] = {
68         {       /* Asus T100HA */
69                 .matches = {
70                   DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
71                   DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100HAN"),
72                 },
73                 .driver_data = (void *)&rotate_data_asus_t100ha,
74         }, {    /*
75                  * GPD Pocket, note that the the DMI data is less generic then
76                  * it seems, devices with a board-vendor of "AMI Corporation"
77                  * are quite rare, as are devices which have both board- *and*
78                  * product-id set to "Default String"
79                  */
80                 .matches = {
81                   DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
82                   DMI_EXACT_MATCH(DMI_BOARD_NAME, "Default string"),
83                   DMI_EXACT_MATCH(DMI_BOARD_SERIAL, "Default string"),
84                   DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Default string"),
85                 },
86                 .driver_data = (void *)&rotate_data_gpd_pocket,
87         }, {    /* GPD Win (same note on DMI match as GPD Pocket) */
88                 .matches = {
89                   DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
90                   DMI_EXACT_MATCH(DMI_BOARD_NAME, "Default string"),
91                   DMI_EXACT_MATCH(DMI_BOARD_SERIAL, "Default string"),
92                   DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Default string"),
93                 },
94                 .driver_data = (void *)&rotate_data_gpd_win,
95         }, {    /* I.T.Works TW891 */
96                 .matches = {
97                   DMI_EXACT_MATCH(DMI_SYS_VENDOR, "To be filled by O.E.M."),
98                   DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TW891"),
99                   DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "To be filled by O.E.M."),
100                   DMI_EXACT_MATCH(DMI_BOARD_NAME, "TW891"),
101                 },
102                 .driver_data = (void *)&rotate_data_itworks_tw891,
103         }, {    /* VIOS LTH17 */
104                 .matches = {
105                   DMI_EXACT_MATCH(DMI_SYS_VENDOR, "VIOS"),
106                   DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "LTH17"),
107                   DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "VIOS"),
108                   DMI_EXACT_MATCH(DMI_BOARD_NAME, "LTH17"),
109                 },
110                 .driver_data = (void *)&rotate_data_vios_lth17,
111         },
112         {}
113 };
114
115 int fbcon_platform_get_rotate(struct fb_info *info)
116 {
117         const struct dmi_system_id *match;
118         const struct fbcon_dmi_rotate_data *data;
119         const char *bios_date;
120         int i;
121
122         for (match = dmi_first_match(rotate_data);
123              match;
124              match = dmi_first_match(match + 1)) {
125                 data = match->driver_data;
126
127                 if (data->width != info->var.xres ||
128                     data->height != info->var.yres)
129                         continue;
130
131                 if (!data->bios_dates)
132                         return data->rotate;
133
134                 bios_date = dmi_get_system_info(DMI_BIOS_DATE);
135                 if (!bios_date)
136                         continue;
137
138                 for (i = 0; data->bios_dates[i]; i++) {
139                         if (!strcmp(data->bios_dates[i], bios_date))
140                                 return data->rotate;
141                 }
142         }
143
144         return FB_ROTATE_UR;
145 }