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
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
|
/*
* Copyright (c) 2016 Samsung Electronics Co., Ltd.
* http://www.samsung.com
*
* Window update file for Samsung EXYNOS DPU driver
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include <video/mipi_display.h>
#include "decon.h"
#include "dpp.h"
#include "dsim.h"
static void win_update_adjust_region(struct decon_device *decon,
struct decon_win_config *win_config,
struct decon_reg_data *regs)
{
int i;
int div_w, div_h;
#ifdef CONFIG_SUPPORT_DOZE
struct panel_state *state = decon->panel_state;
#endif
struct decon_rect r1, r2;
struct decon_win_config *update_config = &win_config[DECON_WIN_UPDATE_IDX];
struct decon_win_config *config;
regs->need_update = false;
DPU_FULL_RECT(®s->up_region, decon->lcd_info);
if (decon->force_fullupdate) {
decon->force_fullupdate = 0;
return;
}
if (!decon->win_up.enabled)
return;
#ifdef CONFIG_SUPPORT_DOZE
if (state->cur_state == PANEL_STATE_ALPM)
return;
#endif
if (update_config->state != DECON_WIN_STATE_UPDATE)
return;
if ((update_config->dst.x < 0) || (update_config->dst.y < 0)) {
update_config->state = DECON_WIN_STATE_DISABLED;
return;
}
r1.left = update_config->dst.x;
r1.top = update_config->dst.y;
r1.right = r1.left + update_config->dst.w - 1;
r1.bottom = r1.top + update_config->dst.h - 1;
for (i = 0; i < decon->dt.max_win; i++) {
config = &win_config[i];
if (config->state != DECON_WIN_STATE_DISABLED) {
if (config->dpp_parm.flip || is_scaling(config)) {
update_config->state = DECON_WIN_STATE_DISABLED;
return;
}
}
}
DPU_DEBUG_WIN("original update region[%d %d %d %d]\n",
update_config->dst.x, update_config->dst.y,
update_config->dst.w, update_config->dst.h);
r2.left = (r1.left / decon->win_up.rect_w) * decon->win_up.rect_w;
r2.top = (r1.top / decon->win_up.rect_h) * decon->win_up.rect_h;
div_w = (r1.right + 1) / decon->win_up.rect_w;
div_w = (div_w * decon->win_up.rect_w == r1.right + 1) ? div_w : div_w + 1;
r2.right = div_w * decon->win_up.rect_w - 1;
div_h = (r1.bottom + 1) / decon->win_up.rect_h;
div_h = (div_h * decon->win_up.rect_h == r1.bottom + 1) ? div_h : div_h + 1;
r2.bottom = div_h * decon->win_up.rect_h - 1;
/* TODO: Now, 4 slices must be used. This will be modified */
r2.left = 0;
r2.right = decon->lcd_info->xres - 1;
memcpy(®s->up_region, &r2, sizeof(struct decon_rect));
DPU_DEBUG_WIN("adjusted update region[%d %d %d %d]\n",
regs->up_region.left, regs->up_region.top,
regs->up_region.right - regs->up_region.left + 1,
regs->up_region.bottom - regs->up_region.top + 1);
}
static void win_update_check_limitation(struct decon_device *decon,
struct decon_win_config *win_config,
struct decon_reg_data *regs)
{
struct decon_win_config *config;
struct decon_win_rect update;
struct decon_rect r;
int i;
int adj_src_x = 0, adj_src_y = 0;
for (i = 0; i < decon->dt.max_win; i++) {
config = &win_config[i];
if (config->state == DECON_WIN_STATE_DISABLED)
continue;
r.left = config->dst.x;
r.top = config->dst.y;
r.right = config->dst.w + config->dst.x - 1;
r.bottom = config->dst.h + config->dst.y - 1;
if (!decon_intersect(®s->up_region, &r))
continue;
decon_intersection(®s->up_region, &r, &r);
if (!(r.right - r.left) && !(r.bottom - r.top))
continue;
if (dpu_get_plane_cnt(config->format) == 1) {
if (((r.right - r.left) < SRC_WIDTH_MIN) ||
((r.bottom - r.top) < SRC_HEIGHT_MIN)) {
goto change_full;
}
} else {
if (((r.right - r.left) < (SRC_WIDTH_MIN * 2)) ||
((r.bottom - r.top) < (SRC_HEIGHT_MIN))) {
goto change_full;
}
/* check alignment for NV12/NV21 format */
update.x = regs->up_region.left;
update.y = regs->up_region.top;
if (update.y > config->dst.y)
adj_src_y = config->src.y + (update.y - config->dst.y);
if (update.x > config->dst.x)
adj_src_x = config->src.x + (update.x - config->dst.x);
if (adj_src_x & 0x1 || adj_src_y & 0x1)
goto change_full;
}
}
return;
change_full:
DPU_DEBUG_WIN("changed full: win(%d) idma(%d) [%d %d %d %d]\n",
i, config->idma_type,
config->dst.x, config->dst.y,
config->dst.w, config->dst.h);
DPU_FULL_RECT(®s->up_region, decon->lcd_info);
}
static void win_update_reconfig_coordinates(struct decon_device *decon,
struct decon_win_config *win_config,
struct decon_reg_data *regs)
{
struct decon_win_config *config;
struct decon_win_rect update;
struct decon_frame origin_dst, origin_src;
struct decon_rect r;
int i;
/* Assume that, window update doesn't support in case of scaling */
for (i = 0; i < decon->dt.max_win; i++) {
config = &win_config[i];
if (config->state == DECON_WIN_STATE_DISABLED)
continue;
r.left = config->dst.x;
r.top = config->dst.y;
r.right = r.left + config->dst.w - 1;
r.bottom = r.top + config->dst.h - 1;
if (!decon_intersect(®s->up_region, &r)) {
config->state = DECON_WIN_STATE_DISABLED;
continue;
}
update.x = regs->up_region.left;
update.y = regs->up_region.top;
update.w = regs->up_region.right - regs->up_region.left + 1;
update.h = regs->up_region.bottom - regs->up_region.top + 1;
memcpy(&origin_dst, &config->dst, sizeof(struct decon_frame));
memcpy(&origin_src, &config->src, sizeof(struct decon_frame));
/* reconfigure destination coordinates */
if (update.x > config->dst.x)
config->dst.w = min(update.w,
config->dst.x + config->dst.w - update.x);
else if (update.x + update.w < config->dst.x + config->dst.w)
config->dst.w = min(config->dst.w,
update.w + update.x - config->dst.x);
if (update.y > config->dst.y)
config->dst.h = min(update.h,
config->dst.y + config->dst.h - update.y);
else if (update.y + update.h < config->dst.y + config->dst.h)
config->dst.h = min(config->dst.h,
update.h + update.y - config->dst.y);
config->dst.x = max(config->dst.x - update.x, 0);
config->dst.y = max(config->dst.y - update.y, 0);
/* reconfigure source coordinates */
if (update.y > origin_dst.y)
config->src.y += (update.y - origin_dst.y);
if (update.x > origin_dst.x)
config->src.x += (update.x - origin_dst.x);
config->src.w = config->dst.w;
config->src.h = config->dst.h;
DPU_DEBUG_WIN("win(%d), idma(%d)\n", i, config->idma_type);
DPU_DEBUG_WIN("src: origin[%d %d %d %d] -> change[%d %d %d %d]\n",
origin_src.x, origin_src.y,
origin_src.w, origin_src.h,
config->src.x, config->src.y,
config->src.w, config->src.h);
DPU_DEBUG_WIN("dst: origin[%d %d %d %d] -> change[%d %d %d %d]\n",
origin_dst.x, origin_dst.y,
origin_dst.w, origin_dst.h,
config->dst.x, config->dst.y,
config->dst.w, config->dst.h);
}
}
void dpu_prepare_win_update_config(struct decon_device *decon,
struct decon_win_config_data *win_data,
struct decon_reg_data *regs)
{
struct decon_win_config *win_config = win_data->config;
bool reconfigure = false;
struct decon_rect r;
#ifdef CONFIG_SUPPORT_DSU
struct decon_lcd dsu_info;
#endif
if (!decon->win_up.enabled)
return;
if (decon->dt.out_type != DECON_OUT_DSI)
return;
#ifdef CONFIG_SUPPORT_DSU
if (regs->dsu.needupdate) {
memset(&dsu_info, 0, sizeof(struct decon_lcd));
dsu_info.xres = regs->dsu.right;
dsu_info.yres = regs->dsu.bottom;
DPU_FULL_RECT(®s->up_region, &dsu_info);
memcpy(&decon->win_up.prev_up_region, ®s->up_region,
sizeof(struct decon_rect));
decon_info("DECON:INFO:%s: DSU Config fullupdate : %d %d\n",
__func__, regs->up_region.left, regs->up_region.bottom);
return;
}
#endif
/* find adjusted update region on LCD */
win_update_adjust_region(decon, win_config, regs);
/* check DPP hw limitation if violated, update region is changed to full */
win_update_check_limitation(decon, win_config, regs);
/*
* If update region is changed, need_update flag is set.
* That means hw configuration is needed
*/
if (is_decon_rect_differ(&decon->win_up.prev_up_region, ®s->up_region))
regs->need_update = true;
else
regs->need_update = false;
/*
* If partial update region is requested, source and destination
* coordinates are needed to change if overlapped with update region.
*/
DPU_FULL_RECT(&r, decon->lcd_info);
if (is_decon_rect_differ(®s->up_region, &r))
reconfigure = true;
if (regs->need_update || reconfigure)
DPU_DEBUG_WIN("need_update(%d), reconfigure(%d)\n",
regs->need_update, reconfigure);
/* Reconfigure source and destination coordinates, if needed. */
if (reconfigure)
win_update_reconfig_coordinates(decon, win_config, regs);
/* TODO: This will be moved after applied hw configuration. */
memcpy(&decon->win_up.prev_up_region, ®s->up_region,
sizeof(struct decon_rect));
}
#define COLUMN_CMD_SIZE 5
#define PAGE_CMD_SIZE 5
static int win_update_send_partial_command(struct dsim_device *dsim,
struct decon_rect *rect)
{
int retry;
char page[COLUMN_CMD_SIZE];
char column[PAGE_CMD_SIZE];
DPU_DEBUG_WIN("SET: [%d %d %d %d]\n", rect->left, rect->top,
rect->right - rect->left + 1, rect->bottom - rect->top + 1);
column[0] = MIPI_DCS_SET_COLUMN_ADDRESS;
column[1] = (rect->left >> 8) & 0xff;
column[2] = rect->left & 0xff;
column[3] = (rect->right >> 8) & 0xff;
column[4] = rect->right & 0xff;
page[0] = MIPI_DCS_SET_PAGE_ADDRESS;
page[1] = (rect->top >> 8) & 0xff;
page[2] = rect->top & 0xff;
page[3] = (rect->bottom >> 8) & 0xff;
page[4] = rect->bottom & 0xff;
retry = 2;
while (dsim_write_data(dsim, MIPI_DSI_DCS_LONG_WRITE,
column, COLUMN_CMD_SIZE) != COLUMN_CMD_SIZE) {
dsim_err("failed to write COLUMN_ADDRESS\n");
if (--retry <= 0) {
dsim_err("COLUMN_ADDRESS is failed: exceed retry count\n");
return -EINVAL;
}
}
retry = 2;
while (dsim_write_data(dsim, MIPI_DSI_DCS_LONG_WRITE,
page, PAGE_CMD_SIZE) != PAGE_CMD_SIZE) {
dsim_err("failed to write PAGE_ADDRESS\n");
if (--retry <= 0) {
dsim_err("PAGE_ADDRESS is failed: exceed retry count\n");
return -EINVAL;
}
}
return 0;
}
static void win_update_find_included_slice(struct decon_lcd *lcd,
struct decon_rect *rect, bool in_slice[])
{
int slice_left, slice_right, slice_width;
int i;
slice_left = 0;
slice_right = 0;
slice_width = lcd->xres / lcd->dsc_slice_num;
for (i = 0; i < lcd->dsc_slice_num; ++i) {
slice_left = slice_width * i;
slice_right = slice_left + slice_width - 1;
in_slice[i] = false;
if ((slice_left >= rect->left) && (slice_right <= rect->right))
in_slice[i] = true;
DPU_DEBUG_WIN("slice_left(%d), right(%d)\n", slice_left, slice_right);
DPU_DEBUG_WIN("slice[%d] is %s\n", i,
in_slice[i] ? "included" : "not included");
}
}
static void win_update_set_partial_size(struct decon_device *decon,
struct decon_rect *rect)
{
struct decon_lcd lcd_info;
struct dsim_device *dsim = get_dsim_drvdata(0);
bool in_slice[MAX_DSC_SLICE_CNT];
memcpy(&lcd_info, decon->lcd_info, sizeof(struct decon_lcd));
lcd_info.xres = rect->right - rect->left + 1;
lcd_info.yres = rect->bottom - rect->top + 1;
lcd_info.hfp = decon->lcd_info->hfp +
((decon->lcd_info->xres - lcd_info.xres) >> 1);
lcd_info.vfp = decon->lcd_info->vfp + decon->lcd_info->yres - lcd_info.yres;
dsim_reg_set_partial_update(dsim->id, &lcd_info);
win_update_find_included_slice(decon->lcd_info, rect, in_slice);
decon_reg_set_partial_update(decon->id, decon->dt.dsi_mode, &lcd_info,
in_slice);
DPU_DEBUG_WIN("SET: vfp %d vbp %d vsa %d hfp %d hbp %d hsa %d w %d h %d\n",
lcd_info.vfp, lcd_info.vbp, lcd_info.vsa,
lcd_info.hfp, lcd_info.hbp, lcd_info.hsa,
lcd_info.xres, lcd_info.yres);
}
void dpu_set_win_update_config(struct decon_device *decon,
struct decon_reg_data *regs)
{
struct dsim_device *dsim = get_dsim_drvdata(0);
bool in_slice[MAX_DSC_SLICE_CNT];
bool full_partial_update = false;
if (!decon->win_up.enabled)
return;
if (decon->dt.out_type != DECON_OUT_DSI)
return;
if (regs == NULL) {
regs = kzalloc(sizeof(struct decon_reg_data), GFP_KERNEL);
if (!regs) {
decon_err("%s:set window update config fail\
reg_data allocation fail\n", __func__);
return;
}
DPU_FULL_RECT(®s->up_region, decon->lcd_info);
regs->need_update = true;
full_partial_update = true;
}
if (decon->force_fullupdate) {
DPU_FULL_RECT(®s->up_region, decon->lcd_info);
regs->need_update = true;
}
if (regs->need_update) {
win_update_find_included_slice(decon->lcd_info,
®s->up_region, in_slice);
/* TODO: Is waiting framedone irq needed in KC ? */
/*
* hw configuration related to partial update must be set
* without DMA operation
*/
decon_reg_wait_idle_status_timeout(decon->id, IDLE_WAIT_TIMEOUT);
win_update_send_partial_command(dsim, ®s->up_region);
win_update_set_partial_size(decon, ®s->up_region);
}
if (full_partial_update)
kfree(regs);
}
void dpu_set_win_update_partial_size(struct decon_device *decon,
struct decon_rect *up_region)
{
if (!decon->win_up.enabled)
return;
win_update_set_partial_size(decon, up_region);
}
void dpu_init_win_update(struct decon_device *decon)
{
struct decon_lcd *lcd = decon->lcd_info;
decon->win_up.enabled = false;
if (!IS_ENABLED(CONFIG_FB_WINDOW_UPDATE)) {
decon_info("window update feature is disabled\n");
return;
}
if (decon->dt.out_type != DECON_OUT_DSI) {
decon_info("out_type(%d) doesn't support window update\n",
decon->dt.out_type);
return;
}
if (lcd->dsc_enabled) {
decon->win_up.rect_w = lcd->xres / lcd->dsc_slice_num;
decon->win_up.rect_h = lcd->dsc_slice_h;
} else {
decon->win_up.rect_w = MIN_WIN_BLOCK_WIDTH;
decon->win_up.rect_h = MIN_WIN_BLOCK_HEIGHT;
}
DPU_FULL_RECT(&decon->win_up.prev_up_region, lcd);
decon->win_up.hori_cnt = decon->lcd_info->xres / decon->win_up.rect_w;
if (decon->lcd_info->xres - decon->win_up.hori_cnt * decon->win_up.rect_w) {
decon_warn("%s: parameters is wrong. lcd w(%d), win rect w(%d)\n",
__func__, decon->lcd_info->xres,
decon->win_up.rect_w);
return;
}
decon->win_up.verti_cnt = decon->lcd_info->yres / decon->win_up.rect_h;
if (decon->lcd_info->yres - decon->win_up.verti_cnt * decon->win_up.rect_h) {
decon_warn("%s: parameters is wrong. lcd h(%d), win rect h(%d)\n",
__func__, decon->lcd_info->yres,
decon->win_up.rect_h);
return;
}
decon_info("window update is enabled: win rectangle w(%d), h(%d)\n",
decon->win_up.rect_w, decon->win_up.rect_h);
decon_info("horizontal count(%d), vertical count(%d)\n",
decon->win_up.hori_cnt, decon->win_up.verti_cnt);
decon->win_up.enabled = true;
}
|