xref: /linux/drivers/gpu/drm/verisilicon/vs_plane.h (revision bba2c3615bd6cfee7456d1130f2e6b01b3f4e9ba)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2025 Icenowy Zheng <uwu@icenowy.me>
4  *
5  * Based on vs_dc_hw.h, which is:
6  *   Copyright (C) 2023 VeriSilicon Holdings Co., Ltd.
7  */
8 
9 #ifndef _VS_PLANE_H_
10 #define _VS_PLANE_H_
11 
12 #include <linux/types.h>
13 
14 #include <drm/drm_device.h>
15 #include <drm/drm_framebuffer.h>
16 #include <drm/drm_plane.h>
17 #include <drm/drm_rect.h>
18 
19 #define VSDC_MAKE_PLANE_SIZE(w, h) (((w) & 0x7fff) | (((h) & 0x7fff) << 15))
20 #define VSDC_MAKE_PLANE_POS(x, y) (((x) & 0x7fff) | (((y) & 0x7fff) << 15))
21 
22 struct vs_dc;
23 
24 enum vs_color_format {
25 	VSDC_COLOR_FORMAT_X4R4G4B4,
26 	VSDC_COLOR_FORMAT_A4R4G4B4,
27 	VSDC_COLOR_FORMAT_X1R5G5B5,
28 	VSDC_COLOR_FORMAT_A1R5G5B5,
29 	VSDC_COLOR_FORMAT_R5G6B5,
30 	VSDC_COLOR_FORMAT_X8R8G8B8,
31 	VSDC_COLOR_FORMAT_A8R8G8B8,
32 	VSDC_COLOR_FORMAT_YUY2,
33 	VSDC_COLOR_FORMAT_UYVY,
34 	VSDC_COLOR_FORMAT_INDEX8,
35 	VSDC_COLOR_FORMAT_MONOCHROME,
36 	VSDC_COLOR_FORMAT_YV12 = 0xf,
37 	VSDC_COLOR_FORMAT_A8,
38 	VSDC_COLOR_FORMAT_NV12,
39 	VSDC_COLOR_FORMAT_NV16,
40 	VSDC_COLOR_FORMAT_RG16,
41 	VSDC_COLOR_FORMAT_R8,
42 	VSDC_COLOR_FORMAT_NV12_10BIT,
43 	VSDC_COLOR_FORMAT_A2R10G10B10,
44 	VSDC_COLOR_FORMAT_NV16_10BIT,
45 	VSDC_COLOR_FORMAT_INDEX1,
46 	VSDC_COLOR_FORMAT_INDEX2,
47 	VSDC_COLOR_FORMAT_INDEX4,
48 	VSDC_COLOR_FORMAT_P010,
49 	VSDC_COLOR_FORMAT_YUV444,
50 	VSDC_COLOR_FORMAT_YUV444_10BIT
51 };
52 
53 enum vs_swizzle {
54 	VSDC_SWIZZLE_ARGB,
55 	VSDC_SWIZZLE_RGBA,
56 	VSDC_SWIZZLE_ABGR,
57 	VSDC_SWIZZLE_BGRA,
58 };
59 
60 struct vs_format {
61 	enum vs_color_format color;
62 	enum vs_swizzle swizzle;
63 	bool uv_swizzle;
64 };
65 
66 struct vs_plane_state {
67 	struct drm_plane_state base;
68 
69 	struct vs_format format;
70 };
71 
72 static inline struct vs_plane_state *to_vs_plane_state(struct drm_plane_state *state)
73 {
74 	return container_of(state, struct vs_plane_state, base);
75 }
76 
77 int drm_format_to_vs_format(u32 drm_format, struct vs_format *vs_format);
78 dma_addr_t vs_fb_get_dma_addr(struct drm_framebuffer *fb,
79 			      const struct drm_rect *src_rect);
80 
81 struct drm_plane_state *vs_plane_duplicate_state(struct drm_plane *plane);
82 void vs_plane_destroy_state(struct drm_plane *plane,
83 			    struct drm_plane_state *state);
84 void vs_plane_reset(struct drm_plane *plane);
85 
86 struct drm_plane *vs_primary_plane_init(struct drm_device *dev, struct vs_dc *dc);
87 struct drm_plane *vs_cursor_plane_init(struct drm_device *dev, struct vs_dc *dc);
88 
89 #endif /* _VS_PLANE_H_ */
90