]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/gpu/host1x/drm/drm.h
gpu: host1x: Make host1x header file public
[karo-tx-linux.git] / drivers / gpu / host1x / drm / 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 struct tegra_fb {
23         struct drm_framebuffer base;
24         struct tegra_bo **planes;
25         unsigned int num_planes;
26 };
27
28 struct tegra_fbdev {
29         struct drm_fb_helper base;
30         struct tegra_fb *fb;
31 };
32
33 struct tegra_drm {
34         struct drm_device *drm;
35         struct device *dev;
36
37         struct mutex subdevs_lock;
38         struct list_head subdevs;
39         struct list_head active;
40
41         struct mutex clients_lock;
42         struct list_head clients;
43
44         struct tegra_fbdev *fbdev;
45 };
46
47 struct host1x_client;
48
49 struct tegra_drm_context {
50         struct host1x_client *client;
51         struct host1x_channel *channel;
52         struct list_head list;
53 };
54
55 struct host1x_client_ops {
56         int (*drm_init)(struct host1x_client *client, struct drm_device *drm);
57         int (*drm_exit)(struct host1x_client *client);
58         int (*open_channel)(struct host1x_client *client,
59                             struct tegra_drm_context *context);
60         void (*close_channel)(struct tegra_drm_context *context);
61         int (*submit)(struct tegra_drm_context *context,
62                       struct drm_tegra_submit *args, struct drm_device *drm,
63                       struct drm_file *file);
64 };
65
66 struct host1x_client {
67         struct tegra_drm *tegra;
68         struct device *dev;
69
70         const struct host1x_client_ops *ops;
71
72         enum host1x_class class;
73         struct host1x_channel *channel;
74
75         struct host1x_syncpt **syncpts;
76         unsigned int num_syncpts;
77
78         struct list_head list;
79 };
80
81 extern int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm);
82 extern int tegra_drm_exit(struct tegra_drm *tegra);
83
84 extern int host1x_register_client(struct tegra_drm *tegra,
85                                   struct host1x_client *client);
86 extern int host1x_unregister_client(struct tegra_drm *tegra,
87                                     struct host1x_client *client);
88
89 struct tegra_output;
90
91 struct tegra_dc {
92         struct host1x_client client;
93         struct device *dev;
94         spinlock_t lock;
95
96         struct drm_crtc base;
97         int pipe;
98
99         struct clk *clk;
100         void __iomem *regs;
101         int irq;
102
103         struct tegra_output *rgb;
104
105         struct list_head list;
106
107         struct drm_info_list *debugfs_files;
108         struct drm_minor *minor;
109         struct dentry *debugfs;
110
111         /* page-flip handling */
112         struct drm_pending_vblank_event *event;
113 };
114
115 static inline struct tegra_dc *host1x_client_to_dc(struct host1x_client *client)
116 {
117         return container_of(client, struct tegra_dc, client);
118 }
119
120 static inline struct tegra_dc *to_tegra_dc(struct drm_crtc *crtc)
121 {
122         return container_of(crtc, struct tegra_dc, base);
123 }
124
125 static inline void tegra_dc_writel(struct tegra_dc *dc, unsigned long value,
126                                    unsigned long reg)
127 {
128         writel(value, dc->regs + (reg << 2));
129 }
130
131 static inline unsigned long tegra_dc_readl(struct tegra_dc *dc,
132                                            unsigned long reg)
133 {
134         return readl(dc->regs + (reg << 2));
135 }
136
137 struct tegra_dc_window {
138         struct {
139                 unsigned int x;
140                 unsigned int y;
141                 unsigned int w;
142                 unsigned int h;
143         } src;
144         struct {
145                 unsigned int x;
146                 unsigned int y;
147                 unsigned int w;
148                 unsigned int h;
149         } dst;
150         unsigned int bits_per_pixel;
151         unsigned int format;
152         unsigned int stride[2];
153         unsigned long base[3];
154 };
155
156 /* from dc.c */
157 extern unsigned int tegra_dc_format(uint32_t format);
158 extern int tegra_dc_setup_window(struct tegra_dc *dc, unsigned int index,
159                                  const struct tegra_dc_window *window);
160 extern void tegra_dc_enable_vblank(struct tegra_dc *dc);
161 extern void tegra_dc_disable_vblank(struct tegra_dc *dc);
162 extern void tegra_dc_cancel_page_flip(struct drm_crtc *crtc,
163                                       struct drm_file *file);
164
165 struct tegra_output_ops {
166         int (*enable)(struct tegra_output *output);
167         int (*disable)(struct tegra_output *output);
168         int (*setup_clock)(struct tegra_output *output, struct clk *clk,
169                            unsigned long pclk);
170         int (*check_mode)(struct tegra_output *output,
171                           struct drm_display_mode *mode,
172                           enum drm_mode_status *status);
173 };
174
175 enum tegra_output_type {
176         TEGRA_OUTPUT_RGB,
177         TEGRA_OUTPUT_HDMI,
178 };
179
180 struct tegra_output {
181         struct device_node *of_node;
182         struct device *dev;
183
184         const struct tegra_output_ops *ops;
185         enum tegra_output_type type;
186
187         struct i2c_adapter *ddc;
188         const struct edid *edid;
189         unsigned int hpd_irq;
190         int hpd_gpio;
191
192         struct drm_encoder encoder;
193         struct drm_connector connector;
194 };
195
196 static inline struct tegra_output *encoder_to_output(struct drm_encoder *e)
197 {
198         return container_of(e, struct tegra_output, encoder);
199 }
200
201 static inline struct tegra_output *connector_to_output(struct drm_connector *c)
202 {
203         return container_of(c, struct tegra_output, connector);
204 }
205
206 static inline int tegra_output_enable(struct tegra_output *output)
207 {
208         if (output && output->ops && output->ops->enable)
209                 return output->ops->enable(output);
210
211         return output ? -ENOSYS : -EINVAL;
212 }
213
214 static inline int tegra_output_disable(struct tegra_output *output)
215 {
216         if (output && output->ops && output->ops->disable)
217                 return output->ops->disable(output);
218
219         return output ? -ENOSYS : -EINVAL;
220 }
221
222 static inline int tegra_output_setup_clock(struct tegra_output *output,
223                                            struct clk *clk, unsigned long pclk)
224 {
225         if (output && output->ops && output->ops->setup_clock)
226                 return output->ops->setup_clock(output, clk, pclk);
227
228         return output ? -ENOSYS : -EINVAL;
229 }
230
231 static inline int tegra_output_check_mode(struct tegra_output *output,
232                                           struct drm_display_mode *mode,
233                                           enum drm_mode_status *status)
234 {
235         if (output && output->ops && output->ops->check_mode)
236                 return output->ops->check_mode(output, mode, status);
237
238         return output ? -ENOSYS : -EINVAL;
239 }
240
241 /* from rgb.c */
242 extern int tegra_dc_rgb_probe(struct tegra_dc *dc);
243 extern int tegra_dc_rgb_init(struct drm_device *drm, struct tegra_dc *dc);
244 extern int tegra_dc_rgb_exit(struct tegra_dc *dc);
245
246 /* from output.c */
247 extern int tegra_output_parse_dt(struct tegra_output *output);
248 extern int tegra_output_init(struct drm_device *drm, struct tegra_output *output);
249 extern int tegra_output_exit(struct tegra_output *output);
250
251 /* from fb.c */
252 struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer,
253                                     unsigned int index);
254 extern int tegra_drm_fb_init(struct drm_device *drm);
255 extern void tegra_drm_fb_exit(struct drm_device *drm);
256 extern void tegra_fbdev_restore_mode(struct tegra_fbdev *fbdev);
257
258 extern struct drm_driver tegra_drm_driver;
259
260 #endif /* HOST1X_DRM_H */