Merge tag 'lsk-v4.4-16.07-android'
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / drm / rockchip / rockchip_drm_drv.c
1 /*
2  * Copyright (C) Fuzhou Rockchip Electronics Co.Ltd
3  * Author:Mark Yao <mark.yao@rock-chips.com>
4  *
5  * based on exynos_drm_drv.c
6  *
7  * This software is licensed under the terms of the GNU General Public
8  * License version 2, as published by the Free Software Foundation, and
9  * may be copied, distributed, and modified under those terms.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  */
16
17 #include <linux/dma-iommu.h>
18
19 #include <drm/drmP.h>
20 #include <drm/drm_crtc_helper.h>
21 #include <drm/drm_fb_helper.h>
22 #include <drm/drm_sync_helper.h>
23 #include <drm/rockchip_drm.h>
24 #include <linux/dma-mapping.h>
25 #include <linux/pm_runtime.h>
26 #include <linux/module.h>
27 #include <linux/of_graph.h>
28 #include <linux/component.h>
29 #include <linux/fence.h>
30 #include <linux/console.h>
31
32 #include "rockchip_drm_drv.h"
33 #include "rockchip_drm_fb.h"
34 #include "rockchip_drm_fbdev.h"
35 #include "rockchip_drm_gem.h"
36 #include "rockchip_drm_rga.h"
37
38 #define DRIVER_NAME     "rockchip"
39 #define DRIVER_DESC     "RockChip Soc DRM"
40 #define DRIVER_DATE     "20140818"
41 #define DRIVER_MAJOR    1
42 #define DRIVER_MINOR    0
43
44 static LIST_HEAD(rockchip_drm_subdrv_list);
45 static DEFINE_MUTEX(subdrv_list_mutex);
46
47 /*
48  * Attach a (component) device to the shared drm dma mapping from master drm
49  * device.  This is used by the VOPs to map GEM buffers to a common DMA
50  * mapping.
51  */
52 int rockchip_drm_dma_attach_device(struct drm_device *drm_dev,
53                                    struct device *dev)
54 {
55         struct rockchip_drm_private *private = drm_dev->dev_private;
56         struct iommu_domain *domain = private->domain;
57         int ret;
58
59         ret = dma_set_coherent_mask(dev, DMA_BIT_MASK(32));
60         if (ret)
61                 return ret;
62
63         dma_set_max_seg_size(dev, DMA_BIT_MASK(32));
64         ret = iommu_attach_device(domain, dev);
65         if (ret) {
66                 dev_err(dev, "Failed to attach iommu device\n");
67                 return ret;
68         }
69
70         if (!common_iommu_setup_dma_ops(dev, 0x10000000, SZ_2G, domain->ops)) {
71                 dev_err(dev, "Failed to set dma_ops\n");
72                 iommu_detach_device(domain, dev);
73                 ret = -ENODEV;
74         }
75
76         return ret;
77 }
78
79 void rockchip_drm_dma_detach_device(struct drm_device *drm_dev,
80                                     struct device *dev)
81 {
82         struct rockchip_drm_private *private = drm_dev->dev_private;
83         struct iommu_domain *domain = private->domain;
84
85         iommu_detach_device(domain, dev);
86 }
87
88 int rockchip_register_crtc_funcs(struct drm_crtc *crtc,
89                                  const struct rockchip_crtc_funcs *crtc_funcs)
90 {
91         int pipe = drm_crtc_index(crtc);
92         struct rockchip_drm_private *priv = crtc->dev->dev_private;
93
94         if (pipe > ROCKCHIP_MAX_CRTC)
95                 return -EINVAL;
96
97         priv->crtc_funcs[pipe] = crtc_funcs;
98
99         return 0;
100 }
101
102 void rockchip_unregister_crtc_funcs(struct drm_crtc *crtc)
103 {
104         int pipe = drm_crtc_index(crtc);
105         struct rockchip_drm_private *priv = crtc->dev->dev_private;
106
107         if (pipe > ROCKCHIP_MAX_CRTC)
108                 return;
109
110         priv->crtc_funcs[pipe] = NULL;
111 }
112
113 static struct drm_crtc *rockchip_crtc_from_pipe(struct drm_device *drm,
114                                                 int pipe)
115 {
116         struct drm_crtc *crtc;
117         int i = 0;
118
119         list_for_each_entry(crtc, &drm->mode_config.crtc_list, head)
120                 if (i++ == pipe)
121                         return crtc;
122
123         return NULL;
124 }
125
126 static int rockchip_drm_crtc_enable_vblank(struct drm_device *dev,
127                                            unsigned int pipe)
128 {
129         struct rockchip_drm_private *priv = dev->dev_private;
130         struct drm_crtc *crtc = rockchip_crtc_from_pipe(dev, pipe);
131
132         if (crtc && priv->crtc_funcs[pipe] &&
133             priv->crtc_funcs[pipe]->enable_vblank)
134                 return priv->crtc_funcs[pipe]->enable_vblank(crtc);
135
136         return 0;
137 }
138
139 static void rockchip_drm_crtc_disable_vblank(struct drm_device *dev,
140                                              unsigned int pipe)
141 {
142         struct rockchip_drm_private *priv = dev->dev_private;
143         struct drm_crtc *crtc = rockchip_crtc_from_pipe(dev, pipe);
144
145         if (crtc && priv->crtc_funcs[pipe] &&
146             priv->crtc_funcs[pipe]->enable_vblank)
147                 priv->crtc_funcs[pipe]->disable_vblank(crtc);
148 }
149
150 static int rockchip_drm_load(struct drm_device *drm_dev, unsigned long flags)
151 {
152         struct rockchip_drm_private *private;
153         struct device *dev = drm_dev->dev;
154         struct drm_connector *connector;
155         struct iommu_group *group;
156         int ret;
157
158         private = devm_kzalloc(drm_dev->dev, sizeof(*private), GFP_KERNEL);
159         if (!private)
160                 return -ENOMEM;
161
162         mutex_init(&private->commit.lock);
163         INIT_WORK(&private->commit.work, rockchip_drm_atomic_work);
164
165         drm_dev->dev_private = private;
166
167 #ifdef CONFIG_DRM_DMA_SYNC
168         private->cpu_fence_context = fence_context_alloc(1);
169         atomic_set(&private->cpu_fence_seqno, 0);
170 #endif
171
172         drm_mode_config_init(drm_dev);
173
174         rockchip_drm_mode_config_init(drm_dev);
175
176         dev->dma_parms = devm_kzalloc(dev, sizeof(*dev->dma_parms),
177                                       GFP_KERNEL);
178         if (!dev->dma_parms) {
179                 ret = -ENOMEM;
180                 goto err_config_cleanup;
181         }
182
183         private->domain = iommu_domain_alloc(&platform_bus_type);
184         if (!private->domain)
185                 return -ENOMEM;
186
187         ret = iommu_get_dma_cookie(private->domain);
188         if (ret)
189                 goto err_free_domain;
190
191         group = iommu_group_get(dev);
192         if (!group) {
193                 group = iommu_group_alloc();
194                 if (IS_ERR(group)) {
195                         dev_err(dev, "Failed to allocate IOMMU group\n");
196                         goto err_put_cookie;
197                 }
198
199                 ret = iommu_group_add_device(group, dev);
200                 iommu_group_put(group);
201                 if (ret) {
202                         dev_err(dev, "failed to add device to IOMMU group\n");
203                         goto err_put_cookie;
204                 }
205         }
206         /*
207          * Attach virtual iommu device, sub iommu device can share the same
208          * mapping with it.
209          */
210         ret = rockchip_drm_dma_attach_device(drm_dev, dev);
211         if (ret)
212                 goto err_group_remove_device;
213
214         /* Try to bind all sub drivers. */
215         ret = component_bind_all(dev, drm_dev);
216         if (ret)
217                 goto err_detach_device;
218
219         /*
220          * All components are now added, we can publish the connector sysfs
221          * entries to userspace.  This will generate hotplug events and so
222          * userspace will expect to be able to access DRM at this point.
223          */
224         list_for_each_entry(connector, &drm_dev->mode_config.connector_list,
225                         head) {
226                 ret = drm_connector_register(connector);
227                 if (ret) {
228                         dev_err(drm_dev->dev,
229                                 "[CONNECTOR:%d:%s] drm_connector_register failed: %d\n",
230                                 connector->base.id,
231                                 connector->name, ret);
232                         goto err_unbind;
233                 }
234         }
235
236         /* init kms poll for handling hpd */
237         drm_kms_helper_poll_init(drm_dev);
238
239         /*
240          * enable drm irq mode.
241          * - with irq_enabled = true, we can use the vblank feature.
242          */
243         drm_dev->irq_enabled = true;
244
245         ret = drm_vblank_init(drm_dev, ROCKCHIP_MAX_CRTC);
246         if (ret)
247                 goto err_kms_helper_poll_fini;
248
249         /*
250          * with vblank_disable_allowed = true, vblank interrupt will be disabled
251          * by drm timer once a current process gives up ownership of
252          * vblank event.(after drm_vblank_put function is called)
253          */
254         drm_dev->vblank_disable_allowed = true;
255
256         drm_mode_config_reset(drm_dev);
257
258         ret = rockchip_drm_fbdev_init(drm_dev);
259         if (ret)
260                 goto err_vblank_cleanup;
261
262         return 0;
263 err_vblank_cleanup:
264         drm_vblank_cleanup(drm_dev);
265 err_kms_helper_poll_fini:
266         drm_kms_helper_poll_fini(drm_dev);
267 err_unbind:
268         component_unbind_all(dev, drm_dev);
269 err_detach_device:
270         rockchip_drm_dma_detach_device(drm_dev, dev);
271 err_group_remove_device:
272         iommu_group_remove_device(dev);
273 err_put_cookie:
274         iommu_put_dma_cookie(private->domain);
275 err_free_domain:
276         iommu_domain_free(private->domain);
277 err_config_cleanup:
278         drm_mode_config_cleanup(drm_dev);
279         drm_dev->dev_private = NULL;
280         return ret;
281 }
282
283 static int rockchip_drm_unload(struct drm_device *drm_dev)
284 {
285         struct device *dev = drm_dev->dev;
286         struct rockchip_drm_private *private = drm_dev->dev_private;
287
288         rockchip_drm_fbdev_fini(drm_dev);
289         drm_vblank_cleanup(drm_dev);
290         drm_kms_helper_poll_fini(drm_dev);
291         component_unbind_all(dev, drm_dev);
292         rockchip_drm_dma_detach_device(drm_dev, dev);
293         iommu_group_remove_device(dev);
294         iommu_put_dma_cookie(private->domain);
295         iommu_domain_free(private->domain);
296         drm_mode_config_cleanup(drm_dev);
297         drm_dev->dev_private = NULL;
298
299         return 0;
300 }
301
302 static void rockchip_drm_crtc_cancel_pending_vblank(struct drm_crtc *crtc,
303                                                     struct drm_file *file_priv)
304 {
305         struct rockchip_drm_private *priv = crtc->dev->dev_private;
306         int pipe = drm_crtc_index(crtc);
307
308         if (pipe < ROCKCHIP_MAX_CRTC &&
309             priv->crtc_funcs[pipe] &&
310             priv->crtc_funcs[pipe]->cancel_pending_vblank)
311                 priv->crtc_funcs[pipe]->cancel_pending_vblank(crtc, file_priv);
312 }
313
314 int rockchip_drm_register_subdrv(struct drm_rockchip_subdrv *subdrv)
315 {
316         if (!subdrv)
317                 return -EINVAL;
318
319         mutex_lock(&subdrv_list_mutex);
320         list_add_tail(&subdrv->list, &rockchip_drm_subdrv_list);
321         mutex_unlock(&subdrv_list_mutex);
322
323         return 0;
324 }
325 EXPORT_SYMBOL_GPL(rockchip_drm_register_subdrv);
326
327 int rockchip_drm_unregister_subdrv(struct drm_rockchip_subdrv *subdrv)
328 {
329         if (!subdrv)
330                 return -EINVAL;
331
332         mutex_lock(&subdrv_list_mutex);
333         list_del(&subdrv->list);
334         mutex_unlock(&subdrv_list_mutex);
335
336         return 0;
337 }
338 EXPORT_SYMBOL_GPL(rockchip_drm_unregister_subdrv);
339
340 static int rockchip_drm_open(struct drm_device *dev, struct drm_file *file)
341 {
342         struct rockchip_drm_file_private *file_priv;
343         struct drm_rockchip_subdrv *subdrv;
344         int ret = 0;
345
346         file_priv = kzalloc(sizeof(*file_priv), GFP_KERNEL);
347         if (!file_priv)
348                 return -ENOMEM;
349         INIT_LIST_HEAD(&file_priv->gem_cpu_acquire_list);
350
351         file->driver_priv = file_priv;
352
353         mutex_lock(&subdrv_list_mutex);
354         list_for_each_entry(subdrv, &rockchip_drm_subdrv_list, list) {
355                 ret = subdrv->open(dev, subdrv->dev, file);
356                 if (ret) {
357                         mutex_unlock(&subdrv_list_mutex);
358                         goto err_free_file_priv;
359                 }
360         }
361         mutex_unlock(&subdrv_list_mutex);
362
363         return 0;
364
365 err_free_file_priv:
366         kfree(file_priv);
367         file_priv = NULL;
368
369         return ret;
370 }
371
372 static void rockchip_drm_preclose(struct drm_device *dev,
373                                   struct drm_file *file_priv)
374 {
375         struct rockchip_drm_file_private *file_private = file_priv->driver_priv;
376         struct rockchip_gem_object_node *cur, *d;
377         struct drm_rockchip_subdrv *subdrv;
378         struct drm_crtc *crtc;
379
380         list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
381                 rockchip_drm_crtc_cancel_pending_vblank(crtc, file_priv);
382
383         mutex_lock(&dev->struct_mutex);
384         list_for_each_entry_safe(cur, d,
385                         &file_private->gem_cpu_acquire_list, list) {
386 #ifdef CONFIG_DRM_DMA_SYNC
387                 BUG_ON(!cur->rockchip_gem_obj->acquire_fence);
388                 drm_fence_signal_and_put(&cur->rockchip_gem_obj->acquire_fence);
389 #endif
390                 drm_gem_object_unreference(&cur->rockchip_gem_obj->base);
391                 kfree(cur);
392         }
393         /* since we are deleting the whole list, just initialize the header
394          * instead of calling list_del for every element
395          */
396         INIT_LIST_HEAD(&file_private->gem_cpu_acquire_list);
397         mutex_unlock(&dev->struct_mutex);
398
399         mutex_lock(&subdrv_list_mutex);
400         list_for_each_entry(subdrv, &rockchip_drm_subdrv_list, list)
401                 subdrv->close(dev, subdrv->dev, file_priv);
402         mutex_unlock(&subdrv_list_mutex);
403 }
404
405 static void rockchip_drm_postclose(struct drm_device *dev, struct drm_file *file)
406 {
407         kfree(file->driver_priv);
408         file->driver_priv = NULL;
409 }
410
411 void rockchip_drm_lastclose(struct drm_device *dev)
412 {
413         struct rockchip_drm_private *priv = dev->dev_private;
414
415         drm_fb_helper_restore_fbdev_mode_unlocked(priv->fbdev_helper);
416 }
417
418 static const struct drm_ioctl_desc rockchip_ioctls[] = {
419         DRM_IOCTL_DEF_DRV(ROCKCHIP_GEM_CREATE, rockchip_gem_create_ioctl,
420                           DRM_UNLOCKED | DRM_AUTH | DRM_RENDER_ALLOW),
421         DRM_IOCTL_DEF_DRV(ROCKCHIP_GEM_MAP_OFFSET,
422                           rockchip_gem_map_offset_ioctl,
423                           DRM_UNLOCKED | DRM_AUTH | DRM_RENDER_ALLOW),
424         DRM_IOCTL_DEF_DRV(ROCKCHIP_GEM_CPU_ACQUIRE,
425                           rockchip_gem_cpu_acquire_ioctl,
426                           DRM_UNLOCKED | DRM_AUTH | DRM_RENDER_ALLOW),
427         DRM_IOCTL_DEF_DRV(ROCKCHIP_GEM_CPU_RELEASE,
428                           rockchip_gem_cpu_release_ioctl,
429                           DRM_UNLOCKED | DRM_AUTH | DRM_RENDER_ALLOW),
430         DRM_IOCTL_DEF_DRV(ROCKCHIP_RGA_GET_VER, rockchip_rga_get_ver_ioctl,
431                           DRM_AUTH | DRM_RENDER_ALLOW),
432         DRM_IOCTL_DEF_DRV(ROCKCHIP_RGA_SET_CMDLIST,
433                           rockchip_rga_set_cmdlist_ioctl,
434                           DRM_AUTH | DRM_RENDER_ALLOW),
435         DRM_IOCTL_DEF_DRV(ROCKCHIP_RGA_EXEC, rockchip_rga_exec_ioctl,
436                           DRM_AUTH | DRM_RENDER_ALLOW),
437 };
438
439 static const struct file_operations rockchip_drm_driver_fops = {
440         .owner = THIS_MODULE,
441         .open = drm_open,
442         .mmap = rockchip_gem_mmap,
443         .poll = drm_poll,
444         .read = drm_read,
445         .unlocked_ioctl = drm_ioctl,
446 #ifdef CONFIG_COMPAT
447         .compat_ioctl = drm_compat_ioctl,
448 #endif
449         .release = drm_release,
450 };
451
452 const struct vm_operations_struct rockchip_drm_vm_ops = {
453         .open = drm_gem_vm_open,
454         .close = drm_gem_vm_close,
455 };
456
457 static struct drm_driver rockchip_drm_driver = {
458         .driver_features        = DRIVER_MODESET | DRIVER_GEM |
459                                   DRIVER_PRIME | DRIVER_ATOMIC |
460                                   DRIVER_RENDER,
461         .load                   = rockchip_drm_load,
462         .unload                 = rockchip_drm_unload,
463         .preclose               = rockchip_drm_preclose,
464         .lastclose              = rockchip_drm_lastclose,
465         .get_vblank_counter     = drm_vblank_no_hw_counter,
466         .open                   = rockchip_drm_open,
467         .postclose              = rockchip_drm_postclose,
468         .enable_vblank          = rockchip_drm_crtc_enable_vblank,
469         .disable_vblank         = rockchip_drm_crtc_disable_vblank,
470         .gem_vm_ops             = &rockchip_drm_vm_ops,
471         .gem_free_object        = rockchip_gem_free_object,
472         .dumb_create            = rockchip_gem_dumb_create,
473         .dumb_map_offset        = rockchip_gem_dumb_map_offset,
474         .dumb_destroy           = drm_gem_dumb_destroy,
475         .prime_handle_to_fd     = drm_gem_prime_handle_to_fd,
476         .prime_fd_to_handle     = drm_gem_prime_fd_to_handle,
477         .gem_prime_import       = drm_gem_prime_import,
478         .gem_prime_import_sg_table = rockchip_gem_prime_import_sg_table,
479         .gem_prime_export       = drm_gem_prime_export,
480         .gem_prime_get_sg_table = rockchip_gem_prime_get_sg_table,
481         .gem_prime_vmap         = rockchip_gem_prime_vmap,
482         .gem_prime_vunmap       = rockchip_gem_prime_vunmap,
483         .gem_prime_mmap         = rockchip_gem_mmap_buf,
484         .ioctls                 = rockchip_ioctls,
485         .num_ioctls             = ARRAY_SIZE(rockchip_ioctls),
486         .fops                   = &rockchip_drm_driver_fops,
487         .name   = DRIVER_NAME,
488         .desc   = DRIVER_DESC,
489         .date   = DRIVER_DATE,
490         .major  = DRIVER_MAJOR,
491         .minor  = DRIVER_MINOR,
492 };
493
494 #ifdef CONFIG_PM_SLEEP
495 void rockchip_drm_fb_suspend(struct drm_device *drm)
496 {
497         struct rockchip_drm_private *priv = drm->dev_private;
498
499         console_lock();
500         drm_fb_helper_set_suspend(priv->fbdev_helper, 1);
501         console_unlock();
502 }
503
504 void rockchip_drm_fb_resume(struct drm_device *drm)
505 {
506         struct rockchip_drm_private *priv = drm->dev_private;
507
508         console_lock();
509         drm_fb_helper_set_suspend(priv->fbdev_helper, 0);
510         console_unlock();
511 }
512
513 static int rockchip_drm_sys_suspend(struct device *dev)
514 {
515         struct drm_device *drm = dev_get_drvdata(dev);
516         struct rockchip_drm_private *priv = drm->dev_private;
517
518         drm_kms_helper_poll_disable(drm);
519         rockchip_drm_fb_suspend(drm);
520
521         priv->state = drm_atomic_helper_suspend(drm);
522         if (IS_ERR(priv->state)) {
523                 rockchip_drm_fb_resume(drm);
524                 drm_kms_helper_poll_enable(drm);
525                 return PTR_ERR(priv->state);
526         }
527
528         return 0;
529 }
530
531 static int rockchip_drm_sys_resume(struct device *dev)
532 {
533         struct drm_device *drm = dev_get_drvdata(dev);
534         struct rockchip_drm_private *priv = drm->dev_private;
535
536         drm_atomic_helper_resume(drm, priv->state);
537         rockchip_drm_fb_resume(drm);
538         drm_kms_helper_poll_enable(drm);
539
540         return 0;
541 }
542 #endif
543
544 static const struct dev_pm_ops rockchip_drm_pm_ops = {
545         SET_SYSTEM_SLEEP_PM_OPS(rockchip_drm_sys_suspend,
546                                 rockchip_drm_sys_resume)
547 };
548
549 static int compare_of(struct device *dev, void *data)
550 {
551         struct device_node *np = data;
552
553         return dev->of_node == np;
554 }
555
556 static void rockchip_add_endpoints(struct device *dev,
557                                    struct component_match **match,
558                                    struct device_node *port)
559 {
560         struct device_node *ep, *remote;
561
562         for_each_child_of_node(port, ep) {
563                 remote = of_graph_get_remote_port_parent(ep);
564                 if (!remote || !of_device_is_available(remote)) {
565                         of_node_put(remote);
566                         continue;
567                 } else if (!of_device_is_available(remote->parent)) {
568                         dev_warn(dev, "parent device of %s is not available\n",
569                                  remote->full_name);
570                         of_node_put(remote);
571                         continue;
572                 }
573
574                 component_match_add(dev, match, compare_of, remote);
575                 of_node_put(remote);
576         }
577 }
578
579 static int rockchip_drm_bind(struct device *dev)
580 {
581         struct drm_device *drm;
582         int ret;
583
584         drm = drm_dev_alloc(&rockchip_drm_driver, dev);
585         if (!drm)
586                 return -ENOMEM;
587
588         ret = drm_dev_set_unique(drm, "%s", dev_name(dev));
589         if (ret)
590                 goto err_free;
591
592         ret = drm_dev_register(drm, 0);
593         if (ret)
594                 goto err_free;
595
596         dev_set_drvdata(dev, drm);
597
598         return 0;
599
600 err_free:
601         drm_dev_unref(drm);
602         return ret;
603 }
604
605 static void rockchip_drm_unbind(struct device *dev)
606 {
607         struct drm_device *drm = dev_get_drvdata(dev);
608
609         drm_dev_unregister(drm);
610         drm_dev_unref(drm);
611         dev_set_drvdata(dev, NULL);
612 }
613
614 static const struct component_master_ops rockchip_drm_ops = {
615         .bind = rockchip_drm_bind,
616         .unbind = rockchip_drm_unbind,
617 };
618
619 static int rockchip_drm_platform_probe(struct platform_device *pdev)
620 {
621         struct device *dev = &pdev->dev;
622         struct component_match *match = NULL;
623         struct device_node *np = dev->of_node;
624         struct device_node *port;
625         int i;
626
627         if (!np)
628                 return -ENODEV;
629         /*
630          * Bind the crtc ports first, so that
631          * drm_of_find_possible_crtcs called from encoder .bind callbacks
632          * works as expected.
633          */
634         for (i = 0;; i++) {
635                 port = of_parse_phandle(np, "ports", i);
636                 if (!port)
637                         break;
638
639                 if (!of_device_is_available(port->parent)) {
640                         of_node_put(port);
641                         continue;
642                 }
643
644                 component_match_add(dev, &match, compare_of, port->parent);
645                 of_node_put(port);
646         }
647
648         if (i == 0) {
649                 dev_err(dev, "missing 'ports' property\n");
650                 return -ENODEV;
651         }
652
653         if (!match) {
654                 dev_err(dev, "No available vop found for display-subsystem.\n");
655                 return -ENODEV;
656         }
657         /*
658          * For each bound crtc, bind the encoders attached to its
659          * remote endpoint.
660          */
661         for (i = 0;; i++) {
662                 port = of_parse_phandle(np, "ports", i);
663                 if (!port)
664                         break;
665
666                 if (!of_device_is_available(port->parent)) {
667                         of_node_put(port);
668                         continue;
669                 }
670
671                 rockchip_add_endpoints(dev, &match, port);
672                 of_node_put(port);
673         }
674
675         return component_master_add_with_match(dev, &rockchip_drm_ops, match);
676 }
677
678 static int rockchip_drm_platform_remove(struct platform_device *pdev)
679 {
680         component_master_del(&pdev->dev, &rockchip_drm_ops);
681
682         return 0;
683 }
684
685 static const struct of_device_id rockchip_drm_dt_ids[] = {
686         { .compatible = "rockchip,display-subsystem", },
687         { /* sentinel */ },
688 };
689 MODULE_DEVICE_TABLE(of, rockchip_drm_dt_ids);
690
691 static struct platform_driver rockchip_drm_platform_driver = {
692         .probe = rockchip_drm_platform_probe,
693         .remove = rockchip_drm_platform_remove,
694         .driver = {
695                 .name = "rockchip-drm",
696                 .of_match_table = rockchip_drm_dt_ids,
697                 .pm = &rockchip_drm_pm_ops,
698         },
699 };
700
701 module_platform_driver(rockchip_drm_platform_driver);
702
703 MODULE_AUTHOR("Mark Yao <mark.yao@rock-chips.com>");
704 MODULE_DESCRIPTION("ROCKCHIP DRM Driver");
705 MODULE_LICENSE("GPL v2");