blob: 2bc9327e1e2b06b5da87b9e107703f9ff300ccb8 [file] [log] [blame]
Neil Armstrongadd986c2018-07-24 17:45:28 +02001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Amlogic Meson Video Processing Unit driver
4 *
5 * Copyright (c) 2018 BayLibre, SAS.
6 * Author: Neil Armstrong <narmstrong@baylibre.com>
7 */
8
9#include "meson_vpu.h"
10
11/* OSDx_BLKx_CFG */
12#define OSD_CANVAS_SEL 16
13
14#define OSD_ENDIANNESS_LE BIT(15)
15#define OSD_ENDIANNESS_BE (0)
16
17#define OSD_BLK_MODE_422 (0x03 << 8)
18#define OSD_BLK_MODE_16 (0x04 << 8)
19#define OSD_BLK_MODE_32 (0x05 << 8)
20#define OSD_BLK_MODE_24 (0x07 << 8)
21
22#define OSD_OUTPUT_COLOR_RGB BIT(7)
23#define OSD_OUTPUT_COLOR_YUV (0)
24
25#define OSD_COLOR_MATRIX_32_RGBA (0x00 << 2)
26#define OSD_COLOR_MATRIX_32_ARGB (0x01 << 2)
27#define OSD_COLOR_MATRIX_32_ABGR (0x02 << 2)
28#define OSD_COLOR_MATRIX_32_BGRA (0x03 << 2)
29
30#define OSD_COLOR_MATRIX_24_RGB (0x00 << 2)
31
32#define OSD_COLOR_MATRIX_16_RGB655 (0x00 << 2)
33#define OSD_COLOR_MATRIX_16_RGB565 (0x04 << 2)
34
35#define OSD_INTERLACE_ENABLED BIT(1)
36#define OSD_INTERLACE_ODD BIT(0)
37#define OSD_INTERLACE_EVEN (0)
38
39/* OSDx_CTRL_STAT */
40#define OSD_ENABLE BIT(21)
41#define OSD_BLK0_ENABLE BIT(0)
42
43#define OSD_GLOBAL_ALPHA_SHIFT 12
44
45/* OSDx_CTRL_STAT2 */
46#define OSD_REPLACE_EN BIT(14)
47#define OSD_REPLACE_SHIFT 6
48
49/*
50 * When the output is interlaced, the OSD must switch between
51 * each field using the INTERLACE_SEL_ODD (0) of VIU_OSD1_BLK0_CFG_W0
52 * at each vsync.
53 * But the vertical scaler can provide such funtionnality if
54 * is configured for 2:1 scaling with interlace options enabled.
55 */
56static void meson_vpp_setup_interlace_vscaler_osd1(struct meson_vpu_priv *priv,
57 struct video_priv *uc_priv)
58{
59 writel(BIT(3) /* Enable scaler */ |
60 BIT(2), /* Select OSD1 */
61 priv->io_base + _REG(VPP_OSD_SC_CTRL0));
62
63 writel(((uc_priv->xsize - 1) << 16) | (uc_priv->ysize - 1),
64 priv->io_base + _REG(VPP_OSD_SCI_WH_M1));
65 /* 2:1 scaling */
66 writel((0 << 16) | uc_priv->xsize,
67 priv->io_base + _REG(VPP_OSD_SCO_H_START_END));
68 writel(((0 >> 1) << 16) | (uc_priv->ysize >> 1),
69 priv->io_base + _REG(VPP_OSD_SCO_V_START_END));
70
71 /* 2:1 scaling values */
72 writel(BIT(16), priv->io_base + _REG(VPP_OSD_VSC_INI_PHASE));
73 writel(BIT(25), priv->io_base + _REG(VPP_OSD_VSC_PHASE_STEP));
74
75 writel(0, priv->io_base + _REG(VPP_OSD_HSC_CTRL0));
76
77 writel((4 << 0) /* osd_vsc_bank_length */ |
78 (4 << 3) /* osd_vsc_top_ini_rcv_num0 */ |
79 (1 << 8) /* osd_vsc_top_rpt_p0_num0 */ |
80 (6 << 11) /* osd_vsc_bot_ini_rcv_num0 */ |
81 (2 << 16) /* osd_vsc_bot_rpt_p0_num0 */ |
82 BIT(23) /* osd_prog_interlace */ |
83 BIT(24), /* Enable vertical scaler */
84 priv->io_base + _REG(VPP_OSD_VSC_CTRL0));
85}
86
87static void
88meson_vpp_disable_interlace_vscaler_osd1(struct meson_vpu_priv *priv)
89{
90 writel(0, priv->io_base + _REG(VPP_OSD_SC_CTRL0));
91 writel(0, priv->io_base + _REG(VPP_OSD_VSC_CTRL0));
92 writel(0, priv->io_base + _REG(VPP_OSD_HSC_CTRL0));
93}
94
95void meson_vpu_setup_plane(struct udevice *dev, bool is_interlaced)
96{
97 struct video_uc_platdata *uc_plat = dev_get_uclass_platdata(dev);
98 struct video_priv *uc_priv = dev_get_uclass_priv(dev);
99 struct meson_vpu_priv *priv = dev_get_priv(dev);
100 u32 osd1_ctrl_stat;
101 u32 osd1_blk0_cfg[5];
102 bool osd1_interlace;
103 unsigned int src_x1, src_x2, src_y1, src_y2;
104 unsigned int dest_x1, dest_x2, dest_y1, dest_y2;
105
106 dest_x1 = src_x1 = 0;
107 dest_x2 = src_x2 = uc_priv->xsize;
108 dest_y1 = src_y1 = 0;
109 dest_y2 = src_y2 = uc_priv->ysize;
110
Neil Armstrong57d6dfe2019-08-30 14:09:24 +0200111 if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) {
112 /* VD1 Preblend vertical start/end */
113 writel(FIELD_PREP(GENMASK(11, 0), 2303),
114 priv->io_base + _REG(VPP_PREBLEND_VD1_V_START_END));
Neil Armstrongadd986c2018-07-24 17:45:28 +0200115
Neil Armstrong57d6dfe2019-08-30 14:09:24 +0200116 /* Setup Blender */
117 writel(uc_priv->xsize |
118 uc_priv->ysize << 16,
119 priv->io_base + _REG(VPP_POSTBLEND_H_SIZE));
120
121 writel(0 << 16 |
122 (uc_priv->xsize - 1),
123 priv->io_base + _REG(VPP_OSD1_BLD_H_SCOPE));
124 writel(0 << 16 |
125 (uc_priv->ysize - 1),
126 priv->io_base + _REG(VPP_OSD1_BLD_V_SCOPE));
127 writel(uc_priv->xsize << 16 |
128 uc_priv->ysize,
129 priv->io_base + _REG(VPP_OUT_H_V_SIZE));
130 } else {
131 /* Enable VPP Postblend */
132 writel(uc_priv->xsize,
133 priv->io_base + _REG(VPP_POSTBLEND_H_SIZE));
134
135 writel_bits(VPP_POSTBLEND_ENABLE, VPP_POSTBLEND_ENABLE,
136 priv->io_base + _REG(VPP_MISC));
137 }
Neil Armstrongadd986c2018-07-24 17:45:28 +0200138
139 /* uc_plat->base is the framebuffer */
140
141 /* Enable OSD and BLK0, set max global alpha */
142 osd1_ctrl_stat = OSD_ENABLE | (0xFF << OSD_GLOBAL_ALPHA_SHIFT) |
143 OSD_BLK0_ENABLE;
144
145 /* Set up BLK0 to point to the right canvas */
146 osd1_blk0_cfg[0] = ((MESON_CANVAS_ID_OSD1 << OSD_CANVAS_SEL) |
147 OSD_ENDIANNESS_LE);
148
149 /* On GXBB, Use the old non-HDR RGB2YUV converter */
150 if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXBB))
151 osd1_blk0_cfg[0] |= OSD_OUTPUT_COLOR_RGB;
152
153 /* For XRGB, replace the pixel's alpha by 0xFF */
154 writel_bits(OSD_REPLACE_EN, OSD_REPLACE_EN,
155 priv->io_base + _REG(VIU_OSD1_CTRL_STAT2));
156 osd1_blk0_cfg[0] |= OSD_BLK_MODE_32 |
157 OSD_COLOR_MATRIX_32_ARGB;
158
159 if (is_interlaced) {
160 osd1_interlace = true;
161 dest_y1 /= 2;
162 dest_y2 /= 2;
163 } else {
164 osd1_interlace = false;
165 }
166
167 /*
168 * The format of these registers is (x2 << 16 | x1),
169 * where x2 is exclusive.
170 * e.g. +30x1920 would be (1919 << 16) | 30
171 */
172 osd1_blk0_cfg[1] = ((src_x2 - 1) << 16) | src_x1;
173 osd1_blk0_cfg[2] = ((src_y2 - 1) << 16) | src_y1;
174 osd1_blk0_cfg[3] = ((dest_x2 - 1) << 16) | dest_x1;
175 osd1_blk0_cfg[4] = ((dest_y2 - 1) << 16) | dest_y1;
176
177 writel(osd1_ctrl_stat, priv->io_base + _REG(VIU_OSD1_CTRL_STAT));
178 writel(osd1_blk0_cfg[0], priv->io_base + _REG(VIU_OSD1_BLK0_CFG_W0));
179 writel(osd1_blk0_cfg[1], priv->io_base + _REG(VIU_OSD1_BLK0_CFG_W1));
180 writel(osd1_blk0_cfg[2], priv->io_base + _REG(VIU_OSD1_BLK0_CFG_W2));
181 writel(osd1_blk0_cfg[3], priv->io_base + _REG(VIU_OSD1_BLK0_CFG_W3));
182 writel(osd1_blk0_cfg[4], priv->io_base + _REG(VIU_OSD1_BLK0_CFG_W4));
183
184 /* If output is interlace, make use of the Scaler */
185 if (osd1_interlace)
186 meson_vpp_setup_interlace_vscaler_osd1(priv, uc_priv);
187 else
188 meson_vpp_disable_interlace_vscaler_osd1(priv);
189
190 meson_canvas_setup(priv, MESON_CANVAS_ID_OSD1,
191 uc_plat->base, uc_priv->xsize * 4,
192 uc_priv->ysize, MESON_CANVAS_WRAP_NONE,
193 MESON_CANVAS_BLKMODE_LINEAR);
194
195 /* Enable OSD1 */
Neil Armstrong57d6dfe2019-08-30 14:09:24 +0200196 if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) {
197 writel(((dest_x2 - 1) << 16) | dest_x1,
198 priv->io_base + _REG(VIU_OSD_BLEND_DIN0_SCOPE_H));
199 writel(((dest_y2 - 1) << 16) | dest_y1,
200 priv->io_base + _REG(VIU_OSD_BLEND_DIN0_SCOPE_V));
201 writel(uc_priv->xsize << 16 | uc_priv->ysize,
202 priv->io_base + _REG(VIU_OSD_BLEND_BLEND0_SIZE));
203 writel(uc_priv->xsize << 16 | uc_priv->ysize,
204 priv->io_base + _REG(VIU_OSD_BLEND_BLEND1_SIZE));
205 writel_bits(3 << 8, 3 << 8,
206 priv->io_base + _REG(OSD1_BLEND_SRC_CTRL));
207 } else
208 writel_bits(VPP_OSD1_POSTBLEND, VPP_OSD1_POSTBLEND,
209 priv->io_base + _REG(VPP_MISC));
Neil Armstrongadd986c2018-07-24 17:45:28 +0200210}