forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/drivers/gpu/drm/msm/disp/dpu1/dpu_encoder_phys_cmd.c
....@@ -1,15 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (c) 2015-2018 The Linux Foundation. All rights reserved.
3
- *
4
- * This program is free software; you can redistribute it and/or modify
5
- * it under the terms of the GNU General Public License version 2 and
6
- * only version 2 as published by the Free Software Foundation.
7
- *
8
- * This program is distributed in the hope that it will be useful,
9
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
- * GNU General Public License for more details.
12
- *
134 */
145
156 #define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__
....@@ -44,14 +35,7 @@
4435
4536 #define DPU_ENC_WR_PTR_START_TIMEOUT_US 20000
4637
47
-static inline int _dpu_encoder_phys_cmd_get_idle_timeout(
48
- struct dpu_encoder_phys_cmd *cmd_enc)
49
-{
50
- return KICKOFF_TIMEOUT_MS;
51
-}
52
-
53
-static inline bool dpu_encoder_phys_cmd_is_master(
54
- struct dpu_encoder_phys *phys_enc)
38
+static bool dpu_encoder_phys_cmd_is_master(struct dpu_encoder_phys *phys_enc)
5539 {
5640 return (phys_enc->split_role != ENC_ROLE_SLAVE) ? true : false;
5741 }
....@@ -61,8 +45,7 @@
6145 const struct drm_display_mode *mode,
6246 struct drm_display_mode *adj_mode)
6347 {
64
- if (phys_enc)
65
- DPU_DEBUG_CMDENC(to_dpu_encoder_phys_cmd(phys_enc), "\n");
48
+ DPU_DEBUG_CMDENC(to_dpu_encoder_phys_cmd(phys_enc), "\n");
6649 return true;
6750 }
6851
....@@ -74,11 +57,8 @@
7457 struct dpu_hw_ctl *ctl;
7558 struct dpu_hw_intf_cfg intf_cfg = { 0 };
7659
77
- if (!phys_enc)
78
- return;
79
-
8060 ctl = phys_enc->hw_ctl;
81
- if (!ctl || !ctl->ops.setup_intf_cfg)
61
+ if (!ctl->ops.setup_intf_cfg)
8262 return;
8363
8464 intf_cfg.intf = phys_enc->intf_idx;
....@@ -95,7 +75,7 @@
9575 int new_cnt;
9676 u32 event = DPU_ENCODER_FRAME_EVENT_DONE;
9777
98
- if (!phys_enc || !phys_enc->hw_pp)
78
+ if (!phys_enc->hw_pp)
9979 return;
10080
10181 DPU_ATRACE_BEGIN("pp_done_irq");
....@@ -122,7 +102,7 @@
122102 struct dpu_encoder_phys *phys_enc = arg;
123103 struct dpu_encoder_phys_cmd *cmd_enc;
124104
125
- if (!phys_enc || !phys_enc->hw_pp)
105
+ if (!phys_enc->hw_pp)
126106 return;
127107
128108 DPU_ATRACE_BEGIN("rd_ptr_irq");
....@@ -140,13 +120,8 @@
140120 static void dpu_encoder_phys_cmd_ctl_start_irq(void *arg, int irq_idx)
141121 {
142122 struct dpu_encoder_phys *phys_enc = arg;
143
- struct dpu_encoder_phys_cmd *cmd_enc;
144
-
145
- if (!phys_enc || !phys_enc->hw_ctl)
146
- return;
147123
148124 DPU_ATRACE_BEGIN("ctl_start_irq");
149
- cmd_enc = to_dpu_encoder_phys_cmd(phys_enc);
150125
151126 atomic_add_unless(&phys_enc->pending_ctlstart_cnt, -1, 0);
152127
....@@ -158,9 +133,6 @@
158133 static void dpu_encoder_phys_cmd_underrun_irq(void *arg, int irq_idx)
159134 {
160135 struct dpu_encoder_phys *phys_enc = arg;
161
-
162
- if (!phys_enc)
163
- return;
164136
165137 if (phys_enc->parent_ops->handle_underrun_virt)
166138 phys_enc->parent_ops->handle_underrun_virt(phys_enc->parent,
....@@ -196,33 +168,14 @@
196168 {
197169 struct dpu_encoder_phys_cmd *cmd_enc =
198170 to_dpu_encoder_phys_cmd(phys_enc);
199
- struct dpu_rm *rm = &phys_enc->dpu_kms->rm;
200
- struct dpu_rm_hw_iter iter;
201
- int i, instance;
202171
203
- if (!phys_enc || !mode || !adj_mode) {
172
+ if (!mode || !adj_mode) {
204173 DPU_ERROR("invalid args\n");
205174 return;
206175 }
207176 phys_enc->cached_mode = *adj_mode;
208177 DPU_DEBUG_CMDENC(cmd_enc, "caching mode:\n");
209178 drm_mode_debug_printmodeline(adj_mode);
210
-
211
- instance = phys_enc->split_role == ENC_ROLE_SLAVE ? 1 : 0;
212
-
213
- /* Retrieve previously allocated HW Resources. Shouldn't fail */
214
- dpu_rm_init_hw_iter(&iter, phys_enc->parent->base.id, DPU_HW_BLK_CTL);
215
- for (i = 0; i <= instance; i++) {
216
- if (dpu_rm_get_hw(rm, &iter))
217
- phys_enc->hw_ctl = (struct dpu_hw_ctl *)iter.hw;
218
- }
219
-
220
- if (IS_ERR_OR_NULL(phys_enc->hw_ctl)) {
221
- DPU_ERROR_CMDENC(cmd_enc, "failed to init ctl: %ld\n",
222
- PTR_ERR(phys_enc->hw_ctl));
223
- phys_enc->hw_ctl = NULL;
224
- return;
225
- }
226179
227180 _dpu_encoder_phys_cmd_setup_irq_hw_idx(phys_enc);
228181 }
....@@ -235,7 +188,7 @@
235188 u32 frame_event = DPU_ENCODER_FRAME_EVENT_ERROR;
236189 bool do_log = false;
237190
238
- if (!phys_enc || !phys_enc->hw_pp || !phys_enc->hw_ctl)
191
+ if (!phys_enc->hw_pp)
239192 return -EINVAL;
240193
241194 cmd_enc->pp_timeout_report_cnt++;
....@@ -262,7 +215,6 @@
262215 atomic_read(&phys_enc->pending_kickoff_cnt));
263216
264217 dpu_encoder_helper_unregister_irq(phys_enc, INTR_IDX_RDPTR);
265
- dpu_dbg_dump(false, __func__, true, true);
266218 }
267219
268220 atomic_add_unless(&phys_enc->pending_kickoff_cnt, -1, 0);
....@@ -285,11 +237,6 @@
285237 struct dpu_encoder_wait_info wait_info;
286238 int ret;
287239
288
- if (!phys_enc) {
289
- DPU_ERROR("invalid encoder\n");
290
- return -EINVAL;
291
- }
292
-
293240 wait_info.wq = &phys_enc->pending_kickoff_wq;
294241 wait_info.atomic_cnt = &phys_enc->pending_kickoff_cnt;
295242 wait_info.timeout_ms = KICKOFF_TIMEOUT_MS;
....@@ -311,7 +258,7 @@
311258 int ret = 0;
312259 int refcount;
313260
314
- if (!phys_enc || !phys_enc->hw_pp) {
261
+ if (!phys_enc->hw_pp) {
315262 DPU_ERROR("invalid encoder\n");
316263 return -EINVAL;
317264 }
....@@ -352,13 +299,6 @@
352299 static void dpu_encoder_phys_cmd_irq_control(struct dpu_encoder_phys *phys_enc,
353300 bool enable)
354301 {
355
- struct dpu_encoder_phys_cmd *cmd_enc;
356
-
357
- if (!phys_enc)
358
- return;
359
-
360
- cmd_enc = to_dpu_encoder_phys_cmd(phys_enc);
361
-
362302 trace_dpu_enc_phys_cmd_irq_ctrl(DRMID(phys_enc->parent),
363303 phys_enc->hw_pp->idx - PINGPONG_0,
364304 enable, atomic_read(&phys_enc->vblank_refcount));
....@@ -391,10 +331,9 @@
391331 struct drm_display_mode *mode;
392332 bool tc_enable = true;
393333 u32 vsync_hz;
394
- struct msm_drm_private *priv;
395334 struct dpu_kms *dpu_kms;
396335
397
- if (!phys_enc || !phys_enc->hw_pp) {
336
+ if (!phys_enc->hw_pp) {
398337 DPU_ERROR("invalid encoder\n");
399338 return;
400339 }
....@@ -409,11 +348,6 @@
409348 }
410349
411350 dpu_kms = phys_enc->dpu_kms;
412
- if (!dpu_kms || !dpu_kms->dev || !dpu_kms->dev->dev_private) {
413
- DPU_ERROR("invalid device\n");
414
- return;
415
- }
416
- priv = dpu_kms->dev->dev_private;
417351
418352 /*
419353 * TE default: dsi byte clock calculated base on 70 fps;
....@@ -431,7 +365,8 @@
431365 return;
432366 }
433367
434
- tc_cfg.vsync_count = vsync_hz / (mode->vtotal * mode->vrefresh);
368
+ tc_cfg.vsync_count = vsync_hz /
369
+ (mode->vtotal * drm_mode_vrefresh(mode));
435370
436371 /* enable external TE after kickoff to avoid premature autorefresh */
437372 tc_cfg.hw_vsync_mode = 0;
....@@ -451,7 +386,7 @@
451386 DPU_DEBUG_CMDENC(cmd_enc,
452387 "tc %d vsync_clk_speed_hz %u vtotal %u vrefresh %u\n",
453388 phys_enc->hw_pp->idx - PINGPONG_0, vsync_hz,
454
- mode->vtotal, mode->vrefresh);
389
+ mode->vtotal, drm_mode_vrefresh(mode));
455390 DPU_DEBUG_CMDENC(cmd_enc,
456391 "tc %d enable %u start_pos %u rd_ptr_irq %u\n",
457392 phys_enc->hw_pp->idx - PINGPONG_0, tc_enable, tc_cfg.start_pos,
....@@ -475,9 +410,8 @@
475410 struct dpu_encoder_phys_cmd *cmd_enc =
476411 to_dpu_encoder_phys_cmd(phys_enc);
477412
478
- if (!phys_enc || !phys_enc->hw_ctl || !phys_enc->hw_pp
479
- || !phys_enc->hw_ctl->ops.setup_intf_cfg) {
480
- DPU_ERROR("invalid arg(s), enc %d\n", phys_enc != 0);
413
+ if (!phys_enc->hw_pp || !phys_enc->hw_ctl->ops.setup_intf_cfg) {
414
+ DPU_ERROR("invalid arg(s), enc %d\n", phys_enc != NULL);
481415 return;
482416 }
483417
....@@ -505,8 +439,8 @@
505439 struct dpu_hw_ctl *ctl;
506440 u32 flush_mask = 0;
507441
508
- if (!phys_enc || !phys_enc->hw_ctl || !phys_enc->hw_pp) {
509
- DPU_ERROR("invalid arg(s), encoder %d\n", phys_enc != 0);
442
+ if (!phys_enc->hw_pp) {
443
+ DPU_ERROR("invalid arg(s), encoder %d\n", phys_enc != NULL);
510444 return;
511445 }
512446
....@@ -515,14 +449,11 @@
515449 _dpu_encoder_phys_cmd_pingpong_config(phys_enc);
516450
517451 if (!dpu_encoder_phys_cmd_is_master(phys_enc))
518
- goto skip_flush;
452
+ return;
519453
520454 ctl = phys_enc->hw_ctl;
521455 ctl->ops.get_bitmask_intf(ctl, &flush_mask, phys_enc->intf_idx);
522456 ctl->ops.update_pending_flush(ctl, flush_mask);
523
-
524
-skip_flush:
525
- return;
526457 }
527458
528459 static void dpu_encoder_phys_cmd_enable(struct dpu_encoder_phys *phys_enc)
....@@ -530,7 +461,7 @@
530461 struct dpu_encoder_phys_cmd *cmd_enc =
531462 to_dpu_encoder_phys_cmd(phys_enc);
532463
533
- if (!phys_enc || !phys_enc->hw_pp) {
464
+ if (!phys_enc->hw_pp) {
534465 DPU_ERROR("invalid phys encoder\n");
535466 return;
536467 }
....@@ -549,8 +480,7 @@
549480 static void _dpu_encoder_phys_cmd_connect_te(
550481 struct dpu_encoder_phys *phys_enc, bool enable)
551482 {
552
- if (!phys_enc || !phys_enc->hw_pp ||
553
- !phys_enc->hw_pp->ops.connect_external_te)
483
+ if (!phys_enc->hw_pp || !phys_enc->hw_pp->ops.connect_external_te)
554484 return;
555485
556486 trace_dpu_enc_phys_cmd_connect_te(DRMID(phys_enc->parent), enable);
....@@ -568,7 +498,7 @@
568498 {
569499 struct dpu_hw_pingpong *hw_pp;
570500
571
- if (!phys_enc || !phys_enc->hw_pp)
501
+ if (!phys_enc->hw_pp)
572502 return -EINVAL;
573503
574504 if (!dpu_encoder_phys_cmd_is_master(phys_enc))
....@@ -586,7 +516,7 @@
586516 struct dpu_encoder_phys_cmd *cmd_enc =
587517 to_dpu_encoder_phys_cmd(phys_enc);
588518
589
- if (!phys_enc || !phys_enc->hw_pp) {
519
+ if (!phys_enc->hw_pp) {
590520 DPU_ERROR("invalid encoder\n");
591521 return;
592522 }
....@@ -609,44 +539,24 @@
609539 struct dpu_encoder_phys_cmd *cmd_enc =
610540 to_dpu_encoder_phys_cmd(phys_enc);
611541
612
- if (!phys_enc) {
613
- DPU_ERROR("invalid encoder\n");
614
- return;
615
- }
616542 kfree(cmd_enc);
617543 }
618544
619545 static void dpu_encoder_phys_cmd_get_hw_resources(
620546 struct dpu_encoder_phys *phys_enc,
621
- struct dpu_encoder_hw_resources *hw_res,
622
- struct drm_connector_state *conn_state)
547
+ struct dpu_encoder_hw_resources *hw_res)
623548 {
624
- struct dpu_encoder_phys_cmd *cmd_enc =
625
- to_dpu_encoder_phys_cmd(phys_enc);
626
-
627
- if (!phys_enc) {
628
- DPU_ERROR("invalid encoder\n");
629
- return;
630
- }
631
-
632
- if ((phys_enc->intf_idx - INTF_0) >= INTF_MAX) {
633
- DPU_ERROR("invalid intf idx:%d\n", phys_enc->intf_idx);
634
- return;
635
- }
636
-
637
- DPU_DEBUG_CMDENC(cmd_enc, "\n");
638549 hw_res->intfs[phys_enc->intf_idx - INTF_0] = INTF_MODE_CMD;
639550 }
640551
641552 static void dpu_encoder_phys_cmd_prepare_for_kickoff(
642
- struct dpu_encoder_phys *phys_enc,
643
- struct dpu_encoder_kickoff_params *params)
553
+ struct dpu_encoder_phys *phys_enc)
644554 {
645555 struct dpu_encoder_phys_cmd *cmd_enc =
646556 to_dpu_encoder_phys_cmd(phys_enc);
647557 int ret;
648558
649
- if (!phys_enc || !phys_enc->hw_pp) {
559
+ if (!phys_enc->hw_pp) {
650560 DPU_ERROR("invalid encoder\n");
651561 return;
652562 }
....@@ -680,11 +590,6 @@
680590 struct dpu_encoder_wait_info wait_info;
681591 int ret;
682592
683
- if (!phys_enc || !phys_enc->hw_ctl) {
684
- DPU_ERROR("invalid argument(s)\n");
685
- return -EINVAL;
686
- }
687
-
688593 wait_info.wq = &phys_enc->pending_kickoff_wq;
689594 wait_info.atomic_cnt = &phys_enc->pending_ctlstart_cnt;
690595 wait_info.timeout_ms = KICKOFF_TIMEOUT_MS;
....@@ -704,12 +609,6 @@
704609 struct dpu_encoder_phys *phys_enc)
705610 {
706611 int rc;
707
- struct dpu_encoder_phys_cmd *cmd_enc;
708
-
709
- if (!phys_enc)
710
- return -EINVAL;
711
-
712
- cmd_enc = to_dpu_encoder_phys_cmd(phys_enc);
713612
714613 rc = _dpu_encoder_phys_cmd_wait_for_idle(phys_enc);
715614 if (rc) {
....@@ -727,9 +626,6 @@
727626 int rc = 0;
728627 struct dpu_encoder_phys_cmd *cmd_enc;
729628
730
- if (!phys_enc)
731
- return -EINVAL;
732
-
733629 cmd_enc = to_dpu_encoder_phys_cmd(phys_enc);
734630
735631 /* only required for master controller */
....@@ -738,7 +634,7 @@
738634
739635 /* required for both controllers */
740636 if (!rc && cmd_enc->serialize_wait4pp)
741
- dpu_encoder_phys_cmd_prepare_for_kickoff(phys_enc, NULL);
637
+ dpu_encoder_phys_cmd_prepare_for_kickoff(phys_enc);
742638
743639 return rc;
744640 }
....@@ -750,9 +646,6 @@
750646 struct dpu_encoder_phys_cmd *cmd_enc;
751647 struct dpu_encoder_wait_info wait_info;
752648
753
- if (!phys_enc)
754
- return -EINVAL;
755
-
756649 cmd_enc = to_dpu_encoder_phys_cmd(phys_enc);
757650
758651 /* only required for master controller */
....@@ -761,7 +654,7 @@
761654
762655 wait_info.wq = &cmd_enc->pending_vblank_wq;
763656 wait_info.atomic_cnt = &cmd_enc->pending_vblank_cnt;
764
- wait_info.timeout_ms = _dpu_encoder_phys_cmd_get_idle_timeout(cmd_enc);
657
+ wait_info.timeout_ms = KICKOFF_TIMEOUT_MS;
765658
766659 atomic_inc(&cmd_enc->pending_vblank_cnt);
767660
....@@ -774,9 +667,6 @@
774667 static void dpu_encoder_phys_cmd_handle_post_kickoff(
775668 struct dpu_encoder_phys *phys_enc)
776669 {
777
- if (!phys_enc)
778
- return;
779
-
780670 /**
781671 * re-enable external TE, either for the first time after enabling
782672 * or if disabled for Autorefresh
....@@ -787,9 +677,6 @@
787677 static void dpu_encoder_phys_cmd_trigger_start(
788678 struct dpu_encoder_phys *phys_enc)
789679 {
790
- if (!phys_enc)
791
- return;
792
-
793680 dpu_encoder_helper_trigger_start(phys_enc);
794681 }
795682
....@@ -810,7 +697,6 @@
810697 ops->wait_for_vblank = dpu_encoder_phys_cmd_wait_for_vblank;
811698 ops->trigger_start = dpu_encoder_phys_cmd_trigger_start;
812699 ops->needs_single_flush = dpu_encoder_phys_cmd_needs_single_flush;
813
- ops->hw_reset = dpu_encoder_helper_hw_reset;
814700 ops->irq_control = dpu_encoder_phys_cmd_irq_control;
815701 ops->restore = dpu_encoder_phys_cmd_enable_helper;
816702 ops->prepare_idle_pc = dpu_encoder_phys_cmd_prepare_idle_pc;
....@@ -823,7 +709,6 @@
823709 {
824710 struct dpu_encoder_phys *phys_enc = NULL;
825711 struct dpu_encoder_phys_cmd *cmd_enc = NULL;
826
- struct dpu_hw_mdp *hw_mdp;
827712 struct dpu_encoder_irq *irq;
828713 int i, ret = 0;
829714
....@@ -833,17 +718,10 @@
833718 if (!cmd_enc) {
834719 ret = -ENOMEM;
835720 DPU_ERROR("failed to allocate\n");
836
- goto fail;
721
+ return ERR_PTR(ret);
837722 }
838723 phys_enc = &cmd_enc->base;
839
-
840
- hw_mdp = dpu_rm_get_mdp(&p->dpu_kms->rm);
841
- if (IS_ERR_OR_NULL(hw_mdp)) {
842
- ret = PTR_ERR(hw_mdp);
843
- DPU_ERROR("failed to get mdptop\n");
844
- goto fail_mdp_init;
845
- }
846
- phys_enc->hw_mdptop = hw_mdp;
724
+ phys_enc->hw_mdptop = p->dpu_kms->hw_mdp;
847725 phys_enc->intf_idx = p->intf_idx;
848726
849727 dpu_encoder_phys_cmd_init_ops(&phys_enc->ops);
....@@ -897,9 +775,4 @@
897775 DPU_DEBUG_CMDENC(cmd_enc, "created\n");
898776
899777 return phys_enc;
900
-
901
-fail_mdp_init:
902
- kfree(cmd_enc);
903
-fail:
904
- return ERR_PTR(ret);
905778 }