WIP FPC-III support
[linux/fpc-iii.git] / drivers / gpu / drm / arm / display / komeda / komeda_format_caps.c
blobc9a1edb9a000a0b20a98a35ba4eaad1a07119358
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * (C) COPYRIGHT 2018 ARM Limited. All rights reserved.
4 * Author: James.Qian.Wang <james.qian.wang@arm.com>
6 */
8 #include <linux/slab.h>
9 #include "komeda_format_caps.h"
10 #include "malidp_utils.h"
12 const struct komeda_format_caps *
13 komeda_get_format_caps(struct komeda_format_caps_table *table,
14 u32 fourcc, u64 modifier)
16 const struct komeda_format_caps *caps;
17 u64 afbc_features = modifier & ~(AFBC_FORMAT_MOD_BLOCK_SIZE_MASK);
18 u32 afbc_layout = modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK;
19 int id;
21 for (id = 0; id < table->n_formats; id++) {
22 caps = &table->format_caps[id];
24 if (fourcc != caps->fourcc)
25 continue;
27 if ((modifier == 0ULL) && (caps->supported_afbc_layouts == 0))
28 return caps;
30 if (has_bits(afbc_features, caps->supported_afbc_features) &&
31 has_bit(afbc_layout, caps->supported_afbc_layouts))
32 return caps;
35 return NULL;
38 u32 komeda_get_afbc_format_bpp(const struct drm_format_info *info, u64 modifier)
40 u32 bpp;
42 switch (info->format) {
43 case DRM_FORMAT_YUV420_8BIT:
44 bpp = 12;
45 break;
46 case DRM_FORMAT_YUV420_10BIT:
47 bpp = 15;
48 break;
49 default:
50 bpp = info->cpp[0] * 8;
51 break;
54 return bpp;
57 /* Two assumptions
58 * 1. RGB always has YTR
59 * 2. Tiled RGB always has SC
61 u64 komeda_supported_modifiers[] = {
62 /* AFBC_16x16 + features: YUV+RGB both */
63 AFBC_16x16(0),
64 /* SPARSE */
65 AFBC_16x16(_SPARSE),
66 /* YTR + (SPARSE) */
67 AFBC_16x16(_YTR | _SPARSE),
68 AFBC_16x16(_YTR),
69 /* SPLIT + SPARSE + YTR RGB only */
70 /* split mode is only allowed for sparse mode */
71 AFBC_16x16(_SPLIT | _SPARSE | _YTR),
72 /* TILED + (SPARSE) */
73 /* TILED YUV format only */
74 AFBC_16x16(_TILED | _SPARSE),
75 AFBC_16x16(_TILED),
76 /* TILED + SC + (SPLIT+SPARSE | SPARSE) + (YTR) */
77 AFBC_16x16(_TILED | _SC | _SPLIT | _SPARSE | _YTR),
78 AFBC_16x16(_TILED | _SC | _SPARSE | _YTR),
79 AFBC_16x16(_TILED | _SC | _YTR),
80 /* AFBC_32x8 + features: which are RGB formats only */
81 /* YTR + (SPARSE) */
82 AFBC_32x8(_YTR | _SPARSE),
83 AFBC_32x8(_YTR),
84 /* SPLIT + SPARSE + (YTR) */
85 /* split mode is only allowed for sparse mode */
86 AFBC_32x8(_SPLIT | _SPARSE | _YTR),
87 /* TILED + SC + (SPLIT+SPARSE | SPARSE) + YTR */
88 AFBC_32x8(_TILED | _SC | _SPLIT | _SPARSE | _YTR),
89 AFBC_32x8(_TILED | _SC | _SPARSE | _YTR),
90 AFBC_32x8(_TILED | _SC | _YTR),
91 DRM_FORMAT_MOD_LINEAR,
92 DRM_FORMAT_MOD_INVALID
95 bool komeda_format_mod_supported(struct komeda_format_caps_table *table,
96 u32 layer_type, u32 fourcc, u64 modifier,
97 u32 rot)
99 const struct komeda_format_caps *caps;
101 caps = komeda_get_format_caps(table, fourcc, modifier);
102 if (!caps)
103 return false;
105 if (!(caps->supported_layer_types & layer_type))
106 return false;
108 if (table->format_mod_supported)
109 return table->format_mod_supported(caps, layer_type, modifier,
110 rot);
112 return true;
115 u32 *komeda_get_layer_fourcc_list(struct komeda_format_caps_table *table,
116 u32 layer_type, u32 *n_fmts)
118 const struct komeda_format_caps *cap;
119 u32 *fmts;
120 int i, j, n = 0;
122 fmts = kcalloc(table->n_formats, sizeof(u32), GFP_KERNEL);
123 if (!fmts)
124 return NULL;
126 for (i = 0; i < table->n_formats; i++) {
127 cap = &table->format_caps[i];
128 if (!(layer_type & cap->supported_layer_types) ||
129 (cap->fourcc == 0))
130 continue;
132 /* one fourcc may has two caps items in table (afbc/none-afbc),
133 * so check the existing list to avoid adding a duplicated one.
135 for (j = n - 1; j >= 0; j--)
136 if (fmts[j] == cap->fourcc)
137 break;
139 if (j < 0)
140 fmts[n++] = cap->fourcc;
143 if (n_fmts)
144 *n_fmts = n;
146 return fmts;
149 void komeda_put_fourcc_list(u32 *fourcc_list)
151 kfree(fourcc_list);