From nobody Fri Nov 29 11:34:16 2024 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.3]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 48FF5768EC; Fri, 20 Sep 2024 08:20:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.3 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820458; cv=none; b=lp/xLmt2OAF9mvaZr8womqL1u1/Zds4WPgL9q/ZmjJXB55JUskikw2q/oHrp3KCmtudREWFM5qs9KCisAncruaWCMooKincrrJ7pt14PCLnaWFwZoD/WomzGXt85gLxaj8afNJ3qpMEUQ3e+wIG2HqQDefZmj4yt5SDCKRDE0K4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820458; c=relaxed/simple; bh=x3X8RQbdE6SM570wlavJozs+cteOJyE1vQl45vVidbY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UhJg3I2W4hyj5j0mr87wYgE9HFeXJm48qGn1UOmrxcV5wVtpzZ0F4GFAQTaisAA8vmGAwwuJmmYEU+noJVd6cZ91Toytj1pJMAc0o97AXPCYZYZhnxjl7/80xeVCStIhtkjBVjaivwvpwZhASx30EzxPMHhMCXnsbIzC9tJQPKM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=A1zjcKxO; arc=none smtp.client-ip=220.197.31.3 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="A1zjcKxO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version; bh=eJHF2 pcHfplRUcW0sn9SdoBYZ2JIyxQKXVLOr2rIMTA=; b=A1zjcKxOrd+cGPnssFd3K h2kzxzUy2hScfI91w8iTCKk/SvWAaV2hh5vw0qrGfUcpM15iOlnhYkjCQbLE/7d7 4t72cqXIb0nqGcQB03i/EY/K9xAJIjKHcNmm6ziN/7sfa0eFdgJnsRktiWA+4wKD LEzEWIdaXo0blMCK/7pX9Q= Received: from ProDesk.. (unknown [58.22.7.114]) by gzga-smtp-mta-g3-0 (Coremail) with SMTP id _____wDXP0w_MO1m6A5QBg--.39714S2; Fri, 20 Sep 2024 16:20:18 +0800 (CST) From: Andy Yan To: heiko@sntech.de Cc: hjc@rock-chips.com, krzk+dt@kernel.org, robh@kernel.org, conor+dt@kernel.org, s.hauer@pengutronix.de, devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, derek.foreman@collabora.com, minhuadotchen@gmail.com, detlev.casanova@collabora.com, Andy Yan Subject: [PATCH v3 01/15] drm/rockchip: vop2: Add debugfs support Date: Fri, 20 Sep 2024 16:20:11 +0800 Message-ID: <20240920082013.6590-1-andyshrk@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240920081626.6433-1-andyshrk@163.com> References: <20240920081626.6433-1-andyshrk@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wDXP0w_MO1m6A5QBg--.39714S2 X-Coremail-Antispam: 1Uf129KBjvAXoWfJw18WFy7GF1fKryDAF1xAFb_yoW8Aw1xAo ZFgFsIqr1xtFy0qrW8Kr48tFy29F10vFn2kryjkF98Z3ZxW345KrW8GrnIvFsxArWFkFy8 Zanaq3WfXryxJayrn29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7v73VFW2AGmfu7bjvjm3 AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvjxUFHUqUUUUU X-CM-SenderInfo: 5dqg52xkunqiywtou0bp/xtbB0ghgXmWX0hsiIgABse Content-Type: text/plain; charset="utf-8" From: Andy Yan /sys/kernel/debug/dri/vop2/summary: dump vop display state /sys/kernel/debug/dri/vop2/regs: dump whole vop registers /sys/kernel/debug/dri/vop2/active_regs: only dump the registers of activated modules Signed-off-by: Andy Yan Reviewed-by: Sascha Hauer Tested-by: Detlev Casanova Tested-by: Michael Riesch # on RK3568 --- (no changes since v1) drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 260 +++++++++++++++++++ drivers/gpu/drm/rockchip/rockchip_drm_vop2.h | 11 + drivers/gpu/drm/rockchip/rockchip_vop2_reg.c | 191 ++++++++++++++ 3 files changed, 462 insertions(+) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c b/drivers/gpu/drm= /rockchip/rockchip_drm_vop2.c index 9873172e3fd3..cd861c022a66 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c @@ -24,9 +24,11 @@ #include #include #include +#include #include #include #include +#include #include #include =20 @@ -186,6 +188,7 @@ struct vop2 { */ u32 registered_num_wins; =20 + struct resource *res; void __iomem *regs; struct regmap *map; =20 @@ -237,6 +240,37 @@ struct vop2 { =20 #define vop2_output_if_is_dpi(x) ((x) =3D=3D ROCKCHIP_VOP2_EP_RGB0) =20 + +/* + * bus-format types. + */ +struct drm_bus_format_enum_list { + int type; + const char *name; +}; + +static const struct drm_bus_format_enum_list drm_bus_format_enum_list[] = =3D { + { DRM_MODE_CONNECTOR_Unknown, "Unknown" }, + { MEDIA_BUS_FMT_RGB565_1X16, "RGB565_1X16" }, + { MEDIA_BUS_FMT_RGB666_1X18, "RGB666_1X18" }, + { MEDIA_BUS_FMT_RGB666_1X24_CPADHI, "RGB666_1X24_CPADHI" }, + { MEDIA_BUS_FMT_RGB666_1X7X3_SPWG, "RGB666_1X7X3_SPWG" }, + { MEDIA_BUS_FMT_YUV8_1X24, "YUV8_1X24" }, + { MEDIA_BUS_FMT_UYYVYY8_0_5X24, "UYYVYY8_0_5X24" }, + { MEDIA_BUS_FMT_YUV10_1X30, "YUV10_1X30" }, + { MEDIA_BUS_FMT_UYYVYY10_0_5X30, "UYYVYY10_0_5X30" }, + { MEDIA_BUS_FMT_RGB888_3X8, "RGB888_3X8" }, + { MEDIA_BUS_FMT_RGB888_1X24, "RGB888_1X24" }, + { MEDIA_BUS_FMT_RGB888_1X7X4_SPWG, "RGB888_1X7X4_SPWG" }, + { MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA, "RGB888_1X7X4_JEIDA" }, + { MEDIA_BUS_FMT_UYVY8_2X8, "UYVY8_2X8" }, + { MEDIA_BUS_FMT_YUYV8_1X16, "YUYV8_1X16" }, + { MEDIA_BUS_FMT_UYVY8_1X16, "UYVY8_1X16" }, + { MEDIA_BUS_FMT_RGB101010_1X30, "RGB101010_1X30" }, + { MEDIA_BUS_FMT_YUYV10_1X20, "YUYV10_1X20" }, +}; +static DRM_ENUM_NAME_FN(drm_get_bus_format_name, drm_bus_format_enum_list) + static const struct regmap_config vop2_regmap_config; =20 static struct vop2_video_port *to_vop2_video_port(struct drm_crtc *crtc) @@ -2513,6 +2547,230 @@ static const struct drm_crtc_helper_funcs vop2_crtc= _helper_funcs =3D { .atomic_disable =3D vop2_crtc_atomic_disable, }; =20 +static void vop2_dump_connector_on_crtc(struct drm_crtc *crtc, struct seq_= file *s) +{ + struct drm_connector_list_iter conn_iter; + struct drm_connector *connector; + + drm_connector_list_iter_begin(crtc->dev, &conn_iter); + drm_for_each_connector_iter(connector, &conn_iter) { + if (crtc->state->connector_mask & drm_connector_mask(connector)) + seq_printf(s, " Connector: %s\n", connector->name); + + } + drm_connector_list_iter_end(&conn_iter); +} + +static int vop2_plane_state_dump(struct seq_file *s, struct drm_plane *pla= ne) +{ + struct vop2_win *win =3D to_vop2_win(plane); + struct drm_plane_state *pstate =3D plane->state; + struct drm_rect *src, *dst; + struct drm_framebuffer *fb; + struct drm_gem_object *obj; + struct rockchip_gem_object *rk_obj; + bool xmirror; + bool ymirror; + bool rotate_270; + bool rotate_90; + dma_addr_t fb_addr; + int i; + + seq_printf(s, " %s: %s\n", win->data->name, !pstate ? + "DISABLED" : pstate->crtc ? "ACTIVE" : "DISABLED"); + + if (!pstate || !pstate->fb) + return 0; + + fb =3D pstate->fb; + src =3D &pstate->src; + dst =3D &pstate->dst; + xmirror =3D pstate->rotation & DRM_MODE_REFLECT_X ? true : false; + ymirror =3D pstate->rotation & DRM_MODE_REFLECT_Y ? true : false; + rotate_270 =3D pstate->rotation & DRM_MODE_ROTATE_270; + rotate_90 =3D pstate->rotation & DRM_MODE_ROTATE_90; + + seq_printf(s, "\twin_id: %d\n", win->win_id); + + seq_printf(s, "\tformat: %p4cc%s glb_alpha[0x%x]\n", + &fb->format->format, + drm_is_afbc(fb->modifier) ? "[AFBC]" : "", + pstate->alpha >> 8); + seq_printf(s, "\trotate: xmirror: %d ymirror: %d rotate_90: %d rotate_270= : %d\n", + xmirror, ymirror, rotate_90, rotate_270); + seq_printf(s, "\tzpos: %d\n", pstate->normalized_zpos); + seq_printf(s, "\tsrc: pos[%d, %d] rect[%d x %d]\n", src->x1 >> 16, + src->y1 >> 16, drm_rect_width(src) >> 16, + drm_rect_height(src) >> 16); + seq_printf(s, "\tdst: pos[%d, %d] rect[%d x %d]\n", dst->x1, dst->y1, + drm_rect_width(dst), drm_rect_height(dst)); + + for (i =3D 0; i < fb->format->num_planes; i++) { + obj =3D fb->obj[i]; + rk_obj =3D to_rockchip_obj(obj); + fb_addr =3D rk_obj->dma_addr + fb->offsets[i]; + + seq_printf(s, "\tbuf[%d]: addr: %pad pitch: %d offset: %d\n", + i, &fb_addr, fb->pitches[i], fb->offsets[i]); + } + + return 0; +} + +static int vop2_crtc_state_dump(struct drm_crtc *crtc, struct seq_file *s) +{ + struct vop2_video_port *vp =3D to_vop2_video_port(crtc); + struct drm_crtc_state *cstate =3D crtc->state; + struct rockchip_crtc_state *vcstate; + struct drm_display_mode *mode; + struct drm_plane *plane; + bool interlaced; + + seq_printf(s, "Video Port%d: %s\n", vp->id, !cstate ? + "DISABLED" : cstate->active ? "ACTIVE" : "DISABLED"); + + if (!cstate || !cstate->active) + return 0; + + mode =3D &crtc->state->adjusted_mode; + vcstate =3D to_rockchip_crtc_state(cstate); + interlaced =3D !!(mode->flags & DRM_MODE_FLAG_INTERLACE); + + vop2_dump_connector_on_crtc(crtc, s); + seq_printf(s, "\tbus_format[%x]: %s\n", vcstate->bus_format, + drm_get_bus_format_name(vcstate->bus_format)); + seq_printf(s, "\toutput_mode[%x]", vcstate->output_mode); + seq_printf(s, " color_space[%d]\n", vcstate->color_space); + seq_printf(s, " Display mode: %dx%d%s%d\n", + mode->hdisplay, mode->vdisplay, interlaced ? "i" : "p", + drm_mode_vrefresh(mode)); + seq_printf(s, "\tclk[%d] real_clk[%d] type[%x] flag[%x]\n", + mode->clock, mode->crtc_clock, mode->type, mode->flags); + seq_printf(s, "\tH: %d %d %d %d\n", mode->hdisplay, mode->hsync_start, + mode->hsync_end, mode->htotal); + seq_printf(s, "\tV: %d %d %d %d\n", mode->vdisplay, mode->vsync_start, + mode->vsync_end, mode->vtotal); + + drm_atomic_crtc_for_each_plane(plane, crtc) { + vop2_plane_state_dump(s, plane); + } + + return 0; +} + +static int vop2_summary_show(struct seq_file *s, void *data) +{ + struct drm_info_node *node =3D s->private; + struct drm_minor *minor =3D node->minor; + struct drm_device *drm_dev =3D minor->dev; + struct drm_crtc *crtc; + + drm_modeset_lock_all(drm_dev); + drm_for_each_crtc(crtc, drm_dev) { + vop2_crtc_state_dump(crtc, s); + } + drm_modeset_unlock_all(drm_dev); + + return 0; +} + +static void vop2_regs_print(struct vop2 *vop2, struct seq_file *s, + const struct vop2_regs_dump *dump, bool active_only) +{ + resource_size_t start; + u32 val; + int i; + + if (dump->en_mask && active_only) { + val =3D vop2_readl(vop2, dump->base + dump->en_reg); + if ((val & dump->en_mask) !=3D dump->en_val) + return; + } + + seq_printf(s, "\n%s:\n", dump->name); + + start =3D vop2->res->start + dump->base; + for (i =3D 0; i < dump->size >> 2; i +=3D 4) { + seq_printf(s, "%08x: %08x %08x %08x %08x\n", (u32)start + i * 4, + vop2_readl(vop2, dump->base + (4 * i)), + vop2_readl(vop2, dump->base + (4 * (i + 1))), + vop2_readl(vop2, dump->base + (4 * (i + 2))), + vop2_readl(vop2, dump->base + (4 * (i + 3)))); + } +} + +static void __vop2_regs_dump(struct seq_file *s, bool active_only) +{ + struct drm_info_node *node =3D s->private; + struct vop2 *vop2 =3D node->info_ent->data; + struct drm_minor *minor =3D node->minor; + struct drm_device *drm_dev =3D minor->dev; + const struct vop2_regs_dump *dump; + unsigned int i; + + drm_modeset_lock_all(drm_dev); + + regcache_drop_region(vop2->map, 0, vop2_regmap_config.max_register); + + if (vop2->enable_count) { + for (i =3D 0; i < vop2->data->regs_dump_size; i++) { + dump =3D &vop2->data->regs_dump[i]; + vop2_regs_print(vop2, s, dump, active_only); + } + } else { + seq_printf(s, "VOP disabled\n"); + } + drm_modeset_unlock_all(drm_dev); + +} + +static int vop2_regs_show(struct seq_file *s, void *arg) +{ + __vop2_regs_dump(s, false); + + return 0; +} + +static int vop2_active_regs_show(struct seq_file *s, void *data) +{ + __vop2_regs_dump(s, true); + + return 0; +} + +static struct drm_info_list vop2_debugfs_list[] =3D { + { "summary", vop2_summary_show, 0, NULL }, + { "active_regs", vop2_active_regs_show, 0, NULL }, + { "regs", vop2_regs_show, 0, NULL }, +}; + +static void vop2_debugfs_init(struct vop2 *vop2, struct drm_minor *minor) +{ + struct dentry *root; + unsigned int i; + + root =3D debugfs_create_dir("vop2", minor->debugfs_root); + if (!IS_ERR(root)) { + for (i =3D 0; i < ARRAY_SIZE(vop2_debugfs_list); i++) + vop2_debugfs_list[i].data =3D vop2; + + drm_debugfs_create_files(vop2_debugfs_list, + ARRAY_SIZE(vop2_debugfs_list), + root, minor); + } +} + +static int vop2_crtc_late_register(struct drm_crtc *crtc) +{ + struct vop2_video_port *vp =3D to_vop2_video_port(crtc); + struct vop2 *vop2 =3D vp->vop2; + + if (drm_crtc_index(crtc) =3D=3D 0) + vop2_debugfs_init(vop2, crtc->dev->primary); + + return 0; +} + static struct drm_crtc_state *vop2_crtc_duplicate_state(struct drm_crtc *c= rtc) { struct rockchip_crtc_state *vcstate; @@ -2562,6 +2820,7 @@ static const struct drm_crtc_funcs vop2_crtc_funcs = =3D { .atomic_destroy_state =3D vop2_crtc_destroy_state, .enable_vblank =3D vop2_crtc_enable_vblank, .disable_vblank =3D vop2_crtc_disable_vblank, + .late_register =3D vop2_crtc_late_register, }; =20 static irqreturn_t vop2_isr(int irq, void *data) @@ -3106,6 +3365,7 @@ static int vop2_bind(struct device *dev, struct devic= e *master, void *data) return -EINVAL; } =20 + vop2->res =3D res; vop2->regs =3D devm_ioremap_resource(dev, res); if (IS_ERR(vop2->regs)) return PTR_ERR(vop2->regs); diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.h b/drivers/gpu/drm= /rockchip/rockchip_drm_vop2.h index 615a16196aff..59cd6b933bfb 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.h +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.h @@ -122,6 +122,15 @@ enum vop2_win_regs { VOP2_WIN_MAX_REG, }; =20 +struct vop2_regs_dump { + const char *name; + u32 base; + u32 size; + u32 en_reg; + u32 en_val; + u32 en_mask; +}; + struct vop2_win_data { const char *name; unsigned int phys_id; @@ -160,10 +169,12 @@ struct vop2_data { u64 feature; const struct vop2_win_data *win; const struct vop2_video_port_data *vp; + const struct vop2_regs_dump *regs_dump; struct vop_rect max_input; struct vop_rect max_output; =20 unsigned int win_size; + unsigned int regs_dump_size; unsigned int soc_id; }; =20 diff --git a/drivers/gpu/drm/rockchip/rockchip_vop2_reg.c b/drivers/gpu/drm= /rockchip/rockchip_vop2_reg.c index 18efb3fe1c00..8ff0bd528d65 100644 --- a/drivers/gpu/drm/rockchip/rockchip_vop2_reg.c +++ b/drivers/gpu/drm/rockchip/rockchip_vop2_reg.c @@ -258,6 +258,88 @@ static const struct vop2_win_data rk3568_vop_win_data[= ] =3D { }, }; =20 +static const struct vop2_regs_dump rk3568_regs_dump[] =3D { + { + .name =3D "SYS", + .base =3D RK3568_REG_CFG_DONE, + .size =3D 0x100, + .en_reg =3D 0, + .en_val =3D 0, + .en_mask =3D 0 + }, { + .name =3D "OVL", + .base =3D RK3568_OVL_CTRL, + .size =3D 0x100, + .en_reg =3D 0, + .en_val =3D 0, + .en_mask =3D 0, + }, { + .name =3D "VP0", + .base =3D RK3568_VP0_CTRL_BASE, + .size =3D 0x100, + .en_reg =3D RK3568_VP_DSP_CTRL, + .en_val =3D 0, + .en_mask =3D RK3568_VP_DSP_CTRL__STANDBY, + }, { + .name =3D "VP1", + .base =3D RK3568_VP1_CTRL_BASE, + .size =3D 0x100, + .en_reg =3D RK3568_VP_DSP_CTRL, + .en_val =3D 0, + .en_mask =3D RK3568_VP_DSP_CTRL__STANDBY, + }, { + .name =3D "VP2", + .base =3D RK3568_VP2_CTRL_BASE, + .size =3D 0x100, + .en_reg =3D RK3568_VP_DSP_CTRL, + .en_val =3D 0, + .en_mask =3D RK3568_VP_DSP_CTRL__STANDBY, + + }, { + .name =3D "Cluster0", + .base =3D RK3568_CLUSTER0_CTRL_BASE, + .size =3D 0x110, + .en_reg =3D RK3568_CLUSTER_WIN_CTRL0, + .en_val =3D RK3568_CLUSTER_WIN_CTRL0__WIN0_EN, + .en_mask =3D RK3568_CLUSTER_WIN_CTRL0__WIN0_EN, + }, { + .name =3D "Cluster1", + .base =3D RK3568_CLUSTER1_CTRL_BASE, + .size =3D 0x110, + .en_reg =3D RK3568_CLUSTER_WIN_CTRL0, + .en_val =3D RK3568_CLUSTER_WIN_CTRL0__WIN0_EN, + .en_mask =3D RK3568_CLUSTER_WIN_CTRL0__WIN0_EN, + }, { + .name =3D "Esmart0", + .base =3D RK3568_ESMART0_CTRL_BASE, + .size =3D 0xf0, + .en_reg =3D RK3568_SMART_REGION0_CTRL, + .en_val =3D RK3568_SMART_REGION0_CTRL__WIN0_EN, + .en_mask =3D RK3568_SMART_REGION0_CTRL__WIN0_EN, + }, { + .name =3D "Esmart1", + .base =3D RK3568_ESMART1_CTRL_BASE, + .size =3D 0xf0, + .en_reg =3D RK3568_SMART_REGION0_CTRL, + .en_val =3D RK3568_SMART_REGION0_CTRL__WIN0_EN, + .en_mask =3D RK3568_SMART_REGION0_CTRL__WIN0_EN, + }, { + .name =3D "Smart0", + .base =3D RK3568_SMART0_CTRL_BASE, + .size =3D 0xf0, + .en_reg =3D RK3568_SMART_REGION0_CTRL, + .en_val =3D RK3568_SMART_REGION0_CTRL__WIN0_EN, + .en_mask =3D RK3568_SMART_REGION0_CTRL__WIN0_EN, + }, { + .name =3D "Smart1", + .base =3D RK3568_SMART1_CTRL_BASE, + .size =3D 0xf0, + .en_reg =3D RK3568_SMART_REGION0_CTRL, + .en_val =3D RK3568_SMART_REGION0_CTRL__WIN0_EN, + .en_mask =3D RK3568_SMART_REGION0_CTRL__WIN0_EN, + }, +}; + static const struct vop2_video_port_data rk3588_vop_video_ports[] =3D { { .id =3D 0, @@ -438,6 +520,109 @@ static const struct vop2_win_data rk3588_vop_win_data= [] =3D { }, }; =20 +static const struct vop2_regs_dump rk3588_regs_dump[] =3D { + { + .name =3D "SYS", + .base =3D RK3568_REG_CFG_DONE, + .size =3D 0x100, + .en_reg =3D 0, + .en_val =3D 0, + .en_mask =3D 0 + }, { + .name =3D "OVL", + .base =3D RK3568_OVL_CTRL, + .size =3D 0x100, + .en_reg =3D 0, + .en_val =3D 0, + .en_mask =3D 0, + }, { + .name =3D "VP0", + .base =3D RK3568_VP0_CTRL_BASE, + .size =3D 0x100, + .en_reg =3D RK3568_VP_DSP_CTRL, + .en_val =3D 0, + .en_mask =3D RK3568_VP_DSP_CTRL__STANDBY, + }, { + .name =3D "VP1", + .base =3D RK3568_VP1_CTRL_BASE, + .size =3D 0x100, + .en_reg =3D RK3568_VP_DSP_CTRL, + .en_val =3D 0, + .en_mask =3D RK3568_VP_DSP_CTRL__STANDBY, + }, { + .name =3D "VP2", + .base =3D RK3568_VP2_CTRL_BASE, + .size =3D 0x100, + .en_reg =3D RK3568_VP_DSP_CTRL, + .en_val =3D 0, + .en_mask =3D RK3568_VP_DSP_CTRL__STANDBY, + + }, { + .name =3D "VP3", + .base =3D RK3588_VP3_CTRL_BASE, + .size =3D 0x100, + .en_reg =3D RK3568_VP_DSP_CTRL, + .en_val =3D 0, + .en_mask =3D RK3568_VP_DSP_CTRL__STANDBY, + }, { + .name =3D "Cluster0", + .base =3D RK3568_CLUSTER0_CTRL_BASE, + .size =3D 0x110, + .en_reg =3D RK3568_CLUSTER_WIN_CTRL0, + .en_val =3D RK3568_CLUSTER_WIN_CTRL0__WIN0_EN, + .en_mask =3D RK3568_CLUSTER_WIN_CTRL0__WIN0_EN, + }, { + .name =3D "Cluster1", + .base =3D RK3568_CLUSTER1_CTRL_BASE, + .size =3D 0x110, + .en_reg =3D RK3568_CLUSTER_WIN_CTRL0, + .en_val =3D RK3568_CLUSTER_WIN_CTRL0__WIN0_EN, + .en_mask =3D RK3568_CLUSTER_WIN_CTRL0__WIN0_EN, + }, { + .name =3D "Cluster2", + .base =3D RK3588_CLUSTER2_CTRL_BASE, + .size =3D 0x110, + .en_reg =3D RK3568_CLUSTER_WIN_CTRL0, + .en_val =3D RK3568_CLUSTER_WIN_CTRL0__WIN0_EN, + .en_mask =3D RK3568_CLUSTER_WIN_CTRL0__WIN0_EN, + }, { + .name =3D "Cluster3", + .base =3D RK3588_CLUSTER3_CTRL_BASE, + .size =3D 0x110, + .en_reg =3D RK3568_CLUSTER_WIN_CTRL0, + .en_val =3D RK3568_CLUSTER_WIN_CTRL0__WIN0_EN, + .en_mask =3D RK3568_CLUSTER_WIN_CTRL0__WIN0_EN, + }, { + .name =3D "Esmart0", + .base =3D RK3568_ESMART0_CTRL_BASE, + .size =3D 0xf0, + .en_reg =3D RK3568_SMART_REGION0_CTRL, + .en_val =3D RK3568_SMART_REGION0_CTRL__WIN0_EN, + .en_mask =3D RK3568_SMART_REGION0_CTRL__WIN0_EN, + }, { + .name =3D "Esmart1", + .base =3D RK3568_ESMART1_CTRL_BASE, + .size =3D 0xf0, + .en_reg =3D RK3568_SMART_REGION0_CTRL, + .en_val =3D RK3568_SMART_REGION0_CTRL__WIN0_EN, + .en_mask =3D RK3568_SMART_REGION0_CTRL__WIN0_EN, + }, { + .name =3D "Esmart2", + .base =3D RK3588_ESMART2_CTRL_BASE, + .size =3D 0xf0, + .en_reg =3D RK3568_SMART_REGION0_CTRL, + .en_val =3D RK3568_SMART_REGION0_CTRL__WIN0_EN, + .en_mask =3D RK3568_SMART_REGION0_CTRL__WIN0_EN, + }, { + .name =3D "Esmart3", + .base =3D RK3588_ESMART3_CTRL_BASE, + .size =3D 0xf0, + .en_reg =3D RK3568_SMART_REGION0_CTRL, + .en_val =3D RK3568_SMART_REGION0_CTRL__WIN0_EN, + .en_mask =3D RK3568_SMART_REGION0_CTRL__WIN0_EN, + }, +}; + static const struct vop2_data rk3566_vop =3D { .feature =3D VOP2_FEATURE_HAS_SYS_GRF, .nr_vps =3D 3, @@ -446,6 +631,8 @@ static const struct vop2_data rk3566_vop =3D { .vp =3D rk3568_vop_video_ports, .win =3D rk3568_vop_win_data, .win_size =3D ARRAY_SIZE(rk3568_vop_win_data), + .regs_dump =3D rk3568_regs_dump, + .regs_dump_size =3D ARRAY_SIZE(rk3568_regs_dump), .soc_id =3D 3566, }; =20 @@ -457,6 +644,8 @@ static const struct vop2_data rk3568_vop =3D { .vp =3D rk3568_vop_video_ports, .win =3D rk3568_vop_win_data, .win_size =3D ARRAY_SIZE(rk3568_vop_win_data), + .regs_dump =3D rk3568_regs_dump, + .regs_dump_size =3D ARRAY_SIZE(rk3568_regs_dump), .soc_id =3D 3568, }; =20 @@ -469,6 +658,8 @@ static const struct vop2_data rk3588_vop =3D { .vp =3D rk3588_vop_video_ports, .win =3D rk3588_vop_win_data, .win_size =3D ARRAY_SIZE(rk3588_vop_win_data), + .regs_dump =3D rk3588_regs_dump, + .regs_dump_size =3D ARRAY_SIZE(rk3588_regs_dump), .soc_id =3D 3588, }; =20 --=20 2.34.1 From nobody Fri Nov 29 11:34:16 2024 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.5]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 29D24770FE; Fri, 20 Sep 2024 08:21:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820473; cv=none; b=LePs8DGLBCSPTiNkkQPZa3HzWmFnMwxeSuYcmqzFLof18Em5C5GfQjFjmLGWjtcphnNv3ejsgbXqZiZYTxQx77wCUGf4WTipBpPNkoK68bWMYw2QkMT7uUYHVbhSreqYJg0FWZU6IpHBK3/BY23HmPX6GefLGDM5FCSVpA90h/Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820473; c=relaxed/simple; bh=ryHQMHCPPZJodfqNIYsZ85GCvifO/TIN92/nFcCWRvY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gIeWxkfgTF2XIR63L9c46uC1ZFFYr3Zv01itmqy7lqxUommXwI3DWp2n1kABgoL6JGPsZPMlOSreK7ZYH437eZtUTjAEenlrgHYYIIm0GHANznyBsvudH5hJb/S/S05/gZGBR4miUlzySsRwtMqXXY8fM0KhSlSnpqdHrNU0mwU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=Ms/OpU2x; arc=none smtp.client-ip=117.135.210.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="Ms/OpU2x" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version; bh=GBq4X 3SvjcKdAw76+LCZ96Aeae4FkXSnYqiBRPXZuM4=; b=Ms/OpU2xi0lF+5s6ABh2o yW/zFVMA64LbYDTSwaf8EpKAuzQzwpnTPAZF2sZv/aDKCbf4B0mbFz80m0BJLE0a Pd6MftUJWeiep/YPfLfiEDyVnfBX6AX6tdjSa4ZXqTm5D6znQLto6ceTurcepa0T iARi+8b9tBdYiKKv6gjbx0= Received: from ProDesk.. (unknown [58.22.7.114]) by gzga-smtp-mta-g3-0 (Coremail) with SMTP id _____wCnL3ZVMO1mBh1QBg--.6466S2; Fri, 20 Sep 2024 16:20:40 +0800 (CST) From: Andy Yan To: heiko@sntech.de Cc: hjc@rock-chips.com, krzk+dt@kernel.org, robh@kernel.org, conor+dt@kernel.org, s.hauer@pengutronix.de, devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, derek.foreman@collabora.com, minhuadotchen@gmail.com, detlev.casanova@collabora.com, Andy Yan Subject: [PATCH v3 02/15] drm/rockchip: Set dma mask to 64 bit Date: Fri, 20 Sep 2024 16:20:23 +0800 Message-ID: <20240920082036.6623-1-andyshrk@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240920081626.6433-1-andyshrk@163.com> References: <20240920081626.6433-1-andyshrk@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wCnL3ZVMO1mBh1QBg--.6466S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7CF1xur1rJr1fWF13GFWUtwb_yoW8WFWfp3 s0kFZrKrW8GayDXFWjkFsxAF45Kw1vya17G343JwnxJw17Krn8A3ZI9FyDt3y3Jr1xC3Wa yrsxKrWI9Fs2vr7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jFT5dUUUUU= X-CM-SenderInfo: 5dqg52xkunqiywtou0bp/xtbB0h5gXmWX0hsr2QAAs7 Content-Type: text/plain; charset="utf-8" From: Andy Yan The vop mmu support translate physical address upper 4 GB to iova below 4 GB. So set dma mask to 64 bit to indicate we support address > 4GB. This can avoid warnging message like this on some boards with DDR > 4 GB: rockchip-drm display-subsystem: swiotlb buffer is full (sz: 266240 bytes), = total 32768 (slots), used 130 (slots) rockchip-drm display-subsystem: swiotlb buffer is full (sz: 266240 bytes), = total 32768 (slots), used 0 (slots) rockchip-drm display-subsystem: swiotlb buffer is full (sz: 266240 bytes), = total 32768 (slots), used 130 (slots) rockchip-drm display-subsystem: swiotlb buffer is full (sz: 266240 bytes), = total 32768 (slots), used 130 (slots) rockchip-drm display-subsystem: swiotlb buffer is full (sz: 266240 bytes), = total 32768 (slots), used 0 (slots) Signed-off-by: Andy Yan Tested-by: Derek Foreman Tested-by: Detlev Casanova Tested-by: Michael Riesch # on RK3568 --- (no changes since v1) drivers/gpu/drm/rockchip/rockchip_drm_drv.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c b/drivers/gpu/drm/= rockchip/rockchip_drm_drv.c index 04ef7a2c3833..8bc2ff3b04bb 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c @@ -445,7 +445,9 @@ static int rockchip_drm_platform_probe(struct platform_= device *pdev) return ret; } =20 - return 0; + ret =3D dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(64)); + + return ret; } =20 static void rockchip_drm_platform_remove(struct platform_device *pdev) --=20 2.34.1 From nobody Fri Nov 29 11:34:16 2024 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.2]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7094F7DA87; Fri, 20 Sep 2024 08:21:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820484; cv=none; b=YfltM134pemmd7mpCMSviZo9+1tYPJk+0CYmoZN1oqoBtgsK3nrz6CmMlfJ28C7YHN4V+TO2WZbKg3LXnbeI+isYVb0X5YseJK/i4lxMQ9+fh8uXXkWaZkhvT9kEkV3cs1x5rJyKJf8LmydBBVzMcYNoCDT653aVrEEvj1CVDNg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820484; c=relaxed/simple; bh=EOmQhYbiLlUqTbcn5CgQdOL+C2Ftj8u4+F/UP5qISAs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XXN3R7TXBRrTJPuQgKCj0cXbRVjlhmZiUe+DnTHzgegkiFrb2aLbJlt96RfR6Ehs4gCDgwV2vdKrnltjVbED2l4zYvu7g4dCQGzIb4xYgZODGLKjQrwjKeRL6aAHBKIKCih6ZySYmt4ZHWutQhF30nAbssL+knMWC9MKR9wjm9E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=Pq7VX52/; arc=none smtp.client-ip=117.135.210.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="Pq7VX52/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version; bh=zdtnZ XQBgydk7bGZT06QonATEgeUXXTkYAaR5QACEzM=; b=Pq7VX52/XcUYMTCmb+EWy v3pUqQwk8yoVMRQJDieiRywKAsTFlnu1zbkCAec9q5GMOPaMO6IcMn1S4hNHtJvt V0P2KNt8q9zSpb4v1UTqQOj+zA2wCDh/HrrzzQn6m4qErMkHxtbv/vRNxu53z+uu Osny7jiV6SfekFa/Zj/MwU= Received: from ProDesk.. (unknown [58.22.7.114]) by gzga-smtp-mta-g3-0 (Coremail) with SMTP id _____wD3P2phMO1mxSRQBg--.39474S2; Fri, 20 Sep 2024 16:20:53 +0800 (CST) From: Andy Yan To: heiko@sntech.de Cc: hjc@rock-chips.com, krzk+dt@kernel.org, robh@kernel.org, conor+dt@kernel.org, s.hauer@pengutronix.de, devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, derek.foreman@collabora.com, minhuadotchen@gmail.com, detlev.casanova@collabora.com, Andy Yan Subject: [PATCH v3 03/15] drm/rockchip: vop2: Fix cluster windows alpha ctrl regsiters offset Date: Fri, 20 Sep 2024 16:20:46 +0800 Message-ID: <20240920082048.6654-1-andyshrk@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240920081626.6433-1-andyshrk@163.com> References: <20240920081626.6433-1-andyshrk@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wD3P2phMO1mxSRQBg--.39474S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Ar4kZr1ktry3Xw1DJw18Krg_yoW8urWkpF y7Ar98Xr47KFs0gr4xJrWDuryfKws2kFWxAF97K3WYgry3Kr9rC3Wq93WDCry5JFy7Cr12 ka9xGry7uF4jkF7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jF7KsUUUUU= X-CM-SenderInfo: 5dqg52xkunqiywtou0bp/1tbiMxJgXmbtL08ijAAAsa Content-Type: text/plain; charset="utf-8" From: Andy Yan The phy_id of cluster windws are not increase one for each window. Fixes: 604be85547ce ("drm/rockchip: Add VOP2 driver") Signed-off-by: Andy Yan Tested-by: Derek Foreman Tested-by: Detlev Casanova Tested-by: Michael Riesch # on RK3568 --- (no changes since v1) drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c b/drivers/gpu/drm= /rockchip/rockchip_drm_vop2.c index cd861c022a66..bff190151ae8 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c @@ -2193,7 +2193,6 @@ static int vop2_find_start_mixer_id_for_vp(struct vop= 2 *vop2, u8 port_id) =20 static void vop2_setup_cluster_alpha(struct vop2 *vop2, struct vop2_win *m= ain_win) { - u32 offset =3D (main_win->data->phys_id * 0x10); struct vop2_alpha_config alpha_config; struct vop2_alpha alpha; struct drm_plane_state *bottom_win_pstate; @@ -2201,6 +2200,7 @@ static void vop2_setup_cluster_alpha(struct vop2 *vop= 2, struct vop2_win *main_wi u16 src_glb_alpha_val, dst_glb_alpha_val; bool premulti_en =3D false; bool swap =3D false; + u32 offset =3D 0; =20 /* At one win mode, win0 is dst/bottom win, and win1 is a all zero src/to= p win */ bottom_win_pstate =3D main_win->base.state; @@ -2219,6 +2219,22 @@ static void vop2_setup_cluster_alpha(struct vop2 *vo= p2, struct vop2_win *main_wi vop2_parse_alpha(&alpha_config, &alpha); =20 alpha.src_color_ctrl.bits.src_dst_swap =3D swap; + + switch (main_win->data->phys_id) { + case ROCKCHIP_VOP2_CLUSTER0: + offset =3D 0x0; + break; + case ROCKCHIP_VOP2_CLUSTER1: + offset =3D 0x10; + break; + case ROCKCHIP_VOP2_CLUSTER2: + offset =3D 0x20; + break; + case ROCKCHIP_VOP2_CLUSTER3: + offset =3D 0x30; + break; + } + vop2_writel(vop2, RK3568_CLUSTER0_MIX_SRC_COLOR_CTRL + offset, alpha.src_color_ctrl.val); vop2_writel(vop2, RK3568_CLUSTER0_MIX_DST_COLOR_CTRL + offset, --=20 2.34.1 From nobody Fri Nov 29 11:34:16 2024 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.3]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1EA1B7D401; Fri, 20 Sep 2024 08:21:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.3 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820501; cv=none; b=eVvUc5CHk0kTyV+dc5AByU9pUZFzg6bH3p2G7ibzwo1osvbn5hCCsg0dyNJefqq8wCCc4MlTEYqlUzWe4LqMBW1Wqj0GF+7sreD/h2qx3kTsm7J92ulJyKotd6H/f/K424H3tg41/Q6L9rts7Nn7j1jDhx40gUc8EO6h557+324= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820501; c=relaxed/simple; bh=IadptqnbaT9c2K1pNM/SXaZhFjND1guNP3ocQdMNleU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fMdT3962cNj9wsTPlPDh1JiCPpw15SWPdUWpumuUDgYXaX7kfjjXPozWSMqjLbsK/9hZsjipwfirzFbtQA50ujbifk+jI5d93RrGDJjBDuusXIBGr8n6kte6Xq/xOB66GIPLaFd66mhOQeM8bjepextQ1RdT/P/a6lU8il3uDwc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=TGGmPIpd; arc=none smtp.client-ip=117.135.210.3 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="TGGmPIpd" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version; bh=0GYSG +chUw6Ysv1qyoAIdKhyk6i2g6/WZX6U7MclNH0=; b=TGGmPIpdvvXtsugOEABzZ /I8bOStNtgaFjjNuuYCoL2cRqbQXK2SMdQieRctHtlUT+WOIRXHwcNY+m/KYCoFD 1OvtuQxSm1GCKCg6ZIzEUpzNXk5RSXv2np3aQbdG3bynpnZ8AwLfW6nEsd5XktS7 a50W+lLehX2fASanH1cXeU= Received: from ProDesk.. (unknown [58.22.7.114]) by gzga-smtp-mta-g3-1 (Coremail) with SMTP id _____wDX3_dtMO1mi4uaBQ--.13042S2; Fri, 20 Sep 2024 16:21:05 +0800 (CST) From: Andy Yan To: heiko@sntech.de Cc: hjc@rock-chips.com, krzk+dt@kernel.org, robh@kernel.org, conor+dt@kernel.org, s.hauer@pengutronix.de, devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, derek.foreman@collabora.com, minhuadotchen@gmail.com, detlev.casanova@collabora.com, Andy Yan Subject: [PATCH v3 04/15] drm/rockchip: vop2: Fix the mixer alpha setup for layer 0 Date: Fri, 20 Sep 2024 16:20:58 +0800 Message-ID: <20240920082100.6683-1-andyshrk@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240920081626.6433-1-andyshrk@163.com> References: <20240920081626.6433-1-andyshrk@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wDX3_dtMO1mi4uaBQ--.13042S2 X-Coremail-Antispam: 1Uf129KBjvdXoW7XF4rXr13WF4kZr45GFWfKrg_yoWkKFg_G3 4fWrn3Grn7GFn8Jw1jka1fGFZ2yan2kF18Ga1DtF90yFykA3Wxta4rXryxX34UCF4rAr97 G3W8Xw1rCrnxWjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IU8AWrJUUUUU== X-CM-SenderInfo: 5dqg52xkunqiywtou0bp/1tbiMxJgXmbtL08ijAACsY Content-Type: text/plain; charset="utf-8" From: Andy Yan The alpha setup should start from the second layer, the current calculation starts incorrectly from the first layer, a negative offset will be obtained in the following formula: offset =3D (mixer_id + zpos - 1) * 0x10 Fixes: 604be85547ce ("drm/rockchip: Add VOP2 driver") Signed-off-by: Andy Yan Tested-by: Derek Foreman Tested-by: Detlev Casanova Tested-by: Michael Riesch # on RK3568 --- (no changes since v1) drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c b/drivers/gpu/drm= /rockchip/rockchip_drm_vop2.c index bff190151ae8..c50d93df8404 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c @@ -2282,6 +2282,12 @@ static void vop2_setup_alpha(struct vop2_video_port = *vp) struct vop2_win *win =3D to_vop2_win(plane); int zpos =3D plane->state->normalized_zpos; =20 + /* + * Need to configure alpha from second layer. + */ + if (zpos =3D=3D 0) + continue; + if (plane->state->pixel_blend_mode =3D=3D DRM_MODE_BLEND_PREMULTI) premulti_en =3D 1; else --=20 2.34.1 From nobody Fri Nov 29 11:34:16 2024 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.4]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7338882876; Fri, 20 Sep 2024 08:21:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820504; cv=none; b=ZvISJtVqbNFw15FN/jDSYvGy0dtsM10FEYO4M5b9Tz3brdCCusAaLVRzvjGlUJmJ8PvxL9ZWGujYZ0kDwqVpE37FudE3BuLD5dbHkT+pFEhSd4Yb/fjcqXdleh8RTOqfcohqfW9GZ/L3850AJoVtncbiE+QQUfVpOHpBN3iFX/E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820504; c=relaxed/simple; bh=NkJZMKGNeBL80jNOVq4j9ciirDMAEdlUiDgcdlD0BZw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lNeJ6jQaMNABRZyxZc8XPdKn1/op8jMa8EogutekHrfQYAB6v88KJxfihvPupxDR/e7bdqC4r3rRGYnPMrQNo2Wz9Gxe8HLOkTAXpPpMqssyxskFsUAzWfS/xuEBDzRPxjd7l1mNloSxLv+2rcLprm5LX6p/Adxvgz00wVKizLA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=aCLjwB4V; arc=none smtp.client-ip=220.197.31.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="aCLjwB4V" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version; bh=SU0ce PcU3UeiZAFIZupQ6VPwSqSkMbhiZUCKiN2xRRc=; b=aCLjwB4VlDI1eEKQcJFTM VpLSfIx7+mp95MaETbeYJ6QQ5IjKrFPNz/vW0FNF2X6Ty1wm/Y8vnoODylmIR52X H04a28qrP8Rx9F43UlSCPH+9DRWeqqcyY4rJgaev3rtff3QqsThdjyd+FLDcJLhu fdVasNVM9hnWvd+aojXMjY= Received: from ProDesk.. (unknown [58.22.7.114]) by gzsmtp2 (Coremail) with SMTP id sSgvCgBnY9R4MO1mbdlnBg--.49799S2; Fri, 20 Sep 2024 16:21:16 +0800 (CST) From: Andy Yan To: heiko@sntech.de Cc: hjc@rock-chips.com, krzk+dt@kernel.org, robh@kernel.org, conor+dt@kernel.org, s.hauer@pengutronix.de, devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, derek.foreman@collabora.com, minhuadotchen@gmail.com, detlev.casanova@collabora.com, Andy Yan Subject: [PATCH v3 05/15] drm/rockchip: vop2: Fix the windows switch between different layers Date: Fri, 20 Sep 2024 16:21:10 +0800 Message-ID: <20240920082111.6712-1-andyshrk@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240920081626.6433-1-andyshrk@163.com> References: <20240920081626.6433-1-andyshrk@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: sSgvCgBnY9R4MO1mbdlnBg--.49799S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxZw4fWF4DAFW7Gw15ur4fAFb_yoW5CF13pF 15WrWjgw4UKFsIqr9rtr48uF4ay397Kay7W3Z7tw1rGFy8tr1DJan8Cr9ayryUGFn3uryj yr1Uur909FWjyF7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jFSoJUUUUU= X-CM-SenderInfo: 5dqg52xkunqiywtou0bp/1tbiqRxgXmVODBHcAgAAsj Content-Type: text/plain; charset="utf-8" From: Andy Yan Every layer of vop2 should bind a window, and we also need to make sure that this window is not used by other layer. 0x5 is a reserved layer sel value on rk3568, but it will select Cluster3 on rk3588, configure unused layers to 0x5 will lead alpha blending error on rk3588. When we bind a window from layerM to layerN, we move the old window on layerN to layerM. Fixes: 604be85547ce ("drm/rockchip: Add VOP2 driver") Signed-off-by: Andy Yan Tested-by: Derek Foreman Tested-by: Detlev Casanova Tested-by: Michael Riesch # on RK3568 --- (no changes since v1) drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 38 +++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c b/drivers/gpu/drm= /rockchip/rockchip_drm_vop2.c index c50d93df8404..4776a227e62c 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c @@ -2364,7 +2364,9 @@ static void vop2_setup_layer_mixer(struct vop2_video_= port *vp) struct drm_plane *plane; u32 layer_sel =3D 0; u32 port_sel; - unsigned int nlayer, ofs; + u8 old_layer_id; + u8 layer_sel_id; + unsigned int ofs; u32 ovl_ctrl; int i; struct vop2_video_port *vp0 =3D &vop2->vps[0]; @@ -2408,9 +2410,28 @@ static void vop2_setup_layer_mixer(struct vop2_video= _port *vp) for (i =3D 0; i < vp->id; i++) ofs +=3D vop2->vps[i].nlayers; =20 - nlayer =3D 0; drm_atomic_crtc_for_each_plane(plane, &vp->crtc) { struct vop2_win *win =3D to_vop2_win(plane); + struct vop2_win *old_win; + + /* + * Find the layer this win bind in old state. + */ + for (old_layer_id =3D 0; old_layer_id < vop2->data->win_size; old_layer_= id++) { + layer_sel_id =3D (layer_sel >> (4 * old_layer_id)) & 0xf; + if (layer_sel_id =3D=3D win->data->layer_sel_id) + break; + } + + /* + * Find the win bind to this layer in old state + */ + for (i =3D 0; i < vop2->data->win_size; i++) { + old_win =3D &vop2->win[i]; + layer_sel_id =3D (layer_sel >> (4 * (plane->state->normalized_zpos + of= s))) & 0xf; + if (layer_sel_id =3D=3D old_win->data->layer_sel_id) + break; + } =20 switch (win->data->phys_id) { case ROCKCHIP_VOP2_CLUSTER0: @@ -2459,13 +2480,12 @@ static void vop2_setup_layer_mixer(struct vop2_vide= o_port *vp) 0x7); layer_sel |=3D RK3568_OVL_LAYER_SEL__LAYER(plane->state->normalized_zpos= + ofs, win->data->layer_sel_id); - nlayer++; - } - - /* configure unused layers to 0x5 (reserved) */ - for (; nlayer < vp->nlayers; nlayer++) { - layer_sel &=3D ~RK3568_OVL_LAYER_SEL__LAYER(nlayer + ofs, 0x7); - layer_sel |=3D RK3568_OVL_LAYER_SEL__LAYER(nlayer + ofs, 5); + /* + * When we bind a window from layerM to layerN, we also need to move the= old + * window on layerN to layerM to avoid one window selected by two or mor= e layers. + */ + layer_sel &=3D ~RK3568_OVL_LAYER_SEL__LAYER(old_layer_id, 0x7); + layer_sel |=3D RK3568_OVL_LAYER_SEL__LAYER(old_layer_id, old_win->data->= layer_sel_id); } =20 vop2_writel(vop2, RK3568_OVL_LAYER_SEL, layer_sel); --=20 2.34.1 From nobody Fri Nov 29 11:34:16 2024 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.4]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F0729770ED; Fri, 20 Sep 2024 08:21:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820522; cv=none; b=bZmzI04GQpJ9MxxpFE2McnDcgHWRqp+FUevxANOLx6mRQhVLVp+luiO6N6sgBkegbKrZLTn8wH2ZZ+yg2RAD4wnu2mcI+FLVJORePql4hgyA1IQXleII5B05cODOuWpozbF4GCk58AlD54yFPUrISZGTFy7ObQnVJG/lzbA4qMM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820522; c=relaxed/simple; bh=uV7PUiyIYsNO0DHtNqE/2KADFoDucxgrHHpWDPxEEkI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oDKuOYfQZX6LM0y06I2yBl926iOoimyWdq89gV4L7xXmZBlWmeO6WJtrdz67dz8nPj9xAMFK7ZHNc2an8sEAr7vNrukGo+LvHvGtkJkSwW3BKV7SniSto6kca06pm+ciCwQNiAuIfBb2b6HQjVSnNhwGZzmA3fpr756L84WrE6Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=W2T7HbBL; arc=none smtp.client-ip=220.197.31.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="W2T7HbBL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version; bh=bxwDJ AkXvK8AdSR7veh+eMKRy+rJ61dS+tkTSOb3PvE=; b=W2T7HbBLhfMxj+T45i8BB X+sfflFZsdpik4Yj/CfQu00Nz2Tu4GUIvPK0r+tOhvNoQwN6Q0P1ij/YUxoYX4wb /RXFhkoDvGwGvYQvLkTLZSiab1h/xa0jBrKaL11u/r+SFq4VWTmAdLzfJTAGM6CG NIYDfuyJHevDCwP5n8GVhY= Received: from ProDesk.. (unknown [58.22.7.114]) by gzga-smtp-mta-g3-4 (Coremail) with SMTP id _____wD3X7mDMO1m_7DTEw--.2482S2; Fri, 20 Sep 2024 16:21:26 +0800 (CST) From: Andy Yan To: heiko@sntech.de Cc: hjc@rock-chips.com, krzk+dt@kernel.org, robh@kernel.org, conor+dt@kernel.org, s.hauer@pengutronix.de, devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, derek.foreman@collabora.com, minhuadotchen@gmail.com, detlev.casanova@collabora.com, Andy Yan Subject: [PATCH v3 06/15] drm/rockchip: vop2: include rockchip_drm_drv.h Date: Fri, 20 Sep 2024 16:21:21 +0800 Message-ID: <20240920082122.6742-1-andyshrk@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240920081626.6433-1-andyshrk@163.com> References: <20240920081626.6433-1-andyshrk@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wD3X7mDMO1m_7DTEw--.2482S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Aw15AryUXr1xtry5JF43KFg_yoW8CF4UpF s8AFWUZrWxKFWjqr1DAF9xCr4Fy3ZrCayxGFn7G3ZxZF17KFyDGwnru3s8JrZrXr47ZF42 krs3J34UAF42vr7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UZIDcUUUUU= X-CM-SenderInfo: 5dqg52xkunqiywtou0bp/1tbiMw5gXmbtL08mhAAAsK Content-Type: text/plain; charset="utf-8" From: Andy Yan Move rockchip_drm_drv.h in rockchip_drm_vop2.h to fix the follow sparse warning: ARCH=3Darm64 LLVM=3D1 make C=3D1 CF=3D'-fdiagnostic-prefix -D__CHECK_ENDIAN= __' mrproper defconfig all -j12 drivers/gpu/drm/rockchip/rockchip_vop2_reg.c:502:24: sparse: warning: symbol 'vop2_platform_driver' was not declared. Should it be static? It is also beneficial for the upcoming support for rk3576. Fixes: 604be85547ce ("drm/rockchip: Add VOP2 driver") Signed-off-by: Andy Yan Signed-off-by: Min-Hua Chen Reviewed-by: Min-Hua Chen Tested-by: Detlev Casanova Tested-by: Michael Riesch # on RK3568 --- Changes in v3: - Split it from 10/15, as it fix a exiting compile warning. drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 1 - drivers/gpu/drm/rockchip/rockchip_drm_vop2.h | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c b/drivers/gpu/drm= /rockchip/rockchip_drm_vop2.c index 4776a227e62c..a7f9f88869a6 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c @@ -35,7 +35,6 @@ #include #include =20 -#include "rockchip_drm_drv.h" #include "rockchip_drm_gem.h" #include "rockchip_drm_vop2.h" #include "rockchip_rgb.h" diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.h b/drivers/gpu/drm= /rockchip/rockchip_drm_vop2.h index 59cd6b933bfb..bc001f715847 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.h +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.h @@ -9,6 +9,7 @@ =20 #include #include +#include "rockchip_drm_drv.h" #include "rockchip_drm_vop.h" =20 #define VOP2_VP_FEATURE_OUTPUT_10BIT BIT(0) --=20 2.34.1 From nobody Fri Nov 29 11:34:16 2024 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.3]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9AC821311AC; Fri, 20 Sep 2024 08:22:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.3 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820528; cv=none; b=iLuLRiMgiZAccCel478i6sKeOb0zneYjfEnNvFYHVg0s8ZFJqDvmO4mmXPz4WlkqoWT5EMR4LH39CLwMjH3hLGX3vwteKLhW3Tq/cTUxvlzz8el6mrPDj1sWlrP6FmddkfjVuUfuPBD/+Mmi2kmmVj0jwd/5FrSoSDtmRxpzZ3w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820528; c=relaxed/simple; bh=2qmbHyqDgpozMZtbVr2bnHgnBVuWqIWsPpUf7E72uJU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SV2jlDvjCqCNACAaCxSTOttHXpNyu5xlpC4N+v+TIcnS135Rjvy/HBmM2FyHTYeZgIrC3+q5mULEkWxbFo7W7PRprYa37wSfF3qJ43IG2EKHZVcXmN1WdVAcSNgRmFjxIZLsn4siwnr59ctAJl/umbkVVf5TYysNfrvIbTkKBUY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=Y/BKataO; arc=none smtp.client-ip=220.197.31.3 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="Y/BKataO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version; bh=x6qQR zhQ+WwsX3+8y8fTI3CGANuJPV4QqizubWTDtQw=; b=Y/BKataO75IhJ5SZDZYzg tE61C9BjjHanvFStHjRJXIFvH+hiAzA7aqCrxWlg8UUnLTiv/6HCE7b+V4Gf/OQg mKFpZLLc1ec30TLhEw+lEx5ma20WlgFR19yRrvDFcMOtq89T+2JnHPmCzKt825dL P8yJxUduwFPCNtY2XWKbv4= Received: from ProDesk.. (unknown [58.22.7.114]) by gzga-smtp-mta-g2-3 (Coremail) with SMTP id _____wDXJxiNMO1m7rcECA--.53890S2; Fri, 20 Sep 2024 16:21:36 +0800 (CST) From: Andy Yan To: heiko@sntech.de Cc: hjc@rock-chips.com, krzk+dt@kernel.org, robh@kernel.org, conor+dt@kernel.org, s.hauer@pengutronix.de, devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, derek.foreman@collabora.com, minhuadotchen@gmail.com, detlev.casanova@collabora.com, Andy Yan Subject: [PATCH v3 07/15] drm/rockchip: vop2: Support 32x8 superblock afbc Date: Fri, 20 Sep 2024 16:21:31 +0800 Message-ID: <20240920082132.6771-1-andyshrk@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240920081626.6433-1-andyshrk@163.com> References: <20240920081626.6433-1-andyshrk@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wDXJxiNMO1m7rcECA--.53890S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Cw17Cr13GF1UAF18Wry3Jwb_yoW5Jr18pr W3ZrWqgr4DKF1jqa1DJFZ8ZF45Aan2k3y7XFnrKr1jgryYkrZrWa4qka4UZrWDtrWfGFW0 vFn7JrW7Zw1Fyr7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UKksgUUUUU= X-CM-SenderInfo: 5dqg52xkunqiywtou0bp/1tbiMxhgXmbtL08n3AAAsF Content-Type: text/plain; charset="utf-8" From: Andy Yan This is the only afbc format supported by the upcoming VOP for rk3576. Add support for it. Signed-off-by: Andy Yan Tested-by: Detlev Casanova Tested-by: Michael Riesch # on RK3568 --- (no changes since v2) Changes in v2: - split it from main patch add support for rk3576 drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c b/drivers/gpu/drm= /rockchip/rockchip_drm_vop2.c index a7f9f88869a6..f6a030fd8e55 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c @@ -1357,16 +1357,18 @@ static void vop2_plane_atomic_update(struct drm_pla= ne *plane, vop2_win_write(win, VOP2_WIN_AFBC_HALF_BLOCK_EN, half_block_en); =20 if (afbc_en) { - u32 stride; + u32 stride, block_w; + + /* the afbc superblock is 16 x 16 or 32 x 8 */ + block_w =3D fb->modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_32x8 ? 32 : 16; =20 - /* the afbc superblock is 16 x 16 */ afbc_format =3D vop2_convert_afbc_format(fb->format->format); =20 /* Enable color transform for YTR */ if (fb->modifier & AFBC_FORMAT_MOD_YTR) afbc_format |=3D (1 << 4); =20 - afbc_tile_num =3D ALIGN(actual_w, 16) >> 4; + afbc_tile_num =3D ALIGN(actual_w, block_w) / block_w; =20 /* * AFBC pic_vir_width is count by pixel, this is different @@ -1377,6 +1379,9 @@ static void vop2_plane_atomic_update(struct drm_plane= *plane, drm_err(vop2->drm, "vp%d %s stride[%d] not 64 pixel aligned\n", vp->id, win->data->name, stride); =20 + /* It's for head stride, each head size is 16 byte */ + stride =3D ALIGN(stride, block_w) / block_w * 16; + uv_swap =3D vop2_afbc_uv_swap(fb->format->format); /* * This is a workaround for crazy IC design, Cluster @@ -1407,7 +1412,11 @@ static void vop2_plane_atomic_update(struct drm_plan= e *plane, else vop2_win_write(win, VOP2_WIN_AFBC_AUTO_GATING_EN, 1); =20 - vop2_win_write(win, VOP2_WIN_AFBC_BLOCK_SPLIT_EN, 0); + if (fb->modifier & AFBC_FORMAT_MOD_SPLIT) + vop2_win_write(win, VOP2_WIN_AFBC_BLOCK_SPLIT_EN, 1); + else + vop2_win_write(win, VOP2_WIN_AFBC_BLOCK_SPLIT_EN, 0); + transform_offset =3D vop2_afbc_transform_offset(pstate, half_block_en); vop2_win_write(win, VOP2_WIN_AFBC_HDR_PTR, yrgb_mst); vop2_win_write(win, VOP2_WIN_AFBC_PIC_SIZE, act_info); --=20 2.34.1 From nobody Fri Nov 29 11:34:16 2024 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.5]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0A0887E0E8; Fri, 20 Sep 2024 08:22:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820554; cv=none; b=BgZOIlAu7kjd5PsG/fgsTJLhNIS0x0NZRHcO1a+WrIb9TcbPRX+FK7U6r9ySXCsVTrpje47a39PVdKd2twzBege1NgtM/YeLJJbx64YGu8FcbZIKL2adbyXRcPYesXvGov6d5xC8l0gB6sXTtFtdxKxC45HhuCkVoYCMFBjEj7A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820554; c=relaxed/simple; bh=FxOnH86S2LSGy1Rdg8fv2K0ZBsnswFaEH2l9XlQX9GE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GALZtMeAv1yDyX7WApD2DwtNsvkFoSC9cSX5gPFgXrII12ifrX4CDtmkoK8YiNXheBDcb03B7tn3Re6b7OVBGd9TEq53yM+wdlCAnTXa0hA0fci4cTr5FUl+oQan+EYeHTbk9jbcnKxpJOmhTBwh6nW6G4yKhFuj138zlTyDWcE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=ahjpyL8C; arc=none smtp.client-ip=220.197.31.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="ahjpyL8C" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version; bh=6myTC Wql0suhj2gugdkJI32ld5rCeLo5KpbrS9E151I=; b=ahjpyL8CQMiQlSPlQcSq4 23mleobAliDEgfUNQdRx/OYwgg25ppacloLx1FCwUgMK9PZribp1Wj+YxAHroQLk Wol/vi49S11rWmic6vX0IvOp3CPEiijOlkZu+D8msGVhN9Ly7EgavK8GWKAEmo2t Vsx6Yso/SzN9+VEKQvkHGA= Received: from ProDesk.. (unknown [58.22.7.114]) by gzga-smtp-mta-g2-5 (Coremail) with SMTP id _____wD3H46XMO1mbMq6IA--.6405S2; Fri, 20 Sep 2024 16:21:47 +0800 (CST) From: Andy Yan To: heiko@sntech.de Cc: hjc@rock-chips.com, krzk+dt@kernel.org, robh@kernel.org, conor+dt@kernel.org, s.hauer@pengutronix.de, devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, derek.foreman@collabora.com, minhuadotchen@gmail.com, detlev.casanova@collabora.com, Andy Yan Subject: [PATCH v3 08/15] drm/rockchip: vop2: Add platform specific callback Date: Fri, 20 Sep 2024 16:21:41 +0800 Message-ID: <20240920082142.6800-1-andyshrk@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240920081626.6433-1-andyshrk@163.com> References: <20240920081626.6433-1-andyshrk@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wD3H46XMO1mbMq6IA--.6405S2 X-Coremail-Antispam: 1Uf129KBjvAXoWDtFWfuFy3JFyfAw4ktr13urg_yoWfCF1DAo W7uF1Yqr4xtw1Fg39rWr17Xay7W3y8Can7Cr17XFnxZ39xX3yjkF92q3ZrtF17Jr15Cay5 Aws5t3WrZa1fXFs7n29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7v73VFW2AGmfu7bjvjm3 AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvjxUx8nYUUUUU X-CM-SenderInfo: 5dqg52xkunqiywtou0bp/xtbB0h1gXmWX0hszMgAAsL Content-Type: text/plain; charset="utf-8" From: Andy Yan The VOP interface mux, overlay, background delay cycle configuration of different SOC are much different. Add platform specific callback ops to let the core driver look cleaner and more refined. Signed-off-by: Andy Yan Tested-by: Detlev Casanova Tested-by: Michael Riesch # on RK3568 --- (no changes since v2) Changes in v2: - Add platform specific callback drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 1125 +----------------- drivers/gpu/drm/rockchip/rockchip_drm_vop2.h | 159 +++ drivers/gpu/drm/rockchip/rockchip_vop2_reg.c | 982 +++++++++++++++ 3 files changed, 1161 insertions(+), 1105 deletions(-) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c b/drivers/gpu/drm= /rockchip/rockchip_drm_vop2.c index f6a030fd8e55..6a7982ad3550 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c @@ -33,7 +33,6 @@ #include =20 #include -#include =20 #include "rockchip_drm_gem.h" #include "rockchip_drm_vop2.h" @@ -102,143 +101,6 @@ enum vop2_afbc_format { VOP2_AFBC_FMT_INVALID =3D -1, }; =20 -union vop2_alpha_ctrl { - u32 val; - struct { - /* [0:1] */ - u32 color_mode:1; - u32 alpha_mode:1; - /* [2:3] */ - u32 blend_mode:2; - u32 alpha_cal_mode:1; - /* [5:7] */ - u32 factor_mode:3; - /* [8:9] */ - u32 alpha_en:1; - u32 src_dst_swap:1; - u32 reserved:6; - /* [16:23] */ - u32 glb_alpha:8; - } bits; -}; - -struct vop2_alpha { - union vop2_alpha_ctrl src_color_ctrl; - union vop2_alpha_ctrl dst_color_ctrl; - union vop2_alpha_ctrl src_alpha_ctrl; - union vop2_alpha_ctrl dst_alpha_ctrl; -}; - -struct vop2_alpha_config { - bool src_premulti_en; - bool dst_premulti_en; - bool src_pixel_alpha_en; - bool dst_pixel_alpha_en; - u16 src_glb_alpha_value; - u16 dst_glb_alpha_value; -}; - -struct vop2_win { - struct vop2 *vop2; - struct drm_plane base; - const struct vop2_win_data *data; - struct regmap_field *reg[VOP2_WIN_MAX_REG]; - - /** - * @win_id: graphic window id, a cluster may be split into two - * graphics windows. - */ - u8 win_id; - u8 delay; - u32 offset; - - enum drm_plane_type type; -}; - -struct vop2_video_port { - struct drm_crtc crtc; - struct vop2 *vop2; - struct clk *dclk; - unsigned int id; - const struct vop2_video_port_data *data; - - struct completion dsp_hold_completion; - - /** - * @win_mask: Bitmask of windows attached to the video port; - */ - u32 win_mask; - - struct vop2_win *primary_plane; - struct drm_pending_vblank_event *event; - - unsigned int nlayers; -}; - -struct vop2 { - struct device *dev; - struct drm_device *drm; - struct vop2_video_port vps[ROCKCHIP_MAX_CRTC]; - - const struct vop2_data *data; - /* - * Number of windows that are registered as plane, may be less than the - * total number of hardware windows. - */ - u32 registered_num_wins; - - struct resource *res; - void __iomem *regs; - struct regmap *map; - - struct regmap *sys_grf; - struct regmap *vop_grf; - struct regmap *vo1_grf; - struct regmap *sys_pmu; - - /* physical map length of vop2 register */ - u32 len; - - void __iomem *lut_regs; - - /* protects crtc enable/disable */ - struct mutex vop2_lock; - - int irq; - - /* - * Some global resources are shared between all video ports(crtcs), so - * we need a ref counter here. - */ - unsigned int enable_count; - struct clk *hclk; - struct clk *aclk; - struct clk *pclk; - - /* optional internal rgb encoder */ - struct rockchip_rgb *rgb; - - /* must be put at the end of the struct */ - struct vop2_win win[]; -}; - -#define vop2_output_if_is_hdmi(x) ((x) =3D=3D ROCKCHIP_VOP2_EP_HDMI0 || \ - (x) =3D=3D ROCKCHIP_VOP2_EP_HDMI1) - -#define vop2_output_if_is_dp(x) ((x) =3D=3D ROCKCHIP_VOP2_EP_DP0 || \ - (x) =3D=3D ROCKCHIP_VOP2_EP_DP1) - -#define vop2_output_if_is_edp(x) ((x) =3D=3D ROCKCHIP_VOP2_EP_EDP0 || \ - (x) =3D=3D ROCKCHIP_VOP2_EP_EDP1) - -#define vop2_output_if_is_mipi(x) ((x) =3D=3D ROCKCHIP_VOP2_EP_MIPI0 || \ - (x) =3D=3D ROCKCHIP_VOP2_EP_MIPI1) - -#define vop2_output_if_is_lvds(x) ((x) =3D=3D ROCKCHIP_VOP2_EP_LVDS0 || \ - (x) =3D=3D ROCKCHIP_VOP2_EP_LVDS1) - -#define vop2_output_if_is_dpi(x) ((x) =3D=3D ROCKCHIP_VOP2_EP_RGB0) - =20 /* * bus-format types. @@ -272,15 +134,6 @@ static DRM_ENUM_NAME_FN(drm_get_bus_format_name, drm_b= us_format_enum_list) =20 static const struct regmap_config vop2_regmap_config; =20 -static struct vop2_video_port *to_vop2_video_port(struct drm_crtc *crtc) -{ - return container_of(crtc, struct vop2_video_port, crtc); -} - -static struct vop2_win *to_vop2_win(struct drm_plane *p) -{ - return container_of(p, struct vop2_win, base); -} =20 static void vop2_lock(struct vop2 *vop2) { @@ -292,35 +145,6 @@ static void vop2_unlock(struct vop2 *vop2) mutex_unlock(&vop2->vop2_lock); } =20 -static void vop2_writel(struct vop2 *vop2, u32 offset, u32 v) -{ - regmap_write(vop2->map, offset, v); -} - -static void vop2_vp_write(struct vop2_video_port *vp, u32 offset, u32 v) -{ - regmap_write(vp->vop2->map, vp->data->offset + offset, v); -} - -static u32 vop2_readl(struct vop2 *vop2, u32 offset) -{ - u32 val; - - regmap_read(vop2->map, offset, &val); - - return val; -} - -static void vop2_win_write(const struct vop2_win *win, unsigned int reg, u= 32 v) -{ - regmap_field_write(win->reg[reg], v); -} - -static bool vop2_cluster_window(const struct vop2_win *win) -{ - return win->data->feature & WIN_FEATURE_CLUSTER; -} - /* * Note: * The write mask function is documented but missing on rk3566/8, writes @@ -1556,6 +1380,7 @@ static void vop2_dither_setup(struct drm_crtc *crtc, = u32 *dsp_ctrl) static void vop2_post_config(struct drm_crtc *crtc) { struct vop2_video_port *vp =3D to_vop2_video_port(crtc); + struct vop2 *vop2 =3D vp->vop2; struct drm_display_mode *mode =3D &crtc->state->adjusted_mode; u16 vtotal =3D mode->crtc_vtotal; u16 hdisplay =3D mode->crtc_hdisplay; @@ -1566,18 +1391,10 @@ static void vop2_post_config(struct drm_crtc *crtc) u32 top_margin =3D 100, bottom_margin =3D 100; u16 hsize =3D hdisplay * (left_margin + right_margin) / 200; u16 vsize =3D vdisplay * (top_margin + bottom_margin) / 200; - u16 hsync_len =3D mode->crtc_hsync_end - mode->crtc_hsync_start; u16 hact_end, vact_end; u32 val; - u32 bg_dly; - u32 pre_scan_dly; - - bg_dly =3D vp->data->pre_scan_max_dly[3]; - vop2_writel(vp->vop2, RK3568_VP_BG_MIX_CTRL(vp->id), - FIELD_PREP(RK3568_VP_BG_MIX_CTRL__BG_DLY, bg_dly)); =20 - pre_scan_dly =3D ((bg_dly + (hdisplay >> 1) - 1) << 16) | hsync_len; - vop2_vp_write(vp, RK3568_VP_PRE_SCAN_HTIMING, pre_scan_dly); + vop2->ops->setup_bg_dly(vp); =20 vsize =3D rounddown(vsize, 2); hsize =3D rounddown(hsize, 2); @@ -1613,347 +1430,6 @@ static void vop2_post_config(struct drm_crtc *crtc) vop2_vp_write(vp, RK3568_VP_DSP_BG, 0); } =20 -static unsigned long rk3568_set_intf_mux(struct vop2_video_port *vp, int i= d, u32 polflags) -{ - struct vop2 *vop2 =3D vp->vop2; - struct drm_crtc *crtc =3D &vp->crtc; - u32 die, dip; - - die =3D vop2_readl(vop2, RK3568_DSP_IF_EN); - dip =3D vop2_readl(vop2, RK3568_DSP_IF_POL); - - switch (id) { - case ROCKCHIP_VOP2_EP_RGB0: - die &=3D ~RK3568_SYS_DSP_INFACE_EN_RGB_MUX; - die |=3D RK3568_SYS_DSP_INFACE_EN_RGB | - FIELD_PREP(RK3568_SYS_DSP_INFACE_EN_RGB_MUX, vp->id); - dip &=3D ~RK3568_DSP_IF_POL__RGB_LVDS_PIN_POL; - dip |=3D FIELD_PREP(RK3568_DSP_IF_POL__RGB_LVDS_PIN_POL, polflags); - if (polflags & POLFLAG_DCLK_INV) - regmap_write(vop2->sys_grf, RK3568_GRF_VO_CON1, BIT(3 + 16) | BIT(3)); - else - regmap_write(vop2->sys_grf, RK3568_GRF_VO_CON1, BIT(3 + 16)); - break; - case ROCKCHIP_VOP2_EP_HDMI0: - die &=3D ~RK3568_SYS_DSP_INFACE_EN_HDMI_MUX; - die |=3D RK3568_SYS_DSP_INFACE_EN_HDMI | - FIELD_PREP(RK3568_SYS_DSP_INFACE_EN_HDMI_MUX, vp->id); - dip &=3D ~RK3568_DSP_IF_POL__HDMI_PIN_POL; - dip |=3D FIELD_PREP(RK3568_DSP_IF_POL__HDMI_PIN_POL, polflags); - break; - case ROCKCHIP_VOP2_EP_EDP0: - die &=3D ~RK3568_SYS_DSP_INFACE_EN_EDP_MUX; - die |=3D RK3568_SYS_DSP_INFACE_EN_EDP | - FIELD_PREP(RK3568_SYS_DSP_INFACE_EN_EDP_MUX, vp->id); - dip &=3D ~RK3568_DSP_IF_POL__EDP_PIN_POL; - dip |=3D FIELD_PREP(RK3568_DSP_IF_POL__EDP_PIN_POL, polflags); - break; - case ROCKCHIP_VOP2_EP_MIPI0: - die &=3D ~RK3568_SYS_DSP_INFACE_EN_MIPI0_MUX; - die |=3D RK3568_SYS_DSP_INFACE_EN_MIPI0 | - FIELD_PREP(RK3568_SYS_DSP_INFACE_EN_MIPI0_MUX, vp->id); - dip &=3D ~RK3568_DSP_IF_POL__MIPI_PIN_POL; - dip |=3D FIELD_PREP(RK3568_DSP_IF_POL__MIPI_PIN_POL, polflags); - break; - case ROCKCHIP_VOP2_EP_MIPI1: - die &=3D ~RK3568_SYS_DSP_INFACE_EN_MIPI1_MUX; - die |=3D RK3568_SYS_DSP_INFACE_EN_MIPI1 | - FIELD_PREP(RK3568_SYS_DSP_INFACE_EN_MIPI1_MUX, vp->id); - dip &=3D ~RK3568_DSP_IF_POL__MIPI_PIN_POL; - dip |=3D FIELD_PREP(RK3568_DSP_IF_POL__MIPI_PIN_POL, polflags); - break; - case ROCKCHIP_VOP2_EP_LVDS0: - die &=3D ~RK3568_SYS_DSP_INFACE_EN_LVDS0_MUX; - die |=3D RK3568_SYS_DSP_INFACE_EN_LVDS0 | - FIELD_PREP(RK3568_SYS_DSP_INFACE_EN_LVDS0_MUX, vp->id); - dip &=3D ~RK3568_DSP_IF_POL__RGB_LVDS_PIN_POL; - dip |=3D FIELD_PREP(RK3568_DSP_IF_POL__RGB_LVDS_PIN_POL, polflags); - break; - case ROCKCHIP_VOP2_EP_LVDS1: - die &=3D ~RK3568_SYS_DSP_INFACE_EN_LVDS1_MUX; - die |=3D RK3568_SYS_DSP_INFACE_EN_LVDS1 | - FIELD_PREP(RK3568_SYS_DSP_INFACE_EN_LVDS1_MUX, vp->id); - dip &=3D ~RK3568_DSP_IF_POL__RGB_LVDS_PIN_POL; - dip |=3D FIELD_PREP(RK3568_DSP_IF_POL__RGB_LVDS_PIN_POL, polflags); - break; - default: - drm_err(vop2->drm, "Invalid interface id %d on vp%d\n", id, vp->id); - return 0; - } - - dip |=3D RK3568_DSP_IF_POL__CFG_DONE_IMD; - - vop2_writel(vop2, RK3568_DSP_IF_EN, die); - vop2_writel(vop2, RK3568_DSP_IF_POL, dip); - - return crtc->state->adjusted_mode.crtc_clock * 1000LL; -} - -/* - * calc the dclk on rk3588 - * the available div of dclk is 1, 2, 4 - */ -static unsigned long rk3588_calc_dclk(unsigned long child_clk, unsigned lo= ng max_dclk) -{ - if (child_clk * 4 <=3D max_dclk) - return child_clk * 4; - else if (child_clk * 2 <=3D max_dclk) - return child_clk * 2; - else if (child_clk <=3D max_dclk) - return child_clk; - else - return 0; -} - -/* - * 4 pixclk/cycle on rk3588 - * RGB/eDP/HDMI: if_pixclk >=3D dclk_core - * DP: dp_pixclk =3D dclk_out <=3D dclk_core - * DSI: mipi_pixclk <=3D dclk_out <=3D dclk_core - */ -static unsigned long rk3588_calc_cru_cfg(struct vop2_video_port *vp, int i= d, - int *dclk_core_div, int *dclk_out_div, - int *if_pixclk_div, int *if_dclk_div) -{ - struct vop2 *vop2 =3D vp->vop2; - struct drm_crtc *crtc =3D &vp->crtc; - struct drm_display_mode *adjusted_mode =3D &crtc->state->adjusted_mode; - struct rockchip_crtc_state *vcstate =3D to_rockchip_crtc_state(crtc->stat= e); - int output_mode =3D vcstate->output_mode; - unsigned long v_pixclk =3D adjusted_mode->crtc_clock * 1000LL; /* video t= iming pixclk */ - unsigned long dclk_core_rate =3D v_pixclk >> 2; - unsigned long dclk_rate =3D v_pixclk; - unsigned long dclk_out_rate; - unsigned long if_pixclk_rate; - int K =3D 1; - - if (vop2_output_if_is_hdmi(id)) { - /* - * K =3D 2: dclk_core =3D if_pixclk_rate > if_dclk_rate - * K =3D 1: dclk_core =3D hdmie_edp_dclk > if_pixclk_rate - */ - if (output_mode =3D=3D ROCKCHIP_OUT_MODE_YUV420) { - dclk_rate =3D dclk_rate >> 1; - K =3D 2; - } - - if_pixclk_rate =3D (dclk_core_rate << 1) / K; - /* - * if_dclk_rate =3D dclk_core_rate / K; - * *if_pixclk_div =3D dclk_rate / if_pixclk_rate; - * *if_dclk_div =3D dclk_rate / if_dclk_rate; - */ - *if_pixclk_div =3D 2; - *if_dclk_div =3D 4; - } else if (vop2_output_if_is_edp(id)) { - /* - * edp_pixclk =3D edp_dclk > dclk_core - */ - if_pixclk_rate =3D v_pixclk / K; - dclk_rate =3D if_pixclk_rate * K; - /* - * *if_pixclk_div =3D dclk_rate / if_pixclk_rate; - * *if_dclk_div =3D *if_pixclk_div; - */ - *if_pixclk_div =3D K; - *if_dclk_div =3D K; - } else if (vop2_output_if_is_dp(id)) { - if (output_mode =3D=3D ROCKCHIP_OUT_MODE_YUV420) - dclk_out_rate =3D v_pixclk >> 3; - else - dclk_out_rate =3D v_pixclk >> 2; - - dclk_rate =3D rk3588_calc_dclk(dclk_out_rate, 600000); - if (!dclk_rate) { - drm_err(vop2->drm, "DP dclk_out_rate out of range, dclk_out_rate: %ld K= HZ\n", - dclk_out_rate); - return 0; - } - *dclk_out_div =3D dclk_rate / dclk_out_rate; - } else if (vop2_output_if_is_mipi(id)) { - if_pixclk_rate =3D dclk_core_rate / K; - /* - * dclk_core =3D dclk_out * K =3D if_pixclk * K =3D v_pixclk / 4 - */ - dclk_out_rate =3D if_pixclk_rate; - /* - * dclk_rate =3D N * dclk_core_rate N =3D (1,2,4 ), - * we get a little factor here - */ - dclk_rate =3D rk3588_calc_dclk(dclk_out_rate, 600000); - if (!dclk_rate) { - drm_err(vop2->drm, "MIPI dclk out of range, dclk_out_rate: %ld KHZ\n", - dclk_out_rate); - return 0; - } - *dclk_out_div =3D dclk_rate / dclk_out_rate; - /* - * mipi pixclk =3D=3D dclk_out - */ - *if_pixclk_div =3D 1; - } else if (vop2_output_if_is_dpi(id)) { - dclk_rate =3D v_pixclk; - } - - *dclk_core_div =3D dclk_rate / dclk_core_rate; - *if_pixclk_div =3D ilog2(*if_pixclk_div); - *if_dclk_div =3D ilog2(*if_dclk_div); - *dclk_core_div =3D ilog2(*dclk_core_div); - *dclk_out_div =3D ilog2(*dclk_out_div); - - drm_dbg(vop2->drm, "dclk: %ld, pixclk_div: %d, dclk_div: %d\n", - dclk_rate, *if_pixclk_div, *if_dclk_div); - - return dclk_rate; -} - -/* - * MIPI port mux on rk3588: - * 0: Video Port2 - * 1: Video Port3 - * 3: Video Port 1(MIPI1 only) - */ -static u32 rk3588_get_mipi_port_mux(int vp_id) -{ - if (vp_id =3D=3D 1) - return 3; - else if (vp_id =3D=3D 3) - return 1; - else - return 0; -} - -static u32 rk3588_get_hdmi_pol(u32 flags) -{ - u32 val; - - val =3D (flags & DRM_MODE_FLAG_NHSYNC) ? BIT(HSYNC_POSITIVE) : 0; - val |=3D (flags & DRM_MODE_FLAG_NVSYNC) ? BIT(VSYNC_POSITIVE) : 0; - - return val; -} - -static unsigned long rk3588_set_intf_mux(struct vop2_video_port *vp, int i= d, u32 polflags) -{ - struct vop2 *vop2 =3D vp->vop2; - int dclk_core_div, dclk_out_div, if_pixclk_div, if_dclk_div; - unsigned long clock; - u32 die, dip, div, vp_clk_div, val; - - clock =3D rk3588_calc_cru_cfg(vp, id, &dclk_core_div, &dclk_out_div, - &if_pixclk_div, &if_dclk_div); - if (!clock) - return 0; - - vp_clk_div =3D FIELD_PREP(RK3588_VP_CLK_CTRL__DCLK_CORE_DIV, dclk_core_di= v); - vp_clk_div |=3D FIELD_PREP(RK3588_VP_CLK_CTRL__DCLK_OUT_DIV, dclk_out_div= ); - - die =3D vop2_readl(vop2, RK3568_DSP_IF_EN); - dip =3D vop2_readl(vop2, RK3568_DSP_IF_POL); - div =3D vop2_readl(vop2, RK3568_DSP_IF_CTRL); - - switch (id) { - case ROCKCHIP_VOP2_EP_HDMI0: - div &=3D ~RK3588_DSP_IF_EDP_HDMI0_DCLK_DIV; - div &=3D ~RK3588_DSP_IF_EDP_HDMI0_PCLK_DIV; - div |=3D FIELD_PREP(RK3588_DSP_IF_EDP_HDMI0_DCLK_DIV, if_dclk_div); - div |=3D FIELD_PREP(RK3588_DSP_IF_EDP_HDMI0_PCLK_DIV, if_pixclk_div); - die &=3D ~RK3588_SYS_DSP_INFACE_EN_EDP_HDMI0_MUX; - die |=3D RK3588_SYS_DSP_INFACE_EN_HDMI0 | - FIELD_PREP(RK3588_SYS_DSP_INFACE_EN_EDP_HDMI0_MUX, vp->id); - val =3D rk3588_get_hdmi_pol(polflags); - regmap_write(vop2->vop_grf, RK3588_GRF_VOP_CON2, HIWORD_UPDATE(1, 1, 1)); - regmap_write(vop2->vo1_grf, RK3588_GRF_VO1_CON0, HIWORD_UPDATE(val, 6, 5= )); - break; - case ROCKCHIP_VOP2_EP_HDMI1: - div &=3D ~RK3588_DSP_IF_EDP_HDMI1_DCLK_DIV; - div &=3D ~RK3588_DSP_IF_EDP_HDMI1_PCLK_DIV; - div |=3D FIELD_PREP(RK3588_DSP_IF_EDP_HDMI1_DCLK_DIV, if_dclk_div); - div |=3D FIELD_PREP(RK3588_DSP_IF_EDP_HDMI1_PCLK_DIV, if_pixclk_div); - die &=3D ~RK3588_SYS_DSP_INFACE_EN_EDP_HDMI1_MUX; - die |=3D RK3588_SYS_DSP_INFACE_EN_HDMI1 | - FIELD_PREP(RK3588_SYS_DSP_INFACE_EN_EDP_HDMI1_MUX, vp->id); - val =3D rk3588_get_hdmi_pol(polflags); - regmap_write(vop2->vop_grf, RK3588_GRF_VOP_CON2, HIWORD_UPDATE(1, 4, 4)); - regmap_write(vop2->vo1_grf, RK3588_GRF_VO1_CON0, HIWORD_UPDATE(val, 8, 7= )); - break; - case ROCKCHIP_VOP2_EP_EDP0: - div &=3D ~RK3588_DSP_IF_EDP_HDMI0_DCLK_DIV; - div &=3D ~RK3588_DSP_IF_EDP_HDMI0_PCLK_DIV; - div |=3D FIELD_PREP(RK3588_DSP_IF_EDP_HDMI0_DCLK_DIV, if_dclk_div); - div |=3D FIELD_PREP(RK3588_DSP_IF_EDP_HDMI0_PCLK_DIV, if_pixclk_div); - die &=3D ~RK3588_SYS_DSP_INFACE_EN_EDP_HDMI0_MUX; - die |=3D RK3588_SYS_DSP_INFACE_EN_EDP0 | - FIELD_PREP(RK3588_SYS_DSP_INFACE_EN_EDP_HDMI0_MUX, vp->id); - regmap_write(vop2->vop_grf, RK3588_GRF_VOP_CON2, HIWORD_UPDATE(1, 0, 0)); - break; - case ROCKCHIP_VOP2_EP_EDP1: - div &=3D ~RK3588_DSP_IF_EDP_HDMI1_DCLK_DIV; - div &=3D ~RK3588_DSP_IF_EDP_HDMI1_PCLK_DIV; - div |=3D FIELD_PREP(RK3588_DSP_IF_EDP_HDMI0_DCLK_DIV, if_dclk_div); - div |=3D FIELD_PREP(RK3588_DSP_IF_EDP_HDMI0_PCLK_DIV, if_pixclk_div); - die &=3D ~RK3588_SYS_DSP_INFACE_EN_EDP_HDMI1_MUX; - die |=3D RK3588_SYS_DSP_INFACE_EN_EDP1 | - FIELD_PREP(RK3588_SYS_DSP_INFACE_EN_EDP_HDMI1_MUX, vp->id); - regmap_write(vop2->vop_grf, RK3588_GRF_VOP_CON2, HIWORD_UPDATE(1, 3, 3)); - break; - case ROCKCHIP_VOP2_EP_MIPI0: - div &=3D ~RK3588_DSP_IF_MIPI0_PCLK_DIV; - div |=3D FIELD_PREP(RK3588_DSP_IF_MIPI0_PCLK_DIV, if_pixclk_div); - die &=3D ~RK3588_SYS_DSP_INFACE_EN_MIPI0_MUX; - val =3D rk3588_get_mipi_port_mux(vp->id); - die |=3D RK3588_SYS_DSP_INFACE_EN_MIPI0 | - FIELD_PREP(RK3588_SYS_DSP_INFACE_EN_MIPI0_MUX, !!val); - break; - case ROCKCHIP_VOP2_EP_MIPI1: - div &=3D ~RK3588_DSP_IF_MIPI1_PCLK_DIV; - div |=3D FIELD_PREP(RK3588_DSP_IF_MIPI1_PCLK_DIV, if_pixclk_div); - die &=3D ~RK3588_SYS_DSP_INFACE_EN_MIPI1_MUX; - val =3D rk3588_get_mipi_port_mux(vp->id); - die |=3D RK3588_SYS_DSP_INFACE_EN_MIPI1 | - FIELD_PREP(RK3588_SYS_DSP_INFACE_EN_MIPI1_MUX, val); - break; - case ROCKCHIP_VOP2_EP_DP0: - die &=3D ~RK3588_SYS_DSP_INFACE_EN_DP0_MUX; - die |=3D RK3588_SYS_DSP_INFACE_EN_DP0 | - FIELD_PREP(RK3588_SYS_DSP_INFACE_EN_DP0_MUX, vp->id); - dip &=3D ~RK3588_DSP_IF_POL__DP0_PIN_POL; - dip |=3D FIELD_PREP(RK3588_DSP_IF_POL__DP0_PIN_POL, polflags); - break; - case ROCKCHIP_VOP2_EP_DP1: - die &=3D ~RK3588_SYS_DSP_INFACE_EN_MIPI1_MUX; - die |=3D RK3588_SYS_DSP_INFACE_EN_MIPI1 | - FIELD_PREP(RK3588_SYS_DSP_INFACE_EN_MIPI1_MUX, vp->id); - dip &=3D ~RK3588_DSP_IF_POL__DP1_PIN_POL; - dip |=3D FIELD_PREP(RK3588_DSP_IF_POL__DP1_PIN_POL, polflags); - break; - default: - drm_err(vop2->drm, "Invalid interface id %d on vp%d\n", id, vp->id); - return 0; - } - - dip |=3D RK3568_DSP_IF_POL__CFG_DONE_IMD; - - vop2_vp_write(vp, RK3588_VP_CLK_CTRL, vp_clk_div); - vop2_writel(vop2, RK3568_DSP_IF_EN, die); - vop2_writel(vop2, RK3568_DSP_IF_CTRL, div); - vop2_writel(vop2, RK3568_DSP_IF_POL, dip); - - return clock; -} - -static unsigned long vop2_set_intf_mux(struct vop2_video_port *vp, int ep_= id, u32 polflags) -{ - struct vop2 *vop2 =3D vp->vop2; - - if (vop2->data->soc_id =3D=3D 3566 || vop2->data->soc_id =3D=3D 3568) - return rk3568_set_intf_mux(vp, ep_id, polflags); - else if (vop2->data->soc_id =3D=3D 3588) - return rk3588_set_intf_mux(vp, ep_id, polflags); - else - return 0; -} - static int us_to_vertical_line(struct drm_display_mode *mode, int us) { return us * mode->clock / mode->htotal / 1000; @@ -2026,7 +1502,7 @@ static void vop2_crtc_atomic_enable(struct drm_crtc *= crtc, * process multi(1/2/4/8) pixels per cycle, so the dclk feed by the * system cru may be the 1/2 or 1/4 of mode->clock. */ - clock =3D vop2_set_intf_mux(vp, rkencoder->crtc_endpoint_id, polflags); + clock =3D vop2->ops->setup_intf_mux(vp, rkencoder->crtc_endpoint_id, pol= flags); } =20 if (!clock) { @@ -2121,451 +1597,13 @@ static int vop2_crtc_atomic_check(struct drm_crtc = *crtc, return 0; } =20 -static bool is_opaque(u16 alpha) -{ - return (alpha >> 8) =3D=3D 0xff; -} - -static void vop2_parse_alpha(struct vop2_alpha_config *alpha_config, - struct vop2_alpha *alpha) -{ - int src_glb_alpha_en =3D is_opaque(alpha_config->src_glb_alpha_value) ? 0= : 1; - int dst_glb_alpha_en =3D is_opaque(alpha_config->dst_glb_alpha_value) ? 0= : 1; - int src_color_mode =3D alpha_config->src_premulti_en ? - ALPHA_SRC_PRE_MUL : ALPHA_SRC_NO_PRE_MUL; - int dst_color_mode =3D alpha_config->dst_premulti_en ? - ALPHA_SRC_PRE_MUL : ALPHA_SRC_NO_PRE_MUL; - - alpha->src_color_ctrl.val =3D 0; - alpha->dst_color_ctrl.val =3D 0; - alpha->src_alpha_ctrl.val =3D 0; - alpha->dst_alpha_ctrl.val =3D 0; - - if (!alpha_config->src_pixel_alpha_en) - alpha->src_color_ctrl.bits.blend_mode =3D ALPHA_GLOBAL; - else if (alpha_config->src_pixel_alpha_en && !src_glb_alpha_en) - alpha->src_color_ctrl.bits.blend_mode =3D ALPHA_PER_PIX; - else - alpha->src_color_ctrl.bits.blend_mode =3D ALPHA_PER_PIX_GLOBAL; - - alpha->src_color_ctrl.bits.alpha_en =3D 1; - - if (alpha->src_color_ctrl.bits.blend_mode =3D=3D ALPHA_GLOBAL) { - alpha->src_color_ctrl.bits.color_mode =3D src_color_mode; - alpha->src_color_ctrl.bits.factor_mode =3D SRC_FAC_ALPHA_SRC_GLOBAL; - } else if (alpha->src_color_ctrl.bits.blend_mode =3D=3D ALPHA_PER_PIX) { - alpha->src_color_ctrl.bits.color_mode =3D src_color_mode; - alpha->src_color_ctrl.bits.factor_mode =3D SRC_FAC_ALPHA_ONE; - } else { - alpha->src_color_ctrl.bits.color_mode =3D ALPHA_SRC_PRE_MUL; - alpha->src_color_ctrl.bits.factor_mode =3D SRC_FAC_ALPHA_SRC_GLOBAL; - } - alpha->src_color_ctrl.bits.glb_alpha =3D alpha_config->src_glb_alpha_valu= e >> 8; - alpha->src_color_ctrl.bits.alpha_mode =3D ALPHA_STRAIGHT; - alpha->src_color_ctrl.bits.alpha_cal_mode =3D ALPHA_SATURATION; - - alpha->dst_color_ctrl.bits.alpha_mode =3D ALPHA_STRAIGHT; - alpha->dst_color_ctrl.bits.alpha_cal_mode =3D ALPHA_SATURATION; - alpha->dst_color_ctrl.bits.blend_mode =3D ALPHA_GLOBAL; - alpha->dst_color_ctrl.bits.glb_alpha =3D alpha_config->dst_glb_alpha_valu= e >> 8; - alpha->dst_color_ctrl.bits.color_mode =3D dst_color_mode; - alpha->dst_color_ctrl.bits.factor_mode =3D ALPHA_SRC_INVERSE; - - alpha->src_alpha_ctrl.bits.alpha_mode =3D ALPHA_STRAIGHT; - alpha->src_alpha_ctrl.bits.blend_mode =3D alpha->src_color_ctrl.bits.blen= d_mode; - alpha->src_alpha_ctrl.bits.alpha_cal_mode =3D ALPHA_SATURATION; - alpha->src_alpha_ctrl.bits.factor_mode =3D ALPHA_ONE; - - alpha->dst_alpha_ctrl.bits.alpha_mode =3D ALPHA_STRAIGHT; - if (alpha_config->dst_pixel_alpha_en && !dst_glb_alpha_en) - alpha->dst_alpha_ctrl.bits.blend_mode =3D ALPHA_PER_PIX; - else - alpha->dst_alpha_ctrl.bits.blend_mode =3D ALPHA_PER_PIX_GLOBAL; - alpha->dst_alpha_ctrl.bits.alpha_cal_mode =3D ALPHA_NO_SATURATION; - alpha->dst_alpha_ctrl.bits.factor_mode =3D ALPHA_SRC_INVERSE; -} - -static int vop2_find_start_mixer_id_for_vp(struct vop2 *vop2, u8 port_id) -{ - struct vop2_video_port *vp; - int used_layer =3D 0; - int i; - - for (i =3D 0; i < port_id; i++) { - vp =3D &vop2->vps[i]; - used_layer +=3D hweight32(vp->win_mask); - } - - return used_layer; -} - -static void vop2_setup_cluster_alpha(struct vop2 *vop2, struct vop2_win *m= ain_win) -{ - struct vop2_alpha_config alpha_config; - struct vop2_alpha alpha; - struct drm_plane_state *bottom_win_pstate; - bool src_pixel_alpha_en =3D false; - u16 src_glb_alpha_val, dst_glb_alpha_val; - bool premulti_en =3D false; - bool swap =3D false; - u32 offset =3D 0; - - /* At one win mode, win0 is dst/bottom win, and win1 is a all zero src/to= p win */ - bottom_win_pstate =3D main_win->base.state; - src_glb_alpha_val =3D 0; - dst_glb_alpha_val =3D main_win->base.state->alpha; - - if (!bottom_win_pstate->fb) - return; - - alpha_config.src_premulti_en =3D premulti_en; - alpha_config.dst_premulti_en =3D false; - alpha_config.src_pixel_alpha_en =3D src_pixel_alpha_en; - alpha_config.dst_pixel_alpha_en =3D true; /* alpha value need transfer to= next mix */ - alpha_config.src_glb_alpha_value =3D src_glb_alpha_val; - alpha_config.dst_glb_alpha_value =3D dst_glb_alpha_val; - vop2_parse_alpha(&alpha_config, &alpha); - - alpha.src_color_ctrl.bits.src_dst_swap =3D swap; - - switch (main_win->data->phys_id) { - case ROCKCHIP_VOP2_CLUSTER0: - offset =3D 0x0; - break; - case ROCKCHIP_VOP2_CLUSTER1: - offset =3D 0x10; - break; - case ROCKCHIP_VOP2_CLUSTER2: - offset =3D 0x20; - break; - case ROCKCHIP_VOP2_CLUSTER3: - offset =3D 0x30; - break; - } - - vop2_writel(vop2, RK3568_CLUSTER0_MIX_SRC_COLOR_CTRL + offset, - alpha.src_color_ctrl.val); - vop2_writel(vop2, RK3568_CLUSTER0_MIX_DST_COLOR_CTRL + offset, - alpha.dst_color_ctrl.val); - vop2_writel(vop2, RK3568_CLUSTER0_MIX_SRC_ALPHA_CTRL + offset, - alpha.src_alpha_ctrl.val); - vop2_writel(vop2, RK3568_CLUSTER0_MIX_DST_ALPHA_CTRL + offset, - alpha.dst_alpha_ctrl.val); -} - -static void vop2_setup_alpha(struct vop2_video_port *vp) -{ - struct vop2 *vop2 =3D vp->vop2; - struct drm_framebuffer *fb; - struct vop2_alpha_config alpha_config; - struct vop2_alpha alpha; - struct drm_plane *plane; - int pixel_alpha_en; - int premulti_en, gpremulti_en =3D 0; - int mixer_id; - u32 offset; - bool bottom_layer_alpha_en =3D false; - u32 dst_global_alpha =3D DRM_BLEND_ALPHA_OPAQUE; - - mixer_id =3D vop2_find_start_mixer_id_for_vp(vop2, vp->id); - alpha_config.dst_pixel_alpha_en =3D true; /* alpha value need transfer to= next mix */ - - drm_atomic_crtc_for_each_plane(plane, &vp->crtc) { - struct vop2_win *win =3D to_vop2_win(plane); - - if (plane->state->normalized_zpos =3D=3D 0 && - !is_opaque(plane->state->alpha) && - !vop2_cluster_window(win)) { - /* - * If bottom layer have global alpha effect [except cluster layer, - * because cluster have deal with bottom layer global alpha value - * at cluster mix], bottom layer mix need deal with global alpha. - */ - bottom_layer_alpha_en =3D true; - dst_global_alpha =3D plane->state->alpha; - } - } - - drm_atomic_crtc_for_each_plane(plane, &vp->crtc) { - struct vop2_win *win =3D to_vop2_win(plane); - int zpos =3D plane->state->normalized_zpos; - - /* - * Need to configure alpha from second layer. - */ - if (zpos =3D=3D 0) - continue; - - if (plane->state->pixel_blend_mode =3D=3D DRM_MODE_BLEND_PREMULTI) - premulti_en =3D 1; - else - premulti_en =3D 0; - - plane =3D &win->base; - fb =3D plane->state->fb; - - pixel_alpha_en =3D fb->format->has_alpha; - - alpha_config.src_premulti_en =3D premulti_en; - - if (bottom_layer_alpha_en && zpos =3D=3D 1) { - gpremulti_en =3D premulti_en; - /* Cd =3D Cs + (1 - As) * Cd * Agd */ - alpha_config.dst_premulti_en =3D false; - alpha_config.src_pixel_alpha_en =3D pixel_alpha_en; - alpha_config.src_glb_alpha_value =3D plane->state->alpha; - alpha_config.dst_glb_alpha_value =3D dst_global_alpha; - } else if (vop2_cluster_window(win)) { - /* Mix output data only have pixel alpha */ - alpha_config.dst_premulti_en =3D true; - alpha_config.src_pixel_alpha_en =3D true; - alpha_config.src_glb_alpha_value =3D DRM_BLEND_ALPHA_OPAQUE; - alpha_config.dst_glb_alpha_value =3D DRM_BLEND_ALPHA_OPAQUE; - } else { - /* Cd =3D Cs + (1 - As) * Cd */ - alpha_config.dst_premulti_en =3D true; - alpha_config.src_pixel_alpha_en =3D pixel_alpha_en; - alpha_config.src_glb_alpha_value =3D plane->state->alpha; - alpha_config.dst_glb_alpha_value =3D DRM_BLEND_ALPHA_OPAQUE; - } - - vop2_parse_alpha(&alpha_config, &alpha); - - offset =3D (mixer_id + zpos - 1) * 0x10; - vop2_writel(vop2, RK3568_MIX0_SRC_COLOR_CTRL + offset, - alpha.src_color_ctrl.val); - vop2_writel(vop2, RK3568_MIX0_DST_COLOR_CTRL + offset, - alpha.dst_color_ctrl.val); - vop2_writel(vop2, RK3568_MIX0_SRC_ALPHA_CTRL + offset, - alpha.src_alpha_ctrl.val); - vop2_writel(vop2, RK3568_MIX0_DST_ALPHA_CTRL + offset, - alpha.dst_alpha_ctrl.val); - } - - if (vp->id =3D=3D 0) { - if (bottom_layer_alpha_en) { - /* Transfer pixel alpha to hdr mix */ - alpha_config.src_premulti_en =3D gpremulti_en; - alpha_config.dst_premulti_en =3D true; - alpha_config.src_pixel_alpha_en =3D true; - alpha_config.src_glb_alpha_value =3D DRM_BLEND_ALPHA_OPAQUE; - alpha_config.dst_glb_alpha_value =3D DRM_BLEND_ALPHA_OPAQUE; - vop2_parse_alpha(&alpha_config, &alpha); - - vop2_writel(vop2, RK3568_HDR0_SRC_COLOR_CTRL, - alpha.src_color_ctrl.val); - vop2_writel(vop2, RK3568_HDR0_DST_COLOR_CTRL, - alpha.dst_color_ctrl.val); - vop2_writel(vop2, RK3568_HDR0_SRC_ALPHA_CTRL, - alpha.src_alpha_ctrl.val); - vop2_writel(vop2, RK3568_HDR0_DST_ALPHA_CTRL, - alpha.dst_alpha_ctrl.val); - } else { - vop2_writel(vop2, RK3568_HDR0_SRC_COLOR_CTRL, 0); - } - } -} - -static void vop2_setup_layer_mixer(struct vop2_video_port *vp) -{ - struct vop2 *vop2 =3D vp->vop2; - struct drm_plane *plane; - u32 layer_sel =3D 0; - u32 port_sel; - u8 old_layer_id; - u8 layer_sel_id; - unsigned int ofs; - u32 ovl_ctrl; - int i; - struct vop2_video_port *vp0 =3D &vop2->vps[0]; - struct vop2_video_port *vp1 =3D &vop2->vps[1]; - struct vop2_video_port *vp2 =3D &vop2->vps[2]; - struct rockchip_crtc_state *vcstate =3D to_rockchip_crtc_state(vp->crtc.s= tate); - - ovl_ctrl =3D vop2_readl(vop2, RK3568_OVL_CTRL); - ovl_ctrl |=3D RK3568_OVL_CTRL__LAYERSEL_REGDONE_IMD; - if (vcstate->yuv_overlay) - ovl_ctrl |=3D RK3568_OVL_CTRL__YUV_MODE(vp->id); - else - ovl_ctrl &=3D ~RK3568_OVL_CTRL__YUV_MODE(vp->id); - - vop2_writel(vop2, RK3568_OVL_CTRL, ovl_ctrl); - - port_sel =3D vop2_readl(vop2, RK3568_OVL_PORT_SEL); - port_sel &=3D RK3568_OVL_PORT_SEL__SEL_PORT; - - if (vp0->nlayers) - port_sel |=3D FIELD_PREP(RK3568_OVL_PORT_SET__PORT0_MUX, - vp0->nlayers - 1); - else - port_sel |=3D FIELD_PREP(RK3568_OVL_PORT_SET__PORT0_MUX, 8); - - if (vp1->nlayers) - port_sel |=3D FIELD_PREP(RK3568_OVL_PORT_SET__PORT1_MUX, - (vp0->nlayers + vp1->nlayers - 1)); - else - port_sel |=3D FIELD_PREP(RK3568_OVL_PORT_SET__PORT1_MUX, 8); - - if (vp2->nlayers) - port_sel |=3D FIELD_PREP(RK3568_OVL_PORT_SET__PORT2_MUX, - (vp2->nlayers + vp1->nlayers + vp0->nlayers - 1)); - else - port_sel |=3D FIELD_PREP(RK3568_OVL_PORT_SET__PORT2_MUX, 8); - - layer_sel =3D vop2_readl(vop2, RK3568_OVL_LAYER_SEL); - - ofs =3D 0; - for (i =3D 0; i < vp->id; i++) - ofs +=3D vop2->vps[i].nlayers; - - drm_atomic_crtc_for_each_plane(plane, &vp->crtc) { - struct vop2_win *win =3D to_vop2_win(plane); - struct vop2_win *old_win; - - /* - * Find the layer this win bind in old state. - */ - for (old_layer_id =3D 0; old_layer_id < vop2->data->win_size; old_layer_= id++) { - layer_sel_id =3D (layer_sel >> (4 * old_layer_id)) & 0xf; - if (layer_sel_id =3D=3D win->data->layer_sel_id) - break; - } - - /* - * Find the win bind to this layer in old state - */ - for (i =3D 0; i < vop2->data->win_size; i++) { - old_win =3D &vop2->win[i]; - layer_sel_id =3D (layer_sel >> (4 * (plane->state->normalized_zpos + of= s))) & 0xf; - if (layer_sel_id =3D=3D old_win->data->layer_sel_id) - break; - } - - switch (win->data->phys_id) { - case ROCKCHIP_VOP2_CLUSTER0: - port_sel &=3D ~RK3568_OVL_PORT_SEL__CLUSTER0; - port_sel |=3D FIELD_PREP(RK3568_OVL_PORT_SEL__CLUSTER0, vp->id); - break; - case ROCKCHIP_VOP2_CLUSTER1: - port_sel &=3D ~RK3568_OVL_PORT_SEL__CLUSTER1; - port_sel |=3D FIELD_PREP(RK3568_OVL_PORT_SEL__CLUSTER1, vp->id); - break; - case ROCKCHIP_VOP2_CLUSTER2: - port_sel &=3D ~RK3588_OVL_PORT_SEL__CLUSTER2; - port_sel |=3D FIELD_PREP(RK3588_OVL_PORT_SEL__CLUSTER2, vp->id); - break; - case ROCKCHIP_VOP2_CLUSTER3: - port_sel &=3D ~RK3588_OVL_PORT_SEL__CLUSTER3; - port_sel |=3D FIELD_PREP(RK3588_OVL_PORT_SEL__CLUSTER3, vp->id); - break; - case ROCKCHIP_VOP2_ESMART0: - port_sel &=3D ~RK3568_OVL_PORT_SEL__ESMART0; - port_sel |=3D FIELD_PREP(RK3568_OVL_PORT_SEL__ESMART0, vp->id); - break; - case ROCKCHIP_VOP2_ESMART1: - port_sel &=3D ~RK3568_OVL_PORT_SEL__ESMART1; - port_sel |=3D FIELD_PREP(RK3568_OVL_PORT_SEL__ESMART1, vp->id); - break; - case ROCKCHIP_VOP2_ESMART2: - port_sel &=3D ~RK3588_OVL_PORT_SEL__ESMART2; - port_sel |=3D FIELD_PREP(RK3588_OVL_PORT_SEL__ESMART2, vp->id); - break; - case ROCKCHIP_VOP2_ESMART3: - port_sel &=3D ~RK3588_OVL_PORT_SEL__ESMART3; - port_sel |=3D FIELD_PREP(RK3588_OVL_PORT_SEL__ESMART3, vp->id); - break; - case ROCKCHIP_VOP2_SMART0: - port_sel &=3D ~RK3568_OVL_PORT_SEL__SMART0; - port_sel |=3D FIELD_PREP(RK3568_OVL_PORT_SEL__SMART0, vp->id); - break; - case ROCKCHIP_VOP2_SMART1: - port_sel &=3D ~RK3568_OVL_PORT_SEL__SMART1; - port_sel |=3D FIELD_PREP(RK3568_OVL_PORT_SEL__SMART1, vp->id); - break; - } - - layer_sel &=3D ~RK3568_OVL_LAYER_SEL__LAYER(plane->state->normalized_zpo= s + ofs, - 0x7); - layer_sel |=3D RK3568_OVL_LAYER_SEL__LAYER(plane->state->normalized_zpos= + ofs, - win->data->layer_sel_id); - /* - * When we bind a window from layerM to layerN, we also need to move the= old - * window on layerN to layerM to avoid one window selected by two or mor= e layers. - */ - layer_sel &=3D ~RK3568_OVL_LAYER_SEL__LAYER(old_layer_id, 0x7); - layer_sel |=3D RK3568_OVL_LAYER_SEL__LAYER(old_layer_id, old_win->data->= layer_sel_id); - } - - vop2_writel(vop2, RK3568_OVL_LAYER_SEL, layer_sel); - vop2_writel(vop2, RK3568_OVL_PORT_SEL, port_sel); -} - -static void vop2_setup_dly_for_windows(struct vop2 *vop2) -{ - struct vop2_win *win; - int i =3D 0; - u32 cdly =3D 0, sdly =3D 0; - - for (i =3D 0; i < vop2->data->win_size; i++) { - u32 dly; - - win =3D &vop2->win[i]; - dly =3D win->delay; - - switch (win->data->phys_id) { - case ROCKCHIP_VOP2_CLUSTER0: - cdly |=3D FIELD_PREP(RK3568_CLUSTER_DLY_NUM__CLUSTER0_0, dly); - cdly |=3D FIELD_PREP(RK3568_CLUSTER_DLY_NUM__CLUSTER0_1, dly); - break; - case ROCKCHIP_VOP2_CLUSTER1: - cdly |=3D FIELD_PREP(RK3568_CLUSTER_DLY_NUM__CLUSTER1_0, dly); - cdly |=3D FIELD_PREP(RK3568_CLUSTER_DLY_NUM__CLUSTER1_1, dly); - break; - case ROCKCHIP_VOP2_ESMART0: - sdly |=3D FIELD_PREP(RK3568_SMART_DLY_NUM__ESMART0, dly); - break; - case ROCKCHIP_VOP2_ESMART1: - sdly |=3D FIELD_PREP(RK3568_SMART_DLY_NUM__ESMART1, dly); - break; - case ROCKCHIP_VOP2_SMART0: - sdly |=3D FIELD_PREP(RK3568_SMART_DLY_NUM__SMART0, dly); - break; - case ROCKCHIP_VOP2_SMART1: - sdly |=3D FIELD_PREP(RK3568_SMART_DLY_NUM__SMART1, dly); - break; - } - } - - vop2_writel(vop2, RK3568_CLUSTER_DLY_NUM, cdly); - vop2_writel(vop2, RK3568_SMART_DLY_NUM, sdly); -} - static void vop2_crtc_atomic_begin(struct drm_crtc *crtc, struct drm_atomic_state *state) { struct vop2_video_port *vp =3D to_vop2_video_port(crtc); struct vop2 *vop2 =3D vp->vop2; - struct drm_plane *plane; - - vp->win_mask =3D 0; - - drm_atomic_crtc_for_each_plane(plane, crtc) { - struct vop2_win *win =3D to_vop2_win(plane); - - win->delay =3D win->data->dly[VOP2_DLY_MODE_DEFAULT]; - - vp->win_mask |=3D BIT(win->data->phys_id); - - if (vop2_cluster_window(win)) - vop2_setup_cluster_alpha(vop2, win); - } - - if (!vp->win_mask) - return; =20 - vop2_setup_layer_mixer(vp); - vop2_setup_alpha(vp); - vop2_setup_dly_for_windows(vop2); + vop2->ops->setup_overlay(vp); } =20 static void vop2_crtc_atomic_flush(struct drm_crtc *crtc, @@ -3158,174 +2196,50 @@ static int vop2_find_rgb_encoder(struct vop2 *vop2) return -ENOENT; } =20 -static struct reg_field vop2_cluster_regs[VOP2_WIN_MAX_REG] =3D { - [VOP2_WIN_ENABLE] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL0, 0, 0), - [VOP2_WIN_FORMAT] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL0, 1, 5), - [VOP2_WIN_RB_SWAP] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL0, 14, 14), - [VOP2_WIN_DITHER_UP] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL0, 18, 18), - [VOP2_WIN_ACT_INFO] =3D REG_FIELD(RK3568_CLUSTER_WIN_ACT_INFO, 0, 31), - [VOP2_WIN_DSP_INFO] =3D REG_FIELD(RK3568_CLUSTER_WIN_DSP_INFO, 0, 31), - [VOP2_WIN_DSP_ST] =3D REG_FIELD(RK3568_CLUSTER_WIN_DSP_ST, 0, 31), - [VOP2_WIN_YRGB_MST] =3D REG_FIELD(RK3568_CLUSTER_WIN_YRGB_MST, 0, 31), - [VOP2_WIN_UV_MST] =3D REG_FIELD(RK3568_CLUSTER_WIN_CBR_MST, 0, 31), - [VOP2_WIN_YUV_CLIP] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL0, 19, 19), - [VOP2_WIN_YRGB_VIR] =3D REG_FIELD(RK3568_CLUSTER_WIN_VIR, 0, 15), - [VOP2_WIN_UV_VIR] =3D REG_FIELD(RK3568_CLUSTER_WIN_VIR, 16, 31), - [VOP2_WIN_Y2R_EN] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL0, 8, 8), - [VOP2_WIN_R2Y_EN] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL0, 9, 9), - [VOP2_WIN_CSC_MODE] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL0, 10, 11), - - /* Scale */ - [VOP2_WIN_SCALE_YRGB_X] =3D REG_FIELD(RK3568_CLUSTER_WIN_SCL_FACTOR_YRGB,= 0, 15), - [VOP2_WIN_SCALE_YRGB_Y] =3D REG_FIELD(RK3568_CLUSTER_WIN_SCL_FACTOR_YRGB,= 16, 31), - [VOP2_WIN_YRGB_VER_SCL_MODE] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL1, 14, = 15), - [VOP2_WIN_YRGB_HOR_SCL_MODE] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL1, 12, = 13), - [VOP2_WIN_BIC_COE_SEL] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL1, 2, 3), - [VOP2_WIN_VSD_YRGB_GT2] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL1, 28, 28), - [VOP2_WIN_VSD_YRGB_GT4] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL1, 29, 29), - - /* cluster regs */ - [VOP2_WIN_AFBC_ENABLE] =3D REG_FIELD(RK3568_CLUSTER_CTRL, 1, 1), - [VOP2_WIN_CLUSTER_ENABLE] =3D REG_FIELD(RK3568_CLUSTER_CTRL, 0, 0), - [VOP2_WIN_CLUSTER_LB_MODE] =3D REG_FIELD(RK3568_CLUSTER_CTRL, 4, 7), - - /* afbc regs */ - [VOP2_WIN_AFBC_FORMAT] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_CTRL, 2, 6), - [VOP2_WIN_AFBC_RB_SWAP] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_CTRL, 9, 9= ), - [VOP2_WIN_AFBC_UV_SWAP] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_CTRL, 10, = 10), - [VOP2_WIN_AFBC_AUTO_GATING_EN] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_OUT= PUT_CTRL, 4, 4), - [VOP2_WIN_AFBC_HALF_BLOCK_EN] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_CTRL= , 7, 7), - [VOP2_WIN_AFBC_BLOCK_SPLIT_EN] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_CTR= L, 8, 8), - [VOP2_WIN_AFBC_HDR_PTR] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_HDR_PTR, 0= , 31), - [VOP2_WIN_AFBC_PIC_SIZE] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_PIC_SIZE,= 0, 31), - [VOP2_WIN_AFBC_PIC_VIR_WIDTH] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_VIR_= WIDTH, 0, 15), - [VOP2_WIN_AFBC_TILE_NUM] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_VIR_WIDTH= , 16, 31), - [VOP2_WIN_AFBC_PIC_OFFSET] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_PIC_OFF= SET, 0, 31), - [VOP2_WIN_AFBC_DSP_OFFSET] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_DSP_OFF= SET, 0, 31), - [VOP2_WIN_AFBC_TRANSFORM_OFFSET] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_T= RANSFORM_OFFSET, 0, 31), - [VOP2_WIN_AFBC_ROTATE_90] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_ROTATE_M= ODE, 0, 0), - [VOP2_WIN_AFBC_ROTATE_270] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_ROTATE_= MODE, 1, 1), - [VOP2_WIN_XMIRROR] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_ROTATE_MODE, 2,= 2), - [VOP2_WIN_YMIRROR] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_ROTATE_MODE, 3,= 3), - [VOP2_WIN_UV_SWAP] =3D { .reg =3D 0xffffffff }, - [VOP2_WIN_COLOR_KEY] =3D { .reg =3D 0xffffffff }, - [VOP2_WIN_COLOR_KEY_EN] =3D { .reg =3D 0xffffffff }, - [VOP2_WIN_SCALE_CBCR_X] =3D { .reg =3D 0xffffffff }, - [VOP2_WIN_SCALE_CBCR_Y] =3D { .reg =3D 0xffffffff }, - [VOP2_WIN_YRGB_HSCL_FILTER_MODE] =3D { .reg =3D 0xffffffff }, - [VOP2_WIN_YRGB_VSCL_FILTER_MODE] =3D { .reg =3D 0xffffffff }, - [VOP2_WIN_CBCR_VER_SCL_MODE] =3D { .reg =3D 0xffffffff }, - [VOP2_WIN_CBCR_HSCL_FILTER_MODE] =3D { .reg =3D 0xffffffff }, - [VOP2_WIN_CBCR_HOR_SCL_MODE] =3D { .reg =3D 0xffffffff }, - [VOP2_WIN_CBCR_VSCL_FILTER_MODE] =3D { .reg =3D 0xffffffff }, - [VOP2_WIN_VSD_CBCR_GT2] =3D { .reg =3D 0xffffffff }, - [VOP2_WIN_VSD_CBCR_GT4] =3D { .reg =3D 0xffffffff }, -}; - static int vop2_cluster_init(struct vop2_win *win) { struct vop2 *vop2 =3D win->vop2; struct reg_field *cluster_regs; int ret, i; =20 - cluster_regs =3D kmemdup(vop2_cluster_regs, sizeof(vop2_cluster_regs), + cluster_regs =3D kmemdup(vop2->data->cluster_reg, + sizeof(struct reg_field) * vop2->data->nr_cluster_regs, GFP_KERNEL); if (!cluster_regs) return -ENOMEM; =20 - for (i =3D 0; i < ARRAY_SIZE(vop2_cluster_regs); i++) + for (i =3D 0; i < vop2->data->nr_cluster_regs; i++) if (cluster_regs[i].reg !=3D 0xffffffff) cluster_regs[i].reg +=3D win->offset; =20 ret =3D devm_regmap_field_bulk_alloc(vop2->dev, vop2->map, win->reg, cluster_regs, - ARRAY_SIZE(vop2_cluster_regs)); - + vop2->data->nr_cluster_regs); kfree(cluster_regs); =20 return ret; }; =20 -static struct reg_field vop2_esmart_regs[VOP2_WIN_MAX_REG] =3D { - [VOP2_WIN_ENABLE] =3D REG_FIELD(RK3568_SMART_REGION0_CTRL, 0, 0), - [VOP2_WIN_FORMAT] =3D REG_FIELD(RK3568_SMART_REGION0_CTRL, 1, 5), - [VOP2_WIN_DITHER_UP] =3D REG_FIELD(RK3568_SMART_REGION0_CTRL, 12, 12), - [VOP2_WIN_RB_SWAP] =3D REG_FIELD(RK3568_SMART_REGION0_CTRL, 14, 14), - [VOP2_WIN_UV_SWAP] =3D REG_FIELD(RK3568_SMART_REGION0_CTRL, 16, 16), - [VOP2_WIN_ACT_INFO] =3D REG_FIELD(RK3568_SMART_REGION0_ACT_INFO, 0, 31), - [VOP2_WIN_DSP_INFO] =3D REG_FIELD(RK3568_SMART_REGION0_DSP_INFO, 0, 31), - [VOP2_WIN_DSP_ST] =3D REG_FIELD(RK3568_SMART_REGION0_DSP_ST, 0, 28), - [VOP2_WIN_YRGB_MST] =3D REG_FIELD(RK3568_SMART_REGION0_YRGB_MST, 0, 31), - [VOP2_WIN_UV_MST] =3D REG_FIELD(RK3568_SMART_REGION0_CBR_MST, 0, 31), - [VOP2_WIN_YUV_CLIP] =3D REG_FIELD(RK3568_SMART_REGION0_CTRL, 17, 17), - [VOP2_WIN_YRGB_VIR] =3D REG_FIELD(RK3568_SMART_REGION0_VIR, 0, 15), - [VOP2_WIN_UV_VIR] =3D REG_FIELD(RK3568_SMART_REGION0_VIR, 16, 31), - [VOP2_WIN_Y2R_EN] =3D REG_FIELD(RK3568_SMART_CTRL0, 0, 0), - [VOP2_WIN_R2Y_EN] =3D REG_FIELD(RK3568_SMART_CTRL0, 1, 1), - [VOP2_WIN_CSC_MODE] =3D REG_FIELD(RK3568_SMART_CTRL0, 2, 3), - [VOP2_WIN_YMIRROR] =3D REG_FIELD(RK3568_SMART_CTRL1, 31, 31), - [VOP2_WIN_COLOR_KEY] =3D REG_FIELD(RK3568_SMART_COLOR_KEY_CTRL, 0, 29), - [VOP2_WIN_COLOR_KEY_EN] =3D REG_FIELD(RK3568_SMART_COLOR_KEY_CTRL, 31, 31= ), - - /* Scale */ - [VOP2_WIN_SCALE_YRGB_X] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_FACTOR_YRG= B, 0, 15), - [VOP2_WIN_SCALE_YRGB_Y] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_FACTOR_YRG= B, 16, 31), - [VOP2_WIN_SCALE_CBCR_X] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_FACTOR_CBR= , 0, 15), - [VOP2_WIN_SCALE_CBCR_Y] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_FACTOR_CBR= , 16, 31), - [VOP2_WIN_YRGB_HOR_SCL_MODE] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_CTRL,= 0, 1), - [VOP2_WIN_YRGB_HSCL_FILTER_MODE] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_C= TRL, 2, 3), - [VOP2_WIN_YRGB_VER_SCL_MODE] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_CTRL,= 4, 5), - [VOP2_WIN_YRGB_VSCL_FILTER_MODE] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_C= TRL, 6, 7), - [VOP2_WIN_CBCR_HOR_SCL_MODE] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_CTRL,= 8, 9), - [VOP2_WIN_CBCR_HSCL_FILTER_MODE] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_C= TRL, 10, 11), - [VOP2_WIN_CBCR_VER_SCL_MODE] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_CTRL,= 12, 13), - [VOP2_WIN_CBCR_VSCL_FILTER_MODE] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_C= TRL, 14, 15), - [VOP2_WIN_BIC_COE_SEL] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_CTRL, 16, 1= 7), - [VOP2_WIN_VSD_YRGB_GT2] =3D REG_FIELD(RK3568_SMART_REGION0_CTRL, 8, 8), - [VOP2_WIN_VSD_YRGB_GT4] =3D REG_FIELD(RK3568_SMART_REGION0_CTRL, 9, 9), - [VOP2_WIN_VSD_CBCR_GT2] =3D REG_FIELD(RK3568_SMART_REGION0_CTRL, 10, 10), - [VOP2_WIN_VSD_CBCR_GT4] =3D REG_FIELD(RK3568_SMART_REGION0_CTRL, 11, 11), - [VOP2_WIN_XMIRROR] =3D { .reg =3D 0xffffffff }, - [VOP2_WIN_CLUSTER_ENABLE] =3D { .reg =3D 0xffffffff }, - [VOP2_WIN_AFBC_ENABLE] =3D { .reg =3D 0xffffffff }, - [VOP2_WIN_CLUSTER_LB_MODE] =3D { .reg =3D 0xffffffff }, - [VOP2_WIN_AFBC_FORMAT] =3D { .reg =3D 0xffffffff }, - [VOP2_WIN_AFBC_RB_SWAP] =3D { .reg =3D 0xffffffff }, - [VOP2_WIN_AFBC_UV_SWAP] =3D { .reg =3D 0xffffffff }, - [VOP2_WIN_AFBC_AUTO_GATING_EN] =3D { .reg =3D 0xffffffff }, - [VOP2_WIN_AFBC_BLOCK_SPLIT_EN] =3D { .reg =3D 0xffffffff }, - [VOP2_WIN_AFBC_PIC_VIR_WIDTH] =3D { .reg =3D 0xffffffff }, - [VOP2_WIN_AFBC_TILE_NUM] =3D { .reg =3D 0xffffffff }, - [VOP2_WIN_AFBC_PIC_OFFSET] =3D { .reg =3D 0xffffffff }, - [VOP2_WIN_AFBC_PIC_SIZE] =3D { .reg =3D 0xffffffff }, - [VOP2_WIN_AFBC_DSP_OFFSET] =3D { .reg =3D 0xffffffff }, - [VOP2_WIN_AFBC_TRANSFORM_OFFSET] =3D { .reg =3D 0xffffffff }, - [VOP2_WIN_AFBC_HDR_PTR] =3D { .reg =3D 0xffffffff }, - [VOP2_WIN_AFBC_HALF_BLOCK_EN] =3D { .reg =3D 0xffffffff }, - [VOP2_WIN_AFBC_ROTATE_270] =3D { .reg =3D 0xffffffff }, - [VOP2_WIN_AFBC_ROTATE_90] =3D { .reg =3D 0xffffffff }, -}; - static int vop2_esmart_init(struct vop2_win *win) { struct vop2 *vop2 =3D win->vop2; - struct reg_field *esmart_regs; + struct reg_field *smart_regs; int ret, i; =20 - esmart_regs =3D kmemdup(vop2_esmart_regs, sizeof(vop2_esmart_regs), - GFP_KERNEL); - if (!esmart_regs) + smart_regs =3D kmemdup(vop2->data->smart_reg, + sizeof(struct reg_field) * vop2->data->nr_smart_regs, + GFP_KERNEL); + if (!smart_regs) return -ENOMEM; =20 - for (i =3D 0; i < ARRAY_SIZE(vop2_esmart_regs); i++) - if (esmart_regs[i].reg !=3D 0xffffffff) - esmart_regs[i].reg +=3D win->offset; + for (i =3D 0; i < vop2->data->nr_smart_regs; i++) + if (smart_regs[i].reg !=3D 0xffffffff) + smart_regs[i].reg +=3D win->offset; =20 ret =3D devm_regmap_field_bulk_alloc(vop2->dev, vop2->map, win->reg, - esmart_regs, - ARRAY_SIZE(vop2_esmart_regs)); - - kfree(esmart_regs); + smart_regs, + vop2->data->nr_smart_regs); + kfree(smart_regs); =20 return ret; }; @@ -3405,6 +2319,7 @@ static int vop2_bind(struct device *dev, struct devic= e *master, void *data) =20 vop2->dev =3D dev; vop2->data =3D vop2_data; + vop2->ops =3D vop2_data->ops; vop2->drm =3D drm; =20 dev_set_drvdata(dev, vop2); diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.h b/drivers/gpu/drm= /rockchip/rockchip_drm_vop2.h index bc001f715847..b27163f561de 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.h +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.h @@ -9,6 +9,7 @@ =20 #include #include +#include #include "rockchip_drm_drv.h" #include "rockchip_drm_vop.h" =20 @@ -58,6 +59,23 @@ enum vop2_scale_down_mode { #define VOP2_PD_DSC_4K BIT(6) #define VOP2_PD_ESMART BIT(7) =20 +#define vop2_output_if_is_hdmi(x) ((x) =3D=3D ROCKCHIP_VOP2_EP_HDMI0 || \ + (x) =3D=3D ROCKCHIP_VOP2_EP_HDMI1) + +#define vop2_output_if_is_dp(x) ((x) =3D=3D ROCKCHIP_VOP2_EP_DP0 || \ + (x) =3D=3D ROCKCHIP_VOP2_EP_DP1) + +#define vop2_output_if_is_edp(x) ((x) =3D=3D ROCKCHIP_VOP2_EP_EDP0 || \ + (x) =3D=3D ROCKCHIP_VOP2_EP_EDP1) + +#define vop2_output_if_is_mipi(x) ((x) =3D=3D ROCKCHIP_VOP2_EP_MIPI0 || \ + (x) =3D=3D ROCKCHIP_VOP2_EP_MIPI1) + +#define vop2_output_if_is_lvds(x) ((x) =3D=3D ROCKCHIP_VOP2_EP_LVDS0 || \ + (x) =3D=3D ROCKCHIP_VOP2_EP_LVDS1) + +#define vop2_output_if_is_dpi(x) ((x) =3D=3D ROCKCHIP_VOP2_EP_RGB0) + enum vop2_win_regs { VOP2_WIN_ENABLE, VOP2_WIN_FORMAT, @@ -155,6 +173,23 @@ struct vop2_win_data { const u8 dly[VOP2_DLY_MODE_MAX]; }; =20 +struct vop2_win { + struct vop2 *vop2; + struct drm_plane base; + const struct vop2_win_data *data; + struct regmap_field *reg[VOP2_WIN_MAX_REG]; + + /** + * @win_id: graphic window id, a cluster may be split into two + * graphics windows. + */ + u8 win_id; + u8 delay; + u32 offset; + + enum drm_plane_type type; +}; + struct vop2_video_port_data { unsigned int id; u32 feature; @@ -165,20 +200,105 @@ struct vop2_video_port_data { unsigned int offset; }; =20 +struct vop2_video_port { + struct drm_crtc crtc; + struct vop2 *vop2; + struct clk *dclk; + unsigned int id; + const struct vop2_video_port_data *data; + + struct completion dsp_hold_completion; + + /** + * @win_mask: Bitmask of windows attached to the video port; + */ + u32 win_mask; + + struct vop2_win *primary_plane; + struct drm_pending_vblank_event *event; + + unsigned int nlayers; +}; + +/** + * struct vop2_ops - helper operations for vop2 hardware + * + * These hooks are used by the common part of the vop2 driver to + * implement the proper behaviour of different variants. + */ +struct vop2_ops { + unsigned long (*setup_intf_mux)(struct vop2_video_port *vp, int ep_id, u3= 2 polflags); + void (*setup_bg_dly)(struct vop2_video_port *vp); + void (*setup_overlay)(struct vop2_video_port *vp); +}; + struct vop2_data { u8 nr_vps; u64 feature; + const struct vop2_ops *ops; const struct vop2_win_data *win; const struct vop2_video_port_data *vp; + const struct reg_field *cluster_reg; + const struct reg_field *smart_reg; const struct vop2_regs_dump *regs_dump; struct vop_rect max_input; struct vop_rect max_output; =20 + unsigned int nr_cluster_regs; + unsigned int nr_smart_regs; unsigned int win_size; unsigned int regs_dump_size; unsigned int soc_id; }; =20 +struct vop2 { + struct device *dev; + struct drm_device *drm; + struct vop2_video_port vps[ROCKCHIP_MAX_CRTC]; + + const struct vop2_data *data; + const struct vop2_ops *ops; + /* + * Number of windows that are registered as plane, may be less than the + * total number of hardware windows. + */ + u32 registered_num_wins; + + struct resource *res; + void __iomem *regs; + struct regmap *map; + + struct regmap *sys_grf; + struct regmap *vop_grf; + struct regmap *vo1_grf; + struct regmap *sys_pmu; + + /* physical map length of vop2 register */ + u32 len; + + void __iomem *lut_regs; + + /* protects crtc enable/disable */ + struct mutex vop2_lock; + + int irq; + + /* + * Some global resources are shared between all video ports(crtcs), so + * we need a ref counter here. + */ + unsigned int enable_count; + struct clk *hclk; + struct clk *aclk; + struct clk *pclk; + + /* optional internal rgb encoder */ + struct rockchip_rgb *rgb; + + /* must be put at the end of the struct */ + struct vop2_win win[]; +}; + /* interrupt define */ #define FS_NEW_INTR BIT(4) #define ADDR_SAME_INTR BIT(5) @@ -546,4 +666,43 @@ enum vop2_layer_phy_id { =20 extern const struct component_ops vop2_component_ops; =20 +static inline void vop2_writel(struct vop2 *vop2, u32 offset, u32 v) +{ + regmap_write(vop2->map, offset, v); +} + +static inline void vop2_vp_write(struct vop2_video_port *vp, u32 offset, u= 32 v) +{ + regmap_write(vp->vop2->map, vp->data->offset + offset, v); +} + +static inline u32 vop2_readl(struct vop2 *vop2, u32 offset) +{ + u32 val; + + regmap_read(vop2->map, offset, &val); + + return val; +} + +static inline void vop2_win_write(const struct vop2_win *win, unsigned int= reg, u32 v) +{ + regmap_field_write(win->reg[reg], v); +} + +static inline bool vop2_cluster_window(const struct vop2_win *win) +{ + return win->data->feature & WIN_FEATURE_CLUSTER; +} + +static inline struct vop2_video_port *to_vop2_video_port(struct drm_crtc *= crtc) +{ + return container_of(crtc, struct vop2_video_port, crtc); +} + +static inline struct vop2_win *to_vop2_win(struct drm_plane *p) +{ + return container_of(p, struct vop2_win, base); +} + #endif /* _ROCKCHIP_DRM_VOP2_H */ diff --git a/drivers/gpu/drm/rockchip/rockchip_vop2_reg.c b/drivers/gpu/drm= /rockchip/rockchip_vop2_reg.c index 8ff0bd528d65..0e577aabc9e4 100644 --- a/drivers/gpu/drm/rockchip/rockchip_vop2_reg.c +++ b/drivers/gpu/drm/rockchip/rockchip_vop2_reg.c @@ -9,12 +9,50 @@ #include #include #include +#include #include +#include #include #include =20 #include "rockchip_drm_vop2.h" =20 +union vop2_alpha_ctrl { + u32 val; + struct { + /* [0:1] */ + u32 color_mode:1; + u32 alpha_mode:1; + /* [2:3] */ + u32 blend_mode:2; + u32 alpha_cal_mode:1; + /* [5:7] */ + u32 factor_mode:3; + /* [8:9] */ + u32 alpha_en:1; + u32 src_dst_swap:1; + u32 reserved:6; + /* [16:23] */ + u32 glb_alpha:8; + } bits; +}; + +struct vop2_alpha { + union vop2_alpha_ctrl src_color_ctrl; + union vop2_alpha_ctrl dst_color_ctrl; + union vop2_alpha_ctrl src_alpha_ctrl; + union vop2_alpha_ctrl dst_alpha_ctrl; +}; + +struct vop2_alpha_config { + bool src_premulti_en; + bool dst_premulti_en; + bool src_pixel_alpha_en; + bool dst_pixel_alpha_en; + u16 src_glb_alpha_value; + u16 dst_glb_alpha_value; +}; + static const uint32_t formats_cluster[] =3D { DRM_FORMAT_XRGB2101010, DRM_FORMAT_XBGR2101010, @@ -131,6 +169,130 @@ static const uint64_t format_modifiers_afbc[] =3D { DRM_FORMAT_MOD_INVALID, }; =20 +static const struct reg_field rk3568_vop_cluster_regs[VOP2_WIN_MAX_REG] = =3D { + [VOP2_WIN_ENABLE] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL0, 0, 0), + [VOP2_WIN_FORMAT] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL0, 1, 5), + [VOP2_WIN_RB_SWAP] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL0, 14, 14), + [VOP2_WIN_DITHER_UP] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL0, 18, 18), + [VOP2_WIN_ACT_INFO] =3D REG_FIELD(RK3568_CLUSTER_WIN_ACT_INFO, 0, 31), + [VOP2_WIN_DSP_INFO] =3D REG_FIELD(RK3568_CLUSTER_WIN_DSP_INFO, 0, 31), + [VOP2_WIN_DSP_ST] =3D REG_FIELD(RK3568_CLUSTER_WIN_DSP_ST, 0, 31), + [VOP2_WIN_YRGB_MST] =3D REG_FIELD(RK3568_CLUSTER_WIN_YRGB_MST, 0, 31), + [VOP2_WIN_UV_MST] =3D REG_FIELD(RK3568_CLUSTER_WIN_CBR_MST, 0, 31), + [VOP2_WIN_YUV_CLIP] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL0, 19, 19), + [VOP2_WIN_YRGB_VIR] =3D REG_FIELD(RK3568_CLUSTER_WIN_VIR, 0, 15), + [VOP2_WIN_UV_VIR] =3D REG_FIELD(RK3568_CLUSTER_WIN_VIR, 16, 31), + [VOP2_WIN_Y2R_EN] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL0, 8, 8), + [VOP2_WIN_R2Y_EN] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL0, 9, 9), + [VOP2_WIN_CSC_MODE] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL0, 10, 11), + + /* Scale */ + [VOP2_WIN_SCALE_YRGB_X] =3D REG_FIELD(RK3568_CLUSTER_WIN_SCL_FACTOR_YRGB,= 0, 15), + [VOP2_WIN_SCALE_YRGB_Y] =3D REG_FIELD(RK3568_CLUSTER_WIN_SCL_FACTOR_YRGB,= 16, 31), + [VOP2_WIN_YRGB_VER_SCL_MODE] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL1, 14, = 15), + [VOP2_WIN_YRGB_HOR_SCL_MODE] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL1, 12, = 13), + [VOP2_WIN_BIC_COE_SEL] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL1, 2, 3), + [VOP2_WIN_VSD_YRGB_GT2] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL1, 28, 28), + [VOP2_WIN_VSD_YRGB_GT4] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL1, 29, 29), + + /* cluster regs */ + [VOP2_WIN_AFBC_ENABLE] =3D REG_FIELD(RK3568_CLUSTER_CTRL, 1, 1), + [VOP2_WIN_CLUSTER_ENABLE] =3D REG_FIELD(RK3568_CLUSTER_CTRL, 0, 0), + [VOP2_WIN_CLUSTER_LB_MODE] =3D REG_FIELD(RK3568_CLUSTER_CTRL, 4, 7), + + /* afbc regs */ + [VOP2_WIN_AFBC_FORMAT] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_CTRL, 2, 6), + [VOP2_WIN_AFBC_RB_SWAP] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_CTRL, 9, 9= ), + [VOP2_WIN_AFBC_UV_SWAP] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_CTRL, 10, = 10), + [VOP2_WIN_AFBC_AUTO_GATING_EN] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_OUT= PUT_CTRL, 4, 4), + [VOP2_WIN_AFBC_HALF_BLOCK_EN] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_CTRL= , 7, 7), + [VOP2_WIN_AFBC_BLOCK_SPLIT_EN] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_CTR= L, 8, 8), + [VOP2_WIN_AFBC_HDR_PTR] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_HDR_PTR, 0= , 31), + [VOP2_WIN_AFBC_PIC_SIZE] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_PIC_SIZE,= 0, 31), + [VOP2_WIN_AFBC_PIC_VIR_WIDTH] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_VIR_= WIDTH, 0, 15), + [VOP2_WIN_AFBC_TILE_NUM] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_VIR_WIDTH= , 16, 31), + [VOP2_WIN_AFBC_PIC_OFFSET] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_PIC_OFF= SET, 0, 31), + [VOP2_WIN_AFBC_DSP_OFFSET] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_DSP_OFF= SET, 0, 31), + [VOP2_WIN_AFBC_TRANSFORM_OFFSET] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_T= RANSFORM_OFFSET, 0, 31), + [VOP2_WIN_AFBC_ROTATE_90] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_ROTATE_M= ODE, 0, 0), + [VOP2_WIN_AFBC_ROTATE_270] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_ROTATE_= MODE, 1, 1), + [VOP2_WIN_XMIRROR] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_ROTATE_MODE, 2,= 2), + [VOP2_WIN_YMIRROR] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_ROTATE_MODE, 3,= 3), + [VOP2_WIN_UV_SWAP] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_COLOR_KEY] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_COLOR_KEY_EN] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_SCALE_CBCR_X] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_SCALE_CBCR_Y] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_YRGB_HSCL_FILTER_MODE] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_YRGB_VSCL_FILTER_MODE] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_CBCR_VER_SCL_MODE] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_CBCR_HSCL_FILTER_MODE] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_CBCR_HOR_SCL_MODE] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_CBCR_VSCL_FILTER_MODE] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_VSD_CBCR_GT2] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_VSD_CBCR_GT4] =3D { .reg =3D 0xffffffff }, +}; + +static const struct reg_field rk3568_vop_smart_regs[VOP2_WIN_MAX_REG] =3D { + [VOP2_WIN_ENABLE] =3D REG_FIELD(RK3568_SMART_REGION0_CTRL, 0, 0), + [VOP2_WIN_FORMAT] =3D REG_FIELD(RK3568_SMART_REGION0_CTRL, 1, 5), + [VOP2_WIN_DITHER_UP] =3D REG_FIELD(RK3568_SMART_REGION0_CTRL, 12, 12), + [VOP2_WIN_RB_SWAP] =3D REG_FIELD(RK3568_SMART_REGION0_CTRL, 14, 14), + [VOP2_WIN_UV_SWAP] =3D REG_FIELD(RK3568_SMART_REGION0_CTRL, 16, 16), + [VOP2_WIN_ACT_INFO] =3D REG_FIELD(RK3568_SMART_REGION0_ACT_INFO, 0, 31), + [VOP2_WIN_DSP_INFO] =3D REG_FIELD(RK3568_SMART_REGION0_DSP_INFO, 0, 31), + [VOP2_WIN_DSP_ST] =3D REG_FIELD(RK3568_SMART_REGION0_DSP_ST, 0, 28), + [VOP2_WIN_YRGB_MST] =3D REG_FIELD(RK3568_SMART_REGION0_YRGB_MST, 0, 31), + [VOP2_WIN_UV_MST] =3D REG_FIELD(RK3568_SMART_REGION0_CBR_MST, 0, 31), + [VOP2_WIN_YUV_CLIP] =3D REG_FIELD(RK3568_SMART_REGION0_CTRL, 17, 17), + [VOP2_WIN_YRGB_VIR] =3D REG_FIELD(RK3568_SMART_REGION0_VIR, 0, 15), + [VOP2_WIN_UV_VIR] =3D REG_FIELD(RK3568_SMART_REGION0_VIR, 16, 31), + [VOP2_WIN_Y2R_EN] =3D REG_FIELD(RK3568_SMART_CTRL0, 0, 0), + [VOP2_WIN_R2Y_EN] =3D REG_FIELD(RK3568_SMART_CTRL0, 1, 1), + [VOP2_WIN_CSC_MODE] =3D REG_FIELD(RK3568_SMART_CTRL0, 2, 3), + [VOP2_WIN_YMIRROR] =3D REG_FIELD(RK3568_SMART_CTRL1, 31, 31), + [VOP2_WIN_COLOR_KEY] =3D REG_FIELD(RK3568_SMART_COLOR_KEY_CTRL, 0, 29), + [VOP2_WIN_COLOR_KEY_EN] =3D REG_FIELD(RK3568_SMART_COLOR_KEY_CTRL, 31, 31= ), + + /* Scale */ + [VOP2_WIN_SCALE_YRGB_X] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_FACTOR_YRG= B, 0, 15), + [VOP2_WIN_SCALE_YRGB_Y] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_FACTOR_YRG= B, 16, 31), + [VOP2_WIN_SCALE_CBCR_X] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_FACTOR_CBR= , 0, 15), + [VOP2_WIN_SCALE_CBCR_Y] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_FACTOR_CBR= , 16, 31), + [VOP2_WIN_YRGB_HOR_SCL_MODE] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_CTRL,= 0, 1), + [VOP2_WIN_YRGB_HSCL_FILTER_MODE] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_C= TRL, 2, 3), + [VOP2_WIN_YRGB_VER_SCL_MODE] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_CTRL,= 4, 5), + [VOP2_WIN_YRGB_VSCL_FILTER_MODE] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_C= TRL, 6, 7), + [VOP2_WIN_CBCR_HOR_SCL_MODE] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_CTRL,= 8, 9), + [VOP2_WIN_CBCR_HSCL_FILTER_MODE] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_C= TRL, 10, 11), + [VOP2_WIN_CBCR_VER_SCL_MODE] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_CTRL,= 12, 13), + [VOP2_WIN_CBCR_VSCL_FILTER_MODE] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_C= TRL, 14, 15), + [VOP2_WIN_BIC_COE_SEL] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_CTRL, 16, 1= 7), + [VOP2_WIN_VSD_YRGB_GT2] =3D REG_FIELD(RK3568_SMART_REGION0_CTRL, 8, 8), + [VOP2_WIN_VSD_YRGB_GT4] =3D REG_FIELD(RK3568_SMART_REGION0_CTRL, 9, 9), + [VOP2_WIN_VSD_CBCR_GT2] =3D REG_FIELD(RK3568_SMART_REGION0_CTRL, 10, 10), + [VOP2_WIN_VSD_CBCR_GT4] =3D REG_FIELD(RK3568_SMART_REGION0_CTRL, 11, 11), + [VOP2_WIN_XMIRROR] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_CLUSTER_ENABLE] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_AFBC_ENABLE] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_CLUSTER_LB_MODE] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_AFBC_FORMAT] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_AFBC_RB_SWAP] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_AFBC_UV_SWAP] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_AFBC_AUTO_GATING_EN] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_AFBC_BLOCK_SPLIT_EN] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_AFBC_PIC_VIR_WIDTH] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_AFBC_TILE_NUM] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_AFBC_PIC_OFFSET] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_AFBC_PIC_SIZE] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_AFBC_DSP_OFFSET] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_AFBC_TRANSFORM_OFFSET] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_AFBC_HDR_PTR] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_AFBC_HALF_BLOCK_EN] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_AFBC_ROTATE_270] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_AFBC_ROTATE_90] =3D { .reg =3D 0xffffffff }, +}; + static const struct vop2_video_port_data rk3568_vop_video_ports[] =3D { { .id =3D 0, @@ -623,6 +785,811 @@ static const struct vop2_regs_dump rk3588_regs_dump[]= =3D { }, }; =20 +static unsigned long rk3568_set_intf_mux(struct vop2_video_port *vp, int i= d, u32 polflags) +{ + struct vop2 *vop2 =3D vp->vop2; + struct drm_crtc *crtc =3D &vp->crtc; + u32 die, dip; + + die =3D vop2_readl(vop2, RK3568_DSP_IF_EN); + dip =3D vop2_readl(vop2, RK3568_DSP_IF_POL); + + switch (id) { + case ROCKCHIP_VOP2_EP_RGB0: + die &=3D ~RK3568_SYS_DSP_INFACE_EN_RGB_MUX; + die |=3D RK3568_SYS_DSP_INFACE_EN_RGB | + FIELD_PREP(RK3568_SYS_DSP_INFACE_EN_RGB_MUX, vp->id); + dip &=3D ~RK3568_DSP_IF_POL__RGB_LVDS_PIN_POL; + dip |=3D FIELD_PREP(RK3568_DSP_IF_POL__RGB_LVDS_PIN_POL, polflags); + if (polflags & POLFLAG_DCLK_INV) + regmap_write(vop2->sys_grf, RK3568_GRF_VO_CON1, BIT(3 + 16) | BIT(3)); + else + regmap_write(vop2->sys_grf, RK3568_GRF_VO_CON1, BIT(3 + 16)); + break; + case ROCKCHIP_VOP2_EP_HDMI0: + die &=3D ~RK3568_SYS_DSP_INFACE_EN_HDMI_MUX; + die |=3D RK3568_SYS_DSP_INFACE_EN_HDMI | + FIELD_PREP(RK3568_SYS_DSP_INFACE_EN_HDMI_MUX, vp->id); + dip &=3D ~RK3568_DSP_IF_POL__HDMI_PIN_POL; + dip |=3D FIELD_PREP(RK3568_DSP_IF_POL__HDMI_PIN_POL, polflags); + break; + case ROCKCHIP_VOP2_EP_EDP0: + die &=3D ~RK3568_SYS_DSP_INFACE_EN_EDP_MUX; + die |=3D RK3568_SYS_DSP_INFACE_EN_EDP | + FIELD_PREP(RK3568_SYS_DSP_INFACE_EN_EDP_MUX, vp->id); + dip &=3D ~RK3568_DSP_IF_POL__EDP_PIN_POL; + dip |=3D FIELD_PREP(RK3568_DSP_IF_POL__EDP_PIN_POL, polflags); + break; + case ROCKCHIP_VOP2_EP_MIPI0: + die &=3D ~RK3568_SYS_DSP_INFACE_EN_MIPI0_MUX; + die |=3D RK3568_SYS_DSP_INFACE_EN_MIPI0 | + FIELD_PREP(RK3568_SYS_DSP_INFACE_EN_MIPI0_MUX, vp->id); + dip &=3D ~RK3568_DSP_IF_POL__MIPI_PIN_POL; + dip |=3D FIELD_PREP(RK3568_DSP_IF_POL__MIPI_PIN_POL, polflags); + break; + case ROCKCHIP_VOP2_EP_MIPI1: + die &=3D ~RK3568_SYS_DSP_INFACE_EN_MIPI1_MUX; + die |=3D RK3568_SYS_DSP_INFACE_EN_MIPI1 | + FIELD_PREP(RK3568_SYS_DSP_INFACE_EN_MIPI1_MUX, vp->id); + dip &=3D ~RK3568_DSP_IF_POL__MIPI_PIN_POL; + dip |=3D FIELD_PREP(RK3568_DSP_IF_POL__MIPI_PIN_POL, polflags); + break; + case ROCKCHIP_VOP2_EP_LVDS0: + die &=3D ~RK3568_SYS_DSP_INFACE_EN_LVDS0_MUX; + die |=3D RK3568_SYS_DSP_INFACE_EN_LVDS0 | + FIELD_PREP(RK3568_SYS_DSP_INFACE_EN_LVDS0_MUX, vp->id); + dip &=3D ~RK3568_DSP_IF_POL__RGB_LVDS_PIN_POL; + dip |=3D FIELD_PREP(RK3568_DSP_IF_POL__RGB_LVDS_PIN_POL, polflags); + break; + case ROCKCHIP_VOP2_EP_LVDS1: + die &=3D ~RK3568_SYS_DSP_INFACE_EN_LVDS1_MUX; + die |=3D RK3568_SYS_DSP_INFACE_EN_LVDS1 | + FIELD_PREP(RK3568_SYS_DSP_INFACE_EN_LVDS1_MUX, vp->id); + dip &=3D ~RK3568_DSP_IF_POL__RGB_LVDS_PIN_POL; + dip |=3D FIELD_PREP(RK3568_DSP_IF_POL__RGB_LVDS_PIN_POL, polflags); + break; + default: + drm_err(vop2->drm, "Invalid interface id %d on vp%d\n", id, vp->id); + return 0; + } + + dip |=3D RK3568_DSP_IF_POL__CFG_DONE_IMD; + + vop2_writel(vop2, RK3568_DSP_IF_EN, die); + vop2_writel(vop2, RK3568_DSP_IF_POL, dip); + + return crtc->state->adjusted_mode.crtc_clock * 1000LL; +} + +/* + * calc the dclk on rk3588 + * the available div of dclk is 1, 2, 4 + */ +static unsigned long rk3588_calc_dclk(unsigned long child_clk, unsigned lo= ng max_dclk) +{ + if (child_clk * 4 <=3D max_dclk) + return child_clk * 4; + else if (child_clk * 2 <=3D max_dclk) + return child_clk * 2; + else if (child_clk <=3D max_dclk) + return child_clk; + else + return 0; +} + +/* + * 4 pixclk/cycle on rk3588 + * RGB/eDP/HDMI: if_pixclk >=3D dclk_core + * DP: dp_pixclk =3D dclk_out <=3D dclk_core + * DSI: mipi_pixclk <=3D dclk_out <=3D dclk_core + */ +static unsigned long rk3588_calc_cru_cfg(struct vop2_video_port *vp, int i= d, + int *dclk_core_div, int *dclk_out_div, + int *if_pixclk_div, int *if_dclk_div) +{ + struct vop2 *vop2 =3D vp->vop2; + struct drm_crtc *crtc =3D &vp->crtc; + struct drm_display_mode *adjusted_mode =3D &crtc->state->adjusted_mode; + struct rockchip_crtc_state *vcstate =3D to_rockchip_crtc_state(crtc->stat= e); + int output_mode =3D vcstate->output_mode; + unsigned long v_pixclk =3D adjusted_mode->crtc_clock * 1000LL; /* video t= iming pixclk */ + unsigned long dclk_core_rate =3D v_pixclk >> 2; + unsigned long dclk_rate =3D v_pixclk; + unsigned long dclk_out_rate; + unsigned long if_pixclk_rate; + int K =3D 1; + + if (vop2_output_if_is_hdmi(id)) { + /* + * K =3D 2: dclk_core =3D if_pixclk_rate > if_dclk_rate + * K =3D 1: dclk_core =3D hdmie_edp_dclk > if_pixclk_rate + */ + if (output_mode =3D=3D ROCKCHIP_OUT_MODE_YUV420) { + dclk_rate =3D dclk_rate >> 1; + K =3D 2; + } + + if_pixclk_rate =3D (dclk_core_rate << 1) / K; + /* + * if_dclk_rate =3D dclk_core_rate / K; + * *if_pixclk_div =3D dclk_rate / if_pixclk_rate; + * *if_dclk_div =3D dclk_rate / if_dclk_rate; + */ + *if_pixclk_div =3D 2; + *if_dclk_div =3D 4; + } else if (vop2_output_if_is_edp(id)) { + /* + * edp_pixclk =3D edp_dclk > dclk_core + */ + if_pixclk_rate =3D v_pixclk / K; + dclk_rate =3D if_pixclk_rate * K; + /* + * *if_pixclk_div =3D dclk_rate / if_pixclk_rate; + * *if_dclk_div =3D *if_pixclk_div; + */ + *if_pixclk_div =3D K; + *if_dclk_div =3D K; + } else if (vop2_output_if_is_dp(id)) { + if (output_mode =3D=3D ROCKCHIP_OUT_MODE_YUV420) + dclk_out_rate =3D v_pixclk >> 3; + else + dclk_out_rate =3D v_pixclk >> 2; + + dclk_rate =3D rk3588_calc_dclk(dclk_out_rate, 600000); + if (!dclk_rate) { + drm_err(vop2->drm, "DP dclk_out_rate out of range, dclk_out_rate: %ld K= HZ\n", + dclk_out_rate); + return 0; + } + *dclk_out_div =3D dclk_rate / dclk_out_rate; + } else if (vop2_output_if_is_mipi(id)) { + if_pixclk_rate =3D dclk_core_rate / K; + /* + * dclk_core =3D dclk_out * K =3D if_pixclk * K =3D v_pixclk / 4 + */ + dclk_out_rate =3D if_pixclk_rate; + /* + * dclk_rate =3D N * dclk_core_rate N =3D (1,2,4 ), + * we get a little factor here + */ + dclk_rate =3D rk3588_calc_dclk(dclk_out_rate, 600000); + if (!dclk_rate) { + drm_err(vop2->drm, "MIPI dclk out of range, dclk_out_rate: %ld KHZ\n", + dclk_out_rate); + return 0; + } + *dclk_out_div =3D dclk_rate / dclk_out_rate; + /* + * mipi pixclk =3D=3D dclk_out + */ + *if_pixclk_div =3D 1; + } else if (vop2_output_if_is_dpi(id)) { + dclk_rate =3D v_pixclk; + } + + *dclk_core_div =3D dclk_rate / dclk_core_rate; + *if_pixclk_div =3D ilog2(*if_pixclk_div); + *if_dclk_div =3D ilog2(*if_dclk_div); + *dclk_core_div =3D ilog2(*dclk_core_div); + *dclk_out_div =3D ilog2(*dclk_out_div); + + drm_dbg(vop2->drm, "dclk: %ld, pixclk_div: %d, dclk_div: %d\n", + dclk_rate, *if_pixclk_div, *if_dclk_div); + + return dclk_rate; +} + +/* + * MIPI port mux on rk3588: + * 0: Video Port2 + * 1: Video Port3 + * 3: Video Port 1(MIPI1 only) + */ +static u32 rk3588_get_mipi_port_mux(int vp_id) +{ + if (vp_id =3D=3D 1) + return 3; + else if (vp_id =3D=3D 3) + return 1; + else + return 0; +} + +static u32 rk3588_get_hdmi_pol(u32 flags) +{ + u32 val; + + val =3D (flags & DRM_MODE_FLAG_NHSYNC) ? BIT(HSYNC_POSITIVE) : 0; + val |=3D (flags & DRM_MODE_FLAG_NVSYNC) ? BIT(VSYNC_POSITIVE) : 0; + + return val; +} + +static unsigned long rk3588_set_intf_mux(struct vop2_video_port *vp, int i= d, u32 polflags) +{ + struct vop2 *vop2 =3D vp->vop2; + int dclk_core_div, dclk_out_div, if_pixclk_div, if_dclk_div; + unsigned long clock; + u32 die, dip, div, vp_clk_div, val; + + clock =3D rk3588_calc_cru_cfg(vp, id, &dclk_core_div, &dclk_out_div, + &if_pixclk_div, &if_dclk_div); + if (!clock) + return 0; + + vp_clk_div =3D FIELD_PREP(RK3588_VP_CLK_CTRL__DCLK_CORE_DIV, dclk_core_di= v); + vp_clk_div |=3D FIELD_PREP(RK3588_VP_CLK_CTRL__DCLK_OUT_DIV, dclk_out_div= ); + + die =3D vop2_readl(vop2, RK3568_DSP_IF_EN); + dip =3D vop2_readl(vop2, RK3568_DSP_IF_POL); + div =3D vop2_readl(vop2, RK3568_DSP_IF_CTRL); + + switch (id) { + case ROCKCHIP_VOP2_EP_HDMI0: + div &=3D ~RK3588_DSP_IF_EDP_HDMI0_DCLK_DIV; + div &=3D ~RK3588_DSP_IF_EDP_HDMI0_PCLK_DIV; + div |=3D FIELD_PREP(RK3588_DSP_IF_EDP_HDMI0_DCLK_DIV, if_dclk_div); + div |=3D FIELD_PREP(RK3588_DSP_IF_EDP_HDMI0_PCLK_DIV, if_pixclk_div); + die &=3D ~RK3588_SYS_DSP_INFACE_EN_EDP_HDMI0_MUX; + die |=3D RK3588_SYS_DSP_INFACE_EN_HDMI0 | + FIELD_PREP(RK3588_SYS_DSP_INFACE_EN_EDP_HDMI0_MUX, vp->id); + val =3D rk3588_get_hdmi_pol(polflags); + regmap_write(vop2->vop_grf, RK3588_GRF_VOP_CON2, HIWORD_UPDATE(1, 1, 1)); + regmap_write(vop2->vo1_grf, RK3588_GRF_VO1_CON0, HIWORD_UPDATE(val, 6, 5= )); + break; + case ROCKCHIP_VOP2_EP_HDMI1: + div &=3D ~RK3588_DSP_IF_EDP_HDMI1_DCLK_DIV; + div &=3D ~RK3588_DSP_IF_EDP_HDMI1_PCLK_DIV; + div |=3D FIELD_PREP(RK3588_DSP_IF_EDP_HDMI1_DCLK_DIV, if_dclk_div); + div |=3D FIELD_PREP(RK3588_DSP_IF_EDP_HDMI1_PCLK_DIV, if_pixclk_div); + die &=3D ~RK3588_SYS_DSP_INFACE_EN_EDP_HDMI1_MUX; + die |=3D RK3588_SYS_DSP_INFACE_EN_HDMI1 | + FIELD_PREP(RK3588_SYS_DSP_INFACE_EN_EDP_HDMI1_MUX, vp->id); + val =3D rk3588_get_hdmi_pol(polflags); + regmap_write(vop2->vop_grf, RK3588_GRF_VOP_CON2, HIWORD_UPDATE(1, 4, 4)); + regmap_write(vop2->vo1_grf, RK3588_GRF_VO1_CON0, HIWORD_UPDATE(val, 8, 7= )); + break; + case ROCKCHIP_VOP2_EP_EDP0: + div &=3D ~RK3588_DSP_IF_EDP_HDMI0_DCLK_DIV; + div &=3D ~RK3588_DSP_IF_EDP_HDMI0_PCLK_DIV; + div |=3D FIELD_PREP(RK3588_DSP_IF_EDP_HDMI0_DCLK_DIV, if_dclk_div); + div |=3D FIELD_PREP(RK3588_DSP_IF_EDP_HDMI0_PCLK_DIV, if_pixclk_div); + die &=3D ~RK3588_SYS_DSP_INFACE_EN_EDP_HDMI0_MUX; + die |=3D RK3588_SYS_DSP_INFACE_EN_EDP0 | + FIELD_PREP(RK3588_SYS_DSP_INFACE_EN_EDP_HDMI0_MUX, vp->id); + regmap_write(vop2->vop_grf, RK3588_GRF_VOP_CON2, HIWORD_UPDATE(1, 0, 0)); + break; + case ROCKCHIP_VOP2_EP_EDP1: + div &=3D ~RK3588_DSP_IF_EDP_HDMI1_DCLK_DIV; + div &=3D ~RK3588_DSP_IF_EDP_HDMI1_PCLK_DIV; + div |=3D FIELD_PREP(RK3588_DSP_IF_EDP_HDMI0_DCLK_DIV, if_dclk_div); + div |=3D FIELD_PREP(RK3588_DSP_IF_EDP_HDMI0_PCLK_DIV, if_pixclk_div); + die &=3D ~RK3588_SYS_DSP_INFACE_EN_EDP_HDMI1_MUX; + die |=3D RK3588_SYS_DSP_INFACE_EN_EDP1 | + FIELD_PREP(RK3588_SYS_DSP_INFACE_EN_EDP_HDMI1_MUX, vp->id); + regmap_write(vop2->vop_grf, RK3588_GRF_VOP_CON2, HIWORD_UPDATE(1, 3, 3)); + break; + case ROCKCHIP_VOP2_EP_MIPI0: + div &=3D ~RK3588_DSP_IF_MIPI0_PCLK_DIV; + div |=3D FIELD_PREP(RK3588_DSP_IF_MIPI0_PCLK_DIV, if_pixclk_div); + die &=3D ~RK3588_SYS_DSP_INFACE_EN_MIPI0_MUX; + val =3D rk3588_get_mipi_port_mux(vp->id); + die |=3D RK3588_SYS_DSP_INFACE_EN_MIPI0 | + FIELD_PREP(RK3588_SYS_DSP_INFACE_EN_MIPI0_MUX, !!val); + break; + case ROCKCHIP_VOP2_EP_MIPI1: + div &=3D ~RK3588_DSP_IF_MIPI1_PCLK_DIV; + div |=3D FIELD_PREP(RK3588_DSP_IF_MIPI1_PCLK_DIV, if_pixclk_div); + die &=3D ~RK3588_SYS_DSP_INFACE_EN_MIPI1_MUX; + val =3D rk3588_get_mipi_port_mux(vp->id); + die |=3D RK3588_SYS_DSP_INFACE_EN_MIPI1 | + FIELD_PREP(RK3588_SYS_DSP_INFACE_EN_MIPI1_MUX, val); + break; + case ROCKCHIP_VOP2_EP_DP0: + die &=3D ~RK3588_SYS_DSP_INFACE_EN_DP0_MUX; + die |=3D RK3588_SYS_DSP_INFACE_EN_DP0 | + FIELD_PREP(RK3588_SYS_DSP_INFACE_EN_DP0_MUX, vp->id); + dip &=3D ~RK3588_DSP_IF_POL__DP0_PIN_POL; + dip |=3D FIELD_PREP(RK3588_DSP_IF_POL__DP0_PIN_POL, polflags); + break; + case ROCKCHIP_VOP2_EP_DP1: + die &=3D ~RK3588_SYS_DSP_INFACE_EN_MIPI1_MUX; + die |=3D RK3588_SYS_DSP_INFACE_EN_MIPI1 | + FIELD_PREP(RK3588_SYS_DSP_INFACE_EN_MIPI1_MUX, vp->id); + dip &=3D ~RK3588_DSP_IF_POL__DP1_PIN_POL; + dip |=3D FIELD_PREP(RK3588_DSP_IF_POL__DP1_PIN_POL, polflags); + break; + default: + drm_err(vop2->drm, "Invalid interface id %d on vp%d\n", id, vp->id); + return 0; + } + + dip |=3D RK3568_DSP_IF_POL__CFG_DONE_IMD; + + vop2_vp_write(vp, RK3588_VP_CLK_CTRL, vp_clk_div); + vop2_writel(vop2, RK3568_DSP_IF_EN, die); + vop2_writel(vop2, RK3568_DSP_IF_CTRL, div); + vop2_writel(vop2, RK3568_DSP_IF_POL, dip); + + return clock; +} + +static bool is_opaque(u16 alpha) +{ + return (alpha >> 8) =3D=3D 0xff; +} + +static void vop2_parse_alpha(struct vop2_alpha_config *alpha_config, + struct vop2_alpha *alpha) +{ + int src_glb_alpha_en =3D is_opaque(alpha_config->src_glb_alpha_value) ? 0= : 1; + int dst_glb_alpha_en =3D is_opaque(alpha_config->dst_glb_alpha_value) ? 0= : 1; + int src_color_mode =3D alpha_config->src_premulti_en ? + ALPHA_SRC_PRE_MUL : ALPHA_SRC_NO_PRE_MUL; + int dst_color_mode =3D alpha_config->dst_premulti_en ? + ALPHA_SRC_PRE_MUL : ALPHA_SRC_NO_PRE_MUL; + + alpha->src_color_ctrl.val =3D 0; + alpha->dst_color_ctrl.val =3D 0; + alpha->src_alpha_ctrl.val =3D 0; + alpha->dst_alpha_ctrl.val =3D 0; + + if (!alpha_config->src_pixel_alpha_en) + alpha->src_color_ctrl.bits.blend_mode =3D ALPHA_GLOBAL; + else if (alpha_config->src_pixel_alpha_en && !src_glb_alpha_en) + alpha->src_color_ctrl.bits.blend_mode =3D ALPHA_PER_PIX; + else + alpha->src_color_ctrl.bits.blend_mode =3D ALPHA_PER_PIX_GLOBAL; + + alpha->src_color_ctrl.bits.alpha_en =3D 1; + + if (alpha->src_color_ctrl.bits.blend_mode =3D=3D ALPHA_GLOBAL) { + alpha->src_color_ctrl.bits.color_mode =3D src_color_mode; + alpha->src_color_ctrl.bits.factor_mode =3D SRC_FAC_ALPHA_SRC_GLOBAL; + } else if (alpha->src_color_ctrl.bits.blend_mode =3D=3D ALPHA_PER_PIX) { + alpha->src_color_ctrl.bits.color_mode =3D src_color_mode; + alpha->src_color_ctrl.bits.factor_mode =3D SRC_FAC_ALPHA_ONE; + } else { + alpha->src_color_ctrl.bits.color_mode =3D ALPHA_SRC_PRE_MUL; + alpha->src_color_ctrl.bits.factor_mode =3D SRC_FAC_ALPHA_SRC_GLOBAL; + } + alpha->src_color_ctrl.bits.glb_alpha =3D alpha_config->src_glb_alpha_valu= e >> 8; + alpha->src_color_ctrl.bits.alpha_mode =3D ALPHA_STRAIGHT; + alpha->src_color_ctrl.bits.alpha_cal_mode =3D ALPHA_SATURATION; + + alpha->dst_color_ctrl.bits.alpha_mode =3D ALPHA_STRAIGHT; + alpha->dst_color_ctrl.bits.alpha_cal_mode =3D ALPHA_SATURATION; + alpha->dst_color_ctrl.bits.blend_mode =3D ALPHA_GLOBAL; + alpha->dst_color_ctrl.bits.glb_alpha =3D alpha_config->dst_glb_alpha_valu= e >> 8; + alpha->dst_color_ctrl.bits.color_mode =3D dst_color_mode; + alpha->dst_color_ctrl.bits.factor_mode =3D ALPHA_SRC_INVERSE; + + alpha->src_alpha_ctrl.bits.alpha_mode =3D ALPHA_STRAIGHT; + alpha->src_alpha_ctrl.bits.blend_mode =3D alpha->src_color_ctrl.bits.blen= d_mode; + alpha->src_alpha_ctrl.bits.alpha_cal_mode =3D ALPHA_SATURATION; + alpha->src_alpha_ctrl.bits.factor_mode =3D ALPHA_ONE; + + alpha->dst_alpha_ctrl.bits.alpha_mode =3D ALPHA_STRAIGHT; + if (alpha_config->dst_pixel_alpha_en && !dst_glb_alpha_en) + alpha->dst_alpha_ctrl.bits.blend_mode =3D ALPHA_PER_PIX; + else + alpha->dst_alpha_ctrl.bits.blend_mode =3D ALPHA_PER_PIX_GLOBAL; + alpha->dst_alpha_ctrl.bits.alpha_cal_mode =3D ALPHA_NO_SATURATION; + alpha->dst_alpha_ctrl.bits.factor_mode =3D ALPHA_SRC_INVERSE; +} + +static int vop2_find_start_mixer_id_for_vp(struct vop2 *vop2, u8 port_id) +{ + struct vop2_video_port *vp; + int used_layer =3D 0; + int i; + + for (i =3D 0; i < port_id; i++) { + vp =3D &vop2->vps[i]; + used_layer +=3D hweight32(vp->win_mask); + } + + return used_layer; +} + +static void vop2_setup_cluster_alpha(struct vop2 *vop2, struct vop2_win *m= ain_win) +{ + struct vop2_alpha_config alpha_config; + struct vop2_alpha alpha; + struct drm_plane_state *bottom_win_pstate; + bool src_pixel_alpha_en =3D false; + u16 src_glb_alpha_val, dst_glb_alpha_val; + u32 offset =3D 0; + bool premulti_en =3D false; + bool swap =3D false; + + /* At one win mode, win0 is dst/bottom win, and win1 is a all zero src/to= p win */ + bottom_win_pstate =3D main_win->base.state; + src_glb_alpha_val =3D 0; + dst_glb_alpha_val =3D main_win->base.state->alpha; + + if (!bottom_win_pstate->fb) + return; + + alpha_config.src_premulti_en =3D premulti_en; + alpha_config.dst_premulti_en =3D false; + alpha_config.src_pixel_alpha_en =3D src_pixel_alpha_en; + alpha_config.dst_pixel_alpha_en =3D true; /* alpha value need transfer to= next mix */ + alpha_config.src_glb_alpha_value =3D src_glb_alpha_val; + alpha_config.dst_glb_alpha_value =3D dst_glb_alpha_val; + vop2_parse_alpha(&alpha_config, &alpha); + + alpha.src_color_ctrl.bits.src_dst_swap =3D swap; + + switch (main_win->data->phys_id) { + case ROCKCHIP_VOP2_CLUSTER0: + offset =3D 0x0; + break; + case ROCKCHIP_VOP2_CLUSTER1: + offset =3D 0x10; + break; + case ROCKCHIP_VOP2_CLUSTER2: + offset =3D 0x20; + break; + case ROCKCHIP_VOP2_CLUSTER3: + offset =3D 0x30; + break; + } + + vop2_writel(vop2, RK3568_CLUSTER0_MIX_SRC_COLOR_CTRL + offset, + alpha.src_color_ctrl.val); + vop2_writel(vop2, RK3568_CLUSTER0_MIX_DST_COLOR_CTRL + offset, + alpha.dst_color_ctrl.val); + vop2_writel(vop2, RK3568_CLUSTER0_MIX_SRC_ALPHA_CTRL + offset, + alpha.src_alpha_ctrl.val); + vop2_writel(vop2, RK3568_CLUSTER0_MIX_DST_ALPHA_CTRL + offset, + alpha.dst_alpha_ctrl.val); +} + +static void vop2_setup_alpha(struct vop2_video_port *vp) +{ + struct vop2 *vop2 =3D vp->vop2; + struct drm_framebuffer *fb; + struct vop2_alpha_config alpha_config; + struct vop2_alpha alpha; + struct drm_plane *plane; + int pixel_alpha_en; + int premulti_en, gpremulti_en =3D 0; + int mixer_id; + u32 offset; + bool bottom_layer_alpha_en =3D false; + u32 dst_global_alpha =3D DRM_BLEND_ALPHA_OPAQUE; + + mixer_id =3D vop2_find_start_mixer_id_for_vp(vop2, vp->id); + alpha_config.dst_pixel_alpha_en =3D true; /* alpha value need transfer to= next mix */ + + drm_atomic_crtc_for_each_plane(plane, &vp->crtc) { + struct vop2_win *win =3D to_vop2_win(plane); + + if (plane->state->normalized_zpos =3D=3D 0 && + !is_opaque(plane->state->alpha) && + !vop2_cluster_window(win)) { + /* + * If bottom layer have global alpha effect [except cluster layer, + * because cluster have deal with bottom layer global alpha value + * at cluster mix], bottom layer mix need deal with global alpha. + */ + bottom_layer_alpha_en =3D true; + dst_global_alpha =3D plane->state->alpha; + } + } + + drm_atomic_crtc_for_each_plane(plane, &vp->crtc) { + struct vop2_win *win =3D to_vop2_win(plane); + int zpos =3D plane->state->normalized_zpos; + + /* + * Need to configure alpha from second layer. + */ + if (zpos =3D=3D 0) + continue; + + if (plane->state->pixel_blend_mode =3D=3D DRM_MODE_BLEND_PREMULTI) + premulti_en =3D 1; + else + premulti_en =3D 0; + + plane =3D &win->base; + fb =3D plane->state->fb; + + pixel_alpha_en =3D fb->format->has_alpha; + + alpha_config.src_premulti_en =3D premulti_en; + + if (bottom_layer_alpha_en && zpos =3D=3D 1) { + gpremulti_en =3D premulti_en; + /* Cd =3D Cs + (1 - As) * Cd * Agd */ + alpha_config.dst_premulti_en =3D false; + alpha_config.src_pixel_alpha_en =3D pixel_alpha_en; + alpha_config.src_glb_alpha_value =3D plane->state->alpha; + alpha_config.dst_glb_alpha_value =3D dst_global_alpha; + } else if (vop2_cluster_window(win)) { + /* Mix output data only have pixel alpha */ + alpha_config.dst_premulti_en =3D true; + alpha_config.src_pixel_alpha_en =3D true; + alpha_config.src_glb_alpha_value =3D DRM_BLEND_ALPHA_OPAQUE; + alpha_config.dst_glb_alpha_value =3D DRM_BLEND_ALPHA_OPAQUE; + } else { + /* Cd =3D Cs + (1 - As) * Cd */ + alpha_config.dst_premulti_en =3D true; + alpha_config.src_pixel_alpha_en =3D pixel_alpha_en; + alpha_config.src_glb_alpha_value =3D plane->state->alpha; + alpha_config.dst_glb_alpha_value =3D DRM_BLEND_ALPHA_OPAQUE; + } + + vop2_parse_alpha(&alpha_config, &alpha); + + offset =3D (mixer_id + zpos - 1) * 0x10; + vop2_writel(vop2, RK3568_MIX0_SRC_COLOR_CTRL + offset, + alpha.src_color_ctrl.val); + vop2_writel(vop2, RK3568_MIX0_DST_COLOR_CTRL + offset, + alpha.dst_color_ctrl.val); + vop2_writel(vop2, RK3568_MIX0_SRC_ALPHA_CTRL + offset, + alpha.src_alpha_ctrl.val); + vop2_writel(vop2, RK3568_MIX0_DST_ALPHA_CTRL + offset, + alpha.dst_alpha_ctrl.val); + } + + if (vp->id =3D=3D 0) { + if (bottom_layer_alpha_en) { + /* Transfer pixel alpha to hdr mix */ + alpha_config.src_premulti_en =3D gpremulti_en; + alpha_config.dst_premulti_en =3D true; + alpha_config.src_pixel_alpha_en =3D true; + alpha_config.src_glb_alpha_value =3D DRM_BLEND_ALPHA_OPAQUE; + alpha_config.dst_glb_alpha_value =3D DRM_BLEND_ALPHA_OPAQUE; + vop2_parse_alpha(&alpha_config, &alpha); + + vop2_writel(vop2, RK3568_HDR0_SRC_COLOR_CTRL, + alpha.src_color_ctrl.val); + vop2_writel(vop2, RK3568_HDR0_DST_COLOR_CTRL, + alpha.dst_color_ctrl.val); + vop2_writel(vop2, RK3568_HDR0_SRC_ALPHA_CTRL, + alpha.src_alpha_ctrl.val); + vop2_writel(vop2, RK3568_HDR0_DST_ALPHA_CTRL, + alpha.dst_alpha_ctrl.val); + } else { + vop2_writel(vop2, RK3568_HDR0_SRC_COLOR_CTRL, 0); + } + } +} + +static void rk3568_vop2_setup_layer_mixer(struct vop2_video_port *vp) +{ + struct vop2 *vop2 =3D vp->vop2; + struct drm_plane *plane; + u32 layer_sel =3D 0; + u32 port_sel; + u8 old_layer_id; + u8 layer_sel_id; + unsigned int ofs; + u32 ovl_ctrl; + int i; + struct vop2_video_port *vp0 =3D &vop2->vps[0]; + struct vop2_video_port *vp1 =3D &vop2->vps[1]; + struct vop2_video_port *vp2 =3D &vop2->vps[2]; + struct rockchip_crtc_state *vcstate =3D to_rockchip_crtc_state(vp->crtc.s= tate); + + ovl_ctrl =3D vop2_readl(vop2, RK3568_OVL_CTRL); + ovl_ctrl |=3D RK3568_OVL_CTRL__LAYERSEL_REGDONE_IMD; + if (vcstate->yuv_overlay) + ovl_ctrl |=3D RK3568_OVL_CTRL__YUV_MODE(vp->id); + else + ovl_ctrl &=3D ~RK3568_OVL_CTRL__YUV_MODE(vp->id); + + vop2_writel(vop2, RK3568_OVL_CTRL, ovl_ctrl); + + port_sel =3D vop2_readl(vop2, RK3568_OVL_PORT_SEL); + port_sel &=3D RK3568_OVL_PORT_SEL__SEL_PORT; + + if (vp0->nlayers) + port_sel |=3D FIELD_PREP(RK3568_OVL_PORT_SET__PORT0_MUX, + vp0->nlayers - 1); + else + port_sel |=3D FIELD_PREP(RK3568_OVL_PORT_SET__PORT0_MUX, 8); + + if (vp1->nlayers) + port_sel |=3D FIELD_PREP(RK3568_OVL_PORT_SET__PORT1_MUX, + (vp0->nlayers + vp1->nlayers - 1)); + else + port_sel |=3D FIELD_PREP(RK3568_OVL_PORT_SET__PORT1_MUX, 8); + + if (vp2->nlayers) + port_sel |=3D FIELD_PREP(RK3568_OVL_PORT_SET__PORT2_MUX, + (vp2->nlayers + vp1->nlayers + vp0->nlayers - 1)); + else + port_sel |=3D FIELD_PREP(RK3568_OVL_PORT_SET__PORT2_MUX, 8); + + layer_sel =3D vop2_readl(vop2, RK3568_OVL_LAYER_SEL); + + ofs =3D 0; + for (i =3D 0; i < vp->id; i++) + ofs +=3D vop2->vps[i].nlayers; + + drm_atomic_crtc_for_each_plane(plane, &vp->crtc) { + struct vop2_win *win =3D to_vop2_win(plane); + struct vop2_win *old_win; + + /* + * Find the layer this win bind in old state. + */ + for (old_layer_id =3D 0; old_layer_id < vop2->data->win_size; old_layer_= id++) { + layer_sel_id =3D (layer_sel >> (4 * old_layer_id)) & 0xf; + if (layer_sel_id =3D=3D win->data->layer_sel_id) + break; + } + + /* + * Find the win bind to this layer in old state + */ + for (i =3D 0; i < vop2->data->win_size; i++) { + old_win =3D &vop2->win[i]; + layer_sel_id =3D (layer_sel >> (4 * (plane->state->normalized_zpos + of= s))) & 0xf; + if (layer_sel_id =3D=3D old_win->data->layer_sel_id) + break; + } + + switch (win->data->phys_id) { + case ROCKCHIP_VOP2_CLUSTER0: + port_sel &=3D ~RK3568_OVL_PORT_SEL__CLUSTER0; + port_sel |=3D FIELD_PREP(RK3568_OVL_PORT_SEL__CLUSTER0, vp->id); + break; + case ROCKCHIP_VOP2_CLUSTER1: + port_sel &=3D ~RK3568_OVL_PORT_SEL__CLUSTER1; + port_sel |=3D FIELD_PREP(RK3568_OVL_PORT_SEL__CLUSTER1, vp->id); + break; + case ROCKCHIP_VOP2_CLUSTER2: + port_sel &=3D ~RK3588_OVL_PORT_SEL__CLUSTER2; + port_sel |=3D FIELD_PREP(RK3588_OVL_PORT_SEL__CLUSTER2, vp->id); + break; + case ROCKCHIP_VOP2_CLUSTER3: + port_sel &=3D ~RK3588_OVL_PORT_SEL__CLUSTER3; + port_sel |=3D FIELD_PREP(RK3588_OVL_PORT_SEL__CLUSTER3, vp->id); + break; + case ROCKCHIP_VOP2_ESMART0: + port_sel &=3D ~RK3568_OVL_PORT_SEL__ESMART0; + port_sel |=3D FIELD_PREP(RK3568_OVL_PORT_SEL__ESMART0, vp->id); + break; + case ROCKCHIP_VOP2_ESMART1: + port_sel &=3D ~RK3568_OVL_PORT_SEL__ESMART1; + port_sel |=3D FIELD_PREP(RK3568_OVL_PORT_SEL__ESMART1, vp->id); + break; + case ROCKCHIP_VOP2_ESMART2: + port_sel &=3D ~RK3588_OVL_PORT_SEL__ESMART2; + port_sel |=3D FIELD_PREP(RK3588_OVL_PORT_SEL__ESMART2, vp->id); + break; + case ROCKCHIP_VOP2_ESMART3: + port_sel &=3D ~RK3588_OVL_PORT_SEL__ESMART3; + port_sel |=3D FIELD_PREP(RK3588_OVL_PORT_SEL__ESMART3, vp->id); + break; + case ROCKCHIP_VOP2_SMART0: + port_sel &=3D ~RK3568_OVL_PORT_SEL__SMART0; + port_sel |=3D FIELD_PREP(RK3568_OVL_PORT_SEL__SMART0, vp->id); + break; + case ROCKCHIP_VOP2_SMART1: + port_sel &=3D ~RK3568_OVL_PORT_SEL__SMART1; + port_sel |=3D FIELD_PREP(RK3568_OVL_PORT_SEL__SMART1, vp->id); + break; + } + + layer_sel &=3D ~RK3568_OVL_LAYER_SEL__LAYER(plane->state->normalized_zpo= s + ofs, + 0x7); + layer_sel |=3D RK3568_OVL_LAYER_SEL__LAYER(plane->state->normalized_zpos= + ofs, + win->data->layer_sel_id); + /* + * When we bind a window from layerM to layerN, we also need to move the= old + * window on layerN to layerM to avoid one window selected by two or mor= e layers. + */ + layer_sel &=3D ~RK3568_OVL_LAYER_SEL__LAYER(old_layer_id, 0x7); + layer_sel |=3D RK3568_OVL_LAYER_SEL__LAYER(old_layer_id, old_win->data->= layer_sel_id); + } + + vop2_writel(vop2, RK3568_OVL_LAYER_SEL, layer_sel); + vop2_writel(vop2, RK3568_OVL_PORT_SEL, port_sel); +} + +static void rk3568_vop2_setup_dly_for_windows(struct vop2_video_port *vp) +{ + struct vop2 *vop2 =3D vp->vop2; + struct vop2_win *win; + int i =3D 0; + u32 cdly =3D 0, sdly =3D 0; + + for (i =3D 0; i < vop2->data->win_size; i++) { + u32 dly; + + win =3D &vop2->win[i]; + dly =3D win->delay; + + switch (win->data->phys_id) { + case ROCKCHIP_VOP2_CLUSTER0: + cdly |=3D FIELD_PREP(RK3568_CLUSTER_DLY_NUM__CLUSTER0_0, dly); + cdly |=3D FIELD_PREP(RK3568_CLUSTER_DLY_NUM__CLUSTER0_1, dly); + break; + case ROCKCHIP_VOP2_CLUSTER1: + cdly |=3D FIELD_PREP(RK3568_CLUSTER_DLY_NUM__CLUSTER1_0, dly); + cdly |=3D FIELD_PREP(RK3568_CLUSTER_DLY_NUM__CLUSTER1_1, dly); + break; + case ROCKCHIP_VOP2_ESMART0: + sdly |=3D FIELD_PREP(RK3568_SMART_DLY_NUM__ESMART0, dly); + break; + case ROCKCHIP_VOP2_ESMART1: + sdly |=3D FIELD_PREP(RK3568_SMART_DLY_NUM__ESMART1, dly); + break; + case ROCKCHIP_VOP2_SMART0: + sdly |=3D FIELD_PREP(RK3568_SMART_DLY_NUM__SMART0, dly); + break; + case ROCKCHIP_VOP2_SMART1: + sdly |=3D FIELD_PREP(RK3568_SMART_DLY_NUM__SMART1, dly); + break; + } + } + + vop2_writel(vop2, RK3568_CLUSTER_DLY_NUM, cdly); + vop2_writel(vop2, RK3568_SMART_DLY_NUM, sdly); +} + +static void rk3568_vop2_setup_overlay(struct vop2_video_port *vp) +{ + struct vop2 *vop2 =3D vp->vop2; + struct drm_crtc *crtc =3D &vp->crtc; + struct drm_plane *plane; + + vp->win_mask =3D 0; + + drm_atomic_crtc_for_each_plane(plane, crtc) { + struct vop2_win *win =3D to_vop2_win(plane); + + win->delay =3D win->data->dly[VOP2_DLY_MODE_DEFAULT]; + + vp->win_mask |=3D BIT(win->data->phys_id); + + if (vop2_cluster_window(win)) + vop2_setup_cluster_alpha(vop2, win); + } + + if (!vp->win_mask) + return; + + rk3568_vop2_setup_layer_mixer(vp); + vop2_setup_alpha(vp); + rk3568_vop2_setup_dly_for_windows(vp); +} + +static void rk3568_vop2_setup_bg_dly(struct vop2_video_port *vp) +{ + struct drm_crtc *crtc =3D &vp->crtc; + struct drm_display_mode *mode =3D &crtc->state->adjusted_mode; + u16 hdisplay =3D mode->crtc_hdisplay; + u16 hsync_len =3D mode->crtc_hsync_end - mode->crtc_hsync_start; + u32 bg_dly; + u32 pre_scan_dly; + + bg_dly =3D vp->data->pre_scan_max_dly[3]; + vop2_writel(vp->vop2, RK3568_VP_BG_MIX_CTRL(vp->id), + FIELD_PREP(RK3568_VP_BG_MIX_CTRL__BG_DLY, bg_dly)); + + pre_scan_dly =3D ((bg_dly + (hdisplay >> 1) - 1) << 16) | hsync_len; + vop2_vp_write(vp, RK3568_VP_PRE_SCAN_HTIMING, pre_scan_dly); +} + +static const struct vop2_ops rk3568_vop_ops =3D { + .setup_intf_mux =3D rk3568_set_intf_mux, + .setup_bg_dly =3D rk3568_vop2_setup_bg_dly, + .setup_overlay =3D rk3568_vop2_setup_overlay, +}; + +static const struct vop2_ops rk3588_vop_ops =3D { + .setup_intf_mux =3D rk3588_set_intf_mux, + .setup_bg_dly =3D rk3568_vop2_setup_bg_dly, + .setup_overlay =3D rk3568_vop2_setup_overlay, +}; + static const struct vop2_data rk3566_vop =3D { .feature =3D VOP2_FEATURE_HAS_SYS_GRF, .nr_vps =3D 3, @@ -631,8 +1598,13 @@ static const struct vop2_data rk3566_vop =3D { .vp =3D rk3568_vop_video_ports, .win =3D rk3568_vop_win_data, .win_size =3D ARRAY_SIZE(rk3568_vop_win_data), + .cluster_reg =3D rk3568_vop_cluster_regs, + .nr_cluster_regs =3D ARRAY_SIZE(rk3568_vop_cluster_regs), + .smart_reg =3D rk3568_vop_smart_regs, + .nr_smart_regs =3D ARRAY_SIZE(rk3568_vop_smart_regs), .regs_dump =3D rk3568_regs_dump, .regs_dump_size =3D ARRAY_SIZE(rk3568_regs_dump), + .ops =3D &rk3568_vop_ops, .soc_id =3D 3566, }; =20 @@ -644,8 +1616,13 @@ static const struct vop2_data rk3568_vop =3D { .vp =3D rk3568_vop_video_ports, .win =3D rk3568_vop_win_data, .win_size =3D ARRAY_SIZE(rk3568_vop_win_data), + .cluster_reg =3D rk3568_vop_cluster_regs, + .nr_cluster_regs =3D ARRAY_SIZE(rk3568_vop_cluster_regs), + .smart_reg =3D rk3568_vop_smart_regs, + .nr_smart_regs =3D ARRAY_SIZE(rk3568_vop_smart_regs), .regs_dump =3D rk3568_regs_dump, .regs_dump_size =3D ARRAY_SIZE(rk3568_regs_dump), + .ops =3D &rk3568_vop_ops, .soc_id =3D 3568, }; =20 @@ -658,8 +1635,13 @@ static const struct vop2_data rk3588_vop =3D { .vp =3D rk3588_vop_video_ports, .win =3D rk3588_vop_win_data, .win_size =3D ARRAY_SIZE(rk3588_vop_win_data), + .cluster_reg =3D rk3568_vop_cluster_regs, + .nr_cluster_regs =3D ARRAY_SIZE(rk3568_vop_cluster_regs), + .smart_reg =3D rk3568_vop_smart_regs, + .nr_smart_regs =3D ARRAY_SIZE(rk3568_vop_smart_regs), .regs_dump =3D rk3588_regs_dump, .regs_dump_size =3D ARRAY_SIZE(rk3588_regs_dump), + .ops =3D &rk3588_vop_ops, .soc_id =3D 3588, }; =20 --=20 2.34.1 From nobody Fri Nov 29 11:34:16 2024 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.2]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BB015770E8; Fri, 20 Sep 2024 08:22:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820551; cv=none; b=S1Vz3+K3YhoLVD0q49gPmFbE/rBM0RX+eJVVqkQOeZFcGCVeqA/Hy99KYWfei+EEYYJq1ivowBgHJSzhhDh2v7JowM8zhhDAGTNotvici1/w2RLKDdS2c67likCQRtCuHJ/swv6QLZjx0GgZFd5QlK7Byqbi9GUOPynE2CHIbkc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820551; c=relaxed/simple; bh=66WIHQvyvw0g642s7+5EosWxXkvKknlZBd98whhwf/k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oidA9fmayuMrISkfMVrLndE0oEefaLWRWx3yRMduWpa1XxV3cis/rjuhM00TQYmH0VkWRp9TwASnqJSCPj3iPNPqOSbrWXx68dIvbUl299djp+5NNZWweQneBdvRiPSuOuwfvTpn7ktBv8KWA2AIH4B5SQ4vq8/nrfq+yLbLYnU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=L6J3EeJG; arc=none smtp.client-ip=220.197.31.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="L6J3EeJG" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version; bh=IQ20X j2cdAgvNngQqjG2LvtTlOQtMYrO22RkJ7I1rZI=; b=L6J3EeJGV/AP5M7/dE2vh vtURaaRHRvxMKcP5x5es/eLfq2H4460/MIdwGnjrFKVyJ6uKnlFwR0chUhicOX3X C9+KK9M9LiZR4pwPNNiLIwDt3FnLG38D5stIw+x/uVCBlmowT6vbZgBNoy8PtUfw 2lLub8LTkfaL+LUwMPGR5I= Received: from ProDesk.. (unknown [58.22.7.114]) by gzga-smtp-mta-g2-2 (Coremail) with SMTP id _____wCnrwiiMO1mwEbaIA--.9708S2; Fri, 20 Sep 2024 16:21:59 +0800 (CST) From: Andy Yan To: heiko@sntech.de Cc: hjc@rock-chips.com, krzk+dt@kernel.org, robh@kernel.org, conor+dt@kernel.org, s.hauer@pengutronix.de, devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, derek.foreman@collabora.com, minhuadotchen@gmail.com, detlev.casanova@collabora.com, Andy Yan Subject: [PATCH v3 09/15] drm/rockchip: vop2: Support for different layer selet configuration between VPs Date: Fri, 20 Sep 2024 16:21:52 +0800 Message-ID: <20240920082153.6829-1-andyshrk@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240920081626.6433-1-andyshrk@163.com> References: <20240920081626.6433-1-andyshrk@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wCnrwiiMO1mwEbaIA--.9708S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxtrW8JF1ftrykKrWfKFyrCrg_yoWfJr4Dpa yUursIg3Z8Cr45tryUJay8Zr4rGwnxta13uan3Kw1xGFn5KrWDJF4ktF93A3Z8KF93Zry8 Xw1YgryDZrZrtFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j773kUUUUU= X-CM-SenderInfo: 5dqg52xkunqiywtou0bp/1tbiqQhgXmVODBHhGwAAsT Content-Type: text/plain; charset="utf-8" From: Andy Yan In the upcoming VOP for rk3576, every VP has it's own LAYER_SEL register, and the configuration value of each VP for the same window maybe different, so extend the layer_sel_id to array, let it can descption the layer select configuration value for different VP. Signed-off-by: Andy Yan Tested-by: Detlev Casanova Tested-by: Michael Riesch # on RK3568 --- (no changes since v1) drivers/gpu/drm/rockchip/rockchip_drm_vop2.h | 4 +-- drivers/gpu/drm/rockchip/rockchip_vop2_reg.c | 38 ++++++++++---------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.h b/drivers/gpu/drm= /rockchip/rockchip_drm_vop2.h index b27163f561de..9b269f6e576e 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.h +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.h @@ -163,9 +163,9 @@ struct vop2_win_data { const unsigned int supported_rotations; =20 /** - * @layer_sel_id: defined by register OVERLAY_LAYER_SEL of VOP2 + * @layer_sel_id: defined by register OVERLAY_LAYER_SEL or PORTn_LAYER_SEL */ - unsigned int layer_sel_id; + unsigned int layer_sel_id[ROCKCHIP_MAX_CRTC]; uint64_t feature; =20 unsigned int max_upscale_factor; diff --git a/drivers/gpu/drm/rockchip/rockchip_vop2_reg.c b/drivers/gpu/drm= /rockchip/rockchip_vop2_reg.c index 0e577aabc9e4..8473dc9c232c 100644 --- a/drivers/gpu/drm/rockchip/rockchip_vop2_reg.c +++ b/drivers/gpu/drm/rockchip/rockchip_vop2_reg.c @@ -342,7 +342,8 @@ static const struct vop2_win_data rk3568_vop_win_data[]= =3D { .formats =3D formats_smart, .nformats =3D ARRAY_SIZE(formats_smart), .format_modifiers =3D format_modifiers, - .layer_sel_id =3D 3, + /* 0xf means this layer can't attached to this VP */ + .layer_sel_id =3D { 3, 3, 3, 0xf }, .supported_rotations =3D DRM_MODE_REFLECT_Y, .type =3D DRM_PLANE_TYPE_PRIMARY, .max_upscale_factor =3D 8, @@ -355,7 +356,7 @@ static const struct vop2_win_data rk3568_vop_win_data[]= =3D { .nformats =3D ARRAY_SIZE(formats_smart), .format_modifiers =3D format_modifiers, .base =3D 0x1e00, - .layer_sel_id =3D 7, + .layer_sel_id =3D { 7, 7, 7, 0xf }, .supported_rotations =3D DRM_MODE_REFLECT_Y, .type =3D DRM_PLANE_TYPE_PRIMARY, .max_upscale_factor =3D 8, @@ -368,7 +369,7 @@ static const struct vop2_win_data rk3568_vop_win_data[]= =3D { .nformats =3D ARRAY_SIZE(formats_rk356x_esmart), .format_modifiers =3D format_modifiers, .base =3D 0x1a00, - .layer_sel_id =3D 6, + .layer_sel_id =3D { 6, 6, 6, 0xf }, .supported_rotations =3D DRM_MODE_REFLECT_Y, .type =3D DRM_PLANE_TYPE_PRIMARY, .max_upscale_factor =3D 8, @@ -381,7 +382,7 @@ static const struct vop2_win_data rk3568_vop_win_data[]= =3D { .nformats =3D ARRAY_SIZE(formats_rk356x_esmart), .format_modifiers =3D format_modifiers, .base =3D 0x1800, - .layer_sel_id =3D 2, + .layer_sel_id =3D { 2, 2, 2, 0xf }, .supported_rotations =3D DRM_MODE_REFLECT_Y, .type =3D DRM_PLANE_TYPE_PRIMARY, .max_upscale_factor =3D 8, @@ -394,7 +395,7 @@ static const struct vop2_win_data rk3568_vop_win_data[]= =3D { .formats =3D formats_cluster, .nformats =3D ARRAY_SIZE(formats_cluster), .format_modifiers =3D format_modifiers_afbc, - .layer_sel_id =3D 0, + .layer_sel_id =3D { 0, 0, 0, 0xf }, .supported_rotations =3D DRM_MODE_ROTATE_90 | DRM_MODE_ROTATE_270 | DRM_MODE_REFLECT_X | DRM_MODE_REFLECT_Y, .max_upscale_factor =3D 4, @@ -409,7 +410,7 @@ static const struct vop2_win_data rk3568_vop_win_data[]= =3D { .formats =3D formats_cluster, .nformats =3D ARRAY_SIZE(formats_cluster), .format_modifiers =3D format_modifiers_afbc, - .layer_sel_id =3D 1, + .layer_sel_id =3D { 1, 1, 1, 0xf }, .supported_rotations =3D DRM_MODE_ROTATE_90 | DRM_MODE_ROTATE_270 | DRM_MODE_REFLECT_X | DRM_MODE_REFLECT_Y, .type =3D DRM_PLANE_TYPE_OVERLAY, @@ -574,7 +575,7 @@ static const struct vop2_win_data rk3588_vop_win_data[]= =3D { .formats =3D formats_cluster, .nformats =3D ARRAY_SIZE(formats_cluster), .format_modifiers =3D format_modifiers_afbc, - .layer_sel_id =3D 0, + .layer_sel_id =3D { 0, 0, 0, 0 }, .supported_rotations =3D DRM_MODE_ROTATE_90 | DRM_MODE_ROTATE_270 | DRM_MODE_REFLECT_X | DRM_MODE_REFLECT_Y, .max_upscale_factor =3D 4, @@ -589,7 +590,7 @@ static const struct vop2_win_data rk3588_vop_win_data[]= =3D { .formats =3D formats_cluster, .nformats =3D ARRAY_SIZE(formats_cluster), .format_modifiers =3D format_modifiers_afbc, - .layer_sel_id =3D 1, + .layer_sel_id =3D { 1, 1, 1, 1 }, .supported_rotations =3D DRM_MODE_ROTATE_90 | DRM_MODE_ROTATE_270 | DRM_MODE_REFLECT_X | DRM_MODE_REFLECT_Y, .type =3D DRM_PLANE_TYPE_PRIMARY, @@ -604,7 +605,7 @@ static const struct vop2_win_data rk3588_vop_win_data[]= =3D { .formats =3D formats_cluster, .nformats =3D ARRAY_SIZE(formats_cluster), .format_modifiers =3D format_modifiers_afbc, - .layer_sel_id =3D 4, + .layer_sel_id =3D { 4, 4, 4, 4 }, .supported_rotations =3D DRM_MODE_ROTATE_90 | DRM_MODE_ROTATE_270 | DRM_MODE_REFLECT_X | DRM_MODE_REFLECT_Y, .type =3D DRM_PLANE_TYPE_PRIMARY, @@ -619,7 +620,7 @@ static const struct vop2_win_data rk3588_vop_win_data[]= =3D { .formats =3D formats_cluster, .nformats =3D ARRAY_SIZE(formats_cluster), .format_modifiers =3D format_modifiers_afbc, - .layer_sel_id =3D 5, + .layer_sel_id =3D { 5, 5, 5, 5 }, .supported_rotations =3D DRM_MODE_ROTATE_90 | DRM_MODE_ROTATE_270 | DRM_MODE_REFLECT_X | DRM_MODE_REFLECT_Y, .type =3D DRM_PLANE_TYPE_PRIMARY, @@ -634,7 +635,7 @@ static const struct vop2_win_data rk3588_vop_win_data[]= =3D { .nformats =3D ARRAY_SIZE(formats_esmart), .format_modifiers =3D format_modifiers, .base =3D 0x1800, - .layer_sel_id =3D 2, + .layer_sel_id =3D { 2, 2, 2, 2 }, .supported_rotations =3D DRM_MODE_REFLECT_Y, .type =3D DRM_PLANE_TYPE_OVERLAY, .max_upscale_factor =3D 8, @@ -647,7 +648,7 @@ static const struct vop2_win_data rk3588_vop_win_data[]= =3D { .nformats =3D ARRAY_SIZE(formats_esmart), .format_modifiers =3D format_modifiers, .base =3D 0x1a00, - .layer_sel_id =3D 3, + .layer_sel_id =3D { 3, 3, 3, 3 }, .supported_rotations =3D DRM_MODE_REFLECT_Y, .type =3D DRM_PLANE_TYPE_OVERLAY, .max_upscale_factor =3D 8, @@ -660,7 +661,7 @@ static const struct vop2_win_data rk3588_vop_win_data[]= =3D { .formats =3D formats_esmart, .nformats =3D ARRAY_SIZE(formats_esmart), .format_modifiers =3D format_modifiers, - .layer_sel_id =3D 6, + .layer_sel_id =3D { 6, 6, 6, 6 }, .supported_rotations =3D DRM_MODE_REFLECT_Y, .type =3D DRM_PLANE_TYPE_OVERLAY, .max_upscale_factor =3D 8, @@ -673,7 +674,7 @@ static const struct vop2_win_data rk3588_vop_win_data[]= =3D { .nformats =3D ARRAY_SIZE(formats_esmart), .format_modifiers =3D format_modifiers, .base =3D 0x1e00, - .layer_sel_id =3D 7, + .layer_sel_id =3D { 7, 7, 7, 7 }, .supported_rotations =3D DRM_MODE_REFLECT_Y, .type =3D DRM_PLANE_TYPE_OVERLAY, .max_upscale_factor =3D 8, @@ -1420,7 +1421,7 @@ static void rk3568_vop2_setup_layer_mixer(struct vop2= _video_port *vp) */ for (old_layer_id =3D 0; old_layer_id < vop2->data->win_size; old_layer_= id++) { layer_sel_id =3D (layer_sel >> (4 * old_layer_id)) & 0xf; - if (layer_sel_id =3D=3D win->data->layer_sel_id) + if (layer_sel_id =3D=3D win->data->layer_sel_id[vp->id]) break; } =20 @@ -1430,7 +1431,7 @@ static void rk3568_vop2_setup_layer_mixer(struct vop2= _video_port *vp) for (i =3D 0; i < vop2->data->win_size; i++) { old_win =3D &vop2->win[i]; layer_sel_id =3D (layer_sel >> (4 * (plane->state->normalized_zpos + of= s))) & 0xf; - if (layer_sel_id =3D=3D old_win->data->layer_sel_id) + if (layer_sel_id =3D=3D old_win->data->layer_sel_id[vp->id]) break; } =20 @@ -1480,13 +1481,14 @@ static void rk3568_vop2_setup_layer_mixer(struct vo= p2_video_port *vp) layer_sel &=3D ~RK3568_OVL_LAYER_SEL__LAYER(plane->state->normalized_zpo= s + ofs, 0x7); layer_sel |=3D RK3568_OVL_LAYER_SEL__LAYER(plane->state->normalized_zpos= + ofs, - win->data->layer_sel_id); + win->data->layer_sel_id[vp->id]); /* * When we bind a window from layerM to layerN, we also need to move the= old * window on layerN to layerM to avoid one window selected by two or mor= e layers. */ layer_sel &=3D ~RK3568_OVL_LAYER_SEL__LAYER(old_layer_id, 0x7); - layer_sel |=3D RK3568_OVL_LAYER_SEL__LAYER(old_layer_id, old_win->data->= layer_sel_id); + layer_sel |=3D RK3568_OVL_LAYER_SEL__LAYER(old_layer_id, + old_win->data->layer_sel_id[vp->id]); } =20 vop2_writel(vop2, RK3568_OVL_LAYER_SEL, layer_sel); --=20 2.34.1 From nobody Fri Nov 29 11:34:16 2024 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.5]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5B8A113541B; Fri, 20 Sep 2024 08:22:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820561; cv=none; b=kwfUb+E8kwE/I7tVpbYiZ8pZyGBqIg88j8KKUYPTKnws5pf4dC+iEt0N6okd7xGuiZSReJ7mvca1pB9wzFs1HW6bJ8LA62fmeO0XpamhzBOS8qatIuhvhyYU9weJ3Cus4x4rtdUNoBY08hI1bwm4/mi3SDZFgei/JxSX6oCkecY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820561; c=relaxed/simple; bh=qvjlaw18F8d9nyKc0aqvXANq5Mx8e0zYgibpk8xJiQw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TIsW5nlvwlJkl3aXIev+ePbTCA4N4sTxNWulB2PG0Vt4Pj/ZBc6fge6Hid6UEKElFBrrvxzhfj45zxBauqQZpdqKoMbDt2pot65E73yEkil0SR5NjiAeLRW2a8NVy59EEBRBncsE1xPshQgfs6rMnXKvpnbNZkhYgScGrxC8fJw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=W0mQwA7n; arc=none smtp.client-ip=220.197.31.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="W0mQwA7n" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version; bh=+L2hu lmOrj8kWPHYwkIDVi7uLloU6A250/+u13q2u8M=; b=W0mQwA7nUnaRDzLOKaL3R 6RA5vNAJEdtqdlcUVe93t3KRGQ8DYpszvrO7491xSbG12KDboSmiBplIzlJPsmQV hFvM8c4JUdn4Uw1ehJdvGAfvMp/h7B59Uk9KXf+5cfyLh0t8zjrk2f9W377Jw/gm ZZULwiDmmF9EiiBm9Ga0SY= Received: from ProDesk.. (unknown [58.22.7.114]) by gzsmtp1 (Coremail) with SMTP id sCgvCgAn7jywMO1mJzMoCQ--.45724S2; Fri, 20 Sep 2024 16:22:12 +0800 (CST) From: Andy Yan To: heiko@sntech.de Cc: hjc@rock-chips.com, krzk+dt@kernel.org, robh@kernel.org, conor+dt@kernel.org, s.hauer@pengutronix.de, devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, derek.foreman@collabora.com, minhuadotchen@gmail.com, detlev.casanova@collabora.com, Andy Yan Subject: [PATCH v3 10/15] drm/rockchip: vop2: Introduce vop hardware version Date: Fri, 20 Sep 2024 16:22:06 +0800 Message-ID: <20240920082207.6863-1-andyshrk@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240920081626.6433-1-andyshrk@163.com> References: <20240920081626.6433-1-andyshrk@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: sCgvCgAn7jywMO1mJzMoCQ--.45724S2 X-Coremail-Antispam: 1Uf129KBjvJXoW3Xry3tF47Aw4xCr4kKryUZFb_yoW7ArW7pF W7AFWYgrWxGa1jgws7Xay3ZF4aywn2yayxGanrGw13t3sxKr9rC3Z0qF1ayFs0qFnFkr4j krn7A34UWF47tr7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jFT5dUUUUU= X-CM-SenderInfo: 5dqg52xkunqiywtou0bp/1tbiMxRgXmbtL08sBAAAsa Content-Type: text/plain; charset="utf-8" From: Andy Yan There is a version number hardcoded in the VOP VERSION_INFO register, and the version number increments sequentially based on the production order of the SOC. So using this version number to distinguish different VOP features will simplify the code. Signed-off-by: Andy Yan Tested-by: Detlev Casanova Tested-by: Michael Riesch # on RK3568 --- Changes in v3: - Add comments for why we should treat rk3566 with special care. - Add hardware version check Changes in v2: - Introduce vop hardware version drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 17 ++++++++++++++--- drivers/gpu/drm/rockchip/rockchip_drm_vop2.h | 11 +++++++++++ drivers/gpu/drm/rockchip/rockchip_vop2_reg.c | 3 +++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c b/drivers/gpu/drm= /rockchip/rockchip_drm_vop2.c index 6a7982ad3550..b4964c70149f 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c @@ -354,7 +354,7 @@ static bool vop2_output_uv_swap(u32 bus_format, u32 out= put_mode) =20 static bool vop2_output_rg_swap(struct vop2 *vop2, u32 bus_format) { - if (vop2->data->soc_id =3D=3D 3588) { + if (vop2->version =3D=3D VOP_VERSION_RK3588) { if (bus_format =3D=3D MEDIA_BUS_FMT_YUV8_1X24 || bus_format =3D=3D MEDIA_BUS_FMT_YUV10_1X30) return true; @@ -798,6 +798,7 @@ static void rk3588_vop2_power_domain_enable_all(struct = vop2 *vop2) static void vop2_enable(struct vop2 *vop2) { int ret; + u32 version; =20 ret =3D pm_runtime_resume_and_get(vop2->dev); if (ret < 0) { @@ -817,10 +818,19 @@ static void vop2_enable(struct vop2 *vop2) return; } =20 + version =3D vop2_readl(vop2, RK3568_VERSION_INFO); + if (version !=3D vop2->version) { + drm_err(vop2->drm, "Hardware version(0x%08x) mismatch\n", version); + return; + } + /* + * rk3566 share the same vop version with rk3568, so + * wen need to use soc_id for identification here. + */ if (vop2->data->soc_id =3D=3D 3566) vop2_writel(vop2, RK3568_OTP_WIN_EN, 1); =20 - if (vop2->data->soc_id =3D=3D 3588) + if (vop2->version =3D=3D VOP_VERSION_RK3588) rk3588_vop2_power_domain_enable_all(vop2); =20 vop2_writel(vop2, RK3568_REG_CFG_DONE, RK3568_REG_CFG_DONE__GLB_CFG_DONE_= EN); @@ -1231,7 +1241,7 @@ static void vop2_plane_atomic_update(struct drm_plane= *plane, * this bit is gating disable, we should write 1 to * disable gating when enable afbc. */ - if (vop2->data->soc_id =3D=3D 3566 || vop2->data->soc_id =3D=3D 3568) + if (vop2->version =3D=3D VOP_VERSION_RK3568) vop2_win_write(win, VOP2_WIN_AFBC_AUTO_GATING_EN, 0); else vop2_win_write(win, VOP2_WIN_AFBC_AUTO_GATING_EN, 1); @@ -2320,6 +2330,7 @@ static int vop2_bind(struct device *dev, struct devic= e *master, void *data) vop2->dev =3D dev; vop2->data =3D vop2_data; vop2->ops =3D vop2_data->ops; + vop2->version =3D vop2_data->version; vop2->drm =3D drm; =20 dev_set_drvdata(dev, vop2); diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.h b/drivers/gpu/drm= /rockchip/rockchip_drm_vop2.h index 9b269f6e576e..871d9bcd1d80 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.h +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.h @@ -13,6 +13,15 @@ #include "rockchip_drm_drv.h" #include "rockchip_drm_vop.h" =20 +#define VOP2_VERSION(major, minor, build) ((major) << 24 | (minor) << 16 |= (build)) + +/* The new SOC VOP version is bigger than the old */ +#define VOP_VERSION_RK3568 VOP2_VERSION(0x40, 0x15, 0x8023) +#define VOP_VERSION_RK3588 VOP2_VERSION(0x40, 0x17, 0x6786) +#define VOP_VERSION_RK3528 VOP2_VERSION(0x50, 0x17, 0x1263) +#define VOP_VERSION_RK3562 VOP2_VERSION(0x50, 0x17, 0x4350) +#define VOP_VERSION_RK3576 VOP2_VERSION(0x50, 0x19, 0x9765) + #define VOP2_VP_FEATURE_OUTPUT_10BIT BIT(0) =20 #define VOP2_FEATURE_HAS_SYS_GRF BIT(0) @@ -235,6 +244,7 @@ struct vop2_ops { struct vop2_data { u8 nr_vps; u64 feature; + u32 version; const struct vop2_ops *ops; const struct vop2_win_data *win; const struct vop2_video_port_data *vp; @@ -252,6 +262,7 @@ struct vop2_data { }; =20 struct vop2 { + u32 version; struct device *dev; struct drm_device *drm; struct vop2_video_port vps[ROCKCHIP_MAX_CRTC]; diff --git a/drivers/gpu/drm/rockchip/rockchip_vop2_reg.c b/drivers/gpu/drm= /rockchip/rockchip_vop2_reg.c index 8473dc9c232c..efd704464fab 100644 --- a/drivers/gpu/drm/rockchip/rockchip_vop2_reg.c +++ b/drivers/gpu/drm/rockchip/rockchip_vop2_reg.c @@ -1593,6 +1593,7 @@ static const struct vop2_ops rk3588_vop_ops =3D { }; =20 static const struct vop2_data rk3566_vop =3D { + .version =3D VOP_VERSION_RK3568, .feature =3D VOP2_FEATURE_HAS_SYS_GRF, .nr_vps =3D 3, .max_input =3D { 4096, 2304 }, @@ -1611,6 +1612,7 @@ static const struct vop2_data rk3566_vop =3D { }; =20 static const struct vop2_data rk3568_vop =3D { + .version =3D VOP_VERSION_RK3568, .feature =3D VOP2_FEATURE_HAS_SYS_GRF, .nr_vps =3D 3, .max_input =3D { 4096, 2304 }, @@ -1629,6 +1631,7 @@ static const struct vop2_data rk3568_vop =3D { }; =20 static const struct vop2_data rk3588_vop =3D { + .version =3D VOP_VERSION_RK3588, .feature =3D VOP2_FEATURE_HAS_SYS_GRF | VOP2_FEATURE_HAS_VO1_GRF | VOP2_FEATURE_HAS_VOP_GRF | VOP2_FEATURE_HAS_SYS_PMU, .nr_vps =3D 4, --=20 2.34.1 From nobody Fri Nov 29 11:34:16 2024 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.5]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DAC4A13AA4E; Fri, 20 Sep 2024 08:22:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820577; cv=none; b=Bmugu+WwlbIgDCnjkzwUkVnvMYVA9VEGDK+ToE3RDhT1pEirYrWLKGMCN3ULvy6YGwUIWxFaap3/YaVXRxfvNEugP/5bRsduLW4Oq7XgQrRglbPbaYQ2PZkR9Njs6ZWmnXqv7JdbWlZGnflE7zKGXrEtgA+iu3yGsGBIWHe12yw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820577; c=relaxed/simple; bh=crGAeVD9C52Z8tCthXUiJX4Yh4qf4cH3Gfydib+n0VI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lz057j+El/EtyF1MRpzi00LP/lCT8Xw6pF7BV3vEVJllPTRT3vJqsV3vsT07DpIP1Un7Vx+UnNq2BfzG+YlXMVWJ54sQwvcoL2lrwJaRiNY9sMTjWli2SWfnZoQ2L9k6oPNIh9nETOcnn8aNQ68SRw2WHipA7A6kuP76bby6BcU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=kpO6RUvI; arc=none smtp.client-ip=117.135.210.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="kpO6RUvI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version; bh=YF4IX iwSA9TAaPW947dg3/6HfjKE0T8O5IcQwAmdgkA=; b=kpO6RUvIOFZI4NPWffD4K YJ+kLW04RiMwNDBd2VoNlpNA//BjaGzfrQeWsXwDEpQUSq+8jZ313E9oGm//Hmve c4iycugCl9Z/o020OpV+Pgvmv8GaNVYdyIox11KqJZ8/MVt7PF3+keaN0z2BbBNE o2CO4W7ltT/BfBNxgqvQxo= Received: from ProDesk.. (unknown [58.22.7.114]) by gzga-smtp-mta-g2-4 (Coremail) with SMTP id _____wD3H8y7MO1mK66fCQ--.6610S2; Fri, 20 Sep 2024 16:22:23 +0800 (CST) From: Andy Yan To: heiko@sntech.de Cc: hjc@rock-chips.com, krzk+dt@kernel.org, robh@kernel.org, conor+dt@kernel.org, s.hauer@pengutronix.de, devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, derek.foreman@collabora.com, minhuadotchen@gmail.com, detlev.casanova@collabora.com, Andy Yan Subject: [PATCH v3 11/15] drm/rockchip: vop2: Register the primary plane and overlay plane separately Date: Fri, 20 Sep 2024 16:22:17 +0800 Message-ID: <20240920082218.6893-1-andyshrk@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240920081626.6433-1-andyshrk@163.com> References: <20240920081626.6433-1-andyshrk@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wD3H8y7MO1mK66fCQ--.6610S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxGFWxtw4kKr43tFyrKryxuFg_yoWrCr1Upa 13ta90vr17WF42gry8JF4jyFWYyan2ka17Crs8Kw1a934fKr93ur4rKFn8AF1ruFnrWFya kFW3K39YgFWjgr7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j7fHUUUUUU= X-CM-SenderInfo: 5dqg52xkunqiywtou0bp/xtbB0gNgXmWX0hs3pAAAsH Content-Type: text/plain; charset="utf-8" From: Andy Yan In the upcoming VOP of rk3576, a Window cannot attach to all Video Ports, so make sure all VP find it's suitable primary plane, then register the remain windows as overlay plane will make code easier. Signed-off-by: Andy Yan Tested-by: Detlev Casanova Tested-by: Michael Riesch # on RK3568 --- Changes in v3: - Add comments for why we should treat rk3566 with special care. drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 100 +++++++++++-------- 1 file changed, 61 insertions(+), 39 deletions(-) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c b/drivers/gpu/drm= /rockchip/rockchip_drm_vop2.c index b4964c70149f..e293310b3042 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c @@ -2024,22 +2024,29 @@ static int vop2_plane_init(struct vop2 *vop2, struc= t vop2_win *win, return 0; } =20 -static struct vop2_video_port *find_vp_without_primary(struct vop2 *vop2) +/* + * On RK3566 these windows don't have an independent + * framebuffer. They can only share/mirror the framebuffer + * with smart0, esmart0 and cluster0 respectively. + * And RK3566 share the same vop version with Rk3568, so we + * need to use soc_id for identification here. + */ +static bool vop2_is_mirror_win(struct vop2_win *win) { - int i; - - for (i =3D 0; i < vop2->data->nr_vps; i++) { - struct vop2_video_port *vp =3D &vop2->vps[i]; - - if (!vp->crtc.port) - continue; - if (vp->primary_plane) - continue; + struct vop2 *vop2 =3D win->vop2; =20 - return vp; + if (vop2->data->soc_id =3D=3D 3566) { + switch (win->data->phys_id) { + case ROCKCHIP_VOP2_SMART1: + case ROCKCHIP_VOP2_ESMART1: + case ROCKCHIP_VOP2_CLUSTER1: + return true; + default: + return false; + } + } else { + return false; } - - return NULL; } =20 static int vop2_create_crtcs(struct vop2 *vop2) @@ -2050,7 +2057,9 @@ static int vop2_create_crtcs(struct vop2 *vop2) struct drm_plane *plane; struct device_node *port; struct vop2_video_port *vp; - int i, nvp, nvps =3D 0; + struct vop2_win *win; + u32 possible_crtcs; + int i, j, nvp, nvps =3D 0; int ret; =20 for (i =3D 0; i < vop2_data->nr_vps; i++) { @@ -2089,42 +2098,55 @@ static int vop2_create_crtcs(struct vop2 *vop2) } =20 nvp =3D 0; - for (i =3D 0; i < vop2->registered_num_wins; i++) { - struct vop2_win *win =3D &vop2->win[i]; - u32 possible_crtcs =3D 0; - - if (vop2->data->soc_id =3D=3D 3566) { - /* - * On RK3566 these windows don't have an independent - * framebuffer. They share the framebuffer with smart0, - * esmart0 and cluster0 respectively. - */ - switch (win->data->phys_id) { - case ROCKCHIP_VOP2_SMART1: - case ROCKCHIP_VOP2_ESMART1: - case ROCKCHIP_VOP2_CLUSTER1: + /* Register a primary plane for every crtc */ + for (i =3D 0; i < vop2_data->nr_vps; i++) { + vp =3D &vop2->vps[i]; + + if (!vp->crtc.port) + continue; + + for (j =3D 0; j < vop2->registered_num_wins; j++) { + win =3D &vop2->win[j]; + + /* Aready registered as primary plane */ + if (win->base.type =3D=3D DRM_PLANE_TYPE_PRIMARY) + continue; + + if (vop2_is_mirror_win(win)) continue; - } - } =20 - if (win->type =3D=3D DRM_PLANE_TYPE_PRIMARY) { - vp =3D find_vp_without_primary(vop2); - if (vp) { + if (win->type =3D=3D DRM_PLANE_TYPE_PRIMARY) { possible_crtcs =3D BIT(nvp); vp->primary_plane =3D win; + ret =3D vop2_plane_init(vop2, win, possible_crtcs); + if (ret) { + drm_err(vop2->drm, "failed to init primary plane %s: %d\n", + win->data->name, ret); + return ret; + } nvp++; - } else { - /* change the unused primary window to overlay window */ - win->type =3D DRM_PLANE_TYPE_OVERLAY; + break; } } + } + + /* Register all unused window as overlay plane */ + for (i =3D 0; i < vop2->registered_num_wins; i++) { + win =3D &vop2->win[i]; + + /* Aready registered as primary plane */ + if (win->base.type =3D=3D DRM_PLANE_TYPE_PRIMARY) + continue; + + if (vop2_is_mirror_win(win)) + continue; =20 - if (win->type =3D=3D DRM_PLANE_TYPE_OVERLAY) - possible_crtcs =3D (1 << nvps) - 1; + win->type =3D DRM_PLANE_TYPE_OVERLAY; =20 + possible_crtcs =3D (1 << nvps) - 1; ret =3D vop2_plane_init(vop2, win, possible_crtcs); if (ret) { - drm_err(vop2->drm, "failed to init plane %s: %d\n", + drm_err(vop2->drm, "failed to init overlay plane %s: %d\n", win->data->name, ret); return ret; } --=20 2.34.1 From nobody Fri Nov 29 11:34:16 2024 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.5]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 416BC13A3F7; Fri, 20 Sep 2024 08:22:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820578; cv=none; b=eUKLEgsAvUD1Iu9RSuzfxOjRMvC8MoIYxuhqI4Be0sgBmaRB39uktYPglqnNNBINRmphPLy75wZ3U4sgPk4JDUiCZ0x4No8xJDOUtbjZRtCvgn/c5KtUP13NVvR8HkOR1RjOwTVCw3RSpNDgQc48Bb+fhusJR6F74CK3A4P02I4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820578; c=relaxed/simple; bh=1J3Ib/7AKZhWTIigKdPyi62sC5Wr/oH9QxVfgptQxw4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gecpO5ndPmkWKTi+Le4YnFX0o2SSPm2LqCxYvDpWS6+xosqKx2rol80euQnVx3to915w4A71DR5+IbnKucSr4AXeN/bmr3+teXmvehJJNzqYGh9q4OSOUt8rZQrzyn3oVW2Fr7MDZBEmiJdfidw6Q8GDezGzPUzY+UMDuatwz2M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=Pencszbb; arc=none smtp.client-ip=117.135.210.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="Pencszbb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version; bh=ADJCW UsgZCd8r/Ij0sNjbTndczhdweGSv1hZH8aR7jI=; b=Pencszbb69Yf7rKdEMjq8 9WH3LLD1/VMdFwUKj9jAIathNl739mflh6TGV78yBsHAfEmvxVXLQkh3peYqdOvP BU2wv3xaLEp3zthF7nkLTMQWPHopfIfoVPtiOddebHRG1tSgPlKCxo9SkAIP6FRG oKfRMsd9ODNiqiUzuytWFU= Received: from ProDesk.. (unknown [58.22.7.114]) by gzsmtp2 (Coremail) with SMTP id sSgvCgA3VcXGMO1ml_VnBg--.49853S2; Fri, 20 Sep 2024 16:22:34 +0800 (CST) From: Andy Yan To: heiko@sntech.de Cc: hjc@rock-chips.com, krzk+dt@kernel.org, robh@kernel.org, conor+dt@kernel.org, s.hauer@pengutronix.de, devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, derek.foreman@collabora.com, minhuadotchen@gmail.com, detlev.casanova@collabora.com, Andy Yan Subject: [PATCH v3 12/15] drm/rockchip: vop2: Set plane possible crtcs by possible vp mask Date: Fri, 20 Sep 2024 16:22:27 +0800 Message-ID: <20240920082230.6922-1-andyshrk@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240920081626.6433-1-andyshrk@163.com> References: <20240920081626.6433-1-andyshrk@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: sSgvCgA3VcXGMO1ml_VnBg--.49853S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxtrW8JFWkXF43Zr17tw45GFg_yoWxtr45pa yxZr9xWF43Cr4agry7Ja98uFyak3sxAw4a93ZrKFsxKr13Kry7Wr1UK3Z8CFyDWFy8Zr1j vw43tryDur17tFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jF7KsUUUUU= X-CM-SenderInfo: 5dqg52xkunqiywtou0bp/1tbiqQpgXmVODBHlSAAAsG Content-Type: text/plain; charset="utf-8" From: Andy Yan In the upcoming VOP of rk3576, a window cannot attach to all Video Ports, we introduce a possible_vp_mask for every window to indicate which Video Ports this window can attach to. Signed-off-by: Andy Yan Tested-by: Detlev Casanova Tested-by: Michael Riesch # on RK3568 --- (no changes since v1) drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 18 +++++++++++++++++- drivers/gpu/drm/rockchip/rockchip_drm_vop2.h | 1 + drivers/gpu/drm/rockchip/rockchip_vop2_reg.c | 14 ++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c b/drivers/gpu/drm= /rockchip/rockchip_drm_vop2.c index e293310b3042..9603bd8491bc 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c @@ -2112,6 +2112,10 @@ static int vop2_create_crtcs(struct vop2 *vop2) if (win->base.type =3D=3D DRM_PLANE_TYPE_PRIMARY) continue; =20 + /* If this win can not attached to this VP */ + if (!(win->data->possible_vp_mask & BIT(vp->id))) + continue; + if (vop2_is_mirror_win(win)) continue; =20 @@ -2143,7 +2147,19 @@ static int vop2_create_crtcs(struct vop2 *vop2) =20 win->type =3D DRM_PLANE_TYPE_OVERLAY; =20 - possible_crtcs =3D (1 << nvps) - 1; + possible_crtcs =3D 0; + nvp =3D 0; + for (j =3D 0; j < vop2_data->nr_vps; j++) { + vp =3D &vop2->vps[j]; + + if (!vp->crtc.port) + continue; + + if (win->data->possible_vp_mask & BIT(vp->id)) + possible_crtcs |=3D BIT(nvp); + nvp++; + } + ret =3D vop2_plane_init(vop2, win, possible_crtcs); if (ret) { drm_err(vop2->drm, "failed to init overlay plane %s: %d\n", diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.h b/drivers/gpu/drm= /rockchip/rockchip_drm_vop2.h index 871d9bcd1d80..064167afebf4 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.h +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.h @@ -164,6 +164,7 @@ struct vop2_win_data { unsigned int phys_id; =20 u32 base; + u32 possible_vp_mask; enum drm_plane_type type; =20 u32 nformats; diff --git a/drivers/gpu/drm/rockchip/rockchip_vop2_reg.c b/drivers/gpu/drm= /rockchip/rockchip_vop2_reg.c index efd704464fab..95e31ee84f4f 100644 --- a/drivers/gpu/drm/rockchip/rockchip_vop2_reg.c +++ b/drivers/gpu/drm/rockchip/rockchip_vop2_reg.c @@ -339,6 +339,7 @@ static const struct vop2_win_data rk3568_vop_win_data[]= =3D { .name =3D "Smart0-win0", .phys_id =3D ROCKCHIP_VOP2_SMART0, .base =3D 0x1c00, + .possible_vp_mask =3D BIT(0) | BIT(1) | BIT(2), .formats =3D formats_smart, .nformats =3D ARRAY_SIZE(formats_smart), .format_modifiers =3D format_modifiers, @@ -352,6 +353,7 @@ static const struct vop2_win_data rk3568_vop_win_data[]= =3D { }, { .name =3D "Smart1-win0", .phys_id =3D ROCKCHIP_VOP2_SMART1, + .possible_vp_mask =3D BIT(0) | BIT(1) | BIT(2), .formats =3D formats_smart, .nformats =3D ARRAY_SIZE(formats_smart), .format_modifiers =3D format_modifiers, @@ -365,6 +367,7 @@ static const struct vop2_win_data rk3568_vop_win_data[]= =3D { }, { .name =3D "Esmart1-win0", .phys_id =3D ROCKCHIP_VOP2_ESMART1, + .possible_vp_mask =3D BIT(0) | BIT(1) | BIT(2), .formats =3D formats_rk356x_esmart, .nformats =3D ARRAY_SIZE(formats_rk356x_esmart), .format_modifiers =3D format_modifiers, @@ -378,6 +381,7 @@ static const struct vop2_win_data rk3568_vop_win_data[]= =3D { }, { .name =3D "Esmart0-win0", .phys_id =3D ROCKCHIP_VOP2_ESMART0, + .possible_vp_mask =3D BIT(0) | BIT(1) | BIT(2), .formats =3D formats_rk356x_esmart, .nformats =3D ARRAY_SIZE(formats_rk356x_esmart), .format_modifiers =3D format_modifiers, @@ -392,6 +396,7 @@ static const struct vop2_win_data rk3568_vop_win_data[]= =3D { .name =3D "Cluster0-win0", .phys_id =3D ROCKCHIP_VOP2_CLUSTER0, .base =3D 0x1000, + .possible_vp_mask =3D BIT(0) | BIT(1) | BIT(2), .formats =3D formats_cluster, .nformats =3D ARRAY_SIZE(formats_cluster), .format_modifiers =3D format_modifiers_afbc, @@ -407,6 +412,7 @@ static const struct vop2_win_data rk3568_vop_win_data[]= =3D { .name =3D "Cluster1-win0", .phys_id =3D ROCKCHIP_VOP2_CLUSTER1, .base =3D 0x1200, + .possible_vp_mask =3D BIT(0) | BIT(1) | BIT(2), .formats =3D formats_cluster, .nformats =3D ARRAY_SIZE(formats_cluster), .format_modifiers =3D format_modifiers_afbc, @@ -572,6 +578,7 @@ static const struct vop2_win_data rk3588_vop_win_data[]= =3D { .name =3D "Cluster0-win0", .phys_id =3D ROCKCHIP_VOP2_CLUSTER0, .base =3D 0x1000, + .possible_vp_mask =3D BIT(0) | BIT(1) | BIT(2) | BIT(3), .formats =3D formats_cluster, .nformats =3D ARRAY_SIZE(formats_cluster), .format_modifiers =3D format_modifiers_afbc, @@ -587,6 +594,7 @@ static const struct vop2_win_data rk3588_vop_win_data[]= =3D { .name =3D "Cluster1-win0", .phys_id =3D ROCKCHIP_VOP2_CLUSTER1, .base =3D 0x1200, + .possible_vp_mask =3D BIT(0) | BIT(1) | BIT(2) | BIT(3), .formats =3D formats_cluster, .nformats =3D ARRAY_SIZE(formats_cluster), .format_modifiers =3D format_modifiers_afbc, @@ -602,6 +610,7 @@ static const struct vop2_win_data rk3588_vop_win_data[]= =3D { .name =3D "Cluster2-win0", .phys_id =3D ROCKCHIP_VOP2_CLUSTER2, .base =3D 0x1400, + .possible_vp_mask =3D BIT(0) | BIT(1) | BIT(2) | BIT(3), .formats =3D formats_cluster, .nformats =3D ARRAY_SIZE(formats_cluster), .format_modifiers =3D format_modifiers_afbc, @@ -617,6 +626,7 @@ static const struct vop2_win_data rk3588_vop_win_data[]= =3D { .name =3D "Cluster3-win0", .phys_id =3D ROCKCHIP_VOP2_CLUSTER3, .base =3D 0x1600, + .possible_vp_mask =3D BIT(0) | BIT(1) | BIT(2) | BIT(3), .formats =3D formats_cluster, .nformats =3D ARRAY_SIZE(formats_cluster), .format_modifiers =3D format_modifiers_afbc, @@ -631,6 +641,7 @@ static const struct vop2_win_data rk3588_vop_win_data[]= =3D { }, { .name =3D "Esmart0-win0", .phys_id =3D ROCKCHIP_VOP2_ESMART0, + .possible_vp_mask =3D BIT(0) | BIT(1) | BIT(2) | BIT(3), .formats =3D formats_esmart, .nformats =3D ARRAY_SIZE(formats_esmart), .format_modifiers =3D format_modifiers, @@ -644,6 +655,7 @@ static const struct vop2_win_data rk3588_vop_win_data[]= =3D { }, { .name =3D "Esmart1-win0", .phys_id =3D ROCKCHIP_VOP2_ESMART1, + .possible_vp_mask =3D BIT(0) | BIT(1) | BIT(2) | BIT(3), .formats =3D formats_esmart, .nformats =3D ARRAY_SIZE(formats_esmart), .format_modifiers =3D format_modifiers, @@ -658,6 +670,7 @@ static const struct vop2_win_data rk3588_vop_win_data[]= =3D { .name =3D "Esmart2-win0", .phys_id =3D ROCKCHIP_VOP2_ESMART2, .base =3D 0x1c00, + .possible_vp_mask =3D BIT(0) | BIT(1) | BIT(2) | BIT(3), .formats =3D formats_esmart, .nformats =3D ARRAY_SIZE(formats_esmart), .format_modifiers =3D format_modifiers, @@ -670,6 +683,7 @@ static const struct vop2_win_data rk3588_vop_win_data[]= =3D { }, { .name =3D "Esmart3-win0", .phys_id =3D ROCKCHIP_VOP2_ESMART3, + .possible_vp_mask =3D BIT(0) | BIT(1) | BIT(2) | BIT(3), .formats =3D formats_esmart, .nformats =3D ARRAY_SIZE(formats_esmart), .format_modifiers =3D format_modifiers, --=20 2.34.1 From nobody Fri Nov 29 11:34:16 2024 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.4]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 92EC57DA7F; Fri, 20 Sep 2024 08:23:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820605; cv=none; b=MKGyrIaTiQGTz3Uckgq7rNEV0TU435WgIhaDWM37OxkhfkQSQS1Jp6WzYzIJshiFL6dSxpT+5jyZHhsUoVysTbyKbSQ2l9mLO4o2bI6zBvCawdd4jyuBqOO0lIGpIwDzx0puqc8kmC6cIpEgYGRRgc5WaGeYk/t9H5Tt0Y+k74g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820605; c=relaxed/simple; bh=ACt1+YihUlgaEx/fQmEz6ytZsrPV98VA/NEP28yauno=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ve6koE9wpE5eFObygvcZn/rTKs/gx4dzrwp6TImwPe09xyrAJmBg1R5+myZfTh+wTCjUi/GHV2tIU+XuRlBjV+smogNla9fvWY2gx7u6GCHj8ilQTt++9dUVBroJYX58MhqY4Xg+ZwJ8ctuN+ibNIQYlW/QMqEWyyfd6+RPDGUc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=cxlYDHHq; arc=none smtp.client-ip=220.197.31.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="cxlYDHHq" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version; bh=pssPv On+4Ieo8JXCdj0k3N11a+VxA4LtocfM2lHt8OE=; b=cxlYDHHqN6gHPczPCrCzj EOIi95Ao05cvnzsQYNhve+gEUMZMrQrBsdIQb7+1b0mWTEA0m/FQba1Ss46vkR+d Olo5yinXYBr4FFCEgfsr9EZwAydjyXBUOQzHGt0amzjcPiTyjBrOuCzrAIZA414w g7YC6poKQ6BUPVoXiyT4UI= Received: from ProDesk.. (unknown [58.22.7.114]) by gzga-smtp-mta-g3-2 (Coremail) with SMTP id _____wCXDpvcMO1mQpM6KA--.41288S2; Fri, 20 Sep 2024 16:22:56 +0800 (CST) From: Andy Yan To: heiko@sntech.de Cc: hjc@rock-chips.com, krzk+dt@kernel.org, robh@kernel.org, conor+dt@kernel.org, s.hauer@pengutronix.de, devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, derek.foreman@collabora.com, minhuadotchen@gmail.com, detlev.casanova@collabora.com, Andy Yan Subject: [PATCH v3 13/15] drm/rockchip: vop2: Add uv swap for cluster window Date: Fri, 20 Sep 2024 16:22:40 +0800 Message-ID: <20240920082251.6952-1-andyshrk@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240920081626.6433-1-andyshrk@163.com> References: <20240920081626.6433-1-andyshrk@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: _____wCXDpvcMO1mQpM6KA--.41288S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7tFW8Ww1kAF4UAw47JFy7ZFb_yoW8Gr4kpw 43ZrWqgrW5Kw4Iq34kJFZ8ZFWfCwnxKayxZws7tw109ry3KFyDK3ZIkFWUAr1qya12kF47 tFn3A3y7Zr1jvrJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j7fHUUUUUU= X-CM-SenderInfo: 5dqg52xkunqiywtou0bp/1tbiqRhgXmVODBHm+gABsk Content-Type: text/plain; charset="utf-8" From: Andy Yan The Cluster windows of upcoming VOP on rk3576 also support linear YUV support, we need to set uv swap bit for it. As the VOP2_WIN_UV_SWA register defined on rk3568/rk3588 is 0xffffffff, so this register will not be touched on these two platforms. Signed-off-by: Andy Yan Tested-by: Detlev Casanova Tested-by: Michael Riesch # on RK3568 --- (no changes since v1) drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c b/drivers/gpu/drm= /rockchip/rockchip_drm_vop2.c index 9603bd8491bc..84c67f5d267f 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c @@ -1284,10 +1284,8 @@ static void vop2_plane_atomic_update(struct drm_plan= e *plane, =20 rb_swap =3D vop2_win_rb_swap(fb->format->format); vop2_win_write(win, VOP2_WIN_RB_SWAP, rb_swap); - if (!vop2_cluster_window(win)) { - uv_swap =3D vop2_win_uv_swap(fb->format->format); - vop2_win_write(win, VOP2_WIN_UV_SWAP, uv_swap); - } + uv_swap =3D vop2_win_uv_swap(fb->format->format); + vop2_win_write(win, VOP2_WIN_UV_SWAP, uv_swap); =20 if (fb->format->is_yuv) { vop2_win_write(win, VOP2_WIN_UV_VIR, DIV_ROUND_UP(fb->pitches[1], 4)); --=20 2.34.1 From nobody Fri Nov 29 11:34:16 2024 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.5]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C11D57DA7F; Fri, 20 Sep 2024 08:23:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820613; cv=none; b=d9orKZvNlWWN769zF8uERijLKrY1D7u+d/1Abm32KTyuYghvMCrgrPV3B/X1yzhd1EfvHyK12/hqwX6is1Cco4C5yBRMbOVjjJmTYtJc/Y27yMg6FWfB9vzUvEqVFFcyQoXifMMO7TMUkwkSFAwkYwf72EjC+sz+2nkVifl7FYs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820613; c=relaxed/simple; bh=CHYjGuFvzYe56c3qHxTRthJqcCNbin4VchMMcRFCPJQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t9UukWftn3cW8W64mXoEVogr/sjOURPL27D07C6khYIsNOY4uuXwmRV4UXlt8PbwWBWJESaQ+L7M3GjNp5ISvtDdKLd9EzF1TzOsEqnrQlQIFTFxNvlWWvLvO18Gxgr80UrH2vswr/H99VRBl3MVB7NQxgWhMM7C01BnZdCF27Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=JBQy5fCd; arc=none smtp.client-ip=117.135.210.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="JBQy5fCd" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version; bh=C7BXA 3vRFQzypGqSRa+Pr7mmHTFBAcqnlbyhQTd3wVU=; b=JBQy5fCd8gJu1BMZYWjBt WS1bMgTY2/jGGmacJ0zY+fPrPXMV6GON5OxK5L3649xLNlgpW5sMaWxWCpyPsHxF jQ03uu82829tVXG7lj8xlKNvDlL6bQsZu0IFiMdCOAIzNGPRNgNqlcsIlJMVj6dt jTdNj0dLTG9hrLj9W8uGQY= Received: from ProDesk.. (unknown [58.22.7.114]) by gzsmtp4 (Coremail) with SMTP id sygvCgDHLl7rMO1mqCVvAw--.49823S2; Fri, 20 Sep 2024 16:23:11 +0800 (CST) From: Andy Yan To: heiko@sntech.de Cc: hjc@rock-chips.com, krzk+dt@kernel.org, robh@kernel.org, conor+dt@kernel.org, s.hauer@pengutronix.de, devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, derek.foreman@collabora.com, minhuadotchen@gmail.com, detlev.casanova@collabora.com, Andy Yan Subject: [PATCH v3 14/15] dt-bindings: display: vop2: Add rk3576 support Date: Fri, 20 Sep 2024 16:23:02 +0800 Message-ID: <20240920082306.6982-1-andyshrk@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240920081626.6433-1-andyshrk@163.com> References: <20240920081626.6433-1-andyshrk@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: sygvCgDHLl7rMO1mqCVvAw--.49823S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7WrWrKFW5tF18ZFWrKF4rXwb_yoW8Xw1rpa 93CFyqqrW8GF17X34kGF1rCrs5XFykAF43GFs7tw1xtwsxKrsYgw4agrn8Zr45GFyxAaya 9F4Sk348A392vrJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UZo7NUUUUU= X-CM-SenderInfo: 5dqg52xkunqiywtou0bp/xtbB0g9gXmWX0hs8xwAAsj Content-Type: text/plain; charset="utf-8" From: Andy Yan Add vop found on rk3576, the main difference between rk3576 and the previous vop is that each VP has its own interrupt line. Signed-off-by: Andy Yan Reviewed-by: Krzysztof Kozlowski Tested-by: Detlev Casanova Tested-by: Michael Riesch # on RK3568 --- Changes in v3: - ordered by soc name - Add description for newly added interrupt Changes in v2: - Add dt bindings .../bindings/display/rockchip/rockchip-vop2.yaml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Documentation/devicetree/bindings/display/rockchip/rockchip-vo= p2.yaml b/Documentation/devicetree/bindings/display/rockchip/rockchip-vop2.= yaml index 2531726af306..a44964b6c36a 100644 --- a/Documentation/devicetree/bindings/display/rockchip/rockchip-vop2.yaml +++ b/Documentation/devicetree/bindings/display/rockchip/rockchip-vop2.yaml @@ -20,6 +20,7 @@ properties: enum: - rockchip,rk3566-vop - rockchip,rk3568-vop + - rockchip,rk3576-vop - rockchip,rk3588-vop =20 reg: @@ -37,10 +38,14 @@ properties: - const: gamma-lut =20 interrupts: - maxItems: 1 - description: - The VOP interrupt is shared by several interrupt sources, such as - frame start (VSYNC), line flag and other status interrupts. + minItems: 1 + items: + - description: + vop system interrupt, such as bus error, and vsync for vop versi= on under + rk3576. + - description: + independent interrupts for each video port, such as vsync and ot= her video + port related error interrupts. =20 # See compatible-specific constraints below. clocks: --=20 2.34.1 From nobody Fri Nov 29 11:34:16 2024 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.3]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8807D54277; Fri, 20 Sep 2024 08:24:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.3 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820648; cv=none; b=XJ7jtjj8MlUPOhDjzpjvb/aUTZ4YM9b1GOp1G1x7bUZlKIRXOeX3QaYUwrlNW39fefWUMbuIDEsG2Sig7K5rZpbUu66geJnjtWPIg3grj7YvIkKySkEhvAR0cD2MAqCVBsMmIAdfvFlY80YG5KMK5zKmmBklzHtrfDZXC33yOW0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726820648; c=relaxed/simple; bh=veYR91uJtOo1W5pU/CIMr2W0gYRR/a1extwGUyyK+hw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=il6jS8Q5OQegqNXFAqYvwLtFoWl5QytXE545uXF+uGumJNzvLN9wArTn3kRAUHNQUTjDPG9z6TlezwecdMA7sF+iCDmZcNKaazQBQL36mig3pVtBpHDGGH2+wqIsfBpIoYhwF5g5AkaRmnHH7juY9xNFbCcWt7vnjhm6Jefu3tg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=YaE9ruap; arc=none smtp.client-ip=220.197.31.3 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="YaE9ruap" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version; bh=hn7ws 5O3mPhzFiph9ja4lQDgsLirWDPuKey76A6XfbM=; b=YaE9ruap5NS7r5lF5u96W pjA122KphbKB637zQVq2hO3Ps3XTf4F/Mu8zWuRK+wwTLidh9EAzfAqF84wR2XXV iCz4Cu5A+0np++ROFWPTCW2m23ee7q9I2Es4oNkTAZkN0Lxi6xpClcQPGWsexLbx e5xtdjrEYYpxn1tNpc9VVg= Received: from ProDesk.. (unknown [58.22.7.114]) by gzsmtp3 (Coremail) with SMTP id sigvCgCHF5n3MO1mlL4ZAA--.3563S2; Fri, 20 Sep 2024 16:23:23 +0800 (CST) From: Andy Yan To: heiko@sntech.de Cc: hjc@rock-chips.com, krzk+dt@kernel.org, robh@kernel.org, conor+dt@kernel.org, s.hauer@pengutronix.de, devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, derek.foreman@collabora.com, minhuadotchen@gmail.com, detlev.casanova@collabora.com, Andy Yan Subject: [PATCH v3 15/15] drm/rockchip: vop2: Add support for rk3576 Date: Fri, 20 Sep 2024 16:23:17 +0800 Message-ID: <20240920082318.7012-1-andyshrk@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240920081626.6433-1-andyshrk@163.com> References: <20240920081626.6433-1-andyshrk@163.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: sigvCgCHF5n3MO1mlL4ZAA--.3563S2 X-Coremail-Antispam: 1Uf129KBjvAXoWDCFW3Jry5CFyDZrW8ArykGrg_yoW7Jr17Ao W3CFnIqryxt34Sk395Gr17XryxWF4vkan7ur1IyFy2k3y3X3y5Cryxt3ZIqF4ayw45CFWr A3sYq3WrZFWfZw1xn29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7v73VFW2AGmfu7bjvjm3 AaLaJ3UbIYCTnIWIevJa73UjIFyTuYvjxU44rWUUUUU X-CM-SenderInfo: 5dqg52xkunqiywtou0bp/1tbiqRxgXmVODBHrRAAAsS Content-Type: text/plain; charset="utf-8" From: Andy Yan VOP2 on rk3576: Three video ports: VP0 Max 4096x2160 VP1 Max 2560x1600 VP2 Max 1920x1080 2 4K Cluster windows with AFBC/RFBC, line RGB and YUV 4 Esmart windows with line RGB/YUV support: Esmart0/1: 4K Esmart2/3: 2k, or worked together as a single 4K plane at shared line buffer mode. Compared to the previous VOP, another difference is that each VP has its own independent vsync interrupt number. Signed-off-by: Andy Yan Tested-by: Detlev Casanova Tested-by: Michael Riesch # on RK3568 --- Changes in v3: - Share the alpha setup function with rk3568 - recoder the code block by soc Changes in v2: - Add platform specific callback drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 144 +++- drivers/gpu/drm/rockchip/rockchip_drm_vop2.h | 87 +++ drivers/gpu/drm/rockchip/rockchip_vop2_reg.c | 780 ++++++++++++++++++- 3 files changed, 956 insertions(+), 55 deletions(-) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c b/drivers/gpu/drm= /rockchip/rockchip_drm_vop2.c index 84c67f5d267f..e25904e4f97b 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c @@ -1187,6 +1187,9 @@ static void vop2_plane_atomic_update(struct drm_plane= *plane, &fb->format->format, afbc_en ? "AFBC" : "", &yrgb_mst); =20 + if (vop2->version >=3D VOP_VERSION_RK3576) + vop2_win_write(win, VOP2_WIN_VP_SEL, vp->id); + if (vop2_cluster_window(win)) vop2_win_write(win, VOP2_WIN_AFBC_HALF_BLOCK_EN, half_block_en); =20 @@ -1251,6 +1254,11 @@ static void vop2_plane_atomic_update(struct drm_plan= e *plane, else vop2_win_write(win, VOP2_WIN_AFBC_BLOCK_SPLIT_EN, 0); =20 + if (vop2->version >=3D VOP_VERSION_RK3576) { + vop2_win_write(win, VOP2_WIN_AFBC_PLD_OFFSET_EN, 1); + vop2_win_write(win, VOP2_WIN_AFBC_PLD_OFFSET, yrgb_mst); + } + transform_offset =3D vop2_afbc_transform_offset(pstate, half_block_en); vop2_win_write(win, VOP2_WIN_AFBC_HDR_PTR, yrgb_mst); vop2_win_write(win, VOP2_WIN_AFBC_PIC_SIZE, act_info); @@ -1919,6 +1927,56 @@ static const struct drm_crtc_funcs vop2_crtc_funcs = =3D { .late_register =3D vop2_crtc_late_register, }; =20 +static irqreturn_t rk3576_vp_isr(int irq, void *data) +{ + struct vop2_video_port *vp =3D data; + struct vop2 *vop2 =3D vp->vop2; + struct drm_crtc *crtc =3D &vp->crtc; + uint32_t irqs; + int ret =3D IRQ_NONE; + + /* + * The irq is shared with the iommu. If the runtime-pm state of the + * vop2-device is disabled the irq has to be targeted at the iommu. + */ + if (!pm_runtime_get_if_in_use(vop2->dev)) + return IRQ_NONE; + + irqs =3D vop2_readl(vop2, RK3568_VP_INT_STATUS(vp->id)); + vop2_writel(vop2, RK3568_VP_INT_CLR(vp->id), irqs << 16 | irqs); + + if (irqs & VP_INT_DSP_HOLD_VALID) { + complete(&vp->dsp_hold_completion); + ret =3D IRQ_HANDLED; + } + + if (irqs & VP_INT_FS_FIELD) { + drm_crtc_handle_vblank(crtc); + spin_lock(&crtc->dev->event_lock); + if (vp->event) { + u32 val =3D vop2_readl(vop2, RK3568_REG_CFG_DONE); + + if (!(val & BIT(vp->id))) { + drm_crtc_send_vblank_event(crtc, vp->event); + vp->event =3D NULL; + drm_crtc_vblank_put(crtc); + } + } + spin_unlock(&crtc->dev->event_lock); + + ret =3D IRQ_HANDLED; + } + + if (irqs & VP_INT_POST_BUF_EMPTY) { + drm_err_ratelimited(vop2->drm, "POST_BUF_EMPTY irq err at vp%d\n", vp->i= d); + ret =3D IRQ_HANDLED; + } + + pm_runtime_put(vop2->dev); + + return ret; +} + static irqreturn_t vop2_isr(int irq, void *data) { struct vop2 *vop2 =3D data; @@ -1934,41 +1992,43 @@ static irqreturn_t vop2_isr(int irq, void *data) if (!pm_runtime_get_if_in_use(vop2->dev)) return IRQ_NONE; =20 - for (i =3D 0; i < vop2_data->nr_vps; i++) { - struct vop2_video_port *vp =3D &vop2->vps[i]; - struct drm_crtc *crtc =3D &vp->crtc; - u32 irqs; + if (vop2->version < VOP_VERSION_RK3576) { + for (i =3D 0; i < vop2_data->nr_vps; i++) { + struct vop2_video_port *vp =3D &vop2->vps[i]; + struct drm_crtc *crtc =3D &vp->crtc; + u32 irqs; =20 - irqs =3D vop2_readl(vop2, RK3568_VP_INT_STATUS(vp->id)); - vop2_writel(vop2, RK3568_VP_INT_CLR(vp->id), irqs << 16 | irqs); + irqs =3D vop2_readl(vop2, RK3568_VP_INT_STATUS(vp->id)); + vop2_writel(vop2, RK3568_VP_INT_CLR(vp->id), irqs << 16 | irqs); =20 - if (irqs & VP_INT_DSP_HOLD_VALID) { - complete(&vp->dsp_hold_completion); - ret =3D IRQ_HANDLED; - } - - if (irqs & VP_INT_FS_FIELD) { - drm_crtc_handle_vblank(crtc); - spin_lock(&crtc->dev->event_lock); - if (vp->event) { - u32 val =3D vop2_readl(vop2, RK3568_REG_CFG_DONE); + if (irqs & VP_INT_DSP_HOLD_VALID) { + complete(&vp->dsp_hold_completion); + ret =3D IRQ_HANDLED; + } =20 - if (!(val & BIT(vp->id))) { - drm_crtc_send_vblank_event(crtc, vp->event); - vp->event =3D NULL; - drm_crtc_vblank_put(crtc); + if (irqs & VP_INT_FS_FIELD) { + drm_crtc_handle_vblank(crtc); + spin_lock(&crtc->dev->event_lock); + if (vp->event) { + u32 val =3D vop2_readl(vop2, RK3568_REG_CFG_DONE); + + if (!(val & BIT(vp->id))) { + drm_crtc_send_vblank_event(crtc, vp->event); + vp->event =3D NULL; + drm_crtc_vblank_put(crtc); + } } - } - spin_unlock(&crtc->dev->event_lock); + spin_unlock(&crtc->dev->event_lock); =20 - ret =3D IRQ_HANDLED; - } + ret =3D IRQ_HANDLED; + } =20 - if (irqs & VP_INT_POST_BUF_EMPTY) { - drm_err_ratelimited(vop2->drm, - "POST_BUF_EMPTY irq err at vp%d\n", - vp->id); - ret =3D IRQ_HANDLED; + if (irqs & VP_INT_POST_BUF_EMPTY) { + drm_err_ratelimited(vop2->drm, + "POST_BUF_EMPTY irq err at vp%d\n", + vp->id); + ret =3D IRQ_HANDLED; + } } } =20 @@ -2455,6 +2515,32 @@ static int vop2_bind(struct device *dev, struct devi= ce *master, void *data) if (ret) return ret; =20 + if (vop2->version >=3D VOP_VERSION_RK3576) { + struct drm_crtc *crtc; + + drm_for_each_crtc(crtc, drm) { + struct vop2_video_port *vp =3D to_vop2_video_port(crtc); + int vp_irq; + const char *irq_name =3D devm_kasprintf(dev, GFP_KERNEL, "vop-vp%d", vp= ->id); + + if (!irq_name) + return -ENOMEM; + + vp_irq =3D platform_get_irq_byname(pdev, irq_name); + if (vp_irq < 0) { + DRM_DEV_ERROR(dev, "cannot find irq for vop2 vp%d\n", vp->id); + return vp_irq; + } + + ret =3D devm_request_irq(dev, vp_irq, rk3576_vp_isr, IRQF_SHARED, irq_n= ame, + vp); + if (ret) { + DRM_DEV_ERROR(dev, "request irq for vop2 vp%d failed\n", vp->id); + return ret; + } + } + } + ret =3D vop2_find_rgb_encoder(vop2); if (ret >=3D 0) { vop2->rgb =3D rockchip_rgb_init(dev, &vop2->vps[ret].crtc, diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.h b/drivers/gpu/drm= /rockchip/rockchip_drm_vop2.h index 064167afebf4..e2485c2285ad 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.h +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.h @@ -44,6 +44,13 @@ enum win_dly_mode { VOP2_DLY_MODE_MAX, }; =20 +enum vop2_dly_module { + VOP2_DLY_WIN, /** Win delay cycle for this VP */ + VOP2_DLY_LAYER_MIX, /** Layer Mix delay cycle for this VP */ + VOP2_DLY_HDR_MIX, /** HDR delay cycle for this VP */ + VOP2_DLY_MAX, +}; + enum vop2_scale_up_mode { VOP2_SCALE_UP_NRST_NBOR, VOP2_SCALE_UP_BIL, @@ -137,16 +144,22 @@ enum vop2_win_regs { VOP2_WIN_AFBC_UV_SWAP, VOP2_WIN_AFBC_AUTO_GATING_EN, VOP2_WIN_AFBC_BLOCK_SPLIT_EN, + VOP2_WIN_AFBC_PLD_OFFSET_EN, VOP2_WIN_AFBC_PIC_VIR_WIDTH, VOP2_WIN_AFBC_TILE_NUM, VOP2_WIN_AFBC_PIC_OFFSET, VOP2_WIN_AFBC_PIC_SIZE, VOP2_WIN_AFBC_DSP_OFFSET, + VOP2_WIN_AFBC_PLD_OFFSET, VOP2_WIN_AFBC_TRANSFORM_OFFSET, VOP2_WIN_AFBC_HDR_PTR, VOP2_WIN_AFBC_HALF_BLOCK_EN, VOP2_WIN_AFBC_ROTATE_270, VOP2_WIN_AFBC_ROTATE_90, + + VOP2_WIN_VP_SEL, + VOP2_WIN_DLY_NUM, + VOP2_WIN_MAX_REG, }; =20 @@ -208,6 +221,10 @@ struct vop2_video_port_data { struct vop_rect max_output; const u8 pre_scan_max_dly[4]; unsigned int offset; + /** + * @pixel_rate: pixel per cycle + */ + u8 pixel_rate; }; =20 struct vop2_video_port { @@ -365,10 +382,13 @@ enum dst_factor_mode { #define RK3568_REG_CFG_DONE 0x000 #define RK3568_VERSION_INFO 0x004 #define RK3568_SYS_AUTO_GATING_CTRL 0x008 +#define RK3576_SYS_MMU_CTRL_IMD 0x020 #define RK3568_SYS_AXI_LUT_CTRL 0x024 #define RK3568_DSP_IF_EN 0x028 +#define RK3576_SYS_PORT_CTRL_IMD 0x028 #define RK3568_DSP_IF_CTRL 0x02c #define RK3568_DSP_IF_POL 0x030 +#define RK3576_SYS_CLUSTER_PD_CTRL_IMD 0x030 #define RK3588_SYS_PD_CTRL 0x034 #define RK3568_WB_CTRL 0x40 #define RK3568_WB_XSCAL_FACTOR 0x44 @@ -388,6 +408,55 @@ enum dst_factor_mode { #define RK3568_VP_INT_CLR(vp) (0xA4 + (vp) * 0x10) #define RK3568_VP_INT_STATUS(vp) (0xA8 + (vp) * 0x10) #define RK3568_VP_INT_RAW_STATUS(vp) (0xAC + (vp) * 0x10) +#define RK3576_WB_CTRL 0x100 +#define RK3576_WB_XSCAL_FACTOR 0x104 +#define RK3576_WB_YRGB_MST 0x108 +#define RK3576_WB_CBR_MST 0x10C +#define RK3576_WB_VIR_STRIDE 0x110 +#define RK3576_WB_TIMEOUT_CTRL 0x114 +#define RK3576_MIPI0_IF_CTRL 0x180 +#define RK3576_HDMI0_IF_CTRL 0x184 +#define RK3576_EDP0_IF_CTRL 0x188 +#define RK3576_DP0_IF_CTRL 0x18C +#define RK3576_RGB_IF_CTRL 0x194 +#define RK3576_DP1_IF_CTRL 0x1A4 +#define RK3576_DP2_IF_CTRL 0x1B0 + +/* Extra OVL register definition */ +#define RK3576_SYS_EXTRA_ALPHA_CTRL 0x500 +#define RK3576_CLUSTER0_MIX_SRC_COLOR_CTRL 0x530 +#define RK3576_CLUSTER0_MIX_DST_COLOR_CTRL 0x534 +#define RK3576_CLUSTER0_MIX_SRC_ALPHA_CTRL 0x538 +#define RK3576_CLUSTER0_MIX_DST_ALPHA_CTRL 0x53c +#define RK3576_CLUSTER1_MIX_SRC_COLOR_CTRL 0x540 +#define RK3576_CLUSTER1_MIX_DST_COLOR_CTRL 0x544 +#define RK3576_CLUSTER1_MIX_SRC_ALPHA_CTRL 0x548 +#define RK3576_CLUSTER1_MIX_DST_ALPHA_CTRL 0x54c + +/* OVL registers for Video Port definition */ +#define RK3576_OVL_CTRL(vp) (0x600 + (vp) * 0x100) +#define RK3576_OVL_LAYER_SEL(vp) (0x604 + (vp) * 0x100) +#define RK3576_OVL_MIX0_SRC_COLOR_CTRL(vp) (0x620 + (vp) * 0x100) +#define RK3576_OVL_MIX0_DST_COLOR_CTRL(vp) (0x624 + (vp) * 0x100) +#define RK3576_OVL_MIX0_SRC_ALPHA_CTRL(vp) (0x628 + (vp) * 0x100) +#define RK3576_OVL_MIX0_DST_ALPHA_CTRL(vp) (0x62C + (vp) * 0x100) +#define RK3576_OVL_MIX1_SRC_COLOR_CTRL(vp) (0x630 + (vp) * 0x100) +#define RK3576_OVL_MIX1_DST_COLOR_CTRL(vp) (0x634 + (vp) * 0x100) +#define RK3576_OVL_MIX1_SRC_ALPHA_CTRL(vp) (0x638 + (vp) * 0x100) +#define RK3576_OVL_MIX1_DST_ALPHA_CTRL(vp) (0x63C + (vp) * 0x100) +#define RK3576_OVL_MIX2_SRC_COLOR_CTRL(vp) (0x640 + (vp) * 0x100) +#define RK3576_OVL_MIX2_DST_COLOR_CTRL(vp) (0x644 + (vp) * 0x100) +#define RK3576_OVL_MIX2_SRC_ALPHA_CTRL(vp) (0x648 + (vp) * 0x100) +#define RK3576_OVL_MIX2_DST_ALPHA_CTRL(vp) (0x64C + (vp) * 0x100) +#define RK3576_EXTRA_OVL_SRC_COLOR_CTRL(vp) (0x650 + (vp) * 0x100) +#define RK3576_EXTRA_OVL_DST_COLOR_CTRL(vp) (0x654 + (vp) * 0x100) +#define RK3576_EXTRA_OVL_SRC_ALPHA_CTRL(vp) (0x658 + (vp) * 0x100) +#define RK3576_EXTRA_OVL_DST_ALPHA_CTRL(vp) (0x65C + (vp) * 0x100) +#define RK3576_OVL_HDR_SRC_COLOR_CTRL(vp) (0x660 + (vp) * 0x100) +#define RK3576_OVL_HDR_DST_COLOR_CTRL(vp) (0x664 + (vp) * 0x100) +#define RK3576_OVL_HDR_SRC_ALPHA_CTRL(vp) (0x668 + (vp) * 0x100) +#define RK3576_OVL_HDR_DST_ALPHA_CTRL(vp) (0x66C + (vp) * 0x100) +#define RK3576_OVL_BG_MIX_CTRL(vp) (0x670 + (vp) * 0x100) =20 /* Video Port registers definition */ #define RK3568_VP0_CTRL_BASE 0x0C00 @@ -469,7 +538,11 @@ enum dst_factor_mode { #define RK3568_CLUSTER_WIN_AFBCD_DSP_OFFSET 0x68 #define RK3568_CLUSTER_WIN_AFBCD_CTRL 0x6C =20 +#define RK3576_CLUSTER_WIN_AFBCD_PLD_PTR_OFFSET 0x78 + #define RK3568_CLUSTER_CTRL 0x100 +#define RK3576_CLUSTER_PORT_SEL_IMD 0x1F4 +#define RK3576_CLUSTER_DLY_NUM 0x1F8 =20 /* (E)smart register definition, offset relative to window base */ #define RK3568_SMART_CTRL0 0x00 @@ -519,6 +592,9 @@ enum dst_factor_mode { #define RK3568_SMART_REGION3_SCL_FACTOR_CBR 0xC8 #define RK3568_SMART_REGION3_SCL_OFFSET 0xCC #define RK3568_SMART_COLOR_KEY_CTRL 0xD0 +#define RK3576_SMART_ALPHA_MAP 0xD8 +#define RK3576_SMART_PORT_SEL_IMD 0xF4 +#define RK3576_SMART_DLY_NUM 0xF8 =20 /* HDR register definition */ #define RK3568_HDR_LUT_CTRL 0x2000 @@ -662,6 +738,17 @@ enum dst_factor_mode { =20 #define POLFLAG_DCLK_INV BIT(3) =20 +#define RK3576_OVL_CTRL__YUV_MODE BIT(0) +#define RK3576_OVL_BG_MIX_CTRL__BG_DLY GENMASK(31, 24) + +#define RK3576_DSP_IF_CFG_DONE_IMD BIT(31) +#define RK3576_DSP_IF_DCLK_SEL_OUT BIT(21) +#define RK3576_DSP_IF_PCLK_DIV BIT(20) +#define RK3576_DSP_IF_PIN_POL GENMASK(5, 4) +#define RK3576_DSP_IF_MUX GENMASK(3, 2) +#define RK3576_DSP_IF_CLK_OUT_EN BIT(1) +#define RK3576_DSP_IF_EN BIT(0) + enum vop2_layer_phy_id { ROCKCHIP_VOP2_CLUSTER0 =3D 0, ROCKCHIP_VOP2_CLUSTER1, diff --git a/drivers/gpu/drm/rockchip/rockchip_vop2_reg.c b/drivers/gpu/drm= /rockchip/rockchip_vop2_reg.c index 95e31ee84f4f..91c2443567d1 100644 --- a/drivers/gpu/drm/rockchip/rockchip_vop2_reg.c +++ b/drivers/gpu/drm/rockchip/rockchip_vop2_reg.c @@ -70,6 +70,37 @@ static const uint32_t formats_cluster[] =3D { DRM_FORMAT_Y210, /* yuv422_10bit non-Linear mode only */ }; =20 +/* + * The cluster windows on rk3576 support: + * RGB: linear mode and afbc + * YUV: linear mode and rfbc + * rfbc is a rockchip defined non-linear mode, produced by + * Video decoder + */ +static const uint32_t formats_rk3576_cluster[] =3D { + DRM_FORMAT_XRGB2101010, + DRM_FORMAT_XBGR2101010, + DRM_FORMAT_ARGB2101010, + DRM_FORMAT_ABGR2101010, + DRM_FORMAT_XRGB8888, + DRM_FORMAT_ARGB8888, + DRM_FORMAT_XBGR8888, + DRM_FORMAT_ABGR8888, + DRM_FORMAT_RGB888, + DRM_FORMAT_BGR888, + DRM_FORMAT_RGB565, + DRM_FORMAT_BGR565, + DRM_FORMAT_NV12, /* yuv420_8bit linear mode, 2 plane */ + DRM_FORMAT_NV21, /* yvu420_8bit linear mode, 2 plane */ + DRM_FORMAT_NV16, /* yuv422_8bit linear mode, 2 plane */ + DRM_FORMAT_NV61, /* yvu422_8bit linear mode, 2 plane */ + DRM_FORMAT_NV24, /* yuv444_8bit linear mode, 2 plane */ + DRM_FORMAT_NV42, /* yvu444_8bit linear mode, 2 plane */ + DRM_FORMAT_NV15, /* yuv420_10bit linear mode, 2 plane, no padding */ + DRM_FORMAT_NV20, /* yuv422_10bit linear mode, 2 plane, no padding */ + DRM_FORMAT_NV30, /* yuv444_10bit linear mode, 2 plane, no padding */ +}; + static const uint32_t formats_esmart[] =3D { DRM_FORMAT_XRGB8888, DRM_FORMAT_ARGB8888, @@ -116,6 +147,41 @@ static const uint32_t formats_rk356x_esmart[] =3D { DRM_FORMAT_VYUY, /* yuv422_8bit[VYUY] linear mode */ }; =20 +/* + * Add XRGB2101010/ARGB2101010ARGB1555/XRGB1555 + */ +static const uint32_t formats_rk3576_esmart[] =3D { + DRM_FORMAT_XRGB2101010, + DRM_FORMAT_XBGR2101010, + DRM_FORMAT_ARGB2101010, + DRM_FORMAT_ABGR2101010, + DRM_FORMAT_XRGB8888, + DRM_FORMAT_ARGB8888, + DRM_FORMAT_XBGR8888, + DRM_FORMAT_ABGR8888, + DRM_FORMAT_RGB888, + DRM_FORMAT_BGR888, + DRM_FORMAT_RGB565, + DRM_FORMAT_BGR565, + DRM_FORMAT_ARGB1555, + DRM_FORMAT_ABGR1555, + DRM_FORMAT_XRGB1555, + DRM_FORMAT_XBGR1555, + DRM_FORMAT_NV12, /* yuv420_8bit linear mode, 2 plane */ + DRM_FORMAT_NV21, /* yvu420_8bit linear mode, 2 plane */ + DRM_FORMAT_NV16, /* yuv422_8bit linear mode, 2 plane */ + DRM_FORMAT_NV61, /* yvu422_8bit linear mode, 2 plane */ + DRM_FORMAT_NV20, /* yuv422_10bit linear mode, 2 plane, no padding */ + DRM_FORMAT_NV24, /* yuv444_8bit linear mode, 2 plane */ + DRM_FORMAT_NV42, /* yvu444_8bit linear mode, 2 plane */ + DRM_FORMAT_NV30, /* yuv444_10bit linear mode, 2 plane, no padding */ + DRM_FORMAT_NV15, /* yuv420_10bit linear mode, 2 plane, no padding */ + DRM_FORMAT_YVYU, /* yuv422_8bit[YVYU] linear mode */ + DRM_FORMAT_VYUY, /* yuv422_8bit[VYUY] linear mode */ + DRM_FORMAT_YUYV, /* yuv422_8bit[YUYV] linear mode */ + DRM_FORMAT_UYVY, /* yuv422_8bit[UYVY] linear mode */ +}; + static const uint32_t formats_smart[] =3D { DRM_FORMAT_XRGB8888, DRM_FORMAT_ARGB8888, @@ -169,6 +235,48 @@ static const uint64_t format_modifiers_afbc[] =3D { DRM_FORMAT_MOD_INVALID, }; =20 +/* used from rk3576, afbc 32*8 half mode */ +static const uint64_t format_modifiers_rk3576_afbc[] =3D { + DRM_FORMAT_MOD_ARM_AFBC(AFBC_FORMAT_MOD_BLOCK_SIZE_32x8 | + AFBC_FORMAT_MOD_SPLIT), + + DRM_FORMAT_MOD_ARM_AFBC(AFBC_FORMAT_MOD_BLOCK_SIZE_32x8 | + AFBC_FORMAT_MOD_SPARSE | + AFBC_FORMAT_MOD_SPLIT), + + DRM_FORMAT_MOD_ARM_AFBC(AFBC_FORMAT_MOD_BLOCK_SIZE_32x8 | + AFBC_FORMAT_MOD_YTR | + AFBC_FORMAT_MOD_SPLIT), + + DRM_FORMAT_MOD_ARM_AFBC(AFBC_FORMAT_MOD_BLOCK_SIZE_32x8 | + AFBC_FORMAT_MOD_CBR | + AFBC_FORMAT_MOD_SPLIT), + + DRM_FORMAT_MOD_ARM_AFBC(AFBC_FORMAT_MOD_BLOCK_SIZE_32x8 | + AFBC_FORMAT_MOD_CBR | + AFBC_FORMAT_MOD_SPARSE | + AFBC_FORMAT_MOD_SPLIT), + + DRM_FORMAT_MOD_ARM_AFBC(AFBC_FORMAT_MOD_BLOCK_SIZE_32x8 | + AFBC_FORMAT_MOD_YTR | + AFBC_FORMAT_MOD_CBR | + AFBC_FORMAT_MOD_SPLIT), + + DRM_FORMAT_MOD_ARM_AFBC(AFBC_FORMAT_MOD_BLOCK_SIZE_32x8 | + AFBC_FORMAT_MOD_YTR | + AFBC_FORMAT_MOD_CBR | + AFBC_FORMAT_MOD_SPARSE | + AFBC_FORMAT_MOD_SPLIT), + + /* SPLIT mandates SPARSE, RGB modes mandates YTR */ + DRM_FORMAT_MOD_ARM_AFBC(AFBC_FORMAT_MOD_BLOCK_SIZE_32x8 | + AFBC_FORMAT_MOD_YTR | + AFBC_FORMAT_MOD_SPARSE | + AFBC_FORMAT_MOD_SPLIT), + DRM_FORMAT_MOD_LINEAR, + DRM_FORMAT_MOD_INVALID, +}; + static const struct reg_field rk3568_vop_cluster_regs[VOP2_WIN_MAX_REG] = =3D { [VOP2_WIN_ENABLE] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL0, 0, 0), [VOP2_WIN_FORMAT] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL0, 1, 5), @@ -293,6 +401,136 @@ static const struct reg_field rk3568_vop_smart_regs[V= OP2_WIN_MAX_REG] =3D { [VOP2_WIN_AFBC_ROTATE_90] =3D { .reg =3D 0xffffffff }, }; =20 +static const struct reg_field rk3576_vop_cluster_regs[VOP2_WIN_MAX_REG] = =3D { + [VOP2_WIN_ENABLE] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL0, 0, 0), + [VOP2_WIN_FORMAT] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL0, 1, 5), + [VOP2_WIN_RB_SWAP] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL0, 14, 14), + [VOP2_WIN_UV_SWAP] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL0, 17, 17), + [VOP2_WIN_DITHER_UP] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL0, 18, 18), + [VOP2_WIN_ACT_INFO] =3D REG_FIELD(RK3568_CLUSTER_WIN_ACT_INFO, 0, 31), + [VOP2_WIN_DSP_INFO] =3D REG_FIELD(RK3568_CLUSTER_WIN_DSP_INFO, 0, 31), + [VOP2_WIN_DSP_ST] =3D REG_FIELD(RK3568_CLUSTER_WIN_DSP_ST, 0, 31), + [VOP2_WIN_YRGB_MST] =3D REG_FIELD(RK3568_CLUSTER_WIN_YRGB_MST, 0, 31), + [VOP2_WIN_UV_MST] =3D REG_FIELD(RK3568_CLUSTER_WIN_CBR_MST, 0, 31), + [VOP2_WIN_YUV_CLIP] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL0, 19, 19), + [VOP2_WIN_YRGB_VIR] =3D REG_FIELD(RK3568_CLUSTER_WIN_VIR, 0, 15), + [VOP2_WIN_UV_VIR] =3D REG_FIELD(RK3568_CLUSTER_WIN_VIR, 16, 31), + [VOP2_WIN_Y2R_EN] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL0, 8, 8), + [VOP2_WIN_R2Y_EN] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL0, 9, 9), + [VOP2_WIN_CSC_MODE] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL0, 10, 11), + [VOP2_WIN_VP_SEL] =3D REG_FIELD(RK3576_CLUSTER_PORT_SEL_IMD, 0, 1), + [VOP2_WIN_DLY_NUM] =3D REG_FIELD(RK3576_CLUSTER_DLY_NUM, 0, 7), + + /* Scale */ + [VOP2_WIN_SCALE_YRGB_X] =3D REG_FIELD(RK3568_CLUSTER_WIN_SCL_FACTOR_YRGB,= 0, 15), + [VOP2_WIN_SCALE_YRGB_Y] =3D REG_FIELD(RK3568_CLUSTER_WIN_SCL_FACTOR_YRGB,= 16, 31), + [VOP2_WIN_BIC_COE_SEL] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL1, 2, 3), + [VOP2_WIN_YRGB_VER_SCL_MODE] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL1, 14, = 15), + [VOP2_WIN_YRGB_HOR_SCL_MODE] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL1, 22, = 23), + [VOP2_WIN_VSD_YRGB_GT2] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL1, 28, 28), + [VOP2_WIN_VSD_YRGB_GT4] =3D REG_FIELD(RK3568_CLUSTER_WIN_CTRL1, 29, 29), + + /* cluster regs */ + [VOP2_WIN_AFBC_ENABLE] =3D REG_FIELD(RK3568_CLUSTER_CTRL, 1, 1), + [VOP2_WIN_CLUSTER_ENABLE] =3D REG_FIELD(RK3568_CLUSTER_CTRL, 0, 0), + [VOP2_WIN_CLUSTER_LB_MODE] =3D REG_FIELD(RK3568_CLUSTER_CTRL, 4, 7), + + /* afbc regs */ + [VOP2_WIN_AFBC_FORMAT] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_CTRL, 2, 6), + [VOP2_WIN_AFBC_RB_SWAP] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_CTRL, 9, 9= ), + [VOP2_WIN_AFBC_UV_SWAP] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_CTRL, 10, = 10), + [VOP2_WIN_AFBC_AUTO_GATING_EN] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_OUT= PUT_CTRL, 4, 4), + [VOP2_WIN_AFBC_HALF_BLOCK_EN] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_CTRL= , 7, 7), + [VOP2_WIN_AFBC_BLOCK_SPLIT_EN] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_CTR= L, 8, 8), + [VOP2_WIN_AFBC_PLD_OFFSET_EN] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_CTRL= , 16, 16), + [VOP2_WIN_AFBC_HDR_PTR] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_HDR_PTR, 0= , 31), + [VOP2_WIN_AFBC_PIC_SIZE] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_PIC_SIZE,= 0, 31), + [VOP2_WIN_AFBC_PIC_VIR_WIDTH] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_VIR_= WIDTH, 0, 15), + [VOP2_WIN_AFBC_TILE_NUM] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_VIR_WIDTH= , 16, 31), + [VOP2_WIN_AFBC_PIC_OFFSET] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_PIC_OFF= SET, 0, 31), + [VOP2_WIN_AFBC_DSP_OFFSET] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_DSP_OFF= SET, 0, 31), + [VOP2_WIN_AFBC_PLD_OFFSET] =3D REG_FIELD(RK3576_CLUSTER_WIN_AFBCD_PLD_PTR= _OFFSET, 0, 31), + [VOP2_WIN_AFBC_TRANSFORM_OFFSET] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_T= RANSFORM_OFFSET, 0, 31), + [VOP2_WIN_AFBC_ROTATE_90] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_ROTATE_M= ODE, 0, 0), + [VOP2_WIN_AFBC_ROTATE_270] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_ROTATE_= MODE, 1, 1), + [VOP2_WIN_XMIRROR] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_ROTATE_MODE, 2,= 2), + [VOP2_WIN_YMIRROR] =3D REG_FIELD(RK3568_CLUSTER_WIN_AFBCD_ROTATE_MODE, 3,= 3), + [VOP2_WIN_COLOR_KEY] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_COLOR_KEY_EN] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_SCALE_CBCR_X] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_SCALE_CBCR_Y] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_YRGB_HSCL_FILTER_MODE] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_YRGB_VSCL_FILTER_MODE] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_CBCR_VER_SCL_MODE] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_CBCR_HSCL_FILTER_MODE] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_CBCR_HOR_SCL_MODE] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_CBCR_VSCL_FILTER_MODE] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_VSD_CBCR_GT2] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_VSD_CBCR_GT4] =3D { .reg =3D 0xffffffff }, +}; + +static const struct reg_field rk3576_vop_smart_regs[VOP2_WIN_MAX_REG] =3D { + [VOP2_WIN_ENABLE] =3D REG_FIELD(RK3568_SMART_REGION0_CTRL, 0, 0), + [VOP2_WIN_FORMAT] =3D REG_FIELD(RK3568_SMART_REGION0_CTRL, 1, 5), + [VOP2_WIN_DITHER_UP] =3D REG_FIELD(RK3568_SMART_REGION0_CTRL, 12, 12), + [VOP2_WIN_RB_SWAP] =3D REG_FIELD(RK3568_SMART_REGION0_CTRL, 14, 14), + [VOP2_WIN_UV_SWAP] =3D REG_FIELD(RK3568_SMART_REGION0_CTRL, 16, 16), + [VOP2_WIN_ACT_INFO] =3D REG_FIELD(RK3568_SMART_REGION0_ACT_INFO, 0, 31), + [VOP2_WIN_DSP_INFO] =3D REG_FIELD(RK3568_SMART_REGION0_DSP_INFO, 0, 31), + [VOP2_WIN_DSP_ST] =3D REG_FIELD(RK3568_SMART_REGION0_DSP_ST, 0, 28), + [VOP2_WIN_YRGB_MST] =3D REG_FIELD(RK3568_SMART_REGION0_YRGB_MST, 0, 31), + [VOP2_WIN_UV_MST] =3D REG_FIELD(RK3568_SMART_REGION0_CBR_MST, 0, 31), + [VOP2_WIN_YUV_CLIP] =3D REG_FIELD(RK3568_SMART_REGION0_CTRL, 17, 17), + [VOP2_WIN_YRGB_VIR] =3D REG_FIELD(RK3568_SMART_REGION0_VIR, 0, 15), + [VOP2_WIN_UV_VIR] =3D REG_FIELD(RK3568_SMART_REGION0_VIR, 16, 31), + [VOP2_WIN_Y2R_EN] =3D REG_FIELD(RK3568_SMART_CTRL0, 0, 0), + [VOP2_WIN_R2Y_EN] =3D REG_FIELD(RK3568_SMART_CTRL0, 1, 1), + [VOP2_WIN_CSC_MODE] =3D REG_FIELD(RK3568_SMART_CTRL0, 2, 3), + [VOP2_WIN_YMIRROR] =3D REG_FIELD(RK3568_SMART_CTRL1, 31, 31), + [VOP2_WIN_COLOR_KEY] =3D REG_FIELD(RK3568_SMART_COLOR_KEY_CTRL, 0, 29), + [VOP2_WIN_COLOR_KEY_EN] =3D REG_FIELD(RK3568_SMART_COLOR_KEY_CTRL, 31, 31= ), + [VOP2_WIN_VP_SEL] =3D REG_FIELD(RK3576_SMART_PORT_SEL_IMD, 0, 1), + [VOP2_WIN_DLY_NUM] =3D REG_FIELD(RK3576_SMART_DLY_NUM, 0, 7), + + /* Scale */ + [VOP2_WIN_SCALE_YRGB_X] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_FACTOR_YRG= B, 0, 15), + [VOP2_WIN_SCALE_YRGB_Y] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_FACTOR_YRG= B, 16, 31), + [VOP2_WIN_SCALE_CBCR_X] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_FACTOR_CBR= , 0, 15), + [VOP2_WIN_SCALE_CBCR_Y] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_FACTOR_CBR= , 16, 31), + [VOP2_WIN_YRGB_HOR_SCL_MODE] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_CTRL,= 0, 1), + [VOP2_WIN_YRGB_HSCL_FILTER_MODE] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_C= TRL, 2, 3), + [VOP2_WIN_YRGB_VER_SCL_MODE] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_CTRL,= 4, 5), + [VOP2_WIN_YRGB_VSCL_FILTER_MODE] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_C= TRL, 6, 7), + [VOP2_WIN_CBCR_HOR_SCL_MODE] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_CTRL,= 8, 9), + [VOP2_WIN_CBCR_HSCL_FILTER_MODE] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_C= TRL, 10, 11), + [VOP2_WIN_CBCR_VER_SCL_MODE] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_CTRL,= 12, 13), + [VOP2_WIN_CBCR_VSCL_FILTER_MODE] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_C= TRL, 14, 15), + [VOP2_WIN_BIC_COE_SEL] =3D REG_FIELD(RK3568_SMART_REGION0_SCL_CTRL, 16, 1= 7), + [VOP2_WIN_VSD_YRGB_GT2] =3D REG_FIELD(RK3568_SMART_REGION0_CTRL, 8, 8), + [VOP2_WIN_VSD_YRGB_GT4] =3D REG_FIELD(RK3568_SMART_REGION0_CTRL, 9, 9), + [VOP2_WIN_VSD_CBCR_GT2] =3D REG_FIELD(RK3568_SMART_REGION0_CTRL, 10, 10), + [VOP2_WIN_VSD_CBCR_GT4] =3D REG_FIELD(RK3568_SMART_REGION0_CTRL, 11, 11), + [VOP2_WIN_XMIRROR] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_CLUSTER_ENABLE] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_AFBC_ENABLE] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_CLUSTER_LB_MODE] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_AFBC_FORMAT] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_AFBC_RB_SWAP] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_AFBC_UV_SWAP] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_AFBC_AUTO_GATING_EN] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_AFBC_BLOCK_SPLIT_EN] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_AFBC_PIC_VIR_WIDTH] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_AFBC_TILE_NUM] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_AFBC_PIC_OFFSET] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_AFBC_PIC_SIZE] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_AFBC_DSP_OFFSET] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_AFBC_TRANSFORM_OFFSET] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_AFBC_HDR_PTR] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_AFBC_HALF_BLOCK_EN] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_AFBC_ROTATE_270] =3D { .reg =3D 0xffffffff }, + [VOP2_WIN_AFBC_ROTATE_90] =3D { .reg =3D 0xffffffff }, +}; + static const struct vop2_video_port_data rk3568_vop_video_ports[] =3D { { .id =3D 0, @@ -509,6 +747,272 @@ static const struct vop2_regs_dump rk3568_regs_dump[]= =3D { }, }; =20 +static const struct vop2_video_port_data rk3576_vop_video_ports[] =3D { + { + .id =3D 0, + .feature =3D VOP2_VP_FEATURE_OUTPUT_10BIT, + .gamma_lut_len =3D 1024, + .cubic_lut_len =3D 9 * 9 * 9, /* 9x9x9 */ + .max_output =3D { 4096, 2304 }, + /* win layer_mix hdr */ + .pre_scan_max_dly =3D { 10, 8, 2, 0 }, + .offset =3D 0xc00, + .pixel_rate =3D 2, + }, { + .id =3D 1, + .feature =3D VOP2_VP_FEATURE_OUTPUT_10BIT, + .gamma_lut_len =3D 1024, + .cubic_lut_len =3D 729, /* 9x9x9 */ + .max_output =3D { 2560, 1600 }, + /* win layer_mix hdr */ + .pre_scan_max_dly =3D { 10, 6, 0, 0 }, + .offset =3D 0xd00, + .pixel_rate =3D 1, + }, { + .id =3D 2, + .gamma_lut_len =3D 1024, + .max_output =3D { 1920, 1080 }, + /* win layer_mix hdr */ + .pre_scan_max_dly =3D { 10, 6, 0, 0 }, + .offset =3D 0xe00, + .pixel_rate =3D 1, + }, +}; + +/* + * rk3576 vop with 2 cluster, 4 esmart win. + * Every cluster can work as 4K win or split into two win. + * All win in cluster support AFBCD. + * + * Every esmart win support 4 Multi-region. + * + * VP0 can use Cluster0/1 and Esmart0/2 + * VP1 can use Cluster0/1 and Esmart1/3 + * VP2 can use Esmart0/1/2/3 + * + * Scale filter mode: + * + * * Cluster: + * * Support prescale down: + * * H/V: gt2/avg2 or gt4/avg4 + * * After prescale down: + * * nearest-neighbor/bilinear/multi-phase filter for scale up + * * nearest-neighbor/bilinear/multi-phase filter for scale down + * + * * Esmart: + * * Support prescale down: + * * H: gt2/avg2 or gt4/avg4 + * * V: gt2 or gt4 + * * After prescale down: + * * nearest-neighbor/bilinear/bicubic for scale up + * * nearest-neighbor/bilinear for scale down + * + * AXI config:: + * + * * Cluster0 win0: 0xa, 0xb [AXI0] + * * Cluster0 win1: 0xc, 0xd [AXI0] + * * Cluster1 win0: 0x6, 0x7 [AXI0] + * * Cluster1 win1: 0x8, 0x9 [AXI0] + * * Esmart0: 0x10, 0x11 [AXI0] + * * Esmart1: 0x12, 0x13 [AXI0] + * * Esmart2: 0xa, 0xb [AXI1] + * * Esmart3: 0xc, 0xd [AXI1] + * * Lut dma rid: 0x1, 0x2, 0x3 [AXI0] + * * DCI dma rid: 0x4 [AXI0] + * * Metadata rid: 0x5 [AXI0] + * + * * Limit: + * * (1) 0x0 and 0xf can't be used; + * * (2) cluster and lut/dci/metadata rid must smaller than 0xf, + * * if Cluster rid is bigger than 0xf, VOP will dead at the + * * system bandwidth very terrible scene. + */ +static const struct vop2_win_data rk3576_vop_win_data[] =3D { + { + .name =3D "Cluster0-win0", + .phys_id =3D ROCKCHIP_VOP2_CLUSTER0, + .base =3D 0x1000, + .possible_vp_mask =3D BIT(0) | BIT(1), + .formats =3D formats_rk3576_cluster, + .nformats =3D ARRAY_SIZE(formats_rk3576_cluster), + .format_modifiers =3D format_modifiers_rk3576_afbc, + .layer_sel_id =3D { 0, 0, 0xf, 0xf }, + .supported_rotations =3D DRM_MODE_REFLECT_X | DRM_MODE_REFLECT_Y, + .max_upscale_factor =3D 4, + .max_downscale_factor =3D 4, + .type =3D DRM_PLANE_TYPE_PRIMARY, + .feature =3D WIN_FEATURE_AFBDC | WIN_FEATURE_CLUSTER, + }, { + .name =3D "Cluster1-win0", + .phys_id =3D ROCKCHIP_VOP2_CLUSTER1, + .base =3D 0x1200, + .possible_vp_mask =3D BIT(0) | BIT(1), + .formats =3D formats_rk3576_cluster, + .nformats =3D ARRAY_SIZE(formats_rk3576_cluster), + .format_modifiers =3D format_modifiers_rk3576_afbc, + .layer_sel_id =3D { 1, 1, 0xf, 0xf }, + .supported_rotations =3D DRM_MODE_REFLECT_X | DRM_MODE_REFLECT_Y, + .type =3D DRM_PLANE_TYPE_PRIMARY, + .max_upscale_factor =3D 4, + .max_downscale_factor =3D 4, + .feature =3D WIN_FEATURE_AFBDC | WIN_FEATURE_CLUSTER, + }, { + .name =3D "Esmart0-win0", + .phys_id =3D ROCKCHIP_VOP2_ESMART0, + .base =3D 0x1800, + .possible_vp_mask =3D BIT(0) | BIT(2), + .formats =3D formats_rk3576_esmart, + .nformats =3D ARRAY_SIZE(formats_rk3576_esmart), + .format_modifiers =3D format_modifiers, + .layer_sel_id =3D { 2, 0xf, 0, 0xf }, + .supported_rotations =3D DRM_MODE_REFLECT_Y, + .type =3D DRM_PLANE_TYPE_OVERLAY, + .max_upscale_factor =3D 8, + .max_downscale_factor =3D 8, + }, { + .name =3D "Esmart1-win0", + .phys_id =3D ROCKCHIP_VOP2_ESMART1, + .base =3D 0x1a00, + .possible_vp_mask =3D BIT(1) | BIT(2), + .formats =3D formats_rk3576_esmart, + .nformats =3D ARRAY_SIZE(formats_rk3576_esmart), + .format_modifiers =3D format_modifiers, + .layer_sel_id =3D { 0xf, 2, 1, 0xf }, + .supported_rotations =3D DRM_MODE_REFLECT_Y, + .type =3D DRM_PLANE_TYPE_OVERLAY, + .max_upscale_factor =3D 8, + .max_downscale_factor =3D 8, + }, { + .name =3D "Esmart2-win0", + .phys_id =3D ROCKCHIP_VOP2_ESMART2, + .base =3D 0x1c00, + .possible_vp_mask =3D BIT(0) | BIT(2), + .formats =3D formats_rk3576_esmart, + .nformats =3D ARRAY_SIZE(formats_rk3576_esmart), + .format_modifiers =3D format_modifiers, + .layer_sel_id =3D { 3, 0xf, 2, 0xf }, + .supported_rotations =3D DRM_MODE_REFLECT_Y, + .type =3D DRM_PLANE_TYPE_OVERLAY, + .max_upscale_factor =3D 8, + .max_downscale_factor =3D 8, + }, { + .name =3D "Esmart3-win0", + .phys_id =3D ROCKCHIP_VOP2_ESMART3, + .base =3D 0x1e00, + .possible_vp_mask =3D BIT(1) | BIT(2), + .formats =3D formats_rk3576_esmart, + .nformats =3D ARRAY_SIZE(formats_rk3576_esmart), + .format_modifiers =3D format_modifiers, + .layer_sel_id =3D { 0xf, 3, 3, 0xf }, + .supported_rotations =3D DRM_MODE_REFLECT_Y, + .type =3D DRM_PLANE_TYPE_OVERLAY, + .max_upscale_factor =3D 8, + .max_downscale_factor =3D 8, + }, +}; + +static const struct vop2_regs_dump rk3576_regs_dump[] =3D { + { + .name =3D "SYS", + .base =3D RK3568_REG_CFG_DONE, + .size =3D 0x200, + .en_reg =3D 0, + .en_val =3D 0, + .en_mask =3D 0 + }, { + .name =3D "OVL_SYS", + .base =3D RK3576_SYS_EXTRA_ALPHA_CTRL, + .size =3D 0x50, + .en_reg =3D 0, + .en_val =3D 0, + .en_mask =3D 0, + }, { + .name =3D "OVL_VP0", + .base =3D RK3576_OVL_CTRL(0), + .size =3D 0x80, + .en_reg =3D 0, + .en_val =3D 0, + .en_mask =3D 0, + }, { + .name =3D "OVL_VP1", + .base =3D RK3576_OVL_CTRL(1), + .size =3D 0x80, + .en_reg =3D 0, + .en_val =3D 0, + .en_mask =3D 0, + }, { + .name =3D "OVL_VP2", + .base =3D RK3576_OVL_CTRL(2), + .size =3D 0x80, + .en_reg =3D 0, + .en_val =3D 0, + .en_mask =3D 0, + }, { + .name =3D "VP0", + .base =3D RK3568_VP0_CTRL_BASE, + .size =3D 0x100, + .en_reg =3D RK3568_VP_DSP_CTRL, + .en_val =3D 0, + .en_mask =3D RK3568_VP_DSP_CTRL__STANDBY, + }, { + .name =3D "VP1", + .base =3D RK3568_VP1_CTRL_BASE, + .size =3D 0x100, + .en_reg =3D RK3568_VP_DSP_CTRL, + .en_val =3D 0, + .en_mask =3D RK3568_VP_DSP_CTRL__STANDBY, + }, { + .name =3D "VP2", + .base =3D RK3568_VP2_CTRL_BASE, + .size =3D 0x100, + .en_reg =3D RK3568_VP_DSP_CTRL, + .en_val =3D 0, + .en_mask =3D RK3568_VP_DSP_CTRL__STANDBY, + }, { + .name =3D "Cluster0", + .base =3D RK3568_CLUSTER0_CTRL_BASE, + .size =3D 0x200, + .en_reg =3D RK3568_CLUSTER_WIN_CTRL0, + .en_val =3D RK3568_CLUSTER_WIN_CTRL0__WIN0_EN, + .en_mask =3D RK3568_CLUSTER_WIN_CTRL0__WIN0_EN, + }, { + .name =3D "Cluster1", + .base =3D RK3568_CLUSTER1_CTRL_BASE, + .size =3D 0x200, + .en_reg =3D RK3568_CLUSTER_WIN_CTRL0, + .en_val =3D RK3568_CLUSTER_WIN_CTRL0__WIN0_EN, + .en_mask =3D RK3568_CLUSTER_WIN_CTRL0__WIN0_EN, + }, { + .name =3D "Esmart0", + .base =3D RK3568_ESMART0_CTRL_BASE, + .size =3D 0xf0, + .en_reg =3D RK3568_SMART_REGION0_CTRL, + .en_val =3D RK3568_SMART_REGION0_CTRL__WIN0_EN, + .en_mask =3D RK3568_SMART_REGION0_CTRL__WIN0_EN, + }, { + .name =3D "Esmart1", + .base =3D RK3568_ESMART1_CTRL_BASE, + .size =3D 0xf0, + .en_reg =3D RK3568_SMART_REGION0_CTRL, + .en_val =3D RK3568_SMART_REGION0_CTRL__WIN0_EN, + .en_mask =3D RK3568_SMART_REGION0_CTRL__WIN0_EN, + }, { + .name =3D "Esmart2", + .base =3D RK3588_ESMART2_CTRL_BASE, + .size =3D 0xf0, + .en_reg =3D RK3568_SMART_REGION0_CTRL, + .en_val =3D RK3568_SMART_REGION0_CTRL__WIN0_EN, + .en_mask =3D RK3568_SMART_REGION0_CTRL__WIN0_EN, + }, { + .name =3D "Esmart3", + .base =3D RK3588_ESMART3_CTRL_BASE, + .size =3D 0xf0, + .en_reg =3D RK3568_SMART_REGION0_CTRL, + .en_val =3D RK3568_SMART_REGION0_CTRL__WIN0_EN, + .en_mask =3D RK3568_SMART_REGION0_CTRL__WIN0_EN, + }, +}; + static const struct vop2_video_port_data rk3588_vop_video_ports[] =3D { { .id =3D 0, @@ -876,6 +1380,84 @@ static unsigned long rk3568_set_intf_mux(struct vop2_= video_port *vp, int id, u32 return crtc->state->adjusted_mode.crtc_clock * 1000LL; } =20 +static unsigned long rk3576_set_intf_mux(struct vop2_video_port *vp, int i= d, u32 polflags) +{ + struct vop2 *vop2 =3D vp->vop2; + struct drm_crtc *crtc =3D &vp->crtc; + struct drm_display_mode *adjusted_mode =3D &crtc->state->adjusted_mode; + struct rockchip_crtc_state *vcstate =3D to_rockchip_crtc_state(crtc->stat= e); + u8 port_pix_rate =3D vp->data->pixel_rate; + int dclk_core_div, dclk_out_div, if_pixclk_div, if_dclk_sel; + u32 ctrl, vp_clk_div, reg, dclk_div; + unsigned long dclk_in_rate, dclk_core_rate; + + if (vcstate->output_mode =3D=3D ROCKCHIP_OUT_MODE_YUV420 || adjusted_mode= ->crtc_clock > 600000) + dclk_div =3D 2; + else + dclk_div =3D 1; + + if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK) + dclk_core_rate =3D adjusted_mode->crtc_clock / 2; + else + dclk_core_rate =3D adjusted_mode->crtc_clock / port_pix_rate; + + dclk_in_rate =3D adjusted_mode->crtc_clock / dclk_div; + + dclk_core_div =3D dclk_in_rate > dclk_core_rate ? 1 : 0; + + if (vop2_output_if_is_edp(id)) + if_pixclk_div =3D port_pix_rate =3D=3D 2 ? RK3576_DSP_IF_PCLK_DIV : 0; + else + if_pixclk_div =3D port_pix_rate =3D=3D 1 ? RK3576_DSP_IF_PCLK_DIV : 0; + + if (vcstate->output_mode =3D=3D ROCKCHIP_OUT_MODE_YUV420) { + if_dclk_sel =3D RK3576_DSP_IF_DCLK_SEL_OUT; + dclk_out_div =3D 1; + } else { + if_dclk_sel =3D 0; + dclk_out_div =3D 0; + } + + switch (id) { + case ROCKCHIP_VOP2_EP_HDMI0: + reg =3D RK3576_HDMI0_IF_CTRL; + break; + case ROCKCHIP_VOP2_EP_EDP0: + reg =3D RK3576_EDP0_IF_CTRL; + break; + case ROCKCHIP_VOP2_EP_MIPI0: + reg =3D RK3576_MIPI0_IF_CTRL; + break; + case ROCKCHIP_VOP2_EP_DP0: + reg =3D RK3576_DP0_IF_CTRL; + break; + case ROCKCHIP_VOP2_EP_DP1: + reg =3D RK3576_DP1_IF_CTRL; + break; + default: + drm_err(vop2->drm, "Invalid interface id %d on vp%d\n", id, vp->id); + return 0; + } + + ctrl =3D vop2_readl(vop2, reg); + ctrl &=3D ~RK3576_DSP_IF_DCLK_SEL_OUT; + ctrl &=3D ~RK3576_DSP_IF_PCLK_DIV; + ctrl &=3D ~RK3576_DSP_IF_MUX; + ctrl |=3D RK3576_DSP_IF_CFG_DONE_IMD; + ctrl |=3D if_dclk_sel | if_pixclk_div; + ctrl |=3D RK3576_DSP_IF_CLK_OUT_EN | RK3576_DSP_IF_EN; + ctrl |=3D FIELD_PREP(RK3576_DSP_IF_MUX, vp->id); + ctrl |=3D FIELD_PREP(RK3576_DSP_IF_PIN_POL, polflags); + vop2_writel(vop2, reg, ctrl); + + vp_clk_div =3D FIELD_PREP(RK3588_VP_CLK_CTRL__DCLK_CORE_DIV, dclk_core_di= v); + vp_clk_div |=3D FIELD_PREP(RK3588_VP_CLK_CTRL__DCLK_OUT_DIV, dclk_out_div= ); + + vop2_vp_write(vp, RK3588_VP_CLK_CTRL, vp_clk_div); + + return dclk_in_rate * 1000LL; +} + /* * calc the dclk on rk3588 * the available div of dclk is 1, 2, 4 @@ -1214,6 +1796,7 @@ static void vop2_setup_cluster_alpha(struct vop2 *vop= 2, struct vop2_win *main_wi struct drm_plane_state *bottom_win_pstate; bool src_pixel_alpha_en =3D false; u16 src_glb_alpha_val, dst_glb_alpha_val; + u32 src_color_ctrl_reg, dst_color_ctrl_reg, src_alpha_ctrl_reg, dst_alpha= _ctrl_reg; u32 offset =3D 0; bool premulti_en =3D false; bool swap =3D false; @@ -1251,14 +1834,22 @@ static void vop2_setup_cluster_alpha(struct vop2 *v= op2, struct vop2_win *main_wi break; } =20 - vop2_writel(vop2, RK3568_CLUSTER0_MIX_SRC_COLOR_CTRL + offset, - alpha.src_color_ctrl.val); - vop2_writel(vop2, RK3568_CLUSTER0_MIX_DST_COLOR_CTRL + offset, - alpha.dst_color_ctrl.val); - vop2_writel(vop2, RK3568_CLUSTER0_MIX_SRC_ALPHA_CTRL + offset, - alpha.src_alpha_ctrl.val); - vop2_writel(vop2, RK3568_CLUSTER0_MIX_DST_ALPHA_CTRL + offset, - alpha.dst_alpha_ctrl.val); + if (vop2->version <=3D VOP_VERSION_RK3588) { + src_color_ctrl_reg =3D RK3568_CLUSTER0_MIX_SRC_COLOR_CTRL; + dst_color_ctrl_reg =3D RK3568_CLUSTER0_MIX_DST_COLOR_CTRL; + src_alpha_ctrl_reg =3D RK3568_CLUSTER0_MIX_SRC_ALPHA_CTRL; + dst_alpha_ctrl_reg =3D RK3568_CLUSTER0_MIX_DST_ALPHA_CTRL; + } else { + src_color_ctrl_reg =3D RK3576_CLUSTER0_MIX_SRC_COLOR_CTRL; + dst_color_ctrl_reg =3D RK3576_CLUSTER0_MIX_DST_COLOR_CTRL; + src_alpha_ctrl_reg =3D RK3576_CLUSTER0_MIX_SRC_ALPHA_CTRL; + dst_alpha_ctrl_reg =3D RK3576_CLUSTER0_MIX_DST_ALPHA_CTRL; + } + + vop2_writel(vop2, src_color_ctrl_reg + offset, alpha.src_color_ctrl.val); + vop2_writel(vop2, dst_color_ctrl_reg + offset, alpha.dst_color_ctrl.val); + vop2_writel(vop2, src_alpha_ctrl_reg + offset, alpha.src_alpha_ctrl.val); + vop2_writel(vop2, dst_alpha_ctrl_reg + offset, alpha.dst_alpha_ctrl.val); } =20 static void vop2_setup_alpha(struct vop2_video_port *vp) @@ -1271,11 +1862,16 @@ static void vop2_setup_alpha(struct vop2_video_port= *vp) int pixel_alpha_en; int premulti_en, gpremulti_en =3D 0; int mixer_id; + u32 src_color_ctrl_reg, dst_color_ctrl_reg, src_alpha_ctrl_reg, dst_alpha= _ctrl_reg; u32 offset; bool bottom_layer_alpha_en =3D false; u32 dst_global_alpha =3D DRM_BLEND_ALPHA_OPAQUE; =20 - mixer_id =3D vop2_find_start_mixer_id_for_vp(vop2, vp->id); + if (vop2->version <=3D VOP_VERSION_RK3588) + mixer_id =3D vop2_find_start_mixer_id_for_vp(vop2, vp->id); + else + mixer_id =3D 0; + alpha_config.dst_pixel_alpha_en =3D true; /* alpha value need transfer to= next mix */ =20 drm_atomic_crtc_for_each_plane(plane, &vp->crtc) { @@ -1294,6 +1890,18 @@ static void vop2_setup_alpha(struct vop2_video_port = *vp) } } =20 + if (vop2->version <=3D VOP_VERSION_RK3588) { + src_color_ctrl_reg =3D RK3568_MIX0_SRC_COLOR_CTRL; + dst_color_ctrl_reg =3D RK3568_MIX0_DST_COLOR_CTRL; + src_alpha_ctrl_reg =3D RK3568_MIX0_SRC_ALPHA_CTRL; + dst_alpha_ctrl_reg =3D RK3568_MIX0_DST_ALPHA_CTRL; + } else { + src_color_ctrl_reg =3D RK3576_OVL_MIX0_SRC_COLOR_CTRL(vp->id); + dst_color_ctrl_reg =3D RK3576_OVL_MIX0_DST_COLOR_CTRL(vp->id); + src_alpha_ctrl_reg =3D RK3576_OVL_MIX0_SRC_ALPHA_CTRL(vp->id); + dst_alpha_ctrl_reg =3D RK3576_OVL_MIX0_DST_ALPHA_CTRL(vp->id); + } + drm_atomic_crtc_for_each_plane(plane, &vp->crtc) { struct vop2_win *win =3D to_vop2_win(plane); int zpos =3D plane->state->normalized_zpos; @@ -1340,17 +1948,26 @@ static void vop2_setup_alpha(struct vop2_video_port= *vp) vop2_parse_alpha(&alpha_config, &alpha); =20 offset =3D (mixer_id + zpos - 1) * 0x10; - vop2_writel(vop2, RK3568_MIX0_SRC_COLOR_CTRL + offset, - alpha.src_color_ctrl.val); - vop2_writel(vop2, RK3568_MIX0_DST_COLOR_CTRL + offset, - alpha.dst_color_ctrl.val); - vop2_writel(vop2, RK3568_MIX0_SRC_ALPHA_CTRL + offset, - alpha.src_alpha_ctrl.val); - vop2_writel(vop2, RK3568_MIX0_DST_ALPHA_CTRL + offset, - alpha.dst_alpha_ctrl.val); + + vop2_writel(vop2, src_color_ctrl_reg + offset, alpha.src_color_ctrl.val); + vop2_writel(vop2, dst_color_ctrl_reg + offset, alpha.dst_color_ctrl.val); + vop2_writel(vop2, src_alpha_ctrl_reg + offset, alpha.src_alpha_ctrl.val); + vop2_writel(vop2, dst_alpha_ctrl_reg + offset, alpha.dst_alpha_ctrl.val); } =20 if (vp->id =3D=3D 0) { + if (vop2->version <=3D VOP_VERSION_RK3588) { + src_color_ctrl_reg =3D RK3568_HDR0_SRC_COLOR_CTRL; + dst_color_ctrl_reg =3D RK3568_HDR0_DST_COLOR_CTRL; + src_alpha_ctrl_reg =3D RK3568_HDR0_SRC_ALPHA_CTRL; + dst_alpha_ctrl_reg =3D RK3568_HDR0_DST_ALPHA_CTRL; + } else { + src_color_ctrl_reg =3D RK3576_OVL_HDR_SRC_COLOR_CTRL(vp->id); + dst_color_ctrl_reg =3D RK3576_OVL_HDR_DST_COLOR_CTRL(vp->id); + src_alpha_ctrl_reg =3D RK3576_OVL_HDR_SRC_ALPHA_CTRL(vp->id); + dst_alpha_ctrl_reg =3D RK3576_OVL_HDR_DST_ALPHA_CTRL(vp->id); + } + if (bottom_layer_alpha_en) { /* Transfer pixel alpha to hdr mix */ alpha_config.src_premulti_en =3D gpremulti_en; @@ -1358,18 +1975,15 @@ static void vop2_setup_alpha(struct vop2_video_port= *vp) alpha_config.src_pixel_alpha_en =3D true; alpha_config.src_glb_alpha_value =3D DRM_BLEND_ALPHA_OPAQUE; alpha_config.dst_glb_alpha_value =3D DRM_BLEND_ALPHA_OPAQUE; + vop2_parse_alpha(&alpha_config, &alpha); =20 - vop2_writel(vop2, RK3568_HDR0_SRC_COLOR_CTRL, - alpha.src_color_ctrl.val); - vop2_writel(vop2, RK3568_HDR0_DST_COLOR_CTRL, - alpha.dst_color_ctrl.val); - vop2_writel(vop2, RK3568_HDR0_SRC_ALPHA_CTRL, - alpha.src_alpha_ctrl.val); - vop2_writel(vop2, RK3568_HDR0_DST_ALPHA_CTRL, - alpha.dst_alpha_ctrl.val); + vop2_writel(vop2, src_color_ctrl_reg, alpha.src_color_ctrl.val); + vop2_writel(vop2, dst_color_ctrl_reg, alpha.dst_color_ctrl.val); + vop2_writel(vop2, src_alpha_ctrl_reg, alpha.src_alpha_ctrl.val); + vop2_writel(vop2, dst_alpha_ctrl_reg, alpha.dst_alpha_ctrl.val); } else { - vop2_writel(vop2, RK3568_HDR0_SRC_COLOR_CTRL, 0); + vop2_writel(vop2, src_color_ctrl_reg, 0); } } } @@ -1577,6 +2191,72 @@ static void rk3568_vop2_setup_overlay(struct vop2_vi= deo_port *vp) rk3568_vop2_setup_dly_for_windows(vp); } =20 +static void rk3576_vop2_setup_layer_mixer(struct vop2_video_port *vp) +{ + struct rockchip_crtc_state *vcstate =3D to_rockchip_crtc_state(vp->crtc.s= tate); + struct vop2 *vop2 =3D vp->vop2; + struct drm_plane *plane; + u32 layer_sel =3D 0xffff; /* 0xf means this layer is disabled */ + u32 ovl_ctrl; + + ovl_ctrl =3D vop2_readl(vop2, RK3576_OVL_CTRL(vp->id)); + if (vcstate->yuv_overlay) + ovl_ctrl |=3D RK3576_OVL_CTRL__YUV_MODE; + else + ovl_ctrl &=3D ~RK3576_OVL_CTRL__YUV_MODE; + + vop2_writel(vop2, RK3576_OVL_CTRL(vp->id), ovl_ctrl); + + drm_atomic_crtc_for_each_plane(plane, &vp->crtc) { + struct vop2_win *win =3D to_vop2_win(plane); + + layer_sel &=3D ~RK3568_OVL_LAYER_SEL__LAYER(plane->state->normalized_zpo= s, + 0xf); + layer_sel |=3D RK3568_OVL_LAYER_SEL__LAYER(plane->state->normalized_zpos, + win->data->layer_sel_id[vp->id]); + } + + vop2_writel(vop2, RK3576_OVL_LAYER_SEL(vp->id), layer_sel); +} + +static void rk3576_vop2_setup_dly_for_windows(struct vop2_video_port *vp) +{ + struct drm_plane *plane; + struct vop2_win *win; + + drm_atomic_crtc_for_each_plane(plane, &vp->crtc) { + win =3D to_vop2_win(plane); + vop2_win_write(win, VOP2_WIN_DLY_NUM, 0); + } +} + +static void rk3576_vop2_setup_overlay(struct vop2_video_port *vp) +{ + struct vop2 *vop2 =3D vp->vop2; + struct drm_crtc *crtc =3D &vp->crtc; + struct drm_plane *plane; + + vp->win_mask =3D 0; + + drm_atomic_crtc_for_each_plane(plane, crtc) { + struct vop2_win *win =3D to_vop2_win(plane); + + win->delay =3D win->data->dly[VOP2_DLY_MODE_DEFAULT]; + + vp->win_mask |=3D BIT(win->data->phys_id); + + if (vop2_cluster_window(win)) + vop2_setup_cluster_alpha(vop2, win); + } + + if (!vp->win_mask) + return; + + rk3576_vop2_setup_layer_mixer(vp); + vop2_setup_alpha(vp); + rk3576_vop2_setup_dly_for_windows(vp); +} + static void rk3568_vop2_setup_bg_dly(struct vop2_video_port *vp) { struct drm_crtc *crtc =3D &vp->crtc; @@ -1594,12 +2274,38 @@ static void rk3568_vop2_setup_bg_dly(struct vop2_vi= deo_port *vp) vop2_vp_write(vp, RK3568_VP_PRE_SCAN_HTIMING, pre_scan_dly); } =20 +static void rk3576_vop2_setup_bg_dly(struct vop2_video_port *vp) +{ + struct drm_crtc *crtc =3D &vp->crtc; + struct drm_display_mode *mode =3D &crtc->state->adjusted_mode; + u16 hdisplay =3D mode->crtc_hdisplay; + u16 hsync_len =3D mode->crtc_hsync_end - mode->crtc_hsync_start; + u32 bg_dly; + u32 pre_scan_dly; + + bg_dly =3D vp->data->pre_scan_max_dly[VOP2_DLY_WIN] + + vp->data->pre_scan_max_dly[VOP2_DLY_LAYER_MIX] + + vp->data->pre_scan_max_dly[VOP2_DLY_HDR_MIX]; + + vop2_writel(vp->vop2, RK3576_OVL_BG_MIX_CTRL(vp->id), + FIELD_PREP(RK3576_OVL_BG_MIX_CTRL__BG_DLY, bg_dly)); + + pre_scan_dly =3D ((bg_dly + (hdisplay >> 1) - 1) << 16) | hsync_len; + vop2_vp_write(vp, RK3568_VP_PRE_SCAN_HTIMING, pre_scan_dly); +} + static const struct vop2_ops rk3568_vop_ops =3D { .setup_intf_mux =3D rk3568_set_intf_mux, .setup_bg_dly =3D rk3568_vop2_setup_bg_dly, .setup_overlay =3D rk3568_vop2_setup_overlay, }; =20 +static const struct vop2_ops rk3576_vop_ops =3D { + .setup_intf_mux =3D rk3576_set_intf_mux, + .setup_bg_dly =3D rk3576_vop2_setup_bg_dly, + .setup_overlay =3D rk3576_vop2_setup_overlay, +}; + static const struct vop2_ops rk3588_vop_ops =3D { .setup_intf_mux =3D rk3588_set_intf_mux, .setup_bg_dly =3D rk3568_vop2_setup_bg_dly, @@ -1644,6 +2350,25 @@ static const struct vop2_data rk3568_vop =3D { .soc_id =3D 3568, }; =20 +static const struct vop2_data rk3576_vop =3D { + .version =3D VOP_VERSION_RK3576, + .feature =3D VOP2_FEATURE_HAS_SYS_PMU, + .nr_vps =3D 3, + .max_input =3D { 4096, 4320 }, + .max_output =3D { 4096, 4320 }, + .vp =3D rk3576_vop_video_ports, + .win =3D rk3576_vop_win_data, + .win_size =3D ARRAY_SIZE(rk3576_vop_win_data), + .cluster_reg =3D rk3576_vop_cluster_regs, + .nr_cluster_regs =3D ARRAY_SIZE(rk3576_vop_cluster_regs), + .smart_reg =3D rk3576_vop_smart_regs, + .nr_smart_regs =3D ARRAY_SIZE(rk3576_vop_smart_regs), + .regs_dump =3D rk3576_regs_dump, + .regs_dump_size =3D ARRAY_SIZE(rk3576_regs_dump), + .ops =3D &rk3576_vop_ops, + .soc_id =3D 3576, +}; + static const struct vop2_data rk3588_vop =3D { .version =3D VOP_VERSION_RK3588, .feature =3D VOP2_FEATURE_HAS_SYS_GRF | VOP2_FEATURE_HAS_VO1_GRF | @@ -1671,6 +2396,9 @@ static const struct of_device_id vop2_dt_match[] =3D { }, { .compatible =3D "rockchip,rk3568-vop", .data =3D &rk3568_vop, + }, { + .compatible =3D "rockchip,rk3576-vop", + .data =3D &rk3576_vop, }, { .compatible =3D "rockchip,rk3588-vop", .data =3D &rk3588_vop --=20 2.34.1