Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys rkdrm: Convert to atomic modesetting, as needed for brid...



details:   https://anonhg.NetBSD.org/src/rev/faafe7d42bb4
branches:  trunk
changeset: 1029017:faafe7d42bb4
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Dec 19 12:43:37 2021 +0000

description:
rkdrm: Convert to atomic modesetting, as needed for bridges.


Author: Jared McNeill <jmcneill%invisible.ca@localhost>
Committer: Taylor R Campbell <riastradh%NetBSD.org@localhost>

diffstat:

 sys/arch/arm/rockchip/rk_anxdp.c       |   19 +-
 sys/arch/arm/rockchip/rk_drm.c         |   20 +-
 sys/arch/arm/rockchip/rk_vop.c         |  290 ++++++++++++++++++++------------
 sys/dev/ic/anx_dp.c                    |   81 +++++----
 sys/dev/ic/anx_dp.h                    |    5 +-
 sys/external/bsd/drm2/drm/drm_module.c |    6 +-
 6 files changed, 243 insertions(+), 178 deletions(-)

diffs (truncated from 841 to 300 lines):

diff -r 741d00f4d6ad -r faafe7d42bb4 sys/arch/arm/rockchip/rk_anxdp.c
--- a/sys/arch/arm/rockchip/rk_anxdp.c  Sun Dec 19 12:43:29 2021 +0000
+++ b/sys/arch/arm/rockchip/rk_anxdp.c  Sun Dec 19 12:43:37 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rk_anxdp.c,v 1.5 2021/12/19 11:00:46 riastradh Exp $ */
+/* $NetBSD: rk_anxdp.c,v 1.6 2021/12/19 12:43:37 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2019 Jonathan A. Kollasch <jakllsch%kollasch.net@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rk_anxdp.c,v 1.5 2021/12/19 11:00:46 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rk_anxdp.c,v 1.6 2021/12/19 12:43:37 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -117,19 +117,6 @@
        rk_anxdp_select_input(sc, crtc_index);
 }
 
-static void
-rk_anxdp_encoder_commit(struct drm_encoder *encoder)
-{
-}
-
-static void
-rk_anxdp_encoder_dpms(struct drm_encoder *encoder, int mode)
-{
-       struct rk_anxdp_softc * const sc = to_rk_anxdp_encoder(encoder);
-
-       anxdp_dpms(&sc->sc_base, mode);
-}
-
 static const struct drm_encoder_funcs rk_anxdp_encoder_funcs = {
        .destroy = drm_encoder_cleanup,
 };
@@ -140,8 +127,6 @@
        .mode_set = rk_anxdp_encoder_mode_set,
        .enable = rk_anxdp_encoder_enable,
        .disable = rk_anxdp_encoder_disable,
-       .commit = rk_anxdp_encoder_commit,
-       .dpms = rk_anxdp_encoder_dpms,
 };
 
 static int
diff -r 741d00f4d6ad -r faafe7d42bb4 sys/arch/arm/rockchip/rk_drm.c
--- a/sys/arch/arm/rockchip/rk_drm.c    Sun Dec 19 12:43:29 2021 +0000
+++ b/sys/arch/arm/rockchip/rk_drm.c    Sun Dec 19 12:43:37 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rk_drm.c,v 1.15 2021/12/19 12:43:29 riastradh Exp $ */
+/* $NetBSD: rk_drm.c,v 1.16 2021/12/19 12:43:37 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2019 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rk_drm.c,v 1.15 2021/12/19 12:43:29 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rk_drm.c,v 1.16 2021/12/19 12:43:37 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -46,8 +46,10 @@
 
 #include <arm/rockchip/rk_drm.h>
 
+#include <drm/drm_atomic_helper.h>
 #include <drm/drm_auth.h>
 #include <drm/drm_crtc_helper.h>
+#include <drm/drm_damage_helper.h>
 #include <drm/drm_drv.h>
 #include <drm/drm_fb_helper.h>
 #include <drm/drm_fourcc.h>
@@ -85,7 +87,7 @@
 static void    rk_drm_task_work(struct work *, void *);
 
 static struct drm_driver rk_drm_driver = {
-       .driver_features = DRIVER_MODESET | DRIVER_GEM,
+       .driver_features = DRIVER_MODESET | DRIVER_ATOMIC | DRIVER_GEM,
        .dev_priv_size = 0,
        .load = rk_drm_load,
        .unload = rk_drm_unload,
@@ -252,6 +254,7 @@
 static const struct drm_framebuffer_funcs rk_drm_framebuffer_funcs = {
        .create_handle = rk_drm_fb_create_handle,
        .destroy = rk_drm_fb_destroy,
+       .dirty = drm_atomic_helper_dirtyfb,
 };
 
 static struct drm_framebuffer *
@@ -289,6 +292,12 @@
 
 static struct drm_mode_config_funcs rk_drm_mode_config_funcs = {
        .fb_create = rk_drm_fb_create,
+       .atomic_check = drm_atomic_helper_check,
+       .atomic_commit = drm_atomic_helper_commit,
+};
+
+static struct drm_mode_config_helper_funcs rk_drm_mode_config_helper_funcs = {
+       .atomic_commit_tail = drm_atomic_helper_commit_tail_rpm,
 };
 
 static int
@@ -328,7 +337,6 @@
        fb->offsets[0] = 0;
        fb->width = width;
        fb->height = height;
-       fb->dev = ddev;
        fb->modifier = 0;
        fb->flags = 0;
 #ifdef __ARM_BIG_ENDIAN
@@ -336,6 +344,7 @@
 #else
        fb->format = drm_format_info(DRM_FORMAT_XRGB8888);
 #endif
+       fb->dev = ddev;
 
        error = drm_framebuffer_init(ddev, fb, &rk_drm_framebuffer_funcs);
        if (error != 0) {
@@ -381,6 +390,7 @@
        ddev->mode_config.max_width = RK_DRM_MAX_WIDTH;
        ddev->mode_config.max_height = RK_DRM_MAX_HEIGHT;
        ddev->mode_config.funcs = &rk_drm_mode_config_funcs;
+       ddev->mode_config.helper_private = &rk_drm_mode_config_helper_funcs;
 
        num_crtc = 0;
        data = fdtbus_get_prop(sc->sc_phandle, "ports", &datalen);
@@ -424,8 +434,6 @@
 
        drm_fb_helper_single_add_all_connectors(&fbdev->helper);
 
-       drm_helper_disable_unused_functions(ddev);
-
        drm_fb_helper_initial_config(&fbdev->helper, 32);
 
        /* XXX */
diff -r 741d00f4d6ad -r faafe7d42bb4 sys/arch/arm/rockchip/rk_vop.c
--- a/sys/arch/arm/rockchip/rk_vop.c    Sun Dec 19 12:43:29 2021 +0000
+++ b/sys/arch/arm/rockchip/rk_vop.c    Sun Dec 19 12:43:37 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rk_vop.c,v 1.12 2021/12/19 11:01:10 riastradh Exp $ */
+/* $NetBSD: rk_vop.c,v 1.13 2021/12/19 12:43:37 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2019 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rk_vop.c,v 1.12 2021/12/19 11:01:10 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rk_vop.c,v 1.13 2021/12/19 12:43:37 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -43,6 +43,8 @@
 
 #include <arm/rockchip/rk_drm.h>
 
+#include <drm/drm_atomic.h>
+#include <drm/drm_atomic_helper.h>
 #include <drm/drm_crtc.h>
 #include <drm/drm_crtc_helper.h>
 #include <drm/drm_drv.h>
@@ -129,6 +131,11 @@
        struct rk_vop_softc     *sc;
 };
 
+struct rk_vop_plane {
+       struct drm_plane        base;
+       struct rk_vop_softc     *sc;
+};
+
 struct rk_vop_softc {
        device_t                sc_dev;
        bus_space_tag_t         sc_bst;
@@ -137,6 +144,7 @@
 
        struct clk              *sc_dclk;
 
+       struct rk_vop_plane     sc_plane;
        struct rk_vop_crtc      sc_crtc;
 
        struct fdt_device_ports sc_ports;
@@ -145,6 +153,7 @@
 };
 
 #define        to_rk_vop_crtc(x)       container_of(x, struct rk_vop_crtc, base)
+#define        to_rk_vop_plane(x)      container_of(x, struct rk_vop_plane, base)
 
 #define        RD4(sc, reg)                            \
        bus_space_read_4((sc)->sc_bst, (sc)->sc_bsh, (reg))
@@ -159,6 +168,16 @@
                                                enum vop_ep_type, uint32_t);
 };
 
+static const uint32_t rk_vop_layer_formats[] = {
+       DRM_FORMAT_ARGB8888,
+       DRM_FORMAT_XRGB8888,
+};
+
+static const uint64_t rk_vop_layer_modifiers[] = {
+       DRM_FORMAT_MOD_LINEAR,
+       DRM_FORMAT_MOD_INVALID
+};
+
 #define        RK3399_VOP_MIPI_POL     __BITS(31,28)
 #define        RK3399_VOP_EDP_POL      __BITS(27,24)
 #define        RK3399_VOP_HDMI_POL     __BITS(23,20)
@@ -229,42 +248,132 @@
 };
 
 static int
-rk_vop_mode_do_set_base(struct drm_crtc *crtc, struct drm_framebuffer *fb,
-    int x, int y, int atomic)
+rk_vop_plane_atomic_check(struct drm_plane *plane,
+    struct drm_plane_state *state)
+{
+       struct drm_crtc_state *crtc_state;
+
+       if (state->crtc == NULL)
+               return 0;
+
+       crtc_state = drm_atomic_get_new_crtc_state(state->state, state->crtc);
+       if (IS_ERR(crtc_state))
+               return PTR_ERR(crtc_state);
+
+       return drm_atomic_helper_check_plane_state(state, crtc_state,
+           DRM_PLANE_HELPER_NO_SCALING, DRM_PLANE_HELPER_NO_SCALING,
+           false, true);
+}
+
+static void
+rk_vop_plane_atomic_update(struct drm_plane *plane,
+    struct drm_plane_state *old_state)
 {
-       struct rk_vop_crtc *mixer_crtc = to_rk_vop_crtc(crtc);
-       struct rk_vop_softc * const sc = mixer_crtc->sc;
-       struct rk_drm_framebuffer *sfb = atomic?
-           to_rk_drm_framebuffer(fb) :
-           to_rk_drm_framebuffer(crtc->primary->fb);
+       struct rk_vop_plane *vop_plane = to_rk_vop_plane(plane);
+       struct rk_vop_softc * const sc = vop_plane->sc;
+       struct rk_drm_framebuffer *sfb =
+           to_rk_drm_framebuffer(plane->state->fb);
+       struct drm_display_mode *mode = &plane->state->crtc->mode;
+       struct drm_rect *src = &plane->state->src;
+       struct drm_rect *dst = &plane->state->dst;
+       uint32_t act_width, act_height, dsp_width, dsp_height;
+       uint32_t htotal, hsync_start;
+       uint32_t vtotal, vsync_start;
+       uint32_t lb_mode;
+       uint32_t block_h, block_w, x, y, block_start_y, num_hblocks;
+       uint64_t paddr;
+       uint32_t val;
+
+       act_width = drm_rect_width(src) >> 16;
+       act_height = drm_rect_height(src) >> 16;
+       val = __SHIFTIN(act_width - 1, WIN0_ACT_WIDTH) |
+             __SHIFTIN(act_height - 1, WIN0_ACT_HEIGHT);
+       WR4(sc, VOP_WIN0_ACT_INFO, val);
+
+       dsp_width = drm_rect_width(dst);
+       dsp_height = drm_rect_height(dst);
+       val = __SHIFTIN(dsp_width - 1, WIN0_DSP_WIDTH) |
+             __SHIFTIN(dsp_height - 1, WIN0_DSP_HEIGHT);
+       WR4(sc, VOP_WIN0_DSP_INFO, val);
 
-       uint64_t paddr = (uint64_t)sfb->obj->dmamap->dm_segs[0].ds_addr;
+       htotal = mode->htotal;
+       hsync_start = mode->hsync_start;
+       vtotal = mode->vtotal;
+       vsync_start = mode->vsync_start;
+       val = __SHIFTIN(dst->x1 + htotal - hsync_start, WIN0_DSP_XST) |
+             __SHIFTIN(dst->y1 + vtotal - vsync_start, WIN0_DSP_YST);
+       WR4(sc, VOP_WIN0_DSP_ST, val);
 
+       WR4(sc, VOP_WIN0_COLOR_KEY, 0);
 
-       paddr += y * sfb->base.pitches[0];
-       paddr += x * sfb->base.format->cpp[0];
+       if (act_width > 2560)
+               lb_mode = WIN0_LB_MODE_RGB_3840X2;
+       else if (act_width > 1920)
+               lb_mode = WIN0_LB_MODE_RGB_2560X4;
+       else if (act_width > 1280)
+               lb_mode = WIN0_LB_MODE_RGB_1920X5;
+       else
+               lb_mode = WIN0_LB_MODE_RGB_1280X8;
+       val = __SHIFTIN(lb_mode, WIN0_LB_MODE) |
+             __SHIFTIN(WIN0_DATA_FMT_ARGB888, WIN0_DATA_FMT) |
+             WIN0_EN;
+       WR4(sc, VOP_WIN0_CTRL, val);
+
+       paddr = (uint64_t)sfb->obj->dmamap->dm_segs[0].ds_addr;
+       paddr += sfb->base.offsets[0];
+
+       block_h = drm_format_info_block_height(sfb->base.format, 0);



Home | Main Index | Thread Index | Old Index