[go: nahoru, domu]

drm.h revision 83c0bcb694be31dcd6c04bdd935b96a95a0af548
1/*
2 * Copyright (C) 2012 Avionic Design GmbH
3 * Copyright (C) 2012 NVIDIA CORPORATION.  All rights reserved.
4 *
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
10#ifndef TEGRA_DRM_H
11#define TEGRA_DRM_H 1
12
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>
17#include <drm/drm_gem_cma_helper.h>
18#include <drm/drm_fb_cma_helper.h>
19#include <drm/drm_fixed.h>
20
21struct tegra_framebuffer {
22	struct drm_framebuffer base;
23	struct drm_gem_cma_object *obj;
24};
25
26static inline struct tegra_framebuffer *to_tegra_fb(struct drm_framebuffer *fb)
27{
28	return container_of(fb, struct tegra_framebuffer, base);
29}
30
31struct host1x {
32	struct drm_device *drm;
33	struct device *dev;
34	void __iomem *regs;
35	struct clk *clk;
36	int syncpt;
37	int irq;
38
39	struct mutex drm_clients_lock;
40	struct list_head drm_clients;
41	struct list_head drm_active;
42
43	struct mutex clients_lock;
44	struct list_head clients;
45
46	struct drm_fbdev_cma *fbdev;
47	struct tegra_framebuffer fb;
48};
49
50struct host1x_client;
51
52struct host1x_client_ops {
53	int (*drm_init)(struct host1x_client *client, struct drm_device *drm);
54	int (*drm_exit)(struct host1x_client *client);
55};
56
57struct host1x_client {
58	struct host1x *host1x;
59	struct device *dev;
60
61	const struct host1x_client_ops *ops;
62
63	struct list_head list;
64};
65
66extern int host1x_drm_init(struct host1x *host1x, struct drm_device *drm);
67extern int host1x_drm_exit(struct host1x *host1x);
68
69extern int host1x_register_client(struct host1x *host1x,
70				  struct host1x_client *client);
71extern int host1x_unregister_client(struct host1x *host1x,
72				    struct host1x_client *client);
73
74struct tegra_output;
75
76struct tegra_dc {
77	struct host1x_client client;
78
79	struct host1x *host1x;
80	struct device *dev;
81
82	struct drm_crtc base;
83	int pipe;
84
85	struct clk *clk;
86
87	struct mutex regs_mutex;
88	void __iomem *regs;
89	int irq;
90
91	struct tegra_output *rgb;
92
93	struct list_head list;
94
95	struct drm_info_list *debugfs_files;
96	struct drm_minor *minor;
97	struct dentry *debugfs;
98};
99
100static inline struct tegra_dc *host1x_client_to_dc(struct host1x_client *client)
101{
102	return container_of(client, struct tegra_dc, client);
103}
104
105static inline struct tegra_dc *to_tegra_dc(struct drm_crtc *crtc)
106{
107	return container_of(crtc, struct tegra_dc, base);
108}
109
110static inline void tegra_dc_writel(struct tegra_dc *dc, unsigned long value,
111				   unsigned long reg)
112{
113	writel(value, dc->regs + (reg << 2));
114}
115
116static inline unsigned long tegra_dc_readl(struct tegra_dc *dc,
117					   unsigned long reg)
118{
119	return readl(dc->regs + (reg << 2));
120}
121
122struct tegra_output_ops {
123	int (*enable)(struct tegra_output *output);
124	int (*disable)(struct tegra_output *output);
125	int (*setup_clock)(struct tegra_output *output, struct clk *clk,
126			   unsigned long pclk);
127	int (*check_mode)(struct tegra_output *output,
128			  struct drm_display_mode *mode,
129			  enum drm_mode_status *status);
130};
131
132enum tegra_output_type {
133	TEGRA_OUTPUT_RGB,
134	TEGRA_OUTPUT_HDMI,
135};
136
137struct tegra_output {
138	struct device_node *of_node;
139	struct device *dev;
140
141	const struct tegra_output_ops *ops;
142	enum tegra_output_type type;
143
144	struct i2c_adapter *ddc;
145	const struct edid *edid;
146	unsigned int hpd_irq;
147	int hpd_gpio;
148
149	struct drm_encoder encoder;
150	struct drm_connector connector;
151};
152
153static inline struct tegra_output *encoder_to_output(struct drm_encoder *e)
154{
155	return container_of(e, struct tegra_output, encoder);
156}
157
158static inline struct tegra_output *connector_to_output(struct drm_connector *c)
159{
160	return container_of(c, struct tegra_output, connector);
161}
162
163static inline int tegra_output_enable(struct tegra_output *output)
164{
165	if (output && output->ops && output->ops->enable)
166		return output->ops->enable(output);
167
168	return output ? -ENOSYS : -EINVAL;
169}
170
171static inline int tegra_output_disable(struct tegra_output *output)
172{
173	if (output && output->ops && output->ops->disable)
174		return output->ops->disable(output);
175
176	return output ? -ENOSYS : -EINVAL;
177}
178
179static inline int tegra_output_setup_clock(struct tegra_output *output,
180					   struct clk *clk, unsigned long pclk)
181{
182	if (output && output->ops && output->ops->setup_clock)
183		return output->ops->setup_clock(output, clk, pclk);
184
185	return output ? -ENOSYS : -EINVAL;
186}
187
188static inline int tegra_output_check_mode(struct tegra_output *output,
189					  struct drm_display_mode *mode,
190					  enum drm_mode_status *status)
191{
192	if (output && output->ops && output->ops->check_mode)
193		return output->ops->check_mode(output, mode, status);
194
195	return output ? -ENOSYS : -EINVAL;
196}
197
198/* from rgb.c */
199extern int tegra_dc_rgb_probe(struct tegra_dc *dc);
200extern int tegra_dc_rgb_init(struct drm_device *drm, struct tegra_dc *dc);
201extern int tegra_dc_rgb_exit(struct tegra_dc *dc);
202
203/* from output.c */
204extern int tegra_output_parse_dt(struct tegra_output *output);
205extern int tegra_output_init(struct drm_device *drm, struct tegra_output *output);
206extern int tegra_output_exit(struct tegra_output *output);
207
208/* from gem.c */
209extern struct tegra_gem_object *tegra_gem_alloc(struct drm_device *drm,
210						size_t size);
211extern int tegra_gem_handle_create(struct drm_device *drm,
212				   struct drm_file *file, size_t size,
213				   unsigned long flags, uint32_t *handle);
214extern int tegra_gem_dumb_create(struct drm_file *file, struct drm_device *drm,
215				 struct drm_mode_create_dumb *args);
216extern int tegra_gem_dumb_map_offset(struct drm_file *file,
217				     struct drm_device *drm, uint32_t handle,
218				     uint64_t *offset);
219extern int tegra_gem_dumb_destroy(struct drm_file *file,
220				  struct drm_device *drm, uint32_t handle);
221extern int tegra_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
222extern int tegra_gem_init_object(struct drm_gem_object *obj);
223extern void tegra_gem_free_object(struct drm_gem_object *obj);
224extern struct vm_operations_struct tegra_gem_vm_ops;
225
226/* from fb.c */
227extern int tegra_drm_fb_init(struct drm_device *drm);
228extern void tegra_drm_fb_exit(struct drm_device *drm);
229
230extern struct platform_driver tegra_host1x_driver;
231extern struct platform_driver tegra_hdmi_driver;
232extern struct platform_driver tegra_dc_driver;
233extern struct drm_driver tegra_drm_driver;
234
235#endif /* TEGRA_DRM_H */
236