xref: /linux/drivers/gpu/drm/tegra/drm.h (revision 9a379e77033f02c4a071891afdf0f0a01eff8ccb)
1 /*
2  * Copyright (C) 2012 Avionic Design GmbH
3  * Copyright (C) 2012-2013 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 HOST1X_DRM_H
11 #define HOST1X_DRM_H 1
12 
13 #include <uapi/drm/tegra_drm.h>
14 #include <linux/host1x.h>
15 #include <linux/iova.h>
16 #include <linux/of_gpio.h>
17 
18 #include <drm/drmP.h>
19 #include <drm/drm_atomic.h>
20 #include <drm/drm_crtc_helper.h>
21 #include <drm/drm_edid.h>
22 #include <drm/drm_encoder.h>
23 #include <drm/drm_fb_helper.h>
24 #include <drm/drm_fixed.h>
25 
26 #include "gem.h"
27 #include "hub.h"
28 #include "trace.h"
29 
30 struct reset_control;
31 
32 struct tegra_fb {
33 	struct drm_framebuffer base;
34 	struct tegra_bo **planes;
35 	unsigned int num_planes;
36 };
37 
38 #ifdef CONFIG_DRM_FBDEV_EMULATION
39 struct tegra_fbdev {
40 	struct drm_fb_helper base;
41 	struct tegra_fb *fb;
42 };
43 #endif
44 
45 struct tegra_atomic_state {
46 	struct drm_atomic_state base;
47 
48 	struct clk *clk_disp;
49 	struct tegra_dc *dc;
50 	unsigned long rate;
51 };
52 
53 static inline struct tegra_atomic_state *
54 to_tegra_atomic_state(struct drm_atomic_state *state)
55 {
56 	return container_of(state, struct tegra_atomic_state, base);
57 }
58 
59 struct tegra_drm {
60 	struct drm_device *drm;
61 
62 	struct iommu_domain *domain;
63 	struct iommu_group *group;
64 	struct mutex mm_lock;
65 	struct drm_mm mm;
66 
67 	struct {
68 		struct iova_domain domain;
69 		unsigned long shift;
70 		unsigned long limit;
71 	} carveout;
72 
73 	struct mutex clients_lock;
74 	struct list_head clients;
75 
76 #ifdef CONFIG_DRM_FBDEV_EMULATION
77 	struct tegra_fbdev *fbdev;
78 #endif
79 
80 	unsigned int pitch_align;
81 
82 	struct tegra_display_hub *hub;
83 
84 	struct drm_atomic_state *state;
85 };
86 
87 struct tegra_drm_client;
88 
89 struct tegra_drm_context {
90 	struct tegra_drm_client *client;
91 	struct host1x_channel *channel;
92 	unsigned int id;
93 };
94 
95 struct tegra_drm_client_ops {
96 	int (*open_channel)(struct tegra_drm_client *client,
97 			    struct tegra_drm_context *context);
98 	void (*close_channel)(struct tegra_drm_context *context);
99 	int (*is_addr_reg)(struct device *dev, u32 class, u32 offset);
100 	int (*is_valid_class)(u32 class);
101 	int (*submit)(struct tegra_drm_context *context,
102 		      struct drm_tegra_submit *args, struct drm_device *drm,
103 		      struct drm_file *file);
104 };
105 
106 int tegra_drm_submit(struct tegra_drm_context *context,
107 		     struct drm_tegra_submit *args, struct drm_device *drm,
108 		     struct drm_file *file);
109 
110 struct tegra_drm_client {
111 	struct host1x_client base;
112 	struct list_head list;
113 
114 	const struct tegra_drm_client_ops *ops;
115 };
116 
117 static inline struct tegra_drm_client *
118 host1x_to_drm_client(struct host1x_client *client)
119 {
120 	return container_of(client, struct tegra_drm_client, base);
121 }
122 
123 int tegra_drm_register_client(struct tegra_drm *tegra,
124 			      struct tegra_drm_client *client);
125 int tegra_drm_unregister_client(struct tegra_drm *tegra,
126 				struct tegra_drm_client *client);
127 
128 int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm);
129 int tegra_drm_exit(struct tegra_drm *tegra);
130 
131 void *tegra_drm_alloc(struct tegra_drm *tegra, size_t size, dma_addr_t *iova);
132 void tegra_drm_free(struct tegra_drm *tegra, size_t size, void *virt,
133 		    dma_addr_t iova);
134 
135 struct cec_notifier;
136 
137 struct tegra_output {
138 	struct device_node *of_node;
139 	struct device *dev;
140 
141 	struct drm_panel *panel;
142 	struct i2c_adapter *ddc;
143 	const struct edid *edid;
144 	struct cec_notifier *notifier;
145 	unsigned int hpd_irq;
146 	int hpd_gpio;
147 	enum of_gpio_flags hpd_gpio_flags;
148 
149 	struct drm_encoder encoder;
150 	struct drm_connector connector;
151 };
152 
153 static inline struct tegra_output *encoder_to_output(struct drm_encoder *e)
154 {
155 	return container_of(e, struct tegra_output, encoder);
156 }
157 
158 static inline struct tegra_output *connector_to_output(struct drm_connector *c)
159 {
160 	return container_of(c, struct tegra_output, connector);
161 }
162 
163 /* from output.c */
164 int tegra_output_probe(struct tegra_output *output);
165 void tegra_output_remove(struct tegra_output *output);
166 int tegra_output_init(struct drm_device *drm, struct tegra_output *output);
167 void tegra_output_exit(struct tegra_output *output);
168 void tegra_output_find_possible_crtcs(struct tegra_output *output,
169 				      struct drm_device *drm);
170 
171 int tegra_output_connector_get_modes(struct drm_connector *connector);
172 enum drm_connector_status
173 tegra_output_connector_detect(struct drm_connector *connector, bool force);
174 void tegra_output_connector_destroy(struct drm_connector *connector);
175 
176 void tegra_output_encoder_destroy(struct drm_encoder *encoder);
177 
178 /* from dpaux.c */
179 struct drm_dp_link;
180 
181 struct drm_dp_aux *drm_dp_aux_find_by_of_node(struct device_node *np);
182 enum drm_connector_status drm_dp_aux_detect(struct drm_dp_aux *aux);
183 int drm_dp_aux_attach(struct drm_dp_aux *aux, struct tegra_output *output);
184 int drm_dp_aux_detach(struct drm_dp_aux *aux);
185 int drm_dp_aux_enable(struct drm_dp_aux *aux);
186 int drm_dp_aux_disable(struct drm_dp_aux *aux);
187 int drm_dp_aux_prepare(struct drm_dp_aux *aux, u8 encoding);
188 int drm_dp_aux_train(struct drm_dp_aux *aux, struct drm_dp_link *link,
189 		     u8 pattern);
190 
191 /* from fb.c */
192 struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer,
193 				    unsigned int index);
194 bool tegra_fb_is_bottom_up(struct drm_framebuffer *framebuffer);
195 int tegra_fb_get_tiling(struct drm_framebuffer *framebuffer,
196 			struct tegra_bo_tiling *tiling);
197 struct drm_framebuffer *tegra_fb_create(struct drm_device *drm,
198 					struct drm_file *file,
199 					const struct drm_mode_fb_cmd2 *cmd);
200 int tegra_drm_fb_prepare(struct drm_device *drm);
201 void tegra_drm_fb_free(struct drm_device *drm);
202 int tegra_drm_fb_init(struct drm_device *drm);
203 void tegra_drm_fb_exit(struct drm_device *drm);
204 void tegra_drm_fb_suspend(struct drm_device *drm);
205 void tegra_drm_fb_resume(struct drm_device *drm);
206 
207 extern struct platform_driver tegra_display_hub_driver;
208 extern struct platform_driver tegra_dc_driver;
209 extern struct platform_driver tegra_hdmi_driver;
210 extern struct platform_driver tegra_dsi_driver;
211 extern struct platform_driver tegra_dpaux_driver;
212 extern struct platform_driver tegra_sor_driver;
213 extern struct platform_driver tegra_gr2d_driver;
214 extern struct platform_driver tegra_gr3d_driver;
215 extern struct platform_driver tegra_vic_driver;
216 
217 #endif /* HOST1X_DRM_H */
218