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