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
|
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) 2016-2020, The Linux Foundation. All rights reserved.
*/
#include <drm/drm_atomic_helper.h>
#include <drm/drm_atomic.h>
#include "msm_kms.h"
#include "sde_connector.h"
#include "dsi_drm.h"
#include "sde_trace.h"
#include "sde_dbg.h"
#if defined(CONFIG_DISPLAY_SAMSUNG)
#include "ss_dsi_panel_common.h"
#endif
#define to_dsi_bridge(x) container_of((x), struct dsi_bridge, base)
#define to_dsi_state(x) container_of((x), struct dsi_connector_state, base)
#define DEFAULT_PANEL_JITTER_NUMERATOR 2
#define DEFAULT_PANEL_JITTER_DENOMINATOR 1
#define DEFAULT_PANEL_JITTER_ARRAY_SIZE 2
#define DEFAULT_PANEL_PREFILL_LINES 25
static struct dsi_display_mode_priv_info default_priv_info = {
.panel_jitter_numer = DEFAULT_PANEL_JITTER_NUMERATOR,
.panel_jitter_denom = DEFAULT_PANEL_JITTER_DENOMINATOR,
.panel_prefill_lines = DEFAULT_PANEL_PREFILL_LINES,
.dsc_enabled = false,
};
static void convert_to_dsi_mode(const struct drm_display_mode *drm_mode,
struct dsi_display_mode *dsi_mode)
{
memset(dsi_mode, 0, sizeof(*dsi_mode));
dsi_mode->timing.h_active = drm_mode->hdisplay;
dsi_mode->timing.h_back_porch = drm_mode->htotal - drm_mode->hsync_end;
dsi_mode->timing.h_sync_width = drm_mode->htotal -
(drm_mode->hsync_start + dsi_mode->timing.h_back_porch);
dsi_mode->timing.h_front_porch = drm_mode->hsync_start -
drm_mode->hdisplay;
dsi_mode->timing.h_skew = drm_mode->hskew;
dsi_mode->timing.v_active = drm_mode->vdisplay;
dsi_mode->timing.v_back_porch = drm_mode->vtotal - drm_mode->vsync_end;
dsi_mode->timing.v_sync_width = drm_mode->vtotal -
(drm_mode->vsync_start + dsi_mode->timing.v_back_porch);
dsi_mode->timing.v_front_porch = drm_mode->vsync_start -
drm_mode->vdisplay;
dsi_mode->timing.refresh_rate = drm_mode->vrefresh;
dsi_mode->pixel_clk_khz = drm_mode->clock;
dsi_mode->priv_info =
(struct dsi_display_mode_priv_info *)drm_mode->private;
if (dsi_mode->priv_info) {
dsi_mode->timing.dsc_enabled = dsi_mode->priv_info->dsc_enabled;
dsi_mode->timing.dsc = &dsi_mode->priv_info->dsc;
dsi_mode->timing.vdc_enabled = dsi_mode->priv_info->vdc_enabled;
dsi_mode->timing.vdc = &dsi_mode->priv_info->vdc;
dsi_mode->timing.pclk_scale = dsi_mode->priv_info->pclk_scale;
}
if (msm_is_mode_seamless(drm_mode))
dsi_mode->dsi_mode_flags |= DSI_MODE_FLAG_SEAMLESS;
if (msm_is_mode_dynamic_fps(drm_mode))
dsi_mode->dsi_mode_flags |= DSI_MODE_FLAG_DFPS;
if (msm_needs_vblank_pre_modeset(drm_mode))
dsi_mode->dsi_mode_flags |= DSI_MODE_FLAG_VBLANK_PRE_MODESET;
if (msm_is_mode_seamless_dms(drm_mode))
dsi_mode->dsi_mode_flags |= DSI_MODE_FLAG_DMS;
if (msm_is_mode_seamless_vrr(drm_mode))
dsi_mode->dsi_mode_flags |= DSI_MODE_FLAG_VRR;
if (msm_is_mode_seamless_poms(drm_mode))
dsi_mode->dsi_mode_flags |= DSI_MODE_FLAG_POMS;
if (msm_is_mode_seamless_dyn_clk(drm_mode))
dsi_mode->dsi_mode_flags |= DSI_MODE_FLAG_DYN_CLK;
dsi_mode->timing.h_sync_polarity =
!!(drm_mode->flags & DRM_MODE_FLAG_PHSYNC);
dsi_mode->timing.v_sync_polarity =
!!(drm_mode->flags & DRM_MODE_FLAG_PVSYNC);
if (drm_mode->flags & DRM_MODE_FLAG_VID_MODE_PANEL)
dsi_mode->panel_mode = DSI_OP_VIDEO_MODE;
if (drm_mode->flags & DRM_MODE_FLAG_CMD_MODE_PANEL)
dsi_mode->panel_mode = DSI_OP_CMD_MODE;
#if defined(CONFIG_DISPLAY_SAMSUNG)
dsi_mode->timing.sot_hs_mode = ss_is_sot_hs_from_drm_mode(drm_mode);
dsi_mode->timing.phs_mode = ss_is_phs_from_drm_mode(drm_mode);
#endif
}
void dsi_convert_to_drm_mode(const struct dsi_display_mode *dsi_mode,
struct drm_display_mode *drm_mode)
{
bool video_mode = (dsi_mode->panel_mode == DSI_OP_VIDEO_MODE);
memset(drm_mode, 0, sizeof(*drm_mode));
drm_mode->hdisplay = dsi_mode->timing.h_active;
drm_mode->hsync_start = drm_mode->hdisplay +
dsi_mode->timing.h_front_porch;
drm_mode->hsync_end = drm_mode->hsync_start +
dsi_mode->timing.h_sync_width;
drm_mode->htotal = drm_mode->hsync_end + dsi_mode->timing.h_back_porch;
drm_mode->hskew = dsi_mode->timing.h_skew;
drm_mode->vdisplay = dsi_mode->timing.v_active;
drm_mode->vsync_start = drm_mode->vdisplay +
dsi_mode->timing.v_front_porch;
drm_mode->vsync_end = drm_mode->vsync_start +
dsi_mode->timing.v_sync_width;
drm_mode->vtotal = drm_mode->vsync_end + dsi_mode->timing.v_back_porch;
drm_mode->vrefresh = dsi_mode->timing.refresh_rate;
drm_mode->clock = dsi_mode->pixel_clk_khz;
drm_mode->private = (int *)dsi_mode->priv_info;
if (dsi_mode->dsi_mode_flags & DSI_MODE_FLAG_SEAMLESS)
drm_mode->flags |= DRM_MODE_FLAG_SEAMLESS;
if (dsi_mode->dsi_mode_flags & DSI_MODE_FLAG_DFPS)
drm_mode->private_flags |= MSM_MODE_FLAG_SEAMLESS_DYNAMIC_FPS;
if (dsi_mode->dsi_mode_flags & DSI_MODE_FLAG_VBLANK_PRE_MODESET)
drm_mode->private_flags |= MSM_MODE_FLAG_VBLANK_PRE_MODESET;
if (dsi_mode->dsi_mode_flags & DSI_MODE_FLAG_DMS)
drm_mode->private_flags |= MSM_MODE_FLAG_SEAMLESS_DMS;
if (dsi_mode->dsi_mode_flags & DSI_MODE_FLAG_VRR)
drm_mode->private_flags |= MSM_MODE_FLAG_SEAMLESS_VRR;
if (dsi_mode->dsi_mode_flags & DSI_MODE_FLAG_POMS)
drm_mode->private_flags |= MSM_MODE_FLAG_SEAMLESS_POMS;
if (dsi_mode->dsi_mode_flags & DSI_MODE_FLAG_DYN_CLK)
drm_mode->private_flags |= MSM_MODE_FLAG_SEAMLESS_DYN_CLK;
if (dsi_mode->timing.h_sync_polarity)
drm_mode->flags |= DRM_MODE_FLAG_PHSYNC;
if (dsi_mode->timing.v_sync_polarity)
drm_mode->flags |= DRM_MODE_FLAG_PVSYNC;
if (dsi_mode->panel_mode == DSI_OP_VIDEO_MODE)
drm_mode->flags |= DRM_MODE_FLAG_VID_MODE_PANEL;
if (dsi_mode->panel_mode == DSI_OP_CMD_MODE)
drm_mode->flags |= DRM_MODE_FLAG_CMD_MODE_PANEL;
#if defined(CONFIG_DISPLAY_SAMSUNG)
snprintf(drm_mode->name, DRM_DISPLAY_MODE_LEN, "%dx%dx%dx%d%s%s",
drm_mode->hdisplay, drm_mode->vdisplay,
drm_mode->vrefresh, drm_mode->clock,
video_mode ? "vid" : "cmd",
dsi_mode->timing.sot_hs_mode ? ( dsi_mode->timing.phs_mode ? "PHS" : "HS") : "NS");
#else
/* set mode name */
snprintf(drm_mode->name, DRM_DISPLAY_MODE_LEN, "%dx%dx%dx%d%s",
drm_mode->hdisplay, drm_mode->vdisplay,
drm_mode->vrefresh, drm_mode->clock,
video_mode ? "vid" : "cmd");
#endif
}
static int dsi_bridge_attach(struct drm_bridge *bridge)
{
struct dsi_bridge *c_bridge = to_dsi_bridge(bridge);
if (!bridge) {
DSI_ERR("Invalid params\n");
return -EINVAL;
}
DSI_DEBUG("[%d] attached\n", c_bridge->id);
return 0;
}
static void dsi_bridge_pre_enable(struct drm_bridge *bridge)
{
int rc = 0;
struct dsi_bridge *c_bridge = to_dsi_bridge(bridge);
if (!bridge) {
DSI_ERR("Invalid params\n");
return;
}
if (!c_bridge || !c_bridge->display || !c_bridge->display->panel) {
DSI_ERR("Incorrect bridge details\n");
return;
}
atomic_set(&c_bridge->display->panel->esd_recovery_pending, 0);
/* By this point mode should have been validated through mode_fixup */
rc = dsi_display_set_mode(c_bridge->display,
&(c_bridge->dsi_mode), 0x0);
if (rc) {
DSI_ERR("[%d] failed to perform a mode set, rc=%d\n",
c_bridge->id, rc);
return;
}
if (c_bridge->dsi_mode.dsi_mode_flags &
(DSI_MODE_FLAG_SEAMLESS | DSI_MODE_FLAG_VRR |
DSI_MODE_FLAG_DYN_CLK)) {
DSI_DEBUG("[%d] seamless pre-enable\n", c_bridge->id);
return;
}
SDE_ATRACE_BEGIN("dsi_display_prepare");
rc = dsi_display_prepare(c_bridge->display);
if (rc) {
DSI_ERR("[%d] DSI display prepare failed, rc=%d\n",
c_bridge->id, rc);
SDE_ATRACE_END("dsi_display_prepare");
return;
}
SDE_ATRACE_END("dsi_display_prepare");
SDE_ATRACE_BEGIN("dsi_display_enable");
rc = dsi_display_enable(c_bridge->display);
if (rc) {
DSI_ERR("[%d] DSI display enable failed, rc=%d\n",
c_bridge->id, rc);
(void)dsi_display_unprepare(c_bridge->display);
}
SDE_ATRACE_END("dsi_display_enable");
rc = dsi_display_splash_res_cleanup(c_bridge->display);
if (rc)
DSI_ERR("Continuous splash pipeline cleanup failed, rc=%d\n",
rc);
}
static void dsi_bridge_enable(struct drm_bridge *bridge)
{
int rc = 0;
struct dsi_bridge *c_bridge = to_dsi_bridge(bridge);
struct dsi_display *display;
if (!bridge) {
DSI_ERR("Invalid params\n");
return;
}
if (c_bridge->dsi_mode.dsi_mode_flags &
(DSI_MODE_FLAG_SEAMLESS | DSI_MODE_FLAG_VRR |
DSI_MODE_FLAG_DYN_CLK)) {
DSI_DEBUG("[%d] seamless enable\n", c_bridge->id);
return;
}
display = c_bridge->display;
rc = dsi_display_post_enable(display);
if (rc)
DSI_ERR("[%d] DSI display post enabled failed, rc=%d\n",
c_bridge->id, rc);
if (display && display->drm_conn) {
sde_connector_helper_bridge_enable(display->drm_conn);
if (c_bridge->dsi_mode.dsi_mode_flags & DSI_MODE_FLAG_POMS)
sde_connector_schedule_status_work(display->drm_conn,
true);
}
}
static void dsi_bridge_disable(struct drm_bridge *bridge)
{
int rc = 0;
int private_flags;
struct dsi_display *display;
struct dsi_bridge *c_bridge = to_dsi_bridge(bridge);
if (!bridge) {
DSI_ERR("Invalid params\n");
return;
}
display = c_bridge->display;
private_flags =
bridge->encoder->crtc->state->adjusted_mode.private_flags;
if (display && display->drm_conn) {
display->poms_pending =
private_flags & MSM_MODE_FLAG_SEAMLESS_POMS;
sde_connector_helper_bridge_disable(display->drm_conn);
}
rc = dsi_display_pre_disable(c_bridge->display);
if (rc) {
DSI_ERR("[%d] DSI display pre disable failed, rc=%d\n",
c_bridge->id, rc);
}
}
static void dsi_bridge_post_disable(struct drm_bridge *bridge)
{
int rc = 0;
struct dsi_bridge *c_bridge = to_dsi_bridge(bridge);
if (!bridge) {
DSI_ERR("Invalid params\n");
return;
}
SDE_ATRACE_BEGIN("dsi_bridge_post_disable");
SDE_ATRACE_BEGIN("dsi_display_disable");
rc = dsi_display_disable(c_bridge->display);
if (rc) {
DSI_ERR("[%d] DSI display disable failed, rc=%d\n",
c_bridge->id, rc);
SDE_ATRACE_END("dsi_display_disable");
return;
}
SDE_ATRACE_END("dsi_display_disable");
rc = dsi_display_unprepare(c_bridge->display);
if (rc) {
DSI_ERR("[%d] DSI display unprepare failed, rc=%d\n",
c_bridge->id, rc);
SDE_ATRACE_END("dsi_bridge_post_disable");
return;
}
SDE_ATRACE_END("dsi_bridge_post_disable");
}
static void dsi_bridge_mode_set(struct drm_bridge *bridge,
const struct drm_display_mode *mode,
const struct drm_display_mode *adjusted_mode)
{
struct dsi_bridge *c_bridge = to_dsi_bridge(bridge);
if (!bridge || !mode || !adjusted_mode) {
DSI_ERR("Invalid params\n");
return;
}
memset(&(c_bridge->dsi_mode), 0x0, sizeof(struct dsi_display_mode));
convert_to_dsi_mode(adjusted_mode, &(c_bridge->dsi_mode));
/* restore bit_clk_rate also for dynamic clk use cases */
c_bridge->dsi_mode.timing.clk_rate_hz =
dsi_drm_find_bit_clk_rate(c_bridge->display, adjusted_mode);
DSI_DEBUG("clk_rate: %llu\n", c_bridge->dsi_mode.timing.clk_rate_hz);
}
static bool dsi_bridge_mode_fixup(struct drm_bridge *bridge,
const struct drm_display_mode *mode,
struct drm_display_mode *adjusted_mode)
{
int rc = 0;
struct dsi_bridge *c_bridge = to_dsi_bridge(bridge);
struct dsi_display *display;
struct dsi_display_mode dsi_mode, cur_dsi_mode, *panel_dsi_mode;
struct drm_crtc_state *crtc_state;
crtc_state = container_of(mode, struct drm_crtc_state, mode);
if (!bridge || !mode || !adjusted_mode) {
DSI_ERR("Invalid params\n");
return false;
}
display = c_bridge->display;
if (!display) {
DSI_ERR("Invalid params\n");
return false;
}
/*
* if no timing defined in panel, it must be external mode
* and we'll use empty priv info to populate the mode
*/
if (display->panel && !display->panel->num_timing_nodes) {
*adjusted_mode = *mode;
adjusted_mode->private = (int *)&default_priv_info;
adjusted_mode->private_flags = 0;
return true;
}
convert_to_dsi_mode(mode, &dsi_mode);
/*
* retrieve dsi mode from dsi driver's cache since not safe to take
* the drm mode config mutex in all paths
*/
rc = dsi_display_find_mode(display, &dsi_mode, &panel_dsi_mode);
if (rc)
return rc;
/* propagate the private info to the adjusted_mode derived dsi mode */
dsi_mode.priv_info = panel_dsi_mode->priv_info;
dsi_mode.dsi_mode_flags = panel_dsi_mode->dsi_mode_flags;
dsi_mode.timing.dsc_enabled = dsi_mode.priv_info->dsc_enabled;
dsi_mode.timing.dsc = &dsi_mode.priv_info->dsc;
rc = dsi_display_validate_mode(c_bridge->display, &dsi_mode,
DSI_VALIDATE_FLAG_ALLOW_ADJUST);
if (rc) {
DSI_ERR("[%d] mode is not valid, rc=%d\n", c_bridge->id, rc);
return false;
}
if (bridge->encoder && bridge->encoder->crtc &&
crtc_state->crtc) {
const struct drm_display_mode *cur_mode =
&crtc_state->crtc->state->mode;
convert_to_dsi_mode(cur_mode, &cur_dsi_mode);
cur_dsi_mode.timing.dsc_enabled =
dsi_mode.priv_info->dsc_enabled;
cur_dsi_mode.timing.dsc = &dsi_mode.priv_info->dsc;
rc = dsi_display_validate_mode_change(c_bridge->display,
&cur_dsi_mode, &dsi_mode);
if (rc) {
DSI_ERR("[%s] seamless mode mismatch failure rc=%d\n",
c_bridge->display->name, rc);
return false;
}
/* No panel mode switch when drm pipeline is changing */
if ((dsi_mode.panel_mode != cur_dsi_mode.panel_mode) &&
(!(dsi_mode.dsi_mode_flags & DSI_MODE_FLAG_VRR)) &&
(crtc_state->enable ==
crtc_state->crtc->state->enable)) {
dsi_mode.dsi_mode_flags |= DSI_MODE_FLAG_POMS;
SDE_EVT32(SDE_EVTLOG_FUNC_CASE1,
dsi_mode.timing.h_active,
dsi_mode.timing.v_active,
dsi_mode.timing.refresh_rate,
dsi_mode.pixel_clk_khz,
dsi_mode.panel_mode);
}
/* No DMS/VRR when drm pipeline is changing */
if (!drm_mode_equal(cur_mode, adjusted_mode) &&
(!(dsi_mode.dsi_mode_flags & DSI_MODE_FLAG_VRR)) &&
(!(dsi_mode.dsi_mode_flags & DSI_MODE_FLAG_POMS)) &&
(!(dsi_mode.dsi_mode_flags & DSI_MODE_FLAG_DYN_CLK)) &&
(!crtc_state->active_changed ||
display->is_cont_splash_enabled))
#if defined(CONFIG_DISPLAY_SAMSUNG)
{
if (display->panel->panel_initialized || display->is_cont_splash_enabled) {
struct samsung_display_driver_data *vdd = display->panel->panel_private;
struct vrr_info *vrr = &vdd->vrr;
bool adjusted_sot_hs, adjusted_phs;
bool cur_sot_hs, cur_phs;
vrr->adjusted_refresh_rate = adjusted_mode->vrefresh;
cur_sot_hs = ss_is_sot_hs_from_drm_mode(cur_mode);
cur_phs = ss_is_phs_from_drm_mode(cur_mode);
adjusted_sot_hs = ss_is_sot_hs_from_drm_mode(adjusted_mode);
adjusted_phs = ss_is_phs_from_drm_mode(adjusted_mode);
vrr->adjusted_sot_hs_mode = adjusted_sot_hs;
vrr->adjusted_phs_mode = adjusted_phs;
vrr->cur_h_active = cur_mode->hdisplay;
vrr->cur_v_active = cur_mode->vdisplay;
vrr->adjusted_h_active = adjusted_mode->hdisplay;
vrr->adjusted_v_active = adjusted_mode->vdisplay;
/* vrr->cur_refresh_rate valuse is changed in Bridge RR,
* so use cur_mode info.
*/
if ((cur_mode->vrefresh != adjusted_mode->vrefresh) ||
(cur_sot_hs != adjusted_sot_hs) ||
(cur_phs != adjusted_phs)) {
LCD_INFO("DMS: VRR flag: %d -> 1\n", vrr->is_vrr_changing);
vrr->is_vrr_changing = true;
vdd->vrr.running_vrr_mdp = true;
}
if ((cur_mode->hdisplay != adjusted_mode->hdisplay) ||
(cur_mode->vdisplay != adjusted_mode->vdisplay)) {
LCD_INFO("DMS: MULTI RES flag: %d -> 1\n",
vrr->is_multi_resolution_changing);
vrr->is_multi_resolution_changing = true;
}
dsi_mode.dsi_mode_flags |= DSI_MODE_FLAG_DMS;
/* Set max sde core clock to prevent screen noise due to
* unbalanced clock between MDP and panel
* SDE core clock will be restored in ss_panel_vrr_switch()
* after finish VRR change.
*/
rc = ss_set_max_sde_core_clk(display->drm_dev);
if (rc) {
LCD_ERR("fail to set max sde core clock..(%d)\n", rc);
SS_XLOG(rc, 0xebad);
}
SS_XLOG(cur_mode->vrefresh, cur_sot_hs, cur_phs, adjusted_mode->vrefresh, adjusted_sot_hs);
LCD_INFO("DMS: switch mode %s(%dx%d@%d%s) -> %s(%dx%d@%d%s)\n",
cur_mode->name,
cur_mode->hdisplay,
cur_mode->vdisplay,
cur_mode->vrefresh,
cur_sot_hs ? (cur_phs ? "PHS" : "HS") : "NS",
adjusted_mode->name,
adjusted_mode->hdisplay,
adjusted_mode->vdisplay,
adjusted_mode->vrefresh,
adjusted_sot_hs ? (adjusted_phs ? "PHS" : "HS") : "NS");
}
} else if (!drm_mode_equal(cur_mode, adjusted_mode)) {
/* In case of that
* - display power state is changing,
* - splash is enabled yet, or
* - VRR, POMS, or DYN_CLK is set,
* it will apply display_mode in dsi_display_mode() function without set DMS flag.
*
* But, Samsung VRR should apply target VRR mode in vrr->cur_refresh_rate.
* Brightness setting will apply current VRR mode, and apply it to UB.
* So, in this corner case, just save target VRR mode in vrr->cur_refresh_rate.
*
* Even it is only multi resolution scenario, not VRR scenario,
* it should save resolution for VRR, and it is harmless to save
* current and target refresh rate to intended refresh rate.
*/
struct samsung_display_driver_data *vdd = display->panel->panel_private;
struct vrr_info *vrr = &vdd->vrr;
bool adjusted_sot_hs, adjusted_phs;
bool cur_sot_hs, cur_phs;
cur_sot_hs = ss_is_sot_hs_from_drm_mode(cur_mode);
cur_phs = ss_is_phs_from_drm_mode(cur_mode);
adjusted_sot_hs = ss_is_sot_hs_from_drm_mode(adjusted_mode);
adjusted_phs = ss_is_phs_from_drm_mode(adjusted_mode);
vrr->cur_refresh_rate = vrr->adjusted_refresh_rate =
adjusted_mode->vrefresh;
vrr->cur_sot_hs_mode = vrr->adjusted_sot_hs_mode =
adjusted_sot_hs;
vrr->cur_phs_mode = vrr->adjusted_phs_mode =
adjusted_phs;
vrr->cur_h_active = vrr->adjusted_h_active =
adjusted_mode->hdisplay;
vrr->cur_v_active = vrr->adjusted_v_active =
adjusted_mode->vdisplay;
SS_XLOG(cur_mode->vrefresh, cur_sot_hs, cur_phs,
adjusted_mode->vrefresh, adjusted_sot_hs,
crtc_state->active_changed, display->is_cont_splash_enabled);
LCD_INFO("DMS: switch mode %s(%dx%d@%d%s) -> %s(%dx%d@%d%s) " \
"during active_changed(%d) or splash(%d)\n",
cur_mode->name,
cur_mode->hdisplay,
cur_mode->vdisplay,
cur_mode->vrefresh,
cur_sot_hs ? (cur_phs ? "PHS" : "HS") : "NM",
adjusted_mode->name,
adjusted_mode->hdisplay,
adjusted_mode->vdisplay,
adjusted_mode->vrefresh,
adjusted_sot_hs ? (adjusted_phs ? "PHS" : "HS") : "NM",
crtc_state->active_changed,
display->is_cont_splash_enabled);
}
#else
dsi_mode.dsi_mode_flags |= DSI_MODE_FLAG_DMS;
SDE_EVT32(SDE_EVTLOG_FUNC_CASE2,
dsi_mode.timing.h_active,
dsi_mode.timing.v_active,
dsi_mode.timing.refresh_rate,
dsi_mode.pixel_clk_khz,
dsi_mode.panel_mode);
}
#endif
}
/* Reject seamless transition when active changed */
if (crtc_state->active_changed &&
((dsi_mode.dsi_mode_flags & DSI_MODE_FLAG_VRR) ||
(dsi_mode.dsi_mode_flags & DSI_MODE_FLAG_POMS) ||
(dsi_mode.dsi_mode_flags & DSI_MODE_FLAG_DYN_CLK))) {
DSI_INFO("seamless upon active changed 0x%x %d\n",
dsi_mode.dsi_mode_flags, crtc_state->active_changed);
return false;
}
/* convert back to drm mode, propagating the private info & flags */
dsi_convert_to_drm_mode(&dsi_mode, adjusted_mode);
return true;
}
u32 dsi_drm_get_dfps_maxfps(void *display)
{
u32 dfps_maxfps = 0;
struct dsi_display *dsi_display = display;
/*
* The time of SDE transmitting one frame active data
* will not be changed, if frame rate is adjusted with
* VFP method.
* So only return max fps of DFPS for UIDLE update, if DFPS
* is enabled with VFP.
*/
if (dsi_display && dsi_display->panel &&
dsi_display->panel->panel_mode == DSI_OP_VIDEO_MODE &&
dsi_display->panel->dfps_caps.type ==
DSI_DFPS_IMMEDIATE_VFP)
dfps_maxfps =
dsi_display->panel->dfps_caps.max_refresh_rate;
return dfps_maxfps;
}
u64 dsi_drm_find_bit_clk_rate(void *display,
const struct drm_display_mode *drm_mode)
{
int i = 0, count = 0;
struct dsi_display *dsi_display = display;
struct dsi_display_mode *dsi_mode;
u64 bit_clk_rate = 0;
if (!dsi_display || !drm_mode)
return 0;
dsi_display_get_mode_count(dsi_display, &count);
for (i = 0; i < count; i++) {
dsi_mode = &dsi_display->modes[i];
if ((dsi_mode->timing.v_active == drm_mode->vdisplay) &&
(dsi_mode->timing.h_active == drm_mode->hdisplay) &&
(dsi_mode->pixel_clk_khz == drm_mode->clock) &&
(dsi_mode->timing.refresh_rate == drm_mode->vrefresh)) {
bit_clk_rate = dsi_mode->timing.clk_rate_hz;
break;
}
}
return bit_clk_rate;
}
int dsi_conn_get_mode_info(struct drm_connector *connector,
const struct drm_display_mode *drm_mode,
struct msm_mode_info *mode_info,
void *display, const struct msm_resource_caps_info *avail_res)
{
struct dsi_display_mode dsi_mode;
struct dsi_mode_info *timing;
int src_bpp, tar_bpp;
if (!drm_mode || !mode_info)
return -EINVAL;
convert_to_dsi_mode(drm_mode, &dsi_mode);
if (!dsi_mode.priv_info)
return -EINVAL;
memset(mode_info, 0, sizeof(*mode_info));
timing = &dsi_mode.timing;
mode_info->frame_rate = dsi_mode.timing.refresh_rate;
mode_info->vtotal = DSI_V_TOTAL(timing);
mode_info->prefill_lines = dsi_mode.priv_info->panel_prefill_lines;
mode_info->jitter_numer = dsi_mode.priv_info->panel_jitter_numer;
mode_info->jitter_denom = dsi_mode.priv_info->panel_jitter_denom;
mode_info->clk_rate = dsi_drm_find_bit_clk_rate(display, drm_mode);
mode_info->dfps_maxfps = dsi_drm_get_dfps_maxfps(display);
mode_info->mdp_transfer_time_us =
dsi_mode.priv_info->mdp_transfer_time_us;
#if defined(CONFIG_DISPLAY_SAMSUNG)
mode_info->frame_rate_org = mode_info->frame_rate;
#endif
memcpy(&mode_info->topology, &dsi_mode.priv_info->topology,
sizeof(struct msm_display_topology));
if (dsi_mode.priv_info->dsc_enabled) {
mode_info->comp_info.comp_type = MSM_DISPLAY_COMPRESSION_DSC;
mode_info->topology.comp_type = MSM_DISPLAY_COMPRESSION_DSC;
memcpy(&mode_info->comp_info.dsc_info, &dsi_mode.priv_info->dsc,
sizeof(dsi_mode.priv_info->dsc));
} else if (dsi_mode.priv_info->vdc_enabled) {
mode_info->comp_info.comp_type = MSM_DISPLAY_COMPRESSION_VDC;
mode_info->topology.comp_type = MSM_DISPLAY_COMPRESSION_VDC;
memcpy(&mode_info->comp_info.vdc_info, &dsi_mode.priv_info->vdc,
sizeof(dsi_mode.priv_info->vdc));
}
if (mode_info->comp_info.comp_type) {
tar_bpp = dsi_mode.priv_info->pclk_scale.numer;
src_bpp = dsi_mode.priv_info->pclk_scale.denom;
mode_info->comp_info.comp_ratio = mult_frac(1, src_bpp,
tar_bpp);
mode_info->wide_bus_en = dsi_mode.priv_info->widebus_support;
}
if (dsi_mode.priv_info->roi_caps.enabled) {
memcpy(&mode_info->roi_caps, &dsi_mode.priv_info->roi_caps,
sizeof(dsi_mode.priv_info->roi_caps));
}
mode_info->allowed_mode_switches =
dsi_mode.priv_info->allowed_mode_switch;
return 0;
}
static const struct drm_bridge_funcs dsi_bridge_ops = {
.attach = dsi_bridge_attach,
.mode_fixup = dsi_bridge_mode_fixup,
.pre_enable = dsi_bridge_pre_enable,
.enable = dsi_bridge_enable,
.disable = dsi_bridge_disable,
.post_disable = dsi_bridge_post_disable,
.mode_set = dsi_bridge_mode_set,
};
int dsi_conn_set_info_blob(struct drm_connector *connector,
void *info, void *display, struct msm_mode_info *mode_info)
{
struct dsi_display *dsi_display = display;
struct dsi_panel *panel;
enum dsi_pixel_format fmt;
u32 bpp;
if (!info || !dsi_display)
return -EINVAL;
dsi_display->drm_conn = connector;
sde_kms_info_add_keystr(info,
"display type", dsi_display->display_type);
switch (dsi_display->type) {
case DSI_DISPLAY_SINGLE:
sde_kms_info_add_keystr(info, "display config",
"single display");
break;
case DSI_DISPLAY_EXT_BRIDGE:
sde_kms_info_add_keystr(info, "display config", "ext bridge");
break;
case DSI_DISPLAY_SPLIT:
sde_kms_info_add_keystr(info, "display config",
"split display");
break;
case DSI_DISPLAY_SPLIT_EXT_BRIDGE:
sde_kms_info_add_keystr(info, "display config",
"split ext bridge");
break;
default:
DSI_DEBUG("invalid display type:%d\n", dsi_display->type);
break;
}
if (!dsi_display->panel) {
DSI_DEBUG("invalid panel data\n");
goto end;
}
panel = dsi_display->panel;
sde_kms_info_add_keystr(info, "panel name", panel->name);
switch (panel->panel_mode) {
case DSI_OP_VIDEO_MODE:
sde_kms_info_add_keystr(info, "panel mode", "video");
sde_kms_info_add_keystr(info, "qsync support",
panel->qsync_caps.qsync_min_fps ?
"true" : "false");
break;
case DSI_OP_CMD_MODE:
sde_kms_info_add_keystr(info, "panel mode", "command");
sde_kms_info_add_keyint(info, "mdp_transfer_time_us",
mode_info->mdp_transfer_time_us);
sde_kms_info_add_keystr(info, "qsync support",
panel->qsync_caps.qsync_min_fps ?
"true" : "false");
break;
default:
DSI_DEBUG("invalid panel type:%d\n", panel->panel_mode);
break;
}
sde_kms_info_add_keystr(info, "dfps support",
panel->dfps_caps.dfps_support ? "true" : "false");
if (panel->dfps_caps.dfps_support) {
sde_kms_info_add_keyint(info, "min_fps",
panel->dfps_caps.min_refresh_rate);
sde_kms_info_add_keyint(info, "max_fps",
panel->dfps_caps.max_refresh_rate);
}
sde_kms_info_add_keystr(info, "dyn bitclk support",
panel->dyn_clk_caps.dyn_clk_support ? "true" : "false");
switch (panel->phy_props.rotation) {
case DSI_PANEL_ROTATE_NONE:
sde_kms_info_add_keystr(info, "panel orientation", "none");
break;
case DSI_PANEL_ROTATE_H_FLIP:
sde_kms_info_add_keystr(info, "panel orientation", "horz flip");
break;
case DSI_PANEL_ROTATE_V_FLIP:
sde_kms_info_add_keystr(info, "panel orientation", "vert flip");
break;
case DSI_PANEL_ROTATE_HV_FLIP:
sde_kms_info_add_keystr(info, "panel orientation",
"horz & vert flip");
break;
default:
DSI_DEBUG("invalid panel rotation:%d\n",
panel->phy_props.rotation);
break;
}
switch (panel->bl_config.type) {
case DSI_BACKLIGHT_PWM:
sde_kms_info_add_keystr(info, "backlight type", "pwm");
break;
case DSI_BACKLIGHT_WLED:
sde_kms_info_add_keystr(info, "backlight type", "wled");
break;
case DSI_BACKLIGHT_DCS:
sde_kms_info_add_keystr(info, "backlight type", "dcs");
break;
default:
DSI_DEBUG("invalid panel backlight type:%d\n",
panel->bl_config.type);
break;
}
if (panel->spr_info.enable)
sde_kms_info_add_keystr(info, "spr_pack_type",
msm_spr_pack_type_str[panel->spr_info.pack_type]);
if (mode_info && mode_info->roi_caps.enabled) {
sde_kms_info_add_keyint(info, "partial_update_num_roi",
mode_info->roi_caps.num_roi);
sde_kms_info_add_keyint(info, "partial_update_xstart",
mode_info->roi_caps.align.xstart_pix_align);
sde_kms_info_add_keyint(info, "partial_update_walign",
mode_info->roi_caps.align.width_pix_align);
sde_kms_info_add_keyint(info, "partial_update_wmin",
mode_info->roi_caps.align.min_width);
sde_kms_info_add_keyint(info, "partial_update_ystart",
mode_info->roi_caps.align.ystart_pix_align);
sde_kms_info_add_keyint(info, "partial_update_halign",
mode_info->roi_caps.align.height_pix_align);
sde_kms_info_add_keyint(info, "partial_update_hmin",
mode_info->roi_caps.align.min_height);
sde_kms_info_add_keyint(info, "partial_update_roimerge",
mode_info->roi_caps.merge_rois);
}
fmt = dsi_display->config.common_config.dst_format;
bpp = dsi_ctrl_pixel_format_to_bpp(fmt);
sde_kms_info_add_keyint(info, "bit_depth", bpp);
end:
return 0;
}
enum drm_connector_status dsi_conn_detect(struct drm_connector *conn,
bool force,
void *display)
{
enum drm_connector_status status = connector_status_unknown;
struct msm_display_info info;
int rc;
if (!conn || !display)
return status;
/* get display dsi_info */
memset(&info, 0x0, sizeof(info));
rc = dsi_display_get_info(conn, &info, display);
if (rc) {
DSI_ERR("failed to get display info, rc=%d\n", rc);
return connector_status_disconnected;
}
if (info.capabilities & MSM_DISPLAY_CAP_HOT_PLUG)
status = (info.is_connected ? connector_status_connected :
connector_status_disconnected);
else
status = connector_status_connected;
conn->display_info.width_mm = info.width_mm;
conn->display_info.height_mm = info.height_mm;
return status;
}
void dsi_connector_put_modes(struct drm_connector *connector,
void *display)
{
struct drm_display_mode *drm_mode;
struct dsi_display_mode dsi_mode;
struct dsi_display *dsi_display;
if (!connector || !display)
return;
list_for_each_entry(drm_mode, &connector->modes, head) {
convert_to_dsi_mode(drm_mode, &dsi_mode);
dsi_display_put_mode(display, &dsi_mode);
}
/* free the display structure modes also */
dsi_display = display;
kfree(dsi_display->modes);
dsi_display->modes = NULL;
}
static int dsi_drm_update_edid_name(struct edid *edid, const char *name)
{
u8 *dtd = (u8 *)&edid->detailed_timings[3];
u8 standard_header[] = {0x00, 0x00, 0x00, 0xFE, 0x00};
u32 dtd_size = 18;
u32 header_size = sizeof(standard_header);
if (!name)
return -EINVAL;
/* Fill standard header */
memcpy(dtd, standard_header, header_size);
dtd_size -= header_size;
dtd_size = min_t(u32, dtd_size, strlen(name));
memcpy(dtd + header_size, name, dtd_size);
return 0;
}
static void dsi_drm_update_dtd(struct edid *edid,
struct dsi_display_mode *modes, u32 modes_count)
{
u32 i;
u32 count = min_t(u32, modes_count, 3);
for (i = 0; i < count; i++) {
struct detailed_timing *dtd = &edid->detailed_timings[i];
struct dsi_display_mode *mode = &modes[i];
struct dsi_mode_info *timing = &mode->timing;
struct detailed_pixel_timing *pd = &dtd->data.pixel_data;
u32 h_blank = timing->h_front_porch + timing->h_sync_width +
timing->h_back_porch;
u32 v_blank = timing->v_front_porch + timing->v_sync_width +
timing->v_back_porch;
u32 h_img = 0, v_img = 0;
dtd->pixel_clock = mode->pixel_clk_khz / 10;
pd->hactive_lo = timing->h_active & 0xFF;
pd->hblank_lo = h_blank & 0xFF;
pd->hactive_hblank_hi = ((h_blank >> 8) & 0xF) |
((timing->h_active >> 8) & 0xF) << 4;
pd->vactive_lo = timing->v_active & 0xFF;
pd->vblank_lo = v_blank & 0xFF;
pd->vactive_vblank_hi = ((v_blank >> 8) & 0xF) |
((timing->v_active >> 8) & 0xF) << 4;
pd->hsync_offset_lo = timing->h_front_porch & 0xFF;
pd->hsync_pulse_width_lo = timing->h_sync_width & 0xFF;
pd->vsync_offset_pulse_width_lo =
((timing->v_front_porch & 0xF) << 4) |
(timing->v_sync_width & 0xF);
pd->hsync_vsync_offset_pulse_width_hi =
(((timing->h_front_porch >> 8) & 0x3) << 6) |
(((timing->h_sync_width >> 8) & 0x3) << 4) |
(((timing->v_front_porch >> 4) & 0x3) << 2) |
(((timing->v_sync_width >> 4) & 0x3) << 0);
pd->width_mm_lo = h_img & 0xFF;
pd->height_mm_lo = v_img & 0xFF;
pd->width_height_mm_hi = (((h_img >> 8) & 0xF) << 4) |
((v_img >> 8) & 0xF);
pd->hborder = 0;
pd->vborder = 0;
pd->misc = 0;
}
}
static void dsi_drm_update_checksum(struct edid *edid)
{
u8 *data = (u8 *)edid;
u32 i, sum = 0;
for (i = 0; i < EDID_LENGTH - 1; i++)
sum += data[i];
edid->checksum = 0x100 - (sum & 0xFF);
}
int dsi_connector_get_modes(struct drm_connector *connector, void *data,
const struct msm_resource_caps_info *avail_res)
{
int rc, i;
u32 count = 0, edid_size;
struct dsi_display_mode *modes = NULL;
struct drm_display_mode drm_mode;
struct dsi_display *display = data;
struct edid edid;
#if defined(CONFIG_DISPLAY_SAMSUNG)
unsigned int width_mm = connector->display_info.width_mm;
unsigned int height_mm = connector->display_info.height_mm;
#else
u8 width_mm = connector->display_info.width_mm;
u8 height_mm = connector->display_info.height_mm;
#endif
const u8 edid_buf[EDID_LENGTH] = {
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x44, 0x6D,
0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x1B, 0x10, 0x01, 0x03,
0x80, 0x00, 0x00, 0x78, 0x0A, 0x0D, 0xC9, 0xA0, 0x57, 0x47,
0x98, 0x27, 0x12, 0x48, 0x4C, 0x00, 0x00, 0x00, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01,
};
edid_size = min_t(u32, sizeof(edid), EDID_LENGTH);
memcpy(&edid, edid_buf, edid_size);
rc = dsi_display_get_mode_count(display, &count);
if (rc) {
DSI_ERR("failed to get num of modes, rc=%d\n", rc);
goto end;
}
rc = dsi_display_get_modes(display, &modes);
if (rc) {
DSI_ERR("failed to get modes, rc=%d\n", rc);
count = 0;
goto end;
}
for (i = 0; i < count; i++) {
struct drm_display_mode *m;
memset(&drm_mode, 0x0, sizeof(drm_mode));
dsi_convert_to_drm_mode(&modes[i], &drm_mode);
m = drm_mode_duplicate(connector->dev, &drm_mode);
if (!m) {
DSI_ERR("failed to add mode %ux%u\n",
drm_mode.hdisplay,
drm_mode.vdisplay);
count = -ENOMEM;
goto end;
}
m->width_mm = connector->display_info.width_mm;
m->height_mm = connector->display_info.height_mm;
if (display->cmdline_timing != NO_OVERRIDE) {
/* get the preferred mode from dsi display mode */
if (modes[i].is_preferred)
m->type |= DRM_MODE_TYPE_PREFERRED;
} else if (i == 0) {
/* set the first mode in list as preferred */
m->type |= DRM_MODE_TYPE_PREFERRED;
}
drm_mode_probed_add(connector, m);
}
rc = dsi_drm_update_edid_name(&edid, display->panel->name);
if (rc) {
count = 0;
goto end;
}
edid.width_cm = (connector->display_info.width_mm) / 10;
edid.height_cm = (connector->display_info.height_mm) / 10;
dsi_drm_update_dtd(&edid, modes, count);
dsi_drm_update_checksum(&edid);
rc = drm_connector_update_edid_property(connector, &edid);
if (rc)
count = 0;
/*
* DRM EDID structure maintains panel physical dimensions in
* centimeters, we will be losing the precision anything below cm.
* Changing DRM framework will effect other clients at this
* moment, overriding the values back to millimeter.
*/
connector->display_info.width_mm = width_mm;
connector->display_info.height_mm = height_mm;
end:
DSI_DEBUG("MODE COUNT =%d\n\n", count);
return count;
}
enum drm_mode_status dsi_conn_mode_valid(struct drm_connector *connector,
struct drm_display_mode *mode,
void *display, const struct msm_resource_caps_info *avail_res)
{
struct dsi_display_mode dsi_mode;
int rc;
if (!connector || !mode) {
DSI_ERR("Invalid params\n");
return MODE_ERROR;
}
convert_to_dsi_mode(mode, &dsi_mode);
rc = dsi_display_validate_mode(display, &dsi_mode,
DSI_VALIDATE_FLAG_ALLOW_ADJUST);
if (rc) {
DSI_ERR("mode not supported, rc=%d\n", rc);
return MODE_BAD;
}
return MODE_OK;
}
int dsi_conn_pre_kickoff(struct drm_connector *connector,
void *display,
struct msm_display_kickoff_params *params)
{
if (!connector || !display || !params) {
DSI_ERR("Invalid params\n");
return -EINVAL;
}
return dsi_display_pre_kickoff(connector, display, params);
}
int dsi_conn_prepare_commit(void *display,
struct msm_display_conn_params *params)
{
if (!display || !params) {
pr_err("Invalid params\n");
return -EINVAL;
}
return dsi_display_pre_commit(display, params);
}
void dsi_conn_enable_event(struct drm_connector *connector,
uint32_t event_idx, bool enable, void *display)
{
struct dsi_event_cb_info event_info;
memset(&event_info, 0, sizeof(event_info));
event_info.event_cb = sde_connector_trigger_event;
event_info.event_usr_ptr = connector;
dsi_display_enable_event(connector, display,
event_idx, &event_info, enable);
}
int dsi_conn_post_kickoff(struct drm_connector *connector,
struct msm_display_conn_params *params)
{
struct drm_encoder *encoder;
struct dsi_bridge *c_bridge;
struct dsi_display_mode adj_mode;
struct dsi_display *display;
struct dsi_display_ctrl *m_ctrl, *ctrl;
int i, rc = 0, ctrl_version;
bool enable;
struct dsi_dyn_clk_caps *dyn_clk_caps;
if (!connector || !connector->state) {
DSI_ERR("invalid connector or connector state\n");
return -EINVAL;
}
encoder = connector->state->best_encoder;
if (!encoder) {
DSI_DEBUG("best encoder is not available\n");
return 0;
}
c_bridge = to_dsi_bridge(encoder->bridge);
adj_mode = c_bridge->dsi_mode;
display = c_bridge->display;
dyn_clk_caps = &(display->panel->dyn_clk_caps);
if (adj_mode.dsi_mode_flags & DSI_MODE_FLAG_VRR) {
m_ctrl = &display->ctrl[display->clk_master_idx];
ctrl_version = m_ctrl->ctrl->version;
rc = dsi_ctrl_timing_db_update(m_ctrl->ctrl, false);
if (rc) {
DSI_ERR("[%s] failed to dfps update rc=%d\n",
display->name, rc);
return -EINVAL;
}
if ((ctrl_version >= DSI_CTRL_VERSION_2_5) &&
(dyn_clk_caps->maintain_const_fps)) {
display_for_each_ctrl(i, display) {
ctrl = &display->ctrl[i];
rc = dsi_ctrl_wait4dynamic_refresh_done(
ctrl->ctrl);
if (rc)
DSI_ERR("wait4dfps refresh failed\n");
}
}
/* Update the rest of the controllers */
display_for_each_ctrl(i, display) {
ctrl = &display->ctrl[i];
if (!ctrl->ctrl || (ctrl == m_ctrl))
continue;
rc = dsi_ctrl_timing_db_update(ctrl->ctrl, false);
if (rc) {
DSI_ERR("[%s] failed to dfps update rc=%d\n",
display->name, rc);
return -EINVAL;
}
}
c_bridge->dsi_mode.dsi_mode_flags &= ~DSI_MODE_FLAG_VRR;
}
/* ensure dynamic clk switch flag is reset */
c_bridge->dsi_mode.dsi_mode_flags &= ~DSI_MODE_FLAG_DYN_CLK;
if (params->qsync_update) {
enable = (params->qsync_mode > 0) ? true : false;
display_for_each_ctrl(i, display)
dsi_ctrl_setup_avr(display->ctrl[i].ctrl, enable);
}
return 0;
}
struct dsi_bridge *dsi_drm_bridge_init(struct dsi_display *display,
struct drm_device *dev,
struct drm_encoder *encoder)
{
int rc = 0;
struct dsi_bridge *bridge;
bridge = kzalloc(sizeof(*bridge), GFP_KERNEL);
if (!bridge) {
rc = -ENOMEM;
goto error;
}
bridge->display = display;
bridge->base.funcs = &dsi_bridge_ops;
bridge->base.encoder = encoder;
rc = drm_bridge_attach(encoder, &bridge->base, NULL);
if (rc) {
DSI_ERR("failed to attach bridge, rc=%d\n", rc);
goto error_free_bridge;
}
encoder->bridge = &bridge->base;
return bridge;
error_free_bridge:
kfree(bridge);
error:
return ERR_PTR(rc);
}
void dsi_drm_bridge_cleanup(struct dsi_bridge *bridge)
{
if (bridge && bridge->base.encoder)
bridge->base.encoder->bridge = NULL;
kfree(bridge);
}
static bool is_valid_poms_switch(struct dsi_display_mode *mode_a,
struct dsi_display_mode *mode_b)
{
/*
* POMS cannot happen in conjunction with any other type of mode set.
* Check to ensure FPS remains same between the modes and also
* resolution.
*/
return((mode_a->timing.refresh_rate == mode_b->timing.refresh_rate) &&
(mode_a->timing.v_active == mode_b->timing.v_active) &&
(mode_a->timing.h_active == mode_b->timing.h_active));
}
void dsi_conn_set_allowed_mode_switch(struct drm_connector *connector,
void *display)
{
u32 mode_idx = 0, cmp_mode_idx = 0;
struct drm_display_mode *drm_mode, *cmp_drm_mode;
struct dsi_display_mode dsi_mode, *panel_dsi_mode, *cmp_panel_dsi_mode;
struct list_head *mode_list = &connector->modes;
struct dsi_display *disp = display;
struct dsi_panel *panel;
int mode_count, rc = 0;
struct dsi_display_mode_priv_info *dsi_mode_info, *cmp_dsi_mode_info;
bool allow_switch = false;
if (!disp || !disp->panel) {
DSI_ERR("invalid parameters");
return;
}
panel = disp->panel;
mode_count = panel->num_display_modes;
list_for_each_entry(drm_mode, &connector->modes, head) {
convert_to_dsi_mode(drm_mode, &dsi_mode);
rc = dsi_display_find_mode(display, &dsi_mode, &panel_dsi_mode);
if (rc)
return;
dsi_mode_info = panel_dsi_mode->priv_info;
dsi_mode_info->allowed_mode_switch |= BIT(mode_idx);
if (mode_idx == mode_count - 1)
break;
mode_list = mode_list->next;
cmp_mode_idx = 1;
list_for_each_entry(cmp_drm_mode, mode_list, head) {
convert_to_dsi_mode(cmp_drm_mode, &dsi_mode);
rc = dsi_display_find_mode(display, &dsi_mode,
&cmp_panel_dsi_mode);
if (rc)
return;
cmp_dsi_mode_info = cmp_panel_dsi_mode->priv_info;
allow_switch = false;
/*
* FPS switch among video modes, is only supported
* if DFPS or dynamic clocks are specified.
* Reject any mode switches between video mode timing
* nodes if support for those features is not present.
*/
if (panel_dsi_mode->panel_mode ==
cmp_panel_dsi_mode->panel_mode) {
if (panel_dsi_mode->panel_mode ==
DSI_OP_CMD_MODE)
allow_switch = true;
else if (panel->dfps_caps.dfps_support ||
panel->dyn_clk_caps.dyn_clk_support)
allow_switch = true;
} else {
if (is_valid_poms_switch(panel_dsi_mode,
cmp_panel_dsi_mode))
allow_switch = true;
}
if (allow_switch) {
dsi_mode_info->allowed_mode_switch |=
BIT(mode_idx + cmp_mode_idx);
cmp_dsi_mode_info->allowed_mode_switch |=
BIT(mode_idx);
}
if ((mode_idx + cmp_mode_idx) >= mode_count - 1)
break;
cmp_mode_idx++;
}
mode_idx++;
}
}
|