xref: /linux/drivers/gpu/drm/tegra/drm.h (revision ca915b108a39081edff1206ec00ecdb4136408ac)
1dee8268fSThierry Reding /*
2dee8268fSThierry Reding  * Copyright (C) 2012 Avionic Design GmbH
3dee8268fSThierry Reding  * Copyright (C) 2012-2013 NVIDIA CORPORATION.  All rights reserved.
4dee8268fSThierry Reding  *
5dee8268fSThierry Reding  * This program is free software; you can redistribute it and/or modify
6dee8268fSThierry Reding  * it under the terms of the GNU General Public License version 2 as
7dee8268fSThierry Reding  * published by the Free Software Foundation.
8dee8268fSThierry Reding  */
9dee8268fSThierry Reding 
10dee8268fSThierry Reding #ifndef HOST1X_DRM_H
11dee8268fSThierry Reding #define HOST1X_DRM_H 1
12dee8268fSThierry Reding 
13dee8268fSThierry Reding #include <uapi/drm/tegra_drm.h>
14dee8268fSThierry Reding #include <linux/host1x.h>
15dee8268fSThierry Reding 
16dee8268fSThierry Reding #include <drm/drmP.h>
17dee8268fSThierry Reding #include <drm/drm_crtc_helper.h>
18dee8268fSThierry Reding #include <drm/drm_edid.h>
19dee8268fSThierry Reding #include <drm/drm_fb_helper.h>
20dee8268fSThierry Reding #include <drm/drm_fixed.h>
21dee8268fSThierry Reding 
22c134f019SThierry Reding #include "gem.h"
23c134f019SThierry Reding 
24ca48080aSStephen Warren struct reset_control;
25ca48080aSStephen Warren 
26dee8268fSThierry Reding struct tegra_fb {
27dee8268fSThierry Reding 	struct drm_framebuffer base;
28dee8268fSThierry Reding 	struct tegra_bo **planes;
29dee8268fSThierry Reding 	unsigned int num_planes;
30dee8268fSThierry Reding };
31dee8268fSThierry Reding 
3260c2f709SThierry Reding #ifdef CONFIG_DRM_TEGRA_FBDEV
33dee8268fSThierry Reding struct tegra_fbdev {
34dee8268fSThierry Reding 	struct drm_fb_helper base;
35dee8268fSThierry Reding 	struct tegra_fb *fb;
36dee8268fSThierry Reding };
3760c2f709SThierry Reding #endif
38dee8268fSThierry Reding 
39dee8268fSThierry Reding struct tegra_drm {
40dee8268fSThierry Reding 	struct drm_device *drm;
41dee8268fSThierry Reding 
42df06b759SThierry Reding 	struct iommu_domain *domain;
43df06b759SThierry Reding 	struct drm_mm mm;
44df06b759SThierry Reding 
45dee8268fSThierry Reding 	struct mutex clients_lock;
46dee8268fSThierry Reding 	struct list_head clients;
47dee8268fSThierry Reding 
4860c2f709SThierry Reding #ifdef CONFIG_DRM_TEGRA_FBDEV
49dee8268fSThierry Reding 	struct tegra_fbdev *fbdev;
5060c2f709SThierry Reding #endif
51d1f3e1e0SThierry Reding 
52d1f3e1e0SThierry Reding 	unsigned int pitch_align;
53dee8268fSThierry Reding };
54dee8268fSThierry Reding 
55dee8268fSThierry Reding struct tegra_drm_client;
56dee8268fSThierry Reding 
57dee8268fSThierry Reding struct tegra_drm_context {
58dee8268fSThierry Reding 	struct tegra_drm_client *client;
59dee8268fSThierry Reding 	struct host1x_channel *channel;
60dee8268fSThierry Reding 	struct list_head list;
61dee8268fSThierry Reding };
62dee8268fSThierry Reding 
63dee8268fSThierry Reding struct tegra_drm_client_ops {
64dee8268fSThierry Reding 	int (*open_channel)(struct tegra_drm_client *client,
65dee8268fSThierry Reding 			    struct tegra_drm_context *context);
66dee8268fSThierry Reding 	void (*close_channel)(struct tegra_drm_context *context);
67c40f0f1aSThierry Reding 	int (*is_addr_reg)(struct device *dev, u32 class, u32 offset);
68dee8268fSThierry Reding 	int (*submit)(struct tegra_drm_context *context,
69dee8268fSThierry Reding 		      struct drm_tegra_submit *args, struct drm_device *drm,
70dee8268fSThierry Reding 		      struct drm_file *file);
71dee8268fSThierry Reding };
72dee8268fSThierry Reding 
73c40f0f1aSThierry Reding int tegra_drm_submit(struct tegra_drm_context *context,
74c40f0f1aSThierry Reding 		     struct drm_tegra_submit *args, struct drm_device *drm,
75c40f0f1aSThierry Reding 		     struct drm_file *file);
76c40f0f1aSThierry Reding 
77dee8268fSThierry Reding struct tegra_drm_client {
78dee8268fSThierry Reding 	struct host1x_client base;
79dee8268fSThierry Reding 	struct list_head list;
80dee8268fSThierry Reding 
81dee8268fSThierry Reding 	const struct tegra_drm_client_ops *ops;
82dee8268fSThierry Reding };
83dee8268fSThierry Reding 
84dee8268fSThierry Reding static inline struct tegra_drm_client *
85dee8268fSThierry Reding host1x_to_drm_client(struct host1x_client *client)
86dee8268fSThierry Reding {
87dee8268fSThierry Reding 	return container_of(client, struct tegra_drm_client, base);
88dee8268fSThierry Reding }
89dee8268fSThierry Reding 
90688c59afSThierry Reding int tegra_drm_register_client(struct tegra_drm *tegra,
91dee8268fSThierry Reding 			      struct tegra_drm_client *client);
92688c59afSThierry Reding int tegra_drm_unregister_client(struct tegra_drm *tegra,
93dee8268fSThierry Reding 				struct tegra_drm_client *client);
94dee8268fSThierry Reding 
95688c59afSThierry Reding int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm);
96688c59afSThierry Reding int tegra_drm_exit(struct tegra_drm *tegra);
97dee8268fSThierry Reding 
988620fc62SThierry Reding struct tegra_dc_soc_info;
99dee8268fSThierry Reding struct tegra_output;
100dee8268fSThierry Reding 
101dee8268fSThierry Reding struct tegra_dc {
102dee8268fSThierry Reding 	struct host1x_client client;
103dee8268fSThierry Reding 	struct device *dev;
104dee8268fSThierry Reding 	spinlock_t lock;
105dee8268fSThierry Reding 
106dee8268fSThierry Reding 	struct drm_crtc base;
1079c012700SThierry Reding 	int powergate;
108dee8268fSThierry Reding 	int pipe;
109dee8268fSThierry Reding 
110dee8268fSThierry Reding 	struct clk *clk;
111ca48080aSStephen Warren 	struct reset_control *rst;
112dee8268fSThierry Reding 	void __iomem *regs;
113dee8268fSThierry Reding 	int irq;
114dee8268fSThierry Reding 
115dee8268fSThierry Reding 	struct tegra_output *rgb;
116dee8268fSThierry Reding 
117dee8268fSThierry Reding 	struct list_head list;
118dee8268fSThierry Reding 
119dee8268fSThierry Reding 	struct drm_info_list *debugfs_files;
120dee8268fSThierry Reding 	struct drm_minor *minor;
121dee8268fSThierry Reding 	struct dentry *debugfs;
122dee8268fSThierry Reding 
123dee8268fSThierry Reding 	/* page-flip handling */
124dee8268fSThierry Reding 	struct drm_pending_vblank_event *event;
1258620fc62SThierry Reding 
1268620fc62SThierry Reding 	const struct tegra_dc_soc_info *soc;
127df06b759SThierry Reding 
128df06b759SThierry Reding 	struct iommu_domain *domain;
129dee8268fSThierry Reding };
130dee8268fSThierry Reding 
131dee8268fSThierry Reding static inline struct tegra_dc *
132dee8268fSThierry Reding host1x_client_to_dc(struct host1x_client *client)
133dee8268fSThierry Reding {
134dee8268fSThierry Reding 	return container_of(client, struct tegra_dc, client);
135dee8268fSThierry Reding }
136dee8268fSThierry Reding 
137dee8268fSThierry Reding static inline struct tegra_dc *to_tegra_dc(struct drm_crtc *crtc)
138dee8268fSThierry Reding {
13937826519SThierry Reding 	return crtc ? container_of(crtc, struct tegra_dc, base) : NULL;
140dee8268fSThierry Reding }
141dee8268fSThierry Reding 
14203a60569SThierry Reding static inline void tegra_dc_writel(struct tegra_dc *dc, u32 value,
14303a60569SThierry Reding 				   unsigned long offset)
144dee8268fSThierry Reding {
14503a60569SThierry Reding 	writel(value, dc->regs + (offset << 2));
146dee8268fSThierry Reding }
147dee8268fSThierry Reding 
14803a60569SThierry Reding static inline u32 tegra_dc_readl(struct tegra_dc *dc, unsigned long offset)
149dee8268fSThierry Reding {
15003a60569SThierry Reding 	return readl(dc->regs + (offset << 2));
151dee8268fSThierry Reding }
152dee8268fSThierry Reding 
153dee8268fSThierry Reding struct tegra_dc_window {
154dee8268fSThierry Reding 	struct {
155dee8268fSThierry Reding 		unsigned int x;
156dee8268fSThierry Reding 		unsigned int y;
157dee8268fSThierry Reding 		unsigned int w;
158dee8268fSThierry Reding 		unsigned int h;
159dee8268fSThierry Reding 	} src;
160dee8268fSThierry Reding 	struct {
161dee8268fSThierry Reding 		unsigned int x;
162dee8268fSThierry Reding 		unsigned int y;
163dee8268fSThierry Reding 		unsigned int w;
164dee8268fSThierry Reding 		unsigned int h;
165dee8268fSThierry Reding 	} dst;
166dee8268fSThierry Reding 	unsigned int bits_per_pixel;
167dee8268fSThierry Reding 	unsigned int format;
168f925390eSThierry Reding 	unsigned int swap;
169dee8268fSThierry Reding 	unsigned int stride[2];
170dee8268fSThierry Reding 	unsigned long base[3];
171db7fbdfdSThierry Reding 	bool bottom_up;
172c134f019SThierry Reding 
173c134f019SThierry Reding 	struct tegra_bo_tiling tiling;
174dee8268fSThierry Reding };
175dee8268fSThierry Reding 
176dee8268fSThierry Reding /* from dc.c */
177688c59afSThierry Reding void tegra_dc_enable_vblank(struct tegra_dc *dc);
178688c59afSThierry Reding void tegra_dc_disable_vblank(struct tegra_dc *dc);
179688c59afSThierry Reding void tegra_dc_cancel_page_flip(struct drm_crtc *crtc, struct drm_file *file);
18062b9e063SThierry Reding void tegra_dc_commit(struct tegra_dc *dc);
181c5a107d3SThierry Reding int tegra_dc_setup_clock(struct tegra_dc *dc, struct clk *parent,
182c5a107d3SThierry Reding 			 unsigned long pclk, unsigned int div);
183*ca915b10SThierry Reding int tegra_dc_state_setup_clock(struct tegra_dc *dc,
184*ca915b10SThierry Reding 			       struct drm_crtc_state *crtc_state,
185*ca915b10SThierry Reding 			       struct clk *clk, unsigned long pclk,
186*ca915b10SThierry Reding 			       unsigned int div);
187dee8268fSThierry Reding 
188dee8268fSThierry Reding struct tegra_output {
189dee8268fSThierry Reding 	struct device_node *of_node;
190dee8268fSThierry Reding 	struct device *dev;
191dee8268fSThierry Reding 
1929be7d864SThierry Reding 	struct drm_panel *panel;
193dee8268fSThierry Reding 	struct i2c_adapter *ddc;
194dee8268fSThierry Reding 	const struct edid *edid;
195dee8268fSThierry Reding 	unsigned int hpd_irq;
196dee8268fSThierry Reding 	int hpd_gpio;
197dee8268fSThierry Reding 
198dee8268fSThierry Reding 	struct drm_encoder encoder;
199dee8268fSThierry Reding 	struct drm_connector connector;
200dee8268fSThierry Reding };
201dee8268fSThierry Reding 
202dee8268fSThierry Reding static inline struct tegra_output *encoder_to_output(struct drm_encoder *e)
203dee8268fSThierry Reding {
204dee8268fSThierry Reding 	return container_of(e, struct tegra_output, encoder);
205dee8268fSThierry Reding }
206dee8268fSThierry Reding 
207dee8268fSThierry Reding static inline struct tegra_output *connector_to_output(struct drm_connector *c)
208dee8268fSThierry Reding {
209dee8268fSThierry Reding 	return container_of(c, struct tegra_output, connector);
210dee8268fSThierry Reding }
211dee8268fSThierry Reding 
212dee8268fSThierry Reding /* from rgb.c */
213688c59afSThierry Reding int tegra_dc_rgb_probe(struct tegra_dc *dc);
214688c59afSThierry Reding int tegra_dc_rgb_remove(struct tegra_dc *dc);
215688c59afSThierry Reding int tegra_dc_rgb_init(struct drm_device *drm, struct tegra_dc *dc);
216688c59afSThierry Reding int tegra_dc_rgb_exit(struct tegra_dc *dc);
217dee8268fSThierry Reding 
218dee8268fSThierry Reding /* from output.c */
219688c59afSThierry Reding int tegra_output_probe(struct tegra_output *output);
220328ec69eSThierry Reding void tegra_output_remove(struct tegra_output *output);
221688c59afSThierry Reding int tegra_output_init(struct drm_device *drm, struct tegra_output *output);
222328ec69eSThierry Reding void tegra_output_exit(struct tegra_output *output);
223dee8268fSThierry Reding 
224132085d8SThierry Reding int tegra_output_connector_get_modes(struct drm_connector *connector);
225132085d8SThierry Reding struct drm_encoder *
226132085d8SThierry Reding tegra_output_connector_best_encoder(struct drm_connector *connector);
227132085d8SThierry Reding enum drm_connector_status
228132085d8SThierry Reding tegra_output_connector_detect(struct drm_connector *connector, bool force);
229132085d8SThierry Reding void tegra_output_connector_destroy(struct drm_connector *connector);
230132085d8SThierry Reding 
231132085d8SThierry Reding void tegra_output_encoder_destroy(struct drm_encoder *encoder);
232132085d8SThierry Reding 
2336b6b6042SThierry Reding /* from dpaux.c */
2346b6b6042SThierry Reding struct tegra_dpaux;
2356b6b6042SThierry Reding struct drm_dp_link;
2366b6b6042SThierry Reding 
2376b6b6042SThierry Reding struct tegra_dpaux *tegra_dpaux_find_by_of_node(struct device_node *np);
2386b6b6042SThierry Reding enum drm_connector_status tegra_dpaux_detect(struct tegra_dpaux *dpaux);
2396b6b6042SThierry Reding int tegra_dpaux_attach(struct tegra_dpaux *dpaux, struct tegra_output *output);
2406b6b6042SThierry Reding int tegra_dpaux_detach(struct tegra_dpaux *dpaux);
2416b6b6042SThierry Reding int tegra_dpaux_enable(struct tegra_dpaux *dpaux);
2426b6b6042SThierry Reding int tegra_dpaux_disable(struct tegra_dpaux *dpaux);
2436b6b6042SThierry Reding int tegra_dpaux_prepare(struct tegra_dpaux *dpaux, u8 encoding);
2446b6b6042SThierry Reding int tegra_dpaux_train(struct tegra_dpaux *dpaux, struct drm_dp_link *link,
2456b6b6042SThierry Reding 		      u8 pattern);
2466b6b6042SThierry Reding 
247dee8268fSThierry Reding /* from fb.c */
248dee8268fSThierry Reding struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer,
249dee8268fSThierry Reding 				    unsigned int index);
250db7fbdfdSThierry Reding bool tegra_fb_is_bottom_up(struct drm_framebuffer *framebuffer);
251c134f019SThierry Reding int tegra_fb_get_tiling(struct drm_framebuffer *framebuffer,
252c134f019SThierry Reding 			struct tegra_bo_tiling *tiling);
253f9914214SThierry Reding struct drm_framebuffer *tegra_fb_create(struct drm_device *drm,
254f9914214SThierry Reding 					struct drm_file *file,
255f9914214SThierry Reding 					struct drm_mode_fb_cmd2 *cmd);
256e2215321SThierry Reding int tegra_drm_fb_prepare(struct drm_device *drm);
2571d1e6fe9SThierry Reding void tegra_drm_fb_free(struct drm_device *drm);
258688c59afSThierry Reding int tegra_drm_fb_init(struct drm_device *drm);
259688c59afSThierry Reding void tegra_drm_fb_exit(struct drm_device *drm);
26060c2f709SThierry Reding #ifdef CONFIG_DRM_TEGRA_FBDEV
261688c59afSThierry Reding void tegra_fbdev_restore_mode(struct tegra_fbdev *fbdev);
262f9914214SThierry Reding void tegra_fb_output_poll_changed(struct drm_device *drm);
26360c2f709SThierry Reding #endif
264dee8268fSThierry Reding 
265dee8268fSThierry Reding extern struct platform_driver tegra_dc_driver;
266dec72739SThierry Reding extern struct platform_driver tegra_dsi_driver;
2676b6b6042SThierry Reding extern struct platform_driver tegra_sor_driver;
268dee8268fSThierry Reding extern struct platform_driver tegra_hdmi_driver;
2696b6b6042SThierry Reding extern struct platform_driver tegra_dpaux_driver;
270dee8268fSThierry Reding extern struct platform_driver tegra_gr2d_driver;
2715f60ed0dSThierry Reding extern struct platform_driver tegra_gr3d_driver;
272dee8268fSThierry Reding 
273dee8268fSThierry Reding #endif /* HOST1X_DRM_H */
274