xref: /openbmc/linux/drivers/gpu/drm/tegra/drm.h (revision 0ae797a8)
1 /*
2  * Copyright (C) 2012 Avionic Design GmbH
3  * Copyright (C) 2012-2013 NVIDIA CORPORATION.  All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation.
8  */
9 
10 #ifndef HOST1X_DRM_H
11 #define HOST1X_DRM_H 1
12 
13 #include <uapi/drm/tegra_drm.h>
14 #include <linux/host1x.h>
15 #include <linux/iova.h>
16 #include <linux/of_gpio.h>
17 
18 #include <drm/drmP.h>
19 #include <drm/drm_crtc_helper.h>
20 #include <drm/drm_edid.h>
21 #include <drm/drm_encoder.h>
22 #include <drm/drm_fb_helper.h>
23 #include <drm/drm_fixed.h>
24 
25 #include "gem.h"
26 
27 struct reset_control;
28 
29 struct tegra_fb {
30 	struct drm_framebuffer base;
31 	struct tegra_bo **planes;
32 	unsigned int num_planes;
33 };
34 
35 #ifdef CONFIG_DRM_FBDEV_EMULATION
36 struct tegra_fbdev {
37 	struct drm_fb_helper base;
38 	struct tegra_fb *fb;
39 };
40 #endif
41 
42 struct tegra_drm {
43 	struct drm_device *drm;
44 
45 	struct iommu_domain *domain;
46 	struct mutex mm_lock;
47 	struct drm_mm mm;
48 
49 	struct {
50 		struct iova_domain domain;
51 		unsigned long shift;
52 		unsigned long limit;
53 	} carveout;
54 
55 	struct mutex clients_lock;
56 	struct list_head clients;
57 
58 #ifdef CONFIG_DRM_FBDEV_EMULATION
59 	struct tegra_fbdev *fbdev;
60 #endif
61 
62 	unsigned int pitch_align;
63 
64 	struct {
65 		struct drm_atomic_state *state;
66 		struct work_struct work;
67 		struct mutex lock;
68 	} commit;
69 
70 	struct drm_atomic_state *state;
71 };
72 
73 struct tegra_drm_client;
74 
75 struct tegra_drm_context {
76 	struct tegra_drm_client *client;
77 	struct host1x_channel *channel;
78 	unsigned int id;
79 };
80 
81 struct tegra_drm_client_ops {
82 	int (*open_channel)(struct tegra_drm_client *client,
83 			    struct tegra_drm_context *context);
84 	void (*close_channel)(struct tegra_drm_context *context);
85 	int (*is_addr_reg)(struct device *dev, u32 class, u32 offset);
86 	int (*submit)(struct tegra_drm_context *context,
87 		      struct drm_tegra_submit *args, struct drm_device *drm,
88 		      struct drm_file *file);
89 };
90 
91 int tegra_drm_submit(struct tegra_drm_context *context,
92 		     struct drm_tegra_submit *args, struct drm_device *drm,
93 		     struct drm_file *file);
94 
95 struct tegra_drm_client {
96 	struct host1x_client base;
97 	struct list_head list;
98 
99 	const struct tegra_drm_client_ops *ops;
100 };
101 
102 static inline struct tegra_drm_client *
103 host1x_to_drm_client(struct host1x_client *client)
104 {
105 	return container_of(client, struct tegra_drm_client, base);
106 }
107 
108 int tegra_drm_register_client(struct tegra_drm *tegra,
109 			      struct tegra_drm_client *client);
110 int tegra_drm_unregister_client(struct tegra_drm *tegra,
111 				struct tegra_drm_client *client);
112 
113 int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm);
114 int tegra_drm_exit(struct tegra_drm *tegra);
115 
116 void *tegra_drm_alloc(struct tegra_drm *tegra, size_t size, dma_addr_t *iova);
117 void tegra_drm_free(struct tegra_drm *tegra, size_t size, void *virt,
118 		    dma_addr_t iova);
119 
120 struct tegra_dc_soc_info;
121 struct tegra_output;
122 
123 struct tegra_dc_stats {
124 	unsigned long frames;
125 	unsigned long vblank;
126 	unsigned long underflow;
127 	unsigned long overflow;
128 };
129 
130 struct tegra_dc {
131 	struct host1x_client client;
132 	struct host1x_syncpt *syncpt;
133 	struct device *dev;
134 	spinlock_t lock;
135 
136 	struct drm_crtc base;
137 	unsigned int powergate;
138 	int pipe;
139 
140 	struct clk *clk;
141 	struct reset_control *rst;
142 	void __iomem *regs;
143 	int irq;
144 
145 	struct tegra_output *rgb;
146 
147 	struct tegra_dc_stats stats;
148 	struct list_head list;
149 
150 	struct drm_info_list *debugfs_files;
151 	struct drm_minor *minor;
152 	struct dentry *debugfs;
153 
154 	/* page-flip handling */
155 	struct drm_pending_vblank_event *event;
156 
157 	const struct tegra_dc_soc_info *soc;
158 
159 	struct iommu_domain *domain;
160 };
161 
162 static inline struct tegra_dc *
163 host1x_client_to_dc(struct host1x_client *client)
164 {
165 	return container_of(client, struct tegra_dc, client);
166 }
167 
168 static inline struct tegra_dc *to_tegra_dc(struct drm_crtc *crtc)
169 {
170 	return crtc ? container_of(crtc, struct tegra_dc, base) : NULL;
171 }
172 
173 static inline void tegra_dc_writel(struct tegra_dc *dc, u32 value,
174 				   unsigned long offset)
175 {
176 	writel(value, dc->regs + (offset << 2));
177 }
178 
179 static inline u32 tegra_dc_readl(struct tegra_dc *dc, unsigned long offset)
180 {
181 	return readl(dc->regs + (offset << 2));
182 }
183 
184 struct tegra_dc_window {
185 	struct {
186 		unsigned int x;
187 		unsigned int y;
188 		unsigned int w;
189 		unsigned int h;
190 	} src;
191 	struct {
192 		unsigned int x;
193 		unsigned int y;
194 		unsigned int w;
195 		unsigned int h;
196 	} dst;
197 	unsigned int bits_per_pixel;
198 	unsigned int stride[2];
199 	unsigned long base[3];
200 	bool bottom_up;
201 
202 	struct tegra_bo_tiling tiling;
203 	u32 format;
204 	u32 swap;
205 };
206 
207 /* from dc.c */
208 u32 tegra_dc_get_vblank_counter(struct tegra_dc *dc);
209 void tegra_dc_enable_vblank(struct tegra_dc *dc);
210 void tegra_dc_disable_vblank(struct tegra_dc *dc);
211 void tegra_dc_commit(struct tegra_dc *dc);
212 int tegra_dc_state_setup_clock(struct tegra_dc *dc,
213 			       struct drm_crtc_state *crtc_state,
214 			       struct clk *clk, unsigned long pclk,
215 			       unsigned int div);
216 
217 struct tegra_output {
218 	struct device_node *of_node;
219 	struct device *dev;
220 
221 	struct drm_panel *panel;
222 	struct i2c_adapter *ddc;
223 	const struct edid *edid;
224 	unsigned int hpd_irq;
225 	int hpd_gpio;
226 	enum of_gpio_flags hpd_gpio_flags;
227 
228 	struct drm_encoder encoder;
229 	struct drm_connector connector;
230 };
231 
232 static inline struct tegra_output *encoder_to_output(struct drm_encoder *e)
233 {
234 	return container_of(e, struct tegra_output, encoder);
235 }
236 
237 static inline struct tegra_output *connector_to_output(struct drm_connector *c)
238 {
239 	return container_of(c, struct tegra_output, connector);
240 }
241 
242 /* from rgb.c */
243 int tegra_dc_rgb_probe(struct tegra_dc *dc);
244 int tegra_dc_rgb_remove(struct tegra_dc *dc);
245 int tegra_dc_rgb_init(struct drm_device *drm, struct tegra_dc *dc);
246 int tegra_dc_rgb_exit(struct tegra_dc *dc);
247 
248 /* from output.c */
249 int tegra_output_probe(struct tegra_output *output);
250 void tegra_output_remove(struct tegra_output *output);
251 int tegra_output_init(struct drm_device *drm, struct tegra_output *output);
252 void tegra_output_exit(struct tegra_output *output);
253 
254 int tegra_output_connector_get_modes(struct drm_connector *connector);
255 enum drm_connector_status
256 tegra_output_connector_detect(struct drm_connector *connector, bool force);
257 void tegra_output_connector_destroy(struct drm_connector *connector);
258 
259 void tegra_output_encoder_destroy(struct drm_encoder *encoder);
260 
261 /* from dpaux.c */
262 struct drm_dp_link;
263 
264 struct drm_dp_aux *drm_dp_aux_find_by_of_node(struct device_node *np);
265 enum drm_connector_status drm_dp_aux_detect(struct drm_dp_aux *aux);
266 int drm_dp_aux_attach(struct drm_dp_aux *aux, struct tegra_output *output);
267 int drm_dp_aux_detach(struct drm_dp_aux *aux);
268 int drm_dp_aux_enable(struct drm_dp_aux *aux);
269 int drm_dp_aux_disable(struct drm_dp_aux *aux);
270 int drm_dp_aux_prepare(struct drm_dp_aux *aux, u8 encoding);
271 int drm_dp_aux_train(struct drm_dp_aux *aux, struct drm_dp_link *link,
272 		     u8 pattern);
273 
274 /* from fb.c */
275 struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer,
276 				    unsigned int index);
277 bool tegra_fb_is_bottom_up(struct drm_framebuffer *framebuffer);
278 int tegra_fb_get_tiling(struct drm_framebuffer *framebuffer,
279 			struct tegra_bo_tiling *tiling);
280 struct drm_framebuffer *tegra_fb_create(struct drm_device *drm,
281 					struct drm_file *file,
282 					const struct drm_mode_fb_cmd2 *cmd);
283 int tegra_drm_fb_prepare(struct drm_device *drm);
284 void tegra_drm_fb_free(struct drm_device *drm);
285 int tegra_drm_fb_init(struct drm_device *drm);
286 void tegra_drm_fb_exit(struct drm_device *drm);
287 void tegra_drm_fb_suspend(struct drm_device *drm);
288 void tegra_drm_fb_resume(struct drm_device *drm);
289 #ifdef CONFIG_DRM_FBDEV_EMULATION
290 void tegra_fbdev_restore_mode(struct tegra_fbdev *fbdev);
291 void tegra_fb_output_poll_changed(struct drm_device *drm);
292 #endif
293 
294 extern struct platform_driver tegra_dc_driver;
295 extern struct platform_driver tegra_hdmi_driver;
296 extern struct platform_driver tegra_dsi_driver;
297 extern struct platform_driver tegra_dpaux_driver;
298 extern struct platform_driver tegra_sor_driver;
299 extern struct platform_driver tegra_gr2d_driver;
300 extern struct platform_driver tegra_gr3d_driver;
301 extern struct platform_driver tegra_vic_driver;
302 
303 #endif /* HOST1X_DRM_H */
304