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>
27 struct drm_framebuffer base;
28 struct tegra_bo **planes;
29 unsigned int num_planes;
32 #ifdef CONFIG_DRM_TEGRA_FBDEV
34 struct drm_fb_helper base;
40 struct drm_device *drm;
42 struct mutex clients_lock;
43 struct list_head clients;
45 #ifdef CONFIG_DRM_TEGRA_FBDEV
46 struct tegra_fbdev *fbdev;
49 unsigned int pitch_align;
52 struct tegra_drm_client;
54 struct tegra_drm_context {
55 struct tegra_drm_client *client;
56 struct host1x_channel *channel;
57 struct list_head list;
60 struct tegra_drm_client_ops {
61 int (*open_channel)(struct tegra_drm_client *client,
62 struct tegra_drm_context *context);
63 void (*close_channel)(struct tegra_drm_context *context);
64 int (*is_addr_reg)(struct device *dev, u32 class, u32 offset);
65 int (*submit)(struct tegra_drm_context *context,
66 struct drm_tegra_submit *args, struct drm_device *drm,
67 struct drm_file *file);
70 int tegra_drm_submit(struct tegra_drm_context *context,
71 struct drm_tegra_submit *args, struct drm_device *drm,
72 struct drm_file *file);
74 struct tegra_drm_client {
75 struct host1x_client base;
76 struct list_head list;
78 const struct tegra_drm_client_ops *ops;
81 static inline struct tegra_drm_client *
82 host1x_to_drm_client(struct host1x_client *client)
84 return container_of(client, struct tegra_drm_client, base);
87 int tegra_drm_register_client(struct tegra_drm *tegra,
88 struct tegra_drm_client *client);
89 int tegra_drm_unregister_client(struct tegra_drm *tegra,
90 struct tegra_drm_client *client);
92 int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm);
93 int tegra_drm_exit(struct tegra_drm *tegra);
95 struct tegra_dc_soc_info;
99 struct host1x_client client;
103 struct drm_crtc base;
107 struct reset_control *rst;
111 struct tegra_output *rgb;
113 struct list_head list;
115 struct drm_info_list *debugfs_files;
116 struct drm_minor *minor;
117 struct dentry *debugfs;
119 /* page-flip handling */
120 struct drm_pending_vblank_event *event;
122 const struct tegra_dc_soc_info *soc;
125 static inline struct tegra_dc *
126 host1x_client_to_dc(struct host1x_client *client)
128 return container_of(client, struct tegra_dc, client);
131 static inline struct tegra_dc *to_tegra_dc(struct drm_crtc *crtc)
133 return crtc ? container_of(crtc, struct tegra_dc, base) : NULL;
136 static inline void tegra_dc_writel(struct tegra_dc *dc, unsigned long value,
139 writel(value, dc->regs + (reg << 2));
142 static inline unsigned long tegra_dc_readl(struct tegra_dc *dc,
145 return readl(dc->regs + (reg << 2));
148 struct tegra_dc_window {
161 unsigned int bits_per_pixel;
164 unsigned int stride[2];
165 unsigned long base[3];
168 struct tegra_bo_tiling tiling;
172 void tegra_dc_enable_vblank(struct tegra_dc *dc);
173 void tegra_dc_disable_vblank(struct tegra_dc *dc);
174 void tegra_dc_cancel_page_flip(struct drm_crtc *crtc, struct drm_file *file);
176 struct tegra_output_ops {
177 int (*enable)(struct tegra_output *output);
178 int (*disable)(struct tegra_output *output);
179 int (*setup_clock)(struct tegra_output *output, struct clk *clk,
180 unsigned long pclk, unsigned int *div);
181 int (*check_mode)(struct tegra_output *output,
182 struct drm_display_mode *mode,
183 enum drm_mode_status *status);
184 enum drm_connector_status (*detect)(struct tegra_output *output);
187 enum tegra_output_type {
194 struct tegra_output {
195 struct device_node *of_node;
198 const struct tegra_output_ops *ops;
199 enum tegra_output_type type;
201 struct drm_panel *panel;
202 struct i2c_adapter *ddc;
203 const struct edid *edid;
204 unsigned int hpd_irq;
207 struct drm_encoder encoder;
208 struct drm_connector connector;
211 static inline struct tegra_output *encoder_to_output(struct drm_encoder *e)
213 return container_of(e, struct tegra_output, encoder);
216 static inline struct tegra_output *connector_to_output(struct drm_connector *c)
218 return container_of(c, struct tegra_output, connector);
221 static inline int tegra_output_enable(struct tegra_output *output)
223 if (output && output->ops && output->ops->enable)
224 return output->ops->enable(output);
226 return output ? -ENOSYS : -EINVAL;
229 static inline int tegra_output_disable(struct tegra_output *output)
231 if (output && output->ops && output->ops->disable)
232 return output->ops->disable(output);
234 return output ? -ENOSYS : -EINVAL;
237 static inline int tegra_output_setup_clock(struct tegra_output *output,
238 struct clk *clk, unsigned long pclk,
241 if (output && output->ops && output->ops->setup_clock)
242 return output->ops->setup_clock(output, clk, pclk, div);
244 return output ? -ENOSYS : -EINVAL;
247 static inline int tegra_output_check_mode(struct tegra_output *output,
248 struct drm_display_mode *mode,
249 enum drm_mode_status *status)
251 if (output && output->ops && output->ops->check_mode)
252 return output->ops->check_mode(output, mode, status);
254 return output ? -ENOSYS : -EINVAL;
258 int tegra_dc_rgb_probe(struct tegra_dc *dc);
259 int tegra_dc_rgb_remove(struct tegra_dc *dc);
260 int tegra_dc_rgb_init(struct drm_device *drm, struct tegra_dc *dc);
261 int tegra_dc_rgb_exit(struct tegra_dc *dc);
264 int tegra_output_probe(struct tegra_output *output);
265 int tegra_output_remove(struct tegra_output *output);
266 int tegra_output_init(struct drm_device *drm, struct tegra_output *output);
267 int tegra_output_exit(struct tegra_output *output);
273 struct tegra_dpaux *tegra_dpaux_find_by_of_node(struct device_node *np);
274 enum drm_connector_status tegra_dpaux_detect(struct tegra_dpaux *dpaux);
275 int tegra_dpaux_attach(struct tegra_dpaux *dpaux, struct tegra_output *output);
276 int tegra_dpaux_detach(struct tegra_dpaux *dpaux);
277 int tegra_dpaux_enable(struct tegra_dpaux *dpaux);
278 int tegra_dpaux_disable(struct tegra_dpaux *dpaux);
279 int tegra_dpaux_prepare(struct tegra_dpaux *dpaux, u8 encoding);
280 int tegra_dpaux_train(struct tegra_dpaux *dpaux, struct drm_dp_link *link,
284 struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer,
286 bool tegra_fb_is_bottom_up(struct drm_framebuffer *framebuffer);
287 int tegra_fb_get_tiling(struct drm_framebuffer *framebuffer,
288 struct tegra_bo_tiling *tiling);
289 int tegra_drm_fb_prepare(struct drm_device *drm);
290 int tegra_drm_fb_init(struct drm_device *drm);
291 void tegra_drm_fb_exit(struct drm_device *drm);
292 #ifdef CONFIG_DRM_TEGRA_FBDEV
293 void tegra_fbdev_restore_mode(struct tegra_fbdev *fbdev);
296 extern struct platform_driver tegra_dc_driver;
297 extern struct platform_driver tegra_dsi_driver;
298 extern struct platform_driver tegra_sor_driver;
299 extern struct platform_driver tegra_hdmi_driver;
300 extern struct platform_driver tegra_dpaux_driver;
301 extern struct platform_driver tegra_gr2d_driver;
302 extern struct platform_driver tegra_gr3d_driver;
304 #endif /* HOST1X_DRM_H */