Hi Sascha Hauer
From: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx> Date: 2022-03-11 16:33:21 To: dri-devel@xxxxxxxxxxxxxxxxxxxxx Cc: linux-arm-kernel@xxxxxxxxxxxxxxxxxxx,linux-rockchip@xxxxxxxxxxxxxxxxxxx,devicetree@xxxxxxxxxxxxxxx,kernel@xxxxxxxxxxxxxx,Andy Yan <andy.yan@xxxxxxxxxxxxxx>,Benjamin Gaignard <benjamin.gaignard@xxxxxxxxxxxxx>,Michael Riesch <michael.riesch@xxxxxxxxxxxxxx>,Sandy Huang <hjc@xxxxxxxxxxxxxx>,"Heiko Stübner" <heiko@xxxxxxxxx>,Peter Geis <pgwipeout@xxxxxxxxx>,Sascha Hauer <s.hauer@xxxxxxxxxxxxxx> Subject: [PATCH v8 22/24] drm: rockchip: Add VOP2 driver>From: Andy Yan <andy.yan@xxxxxxxxxxxxxx> > >The VOP2 unit is found on Rockchip SoCs beginning with rk3566/rk3568. >It replaces the VOP unit found in the older Rockchip SoCs. > >This driver has been derived from the downstream Rockchip Kernel and >heavily modified: > >- All nonstandard DRM properties have been removed >- dropped struct vop2_plane_state and pass around less data between > functions >- Dropped all DRM_FORMAT_* not known on upstream >- rework register access to get rid of excessively used macros >- Drop all waiting for framesyncs > >The driver is tested with HDMI and MIPI-DSI display on a RK3568-EVB >board. Overlay support is tested with the modetest utility. AFBC support >on the cluster windows is tested with weston-simple-dmabuf-egl on >weston using the (yet to be upstreamed) panfrost driver support. > >Signed-off-by: Andy Yan <andy.yan@xxxxxxxxxxxxxx> >Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx> >--- > >Notes: > Changes since v6: > - Drop device tree parsing during runtime > - Fix typo in Kconfig help text > > Changes since v5: > - consistently use u8/u16/u32 rather than uint8_t/uint16_t/uint32_t > - Use spin_lock rather than spin_lock_irqsave > - replace printk with drm_dbg > - break some overlong lines > > Changes since v4: > - Avoid stack frame overflow by not allocating big array on the stack > > Changes since v3: > - Sort includes > - fix typos > - Drop spinlock > - Use regmap_set_bits()/regmap_clear_bits() > - simplify vop2_scale_factor() > - simplify vop2_afbc_transform_offset() > > Changes since v4: > - Sort nodes alphabetically > > Changes since v3: > - Fix HDMI connector type > > Changes since v4: > - Add Robs Ack > > Changes since v3: > - Bring back gamma_lut regs > - Drop redundant _vop suffix from clock names > > Changes since v5: > - Drop unnecessary #size-cells/#address-cells from nodes with only single endpoint > > Changes since v5: > - consistently use u8/u16/u32 rather than uint8_t/uint16_t/uint32_t > - Use spin_lock rather than spin_lock_irqsave > - replace printk with drm_dbg > - break some overlong lines > > Changes since v4: > - Avoid stack frame overflow by not allocating big array on the stack > > Changes since v3: > - Sort includes > - fix typos > - Drop spinlock > - Use regmap_set_bits()/regmap_clear_bits() > - simplify vop2_scale_factor() > - simplify vop2_afbc_transform_offset() > > Changes since v4: > - Sort nodes alphabetically > > Changes since v3: > - Fix HDMI connector type > > drivers/gpu/drm/rockchip/Kconfig | 6 + > drivers/gpu/drm/rockchip/Makefile | 1 + > drivers/gpu/drm/rockchip/rockchip_drm_drv.c | 1 + > drivers/gpu/drm/rockchip/rockchip_drm_drv.h | 6 +- > drivers/gpu/drm/rockchip/rockchip_drm_fb.c | 2 + > drivers/gpu/drm/rockchip/rockchip_drm_vop.h | 15 + > drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 2686 ++++++++++++++++++ > drivers/gpu/drm/rockchip/rockchip_drm_vop2.h | 477 ++++ > drivers/gpu/drm/rockchip/rockchip_vop2_reg.c | 281 ++ > 9 files changed, 3474 insertions(+), 1 deletion(-) > create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_vop2.c > create mode 100644 drivers/gpu/drm/rockchip/rockchip_drm_vop2.h > create mode 100644 drivers/gpu/drm/rockchip/rockchip_vop2_reg.c > >diff --git a/drivers/gpu/drm/rockchip/Kconfig b/drivers/gpu/drm/rockchip/Kconfig >index b9b156308460a..f033971103610 100644 >--- a/drivers/gpu/drm/rockchip/Kconfig >+++ b/drivers/gpu/drm/rockchip/Kconfig >@@ -28,6 +28,12 @@ config ROCKCHIP_VOP > This selects support for the VOP driver. You should enable it > on all older SoCs up to RK3399. > >+config ROCKCHIP_VOP2 >+ bool "Rockchip VOP2 driver" >+ help >+ This selects support for the VOP2 driver. You should enable it >+ on all newer SoCs beginning from RK3568.>+rockchip newer SoCs maybe still use the old vop driver, and we are designing the next VOP, i am not sure if we will use the vop2 driver.so we can't say: "You should enable it on all newer SoCs beginning from RK3568."thanks, sandy.> config ROCKCHIP_ANALOGIX_DP > bool "Rockchip specific extensions for Analogix DP driver" > depends on ROCKCHIP_VOP >diff --git a/drivers/gpu/drm/rockchip/Makefile b/drivers/gpu/drm/rockchip/Makefile >index dfc5512fdb9f1..3ff7b21c04149 100644 >--- a/drivers/gpu/drm/rockchip/Makefile >+++ b/drivers/gpu/drm/rockchip/Makefile >@@ -6,6 +6,7 @@ > rockchipdrm-y := rockchip_drm_drv.o rockchip_drm_fb.o \ > rockchip_drm_gem.o > >+rockchipdrm-$(CONFIG_ROCKCHIP_VOP2) += rockchip_drm_vop2.o rockchip_vop2_reg.o > rockchipdrm-$(CONFIG_ROCKCHIP_VOP) += rockchip_drm_vop.o rockchip_vop_reg.o > rockchipdrm-$(CONFIG_ROCKCHIP_ANALOGIX_DP) += analogix_dp-rockchip.o > rockchipdrm-$(CONFIG_ROCKCHIP_CDN_DP) += cdn-dp-core.o cdn-dp-reg.o >diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c >index cf8dba96a7dee..7bebb293eb555 100644 >--- a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c >+++ b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c >@@ -492,6 +492,7 @@ static int __init rockchip_drm_init(void) > > num_rockchip_sub_drivers = 0; > ADD_ROCKCHIP_SUB_DRIVER(vop_platform_driver, CONFIG_ROCKCHIP_VOP); >+ ADD_ROCKCHIP_SUB_DRIVER(vop2_platform_driver, CONFIG_ROCKCHIP_VOP2); > ADD_ROCKCHIP_SUB_DRIVER(rockchip_lvds_driver, > CONFIG_ROCKCHIP_LVDS); > ADD_ROCKCHIP_SUB_DRIVER(rockchip_dp_driver, >diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_drv.h b/drivers/gpu/drm/rockchip/rockchip_drm_drv.h >index 1f66a447acada..370d9e6c8e6d5 100644 >--- a/drivers/gpu/drm/rockchip/rockchip_drm_drv.h >+++ b/drivers/gpu/drm/rockchip/rockchip_drm_drv.h >@@ -18,7 +18,7 @@ > > #define ROCKCHIP_MAX_FB_BUFFER 3 > #define ROCKCHIP_MAX_CONNECTOR 2 >-#define ROCKCHIP_MAX_CRTC 2 >+#define ROCKCHIP_MAX_CRTC 4 > > struct drm_device; > struct drm_connector; >@@ -31,6 +31,9 @@ struct rockchip_crtc_state { > int output_bpc; > int output_flags; > bool enable_afbc; >+ u32 bus_format; >+ u32 bus_flags; >+ int color_space; > }; > #define to_rockchip_crtc_state(s) \ > container_of(s, struct rockchip_crtc_state, base) >@@ -69,6 +72,7 @@ extern struct platform_driver rockchip_dp_driver; > extern struct platform_driver rockchip_lvds_driver; > extern struct platform_driver vop_platform_driver; > extern struct platform_driver rk3066_hdmi_driver; >+extern struct platform_driver vop2_platform_driver; > > static inline struct rockchip_encoder *to_rockchip_encoder(struct drm_encoder *encoder) > { >diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c >index 3aa37e177667e..0d2cb4f3922b8 100644 >--- a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c >+++ b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c >@@ -134,4 +134,6 @@ void rockchip_drm_mode_config_init(struct drm_device *dev) > > dev->mode_config.funcs = &rockchip_drm_mode_config_funcs; > dev->mode_config.helper_private = &rockchip_mode_config_helpers; >+ >+ dev->mode_config.normalize_zpos = true; > } >diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.h b/drivers/gpu/drm/rockchip/rockchip_drm_vop.h >index 857d97cdc67c6..1e364d7b50e69 100644 >--- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.h >+++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.h >@@ -54,9 +54,23 @@ struct vop_afbc { > struct vop_reg enable; > struct vop_reg win_sel; > struct vop_reg format; >+ struct vop_reg rb_swap; >+ struct vop_reg uv_swap; >+ struct vop_reg auto_gating_en; >+ struct vop_reg block_split_en; >+ struct vop_reg pic_vir_width; >+ struct vop_reg tile_num; > struct vop_reg hreg_block_split; >+ struct vop_reg pic_offset; > struct vop_reg pic_size; >+ struct vop_reg dsp_offset; >+ struct vop_reg transform_offset; > struct vop_reg hdr_ptr; >+ struct vop_reg half_block_en; >+ struct vop_reg xmirror; >+ struct vop_reg ymirror; >+ struct vop_reg rotate_270; >+ struct vop_reg rotate_90; > struct vop_reg rstn; > }; > >@@ -410,4 +424,5 @@ static inline int scl_vop_cal_lb_mode(int width, bool is_yuv) > } > > extern const struct component_ops vop_component_ops; >+ > #endif /* _ROCKCHIP_DRM_VOP_H */ >diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c >new file mode 100644 >index 0000000000000..81ff79eddb8a0 >--- /dev/null >+++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c >@@ -0,0 +1,2686 @@ >+// SPDX-License-Identifier: (GPL-2.0+ OR MIT) >+/* >+ * Copyright (c) 2020 Rockchip Electronics Co., Ltd. >+ * Author: Andy Yan <andy.yan@xxxxxxxxxxxxxx> >+ */ >+#include <linux/bitfield.h> >+#include <linux/clk.h> >+#include <linux/component.h> >+#include <linux/delay.h> >+#include <linux/iopoll.h> >+#include <linux/kernel.h> >+#include <linux/mfd/syscon.h> >+#include <linux/module.h> >+#include <linux/of.h> >+#include <linux/of_device.h> >+#include <linux/of_graph.h> >+#include <linux/platform_device.h> >+#include <linux/pm_runtime.h> >+#include <linux/regmap.h> >+#include <linux/swab.h> >+ >+#include <drm/drm.h> >+#include <drm/drm_atomic.h> >+#include <drm/drm_atomic_uapi.h> >+#include <drm/drm_crtc.h> >+#include <drm/drm_crtc_helper.h> >+#include <drm/drm_debugfs.h> >+#include <drm/drm_flip_work.h> >+#include <drm/drm_plane_helper.h> >+#include <drm/drm_probe_helper.h> >+#include <drm/drm_vblank.h> >+ >+#include <uapi/linux/videodev2.h> >+#include <dt-bindings/soc/rockchip,vop2.h> >+ >+#include "rockchip_drm_drv.h" >+#include "rockchip_drm_gem.h" >+#include "rockchip_drm_fb.h" >+#include "rockchip_drm_vop2.h" >+ >+/* >+ * VOP2 architecture >+ * >+ +----------+ +-------------+ +-----------+ >+ | Cluster | | Sel 1 from 6| | 1 from 3 | >+ | window0 | | Layer0 | | RGB | >+ +----------+ +-------------+ +---------------+ +-------------+ +-----------+ >+ +----------+ +-------------+ |N from 6 layers| | | >+ | Cluster | | Sel 1 from 6| | Overlay0 +--->| Video Port0 | +-----------+ >+ | window1 | | Layer1 | | | | | | 1 from 3 | >+ +----------+ +-------------+ +---------------+ +-------------+ | LVDS | >+ +----------+ +-------------+ +-----------+ >+ | Esmart | | Sel 1 from 6| >+ | window0 | | Layer2 | +---------------+ +-------------+ +-----------+ >+ +----------+ +-------------+ |N from 6 Layers| | | +--> | 1 from 3 | >+ +----------+ +-------------+ --------> | Overlay1 +--->| Video Port1 | | MIPI | >+ | Esmart | | Sel 1 from 6| --------> | | | | +-----------+ >+MODULE_DEVICE_TABLE(of, vop2_dt_match); >+ >+static int vop2_probe(struct platform_device *pdev) >+{ >+ struct device *dev = &pdev->dev; >+ >+ return component_add(dev, &vop2_component_ops); >+} >+...>+struct platform_driver vop2_platform_driver = { >+ .probe = vop2_probe, >+ .remove = vop2_remove, >+ .driver = { >+ .name = "rockchip-vop2", >+ .of_match_table = of_match_ptr(vop2_dt_match), >+ }, >+}; >-- >2.30.2 >