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