1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Samsung AMS427AP24 panel with S6E88A0 controller
4 * Copyright (c) 2024 Jakob Hauser <jahau@rocketmail.com>
5 */
6
7 #include <linux/backlight.h>
8 #include <linux/delay.h>
9 #include <linux/gpio/consumer.h>
10 #include <linux/module.h>
11 #include <linux/property.h>
12 #include <linux/regulator/consumer.h>
13
14 #include <video/mipi_display.h>
15
16 #include <drm/drm_mipi_dsi.h>
17 #include <drm/drm_modes.h>
18 #include <drm/drm_panel.h>
19 #include <drm/drm_probe_helper.h>
20
21 #define NUM_STEPS_CANDELA 54
22 #define NUM_STEPS_AID 39
23 #define NUM_STEPS_ELVSS 17
24
25 /* length of the payload data, thereof fixed and variable */
26 #define FIX_LEN_AID 4
27 #define FIX_LEN_ELVSS 2
28 #define FIX_LEN_GAMMA 1
29 #define VAR_LEN_AID 2
30 #define VAR_LEN_ELVSS 1
31 #define VAR_LEN_GAMMA 33
32 #define LEN_AID (FIX_LEN_AID + VAR_LEN_AID)
33 #define LEN_ELVSS (FIX_LEN_ELVSS + VAR_LEN_ELVSS)
34 #define LEN_GAMMA (FIX_LEN_GAMMA + VAR_LEN_GAMMA)
35
36 struct s6e88a0_ams427ap24 {
37 struct drm_panel panel;
38 struct backlight_device *bl_dev;
39 struct mipi_dsi_device *dsi;
40 struct regulator_bulk_data *supplies;
41 struct gpio_desc *reset_gpio;
42 bool flip_horizontal;
43 };
44
45 static const struct regulator_bulk_data s6e88a0_ams427ap24_supplies[] = {
46 { .supply = "vdd3" },
47 { .supply = "vci" },
48 };
49
50 static inline
to_s6e88a0_ams427ap24(struct drm_panel * panel)51 struct s6e88a0_ams427ap24 *to_s6e88a0_ams427ap24(struct drm_panel *panel)
52 {
53 return container_of(panel, struct s6e88a0_ams427ap24, panel);
54 }
55
56 enum candela {
57 CANDELA_10CD, /* 0 */
58 CANDELA_11CD,
59 CANDELA_12CD,
60 CANDELA_13CD,
61 CANDELA_14CD,
62 CANDELA_15CD,
63 CANDELA_16CD,
64 CANDELA_17CD,
65 CANDELA_19CD,
66 CANDELA_20CD,
67 CANDELA_21CD,
68 CANDELA_22CD,
69 CANDELA_24CD,
70 CANDELA_25CD,
71 CANDELA_27CD,
72 CANDELA_29CD,
73 CANDELA_30CD,
74 CANDELA_32CD,
75 CANDELA_34CD,
76 CANDELA_37CD,
77 CANDELA_39CD,
78 CANDELA_41CD,
79 CANDELA_44CD,
80 CANDELA_47CD,
81 CANDELA_50CD,
82 CANDELA_53CD,
83 CANDELA_56CD,
84 CANDELA_60CD,
85 CANDELA_64CD,
86 CANDELA_68CD,
87 CANDELA_72CD,
88 CANDELA_77CD,
89 CANDELA_82CD,
90 CANDELA_87CD,
91 CANDELA_93CD,
92 CANDELA_98CD,
93 CANDELA_105CD,
94 CANDELA_111CD,
95 CANDELA_119CD,
96 CANDELA_126CD,
97 CANDELA_134CD,
98 CANDELA_143CD,
99 CANDELA_152CD,
100 CANDELA_162CD,
101 CANDELA_172CD,
102 CANDELA_183CD,
103 CANDELA_195CD,
104 CANDELA_207CD,
105 CANDELA_220CD,
106 CANDELA_234CD,
107 CANDELA_249CD,
108 CANDELA_265CD,
109 CANDELA_282CD,
110 CANDELA_300CD, /* 53 */
111 };
112
113 static const int s6e88a0_ams427ap24_br_to_cd[NUM_STEPS_CANDELA] = {
114 /* columns: brightness from, brightness till, candela */
115 /* 0 */ 10, /* 10CD */
116 /* 11 */ 11, /* 11CD */
117 /* 12 */ 12, /* 12CD */
118 /* 13 */ 13, /* 13CD */
119 /* 14 */ 14, /* 14CD */
120 /* 15 */ 15, /* 15CD */
121 /* 16 */ 16, /* 16CD */
122 /* 17 */ 17, /* 17CD */
123 /* 18 */ 18, /* 19CD */
124 /* 19 */ 19, /* 20CD */
125 /* 20 */ 20, /* 21CD */
126 /* 21 */ 21, /* 22CD */
127 /* 22 */ 22, /* 24CD */
128 /* 23 */ 23, /* 25CD */
129 /* 24 */ 24, /* 27CD */
130 /* 25 */ 25, /* 29CD */
131 /* 26 */ 26, /* 30CD */
132 /* 27 */ 27, /* 32CD */
133 /* 28 */ 28, /* 34CD */
134 /* 29 */ 29, /* 37CD */
135 /* 30 */ 30, /* 39CD */
136 /* 31 */ 32, /* 41CD */
137 /* 33 */ 34, /* 44CD */
138 /* 35 */ 36, /* 47CD */
139 /* 37 */ 38, /* 50CD */
140 /* 39 */ 40, /* 53CD */
141 /* 41 */ 43, /* 56CD */
142 /* 44 */ 46, /* 60CD */
143 /* 47 */ 49, /* 64CD */
144 /* 50 */ 52, /* 68CD */
145 /* 53 */ 56, /* 72CD */
146 /* 57 */ 59, /* 77CD */
147 /* 60 */ 63, /* 82CD */
148 /* 64 */ 67, /* 87CD */
149 /* 68 */ 71, /* 93CD */
150 /* 72 */ 76, /* 98CD */
151 /* 77 */ 80, /* 105CD */
152 /* 81 */ 86, /* 111CD */
153 /* 87 */ 91, /* 119CD */
154 /* 92 */ 97, /* 126CD */
155 /* 98 */ 104, /* 134CD */
156 /* 105 */ 110, /* 143CD */
157 /* 111 */ 118, /* 152CD */
158 /* 119 */ 125, /* 162CD */
159 /* 126 */ 133, /* 172CD */
160 /* 134 */ 142, /* 183CD */
161 /* 143 */ 150, /* 195CD */
162 /* 151 */ 160, /* 207CD */
163 /* 161 */ 170, /* 220CD */
164 /* 171 */ 181, /* 234CD */
165 /* 182 */ 205, /* 249CD */
166 /* 206 */ 234, /* 265CD */
167 /* 235 */ 254, /* 282CD */
168 /* 255 */ 255, /* 300CD */
169 };
170
171 static const u8 s6e88a0_ams427ap24_aid[NUM_STEPS_AID][VAR_LEN_AID] = {
172 { 0x03, 0x77 }, /* AOR 90.9%, 10CD */
173 { 0x03, 0x73 }, /* AOR 90.5%, 11CD */
174 { 0x03, 0x69 }, /* AOR 89.4%, 12CD */
175 { 0x03, 0x65 }, /* AOR 89.0%, 13CD */
176 { 0x03, 0x61 }, /* AOR 88.6%, 14CD */
177 { 0x03, 0x55 }, /* AOR 87.4%, 15CD */
178 { 0x03, 0x50 }, /* AOR 86.9%, 16CD */
179 { 0x03, 0x45 }, /* AOR 85.8%, 17CD */
180 { 0x03, 0x35 }, /* AOR 84.1%, 19CD */
181 { 0x03, 0x27 }, /* AOR 82.7%, 20CD */
182 { 0x03, 0x23 }, /* AOR 82.3%, 21CD */
183 { 0x03, 0x17 }, /* AOR 81.0%, 22CD */
184 { 0x03, 0x11 }, /* AOR 80.4%, 24CD */
185 { 0x03, 0x04 }, /* AOR 79.1%, 25CD */
186 { 0x02, 0xf4 }, /* AOR 77.5%, 27CD */
187 { 0x02, 0xe3 }, /* AOR 75.7%, 29CD */
188 { 0x02, 0xd7 }, /* AOR 74.5%, 30CD */
189 { 0x02, 0xc6 }, /* AOR 72.7%, 32CD */
190 { 0x02, 0xb7 }, /* AOR 71.2%, 34CD */
191 { 0x02, 0xa1 }, /* AOR 69.0%, 37CD */
192 { 0x02, 0x91 }, /* AOR 67.3%, 39CD */
193 { 0x02, 0x78 }, /* AOR 64.8%, 41CD */
194 { 0x02, 0x62 }, /* AOR 62.5%, 44CD */
195 { 0x02, 0x45 }, /* AOR 59.5%, 47CD */
196 { 0x02, 0x30 }, /* AOR 57.4%, 50CD */
197 { 0x02, 0x13 }, /* AOR 54.4%, 53CD */
198 { 0x01, 0xf5 }, /* AOR 51.3%, 56CD */
199 { 0x01, 0xd3 }, /* AOR 47.8%, 60CD */
200 { 0x01, 0xb1 }, /* AOR 44.4%, 64CD */
201 { 0x01, 0x87 }, /* AOR 40.1%, 68CD */
202 { 0x01, 0x63 }, /* AOR 36.6%, 72CD */
203 { 0x01, 0x35 }, /* AOR 31.7%, 77CD */
204 { 0x01, 0x05 }, /* AOR 26.9%, 82CD */
205 { 0x00, 0xd5 }, /* AOR 21.8%, 87CD */
206 { 0x00, 0xa1 }, /* AOR 16.5%, 93CD */
207 { 0x00, 0x6f }, /* AOR 11.4%, 98CD */
208 { 0x00, 0x31 }, /* AOR 5.0%, 105CD */
209 { 0x01, 0x86 }, /* AOR 40.0%, 111CD ~ 172CD */
210 { 0x00, 0x08 }, /* AOR 0.6%, 183CD ~ 300CD */
211 };
212
213 static const u8 s6e88a0_ams427ap24_elvss[NUM_STEPS_ELVSS][VAR_LEN_ELVSS] = {
214 { 0x14 }, /* 10CD ~ 111CD */
215 { 0x13 }, /* 119CD */
216 { 0x12 }, /* 126CD */
217 { 0x12 }, /* 134CD */
218 { 0x11 }, /* 143CD */
219 { 0x10 }, /* 152CD */
220 { 0x0f }, /* 162CD */
221 { 0x0e }, /* 172CD */
222 { 0x11 }, /* 183CD */
223 { 0x11 }, /* 195CD */
224 { 0x10 }, /* 207CD */
225 { 0x0f }, /* 220CD */
226 { 0x0f }, /* 234CD */
227 { 0x0e }, /* 249CD */
228 { 0x0d }, /* 265CD */
229 { 0x0c }, /* 282CD */
230 { 0x0b }, /* 300CD */
231 };
232
233 static const u8 s6e88a0_ams427ap24_gamma[NUM_STEPS_CANDELA][VAR_LEN_GAMMA] = {
234 /* 10CD */
235 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x8c, 0x8a, 0x8a, 0x8c, 0x8b,
236 0x8c, 0x87, 0x89, 0x89, 0x88, 0x87, 0x8c, 0x80, 0x82, 0x88, 0x7b,
237 0x72, 0x8c, 0x60, 0x68, 0x8c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
238 /* 11CD */
239 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x8c, 0x8a, 0x8a, 0x8c, 0x8b,
240 0x8c, 0x87, 0x89, 0x89, 0x88, 0x87, 0x8c, 0x80, 0x82, 0x88, 0x7b,
241 0x72, 0x8c, 0x60, 0x68, 0x8c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
242 /* 12CD */
243 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x8c, 0x8a, 0x8a, 0x8b, 0x8b,
244 0x8c, 0x88, 0x89, 0x8a, 0x88, 0x87, 0x8c, 0x81, 0x82, 0x87, 0x7a,
245 0x72, 0x8b, 0x60, 0x68, 0x8c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
246 /* 13CD */
247 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x8c, 0x8a, 0x8a, 0x8b, 0x8b,
248 0x8c, 0x88, 0x89, 0x8a, 0x88, 0x87, 0x8c, 0x81, 0x82, 0x87, 0x7a,
249 0x72, 0x8b, 0x61, 0x69, 0x8c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
250 /* 14CD */
251 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x8c, 0x8a, 0x89, 0x8c, 0x8b,
252 0x8c, 0x88, 0x89, 0x8a, 0x87, 0x86, 0x8a, 0x82, 0x82, 0x87, 0x79,
253 0x71, 0x89, 0x63, 0x6c, 0x8e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
254 /* 15CD */
255 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x8c, 0x8a, 0x8a, 0x8c, 0x8c,
256 0x8c, 0x86, 0x87, 0x88, 0x85, 0x85, 0x8a, 0x83, 0x83, 0x88, 0x78,
257 0x72, 0x89, 0x64, 0x6c, 0x8e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
258 /* 16CD */
259 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x8c, 0x8a, 0x89, 0x8c, 0x8b,
260 0x8c, 0x86, 0x88, 0x88, 0x86, 0x86, 0x8a, 0x84, 0x84, 0x88, 0x78,
261 0x72, 0x89, 0x5d, 0x67, 0x8b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
262 /* 17CD */
263 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x8c, 0x8a, 0x89, 0x8b, 0x8b,
264 0x8b, 0x87, 0x89, 0x89, 0x86, 0x86, 0x8a, 0x84, 0x83, 0x87, 0x78,
265 0x73, 0x89, 0x64, 0x6e, 0x8e, 0x38, 0x32, 0x24, 0x00, 0x00, 0x00 },
266 /* 19CD */
267 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x8c, 0x8a, 0x89, 0x8b, 0x8b,
268 0x8b, 0x87, 0x89, 0x89, 0x86, 0x86, 0x89, 0x84, 0x84, 0x87, 0x77,
269 0x72, 0x88, 0x65, 0x6f, 0x8e, 0x38, 0x32, 0x24, 0x00, 0x00, 0x00 },
270 /* 20CD */
271 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x8c, 0x8a, 0x89, 0x8b, 0x8b,
272 0x8b, 0x88, 0x89, 0x89, 0x85, 0x85, 0x88, 0x82, 0x83, 0x85, 0x79,
273 0x73, 0x88, 0x65, 0x6f, 0x8e, 0x38, 0x32, 0x24, 0x00, 0x00, 0x00 },
274 /* 21CD */
275 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x8c, 0x8a, 0x89, 0x8b, 0x8b,
276 0x8b, 0x88, 0x89, 0x89, 0x85, 0x85, 0x88, 0x82, 0x83, 0x85, 0x79,
277 0x74, 0x88, 0x65, 0x6f, 0x8e, 0x38, 0x32, 0x24, 0x00, 0x00, 0x00 },
278 /* 22CD */
279 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x8c, 0x8a, 0x89, 0x8c, 0x8b,
280 0x8c, 0x86, 0x88, 0x87, 0x86, 0x86, 0x89, 0x82, 0x83, 0x85, 0x7c,
281 0x75, 0x87, 0x65, 0x6f, 0x8e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
282 /* 24CD */
283 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x8c, 0x8a, 0x89, 0x8c, 0x8b,
284 0x8c, 0x86, 0x88, 0x87, 0x86, 0x86, 0x89, 0x82, 0x83, 0x85, 0x7c,
285 0x76, 0x86, 0x66, 0x6f, 0x8e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
286 /* 25CD */
287 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x8c, 0x8a, 0x89, 0x8b, 0x8b,
288 0x8b, 0x86, 0x89, 0x88, 0x87, 0x87, 0x89, 0x82, 0x82, 0x84, 0x7f,
289 0x7a, 0x89, 0x6b, 0x73, 0x8f, 0x33, 0x2f, 0x22, 0x00, 0x00, 0x00 },
290 /* 27CD */
291 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x8c, 0x8a, 0x89, 0x8b, 0x8b,
292 0x8b, 0x86, 0x89, 0x88, 0x87, 0x87, 0x89, 0x82, 0x82, 0x84, 0x7f,
293 0x7a, 0x89, 0x6b, 0x73, 0x8f, 0x33, 0x2f, 0x22, 0x00, 0x00, 0x00 },
294 /* 29CD */
295 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x8c, 0x8a, 0x89, 0x8b, 0x8b,
296 0x8b, 0x86, 0x89, 0x88, 0x85, 0x84, 0x87, 0x84, 0x85, 0x86, 0x80,
297 0x7b, 0x88, 0x6a, 0x73, 0x8f, 0x33, 0x2f, 0x22, 0x00, 0x00, 0x00 },
298 /* 30CD */
299 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x8c, 0x8a, 0x89, 0x8b, 0x8b,
300 0x8b, 0x86, 0x89, 0x88, 0x85, 0x84, 0x87, 0x84, 0x85, 0x86, 0x80,
301 0x7b, 0x88, 0x6a, 0x73, 0x8f, 0x33, 0x2f, 0x22, 0x00, 0x00, 0x00 },
302 /* 32CD */
303 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x8c, 0x8a, 0x89, 0x8b, 0x8b,
304 0x8b, 0x86, 0x89, 0x88, 0x85, 0x84, 0x87, 0x84, 0x85, 0x86, 0x80,
305 0x7b, 0x88, 0x6a, 0x73, 0x8f, 0x33, 0x2f, 0x22, 0x00, 0x00, 0x00 },
306 /* 34CD */
307 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x8c, 0x8a, 0x89, 0x8b, 0x8b,
308 0x8b, 0x86, 0x89, 0x88, 0x85, 0x84, 0x87, 0x83, 0x84, 0x84, 0x7f,
309 0x79, 0x86, 0x6c, 0x76, 0x91, 0x33, 0x2f, 0x22, 0x00, 0x00, 0x00 },
310 /* 37CD */
311 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x8b, 0x89, 0x89, 0x8b, 0x8b,
312 0x8b, 0x86, 0x88, 0x88, 0x87, 0x86, 0x87, 0x83, 0x84, 0x84, 0x7f,
313 0x79, 0x86, 0x6c, 0x76, 0x90, 0x33, 0x2f, 0x22, 0x00, 0x00, 0x00 },
314 /* 39CD */
315 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x8b, 0x89, 0x89, 0x8b, 0x8b,
316 0x8b, 0x86, 0x88, 0x87, 0x84, 0x84, 0x86, 0x83, 0x85, 0x85, 0x80,
317 0x79, 0x85, 0x6c, 0x76, 0x90, 0x33, 0x2f, 0x22, 0x00, 0x00, 0x00 },
318 /* 41CD */
319 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x8b, 0x89, 0x89, 0x8b, 0x8b,
320 0x8b, 0x86, 0x88, 0x87, 0x84, 0x84, 0x86, 0x81, 0x84, 0x83, 0x7f,
321 0x79, 0x84, 0x6e, 0x79, 0x93, 0x33, 0x2f, 0x22, 0x00, 0x00, 0x00 },
322 /* 44CD */
323 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x8b, 0x89, 0x89, 0x8b, 0x8b,
324 0x8b, 0x86, 0x88, 0x87, 0x84, 0x84, 0x86, 0x81, 0x84, 0x83, 0x7f,
325 0x79, 0x84, 0x6e, 0x79, 0x92, 0x33, 0x2f, 0x22, 0x00, 0x00, 0x00 },
326 /* 47CD */
327 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x8b, 0x89, 0x89, 0x8b, 0x8b,
328 0x8b, 0x86, 0x88, 0x87, 0x84, 0x85, 0x86, 0x81, 0x84, 0x83, 0x7f,
329 0x79, 0x83, 0x6f, 0x79, 0x91, 0x33, 0x2f, 0x22, 0x00, 0x00, 0x00 },
330 /* 50CD */
331 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x8b, 0x89, 0x89, 0x8b, 0x8b,
332 0x8b, 0x86, 0x88, 0x87, 0x84, 0x85, 0x86, 0x82, 0x84, 0x83, 0x7f,
333 0x79, 0x83, 0x6f, 0x79, 0x90, 0x33, 0x2f, 0x22, 0x00, 0x00, 0x00 },
334 /* 53CD */
335 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x8b, 0x89, 0x89, 0x8b, 0x8b,
336 0x8b, 0x86, 0x88, 0x87, 0x83, 0x83, 0x85, 0x84, 0x85, 0x85, 0x7f,
337 0x79, 0x83, 0x70, 0x79, 0x8f, 0x33, 0x2f, 0x22, 0x00, 0x00, 0x00 },
338 /* 56CD */
339 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x8b, 0x89, 0x89, 0x8b, 0x8a,
340 0x8a, 0x87, 0x89, 0x87, 0x83, 0x83, 0x85, 0x84, 0x85, 0x84, 0x7f,
341 0x79, 0x82, 0x70, 0x7a, 0x8e, 0x33, 0x2f, 0x22, 0x00, 0x00, 0x00 },
342 /* 60CD */
343 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x8b, 0x89, 0x89, 0x8b, 0x8a,
344 0x8a, 0x87, 0x89, 0x87, 0x83, 0x83, 0x85, 0x84, 0x85, 0x84, 0x7e,
345 0x79, 0x82, 0x71, 0x7a, 0x8d, 0x33, 0x2f, 0x22, 0x00, 0x00, 0x00 },
346 /* 64CD */
347 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x8b, 0x89, 0x89, 0x8b, 0x8a,
348 0x8a, 0x86, 0x88, 0x86, 0x84, 0x84, 0x86, 0x82, 0x83, 0x82, 0x80,
349 0x7a, 0x84, 0x71, 0x7a, 0x8c, 0x33, 0x2f, 0x22, 0x00, 0x00, 0x00 },
350 /* 68CD */
351 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x8a, 0x89, 0x89, 0x8c, 0x8a,
352 0x8a, 0x86, 0x88, 0x86, 0x84, 0x84, 0x86, 0x82, 0x84, 0x82, 0x81,
353 0x7b, 0x83, 0x72, 0x7b, 0x8b, 0x33, 0x2f, 0x22, 0x00, 0x00, 0x00 },
354 /* 72CD */
355 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x8a, 0x89, 0x89, 0x8c, 0x8a,
356 0x8a, 0x86, 0x88, 0x86, 0x85, 0x85, 0x86, 0x82, 0x84, 0x82, 0x81,
357 0x7b, 0x83, 0x72, 0x7c, 0x8a, 0x33, 0x2f, 0x22, 0x00, 0x00, 0x00 },
358 /* 77CD */
359 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x8a, 0x89, 0x89, 0x8c, 0x8a,
360 0x8a, 0x85, 0x87, 0x85, 0x85, 0x87, 0x87, 0x82, 0x84, 0x82, 0x81,
361 0x7c, 0x82, 0x72, 0x7c, 0x89, 0x33, 0x2f, 0x22, 0x00, 0x00, 0x00 },
362 /* 82CD */
363 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x8a, 0x89, 0x89, 0x8c, 0x8a,
364 0x8a, 0x85, 0x87, 0x85, 0x85, 0x87, 0x87, 0x82, 0x84, 0x82, 0x81,
365 0x7c, 0x82, 0x73, 0x7c, 0x88, 0x33, 0x2f, 0x22, 0x00, 0x00, 0x00 },
366 /* 87CD */
367 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x8a, 0x89, 0x89, 0x8c, 0x8a,
368 0x8a, 0x85, 0x87, 0x85, 0x84, 0x84, 0x86, 0x80, 0x84, 0x81, 0x80,
369 0x7a, 0x82, 0x76, 0x7f, 0x89, 0x33, 0x2f, 0x22, 0x00, 0x00, 0x00 },
370 /* 93CD */
371 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x8a, 0x89, 0x89, 0x8b, 0x8a,
372 0x8a, 0x86, 0x87, 0x85, 0x84, 0x85, 0x86, 0x80, 0x84, 0x80, 0x80,
373 0x7a, 0x82, 0x76, 0x80, 0x88, 0x33, 0x2f, 0x22, 0x00, 0x00, 0x00 },
374 /* 98CD */
375 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x8a, 0x89, 0x89, 0x8b, 0x8a,
376 0x8a, 0x86, 0x87, 0x85, 0x85, 0x85, 0x86, 0x80, 0x84, 0x80, 0x80,
377 0x7a, 0x82, 0x76, 0x80, 0x88, 0x33, 0x2f, 0x22, 0x00, 0x00, 0x00 },
378 /* 105CD */
379 { 0x00, 0xc8, 0x00, 0xc4, 0x00, 0xc5, 0x89, 0x88, 0x88, 0x8b, 0x8a,
380 0x8a, 0x84, 0x87, 0x85, 0x85, 0x85, 0x85, 0x80, 0x84, 0x80, 0x7f,
381 0x79, 0x81, 0x71, 0x7d, 0x87, 0x38, 0x32, 0x24, 0x00, 0x00, 0x00 },
382 /* 111CD */
383 { 0x00, 0xdf, 0x00, 0xde, 0x00, 0xde, 0x85, 0x85, 0x84, 0x87, 0x86,
384 0x87, 0x85, 0x86, 0x85, 0x83, 0x83, 0x83, 0x81, 0x82, 0x82, 0x80,
385 0x7d, 0x82, 0x75, 0x7f, 0x86, 0x85, 0x85, 0x82, 0x00, 0x00, 0x00 },
386 /* 119CD */
387 { 0x00, 0xe3, 0x00, 0xe1, 0x00, 0xe2, 0x85, 0x85, 0x84, 0x86, 0x85,
388 0x85, 0x84, 0x85, 0x84, 0x83, 0x83, 0x83, 0x82, 0x82, 0x82, 0x7e,
389 0x7b, 0x81, 0x75, 0x7f, 0x86, 0x85, 0x85, 0x82, 0x00, 0x00, 0x00 },
390 /* 126CD */
391 { 0x00, 0xe6, 0x00, 0xe5, 0x00, 0xe5, 0x85, 0x84, 0x84, 0x85, 0x85,
392 0x85, 0x84, 0x84, 0x84, 0x82, 0x83, 0x83, 0x80, 0x81, 0x81, 0x80,
393 0x7f, 0x83, 0x73, 0x7c, 0x84, 0x85, 0x85, 0x82, 0x00, 0x00, 0x00 },
394 /* 134CD */
395 { 0x00, 0xe9, 0x00, 0xe8, 0x00, 0xe8, 0x84, 0x84, 0x83, 0x85, 0x85,
396 0x85, 0x84, 0x84, 0x83, 0x81, 0x82, 0x82, 0x81, 0x81, 0x81, 0x7f,
397 0x7d, 0x81, 0x73, 0x7c, 0x83, 0x85, 0x85, 0x82, 0x00, 0x00, 0x00 },
398 /* 143CD */
399 { 0x00, 0xed, 0x00, 0xec, 0x00, 0xec, 0x84, 0x83, 0x83, 0x84, 0x84,
400 0x84, 0x84, 0x84, 0x83, 0x82, 0x83, 0x83, 0x81, 0x80, 0x81, 0x7f,
401 0x7e, 0x81, 0x70, 0x79, 0x81, 0x85, 0x85, 0x82, 0x00, 0x00, 0x00 },
402 /* 152CD */
403 { 0x00, 0xf0, 0x00, 0xf0, 0x00, 0xf0, 0x83, 0x83, 0x83, 0x83, 0x83,
404 0x83, 0x84, 0x84, 0x83, 0x81, 0x81, 0x81, 0x80, 0x80, 0x81, 0x80,
405 0x80, 0x82, 0x6f, 0x78, 0x7f, 0x85, 0x85, 0x82, 0x00, 0x00, 0x00 },
406 /* 162CD */
407 { 0x00, 0xf4, 0x00, 0xf3, 0x00, 0xf4, 0x83, 0x83, 0x83, 0x83, 0x83,
408 0x83, 0x82, 0x81, 0x81, 0x81, 0x81, 0x81, 0x80, 0x80, 0x81, 0x80,
409 0x7f, 0x82, 0x6f, 0x78, 0x7f, 0x85, 0x85, 0x82, 0x00, 0x00, 0x00 },
410 /* 172CD */
411 { 0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8, 0x82, 0x82, 0x82, 0x82, 0x82,
412 0x82, 0x82, 0x81, 0x81, 0x80, 0x81, 0x80, 0x80, 0x80, 0x81, 0x81,
413 0x80, 0x83, 0x6d, 0x76, 0x7d, 0x85, 0x85, 0x82, 0x00, 0x00, 0x00 },
414 /* 183CD */
415 { 0x00, 0xe0, 0x00, 0xdf, 0x00, 0xdf, 0x84, 0x84, 0x83, 0x86, 0x86,
416 0x86, 0x83, 0x84, 0x83, 0x82, 0x82, 0x82, 0x81, 0x83, 0x81, 0x81,
417 0x7e, 0x81, 0x80, 0x82, 0x84, 0x85, 0x85, 0x82, 0x00, 0x00, 0x00 },
418 /* 195CD */
419 { 0x00, 0xe4, 0x00, 0xe3, 0x00, 0xe3, 0x84, 0x83, 0x83, 0x85, 0x85,
420 0x85, 0x83, 0x84, 0x83, 0x81, 0x82, 0x82, 0x82, 0x83, 0x81, 0x81,
421 0x80, 0x82, 0x7d, 0x7f, 0x81, 0x85, 0x85, 0x82, 0x00, 0x00, 0x00 },
422 /* 207CD */
423 { 0x00, 0xe7, 0x00, 0xe6, 0x00, 0xe6, 0x83, 0x82, 0x82, 0x85, 0x85,
424 0x85, 0x82, 0x83, 0x83, 0x82, 0x82, 0x82, 0x80, 0x81, 0x80, 0x81,
425 0x80, 0x82, 0x7d, 0x7f, 0x81, 0x85, 0x85, 0x82, 0x00, 0x00, 0x00 },
426 /* 220CD */
427 { 0x00, 0xeb, 0x00, 0xea, 0x00, 0xea, 0x83, 0x83, 0x82, 0x84, 0x84,
428 0x84, 0x82, 0x83, 0x82, 0x81, 0x81, 0x82, 0x81, 0x82, 0x81, 0x80,
429 0x7e, 0x80, 0x7d, 0x7f, 0x81, 0x85, 0x85, 0x82, 0x00, 0x00, 0x00 },
430 /* 234CD */
431 { 0x00, 0xef, 0x00, 0xee, 0x00, 0xee, 0x83, 0x82, 0x82, 0x83, 0x83,
432 0x83, 0x82, 0x82, 0x82, 0x81, 0x81, 0x81, 0x80, 0x80, 0x80, 0x80,
433 0x80, 0x81, 0x7b, 0x7c, 0x7f, 0x85, 0x85, 0x82, 0x00, 0x00, 0x00 },
434 /* 249CD */
435 { 0x00, 0xf3, 0x00, 0xf2, 0x00, 0xf2, 0x82, 0x81, 0x81, 0x83, 0x83,
436 0x83, 0x82, 0x82, 0x82, 0x81, 0x81, 0x81, 0x80, 0x81, 0x80, 0x7f,
437 0x7e, 0x7f, 0x7b, 0x7c, 0x7f, 0x85, 0x85, 0x82, 0x00, 0x00, 0x00 },
438 /* 265CD */
439 { 0x00, 0xf7, 0x00, 0xf7, 0x00, 0xf7, 0x81, 0x81, 0x80, 0x82, 0x82,
440 0x82, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x81, 0x80, 0x7f,
441 0x7e, 0x7f, 0x7b, 0x7c, 0x7f, 0x85, 0x85, 0x82, 0x00, 0x00, 0x00 },
442 /* 282CD */
443 { 0x00, 0xfb, 0x00, 0xfb, 0x00, 0xfb, 0x80, 0x80, 0x80, 0x81, 0x81,
444 0x81, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x7f, 0x7f, 0x7f, 0x7f,
445 0x7f, 0x7f, 0x78, 0x79, 0x7d, 0x85, 0x85, 0x82, 0x00, 0x00, 0x00 },
446 /* 300CD */
447 { 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80,
448 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
449 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00 },
450 };
451
s6e88a0_ams427ap24_set_brightness(struct backlight_device * bd)452 static int s6e88a0_ams427ap24_set_brightness(struct backlight_device *bd)
453 {
454 struct s6e88a0_ams427ap24 *ctx = bl_get_data(bd);
455 struct mipi_dsi_device *dsi = ctx->dsi;
456 struct mipi_dsi_multi_context dsi_ctx = { .dsi = dsi };
457 struct device *dev = &dsi->dev;
458 int brightness = bd->props.brightness;
459 int candela_enum;
460 u8 b2[LEN_AID] = { 0xb2, 0x40, 0x08, 0x20, 0x00, 0x00 };
461 u8 b6[LEN_ELVSS] = { 0xb6, 0x28, 0x00 };
462 u8 ca[LEN_GAMMA];
463
464 /* get candela enum from brightness */
465 for (candela_enum = 0; candela_enum < NUM_STEPS_CANDELA; candela_enum++)
466 if (brightness <= s6e88a0_ams427ap24_br_to_cd[candela_enum])
467 break;
468
469 /* get aid */
470 switch (candela_enum) {
471 case CANDELA_10CD ... CANDELA_105CD:
472 memcpy(&b2[FIX_LEN_AID],
473 s6e88a0_ams427ap24_aid[candela_enum],
474 VAR_LEN_AID);
475 break;
476 case CANDELA_111CD ... CANDELA_172CD:
477 memcpy(&b2[FIX_LEN_AID],
478 s6e88a0_ams427ap24_aid[CANDELA_111CD],
479 VAR_LEN_AID);
480 break;
481 case CANDELA_183CD ... CANDELA_300CD:
482 memcpy(&b2[FIX_LEN_AID],
483 s6e88a0_ams427ap24_aid[CANDELA_111CD + 1],
484 VAR_LEN_AID);
485 break;
486 default:
487 dev_err(dev, "Failed to get aid data\n");
488 return -EINVAL;
489 }
490
491 /* get elvss */
492 if (candela_enum <= CANDELA_111CD) {
493 memcpy(&b6[FIX_LEN_ELVSS],
494 s6e88a0_ams427ap24_elvss[0],
495 VAR_LEN_ELVSS);
496 } else {
497 memcpy(&b6[FIX_LEN_ELVSS],
498 s6e88a0_ams427ap24_elvss[candela_enum - CANDELA_111CD],
499 VAR_LEN_ELVSS);
500 }
501
502 /* get gamma */
503 ca[0] = 0xca;
504 memcpy(&ca[FIX_LEN_GAMMA],
505 s6e88a0_ams427ap24_gamma[candela_enum],
506 VAR_LEN_GAMMA);
507
508 /* write data */
509 mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xf0, 0x5a, 0x5a); // level 1 key on
510 mipi_dsi_dcs_write_buffer_multi(&dsi_ctx, b2, ARRAY_SIZE(b2)); // set aid
511 mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0x55, 0x00); // acl off
512 mipi_dsi_dcs_write_buffer_multi(&dsi_ctx, b6, ARRAY_SIZE(b6)); // set elvss
513 mipi_dsi_dcs_write_buffer_multi(&dsi_ctx, ca, ARRAY_SIZE(ca)); // set gamma
514 mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xf7, 0x03); // gamma update
515 mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xf0, 0xa5, 0xa5); // level 1 key off
516
517 return dsi_ctx.accum_err;
518 }
519
s6e88a0_ams427ap24_reset(struct s6e88a0_ams427ap24 * ctx)520 static void s6e88a0_ams427ap24_reset(struct s6e88a0_ams427ap24 *ctx)
521 {
522 gpiod_set_value_cansleep(ctx->reset_gpio, 0);
523 usleep_range(5000, 6000);
524 gpiod_set_value_cansleep(ctx->reset_gpio, 1);
525 usleep_range(1000, 2000);
526 gpiod_set_value_cansleep(ctx->reset_gpio, 0);
527 usleep_range(18000, 19000);
528 }
529
s6e88a0_ams427ap24_on(struct s6e88a0_ams427ap24 * ctx)530 static int s6e88a0_ams427ap24_on(struct s6e88a0_ams427ap24 *ctx)
531 {
532 struct mipi_dsi_device *dsi = ctx->dsi;
533 struct mipi_dsi_multi_context dsi_ctx = { .dsi = dsi };
534 struct device *dev = &dsi->dev;
535 int ret;
536
537 dsi->mode_flags |= MIPI_DSI_MODE_LPM;
538
539 mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xf0, 0x5a, 0x5a); // level 1 key on
540 mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xfc, 0x5a, 0x5a); // level 2 key on
541 mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xb0, 0x11); // src latch set global 1
542 mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xfd, 0x11); // src latch set 1
543 mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xb0, 0x13); // src latch set global 2
544 mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xfd, 0x18); // src latch set 2
545 mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xb0, 0x02); // avdd set 1
546 mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xb8, 0x30); // avdd set 2
547
548 mipi_dsi_dcs_exit_sleep_mode_multi(&dsi_ctx);
549 mipi_dsi_msleep(&dsi_ctx, 20);
550
551 mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xf1, 0x5a, 0x5a); // level 3 key on
552 mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xcc, 0x4c); // pixel clock divider pol.
553 mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xf2, 0x03, 0x0d); // unknown
554 mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xf1, 0xa5, 0xa5); // level 3 key off
555
556 if (ctx->flip_horizontal)
557 mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xcb, 0x0e); // flip display
558
559 mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xf0, 0xa5, 0xa5); // level 1 key off
560 mipi_dsi_dcs_write_seq_multi(&dsi_ctx, 0xfc, 0xa5, 0xa5); // level 2 key off
561
562 ret = s6e88a0_ams427ap24_set_brightness(ctx->bl_dev);
563 if (ret < 0) {
564 dev_err(dev, "Failed to set brightness: %d\n", ret);
565 return ret;
566 }
567
568 mipi_dsi_dcs_set_display_on_multi(&dsi_ctx);
569
570 return dsi_ctx.accum_err;
571 }
572
s6e88a0_ams427ap24_off(struct s6e88a0_ams427ap24 * ctx)573 static int s6e88a0_ams427ap24_off(struct s6e88a0_ams427ap24 *ctx)
574 {
575 struct mipi_dsi_device *dsi = ctx->dsi;
576 struct mipi_dsi_multi_context dsi_ctx = { .dsi = dsi };
577
578 dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;
579
580 mipi_dsi_dcs_set_display_off_multi(&dsi_ctx);
581 mipi_dsi_dcs_enter_sleep_mode_multi(&dsi_ctx);
582 mipi_dsi_msleep(&dsi_ctx, 120);
583
584 return dsi_ctx.accum_err;
585 }
586
s6e88a0_ams427ap24_prepare(struct drm_panel * panel)587 static int s6e88a0_ams427ap24_prepare(struct drm_panel *panel)
588 {
589 struct s6e88a0_ams427ap24 *ctx = to_s6e88a0_ams427ap24(panel);
590 struct device *dev = &ctx->dsi->dev;
591 int ret;
592
593 ret = regulator_bulk_enable(ARRAY_SIZE(s6e88a0_ams427ap24_supplies),
594 ctx->supplies);
595 if (ret < 0) {
596 dev_err(dev, "Failed to enable regulators: %d\n", ret);
597 return ret;
598 }
599
600 s6e88a0_ams427ap24_reset(ctx);
601
602 ret = s6e88a0_ams427ap24_on(ctx);
603 if (ret < 0) {
604 dev_err(dev, "Failed to initialize panel: %d\n", ret);
605 gpiod_set_value_cansleep(ctx->reset_gpio, 1);
606 regulator_bulk_disable(ARRAY_SIZE(s6e88a0_ams427ap24_supplies),
607 ctx->supplies);
608 return ret;
609 }
610
611 return 0;
612 }
613
s6e88a0_ams427ap24_unprepare(struct drm_panel * panel)614 static int s6e88a0_ams427ap24_unprepare(struct drm_panel *panel)
615 {
616 struct s6e88a0_ams427ap24 *ctx = to_s6e88a0_ams427ap24(panel);
617 struct device *dev = &ctx->dsi->dev;
618 int ret;
619
620 ret = s6e88a0_ams427ap24_off(ctx);
621 if (ret < 0)
622 dev_err(dev, "Failed to un-initialize panel: %d\n", ret);
623
624 gpiod_set_value_cansleep(ctx->reset_gpio, 1);
625 regulator_bulk_disable(ARRAY_SIZE(s6e88a0_ams427ap24_supplies),
626 ctx->supplies);
627
628 return 0;
629 }
630
631 static const struct drm_display_mode s6e88a0_ams427ap24_mode = {
632 .clock = (540 + 94 + 4 + 18) * (960 + 12 + 1 + 3) * 60 / 1000,
633 .hdisplay = 540,
634 .hsync_start = 540 + 94,
635 .hsync_end = 540 + 94 + 4,
636 .htotal = 540 + 94 + 4 + 18,
637 .vdisplay = 960,
638 .vsync_start = 960 + 12,
639 .vsync_end = 960 + 12 + 1,
640 .vtotal = 960 + 12 + 1 + 3,
641 .width_mm = 55,
642 .height_mm = 95,
643 .type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED,
644 };
645
s6e88a0_ams427ap24_get_modes(struct drm_panel * panel,struct drm_connector * connector)646 static int s6e88a0_ams427ap24_get_modes(struct drm_panel *panel,
647 struct drm_connector *connector)
648 {
649 return drm_connector_helper_get_modes_fixed(connector,
650 &s6e88a0_ams427ap24_mode);
651 }
652
653 static const struct drm_panel_funcs s6e88a0_ams427ap24_panel_funcs = {
654 .prepare = s6e88a0_ams427ap24_prepare,
655 .unprepare = s6e88a0_ams427ap24_unprepare,
656 .get_modes = s6e88a0_ams427ap24_get_modes,
657 };
658
659 static const struct backlight_ops s6e88a0_ams427ap24_bl_ops = {
660 .update_status = s6e88a0_ams427ap24_set_brightness,
661 };
662
s6e88a0_ams427ap24_register_backlight(struct s6e88a0_ams427ap24 * ctx)663 static int s6e88a0_ams427ap24_register_backlight(struct s6e88a0_ams427ap24 *ctx)
664 {
665 struct backlight_properties props = {
666 .type = BACKLIGHT_RAW,
667 .brightness = 180,
668 .max_brightness = 255,
669 };
670 struct mipi_dsi_device *dsi = ctx->dsi;
671 struct device *dev = &dsi->dev;
672 int ret = 0;
673
674 ctx->bl_dev = devm_backlight_device_register(dev, dev_name(dev), dev, ctx,
675 &s6e88a0_ams427ap24_bl_ops,
676 &props);
677 if (IS_ERR(ctx->bl_dev)) {
678 ret = PTR_ERR(ctx->bl_dev);
679 dev_err(dev, "error registering backlight device (%d)\n", ret);
680 }
681
682 return ret;
683 }
684
s6e88a0_ams427ap24_probe(struct mipi_dsi_device * dsi)685 static int s6e88a0_ams427ap24_probe(struct mipi_dsi_device *dsi)
686 {
687 struct device *dev = &dsi->dev;
688 struct s6e88a0_ams427ap24 *ctx;
689 int ret;
690
691 ctx = devm_drm_panel_alloc(dev, struct s6e88a0_ams427ap24, panel,
692 &s6e88a0_ams427ap24_panel_funcs,
693 DRM_MODE_CONNECTOR_DSI);
694 if (IS_ERR(ctx))
695 return PTR_ERR(ctx);
696
697 ret = devm_regulator_bulk_get_const(dev,
698 ARRAY_SIZE(s6e88a0_ams427ap24_supplies),
699 s6e88a0_ams427ap24_supplies,
700 &ctx->supplies);
701 if (ret < 0)
702 return ret;
703
704 ctx->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
705 if (IS_ERR(ctx->reset_gpio))
706 return dev_err_probe(dev, PTR_ERR(ctx->reset_gpio),
707 "Failed to get reset-gpios\n");
708
709 ctx->dsi = dsi;
710 mipi_dsi_set_drvdata(dsi, ctx);
711
712 dsi->lanes = 2;
713 dsi->format = MIPI_DSI_FMT_RGB888;
714 dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST |
715 MIPI_DSI_MODE_NO_EOT_PACKET | MIPI_DSI_MODE_VIDEO_NO_HFP;
716
717 ctx->panel.prepare_prev_first = true;
718
719 ctx->flip_horizontal = device_property_read_bool(dev, "flip-horizontal");
720
721 ret = s6e88a0_ams427ap24_register_backlight(ctx);
722 if (ret < 0)
723 return ret;
724
725 drm_panel_add(&ctx->panel);
726
727 ret = mipi_dsi_attach(dsi);
728 if (ret < 0) {
729 dev_err(dev, "Failed to attach to DSI host: %d\n", ret);
730 drm_panel_remove(&ctx->panel);
731 return ret;
732 }
733
734 return 0;
735 }
736
s6e88a0_ams427ap24_remove(struct mipi_dsi_device * dsi)737 static void s6e88a0_ams427ap24_remove(struct mipi_dsi_device *dsi)
738 {
739 struct s6e88a0_ams427ap24 *ctx = mipi_dsi_get_drvdata(dsi);
740 int ret;
741
742 ret = mipi_dsi_detach(dsi);
743 if (ret < 0)
744 dev_err(&dsi->dev, "Failed to detach from DSI host: %d\n", ret);
745
746 drm_panel_remove(&ctx->panel);
747 }
748
749 static const struct of_device_id s6e88a0_ams427ap24_of_match[] = {
750 { .compatible = "samsung,s6e88a0-ams427ap24" },
751 { /* sentinel */ },
752 };
753 MODULE_DEVICE_TABLE(of, s6e88a0_ams427ap24_of_match);
754
755 static struct mipi_dsi_driver s6e88a0_ams427ap24_driver = {
756 .probe = s6e88a0_ams427ap24_probe,
757 .remove = s6e88a0_ams427ap24_remove,
758 .driver = {
759 .name = "panel-s6e88a0-ams427ap24",
760 .of_match_table = s6e88a0_ams427ap24_of_match,
761 },
762 };
763 module_mipi_dsi_driver(s6e88a0_ams427ap24_driver);
764
765 MODULE_AUTHOR("Jakob Hauser <jahau@rocketmail.com>");
766 MODULE_DESCRIPTION("Samsung AMS427AP24 panel with S6E88A0 controller");
767 MODULE_LICENSE("GPL v2");
768