2 * Copyright (C) 2012 Avionic Design GmbH
3 * Copyright (C) 2012-2013 NVIDIA CORPORATION. All rights reserved.
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.
11 #define HOST1X_DRM_H 1
13 #include <uapi/drm/tegra_drm.h>
14 #include <linux/host1x.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>
25 struct drm_framebuffer base
;
26 struct tegra_bo
**planes
;
27 unsigned int num_planes
;
31 struct drm_fb_helper base
;
36 struct drm_device
*drm
;
38 struct mutex clients_lock
;
39 struct list_head clients
;
41 struct tegra_fbdev
*fbdev
;
44 struct tegra_drm_client
;
46 struct tegra_drm_context
{
47 struct tegra_drm_client
*client
;
48 struct host1x_channel
*channel
;
49 struct list_head list
;
52 struct tegra_drm_client_ops
{
53 int (*open_channel
)(struct tegra_drm_client
*client
,
54 struct tegra_drm_context
*context
);
55 void (*close_channel
)(struct tegra_drm_context
*context
);
56 int (*is_addr_reg
)(struct device
*dev
, u32
class, u32 offset
);
57 int (*submit
)(struct tegra_drm_context
*context
,
58 struct drm_tegra_submit
*args
, struct drm_device
*drm
,
59 struct drm_file
*file
);
62 int tegra_drm_submit(struct tegra_drm_context
*context
,
63 struct drm_tegra_submit
*args
, struct drm_device
*drm
,
64 struct drm_file
*file
);
66 struct tegra_drm_client
{
67 struct host1x_client base
;
68 struct list_head list
;
70 const struct tegra_drm_client_ops
*ops
;
73 static inline struct tegra_drm_client
*
74 host1x_to_drm_client(struct host1x_client
*client
)
76 return container_of(client
, struct tegra_drm_client
, base
);
79 extern int tegra_drm_register_client(struct tegra_drm
*tegra
,
80 struct tegra_drm_client
*client
);
81 extern int tegra_drm_unregister_client(struct tegra_drm
*tegra
,
82 struct tegra_drm_client
*client
);
84 extern int tegra_drm_init(struct tegra_drm
*tegra
, struct drm_device
*drm
);
85 extern int tegra_drm_exit(struct tegra_drm
*tegra
);
90 struct host1x_client client
;
98 struct reset_control
*rst
;
102 struct tegra_output
*rgb
;
104 struct list_head list
;
106 struct drm_info_list
*debugfs_files
;
107 struct drm_minor
*minor
;
108 struct dentry
*debugfs
;
110 /* page-flip handling */
111 struct drm_pending_vblank_event
*event
;
114 static inline struct tegra_dc
*
115 host1x_client_to_dc(struct host1x_client
*client
)
117 return container_of(client
, struct tegra_dc
, client
);
120 static inline struct tegra_dc
*to_tegra_dc(struct drm_crtc
*crtc
)
122 return crtc
? container_of(crtc
, struct tegra_dc
, base
) : NULL
;
125 static inline void tegra_dc_writel(struct tegra_dc
*dc
, unsigned long value
,
128 writel(value
, dc
->regs
+ (reg
<< 2));
131 static inline unsigned long tegra_dc_readl(struct tegra_dc
*dc
,
134 return readl(dc
->regs
+ (reg
<< 2));
137 struct tegra_dc_window
{
150 unsigned int bits_per_pixel
;
152 unsigned int stride
[2];
153 unsigned long base
[3];
159 extern unsigned int tegra_dc_format(uint32_t format
);
160 extern int tegra_dc_setup_window(struct tegra_dc
*dc
, unsigned int index
,
161 const struct tegra_dc_window
*window
);
162 extern void tegra_dc_enable_vblank(struct tegra_dc
*dc
);
163 extern void tegra_dc_disable_vblank(struct tegra_dc
*dc
);
164 extern void tegra_dc_cancel_page_flip(struct drm_crtc
*crtc
,
165 struct drm_file
*file
);
167 struct tegra_output_ops
{
168 int (*enable
)(struct tegra_output
*output
);
169 int (*disable
)(struct tegra_output
*output
);
170 int (*setup_clock
)(struct tegra_output
*output
, struct clk
*clk
,
172 int (*check_mode
)(struct tegra_output
*output
,
173 struct drm_display_mode
*mode
,
174 enum drm_mode_status
*status
);
177 enum tegra_output_type
{
182 struct tegra_output
{
183 struct device_node
*of_node
;
186 const struct tegra_output_ops
*ops
;
187 enum tegra_output_type type
;
189 struct i2c_adapter
*ddc
;
190 const struct edid
*edid
;
191 unsigned int hpd_irq
;
194 struct drm_encoder encoder
;
195 struct drm_connector connector
;
198 static inline struct tegra_output
*encoder_to_output(struct drm_encoder
*e
)
200 return container_of(e
, struct tegra_output
, encoder
);
203 static inline struct tegra_output
*connector_to_output(struct drm_connector
*c
)
205 return container_of(c
, struct tegra_output
, connector
);
208 static inline int tegra_output_enable(struct tegra_output
*output
)
210 if (output
&& output
->ops
&& output
->ops
->enable
)
211 return output
->ops
->enable(output
);
213 return output
? -ENOSYS
: -EINVAL
;
216 static inline int tegra_output_disable(struct tegra_output
*output
)
218 if (output
&& output
->ops
&& output
->ops
->disable
)
219 return output
->ops
->disable(output
);
221 return output
? -ENOSYS
: -EINVAL
;
224 static inline int tegra_output_setup_clock(struct tegra_output
*output
,
225 struct clk
*clk
, unsigned long pclk
)
227 if (output
&& output
->ops
&& output
->ops
->setup_clock
)
228 return output
->ops
->setup_clock(output
, clk
, pclk
);
230 return output
? -ENOSYS
: -EINVAL
;
233 static inline int tegra_output_check_mode(struct tegra_output
*output
,
234 struct drm_display_mode
*mode
,
235 enum drm_mode_status
*status
)
237 if (output
&& output
->ops
&& output
->ops
->check_mode
)
238 return output
->ops
->check_mode(output
, mode
, status
);
240 return output
? -ENOSYS
: -EINVAL
;
244 int drm_host1x_init(struct drm_driver
*driver
, struct host1x_device
*device
);
245 void drm_host1x_exit(struct drm_driver
*driver
, struct host1x_device
*device
);
248 extern int tegra_dc_rgb_probe(struct tegra_dc
*dc
);
249 extern int tegra_dc_rgb_remove(struct tegra_dc
*dc
);
250 extern int tegra_dc_rgb_init(struct drm_device
*drm
, struct tegra_dc
*dc
);
251 extern int tegra_dc_rgb_exit(struct tegra_dc
*dc
);
254 extern int tegra_output_probe(struct tegra_output
*output
);
255 extern int tegra_output_remove(struct tegra_output
*output
);
256 extern int tegra_output_init(struct drm_device
*drm
, struct tegra_output
*output
);
257 extern int tegra_output_exit(struct tegra_output
*output
);
260 struct tegra_bo
*tegra_fb_get_plane(struct drm_framebuffer
*framebuffer
,
262 bool tegra_fb_is_bottom_up(struct drm_framebuffer
*framebuffer
);
263 bool tegra_fb_is_tiled(struct drm_framebuffer
*framebuffer
);
264 extern int tegra_drm_fb_init(struct drm_device
*drm
);
265 extern void tegra_drm_fb_exit(struct drm_device
*drm
);
266 extern void tegra_fbdev_restore_mode(struct tegra_fbdev
*fbdev
);
268 extern struct platform_driver tegra_dc_driver
;
269 extern struct platform_driver tegra_hdmi_driver
;
270 extern struct platform_driver tegra_gr2d_driver
;
271 extern struct platform_driver tegra_gr3d_driver
;
273 #endif /* HOST1X_DRM_H */