Merge tag 'zxdrm-4.11' of git://git.kernel.org/pub/scm/linux/kernel/git/shawnguo...
authorDave Airlie <airlied@redhat.com>
Tue, 31 Jan 2017 22:26:33 +0000 (08:26 +1000)
committerDave Airlie <airlied@redhat.com>
Tue, 31 Jan 2017 22:29:04 +0000 (08:29 +1000)
ZTE DRM driver updates for 4.11:
 - Add missing selection of VIDEOMODE_HELPERS in Kconfig, since ZTE DRM
   driver uses drm_display_mode_to_videomode().
 - Enable HDMI audio support through SPDIF interface based on generic
   hdmi-audio-codec driver.
 - Enable VOU VL (Video Layer) to support overlay plane with scaling
   function.
 - Refine zx_vou driver a bit and then add TV Encoder output device
   support.

[airlied: fixup plane format change]

* tag 'zxdrm-4.11' of git://git.kernel.org/pub/scm/linux/kernel/git/shawnguo/linux:
  drm: zte: add tvenc driver support
  dt: add bindings for ZTE tvenc device
  drm: zte: add function to configure vou_ctrl dividers
  drm: zte: move struct vou_inf into zx_vou driver
  drm: zte: add interlace mode support
  drm: zte: add overlay plane support
  drm: zte: add .atomic_disable hook to disable graphic layer
  drm: zte: make zx_plane accessible from zx_vou driver
  drm: zte: support hdmi audio through spdif
  drm: zte: select VIDEOMODE_HELPERS in Kconfig

1  2 
drivers/gpu/drm/zte/zx_plane.c
drivers/gpu/drm/zte/zx_vou.c

index b634b090cdc1bc7d79fbe7d6faf7885984658bfc,6c742993ed9eb1047b1d8b5d7fe28d2d7854b140..1d08ba381098e5f905be122a926ba5e8cf0b00fe
@@@ -40,6 -30,261 +30,261 @@@ static const uint32_t gl_formats[] = 
        DRM_FORMAT_ARGB4444,
  };
  
 -      format = fb->pixel_format;
+ static const uint32_t vl_formats[] = {
+       DRM_FORMAT_NV12,        /* Semi-planar YUV420 */
+       DRM_FORMAT_YUV420,      /* Planar YUV420 */
+       DRM_FORMAT_YUYV,        /* Packed YUV422 */
+       DRM_FORMAT_YVYU,
+       DRM_FORMAT_UYVY,
+       DRM_FORMAT_VYUY,
+       DRM_FORMAT_YUV444,      /* YUV444 8bit */
+       /*
+        * TODO: add formats below that HW supports:
+        *  - YUV420 P010
+        *  - YUV420 Hantro
+        *  - YUV444 10bit
+        */
+ };
+ #define FRAC_16_16(mult, div)    (((mult) << 16) / (div))
+ static int zx_vl_plane_atomic_check(struct drm_plane *plane,
+                                   struct drm_plane_state *plane_state)
+ {
+       struct drm_framebuffer *fb = plane_state->fb;
+       struct drm_crtc *crtc = plane_state->crtc;
+       struct drm_crtc_state *crtc_state;
+       struct drm_rect clip;
+       int min_scale = FRAC_16_16(1, 8);
+       int max_scale = FRAC_16_16(8, 1);
+       if (!crtc || !fb)
+               return 0;
+       crtc_state = drm_atomic_get_existing_crtc_state(plane_state->state,
+                                                       crtc);
+       if (WARN_ON(!crtc_state))
+               return -EINVAL;
+       /* nothing to check when disabling or disabled */
+       if (!crtc_state->enable)
+               return 0;
+       /* plane must be enabled */
+       if (!plane_state->crtc)
+               return -EINVAL;
+       clip.x1 = 0;
+       clip.y1 = 0;
+       clip.x2 = crtc_state->adjusted_mode.hdisplay;
+       clip.y2 = crtc_state->adjusted_mode.vdisplay;
+       return drm_plane_helper_check_state(plane_state, &clip,
+                                           min_scale, max_scale,
+                                           true, true);
+ }
+ static int zx_vl_get_fmt(uint32_t format)
+ {
+       switch (format) {
+       case DRM_FORMAT_NV12:
+               return VL_FMT_YUV420;
+       case DRM_FORMAT_YUV420:
+               return VL_YUV420_PLANAR | VL_FMT_YUV420;
+       case DRM_FORMAT_YUYV:
+               return VL_YUV422_YUYV | VL_FMT_YUV422;
+       case DRM_FORMAT_YVYU:
+               return VL_YUV422_YVYU | VL_FMT_YUV422;
+       case DRM_FORMAT_UYVY:
+               return VL_YUV422_UYVY | VL_FMT_YUV422;
+       case DRM_FORMAT_VYUY:
+               return VL_YUV422_VYUY | VL_FMT_YUV422;
+       case DRM_FORMAT_YUV444:
+               return VL_FMT_YUV444_8BIT;
+       default:
+               WARN_ONCE(1, "invalid pixel format %d\n", format);
+               return -EINVAL;
+       }
+ }
+ static inline void zx_vl_set_update(struct zx_plane *zplane)
+ {
+       void __iomem *layer = zplane->layer;
+       zx_writel_mask(layer + VL_CTRL0, VL_UPDATE, VL_UPDATE);
+ }
+ static inline void zx_vl_rsz_set_update(struct zx_plane *zplane)
+ {
+       zx_writel(zplane->rsz + RSZ_VL_ENABLE_CFG, 1);
+ }
+ static int zx_vl_rsz_get_fmt(uint32_t format)
+ {
+       switch (format) {
+       case DRM_FORMAT_NV12:
+       case DRM_FORMAT_YUV420:
+               return RSZ_VL_FMT_YCBCR420;
+       case DRM_FORMAT_YUYV:
+       case DRM_FORMAT_YVYU:
+       case DRM_FORMAT_UYVY:
+       case DRM_FORMAT_VYUY:
+               return RSZ_VL_FMT_YCBCR422;
+       case DRM_FORMAT_YUV444:
+               return RSZ_VL_FMT_YCBCR444;
+       default:
+               WARN_ONCE(1, "invalid pixel format %d\n", format);
+               return -EINVAL;
+       }
+ }
+ static inline u32 rsz_step_value(u32 src, u32 dst)
+ {
+       u32 val = 0;
+       if (src == dst)
+               val = 0;
+       else if (src < dst)
+               val = RSZ_PARA_STEP((src << 16) / dst);
+       else if (src > dst)
+               val = RSZ_DATA_STEP(src / dst) |
+                     RSZ_PARA_STEP(((src << 16) / dst) & 0xffff);
+       return val;
+ }
+ static void zx_vl_rsz_setup(struct zx_plane *zplane, uint32_t format,
+                           u32 src_w, u32 src_h, u32 dst_w, u32 dst_h)
+ {
+       void __iomem *rsz = zplane->rsz;
+       u32 src_chroma_w = src_w;
+       u32 src_chroma_h = src_h;
+       u32 fmt;
+       /* Set up source and destination resolution */
+       zx_writel(rsz + RSZ_SRC_CFG, RSZ_VER(src_h - 1) | RSZ_HOR(src_w - 1));
+       zx_writel(rsz + RSZ_DEST_CFG, RSZ_VER(dst_h - 1) | RSZ_HOR(dst_w - 1));
+       /* Configure data format for VL RSZ */
+       fmt = zx_vl_rsz_get_fmt(format);
+       if (fmt >= 0)
+               zx_writel_mask(rsz + RSZ_VL_CTRL_CFG, RSZ_VL_FMT_MASK, fmt);
+       /* Calculate Chroma height and width */
+       if (fmt == RSZ_VL_FMT_YCBCR420) {
+               src_chroma_w = src_w >> 1;
+               src_chroma_h = src_h >> 1;
+       } else if (fmt == RSZ_VL_FMT_YCBCR422) {
+               src_chroma_w = src_w >> 1;
+       }
+       /* Set up Luma and Chroma step registers */
+       zx_writel(rsz + RSZ_VL_LUMA_HOR, rsz_step_value(src_w, dst_w));
+       zx_writel(rsz + RSZ_VL_LUMA_VER, rsz_step_value(src_h, dst_h));
+       zx_writel(rsz + RSZ_VL_CHROMA_HOR, rsz_step_value(src_chroma_w, dst_w));
+       zx_writel(rsz + RSZ_VL_CHROMA_VER, rsz_step_value(src_chroma_h, dst_h));
+       zx_vl_rsz_set_update(zplane);
+ }
+ static void zx_vl_plane_atomic_update(struct drm_plane *plane,
+                                     struct drm_plane_state *old_state)
+ {
+       struct zx_plane *zplane = to_zx_plane(plane);
+       struct drm_plane_state *state = plane->state;
+       struct drm_framebuffer *fb = state->fb;
+       struct drm_rect *src = &state->src;
+       struct drm_rect *dst = &state->dst;
+       struct drm_gem_cma_object *cma_obj;
+       void __iomem *layer = zplane->layer;
+       void __iomem *hbsc = zplane->hbsc;
+       void __iomem *paddr_reg;
+       dma_addr_t paddr;
+       u32 src_x, src_y, src_w, src_h;
+       u32 dst_x, dst_y, dst_w, dst_h;
+       uint32_t format;
+       u32 fmt;
+       int num_planes;
+       int i;
+       if (!fb)
+               return;
++      format = fb->format->format;
+       src_x = src->x1 >> 16;
+       src_y = src->y1 >> 16;
+       src_w = drm_rect_width(src) >> 16;
+       src_h = drm_rect_height(src) >> 16;
+       dst_x = dst->x1;
+       dst_y = dst->y1;
+       dst_w = drm_rect_width(dst);
+       dst_h = drm_rect_height(dst);
+       /* Set up data address registers for Y, Cb and Cr planes */
+       num_planes = drm_format_num_planes(format);
+       paddr_reg = layer + VL_Y;
+       for (i = 0; i < num_planes; i++) {
+               cma_obj = drm_fb_cma_get_gem_obj(fb, i);
+               paddr = cma_obj->paddr + fb->offsets[i];
+               paddr += src_y * fb->pitches[i];
+               paddr += src_x * drm_format_plane_cpp(format, i);
+               zx_writel(paddr_reg, paddr);
+               paddr_reg += 4;
+       }
+       /* Set up source height/width register */
+       zx_writel(layer + VL_SRC_SIZE, GL_SRC_W(src_w) | GL_SRC_H(src_h));
+       /* Set up start position register */
+       zx_writel(layer + VL_POS_START, GL_POS_X(dst_x) | GL_POS_Y(dst_y));
+       /* Set up end position register */
+       zx_writel(layer + VL_POS_END,
+                 GL_POS_X(dst_x + dst_w) | GL_POS_Y(dst_y + dst_h));
+       /* Strides of Cb and Cr planes should be identical */
+       zx_writel(layer + VL_STRIDE, LUMA_STRIDE(fb->pitches[0]) |
+                 CHROMA_STRIDE(fb->pitches[1]));
+       /* Set up video layer data format */
+       fmt = zx_vl_get_fmt(format);
+       if (fmt >= 0)
+               zx_writel(layer + VL_CTRL1, fmt);
+       /* Always use scaler since it exists (set for not bypass) */
+       zx_writel_mask(layer + VL_CTRL2, VL_SCALER_BYPASS_MODE,
+                      VL_SCALER_BYPASS_MODE);
+       zx_vl_rsz_setup(zplane, format, src_w, src_h, dst_w, dst_h);
+       /* Enable HBSC block */
+       zx_writel_mask(hbsc + HBSC_CTRL0, HBSC_CTRL_EN, HBSC_CTRL_EN);
+       zx_vou_layer_enable(plane);
+       zx_vl_set_update(zplane);
+ }
+ static void zx_plane_atomic_disable(struct drm_plane *plane,
+                                   struct drm_plane_state *old_state)
+ {
+       struct zx_plane *zplane = to_zx_plane(plane);
+       void __iomem *hbsc = zplane->hbsc;
+       zx_vou_layer_disable(plane);
+       /* Disable HBSC block */
+       zx_writel_mask(hbsc + HBSC_CTRL0, HBSC_CTRL_EN, 0);
+ }
+ static const struct drm_plane_helper_funcs zx_vl_plane_helper_funcs = {
+       .atomic_check = zx_vl_plane_atomic_check,
+       .atomic_update = zx_vl_plane_atomic_update,
+       .atomic_disable = zx_plane_atomic_disable,
+ };
  static int zx_gl_plane_atomic_check(struct drm_plane *plane,
                                    struct drm_plane_state *plane_state)
  {
Simple merge