ca0124bab77fcc4d41562ae62da5fde6dfbdc147
[oweals/openwrt.git] /
1 From 5edffe06ee9b72d3fb56853d0652dd9cdc02e44d Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.org>
3 Date: Mon, 24 Jun 2019 02:29:40 +0100
4 Subject: [PATCH 682/703] drm/vc4: Add support for color encoding on YUV planes
5
6 Adds signalling for BT601/709/2020, and limited/full range
7 (on BT601).
8
9 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
10 ---
11  drivers/gpu/drm/vc4/vc4_firmware_kms.c | 32 +++++++++++++++++++++++++-
12  drivers/gpu/drm/vc4/vc_image_types.h   | 28 ++++++++++++++++++++++
13  2 files changed, 59 insertions(+), 1 deletion(-)
14
15 --- a/drivers/gpu/drm/vc4/vc4_firmware_kms.c
16 +++ b/drivers/gpu/drm/vc4/vc4_firmware_kms.c
17 @@ -66,7 +66,7 @@ struct set_plane {
18         u8 alpha;
19         u8 num_planes;
20         u8 is_vu;
21 -       u8 padding;
22 +       u8 color_encoding;
23  
24         u32 planes[4];  /* DMA address of each plane */
25  
26 @@ -454,6 +454,28 @@ static void vc4_plane_atomic_update(stru
27                 if (num_planes == 3 &&
28                     (fb->offsets[2] - fb->offsets[1]) == fb->pitches[1])
29                         mb->plane.vc_image_type = VC_IMAGE_YUV420_S;
30 +
31 +               switch (state->color_encoding) {
32 +               default:
33 +               case DRM_COLOR_YCBCR_BT601:
34 +                       if (state->color_range == DRM_COLOR_YCBCR_LIMITED_RANGE)
35 +                               mb->plane.color_encoding =
36 +                                               VC_IMAGE_YUVINFO_CSC_ITUR_BT601;
37 +                       else
38 +                               mb->plane.color_encoding =
39 +                                               VC_IMAGE_YUVINFO_CSC_JPEG_JFIF;
40 +                       break;
41 +               case DRM_COLOR_YCBCR_BT709:
42 +                       /* Currently no support for a full range BT709 */
43 +                       mb->plane.color_encoding =
44 +                                               VC_IMAGE_YUVINFO_CSC_ITUR_BT709;
45 +                       break;
46 +               case DRM_COLOR_YCBCR_BT2020:
47 +                       /* Currently no support for a full range BT2020 */
48 +                       mb->plane.color_encoding =
49 +                                       VC_IMAGE_YUVINFO_CSC_REC_2020;
50 +                       break;
51 +               }
52         } else {
53                 mb->plane.planes[1] = 0;
54                 mb->plane.planes[2] = 0;
55 @@ -643,6 +665,14 @@ static struct drm_plane *vc4_fkms_plane_
56         drm_plane_create_alpha_property(plane);
57         drm_plane_create_rotation_property(plane, DRM_MODE_ROTATE_0,
58                                            SUPPORTED_ROTATIONS);
59 +       drm_plane_create_color_properties(plane,
60 +                                         BIT(DRM_COLOR_YCBCR_BT601) |
61 +                                         BIT(DRM_COLOR_YCBCR_BT709) |
62 +                                         BIT(DRM_COLOR_YCBCR_BT2020),
63 +                                         BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) |
64 +                                         BIT(DRM_COLOR_YCBCR_FULL_RANGE),
65 +                                         DRM_COLOR_YCBCR_BT709,
66 +                                         DRM_COLOR_YCBCR_LIMITED_RANGE);
67  
68         /*
69          * Default frame buffer setup is with FB on -127, and raspistill etc
70 --- a/drivers/gpu/drm/vc4/vc_image_types.h
71 +++ b/drivers/gpu/drm/vc4/vc_image_types.h
72 @@ -4,6 +4,8 @@
73   *
74   * Values taken from vc_image_types.h released by Broadcom at
75   * https://github.com/raspberrypi/userland/blob/master/interface/vctypes/vc_image_types.h
76 + * and vc_image_structs.h at
77 + * https://github.com/raspberrypi/userland/blob/master/interface/vctypes/vc_image_structs.h
78   *
79   * This program is free software; you can redistribute it and/or modify
80   * it under the terms of the GNU General Public License version 2 as
81 @@ -141,3 +143,29 @@ enum {
82         VC_IMAGE_MAX,     /* bounds for error checking */
83         VC_IMAGE_FORCE_ENUM_16BIT = 0xffff,
84  };
85 +
86 +enum {
87 +       /* Unknown or unset - defaults to BT601 interstitial */
88 +       VC_IMAGE_YUVINFO_UNSPECIFIED    = 0,
89 +
90 +       /* colour-space conversions data [4 bits] */
91 +
92 +       /* ITU-R BT.601-5 [SDTV] (compatible with VideoCore-II) */
93 +       VC_IMAGE_YUVINFO_CSC_ITUR_BT601      = 1,
94 +       /* ITU-R BT.709-3 [HDTV] */
95 +       VC_IMAGE_YUVINFO_CSC_ITUR_BT709      = 2,
96 +       /* JPEG JFIF */
97 +       VC_IMAGE_YUVINFO_CSC_JPEG_JFIF       = 3,
98 +       /* Title 47 Code of Federal Regulations (2003) 73.682 (a) (20) */
99 +       VC_IMAGE_YUVINFO_CSC_FCC             = 4,
100 +       /* Society of Motion Picture and Television Engineers 240M (1999) */
101 +       VC_IMAGE_YUVINFO_CSC_SMPTE_240M      = 5,
102 +       /* ITU-R BT.470-2 System M */
103 +       VC_IMAGE_YUVINFO_CSC_ITUR_BT470_2_M  = 6,
104 +       /* ITU-R BT.470-2 System B,G */
105 +       VC_IMAGE_YUVINFO_CSC_ITUR_BT470_2_BG = 7,
106 +       /* JPEG JFIF, but with 16..255 luma */
107 +       VC_IMAGE_YUVINFO_CSC_JPEG_JFIF_Y16_255 = 8,
108 +       /* Rec 2020 */
109 +       VC_IMAGE_YUVINFO_CSC_REC_2020        = 9,
110 +};