xref: /linux/drivers/gpu/drm/msm/disp/mdp4/mdp4_kms.h (revision db5d28c0bfe566908719bec8e25443aabecbb802)
1caab277bSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
214be3200SRob Clark /*
314be3200SRob Clark  * Copyright (C) 2013 Red Hat
414be3200SRob Clark  * Author: Rob Clark <robdclark@gmail.com>
514be3200SRob Clark  */
614be3200SRob Clark 
714be3200SRob Clark #ifndef __MDP4_KMS_H__
814be3200SRob Clark #define __MDP4_KMS_H__
914be3200SRob Clark 
1014be3200SRob Clark #include <drm/drm_panel.h>
1114be3200SRob Clark 
1214be3200SRob Clark #include "msm_drv.h"
1314be3200SRob Clark #include "msm_kms.h"
1414be3200SRob Clark #include "disp/mdp_kms.h"
1514be3200SRob Clark #include "mdp4.xml.h"
1614be3200SRob Clark 
1714be3200SRob Clark struct device_node;
1814be3200SRob Clark 
1914be3200SRob Clark struct mdp4_kms {
2014be3200SRob Clark 	struct mdp_kms base;
2114be3200SRob Clark 
2214be3200SRob Clark 	struct drm_device *dev;
2314be3200SRob Clark 
2414be3200SRob Clark 	int rev;
2514be3200SRob Clark 
2614be3200SRob Clark 	void __iomem *mmio;
2714be3200SRob Clark 
2814be3200SRob Clark 	struct regulator *vdd;
2914be3200SRob Clark 
3014be3200SRob Clark 	struct clk *clk;
3114be3200SRob Clark 	struct clk *pclk;
3214be3200SRob Clark 	struct clk *lut_clk;
3314be3200SRob Clark 	struct clk *axi_clk;
3414be3200SRob Clark 
3514be3200SRob Clark 	struct mdp_irq error_handler;
3614be3200SRob Clark 
3714be3200SRob Clark 	bool rpm_enabled;
3814be3200SRob Clark 
3914be3200SRob Clark 	/* empty/blank cursor bo to use when cursor is "disabled" */
4014be3200SRob Clark 	struct drm_gem_object *blank_cursor_bo;
4114be3200SRob Clark 	uint64_t blank_cursor_iova;
4214be3200SRob Clark };
4314be3200SRob Clark #define to_mdp4_kms(x) container_of(x, struct mdp4_kms, base)
4414be3200SRob Clark 
mdp4_write(struct mdp4_kms * mdp4_kms,u32 reg,u32 data)4514be3200SRob Clark static inline void mdp4_write(struct mdp4_kms *mdp4_kms, u32 reg, u32 data)
4614be3200SRob Clark {
47*0efadfb0SKonrad Dybcio 	writel(data, mdp4_kms->mmio + reg);
4814be3200SRob Clark }
4914be3200SRob Clark 
mdp4_read(struct mdp4_kms * mdp4_kms,u32 reg)5014be3200SRob Clark static inline u32 mdp4_read(struct mdp4_kms *mdp4_kms, u32 reg)
5114be3200SRob Clark {
52*0efadfb0SKonrad Dybcio 	return readl(mdp4_kms->mmio + reg);
5314be3200SRob Clark }
5414be3200SRob Clark 
pipe2flush(enum mdp4_pipe pipe)5514be3200SRob Clark static inline uint32_t pipe2flush(enum mdp4_pipe pipe)
5614be3200SRob Clark {
5714be3200SRob Clark 	switch (pipe) {
5814be3200SRob Clark 	case VG1:      return MDP4_OVERLAY_FLUSH_VG1;
5914be3200SRob Clark 	case VG2:      return MDP4_OVERLAY_FLUSH_VG2;
6014be3200SRob Clark 	case RGB1:     return MDP4_OVERLAY_FLUSH_RGB1;
6114be3200SRob Clark 	case RGB2:     return MDP4_OVERLAY_FLUSH_RGB2;
6214be3200SRob Clark 	default:       return 0;
6314be3200SRob Clark 	}
6414be3200SRob Clark }
6514be3200SRob Clark 
ovlp2flush(int ovlp)6614be3200SRob Clark static inline uint32_t ovlp2flush(int ovlp)
6714be3200SRob Clark {
6814be3200SRob Clark 	switch (ovlp) {
6914be3200SRob Clark 	case 0:        return MDP4_OVERLAY_FLUSH_OVLP0;
7014be3200SRob Clark 	case 1:        return MDP4_OVERLAY_FLUSH_OVLP1;
7114be3200SRob Clark 	default:       return 0;
7214be3200SRob Clark 	}
7314be3200SRob Clark }
7414be3200SRob Clark 
dma2irq(enum mdp4_dma dma)7514be3200SRob Clark static inline uint32_t dma2irq(enum mdp4_dma dma)
7614be3200SRob Clark {
7714be3200SRob Clark 	switch (dma) {
7814be3200SRob Clark 	case DMA_P:    return MDP4_IRQ_DMA_P_DONE;
7914be3200SRob Clark 	case DMA_S:    return MDP4_IRQ_DMA_S_DONE;
8014be3200SRob Clark 	case DMA_E:    return MDP4_IRQ_DMA_E_DONE;
8114be3200SRob Clark 	default:       return 0;
8214be3200SRob Clark 	}
8314be3200SRob Clark }
8414be3200SRob Clark 
dma2err(enum mdp4_dma dma)8514be3200SRob Clark static inline uint32_t dma2err(enum mdp4_dma dma)
8614be3200SRob Clark {
8714be3200SRob Clark 	switch (dma) {
8814be3200SRob Clark 	case DMA_P:    return MDP4_IRQ_PRIMARY_INTF_UDERRUN;
8914be3200SRob Clark 	case DMA_S:    return 0;  // ???
9014be3200SRob Clark 	case DMA_E:    return MDP4_IRQ_EXTERNAL_INTF_UDERRUN;
9114be3200SRob Clark 	default:       return 0;
9214be3200SRob Clark 	}
9314be3200SRob Clark }
9414be3200SRob Clark 
mixercfg(uint32_t mixer_cfg,int mixer,enum mdp4_pipe pipe,enum mdp_mixer_stage_id stage)9514be3200SRob Clark static inline uint32_t mixercfg(uint32_t mixer_cfg, int mixer,
9614be3200SRob Clark 		enum mdp4_pipe pipe, enum mdp_mixer_stage_id stage)
9714be3200SRob Clark {
9814be3200SRob Clark 	switch (pipe) {
9914be3200SRob Clark 	case VG1:
10014be3200SRob Clark 		mixer_cfg &= ~(MDP4_LAYERMIXER_IN_CFG_PIPE0__MASK |
10114be3200SRob Clark 				MDP4_LAYERMIXER_IN_CFG_PIPE0_MIXER1);
10214be3200SRob Clark 		mixer_cfg |= MDP4_LAYERMIXER_IN_CFG_PIPE0(stage) |
10314be3200SRob Clark 			COND(mixer == 1, MDP4_LAYERMIXER_IN_CFG_PIPE0_MIXER1);
10414be3200SRob Clark 		break;
10514be3200SRob Clark 	case VG2:
10614be3200SRob Clark 		mixer_cfg &= ~(MDP4_LAYERMIXER_IN_CFG_PIPE1__MASK |
10714be3200SRob Clark 				MDP4_LAYERMIXER_IN_CFG_PIPE1_MIXER1);
10814be3200SRob Clark 		mixer_cfg |= MDP4_LAYERMIXER_IN_CFG_PIPE1(stage) |
10914be3200SRob Clark 			COND(mixer == 1, MDP4_LAYERMIXER_IN_CFG_PIPE1_MIXER1);
11014be3200SRob Clark 		break;
11114be3200SRob Clark 	case RGB1:
11214be3200SRob Clark 		mixer_cfg &= ~(MDP4_LAYERMIXER_IN_CFG_PIPE2__MASK |
11314be3200SRob Clark 				MDP4_LAYERMIXER_IN_CFG_PIPE2_MIXER1);
11414be3200SRob Clark 		mixer_cfg |= MDP4_LAYERMIXER_IN_CFG_PIPE2(stage) |
11514be3200SRob Clark 			COND(mixer == 1, MDP4_LAYERMIXER_IN_CFG_PIPE2_MIXER1);
11614be3200SRob Clark 		break;
11714be3200SRob Clark 	case RGB2:
11814be3200SRob Clark 		mixer_cfg &= ~(MDP4_LAYERMIXER_IN_CFG_PIPE3__MASK |
11914be3200SRob Clark 				MDP4_LAYERMIXER_IN_CFG_PIPE3_MIXER1);
12014be3200SRob Clark 		mixer_cfg |= MDP4_LAYERMIXER_IN_CFG_PIPE3(stage) |
12114be3200SRob Clark 			COND(mixer == 1, MDP4_LAYERMIXER_IN_CFG_PIPE3_MIXER1);
12214be3200SRob Clark 		break;
12314be3200SRob Clark 	case RGB3:
12414be3200SRob Clark 		mixer_cfg &= ~(MDP4_LAYERMIXER_IN_CFG_PIPE4__MASK |
12514be3200SRob Clark 				MDP4_LAYERMIXER_IN_CFG_PIPE4_MIXER1);
12614be3200SRob Clark 		mixer_cfg |= MDP4_LAYERMIXER_IN_CFG_PIPE4(stage) |
12714be3200SRob Clark 			COND(mixer == 1, MDP4_LAYERMIXER_IN_CFG_PIPE4_MIXER1);
12814be3200SRob Clark 		break;
12914be3200SRob Clark 	case VG3:
13014be3200SRob Clark 		mixer_cfg &= ~(MDP4_LAYERMIXER_IN_CFG_PIPE5__MASK |
13114be3200SRob Clark 				MDP4_LAYERMIXER_IN_CFG_PIPE5_MIXER1);
13214be3200SRob Clark 		mixer_cfg |= MDP4_LAYERMIXER_IN_CFG_PIPE5(stage) |
13314be3200SRob Clark 			COND(mixer == 1, MDP4_LAYERMIXER_IN_CFG_PIPE5_MIXER1);
13414be3200SRob Clark 		break;
13514be3200SRob Clark 	case VG4:
13614be3200SRob Clark 		mixer_cfg &= ~(MDP4_LAYERMIXER_IN_CFG_PIPE6__MASK |
13714be3200SRob Clark 				MDP4_LAYERMIXER_IN_CFG_PIPE6_MIXER1);
13814be3200SRob Clark 		mixer_cfg |= MDP4_LAYERMIXER_IN_CFG_PIPE6(stage) |
13914be3200SRob Clark 			COND(mixer == 1, MDP4_LAYERMIXER_IN_CFG_PIPE6_MIXER1);
14014be3200SRob Clark 		break;
14114be3200SRob Clark 	default:
14214be3200SRob Clark 		WARN(1, "invalid pipe");
14314be3200SRob Clark 		break;
14414be3200SRob Clark 	}
14514be3200SRob Clark 
14614be3200SRob Clark 	return mixer_cfg;
14714be3200SRob Clark }
14814be3200SRob Clark 
14914be3200SRob Clark int mdp4_disable(struct mdp4_kms *mdp4_kms);
15014be3200SRob Clark int mdp4_enable(struct mdp4_kms *mdp4_kms);
15114be3200SRob Clark 
15214be3200SRob Clark void mdp4_set_irqmask(struct mdp_kms *mdp_kms, uint32_t irqmask,
15314be3200SRob Clark 		uint32_t old_irqmask);
15414be3200SRob Clark void mdp4_irq_preinstall(struct msm_kms *kms);
15514be3200SRob Clark int mdp4_irq_postinstall(struct msm_kms *kms);
15614be3200SRob Clark void mdp4_irq_uninstall(struct msm_kms *kms);
15714be3200SRob Clark irqreturn_t mdp4_irq(struct msm_kms *kms);
15814be3200SRob Clark int mdp4_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
15914be3200SRob Clark void mdp4_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
16014be3200SRob Clark 
mdp4_pipe_caps(enum mdp4_pipe pipe)16114be3200SRob Clark static inline uint32_t mdp4_pipe_caps(enum mdp4_pipe pipe)
16214be3200SRob Clark {
16314be3200SRob Clark 	switch (pipe) {
16414be3200SRob Clark 	case VG1:
16514be3200SRob Clark 	case VG2:
16614be3200SRob Clark 	case VG3:
16714be3200SRob Clark 	case VG4:
16814be3200SRob Clark 		return MDP_PIPE_CAP_HFLIP | MDP_PIPE_CAP_VFLIP |
16914be3200SRob Clark 				MDP_PIPE_CAP_SCALE | MDP_PIPE_CAP_CSC;
17014be3200SRob Clark 	case RGB1:
17114be3200SRob Clark 	case RGB2:
17214be3200SRob Clark 	case RGB3:
17314be3200SRob Clark 		return MDP_PIPE_CAP_SCALE;
17414be3200SRob Clark 	default:
17514be3200SRob Clark 		return 0;
17614be3200SRob Clark 	}
17714be3200SRob Clark }
17814be3200SRob Clark 
17914be3200SRob Clark enum mdp4_pipe mdp4_plane_pipe(struct drm_plane *plane);
18014be3200SRob Clark struct drm_plane *mdp4_plane_init(struct drm_device *dev,
18114be3200SRob Clark 		enum mdp4_pipe pipe_id, bool private_plane);
18214be3200SRob Clark 
18314be3200SRob Clark uint32_t mdp4_crtc_vblank(struct drm_crtc *crtc);
18414be3200SRob Clark void mdp4_crtc_set_config(struct drm_crtc *crtc, uint32_t config);
18514be3200SRob Clark void mdp4_crtc_set_intf(struct drm_crtc *crtc, enum mdp4_intf intf, int mixer);
18614be3200SRob Clark void mdp4_crtc_wait_for_commit_done(struct drm_crtc *crtc);
18714be3200SRob Clark struct drm_crtc *mdp4_crtc_init(struct drm_device *dev,
18814be3200SRob Clark 		struct drm_plane *plane, int id, int ovlp_id,
18914be3200SRob Clark 		enum mdp4_dma dma_id);
19014be3200SRob Clark 
19114be3200SRob Clark long mdp4_dtv_round_pixclk(struct drm_encoder *encoder, unsigned long rate);
19214be3200SRob Clark struct drm_encoder *mdp4_dtv_encoder_init(struct drm_device *dev);
19314be3200SRob Clark 
19414be3200SRob Clark long mdp4_lcdc_round_pixclk(struct drm_encoder *encoder, unsigned long rate);
19514be3200SRob Clark struct drm_encoder *mdp4_lcdc_encoder_init(struct drm_device *dev,
19614be3200SRob Clark 		struct device_node *panel_node);
19714be3200SRob Clark 
19814be3200SRob Clark struct drm_connector *mdp4_lvds_connector_init(struct drm_device *dev,
19914be3200SRob Clark 		struct device_node *panel_node, struct drm_encoder *encoder);
20014be3200SRob Clark 
20114be3200SRob Clark #ifdef CONFIG_DRM_MSM_DSI
20214be3200SRob Clark struct drm_encoder *mdp4_dsi_encoder_init(struct drm_device *dev);
20314be3200SRob Clark #else
mdp4_dsi_encoder_init(struct drm_device * dev)20414be3200SRob Clark static inline struct drm_encoder *mdp4_dsi_encoder_init(struct drm_device *dev)
20514be3200SRob Clark {
20614be3200SRob Clark 	return ERR_PTR(-ENODEV);
20714be3200SRob Clark }
20814be3200SRob Clark #endif
20914be3200SRob Clark 
21014be3200SRob Clark #ifdef CONFIG_COMMON_CLK
21114be3200SRob Clark struct clk *mpd4_lvds_pll_init(struct drm_device *dev);
21214be3200SRob Clark #else
mpd4_lvds_pll_init(struct drm_device * dev)21314be3200SRob Clark static inline struct clk *mpd4_lvds_pll_init(struct drm_device *dev)
21414be3200SRob Clark {
21514be3200SRob Clark 	return ERR_PTR(-ENODEV);
21614be3200SRob Clark }
21714be3200SRob Clark #endif
21814be3200SRob Clark 
21914be3200SRob Clark #endif /* __MDP4_KMS_H__ */
220