Commit | Line | Data |
---|---|---|
c8afe684 | 1 | /* |
7ca12718 | 2 | * Copyright (c) 2014 The Linux Foundation. All rights reserved. |
c8afe684 RC |
3 | * Copyright (C) 2013 Red Hat |
4 | * Author: Rob Clark <robdclark@gmail.com> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify it | |
7 | * under the terms of the GNU General Public License version 2 as published by | |
8 | * the Free Software Foundation. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
13 | * more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License along with | |
16 | * this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | */ | |
18 | ||
19 | ||
20 | #include "msm_drv.h" | |
10a02eb6 | 21 | #include "mdp_kms.h" |
c8afe684 | 22 | |
7ca12718 SV |
23 | static struct csc_cfg csc_convert[CSC_MAX] = { |
24 | [CSC_RGB2RGB] = { | |
25 | .type = CSC_RGB2RGB, | |
26 | .matrix = { | |
27 | 0x0200, 0x0000, 0x0000, | |
28 | 0x0000, 0x0200, 0x0000, | |
29 | 0x0000, 0x0000, 0x0200 | |
30 | }, | |
31 | .pre_bias = { 0x0, 0x0, 0x0 }, | |
32 | .post_bias = { 0x0, 0x0, 0x0 }, | |
33 | .pre_clamp = { 0x0, 0xff, 0x0, 0xff, 0x0, 0xff }, | |
34 | .post_clamp = { 0x0, 0xff, 0x0, 0xff, 0x0, 0xff }, | |
35 | }, | |
36 | [CSC_YUV2RGB] = { | |
37 | .type = CSC_YUV2RGB, | |
38 | .matrix = { | |
39 | 0x0254, 0x0000, 0x0331, | |
40 | 0x0254, 0xff37, 0xfe60, | |
41 | 0x0254, 0x0409, 0x0000 | |
42 | }, | |
43 | .pre_bias = { 0xfff0, 0xff80, 0xff80 }, | |
44 | .post_bias = { 0x00, 0x00, 0x00 }, | |
45 | .pre_clamp = { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff }, | |
46 | .post_clamp = { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff }, | |
47 | }, | |
48 | [CSC_RGB2YUV] = { | |
49 | .type = CSC_RGB2YUV, | |
50 | .matrix = { | |
51 | 0x0083, 0x0102, 0x0032, | |
52 | 0x1fb5, 0x1f6c, 0x00e1, | |
53 | 0x00e1, 0x1f45, 0x1fdc | |
54 | }, | |
55 | .pre_bias = { 0x00, 0x00, 0x00 }, | |
56 | .post_bias = { 0x10, 0x80, 0x80 }, | |
57 | .pre_clamp = { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff }, | |
58 | .post_clamp = { 0x10, 0xeb, 0x10, 0xf0, 0x10, 0xf0 }, | |
59 | }, | |
60 | [CSC_YUV2YUV] = { | |
61 | .type = CSC_YUV2YUV, | |
62 | .matrix = { | |
63 | 0x0200, 0x0000, 0x0000, | |
64 | 0x0000, 0x0200, 0x0000, | |
65 | 0x0000, 0x0000, 0x0200 | |
66 | }, | |
67 | .pre_bias = { 0x00, 0x00, 0x00 }, | |
68 | .post_bias = { 0x00, 0x00, 0x00 }, | |
69 | .pre_clamp = { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff }, | |
70 | .post_clamp = { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff }, | |
71 | }, | |
72 | }; | |
73 | ||
ff78a6b3 | 74 | #define FMT(name, a, r, g, b, e0, e1, e2, e3, alpha, tight, c, cnt, fp, cs, yuv) { \ |
c8afe684 RC |
75 | .base = { .pixel_format = DRM_FORMAT_ ## name }, \ |
76 | .bpc_a = BPC ## a ## A, \ | |
77 | .bpc_r = BPC ## r, \ | |
78 | .bpc_g = BPC ## g, \ | |
79 | .bpc_b = BPC ## b, \ | |
80 | .unpack = { e0, e1, e2, e3 }, \ | |
81 | .alpha_enable = alpha, \ | |
82 | .unpack_tight = tight, \ | |
83 | .cpp = c, \ | |
84 | .unpack_count = cnt, \ | |
7ca12718 | 85 | .fetch_type = fp, \ |
ff78a6b3 WX |
86 | .chroma_sample = cs, \ |
87 | .is_yuv = yuv, \ | |
7ca12718 | 88 | } |
c8afe684 RC |
89 | |
90 | #define BPC0A 0 | |
91 | ||
7ca12718 SV |
92 | /* |
93 | * Note: Keep RGB formats 1st, followed by YUV formats to avoid breaking | |
94 | * mdp_get_rgb_formats()'s implementation. | |
95 | */ | |
10a02eb6 | 96 | static const struct mdp_format formats[] = { |
7ca12718 SV |
97 | /* name a r g b e0 e1 e2 e3 alpha tight cpp cnt ... */ |
98 | FMT(ARGB8888, 8, 8, 8, 8, 1, 0, 2, 3, true, true, 4, 4, | |
ff78a6b3 | 99 | MDP_PLANE_INTERLEAVED, CHROMA_FULL, false), |
fbd4ae8a | 100 | FMT(ABGR8888, 8, 8, 8, 8, 2, 0, 1, 3, true, true, 4, 4, |
ff78a6b3 | 101 | MDP_PLANE_INTERLEAVED, CHROMA_FULL, false), |
fbd4ae8a | 102 | FMT(RGBA8888, 8, 8, 8, 8, 3, 1, 0, 2, true, true, 4, 4, |
ff78a6b3 | 103 | MDP_PLANE_INTERLEAVED, CHROMA_FULL, false), |
fbd4ae8a | 104 | FMT(BGRA8888, 8, 8, 8, 8, 3, 2, 0, 1, true, true, 4, 4, |
ff78a6b3 | 105 | MDP_PLANE_INTERLEAVED, CHROMA_FULL, false), |
7ca12718 | 106 | FMT(XRGB8888, 8, 8, 8, 8, 1, 0, 2, 3, false, true, 4, 4, |
ff78a6b3 | 107 | MDP_PLANE_INTERLEAVED, CHROMA_FULL, false), |
7ca12718 | 108 | FMT(RGB888, 0, 8, 8, 8, 1, 0, 2, 0, false, true, 3, 3, |
ff78a6b3 | 109 | MDP_PLANE_INTERLEAVED, CHROMA_FULL, false), |
7ca12718 | 110 | FMT(BGR888, 0, 8, 8, 8, 2, 0, 1, 0, false, true, 3, 3, |
ff78a6b3 | 111 | MDP_PLANE_INTERLEAVED, CHROMA_FULL, false), |
7ca12718 | 112 | FMT(RGB565, 0, 5, 6, 5, 1, 0, 2, 0, false, true, 2, 3, |
ff78a6b3 | 113 | MDP_PLANE_INTERLEAVED, CHROMA_FULL, false), |
7ca12718 | 114 | FMT(BGR565, 0, 5, 6, 5, 2, 0, 1, 0, false, true, 2, 3, |
ff78a6b3 | 115 | MDP_PLANE_INTERLEAVED, CHROMA_FULL, false), |
7ca12718 SV |
116 | |
117 | /* --- RGB formats above / YUV formats below this line --- */ | |
118 | ||
bef799fb | 119 | /* 2 plane YUV */ |
7ca12718 | 120 | FMT(NV12, 0, 8, 8, 8, 1, 2, 0, 0, false, true, 2, 2, |
ff78a6b3 | 121 | MDP_PLANE_PSEUDO_PLANAR, CHROMA_420, true), |
7ca12718 | 122 | FMT(NV21, 0, 8, 8, 8, 2, 1, 0, 0, false, true, 2, 2, |
ff78a6b3 | 123 | MDP_PLANE_PSEUDO_PLANAR, CHROMA_420, true), |
bef799fb SV |
124 | FMT(NV16, 0, 8, 8, 8, 1, 2, 0, 0, false, true, 2, 2, |
125 | MDP_PLANE_PSEUDO_PLANAR, CHROMA_H2V1, true), | |
126 | FMT(NV61, 0, 8, 8, 8, 2, 1, 0, 0, false, true, 2, 2, | |
127 | MDP_PLANE_PSEUDO_PLANAR, CHROMA_H2V1, true), | |
128 | /* 1 plane YUV */ | |
129 | FMT(VYUY, 0, 8, 8, 8, 2, 0, 1, 0, false, true, 2, 4, | |
130 | MDP_PLANE_INTERLEAVED, CHROMA_H2V1, true), | |
131 | FMT(UYVY, 0, 8, 8, 8, 1, 0, 2, 0, false, true, 2, 4, | |
132 | MDP_PLANE_INTERLEAVED, CHROMA_H2V1, true), | |
133 | FMT(YUYV, 0, 8, 8, 8, 0, 1, 0, 2, false, true, 2, 4, | |
134 | MDP_PLANE_INTERLEAVED, CHROMA_H2V1, true), | |
135 | FMT(YVYU, 0, 8, 8, 8, 0, 2, 0, 1, false, true, 2, 4, | |
136 | MDP_PLANE_INTERLEAVED, CHROMA_H2V1, true), | |
137 | /* 3 plane YUV */ | |
138 | FMT(YUV420, 0, 8, 8, 8, 2, 1, 0, 0, false, true, 1, 1, | |
139 | MDP_PLANE_PLANAR, CHROMA_420, true), | |
140 | FMT(YVU420, 0, 8, 8, 8, 1, 2, 0, 0, false, true, 1, 1, | |
141 | MDP_PLANE_PLANAR, CHROMA_420, true), | |
c8afe684 RC |
142 | }; |
143 | ||
7ca12718 SV |
144 | /* |
145 | * Note: | |
146 | * @rgb_only must be set to true, when requesting | |
147 | * supported formats for RGB pipes. | |
148 | */ | |
149 | uint32_t mdp_get_formats(uint32_t *pixel_formats, uint32_t max_formats, | |
150 | bool rgb_only) | |
a8623918 RC |
151 | { |
152 | uint32_t i; | |
153 | for (i = 0; i < ARRAY_SIZE(formats); i++) { | |
10a02eb6 | 154 | const struct mdp_format *f = &formats[i]; |
a8623918 RC |
155 | |
156 | if (i == max_formats) | |
157 | break; | |
158 | ||
7ca12718 SV |
159 | if (rgb_only && MDP_FORMAT_IS_YUV(f)) |
160 | break; | |
161 | ||
a8623918 RC |
162 | pixel_formats[i] = f->base.pixel_format; |
163 | } | |
164 | ||
165 | return i; | |
166 | } | |
167 | ||
10a02eb6 | 168 | const struct msm_format *mdp_get_format(struct msm_kms *kms, uint32_t format) |
c8afe684 RC |
169 | { |
170 | int i; | |
171 | for (i = 0; i < ARRAY_SIZE(formats); i++) { | |
10a02eb6 | 172 | const struct mdp_format *f = &formats[i]; |
c8afe684 RC |
173 | if (f->base.pixel_format == format) |
174 | return &f->base; | |
175 | } | |
176 | return NULL; | |
177 | } | |
7ca12718 SV |
178 | |
179 | struct csc_cfg *mdp_get_default_csc_cfg(enum csc_type type) | |
180 | { | |
181 | if (unlikely(WARN_ON(type >= CSC_MAX))) | |
182 | return NULL; | |
183 | ||
184 | return &csc_convert[type]; | |
185 | } |