]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/gpu/drm/tegra/drm.h
drm/tegra: Implement VBLANK support
[karo-tx-linux.git] / drivers / gpu / drm / tegra / drm.h
1 /*
2  * Copyright (C) 2012 Avionic Design GmbH
3  * Copyright (C) 2012 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 TEGRA_DRM_H
11 #define TEGRA_DRM_H 1
12
13 #include <drm/drmP.h>
14 #include <drm/drm_crtc_helper.h>
15 #include <drm/drm_edid.h>
16 #include <drm/drm_fb_helper.h>
17 #include <drm/drm_gem_cma_helper.h>
18 #include <drm/drm_fb_cma_helper.h>
19 #include <drm/drm_fixed.h>
20
21 struct host1x {
22         struct drm_device *drm;
23         struct device *dev;
24         void __iomem *regs;
25         struct clk *clk;
26         int syncpt;
27         int irq;
28
29         struct mutex drm_clients_lock;
30         struct list_head drm_clients;
31         struct list_head drm_active;
32
33         struct mutex clients_lock;
34         struct list_head clients;
35
36         struct drm_fbdev_cma *fbdev;
37 };
38
39 struct host1x_client;
40
41 struct host1x_client_ops {
42         int (*drm_init)(struct host1x_client *client, struct drm_device *drm);
43         int (*drm_exit)(struct host1x_client *client);
44 };
45
46 struct host1x_client {
47         struct host1x *host1x;
48         struct device *dev;
49
50         const struct host1x_client_ops *ops;
51
52         struct list_head list;
53 };
54
55 extern int host1x_drm_init(struct host1x *host1x, struct drm_device *drm);
56 extern int host1x_drm_exit(struct host1x *host1x);
57
58 extern int host1x_register_client(struct host1x *host1x,
59                                   struct host1x_client *client);
60 extern int host1x_unregister_client(struct host1x *host1x,
61                                     struct host1x_client *client);
62
63 struct tegra_output;
64
65 struct tegra_dc {
66         struct host1x_client client;
67         spinlock_t lock;
68
69         struct host1x *host1x;
70         struct device *dev;
71
72         struct drm_crtc base;
73         int pipe;
74
75         struct clk *clk;
76
77         void __iomem *regs;
78         int irq;
79
80         struct tegra_output *rgb;
81
82         struct list_head list;
83
84         struct drm_info_list *debugfs_files;
85         struct drm_minor *minor;
86         struct dentry *debugfs;
87 };
88
89 static inline struct tegra_dc *host1x_client_to_dc(struct host1x_client *client)
90 {
91         return container_of(client, struct tegra_dc, client);
92 }
93
94 static inline struct tegra_dc *to_tegra_dc(struct drm_crtc *crtc)
95 {
96         return container_of(crtc, struct tegra_dc, base);
97 }
98
99 static inline void tegra_dc_writel(struct tegra_dc *dc, unsigned long value,
100                                    unsigned long reg)
101 {
102         writel(value, dc->regs + (reg << 2));
103 }
104
105 static inline unsigned long tegra_dc_readl(struct tegra_dc *dc,
106                                            unsigned long reg)
107 {
108         return readl(dc->regs + (reg << 2));
109 }
110
111 struct tegra_dc_window {
112         struct {
113                 unsigned int x;
114                 unsigned int y;
115                 unsigned int w;
116                 unsigned int h;
117         } src;
118         struct {
119                 unsigned int x;
120                 unsigned int y;
121                 unsigned int w;
122                 unsigned int h;
123         } dst;
124         unsigned int bits_per_pixel;
125         unsigned int format;
126         unsigned int stride[2];
127         unsigned long base[3];
128 };
129
130 /* from dc.c */
131 extern unsigned int tegra_dc_format(uint32_t format);
132 extern int tegra_dc_setup_window(struct tegra_dc *dc, unsigned int index,
133                                  const struct tegra_dc_window *window);
134 extern void tegra_dc_enable_vblank(struct tegra_dc *dc);
135 extern void tegra_dc_disable_vblank(struct tegra_dc *dc);
136
137 struct tegra_output_ops {
138         int (*enable)(struct tegra_output *output);
139         int (*disable)(struct tegra_output *output);
140         int (*setup_clock)(struct tegra_output *output, struct clk *clk,
141                            unsigned long pclk);
142         int (*check_mode)(struct tegra_output *output,
143                           struct drm_display_mode *mode,
144                           enum drm_mode_status *status);
145 };
146
147 enum tegra_output_type {
148         TEGRA_OUTPUT_RGB,
149         TEGRA_OUTPUT_HDMI,
150 };
151
152 struct tegra_output {
153         struct device_node *of_node;
154         struct device *dev;
155
156         const struct tegra_output_ops *ops;
157         enum tegra_output_type type;
158
159         struct i2c_adapter *ddc;
160         const struct edid *edid;
161         unsigned int hpd_irq;
162         int hpd_gpio;
163
164         struct drm_encoder encoder;
165         struct drm_connector connector;
166 };
167
168 static inline struct tegra_output *encoder_to_output(struct drm_encoder *e)
169 {
170         return container_of(e, struct tegra_output, encoder);
171 }
172
173 static inline struct tegra_output *connector_to_output(struct drm_connector *c)
174 {
175         return container_of(c, struct tegra_output, connector);
176 }
177
178 static inline int tegra_output_enable(struct tegra_output *output)
179 {
180         if (output && output->ops && output->ops->enable)
181                 return output->ops->enable(output);
182
183         return output ? -ENOSYS : -EINVAL;
184 }
185
186 static inline int tegra_output_disable(struct tegra_output *output)
187 {
188         if (output && output->ops && output->ops->disable)
189                 return output->ops->disable(output);
190
191         return output ? -ENOSYS : -EINVAL;
192 }
193
194 static inline int tegra_output_setup_clock(struct tegra_output *output,
195                                            struct clk *clk, unsigned long pclk)
196 {
197         if (output && output->ops && output->ops->setup_clock)
198                 return output->ops->setup_clock(output, clk, pclk);
199
200         return output ? -ENOSYS : -EINVAL;
201 }
202
203 static inline int tegra_output_check_mode(struct tegra_output *output,
204                                           struct drm_display_mode *mode,
205                                           enum drm_mode_status *status)
206 {
207         if (output && output->ops && output->ops->check_mode)
208                 return output->ops->check_mode(output, mode, status);
209
210         return output ? -ENOSYS : -EINVAL;
211 }
212
213 /* from rgb.c */
214 extern int tegra_dc_rgb_probe(struct tegra_dc *dc);
215 extern int tegra_dc_rgb_init(struct drm_device *drm, struct tegra_dc *dc);
216 extern int tegra_dc_rgb_exit(struct tegra_dc *dc);
217
218 /* from output.c */
219 extern int tegra_output_parse_dt(struct tegra_output *output);
220 extern int tegra_output_init(struct drm_device *drm, struct tegra_output *output);
221 extern int tegra_output_exit(struct tegra_output *output);
222
223 /* from fb.c */
224 extern int tegra_drm_fb_init(struct drm_device *drm);
225 extern void tegra_drm_fb_exit(struct drm_device *drm);
226
227 extern struct platform_driver tegra_host1x_driver;
228 extern struct platform_driver tegra_hdmi_driver;
229 extern struct platform_driver tegra_dc_driver;
230 extern struct drm_driver tegra_drm_driver;
231
232 #endif /* TEGRA_DRM_H */