summaryrefstree
path: root/kernel/drivers/media/platform/g2d1shot/g2d1shot_helper.c
blob: 74d07ef287be76091c2836e0bc4e55ff6fbe2950 (plain)
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
/* linux/drivers/media/platform/exynos/fimg2d_v5/g2d1shot_helper.c
 *
 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
 *	http://www.samsung.com/
 *
 * Samsung Graphics 2D 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 <linux/module.h>
#include <linux/kernel.h>
#include <linux/platform_device.h>
#include <linux/of.h>

#include "g2d1shot.h"
#include "g2d1shot_helper.h"

struct regs_info {
	int start;
	int size;
	const char *name;
};

void g2d_dump_regs(struct g2d1shot_dev *g2d_dev)
{
	int i, count;
	struct regs_info info[] = {
		/* Start, Size, Name */
		{ 0x0,   0x20, "General 1" },
		{ 0xF0,  0x10, "General 2" },
		{ 0x100, 0x10, "Command" },
		{ 0x120, 0xE0, "Destination" },
		{ 0x200, 0x100, "Layer0" },
		{ 0x300, 0x100, "Layer1" },
		{ 0x400, 0x100, "Layer2" },
		{ 0x500, 0x100, "Layer3" },
		{ 0x600, 0x100, "Layer4" },
		{ 0x700, 0x100, "Layer5" },
		{ 0x800, 0x100, "Layer6" },
		{ 0x900, 0x100, "Layer7" },
		{ 0xA00, 0x100, "CSC" },
	};

	count = ARRAY_SIZE(info);

	pr_info(">>> DUMP all regs (base = %p)\n", g2d_dev->reg);

	for (i = 0; i < count; i++) {
		pr_info("[%s: %04X .. %04X]\n",
			info[i].name, info[i].start,
			info[i].start + info[i].size);
		print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, 32, 4,
			g2d_dev->reg + info[i].start, info[i].size, false);
	}

	pr_info("DUMP finished <<<\n");
}

const char *op_string[] = {
	"NONE",
	"CLEAR",
	"SRC",
	"DST",
	"SRCOVER",
	"DSTOVER",
	"SRCIN	",
	"DSTIN	",
	"SRCOUT	",
	"DSTOUT	",
	"SRCATOP",
	"DSTATOP",
	"XOR",
	"PLUS",
	"MULTIPLY",
	"SCREEN",
	"DARKEN",
	"LIGHTEN",
};

const char *buf_type_string[] = {
	"NONE",
	"EMPTY",
	"USERPTR",
	"DMABUF",
};

static void _g2d_disp_format(struct m2m1shot2_context_format *ctx_fmt)
{
	const struct g2d1shot_fmt *g2d_fmt = ctx_fmt->priv;
	struct m2m1shot2_format *fmt = &ctx_fmt->fmt;

	pr_info("-- Format\n");
	pr_info("w x h : %d x %d, format : 0x%x (%s)\n",
		fmt->width, fmt->height, fmt->pixelformat, g2d_fmt->name);
	pr_info("crop : lt(%d, %d) rb(%d, %d)\n",
		fmt->crop.left, fmt->crop.top,
		fmt->crop.left + fmt->crop.width,
		fmt->crop.top + fmt->crop.height);
	pr_info("window : lt(%d, %d) rb(%d, %d)\n",
		fmt->window.left, fmt->window.top,
		fmt->window.left + fmt->window.width,
		fmt->window.top + fmt->window.height);
}

static void _g2d_disp_extra(struct m2m1shot2_extra *ext)
{
	pr_info("-- Extra setting\n");
	pr_info("composit mode : %d (%s), fillcolor(0x%x), transform(0x%x)\n",
			ext->composit_mode, op_string[ext->composit_mode],
			ext->fillcolor, ext->transform);
	pr_info("galpha r/g/b : %d/%d/%d, repeat x/y : %d/%d, scale : %d\n",
			ext->galpha_red, ext->galpha_green, ext->galpha_blue,
			ext->xrepeat, ext->yrepeat, ext->scaler_filter);
}

static void _g2d_disp_image(struct m2m1shot2_context_image *img)
{
	pr_info("-- Image\n");
	pr_info("buffer type : %d(%s), flags:0x%x\n",
			img->memory, buf_type_string[img->memory],
			img->flags);
}

static void _g2d_disp_source(struct m2m1shot2_context *ctx, int index)
{
	int i;

	_g2d_disp_image(&ctx->source[index].img);
	_g2d_disp_format(&ctx->source[index].img.fmt);
	_g2d_disp_extra(&ctx->source[index].ext);
	for (i = 0; i < ctx->source[index].img.num_planes; i++)
		pr_info("Addr[%d] : %#lx\n", i,
			(unsigned long)m2m1shot2_src_dma_addr(ctx, index, i));
}

static void _g2d_disp_target(struct m2m1shot2_context *ctx)
{
	int i;

	_g2d_disp_image(&ctx->target);
	_g2d_disp_format(&ctx->target.fmt);
	for (i = 0; i < ctx->target.num_planes; i++)
		pr_info("Addr[%d] : %#lx\n", i,
			(unsigned long)m2m1shot2_dst_dma_addr(ctx, i));
}

int g2d_disp_info(struct m2m1shot2_context *ctx)
{
	int i;

	pr_info(">>> Disp info (num of source : %d)\n", ctx->num_sources);

	for (i = 0; i < ctx->num_sources; i++) {
		pr_info("[ Source %d ]\n", i);
		_g2d_disp_source(ctx, i);
	}
	pr_info("[ Destination ]\n");
	_g2d_disp_target(ctx);

	pr_info("Flags:0x%x (Dither : %s, %s block mode) <<<\n\n",
		ctx->flags,
		(ctx->flags & M2M1SHOT2_FLAG_DITHER ? "enabled" : "disabled"),
		(ctx->flags & M2M1SHOT2_FLAG_NONBLOCK ? "Non" : ""));

	return 0;
}