diff options
author | Joseph Chan <JosephChan@via.com.tw> | 2008-10-15 22:03:27 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-10-16 11:21:41 -0700 |
commit | 29b619fae69a0638ce10d5d6bb3c53f5d3ca0390 (patch) | |
tree | c3ded8d268115796f8b6994a61d0c0f30da50a99 /drivers/video | |
parent | d42823ef6a3ebd388b193c5533efd7e7a00b7aa8 (diff) |
viafb: viafbdev.c, viafbdev.h
Correct by following Jiri Slaby's suggestions.
Initialization, remove and some other important functions of viafb.
[akpm@linux-foundation.org: coding-style fixes]
Signed-off-by: Joseph Chan <josephchan@via.com.tw>
Cc: Krzysztof Helt <krzysztof.h1@poczta.fm>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Jiri Slaby <jirislaby@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/video')
-rw-r--r-- | drivers/video/via/viafbdev.c | 2567 | ||||
-rw-r--r-- | drivers/video/via/viafbdev.h | 112 |
2 files changed, 2679 insertions, 0 deletions
diff --git a/drivers/video/via/viafbdev.c b/drivers/video/via/viafbdev.c new file mode 100644 index 00000000000..ba8ce61140c --- /dev/null +++ b/drivers/video/via/viafbdev.c @@ -0,0 +1,2567 @@ +/* + * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved. + * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved. + + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; + * either version 2, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE.See the GNU General Public License + * for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <linux/module.h> +#define _MASTER_FILE + +#include "global.h" + +static int MAX_CURS = 32; +static struct fb_var_screeninfo default_var; +static char *viafb_name = "Via"; +static u32 pseudo_pal[17]; + +/* video mode */ +static char *viafb_mode = "640x480"; +static char *viafb_mode1 = "640x480"; +static int viafb_resMode = VIA_RES_640X480; + +/* Added for specifying active devices.*/ +char *viafb_active_dev = ""; + +/* Added for specifying video on devices.*/ +char *viafb_video_dev = ""; + +/*Added for specify lcd output port*/ +char *viafb_lcd_port = ""; +char *viafb_dvi_port = ""; + +static void viafb_set_device(struct device_t active_dev); +static int apply_device_setting(struct viafb_ioctl_setting setting_info, + struct fb_info *info); +static void apply_second_mode_setting(struct fb_var_screeninfo + *sec_var); +static void retrieve_device_setting(struct viafb_ioctl_setting + *setting_info); +static void viafb_set_video_device(u32 video_dev_info); +static void viafb_get_video_device(u32 *video_dev_info); + +/* Mode information */ +static const struct viafb_modeinfo viafb_modentry[] = { + {480, 640, VIA_RES_480X640, "480x640"}, + {640, 480, VIA_RES_640X480, "640x480"}, + {800, 480, VIA_RES_800X480, "800x480"}, + {800, 600, VIA_RES_800X600, "800x600"}, + {1024, 768, VIA_RES_1024X768, "1024x768"}, + {1152, 864, VIA_RES_1152X864, "1152x864"}, + {1280, 1024, VIA_RES_1280X1024, "1280x1024"}, + {1600, 1200, VIA_RES_1600X1200, "1600x1200"}, + {1440, 1050, VIA_RES_1440X1050, "1440x1050"}, + {1280, 768, VIA_RES_1280X768, "1280x768"}, + {1280, 800, VIA_RES_1280X800, "1280x800"}, + {1280, 960, VIA_RES_1280X960, "1280x960"}, + {1920, 1440, VIA_RES_1920X1440, "1920x1440"}, + {848, 480, VIA_RES_848X480, "848x480"}, + {1400, 1050, VIA_RES_1400X1050, "1400x1050"}, + {720, 480, VIA_RES_720X480, "720x480"}, + {720, 576, VIA_RES_720X576, "720x576"}, + {1024, 512, VIA_RES_1024X512, "1024x512"}, + {1024, 576, VIA_RES_1024X576, "1024x576"}, + {1024, 600, VIA_RES_1024X600, "1024x600"}, + {1280, 720, VIA_RES_1280X720, "1280x720"}, + {1920, 1080, VIA_RES_1920X1080, "1920x1080"}, + {1366, 768, VIA_RES_1368X768, "1368x768"}, + {1680, 1050, VIA_RES_1680X1050, "1680x1050"}, + {960, 600, VIA_RES_960X600, "960x600"}, + {1000, 600, VIA_RES_1000X600, "1000x600"}, + {1024, 576, VIA_RES_1024X576, "1024x576"}, + {1024, 600, VIA_RES_1024X600, "1024x600"}, + {1088, 612, VIA_RES_1088X612, "1088x612"}, + {1152, 720, VIA_RES_1152X720, "1152x720"}, + {1200, 720, VIA_RES_1200X720, "1200x720"}, + {1280, 600, VIA_RES_1280X600, "1280x600"}, + {1360, 768, VIA_RES_1360X768, "1360x768"}, + {1440, 900, VIA_RES_1440X900, "1440x900"}, + {1600, 900, VIA_RES_1600X900, "1600x900"}, + {1600, 1024, VIA_RES_1600X1024, "1600x1024"}, + {1792, 1344, VIA_RES_1792X1344, "1792x1344"}, + {1856, 1392, VIA_RES_1856X1392, "1856x1392"}, + {1920, 1200, VIA_RES_1920X1200, "1920x1200"}, + {2048, 1536, VIA_RES_2048X1536, "2048x1536"}, + {0, 0, VIA_RES_INVALID, "640x480"} +}; + +static struct fb_ops viafb_ops; + +static int viafb_update_fix(struct fb_fix_screeninfo *fix, struct fb_info *info) +{ + struct viafb_par *ppar; + ppar = info->par; + + DEBUG_MSG(KERN_INFO "viafb_update_fix!\n"); + + fix->visual = + ppar->bpp == 8 ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR; + fix->line_length = ppar->linelength; + + return 0; +} + + +static void viafb_setup_fixinfo(struct fb_fix_screeninfo *fix, + struct viafb_par *viaparinfo) +{ + memset(fix, 0, sizeof(struct fb_fix_screeninfo)); + strcpy(fix->id, viafb_name); + + fix->smem_start = viaparinfo->fbmem; + fix->smem_len = viaparinfo->fbmem_free; + fix->mmio_start = viaparinfo->mmio_base; + fix->mmio_len = viaparinfo->mmio_len; + + fix->type = FB_TYPE_PACKED_PIXELS; + fix->type_aux = 0; + + fix->xpanstep = fix->ywrapstep = 0; + fix->ypanstep = 1; + + /* Just tell the accel name */ + viafbinfo->fix.accel = FB_ACCEL_VIA_UNICHROME; +} +static int viafb_open(struct fb_info *info, int user) +{ + DEBUG_MSG(KERN_INFO "viafb_open!\n"); + return 0; +} + +static int viafb_release(struct fb_info *info, int user) +{ + DEBUG_MSG(KERN_INFO "viafb_release!\n"); + return 0; +} + +static void viafb_update_viafb_par(struct fb_info *info) +{ + struct viafb_par *ppar; + + ppar = info->par; + ppar->bpp = info->var.bits_per_pixel; + ppar->linelength = ((info->var.xres_virtual + 7) & ~7) * ppar->bpp / 8; + ppar->hres = info->var.xres; + ppar->vres = info->var.yres; + ppar->xoffset = info->var.xoffset; + ppar->yoffset = info->var.yoffset; +} + +static int viafb_check_var(struct fb_var_screeninfo *var, + struct fb_info *info) +{ + int vmode_index, htotal, vtotal; + struct viafb_par *ppar; + u32 long_refresh; + struct viafb_par *p_viafb_par; + ppar = info->par; + + + DEBUG_MSG(KERN_INFO "viafb_check_var!\n"); + /* Sanity check */ + /* HW neither support interlacte nor double-scaned mode */ + if (var->vmode & FB_VMODE_INTERLACED || var->vmode & FB_VMODE_DOUBLE) + return -EINVAL; + + vmode_index = viafb_get_mode_index(var->xres, var->yres, 0); + if (vmode_index == VIA_RES_INVALID) { + DEBUG_MSG(KERN_INFO + "viafb: Mode %dx%dx%d not supported!!\n", + var->xres, var->yres, var->bits_per_pixel); + return -EINVAL; + } + + if (24 == var->bits_per_pixel) + var->bits_per_pixel = 32; + + if (var->bits_per_pixel != 8 && var->bits_per_pixel != 16 && + var->bits_per_pixel != 32) + return -EINVAL; + + if ((var->xres_virtual * (var->bits_per_pixel >> 3)) & 0x1F) + /*32 pixel alignment */ + var->xres_virtual = (var->xres_virtual + 31) & ~31; + if (var->xres_virtual * var->yres_virtual * var->bits_per_pixel / 8 > + ppar->memsize) + return -EINVAL; + + /* Based on var passed in to calculate the refresh, + * because our driver use some modes special. + */ + htotal = var->xres + var->left_margin + + var->right_margin + var->hsync_len; + vtotal = var->yres + var->upper_margin + + var->lower_margin + var->vsync_len; + long_refresh = 1000000000UL / var->pixclock * 1000; + long_refresh /= (htotal * vtotal); + + viafb_refresh = viafb_get_refresh(var->xres, var->yres, long_refresh); + + /* Adjust var according to our driver's own table */ + viafb_fill_var_timing_info(var, viafb_refresh, vmode_index); + + /* This is indeed a patch for VT3353 */ + if (!info->par) + return -1; + p_viafb_par = (struct viafb_par *)info->par; + if (p_viafb_par->chip_info->gfx_chip_name == UNICHROME_VX800) + var->accel_flags = 0; + + return 0; +} + +static int viafb_set_par(struct fb_info *info) +{ + int vmode_index; + int vmode_index1 = 0; + DEBUG_MSG(KERN_INFO "viafb_set_par!\n"); + + viafb_update_device_setting(info->var.xres, info->var.yres, + info->var.bits_per_pixel, viafb_refresh, 0); + + vmode_index = viafb_get_mode_index(info->var.xres, info->var.yres, 0); + + if (viafb_SAMM_ON == 1) { + DEBUG_MSG(KERN_INFO + "viafb_second_xres = %d, viafb_second_yres = %d, bpp = %d\n", + viafb_second_xres, viafb_second_yres, viafb_bpp1); + vmode_index1 = viafb_get_mode_index(viafb_second_xres, + viafb_second_yres, 1); + DEBUG_MSG(KERN_INFO "->viafb_SAMM_ON: index=%d\n", + vmode_index1); + + viafb_update_device_setting(viafb_second_xres, + viafb_second_yres, viafb_bpp1, viafb_refresh1, 1); + } + + if (vmode_index != VIA_RES_INVALID) { + viafb_setmode(vmode_index, info->var.xres, info->var.yres, + info->var.bits_per_pixel, vmode_index1, + viafb_second_xres, viafb_second_yres, viafb_bpp1); + + /*We should set memory offset according virtual_x */ + /*Fix me:put this function into viafb_setmode */ + viafb_memory_pitch_patch(info); + + /* Update ***fb_par information */ + viafb_update_viafb_par(info); + + /* Update other fixed information */ + viafb_update_fix(&info->fix, info); + viafb_bpp = info->var.bits_per_pixel; + /* Update viafb_accel, it is necessary to our 2D accelerate */ + viafb_accel = info->var.accel_flags; + + if (viafb_accel) + viafb_set_2d_color_depth(info->var.bits_per_pixel); + } + + return 0; +} + +/* Set one color register */ +static int viafb_setcolreg(unsigned regno, unsigned red, unsigned green, +unsigned blue, unsigned transp, struct fb_info *info) +{ + u8 sr1a, sr1b, cr67, cr6a, rev = 0, shift = 10; + unsigned cmap_entries = (info->var.bits_per_pixel == 8) ? 256 : 16; + DEBUG_MSG(KERN_INFO "viafb_setcolreg!\n"); + if (regno >= cmap_entries) + return 1; + if (UNICHROME_CLE266 == viaparinfo->chip_info->gfx_chip_name) { + /* + * Read PCI bus 0,dev 0,function 0,index 0xF6 to get chip rev. + */ + outl(0x80000000 | (0xf6 & ~3), (unsigned long)0xCF8); + rev = (inl((unsigned long)0xCFC) >> ((0xf6 & 3) * 8)) & 0xff; + } + switch (info->var.bits_per_pixel) { + case 8: + outb(0x1A, 0x3C4); + sr1a = inb(0x3C5); + outb(0x1B, 0x3C4); + sr1b = inb(0x3C5); + outb(0x67, 0x3D4); + cr67 = inb(0x3D5); + outb(0x6A, 0x3D4); + cr6a = inb(0x3D5); + + /* Map the 3C6/7/8/9 to the IGA2 */ + outb(0x1A, 0x3C4); + outb(sr1a | 0x01, 0x3C5); + /* Second Display Engine colck always on */ + outb(0x1B, 0x3C4); + outb(sr1b | 0x80, 0x3C5); + /* Second Display Color Depth 8 */ + outb(0x67, 0x3D4); + outb(cr67 & 0x3F, 0x3D5); + outb(0x6A, 0x3D4); + /* Second Display Channel Reset CR6A[6]) */ + outb(cr6a & 0xBF, 0x3D5); + /* Second Display Channel Enable CR6A[7] */ + outb(cr6a | 0x80, 0x3D5); + /* Second Display Channel stop reset) */ + outb(cr6a | 0x40, 0x3D5); + + /* Bit mask of palette */ + outb(0xFF, 0x3c6); + /* Write one register of IGA2 */ + outb(regno, 0x3C8); + if (UNICHROME_CLE266 == viaparinfo->chip_info->gfx_chip_name && + rev >= 15) { + shift = 8; + viafb_write_reg_mask(CR6A, VIACR, BIT5, BIT5); + viafb_write_reg_mask(SR15, VIASR, BIT7, BIT7); + } else { + shift = 10; + viafb_write_reg_mask(CR6A, VIACR, 0, BIT5); + viafb_write_reg_mask(SR15, VIASR, 0, BIT7); + } + outb(red >> shift, 0x3C9); + outb(green >> shift, 0x3C9); + outb(blue >> shift, 0x3C9); + + /* Map the 3C6/7/8/9 to the IGA1 */ + outb(0x1A, 0x3C4); + outb(sr1a & 0xFE, 0x3C5); + /* Bit mask of palette */ + outb(0xFF, 0x3c6); + /* Write one register of IGA1 */ + outb(regno, 0x3C8); + outb(red >> shift, 0x3C9); + outb(green >> shift, 0x3C9); + outb(blue >> shift, 0x3C9); + + outb(0x1A, 0x3C4); + outb(sr1a, 0x3C5); + outb(0x1B, 0x3C4); + outb(sr1b, 0x3C5); + outb(0x67, 0x3D4); + outb(cr67, 0x3D5); + outb(0x6A, 0x3D4); + outb(cr6a, 0x3D5); + break; + case 16: + ((u32 *) info->pseudo_palette)[regno] = (red & 0xF800) | + ((green & 0xFC00) >> 5) | ((blue & 0xF800) >> 11); + break; + case 32: + ((u32 *) info->pseudo_palette)[regno] = + ((transp & 0xFF00) << 16) | + ((red & 0xFF00) << 8) | + ((green & 0xFF00)) | ((blue & 0xFF00) >> 8); + break; + } + + return 0; + +} + +/*CALLED BY: fb_set_cmap */ +/* fb_set_var, pass 256 colors */ +/*CALLED BY: fb_set_cmap */ +/* fbcon_set_palette, pass 16 colors */ +static int viafb_setcmap(struct fb_cmap *cmap, struct fb_info *info) +{ + u32 len = cmap->len; + u32 i; + u16 *pred = cmap->red; + u16 *pgreen = cmap->green; + u16 *pblue = cmap->blue; + u16 *ptransp = cmap->transp; + u8 sr1a, sr1b, cr67, cr6a, rev = 0, shift = 10; + if (len > 256) + return 1; + if (UNICHROME_CLE266 == viaparinfo->chip_info->gfx_chip_name) { + /* + * Read PCI bus 0, dev 0, function 0, index 0xF6 to get chip + * rev. + */ + outl(0x80000000 | (0xf6 & ~3), (unsigned long)0xCF8); + rev = (inl((unsigned long)0xCFC) >> ((0xf6 & 3) * 8)) & 0xff; + } + switch (info->var.bits_per_pixel) { + case 8: + outb(0x1A, 0x3C4); + sr1a = inb(0x3C5); + outb(0x1B, 0x3C4); + sr1b = inb(0x3C5); + outb(0x67, 0x3D4); + cr67 = inb(0x3D5); + outb(0x6A, 0x3D4); + cr6a = inb(0x3D5); + /* Map the 3C6/7/8/9 to the IGA2 */ + outb(0x1A, 0x3C4); + outb(sr1a | 0x01, 0x3C5); + outb(0x1B, 0x3C4); + /* Second Display Engine colck always on */ + outb(sr1b | 0x80, 0x3C5); + outb(0x67, 0x3D4); + /* Second Display Color Depth 8 */ + outb(cr67 & 0x3F, 0x3D5); + outb(0x6A, 0x3D4); + /* Second Display Channel Reset CR6A[6]) */ + outb(cr6a & 0xBF, 0x3D5); + /* Second Display Channel Enable CR6A[7] */ + outb(cr6a | 0x80, 0x3D5); + /* Second Display Channel stop reset) */ + outb(cr6a | 0xC0, 0x3D5); + + /* Bit mask of palette */ + outb(0xFF, 0x3c6); + outb(0x00, 0x3C8); + if (UNICHROME_CLE266 == viaparinfo->chip_info->gfx_chip_name && + rev >= 15) { + shift = 8; + viafb_write_reg_mask(CR6A, VIACR, BIT5, BIT5); + viafb_write_reg_mask(SR15, VIASR, BIT7, BIT7); + } else { + shift = 10; + viafb_write_reg_mask(CR6A, VIACR, 0, BIT5); + viafb_write_reg_mask(SR15, VIASR, 0, BIT7); + } + for (i = 0; i < len; i++) { + outb((*(pred + i)) >> shift, 0x3C9); + outb((*(pgreen + i)) >> shift, 0x3C9); + outb((*(pblue + i)) >> shift, 0x3C9); + } + + outb(0x1A, 0x3C4); + /* Map the 3C6/7/8/9 to the IGA1 */ + outb(sr1a & 0xFE, 0x3C5); + /* Bit mask of palette */ + outb(0xFF, 0x3c6); + outb(0x00, 0x3C8); + for (i = 0; i < len; i++) { + outb((*(pred + i)) >> shift, 0x3C9); + outb((*(pgreen + i)) >> shift, 0x3C9); + outb((*(pblue + i)) >> shift, 0x3C9); + } + + outb(0x1A, 0x3C4); + outb(sr1a, 0x3C5); + outb(0x1B, 0x3C4); + outb(sr1b, 0x3C5); + outb(0x67, 0x3D4); + outb(cr67, 0x3D5); + outb(0x6A, 0x3D4); + outb(cr6a, 0x3D5); + break; + case 16: + if (len > 17) + return 0; /* Because static u32 pseudo_pal[17]; */ + for (i = 0; i < len; i++) + ((u32 *) info->pseudo_palette)[i] = + (*(pred + i) & 0xF800) | + ((*(pgreen + i) & 0xFC00) >> 5) | + ((*(pblue + i) & 0xF800) >> 11); + break; + case 32: + if (len > 17) + return 0; + if (ptransp) { + for (i = 0; i < len; i++) + ((u32 *) info->pseudo_palette)[i] = + ((*(ptransp + i) & 0xFF00) << 16) | + ((*(pred + i) & 0xFF00) << 8) | + ((*(pgreen + i) & 0xFF00)) | + ((*(pblue + i) & 0xFF00) >> 8); + } else { + for (i = 0; i < len; i++) + ((u32 *) info->pseudo_palette)[i] = + 0x00000000 | + ((*(pred + i) & 0xFF00) << 8) | + ((*(pgreen + i) & 0xFF00)) | + ((*(pblue + i) & 0xFF00) >> 8); + } + break; + } + return 0; +} + +static int viafb_pan_display(struct fb_var_screeninfo *var, + struct fb_info *info) +{ + unsigned int offset; + + DEBUG_MSG(KERN_INFO "viafb_pan_display!\n"); + + offset = (var->xoffset + (var->yoffset * var->xres_virtual)) * + var->bits_per_pixel / 16; + + DEBUG_MSG(KERN_INFO "\nviafb_pan_display,offset =%d ", offset); + + viafb_write_reg_mask(0x48, 0x3d4, ((offset >> 24) & 0x3), 0x3); + viafb_write_reg_mask(0x34, 0x3d4, ((offset >> 16) & 0xff), 0xff); + viafb_write_reg_mask(0x0c, 0x3d4, ((offset >> 8) & 0xff), 0xff); + viafb_write_reg_mask(0x0d, 0x3d4, (offset & 0xff), 0xff); + + return 0; +} + +static int viafb_blank(int blank_mode, struct fb_info *info) +{ + DEBUG_MSG(KERN_INFO "viafb_blank!\n"); + /* clear DPMS setting */ + + switch (blank_mode) { + case FB_BLANK_UNBLANK: + /* Screen: On, HSync: On, VSync: On */ + /* control CRT monitor power management */ + viafb_write_reg_mask(CR36, VIACR, 0x00, BIT4 + BIT5); + break; + case FB_BLANK_HSYNC_SUSPEND: + /* Screen: Off, HSync: Off, VSync: On */ + /* control CRT monitor power management */ + viafb_write_reg_mask(CR36, VIACR, 0x10, BIT4 + BIT5); + break; + case FB_BLANK_VSYNC_SUSPEND: + /* Screen: Off, HSync: On, VSync: Off */ + /* control CRT monitor power management */ + viafb_write_reg_mask(CR36, VIACR, 0x20, BIT4 + BIT5); + break; + case FB_BLANK_POWERDOWN: + /* Screen: Off, HSync: Off, VSync: Off */ + /* control CRT monitor power management */ + viafb_write_reg_mask(CR36, VIACR, 0x30, BIT4 + BIT5); + break; + } + + return 0; +} + +static int viafb_ioctl(struct fb_info *info, u_int cmd, u_long arg) +{ + struct viafb_ioctl_mode viamode; + struct viafb_ioctl_samm viasamm; + struct viafb_driver_version driver_version; + struct fb_var_screeninfo sec_var; + struct _panel_size_pos_info panel_pos_size_para; + u32 state_info = 0; + u32 viainfo_size = sizeof(struct viafb_ioctl_info); + u32 *viafb_gamma_table; + char driver_name[] = "viafb"; + + u32 __user *argp = (u32 __user *) arg; + u32 gpu32; + u32 video_dev_info = 0; + struct viafb_ioctl_setting viafb_setting = {}; + struct device_t active_dev = {}; + + DEBUG_MSG(KERN_INFO "viafb_ioctl: 0x%X !!\n", cmd); + + switch (cmd) { + case VIAFB_GET_CHIP_INFO: + if (copy_to_user(argp, viaparinfo->chip_info, + sizeof(struct chip_information))) + return -EFAULT; + break; + case VIAFB_GET_INFO_SIZE: + return put_user(viainfo_size, argp); + case VIAFB_GET_INFO: + return viafb_ioctl_get_viafb_info(arg); + case VIAFB_HOTPLUG: + return put_user(viafb_ioctl_hotplug(info->var.xres, + info->var.yres, + info->var.bits_per_pixel), argp); + case VIAFB_SET_HOTPLUG_FLAG: + if (copy_from_user(&gpu32, argp, sizeof(gpu32))) + return -EFAULT; + viafb_hotplug = (gpu32) ? 1 : 0; + break; + case VIAFB_GET_RESOLUTION: + viamode.xres = (u32) viafb_hotplug_Xres; + viamode.yres = (u32) viafb_hotplug_Yres; + viamode.refresh = (u32) viafb_hotplug_refresh; + viamode.bpp = (u32) viafb_hotplug_bpp; + if (viafb_SAMM_ON == 1) { + viamode.xres_sec = viafb_second_xres; + viamode.yres_sec = viafb_second_yres; + viamode.virtual_xres_sec = viafb_second_virtual_xres; + viamode.virtual_yres_sec = viafb_second_virtual_yres; + viamode.refresh_sec = viafb_refresh1; + viamode.bpp_sec = viafb_bpp1; + } else { + viamode.xres_sec = 0; + viamode.yres_sec = 0; + viamode.virtual_xres_sec = 0; + viamode.virtual_yres_sec = 0; + viamode.refresh_sec = 0; + viamode.bpp_sec = 0; + } + if (copy_to_user(argp, &viamode, sizeof(viamode))) + return -EFAULT; + break; + case VIAFB_GET_SAMM_INFO: + viasamm.samm_status = viafb_SAMM_ON; + + if (viafb_SAMM_ON == 1) { + if (viafb_dual_fb) { + viasamm.size_prim = viaparinfo->fbmem_free; + viasamm.size_sec = viaparinfo1->fbmem_free; + } else { + if (viafb_second_size) { + viasamm.size_prim = + viaparinfo->fbmem_free - + viafb_second_size * 1024 * 1024; + viasamm.size_sec = + viafb_second_size * 1024 * 1024; + } else { + viasamm.size_prim = + viaparinfo->fbmem_free >> 1; + viasamm.size_sec = + (viaparinfo->fbmem_free >> 1); + } + } + viasamm.mem_base = viaparinfo->fbmem; + viasamm.offset_sec = viafb_second_offset; + } else { + viasamm.size_prim = + viaparinfo->memsize - viaparinfo->fbmem_used; + viasamm.size_sec = 0; + viasamm.mem_base = viaparinfo->fbmem; + viasamm.offset_sec = 0; + } + + if (copy_to_user(argp, &viasamm, sizeof(viasamm))) + return -EFAULT; + + break; + case VIAFB_TURN_ON_OUTPUT_DEVICE: + if (copy_from_user(&gpu32, argp, sizeof(gpu32))) + return -EFAULT; + if (gpu32 & CRT_Device) + viafb_crt_enable(); + if (gpu32 & DVI_Device) + viafb_dvi_enable(); + if (gpu32 & LCD_Device) + viafb_lcd_enable(); + break; + case VIAFB_TURN_OFF_OUTPUT_DEVICE: + if (copy_from_user(&gpu32, argp, sizeof(gpu32))) + return -EFAULT; + if (gpu32 & CRT_Device) + viafb_crt_disable(); + if (gpu32 & DVI_Device) + viafb_dvi_disable(); + if (gpu32 & LCD_Device) + viafb_lcd_disable(); + break; + case VIAFB_SET_DEVICE: + if (copy_from_user(&active_dev, (void *)argp, + sizeof(active_dev))) + return -EFAULT; + viafb_set_device(active_dev); + viafb_set_par(info); + break; + case VIAFB_GET_DEVICE: + active_dev.crt = viafb_CRT_ON; + active_dev.dvi = viafb_DVI_ON; + active_dev.lcd = viafb_LCD_ON; + active_dev.samm = viafb_SAMM_ON; + active_dev.primary_dev = viafb_primary_dev; + + active_dev.lcd_dsp_cent = viafb_lcd_dsp_method; + active_dev.lcd_panel_id = viafb_lcd_panel_id; + active_dev.lcd_mode = viafb_lcd_mode; + + active_dev.xres = viafb_hotplug_Xres; + active_dev.yres = viafb_hotplug_Yres; + + active_dev.xres1 = viafb_second_xres; + active_dev.yres1 = viafb_second_yres; + + active_dev.bpp = viafb_bpp; + active_dev.bpp1 = viafb_bpp1; + active_dev.refresh = viafb_refresh; + active_dev.refresh1 = viafb_refresh1; + + active_dev.epia_dvi = viafb_platform_epia_dvi; + active_dev.lcd_dual_edge = viafb_device_lcd_dualedge; + active_dev.bus_width = viafb_bus_width; + + if (copy_to_user(argp, &active_dev, sizeof(active_dev))) + return -EFAULT; + break; + + case VIAFB_GET_DRIVER_VERSION: + driver_version.iMajorNum = VERSION_MAJOR; + driver_version.iKernelNum = VERSION_KERNEL; + driver_version.iOSNum = VERSION_OS; + driver_version.iMinorNum = VERSION_MINOR; + + if (copy_to_user(argp, &driver_version, + sizeof(driver_version))) + return -EFAULT; + + break; + + case VIAFB_SET_DEVICE_INFO: + if (copy_from_user(&viafb_setting, + argp, sizeof(viafb_setting))) + return -EFAULT; + if (apply_device_setting(viafb_setting, info) < 0) + return -EINVAL; + + break; + + case VIAFB_SET_SECOND_MODE: + if (copy_from_user(&sec_var, argp, sizeof(sec_var))) + return -EFAULT; + apply_second_mode_setting(&sec_var); + break; + + case VIAFB_GET_DEVICE_INFO: + + retrieve_device_setting(&viafb_setting); + + if (copy_to_user(argp, &viafb_setting, sizeof(viafb_setting))) + return -EFAULT; + + break; + + case VIAFB_GET_DEVICE_SUPPORT: + viafb_get_device_support_state(&state_info); + if (put_user(state_info, argp)) + return -EFAULT; + break; + + case VIAFB_GET_DEVICE_CONNECT: + viafb_get_device_connect_state(&state_info); + if (put_user(state_info, argp)) + return -EFAULT; + break; + + case VIAFB_GET_PANEL_SUPPORT_EXPAND: + state_info = + viafb_lcd_get_support_expand_state(info->var.xres, + info->var.yres); + if (put_user(state_info, argp)) + return -EFAULT; + break; + + case VIAFB_GET_DRIVER_NAME: + if (copy_to_user(argp, driver_name, sizeof(driver_name))) + return -EFAULT; + break; + + case VIAFB_SET_GAMMA_LUT: + viafb_gamma_table = kmalloc(256 * sizeof(u32), GFP_KERNEL); + if (!viafb_gamma_table) + return -ENOMEM; + if (copy_from_user(viafb_gamma_table, argp, + sizeof(viafb_gamma_table))) { + kfree(viafb_gamma_table); + return -EFAULT; + } + viafb_set_gamma_table(viafb_bpp, viafb_gamma_table); + kfree(viafb_gamma_table); + break; + + case VIAFB_GET_GAMMA_LUT: + viafb_gamma_table = kmalloc(256 * sizeof(u32), GFP_KERNEL); + if (!viafb_gamma_table) + return -ENOMEM; + viafb_get_gamma_table(viafb_gamma_table); + if (copy_to_user(argp, viafb_gamma_table, + sizeof(viafb_gamma_table))) { + kfree(viafb_gamma_table); + return -EFAULT; + } + kfree(viafb_gamma_table); + break; + + case VIAFB_GET_GAMMA_SUPPORT_STATE: + viafb_get_gamma_support_state(viafb_bpp, &state_info); + if (put_user(state_info, argp)) + return -EFAULT; + break; + case VIAFB_SET_VIDEO_DEVICE: + get_user(video_dev_info, argp); + viafb_set_video_device(video_dev_info); + break; + case VIAFB_GET_VIDEO_DEVICE: + viafb_get_video_device(&video_dev_info); + if (put_user(video_dev_info, argp)) + return -EFAULT; + break; + case VIAFB_SYNC_SURFACE: + DEBUG_MSG(KERN_INFO "lobo VIAFB_SYNC_SURFACE\n"); + break; + case VIAFB_GET_DRIVER_CAPS: + break; + + case VIAFB_GET_PANEL_MAX_SIZE: + if (copy_from_user + (&panel_pos_size_para, argp, sizeof(panel_pos_size_para))) + return -EFAULT; + panel_pos_size_para.x = panel_pos_size_para.y = 0; + if (copy_to_user(argp, &panel_pos_size_para, + sizeof(panel_pos_size_para))) + return -EFAULT; + break; + case VIAFB_GET_PANEL_MAX_POSITION: + if (copy_from_user + (&panel_pos_size_para, argp, sizeof(panel_pos_size_para))) + return -EFAULT; + panel_pos_size_para.x = panel_pos_size_para.y = 0; + if (copy_to_user(argp, &panel_pos_size_para, + sizeof(panel_pos_size_para))) + return -EFAULT; + break; + + case VIAFB_GET_PANEL_POSITION: + if (copy_from_user + (&panel_pos_size_para, argp, sizeof(panel_pos_size_para))) + return -EFAULT; + panel_pos_size_para.x = panel_pos_size_para.y = 0; + if (copy_to_user(argp, &panel_pos_size_para, + sizeof(panel_pos_size_para))) + return -EFAULT; + break; + case VIAFB_GET_PANEL_SIZE: + if (copy_from_user + (&panel_pos_size_para, argp, sizeof(panel_pos_size_para))) + return -EFAULT; + panel_pos_size_para.x = panel_pos_size_para.y = 0; + if (copy_to_user(argp, &panel_pos_size_para, + sizeof(panel_pos_size_para))) + return -EFAULT; + break; + + case VIAFB_SET_PANEL_POSITION: + if (copy_from_user + (&panel_pos_size_para, argp, sizeof(panel_pos_size_para))) + return -EFAULT; + break; + case VIAFB_SET_PANEL_SIZE: + if (copy_from_user + (&panel_pos_size_para, argp, sizeof(panel_pos_size_para))) + return -EFAULT; + break; + + default: + return -EINVAL; + } + + return 0; +} + +static void viafb_fillrect(struct fb_info *info, + const struct fb_fillrect *rect) +{ + u32 col = 0, rop = 0; + int pitch; + + if (!viafb_accel) + return cfb_fillrect(info, rect); + + if (!rect->width || !rect->height) + return; + + switch (rect->rop) { + case ROP_XOR: + rop = 0x5A; + break; + case ROP_COPY: + default: + rop = 0xF0; + break; + } + + switch (info->var.bits_per_pixel) { + case 8: + col = rect->color; + break; + case 16: + col = ((u32 *) (info->pseudo_palette))[rect->color]; + break; + case 32: + col = ((u32 *) (info->pseudo_palette))[rect->color]; + break; + } + + /* BitBlt Source Address */ + MMIO_OUT32(VIA_REG_SRCPOS, 0x0); + /* Source Base Address */ + MMIO_OUT32(VIA_REG_SRCBASE, 0x0); + /* Destination Base Address */ + /*MMIO_OUT32(VIA_REG_DSTBASE, 0x0); */ + MMIO_OUT32(VIA_REG_DSTBASE, + ((u32) (info->screen_base) - (u32) viafb_FB_MM) >> 3); + /* Pitch */ + pitch = (info->var.xres_virtual + 7) & ~7; + MMIO_OUT32(VIA_REG_PITCH, + VIA_PITCH_ENABLE | + (((pitch * + info->var.bits_per_pixel >> 3) >> 3) | + (((pitch * info-> + var.bits_per_pixel >> 3) >> 3) << 16))); + /* BitBlt Destination Address */ + MMIO_OUT32(VIA_REG_DSTPOS, ((rect->dy << 16) | rect->dx)); + /* Dimension: width & height */ + MMIO_OUT32(VIA_REG_DIMENSION, + (((rect->height - 1) << 16) | (rect->width - 1))); + /* Forground color or Destination color */ + MMIO_OUT32(VIA_REG_FGCOLOR, col); + /* GE Command */ + MMIO_OUT32(VIA_REG_GECMD, (0x01 | 0x2000 | (rop << 24))); + +} + +static void viafb_copyarea(struct fb_info *info, + const struct fb_copyarea *area) +{ + u32 dy = area->dy, sy = area->sy, direction = 0x0; + u32 sx = area->sx, dx = area->dx, width = area->width; + int pitch; + + DEBUG_MSG(KERN_INFO "viafb_copyarea!!\n"); + + if (!viafb_accel) + return cfb_copyarea(info, area); + + if (!area->width || !area->height) + return; + + if (sy < dy) { + dy += area->height - 1; + sy += area->height - 1; + direction |= 0x4000; + } + + if (sx < dx) { + dx += width - 1; + sx += width - 1; + direction |= 0x8000; + } + + /* Source Base Address */ + /*MMIO_OUT32(VIA_REG_SRCBASE, 0x0); */ + MMIO_OUT32(VIA_REG_SRCBASE, + ((u32) (info->screen_base) - (u32) viafb_FB_MM) >> 3); + /* Destination Base Address */ + /*MMIO_OUT32(VIA_REG_DSTBASE, 0x0); */ + MMIO_OUT32(VIA_REG_DSTBASE, + ((u32) (info->screen_base) - (u32) viafb_FB_MM) >> 3); + /* Pitch */ + pitch = (info->var.xres_virtual + 7) & ~7; + /* VIA_PITCH_ENABLE can be omitted now. */ + MMIO_OUT32(VIA_REG_PITCH, + VIA_PITCH_ENABLE | + (((pitch * + info->var.bits_per_pixel >> 3) >> 3) | (((pitch * + info->var. + bits_per_pixel + >> 3) >> 3) + << 16))); + /* BitBlt Source Address */ + MMIO_OUT32(VIA_REG_SRCPOS, ((sy << 16) | sx)); + /* BitBlt Destination Address */ + MMIO_OUT32(VIA_REG_DSTPOS, ((dy << 16) | dx)); + /* Dimension: width & height */ + MMIO_OUT32(VIA_REG_DIMENSION, + (((area->height - 1) << 16) | (area->width - 1))); + /* GE Command */ + MMIO_OUT32(VIA_REG_GECMD, (0x01 | direction | (0xCC << 24))); + +} + +static void viafb_imageblit(struct fb_info *info, + const struct fb_image *image) +{ + u32 size, bg_col = 0, fg_col = 0, *udata; + int i; + int pitch; + + if (!viafb_accel) + return cfb_imageblit(info, image); + + udata = (u32 *) image->data; + + switch (info->var.bits_per_pixel) { + case 8: + bg_col = image->bg_color; + fg_col = image->fg_color; + break; + case 16: + bg_col = ((u32 *) (info->pseudo_palette))[image->bg_color]; + fg_col = ((u32 *) (info->pseudo_palette))[image->fg_color]; + break; + case 32: + bg_col = ((u32 *) (info->pseudo_palette))[image->bg_color]; + fg_col = ((u32 *) (info->pseudo_palette))[image->fg_color]; + break; + } + size = image->width * image->height; + + /* Source Base Address */ + MMIO_OUT32(VIA_REG_SRCBASE, 0x0); + /* Destination Base Address */ + /*MMIO_OUT32(VIA_REG_DSTBASE, 0x0); */ + MMIO_OUT32(VIA_REG_DSTBASE, + ((u32) (info->screen_base) - (u32) viafb_FB_MM) >> 3); + /* Pitch */ + pitch = (info->var.xres_virtual + 7) & ~7; + MMIO_OUT32(VIA_REG_PITCH, + VIA_PITCH_ENABLE | + (((pitch * + info->var.bits_per_pixel >> 3) >> 3) | (((pitch * + info->var. + bits_per_pixel + >> 3) >> 3) + << 16))); + /* BitBlt Source Address */ + MMIO_OUT32(VIA_REG_SRCPOS, 0x0); + /* BitBlt Destination Address */ + MMIO_OUT32(VIA_REG_DSTPOS, ((image->dy << 16) | image->dx)); + /* Dimension: width & height */ + MMIO_OUT32(VIA_REG_DIMENSION, + (((image->height - 1) << 16) | (image->width - 1))); + /* fb color */ + MMIO_OUT32(VIA_REG_FGCOLOR, fg_col); + /* bg color */ + MMIO_OUT32(VIA_REG_BGCOLOR, bg_col); + /* GE Command */ + MMIO_OUT32(VIA_REG_GECMD, 0xCC020142); + + for (i = 0; i < size / 4; i++) { + MMIO_OUT32(VIA_MMIO_BLTBASE, *udata); + udata++; + } + +} + +static int viafb_cursor(struct fb_info *info, struct fb_cursor *cursor) +{ + u8 data[CURSOR_SIZE / 8]; + u32 data_bak[CURSOR_SIZE / 32]; + u32 temp, xx, yy, bg_col = 0, fg_col = 0; + int size, i, j = 0; + static int hw_cursor; + struct viafb_par *p_viafb_par; + + if (viafb_accel) + hw_cursor = 1; + + if (!viafb_accel) { + if (hw_cursor) { + viafb_show_hw_cursor(info, HW_Cursor_OFF); + hw_cursor = 0; + } + return -ENODEV; + } + + if ((((struct viafb_par *)(info->par))->iga_path == IGA2) + && (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266)) + return -ENODEV; + + /* When duoview and using lcd , use soft cursor */ + if (viafb_LCD_ON || ((struct viafb_par *)(info->par))->duoview) + return -ENODEV; + + viafb_show_hw_cursor(info, HW_Cursor_OFF); + viacursor = *cursor; + + if (cursor->set & FB_CUR_SETHOT) { + viacursor.hot = cursor->hot; + temp = ((viacursor.hot.x) << 16) + viacursor.hot.y; + MMIO_OUT32(VIA_REG_CURSOR_ORG, temp); + } + + if (cursor->set & FB_CUR_SETPOS) { + viacursor.image.dx = cursor->image.dx; + viacursor.image.dy = cursor->image.dy; + yy = cursor->image.dy - info->var.yoffset; + xx = cursor->image.dx - info->var.xoffset; + temp = yy & 0xFFFF; + temp |= (xx << 16); + MMIO_OUT32(VIA_REG_CURSOR_POS, temp); + } + + if (cursor->set & FB_CUR_SETSIZE) { + temp = MMIO_IN32(VIA_REG_CURSOR_MODE); + + if ((cursor->image.width <= 32) + && (cursor->image.height <= 32)) { + MAX_CURS = 32; + temp |= 0x2; + } else if ((cursor->image.width <= 64) + && (cursor->image.height <= 64)) { + MAX_CURS = 64; + temp &= 0xFFFFFFFD; + } else { + DEBUG_MSG(KERN_INFO + "The cursor image i |