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
|
/* iva_vdma.c
*
* Copyright (C) 2016 Samsung Electronics Co.Ltd
* Authors:
* Ilkwan Kim <ilkwan.kim@samsung.com>
*
* 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/kernel.h>
#include <linux/stat.h>
#include <linux/fs.h>
#include <linux/io.h>
#include <linux/time.h>
#include "regs/iva_base_addr.h"
#include "regs/iva_vdma_reg.h"
#include "iva_pmu.h"
#if defined(CONFIG_SOC_EXYNOS8895)
#include "iva_vdma.h"
#elif defined(CONFIG_SOC_EXYNOS9810)
#include "iva_vdma20.h"
#endif
/* pixel/data types */
enum data_fmt_t {
e_data_8b = 0,
e_data_16b,
e_data_32b,
e_data_64b,
e_data_128b,
e_data_fmt_invalid = 255
};
enum vdma_ttype {
vdma_ttype_ext_to_loc = 0,
vdma_ttype_loc_to_ext = 1,
vdma_ttype_loc_to_loc = 2,
vdma_ttype_ext_to_ext = 3,
vdma_ttype_max
};
enum vdma_addr_mode {
vdma_addr_mode_2d = 0,
vdma_addr_mode_linear = 1,
vdma_addr_mode_max,
};
enum vdma_planar_mode {
vdma_planar = 0,
vdma_2_planes = 1,
vdma_3_planes = 2,
vdma_planar_max,
vdma_known = vdma_planar_max,/* not supported */
};
enum vdma_yuv_mode {
vdma_ym_yuyv = 0,
vdma_ym_yvyu = 1,
vdma_ym_uyvy = 2,
vdma_ym_vyuy = 3,
};
#define GET_DMA_CH_BASE_F_HANDLE(hdl) (IVA_VDMA0_BASE_ADDR +\
VDMA_CH_BASE_ADDR(HALDLE_TO_CH(hdl)))
static void vdma_clear_planar_config(void *ch_base)
{
#if 0 /* TO DO */
/* Planar mode of transfer */
writel(0x0, ch_base + VDE_CH_CFG_REG_YUV_ADDR);
/* clear the Planar buffer configurations not to use flow-control */
writel(0x0, ch_base + VDE_CH_P_CBWCFG_ADDR(0, 0));
writel(0x0, ch_base + VDE_CH_P_CBRCFG_ADDR(0, 0));
writel(0x0, ch_base + VDE_CH_P_CBWCFG_ADDR(1, 0));
writel(0x0, ch_base + VDE_CH_P_CBRCFG_ADDR(1, 0));
writel(0x0, ch_base + VDE_CH_P_CBWCFG_ADDR(2, 0));
writel(0x0, ch_base + VDE_CH_P_CBRCFG_ADDR(2, 0));
#endif
}
void iva_vdma_start_cmd(struct iva_dev_data *iva, uint32_t handle)
{
void *ch_base = iva->iva_va + GET_DMA_CH_BASE_F_HANDLE(handle);
/* start the DMA transfer really */
writel(VDMA_CH_CMD_TR_START, ch_base + VDMA_CH_CMD_ADDR);
}
/* busy wait*/
void iva_vdma_wait_done(struct iva_dev_data *iva, uint32_t handle)
{
void *dma_base = iva->iva_va + IVA_VDMA0_BASE_ADDR;
uint32_t ch_mask = 0x1 << HALDLE_TO_CH(handle);
uint32_t val;
do {
val = readl(dma_base + VDMA_IRQ_RAW_STATUS_DONE_ADDR);
} while (!(val & ch_mask)); /* RSTAT_DONE high = done */
/* clear */
writel(ch_mask, dma_base + VDMA_IRQ_RAW_STATUS_DONE_ADDR);
}
int32_t iva_vdma_config_dram_to_mcu(struct iva_dev_data *iva,
uint32_t handle, uint32_t io_va,
uint32_t mcu_addr, uint32_t x_size, bool start)
{
uint32_t val;
void *ch_base = iva->iva_va + GET_DMA_CH_BASE_F_HANDLE(handle);
/* config for external source */
val = (vdma_addr_mode_linear << VDMA_CH_CFG4_ADDR_MODE_S) |
(vdma_ttype_ext_to_ext << VDMA_CH_CFG4_TTYPE_S) |
(e_data_8b << VDMA_CH_CFG4_BPP_S);
writel(val, ch_base + VDMA_CH_CFG4_ADDR);
/* linear transfer size, TO DO: size check*/
writel(x_size, ch_base + VDMA_CH_CFG5_ADDR);
/* global source (iova) and mcu */
writel(io_va, ch_base + VDMA_CH_CFG0_ADDR);
writel(mcu_addr + IVA_VMCU_MEM_BASE_ADDR, ch_base + VDMA_CH_CFG1_ADDR);
/* clear to planar mode w/o flow-control */
vdma_clear_planar_config(ch_base);
/* clear the vCF circular buffer RP/WP configuration */
writel(0x0, ch_base + VDMA_CH_CBRCFG_ADDR(0));
writel(0x0, ch_base + VDMA_CH_CBWCFG_ADDR(0));
if (start)
iva_vdma_start_cmd(iva, handle);
return 0;
}
int32_t iva_vdma_enable(struct iva_dev_data *iva, bool enable)
{
if (enable) {
iva_pmu_enable_clk(iva, pmu_vdma_id, true);
iva_pmu_reset_hwa(iva, pmu_vdma_id, false);
iva_pmu_reset_hwa(iva, pmu_vdma_id, true);
} else {
iva_pmu_reset_hwa(iva, pmu_vdma_id, false);
iva_pmu_enable_clk(iva, pmu_vdma_id, false);
}
return 0;
}
static const char *iva_vdma_get_irq_type_str(int32_t irq_type)
{
switch (irq_type) {
case IRQ_DONE: return "DONE";
case IRQ_READY: return "READY";
case IRQ_ERR: return "ERR";
case IRQ_HOST1_DONE: return "HOST1_DONE";
case IRQ_HOST1_READY: return "HOST1_READY";
case IRQ_HOST1_ERR: return "HOST1_ERR";
}
return "unknown";
}
struct iva_vdma_dump_reg {
const char *name;
const uint32_t reg_offset;
};
struct iva_vdma_dump_regs {
const struct iva_vdma_dump_reg *regs;
const uint32_t reg_num;
};
static const struct iva_vdma_dump_reg iva_vdma_common_reg[] = {
{ "STATUS", VDMA_CH_STATUS_ADDR },
{ "CFG0", VDMA_CH_CFG0_ADDR },
{ "CFG1", VDMA_CH_CFG1_ADDR },
{ "CFG2", VDMA_CH_CFG2_ADDR },
{ "CFG3", VDMA_CH_CFG3_ADDR },
{ "CFG4", VDMA_CH_CFG4_ADDR },
{ "CFG5", VDMA_CH_CFG5_ADDR },
{ "PRI", VDMA_CH_CFG_PRI_ADDR },
};
static const struct iva_vdma_dump_reg iva_vdma_ro_reg[] = {
{ "CBWCFG0", VDMA_CH_CBWCFG_ADDR(0) },
{ "CBWCFG1", VDMA_CH_CBWCFG_ADDR(1) },
{ "CBWCFG2", VDMA_CH_CBWCFG_ADDR(2) },
{ "CBWCFG3", VDMA_CH_CBWCFG_ADDR(3) },
{ "CBWCFG4", VDMA_CH_CBWCFG_ADDR(4) },
};
static const struct iva_vdma_dump_reg iva_vdma_ro_yuv_reg[] = {
{ "P1_DST", VDMA_CH_RO_YUV_P1_BUF_DST_ADDR },
{ "P2_DST", VDMA_CH_RO_YUV_P2_BUF_DST_ADDR },
{ "CFG6", VDMA_CH_CFG6_ADDR },
{ "P1_CBW_2", VDMA_CH_RO_YUV_P1_CBWCFG2_ADDR },
{ "P2_CBW_2", VDMA_CH_RO_YUV_P2_CBWCFG2_ADDR },
{ "UV_CBW_4", VDMA_CH_RO_YUV_UV_CBWCFG4_ADDR },
{ "P1_CBW_5", VDMA_CH_RO_YUV_P1_CBWCFG5_ADDR },
{ "P2_CBW_5", VDMA_CH_RO_YUV_P2_CBWCFG5_ADDR },
};
static const struct iva_vdma_dump_reg iva_vdma_ro_spl_reg[] = {
{ "TILECFG0", VDMA_CH_RO_SPL_TILE_CFG0_ADDR },
{ "TILECFG1", VDMA_CH_RO_SPL_TILE_CFG1_ADDR },
{ "TILECFG2", VDMA_CH_RO_SPL_TILE_CFG2_ADDR },
{ "TILECFG3", VDMA_CH_RO_SPL_TILE_CFG3_ADDR },
};
static const struct iva_vdma_dump_reg iva_vdma_wo_reg[] = {
{ "CBRCFG0", VDMA_CH_CBRCFG_ADDR(0) },
{ "CBRCFG1", VDMA_CH_CBRCFG_ADDR(1) },
{ "CBRCFG2", VDMA_CH_CBRCFG_ADDR(2) },
{ "CBRCFG3", VDMA_CH_CBRCFG_ADDR(3) },
{ "CBRCFG4", VDMA_CH_CBRCFG_ADDR(4) },
{ "ROICFG0", VDMA_CH_WO_ROICFG0_ADDR },
{ "ROICFG1", VDMA_CH_WO_ROICFG1_ADDR },
};
static const struct iva_vdma_dump_reg iva_vdma_wo_yuv_reg[] = {
{ "P1_SRC", VDMA_CH_WO_YUV_P1_BUF_SRC_ADDR },
{ "P2_SRC", VDMA_CH_WO_YUV_P2_BUF_SRC_ADDR },
{ "CFG6", VDMA_CH_CFG6_ADDR },
{ "P1_CBR_2", VDMA_CH_WO_YUV_P1_CBRCFG2_ADDR },
{ "P2_CBR_2", VDMA_CH_WO_YUV_P2_CBRCFG2_ADDR },
{ "UV_CBR_4", VDMA_CH_WO_YUV_UV_CBRCFG4_ADDR },
{ "UV_CBR_5", VDMA_CH_WO_YUV_UV_CBRCFG5_ADDR },
};
static const struct iva_vdma_dump_regs ro_list[] = {
{ iva_vdma_common_reg, ARRAY_SIZE(iva_vdma_common_reg) },
{ iva_vdma_ro_reg, ARRAY_SIZE(iva_vdma_ro_reg) },
{ NULL, 0 },
};
static const struct iva_vdma_dump_regs ro_yuv_list[] = {
{ iva_vdma_common_reg, ARRAY_SIZE(iva_vdma_common_reg) },
{ iva_vdma_ro_reg, ARRAY_SIZE(iva_vdma_ro_reg) },
{ iva_vdma_ro_yuv_reg, ARRAY_SIZE(iva_vdma_ro_yuv_reg) },
{ NULL, 0 },
};
static const struct iva_vdma_dump_regs ro_spl_list[] = {
{ iva_vdma_common_reg, ARRAY_SIZE(iva_vdma_common_reg) },
{ iva_vdma_ro_reg, ARRAY_SIZE(iva_vdma_ro_reg) },
{ iva_vdma_ro_spl_reg, ARRAY_SIZE(iva_vdma_ro_spl_reg) },
{ NULL, 0 },
};
static const struct iva_vdma_dump_regs wo_list[] = {
{ iva_vdma_common_reg, ARRAY_SIZE(iva_vdma_common_reg) },
{ iva_vdma_wo_reg, ARRAY_SIZE(iva_vdma_wo_reg) },
{ NULL, 0 },
};
static const struct iva_vdma_dump_regs wo_yuv_list[] = {
{ iva_vdma_common_reg, ARRAY_SIZE(iva_vdma_common_reg) },
{ iva_vdma_wo_reg, ARRAY_SIZE(iva_vdma_wo_reg) },
{ iva_vdma_wo_yuv_reg, ARRAY_SIZE(iva_vdma_wo_yuv_reg) },
{ NULL, 0 },
};
static const struct iva_vdma_dump_regs wr_list[] = {
{ iva_vdma_common_reg, ARRAY_SIZE(iva_vdma_common_reg) },
{ iva_vdma_ro_reg, ARRAY_SIZE(iva_vdma_ro_reg) },
{ iva_vdma_wo_reg, ARRAY_SIZE(iva_vdma_wo_reg) },
{ NULL, 0 }
};
static const struct iva_vdma_dump_regs *ch_dump_list[vdma_ch_max] = {
[vdma_ch0_type_ro] = ro_list,
[vdma_ch1_type_ro] = ro_list,
[vdma_ch2_type_ro] = ro_list,
[vdma_ch3_type_ro] = ro_list,
[vdma_ch4_type_ro] = ro_list,
[vdma_ch5_type_ro_yuv] = ro_yuv_list,
[vdma_ch6_type_ro_yuv] = ro_yuv_list,
[vdma_ch7_type_ro_spl] = ro_spl_list,
[vdma_ch8_type_wo] = wo_list,
[vdma_ch9_type_wo] = wo_list,
[vdma_ch10_type_wo] = wo_list,
[vdma_ch11_type_wo] = wo_list,
[vdma_ch12_type_wo] = wo_list,
[vdma_ch13_type_wo_yuv] = wo_yuv_list,
[vdma_ch14_type_wo_yuv] = wo_yuv_list,
[vdma_ch15_type_rw] = wr_list,
};
static const struct iva_vdma_dump_regs *iva_vdma_get_ch_dump_regs(enum vdma_ch ch)
{
if (ch < vdma_ch0_type_ro || ch >= vdma_ch_max)
return NULL;
return ch_dump_list[ch];
}
void iva_vdma_show_status(struct iva_dev_data *iva)
{
struct device *dev = iva->dev;
void *dma_base = iva->iva_va + IVA_VDMA0_BASE_ADDR;
void *ch_base;
u32 val;
int irq_type;
bool vdma_sfr_clk;
char line_buf[128];
char line_buf1[128];
int line_str;
int busy_ch_cnt = 0;
uint32_t ch, i;
int line_num, line_num1;
int breaker;
const struct iva_vdma_dump_regs *ch_regs;
vdma_sfr_clk = !!iva_pmu_enable_sfr_clk(iva, pmu_vdma_id, true);
if (!vdma_sfr_clk)
dev_info(dev, "vdma sfr clock was off.\n");
/* GBL */
dev_info(dev, "------------- VDMA2.0 GBL ------------\n");
dev_info(dev, " IRQ_EN IRQ_RAW STATUS\n");
for (irq_type = IRQ_DONE; irq_type <= IRQ_HOST1_ERR; irq_type++) {
line_str = snprintf(line_buf, sizeof(line_buf),
"%11s %08X %08X %08X\n",
iva_vdma_get_irq_type_str(irq_type),
readl(dma_base + VDMA_IRQ_EN_ADDR(irq_type)),
readl(dma_base + VDMA_IRQ_RAW_STATUS_ADDR(irq_type)),
readl(dma_base + VDMA_IRQ_STATUS_ADDR(irq_type)));
if (line_str == sizeof(line_buf))
line_buf[sizeof(line_buf) - 1] = 0x0;
dev_info(dev, "%s", line_buf);
}
/* per CH */
for (ch = vdma_ch0_type_ro; ch < vdma_ch_max; ch++) {
ch_base = iva->iva_va + GET_DMA_CH_BASE_F_HANDLE(CH_TO_HANDLE(ch));
val = readl(ch_base + VDMA_CH_STATUS_ADDR);
if (!(val & VDMA_CH_STAUS_CH_BUSY_M))
continue;
busy_ch_cnt++;
}
if (!busy_ch_cnt) {
dev_info(dev, "No busy VDMA2.0 Channels found\n");
goto out;
}
#define PAD_NEW_LINE(str_buf, str_num) \
do { \
int new_line_offset; \
if (str_num < sizeof(str_buf) - 1) \
new_line_offset = str_num; \
else \
new_line_offset = sizeof(str_buf) - 2; \
str_buf[new_line_offset] = '\n'; \
str_buf[new_line_offset + 1] = 0; \
} while (0)
for (ch = vdma_ch0_type_ro; ch < vdma_ch_max; ch++) {
ch_base = iva->iva_va + GET_DMA_CH_BASE_F_HANDLE(CH_TO_HANDLE(ch));
val = readl(ch_base + VDMA_CH_STATUS_ADDR);
if (!(val & VDMA_CH_STAUS_CH_BUSY_M))
continue;
dev_info(dev, "+- CH[%2d] -------------------------------------------------------------------------------+\n", ch);
line_num = 0;
line_num1 = 0;
breaker = 0;
ch_regs = iva_vdma_get_ch_dump_regs(ch);
if (!ch_regs)
continue;
while (ch_regs->reg_num != 0) {
for (i = 0 ; i < ch_regs->reg_num; i++) {
const struct iva_vdma_dump_reg *reg = &ch_regs->regs[i];
line_num += snprintf(line_buf + line_num,
sizeof(line_buf) - line_num, " %8s",
reg->name);
line_num1 += snprintf(line_buf1 + line_num1,
sizeof(line_buf1) - line_num1, " %08X",
readl(ch_base + reg->reg_offset));
breaker++;
if (breaker != 0 && (breaker % 10) == 0) {
PAD_NEW_LINE(line_buf, line_num);
PAD_NEW_LINE(line_buf1, line_num1);
dev_info(dev, "%s", line_buf);
dev_info(dev, "%s", line_buf1);
line_num = 0;
line_num1 = 0;
}
}
ch_regs++;
}
if (line_num > 1) {
PAD_NEW_LINE(line_buf, line_num);
PAD_NEW_LINE(line_buf1, line_num1);
dev_info(dev, "%s", line_buf);
dev_info(dev, "%s", line_buf1);
}
}
dev_info(dev, "+----------------------------------------------------------------------------------------+\n");
out:
if (!vdma_sfr_clk)
iva_pmu_enable_sfr_clk(iva, pmu_vdma_id, false);
}
|