forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-04 1543e317f1da31b75942316931e8f491a8920811
kernel/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c
....@@ -4,17 +4,22 @@
44 * Author: Andy Yan <andy.yan@rock-chips.com>
55 */
66 #include <drm/drm.h>
7
-#include <drm/drmP.h>
87 #include <drm/drm_atomic.h>
8
+#include <drm/drm_atomic_uapi.h>
99 #include <drm/drm_crtc.h>
1010 #include <drm/drm_crtc_helper.h>
11
+#include <drm/drm_debugfs.h>
1112 #include <drm/drm_flip_work.h>
13
+#include <drm/drm_fourcc.h>
14
+#include <drm/drm_gem_framebuffer_helper.h>
1215 #include <drm/drm_plane_helper.h>
16
+#include <drm/drm_probe_helper.h>
17
+#include <drm/drm_self_refresh_helper.h>
18
+
1319 #include <drm/drm_writeback.h>
1420 #ifdef CONFIG_DRM_ANALOGIX_DP
1521 #include <drm/bridge/analogix_dp.h>
1622 #endif
17
-#include <dt-bindings/soc/rockchip-system-status.h>
1823
1924 #include <linux/debugfs.h>
2025 #include <linux/fixp-arith.h>
....@@ -23,6 +28,8 @@
2328 #include <linux/module.h>
2429 #include <linux/platform_device.h>
2530 #include <linux/clk.h>
31
+#include <linux/clk-provider.h>
32
+#include <linux/clk/clk-conf.h>
2633 #include <linux/iopoll.h>
2734 #include <linux/of.h>
2835 #include <linux/of_device.h>
....@@ -30,6 +37,7 @@
3037 #include <linux/pm_runtime.h>
3138 #include <linux/component.h>
3239 #include <linux/regmap.h>
40
+#include <linux/reset.h>
3341 #include <linux/mfd/syscon.h>
3442 #include <linux/delay.h>
3543 #include <linux/swab.h>
....@@ -37,16 +45,17 @@
3745 #include <linux/rockchip/cpu.h>
3846 #include <linux/workqueue.h>
3947 #include <linux/types.h>
48
+#include <soc/rockchip/rockchip_csu.h>
4049 #include <soc/rockchip/rockchip_dmc.h>
4150 #include <soc/rockchip/rockchip-system-status.h>
4251 #include <uapi/linux/videodev2.h>
4352
53
+#include "../drm_crtc_internal.h"
4454 #include "../drm_internal.h"
4555
4656 #include "rockchip_drm_drv.h"
4757 #include "rockchip_drm_gem.h"
4858 #include "rockchip_drm_fb.h"
49
-#include "rockchip_drm_psr.h"
5059 #include "rockchip_drm_vop.h"
5160 #include "rockchip_vop_reg.h"
5261 #include "rockchip_post_csc.h"
....@@ -117,27 +126,32 @@
117126 #define VOP_WIN_GET(vop2, win, name) \
118127 vop2_read_reg(vop2, win->offset, &VOP_WIN_NAME(win, name))
119128
129
+#define VOP_WIN_GET_REG_BAK(vop2, win, name) \
130
+ vop2_read_reg_bak(vop2, win->offset, &VOP_WIN_NAME(win, name))
131
+
120132 #define VOP_WIN_NAME(win, name) \
121133 (vop2_get_win_regs(win, &win->regs->name)->name)
122134
123135 #define VOP_WIN_TO_INDEX(vop2_win) \
124136 ((vop2_win) - (vop2_win)->vop2->win)
125137
126
-#define VOP_GRF_SET(vop2, reg, v) \
138
+#define VOP_GRF_SET(vop2, grf, reg, v) \
127139 do { \
128
- if (vop2->data->grf_ctrl) { \
129
- vop2_grf_writel(vop2, vop2->data->grf_ctrl->reg, v); \
140
+ if (vop2->data->grf) { \
141
+ vop2_grf_writel(vop2->grf, vop2->data->grf->reg, v); \
130142 } \
131143 } while (0)
132144
133
-#define to_vop2_video_port(c) container_of(c, struct vop2_video_port, crtc)
134145 #define to_vop2_win(x) container_of(x, struct vop2_win, base)
135146 #define to_vop2_plane_state(x) container_of(x, struct vop2_plane_state, base)
136147 #define to_wb_state(x) container_of(x, struct vop2_wb_connector_state, base)
137
-
138
-#ifndef drm_is_afbc
139
-#define drm_is_afbc(modifier) (((modifier) >> 56) == DRM_FORMAT_MOD_VENDOR_ARM)
140
-#endif
148
+#define output_if_is_hdmi(x) (x & (VOP_OUTPUT_IF_HDMI0 | VOP_OUTPUT_IF_HDMI1))
149
+#define output_if_is_dp(x) (x & (VOP_OUTPUT_IF_DP0 | VOP_OUTPUT_IF_DP1))
150
+#define output_if_is_edp(x) (x & (VOP_OUTPUT_IF_eDP0 | VOP_OUTPUT_IF_eDP1))
151
+#define output_if_is_mipi(x) (x & (VOP_OUTPUT_IF_MIPI0 | VOP_OUTPUT_IF_MIPI1))
152
+#define output_if_is_lvds(x) (x & (VOP_OUTPUT_IF_LVDS0 | VOP_OUTPUT_IF_LVDS1))
153
+#define output_if_is_dpi(x) (x & (VOP_OUTPUT_IF_BT656 | VOP_OUTPUT_IF_BT1120 | \
154
+ VOP_OUTPUT_IF_RGB))
141155
142156 /*
143157 * max two jobs a time, one is running(writing back),
....@@ -146,7 +160,11 @@
146160 #define VOP2_WB_JOB_MAX 2
147161 #define VOP2_SYS_AXI_BUS_NUM 2
148162
149
-#define VOP2_CLUSTER_YUV444_10 0x12
163
+#define VOP2_MAX_VP_OUTPUT_WIDTH 4096
164
+/* KHZ */
165
+#define VOP2_MAX_DCLK_RATE 600000
166
+/* KHZ */
167
+#define VOP2_COMMON_ACLK_RATE 500000
150168
151169 enum vop2_data_format {
152170 VOP2_FMT_ARGB8888 = 0,
....@@ -238,6 +256,36 @@
238256 ROCKCHIP_VOP2_PHY_ID_INVALID = -1,
239257 };
240258
259
+struct vop2_power_domain {
260
+ struct vop2_power_domain *parent;
261
+ struct vop2 *vop2;
262
+ /*
263
+ * @lock: protect power up/down procedure.
264
+ * power on take effect immediately,
265
+ * power down take effect by vsync.
266
+ * we must check power_domain_status register
267
+ * to make sure the power domain is down before
268
+ * send a power on request.
269
+ *
270
+ */
271
+ spinlock_t lock;
272
+ unsigned int ref_count;
273
+ bool on;
274
+ /* @vp_mask: Bit mask of video port of the power domain's
275
+ * module attached to.
276
+ * For example: PD_CLUSTER0 belongs to module Cluster0, it's
277
+ * bitmask is the VP which Cluster0 attached to. PD_ESMART is
278
+ * shared between Esmart1/2/3, it's bitmask will be all the VP
279
+ * which Esmart1/2/3 attached to.
280
+ * This is used to check if we can power off a PD by vsync.
281
+ */
282
+ uint8_t vp_mask;
283
+
284
+ const struct vop2_power_domain_data *data;
285
+ struct list_head list;
286
+ struct delayed_work power_off_work;
287
+};
288
+
241289 struct vop2_zpos {
242290 struct drm_plane *plane;
243291 int win_phys_id;
....@@ -321,7 +369,6 @@
321369 int global_alpha;
322370 int blend_mode;
323371 uint64_t color_key;
324
- void *yrgb_kvaddr;
325372 unsigned long offset;
326373 int pdaf_data_type;
327374 bool async_commit;
....@@ -343,11 +390,37 @@
343390 bool two_win_mode;
344391
345392 /**
393
+ * ---------------------------
394
+ * | | |
395
+ * | Left | Right |
396
+ * | | |
397
+ * | Cluster0 | Cluster1 |
398
+ * ---------------------------
399
+ */
400
+
401
+ /*
402
+ * @splice_mode_right: As right part of the screen in splice mode.
403
+ */
404
+ bool splice_mode_right;
405
+
406
+ /**
407
+ * @splice_win: splice win which used to splice for a plane
408
+ * hdisplay > 4096
409
+ */
410
+ struct vop2_win *splice_win;
411
+ struct vop2_win *left_win;
412
+
413
+ uint8_t splice_win_id;
414
+
415
+ struct vop2_power_domain *pd;
416
+
417
+ /**
346418 * @phys_id: physical id for cluster0/1, esmart0/1, smart0/1
347419 * Will be used as a identification for some register
348420 * configuration such as OVL_LAYER_SEL/OVL_PORT_SEL.
349421 */
350422 uint8_t phys_id;
423
+
351424 /**
352425 * @win_id: graphic window id, a cluster maybe split into two
353426 * graphics windows.
....@@ -415,6 +488,7 @@
415488 };
416489
417490 struct vop2_cluster {
491
+ bool splice_mode;
418492 struct vop2_win *main;
419493 struct vop2_win *sub;
420494 };
....@@ -456,6 +530,17 @@
456530
457531 };
458532
533
+struct vop2_dsc {
534
+ uint8_t id;
535
+ uint8_t max_slice_num;
536
+ uint8_t max_linebuf_depth; /* used to generate the bitstream */
537
+ uint8_t min_bits_per_pixel; /* bit num after encoder compress */
538
+ bool enabled;
539
+ char attach_vp_id;
540
+ const struct vop2_dsc_regs *regs;
541
+ struct vop2_power_domain *pd;
542
+};
543
+
459544 enum vop2_wb_format {
460545 VOP2_WB_ARGB8888,
461546 VOP2_WB_BGR888,
....@@ -476,9 +561,12 @@
476561 };
477562
478563 struct vop2_video_port {
479
- struct drm_crtc crtc;
564
+ struct rockchip_crtc rockchip_crtc;
565
+ struct rockchip_mcu_timing mcu_timing;
480566 struct vop2 *vop2;
567
+ struct reset_control *dclk_rst;
481568 struct clk *dclk;
569
+ struct clk *dclk_parent;
482570 uint8_t id;
483571 bool layer_sel_update;
484572 bool xmirror_en;
....@@ -531,15 +619,46 @@
531619 int hdr_en;
532620
533621 /**
622
+ * -----------------
623
+ * | | |
624
+ * | Left | Right |
625
+ * | | |
626
+ * | VP0 | VP1 |
627
+ * -----------------
628
+ * @splice_mode_right: As right part of the screen in splice mode.
629
+ */
630
+ bool splice_mode_right;
631
+
632
+ /**
633
+ * @hdr10_at_splice_mode: enable hdr10 at splice mode on rk3588.
634
+ */
635
+ bool hdr10_at_splice_mode;
636
+ /**
637
+ * @left_vp: VP as left part of the screen in splice mode.
638
+ */
639
+ struct vop2_video_port *left_vp;
640
+
641
+ /**
534642 * @win_mask: Bitmask of wins attached to the video port;
535643 */
536644 uint32_t win_mask;
645
+ /**
646
+ * @enabled_win_mask: Bitmask of enabled wins attached to the video port;
647
+ */
648
+ uint32_t enabled_win_mask;
649
+
537650 /**
538651 * @nr_layers: active layers attached to the video port;
539652 */
540653 uint8_t nr_layers;
541654
542655 int cursor_win_id;
656
+ /**
657
+ * @output_if: output connector attached to the video port,
658
+ * this flag is maintained in vop driver, updated in crtc_atomic_enable,
659
+ * cleared in crtc_atomic_disable;
660
+ */
661
+ u32 output_if;
543662
544663 /**
545664 * @active_tv_state: TV connector related states
....@@ -606,6 +725,25 @@
606725 * @plane_mask_prop: plane mask interaction with userspace
607726 */
608727 struct drm_property *plane_mask_prop;
728
+ /**
729
+ * @feature_prop: crtc feature interaction with userspace
730
+ */
731
+ struct drm_property *feature_prop;
732
+
733
+ /**
734
+ * @variable_refresh_rate_prop: crtc variable refresh rate interaction with userspace
735
+ */
736
+ struct drm_property *variable_refresh_rate_prop;
737
+
738
+ /**
739
+ * @max_refresh_rate_prop: crtc max refresh rate interaction with userspace
740
+ */
741
+ struct drm_property *max_refresh_rate_prop;
742
+
743
+ /**
744
+ * @min_refresh_rate_prop: crtc min refresh rate interaction with userspace
745
+ */
746
+ struct drm_property *min_refresh_rate_prop;
609747
610748 /**
611749 * @hdr_ext_data_prop: hdr extend data interaction with userspace
....@@ -622,6 +760,14 @@
622760 * @post_csc_data_prop: post csc data interaction with userspace
623761 */
624762 struct drm_property *post_csc_data_prop;
763
+ /**
764
+ * @output_width_prop: vp max output width prop
765
+ */
766
+ struct drm_property *output_width_prop;
767
+ /**
768
+ * @output_dclk_prop: vp max output dclk prop
769
+ */
770
+ struct drm_property *output_dclk_prop;
625771
626772 /**
627773 * @primary_plane_phy_id: vp primary plane phy id, the primary plane
....@@ -631,21 +777,29 @@
631777
632778 struct post_acm acm_info;
633779 struct post_csc csc_info;
780
+
781
+ /**
782
+ * @refresh_rate_change: indicate whether refresh rate change
783
+ */
784
+ bool refresh_rate_change;
785
+};
786
+
787
+struct vop2_extend_pll {
788
+ struct list_head list;
789
+ struct clk *clk;
790
+ char clk_name[32];
791
+ u32 vp_mask;
634792 };
635793
636794 struct vop2 {
637795 u32 version;
638796 struct device *dev;
639797 struct drm_device *drm_dev;
798
+ struct vop2_dsc dscs[ROCKCHIP_MAX_CRTC];
640799 struct vop2_video_port vps[ROCKCHIP_MAX_CRTC];
641800 struct vop2_wb wb;
642801 struct dentry *debugfs;
643802 struct drm_info_list *debugfs_files;
644
- struct drm_property *soc_id_prop;
645
- struct drm_property *vp_id_prop;
646
- struct drm_property *aclk_prop;
647
- struct drm_property *bg_prop;
648
- struct drm_property *line_flag_prop;
649803 struct drm_prop_enum_list *plane_name_list;
650804 bool is_iommu_enabled;
651805 bool is_iommu_needed;
....@@ -681,6 +835,9 @@
681835
682836 bool loader_protect;
683837
838
+ bool aclk_rate_reset;
839
+ unsigned long aclk_rate;
840
+
684841 const struct vop2_data *data;
685842 /* Number of win that registered as plane,
686843 * maybe less than the total number of hardware
....@@ -699,6 +856,10 @@
699856 struct resource *res;
700857 void __iomem *regs;
701858 struct regmap *grf;
859
+ struct regmap *sys_grf;
860
+ struct regmap *vo0_grf;
861
+ struct regmap *vo1_grf;
862
+ struct regmap *sys_pmu;
702863
703864 /* physical map length of vop2 register */
704865 uint32_t len;
....@@ -721,6 +882,16 @@
721882 unsigned int enable_count;
722883 struct clk *hclk;
723884 struct clk *aclk;
885
+ struct clk *pclk;
886
+ struct reset_control *ahb_rst;
887
+ struct reset_control *axi_rst;
888
+ struct csu_clk *csu_aclk;
889
+
890
+ /* list_head of extend clk */
891
+ struct list_head extend_clk_list_head;
892
+ /* list_head of internal clk */
893
+ struct list_head clk_list_head;
894
+ struct list_head pd_list_head;
724895 struct work_struct post_buf_empty_work;
725896 struct workqueue_struct *workqueue;
726897
....@@ -728,6 +899,18 @@
728899 /* must put at the end of the struct */
729900 struct vop2_win win[];
730901 };
902
+
903
+struct vop2_clk {
904
+ struct vop2 *vop2;
905
+ struct list_head list;
906
+ unsigned long rate;
907
+ struct clk_hw hw;
908
+ struct clk_divider div;
909
+ int div_val;
910
+ u8 parent_index;
911
+};
912
+
913
+#define to_vop2_clk(_hw) container_of(_hw, struct vop2_clk, hw)
731914
732915 /*
733916 * bus-format types.
....@@ -743,23 +926,33 @@
743926 { MEDIA_BUS_FMT_RGB666_1X18, "RGB666_1X18" },
744927 { MEDIA_BUS_FMT_RGB666_1X24_CPADHI, "RGB666_1X24_CPADHI" },
745928 { MEDIA_BUS_FMT_RGB666_1X7X3_SPWG, "RGB666_1X7X3_SPWG" },
746
- { MEDIA_BUS_FMT_RGB666_1X7X3_JEIDA, "RGB666_1X7X3_JEIDA" },
747929 { MEDIA_BUS_FMT_YUV8_1X24, "YUV8_1X24" },
748930 { MEDIA_BUS_FMT_UYYVYY8_0_5X24, "UYYVYY8_0_5X24" },
749931 { MEDIA_BUS_FMT_YUV10_1X30, "YUV10_1X30" },
750932 { MEDIA_BUS_FMT_UYYVYY10_0_5X30, "UYYVYY10_0_5X30" },
751
- { MEDIA_BUS_FMT_SRGB888_3X8, "SRGB888_3X8" },
752
- { MEDIA_BUS_FMT_SRGB888_DUMMY_4X8, "SRGB888_DUMMY_4X8" },
933
+ { MEDIA_BUS_FMT_RGB565_2X8_LE, "RGB565_2X8_LE" },
934
+ { MEDIA_BUS_FMT_RGB888_3X8, "RGB888_3X8" },
935
+ { MEDIA_BUS_FMT_RGB888_DUMMY_4X8, "RGB888_DUMMY_4X8" },
753936 { MEDIA_BUS_FMT_RGB888_1X24, "RGB888_1X24" },
754937 { MEDIA_BUS_FMT_RGB888_1X7X4_SPWG, "RGB888_1X7X4_SPWG" },
755938 { MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA, "RGB888_1X7X4_JEIDA" },
756939 { MEDIA_BUS_FMT_UYVY8_2X8, "UYVY8_2X8" },
757940 { MEDIA_BUS_FMT_YUYV8_1X16, "YUYV8_1X16" },
758941 { MEDIA_BUS_FMT_UYVY8_1X16, "UYVY8_1X16" },
759
- { MEDIA_BUS_FMT_RGB101010_1X30, "RGB101010_1x30" },
942
+ { MEDIA_BUS_FMT_RGB101010_1X30, "RGB101010_1X30" },
943
+ { MEDIA_BUS_FMT_YUYV10_1X20, "YUYV10_1X20" },
760944 };
761945
762946 static DRM_ENUM_NAME_FN(drm_get_bus_format_name, drm_bus_format_enum_list)
947
+
948
+static inline struct vop2_video_port *to_vop2_video_port(struct drm_crtc *crtc)
949
+{
950
+ struct rockchip_crtc *rockchip_crtc;
951
+
952
+ rockchip_crtc = container_of(crtc, struct rockchip_crtc, crtc);
953
+
954
+ return container_of(rockchip_crtc, struct vop2_video_port, rockchip_crtc);
955
+}
763956
764957 static void vop2_lock(struct vop2 *vop2)
765958 {
....@@ -773,17 +966,26 @@
773966 mutex_unlock(&vop2->vop2_lock);
774967 }
775968
776
-static inline void vop2_grf_writel(struct vop2 *vop2, struct vop_reg reg, u32 v)
969
+static inline void vop2_grf_writel(struct regmap *regmap, struct vop_reg reg, u32 v)
777970 {
778971 u32 val = 0;
779972
780
- if (IS_ERR_OR_NULL(vop2->grf))
973
+ if (IS_ERR_OR_NULL(regmap))
781974 return;
782975
783976 if (reg.mask) {
784977 val = (v << reg.shift) | (reg.mask << (reg.shift + 16));
785
- regmap_write(vop2->grf, reg.offset, val);
978
+ regmap_write(regmap, reg.offset, val);
786979 }
980
+}
981
+
982
+static inline uint32_t vop2_grf_readl(struct regmap *regmap, const struct vop_reg *reg)
983
+{
984
+ uint32_t v;
985
+
986
+ regmap_read(regmap, reg->offset, &v);
987
+
988
+ return v;
787989 }
788990
789991 static inline void vop2_writel(struct vop2 *vop2, uint32_t offset, uint32_t v)
....@@ -801,6 +1003,26 @@
8011003 const struct vop_reg *reg)
8021004 {
8031005 return (vop2_readl(vop2, base + reg->offset) >> reg->shift) & reg->mask;
1006
+}
1007
+
1008
+static inline uint32_t vop2_read_reg_bak(struct vop2 *vop2, uint32_t base,
1009
+ const struct vop_reg *reg)
1010
+{
1011
+ return (vop2->regsbak[(base + reg->offset) >> 2] >> reg->shift) & reg->mask;
1012
+}
1013
+
1014
+static inline uint32_t vop2_read_grf_reg(struct regmap *regmap, const struct vop_reg *reg)
1015
+{
1016
+ return (vop2_grf_readl(regmap, reg) >> reg->shift) & reg->mask;
1017
+}
1018
+
1019
+static inline void vop2_write_reg_uncached(struct vop2 *vop2, const struct vop_reg *reg, uint32_t v)
1020
+{
1021
+ uint32_t offset = reg->offset;
1022
+ uint32_t cached_val = vop2->regsbak[offset >> 2];
1023
+
1024
+ v = (cached_val & ~(reg->mask << reg->shift)) | ((v & reg->mask) << reg->shift);
1025
+ writel(v, vop2->regs + offset);
8041026 }
8051027
8061028 static inline void vop2_mask_write(struct vop2 *vop2, uint32_t offset,
....@@ -881,7 +1103,7 @@
8811103 }
8821104 }
8831105
884
-void vop2_standby(struct drm_crtc *crtc, bool standby)
1106
+static void vop2_crtc_standby(struct drm_crtc *crtc, bool standby)
8851107 {
8861108 struct vop2_video_port *vp = to_vop2_video_port(crtc);
8871109 struct vop2 *vop2 = vp->vop2;
....@@ -893,7 +1115,6 @@
8931115 VOP_MODULE_SET(vop2, vp, standby, 0);
8941116 }
8951117 }
896
-EXPORT_SYMBOL(vop2_standby);
8971118
8981119 static inline const struct vop2_win_regs *vop2_get_win_regs(struct vop2_win *win,
8991120 const struct vop_reg *reg)
....@@ -939,6 +1160,32 @@
9391160 return NULL;
9401161 }
9411162
1163
+static struct vop2_power_domain *vop2_find_pd_by_id(struct vop2 *vop2, uint8_t id)
1164
+{
1165
+ struct vop2_power_domain *pd, *n;
1166
+
1167
+ list_for_each_entry_safe(pd, n, &vop2->pd_list_head, list) {
1168
+ if (pd->data->id == id)
1169
+ return pd;
1170
+ }
1171
+
1172
+ return NULL;
1173
+}
1174
+
1175
+static const struct vop2_connector_if_data *vop2_find_connector_if_data(struct vop2 *vop2, int id)
1176
+{
1177
+ const struct vop2_connector_if_data *if_data;
1178
+ int i;
1179
+
1180
+ for (i = 0; i < vop2->data->nr_conns; i++) {
1181
+ if_data = &vop2->data->conn[i];
1182
+ if (if_data->id == id)
1183
+ return if_data;
1184
+ }
1185
+
1186
+ return NULL;
1187
+}
1188
+
9421189 static struct drm_crtc *vop2_find_crtc_by_plane_mask(struct vop2 *vop2, uint8_t phys_id)
9431190 {
9441191 struct vop2_video_port *vp;
....@@ -947,10 +1194,28 @@
9471194 for (i = 0; i < vop2->data->nr_vps; i++) {
9481195 vp = &vop2->vps[i];
9491196 if (vp->plane_mask & BIT(phys_id))
950
- return &vp->crtc;
1197
+ return &vp->rockchip_crtc.crtc;
9511198 }
9521199
9531200 return NULL;
1201
+}
1202
+
1203
+static int vop2_clk_reset(struct reset_control *rstc)
1204
+{
1205
+ int ret;
1206
+
1207
+ if (!rstc)
1208
+ return 0;
1209
+
1210
+ ret = reset_control_assert(rstc);
1211
+ if (ret < 0)
1212
+ DRM_WARN("failed to assert reset\n");
1213
+ udelay(10);
1214
+ ret = reset_control_deassert(rstc);
1215
+ if (ret < 0)
1216
+ DRM_WARN("failed to deassert reset\n");
1217
+
1218
+ return ret;
9541219 }
9551220
9561221 static void vop2_load_hdr2sdr_table(struct vop2_video_port *vp)
....@@ -1167,7 +1432,7 @@
11671432 done_bits &= ~BIT(vp->id);
11681433 vp_id = ffs(done_bits) - 1;
11691434 done_vp = &vop2->vps[vp_id];
1170
- adjusted_mode = &done_vp->crtc.state->adjusted_mode;
1435
+ adjusted_mode = &done_vp->rockchip_crtc.crtc.state->adjusted_mode;
11711436 vcnt = vop2_read_vcnt(done_vp);
11721437 if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
11731438 vcnt >>= 1;
....@@ -1188,7 +1453,7 @@
11881453
11891454 first_vp_id = ffs(done_bits) - 1;
11901455 first_done_vp = &vop2->vps[first_vp_id];
1191
- first_mode = &first_done_vp->crtc.state->adjusted_mode;
1456
+ first_mode = &first_done_vp->rockchip_crtc.crtc.state->adjusted_mode;
11921457 /* set last 1/8 frame time as safe section */
11931458 vrefresh = drm_mode_vrefresh(first_mode);
11941459 if (!vrefresh) {
....@@ -1200,7 +1465,7 @@
12001465 done_bits &= ~BIT(first_vp_id);
12011466 second_vp_id = ffs(done_bits) - 1;
12021467 second_done_vp = &vop2->vps[second_vp_id];
1203
- second_mode = &second_done_vp->crtc.state->adjusted_mode;
1468
+ second_mode = &second_done_vp->rockchip_crtc.crtc.state->adjusted_mode;
12041469 /* set last 1/8 frame time as safe section */
12051470 vrefresh = drm_mode_vrefresh(second_mode);
12061471 if (!vrefresh) {
....@@ -1245,6 +1510,26 @@
12451510 return done_bits;
12461511 }
12471512
1513
+static inline void rk3588_vop2_dsc_cfg_done(struct drm_crtc *crtc)
1514
+{
1515
+ struct vop2_video_port *vp = to_vop2_video_port(crtc);
1516
+ struct vop2 *vop2 = vp->vop2;
1517
+ struct rockchip_crtc_state *vcstate = to_rockchip_crtc_state(crtc->state);
1518
+ struct vop2_dsc *dsc = &vop2->dscs[vcstate->dsc_id];
1519
+
1520
+ if (vcstate->output_flags & ROCKCHIP_OUTPUT_DUAL_CHANNEL_LEFT_RIGHT_MODE) {
1521
+ dsc = &vop2->dscs[0];
1522
+ if (vcstate->dsc_enable)
1523
+ VOP_MODULE_SET(vop2, dsc, dsc_cfg_done, 1);
1524
+ dsc = &vop2->dscs[1];
1525
+ if (vcstate->dsc_enable)
1526
+ VOP_MODULE_SET(vop2, dsc, dsc_cfg_done, 1);
1527
+ } else {
1528
+ if (vcstate->dsc_enable)
1529
+ VOP_MODULE_SET(vop2, dsc, dsc_cfg_done, 1);
1530
+ }
1531
+}
1532
+
12481533 static inline void rk3568_vop2_cfg_done(struct drm_crtc *crtc)
12491534 {
12501535 struct vop2_video_port *vp = to_vop2_video_port(crtc);
....@@ -1279,6 +1564,9 @@
12791564 * This is rather low probability for miss some done bit.
12801565 */
12811566 val |= vop2_readl(vop2, RK3568_REG_CFG_DONE) & 0x7;
1567
+
1568
+ rockchip_drm_dbg(vop2->dev, VOP_DEBUG_CFG_DONE, "cfg_done: 0x%x\n", val);
1569
+
12821570 vop2_writel(vop2, 0, val);
12831571
12841572 /**
....@@ -1295,10 +1583,16 @@
12951583 static inline void rk3588_vop2_cfg_done(struct drm_crtc *crtc)
12961584 {
12971585 struct vop2_video_port *vp = to_vop2_video_port(crtc);
1586
+ struct rockchip_crtc_state *vcstate = to_rockchip_crtc_state(crtc->state);
1587
+ const struct vop2_video_port_data *vp_data = &vp->vop2->data->vp[vp->id];
12981588 struct vop2 *vop2 = vp->vop2;
12991589 uint32_t val;
13001590
13011591 val = RK3568_VOP2_GLB_CFG_DONE_EN | BIT(vp->id) | (BIT(vp->id) << 16);
1592
+ if (vcstate->splice_mode)
1593
+ val |= BIT(vp_data->splice_vp_id) | (BIT(vp_data->splice_vp_id) << 16);
1594
+
1595
+ rockchip_drm_dbg(vop2->dev, VOP_DEBUG_CFG_DONE, "cfg_done: 0x%x\n", val);
13021596
13031597 vop2_writel(vop2, 0, val);
13041598 }
....@@ -1320,6 +1614,7 @@
13201614 } else {
13211615 vop2_writel(vop2, 0, val);
13221616 }
1617
+
13231618 }
13241619
13251620 static inline void vop2_cfg_done(struct drm_crtc *crtc)
....@@ -1331,6 +1626,178 @@
13311626 return rk3568_vop2_cfg_done(crtc);
13321627 else
13331628 return rk3588_vop2_cfg_done(crtc);
1629
+}
1630
+
1631
+/*
1632
+ * A PD can power off by vsync when it's module attached to
1633
+ * a activated VP.
1634
+ */
1635
+static uint32_t vop2_power_domain_can_off_by_vsync(struct vop2_power_domain *pd)
1636
+{
1637
+ struct vop2 *vop2 = pd->vop2;
1638
+
1639
+ if (vop2->active_vp_mask & pd->vp_mask)
1640
+ return true;
1641
+ else
1642
+ return false;
1643
+}
1644
+
1645
+/*
1646
+ * Read VOP internal power domain on/off status.
1647
+ * We should query BISR_STS register in PMU for
1648
+ * power up/down status when memory repair is enabled.
1649
+ * Return value: 1 for power on, 0 for power off;
1650
+ */
1651
+static uint32_t vop2_power_domain_status(struct vop2_power_domain *pd)
1652
+{
1653
+ struct vop2 *vop2 = pd->vop2;
1654
+
1655
+ if (vop2_read_grf_reg(vop2->sys_pmu, &pd->data->regs->bisr_en_status))
1656
+ return vop2_read_grf_reg(vop2->sys_pmu, &pd->data->regs->pmu_status);
1657
+ else
1658
+ return vop2_read_reg(vop2, 0, &pd->data->regs->status) ? 0 : 1;
1659
+}
1660
+
1661
+static void vop2_wait_power_domain_off(struct vop2_power_domain *pd)
1662
+{
1663
+ struct vop2 *vop2 = pd->vop2;
1664
+ int val;
1665
+ int ret;
1666
+
1667
+ ret = readx_poll_timeout_atomic(vop2_power_domain_status, pd, val, !val, 0, 50 * 1000);
1668
+
1669
+ if (ret)
1670
+ DRM_DEV_ERROR(vop2->dev, "wait pd%d off timeout power_ctrl: 0x%x\n",
1671
+ ffs(pd->data->id) - 1, vop2_readl(vop2, 0x34));
1672
+}
1673
+
1674
+static void vop2_wait_power_domain_on(struct vop2_power_domain *pd)
1675
+{
1676
+ struct vop2 *vop2 = pd->vop2;
1677
+ int val;
1678
+ int ret;
1679
+
1680
+ ret = readx_poll_timeout_atomic(vop2_power_domain_status, pd, val, val, 0, 50 * 1000);
1681
+ if (ret)
1682
+ DRM_DEV_ERROR(vop2->dev, "wait pd%d on timeout power_ctrl: 0x%x\n",
1683
+ ffs(pd->data->id) - 1, vop2_readl(vop2, 0x34));
1684
+}
1685
+
1686
+/*
1687
+ * Power domain on take effect immediately
1688
+ */
1689
+static void vop2_power_domain_on(struct vop2_power_domain *pd)
1690
+{
1691
+ struct vop2 *vop2 = pd->vop2;
1692
+
1693
+ if (!pd->on) {
1694
+ dev_dbg(vop2->dev, "pd%d on\n", ffs(pd->data->id) - 1);
1695
+ vop2_wait_power_domain_off(pd);
1696
+ VOP_MODULE_SET(vop2, pd->data, pd, 0);
1697
+ vop2_wait_power_domain_on(pd);
1698
+ pd->on = true;
1699
+ }
1700
+}
1701
+
1702
+/*
1703
+ * Power domain off take effect by vsync.
1704
+ */
1705
+static void vop2_power_domain_off(struct vop2_power_domain *pd)
1706
+{
1707
+ struct vop2 *vop2 = pd->vop2;
1708
+
1709
+ dev_dbg(vop2->dev, "pd%d off\n", ffs(pd->data->id) - 1);
1710
+ pd->on = false;
1711
+ VOP_MODULE_SET(vop2, pd->data, pd, 1);
1712
+}
1713
+
1714
+static void vop2_power_domain_get(struct vop2_power_domain *pd)
1715
+{
1716
+ if (pd->parent)
1717
+ vop2_power_domain_get(pd->parent);
1718
+
1719
+ spin_lock(&pd->lock);
1720
+ if (pd->ref_count == 0) {
1721
+ if (pd->vop2->data->delayed_pd)
1722
+ cancel_delayed_work(&pd->power_off_work);
1723
+ vop2_power_domain_on(pd);
1724
+ }
1725
+ pd->ref_count++;
1726
+ spin_unlock(&pd->lock);
1727
+}
1728
+
1729
+static void vop2_power_domain_put(struct vop2_power_domain *pd)
1730
+{
1731
+ spin_lock(&pd->lock);
1732
+
1733
+ /*
1734
+ * For a nested power domain(PD_Cluster0 is the parent of PD_CLuster1/2/3)
1735
+ * the parent power domain must be enabled before child power domain
1736
+ * is on.
1737
+ *
1738
+ * So we may met this condition: Cluster0 is not on a activated VP,
1739
+ * but PD_Cluster0 must enabled as one of the child PD_CLUSTER1/2/3 is enabled.
1740
+ * when all child PD is disabled, we want disable the parent
1741
+ * PD(PD_CLUSTER0), but as module CLUSTER0 is not attcthed on a activated VP,
1742
+ * the turn off operation(which is take effect by vsync) will never take effect.
1743
+ * so we will see a "wait pd0 off timeout" log when we turn on PD_CLUSTER0 next time.
1744
+ *
1745
+ * So we have a check here
1746
+ */
1747
+ if (--pd->ref_count == 0 && vop2_power_domain_can_off_by_vsync(pd)) {
1748
+ if (pd->vop2->data->delayed_pd)
1749
+ schedule_delayed_work(&pd->power_off_work, msecs_to_jiffies(2500));
1750
+ else
1751
+ vop2_power_domain_off(pd);
1752
+ }
1753
+
1754
+ spin_unlock(&pd->lock);
1755
+ if (pd->parent)
1756
+ vop2_power_domain_put(pd->parent);
1757
+}
1758
+
1759
+/*
1760
+ * Called if the pd ref_count reach 0 after 2.5
1761
+ * seconds.
1762
+ */
1763
+static void vop2_power_domain_off_work(struct work_struct *work)
1764
+{
1765
+ struct vop2_power_domain *pd;
1766
+
1767
+ pd = container_of(to_delayed_work(work), struct vop2_power_domain, power_off_work);
1768
+
1769
+ spin_lock(&pd->lock);
1770
+ if (pd->ref_count == 0)
1771
+ vop2_power_domain_off(pd);
1772
+ spin_unlock(&pd->lock);
1773
+}
1774
+
1775
+static void vop2_win_enable(struct vop2_win *win)
1776
+{
1777
+ /*
1778
+ * a win such as cursor update by async:
1779
+ * first frame enable win pd, enable win, return without wait vsync
1780
+ * second frame come, but the first frame may still not enabled
1781
+ * in this case, the win pd is turn on by fist frame, so we don't
1782
+ * need get pd again.
1783
+ *
1784
+ * another case:
1785
+ * first frame: disable win, disable pd, return without wait vsync
1786
+ * second frame come very soon, the previous win disable may still not
1787
+ * take effect, but the pd is disable in progress, we should do pd_get
1788
+ * at this situation.
1789
+ *
1790
+ * check the backup register for previous enable operation.
1791
+ */
1792
+ if (!VOP_WIN_GET_REG_BAK(win->vop2, win, enable)) {
1793
+ if (win->pd) {
1794
+ if (win->pd->data->id == VOP2_PD_ESMART)
1795
+ return;
1796
+
1797
+ vop2_power_domain_get(win->pd);
1798
+ win->pd->vp_mask |= win->vp_mask;
1799
+ }
1800
+ }
13341801 }
13351802
13361803 static void vop2_win_multi_area_disable(struct vop2_win *parent)
....@@ -1346,31 +1813,63 @@
13461813 }
13471814 }
13481815
1349
-static void vop2_win_disable(struct vop2_win *win)
1816
+static void vop2_win_disable(struct vop2_win *win, bool skip_splice_win)
13501817 {
13511818 struct vop2 *vop2 = win->vop2;
13521819
1353
- VOP_WIN_SET(vop2, win, enable, 0);
1354
- if (win->feature & WIN_FEATURE_CLUSTER_MAIN) {
1355
- struct vop2_win *sub_win;
1356
- int i = 0;
1357
-
1358
- for (i = 0; i < vop2->registered_num_wins; i++) {
1359
- sub_win = &vop2->win[i];
1360
-
1361
- if ((sub_win->phys_id == win->phys_id) &&
1362
- (sub_win->feature & WIN_FEATURE_CLUSTER_SUB))
1363
- VOP_WIN_SET(vop2, sub_win, enable, 0);
1364
- }
1365
-
1366
- VOP_CLUSTER_SET(vop2, win, enable, 0);
1820
+ /* Disable the right splice win */
1821
+ if (win->splice_win && !skip_splice_win) {
1822
+ vop2_win_disable(win->splice_win, false);
1823
+ win->splice_win = NULL;
13671824 }
13681825
1369
- /*
1370
- * disable all other multi area win if we want disable area0 here
1371
- */
1372
- if (!win->parent && (win->feature & WIN_FEATURE_MULTI_AREA))
1373
- vop2_win_multi_area_disable(win);
1826
+ if (VOP_WIN_GET(vop2, win, enable) || VOP_WIN_GET_REG_BAK(vop2, win, enable)) {
1827
+ VOP_WIN_SET(vop2, win, enable, 0);
1828
+ if (win->feature & WIN_FEATURE_CLUSTER_MAIN) {
1829
+ struct vop2_win *sub_win;
1830
+ int i = 0;
1831
+
1832
+ for (i = 0; i < vop2->registered_num_wins; i++) {
1833
+ sub_win = &vop2->win[i];
1834
+
1835
+ if ((sub_win->phys_id == win->phys_id) &&
1836
+ (sub_win->feature & WIN_FEATURE_CLUSTER_SUB))
1837
+ VOP_WIN_SET(vop2, sub_win, enable, 0);
1838
+ }
1839
+
1840
+ VOP_CLUSTER_SET(vop2, win, enable, 0);
1841
+ }
1842
+
1843
+ /*
1844
+ * disable all other multi area win if we want disable area0 here
1845
+ */
1846
+ if (!win->parent && (win->feature & WIN_FEATURE_MULTI_AREA))
1847
+ vop2_win_multi_area_disable(win);
1848
+
1849
+ if (win->pd) {
1850
+
1851
+ /*
1852
+ * Don't dynamic turn on/off PD_ESMART.
1853
+ * (1) There is a design issue for PD_EMSART when attached
1854
+ * on VP1/2/3, we found it will trigger POST_BUF_EMPTY irq at vp0
1855
+ * in splice mode.
1856
+ * (2) PD_ESMART will be closed at esmart layers attathed on VPs
1857
+ * config done + FS, but different VP FS time is different, this
1858
+ * maybe lead to PD_ESMART closed at wrong time and display error.
1859
+ * (3) PD_ESMART power up maybe have 4 us delay, this will lead to POST_BUF_EMPTY.
1860
+ */
1861
+ if (win->pd->data->id == VOP2_PD_ESMART)
1862
+ return;
1863
+
1864
+ vop2_power_domain_put(win->pd);
1865
+ win->pd->vp_mask &= ~win->vp_mask;
1866
+ }
1867
+ }
1868
+
1869
+ if (win->left_win && win->splice_mode_right) {
1870
+ win->left_win = NULL;
1871
+ win->splice_mode_right = false;
1872
+ }
13741873 }
13751874
13761875 static inline void vop2_write_lut(struct vop2 *vop2, uint32_t offset, uint32_t v)
....@@ -1383,9 +1882,26 @@
13831882 return readl(vop2->lut_regs + offset);
13841883 }
13851884
1885
+static bool is_linear_10bit_yuv(uint32_t format)
1886
+{
1887
+ switch (format) {
1888
+ case DRM_FORMAT_NV15:
1889
+ case DRM_FORMAT_NV20:
1890
+ case DRM_FORMAT_NV30:
1891
+ return true;
1892
+ default:
1893
+ return false;
1894
+ }
1895
+}
1896
+
13861897 static enum vop2_data_format vop2_convert_format(uint32_t format)
13871898 {
13881899 switch (format) {
1900
+ case DRM_FORMAT_XRGB2101010:
1901
+ case DRM_FORMAT_ARGB2101010:
1902
+ case DRM_FORMAT_XBGR2101010:
1903
+ case DRM_FORMAT_ABGR2101010:
1904
+ return VOP2_FMT_XRGB101010;
13891905 case DRM_FORMAT_XRGB8888:
13901906 case DRM_FORMAT_ARGB8888:
13911907 case DRM_FORMAT_XBGR8888:
....@@ -1398,16 +1914,22 @@
13981914 case DRM_FORMAT_BGR565:
13991915 return VOP2_FMT_RGB565;
14001916 case DRM_FORMAT_NV12:
1917
+ case DRM_FORMAT_NV21:
1918
+ case DRM_FORMAT_YUV420_8BIT:
14011919 return VOP2_FMT_YUV420SP;
1402
- case DRM_FORMAT_NV12_10:
1920
+ case DRM_FORMAT_NV15:
1921
+ case DRM_FORMAT_YUV420_10BIT:
14031922 return VOP2_FMT_YUV420SP_10;
14041923 case DRM_FORMAT_NV16:
1924
+ case DRM_FORMAT_NV61:
14051925 return VOP2_FMT_YUV422SP;
1406
- case DRM_FORMAT_NV16_10:
1926
+ case DRM_FORMAT_NV20:
1927
+ case DRM_FORMAT_Y210:
14071928 return VOP2_FMT_YUV422SP_10;
14081929 case DRM_FORMAT_NV24:
1930
+ case DRM_FORMAT_NV42:
14091931 return VOP2_FMT_YUV444SP;
1410
- case DRM_FORMAT_NV24_10:
1932
+ case DRM_FORMAT_NV30:
14111933 return VOP2_FMT_YUV444SP_10;
14121934 case DRM_FORMAT_YUYV:
14131935 case DRM_FORMAT_YVYU:
....@@ -1424,6 +1946,11 @@
14241946 static enum vop2_afbc_format vop2_convert_afbc_format(uint32_t format)
14251947 {
14261948 switch (format) {
1949
+ case DRM_FORMAT_XRGB2101010:
1950
+ case DRM_FORMAT_ARGB2101010:
1951
+ case DRM_FORMAT_XBGR2101010:
1952
+ case DRM_FORMAT_ABGR2101010:
1953
+ return VOP2_AFBC_FMT_ARGB2101010;
14271954 case DRM_FORMAT_XRGB8888:
14281955 case DRM_FORMAT_ARGB8888:
14291956 case DRM_FORMAT_XBGR8888:
....@@ -1435,14 +1962,16 @@
14351962 case DRM_FORMAT_RGB565:
14361963 case DRM_FORMAT_BGR565:
14371964 return VOP2_AFBC_FMT_RGB565;
1438
- case DRM_FORMAT_NV12:
1965
+ case DRM_FORMAT_YUV420_8BIT:
14391966 return VOP2_AFBC_FMT_YUV420;
1440
- case DRM_FORMAT_NV12_10:
1967
+ case DRM_FORMAT_YUV420_10BIT:
14411968 return VOP2_AFBC_FMT_YUV420_10BIT;
1442
- case DRM_FORMAT_NV16:
1969
+ case DRM_FORMAT_YVYU:
14431970 case DRM_FORMAT_YUYV:
1971
+ case DRM_FORMAT_VYUY:
1972
+ case DRM_FORMAT_UYVY:
14441973 return VOP2_AFBC_FMT_YUV422;
1445
- case DRM_FORMAT_NV16_10:
1974
+ case DRM_FORMAT_Y210:
14461975 return VOP2_AFBC_FMT_YUV422_10BIT;
14471976
14481977 /* either of the below should not be reachable */
....@@ -1466,11 +1995,11 @@
14661995 case DRM_FORMAT_NV24:
14671996 case DRM_FORMAT_NV42:
14681997 return VOP2_TILED_8X8_FMT_YUV444SP;
1469
- case DRM_FORMAT_NV12_10:
1998
+ case DRM_FORMAT_NV15:
14701999 return VOP2_TILED_8X8_FMT_YUV420SP_10;
1471
- case DRM_FORMAT_NV16_10:
2000
+ case DRM_FORMAT_NV20:
14722001 return VOP2_TILED_8X8_FMT_YUV422SP_10;
1473
- case DRM_FORMAT_NV24_10:
2002
+ case DRM_FORMAT_NV30:
14742003 return VOP2_TILED_8X8_FMT_YUV444SP_10;
14752004 default:
14762005 DRM_WARN_ONCE("unsupported tiled format[%08x]\n", format);
....@@ -1495,13 +2024,13 @@
14952024 case DRM_FORMAT_NV42:
14962025 return tile_mode == ROCKCHIP_TILED_BLOCK_SIZE_8x8 ?
14972026 VOP3_TILED_8X8_FMT_YUV444SP : VOP3_TILED_4X4_FMT_YUV444SP;
1498
- case DRM_FORMAT_NV12_10:
2027
+ case DRM_FORMAT_NV15:
14992028 return tile_mode == ROCKCHIP_TILED_BLOCK_SIZE_8x8 ?
15002029 VOP3_TILED_8X8_FMT_YUV420SP_10 : VOP3_TILED_4X4_FMT_YUV420SP_10;
1501
- case DRM_FORMAT_NV16_10:
2030
+ case DRM_FORMAT_NV20:
15022031 return tile_mode == ROCKCHIP_TILED_BLOCK_SIZE_8x8 ?
15032032 VOP3_TILED_8X8_FMT_YUV422SP_10 : VOP3_TILED_4X4_FMT_YUV422SP_10;
1504
- case DRM_FORMAT_NV24_10:
2033
+ case DRM_FORMAT_NV30:
15052034 return tile_mode == ROCKCHIP_TILED_BLOCK_SIZE_8x8 ?
15062035 VOP3_TILED_8X8_FMT_YUV444SP_10 : VOP3_TILED_4X4_FMT_YUV444SP_10;
15072036 default:
....@@ -1540,6 +2069,8 @@
15402069 static bool vop2_win_rb_swap(uint32_t format)
15412070 {
15422071 switch (format) {
2072
+ case DRM_FORMAT_XBGR2101010:
2073
+ case DRM_FORMAT_ABGR2101010:
15432074 case DRM_FORMAT_XBGR8888:
15442075 case DRM_FORMAT_ABGR8888:
15452076 case DRM_FORMAT_BGR888:
....@@ -1554,7 +2085,7 @@
15542085 {
15552086 switch (format) {
15562087 case DRM_FORMAT_NV24:
1557
- case DRM_FORMAT_NV24_10:
2088
+ case DRM_FORMAT_NV30:
15582089 return true;
15592090 default:
15602091 return false;
....@@ -1567,8 +2098,9 @@
15672098 case DRM_FORMAT_NV12:
15682099 case DRM_FORMAT_NV16:
15692100 case DRM_FORMAT_YUYV:
1570
- case DRM_FORMAT_NV12_10:
1571
- case DRM_FORMAT_NV16_10:
2101
+ case DRM_FORMAT_Y210:
2102
+ case DRM_FORMAT_YUV420_8BIT:
2103
+ case DRM_FORMAT_YUV420_10BIT:
15722104 return true;
15732105 default:
15742106 return false;
....@@ -1581,9 +2113,9 @@
15812113 case DRM_FORMAT_NV12:
15822114 case DRM_FORMAT_NV16:
15832115 case DRM_FORMAT_NV24:
1584
- case DRM_FORMAT_NV12_10:
1585
- case DRM_FORMAT_NV16_10:
1586
- case DRM_FORMAT_NV24_10:
2116
+ case DRM_FORMAT_NV15:
2117
+ case DRM_FORMAT_NV20:
2118
+ case DRM_FORMAT_NV30:
15872119 case DRM_FORMAT_YUYV:
15882120 case DRM_FORMAT_UYVY:
15892121 return true;
....@@ -1627,6 +2159,19 @@
16272159 return false;
16282160 }
16292161
2162
+static bool vop3_output_rb_swap(uint32_t bus_format, uint32_t output_mode)
2163
+{
2164
+ /*
2165
+ * The default component order of serial rgb3x8 formats
2166
+ * is BGR. So it is needed to enable RB swap.
2167
+ */
2168
+ if (bus_format == MEDIA_BUS_FMT_RGB888_3X8 ||
2169
+ bus_format == MEDIA_BUS_FMT_RGB888_DUMMY_4X8)
2170
+ return true;
2171
+ else
2172
+ return false;
2173
+}
2174
+
16302175 static bool vop2_output_yc_swap(uint32_t bus_format)
16312176 {
16322177 switch (bus_format) {
....@@ -1645,6 +2190,7 @@
16452190 switch (bus_format) {
16462191 case MEDIA_BUS_FMT_YUV8_1X24:
16472192 case MEDIA_BUS_FMT_YUV10_1X30:
2193
+ case MEDIA_BUS_FMT_YUYV10_1X20:
16482194 case MEDIA_BUS_FMT_UYYVYY8_0_5X24:
16492195 case MEDIA_BUS_FMT_UYYVYY10_0_5X30:
16502196 case MEDIA_BUS_FMT_YUYV8_2X8:
....@@ -1740,6 +2286,15 @@
17402286 return (win->feature & WIN_FEATURE_CLUSTER_SUB);
17412287 }
17422288
2289
+static inline bool vop2_has_feature(struct vop2 *vop2, uint64_t feature)
2290
+{
2291
+ return (vop2->data->feature & feature);
2292
+}
2293
+
2294
+/*
2295
+ * 0: Full mode, 16 lines for one tail
2296
+ * 1: half block mode
2297
+ */
17432298 static int vop2_afbc_half_block_enable(struct vop2_plane_state *vpstate)
17442299 {
17452300 if (vpstate->rotate_270_en || vpstate->rotate_90_en)
....@@ -1748,11 +2303,15 @@
17482303 return 1;
17492304 }
17502305
1751
-static uint32_t vop2_afbc_transform_offset(struct vop2_plane_state *vpstate)
2306
+/*
2307
+ * @xoffset: the src x offset of the right win in splice mode, other wise it
2308
+ * must be zero.
2309
+ */
2310
+static uint32_t vop2_afbc_transform_offset(struct vop2_plane_state *vpstate, int xoffset)
17522311 {
17532312 struct drm_rect *src = &vpstate->src;
17542313 struct drm_framebuffer *fb = vpstate->base.fb;
1755
- uint32_t bpp = fb->format->bpp[0];
2314
+ uint32_t bpp = rockchip_drm_get_bpp(fb->format);
17562315 uint32_t vir_width = (fb->pitches[0] << 3) / (bpp ? bpp : 1);
17572316 uint32_t width = drm_rect_width(src) >> 16;
17582317 uint32_t height = drm_rect_height(src) >> 16;
....@@ -1768,6 +2327,7 @@
17682327 uint8_t top_crop_line_num = 0;
17692328 uint8_t bottom_crop_line_num = 0;
17702329
2330
+ act_xoffset += xoffset;
17712331 /* 16 pixel align */
17722332 if (height & 0xf)
17732333 align16_crop = 16 - (height & 0xf);
....@@ -2011,12 +2571,12 @@
20112571 {
20122572 const struct vop2_data *vop2_data = vop2->data;
20132573 const struct vop2_win_data *win_data = &vop2_data->win[win->win_id];
2014
- const struct drm_format_info *info;
20152574 struct vop2_plane_state *vpstate = to_vop2_plane_state(pstate);
20162575 struct drm_framebuffer *fb = pstate->fb;
20172576 uint32_t pixel_format = fb->format->format;
2018
- int hsub = drm_format_horz_chroma_subsampling(pixel_format);
2019
- int vsub = drm_format_vert_chroma_subsampling(pixel_format);
2577
+ const struct drm_format_info *info = drm_format_info(pixel_format);
2578
+ uint8_t hsub = info->hsub;
2579
+ uint8_t vsub = info->vsub;
20202580 uint16_t cbcr_src_w = src_w / hsub;
20212581 uint16_t cbcr_src_h = src_h / vsub;
20222582 uint16_t yrgb_hor_scl_mode, yrgb_ver_scl_mode;
....@@ -2025,8 +2585,6 @@
20252585 uint8_t xgt2 = 0, xgt4 = 0;
20262586 uint8_t ygt2 = 0, ygt4 = 0;
20272587 uint32_t val;
2028
-
2029
- info = drm_format_info(pixel_format);
20302588
20312589 if (is_vop3(vop2)) {
20322590 if (src_w >= (4 * dst_w)) {
....@@ -2246,7 +2804,7 @@
22462804 for_each_set_bit(phys_id, &win_mask, ROCKCHIP_MAX_LAYER) {
22472805 win = vop2_find_win_by_phys_id(vop2, phys_id);
22482806 need_wait_win_disabled |= VOP_WIN_GET(vop2, win, enable);
2249
- vop2_win_disable(win);
2807
+ vop2_win_disable(win, false);
22502808 }
22512809
22522810 if (need_wait_win_disabled) {
....@@ -2295,7 +2853,7 @@
22952853 struct vop2_plane_state *vpstate)
22962854 {
22972855 struct drm_plane_state *pstate = &vpstate->base;
2298
- struct rockchip_crtc_state *vcstate = to_rockchip_crtc_state(vp->crtc.state);
2856
+ struct rockchip_crtc_state *vcstate = to_rockchip_crtc_state(vp->rockchip_crtc.crtc.state);
22992857 int is_input_yuv = pstate->fb->format->is_yuv;
23002858 int is_output_yuv = vcstate->yuv_overlay;
23012859 int input_csc = vpstate->color_space;
....@@ -2480,8 +3038,14 @@
24803038 if (ret < 0)
24813039 goto err_disable_hclk;
24823040
3041
+ ret = clk_enable(vop2->pclk);
3042
+ if (ret < 0)
3043
+ goto err_disable_aclk;
3044
+
24833045 return 0;
24843046
3047
+err_disable_aclk:
3048
+ clk_disable(vop2->aclk);
24853049 err_disable_hclk:
24863050 clk_disable(vop2->hclk);
24873051 return ret;
....@@ -2489,6 +3053,7 @@
24893053
24903054 static void vop2_core_clks_disable(struct vop2 *vop2)
24913055 {
3056
+ clk_disable(vop2->pclk);
24923057 clk_disable(vop2->aclk);
24933058 clk_disable(vop2->hclk);
24943059 }
....@@ -2599,6 +3164,18 @@
25993164 return MODE_OK;
26003165 }
26013166
3167
+static inline bool
3168
+vop2_wb_connector_changed_only(struct drm_crtc_state *cstate, struct drm_connector *conn)
3169
+{
3170
+ struct drm_crtc_state *old_state;
3171
+ u32 changed_connectors;
3172
+
3173
+ old_state = drm_atomic_get_old_crtc_state(cstate->state, cstate->crtc);
3174
+ changed_connectors = cstate->connector_mask ^ old_state->connector_mask;
3175
+
3176
+ return BIT(drm_connector_index(conn)) == changed_connectors;
3177
+}
3178
+
26023179 static int vop2_wb_encoder_atomic_check(struct drm_encoder *encoder,
26033180 struct drm_crtc_state *cstate,
26043181 struct drm_connector_state *conn_state)
....@@ -2607,7 +3184,18 @@
26073184 struct rockchip_crtc_state *vcstate = to_rockchip_crtc_state(cstate);
26083185 struct vop2_video_port *vp = to_vop2_video_port(cstate->crtc);
26093186 struct drm_framebuffer *fb;
3187
+ struct drm_gem_object *obj, *uv_obj;
3188
+ struct rockchip_gem_object *rk_obj, *rk_uv_obj;
26103189
3190
+ /*
3191
+ * No need for a full modested when the only connector changed is the
3192
+ * writeback connector.
3193
+ */
3194
+ if (cstate->connectors_changed &&
3195
+ vop2_wb_connector_changed_only(cstate, conn_state->connector)) {
3196
+ cstate->connectors_changed = false;
3197
+ DRM_DEBUG("VP%d force change connectors_changed to false when only wb changed\n", vp->id);
3198
+ }
26113199 if (!conn_state->writeback_job || !conn_state->writeback_job->fb)
26123200 return 0;
26133201
....@@ -2620,7 +3208,7 @@
26203208 }
26213209
26223210 if ((fb->width > cstate->mode.hdisplay) ||
2623
- ((fb->height != cstate->mode.vdisplay) &&
3211
+ ((fb->height < cstate->mode.vdisplay) &&
26243212 (fb->height != (cstate->mode.vdisplay >> 1)))) {
26253213 DRM_DEBUG_KMS("Invalid framebuffer size %ux%u, Only support x scale down and 1/2 y scale down\n",
26263214 fb->width, fb->height);
....@@ -2628,7 +3216,7 @@
26283216 }
26293217
26303218 wb_state->scale_x_factor = vop2_scale_factor(SCALE_DOWN, VOP2_SCALE_DOWN_BIL,
2631
- cstate->mode.hdisplay, fb->width);
3219
+ cstate->mode.hdisplay, fb->width);
26323220 wb_state->scale_x_en = (fb->width < cstate->mode.hdisplay) ? 1 : 0;
26333221 wb_state->scale_y_en = (fb->height < cstate->mode.vdisplay) ? 1 : 0;
26343222
....@@ -2643,22 +3231,35 @@
26433231 }
26443232
26453233 wb_state->vp_id = vp->id;
2646
- wb_state->yrgb_addr = rockchip_fb_get_dma_addr(fb, 0);
2647
- /*
2648
- * uv address must follow yrgb address without gap.
2649
- * the fb->offsets is include stride, so we should
2650
- * not use it.
2651
- */
3234
+ obj = fb->obj[0];
3235
+ rk_obj = to_rockchip_obj(obj);
3236
+ wb_state->yrgb_addr = rk_obj->dma_addr + fb->offsets[0];
3237
+
26523238 if (fb->format->is_yuv) {
2653
- wb_state->uv_addr = wb_state->yrgb_addr;
2654
- wb_state->uv_addr += DIV_ROUND_UP(fb->width * fb->format->bpp[0], 8) * fb->height;
3239
+ uv_obj = fb->obj[1];
3240
+ rk_uv_obj = to_rockchip_obj(uv_obj);
3241
+
3242
+ wb_state->uv_addr = rk_uv_obj->dma_addr + fb->offsets[1];
26553243 }
26563244
26573245 return 0;
26583246 }
26593247
3248
+static void vop2_wb_encoder_atomic_disable(struct drm_encoder *encoder,
3249
+ struct drm_atomic_state *state)
3250
+{
3251
+ struct drm_crtc *crtc = encoder->crtc;
3252
+ struct vop2_video_port *vp = to_vop2_video_port(crtc);
3253
+
3254
+ if (!crtc->state->active_changed && !crtc->state->mode_changed) {
3255
+ crtc->state->connectors_changed = false;
3256
+ DRM_DEBUG("VP%d force change connectors_changed to false when disable wb\n", vp->id);
3257
+ }
3258
+}
3259
+
26603260 static const struct drm_encoder_helper_funcs vop2_wb_encoder_helper_funcs = {
26613261 .atomic_check = vop2_wb_encoder_atomic_check,
3262
+ .atomic_disable = vop2_wb_encoder_atomic_disable,
26623263 };
26633264
26643265 static const struct drm_connector_helper_funcs vop2_wb_connector_helper_funcs = {
....@@ -2741,10 +3342,12 @@
27413342 if (conn_state->writeback_job && conn_state->writeback_job->fb) {
27423343 struct drm_framebuffer *fb = conn_state->writeback_job->fb;
27433344
2744
- DRM_DEV_DEBUG(vop2->dev, "Enable wb %ux%u fmt: %u pitches: %d addr: %pad\n",
2745
- fb->width, fb->height, wb_state->format, fb->pitches[0], &wb_state->yrgb_addr);
3345
+ rockchip_drm_dbg(vop2->dev, VOP_DEBUG_WB,
3346
+ "Enable wb %ux%u fmt: %u pitches: %d addr: %pad\n",
3347
+ fb->width, fb->height, wb_state->format,
3348
+ fb->pitches[0], &wb_state->yrgb_addr);
27463349
2747
- drm_writeback_queue_job(wb_conn, conn_state->writeback_job);
3350
+ drm_writeback_queue_job(wb_conn, conn_state);
27483351 conn_state->writeback_job = NULL;
27493352
27503353 spin_lock_irqsave(&wb->job_lock, flags);
....@@ -2773,6 +3376,7 @@
27733376 VOP_MODULE_SET(vop2, wb, r2y_en, r2y);
27743377 VOP_MODULE_SET(vop2, wb, enable, 1);
27753378 vop2_wb_irqs_enable(vop2);
3379
+ VOP_CTRL_SET(vop2, wb_dma_finish_and_en, 1);
27763380 }
27773381 }
27783382
....@@ -2797,6 +3401,7 @@
27973401
27983402 return;
27993403 }
3404
+
28003405 spin_lock(&vop2->reg_lock);
28013406 VOP_MODULE_SET(vop2, vp, dsp_lut_en, 0);
28023407 vop2_cfg_done(crtc);
....@@ -2812,8 +3417,7 @@
28123417 spin_lock(&vop2->reg_lock);
28133418
28143419 VOP_MODULE_SET(vop2, vp, dsp_lut_en, 1);
2815
- VOP_MODULE_SET(vop2, vp, gamma_update_en, 1);
2816
- vop2_cfg_done(crtc);
3420
+ vop2_write_reg_uncached(vop2, &vp->regs->gamma_update_en, 1);
28173421 vp->gamma_lut_active = true;
28183422
28193423 spin_unlock(&vop2->reg_lock);
....@@ -2833,7 +3437,7 @@
28333437 vop2_write_lut(vop2, i << 2, lut[i]);
28343438
28353439 VOP_MODULE_SET(vop2, vp, dsp_lut_en, 1);
2836
- VOP_MODULE_SET(vop2, vp, gamma_update_en, 1);
3440
+ vop2_write_reg_uncached(vop2, &vp->regs->gamma_update_en, 1);
28373441 vp->gamma_lut_active = true;
28383442
28393443 spin_unlock(&vop2->reg_lock);
....@@ -2853,27 +3457,14 @@
28533457 if (vop2->version == VOP_VERSION_RK3568) {
28543458 rk3568_crtc_load_lut(crtc);
28553459 } else {
2856
- rk3588_crtc_load_lut(crtc, vp->lut);
2857
- vop2_cfg_done(crtc);
3460
+ struct rockchip_crtc_state *vcstate = to_rockchip_crtc_state(crtc->state);
3461
+ const struct vop2_video_port_data *vp_data = &vop2->data->vp[vp->id];
3462
+ struct vop2_video_port *splice_vp = &vop2->vps[vp_data->splice_vp_id];
3463
+
3464
+ rk3588_crtc_load_lut(&vp->rockchip_crtc.crtc, vp->lut);
3465
+ if (vcstate->splice_mode)
3466
+ rk3588_crtc_load_lut(&splice_vp->rockchip_crtc.crtc, vp->lut);
28583467 }
2859
- /*
2860
- * maybe appear the following case:
2861
- * -> set gamma
2862
- * -> config done
2863
- * -> atomic commit
2864
- * --> update win format
2865
- * --> update win address
2866
- * ---> here maybe meet vop hardware frame start, and triggle some config take affect.
2867
- * ---> as only some config take affect, this maybe lead to iommu pagefault.
2868
- * --> update win size
2869
- * --> update win other parameters
2870
- * -> config done
2871
- *
2872
- * so we add vop2_wait_for_fs_by_done_bit_status() to make sure the first config done take
2873
- * effect and then to do next frame config.
2874
- */
2875
- if (VOP_MODULE_GET(vop2, vp, standby) == 0)
2876
- vop2_wait_for_fs_by_done_bit_status(vp);
28773468 }
28783469
28793470 static void rockchip_vop2_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red,
....@@ -2915,6 +3506,7 @@
29153506 struct drm_modeset_acquire_ctx *ctx)
29163507 {
29173508 struct vop2_video_port *vp = to_vop2_video_port(crtc);
3509
+ struct vop2 *vop2 = vp->vop2;
29183510 int i;
29193511
29203512 if (!vp->lut)
....@@ -2929,6 +3521,25 @@
29293521 rockchip_vop2_crtc_fb_gamma_set(crtc, red[i], green[i],
29303522 blue[i], i);
29313523 vop2_crtc_load_lut(crtc);
3524
+ vop2_cfg_done(crtc);
3525
+ /*
3526
+ * maybe appear the following case:
3527
+ * -> set gamma
3528
+ * -> config done
3529
+ * -> atomic commit
3530
+ * --> update win format
3531
+ * --> update win address
3532
+ * ---> here maybe meet vop hardware frame start, and triggle some config take affect.
3533
+ * ---> as only some config take affect, this maybe lead to iommu pagefault.
3534
+ * --> update win size
3535
+ * --> update win other parameters
3536
+ * -> config done
3537
+ *
3538
+ * so we add vop2_wait_for_fs_by_done_bit_status() to make sure the first config done take
3539
+ * effect and then to do next frame config.
3540
+ */
3541
+ if (VOP_MODULE_GET(vop2, vp, standby) == 0)
3542
+ vop2_wait_for_fs_by_done_bit_status(vp);
29323543
29333544 return 0;
29343545 }
....@@ -2951,6 +3562,7 @@
29513562 static int vop2_crtc_atomic_cubic_lut_set(struct drm_crtc *crtc,
29523563 struct drm_crtc_state *old_state)
29533564 {
3565
+ struct rockchip_crtc_state *vcstate = to_rockchip_crtc_state(crtc->state);
29543566 struct vop2_video_port *vp = to_vop2_video_port(crtc);
29553567 struct rockchip_drm_private *private = crtc->dev->dev_private;
29563568 struct drm_color_lut *lut = vp->cubic_lut;
....@@ -3001,12 +3613,51 @@
30013613 *cubic_lut_kvaddr = 0;
30023614 }
30033615
3616
+ VOP_MODULE_SET(vop2, vp, lut_dma_rid, vp->lut_dma_rid);
30043617 VOP_MODULE_SET(vop2, vp, cubic_lut_mst, cubic_lut_mst);
30053618 VOP_MODULE_SET(vop2, vp, cubic_lut_update_en, 1);
30063619 VOP_MODULE_SET(vop2, vp, cubic_lut_en, 1);
30073620 VOP_CTRL_SET(vop2, lut_dma_en, 1);
30083621
3622
+ if (vcstate->splice_mode) {
3623
+ const struct vop2_video_port_data *vp_data = &vop2->data->vp[vp->id];
3624
+ struct vop2_video_port *splice_vp = &vop2->vps[vp_data->splice_vp_id];
3625
+
3626
+ VOP_MODULE_SET(vop2, splice_vp, cubic_lut_mst, cubic_lut_mst);
3627
+ VOP_MODULE_SET(vop2, splice_vp, cubic_lut_update_en, 1);
3628
+ VOP_MODULE_SET(vop2, splice_vp, cubic_lut_en, 1);
3629
+ }
3630
+
30093631 return 0;
3632
+}
3633
+
3634
+static void vop2_attach_cubic_lut_prop(struct drm_crtc *crtc, unsigned int cubic_lut_size)
3635
+{
3636
+ struct rockchip_drm_private *private = crtc->dev->dev_private;
3637
+
3638
+ drm_object_attach_property(&crtc->base, private->cubic_lut_prop, 0);
3639
+ drm_object_attach_property(&crtc->base, private->cubic_lut_size_prop, cubic_lut_size);
3640
+}
3641
+
3642
+static void vop2_cubic_lut_init(struct vop2 *vop2)
3643
+{
3644
+ const struct vop2_data *vop2_data = vop2->data;
3645
+ const struct vop2_video_port_data *vp_data;
3646
+ struct vop2_video_port *vp;
3647
+ struct drm_crtc *crtc;
3648
+ int i;
3649
+
3650
+ for (i = 0; i < vop2_data->nr_vps; i++) {
3651
+ vp = &vop2->vps[i];
3652
+ crtc = &vp->rockchip_crtc.crtc;
3653
+ if (!crtc->dev)
3654
+ continue;
3655
+ vp_data = &vop2_data->vp[vp->id];
3656
+ vp->cubic_lut_len = vp_data->cubic_lut_len;
3657
+
3658
+ if (vp->cubic_lut_len)
3659
+ vop2_attach_cubic_lut_prop(crtc, vp->cubic_lut_len);
3660
+ }
30103661 }
30113662
30123663 static int vop2_core_clks_prepare_enable(struct vop2 *vop2)
....@@ -3025,7 +3676,15 @@
30253676 goto err;
30263677 }
30273678
3679
+ ret = clk_prepare_enable(vop2->pclk);
3680
+ if (ret < 0) {
3681
+ dev_err(vop2->dev, "failed to enable pclk - %d\n", ret);
3682
+ goto err1;
3683
+ }
3684
+
30283685 return 0;
3686
+err1:
3687
+ clk_disable_unprepare(vop2->aclk);
30293688 err:
30303689 clk_disable_unprepare(vop2->hclk);
30313690
....@@ -3142,6 +3801,18 @@
31423801
31433802 }
31443803
3804
+static void rk3588_vop2_regsbak(struct vop2 *vop2)
3805
+{
3806
+ uint32_t *base = vop2->regs;
3807
+ int i;
3808
+
3809
+ /*
3810
+ * No need to backup DSC/GAMMA_LUT/BPP_LUT/MMU
3811
+ */
3812
+ for (i = 0; i < (0x2000 >> 2); i++)
3813
+ vop2->regsbak[i] = base[i];
3814
+}
3815
+
31453816 static void vop2_initial(struct drm_crtc *crtc)
31463817 {
31473818 struct vop2_video_port *vp = to_vop2_video_port(crtc);
....@@ -3166,7 +3837,13 @@
31663837 if (vop2_soc_is_rk3566())
31673838 VOP_CTRL_SET(vop2, otp_en, 1);
31683839
3169
- memcpy(vop2->regsbak, vop2->regs, vop2->len);
3840
+ /*
3841
+ * rk3588 don't support access mmio by memcpy
3842
+ */
3843
+ if (vop2->version == VOP_VERSION_RK3588)
3844
+ rk3588_vop2_regsbak(vop2);
3845
+ else
3846
+ memcpy(vop2->regsbak, vop2->regs, vop2->len);
31703847
31713848 VOP_MODULE_SET(vop2, wb, axi_yrgb_id, 0xd);
31723849 VOP_MODULE_SET(vop2, wb, axi_uv_id, 0xe);
....@@ -3178,10 +3855,10 @@
31783855 }
31793856
31803857 /*
3181
- * This is unused and error init value for rk3528 vp1, if less of this config,
3858
+ * This is unused and error init value for rk3528/rk3562 vp1, if less of this config,
31823859 * vp1 can't display normally.
31833860 */
3184
- if (vop2->version == VOP_VERSION_RK3528)
3861
+ if (vop2->version == VOP_VERSION_RK3528 || vop2->version == VOP_VERSION_RK3562)
31853862 vop2_mask_write(vop2, 0x700, 0x3, 4, 0, 0, true);
31863863
31873864 VOP_CTRL_SET(vop2, cfg_done_en, 1);
....@@ -3192,6 +3869,7 @@
31923869 VOP_CTRL_SET(vop2, auto_gating_en, 0);
31933870
31943871 VOP_CTRL_SET(vop2, aclk_pre_auto_gating_en, 0);
3872
+
31953873 /*
31963874 * Register OVERLAY_LAYER_SEL and OVERLAY_PORT_SEL should take effect immediately,
31973875 * than windows configuration(CLUSTER/ESMART/SMART) can take effect according the
....@@ -3204,9 +3882,17 @@
32043882 */
32053883 VOP_CTRL_SET(vop2, if_ctrl_cfg_done_imd, 1);
32063884
3885
+ /* Close dynamic turn on/off rk3588 PD_ESMART and keep esmart pd on when enable */
3886
+ if (vop2->version == VOP_VERSION_RK3588) {
3887
+ struct vop2_power_domain *esmart_pd = vop2_find_pd_by_id(vop2, VOP2_PD_ESMART);
3888
+
3889
+ if (vop2_power_domain_status(esmart_pd))
3890
+ esmart_pd->on = true;
3891
+ else
3892
+ vop2_power_domain_on(esmart_pd);
3893
+ }
32073894 vop2_layer_map_initial(vop2, current_vp_id);
32083895 vop2_axi_irqs_enable(vop2);
3209
-
32103896 vop2->is_enabled = true;
32113897 }
32123898
....@@ -3220,6 +3906,93 @@
32203906 vp->id, ret);
32213907 }
32223908
3909
+/*
3910
+ * The internal PD of VOP2 on rk3588 take effect immediately
3911
+ * for power up and take effect by vsync for power down.
3912
+ *
3913
+ * And the PD_CLUSTER0 is a parent PD of PD_CLUSTER1/2/3,
3914
+ * we may have this use case:
3915
+ * Cluster0 is attached to VP0 for HDMI output,
3916
+ * Cluster1 is attached to VP1 for MIPI DSI,
3917
+
3918
+ * When we enable Cluster1 on VP1, we should enable PD_CLUSTER0 as
3919
+ * it is the parent PD, event though HDMI is plugout, VP1 is disabled,
3920
+ * the PD of Cluster0 should keep power on.
3921
+
3922
+ * When system go to suspend:
3923
+ * (1) Power down PD of Cluster1 before VP1 standby(the power down is take
3924
+ * effect by vsync)
3925
+ * (2) Power down PD of Cluster0
3926
+ *
3927
+ * But we have problem at step (2), Cluster0 is attached to VP0. but VP0
3928
+ * is in standby mode, as it is never used or hdmi plugout. So there is
3929
+ * no vsync, the power down will never take effect.
3930
+
3931
+ * According to IC designer: We must power down all internal PD of VOP
3932
+ * before we power down the global PD_VOP.
3933
+
3934
+ * So we get this workaround:
3935
+ * If we found a VP is in standby mode when we want power down a PD is
3936
+ * attached to it, we release the VP from standby mode, than it will
3937
+ * run a default timing and generate vsync. Than we can power down the
3938
+ * PD by this vsync. After all this is done, we standby the VP at last.
3939
+ */
3940
+static void vop2_power_domain_off_by_disabled_vp(struct vop2_power_domain *pd)
3941
+{
3942
+ struct vop2_video_port *vp = NULL;
3943
+ struct vop2 *vop2 = pd->vop2;
3944
+ struct vop2_win *win;
3945
+ struct drm_crtc *crtc;
3946
+ uint32_t vp_id;
3947
+ uint8_t phys_id;
3948
+ int ret;
3949
+
3950
+ if (pd->data->id == VOP2_PD_CLUSTER0 || pd->data->id == VOP2_PD_CLUSTER1 ||
3951
+ pd->data->id == VOP2_PD_CLUSTER2 || pd->data->id == VOP2_PD_CLUSTER3 ||
3952
+ pd->data->id == VOP2_PD_ESMART) {
3953
+ phys_id = ffs(pd->data->module_id_mask) - 1;
3954
+ win = vop2_find_win_by_phys_id(vop2, phys_id);
3955
+ vp_id = ffs(win->vp_mask) - 1;
3956
+ vp = &vop2->vps[vp_id];
3957
+ } else {
3958
+ DRM_DEV_ERROR(vop2->dev, "unexpected power on pd%d\n", ffs(pd->data->id) - 1);
3959
+ }
3960
+
3961
+ if (vp) {
3962
+ ret = clk_prepare_enable(vp->dclk);
3963
+ if (ret < 0)
3964
+ DRM_DEV_ERROR(vop2->dev, "failed to enable dclk for video port%d - %d\n",
3965
+ vp->id, ret);
3966
+ crtc = &vp->rockchip_crtc.crtc;
3967
+ VOP_MODULE_SET(vop2, vp, standby, 0);
3968
+ vop2_power_domain_off(pd);
3969
+ vop2_cfg_done(crtc);
3970
+ vop2_wait_power_domain_off(pd);
3971
+
3972
+ reinit_completion(&vp->dsp_hold_completion);
3973
+ vop2_dsp_hold_valid_irq_enable(crtc);
3974
+ VOP_MODULE_SET(vop2, vp, standby, 1);
3975
+ ret = wait_for_completion_timeout(&vp->dsp_hold_completion, msecs_to_jiffies(50));
3976
+ if (!ret)
3977
+ DRM_DEV_INFO(vop2->dev, "wait for vp%d dsp_hold timeout\n", vp->id);
3978
+
3979
+ vop2_dsp_hold_valid_irq_disable(crtc);
3980
+ clk_disable_unprepare(vp->dclk);
3981
+ }
3982
+}
3983
+
3984
+static void vop2_power_off_all_pd(struct vop2 *vop2)
3985
+{
3986
+ struct vop2_power_domain *pd, *n;
3987
+
3988
+ list_for_each_entry_safe_reverse(pd, n, &vop2->pd_list_head, list) {
3989
+ if (vop2_power_domain_status(pd))
3990
+ vop2_power_domain_off_by_disabled_vp(pd);
3991
+ pd->on = false;
3992
+ pd->vp_mask = 0;
3993
+ }
3994
+}
3995
+
32233996 static void vop2_disable(struct drm_crtc *crtc)
32243997 {
32253998 struct vop2_video_port *vp = to_vop2_video_port(crtc);
....@@ -3230,7 +4003,6 @@
32304003 if (--vop2->enable_count > 0)
32314004 return;
32324005
3233
- vop2->is_enabled = false;
32344006 if (vop2->is_iommu_enabled) {
32354007 /*
32364008 * vop2 standby complete, so iommu detach is safe.
....@@ -3239,25 +4011,393 @@
32394011 rockchip_drm_dma_detach_device(vop2->drm_dev, vop2->dev);
32404012 vop2->is_iommu_enabled = false;
32414013 }
4014
+ if (vop2->version == VOP_VERSION_RK3588)
4015
+ vop2_power_off_all_pd(vop2);
32424016
4017
+ vop2->is_enabled = false;
32434018 pm_runtime_put_sync(vop2->dev);
32444019
4020
+ clk_disable_unprepare(vop2->pclk);
32454021 clk_disable_unprepare(vop2->aclk);
32464022 clk_disable_unprepare(vop2->hclk);
4023
+}
4024
+
4025
+static void vop2_crtc_disable_dsc(struct vop2 *vop2, u8 dsc_id)
4026
+{
4027
+ struct vop2_dsc *dsc = &vop2->dscs[dsc_id];
4028
+
4029
+ VOP_MODULE_SET(vop2, dsc, dsc_mer, 1);
4030
+ VOP_MODULE_SET(vop2, dsc, dsc_interface_mode, 0);
4031
+ VOP_MODULE_SET(vop2, dsc, dsc_en, 0);
4032
+ VOP_MODULE_SET(vop2, dsc, rst_deassert, 0);
4033
+}
4034
+
4035
+static struct vop2_clk *vop2_clk_get(struct vop2 *vop2, const char *name)
4036
+{
4037
+ struct vop2_clk *clk, *n;
4038
+
4039
+ if (!name)
4040
+ return NULL;
4041
+
4042
+ list_for_each_entry_safe(clk, n, &vop2->clk_list_head, list) {
4043
+ if (!strcmp(clk_hw_get_name(&clk->hw), name))
4044
+ return clk;
4045
+ }
4046
+
4047
+ return NULL;
4048
+}
4049
+
4050
+static void vop2_clk_set_parent(struct clk *clk, struct clk *parent)
4051
+{
4052
+ int ret = 0;
4053
+
4054
+ if (parent)
4055
+ ret = clk_set_parent(clk, parent);
4056
+ if (ret < 0)
4057
+ DRM_WARN("failed to set %s as parent for %s\n",
4058
+ __clk_get_name(parent), __clk_get_name(clk));
4059
+}
4060
+
4061
+static int vop2_extend_clk_init(struct vop2 *vop2)
4062
+{
4063
+ const char * const extend_clk_name[] = {
4064
+ "hdmi0_phy_pll", "hdmi1_phy_pll"};
4065
+ struct drm_device *drm_dev = vop2->drm_dev;
4066
+ struct clk *clk;
4067
+ struct vop2_extend_pll *extend_pll;
4068
+ int i;
4069
+
4070
+ INIT_LIST_HEAD(&vop2->extend_clk_list_head);
4071
+
4072
+ if (vop2->version != VOP_VERSION_RK3588)
4073
+ return 0;
4074
+
4075
+ for (i = 0; i < ARRAY_SIZE(extend_clk_name); i++) {
4076
+ clk = devm_clk_get_optional(drm_dev->dev, extend_clk_name[i]);
4077
+ if (IS_ERR(clk)) {
4078
+ dev_warn(drm_dev->dev, "failed to get %s: %ld\n",
4079
+ extend_clk_name[i], PTR_ERR(clk));
4080
+ continue;
4081
+ }
4082
+
4083
+ if (!clk)
4084
+ continue;
4085
+
4086
+ extend_pll = devm_kzalloc(drm_dev->dev, sizeof(*extend_pll), GFP_KERNEL);
4087
+ if (!extend_pll)
4088
+ return -ENOMEM;
4089
+
4090
+ extend_pll->clk = clk;
4091
+ extend_pll->vp_mask = 0;
4092
+ strncpy(extend_pll->clk_name, extend_clk_name[i], sizeof(extend_pll->clk_name));
4093
+ list_add_tail(&extend_pll->list, &vop2->extend_clk_list_head);
4094
+ }
4095
+
4096
+ return 0;
4097
+}
4098
+
4099
+static struct vop2_extend_pll *vop2_extend_clk_find_by_name(struct vop2 *vop2, char *clk_name)
4100
+{
4101
+ struct vop2_extend_pll *extend_pll;
4102
+
4103
+ list_for_each_entry(extend_pll, &vop2->extend_clk_list_head, list) {
4104
+ if (!strcmp(extend_pll->clk_name, clk_name))
4105
+ return extend_pll;
4106
+ }
4107
+
4108
+ return NULL;
4109
+}
4110
+
4111
+static int vop2_extend_clk_switch_pll(struct vop2 *vop2, struct vop2_extend_pll *src,
4112
+ struct vop2_extend_pll *dst)
4113
+{
4114
+ struct vop2_clk *dclk;
4115
+ u32 vp_mask;
4116
+ int i = 0;
4117
+ char clk_name[32];
4118
+
4119
+ if (!src->vp_mask)
4120
+ return -EINVAL;
4121
+
4122
+ if (dst->vp_mask)
4123
+ return -EBUSY;
4124
+
4125
+ vp_mask = src->vp_mask;
4126
+
4127
+ while (vp_mask) {
4128
+ if ((BIT(i) & src->vp_mask)) {
4129
+ snprintf(clk_name, sizeof(clk_name), "dclk%d", i);
4130
+ dclk = vop2_clk_get(vop2, clk_name);
4131
+ clk_set_rate(dst->clk, dclk->rate);
4132
+ vop2_clk_set_parent(vop2->vps[i].dclk, dst->clk);
4133
+ src->vp_mask &= ~BIT(i);
4134
+ dst->vp_mask |= BIT(i);
4135
+ }
4136
+ i++;
4137
+ vp_mask = vp_mask >> 1;
4138
+ }
4139
+
4140
+ return 0;
4141
+}
4142
+
4143
+static inline int vop2_extend_clk_get_vp_id(struct vop2_extend_pll *ext_pll)
4144
+{
4145
+ return ffs(ext_pll->vp_mask) - 1;
4146
+}
4147
+
4148
+/*
4149
+ * Here are 2 hdmi phy pll can use for video port dclk. The strategies of how to use hdmi phy pll
4150
+ * as follow:
4151
+ *
4152
+ * 1. hdmi phy pll can be used for video port0/1/2 when output format under 4K@60Hz;
4153
+ *
4154
+ * 2. When a video port connect both hdmi0 and hdmi1(may also connect other output interface),
4155
+ * it must hold the hdmi0 and hdmi1 phy pll, and other video port can't use it. if request dclk
4156
+ * is under 4K@60Hz, set the video port dlk parent as hdmi0 phy pll.if hdmi0 or hdmi1 phy pll
4157
+ * is used by other video port, report a error.
4158
+ *
4159
+ * 3. When a video port(A) connect hdmi0(may also connect other output interface but not hdmi1),
4160
+ * it must hold the hdmi0 phy pll, and other video port can't use it. If both hdmi0 and hdmi1
4161
+ * phy pll is used by other video port, report a error. If hdmi0 phy pll is used by another
4162
+ * video port(B) and hdmi1 phy pll is free, set hdmi1 phy pll as video port(B) dclk parent and
4163
+ * video port(A) hold hdmi0 phy pll. If hdmi0 phy pll is free, video port(A) hold hdmi0 pll.If
4164
+ * video port(A) hold hdmi0 phy pll and request dclk is under 4k@60Hz, set hdmi0 phy pll as
4165
+ * video port(A) dclk parent.
4166
+ *
4167
+ * 4. When a video port(A) connect hdmi1(may also connect other output interface but not hdmi0),
4168
+ * it must hold the hdmi1 phy pll, and other video port can't use it. If both hdmi0 and hdmi1
4169
+ * phy pll is used by other video port, report a error. If hdmi1 phy pll is used by another
4170
+ * video port(B) and hdmi0 phy pll is free, set hdmi0 phy pll as video port(B) dclk parent and
4171
+ * video port(A) hold hdmi1 phy pll. If hdmi1 phy pll is free, video port(A) hold hdmi1 pll. If
4172
+ * video port(A) hold hdmi1 phy pll and request dclk is under 4k@60Hz, set hdmi1 phy pll as
4173
+ * video port(A) dclk parent.
4174
+ *
4175
+ * 5. When a video port connect dp(0, 1, or both, may also connect other output type but not hdmi0
4176
+ * and hdmi1). If the request dclk is higher than 4K@60Hz or video port id is 2, do nothing.
4177
+ * Otherwise get a free hdmi phy pll as video port dclk parent. If no free hdmi phy pll can be
4178
+ * get, report a error.
4179
+ */
4180
+
4181
+static int vop2_clk_set_parent_extend(struct vop2_video_port *vp,
4182
+ struct rockchip_crtc_state *vcstate, bool enable)
4183
+{
4184
+ struct vop2 *vop2 = vp->vop2;
4185
+ struct vop2_extend_pll *hdmi0_phy_pll, *hdmi1_phy_pll;
4186
+ struct drm_crtc *crtc = &vp->rockchip_crtc.crtc;
4187
+ struct drm_display_mode *adjusted_mode = &crtc->state->adjusted_mode;
4188
+
4189
+ hdmi0_phy_pll = vop2_extend_clk_find_by_name(vop2, "hdmi0_phy_pll");
4190
+ hdmi1_phy_pll = vop2_extend_clk_find_by_name(vop2, "hdmi1_phy_pll");
4191
+
4192
+ if (hdmi0_phy_pll)
4193
+ clk_get_rate(hdmi0_phy_pll->clk);
4194
+ if (hdmi1_phy_pll)
4195
+ clk_get_rate(hdmi1_phy_pll->clk);
4196
+
4197
+ if ((!hdmi0_phy_pll && !hdmi1_phy_pll) ||
4198
+ ((vcstate->output_if & VOP_OUTPUT_IF_HDMI0) && !hdmi0_phy_pll) ||
4199
+ ((vcstate->output_if & VOP_OUTPUT_IF_HDMI1) && !hdmi1_phy_pll))
4200
+ return 0;
4201
+
4202
+ if (enable) {
4203
+ if ((vcstate->output_if & VOP_OUTPUT_IF_HDMI0) &&
4204
+ (vcstate->output_if & VOP_OUTPUT_IF_HDMI1)) {
4205
+ if (hdmi0_phy_pll->vp_mask) {
4206
+ DRM_ERROR("hdmi0 phy pll is used by vp%d\n",
4207
+ vop2_extend_clk_get_vp_id(hdmi0_phy_pll));
4208
+ return -EBUSY;
4209
+ }
4210
+
4211
+ if (hdmi1_phy_pll->vp_mask) {
4212
+ DRM_ERROR("hdmi1 phy pll is used by vp%d\n",
4213
+ vop2_extend_clk_get_vp_id(hdmi1_phy_pll));
4214
+ return -EBUSY;
4215
+ }
4216
+
4217
+ if (adjusted_mode->crtc_clock > VOP2_MAX_DCLK_RATE)
4218
+ vop2_clk_set_parent(vp->dclk, vp->dclk_parent);
4219
+ else
4220
+ vop2_clk_set_parent(vp->dclk, hdmi0_phy_pll->clk);
4221
+
4222
+ hdmi0_phy_pll->vp_mask |= BIT(vp->id);
4223
+ hdmi1_phy_pll->vp_mask |= BIT(vp->id);
4224
+ } else if ((vcstate->output_if & VOP_OUTPUT_IF_HDMI0) &&
4225
+ !(vcstate->output_if & VOP_OUTPUT_IF_HDMI1)) {
4226
+ if (hdmi0_phy_pll->vp_mask) {
4227
+ if (hdmi1_phy_pll) {
4228
+ if (hdmi1_phy_pll->vp_mask) {
4229
+ DRM_ERROR("hdmi0: phy pll is used by vp%d:vp%d\n",
4230
+ vop2_extend_clk_get_vp_id(hdmi0_phy_pll),
4231
+ vop2_extend_clk_get_vp_id(hdmi1_phy_pll));
4232
+ return -EBUSY;
4233
+ }
4234
+
4235
+ vop2_extend_clk_switch_pll(vop2, hdmi0_phy_pll,
4236
+ hdmi1_phy_pll);
4237
+ } else {
4238
+ DRM_ERROR("hdmi0: phy pll is used by vp%d\n",
4239
+ vop2_extend_clk_get_vp_id(hdmi0_phy_pll));
4240
+ return -EBUSY;
4241
+ }
4242
+ }
4243
+
4244
+ if (adjusted_mode->crtc_clock > VOP2_MAX_DCLK_RATE)
4245
+ vop2_clk_set_parent(vp->dclk, vp->dclk_parent);
4246
+ else
4247
+ vop2_clk_set_parent(vp->dclk, hdmi0_phy_pll->clk);
4248
+
4249
+ hdmi0_phy_pll->vp_mask |= BIT(vp->id);
4250
+ } else if (!(vcstate->output_if & VOP_OUTPUT_IF_HDMI0) &&
4251
+ (vcstate->output_if & VOP_OUTPUT_IF_HDMI1)) {
4252
+ if (hdmi1_phy_pll->vp_mask) {
4253
+ if (hdmi0_phy_pll) {
4254
+ if (hdmi0_phy_pll->vp_mask) {
4255
+ DRM_ERROR("hdmi1: phy pll is used by vp%d:vp%d\n",
4256
+ vop2_extend_clk_get_vp_id(hdmi0_phy_pll),
4257
+ vop2_extend_clk_get_vp_id(hdmi1_phy_pll));
4258
+ return -EBUSY;
4259
+ }
4260
+
4261
+ vop2_extend_clk_switch_pll(vop2, hdmi1_phy_pll,
4262
+ hdmi0_phy_pll);
4263
+ } else {
4264
+ DRM_ERROR("hdmi1: phy pll is used by vp%d\n",
4265
+ vop2_extend_clk_get_vp_id(hdmi1_phy_pll));
4266
+ return -EBUSY;
4267
+ }
4268
+ }
4269
+
4270
+ if (adjusted_mode->crtc_clock > VOP2_MAX_DCLK_RATE)
4271
+ vop2_clk_set_parent(vp->dclk, vp->dclk_parent);
4272
+ else
4273
+ vop2_clk_set_parent(vp->dclk, hdmi1_phy_pll->clk);
4274
+
4275
+ hdmi1_phy_pll->vp_mask |= BIT(vp->id);
4276
+ } else if (output_if_is_dp(vcstate->output_if)) {
4277
+ if (vp->id == 2) {
4278
+ vop2_clk_set_parent(vp->dclk, vp->dclk_parent);
4279
+ return 0;
4280
+ }
4281
+
4282
+ if (hdmi0_phy_pll && !hdmi0_phy_pll->vp_mask) {
4283
+ vop2_clk_set_parent(vp->dclk, hdmi0_phy_pll->clk);
4284
+ hdmi0_phy_pll->vp_mask |= BIT(vp->id);
4285
+ } else if (hdmi1_phy_pll && !hdmi1_phy_pll->vp_mask) {
4286
+ vop2_clk_set_parent(vp->dclk, hdmi1_phy_pll->clk);
4287
+ hdmi1_phy_pll->vp_mask |= BIT(vp->id);
4288
+ } else {
4289
+ vop2_clk_set_parent(vp->dclk, vp->dclk_parent);
4290
+ DRM_INFO("No free hdmi phy pll for DP, use default parent\n");
4291
+ }
4292
+ }
4293
+ } else {
4294
+ if (hdmi0_phy_pll && (BIT(vp->id) & hdmi0_phy_pll->vp_mask))
4295
+ hdmi0_phy_pll->vp_mask &= ~BIT(vp->id);
4296
+
4297
+ if (hdmi1_phy_pll && (BIT(vp->id) & hdmi1_phy_pll->vp_mask))
4298
+ hdmi1_phy_pll->vp_mask &= ~BIT(vp->id);
4299
+ }
4300
+
4301
+ return 0;
4302
+}
4303
+
4304
+static void vop2_crtc_atomic_enter_psr(struct drm_crtc *crtc, struct drm_crtc_state *old_state)
4305
+{
4306
+ struct vop2_video_port *vp = to_vop2_video_port(crtc);
4307
+ struct vop2 *vop2 = vp->vop2;
4308
+ struct vop2_win *win;
4309
+ unsigned long win_mask = vp->enabled_win_mask;
4310
+ int phys_id;
4311
+
4312
+ for_each_set_bit(phys_id, &win_mask, ROCKCHIP_MAX_LAYER) {
4313
+ win = vop2_find_win_by_phys_id(vop2, phys_id);
4314
+ VOP_WIN_SET(vop2, win, enable, 0);
4315
+
4316
+ if (win->feature & WIN_FEATURE_CLUSTER_MAIN)
4317
+ VOP_CLUSTER_SET(vop2, win, enable, 0);
4318
+ }
4319
+
4320
+ vop2_cfg_done(crtc);
4321
+ vop2_wait_for_fs_by_done_bit_status(vp);
4322
+ drm_crtc_vblank_off(crtc);
4323
+ if (hweight8(vop2->active_vp_mask) == 1) {
4324
+ u32 adjust_aclk_rate = 0;
4325
+ u32 htotal = (VOP_MODULE_GET(vop2, vp, htotal_pw) >> 16) & 0xffff;
4326
+ u32 pre_scan_dly = VOP_MODULE_GET(vop2, vp, pre_scan_htiming);
4327
+ u32 pre_scan_hblank = pre_scan_dly & 0x1fff;
4328
+ u32 pre_scan_hactive = (pre_scan_dly >> 16) & 0x1fff;
4329
+ u32 dclk_rate = crtc->state->adjusted_mode.crtc_clock / 1000;
4330
+ /**
4331
+ * (pre_scan_hblank + pre_scan_hactive) x aclk_margin / adjust_aclk_rate = hotal / dclk_rate
4332
+ * aclk_margin = 1.2, so
4333
+ * adjust_aclk_rate = (pre_scan_hblank + pre_scan_hactive) x 1.2 * aclk_margin / htotal
4334
+ */
4335
+
4336
+ adjust_aclk_rate = (pre_scan_hblank + pre_scan_hactive) * dclk_rate * 12 / 10 / htotal;
4337
+
4338
+ vop2->aclk_rate = clk_get_rate(vop2->aclk);
4339
+ clk_set_rate(vop2->aclk, adjust_aclk_rate * 1000000L);
4340
+ vop2->aclk_rate_reset = true;
4341
+ }
4342
+}
4343
+
4344
+static void vop2_crtc_atomic_exit_psr(struct drm_crtc *crtc, struct drm_crtc_state *old_state)
4345
+{
4346
+ struct vop2_video_port *vp = to_vop2_video_port(crtc);
4347
+ struct vop2 *vop2 = vp->vop2;
4348
+ u32 phys_id;
4349
+ struct vop2_win *win;
4350
+ unsigned long enabled_win_mask = vp->enabled_win_mask;
4351
+
4352
+ drm_crtc_vblank_on(crtc);
4353
+ if (vop2->aclk_rate_reset)
4354
+ clk_set_rate(vop2->aclk, vop2->aclk_rate);
4355
+ vop2->aclk_rate_reset = false;
4356
+
4357
+ for_each_set_bit(phys_id, &enabled_win_mask, ROCKCHIP_MAX_LAYER) {
4358
+ win = vop2_find_win_by_phys_id(vop2, phys_id);
4359
+ VOP_WIN_SET(vop2, win, enable, 1);
4360
+ if (win->feature & WIN_FEATURE_CLUSTER_MAIN)
4361
+ VOP_CLUSTER_SET(vop2, win, enable, 1);
4362
+ }
4363
+
4364
+ vop2_cfg_done(crtc);
4365
+ vop2_wait_for_fs_by_done_bit_status(vp);
32474366 }
32484367
32494368 static void vop2_crtc_atomic_disable(struct drm_crtc *crtc,
32504369 struct drm_crtc_state *old_state)
32514370 {
32524371 struct vop2_video_port *vp = to_vop2_video_port(crtc);
4372
+ struct rockchip_crtc_state *vcstate = to_rockchip_crtc_state(crtc->state);
32534373 struct vop2 *vop2 = vp->vop2;
32544374 const struct vop2_video_port_data *vp_data = &vop2->data->vp[vp->id];
4375
+ struct vop2_video_port *splice_vp = &vop2->vps[vp_data->splice_vp_id];
4376
+ bool dual_channel = !!(vcstate->output_flags & ROCKCHIP_OUTPUT_DUAL_CHANNEL_LEFT_RIGHT_MODE);
32554377 int ret;
32564378
32574379 WARN_ON(vp->event);
4380
+
4381
+ if (crtc->state->self_refresh_active) {
4382
+ vop2_crtc_atomic_enter_psr(crtc, old_state);
4383
+ goto out;
4384
+ }
4385
+
32584386 vop2_lock(vop2);
32594387 DRM_DEV_INFO(vop2->dev, "Crtc atomic disable vp%d\n", vp->id);
4388
+ VOP_MODULE_SET(vop2, vp, almost_full_or_en, 0);
4389
+ VOP_MODULE_SET(vop2, vp, line_flag_or_en, 0);
32604390 drm_crtc_vblank_off(crtc);
4391
+ if (vop2->dscs[vcstate->dsc_id].enabled &&
4392
+ vop2->dscs[vcstate->dsc_id].attach_vp_id == vp->id &&
4393
+ vop2->data->nr_dscs) {
4394
+ if (dual_channel) {
4395
+ vop2_crtc_disable_dsc(vop2, 0);
4396
+ vop2_crtc_disable_dsc(vop2, 1);
4397
+ } else {
4398
+ vop2_crtc_disable_dsc(vop2, vcstate->dsc_id);
4399
+ }
4400
+ }
32614401
32624402 if (vp->cubic_lut) {
32634403 VOP_MODULE_SET(vop2, vp, cubic_lut_update_en, 0);
....@@ -3268,6 +4408,58 @@
32684408 VOP_MODULE_SET(vop2, vp, hdr_lut_update_en, 0);
32694409 vop2_disable_all_planes_for_crtc(crtc);
32704410
4411
+ if (vop2->dscs[vcstate->dsc_id].enabled &&
4412
+ vop2->dscs[vcstate->dsc_id].attach_vp_id == vp->id &&
4413
+ vop2->data->nr_dscs && vop2->dscs[vcstate->dsc_id].pd) {
4414
+ if (dual_channel) {
4415
+ vop2_power_domain_put(vop2->dscs[0].pd);
4416
+ vop2_power_domain_put(vop2->dscs[1].pd);
4417
+ vop2->dscs[0].pd->vp_mask = 0;
4418
+ vop2->dscs[1].pd->vp_mask = 0;
4419
+ vop2->dscs[0].attach_vp_id = -1;
4420
+ vop2->dscs[1].attach_vp_id = -1;
4421
+ } else {
4422
+ vop2_power_domain_put(vop2->dscs[vcstate->dsc_id].pd);
4423
+ vop2->dscs[vcstate->dsc_id].pd->vp_mask = 0;
4424
+ vop2->dscs[vcstate->dsc_id].attach_vp_id = -1;
4425
+ }
4426
+ vop2->dscs[vcstate->dsc_id].enabled = false;
4427
+ vcstate->dsc_enable = false;
4428
+ }
4429
+
4430
+ if (vp->output_if & VOP_OUTPUT_IF_eDP0)
4431
+ VOP_GRF_SET(vop2, grf, grf_edp0_en, 0);
4432
+
4433
+ if (vp->output_if & VOP_OUTPUT_IF_eDP1) {
4434
+ VOP_GRF_SET(vop2, grf, grf_edp1_en, 0);
4435
+ if (dual_channel)
4436
+ VOP_CTRL_SET(vop2, edp_dual_en, 0);
4437
+ }
4438
+
4439
+ if (vp->output_if & VOP_OUTPUT_IF_HDMI0) {
4440
+ VOP_GRF_SET(vop2, grf, grf_hdmi0_dsc_en, 0);
4441
+ VOP_GRF_SET(vop2, grf, grf_hdmi0_en, 0);
4442
+ }
4443
+
4444
+ if (vp->output_if & VOP_OUTPUT_IF_HDMI1) {
4445
+ VOP_GRF_SET(vop2, grf, grf_hdmi1_dsc_en, 0);
4446
+ VOP_GRF_SET(vop2, grf, grf_hdmi1_en, 0);
4447
+ if (dual_channel)
4448
+ VOP_CTRL_SET(vop2, hdmi_dual_en, 0);
4449
+ }
4450
+
4451
+ if ((vcstate->output_if & VOP_OUTPUT_IF_DP1) && dual_channel)
4452
+ VOP_CTRL_SET(vop2, dp_dual_en, 0);
4453
+
4454
+ if ((vcstate->output_if & VOP_OUTPUT_IF_MIPI1) && dual_channel)
4455
+ VOP_CTRL_SET(vop2, mipi_dual_en, 0);
4456
+
4457
+ VOP_MODULE_SET(vop2, vp, dual_channel_en, 0);
4458
+ VOP_MODULE_SET(vop2, vp, dual_channel_swap, 0);
4459
+
4460
+ vp->output_if = 0;
4461
+
4462
+ vop2_clk_set_parent_extend(vp, vcstate, false);
32714463 /*
32724464 * Vop standby will take effect at end of current frame,
32734465 * if dsp hold valid irq happen, it means standby complete.
....@@ -3280,6 +4472,8 @@
32804472
32814473 spin_lock(&vop2->reg_lock);
32824474
4475
+ VOP_MODULE_SET(vop2, vp, splice_en, 0);
4476
+
32834477 VOP_MODULE_SET(vop2, vp, standby, 1);
32844478
32854479 spin_unlock(&vop2->reg_lock);
....@@ -3291,12 +4485,21 @@
32914485 vop2_dsp_hold_valid_irq_disable(crtc);
32924486
32934487 vop2_disable(crtc);
4488
+
4489
+ vop2->active_vp_mask &= ~BIT(vp->id);
4490
+ if (vcstate->splice_mode)
4491
+ vop2->active_vp_mask &= ~BIT(splice_vp->id);
4492
+ vcstate->splice_mode = false;
4493
+ vcstate->output_flags = 0;
4494
+ vp->splice_mode_right = false;
4495
+ vp->loader_protect = false;
4496
+ splice_vp->splice_mode_right = false;
32944497 memset(&vp->active_tv_state, 0, sizeof(vp->active_tv_state));
32954498 vop2_unlock(vop2);
32964499
3297
- vop2->active_vp_mask &= ~BIT(vp->id);
32984500 vop2_set_system_status(vop2);
32994501
4502
+out:
33004503 if (crtc->state->event && !crtc->state->active) {
33014504 spin_lock_irq(&crtc->dev->event_lock);
33024505 drm_crtc_send_vblank_event(crtc, crtc->state->event);
....@@ -3306,23 +4509,241 @@
33064509 }
33074510 }
33084511
4512
+static int vop2_cluster_two_win_mode_check(struct drm_plane_state *pstate)
4513
+{
4514
+ struct drm_atomic_state *state = pstate->state;
4515
+ struct drm_plane *plane = pstate->plane;
4516
+ struct vop2_win *win = to_vop2_win(plane);
4517
+ struct vop2 *vop2 = win->vop2;
4518
+ struct vop2_win *main_win = vop2_find_win_by_phys_id(vop2, win->phys_id);
4519
+ struct drm_plane_state *main_pstate;
4520
+ int actual_w = drm_rect_width(&pstate->src) >> 16;
4521
+ int xoffset;
4522
+
4523
+ if (pstate->fb->modifier == DRM_FORMAT_MOD_LINEAR)
4524
+ xoffset = 0;
4525
+ else
4526
+ xoffset = pstate->src.x1 >> 16;
4527
+
4528
+ if ((actual_w + xoffset % 16) > 2048) {
4529
+ DRM_ERROR("%s act_w(%d) + xoffset(%d) / 16 << 2048 in two win mode\n",
4530
+ win->name, actual_w, xoffset);
4531
+ return -EINVAL;
4532
+ }
4533
+
4534
+ main_pstate = drm_atomic_get_new_plane_state(state, &main_win->base);
4535
+
4536
+ if (pstate->fb->modifier != main_pstate->fb->modifier) {
4537
+ DRM_ERROR("%s(fb->modifier: 0x%llx) must use same data layout as %s(fb->modifier: 0x%llx)\n",
4538
+ win->name, pstate->fb->modifier, main_win->name, main_pstate->fb->modifier);
4539
+ return -EINVAL;
4540
+ }
4541
+
4542
+ if (main_pstate->fb->modifier == DRM_FORMAT_MOD_LINEAR)
4543
+ xoffset = 0;
4544
+ else
4545
+ xoffset = main_pstate->src.x1 >> 16;
4546
+ actual_w = drm_rect_width(&main_pstate->src) >> 16;
4547
+
4548
+ if ((actual_w + xoffset % 16) > 2048) {
4549
+ DRM_ERROR("%s act_w(%d) + xoffset(%d) / 16 << 2048 in two win mode\n",
4550
+ main_win->name, actual_w, xoffset);
4551
+ return -EINVAL;
4552
+ }
4553
+
4554
+ return 0;
4555
+}
4556
+
4557
+static int vop2_cluter_splice_scale_check(struct vop2_win *win, struct drm_plane_state *pstate,
4558
+ u16 hdisplay)
4559
+{
4560
+ struct drm_rect src = drm_plane_state_src(pstate);
4561
+ struct drm_rect dst = drm_plane_state_dest(pstate);
4562
+ u16 half_hdisplay = hdisplay >> 1;
4563
+
4564
+ /* scale up is ok */
4565
+ if ((drm_rect_width(&src) >> 16) <= drm_rect_width(&dst))
4566
+ return 0;
4567
+
4568
+ if ((drm_rect_width(&src) >> 16) <= VOP2_MAX_VP_OUTPUT_WIDTH)
4569
+ return 0;
4570
+ /*
4571
+ * Cluster scale down limitation in splice mode:
4572
+ * If scale down, must display at horizontal center
4573
+ */
4574
+ if ((dst.x1 < half_hdisplay) && (dst.x2 > half_hdisplay)) {
4575
+ if ((dst.x2 + dst.x1) != hdisplay) {
4576
+ DRM_ERROR("%s src_w: %d dst_w %d dst(%d %d) must scale down at center in splice mode\n",
4577
+ win->name, drm_rect_width(&src) >> 16,
4578
+ drm_rect_width(&dst), dst.x1, dst.x2);
4579
+ return -EINVAL;
4580
+ }
4581
+
4582
+ if (drm_rect_calc_hscale(&src, &dst, 1, FRAC_16_16(6, 5)) < 0) {
4583
+ DRM_ERROR("%s %d --> %d scale down factor should < 1.2 in splice mode\n",
4584
+ win->name, drm_rect_width(&src) >> 16, drm_rect_width(&dst));
4585
+ return -EINVAL;
4586
+ }
4587
+ }
4588
+
4589
+ return 0;
4590
+}
4591
+
4592
+static int vop2_plane_splice_check(struct drm_plane *plane, struct drm_plane_state *pstate,
4593
+ struct drm_display_mode *mode)
4594
+{
4595
+ struct vop2_win *win = to_vop2_win(plane);
4596
+ int ret = 0;
4597
+
4598
+ if (!(win->feature & WIN_FEATURE_SPLICE_LEFT)) {
4599
+ DRM_ERROR("%s can't be left win in splice mode\n", win->name);
4600
+ return -EINVAL;
4601
+ }
4602
+
4603
+ if (win->feature & WIN_FEATURE_CLUSTER_SUB) {
4604
+ DRM_ERROR("%s can't use two win mode in splice mode\n", win->name);
4605
+ return -EINVAL;
4606
+ }
4607
+
4608
+ if ((pstate->rotation & DRM_MODE_ROTATE_270) ||
4609
+ (pstate->rotation & DRM_MODE_ROTATE_90) ||
4610
+ (pstate->rotation & DRM_MODE_REFLECT_X)) {
4611
+ DRM_ERROR("%s can't rotate 270/90 and xmirror in splice mode\n", win->name);
4612
+ return -EINVAL;
4613
+ }
4614
+
4615
+ /* check for cluster splice scale down */
4616
+ if (win->feature & WIN_FEATURE_CLUSTER_MAIN)
4617
+ ret = vop2_cluter_splice_scale_check(win, pstate, mode->hdisplay);
4618
+
4619
+ return ret;
4620
+}
4621
+
4622
+/*
4623
+ * 1. NV12/NV16/YUYV xoffset must aligned as 2 pixel;
4624
+ * 2. NV12/NV15 yoffset must aligned as 2 pixel;
4625
+ * 3. NV30 xoffset must aligned as 4 pixel;
4626
+ * 4. NV15/NV20 xoffset must aligend as 8 pixel at rk3568/rk3588/rk3528/rk3562,
4627
+ * others must aligned as 4 pixel;
4628
+ */
4629
+static int vop2_linear_yuv_format_check(struct drm_plane *plane, struct drm_plane_state *state)
4630
+{
4631
+ struct vop2_plane_state *vpstate = to_vop2_plane_state(state);
4632
+ struct drm_crtc *crtc = state->crtc;
4633
+ struct vop2_video_port *vp = to_vop2_video_port(crtc);
4634
+ struct vop2_win *win = to_vop2_win(plane);
4635
+ struct drm_framebuffer *fb = state->fb;
4636
+ struct drm_rect *src = &vpstate->src;
4637
+ u32 val = 0;
4638
+
4639
+ if (vpstate->afbc_en || vpstate->tiled_en || !fb->format->is_yuv)
4640
+ return 0;
4641
+
4642
+ switch (fb->format->format) {
4643
+ case DRM_FORMAT_NV12:
4644
+ case DRM_FORMAT_NV21:
4645
+ val = src->x1 >> 16;
4646
+ if (val % 2) {
4647
+ src->x1 = ALIGN(val, 2) << 16;
4648
+ DRM_WARN("VP%d %s src x offset[%d] must aligned as 2 pixel at NV12 fmt, and adjust to: %d\n", vp->id, win->name, val, src->x1 >> 16);
4649
+ }
4650
+ val = src->y1 >> 16;
4651
+ if (val % 2) {
4652
+ src->y1 = ALIGN(val, 2) << 16;
4653
+ DRM_WARN("VP%d %s src y offset[%d] must aligned as 2 pixel at NV12 fmt, and adjust to: %d\n", vp->id, win->name, val, src->y1 >> 16);
4654
+ }
4655
+ break;
4656
+ case DRM_FORMAT_NV15:
4657
+ val = src->y1 >> 16;
4658
+ if (val % 2) {
4659
+ src->y1 = ALIGN(val, 2) << 16;
4660
+ DRM_WARN("VP%d %s src y offset[%d] must aligned as 2 pixel at NV15 fmt, and adjust to: %d\n", vp->id, win->name, val, src->y1 >> 16);
4661
+ }
4662
+ if (vp->vop2->version == VOP_VERSION_RK3568 ||
4663
+ vp->vop2->version == VOP_VERSION_RK3588 ||
4664
+ vp->vop2->version == VOP_VERSION_RK3528 ||
4665
+ vp->vop2->version == VOP_VERSION_RK3562) {
4666
+ val = src->x1 >> 16;
4667
+ if (val % 8) {
4668
+ src->x1 = ALIGN(val, 8) << 16;
4669
+ DRM_WARN("VP%d %s src x offset[%d] must aligned as 8 pixel at NV15 fmt, and adjust to: %d\n", vp->id, win->name, val, src->x1 >> 16);
4670
+ }
4671
+ } else {
4672
+ val = src->x1 >> 16;
4673
+ if (val % 4) {
4674
+ src->x1 = ALIGN(val, 4) << 16;
4675
+ DRM_WARN("VP%d %s src x offset[%d] must aligned as 4 pixel at NV15 fmt, and adjust to: %d\n", vp->id, win->name, val, src->x1 >> 16);
4676
+ }
4677
+ }
4678
+ break;
4679
+ case DRM_FORMAT_NV16:
4680
+ case DRM_FORMAT_NV61:
4681
+ case DRM_FORMAT_YUYV:
4682
+ case DRM_FORMAT_YVYU:
4683
+ case DRM_FORMAT_VYUY:
4684
+ case DRM_FORMAT_UYVY:
4685
+ val = src->x1 >> 16;
4686
+ if (val % 2) {
4687
+ src->x1 = ALIGN(val, 2) << 16;
4688
+ DRM_WARN("VP%d %s src x offset[%d] must aligned as 2 pixel at YUYV fmt, and adjust to: %d\n", vp->id, win->name, val, src->x1 >> 16);
4689
+ }
4690
+ break;
4691
+ case DRM_FORMAT_NV20:
4692
+ if (vp->vop2->version == VOP_VERSION_RK3568 ||
4693
+ vp->vop2->version == VOP_VERSION_RK3588 ||
4694
+ vp->vop2->version == VOP_VERSION_RK3528 ||
4695
+ vp->vop2->version == VOP_VERSION_RK3562) {
4696
+ val = src->x1 >> 16;
4697
+ if (val % 8) {
4698
+ src->x1 = ALIGN(val, 8) << 16;
4699
+ DRM_WARN("VP%d %s src x offset[%d] must aligned as 8 pixel at NV20 fmt, and adjust to: %d\n", vp->id, win->name, val, src->x1 >> 16);
4700
+ }
4701
+ } else {
4702
+ val = src->x1 >> 16;
4703
+ if (val % 4) {
4704
+ src->x1 = ALIGN(val, 4) << 16;
4705
+ DRM_WARN("VP%d %s src x offset[%d] must aligned as 4 pixel at NV20 fmt, and adjust to: %d\n", vp->id, win->name, val, src->x1 >> 16);
4706
+ }
4707
+ }
4708
+ break;
4709
+ case DRM_FORMAT_NV30:
4710
+ val = src->x1 >> 16;
4711
+ if (val % 4) {
4712
+ src->x1 = ALIGN(val, 4) << 16;
4713
+ DRM_WARN("VP%d %s src x offset[%d] must aligned as 4 pixel at NV30 fmt, and adjust to: %d\n", vp->id, win->name, val, src->x1 >> 16);
4714
+ }
4715
+ break;
4716
+ default:
4717
+ return 0;
4718
+ }
4719
+
4720
+ return 0;
4721
+}
4722
+
33094723 static int vop2_plane_atomic_check(struct drm_plane *plane, struct drm_plane_state *state)
33104724 {
33114725 struct vop2_plane_state *vpstate = to_vop2_plane_state(state);
33124726 struct vop2_win *win = to_vop2_win(plane);
4727
+ struct vop2_win *splice_win;
4728
+ struct vop2 *vop2 = win->vop2;
33134729 struct drm_framebuffer *fb = state->fb;
4730
+ struct drm_display_mode *mode;
33144731 struct drm_crtc *crtc = state->crtc;
33154732 struct drm_crtc_state *cstate;
4733
+ struct rockchip_crtc_state *vcstate;
33164734 struct vop2_video_port *vp;
33174735 const struct vop2_data *vop2_data;
33184736 struct drm_rect *dest = &vpstate->dest;
33194737 struct drm_rect *src = &vpstate->src;
4738
+ struct drm_gem_object *obj, *uv_obj;
4739
+ struct rockchip_gem_object *rk_obj, *rk_uv_obj;
33204740 int min_scale = win->regs->scl ? FRAC_16_16(1, 8) : DRM_PLANE_HELPER_NO_SCALING;
33214741 int max_scale = win->regs->scl ? FRAC_16_16(8, 1) : DRM_PLANE_HELPER_NO_SCALING;
33224742 uint32_t tile_size = 1;
4743
+ int max_input_w;
4744
+ int max_input_h;
33234745 unsigned long offset;
33244746 dma_addr_t dma_addr;
3325
- void *kvaddr;
33264747 int ret;
33274748
33284749 crtc = crtc ? crtc : plane->state->crtc;
....@@ -3338,6 +4759,26 @@
33384759 if (WARN_ON(!cstate))
33394760 return -EINVAL;
33404761
4762
+ mode = &cstate->mode;
4763
+ vcstate = to_rockchip_crtc_state(cstate);
4764
+
4765
+ max_input_w = vop2_data->max_input.width;
4766
+ max_input_h = vop2_data->max_input.height;
4767
+
4768
+ if (vop2_has_feature(win->vop2, VOP_FEATURE_SPLICE)) {
4769
+ if (mode->hdisplay > VOP2_MAX_VP_OUTPUT_WIDTH) {
4770
+ vcstate->splice_mode = true;
4771
+ ret = vop2_plane_splice_check(plane, state, mode);
4772
+ if (ret < 0)
4773
+ return ret;
4774
+ splice_win = vop2_find_win_by_phys_id(vop2, win->splice_win_id);
4775
+ splice_win->splice_mode_right = true;
4776
+ splice_win->left_win = win;
4777
+ win->splice_win = splice_win;
4778
+ max_input_w <<= 1;
4779
+ }
4780
+ }
4781
+
33414782 vpstate->xmirror_en = (state->rotation & DRM_MODE_REFLECT_X) ? 1 : 0;
33424783 vpstate->ymirror_en = (state->rotation & DRM_MODE_REFLECT_Y) ? 1 : 0;
33434784 vpstate->rotate_270_en = (state->rotation & DRM_MODE_ROTATE_270) ? 1 : 0;
....@@ -3347,7 +4788,6 @@
33474788 DRM_ERROR("Can't rotate 90 and 270 at the same time\n");
33484789 return -EINVAL;
33494790 }
3350
-
33514791
33524792 ret = drm_atomic_helper_check_plane_state(state, cstate,
33534793 min_scale, max_scale,
....@@ -3388,13 +4828,13 @@
33884828 return 0;
33894829 }
33904830
3391
- if (drm_rect_width(src) >> 16 > vop2_data->max_input.width ||
3392
- drm_rect_height(src) >> 16 > vop2_data->max_input.height) {
4831
+ if (drm_rect_width(src) >> 16 > max_input_w ||
4832
+ drm_rect_height(src) >> 16 > max_input_h) {
33934833 DRM_ERROR("Invalid source: %dx%d. max input: %dx%d\n",
33944834 drm_rect_width(src) >> 16,
33954835 drm_rect_height(src) >> 16,
3396
- vop2_data->max_input.width,
3397
- vop2_data->max_input.height);
4836
+ max_input_w,
4837
+ max_input_h);
33984838 return -EINVAL;
33994839 }
34004840
....@@ -3417,23 +4857,40 @@
34174857 * This is special feature at rk356x, the cluster layer only can support
34184858 * afbc format and can't support linear format;
34194859 */
3420
- if (VOP_MAJOR(vop2_data->version) == 0x40 && VOP_MINOR(vop2_data->version) == 0x15) {
4860
+ if (vp->vop2->version == VOP_VERSION_RK3568) {
34214861 if (vop2_cluster_window(win) && !vpstate->afbc_en) {
34224862 DRM_ERROR("Unsupported linear format at %s\n", win->name);
34234863 return -EINVAL;
34244864 }
34254865 }
34264866
3427
- /*
3428
- * Src.x1 can be odd when do clip, but yuv plane start point
3429
- * need align with 2 pixel.
3430
- */
3431
- if (fb->format->is_yuv && ((state->src.x1 >> 16) % 2)) {
3432
- DRM_ERROR("Invalid Source: Yuv format not support odd xpos\n");
3433
- return -EINVAL;
4867
+ if (vp->vop2->version > VOP_VERSION_RK3568) {
4868
+ if (vop2_cluster_window(win) && !vpstate->afbc_en && fb->format->is_yuv && !is_vop3(vop2)) {
4869
+ DRM_ERROR("Unsupported linear yuv format at %s\n", win->name);
4870
+ return -EINVAL;
4871
+ }
4872
+
4873
+ if (vop2_cluster_window(win) && !vpstate->afbc_en &&
4874
+ (win->supported_rotations & state->rotation)) {
4875
+ DRM_ERROR("Unsupported linear rotation(%d) format at %s\n",
4876
+ state->rotation, win->name);
4877
+ return -EINVAL;
4878
+ }
34344879 }
34354880
3436
- offset = ALIGN_DOWN(src->x1 >> 16, tile_size) * fb->format->bpp[0] / 8 * tile_size;
4881
+ if (win->feature & WIN_FEATURE_CLUSTER_SUB) {
4882
+ ret = vop2_cluster_two_win_mode_check(state);
4883
+ if (ret < 0)
4884
+ return ret;
4885
+ }
4886
+
4887
+ if (vop2_linear_yuv_format_check(plane, state))
4888
+ return -EINVAL;
4889
+
4890
+ if (fb->format->char_per_block[0] == 0)
4891
+ offset = ALIGN_DOWN(src->x1 >> 16, tile_size) * fb->format->cpp[0] * tile_size;
4892
+ else
4893
+ offset = drm_format_info_min_pitch(fb->format, 0, ALIGN_DOWN(src->x1 >> 16, tile_size)) * tile_size;
34374894 vpstate->offset = offset + fb->offsets[0];
34384895
34394896 /*
....@@ -3446,30 +4903,33 @@
34464903 else
34474904 offset += ALIGN_DOWN(src->y1 >> 16, tile_size) * fb->pitches[0];
34484905
3449
- dma_addr = rockchip_fb_get_dma_addr(fb, 0);
3450
- kvaddr = rockchip_fb_get_kvaddr(fb, 0);
4906
+ obj = fb->obj[0];
4907
+ rk_obj = to_rockchip_obj(obj);
34514908
3452
- vpstate->yrgb_mst = dma_addr + offset + fb->offsets[0];
3453
- vpstate->yrgb_kvaddr = kvaddr + offset + fb->offsets[0];
3454
- if (fb->format->is_yuv) {
3455
- int hsub = drm_format_horz_chroma_subsampling(fb->format->format);
3456
- int vsub = drm_format_vert_chroma_subsampling(fb->format->format);
4909
+ vpstate->yrgb_mst = rk_obj->dma_addr + offset + fb->offsets[0];
4910
+ if (fb->format->is_yuv && fb->format->num_planes > 1) {
4911
+ int hsub = fb->format->hsub;
4912
+ int vsub = fb->format->vsub;
34574913
3458
- offset = ALIGN_DOWN(src->x1 >> 16, tile_size) * fb->format->bpp[1] / hsub / 8 * tile_size;
4914
+ if (fb->format->char_per_block[0] == 0)
4915
+ offset = ALIGN_DOWN(src->x1 >> 16, tile_size) * fb->format->cpp[1] / hsub * tile_size;
4916
+ else
4917
+ offset = drm_format_info_min_pitch(fb->format, 1, ALIGN_DOWN(src->x1 >> 16, tile_size)) * tile_size / hsub;
4918
+
34594919 if (vpstate->tiled_en)
34604920 offset /= vsub;
34614921 offset += ALIGN_DOWN(src->y1 >> 16, tile_size) * fb->pitches[1] / vsub;
4922
+
4923
+ uv_obj = fb->obj[1];
4924
+ rk_uv_obj = to_rockchip_obj(uv_obj);
4925
+
34624926 if (vpstate->ymirror_en && !vpstate->afbc_en)
34634927 offset += fb->pitches[1] * ((state->src_h >> 16) - 2) / vsub;
3464
- dma_addr = rockchip_fb_get_dma_addr(fb, 1);
3465
- dma_addr += offset + fb->offsets[1];
4928
+ dma_addr = rk_uv_obj->dma_addr + offset + fb->offsets[1];
34664929 vpstate->uv_mst = dma_addr;
3467
-
34684930 /* tile 4x4 m0 format, y and uv is packed together */
3469
- if (vpstate->tiled_en == ROCKCHIP_TILED_BLOCK_SIZE_4x4_MODE0) {
4931
+ if (vpstate->tiled_en == ROCKCHIP_TILED_BLOCK_SIZE_4x4_MODE0)
34704932 vpstate->yrgb_mst += offset;
3471
- vpstate->yrgb_kvaddr += offset;
3472
- }
34734933 }
34744934
34754935 return 0;
....@@ -3479,19 +4939,30 @@
34794939 {
34804940 struct vop2_win *win = to_vop2_win(plane);
34814941 struct vop2 *vop2 = win->vop2;
4942
+ struct drm_crtc *crtc;
4943
+ struct vop2_video_port *vp;
4944
+
34824945 #if defined(CONFIG_ROCKCHIP_DRM_DEBUG)
34834946 struct vop2_plane_state *vpstate = to_vop2_plane_state(plane->state);
34844947 #endif
34854948
3486
- DRM_DEV_DEBUG(vop2->dev, "%s disable\n", win->name);
4949
+ rockchip_drm_dbg(vop2->dev, VOP_DEBUG_PLANE, "%s disable %s\n",
4950
+ win->name, current->comm);
34874951
34884952 if (!old_state->crtc)
34894953 return;
34904954
34914955 spin_lock(&vop2->reg_lock);
34924956
3493
- vop2_win_disable(win);
3494
- VOP_WIN_SET(vop2, win, yuv_clip, 0);
4957
+ crtc = old_state->crtc;
4958
+ vp = to_vop2_video_port(crtc);
4959
+
4960
+ vop2_win_disable(win, false);
4961
+ vp->enabled_win_mask &= ~BIT(win->phys_id);
4962
+ if (win->splice_win) {
4963
+ vop2_win_disable(win->splice_win, false);
4964
+ vp->enabled_win_mask &= ~BIT(win->splice_win->phys_id);
4965
+ }
34954966
34964967 #if defined(CONFIG_ROCKCHIP_DRM_DEBUG)
34974968 kfree(vpstate->planlist);
....@@ -3555,6 +5026,64 @@
35555026 VOP_WIN_SET(vop2, win, color_key, color_key);
35565027 }
35575028
5029
+static void vop2_calc_drm_rect_for_splice(struct vop2_plane_state *vpstate,
5030
+ struct drm_rect *left_src, struct drm_rect *left_dst,
5031
+ struct drm_rect *right_src, struct drm_rect *right_dst)
5032
+{
5033
+ struct drm_crtc *crtc = vpstate->base.crtc;
5034
+ struct drm_display_mode *mode = &crtc->state->adjusted_mode;
5035
+ struct drm_rect *dst = &vpstate->dest;
5036
+ struct drm_rect *src = &vpstate->src;
5037
+ u16 half_hdisplay = mode->crtc_hdisplay >> 1;
5038
+ int hscale = drm_rect_calc_hscale(src, dst, 0, INT_MAX);
5039
+ int dst_w = drm_rect_width(dst);
5040
+ int src_w = drm_rect_width(src) >> 16;
5041
+ int left_src_w, left_dst_w, right_dst_w;
5042
+ struct drm_plane_state *pstate = &vpstate->base;
5043
+ struct drm_framebuffer *fb = pstate->fb;
5044
+
5045
+ left_dst_w = min_t(u16, half_hdisplay, dst->x2) - dst->x1;
5046
+ if (left_dst_w < 0)
5047
+ left_dst_w = 0;
5048
+ right_dst_w = dst_w - left_dst_w;
5049
+
5050
+ if (!right_dst_w)
5051
+ left_src_w = src_w;
5052
+ else
5053
+ left_src_w = (left_dst_w * hscale) >> 16;
5054
+
5055
+ /*
5056
+ * Make sure the yrgb/uv mst of right win are byte aligned
5057
+ * with full pixel.
5058
+ */
5059
+ if (right_dst_w) {
5060
+ if (fb->format->format == DRM_FORMAT_NV15)
5061
+ left_src_w &= ~0x7;
5062
+ else if (fb->format->format == DRM_FORMAT_NV12)
5063
+ left_src_w &= ~0x1;
5064
+ }
5065
+ left_src->x1 = src->x1;
5066
+ left_src->x2 = src->x1 + (left_src_w << 16);
5067
+ left_dst->x1 = dst->x1;
5068
+ left_dst->x2 = dst->x1 + left_dst_w;
5069
+ right_src->x1 = left_src->x2;
5070
+ right_src->x2 = src->x2;
5071
+ right_dst->x1 = dst->x1 + left_dst_w - half_hdisplay;
5072
+ if (right_dst->x1 < 0)
5073
+ right_dst->x1 = 0;
5074
+
5075
+ right_dst->x2 = right_dst->x1 + right_dst_w;
5076
+
5077
+ left_src->y1 = src->y1;
5078
+ left_src->y2 = src->y2;
5079
+ left_dst->y1 = dst->y1;
5080
+ left_dst->y2 = dst->y2;
5081
+ right_src->y1 = src->y1;
5082
+ right_src->y2 = src->y2;
5083
+ right_dst->y1 = dst->y1;
5084
+ right_dst->y2 = dst->y2;
5085
+}
5086
+
35585087 static void rk3588_vop2_win_cfg_axi(struct vop2_win *win)
35595088 {
35605089 struct vop2 *vop2 = win->vop2;
....@@ -3589,18 +5118,17 @@
35895118 }
35905119 }
35915120
3592
-static void vop2_plane_atomic_update(struct drm_plane *plane, struct drm_plane_state *old_state)
5121
+static void vop2_win_atomic_update(struct vop2_win *win, struct drm_rect *src, struct drm_rect *dst,
5122
+ struct drm_plane_state *pstate)
35935123 {
3594
- struct drm_plane_state *pstate = plane->state;
35955124 struct drm_crtc *crtc = pstate->crtc;
3596
- struct vop2_win *win = to_vop2_win(plane);
35975125 struct vop2_video_port *vp = to_vop2_video_port(crtc);
35985126 struct vop2_plane_state *vpstate = to_vop2_plane_state(pstate);
35995127 struct drm_display_mode *adjusted_mode = &crtc->state->adjusted_mode;
3600
- struct rockchip_crtc_state *vcstate = to_rockchip_crtc_state(crtc->state);
36015128 struct vop2 *vop2 = win->vop2;
36025129 struct drm_framebuffer *fb = pstate->fb;
3603
- uint32_t bpp = fb->format->bpp[0];
5130
+ struct drm_rect *left_src = &vpstate->src;
5131
+ uint32_t bpp = rockchip_drm_get_bpp(fb->format);
36045132 uint32_t actual_w, actual_h, dsp_w, dsp_h;
36055133 uint32_t dsp_stx, dsp_sty;
36065134 uint32_t act_info, dsp_info, dsp_st;
....@@ -3608,30 +5136,294 @@
36085136 uint32_t afbc_format;
36095137 uint32_t rb_swap;
36105138 uint32_t uv_swap;
3611
- struct drm_rect *src = &vpstate->src;
3612
- struct drm_rect *dest = &vpstate->dest;
3613
- uint32_t afbc_tile_num;
36145139 uint32_t afbc_half_block_en;
5140
+ uint32_t afbc_tile_num;
36155141 uint32_t lb_mode;
36165142 uint32_t stride, uv_stride = 0;
36175143 uint32_t transform_offset;
5144
+ /* offset of the right window in splice mode */
5145
+ uint32_t splice_pixel_offset = 0;
5146
+ uint32_t splice_yrgb_offset = 0;
5147
+ uint32_t splice_uv_offset = 0;
5148
+ uint32_t afbc_xoffset;
5149
+ uint32_t hsub;
5150
+ dma_addr_t yrgb_mst;
5151
+ dma_addr_t uv_mst;
5152
+
36185153 struct drm_format_name_buf format_name;
36195154 bool dither_up;
36205155 bool tile_4x4_m0 = vpstate->tiled_en == ROCKCHIP_TILED_BLOCK_SIZE_4x4_MODE0 ? true : false;
36215156
5157
+ actual_w = drm_rect_width(src) >> 16;
5158
+ actual_h = drm_rect_height(src) >> 16;
5159
+
5160
+ if (!actual_w || !actual_h || !bpp) {
5161
+ vop2_win_disable(win, true);
5162
+ return;
5163
+ }
5164
+
5165
+ dsp_w = drm_rect_width(dst);
5166
+ /*
5167
+ * This win is for the right part of the plane,
5168
+ * we need calculate the fb offset for it.
5169
+ */
5170
+ if (win->splice_mode_right) {
5171
+ splice_pixel_offset = (src->x1 - left_src->x1) >> 16;
5172
+ splice_yrgb_offset = drm_format_info_min_pitch(fb->format, 0, splice_pixel_offset);
5173
+ if (fb->format->is_yuv && fb->format->num_planes > 1) {
5174
+ hsub = fb->format->hsub;
5175
+ splice_uv_offset = drm_format_info_min_pitch(fb->format, 1, splice_pixel_offset / hsub);
5176
+ }
5177
+ }
5178
+
5179
+ if (dst->x1 + dsp_w > adjusted_mode->crtc_hdisplay) {
5180
+ DRM_ERROR("vp%d %s dest->x1[%d] + dsp_w[%d] exceed mode hdisplay[%d]\n",
5181
+ vp->id, win->name, dst->x1, dsp_w, adjusted_mode->crtc_hdisplay);
5182
+ dsp_w = adjusted_mode->crtc_hdisplay - dst->x1;
5183
+ if (dsp_w < 4)
5184
+ dsp_w = 4;
5185
+ actual_w = dsp_w * actual_w / drm_rect_width(dst);
5186
+ }
5187
+ dsp_h = drm_rect_height(dst);
5188
+ check_size = adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE ? adjusted_mode->vdisplay : adjusted_mode->crtc_vdisplay;
5189
+ if (dst->y1 + dsp_h > check_size) {
5190
+ DRM_ERROR("vp%d %s dest->y1[%d] + dsp_h[%d] exceed mode vdisplay[%d]\n",
5191
+ vp->id, win->name, dst->y1, dsp_h, adjusted_mode->crtc_vdisplay);
5192
+ dsp_h = adjusted_mode->crtc_vdisplay - dst->y1;
5193
+ if (dsp_h < 4)
5194
+ dsp_h = 4;
5195
+ actual_h = dsp_h * actual_h / drm_rect_height(dst);
5196
+ }
5197
+
5198
+ /*
5199
+ * Workaround only for rk3568 vop
5200
+ */
5201
+ if (vop2->version == VOP_VERSION_RK3568) {
5202
+ /*
5203
+ * This is workaround solution for IC design:
5204
+ * esmart can't support scale down when actual_w % 16 == 1;
5205
+ * esmart can't support scale down when dsp_w % 2 == 1;
5206
+ * esmart actual_w should align as 4 pixel when is linear 10 bit yuv format;
5207
+ *
5208
+ * cluster actual_w should align as 4 pixel when enable afbc;
5209
+ */
5210
+ if (!vop2_cluster_window(win)) {
5211
+ if (actual_w > dsp_w && (actual_w & 0xf) == 1) {
5212
+ DRM_WARN("vp%d %s act_w[%d] MODE 16 == 1 at scale down mode\n", vp->id, win->name, actual_w);
5213
+ actual_w -= 1;
5214
+ }
5215
+ if (actual_w > dsp_w && (dsp_w & 0x1) == 1) {
5216
+ DRM_WARN("vp%d %s dsp_w[%d] MODE 2 == 1 at scale down mode\n", vp->id, win->name, dsp_w);
5217
+ dsp_w -= 1;
5218
+ }
5219
+ }
5220
+
5221
+ if (vop2_cluster_window(win) && actual_w % 4) {
5222
+ DRM_WARN("vp%d %s actual_w[%d] should align as 4 pixel when enable afbc\n",
5223
+ vp->id, win->name, actual_w);
5224
+ actual_w = ALIGN_DOWN(actual_w, 4);
5225
+ }
5226
+ }
5227
+
5228
+ if (is_linear_10bit_yuv(fb->format->format) && actual_w & 0x3) {
5229
+ DRM_WARN("vp%d %s actual_w[%d] should align as 4 pixel when is linear 10 bit yuv format\n", vp->id, win->name, actual_w);
5230
+ actual_w = ALIGN_DOWN(actual_w, 4);
5231
+ }
5232
+
5233
+ act_info = (actual_h - 1) << 16 | ((actual_w - 1) & 0xffff);
5234
+ dsp_info = (dsp_h - 1) << 16 | ((dsp_w - 1) & 0xffff);
5235
+ stride = DIV_ROUND_UP(fb->pitches[0], 4);
5236
+ dsp_stx = dst->x1;
5237
+ dsp_sty = dst->y1;
5238
+ dsp_st = dsp_sty << 16 | (dsp_stx & 0xffff);
5239
+
5240
+ if (vpstate->tiled_en) {
5241
+ if (is_vop3(vop2))
5242
+ format = vop3_convert_tiled_format(fb->format->format, vpstate->tiled_en);
5243
+ else
5244
+ format = vop2_convert_tiled_format(fb->format->format);
5245
+ } else {
5246
+ format = vop2_convert_format(fb->format->format);
5247
+ }
5248
+
5249
+ vop2_setup_csc_mode(vp, vpstate);
5250
+
5251
+ afbc_half_block_en = vop2_afbc_half_block_enable(vpstate);
5252
+
5253
+ vop2_win_enable(win);
5254
+ spin_lock(&vop2->reg_lock);
5255
+ rockchip_drm_dbg(vop2->dev, VOP_DEBUG_PLANE,
5256
+ "vp%d update %s[%dx%d->%dx%d@(%d, %d)] fmt[%.4s%s] addr[%pad] by %s\n",
5257
+ vp->id, win->name, actual_w, actual_h, dsp_w, dsp_h,
5258
+ dsp_stx, dsp_sty,
5259
+ drm_get_format_name(fb->format->format, &format_name),
5260
+ modifier_to_string(fb->modifier), &vpstate->yrgb_mst, current->comm);
5261
+
5262
+ if (vop2->version != VOP_VERSION_RK3568)
5263
+ rk3588_vop2_win_cfg_axi(win);
5264
+
5265
+ if (!win->parent && !vop2_cluster_window(win) && is_vop3(vop2))
5266
+ VOP_WIN_SET(vop2, win, scale_engine_num, win->scale_engine_num);
5267
+
5268
+ if (vpstate->afbc_en) {
5269
+ /* the afbc superblock is 16 x 16 */
5270
+ afbc_format = vop2_convert_afbc_format(fb->format->format);
5271
+ /* Enable color transform for YTR */
5272
+ if (fb->modifier & AFBC_FORMAT_MOD_YTR)
5273
+ afbc_format |= (1 << 4);
5274
+ afbc_tile_num = ALIGN(actual_w, 16) >> 4;
5275
+
5276
+ /* The right win should have a src offset in splice mode */
5277
+ afbc_xoffset = (src->x1 >> 16);
5278
+ /* AFBC pic_vir_width is count by pixel, this is different
5279
+ * with WIN_VIR_STRIDE.
5280
+ */
5281
+ stride = (fb->pitches[0] << 3) / bpp;
5282
+ if ((stride & 0x3f) &&
5283
+ (vpstate->xmirror_en || vpstate->rotate_90_en || vpstate->rotate_270_en))
5284
+ DRM_ERROR("vp%d %s stride[%d] must align as 64 pixel when enable xmirror/rotate_90/rotate_270[0x%x]\n",
5285
+ vp->id, win->name, stride, pstate->rotation);
5286
+
5287
+ rb_swap = vop2_afbc_rb_swap(fb->format->format);
5288
+ uv_swap = vop2_afbc_uv_swap(fb->format->format);
5289
+ vpstate->afbc_half_block_en = afbc_half_block_en;
5290
+
5291
+ transform_offset = vop2_afbc_transform_offset(vpstate, splice_pixel_offset);
5292
+ VOP_CLUSTER_SET(vop2, win, afbc_enable, 1);
5293
+ VOP_AFBC_SET(vop2, win, format, afbc_format);
5294
+ VOP_AFBC_SET(vop2, win, rb_swap, rb_swap);
5295
+ VOP_AFBC_SET(vop2, win, uv_swap, uv_swap);
5296
+
5297
+ if (vop2->version == VOP_VERSION_RK3568)
5298
+ VOP_AFBC_SET(vop2, win, auto_gating_en, 0);
5299
+ else
5300
+ VOP_AFBC_SET(vop2, win, auto_gating_en, 1);
5301
+ VOP_AFBC_SET(vop2, win, block_split_en, 0);
5302
+ VOP_AFBC_SET(vop2, win, hdr_ptr, vpstate->yrgb_mst);
5303
+ VOP_AFBC_SET(vop2, win, pic_size, act_info);
5304
+ VOP_AFBC_SET(vop2, win, transform_offset, transform_offset);
5305
+ VOP_AFBC_SET(vop2, win, pic_offset, (afbc_xoffset | src->y1));
5306
+ VOP_AFBC_SET(vop2, win, dsp_offset, (dst->x1 | (dst->y1 << 16)));
5307
+ VOP_AFBC_SET(vop2, win, pic_vir_width, stride);
5308
+ VOP_AFBC_SET(vop2, win, tile_num, afbc_tile_num);
5309
+ VOP_AFBC_SET(vop2, win, xmirror, vpstate->xmirror_en);
5310
+ VOP_AFBC_SET(vop2, win, ymirror, vpstate->ymirror_en);
5311
+ VOP_AFBC_SET(vop2, win, rotate_270, vpstate->rotate_270_en);
5312
+ VOP_AFBC_SET(vop2, win, rotate_90, vpstate->rotate_90_en);
5313
+ } else {
5314
+ VOP_CLUSTER_SET(vop2, win, afbc_enable, 0);
5315
+ transform_offset = vop2_tile_transform_offset(vpstate, vpstate->tiled_en);
5316
+ VOP_AFBC_SET(vop2, win, transform_offset, transform_offset);
5317
+ VOP_WIN_SET(vop2, win, ymirror, vpstate->ymirror_en);
5318
+ VOP_WIN_SET(vop2, win, xmirror, vpstate->xmirror_en);
5319
+ }
5320
+
5321
+ if (vpstate->rotate_90_en || vpstate->rotate_270_en) {
5322
+ act_info = swahw32(act_info);
5323
+ actual_w = drm_rect_height(src) >> 16;
5324
+ actual_h = drm_rect_width(src) >> 16;
5325
+ }
5326
+
5327
+ yrgb_mst = vpstate->yrgb_mst + splice_yrgb_offset;
5328
+ uv_mst = vpstate->uv_mst + splice_uv_offset;
5329
+ /* rk3588 should set half_blocK_en to 1 in line and tile mode */
5330
+ VOP_AFBC_SET(vop2, win, half_block_en, afbc_half_block_en);
5331
+
5332
+ VOP_WIN_SET(vop2, win, format, format);
5333
+ VOP_WIN_SET(vop2, win, yrgb_mst, yrgb_mst);
5334
+
5335
+ rb_swap = vop2_win_rb_swap(fb->format->format);
5336
+ uv_swap = vop2_win_uv_swap(fb->format->format);
5337
+ if (vpstate->tiled_en) {
5338
+ uv_swap = 1;
5339
+ if (vpstate->tiled_en == ROCKCHIP_TILED_BLOCK_SIZE_8x8)
5340
+ stride <<= 3;
5341
+ else
5342
+ stride <<= 2;
5343
+ }
5344
+ VOP_WIN_SET(vop2, win, rb_swap, rb_swap);
5345
+ VOP_WIN_SET(vop2, win, uv_swap, uv_swap);
5346
+
5347
+ if (fb->format->is_yuv) {
5348
+ uv_stride = DIV_ROUND_UP(fb->pitches[1], 4);
5349
+ if (vpstate->tiled_en) {
5350
+ int vsub = fb->format->vsub;
5351
+
5352
+ if (vpstate->tiled_en == ROCKCHIP_TILED_BLOCK_SIZE_8x8)
5353
+ uv_stride = uv_stride * 8 / vsub;
5354
+ else
5355
+ uv_stride = uv_stride * 4 / vsub;
5356
+ VOP_WIN_SET(vop2, win, tile_mode, tile_4x4_m0);
5357
+ }
5358
+
5359
+ VOP_WIN_SET(vop2, win, uv_vir, uv_stride);
5360
+ VOP_WIN_SET(vop2, win, uv_mst, uv_mst);
5361
+ }
5362
+
5363
+ /* tile 4x4 m0 format, y and uv is packed together */
5364
+ if (tile_4x4_m0)
5365
+ VOP_WIN_SET(vop2, win, yrgb_vir, stride + uv_stride);
5366
+ else
5367
+ VOP_WIN_SET(vop2, win, yrgb_vir, stride);
5368
+
5369
+ vop2_setup_scale(vop2, win, actual_w, actual_h, dsp_w, dsp_h, pstate);
5370
+ vop2_plane_setup_color_key(&win->base);
5371
+ VOP_WIN_SET(vop2, win, act_info, act_info);
5372
+ VOP_WIN_SET(vop2, win, dsp_info, dsp_info);
5373
+ VOP_WIN_SET(vop2, win, dsp_st, dsp_st);
5374
+
5375
+ VOP_WIN_SET(vop2, win, y2r_en, vpstate->y2r_en);
5376
+ VOP_WIN_SET(vop2, win, r2y_en, vpstate->r2y_en);
5377
+ VOP_WIN_SET(vop2, win, csc_mode, vpstate->csc_mode);
5378
+
5379
+ if (win->feature & WIN_FEATURE_Y2R_13BIT_DEPTH && !vop2_cluster_window(win))
5380
+ VOP_WIN_SET(vop2, win, csc_13bit_en, !!(vpstate->csc_mode & CSC_BT709L_13BIT));
5381
+
5382
+ dither_up = vop2_win_dither_up(fb->format->format);
5383
+ VOP_WIN_SET(vop2, win, dither_up, dither_up);
5384
+
5385
+ VOP_WIN_SET(vop2, win, enable, 1);
5386
+ vp->enabled_win_mask |= BIT(win->phys_id);
5387
+ if (vop2_cluster_window(win)) {
5388
+ lb_mode = vop2_get_cluster_lb_mode(win, vpstate);
5389
+ VOP_CLUSTER_SET(vop2, win, lb_mode, lb_mode);
5390
+ VOP_CLUSTER_SET(vop2, win, scl_lb_mode, lb_mode == 1 ? 3 : 0);
5391
+ VOP_CLUSTER_SET(vop2, win, enable, 1);
5392
+ VOP_CLUSTER_SET(vop2, win, frm_reset_en, 1);
5393
+ }
5394
+ spin_unlock(&vop2->reg_lock);
5395
+}
5396
+
5397
+static void vop2_plane_atomic_update(struct drm_plane *plane, struct drm_plane_state *old_state)
5398
+{
5399
+ struct drm_plane_state *pstate = plane->state;
5400
+ struct drm_crtc *crtc = pstate->crtc;
5401
+ struct vop2_win *win = to_vop2_win(plane);
5402
+ struct vop2_win *splice_win;
5403
+ struct vop2_video_port *vp = to_vop2_video_port(crtc);
5404
+ struct vop2_plane_state *vpstate = to_vop2_plane_state(pstate);
5405
+ struct rockchip_crtc_state *vcstate = to_rockchip_crtc_state(crtc->state);
5406
+ struct drm_framebuffer *fb = pstate->fb;
5407
+ struct drm_format_name_buf format_name;
5408
+ struct vop2 *vop2 = win->vop2;
5409
+ struct drm_rect wsrc;
5410
+ struct drm_rect wdst;
5411
+ /* right part in splice mode */
5412
+ struct drm_rect right_wsrc;
5413
+ struct drm_rect right_wdst;
5414
+
36225415 #if defined(CONFIG_ROCKCHIP_DRM_DEBUG)
5416
+ struct drm_rect *psrc = &vpstate->src;
36235417 bool AFBC_flag = false;
36245418 struct vop_dump_list *planlist;
36255419 unsigned long num_pages;
36265420 struct page **pages;
3627
- struct rockchip_drm_fb *rk_fb;
36285421 struct drm_gem_object *obj;
36295422 struct rockchip_gem_object *rk_obj;
36305423
36315424 num_pages = 0;
36325425 pages = NULL;
3633
- rk_fb = to_rockchip_fb(fb);
3634
- obj = rk_fb->obj[0];
5426
+ obj = fb->obj[0];
36355427 rk_obj = to_rockchip_obj(obj);
36365428 if (rk_obj) {
36375429 num_pages = rk_obj->num_pages;
....@@ -3670,219 +5462,24 @@
36705462 vp->skip_vsync = false;
36715463 }
36725464
3673
- actual_w = drm_rect_width(src) >> 16;
3674
- actual_h = drm_rect_height(src) >> 16;
3675
- dsp_w = drm_rect_width(dest);
3676
- if (dest->x1 + dsp_w > adjusted_mode->crtc_hdisplay) {
3677
- DRM_ERROR("vp%d %s dest->x1[%d] + dsp_w[%d] exceed mode hdisplay[%d]\n",
3678
- vp->id, win->name, dest->x1, dsp_w, adjusted_mode->crtc_hdisplay);
3679
- dsp_w = adjusted_mode->hdisplay - dest->x1;
3680
- if (dsp_w < 4)
3681
- dsp_w = 4;
3682
- actual_w = dsp_w * actual_w / drm_rect_width(dest);
3683
- }
3684
- dsp_h = drm_rect_height(dest);
3685
- check_size = adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE ? adjusted_mode->vdisplay : adjusted_mode->crtc_vdisplay;
3686
- if (dest->y1 + dsp_h > check_size) {
3687
- DRM_ERROR("vp%d %s dest->y1[%d] + dsp_h[%d] exceed mode vdisplay[%d]\n",
3688
- vp->id, win->name, dest->y1, dsp_h, adjusted_mode->crtc_vdisplay);
3689
- dsp_h = adjusted_mode->vdisplay - dest->y1;
3690
- if (dsp_h < 4)
3691
- dsp_h = 4;
3692
- actual_h = dsp_h * actual_h / drm_rect_height(dest);
3693
- }
5465
+ if (vcstate->splice_mode) {
5466
+ DRM_DEV_DEBUG(vop2->dev, "vp%d update %s[%dx%d->%dx%d@(%d,%d)] fmt[%.4s%s] addr[%pad]\n",
5467
+ vp->id, win->name, drm_rect_width(&vpstate->src) >> 16,
5468
+ drm_rect_height(&vpstate->src) >> 16,
5469
+ drm_rect_width(&vpstate->dest), drm_rect_height(&vpstate->dest),
5470
+ vpstate->dest.x1, vpstate->dest.y1,
5471
+ drm_get_format_name(fb->format->format, &format_name),
5472
+ modifier_to_string(fb->modifier), &vpstate->yrgb_mst);
36945473
3695
- /*
3696
- * Workaround only for rk3568 vop
3697
- */
3698
- if (vop2->version == VOP_VERSION_RK3568) {
3699
- /*
3700
- * This is workaround solution for IC design:
3701
- * esmart can't support scale down when actual_w % 16 == 1.
3702
- */
3703
- if (!(win->feature & WIN_FEATURE_AFBDC)) {
3704
- if (actual_w > dsp_w && (actual_w & 0xf) == 1) {
3705
- DRM_WARN("vp%d %s act_w[%d] MODE 16 == 1\n", vp->id, win->name, actual_w);
3706
- actual_w -= 1;
3707
- }
3708
- }
3709
-
3710
- if (vpstate->afbc_en && actual_w % 4) {
3711
- DRM_ERROR("vp%d %s actual_w[%d] should align as 4 pixel when enable afbc\n",
3712
- vp->id, win->name, actual_w);
3713
- actual_w = ALIGN_DOWN(actual_w, 4);
3714
- }
3715
- }
3716
-
3717
- act_info = (actual_h - 1) << 16 | ((actual_w - 1) & 0xffff);
3718
- dsp_info = (dsp_h - 1) << 16 | ((dsp_w - 1) & 0xffff);
3719
- stride = DIV_ROUND_UP(fb->pitches[0], 4);
3720
- dsp_stx = dest->x1;
3721
- dsp_sty = dest->y1;
3722
- dsp_st = dsp_sty << 16 | (dsp_stx & 0xffff);
3723
-
3724
- if (vpstate->tiled_en) {
3725
- if (is_vop3(vop2))
3726
- format = vop3_convert_tiled_format(fb->format->format, vpstate->tiled_en);
3727
- else
3728
- format = vop2_convert_tiled_format(fb->format->format);
5474
+ vop2_calc_drm_rect_for_splice(vpstate, &wsrc, &wdst, &right_wsrc, &right_wdst);
5475
+ splice_win = win->splice_win;
5476
+ vop2_win_atomic_update(splice_win, &right_wsrc, &right_wdst, pstate);
37295477 } else {
3730
- format = vop2_convert_format(fb->format->format);
5478
+ memcpy(&wsrc, &vpstate->src, sizeof(struct drm_rect));
5479
+ memcpy(&wdst, &vpstate->dest, sizeof(struct drm_rect));
37315480 }
37325481
3733
- vop2_setup_csc_mode(vp, vpstate);
3734
- afbc_half_block_en = vop2_afbc_half_block_enable(vpstate);
3735
-
3736
- spin_lock(&vop2->reg_lock);
3737
- DRM_DEV_DEBUG(vop2->dev, "vp%d update %s[%dx%d->%dx%d@%dx%d] fmt[%.4s%s] addr[%pad] zpos[%d]\n",
3738
- vp->id, win->name, actual_w, actual_h, dsp_w, dsp_h,
3739
- dsp_stx, dsp_sty,
3740
- drm_get_format_name(fb->format->format, &format_name),
3741
- modifier_to_string(fb->modifier), &vpstate->yrgb_mst, vpstate->zpos);
3742
-
3743
- if (vop2->version != VOP_VERSION_RK3568)
3744
- rk3588_vop2_win_cfg_axi(win);
3745
-
3746
- if (is_vop3(vop2) && !vop2_cluster_window(win) && !win->parent)
3747
- VOP_WIN_SET(vop2, win, scale_engine_num, win->scale_engine_num);
3748
-
3749
- if (vpstate->afbc_en) {
3750
- /* the afbc superblock is 16 x 16 */
3751
- afbc_format = vop2_convert_afbc_format(fb->format->format);
3752
- /* Enable color transform for YTR */
3753
- if (fb->modifier & AFBC_FORMAT_MOD_YTR)
3754
- afbc_format |= (1 << 4);
3755
- afbc_tile_num = ALIGN(actual_w, 16) >> 4;
3756
- /* AFBC pic_vir_width is count by pixel, this is different
3757
- * with WIN_VIR_STRIDE.
3758
- */
3759
- if (!bpp) {
3760
- WARN(1, "bpp is zero\n");
3761
- bpp = 1;
3762
- }
3763
- stride = (fb->pitches[0] << 3) / bpp;
3764
- if ((stride & 0x3f) &&
3765
- (vpstate->xmirror_en || vpstate->rotate_90_en || vpstate->rotate_270_en))
3766
- DRM_ERROR("vp%d %s stride[%d] must align as 64 pixel when enable xmirror/rotate_90/rotate_270[0x%x]\n",
3767
- vp->id, win->name, stride, pstate->rotation);
3768
-
3769
- rb_swap = vop2_afbc_rb_swap(fb->format->format);
3770
- uv_swap = vop2_afbc_uv_swap(fb->format->format);
3771
- /*
3772
- * This is a workaround for crazy IC design, Cluster
3773
- * and Esmart/Smart use different format configuration map:
3774
- * YUV420_10BIT: 0x10 for Cluster, 0x14 for Esmart/Smart.
3775
- *
3776
- * This is one thing we can make the convert simple:
3777
- * AFBCD decode all the YUV data to YUV444. So we just
3778
- * set all the yuv 10 bit to YUV444_10.
3779
- */
3780
- if (fb->format->is_yuv && (bpp == 10) && (vop2->version == VOP_VERSION_RK3568))
3781
- format = VOP2_CLUSTER_YUV444_10;
3782
-
3783
- vpstate->afbc_half_block_en = afbc_half_block_en;
3784
- transform_offset = vop2_afbc_transform_offset(vpstate);
3785
- VOP_CLUSTER_SET(vop2, win, afbc_enable, 1);
3786
- VOP_AFBC_SET(vop2, win, format, afbc_format);
3787
- VOP_AFBC_SET(vop2, win, rb_swap, rb_swap);
3788
- VOP_AFBC_SET(vop2, win, uv_swap, uv_swap);
3789
- if (vop2->version == VOP_VERSION_RK3568)
3790
- VOP_AFBC_SET(vop2, win, auto_gating_en, 0);
3791
- else
3792
- VOP_AFBC_SET(vop2, win, auto_gating_en, 1);
3793
- VOP_AFBC_SET(vop2, win, block_split_en, 0);
3794
- VOP_AFBC_SET(vop2, win, hdr_ptr, vpstate->yrgb_mst);
3795
- VOP_AFBC_SET(vop2, win, pic_size, act_info);
3796
- VOP_AFBC_SET(vop2, win, transform_offset, transform_offset);
3797
- VOP_AFBC_SET(vop2, win, pic_offset, ((src->x1 >> 16) | src->y1));
3798
- VOP_AFBC_SET(vop2, win, dsp_offset, (dest->x1 | (dest->y1 << 16)));
3799
- VOP_AFBC_SET(vop2, win, pic_vir_width, stride);
3800
- VOP_AFBC_SET(vop2, win, tile_num, afbc_tile_num);
3801
- VOP_AFBC_SET(vop2, win, xmirror, vpstate->xmirror_en);
3802
- VOP_AFBC_SET(vop2, win, ymirror, vpstate->ymirror_en);
3803
- VOP_AFBC_SET(vop2, win, rotate_270, vpstate->rotate_270_en);
3804
- VOP_AFBC_SET(vop2, win, rotate_90, vpstate->rotate_90_en);
3805
- } else {
3806
- VOP_AFBC_SET(vop2, win, enable, 0);
3807
- VOP_CLUSTER_SET(vop2, win, afbc_enable, 0);
3808
- transform_offset = vop2_tile_transform_offset(vpstate, vpstate->tiled_en);
3809
- VOP_AFBC_SET(vop2, win, transform_offset, transform_offset);
3810
- VOP_WIN_SET(vop2, win, ymirror, vpstate->ymirror_en);
3811
- VOP_WIN_SET(vop2, win, xmirror, vpstate->xmirror_en);
3812
- }
3813
-
3814
- if (vpstate->rotate_90_en || vpstate->rotate_270_en) {
3815
- act_info = swahw32(act_info);
3816
- actual_w = drm_rect_height(src) >> 16;
3817
- actual_h = drm_rect_width(src) >> 16;
3818
- }
3819
- VOP_AFBC_SET(vop2, win, half_block_en, afbc_half_block_en);
3820
-
3821
- VOP_WIN_SET(vop2, win, format, format);
3822
- VOP_WIN_SET(vop2, win, yrgb_mst, vpstate->yrgb_mst);
3823
-
3824
- rb_swap = vop2_win_rb_swap(fb->format->format);
3825
- uv_swap = vop2_win_uv_swap(fb->format->format);
3826
- if (vpstate->tiled_en) {
3827
- uv_swap = 1;
3828
- if (vpstate->tiled_en == ROCKCHIP_TILED_BLOCK_SIZE_8x8)
3829
- stride <<= 3;
3830
- else
3831
- stride <<= 2;
3832
- }
3833
- VOP_WIN_SET(vop2, win, rb_swap, rb_swap);
3834
- VOP_WIN_SET(vop2, win, uv_swap, uv_swap);
3835
-
3836
- if (fb->format->is_yuv) {
3837
- uv_stride = DIV_ROUND_UP(fb->pitches[1], 4);
3838
- if (vpstate->tiled_en) {
3839
- int vsub = drm_format_vert_chroma_subsampling(fb->format->format);
3840
-
3841
- if (vpstate->tiled_en == ROCKCHIP_TILED_BLOCK_SIZE_8x8)
3842
- uv_stride = uv_stride * 8 / vsub;
3843
- else
3844
- uv_stride = uv_stride * 4 / vsub;
3845
- VOP_WIN_SET(vop2, win, tile_mode, tile_4x4_m0);
3846
- }
3847
-
3848
- VOP_WIN_SET(vop2, win, uv_vir, uv_stride);
3849
- VOP_WIN_SET(vop2, win, uv_mst, vpstate->uv_mst);
3850
- }
3851
-
3852
- /* tile 4x4 m0 format, y and uv is packed together */
3853
- if (tile_4x4_m0)
3854
- VOP_WIN_SET(vop2, win, yrgb_vir, stride + uv_stride);
3855
- else
3856
- VOP_WIN_SET(vop2, win, yrgb_vir, stride);
3857
-
3858
- vop2_setup_scale(vop2, win, actual_w, actual_h, dsp_w, dsp_h, pstate);
3859
- vop2_plane_setup_color_key(plane);
3860
- VOP_WIN_SET(vop2, win, act_info, act_info);
3861
- VOP_WIN_SET(vop2, win, dsp_info, dsp_info);
3862
- VOP_WIN_SET(vop2, win, dsp_st, dsp_st);
3863
-
3864
- VOP_WIN_SET(vop2, win, y2r_en, vpstate->y2r_en);
3865
- VOP_WIN_SET(vop2, win, r2y_en, vpstate->r2y_en);
3866
- VOP_WIN_SET(vop2, win, csc_mode, vpstate->csc_mode);
3867
-
3868
- if (win->feature & WIN_FEATURE_Y2R_13BIT_DEPTH && !vop2_cluster_window(win))
3869
- VOP_WIN_SET(vop2, win, csc_13bit_en, !!(vpstate->csc_mode & CSC_BT709L_13BIT));
3870
-
3871
- dither_up = vop2_win_dither_up(fb->format->format);
3872
- VOP_WIN_SET(vop2, win, dither_up, dither_up);
3873
-
3874
- VOP_WIN_SET(vop2, win, enable, 1);
3875
- if (vop2_cluster_window(win)) {
3876
- lb_mode = vop2_get_cluster_lb_mode(win, vpstate);
3877
- VOP_CLUSTER_SET(vop2, win, lb_mode, lb_mode);
3878
- VOP_CLUSTER_SET(vop2, win, scl_lb_mode, lb_mode == 1 ? 3 : 0);
3879
- VOP_CLUSTER_SET(vop2, win, enable, 1);
3880
- VOP_CLUSTER_SET(vop2, win, frm_reset_en, 1);
3881
- }
3882
- if (vcstate->output_if & VOP_OUTPUT_IF_BT1120 ||
3883
- vcstate->output_if & VOP_OUTPUT_IF_BT656)
3884
- VOP_WIN_SET(vop2, win, yuv_clip, 1);
3885
- spin_unlock(&vop2->reg_lock);
5482
+ vop2_win_atomic_update(win, &wsrc, &wdst, pstate);
38865483
38875484 vop2->is_iommu_needed = true;
38885485 #if defined(CONFIG_ROCKCHIP_DRM_DEBUG)
....@@ -3899,18 +5496,18 @@
38995496 planlist->dump_info.pages = pages;
39005497 planlist->dump_info.offset = vpstate->offset;
39015498 planlist->dump_info.pitches = fb->pitches[0];
3902
- planlist->dump_info.height = actual_h;
3903
- planlist->dump_info.pixel_format = fb->format->format;
3904
- list_add_tail(&planlist->entry, &crtc->vop_dump_list_head);
5499
+ planlist->dump_info.height = drm_rect_height(psrc) >> 16;
5500
+ planlist->dump_info.format = fb->format;
5501
+ list_add_tail(&planlist->entry, &vp->rockchip_crtc.vop_dump_list_head);
39055502 vpstate->planlist = planlist;
39065503 } else {
39075504 DRM_ERROR("can't alloc a node of planlist %p\n", planlist);
39085505 return;
39095506 }
3910
- if (crtc->vop_dump_status == DUMP_KEEP ||
3911
- crtc->vop_dump_times > 0) {
3912
- vop_plane_dump(&planlist->dump_info, crtc->frame_count);
3913
- crtc->vop_dump_times--;
5507
+ if (vp->rockchip_crtc.vop_dump_status == DUMP_KEEP ||
5508
+ vp->rockchip_crtc.vop_dump_times > 0) {
5509
+ rockchip_drm_dump_plane_buffer(&planlist->dump_info, vp->rockchip_crtc.frame_count);
5510
+ vp->rockchip_crtc.vop_dump_times--;
39145511 }
39155512 #endif
39165513 }
....@@ -4056,11 +5653,8 @@
40565653 if (!vpstate)
40575654 return;
40585655
4059
- plane->state = &vpstate->base;
4060
- plane->state->plane = plane;
4061
- plane->state->zpos = win->zpos;
4062
- plane->state->alpha = DRM_BLEND_ALPHA_OPAQUE;
4063
- plane->state->rotation = DRM_MODE_ROTATE_0;
5656
+ __drm_atomic_helper_plane_reset(plane, &vpstate->base);
5657
+ vpstate->base.zpos = win->zpos;
40645658 }
40655659
40665660 static struct drm_plane_state *vop2_atomic_plane_duplicate_state(struct drm_plane *plane)
....@@ -4248,6 +5842,192 @@
42485842 spin_unlock_irqrestore(&drm->event_lock, flags);
42495843 }
42505844
5845
+static bool vop2_crtc_line_flag_irq_is_enabled(struct vop2_video_port *vp)
5846
+{
5847
+ struct vop2 *vop2 = vp->vop2;
5848
+ const struct vop2_data *vop2_data = vop2->data;
5849
+ const struct vop2_video_port_data *vp_data = &vop2_data->vp[vp->id];
5850
+ const struct vop_intr *intr = vp_data->intr;
5851
+ uint32_t line_flag_irq;
5852
+ unsigned long flags;
5853
+
5854
+ spin_lock_irqsave(&vop2->irq_lock, flags);
5855
+ line_flag_irq = VOP_INTR_GET_TYPE(vop2, intr, enable, LINE_FLAG_INTR);
5856
+ spin_unlock_irqrestore(&vop2->irq_lock, flags);
5857
+
5858
+ return !!line_flag_irq;
5859
+}
5860
+
5861
+static void vop2_crtc_line_flag_irq_enable(struct vop2_video_port *vp)
5862
+{
5863
+ struct vop2 *vop2 = vp->vop2;
5864
+ const struct vop2_data *vop2_data = vop2->data;
5865
+ const struct vop2_video_port_data *vp_data = &vop2_data->vp[vp->id];
5866
+ const struct vop_intr *intr = vp_data->intr;
5867
+ unsigned long flags;
5868
+
5869
+ if (!vop2->is_enabled)
5870
+ return;
5871
+
5872
+ spin_lock_irqsave(&vop2->irq_lock, flags);
5873
+ VOP_INTR_SET_TYPE(vop2, intr, clear, LINE_FLAG_INTR, 1);
5874
+ VOP_INTR_SET_TYPE(vop2, intr, enable, LINE_FLAG_INTR, 1);
5875
+ spin_unlock_irqrestore(&vop2->irq_lock, flags);
5876
+}
5877
+
5878
+static void vop2_crtc_line_flag_irq_disable(struct vop2_video_port *vp)
5879
+{
5880
+ struct vop2 *vop2 = vp->vop2;
5881
+ const struct vop2_data *vop2_data = vop2->data;
5882
+ const struct vop2_video_port_data *vp_data = &vop2_data->vp[vp->id];
5883
+ const struct vop_intr *intr = vp_data->intr;
5884
+ unsigned long flags;
5885
+
5886
+ if (!vop2->is_enabled)
5887
+ return;
5888
+
5889
+ spin_lock_irqsave(&vop2->irq_lock, flags);
5890
+ VOP_INTR_SET_TYPE(vop2, intr, enable, LINE_FLAG_INTR, 0);
5891
+ spin_unlock_irqrestore(&vop2->irq_lock, flags);
5892
+}
5893
+
5894
+static void vop3_mcu_mode_setup(struct drm_crtc *crtc)
5895
+{
5896
+ struct vop2_video_port *vp = to_vop2_video_port(crtc);
5897
+ struct vop2 *vop2 = vp->vop2;
5898
+
5899
+ VOP_MODULE_SET(vop2, vp, mcu_type, 1);
5900
+ VOP_MODULE_SET(vop2, vp, mcu_hold_mode, 1);
5901
+ VOP_MODULE_SET(vop2, vp, mcu_pix_total, vp->mcu_timing.mcu_pix_total);
5902
+ VOP_MODULE_SET(vop2, vp, mcu_cs_pst, vp->mcu_timing.mcu_cs_pst);
5903
+ VOP_MODULE_SET(vop2, vp, mcu_cs_pend, vp->mcu_timing.mcu_cs_pend);
5904
+ VOP_MODULE_SET(vop2, vp, mcu_rw_pst, vp->mcu_timing.mcu_rw_pst);
5905
+ VOP_MODULE_SET(vop2, vp, mcu_rw_pend, vp->mcu_timing.mcu_rw_pend);
5906
+}
5907
+
5908
+static void vop3_mcu_bypass_mode_setup(struct drm_crtc *crtc)
5909
+{
5910
+ struct vop2_video_port *vp = to_vop2_video_port(crtc);
5911
+ struct vop2 *vop2 = vp->vop2;
5912
+
5913
+ VOP_MODULE_SET(vop2, vp, mcu_type, 1);
5914
+ VOP_MODULE_SET(vop2, vp, mcu_hold_mode, 1);
5915
+ VOP_MODULE_SET(vop2, vp, mcu_pix_total, 53);
5916
+ VOP_MODULE_SET(vop2, vp, mcu_cs_pst, 6);
5917
+ VOP_MODULE_SET(vop2, vp, mcu_cs_pend, 48);
5918
+ VOP_MODULE_SET(vop2, vp, mcu_rw_pst, 12);
5919
+ VOP_MODULE_SET(vop2, vp, mcu_rw_pend, 30);
5920
+}
5921
+
5922
+static u32 vop3_mode_done(struct vop2_video_port *vp)
5923
+{
5924
+ return VOP_MODULE_GET(vp->vop2, vp, out_mode);
5925
+}
5926
+
5927
+static void vop3_set_out_mode(struct drm_crtc *crtc, u32 out_mode)
5928
+{
5929
+ struct vop2_video_port *vp = to_vop2_video_port(crtc);
5930
+ struct vop2 *vop2 = vp->vop2;
5931
+ int ret;
5932
+ u32 val;
5933
+
5934
+ VOP_MODULE_SET(vop2, vp, out_mode, out_mode);
5935
+ vop2_cfg_done(crtc);
5936
+ ret = readx_poll_timeout(vop3_mode_done, vp, val, val == out_mode,
5937
+ 1000, 500 * 1000);
5938
+ if (ret)
5939
+ dev_err(vop2->dev, "wait mode 0x%x timeout\n", out_mode);
5940
+}
5941
+
5942
+static void vop3_crtc_send_mcu_cmd(struct drm_crtc *crtc, u32 type, u32 value)
5943
+{
5944
+ struct drm_crtc_state *crtc_state;
5945
+ struct drm_display_mode *adjusted_mode;
5946
+ struct vop2_video_port *vp;
5947
+ struct vop2 *vop2;
5948
+
5949
+ if (!crtc)
5950
+ return;
5951
+
5952
+ crtc_state = crtc->state;
5953
+ adjusted_mode = &crtc_state->adjusted_mode;
5954
+ vp = to_vop2_video_port(crtc);
5955
+ vop2 = vp->vop2;
5956
+
5957
+ /*
5958
+ * 1.set mcu bypass mode timing.
5959
+ * 2.set dclk rate to 150M.
5960
+ */
5961
+ if ((type == MCU_SETBYPASS) && value) {
5962
+ vop3_mcu_bypass_mode_setup(crtc);
5963
+ clk_set_rate(vp->dclk, 150000000);
5964
+ }
5965
+
5966
+ mutex_lock(&vop2->vop2_lock);
5967
+ if (vop2 && vop2->is_enabled) {
5968
+ switch (type) {
5969
+ case MCU_WRCMD:
5970
+ VOP_MODULE_SET(vop2, vp, mcu_rs, 0);
5971
+ VOP_MODULE_SET(vop2, vp, mcu_rw_bypass_port, value);
5972
+ VOP_MODULE_SET(vop2, vp, mcu_rs, 1);
5973
+ break;
5974
+ case MCU_WRDATA:
5975
+ VOP_MODULE_SET(vop2, vp, mcu_rs, 1);
5976
+ VOP_MODULE_SET(vop2, vp, mcu_rw_bypass_port, value);
5977
+ break;
5978
+ case MCU_SETBYPASS:
5979
+ VOP_MODULE_SET(vop2, vp, mcu_bypass, value ? 1 : 0);
5980
+ break;
5981
+ default:
5982
+ break;
5983
+ }
5984
+ }
5985
+ mutex_unlock(&vop2->vop2_lock);
5986
+
5987
+ /*
5988
+ * 1.restore mcu data mode timing.
5989
+ * 2.restore dclk rate to crtc_clock.
5990
+ */
5991
+ if ((type == MCU_SETBYPASS) && !value) {
5992
+ vop3_mcu_mode_setup(crtc);
5993
+ clk_set_rate(vp->dclk, adjusted_mode->crtc_clock * 1000);
5994
+ }
5995
+}
5996
+
5997
+static int vop2_crtc_wait_vact_end(struct drm_crtc *crtc, unsigned int mstimeout)
5998
+{
5999
+ struct vop2_video_port *vp = to_vop2_video_port(crtc);
6000
+ struct vop2 *vop2 = vp->vop2;
6001
+ unsigned long jiffies_left;
6002
+ int ret = 0;
6003
+
6004
+ if (!vop2->is_enabled)
6005
+ return -ENODEV;
6006
+
6007
+ mutex_lock(&vop2->vop2_lock);
6008
+
6009
+ if (vop2_crtc_line_flag_irq_is_enabled(vp)) {
6010
+ ret = -EBUSY;
6011
+ goto out;
6012
+ }
6013
+
6014
+ reinit_completion(&vp->line_flag_completion);
6015
+ vop2_crtc_line_flag_irq_enable(vp);
6016
+ jiffies_left = wait_for_completion_timeout(&vp->line_flag_completion,
6017
+ msecs_to_jiffies(mstimeout));
6018
+ vop2_crtc_line_flag_irq_disable(vp);
6019
+
6020
+ if (jiffies_left == 0) {
6021
+ DRM_DEV_ERROR(vop2->dev, "timeout waiting for lineflag IRQ\n");
6022
+ ret = -ETIMEDOUT;
6023
+ goto out;
6024
+ }
6025
+
6026
+out:
6027
+ mutex_unlock(&vop2->vop2_lock);
6028
+ return ret;
6029
+}
6030
+
42516031 static int vop2_crtc_enable_line_flag_event(struct drm_crtc *crtc, uint32_t line)
42526032 {
42536033 struct vop2_video_port *vp = to_vop2_video_port(crtc);
....@@ -4291,21 +6071,150 @@
42916071 spin_unlock_irqrestore(&vop2->irq_lock, flags);
42926072 }
42936073
4294
-
4295
-static int vop2_crtc_loader_protect(struct drm_crtc *crtc, bool on)
6074
+static int vop2_crtc_get_inital_acm_info(struct drm_crtc *crtc)
42966075 {
42976076 struct vop2_video_port *vp = to_vop2_video_port(crtc);
42986077 struct vop2 *vop2 = vp->vop2;
6078
+ struct post_acm *acm = &vp->acm_info;
6079
+ s16 *lut_y;
6080
+ s16 *lut_h;
6081
+ s16 *lut_s;
6082
+ u32 value;
6083
+ int i;
6084
+
6085
+ value = readl(vop2->acm_regs + RK3528_ACM_CTRL);
6086
+ acm->acm_enable = value & 0x1;
6087
+ value = readl(vop2->acm_regs + RK3528_ACM_DELTA_RANGE);
6088
+ acm->y_gain = value & 0x3ff;
6089
+ acm->h_gain = (value >> 10) & 0x3ff;
6090
+ acm->s_gain = (value >> 20) & 0x3ff;
6091
+
6092
+ lut_y = &acm->gain_lut_hy[0];
6093
+ lut_h = &acm->gain_lut_hy[ACM_GAIN_LUT_HY_LENGTH];
6094
+ lut_s = &acm->gain_lut_hy[ACM_GAIN_LUT_HY_LENGTH * 2];
6095
+ for (i = 0; i < ACM_GAIN_LUT_HY_LENGTH; i++) {
6096
+ value = readl(vop2->acm_regs + RK3528_ACM_YHS_DEL_HY_SEG0 + (i << 2));
6097
+ lut_y[i] = value & 0xff;
6098
+ lut_h[i] = (value >> 8) & 0xff;
6099
+ lut_s[i] = (value >> 16) & 0xff;
6100
+ }
6101
+
6102
+ lut_y = &acm->gain_lut_hs[0];
6103
+ lut_h = &acm->gain_lut_hs[ACM_GAIN_LUT_HS_LENGTH];
6104
+ lut_s = &acm->gain_lut_hs[ACM_GAIN_LUT_HS_LENGTH * 2];
6105
+ for (i = 0; i < ACM_GAIN_LUT_HS_LENGTH; i++) {
6106
+ value = readl(vop2->acm_regs + RK3528_ACM_YHS_DEL_HS_SEG0 + (i << 2));
6107
+ lut_y[i] = value & 0xff;
6108
+ lut_h[i] = (value >> 8) & 0xff;
6109
+ lut_s[i] = (value >> 16) & 0xff;
6110
+ }
6111
+
6112
+ lut_y = &acm->delta_lut_h[0];
6113
+ lut_h = &acm->delta_lut_h[ACM_DELTA_LUT_H_LENGTH];
6114
+ lut_s = &acm->delta_lut_h[ACM_DELTA_LUT_H_LENGTH * 2];
6115
+ for (i = 0; i < ACM_DELTA_LUT_H_LENGTH; i++) {
6116
+ value = readl(vop2->acm_regs + RK3528_ACM_YHS_DEL_HGAIN_SEG0 + (i << 2));
6117
+ lut_y[i] = value & 0x3ff;
6118
+ lut_h[i] = (value >> 12) & 0xff;
6119
+ lut_s[i] = (value >> 20) & 0x3ff;
6120
+ }
6121
+
6122
+ return 0;
6123
+}
6124
+
6125
+static void vop2_crtc_csu_set_rate(struct drm_crtc *crtc)
6126
+{
6127
+ struct vop2_video_port *vp = to_vop2_video_port(crtc);
6128
+ struct vop2 *vop2 = vp->vop2;
6129
+ unsigned long aclk_rate = 0, dclk_rate = 0;
6130
+ u32 csu_div = 0;
6131
+
6132
+ if (!vop2->csu_aclk)
6133
+ return;
6134
+
6135
+ aclk_rate = clk_get_rate(vop2->aclk);
6136
+ dclk_rate = clk_get_rate(vp->dclk);
6137
+ if (!dclk_rate)
6138
+ return;
6139
+
6140
+ /* aclk >= 1/2 * dclk */
6141
+ csu_div = aclk_rate * 2 / dclk_rate;
6142
+
6143
+ rockchip_csu_set_div(vop2->csu_aclk, csu_div);
6144
+}
6145
+
6146
+static int vop2_crtc_loader_protect(struct drm_crtc *crtc, bool on, void *data)
6147
+{
6148
+ struct vop2_video_port *vp = to_vop2_video_port(crtc);
6149
+ struct rockchip_crtc_state *vcstate = to_rockchip_crtc_state(crtc->state);
6150
+ struct vop2 *vop2 = vp->vop2;
42996151 struct rockchip_drm_private *private = crtc->dev->dev_private;
6152
+ const struct vop2_video_port_data *vp_data = &vop2->data->vp[vp->id];
6153
+ struct vop2_video_port *splice_vp = &vop2->vps[vp_data->splice_vp_id];
6154
+ struct drm_crtc_state *crtc_state;
6155
+ struct drm_display_mode *mode;
6156
+ struct vop2_win *win, *splice_win;
6157
+ struct vop2_extend_pll *ext_pll;
6158
+ struct clk *parent_clk;
6159
+ const char *clk_name;
43006160
43016161 if (on == vp->loader_protect)
43026162 return 0;
43036163
43046164 if (on) {
6165
+ vp->loader_protect = true;
43056166 vop2->active_vp_mask |= BIT(vp->id);
43066167 vop2_set_system_status(vop2);
43076168 vop2_initial(crtc);
6169
+ if (crtc->primary) {
6170
+ win = to_vop2_win(crtc->primary);
6171
+ if (VOP_WIN_GET(vop2, win, enable)) {
6172
+ if (win->pd) {
6173
+ win->pd->ref_count++;
6174
+ win->pd->vp_mask |= BIT(vp->id);
6175
+ }
6176
+
6177
+ vp->enabled_win_mask |= BIT(win->phys_id);
6178
+ crtc_state = drm_atomic_get_crtc_state(crtc->state->state, crtc);
6179
+ mode = &crtc_state->adjusted_mode;
6180
+ if (mode->hdisplay > VOP2_MAX_VP_OUTPUT_WIDTH) {
6181
+ vcstate->splice_mode = true;
6182
+ splice_win = vop2_find_win_by_phys_id(vop2,
6183
+ win->splice_win_id);
6184
+ splice_win->splice_mode_right = true;
6185
+ splice_win->left_win = win;
6186
+ win->splice_win = splice_win;
6187
+ splice_vp->win_mask |= BIT(splice_win->phys_id);
6188
+ splice_win->vp_mask = BIT(splice_vp->id);
6189
+ vop2->active_vp_mask |= BIT(splice_vp->id);
6190
+ vp->enabled_win_mask |= BIT(splice_win->phys_id);
6191
+
6192
+ if (splice_win->pd &&
6193
+ VOP_WIN_GET(vop2, splice_win, enable)) {
6194
+ splice_win->pd->ref_count++;
6195
+ splice_win->pd->vp_mask |= BIT(splice_vp->id);
6196
+ }
6197
+ }
6198
+ }
6199
+ }
6200
+ parent_clk = clk_get_parent(vp->dclk);
6201
+ clk_name = __clk_get_name(parent_clk);
6202
+ if (!strcmp(clk_name, "clk_hdmiphy_pixel0")) {
6203
+ ext_pll = vop2_extend_clk_find_by_name(vop2, "hdmi0_phy_pll");
6204
+ if (ext_pll)
6205
+ ext_pll->vp_mask |= BIT(vp->id);
6206
+ } else if (!strcmp(clk_name, "clk_hdmiphy_pixel1")) {
6207
+ ext_pll = vop2_extend_clk_find_by_name(vop2, "hdmi1_phy_pll");
6208
+ if (ext_pll)
6209
+ ext_pll->vp_mask |= BIT(vp->id);
6210
+ }
43086211 drm_crtc_vblank_on(crtc);
6212
+ if (is_vop3(vop2)) {
6213
+ if (vp_data->feature & (VOP_FEATURE_POST_ACM))
6214
+ vop2_crtc_get_inital_acm_info(crtc);
6215
+ if (data && (vp_data->feature & VOP_FEATURE_POST_CSC))
6216
+ memcpy(&vp->csc_info, data, sizeof(struct post_csc));
6217
+ }
43096218 if (private->cubic_lut[vp->id].enable) {
43106219 dma_addr_t cubic_lut_mst;
43116220 struct loader_cubic_lut *cubic_lut = &private->cubic_lut[vp->id];
....@@ -4313,10 +6222,10 @@
43136222 cubic_lut_mst = cubic_lut->offset + private->cubic_lut_dma_addr;
43146223 VOP_MODULE_SET(vop2, vp, cubic_lut_mst, cubic_lut_mst);
43156224 }
4316
- vp->loader_protect = true;
6225
+
6226
+ vop2_crtc_csu_set_rate(crtc);
43176227 } else {
43186228 vop2_crtc_atomic_disable(crtc, NULL);
4319
- vp->loader_protect = false;
43206229 }
43216230
43226231 return 0;
....@@ -4338,6 +6247,10 @@
43386247 struct drm_rect *src, *dest;
43396248 struct drm_framebuffer *fb = pstate->fb;
43406249 struct drm_format_name_buf format_name;
6250
+ struct drm_gem_object *obj;
6251
+ struct rockchip_gem_object *rk_obj;
6252
+ dma_addr_t fb_addr;
6253
+
43416254 int i;
43426255
43436256 DEBUG_PRINT(" %s: %s\n", win->name, pstate->crtc ? "ACTIVE" : "DISABLED");
....@@ -4368,8 +6281,10 @@
43686281 DEBUG_PRINT("\tdst: pos[%d, %d] rect[%d x %d]\n", dest->x1, dest->y1,
43696282 drm_rect_width(dest), drm_rect_height(dest));
43706283
4371
- for (i = 0; i < drm_format_num_planes(fb->format->format); i++) {
4372
- dma_addr_t fb_addr = rockchip_fb_get_dma_addr(fb, i);
6284
+ for (i = 0; i < fb->format->num_planes; i++) {
6285
+ obj = fb->obj[0];
6286
+ rk_obj = to_rockchip_obj(obj);
6287
+ fb_addr = rk_obj->dma_addr + fb->offsets[0];
43736288
43746289 DEBUG_PRINT("\tbuf[%d]: addr: %pad pitch: %d offset: %d\n",
43756290 i, &fb_addr, fb->pitches[i], fb->offsets[i]);
....@@ -4449,8 +6364,9 @@
44496364
44506365 /* only need to dump once at first active crtc for vop2 */
44516366 for (i = 0; i < vop2_data->nr_vps; i++) {
4452
- if (vop2->vps[i].crtc.state->active) {
4453
- first_active_crtc = &vop2->vps[i].crtc;
6367
+ if (vop2->vps[i].rockchip_crtc.crtc.state &&
6368
+ vop2->vps[i].rockchip_crtc.crtc.state->active) {
6369
+ first_active_crtc = &vop2->vps[i].rockchip_crtc.crtc;
44546370 break;
44556371 }
44566372 }
....@@ -4492,8 +6408,9 @@
44926408
44936409 /* only need to dump once at first active crtc for vop2 */
44946410 for (i = 0; i < vop2_data->nr_vps; i++) {
4495
- if (vop2->vps[i].crtc.state->active) {
4496
- first_active_crtc = &vop2->vps[i].crtc;
6411
+ if (vop2->vps[i].rockchip_crtc.crtc.state &&
6412
+ vop2->vps[i].rockchip_crtc.crtc.state->active) {
6413
+ first_active_crtc = &vop2->vps[i].rockchip_crtc.crtc;
44976414 break;
44986415 }
44996416 }
....@@ -4529,7 +6446,7 @@
45296446 struct vop2_video_port *vp = &vop2->vps[i];
45306447
45316448 if (!vp->lut || !vp->gamma_lut_active ||
4532
- !vop2->lut_regs || !vp->crtc.state->enable) {
6449
+ !vop2->lut_regs || !vp->rockchip_crtc.crtc.state->enable) {
45336450 DEBUG_PRINT("Video port%d gamma disabled\n", vp->id);
45346451 continue;
45356452 }
....@@ -4556,7 +6473,7 @@
45566473 struct vop2_video_port *vp = &vop2->vps[i];
45576474
45586475 if ((!vp->cubic_lut_gem_obj && !private->cubic_lut[vp->id].enable) ||
4559
- !vp->cubic_lut || !vp->crtc.state->enable) {
6476
+ !vp->cubic_lut || !vp->rockchip_crtc.crtc.state->enable) {
45606477 DEBUG_PRINT("Video port%d cubic lut disabled\n", vp->id);
45616478 continue;
45626479 }
....@@ -4599,24 +6516,17 @@
45996516 goto remove;
46006517 }
46016518 #if defined(CONFIG_ROCKCHIP_DRM_DEBUG)
4602
- drm_debugfs_vop_add(crtc, vop2->debugfs);
6519
+ rockchip_drm_add_dump_buffer(crtc, vop2->debugfs);
6520
+ rockchip_drm_debugfs_add_color_bar(crtc, vop2->debugfs);
46036521 #endif
46046522 for (i = 0; i < ARRAY_SIZE(vop2_debugfs_files); i++)
46056523 vop2->debugfs_files[i].data = vop2;
46066524
4607
- ret = drm_debugfs_create_files(vop2->debugfs_files,
4608
- ARRAY_SIZE(vop2_debugfs_files),
4609
- vop2->debugfs,
4610
- minor);
4611
- if (ret) {
4612
- dev_err(vop2->dev, "could not install rockchip_debugfs_list\n");
4613
- goto free;
4614
- }
4615
-
6525
+ drm_debugfs_create_files(vop2->debugfs_files,
6526
+ ARRAY_SIZE(vop2_debugfs_files),
6527
+ vop2->debugfs,
6528
+ minor);
46166529 return 0;
4617
-free:
4618
- kfree(vop2->debugfs_files);
4619
- vop2->debugfs_files = NULL;
46206530 remove:
46216531 debugfs_remove(vop2->debugfs);
46226532 vop2->debugfs = NULL;
....@@ -4624,29 +6534,60 @@
46246534 }
46256535
46266536 static enum drm_mode_status
4627
-vop2_crtc_mode_valid(struct drm_crtc *crtc, const struct drm_display_mode *mode,
4628
- int output_type)
6537
+vop2_crtc_mode_valid(struct drm_crtc *crtc, const struct drm_display_mode *mode)
46296538 {
6539
+ struct rockchip_crtc_state *vcstate = to_rockchip_crtc_state(crtc->state);
46306540 struct vop2_video_port *vp = to_vop2_video_port(crtc);
46316541 struct vop2 *vop2 = vp->vop2;
46326542 const struct vop2_data *vop2_data = vop2->data;
46336543 const struct vop2_video_port_data *vp_data = &vop2_data->vp[vp->id];
46346544 int request_clock = mode->clock;
46356545 int clock;
6546
+ unsigned long aclk_rate;
6547
+ uint8_t active_vp_mask = vop2->active_vp_mask;
6548
+
6549
+ /*
6550
+ * For RK3588, VP0 and VP1 will be both used in splice mode. All display
6551
+ * modes of the right VP should be set as invalid when vop2 is working in
6552
+ * splice mode.
6553
+ */
6554
+ if (vp->splice_mode_right)
6555
+ return MODE_BAD;
6556
+
6557
+ if ((active_vp_mask & BIT(ROCKCHIP_VOP_VP1)) && !vcstate->splice_mode &&
6558
+ mode->hdisplay > VOP2_MAX_VP_OUTPUT_WIDTH) {
6559
+ DRM_DEV_DEBUG(vop2->dev, "can not support resolution %dx%d, vp1 is busy\n",
6560
+ mode->hdisplay, mode->vdisplay);
6561
+ return MODE_BAD;
6562
+ }
46366563
46376564 if (mode->hdisplay > vp_data->max_output.width)
46386565 return MODE_BAD_HVALUE;
46396566
4640
- if (mode->flags & DRM_MODE_FLAG_DBLCLK)
6567
+ if (mode->flags & DRM_MODE_FLAG_DBLCLK || vcstate->output_if & VOP_OUTPUT_IF_BT656)
46416568 request_clock *= 2;
46426569
4643
- clock = clk_round_rate(vp->dclk, request_clock * 1000) / 1000;
6570
+ aclk_rate = clk_get_rate(vop2->aclk) / 1000;
6571
+
6572
+ if (request_clock > VOP2_MAX_DCLK_RATE && aclk_rate <= VOP2_COMMON_ACLK_RATE)
6573
+ return MODE_BAD;
6574
+
6575
+ if ((request_clock <= VOP2_MAX_DCLK_RATE) &&
6576
+ (vop2_extend_clk_find_by_name(vop2, "hdmi0_phy_pll") ||
6577
+ vop2_extend_clk_find_by_name(vop2, "hdmi1_phy_pll"))) {
6578
+ clock = request_clock;
6579
+ } else {
6580
+ if (request_clock > VOP2_MAX_DCLK_RATE)
6581
+ request_clock = request_clock >> 2;
6582
+ clock = rockchip_drm_dclk_round_rate(vop2->version, vp->dclk,
6583
+ request_clock * 1000) / 1000;
6584
+ }
46446585
46456586 /*
46466587 * Hdmi or DisplayPort request a Accurate clock.
46476588 */
4648
- if (output_type == DRM_MODE_CONNECTOR_HDMIA ||
4649
- output_type == DRM_MODE_CONNECTOR_DisplayPort)
6589
+ if (vcstate->output_type == DRM_MODE_CONNECTOR_HDMIA ||
6590
+ vcstate->output_type == DRM_MODE_CONNECTOR_DisplayPort)
46506591 if (clock != request_clock)
46516592 return MODE_CLOCK_RANGE;
46526593
....@@ -4673,7 +6614,7 @@
46736614 struct drm_framebuffer *fb = pstate->fb;
46746615 struct drm_rect *dst = &vpstate->dest;
46756616 struct drm_rect *src = &vpstate->src;
4676
- int bpp = fb->format->bpp[0];
6617
+ int bpp = rockchip_drm_get_bpp(fb->format);
46776618 int src_width = drm_rect_width(src) >> 16;
46786619 int src_height = drm_rect_height(src) >> 16;
46796620 int dst_width = drm_rect_width(dst);
....@@ -4682,16 +6623,16 @@
46826623 size_t bandwidth;
46836624
46846625 if (src_width <= 0 || src_height <= 0 || dst_width <= 0 ||
4685
- dst_height <= 0)
6626
+ dst_height <= 0 || !bpp)
46866627 return 0;
46876628
46886629 bandwidth = src_width * bpp / 8;
46896630
46906631 bandwidth = bandwidth * src_width / dst_width;
46916632 bandwidth = bandwidth * src_height / dst_height;
4692
- if (vskiplines == 2)
6633
+ if (vskiplines == 2 && vpstate->afbc_en == 0)
46936634 bandwidth /= 2;
4694
- else if (vskiplines == 4)
6635
+ else if (vskiplines == 4 && vpstate->afbc_en == 0)
46956636 bandwidth /= 4;
46966637
46976638 return bandwidth;
....@@ -4721,10 +6662,9 @@
47216662
47226663 static size_t vop2_crtc_bandwidth(struct drm_crtc *crtc,
47236664 struct drm_crtc_state *crtc_state,
4724
- size_t *frame_bw_mbyte,
4725
- unsigned int *plane_num_total)
6665
+ struct dmcfreq_vop_info *vop_bw_info)
47266666 {
4727
- struct drm_display_mode *adjusted_mode = &crtc_state->adjusted_mode;
6667
+ struct drm_display_mode *adjusted_mode = &crtc->state->adjusted_mode;
47286668 uint16_t htotal = adjusted_mode->crtc_htotal;
47296669 uint16_t vdisplay = adjusted_mode->crtc_vdisplay;
47306670 int clock = adjusted_mode->crtc_clock;
....@@ -4733,44 +6673,49 @@
47336673 struct drm_plane_state *pstate;
47346674 struct vop2_bandwidth *pbandwidth;
47356675 struct drm_plane *plane;
4736
- uint64_t line_bandwidth;
6676
+ u64 line_bw_mbyte = 0;
47376677 int8_t cnt = 0, plane_num = 0;
6678
+ int i = 0;
47386679 #if defined(CONFIG_ROCKCHIP_DRM_DEBUG)
47396680 struct vop_dump_list *pos, *n;
6681
+ struct vop2_video_port *vp = to_vop2_video_port(crtc);
47406682 #endif
47416683
47426684 if (!htotal || !vdisplay)
47436685 return 0;
47446686
47456687 #if defined(CONFIG_ROCKCHIP_DRM_DEBUG)
4746
- if (!crtc->vop_dump_list_init_flag) {
4747
- INIT_LIST_HEAD(&crtc->vop_dump_list_head);
4748
- crtc->vop_dump_list_init_flag = true;
6688
+ if (!vp->rockchip_crtc.vop_dump_list_init_flag) {
6689
+ INIT_LIST_HEAD(&vp->rockchip_crtc.vop_dump_list_head);
6690
+ vp->rockchip_crtc.vop_dump_list_init_flag = true;
47496691 }
4750
- list_for_each_entry_safe(pos, n, &crtc->vop_dump_list_head, entry) {
6692
+ list_for_each_entry_safe(pos, n, &vp->rockchip_crtc.vop_dump_list_head, entry) {
47516693 list_del(&pos->entry);
47526694 }
4753
- if (crtc->vop_dump_status == DUMP_KEEP ||
4754
- crtc->vop_dump_times > 0) {
4755
- crtc->frame_count++;
6695
+ if (vp->rockchip_crtc.vop_dump_status == DUMP_KEEP ||
6696
+ vp->rockchip_crtc.vop_dump_times > 0) {
6697
+ vp->rockchip_crtc.frame_count++;
47566698 }
47576699 #endif
47586700
4759
- drm_atomic_crtc_state_for_each_plane(plane, crtc_state)
4760
- plane_num++;
6701
+ for_each_new_plane_in_state(state, plane, pstate, i) {
6702
+ if (pstate->crtc == crtc)
6703
+ plane_num++;
6704
+ }
47616705
4762
- if (plane_num_total)
4763
- *plane_num_total += plane_num;
6706
+ vop_bw_info->plane_num += plane_num;
47646707 pbandwidth = kmalloc_array(plane_num, sizeof(*pbandwidth),
47656708 GFP_KERNEL);
47666709 if (!pbandwidth)
47676710 return -ENOMEM;
4768
- drm_atomic_crtc_state_for_each_plane(plane, crtc_state) {
4769
- int act_w, act_h, bpp, afbc_fac;
47706711
4771
- pstate = drm_atomic_get_new_plane_state(state, plane);
6712
+ for_each_new_plane_in_state(state, plane, pstate, i) {
6713
+ int act_w, act_h, bpp, afbc_fac;
6714
+ int fps = drm_mode_vrefresh(adjusted_mode);
6715
+
47726716 if (!pstate || pstate->crtc != crtc || !pstate->fb)
47736717 continue;
6718
+
47746719 /* This is an empirical value, if it's afbc format, the frame buffer size div 2 */
47756720 afbc_fac = rockchip_afbc(plane, pstate->fb->modifier) ? 2 : 1;
47766721
....@@ -4781,24 +6726,28 @@
47816726
47826727 act_w = drm_rect_width(&pstate->src) >> 16;
47836728 act_h = drm_rect_height(&pstate->src) >> 16;
4784
- bpp = pstate->fb->format->bpp[0];
6729
+ if (pstate->fb->format->is_yuv && (act_w >= 3840 || act_h >= 3840))
6730
+ vop_bw_info->plane_num_4k++;
47856731
4786
- *frame_bw_mbyte += act_w * act_h / 1000 * bpp / 8 * adjusted_mode->vrefresh / afbc_fac / 1000;
6732
+ bpp = rockchip_drm_get_bpp(pstate->fb->format);
6733
+
6734
+ vop_bw_info->frame_bw_mbyte += act_w * act_h / 1000 * bpp / 8 * fps / 1000 / afbc_fac;
47876735 }
47886736
47896737 sort(pbandwidth, cnt, sizeof(pbandwidth[0]), vop2_bandwidth_cmp, NULL);
47906738
4791
- line_bandwidth = vop2_calc_max_bandwidth(pbandwidth, 0, cnt, vdisplay);
6739
+ line_bw_mbyte = vop2_calc_max_bandwidth(pbandwidth, 0, cnt, vdisplay);
47926740 kfree(pbandwidth);
47936741 /*
47946742 * line_bandwidth(MB/s)
4795
- * = line_bandwidth(Byte) / line_time(s)
6743
+ * = line_bandwidth / line_time
47966744 * = line_bandwidth(Byte) * clock(KHZ) / 1000 / htotal
47976745 */
4798
- line_bandwidth *= clock;
4799
- do_div(line_bandwidth, htotal * 1000);
6746
+ line_bw_mbyte *= clock;
6747
+ do_div(line_bw_mbyte, htotal * 1000);
6748
+ vop_bw_info->line_bw_mbyte = line_bw_mbyte;
48006749
4801
- return line_bandwidth;
6750
+ return 0;
48026751 }
48036752
48046753 static void vop2_crtc_close(struct drm_crtc *crtc)
....@@ -4830,6 +6779,44 @@
48306779 VOP_MODULE_SET(vop2, vp, edpi_wms_fs, 1);
48316780 }
48326781
6782
+static int vop2_crtc_set_color_bar(struct drm_crtc *crtc, enum rockchip_color_bar_mode mode)
6783
+{
6784
+ struct vop2_video_port *vp = to_vop2_video_port(crtc);
6785
+ struct vop2 *vop2 = vp->vop2;
6786
+ int ret = 0;
6787
+
6788
+ if (!crtc->state->active) {
6789
+ DRM_INFO("Video port%d disabled\n", vp->id);
6790
+ return -EINVAL;
6791
+ }
6792
+
6793
+ switch (mode) {
6794
+ case ROCKCHIP_COLOR_BAR_OFF:
6795
+ DRM_INFO("disable color bar in VP%d\n", vp->id);
6796
+ VOP_MODULE_SET(vop2, vp, color_bar_en, 0);
6797
+ vop2_cfg_done(crtc);
6798
+ break;
6799
+ case ROCKCHIP_COLOR_BAR_HORIZONTAL:
6800
+ DRM_INFO("enable horizontal color bar in VP%d\n", vp->id);
6801
+ VOP_MODULE_SET(vop2, vp, color_bar_mode, 0);
6802
+ VOP_MODULE_SET(vop2, vp, color_bar_en, 1);
6803
+ vop2_cfg_done(crtc);
6804
+ break;
6805
+ case ROCKCHIP_COLOR_BAR_VERTICAL:
6806
+ DRM_INFO("enable vertical color bar in VP%d\n", vp->id);
6807
+ VOP_MODULE_SET(vop2, vp, color_bar_mode, 1);
6808
+ VOP_MODULE_SET(vop2, vp, color_bar_en, 1);
6809
+ vop2_cfg_done(crtc);
6810
+ break;
6811
+ default:
6812
+ DRM_INFO("Unsupported color bar mode\n");
6813
+ ret = -EINVAL;
6814
+ break;
6815
+ }
6816
+
6817
+ return ret;
6818
+}
6819
+
48336820 static const struct rockchip_crtc_funcs private_crtc_funcs = {
48346821 .loader_protect = vop2_crtc_loader_protect,
48356822 .cancel_pending_vblank = vop2_crtc_cancel_pending_vblank,
....@@ -4837,10 +6824,13 @@
48376824 .debugfs_dump = vop2_crtc_debugfs_dump,
48386825 .regs_dump = vop2_crtc_regs_dump,
48396826 .active_regs_dump = vop2_crtc_active_regs_dump,
4840
- .mode_valid = vop2_crtc_mode_valid,
48416827 .bandwidth = vop2_crtc_bandwidth,
48426828 .crtc_close = vop2_crtc_close,
48436829 .te_handler = vop2_crtc_te_handler,
6830
+ .crtc_send_mcu_cmd = vop3_crtc_send_mcu_cmd,
6831
+ .wait_vact_end = vop2_crtc_wait_vact_end,
6832
+ .crtc_standby = vop2_crtc_standby,
6833
+ .crtc_set_color_bar = vop2_crtc_set_color_bar,
48446834 };
48456835
48466836 static bool vop2_crtc_mode_fixup(struct drm_crtc *crtc,
....@@ -4849,6 +6839,10 @@
48496839 {
48506840 struct vop2_video_port *vp = to_vop2_video_port(crtc);
48516841 struct vop2 *vop2 = vp->vop2;
6842
+ struct drm_connector *connector;
6843
+ struct drm_connector_list_iter conn_iter;
6844
+ struct drm_crtc_state *new_crtc_state = container_of(mode, struct drm_crtc_state, mode);
6845
+ struct rockchip_crtc_state *vcstate = to_rockchip_crtc_state(new_crtc_state);
48526846
48536847 /*
48546848 * For RK3568 and RK3588, the hactive of video timing must
....@@ -4872,57 +6866,87 @@
48726866
48736867 drm_mode_set_crtcinfo(adj_mode, CRTC_INTERLACE_HALVE_V | CRTC_STEREO_DOUBLE);
48746868
4875
- if (mode->flags & DRM_MODE_FLAG_DBLCLK)
6869
+ if (mode->flags & DRM_MODE_FLAG_DBLCLK || vcstate->output_if & VOP_OUTPUT_IF_BT656)
48766870 adj_mode->crtc_clock *= 2;
48776871
4878
- adj_mode->crtc_clock = DIV_ROUND_UP(clk_round_rate(vp->dclk,
4879
- adj_mode->crtc_clock * 1000), 1000);
6872
+ /*
6873
+ * For RK3528, the path of CVBS output is like:
6874
+ * VOP BT656 ENCODER -> CVBS BT656 DECODER -> CVBS ENCODER -> CVBS VDAC
6875
+ * The vop2 dclk should be four times crtc_clock for CVBS sampling clock needs.
6876
+ */
6877
+ if (vop2->version == VOP_VERSION_RK3528 && vcstate->output_if & VOP_OUTPUT_IF_BT656)
6878
+ adj_mode->crtc_clock *= 4;
48806879
6880
+ if (vp->mcu_timing.mcu_pix_total)
6881
+ adj_mode->crtc_clock *= rockchip_drm_get_cycles_per_pixel(vcstate->bus_format) *
6882
+ (vp->mcu_timing.mcu_pix_total + 1);
6883
+
6884
+ drm_connector_list_iter_begin(crtc->dev, &conn_iter);
6885
+ drm_for_each_connector_iter(connector, &conn_iter) {
6886
+ if ((new_crtc_state->connector_mask & drm_connector_mask(connector)) &&
6887
+ ((connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) ||
6888
+ (connector->connector_type == DRM_MODE_CONNECTOR_HDMIA))) {
6889
+ drm_connector_list_iter_end(&conn_iter);
6890
+ return true;
6891
+ }
6892
+ }
6893
+ drm_connector_list_iter_end(&conn_iter);
6894
+
6895
+ if (adj_mode->crtc_clock <= VOP2_MAX_DCLK_RATE) {
6896
+ adj_mode->crtc_clock = rockchip_drm_dclk_round_rate(vop2->version, vp->dclk,
6897
+ adj_mode->crtc_clock * 1000);
6898
+ adj_mode->crtc_clock = DIV_ROUND_UP(adj_mode->crtc_clock, 1000);
6899
+ }
48816900 return true;
48826901 }
48836902
4884
-static void vop2_dither_setup(struct drm_crtc *crtc)
6903
+static void vop2_dither_setup(struct rockchip_crtc_state *vcstate, struct drm_crtc *crtc)
48856904 {
4886
- struct rockchip_crtc_state *vcstate = to_rockchip_crtc_state(crtc->state);
48876905 struct vop2_video_port *vp = to_vop2_video_port(crtc);
48886906 struct vop2 *vop2 = vp->vop2;
6907
+ bool pre_dither_down_en = false;
48896908
48906909 switch (vcstate->bus_format) {
48916910 case MEDIA_BUS_FMT_RGB565_1X16:
48926911 VOP_MODULE_SET(vop2, vp, dither_down_en, 1);
48936912 VOP_MODULE_SET(vop2, vp, dither_down_mode, RGB888_TO_RGB565);
4894
- VOP_MODULE_SET(vop2, vp, pre_dither_down_en, 1);
6913
+ pre_dither_down_en = true;
48956914 break;
48966915 case MEDIA_BUS_FMT_RGB666_1X18:
48976916 case MEDIA_BUS_FMT_RGB666_1X24_CPADHI:
48986917 case MEDIA_BUS_FMT_RGB666_1X7X3_SPWG:
4899
- case MEDIA_BUS_FMT_RGB666_1X7X3_JEIDA:
49006918 VOP_MODULE_SET(vop2, vp, dither_down_en, 1);
49016919 VOP_MODULE_SET(vop2, vp, dither_down_mode, RGB888_TO_RGB666);
4902
- VOP_MODULE_SET(vop2, vp, pre_dither_down_en, 1);
6920
+ pre_dither_down_en = true;
49036921 break;
6922
+ case MEDIA_BUS_FMT_YUYV8_1X16:
49046923 case MEDIA_BUS_FMT_YUV8_1X24:
49056924 case MEDIA_BUS_FMT_UYYVYY8_0_5X24:
49066925 VOP_MODULE_SET(vop2, vp, dither_down_en, 0);
4907
- VOP_MODULE_SET(vop2, vp, pre_dither_down_en, 1);
6926
+ pre_dither_down_en = true;
49086927 break;
6928
+ case MEDIA_BUS_FMT_YUYV10_1X20:
49096929 case MEDIA_BUS_FMT_YUV10_1X30:
49106930 case MEDIA_BUS_FMT_UYYVYY10_0_5X30:
49116931 case MEDIA_BUS_FMT_RGB101010_1X30:
49126932 VOP_MODULE_SET(vop2, vp, dither_down_en, 0);
4913
- VOP_MODULE_SET(vop2, vp, pre_dither_down_en, 0);
6933
+ pre_dither_down_en = false;
49146934 break;
4915
- case MEDIA_BUS_FMT_SRGB888_3X8:
4916
- case MEDIA_BUS_FMT_SRGB888_DUMMY_4X8:
6935
+ case MEDIA_BUS_FMT_RGB888_3X8:
6936
+ case MEDIA_BUS_FMT_RGB888_DUMMY_4X8:
49176937 case MEDIA_BUS_FMT_RGB888_1X24:
49186938 case MEDIA_BUS_FMT_RGB888_1X7X4_SPWG:
49196939 case MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA:
49206940 default:
49216941 VOP_MODULE_SET(vop2, vp, dither_down_en, 0);
4922
- VOP_MODULE_SET(vop2, vp, pre_dither_down_en, 1);
6942
+ pre_dither_down_en = true;
49236943 break;
49246944 }
49256945
6946
+ if (is_yuv_output(vcstate->bus_format))
6947
+ pre_dither_down_en = false;
6948
+
6949
+ VOP_MODULE_SET(vop2, vp, pre_dither_down_en, pre_dither_down_en);
49266950 VOP_MODULE_SET(vop2, vp, dither_down_sel, DITHER_DOWN_ALLEGRO);
49276951 }
49286952
....@@ -5009,18 +7033,619 @@
50097033 u16 vact_end = vact_st + vdisplay;
50107034 u32 htotal_sync = htotal << 16 | hsync_len;
50117035 u32 hactive_st_end = hact_st << 16 | hact_end;
5012
- u32 vtotal_sync = vtotal << 16 | vsync_len;
50137036 u32 vactive_st_end = vact_st << 16 | vact_end;
50147037 u32 crtc_clock = adjusted_mode->crtc_clock * 100;
50157038
50167039 if (htotal_sync != VOP_MODULE_GET(vop2, vp, htotal_pw) ||
50177040 hactive_st_end != VOP_MODULE_GET(vop2, vp, hact_st_end) ||
5018
- vtotal_sync != VOP_MODULE_GET(vop2, vp, vtotal_pw) ||
7041
+ vtotal != VOP_MODULE_GET(vop2, vp, dsp_vtotal) ||
7042
+ vsync_len != VOP_MODULE_GET(vop2, vp, dsp_vs_end) ||
50197043 vactive_st_end != VOP_MODULE_GET(vop2, vp, vact_st_end) ||
50207044 crtc_clock != clk_get_rate(vp->dclk))
50217045 return true;
50227046
50237047 return false;
7048
+}
7049
+
7050
+static int vop2_cru_set_rate(struct vop2_clk *if_pixclk, struct vop2_clk *if_dclk)
7051
+{
7052
+ int ret = 0;
7053
+
7054
+ if (if_pixclk) {
7055
+ ret = clk_set_rate(if_pixclk->hw.clk, if_pixclk->rate);
7056
+ if (ret < 0) {
7057
+ DRM_DEV_ERROR(if_pixclk->vop2->dev, "set %s to %ld failed: %d\n",
7058
+ clk_hw_get_name(&if_pixclk->hw), if_pixclk->rate, ret);
7059
+ return ret;
7060
+ }
7061
+ }
7062
+
7063
+ if (if_dclk) {
7064
+ ret = clk_set_rate(if_dclk->hw.clk, if_dclk->rate);
7065
+ if (ret < 0)
7066
+ DRM_DEV_ERROR(if_dclk->vop2->dev, "set %s to %ld failed %d\n",
7067
+ clk_hw_get_name(&if_dclk->hw), if_dclk->rate, ret);
7068
+ }
7069
+
7070
+ return ret;
7071
+}
7072
+
7073
+static int vop2_set_dsc_clk(struct drm_crtc *crtc, u8 dsc_id)
7074
+{
7075
+ struct vop2_video_port *vp = to_vop2_video_port(crtc);
7076
+ struct rockchip_crtc_state *vcstate = to_rockchip_crtc_state(crtc->state);
7077
+ struct vop2 *vop2 = vp->vop2;
7078
+ const struct vop2_data *vop2_data = vop2->data;
7079
+ const struct vop2_dsc_data *dsc_data = &vop2_data->dsc[dsc_id];
7080
+ struct vop2_clk *dsc_txp_clk, *dsc_pxl_clk, *dsc_cds_clk, *dsc_txp_clk_parent;
7081
+ char clk_name[32];
7082
+ int ret = 0;
7083
+
7084
+ /* set clk parent */
7085
+ snprintf(clk_name, sizeof(clk_name), "dclk%d", vp->id);
7086
+ dsc_txp_clk = vop2_clk_get(vop2, dsc_data->dsc_txp_clk_src_name);
7087
+ dsc_txp_clk_parent = vop2_clk_get(vop2, clk_name);
7088
+ if (!dsc_txp_clk || !dsc_txp_clk_parent) {
7089
+ DRM_DEV_ERROR(vop2->dev, "failed to get dsc clk\n");
7090
+ return -ENODEV;
7091
+ }
7092
+ ret = clk_set_parent(dsc_txp_clk->hw.clk, dsc_txp_clk_parent->hw.clk);
7093
+ if (ret < 0) {
7094
+ DRM_DEV_ERROR(vop2->dev, "failed to set parent(%s) for %s: %d\n",
7095
+ __clk_get_name(dsc_txp_clk_parent->hw.clk),
7096
+ __clk_get_name(dsc_txp_clk->hw.clk), ret);
7097
+ return ret;
7098
+ }
7099
+
7100
+ /* set dsc txp clk rate */
7101
+ clk_set_rate(dsc_txp_clk->hw.clk, vcstate->dsc_txp_clk_rate);
7102
+
7103
+ /* set dsc pxl clk rate */
7104
+ dsc_pxl_clk = vop2_clk_get(vop2, dsc_data->dsc_pxl_clk_name);
7105
+ if (!dsc_pxl_clk) {
7106
+ DRM_DEV_ERROR(vop2->dev, "failed to get dsc_pxl_clk\n");
7107
+ return -ENODEV;
7108
+ }
7109
+ clk_set_rate(dsc_pxl_clk->hw.clk, vcstate->dsc_pxl_clk_rate);
7110
+
7111
+ /* set dsc cds clk rate */
7112
+ dsc_cds_clk = vop2_clk_get(vop2, dsc_data->dsc_cds_clk_name);
7113
+ if (!dsc_cds_clk) {
7114
+ DRM_DEV_ERROR(vop2->dev, "failed to get dsc_cds_clk\n");
7115
+ return -ENODEV;
7116
+ }
7117
+ clk_set_rate(dsc_cds_clk->hw.clk, vcstate->dsc_cds_clk_rate);
7118
+
7119
+ return 0;
7120
+}
7121
+
7122
+static int vop2_calc_if_clk(struct drm_crtc *crtc, const struct vop2_connector_if_data *if_data,
7123
+ struct vop2_clk *if_pixclk, struct vop2_clk *if_dclk, int conn_id)
7124
+{
7125
+ struct vop2_video_port *vp = to_vop2_video_port(crtc);
7126
+ struct vop2 *vop2 = vp->vop2;
7127
+ struct drm_display_mode *adjusted_mode = &crtc->state->adjusted_mode;
7128
+ struct rockchip_crtc_state *vcstate = to_rockchip_crtc_state(crtc->state);
7129
+ u64 v_pixclk = adjusted_mode->crtc_clock * 1000LL; /* video timing pixclk */
7130
+ unsigned long dclk_core_rate, dclk_out_rate = 0;
7131
+ /*conn_dclk = conn_pixclk or conn_dclk = conn_pixclk / 2 */
7132
+ u64 hdmi_edp_pixclk, hdmi_edp_dclk, mipi_pixclk;
7133
+ char dclk_core_div_shift = 2;
7134
+ char K = 1;
7135
+ char clk_name[32];
7136
+ struct vop2_clk *dclk_core, *dclk_out, *dclk;
7137
+ int ret;
7138
+ bool dsc_txp_clk_is_biggest = false;
7139
+ u8 dsc_id = conn_id & (VOP_OUTPUT_IF_MIPI0 | VOP_OUTPUT_IF_HDMI0) ? 0 : 1;
7140
+
7141
+ dclk_core_div_shift = if_data->post_proc_div_shift;
7142
+ dclk_core_rate = v_pixclk >> dclk_core_div_shift;
7143
+
7144
+ if (!if_dclk && (output_if_is_hdmi(conn_id) || output_if_is_edp(conn_id)))
7145
+ return -EINVAL;
7146
+ if ((vcstate->output_flags & ROCKCHIP_OUTPUT_DUAL_CHANNEL_LEFT_RIGHT_MODE) &&
7147
+ (vcstate->output_mode == ROCKCHIP_OUT_MODE_YUV420)) {
7148
+ DRM_DEV_ERROR(vop2->dev, "Dual channel and YUV420 can't work together\n");
7149
+ return -EINVAL;
7150
+ }
7151
+
7152
+ if ((vcstate->output_flags & ROCKCHIP_OUTPUT_DUAL_CHANNEL_LEFT_RIGHT_MODE) ||
7153
+ (vcstate->output_mode == ROCKCHIP_OUT_MODE_YUV420))
7154
+ K = 2;
7155
+
7156
+ if (output_if_is_hdmi(conn_id)) {
7157
+ if (vcstate->dsc_enable) {
7158
+ hdmi_edp_pixclk = vcstate->dsc_cds_clk_rate << 1;
7159
+ hdmi_edp_dclk = vcstate->dsc_cds_clk_rate;
7160
+ } else {
7161
+ hdmi_edp_pixclk = (dclk_core_rate << 1) / K;
7162
+ hdmi_edp_dclk = dclk_core_rate / K;
7163
+ }
7164
+
7165
+ if_pixclk->rate = hdmi_edp_pixclk;
7166
+ if_dclk->rate = hdmi_edp_dclk;
7167
+ } else if (output_if_is_edp(conn_id)) {
7168
+ hdmi_edp_pixclk = v_pixclk;
7169
+ do_div(hdmi_edp_pixclk, K);
7170
+ hdmi_edp_dclk = hdmi_edp_pixclk;
7171
+
7172
+ if_pixclk->rate = hdmi_edp_pixclk;
7173
+ if_dclk->rate = hdmi_edp_dclk;
7174
+ } else if (output_if_is_dp(conn_id)) {
7175
+ dclk_out_rate = v_pixclk >> 2;
7176
+ dclk_out_rate = dclk_out_rate / K;
7177
+ if_pixclk->rate = dclk_out_rate;
7178
+ } else if (output_if_is_mipi(conn_id)) {
7179
+ if (vcstate->dsc_enable)
7180
+ /* dsc output is 96bit, dsi input is 192 bit */
7181
+ mipi_pixclk = vcstate->dsc_cds_clk_rate >> 1;
7182
+ else
7183
+ mipi_pixclk = dclk_core_rate / K;
7184
+
7185
+ dclk_out_rate = dclk_core_rate / K;
7186
+ if_pixclk->rate = mipi_pixclk;
7187
+ } else if (output_if_is_dpi(conn_id)) {
7188
+ if_pixclk->rate = v_pixclk;
7189
+ }
7190
+
7191
+ /*
7192
+ * RGB/eDP/HDMI: if_pixclk >= dclk_core
7193
+ * DP: dp_pixclk = dclk_out <= dclk_core
7194
+ * DSI: mipi_pixclk <= dclk_out <= dclk_core
7195
+ *
7196
+ */
7197
+ snprintf(clk_name, sizeof(clk_name), "dclk_core%d", vp->id);
7198
+ dclk_core = vop2_clk_get(vop2, clk_name);
7199
+
7200
+ snprintf(clk_name, sizeof(clk_name), "dclk_out%d", vp->id);
7201
+ dclk_out = vop2_clk_get(vop2, clk_name);
7202
+
7203
+ /*
7204
+ * HDMI use 1:1 dclk for rgb/yuv444, 1:2 for yuv420 when
7205
+ * pixclk <= 600
7206
+ * We want use HDMI PHY clk as dclk source for DP/HDMI.
7207
+ * The max freq of HDMI PHY CLK is 600 MHZ.
7208
+ * When used for HDMI, the input freq and v_pixclk must
7209
+ * keep 1:1 for rgb/yuv444, 1:2 for yuv420
7210
+ */
7211
+ if (output_if_is_hdmi(conn_id) || output_if_is_dp(conn_id) || output_if_is_mipi(conn_id)) {
7212
+ snprintf(clk_name, sizeof(clk_name), "dclk%d", vp->id);
7213
+ dclk = vop2_clk_get(vop2, clk_name);
7214
+ if (v_pixclk <= (VOP2_MAX_DCLK_RATE * 1000)) {
7215
+ if (vcstate->output_mode == ROCKCHIP_OUT_MODE_YUV420 ||
7216
+ (vcstate->output_flags & ROCKCHIP_OUTPUT_DUAL_CHANNEL_LEFT_RIGHT_MODE))
7217
+ v_pixclk = v_pixclk >> 1;
7218
+ } else {
7219
+ v_pixclk = v_pixclk >> 2;
7220
+ }
7221
+ clk_set_rate(dclk->hw.clk, v_pixclk);
7222
+ }
7223
+
7224
+ if (vcstate->dsc_enable) {
7225
+ if ((vcstate->dsc_txp_clk_rate >= dclk_core_rate) &&
7226
+ (vcstate->dsc_txp_clk_rate >= if_pixclk->rate)) {
7227
+ dsc_txp_clk_is_biggest = true;
7228
+ if (vcstate->output_flags & ROCKCHIP_OUTPUT_DUAL_CHANNEL_LEFT_RIGHT_MODE) {
7229
+ vop2_set_dsc_clk(crtc, 0);
7230
+ vop2_set_dsc_clk(crtc, 1);
7231
+ } else {
7232
+ vop2_set_dsc_clk(crtc, dsc_id);
7233
+ }
7234
+ }
7235
+ }
7236
+
7237
+ if (dclk_core_rate > if_pixclk->rate) {
7238
+ clk_set_rate(dclk_core->hw.clk, dclk_core_rate);
7239
+ if (output_if_is_mipi(conn_id))
7240
+ clk_set_rate(dclk_out->hw.clk, dclk_out_rate);
7241
+ ret = vop2_cru_set_rate(if_pixclk, if_dclk);
7242
+ } else {
7243
+ if (output_if_is_mipi(conn_id))
7244
+ clk_set_rate(dclk_out->hw.clk, dclk_out_rate);
7245
+ ret = vop2_cru_set_rate(if_pixclk, if_dclk);
7246
+ clk_set_rate(dclk_core->hw.clk, dclk_core_rate);
7247
+ }
7248
+
7249
+ if (!dsc_txp_clk_is_biggest && vcstate->dsc_enable) {
7250
+ if (vcstate->output_flags & ROCKCHIP_OUTPUT_DUAL_CHANNEL_LEFT_RIGHT_MODE) {
7251
+ vop2_set_dsc_clk(crtc, 0);
7252
+ vop2_set_dsc_clk(crtc, 1);
7253
+ } else {
7254
+ vop2_set_dsc_clk(crtc, dsc_id);
7255
+ }
7256
+ }
7257
+
7258
+ return ret;
7259
+}
7260
+
7261
+static int vop2_calc_dsc_clk(struct drm_crtc *crtc)
7262
+{
7263
+ struct vop2_video_port *vp = to_vop2_video_port(crtc);
7264
+ struct rockchip_crtc_state *vcstate = to_rockchip_crtc_state(crtc->state);
7265
+ struct vop2 *vop2 = vp->vop2;
7266
+ struct drm_display_mode *adjusted_mode = &crtc->state->adjusted_mode;
7267
+ u64 v_pixclk = adjusted_mode->crtc_clock * 1000LL; /* video timing pixclk */
7268
+ u8 k = 1;
7269
+
7270
+ if (!vop2->data->nr_dscs) {
7271
+ DRM_WARN("Unsupported DSC\n");
7272
+
7273
+ return 0;
7274
+ }
7275
+
7276
+ if (vcstate->output_flags & ROCKCHIP_OUTPUT_DUAL_CHANNEL_LEFT_RIGHT_MODE)
7277
+ k = 2;
7278
+
7279
+ vcstate->dsc_txp_clk_rate = v_pixclk;
7280
+ do_div(vcstate->dsc_txp_clk_rate, (vcstate->dsc_pixel_num * k));
7281
+
7282
+ vcstate->dsc_pxl_clk_rate = v_pixclk;
7283
+ do_div(vcstate->dsc_pxl_clk_rate, (vcstate->dsc_slice_num * k));
7284
+
7285
+ /* dsc_cds = crtc_clock / (cds_dat_width / bits_per_pixel)
7286
+ * cds_dat_width = 96;
7287
+ * bits_per_pixel = [8-12];
7288
+ * As cds clk is div from txp clk and only support 1/2/4 div,
7289
+ * so when txp_clk is equal to v_pixclk, we set dsc_cds = crtc_clock / 4,
7290
+ * otherwise dsc_cds = crtc_clock / 8;
7291
+ */
7292
+ vcstate->dsc_cds_clk_rate = v_pixclk / (vcstate->dsc_txp_clk_rate == v_pixclk ? 4 : 8);
7293
+
7294
+ return 0;
7295
+}
7296
+
7297
+static int vop2_calc_cru_cfg(struct drm_crtc *crtc, int conn_id,
7298
+ struct vop2_clk **if_pixclk, struct vop2_clk **if_dclk)
7299
+{
7300
+ struct vop2_video_port *vp = to_vop2_video_port(crtc);
7301
+ struct vop2 *vop2 = vp->vop2;
7302
+ const struct vop2_connector_if_data *if_data;
7303
+ struct vop2_clk *if_clk_src, *if_clk_parent;
7304
+ char clk_name[32];
7305
+ int ret;
7306
+
7307
+ if (vop2->version != VOP_VERSION_RK3588)
7308
+ return 0;
7309
+
7310
+ if_data = vop2_find_connector_if_data(vop2, conn_id);
7311
+ if_clk_src = vop2_clk_get(vop2, if_data->clk_src_name);
7312
+ snprintf(clk_name, sizeof(clk_name), "%s%d", if_data->clk_parent_name, vp->id);
7313
+ if_clk_parent = vop2_clk_get(vop2, clk_name);
7314
+ *if_pixclk = vop2_clk_get(vop2, if_data->pixclk_name);
7315
+ *if_dclk = vop2_clk_get(vop2, if_data->dclk_name);
7316
+ if (!(*if_pixclk) || !if_clk_parent) {
7317
+ DRM_DEV_ERROR(vop2->dev, "failed to get connector interface clk\n");
7318
+ return -ENODEV;
7319
+ }
7320
+
7321
+ ret = clk_set_parent(if_clk_src->hw.clk, if_clk_parent->hw.clk);
7322
+ if (ret < 0) {
7323
+ DRM_DEV_ERROR(vop2->dev, "failed to set parent(%s) for %s: %d\n",
7324
+ __clk_get_name(if_clk_parent->hw.clk),
7325
+ __clk_get_name(if_clk_src->hw.clk), ret);
7326
+ return ret;
7327
+ }
7328
+
7329
+ /* HDMI and eDP use independent if_pixclk and if_dclk, and others if_pixclk = if_dclk */
7330
+ if (output_if_is_hdmi(conn_id) || output_if_is_edp(conn_id))
7331
+ ret = vop2_calc_if_clk(crtc, if_data, *if_pixclk, *if_dclk, conn_id);
7332
+ else
7333
+ ret = vop2_calc_if_clk(crtc, if_data, *if_pixclk, NULL, conn_id);
7334
+
7335
+ return ret;
7336
+}
7337
+
7338
+static void vop2_crtc_load_pps(struct drm_crtc *crtc, u8 dsc_id)
7339
+{
7340
+ struct vop2_video_port *vp = to_vop2_video_port(crtc);
7341
+ struct vop2 *vop2 = vp->vop2;
7342
+ struct rockchip_crtc_state *vcstate = to_rockchip_crtc_state(crtc->state);
7343
+
7344
+ struct drm_dsc_picture_parameter_set *pps = &vcstate->pps;
7345
+ struct drm_dsc_picture_parameter_set config_pps;
7346
+ int i = 0;
7347
+ u32 *pps_val = (u32 *)&config_pps;
7348
+ u32 offset;
7349
+ struct vop2_dsc *dsc;
7350
+
7351
+ dsc = &vop2->dscs[dsc_id];
7352
+ offset = dsc->regs->dsc_pps0_3.offset;
7353
+
7354
+ memcpy(&config_pps, pps, sizeof(config_pps));
7355
+
7356
+ if ((config_pps.pps_3 & 0xf) > dsc->max_linebuf_depth) {
7357
+ config_pps.pps_3 &= 0xf0;
7358
+ config_pps.pps_3 |= dsc->max_linebuf_depth;
7359
+ DRM_WARN("DSC%d max_linebuf_depth is: %d, current set value is: %d\n",
7360
+ dsc_id, dsc->max_linebuf_depth, config_pps.pps_3 & 0xf);
7361
+ }
7362
+
7363
+ for (i = 0; i < DSC_NUM_BUF_RANGES; i++) {
7364
+ config_pps.rc_range_parameters[i] =
7365
+ (pps->rc_range_parameters[i] >> 3 & 0x1f) |
7366
+ ((pps->rc_range_parameters[i] >> 14 & 0x3) << 5) |
7367
+ ((pps->rc_range_parameters[i] >> 0 & 0x7) << 7) |
7368
+ ((pps->rc_range_parameters[i] >> 8 & 0x3f) << 10);
7369
+ }
7370
+
7371
+ for (i = 0; i < ROCKCHIP_DSC_PPS_SIZE_BYTE / 4; i++)
7372
+ vop2_writel(vop2, offset + i * 4, *pps_val++);
7373
+}
7374
+
7375
+static void vop2_crtc_enable_dsc(struct drm_crtc *crtc, struct drm_crtc_state *old_state, u8 dsc_id)
7376
+{
7377
+ struct vop2_video_port *vp = to_vop2_video_port(crtc);
7378
+ struct vop2 *vop2 = vp->vop2;
7379
+ struct rockchip_crtc_state *vcstate = to_rockchip_crtc_state(crtc->state);
7380
+ struct drm_display_mode *adjusted_mode = &crtc->state->adjusted_mode;
7381
+ struct rockchip_dsc_sink_cap *dsc_sink_cap = &vcstate->dsc_sink_cap;
7382
+ u16 hsync_len = adjusted_mode->crtc_hsync_end - adjusted_mode->crtc_hsync_start;
7383
+ u16 hdisplay = adjusted_mode->crtc_hdisplay;
7384
+ u16 htotal = adjusted_mode->crtc_htotal;
7385
+ u16 hact_st = adjusted_mode->crtc_htotal - adjusted_mode->crtc_hsync_start;
7386
+ u16 vdisplay = adjusted_mode->crtc_vdisplay;
7387
+ u16 vtotal = adjusted_mode->crtc_vtotal;
7388
+ u16 vsync_len = adjusted_mode->crtc_vsync_end - adjusted_mode->crtc_vsync_start;
7389
+ u16 vact_st = adjusted_mode->crtc_vtotal - adjusted_mode->crtc_vsync_start;
7390
+ u16 vact_end = vact_st + vdisplay;
7391
+ u8 dsc_interface_mode = 0;
7392
+ struct vop2_dsc *dsc;
7393
+ struct vop2_clk *dsc_cds_clk, *dsc_pxl_clk, *dsc_txp_clk;
7394
+ const struct vop2_data *vop2_data = vop2->data;
7395
+ const struct vop2_dsc_data *dsc_data = &vop2_data->dsc[dsc_id];
7396
+ bool mipi_ds_mode = false;
7397
+ uint32_t *reg_base = vop2->regs;
7398
+ u32 offset = 0;
7399
+
7400
+ if (!vop2->data->nr_dscs) {
7401
+ DRM_WARN("Unsupported DSC\n");
7402
+
7403
+ return;
7404
+ }
7405
+
7406
+ if (vcstate->dsc_slice_num > dsc_data->max_slice_num)
7407
+ DRM_ERROR("DSC%d supported max slice is: %d, current is: %d\n",
7408
+ dsc_data->id, dsc_data->max_slice_num, vcstate->dsc_slice_num);
7409
+
7410
+ dsc = &vop2->dscs[dsc_id];
7411
+ if (dsc->pd) {
7412
+ dsc->pd->vp_mask = BIT(vp->id);
7413
+ vop2_power_domain_get(dsc->pd);
7414
+ }
7415
+
7416
+ VOP_MODULE_SET(vop2, dsc, scan_timing_para_imd_en, 1);
7417
+ VOP_MODULE_SET(vop2, dsc, dsc_port_sel, vp->id);
7418
+ if (vcstate->output_if & (VOP_OUTPUT_IF_HDMI0 | VOP_OUTPUT_IF_HDMI1)) {
7419
+ dsc_interface_mode = VOP_DSC_IF_HDMI;
7420
+ } else {
7421
+ mipi_ds_mode = !!(vcstate->output_flags & ROCKCHIP_OUTPUT_MIPI_DS_MODE);
7422
+ if (mipi_ds_mode)
7423
+ dsc_interface_mode = VOP_DSC_IF_MIPI_DS_MODE;
7424
+ else
7425
+ dsc_interface_mode = VOP_DSC_IF_MIPI_VIDEO_MODE;
7426
+ }
7427
+
7428
+ if (vcstate->output_flags & ROCKCHIP_OUTPUT_DUAL_CHANNEL_LEFT_RIGHT_MODE)
7429
+ VOP_MODULE_SET(vop2, dsc, dsc_man_mode, 0);
7430
+ else
7431
+ VOP_MODULE_SET(vop2, dsc, dsc_man_mode, 1);
7432
+ dsc_cds_clk = vop2_clk_get(vop2, dsc_data->dsc_cds_clk_name);
7433
+ dsc_pxl_clk = vop2_clk_get(vop2, dsc_data->dsc_pxl_clk_name);
7434
+ dsc_txp_clk = vop2_clk_get(vop2, dsc_data->dsc_txp_clk_name);
7435
+
7436
+ VOP_MODULE_SET(vop2, dsc, dsc_interface_mode, dsc_interface_mode);
7437
+ VOP_MODULE_SET(vop2, dsc, dsc_pixel_num, vcstate->dsc_pixel_num >> 1);
7438
+ VOP_MODULE_SET(vop2, dsc, dsc_txp_clk_div, dsc_txp_clk->div_val);
7439
+ VOP_MODULE_SET(vop2, dsc, dsc_pxl_clk_div, dsc_pxl_clk->div_val);
7440
+ VOP_MODULE_SET(vop2, dsc, dsc_cds_clk_div, dsc_cds_clk->div_val);
7441
+ VOP_MODULE_SET(vop2, dsc, dsc_scan_en, !mipi_ds_mode);
7442
+ VOP_MODULE_SET(vop2, dsc, dsc_halt_en, mipi_ds_mode);
7443
+
7444
+ if (!mipi_ds_mode) {
7445
+ u16 dsc_hsync, dsc_htotal, dsc_hact_st, dsc_hact_end;
7446
+ u32 target_bpp = dsc_sink_cap->target_bits_per_pixel_x16;
7447
+ u64 dsc_cds_rate = vcstate->dsc_cds_clk_rate;
7448
+ u32 v_pixclk_mhz = adjusted_mode->crtc_clock / 1000; /* video timing pixclk */
7449
+ u32 dly_num, dsc_cds_rate_mhz, val = 0;
7450
+ struct vop2_clk *dclk_core;
7451
+ char clk_name[32];
7452
+ int k = 1;
7453
+
7454
+ if (vcstate->output_flags & ROCKCHIP_OUTPUT_DUAL_CHANNEL_LEFT_RIGHT_MODE)
7455
+ k = 2;
7456
+
7457
+ snprintf(clk_name, sizeof(clk_name), "dclk_core%d", vp->id);
7458
+ dclk_core = vop2_clk_get(vop2, clk_name);
7459
+
7460
+ if (target_bpp >> 4 < dsc->min_bits_per_pixel)
7461
+ DRM_ERROR("Unsupported bpp less than: %d\n", dsc->min_bits_per_pixel);
7462
+
7463
+ /*
7464
+ * dly_num = delay_line_num * T(one-line) / T (dsc_cds)
7465
+ * T (one-line) = 1/v_pixclk_mhz * htotal = htotal/v_pixclk_mhz
7466
+ * T (dsc_cds) = 1 / dsc_cds_rate_mhz
7467
+ *
7468
+ * HDMI:
7469
+ * delay_line_num: according the pps initial_xmit_delay to adjust vop dsc delay
7470
+ * delay_line_num = 4 - BPP / 8
7471
+ * = (64 - target_bpp / 8) / 16
7472
+ * dly_num = htotal * dsc_cds_rate_mhz / v_pixclk_mhz * (64 - target_bpp / 8) / 16;
7473
+ *
7474
+ * MIPI DSI[4320 and 9216 is buffer size for DSC]:
7475
+ * DSC0:delay_line_num = 4320 * 8 / slince_num / chunk_size;
7476
+ * delay_line_num = delay_line_num > 5 ? 5 : delay_line_num;
7477
+ * DSC1:delay_line_num = 9216 * 2 / slince_num / chunk_size;
7478
+ * delay_line_num = delay_line_num > 5 ? 5 : delay_line_num;
7479
+ * dly_num = htotal * dsc_cds_rate_mhz / v_pixclk_mhz * delay_line_num
7480
+ */
7481
+ do_div(dsc_cds_rate, 1000000); /* hz to Mhz */
7482
+ dsc_cds_rate_mhz = dsc_cds_rate;
7483
+ dsc_hsync = hsync_len / 2;
7484
+ if (dsc_interface_mode == VOP_DSC_IF_HDMI) {
7485
+ dly_num = htotal * dsc_cds_rate_mhz / v_pixclk_mhz * (64 - target_bpp / 8) / 16;
7486
+ } else {
7487
+ int dsc_buf_size = dsc->id == 0 ? 4320 * 8 : 9216 * 2;
7488
+ int delay_line_num = dsc_buf_size / vcstate->dsc_slice_num / be16_to_cpu(vcstate->pps.chunk_size);
7489
+
7490
+ delay_line_num = delay_line_num > 5 ? 5 : delay_line_num;
7491
+ dly_num = htotal * dsc_cds_rate_mhz / v_pixclk_mhz * delay_line_num;
7492
+
7493
+ /* The dsc mipi video mode dsc_hsync minimum size is 8 pixels */
7494
+ if (dsc_hsync < 8)
7495
+ dsc_hsync = 8;
7496
+ }
7497
+ VOP_MODULE_SET(vop2, dsc, dsc_init_dly_mode, 0);
7498
+ VOP_MODULE_SET(vop2, dsc, dsc_init_dly_num, dly_num);
7499
+ /*
7500
+ * htotal / dclk_core = dsc_htotal /cds_clk
7501
+ *
7502
+ * dclk_core = DCLK / (1 << dclk_core->div_val)
7503
+ * cds_clk = txp_clk / (1 << dsc_cds_clk->div_val)
7504
+ * txp_clk = DCLK / (1 << dsc_txp_clk->div_val)
7505
+ *
7506
+ * dsc_htotal = htotal * (1 << dclk_core->div_val) /
7507
+ ((1 << dsc_txp_clk->div_val) * (1 << dsc_cds_clk->div_val))
7508
+ */
7509
+ dsc_htotal = htotal * (1 << dclk_core->div_val) /
7510
+ ((1 << dsc_txp_clk->div_val) * (1 << dsc_cds_clk->div_val));
7511
+ val = dsc_htotal << 16 | dsc_hsync;
7512
+ VOP_MODULE_SET(vop2, dsc, dsc_htotal_pw, val);
7513
+
7514
+ dsc_hact_st = hact_st / 2;
7515
+ dsc_hact_end = (hdisplay / k * target_bpp >> 4) / 24 + dsc_hact_st;
7516
+ val = dsc_hact_end << 16 | dsc_hact_st;
7517
+ VOP_MODULE_SET(vop2, dsc, dsc_hact_st_end, val);
7518
+
7519
+ VOP_MODULE_SET(vop2, dsc, dsc_vtotal, vtotal);
7520
+ VOP_MODULE_SET(vop2, dsc, dsc_vs_end, vsync_len);
7521
+ VOP_MODULE_SET(vop2, dsc, dsc_vact_st_end, vact_end << 16 | vact_st);
7522
+ }
7523
+
7524
+ VOP_MODULE_SET(vop2, dsc, rst_deassert, 1);
7525
+ udelay(10);
7526
+ /* read current dsc core register and backup to regsbak */
7527
+ offset = dsc->regs->dsc_en.offset;
7528
+ vop2->regsbak[offset >> 2] = reg_base[offset >> 2];
7529
+
7530
+ VOP_MODULE_SET(vop2, dsc, dsc_en, 1);
7531
+ vop2_crtc_load_pps(crtc, dsc_id);
7532
+
7533
+ VOP_MODULE_SET(vop2, dsc, dsc_rbit, 1);
7534
+ VOP_MODULE_SET(vop2, dsc, dsc_rbyt, 0);
7535
+ VOP_MODULE_SET(vop2, dsc, dsc_flal, 1);
7536
+ VOP_MODULE_SET(vop2, dsc, dsc_mer, 1);
7537
+ VOP_MODULE_SET(vop2, dsc, dsc_epb, 0);
7538
+ VOP_MODULE_SET(vop2, dsc, dsc_epl, 1);
7539
+ VOP_MODULE_SET(vop2, dsc, dsc_nslc, ilog2(vcstate->dsc_slice_num));
7540
+ VOP_MODULE_SET(vop2, dsc, dsc_sbo, 1);
7541
+ VOP_MODULE_SET(vop2, dsc, dsc_ifep, dsc_sink_cap->version_minor == 2 ? 1 : 0);
7542
+ VOP_MODULE_SET(vop2, dsc, dsc_pps_upd, 1);
7543
+
7544
+ DRM_DEV_INFO(vop2->dev, "DSC%d: txp:%lld div:%d, pxl:%lld div:%d, dsc:%lld div:%d\n",
7545
+ dsc->id,
7546
+ vcstate->dsc_txp_clk_rate, dsc_txp_clk->div_val,
7547
+ vcstate->dsc_pxl_clk_rate, dsc_pxl_clk->div_val,
7548
+ vcstate->dsc_cds_clk_rate, dsc_cds_clk->div_val);
7549
+
7550
+ dsc->attach_vp_id = vp->id;
7551
+ dsc->enabled = true;
7552
+}
7553
+
7554
+static inline bool vop2_mark_as_left_panel(struct rockchip_crtc_state *vcstate, u32 output_if)
7555
+{
7556
+ return vcstate->output_if_left_panel & output_if;
7557
+}
7558
+
7559
+static void vop2_setup_dual_channel_if(struct drm_crtc *crtc)
7560
+{
7561
+ struct vop2_video_port *vp = to_vop2_video_port(crtc);
7562
+ struct rockchip_crtc_state *vcstate = to_rockchip_crtc_state(crtc->state);
7563
+ struct vop2 *vop2 = vp->vop2;
7564
+
7565
+ if (vcstate->output_flags & ROCKCHIP_OUTPUT_DUAL_CHANNEL_ODD_EVEN_MODE) {
7566
+ VOP_CTRL_SET(vop2, lvds_dual_en, 1);
7567
+ VOP_CTRL_SET(vop2, lvds_dual_mode, 0);
7568
+ if (vcstate->output_flags & ROCKCHIP_OUTPUT_DATA_SWAP)
7569
+ VOP_CTRL_SET(vop2, lvds_dual_channel_swap, 1);
7570
+ return;
7571
+ }
7572
+
7573
+ VOP_MODULE_SET(vop2, vp, dual_channel_en, 1);
7574
+ if (vcstate->output_flags & ROCKCHIP_OUTPUT_DATA_SWAP)
7575
+ VOP_MODULE_SET(vop2, vp, dual_channel_swap, 1);
7576
+
7577
+ if (vcstate->output_if & VOP_OUTPUT_IF_DP1 &&
7578
+ !vop2_mark_as_left_panel(vcstate, VOP_OUTPUT_IF_DP1))
7579
+ VOP_CTRL_SET(vop2, dp_dual_en, 1);
7580
+ else if (vcstate->output_if & VOP_OUTPUT_IF_eDP1 &&
7581
+ !vop2_mark_as_left_panel(vcstate, VOP_OUTPUT_IF_eDP1))
7582
+ VOP_CTRL_SET(vop2, edp_dual_en, 1);
7583
+ else if (vcstate->output_if & VOP_OUTPUT_IF_HDMI1 &&
7584
+ !vop2_mark_as_left_panel(vcstate, VOP_OUTPUT_IF_HDMI1))
7585
+ VOP_CTRL_SET(vop2, hdmi_dual_en, 1);
7586
+ else if (vcstate->output_if & VOP_OUTPUT_IF_MIPI1 &&
7587
+ !vop2_mark_as_left_panel(vcstate, VOP_OUTPUT_IF_MIPI1))
7588
+ VOP_CTRL_SET(vop2, mipi_dual_en, 1);
7589
+ else if (vcstate->output_if & VOP_OUTPUT_IF_LVDS1) {
7590
+ VOP_CTRL_SET(vop2, lvds_dual_en, 1);
7591
+ VOP_CTRL_SET(vop2, lvds_dual_mode, 1);
7592
+ }
7593
+}
7594
+
7595
+/*
7596
+ * MIPI port mux on rk3588:
7597
+ * 0: Video Port2
7598
+ * 1: Video Port3
7599
+ * 3: Video Port 1(MIPI1 only)
7600
+ */
7601
+static int vop2_get_mipi_port_mux(struct vop2 *vop2, int vp_id)
7602
+{
7603
+ if (vop2->version == VOP_VERSION_RK3588) {
7604
+ if (vp_id == 1)
7605
+ return 3;
7606
+ else if (vp_id == 3)
7607
+ return 1;
7608
+ else
7609
+ return 0;
7610
+ } else {
7611
+ return vp_id;
7612
+ }
7613
+}
7614
+
7615
+static u32 vop2_get_hdmi_pol(struct vop2 *vop2, u32 flags)
7616
+{
7617
+ u32 val;
7618
+
7619
+ if (vop2->version == VOP_VERSION_RK3588) {
7620
+ val = (flags & DRM_MODE_FLAG_NHSYNC) ? BIT(HSYNC_POSITIVE) : 0;
7621
+ val |= (flags & DRM_MODE_FLAG_NVSYNC) ? BIT(VSYNC_POSITIVE) : 0;
7622
+ } else {
7623
+ val = (flags & DRM_MODE_FLAG_NHSYNC) ? 0 : BIT(HSYNC_POSITIVE);
7624
+ val |= (flags & DRM_MODE_FLAG_NVSYNC) ? 0 : BIT(VSYNC_POSITIVE);
7625
+ }
7626
+
7627
+ return val;
7628
+}
7629
+
7630
+static void vop2_post_color_swap(struct drm_crtc *crtc)
7631
+{
7632
+ struct vop2_video_port *vp = to_vop2_video_port(crtc);
7633
+ struct vop2 *vop2 = vp->vop2;
7634
+ struct rockchip_crtc_state *vcstate = to_rockchip_crtc_state(crtc->state);
7635
+ u32 output_if = vcstate->output_if;
7636
+ u32 data_swap = 0;
7637
+
7638
+ if (vop2_output_uv_swap(vcstate->bus_format, vcstate->output_mode) ||
7639
+ vop3_output_rb_swap(vcstate->bus_format, vcstate->output_mode))
7640
+ data_swap = DSP_RB_SWAP;
7641
+
7642
+ if (vop2->version == VOP_VERSION_RK3588 &&
7643
+ (output_if_is_hdmi(output_if) || output_if_is_dp(output_if)) &&
7644
+ (vcstate->bus_format == MEDIA_BUS_FMT_YUV8_1X24 ||
7645
+ vcstate->bus_format == MEDIA_BUS_FMT_YUV10_1X30))
7646
+ data_swap |= DSP_RG_SWAP;
7647
+
7648
+ VOP_MODULE_SET(vop2, vp, dsp_data_swap, data_swap);
50247649 }
50257650
50267651 /*
....@@ -5048,7 +7673,7 @@
50487673 static void vop3_setup_pipe_dly(struct vop2_video_port *vp, const struct vop2_zpos *vop2_zpos)
50497674 {
50507675 struct vop2 *vop2 = vp->vop2;
5051
- struct drm_crtc *crtc = &vp->crtc;
7676
+ struct drm_crtc *crtc = &vp->rockchip_crtc.crtc;
50527677 const struct vop2_zpos *zpos;
50537678 struct drm_plane *plane;
50547679 struct vop2_plane_state *vpstate;
....@@ -5127,12 +7752,14 @@
51277752 static void vop2_crtc_atomic_enable(struct drm_crtc *crtc, struct drm_crtc_state *old_state)
51287753 {
51297754 struct vop2_video_port *vp = to_vop2_video_port(crtc);
7755
+ struct vop2_video_port *splice_vp;
51307756 struct vop2 *vop2 = vp->vop2;
51317757 const struct vop2_data *vop2_data = vop2->data;
51327758 const struct vop2_video_port_data *vp_data = &vop2_data->vp[vp->id];
51337759 const struct vop_intr *intr = vp_data->intr;
51347760 struct rockchip_crtc_state *vcstate = to_rockchip_crtc_state(crtc->state);
51357761 struct drm_display_mode *adjusted_mode = &crtc->state->adjusted_mode;
7762
+ struct rockchip_dsc_sink_cap *dsc_sink_cap = &vcstate->dsc_sink_cap;
51367763 u16 hsync_len = adjusted_mode->crtc_hsync_end - adjusted_mode->crtc_hsync_start;
51377764 u16 hdisplay = adjusted_mode->crtc_hdisplay;
51387765 u16 htotal = adjusted_mode->crtc_htotal;
....@@ -5147,14 +7774,58 @@
51477774 bool dclk_inv, yc_swap = false;
51487775 int act_end;
51497776 uint32_t val;
7777
+ char clk_name[32];
7778
+ struct vop2_clk *if_pixclk = NULL;
7779
+ struct vop2_clk *if_dclk = NULL;
7780
+ struct vop2_clk *dclk, *dclk_out, *dclk_core;
7781
+ int splice_en = 0;
7782
+ int port_mux;
7783
+ int ret;
7784
+
7785
+ if (old_state && old_state->self_refresh_active) {
7786
+ vop2_crtc_atomic_exit_psr(crtc, old_state);
7787
+
7788
+ return;
7789
+ }
51507790
51517791 vop2->active_vp_mask |= BIT(vp->id);
51527792 vop2_set_system_status(vop2);
51537793
51547794 vop2_lock(vop2);
5155
- DRM_DEV_INFO(vop2->dev, "Update mode to %dx%d%s%d, type: %d for vp%d\n",
5156
- hdisplay, vdisplay, interlaced ? "i" : "p",
5157
- adjusted_mode->vrefresh, vcstate->output_type, vp->id);
7795
+ DRM_DEV_INFO(vop2->dev, "Update mode to %dx%d%s%d, type: %d(if:%x, flag:0x%x) for vp%d dclk: %llu\n",
7796
+ hdisplay, adjusted_mode->vdisplay, interlaced ? "i" : "p",
7797
+ drm_mode_vrefresh(adjusted_mode),
7798
+ vcstate->output_type, vcstate->output_if, vcstate->output_flags,
7799
+ vp->id, (unsigned long long)adjusted_mode->crtc_clock * 1000);
7800
+
7801
+ if (adjusted_mode->hdisplay > VOP2_MAX_VP_OUTPUT_WIDTH) {
7802
+ vcstate->splice_mode = true;
7803
+ splice_vp = &vop2->vps[vp_data->splice_vp_id];
7804
+ splice_vp->splice_mode_right = true;
7805
+ splice_vp->left_vp = vp;
7806
+ splice_en = 1;
7807
+ vop2->active_vp_mask |= BIT(splice_vp->id);
7808
+ }
7809
+
7810
+ if (vcstate->output_flags & ROCKCHIP_OUTPUT_DUAL_CONNECTOR_SPLIT_MODE)
7811
+ vcstate->output_flags |= ROCKCHIP_OUTPUT_DUAL_CHANNEL_LEFT_RIGHT_MODE;
7812
+
7813
+ if (vcstate->dsc_enable) {
7814
+ int k = 1;
7815
+
7816
+ if (vcstate->output_flags & ROCKCHIP_OUTPUT_DUAL_CHANNEL_LEFT_RIGHT_MODE)
7817
+ k = 2;
7818
+
7819
+ vcstate->dsc_id = vcstate->output_if & (VOP_OUTPUT_IF_MIPI0 | VOP_OUTPUT_IF_HDMI0) ? 0 : 1;
7820
+ vcstate->dsc_slice_num = hdisplay / dsc_sink_cap->slice_width / k;
7821
+ vcstate->dsc_pixel_num = vcstate->dsc_slice_num > 4 ? 4 : vcstate->dsc_slice_num;
7822
+
7823
+ vop2_calc_dsc_clk(crtc);
7824
+ DRM_DEV_INFO(vop2->dev, "Enable DSC%d slice:%dx%d, slice num:%d\n",
7825
+ vcstate->dsc_id, dsc_sink_cap->slice_width,
7826
+ dsc_sink_cap->slice_height, vcstate->dsc_slice_num);
7827
+ }
7828
+
51587829 vop2_initial(crtc);
51597830 vcstate->vdisplay = vdisplay;
51607831 vcstate->mode_update = vop2_crtc_mode_update(crtc);
....@@ -5165,26 +7836,51 @@
51657836 val = (adjusted_mode->flags & DRM_MODE_FLAG_NHSYNC) ? 0 : BIT(HSYNC_POSITIVE);
51667837 val |= (adjusted_mode->flags & DRM_MODE_FLAG_NVSYNC) ? 0 : BIT(VSYNC_POSITIVE);
51677838
7839
+ vp->output_if = vcstate->output_if;
7840
+
51687841 if (vcstate->output_if & VOP_OUTPUT_IF_RGB) {
7842
+ ret = vop2_calc_cru_cfg(crtc, VOP_OUTPUT_IF_RGB, &if_pixclk, &if_dclk);
7843
+ if (ret < 0)
7844
+ goto out;
7845
+
51697846 VOP_CTRL_SET(vop2, rgb_en, 1);
51707847 VOP_CTRL_SET(vop2, rgb_mux, vp_data->id);
51717848 VOP_CTRL_SET(vop2, rgb_pin_pol, val);
5172
- VOP_GRF_SET(vop2, grf_dclk_inv, dclk_inv);
7849
+ VOP_GRF_SET(vop2, sys_grf, grf_dclk_inv, dclk_inv);
51737850 }
51747851
51757852 if (vcstate->output_if & VOP_OUTPUT_IF_BT1120) {
5176
- VOP_CTRL_SET(vop2, rgb_en, 1);
5177
- VOP_CTRL_SET(vop2, bt1120_en, 1);
7853
+ ret = vop2_calc_cru_cfg(crtc, VOP_OUTPUT_IF_RGB, &if_pixclk, &if_dclk);
7854
+ if (ret < 0)
7855
+ goto out;
7856
+
7857
+ if (vop2->version == VOP_VERSION_RK3588) {
7858
+ VOP_CTRL_SET(vop2, bt1120_en, 3);
7859
+ } else {
7860
+ VOP_CTRL_SET(vop2, rgb_en, 1);
7861
+ VOP_CTRL_SET(vop2, bt1120_en, 1);
7862
+ }
51787863 VOP_CTRL_SET(vop2, rgb_mux, vp_data->id);
5179
- VOP_GRF_SET(vop2, grf_bt1120_clk_inv, !dclk_inv);
7864
+ VOP_GRF_SET(vop2, sys_grf, grf_bt1120_clk_inv, !dclk_inv);
7865
+ VOP_CTRL_SET(vop2, bt1120_dclk_pol, !dclk_inv);
51807866 yc_swap = vop2_output_yc_swap(vcstate->bus_format);
51817867 VOP_CTRL_SET(vop2, bt1120_yc_swap, yc_swap);
51827868 }
51837869
51847870 if (vcstate->output_if & VOP_OUTPUT_IF_BT656) {
5185
- VOP_CTRL_SET(vop2, bt656_en, 1);
7871
+ ret = vop2_calc_cru_cfg(crtc, VOP_OUTPUT_IF_RGB, &if_pixclk, &if_dclk);
7872
+ if (ret < 0)
7873
+ goto out;
7874
+
7875
+ if (vop2->version == VOP_VERSION_RK3588) {
7876
+ VOP_CTRL_SET(vop2, bt656_en, 1);
7877
+ } else {
7878
+ VOP_CTRL_SET(vop2, rgb_en, 1);
7879
+ VOP_CTRL_SET(vop2, bt656_en, 1);
7880
+ }
51867881 VOP_CTRL_SET(vop2, rgb_mux, vp_data->id);
5187
- VOP_GRF_SET(vop2, grf_bt656_clk_inv, !dclk_inv);
7882
+ VOP_GRF_SET(vop2, sys_grf, grf_bt656_clk_inv, !dclk_inv);
7883
+ VOP_CTRL_SET(vop2, bt656_dclk_pol, !dclk_inv);
51887884 yc_swap = vop2_output_yc_swap(vcstate->bus_format);
51897885 VOP_CTRL_SET(vop2, bt656_yc_swap, yc_swap);
51907886 }
....@@ -5203,18 +7899,19 @@
52037899 VOP_CTRL_SET(vop2, lvds_dclk_pol, dclk_inv);
52047900 }
52057901
5206
- if (vcstate->output_flags & (ROCKCHIP_OUTPUT_DUAL_CHANNEL_ODD_EVEN_MODE |
5207
- ROCKCHIP_OUTPUT_DUAL_CHANNEL_LEFT_RIGHT_MODE)) {
5208
- VOP_CTRL_SET(vop2, lvds_dual_en, 1);
5209
- if (vcstate->output_flags & ROCKCHIP_OUTPUT_DUAL_CHANNEL_LEFT_RIGHT_MODE)
5210
- VOP_CTRL_SET(vop2, lvds_dual_mode, 1);
5211
- if (vcstate->output_flags & ROCKCHIP_OUTPUT_DATA_SWAP)
5212
- VOP_CTRL_SET(vop2, lvds_dual_channel_swap, 1);
5213
- }
5214
-
52157902 if (vcstate->output_if & VOP_OUTPUT_IF_MIPI0) {
7903
+ ret = vop2_calc_cru_cfg(crtc, VOP_OUTPUT_IF_MIPI0, &if_pixclk, &if_dclk);
7904
+ if (ret < 0)
7905
+ goto out;
7906
+ if (if_pixclk)
7907
+ VOP_CTRL_SET(vop2, mipi0_pixclk_div, if_pixclk->div_val);
7908
+
7909
+ if (vcstate->output_flags & ROCKCHIP_OUTPUT_MIPI_DS_MODE)
7910
+ VOP_CTRL_SET(vop2, mipi0_ds_mode, 1);
7911
+
7912
+ port_mux = vop2_get_mipi_port_mux(vop2, vp_data->id);
52167913 VOP_CTRL_SET(vop2, mipi0_en, 1);
5217
- VOP_CTRL_SET(vop2, mipi0_mux, vp_data->id);
7914
+ VOP_CTRL_SET(vop2, mipi0_mux, port_mux);
52187915 VOP_CTRL_SET(vop2, mipi_pin_pol, val);
52197916 VOP_CTRL_SET(vop2, mipi_dclk_pol, dclk_inv);
52207917 if (vcstate->hold_mode) {
....@@ -5224,8 +7921,19 @@
52247921 }
52257922
52267923 if (vcstate->output_if & VOP_OUTPUT_IF_MIPI1) {
7924
+ ret = vop2_calc_cru_cfg(crtc, VOP_OUTPUT_IF_MIPI1, &if_pixclk, &if_dclk);
7925
+ if (ret < 0)
7926
+ goto out;
7927
+ if (if_pixclk)
7928
+ VOP_CTRL_SET(vop2, mipi1_pixclk_div, if_pixclk->div_val);
7929
+
7930
+ if (vcstate->output_flags & ROCKCHIP_OUTPUT_MIPI_DS_MODE)
7931
+ VOP_CTRL_SET(vop2, mipi1_ds_mode, 1);
7932
+
7933
+ port_mux = vop2_get_mipi_port_mux(vop2, vp_data->id);
7934
+
52277935 VOP_CTRL_SET(vop2, mipi1_en, 1);
5228
- VOP_CTRL_SET(vop2, mipi1_mux, vp_data->id);
7936
+ VOP_CTRL_SET(vop2, mipi1_mux, port_mux);
52297937 VOP_CTRL_SET(vop2, mipi_pin_pol, val);
52307938 VOP_CTRL_SET(vop2, mipi_dclk_pol, dclk_inv);
52317939 if (vcstate->hold_mode) {
....@@ -5234,41 +7942,79 @@
52347942 }
52357943 }
52367944
5237
- if (vcstate->output_flags & ROCKCHIP_OUTPUT_DUAL_CHANNEL_LEFT_RIGHT_MODE) {
5238
- VOP_MODULE_SET(vop2, vp, mipi_dual_en, 1);
5239
- if (vcstate->output_flags & ROCKCHIP_OUTPUT_DATA_SWAP)
5240
- VOP_MODULE_SET(vop2, vp, mipi_dual_channel_swap, 1);
5241
- }
7945
+ if (vcstate->output_flags & ROCKCHIP_OUTPUT_DUAL_CHANNEL_LEFT_RIGHT_MODE ||
7946
+ vcstate->output_flags & ROCKCHIP_OUTPUT_DUAL_CHANNEL_ODD_EVEN_MODE)
7947
+ vop2_setup_dual_channel_if(crtc);
52427948
52437949 if (vcstate->output_if & VOP_OUTPUT_IF_eDP0) {
7950
+ ret = vop2_calc_cru_cfg(crtc, VOP_OUTPUT_IF_eDP0, &if_pixclk, &if_dclk);
7951
+ if (ret < 0)
7952
+ goto out;
7953
+ if (if_pixclk && if_dclk) {
7954
+ VOP_CTRL_SET(vop2, edp0_pixclk_div, if_pixclk->div_val);
7955
+ VOP_CTRL_SET(vop2, edp0_dclk_div, if_dclk->div_val);
7956
+ }
7957
+
52447958 VOP_CTRL_SET(vop2, edp0_en, 1);
52457959 VOP_CTRL_SET(vop2, edp0_mux, vp_data->id);
52467960 VOP_CTRL_SET(vop2, edp_pin_pol, val);
52477961 VOP_CTRL_SET(vop2, edp_dclk_pol, dclk_inv);
7962
+ VOP_GRF_SET(vop2, grf, grf_edp0_en, 1);
52487963 }
52497964
52507965 if (vcstate->output_if & VOP_OUTPUT_IF_eDP1) {
7966
+ ret = vop2_calc_cru_cfg(crtc, VOP_OUTPUT_IF_eDP1, &if_pixclk, &if_dclk);
7967
+ if (ret < 0)
7968
+ goto out;
7969
+ if (if_pixclk && if_dclk) {
7970
+ VOP_CTRL_SET(vop2, edp1_pixclk_div, if_pixclk->div_val);
7971
+ VOP_CTRL_SET(vop2, edp1_dclk_div, if_dclk->div_val);
7972
+ }
7973
+
52517974 VOP_CTRL_SET(vop2, edp1_en, 1);
52527975 VOP_CTRL_SET(vop2, edp1_mux, vp_data->id);
52537976 VOP_CTRL_SET(vop2, edp_pin_pol, val);
52547977 VOP_CTRL_SET(vop2, edp_dclk_pol, dclk_inv);
7978
+ VOP_GRF_SET(vop2, grf, grf_edp1_en, 1);
52557979 }
52567980
52577981 if (vcstate->output_if & VOP_OUTPUT_IF_DP0) {
7982
+ ret = vop2_calc_cru_cfg(crtc, VOP_OUTPUT_IF_DP0, &if_pixclk, &if_dclk);
7983
+ if (ret < 0)
7984
+ goto out;
52587985 VOP_CTRL_SET(vop2, dp0_en, 1);
52597986 VOP_CTRL_SET(vop2, dp0_mux, vp_data->id);
5260
- VOP_CTRL_SET(vop2, dp_dclk_pol, 0);
5261
- VOP_CTRL_SET(vop2, dp_pin_pol, val);
7987
+ VOP_CTRL_SET(vop2, dp0_dclk_pol, 0);
7988
+ VOP_CTRL_SET(vop2, dp0_pin_pol, val);
52627989 }
52637990
52647991 if (vcstate->output_if & VOP_OUTPUT_IF_DP1) {
7992
+ ret = vop2_calc_cru_cfg(crtc, VOP_OUTPUT_IF_DP0, &if_pixclk, &if_dclk);
7993
+ if (ret < 0)
7994
+ goto out;
7995
+
52657996 VOP_CTRL_SET(vop2, dp1_en, 1);
52667997 VOP_CTRL_SET(vop2, dp1_mux, vp_data->id);
5267
- VOP_CTRL_SET(vop2, dp_dclk_pol, 0);
5268
- VOP_CTRL_SET(vop2, dp_pin_pol, val);
7998
+ VOP_CTRL_SET(vop2, dp1_dclk_pol, 0);
7999
+ VOP_CTRL_SET(vop2, dp1_pin_pol, val);
52698000 }
52708001
52718002 if (vcstate->output_if & VOP_OUTPUT_IF_HDMI0) {
8003
+ ret = vop2_calc_cru_cfg(crtc, VOP_OUTPUT_IF_HDMI0, &if_pixclk, &if_dclk);
8004
+ if (ret < 0)
8005
+ goto out;
8006
+ if (if_pixclk && if_dclk) {
8007
+ VOP_CTRL_SET(vop2, hdmi0_pixclk_div, if_pixclk->div_val);
8008
+ VOP_CTRL_SET(vop2, hdmi0_dclk_div, if_dclk->div_val);
8009
+ }
8010
+
8011
+ if (vcstate->dsc_enable)
8012
+ VOP_GRF_SET(vop2, grf, grf_hdmi0_dsc_en, 1);
8013
+
8014
+ val = vop2_get_hdmi_pol(vop2, adjusted_mode->flags);
8015
+ VOP_GRF_SET(vop2, grf, grf_hdmi0_en, 1);
8016
+ VOP_GRF_SET(vop2, vo1_grf, grf_hdmi0_pin_pol, val);
8017
+
52728018 VOP_CTRL_SET(vop2, hdmi0_en, 1);
52738019 VOP_CTRL_SET(vop2, hdmi0_mux, vp_data->id);
52748020 VOP_CTRL_SET(vop2, hdmi_pin_pol, val);
....@@ -5276,11 +8022,29 @@
52768022 }
52778023
52788024 if (vcstate->output_if & VOP_OUTPUT_IF_HDMI1) {
8025
+ ret = vop2_calc_cru_cfg(crtc, VOP_OUTPUT_IF_HDMI1, &if_pixclk, &if_dclk);
8026
+ if (ret < 0)
8027
+ goto out;
8028
+
8029
+ if (if_pixclk && if_dclk) {
8030
+ VOP_CTRL_SET(vop2, hdmi1_pixclk_div, if_pixclk->div_val);
8031
+ VOP_CTRL_SET(vop2, hdmi1_dclk_div, if_dclk->div_val);
8032
+ }
8033
+
8034
+ if (vcstate->dsc_enable)
8035
+ VOP_GRF_SET(vop2, grf, grf_hdmi1_dsc_en, 1);
8036
+
8037
+ val = vop2_get_hdmi_pol(vop2, adjusted_mode->flags);
8038
+ VOP_GRF_SET(vop2, grf, grf_hdmi1_en, 1);
8039
+ VOP_GRF_SET(vop2, vo1_grf, grf_hdmi1_pin_pol, val);
8040
+
52798041 VOP_CTRL_SET(vop2, hdmi1_en, 1);
52808042 VOP_CTRL_SET(vop2, hdmi1_mux, vp_data->id);
52818043 VOP_CTRL_SET(vop2, hdmi_pin_pol, val);
52828044 VOP_CTRL_SET(vop2, hdmi_dclk_pol, 1);
52838045 }
8046
+
8047
+ VOP_MODULE_SET(vop2, vp, splice_en, splice_en);
52848048
52858049 VOP_MODULE_SET(vop2, vp, htotal_pw, (htotal << 16) | hsync_len);
52868050 val = hact_st << 16;
....@@ -5318,7 +8082,13 @@
53188082 VOP_INTR_SET(vop2, intr, line_flag_num[0], act_end);
53198083 VOP_INTR_SET(vop2, intr, line_flag_num[1], act_end);
53208084
5321
- VOP_MODULE_SET(vop2, vp, vtotal_pw, vtotal << 16 | vsync_len);
8085
+ VOP_MODULE_SET(vop2, vp, dsp_vtotal, vtotal);
8086
+ VOP_MODULE_SET(vop2, vp, dsp_vs_end, vsync_len);
8087
+ /**
8088
+ * when display interface support vrr, config vtotal valid immediately
8089
+ */
8090
+ if (vcstate->max_refresh_rate && vcstate->min_refresh_rate)
8091
+ VOP_MODULE_SET(vop2, vp, sw_dsp_vtotal_imd, 1);
53228092
53238093 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK ||
53248094 vcstate->output_if & VOP_OUTPUT_IF_BT656)
....@@ -5334,21 +8104,65 @@
53348104 VOP_MODULE_SET(vop2, vp, dclk_div2_phase_lock, 0);
53358105 }
53368106
5337
- /*
5338
- * For RK3528, the path of CVBS output is like:
5339
- * VOP BT656 ENCODER -> CVBS BT656 DECODER -> CVBS ENCODER -> CVBS VDAC
5340
- * The vop2 dclk should be four times crtc_clock for CVBS sampling clock needs.
8107
+ snprintf(clk_name, sizeof(clk_name), "dclk_out%d", vp->id);
8108
+ dclk_out = vop2_clk_get(vop2, clk_name);
8109
+ snprintf(clk_name, sizeof(clk_name), "dclk_core%d", vp->id);
8110
+ dclk_core = vop2_clk_get(vop2, clk_name);
8111
+ if (dclk_out && dclk_core) {
8112
+ DRM_DEV_INFO(vop2->dev, "%s div: %d %s div: %d\n",
8113
+ __clk_get_name(dclk_out->hw.clk), dclk_out->div_val,
8114
+ __clk_get_name(dclk_core->hw.clk), dclk_core->div_val);
8115
+ VOP_MODULE_SET(vop2, vp, dclk_src_sel, 0);
8116
+ VOP_MODULE_SET(vop2, vp, dclk_out_div, dclk_out->div_val);
8117
+ VOP_MODULE_SET(vop2, vp, dclk_core_div, dclk_core->div_val);
8118
+ }
8119
+
8120
+ snprintf(clk_name, sizeof(clk_name), "dclk%d", vp->id);
8121
+ dclk = vop2_clk_get(vop2, clk_name);
8122
+ if (dclk) {
8123
+ /*
8124
+ * use HDMI_PHY_PLL as dclk source under 4K@60 if it is available,
8125
+ * otherwise use system cru as dclk source.
8126
+ */
8127
+ ret = vop2_clk_set_parent_extend(vp, vcstate, true);
8128
+ if (ret < 0)
8129
+ goto out;
8130
+
8131
+ rockchip_drm_dclk_set_rate(vop2->version, vp->dclk, dclk->rate);
8132
+ DRM_DEV_INFO(vop2->dev, "set %s to %ld, get %ld\n",
8133
+ __clk_get_name(vp->dclk), dclk->rate, clk_get_rate(vp->dclk));
8134
+ } else {
8135
+ rockchip_drm_dclk_set_rate(vop2->version, vp->dclk,
8136
+ adjusted_mode->crtc_clock * 1000);
8137
+ }
8138
+
8139
+ if (vp_data->feature & VOP_FEATURE_OVERSCAN)
8140
+ vop2_post_config(crtc);
8141
+
8142
+ VOP_MODULE_SET(vop2, vp, almost_full_or_en, 1);
8143
+ VOP_MODULE_SET(vop2, vp, line_flag_or_en, 1);
8144
+ if (vcstate->dsc_enable) {
8145
+ if (vcstate->output_flags & ROCKCHIP_OUTPUT_DUAL_CHANNEL_LEFT_RIGHT_MODE) {
8146
+ vop2_crtc_enable_dsc(crtc, old_state, 0);
8147
+ vop2_crtc_enable_dsc(crtc, old_state, 1);
8148
+ } else {
8149
+ vop2_crtc_enable_dsc(crtc, old_state, vcstate->dsc_id);
8150
+ }
8151
+ }
8152
+ /* For RK3588, the reset value of background is 0xa0080200,
8153
+ * which will enable background and output a grey image. But
8154
+ * the reset value is just valid in first frame and disable
8155
+ * in follow frames. If the panel backlight is valid before
8156
+ * follow frames. The screen may flick a grey image. To avoid
8157
+ * this phenomenon appear, setting black background after
8158
+ * reset vop
53418159 */
5342
- if (vop2->version == VOP_VERSION_RK3528 && vcstate->output_if & VOP_OUTPUT_IF_BT656)
5343
- clk_set_rate(vp->dclk, 4 * adjusted_mode->crtc_clock * 1000);
5344
- else
5345
- clk_set_rate(vp->dclk, adjusted_mode->crtc_clock * 1000);
5346
-
5347
- vop2_post_config(crtc);
5348
-
8160
+ if (vop2->version == VOP_VERSION_RK3588)
8161
+ VOP_MODULE_SET(vop2, vp, dsp_background, 0x80000000);
53498162 if (is_vop3(vop2))
53508163 vop3_setup_pipe_dly(vp, NULL);
53518164
8165
+ vop2_crtc_csu_set_rate(crtc);
53528166 vop2_cfg_done(crtc);
53538167
53548168 /*
....@@ -5368,14 +8182,49 @@
53688182 */
53698183 VOP_MODULE_SET(vop2, vp, standby, 0);
53708184
5371
- drm_crtc_vblank_on(crtc);
8185
+ if (vp->mcu_timing.mcu_pix_total) {
8186
+ vop3_set_out_mode(crtc, vcstate->output_mode);
8187
+ vop3_mcu_mode_setup(crtc);
8188
+ }
53728189
8190
+ if (!vp->loader_protect)
8191
+ vop2_clk_reset(vp->dclk_rst);
8192
+ if (vcstate->dsc_enable)
8193
+ rk3588_vop2_dsc_cfg_done(crtc);
8194
+ drm_crtc_vblank_on(crtc);
53738195 /*
53748196 * restore the lut table.
53758197 */
5376
- if (vp->gamma_lut_active)
8198
+ if (vp->gamma_lut_active) {
53778199 vop2_crtc_load_lut(crtc);
8200
+ vop2_cfg_done(crtc);
8201
+ vop2_wait_for_fs_by_done_bit_status(vp);
8202
+ }
53788203
8204
+ /*
8205
+ * In RK3588 VOP, HDMI1/eDP1 MUX1 module's reset signal should be released
8206
+ * when PD_VOP turn on. If this reset signal is not be released, the HDMI1
8207
+ * or eDP1 output interface can't work normally.
8208
+ * However, If the deassert signal want to transfer to HDMI1/eDP1 MUX1 and
8209
+ * take effect, it need the video port0 dclk's source clk work a few moment.
8210
+ * In some cases, the video port0 dclk's source clk is disabled(now only the
8211
+ * hdmi0/1 phy pll as the dclk source parent will appear) after PD_VOP turn
8212
+ * on, for example, vidoe port0 dclk source select hdmi phy pll. To fix
8213
+ * this issue, enable video port0 dclk for a few monent when active a video
8214
+ * port which attach to eDP1/HDMI1.
8215
+ */
8216
+ if (vop2->version == VOP_VERSION_RK3588) {
8217
+ if (vp->id != 0 && (vp->output_if & (VOP_OUTPUT_IF_eDP1 | VOP_OUTPUT_IF_HDMI1))) {
8218
+ struct vop2_video_port *vp0 = &vop2->vps[0];
8219
+
8220
+ clk_prepare_enable(vp0->dclk);
8221
+ if (!clk_get_rate(vp0->dclk))
8222
+ clk_set_rate(vp0->dclk, 148500000);
8223
+ udelay(20);
8224
+ clk_disable_unprepare(vp0->dclk);
8225
+ }
8226
+ }
8227
+out:
53798228 vop2_unlock(vop2);
53808229 }
53818230
....@@ -5393,6 +8242,30 @@
53938242 static int vop2_crtc_atomic_check(struct drm_crtc *crtc,
53948243 struct drm_crtc_state *crtc_state)
53958244 {
8245
+ struct vop2_video_port *vp = to_vop2_video_port(crtc);
8246
+ struct vop2_video_port *splice_vp;
8247
+ struct vop2 *vop2 = vp->vop2;
8248
+ const struct vop2_data *vop2_data = vop2->data;
8249
+ const struct vop2_video_port_data *vp_data = &vop2_data->vp[vp->id];
8250
+ struct rockchip_crtc_state *vcstate = to_rockchip_crtc_state(crtc->state);
8251
+ struct rockchip_crtc_state *new_vcstate = to_rockchip_crtc_state(crtc_state);
8252
+ struct drm_display_mode *adjusted_mode = &crtc->state->adjusted_mode;
8253
+
8254
+ if (vop2_has_feature(vop2, VOP_FEATURE_SPLICE)) {
8255
+ if (adjusted_mode->hdisplay > VOP2_MAX_VP_OUTPUT_WIDTH) {
8256
+ vcstate->splice_mode = true;
8257
+ splice_vp = &vop2->vps[vp_data->splice_vp_id];
8258
+ splice_vp->splice_mode_right = true;
8259
+ splice_vp->left_vp = vp;
8260
+ }
8261
+ }
8262
+
8263
+ if ((vcstate->request_refresh_rate != new_vcstate->request_refresh_rate) ||
8264
+ crtc_state->active_changed || crtc_state->mode_changed)
8265
+ vp->refresh_rate_change = true;
8266
+ else
8267
+ vp->refresh_rate_change = false;
8268
+
53968269 return 0;
53978270 }
53988271
....@@ -5427,12 +8300,13 @@
54278300 struct drm_plane *plane = &win->base;
54288301 struct drm_plane_state *pstate = plane->state;
54298302 struct vop2_plane_state *vpstate = to_vop2_plane_state(pstate);
5430
- struct drm_crtc_state *cstate = vp->crtc.state;
8303
+ struct drm_crtc_state *cstate = vp->rockchip_crtc.crtc.state;
54318304 struct rockchip_crtc_state *vcstate = to_rockchip_crtc_state(cstate);
54328305 unsigned long win_mask = vp->win_mask;
54338306 int phys_id;
54348307 struct hdrvivid_regs *hdrvivid_data;
54358308 struct hdr_extend *hdr_data;
8309
+ struct rockchip_gem_object *lut_gem_obj;
54368310 bool have_sdr_layer = false;
54378311 uint32_t hdr_mode;
54388312 int i;
....@@ -5463,7 +8337,7 @@
54638337 if (hdr_mode == SDR2HLG_USERSPACE)
54648338 hdr_mode = SDR2HLG;
54658339
5466
- if (hdr_mode <= HDR102SDR && vpstate->eotf != SMPTE_ST2084 && vpstate->eotf != HLG) {
8340
+ if (hdr_mode <= HDR102SDR && vpstate->eotf != HDMI_EOTF_SMPTE_ST2084 && vpstate->eotf != HDMI_EOTF_BT_2100_HLG) {
54678341 DRM_ERROR("Invalid HDR mode:%d, mismatch plane eotf:%d\n", hdr_mode,
54688342 vpstate->eotf);
54698343 return;
....@@ -5493,7 +8367,8 @@
54938367 if (!vop2_plane_active(pstate))
54948368 continue;
54958369
5496
- if (vpstate->eotf != SMPTE_ST2084 && vpstate->eotf != HLG) {
8370
+ if (vpstate->eotf != HDMI_EOTF_SMPTE_ST2084 &&
8371
+ vpstate->eotf != HDMI_EOTF_BT_2100_HLG) {
54978372 have_sdr_layer = true;
54988373 break;
54998374 }
....@@ -5546,6 +8421,16 @@
55468421 vop2_writel(vop2, RK3528_HDR_CSC_COE20_21, hdrvivid_data->hdr_csc_coe20_21);
55478422 vop2_writel(vop2, RK3528_HDR_CSC_COE22, hdrvivid_data->hdr_csc_coe22);
55488423
8424
+ if (!vp->hdr_lut_gem_obj) {
8425
+ lut_gem_obj = rockchip_gem_create_object(vop2->drm_dev,
8426
+ RK_HDRVIVID_TONE_SCA_AXI_TAB_LENGTH * 4, true, 0);
8427
+ if (IS_ERR(lut_gem_obj)) {
8428
+ DRM_ERROR("create hdr lut obj failed\n");
8429
+ return;
8430
+ }
8431
+ vp->hdr_lut_gem_obj = lut_gem_obj;
8432
+ }
8433
+
55498434 tone_lut_kvaddr = (u32 *)vp->hdr_lut_gem_obj->kvaddr;
55508435 tone_lut_mst = vp->hdr_lut_gem_obj->dma_addr;
55518436
....@@ -5583,7 +8468,7 @@
55838468
55848469 static void vop3_setup_dynamic_hdr(struct vop2_video_port *vp, uint8_t win_phys_id)
55858470 {
5586
- struct drm_crtc_state *cstate = vp->crtc.state;
8471
+ struct drm_crtc_state *cstate = vp->rockchip_crtc.crtc.state;
55878472 struct rockchip_crtc_state *vcstate = to_rockchip_crtc_state(cstate);
55888473 struct hdr_extend *hdr_data;
55898474 uint32_t hdr_format;
....@@ -5619,13 +8504,13 @@
56198504 struct vop2 *vop2 = vp->vop2;
56208505 struct vop2_win *win = vop2_find_win_by_phys_id(vop2, win_phys_id);
56218506 struct drm_plane *plane = &win->base;
5622
- struct drm_plane_state *pstate = plane->state;
5623
- struct vop2_plane_state *vpstate = to_vop2_plane_state(pstate);
5624
- struct drm_crtc_state *cstate = vp->crtc.state;
5625
- struct rockchip_crtc_state *vcstate = to_rockchip_crtc_state(cstate);
8507
+ struct drm_plane_state *pstate;
8508
+ struct drm_crtc_state *cstate = vp->rockchip_crtc.crtc.state;
56268509 const struct vop2_data *vop2_data = vop2->data;
56278510 const struct vop2_video_port_data *vp_data = &vop2_data->vp[vp->id];
56288511 const struct vop_hdr_table *hdr_table = vp_data->hdr_table;
8512
+ struct rockchip_crtc_state *vcstate;
8513
+ struct vop2_plane_state *vpstate;
56298514 uint32_t lut_mode = VOP2_HDR_LUT_MODE_AHB;
56308515 uint32_t sdr2hdr_r2r_mode = 0;
56318516 bool hdr_en = 0;
....@@ -5645,14 +8530,27 @@
56458530 return;
56468531
56478532 /*
8533
+ * right vp share the same crtc/plane state in splice mode
8534
+ */
8535
+ if (vp->splice_mode_right) {
8536
+ vcstate = to_rockchip_crtc_state(vp->left_vp->rockchip_crtc.crtc.state);
8537
+ pstate = win->left_win->base.state;
8538
+ } else {
8539
+ vcstate = to_rockchip_crtc_state(cstate);
8540
+ pstate = plane->state;
8541
+ }
8542
+
8543
+ vpstate = to_vop2_plane_state(pstate);
8544
+
8545
+ /*
56488546 * HDR video plane input
56498547 */
5650
- if (vpstate->eotf == SMPTE_ST2084)
8548
+ if (vpstate->eotf == HDMI_EOTF_SMPTE_ST2084)
56518549 hdr_en = 1;
56528550
56538551 vp->hdr_en = hdr_en;
56548552 vp->hdr_in = hdr_en;
5655
- vp->hdr_out = (vcstate->eotf == SMPTE_ST2084) ? true : false;
8553
+ vp->hdr_out = (vcstate->eotf == HDMI_EOTF_SMPTE_ST2084) ? true : false;
56568554
56578555 /*
56588556 * only laryer0 support hdr2sdr
....@@ -5670,15 +8568,21 @@
56708568 */
56718569 for_each_set_bit(phys_id, &win_mask, ROCKCHIP_MAX_LAYER) {
56728570 win = vop2_find_win_by_phys_id(vop2, phys_id);
5673
- plane = &win->base;
5674
- pstate = plane->state;
5675
- vpstate = to_vop2_plane_state(pstate);
8571
+ if (vp->splice_mode_right) {
8572
+ if (win->left_win)
8573
+ pstate = win->left_win->base.state;
8574
+ else
8575
+ pstate = NULL; /* this win is not activated */
8576
+ } else {
8577
+ pstate = win->base.state;
8578
+ }
56768579
5677
- /* skip inactive plane */
8580
+ vpstate = pstate ? to_vop2_plane_state(pstate) : NULL;
8581
+
56788582 if (!vop2_plane_active(pstate))
56798583 continue;
56808584
5681
- if (vpstate->eotf != SMPTE_ST2084) {
8585
+ if (vpstate->eotf != HDMI_EOTF_SMPTE_ST2084) {
56828586 have_sdr_layer = true;
56838587 break;
56848588 }
....@@ -5825,7 +8729,15 @@
58258729
58268730 if (!sub_win) {
58278731 /* At one win mode, win0 is dst/bottom win, and win1 is a all zero src/top win */
5828
- plane = &main_win->base;
8732
+
8733
+ /*
8734
+ * right cluster share the same plane state in splice mode
8735
+ */
8736
+ if (cluster->splice_mode)
8737
+ plane = &main_win->left_win->base;
8738
+ else
8739
+ plane = &main_win->base;
8740
+
58298741 top_win_vpstate = NULL;
58308742 bottom_win_vpstate = to_vop2_plane_state(plane->state);
58318743 src_glb_alpha_val = 0;
....@@ -5884,25 +8796,35 @@
58848796 uint32_t dst_color_ctrl_offset = vop2->data->ctrl->dst_color_ctrl.offset;
58858797 uint32_t src_alpha_ctrl_offset = vop2->data->ctrl->src_alpha_ctrl.offset;
58868798 uint32_t dst_alpha_ctrl_offset = vop2->data->ctrl->dst_alpha_ctrl.offset;
8799
+ unsigned long win_mask = vp->win_mask;
58878800 const struct vop2_zpos *zpos;
5888
- struct drm_framebuffer *fb;
8801
+ struct vop2_plane_state *vpstate;
58898802 struct vop2_alpha_config alpha_config;
58908803 struct vop2_alpha alpha;
58918804 struct vop2_win *win;
5892
- struct drm_plane *plane;
5893
- struct vop2_plane_state *vpstate;
8805
+ struct drm_plane_state *pstate;
8806
+ struct drm_framebuffer *fb;
58948807 int pixel_alpha_en;
5895
- int premulti_en;
8808
+ int premulti_en = 1;
58968809 int mixer_id;
8810
+ int phys_id;
58978811 uint32_t offset;
58988812 int i;
58998813 bool bottom_layer_alpha_en = false;
59008814 u32 dst_global_alpha = 0xff;
59018815
5902
- drm_atomic_crtc_for_each_plane(plane, &vp->crtc) {
5903
- struct vop2_win *win = to_vop2_win(plane);
8816
+ for_each_set_bit(phys_id, &win_mask, ROCKCHIP_MAX_LAYER) {
8817
+ win = vop2_find_win_by_phys_id(vop2, phys_id);
8818
+ if (win->splice_mode_right)
8819
+ pstate = win->left_win->base.state;
8820
+ else
8821
+ pstate = win->base.state;
59048822
5905
- vpstate = to_vop2_plane_state(plane->state);
8823
+ vpstate = to_vop2_plane_state(pstate);
8824
+
8825
+ if (!vop2_plane_active(pstate))
8826
+ continue;
8827
+
59068828 if (vpstate->zpos == 0 && vpstate->global_alpha != 0xff &&
59078829 !vop2_cluster_window(win)) {
59088830 /*
....@@ -5912,19 +8834,33 @@
59128834 */
59138835 bottom_layer_alpha_en = true;
59148836 dst_global_alpha = vpstate->global_alpha;
8837
+ if (pstate->pixel_blend_mode == DRM_MODE_BLEND_PREMULTI)
8838
+ premulti_en = 1;
8839
+ else
8840
+ premulti_en = 0;
8841
+
59158842 break;
59168843 }
59178844 }
59188845
59198846 mixer_id = vop2_find_start_mixer_id_for_vp(vop2, vp->id);
8847
+
8848
+ if (vop2->version == VOP_VERSION_RK3588 &&
8849
+ vp->hdr10_at_splice_mode && vp->id == 0)
8850
+ mixer_id++;/* fixed path for rk3588: layer1 -> hdr10_1 */
8851
+
59208852 alpha_config.dst_pixel_alpha_en = true; /* alpha value need transfer to next mix */
59218853 for (i = 1; i < vp->nr_layers; i++) {
59228854 zpos = &vop2_zpos[i];
59238855 win = vop2_find_win_by_phys_id(vop2, zpos->win_phys_id);
5924
- plane = &win->base;
5925
- vpstate = to_vop2_plane_state(plane->state);
5926
- fb = plane->state->fb;
5927
- if (plane->state->pixel_blend_mode == DRM_MODE_BLEND_PREMULTI)
8856
+ if (win->splice_mode_right)
8857
+ pstate = win->left_win->base.state;
8858
+ else
8859
+ pstate = win->base.state;
8860
+
8861
+ vpstate = to_vop2_plane_state(pstate);
8862
+ fb = pstate->fb;
8863
+ if (pstate->pixel_blend_mode == DRM_MODE_BLEND_PREMULTI)
59288864 premulti_en = 1;
59298865 else
59308866 premulti_en = 0;
....@@ -5954,29 +8890,27 @@
59548890 vop2_writel(vop2, dst_color_ctrl_offset + offset, alpha.dst_color_ctrl.val);
59558891 vop2_writel(vop2, src_alpha_ctrl_offset + offset, alpha.src_alpha_ctrl.val);
59568892 vop2_writel(vop2, dst_alpha_ctrl_offset + offset, alpha.dst_alpha_ctrl.val);
8893
+ }
59578894
5958
- if (i == 1) {
5959
- if (bottom_layer_alpha_en || vp->hdr_en) {
5960
- /* Transfer pixel alpha to hdr mix */
5961
- alpha_config.src_premulti_en = premulti_en;
5962
- alpha_config.dst_premulti_en = true;
5963
- alpha_config.src_pixel_alpha_en = true;
5964
- alpha_config.src_glb_alpha_value = 0xff;
5965
- alpha_config.dst_glb_alpha_value = 0xff;
5966
- vop2_parse_alpha(&alpha_config, &alpha);
8895
+ if (bottom_layer_alpha_en || vp->hdr_en) {
8896
+ /* Transfer pixel alpha to hdr mix */
8897
+ alpha_config.src_premulti_en = premulti_en;
8898
+ alpha_config.dst_premulti_en = true;
8899
+ alpha_config.src_pixel_alpha_en = true;
8900
+ alpha_config.src_glb_alpha_value = 0xff;
8901
+ alpha_config.dst_glb_alpha_value = 0xff;
8902
+ vop2_parse_alpha(&alpha_config, &alpha);
59678903
5968
- VOP_MODULE_SET(vop2, vp, hdr_src_color_ctrl,
5969
- alpha.src_color_ctrl.val);
5970
- VOP_MODULE_SET(vop2, vp, hdr_dst_color_ctrl,
5971
- alpha.dst_color_ctrl.val);
5972
- VOP_MODULE_SET(vop2, vp, hdr_src_alpha_ctrl,
5973
- alpha.src_alpha_ctrl.val);
5974
- VOP_MODULE_SET(vop2, vp, hdr_dst_alpha_ctrl,
5975
- alpha.dst_alpha_ctrl.val);
5976
- } else {
5977
- VOP_MODULE_SET(vop2, vp, hdr_src_color_ctrl, 0);
5978
- }
5979
- }
8904
+ VOP_MODULE_SET(vop2, vp, hdr_src_color_ctrl,
8905
+ alpha.src_color_ctrl.val);
8906
+ VOP_MODULE_SET(vop2, vp, hdr_dst_color_ctrl,
8907
+ alpha.dst_color_ctrl.val);
8908
+ VOP_MODULE_SET(vop2, vp, hdr_src_alpha_ctrl,
8909
+ alpha.src_alpha_ctrl.val);
8910
+ VOP_MODULE_SET(vop2, vp, hdr_dst_alpha_ctrl,
8911
+ alpha.dst_alpha_ctrl.val);
8912
+ } else {
8913
+ VOP_MODULE_SET(vop2, vp, hdr_src_color_ctrl, 0);
59808914 }
59818915
59828916 /* Transfer pixel alpha value to next mix */
....@@ -6137,21 +9071,6 @@
61379071 VOP_MODULE_SET(vop2, vp, bg_mix_ctrl, bg_alpha_ctrl.val);
61389072 }
61399073
6140
-static void vop2_setup_port_mux(struct vop2_video_port *vp, uint16_t port_mux_cfg)
6141
-{
6142
- struct vop2 *vop2 = vp->vop2;
6143
-
6144
- spin_lock(&vop2->reg_lock);
6145
- if (vop2->port_mux_cfg != port_mux_cfg) {
6146
- VOP_CTRL_SET(vop2, ovl_port_mux_cfg, port_mux_cfg);
6147
- vp->skip_vsync = true;
6148
- vop2_cfg_done(&vp->crtc);
6149
- vop2->port_mux_cfg = port_mux_cfg;
6150
- vop2_wait_for_port_mux_done(vop2);
6151
- }
6152
- spin_unlock(&vop2->reg_lock);
6153
-}
6154
-
61559074 static u32 vop2_layer_cfg_update(struct vop2_layer *layer, u32 old_layer_cfg, u8 win_layer_id)
61569075 {
61579076 const struct vop_reg *reg = &layer->regs->layer_sel;
....@@ -6174,6 +9093,12 @@
61749093 for (i = 0; i < vop2_data->nr_vps - 1; i++) {
61759094 prev_vp = &vop2->vps[i];
61769095 used_layers += hweight32(prev_vp->win_mask);
9096
+ if (vop2->version == VOP_VERSION_RK3588) {
9097
+ if (vop2->vps[0].hdr10_at_splice_mode && i == 0)
9098
+ used_layers += 1;
9099
+ if (vop2->vps[0].hdr10_at_splice_mode && i == 1)
9100
+ used_layers -= 1;
9101
+ }
61779102 /*
61789103 * when a window move from vp0 to vp1, or vp0 to vp2,
61799104 * it should flow these steps:
....@@ -6199,10 +9124,26 @@
61999124 prev_vp->bg_ovl_dly = (vop2_data->nr_mixers - port_mux) << 1;
62009125 }
62019126
6202
- if (vop2->data->nr_vps >= 1)
6203
- port_mux_cfg |= 7 << (4 * (vop2->data->nr_vps - 1));
9127
+ port_mux_cfg |= 7 << (4 * (vop2->data->nr_vps - 1));
62049128
62059129 return port_mux_cfg;
9130
+}
9131
+
9132
+static void vop2_setup_port_mux(struct vop2_video_port *vp)
9133
+{
9134
+ struct vop2 *vop2 = vp->vop2;
9135
+ u16 port_mux_cfg;
9136
+
9137
+ port_mux_cfg = vop2_calc_bg_ovl_and_port_mux(vp);
9138
+ spin_lock(&vop2->reg_lock);
9139
+ if (vop2->port_mux_cfg != port_mux_cfg) {
9140
+ VOP_CTRL_SET(vop2, ovl_port_mux_cfg, port_mux_cfg);
9141
+ vp->skip_vsync = true;
9142
+ vop2_cfg_done(&vp->rockchip_crtc.crtc);
9143
+ vop2->port_mux_cfg = port_mux_cfg;
9144
+ vop2_wait_for_port_mux_done(vop2);
9145
+ }
9146
+ spin_unlock(&vop2->reg_lock);
62069147 }
62079148
62089149 static void vop2_setup_layer_mixer_for_vp(struct vop2_video_port *vp,
....@@ -6216,15 +9157,12 @@
62169157 struct vop2_win *win;
62179158 u8 used_layers = 0;
62189159 u8 layer_id, win_phys_id;
6219
- u16 port_mux_cfg;
62209160 u32 layer_cfg_reg_offset = layer->regs->layer_sel.offset;
62219161 u8 nr_layers = vp->nr_layers;
62229162 u32 old_layer_cfg = 0;
62239163 u32 new_layer_cfg = 0;
62249164 u32 atv_layer_cfg;
62259165 int i;
6226
-
6227
- port_mux_cfg = vop2_calc_bg_ovl_and_port_mux(vp);
62289166
62299167 /*
62309168 * Win and layer must map one by one, if a win is selected
....@@ -6240,6 +9178,10 @@
62409178
62419179 old_layer_cfg = vop2->regsbak[layer_cfg_reg_offset >> 2];
62429180 new_layer_cfg = old_layer_cfg;
9181
+
9182
+ if (vp->hdr10_at_splice_mode)
9183
+ nr_layers *= 2;
9184
+
62439185 for (i = 0; i < nr_layers; i++) {
62449186 layer = &vop2->layers[used_layers + i];
62459187 zpos = &vop2_zpos[i];
....@@ -6253,21 +9195,21 @@
62539195 layer = &vop2->layers[layer_id];
62549196 win = vop2_find_win_by_phys_id(vop2, win_phys_id);
62559197 new_layer_cfg = vop2_layer_cfg_update(layer, new_layer_cfg, win->layer_sel_id[vp->id]);
6256
- win->layer_id = layer->id;
62579198 win->layer_id = layer_id;
62589199 layer->win_phys_id = win_phys_id;
62599200 }
62609201
62619202 atv_layer_cfg = vop2_read_layer_cfg(vop2);
6262
- if ((new_layer_cfg != old_layer_cfg) &&
6263
- (atv_layer_cfg != old_layer_cfg)) {
9203
+ if (new_layer_cfg != old_layer_cfg &&
9204
+ atv_layer_cfg != old_layer_cfg &&
9205
+ !vp->splice_mode_right) {
62649206 dev_dbg(vop2->dev, "wait old_layer_sel: 0x%x\n", old_layer_cfg);
62659207 vop2_wait_for_layer_cfg_done(vop2, old_layer_cfg);
62669208 }
62679209 vop2_writel(vop2, RK3568_OVL_LAYER_SEL, new_layer_cfg);
6268
- VOP_CTRL_SET(vop2, ovl_cfg_done_port, vp->id);
9210
+ if (new_layer_cfg != old_layer_cfg)
9211
+ VOP_CTRL_SET(vop2, ovl_cfg_done_port, vp->id);
62699212 VOP_CTRL_SET(vop2, ovl_port_mux_cfg_done_imd, 0);
6270
- vop2_setup_port_mux(vp, port_mux_cfg);
62719213 }
62729214
62739215 static void vop3_setup_layer_sel_for_vp(struct vop2_video_port *vp,
....@@ -6310,7 +9252,9 @@
63109252 struct vop2 *vop2 = vp->vop2;
63119253 const struct vop2_data *vop2_data = vop2->data;
63129254 const struct vop2_video_port_data *vp_data = &vop2_data->vp[vp->id];
6313
- struct drm_crtc *crtc = &vp->crtc;
9255
+ struct vop2_video_port *left_vp = vp->left_vp;
9256
+ struct drm_crtc *crtc = &vp->rockchip_crtc.crtc;
9257
+ struct rockchip_crtc_state *vcstate = to_rockchip_crtc_state(crtc->state);
63149258 struct drm_display_mode *adjusted_mode = &crtc->state->adjusted_mode;
63159259 u16 hsync_len = adjusted_mode->crtc_hsync_end - adjusted_mode->crtc_hsync_start;
63169260 u16 hdisplay = adjusted_mode->crtc_hdisplay;
....@@ -6329,13 +9273,30 @@
63299273 }
63309274 }
63319275
6332
- if (!vp->hdr_in)
9276
+ if (!vp->hdr_in ||
9277
+ (vop2->version == VOP_VERSION_RK3588 && vp->hdr_out))
63339278 bg_dly -= vp->bg_ovl_dly;
63349279
6335
- pre_scan_dly = bg_dly + (hdisplay >> 1) - 1;
6336
- if (vop2->version >= VOP_VERSION_RK3588 && hsync_len < 8)
9280
+ /*
9281
+ * right vp share the same crtc state in splice mode
9282
+ */
9283
+ if (vp->splice_mode_right) {
9284
+ vcstate = to_rockchip_crtc_state(left_vp->rockchip_crtc.crtc.state);
9285
+ adjusted_mode = &left_vp->rockchip_crtc.crtc.state->adjusted_mode;
9286
+ hsync_len = adjusted_mode->crtc_hsync_end - adjusted_mode->crtc_hsync_start;
9287
+ hdisplay = adjusted_mode->crtc_hdisplay;
9288
+ }
9289
+
9290
+ if (vcstate->splice_mode)
9291
+ pre_scan_dly = bg_dly + (hdisplay >> 2) - 1;
9292
+ else
9293
+ pre_scan_dly = bg_dly + (hdisplay >> 1) - 1;
9294
+
9295
+ if (vop2->version == VOP_VERSION_RK3588 && hsync_len < 8)
63379296 hsync_len = 8;
9297
+
63389298 pre_scan_dly = (pre_scan_dly << 16) | hsync_len;
9299
+
63399300 VOP_MODULE_SET(vop2, vp, bg_dly, bg_dly);
63409301 VOP_MODULE_SET(vop2, vp, pre_scan_htiming, pre_scan_dly);
63419302 }
....@@ -6353,8 +9314,17 @@
63539314 for (i = 0; i < vp->nr_layers; i++) {
63549315 zpos = &vop2_zpos[i];
63559316 win = vop2_find_win_by_phys_id(vop2, zpos->win_phys_id);
6356
- plane = &win->base;
6357
- vpstate = to_vop2_plane_state(plane->state);
9317
+ /*
9318
+ * right vp share the same plane state in splice mode
9319
+ */
9320
+ if (vp->splice_mode_right) {
9321
+ plane = &win->left_win->base;
9322
+ vpstate = to_vop2_plane_state(plane->state);
9323
+ } else {
9324
+ plane = &win->base;
9325
+ vpstate = to_vop2_plane_state(plane->state);
9326
+ }
9327
+
63589328 if (vp->hdr_in && !vp->hdr_out && !vpstate->hdr_in) {
63599329 dly = win->dly[VOP2_DLY_MODE_HISO_S];
63609330 dly += vp->bg_ovl_dly;
....@@ -6371,22 +9341,128 @@
63719341 }
63729342 }
63739343
9344
+static void rk3588_vop2_setup_hdr10_splice_layer_mixer(struct drm_crtc *crtc,
9345
+ struct vop2_zpos *vop2_zpos,
9346
+ struct vop2_zpos *vop2_zpos_splice)
9347
+{
9348
+ int zpos_id, i;
9349
+ struct vop2_zpos *vop2_zpos_splice_hdr;
9350
+ struct vop2_video_port *vp = to_vop2_video_port(crtc);
9351
+ struct vop2 *vop2 = vp->vop2;
9352
+
9353
+ vop2_zpos_splice_hdr = kmalloc_array(vop2->data->win_size, sizeof(*vop2_zpos),
9354
+ GFP_KERNEL);
9355
+ if (!vop2_zpos_splice_hdr)
9356
+ goto out;
9357
+
9358
+ zpos_id = 0;
9359
+ vop2_zpos_splice_hdr[zpos_id].zpos = zpos_id;
9360
+ vop2_zpos_splice_hdr[zpos_id].win_phys_id = vop2_zpos[0].win_phys_id;
9361
+ vop2_zpos_splice_hdr[zpos_id].plane = vop2_zpos[0].plane;
9362
+
9363
+ zpos_id++;
9364
+ vop2_zpos_splice_hdr[zpos_id].zpos = zpos_id;
9365
+ vop2_zpos_splice_hdr[zpos_id].win_phys_id = vop2_zpos_splice[0].win_phys_id;
9366
+ vop2_zpos_splice_hdr[zpos_id].plane = vop2_zpos_splice[0].plane;
9367
+
9368
+ for (i = 1; i < vp->nr_layers; i++) {
9369
+ zpos_id++;
9370
+ vop2_zpos_splice_hdr[zpos_id].zpos = zpos_id;
9371
+ vop2_zpos_splice_hdr[zpos_id].win_phys_id = vop2_zpos[i].win_phys_id;
9372
+ vop2_zpos_splice_hdr[zpos_id].plane = vop2_zpos[i].plane;
9373
+ }
9374
+
9375
+ for (i = 1; i < vp->nr_layers; i++) {
9376
+ zpos_id++;
9377
+ vop2_zpos_splice_hdr[zpos_id].zpos = zpos_id;
9378
+ vop2_zpos_splice_hdr[zpos_id].win_phys_id = vop2_zpos_splice[i].win_phys_id;
9379
+ vop2_zpos_splice_hdr[zpos_id].plane = vop2_zpos_splice[i].plane;
9380
+ }
9381
+ vop2_setup_layer_mixer_for_vp(vp, vop2_zpos_splice_hdr);
9382
+
9383
+out:
9384
+ kfree(vop2_zpos_splice_hdr);
9385
+}
9386
+
9387
+static void vop2_crtc_update_vrr(struct drm_crtc *crtc)
9388
+{
9389
+ struct rockchip_crtc_state *vcstate = to_rockchip_crtc_state(crtc->state);
9390
+ struct vop2_video_port *vp = to_vop2_video_port(crtc);
9391
+ struct vop2 *vop2 = vp->vop2;
9392
+ struct drm_display_mode *adjust_mode = &crtc->state->adjusted_mode;
9393
+
9394
+ unsigned int vrefresh;
9395
+ unsigned int new_vtotal, vfp, new_vfp;
9396
+
9397
+ if (!vp->refresh_rate_change)
9398
+ return;
9399
+
9400
+ if (!vcstate->min_refresh_rate || !vcstate->max_refresh_rate)
9401
+ return;
9402
+
9403
+ if (vcstate->request_refresh_rate < vcstate->min_refresh_rate ||
9404
+ vcstate->request_refresh_rate > vcstate->max_refresh_rate) {
9405
+ DRM_ERROR("invalid rate:%d\n", vcstate->request_refresh_rate);
9406
+ return;
9407
+ }
9408
+
9409
+ vrefresh = drm_mode_vrefresh(adjust_mode);
9410
+
9411
+ /* calculate new vfp for new refresh rate */
9412
+ new_vtotal = adjust_mode->vtotal * vrefresh / vcstate->request_refresh_rate;
9413
+ vfp = adjust_mode->vsync_start - adjust_mode->vdisplay;
9414
+ new_vfp = vfp + new_vtotal - adjust_mode->vtotal;
9415
+
9416
+ /* config vop2 vtotal register */
9417
+ VOP_MODULE_SET(vop2, vp, dsp_vtotal, new_vtotal);
9418
+
9419
+ /* config dsc vtotal register */
9420
+ if (vcstate->dsc_enable) {
9421
+ struct vop2_dsc *dsc;
9422
+
9423
+ dsc = &vop2->dscs[vcstate->dsc_id];
9424
+ VOP_MODULE_SET(vop2, dsc, dsc_vtotal, new_vtotal);
9425
+
9426
+ if (vcstate->output_flags & ROCKCHIP_OUTPUT_DUAL_CHANNEL_LEFT_RIGHT_MODE) {
9427
+ dsc = &vop2->dscs[vcstate->dsc_id ? 0 : 1];
9428
+ VOP_MODULE_SET(vop2, dsc, dsc_vtotal, new_vtotal);
9429
+ }
9430
+ }
9431
+
9432
+ /* config all connectors attach to this crtc */
9433
+ rockchip_connector_update_vfp_for_vrr(crtc, adjust_mode, new_vfp);
9434
+}
9435
+
63749436 static void vop2_crtc_atomic_begin(struct drm_crtc *crtc, struct drm_crtc_state *old_crtc_state)
63759437 {
63769438 struct vop2_video_port *vp = to_vop2_video_port(crtc);
63779439 struct vop2 *vop2 = vp->vop2;
9440
+ const struct vop2_video_port_data *vp_data = &vop2->data->vp[vp->id];
9441
+ struct vop2_video_port *splice_vp = &vop2->vps[vp_data->splice_vp_id];
63789442 struct drm_plane *plane;
63799443 struct vop2_plane_state *vpstate;
63809444 struct vop2_zpos *vop2_zpos;
9445
+ struct vop2_zpos *vop2_zpos_splice;
63819446 struct vop2_cluster cluster;
63829447 uint8_t nr_layers = 0;
9448
+ uint8_t splice_nr_layers = 0;
9449
+ bool hdr10_in = false;
9450
+ bool hdr10_at_splice_mode = false;
63839451 struct rockchip_crtc_state *vcstate = to_rockchip_crtc_state(crtc->state);
6384
- const struct vop2_video_port_data *vp_data = &vop2->data->vp[vp->id];
63859452
63869453 vcstate->yuv_overlay = is_yuv_output(vcstate->bus_format);
63879454 vop2_zpos = kmalloc_array(vop2->data->win_size, sizeof(*vop2_zpos), GFP_KERNEL);
63889455 if (!vop2_zpos)
63899456 return;
9457
+ if (vcstate->splice_mode) {
9458
+ vop2_zpos_splice = kmalloc_array(vop2->data->win_size, sizeof(*vop2_zpos),
9459
+ GFP_KERNEL);
9460
+ if (!vop2_zpos_splice)
9461
+ goto out;
9462
+ }
9463
+
9464
+ if (vop2->version == VOP_VERSION_RK3588)
9465
+ vop2_crtc_update_vrr(crtc);
63909466
63919467 /* Process cluster sub windows overlay. */
63929468 drm_atomic_crtc_for_each_plane(plane, crtc) {
....@@ -6396,9 +9472,13 @@
63969472 win->two_win_mode = false;
63979473 if (!(win->feature & WIN_FEATURE_CLUSTER_SUB))
63989474 continue;
9475
+ if (vcstate->splice_mode)
9476
+ DRM_ERROR("vp%d %s not supported two win mode at splice mode\n",
9477
+ vp->id, win->name);
63999478 main_win = vop2_find_win_by_phys_id(vop2, win->phys_id);
64009479 cluster.main = main_win;
64019480 cluster.sub = win;
9481
+ cluster.splice_mode = false;
64029482 win->two_win_mode = true;
64039483 main_win->two_win_mode = true;
64049484 vop2_setup_cluster_alpha(vop2, &cluster);
....@@ -6410,6 +9490,7 @@
64109490
64119491 drm_atomic_crtc_for_each_plane(plane, crtc) {
64129492 struct vop2_win *win = to_vop2_win(plane);
9493
+ struct vop2_win *splice_win;
64139494 struct vop2_video_port *old_vp;
64149495 uint8_t old_vp_id;
64159496
....@@ -6429,35 +9510,93 @@
64299510 vop2_zpos[nr_layers].win_phys_id = win->phys_id;
64309511 vop2_zpos[nr_layers].zpos = vpstate->zpos;
64319512 vop2_zpos[nr_layers].plane = plane;
9513
+
9514
+ rockchip_drm_dbg(vop2->dev, VOP_DEBUG_OVERLAY, "%s active zpos:%d for vp%d from vp%d\n",
9515
+ win->name, vpstate->zpos, vp->id, old_vp->id);
9516
+ /* left and right win may have different number */
9517
+ if (vcstate->splice_mode) {
9518
+ splice_win = vop2_find_win_by_phys_id(vop2, win->splice_win_id);
9519
+ splice_win->splice_mode_right = true;
9520
+ splice_win->left_win = win;
9521
+ win->splice_win = splice_win;
9522
+
9523
+ old_vp_id = ffs(splice_win->vp_mask);
9524
+ old_vp_id = (old_vp_id == 0) ? 0 : old_vp_id - 1;
9525
+ old_vp = &vop2->vps[old_vp_id];
9526
+ old_vp->win_mask &= ~BIT(splice_win->phys_id);
9527
+ splice_vp->win_mask |= BIT(splice_win->phys_id);
9528
+ splice_win->vp_mask = BIT(splice_vp->id);
9529
+ hdr10_in |= vpstate->eotf == HDMI_EOTF_SMPTE_ST2084 ? true : false;
9530
+ vop2_zpos_splice[splice_nr_layers].win_phys_id = splice_win->phys_id;
9531
+ vop2_zpos_splice[splice_nr_layers].zpos = vpstate->zpos;
9532
+ vop2_zpos_splice[splice_nr_layers].plane = &splice_win->base;
9533
+ splice_nr_layers++;
9534
+ DRM_DEV_DEBUG(vop2->dev, "%s active zpos:%d for vp%d from vp%d\n",
9535
+ splice_win->name, vpstate->zpos, splice_vp->id, old_vp->id);
9536
+ }
64329537 nr_layers++;
6433
- DRM_DEV_DEBUG(vop2->dev, "%s active zpos:%d for vp%d from vp%d\n",
6434
- win->name, vpstate->zpos, vp->id, old_vp->id);
64359538 }
64369539
6437
- DRM_DEV_DEBUG(vop2->dev, "vp%d: %d windows, active layers %d\n",
6438
- vp->id, hweight32(vp->win_mask), nr_layers);
9540
+ if (vcstate->splice_mode) {
9541
+ if (hdr10_in)
9542
+ hdr10_at_splice_mode = true;
9543
+
9544
+ splice_vp->hdr10_at_splice_mode = hdr10_at_splice_mode;
9545
+ }
9546
+ vp->hdr10_at_splice_mode = hdr10_at_splice_mode;
9547
+
9548
+ rockchip_drm_dbg(vop2->dev, VOP_DEBUG_OVERLAY, "vp%d: %d windows, active layers %d\n",
9549
+ vp->id, hweight32(vp->win_mask), nr_layers);
64399550 if (nr_layers) {
64409551 vp->nr_layers = nr_layers;
64419552
64429553 sort(vop2_zpos, nr_layers, sizeof(vop2_zpos[0]), vop2_zpos_cmp, NULL);
64439554
9555
+ if (!vp->hdr10_at_splice_mode) {
9556
+ if (is_vop3(vop2)) {
9557
+ vop3_setup_layer_sel_for_vp(vp, vop2_zpos);
9558
+ } else {
9559
+ vop2_setup_port_mux(vp);
9560
+ vop2_setup_layer_mixer_for_vp(vp, vop2_zpos);
9561
+ }
9562
+ }
9563
+
64449564 if (is_vop3(vop2)) {
6445
- vop3_setup_layer_sel_for_vp(vp, vop2_zpos);
64469565 if (vp_data->feature & VOP_FEATURE_VIVID_HDR)
64479566 vop3_setup_dynamic_hdr(vp, vop2_zpos[0].win_phys_id);
64489567 vop3_setup_alpha(vp, vop2_zpos);
64499568 vop3_setup_pipe_dly(vp, vop2_zpos);
64509569 } else {
6451
- vop2_setup_layer_mixer_for_vp(vp, vop2_zpos);
64529570 vop2_setup_hdr10(vp, vop2_zpos[0].win_phys_id);
64539571 vop2_setup_alpha(vp, vop2_zpos);
64549572 vop2_setup_dly_for_vp(vp);
64559573 vop2_setup_dly_for_window(vp, vop2_zpos);
64569574 }
9575
+
9576
+ if (vcstate->splice_mode) {/* Fixme for VOP3 8K */
9577
+ splice_vp->nr_layers = splice_nr_layers;
9578
+
9579
+ sort(vop2_zpos_splice, splice_nr_layers, sizeof(vop2_zpos_splice[0]),
9580
+ vop2_zpos_cmp, NULL);
9581
+
9582
+ vop2_setup_port_mux(splice_vp);
9583
+ if (!vp->hdr10_at_splice_mode)
9584
+ vop2_setup_layer_mixer_for_vp(splice_vp, vop2_zpos_splice);
9585
+ vop2_setup_hdr10(splice_vp, vop2_zpos_splice[0].win_phys_id);
9586
+ vop2_setup_alpha(splice_vp, vop2_zpos_splice);
9587
+ vop2_setup_dly_for_vp(splice_vp);
9588
+ vop2_setup_dly_for_window(splice_vp, vop2_zpos_splice);
9589
+
9590
+ if (vop2->version == VOP_VERSION_RK3588 &&
9591
+ vp->hdr10_at_splice_mode)
9592
+ rk3588_vop2_setup_hdr10_splice_layer_mixer(crtc, vop2_zpos, vop2_zpos_splice);
9593
+ }
64579594 } else {
64589595 if (!is_vop3(vop2)) {
64599596 vop2_calc_bg_ovl_and_port_mux(vp);
64609597 vop2_setup_dly_for_vp(vp);
9598
+ if (vcstate->splice_mode)
9599
+ vop2_setup_dly_for_vp(splice_vp);
64619600 } else {
64629601 vop3_setup_pipe_dly(vp, NULL);
64639602 }
....@@ -6466,6 +9605,7 @@
64669605 /* The pre alpha overlay of Cluster still need process in one win mode. */
64679606 drm_atomic_crtc_for_each_plane(plane, crtc) {
64689607 struct vop2_win *win = to_vop2_win(plane);
9608
+ struct vop2_win *splice_win;
64699609
64709610 if (!(win->feature & WIN_FEATURE_CLUSTER_MAIN))
64719611 continue;
....@@ -6473,9 +9613,19 @@
64739613 continue;
64749614 cluster.main = win;
64759615 cluster.sub = NULL;
9616
+ cluster.splice_mode = false;
64769617 vop2_setup_cluster_alpha(vop2, &cluster);
9618
+ if (vcstate->splice_mode) {
9619
+ splice_win = win->splice_win;
9620
+ cluster.main = splice_win;
9621
+ cluster.splice_mode = true;
9622
+ vop2_setup_cluster_alpha(vop2, &cluster);
9623
+ }
64779624 }
64789625
9626
+ if (vcstate->splice_mode)
9627
+ kfree(vop2_zpos_splice);
9628
+out:
64799629 kfree(vop2_zpos);
64809630 }
64819631
....@@ -6586,6 +9736,12 @@
65869736 bcsh_state.cos_hue = cos_hue;
65879737
65889738 vop2_bcsh_reg_update(vcstate, vp, &bcsh_state);
9739
+ if (vcstate->splice_mode) {
9740
+ const struct vop2_video_port_data *vp_data = &vop2->data->vp[vp->id];
9741
+ struct vop2_video_port *splice_vp = &vop2->vps[vp_data->splice_vp_id];
9742
+
9743
+ vop2_bcsh_reg_update(vcstate, splice_vp, &bcsh_state);
9744
+ }
65899745 }
65909746
65919747 static void vop3_post_csc_config(struct drm_crtc *crtc, struct post_acm *acm, struct post_csc *csc)
....@@ -6755,6 +9911,7 @@
67559911 struct vop2 *vop2 = vp->vop2;
67569912 const struct vop2_data *vop2_data = vop2->data;
67579913 const struct vop2_video_port_data *vp_data = &vop2_data->vp[vp->id];
9914
+ struct vop2_video_port *splice_vp = &vop2->vps[vp_data->splice_vp_id];
67589915 uint32_t val;
67599916 uint32_t r, g, b;
67609917 uint8_t out_mode;
....@@ -6769,12 +9926,11 @@
67699926 out_mode = vcstate->output_mode;
67709927 VOP_MODULE_SET(vop2, vp, out_mode, out_mode);
67719928
6772
- if (vop2_output_uv_swap(vcstate->bus_format, vcstate->output_mode))
6773
- VOP_MODULE_SET(vop2, vp, dsp_data_swap, DSP_RB_SWAP);
6774
- else
6775
- VOP_MODULE_SET(vop2, vp, dsp_data_swap, 0);
9929
+ vop2_post_color_swap(crtc);
67769930
6777
- vop2_dither_setup(crtc);
9931
+ vop2_dither_setup(vcstate, crtc);
9932
+ if (vcstate->splice_mode)
9933
+ vop2_dither_setup(vcstate, &splice_vp->rockchip_crtc.crtc);
67789934
67799935 VOP_MODULE_SET(vop2, vp, overlay_mode, vcstate->yuv_overlay);
67809936
....@@ -6797,10 +9953,15 @@
67979953 }
67989954
67999955 VOP_MODULE_SET(vop2, vp, dsp_background, val);
9956
+ if (vcstate->splice_mode) {
9957
+ VOP_MODULE_SET(vop2, splice_vp, overlay_mode, vcstate->yuv_overlay);
9958
+ VOP_MODULE_SET(vop2, splice_vp, dsp_background, val);
9959
+ }
68009960
68019961 vop2_tv_config_update(crtc, old_crtc_state);
68029962
6803
- vop2_post_config(crtc);
9963
+ if (vp_data->feature & VOP_FEATURE_OVERSCAN)
9964
+ vop2_post_config(crtc);
68049965
68059966 spin_unlock(&vop2->reg_lock);
68069967
....@@ -6808,16 +9969,97 @@
68089969 vop3_post_config(crtc);
68099970 }
68109971
9972
+static void vop2_sleep_scan_line_time(struct vop2_video_port *vp, int scan_line)
9973
+{
9974
+ struct vop2 *vop2 = vp->vop2;
9975
+ struct drm_display_mode *mode = &vp->rockchip_crtc.crtc.state->adjusted_mode;
9976
+
9977
+ if (scan_line <= 0)
9978
+ return;
9979
+
9980
+ if (IS_ENABLED(CONFIG_HIGH_RES_TIMERS) &&
9981
+ (!IS_ENABLED(CONFIG_NO_GKI) || (hrtimer_resolution != LOW_RES_NSEC))) {
9982
+ u16 htotal = VOP_MODULE_GET(vop2, vp, htotal_pw) >> 16;
9983
+ u32 linedur_ns = div_u64((u64) htotal * 1000000, mode->crtc_clock);
9984
+ u64 sleep_time = linedur_ns * scan_line;
9985
+
9986
+ sleep_time = div_u64((sleep_time + 1000), 1000);
9987
+ if (sleep_time > 200)
9988
+ usleep_range(sleep_time, sleep_time);
9989
+ }
9990
+}
9991
+
9992
+/*
9993
+ * return scan timing from FS to the assigned wait line
9994
+ */
9995
+static void vop2_wait_for_scan_timing_max_to_assigned_line(struct vop2_video_port *vp,
9996
+ u32 current_line,
9997
+ u32 wait_line)
9998
+
9999
+{
10000
+ struct vop2 *vop2 = vp->vop2;
10001
+ u32 vcnt;
10002
+ int ret;
10003
+ u16 vtotal = VOP_MODULE_GET(vop2, vp, dsp_vtotal);
10004
+ int delta_line = vtotal - current_line;
10005
+
10006
+ vop2_sleep_scan_line_time(vp, delta_line);
10007
+ if (vop2_read_vcnt(vp) < wait_line)
10008
+ return;
10009
+
10010
+ ret = readx_poll_timeout_atomic(vop2_read_vcnt, vp, vcnt, vcnt < wait_line, 0, 50 * 1000);
10011
+ if (ret)
10012
+ DRM_DEV_ERROR(vop2->dev, "wait scan timing from FS to the assigned wait line: %d, vcnt:%d, ret:%d\n",
10013
+ wait_line, vcnt, ret);
10014
+}
10015
+
10016
+/*
10017
+ * return scan timing from the assigned wait line
10018
+ */
10019
+static void vop2_wait_for_scan_timing_from_the_assigned_line(struct vop2_video_port *vp,
10020
+ u32 current_line,
10021
+ u32 wait_line)
10022
+{
10023
+ struct vop2 *vop2 = vp->vop2;
10024
+ u32 vcnt;
10025
+ int ret;
10026
+ int delta_line = wait_line - current_line;
10027
+
10028
+ vop2_sleep_scan_line_time(vp, delta_line);
10029
+ if (vop2_read_vcnt(vp) > wait_line)
10030
+ return;
10031
+
10032
+ ret = readx_poll_timeout_atomic(vop2_read_vcnt, vp, vcnt, vcnt > wait_line, 0, 50 * 1000);
10033
+ if (ret)
10034
+ DRM_DEV_ERROR(vop2->dev, "wait scan timing from the assigned wait line: %d, vcnt:%d, ret:%d\n",
10035
+ wait_line, vcnt, ret);
10036
+}
10037
+
681110038 static void vop2_crtc_atomic_flush(struct drm_crtc *crtc, struct drm_crtc_state *old_cstate)
681210039 {
681310040 struct rockchip_crtc_state *vcstate = to_rockchip_crtc_state(crtc->state);
681410041 struct drm_atomic_state *old_state = old_cstate->state;
681510042 struct vop2_video_port *vp = to_vop2_video_port(crtc);
6816
- struct drm_plane_state *old_pstate;
681710043 struct vop2 *vop2 = vp->vop2;
10044
+ struct drm_plane_state *old_pstate;
681810045 struct drm_plane *plane;
681910046 unsigned long flags;
682010047 int i, ret;
10048
+ struct vop2_wb *wb = &vop2->wb;
10049
+ struct drm_writeback_connector *wb_conn = &wb->conn;
10050
+ struct drm_connector_state *conn_state = wb_conn->base.state;
10051
+
10052
+ if (conn_state && conn_state->writeback_job && conn_state->writeback_job->fb) {
10053
+ u16 vtotal = VOP_MODULE_GET(vop2, vp, dsp_vtotal);
10054
+ u32 current_line = vop2_read_vcnt(vp);
10055
+
10056
+ if (current_line > vtotal * 7 >> 3)
10057
+ vop2_wait_for_scan_timing_max_to_assigned_line(vp, current_line, vtotal * 7 >> 3);
10058
+
10059
+ current_line = vop2_read_vcnt(vp);
10060
+ if (current_line < vtotal >> 3)
10061
+ vop2_wait_for_scan_timing_from_the_assigned_line(vp, current_line, vtotal >> 3);
10062
+ }
682110063
682210064 vop2_cfg_update(crtc, old_cstate);
682310065
....@@ -6843,10 +10085,9 @@
684310085 vp->gamma_lut = crtc->state->gamma_lut->data;
684410086 vop2_crtc_atomic_gamma_set(crtc, crtc->state);
684510087 }
6846
-
6847
- if (crtc->state->cubic_lut || vp->cubic_lut) {
6848
- if (crtc->state->cubic_lut)
6849
- vp->cubic_lut = crtc->state->cubic_lut->data;
10088
+ if (vcstate->cubic_lut_data || vp->cubic_lut) {
10089
+ if (vcstate->cubic_lut_data)
10090
+ vp->cubic_lut = vcstate->cubic_lut_data->data;
685010091 vop2_crtc_atomic_cubic_lut_set(crtc, crtc->state);
685110092 }
685210093 } else {
....@@ -6861,6 +10102,9 @@
686110102 spin_lock_irqsave(&vop2->irq_lock, flags);
686210103 vop2_wb_commit(crtc);
686310104 vop2_cfg_done(crtc);
10105
+
10106
+ if (vp->mcu_timing.mcu_pix_total)
10107
+ VOP_MODULE_SET(vop2, vp, mcu_hold_mode, 0);
686410108
686510109 spin_unlock_irqrestore(&vop2->irq_lock, flags);
686610110
....@@ -6902,6 +10146,7 @@
690210146 }
690310147
690410148 static const struct drm_crtc_helper_funcs vop2_crtc_helper_funcs = {
10149
+ .mode_valid = vop2_crtc_mode_valid,
690510150 .mode_fixup = vop2_crtc_mode_fixup,
690610151 .atomic_check = vop2_crtc_atomic_check,
690710152 .atomic_begin = vop2_crtc_atomic_begin,
....@@ -6942,6 +10187,9 @@
694210187 struct rockchip_crtc_state *vcstate, *old_vcstate;
694310188 struct vop2_video_port *vp = to_vop2_video_port(crtc);
694410189
10190
+ if (WARN_ON(!crtc->state))
10191
+ return NULL;
10192
+
694510193 old_vcstate = to_rockchip_crtc_state(crtc->state);
694610194 vcstate = kmemdup(old_vcstate, sizeof(*old_vcstate), GFP_KERNEL);
694710195 if (!vcstate)
....@@ -6954,6 +10202,8 @@
695410202 drm_property_blob_get(vcstate->acm_lut_data);
695510203 if (vcstate->post_csc_data)
695610204 drm_property_blob_get(vcstate->post_csc_data);
10205
+ if (vcstate->cubic_lut_data)
10206
+ drm_property_blob_get(vcstate->cubic_lut_data);
695710207
695810208 __drm_atomic_helper_crtc_duplicate_state(crtc, &vcstate->base);
695910209 return &vcstate->base;
....@@ -6968,6 +10218,7 @@
696810218 drm_property_blob_put(vcstate->hdr_ext_data);
696910219 drm_property_blob_put(vcstate->acm_lut_data);
697010220 drm_property_blob_put(vcstate->post_csc_data);
10221
+ drm_property_blob_put(vcstate->cubic_lut_data);
697110222 kfree(vcstate);
697210223 }
697310224
....@@ -7068,36 +10319,56 @@
706810319 return 0;
706910320 }
707010321
7071
- if (property == private->alpha_scale_prop) {
7072
- *val = (vop2->data->feature & VOP_FEATURE_ALPHA_SCALE) ? 1 : 0;
7073
- return 0;
7074
- }
7075
-
7076
- if (property == vop2->aclk_prop) {
10322
+ if (property == private->aclk_prop) {
707710323 /* KHZ, keep align with mode->clock */
707810324 *val = clk_get_rate(vop2->aclk) / 1000;
707910325 return 0;
708010326 }
708110327
7082
-
7083
- if (property == vop2->bg_prop) {
10328
+ if (property == private->bg_prop) {
708410329 *val = vcstate->background;
708510330 return 0;
708610331 }
708710332
7088
- if (property == vop2->line_flag_prop) {
10333
+ if (property == private->line_flag_prop) {
708910334 *val = vcstate->line_flag;
709010335 return 0;
709110336 }
709210337
7093
- if (property == vp->hdr_ext_data_prop)
10338
+ if (property == vp->variable_refresh_rate_prop) {
10339
+ *val = vcstate->request_refresh_rate;
709410340 return 0;
10341
+ }
709510342
7096
- if (property == vp->acm_lut_data_prop)
10343
+ if (property == vp->max_refresh_rate_prop) {
10344
+ *val = vcstate->max_refresh_rate;
709710345 return 0;
10346
+ }
709810347
7099
- if (property == vp->post_csc_data_prop)
10348
+ if (property == vp->min_refresh_rate_prop) {
10349
+ *val = vcstate->min_refresh_rate;
710010350 return 0;
10351
+ }
10352
+
10353
+ if (property == vp->hdr_ext_data_prop) {
10354
+ *val = vcstate->hdr_ext_data ? vcstate->hdr_ext_data->base.id : 0;
10355
+ return 0;
10356
+ }
10357
+
10358
+ if (property == vp->acm_lut_data_prop) {
10359
+ *val = vcstate->acm_lut_data ? vcstate->acm_lut_data->base.id : 0;
10360
+ return 0;
10361
+ }
10362
+
10363
+ if (property == vp->post_csc_data_prop) {
10364
+ *val = vcstate->post_csc_data ? vcstate->post_csc_data->base.id : 0;
10365
+ return 0;
10366
+ }
10367
+
10368
+ if (property == private->cubic_lut_prop) {
10369
+ *val = (vcstate->cubic_lut_data) ? vcstate->cubic_lut_data->base.id : 0;
10370
+ return 0;
10371
+ }
710110372
710210373 DRM_ERROR("failed to get vop2 crtc property: %s\n", property->name);
710310374
....@@ -7144,10 +10415,10 @@
714410415 uint64_t val)
714510416 {
714610417 struct drm_device *drm_dev = crtc->dev;
10418
+ struct rockchip_drm_private *private = drm_dev->dev_private;
714710419 struct rockchip_crtc_state *vcstate = to_rockchip_crtc_state(state);
714810420 struct drm_mode_config *mode_config = &drm_dev->mode_config;
714910421 struct vop2_video_port *vp = to_vop2_video_port(crtc);
7150
- struct vop2 *vop2 = vp->vop2;
715110422 bool replaced = false;
715210423 int ret;
715310424
....@@ -7172,13 +10443,28 @@
717210443 }
717310444
717410445
7175
- if (property == vop2->bg_prop) {
10446
+ if (property == private->bg_prop) {
717610447 vcstate->background = val;
717710448 return 0;
717810449 }
717910450
7180
- if (property == vop2->line_flag_prop) {
10451
+ if (property == private->line_flag_prop) {
718110452 vcstate->line_flag = val;
10453
+ return 0;
10454
+ }
10455
+
10456
+ if (property == vp->variable_refresh_rate_prop) {
10457
+ vcstate->request_refresh_rate = val;
10458
+ return 0;
10459
+ }
10460
+
10461
+ if (property == vp->max_refresh_rate_prop) {
10462
+ vcstate->max_refresh_rate = val;
10463
+ return 0;
10464
+ }
10465
+
10466
+ if (property == vp->min_refresh_rate_prop) {
10467
+ vcstate->min_refresh_rate = val;
718210468 return 0;
718310469 }
718410470
....@@ -7209,6 +10495,16 @@
720910495 return ret;
721010496 }
721110497
10498
+ if (property == private->cubic_lut_prop) {
10499
+ ret = vop2_atomic_replace_property_blob_from_id(drm_dev,
10500
+ &vcstate->cubic_lut_data,
10501
+ val,
10502
+ -1, sizeof(struct drm_color_lut),
10503
+ &replaced);
10504
+ state->color_mgmt_changed |= replaced;
10505
+ return ret;
10506
+ }
10507
+
721210508 DRM_ERROR("failed to set vop2 crtc property %s\n", property->name);
721310509
721410510 return -EINVAL;
....@@ -7235,7 +10531,7 @@
723510531 struct vop2_video_port *vp = container_of(work, struct vop2_video_port, fb_unref_work);
723610532 struct drm_framebuffer *fb = val;
723710533
7238
- drm_crtc_vblank_put(&vp->crtc);
10534
+ drm_crtc_vblank_put(&vp->rockchip_crtc.crtc);
723910535 if (!vp->vop2->skip_ref_fb)
724010536 drm_framebuffer_put(fb);
724110537 }
....@@ -7306,6 +10602,7 @@
730610602 struct vop2_wb *wb = &vop2->wb;
730710603
730810604 VOP_MODULE_SET(vop2, wb, enable, 0);
10605
+ VOP_CTRL_SET(vop2, wb_dma_finish_and_en, 0);
730910606 vop2_wb_cfg_done(vp);
731010607 }
731110608
....@@ -7344,6 +10641,43 @@
734410641 }
734510642 }
734610643 spin_unlock_irqrestore(&wb->job_lock, flags);
10644
+}
10645
+
10646
+static void vop2_dsc_isr(struct vop2 *vop2)
10647
+{
10648
+ const struct vop2_data *vop2_data = vop2->data;
10649
+ struct vop2_dsc *dsc;
10650
+ const struct dsc_error_info *dsc_error_ecw = vop2_data->dsc_error_ecw;
10651
+ const struct dsc_error_info *dsc_error_buffer_flow = vop2_data->dsc_error_buffer_flow;
10652
+ u32 dsc_error_status = 0, dsc_ecw = 0;
10653
+ int i = 0, j = 0;
10654
+
10655
+ for (i = 0; i < vop2_data->nr_dscs; i++) {
10656
+ dsc = &vop2->dscs[i];
10657
+
10658
+ if (!dsc->enabled)
10659
+ continue;
10660
+
10661
+ dsc_error_status = VOP_MODULE_GET(vop2, dsc, dsc_error_status);
10662
+ if (!dsc_error_status)
10663
+ continue;
10664
+ dsc_ecw = VOP_MODULE_GET(vop2, dsc, dsc_ecw);
10665
+
10666
+ for (j = 0; j < vop2_data->nr_dsc_ecw; j++) {
10667
+ if (dsc_ecw == dsc_error_ecw[j].dsc_error_val) {
10668
+ DRM_ERROR("dsc%d %s\n", dsc->id, dsc_error_ecw[j].dsc_error_info);
10669
+ break;
10670
+ }
10671
+ }
10672
+
10673
+ if (dsc_ecw == 0x0120ffff) {
10674
+ u32 offset = dsc->regs->dsc_status.offset;
10675
+
10676
+ for (j = 0; j < vop2_data->nr_dsc_buffer_flow; j++)
10677
+ DRM_ERROR("dsc%d %s:0x%x\n", dsc->id, dsc_error_buffer_flow[j].dsc_error_info,
10678
+ vop2_readl(vop2, offset + (j << 2)));
10679
+ }
10680
+ }
734710681 }
734810682
734910683 static irqreturn_t vop2_isr(int irq, void *data)
....@@ -7400,7 +10734,7 @@
740010734
740110735 for (i = 0; i < vp_max; i++) {
740210736 vp = &vop2->vps[i];
7403
- crtc = &vp->crtc;
10737
+ crtc = &vp->rockchip_crtc.crtc;
740410738 active_irqs = vp_irqs[i];
740510739 if (active_irqs & DSP_HOLD_VALID_INTR) {
740610740 complete(&vp->dsp_hold_completion);
....@@ -7431,6 +10765,7 @@
743110765 }
743210766
743310767 if (active_irqs & FS_FIELD_INTR) {
10768
+ rockchip_drm_dbg(vop2->dev, VOP_DEBUG_VSYNC, "vsync_vp%d\n", vp->id);
743410769 vop2_wb_handler(vp);
743510770 if (likely(!vp->skip_vsync) || (vp->layer_sel_update == false)) {
743610771 drm_crtc_handle_vblank(crtc);
....@@ -7462,6 +10797,9 @@
746210797 if (active_irqs)
746310798 DRM_ERROR("Unknown axi_bus%d IRQs: %02x\n", i, active_irqs);
746410799 }
10800
+
10801
+ if (vop2->data->nr_dscs)
10802
+ vop2_dsc_isr(vop2);
746510803
746610804 vop2_core_clks_disable(vop2);
746710805 out:
....@@ -7668,25 +11006,14 @@
766811006 return 0;
766911007 }
767011008
7671
-static struct drm_plane *vop2_cursor_plane_init(struct vop2_video_port *vp)
11009
+static struct drm_plane *vop2_cursor_plane_init(struct vop2_video_port *vp, u32 possible_crtcs)
767211010 {
767311011 struct vop2 *vop2 = vp->vop2;
767411012 struct drm_plane *cursor = NULL;
767511013 struct vop2_win *win;
7676
- unsigned long possible_crtcs = 0;
767711014
767811015 win = vop2_find_win_by_phys_id(vop2, vp->cursor_win_id);
767911016 if (win) {
7680
- if (vop2->disable_win_move) {
7681
- const struct vop2_data *vop2_data = vop2->data;
7682
- struct drm_crtc *crtc = vop2_find_crtc_by_plane_mask(vop2, win->phys_id);
7683
-
7684
- if (crtc)
7685
- possible_crtcs = drm_crtc_mask(crtc);
7686
- else
7687
- possible_crtcs = (1 << vop2_data->nr_vps) - 1;
7688
- }
7689
-
769011017 if (win->possible_crtcs)
769111018 possible_crtcs = win->possible_crtcs;
769211019 win->type = DRM_PLANE_TYPE_CURSOR;
....@@ -7714,7 +11041,7 @@
771411041
771511042 for (i = 0; i < vop2_data->nr_vps; i++) {
771611043 vp = &vop2->vps[i];
7717
- crtc = &vp->crtc;
11044
+ crtc = &vp->rockchip_crtc.crtc;
771811045 if (!crtc->dev)
771911046 continue;
772011047 vp_data = &vop2_data->vp[vp->id];
....@@ -7751,27 +11078,6 @@
775111078 return 0;
775211079 }
775311080
7754
-static void vop2_cubic_lut_init(struct vop2 *vop2)
7755
-{
7756
- const struct vop2_data *vop2_data = vop2->data;
7757
- const struct vop2_video_port_data *vp_data;
7758
- struct vop2_video_port *vp;
7759
- struct drm_crtc *crtc;
7760
- int i;
7761
-
7762
- for (i = 0; i < vop2_data->nr_vps; i++) {
7763
- vp = &vop2->vps[i];
7764
- crtc = &vp->crtc;
7765
- if (!crtc->dev)
7766
- continue;
7767
- vp_data = &vop2_data->vp[vp->id];
7768
- vp->cubic_lut_len = vp_data->cubic_lut_len;
7769
-
7770
- if (vp->cubic_lut_len)
7771
- drm_crtc_enable_cubic_lut(crtc, vp->cubic_lut_len);
7772
- }
7773
-}
7774
-
777511081 static int vop2_crtc_create_plane_mask_property(struct vop2 *vop2,
777611082 struct drm_crtc *crtc,
777711083 uint32_t plane_mask)
....@@ -7803,6 +11109,95 @@
780311109
780411110 vp->plane_mask_prop = prop;
780511111 drm_object_attach_property(&crtc->base, vp->plane_mask_prop, plane_mask);
11112
+
11113
+ return 0;
11114
+}
11115
+
11116
+static int vop2_crtc_create_feature_property(struct vop2 *vop2, struct drm_crtc *crtc)
11117
+{
11118
+ const struct vop2_data *vop2_data = vop2->data;
11119
+ struct vop2_video_port *vp = to_vop2_video_port(crtc);
11120
+ const struct vop2_video_port_data *vp_data = &vop2_data->vp[vp->id];
11121
+ struct drm_property *prop;
11122
+ u64 feature = 0;
11123
+
11124
+ static const struct drm_prop_enum_list props[] = {
11125
+ { ROCKCHIP_DRM_CRTC_FEATURE_ALPHA_SCALE, "ALPHA_SCALE" },
11126
+ { ROCKCHIP_DRM_CRTC_FEATURE_HDR10, "HDR10" },
11127
+ { ROCKCHIP_DRM_CRTC_FEATURE_NEXT_HDR, "NEXT_HDR" },
11128
+ { ROCKCHIP_DRM_CRTC_FEATURE_VIVID_HDR, "VIVID_HDR" },
11129
+ };
11130
+
11131
+ if (vp_data->feature & VOP_FEATURE_ALPHA_SCALE)
11132
+ feature |= BIT(ROCKCHIP_DRM_CRTC_FEATURE_ALPHA_SCALE);
11133
+ if (vp_data->feature & VOP_FEATURE_HDR10)
11134
+ feature |= BIT(ROCKCHIP_DRM_CRTC_FEATURE_HDR10);
11135
+ if (vp_data->feature & VOP_FEATURE_NEXT_HDR)
11136
+ feature |= BIT(ROCKCHIP_DRM_CRTC_FEATURE_NEXT_HDR);
11137
+ if (vp_data->feature & VOP_FEATURE_VIVID_HDR)
11138
+ feature |= BIT(ROCKCHIP_DRM_CRTC_FEATURE_VIVID_HDR);
11139
+
11140
+ prop = drm_property_create_bitmask(vop2->drm_dev,
11141
+ DRM_MODE_PROP_IMMUTABLE, "FEATURE",
11142
+ props, ARRAY_SIZE(props),
11143
+ 0xffffffff);
11144
+ if (!prop) {
11145
+ DRM_DEV_ERROR(vop2->dev, "create FEATURE prop for vp%d failed\n", vp->id);
11146
+ return -ENOMEM;
11147
+ }
11148
+
11149
+ vp->feature_prop = prop;
11150
+ drm_object_attach_property(&crtc->base, vp->feature_prop, feature);
11151
+
11152
+ prop = drm_property_create_range(vop2->drm_dev, DRM_MODE_PROP_IMMUTABLE, "OUTPUT_WIDTH",
11153
+ 0, vop2->data->vp[vp->id].max_output.width);
11154
+ if (!prop) {
11155
+ DRM_DEV_ERROR(vop2->dev, "create OUTPUT_WIDTH prop for vp%d failed\n", vp->id);
11156
+ return -ENOMEM;
11157
+ }
11158
+ vp->output_width_prop = prop;
11159
+ drm_object_attach_property(&crtc->base, vp->output_width_prop, 0);
11160
+
11161
+ prop = drm_property_create_range(vop2->drm_dev, DRM_MODE_PROP_IMMUTABLE, "OUTPUT_DCLK",
11162
+ 0, rockchip_drm_get_dclk_by_width(vop2->data->vp[vp->id].max_output.width) * 1000);
11163
+ if (!prop) {
11164
+ DRM_DEV_ERROR(vop2->dev, "create OUTPUT_DCLK prop for vp%d failed\n", vp->id);
11165
+ return -ENOMEM;
11166
+ }
11167
+ vp->output_dclk_prop = prop;
11168
+ drm_object_attach_property(&crtc->base, vp->output_dclk_prop, 0);
11169
+
11170
+ return 0;
11171
+}
11172
+
11173
+static int vop2_crtc_create_vrr_property(struct vop2 *vop2, struct drm_crtc *crtc)
11174
+{
11175
+ struct vop2_video_port *vp = to_vop2_video_port(crtc);
11176
+ struct drm_property *prop;
11177
+
11178
+ prop = drm_property_create_range(vop2->drm_dev, 0, "variable refresh rate", 0, 144);
11179
+ if (!prop) {
11180
+ DRM_DEV_ERROR(vop2->dev, "create vrr prop for vp%d failed\n", vp->id);
11181
+ return -ENOMEM;
11182
+ }
11183
+ vp->variable_refresh_rate_prop = prop;
11184
+ drm_object_attach_property(&crtc->base, vp->variable_refresh_rate_prop, 0);
11185
+
11186
+ prop = drm_property_create_range(vop2->drm_dev, 0, "max refresh rate", 0, 144);
11187
+ if (!prop) {
11188
+ DRM_DEV_ERROR(vop2->dev, "create vrr prop for vp%d failed\n", vp->id);
11189
+ return -ENOMEM;
11190
+ }
11191
+ vp->max_refresh_rate_prop = prop;
11192
+ drm_object_attach_property(&crtc->base, vp->max_refresh_rate_prop, 0);
11193
+
11194
+ prop = drm_property_create_range(vop2->drm_dev, 0, "min refresh rate", 0, 144);
11195
+ if (!prop) {
11196
+ DRM_DEV_ERROR(vop2->dev, "create vrr prop for vp%d failed\n", vp->id);
11197
+ return -ENOMEM;
11198
+ }
11199
+ vp->min_refresh_rate_prop = prop;
11200
+ drm_object_attach_property(&crtc->base, vp->min_refresh_rate_prop, 0);
780611201
780711202 return 0;
780811203 }
....@@ -7877,12 +11272,13 @@
787711272 uint64_t soc_id;
787811273 uint32_t registered_num_crtcs = 0;
787911274 uint32_t plane_mask = 0;
7880
- char dclk_name[9];
11275
+ char clk_name[16];
788111276 int i = 0, j = 0, k = 0;
788211277 int ret = 0;
788311278 bool be_used_for_primary_plane = false;
788411279 bool find_primary_plane = false;
788511280 bool bootloader_initialized = false;
11281
+ struct rockchip_drm_private *private = drm_dev->dev_private;
788611282
788711283 /* all planes can attach to any crtc */
788811284 possible_crtcs = (1 << vop2_data->nr_vps) - 1;
....@@ -7921,25 +11317,40 @@
792111317 possible_crtcs = BIT(registered_num_crtcs);
792211318
792311319 /*
7924
- * we assume a vp with a zere plane_mask(set from dts or bootloader)
11320
+ * we assume a vp with a zero plane_mask(set from dts or bootloader)
792511321 * as unused.
792611322 */
7927
- if (!vp->plane_mask && bootloader_initialized)
11323
+ if (!vp->plane_mask && bootloader_initialized) {
11324
+ DRM_DEV_INFO(vop2->dev, "VP%d plane_mask is zero, so ignore register crtc\n", vp->id);
792811325 continue;
11326
+ }
792911327
793011328 if (vop2_soc_is_rk3566())
793111329 soc_id = vp_data->soc_id[1];
793211330 else
793311331 soc_id = vp_data->soc_id[0];
793411332
7935
- snprintf(dclk_name, sizeof(dclk_name), "dclk_vp%d", vp->id);
7936
- vp->dclk = devm_clk_get(vop2->dev, dclk_name);
11333
+ snprintf(clk_name, sizeof(clk_name), "dclk_vp%d", vp->id);
11334
+ vp->dclk_rst = devm_reset_control_get_optional(vop2->dev, clk_name);
11335
+ if (IS_ERR(vp->dclk_rst)) {
11336
+ DRM_DEV_ERROR(vop2->dev, "failed to get dclk reset\n");
11337
+ return PTR_ERR(vp->dclk_rst);
11338
+ }
11339
+
11340
+ vp->dclk = devm_clk_get(vop2->dev, clk_name);
793711341 if (IS_ERR(vp->dclk)) {
7938
- DRM_DEV_ERROR(vop2->dev, "failed to get %s\n", dclk_name);
11342
+ DRM_DEV_ERROR(vop2->dev, "failed to get %s\n", clk_name);
793911343 return PTR_ERR(vp->dclk);
794011344 }
794111345
7942
- crtc = &vp->crtc;
11346
+ snprintf(clk_name, sizeof(clk_name), "dclk_src_vp%d", vp->id);
11347
+ vp->dclk_parent = devm_clk_get_optional(vop2->dev, clk_name);
11348
+ if (IS_ERR(vp->dclk)) {
11349
+ DRM_DEV_ERROR(vop2->dev, "failed to get %s\n", clk_name);
11350
+ return PTR_ERR(vp->dclk);
11351
+ }
11352
+
11353
+ crtc = &vp->rockchip_crtc.crtc;
794311354
794411355 port = of_graph_get_port_by_id(dev->of_node, i);
794511356 if (!port) {
....@@ -8034,7 +11445,7 @@
803411445 }
803511446
803611447 if (vp->cursor_win_id >= 0) {
8037
- cursor = vop2_cursor_plane_init(vp);
11448
+ cursor = vop2_cursor_plane_init(vp, possible_crtcs);
803811449 if (!cursor)
803911450 DRM_WARN("failed to init cursor plane for vp%d\n", vp->id);
804011451 else
....@@ -8057,31 +11468,34 @@
805711468 init_completion(&vp->line_flag_completion);
805811469 rockchip_register_crtc_funcs(crtc, &private_crtc_funcs);
805911470 soc_id = vop2_soc_id_fixup(soc_id);
8060
- drm_object_attach_property(&crtc->base, vop2->soc_id_prop, soc_id);
8061
- drm_object_attach_property(&crtc->base, vop2->vp_id_prop, vp->id);
8062
- drm_object_attach_property(&crtc->base, vop2->aclk_prop, 0);
8063
- drm_object_attach_property(&crtc->base, vop2->bg_prop, 0);
8064
- drm_object_attach_property(&crtc->base, vop2->line_flag_prop, 0);
8065
- drm_object_attach_property(&crtc->base,
8066
- drm_dev->mode_config.tv_left_margin_property, 100);
8067
- drm_object_attach_property(&crtc->base,
8068
- drm_dev->mode_config.tv_right_margin_property, 100);
8069
- drm_object_attach_property(&crtc->base,
8070
- drm_dev->mode_config.tv_top_margin_property, 100);
8071
- drm_object_attach_property(&crtc->base,
8072
- drm_dev->mode_config.tv_bottom_margin_property, 100);
11471
+ drm_object_attach_property(&crtc->base, private->soc_id_prop, soc_id);
11472
+ drm_object_attach_property(&crtc->base, private->port_id_prop, vp->id);
11473
+ drm_object_attach_property(&crtc->base, private->aclk_prop, 0);
11474
+ drm_object_attach_property(&crtc->base, private->bg_prop, 0);
11475
+ drm_object_attach_property(&crtc->base, private->line_flag_prop, 0);
11476
+ if (vp_data->feature & VOP_FEATURE_OVERSCAN) {
11477
+ drm_object_attach_property(&crtc->base,
11478
+ drm_dev->mode_config.tv_left_margin_property, 100);
11479
+ drm_object_attach_property(&crtc->base,
11480
+ drm_dev->mode_config.tv_right_margin_property, 100);
11481
+ drm_object_attach_property(&crtc->base,
11482
+ drm_dev->mode_config.tv_top_margin_property, 100);
11483
+ drm_object_attach_property(&crtc->base,
11484
+ drm_dev->mode_config.tv_bottom_margin_property, 100);
11485
+ }
807311486 if (plane_mask)
807411487 vop2_crtc_create_plane_mask_property(vop2, crtc, plane_mask);
11488
+ vop2_crtc_create_feature_property(vop2, crtc);
11489
+ vop2_crtc_create_vrr_property(vop2, crtc);
807511490
8076
- if (vp_data->feature & VOP_FEATURE_VIVID_HDR) {
11491
+ ret = drm_self_refresh_helper_init(crtc);
11492
+ if (ret)
11493
+ DRM_DEV_DEBUG_KMS(vop2->dev,
11494
+ "Failed to init %s with SR helpers %d, ignoring\n",
11495
+ crtc->name, ret);
11496
+
11497
+ if (vp_data->feature & VOP_FEATURE_VIVID_HDR)
807711498 vop2_crtc_create_hdr_property(vop2, crtc);
8078
- vp->hdr_lut_gem_obj = rockchip_gem_create_object(vop2->drm_dev,
8079
- RK_HDRVIVID_TONE_SCA_AXI_TAB_LENGTH * 4, true, 0);
8080
- if (IS_ERR(vp->hdr_lut_gem_obj)) {
8081
- DRM_ERROR("create hdr lut obj failed\n");
8082
- return -ENOMEM;
8083
- }
8084
- }
808511499 if (vp_data->feature & VOP_FEATURE_POST_ACM)
808611500 vop2_crtc_create_post_acm_property(vop2, crtc);
808711501 if (vp_data->feature & VOP_FEATURE_POST_CSC)
....@@ -8141,7 +11555,7 @@
814111555
814211556 ret = vop2_plane_init(vop2, win, possible_crtcs);
814311557 if (ret)
8144
- DRM_WARN("failed to init overlay plane %s, ret:%d\n", win->name, ret);
11558
+ DRM_WARN("failed to init overlay plane %s\n", win->name);
814511559 }
814611560
814711561 if (is_vop3(vop2))
....@@ -8154,6 +11568,7 @@
815411568 {
815511569 struct vop2_video_port *vp = to_vop2_video_port(crtc);
815611570
11571
+ drm_self_refresh_helper_cleanup(crtc);
815711572 if (vp->hdr_lut_gem_obj)
815811573 rockchip_gem_free_object(&vp->hdr_lut_gem_obj->base);
815911574
....@@ -8167,6 +11582,59 @@
816711582 drm_flip_work_cleanup(&vp->fb_unref_work);
816811583 }
816911584
11585
+static int vop2_pd_data_init(struct vop2 *vop2)
11586
+{
11587
+ const struct vop2_data *vop2_data = vop2->data;
11588
+ const struct vop2_power_domain_data *pd_data;
11589
+ struct vop2_power_domain *pd;
11590
+ int i;
11591
+
11592
+ INIT_LIST_HEAD(&vop2->pd_list_head);
11593
+
11594
+ for (i = 0; i < vop2_data->nr_pds; i++) {
11595
+ pd_data = &vop2_data->pd[i];
11596
+ pd = devm_kzalloc(vop2->dev, sizeof(*pd), GFP_KERNEL);
11597
+ if (!pd)
11598
+ return -ENOMEM;
11599
+ pd->vop2 = vop2;
11600
+ pd->data = pd_data;
11601
+ pd->vp_mask = 0;
11602
+ spin_lock_init(&pd->lock);
11603
+ list_add_tail(&pd->list, &vop2->pd_list_head);
11604
+ INIT_DELAYED_WORK(&pd->power_off_work, vop2_power_domain_off_work);
11605
+ if (pd_data->parent_id) {
11606
+ pd->parent = vop2_find_pd_by_id(vop2, pd_data->parent_id);
11607
+ if (!pd->parent) {
11608
+ DRM_DEV_ERROR(vop2->dev, "no parent pd find for pd%d\n", pd->data->id);
11609
+ return -EINVAL;
11610
+ }
11611
+ }
11612
+ }
11613
+
11614
+ return 0;
11615
+}
11616
+
11617
+static void vop2_dsc_data_init(struct vop2 *vop2)
11618
+{
11619
+ const struct vop2_data *vop2_data = vop2->data;
11620
+ const struct vop2_dsc_data *dsc_data;
11621
+ struct vop2_dsc *dsc;
11622
+ int i;
11623
+
11624
+ for (i = 0; i < vop2_data->nr_dscs; i++) {
11625
+ dsc = &vop2->dscs[i];
11626
+ dsc_data = &vop2_data->dsc[i];
11627
+ dsc->id = dsc_data->id;
11628
+ dsc->max_slice_num = dsc_data->max_slice_num;
11629
+ dsc->max_linebuf_depth = dsc_data->max_linebuf_depth;
11630
+ dsc->min_bits_per_pixel = dsc_data->min_bits_per_pixel;
11631
+ dsc->regs = dsc_data->regs;
11632
+ dsc->attach_vp_id = -1;
11633
+ if (dsc_data->pd_id)
11634
+ dsc->pd = vop2_find_pd_by_id(vop2, dsc_data->pd_id);
11635
+ }
11636
+}
11637
+
817011638 static int vop2_win_init(struct vop2 *vop2)
817111639 {
817211640 const struct vop2_data *vop2_data = vop2->data;
....@@ -8174,8 +11642,8 @@
817411642 struct drm_prop_enum_list *plane_name_list;
817511643 struct vop2_win *win;
817611644 struct vop2_layer *layer;
8177
- struct drm_property *prop;
817811645 char name[DRM_PROP_NAME_LEN];
11646
+ char area_name[DRM_PROP_NAME_LEN];
817911647 unsigned int num_wins = 0;
818011648 uint8_t plane_id = 0;
818111649 unsigned int i, j;
....@@ -8203,6 +11671,7 @@
820311671 win->dly = win_data->dly;
820411672 win->feature = win_data->feature;
820511673 win->phys_id = win_data->phys_id;
11674
+ win->splice_win_id = win_data->splice_win_id;
820611675 win->layer_sel_id = win_data->layer_sel_id;
820711676 win->win_id = i;
820811677 win->plane_id = plane_id++;
....@@ -8213,6 +11682,9 @@
821311682 win->axi_yrgb_id = win_data->axi_yrgb_id;
821411683 win->axi_uv_id = win_data->axi_uv_id;
821511684 win->possible_crtcs = win_data->possible_crtcs;
11685
+
11686
+ if (win_data->pd_id)
11687
+ win->pd = vop2_find_pd_by_id(vop2, win_data->pd_id);
821611688
821711689 num_wins++;
821811690
....@@ -8247,12 +11719,13 @@
824711719 area->phys_id = win->phys_id;
824811720 area->area_id = j + 1;
824911721 area->plane_id = plane_id++;
8250
- snprintf(name, min(sizeof(name), strlen(win->name)), "%s", win->name);
8251
- snprintf(name, sizeof(name), "%s%d", name, area->area_id);
11722
+ snprintf(area_name, min(sizeof(area_name), strlen(win->name)), "%s", win->name);
11723
+ snprintf(name, sizeof(name), "%s%d", area_name, area->area_id);
825211724 area->name = devm_kstrdup(vop2->dev, name, GFP_KERNEL);
825311725 num_wins++;
825411726 }
825511727 }
11728
+
825611729 vop2->registered_num_wins = num_wins;
825711730
825811731 if (!is_vop3(vop2)) {
....@@ -8280,30 +11753,10 @@
828011753
828111754 vop2->plane_name_list = plane_name_list;
828211755
8283
- prop = drm_property_create_object(vop2->drm_dev,
8284
- DRM_MODE_PROP_ATOMIC | DRM_MODE_PROP_IMMUTABLE,
8285
- "SOC_ID", DRM_MODE_OBJECT_CRTC);
8286
- vop2->soc_id_prop = prop;
8287
-
8288
- prop = drm_property_create_object(vop2->drm_dev,
8289
- DRM_MODE_PROP_ATOMIC | DRM_MODE_PROP_IMMUTABLE,
8290
- "PORT_ID", DRM_MODE_OBJECT_CRTC);
8291
- vop2->vp_id_prop = prop;
8292
-
8293
- vop2->aclk_prop = drm_property_create_range(vop2->drm_dev, 0, "ACLK", 0, UINT_MAX);
8294
- vop2->bg_prop = drm_property_create_range(vop2->drm_dev, 0, "BACKGROUND", 0, UINT_MAX);
8295
-
8296
- vop2->line_flag_prop = drm_property_create_range(vop2->drm_dev, 0, "LINE_FLAG1", 0, UINT_MAX);
8297
-
8298
- if (!vop2->soc_id_prop || !vop2->vp_id_prop || !vop2->aclk_prop || !vop2->bg_prop ||
8299
- !vop2->line_flag_prop) {
8300
- DRM_DEV_ERROR(vop2->dev, "failed to create soc_id/vp_id/aclk property\n");
8301
- return -ENOMEM;
8302
- }
8303
-
830411756 return 0;
830511757 }
830611758
11759
+#include "rockchip_vop2_clk.c"
830711760 static void post_buf_empty_work_event(struct work_struct *work)
830811761 {
830911762 struct vop2 *vop2 = container_of(work, struct vop2, post_buf_empty_work);
....@@ -8323,7 +11776,7 @@
832311776 mutex_lock(&private->ovl_lock);
832411777 vop2_wait_for_fs_by_done_bit_status(vp);
832511778 VOP_MODULE_SET(vop2, vp, p2i_en, 0);
8326
- vop2_cfg_done(&vp->crtc);
11779
+ vop2_cfg_done(&vp->rockchip_crtc.crtc);
832711780 vop2_wait_for_fs_by_done_bit_status(vp);
832811781 mutex_unlock(&private->ovl_lock);
832911782
....@@ -8332,11 +11785,102 @@
833211785 mutex_lock(&private->ovl_lock);
833311786 vop2_wait_for_fs_by_done_bit_status(vp);
833411787 VOP_MODULE_SET(vop2, vp, p2i_en, 1);
8335
- vop2_cfg_done(&vp->crtc);
11788
+ vop2_cfg_done(&vp->rockchip_crtc.crtc);
833611789 vop2_wait_for_fs_by_done_bit_status(vp);
833711790 mutex_unlock(&private->ovl_lock);
833811791
833911792 vp->need_reset_p2i_flag = false;
11793
+ }
11794
+ }
11795
+}
11796
+
11797
+static bool vop2_plane_mask_check(struct vop2 *vop2)
11798
+{
11799
+ const struct vop2_data *vop2_data = vop2->data;
11800
+ u32 plane_mask = 0;
11801
+ int i;
11802
+
11803
+ /*
11804
+ * For RK3568 and RK3588, all windows need to be assigned to
11805
+ * one of all vps, and two of vps can not share the same window.
11806
+ */
11807
+ if (vop2->version != VOP_VERSION_RK3568 && vop2->version != VOP_VERSION_RK3588)
11808
+ return true;
11809
+
11810
+ for (i = 0; i < vop2_data->nr_vps; i++) {
11811
+ if (plane_mask & vop2->vps[i].plane_mask) {
11812
+ DRM_WARN("the same window can't be assigned to two vp\n");
11813
+ return false;
11814
+ }
11815
+ plane_mask |= vop2->vps[i].plane_mask;
11816
+ }
11817
+
11818
+ if (hweight32(plane_mask) != vop2_data->nr_layers ||
11819
+ plane_mask != vop2_data->plane_mask_base) {
11820
+ DRM_WARN("all windows should be assigned, full plane mask: 0x%x, current plane mask: 0x%x\n",
11821
+ vop2_data->plane_mask_base, plane_mask);
11822
+ return false;
11823
+ }
11824
+
11825
+ return true;
11826
+}
11827
+
11828
+static uint32_t vop2_vp_plane_mask_to_bitmap(const struct vop2_vp_plane_mask *vp_plane_mask)
11829
+{
11830
+ int layer_phy_id = 0;
11831
+ int plane_mask = 0;
11832
+ int i;
11833
+
11834
+ for (i = 0; i < vp_plane_mask->attached_layers_nr; i++) {
11835
+ layer_phy_id = vp_plane_mask->attached_layers[i];
11836
+ plane_mask |= BIT(layer_phy_id);
11837
+ }
11838
+
11839
+ return plane_mask;
11840
+}
11841
+
11842
+static bool vop2_get_vp_of_status(struct device_node *vp_node)
11843
+{
11844
+ struct device_node *vp_sub_node;
11845
+ struct device_node *remote_node;
11846
+ bool vp_enable = false;
11847
+
11848
+ for_each_child_of_node(vp_node, vp_sub_node) {
11849
+ remote_node = of_graph_get_remote_endpoint(vp_sub_node);
11850
+ vp_enable |= of_device_is_available(remote_node);
11851
+ }
11852
+
11853
+ return vp_enable;
11854
+}
11855
+
11856
+static void vop2_plane_mask_assign(struct vop2 *vop2, struct device_node *vop_out_node)
11857
+{
11858
+ const struct vop2_data *vop2_data = vop2->data;
11859
+ const struct vop2_vp_plane_mask *plane_mask;
11860
+ struct device_node *child;
11861
+ int active_vp_num = 0;
11862
+ int vp_id;
11863
+ int i = 0;
11864
+
11865
+ for_each_child_of_node(vop_out_node, child) {
11866
+ if (vop2_get_vp_of_status(child))
11867
+ active_vp_num++;
11868
+ }
11869
+
11870
+ if (vop2_soc_is_rk3566() && active_vp_num > 2)
11871
+ DRM_WARN("RK3566 only support 2 vps\n");
11872
+ plane_mask = vop2_data->plane_mask;
11873
+ plane_mask += (active_vp_num - 1) * ROCKCHIP_MAX_CRTC;
11874
+
11875
+ for_each_child_of_node(vop_out_node, child) {
11876
+ of_property_read_u32(child, "reg", &vp_id);
11877
+ if (vop2_get_vp_of_status(child)) {
11878
+ vop2->vps[vp_id].plane_mask = vop2_vp_plane_mask_to_bitmap(&plane_mask[i]);
11879
+ vop2->vps[vp_id].primary_plane_phy_id = plane_mask[i].primary_plane_id;
11880
+ i++;
11881
+ } else {
11882
+ vop2->vps[vp_id].plane_mask = 0;
11883
+ vop2->vps[vp_id].primary_plane_phy_id = ROCKCHIP_VOP2_PHY_ID_INVALID;
834011884 }
834111885 }
834211886 }
....@@ -8353,6 +11897,7 @@
835311897 int num_wins = 0;
835411898 int registered_num_crtcs;
835511899 struct device_node *vop_out_node;
11900
+ struct device_node *mcu_timing_node;
835611901
835711902 vop2_data = of_device_get_match_data(dev);
835811903 if (!vop2_data)
....@@ -8382,6 +11927,9 @@
838211927 vop2->disable_win_move = of_property_read_bool(dev->of_node, "disable-win-move");
838311928 vop2->skip_ref_fb = of_property_read_bool(dev->of_node, "skip-ref-fb");
838411929
11930
+ ret = vop2_pd_data_init(vop2);
11931
+ if (ret)
11932
+ return ret;
838511933 /*
838611934 * esmart lb mode default config at vop2_reg.c vop2_data.esmart_lb_mode,
838711935 * you can rewrite at dts vop node:
....@@ -8432,7 +11980,10 @@
843211980 return PTR_ERR(vop2->acm_regs);
843311981 }
843411982
8435
- vop2->grf = syscon_regmap_lookup_by_phandle(dev->of_node, "rockchip,grf");
11983
+ vop2->sys_grf = syscon_regmap_lookup_by_phandle(dev->of_node, "rockchip,grf");
11984
+ vop2->grf = syscon_regmap_lookup_by_phandle(dev->of_node, "rockchip,vop-grf");
11985
+ vop2->vo1_grf = syscon_regmap_lookup_by_phandle(dev->of_node, "rockchip,vo1-grf");
11986
+ vop2->sys_pmu = syscon_regmap_lookup_by_phandle(dev->of_node, "rockchip,pmu");
843611987
843711988 vop2->hclk = devm_clk_get(vop2->dev, "hclk_vop");
843811989 if (IS_ERR(vop2->hclk)) {
....@@ -8444,6 +11995,28 @@
844411995 DRM_DEV_ERROR(vop2->dev, "failed to get aclk source\n");
844511996 return PTR_ERR(vop2->aclk);
844611997 }
11998
+
11999
+ vop2->pclk = devm_clk_get_optional(vop2->dev, "pclk_vop");
12000
+ if (IS_ERR(vop2->pclk)) {
12001
+ DRM_DEV_ERROR(vop2->dev, "failed to get pclk source\n");
12002
+ return PTR_ERR(vop2->pclk);
12003
+ }
12004
+
12005
+ vop2->ahb_rst = devm_reset_control_get_optional(vop2->dev, "ahb");
12006
+ if (IS_ERR(vop2->ahb_rst)) {
12007
+ DRM_DEV_ERROR(vop2->dev, "failed to get ahb reset\n");
12008
+ return PTR_ERR(vop2->ahb_rst);
12009
+ }
12010
+
12011
+ vop2->axi_rst = devm_reset_control_get_optional(vop2->dev, "axi");
12012
+ if (IS_ERR(vop2->axi_rst)) {
12013
+ DRM_DEV_ERROR(vop2->dev, "failed to get axi reset\n");
12014
+ return PTR_ERR(vop2->axi_rst);
12015
+ }
12016
+
12017
+ vop2->csu_aclk = rockchip_csu_get(dev, "aclk");
12018
+ if (IS_ERR(vop2->csu_aclk))
12019
+ vop2->csu_aclk = NULL;
844712020
844812021 vop2->irq = platform_get_irq(pdev, 0);
844912022 if (vop2->irq < 0) {
....@@ -8459,6 +12032,7 @@
845912032 u32 plane_mask = 0;
846012033 u32 primary_plane_phy_id = 0;
846112034 u32 vp_id = 0;
12035
+ u32 val = 0;
846212036
846312037 of_property_read_u32(child, "rockchip,plane-mask", &plane_mask);
846412038 of_property_read_u32(child, "rockchip,primary-plane", &primary_plane_phy_id);
....@@ -8472,12 +12046,42 @@
847212046
847312047 vop2->vps[vp_id].xmirror_en = of_property_read_bool(child, "xmirror-enable");
847412048
12049
+ ret = of_clk_set_defaults(child, false);
12050
+ if (ret) {
12051
+ DRM_DEV_ERROR(dev, "Failed to set clock defaults %d\n", ret);
12052
+ return ret;
12053
+ }
12054
+
12055
+ mcu_timing_node = of_get_child_by_name(child, "mcu-timing");
12056
+ if (mcu_timing_node) {
12057
+ if (!of_property_read_u32(mcu_timing_node, "mcu-pix-total", &val))
12058
+ vop2->vps[vp_id].mcu_timing.mcu_pix_total = val;
12059
+ if (!of_property_read_u32(mcu_timing_node, "mcu-cs-pst", &val))
12060
+ vop2->vps[vp_id].mcu_timing.mcu_cs_pst = val;
12061
+ if (!of_property_read_u32(mcu_timing_node, "mcu-cs-pend", &val))
12062
+ vop2->vps[vp_id].mcu_timing.mcu_cs_pend = val;
12063
+ if (!of_property_read_u32(mcu_timing_node, "mcu-rw-pst", &val))
12064
+ vop2->vps[vp_id].mcu_timing.mcu_rw_pst = val;
12065
+ if (!of_property_read_u32(mcu_timing_node, "mcu-rw-pend", &val))
12066
+ vop2->vps[vp_id].mcu_timing.mcu_rw_pend = val;
12067
+ if (!of_property_read_u32(mcu_timing_node, "mcu-hold-mode", &val))
12068
+ vop2->vps[vp_id].mcu_timing.mcu_hold_mode = val;
12069
+ }
12070
+ }
12071
+
12072
+ if (!vop2_plane_mask_check(vop2)) {
12073
+ DRM_WARN("use default plane mask\n");
12074
+ vop2_plane_mask_assign(vop2, vop_out_node);
12075
+ }
12076
+
12077
+ for (i = 0; i < vop2->data->nr_vps; i++) {
847512078 DRM_DEV_INFO(dev, "vp%d assign plane mask: 0x%x, primary plane phy id: %d\n",
8476
- vp_id, vop2->vps[vp_id].plane_mask,
8477
- vop2->vps[vp_id].primary_plane_phy_id);
12079
+ i, vop2->vps[i].plane_mask,
12080
+ vop2->vps[i].primary_plane_phy_id);
847812081 }
847912082 }
848012083
12084
+ vop2_extend_clk_init(vop2);
848112085 spin_lock_init(&vop2->reg_lock);
848212086 spin_lock_init(&vop2->irq_lock);
848312087 mutex_init(&vop2->vop2_lock);
....@@ -8492,12 +12096,16 @@
849212096 if (ret)
849312097 return ret;
849412098
12099
+ vop2_dsc_data_init(vop2);
12100
+
849512101 registered_num_crtcs = vop2_create_crtc(vop2);
849612102 if (registered_num_crtcs <= 0)
849712103 return -ENODEV;
12104
+
849812105 ret = vop2_gamma_init(vop2);
849912106 if (ret)
850012107 return ret;
12108
+ vop2_clk_init(vop2);
850112109 vop2_cubic_lut_init(vop2);
850212110 vop2_wb_connector_init(vop2, registered_num_crtcs);
850312111 pm_runtime_enable(&pdev->dev);