drm.h 8.6 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>

22 23
#include "gem.h"

S
Stephen Warren 已提交
24 25
struct reset_control;

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

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

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

T
Thierry Reding 已提交
42 43 44
	struct iommu_domain *domain;
	struct drm_mm mm;

T
Thierry Reding 已提交
45 46 47
	struct mutex clients_lock;
	struct list_head clients;

48
#ifdef CONFIG_DRM_TEGRA_FBDEV
49
	struct tegra_fbdev *fbdev;
50
#endif
51 52

	unsigned int pitch_align;
T
Thierry Reding 已提交
53 54
};

55
struct tegra_drm_client;
T
Thierry Reding 已提交
56

57
struct tegra_drm_context {
58
	struct tegra_drm_client *client;
T
Terje Bergstrom 已提交
59 60 61 62
	struct host1x_channel *channel;
	struct list_head list;
};

63 64
struct tegra_drm_client_ops {
	int (*open_channel)(struct tegra_drm_client *client,
65 66
			    struct tegra_drm_context *context);
	void (*close_channel)(struct tegra_drm_context *context);
67
	int (*is_addr_reg)(struct device *dev, u32 class, u32 offset);
68
	int (*submit)(struct tegra_drm_context *context,
T
Terje Bergstrom 已提交
69 70 71 72
		      struct drm_tegra_submit *args, struct drm_device *drm,
		      struct drm_file *file);
};

73 74 75 76
int tegra_drm_submit(struct tegra_drm_context *context,
		     struct drm_tegra_submit *args, struct drm_device *drm,
		     struct drm_file *file);

77 78
struct tegra_drm_client {
	struct host1x_client base;
79
	struct list_head list;
T
Terje Bergstrom 已提交
80

81
	const struct tegra_drm_client_ops *ops;
T
Thierry Reding 已提交
82 83
};

84
static inline struct tegra_drm_client *
85
host1x_to_drm_client(struct host1x_client *client)
86 87 88 89
{
	return container_of(client, struct tegra_drm_client, base);
}

T
Thierry Reding 已提交
90 91 92 93
int tegra_drm_register_client(struct tegra_drm *tegra,
			      struct tegra_drm_client *client);
int tegra_drm_unregister_client(struct tegra_drm *tegra,
				struct tegra_drm_client *client);
94

T
Thierry Reding 已提交
95 96
int tegra_drm_init(struct tegra_drm *tegra, struct drm_device *drm);
int tegra_drm_exit(struct tegra_drm *tegra);
T
Thierry Reding 已提交
97

98
struct tegra_dc_soc_info;
T
Thierry Reding 已提交
99 100 101
struct tegra_output;

struct tegra_dc {
102
	struct host1x_client client;
T
Thierry Reding 已提交
103
	struct device *dev;
104
	spinlock_t lock;
T
Thierry Reding 已提交
105 106

	struct drm_crtc base;
107
	int powergate;
T
Thierry Reding 已提交
108 109 110
	int pipe;

	struct clk *clk;
S
Stephen Warren 已提交
111
	struct reset_control *rst;
T
Thierry Reding 已提交
112 113 114 115 116 117 118 119 120 121
	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;
122 123 124

	/* page-flip handling */
	struct drm_pending_vblank_event *event;
125 126

	const struct tegra_dc_soc_info *soc;
T
Thierry Reding 已提交
127 128

	struct iommu_domain *domain;
T
Thierry Reding 已提交
129 130
};

131
static inline struct tegra_dc *
132
host1x_client_to_dc(struct host1x_client *client)
T
Thierry Reding 已提交
133 134 135 136 137 138
{
	return container_of(client, struct tegra_dc, client);
}

static inline struct tegra_dc *to_tegra_dc(struct drm_crtc *crtc)
{
139
	return crtc ? container_of(crtc, struct tegra_dc, base) : NULL;
T
Thierry Reding 已提交
140 141
}

142 143
static inline void tegra_dc_writel(struct tegra_dc *dc, u32 value,
				   unsigned long offset)
T
Thierry Reding 已提交
144
{
145
	writel(value, dc->regs + (offset << 2));
T
Thierry Reding 已提交
146 147
}

148
static inline u32 tegra_dc_readl(struct tegra_dc *dc, unsigned long offset)
T
Thierry Reding 已提交
149
{
150
	return readl(dc->regs + (offset << 2));
T
Thierry Reding 已提交
151 152
}

T
Thierry Reding 已提交
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
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;
168
	unsigned int swap;
T
Thierry Reding 已提交
169 170
	unsigned int stride[2];
	unsigned long base[3];
171
	bool bottom_up;
172 173

	struct tegra_bo_tiling tiling;
T
Thierry Reding 已提交
174 175 176
};

/* from dc.c */
T
Thierry Reding 已提交
177 178 179
void tegra_dc_enable_vblank(struct tegra_dc *dc);
void tegra_dc_disable_vblank(struct tegra_dc *dc);
void tegra_dc_cancel_page_flip(struct drm_crtc *crtc, struct drm_file *file);
180
void tegra_dc_commit(struct tegra_dc *dc);
T
Thierry Reding 已提交
181

T
Thierry Reding 已提交
182 183 184 185
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,
186
			   unsigned long pclk, unsigned int *div);
T
Thierry Reding 已提交
187 188 189
	int (*check_mode)(struct tegra_output *output,
			  struct drm_display_mode *mode,
			  enum drm_mode_status *status);
T
Thierry Reding 已提交
190
	enum drm_connector_status (*detect)(struct tegra_output *output);
T
Thierry Reding 已提交
191 192 193 194
};

enum tegra_output_type {
	TEGRA_OUTPUT_RGB,
T
Thierry Reding 已提交
195
	TEGRA_OUTPUT_HDMI,
T
Thierry Reding 已提交
196
	TEGRA_OUTPUT_DSI,
T
Thierry Reding 已提交
197
	TEGRA_OUTPUT_EDP,
T
Thierry Reding 已提交
198 199 200 201 202 203 204 205 206
};

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

	const struct tegra_output_ops *ops;
	enum tegra_output_type type;

207
	struct drm_panel *panel;
T
Thierry Reding 已提交
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
	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,
244 245
					   struct clk *clk, unsigned long pclk,
					   unsigned int *div)
T
Thierry Reding 已提交
246 247
{
	if (output && output->ops && output->ops->setup_clock)
248
		return output->ops->setup_clock(output, clk, pclk, div);
T
Thierry Reding 已提交
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263

	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;
}

/* from rgb.c */
T
Thierry Reding 已提交
264 265 266 267
int tegra_dc_rgb_probe(struct tegra_dc *dc);
int tegra_dc_rgb_remove(struct tegra_dc *dc);
int tegra_dc_rgb_init(struct drm_device *drm, struct tegra_dc *dc);
int tegra_dc_rgb_exit(struct tegra_dc *dc);
T
Thierry Reding 已提交
268 269

/* from output.c */
T
Thierry Reding 已提交
270 271 272 273
int tegra_output_probe(struct tegra_output *output);
int tegra_output_remove(struct tegra_output *output);
int tegra_output_init(struct drm_device *drm, struct tegra_output *output);
int tegra_output_exit(struct tegra_output *output);
T
Thierry Reding 已提交
274

275 276 277 278 279 280 281 282 283
int tegra_output_connector_get_modes(struct drm_connector *connector);
struct drm_encoder *
tegra_output_connector_best_encoder(struct drm_connector *connector);
enum drm_connector_status
tegra_output_connector_detect(struct drm_connector *connector, bool force);
void tegra_output_connector_destroy(struct drm_connector *connector);

void tegra_output_encoder_destroy(struct drm_encoder *encoder);

T
Thierry Reding 已提交
284 285 286 287 288 289 290 291 292 293 294 295 296 297
/* from dpaux.c */
struct tegra_dpaux;
struct drm_dp_link;

struct tegra_dpaux *tegra_dpaux_find_by_of_node(struct device_node *np);
enum drm_connector_status tegra_dpaux_detect(struct tegra_dpaux *dpaux);
int tegra_dpaux_attach(struct tegra_dpaux *dpaux, struct tegra_output *output);
int tegra_dpaux_detach(struct tegra_dpaux *dpaux);
int tegra_dpaux_enable(struct tegra_dpaux *dpaux);
int tegra_dpaux_disable(struct tegra_dpaux *dpaux);
int tegra_dpaux_prepare(struct tegra_dpaux *dpaux, u8 encoding);
int tegra_dpaux_train(struct tegra_dpaux *dpaux, struct drm_dp_link *link,
		      u8 pattern);

T
Thierry Reding 已提交
298
/* from fb.c */
299 300
struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer,
				    unsigned int index);
301
bool tegra_fb_is_bottom_up(struct drm_framebuffer *framebuffer);
302 303
int tegra_fb_get_tiling(struct drm_framebuffer *framebuffer,
			struct tegra_bo_tiling *tiling);
304 305 306
struct drm_framebuffer *tegra_fb_create(struct drm_device *drm,
					struct drm_file *file,
					struct drm_mode_fb_cmd2 *cmd);
307
int tegra_drm_fb_prepare(struct drm_device *drm);
308
void tegra_drm_fb_free(struct drm_device *drm);
T
Thierry Reding 已提交
309 310
int tegra_drm_fb_init(struct drm_device *drm);
void tegra_drm_fb_exit(struct drm_device *drm);
311
#ifdef CONFIG_DRM_TEGRA_FBDEV
T
Thierry Reding 已提交
312
void tegra_fbdev_restore_mode(struct tegra_fbdev *fbdev);
313
void tegra_fb_output_poll_changed(struct drm_device *drm);
314
#endif
T
Thierry Reding 已提交
315

316
extern struct platform_driver tegra_dc_driver;
T
Thierry Reding 已提交
317
extern struct platform_driver tegra_dsi_driver;
T
Thierry Reding 已提交
318
extern struct platform_driver tegra_sor_driver;
319
extern struct platform_driver tegra_hdmi_driver;
T
Thierry Reding 已提交
320
extern struct platform_driver tegra_dpaux_driver;
321
extern struct platform_driver tegra_gr2d_driver;
T
Thierry Reding 已提交
322
extern struct platform_driver tegra_gr3d_driver;
T
Thierry Reding 已提交
323

324
#endif /* HOST1X_DRM_H */