blob: fdfe259ed7f8e5e403f984d533b54a3257128aef [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
Thierry Redinge1e90642013-09-24 13:59:01 +020013#include <uapi/drm/tegra_drm.h>
14#include <linux/host1x.h>
15
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000016#include <drm/drmP.h>
17#include <drm/drm_crtc_helper.h>
18#include <drm/drm_edid.h>
19#include <drm/drm_fb_helper.h>
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000020#include <drm/drm_fixed.h>
21
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;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000035
36 struct mutex clients_lock;
37 struct list_head clients;
38
Arto Merilainende2ba662013-03-22 16:34:08 +020039 struct tegra_fbdev *fbdev;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000040};
41
Thierry Reding53fa7f72013-09-24 15:35:40 +020042struct tegra_drm_client;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000043
Thierry Redingc88c3632013-09-26 16:08:22 +020044struct tegra_drm_context {
Thierry Reding53fa7f72013-09-24 15:35:40 +020045 struct tegra_drm_client *client;
Terje Bergstromd43f81c2013-03-22 16:34:09 +020046 struct host1x_channel *channel;
47 struct list_head list;
48};
49
Thierry Reding53fa7f72013-09-24 15:35:40 +020050struct tegra_drm_client_ops {
51 int (*open_channel)(struct tegra_drm_client *client,
Thierry Redingc88c3632013-09-26 16:08:22 +020052 struct tegra_drm_context *context);
53 void (*close_channel)(struct tegra_drm_context *context);
Thierry Redingc40f0f12013-10-10 11:00:33 +020054 int (*is_addr_reg)(struct device *dev, u32 class, u32 offset);
Thierry Redingc88c3632013-09-26 16:08:22 +020055 int (*submit)(struct tegra_drm_context *context,
Terje Bergstromd43f81c2013-03-22 16:34:09 +020056 struct drm_tegra_submit *args, struct drm_device *drm,
57 struct drm_file *file);
58};
59
Thierry Redingc40f0f12013-10-10 11:00:33 +020060int tegra_drm_submit(struct tegra_drm_context *context,
61 struct drm_tegra_submit *args, struct drm_device *drm,
62 struct drm_file *file);
63
Thierry Reding53fa7f72013-09-24 15:35:40 +020064struct tegra_drm_client {
65 struct host1x_client base;
Thierry Reding776dc382013-10-14 14:43:22 +020066 struct list_head list;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000067
Thierry Reding53fa7f72013-09-24 15:35:40 +020068 const struct tegra_drm_client_ops *ops;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000069};
70
Thierry Reding53fa7f72013-09-24 15:35:40 +020071static inline struct tegra_drm_client *
Thierry Reding776dc382013-10-14 14:43:22 +020072host1x_to_drm_client(struct host1x_client *client)
Thierry Reding53fa7f72013-09-24 15:35:40 +020073{
74 return container_of(client, struct tegra_drm_client, base);
75}
76
Thierry Reding776dc382013-10-14 14:43:22 +020077extern int tegra_drm_register_client(struct tegra_drm *tegra,
78 struct tegra_drm_client *client);
79extern int tegra_drm_unregister_client(struct tegra_drm *tegra,
80 struct tegra_drm_client *client);
81
Thierry Reding386a2a72013-09-24 13:22:17 +020082extern int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm);
83extern int tegra_drm_exit(struct tegra_drm *tegra);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000084
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000085struct tegra_output;
86
87struct tegra_dc {
Thierry Reding776dc382013-10-14 14:43:22 +020088 struct host1x_client client;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000089 struct device *dev;
Thierry Redingd18d3032013-09-26 16:09:19 +020090 spinlock_t lock;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000091
92 struct drm_crtc base;
93 int pipe;
94
95 struct clk *clk;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000096 void __iomem *regs;
97 int irq;
98
99 struct tegra_output *rgb;
100
101 struct list_head list;
102
103 struct drm_info_list *debugfs_files;
104 struct drm_minor *minor;
105 struct dentry *debugfs;
Thierry Reding3c03c462012-11-28 12:00:18 +0100106
107 /* page-flip handling */
108 struct drm_pending_vblank_event *event;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000109};
110
Thierry Reding53fa7f72013-09-24 15:35:40 +0200111static inline struct tegra_dc *
Thierry Reding776dc382013-10-14 14:43:22 +0200112host1x_client_to_dc(struct host1x_client *client)
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000113{
114 return container_of(client, struct tegra_dc, client);
115}
116
117static inline struct tegra_dc *to_tegra_dc(struct drm_crtc *crtc)
118{
119 return container_of(crtc, struct tegra_dc, base);
120}
121
122static inline void tegra_dc_writel(struct tegra_dc *dc, unsigned long value,
123 unsigned long reg)
124{
125 writel(value, dc->regs + (reg << 2));
126}
127
128static inline unsigned long tegra_dc_readl(struct tegra_dc *dc,
129 unsigned long reg)
130{
131 return readl(dc->regs + (reg << 2));
132}
133
Thierry Redingf34bc782012-11-04 21:47:13 +0100134struct tegra_dc_window {
135 struct {
136 unsigned int x;
137 unsigned int y;
138 unsigned int w;
139 unsigned int h;
140 } src;
141 struct {
142 unsigned int x;
143 unsigned int y;
144 unsigned int w;
145 unsigned int h;
146 } dst;
147 unsigned int bits_per_pixel;
148 unsigned int format;
149 unsigned int stride[2];
150 unsigned long base[3];
Thierry Redingdb7fbdf2013-10-07 09:47:58 +0200151 bool bottom_up;
Thierry Reding773af772013-10-04 22:34:01 +0200152 bool tiled;
Thierry Redingf34bc782012-11-04 21:47:13 +0100153};
154
155/* from dc.c */
156extern unsigned int tegra_dc_format(uint32_t format);
157extern int tegra_dc_setup_window(struct tegra_dc *dc, unsigned int index,
158 const struct tegra_dc_window *window);
Thierry Reding6e5ff992012-11-28 11:45:47 +0100159extern void tegra_dc_enable_vblank(struct tegra_dc *dc);
160extern void tegra_dc_disable_vblank(struct tegra_dc *dc);
Thierry Reding3c03c462012-11-28 12:00:18 +0100161extern void tegra_dc_cancel_page_flip(struct drm_crtc *crtc,
162 struct drm_file *file);
Thierry Redingf34bc782012-11-04 21:47:13 +0100163
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000164struct 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,
168 unsigned long pclk);
169 int (*check_mode)(struct tegra_output *output,
170 struct drm_display_mode *mode,
171 enum drm_mode_status *status);
172};
173
174enum tegra_output_type {
175 TEGRA_OUTPUT_RGB,
Thierry Redingedec4af2012-11-15 21:28:23 +0000176 TEGRA_OUTPUT_HDMI,
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000177};
178
179struct tegra_output {
180 struct device_node *of_node;
181 struct device *dev;
182
183 const struct tegra_output_ops *ops;
184 enum tegra_output_type type;
185
186 struct i2c_adapter *ddc;
187 const struct edid *edid;
188 unsigned int hpd_irq;
189 int hpd_gpio;
190
191 struct drm_encoder encoder;
192 struct drm_connector connector;
193};
194
195static inline struct tegra_output *encoder_to_output(struct drm_encoder *e)
196{
197 return container_of(e, struct tegra_output, encoder);
198}
199
200static inline struct tegra_output *connector_to_output(struct drm_connector *c)
201{
202 return container_of(c, struct tegra_output, connector);
203}
204
205static inline int tegra_output_enable(struct tegra_output *output)
206{
207 if (output && output->ops && output->ops->enable)
208 return output->ops->enable(output);
209
210 return output ? -ENOSYS : -EINVAL;
211}
212
213static inline int tegra_output_disable(struct tegra_output *output)
214{
215 if (output && output->ops && output->ops->disable)
216 return output->ops->disable(output);
217
218 return output ? -ENOSYS : -EINVAL;
219}
220
221static inline int tegra_output_setup_clock(struct tegra_output *output,
222 struct clk *clk, unsigned long pclk)
223{
224 if (output && output->ops && output->ops->setup_clock)
225 return output->ops->setup_clock(output, clk, pclk);
226
227 return output ? -ENOSYS : -EINVAL;
228}
229
230static inline int tegra_output_check_mode(struct tegra_output *output,
231 struct drm_display_mode *mode,
232 enum drm_mode_status *status)
233{
234 if (output && output->ops && output->ops->check_mode)
235 return output->ops->check_mode(output, mode, status);
236
237 return output ? -ENOSYS : -EINVAL;
238}
239
Thierry Reding776dc382013-10-14 14:43:22 +0200240/* from bus.c */
241int drm_host1x_init(struct drm_driver *driver, struct host1x_device *device);
242void drm_host1x_exit(struct drm_driver *driver, struct host1x_device *device);
243
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000244/* from rgb.c */
245extern int tegra_dc_rgb_probe(struct tegra_dc *dc);
Thierry Reding59d29c02013-10-14 14:26:42 +0200246extern int tegra_dc_rgb_remove(struct tegra_dc *dc);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000247extern 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 */
Thierry Reding59d29c02013-10-14 14:26:42 +0200251extern int tegra_output_probe(struct tegra_output *output);
252extern int tegra_output_remove(struct tegra_output *output);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000253extern int tegra_output_init(struct drm_device *drm, struct tegra_output *output);
254extern int tegra_output_exit(struct tegra_output *output);
255
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000256/* from fb.c */
Arto Merilainende2ba662013-03-22 16:34:08 +0200257struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer,
258 unsigned int index);
Thierry Redingdb7fbdf2013-10-07 09:47:58 +0200259bool tegra_fb_is_bottom_up(struct drm_framebuffer *framebuffer);
Thierry Reding773af772013-10-04 22:34:01 +0200260bool tegra_fb_is_tiled(struct drm_framebuffer *framebuffer);
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 Reding776dc382013-10-14 14:43:22 +0200265extern struct platform_driver tegra_dc_driver;
266extern struct platform_driver tegra_hdmi_driver;
267extern struct platform_driver tegra_gr2d_driver;
Thierry Reding5f60ed02013-02-28 08:08:01 +0100268extern struct platform_driver tegra_gr3d_driver;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000269
Terje Bergstrom4231c6b2013-03-22 16:34:05 +0200270#endif /* HOST1X_DRM_H */