ARM64: DTS: Add rk3399-firefly uart4 device, node as /dev/ttyS1
[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 <drm/drmP.h>
18 #include <drm/drm_atomic.h>
19 #include <drm/drm_crtc_helper.h>
20 #include <drm/drm_fb_helper.h>
21 #include <drm/drm_sync_helper.h>
22 #include <drm/rockchip_drm.h>
23 #include <linux/dma-mapping.h>
24 #include <linux/dma-iommu.h>
25 #include <linux/pm_runtime.h>
26 #include <linux/memblock.h>
27 #include <linux/module.h>
28 #include <linux/of_address.h>
29 #include <linux/of_graph.h>
30 #include <linux/component.h>
31 #include <linux/fence.h>
32 #include <linux/console.h>
33 #include <linux/iommu.h>
34
35 #include <drm/rockchip_drm.h>
36
37 #include "rockchip_drm_drv.h"
38 #include "rockchip_drm_fb.h"
39 #include "rockchip_drm_fbdev.h"
40 #include "rockchip_drm_gem.h"
41 #include "rockchip_drm_rga.h"
42
43 #define DRIVER_NAME     "rockchip"
44 #define DRIVER_DESC     "RockChip Soc DRM"
45 #define DRIVER_DATE     "20140818"
46 #define DRIVER_MAJOR    1
47 #define DRIVER_MINOR    0
48
49 static bool is_support_iommu = true;
50
51 static LIST_HEAD(rockchip_drm_subdrv_list);
52 static DEFINE_MUTEX(subdrv_list_mutex);
53 static struct drm_driver rockchip_drm_driver;
54
55 struct rockchip_drm_mode_set {
56         struct list_head head;
57         struct drm_framebuffer *fb;
58         struct drm_connector *connector;
59         struct drm_crtc *crtc;
60         struct drm_display_mode *mode;
61         int hdisplay;
62         int vdisplay;
63         int vrefresh;
64
65         bool mode_changed;
66         bool ymirror;
67         int ratio;
68 };
69
70 #ifndef MODULE
71 static struct drm_crtc *find_crtc_by_node(struct drm_device *drm_dev,
72                                           struct device_node *node)
73 {
74         struct device_node *np_crtc;
75         struct drm_crtc *crtc;
76
77         np_crtc = of_get_parent(node);
78         if (!np_crtc || !of_device_is_available(np_crtc))
79                 return NULL;
80
81         drm_for_each_crtc(crtc, drm_dev) {
82                 if (crtc->port == np_crtc)
83                         return crtc;
84         }
85
86         return NULL;
87 }
88
89 static struct drm_connector *find_connector_by_node(struct drm_device *drm_dev,
90                                                     struct device_node *node)
91 {
92         struct device_node *np_connector;
93         struct drm_connector *connector;
94
95         np_connector = of_graph_get_remote_port_parent(node);
96         if (!np_connector || !of_device_is_available(np_connector))
97                 return NULL;
98
99         drm_for_each_connector(connector, drm_dev) {
100                 if (connector->port == np_connector)
101                         return connector;
102         }
103
104         return NULL;
105 }
106
107 void rockchip_free_loader_memory(struct drm_device *drm)
108 {
109         struct rockchip_drm_private *private = drm->dev_private;
110         struct rockchip_logo *logo;
111         void *start, *end;
112
113         if (!private || !private->logo || --private->logo->count)
114                 return;
115
116         logo = private->logo;
117         start = phys_to_virt(logo->start);
118         end = phys_to_virt(logo->size);
119
120         if (private->domain) {
121                 iommu_unmap(private->domain, logo->dma_addr,
122                             logo->iommu_map_size);
123                 drm_mm_remove_node(&logo->mm);
124         } else {
125                 dma_unmap_sg(drm->dev, logo->sgt->sgl,
126                              logo->sgt->nents, DMA_TO_DEVICE);
127         }
128         sg_free_table(logo->sgt);
129         memblock_free(logo->start, logo->size);
130         free_reserved_area(start, end, -1, "drm_logo");
131         kfree(logo);
132         private->logo = NULL;
133 }
134
135 static int init_loader_memory(struct drm_device *drm_dev)
136 {
137         struct rockchip_drm_private *private = drm_dev->dev_private;
138         struct rockchip_logo *logo;
139         struct device_node *np = drm_dev->dev->of_node;
140         struct device_node *node;
141         unsigned long nr_pages;
142         struct page **pages;
143         struct sg_table *sgt;
144         phys_addr_t start, size;
145         struct resource res;
146         int i, ret;
147
148         node = of_parse_phandle(np, "memory-region", 0);
149         if (!node)
150                 return -ENOMEM;
151
152         ret = of_address_to_resource(node, 0, &res);
153         if (ret)
154                 return ret;
155         start = res.start;
156         size = resource_size(&res);
157         if (!size)
158                 return -ENOMEM;
159
160         logo = kmalloc(sizeof(*logo), GFP_KERNEL);
161         if (!logo)
162                 return -ENOMEM;
163
164         nr_pages = PAGE_ALIGN(size) >> PAGE_SHIFT;
165         pages = kmalloc_array(nr_pages, sizeof(*pages), GFP_KERNEL);
166         if (!pages)
167                 goto err_free_logo;
168         i = 0;
169         while (i < nr_pages) {
170                 pages[i] = phys_to_page(start);
171                 start += PAGE_SIZE;
172                 i++;
173         }
174         sgt = drm_prime_pages_to_sg(pages, nr_pages);
175         if (IS_ERR(sgt)) {
176                 ret = PTR_ERR(sgt);
177                 goto err_free_pages;
178         }
179
180         if (private->domain) {
181                 memset(&logo->mm, 0, sizeof(logo->mm));
182                 ret = drm_mm_insert_node_generic(&private->mm, &logo->mm,
183                                                  size, PAGE_SIZE,
184                                                  0, 0, 0);
185                 if (ret < 0) {
186                         DRM_ERROR("out of I/O virtual memory: %d\n", ret);
187                         goto err_free_pages;
188                 }
189
190                 logo->dma_addr = logo->mm.start;
191
192                 logo->iommu_map_size = iommu_map_sg(private->domain,
193                                                     logo->dma_addr, sgt->sgl,
194                                                     sgt->nents, IOMMU_READ);
195                 if (logo->iommu_map_size < size) {
196                         DRM_ERROR("failed to map buffer");
197                         ret = -ENOMEM;
198                         goto err_remove_node;
199                 }
200         } else {
201                 dma_map_sg(drm_dev->dev, sgt->sgl, sgt->nents, DMA_TO_DEVICE);
202                 logo->dma_addr = sg_dma_address(sgt->sgl);
203         }
204
205         logo->sgt = sgt;
206         logo->start = res.start;
207         logo->size = size;
208         logo->count = 1;
209         private->logo = logo;
210
211         return 0;
212
213 err_remove_node:
214         drm_mm_remove_node(&logo->mm);
215 err_free_pages:
216         kfree(pages);
217 err_free_logo:
218         kfree(logo);
219
220         return ret;
221 }
222
223 static struct drm_framebuffer *
224 get_framebuffer_by_node(struct drm_device *drm_dev, struct device_node *node)
225 {
226         struct rockchip_drm_private *private = drm_dev->dev_private;
227         struct drm_mode_fb_cmd2 mode_cmd = { 0 };
228         u32 val;
229         int bpp;
230
231         if (WARN_ON(!private->logo))
232                 return NULL;
233
234         if (of_property_read_u32(node, "logo,offset", &val)) {
235                 pr_err("%s: failed to get logo,offset\n", __func__);
236                 return NULL;
237         }
238         mode_cmd.offsets[0] = val;
239
240         if (of_property_read_u32(node, "logo,width", &val)) {
241                 pr_err("%s: failed to get logo,width\n", __func__);
242                 return NULL;
243         }
244         mode_cmd.width = val;
245
246         if (of_property_read_u32(node, "logo,height", &val)) {
247                 pr_err("%s: failed to get logo,height\n", __func__);
248                 return NULL;
249         }
250         mode_cmd.height = val;
251
252         if (of_property_read_u32(node, "logo,bpp", &val)) {
253                 pr_err("%s: failed to get logo,bpp\n", __func__);
254                 return NULL;
255         }
256         bpp = val;
257
258         mode_cmd.pitches[0] = mode_cmd.width * bpp / 8;
259
260         switch (bpp) {
261         case 16:
262                 mode_cmd.pixel_format = DRM_FORMAT_BGR565;
263                 break;
264         case 24:
265                 mode_cmd.pixel_format = DRM_FORMAT_BGR888;
266                 break;
267         case 32:
268                 mode_cmd.pixel_format = DRM_FORMAT_XBGR8888;
269                 break;
270         default:
271                 pr_err("%s: unsupport to logo bpp %d\n", __func__, bpp);
272                 return NULL;
273         }
274
275         return rockchip_fb_alloc(drm_dev, &mode_cmd, NULL, private->logo, 1);
276 }
277
278 static struct rockchip_drm_mode_set *
279 of_parse_display_resource(struct drm_device *drm_dev, struct device_node *route)
280 {
281         struct rockchip_drm_mode_set *set;
282         struct device_node *connect;
283         struct drm_framebuffer *fb;
284         struct drm_connector *connector;
285         struct drm_crtc *crtc;
286         const char *string;
287         u32 val;
288
289         connect = of_parse_phandle(route, "connect", 0);
290         if (!connect)
291                 return NULL;
292
293         fb = get_framebuffer_by_node(drm_dev, route);
294         if (IS_ERR_OR_NULL(fb))
295                 return NULL;
296
297         crtc = find_crtc_by_node(drm_dev, connect);
298         connector = find_connector_by_node(drm_dev, connect);
299         if (!crtc || !connector) {
300                 dev_warn(drm_dev->dev,
301                          "No available crtc or connector for display");
302                 drm_framebuffer_unreference(fb);
303                 return NULL;
304         }
305
306         set = kzalloc(sizeof(*set), GFP_KERNEL);
307         if (!set)
308                 return NULL;
309
310         if (!of_property_read_u32(route, "video,hdisplay", &val))
311                 set->hdisplay = val;
312
313         if (!of_property_read_u32(route, "video,vdisplay", &val))
314                 set->vdisplay = val;
315
316         if (!of_property_read_u32(route, "video,vrefresh", &val))
317                 set->vrefresh = val;
318
319         if (!of_property_read_u32(route, "logo,ymirror", &val))
320                 set->ymirror = val;
321
322         set->ratio = 1;
323         if (!of_property_read_string(route, "logo,mode", &string) &&
324             !strcmp(string, "fullscreen"))
325                         set->ratio = 0;
326
327         set->fb = fb;
328         set->crtc = crtc;
329         set->connector = connector;
330
331         return set;
332 }
333
334 int setup_initial_state(struct drm_device *drm_dev,
335                         struct drm_atomic_state *state,
336                         struct rockchip_drm_mode_set *set)
337 {
338         struct drm_connector *connector = set->connector;
339         struct drm_crtc *crtc = set->crtc;
340         struct drm_crtc_state *crtc_state;
341         struct drm_connector_state *conn_state;
342         struct drm_plane_state *primary_state;
343         struct drm_display_mode *mode = NULL;
344         const struct drm_connector_helper_funcs *funcs;
345         bool is_crtc_enabled = true;
346         int hdisplay, vdisplay;
347         int fb_width, fb_height;
348         int found = 0, match = 0;
349         int num_modes;
350         int ret = 0;
351
352         if (!set->hdisplay || !set->vdisplay || !set->vrefresh)
353                 is_crtc_enabled = false;
354
355         conn_state = drm_atomic_get_connector_state(state, connector);
356         if (IS_ERR(conn_state))
357                 return PTR_ERR(conn_state);
358
359         funcs = connector->helper_private;
360         conn_state->best_encoder = funcs->best_encoder(connector);
361         if (funcs->loader_protect)
362                 funcs->loader_protect(connector, true);
363         connector->loader_protect = true;
364         num_modes = connector->funcs->fill_modes(connector, 4096, 4096);
365         if (!num_modes) {
366                 dev_err(drm_dev->dev, "connector[%s] can't found any modes\n",
367                         connector->name);
368                 ret = -EINVAL;
369                 goto error;
370         }
371
372         list_for_each_entry(mode, &connector->modes, head) {
373                 if (mode->hdisplay == set->hdisplay &&
374                     mode->vdisplay == set->vdisplay &&
375                     drm_mode_vrefresh(mode) == set->vrefresh) {
376                         found = 1;
377                         match = 1;
378                         break;
379                 }
380         }
381
382         if (!found) {
383                 list_for_each_entry(mode, &connector->modes, head) {
384                         if (mode->type & DRM_MODE_TYPE_PREFERRED) {
385                                 found = 1;
386                                 break;
387                         }
388                 }
389
390                 if (!found) {
391                         mode = list_first_entry_or_null(&connector->modes,
392                                                         struct drm_display_mode,
393                                                         head);
394                         if (!mode) {
395                                 pr_err("failed to find available modes\n");
396                                 ret = -EINVAL;
397                                 goto error;
398                         }
399                 }
400         }
401
402         set->mode = mode;
403         crtc_state = drm_atomic_get_crtc_state(state, crtc);
404         if (IS_ERR(crtc_state)) {
405                 ret = PTR_ERR(crtc_state);
406                 goto error;
407         }
408
409         drm_mode_copy(&crtc_state->adjusted_mode, mode);
410         if (!match || !is_crtc_enabled) {
411                 set->mode_changed = true;
412         } else {
413                 ret = drm_atomic_set_crtc_for_connector(conn_state, crtc);
414                 if (ret)
415                         goto error;
416
417                 ret = drm_atomic_set_mode_for_crtc(crtc_state, mode);
418                 if (ret)
419                         goto error;
420
421                 crtc_state->active = true;
422         }
423
424         if (!set->fb) {
425                 ret = 0;
426                 goto error;
427         }
428         primary_state = drm_atomic_get_plane_state(state, crtc->primary);
429         if (IS_ERR(primary_state)) {
430                 ret = PTR_ERR(primary_state);
431                 goto error;
432         }
433
434         hdisplay = mode->hdisplay;
435         vdisplay = mode->vdisplay;
436         fb_width = set->fb->width;
437         fb_height = set->fb->height;
438
439         primary_state->crtc = crtc;
440         primary_state->src_x = 0;
441         primary_state->src_y = 0;
442         primary_state->src_w = fb_width << 16;
443         primary_state->src_h = fb_height << 16;
444         if (set->ratio) {
445                 if (set->fb->width >= hdisplay) {
446                         primary_state->crtc_x = 0;
447                         primary_state->crtc_w = hdisplay;
448                 } else {
449                         primary_state->crtc_x = (hdisplay - fb_width) / 2;
450                         primary_state->crtc_w = set->fb->width;
451                 }
452
453                 if (set->fb->height >= vdisplay) {
454                         primary_state->crtc_y = 0;
455                         primary_state->crtc_h = vdisplay;
456                 } else {
457                         primary_state->crtc_y = (vdisplay - fb_height) / 2;
458                         primary_state->crtc_h = fb_height;
459                 }
460         } else {
461                 primary_state->crtc_x = 0;
462                 primary_state->crtc_y = 0;
463                 primary_state->crtc_w = hdisplay;
464                 primary_state->crtc_h = vdisplay;
465         }
466
467         return 0;
468
469 error:
470         if (funcs->loader_protect)
471                 funcs->loader_protect(connector, false);
472         connector->loader_protect = false;
473         return ret;
474 }
475
476 static int update_state(struct drm_device *drm_dev,
477                         struct drm_atomic_state *state,
478                         struct rockchip_drm_mode_set *set,
479                         unsigned int *plane_mask)
480 {
481         struct drm_mode_config *mode_config = &drm_dev->mode_config;
482         struct drm_crtc *crtc = set->crtc;
483         struct drm_connector *connector = set->connector;
484         struct drm_display_mode *mode = set->mode;
485         struct drm_plane_state *primary_state;
486         struct drm_crtc_state *crtc_state;
487         struct drm_connector_state *conn_state;
488         int ret;
489
490         crtc_state = drm_atomic_get_crtc_state(state, crtc);
491         if (IS_ERR(crtc_state))
492                 return PTR_ERR(crtc_state);
493         conn_state = drm_atomic_get_connector_state(state, connector);
494         if (IS_ERR(conn_state))
495                 return PTR_ERR(conn_state);
496
497         if (set->mode_changed) {
498                 ret = drm_atomic_set_crtc_for_connector(conn_state, crtc);
499                 if (ret)
500                         return ret;
501
502                 ret = drm_atomic_set_mode_for_crtc(crtc_state, mode);
503                 if (ret)
504                         return ret;
505
506                 crtc_state->active = true;
507         } else {
508                 const struct drm_encoder_helper_funcs *encoder_helper_funcs;
509                 const struct drm_connector_helper_funcs *connector_helper_funcs;
510                 struct rockchip_drm_private *priv = drm_dev->dev_private;
511                 struct drm_encoder *encoder;
512                 int pipe = drm_crtc_index(crtc);
513
514                 connector_helper_funcs = connector->helper_private;
515                 if (!priv->crtc_funcs[pipe] ||
516                     !priv->crtc_funcs[pipe]->loader_protect ||
517                     !connector_helper_funcs ||
518                     !connector_helper_funcs->best_encoder)
519                         return -ENXIO;
520                 encoder = connector_helper_funcs->best_encoder(connector);
521                 if (!encoder)
522                         return -ENXIO;
523                 encoder_helper_funcs = encoder->helper_private;
524                 if (!encoder_helper_funcs->atomic_check)
525                         return -ENXIO;
526                 ret = encoder_helper_funcs->atomic_check(encoder, crtc->state,
527                                                          conn_state);
528                 if (ret)
529                         return ret;
530                 if (encoder_helper_funcs->mode_set)
531                         encoder_helper_funcs->mode_set(encoder, mode, mode);
532                 priv->crtc_funcs[pipe]->loader_protect(crtc, true);
533         }
534
535         primary_state = drm_atomic_get_plane_state(state, crtc->primary);
536         if (IS_ERR(primary_state))
537                 return PTR_ERR(primary_state);
538
539         crtc_state->plane_mask = 1 << drm_plane_index(crtc->primary);
540         *plane_mask |= crtc_state->plane_mask;
541
542         drm_atomic_set_fb_for_plane(primary_state, set->fb);
543         drm_framebuffer_unreference(set->fb);
544         ret = drm_atomic_set_crtc_for_plane(primary_state, crtc);
545
546         if (set->ymirror)
547                 /*
548                  * TODO:
549                  * some vop maybe not support ymirror, but force use it now.
550                  */
551                 drm_atomic_plane_set_property(crtc->primary, primary_state,
552                                               mode_config->rotation_property,
553                                               BIT(DRM_REFLECT_Y));
554
555         return ret;
556 }
557
558 static void show_loader_logo(struct drm_device *drm_dev)
559 {
560         struct drm_atomic_state *state;
561         struct device_node *np = drm_dev->dev->of_node;
562         struct drm_mode_config *mode_config = &drm_dev->mode_config;
563         struct device_node *root, *route;
564         struct rockchip_drm_mode_set *set, *tmp;
565         struct list_head mode_set_list;
566         unsigned plane_mask = 0;
567         int ret;
568
569         root = of_get_child_by_name(np, "route");
570         if (!root) {
571                 dev_warn(drm_dev->dev, "failed to parse display resources\n");
572                 return;
573         }
574
575         if (init_loader_memory(drm_dev)) {
576                 dev_warn(drm_dev->dev, "failed to parse loader memory\n");
577                 return;
578         }
579
580         INIT_LIST_HEAD(&mode_set_list);
581         drm_modeset_lock_all(drm_dev);
582         state = drm_atomic_state_alloc(drm_dev);
583         if (!state) {
584                 dev_err(drm_dev->dev, "failed to alloc atomic state\n");
585                 ret = -ENOMEM;
586                 goto err_unlock;
587         }
588
589         state->acquire_ctx = mode_config->acquire_ctx;
590
591         for_each_child_of_node(root, route) {
592                 if (!of_device_is_available(route))
593                         continue;
594
595                 set = of_parse_display_resource(drm_dev, route);
596                 if (!set)
597                         continue;
598
599                 if (setup_initial_state(drm_dev, state, set)) {
600                         drm_framebuffer_unreference(set->fb);
601                         kfree(set);
602                         continue;
603                 }
604                 INIT_LIST_HEAD(&set->head);
605                 list_add_tail(&set->head, &mode_set_list);
606         }
607
608         if (list_empty(&mode_set_list)) {
609                 dev_warn(drm_dev->dev, "can't not find any loader display\n");
610                 ret = -ENXIO;
611                 goto err_free_state;
612         }
613
614         /*
615          * The state save initial devices status, swap the state into
616          * drm deivces as old state, so if new state come, can compare
617          * with this state to judge which status need to update.
618          */
619         drm_atomic_helper_swap_state(drm_dev, state);
620         drm_atomic_state_free(state);
621         state = drm_atomic_helper_duplicate_state(drm_dev,
622                                                   mode_config->acquire_ctx);
623         if (IS_ERR(state)) {
624                 dev_err(drm_dev->dev, "failed to duplicate atomic state\n");
625                 ret = PTR_ERR_OR_ZERO(state);
626                 goto err_unlock;
627         }
628         state->acquire_ctx = mode_config->acquire_ctx;
629         list_for_each_entry(set, &mode_set_list, head)
630                 /*
631                  * We don't want to see any fail on update_state.
632                  */
633                 WARN_ON(update_state(drm_dev, state, set, &plane_mask));
634
635         ret = drm_atomic_commit(state);
636         drm_atomic_clean_old_fb(drm_dev, plane_mask, ret);
637
638         list_for_each_entry_safe(set, tmp, &mode_set_list, head) {
639                 struct drm_crtc *crtc = set->crtc;
640
641                 list_del(&set->head);
642                 kfree(set);
643
644                 /* FIXME:
645                  * primary plane state rotation is not BIT(0), but we only want
646                  * it effect on logo display, userspace may not known to clean
647                  * this property, would get unexpect display, so force set
648                  * primary rotation to BIT(0).
649                  */
650                 if (!crtc->primary || !crtc->primary->state)
651                         continue;
652
653                 drm_atomic_plane_set_property(crtc->primary,
654                                               crtc->primary->state,
655                                               mode_config->rotation_property,
656                                               BIT(0));
657         }
658
659         /*
660          * Is possible get deadlock here?
661          */
662         WARN_ON(ret == -EDEADLK);
663
664         if (ret)
665                 goto err_free_state;
666
667         rockchip_free_loader_memory(drm_dev);
668
669         drm_modeset_unlock_all(drm_dev);
670         return;
671
672 err_free_state:
673         drm_atomic_state_free(state);
674 err_unlock:
675         drm_modeset_unlock_all(drm_dev);
676         if (ret)
677                 dev_err(drm_dev->dev, "failed to show loader logo\n");
678 }
679 #endif
680
681 /*
682  * Attach a (component) device to the shared drm dma mapping from master drm
683  * device.  This is used by the VOPs to map GEM buffers to a common DMA
684  * mapping.
685  */
686 int rockchip_drm_dma_attach_device(struct drm_device *drm_dev,
687                                    struct device *dev)
688 {
689         struct rockchip_drm_private *private = drm_dev->dev_private;
690         int ret;
691
692         if (!is_support_iommu)
693                 return 0;
694
695         ret = iommu_attach_device(private->domain, dev);
696         if (ret) {
697                 dev_err(dev, "Failed to attach iommu device\n");
698                 return ret;
699         }
700
701         return 0;
702 }
703
704 void rockchip_drm_dma_detach_device(struct drm_device *drm_dev,
705                                     struct device *dev)
706 {
707         struct rockchip_drm_private *private = drm_dev->dev_private;
708         struct iommu_domain *domain = private->domain;
709
710         if (!is_support_iommu)
711                 return;
712
713         iommu_detach_device(domain, dev);
714 }
715
716 int rockchip_register_crtc_funcs(struct drm_crtc *crtc,
717                                  const struct rockchip_crtc_funcs *crtc_funcs)
718 {
719         int pipe = drm_crtc_index(crtc);
720         struct rockchip_drm_private *priv = crtc->dev->dev_private;
721
722         if (pipe >= ROCKCHIP_MAX_CRTC)
723                 return -EINVAL;
724
725         priv->crtc_funcs[pipe] = crtc_funcs;
726
727         return 0;
728 }
729
730 void rockchip_unregister_crtc_funcs(struct drm_crtc *crtc)
731 {
732         int pipe = drm_crtc_index(crtc);
733         struct rockchip_drm_private *priv = crtc->dev->dev_private;
734
735         if (pipe >= ROCKCHIP_MAX_CRTC)
736                 return;
737
738         priv->crtc_funcs[pipe] = NULL;
739 }
740
741 static struct drm_crtc *rockchip_crtc_from_pipe(struct drm_device *drm,
742                                                 int pipe)
743 {
744         struct drm_crtc *crtc;
745         int i = 0;
746
747         list_for_each_entry(crtc, &drm->mode_config.crtc_list, head)
748                 if (i++ == pipe)
749                         return crtc;
750
751         return NULL;
752 }
753
754 static int rockchip_drm_crtc_enable_vblank(struct drm_device *dev,
755                                            unsigned int pipe)
756 {
757         struct rockchip_drm_private *priv = dev->dev_private;
758         struct drm_crtc *crtc = rockchip_crtc_from_pipe(dev, pipe);
759
760         if (crtc && priv->crtc_funcs[pipe] &&
761             priv->crtc_funcs[pipe]->enable_vblank)
762                 return priv->crtc_funcs[pipe]->enable_vblank(crtc);
763
764         return 0;
765 }
766
767 static void rockchip_drm_crtc_disable_vblank(struct drm_device *dev,
768                                              unsigned int pipe)
769 {
770         struct rockchip_drm_private *priv = dev->dev_private;
771         struct drm_crtc *crtc = rockchip_crtc_from_pipe(dev, pipe);
772
773         if (crtc && priv->crtc_funcs[pipe] &&
774             priv->crtc_funcs[pipe]->enable_vblank)
775                 priv->crtc_funcs[pipe]->disable_vblank(crtc);
776 }
777
778 static int rockchip_drm_init_iommu(struct drm_device *drm_dev)
779 {
780         struct rockchip_drm_private *private = drm_dev->dev_private;
781         struct iommu_domain_geometry *geometry;
782         u64 start, end;
783
784         if (!is_support_iommu)
785                 return 0;
786
787         private->domain = iommu_domain_alloc(&platform_bus_type);
788         if (!private->domain)
789                 return -ENOMEM;
790
791         geometry = &private->domain->geometry;
792         start = geometry->aperture_start;
793         end = geometry->aperture_end;
794
795         DRM_DEBUG("IOMMU context initialized (aperture: %#llx-%#llx)\n",
796                   start, end);
797         drm_mm_init(&private->mm, start, end - start + 1);
798         mutex_init(&private->mm_lock);
799
800         return 0;
801 }
802
803 static void rockchip_iommu_cleanup(struct drm_device *drm_dev)
804 {
805         struct rockchip_drm_private *private = drm_dev->dev_private;
806
807         if (!is_support_iommu)
808                 return;
809
810         drm_mm_takedown(&private->mm);
811         iommu_domain_free(private->domain);
812 }
813
814 #ifdef CONFIG_DEBUG_FS
815 static int rockchip_drm_mm_dump(struct seq_file *s, void *data)
816 {
817         struct drm_info_node *node = s->private;
818         struct drm_minor *minor = node->minor;
819         struct drm_device *drm_dev = minor->dev;
820         struct rockchip_drm_private *priv = drm_dev->dev_private;
821         int ret;
822
823         mutex_lock(&priv->mm_lock);
824
825         ret = drm_mm_dump_table(s, &priv->mm);
826
827         mutex_unlock(&priv->mm_lock);
828
829         return ret;
830 }
831
832 static int rockchip_drm_summary_show(struct seq_file *s, void *data)
833 {
834         struct drm_info_node *node = s->private;
835         struct drm_minor *minor = node->minor;
836         struct drm_device *drm_dev = minor->dev;
837         struct rockchip_drm_private *priv = drm_dev->dev_private;
838         struct drm_crtc *crtc;
839
840         drm_for_each_crtc(crtc, drm_dev) {
841                 int pipe = drm_crtc_index(crtc);
842
843                 if (priv->crtc_funcs[pipe] &&
844                     priv->crtc_funcs[pipe]->debugfs_dump)
845                         priv->crtc_funcs[pipe]->debugfs_dump(crtc, s);
846         }
847
848         return 0;
849 }
850
851 static struct drm_info_list rockchip_debugfs_files[] = {
852         { "summary", rockchip_drm_summary_show, 0, NULL },
853         { "mm_dump", rockchip_drm_mm_dump, 0, NULL },
854 };
855
856 static int rockchip_drm_debugfs_init(struct drm_minor *minor)
857 {
858         struct drm_device *dev = minor->dev;
859         int ret;
860
861         ret = drm_debugfs_create_files(rockchip_debugfs_files,
862                                        ARRAY_SIZE(rockchip_debugfs_files),
863                                        minor->debugfs_root,
864                                        minor);
865         if (ret) {
866                 dev_err(dev->dev, "could not install rockchip_debugfs_list\n");
867                 return ret;
868         }
869
870         return 0;
871 }
872
873 static void rockchip_drm_debugfs_cleanup(struct drm_minor *minor)
874 {
875         drm_debugfs_remove_files(rockchip_debugfs_files,
876                                  ARRAY_SIZE(rockchip_debugfs_files), minor);
877 }
878 #endif
879
880 static int rockchip_drm_bind(struct device *dev)
881 {
882         struct drm_device *drm_dev;
883         struct rockchip_drm_private *private;
884         int ret;
885
886         drm_dev = drm_dev_alloc(&rockchip_drm_driver, dev);
887         if (!drm_dev)
888                 return -ENOMEM;
889
890         ret = drm_dev_set_unique(drm_dev, "%s", dev_name(dev));
891         if (ret)
892                 goto err_free;
893
894         dev_set_drvdata(dev, drm_dev);
895
896         private = devm_kzalloc(drm_dev->dev, sizeof(*private), GFP_KERNEL);
897         if (!private) {
898                 ret = -ENOMEM;
899                 goto err_free;
900         }
901
902         mutex_init(&private->commit.lock);
903         INIT_WORK(&private->commit.work, rockchip_drm_atomic_work);
904
905         drm_dev->dev_private = private;
906
907 #ifdef CONFIG_DRM_DMA_SYNC
908         private->cpu_fence_context = fence_context_alloc(1);
909         atomic_set(&private->cpu_fence_seqno, 0);
910 #endif
911
912         drm_mode_config_init(drm_dev);
913
914         rockchip_drm_mode_config_init(drm_dev);
915
916         ret = rockchip_drm_init_iommu(drm_dev);
917         if (ret)
918                 goto err_config_cleanup;
919
920         /* Try to bind all sub drivers. */
921         ret = component_bind_all(dev, drm_dev);
922         if (ret)
923                 goto err_iommu_cleanup;
924
925         /* init kms poll for handling hpd */
926         drm_kms_helper_poll_init(drm_dev);
927
928         /*
929          * enable drm irq mode.
930          * - with irq_enabled = true, we can use the vblank feature.
931          */
932         drm_dev->irq_enabled = true;
933
934         ret = drm_vblank_init(drm_dev, ROCKCHIP_MAX_CRTC);
935         if (ret)
936                 goto err_kms_helper_poll_fini;
937
938         /*
939          * with vblank_disable_allowed = true, vblank interrupt will be disabled
940          * by drm timer once a current process gives up ownership of
941          * vblank event.(after drm_vblank_put function is called)
942          */
943         drm_dev->vblank_disable_allowed = true;
944
945         drm_mode_config_reset(drm_dev);
946
947 #ifndef MODULE
948         show_loader_logo(drm_dev);
949 #endif
950
951         ret = rockchip_drm_fbdev_init(drm_dev);
952         if (ret)
953                 goto err_vblank_cleanup;
954
955         drm_dev->mode_config.allow_fb_modifiers = true;
956
957         ret = drm_dev_register(drm_dev, 0);
958         if (ret)
959                 goto err_fbdev_fini;
960
961         return 0;
962 err_fbdev_fini:
963         rockchip_drm_fbdev_fini(drm_dev);
964 err_vblank_cleanup:
965         drm_vblank_cleanup(drm_dev);
966 err_kms_helper_poll_fini:
967         drm_kms_helper_poll_fini(drm_dev);
968         component_unbind_all(dev, drm_dev);
969 err_iommu_cleanup:
970         rockchip_iommu_cleanup(drm_dev);
971 err_config_cleanup:
972         drm_mode_config_cleanup(drm_dev);
973         drm_dev->dev_private = NULL;
974 err_free:
975         drm_dev_unref(drm_dev);
976         return ret;
977 }
978
979 static void rockchip_drm_unbind(struct device *dev)
980 {
981         struct drm_device *drm_dev = dev_get_drvdata(dev);
982
983         rockchip_drm_fbdev_fini(drm_dev);
984         drm_vblank_cleanup(drm_dev);
985         drm_kms_helper_poll_fini(drm_dev);
986         component_unbind_all(dev, drm_dev);
987         rockchip_iommu_cleanup(drm_dev);
988         drm_mode_config_cleanup(drm_dev);
989         drm_dev->dev_private = NULL;
990         drm_dev_unregister(drm_dev);
991         drm_dev_unref(drm_dev);
992         dev_set_drvdata(dev, NULL);
993 }
994
995 static void rockchip_drm_crtc_cancel_pending_vblank(struct drm_crtc *crtc,
996                                                     struct drm_file *file_priv)
997 {
998         struct rockchip_drm_private *priv = crtc->dev->dev_private;
999         int pipe = drm_crtc_index(crtc);
1000
1001         if (pipe < ROCKCHIP_MAX_CRTC &&
1002             priv->crtc_funcs[pipe] &&
1003             priv->crtc_funcs[pipe]->cancel_pending_vblank)
1004                 priv->crtc_funcs[pipe]->cancel_pending_vblank(crtc, file_priv);
1005 }
1006
1007 int rockchip_drm_register_subdrv(struct drm_rockchip_subdrv *subdrv)
1008 {
1009         if (!subdrv)
1010                 return -EINVAL;
1011
1012         mutex_lock(&subdrv_list_mutex);
1013         list_add_tail(&subdrv->list, &rockchip_drm_subdrv_list);
1014         mutex_unlock(&subdrv_list_mutex);
1015
1016         return 0;
1017 }
1018 EXPORT_SYMBOL_GPL(rockchip_drm_register_subdrv);
1019
1020 int rockchip_drm_unregister_subdrv(struct drm_rockchip_subdrv *subdrv)
1021 {
1022         if (!subdrv)
1023                 return -EINVAL;
1024
1025         mutex_lock(&subdrv_list_mutex);
1026         list_del(&subdrv->list);
1027         mutex_unlock(&subdrv_list_mutex);
1028
1029         return 0;
1030 }
1031 EXPORT_SYMBOL_GPL(rockchip_drm_unregister_subdrv);
1032
1033 static int rockchip_drm_open(struct drm_device *dev, struct drm_file *file)
1034 {
1035         struct rockchip_drm_file_private *file_priv;
1036         struct drm_rockchip_subdrv *subdrv;
1037         int ret = 0;
1038
1039         file_priv = kzalloc(sizeof(*file_priv), GFP_KERNEL);
1040         if (!file_priv)
1041                 return -ENOMEM;
1042         INIT_LIST_HEAD(&file_priv->gem_cpu_acquire_list);
1043
1044         file->driver_priv = file_priv;
1045
1046         mutex_lock(&subdrv_list_mutex);
1047         list_for_each_entry(subdrv, &rockchip_drm_subdrv_list, list) {
1048                 ret = subdrv->open(dev, subdrv->dev, file);
1049                 if (ret) {
1050                         mutex_unlock(&subdrv_list_mutex);
1051                         goto err_free_file_priv;
1052                 }
1053         }
1054         mutex_unlock(&subdrv_list_mutex);
1055
1056         return 0;
1057
1058 err_free_file_priv:
1059         kfree(file_priv);
1060         file_priv = NULL;
1061
1062         return ret;
1063 }
1064
1065 static void rockchip_drm_preclose(struct drm_device *dev,
1066                                   struct drm_file *file_priv)
1067 {
1068         struct rockchip_drm_file_private *file_private = file_priv->driver_priv;
1069         struct rockchip_gem_object_node *cur, *d;
1070         struct drm_rockchip_subdrv *subdrv;
1071         struct drm_crtc *crtc;
1072
1073         list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
1074                 rockchip_drm_crtc_cancel_pending_vblank(crtc, file_priv);
1075
1076         mutex_lock(&dev->struct_mutex);
1077         list_for_each_entry_safe(cur, d,
1078                         &file_private->gem_cpu_acquire_list, list) {
1079 #ifdef CONFIG_DRM_DMA_SYNC
1080                 BUG_ON(!cur->rockchip_gem_obj->acquire_fence);
1081                 drm_fence_signal_and_put(&cur->rockchip_gem_obj->acquire_fence);
1082 #endif
1083                 drm_gem_object_unreference(&cur->rockchip_gem_obj->base);
1084                 kfree(cur);
1085         }
1086         /* since we are deleting the whole list, just initialize the header
1087          * instead of calling list_del for every element
1088          */
1089         INIT_LIST_HEAD(&file_private->gem_cpu_acquire_list);
1090         mutex_unlock(&dev->struct_mutex);
1091
1092         mutex_lock(&subdrv_list_mutex);
1093         list_for_each_entry(subdrv, &rockchip_drm_subdrv_list, list)
1094                 subdrv->close(dev, subdrv->dev, file_priv);
1095         mutex_unlock(&subdrv_list_mutex);
1096 }
1097
1098 static void rockchip_drm_postclose(struct drm_device *dev, struct drm_file *file)
1099 {
1100         kfree(file->driver_priv);
1101         file->driver_priv = NULL;
1102 }
1103
1104 void rockchip_drm_lastclose(struct drm_device *dev)
1105 {
1106         struct rockchip_drm_private *priv = dev->dev_private;
1107
1108         if (!priv->logo)
1109                 drm_fb_helper_restore_fbdev_mode_unlocked(priv->fbdev_helper);
1110 }
1111
1112 static const struct drm_ioctl_desc rockchip_ioctls[] = {
1113         DRM_IOCTL_DEF_DRV(ROCKCHIP_GEM_CREATE, rockchip_gem_create_ioctl,
1114                           DRM_UNLOCKED | DRM_AUTH | DRM_RENDER_ALLOW),
1115         DRM_IOCTL_DEF_DRV(ROCKCHIP_GEM_MAP_OFFSET,
1116                           rockchip_gem_map_offset_ioctl,
1117                           DRM_UNLOCKED | DRM_AUTH | DRM_RENDER_ALLOW),
1118         DRM_IOCTL_DEF_DRV(ROCKCHIP_GEM_CPU_ACQUIRE,
1119                           rockchip_gem_cpu_acquire_ioctl,
1120                           DRM_UNLOCKED | DRM_AUTH | DRM_RENDER_ALLOW),
1121         DRM_IOCTL_DEF_DRV(ROCKCHIP_GEM_CPU_RELEASE,
1122                           rockchip_gem_cpu_release_ioctl,
1123                           DRM_UNLOCKED | DRM_AUTH | DRM_RENDER_ALLOW),
1124         DRM_IOCTL_DEF_DRV(ROCKCHIP_RGA_GET_VER, rockchip_rga_get_ver_ioctl,
1125                           DRM_AUTH | DRM_RENDER_ALLOW),
1126         DRM_IOCTL_DEF_DRV(ROCKCHIP_RGA_SET_CMDLIST,
1127                           rockchip_rga_set_cmdlist_ioctl,
1128                           DRM_AUTH | DRM_RENDER_ALLOW),
1129         DRM_IOCTL_DEF_DRV(ROCKCHIP_RGA_EXEC, rockchip_rga_exec_ioctl,
1130                           DRM_AUTH | DRM_RENDER_ALLOW),
1131 };
1132
1133 static const struct file_operations rockchip_drm_driver_fops = {
1134         .owner = THIS_MODULE,
1135         .open = drm_open,
1136         .mmap = rockchip_gem_mmap,
1137         .poll = drm_poll,
1138         .read = drm_read,
1139         .unlocked_ioctl = drm_ioctl,
1140 #ifdef CONFIG_COMPAT
1141         .compat_ioctl = drm_compat_ioctl,
1142 #endif
1143         .release = drm_release,
1144 };
1145
1146 const struct vm_operations_struct rockchip_drm_vm_ops = {
1147         .open = drm_gem_vm_open,
1148         .close = drm_gem_vm_close,
1149 };
1150
1151 static struct drm_driver rockchip_drm_driver = {
1152         .driver_features        = DRIVER_MODESET | DRIVER_GEM |
1153                                   DRIVER_PRIME | DRIVER_ATOMIC |
1154                                   DRIVER_RENDER,
1155         .preclose               = rockchip_drm_preclose,
1156         .lastclose              = rockchip_drm_lastclose,
1157         .get_vblank_counter     = drm_vblank_no_hw_counter,
1158         .open                   = rockchip_drm_open,
1159         .postclose              = rockchip_drm_postclose,
1160         .enable_vblank          = rockchip_drm_crtc_enable_vblank,
1161         .disable_vblank         = rockchip_drm_crtc_disable_vblank,
1162         .gem_vm_ops             = &rockchip_drm_vm_ops,
1163         .gem_free_object        = rockchip_gem_free_object,
1164         .dumb_create            = rockchip_gem_dumb_create,
1165         .dumb_map_offset        = rockchip_gem_dumb_map_offset,
1166         .dumb_destroy           = drm_gem_dumb_destroy,
1167         .prime_handle_to_fd     = drm_gem_prime_handle_to_fd,
1168         .prime_fd_to_handle     = drm_gem_prime_fd_to_handle,
1169         .gem_prime_import       = drm_gem_prime_import,
1170         .gem_prime_export       = drm_gem_prime_export,
1171         .gem_prime_get_sg_table = rockchip_gem_prime_get_sg_table,
1172         .gem_prime_import_sg_table      = rockchip_gem_prime_import_sg_table,
1173         .gem_prime_vmap         = rockchip_gem_prime_vmap,
1174         .gem_prime_vunmap       = rockchip_gem_prime_vunmap,
1175         .gem_prime_mmap         = rockchip_gem_mmap_buf,
1176 #ifdef CONFIG_DEBUG_FS
1177         .debugfs_init           = rockchip_drm_debugfs_init,
1178         .debugfs_cleanup        = rockchip_drm_debugfs_cleanup,
1179 #endif
1180         .ioctls                 = rockchip_ioctls,
1181         .num_ioctls             = ARRAY_SIZE(rockchip_ioctls),
1182         .fops                   = &rockchip_drm_driver_fops,
1183         .name   = DRIVER_NAME,
1184         .desc   = DRIVER_DESC,
1185         .date   = DRIVER_DATE,
1186         .major  = DRIVER_MAJOR,
1187         .minor  = DRIVER_MINOR,
1188 };
1189
1190 #ifdef CONFIG_PM_SLEEP
1191 void rockchip_drm_fb_suspend(struct drm_device *drm)
1192 {
1193         struct rockchip_drm_private *priv = drm->dev_private;
1194
1195         console_lock();
1196         drm_fb_helper_set_suspend(priv->fbdev_helper, 1);
1197         console_unlock();
1198 }
1199
1200 void rockchip_drm_fb_resume(struct drm_device *drm)
1201 {
1202         struct rockchip_drm_private *priv = drm->dev_private;
1203
1204         console_lock();
1205         drm_fb_helper_set_suspend(priv->fbdev_helper, 0);
1206         console_unlock();
1207 }
1208
1209 static int rockchip_drm_sys_suspend(struct device *dev)
1210 {
1211         struct drm_device *drm = dev_get_drvdata(dev);
1212         struct rockchip_drm_private *priv = drm->dev_private;
1213
1214         drm_kms_helper_poll_disable(drm);
1215         rockchip_drm_fb_suspend(drm);
1216
1217         priv->state = drm_atomic_helper_suspend(drm);
1218         if (IS_ERR(priv->state)) {
1219                 rockchip_drm_fb_resume(drm);
1220                 drm_kms_helper_poll_enable(drm);
1221                 return PTR_ERR(priv->state);
1222         }
1223
1224         return 0;
1225 }
1226
1227 static int rockchip_drm_sys_resume(struct device *dev)
1228 {
1229         struct drm_device *drm = dev_get_drvdata(dev);
1230         struct rockchip_drm_private *priv = drm->dev_private;
1231
1232         drm_atomic_helper_resume(drm, priv->state);
1233         rockchip_drm_fb_resume(drm);
1234         drm_kms_helper_poll_enable(drm);
1235
1236         return 0;
1237 }
1238 #endif
1239
1240 static const struct dev_pm_ops rockchip_drm_pm_ops = {
1241         SET_SYSTEM_SLEEP_PM_OPS(rockchip_drm_sys_suspend,
1242                                 rockchip_drm_sys_resume)
1243 };
1244
1245 static int compare_of(struct device *dev, void *data)
1246 {
1247         struct device_node *np = data;
1248
1249         return dev->of_node == np;
1250 }
1251
1252 static void rockchip_add_endpoints(struct device *dev,
1253                                    struct component_match **match,
1254                                    struct device_node *port)
1255 {
1256         struct device_node *ep, *remote;
1257
1258         for_each_child_of_node(port, ep) {
1259                 remote = of_graph_get_remote_port_parent(ep);
1260                 if (!remote || !of_device_is_available(remote)) {
1261                         of_node_put(remote);
1262                         continue;
1263                 } else if (!of_device_is_available(remote->parent)) {
1264                         dev_warn(dev, "parent device of %s is not available\n",
1265                                  remote->full_name);
1266                         of_node_put(remote);
1267                         continue;
1268                 }
1269
1270                 component_match_add(dev, match, compare_of, remote);
1271                 of_node_put(remote);
1272         }
1273 }
1274
1275 static const struct component_master_ops rockchip_drm_ops = {
1276         .bind = rockchip_drm_bind,
1277         .unbind = rockchip_drm_unbind,
1278 };
1279
1280 static int rockchip_drm_platform_probe(struct platform_device *pdev)
1281 {
1282         struct device *dev = &pdev->dev;
1283         struct component_match *match = NULL;
1284         struct device_node *np = dev->of_node;
1285         struct device_node *port;
1286         int i;
1287
1288         if (!np)
1289                 return -ENODEV;
1290         /*
1291          * Bind the crtc ports first, so that
1292          * drm_of_find_possible_crtcs called from encoder .bind callbacks
1293          * works as expected.
1294          */
1295         for (i = 0;; i++) {
1296                 struct device_node *iommu;
1297
1298                 port = of_parse_phandle(np, "ports", i);
1299                 if (!port)
1300                         break;
1301
1302                 if (!of_device_is_available(port->parent)) {
1303                         of_node_put(port);
1304                         continue;
1305                 }
1306
1307                 iommu = of_parse_phandle(port->parent, "iommus", 0);
1308                 if (!iommu || !of_device_is_available(iommu->parent)) {
1309                         dev_dbg(dev, "no iommu attached for %s, using non-iommu buffers\n",
1310                                 port->parent->full_name);
1311                         /*
1312                          * if there is a crtc not support iommu, force set all
1313                          * crtc use non-iommu buffer.
1314                          */
1315                         is_support_iommu = false;
1316                 }
1317
1318                 component_match_add(dev, &match, compare_of, port->parent);
1319                 of_node_put(port);
1320         }
1321
1322         if (i == 0) {
1323                 dev_err(dev, "missing 'ports' property\n");
1324                 return -ENODEV;
1325         }
1326
1327         if (!match) {
1328                 dev_err(dev, "No available vop found for display-subsystem.\n");
1329                 return -ENODEV;
1330         }
1331         /*
1332          * For each bound crtc, bind the encoders attached to its
1333          * remote endpoint.
1334          */
1335         for (i = 0;; i++) {
1336                 port = of_parse_phandle(np, "ports", i);
1337                 if (!port)
1338                         break;
1339
1340                 if (!of_device_is_available(port->parent)) {
1341                         of_node_put(port);
1342                         continue;
1343                 }
1344
1345                 rockchip_add_endpoints(dev, &match, port);
1346                 of_node_put(port);
1347         }
1348
1349         return component_master_add_with_match(dev, &rockchip_drm_ops, match);
1350 }
1351
1352 static int rockchip_drm_platform_remove(struct platform_device *pdev)
1353 {
1354         component_master_del(&pdev->dev, &rockchip_drm_ops);
1355
1356         return 0;
1357 }
1358
1359 static const struct of_device_id rockchip_drm_dt_ids[] = {
1360         { .compatible = "rockchip,display-subsystem", },
1361         { /* sentinel */ },
1362 };
1363 MODULE_DEVICE_TABLE(of, rockchip_drm_dt_ids);
1364
1365 static struct platform_driver rockchip_drm_platform_driver = {
1366         .probe = rockchip_drm_platform_probe,
1367         .remove = rockchip_drm_platform_remove,
1368         .driver = {
1369                 .name = "rockchip-drm",
1370                 .of_match_table = rockchip_drm_dt_ids,
1371                 .pm = &rockchip_drm_pm_ops,
1372         },
1373 };
1374
1375 module_platform_driver(rockchip_drm_platform_driver);
1376
1377 MODULE_AUTHOR("Mark Yao <mark.yao@rock-chips.com>");
1378 MODULE_DESCRIPTION("ROCKCHIP DRM Driver");
1379 MODULE_LICENSE("GPL v2");