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