| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* exynos_drm_fbdev.c |
|---|
| 2 | 3 | * |
|---|
| 3 | 4 | * Copyright (c) 2011 Samsung Electronics Co., Ltd. |
|---|
| .. | .. |
|---|
| 5 | 6 | * Inki Dae <inki.dae@samsung.com> |
|---|
| 6 | 7 | * Joonyoung Shim <jy0922.shim@samsung.com> |
|---|
| 7 | 8 | * Seung-Woo Kim <sw0312.kim@samsung.com> |
|---|
| 8 | | - * |
|---|
| 9 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 10 | | - * under the terms of the GNU General Public License as published by the |
|---|
| 11 | | - * Free Software Foundation; either version 2 of the License, or (at your |
|---|
| 12 | | - * option) any later version. |
|---|
| 13 | 9 | */ |
|---|
| 14 | 10 | |
|---|
| 15 | | -#include <drm/drmP.h> |
|---|
| 11 | +#include <linux/console.h> |
|---|
| 12 | +#include <linux/dma-mapping.h> |
|---|
| 13 | +#include <linux/vmalloc.h> |
|---|
| 14 | + |
|---|
| 16 | 15 | #include <drm/drm_crtc.h> |
|---|
| 17 | 16 | #include <drm/drm_fb_helper.h> |
|---|
| 18 | | -#include <drm/drm_crtc_helper.h> |
|---|
| 17 | +#include <drm/drm_fourcc.h> |
|---|
| 18 | +#include <drm/drm_probe_helper.h> |
|---|
| 19 | 19 | #include <drm/exynos_drm.h> |
|---|
| 20 | | - |
|---|
| 21 | | -#include <linux/console.h> |
|---|
| 22 | 20 | |
|---|
| 23 | 21 | #include "exynos_drm_drv.h" |
|---|
| 24 | 22 | #include "exynos_drm_fb.h" |
|---|
| 25 | 23 | #include "exynos_drm_fbdev.h" |
|---|
| 26 | | -#include "exynos_drm_iommu.h" |
|---|
| 27 | 24 | |
|---|
| 28 | 25 | #define MAX_CONNECTOR 4 |
|---|
| 29 | 26 | #define PREFERRED_BPP 32 |
|---|
| .. | .. |
|---|
| 56 | 53 | exynos_gem->dma_addr, exynos_gem->size, |
|---|
| 57 | 54 | exynos_gem->dma_attrs); |
|---|
| 58 | 55 | if (ret < 0) { |
|---|
| 59 | | - DRM_ERROR("failed to mmap.\n"); |
|---|
| 56 | + DRM_DEV_ERROR(to_dma_dev(helper->dev), "failed to mmap.\n"); |
|---|
| 60 | 57 | return ret; |
|---|
| 61 | 58 | } |
|---|
| 62 | 59 | |
|---|
| 63 | 60 | return 0; |
|---|
| 64 | 61 | } |
|---|
| 65 | 62 | |
|---|
| 66 | | -static struct fb_ops exynos_drm_fb_ops = { |
|---|
| 63 | +static const struct fb_ops exynos_drm_fb_ops = { |
|---|
| 67 | 64 | .owner = THIS_MODULE, |
|---|
| 68 | 65 | DRM_FB_HELPER_DEFAULT_OPS, |
|---|
| 69 | 66 | .fb_mmap = exynos_drm_fb_mmap, |
|---|
| .. | .. |
|---|
| 79 | 76 | struct fb_info *fbi; |
|---|
| 80 | 77 | struct drm_framebuffer *fb = helper->fb; |
|---|
| 81 | 78 | unsigned int size = fb->width * fb->height * fb->format->cpp[0]; |
|---|
| 82 | | - unsigned int nr_pages; |
|---|
| 83 | 79 | unsigned long offset; |
|---|
| 84 | 80 | |
|---|
| 85 | 81 | fbi = drm_fb_helper_alloc_fbi(helper); |
|---|
| 86 | 82 | if (IS_ERR(fbi)) { |
|---|
| 87 | | - DRM_ERROR("failed to allocate fb info.\n"); |
|---|
| 83 | + DRM_DEV_ERROR(to_dma_dev(helper->dev), |
|---|
| 84 | + "failed to allocate fb info.\n"); |
|---|
| 88 | 85 | return PTR_ERR(fbi); |
|---|
| 89 | 86 | } |
|---|
| 90 | 87 | |
|---|
| 91 | | - fbi->par = helper; |
|---|
| 92 | | - fbi->flags = FBINFO_FLAG_DEFAULT; |
|---|
| 93 | 88 | fbi->fbops = &exynos_drm_fb_ops; |
|---|
| 94 | 89 | |
|---|
| 95 | | - drm_fb_helper_fill_fix(fbi, fb->pitches[0], fb->format->depth); |
|---|
| 96 | | - drm_fb_helper_fill_var(fbi, helper, sizes->fb_width, sizes->fb_height); |
|---|
| 97 | | - |
|---|
| 98 | | - nr_pages = exynos_gem->size >> PAGE_SHIFT; |
|---|
| 99 | | - |
|---|
| 100 | | - exynos_gem->kvaddr = (void __iomem *) vmap(exynos_gem->pages, nr_pages, |
|---|
| 101 | | - VM_MAP, pgprot_writecombine(PAGE_KERNEL)); |
|---|
| 102 | | - if (!exynos_gem->kvaddr) { |
|---|
| 103 | | - DRM_ERROR("failed to map pages to kernel space.\n"); |
|---|
| 104 | | - return -EIO; |
|---|
| 105 | | - } |
|---|
| 90 | + drm_fb_helper_fill_info(fbi, helper, sizes); |
|---|
| 106 | 91 | |
|---|
| 107 | 92 | offset = fbi->var.xoffset * fb->format->cpp[0]; |
|---|
| 108 | 93 | offset += fbi->var.yoffset * fb->pitches[0]; |
|---|
| 109 | 94 | |
|---|
| 110 | | - fbi->screen_base = exynos_gem->kvaddr + offset; |
|---|
| 95 | + fbi->screen_buffer = exynos_gem->kvaddr + offset; |
|---|
| 111 | 96 | fbi->screen_size = size; |
|---|
| 112 | 97 | fbi->fix.smem_len = size; |
|---|
| 113 | 98 | |
|---|
| .. | .. |
|---|
| 124 | 109 | unsigned long size; |
|---|
| 125 | 110 | int ret; |
|---|
| 126 | 111 | |
|---|
| 127 | | - DRM_DEBUG_KMS("surface width(%d), height(%d) and bpp(%d\n", |
|---|
| 128 | | - sizes->surface_width, sizes->surface_height, |
|---|
| 129 | | - sizes->surface_bpp); |
|---|
| 112 | + DRM_DEV_DEBUG_KMS(dev->dev, |
|---|
| 113 | + "surface width(%d), height(%d) and bpp(%d\n", |
|---|
| 114 | + sizes->surface_width, sizes->surface_height, |
|---|
| 115 | + sizes->surface_bpp); |
|---|
| 130 | 116 | |
|---|
| 131 | 117 | mode_cmd.width = sizes->surface_width; |
|---|
| 132 | 118 | mode_cmd.height = sizes->surface_height; |
|---|
| .. | .. |
|---|
| 136 | 122 | |
|---|
| 137 | 123 | size = mode_cmd.pitches[0] * mode_cmd.height; |
|---|
| 138 | 124 | |
|---|
| 139 | | - exynos_gem = exynos_drm_gem_create(dev, EXYNOS_BO_CONTIG, size); |
|---|
| 140 | | - /* |
|---|
| 141 | | - * If physically contiguous memory allocation fails and if IOMMU is |
|---|
| 142 | | - * supported then try to get buffer from non physically contiguous |
|---|
| 143 | | - * memory area. |
|---|
| 144 | | - */ |
|---|
| 145 | | - if (IS_ERR(exynos_gem) && is_drm_iommu_supported(dev)) { |
|---|
| 146 | | - dev_warn(dev->dev, "contiguous FB allocation failed, falling back to non-contiguous\n"); |
|---|
| 147 | | - exynos_gem = exynos_drm_gem_create(dev, EXYNOS_BO_NONCONTIG, |
|---|
| 148 | | - size); |
|---|
| 149 | | - } |
|---|
| 150 | | - |
|---|
| 125 | + exynos_gem = exynos_drm_gem_create(dev, EXYNOS_BO_WC, size, true); |
|---|
| 151 | 126 | if (IS_ERR(exynos_gem)) |
|---|
| 152 | 127 | return PTR_ERR(exynos_gem); |
|---|
| 153 | 128 | |
|---|
| .. | .. |
|---|
| 156 | 131 | helper->fb = |
|---|
| 157 | 132 | exynos_drm_framebuffer_init(dev, &mode_cmd, &exynos_gem, 1); |
|---|
| 158 | 133 | if (IS_ERR(helper->fb)) { |
|---|
| 159 | | - DRM_ERROR("failed to create drm framebuffer.\n"); |
|---|
| 134 | + DRM_DEV_ERROR(dev->dev, "failed to create drm framebuffer.\n"); |
|---|
| 160 | 135 | ret = PTR_ERR(helper->fb); |
|---|
| 161 | 136 | goto err_destroy_gem; |
|---|
| 162 | 137 | } |
|---|
| .. | .. |
|---|
| 192 | 167 | struct drm_fb_helper *helper; |
|---|
| 193 | 168 | int ret; |
|---|
| 194 | 169 | |
|---|
| 195 | | - if (!dev->mode_config.num_crtc || !dev->mode_config.num_connector) |
|---|
| 170 | + if (!dev->mode_config.num_crtc) |
|---|
| 196 | 171 | return 0; |
|---|
| 197 | 172 | |
|---|
| 198 | 173 | fbdev = kzalloc(sizeof(*fbdev), GFP_KERNEL); |
|---|
| .. | .. |
|---|
| 203 | 178 | |
|---|
| 204 | 179 | drm_fb_helper_prepare(dev, helper, &exynos_drm_fb_helper_funcs); |
|---|
| 205 | 180 | |
|---|
| 206 | | - ret = drm_fb_helper_init(dev, helper, MAX_CONNECTOR); |
|---|
| 181 | + ret = drm_fb_helper_init(dev, helper); |
|---|
| 207 | 182 | if (ret < 0) { |
|---|
| 208 | | - DRM_ERROR("failed to initialize drm fb helper.\n"); |
|---|
| 183 | + DRM_DEV_ERROR(dev->dev, |
|---|
| 184 | + "failed to initialize drm fb helper.\n"); |
|---|
| 209 | 185 | goto err_init; |
|---|
| 210 | | - } |
|---|
| 211 | | - |
|---|
| 212 | | - ret = drm_fb_helper_single_add_all_connectors(helper); |
|---|
| 213 | | - if (ret < 0) { |
|---|
| 214 | | - DRM_ERROR("failed to register drm_fb_helper_connector.\n"); |
|---|
| 215 | | - goto err_setup; |
|---|
| 216 | | - |
|---|
| 217 | 186 | } |
|---|
| 218 | 187 | |
|---|
| 219 | 188 | ret = drm_fb_helper_initial_config(helper, PREFERRED_BPP); |
|---|
| 220 | 189 | if (ret < 0) { |
|---|
| 221 | | - DRM_ERROR("failed to set up hw configuration.\n"); |
|---|
| 190 | + DRM_DEV_ERROR(dev->dev, |
|---|
| 191 | + "failed to set up hw configuration.\n"); |
|---|
| 222 | 192 | goto err_setup; |
|---|
| 223 | 193 | } |
|---|
| 224 | 194 | |
|---|
| .. | .. |
|---|
| 237 | 207 | static void exynos_drm_fbdev_destroy(struct drm_device *dev, |
|---|
| 238 | 208 | struct drm_fb_helper *fb_helper) |
|---|
| 239 | 209 | { |
|---|
| 240 | | - struct exynos_drm_fbdev *exynos_fbd = to_exynos_fbdev(fb_helper); |
|---|
| 241 | | - struct exynos_drm_gem *exynos_gem = exynos_fbd->exynos_gem; |
|---|
| 242 | 210 | struct drm_framebuffer *fb; |
|---|
| 243 | | - |
|---|
| 244 | | - vunmap(exynos_gem->kvaddr); |
|---|
| 245 | 211 | |
|---|
| 246 | 212 | /* release drm framebuffer and real buffer */ |
|---|
| 247 | 213 | if (fb_helper->fb && fb_helper->fb->funcs) { |
|---|
| .. | .. |
|---|
| 270 | 236 | private->fb_helper = NULL; |
|---|
| 271 | 237 | } |
|---|
| 272 | 238 | |
|---|
| 273 | | -void exynos_drm_fbdev_suspend(struct drm_device *dev) |
|---|
| 274 | | -{ |
|---|
| 275 | | - struct exynos_drm_private *private = dev->dev_private; |
|---|
| 276 | | - |
|---|
| 277 | | - console_lock(); |
|---|
| 278 | | - drm_fb_helper_set_suspend(private->fb_helper, 1); |
|---|
| 279 | | - console_unlock(); |
|---|
| 280 | | -} |
|---|
| 281 | | - |
|---|
| 282 | | -void exynos_drm_fbdev_resume(struct drm_device *dev) |
|---|
| 283 | | -{ |
|---|
| 284 | | - struct exynos_drm_private *private = dev->dev_private; |
|---|
| 285 | | - |
|---|
| 286 | | - console_lock(); |
|---|
| 287 | | - drm_fb_helper_set_suspend(private->fb_helper, 0); |
|---|
| 288 | | - console_unlock(); |
|---|
| 289 | | -} |
|---|