| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) 2012 Texas Instruments |
|---|
| 3 | 4 | * 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/>. |
|---|
| 16 | 5 | */ |
|---|
| 17 | 6 | |
|---|
| 18 | 7 | /* LCDC DRM driver, based on da8xx-fb */ |
|---|
| 19 | 8 | |
|---|
| 20 | 9 | #include <linux/component.h> |
|---|
| 10 | +#include <linux/mod_devicetable.h> |
|---|
| 11 | +#include <linux/module.h> |
|---|
| 21 | 12 | #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 | + |
|---|
| 24 | 16 | #include <drm/drm_atomic_helper.h> |
|---|
| 17 | +#include <drm/drm_debugfs.h> |
|---|
| 18 | +#include <drm/drm_drv.h> |
|---|
| 25 | 19 | #include <drm/drm_fb_helper.h> |
|---|
| 20 | +#include <drm/drm_fourcc.h> |
|---|
| 21 | +#include <drm/drm_gem_cma_helper.h> |
|---|
| 26 | 22 | #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 | + |
|---|
| 27 | 28 | |
|---|
| 28 | 29 | #include "tilcdc_drv.h" |
|---|
| 29 | | -#include "tilcdc_regs.h" |
|---|
| 30 | | -#include "tilcdc_tfp410.h" |
|---|
| 31 | | -#include "tilcdc_panel.h" |
|---|
| 32 | 30 | #include "tilcdc_external.h" |
|---|
| 31 | +#include "tilcdc_panel.h" |
|---|
| 32 | +#include "tilcdc_regs.h" |
|---|
| 33 | 33 | |
|---|
| 34 | 34 | static LIST_HEAD(module_list); |
|---|
| 35 | 35 | |
|---|
| .. | .. |
|---|
| 63 | 63 | |
|---|
| 64 | 64 | static struct of_device_id tilcdc_of_match[]; |
|---|
| 65 | 65 | |
|---|
| 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 | | - |
|---|
| 72 | 66 | static int tilcdc_atomic_check(struct drm_device *dev, |
|---|
| 73 | 67 | struct drm_atomic_state *state) |
|---|
| 74 | 68 | { |
|---|
| .. | .. |
|---|
| 93 | 87 | return ret; |
|---|
| 94 | 88 | } |
|---|
| 95 | 89 | |
|---|
| 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 | | - |
|---|
| 141 | 90 | 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, |
|---|
| 144 | 92 | .atomic_check = tilcdc_atomic_check, |
|---|
| 145 | | - .atomic_commit = tilcdc_commit, |
|---|
| 93 | + .atomic_commit = drm_atomic_helper_commit, |
|---|
| 146 | 94 | }; |
|---|
| 147 | 95 | |
|---|
| 148 | 96 | static void modeset_init(struct drm_device *dev) |
|---|
| .. | .. |
|---|
| 197 | 145 | drm_dev_unregister(dev); |
|---|
| 198 | 146 | |
|---|
| 199 | 147 | drm_kms_helper_poll_fini(dev); |
|---|
| 200 | | - |
|---|
| 201 | | - drm_fb_cma_fbdev_fini(dev); |
|---|
| 202 | | - |
|---|
| 203 | 148 | drm_irq_uninstall(dev); |
|---|
| 204 | 149 | drm_mode_config_cleanup(dev); |
|---|
| 205 | | - tilcdc_remove_external_device(dev); |
|---|
| 206 | 150 | |
|---|
| 207 | 151 | if (priv->clk) |
|---|
| 208 | 152 | clk_put(priv->clk); |
|---|
| .. | .. |
|---|
| 260 | 204 | goto init_failed; |
|---|
| 261 | 205 | } |
|---|
| 262 | 206 | |
|---|
| 263 | | - priv->mmio = ioremap_nocache(res->start, resource_size(res)); |
|---|
| 207 | + priv->mmio = ioremap(res->start, resource_size(res)); |
|---|
| 264 | 208 | if (!priv->mmio) { |
|---|
| 265 | 209 | dev_err(dev, "failed to ioremap\n"); |
|---|
| 266 | 210 | ret = -ENOMEM; |
|---|
| .. | .. |
|---|
| 396 | 340 | |
|---|
| 397 | 341 | drm_mode_config_reset(ddev); |
|---|
| 398 | 342 | |
|---|
| 399 | | - ret = drm_fb_cma_fbdev_init(ddev, bpp, 0); |
|---|
| 400 | | - if (ret) |
|---|
| 401 | | - goto init_failed; |
|---|
| 402 | | - |
|---|
| 403 | 343 | drm_kms_helper_poll_init(ddev); |
|---|
| 404 | 344 | |
|---|
| 405 | 345 | ret = drm_dev_register(ddev, 0); |
|---|
| 406 | 346 | if (ret) |
|---|
| 407 | 347 | goto init_failed; |
|---|
| 408 | | - |
|---|
| 409 | 348 | priv->is_registered = true; |
|---|
| 349 | + |
|---|
| 350 | + drm_fbdev_generic_setup(ddev, bpp); |
|---|
| 410 | 351 | return 0; |
|---|
| 411 | 352 | |
|---|
| 412 | 353 | init_failed: |
|---|
| .. | .. |
|---|
| 491 | 432 | { "mm", tilcdc_mm_show, 0 }, |
|---|
| 492 | 433 | }; |
|---|
| 493 | 434 | |
|---|
| 494 | | -static int tilcdc_debugfs_init(struct drm_minor *minor) |
|---|
| 435 | +static void tilcdc_debugfs_init(struct drm_minor *minor) |
|---|
| 495 | 436 | { |
|---|
| 496 | | - struct drm_device *dev = minor->dev; |
|---|
| 497 | 437 | struct tilcdc_module *mod; |
|---|
| 498 | | - int ret; |
|---|
| 499 | 438 | |
|---|
| 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); |
|---|
| 503 | 442 | |
|---|
| 504 | 443 | list_for_each_entry(mod, &module_list, list) |
|---|
| 505 | 444 | if (mod->funcs->debugfs_init) |
|---|
| 506 | 445 | 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; |
|---|
| 514 | 446 | } |
|---|
| 515 | 447 | #endif |
|---|
| 516 | 448 | |
|---|
| 517 | 449 | DEFINE_DRM_GEM_CMA_FOPS(fops); |
|---|
| 518 | 450 | |
|---|
| 519 | 451 | 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, |
|---|
| 523 | 453 | .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, |
|---|
| 538 | 455 | #ifdef CONFIG_DEBUG_FS |
|---|
| 539 | 456 | .debugfs_init = tilcdc_debugfs_init, |
|---|
| 540 | 457 | #endif |
|---|
| .. | .. |
|---|
| 554 | 471 | static int tilcdc_pm_suspend(struct device *dev) |
|---|
| 555 | 472 | { |
|---|
| 556 | 473 | struct drm_device *ddev = dev_get_drvdata(dev); |
|---|
| 557 | | - struct tilcdc_drm_private *priv = ddev->dev_private; |
|---|
| 474 | + int ret = 0; |
|---|
| 558 | 475 | |
|---|
| 559 | | - priv->saved_state = drm_atomic_helper_suspend(ddev); |
|---|
| 476 | + ret = drm_mode_config_helper_suspend(ddev); |
|---|
| 560 | 477 | |
|---|
| 561 | 478 | /* Select sleep pin state */ |
|---|
| 562 | 479 | pinctrl_pm_select_sleep_state(dev); |
|---|
| 563 | 480 | |
|---|
| 564 | | - return 0; |
|---|
| 481 | + return ret; |
|---|
| 565 | 482 | } |
|---|
| 566 | 483 | |
|---|
| 567 | 484 | static int tilcdc_pm_resume(struct device *dev) |
|---|
| 568 | 485 | { |
|---|
| 569 | 486 | struct drm_device *ddev = dev_get_drvdata(dev); |
|---|
| 570 | | - struct tilcdc_drm_private *priv = ddev->dev_private; |
|---|
| 571 | | - int ret = 0; |
|---|
| 572 | 487 | |
|---|
| 573 | 488 | /* Select default pin state */ |
|---|
| 574 | 489 | 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); |
|---|
| 580 | 491 | } |
|---|
| 581 | 492 | #endif |
|---|
| 582 | 493 | |
|---|
| .. | .. |
|---|
| 665 | 576 | static int __init tilcdc_drm_init(void) |
|---|
| 666 | 577 | { |
|---|
| 667 | 578 | DBG("init"); |
|---|
| 668 | | - tilcdc_tfp410_init(); |
|---|
| 669 | 579 | tilcdc_panel_init(); |
|---|
| 670 | 580 | return platform_driver_register(&tilcdc_platform_driver); |
|---|
| 671 | 581 | } |
|---|
| .. | .. |
|---|
| 675 | 585 | DBG("fini"); |
|---|
| 676 | 586 | platform_driver_unregister(&tilcdc_platform_driver); |
|---|
| 677 | 587 | tilcdc_panel_fini(); |
|---|
| 678 | | - tilcdc_tfp410_fini(); |
|---|
| 679 | 588 | } |
|---|
| 680 | 589 | |
|---|
| 681 | 590 | module_init(tilcdc_drm_init); |
|---|