1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
|
/* linux/drivers/video/exynos/decon/vpp/vpp_regs.c
*
* Copyright (c) 2011 Samsung Electronics Co., Ltd.
* http://www.samsung.com
*
* Samsung EXYNOS5 SoC series G-scaler driver
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 2 of the License,
* or (at your option) any later version.
*/
#include <linux/io.h>
#include <linux/delay.h>
#include <linux/ktime.h>
#include <mach/map.h>
#include "vpp_core.h"
#define VPP_SC_RATIO_MAX ((1 << 20) * 8 / 8)
#define VPP_SC_RATIO_7_8 ((1 << 20) * 8 / 7)
#define VPP_SC_RATIO_6_8 ((1 << 20) * 8 / 6)
#define VPP_SC_RATIO_5_8 ((1 << 20) * 8 / 5)
#define VPP_SC_RATIO_4_8 ((1 << 20) * 8 / 4)
#define VPP_SC_RATIO_3_8 ((1 << 20) * 8 / 3)
extern const s16 h_coef_8t[7][16][8];
extern const s16 v_coef_4t[7][16][4];
int vpp_hw_wait_op_status(struct vpp_dev *vpp)
{
u32 cfg = 0;
ktime_t start = ktime_get();
do {
cfg = readl(vpp->regs + VG_ENABLE);
if (!(cfg & (VG_ENABLE_OP_STATUS)))
return 0;
udelay(10);
} while(ktime_us_delta(ktime_get(), start) < 1000000);
dev_err(DEV, "timeout op_status to idle\n");
return -EBUSY;
}
void vpp_hw_wait_idle(struct vpp_dev *vpp)
{
u32 cfg = 0;
ktime_t start = ktime_get();
do {
cfg = readl(vpp->regs + VG_ENABLE);
if (!(cfg & (VG_ENABLE_OP_STATUS)))
return;
dev_warn(DEV, "vpp%d is operating...\n", vpp->id);
udelay(10);
} while(ktime_us_delta(ktime_get(), start) < 1000000);
dev_err(DEV, "timeout op_status to idle\n");
}
int vpp_hw_set_sw_reset(struct vpp_dev *vpp)
{
u32 cfg = 0;
ktime_t start;
cfg = readl(vpp->regs + VG_ENABLE);
cfg |= VG_ENABLE_SRESET;
writel(cfg, vpp->regs + VG_ENABLE);
start = ktime_get();
do {
cfg = readl(vpp->regs + VG_ENABLE);
if (!(cfg & (VG_ENABLE_SRESET)))
return 0;
udelay(10);
} while(ktime_us_delta(ktime_get(), start) < 1000000);
dev_err(DEV, "timeout sw reset\n");
return -EBUSY;
}
void vpp_hw_set_realtime_path(struct vpp_dev *vpp)
{
u32 cfg = readl(vpp->regs + VG_ENABLE);
cfg |= VG_ENABLE_RT_PATH_EN;
writel(cfg, vpp->regs + VG_ENABLE);
}
void vpp_hw_set_framedone_irq(struct vpp_dev *vpp, bool enable)
{
u32 cfg = readl(vpp->regs + VG_IRQ);
if (enable)
cfg |= VG_IRQ_FRAMEDONE_MASK;
else
cfg &= ~VG_IRQ_FRAMEDONE_MASK;
writel(cfg, vpp->regs + VG_IRQ);
}
void vpp_hw_set_deadlock_irq(struct vpp_dev *vpp, bool enable)
{
u32 cfg = readl(vpp->regs + VG_IRQ);
if (enable)
cfg |= VG_IRQ_DEADLOCK_STATUS_MASK;
else
cfg &= ~VG_IRQ_DEADLOCK_STATUS_MASK;
writel(cfg, vpp->regs + VG_IRQ);
}
void vpp_hw_set_read_slave_err_irq(struct vpp_dev *vpp, bool enable)
{
u32 cfg = readl(vpp->regs + VG_IRQ);
if (enable)
cfg |= VG_IRQ_READ_SLAVE_ERROR_MASK;
else
cfg &= ~VG_IRQ_READ_SLAVE_ERROR_MASK;
writel(cfg, vpp->regs + VG_IRQ);
}
void vpp_hw_set_sfr_update_done_irq(struct vpp_dev *vpp, bool enable)
{
u32 cfg = readl(vpp->regs + VG_IRQ);
if (enable)
cfg |= VG_IRQ_SFR_UPDATE_DONE_MASK;
else
cfg &= ~VG_IRQ_SFR_UPDATE_DONE_MASK;
writel(cfg, vpp->regs + VG_IRQ);
}
void vpp_hw_set_sfr_update_force(struct vpp_dev *vpp)
{
u32 cfg = readl(vpp->regs + VG_ENABLE);
cfg |= VG_ENABLE_SFR_UPDATE_FORCE;
writel(cfg, vpp->regs + VG_ENABLE);
}
void vpp_hw_set_enable_interrupt(struct vpp_dev *vpp)
{
u32 cfg = readl(vpp->regs + VG_IRQ);
cfg |= VG_IRQ_ENABLE;
writel(cfg, vpp->regs + VG_IRQ);
}
void vpp_hw_set_hw_reset_done_mask(struct vpp_dev *vpp, bool enable)
{
u32 cfg = readl(vpp->regs + VG_IRQ);
if (enable)
cfg |= VG_IRQ_HW_RESET_DONE_MASK;
else
cfg &= ~VG_IRQ_HW_RESET_DONE_MASK;
writel(cfg, vpp->regs + VG_IRQ);
}
int vpp_hw_set_in_format(struct vpp_dev *vpp)
{
struct decon_win_config *config = vpp->config;
u32 cfg = readl(vpp->regs + VG_IN_CON);
cfg &= ~(VG_IN_CON_IMG_FORMAT_MASK |
VG_IN_CON_CHROMINANCE_STRIDE_EN);
switch(config->format) {
case DECON_PIXEL_FORMAT_ARGB_8888:
cfg |= VG_IN_CON_IMG_FORMAT_ARGB8888;
break;
case DECON_PIXEL_FORMAT_ABGR_8888:
cfg |= VG_IN_CON_IMG_FORMAT_ABGR8888;
break;
case DECON_PIXEL_FORMAT_RGBA_8888:
cfg |= VG_IN_CON_IMG_FORMAT_RGBA8888;
break;
case DECON_PIXEL_FORMAT_BGRA_8888:
cfg |= VG_IN_CON_IMG_FORMAT_BGRA8888;
break;
case DECON_PIXEL_FORMAT_XRGB_8888:
cfg |= VG_IN_CON_IMG_FORMAT_XRGB8888;
break;
case DECON_PIXEL_FORMAT_XBGR_8888:
cfg |= VG_IN_CON_IMG_FORMAT_XBGR8888;
break;
case DECON_PIXEL_FORMAT_RGBX_8888:
cfg |= VG_IN_CON_IMG_FORMAT_RGBX8888;
break;
case DECON_PIXEL_FORMAT_BGRX_8888:
cfg |= VG_IN_CON_IMG_FORMAT_BGRX8888;
break;
case DECON_PIXEL_FORMAT_RGB_565:
cfg |= VG_IN_CON_IMG_FORMAT_RGB565;
break;
case DECON_PIXEL_FORMAT_NV16:
cfg |= VG_IN_CON_IMG_FORMAT_YUV422_2P;
break;
case DECON_PIXEL_FORMAT_NV61:
cfg |= VG_IN_CON_IMG_FORMAT_YVU422_2P;
break;
case DECON_PIXEL_FORMAT_NV12:
case DECON_PIXEL_FORMAT_NV12M:
cfg |= VG_IN_CON_IMG_FORMAT_YUV420_2P;
break;
case DECON_PIXEL_FORMAT_NV21:
case DECON_PIXEL_FORMAT_NV21M:
cfg |= VG_IN_CON_IMG_FORMAT_YVU420_2P;
break;
default:
dev_err(DEV, "Unsupported Format\n");
return -EINVAL ;
}
writel(cfg, vpp->regs + VG_IN_CON);
return 0;
}
void vpp_hw_set_h_coef(struct vpp_dev *vpp, u32 h_ratio)
{
int i, j, k, sc_ratio;
if (h_ratio <= VPP_SC_RATIO_MAX)
sc_ratio = 0;
else if (h_ratio <= VPP_SC_RATIO_7_8)
sc_ratio = 1;
else if (h_ratio <= VPP_SC_RATIO_6_8)
sc_ratio = 2;
else if (h_ratio <= VPP_SC_RATIO_5_8)
sc_ratio = 3;
else if (h_ratio <= VPP_SC_RATIO_4_8)
sc_ratio = 4;
else if (h_ratio <= VPP_SC_RATIO_3_8)
sc_ratio = 5;
else
sc_ratio = 6;
for (i = 0; i < 9; i++) {
for (j = 0; j < 8; j++) {
for (k = 0; k < 2; k++) {
__raw_writel(h_coef_8t[sc_ratio][i][j],
vpp->regs + VG_H_COEF(i, j, k));
}
}
}
}
void vpp_hw_set_v_coef(struct vpp_dev *vpp, u32 v_ratio)
{
int i, j, k, sc_ratio;
if (v_ratio <= VPP_SC_RATIO_MAX)
sc_ratio = 0;
else if (v_ratio <= VPP_SC_RATIO_7_8)
sc_ratio = 1;
else if (v_ratio <= VPP_SC_RATIO_6_8)
sc_ratio = 2;
else if (v_ratio <= VPP_SC_RATIO_5_8)
sc_ratio = 3;
else if (v_ratio <= VPP_SC_RATIO_4_8)
sc_ratio = 4;
else if (v_ratio <= VPP_SC_RATIO_3_8)
sc_ratio = 5;
else
sc_ratio = 6;
for (i = 0; i < 9; i++) {
for (j = 0; j < 4; j++) {
for (k = 0; k < 2; k++) {
__raw_writel(v_coef_4t[sc_ratio][i][j],
vpp->regs + VG_V_COEF(i, j, k));
}
}
}
}
int vpp_hw_set_rotation(struct vpp_dev *vpp)
{
struct decon_win_config *config = vpp->config;
u32 cfg = readl(vpp->regs + VG_IN_CON);
cfg &= ~VG_IN_CON_IN_ROTATION_MASK;
cfg |= config->vpp_parm.rot << 8;
writel(cfg, vpp->regs + VG_IN_CON);
return 0;
}
void vpp_hw_set_scale_ratio(struct vpp_dev *vpp)
{
struct decon_win_config *config = vpp->config;
struct vpp_fraction *fr = &vpp->fract_val;
u32 h_ratio, v_ratio = 0;
u32 tmp_width, tmp_height = 0;
u32 tmp_fr_w, tmp_fr_h = 0;
if (is_rotation(config)) {
tmp_width = config->src.h;
tmp_height = config->src.w;
tmp_fr_w = fr->h;
tmp_fr_h = fr->w;
} else {
tmp_width = config->src.w;
tmp_height = config->src.h;
tmp_fr_w = fr->w;
tmp_fr_h = fr->h;
}
h_ratio = ((tmp_width << 20) + tmp_fr_w) / config->dst.w;
v_ratio = ((tmp_height << 20) + tmp_fr_h) / config->dst.h;
if (vpp->h_ratio != h_ratio) {
writel(h_ratio, vpp->regs + VG_H_RATIO);
vpp_hw_set_h_coef(vpp, h_ratio);
}
if (vpp->v_ratio != v_ratio) {
writel(v_ratio, vpp->regs + VG_V_RATIO);
vpp_hw_set_v_coef(vpp, v_ratio);
}
vpp->h_ratio = h_ratio;
vpp->v_ratio = v_ratio;
dev_dbg(DEV, "h_ratio : %#x, v_ratio : %#x\n",
h_ratio, v_ratio);
}
void vpp_hw_set_in_buf_addr(struct vpp_dev *vpp)
{
struct decon_device *decon = get_decon_drvdata(0);
struct vpp_params *vpp_parm = &vpp->config->vpp_parm;
dma_addr_t cb_addr = 0;
u32 addr;
dev_dbg(DEV, "y : %pa, cb : %pa, cr : %pa\n",
&vpp_parm->addr[0], &vpp_parm->addr[1], &vpp_parm->addr[2]);
writel(vpp_parm->addr[0], vpp->regs + VG_BASE_ADDR_Y(0));
writel(vpp_parm->addr[1], vpp->regs + VG_BASE_ADDR_CB(0));
if (vpp->id == 2)
cb_addr = decon->vgr0_cb_addr;
else if (vpp->id == 3)
cb_addr = decon->vgr1_cb_addr;
if(cb_addr > 0) {
addr = readl(vpp->regs + VG_BASE_ADDR_CB(0));
if(addr != (u32)cb_addr)
dev_err(DEV, "vpp CB_ADDR is incorrect(0x%x, 0x%x\n",
addr, (u32)cb_addr);
}
}
void vpp_hw_set_in_size(struct vpp_dev *vpp)
{
struct decon_win_config *config = vpp->config;
u32 cfg = 0;
/* source offset */
cfg = VG_SRC_OFFSET_X(config->src.x);
cfg |= VG_SRC_OFFSET_Y(config->src.y);
writel(cfg, vpp->regs + VG_SRC_OFFSET);
/* source full(alloc) size */
cfg = VG_SRC_SIZE_WIDTH(config->src.f_w);
cfg |= VG_SRC_SIZE_HEIGHT(config->src.f_h);
writel(cfg, vpp->regs + VG_SRC_SIZE);
/* source cropped size */
cfg = VG_IMG_SIZE_WIDTH(config->src.w);
cfg |= VG_IMG_SIZE_HEIGHT(config->src.h);
writel(cfg, vpp->regs + VG_IMG_SIZE);
if (vpp->fract_val.w)
config->src.w--;
if (vpp->fract_val.h)
config->src.h--;
/* fraction position */
writel(vpp->fract_val.y_x, vpp->regs + VG_YHPOSITION0);
writel(vpp->fract_val.y_y, vpp->regs + VG_YVPOSITION0);
writel(vpp->fract_val.c_x, vpp->regs + VG_CHPOSITION0);
writel(vpp->fract_val.c_y, vpp->regs + VG_CVPOSITION0);
}
void vpp_hw_set_in_block_size(struct vpp_dev *vpp, bool enable)
{
struct decon_win_config *config = vpp->config;
u32 cfg = 0;
if (!enable) {
cfg = readl(vpp->regs + VG_IN_CON);
cfg &= ~VG_IN_CON_BLOCKING_FEATURE_EN;
writel(cfg, vpp->regs + VG_IN_CON);
return;
}
/* blocking area offset */
cfg = VG_BLK_OFFSET_X(config->block_area.x);
cfg |= VG_BLK_OFFSET_Y(config->block_area.y);
writel(cfg, vpp->regs + VG_BLK_OFFSET);
/* blocking area size */
cfg = VG_BLK_SIZE_WIDTH(config->block_area.w);
cfg |= VG_BLK_SIZE_HEIGHT(config->block_area.h);
writel(cfg, vpp->regs + VG_BLK_SIZE);
cfg = readl(vpp->regs + VG_IN_CON);
cfg |= VG_IN_CON_BLOCKING_FEATURE_EN;
writel(cfg, vpp->regs + VG_IN_CON);
dev_dbg(DEV, "block x : %d, y : %d, w : %d, h : %d\n",
config->block_area.x, config->block_area.y,
config->block_area.w, config->block_area.h);
}
void vpp_hw_set_out_size(struct vpp_dev *vpp)
{
struct decon_win_config *config = vpp->config;
u32 cfg = 0;
/* destination scaled size */
cfg = VG_SCALED_SIZE_WIDTH(config->dst.w);
cfg |= VG_SCALED_SIZE_HEIGHT(config->dst.h);
writel(cfg, vpp->regs + VG_SCALED_SIZE);
}
void vpp_hw_set_rgb_type(struct vpp_dev *vpp)
{
u32 cfg = VG_OUT_CON_RGB_TYPE_601_WIDE;
writel(cfg, vpp->regs + VG_OUT_CON);
}
void vpp_hw_set_plane_alpha(struct vpp_dev *vpp)
{
struct decon_win_config *config = vpp->config;
u32 cfg = readl(vpp->regs + VG_OUT_CON);
if (config->plane_alpha > 0xFF)
dev_warn(DEV, "%d is too much value\n",
config->plane_alpha);
cfg &= ~VG_OUT_CON_FRAME_ALPHA_MASK;
cfg |= VG_OUT_CON_FRAME_ALPHA(config->plane_alpha);
writel(cfg, vpp->regs + VG_OUT_CON);
}
void vpp_hw_set_plane_alpha_fixed(struct vpp_dev *vpp)
{
u32 cfg = readl(vpp->regs + VG_OUT_CON);
cfg &= ~VG_OUT_CON_FRAME_ALPHA_MASK;
cfg |= VG_OUT_CON_FRAME_ALPHA(0xFF);
writel(cfg, vpp->regs + VG_OUT_CON);
}
void vpp_hw_set_smart_if_pix_num(struct vpp_dev *vpp)
{
struct decon_win_config *config = vpp->config;
u32 cfg = readl(vpp->regs + VG_SMART_IF_PIXEL_NUM);
cfg = config->dst.w * config->dst.h;
writel(cfg, vpp->regs + VG_SMART_IF_PIXEL_NUM);
}
void vpp_hw_set_lookup_table(struct vpp_dev *vpp)
{
writel(0x44444444, vpp->regs + VG_QOS_LUT07_00);
writel(0x44444444, vpp->regs + VG_QOS_LUT15_08);
}
void vpp_hw_set_dynamic_clock_gating(struct vpp_dev *vpp)
{
writel(0x3F, vpp->regs + VG_DYNAMIC_GATING_ENABLE);
}
|