summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/msm/disp/mdp_format.c
blob: b9f0b13d25d5429c020c6456da378d1e7df989b1 (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
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2014 The Linux Foundation. All rights reserved.
 * Copyright (C) 2013 Red Hat
 * Author: Rob Clark <robdclark@gmail.com>
 */

#include <drm/drm_fourcc.h>
#include <drm/drm_framebuffer.h>

#include "msm_drv.h"
#include "mdp_kms.h"

static struct csc_cfg csc_convert[CSC_MAX] = {
	[CSC_RGB2RGB] = {
		.type = CSC_RGB2RGB,
		.matrix = {
			0x0200, 0x0000, 0x0000,
			0x0000, 0x0200, 0x0000,
			0x0000, 0x0000, 0x0200
		},
		.pre_bias =	{ 0x0, 0x0, 0x0 },
		.post_bias =	{ 0x0, 0x0, 0x0 },
		.pre_clamp =	{ 0x0, 0xff, 0x0, 0xff, 0x0, 0xff },
		.post_clamp =	{ 0x0, 0xff, 0x0, 0xff, 0x0, 0xff },
	},
	[CSC_YUV2RGB] = {
		.type = CSC_YUV2RGB,
		.matrix = {
			0x0254, 0x0000, 0x0331,
			0x0254, 0xff37, 0xfe60,
			0x0254, 0x0409, 0x0000
		},
		.pre_bias =	{ 0xfff0, 0xff80, 0xff80 },
		.post_bias =	{ 0x00, 0x00, 0x00 },
		.pre_clamp =	{ 0x00, 0xff, 0x00, 0xff, 0x00, 0xff },
		.post_clamp =	{ 0x00, 0xff, 0x00, 0xff, 0x00, 0xff },
	},
	[CSC_RGB2YUV] = {
		.type = CSC_RGB2YUV,
		.matrix = {
			0x0083, 0x0102, 0x0032,
			0x1fb5, 0x1f6c, 0x00e1,
			0x00e1, 0x1f45, 0x1fdc
		},
		.pre_bias =	{ 0x00, 0x00, 0x00 },
		.post_bias =	{ 0x10, 0x80, 0x80 },
		.pre_clamp =	{ 0x00, 0xff, 0x00, 0xff, 0x00, 0xff },
		.post_clamp =	{ 0x10, 0xeb, 0x10, 0xf0, 0x10, 0xf0 },
	},
	[CSC_YUV2YUV] = {
		.type = CSC_YUV2YUV,
		.matrix = {
			0x0200, 0x0000, 0x0000,
			0x0000, 0x0200, 0x0000,
			0x0000, 0x0000, 0x0200
		},
		.pre_bias =	{ 0x00, 0x00, 0x00 },
		.post_bias =	{ 0x00, 0x00, 0x00 },
		.pre_clamp =	{ 0x00, 0xff, 0x00, 0xff, 0x00, 0xff },
		.post_clamp =	{ 0x00, 0xff, 0x00, 0xff, 0x00, 0xff },
	},
};

#define FMT(name, a, r, g, b, e0, e1, e2, e3, alpha, c, cnt, fp, cs, yuv) { \
		.pixel_format = DRM_FORMAT_ ## name,             \
		.bpc_a = BPC ## a ## A,                          \
		.bpc_r_cr = BPC ## r,                            \
		.bpc_g_y = BPC ## g,                             \
		.bpc_b_cb = BPC ## b,                            \
		.element = { e0, e1, e2, e3 },                   \
		.fetch_type = fp,                                \
		.chroma_sample = cs,                             \
		.alpha_enable = alpha,                           \
		.unpack_count = cnt,                             \
		.bpp = c,                                        \
		.flags = MSM_FORMAT_FLAG_UNPACK_TIGHT |          \
			(yuv ? MSM_FORMAT_FLAG_YUV : 0),         \
}

#define BPC0A 0

static const struct msm_format formats[] = {
	/*  name      a  r  g  b   e0 e1 e2 e3  alpha   cpp cnt ... */
	FMT(ARGB8888, 8, 8, 8, 8,  1, 0, 2, 3,  true,   4,  4,
			MDP_PLANE_INTERLEAVED, CHROMA_FULL, false),
	FMT(ABGR8888, 8, 8, 8, 8,  2, 0, 1, 3,  true,   4,  4,
			MDP_PLANE_INTERLEAVED, CHROMA_FULL, false),
	FMT(RGBA8888, 8, 8, 8, 8,  3, 1, 0, 2,  true,   4,  4,
			MDP_PLANE_INTERLEAVED, CHROMA_FULL, false),
	FMT(BGRA8888, 8, 8, 8, 8,  3, 2, 0, 1,  true,   4,  4,
			MDP_PLANE_INTERLEAVED, CHROMA_FULL, false),
	FMT(XRGB8888, 8, 8, 8, 8,  1, 0, 2, 3,  false,  4,  4,
			MDP_PLANE_INTERLEAVED, CHROMA_FULL, false),
	FMT(XBGR8888, 8, 8, 8, 8,  2, 0, 1, 3,  false,  4,  4,
			MDP_PLANE_INTERLEAVED, CHROMA_FULL, false),
	FMT(RGBX8888, 8, 8, 8, 8,  3, 1, 0, 2,  false,  4,  4,
			MDP_PLANE_INTERLEAVED, CHROMA_FULL, false),
	FMT(BGRX8888, 8, 8, 8, 8,  3, 2, 0, 1,  false,  4,  4,
			MDP_PLANE_INTERLEAVED, CHROMA_FULL, false),
	FMT(RGB888,   0, 8, 8, 8,  1, 0, 2, 0,  false,  3,  3,
			MDP_PLANE_INTERLEAVED, CHROMA_FULL, false),
	FMT(BGR888,   0, 8, 8, 8,  2, 0, 1, 0,  false,  3,  3,
			MDP_PLANE_INTERLEAVED, CHROMA_FULL, false),
	FMT(RGB565,   0, 5, 6, 5,  1, 0, 2, 0,  false,  2,  3,
			MDP_PLANE_INTERLEAVED, CHROMA_FULL, false),
	FMT(BGR565,   0, 5, 6, 5,  2, 0, 1, 0,  false,  2,  3,
			MDP_PLANE_INTERLEAVED, CHROMA_FULL, false),

	/* --- RGB formats above / YUV formats below this line --- */

	/* 2 plane YUV */
	FMT(NV12,     0, 8, 8, 8,  1, 2, 0, 0,  false,  2, 2,
			MDP_PLANE_PSEUDO_PLANAR, CHROMA_420, true),
	FMT(NV21,     0, 8, 8, 8,  2, 1, 0, 0,  false,  2, 2,
			MDP_PLANE_PSEUDO_PLANAR, CHROMA_420, true),
	FMT(NV16,     0, 8, 8, 8,  1, 2, 0, 0,  false,  2, 2,
			MDP_PLANE_PSEUDO_PLANAR, CHROMA_H2V1, true),
	FMT(NV61,     0, 8, 8, 8,  2, 1, 0, 0,  false,  2, 2,
			MDP_PLANE_PSEUDO_PLANAR, CHROMA_H2V1, true),
	/* 1 plane YUV */
	FMT(VYUY,     0, 8, 8, 8,  2, 0, 1, 0,  false,  2, 4,
			MDP_PLANE_INTERLEAVED, CHROMA_H2V1, true),
	FMT(UYVY,     0, 8, 8, 8,  1, 0, 2, 0,  false,  2, 4,
			MDP_PLANE_INTERLEAVED, CHROMA_H2V1, true),
	FMT(YUYV,     0, 8, 8, 8,  0, 1, 0, 2,  false,  2, 4,
			MDP_PLANE_INTERLEAVED, CHROMA_H2V1, true),
	FMT(YVYU,     0, 8, 8, 8,  0, 2, 0, 1,  false,  2, 4,
			MDP_PLANE_INTERLEAVED, CHROMA_H2V1, true),
	/* 3 plane YUV */
	FMT(YUV420,   0, 8, 8, 8,  2, 1, 0, 0,  false,  1, 1,
			MDP_PLANE_PLANAR, CHROMA_420, true),
	FMT(YVU420,   0, 8, 8, 8,  1, 2, 0, 0,  false,  1, 1,
			MDP_PLANE_PLANAR, CHROMA_420, true),
};

const struct msm_format *mdp_get_format(struct msm_kms *kms, uint32_t format,
		uint64_t modifier)
{
	int i;
	for (i = 0; i < ARRAY_SIZE(formats); i++) {
		const struct msm_format *f = &formats[i];
		if (f->pixel_format == format)
			return f;
	}
	return NULL;
}

struct csc_cfg *mdp_get_default_csc_cfg(enum csc_type type)
{
	if (WARN_ON(type >= CSC_MAX))
		return NULL;

	return &csc_convert[type];
}