video: tegra: update overlay stride in fb_set_par
[linux-2.6.git] / drivers / video / tegra / fb.c
1 /*
2  * drivers/video/tegra/fb.c
3  *
4  * Copyright (C) 2010 Google, Inc.
5  * Author: Erik Gilling <konkers@android.com>
6  *         Colin Cross <ccross@android.com>
7  *         Travis Geiselbrecht <travis@palm.com>
8  *
9  * This software is licensed under the terms of the GNU General Public
10  * License version 2, as published by the Free Software Foundation, and
11  * may be copied, distributed, and modified under those terms.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  */
19
20 #include <linux/fb.h>
21 #include <linux/module.h>
22 #include <linux/kernel.h>
23 #include <linux/errno.h>
24 #include <linux/string.h>
25 #include <linux/mm.h>
26 #include <linux/uaccess.h>
27 #include <linux/slab.h>
28 #include <linux/file.h>
29 #include <linux/workqueue.h>
30
31 #include <asm/atomic.h>
32
33 #include <video/tegrafb.h>
34
35 #include <mach/dc.h>
36 #include <mach/fb.h>
37 #include <mach/nvhost.h>
38 #include <mach/nvmap.h>
39
40 #include "host/dev.h"
41 #include "nvmap/nvmap.h"
42
43 struct tegra_fb_info {
44         struct tegra_dc_win     *win;
45         struct nvhost_device    *ndev;
46         struct fb_info          *info;
47         bool                    valid;
48
49         struct resource         *fb_mem;
50
51         int                     xres;
52         int                     yres;
53
54         atomic_t                in_use;
55         struct nvmap_client     *user_nvmap;
56         struct nvmap_client     *fb_nvmap;
57
58         struct workqueue_struct *flip_wq;
59 };
60
61 struct tegra_fb_flip_win {
62         struct tegra_fb_windowattr      attr;
63         struct nvmap_handle_ref         *handle;
64         dma_addr_t                      phys_addr;
65 };
66
67 struct tegra_fb_flip_data {
68         struct work_struct              work;
69         struct tegra_fb_info            *fb;
70         struct tegra_fb_flip_win        win[TEGRA_FB_FLIP_N_WINDOWS];
71         u32                             syncpt_max;
72 };
73
74 /* palette array used by the fbcon */
75 static u32 pseudo_palette[16];
76
77 static int tegra_fb_open(struct fb_info *info, int user)
78 {
79         struct tegra_fb_info *tegra_fb = info->par;
80
81         if (atomic_xchg(&tegra_fb->in_use, 1))
82                 return -EBUSY;
83
84         tegra_fb->user_nvmap = NULL;
85
86         return 0;
87 }
88
89 static int tegra_fb_release(struct fb_info *info, int user)
90 {
91         struct tegra_fb_info *tegra_fb = info->par;
92
93         flush_workqueue(tegra_fb->flip_wq);
94
95         if (tegra_fb->user_nvmap) {
96                 nvmap_client_put(tegra_fb->user_nvmap);
97                 tegra_fb->user_nvmap = NULL;
98         }
99
100         WARN_ON(!atomic_xchg(&tegra_fb->in_use, 0));
101
102         return 0;
103 }
104
105 static int tegra_fb_check_var(struct fb_var_screeninfo *var,
106                               struct fb_info *info)
107 {
108         if ((var->yres * var->xres * var->bits_per_pixel / 8 * 2) >
109             info->screen_size)
110                 return -EINVAL;
111
112         /* double yres_virtual to allow double buffering through pan_display */
113         var->yres_virtual = var->yres * 2;
114
115         return 0;
116 }
117
118 static int tegra_fb_set_par(struct fb_info *info)
119 {
120         struct tegra_fb_info *tegra_fb = info->par;
121         struct fb_var_screeninfo *var = &info->var;
122
123         /* we only support RGB ordering for now */
124         switch (var->bits_per_pixel) {
125         case 32:
126         case 24:
127                 var->red.offset = 0;
128                 var->red.length = 8;
129                 var->green.offset = 8;
130                 var->green.length = 8;
131                 var->blue.offset = 16;
132                 var->blue.length = 8;
133                 tegra_fb->win->fmt = TEGRA_WIN_FMT_R8G8B8A8;
134                 break;
135         case 16:
136                 var->red.offset = 11;
137                 var->red.length = 5;
138                 var->green.offset = 5;
139                 var->green.length = 6;
140                 var->blue.offset = 0;
141                 var->blue.length = 5;
142                 tegra_fb->win->fmt = TEGRA_WIN_FMT_B5G6R5;
143                 break;
144
145         case 0:
146                 break;
147
148         default:
149                 return -EINVAL;
150         }
151         info->fix.line_length = var->xres * var->bits_per_pixel / 8;
152         tegra_fb->win->stride = info->fix.line_length;
153
154         if (var->pixclock) {
155                 struct tegra_dc_mode mode;
156
157                 info->mode = (struct fb_videomode *)
158                         fb_find_best_mode(var, &info->modelist);
159                 if (!info->mode) {
160                         dev_warn(&tegra_fb->ndev->dev, "can't match video mode\n");
161                         return -EINVAL;
162                 }
163
164                 mode.pclk = PICOS2KHZ(info->mode->pixclock) * 1000;
165                 mode.h_ref_to_sync = 1;
166                 mode.v_ref_to_sync = 1;
167                 mode.h_sync_width = info->mode->hsync_len;
168                 mode.v_sync_width = info->mode->vsync_len;
169                 mode.h_back_porch = info->mode->left_margin;
170                 mode.v_back_porch = info->mode->upper_margin;
171                 mode.h_active = info->mode->xres;
172                 mode.v_active = info->mode->yres;
173                 mode.h_front_porch = info->mode->right_margin;
174                 mode.v_front_porch = info->mode->lower_margin;
175
176                 tegra_dc_set_mode(tegra_fb->win->dc, &mode);
177
178                 tegra_fb->win->w = info->mode->xres;
179                 tegra_fb->win->h = info->mode->xres;
180                 tegra_fb->win->out_w = info->mode->xres;
181                 tegra_fb->win->out_h = info->mode->xres;
182         }
183         return 0;
184 }
185
186 static int tegra_fb_setcolreg(unsigned regno, unsigned red, unsigned green,
187         unsigned blue, unsigned transp, struct fb_info *info)
188 {
189         struct fb_var_screeninfo *var = &info->var;
190
191         if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
192             info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
193                 u32 v;
194
195                 if (regno >= 16)
196                         return -EINVAL;
197
198                 v = (red << var->red.offset) |
199                         (green << var->green.offset) |
200                         (blue << var->blue.offset);
201
202                 ((u32 *)info->pseudo_palette)[regno] = v;
203         }
204
205         return 0;
206 }
207
208 static int tegra_fb_blank(int blank, struct fb_info *info)
209 {
210         struct tegra_fb_info *tegra_fb = info->par;
211
212         switch (blank) {
213         case FB_BLANK_UNBLANK:
214                 dev_dbg(&tegra_fb->ndev->dev, "unblank\n");
215                 tegra_dc_enable(tegra_fb->win->dc);
216                 return 0;
217
218         case FB_BLANK_POWERDOWN:
219                 dev_dbg(&tegra_fb->ndev->dev, "blank\n");
220                 tegra_dc_disable(tegra_fb->win->dc);
221                 return 0;
222
223         default:
224                 return -ENOTTY;
225         }
226 }
227
228 static int tegra_fb_pan_display(struct fb_var_screeninfo *var,
229                                 struct fb_info *info)
230 {
231         struct tegra_fb_info *tegra_fb = info->par;
232         char __iomem *flush_start;
233         char __iomem *flush_end;
234         u32 addr;
235
236         flush_start = info->screen_base + (var->yoffset * info->fix.line_length);
237         flush_end = flush_start + (var->yres * info->fix.line_length);
238
239         info->var.xoffset = var->xoffset;
240         info->var.yoffset = var->yoffset;
241
242         addr = info->fix.smem_start + (var->yoffset * info->fix.line_length) +
243                 (var->xoffset * (var->bits_per_pixel/8));
244
245         tegra_fb->win->phys_addr = addr;
246         /* TODO: update virt_addr */
247
248         tegra_dc_update_windows(&tegra_fb->win, 1);
249         tegra_dc_sync_windows(&tegra_fb->win, 1);
250
251         if (WARN_ON(tegra_fb->win->cur_handle)) {
252                 nvmap_unpin(tegra_fb->fb_nvmap, tegra_fb->win->cur_handle);
253                 nvmap_free(tegra_fb->fb_nvmap, tegra_fb->win->cur_handle);
254                 tegra_fb->win->cur_handle = NULL;
255         }
256
257         return 0;
258 }
259
260 static void tegra_fb_fillrect(struct fb_info *info,
261                               const struct fb_fillrect *rect)
262 {
263         cfb_fillrect(info, rect);
264 }
265
266 static void tegra_fb_copyarea(struct fb_info *info,
267                               const struct fb_copyarea *region)
268 {
269         cfb_copyarea(info, region);
270 }
271
272 static void tegra_fb_imageblit(struct fb_info *info,
273                                const struct fb_image *image)
274 {
275         cfb_imageblit(info, image);
276 }
277
278 /* TODO: implement ALLOC, FREE, BLANK ioctls */
279
280 static int tegra_fb_set_nvmap_fd(struct tegra_fb_info *tegra_fb, int fd)
281 {
282         struct nvmap_client *nvmap = NULL;
283
284         if (fd < 0)
285                 return -EINVAL;
286
287         nvmap = nvmap_client_get_file(fd);
288         if (IS_ERR(nvmap))
289                 return PTR_ERR(nvmap);
290
291         if (tegra_fb->user_nvmap)
292                 nvmap_client_put(tegra_fb->user_nvmap);
293
294         tegra_fb->user_nvmap = nvmap;
295
296         return 0;
297 }
298
299 static int tegra_fb_pin_window(struct tegra_fb_info *tegra_fb,
300                                struct tegra_fb_flip_win *flip_win)
301 {
302         struct nvmap_handle_ref *win_dupe;
303         struct nvmap_handle *win_handle;
304         unsigned long buff_id = flip_win->attr.buff_id;
305
306         if (!buff_id)
307                 return 0;
308
309         win_handle = nvmap_get_handle_id(tegra_fb->user_nvmap, buff_id);
310         if (win_handle == NULL) {
311                 dev_err(&tegra_fb->ndev->dev, "%s: flip invalid "
312                         "handle %08lx\n", current->comm, buff_id);
313                 return -EPERM;
314         }
315
316         /* duplicate the new framebuffer's handle into the fb driver's
317          * nvmap context, to ensure that the handle won't be freed as
318          * long as it is in-use by the fb driver */
319         win_dupe = nvmap_duplicate_handle_id(tegra_fb->fb_nvmap, buff_id);
320         nvmap_handle_put(win_handle);
321
322         if (IS_ERR(win_dupe)) {
323                 dev_err(&tegra_fb->ndev->dev, "couldn't duplicate handle\n");
324                 return PTR_ERR(win_dupe);
325         }
326
327         flip_win->handle = win_dupe;
328
329         flip_win->phys_addr = nvmap_pin(tegra_fb->fb_nvmap, win_dupe);
330         if (IS_ERR((void *)flip_win->phys_addr)) {
331                 dev_err(&tegra_fb->ndev->dev, "couldn't pin handle\n");
332                 nvmap_free(tegra_fb->fb_nvmap, win_dupe);
333                 return PTR_ERR((void *)flip_win->phys_addr);
334         }
335
336         return 0;
337 }
338
339 static int tegra_fb_set_windowattr(struct tegra_fb_info *tegra_fb,
340                                    struct tegra_dc_win *win,
341                                    const struct tegra_fb_flip_win *flip_win)
342 {
343         if (flip_win->handle == NULL) {
344                 win->flags = 0;
345                 return 0;
346         }
347
348         win->flags = TEGRA_WIN_FLAG_ENABLED;
349         if (flip_win->attr.blend == TEGRA_FB_WIN_BLEND_PREMULT)
350                 win->flags |= TEGRA_WIN_FLAG_BLEND_PREMULT;
351         else if (flip_win->attr.blend == TEGRA_FB_WIN_BLEND_COVERAGE)
352                 win->flags |= TEGRA_WIN_FLAG_BLEND_COVERAGE;
353         win->fmt = flip_win->attr.pixformat;
354         win->x = flip_win->attr.x;
355         win->y = flip_win->attr.y;
356         win->w = flip_win->attr.w;
357         win->h = flip_win->attr.h;
358         win->out_x = flip_win->attr.out_x;
359         win->out_y = flip_win->attr.out_y;
360         win->out_w = flip_win->attr.out_w;
361         win->out_h = flip_win->attr.out_h;
362         win->z = flip_win->attr.z;
363         win->cur_handle = flip_win->handle;
364
365         /* STOPSHIP verify that this won't read outside of the surface */
366         win->phys_addr = flip_win->phys_addr + flip_win->attr.offset;
367         win->stride = flip_win->attr.stride;
368
369         if ((s32)flip_win->attr.pre_syncpt_id >= 0) {
370                 nvhost_syncpt_wait_timeout(&tegra_fb->ndev->host->syncpt,
371                                            flip_win->attr.pre_syncpt_id,
372                                            flip_win->attr.pre_syncpt_val,
373                                            msecs_to_jiffies(500));
374         }
375
376
377         return 0;
378 }
379
380 static void tegra_fb_flip_worker(struct work_struct *work)
381 {
382         struct tegra_fb_flip_data *data =
383                 container_of(work, struct tegra_fb_flip_data, work);
384         struct tegra_fb_info *tegra_fb = data->fb;
385         struct tegra_dc_win *win;
386         struct tegra_dc_win *wins[TEGRA_FB_FLIP_N_WINDOWS];
387         struct nvmap_handle_ref *unpin_handles[TEGRA_FB_FLIP_N_WINDOWS];
388         int i, nr_win = 0, nr_unpin = 0;
389
390         data = container_of(work, struct tegra_fb_flip_data, work);
391
392         for (i = 0; i < TEGRA_FB_FLIP_N_WINDOWS; i++) {
393                 struct tegra_fb_flip_win *flip_win = &data->win[i];
394                 int idx = flip_win->attr.index;
395                 win = tegra_dc_get_window(tegra_fb->win->dc, idx);
396
397                 if (!win)
398                         continue;
399
400                 if (win->flags && win->cur_handle)
401                         unpin_handles[nr_unpin++] = win->cur_handle;
402
403                 tegra_fb_set_windowattr(tegra_fb, win, &data->win[i]);
404
405                 wins[nr_win++] = win;
406
407 #if 0
408                 if (flip_win->attr.pre_syncpt_id < 0)
409                         continue;
410                 printk("%08x %08x\n",
411                        flip_win->attr.pre_syncpt_id,
412                        flip_win->attr.pre_syncpt_val);
413
414                 nvhost_syncpt_wait_timeout(&tegra_fb->ndev->host->syncpt,
415                                            flip_win->attr.pre_syncpt_id,
416                                            flip_win->attr.pre_syncpt_val,
417                                            msecs_to_jiffies(500));
418 #endif
419         }
420
421         tegra_dc_update_windows(wins, nr_win);
422         /* TODO: implement swapinterval here */
423         tegra_dc_sync_windows(wins, nr_win);
424
425         tegra_dc_incr_syncpt_min(tegra_fb->win->dc, data->syncpt_max);
426
427         /* unpin and deref previous front buffers */
428         for (i = 0; i < nr_unpin; i++) {
429                 nvmap_unpin(tegra_fb->fb_nvmap, unpin_handles[i]);
430                 nvmap_free(tegra_fb->fb_nvmap, unpin_handles[i]);
431         }
432
433         kfree(data);
434 }
435
436 static int tegra_fb_flip(struct tegra_fb_info *tegra_fb,
437                          struct tegra_fb_flip_args *args)
438 {
439         struct tegra_fb_flip_data *data;
440         struct tegra_fb_flip_win *flip_win;
441         u32 syncpt_max;
442         int i, err;
443
444         if (WARN_ON(!tegra_fb->user_nvmap))
445                 return -EFAULT;
446
447         if (WARN_ON(!tegra_fb->ndev))
448                 return -EFAULT;
449
450         data = kzalloc(sizeof(*data), GFP_KERNEL);
451         if (data == NULL) {
452                 dev_err(&tegra_fb->ndev->dev,
453                         "can't allocate memory for flip\n");
454                 return -ENOMEM;
455         }
456
457         INIT_WORK(&data->work, tegra_fb_flip_worker);
458         data->fb = tegra_fb;
459
460         for (i = 0; i < TEGRA_FB_FLIP_N_WINDOWS; i++) {
461                 flip_win = &data->win[i];
462
463                 memcpy(&flip_win->attr, &args->win[i], sizeof(flip_win->attr));
464
465                 err = tegra_fb_pin_window(tegra_fb, flip_win);
466                 if (err < 0) {
467                         dev_err(&tegra_fb->ndev->dev,
468                                 "error setting window attributes\n");
469                         goto surf_err;
470                 }
471         }
472
473         syncpt_max = tegra_dc_incr_syncpt_max(tegra_fb->win->dc);
474         data->syncpt_max = syncpt_max;
475
476         queue_work(tegra_fb->flip_wq, &data->work);
477
478         args->post_syncpt_val = syncpt_max;
479         args->post_syncpt_id = tegra_dc_get_syncpt_id(tegra_fb->win->dc);
480
481         return 0;
482
483 surf_err:
484         while (i--) {
485                 if (data->win[i].handle) {
486                         nvmap_unpin(tegra_fb->fb_nvmap,
487                                     data->win[i].handle);
488                         nvmap_free(tegra_fb->fb_nvmap,
489                                    data->win[i].handle);
490                 }
491         }
492         kfree(data);
493         return err;
494 }
495
496 /* TODO: implement private window ioctls to set overlay x,y */
497
498 static int tegra_fb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
499 {
500         struct tegra_fb_info *tegra_fb = info->par;
501         struct tegra_fb_flip_args flip_args;
502         int fd;
503         int ret;
504
505         switch (cmd) {
506         case FBIO_TEGRA_SET_NVMAP_FD:
507                 if (copy_from_user(&fd, (void __user *)arg, sizeof(fd)))
508                         return -EFAULT;
509
510                 return tegra_fb_set_nvmap_fd(tegra_fb, fd);
511
512         case FBIO_TEGRA_FLIP:
513                 if (copy_from_user(&flip_args, (void __user *)arg, sizeof(flip_args)))
514                         return -EFAULT;
515
516                 ret = tegra_fb_flip(tegra_fb, &flip_args);
517
518                 if (copy_to_user((void __user *)arg, &flip_args, sizeof(flip_args)))
519                         return -EFAULT;
520
521                 return ret;
522
523         default:
524                 return -ENOTTY;
525         }
526
527         return 0;
528 }
529
530 static struct fb_ops tegra_fb_ops = {
531         .owner = THIS_MODULE,
532         .fb_open = tegra_fb_open,
533         .fb_release = tegra_fb_release,
534         .fb_check_var = tegra_fb_check_var,
535         .fb_set_par = tegra_fb_set_par,
536         .fb_setcolreg = tegra_fb_setcolreg,
537         .fb_blank = tegra_fb_blank,
538         .fb_pan_display = tegra_fb_pan_display,
539         .fb_fillrect = tegra_fb_fillrect,
540         .fb_copyarea = tegra_fb_copyarea,
541         .fb_imageblit = tegra_fb_imageblit,
542         .fb_ioctl = tegra_fb_ioctl,
543 };
544
545 void tegra_fb_update_monspecs(struct tegra_fb_info *fb_info,
546                               struct fb_monspecs *specs,
547                               bool (*mode_filter)(struct fb_videomode *mode))
548 {
549         struct fb_event event;
550         int i;
551
552         mutex_lock(&fb_info->info->lock);
553         fb_destroy_modedb(fb_info->info->monspecs.modedb);
554
555         memcpy(&fb_info->info->monspecs, specs,
556                sizeof(fb_info->info->monspecs));
557
558         fb_destroy_modelist(&fb_info->info->modelist);
559
560         for (i = 0; i < specs->modedb_len; i++) {
561                 if (mode_filter) {
562                         if (mode_filter(&specs->modedb[i]))
563                                 fb_add_videomode(&specs->modedb[i],
564                                                  &fb_info->info->modelist);
565                 } else {
566                         fb_add_videomode(&specs->modedb[i],
567                                          &fb_info->info->modelist);
568                 }
569         }
570
571         fb_info->info->mode = (struct fb_videomode *)
572                 fb_find_best_display(specs, &fb_info->info->modelist);
573
574         event.info = fb_info->info;
575         fb_notifier_call_chain(FB_EVENT_NEW_MODELIST, &event);
576         mutex_unlock(&fb_info->info->lock);
577 }
578
579 struct tegra_fb_info *tegra_fb_register(struct nvhost_device *ndev,
580                                         struct tegra_dc *dc,
581                                         struct tegra_fb_data *fb_data,
582                                         struct resource *fb_mem)
583 {
584         struct tegra_dc_win *win;
585         struct fb_info *info;
586         struct tegra_fb_info *tegra_fb;
587         void __iomem *fb_base = NULL;
588         unsigned long fb_size = 0;
589         unsigned long fb_phys = 0;
590         int ret = 0;
591
592         win = tegra_dc_get_window(dc, fb_data->win);
593         if (!win) {
594                 dev_err(&ndev->dev, "dc does not have a window at index %d\n",
595                         fb_data->win);
596                 return ERR_PTR(-ENOENT);
597         }
598
599         info = framebuffer_alloc(sizeof(struct tegra_fb_info), &ndev->dev);
600         if (!info) {
601                 ret = -ENOMEM;
602                 goto err;
603         }
604
605         tegra_fb = info->par;
606         tegra_fb->win = win;
607         tegra_fb->ndev = ndev;
608         tegra_fb->fb_mem = fb_mem;
609         tegra_fb->xres = fb_data->xres;
610         tegra_fb->yres = fb_data->yres;
611         tegra_fb->fb_nvmap = nvmap_create_client(nvmap_dev);
612         if (!tegra_fb->fb_nvmap) {
613                 dev_err(&ndev->dev, "couldn't create nvmap client\n");
614                 ret = -ENOMEM;
615                 goto err_free;
616         }
617         atomic_set(&tegra_fb->in_use, 0);
618
619         tegra_fb->flip_wq = create_singlethread_workqueue(dev_name(&ndev->dev));
620         if (!tegra_fb->flip_wq) {
621                 dev_err(&ndev->dev, "couldn't create flip work-queue\n");
622                 ret = -ENOMEM;
623                 goto err_delete_wq;
624         }
625
626         if (fb_mem) {
627                 fb_size = resource_size(fb_mem);
628                 fb_phys = fb_mem->start;
629                 fb_base = ioremap_nocache(fb_phys, fb_size);
630                 if (!fb_base) {
631                         dev_err(&ndev->dev, "fb can't be mapped\n");
632                         ret = -EBUSY;
633                         goto err_put_client;
634                 }
635                 tegra_fb->valid = true;
636         }
637
638         info->fbops = &tegra_fb_ops;
639         info->pseudo_palette = pseudo_palette;
640         info->screen_base = fb_base;
641         info->screen_size = fb_size;
642
643         strlcpy(info->fix.id, "tegra_fb", sizeof(info->fix.id));
644         info->fix.type          = FB_TYPE_PACKED_PIXELS;
645         info->fix.visual        = FB_VISUAL_TRUECOLOR;
646         info->fix.xpanstep      = 1;
647         info->fix.ypanstep      = 1;
648         info->fix.accel         = FB_ACCEL_NONE;
649         info->fix.smem_start    = fb_phys;
650         info->fix.smem_len      = fb_size;
651
652         info->var.xres                  = fb_data->xres;
653         info->var.yres                  = fb_data->yres;
654         info->var.xres_virtual          = fb_data->xres;
655         info->var.yres_virtual          = fb_data->yres * 2;
656         info->var.bits_per_pixel        = fb_data->bits_per_pixel;
657         info->var.activate              = FB_ACTIVATE_VBL;
658         /* TODO: fill in the following by querying the DC */
659         info->var.height                = -1;
660         info->var.width                 = -1;
661         info->var.pixclock              = 0;
662         info->var.left_margin           = 0;
663         info->var.right_margin          = 0;
664         info->var.upper_margin          = 0;
665         info->var.lower_margin          = 0;
666         info->var.hsync_len             = 0;
667         info->var.vsync_len             = 0;
668         info->var.vmode                 = FB_VMODE_NONINTERLACED;
669
670         win->x = 0;
671         win->y = 0;
672         win->w = fb_data->xres;
673         win->h = fb_data->yres;
674         /* TODO: set to output res dc */
675         win->out_x = 0;
676         win->out_y = 0;
677         win->out_w = fb_data->xres;
678         win->out_h = fb_data->yres;
679         win->z = 0;
680         win->phys_addr = fb_phys;
681         win->virt_addr = fb_base;
682         win->stride = fb_data->xres * fb_data->bits_per_pixel / 8;
683         win->flags = TEGRA_WIN_FLAG_ENABLED;
684
685         if (fb_mem)
686                 tegra_fb_set_par(info);
687
688         if (register_framebuffer(info)) {
689                 dev_err(&ndev->dev, "failed to register framebuffer\n");
690                 ret = -ENODEV;
691                 goto err_iounmap_fb;
692         }
693
694         tegra_fb->info = info;
695
696         dev_info(&ndev->dev, "probed\n");
697
698         return tegra_fb;
699
700 err_iounmap_fb:
701         iounmap(fb_base);
702 err_put_client:
703         nvmap_client_put(tegra_fb->fb_nvmap);
704 err_delete_wq:
705         destroy_workqueue(tegra_fb->flip_wq);
706 err_free:
707         framebuffer_release(info);
708 err:
709         return ERR_PTR(ret);
710 }
711
712 void tegra_fb_unregister(struct tegra_fb_info *fb_info)
713 {
714         struct fb_info *info = fb_info->info;
715
716         if (fb_info->win->cur_handle) {
717                 nvmap_unpin(fb_info->fb_nvmap, fb_info->win->cur_handle);
718                 nvmap_free(fb_info->fb_nvmap, fb_info->win->cur_handle);
719         }
720
721         if (fb_info->fb_nvmap)
722                 nvmap_client_put(fb_info->fb_nvmap);
723
724         unregister_framebuffer(info);
725
726         flush_workqueue(fb_info->flip_wq);
727         destroy_workqueue(fb_info->flip_wq);
728
729         iounmap(info->screen_base);
730         framebuffer_release(info);
731 }