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/>.
22 static struct mdp4_platform_config *mdp4_get_config(struct platform_device *dev);
24 static int mdp4_hw_init(struct msm_kms *kms)
26 struct mdp4_kms *mdp4_kms = to_mdp4_kms(kms);
27 struct drm_device *dev = mdp4_kms->dev;
28 uint32_t version, major, minor, dmap_cfg, vg_cfg;
32 pm_runtime_get_sync(dev->dev);
34 version = mdp4_read(mdp4_kms, REG_MDP4_VERSION);
36 major = FIELD(version, MDP4_VERSION_MAJOR);
37 minor = FIELD(version, MDP4_VERSION_MINOR);
39 DBG("found MDP version v%d.%d", major, minor);
42 dev_err(dev->dev, "unexpected MDP version: v%d.%d\n",
48 mdp4_kms->rev = minor;
50 if (mdp4_kms->dsi_pll_vdda) {
51 if ((mdp4_kms->rev == 2) || (mdp4_kms->rev == 4)) {
52 ret = regulator_set_voltage(mdp4_kms->dsi_pll_vdda,
56 "failed to set dsi_pll_vdda voltage: %d\n", ret);
62 if (mdp4_kms->dsi_pll_vddio) {
63 if (mdp4_kms->rev == 2) {
64 ret = regulator_set_voltage(mdp4_kms->dsi_pll_vddio,
68 "failed to set dsi_pll_vddio voltage: %d\n", ret);
74 if (mdp4_kms->rev > 1) {
75 mdp4_write(mdp4_kms, REG_MDP4_CS_CONTROLLER0, 0x0707ffff);
76 mdp4_write(mdp4_kms, REG_MDP4_CS_CONTROLLER1, 0x03073f3f);
79 mdp4_write(mdp4_kms, REG_MDP4_PORTMAP_MODE, 0x3);
81 /* max read pending cmd config, 3 pending requests: */
82 mdp4_write(mdp4_kms, REG_MDP4_READ_CNFG, 0x02222);
84 clk = clk_get_rate(mdp4_kms->clk);
86 if ((mdp4_kms->rev >= 1) || (clk >= 90000000)) {
87 dmap_cfg = 0x47; /* 16 bytes-burst x 8 req */
88 vg_cfg = 0x47; /* 16 bytes-burs x 8 req */
90 dmap_cfg = 0x27; /* 8 bytes-burst x 8 req */
91 vg_cfg = 0x43; /* 16 bytes-burst x 4 req */
94 DBG("fetch config: dmap=%02x, vg=%02x", dmap_cfg, vg_cfg);
96 mdp4_write(mdp4_kms, REG_MDP4_DMA_FETCH_CONFIG(DMA_P), dmap_cfg);
97 mdp4_write(mdp4_kms, REG_MDP4_DMA_FETCH_CONFIG(DMA_E), dmap_cfg);
99 mdp4_write(mdp4_kms, REG_MDP4_PIPE_FETCH_CONFIG(VG1), vg_cfg);
100 mdp4_write(mdp4_kms, REG_MDP4_PIPE_FETCH_CONFIG(VG2), vg_cfg);
101 mdp4_write(mdp4_kms, REG_MDP4_PIPE_FETCH_CONFIG(RGB1), vg_cfg);
102 mdp4_write(mdp4_kms, REG_MDP4_PIPE_FETCH_CONFIG(RGB2), vg_cfg);
104 if (mdp4_kms->rev >= 2)
105 mdp4_write(mdp4_kms, REG_MDP4_LAYERMIXER_IN_CFG_UPDATE_METHOD, 1);
107 /* disable CSC matrix / YUV by default: */
108 mdp4_write(mdp4_kms, REG_MDP4_PIPE_OP_MODE(VG1), 0);
109 mdp4_write(mdp4_kms, REG_MDP4_PIPE_OP_MODE(VG2), 0);
110 mdp4_write(mdp4_kms, REG_MDP4_DMA_P_OP_MODE, 0);
111 mdp4_write(mdp4_kms, REG_MDP4_DMA_S_OP_MODE, 0);
112 mdp4_write(mdp4_kms, REG_MDP4_OVLP_CSC_CONFIG(1), 0);
113 mdp4_write(mdp4_kms, REG_MDP4_OVLP_CSC_CONFIG(2), 0);
115 if (mdp4_kms->rev > 1)
116 mdp4_write(mdp4_kms, REG_MDP4_RESET_STATUS, 1);
119 pm_runtime_put_sync(dev->dev);
124 static long mdp4_round_pixclk(struct msm_kms *kms, unsigned long rate,
125 struct drm_encoder *encoder)
127 /* if we had >1 encoder, we'd need something more clever: */
128 return mdp4_dtv_round_pixclk(encoder, rate);
131 static void mdp4_preclose(struct msm_kms *kms, struct drm_file *file)
133 struct mdp4_kms *mdp4_kms = to_mdp4_kms(kms);
134 struct msm_drm_private *priv = mdp4_kms->dev->dev_private;
137 for (i = 0; i < priv->num_crtcs; i++)
138 mdp4_crtc_cancel_pending_flip(priv->crtcs[i], file);
141 static void mdp4_destroy(struct msm_kms *kms)
143 struct mdp4_kms *mdp4_kms = to_mdp4_kms(kms);
147 static const struct msm_kms_funcs kms_funcs = {
148 .hw_init = mdp4_hw_init,
149 .irq_preinstall = mdp4_irq_preinstall,
150 .irq_postinstall = mdp4_irq_postinstall,
151 .irq_uninstall = mdp4_irq_uninstall,
153 .enable_vblank = mdp4_enable_vblank,
154 .disable_vblank = mdp4_disable_vblank,
155 .get_format = mdp4_get_format,
156 .round_pixclk = mdp4_round_pixclk,
157 .preclose = mdp4_preclose,
158 .destroy = mdp4_destroy,
161 int mdp4_disable(struct mdp4_kms *mdp4_kms)
165 clk_disable_unprepare(mdp4_kms->clk);
167 clk_disable_unprepare(mdp4_kms->pclk);
168 clk_disable_unprepare(mdp4_kms->lut_clk);
173 int mdp4_enable(struct mdp4_kms *mdp4_kms)
177 clk_prepare_enable(mdp4_kms->clk);
179 clk_prepare_enable(mdp4_kms->pclk);
180 clk_prepare_enable(mdp4_kms->lut_clk);
185 static int modeset_init(struct mdp4_kms *mdp4_kms)
187 struct drm_device *dev = mdp4_kms->dev;
188 struct msm_drm_private *priv = dev->dev_private;
189 struct drm_plane *plane;
190 struct drm_crtc *crtc;
191 struct drm_encoder *encoder;
195 * NOTE: this is a bit simplistic until we add support
196 * for more than just RGB1->DMA_E->DTV->HDMI
199 /* construct non-private planes: */
200 plane = mdp4_plane_init(dev, VG1, false);
202 dev_err(dev->dev, "failed to construct plane for VG1\n");
203 ret = PTR_ERR(plane);
206 priv->planes[priv->num_planes++] = plane;
208 plane = mdp4_plane_init(dev, VG2, false);
210 dev_err(dev->dev, "failed to construct plane for VG2\n");
211 ret = PTR_ERR(plane);
214 priv->planes[priv->num_planes++] = plane;
216 /* the CRTCs get constructed with a private plane: */
217 plane = mdp4_plane_init(dev, RGB1, true);
219 dev_err(dev->dev, "failed to construct plane for RGB1\n");
220 ret = PTR_ERR(plane);
224 crtc = mdp4_crtc_init(dev, plane, priv->num_crtcs, 1, DMA_E);
226 dev_err(dev->dev, "failed to construct crtc for DMA_E\n");
230 priv->crtcs[priv->num_crtcs++] = crtc;
232 encoder = mdp4_dtv_encoder_init(dev);
233 if (IS_ERR(encoder)) {
234 dev_err(dev->dev, "failed to construct DTV encoder\n");
235 ret = PTR_ERR(encoder);
238 encoder->possible_crtcs = 0x1; /* DTV can be hooked to DMA_E */
239 priv->encoders[priv->num_encoders++] = encoder;
241 ret = hdmi_init(dev, encoder);
243 dev_err(dev->dev, "failed to initialize HDMI\n");
253 static const char *iommu_ports[] = {
254 "mdp_port0_cb0", "mdp_port1_cb0",
257 struct msm_kms *mdp4_kms_init(struct drm_device *dev)
259 struct platform_device *pdev = dev->platformdev;
260 struct mdp4_platform_config *config = mdp4_get_config(pdev);
261 struct mdp4_kms *mdp4_kms;
262 struct msm_kms *kms = NULL;
265 mdp4_kms = kzalloc(sizeof(*mdp4_kms), GFP_KERNEL);
267 dev_err(dev->dev, "failed to allocate kms\n");
272 kms = &mdp4_kms->base;
273 kms->funcs = &kms_funcs;
277 mdp4_kms->mmio = msm_ioremap(pdev, NULL, "MDP4");
278 if (IS_ERR(mdp4_kms->mmio)) {
279 ret = PTR_ERR(mdp4_kms->mmio);
283 mdp4_kms->dsi_pll_vdda = devm_regulator_get(&pdev->dev, "dsi_pll_vdda");
284 if (IS_ERR(mdp4_kms->dsi_pll_vdda))
285 mdp4_kms->dsi_pll_vdda = NULL;
287 mdp4_kms->dsi_pll_vddio = devm_regulator_get(&pdev->dev, "dsi_pll_vddio");
288 if (IS_ERR(mdp4_kms->dsi_pll_vddio))
289 mdp4_kms->dsi_pll_vddio = NULL;
291 mdp4_kms->vdd = devm_regulator_get(&pdev->dev, "vdd");
292 if (IS_ERR(mdp4_kms->vdd))
293 mdp4_kms->vdd = NULL;
296 ret = regulator_enable(mdp4_kms->vdd);
298 dev_err(dev->dev, "failed to enable regulator vdd: %d\n", ret);
303 mdp4_kms->clk = devm_clk_get(&pdev->dev, "core_clk");
304 if (IS_ERR(mdp4_kms->clk)) {
305 dev_err(dev->dev, "failed to get core_clk\n");
306 ret = PTR_ERR(mdp4_kms->clk);
310 mdp4_kms->pclk = devm_clk_get(&pdev->dev, "iface_clk");
311 if (IS_ERR(mdp4_kms->pclk))
312 mdp4_kms->pclk = NULL;
314 // XXX if (rev >= MDP_REV_42) { ???
315 mdp4_kms->lut_clk = devm_clk_get(&pdev->dev, "lut_clk");
316 if (IS_ERR(mdp4_kms->lut_clk)) {
317 dev_err(dev->dev, "failed to get lut_clk\n");
318 ret = PTR_ERR(mdp4_kms->lut_clk);
322 clk_set_rate(mdp4_kms->clk, config->max_clk);
323 clk_set_rate(mdp4_kms->lut_clk, config->max_clk);
325 if (!config->iommu) {
326 dev_err(dev->dev, "no iommu\n");
331 /* make sure things are off before attaching iommu (bootloader could
332 * have left things on, in which case we'll start getting faults if
335 mdp4_write(mdp4_kms, REG_MDP4_DTV_ENABLE, 0);
336 mdp4_write(mdp4_kms, REG_MDP4_LCDC_ENABLE, 0);
337 mdp4_write(mdp4_kms, REG_MDP4_DSI_ENABLE, 0);
340 ret = msm_iommu_attach(dev, config->iommu,
341 iommu_ports, ARRAY_SIZE(iommu_ports));
345 mdp4_kms->id = msm_register_iommu(dev, config->iommu);
346 if (mdp4_kms->id < 0) {
348 dev_err(dev->dev, "failed to register mdp4 iommu: %d\n", ret);
352 ret = modeset_init(mdp4_kms);
354 dev_err(dev->dev, "modeset_init failed: %d\n", ret);
366 static struct mdp4_platform_config *mdp4_get_config(struct platform_device *dev)
368 static struct mdp4_platform_config config = {};
372 if (cpu_is_apq8064())
373 config.max_clk = 266667000;
375 config.max_clk = 200000000;
377 config.iommu = msm_get_iommu_domain(DISPLAY_READ_DOMAIN);