1 // SPDX-License-Identifier: MIT
2 /*
3  * Copyright © 2018 Intel Corporation
4  */
5 
6 #include <linux/dmi.h>
7 
8 #include "intel_display_types.h"
9 #include "intel_quirks.h"
10 
11 /*
12  * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
13  */
14 static void quirk_ssc_force_disable(struct drm_i915_private *i915)
15 {
16 	i915->quirks |= QUIRK_LVDS_SSC_DISABLE;
17 	drm_info(&i915->drm, "applying lvds SSC disable quirk\n");
18 }
19 
20 /*
21  * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
22  * brightness value
23  */
24 static void quirk_invert_brightness(struct drm_i915_private *i915)
25 {
26 	i915->quirks |= QUIRK_INVERT_BRIGHTNESS;
27 	drm_info(&i915->drm, "applying inverted panel brightness quirk\n");
28 }
29 
30 /* Some VBT's incorrectly indicate no backlight is present */
31 static void quirk_backlight_present(struct drm_i915_private *i915)
32 {
33 	i915->quirks |= QUIRK_BACKLIGHT_PRESENT;
34 	drm_info(&i915->drm, "applying backlight present quirk\n");
35 }
36 
37 /* Toshiba Satellite P50-C-18C requires T12 delay to be min 800ms
38  * which is 300 ms greater than eDP spec T12 min.
39  */
40 static void quirk_increase_t12_delay(struct drm_i915_private *i915)
41 {
42 	i915->quirks |= QUIRK_INCREASE_T12_DELAY;
43 	drm_info(&i915->drm, "Applying T12 delay quirk\n");
44 }
45 
46 /*
47  * GeminiLake NUC HDMI outputs require additional off time
48  * this allows the onboard retimer to correctly sync to signal
49  */
50 static void quirk_increase_ddi_disabled_time(struct drm_i915_private *i915)
51 {
52 	i915->quirks |= QUIRK_INCREASE_DDI_DISABLED_TIME;
53 	drm_info(&i915->drm, "Applying Increase DDI Disabled quirk\n");
54 }
55 
56 static void quirk_no_pps_backlight_power_hook(struct drm_i915_private *i915)
57 {
58 	i915->quirks |= QUIRK_NO_PPS_BACKLIGHT_POWER_HOOK;
59 	drm_info(&i915->drm, "Applying no pps backlight power quirk\n");
60 }
61 
62 struct intel_quirk {
63 	int device;
64 	int subsystem_vendor;
65 	int subsystem_device;
66 	void (*hook)(struct drm_i915_private *i915);
67 };
68 
69 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
70 struct intel_dmi_quirk {
71 	void (*hook)(struct drm_i915_private *i915);
72 	const struct dmi_system_id (*dmi_id_list)[];
73 };
74 
75 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
76 {
77 	DRM_INFO("Backlight polarity reversed on %s\n", id->ident);
78 	return 1;
79 }
80 
81 static int intel_dmi_no_pps_backlight(const struct dmi_system_id *id)
82 {
83 	DRM_INFO("No pps backlight support on %s\n", id->ident);
84 	return 1;
85 }
86 
87 static const struct intel_dmi_quirk intel_dmi_quirks[] = {
88 	{
89 		.dmi_id_list = &(const struct dmi_system_id[]) {
90 			{
91 				.callback = intel_dmi_reverse_brightness,
92 				.ident = "NCR Corporation",
93 				.matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
94 					    DMI_MATCH(DMI_PRODUCT_NAME, ""),
95 				},
96 			},
97 			{
98 				.callback = intel_dmi_reverse_brightness,
99 				.ident = "Thundersoft TST178 tablet",
100 				/* DMI strings are too generic, also match on BIOS date */
101 				.matches = {DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
102 					    DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
103 					    DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "To be filled by O.E.M."),
104 					    DMI_EXACT_MATCH(DMI_BIOS_DATE, "04/15/2014"),
105 				},
106 			},
107 			{ }  /* terminating entry */
108 		},
109 		.hook = quirk_invert_brightness,
110 	},
111 	{
112 		.dmi_id_list = &(const struct dmi_system_id[]) {
113 			{
114 				.callback = intel_dmi_no_pps_backlight,
115 				.ident = "Google Lillipup sku524294",
116 				.matches = {DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Google"),
117 					    DMI_EXACT_MATCH(DMI_BOARD_NAME, "Lindar"),
118 					    DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "sku524294"),
119 				},
120 			},
121 			{
122 				.callback = intel_dmi_no_pps_backlight,
123 				.ident = "Google Lillipup sku524295",
124 				.matches = {DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Google"),
125 					    DMI_EXACT_MATCH(DMI_BOARD_NAME, "Lindar"),
126 					    DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "sku524295"),
127 				},
128 			},
129 			{ }
130 		},
131 		.hook = quirk_no_pps_backlight_power_hook,
132 	},
133 };
134 
135 static struct intel_quirk intel_quirks[] = {
136 	/* Lenovo U160 cannot use SSC on LVDS */
137 	{ 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable },
138 
139 	/* Sony Vaio Y cannot use SSC on LVDS */
140 	{ 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable },
141 
142 	/* Acer Aspire 5734Z must invert backlight brightness */
143 	{ 0x2a42, 0x1025, 0x0459, quirk_invert_brightness },
144 
145 	/* Acer/eMachines G725 */
146 	{ 0x2a42, 0x1025, 0x0210, quirk_invert_brightness },
147 
148 	/* Acer/eMachines e725 */
149 	{ 0x2a42, 0x1025, 0x0212, quirk_invert_brightness },
150 
151 	/* Acer/Packard Bell NCL20 */
152 	{ 0x2a42, 0x1025, 0x034b, quirk_invert_brightness },
153 
154 	/* Acer Aspire 4736Z */
155 	{ 0x2a42, 0x1025, 0x0260, quirk_invert_brightness },
156 
157 	/* Acer Aspire 5336 */
158 	{ 0x2a42, 0x1025, 0x048a, quirk_invert_brightness },
159 
160 	/* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */
161 	{ 0x0a06, 0x1025, 0x0a11, quirk_backlight_present },
162 
163 	/* Acer C720 Chromebook (Core i3 4005U) */
164 	{ 0x0a16, 0x1025, 0x0a11, quirk_backlight_present },
165 
166 	/* Apple Macbook 2,1 (Core 2 T7400) */
167 	{ 0x27a2, 0x8086, 0x7270, quirk_backlight_present },
168 
169 	/* Apple Macbook 4,1 */
170 	{ 0x2a02, 0x106b, 0x00a1, quirk_backlight_present },
171 
172 	/* Toshiba CB35 Chromebook (Celeron 2955U) */
173 	{ 0x0a06, 0x1179, 0x0a88, quirk_backlight_present },
174 
175 	/* HP Chromebook 14 (Celeron 2955U) */
176 	{ 0x0a06, 0x103c, 0x21ed, quirk_backlight_present },
177 
178 	/* Dell Chromebook 11 */
179 	{ 0x0a06, 0x1028, 0x0a35, quirk_backlight_present },
180 
181 	/* Dell Chromebook 11 (2015 version) */
182 	{ 0x0a16, 0x1028, 0x0a35, quirk_backlight_present },
183 
184 	/* Toshiba Satellite P50-C-18C */
185 	{ 0x191B, 0x1179, 0xF840, quirk_increase_t12_delay },
186 
187 	/* GeminiLake NUC */
188 	{ 0x3185, 0x8086, 0x2072, quirk_increase_ddi_disabled_time },
189 	{ 0x3184, 0x8086, 0x2072, quirk_increase_ddi_disabled_time },
190 	/* ASRock ITX*/
191 	{ 0x3185, 0x1849, 0x2212, quirk_increase_ddi_disabled_time },
192 	{ 0x3184, 0x1849, 0x2212, quirk_increase_ddi_disabled_time },
193 };
194 
195 void intel_init_quirks(struct drm_i915_private *i915)
196 {
197 	struct pci_dev *d = to_pci_dev(i915->drm.dev);
198 	int i;
199 
200 	for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) {
201 		struct intel_quirk *q = &intel_quirks[i];
202 
203 		if (d->device == q->device &&
204 		    (d->subsystem_vendor == q->subsystem_vendor ||
205 		     q->subsystem_vendor == PCI_ANY_ID) &&
206 		    (d->subsystem_device == q->subsystem_device ||
207 		     q->subsystem_device == PCI_ANY_ID))
208 			q->hook(i915);
209 	}
210 	for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) {
211 		if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0)
212 			intel_dmi_quirks[i].hook(i915);
213 	}
214 }
215