xref: /linux/drivers/gpu/drm/verisilicon/vs_hwdb.c (revision 0fc8f6200d2313278fbf4539bbab74677c685531)
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 		.formats = &vs_formats_no_yuv444,
99 	},
100 	{
101 		.model = 0x8200,
102 		.revision = 0x5721,
103 		.customer_id = 0x30B,
104 
105 		.display_count = 2,
106 		.formats = &vs_formats_no_yuv444,
107 	},
108 	{
109 		.model = 0x8200,
110 		.revision = 0x5720,
111 		.customer_id = 0x310,
112 
113 		.display_count = 2,
114 		.formats = &vs_formats_with_yuv444,
115 	},
116 	{
117 		.model = 0x8200,
118 		.revision = 0x5720,
119 		.customer_id = 0x311,
120 
121 		.display_count = 2,
122 		.formats = &vs_formats_no_yuv444,
123 	},
124 };
125 
126 int vs_fill_chip_identity(struct regmap *regs,
127 			  struct vs_chip_identity *ident)
128 {
129 	u32 model;
130 	u32 revision;
131 	u32 customer_id;
132 	int i;
133 
134 	regmap_read(regs, VSDC_TOP_CHIP_MODEL, &model);
135 	regmap_read(regs, VSDC_TOP_CHIP_REV, &revision);
136 	regmap_read(regs, VSDC_TOP_CHIP_CUSTOMER_ID, &customer_id);
137 
138 	for (i = 0; i < ARRAY_SIZE(vs_chip_identities); i++) {
139 		if (vs_chip_identities[i].model == model &&
140 		    vs_chip_identities[i].revision == revision &&
141 		    (vs_chip_identities[i].customer_id == customer_id ||
142 		     vs_chip_identities[i].customer_id == ~0U)) {
143 			memcpy(ident, &vs_chip_identities[i], sizeof(*ident));
144 			ident->customer_id = customer_id;
145 			return 0;
146 		}
147 	}
148 
149 	return -EINVAL;
150 }
151