xref: /linux/drivers/gpu/drm/verisilicon/vs_hwdb.c (revision 2b109eccd80b660e58d4523e8b80ce11bc3e532e)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (C) 2025 Icenowy Zheng <uwu@icenowy.me>
4  */
5 
6 #include <linux/errno.h>
7 
8 #include <drm/drm_fourcc.h>
9 
10 #include "vs_dc_top_regs.h"
11 #include "vs_hwdb.h"
12 
13 static const u32 vs_formats_array_no_yuv444[] = {
14 	DRM_FORMAT_XRGB4444,
15 	DRM_FORMAT_XBGR4444,
16 	DRM_FORMAT_RGBX4444,
17 	DRM_FORMAT_BGRX4444,
18 	DRM_FORMAT_ARGB4444,
19 	DRM_FORMAT_ABGR4444,
20 	DRM_FORMAT_RGBA4444,
21 	DRM_FORMAT_BGRA4444,
22 	DRM_FORMAT_XRGB1555,
23 	DRM_FORMAT_XBGR1555,
24 	DRM_FORMAT_RGBX5551,
25 	DRM_FORMAT_BGRX5551,
26 	DRM_FORMAT_ARGB1555,
27 	DRM_FORMAT_ABGR1555,
28 	DRM_FORMAT_RGBA5551,
29 	DRM_FORMAT_BGRA5551,
30 	DRM_FORMAT_RGB565,
31 	DRM_FORMAT_BGR565,
32 	DRM_FORMAT_XRGB8888,
33 	DRM_FORMAT_XBGR8888,
34 	DRM_FORMAT_RGBX8888,
35 	DRM_FORMAT_BGRX8888,
36 	DRM_FORMAT_ARGB8888,
37 	DRM_FORMAT_ABGR8888,
38 	DRM_FORMAT_RGBA8888,
39 	DRM_FORMAT_BGRA8888,
40 	DRM_FORMAT_ARGB2101010,
41 	DRM_FORMAT_ABGR2101010,
42 	DRM_FORMAT_RGBA1010102,
43 	DRM_FORMAT_BGRA1010102,
44 	/* TODO: non-RGB formats */
45 };
46 
47 static const u32 vs_formats_array_with_yuv444[] = {
48 	DRM_FORMAT_XRGB4444,
49 	DRM_FORMAT_XBGR4444,
50 	DRM_FORMAT_RGBX4444,
51 	DRM_FORMAT_BGRX4444,
52 	DRM_FORMAT_ARGB4444,
53 	DRM_FORMAT_ABGR4444,
54 	DRM_FORMAT_RGBA4444,
55 	DRM_FORMAT_BGRA4444,
56 	DRM_FORMAT_XRGB1555,
57 	DRM_FORMAT_XBGR1555,
58 	DRM_FORMAT_RGBX5551,
59 	DRM_FORMAT_BGRX5551,
60 	DRM_FORMAT_ARGB1555,
61 	DRM_FORMAT_ABGR1555,
62 	DRM_FORMAT_RGBA5551,
63 	DRM_FORMAT_BGRA5551,
64 	DRM_FORMAT_RGB565,
65 	DRM_FORMAT_BGR565,
66 	DRM_FORMAT_XRGB8888,
67 	DRM_FORMAT_XBGR8888,
68 	DRM_FORMAT_RGBX8888,
69 	DRM_FORMAT_BGRX8888,
70 	DRM_FORMAT_ARGB8888,
71 	DRM_FORMAT_ABGR8888,
72 	DRM_FORMAT_RGBA8888,
73 	DRM_FORMAT_BGRA8888,
74 	DRM_FORMAT_ARGB2101010,
75 	DRM_FORMAT_ABGR2101010,
76 	DRM_FORMAT_RGBA1010102,
77 	DRM_FORMAT_BGRA1010102,
78 	/* TODO: non-RGB formats */
79 };
80 
81 static const struct vs_formats vs_formats_no_yuv444 = {
82 	.array = vs_formats_array_no_yuv444,
83 	.num = ARRAY_SIZE(vs_formats_array_no_yuv444)
84 };
85 
86 static const struct vs_formats vs_formats_with_yuv444 = {
87 	.array = vs_formats_array_with_yuv444,
88 	.num = ARRAY_SIZE(vs_formats_array_with_yuv444)
89 };
90 
91 static struct vs_chip_identity vs_chip_identities[] = {
92 	{
93 		.model = 0x8200,
94 		.revision = 0x5720,
95 		.customer_id = ~0U,
96 
97 		.display_count = 2,
98 		.max_cursor_size = 64,
99 		.formats = &vs_formats_no_yuv444,
100 	},
101 	{
102 		.model = 0x8200,
103 		.revision = 0x5721,
104 		.customer_id = 0x30B,
105 
106 		.display_count = 2,
107 		.max_cursor_size = 64,
108 		.formats = &vs_formats_no_yuv444,
109 	},
110 	{
111 		.model = 0x8200,
112 		.revision = 0x5720,
113 		.customer_id = 0x310,
114 
115 		.display_count = 2,
116 		.max_cursor_size = 64,
117 		.formats = &vs_formats_with_yuv444,
118 	},
119 	{
120 		.model = 0x8200,
121 		.revision = 0x5720,
122 		.customer_id = 0x311,
123 
124 		.display_count = 2,
125 		.max_cursor_size = 64,
126 		.formats = &vs_formats_no_yuv444,
127 	},
128 };
129 
130 int vs_fill_chip_identity(struct regmap *regs,
131 			  struct vs_chip_identity *ident)
132 {
133 	u32 model;
134 	u32 revision;
135 	u32 customer_id;
136 	int i;
137 
138 	regmap_read(regs, VSDC_TOP_CHIP_MODEL, &model);
139 	regmap_read(regs, VSDC_TOP_CHIP_REV, &revision);
140 	regmap_read(regs, VSDC_TOP_CHIP_CUSTOMER_ID, &customer_id);
141 
142 	for (i = 0; i < ARRAY_SIZE(vs_chip_identities); i++) {
143 		if (vs_chip_identities[i].model == model &&
144 		    vs_chip_identities[i].revision == revision &&
145 		    (vs_chip_identities[i].customer_id == customer_id ||
146 		     vs_chip_identities[i].customer_id == ~0U)) {
147 			memcpy(ident, &vs_chip_identities[i], sizeof(*ident));
148 			ident->customer_id = customer_id;
149 			return 0;
150 		}
151 	}
152 
153 	return -EINVAL;
154 }
155