xref: /linux/drivers/gpu/drm/vc4/vc4_drv.h (revision 48666d56312b337ff3f04451bf6c3f014fee1eeb)
1c8b75bcaSEric Anholt /*
2c8b75bcaSEric Anholt  * Copyright (C) 2015 Broadcom
3c8b75bcaSEric Anholt  *
4c8b75bcaSEric Anholt  * This program is free software; you can redistribute it and/or modify
5c8b75bcaSEric Anholt  * it under the terms of the GNU General Public License version 2 as
6c8b75bcaSEric Anholt  * published by the Free Software Foundation.
7c8b75bcaSEric Anholt  */
8c8b75bcaSEric Anholt 
9c8b75bcaSEric Anholt #include "drmP.h"
10c8b75bcaSEric Anholt #include "drm_gem_cma_helper.h"
11c8b75bcaSEric Anholt 
12c8b75bcaSEric Anholt struct vc4_dev {
13c8b75bcaSEric Anholt 	struct drm_device *dev;
14c8b75bcaSEric Anholt 
15c8b75bcaSEric Anholt 	struct vc4_hdmi *hdmi;
16c8b75bcaSEric Anholt 	struct vc4_hvs *hvs;
17c8b75bcaSEric Anholt 	struct vc4_crtc *crtc[3];
18*48666d56SDerek Foreman 
19*48666d56SDerek Foreman 	struct drm_fbdev_cma *fbdev;
20c8b75bcaSEric Anholt };
21c8b75bcaSEric Anholt 
22c8b75bcaSEric Anholt static inline struct vc4_dev *
23c8b75bcaSEric Anholt to_vc4_dev(struct drm_device *dev)
24c8b75bcaSEric Anholt {
25c8b75bcaSEric Anholt 	return (struct vc4_dev *)dev->dev_private;
26c8b75bcaSEric Anholt }
27c8b75bcaSEric Anholt 
28c8b75bcaSEric Anholt struct vc4_bo {
29c8b75bcaSEric Anholt 	struct drm_gem_cma_object base;
30c8b75bcaSEric Anholt };
31c8b75bcaSEric Anholt 
32c8b75bcaSEric Anholt static inline struct vc4_bo *
33c8b75bcaSEric Anholt to_vc4_bo(struct drm_gem_object *bo)
34c8b75bcaSEric Anholt {
35c8b75bcaSEric Anholt 	return (struct vc4_bo *)bo;
36c8b75bcaSEric Anholt }
37c8b75bcaSEric Anholt 
38c8b75bcaSEric Anholt struct vc4_hvs {
39c8b75bcaSEric Anholt 	struct platform_device *pdev;
40c8b75bcaSEric Anholt 	void __iomem *regs;
41c8b75bcaSEric Anholt 	void __iomem *dlist;
42c8b75bcaSEric Anholt };
43c8b75bcaSEric Anholt 
44c8b75bcaSEric Anholt struct vc4_plane {
45c8b75bcaSEric Anholt 	struct drm_plane base;
46c8b75bcaSEric Anholt };
47c8b75bcaSEric Anholt 
48c8b75bcaSEric Anholt static inline struct vc4_plane *
49c8b75bcaSEric Anholt to_vc4_plane(struct drm_plane *plane)
50c8b75bcaSEric Anholt {
51c8b75bcaSEric Anholt 	return (struct vc4_plane *)plane;
52c8b75bcaSEric Anholt }
53c8b75bcaSEric Anholt 
54c8b75bcaSEric Anholt enum vc4_encoder_type {
55c8b75bcaSEric Anholt 	VC4_ENCODER_TYPE_HDMI,
56c8b75bcaSEric Anholt 	VC4_ENCODER_TYPE_VEC,
57c8b75bcaSEric Anholt 	VC4_ENCODER_TYPE_DSI0,
58c8b75bcaSEric Anholt 	VC4_ENCODER_TYPE_DSI1,
59c8b75bcaSEric Anholt 	VC4_ENCODER_TYPE_SMI,
60c8b75bcaSEric Anholt 	VC4_ENCODER_TYPE_DPI,
61c8b75bcaSEric Anholt };
62c8b75bcaSEric Anholt 
63c8b75bcaSEric Anholt struct vc4_encoder {
64c8b75bcaSEric Anholt 	struct drm_encoder base;
65c8b75bcaSEric Anholt 	enum vc4_encoder_type type;
66c8b75bcaSEric Anholt 	u32 clock_select;
67c8b75bcaSEric Anholt };
68c8b75bcaSEric Anholt 
69c8b75bcaSEric Anholt static inline struct vc4_encoder *
70c8b75bcaSEric Anholt to_vc4_encoder(struct drm_encoder *encoder)
71c8b75bcaSEric Anholt {
72c8b75bcaSEric Anholt 	return container_of(encoder, struct vc4_encoder, base);
73c8b75bcaSEric Anholt }
74c8b75bcaSEric Anholt 
75c8b75bcaSEric Anholt #define HVS_READ(offset) readl(vc4->hvs->regs + offset)
76c8b75bcaSEric Anholt #define HVS_WRITE(offset, val) writel(val, vc4->hvs->regs + offset)
77c8b75bcaSEric Anholt 
78c8b75bcaSEric Anholt /**
79c8b75bcaSEric Anholt  * _wait_for - magic (register) wait macro
80c8b75bcaSEric Anholt  *
81c8b75bcaSEric Anholt  * Does the right thing for modeset paths when run under kdgb or similar atomic
82c8b75bcaSEric Anholt  * contexts. Note that it's important that we check the condition again after
83c8b75bcaSEric Anholt  * having timed out, since the timeout could be due to preemption or similar and
84c8b75bcaSEric Anholt  * we've never had a chance to check the condition before the timeout.
85c8b75bcaSEric Anholt  */
86c8b75bcaSEric Anholt #define _wait_for(COND, MS, W) ({ \
87c8b75bcaSEric Anholt 	unsigned long timeout__ = jiffies + msecs_to_jiffies(MS) + 1;	\
88c8b75bcaSEric Anholt 	int ret__ = 0;							\
89c8b75bcaSEric Anholt 	while (!(COND)) {						\
90c8b75bcaSEric Anholt 		if (time_after(jiffies, timeout__)) {			\
91c8b75bcaSEric Anholt 			if (!(COND))					\
92c8b75bcaSEric Anholt 				ret__ = -ETIMEDOUT;			\
93c8b75bcaSEric Anholt 			break;						\
94c8b75bcaSEric Anholt 		}							\
95c8b75bcaSEric Anholt 		if (W && drm_can_sleep())  {				\
96c8b75bcaSEric Anholt 			msleep(W);					\
97c8b75bcaSEric Anholt 		} else {						\
98c8b75bcaSEric Anholt 			cpu_relax();					\
99c8b75bcaSEric Anholt 		}							\
100c8b75bcaSEric Anholt 	}								\
101c8b75bcaSEric Anholt 	ret__;								\
102c8b75bcaSEric Anholt })
103c8b75bcaSEric Anholt 
104c8b75bcaSEric Anholt #define wait_for(COND, MS) _wait_for(COND, MS, 1)
105c8b75bcaSEric Anholt 
106c8b75bcaSEric Anholt /* vc4_bo.c */
107c8b75bcaSEric Anholt void vc4_free_object(struct drm_gem_object *gem_obj);
108c8b75bcaSEric Anholt struct vc4_bo *vc4_bo_create(struct drm_device *dev, size_t size);
109c8b75bcaSEric Anholt int vc4_dumb_create(struct drm_file *file_priv,
110c8b75bcaSEric Anholt 		    struct drm_device *dev,
111c8b75bcaSEric Anholt 		    struct drm_mode_create_dumb *args);
112c8b75bcaSEric Anholt struct dma_buf *vc4_prime_export(struct drm_device *dev,
113c8b75bcaSEric Anholt 				 struct drm_gem_object *obj, int flags);
114c8b75bcaSEric Anholt 
115c8b75bcaSEric Anholt /* vc4_crtc.c */
116c8b75bcaSEric Anholt extern struct platform_driver vc4_crtc_driver;
117c8b75bcaSEric Anholt int vc4_enable_vblank(struct drm_device *dev, int crtc_id);
118c8b75bcaSEric Anholt void vc4_disable_vblank(struct drm_device *dev, int crtc_id);
119c8b75bcaSEric Anholt void vc4_cancel_page_flip(struct drm_crtc *crtc, struct drm_file *file);
120c8b75bcaSEric Anholt int vc4_crtc_debugfs_regs(struct seq_file *m, void *arg);
121c8b75bcaSEric Anholt 
122c8b75bcaSEric Anholt /* vc4_debugfs.c */
123c8b75bcaSEric Anholt int vc4_debugfs_init(struct drm_minor *minor);
124c8b75bcaSEric Anholt void vc4_debugfs_cleanup(struct drm_minor *minor);
125c8b75bcaSEric Anholt 
126c8b75bcaSEric Anholt /* vc4_drv.c */
127c8b75bcaSEric Anholt void __iomem *vc4_ioremap_regs(struct platform_device *dev, int index);
128c8b75bcaSEric Anholt 
129c8b75bcaSEric Anholt /* vc4_hdmi.c */
130c8b75bcaSEric Anholt extern struct platform_driver vc4_hdmi_driver;
131c8b75bcaSEric Anholt int vc4_hdmi_debugfs_regs(struct seq_file *m, void *unused);
132c8b75bcaSEric Anholt 
133c8b75bcaSEric Anholt /* vc4_hvs.c */
134c8b75bcaSEric Anholt extern struct platform_driver vc4_hvs_driver;
135c8b75bcaSEric Anholt void vc4_hvs_dump_state(struct drm_device *dev);
136c8b75bcaSEric Anholt int vc4_hvs_debugfs_regs(struct seq_file *m, void *unused);
137c8b75bcaSEric Anholt 
138c8b75bcaSEric Anholt /* vc4_kms.c */
139c8b75bcaSEric Anholt int vc4_kms_load(struct drm_device *dev);
140c8b75bcaSEric Anholt 
141c8b75bcaSEric Anholt /* vc4_plane.c */
142c8b75bcaSEric Anholt struct drm_plane *vc4_plane_init(struct drm_device *dev,
143c8b75bcaSEric Anholt 				 enum drm_plane_type type);
144c8b75bcaSEric Anholt u32 vc4_plane_write_dlist(struct drm_plane *plane, u32 __iomem *dlist);
145c8b75bcaSEric Anholt u32 vc4_plane_dlist_size(struct drm_plane_state *state);
146