xref: /netbsd-src/sys/arch/arm/rockchip/rk_drm.h (revision 5549b16be2f2338b498d9e65d71616967a499fd3)
1 /* $NetBSD: rk_drm.h,v 1.2 2021/12/19 12:28:27 riastradh Exp $ */
2 
3 /*-
4  * Copyright (c) 2019 Jared D. McNeill <jmcneill@invisible.ca>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #ifndef _ARM_RK_DRM_H
30 #define _ARM_RK_DRM_H
31 
32 #include <sys/workqueue.h>
33 #include <drm/drm_fb_helper.h>
34 #include <drm/drm_gem_cma_helper.h>
35 
36 #define DRIVER_AUTHOR		"Jared McNeill"
37 
38 #define DRIVER_NAME		"rk"
39 #define DRIVER_DESC		"Rockchip Display Subsystem"
40 #define DRIVER_DATE		"20191109"
41 
42 #define DRIVER_MAJOR		1
43 #define DRIVER_MINOR		0
44 #define DRIVER_PATCHLEVEL	0
45 
46 struct rk_framebuffer;
47 
48 #define	RK_DRM_MAX_CRTC	2
49 
50 struct rk_drm_vblank {
51 	void			*priv;
52 	void			(*enable_vblank)(void *);
53 	void			(*disable_vblank)(void *);
54 	uint32_t		(*get_vblank_counter)(void *);
55 };
56 
57 struct rk_drm_softc {
58 	device_t		sc_dev;
59 	struct drm_device	*sc_ddev;
60 
61 	bus_space_tag_t		sc_bst;
62 	bus_dma_tag_t		sc_dmat;
63 
64 	int			sc_phandle;
65 
66 	struct lwp			*sc_task_thread;
67 	SIMPLEQ_HEAD(, rk_drm_task)	sc_tasks;
68 	struct workqueue		*sc_task_wq;
69 
70 	bool			sc_dev_registered;
71 
72 	struct rk_drm_vblank	sc_vbl[RK_DRM_MAX_CRTC];
73 };
74 
75 struct rk_drm_framebuffer {
76 	struct drm_framebuffer	base;
77 	struct drm_gem_cma_object *obj;
78 };
79 
80 struct rk_drm_ports {
81 	int			phandle;
82 	struct fdt_device_ports	*port;
83 	struct drm_device	*ddev;
84 	TAILQ_ENTRY(rk_drm_ports) entries;
85 };
86 
87 struct rk_drm_fbdev {
88 	struct drm_fb_helper	helper;
89 };
90 
91 struct rk_drmfb_attach_args {
92 	struct drm_device	*sfa_drm_dev;
93 	struct drm_fb_helper	*sfa_fb_helper;
94 	struct drm_fb_helper_surface_size sfa_fb_sizes;
95 	bus_space_tag_t		sfa_fb_bst;
96 	bus_dma_tag_t		sfa_fb_dmat;
97 	uint32_t		sfa_fb_linebytes;
98 };
99 
100 struct rk_drm_task {
101 	union {
102 		SIMPLEQ_ENTRY(rk_drm_task)	queue;
103 		struct work			work;
104 	}		rdt_u;
105 	void		(*rdt_fn)(struct rk_drm_task *);
106 };
107 
108 #define rk_drm_private(ddev)		(ddev)->dev_private
109 #define	to_rk_drm_framebuffer(x)	container_of(x, struct rk_drm_framebuffer, base)
110 
111 int	rk_drm_register_port(int, struct fdt_device_ports *);
112 struct drm_device *rk_drm_port_device(struct fdt_device_ports *);
113 
114 void	rk_task_init(struct rk_drm_task *,
115 	    void (*)(struct rk_drm_task *));
116 void	rk_task_schedule(device_t, struct rk_drm_task *);
117 
118 #endif /* _ARM_RK_DRM_H */
119