1. 程式人生 > >s3c6410_LCD & frame buffer 驅動分析(二)

s3c6410_LCD & frame buffer 驅動分析(二)

int s3cfb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
{
    s3cfb_info_t *fbi = container_of(info, s3cfb_info_t, fb);
    s3cfb_win_info_t win_info;
    s3cfb_color_key_info_t colkey_info;
    s3cfb_color_val_info_t colval_info;
    s3cfb_dma_info_t dma_info;
    s3cfb_next_info_t next_fb_info;
    struct fb_var_screeninfo *var= &fbi->fb.var;
    unsigned int crt, alpha_level, alpha_mode;
#if defined(CONFIG_S3C6410_PWM)
    int brightness;
#endif
#if defined(CONFIG_FB_S3C_EXT_DOUBLE_BUFFERING)
    unsigned int f_num_val;
#endif
#if defined(CONFIG_FB_S3C_EXT_VIRTUAL_SCREEN)
    s3cfb_vs_info_t vs_info;
#endif
    switch(cmd){
    case S3CFB_GET_INFO:

        dma_info.map_dma_f1 = fbi->map_dma_f1;
        dma_info.map_dma_f2 = fbi->map_dma_f2;
        if(copy_to_user((void *) arg, (const void *) &dma_info, sizeof(s3cfb_dma_info_t)))
            return -EFAULT;
        break;
    case S3CFB_OSD_SET_INFO:
        if (copy_from_user(&win_info, (s3cfb_win_info_t *) arg, sizeof(s3cfb_win_info_t)))
            return -EFAULT;
        s3cfb_init_win(fbi, win_info.bpp, win_info.left_x, win_info.top_y, win_info.width, win_info.height, OFF);
        break;
    case S3CFB_OSD_START:

        s3cfb_onoff_win(fbi, ON);
        break;
    case S3CFB_OSD_STOP:
        s3cfb_onoff_win(fbi, OFF);
        break;
    case S3CFB_OSD_ALPHA_UP:
        alpha_level = readl(S3C_VIDOSD0C + (0x10 * fbi->win_id)) & 0xf;
        if (alpha_level < S3CFB_MAX_ALPHA_LEVEL)
            alpha_level++;
        s3cfb_set_alpha_level(fbi, alpha_level, 1);
        break;
    case S3CFB_OSD_ALPHA_DOWN:

        alpha_level = readl(S3C_VIDOSD0C + (0x10 * fbi->win_id)) & 0xf;
        if (alpha_level > 0)
            alpha_level--;
        s3cfb_set_alpha_level(fbi, alpha_level, 1);
        break;
    case S3CFB_OSD_ALPHA0_SET:
        alpha_level = (unsigned int) arg;
        if (alpha_level > S3CFB_MAX_ALPHA_LEVEL)
            alpha_level = S3CFB_MAX_ALPHA_LEVEL;
        s3cfb_set_alpha_level(fbi, alpha_level, 0);
        break;
    case S3CFB_OSD_ALPHA1_SET:
        alpha_level = (unsigned int) arg;
        if (alpha_level > S3CFB_MAX_ALPHA_LEVEL)
            alpha_level = S3CFB_MAX_ALPHA_LEVEL;
        s3cfb_set_alpha_level(fbi, alpha_level, 1);
        break;
    case S3CFB_OSD_ALPHA_MODE:
        alpha_mode = (unsigned int) arg;
        s3cfb_set_alpha_mode(fbi, alpha_mode);
        break;
    case S3CFB_OSD_MOVE_LEFT:
        if (var->xoffset > 0)
            var->xoffset--;
        s3cfb_set_win_position(fbi, var->xoffset, var->yoffset, var->xres, var->yres);
        break;
    case S3CFB_OSD_MOVE_RIGHT:
        if (var->xoffset < (s3cfb_fimd.width - var->xres))
            var->xoffset++;
        s3cfb_set_win_position(fbi, var->xoffset, var->yoffset, var->xres, var->yres);
        break;
    case S3CFB_OSD_MOVE_UP:
        if (var->yoffset > 0)
            var->yoffset--;
        s3cfb_set_win_position(fbi, var->xoffset, var->yoffset, var->xres, var->yres);
        break;
    case S3CFB_OSD_MOVE_DOWN:
        if (var->yoffset < (s3cfb_fimd.height - var->yres))
            var->yoffset++;
        s3cfb_set_win_position(fbi, var->xoffset, var->yoffset, var->xres, var->yres);
        break;
    case FBIO_WAITFORVSYNC:
        if (get_user(crt, (unsigned int __user *)arg))
            return -EFAULT;
        return s3cfb_wait_for_vsync();
    case S3CFB_COLOR_KEY_START:
        s3cfb_onoff_color_key(fbi, ON);
        break;
    case S3CFB_COLOR_KEY_STOP:
        s3cfb_onoff_color_key(fbi, OFF);
        break;
    case S3CFB_COLOR_KEY_ALPHA_START:
        s3cfb_onoff_color_key_alpha(fbi, ON);
        break;
    case S3CFB_COLOR_KEY_ALPHA_STOP:
        s3cfb_onoff_color_key_alpha(fbi, OFF);
        break;
    case S3CFB_COLOR_KEY_SET_INFO:
        if (copy_from_user(&colkey_info, (s3cfb_color_key_info_t *) arg, sizeof(s3cfb_color_key_info_t)))
            return -EFAULT;
        s3cfb_set_color_key_registers(fbi, colkey_info);
        break;
    case S3CFB_COLOR_KEY_VALUE:
        if (copy_from_user(&colval_info, (s3cfb_color_val_info_t *) arg, sizeof(s3cfb_color_val_info_t)))
            return -EFAULT;
        s3cfb_set_color_value(fbi, colval_info);
        break;
    case S3CFB_SET_VSYNC_INT:
        s3cfb_fimd.vidintcon0 &= ~S3C_VIDINTCON0_FRAMESEL0_MASK;
        s3cfb_fimd.vidintcon0 |= S3C_VIDINTCON0_FRAMESEL0_VSYNC;
        if (arg)
            s3cfb_fimd.vidintcon0 |= S3C_VIDINTCON0_INTFRMEN_ENABLE;
        else
            s3cfb_fimd.vidintcon0 &= ~S3C_VIDINTCON0_INTFRMEN_ENABLE;
        writel(s3cfb_fimd.vidintcon0, S3C_VIDINTCON0);
        break;
    case S3CFB_SET_NEXT_FB_INFO:
        if (copy_from_user(&next_fb_info, (s3cfb_next_info_t *) arg, sizeof(s3cfb_next_info_t)))
            return -EFAULT;
        /* check arguments */
        if ((next_fb_info.xres + next_fb_info.xoffset) > next_fb_info.xres_virtual ||
            (next_fb_info.yres + next_fb_info.yoffset) > next_fb_info.yres_virtual ||
            (next_fb_info.xres + next_fb_info.lcd_offset_x ) > s3cfb_fimd.width ||
            (next_fb_info.yres + next_fb_info.lcd_offset_y ) > s3cfb_fimd.height) {
            printk("Error : S3CFB_SET_NEXT_FB_INFO\n");
             return -EINVAL;
        }
        fbi->next_fb_info = next_fb_info;
        fbi->next_fb_info_change_req = 1;
        break;
    case S3CFB_GET_CURR_FB_INFO:
        next_fb_info.phy_start_addr = fbi->fb.fix.smem_start;
        next_fb_info.xres = fbi->fb.var.xres;
        next_fb_info.yres = fbi->fb.var.yres;
        next_fb_info.xres_virtual = fbi->fb.var.xres_virtual;
        next_fb_info.yres_virtual = fbi->fb.var.yres_virtual;
        next_fb_info.xoffset = fbi->fb.var.xoffset;
        next_fb_info.yoffset = fbi->fb.var.yoffset;
        next_fb_info.lcd_offset_x = fbi->lcd_offset_x;
        next_fb_info.lcd_offset_y = fbi->lcd_offset_y;
        if (copy_to_user((void *)arg, (s3cfb_next_info_t *) &next_fb_info, sizeof(s3cfb_next_info_t)))
            return -EFAULT;
        break;
    case S3CFB_GET_BRIGHTNESS:
        if (copy_to_user((void *)arg, (const void *) &s3cfb_fimd.brightness, sizeof(int)))
            return -EFAULT;
        break;
#if defined(CONFIG_S3C6410_PWM)
    case S3CFB_SET_BRIGHTNESS:
        if (copy_from_user(&brightness, (int *) arg, sizeof(int)))
            return -EFAULT;

        s3cfb_set_brightness(brightness);
        break;
#endif
#if defined(CONFIG_FB_S3C_EXT_VIRTUAL_SCREEN)
    case S3CFB_VS_START:
        s3cfb_fimd.wincon0 &= ~(S3C_WINCONx_ENWIN_F_ENABLE);
        writel(s3cfb_fimd.wincon0 | S3C_WINCONx_ENWIN_F_ENABLE, S3C_WINCON0);

        fbi->fb.var.xoffset = s3cfb_fimd.xoffset;
        fbi->fb.var.yoffset = s3cfb_fimd.yoffset;
        break;
    case S3CFB_VS_STOP:
        s3cfb_fimd.vidw00add0b0 = fbi->screen_dma_f1;
        s3cfb_fimd.vidw00add0b1 = fbi->screen_dma_f2;
        fbi->fb.var.xoffset = 0;
        fbi->fb.var.yoffset = 0;
        writel(s3cfb_fimd.vidw00add0b0, S3C_VIDW00ADD0B0);
        writel(s3cfb_fimd.vidw00add0b1, S3C_VIDW00ADD0B1);
        break;
    case S3CFB_VS_SET_INFO:
        if (copy_from_user(&vs_info, (s3cfb_vs_info_t *) arg, sizeof(s3cfb_vs_info_t)))
            return -EFAULT;

        if (s3cfb_set_vs_info(vs_info)) {
            printk("Error S3CFB_VS_SET_INFO\n");
            return -EINVAL;
        }
        s3cfb_set_vs_registers(S3CFB_VS_SET);
        fbi->fb.var.xoffset = s3cfb_fimd.xoffset;
        fbi->fb.var.yoffset = s3cfb_fimd.yoffset;
        break;
    case S3CFB_VS_MOVE:
        s3cfb_set_vs_registers(arg);

        fbi->fb.var.xoffset = s3cfb_fimd.xoffset;
        fbi->fb.var.yoffset = s3cfb_fimd.yoffset;
        break;
#endif
#if defined(CONFIG_FB_S3C_EXT_DOUBLE_BUFFERING)
    case S3CFB_GET_NUM:
        if (copy_from_user((void *)&f_num_val, (const void *)arg, sizeof(u_int)))
            return -EFAULT;
        if (copy_to_user((void *)arg, (const void *) &f_num_val, sizeof(u_int)))
            return -EFAULT;
        break;
    case S3CFB_CHANGE_REQ:
        s3cfb_change_buff(0, (int) arg);
        break;
#endif

    default:
        return -EINVAL;
    }
    return 0;
}