drm.h 7.3 KB
Newer Older
T
Thierry Reding 已提交
1 2
/*
 * Copyright (C) 2012 Avionic Design GmbH
T
Terje Bergstrom 已提交
3
 * Copyright (C) 2012-2013 NVIDIA CORPORATION.  All rights reserved.
T
Thierry Reding 已提交
4 5 6 7 8 9
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

10 11
#ifndef HOST1X_DRM_H
#define HOST1X_DRM_H 1
T
Thierry Reding 已提交
12

13 14 15
#include <uapi/drm/tegra_drm.h>
#include <linux/host1x.h>

T
Thierry Reding 已提交
16 17 18 19 20 21
#include <drm/drmP.h>
#include <drm/drm_crtc_helper.h>
#include <drm/drm_edid.h>
#include <drm/drm_fb_helper.h>
#include <drm/drm_fixed.h>

S
Stephen Warren 已提交
22 23
struct reset_control;

24 25 26 27 28 29
struct tegra_fb {
	struct drm_framebuffer base;
	struct tegra_bo **planes;
	unsigned int num_planes;
};

30
#ifdef CONFIG_DRM_TEGRA_FBDEV
31 32 33 34
struct tegra_fbdev {
	struct drm_fb_helper base;
	struct tegra_fb *fb;
};
35
#endif
36

37
struct tegra_drm {
T
Thierry Reding 已提交
38 39 40 41 42
	struct drm_device *drm;

	struct mutex clients_lock;
	struct list_head clients;

43
#ifdef CONFIG_DRM_TEGRA_FBDEV
44
	struct tegra_fbdev *fbdev;
45
#endif
T
Thierry Reding 已提交
46 47
};

48
struct tegra_drm_client;
T
Thierry Reding 已提交
49

50
struct tegra_drm_context {
51
	struct tegra_drm_client *client;
T
Terje Bergstrom 已提交
52 53 54 55
	struct host1x_channel *channel;
	struct list_head list;
};

56 57
struct tegra_drm_client_ops {
	int (*open_channel)(struct tegra_drm_client *client,
58 59
			    struct tegra_drm_context *context);
	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,
T
Terje Bergstrom 已提交
62 63 64 65
		      struct drm_tegra_submit *args, struct drm_device *drm,
		      struct drm_file *file);
};

66 67 68 69
int tegra_drm_submit(struct tegra_drm_context *context,
		     struct drm_tegra_submit *args, struct drm_device *drm,
		     struct drm_file *file);

70 71
struct tegra_drm_client {
	struct host1x_client base;
72
	struct list_head list;
T
Terje Bergstrom 已提交
73

74
	const struct tegra_drm_client_ops *ops;
T
Thierry Reding 已提交
75 76
};

77
static inline struct tegra_drm_client *
78
host1x_to_drm_client(struct host1x_client *client)
79 80 81 82
{
	return container_of(client, struct tegra_drm_client, base);
}

83 84 85 86 87
extern int tegra_drm_register_client(struct tegra_drm *tegra,
				     struct tegra_drm_client *client);
extern int tegra_drm_unregister_client(struct tegra_drm *tegra,
				       struct tegra_drm_client *client);

88 89
extern int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm);
extern int tegra_drm_exit(struct tegra_drm *tegra);
T
Thierry Reding 已提交
90 91 92 93

struct tegra_output;

struct tegra_dc {
94
	struct host1x_client client;
T
Thierry Reding 已提交
95
	struct device *dev;
96
	spinlock_t lock;
T
Thierry Reding 已提交
97 98 99 100 101

	struct drm_crtc base;
	int pipe;

	struct clk *clk;
S
Stephen Warren 已提交
102
	struct reset_control *rst;
T
Thierry Reding 已提交
103 104 105 106 107 108 109 110 111 112
	void __iomem *regs;
	int irq;

	struct tegra_output *rgb;

	struct list_head list;

	struct drm_info_list *debugfs_files;
	struct drm_minor *minor;
	struct dentry *debugfs;
113 114 115

	/* page-flip handling */
	struct drm_pending_vblank_event *event;
T
Thierry Reding 已提交
116 117
};

118
static inline struct tegra_dc *
119
host1x_client_to_dc(struct host1x_client *client)
T
Thierry Reding 已提交
120 121 122 123 124 125
{
	return container_of(client, struct tegra_dc, client);
}

static inline struct tegra_dc *to_tegra_dc(struct drm_crtc *crtc)
{
126
	return crtc ? container_of(crtc, struct tegra_dc, base) : NULL;
T
Thierry Reding 已提交
127 128 129 130 131 132 133 134 135 136 137 138 139 140
}

static inline void tegra_dc_writel(struct tegra_dc *dc, unsigned long value,
				   unsigned long reg)
{
	writel(value, dc->regs + (reg << 2));
}

static inline unsigned long tegra_dc_readl(struct tegra_dc *dc,
					   unsigned long reg)
{
	return readl(dc->regs + (reg << 2));
}

T
Thierry Reding 已提交
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
struct tegra_dc_window {
	struct {
		unsigned int x;
		unsigned int y;
		unsigned int w;
		unsigned int h;
	} src;
	struct {
		unsigned int x;
		unsigned int y;
		unsigned int w;
		unsigned int h;
	} dst;
	unsigned int bits_per_pixel;
	unsigned int format;
	unsigned int stride[2];
	unsigned long base[3];
158
	bool bottom_up;
159
	bool tiled;
T
Thierry Reding 已提交
160 161 162 163 164 165
};

/* from dc.c */
extern unsigned int tegra_dc_format(uint32_t format);
extern int tegra_dc_setup_window(struct tegra_dc *dc, unsigned int index,
				 const struct tegra_dc_window *window);
166 167
extern void tegra_dc_enable_vblank(struct tegra_dc *dc);
extern void tegra_dc_disable_vblank(struct tegra_dc *dc);
168 169
extern void tegra_dc_cancel_page_flip(struct drm_crtc *crtc,
				      struct drm_file *file);
T
Thierry Reding 已提交
170

T
Thierry Reding 已提交
171 172 173 174 175 176 177 178 179 180 181 182
struct tegra_output_ops {
	int (*enable)(struct tegra_output *output);
	int (*disable)(struct tegra_output *output);
	int (*setup_clock)(struct tegra_output *output, struct clk *clk,
			   unsigned long pclk);
	int (*check_mode)(struct tegra_output *output,
			  struct drm_display_mode *mode,
			  enum drm_mode_status *status);
};

enum tegra_output_type {
	TEGRA_OUTPUT_RGB,
T
Thierry Reding 已提交
183
	TEGRA_OUTPUT_HDMI,
T
Thierry Reding 已提交
184
	TEGRA_OUTPUT_DSI,
T
Thierry Reding 已提交
185 186 187 188 189 190 191 192 193
};

struct tegra_output {
	struct device_node *of_node;
	struct device *dev;

	const struct tegra_output_ops *ops;
	enum tegra_output_type type;

194
	struct drm_panel *panel;
T
Thierry Reding 已提交
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
	struct i2c_adapter *ddc;
	const struct edid *edid;
	unsigned int hpd_irq;
	int hpd_gpio;

	struct drm_encoder encoder;
	struct drm_connector connector;
};

static inline struct tegra_output *encoder_to_output(struct drm_encoder *e)
{
	return container_of(e, struct tegra_output, encoder);
}

static inline struct tegra_output *connector_to_output(struct drm_connector *c)
{
	return container_of(c, struct tegra_output, connector);
}

static inline int tegra_output_enable(struct tegra_output *output)
{
	if (output && output->ops && output->ops->enable)
		return output->ops->enable(output);

	return output ? -ENOSYS : -EINVAL;
}

static inline int tegra_output_disable(struct tegra_output *output)
{
	if (output && output->ops && output->ops->disable)
		return output->ops->disable(output);

	return output ? -ENOSYS : -EINVAL;
}

static inline int tegra_output_setup_clock(struct tegra_output *output,
					   struct clk *clk, unsigned long pclk)
{
	if (output && output->ops && output->ops->setup_clock)
		return output->ops->setup_clock(output, clk, pclk);

	return output ? -ENOSYS : -EINVAL;
}

static inline int tegra_output_check_mode(struct tegra_output *output,
					  struct drm_display_mode *mode,
					  enum drm_mode_status *status)
{
	if (output && output->ops && output->ops->check_mode)
		return output->ops->check_mode(output, mode, status);

	return output ? -ENOSYS : -EINVAL;
}

249 250 251 252
/* from bus.c */
int drm_host1x_init(struct drm_driver *driver, struct host1x_device *device);
void drm_host1x_exit(struct drm_driver *driver, struct host1x_device *device);

T
Thierry Reding 已提交
253 254
/* from rgb.c */
extern int tegra_dc_rgb_probe(struct tegra_dc *dc);
255
extern int tegra_dc_rgb_remove(struct tegra_dc *dc);
T
Thierry Reding 已提交
256 257 258 259
extern int tegra_dc_rgb_init(struct drm_device *drm, struct tegra_dc *dc);
extern int tegra_dc_rgb_exit(struct tegra_dc *dc);

/* from output.c */
260 261
extern int tegra_output_probe(struct tegra_output *output);
extern int tegra_output_remove(struct tegra_output *output);
T
Thierry Reding 已提交
262 263 264 265
extern int tegra_output_init(struct drm_device *drm, struct tegra_output *output);
extern int tegra_output_exit(struct tegra_output *output);

/* from fb.c */
266 267
struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer,
				    unsigned int index);
268
bool tegra_fb_is_bottom_up(struct drm_framebuffer *framebuffer);
269
bool tegra_fb_is_tiled(struct drm_framebuffer *framebuffer);
T
Thierry Reding 已提交
270 271
extern int tegra_drm_fb_init(struct drm_device *drm);
extern void tegra_drm_fb_exit(struct drm_device *drm);
272
#ifdef CONFIG_DRM_TEGRA_FBDEV
273
extern void tegra_fbdev_restore_mode(struct tegra_fbdev *fbdev);
274
#endif
T
Thierry Reding 已提交
275

276
extern struct platform_driver tegra_dc_driver;
T
Thierry Reding 已提交
277
extern struct platform_driver tegra_dsi_driver;
278 279
extern struct platform_driver tegra_hdmi_driver;
extern struct platform_driver tegra_gr2d_driver;
T
Thierry Reding 已提交
280
extern struct platform_driver tegra_gr3d_driver;
T
Thierry Reding 已提交
281

282
#endif /* HOST1X_DRM_H */