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.
11 #define HOST1X_DRM_H 1
13 #include <uapi/drm/tegra_drm.h>
14 #include <linux/host1x.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>
23 struct drm_framebuffer base;
24 struct tegra_bo **planes;
25 unsigned int num_planes;
29 struct drm_fb_helper base;
34 struct drm_device *drm;
36 struct mutex clients_lock;
37 struct list_head clients;
39 struct tegra_fbdev *fbdev;
42 struct tegra_drm_client;
44 struct tegra_drm_context {
45 struct tegra_drm_client *client;
46 struct host1x_channel *channel;
47 struct list_head list;
50 struct tegra_drm_client_ops {
51 int (*open_channel)(struct tegra_drm_client *client,
52 struct tegra_drm_context *context);
53 void (*close_channel)(struct tegra_drm_context *context);
54 int (*is_addr_reg)(struct device *dev, u32 class, u32 offset);
55 int (*submit)(struct tegra_drm_context *context,
56 struct drm_tegra_submit *args, struct drm_device *drm,
57 struct drm_file *file);
60 int tegra_drm_submit(struct tegra_drm_context *context,
61 struct drm_tegra_submit *args, struct drm_device *drm,
62 struct drm_file *file);
64 struct tegra_drm_client {
65 struct host1x_client base;
66 struct list_head list;
68 const struct tegra_drm_client_ops *ops;
71 static inline struct tegra_drm_client *
72 host1x_to_drm_client(struct host1x_client *client)
74 return container_of(client, struct tegra_drm_client, base);
77 extern int tegra_drm_register_client(struct tegra_drm *tegra,
78 struct tegra_drm_client *client);
79 extern int tegra_drm_unregister_client(struct tegra_drm *tegra,
80 struct tegra_drm_client *client);
82 extern int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm);
83 extern int tegra_drm_exit(struct tegra_drm *tegra);
88 struct host1x_client client;
99 struct tegra_output *rgb;
101 struct list_head list;
103 struct drm_info_list *debugfs_files;
104 struct drm_minor *minor;
105 struct dentry *debugfs;
107 /* page-flip handling */
108 struct drm_pending_vblank_event *event;
111 static inline struct tegra_dc *
112 host1x_client_to_dc(struct host1x_client *client)
114 return container_of(client, struct tegra_dc, client);
117 static inline struct tegra_dc *to_tegra_dc(struct drm_crtc *crtc)
119 return crtc ? container_of(crtc, struct tegra_dc, base) : NULL;
122 static inline void tegra_dc_writel(struct tegra_dc *dc, unsigned long value,
125 writel(value, dc->regs + (reg << 2));
128 static inline unsigned long tegra_dc_readl(struct tegra_dc *dc,
131 return readl(dc->regs + (reg << 2));
134 struct tegra_dc_window {
147 unsigned int bits_per_pixel;
149 unsigned int stride[2];
150 unsigned long base[3];
156 extern unsigned int tegra_dc_format(uint32_t format);
157 extern int tegra_dc_setup_window(struct tegra_dc *dc, unsigned int index,
158 const struct tegra_dc_window *window);
159 extern void tegra_dc_enable_vblank(struct tegra_dc *dc);
160 extern void tegra_dc_disable_vblank(struct tegra_dc *dc);
161 extern void tegra_dc_cancel_page_flip(struct drm_crtc *crtc,
162 struct drm_file *file);
164 struct tegra_output_ops {
165 int (*enable)(struct tegra_output *output);
166 int (*disable)(struct tegra_output *output);
167 int (*setup_clock)(struct tegra_output *output, struct clk *clk,
169 int (*check_mode)(struct tegra_output *output,
170 struct drm_display_mode *mode,
171 enum drm_mode_status *status);
174 enum tegra_output_type {
179 struct tegra_output {
180 struct device_node *of_node;
183 const struct tegra_output_ops *ops;
184 enum tegra_output_type type;
186 struct i2c_adapter *ddc;
187 const struct edid *edid;
188 unsigned int hpd_irq;
191 struct drm_encoder encoder;
192 struct drm_connector connector;
195 static inline struct tegra_output *encoder_to_output(struct drm_encoder *e)
197 return container_of(e, struct tegra_output, encoder);
200 static inline struct tegra_output *connector_to_output(struct drm_connector *c)
202 return container_of(c, struct tegra_output, connector);
205 static inline int tegra_output_enable(struct tegra_output *output)
207 if (output && output->ops && output->ops->enable)
208 return output->ops->enable(output);
210 return output ? -ENOSYS : -EINVAL;
213 static inline int tegra_output_disable(struct tegra_output *output)
215 if (output && output->ops && output->ops->disable)
216 return output->ops->disable(output);
218 return output ? -ENOSYS : -EINVAL;
221 static inline int tegra_output_setup_clock(struct tegra_output *output,
222 struct clk *clk, unsigned long pclk)
224 if (output && output->ops && output->ops->setup_clock)
225 return output->ops->setup_clock(output, clk, pclk);
227 return output ? -ENOSYS : -EINVAL;
230 static inline int tegra_output_check_mode(struct tegra_output *output,
231 struct drm_display_mode *mode,
232 enum drm_mode_status *status)
234 if (output && output->ops && output->ops->check_mode)
235 return output->ops->check_mode(output, mode, status);
237 return output ? -ENOSYS : -EINVAL;
241 int drm_host1x_init(struct drm_driver *driver, struct host1x_device *device);
242 void drm_host1x_exit(struct drm_driver *driver, struct host1x_device *device);
245 extern int tegra_dc_rgb_probe(struct tegra_dc *dc);
246 extern int tegra_dc_rgb_remove(struct tegra_dc *dc);
247 extern int tegra_dc_rgb_init(struct drm_device *drm, struct tegra_dc *dc);
248 extern int tegra_dc_rgb_exit(struct tegra_dc *dc);
251 extern int tegra_output_probe(struct tegra_output *output);
252 extern int tegra_output_remove(struct tegra_output *output);
253 extern int tegra_output_init(struct drm_device *drm, struct tegra_output *output);
254 extern int tegra_output_exit(struct tegra_output *output);
257 struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer,
259 bool tegra_fb_is_bottom_up(struct drm_framebuffer *framebuffer);
260 bool tegra_fb_is_tiled(struct drm_framebuffer *framebuffer);
261 extern int tegra_drm_fb_init(struct drm_device *drm);
262 extern void tegra_drm_fb_exit(struct drm_device *drm);
263 extern void tegra_fbdev_restore_mode(struct tegra_fbdev *fbdev);
265 extern struct platform_driver tegra_dc_driver;
266 extern struct platform_driver tegra_hdmi_driver;
267 extern struct platform_driver tegra_gr2d_driver;
268 extern struct platform_driver tegra_gr3d_driver;
270 #endif /* HOST1X_DRM_H */