xref: /openbmc/linux/drivers/gpu/drm/tegra/drm.h (revision 2359ccdd)
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_drm {
46 	struct drm_device *drm;
47 
48 	struct iommu_domain *domain;
49 	struct iommu_group *group;
50 	struct mutex mm_lock;
51 	struct drm_mm mm;
52 
53 	struct {
54 		struct iova_domain domain;
55 		unsigned long shift;
56 		unsigned long limit;
57 	} carveout;
58 
59 	struct mutex clients_lock;
60 	struct list_head clients;
61 
62 #ifdef CONFIG_DRM_FBDEV_EMULATION
63 	struct tegra_fbdev *fbdev;
64 #endif
65 
66 	unsigned int pitch_align;
67 
68 	struct tegra_display_hub *hub;
69 
70 	struct drm_atomic_state *state;
71 };
72 
73 struct tegra_drm_client;
74 
75 struct tegra_drm_context {
76 	struct tegra_drm_client *client;
77 	struct host1x_channel *channel;
78 	unsigned int id;
79 };
80 
81 struct tegra_drm_client_ops {
82 	int (*open_channel)(struct tegra_drm_client *client,
83 			    struct tegra_drm_context *context);
84 	void (*close_channel)(struct tegra_drm_context *context);
85 	int (*is_addr_reg)(struct device *dev, u32 class, u32 offset);
86 	int (*is_valid_class)(u32 class);
87 	int (*submit)(struct tegra_drm_context *context,
88 		      struct drm_tegra_submit *args, struct drm_device *drm,
89 		      struct drm_file *file);
90 };
91 
92 int tegra_drm_submit(struct tegra_drm_context *context,
93 		     struct drm_tegra_submit *args, struct drm_device *drm,
94 		     struct drm_file *file);
95 
96 struct tegra_drm_client {
97 	struct host1x_client base;
98 	struct list_head list;
99 
100 	const struct tegra_drm_client_ops *ops;
101 };
102 
103 static inline struct tegra_drm_client *
104 host1x_to_drm_client(struct host1x_client *client)
105 {
106 	return container_of(client, struct tegra_drm_client, base);
107 }
108 
109 int tegra_drm_register_client(struct tegra_drm *tegra,
110 			      struct tegra_drm_client *client);
111 int tegra_drm_unregister_client(struct tegra_drm *tegra,
112 				struct tegra_drm_client *client);
113 
114 int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm);
115 int tegra_drm_exit(struct tegra_drm *tegra);
116 
117 void *tegra_drm_alloc(struct tegra_drm *tegra, size_t size, dma_addr_t *iova);
118 void tegra_drm_free(struct tegra_drm *tegra, size_t size, void *virt,
119 		    dma_addr_t iova);
120 
121 struct cec_notifier;
122 
123 struct tegra_output {
124 	struct device_node *of_node;
125 	struct device *dev;
126 
127 	struct drm_panel *panel;
128 	struct i2c_adapter *ddc;
129 	const struct edid *edid;
130 	struct cec_notifier *notifier;
131 	unsigned int hpd_irq;
132 	int hpd_gpio;
133 	enum of_gpio_flags hpd_gpio_flags;
134 
135 	struct drm_encoder encoder;
136 	struct drm_connector connector;
137 };
138 
139 static inline struct tegra_output *encoder_to_output(struct drm_encoder *e)
140 {
141 	return container_of(e, struct tegra_output, encoder);
142 }
143 
144 static inline struct tegra_output *connector_to_output(struct drm_connector *c)
145 {
146 	return container_of(c, struct tegra_output, connector);
147 }
148 
149 /* from output.c */
150 int tegra_output_probe(struct tegra_output *output);
151 void tegra_output_remove(struct tegra_output *output);
152 int tegra_output_init(struct drm_device *drm, struct tegra_output *output);
153 void tegra_output_exit(struct tegra_output *output);
154 void tegra_output_find_possible_crtcs(struct tegra_output *output,
155 				      struct drm_device *drm);
156 
157 int tegra_output_connector_get_modes(struct drm_connector *connector);
158 enum drm_connector_status
159 tegra_output_connector_detect(struct drm_connector *connector, bool force);
160 void tegra_output_connector_destroy(struct drm_connector *connector);
161 
162 void tegra_output_encoder_destroy(struct drm_encoder *encoder);
163 
164 /* from dpaux.c */
165 struct drm_dp_link;
166 
167 struct drm_dp_aux *drm_dp_aux_find_by_of_node(struct device_node *np);
168 enum drm_connector_status drm_dp_aux_detect(struct drm_dp_aux *aux);
169 int drm_dp_aux_attach(struct drm_dp_aux *aux, struct tegra_output *output);
170 int drm_dp_aux_detach(struct drm_dp_aux *aux);
171 int drm_dp_aux_enable(struct drm_dp_aux *aux);
172 int drm_dp_aux_disable(struct drm_dp_aux *aux);
173 int drm_dp_aux_prepare(struct drm_dp_aux *aux, u8 encoding);
174 int drm_dp_aux_train(struct drm_dp_aux *aux, struct drm_dp_link *link,
175 		     u8 pattern);
176 
177 /* from fb.c */
178 struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer,
179 				    unsigned int index);
180 bool tegra_fb_is_bottom_up(struct drm_framebuffer *framebuffer);
181 int tegra_fb_get_tiling(struct drm_framebuffer *framebuffer,
182 			struct tegra_bo_tiling *tiling);
183 struct drm_framebuffer *tegra_fb_create(struct drm_device *drm,
184 					struct drm_file *file,
185 					const struct drm_mode_fb_cmd2 *cmd);
186 int tegra_drm_fb_prepare(struct drm_device *drm);
187 void tegra_drm_fb_free(struct drm_device *drm);
188 int tegra_drm_fb_init(struct drm_device *drm);
189 void tegra_drm_fb_exit(struct drm_device *drm);
190 void tegra_drm_fb_suspend(struct drm_device *drm);
191 void tegra_drm_fb_resume(struct drm_device *drm);
192 
193 extern struct platform_driver tegra_display_hub_driver;
194 extern struct platform_driver tegra_dc_driver;
195 extern struct platform_driver tegra_hdmi_driver;
196 extern struct platform_driver tegra_dsi_driver;
197 extern struct platform_driver tegra_dpaux_driver;
198 extern struct platform_driver tegra_sor_driver;
199 extern struct platform_driver tegra_gr2d_driver;
200 extern struct platform_driver tegra_gr3d_driver;
201 extern struct platform_driver tegra_vic_driver;
202 
203 #endif /* HOST1X_DRM_H */
204