95b6aebfaf00b05d8c903c963495e6d614477756
[pandora-kernel.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
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
55 struct tegra_drm_client;
56
57 struct tegra_drm_context {
58         struct tegra_drm_client *client;
59         struct host1x_channel *channel;
60         struct list_head list;
61 };
62
63 struct tegra_drm_client_ops {
64         int (*open_channel)(struct tegra_drm_client *client,
65                             struct tegra_drm_context *context);
66         void (*close_channel)(struct tegra_drm_context *context);
67         int (*is_addr_reg)(struct device *dev, u32 class, u32 offset);
68         int (*submit)(struct tegra_drm_context *context,
69                       struct drm_tegra_submit *args, struct drm_device *drm,
70                       struct drm_file *file);
71 };
72
73 int tegra_drm_submit(struct tegra_drm_context *context,
74                      struct drm_tegra_submit *args, struct drm_device *drm,
75                      struct drm_file *file);
76
77 struct tegra_drm_client {
78         struct host1x_client base;
79         struct list_head list;
80
81         const struct tegra_drm_client_ops *ops;
82 };
83
84 static inline struct tegra_drm_client *
85 host1x_to_drm_client(struct host1x_client *client)
86 {
87         return container_of(client, struct tegra_drm_client, base);
88 }
89
90 int tegra_drm_register_client(struct tegra_drm *tegra,
91                               struct tegra_drm_client *client);
92 int tegra_drm_unregister_client(struct tegra_drm *tegra,
93                                 struct tegra_drm_client *client);
94
95 int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm);
96 int tegra_drm_exit(struct tegra_drm *tegra);
97
98 struct tegra_dc_soc_info;
99 struct tegra_output;
100
101 struct tegra_dc {
102         struct host1x_client client;
103         struct device *dev;
104         spinlock_t lock;
105
106         struct drm_crtc base;
107         int powergate;
108         int pipe;
109
110         struct clk *clk;
111         struct reset_control *rst;
112         void __iomem *regs;
113         int irq;
114
115         struct tegra_output *rgb;
116
117         struct list_head list;
118
119         struct drm_info_list *debugfs_files;
120         struct drm_minor *minor;
121         struct dentry *debugfs;
122
123         /* page-flip handling */
124         struct drm_pending_vblank_event *event;
125
126         const struct tegra_dc_soc_info *soc;
127
128         struct iommu_domain *domain;
129 };
130
131 static inline struct tegra_dc *
132 host1x_client_to_dc(struct host1x_client *client)
133 {
134         return container_of(client, struct tegra_dc, client);
135 }
136
137 static inline struct tegra_dc *to_tegra_dc(struct drm_crtc *crtc)
138 {
139         return crtc ? container_of(crtc, struct tegra_dc, base) : NULL;
140 }
141
142 static inline void tegra_dc_writel(struct tegra_dc *dc, u32 value,
143                                    unsigned long offset)
144 {
145         writel(value, dc->regs + (offset << 2));
146 }
147
148 static inline u32 tegra_dc_readl(struct tegra_dc *dc, unsigned long offset)
149 {
150         return readl(dc->regs + (offset << 2));
151 }
152
153 struct tegra_dc_window {
154         struct {
155                 unsigned int x;
156                 unsigned int y;
157                 unsigned int w;
158                 unsigned int h;
159         } src;
160         struct {
161                 unsigned int x;
162                 unsigned int y;
163                 unsigned int w;
164                 unsigned int h;
165         } dst;
166         unsigned int bits_per_pixel;
167         unsigned int format;
168         unsigned int swap;
169         unsigned int stride[2];
170         unsigned long base[3];
171         bool bottom_up;
172
173         struct tegra_bo_tiling tiling;
174 };
175
176 /* from dc.c */
177 void tegra_dc_enable_vblank(struct tegra_dc *dc);
178 void tegra_dc_disable_vblank(struct tegra_dc *dc);
179 void tegra_dc_cancel_page_flip(struct drm_crtc *crtc, struct drm_file *file);
180 void tegra_dc_commit(struct tegra_dc *dc);
181 int tegra_dc_setup_clock(struct tegra_dc *dc, struct clk *parent,
182                          unsigned long pclk, unsigned int div);
183
184 struct tegra_output_ops {
185         int (*enable)(struct tegra_output *output);
186         int (*disable)(struct tegra_output *output);
187         int (*setup_clock)(struct tegra_output *output, struct clk *clk,
188                            unsigned long pclk, unsigned int *div);
189         int (*check_mode)(struct tegra_output *output,
190                           struct drm_display_mode *mode,
191                           enum drm_mode_status *status);
192         enum drm_connector_status (*detect)(struct tegra_output *output);
193 };
194
195 enum tegra_output_type {
196         TEGRA_OUTPUT_DSI,
197         TEGRA_OUTPUT_EDP,
198 };
199
200 struct tegra_output {
201         struct device_node *of_node;
202         struct device *dev;
203
204         const struct tegra_output_ops *ops;
205         enum tegra_output_type type;
206
207         struct drm_panel *panel;
208         struct i2c_adapter *ddc;
209         const struct edid *edid;
210         unsigned int hpd_irq;
211         int hpd_gpio;
212
213         struct drm_encoder encoder;
214         struct drm_connector connector;
215 };
216
217 static inline struct tegra_output *encoder_to_output(struct drm_encoder *e)
218 {
219         return container_of(e, struct tegra_output, encoder);
220 }
221
222 static inline struct tegra_output *connector_to_output(struct drm_connector *c)
223 {
224         return container_of(c, struct tegra_output, connector);
225 }
226
227 static inline int tegra_output_enable(struct tegra_output *output)
228 {
229         if (output && output->ops && output->ops->enable)
230                 return output->ops->enable(output);
231
232         return output ? -ENOSYS : -EINVAL;
233 }
234
235 static inline int tegra_output_disable(struct tegra_output *output)
236 {
237         if (output && output->ops && output->ops->disable)
238                 return output->ops->disable(output);
239
240         return output ? -ENOSYS : -EINVAL;
241 }
242
243 static inline int tegra_output_check_mode(struct tegra_output *output,
244                                           struct drm_display_mode *mode,
245                                           enum drm_mode_status *status)
246 {
247         if (output && output->ops && output->ops->check_mode)
248                 return output->ops->check_mode(output, mode, status);
249
250         return output ? -ENOSYS : -EINVAL;
251 }
252
253 /* from rgb.c */
254 int tegra_dc_rgb_probe(struct tegra_dc *dc);
255 int tegra_dc_rgb_remove(struct tegra_dc *dc);
256 int tegra_dc_rgb_init(struct drm_device *drm, struct tegra_dc *dc);
257 int tegra_dc_rgb_exit(struct tegra_dc *dc);
258
259 /* from output.c */
260 int tegra_output_probe(struct tegra_output *output);
261 int tegra_output_remove(struct tegra_output *output);
262 int tegra_output_init(struct drm_device *drm, struct tegra_output *output);
263 int tegra_output_exit(struct tegra_output *output);
264
265 int tegra_output_connector_get_modes(struct drm_connector *connector);
266 struct drm_encoder *
267 tegra_output_connector_best_encoder(struct drm_connector *connector);
268 enum drm_connector_status
269 tegra_output_connector_detect(struct drm_connector *connector, bool force);
270 void tegra_output_connector_destroy(struct drm_connector *connector);
271
272 void tegra_output_encoder_destroy(struct drm_encoder *encoder);
273
274 /* from dpaux.c */
275 struct tegra_dpaux;
276 struct drm_dp_link;
277
278 struct tegra_dpaux *tegra_dpaux_find_by_of_node(struct device_node *np);
279 enum drm_connector_status tegra_dpaux_detect(struct tegra_dpaux *dpaux);
280 int tegra_dpaux_attach(struct tegra_dpaux *dpaux, struct tegra_output *output);
281 int tegra_dpaux_detach(struct tegra_dpaux *dpaux);
282 int tegra_dpaux_enable(struct tegra_dpaux *dpaux);
283 int tegra_dpaux_disable(struct tegra_dpaux *dpaux);
284 int tegra_dpaux_prepare(struct tegra_dpaux *dpaux, u8 encoding);
285 int tegra_dpaux_train(struct tegra_dpaux *dpaux, struct drm_dp_link *link,
286                       u8 pattern);
287
288 /* from fb.c */
289 struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer,
290                                     unsigned int index);
291 bool tegra_fb_is_bottom_up(struct drm_framebuffer *framebuffer);
292 int tegra_fb_get_tiling(struct drm_framebuffer *framebuffer,
293                         struct tegra_bo_tiling *tiling);
294 struct drm_framebuffer *tegra_fb_create(struct drm_device *drm,
295                                         struct drm_file *file,
296                                         struct drm_mode_fb_cmd2 *cmd);
297 int tegra_drm_fb_prepare(struct drm_device *drm);
298 void tegra_drm_fb_free(struct drm_device *drm);
299 int tegra_drm_fb_init(struct drm_device *drm);
300 void tegra_drm_fb_exit(struct drm_device *drm);
301 #ifdef CONFIG_DRM_TEGRA_FBDEV
302 void tegra_fbdev_restore_mode(struct tegra_fbdev *fbdev);
303 void tegra_fb_output_poll_changed(struct drm_device *drm);
304 #endif
305
306 extern struct platform_driver tegra_dc_driver;
307 extern struct platform_driver tegra_dsi_driver;
308 extern struct platform_driver tegra_sor_driver;
309 extern struct platform_driver tegra_hdmi_driver;
310 extern struct platform_driver tegra_dpaux_driver;
311 extern struct platform_driver tegra_gr2d_driver;
312 extern struct platform_driver tegra_gr3d_driver;
313
314 #endif /* HOST1X_DRM_H */