xref: /openbmc/linux/drivers/gpu/drm/msm/msm_kms.h (revision 176f011b)
1 /*
2  * Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
3  * Copyright (C) 2013 Red Hat
4  * Author: Rob Clark <robdclark@gmail.com>
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License version 2 as published by
8  * the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along with
16  * this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef __MSM_KMS_H__
20 #define __MSM_KMS_H__
21 
22 #include <linux/clk.h>
23 #include <linux/regulator/consumer.h>
24 
25 #include "msm_drv.h"
26 
27 #define MAX_PLANE	4
28 
29 /* As there are different display controller blocks depending on the
30  * snapdragon version, the kms support is split out and the appropriate
31  * implementation is loaded at runtime.  The kms module is responsible
32  * for constructing the appropriate planes/crtcs/encoders/connectors.
33  */
34 struct msm_kms_funcs {
35 	/* hw initialization: */
36 	int (*hw_init)(struct msm_kms *kms);
37 	/* irq handling: */
38 	void (*irq_preinstall)(struct msm_kms *kms);
39 	int (*irq_postinstall)(struct msm_kms *kms);
40 	void (*irq_uninstall)(struct msm_kms *kms);
41 	irqreturn_t (*irq)(struct msm_kms *kms);
42 	int (*enable_vblank)(struct msm_kms *kms, struct drm_crtc *crtc);
43 	void (*disable_vblank)(struct msm_kms *kms, struct drm_crtc *crtc);
44 	/* modeset, bracketing atomic_commit(): */
45 	void (*prepare_commit)(struct msm_kms *kms, struct drm_atomic_state *state);
46 	void (*commit)(struct msm_kms *kms, struct drm_atomic_state *state);
47 	void (*complete_commit)(struct msm_kms *kms, struct drm_atomic_state *state);
48 	/* functions to wait for atomic commit completed on each CRTC */
49 	void (*wait_for_crtc_commit_done)(struct msm_kms *kms,
50 					struct drm_crtc *crtc);
51 	/* get msm_format w/ optional format modifiers from drm_mode_fb_cmd2 */
52 	const struct msm_format *(*get_format)(struct msm_kms *kms,
53 					const uint32_t format,
54 					const uint64_t modifiers);
55 	/* do format checking on format modified through fb_cmd2 modifiers */
56 	int (*check_modified_format)(const struct msm_kms *kms,
57 			const struct msm_format *msm_fmt,
58 			const struct drm_mode_fb_cmd2 *cmd,
59 			struct drm_gem_object **bos);
60 	/* misc: */
61 	long (*round_pixclk)(struct msm_kms *kms, unsigned long rate,
62 			struct drm_encoder *encoder);
63 	int (*set_split_display)(struct msm_kms *kms,
64 			struct drm_encoder *encoder,
65 			struct drm_encoder *slave_encoder,
66 			bool is_cmd_mode);
67 	void (*set_encoder_mode)(struct msm_kms *kms,
68 				 struct drm_encoder *encoder,
69 				 bool cmd_mode);
70 	/* cleanup: */
71 	void (*destroy)(struct msm_kms *kms);
72 #ifdef CONFIG_DEBUG_FS
73 	/* debugfs: */
74 	int (*debugfs_init)(struct msm_kms *kms, struct drm_minor *minor);
75 #endif
76 };
77 
78 struct msm_kms {
79 	const struct msm_kms_funcs *funcs;
80 
81 	/* irq number to be passed on to drm_irq_install */
82 	int irq;
83 
84 	/* mapper-id used to request GEM buffer mapped for scanout: */
85 	struct msm_gem_address_space *aspace;
86 };
87 
88 static inline void msm_kms_init(struct msm_kms *kms,
89 		const struct msm_kms_funcs *funcs)
90 {
91 	kms->funcs = funcs;
92 }
93 
94 struct msm_kms *mdp4_kms_init(struct drm_device *dev);
95 struct msm_kms *mdp5_kms_init(struct drm_device *dev);
96 struct msm_kms *dpu_kms_init(struct drm_device *dev);
97 
98 struct msm_mdss_funcs {
99 	int (*enable)(struct msm_mdss *mdss);
100 	int (*disable)(struct msm_mdss *mdss);
101 	void (*destroy)(struct drm_device *dev);
102 };
103 
104 struct msm_mdss {
105 	struct drm_device *dev;
106 	const struct msm_mdss_funcs *funcs;
107 };
108 
109 int mdp5_mdss_init(struct drm_device *dev);
110 int dpu_mdss_init(struct drm_device *dev);
111 
112 #endif /* __MSM_KMS_H__ */
113