bcm27xx: add kernel 5.10 support
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.10 / 950-0702-drm-vc4-Add-support-for-more-analog-TV-standards.patch
1 From 6eca6c329b247adab647f1d4b380cd630f923806 Mon Sep 17 00:00:00 2001
2 From: Mateusz Kwiatkowski <kfyatek+publicgit@gmail.com>
3 Date: Thu, 15 Jul 2021 01:07:58 +0200
4 Subject: [PATCH] drm/vc4: Add support for more analog TV standards
5
6 Add support for the following composite output modes (all of them are
7 somewhat more obscure than the previously defined ones):
8
9 - NTSC_443 - NTSC-style signal with the chroma subcarrier shifted to
10 4.43361875 MHz (the PAL subcarrier frequency). Never used for
11 broadcasting, but sometimes used as a hack to play NTSC content in PAL
12 regions (e.g. on VCRs).
13 - PAL_N - PAL with alternative chroma subcarrier frequency,
14 3.58205625 MHz. Used as a broadcast standard in Argentina, Paraguay
15 and Uruguay to fit 576i50 with colour in 6 MHz channel raster.
16 - PAL60 - 480i60 signal with PAL-style color at normal European PAL
17 frequency. Another non-standard, non-broadcast mode, used in similar
18 contexts as NTSC_443. Some displays support one but not the other.
19 - SECAM - French frequency-modulated analog color standard; also have
20 been broadcast in Eastern Europe and various parts of Africa and Asia.
21 Uses the same 576i50 timings as PAL.
22
23 Also added some comments explaining color subcarrier frequency
24 registers.
25
26 Signed-off-by: Mateusz Kwiatkowski <kfyatek+publicgit@gmail.com>
27 ---
28 drivers/gpu/drm/vc4/vc4_vec.c | 63 +++++++++++++++++++++++++++++++++++
29 1 file changed, 63 insertions(+)
30
31 --- a/drivers/gpu/drm/vc4/vc4_vec.c
32 +++ b/drivers/gpu/drm/vc4/vc4_vec.c
33 @@ -45,6 +45,7 @@
34 #define VEC_CONFIG0_YDEL(x) ((x) << 26)
35 #define VEC_CONFIG0_CDEL_MASK GENMASK(25, 24)
36 #define VEC_CONFIG0_CDEL(x) ((x) << 24)
37 +#define VEC_CONFIG0_SECAM_STD BIT(21)
38 #define VEC_CONFIG0_PBPR_FIL BIT(18)
39 #define VEC_CONFIG0_CHROMA_GAIN_MASK GENMASK(17, 16)
40 #define VEC_CONFIG0_CHROMA_GAIN_UNITY (0 << 16)
41 @@ -75,6 +76,27 @@
42 #define VEC_SOFT_RESET 0x10c
43 #define VEC_CLMP0_START 0x144
44 #define VEC_CLMP0_END 0x148
45 +
46 +/*
47 + * These set the color subcarrier frequency
48 + * if VEC_CONFIG1_CUSTOM_FREQ is enabled.
49 + *
50 + * VEC_FREQ1_0 contains the most significant 16-bit half-word,
51 + * VEC_FREQ3_2 contains the least significant 16-bit half-word.
52 + * 0x80000000 seems to be equivalent to the pixel clock
53 + * (which itself is the VEC clock divided by 8).
54 + *
55 + * Reference values (with the default pixel clock of 13.5 MHz):
56 + *
57 + * NTSC (3579545.[45] Hz) - 0x21F07C1F
58 + * PAL (4433618.75 Hz) - 0x2A098ACB
59 + * PAL-M (3575611.[888111] Hz) - 0x21E6EFE3
60 + * PAL-N (3582056.25 Hz) - 0x21F69446
61 + *
62 + * NOTE: For SECAM, it is used as the Dr center frequency,
63 + * regardless of whether VEC_CONFIG1_CUSTOM_FREQ is enabled or not;
64 + * that is specified as 4406250 Hz, which corresponds to 0x29C71C72.
65 + */
66 #define VEC_FREQ3_2 0x180
67 #define VEC_FREQ1_0 0x184
68
69 @@ -117,6 +139,14 @@
70
71 #define VEC_INTERRUPT_CONTROL 0x190
72 #define VEC_INTERRUPT_STATUS 0x194
73 +
74 +/*
75 + * Db center frequency for SECAM; the clock for this is the same as for
76 + * VEC_FREQ3_2/VEC_FREQ1_0, which is used for Dr center frequency.
77 + *
78 + * This is specified as 4250000 Hz, which corresponds to 0x284BDA13.
79 + * That is also the default value, so no need to set it explicitly.
80 + */
81 #define VEC_FCW_SECAM_B 0x198
82 #define VEC_SECAM_GAIN_VAL 0x19c
83
84 @@ -210,8 +240,12 @@ to_vc4_vec_connector(struct drm_connecto
85 enum vc4_vec_tv_mode_id {
86 VC4_VEC_TV_MODE_NTSC,
87 VC4_VEC_TV_MODE_NTSC_J,
88 + VC4_VEC_TV_MODE_NTSC_443,
89 VC4_VEC_TV_MODE_PAL,
90 VC4_VEC_TV_MODE_PAL_M,
91 + VC4_VEC_TV_MODE_PAL_N,
92 + VC4_VEC_TV_MODE_PAL60,
93 + VC4_VEC_TV_MODE_SECAM,
94 };
95
96 struct vc4_vec_tv_mode {
97 @@ -273,6 +307,13 @@ static const struct vc4_vec_tv_mode vc4_
98 .config0 = VEC_CONFIG0_NTSC_STD,
99 .config1 = VEC_CONFIG1_C_CVBS_CVBS,
100 },
101 + [VC4_VEC_TV_MODE_NTSC_443] = {
102 + /* NTSC with PAL chroma frequency */
103 + .mode = &drm_mode_480i,
104 + .config0 = VEC_CONFIG0_NTSC_STD,
105 + .config1 = VEC_CONFIG1_C_CVBS_CVBS | VEC_CONFIG1_CUSTOM_FREQ,
106 + .custom_freq = 0x2a098acb,
107 + },
108 [VC4_VEC_TV_MODE_PAL] = {
109 .mode = &drm_mode_576i,
110 .config0 = VEC_CONFIG0_PAL_BDGHI_STD,
111 @@ -283,6 +324,24 @@ static const struct vc4_vec_tv_mode vc4_
112 .config0 = VEC_CONFIG0_PAL_M_STD,
113 .config1 = VEC_CONFIG1_C_CVBS_CVBS,
114 },
115 + [VC4_VEC_TV_MODE_PAL_N] = {
116 + .mode = &drm_mode_576i,
117 + .config0 = VEC_CONFIG0_PAL_N_STD,
118 + .config1 = VEC_CONFIG1_C_CVBS_CVBS,
119 + },
120 + [VC4_VEC_TV_MODE_PAL60] = {
121 + /* PAL-M with chroma frequency of regular PAL */
122 + .mode = &drm_mode_480i,
123 + .config0 = VEC_CONFIG0_PAL_M_STD,
124 + .config1 = VEC_CONFIG1_C_CVBS_CVBS | VEC_CONFIG1_CUSTOM_FREQ,
125 + .custom_freq = 0x2a098acb,
126 + },
127 + [VC4_VEC_TV_MODE_SECAM] = {
128 + .mode = &drm_mode_576i,
129 + .config0 = VEC_CONFIG0_SECAM_STD,
130 + .config1 = VEC_CONFIG1_C_CVBS_CVBS,
131 + .custom_freq = 0x29c71c72,
132 + },
133 };
134
135 static enum drm_connector_status
136 @@ -505,8 +564,12 @@ static const struct of_device_id vc4_vec
137 static const char * const tv_mode_names[] = {
138 [VC4_VEC_TV_MODE_NTSC] = "NTSC",
139 [VC4_VEC_TV_MODE_NTSC_J] = "NTSC-J",
140 + [VC4_VEC_TV_MODE_NTSC_443] = "NTSC-443",
141 [VC4_VEC_TV_MODE_PAL] = "PAL",
142 [VC4_VEC_TV_MODE_PAL_M] = "PAL-M",
143 + [VC4_VEC_TV_MODE_PAL_N] = "PAL-N",
144 + [VC4_VEC_TV_MODE_PAL60] = "PAL60",
145 + [VC4_VEC_TV_MODE_SECAM] = "SECAM",
146 };
147
148 static int vc4_vec_bind(struct device *dev, struct device *master, void *data)