rk3036 lcdc: commit driver code, just pass compiling.
[firefly-linux-kernel-4.4.55.git] / drivers / video / fbmem.c
index 7a41220aebdd19d4df5b9572b5853fe56f4cdc3d..098bfc64cfb93561e8fb0b9817531eb7412d5a27 100644 (file)
@@ -727,7 +727,7 @@ static const struct file_operations fb_proc_fops = {
  */
 static struct fb_info *file_fb_info(struct file *file)
 {
-       struct inode *inode = file->f_path.dentry->d_inode;
+       struct inode *inode = file_inode(file);
        int fbidx = iminor(inode);
        struct fb_info *info = registered_fb[fbidx];
 
@@ -967,6 +967,20 @@ fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var)
            memcmp(&info->var, var, sizeof(struct fb_var_screeninfo))) {
                u32 activate = var->activate;
 
+               /* When using FOURCC mode, make sure the red, green, blue and
+                * transp fields are set to 0.
+                */
+               if ((info->fix.capabilities & FB_CAP_FOURCC) &&
+                   var->grayscale > 1) {
+                       if (var->red.offset     || var->green.offset    ||
+                           var->blue.offset    || var->transp.offset   ||
+                           var->red.length     || var->green.length    ||
+                           var->blue.length    || var->transp.length   ||
+                           var->red.msb_right  || var->green.msb_right ||
+                           var->blue.msb_right || var->transp.msb_right)
+                               return -EINVAL;
+               }
+
                if (!info->fbops->fb_check_var) {
                        *var = info->var;
                        goto done;
@@ -1032,20 +1046,29 @@ fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var)
 int
 fb_blank(struct fb_info *info, int blank)
 {      
-       int ret = -EINVAL;
+       struct fb_event event;
+       int ret = -EINVAL, early_ret;
 
        if (blank > FB_BLANK_POWERDOWN)
                blank = FB_BLANK_POWERDOWN;
 
+       event.info = info;
+       event.data = ␣
+
+       early_ret = fb_notifier_call_chain(FB_EARLY_EVENT_BLANK, &event);
+
        if (info->fbops->fb_blank)
                ret = info->fbops->fb_blank(blank, info);
 
-       if (!ret) {
-               struct fb_event event;
-
-               event.info = info;
-               event.data = ␣
+       if (!ret)
                fb_notifier_call_chain(FB_EVENT_BLANK, &event);
+       else {
+               /*
+                * if fb_blank is failed then revert effects of
+                * the early blank event.
+                */
+               if (!early_ret)
+                       fb_notifier_call_chain(FB_R_EARLY_EVENT_BLANK, &event);
        }
 
        return ret;
@@ -1154,8 +1177,10 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
                event.data = &con2fb;
                if (!lock_fb_info(info))
                        return -ENODEV;
+               console_lock();
                event.info = info;
                ret = fb_notifier_call_chain(FB_EVENT_SET_CONSOLE_MAP, &event);
+               console_unlock();
                unlock_fb_info(info);
                break;
        case FBIOBLANK:
@@ -1348,15 +1373,12 @@ fb_mmap(struct file *file, struct vm_area_struct * vma)
 {
        struct fb_info *info = file_fb_info(file);
        struct fb_ops *fb;
-       unsigned long off;
+       unsigned long mmio_pgoff;
        unsigned long start;
        u32 len;
 
        if (!info)
                return -ENODEV;
-       if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT))
-               return -EINVAL;
-       off = vma->vm_pgoff << PAGE_SHIFT;
        fb = info->fbops;
        if (!fb)
                return -ENODEV;
@@ -1368,33 +1390,29 @@ fb_mmap(struct file *file, struct vm_area_struct * vma)
                return res;
        }
 
-       /* frame buffer memory */
+       /*
+        * Ugh. This can be either the frame buffer mapping, or
+        * if pgoff points past it, the mmio mapping.
+        */
        start = info->fix.smem_start;
-       len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.smem_len);
-       if (off >= len) {
-               /* memory mapped io */
-               off -= len;
+       len = info->fix.smem_len;
+       mmio_pgoff = PAGE_ALIGN((start & ~PAGE_MASK) + len) >> PAGE_SHIFT;
+       if (vma->vm_pgoff >= mmio_pgoff) {
                if (info->var.accel_flags) {
                        mutex_unlock(&info->mm_lock);
                        return -EINVAL;
                }
+
+               vma->vm_pgoff -= mmio_pgoff;
                start = info->fix.mmio_start;
-               len = PAGE_ALIGN((start & ~PAGE_MASK) + info->fix.mmio_len);
+               len = info->fix.mmio_len;
        }
        mutex_unlock(&info->mm_lock);
-       start &= PAGE_MASK;
-       if ((vma->vm_end - vma->vm_start + off) > len)
-               return -EINVAL;
-       off += start;
-       vma->vm_pgoff = off >> PAGE_SHIFT;
-       /* This is an IO map - tell maydump to skip this VMA */
-       vma->vm_flags |= VM_IO | VM_RESERVED;
+
        vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
-       fb_pgprotect(file, vma, off);
-       if (io_remap_pfn_range(vma, vma->vm_start, off >> PAGE_SHIFT,
-                            vma->vm_end - vma->vm_start, vma->vm_page_prot))
-               return -EAGAIN;
-       return 0;
+       fb_pgprotect(file, vma, start);
+
+       return vm_iomap_memory(vma, start, len);
 }
 
 static int
@@ -1621,6 +1639,11 @@ static int do_register_framebuffer(struct fb_info *fb_info)
        if (!fb_info->modelist.prev || !fb_info->modelist.next)
                INIT_LIST_HEAD(&fb_info->modelist);
 
+       if (fb_info->skip_vt_switch)
+               pm_vt_switch_required(fb_info->dev, false);
+       else
+               pm_vt_switch_required(fb_info->dev, true);
+
        fb_var_to_videomode(&mode, &fb_info->var);
        fb_add_videomode(&mode, &fb_info->modelist);
        registered_fb[i] = fb_info;
@@ -1628,7 +1651,9 @@ static int do_register_framebuffer(struct fb_info *fb_info)
        event.info = fb_info;
        if (!lock_fb_info(fb_info))
                return -ENODEV;
+       console_lock();
        fb_notifier_call_chain(FB_EVENT_FB_REGISTERED, &event);
+       console_unlock();
        unlock_fb_info(fb_info);
        return 0;
 }
@@ -1644,13 +1669,17 @@ static int do_unregister_framebuffer(struct fb_info *fb_info)
 
        if (!lock_fb_info(fb_info))
                return -ENODEV;
+       console_lock();
        event.info = fb_info;
        ret = fb_notifier_call_chain(FB_EVENT_FB_UNBIND, &event);
+       console_unlock();
        unlock_fb_info(fb_info);
 
        if (ret)
                return -EINVAL;
 
+       pm_vt_switch_unregister(fb_info->dev);
+
        unlink_framebuffer(fb_info);
        if (fb_info->pixmap.addr &&
            (fb_info->pixmap.flags & FB_PIXMAP_DEFAULT))
@@ -1660,7 +1689,9 @@ static int do_unregister_framebuffer(struct fb_info *fb_info)
        num_registered_fb--;
        fb_cleanup_device(fb_info);
        event.info = fb_info;
+       console_lock();
        fb_notifier_call_chain(FB_EVENT_FB_UNREGISTERED, &event);
+       console_unlock();
 
        /* this may free fb info */
        put_fb_info(fb_info);
@@ -1831,11 +1862,8 @@ int fb_new_modelist(struct fb_info *info)
        err = 1;
 
        if (!list_empty(&info->modelist)) {
-               if (!lock_fb_info(info))
-                       return -ENODEV;
                event.info = info;
                err = fb_notifier_call_chain(FB_EVENT_NEW_MODELIST, &event);
-               unlock_fb_info(info);
        }
 
        return err;