2 * Copyright (c) 2014, The Linux Foundation. All rights reserved.
3 * Copyright (C) 2013 Red Hat
4 * Author: Rob Clark <robdclark@gmail.com>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program. If not, see <http://www.gnu.org/licenses/>.
19 #include <linux/of_irq.h>
26 static const char *iommu_ports[] = {
30 static int mdp5_hw_init(struct msm_kms *kms)
32 struct mdp5_kms *mdp5_kms = to_mdp5_kms(to_mdp_kms(kms));
33 struct platform_device *pdev = mdp5_kms->pdev;
36 pm_runtime_get_sync(&pdev->dev);
37 mdp5_enable(mdp5_kms);
39 /* Magic unknown register writes:
41 * W VBIF:0x004 00000001 (mdss_mdp.c:839)
42 * W MDP5:0x2e0 0xe9 (mdss_mdp.c:839)
43 * W MDP5:0x2e4 0x55 (mdss_mdp.c:839)
44 * W MDP5:0x3ac 0xc0000ccc (mdss_mdp.c:839)
45 * W MDP5:0x3b4 0xc0000ccc (mdss_mdp.c:839)
46 * W MDP5:0x3bc 0xcccccc (mdss_mdp.c:839)
47 * W MDP5:0x4a8 0xcccc0c0 (mdss_mdp.c:839)
48 * W MDP5:0x4b0 0xccccc0c0 (mdss_mdp.c:839)
49 * W MDP5:0x4b8 0xccccc000 (mdss_mdp.c:839)
51 * Downstream fbdev driver gets these register offsets/values
52 * from DT.. not really sure what these registers are or if
53 * different values for different boards/SoC's, etc. I guess
54 * they are the golden registers.
56 * Not setting these does not seem to cause any problem. But
57 * we may be getting lucky with the bootloader initializing
58 * them for us. OTOH, if we can always count on the bootloader
59 * setting the golden registers, then perhaps we don't need to
63 spin_lock_irqsave(&mdp5_kms->resource_lock, flags);
64 mdp5_write(mdp5_kms, REG_MDP5_DISP_INTF_SEL, 0);
65 spin_unlock_irqrestore(&mdp5_kms->resource_lock, flags);
67 mdp5_ctlm_hw_reset(mdp5_kms->ctlm);
69 mdp5_disable(mdp5_kms);
70 pm_runtime_put_sync(&pdev->dev);
75 struct mdp5_state *mdp5_get_state(struct drm_atomic_state *s)
77 struct msm_drm_private *priv = s->dev->dev_private;
78 struct mdp5_kms *mdp5_kms = to_mdp5_kms(to_mdp_kms(priv->kms));
79 struct msm_kms_state *state = to_kms_state(s);
80 struct mdp5_state *new_state;
86 ret = drm_modeset_lock(&mdp5_kms->state_lock, s->acquire_ctx);
90 new_state = kmalloc(sizeof(*mdp5_kms->state), GFP_KERNEL);
92 return ERR_PTR(-ENOMEM);
95 new_state->hwpipe = mdp5_kms->state->hwpipe;
97 new_state->smp = mdp5_kms->state->smp;
99 state->state = new_state;
104 static void mdp5_swap_state(struct msm_kms *kms, struct drm_atomic_state *state)
106 struct mdp5_kms *mdp5_kms = to_mdp5_kms(to_mdp_kms(kms));
107 swap(to_kms_state(state)->state, mdp5_kms->state);
110 static void mdp5_prepare_commit(struct msm_kms *kms, struct drm_atomic_state *state)
112 struct mdp5_kms *mdp5_kms = to_mdp5_kms(to_mdp_kms(kms));
114 mdp5_enable(mdp5_kms);
117 mdp5_smp_prepare_commit(mdp5_kms->smp, &mdp5_kms->state->smp);
120 static void mdp5_complete_commit(struct msm_kms *kms, struct drm_atomic_state *state)
123 struct mdp5_kms *mdp5_kms = to_mdp5_kms(to_mdp_kms(kms));
124 struct drm_plane *plane;
125 struct drm_plane_state *plane_state;
127 for_each_plane_in_state(state, plane, plane_state, i)
128 mdp5_plane_complete_commit(plane, plane_state);
131 mdp5_smp_complete_commit(mdp5_kms->smp, &mdp5_kms->state->smp);
133 mdp5_disable(mdp5_kms);
136 static void mdp5_wait_for_crtc_commit_done(struct msm_kms *kms,
137 struct drm_crtc *crtc)
139 mdp5_crtc_wait_for_commit_done(crtc);
142 static long mdp5_round_pixclk(struct msm_kms *kms, unsigned long rate,
143 struct drm_encoder *encoder)
148 static int mdp5_set_split_display(struct msm_kms *kms,
149 struct drm_encoder *encoder,
150 struct drm_encoder *slave_encoder,
154 return mdp5_cmd_encoder_set_split_display(encoder,
157 return mdp5_encoder_set_split_display(encoder, slave_encoder);
160 static void mdp5_kms_destroy(struct msm_kms *kms)
162 struct mdp5_kms *mdp5_kms = to_mdp5_kms(to_mdp_kms(kms));
163 struct msm_gem_address_space *aspace = mdp5_kms->aspace;
166 for (i = 0; i < mdp5_kms->num_hwpipes; i++)
167 mdp5_pipe_destroy(mdp5_kms->hwpipes[i]);
170 aspace->mmu->funcs->detach(aspace->mmu,
171 iommu_ports, ARRAY_SIZE(iommu_ports));
172 msm_gem_address_space_destroy(aspace);
176 #ifdef CONFIG_DEBUG_FS
177 static int smp_show(struct seq_file *m, void *arg)
179 struct drm_info_node *node = (struct drm_info_node *) m->private;
180 struct drm_device *dev = node->minor->dev;
181 struct msm_drm_private *priv = dev->dev_private;
182 struct mdp5_kms *mdp5_kms = to_mdp5_kms(to_mdp_kms(priv->kms));
183 struct drm_printer p = drm_seq_file_printer(m);
185 if (!mdp5_kms->smp) {
186 drm_printf(&p, "no SMP pool\n");
190 mdp5_smp_dump(mdp5_kms->smp, &p);
195 static struct drm_info_list mdp5_debugfs_list[] = {
199 static int mdp5_kms_debugfs_init(struct msm_kms *kms, struct drm_minor *minor)
201 struct drm_device *dev = minor->dev;
204 ret = drm_debugfs_create_files(mdp5_debugfs_list,
205 ARRAY_SIZE(mdp5_debugfs_list),
206 minor->debugfs_root, minor);
209 dev_err(dev->dev, "could not install mdp5_debugfs_list\n");
216 static void mdp5_kms_debugfs_cleanup(struct msm_kms *kms, struct drm_minor *minor)
218 drm_debugfs_remove_files(mdp5_debugfs_list,
219 ARRAY_SIZE(mdp5_debugfs_list), minor);
223 static const struct mdp_kms_funcs kms_funcs = {
225 .hw_init = mdp5_hw_init,
226 .irq_preinstall = mdp5_irq_preinstall,
227 .irq_postinstall = mdp5_irq_postinstall,
228 .irq_uninstall = mdp5_irq_uninstall,
230 .enable_vblank = mdp5_enable_vblank,
231 .disable_vblank = mdp5_disable_vblank,
232 .swap_state = mdp5_swap_state,
233 .prepare_commit = mdp5_prepare_commit,
234 .complete_commit = mdp5_complete_commit,
235 .wait_for_crtc_commit_done = mdp5_wait_for_crtc_commit_done,
236 .get_format = mdp_get_format,
237 .round_pixclk = mdp5_round_pixclk,
238 .set_split_display = mdp5_set_split_display,
239 .destroy = mdp5_kms_destroy,
240 #ifdef CONFIG_DEBUG_FS
241 .debugfs_init = mdp5_kms_debugfs_init,
242 .debugfs_cleanup = mdp5_kms_debugfs_cleanup,
245 .set_irqmask = mdp5_set_irqmask,
248 int mdp5_disable(struct mdp5_kms *mdp5_kms)
252 clk_disable_unprepare(mdp5_kms->ahb_clk);
253 clk_disable_unprepare(mdp5_kms->axi_clk);
254 clk_disable_unprepare(mdp5_kms->core_clk);
255 if (mdp5_kms->lut_clk)
256 clk_disable_unprepare(mdp5_kms->lut_clk);
261 int mdp5_enable(struct mdp5_kms *mdp5_kms)
265 clk_prepare_enable(mdp5_kms->ahb_clk);
266 clk_prepare_enable(mdp5_kms->axi_clk);
267 clk_prepare_enable(mdp5_kms->core_clk);
268 if (mdp5_kms->lut_clk)
269 clk_prepare_enable(mdp5_kms->lut_clk);
274 static struct drm_encoder *construct_encoder(struct mdp5_kms *mdp5_kms,
275 enum mdp5_intf_type intf_type, int intf_num,
276 enum mdp5_intf_mode intf_mode, struct mdp5_ctl *ctl)
278 struct drm_device *dev = mdp5_kms->dev;
279 struct msm_drm_private *priv = dev->dev_private;
280 struct drm_encoder *encoder;
281 struct mdp5_interface intf = {
287 if ((intf_type == INTF_DSI) &&
288 (intf_mode == MDP5_INTF_DSI_MODE_COMMAND))
289 encoder = mdp5_cmd_encoder_init(dev, &intf, ctl);
291 encoder = mdp5_encoder_init(dev, &intf, ctl);
293 if (IS_ERR(encoder)) {
294 dev_err(dev->dev, "failed to construct encoder\n");
298 encoder->possible_crtcs = (1 << priv->num_crtcs) - 1;
299 priv->encoders[priv->num_encoders++] = encoder;
304 static int get_dsi_id_from_intf(const struct mdp5_cfg_hw *hw_cfg, int intf_num)
306 const enum mdp5_intf_type *intfs = hw_cfg->intf.connect;
307 const int intf_cnt = ARRAY_SIZE(hw_cfg->intf.connect);
310 for (i = 0; i < intf_cnt; i++) {
311 if (intfs[i] == INTF_DSI) {
322 static int modeset_init_intf(struct mdp5_kms *mdp5_kms, int intf_num)
324 struct drm_device *dev = mdp5_kms->dev;
325 struct msm_drm_private *priv = dev->dev_private;
326 const struct mdp5_cfg_hw *hw_cfg =
327 mdp5_cfg_get_hw_config(mdp5_kms->cfg);
328 enum mdp5_intf_type intf_type = hw_cfg->intf.connect[intf_num];
329 struct mdp5_ctl_manager *ctlm = mdp5_kms->ctlm;
330 struct mdp5_ctl *ctl;
331 struct drm_encoder *encoder;
341 ctl = mdp5_ctlm_request(ctlm, intf_num);
347 encoder = construct_encoder(mdp5_kms, INTF_eDP, intf_num,
348 MDP5_INTF_MODE_NONE, ctl);
349 if (IS_ERR(encoder)) {
350 ret = PTR_ERR(encoder);
354 ret = msm_edp_modeset_init(priv->edp, dev, encoder);
360 ctl = mdp5_ctlm_request(ctlm, intf_num);
366 encoder = construct_encoder(mdp5_kms, INTF_HDMI, intf_num,
367 MDP5_INTF_MODE_NONE, ctl);
368 if (IS_ERR(encoder)) {
369 ret = PTR_ERR(encoder);
373 ret = msm_hdmi_modeset_init(priv->hdmi, dev, encoder);
377 int dsi_id = get_dsi_id_from_intf(hw_cfg, intf_num);
378 struct drm_encoder *dsi_encs[MSM_DSI_ENCODER_NUM];
379 enum mdp5_intf_mode mode;
382 if ((dsi_id >= ARRAY_SIZE(priv->dsi)) || (dsi_id < 0)) {
383 dev_err(dev->dev, "failed to find dsi from intf %d\n",
389 if (!priv->dsi[dsi_id])
392 ctl = mdp5_ctlm_request(ctlm, intf_num);
398 for (i = 0; i < MSM_DSI_ENCODER_NUM; i++) {
399 mode = (i == MSM_DSI_CMD_ENCODER_ID) ?
400 MDP5_INTF_DSI_MODE_COMMAND :
401 MDP5_INTF_DSI_MODE_VIDEO;
402 dsi_encs[i] = construct_encoder(mdp5_kms, INTF_DSI,
403 intf_num, mode, ctl);
404 if (IS_ERR(dsi_encs[i])) {
405 ret = PTR_ERR(dsi_encs[i]);
410 ret = msm_dsi_modeset_init(priv->dsi[dsi_id], dev, dsi_encs);
414 dev_err(dev->dev, "unknown intf: %d\n", intf_type);
422 static int modeset_init(struct mdp5_kms *mdp5_kms)
424 struct drm_device *dev = mdp5_kms->dev;
425 struct msm_drm_private *priv = dev->dev_private;
426 const struct mdp5_cfg_hw *hw_cfg;
429 hw_cfg = mdp5_cfg_get_hw_config(mdp5_kms->cfg);
431 /* Construct planes equaling the number of hw pipes, and CRTCs
432 * for the N layer-mixers (LM). The first N planes become primary
433 * planes for the CRTCs, with the remainder as overlay planes:
435 for (i = 0; i < mdp5_kms->num_hwpipes; i++) {
436 bool primary = i < mdp5_cfg->lm.count;
437 struct drm_plane *plane;
438 struct drm_crtc *crtc;
440 plane = mdp5_plane_init(dev, primary);
442 ret = PTR_ERR(plane);
443 dev_err(dev->dev, "failed to construct plane %d (%d)\n", i, ret);
446 priv->planes[priv->num_planes++] = plane;
451 crtc = mdp5_crtc_init(dev, plane, i);
454 dev_err(dev->dev, "failed to construct crtc %d (%d)\n", i, ret);
457 priv->crtcs[priv->num_crtcs++] = crtc;
460 /* Construct encoders and modeset initialize connector devices
461 * for each external display interface.
463 for (i = 0; i < ARRAY_SIZE(hw_cfg->intf.connect); i++) {
464 ret = modeset_init_intf(mdp5_kms, i);
475 static void read_mdp_hw_revision(struct mdp5_kms *mdp5_kms,
476 u32 *major, u32 *minor)
480 mdp5_enable(mdp5_kms);
481 version = mdp5_read(mdp5_kms, REG_MDP5_HW_VERSION);
482 mdp5_disable(mdp5_kms);
484 *major = FIELD(version, MDP5_HW_VERSION_MAJOR);
485 *minor = FIELD(version, MDP5_HW_VERSION_MINOR);
487 DBG("MDP5 version v%d.%d", *major, *minor);
490 static int get_clk(struct platform_device *pdev, struct clk **clkp,
491 const char *name, bool mandatory)
493 struct device *dev = &pdev->dev;
494 struct clk *clk = devm_clk_get(dev, name);
495 if (IS_ERR(clk) && mandatory) {
496 dev_err(dev, "failed to get %s (%ld)\n", name, PTR_ERR(clk));
500 DBG("skipping %s", name);
507 static struct drm_encoder *get_encoder_from_crtc(struct drm_crtc *crtc)
509 struct drm_device *dev = crtc->dev;
510 struct drm_encoder *encoder;
512 drm_for_each_encoder(encoder, dev)
513 if (encoder->crtc == crtc)
519 static int mdp5_get_scanoutpos(struct drm_device *dev, unsigned int pipe,
520 unsigned int flags, int *vpos, int *hpos,
521 ktime_t *stime, ktime_t *etime,
522 const struct drm_display_mode *mode)
524 struct msm_drm_private *priv = dev->dev_private;
525 struct drm_crtc *crtc;
526 struct drm_encoder *encoder;
527 int line, vsw, vbp, vactive_start, vactive_end, vfp_end;
530 crtc = priv->crtcs[pipe];
532 DRM_ERROR("Invalid crtc %d\n", pipe);
536 encoder = get_encoder_from_crtc(crtc);
538 DRM_ERROR("no encoder found for crtc %d\n", pipe);
542 ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
544 vsw = mode->crtc_vsync_end - mode->crtc_vsync_start;
545 vbp = mode->crtc_vtotal - mode->crtc_vsync_end;
548 * the line counter is 1 at the start of the VSYNC pulse and VTOTAL at
549 * the end of VFP. Translate the porch values relative to the line
553 vactive_start = vsw + vbp + 1;
555 vactive_end = vactive_start + mode->crtc_vdisplay;
557 /* last scan line before VSYNC */
558 vfp_end = mode->crtc_vtotal;
561 *stime = ktime_get();
563 line = mdp5_encoder_get_linecount(encoder);
565 if (line < vactive_start) {
566 line -= vactive_start;
567 ret |= DRM_SCANOUTPOS_IN_VBLANK;
568 } else if (line > vactive_end) {
569 line = line - vfp_end - vactive_start;
570 ret |= DRM_SCANOUTPOS_IN_VBLANK;
572 line -= vactive_start;
579 *etime = ktime_get();
584 static int mdp5_get_vblank_timestamp(struct drm_device *dev, unsigned int pipe,
586 struct timeval *vblank_time,
589 struct msm_drm_private *priv = dev->dev_private;
590 struct drm_crtc *crtc;
592 if (pipe < 0 || pipe >= priv->num_crtcs) {
593 DRM_ERROR("Invalid crtc %d\n", pipe);
597 crtc = priv->crtcs[pipe];
599 DRM_ERROR("Invalid crtc %d\n", pipe);
603 return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
608 static u32 mdp5_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
610 struct msm_drm_private *priv = dev->dev_private;
611 struct drm_crtc *crtc;
612 struct drm_encoder *encoder;
614 if (pipe < 0 || pipe >= priv->num_crtcs)
617 crtc = priv->crtcs[pipe];
621 encoder = get_encoder_from_crtc(crtc);
625 return mdp5_encoder_get_framecount(encoder);
628 struct msm_kms *mdp5_kms_init(struct drm_device *dev)
630 struct msm_drm_private *priv = dev->dev_private;
631 struct platform_device *pdev;
632 struct mdp5_kms *mdp5_kms;
633 struct mdp5_cfg *config;
635 struct msm_gem_address_space *aspace;
638 /* priv->kms would have been populated by the MDP5 driver */
643 mdp5_kms = to_mdp5_kms(to_mdp_kms(kms));
645 mdp_kms_init(&mdp5_kms->base, &kms_funcs);
647 pdev = mdp5_kms->pdev;
649 irq = irq_of_parse_and_map(pdev->dev.of_node, 0);
652 dev_err(&pdev->dev, "failed to get irq: %d\n", ret);
658 config = mdp5_cfg_get_config(mdp5_kms->cfg);
660 /* make sure things are off before attaching iommu (bootloader could
661 * have left things on, in which case we'll start getting faults if
664 mdp5_enable(mdp5_kms);
665 for (i = 0; i < MDP5_INTF_NUM_MAX; i++) {
666 if (mdp5_cfg_intf_is_virtual(config->hw->intf.connect[i]) ||
667 !config->hw->intf.base[i])
669 mdp5_write(mdp5_kms, REG_MDP5_INTF_TIMING_ENGINE_EN(i), 0);
671 mdp5_write(mdp5_kms, REG_MDP5_INTF_FRAME_LINE_COUNT_EN(i), 0x3);
673 mdp5_disable(mdp5_kms);
676 if (config->platform.iommu) {
677 aspace = msm_gem_address_space_create(&pdev->dev,
678 config->platform.iommu, "mdp5");
679 if (IS_ERR(aspace)) {
680 ret = PTR_ERR(aspace);
684 mdp5_kms->aspace = aspace;
686 ret = aspace->mmu->funcs->attach(aspace->mmu, iommu_ports,
687 ARRAY_SIZE(iommu_ports));
689 dev_err(&pdev->dev, "failed to attach iommu: %d\n",
695 "no iommu, fallback to phys contig buffers for scanout\n");
699 mdp5_kms->id = msm_register_address_space(dev, aspace);
700 if (mdp5_kms->id < 0) {
702 dev_err(&pdev->dev, "failed to register mdp5 iommu: %d\n", ret);
706 ret = modeset_init(mdp5_kms);
708 dev_err(&pdev->dev, "modeset_init failed: %d\n", ret);
712 dev->mode_config.min_width = 0;
713 dev->mode_config.min_height = 0;
714 dev->mode_config.max_width = 0xffff;
715 dev->mode_config.max_height = 0xffff;
717 dev->driver->get_vblank_timestamp = mdp5_get_vblank_timestamp;
718 dev->driver->get_scanout_position = mdp5_get_scanoutpos;
719 dev->driver->get_vblank_counter = mdp5_get_vblank_counter;
720 dev->max_vblank_count = 0xffffffff;
721 dev->vblank_disable_immediate = true;
726 mdp5_kms_destroy(kms);
730 static void mdp5_destroy(struct platform_device *pdev)
732 struct mdp5_kms *mdp5_kms = platform_get_drvdata(pdev);
735 mdp5_ctlm_destroy(mdp5_kms->ctlm);
737 mdp5_smp_destroy(mdp5_kms->smp);
739 mdp5_cfg_destroy(mdp5_kms->cfg);
741 if (mdp5_kms->rpm_enabled)
742 pm_runtime_disable(&pdev->dev);
744 kfree(mdp5_kms->state);
747 static int construct_pipes(struct mdp5_kms *mdp5_kms, int cnt,
748 const enum mdp5_pipe *pipes, const uint32_t *offsets,
751 struct drm_device *dev = mdp5_kms->dev;
754 for (i = 0; i < cnt; i++) {
755 struct mdp5_hw_pipe *hwpipe;
757 hwpipe = mdp5_pipe_init(pipes[i], offsets[i], caps);
758 if (IS_ERR(hwpipe)) {
759 ret = PTR_ERR(hwpipe);
760 dev_err(dev->dev, "failed to construct pipe for %s (%d)\n",
761 pipe2name(pipes[i]), ret);
764 hwpipe->idx = mdp5_kms->num_hwpipes;
765 mdp5_kms->hwpipes[mdp5_kms->num_hwpipes++] = hwpipe;
771 static int hwpipe_init(struct mdp5_kms *mdp5_kms)
773 static const enum mdp5_pipe rgb_planes[] = {
774 SSPP_RGB0, SSPP_RGB1, SSPP_RGB2, SSPP_RGB3,
776 static const enum mdp5_pipe vig_planes[] = {
777 SSPP_VIG0, SSPP_VIG1, SSPP_VIG2, SSPP_VIG3,
779 static const enum mdp5_pipe dma_planes[] = {
780 SSPP_DMA0, SSPP_DMA1,
782 const struct mdp5_cfg_hw *hw_cfg;
785 hw_cfg = mdp5_cfg_get_hw_config(mdp5_kms->cfg);
787 /* Construct RGB pipes: */
788 ret = construct_pipes(mdp5_kms, hw_cfg->pipe_rgb.count, rgb_planes,
789 hw_cfg->pipe_rgb.base, hw_cfg->pipe_rgb.caps);
793 /* Construct video (VIG) pipes: */
794 ret = construct_pipes(mdp5_kms, hw_cfg->pipe_vig.count, vig_planes,
795 hw_cfg->pipe_vig.base, hw_cfg->pipe_vig.caps);
799 /* Construct DMA pipes: */
800 ret = construct_pipes(mdp5_kms, hw_cfg->pipe_dma.count, dma_planes,
801 hw_cfg->pipe_dma.base, hw_cfg->pipe_dma.caps);
808 static int mdp5_init(struct platform_device *pdev, struct drm_device *dev)
810 struct msm_drm_private *priv = dev->dev_private;
811 struct mdp5_kms *mdp5_kms;
812 struct mdp5_cfg *config;
816 mdp5_kms = devm_kzalloc(&pdev->dev, sizeof(*mdp5_kms), GFP_KERNEL);
822 platform_set_drvdata(pdev, mdp5_kms);
824 spin_lock_init(&mdp5_kms->resource_lock);
827 mdp5_kms->pdev = pdev;
829 drm_modeset_lock_init(&mdp5_kms->state_lock);
830 mdp5_kms->state = kzalloc(sizeof(*mdp5_kms->state), GFP_KERNEL);
831 if (!mdp5_kms->state) {
836 mdp5_kms->mmio = msm_ioremap(pdev, "mdp_phys", "MDP5");
837 if (IS_ERR(mdp5_kms->mmio)) {
838 ret = PTR_ERR(mdp5_kms->mmio);
842 /* mandatory clocks: */
843 ret = get_clk(pdev, &mdp5_kms->axi_clk, "bus_clk", true);
846 ret = get_clk(pdev, &mdp5_kms->ahb_clk, "iface_clk", true);
849 ret = get_clk(pdev, &mdp5_kms->core_clk, "core_clk", true);
852 ret = get_clk(pdev, &mdp5_kms->vsync_clk, "vsync_clk", true);
856 /* optional clocks: */
857 get_clk(pdev, &mdp5_kms->lut_clk, "lut_clk", false);
859 /* we need to set a default rate before enabling. Set a safe
860 * rate first, then figure out hw revision, and then set a
863 clk_set_rate(mdp5_kms->core_clk, 200000000);
865 pm_runtime_enable(&pdev->dev);
866 mdp5_kms->rpm_enabled = true;
868 read_mdp_hw_revision(mdp5_kms, &major, &minor);
870 mdp5_kms->cfg = mdp5_cfg_init(mdp5_kms, major, minor);
871 if (IS_ERR(mdp5_kms->cfg)) {
872 ret = PTR_ERR(mdp5_kms->cfg);
873 mdp5_kms->cfg = NULL;
877 config = mdp5_cfg_get_config(mdp5_kms->cfg);
878 mdp5_kms->caps = config->hw->mdp.caps;
880 /* TODO: compute core clock rate at runtime */
881 clk_set_rate(mdp5_kms->core_clk, config->hw->max_clk);
884 * Some chipsets have a Shared Memory Pool (SMP), while others
885 * have dedicated latency buffering per source pipe instead;
886 * this section initializes the SMP:
888 if (mdp5_kms->caps & MDP_CAP_SMP) {
889 mdp5_kms->smp = mdp5_smp_init(mdp5_kms, &config->hw->smp);
890 if (IS_ERR(mdp5_kms->smp)) {
891 ret = PTR_ERR(mdp5_kms->smp);
892 mdp5_kms->smp = NULL;
897 mdp5_kms->ctlm = mdp5_ctlm_init(dev, mdp5_kms->mmio, mdp5_kms->cfg);
898 if (IS_ERR(mdp5_kms->ctlm)) {
899 ret = PTR_ERR(mdp5_kms->ctlm);
900 mdp5_kms->ctlm = NULL;
904 ret = hwpipe_init(mdp5_kms);
908 /* set uninit-ed kms */
909 priv->kms = &mdp5_kms->base.base;
917 static int mdp5_bind(struct device *dev, struct device *master, void *data)
919 struct drm_device *ddev = dev_get_drvdata(master);
920 struct platform_device *pdev = to_platform_device(dev);
924 return mdp5_init(pdev, ddev);
927 static void mdp5_unbind(struct device *dev, struct device *master,
930 struct platform_device *pdev = to_platform_device(dev);
935 static const struct component_ops mdp5_ops = {
937 .unbind = mdp5_unbind,
940 static int mdp5_dev_probe(struct platform_device *pdev)
943 return component_add(&pdev->dev, &mdp5_ops);
946 static int mdp5_dev_remove(struct platform_device *pdev)
949 component_del(&pdev->dev, &mdp5_ops);
953 static const struct of_device_id mdp5_dt_match[] = {
954 { .compatible = "qcom,mdp5", },
955 /* to support downstream DT files */
956 { .compatible = "qcom,mdss_mdp", },
959 MODULE_DEVICE_TABLE(of, mdp5_dt_match);
961 static struct platform_driver mdp5_driver = {
962 .probe = mdp5_dev_probe,
963 .remove = mdp5_dev_remove,
966 .of_match_table = mdp5_dt_match,
970 void __init msm_mdp_register(void)
973 platform_driver_register(&mdp5_driver);
976 void __exit msm_mdp_unregister(void)
979 platform_driver_unregister(&mdp5_driver);