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