| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) 2015 Free Electrons |
|---|
| 3 | 4 | * Copyright (C) 2015 NextThing Co |
|---|
| 4 | 5 | * |
|---|
| 5 | 6 | * Maxime Ripard <maxime.ripard@free-electrons.com> |
|---|
| 6 | | - * |
|---|
| 7 | | - * This program is free software; you can redistribute it and/or |
|---|
| 8 | | - * modify it under the terms of the GNU General Public License as |
|---|
| 9 | | - * published by the Free Software Foundation; either version 2 of |
|---|
| 10 | | - * the License, or (at your option) any later version. |
|---|
| 11 | 7 | */ |
|---|
| 12 | 8 | |
|---|
| 13 | 9 | #include <linux/component.h> |
|---|
| 14 | 10 | #include <linux/kfifo.h> |
|---|
| 11 | +#include <linux/module.h> |
|---|
| 15 | 12 | #include <linux/of_graph.h> |
|---|
| 16 | 13 | #include <linux/of_reserved_mem.h> |
|---|
| 14 | +#include <linux/platform_device.h> |
|---|
| 17 | 15 | |
|---|
| 18 | | -#include <drm/drmP.h> |
|---|
| 19 | | -#include <drm/drm_crtc_helper.h> |
|---|
| 16 | +#include <drm/drm_atomic_helper.h> |
|---|
| 17 | +#include <drm/drm_drv.h> |
|---|
| 20 | 18 | #include <drm/drm_fb_cma_helper.h> |
|---|
| 21 | | -#include <drm/drm_gem_cma_helper.h> |
|---|
| 22 | 19 | #include <drm/drm_fb_helper.h> |
|---|
| 20 | +#include <drm/drm_gem_cma_helper.h> |
|---|
| 23 | 21 | #include <drm/drm_of.h> |
|---|
| 22 | +#include <drm/drm_probe_helper.h> |
|---|
| 23 | +#include <drm/drm_vblank.h> |
|---|
| 24 | 24 | |
|---|
| 25 | 25 | #include "sun4i_drv.h" |
|---|
| 26 | 26 | #include "sun4i_frontend.h" |
|---|
| .. | .. |
|---|
| 28 | 28 | #include "sun4i_tcon.h" |
|---|
| 29 | 29 | #include "sun8i_tcon_top.h" |
|---|
| 30 | 30 | |
|---|
| 31 | +static int drm_sun4i_gem_dumb_create(struct drm_file *file_priv, |
|---|
| 32 | + struct drm_device *drm, |
|---|
| 33 | + struct drm_mode_create_dumb *args) |
|---|
| 34 | +{ |
|---|
| 35 | + /* The hardware only allows even pitches for YUV buffers. */ |
|---|
| 36 | + args->pitch = ALIGN(DIV_ROUND_UP(args->width * args->bpp, 8), 2); |
|---|
| 37 | + |
|---|
| 38 | + return drm_gem_cma_dumb_create_internal(file_priv, drm, args); |
|---|
| 39 | +} |
|---|
| 40 | + |
|---|
| 31 | 41 | DEFINE_DRM_GEM_CMA_FOPS(sun4i_drv_fops); |
|---|
| 32 | 42 | |
|---|
| 33 | 43 | static struct drm_driver sun4i_drv_driver = { |
|---|
| 34 | | - .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_PRIME | DRIVER_ATOMIC, |
|---|
| 44 | + .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC, |
|---|
| 35 | 45 | |
|---|
| 36 | 46 | /* Generic Operations */ |
|---|
| 37 | | - .lastclose = drm_fb_helper_lastclose, |
|---|
| 38 | 47 | .fops = &sun4i_drv_fops, |
|---|
| 39 | 48 | .name = "sun4i-drm", |
|---|
| 40 | 49 | .desc = "Allwinner sun4i Display Engine", |
|---|
| .. | .. |
|---|
| 43 | 52 | .minor = 0, |
|---|
| 44 | 53 | |
|---|
| 45 | 54 | /* GEM Operations */ |
|---|
| 46 | | - .dumb_create = drm_gem_cma_dumb_create, |
|---|
| 47 | | - .gem_free_object_unlocked = drm_gem_cma_free_object, |
|---|
| 48 | | - .gem_vm_ops = &drm_gem_cma_vm_ops, |
|---|
| 49 | | - |
|---|
| 50 | | - /* PRIME Operations */ |
|---|
| 51 | | - .prime_handle_to_fd = drm_gem_prime_handle_to_fd, |
|---|
| 52 | | - .prime_fd_to_handle = drm_gem_prime_fd_to_handle, |
|---|
| 53 | | - .gem_prime_import = drm_gem_prime_import, |
|---|
| 54 | | - .gem_prime_export = drm_gem_prime_export, |
|---|
| 55 | | - .gem_prime_get_sg_table = drm_gem_cma_prime_get_sg_table, |
|---|
| 56 | | - .gem_prime_import_sg_table = drm_gem_cma_prime_import_sg_table, |
|---|
| 57 | | - .gem_prime_vmap = drm_gem_cma_prime_vmap, |
|---|
| 58 | | - .gem_prime_vunmap = drm_gem_cma_prime_vunmap, |
|---|
| 59 | | - .gem_prime_mmap = drm_gem_cma_prime_mmap, |
|---|
| 60 | | - |
|---|
| 61 | | - /* Frame Buffer Operations */ |
|---|
| 55 | + DRM_GEM_CMA_DRIVER_OPS_VMAP_WITH_DUMB_CREATE(drm_sun4i_gem_dumb_create), |
|---|
| 62 | 56 | }; |
|---|
| 63 | | - |
|---|
| 64 | | -static void sun4i_remove_framebuffers(void) |
|---|
| 65 | | -{ |
|---|
| 66 | | - struct apertures_struct *ap; |
|---|
| 67 | | - |
|---|
| 68 | | - ap = alloc_apertures(1); |
|---|
| 69 | | - if (!ap) |
|---|
| 70 | | - return; |
|---|
| 71 | | - |
|---|
| 72 | | - /* The framebuffer can be located anywhere in RAM */ |
|---|
| 73 | | - ap->ranges[0].base = 0; |
|---|
| 74 | | - ap->ranges[0].size = ~0; |
|---|
| 75 | | - |
|---|
| 76 | | - drm_fb_helper_remove_conflicting_framebuffers(ap, "sun4i-drm-fb", false); |
|---|
| 77 | | - kfree(ap); |
|---|
| 78 | | -} |
|---|
| 79 | 57 | |
|---|
| 80 | 58 | static int sun4i_drv_bind(struct device *dev) |
|---|
| 81 | 59 | { |
|---|
| .. | .. |
|---|
| 93 | 71 | goto free_drm; |
|---|
| 94 | 72 | } |
|---|
| 95 | 73 | |
|---|
| 96 | | - dev_set_drvdata(dev, drm); |
|---|
| 97 | 74 | drm->dev_private = drv; |
|---|
| 98 | 75 | INIT_LIST_HEAD(&drv->frontend_list); |
|---|
| 99 | 76 | INIT_LIST_HEAD(&drv->engine_list); |
|---|
| .. | .. |
|---|
| 116 | 93 | /* drm_vblank_init calls kcalloc, which can fail */ |
|---|
| 117 | 94 | ret = drm_vblank_init(drm, drm->mode_config.num_crtc); |
|---|
| 118 | 95 | if (ret) |
|---|
| 119 | | - goto cleanup_mode_config; |
|---|
| 96 | + goto unbind_all; |
|---|
| 120 | 97 | |
|---|
| 121 | 98 | drm->irq_enabled = true; |
|---|
| 122 | 99 | |
|---|
| 123 | 100 | /* Remove early framebuffers (ie. simplefb) */ |
|---|
| 124 | | - sun4i_remove_framebuffers(); |
|---|
| 101 | + drm_fb_helper_remove_conflicting_framebuffers(NULL, "sun4i-drm-fb", false); |
|---|
| 125 | 102 | |
|---|
| 126 | | - /* Create our framebuffer */ |
|---|
| 127 | | - ret = sun4i_framebuffer_init(drm); |
|---|
| 128 | | - if (ret) { |
|---|
| 129 | | - dev_err(drm->dev, "Couldn't create our framebuffer\n"); |
|---|
| 130 | | - goto cleanup_mode_config; |
|---|
| 131 | | - } |
|---|
| 103 | + sun4i_framebuffer_init(drm); |
|---|
| 132 | 104 | |
|---|
| 133 | 105 | /* Enable connectors polling */ |
|---|
| 134 | 106 | drm_kms_helper_poll_init(drm); |
|---|
| .. | .. |
|---|
| 137 | 109 | if (ret) |
|---|
| 138 | 110 | goto finish_poll; |
|---|
| 139 | 111 | |
|---|
| 112 | + drm_fbdev_generic_setup(drm, 32); |
|---|
| 113 | + |
|---|
| 114 | + dev_set_drvdata(dev, drm); |
|---|
| 115 | + |
|---|
| 140 | 116 | return 0; |
|---|
| 141 | 117 | |
|---|
| 142 | 118 | finish_poll: |
|---|
| 143 | 119 | drm_kms_helper_poll_fini(drm); |
|---|
| 144 | | - sun4i_framebuffer_free(drm); |
|---|
| 120 | +unbind_all: |
|---|
| 121 | + component_unbind_all(dev, NULL); |
|---|
| 145 | 122 | cleanup_mode_config: |
|---|
| 146 | 123 | drm_mode_config_cleanup(drm); |
|---|
| 147 | 124 | of_reserved_mem_device_release(dev); |
|---|
| .. | .. |
|---|
| 154 | 131 | { |
|---|
| 155 | 132 | struct drm_device *drm = dev_get_drvdata(dev); |
|---|
| 156 | 133 | |
|---|
| 134 | + dev_set_drvdata(dev, NULL); |
|---|
| 157 | 135 | drm_dev_unregister(drm); |
|---|
| 158 | 136 | drm_kms_helper_poll_fini(drm); |
|---|
| 159 | | - sun4i_framebuffer_free(drm); |
|---|
| 137 | + drm_atomic_helper_shutdown(drm); |
|---|
| 160 | 138 | drm_mode_config_cleanup(drm); |
|---|
| 161 | 139 | |
|---|
| 162 | 140 | component_unbind_all(dev, NULL); |
|---|
| .. | .. |
|---|
| 181 | 159 | of_device_is_compatible(node, "allwinner,sun5i-a13-display-frontend") || |
|---|
| 182 | 160 | of_device_is_compatible(node, "allwinner,sun6i-a31-display-frontend") || |
|---|
| 183 | 161 | of_device_is_compatible(node, "allwinner,sun7i-a20-display-frontend") || |
|---|
| 162 | + of_device_is_compatible(node, "allwinner,sun8i-a23-display-frontend") || |
|---|
| 184 | 163 | of_device_is_compatible(node, "allwinner,sun8i-a33-display-frontend") || |
|---|
| 185 | 164 | of_device_is_compatible(node, "allwinner,sun9i-a80-display-frontend"); |
|---|
| 186 | 165 | } |
|---|
| .. | .. |
|---|
| 369 | 348 | return count; |
|---|
| 370 | 349 | } |
|---|
| 371 | 350 | |
|---|
| 351 | +#ifdef CONFIG_PM_SLEEP |
|---|
| 352 | +static int sun4i_drv_drm_sys_suspend(struct device *dev) |
|---|
| 353 | +{ |
|---|
| 354 | + struct drm_device *drm = dev_get_drvdata(dev); |
|---|
| 355 | + |
|---|
| 356 | + return drm_mode_config_helper_suspend(drm); |
|---|
| 357 | +} |
|---|
| 358 | + |
|---|
| 359 | +static int sun4i_drv_drm_sys_resume(struct device *dev) |
|---|
| 360 | +{ |
|---|
| 361 | + struct drm_device *drm = dev_get_drvdata(dev); |
|---|
| 362 | + |
|---|
| 363 | + return drm_mode_config_helper_resume(drm); |
|---|
| 364 | +} |
|---|
| 365 | +#endif |
|---|
| 366 | + |
|---|
| 367 | +static const struct dev_pm_ops sun4i_drv_drm_pm_ops = { |
|---|
| 368 | + SET_SYSTEM_SLEEP_PM_OPS(sun4i_drv_drm_sys_suspend, |
|---|
| 369 | + sun4i_drv_drm_sys_resume) |
|---|
| 370 | +}; |
|---|
| 371 | + |
|---|
| 372 | 372 | static int sun4i_drv_probe(struct platform_device *pdev) |
|---|
| 373 | 373 | { |
|---|
| 374 | 374 | struct component_match *match = NULL; |
|---|
| .. | .. |
|---|
| 422 | 422 | { .compatible = "allwinner,sun6i-a31-display-engine" }, |
|---|
| 423 | 423 | { .compatible = "allwinner,sun6i-a31s-display-engine" }, |
|---|
| 424 | 424 | { .compatible = "allwinner,sun7i-a20-display-engine" }, |
|---|
| 425 | + { .compatible = "allwinner,sun8i-a23-display-engine" }, |
|---|
| 425 | 426 | { .compatible = "allwinner,sun8i-a33-display-engine" }, |
|---|
| 426 | 427 | { .compatible = "allwinner,sun8i-a83t-display-engine" }, |
|---|
| 427 | 428 | { .compatible = "allwinner,sun8i-h3-display-engine" }, |
|---|
| 429 | + { .compatible = "allwinner,sun8i-r40-display-engine" }, |
|---|
| 428 | 430 | { .compatible = "allwinner,sun8i-v3s-display-engine" }, |
|---|
| 429 | 431 | { .compatible = "allwinner,sun9i-a80-display-engine" }, |
|---|
| 432 | + { .compatible = "allwinner,sun50i-a64-display-engine" }, |
|---|
| 433 | + { .compatible = "allwinner,sun50i-h6-display-engine" }, |
|---|
| 430 | 434 | { } |
|---|
| 431 | 435 | }; |
|---|
| 432 | 436 | MODULE_DEVICE_TABLE(of, sun4i_drv_of_table); |
|---|
| .. | .. |
|---|
| 437 | 441 | .driver = { |
|---|
| 438 | 442 | .name = "sun4i-drm", |
|---|
| 439 | 443 | .of_match_table = sun4i_drv_of_table, |
|---|
| 444 | + .pm = &sun4i_drv_drm_pm_ops, |
|---|
| 440 | 445 | }, |
|---|
| 441 | 446 | }; |
|---|
| 442 | 447 | module_platform_driver(sun4i_drv_platform_driver); |
|---|