Loading...
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * Copyright (C) 2012 Avionic Design GmbH
4 * Copyright (C) 2012-2013 NVIDIA CORPORATION. All rights reserved.
5 */
6
7#ifndef HOST1X_DRM_H
8#define HOST1X_DRM_H 1
9
10#include <linux/host1x.h>
11#include <linux/iova.h>
12#include <linux/of_gpio.h>
13
14#include <drm/drm_atomic.h>
15#include <drm/drm_edid.h>
16#include <drm/drm_encoder.h>
17#include <drm/drm_fb_helper.h>
18#include <drm/drm_fixed.h>
19#include <drm/drm_probe_helper.h>
20#include <uapi/drm/tegra_drm.h>
21
22#include "gem.h"
23#include "hub.h"
24#include "trace.h"
25
26struct reset_control;
27
28#ifdef CONFIG_DRM_FBDEV_EMULATION
29struct tegra_fbdev {
30 struct drm_fb_helper base;
31 struct drm_framebuffer *fb;
32};
33#endif
34
35struct tegra_drm {
36 struct drm_device *drm;
37
38 struct iommu_domain *domain;
39 struct iommu_group *group;
40 struct mutex mm_lock;
41 struct drm_mm mm;
42
43 struct {
44 struct iova_domain domain;
45 unsigned long shift;
46 unsigned long limit;
47 } carveout;
48
49 struct mutex clients_lock;
50 struct list_head clients;
51
52#ifdef CONFIG_DRM_FBDEV_EMULATION
53 struct tegra_fbdev *fbdev;
54#endif
55
56 unsigned int pitch_align;
57
58 struct tegra_display_hub *hub;
59};
60
61struct tegra_drm_client;
62
63struct tegra_drm_context {
64 struct tegra_drm_client *client;
65 struct host1x_channel *channel;
66 unsigned int id;
67};
68
69struct tegra_drm_client_ops {
70 int (*open_channel)(struct tegra_drm_client *client,
71 struct tegra_drm_context *context);
72 void (*close_channel)(struct tegra_drm_context *context);
73 int (*is_addr_reg)(struct device *dev, u32 class, u32 offset);
74 int (*is_valid_class)(u32 class);
75 int (*submit)(struct tegra_drm_context *context,
76 struct drm_tegra_submit *args, struct drm_device *drm,
77 struct drm_file *file);
78};
79
80int tegra_drm_submit(struct tegra_drm_context *context,
81 struct drm_tegra_submit *args, struct drm_device *drm,
82 struct drm_file *file);
83
84struct tegra_drm_client {
85 struct host1x_client base;
86 struct list_head list;
87 struct tegra_drm *drm;
88
89 unsigned int version;
90 const struct tegra_drm_client_ops *ops;
91};
92
93static inline struct tegra_drm_client *
94host1x_to_drm_client(struct host1x_client *client)
95{
96 return container_of(client, struct tegra_drm_client, base);
97}
98
99int tegra_drm_register_client(struct tegra_drm *tegra,
100 struct tegra_drm_client *client);
101int tegra_drm_unregister_client(struct tegra_drm *tegra,
102 struct tegra_drm_client *client);
103struct iommu_group *host1x_client_iommu_attach(struct host1x_client *client,
104 bool shared);
105void host1x_client_iommu_detach(struct host1x_client *client,
106 struct iommu_group *group);
107
108int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm);
109int tegra_drm_exit(struct tegra_drm *tegra);
110
111void *tegra_drm_alloc(struct tegra_drm *tegra, size_t size, dma_addr_t *iova);
112void tegra_drm_free(struct tegra_drm *tegra, size_t size, void *virt,
113 dma_addr_t iova);
114
115struct cec_notifier;
116
117struct tegra_output {
118 struct device_node *of_node;
119 struct device *dev;
120
121 struct drm_panel *panel;
122 struct i2c_adapter *ddc;
123 const struct edid *edid;
124 struct cec_notifier *cec;
125 unsigned int hpd_irq;
126 struct gpio_desc *hpd_gpio;
127
128 struct drm_encoder encoder;
129 struct drm_connector connector;
130};
131
132static inline struct tegra_output *encoder_to_output(struct drm_encoder *e)
133{
134 return container_of(e, struct tegra_output, encoder);
135}
136
137static inline struct tegra_output *connector_to_output(struct drm_connector *c)
138{
139 return container_of(c, struct tegra_output, connector);
140}
141
142/* from output.c */
143int tegra_output_probe(struct tegra_output *output);
144void tegra_output_remove(struct tegra_output *output);
145int tegra_output_init(struct drm_device *drm, struct tegra_output *output);
146void tegra_output_exit(struct tegra_output *output);
147void tegra_output_find_possible_crtcs(struct tegra_output *output,
148 struct drm_device *drm);
149
150int tegra_output_connector_get_modes(struct drm_connector *connector);
151enum drm_connector_status
152tegra_output_connector_detect(struct drm_connector *connector, bool force);
153void tegra_output_connector_destroy(struct drm_connector *connector);
154
155void tegra_output_encoder_destroy(struct drm_encoder *encoder);
156
157/* from dpaux.c */
158struct drm_dp_link;
159
160struct drm_dp_aux *drm_dp_aux_find_by_of_node(struct device_node *np);
161enum drm_connector_status drm_dp_aux_detect(struct drm_dp_aux *aux);
162int drm_dp_aux_attach(struct drm_dp_aux *aux, struct tegra_output *output);
163int drm_dp_aux_detach(struct drm_dp_aux *aux);
164int drm_dp_aux_enable(struct drm_dp_aux *aux);
165int drm_dp_aux_disable(struct drm_dp_aux *aux);
166int drm_dp_aux_prepare(struct drm_dp_aux *aux, u8 encoding);
167int drm_dp_aux_train(struct drm_dp_aux *aux, struct drm_dp_link *link,
168 u8 pattern);
169
170/* from fb.c */
171struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer,
172 unsigned int index);
173bool tegra_fb_is_bottom_up(struct drm_framebuffer *framebuffer);
174int tegra_fb_get_tiling(struct drm_framebuffer *framebuffer,
175 struct tegra_bo_tiling *tiling);
176struct drm_framebuffer *tegra_fb_create(struct drm_device *drm,
177 struct drm_file *file,
178 const struct drm_mode_fb_cmd2 *cmd);
179int tegra_drm_fb_prepare(struct drm_device *drm);
180void tegra_drm_fb_free(struct drm_device *drm);
181int tegra_drm_fb_init(struct drm_device *drm);
182void tegra_drm_fb_exit(struct drm_device *drm);
183
184extern struct platform_driver tegra_display_hub_driver;
185extern struct platform_driver tegra_dc_driver;
186extern struct platform_driver tegra_hdmi_driver;
187extern struct platform_driver tegra_dsi_driver;
188extern struct platform_driver tegra_dpaux_driver;
189extern struct platform_driver tegra_sor_driver;
190extern struct platform_driver tegra_gr2d_driver;
191extern struct platform_driver tegra_gr3d_driver;
192extern struct platform_driver tegra_vic_driver;
193
194#endif /* HOST1X_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
16#include <drm/drmP.h>
17#include <drm/drm_crtc_helper.h>
18#include <drm/drm_edid.h>
19#include <drm/drm_fb_helper.h>
20#include <drm/drm_fixed.h>
21
22struct reset_control;
23
24struct tegra_fb {
25 struct drm_framebuffer base;
26 struct tegra_bo **planes;
27 unsigned int num_planes;
28};
29
30#ifdef CONFIG_DRM_TEGRA_FBDEV
31struct tegra_fbdev {
32 struct drm_fb_helper base;
33 struct tegra_fb *fb;
34};
35#endif
36
37struct tegra_drm {
38 struct drm_device *drm;
39
40 struct mutex clients_lock;
41 struct list_head clients;
42
43#ifdef CONFIG_DRM_TEGRA_FBDEV
44 struct tegra_fbdev *fbdev;
45#endif
46};
47
48struct tegra_drm_client;
49
50struct tegra_drm_context {
51 struct tegra_drm_client *client;
52 struct host1x_channel *channel;
53 struct list_head list;
54};
55
56struct tegra_drm_client_ops {
57 int (*open_channel)(struct tegra_drm_client *client,
58 struct tegra_drm_context *context);
59 void (*close_channel)(struct tegra_drm_context *context);
60 int (*is_addr_reg)(struct device *dev, u32 class, u32 offset);
61 int (*submit)(struct tegra_drm_context *context,
62 struct drm_tegra_submit *args, struct drm_device *drm,
63 struct drm_file *file);
64};
65
66int tegra_drm_submit(struct tegra_drm_context *context,
67 struct drm_tegra_submit *args, struct drm_device *drm,
68 struct drm_file *file);
69
70struct tegra_drm_client {
71 struct host1x_client base;
72 struct list_head list;
73
74 const struct tegra_drm_client_ops *ops;
75};
76
77static inline struct tegra_drm_client *
78host1x_to_drm_client(struct host1x_client *client)
79{
80 return container_of(client, struct tegra_drm_client, base);
81}
82
83extern int tegra_drm_register_client(struct tegra_drm *tegra,
84 struct tegra_drm_client *client);
85extern int tegra_drm_unregister_client(struct tegra_drm *tegra,
86 struct tegra_drm_client *client);
87
88extern int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm);
89extern int tegra_drm_exit(struct tegra_drm *tegra);
90
91struct tegra_dc_soc_info;
92struct tegra_output;
93
94struct tegra_dc {
95 struct host1x_client client;
96 struct device *dev;
97 spinlock_t lock;
98
99 struct drm_crtc base;
100 int pipe;
101
102 struct clk *clk;
103 struct reset_control *rst;
104 void __iomem *regs;
105 int irq;
106
107 struct tegra_output *rgb;
108
109 struct list_head list;
110
111 struct drm_info_list *debugfs_files;
112 struct drm_minor *minor;
113 struct dentry *debugfs;
114
115 /* page-flip handling */
116 struct drm_pending_vblank_event *event;
117
118 const struct tegra_dc_soc_info *soc;
119};
120
121static inline struct tegra_dc *
122host1x_client_to_dc(struct host1x_client *client)
123{
124 return container_of(client, struct tegra_dc, client);
125}
126
127static inline struct tegra_dc *to_tegra_dc(struct drm_crtc *crtc)
128{
129 return crtc ? container_of(crtc, struct tegra_dc, base) : NULL;
130}
131
132static inline void tegra_dc_writel(struct tegra_dc *dc, unsigned long value,
133 unsigned long reg)
134{
135 writel(value, dc->regs + (reg << 2));
136}
137
138static inline unsigned long tegra_dc_readl(struct tegra_dc *dc,
139 unsigned long reg)
140{
141 return readl(dc->regs + (reg << 2));
142}
143
144struct tegra_dc_window {
145 struct {
146 unsigned int x;
147 unsigned int y;
148 unsigned int w;
149 unsigned int h;
150 } src;
151 struct {
152 unsigned int x;
153 unsigned int y;
154 unsigned int w;
155 unsigned int h;
156 } dst;
157 unsigned int bits_per_pixel;
158 unsigned int format;
159 unsigned int stride[2];
160 unsigned long base[3];
161 bool bottom_up;
162 bool tiled;
163};
164
165/* from dc.c */
166extern unsigned int tegra_dc_format(uint32_t format);
167extern int tegra_dc_setup_window(struct tegra_dc *dc, unsigned int index,
168 const struct tegra_dc_window *window);
169extern void tegra_dc_enable_vblank(struct tegra_dc *dc);
170extern void tegra_dc_disable_vblank(struct tegra_dc *dc);
171extern void tegra_dc_cancel_page_flip(struct drm_crtc *crtc,
172 struct drm_file *file);
173
174struct tegra_output_ops {
175 int (*enable)(struct tegra_output *output);
176 int (*disable)(struct tegra_output *output);
177 int (*setup_clock)(struct tegra_output *output, struct clk *clk,
178 unsigned long pclk);
179 int (*check_mode)(struct tegra_output *output,
180 struct drm_display_mode *mode,
181 enum drm_mode_status *status);
182 enum drm_connector_status (*detect)(struct tegra_output *output);
183};
184
185enum tegra_output_type {
186 TEGRA_OUTPUT_RGB,
187 TEGRA_OUTPUT_HDMI,
188 TEGRA_OUTPUT_DSI,
189 TEGRA_OUTPUT_EDP,
190};
191
192struct tegra_output {
193 struct device_node *of_node;
194 struct device *dev;
195
196 const struct tegra_output_ops *ops;
197 enum tegra_output_type type;
198
199 struct drm_panel *panel;
200 struct i2c_adapter *ddc;
201 const struct edid *edid;
202 unsigned int hpd_irq;
203 int hpd_gpio;
204
205 struct drm_encoder encoder;
206 struct drm_connector connector;
207};
208
209static inline struct tegra_output *encoder_to_output(struct drm_encoder *e)
210{
211 return container_of(e, struct tegra_output, encoder);
212}
213
214static inline struct tegra_output *connector_to_output(struct drm_connector *c)
215{
216 return container_of(c, struct tegra_output, connector);
217}
218
219static inline int tegra_output_enable(struct tegra_output *output)
220{
221 if (output && output->ops && output->ops->enable)
222 return output->ops->enable(output);
223
224 return output ? -ENOSYS : -EINVAL;
225}
226
227static inline int tegra_output_disable(struct tegra_output *output)
228{
229 if (output && output->ops && output->ops->disable)
230 return output->ops->disable(output);
231
232 return output ? -ENOSYS : -EINVAL;
233}
234
235static inline int tegra_output_setup_clock(struct tegra_output *output,
236 struct clk *clk, unsigned long pclk)
237{
238 if (output && output->ops && output->ops->setup_clock)
239 return output->ops->setup_clock(output, clk, pclk);
240
241 return output ? -ENOSYS : -EINVAL;
242}
243
244static inline int tegra_output_check_mode(struct tegra_output *output,
245 struct drm_display_mode *mode,
246 enum drm_mode_status *status)
247{
248 if (output && output->ops && output->ops->check_mode)
249 return output->ops->check_mode(output, mode, status);
250
251 return output ? -ENOSYS : -EINVAL;
252}
253
254/* from bus.c */
255int drm_host1x_init(struct drm_driver *driver, struct host1x_device *device);
256void drm_host1x_exit(struct drm_driver *driver, struct host1x_device *device);
257
258/* from rgb.c */
259extern int tegra_dc_rgb_probe(struct tegra_dc *dc);
260extern int tegra_dc_rgb_remove(struct tegra_dc *dc);
261extern int tegra_dc_rgb_init(struct drm_device *drm, struct tegra_dc *dc);
262extern int tegra_dc_rgb_exit(struct tegra_dc *dc);
263
264/* from output.c */
265extern int tegra_output_probe(struct tegra_output *output);
266extern int tegra_output_remove(struct tegra_output *output);
267extern int tegra_output_init(struct drm_device *drm, struct tegra_output *output);
268extern int tegra_output_exit(struct tegra_output *output);
269
270/* from dpaux.c */
271
272struct tegra_dpaux;
273struct drm_dp_link;
274struct drm_dp_aux;
275
276struct tegra_dpaux *tegra_dpaux_find_by_of_node(struct device_node *np);
277enum drm_connector_status tegra_dpaux_detect(struct tegra_dpaux *dpaux);
278int tegra_dpaux_attach(struct tegra_dpaux *dpaux, struct tegra_output *output);
279int tegra_dpaux_detach(struct tegra_dpaux *dpaux);
280int tegra_dpaux_enable(struct tegra_dpaux *dpaux);
281int tegra_dpaux_disable(struct tegra_dpaux *dpaux);
282int tegra_dpaux_prepare(struct tegra_dpaux *dpaux, u8 encoding);
283int tegra_dpaux_train(struct tegra_dpaux *dpaux, struct drm_dp_link *link,
284 u8 pattern);
285
286/* from fb.c */
287struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer,
288 unsigned int index);
289bool tegra_fb_is_bottom_up(struct drm_framebuffer *framebuffer);
290bool tegra_fb_is_tiled(struct drm_framebuffer *framebuffer);
291extern int tegra_drm_fb_init(struct drm_device *drm);
292extern void tegra_drm_fb_exit(struct drm_device *drm);
293#ifdef CONFIG_DRM_TEGRA_FBDEV
294extern void tegra_fbdev_restore_mode(struct tegra_fbdev *fbdev);
295#endif
296
297extern struct platform_driver tegra_dc_driver;
298extern struct platform_driver tegra_dsi_driver;
299extern struct platform_driver tegra_sor_driver;
300extern struct platform_driver tegra_hdmi_driver;
301extern struct platform_driver tegra_dpaux_driver;
302extern struct platform_driver tegra_gr2d_driver;
303extern struct platform_driver tegra_gr3d_driver;
304
305#endif /* HOST1X_DRM_H */