2 * Copyright (C) 2012 Avionic Design GmbH
3 * Copyright (C) 2012 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.
14 #include <drm/drm_crtc_helper.h>
15 #include <drm/drm_edid.h>
16 #include <drm/drm_fb_helper.h>
17 #include <drm/drm_gem_cma_helper.h>
18 #include <drm/drm_fb_cma_helper.h>
19 #include <drm/drm_fixed.h>
21 struct tegra_framebuffer
{
22 struct drm_framebuffer base
;
23 struct drm_gem_cma_object
*obj
;
26 static inline struct tegra_framebuffer
*to_tegra_fb(struct drm_framebuffer
*fb
)
28 return container_of(fb
, struct tegra_framebuffer
, base
);
32 struct drm_device
*drm
;
39 struct mutex drm_clients_lock
;
40 struct list_head drm_clients
;
41 struct list_head drm_active
;
43 struct mutex clients_lock
;
44 struct list_head clients
;
46 struct drm_fbdev_cma
*fbdev
;
47 struct tegra_framebuffer fb
;
52 struct host1x_client_ops
{
53 int (*drm_init
)(struct host1x_client
*client
, struct drm_device
*drm
);
54 int (*drm_exit
)(struct host1x_client
*client
);
57 struct host1x_client
{
58 struct host1x
*host1x
;
61 const struct host1x_client_ops
*ops
;
63 struct list_head list
;
66 extern int host1x_drm_init(struct host1x
*host1x
, struct drm_device
*drm
);
67 extern int host1x_drm_exit(struct host1x
*host1x
);
69 extern int host1x_register_client(struct host1x
*host1x
,
70 struct host1x_client
*client
);
71 extern int host1x_unregister_client(struct host1x
*host1x
,
72 struct host1x_client
*client
);
77 struct host1x_client client
;
79 struct host1x
*host1x
;
90 struct tegra_output
*rgb
;
92 struct list_head list
;
94 struct drm_info_list
*debugfs_files
;
95 struct drm_minor
*minor
;
96 struct dentry
*debugfs
;
99 static inline struct tegra_dc
*host1x_client_to_dc(struct host1x_client
*client
)
101 return container_of(client
, struct tegra_dc
, client
);
104 static inline struct tegra_dc
*to_tegra_dc(struct drm_crtc
*crtc
)
106 return container_of(crtc
, struct tegra_dc
, base
);
109 static inline void tegra_dc_writel(struct tegra_dc
*dc
, unsigned long value
,
112 writel(value
, dc
->regs
+ (reg
<< 2));
115 static inline unsigned long tegra_dc_readl(struct tegra_dc
*dc
,
118 return readl(dc
->regs
+ (reg
<< 2));
121 struct tegra_output_ops
{
122 int (*enable
)(struct tegra_output
*output
);
123 int (*disable
)(struct tegra_output
*output
);
124 int (*setup_clock
)(struct tegra_output
*output
, struct clk
*clk
,
126 int (*check_mode
)(struct tegra_output
*output
,
127 struct drm_display_mode
*mode
,
128 enum drm_mode_status
*status
);
131 enum tegra_output_type
{
135 struct tegra_output
{
136 struct device_node
*of_node
;
139 const struct tegra_output_ops
*ops
;
140 enum tegra_output_type type
;
142 struct i2c_adapter
*ddc
;
143 const struct edid
*edid
;
144 unsigned int hpd_irq
;
147 struct drm_encoder encoder
;
148 struct drm_connector connector
;
151 static inline struct tegra_output
*encoder_to_output(struct drm_encoder
*e
)
153 return container_of(e
, struct tegra_output
, encoder
);
156 static inline struct tegra_output
*connector_to_output(struct drm_connector
*c
)
158 return container_of(c
, struct tegra_output
, connector
);
161 static inline int tegra_output_enable(struct tegra_output
*output
)
163 if (output
&& output
->ops
&& output
->ops
->enable
)
164 return output
->ops
->enable(output
);
166 return output
? -ENOSYS
: -EINVAL
;
169 static inline int tegra_output_disable(struct tegra_output
*output
)
171 if (output
&& output
->ops
&& output
->ops
->disable
)
172 return output
->ops
->disable(output
);
174 return output
? -ENOSYS
: -EINVAL
;
177 static inline int tegra_output_setup_clock(struct tegra_output
*output
,
178 struct clk
*clk
, unsigned long pclk
)
180 if (output
&& output
->ops
&& output
->ops
->setup_clock
)
181 return output
->ops
->setup_clock(output
, clk
, pclk
);
183 return output
? -ENOSYS
: -EINVAL
;
186 static inline int tegra_output_check_mode(struct tegra_output
*output
,
187 struct drm_display_mode
*mode
,
188 enum drm_mode_status
*status
)
190 if (output
&& output
->ops
&& output
->ops
->check_mode
)
191 return output
->ops
->check_mode(output
, mode
, status
);
193 return output
? -ENOSYS
: -EINVAL
;
197 extern int tegra_dc_rgb_probe(struct tegra_dc
*dc
);
198 extern int tegra_dc_rgb_init(struct drm_device
*drm
, struct tegra_dc
*dc
);
199 extern int tegra_dc_rgb_exit(struct tegra_dc
*dc
);
202 extern int tegra_output_parse_dt(struct tegra_output
*output
);
203 extern int tegra_output_init(struct drm_device
*drm
, struct tegra_output
*output
);
204 extern int tegra_output_exit(struct tegra_output
*output
);
207 extern struct tegra_gem_object
*tegra_gem_alloc(struct drm_device
*drm
,
209 extern int tegra_gem_handle_create(struct drm_device
*drm
,
210 struct drm_file
*file
, size_t size
,
211 unsigned long flags
, uint32_t *handle
);
212 extern int tegra_gem_dumb_create(struct drm_file
*file
, struct drm_device
*drm
,
213 struct drm_mode_create_dumb
*args
);
214 extern int tegra_gem_dumb_map_offset(struct drm_file
*file
,
215 struct drm_device
*drm
, uint32_t handle
,
217 extern int tegra_gem_dumb_destroy(struct drm_file
*file
,
218 struct drm_device
*drm
, uint32_t handle
);
219 extern int tegra_drm_gem_mmap(struct file
*filp
, struct vm_area_struct
*vma
);
220 extern int tegra_gem_init_object(struct drm_gem_object
*obj
);
221 extern void tegra_gem_free_object(struct drm_gem_object
*obj
);
222 extern struct vm_operations_struct tegra_gem_vm_ops
;
225 extern int tegra_drm_fb_init(struct drm_device
*drm
);
226 extern void tegra_drm_fb_exit(struct drm_device
*drm
);
228 extern struct platform_driver tegra_host1x_driver
;
229 extern struct platform_driver tegra_dc_driver
;
230 extern struct drm_driver tegra_drm_driver
;
232 #endif /* TEGRA_DRM_H */