2 * Copyright (C) 2013 Red Hat
3 * Author: Rob Clark <robdclark@gmail.com>
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef __MDP4_KMS_H__
19 #define __MDP4_KMS_H__
23 #include "mdp/mdp_kms.h"
29 struct drm_device *dev;
33 /* mapper-id used to request GEM buffer mapped for scanout: */
38 struct regulator *dsi_pll_vdda;
39 struct regulator *dsi_pll_vddio;
40 struct regulator *vdd;
46 struct mdp_irq error_handler;
48 /* empty/blank cursor bo to use when cursor is "disabled" */
49 struct drm_gem_object *blank_cursor_bo;
50 uint32_t blank_cursor_iova;
52 #define to_mdp4_kms(x) container_of(x, struct mdp4_kms, base)
54 /* platform config data (ie. from DT, or pdata) */
55 struct mdp4_platform_config {
56 struct iommu_domain *iommu;
60 static inline void mdp4_write(struct mdp4_kms *mdp4_kms, u32 reg, u32 data)
62 msm_writel(data, mdp4_kms->mmio + reg);
65 static inline u32 mdp4_read(struct mdp4_kms *mdp4_kms, u32 reg)
67 return msm_readl(mdp4_kms->mmio + reg);
70 static inline uint32_t pipe2flush(enum mdp4_pipe pipe)
73 case VG1: return MDP4_OVERLAY_FLUSH_VG1;
74 case VG2: return MDP4_OVERLAY_FLUSH_VG2;
75 case RGB1: return MDP4_OVERLAY_FLUSH_RGB1;
76 case RGB2: return MDP4_OVERLAY_FLUSH_RGB1;
81 static inline uint32_t ovlp2flush(int ovlp)
84 case 0: return MDP4_OVERLAY_FLUSH_OVLP0;
85 case 1: return MDP4_OVERLAY_FLUSH_OVLP1;
90 static inline uint32_t dma2irq(enum mdp4_dma dma)
93 case DMA_P: return MDP4_IRQ_DMA_P_DONE;
94 case DMA_S: return MDP4_IRQ_DMA_S_DONE;
95 case DMA_E: return MDP4_IRQ_DMA_E_DONE;
100 static inline uint32_t dma2err(enum mdp4_dma dma)
103 case DMA_P: return MDP4_IRQ_PRIMARY_INTF_UDERRUN;
104 case DMA_S: return 0; // ???
105 case DMA_E: return MDP4_IRQ_EXTERNAL_INTF_UDERRUN;
110 static inline uint32_t mixercfg(int mixer, enum mdp4_pipe pipe,
111 enum mdp_mixer_stage_id stage)
113 uint32_t mixer_cfg = 0;
117 mixer_cfg = MDP4_LAYERMIXER_IN_CFG_PIPE0(stage) |
118 COND(mixer == 1, MDP4_LAYERMIXER_IN_CFG_PIPE0_MIXER1);
121 mixer_cfg = MDP4_LAYERMIXER_IN_CFG_PIPE1(stage) |
122 COND(mixer == 1, MDP4_LAYERMIXER_IN_CFG_PIPE1_MIXER1);
125 mixer_cfg = MDP4_LAYERMIXER_IN_CFG_PIPE2(stage) |
126 COND(mixer == 1, MDP4_LAYERMIXER_IN_CFG_PIPE2_MIXER1);
129 mixer_cfg = MDP4_LAYERMIXER_IN_CFG_PIPE3(stage) |
130 COND(mixer == 1, MDP4_LAYERMIXER_IN_CFG_PIPE3_MIXER1);
133 mixer_cfg = MDP4_LAYERMIXER_IN_CFG_PIPE4(stage) |
134 COND(mixer == 1, MDP4_LAYERMIXER_IN_CFG_PIPE4_MIXER1);
137 mixer_cfg = MDP4_LAYERMIXER_IN_CFG_PIPE5(stage) |
138 COND(mixer == 1, MDP4_LAYERMIXER_IN_CFG_PIPE5_MIXER1);
141 mixer_cfg = MDP4_LAYERMIXER_IN_CFG_PIPE6(stage) |
142 COND(mixer == 1, MDP4_LAYERMIXER_IN_CFG_PIPE6_MIXER1);
145 WARN_ON("invalid pipe");
152 int mdp4_disable(struct mdp4_kms *mdp4_kms);
153 int mdp4_enable(struct mdp4_kms *mdp4_kms);
155 void mdp4_set_irqmask(struct mdp_kms *mdp_kms, uint32_t irqmask);
156 void mdp4_irq_preinstall(struct msm_kms *kms);
157 int mdp4_irq_postinstall(struct msm_kms *kms);
158 void mdp4_irq_uninstall(struct msm_kms *kms);
159 irqreturn_t mdp4_irq(struct msm_kms *kms);
160 int mdp4_enable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
161 void mdp4_disable_vblank(struct msm_kms *kms, struct drm_crtc *crtc);
164 uint32_t mdp4_get_formats(enum mdp4_pipe pipe_id, uint32_t *pixel_formats,
165 uint32_t max_formats)
167 /* TODO when we have YUV, we need to filter supported formats
170 return mdp_get_formats(pixel_formats, max_formats);
173 void mdp4_plane_install_properties(struct drm_plane *plane,
174 struct drm_mode_object *obj);
175 void mdp4_plane_set_scanout(struct drm_plane *plane,
176 struct drm_framebuffer *fb);
177 int mdp4_plane_mode_set(struct drm_plane *plane,
178 struct drm_crtc *crtc, struct drm_framebuffer *fb,
179 int crtc_x, int crtc_y,
180 unsigned int crtc_w, unsigned int crtc_h,
181 uint32_t src_x, uint32_t src_y,
182 uint32_t src_w, uint32_t src_h);
183 enum mdp4_pipe mdp4_plane_pipe(struct drm_plane *plane);
184 struct drm_plane *mdp4_plane_init(struct drm_device *dev,
185 enum mdp4_pipe pipe_id, bool private_plane);
187 uint32_t mdp4_crtc_vblank(struct drm_crtc *crtc);
188 void mdp4_crtc_cancel_pending_flip(struct drm_crtc *crtc, struct drm_file *file);
189 void mdp4_crtc_set_config(struct drm_crtc *crtc, uint32_t config);
190 void mdp4_crtc_set_intf(struct drm_crtc *crtc, enum mdp4_intf intf);
191 void mdp4_crtc_attach(struct drm_crtc *crtc, struct drm_plane *plane);
192 void mdp4_crtc_detach(struct drm_crtc *crtc, struct drm_plane *plane);
193 struct drm_crtc *mdp4_crtc_init(struct drm_device *dev,
194 struct drm_plane *plane, int id, int ovlp_id,
195 enum mdp4_dma dma_id);
197 long mdp4_dtv_round_pixclk(struct drm_encoder *encoder, unsigned long rate);
198 struct drm_encoder *mdp4_dtv_encoder_init(struct drm_device *dev);
200 #ifdef CONFIG_MSM_BUS_SCALING
201 static inline int match_dev_name(struct device *dev, void *data)
203 return !strcmp(dev_name(dev), data);
205 /* bus scaling data is associated with extra pointless platform devices,
206 * "dtv", etc.. this is a bit of a hack, but we need a way for encoders
207 * to find their pdata to make the bus-scaling stuff work.
209 static inline void *mdp4_find_pdata(const char *devname)
212 dev = bus_find_device(&platform_bus_type, NULL,
213 (void *)devname, match_dev_name);
214 return dev ? dev->platform_data : NULL;
218 #endif /* __MDP4_KMS_H__ */