1*2874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2a269e53bSPhilipp Zabel /*
3a269e53bSPhilipp Zabel * Coda multi-standard codec IP
4a269e53bSPhilipp Zabel *
5a269e53bSPhilipp Zabel * Copyright (C) 2014 Philipp Zabel, Pengutronix
6a269e53bSPhilipp Zabel */
7a269e53bSPhilipp Zabel
8a269e53bSPhilipp Zabel #include <linux/bitops.h>
9a269e53bSPhilipp Zabel #include "coda.h"
10a269e53bSPhilipp Zabel
11a269e53bSPhilipp Zabel #define XY2_INVERT BIT(7)
12a269e53bSPhilipp Zabel #define XY2_ZERO BIT(6)
13a269e53bSPhilipp Zabel #define XY2_TB_XOR BIT(5)
14a269e53bSPhilipp Zabel #define XY2_XYSEL BIT(4)
15a269e53bSPhilipp Zabel #define XY2_Y (1 << 4)
16a269e53bSPhilipp Zabel #define XY2_X (0 << 4)
17a269e53bSPhilipp Zabel
18a269e53bSPhilipp Zabel #define XY2(luma_sel, luma_bit, chroma_sel, chroma_bit) \
19a269e53bSPhilipp Zabel (((XY2_##luma_sel) | (luma_bit)) << 8 | \
20a269e53bSPhilipp Zabel (XY2_##chroma_sel) | (chroma_bit))
21a269e53bSPhilipp Zabel
22a269e53bSPhilipp Zabel static const u16 xy2ca_zero_map[16] = {
23a269e53bSPhilipp Zabel XY2(ZERO, 0, ZERO, 0),
24a269e53bSPhilipp Zabel XY2(ZERO, 0, ZERO, 0),
25a269e53bSPhilipp Zabel XY2(ZERO, 0, ZERO, 0),
26a269e53bSPhilipp Zabel XY2(ZERO, 0, ZERO, 0),
27a269e53bSPhilipp Zabel XY2(ZERO, 0, ZERO, 0),
28a269e53bSPhilipp Zabel XY2(ZERO, 0, ZERO, 0),
29a269e53bSPhilipp Zabel XY2(ZERO, 0, ZERO, 0),
30a269e53bSPhilipp Zabel XY2(ZERO, 0, ZERO, 0),
31a269e53bSPhilipp Zabel XY2(ZERO, 0, ZERO, 0),
32a269e53bSPhilipp Zabel XY2(ZERO, 0, ZERO, 0),
33a269e53bSPhilipp Zabel XY2(ZERO, 0, ZERO, 0),
34a269e53bSPhilipp Zabel XY2(ZERO, 0, ZERO, 0),
35a269e53bSPhilipp Zabel XY2(ZERO, 0, ZERO, 0),
36a269e53bSPhilipp Zabel XY2(ZERO, 0, ZERO, 0),
37a269e53bSPhilipp Zabel XY2(ZERO, 0, ZERO, 0),
38a269e53bSPhilipp Zabel XY2(ZERO, 0, ZERO, 0),
39a269e53bSPhilipp Zabel };
40a269e53bSPhilipp Zabel
41a269e53bSPhilipp Zabel static const u16 xy2ca_tiled_map[16] = {
42a269e53bSPhilipp Zabel XY2(Y, 0, Y, 0),
43a269e53bSPhilipp Zabel XY2(Y, 1, Y, 1),
44a269e53bSPhilipp Zabel XY2(Y, 2, Y, 2),
45a269e53bSPhilipp Zabel XY2(Y, 3, X, 3),
46a269e53bSPhilipp Zabel XY2(X, 3, ZERO, 0),
47a269e53bSPhilipp Zabel XY2(ZERO, 0, ZERO, 0),
48a269e53bSPhilipp Zabel XY2(ZERO, 0, ZERO, 0),
49a269e53bSPhilipp Zabel XY2(ZERO, 0, ZERO, 0),
50a269e53bSPhilipp Zabel XY2(ZERO, 0, ZERO, 0),
51a269e53bSPhilipp Zabel XY2(ZERO, 0, ZERO, 0),
52a269e53bSPhilipp Zabel XY2(ZERO, 0, ZERO, 0),
53a269e53bSPhilipp Zabel XY2(ZERO, 0, ZERO, 0),
54a269e53bSPhilipp Zabel XY2(ZERO, 0, ZERO, 0),
55a269e53bSPhilipp Zabel XY2(ZERO, 0, ZERO, 0),
56a269e53bSPhilipp Zabel XY2(ZERO, 0, ZERO, 0),
57a269e53bSPhilipp Zabel XY2(ZERO, 0, ZERO, 0),
58a269e53bSPhilipp Zabel };
59a269e53bSPhilipp Zabel
60a269e53bSPhilipp Zabel /*
61a269e53bSPhilipp Zabel * RA[15:0], CA[15:8] are hardwired to contain the 24-bit macroblock
62a269e53bSPhilipp Zabel * start offset (macroblock size is 16x16 for luma, 16x8 for chroma).
63a269e53bSPhilipp Zabel * Bits CA[4:0] are set using XY2CA above. BA[3:0] seems to be unused.
64a269e53bSPhilipp Zabel */
65a269e53bSPhilipp Zabel
66a269e53bSPhilipp Zabel #define RBC_CA (0 << 4)
67a269e53bSPhilipp Zabel #define RBC_BA (1 << 4)
68a269e53bSPhilipp Zabel #define RBC_RA (2 << 4)
69a269e53bSPhilipp Zabel #define RBC_ZERO (3 << 4)
70a269e53bSPhilipp Zabel
71a269e53bSPhilipp Zabel #define RBC(luma_sel, luma_bit, chroma_sel, chroma_bit) \
72a269e53bSPhilipp Zabel (((RBC_##luma_sel) | (luma_bit)) << 6 | \
73a269e53bSPhilipp Zabel (RBC_##chroma_sel) | (chroma_bit))
74a269e53bSPhilipp Zabel
75a269e53bSPhilipp Zabel static const u16 rbc2axi_tiled_map[32] = {
76a269e53bSPhilipp Zabel RBC(ZERO, 0, ZERO, 0),
77a269e53bSPhilipp Zabel RBC(ZERO, 0, ZERO, 0),
78a269e53bSPhilipp Zabel RBC(ZERO, 0, ZERO, 0),
79a269e53bSPhilipp Zabel RBC(CA, 0, CA, 0),
80a269e53bSPhilipp Zabel RBC(CA, 1, CA, 1),
81a269e53bSPhilipp Zabel RBC(CA, 2, CA, 2),
82a269e53bSPhilipp Zabel RBC(CA, 3, CA, 3),
83a269e53bSPhilipp Zabel RBC(CA, 4, CA, 8),
84a269e53bSPhilipp Zabel RBC(CA, 8, CA, 9),
85a269e53bSPhilipp Zabel RBC(CA, 9, CA, 10),
86a269e53bSPhilipp Zabel RBC(CA, 10, CA, 11),
87a269e53bSPhilipp Zabel RBC(CA, 11, CA, 12),
88a269e53bSPhilipp Zabel RBC(CA, 12, CA, 13),
89a269e53bSPhilipp Zabel RBC(CA, 13, CA, 14),
90a269e53bSPhilipp Zabel RBC(CA, 14, CA, 15),
91a269e53bSPhilipp Zabel RBC(CA, 15, RA, 0),
92a269e53bSPhilipp Zabel RBC(RA, 0, RA, 1),
93a269e53bSPhilipp Zabel RBC(RA, 1, RA, 2),
94a269e53bSPhilipp Zabel RBC(RA, 2, RA, 3),
95a269e53bSPhilipp Zabel RBC(RA, 3, RA, 4),
96a269e53bSPhilipp Zabel RBC(RA, 4, RA, 5),
97a269e53bSPhilipp Zabel RBC(RA, 5, RA, 6),
98a269e53bSPhilipp Zabel RBC(RA, 6, RA, 7),
99a269e53bSPhilipp Zabel RBC(RA, 7, RA, 8),
100a269e53bSPhilipp Zabel RBC(RA, 8, RA, 9),
101a269e53bSPhilipp Zabel RBC(RA, 9, RA, 10),
102a269e53bSPhilipp Zabel RBC(RA, 10, RA, 11),
103a269e53bSPhilipp Zabel RBC(RA, 11, RA, 12),
104a269e53bSPhilipp Zabel RBC(RA, 12, RA, 13),
105a269e53bSPhilipp Zabel RBC(RA, 13, RA, 14),
106a269e53bSPhilipp Zabel RBC(RA, 14, RA, 15),
107a269e53bSPhilipp Zabel RBC(RA, 15, ZERO, 0),
108a269e53bSPhilipp Zabel };
109a269e53bSPhilipp Zabel
coda_set_gdi_regs(struct coda_ctx * ctx)110a269e53bSPhilipp Zabel void coda_set_gdi_regs(struct coda_ctx *ctx)
111a269e53bSPhilipp Zabel {
112a269e53bSPhilipp Zabel struct coda_dev *dev = ctx->dev;
113a269e53bSPhilipp Zabel const u16 *xy2ca_map;
114a269e53bSPhilipp Zabel u32 xy2rbc_config;
115a269e53bSPhilipp Zabel int i;
116a269e53bSPhilipp Zabel
117a269e53bSPhilipp Zabel switch (ctx->tiled_map_type) {
118a269e53bSPhilipp Zabel case GDI_LINEAR_FRAME_MAP:
119a269e53bSPhilipp Zabel default:
120a269e53bSPhilipp Zabel xy2ca_map = xy2ca_zero_map;
121a269e53bSPhilipp Zabel xy2rbc_config = 0;
122a269e53bSPhilipp Zabel break;
123a269e53bSPhilipp Zabel case GDI_TILED_FRAME_MB_RASTER_MAP:
124a269e53bSPhilipp Zabel xy2ca_map = xy2ca_tiled_map;
125a269e53bSPhilipp Zabel xy2rbc_config = CODA9_XY2RBC_TILED_MAP |
126a269e53bSPhilipp Zabel CODA9_XY2RBC_CA_INC_HOR |
127a269e53bSPhilipp Zabel (16 - 1) << 12 | (8 - 1) << 4;
128a269e53bSPhilipp Zabel break;
129a269e53bSPhilipp Zabel }
130a269e53bSPhilipp Zabel
131a269e53bSPhilipp Zabel for (i = 0; i < 16; i++)
132a269e53bSPhilipp Zabel coda_write(dev, xy2ca_map[i],
133a269e53bSPhilipp Zabel CODA9_GDI_XY2_CAS_0 + 4 * i);
134a269e53bSPhilipp Zabel for (i = 0; i < 4; i++)
135a269e53bSPhilipp Zabel coda_write(dev, XY2(ZERO, 0, ZERO, 0),
136a269e53bSPhilipp Zabel CODA9_GDI_XY2_BA_0 + 4 * i);
137a269e53bSPhilipp Zabel for (i = 0; i < 16; i++)
138a269e53bSPhilipp Zabel coda_write(dev, XY2(ZERO, 0, ZERO, 0),
139a269e53bSPhilipp Zabel CODA9_GDI_XY2_RAS_0 + 4 * i);
140a269e53bSPhilipp Zabel coda_write(dev, xy2rbc_config, CODA9_GDI_XY2_RBC_CONFIG);
141a269e53bSPhilipp Zabel if (xy2rbc_config) {
142a269e53bSPhilipp Zabel for (i = 0; i < 32; i++)
143a269e53bSPhilipp Zabel coda_write(dev, rbc2axi_tiled_map[i],
144a269e53bSPhilipp Zabel CODA9_GDI_RBC2_AXI_0 + 4 * i);
145a269e53bSPhilipp Zabel }
146a269e53bSPhilipp Zabel }
147