blob: 25522e23c7b87fe12497aad64e54babe744129b7 [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);
54 int (*submit)(struct tegra_drm_context *context,
Terje Bergstromd43f81c2013-03-22 16:34:09 +020055 struct drm_tegra_submit *args, struct drm_device *drm,
56 struct drm_file *file);
57};
58
Thierry Reding53fa7f72013-09-24 15:35:40 +020059struct tegra_drm_client {
60 struct host1x_client base;
Thierry Reding776dc382013-10-14 14:43:22 +020061 struct list_head list;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000062
Thierry Reding53fa7f72013-09-24 15:35:40 +020063 const struct tegra_drm_client_ops *ops;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000064};
65
Thierry Reding53fa7f72013-09-24 15:35:40 +020066static inline struct tegra_drm_client *
Thierry Reding776dc382013-10-14 14:43:22 +020067host1x_to_drm_client(struct host1x_client *client)
Thierry Reding53fa7f72013-09-24 15:35:40 +020068{
69 return container_of(client, struct tegra_drm_client, base);
70}
71
Thierry Reding776dc382013-10-14 14:43:22 +020072extern int tegra_drm_register_client(struct tegra_drm *tegra,
73 struct tegra_drm_client *client);
74extern int tegra_drm_unregister_client(struct tegra_drm *tegra,
75 struct tegra_drm_client *client);
76
Thierry Reding386a2a72013-09-24 13:22:17 +020077extern int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm);
78extern int tegra_drm_exit(struct tegra_drm *tegra);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000079
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000080struct tegra_output;
81
82struct tegra_dc {
Thierry Reding776dc382013-10-14 14:43:22 +020083 struct host1x_client client;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000084 struct device *dev;
Thierry Redingd18d3032013-09-26 16:09:19 +020085 spinlock_t lock;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000086
87 struct drm_crtc base;
88 int pipe;
89
90 struct clk *clk;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000091 void __iomem *regs;
92 int irq;
93
94 struct tegra_output *rgb;
95
96 struct list_head list;
97
98 struct drm_info_list *debugfs_files;
99 struct drm_minor *minor;
100 struct dentry *debugfs;
Thierry Reding3c03c462012-11-28 12:00:18 +0100101
102 /* page-flip handling */
103 struct drm_pending_vblank_event *event;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000104};
105
Thierry Reding53fa7f72013-09-24 15:35:40 +0200106static inline struct tegra_dc *
Thierry Reding776dc382013-10-14 14:43:22 +0200107host1x_client_to_dc(struct host1x_client *client)
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000108{
109 return container_of(client, struct tegra_dc, client);
110}
111
112static inline struct tegra_dc *to_tegra_dc(struct drm_crtc *crtc)
113{
114 return container_of(crtc, struct tegra_dc, base);
115}
116
117static inline void tegra_dc_writel(struct tegra_dc *dc, unsigned long value,
118 unsigned long reg)
119{
120 writel(value, dc->regs + (reg << 2));
121}
122
123static inline unsigned long tegra_dc_readl(struct tegra_dc *dc,
124 unsigned long reg)
125{
126 return readl(dc->regs + (reg << 2));
127}
128
Thierry Redingf34bc782012-11-04 21:47:13 +0100129struct tegra_dc_window {
130 struct {
131 unsigned int x;
132 unsigned int y;
133 unsigned int w;
134 unsigned int h;
135 } src;
136 struct {
137 unsigned int x;
138 unsigned int y;
139 unsigned int w;
140 unsigned int h;
141 } dst;
142 unsigned int bits_per_pixel;
143 unsigned int format;
144 unsigned int stride[2];
145 unsigned long base[3];
146};
147
148/* from dc.c */
149extern unsigned int tegra_dc_format(uint32_t format);
150extern int tegra_dc_setup_window(struct tegra_dc *dc, unsigned int index,
151 const struct tegra_dc_window *window);
Thierry Reding6e5ff992012-11-28 11:45:47 +0100152extern void tegra_dc_enable_vblank(struct tegra_dc *dc);
153extern void tegra_dc_disable_vblank(struct tegra_dc *dc);
Thierry Reding3c03c462012-11-28 12:00:18 +0100154extern void tegra_dc_cancel_page_flip(struct drm_crtc *crtc,
155 struct drm_file *file);
Thierry Redingf34bc782012-11-04 21:47:13 +0100156
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000157struct tegra_output_ops {
158 int (*enable)(struct tegra_output *output);
159 int (*disable)(struct tegra_output *output);
160 int (*setup_clock)(struct tegra_output *output, struct clk *clk,
161 unsigned long pclk);
162 int (*check_mode)(struct tegra_output *output,
163 struct drm_display_mode *mode,
164 enum drm_mode_status *status);
165};
166
167enum tegra_output_type {
168 TEGRA_OUTPUT_RGB,
Thierry Redingedec4af2012-11-15 21:28:23 +0000169 TEGRA_OUTPUT_HDMI,
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000170};
171
172struct tegra_output {
173 struct device_node *of_node;
174 struct device *dev;
175
176 const struct tegra_output_ops *ops;
177 enum tegra_output_type type;
178
179 struct i2c_adapter *ddc;
180 const struct edid *edid;
181 unsigned int hpd_irq;
182 int hpd_gpio;
183
184 struct drm_encoder encoder;
185 struct drm_connector connector;
186};
187
188static inline struct tegra_output *encoder_to_output(struct drm_encoder *e)
189{
190 return container_of(e, struct tegra_output, encoder);
191}
192
193static inline struct tegra_output *connector_to_output(struct drm_connector *c)
194{
195 return container_of(c, struct tegra_output, connector);
196}
197
198static inline int tegra_output_enable(struct tegra_output *output)
199{
200 if (output && output->ops && output->ops->enable)
201 return output->ops->enable(output);
202
203 return output ? -ENOSYS : -EINVAL;
204}
205
206static inline int tegra_output_disable(struct tegra_output *output)
207{
208 if (output && output->ops && output->ops->disable)
209 return output->ops->disable(output);
210
211 return output ? -ENOSYS : -EINVAL;
212}
213
214static inline int tegra_output_setup_clock(struct tegra_output *output,
215 struct clk *clk, unsigned long pclk)
216{
217 if (output && output->ops && output->ops->setup_clock)
218 return output->ops->setup_clock(output, clk, pclk);
219
220 return output ? -ENOSYS : -EINVAL;
221}
222
223static inline int tegra_output_check_mode(struct tegra_output *output,
224 struct drm_display_mode *mode,
225 enum drm_mode_status *status)
226{
227 if (output && output->ops && output->ops->check_mode)
228 return output->ops->check_mode(output, mode, status);
229
230 return output ? -ENOSYS : -EINVAL;
231}
232
Thierry Reding776dc382013-10-14 14:43:22 +0200233/* from bus.c */
234int drm_host1x_init(struct drm_driver *driver, struct host1x_device *device);
235void drm_host1x_exit(struct drm_driver *driver, struct host1x_device *device);
236
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000237/* from rgb.c */
238extern int tegra_dc_rgb_probe(struct tegra_dc *dc);
239extern int tegra_dc_rgb_init(struct drm_device *drm, struct tegra_dc *dc);
240extern int tegra_dc_rgb_exit(struct tegra_dc *dc);
241
242/* from output.c */
243extern int tegra_output_parse_dt(struct tegra_output *output);
244extern int tegra_output_init(struct drm_device *drm, struct tegra_output *output);
245extern int tegra_output_exit(struct tegra_output *output);
246
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000247/* from fb.c */
Arto Merilainende2ba662013-03-22 16:34:08 +0200248struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer,
249 unsigned int index);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000250extern int tegra_drm_fb_init(struct drm_device *drm);
251extern void tegra_drm_fb_exit(struct drm_device *drm);
Arto Merilainende2ba662013-03-22 16:34:08 +0200252extern void tegra_fbdev_restore_mode(struct tegra_fbdev *fbdev);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000253
Thierry Reding776dc382013-10-14 14:43:22 +0200254extern struct platform_driver tegra_dc_driver;
255extern struct platform_driver tegra_hdmi_driver;
256extern struct platform_driver tegra_gr2d_driver;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000257
Terje Bergstrom4231c6b2013-03-22 16:34:05 +0200258#endif /* HOST1X_DRM_H */