1 /*
2 * Copyright 2019-2021 NXP
3 * All rights reserved.
4 *
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9 #include "fsl_display.h"
10 #include "fsl_rm68200.h"
11
12 /*******************************************************************************
13 * Definitions
14 ******************************************************************************/
15 #define RM68200_DelayMs VIDEO_DelayMs
16
17 /*******************************************************************************
18 * Variables
19 ******************************************************************************/
20
21 uint8_t RM68200_DDB_START[5] = {0x00, 0x00, 0x00, 0x00, 0xff};
22
23 static const uint8_t lcmInitPage0Setting[][2] = {
24 {0xFE, 0x01}, {0x24, 0xC0}, {0x25, 0x53}, {0x26, 0x00}, {0x2B, 0xE5}, {0x27, 0x0A},
25 {0x29, 0x0A}, {0x16, 0x52}, {0x2F, 0x53}, {0x34, 0x5A}, {0x1B, 0x00}, {0x12, 0x0A},
26 {0x1A, 0x06}, {0x46, 0x56}, {0x52, 0xA0}, {0x53, 0x00}, {0x54, 0xA0}, {0x55, 0x00},
27 };
28
29 static const uint8_t lcmInitSetting[][2] = {
30 {0xFE, 0x03},
31 {0x00, 0x05},
32 {0x02, 0x0B},
33 {0x03, 0x0F},
34 {0x04, 0x7D},
35 {0x05, 0x00},
36 {0x06, 0x50},
37 {0x07, 0x05},
38 {0x08, 0x16},
39 {0x09, 0x0D},
40 {0x0A, 0x11},
41 {0x0B, 0x7D},
42 {0x0C, 0x00},
43 {0x0D, 0x50},
44 {0x0E, 0x07},
45 {0x0F, 0x08},
46 {0x10, 0x01},
47 {0x11, 0x02},
48 {0x12, 0x00},
49 {0x13, 0x7D},
50 {0x14, 0x00},
51 {0x15, 0x85},
52 {0x16, 0x08},
53 {0x17, 0x03},
54 {0x18, 0x04},
55 {0x19, 0x05},
56 {0x1A, 0x06},
57 {0x1B, 0x00},
58 {0x1C, 0x7D},
59 {0x1D, 0x00},
60 {0x1E, 0x85},
61 {0x1F, 0x08},
62 {0x20, 0x00},
63 {0x21, 0x00},
64 {0x22, 0x00},
65 {0x23, 0x00},
66 {0x24, 0x00},
67 {0x25, 0x00},
68 {0x26, 0x00},
69 {0x27, 0x00},
70 {0x28, 0x00},
71 {0x29, 0x00},
72 {0x2A, 0x07},
73 {0x2B, 0x08},
74 {0x2D, 0x01},
75 {0x2F, 0x02},
76 {0x30, 0x00},
77 {0x31, 0x40},
78 {0x32, 0x05},
79 {0x33, 0x08},
80 {0x34, 0x54},
81 {0x35, 0x7D},
82 {0x36, 0x00},
83 {0x37, 0x03},
84 {0x38, 0x04},
85 {0x39, 0x05},
86 {0x3A, 0x06},
87 {0x3B, 0x00},
88 {0x3D, 0x40},
89 {0x3F, 0x05},
90 {0x40, 0x08},
91 {0x41, 0x54},
92 {0x42, 0x7D},
93 {0x43, 0x00},
94 {0x44, 0x00},
95 {0x45, 0x00},
96 {0x46, 0x00},
97 {0x47, 0x00},
98 {0x48, 0x00},
99 {0x49, 0x00},
100 {0x4A, 0x00},
101 {0x4B, 0x00},
102 {0x4C, 0x00},
103 {0x4D, 0x00},
104 {0x4E, 0x00},
105 {0x4F, 0x00},
106 {0x50, 0x00},
107 {0x51, 0x00},
108 {0x52, 0x00},
109 {0x53, 0x00},
110 {0x54, 0x00},
111 {0x55, 0x00},
112 {0x56, 0x00},
113 {0x58, 0x00},
114 {0x59, 0x00},
115 {0x5A, 0x00},
116 {0x5B, 0x00},
117 {0x5C, 0x00},
118 {0x5D, 0x00},
119 {0x5E, 0x00},
120 {0x5F, 0x00},
121 {0x60, 0x00},
122 {0x61, 0x00},
123 {0x62, 0x00},
124 {0x63, 0x00},
125 {0x64, 0x00},
126 {0x65, 0x00},
127 {0x66, 0x00},
128 {0x67, 0x00},
129 {0x68, 0x00},
130 {0x69, 0x00},
131 {0x6A, 0x00},
132 {0x6B, 0x00},
133 {0x6C, 0x00},
134 {0x6D, 0x00},
135 {0x6E, 0x00},
136 {0x6F, 0x00},
137 {0x70, 0x00},
138 {0x71, 0x00},
139 {0x72, 0x20},
140 {0x73, 0x00},
141 {0x74, 0x08},
142 {0x75, 0x08},
143 {0x76, 0x08},
144 {0x77, 0x08},
145 {0x78, 0x08},
146 {0x79, 0x08},
147 {0x7A, 0x00},
148 {0x7B, 0x00},
149 {0x7C, 0x00},
150 {0x7D, 0x00},
151 {0x7E, 0xBF},
152 {0x7F, 0x02},
153 {0x80, 0x06},
154 {0x81, 0x14},
155 {0x82, 0x10},
156 {0x83, 0x16},
157 {0x84, 0x12},
158 {0x85, 0x08},
159 {0x86, 0x3F},
160 {0x87, 0x3F},
161 {0x88, 0x3F},
162 {0x89, 0x3F},
163 {0x8A, 0x3F},
164 {0x8B, 0x0C},
165 {0x8C, 0x0A},
166 {0x8D, 0x0E},
167 {0x8E, 0x3F},
168 {0x8F, 0x3F},
169 {0x90, 0x00},
170 {0x91, 0x04},
171 {0x92, 0x3F},
172 {0x93, 0x3F},
173 {0x94, 0x3F},
174 {0x95, 0x3F},
175 {0x96, 0x05},
176 {0x97, 0x01},
177 {0x98, 0x3F},
178 {0x99, 0x3F},
179 {0x9A, 0x0F},
180 {0x9B, 0x0B},
181 {0x9C, 0x0D},
182 {0x9D, 0x3F},
183 {0x9E, 0x3F},
184 {0x9F, 0x3F},
185 {0xA0, 0x3F},
186 {0xA2, 0x3F},
187 {0xA3, 0x09},
188 {0xA4, 0x13},
189 {0xA5, 0x17},
190 {0xA6, 0x11},
191 {0xA7, 0x15},
192 {0xA9, 0x07},
193 {0xAA, 0x03},
194 {0xAB, 0x3F},
195 {0xAC, 0x3F},
196 {0xAD, 0x05},
197 {0xAE, 0x01},
198 {0xAF, 0x17},
199 {0xB0, 0x13},
200 {0xB1, 0x15},
201 {0xB2, 0x11},
202 {0xB3, 0x0F},
203 {0xB4, 0x3F},
204 {0xB5, 0x3F},
205 {0xB6, 0x3F},
206 {0xB7, 0x3F},
207 {0xB8, 0x3F},
208 {0xB9, 0x0B},
209 {0xBA, 0x0D},
210 {0xBB, 0x09},
211 {0xBC, 0x3F},
212 {0xBD, 0x3F},
213 {0xBE, 0x07},
214 {0xBF, 0x03},
215 {0xC0, 0x3F},
216 {0xC1, 0x3F},
217 {0xC2, 0x3F},
218 {0xC3, 0x3F},
219 {0xC4, 0x02},
220 {0xC5, 0x06},
221 {0xC6, 0x3F},
222 {0xC7, 0x3F},
223 {0xC8, 0x08},
224 {0xC9, 0x0C},
225 {0xCA, 0x0A},
226 {0xCB, 0x3F},
227 {0xCC, 0x3F},
228 {0xCD, 0x3F},
229 {0xCE, 0x3F},
230 {0xCF, 0x3F},
231 {0xD0, 0x0E},
232 {0xD1, 0x10},
233 {0xD2, 0x14},
234 {0xD3, 0x12},
235 {0xD4, 0x16},
236 {0xD5, 0x00},
237 {0xD6, 0x04},
238 {0xD7, 0x3F},
239 {0xDC, 0x02},
240 {0xDE, 0x12},
241 {0xFE, 0x0E},
242 {0x01, 0x75},
243
244 /* Gamma Settings */
245 {0xFE, 0x04},
246 {0x60, 0x00},
247 {0x61, 0x0C},
248 {0x62, 0x12},
249 {0x63, 0x0E},
250 {0x64, 0x06},
251 {0x65, 0x12},
252 {0x66, 0x0E},
253 {0x67, 0x0B},
254 {0x68, 0x15},
255 {0x69, 0x0B},
256 {0x6A, 0x10},
257 {0x6B, 0x07},
258 {0x6C, 0x0F},
259 {0x6D, 0x12},
260 {0x6E, 0x0C},
261 {0x6F, 0x00},
262 {0x70, 0x00},
263 {0x71, 0x0C},
264 {0x72, 0x12},
265 {0x73, 0x0E},
266 {0x74, 0x06},
267 {0x75, 0x12},
268 {0x76, 0x0E},
269 {0x77, 0x0B},
270 {0x78, 0x15},
271 {0x79, 0x0B},
272 {0x7A, 0x10},
273 {0x7B, 0x07},
274 {0x7C, 0x0F},
275 {0x7D, 0x12},
276 {0x7E, 0x0C},
277 {0x7F, 0x00},
278
279 /* Page 0. */
280 {0xFE, 0x00},
281 {0x11, 0x00},
282 };
283
284 const display_operations_t rm68200_ops = {
285 .init = RM68200_Init,
286 .deinit = RM68200_Deinit,
287 .start = RM68200_Start,
288 .stop = RM68200_Stop,
289 };
290
291 /*******************************************************************************
292 * Code
293 ******************************************************************************/
294
RM68200_Init(display_handle_t * handle,const display_config_t * config)295 status_t RM68200_Init(display_handle_t *handle, const display_config_t *config)
296 {
297 uint32_t i;
298 uint8_t param[2];
299 status_t status = kStatus_Success;
300 const rm68200_resource_t *resource = (const rm68200_resource_t *)(handle->resource);
301 mipi_dsi_device_t *dsiDevice = resource->dsiDevice;
302
303 /* Only support 720 * 1280 */
304 if (config->resolution != FSL_VIDEO_RESOLUTION(720, 1280))
305 {
306 return kStatus_InvalidArgument;
307 }
308
309 /* Power on. */
310 resource->pullPowerPin(true);
311 RM68200_DelayMs(1);
312
313 /* Perform reset. */
314 resource->pullResetPin(false);
315 RM68200_DelayMs(1);
316 resource->pullResetPin(true);
317 RM68200_DelayMs(5);
318
319 /* Set the LCM page0 init settings. */
320 for (i = 0; i < ARRAY_SIZE(lcmInitPage0Setting); i++)
321 {
322 status = MIPI_DSI_GenericWrite(dsiDevice, lcmInitPage0Setting[i], 2);
323
324 if (kStatus_Success != status)
325 {
326 return status;
327 }
328 }
329
330 /* Data lane number selection. */
331 param[0] = 0x5FU;
332 param[1] = 0x10U | (config->dsiLanes - 1U);
333 status = MIPI_DSI_GenericWrite(dsiDevice, param, 2);
334 if (kStatus_Success != status)
335 {
336 return status;
337 }
338
339 /* Set the LCM init settings. */
340 for (i = 0; i < ARRAY_SIZE(lcmInitSetting); i++)
341 {
342 status = MIPI_DSI_GenericWrite(dsiDevice, lcmInitSetting[i], 2);
343
344 if (kStatus_Success != status)
345 {
346 return status;
347 }
348 }
349
350 RM68200_DelayMs(200);
351
352 param[0] = 0x29;
353 param[1] = 0x00;
354 status = MIPI_DSI_GenericWrite(dsiDevice, param, 2);
355 if (kStatus_Success != status)
356 {
357 return status;
358 }
359
360 RM68200_DelayMs(100);
361
362 param[0] = 0x2c;
363 status = MIPI_DSI_GenericWrite(dsiDevice, param, 1);
364 if (kStatus_Success != status)
365 {
366 return status;
367 }
368
369 param[0] = 0x35;
370 param[1] = 0x00;
371 status = MIPI_DSI_GenericWrite(dsiDevice, param, 2);
372 if (kStatus_Success != status)
373 {
374 return status;
375 }
376
377 RM68200_DelayMs(200);
378
379 return kStatus_Success;
380 }
381
RM68200_Deinit(display_handle_t * handle)382 status_t RM68200_Deinit(display_handle_t *handle)
383 {
384 const rm68200_resource_t *resource = (const rm68200_resource_t *)(handle->resource);
385 mipi_dsi_device_t *dsiDevice = resource->dsiDevice;
386
387 (void)MIPI_DSI_DCS_EnterSleepMode(dsiDevice, true);
388
389 resource->pullResetPin(false);
390 resource->pullPowerPin(false);
391
392 return kStatus_Success;
393 }
394
RM68200_Start(display_handle_t * handle)395 status_t RM68200_Start(display_handle_t *handle)
396 {
397 const rm68200_resource_t *resource = (const rm68200_resource_t *)(handle->resource);
398 mipi_dsi_device_t *dsiDevice = resource->dsiDevice;
399
400 return MIPI_DSI_DCS_SetDisplayOn(dsiDevice, true);
401 }
402
RM68200_Stop(display_handle_t * handle)403 status_t RM68200_Stop(display_handle_t *handle)
404 {
405 const rm68200_resource_t *resource = (const rm68200_resource_t *)(handle->resource);
406 mipi_dsi_device_t *dsiDevice = resource->dsiDevice;
407
408 return MIPI_DSI_DCS_SetDisplayOn(dsiDevice, false);
409 }
410