xref: /netbsd-src/sys/arch/arm/ti/ti_lcdc.h (revision 9fb66d812c00ebfb445c0b47dea128f32aa6fe96)
1 /* $NetBSD: ti_lcdc.h,v 1.1 2019/11/03 22:59:06 jmcneill 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_TI_TI_LCDC_H
30 #define _ARM_TI_TI_LCDC_H
31 
32 #include <drm/drm_fb_helper.h>
33 #include <drm/drm_gem_cma_helper.h>
34 
35 #define DRIVER_AUTHOR		"NetBSD"
36 
37 #define DRIVER_NAME		"tilcdc"
38 #define DRIVER_DESC		"TI LCDC"
39 #define DRIVER_DATE		"20191103"
40 
41 #define DRIVER_MAJOR		1
42 #define DRIVER_MINOR		0
43 #define DRIVER_PATCHLEVEL	0
44 
45 struct tilcdc_softc;
46 struct tilcdc_framebuffer;
47 
48 struct tilcdc_vblank {
49 	void			*priv;
50 	void			(*enable_vblank)(void *);
51 	void			(*disable_vblank)(void *);
52 	uint32_t		(*get_vblank_counter)(void *);
53 };
54 
55 struct tilcdc_crtc {
56 	struct drm_crtc		base;
57 	struct tilcdc_softc	*sc;
58 };
59 
60 struct tilcdc_encoder {
61 	struct drm_encoder	base;
62 	struct tilcdc_softc	*sc;
63 };
64 
65 struct tilcdc_softc {
66 	device_t		sc_dev;
67 	struct drm_device	*sc_ddev;
68 
69 	bus_space_tag_t		sc_bst;
70 	bus_space_handle_t	sc_bsh;
71 	bus_dma_tag_t		sc_dmat;
72 
73 	struct clk		*sc_clk;
74 	int			sc_phandle;
75 
76 	struct tilcdc_crtc	sc_crtc;
77 	struct tilcdc_encoder	sc_encoder;
78 	struct tilcdc_vblank	sc_vbl;
79 
80 	struct fdt_device_ports	sc_ports;
81 };
82 
83 struct tilcdc_framebuffer {
84 	struct drm_framebuffer	base;
85 	struct drm_gem_cma_object *obj;
86 };
87 
88 struct tilcdc_fbdev {
89 	struct drm_fb_helper	helper;
90 };
91 
92 struct tilcdcfb_attach_args {
93 	struct drm_device	*tfa_drm_dev;
94 	struct drm_fb_helper	*tfa_fb_helper;
95 	struct drm_fb_helper_surface_size tfa_fb_sizes;
96 	bus_space_tag_t		tfa_fb_bst;
97 	bus_dma_tag_t		tfa_fb_dmat;
98 	uint32_t		tfa_fb_linebytes;
99 };
100 
101 #define tilcdc_private(ddev)		(ddev)->dev_private
102 #define	to_tilcdc_framebuffer(x)	container_of(x, struct tilcdc_framebuffer, base)
103 #define	to_tilcdc_crtc(x)		container_of(x, struct tilcdc_crtc, base)
104 
105 #define	RD4(sc, reg)			\
106 	bus_space_read_4((sc)->sc_bst, (sc)->sc_bsh, (reg))
107 #define	WR4(sc, reg, val)		\
108 	bus_space_write_4((sc)->sc_bst, (sc)->sc_bsh, (reg), (val))
109 
110 #endif /* _ARM_TI_TI_LCDC_H */
111