• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (c) 2015 MediaTek Inc.
4  * Author: YT SHEN <yt.shen@mediatek.com>
5  */
6 
7 #include <linux/component.h>
8 #include <linux/iommu.h>
9 #include <linux/module.h>
10 #include <linux/of_address.h>
11 #include <linux/of_platform.h>
12 #include <linux/pm_runtime.h>
13 #include <linux/soc/mediatek/mtk-mmsys.h>
14 #include <linux/dma-mapping.h>
15 
16 #include <drm/drm_atomic.h>
17 #include <drm/drm_atomic_helper.h>
18 #include <drm/drm_drv.h>
19 #include <drm/drm_fb_helper.h>
20 #include <drm/drm_fourcc.h>
21 #include <drm/drm_gem.h>
22 #include <drm/drm_gem_cma_helper.h>
23 #include <drm/drm_gem_framebuffer_helper.h>
24 #include <drm/drm_of.h>
25 #include <drm/drm_probe_helper.h>
26 #include <drm/drm_vblank.h>
27 
28 #include "mtk_drm_crtc.h"
29 #include "mtk_drm_ddp.h"
30 #include "mtk_drm_ddp_comp.h"
31 #include "mtk_drm_drv.h"
32 #include "mtk_drm_gem.h"
33 
34 #define DRIVER_NAME "mediatek"
35 #define DRIVER_DESC "Mediatek SoC DRM"
36 #define DRIVER_DATE "20150513"
37 #define DRIVER_MAJOR 1
38 #define DRIVER_MINOR 0
39 
40 static const struct drm_mode_config_helper_funcs mtk_drm_mode_config_helpers = {
41 	.atomic_commit_tail = drm_atomic_helper_commit_tail_rpm,
42 };
43 
44 static struct drm_framebuffer *
mtk_drm_mode_fb_create(struct drm_device * dev,struct drm_file * file,const struct drm_mode_fb_cmd2 * cmd)45 mtk_drm_mode_fb_create(struct drm_device *dev,
46 		       struct drm_file *file,
47 		       const struct drm_mode_fb_cmd2 *cmd)
48 {
49 	const struct drm_format_info *info = drm_get_format_info(dev, cmd);
50 
51 	if (info->num_planes != 1)
52 		return ERR_PTR(-EINVAL);
53 
54 	return drm_gem_fb_create(dev, file, cmd);
55 }
56 
57 static const struct drm_mode_config_funcs mtk_drm_mode_config_funcs = {
58 	.fb_create = mtk_drm_mode_fb_create,
59 	.atomic_check = drm_atomic_helper_check,
60 	.atomic_commit = drm_atomic_helper_commit,
61 };
62 
63 static const enum mtk_ddp_comp_id mt2701_mtk_ddp_main[] = {
64 	DDP_COMPONENT_OVL0,
65 	DDP_COMPONENT_RDMA0,
66 	DDP_COMPONENT_COLOR0,
67 	DDP_COMPONENT_BLS,
68 	DDP_COMPONENT_DSI0,
69 };
70 
71 static const enum mtk_ddp_comp_id mt2701_mtk_ddp_ext[] = {
72 	DDP_COMPONENT_RDMA1,
73 	DDP_COMPONENT_DPI0,
74 };
75 
76 static const enum mtk_ddp_comp_id mt7623_mtk_ddp_main[] = {
77 	DDP_COMPONENT_OVL0,
78 	DDP_COMPONENT_RDMA0,
79 	DDP_COMPONENT_COLOR0,
80 	DDP_COMPONENT_BLS,
81 	DDP_COMPONENT_DPI0,
82 };
83 
84 static const enum mtk_ddp_comp_id mt7623_mtk_ddp_ext[] = {
85 	DDP_COMPONENT_RDMA1,
86 	DDP_COMPONENT_DSI0,
87 };
88 
89 static const enum mtk_ddp_comp_id mt2712_mtk_ddp_main[] = {
90 	DDP_COMPONENT_OVL0,
91 	DDP_COMPONENT_COLOR0,
92 	DDP_COMPONENT_AAL0,
93 	DDP_COMPONENT_OD0,
94 	DDP_COMPONENT_RDMA0,
95 	DDP_COMPONENT_DPI0,
96 	DDP_COMPONENT_PWM0,
97 };
98 
99 static const enum mtk_ddp_comp_id mt2712_mtk_ddp_ext[] = {
100 	DDP_COMPONENT_OVL1,
101 	DDP_COMPONENT_COLOR1,
102 	DDP_COMPONENT_AAL1,
103 	DDP_COMPONENT_OD1,
104 	DDP_COMPONENT_RDMA1,
105 	DDP_COMPONENT_DPI1,
106 	DDP_COMPONENT_PWM1,
107 };
108 
109 static const enum mtk_ddp_comp_id mt2712_mtk_ddp_third[] = {
110 	DDP_COMPONENT_RDMA2,
111 	DDP_COMPONENT_DSI3,
112 	DDP_COMPONENT_PWM2,
113 };
114 
115 static const enum mtk_ddp_comp_id mt8173_mtk_ddp_main[] = {
116 	DDP_COMPONENT_OVL0,
117 	DDP_COMPONENT_COLOR0,
118 	DDP_COMPONENT_AAL0,
119 	DDP_COMPONENT_OD0,
120 	DDP_COMPONENT_RDMA0,
121 	DDP_COMPONENT_UFOE,
122 	DDP_COMPONENT_DSI0,
123 	DDP_COMPONENT_PWM0,
124 };
125 
126 static const enum mtk_ddp_comp_id mt8173_mtk_ddp_ext[] = {
127 	DDP_COMPONENT_OVL1,
128 	DDP_COMPONENT_COLOR1,
129 	DDP_COMPONENT_GAMMA,
130 	DDP_COMPONENT_RDMA1,
131 	DDP_COMPONENT_DPI0,
132 };
133 
134 static const struct mtk_mmsys_driver_data mt2701_mmsys_driver_data = {
135 	.main_path = mt2701_mtk_ddp_main,
136 	.main_len = ARRAY_SIZE(mt2701_mtk_ddp_main),
137 	.ext_path = mt2701_mtk_ddp_ext,
138 	.ext_len = ARRAY_SIZE(mt2701_mtk_ddp_ext),
139 	.shadow_register = true,
140 };
141 
142 static const struct mtk_mmsys_driver_data mt7623_mmsys_driver_data = {
143 	.main_path = mt7623_mtk_ddp_main,
144 	.main_len = ARRAY_SIZE(mt7623_mtk_ddp_main),
145 	.ext_path = mt7623_mtk_ddp_ext,
146 	.ext_len = ARRAY_SIZE(mt7623_mtk_ddp_ext),
147 	.shadow_register = true,
148 };
149 
150 static const struct mtk_mmsys_driver_data mt2712_mmsys_driver_data = {
151 	.main_path = mt2712_mtk_ddp_main,
152 	.main_len = ARRAY_SIZE(mt2712_mtk_ddp_main),
153 	.ext_path = mt2712_mtk_ddp_ext,
154 	.ext_len = ARRAY_SIZE(mt2712_mtk_ddp_ext),
155 	.third_path = mt2712_mtk_ddp_third,
156 	.third_len = ARRAY_SIZE(mt2712_mtk_ddp_third),
157 };
158 
159 static const struct mtk_mmsys_driver_data mt8173_mmsys_driver_data = {
160 	.main_path = mt8173_mtk_ddp_main,
161 	.main_len = ARRAY_SIZE(mt8173_mtk_ddp_main),
162 	.ext_path = mt8173_mtk_ddp_ext,
163 	.ext_len = ARRAY_SIZE(mt8173_mtk_ddp_ext),
164 };
165 
mtk_drm_kms_init(struct drm_device * drm)166 static int mtk_drm_kms_init(struct drm_device *drm)
167 {
168 	struct mtk_drm_private *private = drm->dev_private;
169 	struct platform_device *pdev;
170 	struct device_node *np;
171 	struct device *dma_dev;
172 	int ret;
173 
174 	if (!iommu_present(&platform_bus_type))
175 		return -EPROBE_DEFER;
176 
177 	pdev = of_find_device_by_node(private->mutex_node);
178 	if (!pdev) {
179 		dev_err(drm->dev, "Waiting for disp-mutex device %pOF\n",
180 			private->mutex_node);
181 		of_node_put(private->mutex_node);
182 		return -EPROBE_DEFER;
183 	}
184 	private->mutex_dev = &pdev->dev;
185 
186 	ret = drmm_mode_config_init(drm);
187 	if (ret)
188 		goto put_mutex_dev;
189 
190 	drm->mode_config.min_width = 64;
191 	drm->mode_config.min_height = 64;
192 
193 	/*
194 	 * set max width and height as default value(4096x4096).
195 	 * this value would be used to check framebuffer size limitation
196 	 * at drm_mode_addfb().
197 	 */
198 	drm->mode_config.max_width = 4096;
199 	drm->mode_config.max_height = 4096;
200 	drm->mode_config.funcs = &mtk_drm_mode_config_funcs;
201 	drm->mode_config.helper_private = &mtk_drm_mode_config_helpers;
202 
203 	ret = component_bind_all(drm->dev, drm);
204 	if (ret)
205 		goto put_mutex_dev;
206 
207 	/*
208 	 * We currently support two fixed data streams, each optional,
209 	 * and each statically assigned to a crtc:
210 	 * OVL0 -> COLOR0 -> AAL -> OD -> RDMA0 -> UFOE -> DSI0 ...
211 	 */
212 	ret = mtk_drm_crtc_create(drm, private->data->main_path,
213 				  private->data->main_len);
214 	if (ret < 0)
215 		goto err_component_unbind;
216 	/* ... and OVL1 -> COLOR1 -> GAMMA -> RDMA1 -> DPI0. */
217 	ret = mtk_drm_crtc_create(drm, private->data->ext_path,
218 				  private->data->ext_len);
219 	if (ret < 0)
220 		goto err_component_unbind;
221 
222 	ret = mtk_drm_crtc_create(drm, private->data->third_path,
223 				  private->data->third_len);
224 	if (ret < 0)
225 		goto err_component_unbind;
226 
227 	/* Use OVL device for all DMA memory allocations */
228 	np = private->comp_node[private->data->main_path[0]] ?:
229 	     private->comp_node[private->data->ext_path[0]];
230 	pdev = of_find_device_by_node(np);
231 	if (!pdev) {
232 		ret = -ENODEV;
233 		dev_err(drm->dev, "Need at least one OVL device\n");
234 		goto err_component_unbind;
235 	}
236 
237 	dma_dev = &pdev->dev;
238 	private->dma_dev = dma_dev;
239 
240 	/*
241 	 * Configure the DMA segment size to make sure we get contiguous IOVA
242 	 * when importing PRIME buffers.
243 	 */
244 	if (!dma_dev->dma_parms) {
245 		private->dma_parms_allocated = true;
246 		dma_dev->dma_parms =
247 			devm_kzalloc(drm->dev, sizeof(*dma_dev->dma_parms),
248 				     GFP_KERNEL);
249 	}
250 	if (!dma_dev->dma_parms) {
251 		ret = -ENOMEM;
252 		goto put_dma_dev;
253 	}
254 
255 	ret = dma_set_max_seg_size(dma_dev, (unsigned int)DMA_BIT_MASK(32));
256 	if (ret) {
257 		dev_err(dma_dev, "Failed to set DMA segment size\n");
258 		goto err_unset_dma_parms;
259 	}
260 
261 	/*
262 	 * We don't use the drm_irq_install() helpers provided by the DRM
263 	 * core, so we need to set this manually in order to allow the
264 	 * DRM_IOCTL_WAIT_VBLANK to operate correctly.
265 	 */
266 	drm->irq_enabled = true;
267 	ret = drm_vblank_init(drm, MAX_CRTC);
268 	if (ret < 0)
269 		goto err_unset_dma_parms;
270 
271 	drm_kms_helper_poll_init(drm);
272 	drm_mode_config_reset(drm);
273 
274 	return 0;
275 
276 err_unset_dma_parms:
277 	if (private->dma_parms_allocated)
278 		dma_dev->dma_parms = NULL;
279 put_dma_dev:
280 	put_device(private->dma_dev);
281 err_component_unbind:
282 	component_unbind_all(drm->dev, drm);
283 put_mutex_dev:
284 	put_device(private->mutex_dev);
285 	return ret;
286 }
287 
mtk_drm_kms_deinit(struct drm_device * drm)288 static void mtk_drm_kms_deinit(struct drm_device *drm)
289 {
290 	struct mtk_drm_private *private = drm->dev_private;
291 
292 	drm_kms_helper_poll_fini(drm);
293 	drm_atomic_helper_shutdown(drm);
294 
295 	if (private->dma_parms_allocated)
296 		private->dma_dev->dma_parms = NULL;
297 
298 	component_unbind_all(drm->dev, drm);
299 }
300 
301 static const struct file_operations mtk_drm_fops = {
302 	.owner = THIS_MODULE,
303 	.open = drm_open,
304 	.release = drm_release,
305 	.unlocked_ioctl = drm_ioctl,
306 	.mmap = mtk_drm_gem_mmap,
307 	.poll = drm_poll,
308 	.read = drm_read,
309 	.compat_ioctl = drm_compat_ioctl,
310 };
311 
312 /*
313  * We need to override this because the device used to import the memory is
314  * not dev->dev, as drm_gem_prime_import() expects.
315  */
mtk_drm_gem_prime_import(struct drm_device * dev,struct dma_buf * dma_buf)316 struct drm_gem_object *mtk_drm_gem_prime_import(struct drm_device *dev,
317 						struct dma_buf *dma_buf)
318 {
319 	struct mtk_drm_private *private = dev->dev_private;
320 
321 	return drm_gem_prime_import_dev(dev, dma_buf, private->dma_dev);
322 }
323 
324 static struct drm_driver mtk_drm_driver = {
325 	.driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_ATOMIC,
326 
327 	.gem_free_object_unlocked = mtk_drm_gem_free_object,
328 	.gem_vm_ops = &drm_gem_cma_vm_ops,
329 	.dumb_create = mtk_drm_gem_dumb_create,
330 
331 	.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
332 	.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
333 	.gem_prime_import = mtk_drm_gem_prime_import,
334 	.gem_prime_get_sg_table = mtk_gem_prime_get_sg_table,
335 	.gem_prime_import_sg_table = mtk_gem_prime_import_sg_table,
336 	.gem_prime_mmap = mtk_drm_gem_mmap_buf,
337 	.gem_prime_vmap = mtk_drm_gem_prime_vmap,
338 	.gem_prime_vunmap = mtk_drm_gem_prime_vunmap,
339 	.fops = &mtk_drm_fops,
340 
341 	.name = DRIVER_NAME,
342 	.desc = DRIVER_DESC,
343 	.date = DRIVER_DATE,
344 	.major = DRIVER_MAJOR,
345 	.minor = DRIVER_MINOR,
346 };
347 
compare_of(struct device * dev,void * data)348 static int compare_of(struct device *dev, void *data)
349 {
350 	return dev->of_node == data;
351 }
352 
mtk_drm_bind(struct device * dev)353 static int mtk_drm_bind(struct device *dev)
354 {
355 	struct mtk_drm_private *private = dev_get_drvdata(dev);
356 	struct drm_device *drm;
357 	int ret;
358 
359 	drm = drm_dev_alloc(&mtk_drm_driver, dev);
360 	if (IS_ERR(drm))
361 		return PTR_ERR(drm);
362 
363 	drm->dev_private = private;
364 	private->drm = drm;
365 
366 	ret = mtk_drm_kms_init(drm);
367 	if (ret < 0)
368 		goto err_free;
369 
370 	ret = drm_dev_register(drm, 0);
371 	if (ret < 0)
372 		goto err_deinit;
373 
374 	drm_fbdev_generic_setup(drm, 32);
375 
376 	return 0;
377 
378 err_deinit:
379 	mtk_drm_kms_deinit(drm);
380 err_free:
381 	private->drm = NULL;
382 	drm_dev_put(drm);
383 	return ret;
384 }
385 
mtk_drm_unbind(struct device * dev)386 static void mtk_drm_unbind(struct device *dev)
387 {
388 	struct mtk_drm_private *private = dev_get_drvdata(dev);
389 
390 	drm_dev_unregister(private->drm);
391 	mtk_drm_kms_deinit(private->drm);
392 	drm_dev_put(private->drm);
393 	private->num_pipes = 0;
394 	private->drm = NULL;
395 }
396 
397 static const struct component_master_ops mtk_drm_ops = {
398 	.bind		= mtk_drm_bind,
399 	.unbind		= mtk_drm_unbind,
400 };
401 
402 static const struct of_device_id mtk_ddp_comp_dt_ids[] = {
403 	{ .compatible = "mediatek,mt2701-disp-ovl",
404 	  .data = (void *)MTK_DISP_OVL },
405 	{ .compatible = "mediatek,mt8173-disp-ovl",
406 	  .data = (void *)MTK_DISP_OVL },
407 	{ .compatible = "mediatek,mt2701-disp-rdma",
408 	  .data = (void *)MTK_DISP_RDMA },
409 	{ .compatible = "mediatek,mt8173-disp-rdma",
410 	  .data = (void *)MTK_DISP_RDMA },
411 	{ .compatible = "mediatek,mt8173-disp-wdma",
412 	  .data = (void *)MTK_DISP_WDMA },
413 	{ .compatible = "mediatek,mt2701-disp-color",
414 	  .data = (void *)MTK_DISP_COLOR },
415 	{ .compatible = "mediatek,mt8173-disp-color",
416 	  .data = (void *)MTK_DISP_COLOR },
417 	{ .compatible = "mediatek,mt8173-disp-aal",
418 	  .data = (void *)MTK_DISP_AAL},
419 	{ .compatible = "mediatek,mt8173-disp-gamma",
420 	  .data = (void *)MTK_DISP_GAMMA, },
421 	{ .compatible = "mediatek,mt8173-disp-ufoe",
422 	  .data = (void *)MTK_DISP_UFOE },
423 	{ .compatible = "mediatek,mt2701-dsi",
424 	  .data = (void *)MTK_DSI },
425 	{ .compatible = "mediatek,mt8173-dsi",
426 	  .data = (void *)MTK_DSI },
427 	{ .compatible = "mediatek,mt2701-dpi",
428 	  .data = (void *)MTK_DPI },
429 	{ .compatible = "mediatek,mt8173-dpi",
430 	  .data = (void *)MTK_DPI },
431 	{ .compatible = "mediatek,mt2701-disp-mutex",
432 	  .data = (void *)MTK_DISP_MUTEX },
433 	{ .compatible = "mediatek,mt2712-disp-mutex",
434 	  .data = (void *)MTK_DISP_MUTEX },
435 	{ .compatible = "mediatek,mt8173-disp-mutex",
436 	  .data = (void *)MTK_DISP_MUTEX },
437 	{ .compatible = "mediatek,mt2701-disp-pwm",
438 	  .data = (void *)MTK_DISP_BLS },
439 	{ .compatible = "mediatek,mt8173-disp-pwm",
440 	  .data = (void *)MTK_DISP_PWM },
441 	{ .compatible = "mediatek,mt8173-disp-od",
442 	  .data = (void *)MTK_DISP_OD },
443 	{ }
444 };
445 
446 static const struct of_device_id mtk_drm_of_ids[] = {
447 	{ .compatible = "mediatek,mt2701-mmsys",
448 	  .data = &mt2701_mmsys_driver_data},
449 	{ .compatible = "mediatek,mt7623-mmsys",
450 	  .data = &mt7623_mmsys_driver_data},
451 	{ .compatible = "mediatek,mt2712-mmsys",
452 	  .data = &mt2712_mmsys_driver_data},
453 	{ .compatible = "mediatek,mt8173-mmsys",
454 	  .data = &mt8173_mmsys_driver_data},
455 	{ }
456 };
457 
mtk_drm_probe(struct platform_device * pdev)458 static int mtk_drm_probe(struct platform_device *pdev)
459 {
460 	struct device *dev = &pdev->dev;
461 	struct device_node *phandle = dev->parent->of_node;
462 	const struct of_device_id *of_id;
463 	struct mtk_drm_private *private;
464 	struct device_node *node;
465 	struct component_match *match = NULL;
466 	int ret;
467 	int i;
468 
469 	private = devm_kzalloc(dev, sizeof(*private), GFP_KERNEL);
470 	if (!private)
471 		return -ENOMEM;
472 
473 	private->mmsys_dev = dev->parent;
474 	if (!private->mmsys_dev) {
475 		dev_err(dev, "Failed to get MMSYS device\n");
476 		return -ENODEV;
477 	}
478 
479 	of_id = of_match_node(mtk_drm_of_ids, phandle);
480 	if (!of_id)
481 		return -ENODEV;
482 
483 	private->data = of_id->data;
484 
485 	/* Iterate over sibling DISP function blocks */
486 	for_each_child_of_node(phandle->parent, node) {
487 		const struct of_device_id *of_id;
488 		enum mtk_ddp_comp_type comp_type;
489 		int comp_id;
490 
491 		of_id = of_match_node(mtk_ddp_comp_dt_ids, node);
492 		if (!of_id)
493 			continue;
494 
495 		if (!of_device_is_available(node)) {
496 			dev_dbg(dev, "Skipping disabled component %pOF\n",
497 				node);
498 			continue;
499 		}
500 
501 		comp_type = (enum mtk_ddp_comp_type)of_id->data;
502 
503 		if (comp_type == MTK_DISP_MUTEX) {
504 			private->mutex_node = of_node_get(node);
505 			continue;
506 		}
507 
508 		comp_id = mtk_ddp_comp_get_id(node, comp_type);
509 		if (comp_id < 0) {
510 			dev_warn(dev, "Skipping unknown component %pOF\n",
511 				 node);
512 			continue;
513 		}
514 
515 		private->comp_node[comp_id] = of_node_get(node);
516 
517 		/*
518 		 * Currently only the COLOR, OVL, RDMA, DSI, and DPI blocks have
519 		 * separate component platform drivers and initialize their own
520 		 * DDP component structure. The others are initialized here.
521 		 */
522 		if (comp_type == MTK_DISP_COLOR ||
523 		    comp_type == MTK_DISP_OVL ||
524 		    comp_type == MTK_DISP_OVL_2L ||
525 		    comp_type == MTK_DISP_RDMA ||
526 		    comp_type == MTK_DSI ||
527 		    comp_type == MTK_DPI) {
528 			dev_info(dev, "Adding component match for %pOF\n",
529 				 node);
530 			drm_of_component_match_add(dev, &match, compare_of,
531 						   node);
532 		} else {
533 			struct mtk_ddp_comp *comp;
534 
535 			comp = devm_kzalloc(dev, sizeof(*comp), GFP_KERNEL);
536 			if (!comp) {
537 				ret = -ENOMEM;
538 				of_node_put(node);
539 				goto err_node;
540 			}
541 
542 			ret = mtk_ddp_comp_init(dev->parent, node, comp,
543 						comp_id, NULL);
544 			if (ret) {
545 				of_node_put(node);
546 				goto err_node;
547 			}
548 
549 			private->ddp_comp[comp_id] = comp;
550 		}
551 	}
552 
553 	if (!private->mutex_node) {
554 		dev_err(dev, "Failed to find disp-mutex node\n");
555 		ret = -ENODEV;
556 		goto err_node;
557 	}
558 
559 	pm_runtime_enable(dev);
560 
561 	platform_set_drvdata(pdev, private);
562 
563 	ret = component_master_add_with_match(dev, &mtk_drm_ops, match);
564 	if (ret)
565 		goto err_pm;
566 
567 	return 0;
568 
569 err_pm:
570 	pm_runtime_disable(dev);
571 err_node:
572 	of_node_put(private->mutex_node);
573 	for (i = 0; i < DDP_COMPONENT_ID_MAX; i++) {
574 		of_node_put(private->comp_node[i]);
575 		if (private->ddp_comp[i]) {
576 			put_device(private->ddp_comp[i]->larb_dev);
577 			private->ddp_comp[i] = NULL;
578 		}
579 	}
580 	return ret;
581 }
582 
mtk_drm_remove(struct platform_device * pdev)583 static int mtk_drm_remove(struct platform_device *pdev)
584 {
585 	struct mtk_drm_private *private = platform_get_drvdata(pdev);
586 	int i;
587 
588 	component_master_del(&pdev->dev, &mtk_drm_ops);
589 	pm_runtime_disable(&pdev->dev);
590 	of_node_put(private->mutex_node);
591 	for (i = 0; i < DDP_COMPONENT_ID_MAX; i++)
592 		of_node_put(private->comp_node[i]);
593 
594 	return 0;
595 }
596 
597 #ifdef CONFIG_PM_SLEEP
mtk_drm_sys_suspend(struct device * dev)598 static int mtk_drm_sys_suspend(struct device *dev)
599 {
600 	struct mtk_drm_private *private = dev_get_drvdata(dev);
601 	struct drm_device *drm = private->drm;
602 	int ret;
603 
604 	ret = drm_mode_config_helper_suspend(drm);
605 
606 	return ret;
607 }
608 
mtk_drm_sys_resume(struct device * dev)609 static int mtk_drm_sys_resume(struct device *dev)
610 {
611 	struct mtk_drm_private *private = dev_get_drvdata(dev);
612 	struct drm_device *drm = private->drm;
613 	int ret;
614 
615 	ret = drm_mode_config_helper_resume(drm);
616 
617 	return ret;
618 }
619 #endif
620 
621 static SIMPLE_DEV_PM_OPS(mtk_drm_pm_ops, mtk_drm_sys_suspend,
622 			 mtk_drm_sys_resume);
623 
624 static struct platform_driver mtk_drm_platform_driver = {
625 	.probe	= mtk_drm_probe,
626 	.remove	= mtk_drm_remove,
627 	.driver	= {
628 		.name	= "mediatek-drm",
629 		.pm     = &mtk_drm_pm_ops,
630 	},
631 };
632 
633 static struct platform_driver * const mtk_drm_drivers[] = {
634 	&mtk_ddp_driver,
635 	&mtk_disp_color_driver,
636 	&mtk_disp_ovl_driver,
637 	&mtk_disp_rdma_driver,
638 	&mtk_dpi_driver,
639 	&mtk_drm_platform_driver,
640 	&mtk_mipi_tx_driver,
641 	&mtk_dsi_driver,
642 };
643 
mtk_drm_init(void)644 static int __init mtk_drm_init(void)
645 {
646 	return platform_register_drivers(mtk_drm_drivers,
647 					 ARRAY_SIZE(mtk_drm_drivers));
648 }
649 
mtk_drm_exit(void)650 static void __exit mtk_drm_exit(void)
651 {
652 	platform_unregister_drivers(mtk_drm_drivers,
653 				    ARRAY_SIZE(mtk_drm_drivers));
654 }
655 
656 module_init(mtk_drm_init);
657 module_exit(mtk_drm_exit);
658 
659 MODULE_AUTHOR("YT SHEN <yt.shen@mediatek.com>");
660 MODULE_DESCRIPTION("Mediatek SoC DRM driver");
661 MODULE_LICENSE("GPL v2");
662