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