blob: 858bfc0db78a6a776b188c70b8bbcaa95bfa7a7a [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
Thierry Reding386a2a72013-09-24 13:22:17 +020033struct tegra_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
Thierry Reding386a2a72013-09-24 13:22:17 +020037 struct mutex subdevs_lock;
38 struct list_head subdevs;
39 struct list_head active;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000040
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 {
Thierry Reding386a2a72013-09-24 13:22:17 +020071 struct tegra_drm *tegra;
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
Thierry Reding386a2a72013-09-24 13:22:17 +020085extern int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm);
86extern int tegra_drm_exit(struct tegra_drm *tegra);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000087
Thierry Reding386a2a72013-09-24 13:22:17 +020088extern int host1x_register_client(struct tegra_drm *tegra,
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000089 struct host1x_client *client);
Thierry Reding386a2a72013-09-24 13:22:17 +020090extern int host1x_unregister_client(struct tegra_drm *tegra,
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 Redingd8f4a9e2012-11-15 21:28:22 +000097 struct device *dev;
Thierry Redingd18d3032013-09-26 16:09:19 +020098 spinlock_t lock;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000099
100 struct drm_crtc base;
101 int pipe;
102
103 struct clk *clk;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000104 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;
Thierry Reding3c03c462012-11-28 12:00:18 +0100114
115 /* page-flip handling */
116 struct drm_pending_vblank_event *event;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000117};
118
119static inline struct tegra_dc *host1x_client_to_dc(struct host1x_client *client)
120{
121 return container_of(client, struct tegra_dc, client);
122}
123
124static inline struct tegra_dc *to_tegra_dc(struct drm_crtc *crtc)
125{
126 return container_of(crtc, struct tegra_dc, base);
127}
128
129static inline void tegra_dc_writel(struct tegra_dc *dc, unsigned long value,
130 unsigned long reg)
131{
132 writel(value, dc->regs + (reg << 2));
133}
134
135static inline unsigned long tegra_dc_readl(struct tegra_dc *dc,
136 unsigned long reg)
137{
138 return readl(dc->regs + (reg << 2));
139}
140
Thierry Redingf34bc782012-11-04 21:47:13 +0100141struct tegra_dc_window {
142 struct {
143 unsigned int x;
144 unsigned int y;
145 unsigned int w;
146 unsigned int h;
147 } src;
148 struct {
149 unsigned int x;
150 unsigned int y;
151 unsigned int w;
152 unsigned int h;
153 } dst;
154 unsigned int bits_per_pixel;
155 unsigned int format;
156 unsigned int stride[2];
157 unsigned long base[3];
158};
159
160/* from dc.c */
161extern unsigned int tegra_dc_format(uint32_t format);
162extern int tegra_dc_setup_window(struct tegra_dc *dc, unsigned int index,
163 const struct tegra_dc_window *window);
Thierry Reding6e5ff992012-11-28 11:45:47 +0100164extern void tegra_dc_enable_vblank(struct tegra_dc *dc);
165extern void tegra_dc_disable_vblank(struct tegra_dc *dc);
Thierry Reding3c03c462012-11-28 12:00:18 +0100166extern void tegra_dc_cancel_page_flip(struct drm_crtc *crtc,
167 struct drm_file *file);
Thierry Redingf34bc782012-11-04 21:47:13 +0100168
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000169struct tegra_output_ops {
170 int (*enable)(struct tegra_output *output);
171 int (*disable)(struct tegra_output *output);
172 int (*setup_clock)(struct tegra_output *output, struct clk *clk,
173 unsigned long pclk);
174 int (*check_mode)(struct tegra_output *output,
175 struct drm_display_mode *mode,
176 enum drm_mode_status *status);
177};
178
179enum tegra_output_type {
180 TEGRA_OUTPUT_RGB,
Thierry Redingedec4af2012-11-15 21:28:23 +0000181 TEGRA_OUTPUT_HDMI,
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000182};
183
184struct tegra_output {
185 struct device_node *of_node;
186 struct device *dev;
187
188 const struct tegra_output_ops *ops;
189 enum tegra_output_type type;
190
191 struct i2c_adapter *ddc;
192 const struct edid *edid;
193 unsigned int hpd_irq;
194 int hpd_gpio;
195
196 struct drm_encoder encoder;
197 struct drm_connector connector;
198};
199
200static inline struct tegra_output *encoder_to_output(struct drm_encoder *e)
201{
202 return container_of(e, struct tegra_output, encoder);
203}
204
205static inline struct tegra_output *connector_to_output(struct drm_connector *c)
206{
207 return container_of(c, struct tegra_output, connector);
208}
209
210static inline int tegra_output_enable(struct tegra_output *output)
211{
212 if (output && output->ops && output->ops->enable)
213 return output->ops->enable(output);
214
215 return output ? -ENOSYS : -EINVAL;
216}
217
218static inline int tegra_output_disable(struct tegra_output *output)
219{
220 if (output && output->ops && output->ops->disable)
221 return output->ops->disable(output);
222
223 return output ? -ENOSYS : -EINVAL;
224}
225
226static inline int tegra_output_setup_clock(struct tegra_output *output,
227 struct clk *clk, unsigned long pclk)
228{
229 if (output && output->ops && output->ops->setup_clock)
230 return output->ops->setup_clock(output, clk, pclk);
231
232 return output ? -ENOSYS : -EINVAL;
233}
234
235static inline int tegra_output_check_mode(struct tegra_output *output,
236 struct drm_display_mode *mode,
237 enum drm_mode_status *status)
238{
239 if (output && output->ops && output->ops->check_mode)
240 return output->ops->check_mode(output, mode, status);
241
242 return output ? -ENOSYS : -EINVAL;
243}
244
245/* from rgb.c */
246extern int tegra_dc_rgb_probe(struct tegra_dc *dc);
247extern int tegra_dc_rgb_init(struct drm_device *drm, struct tegra_dc *dc);
248extern int tegra_dc_rgb_exit(struct tegra_dc *dc);
249
250/* from output.c */
251extern int tegra_output_parse_dt(struct tegra_output *output);
252extern int tegra_output_init(struct drm_device *drm, struct tegra_output *output);
253extern int tegra_output_exit(struct tegra_output *output);
254
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000255/* from fb.c */
Arto Merilainende2ba662013-03-22 16:34:08 +0200256struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer,
257 unsigned int index);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000258extern int tegra_drm_fb_init(struct drm_device *drm);
259extern void tegra_drm_fb_exit(struct drm_device *drm);
Arto Merilainende2ba662013-03-22 16:34:08 +0200260extern void tegra_fbdev_restore_mode(struct tegra_fbdev *fbdev);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000261
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000262extern struct drm_driver tegra_drm_driver;
263
Terje Bergstrom4231c6b2013-03-22 16:34:05 +0200264#endif /* HOST1X_DRM_H */