xref: /linux/drivers/gpu/drm/tegra/drm.h (revision 9338203c4f03ffe323b67f0b2fa17b9811fa9bb6)
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>
20*9338203cSLaurent Pinchart #include <drm/drm_encoder.h>
21dee8268fSThierry Reding #include <drm/drm_fb_helper.h>
22dee8268fSThierry Reding #include <drm/drm_fixed.h>
23dee8268fSThierry Reding 
24c134f019SThierry Reding #include "gem.h"
25c134f019SThierry Reding 
26ca48080aSStephen Warren struct reset_control;
27ca48080aSStephen Warren 
28dee8268fSThierry Reding struct tegra_fb {
29dee8268fSThierry Reding 	struct drm_framebuffer base;
30dee8268fSThierry Reding 	struct tegra_bo **planes;
31dee8268fSThierry Reding 	unsigned int num_planes;
32dee8268fSThierry Reding };
33dee8268fSThierry Reding 
34b110ef37SArchit Taneja #ifdef CONFIG_DRM_FBDEV_EMULATION
35dee8268fSThierry Reding struct tegra_fbdev {
36dee8268fSThierry Reding 	struct drm_fb_helper base;
37dee8268fSThierry Reding 	struct tegra_fb *fb;
38dee8268fSThierry Reding };
3960c2f709SThierry Reding #endif
40dee8268fSThierry Reding 
41dee8268fSThierry Reding struct tegra_drm {
42dee8268fSThierry Reding 	struct drm_device *drm;
43dee8268fSThierry Reding 
44df06b759SThierry Reding 	struct iommu_domain *domain;
45df06b759SThierry Reding 	struct drm_mm mm;
46df06b759SThierry Reding 
47dee8268fSThierry Reding 	struct mutex clients_lock;
48dee8268fSThierry Reding 	struct list_head clients;
49dee8268fSThierry Reding 
50b110ef37SArchit Taneja #ifdef CONFIG_DRM_FBDEV_EMULATION
51dee8268fSThierry Reding 	struct tegra_fbdev *fbdev;
5260c2f709SThierry Reding #endif
53d1f3e1e0SThierry Reding 
54d1f3e1e0SThierry Reding 	unsigned int pitch_align;
551503ca47SThierry Reding 
561503ca47SThierry Reding 	struct {
571503ca47SThierry Reding 		struct drm_atomic_state *state;
581503ca47SThierry Reding 		struct work_struct work;
591503ca47SThierry Reding 		struct mutex lock;
601503ca47SThierry Reding 	} commit;
61986c58d1SThierry Reding 
62986c58d1SThierry Reding 	struct drm_atomic_state *state;
63dee8268fSThierry Reding };
64dee8268fSThierry Reding 
65dee8268fSThierry Reding struct tegra_drm_client;
66dee8268fSThierry Reding 
67dee8268fSThierry Reding struct tegra_drm_context {
68dee8268fSThierry Reding 	struct tegra_drm_client *client;
69dee8268fSThierry Reding 	struct host1x_channel *channel;
70dee8268fSThierry Reding 	struct list_head list;
71dee8268fSThierry Reding };
72dee8268fSThierry Reding 
73dee8268fSThierry Reding struct tegra_drm_client_ops {
74dee8268fSThierry Reding 	int (*open_channel)(struct tegra_drm_client *client,
75dee8268fSThierry Reding 			    struct tegra_drm_context *context);
76dee8268fSThierry Reding 	void (*close_channel)(struct tegra_drm_context *context);
77c40f0f1aSThierry Reding 	int (*is_addr_reg)(struct device *dev, u32 class, u32 offset);
78dee8268fSThierry Reding 	int (*submit)(struct tegra_drm_context *context,
79dee8268fSThierry Reding 		      struct drm_tegra_submit *args, struct drm_device *drm,
80dee8268fSThierry Reding 		      struct drm_file *file);
81dee8268fSThierry Reding };
82dee8268fSThierry Reding 
83c40f0f1aSThierry Reding int tegra_drm_submit(struct tegra_drm_context *context,
84c40f0f1aSThierry Reding 		     struct drm_tegra_submit *args, struct drm_device *drm,
85c40f0f1aSThierry Reding 		     struct drm_file *file);
86c40f0f1aSThierry Reding 
87dee8268fSThierry Reding struct tegra_drm_client {
88dee8268fSThierry Reding 	struct host1x_client base;
89dee8268fSThierry Reding 	struct list_head list;
90dee8268fSThierry Reding 
91dee8268fSThierry Reding 	const struct tegra_drm_client_ops *ops;
92dee8268fSThierry Reding };
93dee8268fSThierry Reding 
94dee8268fSThierry Reding static inline struct tegra_drm_client *
95dee8268fSThierry Reding host1x_to_drm_client(struct host1x_client *client)
96dee8268fSThierry Reding {
97dee8268fSThierry Reding 	return container_of(client, struct tegra_drm_client, base);
98dee8268fSThierry Reding }
99dee8268fSThierry Reding 
100688c59afSThierry Reding int tegra_drm_register_client(struct tegra_drm *tegra,
101dee8268fSThierry Reding 			      struct tegra_drm_client *client);
102688c59afSThierry Reding int tegra_drm_unregister_client(struct tegra_drm *tegra,
103dee8268fSThierry Reding 				struct tegra_drm_client *client);
104dee8268fSThierry Reding 
105688c59afSThierry Reding int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm);
106688c59afSThierry Reding int tegra_drm_exit(struct tegra_drm *tegra);
107dee8268fSThierry Reding 
1088620fc62SThierry Reding struct tegra_dc_soc_info;
109dee8268fSThierry Reding struct tegra_output;
110dee8268fSThierry Reding 
111791ddb1eSThierry Reding struct tegra_dc_stats {
112791ddb1eSThierry Reding 	unsigned long frames;
113791ddb1eSThierry Reding 	unsigned long vblank;
114791ddb1eSThierry Reding 	unsigned long underflow;
115791ddb1eSThierry Reding 	unsigned long overflow;
116791ddb1eSThierry Reding };
117791ddb1eSThierry Reding 
118dee8268fSThierry Reding struct tegra_dc {
119dee8268fSThierry Reding 	struct host1x_client client;
12042e9ce05SThierry Reding 	struct host1x_syncpt *syncpt;
121dee8268fSThierry Reding 	struct device *dev;
122dee8268fSThierry Reding 	spinlock_t lock;
123dee8268fSThierry Reding 
124dee8268fSThierry Reding 	struct drm_crtc base;
12570293ed0SJon Hunter 	unsigned int powergate;
126dee8268fSThierry Reding 	int pipe;
127dee8268fSThierry Reding 
128dee8268fSThierry Reding 	struct clk *clk;
129ca48080aSStephen Warren 	struct reset_control *rst;
130dee8268fSThierry Reding 	void __iomem *regs;
131dee8268fSThierry Reding 	int irq;
132dee8268fSThierry Reding 
133dee8268fSThierry Reding 	struct tegra_output *rgb;
134dee8268fSThierry Reding 
135791ddb1eSThierry Reding 	struct tegra_dc_stats stats;
136dee8268fSThierry Reding 	struct list_head list;
137dee8268fSThierry Reding 
138dee8268fSThierry Reding 	struct drm_info_list *debugfs_files;
139dee8268fSThierry Reding 	struct drm_minor *minor;
140dee8268fSThierry Reding 	struct dentry *debugfs;
141dee8268fSThierry Reding 
142dee8268fSThierry Reding 	/* page-flip handling */
143dee8268fSThierry Reding 	struct drm_pending_vblank_event *event;
1448620fc62SThierry Reding 
1458620fc62SThierry Reding 	const struct tegra_dc_soc_info *soc;
146df06b759SThierry Reding 
147df06b759SThierry Reding 	struct iommu_domain *domain;
148dee8268fSThierry Reding };
149dee8268fSThierry Reding 
150dee8268fSThierry Reding static inline struct tegra_dc *
151dee8268fSThierry Reding host1x_client_to_dc(struct host1x_client *client)
152dee8268fSThierry Reding {
153dee8268fSThierry Reding 	return container_of(client, struct tegra_dc, client);
154dee8268fSThierry Reding }
155dee8268fSThierry Reding 
156dee8268fSThierry Reding static inline struct tegra_dc *to_tegra_dc(struct drm_crtc *crtc)
157dee8268fSThierry Reding {
15837826519SThierry Reding 	return crtc ? container_of(crtc, struct tegra_dc, base) : NULL;
159dee8268fSThierry Reding }
160dee8268fSThierry Reding 
16103a60569SThierry Reding static inline void tegra_dc_writel(struct tegra_dc *dc, u32 value,
16203a60569SThierry Reding 				   unsigned long offset)
163dee8268fSThierry Reding {
16403a60569SThierry Reding 	writel(value, dc->regs + (offset << 2));
165dee8268fSThierry Reding }
166dee8268fSThierry Reding 
16703a60569SThierry Reding static inline u32 tegra_dc_readl(struct tegra_dc *dc, unsigned long offset)
168dee8268fSThierry Reding {
16903a60569SThierry Reding 	return readl(dc->regs + (offset << 2));
170dee8268fSThierry Reding }
171dee8268fSThierry Reding 
172dee8268fSThierry Reding struct tegra_dc_window {
173dee8268fSThierry Reding 	struct {
174dee8268fSThierry Reding 		unsigned int x;
175dee8268fSThierry Reding 		unsigned int y;
176dee8268fSThierry Reding 		unsigned int w;
177dee8268fSThierry Reding 		unsigned int h;
178dee8268fSThierry Reding 	} src;
179dee8268fSThierry Reding 	struct {
180dee8268fSThierry Reding 		unsigned int x;
181dee8268fSThierry Reding 		unsigned int y;
182dee8268fSThierry Reding 		unsigned int w;
183dee8268fSThierry Reding 		unsigned int h;
184dee8268fSThierry Reding 	} dst;
185dee8268fSThierry Reding 	unsigned int bits_per_pixel;
186dee8268fSThierry Reding 	unsigned int stride[2];
187dee8268fSThierry Reding 	unsigned long base[3];
188db7fbdfdSThierry Reding 	bool bottom_up;
189c134f019SThierry Reding 
190c134f019SThierry Reding 	struct tegra_bo_tiling tiling;
1918f604f8cSThierry Reding 	u32 format;
1928f604f8cSThierry Reding 	u32 swap;
193dee8268fSThierry Reding };
194dee8268fSThierry Reding 
195dee8268fSThierry Reding /* from dc.c */
19642e9ce05SThierry Reding u32 tegra_dc_get_vblank_counter(struct tegra_dc *dc);
197688c59afSThierry Reding void tegra_dc_enable_vblank(struct tegra_dc *dc);
198688c59afSThierry Reding void tegra_dc_disable_vblank(struct tegra_dc *dc);
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 enum drm_connector_status
244132085d8SThierry Reding tegra_output_connector_detect(struct drm_connector *connector, bool force);
245132085d8SThierry Reding void tegra_output_connector_destroy(struct drm_connector *connector);
246132085d8SThierry Reding 
247132085d8SThierry Reding void tegra_output_encoder_destroy(struct drm_encoder *encoder);
248132085d8SThierry Reding 
2496b6b6042SThierry Reding /* from dpaux.c */
2506b6b6042SThierry Reding struct drm_dp_link;
2516b6b6042SThierry Reding 
2529542c237SThierry Reding struct drm_dp_aux *drm_dp_aux_find_by_of_node(struct device_node *np);
2539542c237SThierry Reding enum drm_connector_status drm_dp_aux_detect(struct drm_dp_aux *aux);
2549542c237SThierry Reding int drm_dp_aux_attach(struct drm_dp_aux *aux, struct tegra_output *output);
2559542c237SThierry Reding int drm_dp_aux_detach(struct drm_dp_aux *aux);
2569542c237SThierry Reding int drm_dp_aux_enable(struct drm_dp_aux *aux);
2579542c237SThierry Reding int drm_dp_aux_disable(struct drm_dp_aux *aux);
2589542c237SThierry Reding int drm_dp_aux_prepare(struct drm_dp_aux *aux, u8 encoding);
2599542c237SThierry Reding int drm_dp_aux_train(struct drm_dp_aux *aux, struct drm_dp_link *link,
2606b6b6042SThierry Reding 		     u8 pattern);
2616b6b6042SThierry Reding 
262dee8268fSThierry Reding /* from fb.c */
263dee8268fSThierry Reding struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer,
264dee8268fSThierry Reding 				    unsigned int index);
265db7fbdfdSThierry Reding bool tegra_fb_is_bottom_up(struct drm_framebuffer *framebuffer);
266c134f019SThierry Reding int tegra_fb_get_tiling(struct drm_framebuffer *framebuffer,
267c134f019SThierry Reding 			struct tegra_bo_tiling *tiling);
268f9914214SThierry Reding struct drm_framebuffer *tegra_fb_create(struct drm_device *drm,
269f9914214SThierry Reding 					struct drm_file *file,
2701eb83451SVille Syrjälä 					const struct drm_mode_fb_cmd2 *cmd);
271e2215321SThierry Reding int tegra_drm_fb_prepare(struct drm_device *drm);
2721d1e6fe9SThierry Reding void tegra_drm_fb_free(struct drm_device *drm);
273688c59afSThierry Reding int tegra_drm_fb_init(struct drm_device *drm);
274688c59afSThierry Reding void tegra_drm_fb_exit(struct drm_device *drm);
275986c58d1SThierry Reding void tegra_drm_fb_suspend(struct drm_device *drm);
276986c58d1SThierry Reding void tegra_drm_fb_resume(struct drm_device *drm);
277b110ef37SArchit Taneja #ifdef CONFIG_DRM_FBDEV_EMULATION
278688c59afSThierry Reding void tegra_fbdev_restore_mode(struct tegra_fbdev *fbdev);
279f9914214SThierry Reding void tegra_fb_output_poll_changed(struct drm_device *drm);
28060c2f709SThierry Reding #endif
281dee8268fSThierry Reding 
282dee8268fSThierry Reding extern struct platform_driver tegra_dc_driver;
283dee8268fSThierry Reding extern struct platform_driver tegra_hdmi_driver;
284473112e4SThierry Reding extern struct platform_driver tegra_dsi_driver;
2856b6b6042SThierry Reding extern struct platform_driver tegra_dpaux_driver;
286473112e4SThierry Reding extern struct platform_driver tegra_sor_driver;
287dee8268fSThierry Reding extern struct platform_driver tegra_gr2d_driver;
2885f60ed0dSThierry Reding extern struct platform_driver tegra_gr3d_driver;
289dee8268fSThierry Reding 
290dee8268fSThierry Reding #endif /* HOST1X_DRM_H */
291