xref: /openbmc/linux/drivers/gpu/drm/msm/msm_kms.h (revision bfe655d1)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
4  * Copyright (C) 2013 Red Hat
5  * Author: Rob Clark <robdclark@gmail.com>
6  */
7 
8 #ifndef __MSM_KMS_H__
9 #define __MSM_KMS_H__
10 
11 #include <linux/clk.h>
12 #include <linux/regulator/consumer.h>
13 
14 #include "msm_drv.h"
15 
16 #define MAX_PLANE	4
17 
18 /* As there are different display controller blocks depending on the
19  * snapdragon version, the kms support is split out and the appropriate
20  * implementation is loaded at runtime.  The kms module is responsible
21  * for constructing the appropriate planes/crtcs/encoders/connectors.
22  */
23 struct msm_kms_funcs {
24 	/* hw initialization: */
25 	int (*hw_init)(struct msm_kms *kms);
26 	/* irq handling: */
27 	void (*irq_preinstall)(struct msm_kms *kms);
28 	int (*irq_postinstall)(struct msm_kms *kms);
29 	void (*irq_uninstall)(struct msm_kms *kms);
30 	irqreturn_t (*irq)(struct msm_kms *kms);
31 	int (*enable_vblank)(struct msm_kms *kms, struct drm_crtc *crtc);
32 	void (*disable_vblank)(struct msm_kms *kms, struct drm_crtc *crtc);
33 	/* modeset, bracketing atomic_commit(): */
34 	void (*prepare_commit)(struct msm_kms *kms, struct drm_atomic_state *state);
35 	void (*commit)(struct msm_kms *kms, struct drm_atomic_state *state);
36 	void (*complete_commit)(struct msm_kms *kms, struct drm_atomic_state *state);
37 	/* functions to wait for atomic commit completed on each CRTC */
38 	void (*wait_for_crtc_commit_done)(struct msm_kms *kms,
39 					struct drm_crtc *crtc);
40 	/* get msm_format w/ optional format modifiers from drm_mode_fb_cmd2 */
41 	const struct msm_format *(*get_format)(struct msm_kms *kms,
42 					const uint32_t format,
43 					const uint64_t modifiers);
44 	/* do format checking on format modified through fb_cmd2 modifiers */
45 	int (*check_modified_format)(const struct msm_kms *kms,
46 			const struct msm_format *msm_fmt,
47 			const struct drm_mode_fb_cmd2 *cmd,
48 			struct drm_gem_object **bos);
49 	/* misc: */
50 	long (*round_pixclk)(struct msm_kms *kms, unsigned long rate,
51 			struct drm_encoder *encoder);
52 	int (*set_split_display)(struct msm_kms *kms,
53 			struct drm_encoder *encoder,
54 			struct drm_encoder *slave_encoder,
55 			bool is_cmd_mode);
56 	void (*set_encoder_mode)(struct msm_kms *kms,
57 				 struct drm_encoder *encoder,
58 				 bool cmd_mode);
59 	/* cleanup: */
60 	void (*destroy)(struct msm_kms *kms);
61 #ifdef CONFIG_DEBUG_FS
62 	/* debugfs: */
63 	int (*debugfs_init)(struct msm_kms *kms, struct drm_minor *minor);
64 #endif
65 };
66 
67 struct msm_kms {
68 	const struct msm_kms_funcs *funcs;
69 
70 	/* irq number to be passed on to drm_irq_install */
71 	int irq;
72 
73 	/* mapper-id used to request GEM buffer mapped for scanout: */
74 	struct msm_gem_address_space *aspace;
75 };
76 
77 static inline void msm_kms_init(struct msm_kms *kms,
78 		const struct msm_kms_funcs *funcs)
79 {
80 	kms->funcs = funcs;
81 }
82 
83 struct msm_kms *mdp4_kms_init(struct drm_device *dev);
84 struct msm_kms *mdp5_kms_init(struct drm_device *dev);
85 struct msm_kms *dpu_kms_init(struct drm_device *dev);
86 
87 struct msm_mdss_funcs {
88 	int (*enable)(struct msm_mdss *mdss);
89 	int (*disable)(struct msm_mdss *mdss);
90 	void (*destroy)(struct drm_device *dev);
91 };
92 
93 struct msm_mdss {
94 	struct drm_device *dev;
95 	const struct msm_mdss_funcs *funcs;
96 };
97 
98 int mdp5_mdss_init(struct drm_device *dev);
99 int dpu_mdss_init(struct drm_device *dev);
100 
101 #endif /* __MSM_KMS_H__ */
102