0001
0002
0003
0004
0005
0006
0007
0008 #include <drm/drm_fourcc.h>
0009 #include <drm/drm_framebuffer.h>
0010
0011 #include "msm_drv.h"
0012 #include "mdp_kms.h"
0013
0014 static struct csc_cfg csc_convert[CSC_MAX] = {
0015 [CSC_RGB2RGB] = {
0016 .type = CSC_RGB2RGB,
0017 .matrix = {
0018 0x0200, 0x0000, 0x0000,
0019 0x0000, 0x0200, 0x0000,
0020 0x0000, 0x0000, 0x0200
0021 },
0022 .pre_bias = { 0x0, 0x0, 0x0 },
0023 .post_bias = { 0x0, 0x0, 0x0 },
0024 .pre_clamp = { 0x0, 0xff, 0x0, 0xff, 0x0, 0xff },
0025 .post_clamp = { 0x0, 0xff, 0x0, 0xff, 0x0, 0xff },
0026 },
0027 [CSC_YUV2RGB] = {
0028 .type = CSC_YUV2RGB,
0029 .matrix = {
0030 0x0254, 0x0000, 0x0331,
0031 0x0254, 0xff37, 0xfe60,
0032 0x0254, 0x0409, 0x0000
0033 },
0034 .pre_bias = { 0xfff0, 0xff80, 0xff80 },
0035 .post_bias = { 0x00, 0x00, 0x00 },
0036 .pre_clamp = { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff },
0037 .post_clamp = { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff },
0038 },
0039 [CSC_RGB2YUV] = {
0040 .type = CSC_RGB2YUV,
0041 .matrix = {
0042 0x0083, 0x0102, 0x0032,
0043 0x1fb5, 0x1f6c, 0x00e1,
0044 0x00e1, 0x1f45, 0x1fdc
0045 },
0046 .pre_bias = { 0x00, 0x00, 0x00 },
0047 .post_bias = { 0x10, 0x80, 0x80 },
0048 .pre_clamp = { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff },
0049 .post_clamp = { 0x10, 0xeb, 0x10, 0xf0, 0x10, 0xf0 },
0050 },
0051 [CSC_YUV2YUV] = {
0052 .type = CSC_YUV2YUV,
0053 .matrix = {
0054 0x0200, 0x0000, 0x0000,
0055 0x0000, 0x0200, 0x0000,
0056 0x0000, 0x0000, 0x0200
0057 },
0058 .pre_bias = { 0x00, 0x00, 0x00 },
0059 .post_bias = { 0x00, 0x00, 0x00 },
0060 .pre_clamp = { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff },
0061 .post_clamp = { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff },
0062 },
0063 };
0064
0065 #define FMT(name, a, r, g, b, e0, e1, e2, e3, alpha, tight, c, cnt, fp, cs, yuv) { \
0066 .base = { .pixel_format = DRM_FORMAT_ ## name }, \
0067 .bpc_a = BPC ## a ## A, \
0068 .bpc_r = BPC ## r, \
0069 .bpc_g = BPC ## g, \
0070 .bpc_b = BPC ## b, \
0071 .unpack = { e0, e1, e2, e3 }, \
0072 .alpha_enable = alpha, \
0073 .unpack_tight = tight, \
0074 .cpp = c, \
0075 .unpack_count = cnt, \
0076 .fetch_type = fp, \
0077 .chroma_sample = cs, \
0078 .is_yuv = yuv, \
0079 }
0080
0081 #define BPC0A 0
0082
0083
0084
0085
0086
0087 static const struct mdp_format formats[] = {
0088
0089 FMT(ARGB8888, 8, 8, 8, 8, 1, 0, 2, 3, true, true, 4, 4,
0090 MDP_PLANE_INTERLEAVED, CHROMA_FULL, false),
0091 FMT(ABGR8888, 8, 8, 8, 8, 2, 0, 1, 3, true, true, 4, 4,
0092 MDP_PLANE_INTERLEAVED, CHROMA_FULL, false),
0093 FMT(RGBA8888, 8, 8, 8, 8, 3, 1, 0, 2, true, true, 4, 4,
0094 MDP_PLANE_INTERLEAVED, CHROMA_FULL, false),
0095 FMT(BGRA8888, 8, 8, 8, 8, 3, 2, 0, 1, true, true, 4, 4,
0096 MDP_PLANE_INTERLEAVED, CHROMA_FULL, false),
0097 FMT(XRGB8888, 8, 8, 8, 8, 1, 0, 2, 3, false, true, 4, 4,
0098 MDP_PLANE_INTERLEAVED, CHROMA_FULL, false),
0099 FMT(XBGR8888, 8, 8, 8, 8, 2, 0, 1, 3, false, true, 4, 4,
0100 MDP_PLANE_INTERLEAVED, CHROMA_FULL, false),
0101 FMT(RGBX8888, 8, 8, 8, 8, 3, 1, 0, 2, false, true, 4, 4,
0102 MDP_PLANE_INTERLEAVED, CHROMA_FULL, false),
0103 FMT(BGRX8888, 8, 8, 8, 8, 3, 2, 0, 1, false, true, 4, 4,
0104 MDP_PLANE_INTERLEAVED, CHROMA_FULL, false),
0105 FMT(RGB888, 0, 8, 8, 8, 1, 0, 2, 0, false, true, 3, 3,
0106 MDP_PLANE_INTERLEAVED, CHROMA_FULL, false),
0107 FMT(BGR888, 0, 8, 8, 8, 2, 0, 1, 0, false, true, 3, 3,
0108 MDP_PLANE_INTERLEAVED, CHROMA_FULL, false),
0109 FMT(RGB565, 0, 5, 6, 5, 1, 0, 2, 0, false, true, 2, 3,
0110 MDP_PLANE_INTERLEAVED, CHROMA_FULL, false),
0111 FMT(BGR565, 0, 5, 6, 5, 2, 0, 1, 0, false, true, 2, 3,
0112 MDP_PLANE_INTERLEAVED, CHROMA_FULL, false),
0113
0114
0115
0116
0117 FMT(NV12, 0, 8, 8, 8, 1, 2, 0, 0, false, true, 2, 2,
0118 MDP_PLANE_PSEUDO_PLANAR, CHROMA_420, true),
0119 FMT(NV21, 0, 8, 8, 8, 2, 1, 0, 0, false, true, 2, 2,
0120 MDP_PLANE_PSEUDO_PLANAR, CHROMA_420, true),
0121 FMT(NV16, 0, 8, 8, 8, 1, 2, 0, 0, false, true, 2, 2,
0122 MDP_PLANE_PSEUDO_PLANAR, CHROMA_H2V1, true),
0123 FMT(NV61, 0, 8, 8, 8, 2, 1, 0, 0, false, true, 2, 2,
0124 MDP_PLANE_PSEUDO_PLANAR, CHROMA_H2V1, true),
0125
0126 FMT(VYUY, 0, 8, 8, 8, 2, 0, 1, 0, false, true, 2, 4,
0127 MDP_PLANE_INTERLEAVED, CHROMA_H2V1, true),
0128 FMT(UYVY, 0, 8, 8, 8, 1, 0, 2, 0, false, true, 2, 4,
0129 MDP_PLANE_INTERLEAVED, CHROMA_H2V1, true),
0130 FMT(YUYV, 0, 8, 8, 8, 0, 1, 0, 2, false, true, 2, 4,
0131 MDP_PLANE_INTERLEAVED, CHROMA_H2V1, true),
0132 FMT(YVYU, 0, 8, 8, 8, 0, 2, 0, 1, false, true, 2, 4,
0133 MDP_PLANE_INTERLEAVED, CHROMA_H2V1, true),
0134
0135 FMT(YUV420, 0, 8, 8, 8, 2, 1, 0, 0, false, true, 1, 1,
0136 MDP_PLANE_PLANAR, CHROMA_420, true),
0137 FMT(YVU420, 0, 8, 8, 8, 1, 2, 0, 0, false, true, 1, 1,
0138 MDP_PLANE_PLANAR, CHROMA_420, true),
0139 };
0140
0141
0142
0143
0144
0145
0146 uint32_t mdp_get_formats(uint32_t *pixel_formats, uint32_t max_formats,
0147 bool rgb_only)
0148 {
0149 uint32_t i;
0150 for (i = 0; i < ARRAY_SIZE(formats); i++) {
0151 const struct mdp_format *f = &formats[i];
0152
0153 if (i == max_formats)
0154 break;
0155
0156 if (rgb_only && MDP_FORMAT_IS_YUV(f))
0157 break;
0158
0159 pixel_formats[i] = f->base.pixel_format;
0160 }
0161
0162 return i;
0163 }
0164
0165 const struct msm_format *mdp_get_format(struct msm_kms *kms, uint32_t format,
0166 uint64_t modifier)
0167 {
0168 int i;
0169 for (i = 0; i < ARRAY_SIZE(formats); i++) {
0170 const struct mdp_format *f = &formats[i];
0171 if (f->base.pixel_format == format)
0172 return &f->base;
0173 }
0174 return NULL;
0175 }
0176
0177 struct csc_cfg *mdp_get_default_csc_cfg(enum csc_type type)
0178 {
0179 if (WARN_ON(type >= CSC_MAX))
0180 return NULL;
0181
0182 return &csc_convert[type];
0183 }