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