2 * Copyright (C) 2013 Red Hat
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/>.
19 #include "msm_debugfs.h"
20 #include "msm_fence.h"
27 * - 1.0.0 - initial interface
28 * - 1.1.0 - adds madvise, and support for submits with > 4 cmd buffers
29 * - 1.2.0 - adds explicit fence support for submit ioctl
31 #define MSM_VERSION_MAJOR 1
32 #define MSM_VERSION_MINOR 2
33 #define MSM_VERSION_PATCHLEVEL 0
35 static void msm_fb_output_poll_changed(struct drm_device *dev)
37 struct msm_drm_private *priv = dev->dev_private;
39 drm_fb_helper_hotplug_event(priv->fbdev);
42 static const struct drm_mode_config_funcs mode_config_funcs = {
43 .fb_create = msm_framebuffer_create,
44 .output_poll_changed = msm_fb_output_poll_changed,
45 .atomic_check = msm_atomic_check,
46 .atomic_commit = msm_atomic_commit,
49 int msm_register_mmu(struct drm_device *dev, struct msm_mmu *mmu)
51 struct msm_drm_private *priv = dev->dev_private;
52 int idx = priv->num_mmus++;
54 if (WARN_ON(idx >= ARRAY_SIZE(priv->mmus)))
57 priv->mmus[idx] = mmu;
62 #ifdef CONFIG_DRM_MSM_REGISTER_LOGGING
63 static bool reglog = false;
64 MODULE_PARM_DESC(reglog, "Enable register read/write logging");
65 module_param(reglog, bool, 0600);
70 #ifdef CONFIG_DRM_FBDEV_EMULATION
71 static bool fbdev = true;
72 MODULE_PARM_DESC(fbdev, "Enable fbdev compat layer");
73 module_param(fbdev, bool, 0600);
76 static char *vram = "16m";
77 MODULE_PARM_DESC(vram, "Configure VRAM size (for devices without IOMMU/GPUMMU)");
78 module_param(vram, charp, 0);
84 void __iomem *msm_ioremap(struct platform_device *pdev, const char *name,
92 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, name);
94 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
97 dev_err(&pdev->dev, "failed to get memory resource: %s\n", name);
98 return ERR_PTR(-EINVAL);
101 size = resource_size(res);
103 ptr = devm_ioremap_nocache(&pdev->dev, res->start, size);
105 dev_err(&pdev->dev, "failed to ioremap: %s\n", name);
106 return ERR_PTR(-ENOMEM);
110 printk(KERN_DEBUG "IO:region %s %p %08lx\n", dbgname, ptr, size);
115 void msm_writel(u32 data, void __iomem *addr)
118 printk(KERN_DEBUG "IO:W %p %08x\n", addr, data);
122 u32 msm_readl(const void __iomem *addr)
124 u32 val = readl(addr);
126 printk(KERN_ERR "IO:R %p %08x\n", addr, val);
130 struct vblank_event {
131 struct list_head node;
136 static void vblank_ctrl_worker(struct work_struct *work)
138 struct msm_vblank_ctrl *vbl_ctrl = container_of(work,
139 struct msm_vblank_ctrl, work);
140 struct msm_drm_private *priv = container_of(vbl_ctrl,
141 struct msm_drm_private, vblank_ctrl);
142 struct msm_kms *kms = priv->kms;
143 struct vblank_event *vbl_ev, *tmp;
146 spin_lock_irqsave(&vbl_ctrl->lock, flags);
147 list_for_each_entry_safe(vbl_ev, tmp, &vbl_ctrl->event_list, node) {
148 list_del(&vbl_ev->node);
149 spin_unlock_irqrestore(&vbl_ctrl->lock, flags);
152 kms->funcs->enable_vblank(kms,
153 priv->crtcs[vbl_ev->crtc_id]);
155 kms->funcs->disable_vblank(kms,
156 priv->crtcs[vbl_ev->crtc_id]);
160 spin_lock_irqsave(&vbl_ctrl->lock, flags);
163 spin_unlock_irqrestore(&vbl_ctrl->lock, flags);
166 static int vblank_ctrl_queue_work(struct msm_drm_private *priv,
167 int crtc_id, bool enable)
169 struct msm_vblank_ctrl *vbl_ctrl = &priv->vblank_ctrl;
170 struct vblank_event *vbl_ev;
173 vbl_ev = kzalloc(sizeof(*vbl_ev), GFP_ATOMIC);
177 vbl_ev->crtc_id = crtc_id;
178 vbl_ev->enable = enable;
180 spin_lock_irqsave(&vbl_ctrl->lock, flags);
181 list_add_tail(&vbl_ev->node, &vbl_ctrl->event_list);
182 spin_unlock_irqrestore(&vbl_ctrl->lock, flags);
184 queue_work(priv->wq, &vbl_ctrl->work);
189 static int msm_drm_uninit(struct device *dev)
191 struct platform_device *pdev = to_platform_device(dev);
192 struct drm_device *ddev = platform_get_drvdata(pdev);
193 struct msm_drm_private *priv = ddev->dev_private;
194 struct msm_kms *kms = priv->kms;
195 struct msm_gpu *gpu = priv->gpu;
196 struct msm_vblank_ctrl *vbl_ctrl = &priv->vblank_ctrl;
197 struct vblank_event *vbl_ev, *tmp;
199 /* We must cancel and cleanup any pending vblank enable/disable
200 * work before drm_irq_uninstall() to avoid work re-enabling an
201 * irq after uninstall has disabled it.
203 cancel_work_sync(&vbl_ctrl->work);
204 list_for_each_entry_safe(vbl_ev, tmp, &vbl_ctrl->event_list, node) {
205 list_del(&vbl_ev->node);
209 msm_gem_shrinker_cleanup(ddev);
211 drm_kms_helper_poll_fini(ddev);
213 drm_dev_unregister(ddev);
215 #ifdef CONFIG_DRM_FBDEV_EMULATION
216 if (fbdev && priv->fbdev)
217 msm_fbdev_free(ddev);
219 drm_mode_config_cleanup(ddev);
221 pm_runtime_get_sync(dev);
222 drm_irq_uninstall(ddev);
223 pm_runtime_put_sync(dev);
225 flush_workqueue(priv->wq);
226 destroy_workqueue(priv->wq);
228 flush_workqueue(priv->atomic_wq);
229 destroy_workqueue(priv->atomic_wq);
232 kms->funcs->destroy(kms);
235 mutex_lock(&ddev->struct_mutex);
236 gpu->funcs->pm_suspend(gpu);
237 mutex_unlock(&ddev->struct_mutex);
238 gpu->funcs->destroy(gpu);
241 if (priv->vram.paddr) {
242 unsigned long attrs = DMA_ATTR_NO_KERNEL_MAPPING;
243 drm_mm_takedown(&priv->vram.mm);
244 dma_free_attrs(dev, priv->vram.size, NULL,
245 priv->vram.paddr, attrs);
248 component_unbind_all(dev, ddev);
250 msm_mdss_destroy(ddev);
252 ddev->dev_private = NULL;
260 static int get_mdp_ver(struct platform_device *pdev)
262 struct device *dev = &pdev->dev;
264 return (int) (unsigned long) of_device_get_match_data(dev);
267 #include <linux/of_address.h>
269 static int msm_init_vram(struct drm_device *dev)
271 struct msm_drm_private *priv = dev->dev_private;
272 struct device_node *node;
273 unsigned long size = 0;
276 /* In the device-tree world, we could have a 'memory-region'
277 * phandle, which gives us a link to our "vram". Allocating
278 * is all nicely abstracted behind the dma api, but we need
279 * to know the entire size to allocate it all in one go. There
281 * 1) device with no IOMMU, in which case we need exclusive
282 * access to a VRAM carveout big enough for all gpu
284 * 2) device with IOMMU, but where the bootloader puts up
285 * a splash screen. In this case, the VRAM carveout
286 * need only be large enough for fbdev fb. But we need
287 * exclusive access to the buffer to avoid the kernel
288 * using those pages for other purposes (which appears
289 * as corruption on screen before we have a chance to
290 * load and do initial modeset)
293 node = of_parse_phandle(dev->dev->of_node, "memory-region", 0);
296 ret = of_address_to_resource(node, 0, &r);
300 size = r.end - r.start;
301 DRM_INFO("using VRAM carveout: %lx@%pa\n", size, &r.start);
303 /* if we have no IOMMU, then we need to use carveout allocator.
304 * Grab the entire CMA chunk carved out in early startup in
307 } else if (!iommu_present(&platform_bus_type)) {
308 DRM_INFO("using %s VRAM carveout\n", vram);
309 size = memparse(vram, NULL);
313 unsigned long attrs = 0;
316 priv->vram.size = size;
318 drm_mm_init(&priv->vram.mm, 0, (size >> PAGE_SHIFT) - 1);
320 attrs |= DMA_ATTR_NO_KERNEL_MAPPING;
321 attrs |= DMA_ATTR_WRITE_COMBINE;
323 /* note that for no-kernel-mapping, the vaddr returned
324 * is bogus, but non-null if allocation succeeded:
326 p = dma_alloc_attrs(dev->dev, size,
327 &priv->vram.paddr, GFP_KERNEL, attrs);
329 dev_err(dev->dev, "failed to allocate VRAM\n");
330 priv->vram.paddr = 0;
334 dev_info(dev->dev, "VRAM: %08x->%08x\n",
335 (uint32_t)priv->vram.paddr,
336 (uint32_t)(priv->vram.paddr + size));
342 static int msm_drm_init(struct device *dev, struct drm_driver *drv)
344 struct platform_device *pdev = to_platform_device(dev);
345 struct drm_device *ddev;
346 struct msm_drm_private *priv;
350 ddev = drm_dev_alloc(drv, dev);
352 dev_err(dev, "failed to allocate drm_device\n");
353 return PTR_ERR(ddev);
356 platform_set_drvdata(pdev, ddev);
357 ddev->platformdev = pdev;
359 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
365 ddev->dev_private = priv;
368 ret = msm_mdss_init(ddev);
375 priv->wq = alloc_ordered_workqueue("msm", 0);
376 priv->atomic_wq = alloc_ordered_workqueue("msm:atomic", 0);
377 init_waitqueue_head(&priv->pending_crtcs_event);
379 INIT_LIST_HEAD(&priv->inactive_list);
380 INIT_LIST_HEAD(&priv->vblank_ctrl.event_list);
381 INIT_WORK(&priv->vblank_ctrl.work, vblank_ctrl_worker);
382 spin_lock_init(&priv->vblank_ctrl.lock);
384 drm_mode_config_init(ddev);
386 /* Bind all our sub-components: */
387 ret = component_bind_all(dev, ddev);
389 msm_mdss_destroy(ddev);
395 ret = msm_init_vram(ddev);
399 msm_gem_shrinker_init(ddev);
401 switch (get_mdp_ver(pdev)) {
403 kms = mdp4_kms_init(ddev);
407 kms = mdp5_kms_init(ddev);
410 kms = ERR_PTR(-ENODEV);
416 * NOTE: once we have GPU support, having no kms should not
417 * be considered fatal.. ideally we would still support gpu
418 * and (for example) use dmabuf/prime to share buffers with
419 * imx drm driver on iMX5
421 dev_err(dev, "failed to load kms\n");
427 ret = kms->funcs->hw_init(kms);
429 dev_err(dev, "kms hw init failed: %d\n", ret);
434 ddev->mode_config.funcs = &mode_config_funcs;
436 ret = drm_vblank_init(ddev, priv->num_crtcs);
438 dev_err(dev, "failed to initialize vblank\n");
443 pm_runtime_get_sync(dev);
444 ret = drm_irq_install(ddev, kms->irq);
445 pm_runtime_put_sync(dev);
447 dev_err(dev, "failed to install IRQ handler\n");
452 ret = drm_dev_register(ddev, 0);
456 drm_mode_config_reset(ddev);
458 #ifdef CONFIG_DRM_FBDEV_EMULATION
460 priv->fbdev = msm_fbdev_init(ddev);
463 ret = msm_debugfs_late_init(ddev);
467 drm_kms_helper_poll_init(ddev);
480 static void load_gpu(struct drm_device *dev)
482 static DEFINE_MUTEX(init_lock);
483 struct msm_drm_private *priv = dev->dev_private;
485 mutex_lock(&init_lock);
488 priv->gpu = adreno_load_gpu(dev);
490 mutex_unlock(&init_lock);
493 static int msm_open(struct drm_device *dev, struct drm_file *file)
495 struct msm_file_private *ctx;
497 /* For now, load gpu on open.. to avoid the requirement of having
498 * firmware in the initrd.
502 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
506 file->driver_priv = ctx;
511 static void msm_preclose(struct drm_device *dev, struct drm_file *file)
513 struct msm_drm_private *priv = dev->dev_private;
514 struct msm_file_private *ctx = file->driver_priv;
516 mutex_lock(&dev->struct_mutex);
517 if (ctx == priv->lastctx)
518 priv->lastctx = NULL;
519 mutex_unlock(&dev->struct_mutex);
524 static void msm_lastclose(struct drm_device *dev)
526 struct msm_drm_private *priv = dev->dev_private;
528 drm_fb_helper_restore_fbdev_mode_unlocked(priv->fbdev);
531 static irqreturn_t msm_irq(int irq, void *arg)
533 struct drm_device *dev = arg;
534 struct msm_drm_private *priv = dev->dev_private;
535 struct msm_kms *kms = priv->kms;
537 return kms->funcs->irq(kms);
540 static void msm_irq_preinstall(struct drm_device *dev)
542 struct msm_drm_private *priv = dev->dev_private;
543 struct msm_kms *kms = priv->kms;
545 kms->funcs->irq_preinstall(kms);
548 static int msm_irq_postinstall(struct drm_device *dev)
550 struct msm_drm_private *priv = dev->dev_private;
551 struct msm_kms *kms = priv->kms;
553 return kms->funcs->irq_postinstall(kms);
556 static void msm_irq_uninstall(struct drm_device *dev)
558 struct msm_drm_private *priv = dev->dev_private;
559 struct msm_kms *kms = priv->kms;
561 kms->funcs->irq_uninstall(kms);
564 static int msm_enable_vblank(struct drm_device *dev, unsigned int pipe)
566 struct msm_drm_private *priv = dev->dev_private;
567 struct msm_kms *kms = priv->kms;
570 DBG("dev=%p, crtc=%u", dev, pipe);
571 return vblank_ctrl_queue_work(priv, pipe, true);
574 static void msm_disable_vblank(struct drm_device *dev, unsigned int pipe)
576 struct msm_drm_private *priv = dev->dev_private;
577 struct msm_kms *kms = priv->kms;
580 DBG("dev=%p, crtc=%u", dev, pipe);
581 vblank_ctrl_queue_work(priv, pipe, false);
588 static int msm_ioctl_get_param(struct drm_device *dev, void *data,
589 struct drm_file *file)
591 struct msm_drm_private *priv = dev->dev_private;
592 struct drm_msm_param *args = data;
595 /* for now, we just have 3d pipe.. eventually this would need to
596 * be more clever to dispatch to appropriate gpu module:
598 if (args->pipe != MSM_PIPE_3D0)
606 return gpu->funcs->get_param(gpu, args->param, &args->value);
609 static int msm_ioctl_gem_new(struct drm_device *dev, void *data,
610 struct drm_file *file)
612 struct drm_msm_gem_new *args = data;
614 if (args->flags & ~MSM_BO_FLAGS) {
615 DRM_ERROR("invalid flags: %08x\n", args->flags);
619 return msm_gem_new_handle(dev, file, args->size,
620 args->flags, &args->handle);
623 static inline ktime_t to_ktime(struct drm_msm_timespec timeout)
625 return ktime_set(timeout.tv_sec, timeout.tv_nsec);
628 static int msm_ioctl_gem_cpu_prep(struct drm_device *dev, void *data,
629 struct drm_file *file)
631 struct drm_msm_gem_cpu_prep *args = data;
632 struct drm_gem_object *obj;
633 ktime_t timeout = to_ktime(args->timeout);
636 if (args->op & ~MSM_PREP_FLAGS) {
637 DRM_ERROR("invalid op: %08x\n", args->op);
641 obj = drm_gem_object_lookup(file, args->handle);
645 ret = msm_gem_cpu_prep(obj, args->op, &timeout);
647 drm_gem_object_unreference_unlocked(obj);
652 static int msm_ioctl_gem_cpu_fini(struct drm_device *dev, void *data,
653 struct drm_file *file)
655 struct drm_msm_gem_cpu_fini *args = data;
656 struct drm_gem_object *obj;
659 obj = drm_gem_object_lookup(file, args->handle);
663 ret = msm_gem_cpu_fini(obj);
665 drm_gem_object_unreference_unlocked(obj);
670 static int msm_ioctl_gem_info(struct drm_device *dev, void *data,
671 struct drm_file *file)
673 struct drm_msm_gem_info *args = data;
674 struct drm_gem_object *obj;
680 obj = drm_gem_object_lookup(file, args->handle);
684 args->offset = msm_gem_mmap_offset(obj);
686 drm_gem_object_unreference_unlocked(obj);
691 static int msm_ioctl_wait_fence(struct drm_device *dev, void *data,
692 struct drm_file *file)
694 struct msm_drm_private *priv = dev->dev_private;
695 struct drm_msm_wait_fence *args = data;
696 ktime_t timeout = to_ktime(args->timeout);
699 DRM_ERROR("invalid pad: %08x\n", args->pad);
706 return msm_wait_fence(priv->gpu->fctx, args->fence, &timeout, true);
709 static int msm_ioctl_gem_madvise(struct drm_device *dev, void *data,
710 struct drm_file *file)
712 struct drm_msm_gem_madvise *args = data;
713 struct drm_gem_object *obj;
716 switch (args->madv) {
717 case MSM_MADV_DONTNEED:
718 case MSM_MADV_WILLNEED:
724 ret = mutex_lock_interruptible(&dev->struct_mutex);
728 obj = drm_gem_object_lookup(file, args->handle);
734 ret = msm_gem_madvise(obj, args->madv);
736 args->retained = ret;
740 drm_gem_object_unreference(obj);
743 mutex_unlock(&dev->struct_mutex);
747 static const struct drm_ioctl_desc msm_ioctls[] = {
748 DRM_IOCTL_DEF_DRV(MSM_GET_PARAM, msm_ioctl_get_param, DRM_AUTH|DRM_RENDER_ALLOW),
749 DRM_IOCTL_DEF_DRV(MSM_GEM_NEW, msm_ioctl_gem_new, DRM_AUTH|DRM_RENDER_ALLOW),
750 DRM_IOCTL_DEF_DRV(MSM_GEM_INFO, msm_ioctl_gem_info, DRM_AUTH|DRM_RENDER_ALLOW),
751 DRM_IOCTL_DEF_DRV(MSM_GEM_CPU_PREP, msm_ioctl_gem_cpu_prep, DRM_AUTH|DRM_RENDER_ALLOW),
752 DRM_IOCTL_DEF_DRV(MSM_GEM_CPU_FINI, msm_ioctl_gem_cpu_fini, DRM_AUTH|DRM_RENDER_ALLOW),
753 DRM_IOCTL_DEF_DRV(MSM_GEM_SUBMIT, msm_ioctl_gem_submit, DRM_AUTH|DRM_RENDER_ALLOW),
754 DRM_IOCTL_DEF_DRV(MSM_WAIT_FENCE, msm_ioctl_wait_fence, DRM_AUTH|DRM_RENDER_ALLOW),
755 DRM_IOCTL_DEF_DRV(MSM_GEM_MADVISE, msm_ioctl_gem_madvise, DRM_AUTH|DRM_RENDER_ALLOW),
758 static const struct vm_operations_struct vm_ops = {
759 .fault = msm_gem_fault,
760 .open = drm_gem_vm_open,
761 .close = drm_gem_vm_close,
764 static const struct file_operations fops = {
765 .owner = THIS_MODULE,
767 .release = drm_release,
768 .unlocked_ioctl = drm_ioctl,
770 .compat_ioctl = drm_compat_ioctl,
775 .mmap = msm_gem_mmap,
778 static struct drm_driver msm_driver = {
779 .driver_features = DRIVER_HAVE_IRQ |
786 .preclose = msm_preclose,
787 .lastclose = msm_lastclose,
788 .irq_handler = msm_irq,
789 .irq_preinstall = msm_irq_preinstall,
790 .irq_postinstall = msm_irq_postinstall,
791 .irq_uninstall = msm_irq_uninstall,
792 .get_vblank_counter = drm_vblank_no_hw_counter,
793 .enable_vblank = msm_enable_vblank,
794 .disable_vblank = msm_disable_vblank,
795 .gem_free_object = msm_gem_free_object,
796 .gem_vm_ops = &vm_ops,
797 .dumb_create = msm_gem_dumb_create,
798 .dumb_map_offset = msm_gem_dumb_map_offset,
799 .dumb_destroy = drm_gem_dumb_destroy,
800 .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
801 .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
802 .gem_prime_export = drm_gem_prime_export,
803 .gem_prime_import = drm_gem_prime_import,
804 .gem_prime_pin = msm_gem_prime_pin,
805 .gem_prime_unpin = msm_gem_prime_unpin,
806 .gem_prime_get_sg_table = msm_gem_prime_get_sg_table,
807 .gem_prime_import_sg_table = msm_gem_prime_import_sg_table,
808 .gem_prime_vmap = msm_gem_prime_vmap,
809 .gem_prime_vunmap = msm_gem_prime_vunmap,
810 .gem_prime_mmap = msm_gem_prime_mmap,
811 #ifdef CONFIG_DEBUG_FS
812 .debugfs_init = msm_debugfs_init,
813 .debugfs_cleanup = msm_debugfs_cleanup,
815 .ioctls = msm_ioctls,
816 .num_ioctls = DRM_MSM_NUM_IOCTLS,
819 .desc = "MSM Snapdragon DRM",
821 .major = MSM_VERSION_MAJOR,
822 .minor = MSM_VERSION_MINOR,
823 .patchlevel = MSM_VERSION_PATCHLEVEL,
826 #ifdef CONFIG_PM_SLEEP
827 static int msm_pm_suspend(struct device *dev)
829 struct drm_device *ddev = dev_get_drvdata(dev);
831 drm_kms_helper_poll_disable(ddev);
836 static int msm_pm_resume(struct device *dev)
838 struct drm_device *ddev = dev_get_drvdata(dev);
840 drm_kms_helper_poll_enable(ddev);
846 static const struct dev_pm_ops msm_pm_ops = {
847 SET_SYSTEM_SLEEP_PM_OPS(msm_pm_suspend, msm_pm_resume)
851 * Componentized driver support:
855 * NOTE: duplication of the same code as exynos or imx (or probably any other).
856 * so probably some room for some helpers
858 static int compare_of(struct device *dev, void *data)
860 return dev->of_node == data;
864 * Identify what components need to be added by parsing what remote-endpoints
865 * our MDP output ports are connected to. In the case of LVDS on MDP4, there
866 * is no external component that we need to add since LVDS is within MDP4
869 static int add_components_mdp(struct device *mdp_dev,
870 struct component_match **matchptr)
872 struct device_node *np = mdp_dev->of_node;
873 struct device_node *ep_node;
874 struct device *master_dev;
877 * on MDP4 based platforms, the MDP platform device is the component
878 * master that adds other display interface components to itself.
880 * on MDP5 based platforms, the MDSS platform device is the component
881 * master that adds MDP5 and other display interface components to
884 if (of_device_is_compatible(np, "qcom,mdp4"))
885 master_dev = mdp_dev;
887 master_dev = mdp_dev->parent;
889 for_each_endpoint_of_node(np, ep_node) {
890 struct device_node *intf;
891 struct of_endpoint ep;
894 ret = of_graph_parse_endpoint(ep_node, &ep);
896 dev_err(mdp_dev, "unable to parse port endpoint\n");
897 of_node_put(ep_node);
902 * The LCDC/LVDS port on MDP4 is a speacial case where the
903 * remote-endpoint isn't a component that we need to add
905 if (of_device_is_compatible(np, "qcom,mdp4") &&
907 of_node_put(ep_node);
912 * It's okay if some of the ports don't have a remote endpoint
913 * specified. It just means that the port isn't connected to
914 * any external interface.
916 intf = of_graph_get_remote_port_parent(ep_node);
918 of_node_put(ep_node);
922 component_match_add(master_dev, matchptr, compare_of, intf);
925 of_node_put(ep_node);
931 static int compare_name_mdp(struct device *dev, void *data)
933 return (strstr(dev_name(dev), "mdp") != NULL);
936 static int add_display_components(struct device *dev,
937 struct component_match **matchptr)
939 struct device *mdp_dev;
943 * MDP5 based devices don't have a flat hierarchy. There is a top level
944 * parent: MDSS, and children: MDP5, DSI, HDMI, eDP etc. Populate the
945 * children devices, find the MDP5 node, and then add the interfaces
946 * to our components list.
948 if (of_device_is_compatible(dev->of_node, "qcom,mdss")) {
949 ret = of_platform_populate(dev->of_node, NULL, NULL, dev);
951 dev_err(dev, "failed to populate children devices\n");
955 mdp_dev = device_find_child(dev, NULL, compare_name_mdp);
957 dev_err(dev, "failed to find MDSS MDP node\n");
958 of_platform_depopulate(dev);
964 /* add the MDP component itself */
965 component_match_add(dev, matchptr, compare_of,
972 ret = add_components_mdp(mdp_dev, matchptr);
974 of_platform_depopulate(dev);
980 * We don't know what's the best binding to link the gpu with the drm device.
981 * Fow now, we just hunt for all the possible gpus that we support, and add them
984 static const struct of_device_id msm_gpu_match[] = {
985 { .compatible = "qcom,adreno-3xx" },
986 { .compatible = "qcom,kgsl-3d0" },
990 static int add_gpu_components(struct device *dev,
991 struct component_match **matchptr)
993 struct device_node *np;
995 np = of_find_matching_node(NULL, msm_gpu_match);
999 component_match_add(dev, matchptr, compare_of, np);
1006 static int msm_drm_bind(struct device *dev)
1008 return msm_drm_init(dev, &msm_driver);
1011 static void msm_drm_unbind(struct device *dev)
1013 msm_drm_uninit(dev);
1016 static const struct component_master_ops msm_drm_ops = {
1017 .bind = msm_drm_bind,
1018 .unbind = msm_drm_unbind,
1025 static int msm_pdev_probe(struct platform_device *pdev)
1027 struct component_match *match = NULL;
1030 ret = add_display_components(&pdev->dev, &match);
1034 ret = add_gpu_components(&pdev->dev, &match);
1038 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
1039 return component_master_add_with_match(&pdev->dev, &msm_drm_ops, match);
1042 static int msm_pdev_remove(struct platform_device *pdev)
1044 component_master_del(&pdev->dev, &msm_drm_ops);
1045 of_platform_depopulate(&pdev->dev);
1050 static const struct of_device_id dt_match[] = {
1051 { .compatible = "qcom,mdp4", .data = (void *)4 }, /* MDP4 */
1052 { .compatible = "qcom,mdss", .data = (void *)5 }, /* MDP5 MDSS */
1055 MODULE_DEVICE_TABLE(of, dt_match);
1057 static struct platform_driver msm_platform_driver = {
1058 .probe = msm_pdev_probe,
1059 .remove = msm_pdev_remove,
1062 .of_match_table = dt_match,
1067 static int __init msm_drm_register(void)
1073 msm_hdmi_register();
1075 return platform_driver_register(&msm_platform_driver);
1078 static void __exit msm_drm_unregister(void)
1081 platform_driver_unregister(&msm_platform_driver);
1082 msm_hdmi_unregister();
1083 adreno_unregister();
1084 msm_edp_unregister();
1085 msm_dsi_unregister();
1086 msm_mdp_unregister();
1089 module_init(msm_drm_register);
1090 module_exit(msm_drm_unregister);
1093 MODULE_DESCRIPTION("MSM DRM Driver");
1094 MODULE_LICENSE("GPL");