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