xref: /OK3568_Linux_fs/kernel/drivers/media/platform/sti/bdisp/bdisp-hw.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright (C) STMicroelectronics SA 2014
4*4882a593Smuzhiyun  * Authors: Fabien Dessenne <fabien.dessenne@st.com> for STMicroelectronics.
5*4882a593Smuzhiyun  */
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun #include <linux/delay.h>
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #include "bdisp.h"
10*4882a593Smuzhiyun #include "bdisp-filter.h"
11*4882a593Smuzhiyun #include "bdisp-reg.h"
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun /* Max width of the source frame in a single node */
14*4882a593Smuzhiyun #define MAX_SRC_WIDTH           2048
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun /* Reset & boot poll config */
17*4882a593Smuzhiyun #define POLL_RST_MAX            500
18*4882a593Smuzhiyun #define POLL_RST_DELAY_MS       2
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun enum bdisp_target_plan {
21*4882a593Smuzhiyun 	BDISP_RGB,
22*4882a593Smuzhiyun 	BDISP_Y,
23*4882a593Smuzhiyun 	BDISP_CBCR
24*4882a593Smuzhiyun };
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun struct bdisp_op_cfg {
27*4882a593Smuzhiyun 	bool cconv;          /* RGB - YUV conversion */
28*4882a593Smuzhiyun 	bool hflip;          /* Horizontal flip */
29*4882a593Smuzhiyun 	bool vflip;          /* Vertical flip */
30*4882a593Smuzhiyun 	bool wide;           /* Wide (>MAX_SRC_WIDTH) */
31*4882a593Smuzhiyun 	bool scale;          /* Scale */
32*4882a593Smuzhiyun 	u16  h_inc;          /* Horizontal increment in 6.10 format */
33*4882a593Smuzhiyun 	u16  v_inc;          /* Vertical increment in 6.10 format */
34*4882a593Smuzhiyun 	bool src_interlaced; /* is the src an interlaced buffer */
35*4882a593Smuzhiyun 	u8   src_nbp;        /* nb of planes of the src */
36*4882a593Smuzhiyun 	bool src_yuv;        /* is the src a YUV color format */
37*4882a593Smuzhiyun 	bool src_420;        /* is the src 4:2:0 chroma subsampled */
38*4882a593Smuzhiyun 	u8   dst_nbp;        /* nb of planes of the dst */
39*4882a593Smuzhiyun 	bool dst_yuv;        /* is the dst a YUV color format */
40*4882a593Smuzhiyun 	bool dst_420;        /* is the dst 4:2:0 chroma subsampled */
41*4882a593Smuzhiyun };
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun struct bdisp_filter_addr {
44*4882a593Smuzhiyun 	u16 min;             /* Filter min scale factor (6.10 fixed point) */
45*4882a593Smuzhiyun 	u16 max;             /* Filter max scale factor (6.10 fixed point) */
46*4882a593Smuzhiyun 	void *virt;          /* Virtual address for filter table */
47*4882a593Smuzhiyun 	dma_addr_t paddr;    /* Physical address for filter table */
48*4882a593Smuzhiyun };
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun static const struct bdisp_filter_h_spec bdisp_h_spec[] = {
51*4882a593Smuzhiyun 	{
52*4882a593Smuzhiyun 		.min = 0,
53*4882a593Smuzhiyun 		.max = 921,
54*4882a593Smuzhiyun 		.coef = {
55*4882a593Smuzhiyun 			0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
56*4882a593Smuzhiyun 			0x00, 0x00, 0xff, 0x07, 0x3d, 0xfc, 0x01, 0x00,
57*4882a593Smuzhiyun 			0x00, 0x01, 0xfd, 0x11, 0x36, 0xf9, 0x02, 0x00,
58*4882a593Smuzhiyun 			0x00, 0x01, 0xfb, 0x1b, 0x2e, 0xf9, 0x02, 0x00,
59*4882a593Smuzhiyun 			0x00, 0x01, 0xf9, 0x26, 0x26, 0xf9, 0x01, 0x00,
60*4882a593Smuzhiyun 			0x00, 0x02, 0xf9, 0x30, 0x19, 0xfb, 0x01, 0x00,
61*4882a593Smuzhiyun 			0x00, 0x02, 0xf9, 0x39, 0x0e, 0xfd, 0x01, 0x00,
62*4882a593Smuzhiyun 			0x00, 0x01, 0xfc, 0x3e, 0x06, 0xff, 0x00, 0x00
63*4882a593Smuzhiyun 		}
64*4882a593Smuzhiyun 	},
65*4882a593Smuzhiyun 	{
66*4882a593Smuzhiyun 		.min = 921,
67*4882a593Smuzhiyun 		.max = 1024,
68*4882a593Smuzhiyun 		.coef = {
69*4882a593Smuzhiyun 			0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
70*4882a593Smuzhiyun 			0xff, 0x03, 0xfd, 0x08, 0x3e, 0xf9, 0x04, 0xfe,
71*4882a593Smuzhiyun 			0xfd, 0x06, 0xf8, 0x13, 0x3b, 0xf4, 0x07, 0xfc,
72*4882a593Smuzhiyun 			0xfb, 0x08, 0xf5, 0x1f, 0x34, 0xf1, 0x09, 0xfb,
73*4882a593Smuzhiyun 			0xfb, 0x09, 0xf2, 0x2b, 0x2a, 0xf1, 0x09, 0xfb,
74*4882a593Smuzhiyun 			0xfb, 0x09, 0xf2, 0x35, 0x1e, 0xf4, 0x08, 0xfb,
75*4882a593Smuzhiyun 			0xfc, 0x07, 0xf5, 0x3c, 0x12, 0xf7, 0x06, 0xfd,
76*4882a593Smuzhiyun 			0xfe, 0x04, 0xfa, 0x3f, 0x07, 0xfc, 0x03, 0xff
77*4882a593Smuzhiyun 		}
78*4882a593Smuzhiyun 	},
79*4882a593Smuzhiyun 	{
80*4882a593Smuzhiyun 		.min = 1024,
81*4882a593Smuzhiyun 		.max = 1126,
82*4882a593Smuzhiyun 		.coef = {
83*4882a593Smuzhiyun 			0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
84*4882a593Smuzhiyun 			0xff, 0x03, 0xfd, 0x08, 0x3e, 0xf9, 0x04, 0xfe,
85*4882a593Smuzhiyun 			0xfd, 0x06, 0xf8, 0x13, 0x3b, 0xf4, 0x07, 0xfc,
86*4882a593Smuzhiyun 			0xfb, 0x08, 0xf5, 0x1f, 0x34, 0xf1, 0x09, 0xfb,
87*4882a593Smuzhiyun 			0xfb, 0x09, 0xf2, 0x2b, 0x2a, 0xf1, 0x09, 0xfb,
88*4882a593Smuzhiyun 			0xfb, 0x09, 0xf2, 0x35, 0x1e, 0xf4, 0x08, 0xfb,
89*4882a593Smuzhiyun 			0xfc, 0x07, 0xf5, 0x3c, 0x12, 0xf7, 0x06, 0xfd,
90*4882a593Smuzhiyun 			0xfe, 0x04, 0xfa, 0x3f, 0x07, 0xfc, 0x03, 0xff
91*4882a593Smuzhiyun 		}
92*4882a593Smuzhiyun 	},
93*4882a593Smuzhiyun 	{
94*4882a593Smuzhiyun 		.min = 1126,
95*4882a593Smuzhiyun 		.max = 1228,
96*4882a593Smuzhiyun 		.coef = {
97*4882a593Smuzhiyun 			0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
98*4882a593Smuzhiyun 			0xff, 0x03, 0xfd, 0x08, 0x3e, 0xf9, 0x04, 0xfe,
99*4882a593Smuzhiyun 			0xfd, 0x06, 0xf8, 0x13, 0x3b, 0xf4, 0x07, 0xfc,
100*4882a593Smuzhiyun 			0xfb, 0x08, 0xf5, 0x1f, 0x34, 0xf1, 0x09, 0xfb,
101*4882a593Smuzhiyun 			0xfb, 0x09, 0xf2, 0x2b, 0x2a, 0xf1, 0x09, 0xfb,
102*4882a593Smuzhiyun 			0xfb, 0x09, 0xf2, 0x35, 0x1e, 0xf4, 0x08, 0xfb,
103*4882a593Smuzhiyun 			0xfc, 0x07, 0xf5, 0x3c, 0x12, 0xf7, 0x06, 0xfd,
104*4882a593Smuzhiyun 			0xfe, 0x04, 0xfa, 0x3f, 0x07, 0xfc, 0x03, 0xff
105*4882a593Smuzhiyun 		}
106*4882a593Smuzhiyun 	},
107*4882a593Smuzhiyun 	{
108*4882a593Smuzhiyun 		.min = 1228,
109*4882a593Smuzhiyun 		.max = 1331,
110*4882a593Smuzhiyun 		.coef = {
111*4882a593Smuzhiyun 			0xfd, 0x04, 0xfc, 0x05, 0x39, 0x05, 0xfc, 0x04,
112*4882a593Smuzhiyun 			0xfc, 0x06, 0xf9, 0x0c, 0x39, 0xfe, 0x00, 0x02,
113*4882a593Smuzhiyun 			0xfb, 0x08, 0xf6, 0x17, 0x35, 0xf9, 0x02, 0x00,
114*4882a593Smuzhiyun 			0xfc, 0x08, 0xf4, 0x20, 0x30, 0xf4, 0x05, 0xff,
115*4882a593Smuzhiyun 			0xfd, 0x07, 0xf4, 0x29, 0x28, 0xf3, 0x07, 0xfd,
116*4882a593Smuzhiyun 			0xff, 0x05, 0xf5, 0x31, 0x1f, 0xf3, 0x08, 0xfc,
117*4882a593Smuzhiyun 			0x00, 0x02, 0xf9, 0x38, 0x14, 0xf6, 0x08, 0xfb,
118*4882a593Smuzhiyun 			0x02, 0x00, 0xff, 0x3a, 0x0b, 0xf8, 0x06, 0xfc
119*4882a593Smuzhiyun 		}
120*4882a593Smuzhiyun 	},
121*4882a593Smuzhiyun 	{
122*4882a593Smuzhiyun 		.min = 1331,
123*4882a593Smuzhiyun 		.max = 1433,
124*4882a593Smuzhiyun 		.coef = {
125*4882a593Smuzhiyun 			0xfc, 0x06, 0xf9, 0x09, 0x34, 0x09, 0xf9, 0x06,
126*4882a593Smuzhiyun 			0xfd, 0x07, 0xf7, 0x10, 0x32, 0x02, 0xfc, 0x05,
127*4882a593Smuzhiyun 			0xfe, 0x07, 0xf6, 0x17, 0x2f, 0xfc, 0xff, 0x04,
128*4882a593Smuzhiyun 			0xff, 0x06, 0xf5, 0x20, 0x2a, 0xf9, 0x01, 0x02,
129*4882a593Smuzhiyun 			0x00, 0x04, 0xf6, 0x27, 0x25, 0xf6, 0x04, 0x00,
130*4882a593Smuzhiyun 			0x02, 0x01, 0xf9, 0x2d, 0x1d, 0xf5, 0x06, 0xff,
131*4882a593Smuzhiyun 			0x04, 0xff, 0xfd, 0x31, 0x15, 0xf5, 0x07, 0xfe,
132*4882a593Smuzhiyun 			0x05, 0xfc, 0x02, 0x35, 0x0d, 0xf7, 0x07, 0xfd
133*4882a593Smuzhiyun 		}
134*4882a593Smuzhiyun 	},
135*4882a593Smuzhiyun 	{
136*4882a593Smuzhiyun 		.min = 1433,
137*4882a593Smuzhiyun 		.max = 1536,
138*4882a593Smuzhiyun 		.coef = {
139*4882a593Smuzhiyun 			0xfe, 0x06, 0xf8, 0x0b, 0x30, 0x0b, 0xf8, 0x06,
140*4882a593Smuzhiyun 			0xff, 0x06, 0xf7, 0x12, 0x2d, 0x05, 0xfa, 0x06,
141*4882a593Smuzhiyun 			0x00, 0x04, 0xf6, 0x18, 0x2c, 0x00, 0xfc, 0x06,
142*4882a593Smuzhiyun 			0x01, 0x02, 0xf7, 0x1f, 0x27, 0xfd, 0xff, 0x04,
143*4882a593Smuzhiyun 			0x03, 0x00, 0xf9, 0x24, 0x24, 0xf9, 0x00, 0x03,
144*4882a593Smuzhiyun 			0x04, 0xff, 0xfd, 0x29, 0x1d, 0xf7, 0x02, 0x01,
145*4882a593Smuzhiyun 			0x06, 0xfc, 0x00, 0x2d, 0x17, 0xf6, 0x04, 0x00,
146*4882a593Smuzhiyun 			0x06, 0xfa, 0x05, 0x30, 0x0f, 0xf7, 0x06, 0xff
147*4882a593Smuzhiyun 		}
148*4882a593Smuzhiyun 	},
149*4882a593Smuzhiyun 	{
150*4882a593Smuzhiyun 		.min = 1536,
151*4882a593Smuzhiyun 		.max = 2048,
152*4882a593Smuzhiyun 		.coef = {
153*4882a593Smuzhiyun 			0x05, 0xfd, 0xfb, 0x13, 0x25, 0x13, 0xfb, 0xfd,
154*4882a593Smuzhiyun 			0x05, 0xfc, 0xfd, 0x17, 0x24, 0x0f, 0xf9, 0xff,
155*4882a593Smuzhiyun 			0x04, 0xfa, 0xff, 0x1b, 0x24, 0x0b, 0xf9, 0x00,
156*4882a593Smuzhiyun 			0x03, 0xf9, 0x01, 0x1f, 0x23, 0x08, 0xf8, 0x01,
157*4882a593Smuzhiyun 			0x02, 0xf9, 0x04, 0x22, 0x20, 0x04, 0xf9, 0x02,
158*4882a593Smuzhiyun 			0x01, 0xf8, 0x08, 0x25, 0x1d, 0x01, 0xf9, 0x03,
159*4882a593Smuzhiyun 			0x00, 0xf9, 0x0c, 0x25, 0x1a, 0xfe, 0xfa, 0x04,
160*4882a593Smuzhiyun 			0xff, 0xf9, 0x10, 0x26, 0x15, 0xfc, 0xfc, 0x05
161*4882a593Smuzhiyun 		}
162*4882a593Smuzhiyun 	},
163*4882a593Smuzhiyun 	{
164*4882a593Smuzhiyun 		.min = 2048,
165*4882a593Smuzhiyun 		.max = 3072,
166*4882a593Smuzhiyun 		.coef = {
167*4882a593Smuzhiyun 			0xfc, 0xfd, 0x06, 0x13, 0x18, 0x13, 0x06, 0xfd,
168*4882a593Smuzhiyun 			0xfc, 0xfe, 0x08, 0x15, 0x17, 0x12, 0x04, 0xfc,
169*4882a593Smuzhiyun 			0xfb, 0xfe, 0x0a, 0x16, 0x18, 0x10, 0x03, 0xfc,
170*4882a593Smuzhiyun 			0xfb, 0x00, 0x0b, 0x18, 0x17, 0x0f, 0x01, 0xfb,
171*4882a593Smuzhiyun 			0xfb, 0x00, 0x0d, 0x19, 0x17, 0x0d, 0x00, 0xfb,
172*4882a593Smuzhiyun 			0xfb, 0x01, 0x0f, 0x19, 0x16, 0x0b, 0x00, 0xfb,
173*4882a593Smuzhiyun 			0xfc, 0x03, 0x11, 0x19, 0x15, 0x09, 0xfe, 0xfb,
174*4882a593Smuzhiyun 			0xfc, 0x04, 0x12, 0x1a, 0x12, 0x08, 0xfe, 0xfc
175*4882a593Smuzhiyun 		}
176*4882a593Smuzhiyun 	},
177*4882a593Smuzhiyun 	{
178*4882a593Smuzhiyun 		.min = 3072,
179*4882a593Smuzhiyun 		.max = 4096,
180*4882a593Smuzhiyun 		.coef = {
181*4882a593Smuzhiyun 			0xfe, 0x02, 0x09, 0x0f, 0x0e, 0x0f, 0x09, 0x02,
182*4882a593Smuzhiyun 			0xff, 0x02, 0x09, 0x0f, 0x10, 0x0e, 0x08, 0x01,
183*4882a593Smuzhiyun 			0xff, 0x03, 0x0a, 0x10, 0x10, 0x0d, 0x07, 0x00,
184*4882a593Smuzhiyun 			0x00, 0x04, 0x0b, 0x10, 0x0f, 0x0c, 0x06, 0x00,
185*4882a593Smuzhiyun 			0x00, 0x05, 0x0c, 0x10, 0x0e, 0x0c, 0x05, 0x00,
186*4882a593Smuzhiyun 			0x00, 0x06, 0x0c, 0x11, 0x0e, 0x0b, 0x04, 0x00,
187*4882a593Smuzhiyun 			0x00, 0x07, 0x0d, 0x11, 0x0f, 0x0a, 0x03, 0xff,
188*4882a593Smuzhiyun 			0x01, 0x08, 0x0e, 0x11, 0x0e, 0x09, 0x02, 0xff
189*4882a593Smuzhiyun 		}
190*4882a593Smuzhiyun 	},
191*4882a593Smuzhiyun 	{
192*4882a593Smuzhiyun 		.min = 4096,
193*4882a593Smuzhiyun 		.max = 5120,
194*4882a593Smuzhiyun 		.coef = {
195*4882a593Smuzhiyun 			0x00, 0x04, 0x09, 0x0c, 0x0e, 0x0c, 0x09, 0x04,
196*4882a593Smuzhiyun 			0x01, 0x05, 0x09, 0x0c, 0x0d, 0x0c, 0x08, 0x04,
197*4882a593Smuzhiyun 			0x01, 0x05, 0x0a, 0x0c, 0x0e, 0x0b, 0x08, 0x03,
198*4882a593Smuzhiyun 			0x02, 0x06, 0x0a, 0x0d, 0x0c, 0x0b, 0x07, 0x03,
199*4882a593Smuzhiyun 			0x02, 0x07, 0x0a, 0x0d, 0x0d, 0x0a, 0x07, 0x02,
200*4882a593Smuzhiyun 			0x03, 0x07, 0x0b, 0x0d, 0x0c, 0x0a, 0x06, 0x02,
201*4882a593Smuzhiyun 			0x03, 0x08, 0x0b, 0x0d, 0x0d, 0x0a, 0x05, 0x01,
202*4882a593Smuzhiyun 			0x04, 0x08, 0x0c, 0x0d, 0x0c, 0x09, 0x05, 0x01
203*4882a593Smuzhiyun 		}
204*4882a593Smuzhiyun 	},
205*4882a593Smuzhiyun 	{
206*4882a593Smuzhiyun 		.min = 5120,
207*4882a593Smuzhiyun 		.max = 65535,
208*4882a593Smuzhiyun 		.coef = {
209*4882a593Smuzhiyun 			0x03, 0x06, 0x09, 0x0b, 0x09, 0x0b, 0x09, 0x06,
210*4882a593Smuzhiyun 			0x03, 0x06, 0x09, 0x0b, 0x0c, 0x0a, 0x08, 0x05,
211*4882a593Smuzhiyun 			0x03, 0x06, 0x09, 0x0b, 0x0c, 0x0a, 0x08, 0x05,
212*4882a593Smuzhiyun 			0x04, 0x07, 0x09, 0x0b, 0x0b, 0x0a, 0x08, 0x04,
213*4882a593Smuzhiyun 			0x04, 0x07, 0x0a, 0x0b, 0x0b, 0x0a, 0x07, 0x04,
214*4882a593Smuzhiyun 			0x04, 0x08, 0x0a, 0x0b, 0x0b, 0x09, 0x07, 0x04,
215*4882a593Smuzhiyun 			0x05, 0x08, 0x0a, 0x0b, 0x0c, 0x09, 0x06, 0x03,
216*4882a593Smuzhiyun 			0x05, 0x08, 0x0a, 0x0b, 0x0c, 0x09, 0x06, 0x03
217*4882a593Smuzhiyun 		}
218*4882a593Smuzhiyun 	}
219*4882a593Smuzhiyun };
220*4882a593Smuzhiyun 
221*4882a593Smuzhiyun #define NB_H_FILTER ARRAY_SIZE(bdisp_h_spec)
222*4882a593Smuzhiyun 
223*4882a593Smuzhiyun 
224*4882a593Smuzhiyun static const struct bdisp_filter_v_spec bdisp_v_spec[] = {
225*4882a593Smuzhiyun 	{
226*4882a593Smuzhiyun 		.min = 0,
227*4882a593Smuzhiyun 		.max = 1024,
228*4882a593Smuzhiyun 		.coef = {
229*4882a593Smuzhiyun 			0x00, 0x00, 0x40, 0x00, 0x00,
230*4882a593Smuzhiyun 			0x00, 0x06, 0x3d, 0xfd, 0x00,
231*4882a593Smuzhiyun 			0xfe, 0x0f, 0x38, 0xfb, 0x00,
232*4882a593Smuzhiyun 			0xfd, 0x19, 0x2f, 0xfb, 0x00,
233*4882a593Smuzhiyun 			0xfc, 0x24, 0x24, 0xfc, 0x00,
234*4882a593Smuzhiyun 			0xfb, 0x2f, 0x19, 0xfd, 0x00,
235*4882a593Smuzhiyun 			0xfb, 0x38, 0x0f, 0xfe, 0x00,
236*4882a593Smuzhiyun 			0xfd, 0x3d, 0x06, 0x00, 0x00
237*4882a593Smuzhiyun 		}
238*4882a593Smuzhiyun 	},
239*4882a593Smuzhiyun 	{
240*4882a593Smuzhiyun 		.min = 1024,
241*4882a593Smuzhiyun 		.max = 1331,
242*4882a593Smuzhiyun 		.coef = {
243*4882a593Smuzhiyun 			0xfc, 0x05, 0x3e, 0x05, 0xfc,
244*4882a593Smuzhiyun 			0xf8, 0x0e, 0x3b, 0xff, 0x00,
245*4882a593Smuzhiyun 			0xf5, 0x18, 0x38, 0xf9, 0x02,
246*4882a593Smuzhiyun 			0xf4, 0x21, 0x31, 0xf5, 0x05,
247*4882a593Smuzhiyun 			0xf4, 0x2a, 0x27, 0xf4, 0x07,
248*4882a593Smuzhiyun 			0xf6, 0x30, 0x1e, 0xf4, 0x08,
249*4882a593Smuzhiyun 			0xf9, 0x35, 0x15, 0xf6, 0x07,
250*4882a593Smuzhiyun 			0xff, 0x37, 0x0b, 0xf9, 0x06
251*4882a593Smuzhiyun 		}
252*4882a593Smuzhiyun 	},
253*4882a593Smuzhiyun 	{
254*4882a593Smuzhiyun 		.min = 1331,
255*4882a593Smuzhiyun 		.max = 1433,
256*4882a593Smuzhiyun 		.coef = {
257*4882a593Smuzhiyun 			0xf8, 0x0a, 0x3c, 0x0a, 0xf8,
258*4882a593Smuzhiyun 			0xf6, 0x12, 0x3b, 0x02, 0xfb,
259*4882a593Smuzhiyun 			0xf4, 0x1b, 0x35, 0xfd, 0xff,
260*4882a593Smuzhiyun 			0xf4, 0x23, 0x30, 0xf8, 0x01,
261*4882a593Smuzhiyun 			0xf6, 0x29, 0x27, 0xf6, 0x04,
262*4882a593Smuzhiyun 			0xf9, 0x2e, 0x1e, 0xf5, 0x06,
263*4882a593Smuzhiyun 			0xfd, 0x31, 0x16, 0xf6, 0x06,
264*4882a593Smuzhiyun 			0x02, 0x32, 0x0d, 0xf8, 0x07
265*4882a593Smuzhiyun 		}
266*4882a593Smuzhiyun 	},
267*4882a593Smuzhiyun 	{
268*4882a593Smuzhiyun 		.min = 1433,
269*4882a593Smuzhiyun 		.max = 1536,
270*4882a593Smuzhiyun 		.coef = {
271*4882a593Smuzhiyun 			0xf6, 0x0e, 0x38, 0x0e, 0xf6,
272*4882a593Smuzhiyun 			0xf5, 0x15, 0x38, 0x06, 0xf8,
273*4882a593Smuzhiyun 			0xf5, 0x1d, 0x33, 0x00, 0xfb,
274*4882a593Smuzhiyun 			0xf6, 0x23, 0x2d, 0xfc, 0xfe,
275*4882a593Smuzhiyun 			0xf9, 0x28, 0x26, 0xf9, 0x00,
276*4882a593Smuzhiyun 			0xfc, 0x2c, 0x1e, 0xf7, 0x03,
277*4882a593Smuzhiyun 			0x00, 0x2e, 0x18, 0xf6, 0x04,
278*4882a593Smuzhiyun 			0x05, 0x2e, 0x11, 0xf7, 0x05
279*4882a593Smuzhiyun 		}
280*4882a593Smuzhiyun 	},
281*4882a593Smuzhiyun 	{
282*4882a593Smuzhiyun 		.min = 1536,
283*4882a593Smuzhiyun 		.max = 2048,
284*4882a593Smuzhiyun 		.coef = {
285*4882a593Smuzhiyun 			0xfb, 0x13, 0x24, 0x13, 0xfb,
286*4882a593Smuzhiyun 			0xfd, 0x17, 0x23, 0x0f, 0xfa,
287*4882a593Smuzhiyun 			0xff, 0x1a, 0x23, 0x0b, 0xf9,
288*4882a593Smuzhiyun 			0x01, 0x1d, 0x22, 0x07, 0xf9,
289*4882a593Smuzhiyun 			0x04, 0x20, 0x1f, 0x04, 0xf9,
290*4882a593Smuzhiyun 			0x07, 0x22, 0x1c, 0x01, 0xfa,
291*4882a593Smuzhiyun 			0x0b, 0x24, 0x17, 0xff, 0xfb,
292*4882a593Smuzhiyun 			0x0f, 0x24, 0x14, 0xfd, 0xfc
293*4882a593Smuzhiyun 		}
294*4882a593Smuzhiyun 	},
295*4882a593Smuzhiyun 	{
296*4882a593Smuzhiyun 		.min = 2048,
297*4882a593Smuzhiyun 		.max = 3072,
298*4882a593Smuzhiyun 		.coef = {
299*4882a593Smuzhiyun 			0x05, 0x10, 0x16, 0x10, 0x05,
300*4882a593Smuzhiyun 			0x06, 0x11, 0x16, 0x0f, 0x04,
301*4882a593Smuzhiyun 			0x08, 0x13, 0x15, 0x0e, 0x02,
302*4882a593Smuzhiyun 			0x09, 0x14, 0x16, 0x0c, 0x01,
303*4882a593Smuzhiyun 			0x0b, 0x15, 0x15, 0x0b, 0x00,
304*4882a593Smuzhiyun 			0x0d, 0x16, 0x13, 0x0a, 0x00,
305*4882a593Smuzhiyun 			0x0f, 0x17, 0x13, 0x08, 0xff,
306*4882a593Smuzhiyun 			0x11, 0x18, 0x12, 0x07, 0xfe
307*4882a593Smuzhiyun 		}
308*4882a593Smuzhiyun 	},
309*4882a593Smuzhiyun 	{
310*4882a593Smuzhiyun 		.min = 3072,
311*4882a593Smuzhiyun 		.max = 4096,
312*4882a593Smuzhiyun 		.coef = {
313*4882a593Smuzhiyun 			0x09, 0x0f, 0x10, 0x0f, 0x09,
314*4882a593Smuzhiyun 			0x09, 0x0f, 0x12, 0x0e, 0x08,
315*4882a593Smuzhiyun 			0x0a, 0x10, 0x11, 0x0e, 0x07,
316*4882a593Smuzhiyun 			0x0b, 0x11, 0x11, 0x0d, 0x06,
317*4882a593Smuzhiyun 			0x0c, 0x11, 0x12, 0x0c, 0x05,
318*4882a593Smuzhiyun 			0x0d, 0x12, 0x11, 0x0c, 0x04,
319*4882a593Smuzhiyun 			0x0e, 0x12, 0x11, 0x0b, 0x04,
320*4882a593Smuzhiyun 			0x0f, 0x13, 0x11, 0x0a, 0x03
321*4882a593Smuzhiyun 		}
322*4882a593Smuzhiyun 	},
323*4882a593Smuzhiyun 	{
324*4882a593Smuzhiyun 		.min = 4096,
325*4882a593Smuzhiyun 		.max = 5120,
326*4882a593Smuzhiyun 		.coef = {
327*4882a593Smuzhiyun 			0x0a, 0x0e, 0x10, 0x0e, 0x0a,
328*4882a593Smuzhiyun 			0x0b, 0x0e, 0x0f, 0x0e, 0x0a,
329*4882a593Smuzhiyun 			0x0b, 0x0f, 0x10, 0x0d, 0x09,
330*4882a593Smuzhiyun 			0x0c, 0x0f, 0x10, 0x0d, 0x08,
331*4882a593Smuzhiyun 			0x0d, 0x0f, 0x0f, 0x0d, 0x08,
332*4882a593Smuzhiyun 			0x0d, 0x10, 0x10, 0x0c, 0x07,
333*4882a593Smuzhiyun 			0x0e, 0x10, 0x0f, 0x0c, 0x07,
334*4882a593Smuzhiyun 			0x0f, 0x10, 0x10, 0x0b, 0x06
335*4882a593Smuzhiyun 		}
336*4882a593Smuzhiyun 	},
337*4882a593Smuzhiyun 	{
338*4882a593Smuzhiyun 		.min = 5120,
339*4882a593Smuzhiyun 		.max = 65535,
340*4882a593Smuzhiyun 		.coef = {
341*4882a593Smuzhiyun 			0x0b, 0x0e, 0x0e, 0x0e, 0x0b,
342*4882a593Smuzhiyun 			0x0b, 0x0e, 0x0f, 0x0d, 0x0b,
343*4882a593Smuzhiyun 			0x0c, 0x0e, 0x0f, 0x0d, 0x0a,
344*4882a593Smuzhiyun 			0x0c, 0x0e, 0x0f, 0x0d, 0x0a,
345*4882a593Smuzhiyun 			0x0d, 0x0f, 0x0e, 0x0d, 0x09,
346*4882a593Smuzhiyun 			0x0d, 0x0f, 0x0f, 0x0c, 0x09,
347*4882a593Smuzhiyun 			0x0e, 0x0f, 0x0e, 0x0c, 0x09,
348*4882a593Smuzhiyun 			0x0e, 0x0f, 0x0f, 0x0c, 0x08
349*4882a593Smuzhiyun 		}
350*4882a593Smuzhiyun 	}
351*4882a593Smuzhiyun };
352*4882a593Smuzhiyun 
353*4882a593Smuzhiyun #define NB_V_FILTER ARRAY_SIZE(bdisp_v_spec)
354*4882a593Smuzhiyun 
355*4882a593Smuzhiyun static struct bdisp_filter_addr bdisp_h_filter[NB_H_FILTER];
356*4882a593Smuzhiyun static struct bdisp_filter_addr bdisp_v_filter[NB_V_FILTER];
357*4882a593Smuzhiyun 
358*4882a593Smuzhiyun /**
359*4882a593Smuzhiyun  * bdisp_hw_reset
360*4882a593Smuzhiyun  * @bdisp:      bdisp entity
361*4882a593Smuzhiyun  *
362*4882a593Smuzhiyun  * Resets HW
363*4882a593Smuzhiyun  *
364*4882a593Smuzhiyun  * RETURNS:
365*4882a593Smuzhiyun  * 0 on success.
366*4882a593Smuzhiyun  */
bdisp_hw_reset(struct bdisp_dev * bdisp)367*4882a593Smuzhiyun int bdisp_hw_reset(struct bdisp_dev *bdisp)
368*4882a593Smuzhiyun {
369*4882a593Smuzhiyun 	unsigned int i;
370*4882a593Smuzhiyun 
371*4882a593Smuzhiyun 	dev_dbg(bdisp->dev, "%s\n", __func__);
372*4882a593Smuzhiyun 
373*4882a593Smuzhiyun 	/* Mask Interrupt */
374*4882a593Smuzhiyun 	writel(0, bdisp->regs + BLT_ITM0);
375*4882a593Smuzhiyun 
376*4882a593Smuzhiyun 	/* Reset */
377*4882a593Smuzhiyun 	writel(readl(bdisp->regs + BLT_CTL) | BLT_CTL_RESET,
378*4882a593Smuzhiyun 	       bdisp->regs + BLT_CTL);
379*4882a593Smuzhiyun 	writel(0, bdisp->regs + BLT_CTL);
380*4882a593Smuzhiyun 
381*4882a593Smuzhiyun 	/* Wait for reset done */
382*4882a593Smuzhiyun 	for (i = 0; i < POLL_RST_MAX; i++) {
383*4882a593Smuzhiyun 		if (readl(bdisp->regs + BLT_STA1) & BLT_STA1_IDLE)
384*4882a593Smuzhiyun 			break;
385*4882a593Smuzhiyun 		udelay(POLL_RST_DELAY_MS * 1000);
386*4882a593Smuzhiyun 	}
387*4882a593Smuzhiyun 	if (i == POLL_RST_MAX)
388*4882a593Smuzhiyun 		dev_err(bdisp->dev, "Reset timeout\n");
389*4882a593Smuzhiyun 
390*4882a593Smuzhiyun 	return (i == POLL_RST_MAX) ? -EAGAIN : 0;
391*4882a593Smuzhiyun }
392*4882a593Smuzhiyun 
393*4882a593Smuzhiyun /**
394*4882a593Smuzhiyun  * bdisp_hw_get_and_clear_irq
395*4882a593Smuzhiyun  * @bdisp:      bdisp entity
396*4882a593Smuzhiyun  *
397*4882a593Smuzhiyun  * Read then reset interrupt status
398*4882a593Smuzhiyun  *
399*4882a593Smuzhiyun  * RETURNS:
400*4882a593Smuzhiyun  * 0 if expected interrupt was raised.
401*4882a593Smuzhiyun  */
bdisp_hw_get_and_clear_irq(struct bdisp_dev * bdisp)402*4882a593Smuzhiyun int bdisp_hw_get_and_clear_irq(struct bdisp_dev *bdisp)
403*4882a593Smuzhiyun {
404*4882a593Smuzhiyun 	u32 its;
405*4882a593Smuzhiyun 
406*4882a593Smuzhiyun 	its = readl(bdisp->regs + BLT_ITS);
407*4882a593Smuzhiyun 
408*4882a593Smuzhiyun 	/* Check for the only expected IT: LastNode of AQ1 */
409*4882a593Smuzhiyun 	if (!(its & BLT_ITS_AQ1_LNA)) {
410*4882a593Smuzhiyun 		dev_dbg(bdisp->dev, "Unexpected IT status: 0x%08X\n", its);
411*4882a593Smuzhiyun 		writel(its, bdisp->regs + BLT_ITS);
412*4882a593Smuzhiyun 		return -1;
413*4882a593Smuzhiyun 	}
414*4882a593Smuzhiyun 
415*4882a593Smuzhiyun 	/* Clear and mask */
416*4882a593Smuzhiyun 	writel(its, bdisp->regs + BLT_ITS);
417*4882a593Smuzhiyun 	writel(0, bdisp->regs + BLT_ITM0);
418*4882a593Smuzhiyun 
419*4882a593Smuzhiyun 	return 0;
420*4882a593Smuzhiyun }
421*4882a593Smuzhiyun 
422*4882a593Smuzhiyun /**
423*4882a593Smuzhiyun  * bdisp_hw_free_nodes
424*4882a593Smuzhiyun  * @ctx:        bdisp context
425*4882a593Smuzhiyun  *
426*4882a593Smuzhiyun  * Free node memory
427*4882a593Smuzhiyun  *
428*4882a593Smuzhiyun  * RETURNS:
429*4882a593Smuzhiyun  * None
430*4882a593Smuzhiyun  */
bdisp_hw_free_nodes(struct bdisp_ctx * ctx)431*4882a593Smuzhiyun void bdisp_hw_free_nodes(struct bdisp_ctx *ctx)
432*4882a593Smuzhiyun {
433*4882a593Smuzhiyun 	if (ctx && ctx->node[0])
434*4882a593Smuzhiyun 		dma_free_attrs(ctx->bdisp_dev->dev,
435*4882a593Smuzhiyun 			       sizeof(struct bdisp_node) * MAX_NB_NODE,
436*4882a593Smuzhiyun 			       ctx->node[0], ctx->node_paddr[0],
437*4882a593Smuzhiyun 			       DMA_ATTR_WRITE_COMBINE);
438*4882a593Smuzhiyun }
439*4882a593Smuzhiyun 
440*4882a593Smuzhiyun /**
441*4882a593Smuzhiyun  * bdisp_hw_alloc_nodes
442*4882a593Smuzhiyun  * @ctx:        bdisp context
443*4882a593Smuzhiyun  *
444*4882a593Smuzhiyun  * Allocate dma memory for nodes
445*4882a593Smuzhiyun  *
446*4882a593Smuzhiyun  * RETURNS:
447*4882a593Smuzhiyun  * 0 on success
448*4882a593Smuzhiyun  */
bdisp_hw_alloc_nodes(struct bdisp_ctx * ctx)449*4882a593Smuzhiyun int bdisp_hw_alloc_nodes(struct bdisp_ctx *ctx)
450*4882a593Smuzhiyun {
451*4882a593Smuzhiyun 	struct device *dev = ctx->bdisp_dev->dev;
452*4882a593Smuzhiyun 	unsigned int i, node_size = sizeof(struct bdisp_node);
453*4882a593Smuzhiyun 	void *base;
454*4882a593Smuzhiyun 	dma_addr_t paddr;
455*4882a593Smuzhiyun 
456*4882a593Smuzhiyun 	/* Allocate all the nodes within a single memory page */
457*4882a593Smuzhiyun 	base = dma_alloc_attrs(dev, node_size * MAX_NB_NODE, &paddr,
458*4882a593Smuzhiyun 			       GFP_KERNEL, DMA_ATTR_WRITE_COMBINE);
459*4882a593Smuzhiyun 	if (!base) {
460*4882a593Smuzhiyun 		dev_err(dev, "%s no mem\n", __func__);
461*4882a593Smuzhiyun 		return -ENOMEM;
462*4882a593Smuzhiyun 	}
463*4882a593Smuzhiyun 
464*4882a593Smuzhiyun 	memset(base, 0, node_size * MAX_NB_NODE);
465*4882a593Smuzhiyun 
466*4882a593Smuzhiyun 	for (i = 0; i < MAX_NB_NODE; i++) {
467*4882a593Smuzhiyun 		ctx->node[i] = base;
468*4882a593Smuzhiyun 		ctx->node_paddr[i] = paddr;
469*4882a593Smuzhiyun 		dev_dbg(dev, "node[%d]=0x%p (paddr=%pad)\n", i, ctx->node[i],
470*4882a593Smuzhiyun 			&paddr);
471*4882a593Smuzhiyun 		base += node_size;
472*4882a593Smuzhiyun 		paddr += node_size;
473*4882a593Smuzhiyun 	}
474*4882a593Smuzhiyun 
475*4882a593Smuzhiyun 	return 0;
476*4882a593Smuzhiyun }
477*4882a593Smuzhiyun 
478*4882a593Smuzhiyun /**
479*4882a593Smuzhiyun  * bdisp_hw_free_filters
480*4882a593Smuzhiyun  * @dev:        device
481*4882a593Smuzhiyun  *
482*4882a593Smuzhiyun  * Free filters memory
483*4882a593Smuzhiyun  *
484*4882a593Smuzhiyun  * RETURNS:
485*4882a593Smuzhiyun  * None
486*4882a593Smuzhiyun  */
bdisp_hw_free_filters(struct device * dev)487*4882a593Smuzhiyun void bdisp_hw_free_filters(struct device *dev)
488*4882a593Smuzhiyun {
489*4882a593Smuzhiyun 	int size = (BDISP_HF_NB * NB_H_FILTER) + (BDISP_VF_NB * NB_V_FILTER);
490*4882a593Smuzhiyun 
491*4882a593Smuzhiyun 	if (bdisp_h_filter[0].virt)
492*4882a593Smuzhiyun 		dma_free_attrs(dev, size, bdisp_h_filter[0].virt,
493*4882a593Smuzhiyun 			       bdisp_h_filter[0].paddr, DMA_ATTR_WRITE_COMBINE);
494*4882a593Smuzhiyun }
495*4882a593Smuzhiyun 
496*4882a593Smuzhiyun /**
497*4882a593Smuzhiyun  * bdisp_hw_alloc_filters
498*4882a593Smuzhiyun  * @dev:        device
499*4882a593Smuzhiyun  *
500*4882a593Smuzhiyun  * Allocate dma memory for filters
501*4882a593Smuzhiyun  *
502*4882a593Smuzhiyun  * RETURNS:
503*4882a593Smuzhiyun  * 0 on success
504*4882a593Smuzhiyun  */
bdisp_hw_alloc_filters(struct device * dev)505*4882a593Smuzhiyun int bdisp_hw_alloc_filters(struct device *dev)
506*4882a593Smuzhiyun {
507*4882a593Smuzhiyun 	unsigned int i, size;
508*4882a593Smuzhiyun 	void *base;
509*4882a593Smuzhiyun 	dma_addr_t paddr;
510*4882a593Smuzhiyun 
511*4882a593Smuzhiyun 	/* Allocate all the filters within a single memory page */
512*4882a593Smuzhiyun 	size = (BDISP_HF_NB * NB_H_FILTER) + (BDISP_VF_NB * NB_V_FILTER);
513*4882a593Smuzhiyun 	base = dma_alloc_attrs(dev, size, &paddr, GFP_KERNEL,
514*4882a593Smuzhiyun 			       DMA_ATTR_WRITE_COMBINE);
515*4882a593Smuzhiyun 	if (!base)
516*4882a593Smuzhiyun 		return -ENOMEM;
517*4882a593Smuzhiyun 
518*4882a593Smuzhiyun 	/* Setup filter addresses */
519*4882a593Smuzhiyun 	for (i = 0; i < NB_H_FILTER; i++) {
520*4882a593Smuzhiyun 		bdisp_h_filter[i].min = bdisp_h_spec[i].min;
521*4882a593Smuzhiyun 		bdisp_h_filter[i].max = bdisp_h_spec[i].max;
522*4882a593Smuzhiyun 		memcpy(base, bdisp_h_spec[i].coef, BDISP_HF_NB);
523*4882a593Smuzhiyun 		bdisp_h_filter[i].virt = base;
524*4882a593Smuzhiyun 		bdisp_h_filter[i].paddr = paddr;
525*4882a593Smuzhiyun 		base += BDISP_HF_NB;
526*4882a593Smuzhiyun 		paddr += BDISP_HF_NB;
527*4882a593Smuzhiyun 	}
528*4882a593Smuzhiyun 
529*4882a593Smuzhiyun 	for (i = 0; i < NB_V_FILTER; i++) {
530*4882a593Smuzhiyun 		bdisp_v_filter[i].min = bdisp_v_spec[i].min;
531*4882a593Smuzhiyun 		bdisp_v_filter[i].max = bdisp_v_spec[i].max;
532*4882a593Smuzhiyun 		memcpy(base, bdisp_v_spec[i].coef, BDISP_VF_NB);
533*4882a593Smuzhiyun 		bdisp_v_filter[i].virt = base;
534*4882a593Smuzhiyun 		bdisp_v_filter[i].paddr = paddr;
535*4882a593Smuzhiyun 		base += BDISP_VF_NB;
536*4882a593Smuzhiyun 		paddr += BDISP_VF_NB;
537*4882a593Smuzhiyun 	}
538*4882a593Smuzhiyun 
539*4882a593Smuzhiyun 	return 0;
540*4882a593Smuzhiyun }
541*4882a593Smuzhiyun 
542*4882a593Smuzhiyun /**
543*4882a593Smuzhiyun  * bdisp_hw_get_hf_addr
544*4882a593Smuzhiyun  * @inc:        resize increment
545*4882a593Smuzhiyun  *
546*4882a593Smuzhiyun  * Find the horizontal filter table that fits the resize increment
547*4882a593Smuzhiyun  *
548*4882a593Smuzhiyun  * RETURNS:
549*4882a593Smuzhiyun  * table physical address
550*4882a593Smuzhiyun  */
bdisp_hw_get_hf_addr(u16 inc)551*4882a593Smuzhiyun static dma_addr_t bdisp_hw_get_hf_addr(u16 inc)
552*4882a593Smuzhiyun {
553*4882a593Smuzhiyun 	unsigned int i;
554*4882a593Smuzhiyun 
555*4882a593Smuzhiyun 	for (i = NB_H_FILTER - 1; i > 0; i--)
556*4882a593Smuzhiyun 		if ((bdisp_h_filter[i].min < inc) &&
557*4882a593Smuzhiyun 		    (inc <= bdisp_h_filter[i].max))
558*4882a593Smuzhiyun 			break;
559*4882a593Smuzhiyun 
560*4882a593Smuzhiyun 	return bdisp_h_filter[i].paddr;
561*4882a593Smuzhiyun }
562*4882a593Smuzhiyun 
563*4882a593Smuzhiyun /**
564*4882a593Smuzhiyun  * bdisp_hw_get_vf_addr
565*4882a593Smuzhiyun  * @inc:        resize increment
566*4882a593Smuzhiyun  *
567*4882a593Smuzhiyun  * Find the vertical filter table that fits the resize increment
568*4882a593Smuzhiyun  *
569*4882a593Smuzhiyun  * RETURNS:
570*4882a593Smuzhiyun  * table physical address
571*4882a593Smuzhiyun  */
bdisp_hw_get_vf_addr(u16 inc)572*4882a593Smuzhiyun static dma_addr_t bdisp_hw_get_vf_addr(u16 inc)
573*4882a593Smuzhiyun {
574*4882a593Smuzhiyun 	unsigned int i;
575*4882a593Smuzhiyun 
576*4882a593Smuzhiyun 	for (i = NB_V_FILTER - 1; i > 0; i--)
577*4882a593Smuzhiyun 		if ((bdisp_v_filter[i].min < inc) &&
578*4882a593Smuzhiyun 		    (inc <= bdisp_v_filter[i].max))
579*4882a593Smuzhiyun 			break;
580*4882a593Smuzhiyun 
581*4882a593Smuzhiyun 	return bdisp_v_filter[i].paddr;
582*4882a593Smuzhiyun }
583*4882a593Smuzhiyun 
584*4882a593Smuzhiyun /**
585*4882a593Smuzhiyun  * bdisp_hw_get_inc
586*4882a593Smuzhiyun  * @from:       input size
587*4882a593Smuzhiyun  * @to:         output size
588*4882a593Smuzhiyun  * @inc:        resize increment in 6.10 format
589*4882a593Smuzhiyun  *
590*4882a593Smuzhiyun  * Computes the increment (inverse of scale) in 6.10 format
591*4882a593Smuzhiyun  *
592*4882a593Smuzhiyun  * RETURNS:
593*4882a593Smuzhiyun  * 0 on success
594*4882a593Smuzhiyun  */
bdisp_hw_get_inc(u32 from,u32 to,u16 * inc)595*4882a593Smuzhiyun static int bdisp_hw_get_inc(u32 from, u32 to, u16 *inc)
596*4882a593Smuzhiyun {
597*4882a593Smuzhiyun 	u32 tmp;
598*4882a593Smuzhiyun 
599*4882a593Smuzhiyun 	if (!to)
600*4882a593Smuzhiyun 		return -EINVAL;
601*4882a593Smuzhiyun 
602*4882a593Smuzhiyun 	if (to == from) {
603*4882a593Smuzhiyun 		*inc = 1 << 10;
604*4882a593Smuzhiyun 		return 0;
605*4882a593Smuzhiyun 	}
606*4882a593Smuzhiyun 
607*4882a593Smuzhiyun 	tmp = (from << 10) / to;
608*4882a593Smuzhiyun 	if ((tmp > 0xFFFF) || (!tmp))
609*4882a593Smuzhiyun 		/* overflow (downscale x 63) or too small (upscale x 1024) */
610*4882a593Smuzhiyun 		return -EINVAL;
611*4882a593Smuzhiyun 
612*4882a593Smuzhiyun 	*inc = (u16)tmp;
613*4882a593Smuzhiyun 
614*4882a593Smuzhiyun 	return 0;
615*4882a593Smuzhiyun }
616*4882a593Smuzhiyun 
617*4882a593Smuzhiyun /**
618*4882a593Smuzhiyun  * bdisp_hw_get_hv_inc
619*4882a593Smuzhiyun  * @ctx:        device context
620*4882a593Smuzhiyun  * @h_inc:      horizontal increment
621*4882a593Smuzhiyun  * @v_inc:      vertical increment
622*4882a593Smuzhiyun  *
623*4882a593Smuzhiyun  * Computes the horizontal & vertical increments (inverse of scale)
624*4882a593Smuzhiyun  *
625*4882a593Smuzhiyun  * RETURNS:
626*4882a593Smuzhiyun  * 0 on success
627*4882a593Smuzhiyun  */
bdisp_hw_get_hv_inc(struct bdisp_ctx * ctx,u16 * h_inc,u16 * v_inc)628*4882a593Smuzhiyun static int bdisp_hw_get_hv_inc(struct bdisp_ctx *ctx, u16 *h_inc, u16 *v_inc)
629*4882a593Smuzhiyun {
630*4882a593Smuzhiyun 	u32 src_w, src_h, dst_w, dst_h;
631*4882a593Smuzhiyun 
632*4882a593Smuzhiyun 	src_w = ctx->src.crop.width;
633*4882a593Smuzhiyun 	src_h = ctx->src.crop.height;
634*4882a593Smuzhiyun 	dst_w = ctx->dst.crop.width;
635*4882a593Smuzhiyun 	dst_h = ctx->dst.crop.height;
636*4882a593Smuzhiyun 
637*4882a593Smuzhiyun 	if (bdisp_hw_get_inc(src_w, dst_w, h_inc) ||
638*4882a593Smuzhiyun 	    bdisp_hw_get_inc(src_h, dst_h, v_inc)) {
639*4882a593Smuzhiyun 		dev_err(ctx->bdisp_dev->dev,
640*4882a593Smuzhiyun 			"scale factors failed (%dx%d)->(%dx%d)\n",
641*4882a593Smuzhiyun 			src_w, src_h, dst_w, dst_h);
642*4882a593Smuzhiyun 		return -EINVAL;
643*4882a593Smuzhiyun 	}
644*4882a593Smuzhiyun 
645*4882a593Smuzhiyun 	return 0;
646*4882a593Smuzhiyun }
647*4882a593Smuzhiyun 
648*4882a593Smuzhiyun /**
649*4882a593Smuzhiyun  * bdisp_hw_get_op_cfg
650*4882a593Smuzhiyun  * @ctx:        device context
651*4882a593Smuzhiyun  * @c:          operation configuration
652*4882a593Smuzhiyun  *
653*4882a593Smuzhiyun  * Check which blitter operations are expected and sets the scaling increments
654*4882a593Smuzhiyun  *
655*4882a593Smuzhiyun  * RETURNS:
656*4882a593Smuzhiyun  * 0 on success
657*4882a593Smuzhiyun  */
bdisp_hw_get_op_cfg(struct bdisp_ctx * ctx,struct bdisp_op_cfg * c)658*4882a593Smuzhiyun static int bdisp_hw_get_op_cfg(struct bdisp_ctx *ctx, struct bdisp_op_cfg *c)
659*4882a593Smuzhiyun {
660*4882a593Smuzhiyun 	struct device *dev = ctx->bdisp_dev->dev;
661*4882a593Smuzhiyun 	struct bdisp_frame *src = &ctx->src;
662*4882a593Smuzhiyun 	struct bdisp_frame *dst = &ctx->dst;
663*4882a593Smuzhiyun 
664*4882a593Smuzhiyun 	if (src->width > MAX_SRC_WIDTH * MAX_VERTICAL_STRIDES) {
665*4882a593Smuzhiyun 		dev_err(dev, "Image width out of HW caps\n");
666*4882a593Smuzhiyun 		return -EINVAL;
667*4882a593Smuzhiyun 	}
668*4882a593Smuzhiyun 
669*4882a593Smuzhiyun 	c->wide = src->width > MAX_SRC_WIDTH;
670*4882a593Smuzhiyun 
671*4882a593Smuzhiyun 	c->hflip = ctx->hflip;
672*4882a593Smuzhiyun 	c->vflip = ctx->vflip;
673*4882a593Smuzhiyun 
674*4882a593Smuzhiyun 	c->src_interlaced = (src->field == V4L2_FIELD_INTERLACED);
675*4882a593Smuzhiyun 
676*4882a593Smuzhiyun 	c->src_nbp = src->fmt->nb_planes;
677*4882a593Smuzhiyun 	c->src_yuv = (src->fmt->pixelformat == V4L2_PIX_FMT_NV12) ||
678*4882a593Smuzhiyun 			(src->fmt->pixelformat == V4L2_PIX_FMT_YUV420);
679*4882a593Smuzhiyun 	c->src_420 = c->src_yuv;
680*4882a593Smuzhiyun 
681*4882a593Smuzhiyun 	c->dst_nbp = dst->fmt->nb_planes;
682*4882a593Smuzhiyun 	c->dst_yuv = (dst->fmt->pixelformat == V4L2_PIX_FMT_NV12) ||
683*4882a593Smuzhiyun 			(dst->fmt->pixelformat == V4L2_PIX_FMT_YUV420);
684*4882a593Smuzhiyun 	c->dst_420 = c->dst_yuv;
685*4882a593Smuzhiyun 
686*4882a593Smuzhiyun 	c->cconv = (c->src_yuv != c->dst_yuv);
687*4882a593Smuzhiyun 
688*4882a593Smuzhiyun 	if (bdisp_hw_get_hv_inc(ctx, &c->h_inc, &c->v_inc)) {
689*4882a593Smuzhiyun 		dev_err(dev, "Scale factor out of HW caps\n");
690*4882a593Smuzhiyun 		return -EINVAL;
691*4882a593Smuzhiyun 	}
692*4882a593Smuzhiyun 
693*4882a593Smuzhiyun 	/* Deinterlacing adjustment : stretch a field to a frame */
694*4882a593Smuzhiyun 	if (c->src_interlaced)
695*4882a593Smuzhiyun 		c->v_inc /= 2;
696*4882a593Smuzhiyun 
697*4882a593Smuzhiyun 	if ((c->h_inc != (1 << 10)) || (c->v_inc != (1 << 10)))
698*4882a593Smuzhiyun 		c->scale = true;
699*4882a593Smuzhiyun 	else
700*4882a593Smuzhiyun 		c->scale = false;
701*4882a593Smuzhiyun 
702*4882a593Smuzhiyun 	return 0;
703*4882a593Smuzhiyun }
704*4882a593Smuzhiyun 
705*4882a593Smuzhiyun /**
706*4882a593Smuzhiyun  * bdisp_hw_color_format
707*4882a593Smuzhiyun  * @pixelformat: v4l2 pixel format
708*4882a593Smuzhiyun  *
709*4882a593Smuzhiyun  * v4l2 to bdisp pixel format convert
710*4882a593Smuzhiyun  *
711*4882a593Smuzhiyun  * RETURNS:
712*4882a593Smuzhiyun  * bdisp pixel format
713*4882a593Smuzhiyun  */
bdisp_hw_color_format(u32 pixelformat)714*4882a593Smuzhiyun static u32 bdisp_hw_color_format(u32 pixelformat)
715*4882a593Smuzhiyun {
716*4882a593Smuzhiyun 	u32 ret;
717*4882a593Smuzhiyun 
718*4882a593Smuzhiyun 	switch (pixelformat) {
719*4882a593Smuzhiyun 	case V4L2_PIX_FMT_YUV420:
720*4882a593Smuzhiyun 		ret = (BDISP_YUV_3B << BLT_TTY_COL_SHIFT);
721*4882a593Smuzhiyun 		break;
722*4882a593Smuzhiyun 	case V4L2_PIX_FMT_NV12:
723*4882a593Smuzhiyun 		ret = (BDISP_NV12 << BLT_TTY_COL_SHIFT) | BLT_TTY_BIG_END;
724*4882a593Smuzhiyun 		break;
725*4882a593Smuzhiyun 	case V4L2_PIX_FMT_RGB565:
726*4882a593Smuzhiyun 		ret = (BDISP_RGB565 << BLT_TTY_COL_SHIFT);
727*4882a593Smuzhiyun 		break;
728*4882a593Smuzhiyun 	case V4L2_PIX_FMT_XBGR32: /* This V4L format actually refers to xRGB */
729*4882a593Smuzhiyun 		ret = (BDISP_XRGB8888 << BLT_TTY_COL_SHIFT);
730*4882a593Smuzhiyun 		break;
731*4882a593Smuzhiyun 	case V4L2_PIX_FMT_RGB24:  /* RGB888 format */
732*4882a593Smuzhiyun 		ret = (BDISP_RGB888 << BLT_TTY_COL_SHIFT) | BLT_TTY_BIG_END;
733*4882a593Smuzhiyun 		break;
734*4882a593Smuzhiyun 	case V4L2_PIX_FMT_ABGR32: /* This V4L format actually refers to ARGB */
735*4882a593Smuzhiyun 
736*4882a593Smuzhiyun 	default:
737*4882a593Smuzhiyun 		ret = (BDISP_ARGB8888 << BLT_TTY_COL_SHIFT) | BLT_TTY_ALPHA_R;
738*4882a593Smuzhiyun 		break;
739*4882a593Smuzhiyun 	}
740*4882a593Smuzhiyun 
741*4882a593Smuzhiyun 	return ret;
742*4882a593Smuzhiyun }
743*4882a593Smuzhiyun 
744*4882a593Smuzhiyun /**
745*4882a593Smuzhiyun  * bdisp_hw_build_node
746*4882a593Smuzhiyun  * @ctx:        device context
747*4882a593Smuzhiyun  * @cfg:        operation configuration
748*4882a593Smuzhiyun  * @node:       node to be set
749*4882a593Smuzhiyun  * @t_plan:     whether the node refers to a RGB/Y or a CbCr plane
750*4882a593Smuzhiyun  * @src_x_offset: x offset in the source image
751*4882a593Smuzhiyun  *
752*4882a593Smuzhiyun  * Build a node
753*4882a593Smuzhiyun  *
754*4882a593Smuzhiyun  * RETURNS:
755*4882a593Smuzhiyun  * None
756*4882a593Smuzhiyun  */
bdisp_hw_build_node(struct bdisp_ctx * ctx,struct bdisp_op_cfg * cfg,struct bdisp_node * node,enum bdisp_target_plan t_plan,int src_x_offset)757*4882a593Smuzhiyun static void bdisp_hw_build_node(struct bdisp_ctx *ctx,
758*4882a593Smuzhiyun 				struct bdisp_op_cfg *cfg,
759*4882a593Smuzhiyun 				struct bdisp_node *node,
760*4882a593Smuzhiyun 				enum bdisp_target_plan t_plan, int src_x_offset)
761*4882a593Smuzhiyun {
762*4882a593Smuzhiyun 	struct bdisp_frame *src = &ctx->src;
763*4882a593Smuzhiyun 	struct bdisp_frame *dst = &ctx->dst;
764*4882a593Smuzhiyun 	u16 h_inc, v_inc, yh_inc, yv_inc;
765*4882a593Smuzhiyun 	struct v4l2_rect src_rect = src->crop;
766*4882a593Smuzhiyun 	struct v4l2_rect dst_rect = dst->crop;
767*4882a593Smuzhiyun 	int dst_x_offset;
768*4882a593Smuzhiyun 	s32 dst_width = dst->crop.width;
769*4882a593Smuzhiyun 	u32 src_fmt, dst_fmt;
770*4882a593Smuzhiyun 	const u32 *ivmx;
771*4882a593Smuzhiyun 
772*4882a593Smuzhiyun 	dev_dbg(ctx->bdisp_dev->dev, "%s\n", __func__);
773*4882a593Smuzhiyun 
774*4882a593Smuzhiyun 	memset(node, 0, sizeof(*node));
775*4882a593Smuzhiyun 
776*4882a593Smuzhiyun 	/* Adjust src and dst areas wrt src_x_offset */
777*4882a593Smuzhiyun 	src_rect.left += src_x_offset;
778*4882a593Smuzhiyun 	src_rect.width -= src_x_offset;
779*4882a593Smuzhiyun 	src_rect.width = min_t(__s32, MAX_SRC_WIDTH, src_rect.width);
780*4882a593Smuzhiyun 
781*4882a593Smuzhiyun 	dst_x_offset = (src_x_offset * dst_width) / ctx->src.crop.width;
782*4882a593Smuzhiyun 	dst_rect.left += dst_x_offset;
783*4882a593Smuzhiyun 	dst_rect.width = (src_rect.width * dst_width) / ctx->src.crop.width;
784*4882a593Smuzhiyun 
785*4882a593Smuzhiyun 	/* General */
786*4882a593Smuzhiyun 	src_fmt = src->fmt->pixelformat;
787*4882a593Smuzhiyun 	dst_fmt = dst->fmt->pixelformat;
788*4882a593Smuzhiyun 
789*4882a593Smuzhiyun 	node->nip = 0;
790*4882a593Smuzhiyun 	node->cic = BLT_CIC_ALL_GRP;
791*4882a593Smuzhiyun 	node->ack = BLT_ACK_BYPASS_S2S3;
792*4882a593Smuzhiyun 
793*4882a593Smuzhiyun 	switch (cfg->src_nbp) {
794*4882a593Smuzhiyun 	case 1:
795*4882a593Smuzhiyun 		/* Src2 = RGB / Src1 = Src3 = off */
796*4882a593Smuzhiyun 		node->ins = BLT_INS_S1_OFF | BLT_INS_S2_MEM | BLT_INS_S3_OFF;
797*4882a593Smuzhiyun 		break;
798*4882a593Smuzhiyun 	case 2:
799*4882a593Smuzhiyun 		/* Src3 = Y
800*4882a593Smuzhiyun 		 * Src2 = CbCr or ColorFill if writing the Y plane
801*4882a593Smuzhiyun 		 * Src1 = off */
802*4882a593Smuzhiyun 		node->ins = BLT_INS_S1_OFF | BLT_INS_S3_MEM;
803*4882a593Smuzhiyun 		if (t_plan == BDISP_Y)
804*4882a593Smuzhiyun 			node->ins |= BLT_INS_S2_CF;
805*4882a593Smuzhiyun 		else
806*4882a593Smuzhiyun 			node->ins |= BLT_INS_S2_MEM;
807*4882a593Smuzhiyun 		break;
808*4882a593Smuzhiyun 	case 3:
809*4882a593Smuzhiyun 	default:
810*4882a593Smuzhiyun 		/* Src3 = Y
811*4882a593Smuzhiyun 		 * Src2 = Cb or ColorFill if writing the Y plane
812*4882a593Smuzhiyun 		 * Src1 = Cr or ColorFill if writing the Y plane */
813*4882a593Smuzhiyun 		node->ins = BLT_INS_S3_MEM;
814*4882a593Smuzhiyun 		if (t_plan == BDISP_Y)
815*4882a593Smuzhiyun 			node->ins |= BLT_INS_S2_CF | BLT_INS_S1_CF;
816*4882a593Smuzhiyun 		else
817*4882a593Smuzhiyun 			node->ins |= BLT_INS_S2_MEM | BLT_INS_S1_MEM;
818*4882a593Smuzhiyun 		break;
819*4882a593Smuzhiyun 	}
820*4882a593Smuzhiyun 
821*4882a593Smuzhiyun 	/* Color convert */
822*4882a593Smuzhiyun 	node->ins |= cfg->cconv ? BLT_INS_IVMX : 0;
823*4882a593Smuzhiyun 	/* Scale needed if scaling OR 4:2:0 up/downsampling */
824*4882a593Smuzhiyun 	node->ins |= (cfg->scale || cfg->src_420 || cfg->dst_420) ?
825*4882a593Smuzhiyun 			BLT_INS_SCALE : 0;
826*4882a593Smuzhiyun 
827*4882a593Smuzhiyun 	/* Target */
828*4882a593Smuzhiyun 	node->tba = (t_plan == BDISP_CBCR) ? dst->paddr[1] : dst->paddr[0];
829*4882a593Smuzhiyun 
830*4882a593Smuzhiyun 	node->tty = dst->bytesperline;
831*4882a593Smuzhiyun 	node->tty |= bdisp_hw_color_format(dst_fmt);
832*4882a593Smuzhiyun 	node->tty |= BLT_TTY_DITHER;
833*4882a593Smuzhiyun 	node->tty |= (t_plan == BDISP_CBCR) ? BLT_TTY_CHROMA : 0;
834*4882a593Smuzhiyun 	node->tty |= cfg->hflip ? BLT_TTY_HSO : 0;
835*4882a593Smuzhiyun 	node->tty |= cfg->vflip ? BLT_TTY_VSO : 0;
836*4882a593Smuzhiyun 
837*4882a593Smuzhiyun 	if (cfg->dst_420 && (t_plan == BDISP_CBCR)) {
838*4882a593Smuzhiyun 		/* 420 chroma downsampling */
839*4882a593Smuzhiyun 		dst_rect.height /= 2;
840*4882a593Smuzhiyun 		dst_rect.width /= 2;
841*4882a593Smuzhiyun 		dst_rect.left /= 2;
842*4882a593Smuzhiyun 		dst_rect.top /= 2;
843*4882a593Smuzhiyun 		dst_x_offset /= 2;
844*4882a593Smuzhiyun 		dst_width /= 2;
845*4882a593Smuzhiyun 	}
846*4882a593Smuzhiyun 
847*4882a593Smuzhiyun 	node->txy = cfg->vflip ? (dst_rect.height - 1) : dst_rect.top;
848*4882a593Smuzhiyun 	node->txy <<= 16;
849*4882a593Smuzhiyun 	node->txy |= cfg->hflip ? (dst_width - dst_x_offset - 1) :
850*4882a593Smuzhiyun 			dst_rect.left;
851*4882a593Smuzhiyun 
852*4882a593Smuzhiyun 	node->tsz = dst_rect.height << 16 | dst_rect.width;
853*4882a593Smuzhiyun 
854*4882a593Smuzhiyun 	if (cfg->src_interlaced) {
855*4882a593Smuzhiyun 		/* handle only the top field which is half height of a frame */
856*4882a593Smuzhiyun 		src_rect.top /= 2;
857*4882a593Smuzhiyun 		src_rect.height /= 2;
858*4882a593Smuzhiyun 	}
859*4882a593Smuzhiyun 
860*4882a593Smuzhiyun 	if (cfg->src_nbp == 1) {
861*4882a593Smuzhiyun 		/* Src 2 : RGB */
862*4882a593Smuzhiyun 		node->s2ba = src->paddr[0];
863*4882a593Smuzhiyun 
864*4882a593Smuzhiyun 		node->s2ty = src->bytesperline;
865*4882a593Smuzhiyun 		if (cfg->src_interlaced)
866*4882a593Smuzhiyun 			node->s2ty *= 2;
867*4882a593Smuzhiyun 
868*4882a593Smuzhiyun 		node->s2ty |= bdisp_hw_color_format(src_fmt);
869*4882a593Smuzhiyun 
870*4882a593Smuzhiyun 		node->s2xy = src_rect.top << 16 | src_rect.left;
871*4882a593Smuzhiyun 		node->s2sz = src_rect.height << 16 | src_rect.width;
872*4882a593Smuzhiyun 	} else {
873*4882a593Smuzhiyun 		/* Src 2 : Cb or CbCr */
874*4882a593Smuzhiyun 		if (cfg->src_420) {
875*4882a593Smuzhiyun 			/* 420 chroma upsampling */
876*4882a593Smuzhiyun 			src_rect.top /= 2;
877*4882a593Smuzhiyun 			src_rect.left /= 2;
878*4882a593Smuzhiyun 			src_rect.width /= 2;
879*4882a593Smuzhiyun 			src_rect.height /= 2;
880*4882a593Smuzhiyun 		}
881*4882a593Smuzhiyun 
882*4882a593Smuzhiyun 		node->s2ba = src->paddr[1];
883*4882a593Smuzhiyun 
884*4882a593Smuzhiyun 		node->s2ty = src->bytesperline;
885*4882a593Smuzhiyun 		if (cfg->src_nbp == 3)
886*4882a593Smuzhiyun 			node->s2ty /= 2;
887*4882a593Smuzhiyun 		if (cfg->src_interlaced)
888*4882a593Smuzhiyun 			node->s2ty *= 2;
889*4882a593Smuzhiyun 
890*4882a593Smuzhiyun 		node->s2ty |= bdisp_hw_color_format(src_fmt);
891*4882a593Smuzhiyun 
892*4882a593Smuzhiyun 		node->s2xy = src_rect.top << 16 | src_rect.left;
893*4882a593Smuzhiyun 		node->s2sz = src_rect.height << 16 | src_rect.width;
894*4882a593Smuzhiyun 
895*4882a593Smuzhiyun 		if (cfg->src_nbp == 3) {
896*4882a593Smuzhiyun 			/* Src 1 : Cr */
897*4882a593Smuzhiyun 			node->s1ba = src->paddr[2];
898*4882a593Smuzhiyun 
899*4882a593Smuzhiyun 			node->s1ty = node->s2ty;
900*4882a593Smuzhiyun 			node->s1xy = node->s2xy;
901*4882a593Smuzhiyun 		}
902*4882a593Smuzhiyun 
903*4882a593Smuzhiyun 		/* Src 3 : Y */
904*4882a593Smuzhiyun 		node->s3ba = src->paddr[0];
905*4882a593Smuzhiyun 
906*4882a593Smuzhiyun 		node->s3ty = src->bytesperline;
907*4882a593Smuzhiyun 		if (cfg->src_interlaced)
908*4882a593Smuzhiyun 			node->s3ty *= 2;
909*4882a593Smuzhiyun 		node->s3ty |= bdisp_hw_color_format(src_fmt);
910*4882a593Smuzhiyun 
911*4882a593Smuzhiyun 		if ((t_plan != BDISP_CBCR) && cfg->src_420) {
912*4882a593Smuzhiyun 			/* No chroma upsampling for output RGB / Y plane */
913*4882a593Smuzhiyun 			node->s3xy = node->s2xy * 2;
914*4882a593Smuzhiyun 			node->s3sz = node->s2sz * 2;
915*4882a593Smuzhiyun 		} else {
916*4882a593Smuzhiyun 			/* No need to read Y (Src3) when writing Chroma */
917*4882a593Smuzhiyun 			node->s3ty |= BLT_S3TY_BLANK_ACC;
918*4882a593Smuzhiyun 			node->s3xy = node->s2xy;
919*4882a593Smuzhiyun 			node->s3sz = node->s2sz;
920*4882a593Smuzhiyun 		}
921*4882a593Smuzhiyun 	}
922*4882a593Smuzhiyun 
923*4882a593Smuzhiyun 	/* Resize (scale OR 4:2:0: chroma up/downsampling) */
924*4882a593Smuzhiyun 	if (node->ins & BLT_INS_SCALE) {
925*4882a593Smuzhiyun 		/* no need to compute Y when writing CbCr from RGB input */
926*4882a593Smuzhiyun 		bool skip_y = (t_plan == BDISP_CBCR) && !cfg->src_yuv;
927*4882a593Smuzhiyun 
928*4882a593Smuzhiyun 		/* FCTL */
929*4882a593Smuzhiyun 		if (cfg->scale) {
930*4882a593Smuzhiyun 			node->fctl = BLT_FCTL_HV_SCALE;
931*4882a593Smuzhiyun 			if (!skip_y)
932*4882a593Smuzhiyun 				node->fctl |= BLT_FCTL_Y_HV_SCALE;
933*4882a593Smuzhiyun 		} else {
934*4882a593Smuzhiyun 			node->fctl = BLT_FCTL_HV_SAMPLE;
935*4882a593Smuzhiyun 			if (!skip_y)
936*4882a593Smuzhiyun 				node->fctl |= BLT_FCTL_Y_HV_SAMPLE;
937*4882a593Smuzhiyun 		}
938*4882a593Smuzhiyun 
939*4882a593Smuzhiyun 		/* RSF - Chroma may need to be up/downsampled */
940*4882a593Smuzhiyun 		h_inc = cfg->h_inc;
941*4882a593Smuzhiyun 		v_inc = cfg->v_inc;
942*4882a593Smuzhiyun 		if (!cfg->src_420 && cfg->dst_420 && (t_plan == BDISP_CBCR)) {
943*4882a593Smuzhiyun 			/* RGB to 4:2:0 for Chroma: downsample */
944*4882a593Smuzhiyun 			h_inc *= 2;
945*4882a593Smuzhiyun 			v_inc *= 2;
946*4882a593Smuzhiyun 		} else if (cfg->src_420 && !cfg->dst_420) {
947*4882a593Smuzhiyun 			/* 4:2:0: to RGB: upsample*/
948*4882a593Smuzhiyun 			h_inc /= 2;
949*4882a593Smuzhiyun 			v_inc /= 2;
950*4882a593Smuzhiyun 		}
951*4882a593Smuzhiyun 		node->rsf = v_inc << 16 | h_inc;
952*4882a593Smuzhiyun 
953*4882a593Smuzhiyun 		/* RZI */
954*4882a593Smuzhiyun 		node->rzi = BLT_RZI_DEFAULT;
955*4882a593Smuzhiyun 
956*4882a593Smuzhiyun 		/* Filter table physical addr */
957*4882a593Smuzhiyun 		node->hfp = bdisp_hw_get_hf_addr(h_inc);
958*4882a593Smuzhiyun 		node->vfp = bdisp_hw_get_vf_addr(v_inc);
959*4882a593Smuzhiyun 
960*4882a593Smuzhiyun 		/* Y version */
961*4882a593Smuzhiyun 		if (!skip_y) {
962*4882a593Smuzhiyun 			yh_inc = cfg->h_inc;
963*4882a593Smuzhiyun 			yv_inc = cfg->v_inc;
964*4882a593Smuzhiyun 
965*4882a593Smuzhiyun 			node->y_rsf = yv_inc << 16 | yh_inc;
966*4882a593Smuzhiyun 			node->y_rzi = BLT_RZI_DEFAULT;
967*4882a593Smuzhiyun 			node->y_hfp = bdisp_hw_get_hf_addr(yh_inc);
968*4882a593Smuzhiyun 			node->y_vfp = bdisp_hw_get_vf_addr(yv_inc);
969*4882a593Smuzhiyun 		}
970*4882a593Smuzhiyun 	}
971*4882a593Smuzhiyun 
972*4882a593Smuzhiyun 	/* Versatile matrix for RGB / YUV conversion */
973*4882a593Smuzhiyun 	if (cfg->cconv) {
974*4882a593Smuzhiyun 		ivmx = cfg->src_yuv ? bdisp_yuv_to_rgb : bdisp_rgb_to_yuv;
975*4882a593Smuzhiyun 
976*4882a593Smuzhiyun 		node->ivmx0 = ivmx[0];
977*4882a593Smuzhiyun 		node->ivmx1 = ivmx[1];
978*4882a593Smuzhiyun 		node->ivmx2 = ivmx[2];
979*4882a593Smuzhiyun 		node->ivmx3 = ivmx[3];
980*4882a593Smuzhiyun 	}
981*4882a593Smuzhiyun }
982*4882a593Smuzhiyun 
983*4882a593Smuzhiyun /**
984*4882a593Smuzhiyun  * bdisp_hw_build_all_nodes
985*4882a593Smuzhiyun  * @ctx:        device context
986*4882a593Smuzhiyun  *
987*4882a593Smuzhiyun  * Build all the nodes for the blitter operation
988*4882a593Smuzhiyun  *
989*4882a593Smuzhiyun  * RETURNS:
990*4882a593Smuzhiyun  * 0 on success
991*4882a593Smuzhiyun  */
bdisp_hw_build_all_nodes(struct bdisp_ctx * ctx)992*4882a593Smuzhiyun static int bdisp_hw_build_all_nodes(struct bdisp_ctx *ctx)
993*4882a593Smuzhiyun {
994*4882a593Smuzhiyun 	struct bdisp_op_cfg cfg;
995*4882a593Smuzhiyun 	unsigned int i, nid = 0;
996*4882a593Smuzhiyun 	int src_x_offset = 0;
997*4882a593Smuzhiyun 
998*4882a593Smuzhiyun 	for (i = 0; i < MAX_NB_NODE; i++)
999*4882a593Smuzhiyun 		if (!ctx->node[i]) {
1000*4882a593Smuzhiyun 			dev_err(ctx->bdisp_dev->dev, "node %d is null\n", i);
1001*4882a593Smuzhiyun 			return -EINVAL;
1002*4882a593Smuzhiyun 		}
1003*4882a593Smuzhiyun 
1004*4882a593Smuzhiyun 	/* Get configuration (scale, flip, ...) */
1005*4882a593Smuzhiyun 	if (bdisp_hw_get_op_cfg(ctx, &cfg))
1006*4882a593Smuzhiyun 		return -EINVAL;
1007*4882a593Smuzhiyun 
1008*4882a593Smuzhiyun 	/* Split source in vertical strides (HW constraint) */
1009*4882a593Smuzhiyun 	for (i = 0; i < MAX_VERTICAL_STRIDES; i++) {
1010*4882a593Smuzhiyun 		/* Build RGB/Y node and link it to the previous node */
1011*4882a593Smuzhiyun 		bdisp_hw_build_node(ctx, &cfg, ctx->node[nid],
1012*4882a593Smuzhiyun 				    cfg.dst_nbp == 1 ? BDISP_RGB : BDISP_Y,
1013*4882a593Smuzhiyun 				    src_x_offset);
1014*4882a593Smuzhiyun 		if (nid)
1015*4882a593Smuzhiyun 			ctx->node[nid - 1]->nip = ctx->node_paddr[nid];
1016*4882a593Smuzhiyun 		nid++;
1017*4882a593Smuzhiyun 
1018*4882a593Smuzhiyun 		/* Build additional Cb(Cr) node, link it to the previous one */
1019*4882a593Smuzhiyun 		if (cfg.dst_nbp > 1) {
1020*4882a593Smuzhiyun 			bdisp_hw_build_node(ctx, &cfg, ctx->node[nid],
1021*4882a593Smuzhiyun 					    BDISP_CBCR, src_x_offset);
1022*4882a593Smuzhiyun 			ctx->node[nid - 1]->nip = ctx->node_paddr[nid];
1023*4882a593Smuzhiyun 			nid++;
1024*4882a593Smuzhiyun 		}
1025*4882a593Smuzhiyun 
1026*4882a593Smuzhiyun 		/* Next stride until full width covered */
1027*4882a593Smuzhiyun 		src_x_offset += MAX_SRC_WIDTH;
1028*4882a593Smuzhiyun 		if (src_x_offset >= ctx->src.crop.width)
1029*4882a593Smuzhiyun 			break;
1030*4882a593Smuzhiyun 	}
1031*4882a593Smuzhiyun 
1032*4882a593Smuzhiyun 	/* Mark last node as the last */
1033*4882a593Smuzhiyun 	ctx->node[nid - 1]->nip = 0;
1034*4882a593Smuzhiyun 
1035*4882a593Smuzhiyun 	return 0;
1036*4882a593Smuzhiyun }
1037*4882a593Smuzhiyun 
1038*4882a593Smuzhiyun /**
1039*4882a593Smuzhiyun  * bdisp_hw_save_request
1040*4882a593Smuzhiyun  * @ctx:        device context
1041*4882a593Smuzhiyun  *
1042*4882a593Smuzhiyun  * Save a copy of the request and of the built nodes
1043*4882a593Smuzhiyun  *
1044*4882a593Smuzhiyun  * RETURNS:
1045*4882a593Smuzhiyun  * None
1046*4882a593Smuzhiyun  */
bdisp_hw_save_request(struct bdisp_ctx * ctx)1047*4882a593Smuzhiyun static void bdisp_hw_save_request(struct bdisp_ctx *ctx)
1048*4882a593Smuzhiyun {
1049*4882a593Smuzhiyun 	struct bdisp_node **copy_node = ctx->bdisp_dev->dbg.copy_node;
1050*4882a593Smuzhiyun 	struct bdisp_request *request = &ctx->bdisp_dev->dbg.copy_request;
1051*4882a593Smuzhiyun 	struct bdisp_node **node = ctx->node;
1052*4882a593Smuzhiyun 	int i;
1053*4882a593Smuzhiyun 
1054*4882a593Smuzhiyun 	/* Request copy */
1055*4882a593Smuzhiyun 	request->src = ctx->src;
1056*4882a593Smuzhiyun 	request->dst = ctx->dst;
1057*4882a593Smuzhiyun 	request->hflip = ctx->hflip;
1058*4882a593Smuzhiyun 	request->vflip = ctx->vflip;
1059*4882a593Smuzhiyun 	request->nb_req++;
1060*4882a593Smuzhiyun 
1061*4882a593Smuzhiyun 	/* Nodes copy */
1062*4882a593Smuzhiyun 	for (i = 0; i < MAX_NB_NODE; i++) {
1063*4882a593Smuzhiyun 		/* Allocate memory if not done yet */
1064*4882a593Smuzhiyun 		if (!copy_node[i]) {
1065*4882a593Smuzhiyun 			copy_node[i] = devm_kzalloc(ctx->bdisp_dev->dev,
1066*4882a593Smuzhiyun 						    sizeof(*copy_node[i]),
1067*4882a593Smuzhiyun 						    GFP_ATOMIC);
1068*4882a593Smuzhiyun 			if (!copy_node[i])
1069*4882a593Smuzhiyun 				return;
1070*4882a593Smuzhiyun 		}
1071*4882a593Smuzhiyun 		*copy_node[i] = *node[i];
1072*4882a593Smuzhiyun 	}
1073*4882a593Smuzhiyun }
1074*4882a593Smuzhiyun 
1075*4882a593Smuzhiyun /**
1076*4882a593Smuzhiyun  * bdisp_hw_update
1077*4882a593Smuzhiyun  * @ctx:        device context
1078*4882a593Smuzhiyun  *
1079*4882a593Smuzhiyun  * Send the request to the HW
1080*4882a593Smuzhiyun  *
1081*4882a593Smuzhiyun  * RETURNS:
1082*4882a593Smuzhiyun  * 0 on success
1083*4882a593Smuzhiyun  */
bdisp_hw_update(struct bdisp_ctx * ctx)1084*4882a593Smuzhiyun int bdisp_hw_update(struct bdisp_ctx *ctx)
1085*4882a593Smuzhiyun {
1086*4882a593Smuzhiyun 	int ret;
1087*4882a593Smuzhiyun 	struct bdisp_dev *bdisp = ctx->bdisp_dev;
1088*4882a593Smuzhiyun 	struct device *dev = bdisp->dev;
1089*4882a593Smuzhiyun 	unsigned int node_id;
1090*4882a593Smuzhiyun 
1091*4882a593Smuzhiyun 	dev_dbg(dev, "%s\n", __func__);
1092*4882a593Smuzhiyun 
1093*4882a593Smuzhiyun 	/* build nodes */
1094*4882a593Smuzhiyun 	ret = bdisp_hw_build_all_nodes(ctx);
1095*4882a593Smuzhiyun 	if (ret) {
1096*4882a593Smuzhiyun 		dev_err(dev, "cannot build nodes (%d)\n", ret);
1097*4882a593Smuzhiyun 		return ret;
1098*4882a593Smuzhiyun 	}
1099*4882a593Smuzhiyun 
1100*4882a593Smuzhiyun 	/* Save a copy of the request */
1101*4882a593Smuzhiyun 	bdisp_hw_save_request(ctx);
1102*4882a593Smuzhiyun 
1103*4882a593Smuzhiyun 	/* Configure interrupt to 'Last Node Reached for AQ1' */
1104*4882a593Smuzhiyun 	writel(BLT_AQ1_CTL_CFG, bdisp->regs + BLT_AQ1_CTL);
1105*4882a593Smuzhiyun 	writel(BLT_ITS_AQ1_LNA, bdisp->regs + BLT_ITM0);
1106*4882a593Smuzhiyun 
1107*4882a593Smuzhiyun 	/* Write first node addr */
1108*4882a593Smuzhiyun 	writel(ctx->node_paddr[0], bdisp->regs + BLT_AQ1_IP);
1109*4882a593Smuzhiyun 
1110*4882a593Smuzhiyun 	/* Find and write last node addr : this starts the HW processing */
1111*4882a593Smuzhiyun 	for (node_id = 0; node_id < MAX_NB_NODE - 1; node_id++) {
1112*4882a593Smuzhiyun 		if (!ctx->node[node_id]->nip)
1113*4882a593Smuzhiyun 			break;
1114*4882a593Smuzhiyun 	}
1115*4882a593Smuzhiyun 	writel(ctx->node_paddr[node_id], bdisp->regs + BLT_AQ1_LNA);
1116*4882a593Smuzhiyun 
1117*4882a593Smuzhiyun 	return 0;
1118*4882a593Smuzhiyun }
1119