summaryrefstree
path: root/kernel/drivers/video/fbdev/exynos/dual_panel/sysfs.c
blob: 5b833d6f3e987ab9b86dec3ec225721e9dc11983 (plain)
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
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
/*
 * linux/drivers/video/fbdev/exynos/panel/sysfs.c
 *
 * Samsung MIPI-DSI Panel SYSFS driver.
 *
 * Copyright (c) 2016 Samsung Electronics
 * JiHoon Kim <jihoonn.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/ctype.h>
#include <linux/lcd.h>

#include "../dual_dpu/dsim.h"
#include "panel.h"
#include "panel_drv.h"
#include "panel_bl.h"
#include "../dual_dpu/decon.h"
#include "copr.h"
#if defined(CONFIG_EXYNOS_DECON_MDNIE_LITE)
#include "mdnie.h"
#endif
#ifdef CONFIG_PANEL_AID_DIMMING
#include "dimming.h"
#endif

extern struct kset *devices_kset;

void g_tracing_mark_write( char id, char* str1, int value );
int fingerprint_value = -1;
static ssize_t fingerprint_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	sprintf(buf, "%u\n", fingerprint_value);

	return strlen(buf);
}

static ssize_t fingerprint_store(struct device *dev,
	struct device_attribute *attr, const char *buf, size_t size)
{
	int rc;

	rc = kstrtouint(buf, (unsigned int)0, &fingerprint_value);
	if (rc < 0)
		return rc;

	g_tracing_mark_write( 'C', "BCDS_hbm", fingerprint_value & 4);
	g_tracing_mark_write( 'C', "BCDS_alpha", fingerprint_value & 2);

	dev_info(dev, "%s: %d\n", __func__, fingerprint_value);

	return size;
}

static ssize_t lcd_type_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	struct panel_info *panel_data;
	struct panel_device *panel = dev_get_drvdata(dev);

	if (panel == NULL) {
		panel_err("PANEL:ERR:%s:panel is null\n", __func__);
		return -EINVAL;
	}
	panel_data = &panel->panel_data;

	sprintf(buf, "SDC_%02X%02X%02X\n",
			panel_data->id[0], panel_data->id[1], panel_data->id[2]);

	return strlen(buf);
}

static ssize_t window_type_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	struct panel_info *panel_data;
	struct panel_device *panel = dev_get_drvdata(dev);

	if (panel == NULL) {
		panel_err("PANEL:ERR:%s:panel is null\n", __func__);
		return -EINVAL;
	}
	panel_data = &panel->panel_data;

	sprintf(buf, "%02x %02x %02x\n",
			panel_data->id[0], panel_data->id[1], panel_data->id[2]);
	pr_info("%s %02x %02x %02x\n",
			__func__, panel_data->id[0], panel_data->id[1], panel_data->id[2]);
	return strlen(buf);
}

static ssize_t manufacture_code_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	u8 code[5] = { 0, };
	struct panel_info *panel_data;
	struct panel_device *panel = dev_get_drvdata(dev);

	if (panel == NULL) {
		panel_err("PANEL:ERR:%s:panel is null\n", __func__);
		return -EINVAL;
	}
	panel_data = &panel->panel_data;

	resource_copy_by_name(panel_data, code, "code");

	sprintf(buf, "%02X%02X%02X%02X%02X\n",
		code[0], code[1], code[2], code[3], code[4]);

	return strlen(buf);
}

static ssize_t cell_id_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	u8 date[7] = { 0, }, coordinate[4] = { 0, };
	struct panel_info *panel_data;
	struct panel_device *panel = dev_get_drvdata(dev);

	if (panel == NULL) {
		panel_err("PANEL:ERR:%s:panel is null\n", __func__);
		return -EINVAL;
	}
	panel_data = &panel->panel_data;

	resource_copy_by_name(panel_data, date, "date");
	resource_copy_by_name(panel_data, coordinate, "coordinate");

	sprintf(buf, "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n",
		date[0] , date[1], date[2], date[3], date[4], date[5], date[6],
		coordinate[0], coordinate[1], coordinate[2], coordinate[3]);

	return strlen(buf);
}

static ssize_t SVC_OCTA_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	u8 date[7] = { 0, }, coordinate[4] = { 0, };
	struct panel_info *panel_data;
	struct panel_device *panel = dev_get_drvdata(dev);

	if (panel == NULL) {
		panel_err("PANEL:ERR:%s:panel is null\n", __func__);
		return -EINVAL;
	}
	panel_data = &panel->panel_data;

	resource_copy_by_name(panel_data, date, "date");
	resource_copy_by_name(panel_data, coordinate, "coordinate");

	sprintf(buf, "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X\n",
		date[0] , date[1], date[2], date[3], date[4], date[5], date[6],
		coordinate[0], coordinate[1], coordinate[2], coordinate[3]);

	return strlen(buf);
}

#ifdef CONFIG_SEC_FACTORY
static ssize_t octa_id_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	int i, site, rework, poc;
	u8 cell_id[16], octa_id[PANEL_OCTA_ID_LEN] = { 0, };
	struct panel_info *panel_data;
	struct panel_device *panel = dev_get_drvdata(dev);
	char *p = buf;
	bool cell_id_exist = true;


	if (panel == NULL) {
		panel_err("PANEL:ERR:%s:panel is null\n", __func__);
		return -EINVAL;
	}
	panel_data = &panel->panel_data;

	resource_copy_by_name(panel_data, octa_id, "octa_id");

	site = (octa_id[0] >> 4) & 0x0F;
	rework = octa_id[0] & 0x0F;
	poc = octa_id[1] & 0x0F;

	panel_dbg("site (%d), rework (%d), poc (%d)\n",
			site, rework, poc);

	panel_dbg("<CELL ID>\n");
	for (i = 0; i < 16; i++) {
		cell_id[i] = isalnum(octa_id[i + 4]) ? octa_id[i + 4] : '\0';
		panel_dbg("%x -> %c\n", octa_id[i + 4], cell_id[i]);
		if (cell_id[i] == '\0')
			cell_id_exist = false;
	}

	p += sprintf(p, "%d%d%d%02x%02x", site, rework, poc, octa_id[2], octa_id[3]);
	if (cell_id_exist) {
		for (i = 0; i < 16; i++)
			p += sprintf(p, "%c", cell_id[i]);
	}
	p += sprintf(p, "\n");

	return strlen(buf);
}
#endif /* CONFIG_SEC_FACTORY */

static ssize_t color_coordinate_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	u8 coordinate[4] = { 0, };
	struct panel_info *panel_data;
	struct panel_device *panel = dev_get_drvdata(dev);

	if (panel == NULL) {
		panel_err("PANEL:ERR:%s:panel is null\n", __func__);
		return -EINVAL;
	}
	panel_data = &panel->panel_data;

	resource_copy_by_name(panel_data, coordinate, "coordinate");

	sprintf(buf, "%u, %u\n", /* X, Y */
			coordinate[0] << 8 | coordinate[1],
			coordinate[2] << 8 | coordinate[3]);
	return strlen(buf);
}

static ssize_t manufacture_date_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	u16 year;
	u8 month, day, hour, min, date[4] = { 0, };
	struct panel_info *panel_data;
	struct panel_device *panel = dev_get_drvdata(dev);

	if (panel == NULL) {
		panel_err("PANEL:ERR:%s:panel is null\n", __func__);
		return -EINVAL;
	}
	panel_data = &panel->panel_data;

	resource_copy_by_name(panel_data, date, "date");

	year = ((date[0] & 0xF0) >> 4) + 2011;
	month = date[0] & 0xF;
	day = date[1] & 0x1F;
	hour = date[2] & 0x1F;
	min = date[3] & 0x3F;

	sprintf(buf, "%d, %d, %d, %d:%d\n", year, month, day, hour, min);
	return strlen(buf);
}

static ssize_t brightness_table_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	struct panel_device *panel = dev_get_drvdata(dev);
	struct panel_bl_device *panel_bl;
	char *pos = buf;
	int br;

	if (panel == NULL) {
		panel_err("PANEL:ERR:%s:panel is null\n", __func__);
		return -EINVAL;
	}
	panel_bl = &panel->panel_bl;

	for (br = 0; br <= EXTEND_BRIGHTNESS; br += BRT_SCALE)
		pos += sprintf(pos, "%5d %3d\n",
				br, get_actual_brightness(panel_bl, br));

	return pos - buf;
}

static ssize_t adaptive_control_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	struct panel_info *panel_data;
	struct panel_device *panel = dev_get_drvdata(dev);

	if (panel == NULL) {
		panel_err("PANEL:ERR:%s:panel is null\n", __func__);
		return -EINVAL;
	}
	panel_data = &panel->panel_data;

	sprintf(buf, "%d\n", panel_data->props.adaptive_control);

	return strlen(buf);
}

static ssize_t adaptive_control_store(struct device *dev,
	struct device_attribute *attr, const char *buf, size_t size)
{
	struct panel_info *panel_data;
	struct panel_device *panel = dev_get_drvdata(dev);
	struct panel_bl_device *panel_bl;
	struct backlight_device *bd;
	int value, rc;

	if (panel == NULL) {
		panel_err("PANEL:ERR:%s:panel is null\n", __func__);
		return -EINVAL;
	}

	panel_data = &panel->panel_data;
	panel_bl = &panel->panel_bl;
	bd = panel_bl->bd;

	if (bd == NULL) {
		panel_err("PANEL:ERR:%s:backlight device is null\n", __func__);
		return -EINVAL;
	}

	rc = kstrtouint(buf, (unsigned int)0, &value);
	if (rc < 0)
		return rc;

	if (panel_data->props.adaptive_control == value)
		return size;

	mutex_lock(&panel_bl->lock);
	panel_data->props.adaptive_control = value;
	mutex_unlock(&panel_bl->lock);
	backlight_update_status(bd);

	dev_info(dev, "%s, adaptive_control %d\n",
			__func__, panel_data->props.adaptive_control);

	return size;
}

static ssize_t siop_enable_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	struct panel_info *panel_data;
	struct panel_device *panel = dev_get_drvdata(dev);

	if (panel == NULL) {
		panel_err("PANEL:ERR:%s:panel is null\n", __func__);
		return -EINVAL;
	}
	panel_data = &panel->panel_data;

	sprintf(buf, "%u\n", panel_data->props.siop_enable);

	return strlen(buf);
}

static ssize_t siop_enable_store(struct device *dev,
	struct device_attribute *attr, const char *buf, size_t size)
{
	struct panel_info *panel_data;
	struct panel_device *panel = dev_get_drvdata(dev);
	struct backlight_device *bd;
	int value, rc;

	if (panel == NULL) {
		panel_err("PANEL:ERR:%s:panel is null\n", __func__);
		return -EINVAL;
	}
	panel_data = &panel->panel_data;

	bd = panel->panel_bl.bd;
	if (bd == NULL) {
		panel_err("PANEL:ERR:%s:backlight device is null\n", __func__);
		return -EINVAL;
	}

	rc = kstrtouint(buf, (unsigned int)0, &value);
	if (rc < 0)
		return rc;

	if (panel_data->props.siop_enable == value)
		return size;

	mutex_lock(&panel->op_lock);
	panel_data->props.siop_enable = value;
	mutex_unlock(&panel->op_lock);
	backlight_update_status(bd);

	dev_info(dev, "%s, siop_enable %d\n",
			__func__, panel_data->props.siop_enable);
	return size;
}

static ssize_t temperature_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	char temp[] = "-15, -14, 0, 1\n";

	strcat(buf, temp);
	return strlen(buf);
}

static ssize_t temperature_store(struct device *dev,
	struct device_attribute *attr, const char *buf, size_t size)
{
	struct panel_info *panel_data;
	struct panel_device *panel = dev_get_drvdata(dev);
	struct backlight_device *bd;
	int value, rc;

	if (panel == NULL) {
		panel_err("PANEL:ERR:%s:panel is null\n", __func__);
		return -EINVAL;
	}
	panel_data = &panel->panel_data;

	bd = panel->panel_bl.bd;
	if (bd == NULL) {
		panel_err("PANEL:ERR:%s:backlight device is null\n", __func__);
		return -EINVAL;
	}

	rc = kstrtoint(buf, 10, &value);
	if (rc < 0)
		return rc;

	mutex_lock(&panel->op_lock);
	panel_data->props.temperature = value;
	mutex_unlock(&panel->op_lock);
	backlight_update_status(bd);

	dev_info(dev, "%s, temperature %d\n",
			__func__, panel_data->props.temperature);

	return size;
}

static ssize_t read_mtp_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	return strlen(buf);
}

static ssize_t read_mtp_store(struct device *dev,
	struct device_attribute *attr, const char *buf, size_t size)
{
	struct panel_device *panel = dev_get_drvdata(dev);
	unsigned int reg, pos, length, i;
	int ret;
	unsigned char readbuf[256] = {0xff, };

	sscanf(buf, "%x %d %d", &reg, &pos, &length);

	if (!reg || !length || reg > 0xff || length > 255 || pos > 255)
		return -EINVAL;

	if (!IS_PANEL_ACTIVE(panel)) {
		return -EINVAL;
	}

	mutex_lock(&panel->op_lock);
	panel_set_key(panel, 3, true);
	ret = panel_rx_nbytes(panel, DSI_PKT_TYPE_RD, readbuf, reg, pos, length);
	panel_set_key(panel, 3, false);

	if (unlikely(ret != length)) {
		pr_err("%s, failed to read reg %02Xh pos %d len %d\n",
				__func__, reg, pos, length);
		ret = -EIO;
		goto store_err;
	}

	pr_info("READ_Reg addr : %02x, start pos : %d len : %d \n", reg, pos, length);
	for (i = 0; i < length; i++)
		pr_info("READ_Reg %dth : %02x \n", i + 1, readbuf[i]);

store_err:
	mutex_unlock(&panel->op_lock);
	return size;
}


static ssize_t mcd_mode_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	struct panel_info *panel_data;
	struct panel_device *panel = dev_get_drvdata(dev);

	if (panel == NULL) {
		panel_err("PANEL:ERR:%s:panel is null\n", __func__);
		return -EINVAL;
	}
	panel_data = &panel->panel_data;

	sprintf(buf, "%u\n", panel_data->props.mcd_on);

	return strlen(buf);
}

static ssize_t mcd_mode_store(struct device *dev,
	struct device_attribute *attr, const char *buf, size_t size)
{
	int value, rc, ret;
	struct panel_info *panel_data;
	struct panel_device *panel = dev_get_drvdata(dev);

	if (panel == NULL) {
		panel_err("PANEL:ERR:%s:panel is null\n", __func__);
		return -EINVAL;
	}
	panel_data = &panel->panel_data;

	rc = kstrtouint(buf, (unsigned int)0, &value);
	if (rc < 0)
		return rc;

	if (panel_data->props.mcd_on == value)
		return size;

	mutex_lock(&panel->op_lock);
	panel_data->props.mcd_on = value;
	mutex_unlock(&panel->op_lock);

	ret = panel_do_seqtbl_by_index(panel,
			value ? PANEL_MCD_ON_SEQ : PANEL_MCD_OFF_SEQ);
	if (unlikely(ret < 0)) {
		pr_err("%s, failed to write mcd seq\n", __func__);
		return ret;
	}
	dev_info(dev, "%s, mcd %s\n",
			__func__, panel_data->props.mcd_on ? "on" : "off");

	return size;
}

#ifdef CONFIG_SUPPORT_MST
static ssize_t mst_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	struct panel_info *panel_data;
	struct panel_device *panel = dev_get_drvdata(dev);

	if (panel == NULL) {
		panel_err("PANEL:ERR:%s:panel is null\n", __func__);
		return -EINVAL;
	}
	panel_data = &panel->panel_data;

	sprintf(buf, "%u\n", panel_data->props.mst_on);

	return strlen(buf);
}

static ssize_t mst_store(struct device *dev,
	struct device_attribute *attr, const char *buf, size_t size)
{
	int value, rc, ret;
	struct panel_info *panel_data;
	struct panel_device *panel = dev_get_drvdata(dev);

	if (panel == NULL) {
		panel_err("PANEL:ERR:%s:panel is null\n", __func__);
		return -EINVAL;
	}
	panel_data = &panel->panel_data;

	rc = kstrtouint(buf, (unsigned int)0, &value);
	if (rc < 0)
		return rc;

	if (panel_data->props.mst_on == value)
		return size;

	mutex_lock(&panel->op_lock);
	panel_data->props.mst_on = value;
	mutex_unlock(&panel->op_lock);

	ret = panel_do_seqtbl_by_index(panel,
			value ? PANEL_MST_ON_SEQ : PANEL_MST_OFF_SEQ);
	if (unlikely(ret < 0)) {
		pr_err("%s, failed to write mcd seq\n", __func__);
		return ret;
	}
	dev_info(dev, "%s, mst %s\n",
			__func__, panel_data->props.mst_on ? "on" : "off");

	return size;
}
#endif

#ifdef CONFIG_SUPPORT_XTALK_MODE
static ssize_t xtalk_mode_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	struct panel_info *panel_data;
	struct panel_device *panel = dev_get_drvdata(dev);

	if (panel == NULL) {
		panel_err("PANEL:ERR:%s:panel is null\n", __func__);
		return -EINVAL;
	}
	panel_data = &panel->panel_data;

	sprintf(buf, "%u\n", panel_data->props.xtalk_mode);

	return strlen(buf);
}

static ssize_t xtalk_mode_store(struct device *dev,
	struct device_attribute *attr, const char *buf, size_t size)
{
	int value, rc;
	struct panel_info *panel_data;
	struct panel_bl_device *panel_bl;
	struct panel_device *panel = dev_get_drvdata(dev);
	struct backlight_device *bd;

	if (panel == NULL) {
		panel_err("PANEL:ERR:%s:panel is null\n", __func__);
		return -EINVAL;
	}
	panel_data = &panel->panel_data;
	panel_bl = &panel->panel_bl;
	bd = panel_bl->bd;

	if (bd == NULL) {
		panel_err("PANEL:ERR:%s:backlight device is null\n", __func__);
		return -EINVAL;
	}

	rc = kstrtouint(buf, (unsigned int)0, &value);
	if (rc < 0)
		return rc;

	if (panel_data->props.xtalk_mode == value)
		return size;

	mutex_lock(&panel_bl->lock);
	panel_data->props.xtalk_mode = value;
	mutex_unlock(&panel_bl->lock);
	backlight_update_status(bd);

	dev_info(dev, "%s, xtalk_mode %d\n",
			__func__, panel_data->props.xtalk_mode);

	return size;
}
#endif

#ifdef CONFIG_SUPPORT_HMD
static ssize_t hmt_bright_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	struct panel_bl_device *panel_bl;
	struct panel_device *panel = dev_get_drvdata(dev);
	int size;

	if (panel == NULL) {
		panel_err("PANEL:ERR:%s:panel is null\n", __func__);
		return -EINVAL;
	}

	panel_bl = &panel->panel_bl;
	mutex_lock(&panel_bl->lock);
	if (panel_bl->props.id == PANEL_BL_SUBDEV_TYPE_DISP) {
		size = snprintf(buf, 30, "HMD off state\n");
	} else {
		size = sprintf(buf, "index : %d, brightenss : %d\n",
				panel_bl->props.actual_brightness_index,
				BRT_USER(panel_bl->props.brightness));
	}
	mutex_unlock(&panel_bl->lock);
	return size;
}

static ssize_t hmt_bright_store(struct device *dev,
	struct device_attribute *attr, const char *buf, size_t size)
{
	int value, rc, ret;
	struct panel_bl_device *panel_bl;
	struct panel_device *panel = dev_get_drvdata(dev);

	if (panel == NULL) {
		panel_err("PANEL:ERR:%s:panel is null\n", __func__);
		return -EINVAL;
	}
	panel_bl = &panel->panel_bl;

	rc = kstrtouint(buf, (unsigned int)0, &value);
	if (rc < 0)
		return rc;

	panel_info("PANEL:INFO:%s: brightness : %d\n",
			__func__, value);

	mutex_lock(&panel_bl->lock);
	if (panel_bl->subdev[PANEL_BL_SUBDEV_TYPE_HMD].brightness != BRT(value)) {
		panel_bl->subdev[PANEL_BL_SUBDEV_TYPE_HMD].brightness = BRT(value);
	}

	if (panel->state.hmd_on != PANEL_HMD_ON) {
		panel_info("PANEL:WARN:%s: hmd off\n", __func__);
		goto exit_store;
	}

	ret = panel_bl_set_brightness(panel_bl, PANEL_BL_SUBDEV_TYPE_HMD, 1);
	if (ret) {
		pr_err("%s : fail to set brightness\n", __func__);
		goto exit_store;
	}

exit_store:
	mutex_unlock(&panel_bl->lock);
	return size;
}

static ssize_t hmt_on_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	struct panel_state *state;
	struct panel_device *panel = dev_get_drvdata(dev);

	if (panel == NULL) {
		panel_err("PANEL:ERR:%s:panel is null\n", __func__);
		return -EINVAL;
	}
	state = &panel->state;

	sprintf(buf, "%u\n", state->hmd_on);

	return strlen(buf);
}

static ssize_t hmt_on_store(struct device *dev,
	struct device_attribute *attr, const char *buf, size_t size)
{
	int ret;
	int value, rc;
	struct backlight_device *bd;
	struct panel_state *state;
	struct panel_device *panel = dev_get_drvdata(dev);
	struct panel_bl_device *panel_bl;

	if (panel == NULL) {
		panel_err("PANEL:ERR:%s:panel is null\n", __func__);
		return -EINVAL;
	}

	panel_bl = &panel->panel_bl;
	bd = panel_bl->bd;
	state = &panel->state;

	rc = kstrtoint(buf, 0, &value);
	if (rc < 0)
		return rc;

	panel_info("PANEL:INFO:%s: hmt %s\n",
			__func__, value ? "on" : "off");

	if (value == state->hmd_on) {
		panel_warn("PANEL:WARN:%s:already set : %d\n",
			__func__, value);
		return size;
	}

	mutex_lock(&panel_bl->lock);
	if (value == PANEL_HMD_ON) {
		ret = panel_do_seqtbl_by_index(panel, PANEL_HMD_ON_SEQ);
		if (ret) {
			panel_err("PANEL:ERR:%s:failed to set hmd on seq\n", __func__);
			goto exit_store;
		}
		ret = panel_bl_set_brightness(panel_bl, PANEL_BL_SUBDEV_TYPE_HMD, 1);
		if (ret) {
			pr_err("%s : fail to set brightness\n", __func__);
			goto exit_store;
		}
	} else {
		ret = panel_do_seqtbl_by_index(panel, PANEL_HMD_OFF_SEQ);
		if (ret) {
			panel_err("PANEL:ERR:%s:failed to set hmd off seq\n",
				__func__);
			goto exit_store;
		}
		ret = panel_bl_set_brightness(panel_bl, PANEL_BL_SUBDEV_TYPE_DISP, 1);
		if (ret) {
			pr_err("%s : fail to set brightness\n", __func__);
			goto exit_store;
		}
	}
	state->hmd_on = value;

exit_store:
	mutex_unlock(&panel_bl->lock);
	return size;
}
#endif /* CONFIG_SUPPORT_HMD */

#ifdef CONFIG_SUPPORT_DOZE

#ifdef CONFIG_SEC_FACTORY

static int backup_br = 0;
static int factory_set_alpm(struct panel_device *panel, int mode)
{
	int ret = 0;
	struct backlight_device *bd = panel->panel_bl.bd;
	struct panel_info *panel_data = &panel->panel_data;

	if (mode == panel_data->props.alpm_mode) {
		goto do_exit;
	}

	switch (mode) {
		case ALPM_LOW_BR:
		case HLPM_LOW_BR:
		case ALPM_HIGH_BR:
		case HLPM_HIGH_BR:
			if (panel_data->props.alpm_mode == ALPM_OFF) {
				backup_br = bd->props.brightness;
				bd->props.brightness = UI_MIN_BRIGHTNESS;
				backlight_update_status(bd);
			}
			panel_data->props.alpm_mode = mode;
			ret = panel_do_seqtbl_by_index(panel, PANEL_ALPM_ENTER_SEQ);
			if (unlikely(ret < 0)) {
				panel_err("PANEL:ERR:%s, failed to write init seqtbl\n",
					__func__);
			}
		break;

	case ALPM_OFF:
		if (backup_br) {
			bd->props.brightness = backup_br;
			backlight_update_status(bd);
		}
		ret = panel_do_seqtbl_by_index(panel, PANEL_ALPM_EXIT_SEQ);
		if (unlikely(ret < 0)) {
			panel_err("PANEL:ERR:%s, failed to write init seqtbl\n",
				__func__);
		}
		panel_data->props.alpm_mode = mode;
		break;

	default:
		panel_err("PANEL:ERR:%s:Invalid ALPM Mode : %d\n", __func__, mode);
		goto do_exit;
	}

	return ret;

do_exit:
	return ret;
}
#endif // CONFIG_SEC_FACTORY

static int set_alpm_mode(struct panel_device *panel, int mode)
{
	int ret = 0;
	struct panel_info *panel_data = &panel->panel_data;

	switch (mode) {
		case ALPM_LOW_BR:
		case HLPM_LOW_BR:
		case ALPM_HIGH_BR:
		case HLPM_HIGH_BR:
			if (panel->state.cur_state != PANEL_STATE_ALPM) {
				panel_info("PANEL:INFO:%s:panel state : %d\n", __func__,
					panel->state.cur_state);
				return 0;
			}
			if (mode != panel_data->props.alpm_mode) {
				panel_data->props.alpm_mode = mode;
				ret = panel_do_seqtbl_by_index(panel, PANEL_ALPM_ENTER_SEQ);
				if (ret) {
					panel_err("PANEL:ERR:%s, failed to write init seqtbl\n",
						__func__);
				}
			}
			break;
		default:
			panel_err("PANEL:ERR:%s:Invalid ALPM Mode : %d\n", __func__, mode);
			break;
	}
	return ret;
}
#endif

static ssize_t alpm_store(struct device *dev,
	struct device_attribute *attr, const char *buf, size_t size)
{
	int value;
	struct panel_device *panel = dev_get_drvdata(dev);
	struct panel_info *panel_data = &panel->panel_data;

	mutex_lock(&panel->io_lock);

	sscanf(buf, "%9d", &value);

	panel_info("PANEL:INFO:%s:mode : %d\n", __func__, value);
#ifdef CONFIG_SUPPORT_DOZE
#ifdef CONFIG_SEC_FACTORY
	if (factory_set_alpm(panel, value))
		panel_err("PANEL:ERR:%s:failed to set factory alpm\n", __func__);
	goto exit_store;
#endif
	if (set_alpm_mode(panel, value)) {
		panel_err("PANEL:ERR:%s:failed to set alpm\n", __func__);
		goto exit_store;
	}
#endif
	panel_data->props.alpm_mode = value;

#if defined(CONFIG_SUPPORT_DOZE)
exit_store:
#endif
	mutex_unlock(&panel->io_lock);
	return size;
}

static ssize_t alpm_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	struct panel_info *panel_data;
	struct panel_device *panel = dev_get_drvdata(dev);

	if (panel == NULL) {
		panel_err("PANEL:ERR:%s:panel is null\n", __func__);
		return -EINVAL;
	}
	panel_data = &panel->panel_data;

	sprintf(buf, "%d\n", panel_data->props.alpm_mode);
	panel_dbg("%s: %d\n", __func__, panel_data->props.alpm_mode);

	return strlen(buf);
}

#ifdef CONFIG_PANEL_AID_DIMMING
static void show_aid_log(struct panel_info *panel_data, int id)
{
	struct dimming_info *dim_info;
	struct maptbl *tbl = NULL, *aor_tbl = NULL, *irc_tbl = NULL;
	int layer, row, col, i;
	char buf[1024], *p;
	struct panel_device *panel = to_panel_device(panel_data);
	struct panel_bl_device *panel_bl = &panel->panel_bl;
	struct panel_bl_sub_dev *subdev;

	if (unlikely(!panel_data)) {
		panel_err("%s:panel is NULL\n", __func__);
		return;
	}

	if (id >= MAX_PANEL_BL_SUBDEV) {
		panel_err("%s invalid bl-%d\n", __func__, id);
		return;
	}

	subdev = &panel_bl->subdev[id];

	pr_info("[====================== [%s] ======================]\n",
			(id == PANEL_BL_SUBDEV_TYPE_HMD ? "HMD" : "DISP"));
	dim_info = panel_data->dim_info[id];
	if (!dim_info) {
		panel_warn("%s bl-%d dim_info is null\n", __func__, id);
		return;
	}

	print_dimming_info(dim_info, TAG_MTP_OFFSET_START);
	print_dimming_info(dim_info, TAG_TP_VOLT_START);
	print_dimming_info(dim_info, TAG_GRAY_SCALE_VOLT_START);
	print_dimming_info(dim_info, TAG_GAMMA_CENTER_START);

	/* TODO : 0 means GAMMA_MAPTBL.
	          To use commonly in panel driver some maptbl index should be same
	 */
	if (id == PANEL_BL_SUBDEV_TYPE_HMD)
		tbl = find_panel_maptbl_by_name(panel_data, "hmd_gamma_table");
	else
		tbl = find_panel_maptbl_by_name(panel_data, "gamma_table");

	if (tbl) {
		pr_info("[GAMMA MAPTBL] HEXA-DECIMAL\n");
		for_each_layer(tbl, layer) {
			for_each_row(tbl, row) {
				p = buf;
				p += sprintf(p, "gamma[%3d] : ",
						subdev->brt_tbl.lum[row]);
				for_each_col(tbl, i)
					p += sprintf(p, "%02X ",
							tbl->arr[row * sizeof_row(tbl) + i]);
				pr_info("%s\n", buf);
			}
		}
	}

	if (id == PANEL_BL_SUBDEV_TYPE_HMD)
		aor_tbl = find_panel_maptbl_by_name(panel_data, "hmd_aor_table");
	else
		aor_tbl = find_panel_maptbl_by_name(panel_data, "aor_table");

	if (id != PANEL_BL_SUBDEV_TYPE_HMD)
		irc_tbl = find_panel_maptbl_by_name(panel_data, "irc_table");

	panel_info("\n[BRIGHTNESS, %s %s table]\n",
			aor_tbl ? "AOR" : "", irc_tbl ? "IRC" : "");
	p = buf;
	p += sprintf(p, "[idx] platform   luminance  ");
	if (aor_tbl)
		p += sprintf(p, "|  aor  ");
	if (irc_tbl)
		p += sprintf(p, "| =========================== irc ===========================");
	pr_info("%s\n", buf);

	for (i = 0; i < subdev->brt_tbl.sz_brt_to_step; i++) {
		p = buf;
		p += sprintf(p, "[%3d]   %-5d   %3d(%3d.%02d) ", i,
				subdev->brt_tbl.brt_to_step[i],
				get_subdev_actual_brightness(panel_bl, id,
					subdev->brt_tbl.brt_to_step[i]),
				get_subdev_actual_brightness_interpolation(panel_bl, id,
					subdev->brt_tbl.brt_to_step[i]) / 100,
				get_subdev_actual_brightness_interpolation(panel_bl, id,
					subdev->brt_tbl.brt_to_step[i]) % 100);
		if (aor_tbl) {
			p += sprintf(p, "| ");
			for_each_col(aor_tbl, col)
				p += sprintf(p, "%02X ", aor_tbl->arr[i * sizeof_row(aor_tbl) + col]);
		}

		if (irc_tbl) {
			p += sprintf(p, "| ");
			for_each_col(irc_tbl, col)
				p += sprintf(p, "%02X ", irc_tbl->arr[i * sizeof_row(irc_tbl) + col]);
		}
		pr_info("%s\n", buf);
	}
}

static ssize_t aid_log_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	struct panel_info *panel_data;
	struct panel_device *panel = dev_get_drvdata(dev);

	if (panel == NULL) {
		panel_err("PANEL:ERR:%s:panel is null\n", __func__);
		return -EINVAL;
	}
	panel_data = &panel->panel_data;

	print_panel_resource(panel);

	show_aid_log(panel_data, PANEL_BL_SUBDEV_TYPE_DISP);
#ifdef CONFIG_SUPPORT_HMD
	show_aid_log(panel_data, PANEL_BL_SUBDEV_TYPE_HMD);
#endif

	return strlen(buf);
}
#endif /* CONFIG_PANEL_AID_DIMMING */

#ifdef CONFIG_LCD_WEAKNESS_CCB
void ccb_set_mode(struct panel_device *panel, u8 ccb, int stepping)
{
#if 0
	u8 ccb_cmd[3] = {0xB7, 0x00, 0x00};
	u8 secondval = 0;

	dsim_write_hl_data(dsim, SEQ_TEST_KEY_ON_F0, ARRAY_SIZE(SEQ_TEST_KEY_ON_F0));
	switch (dsim->priv.panel_type) {

	case LCD_TYPE_S6E3HF4_WQHD:
		ccb_cmd[1] = ccb;
		ccb_cmd[2] = 0x2A;
		dsim_write_hl_data(dsim, ccb_cmd, ARRAY_SIZE(ccb_cmd));
		break;
	case LCD_TYPE_S6E3HA3_WQHD:
		if((ccb & 0x0F) == 0x00) {		// off
			if(stepping) {
				ccb_cmd[1] = dsim->priv.current_ccb;
				for(secondval = 0x2A; secondval <= 0x3F; secondval += 1) {
					ccb_cmd[2] = secondval;
					dsim_write_hl_data(dsim, ccb_cmd, ARRAY_SIZE(ccb_cmd));
					msleep(17);
				}
			}
			ccb_cmd[1] = 0x00;
			ccb_cmd[2] = 0x3F;
			dsim_write_hl_data(dsim, ccb_cmd, ARRAY_SIZE(ccb_cmd));
		} else {						// on
			ccb_cmd[1] = ccb;
			if(stepping) {
				for(secondval = 0x3F; secondval >= 0x2A; secondval -= 1) {
					ccb_cmd[2] = secondval;
					dsim_write_hl_data(dsim, ccb_cmd, ARRAY_SIZE(ccb_cmd));
					if(secondval != 0x2A)
						msleep(17);
				}
			} else {
				ccb_cmd[2] = 0x2A;
				dsim_write_hl_data(dsim, ccb_cmd, ARRAY_SIZE(ccb_cmd));
			}
		}
		msleep(17);
		break;
	default:
		pr_info("%s unknown panel \n", __func__);
		break;
	}

	dsim_write_hl_data(dsim, SEQ_TEST_KEY_OFF_F0, ARRAY_SIZE(SEQ_TEST_KEY_OFF_F0));
#endif
}

static ssize_t weakness_ccb_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	return strlen(buf);
}

static ssize_t weakness_ccb_store(struct device *dev,
	struct device_attribute *attr, const char *buf, size_t size)
{
	int ret, type, serverity;
	unsigned char set_ccb = 0x00;
	struct panel_info *panel_data;
	struct panel_device *panel = dev_get_drvdata(dev);

	if (panel == NULL) {
		panel_err("PANEL:ERR:%s:panel is null\n", __func__);
		return -EINVAL;
	}
	panel_data = &panel->panel_data;

	ret = sscanf(buf, "%d %d", &type, &serverity);
	if (ret < 0)
		return ret;

	dev_info(dev, "%s: type = %d serverity = %d\n", __func__, type, serverity);

	if (panel_data->ccb_support == UNSUPPORT_CCB) {
		pr_info("%s, CCB unsupported\n", __func__);
		return size;
	}

	if ((type < 0) || (type > 3)) {
		dev_info(dev, "%s: type is out of range\n", __func__);
		return -EINVAL;
	}

	if ((serverity < 0) || (serverity > 9)) {
		dev_info(dev, "%s: serverity is out of range\n", __func__);
		return -EINVAL;
	}

	set_ccb = ((u8)(serverity) << 4);
	switch (type) {
		case 0:
			set_ccb = 0;
			panel_dbg("%s: disable ccb\n", __func__);
			break;
		case 1:
			set_ccb += 1;
			panel_dbg("%s: enable red\n", __func__);
			break;
		case 2:
			set_ccb += 5;
			panel_dbg( "%s: enable green\n", __func__);
			break;
		case 3:
			if (serverity == 0) {
				set_ccb += 9;
				panel_dbg("%s: enable blue\n", __func__);
			} else {
				set_ccb = 0;
				set_ccb += 9;
				panel_dbg("%s, serverity is out of range, blue only support 0\n", __func__);
			}
			break;
		default:
			set_ccb = 0;
			break;
	}
	if (panel->current_ccb == set_ccb) {
		panel_dbg("%s: aleady set same ccb\n", __func__);
	} else {
		ccb_set_mode(panel, set_ccb, 1);
		panel_data->current_ccb = set_ccb;
	}
	dev_info(dev, "%s: --\n", __func__);

	return size;
}
#endif /* CONFIG_LCD_WEAKNESS_CCB */

#if defined(CONFIG_EXYNOS_DECON_MDNIE_LITE)
static ssize_t lux_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	struct panel_info *panel_data;
	struct panel_device *panel = dev_get_drvdata(dev);

	if (panel == NULL) {
		panel_err("PANEL:ERR:%s:panel is null\n", __func__);
		return -EINVAL;
	}
	panel_data = &panel->panel_data;

	sprintf(buf, "%d\n", panel_data->props.lux);

	return strlen(buf);
}

static ssize_t lux_store(struct device *dev,
	struct device_attribute *attr, const char *buf, size_t size)
{
	int rc;
	int value;
	struct mdnie_info *mdnie;
	struct panel_info *panel_data;
	struct panel_device *panel = dev_get_drvdata(dev);

	if (panel == NULL) {
		panel_err("PANEL:ERR:%s:panel is null\n", __func__);
		return -EINVAL;
	}
	mdnie = &panel->mdnie;
	panel_data = &panel->panel_data;

	rc = kstrtoint(buf, 0, &value);

	if (rc < 0)
		return rc;

	if (panel_data->props.lux != value) {
		mutex_lock(&panel->op_lock);
		panel_data->props.lux = value;
		mutex_unlock(&panel->op_lock);
		attr_store_for_each(mdnie->class, attr->attr.name, buf, size);
	}

	return size;
}
#endif /* CONFIG_EXYNOS_DECON_MDNIE_LITE */

#ifdef CONFIG_EXYNOS_DECON_LCD_COPR
static ssize_t copr_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	struct panel_device *panel = dev_get_drvdata(dev);
	struct copr_info *copr = &panel->copr;
	int copr_avg, brt_avg, ret;

	if (!copr_is_enabled(copr)) {
		panel_err("%s copr is off state\n", __func__);
		return -EIO;
	}

	ret = copr_get_average(copr, &copr_avg, &brt_avg);
	if (ret < 0) {
		panel_err("%s failed to get average\n", __func__);
		return ret;
	}

	sprintf(buf, "%d %d\n", copr_avg, brt_avg);

	return strlen(buf);
}

static ssize_t copr_store(struct device *dev,
	struct device_attribute *attr, const char *buf, size_t size)
{
	struct panel_device *panel = dev_get_drvdata(dev);
	struct copr_info *copr = &panel->copr;
	int copr_en, copr_gamma, copr_er, copr_eg, copr_eb;
	int roi_on, roi_xs, roi_ys, roi_xe, roi_ye;
	int rc;

	rc = sscanf(buf, "%i %i %i %i %i %i %i %i %i %i",
			&copr_en, &copr_gamma, &copr_er, &copr_eg, &copr_eb,
			&roi_on, &roi_xs, &roi_ys, &roi_xe, &roi_ye);
	if (rc < 0)
		return rc;

	mutex_lock(&copr->lock);
	if (copr->props.reg.copr_en != !!copr_en) {
		copr->props.reg.copr_en = !!copr_en;
		copr->props.state = COPR_UNINITIALIZED;
		pr_info("%s copr %s\n", __func__, copr_en ? "enable" : "disable");
	}

	if ((copr_gamma == 0 || copr_gamma == 1) &&
			(copr_er > 0 && copr_er < 0xFF) &&
			(copr_eg > 0 && copr_eg < 0xFF) &&
			(copr_eb > 0 && copr_eb < 0xFF) &&
			((copr_er + copr_eg + copr_eb) == 384) &&
			(roi_on == 0 || roi_on == 1)) {
		copr->props.reg.copr_gamma = !!copr_gamma;
		copr->props.reg.copr_er = copr_er;
		copr->props.reg.copr_eg = copr_eg;
		copr->props.reg.copr_eb = copr_eb;
		copr->props.reg.roi_on = !!roi_on;

		if (roi_on && (roi_xs % 4 == 0) && (roi_xe % 4 == 3) && (roi_xe - roi_xs + 1 >= 12) &&
				(roi_ys % 4 == 0) && (roi_ye % 4 == 3) && (roi_ye - roi_ys + 1 >= 12)) {
			copr->props.reg.roi_xs = roi_xs;
			copr->props.reg.roi_ys = roi_ys;
			copr->props.reg.roi_xe = roi_xe;
			copr->props.reg.roi_ye = roi_ye;
		}
		pr_info("%s copr en %d gamma %d er 0x%02X eg 0x%02X eb 0x%02X\n",
				__func__, copr_en, copr_gamma, copr_er, copr_eg, copr_eb);
		copr->props.state = COPR_UNINITIALIZED;
	}
	mutex_unlock(&copr->lock);
	copr_update_start(&panel->copr, 1);

	return size;
}

static ssize_t read_copr_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	struct panel_device *panel = dev_get_drvdata(dev);
	struct copr_info *copr = &panel->copr;
	int cur_copr;

	if (!copr_is_enabled(copr)) {
		panel_err("%s copr is off state\n", __func__);
		return -EIO;
	}

	cur_copr = copr_get_value(copr);
	if (cur_copr < 0) {
		panel_err("%s failed to get copr\n", __func__);
		return -EIO;
	}

	sprintf(buf, "%d\n", cur_copr);

	return strlen(buf);
}
#endif

#if 0
#ifdef CONFIG_ACTIVE_CLOCK
static ssize_t active_clock_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	int len = 0;
	struct act_clk_info *info;
	struct panel_device *panel = dev_get_drvdata(dev);

	info = &panel->act_clk_dev.act_info;

	len = sprintf(buf, "active en : %d\n", info->en);
	len += sprintf(buf+len, "interval : %d ms\n", info->interval);
	len += sprintf(buf+len, "time %d:%d:%d:%d\n",
		info->time_hr, info->time_min, info->time_sec, info->time_ms);
	len += sprintf(buf+len, "pos : %d, %d\n", info->pos_x, info->pos_y);

	return strlen(buf);
}

static ssize_t active_clock_store(struct device *dev,
	struct device_attribute *attr, const char *buf, size_t size)
{
	int rc;
	struct act_clk_info *info;
	struct act_clk_info new_info;
	struct panel_device *panel = dev_get_drvdata(dev);

	panel_info("%s was called\n", __func__);

	info = &panel->act_clk_dev.act_info;

	rc = sscanf(buf, "%d %d %d %d %d %d %d %d\n",
			&new_info.en, &new_info.interval, &new_info.time_hr, &new_info.time_min,
			&new_info.time_sec, &new_info.time_ms, &new_info.pos_x, &new_info.pos_y);

	if (rc < 0)
		return rc;

	info->en = new_info.en;
	info->interval = new_info.interval;
	info->time_hr = new_info.time_hr;
	info->time_min = new_info.time_min;
	info->time_sec = new_info.time_sec;
	info->time_ms = new_info.time_ms;
	info->pos_x = new_info.pos_x;
	info->pos_y = new_info.pos_y;

	return size;
}


static ssize_t active_blink_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	int len = 0;
	struct act_blink_info *info;
	struct panel_device *panel = dev_get_drvdata(dev);

	info = &panel->act_clk_dev.blink_info;

	len = sprintf(buf, "blink en : %d\n", info->en);
	len += sprintf(buf+len, "interval : %d ms\n", info->interval);
	len += sprintf(buf+len, "pos %d:%d:%d:%d\n",
		info->pos1_x, info->pos1_y, info->pos2_x, info->pos2_y);
	len += sprintf(buf+len, "radius : %d,  color : %x\n", info->radius, info->color);

	return strlen(buf);
}

static ssize_t active_blink_store(struct device *dev,
	struct device_attribute *attr, const char *buf, size_t size)
{
	int rc;
	struct act_blink_info *info;
	struct act_blink_info new_info;
	struct panel_device *panel = dev_get_drvdata(dev);

	panel_info("%s was called\n", __func__);

	info = &panel->act_clk_dev.blink_info;

	rc = sscanf(buf, "%d %d %d %d %d %d %d %d %d\n",
			&new_info.en, &new_info.interval, &new_info.color, &new_info.radius, &new_info.line_width,
			&new_info.pos1_x, &new_info.pos1_y, &new_info.pos2_x, &new_info.pos2_y);

	switch (new_info.color) {
		case 0 :
			new_info.color = 0x000000;
			break;
		case 1 :
			new_info.color = 0x0000ff;
			break;
		case 2 :
			new_info.color = 0x00ff00;
			break;
		case 3:
			new_info.color = 0xff0000;
			break;
		case 4:
			new_info.color = 0xffffff;
			break;
	}

	if (rc < 0)
		return rc;

	info->en = new_info.en;
	info->interval = new_info.interval;
	info->radius = new_info.radius;
	info->color = new_info.color;
	info->line_width = new_info.line_width;
	info->pos1_x = new_info.pos1_x;
	info->pos1_y = new_info.pos1_y;
	info->pos2_x = new_info.pos2_x;
	info->pos2_y = new_info.pos2_y;

	return size;
}
#endif
#endif
#ifdef CONFIG_DISPLAY_USE_INFO
/*
 * HW PARAM LOGGING SYSFS NODE
 */
static ssize_t dpui_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	update_dpui_log(DPUI_LOG_LEVEL_INFO);
	get_dpui_log(buf, DPUI_LOG_LEVEL_INFO);

	pr_info("%s\n", buf);

	return strlen(buf);
}

static ssize_t dpui_store(struct device *dev,
	struct device_attribute *attr, const char *buf, size_t size)
{
	if (buf[0] == 'C' || buf[0] == 'c' )
		clear_dpui_log(DPUI_LOG_LEVEL_INFO);

	return size;
}

/*
 * [DEV ONLY]
 * HW PARAM LOGGING SYSFS NODE
 */
static ssize_t dpui_dbg_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	update_dpui_log(DPUI_LOG_LEVEL_DEBUG);
	get_dpui_log(buf, DPUI_LOG_LEVEL_DEBUG);

	pr_info("%s\n", buf);

	return strlen(buf);
}

static ssize_t dpui_dbg_store(struct device *dev,
	struct device_attribute *attr, const char *buf, size_t size)
{
	if (buf[0] == 'C' || buf[0] == 'c' )
		clear_dpui_log(DPUI_LOG_LEVEL_DEBUG);

	return size;
}
#endif

struct device_attribute panel_attrs[] = {
	__PANEL_ATTR_RO(lcd_type, 0444),
	__PANEL_ATTR_RO(window_type, 0444),
	__PANEL_ATTR_RO(manufacture_code, 0444),
	__PANEL_ATTR_RO(cell_id, 0444),
	__PANEL_ATTR_RO(SVC_OCTA, 0444),
#ifdef CONFIG_SEC_FACTORY
	__PANEL_ATTR_RO(octa_id, 0444),
#endif
#ifdef CONFIG_SUPPORT_XTALK_MODE
	__PANEL_ATTR_RW(xtalk_mode, 0664),
#endif
#ifdef CONFIG_SUPPORT_MST
	__PANEL_ATTR_RW(mst, 0664),
#endif
	__PANEL_ATTR_RO(color_coordinate, 0444),
	__PANEL_ATTR_RO(manufacture_date, 0444),
	__PANEL_ATTR_RO(brightness_table, 0444),
	__PANEL_ATTR_RW(adaptive_control, 0664),
	__PANEL_ATTR_RW(siop_enable, 0664),
	__PANEL_ATTR_RW(temperature, 0664),
	__PANEL_ATTR_RW(read_mtp, 0644),
	__PANEL_ATTR_RW(mcd_mode, 0664),
#ifdef CONFIG_PANEL_AID_DIMMING
	__PANEL_ATTR_RO(aid_log, 0440),
#endif
#ifdef CONFIG_LCD_WEAKNESS_CCB
	__PANEL_ATTR_RO(weakness_ccb, 0644),
#endif
#if defined(CONFIG_EXYNOS_DECON_MDNIE_LITE)
	__PANEL_ATTR_RW(lux, 0644),
#endif
#if defined(CONFIG_EXYNOS_DECON_LCD_COPR)
	__PANEL_ATTR_RW(copr, 0600),
	__PANEL_ATTR_RO(read_copr, 0440),
#endif
	__PANEL_ATTR_RW(alpm, 0664),
	__PANEL_ATTR_RW(fingerprint, 0644),
#if 0
#ifdef CONFIG_ACTIVE_CLOCK
	__PANEL_ATTR_RW(active_clock, 0644),
	__PANEL_ATTR_RW(active_blink, 0644),
#endif
#endif
#ifdef CONFIG_SUPPORT_HMD
	__PANEL_ATTR_RW(hmt_bright, 0664),
	__PANEL_ATTR_RW(hmt_on, 0664),
#endif
#ifdef CONFIG_DISPLAY_USE_INFO
	__PANEL_ATTR_RW(dpui, 0660),
	__PANEL_ATTR_RW(dpui_dbg, 0660),
#endif
};

int panel_sysfs_probe(struct panel_device *panel)
{
	struct lcd_device *lcd;
	int i, ret;
	struct kernfs_node *svc_sd;
	struct kobject *svc;

	lcd = panel->lcd;
	if (unlikely(!lcd)) {
		pr_err("%s, lcd device not exist\n", __func__);
		return -ENODEV;
	}

	for (i = 0; i < ARRAY_SIZE(panel_attrs); i++) {
		ret = device_create_file(&lcd->dev, &panel_attrs[i]);
		if (ret < 0) {
			dev_err(&lcd->dev, "%s, failed to add %s sysfs entries, %d\n",
					__func__, panel_attrs[i].attr.name, ret);
			return -ENODEV;
		}
	}

	/* to /sys/devices/svc/ */
	if (panel->id == 0) {
		svc_sd = sysfs_get_dirent(devices_kset->kobj.sd, "svc");
	} else if (panel->id == 1) {
		svc_sd = sysfs_get_dirent(devices_kset->kobj.sd, "svc_1");
	} else {
		panel_err("PANEL:ERR:%s:invalid panel id : %d\n", __func__, panel->id);
		return -EINVAL;
	}
	if (IS_ERR_OR_NULL(svc_sd)) {
		svc = kobject_create_and_add("svc", &devices_kset->kobj);
		if (IS_ERR_OR_NULL(svc))
			pr_err("failed to create /sys/devices/svc already exist svc : 0x%p\n", svc);
		else
			pr_err("success to create /sys/devices/svc svc : 0x%p\n", svc);
	} else {
		svc = (struct kobject*)svc_sd->priv;
		pr_info("success to find svc_sd : 0x%p  svc : 0x%p\n", svc_sd, svc);
	}

	if (!IS_ERR_OR_NULL(svc)) {
		ret = sysfs_create_link(svc, &lcd->dev.kobj, "OCTA");
		if (ret)
			pr_err("failed to create svc/OCTA/ \n");
		else
			pr_info("success to create svc/OCTA/ \n");
	} else {
		pr_err("failed to find svc kobject\n");
	}

	return 0;
}