blob: 6b293c88a8caf2bdf2d6c16fbe5cb8975181fba4 [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
Stephen Warrenca480802013-11-06 16:20:54 -070022struct reset_control;
23
Arto Merilainende2ba662013-03-22 16:34:08 +020024struct tegra_fb {
25 struct drm_framebuffer base;
26 struct tegra_bo **planes;
27 unsigned int num_planes;
28};
29
Thierry Reding60c2f702013-10-31 13:28:50 +010030#ifdef CONFIG_DRM_TEGRA_FBDEV
Arto Merilainende2ba662013-03-22 16:34:08 +020031struct tegra_fbdev {
32 struct drm_fb_helper base;
33 struct tegra_fb *fb;
34};
Thierry Reding60c2f702013-10-31 13:28:50 +010035#endif
Arto Merilainende2ba662013-03-22 16:34:08 +020036
Thierry Reding386a2a72013-09-24 13:22:17 +020037struct tegra_drm {
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000038 struct drm_device *drm;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000039
40 struct mutex clients_lock;
41 struct list_head clients;
42
Thierry Reding60c2f702013-10-31 13:28:50 +010043#ifdef CONFIG_DRM_TEGRA_FBDEV
Arto Merilainende2ba662013-03-22 16:34:08 +020044 struct tegra_fbdev *fbdev;
Thierry Reding60c2f702013-10-31 13:28:50 +010045#endif
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000046};
47
Thierry Reding53fa7f72013-09-24 15:35:40 +020048struct tegra_drm_client;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000049
Thierry Redingc88c3632013-09-26 16:08:22 +020050struct tegra_drm_context {
Thierry Reding53fa7f72013-09-24 15:35:40 +020051 struct tegra_drm_client *client;
Terje Bergstromd43f81c2013-03-22 16:34:09 +020052 struct host1x_channel *channel;
53 struct list_head list;
54};
55
Thierry Reding53fa7f72013-09-24 15:35:40 +020056struct tegra_drm_client_ops {
57 int (*open_channel)(struct tegra_drm_client *client,
Thierry Redingc88c3632013-09-26 16:08:22 +020058 struct tegra_drm_context *context);
59 void (*close_channel)(struct tegra_drm_context *context);
Thierry Redingc40f0f12013-10-10 11:00:33 +020060 int (*is_addr_reg)(struct device *dev, u32 class, u32 offset);
Thierry Redingc88c3632013-09-26 16:08:22 +020061 int (*submit)(struct tegra_drm_context *context,
Terje Bergstromd43f81c2013-03-22 16:34:09 +020062 struct drm_tegra_submit *args, struct drm_device *drm,
63 struct drm_file *file);
64};
65
Thierry Redingc40f0f12013-10-10 11:00:33 +020066int tegra_drm_submit(struct tegra_drm_context *context,
67 struct drm_tegra_submit *args, struct drm_device *drm,
68 struct drm_file *file);
69
Thierry Reding53fa7f72013-09-24 15:35:40 +020070struct tegra_drm_client {
71 struct host1x_client base;
Thierry Reding776dc382013-10-14 14:43:22 +020072 struct list_head list;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000073
Thierry Reding53fa7f72013-09-24 15:35:40 +020074 const struct tegra_drm_client_ops *ops;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000075};
76
Thierry Reding53fa7f72013-09-24 15:35:40 +020077static inline struct tegra_drm_client *
Thierry Reding776dc382013-10-14 14:43:22 +020078host1x_to_drm_client(struct host1x_client *client)
Thierry Reding53fa7f72013-09-24 15:35:40 +020079{
80 return container_of(client, struct tegra_drm_client, base);
81}
82
Thierry Reding776dc382013-10-14 14:43:22 +020083extern 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
Thierry Reding386a2a72013-09-24 13:22:17 +020088extern int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm);
89extern int tegra_drm_exit(struct tegra_drm *tegra);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000090
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000091struct tegra_output;
92
93struct tegra_dc {
Thierry Reding776dc382013-10-14 14:43:22 +020094 struct host1x_client client;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000095 struct device *dev;
Thierry Redingd18d3032013-09-26 16:09:19 +020096 spinlock_t lock;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +000097
98 struct drm_crtc base;
99 int pipe;
100
101 struct clk *clk;
Stephen Warrenca480802013-11-06 16:20:54 -0700102 struct reset_control *rst;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000103 void __iomem *regs;
104 int irq;
105
106 struct tegra_output *rgb;
107
108 struct list_head list;
109
110 struct drm_info_list *debugfs_files;
111 struct drm_minor *minor;
112 struct dentry *debugfs;
Thierry Reding3c03c462012-11-28 12:00:18 +0100113
114 /* page-flip handling */
115 struct drm_pending_vblank_event *event;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000116};
117
Thierry Reding53fa7f72013-09-24 15:35:40 +0200118static inline struct tegra_dc *
Thierry Reding776dc382013-10-14 14:43:22 +0200119host1x_client_to_dc(struct host1x_client *client)
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000120{
121 return container_of(client, struct tegra_dc, client);
122}
123
124static inline struct tegra_dc *to_tegra_dc(struct drm_crtc *crtc)
125{
Thierry Reding37826512013-11-08 12:30:37 +0100126 return crtc ? container_of(crtc, struct tegra_dc, base) : NULL;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000127}
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];
Thierry Redingdb7fbdf2013-10-07 09:47:58 +0200158 bool bottom_up;
Thierry Reding773af772013-10-04 22:34:01 +0200159 bool tiled;
Thierry Redingf34bc782012-11-04 21:47:13 +0100160};
161
162/* from dc.c */
163extern unsigned int tegra_dc_format(uint32_t format);
164extern int tegra_dc_setup_window(struct tegra_dc *dc, unsigned int index,
165 const struct tegra_dc_window *window);
Thierry Reding6e5ff992012-11-28 11:45:47 +0100166extern void tegra_dc_enable_vblank(struct tegra_dc *dc);
167extern void tegra_dc_disable_vblank(struct tegra_dc *dc);
Thierry Reding3c03c462012-11-28 12:00:18 +0100168extern void tegra_dc_cancel_page_flip(struct drm_crtc *crtc,
169 struct drm_file *file);
Thierry Redingf34bc782012-11-04 21:47:13 +0100170
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000171struct tegra_output_ops {
172 int (*enable)(struct tegra_output *output);
173 int (*disable)(struct tegra_output *output);
174 int (*setup_clock)(struct tegra_output *output, struct clk *clk,
175 unsigned long pclk);
176 int (*check_mode)(struct tegra_output *output,
177 struct drm_display_mode *mode,
178 enum drm_mode_status *status);
179};
180
181enum tegra_output_type {
182 TEGRA_OUTPUT_RGB,
Thierry Redingedec4af2012-11-15 21:28:23 +0000183 TEGRA_OUTPUT_HDMI,
Thierry Redingdec72732013-09-03 08:45:46 +0200184 TEGRA_OUTPUT_DSI,
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
Thierry Reding9be7d862013-08-30 15:22:36 +0200194 struct drm_panel *panel;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000195 struct i2c_adapter *ddc;
196 const struct edid *edid;
197 unsigned int hpd_irq;
198 int hpd_gpio;
199
200 struct drm_encoder encoder;
201 struct drm_connector connector;
202};
203
204static inline struct tegra_output *encoder_to_output(struct drm_encoder *e)
205{
206 return container_of(e, struct tegra_output, encoder);
207}
208
209static inline struct tegra_output *connector_to_output(struct drm_connector *c)
210{
211 return container_of(c, struct tegra_output, connector);
212}
213
214static inline int tegra_output_enable(struct tegra_output *output)
215{
216 if (output && output->ops && output->ops->enable)
217 return output->ops->enable(output);
218
219 return output ? -ENOSYS : -EINVAL;
220}
221
222static inline int tegra_output_disable(struct tegra_output *output)
223{
224 if (output && output->ops && output->ops->disable)
225 return output->ops->disable(output);
226
227 return output ? -ENOSYS : -EINVAL;
228}
229
230static inline int tegra_output_setup_clock(struct tegra_output *output,
231 struct clk *clk, unsigned long pclk)
232{
233 if (output && output->ops && output->ops->setup_clock)
234 return output->ops->setup_clock(output, clk, pclk);
235
236 return output ? -ENOSYS : -EINVAL;
237}
238
239static inline int tegra_output_check_mode(struct tegra_output *output,
240 struct drm_display_mode *mode,
241 enum drm_mode_status *status)
242{
243 if (output && output->ops && output->ops->check_mode)
244 return output->ops->check_mode(output, mode, status);
245
246 return output ? -ENOSYS : -EINVAL;
247}
248
Thierry Reding776dc382013-10-14 14:43:22 +0200249/* from bus.c */
250int drm_host1x_init(struct drm_driver *driver, struct host1x_device *device);
251void drm_host1x_exit(struct drm_driver *driver, struct host1x_device *device);
252
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000253/* from rgb.c */
254extern int tegra_dc_rgb_probe(struct tegra_dc *dc);
Thierry Reding59d29c02013-10-14 14:26:42 +0200255extern int tegra_dc_rgb_remove(struct tegra_dc *dc);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000256extern int tegra_dc_rgb_init(struct drm_device *drm, struct tegra_dc *dc);
257extern int tegra_dc_rgb_exit(struct tegra_dc *dc);
258
259/* from output.c */
Thierry Reding59d29c02013-10-14 14:26:42 +0200260extern int tegra_output_probe(struct tegra_output *output);
261extern int tegra_output_remove(struct tegra_output *output);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000262extern int tegra_output_init(struct drm_device *drm, struct tegra_output *output);
263extern int tegra_output_exit(struct tegra_output *output);
264
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000265/* from fb.c */
Arto Merilainende2ba662013-03-22 16:34:08 +0200266struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer,
267 unsigned int index);
Thierry Redingdb7fbdf2013-10-07 09:47:58 +0200268bool tegra_fb_is_bottom_up(struct drm_framebuffer *framebuffer);
Thierry Reding773af772013-10-04 22:34:01 +0200269bool tegra_fb_is_tiled(struct drm_framebuffer *framebuffer);
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000270extern int tegra_drm_fb_init(struct drm_device *drm);
271extern void tegra_drm_fb_exit(struct drm_device *drm);
Thierry Reding60c2f702013-10-31 13:28:50 +0100272#ifdef CONFIG_DRM_TEGRA_FBDEV
Arto Merilainende2ba662013-03-22 16:34:08 +0200273extern void tegra_fbdev_restore_mode(struct tegra_fbdev *fbdev);
Thierry Reding60c2f702013-10-31 13:28:50 +0100274#endif
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000275
Thierry Reding776dc382013-10-14 14:43:22 +0200276extern struct platform_driver tegra_dc_driver;
Thierry Redingdec72732013-09-03 08:45:46 +0200277extern struct platform_driver tegra_dsi_driver;
Thierry Reding776dc382013-10-14 14:43:22 +0200278extern struct platform_driver tegra_hdmi_driver;
279extern struct platform_driver tegra_gr2d_driver;
Thierry Reding5f60ed02013-02-28 08:08:01 +0100280extern struct platform_driver tegra_gr3d_driver;
Thierry Redingd8f4a9e2012-11-15 21:28:22 +0000281
Terje Bergstrom4231c6b2013-03-22 16:34:05 +0200282#endif /* HOST1X_DRM_H */