mdp5_kms.h 7.9 KB
Newer Older
R
Rob Clark 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * Copyright (C) 2013 Red Hat
 * Author: Rob Clark <robdclark@gmail.com>
 *
 * 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.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef __MDP5_KMS_H__
#define __MDP5_KMS_H__

#include "msm_drv.h"
#include "msm_kms.h"
#include "mdp/mdp_kms.h"
24
#include "mdp5_cfg.h"	/* must be included before mdp5.xml.h */
R
Rob Clark 已提交
25
#include "mdp5.xml.h"
26
#include "mdp5_ctl.h"
R
Rob Clark 已提交
27
#include "mdp5_pipe.h"
R
Rob Clark 已提交
28 29
#include "mdp5_smp.h"

R
Rob Clark 已提交
30 31
struct mdp5_state;

R
Rob Clark 已提交
32 33 34 35 36
struct mdp5_kms {
	struct mdp_kms base;

	struct drm_device *dev;

37 38
	struct platform_device *pdev;

R
Rob Clark 已提交
39 40 41
	unsigned num_hwpipes;
	struct mdp5_hw_pipe *hwpipes[SSPP_MAX];

42
	struct mdp5_cfg_handler *cfg;
43 44
	uint32_t caps;	/* MDP capabilities (MDP_CAP_XXX bits) */

R
Rob Clark 已提交
45 46 47 48 49
	/**
	 * Global atomic state.  Do not access directly, use mdp5_get_state()
	 */
	struct mdp5_state *state;
	struct drm_modeset_lock state_lock;
R
Rob Clark 已提交
50 51 52

	/* mapper-id used to request GEM buffer mapped for scanout: */
	int id;
53
	struct msm_gem_address_space *aspace;
R
Rob Clark 已提交
54

55 56
	struct mdp5_smp *smp;
	struct mdp5_ctl_manager *ctlm;
R
Rob Clark 已提交
57 58

	/* io/register spaces: */
59
	void __iomem *mmio;
R
Rob Clark 已提交
60 61 62 63 64 65 66

	struct clk *axi_clk;
	struct clk *ahb_clk;
	struct clk *core_clk;
	struct clk *lut_clk;
	struct clk *vsync_clk;

67 68
	/*
	 * lock to protect access to global resources: ie., following register:
69
	 *	- REG_MDP5_DISP_INTF_SEL
70 71 72
	 */
	spinlock_t resource_lock;

73 74
	bool rpm_enabled;

R
Rob Clark 已提交
75 76 77 78
	struct mdp_irq error_handler;
};
#define to_mdp5_kms(x) container_of(x, struct mdp5_kms, base)

R
Rob Clark 已提交
79 80 81 82 83 84
/* Global atomic state for tracking resources that are shared across
 * multiple kms objects (planes/crtcs/etc).
 *
 * For atomic updates which require modifying global state,
 */
struct mdp5_state {
85
	struct mdp5_hw_pipe_state hwpipe;
86
	struct mdp5_smp_state smp;
R
Rob Clark 已提交
87 88 89 90 91 92 93 94
};

struct mdp5_state *__must_check
mdp5_get_state(struct drm_atomic_state *s);

/* Atomic plane state.  Subclasses the base drm_plane_state in order to
 * track assigned hwpipe and hw specific state.
 */
R
Rob Clark 已提交
95 96 97
struct mdp5_plane_state {
	struct drm_plane_state base;

98 99
	struct mdp5_hw_pipe *hwpipe;

100 101 102 103
	/* aligned with property */
	uint8_t premultiplied;
	uint8_t zpos;
	uint8_t alpha;
R
Rob Clark 已提交
104

105
	/* assigned by crtc blender */
R
Rob Clark 已提交
106
	enum mdp_mixer_stage_id stage;
107
};
R
Rob Clark 已提交
108 109
#define to_mdp5_plane_state(x) \
		container_of(x, struct mdp5_plane_state, base)
110

111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
enum mdp5_intf_mode {
	MDP5_INTF_MODE_NONE = 0,

	/* Modes used for DSI interface (INTF_DSI type): */
	MDP5_INTF_DSI_MODE_VIDEO,
	MDP5_INTF_DSI_MODE_COMMAND,

	/* Modes used for WB interface (INTF_WB type):  */
	MDP5_INTF_WB_MODE_BLOCK,
	MDP5_INTF_WB_MODE_LINE,
};

struct mdp5_interface {
	int num; /* display interface number */
	enum mdp5_intf_type type;
	enum mdp5_intf_mode mode;
};

129 130 131 132 133 134 135 136 137 138 139
struct mdp5_encoder {
	struct drm_encoder base;
	struct mdp5_interface intf;
	spinlock_t intf_lock;	/* protect REG_MDP5_INTF_* registers */
	bool enabled;
	uint32_t bsc;

	struct mdp5_ctl *ctl;
};
#define to_mdp5_encoder(x) container_of(x, struct mdp5_encoder, base)

R
Rob Clark 已提交
140 141 142 143 144 145 146 147 148 149
static inline void mdp5_write(struct mdp5_kms *mdp5_kms, u32 reg, u32 data)
{
	msm_writel(data, mdp5_kms->mmio + reg);
}

static inline u32 mdp5_read(struct mdp5_kms *mdp5_kms, u32 reg)
{
	return msm_readl(mdp5_kms->mmio + reg);
}

150 151 152 153 154 155 156 157 158 159 160 161
static inline const char *stage2name(enum mdp_mixer_stage_id stage)
{
	static const char *names[] = {
#define NAME(n) [n] = #n
		NAME(STAGE_UNUSED), NAME(STAGE_BASE),
		NAME(STAGE0), NAME(STAGE1), NAME(STAGE2),
		NAME(STAGE3), NAME(STAGE4), NAME(STAGE6),
#undef NAME
	};
	return names[stage];
}

R
Rob Clark 已提交
162 163 164 165 166 167 168
static inline const char *pipe2name(enum mdp5_pipe pipe)
{
	static const char *names[] = {
#define NAME(n) [SSPP_ ## n] = #n
		NAME(VIG0), NAME(VIG1), NAME(VIG2),
		NAME(RGB0), NAME(RGB1), NAME(RGB2),
		NAME(DMA0), NAME(DMA1),
169
		NAME(VIG3), NAME(RGB3),
170
		NAME(CURSOR0), NAME(CURSOR1),
R
Rob Clark 已提交
171 172 173 174 175 176 177 178 179 180 181
#undef NAME
	};
	return names[pipe];
}

static inline int pipe2nclients(enum mdp5_pipe pipe)
{
	switch (pipe) {
	case SSPP_RGB0:
	case SSPP_RGB1:
	case SSPP_RGB2:
182
	case SSPP_RGB3:
R
Rob Clark 已提交
183 184 185 186 187 188
		return 1;
	default:
		return 3;
	}
}

189
static inline uint32_t intf2err(int intf_num)
R
Rob Clark 已提交
190
{
191
	switch (intf_num) {
R
Rob Clark 已提交
192 193 194 195 196 197 198 199
	case 0:  return MDP5_IRQ_INTF0_UNDER_RUN;
	case 1:  return MDP5_IRQ_INTF1_UNDER_RUN;
	case 2:  return MDP5_IRQ_INTF2_UNDER_RUN;
	case 3:  return MDP5_IRQ_INTF3_UNDER_RUN;
	default: return 0;
	}
}

200
#define GET_PING_PONG_ID(layer_mixer)	((layer_mixer == 5) ? 3 : layer_mixer)
201
static inline uint32_t intf2vblank(int lm, struct mdp5_interface *intf)
R
Rob Clark 已提交
202
{
203 204 205 206 207 208 209 210 211 212 213 214 215 216
	/*
	 * In case of DSI Command Mode, the Ping Pong's read pointer IRQ
	 * acts as a Vblank signal. The Ping Pong buffer used is bound to
	 * layer mixer.
	 */

	if ((intf->type == INTF_DSI) &&
			(intf->mode == MDP5_INTF_DSI_MODE_COMMAND))
		return MDP5_IRQ_PING_PONG_0_RD_PTR << GET_PING_PONG_ID(lm);

	if (intf->type == INTF_WB)
		return MDP5_IRQ_WB_2_DONE;

	switch (intf->num) {
R
Rob Clark 已提交
217 218 219 220 221 222 223 224
	case 0:  return MDP5_IRQ_INTF0_VSYNC;
	case 1:  return MDP5_IRQ_INTF1_VSYNC;
	case 2:  return MDP5_IRQ_INTF2_VSYNC;
	case 3:  return MDP5_IRQ_INTF3_VSYNC;
	default: return 0;
	}
}

225 226 227 228 229
static inline uint32_t lm2ppdone(int lm)
{
	return MDP5_IRQ_PING_PONG_0_DONE << GET_PING_PONG_ID(lm);
}

R
Rob Clark 已提交
230 231 232
int mdp5_disable(struct mdp5_kms *mdp5_kms);
int mdp5_enable(struct mdp5_kms *mdp5_kms);

233 234
void mdp5_set_irqmask(struct mdp_kms *mdp_kms, uint32_t irqmask,
		uint32_t old_irqmask);
R
Rob Clark 已提交
235 236 237 238 239 240
void mdp5_irq_preinstall(struct msm_kms *kms);
int mdp5_irq_postinstall(struct msm_kms *kms);
void mdp5_irq_uninstall(struct msm_kms *kms);
irqreturn_t mdp5_irq(struct msm_kms *kms);
int mdp5_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
void mdp5_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
R
Rob Clark 已提交
241 242
int mdp5_irq_domain_init(struct mdp5_kms *mdp5_kms);
void mdp5_irq_domain_fini(struct mdp5_kms *mdp5_kms);
R
Rob Clark 已提交
243

244
uint32_t mdp5_plane_get_flush(struct drm_plane *plane);
R
Rob Clark 已提交
245
enum mdp5_pipe mdp5_plane_pipe(struct drm_plane *plane);
246 247
struct drm_plane *mdp5_plane_init(struct drm_device *dev,
				  enum drm_plane_type type);
R
Rob Clark 已提交
248 249 250

uint32_t mdp5_crtc_vblank(struct drm_crtc *crtc);

251
int mdp5_crtc_get_lm(struct drm_crtc *crtc);
252 253
void mdp5_crtc_set_pipeline(struct drm_crtc *crtc,
		struct mdp5_interface *intf, struct mdp5_ctl *ctl);
254
void mdp5_crtc_wait_for_commit_done(struct drm_crtc *crtc);
R
Rob Clark 已提交
255
struct drm_crtc *mdp5_crtc_init(struct drm_device *dev,
256 257
				struct drm_plane *plane,
				struct drm_plane *cursor_plane, int id);
R
Rob Clark 已提交
258

259
struct drm_encoder *mdp5_encoder_init(struct drm_device *dev,
260
		struct mdp5_interface *intf, struct mdp5_ctl *ctl);
261 262
int mdp5_vid_encoder_set_split_display(struct drm_encoder *encoder,
				       struct drm_encoder *slave_encoder);
263
void mdp5_encoder_set_intf_mode(struct drm_encoder *encoder, bool cmd_mode);
264 265
int mdp5_encoder_get_linecount(struct drm_encoder *encoder);
u32 mdp5_encoder_get_framecount(struct drm_encoder *encoder);
266 267

#ifdef CONFIG_DRM_MSM_DSI
268 269 270 271 272
void mdp5_cmd_encoder_mode_set(struct drm_encoder *encoder,
			       struct drm_display_mode *mode,
			       struct drm_display_mode *adjusted_mode);
void mdp5_cmd_encoder_disable(struct drm_encoder *encoder);
void mdp5_cmd_encoder_enable(struct drm_encoder *encoder);
273
int mdp5_cmd_encoder_set_split_display(struct drm_encoder *encoder,
274
				       struct drm_encoder *slave_encoder);
275
#else
276 277 278 279 280 281 282 283 284
static inline void mdp5_cmd_encoder_mode_set(struct drm_encoder *encoder,
					     struct drm_display_mode *mode,
					     struct drm_display_mode *adjusted_mode)
{
}
static inline void mdp5_cmd_encoder_disable(struct drm_encoder *encoder)
{
}
static inline void mdp5_cmd_encoder_enable(struct drm_encoder *encoder)
285 286 287 288 289 290 291 292
{
}
static inline int mdp5_cmd_encoder_set_split_display(
	struct drm_encoder *encoder, struct drm_encoder *slave_encoder)
{
	return -EINVAL;
}
#endif
R
Rob Clark 已提交
293 294

#endif /* __MDP5_KMS_H__ */