blob: f7cd946df8fac99e6967f1c7af164e07a1112be6 [file] [log] [blame]
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00001/*
2 * Copyright (C) 2012 Avionic Design GmbH
Terje Bergstromd43f81c2013-03-22 16:34:09 +02003 * Copyright (C) 2012-2013 NVIDIA CORPORATION. All rights reserved.
Thierry Redingd8f4a9e2012-11-15 21:28:22 +00004 *
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
Terje Bergstrom4231c6b2013-03-22 16:34:05 +020010#ifndef HOST1X_DRM_H
11#define HOST1X_DRM_H 1
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000012
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>
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000017#include <drm/drm_fixed.h>
Terje Bergstromd43f81c2013-03-22 16:34:09 +020018#include <uapi/drm/tegra_drm.h>
19
20#include "host1x.h"
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000021
Arto Merilainende2ba662013-03-22 16:34:08 +020022struct tegra_fb {
23 struct drm_framebuffer base;
24 struct tegra_bo **planes;
25 unsigned int num_planes;
26};
27
28struct tegra_fbdev {
29 struct drm_fb_helper base;
30 struct tegra_fb *fb;
31};
32
Arto Merilainenc89c0ea2013-03-22 16:34:06 +020033struct host1x_drm {
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000034 struct drm_device *drm;
35 struct device *dev;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000036
37 struct mutex drm_clients_lock;
38 struct list_head drm_clients;
39 struct list_head drm_active;
40
41 struct mutex clients_lock;
42 struct list_head clients;
43
Arto Merilainende2ba662013-03-22 16:34:08 +020044 struct tegra_fbdev *fbdev;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000045};
46
47struct host1x_client;
48
Terje Bergstromd43f81c2013-03-22 16:34:09 +020049struct host1x_drm_context {
50 struct host1x_client *client;
51 struct host1x_channel *channel;
52 struct list_head list;
53};
54
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000055struct host1x_client_ops {
56 int (*drm_init)(struct host1x_client *client, struct drm_device *drm);
57 int (*drm_exit)(struct host1x_client *client);
Terje Bergstromd43f81c2013-03-22 16:34:09 +020058 int (*open_channel)(struct host1x_client *client,
59 struct host1x_drm_context *context);
60 void (*close_channel)(struct host1x_drm_context *context);
61 int (*submit)(struct host1x_drm_context *context,
62 struct drm_tegra_submit *args, struct drm_device *drm,
63 struct drm_file *file);
64};
65
66struct host1x_drm_file {
67 struct list_head contexts;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000068};
69
70struct host1x_client {
Arto Merilainenc89c0ea2013-03-22 16:34:06 +020071 struct host1x_drm *host1x;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000072 struct device *dev;
73
74 const struct host1x_client_ops *ops;
75
Terje Bergstromd43f81c2013-03-22 16:34:09 +020076 enum host1x_class class;
77 struct host1x_channel *channel;
78
79 struct host1x_syncpt **syncpts;
80 unsigned int num_syncpts;
81
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000082 struct list_head list;
83};
84
Arto Merilainenc89c0ea2013-03-22 16:34:06 +020085extern int host1x_drm_init(struct host1x_drm *host1x, struct drm_device *drm);
86extern int host1x_drm_exit(struct host1x_drm *host1x);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000087
Arto Merilainenc89c0ea2013-03-22 16:34:06 +020088extern int host1x_register_client(struct host1x_drm *host1x,
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000089 struct host1x_client *client);
Arto Merilainenc89c0ea2013-03-22 16:34:06 +020090extern int host1x_unregister_client(struct host1x_drm *host1x,
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000091 struct host1x_client *client);
92
93struct tegra_output;
94
95struct tegra_dc {
96 struct host1x_client client;
Thierry Reding6e5ff992012-11-28 11:45:47 +010097 spinlock_t lock;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000098
Arto Merilainenc89c0ea2013-03-22 16:34:06 +020099 struct host1x_drm *host1x;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000100 struct device *dev;
101
102 struct drm_crtc base;
103 int pipe;
104
105 struct clk *clk;
106
107 void __iomem *regs;
108 int irq;
109
110 struct tegra_output *rgb;
111
112 struct list_head list;
113
114 struct drm_info_list *debugfs_files;
115 struct drm_minor *minor;
116 struct dentry *debugfs;
Thierry Reding3c03c462012-11-28 12:00:18 +0100117
118 /* page-flip handling */
119 struct drm_pending_vblank_event *event;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000120};
121
122static inline struct tegra_dc *host1x_client_to_dc(struct host1x_client *client)
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{
129 return container_of(crtc, struct tegra_dc, base);
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
Thierry Redingf34bc782012-11-04 21:47:13 +0100144struct 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};
162
163/* from dc.c */
164extern unsigned int tegra_dc_format(uint32_t format);
165extern int tegra_dc_setup_window(struct tegra_dc *dc, unsigned int index,
166 const struct tegra_dc_window *window);
Thierry Reding6e5ff992012-11-28 11:45:47 +0100167extern void tegra_dc_enable_vblank(struct tegra_dc *dc);
168extern void tegra_dc_disable_vblank(struct tegra_dc *dc);
Thierry Reding3c03c462012-11-28 12:00:18 +0100169extern void tegra_dc_cancel_page_flip(struct drm_crtc *crtc,
170 struct drm_file *file);
Thierry Redingf34bc782012-11-04 21:47:13 +0100171
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000172struct tegra_output_ops {
173 int (*enable)(struct tegra_output *output);
174 int (*disable)(struct tegra_output *output);
175 int (*setup_clock)(struct tegra_output *output, struct clk *clk,
176 unsigned long pclk);
177 int (*check_mode)(struct tegra_output *output,
178 struct drm_display_mode *mode,
179 enum drm_mode_status *status);
180};
181
182enum tegra_output_type {
183 TEGRA_OUTPUT_RGB,
Thierry Redingedec4af2012-11-15 21:28:23 +0000184 TEGRA_OUTPUT_HDMI,
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000185};
186
187struct tegra_output {
188 struct device_node *of_node;
189 struct device *dev;
190
191 const struct tegra_output_ops *ops;
192 enum tegra_output_type type;
193
194 struct i2c_adapter *ddc;
195 const struct edid *edid;
196 unsigned int hpd_irq;
197 int hpd_gpio;
198
199 struct drm_encoder encoder;
200 struct drm_connector connector;
201};
202
203static inline struct tegra_output *encoder_to_output(struct drm_encoder *e)
204{
205 return container_of(e, struct tegra_output, encoder);
206}
207
208static inline struct tegra_output *connector_to_output(struct drm_connector *c)
209{
210 return container_of(c, struct tegra_output, connector);
211}
212
213static inline int tegra_output_enable(struct tegra_output *output)
214{
215 if (output && output->ops && output->ops->enable)
216 return output->ops->enable(output);
217
218 return output ? -ENOSYS : -EINVAL;
219}
220
221static inline int tegra_output_disable(struct tegra_output *output)
222{
223 if (output && output->ops && output->ops->disable)
224 return output->ops->disable(output);
225
226 return output ? -ENOSYS : -EINVAL;
227}
228
229static inline int tegra_output_setup_clock(struct tegra_output *output,
230 struct clk *clk, unsigned long pclk)
231{
232 if (output && output->ops && output->ops->setup_clock)
233 return output->ops->setup_clock(output, clk, pclk);
234
235 return output ? -ENOSYS : -EINVAL;
236}
237
238static inline int tegra_output_check_mode(struct tegra_output *output,
239 struct drm_display_mode *mode,
240 enum drm_mode_status *status)
241{
242 if (output && output->ops && output->ops->check_mode)
243 return output->ops->check_mode(output, mode, status);
244
245 return output ? -ENOSYS : -EINVAL;
246}
247
248/* from rgb.c */
249extern int tegra_dc_rgb_probe(struct tegra_dc *dc);
250extern int tegra_dc_rgb_init(struct drm_device *drm, struct tegra_dc *dc);
251extern int tegra_dc_rgb_exit(struct tegra_dc *dc);
252
253/* from output.c */
254extern int tegra_output_parse_dt(struct tegra_output *output);
255extern int tegra_output_init(struct drm_device *drm, struct tegra_output *output);
256extern int tegra_output_exit(struct tegra_output *output);
257
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000258/* from fb.c */
Arto Merilainende2ba662013-03-22 16:34:08 +0200259struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer,
260 unsigned int index);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000261extern int tegra_drm_fb_init(struct drm_device *drm);
262extern void tegra_drm_fb_exit(struct drm_device *drm);
Arto Merilainende2ba662013-03-22 16:34:08 +0200263extern void tegra_fbdev_restore_mode(struct tegra_fbdev *fbdev);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000264
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000265extern struct drm_driver tegra_drm_driver;
266
Terje Bergstrom4231c6b2013-03-22 16:34:05 +0200267#endif /* HOST1X_DRM_H */