Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 1 | /* |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 2 | * Copyright (C) 2012-2013 Avionic Design GmbH |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 3 | * Copyright (C) 2012 NVIDIA CORPORATION. All rights reserved. |
| 4 | * |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 5 | * Based on the KMS/FB CMA helpers |
| 6 | * Copyright (C) 2012 Analog Device Inc. |
| 7 | * |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | */ |
| 12 | |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 13 | #include "drm.h" |
| 14 | #include "gem.h" |
| 15 | |
| 16 | static inline struct tegra_fb *to_tegra_fb(struct drm_framebuffer *fb) |
| 17 | { |
| 18 | return container_of(fb, struct tegra_fb, base); |
| 19 | } |
| 20 | |
Thierry Reding | 60c2f70 | 2013-10-31 13:28:50 +0100 | [diff] [blame] | 21 | #ifdef CONFIG_DRM_TEGRA_FBDEV |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 22 | static inline struct tegra_fbdev *to_tegra_fbdev(struct drm_fb_helper *helper) |
| 23 | { |
| 24 | return container_of(helper, struct tegra_fbdev, base); |
| 25 | } |
Thierry Reding | 60c2f70 | 2013-10-31 13:28:50 +0100 | [diff] [blame] | 26 | #endif |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 27 | |
| 28 | struct tegra_bo *tegra_fb_get_plane(struct drm_framebuffer *framebuffer, |
| 29 | unsigned int index) |
| 30 | { |
| 31 | struct tegra_fb *fb = to_tegra_fb(framebuffer); |
| 32 | |
| 33 | if (index >= drm_format_num_planes(framebuffer->pixel_format)) |
| 34 | return NULL; |
| 35 | |
| 36 | return fb->planes[index]; |
| 37 | } |
| 38 | |
Thierry Reding | db7fbdf | 2013-10-07 09:47:58 +0200 | [diff] [blame] | 39 | bool tegra_fb_is_bottom_up(struct drm_framebuffer *framebuffer) |
| 40 | { |
| 41 | struct tegra_fb *fb = to_tegra_fb(framebuffer); |
| 42 | |
| 43 | if (fb->planes[0]->flags & TEGRA_BO_BOTTOM_UP) |
| 44 | return true; |
| 45 | |
| 46 | return false; |
| 47 | } |
| 48 | |
Thierry Reding | c134f01 | 2014-06-03 14:48:12 +0200 | [diff] [blame] | 49 | int tegra_fb_get_tiling(struct drm_framebuffer *framebuffer, |
| 50 | struct tegra_bo_tiling *tiling) |
Thierry Reding | 773af77 | 2013-10-04 22:34:01 +0200 | [diff] [blame] | 51 | { |
| 52 | struct tegra_fb *fb = to_tegra_fb(framebuffer); |
| 53 | |
Thierry Reding | c134f01 | 2014-06-03 14:48:12 +0200 | [diff] [blame] | 54 | /* TODO: handle YUV formats? */ |
| 55 | *tiling = fb->planes[0]->tiling; |
Thierry Reding | 773af77 | 2013-10-04 22:34:01 +0200 | [diff] [blame] | 56 | |
Thierry Reding | c134f01 | 2014-06-03 14:48:12 +0200 | [diff] [blame] | 57 | return 0; |
Thierry Reding | 773af77 | 2013-10-04 22:34:01 +0200 | [diff] [blame] | 58 | } |
| 59 | |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 60 | static void tegra_fb_destroy(struct drm_framebuffer *framebuffer) |
| 61 | { |
| 62 | struct tegra_fb *fb = to_tegra_fb(framebuffer); |
| 63 | unsigned int i; |
| 64 | |
| 65 | for (i = 0; i < fb->num_planes; i++) { |
| 66 | struct tegra_bo *bo = fb->planes[i]; |
| 67 | |
Thierry Reding | df06b75 | 2014-06-26 21:41:53 +0200 | [diff] [blame] | 68 | if (bo) { |
| 69 | if (bo->pages && bo->vaddr) |
| 70 | vunmap(bo->vaddr); |
| 71 | |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 72 | drm_gem_object_unreference_unlocked(&bo->gem); |
Thierry Reding | df06b75 | 2014-06-26 21:41:53 +0200 | [diff] [blame] | 73 | } |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | drm_framebuffer_cleanup(framebuffer); |
| 77 | kfree(fb->planes); |
| 78 | kfree(fb); |
| 79 | } |
| 80 | |
| 81 | static int tegra_fb_create_handle(struct drm_framebuffer *framebuffer, |
| 82 | struct drm_file *file, unsigned int *handle) |
| 83 | { |
| 84 | struct tegra_fb *fb = to_tegra_fb(framebuffer); |
| 85 | |
| 86 | return drm_gem_handle_create(file, &fb->planes[0]->gem, handle); |
| 87 | } |
| 88 | |
| 89 | static struct drm_framebuffer_funcs tegra_fb_funcs = { |
| 90 | .destroy = tegra_fb_destroy, |
| 91 | .create_handle = tegra_fb_create_handle, |
| 92 | }; |
| 93 | |
| 94 | static struct tegra_fb *tegra_fb_alloc(struct drm_device *drm, |
| 95 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 96 | struct tegra_bo **planes, |
| 97 | unsigned int num_planes) |
| 98 | { |
| 99 | struct tegra_fb *fb; |
| 100 | unsigned int i; |
| 101 | int err; |
| 102 | |
| 103 | fb = kzalloc(sizeof(*fb), GFP_KERNEL); |
| 104 | if (!fb) |
| 105 | return ERR_PTR(-ENOMEM); |
| 106 | |
| 107 | fb->planes = kzalloc(num_planes * sizeof(*planes), GFP_KERNEL); |
Dan Carpenter | 6b7c79d | 2013-11-12 13:25:26 +0300 | [diff] [blame] | 108 | if (!fb->planes) { |
| 109 | kfree(fb); |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 110 | return ERR_PTR(-ENOMEM); |
Dan Carpenter | 6b7c79d | 2013-11-12 13:25:26 +0300 | [diff] [blame] | 111 | } |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 112 | |
| 113 | fb->num_planes = num_planes; |
| 114 | |
| 115 | drm_helper_mode_fill_fb_struct(&fb->base, mode_cmd); |
| 116 | |
| 117 | for (i = 0; i < fb->num_planes; i++) |
| 118 | fb->planes[i] = planes[i]; |
| 119 | |
| 120 | err = drm_framebuffer_init(drm, &fb->base, &tegra_fb_funcs); |
| 121 | if (err < 0) { |
| 122 | dev_err(drm->dev, "failed to initialize framebuffer: %d\n", |
| 123 | err); |
| 124 | kfree(fb->planes); |
| 125 | kfree(fb); |
| 126 | return ERR_PTR(err); |
| 127 | } |
| 128 | |
| 129 | return fb; |
| 130 | } |
| 131 | |
Thierry Reding | f991421 | 2014-11-26 13:03:57 +0100 | [diff] [blame] | 132 | struct drm_framebuffer *tegra_fb_create(struct drm_device *drm, |
| 133 | struct drm_file *file, |
| 134 | struct drm_mode_fb_cmd2 *cmd) |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 135 | { |
| 136 | unsigned int hsub, vsub, i; |
| 137 | struct tegra_bo *planes[4]; |
| 138 | struct drm_gem_object *gem; |
| 139 | struct tegra_fb *fb; |
| 140 | int err; |
| 141 | |
| 142 | hsub = drm_format_horz_chroma_subsampling(cmd->pixel_format); |
| 143 | vsub = drm_format_vert_chroma_subsampling(cmd->pixel_format); |
| 144 | |
| 145 | for (i = 0; i < drm_format_num_planes(cmd->pixel_format); i++) { |
| 146 | unsigned int width = cmd->width / (i ? hsub : 1); |
| 147 | unsigned int height = cmd->height / (i ? vsub : 1); |
| 148 | unsigned int size, bpp; |
| 149 | |
| 150 | gem = drm_gem_object_lookup(drm, file, cmd->handles[i]); |
| 151 | if (!gem) { |
| 152 | err = -ENXIO; |
| 153 | goto unreference; |
| 154 | } |
| 155 | |
| 156 | bpp = drm_format_plane_cpp(cmd->pixel_format, i); |
| 157 | |
| 158 | size = (height - 1) * cmd->pitches[i] + |
| 159 | width * bpp + cmd->offsets[i]; |
| 160 | |
| 161 | if (gem->size < size) { |
| 162 | err = -EINVAL; |
| 163 | goto unreference; |
| 164 | } |
| 165 | |
| 166 | planes[i] = to_tegra_bo(gem); |
| 167 | } |
| 168 | |
| 169 | fb = tegra_fb_alloc(drm, cmd, planes, i); |
| 170 | if (IS_ERR(fb)) { |
| 171 | err = PTR_ERR(fb); |
| 172 | goto unreference; |
| 173 | } |
| 174 | |
| 175 | return &fb->base; |
| 176 | |
| 177 | unreference: |
| 178 | while (i--) |
| 179 | drm_gem_object_unreference_unlocked(&planes[i]->gem); |
| 180 | |
| 181 | return ERR_PTR(err); |
| 182 | } |
| 183 | |
Thierry Reding | 60c2f70 | 2013-10-31 13:28:50 +0100 | [diff] [blame] | 184 | #ifdef CONFIG_DRM_TEGRA_FBDEV |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 185 | static struct fb_ops tegra_fb_ops = { |
| 186 | .owner = THIS_MODULE, |
| 187 | .fb_fillrect = sys_fillrect, |
| 188 | .fb_copyarea = sys_copyarea, |
| 189 | .fb_imageblit = sys_imageblit, |
| 190 | .fb_check_var = drm_fb_helper_check_var, |
| 191 | .fb_set_par = drm_fb_helper_set_par, |
| 192 | .fb_blank = drm_fb_helper_blank, |
| 193 | .fb_pan_display = drm_fb_helper_pan_display, |
| 194 | .fb_setcmap = drm_fb_helper_setcmap, |
| 195 | }; |
| 196 | |
| 197 | static int tegra_fbdev_probe(struct drm_fb_helper *helper, |
| 198 | struct drm_fb_helper_surface_size *sizes) |
| 199 | { |
| 200 | struct tegra_fbdev *fbdev = to_tegra_fbdev(helper); |
Thierry Reding | d1f3e1e | 2014-07-11 08:29:14 +0200 | [diff] [blame] | 201 | struct tegra_drm *tegra = helper->dev->dev_private; |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 202 | struct drm_device *drm = helper->dev; |
| 203 | struct drm_mode_fb_cmd2 cmd = { 0 }; |
| 204 | unsigned int bytes_per_pixel; |
| 205 | struct drm_framebuffer *fb; |
| 206 | unsigned long offset; |
| 207 | struct fb_info *info; |
| 208 | struct tegra_bo *bo; |
| 209 | size_t size; |
| 210 | int err; |
| 211 | |
| 212 | bytes_per_pixel = DIV_ROUND_UP(sizes->surface_bpp, 8); |
| 213 | |
| 214 | cmd.width = sizes->surface_width; |
| 215 | cmd.height = sizes->surface_height; |
Thierry Reding | d1f3e1e | 2014-07-11 08:29:14 +0200 | [diff] [blame] | 216 | cmd.pitches[0] = round_up(sizes->surface_width * bytes_per_pixel, |
| 217 | tegra->pitch_align); |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 218 | cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp, |
| 219 | sizes->surface_depth); |
| 220 | |
| 221 | size = cmd.pitches[0] * cmd.height; |
| 222 | |
Thierry Reding | 773af77 | 2013-10-04 22:34:01 +0200 | [diff] [blame] | 223 | bo = tegra_bo_create(drm, size, 0); |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 224 | if (IS_ERR(bo)) |
| 225 | return PTR_ERR(bo); |
| 226 | |
| 227 | info = framebuffer_alloc(0, drm->dev); |
| 228 | if (!info) { |
| 229 | dev_err(drm->dev, "failed to allocate framebuffer info\n"); |
Thierry Reding | b88f005 | 2014-11-06 14:33:19 +0100 | [diff] [blame] | 230 | drm_gem_object_unreference_unlocked(&bo->gem); |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 231 | return -ENOMEM; |
| 232 | } |
| 233 | |
| 234 | fbdev->fb = tegra_fb_alloc(drm, &cmd, &bo, 1); |
| 235 | if (IS_ERR(fbdev->fb)) { |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 236 | err = PTR_ERR(fbdev->fb); |
Thierry Reding | cb10c81 | 2014-11-06 14:36:19 +0100 | [diff] [blame] | 237 | dev_err(drm->dev, "failed to allocate DRM framebuffer: %d\n", |
| 238 | err); |
Thierry Reding | b88f005 | 2014-11-06 14:33:19 +0100 | [diff] [blame] | 239 | drm_gem_object_unreference_unlocked(&bo->gem); |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 240 | goto release; |
| 241 | } |
| 242 | |
| 243 | fb = &fbdev->fb->base; |
| 244 | helper->fb = fb; |
| 245 | helper->fbdev = info; |
| 246 | |
| 247 | info->par = helper; |
| 248 | info->flags = FBINFO_FLAG_DEFAULT; |
| 249 | info->fbops = &tegra_fb_ops; |
| 250 | |
| 251 | err = fb_alloc_cmap(&info->cmap, 256, 0); |
| 252 | if (err < 0) { |
| 253 | dev_err(drm->dev, "failed to allocate color map: %d\n", err); |
| 254 | goto destroy; |
| 255 | } |
| 256 | |
| 257 | drm_fb_helper_fill_fix(info, fb->pitches[0], fb->depth); |
| 258 | drm_fb_helper_fill_var(info, helper, fb->width, fb->height); |
| 259 | |
| 260 | offset = info->var.xoffset * bytes_per_pixel + |
| 261 | info->var.yoffset * fb->pitches[0]; |
| 262 | |
Thierry Reding | df06b75 | 2014-06-26 21:41:53 +0200 | [diff] [blame] | 263 | if (bo->pages) { |
| 264 | bo->vaddr = vmap(bo->pages, bo->num_pages, VM_MAP, |
| 265 | pgprot_writecombine(PAGE_KERNEL)); |
| 266 | if (!bo->vaddr) { |
| 267 | dev_err(drm->dev, "failed to vmap() framebuffer\n"); |
| 268 | err = -ENOMEM; |
| 269 | goto destroy; |
| 270 | } |
| 271 | } |
| 272 | |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 273 | drm->mode_config.fb_base = (resource_size_t)bo->paddr; |
Thierry Reding | 9ab3415 | 2013-11-08 13:18:14 +0100 | [diff] [blame] | 274 | info->screen_base = (void __iomem *)bo->vaddr + offset; |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 275 | info->screen_size = size; |
| 276 | info->fix.smem_start = (unsigned long)(bo->paddr + offset); |
| 277 | info->fix.smem_len = size; |
| 278 | |
| 279 | return 0; |
| 280 | |
| 281 | destroy: |
| 282 | drm_framebuffer_unregister_private(fb); |
| 283 | tegra_fb_destroy(fb); |
| 284 | release: |
| 285 | framebuffer_release(info); |
| 286 | return err; |
| 287 | } |
| 288 | |
Thierry Reding | 3a49387 | 2014-06-27 17:19:23 +0200 | [diff] [blame] | 289 | static const struct drm_fb_helper_funcs tegra_fb_helper_funcs = { |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 290 | .fb_probe = tegra_fbdev_probe, |
| 291 | }; |
| 292 | |
Thierry Reding | e221532 | 2014-06-27 17:19:25 +0200 | [diff] [blame] | 293 | static struct tegra_fbdev *tegra_fbdev_create(struct drm_device *drm) |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 294 | { |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 295 | struct tegra_fbdev *fbdev; |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 296 | |
| 297 | fbdev = kzalloc(sizeof(*fbdev), GFP_KERNEL); |
| 298 | if (!fbdev) { |
| 299 | dev_err(drm->dev, "failed to allocate DRM fbdev\n"); |
| 300 | return ERR_PTR(-ENOMEM); |
| 301 | } |
| 302 | |
Thierry Reding | 10a2310 | 2014-06-27 17:19:24 +0200 | [diff] [blame] | 303 | drm_fb_helper_prepare(drm, &fbdev->base, &tegra_fb_helper_funcs); |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 304 | |
Thierry Reding | e221532 | 2014-06-27 17:19:25 +0200 | [diff] [blame] | 305 | return fbdev; |
| 306 | } |
| 307 | |
Thierry Reding | 1d1e6fe | 2014-11-06 14:12:08 +0100 | [diff] [blame] | 308 | static void tegra_fbdev_free(struct tegra_fbdev *fbdev) |
| 309 | { |
| 310 | kfree(fbdev); |
| 311 | } |
| 312 | |
Thierry Reding | e221532 | 2014-06-27 17:19:25 +0200 | [diff] [blame] | 313 | static int tegra_fbdev_init(struct tegra_fbdev *fbdev, |
| 314 | unsigned int preferred_bpp, |
| 315 | unsigned int num_crtc, |
| 316 | unsigned int max_connectors) |
| 317 | { |
| 318 | struct drm_device *drm = fbdev->base.dev; |
| 319 | int err; |
| 320 | |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 321 | err = drm_fb_helper_init(drm, &fbdev->base, num_crtc, max_connectors); |
| 322 | if (err < 0) { |
Thierry Reding | cb10c81 | 2014-11-06 14:36:19 +0100 | [diff] [blame] | 323 | dev_err(drm->dev, "failed to initialize DRM FB helper: %d\n", |
| 324 | err); |
Thierry Reding | e221532 | 2014-06-27 17:19:25 +0200 | [diff] [blame] | 325 | return err; |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | err = drm_fb_helper_single_add_all_connectors(&fbdev->base); |
| 329 | if (err < 0) { |
Thierry Reding | cb10c81 | 2014-11-06 14:36:19 +0100 | [diff] [blame] | 330 | dev_err(drm->dev, "failed to add connectors: %d\n", err); |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 331 | goto fini; |
| 332 | } |
| 333 | |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 334 | err = drm_fb_helper_initial_config(&fbdev->base, preferred_bpp); |
| 335 | if (err < 0) { |
Thierry Reding | cb10c81 | 2014-11-06 14:36:19 +0100 | [diff] [blame] | 336 | dev_err(drm->dev, "failed to set initial configuration: %d\n", |
| 337 | err); |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 338 | goto fini; |
| 339 | } |
| 340 | |
Thierry Reding | e221532 | 2014-06-27 17:19:25 +0200 | [diff] [blame] | 341 | return 0; |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 342 | |
| 343 | fini: |
| 344 | drm_fb_helper_fini(&fbdev->base); |
Thierry Reding | e221532 | 2014-06-27 17:19:25 +0200 | [diff] [blame] | 345 | return err; |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 346 | } |
| 347 | |
Thierry Reding | 1d1e6fe | 2014-11-06 14:12:08 +0100 | [diff] [blame] | 348 | static void tegra_fbdev_exit(struct tegra_fbdev *fbdev) |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 349 | { |
| 350 | struct fb_info *info = fbdev->base.fbdev; |
| 351 | |
| 352 | if (info) { |
| 353 | int err; |
| 354 | |
| 355 | err = unregister_framebuffer(info); |
| 356 | if (err < 0) |
| 357 | DRM_DEBUG_KMS("failed to unregister framebuffer\n"); |
| 358 | |
| 359 | if (info->cmap.len) |
| 360 | fb_dealloc_cmap(&info->cmap); |
| 361 | |
| 362 | framebuffer_release(info); |
| 363 | } |
| 364 | |
| 365 | if (fbdev->fb) { |
| 366 | drm_framebuffer_unregister_private(&fbdev->fb->base); |
Thierry Reding | 3feaf3e | 2014-10-21 13:56:59 +0200 | [diff] [blame] | 367 | drm_framebuffer_remove(&fbdev->fb->base); |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | drm_fb_helper_fini(&fbdev->base); |
Thierry Reding | 1d1e6fe | 2014-11-06 14:12:08 +0100 | [diff] [blame] | 371 | tegra_fbdev_free(fbdev); |
Arto Merilainen | de2ba66 | 2013-03-22 16:34:08 +0200 | [diff] [blame] | 372 | } |
| 373 | |
Thierry Reding | 60c2f70 | 2013-10-31 13:28:50 +0100 | [diff] [blame] | 374 | void tegra_fbdev_restore_mode(struct tegra_fbdev *fbdev) |
| 375 | { |
Rob Clark | 5ea1f75 | 2014-05-30 12:29:48 -0400 | [diff] [blame] | 376 | if (fbdev) |
| 377 | drm_fb_helper_restore_fbdev_mode_unlocked(&fbdev->base); |
Thierry Reding | 60c2f70 | 2013-10-31 13:28:50 +0100 | [diff] [blame] | 378 | } |
| 379 | |
Thierry Reding | f991421 | 2014-11-26 13:03:57 +0100 | [diff] [blame] | 380 | void tegra_fb_output_poll_changed(struct drm_device *drm) |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 381 | { |
Thierry Reding | 386a2a7 | 2013-09-24 13:22:17 +0200 | [diff] [blame] | 382 | struct tegra_drm *tegra = drm->dev_private; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 383 | |
Thierry Reding | 386a2a7 | 2013-09-24 13:22:17 +0200 | [diff] [blame] | 384 | if (tegra->fbdev) |
| 385 | drm_fb_helper_hotplug_event(&tegra->fbdev->base); |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 386 | } |
Thierry Reding | 60c2f70 | 2013-10-31 13:28:50 +0100 | [diff] [blame] | 387 | #endif |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 388 | |
Thierry Reding | e221532 | 2014-06-27 17:19:25 +0200 | [diff] [blame] | 389 | int tegra_drm_fb_prepare(struct drm_device *drm) |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 390 | { |
Thierry Reding | 60c2f70 | 2013-10-31 13:28:50 +0100 | [diff] [blame] | 391 | #ifdef CONFIG_DRM_TEGRA_FBDEV |
Thierry Reding | 386a2a7 | 2013-09-24 13:22:17 +0200 | [diff] [blame] | 392 | struct tegra_drm *tegra = drm->dev_private; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 393 | |
Thierry Reding | e221532 | 2014-06-27 17:19:25 +0200 | [diff] [blame] | 394 | tegra->fbdev = tegra_fbdev_create(drm); |
Thierry Reding | 60c2f70 | 2013-10-31 13:28:50 +0100 | [diff] [blame] | 395 | if (IS_ERR(tegra->fbdev)) |
| 396 | return PTR_ERR(tegra->fbdev); |
| 397 | #endif |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 398 | |
| 399 | return 0; |
| 400 | } |
| 401 | |
Thierry Reding | 1d1e6fe | 2014-11-06 14:12:08 +0100 | [diff] [blame] | 402 | void tegra_drm_fb_free(struct drm_device *drm) |
| 403 | { |
| 404 | #ifdef CONFIG_DRM_TEGRA_FBDEV |
| 405 | struct tegra_drm *tegra = drm->dev_private; |
| 406 | |
| 407 | tegra_fbdev_free(tegra->fbdev); |
| 408 | #endif |
| 409 | } |
| 410 | |
Thierry Reding | e221532 | 2014-06-27 17:19:25 +0200 | [diff] [blame] | 411 | int tegra_drm_fb_init(struct drm_device *drm) |
| 412 | { |
| 413 | #ifdef CONFIG_DRM_TEGRA_FBDEV |
| 414 | struct tegra_drm *tegra = drm->dev_private; |
| 415 | int err; |
| 416 | |
| 417 | err = tegra_fbdev_init(tegra->fbdev, 32, drm->mode_config.num_crtc, |
| 418 | drm->mode_config.num_connector); |
| 419 | if (err < 0) |
| 420 | return err; |
| 421 | #endif |
| 422 | |
| 423 | return 0; |
| 424 | } |
| 425 | |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 426 | void tegra_drm_fb_exit(struct drm_device *drm) |
| 427 | { |
Thierry Reding | 60c2f70 | 2013-10-31 13:28:50 +0100 | [diff] [blame] | 428 | #ifdef CONFIG_DRM_TEGRA_FBDEV |
Thierry Reding | 386a2a7 | 2013-09-24 13:22:17 +0200 | [diff] [blame] | 429 | struct tegra_drm *tegra = drm->dev_private; |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 430 | |
Thierry Reding | 1d1e6fe | 2014-11-06 14:12:08 +0100 | [diff] [blame] | 431 | tegra_fbdev_exit(tegra->fbdev); |
Thierry Reding | 60c2f70 | 2013-10-31 13:28:50 +0100 | [diff] [blame] | 432 | #endif |
Thierry Reding | d8f4a9e | 2012-11-15 21:28:22 +0000 | [diff] [blame] | 433 | } |