forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/gpu/drm/tilcdc/tilcdc_drv.c
....@@ -1,35 +1,35 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (C) 2012 Texas Instruments
34 * Author: Rob Clark <robdclark@gmail.com>
4
- *
5
- * This program is free software; you can redistribute it and/or modify it
6
- * under the terms of the GNU General Public License version 2 as published by
7
- * the Free Software Foundation.
8
- *
9
- * This program is distributed in the hope that it will be useful, but WITHOUT
10
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12
- * more details.
13
- *
14
- * You should have received a copy of the GNU General Public License along with
15
- * this program. If not, see <http://www.gnu.org/licenses/>.
165 */
176
187 /* LCDC DRM driver, based on da8xx-fb */
198
209 #include <linux/component.h>
10
+#include <linux/mod_devicetable.h>
11
+#include <linux/module.h>
2112 #include <linux/pinctrl/consumer.h>
22
-#include <linux/suspend.h>
23
-#include <drm/drm_atomic.h>
13
+#include <linux/platform_device.h>
14
+#include <linux/pm_runtime.h>
15
+
2416 #include <drm/drm_atomic_helper.h>
17
+#include <drm/drm_debugfs.h>
18
+#include <drm/drm_drv.h>
2519 #include <drm/drm_fb_helper.h>
20
+#include <drm/drm_fourcc.h>
21
+#include <drm/drm_gem_cma_helper.h>
2622 #include <drm/drm_gem_framebuffer_helper.h>
23
+#include <drm/drm_irq.h>
24
+#include <drm/drm_mm.h>
25
+#include <drm/drm_probe_helper.h>
26
+#include <drm/drm_vblank.h>
27
+
2728
2829 #include "tilcdc_drv.h"
29
-#include "tilcdc_regs.h"
30
-#include "tilcdc_tfp410.h"
31
-#include "tilcdc_panel.h"
3230 #include "tilcdc_external.h"
31
+#include "tilcdc_panel.h"
32
+#include "tilcdc_regs.h"
3333
3434 static LIST_HEAD(module_list);
3535
....@@ -63,12 +63,6 @@
6363
6464 static struct of_device_id tilcdc_of_match[];
6565
66
-static struct drm_framebuffer *tilcdc_fb_create(struct drm_device *dev,
67
- struct drm_file *file_priv, const struct drm_mode_fb_cmd2 *mode_cmd)
68
-{
69
- return drm_gem_fb_create(dev, file_priv, mode_cmd);
70
-}
71
-
7266 static int tilcdc_atomic_check(struct drm_device *dev,
7367 struct drm_atomic_state *state)
7468 {
....@@ -93,56 +87,10 @@
9387 return ret;
9488 }
9589
96
-static int tilcdc_commit(struct drm_device *dev,
97
- struct drm_atomic_state *state,
98
- bool async)
99
-{
100
- int ret;
101
-
102
- ret = drm_atomic_helper_prepare_planes(dev, state);
103
- if (ret)
104
- return ret;
105
-
106
- ret = drm_atomic_helper_swap_state(state, true);
107
- if (ret) {
108
- drm_atomic_helper_cleanup_planes(dev, state);
109
- return ret;
110
- }
111
-
112
- /*
113
- * Everything below can be run asynchronously without the need to grab
114
- * any modeset locks at all under one condition: It must be guaranteed
115
- * that the asynchronous work has either been cancelled (if the driver
116
- * supports it, which at least requires that the framebuffers get
117
- * cleaned up with drm_atomic_helper_cleanup_planes()) or completed
118
- * before the new state gets committed on the software side with
119
- * drm_atomic_helper_swap_state().
120
- *
121
- * This scheme allows new atomic state updates to be prepared and
122
- * checked in parallel to the asynchronous completion of the previous
123
- * update. Which is important since compositors need to figure out the
124
- * composition of the next frame right after having submitted the
125
- * current layout.
126
- */
127
-
128
- drm_atomic_helper_commit_modeset_disables(dev, state);
129
-
130
- drm_atomic_helper_commit_planes(dev, state, 0);
131
-
132
- drm_atomic_helper_commit_modeset_enables(dev, state);
133
-
134
- drm_atomic_helper_wait_for_vblanks(dev, state);
135
-
136
- drm_atomic_helper_cleanup_planes(dev, state);
137
-
138
- return 0;
139
-}
140
-
14190 static const struct drm_mode_config_funcs mode_config_funcs = {
142
- .fb_create = tilcdc_fb_create,
143
- .output_poll_changed = drm_fb_helper_output_poll_changed,
91
+ .fb_create = drm_gem_fb_create,
14492 .atomic_check = tilcdc_atomic_check,
145
- .atomic_commit = tilcdc_commit,
93
+ .atomic_commit = drm_atomic_helper_commit,
14694 };
14795
14896 static void modeset_init(struct drm_device *dev)
....@@ -197,12 +145,8 @@
197145 drm_dev_unregister(dev);
198146
199147 drm_kms_helper_poll_fini(dev);
200
-
201
- drm_fb_cma_fbdev_fini(dev);
202
-
203148 drm_irq_uninstall(dev);
204149 drm_mode_config_cleanup(dev);
205
- tilcdc_remove_external_device(dev);
206150
207151 if (priv->clk)
208152 clk_put(priv->clk);
....@@ -260,7 +204,7 @@
260204 goto init_failed;
261205 }
262206
263
- priv->mmio = ioremap_nocache(res->start, resource_size(res));
207
+ priv->mmio = ioremap(res->start, resource_size(res));
264208 if (!priv->mmio) {
265209 dev_err(dev, "failed to ioremap\n");
266210 ret = -ENOMEM;
....@@ -396,17 +340,14 @@
396340
397341 drm_mode_config_reset(ddev);
398342
399
- ret = drm_fb_cma_fbdev_init(ddev, bpp, 0);
400
- if (ret)
401
- goto init_failed;
402
-
403343 drm_kms_helper_poll_init(ddev);
404344
405345 ret = drm_dev_register(ddev, 0);
406346 if (ret)
407347 goto init_failed;
408
-
409348 priv->is_registered = true;
349
+
350
+ drm_fbdev_generic_setup(ddev, bpp);
410351 return 0;
411352
412353 init_failed:
....@@ -491,50 +432,26 @@
491432 { "mm", tilcdc_mm_show, 0 },
492433 };
493434
494
-static int tilcdc_debugfs_init(struct drm_minor *minor)
435
+static void tilcdc_debugfs_init(struct drm_minor *minor)
495436 {
496
- struct drm_device *dev = minor->dev;
497437 struct tilcdc_module *mod;
498
- int ret;
499438
500
- ret = drm_debugfs_create_files(tilcdc_debugfs_list,
501
- ARRAY_SIZE(tilcdc_debugfs_list),
502
- minor->debugfs_root, minor);
439
+ drm_debugfs_create_files(tilcdc_debugfs_list,
440
+ ARRAY_SIZE(tilcdc_debugfs_list),
441
+ minor->debugfs_root, minor);
503442
504443 list_for_each_entry(mod, &module_list, list)
505444 if (mod->funcs->debugfs_init)
506445 mod->funcs->debugfs_init(mod, minor);
507
-
508
- if (ret) {
509
- dev_err(dev->dev, "could not install tilcdc_debugfs_list\n");
510
- return ret;
511
- }
512
-
513
- return ret;
514446 }
515447 #endif
516448
517449 DEFINE_DRM_GEM_CMA_FOPS(fops);
518450
519451 static struct drm_driver tilcdc_driver = {
520
- .driver_features = (DRIVER_HAVE_IRQ | DRIVER_GEM | DRIVER_MODESET |
521
- DRIVER_PRIME | DRIVER_ATOMIC),
522
- .lastclose = drm_fb_helper_lastclose,
452
+ .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC,
523453 .irq_handler = tilcdc_irq,
524
- .gem_free_object_unlocked = drm_gem_cma_free_object,
525
- .gem_print_info = drm_gem_cma_print_info,
526
- .gem_vm_ops = &drm_gem_cma_vm_ops,
527
- .dumb_create = drm_gem_cma_dumb_create,
528
-
529
- .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
530
- .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
531
- .gem_prime_import = drm_gem_prime_import,
532
- .gem_prime_export = drm_gem_prime_export,
533
- .gem_prime_get_sg_table = drm_gem_cma_prime_get_sg_table,
534
- .gem_prime_import_sg_table = drm_gem_cma_prime_import_sg_table,
535
- .gem_prime_vmap = drm_gem_cma_prime_vmap,
536
- .gem_prime_vunmap = drm_gem_cma_prime_vunmap,
537
- .gem_prime_mmap = drm_gem_cma_prime_mmap,
454
+ DRM_GEM_CMA_DRIVER_OPS,
538455 #ifdef CONFIG_DEBUG_FS
539456 .debugfs_init = tilcdc_debugfs_init,
540457 #endif
....@@ -554,29 +471,23 @@
554471 static int tilcdc_pm_suspend(struct device *dev)
555472 {
556473 struct drm_device *ddev = dev_get_drvdata(dev);
557
- struct tilcdc_drm_private *priv = ddev->dev_private;
474
+ int ret = 0;
558475
559
- priv->saved_state = drm_atomic_helper_suspend(ddev);
476
+ ret = drm_mode_config_helper_suspend(ddev);
560477
561478 /* Select sleep pin state */
562479 pinctrl_pm_select_sleep_state(dev);
563480
564
- return 0;
481
+ return ret;
565482 }
566483
567484 static int tilcdc_pm_resume(struct device *dev)
568485 {
569486 struct drm_device *ddev = dev_get_drvdata(dev);
570
- struct tilcdc_drm_private *priv = ddev->dev_private;
571
- int ret = 0;
572487
573488 /* Select default pin state */
574489 pinctrl_pm_select_default_state(dev);
575
-
576
- if (priv->saved_state)
577
- ret = drm_atomic_helper_resume(ddev, priv->saved_state);
578
-
579
- return ret;
490
+ return drm_mode_config_helper_resume(ddev);
580491 }
581492 #endif
582493
....@@ -665,7 +576,6 @@
665576 static int __init tilcdc_drm_init(void)
666577 {
667578 DBG("init");
668
- tilcdc_tfp410_init();
669579 tilcdc_panel_init();
670580 return platform_driver_register(&tilcdc_platform_driver);
671581 }
....@@ -675,7 +585,6 @@
675585 DBG("fini");
676586 platform_driver_unregister(&tilcdc_platform_driver);
677587 tilcdc_panel_fini();
678
- tilcdc_tfp410_fini();
679588 }
680589
681590 module_init(tilcdc_drm_init);