1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
|
/* linux/drivers/video/exynos_decon/panel/dsim_backlight.c
*
* Header file for Samsung MIPI-DSI Backlight driver.
*
* Copyright (c) 2013 Samsung Electronics
* Minwoo Kim <minwoo7945.kim@samsung.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include <linux/backlight.h>
#include "../dsim.h"
#include "dsim_backlight.h"
#include "panel_info.h"
#ifdef CONFIG_PANEL_AID_DIMMING
#include "aid_dimming.h"
#endif
#ifndef USE_PANEL_PARAMETER_MAX_SIZE
#define ELVSS_LEN_MAX ELVSS_LEN
#define TSET_LEN_MAX TSET_LEN
#endif
#ifdef CONFIG_PANEL_AID_DIMMING
unsigned int get_actual_br_value(struct dsim_device *dsim, int index)
{
struct panel_private *panel = &dsim->priv;
struct SmtDimInfo *dimming_info = (struct SmtDimInfo *)panel->dim_info;
if (dimming_info == NULL) {
dsim_err("%s : dimming info is NULL\n", __func__);
goto get_br_err;
}
if (index > MAX_BR_INFO)
index = MAX_BR_INFO;
return dimming_info[index].br;
get_br_err:
return 0;
}
static unsigned char *get_gamma_from_index(struct dsim_device *dsim, int index)
{
struct panel_private *panel = &dsim->priv;
struct SmtDimInfo *dimming_info = (struct SmtDimInfo *)panel->dim_info;
if (dimming_info == NULL) {
dsim_err("%s : dimming info is NULL\n", __func__);
goto get_gamma_err;
}
if (index > MAX_BR_INFO)
index = MAX_BR_INFO;
return (unsigned char *)dimming_info[index].gamma;
get_gamma_err:
return NULL;
}
static unsigned char *get_aid_from_index(struct dsim_device *dsim, int index)
{
struct panel_private *panel = &dsim->priv;
struct SmtDimInfo *dimming_info = (struct SmtDimInfo *)panel->dim_info;
if (dimming_info == NULL) {
dsim_err("%s : dimming info is NULL\n", __func__);
goto get_aid_err;
}
if (index > MAX_BR_INFO)
index = MAX_BR_INFO;
return (u8 *)dimming_info[index].aid;
get_aid_err:
return NULL;
}
static unsigned char *get_elvss_from_index(struct dsim_device *dsim, int index, int caps)
{
struct panel_private *panel = &dsim->priv;
struct SmtDimInfo *dimming_info = (struct SmtDimInfo *)panel->dim_info;
if (dimming_info == NULL) {
dsim_err("%s : dimming info is NULL\n", __func__);
goto get_elvess_err;
}
if(caps)
return (unsigned char *)dimming_info[index].elvCaps;
else
return (unsigned char *)dimming_info[index].elv;
get_elvess_err:
return NULL;
}
static void dsim_panel_gamma_ctrl(struct dsim_device *dsim)
{
u8 *gamma = NULL;
gamma = get_gamma_from_index(dsim, dsim->priv.br_index);
if (gamma == NULL) {
dsim_err("%s :faied to get gamma\n", __func__);
return;
}
if (dsim_write_hl_data(dsim, gamma, GAMMA_CMD_CNT) < 0)
dsim_err("%s : failed to write gamma \n", __func__);
}
static char dsim_panel_get_elvssoffset(struct dsim_device *dsim)
{
char retVal = 0x00;
struct panel_private* panel = &(dsim->priv);
if(UNDER_MINUS_20(panel->temperature))
retVal = HBM_INTER_22TH_OFFSET[panel->br_index][TEMP_UNDER_MINUS_20];
else if(UNDER_0(panel->temperature))
retVal = HBM_INTER_22TH_OFFSET[panel->br_index][TEMP_UNDER_0];
else
retVal = HBM_INTER_22TH_OFFSET[panel->br_index][TEMP_ABOVE_0];
pr_info("%s %d\n", __func__, retVal);
return retVal;
}
static void dsim_panel_aid_ctrl(struct dsim_device *dsim)
{
u8 *aid = NULL;
aid = get_aid_from_index(dsim, dsim->priv.br_index);
if (aid == NULL) {
dsim_err("%s : faield to get aid value\n", __func__);
return;
}
if (dsim_write_hl_data(dsim, aid, AID_CMD_CNT) < 0)
dsim_err("%s : failed to write gamma \n", __func__);
}
static void dsim_panel_set_elvss(struct dsim_device *dsim)
{
u8 *elvss = NULL;
unsigned char SEQ_ELVSS[ELVSS_LEN_MAX] = {0, };
SEQ_ELVSS[0] = ELVSS_REG;
elvss = get_elvss_from_index(dsim, dsim->priv.br_index, dsim->priv.caps_enable);
if (elvss == NULL) {
dsim_err("%s : failed to get elvss value\n", __func__);
return;
}
memcpy(&SEQ_ELVSS[1], dsim->priv.elvss_set, ELVSS_LEN - 1);
memcpy(SEQ_ELVSS, elvss, ELVSS_CMD_CNT);
SEQ_ELVSS[ELVSS_LEN - 1] += dsim_panel_get_elvssoffset(dsim);
if (dsim_write_hl_data(dsim, SEQ_ELVSS, ELVSS_LEN) < 0)
dsim_err("%s : failed to write elvss \n", __func__);
}
static int dsim_panel_set_acl(struct dsim_device *dsim, int force )
{
int ret = 0, level = ACL_OPR_OFF, enabled;
struct panel_private *panel = &dsim->priv;
if (panel == NULL) {
dsim_err("%s : panel is NULL\n", __func__);
goto exit;
}
level = ACL_OPR_OFF;
enabled = ACL_STATUS_OFF;
if (dsim->priv.siop_enable)
goto acl_update;
level = dsim->priv.acl_enable;
enabled = (dsim->priv.acl_enable != ACL_OPR_OFF);
acl_update:
if(force || dsim->priv.current_acl != level) {
if((ret = dsim_write_hl_data(dsim, panel->acl_opr_tbl[level], ACL_OPR_LEN)) < 0) {
dsim_err("fail to write acl opr command.\n");
goto exit;
}
if((ret = dsim_write_hl_data(dsim, panel->acl_cutoff_tbl[enabled], ACL_CMD_LEN)) < 0) {
dsim_err("fail to write acl command.\n");
goto exit;
}
dsim->priv.current_acl = level;
dsim_info("acl : %x, opr: %x\n",
panel->acl_cutoff_tbl[enabled][1], panel->acl_opr_tbl[level][ACL_OPR_LEN-1]);
dsim_info("acl: %d(%x), adaptive_control: %d\n", dsim->priv.current_acl, panel->acl_opr_tbl[level][ACL_CMD_LEN-1], dsim->priv.adaptive_control);
}
exit:
if (!ret)
ret = -EPERM;
return ret;
}
static int dsim_panel_set_tset(struct dsim_device *dsim, int force)
{
int ret = 0;
int tset = 0;
unsigned char SEQ_TSET[TSET_LEN_MAX] = {0, };
SEQ_TSET[0] = TSET_REG;
tset = (dsim->priv.temperature < 0) ? BIT(7) | abs(dsim->priv.temperature) : dsim->priv.temperature;
if(force || dsim->priv.tset[TSET_LEN - 2] != tset) {
memcpy(&SEQ_TSET[1], dsim->priv.tset, TSET_LEN - 1);
dsim->priv.tset[TSET_LEN - 2] = SEQ_TSET[TSET_LEN - 1] = tset;
if ((ret = dsim_write_hl_data(dsim, SEQ_TSET, ARRAY_SIZE(SEQ_TSET))) < 0) {
dsim_err("fail to write tset command.\n");
ret = -EPERM;
}
dsim_info("%s temperature: %d, tset: %d\n",
__func__, dsim->priv.temperature, SEQ_TSET[TSET_LEN - 1]);
}
return ret;
}
static int dsim_panel_set_vint(struct dsim_device *dsim, int force)
{
int ret = 0;
int nit = 0;
int i, level = 0;
int arraySize = ARRAY_SIZE(VINT_DIM_TABLE);
struct panel_private* panel = &(dsim->priv);
unsigned char SEQ_VINT[VINT_LEN] = {VINT_REG, 0x8B, 0x21};
unsigned char *vint_tbl = (unsigned char *)VINT_TABLE;
level = arraySize - 1;
if(UNDER_MINUS_20(panel->temperature))
goto set_vint;
#ifdef CONFIG_LCD_HMT
if(panel->hmt_on == HMT_ON)
goto set_vint;
#endif
nit = get_actual_br_value(dsim, panel->br_index);
level = arraySize - 1;
for (i = 0; i < arraySize; i++) {
if (nit <= VINT_DIM_TABLE[i]) {
level = i;
goto set_vint;
}
}
set_vint:
if(force || panel->current_vint != vint_tbl[level]) {
SEQ_VINT[VINT_LEN - 1] = vint_tbl[level];
if ((ret = dsim_write_hl_data(dsim, SEQ_VINT, ARRAY_SIZE(SEQ_VINT))) < 0) {
dsim_err("fail to write vint command.\n");
ret = -EPERM;
}
panel->current_vint = vint_tbl[level];
dsim_info("vint: %02x\n", panel->current_vint);
}
return ret;
}
static int dsim_panel_set_hbm(struct dsim_device *dsim, int force)
{
int ret = 0, level = LEVEL_IS_HBM(dsim->priv.bd->props.brightness);
struct panel_private *panel = &dsim->priv;
if (panel == NULL) {
dsim_err("%s : panel is NULL\n", __func__);
goto exit;
}
if(force || dsim->priv.current_hbm != panel->hbm_tbl[level][1]) {
dsim->priv.current_hbm = panel->hbm_tbl[level][1];
if((ret = dsim_write_hl_data(dsim, panel->hbm_tbl[level], ARRAY_SIZE(SEQ_HBM_OFF))) < 0) {
dsim_err("fail to write hbm command.\n");
ret = -EPERM;
}
dsim_info("hbm: %d, brightness: %d\n", dsim->priv.current_hbm, dsim->priv.bd->props.brightness);
}
exit:
return ret;
}
static int low_level_set_brightness(struct dsim_device *dsim ,int force)
{
if (dsim_write_hl_data(dsim, SEQ_TEST_KEY_ON_F0, ARRAY_SIZE(SEQ_TEST_KEY_ON_F0)) < 0)
dsim_err("%s : fail to write F0 on command.\n", __func__);
if (dsim_write_hl_data(dsim, SEQ_TEST_KEY_ON_FC, ARRAY_SIZE(SEQ_TEST_KEY_ON_FC)) < 0)
dsim_err("%s : fail to write F0 on command.\n", __func__);
dsim_panel_gamma_ctrl(dsim);
dsim_panel_aid_ctrl(dsim);
dsim_panel_set_elvss(dsim);
dsim_panel_set_vint(dsim, force);
if (dsim_write_hl_data(dsim, SEQ_GAMMA_UPDATE, ARRAY_SIZE(SEQ_GAMMA_UPDATE)) < 0)
dsim_err("%s : failed to write gamma \n", __func__);
if (dsim_write_hl_data(dsim, SEQ_GAMMA_UPDATE_L, ARRAY_SIZE(SEQ_GAMMA_UPDATE_L)) < 0)
dsim_err("%s : failed to write gamma \n", __func__);
dsim_panel_set_acl(dsim, force);
dsim_panel_set_tset(dsim, force);
#ifdef CONFIG_LCD_ALPM
if (!(dsim->priv.current_alpm && dsim->priv.alpm))
#endif
dsim_panel_set_hbm(dsim, force);
if (dsim_write_hl_data(dsim, SEQ_TEST_KEY_OFF_FC, ARRAY_SIZE(SEQ_TEST_KEY_OFF_FC)) < 0)
dsim_err("%s : fail to write F0 on command.\n", __func__);
if (dsim_write_hl_data(dsim, SEQ_TEST_KEY_OFF_F0, ARRAY_SIZE(SEQ_TEST_KEY_OFF_F0)) < 0)
dsim_err("%s : fail to write F0 on command\n", __func__);
return 0;
}
int get_acutal_br_index(struct dsim_device *dsim, int br)
{
int i;
int min;
int gap;
int index = 0;
struct panel_private *panel = &dsim->priv;
struct SmtDimInfo *dimming_info = panel->dim_info;
if (dimming_info == NULL) {
dsim_err("%s : dimming_info is NULL\n", __func__);
return 0;
}
min = MAX_BRIGHTNESS;
for (i = 0; i < MAX_BR_INFO; i++) {
if (br > dimming_info[i].br)
gap = br - dimming_info[i].br;
else
gap = dimming_info[i].br - br;
if (gap == 0) {
index = i;
break;
}
if (gap < min) {
min = gap;
index = i;
}
}
return index;
}
#endif
static int get_panel_acl_level(int p_br, int nit, int adaptive_control)
{
int retVal = ACL_OPR_15P;
if (255 <= p_br && 433 == nit && !adaptive_control)
retVal = ACL_OPR_OFF;
else if (255 <= p_br)
retVal = ACL_OPR_8P;
return retVal;
}
int dsim_panel_set_brightness(struct dsim_device *dsim, int force)
{
int ret = 0;
#ifndef CONFIG_PANEL_AID_DIMMING
dsim_info("%s:this panel does not support dimming \n", __func__);
#else
struct dim_data *dimming;
struct panel_private *panel = &dsim->priv;
int p_br = panel->bd->props.brightness;
int acutal_br = 0;
int real_br = 0;
int prev_index = panel->br_index;
int m_force = force;
bool is_gallery;
unsigned int prev_acl = panel->acl_enable;
#ifdef CONFIG_LCD_HMT
if(panel->hmt_on == HMT_ON) {
pr_info("%s hmt is enabled, plz set hmt brightness \n", __func__);
goto set_br_exit;
}
#endif
if (panel->is_br_override && p_br!=panel->override_br_value) {
pr_info( "%s : brightness %d canceled by override(%d)\n",
__func__, p_br, panel->override_br_value );
goto set_br_exit;
}
is_gallery = !panel->adaptive_control;
#ifdef CONFIG_LCD_BURNIN_CORRECTION
if (panel->ldu_correction_state) {
is_gallery = false;
}
#endif
#ifdef CONFIG_LCD_HBM_INTERPOLATION
if (panel->accessibility) {
is_gallery = false;
}
#endif
dimming = (struct dim_data *)panel->dim_data;
if ((dimming == NULL) || (panel->br_tbl == NULL)) {
dsim_info("%s : this panel does not support dimming\n", __func__);
return ret;
}
if(is_gallery) // gallery
acutal_br = panel->gallery_br_tbl[p_br];
else
acutal_br = panel->br_tbl[p_br];
panel->br_index = get_acutal_br_index(dsim, acutal_br);
real_br = get_actual_br_value(dsim, panel->br_index);
panel->caps_enable = CAPS_IS_ON(real_br);
panel->acl_enable = get_panel_acl_level(p_br, real_br, panel->adaptive_control);
if (prev_acl != panel->acl_enable) {
m_force = 1;
}
if (panel->state != PANEL_STATE_RESUMED) {
dsim_info("%s : panel is not active state..\n", __func__);
goto set_br_exit;
}
dsim_info("%s : platform : %d, : mapping : %d, real : %d, index : %d\n",
__func__, p_br, acutal_br, real_br, panel->br_index);
if (!m_force && panel->br_index == prev_index)
goto set_br_exit;
if ((acutal_br == 0) || (real_br == 0))
goto set_br_exit;
mutex_lock(&panel->lock);
ret = low_level_set_brightness(dsim, m_force);
if (ret) {
dsim_err("%s failed to set brightness : %d\n", __func__, acutal_br);
}
mutex_unlock(&panel->lock);
set_br_exit:
#endif
return ret;
}
#ifdef CONFIG_LCD_HMT
#ifdef CONFIG_PANEL_AID_DIMMING
static unsigned char *get_gamma_from_index_for_hmt(struct dsim_device *dsim, int index)
{
struct panel_private *panel = &dsim->priv;
struct SmtDimInfo *dimming_info = (struct SmtDimInfo *)panel->hmt_dim_info;
if (dimming_info == NULL) {
dsim_err("%s : dimming info is NULL\n", __func__);
goto get_gamma_err;
}
if (index > HMT_MAX_BR_INFO - 1)
index = HMT_MAX_BR_INFO - 1;
return (unsigned char *)dimming_info[index].gamma;
get_gamma_err:
return NULL;
}
static unsigned char *get_aid_from_index_for_hmt(struct dsim_device *dsim, int index)
{
struct panel_private *panel = &dsim->priv;
struct SmtDimInfo *dimming_info = (struct SmtDimInfo *)panel->hmt_dim_info;
if (dimming_info == NULL) {
dsim_err("%s : dimming info is NULL\n", __func__);
goto get_aid_err;
}
if (index > HMT_MAX_BR_INFO - 1)
index = HMT_MAX_BR_INFO - 1;
return (u8 *)dimming_info[index].aid;
get_aid_err:
return NULL;
}
static unsigned char *get_elvss_from_index_for_hmt(struct dsim_device *dsim, int index, int caps)
{
struct panel_private *panel = &dsim->priv;
struct SmtDimInfo *dimming_info = (struct SmtDimInfo *)panel->hmt_dim_info;
if (dimming_info == NULL) {
dsim_err("%s : dimming info is NULL\n", __func__);
goto get_elvess_err;
}
if(caps)
return (unsigned char *)dimming_info[index].elvCaps;
else
return (unsigned char *)dimming_info[index].elv;
get_elvess_err:
return NULL;
}
static void dsim_panel_gamma_ctrl_for_hmt(struct dsim_device *dsim)
{
u8 *gamma = NULL;
gamma = get_gamma_from_index_for_hmt(dsim, dsim->priv.hmt_br_index);
if (gamma == NULL) {
dsim_err("%s :faied to get gamma\n", __func__);
return;
}
if (dsim_write_hl_data(dsim, gamma, GAMMA_CMD_CNT) < 0)
dsim_err("%s : failed to write hmt gamma \n", __func__);
}
static void dsim_panel_aid_ctrl_for_hmt(struct dsim_device *dsim)
{
u8 *aid = NULL;
aid = get_aid_from_index_for_hmt(dsim, dsim->priv.hmt_br_index);
if (aid == NULL) {
dsim_err("%s : faield to get aid value\n", __func__);
return;
}
if (dsim_write_hl_data(dsim, aid, AID_CMD_CNT + 1) < 0)
dsim_err("%s : failed to write hmt aid \n", __func__);
}
static void dsim_panel_set_elvss_for_hmt(struct dsim_device *dsim)
{
u8 *elvss = NULL;
unsigned char SEQ_ELVSS[ELVSS_LEN_MAX] = {ELVSS_REG, };
SEQ_ELVSS[0] = ELVSS_REG;
elvss = get_elvss_from_index_for_hmt(dsim, dsim->priv.hmt_br_index, dsim->priv.acl_enable);
if (elvss == NULL) {
dsim_err("%s : failed to get elvss value\n", __func__);
return;
}
memcpy(&SEQ_ELVSS[1], dsim->priv.elvss_set, ELVSS_LEN - 1);
memcpy(SEQ_ELVSS, elvss, ELVSS_CMD_CNT);
if(UNDER_MINUS_20(dsim->priv.temperature)) // tset
SEQ_ELVSS[ELVSS_LEN - 1] -= TSET_MINUS_OFFSET;
if (dsim_write_hl_data(dsim, SEQ_ELVSS, ELVSS_LEN) < 0)
dsim_err("%s : failed to write elvss \n", __func__);
}
static int low_level_set_brightness_for_hmt(struct dsim_device *dsim ,int force)
{
if (dsim_write_hl_data(dsim, SEQ_TEST_KEY_ON_F0, ARRAY_SIZE(SEQ_TEST_KEY_ON_F0)) < 0)
dsim_err("%s : fail to write F0 on command.\n", __func__);
if (dsim_write_hl_data(dsim, SEQ_TEST_KEY_ON_FC, ARRAY_SIZE(SEQ_TEST_KEY_ON_FC)) < 0)
dsim_err("%s : fail to write F0 on command.\n", __func__);
dsim_panel_gamma_ctrl_for_hmt(dsim);
dsim_panel_aid_ctrl_for_hmt(dsim);
dsim_panel_set_elvss_for_hmt(dsim);
dsim_panel_set_vint(dsim, force);
if (dsim_write_hl_data(dsim, SEQ_GAMMA_UPDATE, ARRAY_SIZE(SEQ_GAMMA_UPDATE)) < 0)
dsim_err("%s : failed to write gamma \n", __func__);
if (dsim_write_hl_data(dsim, SEQ_GAMMA_UPDATE_L, ARRAY_SIZE(SEQ_GAMMA_UPDATE_L)) < 0)
dsim_err("%s : failed to write gamma \n", __func__);
dsim_panel_set_acl(dsim, force);
dsim_panel_set_tset(dsim, force);
if (dsim_write_hl_data(dsim, SEQ_TEST_KEY_OFF_FC, ARRAY_SIZE(SEQ_TEST_KEY_OFF_FC)) < 0)
dsim_err("%s : fail to write F0 on command.\n", __func__);
if (dsim_write_hl_data(dsim, SEQ_TEST_KEY_OFF_F0, ARRAY_SIZE(SEQ_TEST_KEY_OFF_F0)) < 0)
dsim_err("%s : fail to write F0 on command\n", __func__);
return 0;
}
static int get_acutal_br_index_for_hmt(struct dsim_device *dsim, int br)
{
int i;
int min;
int gap;
int index = 0;
struct panel_private *panel = &dsim->priv;
struct SmtDimInfo *dimming_info = panel->hmt_dim_info;
if (dimming_info == NULL) {
dsim_err("%s : dimming_info is NULL\n", __func__);
return 0;
}
min = HMT_MAX_BRIGHTNESS;
for (i = 0; i < MAX_BR_INFO; i++) {
if (br > dimming_info[i].br)
gap = br - dimming_info[i].br;
else
gap = dimming_info[i].br - br;
if (gap == 0) {
index = i;
break;
}
if (gap < min) {
min = gap;
index = i;
}
}
return index;
}
#endif
int dsim_panel_set_brightness_for_hmt(struct dsim_device *dsim, int force)
{
int ret = 0;
#ifndef CONFIG_PANEL_AID_DIMMING
dsim_info("%s:this panel does not support dimming \n", __func__);
#else
struct dim_data *dimming;
struct panel_private *panel = &dsim->priv;
int p_br = panel->hmt_brightness;
int acutal_br = 0;
int prev_index = panel->hmt_br_index;
dimming = (struct dim_data *)panel->hmt_dim_data;
if ((dimming == NULL) || (panel->hmt_br_tbl == NULL)) {
dsim_info("%s : this panel does not support dimming\n", __func__);
return ret;
}
acutal_br = panel->hmt_br_tbl[p_br];
panel->acl_enable = 0;
panel->hmt_br_index = get_acutal_br_index_for_hmt(dsim, acutal_br);
if(panel->siop_enable) // check auto acl
panel->acl_enable = 1;
if (panel->state != PANEL_STATE_RESUMED) {
dsim_info("%s : panel is not active state..\n", __func__);
goto set_br_exit;
}
if (!force && panel->hmt_br_index == prev_index)
goto set_br_exit;
dsim_info("%s : req : %d : nit : %d index : %d\n",
__func__, p_br, acutal_br, panel->hmt_br_index);
if (acutal_br == 0)
goto set_br_exit;
mutex_lock(&panel->lock);
ret = low_level_set_brightness_for_hmt(dsim, force);
if (ret) {
dsim_err("%s failed to hmt set brightness : %d\n", __func__, acutal_br);
}
mutex_unlock(&panel->lock);
set_br_exit:
#endif
return ret;
}
#endif
static int panel_get_brightness(struct backlight_device *bd)
{
struct panel_private *priv = bl_get_data(bd);
struct dsim_device *dsim = container_of(priv, struct dsim_device, priv);
return get_actual_br_value(dsim, priv->br_index);
}
static int panel_set_brightness(struct backlight_device *bd)
{
int ret = 0;
int brightness = bd->props.brightness;
struct panel_private *priv = bl_get_data(bd);
struct dsim_device *dsim;
dsim = container_of(priv, struct dsim_device, priv);
if (brightness < UI_MIN_BRIGHTNESS || brightness > EXTEND_BRIGHTNESS) {
pr_alert("Brightness %d is out of range\n", brightness);
ret = -EINVAL;
goto exit_set;
}
ret = dsim_panel_set_brightness(dsim, 0);
if (ret) {
dsim_err("%s : fail to set brightness\n", __func__);
goto exit_set;
}
exit_set:
return ret;
}
static const struct backlight_ops panel_backlight_ops = {
.get_brightness = panel_get_brightness,
.update_status = panel_set_brightness,
};
int dsim_backlight_probe(struct dsim_device *dsim)
{
int ret = 0;
struct panel_private *panel = &dsim->priv;
panel->bd = backlight_device_register("panel", dsim->dev, &dsim->priv,
&panel_backlight_ops, NULL);
if (IS_ERR(panel->bd)) {
dsim_err("%s:failed register backlight\n", __func__);
ret = PTR_ERR(panel->bd);
}
panel->bd->props.max_brightness = EXTEND_BRIGHTNESS;
panel->bd->props.brightness = UI_DEFAULT_BRIGHTNESS;
#ifdef CONFIG_LCD_HMT
panel->hmt_on = HMT_OFF;
panel->hmt_brightness = DEFAULT_HMT_BRIGHTNESS;
panel->hmt_br_index = 0;
#endif
return ret;
}
|