PM / sleep: Asynchronous threads for suspend_noirq
[linux/fpc-iii.git] / drivers / gpu / drm / tegra / drm.h
blobbf1cac7658f8d20333ce0cefbac8383e62f98c37
1 /*
2 * Copyright (C) 2012 Avionic Design GmbH
3 * Copyright (C) 2012-2013 NVIDIA CORPORATION. All rights reserved.
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 */
10 #ifndef HOST1X_DRM_H
11 #define HOST1X_DRM_H 1
13 #include <uapi/drm/tegra_drm.h>
14 #include <linux/host1x.h>
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>
22 struct reset_control;
24 struct tegra_fb {
25 struct drm_framebuffer base;
26 struct tegra_bo **planes;
27 unsigned int num_planes;
30 #ifdef CONFIG_DRM_TEGRA_FBDEV
31 struct tegra_fbdev {
32 struct drm_fb_helper base;
33 struct tegra_fb *fb;
35 #endif
37 struct tegra_drm {
38 struct drm_device *drm;
40 struct mutex clients_lock;
41 struct list_head clients;
43 #ifdef CONFIG_DRM_TEGRA_FBDEV
44 struct tegra_fbdev *fbdev;
45 #endif
48 struct tegra_drm_client;
50 struct tegra_drm_context {
51 struct tegra_drm_client *client;
52 struct host1x_channel *channel;
53 struct list_head list;
56 struct tegra_drm_client_ops {
57 int (*open_channel)(struct tegra_drm_client *client,
58 struct tegra_drm_context *context);
59 void (*close_channel)(struct tegra_drm_context *context);
60 int (*is_addr_reg)(struct device *dev, u32 class, u32 offset);
61 int (*submit)(struct tegra_drm_context *context,
62 struct drm_tegra_submit *args, struct drm_device *drm,
63 struct drm_file *file);
66 int tegra_drm_submit(struct tegra_drm_context *context,
67 struct drm_tegra_submit *args, struct drm_device *drm,
68 struct drm_file *file);
70 struct tegra_drm_client {
71 struct host1x_client base;
72 struct list_head list;
74 const struct tegra_drm_client_ops *ops;
77 static inline struct tegra_drm_client *
78 host1x_to_drm_client(struct host1x_client *client)
80 return container_of(client, struct tegra_drm_client, base);
83 extern int tegra_drm_register_client(struct tegra_drm *tegra,
84 struct tegra_drm_client *client);
85 extern int tegra_drm_unregister_client(struct tegra_drm *tegra,
86 struct tegra_drm_client *client);
88 extern int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm);
89 extern int tegra_drm_exit(struct tegra_drm *tegra);
91 struct tegra_dc_soc_info;
92 struct tegra_output;
94 struct tegra_dc {
95 struct host1x_client client;
96 struct device *dev;
97 spinlock_t lock;
99 struct drm_crtc base;
100 int pipe;
102 struct clk *clk;
103 struct reset_control *rst;
104 void __iomem *regs;
105 int irq;
107 struct tegra_output *rgb;
109 struct list_head list;
111 struct drm_info_list *debugfs_files;
112 struct drm_minor *minor;
113 struct dentry *debugfs;
115 /* page-flip handling */
116 struct drm_pending_vblank_event *event;
118 const struct tegra_dc_soc_info *soc;
121 static inline struct tegra_dc *
122 host1x_client_to_dc(struct host1x_client *client)
124 return container_of(client, struct tegra_dc, client);
127 static inline struct tegra_dc *to_tegra_dc(struct drm_crtc *crtc)
129 return crtc ? container_of(crtc, struct tegra_dc, base) : NULL;
132 static inline void tegra_dc_writel(struct tegra_dc *dc, unsigned long value,
133 unsigned long reg)
135 writel(value, dc->regs + (reg << 2));
138 static inline unsigned long tegra_dc_readl(struct tegra_dc *dc,
139 unsigned long reg)
141 return readl(dc->regs + (reg << 2));
144 struct tegra_dc_window {
145 struct {
146 unsigned int x;
147 unsigned int y;
148 unsigned int w;
149 unsigned int h;
150 } src;
151 struct {
152 unsigned int x;
153 unsigned int y;
154 unsigned int w;
155 unsigned int h;
156 } dst;
157 unsigned int bits_per_pixel;
158 unsigned int format;
159 unsigned int stride[2];
160 unsigned long base[3];
161 bool bottom_up;
162 bool tiled;
165 /* from dc.c */
166 extern unsigned int tegra_dc_format(uint32_t format);
167 extern int tegra_dc_setup_window(struct tegra_dc *dc, unsigned int index,
168 const struct tegra_dc_window *window);
169 extern void tegra_dc_enable_vblank(struct tegra_dc *dc);
170 extern void tegra_dc_disable_vblank(struct tegra_dc *dc);
171 extern void tegra_dc_cancel_page_flip(struct drm_crtc *crtc,
172 struct drm_file *file);
174 struct tegra_output_ops {
175 int (*enable)(struct tegra_output *output);
176 int (*disable)(struct tegra_output *output);
177 int (*setup_clock)(struct tegra_output *output, struct clk *clk,
178 unsigned long pclk);
179 int (*check_mode)(struct tegra_output *output,
180 struct drm_display_mode *mode,
181 enum drm_mode_status *status);
184 enum tegra_output_type {
185 TEGRA_OUTPUT_RGB,
186 TEGRA_OUTPUT_HDMI,
187 TEGRA_OUTPUT_DSI,
190 struct tegra_output {
191 struct device_node *of_node;
192 struct device *dev;
194 const struct tegra_output_ops *ops;
195 enum tegra_output_type type;
197 struct drm_panel *panel;
198 struct i2c_adapter *ddc;
199 const struct edid *edid;
200 unsigned int hpd_irq;
201 int hpd_gpio;
203 struct drm_encoder encoder;
204 struct drm_connector connector;
207 static inline struct tegra_output *encoder_to_output(struct drm_encoder *e)
209 return container_of(e, struct tegra_output, encoder);
212 static inline struct tegra_output *connector_to_output(struct drm_connector *c)
214 return container_of(c, struct tegra_output, connector);
217 static inline int tegra_output_enable(struct tegra_output *output)
219 if (output && output->ops && output->ops->enable)
220 return output->ops->enable(output);
222 return output ? -ENOSYS : -EINVAL;
225 static inline int tegra_output_disable(struct tegra_output *output)
227 if (output && output->ops && output->ops->disable)
228 return output->ops->disable(output);
230 return output ? -ENOSYS : -EINVAL;
233 static inline int tegra_output_setup_clock(struct tegra_output *output,
234 struct clk *clk, unsigned long pclk)
236 if (output && output->ops && output->ops->setup_clock)
237 return output->ops->setup_clock(output, clk, pclk);
239 return output ? -ENOSYS : -EINVAL;
242 static inline int tegra_output_check_mode(struct tegra_output *output,
243 struct drm_display_mode *mode,
244 enum drm_mode_status *status)
246 if (output && output->ops && output->ops->check_mode)
247 return output->ops->check_mode(output, mode, status);
249 return output ? -ENOSYS : -EINVAL;
252 /* from bus.c */
253 int drm_host1x_init(struct drm_driver *driver, struct host1x_device *device);
254 void drm_host1x_exit(struct drm_driver *driver, struct host1x_device *device);
256 /* from rgb.c */
257 extern int tegra_dc_rgb_probe(struct tegra_dc *dc);
258 extern int tegra_dc_rgb_remove(struct tegra_dc *dc);
259 extern int tegra_dc_rgb_init(struct drm_device *drm, struct tegra_dc *dc);
260 extern int tegra_dc_rgb_exit(struct tegra_dc *dc);
262 /* from output.c */
263 extern int tegra_output_probe(struct tegra_output *output);
264 extern int tegra_output_remove(struct tegra_output *output);
265 extern int tegra_output_init(struct drm_device *drm, struct tegra_output *output);
266 extern int tegra_output_exit(struct tegra_output *output);
268 /* from fb.c */
269 struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer,
270 unsigned int index);
271 bool tegra_fb_is_bottom_up(struct drm_framebuffer *framebuffer);
272 bool tegra_fb_is_tiled(struct drm_framebuffer *framebuffer);
273 extern int tegra_drm_fb_init(struct drm_device *drm);
274 extern void tegra_drm_fb_exit(struct drm_device *drm);
275 #ifdef CONFIG_DRM_TEGRA_FBDEV
276 extern void tegra_fbdev_restore_mode(struct tegra_fbdev *fbdev);
277 #endif
279 extern struct platform_driver tegra_dc_driver;
280 extern struct platform_driver tegra_dsi_driver;
281 extern struct platform_driver tegra_hdmi_driver;
282 extern struct platform_driver tegra_gr2d_driver;
283 extern struct platform_driver tegra_gr3d_driver;
285 #endif /* HOST1X_DRM_H */