blob: 3104dda5635cf16fd8ce47650b3b6b05f780f8e6 [file] [log] [blame]
Fuchsia firmware teamd2ca3282021-02-11 11:07:21 -08001/*
2 * drivers/display/lcd/aml_lcd_unifykey.c
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the named License,
7 * or any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 */
15
16#include <common.h>
17#include <malloc.h>
18#include <asm/arch/gpio.h>
19#ifdef CONFIG_OF_LIBFDT
20#include <libfdt.h>
21#endif
22#include <amlogic/keyunify.h>
23#include <amlogic/aml_lcd.h>
24#include "aml_lcd_reg.h"
25#include "aml_lcd_common.h"
26#ifdef CONFIG_UNIFY_KEY_MANAGE
27#include "aml_lcd_unifykey_tcon.h"
28#endif
29
30#define LCD_UNIFYKEY_TEST
31#define LCDUKEY(fmt, args...) printf("lcd ukey: "fmt"", ## args)
32#define LCDUKEYERR(fmt, args...) printf("lcd ukey err: "fmt"", ## args)
33
34#ifdef CONFIG_UNIFY_KEY_MANAGE
35int aml_lcd_unifykey_len_check(int key_len, int len)
36{
37 if (key_len < len) {
38 LCDUKEYERR("invalid unifykey length %d, need %d\n", key_len, len);
39 return -1;
40 }
41 return 0;
42}
43
44int aml_lcd_unifykey_header_check(unsigned char *buf, struct aml_lcd_unifykey_header_s *header)
45{
46 header->crc32 = (buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24));
47 header->data_len = (buf[4] | (buf[5] << 8));
48 header->version = (buf[6] | (buf[7] << 8));
49 header->reserved = (buf[8] | (buf[9] << 8));
50
51 return 0;
52}
53
54int aml_lcd_unifykey_check(const char *key_name)
55{
56 ssize_t key_size;
57 int key_exist, isSecure, key_len;
58 unsigned char *buf;
59 struct aml_lcd_unifykey_header_s key_header;
60 int retry_cnt = 0;
61 uint32_t key_crc;
62 unsigned int key_crc32;
63 int ret;
64
65 key_size = 0;
66 key_exist = 0;
67 ret = key_unify_query_exist(key_name, &key_exist);
68 if (ret) {
69 if (lcd_debug_print_flag)
70 LCDUKEYERR("%s query exist error\n", key_name);
71 return -1;
72 }
73 if (key_exist == 0) {
74 if (lcd_debug_print_flag)
75 LCDUKEYERR("%s is not exist\n", key_name);
76 return -1;
77 }
78 ret = key_unify_query_secure(key_name, &isSecure);
79 if (ret) {
80 LCDUKEYERR("%s query secure error\n", key_name);
81 return -1;
82 }
83 if (isSecure) {
84 LCDUKEYERR("%s is secure key\n", key_name);
85 return -1;
86 }
87 ret = key_unify_query_size(key_name, &key_size);
88 if (ret) {
89 LCDUKEYERR("%s query size error\n", key_name);
90 return -1;
91 }
92 key_len = (int)key_size;
93 if (key_len == 0) {
94 if (lcd_debug_print_flag)
95 LCDUKEY("%s size is zero\n", key_name);
96 return -1;
97 }
98 if (lcd_debug_print_flag)
99 LCDUKEY("%s size: %d\n", key_name, key_len);
100
101lcd_unifykey_read:
102 buf = (unsigned char *)malloc(sizeof(unsigned char) * key_len);
103 if (!buf) {
104 LCDERR("%s: Not enough memory\n", __func__);
105 return -1;
106 }
107 ret = key_unify_read(key_name, buf, key_len);
108 if (ret) {
109 LCDUKEYERR("%s unify read error\n", key_name);
110 return -1;
111 }
112
113 /* check header */
114 if (key_len <= LCD_UKEY_HEAD_SIZE) {
115 LCDUKEYERR("%s unify key_len %d error\n", key_name, key_len);
116 return -1;
117 }
118 aml_lcd_unifykey_header_check(buf, &key_header);
119 if (key_len != key_header.data_len) { //length check
120 if (lcd_debug_print_flag) {
121 LCDUKEYERR("data_len %d is not match key_len %d\n",
122 key_header.data_len, key_len);
123 }
124 if (retry_cnt < LCD_UKEY_RETRY_CNT_MAX) {
125 retry_cnt++;
126 goto lcd_unifykey_read;
127 } else {
128 LCDUKEYERR("%s: load unifykey failed\n", key_name);
129 return -1;
130 }
131 }
132 key_crc = crc32(0, &buf[4], (key_len - 4)); //except crc32
133 key_crc32 = (unsigned int)key_crc;
134 if (key_crc32 != key_header.crc32) { //crc32 check
135 if (lcd_debug_print_flag) {
136 LCDUKEYERR("crc32 0x%08x is not match 0x%08x\n",
137 key_header.crc32, key_crc32);
138 }
139 if (retry_cnt < LCD_UKEY_RETRY_CNT_MAX) {
140 retry_cnt++;
141 goto lcd_unifykey_read;
142 } else {
143 LCDUKEYERR("%s: load unifykey failed\n", key_name);
144 return -1;
145 }
146 }
147
148 return 0;
149}
150
151int aml_lcd_unifykey_get(const char *key_name, unsigned char *buf, int *len)
152{
153 ssize_t key_size;
154 int key_len;
155 int ret;
156
157 key_size = 0;
158 ret = aml_lcd_unifykey_check(key_name);
159 if (ret)
160 return -1;
161 ret = key_unify_query_size(key_name, &key_size);
162 key_len = (int)key_size;
163 if (key_len > *len) {
164 LCDUKEYERR("%s size(%d) is bigger than buf_size(%d)\n",
165 key_name, key_len, *len);
166 return -1;
167 }
168 *len = key_len;
169
170 ret = key_unify_read(key_name, buf, key_len);
171 if (ret) {
172 LCDUKEYERR("%s unify read error\n", key_name);
173 return -1;
174 }
175 return 0;
176}
177
178int aml_lcd_unifykey_check_no_header(const char *key_name)
179{
180 ssize_t key_size;
181 int key_exist, isSecure, key_len;
182 int ret;
183
184 key_size = 0;
185 key_exist = 0;
186 ret = key_unify_query_exist(key_name, &key_exist);
187 if (ret) {
188 if (lcd_debug_print_flag)
189 LCDUKEYERR("%s query exist error\n", key_name);
190 return -1;
191 }
192 if (key_exist == 0) {
193 if (lcd_debug_print_flag)
194 LCDUKEYERR("%s is not exist\n", key_name);
195 return -1;
196 }
197 ret = key_unify_query_secure(key_name, &isSecure);
198 if (ret) {
199 LCDUKEYERR("%s query secure error\n", key_name);
200 return -1;
201 }
202 if (isSecure) {
203 LCDUKEYERR("%s is secure key\n", key_name);
204 return -1;
205 }
206 ret = key_unify_query_size(key_name, &key_size);
207 if (ret) {
208 LCDUKEYERR("%s query size error\n", key_name);
209 return -1;
210 }
211 key_len = (int)key_size;
212 if (key_len == 0) {
213 if (lcd_debug_print_flag)
214 LCDUKEY("%s size is zero\n", key_name);
215 return -1;
216 }
217 if (lcd_debug_print_flag)
218 LCDUKEY("%s size: %d\n", key_name, key_len);
219
220 return 0;
221}
222
223int aml_lcd_unifykey_get_no_header(const char *key_name, unsigned char *buf, int *len)
224{
225 ssize_t key_size;
226 int key_len;
227 int ret;
228
229 key_size = 0;
230 ret = aml_lcd_unifykey_check_no_header(key_name);
231 if (ret)
232 return -1;
233 ret = key_unify_query_size(key_name, &key_size);
234 key_len = (int)key_size;
235 if (key_len > *len) {
236 LCDUKEYERR("%s size(%d) is bigger than buf_size(%d)\n",
237 key_name, key_len, *len);
238 return -1;
239 }
240 *len = key_len;
241
242 ret = key_unify_read(key_name, buf, key_len);
243 if (ret) {
244 LCDUKEYERR("%s unify read error\n", key_name);
245 return -1;
246 }
247 return 0;
248}
249
250#ifdef LCD_UNIFYKEY_TEST
251static void aml_lcd_test_unifykey(void)
252{
253 int len;
254 unsigned char buf[204];
255 const char *str;
256 int i, n;
257 uint32_t key_crc;
258 unsigned int key_crc32;
259
260 /* basic: 36byte(10~45) */
261 str = "lcd_unifykey_test";
262 n = strlen(str);
263 strcpy((char *)(&buf[10]), str);
264 buf[10+n] = '\0';
265 buf[39] = '\0';
266 buf[40] = 2; /* interface */
267 buf[41] = 10; /* lcd bits */
268 buf[42] = 16; /* screen width bit[7:0] */
269 buf[43] = 0; /* screen width bit[15:8] */
270 buf[44] = 9; /* screen height bit[7:0] */
271 buf[45] = 0; /* screen height bit[15:8] */
272
273 /* timing: 18byte(46~63) */
274 buf[46] = 0x00; /* h active bit[7:0] */ /* 3840 */
275 buf[47] = 0x0f; /* h active bit[15:8] */
276 buf[48] = 0x70; /* v active bit[7:0] */ /* 2160 */
277 buf[49] = 0x08; /* v active bit[15:8] */
278 buf[50] = 0x30; /* h period bit[7:0] */ /* 4400 */
279 buf[51] = 0x11; /* h period bit[15:8] */
280 buf[52] = 0xca; /* v period bit[7:0] */ /* 2250 */
281 buf[53] = 0x08; /* v period bit[15:8] */
282 buf[54] = 33; /* hs width bit[7:0] */
283 buf[55] = 0; /* hs width bit[15:8] */
284 buf[56] = 0xdd; /* hs bp bit[7:0] */ /* 477 */
285 buf[57] = 0x01; /* hs bp bit[15:8] */
286 buf[58] = 0; /* hs pol */
287 buf[59] = 6; /* vs width bit[7:0] */
288 buf[60] = 0; /* vs width bit[15:8] */
289 buf[61] = 65; /* vs bp bit[7:0] */
290 buf[62] = 0; /* vs bp bit[15:8] */
291 buf[63] = 0; /* hs pol */
292
293 /* customer: 31byte(64~94) */
294 buf[64] = 2; /* fr_adj_type */
295 buf[65] = 0; /* ss_level */
296 buf[66] = 1; /* clk_auto_gen */
297 buf[67] = 0; /* pclk bit[7:0] */
298 buf[68] = 0; /* pclk bit[15:8] */
299 buf[69] = 0; /* pclk bit[23:16] */
300 buf[70] = 0; /* pclk bit[31:24] */
301 for (i = 71; i < 95; i++)
302 buf[i] = 0;
303#if 1 /* v2 */
304 /* interface: 20byte(95~114) */
305 buf[95] = 8; /* vx1_lane_count bit[7:0] */
306 buf[96] = 0; /* vx1_lane_count bit[15:8] */
307 buf[97] = 2; /* vx1_region_num bit[7:0] */
308 buf[98] = 0; /* vx1_region_num bit[15:8] */
309 buf[99] = 4; /* vx1_byte_mode bit[7:0] */
310 buf[100] = 0; /* vx1_byte_mode bit[15:8] */
311 buf[101] = 4; /* vx1_color_fmt bit[7:0] */
312 buf[102] = 0; /* vx1_color_fmt bit[15:8] */
313 buf[103] = 1; /* vx1_intr_en bit[7:0] */
314 buf[104] = 0; /* vx1_intr_en bit[15:8] */
315 buf[105] = 1; /* vx1_vsync_intr_en bit[7:0] */
316 buf[106] = 0; /* vx1_vsync_intr_en bit[15:8] */
317 for (i = 107; i < 115; i++)
318 buf[i] = 0;
319
320 /* ctrl: 44byte(115~158) */
321 buf[115] = 0x10; /* ctrl_flag bit[7:0] */
322 buf[116] = 0; /* ctrl_flag bit[15:8] */
323 buf[117] = 0; /* ctrl_flag bit[7:0] */
324 buf[118] = 0; /* ctrl_flag bit[15:8] */
325 buf[119] = 0; /* vx1_power_on_sw_reset_delay bit[7:0] */
326 buf[120] = 0; /* vx1_power_on_sw_reset_delay bit[15:8] */
327 buf[121] = 10; /* vx1_filter_time bit[7:0] */
328 buf[122] = 0; /* vx1_filter_time bit[15:8] */
329 buf[123] = 6; /* vx1_filter_cnt bit[7:0] */
330 buf[124] = 0; /* vx1_filter_cnt bit[15:8] */
331 buf[125] = 2; /* vx1_filter_retry_cnt bit[7:0] */
332 buf[126] = 0; /* vx1_filter_retry_cnt bit[15:8] */
333 buf[127] = 100; /* vx1_filter_retry_delay bit[7:0] */
334 buf[128] = 0; /* vx1_filter_retry_delay bit[15:8] */
335 buf[129] = 20; /* vx1_filter_cdr_detect_time bit[7:0] */
336 buf[130] = 0; /* vx1_filter_cdr_detect_time bit[15:8] */
337 buf[131] = 100; /* vx1_filter_cdr_detect_cnt bit[7:0] */
338 buf[132] = 0; /* vx1_filter_cdr_detect_cnt bit[15:8] */
339 buf[133] = 100; /* vx1_filter_cdr_timeout_cnt bit[7:0] */
340 buf[134] = 0; /* vx1_filter_cdr_timeout_cnt bit[15:8] */
341 buf[125] = 10; /* vx1_hpd_lockn_delay bit[7:0] */
342 buf[136] = 0; /* vx1_hpd_lockn_delay bit[15:8] */
343 buf[137] = 0; /* vx1_cdr_training_delay bit[7:0] */
344 buf[138] = 0; /* vx1_cdr_training_delay bit[15:8] */
345 for (i = 139; i < 159; i++)
346 buf[i] = 0;
347
348 /* phy: 10byte(159~168) */
349 buf[159] = 3; /* phy_vswing_level */
350 buf[160] = 1; /* phy_preem_level */
351 buf[161] = 0; /* phy_clk_vswing_level */
352 buf[162] = 0; /* phy_clk_preem_level */
353 for (i = 163; i < 169; i++)
354 buf[i] = 0;
355
356 /* power */
357 buf[169] = 0; /* power_on: type */
358 buf[170] = 0; /* power_on: index */
359 buf[171] = 1; /* power_on: val */
360 buf[172] = 20; /* power_on: delay bit[7:0] */
361 buf[173] = 0; /* power_on: delay bit[15:8] */
362 buf[174] = 2; /* power_on: type */
363 buf[175] = 0; /* power_on: index */
364 buf[176] = 0; /* power_on: val */
365 buf[177] = 10; /* power_on: delay bit[7:0] */
366 buf[178] = 0; /* power_on: delay bit[15:8] */
367 buf[179] = 3; /* power_on: type */
368 buf[180] = 0; /* power_on: index */
369 buf[181] = 0; /* power_on: val */
370 buf[182] = 10; /* power_on: delay bit[7:0] */
371 buf[183] = 0; /* power_on: delay bit[15:8] */
372 buf[184] = 0xff; /* power_on: type */
373 buf[185] = 0; /* power_on: index */
374 buf[186] = 0; /* power_on: val */
375 buf[187] = 0; /* power_on: delay bit[7:0] */
376 buf[188] = 0; /* power_on: delay bit[15:8] */
377 buf[189] = 2; /* power_off: type */
378 buf[190] = 0; /* power_off: index */
379 buf[191] = 0; /* power_off: val */
380 buf[192] = 20; /* power_off: delay bit[7:0] */
381 buf[193] = 0; /* power_off: delay bit[15:8] */
382 buf[194] = 0; /* power_off: type */
383 buf[195] = 0; /* power_off: index */
384 buf[196] = 0; /* power_off: val */
385 buf[197] = 100; /* power_off: delay bit[7:0] */
386 buf[198] = 0; /* power_off: delay bit[15:8] */
387 buf[199] = 0xff; /* power_off: type */
388 buf[200] = 0; /* power_off: index */
389 buf[201] = 0; /* power_off: val */
390 buf[202] = 0; /* power_off: delay bit[7:0] */
391 buf[203] = 0; /* power_off: delay bit[15:8] */
392
393 len = 204;//10 + 36 + 18 + 31 + 20 + 44 + 10 + 35;
394 /* header */
395 buf[4] = (len & 0xff); /* data_len */
396 buf[5] = ((len >> 8) & 0xff);
397 buf[6] = 2; /* version */
398 buf[7] = 0;
399 buf[8] = 0; /* reserved */
400 buf[9] = 0;
401#else /* v1 */
402 /* interface: 20byte(95~114) */
403 buf[95] = 8; /* vx1_lane_count bit[7:0] */
404 buf[96] = 0; /* vx1_lane_count bit[15:8] */
405 buf[97] = 2; /* vx1_region_num bit[7:0] */
406 buf[98] = 0; /* vx1_region_num bit[15:8] */
407 buf[99] = 4; /* vx1_byte_mode bit[7:0] */
408 buf[100] = 0; /* vx1_byte_mode bit[15:8] */
409 buf[101] = 4; /* vx1_color_fmt bit[7:0] */
410 buf[102] = 0; /* vx1_color_fmt bit[15:8] */
411 buf[103] = 3; /* phy_vswing_level bit[7:0] */
412 buf[104] = 0; /* phy_vswing_level bit[15:8] */
413 buf[105] = 1; /* phy_preem_level bit[7:0] */
414 buf[106] = 0; /* phy_preem_level bit[15:8] */
415 buf[107] = 1; /* vbyone_intr_en bit[7:0] */
416 buf[108] = 0; /* vbyone_intr_en bit[15:8] */
417 buf[109] = 1; /* vbyone_vsync_intr_en bit[7:0] */
418 buf[110] = 0; /* vbyone_vsync_intr_en bit[15:8] */
419 for (i = 111; i < 115; i++)
420 buf[i] = 0;
421
422 /* power */
423 buf[115] = 0; /* power_on: type */
424 buf[116] = 0; /* power_on: index */
425 buf[117] = 1; /* power_on: val */
426 buf[118] = 20; /* power_on: delay bit[7:0] */
427 buf[119] = 0; /* power_on: delay bit[15:8] */
428 buf[120] = 2; /* power_on: type */
429 buf[121] = 0; /* power_on: index */
430 buf[122] = 0; /* power_on: val */
431 buf[123] = 10; /* power_on: delay bit[7:0] */
432 buf[124] = 0; /* power_on: delay bit[15:8] */
433 buf[125] = 3; /* power_on: type */
434 buf[126] = 0; /* power_on: index */
435 buf[127] = 0; /* power_on: val */
436 buf[128] = 10; /* power_on: delay bit[7:0] */
437 buf[129] = 0; /* power_on: delay bit[15:8] */
438 buf[130] = 0xff; /* power_on: type */
439 buf[131] = 0; /* power_on: index */
440 buf[132] = 0; /* power_on: val */
441 buf[133] = 0; /* power_on: delay bit[7:0] */
442 buf[134] = 0; /* power_on: delay bit[15:8] */
443 buf[135] = 2; /* power_off: type */
444 buf[136] = 0; /* power_off: index */
445 buf[137] = 0; /* power_off: val */
446 buf[138] = 20; /* power_off: delay bit[7:0] */
447 buf[139] = 0; /* power_off: delay bit[15:8] */
448 buf[140] = 0; /* power_off: type */
449 buf[141] = 0; /* power_off: index */
450 buf[142] = 0; /* power_off: val */
451 buf[143] = 100; /* power_off: delay bit[7:0] */
452 buf[144] = 0; /* power_off: delay bit[15:8] */
453 buf[145] = 0xff; /* power_off: type */
454 buf[146] = 0; /* power_off: index */
455 buf[147] = 0; /* power_off: val */
456 buf[148] = 0; /* power_off: delay bit[7:0] */
457 buf[149] = 0; /* power_off: delay bit[15:8] */
458
459 len = 150;//10 + 36 + 18 + 31 + 20 + 44 + 10 + 35;
460 /* header */
461 buf[4] = (len & 0xff); /* data_len */
462 buf[5] = ((len >> 8) & 0xff);
463 buf[6] = 1; /* version */
464 buf[7] = 0;
465 buf[8] = 0; /* reserved */
466 buf[9] = 0;
467#endif
468 key_crc = crc32(0, &buf[4], (len - 4)); //except crc32
469 key_crc32 = (unsigned int)key_crc;
470 for (i = 0; i < 4; i++)
471 buf[i] = (unsigned char)((key_crc32 >> (i * 8)) & 0xff);
472
473 key_unify_write("lcd", buf, len);
474}
475
476static void aml_lcd_extern_test_unifykey(void)
477{
478 int len;
479 unsigned char buf[99];
480 const char *str;
481 int i, n;
482 uint32_t key_crc;
483 unsigned int key_crc32;
484
485 /* basic: 33byte(10~42) */
486 str = "lcd_extern_unifykey_test";
487 n = strlen(str);
488 strcpy((char *)(&buf[10]), str);
489 buf[10+n] = '\0';
490 buf[39] = '\0';
491 buf[40] = 0; /* index */
492 buf[41] = 0; /* type */
493 buf[42] = 1; /* status */
494
495 /* type: 10byte(43~52) */
496 buf[43] = 0x1c; /* i2c_addr */
497 buf[44] = 0xff; /* i2c_second_addr */
498 buf[45] = 0x1; /* i2c_bus */
499
500#if 0 /* init_table_dynamic_size */
501 buf[46] = 0xff; /* cmd_size */
502 for (i = 47; i < 53; i++)
503 buf[i] = 0;
504
505 /* init */
506 buf[53] = 0x10;
507 buf[54] = 0x07;
508 buf[55] = 0x01;
509 buf[56] = 0x02;
510 buf[57] = 0x00;
511 buf[58] = 0x40;
512 buf[59] = 0xff;
513 buf[60] = 0x00;
514 buf[61] = 0x00; //init step 1
515 buf[62] = 0x10;
516 buf[63] = 0x03;
517 buf[64] = 0x02;
518 buf[65] = 0x00;
519 buf[66] = 0x40; //init step 2
520 buf[67] = 0x00;
521 buf[68] = 0x05;
522 buf[69] = 0x73;
523 buf[70] = 0x0a;
524 buf[71] = 0x01;
525 buf[72] = 0x00;
526 buf[73] = 0x00; //init step 3
527 buf[74] = 0x00;
528 buf[75] = 0x02;
529 buf[76] = 0x06;
530 buf[77] = 0x08; //init step 4
531 buf[78] = 0xff;
532 buf[79] = 0x00; //init_on ending
533 buf[80] = 0x10;
534 buf[81] = 0x02;
535 buf[82] = 0x30;
536 buf[83] = 0x40; //init_off 1
537 buf[84] = 0x10;
538 buf[85] = 0x06;
539 buf[86] = 0x70;
540 buf[87] = 0x80;
541 buf[88] = 0x90; //init_off 2
542 buf[89] = 0xff;
543 buf[90] = 0x00;
544 buf[91] = 0x00; //init_off 3
545 buf[92] = 0x00;
546 buf[93] = 0x02;
547 buf[94] = 0x09;
548 buf[95] = 0x0a; //init_off 4
549 buf[96] = 0xff;
550 buf[97] = 0x00; //init_off ending
551#else /* init_table_fixed_size */
552 buf[46] = 0x9; /* cmd_size */
553 for (i = 47; i < 53; i++)
554 buf[i] = 0;
555
556 /* init */
557 buf[53] = 0x10;
558 buf[54] = 0x20;
559 buf[55] = 0x01;
560 buf[56] = 0x02;
561 buf[57] = 0x00;
562 buf[58] = 0x40;
563 buf[59] = 0xff;
564 buf[60] = 0x00;
565 buf[61] = 0x00; //init step 1
566 buf[62] = 0x10;
567 buf[63] = 0x80;
568 buf[64] = 0x02;
569 buf[65] = 0x00;
570 buf[66] = 0x40;
571 buf[67] = 0x62;
572 buf[68] = 0x51;
573 buf[69] = 0x73;
574 buf[70] = 0x0a; //init step 2
575 buf[71] = 0xff;
576 buf[72] = 0x00;
577 buf[73] = 0x00;
578 buf[74] = 0x00;
579 buf[75] = 0x00;
580 buf[76] = 0x00;
581 buf[77] = 0x00;
582 buf[78] = 0x00;
583 buf[79] = 0x00; //init_on ending
584 buf[80] = 0x10;
585 buf[81] = 0x20;
586 buf[82] = 0x30;
587 buf[83] = 0x40;
588 buf[84] = 0x50;
589 buf[85] = 0x60;
590 buf[86] = 0x70;
591 buf[87] = 0x80;
592 buf[88] = 0x90; //init_off
593 buf[89] = 0xff;
594 buf[90] = 0x00;
595 buf[91] = 0x00;
596 buf[92] = 0x00;
597 buf[93] = 0x00;
598 buf[94] = 0x00;
599 buf[95] = 0x00;
600 buf[96] = 0x00;
601 buf[97] = 0x00; //init_off ending
602#endif
603
604 len = 10 + 33 + 10 + 5*9;
605 /* header */
606 buf[4] = (len & 0xff); /* data_len */
607 buf[5] = ((len >> 8) & 0xff);
608 buf[6] = 1; /* version */
609 buf[7] = 0;
610 buf[8] = 0; /* reserved */
611 buf[9] = 0;
612 key_crc = crc32(0, &buf[4], (len - 4)); //except crc32
613 key_crc32 = (unsigned int)key_crc;
614 for (i = 0; i < 4; i++)
615 buf[i] = (unsigned char)((key_crc32 >> (i * 8)) & 0xff);
616
617 key_unify_write("lcd_extern", buf, len);
618}
619
620static void aml_bl_test_unifykey(void)
621{
622 int len;
623 unsigned char buf[102];
624 const char *str;
625 int i, n;
626 uint32_t key_crc;
627 unsigned int key_crc32;
628
629 /* basic: 30byte(10~39) */
630 str = "backlight_unifykey_test";
631 n = strlen(str);
632 strcpy((char *)(&buf[10]), str);
633 buf[10+n] = '\0';
634 buf[39] = '\0';
635
636 /* level: 12byte(40~51) */
637 buf[40] = 128; /* level uboot */
638 buf[41] = 0;
639 buf[42] = 128; /* level kernel */
640 buf[43] = 0;
641 buf[44] = 255; /* level max */
642 buf[45] = 0;
643 buf[46] = 10; /* level min */
644 buf[47] = 0;
645 buf[48] = 128; /* level mid */
646 buf[49] = 0;
647 buf[50] = 128; /* level mid mapping */
648 buf[51] = 0;
649#if 1
650 /* method: 8byte(52~59) */
651 buf[52] = 1; /* bl method */
652 buf[53] = 0; /* bl enable gpio */
653 buf[54] = 1; /* bl enable gpio on */
654 buf[55] = 0; /* bl enable gpio off */
655 buf[56] = 200; /* power on delay bit[7:0] */
656 buf[57] = 0; /* power on delay bit[15:8] */
657 buf[58] = 30; /* power off delay bit[7:0] */
658 buf[59] = 0; /* power off delay bit[15:8] */
659
660 /* pwm: 32byte(60~91) */
661 buf[60] = 10; /* pwm on delay bit[15:8] */
662 buf[61] = 0; /* pwm on delay bit[15:8] */
663 buf[62] = 10; /* pwm off delay bit[15:8] */
664 buf[63] = 0; /* pwm off delay bit[15:8] */
665
666 buf[64] = 1; /* pwm method */
667 buf[65] = 3; /* pwm port */
668 buf[66] = 180; /* pwm freq bit[7:0] */
669 buf[67] = 0; /* pwm freq bit[15:8] */
670 buf[68] = 0; /* pwm freq bit[23:16] */
671 buf[69] = 0; /* pwm freq bit[31:24] */
672 buf[70] = 100; /* pwm duty max */
673 buf[71] = 25; /* pwm duty min */
674 buf[72] = 1; /* pwm gpio */
675 buf[73] = 0; /* pwm gpio off */
676 for (i = 74; i < 84; i++) /* pwm2 for pwm_combo */
677 buf[i] = 0;
678
679 for (i = 84; i < 92; i++) /* pwm/pwm2_level_range for pwm_combo */
680 buf[i] = 0;
681#else
682 /* method: 8byte(52~59) */
683 buf[52] = 2; /* bl method */
684 buf[53] = 0; /* bl enable gpio */
685 buf[54] = 1; /* bl enable gpio on */
686 buf[55] = 0; /* bl enable gpio off */
687 buf[56] = 0xf2; /* power on delay bit[7:0] */
688 buf[57] = 0x03; /* power on delay bit[15:8] */
689 buf[58] = 0x6e; /* power off delay bit[7:0] */
690 buf[59] = 0; /* power off delay bit[15:8] */
691
692 /* pwm: 32byte(60~91) */
693 buf[60] = 10; /* pwm on delay bit[15:8] */
694 buf[61] = 0; /* pwm on delay bit[15:8] */
695 buf[62] = 10; /* pwm off delay bit[15:8] */
696 buf[63] = 0; /* pwm off delay bit[15:8] */
697
698 buf[64] = 1; /* pwm method */
699 buf[65] = 1; /* pwm port */
700 buf[66] = 180; /* pwm freq bit[7:0] */
701 buf[67] = 0; /* pwm freq bit[15:8] */
702 buf[68] = 0; /* pwm freq bit[23:16] */
703 buf[69] = 0; /* pwm freq bit[31:24] */
704 buf[70] = 100; /* pwm duty max */
705 buf[71] = 25; /* pwm duty min */
706 buf[72] = 1; /* pwm gpio */
707 buf[73] = 0; /* pwm gpio off */
708
709 buf[74] = 1; /* pwm2 method */
710 buf[75] = 2; /* pwm2 port */
711 buf[76] = 0x50; /* pwm2 freq bit[7:0] */
712 buf[77] = 0x46; /* pwm2 freq bit[15:8] */
713 buf[78] = 0; /* pwm2 freq bit[23:16] */
714 buf[79] = 0; /* pwm2 freq bit[31:24] */
715 buf[80] = 100; /* pwm2 duty max */
716 buf[81] = 20; /* pwm2 duty min */
717 buf[82] = 2; /* pwm2 gpio */
718 buf[83] = 0; /* pwm2 gpio off */
719
720 buf[84] = 50;
721 buf[85] = 0;
722 buf[86] = 10;
723 buf[87] = 0;
724 buf[88] = 255;
725 buf[89] = 0;
726 buf[90] = 50;
727 buf[91] = 0;
728#endif
729 /* customer: 10byte(92~101) */
730 for (i = 92; i < 102; i++)
731 buf[i] = 0;
732
733 len = 102;
734 /* header */
735 buf[4] = (len & 0xff); /* data_len */
736 buf[5] = ((len >> 8) & 0xff);
737 buf[6] = 2; /* version */
738 buf[7] = 0;
739 buf[8] = 0; /* reserved */
740 buf[9] = 0;
741 key_crc = crc32(0, &buf[4], (len - 4)); //except crc32
742 key_crc32 = (unsigned int)key_crc;
743 for (i = 0; i < 4; i++)
744 buf[i] = (unsigned char)((key_crc32 >> (i * 8)) & 0xff);
745
746 key_unify_write("backlight", buf, len);
747}
748
749static void aml_lcd_tcon_test_unifykey(int n)
750{
751 int len = LCD_UKEY_TCON_SIZE;
752 unsigned char *buf;
753
754 switch (n) {
755 case 768:
756 buf = &tcon_boe_hd_hsd_n56[0];
757 break;
758 default:
759 case 1080:
760 buf = &tcon_boe_fhd_goa_n10[0];
761 break;
762 }
763
764 key_unify_write("lcd_tcon", buf, len);
765}
766#endif
767
768void aml_lcd_unifykey_test(void)
769{
770#ifdef LCD_UNIFYKEY_TEST
771 LCDUKEY("Be Careful!! This test will overwrite lcd unifykeys!!\n");
772 aml_lcd_test_unifykey();
773 aml_lcd_extern_test_unifykey();
774 aml_bl_test_unifykey();
775#else
776 LCDUKEY("default bypass for lcd unifykey test\n");
777 LCDUKEY("should enable macro definition: LCD_UNIFYKEY_TEST\n");
778 LCDUKEY("Be Careful!! This test will overwrite lcd unifykeys!!\n");
779#endif
780}
781
782void aml_lcd_unifykey_tcon_test(int n)
783{
784#ifdef LCD_UNIFYKEY_TEST
785 LCDUKEY("Be Careful!! This test will overwrite lcd_tcon unifykeys!!\n");
786 aml_lcd_tcon_test_unifykey(n);
787#else
788 LCDUKEY("default bypass for lcd unifykey test\n");
789 LCDUKEY("should enable macro definition: LCD_UNIFYKEY_TEST\n");
790 LCDUKEY("Be Careful!! This test will overwrite lcd unifykeys!!\n");
791#endif
792}
793
794void aml_lcd_unifykey_dump(int flag)
795{
796 unsigned char *para;
797 int key_len;
798 int ret, i;
799
800 /* dump unifykey: lcd */
801 para = (unsigned char *)malloc(sizeof(unsigned char) * LCD_UKEY_LCD_SIZE);
802 if (!para) {
803 LCDUKEYERR("%s: Not enough memory\n", __func__);
804 return;
805 }
806 key_len = LCD_UKEY_LCD_SIZE;
807 memset(para, 0, (sizeof(unsigned char) * key_len));
808 ret = aml_lcd_unifykey_get("lcd", para, &key_len);
809 if (ret == 0) {
810 printf("unifykey: lcd:");
811 for (i = 0; i < key_len; i++) {
812 if ((i % 16) == 0)
813 printf("\n%03x0:", (i / 16));
814 printf(" %02x", para[i]);
815 }
816 }
817 printf("\n");
818 free(para);
819
820 /* dump unifykey: lcd_extern */
821 para = (unsigned char *)malloc(sizeof(unsigned char) * LCD_UKEY_LCD_EXT_SIZE);
822 if (!para) {
823 LCDUKEYERR("%s: Not enough memory\n", __func__);
824 return;
825 }
826 key_len = LCD_UKEY_LCD_EXT_SIZE;
827 memset(para, 0, (sizeof(unsigned char) * key_len));
828 ret = aml_lcd_unifykey_get("lcd_extern", para, &key_len);
829 if (ret == 0) {
830 printf("unifykey: lcd_extern:");
831 for (i = 0; i < key_len; i++) {
832 if ((i % 16) == 0)
833 printf("\n%03x0:", (i / 16));
834 printf(" %02x", para[i]);
835 }
836 }
837 printf("\n");
838 free(para);
839
840 /* dump unifykey: backlight */
841 para = (unsigned char *)malloc(sizeof(unsigned char) * LCD_UKEY_BL_SIZE);
842 if (!para) {
843 LCDUKEYERR("%s: Not enough memory\n", __func__);
844 return;
845 }
846 key_len = LCD_UKEY_BL_SIZE;
847 memset(para, 0, (sizeof(unsigned char) * key_len));
848 ret = aml_lcd_unifykey_get("backlight", para, &key_len);
849 if (ret == 0) {
850 printf("unifykey: backlight:");
851 for (i = 0; i < key_len; i++) {
852 if ((i % 16) == 0)
853 printf("\n%03x0:", (i / 16));
854 printf(" %02x", para[i]);
855 }
856 }
857 printf("\n");
858 free(para);
859
860 if ((flag & LCD_UKEY_DEBUG_TCON) == 0)
861 return;
862 /* dump unifykey: lcd_tcon */
863 para = (unsigned char *)malloc(sizeof(unsigned char) * LCD_UKEY_TCON_SIZE);
864 if (!para) {
865 LCDUKEYERR("%s: Not enough memory\n", __func__);
866 return;
867 }
868 key_len = LCD_UKEY_TCON_SIZE;
869 memset(para, 0, (sizeof(unsigned char) * key_len));
870 ret = aml_lcd_unifykey_get_no_header("lcd_tcon", para, &key_len);
871 if (ret == 0) {
872 printf("unifykey: lcd_tcon:");
873 for (i = 0; i < key_len; i++) {
874 if ((i % 16) == 0)
875 printf("\n%03x0:", (i / 16));
876 printf(" %02x", para[i]);
877 }
878 }
879 printf("\n");
880 free(para);
881}
882
883#else
884/* dummy driver */
885int aml_lcd_unifykey_len_check(int key_len, int len)
886{
887 LCDUKEYERR("Don't support unifykey\n");
888 return -1;
889}
890
891int aml_lcd_unifykey_header_check(unsigned char *buf, struct aml_lcd_unifykey_header_s *header)
892{
893 LCDUKEYERR("Don't support unifykey\n");
894 return -1;
895}
896
897int aml_lcd_unifykey_check(const char *key_name)
898{
899 LCDUKEYERR("Don't support unifykey\n");
900 return -1;
901}
902
903int aml_lcd_unifykey_get(const char *key_name, unsigned char *buf, int *len)
904{
905 LCDUKEYERR("Don't support unifykey\n");
906 return -1;
907}
908
909int aml_lcd_unifykey_check_no_header(const char *key_name)
910{
911 LCDUKEYERR("Don't support unifykey\n");
912 return -1;
913}
914
915int aml_lcd_unifykey_get_no_header(const char *key_name, unsigned char *buf, int *len)
916{
917 LCDUKEYERR("Don't support unifykey\n");
918 return -1;
919}
920
921void aml_lcd_unifykey_test(void)
922{
923 LCDUKEYERR("Don't support unifykey\n");
924}
925
926void aml_lcd_unifykey_tcon_test(int n)
927{
928 LCDUKEYERR("Don't support unifykey\n");
929}
930
931void aml_lcd_unifykey_dump(int flag)
932{
933 LCDUKEYERR("Don't support unifykey\n");
934}
935
936#endif
937
938