]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - drivers/gpu/drm/tegra/drm.h
Merge tag 'pm+acpi-3.15-rc1-3' of git://git.kernel.org/pub/scm/linux/kernel/git/rafae...
[mirror_ubuntu-hirsute-kernel.git] / drivers / gpu / drm / tegra / drm.h
CommitLineData
d8f4a9ed
TR
1/*
2 * Copyright (C) 2012 Avionic Design GmbH
d43f81cb 3 * Copyright (C) 2012-2013 NVIDIA CORPORATION. All rights reserved.
d8f4a9ed
TR
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
4231c6b0
TB
10#ifndef HOST1X_DRM_H
11#define HOST1X_DRM_H 1
d8f4a9ed 12
e1e90644
TR
13#include <uapi/drm/tegra_drm.h>
14#include <linux/host1x.h>
15
d8f4a9ed
TR
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>
d8f4a9ed
TR
20#include <drm/drm_fixed.h>
21
ca48080a
SW
22struct reset_control;
23
de2ba664
AM
24struct tegra_fb {
25 struct drm_framebuffer base;
26 struct tegra_bo **planes;
27 unsigned int num_planes;
28};
29
60c2f709 30#ifdef CONFIG_DRM_TEGRA_FBDEV
de2ba664
AM
31struct tegra_fbdev {
32 struct drm_fb_helper base;
33 struct tegra_fb *fb;
34};
60c2f709 35#endif
de2ba664 36
386a2a71 37struct tegra_drm {
d8f4a9ed 38 struct drm_device *drm;
d8f4a9ed
TR
39
40 struct mutex clients_lock;
41 struct list_head clients;
42
60c2f709 43#ifdef CONFIG_DRM_TEGRA_FBDEV
de2ba664 44 struct tegra_fbdev *fbdev;
60c2f709 45#endif
d8f4a9ed
TR
46};
47
53fa7f72 48struct tegra_drm_client;
d8f4a9ed 49
c88c3630 50struct tegra_drm_context {
53fa7f72 51 struct tegra_drm_client *client;
d43f81cb
TB
52 struct host1x_channel *channel;
53 struct list_head list;
54};
55
53fa7f72
TR
56struct tegra_drm_client_ops {
57 int (*open_channel)(struct tegra_drm_client *client,
c88c3630
TR
58 struct tegra_drm_context *context);
59 void (*close_channel)(struct tegra_drm_context *context);
c40f0f1a 60 int (*is_addr_reg)(struct device *dev, u32 class, u32 offset);
c88c3630 61 int (*submit)(struct tegra_drm_context *context,
d43f81cb
TB
62 struct drm_tegra_submit *args, struct drm_device *drm,
63 struct drm_file *file);
64};
65
c40f0f1a
TR
66int tegra_drm_submit(struct tegra_drm_context *context,
67 struct drm_tegra_submit *args, struct drm_device *drm,
68 struct drm_file *file);
69
53fa7f72
TR
70struct tegra_drm_client {
71 struct host1x_client base;
776dc384 72 struct list_head list;
d43f81cb 73
53fa7f72 74 const struct tegra_drm_client_ops *ops;
d8f4a9ed
TR
75};
76
53fa7f72 77static inline struct tegra_drm_client *
776dc384 78host1x_to_drm_client(struct host1x_client *client)
53fa7f72
TR
79{
80 return container_of(client, struct tegra_drm_client, base);
81}
82
776dc384
TR
83extern int tegra_drm_register_client(struct tegra_drm *tegra,
84 struct tegra_drm_client *client);
85extern int tegra_drm_unregister_client(struct tegra_drm *tegra,
86 struct tegra_drm_client *client);
87
386a2a71
TR
88extern int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm);
89extern int tegra_drm_exit(struct tegra_drm *tegra);
d8f4a9ed 90
8620fc62 91struct tegra_dc_soc_info;
d8f4a9ed
TR
92struct tegra_output;
93
94struct tegra_dc {
776dc384 95 struct host1x_client client;
d8f4a9ed 96 struct device *dev;
d18d3033 97 spinlock_t lock;
d8f4a9ed
TR
98
99 struct drm_crtc base;
100 int pipe;
101
102 struct clk *clk;
ca48080a 103 struct reset_control *rst;
d8f4a9ed
TR
104 void __iomem *regs;
105 int irq;
106
107 struct tegra_output *rgb;
108
109 struct list_head list;
110
111 struct drm_info_list *debugfs_files;
112 struct drm_minor *minor;
113 struct dentry *debugfs;
3c03c46a
TR
114
115 /* page-flip handling */
116 struct drm_pending_vblank_event *event;
8620fc62
TR
117
118 const struct tegra_dc_soc_info *soc;
d8f4a9ed
TR
119};
120
53fa7f72 121static inline struct tegra_dc *
776dc384 122host1x_client_to_dc(struct host1x_client *client)
d8f4a9ed
TR
123{
124 return container_of(client, struct tegra_dc, client);
125}
126
127static inline struct tegra_dc *to_tegra_dc(struct drm_crtc *crtc)
128{
37826519 129 return crtc ? container_of(crtc, struct tegra_dc, base) : NULL;
d8f4a9ed
TR
130}
131
132static inline void tegra_dc_writel(struct tegra_dc *dc, unsigned long value,
133 unsigned long reg)
134{
135 writel(value, dc->regs + (reg << 2));
136}
137
138static inline unsigned long tegra_dc_readl(struct tegra_dc *dc,
139 unsigned long reg)
140{
141 return readl(dc->regs + (reg << 2));
142}
143
f34bc787
TR
144struct 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];
db7fbdfd 161 bool bottom_up;
773af77f 162 bool tiled;
f34bc787
TR
163};
164
165/* from dc.c */
166extern unsigned int tegra_dc_format(uint32_t format);
167extern int tegra_dc_setup_window(struct tegra_dc *dc, unsigned int index,
168 const struct tegra_dc_window *window);
6e5ff998
TR
169extern void tegra_dc_enable_vblank(struct tegra_dc *dc);
170extern void tegra_dc_disable_vblank(struct tegra_dc *dc);
3c03c46a
TR
171extern void tegra_dc_cancel_page_flip(struct drm_crtc *crtc,
172 struct drm_file *file);
f34bc787 173
d8f4a9ed
TR
174struct 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);
6b6b6042 182 enum drm_connector_status (*detect)(struct tegra_output *output);
d8f4a9ed
TR
183};
184
185enum tegra_output_type {
186 TEGRA_OUTPUT_RGB,
edec4af4 187 TEGRA_OUTPUT_HDMI,
dec72739 188 TEGRA_OUTPUT_DSI,
6b6b6042 189 TEGRA_OUTPUT_EDP,
d8f4a9ed
TR
190};
191
192struct tegra_output {
193 struct device_node *of_node;
194 struct device *dev;
195
196 const struct tegra_output_ops *ops;
197 enum tegra_output_type type;
198
9be7d864 199 struct drm_panel *panel;
d8f4a9ed
TR
200 struct i2c_adapter *ddc;
201 const struct edid *edid;
202 unsigned int hpd_irq;
203 int hpd_gpio;
204
205 struct drm_encoder encoder;
206 struct drm_connector connector;
207};
208
209static inline struct tegra_output *encoder_to_output(struct drm_encoder *e)
210{
211 return container_of(e, struct tegra_output, encoder);
212}
213
214static inline struct tegra_output *connector_to_output(struct drm_connector *c)
215{
216 return container_of(c, struct tegra_output, connector);
217}
218
219static inline int tegra_output_enable(struct tegra_output *output)
220{
221 if (output && output->ops && output->ops->enable)
222 return output->ops->enable(output);
223
224 return output ? -ENOSYS : -EINVAL;
225}
226
227static inline int tegra_output_disable(struct tegra_output *output)
228{
229 if (output && output->ops && output->ops->disable)
230 return output->ops->disable(output);
231
232 return output ? -ENOSYS : -EINVAL;
233}
234
235static inline int tegra_output_setup_clock(struct tegra_output *output,
236 struct clk *clk, unsigned long pclk)
237{
238 if (output && output->ops && output->ops->setup_clock)
239 return output->ops->setup_clock(output, clk, pclk);
240
241 return output ? -ENOSYS : -EINVAL;
242}
243
244static inline int tegra_output_check_mode(struct tegra_output *output,
245 struct drm_display_mode *mode,
246 enum drm_mode_status *status)
247{
248 if (output && output->ops && output->ops->check_mode)
249 return output->ops->check_mode(output, mode, status);
250
251 return output ? -ENOSYS : -EINVAL;
252}
253
776dc384
TR
254/* from bus.c */
255int drm_host1x_init(struct drm_driver *driver, struct host1x_device *device);
256void drm_host1x_exit(struct drm_driver *driver, struct host1x_device *device);
257
d8f4a9ed
TR
258/* from rgb.c */
259extern int tegra_dc_rgb_probe(struct tegra_dc *dc);
59d29c0e 260extern int tegra_dc_rgb_remove(struct tegra_dc *dc);
d8f4a9ed
TR
261extern int tegra_dc_rgb_init(struct drm_device *drm, struct tegra_dc *dc);
262extern int tegra_dc_rgb_exit(struct tegra_dc *dc);
263
264/* from output.c */
59d29c0e
TR
265extern int tegra_output_probe(struct tegra_output *output);
266extern int tegra_output_remove(struct tegra_output *output);
d8f4a9ed
TR
267extern int tegra_output_init(struct drm_device *drm, struct tegra_output *output);
268extern int tegra_output_exit(struct tegra_output *output);
269
6b6b6042
TR
270/* from dpaux.c */
271
272struct tegra_dpaux;
273struct drm_dp_link;
274struct drm_dp_aux;
275
276struct tegra_dpaux *tegra_dpaux_find_by_of_node(struct device_node *np);
277enum drm_connector_status tegra_dpaux_detect(struct tegra_dpaux *dpaux);
278int tegra_dpaux_attach(struct tegra_dpaux *dpaux, struct tegra_output *output);
279int tegra_dpaux_detach(struct tegra_dpaux *dpaux);
280int tegra_dpaux_enable(struct tegra_dpaux *dpaux);
281int tegra_dpaux_disable(struct tegra_dpaux *dpaux);
282int tegra_dpaux_prepare(struct tegra_dpaux *dpaux, u8 encoding);
283int tegra_dpaux_train(struct tegra_dpaux *dpaux, struct drm_dp_link *link,
284 u8 pattern);
285
d8f4a9ed 286/* from fb.c */
de2ba664
AM
287struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer,
288 unsigned int index);
db7fbdfd 289bool tegra_fb_is_bottom_up(struct drm_framebuffer *framebuffer);
773af77f 290bool tegra_fb_is_tiled(struct drm_framebuffer *framebuffer);
d8f4a9ed
TR
291extern int tegra_drm_fb_init(struct drm_device *drm);
292extern void tegra_drm_fb_exit(struct drm_device *drm);
60c2f709 293#ifdef CONFIG_DRM_TEGRA_FBDEV
de2ba664 294extern void tegra_fbdev_restore_mode(struct tegra_fbdev *fbdev);
60c2f709 295#endif
d8f4a9ed 296
776dc384 297extern struct platform_driver tegra_dc_driver;
dec72739 298extern struct platform_driver tegra_dsi_driver;
6b6b6042 299extern struct platform_driver tegra_sor_driver;
776dc384 300extern struct platform_driver tegra_hdmi_driver;
6b6b6042 301extern struct platform_driver tegra_dpaux_driver;
776dc384 302extern struct platform_driver tegra_gr2d_driver;
5f60ed0d 303extern struct platform_driver tegra_gr3d_driver;
d8f4a9ed 304
4231c6b0 305#endif /* HOST1X_DRM_H */