xref: /linux/drivers/gpu/drm/tegra/drm.h (revision 986c58d1625df222c6148c1dc72e59fbf96ef75e)
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>
15fb36d0eeSThierry Reding #include <linux/of_gpio.h>
16dee8268fSThierry Reding 
17dee8268fSThierry Reding #include <drm/drmP.h>
18dee8268fSThierry Reding #include <drm/drm_crtc_helper.h>
19dee8268fSThierry Reding #include <drm/drm_edid.h>
20dee8268fSThierry Reding #include <drm/drm_fb_helper.h>
21dee8268fSThierry Reding #include <drm/drm_fixed.h>
22dee8268fSThierry Reding 
23c134f019SThierry Reding #include "gem.h"
24c134f019SThierry Reding 
25ca48080aSStephen Warren struct reset_control;
26ca48080aSStephen Warren 
27dee8268fSThierry Reding struct tegra_fb {
28dee8268fSThierry Reding 	struct drm_framebuffer base;
29dee8268fSThierry Reding 	struct tegra_bo **planes;
30dee8268fSThierry Reding 	unsigned int num_planes;
31dee8268fSThierry Reding };
32dee8268fSThierry Reding 
33b110ef37SArchit Taneja #ifdef CONFIG_DRM_FBDEV_EMULATION
34dee8268fSThierry Reding struct tegra_fbdev {
35dee8268fSThierry Reding 	struct drm_fb_helper base;
36dee8268fSThierry Reding 	struct tegra_fb *fb;
37dee8268fSThierry Reding };
3860c2f709SThierry Reding #endif
39dee8268fSThierry Reding 
40dee8268fSThierry Reding struct tegra_drm {
41dee8268fSThierry Reding 	struct drm_device *drm;
42dee8268fSThierry Reding 
43df06b759SThierry Reding 	struct iommu_domain *domain;
44df06b759SThierry Reding 	struct drm_mm mm;
45df06b759SThierry Reding 
46dee8268fSThierry Reding 	struct mutex clients_lock;
47dee8268fSThierry Reding 	struct list_head clients;
48dee8268fSThierry Reding 
49b110ef37SArchit Taneja #ifdef CONFIG_DRM_FBDEV_EMULATION
50dee8268fSThierry Reding 	struct tegra_fbdev *fbdev;
5160c2f709SThierry Reding #endif
52d1f3e1e0SThierry Reding 
53d1f3e1e0SThierry Reding 	unsigned int pitch_align;
541503ca47SThierry Reding 
551503ca47SThierry Reding 	struct {
561503ca47SThierry Reding 		struct drm_atomic_state *state;
571503ca47SThierry Reding 		struct work_struct work;
581503ca47SThierry Reding 		struct mutex lock;
591503ca47SThierry Reding 	} commit;
60*986c58d1SThierry Reding 
61*986c58d1SThierry Reding 	struct drm_atomic_state *state;
62dee8268fSThierry Reding };
63dee8268fSThierry Reding 
64dee8268fSThierry Reding struct tegra_drm_client;
65dee8268fSThierry Reding 
66dee8268fSThierry Reding struct tegra_drm_context {
67dee8268fSThierry Reding 	struct tegra_drm_client *client;
68dee8268fSThierry Reding 	struct host1x_channel *channel;
69dee8268fSThierry Reding 	struct list_head list;
70dee8268fSThierry Reding };
71dee8268fSThierry Reding 
72dee8268fSThierry Reding struct tegra_drm_client_ops {
73dee8268fSThierry Reding 	int (*open_channel)(struct tegra_drm_client *client,
74dee8268fSThierry Reding 			    struct tegra_drm_context *context);
75dee8268fSThierry Reding 	void (*close_channel)(struct tegra_drm_context *context);
76c40f0f1aSThierry Reding 	int (*is_addr_reg)(struct device *dev, u32 class, u32 offset);
77dee8268fSThierry Reding 	int (*submit)(struct tegra_drm_context *context,
78dee8268fSThierry Reding 		      struct drm_tegra_submit *args, struct drm_device *drm,
79dee8268fSThierry Reding 		      struct drm_file *file);
80dee8268fSThierry Reding };
81dee8268fSThierry Reding 
82c40f0f1aSThierry Reding int tegra_drm_submit(struct tegra_drm_context *context,
83c40f0f1aSThierry Reding 		     struct drm_tegra_submit *args, struct drm_device *drm,
84c40f0f1aSThierry Reding 		     struct drm_file *file);
85c40f0f1aSThierry Reding 
86dee8268fSThierry Reding struct tegra_drm_client {
87dee8268fSThierry Reding 	struct host1x_client base;
88dee8268fSThierry Reding 	struct list_head list;
89dee8268fSThierry Reding 
90dee8268fSThierry Reding 	const struct tegra_drm_client_ops *ops;
91dee8268fSThierry Reding };
92dee8268fSThierry Reding 
93dee8268fSThierry Reding static inline struct tegra_drm_client *
94dee8268fSThierry Reding host1x_to_drm_client(struct host1x_client *client)
95dee8268fSThierry Reding {
96dee8268fSThierry Reding 	return container_of(client, struct tegra_drm_client, base);
97dee8268fSThierry Reding }
98dee8268fSThierry Reding 
99688c59afSThierry Reding int tegra_drm_register_client(struct tegra_drm *tegra,
100dee8268fSThierry Reding 			      struct tegra_drm_client *client);
101688c59afSThierry Reding int tegra_drm_unregister_client(struct tegra_drm *tegra,
102dee8268fSThierry Reding 				struct tegra_drm_client *client);
103dee8268fSThierry Reding 
104688c59afSThierry Reding int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm);
105688c59afSThierry Reding int tegra_drm_exit(struct tegra_drm *tegra);
106dee8268fSThierry Reding 
1078620fc62SThierry Reding struct tegra_dc_soc_info;
108dee8268fSThierry Reding struct tegra_output;
109dee8268fSThierry Reding 
110791ddb1eSThierry Reding struct tegra_dc_stats {
111791ddb1eSThierry Reding 	unsigned long frames;
112791ddb1eSThierry Reding 	unsigned long vblank;
113791ddb1eSThierry Reding 	unsigned long underflow;
114791ddb1eSThierry Reding 	unsigned long overflow;
115791ddb1eSThierry Reding };
116791ddb1eSThierry Reding 
117dee8268fSThierry Reding struct tegra_dc {
118dee8268fSThierry Reding 	struct host1x_client client;
11942e9ce05SThierry Reding 	struct host1x_syncpt *syncpt;
120dee8268fSThierry Reding 	struct device *dev;
121dee8268fSThierry Reding 	spinlock_t lock;
122dee8268fSThierry Reding 
123dee8268fSThierry Reding 	struct drm_crtc base;
1249c012700SThierry Reding 	int powergate;
125dee8268fSThierry Reding 	int pipe;
126dee8268fSThierry Reding 
127dee8268fSThierry Reding 	struct clk *clk;
128ca48080aSStephen Warren 	struct reset_control *rst;
129dee8268fSThierry Reding 	void __iomem *regs;
130dee8268fSThierry Reding 	int irq;
131dee8268fSThierry Reding 
132dee8268fSThierry Reding 	struct tegra_output *rgb;
133dee8268fSThierry Reding 
134791ddb1eSThierry Reding 	struct tegra_dc_stats stats;
135dee8268fSThierry Reding 	struct list_head list;
136dee8268fSThierry Reding 
137dee8268fSThierry Reding 	struct drm_info_list *debugfs_files;
138dee8268fSThierry Reding 	struct drm_minor *minor;
139dee8268fSThierry Reding 	struct dentry *debugfs;
140dee8268fSThierry Reding 
141dee8268fSThierry Reding 	/* page-flip handling */
142dee8268fSThierry Reding 	struct drm_pending_vblank_event *event;
1438620fc62SThierry Reding 
1448620fc62SThierry Reding 	const struct tegra_dc_soc_info *soc;
145df06b759SThierry Reding 
146df06b759SThierry Reding 	struct iommu_domain *domain;
147dee8268fSThierry Reding };
148dee8268fSThierry Reding 
149dee8268fSThierry Reding static inline struct tegra_dc *
150dee8268fSThierry Reding host1x_client_to_dc(struct host1x_client *client)
151dee8268fSThierry Reding {
152dee8268fSThierry Reding 	return container_of(client, struct tegra_dc, client);
153dee8268fSThierry Reding }
154dee8268fSThierry Reding 
155dee8268fSThierry Reding static inline struct tegra_dc *to_tegra_dc(struct drm_crtc *crtc)
156dee8268fSThierry Reding {
15737826519SThierry Reding 	return crtc ? container_of(crtc, struct tegra_dc, base) : NULL;
158dee8268fSThierry Reding }
159dee8268fSThierry Reding 
16003a60569SThierry Reding static inline void tegra_dc_writel(struct tegra_dc *dc, u32 value,
16103a60569SThierry Reding 				   unsigned long offset)
162dee8268fSThierry Reding {
16303a60569SThierry Reding 	writel(value, dc->regs + (offset << 2));
164dee8268fSThierry Reding }
165dee8268fSThierry Reding 
16603a60569SThierry Reding static inline u32 tegra_dc_readl(struct tegra_dc *dc, unsigned long offset)
167dee8268fSThierry Reding {
16803a60569SThierry Reding 	return readl(dc->regs + (offset << 2));
169dee8268fSThierry Reding }
170dee8268fSThierry Reding 
171dee8268fSThierry Reding struct tegra_dc_window {
172dee8268fSThierry Reding 	struct {
173dee8268fSThierry Reding 		unsigned int x;
174dee8268fSThierry Reding 		unsigned int y;
175dee8268fSThierry Reding 		unsigned int w;
176dee8268fSThierry Reding 		unsigned int h;
177dee8268fSThierry Reding 	} src;
178dee8268fSThierry Reding 	struct {
179dee8268fSThierry Reding 		unsigned int x;
180dee8268fSThierry Reding 		unsigned int y;
181dee8268fSThierry Reding 		unsigned int w;
182dee8268fSThierry Reding 		unsigned int h;
183dee8268fSThierry Reding 	} dst;
184dee8268fSThierry Reding 	unsigned int bits_per_pixel;
185dee8268fSThierry Reding 	unsigned int stride[2];
186dee8268fSThierry Reding 	unsigned long base[3];
187db7fbdfdSThierry Reding 	bool bottom_up;
188c134f019SThierry Reding 
189c134f019SThierry Reding 	struct tegra_bo_tiling tiling;
1908f604f8cSThierry Reding 	u32 format;
1918f604f8cSThierry Reding 	u32 swap;
192dee8268fSThierry Reding };
193dee8268fSThierry Reding 
194dee8268fSThierry Reding /* from dc.c */
19542e9ce05SThierry Reding u32 tegra_dc_get_vblank_counter(struct tegra_dc *dc);
196688c59afSThierry Reding void tegra_dc_enable_vblank(struct tegra_dc *dc);
197688c59afSThierry Reding void tegra_dc_disable_vblank(struct tegra_dc *dc);
198688c59afSThierry Reding void tegra_dc_cancel_page_flip(struct drm_crtc *crtc, struct drm_file *file);
19962b9e063SThierry Reding void tegra_dc_commit(struct tegra_dc *dc);
200ca915b10SThierry Reding int tegra_dc_state_setup_clock(struct tegra_dc *dc,
201ca915b10SThierry Reding 			       struct drm_crtc_state *crtc_state,
202ca915b10SThierry Reding 			       struct clk *clk, unsigned long pclk,
203ca915b10SThierry Reding 			       unsigned int div);
204dee8268fSThierry Reding 
205dee8268fSThierry Reding struct tegra_output {
206dee8268fSThierry Reding 	struct device_node *of_node;
207dee8268fSThierry Reding 	struct device *dev;
208dee8268fSThierry Reding 
2099be7d864SThierry Reding 	struct drm_panel *panel;
210dee8268fSThierry Reding 	struct i2c_adapter *ddc;
211dee8268fSThierry Reding 	const struct edid *edid;
212dee8268fSThierry Reding 	unsigned int hpd_irq;
213dee8268fSThierry Reding 	int hpd_gpio;
214fb36d0eeSThierry Reding 	enum of_gpio_flags hpd_gpio_flags;
215dee8268fSThierry Reding 
216dee8268fSThierry Reding 	struct drm_encoder encoder;
217dee8268fSThierry Reding 	struct drm_connector connector;
218dee8268fSThierry Reding };
219dee8268fSThierry Reding 
220dee8268fSThierry Reding static inline struct tegra_output *encoder_to_output(struct drm_encoder *e)
221dee8268fSThierry Reding {
222dee8268fSThierry Reding 	return container_of(e, struct tegra_output, encoder);
223dee8268fSThierry Reding }
224dee8268fSThierry Reding 
225dee8268fSThierry Reding static inline struct tegra_output *connector_to_output(struct drm_connector *c)
226dee8268fSThierry Reding {
227dee8268fSThierry Reding 	return container_of(c, struct tegra_output, connector);
228dee8268fSThierry Reding }
229dee8268fSThierry Reding 
230dee8268fSThierry Reding /* from rgb.c */
231688c59afSThierry Reding int tegra_dc_rgb_probe(struct tegra_dc *dc);
232688c59afSThierry Reding int tegra_dc_rgb_remove(struct tegra_dc *dc);
233688c59afSThierry Reding int tegra_dc_rgb_init(struct drm_device *drm, struct tegra_dc *dc);
234688c59afSThierry Reding int tegra_dc_rgb_exit(struct tegra_dc *dc);
235dee8268fSThierry Reding 
236dee8268fSThierry Reding /* from output.c */
237688c59afSThierry Reding int tegra_output_probe(struct tegra_output *output);
238328ec69eSThierry Reding void tegra_output_remove(struct tegra_output *output);
239688c59afSThierry Reding int tegra_output_init(struct drm_device *drm, struct tegra_output *output);
240328ec69eSThierry Reding void tegra_output_exit(struct tegra_output *output);
241dee8268fSThierry Reding 
242132085d8SThierry Reding int tegra_output_connector_get_modes(struct drm_connector *connector);
243132085d8SThierry Reding struct drm_encoder *
244132085d8SThierry Reding tegra_output_connector_best_encoder(struct drm_connector *connector);
245132085d8SThierry Reding enum drm_connector_status
246132085d8SThierry Reding tegra_output_connector_detect(struct drm_connector *connector, bool force);
247132085d8SThierry Reding void tegra_output_connector_destroy(struct drm_connector *connector);
248132085d8SThierry Reding 
249132085d8SThierry Reding void tegra_output_encoder_destroy(struct drm_encoder *encoder);
250132085d8SThierry Reding 
2516b6b6042SThierry Reding /* from dpaux.c */
2526b6b6042SThierry Reding struct drm_dp_link;
2536b6b6042SThierry Reding 
2549542c237SThierry Reding struct drm_dp_aux *drm_dp_aux_find_by_of_node(struct device_node *np);
2559542c237SThierry Reding enum drm_connector_status drm_dp_aux_detect(struct drm_dp_aux *aux);
2569542c237SThierry Reding int drm_dp_aux_attach(struct drm_dp_aux *aux, struct tegra_output *output);
2579542c237SThierry Reding int drm_dp_aux_detach(struct drm_dp_aux *aux);
2589542c237SThierry Reding int drm_dp_aux_enable(struct drm_dp_aux *aux);
2599542c237SThierry Reding int drm_dp_aux_disable(struct drm_dp_aux *aux);
2609542c237SThierry Reding int drm_dp_aux_prepare(struct drm_dp_aux *aux, u8 encoding);
2619542c237SThierry Reding int drm_dp_aux_train(struct drm_dp_aux *aux, struct drm_dp_link *link,
2626b6b6042SThierry Reding 		     u8 pattern);
2636b6b6042SThierry Reding 
264dee8268fSThierry Reding /* from fb.c */
265dee8268fSThierry Reding struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer,
266dee8268fSThierry Reding 				    unsigned int index);
267db7fbdfdSThierry Reding bool tegra_fb_is_bottom_up(struct drm_framebuffer *framebuffer);
268c134f019SThierry Reding int tegra_fb_get_tiling(struct drm_framebuffer *framebuffer,
269c134f019SThierry Reding 			struct tegra_bo_tiling *tiling);
270f9914214SThierry Reding struct drm_framebuffer *tegra_fb_create(struct drm_device *drm,
271f9914214SThierry Reding 					struct drm_file *file,
2721eb83451SVille Syrjälä 					const struct drm_mode_fb_cmd2 *cmd);
273e2215321SThierry Reding int tegra_drm_fb_prepare(struct drm_device *drm);
2741d1e6fe9SThierry Reding void tegra_drm_fb_free(struct drm_device *drm);
275688c59afSThierry Reding int tegra_drm_fb_init(struct drm_device *drm);
276688c59afSThierry Reding void tegra_drm_fb_exit(struct drm_device *drm);
277*986c58d1SThierry Reding void tegra_drm_fb_suspend(struct drm_device *drm);
278*986c58d1SThierry Reding void tegra_drm_fb_resume(struct drm_device *drm);
279b110ef37SArchit Taneja #ifdef CONFIG_DRM_FBDEV_EMULATION
280688c59afSThierry Reding void tegra_fbdev_restore_mode(struct tegra_fbdev *fbdev);
281f9914214SThierry Reding void tegra_fb_output_poll_changed(struct drm_device *drm);
28260c2f709SThierry Reding #endif
283dee8268fSThierry Reding 
284dee8268fSThierry Reding extern struct platform_driver tegra_dc_driver;
285dee8268fSThierry Reding extern struct platform_driver tegra_hdmi_driver;
286473112e4SThierry Reding extern struct platform_driver tegra_dsi_driver;
2876b6b6042SThierry Reding extern struct platform_driver tegra_dpaux_driver;
288473112e4SThierry Reding extern struct platform_driver tegra_sor_driver;
289dee8268fSThierry Reding extern struct platform_driver tegra_gr2d_driver;
2905f60ed0dSThierry Reding extern struct platform_driver tegra_gr3d_driver;
291dee8268fSThierry Reding 
292dee8268fSThierry Reding #endif /* HOST1X_DRM_H */
293