Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved. |
| 3 | * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved. |
| 4 | |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public |
| 7 | * License as published by the Free Software Foundation; |
| 8 | * either version 2, or (at your option) any later version. |
| 9 | |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even |
| 12 | * the implied warranty of MERCHANTABILITY or FITNESS FOR |
| 13 | * A PARTICULAR PURPOSE.See the GNU General Public License |
| 14 | * for more details. |
| 15 | |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., |
| 19 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 20 | */ |
| 21 | |
| 22 | #include <linux/module.h> |
| 23 | #define _MASTER_FILE |
| 24 | |
| 25 | #include "global.h" |
| 26 | |
| 27 | static int MAX_CURS = 32; |
| 28 | static struct fb_var_screeninfo default_var; |
| 29 | static char *viafb_name = "Via"; |
| 30 | static u32 pseudo_pal[17]; |
| 31 | |
| 32 | /* video mode */ |
| 33 | static char *viafb_mode = "640x480"; |
| 34 | static char *viafb_mode1 = "640x480"; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 35 | |
| 36 | /* Added for specifying active devices.*/ |
| 37 | char *viafb_active_dev = ""; |
| 38 | |
| 39 | /* Added for specifying video on devices.*/ |
| 40 | char *viafb_video_dev = ""; |
| 41 | |
| 42 | /*Added for specify lcd output port*/ |
| 43 | char *viafb_lcd_port = ""; |
| 44 | char *viafb_dvi_port = ""; |
| 45 | |
| 46 | static void viafb_set_device(struct device_t active_dev); |
| 47 | static int apply_device_setting(struct viafb_ioctl_setting setting_info, |
| 48 | struct fb_info *info); |
| 49 | static void apply_second_mode_setting(struct fb_var_screeninfo |
| 50 | *sec_var); |
| 51 | static void retrieve_device_setting(struct viafb_ioctl_setting |
| 52 | *setting_info); |
| 53 | static void viafb_set_video_device(u32 video_dev_info); |
| 54 | static void viafb_get_video_device(u32 *video_dev_info); |
| 55 | |
| 56 | /* Mode information */ |
| 57 | static const struct viafb_modeinfo viafb_modentry[] = { |
Florian Tobias Schandinat | 5215944 | 2009-08-06 15:07:34 -0700 | [diff] [blame] | 58 | {480, 640, VIA_RES_480X640}, |
| 59 | {640, 480, VIA_RES_640X480}, |
| 60 | {800, 480, VIA_RES_800X480}, |
| 61 | {800, 600, VIA_RES_800X600}, |
| 62 | {1024, 768, VIA_RES_1024X768}, |
| 63 | {1152, 864, VIA_RES_1152X864}, |
| 64 | {1280, 1024, VIA_RES_1280X1024}, |
| 65 | {1600, 1200, VIA_RES_1600X1200}, |
| 66 | {1440, 1050, VIA_RES_1440X1050}, |
| 67 | {1280, 768, VIA_RES_1280X768,}, |
| 68 | {1280, 800, VIA_RES_1280X800}, |
| 69 | {1280, 960, VIA_RES_1280X960}, |
| 70 | {1920, 1440, VIA_RES_1920X1440}, |
| 71 | {848, 480, VIA_RES_848X480}, |
| 72 | {1400, 1050, VIA_RES_1400X1050}, |
| 73 | {720, 480, VIA_RES_720X480}, |
| 74 | {720, 576, VIA_RES_720X576}, |
| 75 | {1024, 512, VIA_RES_1024X512}, |
| 76 | {1024, 576, VIA_RES_1024X576}, |
| 77 | {1024, 600, VIA_RES_1024X600}, |
| 78 | {1280, 720, VIA_RES_1280X720}, |
| 79 | {1920, 1080, VIA_RES_1920X1080}, |
| 80 | {1366, 768, VIA_RES_1368X768}, |
| 81 | {1680, 1050, VIA_RES_1680X1050}, |
| 82 | {960, 600, VIA_RES_960X600}, |
| 83 | {1000, 600, VIA_RES_1000X600}, |
| 84 | {1024, 576, VIA_RES_1024X576}, |
| 85 | {1024, 600, VIA_RES_1024X600}, |
| 86 | {1088, 612, VIA_RES_1088X612}, |
| 87 | {1152, 720, VIA_RES_1152X720}, |
| 88 | {1200, 720, VIA_RES_1200X720}, |
| 89 | {1280, 600, VIA_RES_1280X600}, |
| 90 | {1360, 768, VIA_RES_1360X768}, |
| 91 | {1440, 900, VIA_RES_1440X900}, |
| 92 | {1600, 900, VIA_RES_1600X900}, |
| 93 | {1600, 1024, VIA_RES_1600X1024}, |
| 94 | {1792, 1344, VIA_RES_1792X1344}, |
| 95 | {1856, 1392, VIA_RES_1856X1392}, |
| 96 | {1920, 1200, VIA_RES_1920X1200}, |
| 97 | {2048, 1536, VIA_RES_2048X1536}, |
| 98 | {0, 0, VIA_RES_INVALID} |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | static struct fb_ops viafb_ops; |
| 102 | |
| 103 | static int viafb_update_fix(struct fb_fix_screeninfo *fix, struct fb_info *info) |
| 104 | { |
| 105 | struct viafb_par *ppar; |
| 106 | ppar = info->par; |
| 107 | |
| 108 | DEBUG_MSG(KERN_INFO "viafb_update_fix!\n"); |
| 109 | |
| 110 | fix->visual = |
| 111 | ppar->bpp == 8 ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR; |
| 112 | fix->line_length = ppar->linelength; |
| 113 | |
| 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | |
| 118 | static void viafb_setup_fixinfo(struct fb_fix_screeninfo *fix, |
| 119 | struct viafb_par *viaparinfo) |
| 120 | { |
| 121 | memset(fix, 0, sizeof(struct fb_fix_screeninfo)); |
| 122 | strcpy(fix->id, viafb_name); |
| 123 | |
| 124 | fix->smem_start = viaparinfo->fbmem; |
| 125 | fix->smem_len = viaparinfo->fbmem_free; |
| 126 | fix->mmio_start = viaparinfo->mmio_base; |
| 127 | fix->mmio_len = viaparinfo->mmio_len; |
| 128 | |
| 129 | fix->type = FB_TYPE_PACKED_PIXELS; |
| 130 | fix->type_aux = 0; |
| 131 | |
| 132 | fix->xpanstep = fix->ywrapstep = 0; |
| 133 | fix->ypanstep = 1; |
| 134 | |
| 135 | /* Just tell the accel name */ |
| 136 | viafbinfo->fix.accel = FB_ACCEL_VIA_UNICHROME; |
| 137 | } |
| 138 | static int viafb_open(struct fb_info *info, int user) |
| 139 | { |
| 140 | DEBUG_MSG(KERN_INFO "viafb_open!\n"); |
| 141 | return 0; |
| 142 | } |
| 143 | |
| 144 | static int viafb_release(struct fb_info *info, int user) |
| 145 | { |
| 146 | DEBUG_MSG(KERN_INFO "viafb_release!\n"); |
| 147 | return 0; |
| 148 | } |
| 149 | |
| 150 | static void viafb_update_viafb_par(struct fb_info *info) |
| 151 | { |
| 152 | struct viafb_par *ppar; |
| 153 | |
| 154 | ppar = info->par; |
| 155 | ppar->bpp = info->var.bits_per_pixel; |
| 156 | ppar->linelength = ((info->var.xres_virtual + 7) & ~7) * ppar->bpp / 8; |
| 157 | ppar->hres = info->var.xres; |
| 158 | ppar->vres = info->var.yres; |
| 159 | ppar->xoffset = info->var.xoffset; |
| 160 | ppar->yoffset = info->var.yoffset; |
| 161 | } |
| 162 | |
| 163 | static int viafb_check_var(struct fb_var_screeninfo *var, |
| 164 | struct fb_info *info) |
| 165 | { |
| 166 | int vmode_index, htotal, vtotal; |
| 167 | struct viafb_par *ppar; |
| 168 | u32 long_refresh; |
| 169 | struct viafb_par *p_viafb_par; |
| 170 | ppar = info->par; |
| 171 | |
| 172 | |
| 173 | DEBUG_MSG(KERN_INFO "viafb_check_var!\n"); |
| 174 | /* Sanity check */ |
| 175 | /* HW neither support interlacte nor double-scaned mode */ |
| 176 | if (var->vmode & FB_VMODE_INTERLACED || var->vmode & FB_VMODE_DOUBLE) |
| 177 | return -EINVAL; |
| 178 | |
Florian Tobias Schandinat | 5215944 | 2009-08-06 15:07:34 -0700 | [diff] [blame] | 179 | vmode_index = viafb_get_mode_index(var->xres, var->yres); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 180 | if (vmode_index == VIA_RES_INVALID) { |
| 181 | DEBUG_MSG(KERN_INFO |
| 182 | "viafb: Mode %dx%dx%d not supported!!\n", |
| 183 | var->xres, var->yres, var->bits_per_pixel); |
| 184 | return -EINVAL; |
| 185 | } |
| 186 | |
| 187 | if (24 == var->bits_per_pixel) |
| 188 | var->bits_per_pixel = 32; |
| 189 | |
| 190 | if (var->bits_per_pixel != 8 && var->bits_per_pixel != 16 && |
| 191 | var->bits_per_pixel != 32) |
| 192 | return -EINVAL; |
| 193 | |
| 194 | if ((var->xres_virtual * (var->bits_per_pixel >> 3)) & 0x1F) |
| 195 | /*32 pixel alignment */ |
| 196 | var->xres_virtual = (var->xres_virtual + 31) & ~31; |
| 197 | if (var->xres_virtual * var->yres_virtual * var->bits_per_pixel / 8 > |
| 198 | ppar->memsize) |
| 199 | return -EINVAL; |
| 200 | |
| 201 | /* Based on var passed in to calculate the refresh, |
| 202 | * because our driver use some modes special. |
| 203 | */ |
| 204 | htotal = var->xres + var->left_margin + |
| 205 | var->right_margin + var->hsync_len; |
| 206 | vtotal = var->yres + var->upper_margin + |
| 207 | var->lower_margin + var->vsync_len; |
| 208 | long_refresh = 1000000000UL / var->pixclock * 1000; |
| 209 | long_refresh /= (htotal * vtotal); |
| 210 | |
| 211 | viafb_refresh = viafb_get_refresh(var->xres, var->yres, long_refresh); |
| 212 | |
| 213 | /* Adjust var according to our driver's own table */ |
| 214 | viafb_fill_var_timing_info(var, viafb_refresh, vmode_index); |
| 215 | |
| 216 | /* This is indeed a patch for VT3353 */ |
| 217 | if (!info->par) |
| 218 | return -1; |
| 219 | p_viafb_par = (struct viafb_par *)info->par; |
| 220 | if (p_viafb_par->chip_info->gfx_chip_name == UNICHROME_VX800) |
| 221 | var->accel_flags = 0; |
| 222 | |
| 223 | return 0; |
| 224 | } |
| 225 | |
| 226 | static int viafb_set_par(struct fb_info *info) |
| 227 | { |
| 228 | int vmode_index; |
| 229 | int vmode_index1 = 0; |
| 230 | DEBUG_MSG(KERN_INFO "viafb_set_par!\n"); |
| 231 | |
| 232 | viafb_update_device_setting(info->var.xres, info->var.yres, |
| 233 | info->var.bits_per_pixel, viafb_refresh, 0); |
| 234 | |
Florian Tobias Schandinat | 5215944 | 2009-08-06 15:07:34 -0700 | [diff] [blame] | 235 | vmode_index = viafb_get_mode_index(info->var.xres, info->var.yres); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 236 | |
| 237 | if (viafb_SAMM_ON == 1) { |
| 238 | DEBUG_MSG(KERN_INFO |
| 239 | "viafb_second_xres = %d, viafb_second_yres = %d, bpp = %d\n", |
| 240 | viafb_second_xres, viafb_second_yres, viafb_bpp1); |
| 241 | vmode_index1 = viafb_get_mode_index(viafb_second_xres, |
Florian Tobias Schandinat | 5215944 | 2009-08-06 15:07:34 -0700 | [diff] [blame] | 242 | viafb_second_yres); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 243 | DEBUG_MSG(KERN_INFO "->viafb_SAMM_ON: index=%d\n", |
| 244 | vmode_index1); |
| 245 | |
| 246 | viafb_update_device_setting(viafb_second_xres, |
| 247 | viafb_second_yres, viafb_bpp1, viafb_refresh1, 1); |
| 248 | } |
| 249 | |
| 250 | if (vmode_index != VIA_RES_INVALID) { |
| 251 | viafb_setmode(vmode_index, info->var.xres, info->var.yres, |
| 252 | info->var.bits_per_pixel, vmode_index1, |
| 253 | viafb_second_xres, viafb_second_yres, viafb_bpp1); |
| 254 | |
| 255 | /*We should set memory offset according virtual_x */ |
| 256 | /*Fix me:put this function into viafb_setmode */ |
| 257 | viafb_memory_pitch_patch(info); |
| 258 | |
| 259 | /* Update ***fb_par information */ |
| 260 | viafb_update_viafb_par(info); |
| 261 | |
| 262 | /* Update other fixed information */ |
| 263 | viafb_update_fix(&info->fix, info); |
| 264 | viafb_bpp = info->var.bits_per_pixel; |
| 265 | /* Update viafb_accel, it is necessary to our 2D accelerate */ |
| 266 | viafb_accel = info->var.accel_flags; |
| 267 | |
| 268 | if (viafb_accel) |
| 269 | viafb_set_2d_color_depth(info->var.bits_per_pixel); |
| 270 | } |
| 271 | |
| 272 | return 0; |
| 273 | } |
| 274 | |
| 275 | /* Set one color register */ |
| 276 | static int viafb_setcolreg(unsigned regno, unsigned red, unsigned green, |
| 277 | unsigned blue, unsigned transp, struct fb_info *info) |
| 278 | { |
| 279 | u8 sr1a, sr1b, cr67, cr6a, rev = 0, shift = 10; |
| 280 | unsigned cmap_entries = (info->var.bits_per_pixel == 8) ? 256 : 16; |
| 281 | DEBUG_MSG(KERN_INFO "viafb_setcolreg!\n"); |
| 282 | if (regno >= cmap_entries) |
| 283 | return 1; |
| 284 | if (UNICHROME_CLE266 == viaparinfo->chip_info->gfx_chip_name) { |
| 285 | /* |
| 286 | * Read PCI bus 0,dev 0,function 0,index 0xF6 to get chip rev. |
| 287 | */ |
| 288 | outl(0x80000000 | (0xf6 & ~3), (unsigned long)0xCF8); |
| 289 | rev = (inl((unsigned long)0xCFC) >> ((0xf6 & 3) * 8)) & 0xff; |
| 290 | } |
| 291 | switch (info->var.bits_per_pixel) { |
| 292 | case 8: |
| 293 | outb(0x1A, 0x3C4); |
| 294 | sr1a = inb(0x3C5); |
| 295 | outb(0x1B, 0x3C4); |
| 296 | sr1b = inb(0x3C5); |
| 297 | outb(0x67, 0x3D4); |
| 298 | cr67 = inb(0x3D5); |
| 299 | outb(0x6A, 0x3D4); |
| 300 | cr6a = inb(0x3D5); |
| 301 | |
| 302 | /* Map the 3C6/7/8/9 to the IGA2 */ |
| 303 | outb(0x1A, 0x3C4); |
| 304 | outb(sr1a | 0x01, 0x3C5); |
| 305 | /* Second Display Engine colck always on */ |
| 306 | outb(0x1B, 0x3C4); |
| 307 | outb(sr1b | 0x80, 0x3C5); |
| 308 | /* Second Display Color Depth 8 */ |
| 309 | outb(0x67, 0x3D4); |
| 310 | outb(cr67 & 0x3F, 0x3D5); |
| 311 | outb(0x6A, 0x3D4); |
| 312 | /* Second Display Channel Reset CR6A[6]) */ |
| 313 | outb(cr6a & 0xBF, 0x3D5); |
| 314 | /* Second Display Channel Enable CR6A[7] */ |
| 315 | outb(cr6a | 0x80, 0x3D5); |
| 316 | /* Second Display Channel stop reset) */ |
| 317 | outb(cr6a | 0x40, 0x3D5); |
| 318 | |
| 319 | /* Bit mask of palette */ |
| 320 | outb(0xFF, 0x3c6); |
| 321 | /* Write one register of IGA2 */ |
| 322 | outb(regno, 0x3C8); |
| 323 | if (UNICHROME_CLE266 == viaparinfo->chip_info->gfx_chip_name && |
| 324 | rev >= 15) { |
| 325 | shift = 8; |
| 326 | viafb_write_reg_mask(CR6A, VIACR, BIT5, BIT5); |
| 327 | viafb_write_reg_mask(SR15, VIASR, BIT7, BIT7); |
| 328 | } else { |
| 329 | shift = 10; |
| 330 | viafb_write_reg_mask(CR6A, VIACR, 0, BIT5); |
| 331 | viafb_write_reg_mask(SR15, VIASR, 0, BIT7); |
| 332 | } |
| 333 | outb(red >> shift, 0x3C9); |
| 334 | outb(green >> shift, 0x3C9); |
| 335 | outb(blue >> shift, 0x3C9); |
| 336 | |
| 337 | /* Map the 3C6/7/8/9 to the IGA1 */ |
| 338 | outb(0x1A, 0x3C4); |
| 339 | outb(sr1a & 0xFE, 0x3C5); |
| 340 | /* Bit mask of palette */ |
| 341 | outb(0xFF, 0x3c6); |
| 342 | /* Write one register of IGA1 */ |
| 343 | outb(regno, 0x3C8); |
| 344 | outb(red >> shift, 0x3C9); |
| 345 | outb(green >> shift, 0x3C9); |
| 346 | outb(blue >> shift, 0x3C9); |
| 347 | |
| 348 | outb(0x1A, 0x3C4); |
| 349 | outb(sr1a, 0x3C5); |
| 350 | outb(0x1B, 0x3C4); |
| 351 | outb(sr1b, 0x3C5); |
| 352 | outb(0x67, 0x3D4); |
| 353 | outb(cr67, 0x3D5); |
| 354 | outb(0x6A, 0x3D4); |
| 355 | outb(cr6a, 0x3D5); |
| 356 | break; |
| 357 | case 16: |
| 358 | ((u32 *) info->pseudo_palette)[regno] = (red & 0xF800) | |
| 359 | ((green & 0xFC00) >> 5) | ((blue & 0xF800) >> 11); |
| 360 | break; |
| 361 | case 32: |
| 362 | ((u32 *) info->pseudo_palette)[regno] = |
| 363 | ((transp & 0xFF00) << 16) | |
| 364 | ((red & 0xFF00) << 8) | |
| 365 | ((green & 0xFF00)) | ((blue & 0xFF00) >> 8); |
| 366 | break; |
| 367 | } |
| 368 | |
| 369 | return 0; |
| 370 | |
| 371 | } |
| 372 | |
| 373 | /*CALLED BY: fb_set_cmap */ |
| 374 | /* fb_set_var, pass 256 colors */ |
| 375 | /*CALLED BY: fb_set_cmap */ |
| 376 | /* fbcon_set_palette, pass 16 colors */ |
| 377 | static int viafb_setcmap(struct fb_cmap *cmap, struct fb_info *info) |
| 378 | { |
| 379 | u32 len = cmap->len; |
| 380 | u32 i; |
| 381 | u16 *pred = cmap->red; |
| 382 | u16 *pgreen = cmap->green; |
| 383 | u16 *pblue = cmap->blue; |
| 384 | u16 *ptransp = cmap->transp; |
| 385 | u8 sr1a, sr1b, cr67, cr6a, rev = 0, shift = 10; |
| 386 | if (len > 256) |
| 387 | return 1; |
| 388 | if (UNICHROME_CLE266 == viaparinfo->chip_info->gfx_chip_name) { |
| 389 | /* |
| 390 | * Read PCI bus 0, dev 0, function 0, index 0xF6 to get chip |
| 391 | * rev. |
| 392 | */ |
| 393 | outl(0x80000000 | (0xf6 & ~3), (unsigned long)0xCF8); |
| 394 | rev = (inl((unsigned long)0xCFC) >> ((0xf6 & 3) * 8)) & 0xff; |
| 395 | } |
| 396 | switch (info->var.bits_per_pixel) { |
| 397 | case 8: |
| 398 | outb(0x1A, 0x3C4); |
| 399 | sr1a = inb(0x3C5); |
| 400 | outb(0x1B, 0x3C4); |
| 401 | sr1b = inb(0x3C5); |
| 402 | outb(0x67, 0x3D4); |
| 403 | cr67 = inb(0x3D5); |
| 404 | outb(0x6A, 0x3D4); |
| 405 | cr6a = inb(0x3D5); |
| 406 | /* Map the 3C6/7/8/9 to the IGA2 */ |
| 407 | outb(0x1A, 0x3C4); |
| 408 | outb(sr1a | 0x01, 0x3C5); |
| 409 | outb(0x1B, 0x3C4); |
| 410 | /* Second Display Engine colck always on */ |
| 411 | outb(sr1b | 0x80, 0x3C5); |
| 412 | outb(0x67, 0x3D4); |
| 413 | /* Second Display Color Depth 8 */ |
| 414 | outb(cr67 & 0x3F, 0x3D5); |
| 415 | outb(0x6A, 0x3D4); |
| 416 | /* Second Display Channel Reset CR6A[6]) */ |
| 417 | outb(cr6a & 0xBF, 0x3D5); |
| 418 | /* Second Display Channel Enable CR6A[7] */ |
| 419 | outb(cr6a | 0x80, 0x3D5); |
| 420 | /* Second Display Channel stop reset) */ |
| 421 | outb(cr6a | 0xC0, 0x3D5); |
| 422 | |
| 423 | /* Bit mask of palette */ |
| 424 | outb(0xFF, 0x3c6); |
| 425 | outb(0x00, 0x3C8); |
| 426 | if (UNICHROME_CLE266 == viaparinfo->chip_info->gfx_chip_name && |
| 427 | rev >= 15) { |
| 428 | shift = 8; |
| 429 | viafb_write_reg_mask(CR6A, VIACR, BIT5, BIT5); |
| 430 | viafb_write_reg_mask(SR15, VIASR, BIT7, BIT7); |
| 431 | } else { |
| 432 | shift = 10; |
| 433 | viafb_write_reg_mask(CR6A, VIACR, 0, BIT5); |
| 434 | viafb_write_reg_mask(SR15, VIASR, 0, BIT7); |
| 435 | } |
| 436 | for (i = 0; i < len; i++) { |
| 437 | outb((*(pred + i)) >> shift, 0x3C9); |
| 438 | outb((*(pgreen + i)) >> shift, 0x3C9); |
| 439 | outb((*(pblue + i)) >> shift, 0x3C9); |
| 440 | } |
| 441 | |
| 442 | outb(0x1A, 0x3C4); |
| 443 | /* Map the 3C6/7/8/9 to the IGA1 */ |
| 444 | outb(sr1a & 0xFE, 0x3C5); |
| 445 | /* Bit mask of palette */ |
| 446 | outb(0xFF, 0x3c6); |
| 447 | outb(0x00, 0x3C8); |
| 448 | for (i = 0; i < len; i++) { |
| 449 | outb((*(pred + i)) >> shift, 0x3C9); |
| 450 | outb((*(pgreen + i)) >> shift, 0x3C9); |
| 451 | outb((*(pblue + i)) >> shift, 0x3C9); |
| 452 | } |
| 453 | |
| 454 | outb(0x1A, 0x3C4); |
| 455 | outb(sr1a, 0x3C5); |
| 456 | outb(0x1B, 0x3C4); |
| 457 | outb(sr1b, 0x3C5); |
| 458 | outb(0x67, 0x3D4); |
| 459 | outb(cr67, 0x3D5); |
| 460 | outb(0x6A, 0x3D4); |
| 461 | outb(cr6a, 0x3D5); |
| 462 | break; |
| 463 | case 16: |
| 464 | if (len > 17) |
| 465 | return 0; /* Because static u32 pseudo_pal[17]; */ |
| 466 | for (i = 0; i < len; i++) |
| 467 | ((u32 *) info->pseudo_palette)[i] = |
| 468 | (*(pred + i) & 0xF800) | |
| 469 | ((*(pgreen + i) & 0xFC00) >> 5) | |
| 470 | ((*(pblue + i) & 0xF800) >> 11); |
| 471 | break; |
| 472 | case 32: |
| 473 | if (len > 17) |
| 474 | return 0; |
| 475 | if (ptransp) { |
| 476 | for (i = 0; i < len; i++) |
| 477 | ((u32 *) info->pseudo_palette)[i] = |
| 478 | ((*(ptransp + i) & 0xFF00) << 16) | |
| 479 | ((*(pred + i) & 0xFF00) << 8) | |
| 480 | ((*(pgreen + i) & 0xFF00)) | |
| 481 | ((*(pblue + i) & 0xFF00) >> 8); |
| 482 | } else { |
| 483 | for (i = 0; i < len; i++) |
| 484 | ((u32 *) info->pseudo_palette)[i] = |
| 485 | 0x00000000 | |
| 486 | ((*(pred + i) & 0xFF00) << 8) | |
| 487 | ((*(pgreen + i) & 0xFF00)) | |
| 488 | ((*(pblue + i) & 0xFF00) >> 8); |
| 489 | } |
| 490 | break; |
| 491 | } |
| 492 | return 0; |
| 493 | } |
| 494 | |
| 495 | static int viafb_pan_display(struct fb_var_screeninfo *var, |
| 496 | struct fb_info *info) |
| 497 | { |
| 498 | unsigned int offset; |
| 499 | |
| 500 | DEBUG_MSG(KERN_INFO "viafb_pan_display!\n"); |
| 501 | |
| 502 | offset = (var->xoffset + (var->yoffset * var->xres_virtual)) * |
| 503 | var->bits_per_pixel / 16; |
| 504 | |
| 505 | DEBUG_MSG(KERN_INFO "\nviafb_pan_display,offset =%d ", offset); |
| 506 | |
| 507 | viafb_write_reg_mask(0x48, 0x3d4, ((offset >> 24) & 0x3), 0x3); |
| 508 | viafb_write_reg_mask(0x34, 0x3d4, ((offset >> 16) & 0xff), 0xff); |
| 509 | viafb_write_reg_mask(0x0c, 0x3d4, ((offset >> 8) & 0xff), 0xff); |
| 510 | viafb_write_reg_mask(0x0d, 0x3d4, (offset & 0xff), 0xff); |
| 511 | |
| 512 | return 0; |
| 513 | } |
| 514 | |
| 515 | static int viafb_blank(int blank_mode, struct fb_info *info) |
| 516 | { |
| 517 | DEBUG_MSG(KERN_INFO "viafb_blank!\n"); |
| 518 | /* clear DPMS setting */ |
| 519 | |
| 520 | switch (blank_mode) { |
| 521 | case FB_BLANK_UNBLANK: |
| 522 | /* Screen: On, HSync: On, VSync: On */ |
| 523 | /* control CRT monitor power management */ |
| 524 | viafb_write_reg_mask(CR36, VIACR, 0x00, BIT4 + BIT5); |
| 525 | break; |
| 526 | case FB_BLANK_HSYNC_SUSPEND: |
| 527 | /* Screen: Off, HSync: Off, VSync: On */ |
| 528 | /* control CRT monitor power management */ |
| 529 | viafb_write_reg_mask(CR36, VIACR, 0x10, BIT4 + BIT5); |
| 530 | break; |
| 531 | case FB_BLANK_VSYNC_SUSPEND: |
| 532 | /* Screen: Off, HSync: On, VSync: Off */ |
| 533 | /* control CRT monitor power management */ |
| 534 | viafb_write_reg_mask(CR36, VIACR, 0x20, BIT4 + BIT5); |
| 535 | break; |
| 536 | case FB_BLANK_POWERDOWN: |
| 537 | /* Screen: Off, HSync: Off, VSync: Off */ |
| 538 | /* control CRT monitor power management */ |
| 539 | viafb_write_reg_mask(CR36, VIACR, 0x30, BIT4 + BIT5); |
| 540 | break; |
| 541 | } |
| 542 | |
| 543 | return 0; |
| 544 | } |
| 545 | |
| 546 | static int viafb_ioctl(struct fb_info *info, u_int cmd, u_long arg) |
| 547 | { |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 548 | union { |
| 549 | struct viafb_ioctl_mode viamode; |
| 550 | struct viafb_ioctl_samm viasamm; |
| 551 | struct viafb_driver_version driver_version; |
| 552 | struct fb_var_screeninfo sec_var; |
| 553 | struct _panel_size_pos_info panel_pos_size_para; |
| 554 | struct viafb_ioctl_setting viafb_setting; |
| 555 | struct device_t active_dev; |
| 556 | } u; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 557 | u32 state_info = 0; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 558 | u32 *viafb_gamma_table; |
| 559 | char driver_name[] = "viafb"; |
| 560 | |
| 561 | u32 __user *argp = (u32 __user *) arg; |
| 562 | u32 gpu32; |
| 563 | u32 video_dev_info = 0; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 564 | |
| 565 | DEBUG_MSG(KERN_INFO "viafb_ioctl: 0x%X !!\n", cmd); |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 566 | memset(&u, 0, sizeof(u)); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 567 | |
| 568 | switch (cmd) { |
| 569 | case VIAFB_GET_CHIP_INFO: |
| 570 | if (copy_to_user(argp, viaparinfo->chip_info, |
| 571 | sizeof(struct chip_information))) |
| 572 | return -EFAULT; |
| 573 | break; |
| 574 | case VIAFB_GET_INFO_SIZE: |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 575 | return put_user((u32)sizeof(struct viafb_ioctl_info), argp); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 576 | case VIAFB_GET_INFO: |
| 577 | return viafb_ioctl_get_viafb_info(arg); |
| 578 | case VIAFB_HOTPLUG: |
| 579 | return put_user(viafb_ioctl_hotplug(info->var.xres, |
| 580 | info->var.yres, |
| 581 | info->var.bits_per_pixel), argp); |
| 582 | case VIAFB_SET_HOTPLUG_FLAG: |
| 583 | if (copy_from_user(&gpu32, argp, sizeof(gpu32))) |
| 584 | return -EFAULT; |
| 585 | viafb_hotplug = (gpu32) ? 1 : 0; |
| 586 | break; |
| 587 | case VIAFB_GET_RESOLUTION: |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 588 | u.viamode.xres = (u32) viafb_hotplug_Xres; |
| 589 | u.viamode.yres = (u32) viafb_hotplug_Yres; |
| 590 | u.viamode.refresh = (u32) viafb_hotplug_refresh; |
| 591 | u.viamode.bpp = (u32) viafb_hotplug_bpp; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 592 | if (viafb_SAMM_ON == 1) { |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 593 | u.viamode.xres_sec = viafb_second_xres; |
| 594 | u.viamode.yres_sec = viafb_second_yres; |
| 595 | u.viamode.virtual_xres_sec = viafb_second_virtual_xres; |
| 596 | u.viamode.virtual_yres_sec = viafb_second_virtual_yres; |
| 597 | u.viamode.refresh_sec = viafb_refresh1; |
| 598 | u.viamode.bpp_sec = viafb_bpp1; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 599 | } else { |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 600 | u.viamode.xres_sec = 0; |
| 601 | u.viamode.yres_sec = 0; |
| 602 | u.viamode.virtual_xres_sec = 0; |
| 603 | u.viamode.virtual_yres_sec = 0; |
| 604 | u.viamode.refresh_sec = 0; |
| 605 | u.viamode.bpp_sec = 0; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 606 | } |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 607 | if (copy_to_user(argp, &u.viamode, sizeof(u.viamode))) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 608 | return -EFAULT; |
| 609 | break; |
| 610 | case VIAFB_GET_SAMM_INFO: |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 611 | u.viasamm.samm_status = viafb_SAMM_ON; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 612 | |
| 613 | if (viafb_SAMM_ON == 1) { |
| 614 | if (viafb_dual_fb) { |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 615 | u.viasamm.size_prim = viaparinfo->fbmem_free; |
| 616 | u.viasamm.size_sec = viaparinfo1->fbmem_free; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 617 | } else { |
| 618 | if (viafb_second_size) { |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 619 | u.viasamm.size_prim = |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 620 | viaparinfo->fbmem_free - |
| 621 | viafb_second_size * 1024 * 1024; |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 622 | u.viasamm.size_sec = |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 623 | viafb_second_size * 1024 * 1024; |
| 624 | } else { |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 625 | u.viasamm.size_prim = |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 626 | viaparinfo->fbmem_free >> 1; |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 627 | u.viasamm.size_sec = |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 628 | (viaparinfo->fbmem_free >> 1); |
| 629 | } |
| 630 | } |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 631 | u.viasamm.mem_base = viaparinfo->fbmem; |
| 632 | u.viasamm.offset_sec = viafb_second_offset; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 633 | } else { |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 634 | u.viasamm.size_prim = |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 635 | viaparinfo->memsize - viaparinfo->fbmem_used; |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 636 | u.viasamm.size_sec = 0; |
| 637 | u.viasamm.mem_base = viaparinfo->fbmem; |
| 638 | u.viasamm.offset_sec = 0; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 639 | } |
| 640 | |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 641 | if (copy_to_user(argp, &u.viasamm, sizeof(u.viasamm))) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 642 | return -EFAULT; |
| 643 | |
| 644 | break; |
| 645 | case VIAFB_TURN_ON_OUTPUT_DEVICE: |
| 646 | if (copy_from_user(&gpu32, argp, sizeof(gpu32))) |
| 647 | return -EFAULT; |
| 648 | if (gpu32 & CRT_Device) |
| 649 | viafb_crt_enable(); |
| 650 | if (gpu32 & DVI_Device) |
| 651 | viafb_dvi_enable(); |
| 652 | if (gpu32 & LCD_Device) |
| 653 | viafb_lcd_enable(); |
| 654 | break; |
| 655 | case VIAFB_TURN_OFF_OUTPUT_DEVICE: |
| 656 | if (copy_from_user(&gpu32, argp, sizeof(gpu32))) |
| 657 | return -EFAULT; |
| 658 | if (gpu32 & CRT_Device) |
| 659 | viafb_crt_disable(); |
| 660 | if (gpu32 & DVI_Device) |
| 661 | viafb_dvi_disable(); |
| 662 | if (gpu32 & LCD_Device) |
| 663 | viafb_lcd_disable(); |
| 664 | break; |
| 665 | case VIAFB_SET_DEVICE: |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 666 | if (copy_from_user(&u.active_dev, (void *)argp, |
| 667 | sizeof(u.active_dev))) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 668 | return -EFAULT; |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 669 | viafb_set_device(u.active_dev); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 670 | viafb_set_par(info); |
| 671 | break; |
| 672 | case VIAFB_GET_DEVICE: |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 673 | u.active_dev.crt = viafb_CRT_ON; |
| 674 | u.active_dev.dvi = viafb_DVI_ON; |
| 675 | u.active_dev.lcd = viafb_LCD_ON; |
| 676 | u.active_dev.samm = viafb_SAMM_ON; |
| 677 | u.active_dev.primary_dev = viafb_primary_dev; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 678 | |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 679 | u.active_dev.lcd_dsp_cent = viafb_lcd_dsp_method; |
| 680 | u.active_dev.lcd_panel_id = viafb_lcd_panel_id; |
| 681 | u.active_dev.lcd_mode = viafb_lcd_mode; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 682 | |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 683 | u.active_dev.xres = viafb_hotplug_Xres; |
| 684 | u.active_dev.yres = viafb_hotplug_Yres; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 685 | |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 686 | u.active_dev.xres1 = viafb_second_xres; |
| 687 | u.active_dev.yres1 = viafb_second_yres; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 688 | |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 689 | u.active_dev.bpp = viafb_bpp; |
| 690 | u.active_dev.bpp1 = viafb_bpp1; |
| 691 | u.active_dev.refresh = viafb_refresh; |
| 692 | u.active_dev.refresh1 = viafb_refresh1; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 693 | |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 694 | u.active_dev.epia_dvi = viafb_platform_epia_dvi; |
| 695 | u.active_dev.lcd_dual_edge = viafb_device_lcd_dualedge; |
| 696 | u.active_dev.bus_width = viafb_bus_width; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 697 | |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 698 | if (copy_to_user(argp, &u.active_dev, sizeof(u.active_dev))) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 699 | return -EFAULT; |
| 700 | break; |
| 701 | |
| 702 | case VIAFB_GET_DRIVER_VERSION: |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 703 | u.driver_version.iMajorNum = VERSION_MAJOR; |
| 704 | u.driver_version.iKernelNum = VERSION_KERNEL; |
| 705 | u.driver_version.iOSNum = VERSION_OS; |
| 706 | u.driver_version.iMinorNum = VERSION_MINOR; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 707 | |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 708 | if (copy_to_user(argp, &u.driver_version, |
| 709 | sizeof(u.driver_version))) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 710 | return -EFAULT; |
| 711 | |
| 712 | break; |
| 713 | |
| 714 | case VIAFB_SET_DEVICE_INFO: |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 715 | if (copy_from_user(&u.viafb_setting, |
| 716 | argp, sizeof(u.viafb_setting))) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 717 | return -EFAULT; |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 718 | if (apply_device_setting(u.viafb_setting, info) < 0) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 719 | return -EINVAL; |
| 720 | |
| 721 | break; |
| 722 | |
| 723 | case VIAFB_SET_SECOND_MODE: |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 724 | if (copy_from_user(&u.sec_var, argp, sizeof(u.sec_var))) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 725 | return -EFAULT; |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 726 | apply_second_mode_setting(&u.sec_var); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 727 | break; |
| 728 | |
| 729 | case VIAFB_GET_DEVICE_INFO: |
| 730 | |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 731 | retrieve_device_setting(&u.viafb_setting); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 732 | |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 733 | if (copy_to_user(argp, &u.viafb_setting, |
| 734 | sizeof(u.viafb_setting))) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 735 | return -EFAULT; |
| 736 | |
| 737 | break; |
| 738 | |
| 739 | case VIAFB_GET_DEVICE_SUPPORT: |
| 740 | viafb_get_device_support_state(&state_info); |
| 741 | if (put_user(state_info, argp)) |
| 742 | return -EFAULT; |
| 743 | break; |
| 744 | |
| 745 | case VIAFB_GET_DEVICE_CONNECT: |
| 746 | viafb_get_device_connect_state(&state_info); |
| 747 | if (put_user(state_info, argp)) |
| 748 | return -EFAULT; |
| 749 | break; |
| 750 | |
| 751 | case VIAFB_GET_PANEL_SUPPORT_EXPAND: |
| 752 | state_info = |
| 753 | viafb_lcd_get_support_expand_state(info->var.xres, |
| 754 | info->var.yres); |
| 755 | if (put_user(state_info, argp)) |
| 756 | return -EFAULT; |
| 757 | break; |
| 758 | |
| 759 | case VIAFB_GET_DRIVER_NAME: |
| 760 | if (copy_to_user(argp, driver_name, sizeof(driver_name))) |
| 761 | return -EFAULT; |
| 762 | break; |
| 763 | |
| 764 | case VIAFB_SET_GAMMA_LUT: |
| 765 | viafb_gamma_table = kmalloc(256 * sizeof(u32), GFP_KERNEL); |
| 766 | if (!viafb_gamma_table) |
| 767 | return -ENOMEM; |
| 768 | if (copy_from_user(viafb_gamma_table, argp, |
| 769 | sizeof(viafb_gamma_table))) { |
| 770 | kfree(viafb_gamma_table); |
| 771 | return -EFAULT; |
| 772 | } |
| 773 | viafb_set_gamma_table(viafb_bpp, viafb_gamma_table); |
| 774 | kfree(viafb_gamma_table); |
| 775 | break; |
| 776 | |
| 777 | case VIAFB_GET_GAMMA_LUT: |
| 778 | viafb_gamma_table = kmalloc(256 * sizeof(u32), GFP_KERNEL); |
| 779 | if (!viafb_gamma_table) |
| 780 | return -ENOMEM; |
| 781 | viafb_get_gamma_table(viafb_gamma_table); |
| 782 | if (copy_to_user(argp, viafb_gamma_table, |
| 783 | sizeof(viafb_gamma_table))) { |
| 784 | kfree(viafb_gamma_table); |
| 785 | return -EFAULT; |
| 786 | } |
| 787 | kfree(viafb_gamma_table); |
| 788 | break; |
| 789 | |
| 790 | case VIAFB_GET_GAMMA_SUPPORT_STATE: |
| 791 | viafb_get_gamma_support_state(viafb_bpp, &state_info); |
| 792 | if (put_user(state_info, argp)) |
| 793 | return -EFAULT; |
| 794 | break; |
| 795 | case VIAFB_SET_VIDEO_DEVICE: |
| 796 | get_user(video_dev_info, argp); |
| 797 | viafb_set_video_device(video_dev_info); |
| 798 | break; |
| 799 | case VIAFB_GET_VIDEO_DEVICE: |
| 800 | viafb_get_video_device(&video_dev_info); |
| 801 | if (put_user(video_dev_info, argp)) |
| 802 | return -EFAULT; |
| 803 | break; |
| 804 | case VIAFB_SYNC_SURFACE: |
| 805 | DEBUG_MSG(KERN_INFO "lobo VIAFB_SYNC_SURFACE\n"); |
| 806 | break; |
| 807 | case VIAFB_GET_DRIVER_CAPS: |
| 808 | break; |
| 809 | |
| 810 | case VIAFB_GET_PANEL_MAX_SIZE: |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 811 | if (copy_from_user(&u.panel_pos_size_para, argp, |
| 812 | sizeof(u.panel_pos_size_para))) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 813 | return -EFAULT; |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 814 | u.panel_pos_size_para.x = u.panel_pos_size_para.y = 0; |
| 815 | if (copy_to_user(argp, &u.panel_pos_size_para, |
| 816 | sizeof(u.panel_pos_size_para))) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 817 | return -EFAULT; |
| 818 | break; |
| 819 | case VIAFB_GET_PANEL_MAX_POSITION: |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 820 | if (copy_from_user(&u.panel_pos_size_para, argp, |
| 821 | sizeof(u.panel_pos_size_para))) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 822 | return -EFAULT; |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 823 | u.panel_pos_size_para.x = u.panel_pos_size_para.y = 0; |
| 824 | if (copy_to_user(argp, &u.panel_pos_size_para, |
| 825 | sizeof(u.panel_pos_size_para))) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 826 | return -EFAULT; |
| 827 | break; |
| 828 | |
| 829 | case VIAFB_GET_PANEL_POSITION: |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 830 | if (copy_from_user(&u.panel_pos_size_para, argp, |
| 831 | sizeof(u.panel_pos_size_para))) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 832 | return -EFAULT; |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 833 | u.panel_pos_size_para.x = u.panel_pos_size_para.y = 0; |
| 834 | if (copy_to_user(argp, &u.panel_pos_size_para, |
| 835 | sizeof(u.panel_pos_size_para))) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 836 | return -EFAULT; |
| 837 | break; |
| 838 | case VIAFB_GET_PANEL_SIZE: |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 839 | if (copy_from_user(&u.panel_pos_size_para, argp, |
| 840 | sizeof(u.panel_pos_size_para))) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 841 | return -EFAULT; |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 842 | u.panel_pos_size_para.x = u.panel_pos_size_para.y = 0; |
| 843 | if (copy_to_user(argp, &u.panel_pos_size_para, |
| 844 | sizeof(u.panel_pos_size_para))) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 845 | return -EFAULT; |
| 846 | break; |
| 847 | |
| 848 | case VIAFB_SET_PANEL_POSITION: |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 849 | if (copy_from_user(&u.panel_pos_size_para, argp, |
| 850 | sizeof(u.panel_pos_size_para))) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 851 | return -EFAULT; |
| 852 | break; |
| 853 | case VIAFB_SET_PANEL_SIZE: |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 854 | if (copy_from_user(&u.panel_pos_size_para, argp, |
| 855 | sizeof(u.panel_pos_size_para))) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 856 | return -EFAULT; |
| 857 | break; |
| 858 | |
| 859 | default: |
| 860 | return -EINVAL; |
| 861 | } |
| 862 | |
| 863 | return 0; |
| 864 | } |
| 865 | |
| 866 | static void viafb_fillrect(struct fb_info *info, |
| 867 | const struct fb_fillrect *rect) |
| 868 | { |
| 869 | u32 col = 0, rop = 0; |
| 870 | int pitch; |
| 871 | |
Hannes Eder | 2899bb0 | 2009-01-06 14:42:32 -0800 | [diff] [blame] | 872 | if (!viafb_accel) { |
| 873 | cfb_fillrect(info, rect); |
| 874 | return; |
| 875 | } |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 876 | |
| 877 | if (!rect->width || !rect->height) |
| 878 | return; |
| 879 | |
| 880 | switch (rect->rop) { |
| 881 | case ROP_XOR: |
| 882 | rop = 0x5A; |
| 883 | break; |
| 884 | case ROP_COPY: |
| 885 | default: |
| 886 | rop = 0xF0; |
| 887 | break; |
| 888 | } |
| 889 | |
| 890 | switch (info->var.bits_per_pixel) { |
| 891 | case 8: |
| 892 | col = rect->color; |
| 893 | break; |
| 894 | case 16: |
| 895 | col = ((u32 *) (info->pseudo_palette))[rect->color]; |
| 896 | break; |
| 897 | case 32: |
| 898 | col = ((u32 *) (info->pseudo_palette))[rect->color]; |
| 899 | break; |
| 900 | } |
| 901 | |
| 902 | /* BitBlt Source Address */ |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 903 | writel(0x0, viaparinfo->io_virt + VIA_REG_SRCPOS); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 904 | /* Source Base Address */ |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 905 | writel(0x0, viaparinfo->io_virt + VIA_REG_SRCBASE); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 906 | /* Destination Base Address */ |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 907 | writel(((unsigned long) (info->screen_base) - |
| 908 | (unsigned long) viafb_FB_MM) >> 3, |
| 909 | viaparinfo->io_virt + VIA_REG_DSTBASE); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 910 | /* Pitch */ |
| 911 | pitch = (info->var.xres_virtual + 7) & ~7; |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 912 | writel(VIA_PITCH_ENABLE | |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 913 | (((pitch * |
| 914 | info->var.bits_per_pixel >> 3) >> 3) | |
| 915 | (((pitch * info-> |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 916 | var.bits_per_pixel >> 3) >> 3) << 16)), |
| 917 | viaparinfo->io_virt + VIA_REG_PITCH); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 918 | /* BitBlt Destination Address */ |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 919 | writel(((rect->dy << 16) | rect->dx), |
| 920 | viaparinfo->io_virt + VIA_REG_DSTPOS); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 921 | /* Dimension: width & height */ |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 922 | writel((((rect->height - 1) << 16) | (rect->width - 1)), |
| 923 | viaparinfo->io_virt + VIA_REG_DIMENSION); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 924 | /* Forground color or Destination color */ |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 925 | writel(col, viaparinfo->io_virt + VIA_REG_FGCOLOR); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 926 | /* GE Command */ |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 927 | writel((0x01 | 0x2000 | (rop << 24)), |
| 928 | viaparinfo->io_virt + VIA_REG_GECMD); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 929 | |
| 930 | } |
| 931 | |
| 932 | static void viafb_copyarea(struct fb_info *info, |
| 933 | const struct fb_copyarea *area) |
| 934 | { |
| 935 | u32 dy = area->dy, sy = area->sy, direction = 0x0; |
| 936 | u32 sx = area->sx, dx = area->dx, width = area->width; |
| 937 | int pitch; |
| 938 | |
| 939 | DEBUG_MSG(KERN_INFO "viafb_copyarea!!\n"); |
| 940 | |
Hannes Eder | 2899bb0 | 2009-01-06 14:42:32 -0800 | [diff] [blame] | 941 | if (!viafb_accel) { |
| 942 | cfb_copyarea(info, area); |
| 943 | return; |
| 944 | } |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 945 | |
| 946 | if (!area->width || !area->height) |
| 947 | return; |
| 948 | |
| 949 | if (sy < dy) { |
| 950 | dy += area->height - 1; |
| 951 | sy += area->height - 1; |
| 952 | direction |= 0x4000; |
| 953 | } |
| 954 | |
| 955 | if (sx < dx) { |
| 956 | dx += width - 1; |
| 957 | sx += width - 1; |
| 958 | direction |= 0x8000; |
| 959 | } |
| 960 | |
| 961 | /* Source Base Address */ |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 962 | writel(((unsigned long) (info->screen_base) - |
| 963 | (unsigned long) viafb_FB_MM) >> 3, |
| 964 | viaparinfo->io_virt + VIA_REG_SRCBASE); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 965 | /* Destination Base Address */ |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 966 | writel(((unsigned long) (info->screen_base) - |
| 967 | (unsigned long) viafb_FB_MM) >> 3, |
| 968 | viaparinfo->io_virt + VIA_REG_DSTBASE); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 969 | /* Pitch */ |
| 970 | pitch = (info->var.xres_virtual + 7) & ~7; |
| 971 | /* VIA_PITCH_ENABLE can be omitted now. */ |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 972 | writel(VIA_PITCH_ENABLE | |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 973 | (((pitch * |
| 974 | info->var.bits_per_pixel >> 3) >> 3) | (((pitch * |
| 975 | info->var. |
| 976 | bits_per_pixel |
| 977 | >> 3) >> 3) |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 978 | << 16)), |
| 979 | viaparinfo->io_virt + VIA_REG_PITCH); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 980 | /* BitBlt Source Address */ |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 981 | writel(((sy << 16) | sx), viaparinfo->io_virt + VIA_REG_SRCPOS); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 982 | /* BitBlt Destination Address */ |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 983 | writel(((dy << 16) | dx), viaparinfo->io_virt + VIA_REG_DSTPOS); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 984 | /* Dimension: width & height */ |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 985 | writel((((area->height - 1) << 16) | (area->width - 1)), |
| 986 | viaparinfo->io_virt + VIA_REG_DIMENSION); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 987 | /* GE Command */ |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 988 | writel((0x01 | direction | (0xCC << 24)), |
| 989 | viaparinfo->io_virt + VIA_REG_GECMD); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 990 | |
| 991 | } |
| 992 | |
| 993 | static void viafb_imageblit(struct fb_info *info, |
| 994 | const struct fb_image *image) |
| 995 | { |
| 996 | u32 size, bg_col = 0, fg_col = 0, *udata; |
| 997 | int i; |
| 998 | int pitch; |
| 999 | |
Hannes Eder | 2899bb0 | 2009-01-06 14:42:32 -0800 | [diff] [blame] | 1000 | if (!viafb_accel) { |
| 1001 | cfb_imageblit(info, image); |
| 1002 | return; |
| 1003 | } |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1004 | |
| 1005 | udata = (u32 *) image->data; |
| 1006 | |
| 1007 | switch (info->var.bits_per_pixel) { |
| 1008 | case 8: |
| 1009 | bg_col = image->bg_color; |
| 1010 | fg_col = image->fg_color; |
| 1011 | break; |
| 1012 | case 16: |
| 1013 | bg_col = ((u32 *) (info->pseudo_palette))[image->bg_color]; |
| 1014 | fg_col = ((u32 *) (info->pseudo_palette))[image->fg_color]; |
| 1015 | break; |
| 1016 | case 32: |
| 1017 | bg_col = ((u32 *) (info->pseudo_palette))[image->bg_color]; |
| 1018 | fg_col = ((u32 *) (info->pseudo_palette))[image->fg_color]; |
| 1019 | break; |
| 1020 | } |
| 1021 | size = image->width * image->height; |
| 1022 | |
| 1023 | /* Source Base Address */ |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 1024 | writel(0x0, viaparinfo->io_virt + VIA_REG_SRCBASE); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1025 | /* Destination Base Address */ |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 1026 | writel(((unsigned long) (info->screen_base) - |
| 1027 | (unsigned long) viafb_FB_MM) >> 3, |
| 1028 | viaparinfo->io_virt + VIA_REG_DSTBASE); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1029 | /* Pitch */ |
| 1030 | pitch = (info->var.xres_virtual + 7) & ~7; |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 1031 | writel(VIA_PITCH_ENABLE | |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1032 | (((pitch * |
| 1033 | info->var.bits_per_pixel >> 3) >> 3) | (((pitch * |
| 1034 | info->var. |
| 1035 | bits_per_pixel |
| 1036 | >> 3) >> 3) |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 1037 | << 16)), |
| 1038 | viaparinfo->io_virt + VIA_REG_PITCH); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1039 | /* BitBlt Source Address */ |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 1040 | writel(0x0, viaparinfo->io_virt + VIA_REG_SRCPOS); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1041 | /* BitBlt Destination Address */ |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 1042 | writel(((image->dy << 16) | image->dx), |
| 1043 | viaparinfo->io_virt + VIA_REG_DSTPOS); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1044 | /* Dimension: width & height */ |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 1045 | writel((((image->height - 1) << 16) | (image->width - 1)), |
| 1046 | viaparinfo->io_virt + VIA_REG_DIMENSION); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1047 | /* fb color */ |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 1048 | writel(fg_col, viaparinfo->io_virt + VIA_REG_FGCOLOR); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1049 | /* bg color */ |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 1050 | writel(bg_col, viaparinfo->io_virt + VIA_REG_BGCOLOR); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1051 | /* GE Command */ |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 1052 | writel(0xCC020142, viaparinfo->io_virt + VIA_REG_GECMD); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1053 | |
| 1054 | for (i = 0; i < size / 4; i++) { |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 1055 | writel(*udata, viaparinfo->io_virt + VIA_MMIO_BLTBASE); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1056 | udata++; |
| 1057 | } |
| 1058 | |
| 1059 | } |
| 1060 | |
| 1061 | static int viafb_cursor(struct fb_info *info, struct fb_cursor *cursor) |
| 1062 | { |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1063 | u32 temp, xx, yy, bg_col = 0, fg_col = 0; |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 1064 | int i, j = 0; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1065 | static int hw_cursor; |
| 1066 | struct viafb_par *p_viafb_par; |
| 1067 | |
| 1068 | if (viafb_accel) |
| 1069 | hw_cursor = 1; |
| 1070 | |
| 1071 | if (!viafb_accel) { |
| 1072 | if (hw_cursor) { |
| 1073 | viafb_show_hw_cursor(info, HW_Cursor_OFF); |
| 1074 | hw_cursor = 0; |
| 1075 | } |
| 1076 | return -ENODEV; |
| 1077 | } |
| 1078 | |
| 1079 | if ((((struct viafb_par *)(info->par))->iga_path == IGA2) |
| 1080 | && (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266)) |
| 1081 | return -ENODEV; |
| 1082 | |
| 1083 | /* When duoview and using lcd , use soft cursor */ |
| 1084 | if (viafb_LCD_ON || ((struct viafb_par *)(info->par))->duoview) |
| 1085 | return -ENODEV; |
| 1086 | |
| 1087 | viafb_show_hw_cursor(info, HW_Cursor_OFF); |
| 1088 | viacursor = *cursor; |
| 1089 | |
| 1090 | if (cursor->set & FB_CUR_SETHOT) { |
| 1091 | viacursor.hot = cursor->hot; |
| 1092 | temp = ((viacursor.hot.x) << 16) + viacursor.hot.y; |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 1093 | writel(temp, viaparinfo->io_virt + VIA_REG_CURSOR_ORG); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1094 | } |
| 1095 | |
| 1096 | if (cursor->set & FB_CUR_SETPOS) { |
| 1097 | viacursor.image.dx = cursor->image.dx; |
| 1098 | viacursor.image.dy = cursor->image.dy; |
| 1099 | yy = cursor->image.dy - info->var.yoffset; |
| 1100 | xx = cursor->image.dx - info->var.xoffset; |
| 1101 | temp = yy & 0xFFFF; |
| 1102 | temp |= (xx << 16); |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 1103 | writel(temp, viaparinfo->io_virt + VIA_REG_CURSOR_POS); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | if (cursor->set & FB_CUR_SETSIZE) { |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 1107 | temp = readl(viaparinfo->io_virt + VIA_REG_CURSOR_MODE); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1108 | |
| 1109 | if ((cursor->image.width <= 32) |
| 1110 | && (cursor->image.height <= 32)) { |
| 1111 | MAX_CURS = 32; |
| 1112 | temp |= 0x2; |
| 1113 | } else if ((cursor->image.width <= 64) |
| 1114 | && (cursor->image.height <= 64)) { |
| 1115 | MAX_CURS = 64; |
| 1116 | temp &= 0xFFFFFFFD; |
| 1117 | } else { |
| 1118 | DEBUG_MSG(KERN_INFO |
| 1119 | "The cursor image is biger than 64x64 bits...\n"); |
| 1120 | return -ENXIO; |
| 1121 | } |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 1122 | writel(temp, viaparinfo->io_virt + VIA_REG_CURSOR_MODE); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1123 | |
| 1124 | viacursor.image.height = cursor->image.height; |
| 1125 | viacursor.image.width = cursor->image.width; |
| 1126 | } |
| 1127 | |
| 1128 | if (cursor->set & FB_CUR_SETCMAP) { |
| 1129 | viacursor.image.fg_color = cursor->image.fg_color; |
| 1130 | viacursor.image.bg_color = cursor->image.bg_color; |
| 1131 | |
| 1132 | switch (info->var.bits_per_pixel) { |
| 1133 | case 8: |
| 1134 | case 16: |
| 1135 | case 32: |
| 1136 | bg_col = |
| 1137 | (0xFF << 24) | |
| 1138 | (((info->cmap.red)[viacursor.image.bg_color] & |
| 1139 | 0xFF00) << 8) | |
| 1140 | ((info->cmap.green)[viacursor.image.bg_color] & |
| 1141 | 0xFF00) | |
| 1142 | (((info->cmap.blue)[viacursor.image.bg_color] & |
| 1143 | 0xFF00) >> 8); |
| 1144 | fg_col = |
| 1145 | (0xFF << 24) | |
| 1146 | (((info->cmap.red)[viacursor.image.fg_color] & |
| 1147 | 0xFF00) << 8) | |
| 1148 | ((info->cmap.green)[viacursor.image.fg_color] & |
| 1149 | 0xFF00) | |
| 1150 | (((info->cmap.blue)[viacursor.image.fg_color] & |
| 1151 | 0xFF00) >> 8); |
| 1152 | break; |
| 1153 | default: |
| 1154 | return 0; |
| 1155 | } |
| 1156 | |
| 1157 | /* This is indeed a patch for VT3324/VT3353 */ |
| 1158 | if (!info->par) |
| 1159 | return 0; |
| 1160 | p_viafb_par = (struct viafb_par *)info->par; |
| 1161 | |
| 1162 | if ((p_viafb_par->chip_info->gfx_chip_name == |
| 1163 | UNICHROME_CX700) || |
| 1164 | ((p_viafb_par->chip_info->gfx_chip_name == |
| 1165 | UNICHROME_VX800))) { |
| 1166 | bg_col = |
| 1167 | (((info->cmap.red)[viacursor.image.bg_color] & |
| 1168 | 0xFFC0) << 14) | |
| 1169 | (((info->cmap.green)[viacursor.image.bg_color] & |
| 1170 | 0xFFC0) << 4) | |
| 1171 | (((info->cmap.blue)[viacursor.image.bg_color] & |
| 1172 | 0xFFC0) >> 6); |
| 1173 | fg_col = |
| 1174 | (((info->cmap.red)[viacursor.image.fg_color] & |
| 1175 | 0xFFC0) << 14) | |
| 1176 | (((info->cmap.green)[viacursor.image.fg_color] & |
| 1177 | 0xFFC0) << 4) | |
| 1178 | (((info->cmap.blue)[viacursor.image.fg_color] & |
| 1179 | 0xFFC0) >> 6); |
| 1180 | } |
| 1181 | |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 1182 | writel(bg_col, viaparinfo->io_virt + VIA_REG_CURSOR_BG); |
| 1183 | writel(fg_col, viaparinfo->io_virt + VIA_REG_CURSOR_FG); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | if (cursor->set & FB_CUR_SETSHAPE) { |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 1187 | struct { |
| 1188 | u8 data[CURSOR_SIZE / 8]; |
| 1189 | u32 bak[CURSOR_SIZE / 32]; |
| 1190 | } *cr_data = kzalloc(sizeof(*cr_data), GFP_ATOMIC); |
| 1191 | int size = |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1192 | ((viacursor.image.width + 7) >> 3) * |
| 1193 | viacursor.image.height; |
| 1194 | |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 1195 | if (cr_data == NULL) |
| 1196 | goto out; |
| 1197 | |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1198 | if (MAX_CURS == 32) { |
| 1199 | for (i = 0; i < (CURSOR_SIZE / 32); i++) { |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 1200 | cr_data->bak[i] = 0x0; |
| 1201 | cr_data->bak[i + 1] = 0xFFFFFFFF; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1202 | i += 1; |
| 1203 | } |
| 1204 | } else if (MAX_CURS == 64) { |
| 1205 | for (i = 0; i < (CURSOR_SIZE / 32); i++) { |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 1206 | cr_data->bak[i] = 0x0; |
| 1207 | cr_data->bak[i + 1] = 0x0; |
| 1208 | cr_data->bak[i + 2] = 0xFFFFFFFF; |
| 1209 | cr_data->bak[i + 3] = 0xFFFFFFFF; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1210 | i += 3; |
| 1211 | } |
| 1212 | } |
| 1213 | |
| 1214 | switch (viacursor.rop) { |
| 1215 | case ROP_XOR: |
| 1216 | for (i = 0; i < size; i++) |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 1217 | cr_data->data[i] = viacursor.mask[i]; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1218 | break; |
| 1219 | case ROP_COPY: |
| 1220 | |
| 1221 | for (i = 0; i < size; i++) |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 1222 | cr_data->data[i] = viacursor.mask[i]; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1223 | break; |
| 1224 | default: |
| 1225 | break; |
| 1226 | } |
| 1227 | |
| 1228 | if (MAX_CURS == 32) { |
| 1229 | for (i = 0; i < size; i++) { |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 1230 | cr_data->bak[j] = (u32) cr_data->data[i]; |
| 1231 | cr_data->bak[j + 1] = ~cr_data->bak[j]; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1232 | j += 2; |
| 1233 | } |
| 1234 | } else if (MAX_CURS == 64) { |
| 1235 | for (i = 0; i < size; i++) { |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 1236 | cr_data->bak[j] = (u32) cr_data->data[i]; |
| 1237 | cr_data->bak[j + 1] = 0x0; |
| 1238 | cr_data->bak[j + 2] = ~cr_data->bak[j]; |
| 1239 | cr_data->bak[j + 3] = ~cr_data->bak[j + 1]; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1240 | j += 4; |
| 1241 | } |
| 1242 | } |
| 1243 | |
| 1244 | memcpy(((struct viafb_par *)(info->par))->fbmem_virt + |
| 1245 | ((struct viafb_par *)(info->par))->cursor_start, |
Bruno Prémont | e687d69 | 2009-01-04 13:11:54 -0800 | [diff] [blame] | 1246 | cr_data->bak, CURSOR_SIZE); |
| 1247 | out: |
| 1248 | kfree(cr_data); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1249 | } |
| 1250 | |
| 1251 | if (viacursor.enable) |
| 1252 | viafb_show_hw_cursor(info, HW_Cursor_ON); |
| 1253 | |
| 1254 | return 0; |
| 1255 | } |
| 1256 | |
| 1257 | static int viafb_sync(struct fb_info *info) |
| 1258 | { |
| 1259 | if (viafb_accel) |
| 1260 | viafb_wait_engine_idle(); |
| 1261 | return 0; |
| 1262 | } |
| 1263 | |
Florian Tobias Schandinat | 5215944 | 2009-08-06 15:07:34 -0700 | [diff] [blame] | 1264 | int viafb_get_mode_index(int hres, int vres) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1265 | { |
| 1266 | u32 i; |
| 1267 | DEBUG_MSG(KERN_INFO "viafb_get_mode_index!\n"); |
| 1268 | |
| 1269 | for (i = 0; viafb_modentry[i].mode_index != VIA_RES_INVALID; i++) |
| 1270 | if (viafb_modentry[i].xres == hres && |
| 1271 | viafb_modentry[i].yres == vres) |
| 1272 | break; |
| 1273 | |
Florian Tobias Schandinat | 5215944 | 2009-08-06 15:07:34 -0700 | [diff] [blame] | 1274 | return viafb_modentry[i].mode_index; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 1275 | } |
| 1276 | |
| 1277 | static void check_available_device_to_enable(int device_id) |
| 1278 | { |
| 1279 | int device_num = 0; |
| 1280 | |
| 1281 | /* Initialize: */ |
| 1282 | viafb_CRT_ON = STATE_OFF; |
| 1283 | viafb_DVI_ON = STATE_OFF; |
| 1284 | viafb_LCD_ON = STATE_OFF; |
| 1285 | viafb_LCD2_ON = STATE_OFF; |
| 1286 | viafb_DeviceStatus = None_Device; |
| 1287 | |
| 1288 | if ((device_id & CRT_Device) && (device_num < MAX_ACTIVE_DEV_NUM)) { |
| 1289 | viafb_CRT_ON = STATE_ON; |
| 1290 | device_num++; |
| 1291 | viafb_DeviceStatus |= CRT_Device; |
| 1292 | } |
| 1293 | |
| 1294 | if ((device_id & DVI_Device) && (device_num < MAX_ACTIVE_DEV_NUM)) { |
| 1295 | viafb_DVI_ON = STATE_ON; |
| 1296 | device_num++; |
| 1297 | viafb_DeviceStatus |= DVI_Device; |
| 1298 | } |
| 1299 | |
| 1300 | if ((device_id & LCD_Device) && (device_num < MAX_ACTIVE_DEV_NUM)) { |
| 1301 | viafb_LCD_ON = STATE_ON; |
| 1302 | device_num++; |
| 1303 | viafb_DeviceStatus |= LCD_Device; |
| 1304 | } |
| 1305 | |
| 1306 | if ((device_id & LCD2_Device) && (device_num < MAX_ACTIVE_DEV_NUM)) { |
| 1307 | viafb_LCD2_ON = STATE_ON; |
| 1308 | device_num++; |
| 1309 | viafb_DeviceStatus |= LCD2_Device; |
| 1310 | } |
| 1311 | |
| 1312 | if (viafb_DeviceStatus == None_Device) { |
| 1313 | /* Use CRT as default active device: */ |
| 1314 | viafb_CRT_ON = STATE_ON; |
| 1315 | viafb_DeviceStatus = CRT_Device; |
| 1316 | } |
| 1317 | DEBUG_MSG(KERN_INFO "Device Status:%x", viafb_DeviceStatus); |
| 1318 | } |
| 1319 | |
| 1320 | static void viafb_set_device(struct device_t active_dev) |
| 1321 | { |
| 1322 | /* Check available device to enable: */ |
| 1323 | int device_id = None_Device; |
| 1324 | if (active_dev.crt) |
| 1325 | device_id |= CRT_Device; |
| 1326 | if (active_dev.dvi) |
| 1327 | device_id |= DVI_Device; |
| 1328 | if (active_dev.lcd) |
| 1329 | device_id |= LCD_Device; |
| 1330 | |
| 1331 | check_available_device_to_enable(device_id); |
| 1332 | |
| 1333 | /* Check property of LCD: */ |
| 1334 | if (viafb_LCD_ON) { |
| 1335 | if (active_dev.lcd_dsp_cent) { |
| 1336 | viaparinfo->lvds_setting_info->display_method = |
| 1337 | viafb_lcd_dsp_method = LCD_CENTERING; |
| 1338 | } else { |
| 1339 | viaparinfo->lvds_setting_info->display_method = |
| 1340 | viafb_lcd_dsp_method = LCD_EXPANDSION; |
| 1341 | } |
| 1342 | |
| 1343 | if (active_dev.lcd_mode == LCD_SPWG) { |
| 1344 | viaparinfo->lvds_setting_info->lcd_mode = |
| 1345 | viafb_lcd_mode = LCD_SPWG; |
| 1346 | } else { |
| 1347 | viaparinfo->lvds_setting_info->lcd_mode = |
| 1348 | viafb_lcd_mode = LCD_OPENLDI; |
| 1349 | } |
| 1350 | |
| 1351 | if (active_dev.lcd_panel_id <= LCD_PANEL_ID_MAXIMUM) { |
| 1352 | viafb_lcd_panel_id = active_dev.lcd_panel_id; |
| 1353 | viafb_init_lcd_size(); |
| 1354 | } |
| 1355 | } |
| 1356 | |
| 1357 | /* Check property of mode: */ |
| 1358 | if (!active_dev.xres1) |
| 1359 | viafb_second_xres = 640; |
| 1360 | else |
| 1361 | viafb_second_xres = active_dev.xres1; |
| 1362 | if (!active_dev.yres1) |
| 1363 | viafb_second_yres = 480; |
| 1364 | else |
| 1365 | viafb_second_yres = active_dev.yres1; |
| 1366 | if (active_dev.bpp != 0) |
| 1367 | viafb_bpp = active_dev.bpp; |
| 1368 | if (active_dev.bpp1 != 0) |
| 1369 | viafb_bpp1 = active_dev.bpp1; |
| 1370 | if (active_dev.refresh != 0) |
| 1371 | viafb_refresh = active_dev.refresh; |
| 1372 | if (active_dev.refresh1 != 0) |
| 1373 | viafb_refresh1 = active_dev.refresh1; |
| 1374 | if ((active_dev.samm == STATE_OFF) || (active_dev.samm == STATE_ON)) |
| 1375 | viafb_SAMM_ON = active_dev.samm; |
| 1376 | viafb_primary_dev = active_dev.primary_dev; |
| 1377 | |
| 1378 | viafb_set_start_addr(); |
| 1379 | viafb_set_iga_path(); |
| 1380 | } |
| 1381 | |
| 1382 | static void viafb_set_video_device(u32 video_dev_info) |
| 1383 | { |
| 1384 | viaparinfo->video_on_crt = STATE_OFF; |
| 1385 | viaparinfo->video_on_dvi = STATE_OFF; |
| 1386 | viaparinfo->video_on_lcd = STATE_OFF; |
| 1387 | |
| 1388 | /* Check available device to enable: */ |
| 1389 | if ((video_dev_info & CRT_Device) == CRT_Device) |
| 1390 | viaparinfo->video_on_crt = STATE_ON; |
| 1391 | else if ((video_dev_info & DVI_Device) == DVI_Device) |
| 1392 | viaparinfo->video_on_dvi = STATE_ON; |
| 1393 | else if ((video_dev_info & LCD_Device) == LCD_Device) |
| 1394 | viaparinfo->video_on_lcd = STATE_ON; |
| 1395 | } |
| 1396 | |
| 1397 | static void viafb_get_video_device(u32 *video_dev_info) |
| 1398 | { |
| 1399 | *video_dev_info = None_Device; |
| 1400 | if (viaparinfo->video_on_crt == STATE_ON) |
| 1401 | *video_dev_info |= CRT_Device; |
| 1402 | else if (viaparinfo->video_on_dvi == STATE_ON) |
| 1403 | *video_dev_info |= DVI_Device; |
| 1404 | else if (viaparinfo->video_on_lcd == STATE_ON) |
| 1405 | *video_dev_info |= LCD_Device; |
| 1406 | } |
| 1407 | |
| 1408 | static int get_primary_device(void) |
| 1409 | { |
| 1410 | int primary_device = 0; |
| 1411 | /* Rule: device on iga1 path are the primary device. */ |
| 1412 | if (viafb_SAMM_ON) { |
| 1413 | if (viafb_CRT_ON) { |
| 1414 | if (viaparinfo->crt_setting_info->iga_path == IGA1) { |
| 1415 | DEBUG_MSG(KERN_INFO "CRT IGA Path:%d\n", |
| 1416 | viaparinfo-> |
| 1417 | crt_setting_info->iga_path); |
| 1418 | primary_device = CRT_Device; |
| 1419 | } |
| 1420 | } |
| 1421 | if (viafb_DVI_ON) { |
| 1422 | if (viaparinfo->tmds_setting_info->iga_path == IGA1) { |
| 1423 | DEBUG_MSG(KERN_INFO "DVI IGA Path:%d\n", |
| 1424 | viaparinfo-> |
| 1425 | tmds_setting_info->iga_path); |
| 1426 | primary_device = DVI_Device; |
| 1427 | } |
| 1428 | } |
| 1429 | if (viafb_LCD_ON) { |
| 1430 | if (viaparinfo->lvds_setting_info->iga_path == IGA1) { |
| 1431 | DEBUG_MSG(KERN_INFO "LCD IGA Path:%d\n", |
| 1432 | viaparinfo-> |
| 1433 | lvds_setting_info->iga_path); |
| 1434 | primary_device = LCD_Device; |
| 1435 | } |
| 1436 | } |
| 1437 | if (viafb_LCD2_ON) { |
| 1438 | if (viaparinfo->lvds_setting_info2->iga_path == IGA1) { |
| 1439 | DEBUG_MSG(KERN_INFO "LCD2 IGA Path:%d\n", |
| 1440 | viaparinfo-> |
| 1441 | lvds_setting_info2->iga_path); |
| 1442 | primary_device = LCD2_Device; |
| 1443 | } |
| 1444 | } |
| 1445 | } |
| 1446 | return primary_device; |
| 1447 | } |
| 1448 | |
| 1449 | static u8 is_duoview(void) |
| 1450 | { |
| 1451 | if (0 == viafb_SAMM_ON) { |
| 1452 | if (viafb_LCD_ON + viafb_LCD2_ON + |
| 1453 | viafb_DVI_ON + viafb_CRT_ON == 2) |
| 1454 | return true; |
| 1455 | return false; |
| 1456 | } else { |
| 1457 | return false; |
| 1458 | } |
| 1459 | } |
| 1460 | |
| 1461 | static void apply_second_mode_setting(struct fb_var_screeninfo |
| 1462 | *sec_var) |
| 1463 | { |
| 1464 | u32 htotal, vtotal, long_refresh; |
| 1465 | |
| 1466 | htotal = sec_var->xres + sec_var->left_margin + |
| 1467 | sec_var->right_margin + sec_var->hsync_len; |
| 1468 | vtotal = sec_var->yres + sec_var->upper_margin + |
| 1469 | sec_var->lower_margin + sec_var->vsync_len; |
| 1470 | if ((sec_var->xres_virtual * (sec_var->bits_per_pixel >> 3)) & 0x1F) { |
| 1471 | /*Is 32 bytes alignment? */ |
| 1472 | /*32 pixel alignment */ |
| 1473 | sec_var->xres_virtual = (sec_var->xres_virtual + 31) & ~31; |
| 1474 | } |
| 1475 | |
| 1476 | htotal = sec_var->xres + sec_var->left_margin + |
| 1477 | sec_var->right_margin + sec_var->hsync_len; |
| 1478 | vtotal = sec_var->yres + sec_var->upper_margin + |
| 1479 | sec_var->lower_margin + sec_var->vsync_len; |
| 1480 | long_refresh = 1000000000UL / sec_var->pixclock * 1000; |
| 1481 | long_refresh /= (htotal * vtotal); |
| 1482 | |
| 1483 | viafb_second_xres = sec_var->xres; |
| 1484 | viafb_second_yres = sec_var->yres; |
| 1485 | viafb_second_virtual_xres = sec_var->xres_virtual; |
| 1486 | viafb_second_virtual_yres = sec_var->yres_virtual; |
| 1487 | viafb_bpp1 = sec_var->bits_per_pixel; |
| 1488 | viafb_refresh1 = viafb_get_refresh(sec_var->xres, sec_var->yres, |
| 1489 | long_refresh); |
| 1490 | } |
| 1491 | |
| 1492 | static int apply_device_setting(struct viafb_ioctl_setting setting_info, |
| 1493 | struct fb_info *info) |
| 1494 | { |
| 1495 | int need_set_mode = 0; |
| 1496 | DEBUG_MSG(KERN_INFO "apply_device_setting\n"); |
| 1497 | |
| 1498 | if (setting_info.device_flag) { |
| 1499 | need_set_mode = 1; |
| 1500 | check_available_device_to_enable(setting_info.device_status); |
| 1501 | } |
| 1502 | |
| 1503 | /* Unlock LCD's operation according to LCD flag |
| 1504 | and check if the setting value is valid. */ |
| 1505 | /* If the value is valid, apply the new setting value to the device. */ |
| 1506 | if (viafb_LCD_ON) { |
| 1507 | if (setting_info.lcd_operation_flag & OP_LCD_CENTERING) { |
| 1508 | need_set_mode = 1; |
| 1509 | if (setting_info.lcd_attributes.display_center) { |
| 1510 | /* Centering */ |
| 1511 | viaparinfo->lvds_setting_info->display_method = |
| 1512 | LCD_CENTERING; |
| 1513 | viafb_lcd_dsp_method = LCD_CENTERING; |
| 1514 | viaparinfo->lvds_setting_info2->display_method = |
| 1515 | viafb_lcd_dsp_method = LCD_CENTERING; |
| 1516 | } else { |
| 1517 | /* expandsion */ |
| 1518 | viaparinfo->lvds_setting_info->display_method = |
| 1519 | LCD_EXPANDSION; |
| 1520 | viafb_lcd_dsp_method = LCD_EXPANDSION; |
| 1521 | viaparinfo->lvds_setting_info2->display_method = |
| 1522 | LCD_EXPANDSION; |
| 1523 | viafb_lcd_dsp_method = LCD_EXPANDSION; |
| 1524 | } |
| 1525 | } |
| 1526 | |
| 1527 | if (setting_info.lcd_operation_flag & OP_LCD_MODE) { |
| 1528 | need_set_mode = 1; |
| 1529 | if (setting_info.lcd_attributes.lcd_mode == |
| 1530 | LCD_SPWG) { |
| 1531 | viaparinfo->lvds_setting_info->lcd_mode = |
| 1532 | viafb_lcd_mode = LCD_SPWG; |
| 1533 | } else { |
| 1534 | viaparinfo->lvds_setting_info->lcd_mode = |
| 1535 | viafb_lcd_mode = LCD_OPENLDI; |
| 1536 | } |
| 1537 | viaparinfo->lvds_setting_info2->lcd_mode = |
| 1538 | viaparinfo->lvds_setting_info->lcd_mode; |
| 1539 | } |
| 1540 | |
| 1541 | if (setting_info.lcd_operation_flag & OP_LCD_PANEL_ID) { |
| 1542 | need_set_mode = 1; |
| 1543 | if (setting_info.lcd_attributes.panel_id <= |
| 1544 | LCD_PANEL_ID_MAXIMUM) { |
| 1545 | viafb_lcd_panel_id = |
| 1546 | setting_info.lcd_attributes.panel_id; |
| 1547 | viafb_init_lcd_size(); |
| 1548 | } |
| 1549 | } |
| 1550 | } |
| 1551 | |
| 1552 | if (0 != (setting_info.samm_status & OP_SAMM)) { |
| 1553 | setting_info.samm_status = |
| 1554 | setting_info.samm_status & (~OP_SAMM); |
| 1555 | if (setting_info.samm_status == 0 |
| 1556 | || setting_info.samm_status == 1) { |
| 1557 | viafb_SAMM_ON = setting_info.samm_status; |
| 1558 | |
| 1559 | if (viafb_SAMM_ON) |
| 1560 | viafb_primary_dev = setting_info.primary_device; |
| 1561 | |
| 1562 | viafb_set_start_addr(); |
| 1563 | viafb_set_iga_path(); |
| 1564 | } |
| 1565 | need_set_mode = 1; |
| 1566 | } |
| 1567 | |
| 1568 | viaparinfo->duoview = is_duoview(); |
| 1569 | |
| 1570 | if (!need_set_mode) { |
| 1571 | ; |
| 1572 | } else { |
| 1573 | viafb_set_iga_path(); |
| 1574 | viafb_set_par(info); |
| 1575 | } |
| 1576 | return true; |
| 1577 | } |
| 1578 | |
| 1579 | static void retrieve_device_setting(struct viafb_ioctl_setting |
| 1580 | *setting_info) |
| 1581 | { |
| 1582 | |
| 1583 | /* get device status */ |
| 1584 | if (viafb_CRT_ON == 1) |
| 1585 | setting_info->device_status = CRT_Device; |
| 1586 | if (viafb_DVI_ON == 1) |
| 1587 | setting_info->device_status |= DVI_Device; |
| 1588 | if (viafb_LCD_ON == 1) |
| 1589 | setting_info->device_status |= LCD_Device; |
| 1590 | if (viafb_LCD2_ON == 1) |
| 1591 | setting_info->device_status |= LCD2_Device; |
| 1592 | if ((viaparinfo->video_on_crt == 1) && (viafb_CRT_ON == 1)) { |
| 1593 | setting_info->video_device_status = |
| 1594 | viaparinfo->crt_setting_info->iga_path; |
| 1595 | } else if ((viaparinfo->video_on_dvi == 1) && (viafb_DVI_ON == 1)) { |
| 1596 | setting_info->video_device_status = |
| 1597 | viaparinfo->tmds_setting_info->iga_path; |
| 1598 | } else if ((viaparinfo->video_on_lcd == 1) && (viafb_LCD_ON == 1)) { |
| 1599 | setting_info->video_device_status = |
| 1600 | viaparinfo->lvds_setting_info->iga_path; |
| 1601 | } else { |
| 1602 | setting_info->video_device_status = 0; |
| 1603 | } |
| 1604 | |
| 1605 | setting_info->samm_status = viafb_SAMM_ON; |
| 1606 | setting_info->primary_device = get_primary_device(); |
| 1607 | |
| 1608 | setting_info->first_dev_bpp = viafb_bpp; |
| 1609 | setting_info->second_dev_bpp = viafb_bpp1; |
| 1610 | |
| 1611 | setting_info->first_dev_refresh = viafb_refresh; |
| 1612 | setting_info->second_dev_refresh = viafb_refresh1; |
| 1613 | |
| 1614 | setting_info->first_dev_hor_res = viafb_hotplug_Xres; |
| 1615 | setting_info->first_dev_ver_res = viafb_hotplug_Yres; |
| 1616 | setting_info->second_dev_hor_res = viafb_second_xres; |
| 1617 | setting_info->second_dev_ver_res = viafb_second_yres; |
| 1618 | |
| 1619 | /* Get lcd attributes */ |
| 1620 | setting_info->lcd_attributes.display_center = viafb_lcd_dsp_method; |
| 1621 | setting_info->lcd_attributes.panel_id = viafb_lcd_panel_id; |
| 1622 | setting_info->lcd_attributes.lcd_mode = viafb_lcd_mode; |
| 1623 | } |
| 1624 | |
| 1625 | static void parse_active_dev(void) |
| 1626 | { |
| 1627 | viafb_CRT_ON = STATE_OFF; |
| 1628 | viafb_DVI_ON = STATE_OFF; |
| 1629 | viafb_LCD_ON = STATE_OFF; |
| 1630 | viafb_LCD2_ON = STATE_OFF; |
| 1631 | /* 1. Modify the active status of devices. */ |
| 1632 | /* 2. Keep the order of devices, so we can set corresponding |
| 1633 | IGA path to devices in SAMM case. */ |
| 1634 | /* Note: The previous of active_dev is primary device, |
| 1635 | and the following is secondary device. */ |
| 1636 | if (!strncmp(viafb_active_dev, "CRT+DVI", 7)) { |
| 1637 | /* CRT+DVI */ |
| 1638 | viafb_CRT_ON = STATE_ON; |
| 1639 | viafb_DVI_ON = STATE_ON; |
| 1640 | viafb_primary_dev = CRT_Device; |
| 1641 | } else if (!strncmp(viafb_active_dev, "DVI+CRT", 7)) { |
| 1642 | /* DVI+CRT */ |
| 1643 | viafb_CRT_ON = STATE_ON; |
| 1644 | viafb_DVI_ON = STATE_ON; |
| 1645 | viafb_primary_dev = DVI_Device; |
| 1646 | } else if (!strncmp(viafb_active_dev, "CRT+LCD", 7)) { |
| 1647 | /* CRT+LCD */ |
| 1648 | viafb_CRT_ON = STATE_ON; |
| 1649 | viafb_LCD_ON = STATE_ON; |
| 1650 | viafb_primary_dev = CRT_Device; |
| 1651 | } else if (!strncmp(viafb_active_dev, "LCD+CRT", 7)) { |
| 1652 | /* LCD+CRT */ |
| 1653 | viafb_CRT_ON = STATE_ON; |
| 1654 | viafb_LCD_ON = STATE_ON; |
| 1655 | viafb_primary_dev = LCD_Device; |
| 1656 | } else if (!strncmp(viafb_active_dev, "DVI+LCD", 7)) { |
| 1657 | /* DVI+LCD */ |
| 1658 | viafb_DVI_ON = STATE_ON; |
| 1659 | viafb_LCD_ON = STATE_ON; |
| 1660 | viafb_primary_dev = DVI_Device; |
| 1661 | } else if (!strncmp(viafb_active_dev, "LCD+DVI", 7)) { |
| 1662 | /* LCD+DVI */ |
| 1663 | viafb_DVI_ON = STATE_ON; |
| 1664 | viafb_LCD_ON = STATE_ON; |
| 1665 | viafb_primary_dev = LCD_Device; |
| 1666 | } else if (!strncmp(viafb_active_dev, "LCD+LCD2", 8)) { |
| 1667 | viafb_LCD_ON = STATE_ON; |
| 1668 | viafb_LCD2_ON = STATE_ON; |
| 1669 | viafb_primary_dev = LCD_Device; |
| 1670 | } else if (!strncmp(viafb_active_dev, "LCD2+LCD", 8)) { |
| 1671 | viafb_LCD_ON = STATE_ON; |
| 1672 | viafb_LCD2_ON = STATE_ON; |
| 1673 | viafb_primary_dev = LCD2_Device; |
| 1674 | } else if (!strncmp(viafb_active_dev, "CRT", 3)) { |
| 1675 | /* CRT only */ |
| 1676 | viafb_CRT_ON = STATE_ON; |
| 1677 | viafb_SAMM_ON = STATE_OFF; |
| 1678 | } else if (!strncmp(viafb_active_dev, "DVI", 3)) { |
| 1679 | /* DVI only */ |
| 1680 | viafb_DVI_ON = STATE_ON; |
| 1681 | viafb_SAMM_ON = STATE_OFF; |
| 1682 | } else if (!strncmp(viafb_active_dev, "LCD", 3)) { |
| 1683 | /* LCD only */ |
| 1684 | viafb_LCD_ON = STATE_ON; |
| 1685 | viafb_SAMM_ON = STATE_OFF; |
| 1686 | } else { |
| 1687 | viafb_CRT_ON = STATE_ON; |
| 1688 | viafb_SAMM_ON = STATE_OFF; |
| 1689 | } |
| 1690 | viaparinfo->duoview = is_duoview(); |
| 1691 | } |
| 1692 | |
| 1693 | static void parse_video_dev(void) |
| 1694 | { |
| 1695 | viaparinfo->video_on_crt = STATE_OFF; |
| 1696 | viaparinfo->video_on_dvi = STATE_OFF; |
| 1697 | viaparinfo->video_on_lcd = STATE_OFF; |
| 1698 | |
| 1699 | if (!strncmp(viafb_video_dev, "CRT", 3)) { |
| 1700 | /* Video on CRT */ |
| 1701 | viaparinfo->video_on_crt = STATE_ON; |
| 1702 | } else if (!strncmp(viafb_video_dev, "DVI", 3)) { |
| 1703 | /* Video on DVI */ |
| 1704 | viaparinfo->video_on_dvi = STATE_ON; |
| 1705 | } else if (!strncmp(viafb_video_dev, "LCD", 3)) { |
| 1706 | /* Video on LCD */ |
| 1707 | viaparinfo->video_on_lcd = STATE_ON; |
| 1708 | } |
| 1709 | } |
| 1710 | |
| 1711 | static int parse_port(char *opt_str, int *output_interface) |
| 1712 | { |
| 1713 | if (!strncmp(opt_str, "DVP0", 4)) |
| 1714 | *output_interface = INTERFACE_DVP0; |
| 1715 | else if (!strncmp(opt_str, "DVP1", 4)) |
| 1716 | *output_interface = INTERFACE_DVP1; |
| 1717 | else if (!strncmp(opt_str, "DFP_HIGHLOW", 11)) |
| 1718 | *output_interface = INTERFACE_DFP; |
| 1719 | else if (!strncmp(opt_str, "DFP_HIGH", 8)) |
| 1720 | *output_interface = INTERFACE_DFP_HIGH; |
| 1721 | else if (!strncmp(opt_str, "DFP_LOW", 7)) |
| 1722 | *output_interface = INTERFACE_DFP_LOW; |
| 1723 | else |
| 1724 | *output_interface = INTERFACE_NONE; |
| 1725 | return 0; |
| 1726 | } |
| 1727 | |
| 1728 | static void parse_lcd_port(void) |
| 1729 | { |
| 1730 | parse_port(viafb_lcd_port, &viaparinfo->chip_info->lvds_chip_info. |
| 1731 | output_interface); |
| 1732 | /*Initialize to avoid unexpected behavior */ |
| 1733 | viaparinfo->chip_info->lvds_chip_info2.output_interface = |
| 1734 | INTERFACE_NONE; |
| 1735 | |
| 1736 | DEBUG_MSG(KERN_INFO "parse_lcd_port: viafb_lcd_port:%s,interface:%d\n", |
| 1737 | viafb_lcd_port, viaparinfo->chip_info->lvds_chip_info. |
| 1738 | output_interface); |
| 1739 | } |
| 1740 | |
| 1741 | static void parse_dvi_port(void) |
| 1742 | { |
| 1743 | parse_port(viafb_dvi_port, &viaparinfo->chip_info->tmds_chip_info. |
| 1744 | output_interface); |
| 1745 | |
| 1746 | DEBUG_MSG(KERN_INFO "parse_dvi_port: viafb_dvi_port:%s,interface:%d\n", |
| 1747 | viafb_dvi_port, viaparinfo->chip_info->tmds_chip_info. |
| 1748 | output_interface); |
| 1749 | } |
| 1750 | |
| 1751 | /* |
| 1752 | * The proc filesystem read/write function, a simple proc implement to |
| 1753 | * get/set the value of DPA DVP0, DVP0DataDriving, DVP0ClockDriving, DVP1, |
| 1754 | * DVP1Driving, DFPHigh, DFPLow CR96, SR2A[5], SR1B[1], SR2A[4], SR1E[2], |
| 1755 | * CR9B, SR65, CR97, CR99 |
| 1756 | */ |
| 1757 | static int viafb_dvp0_proc_read(char *buf, char **start, off_t offset, |
| 1758 | int count, int *eof, void *data) |
| 1759 | { |
| 1760 | int len = 0; |
| 1761 | u8 dvp0_data_dri = 0, dvp0_clk_dri = 0, dvp0 = 0; |
| 1762 | dvp0_data_dri = |
| 1763 | (viafb_read_reg(VIASR, SR2A) & BIT5) >> 4 | |
| 1764 | (viafb_read_reg(VIASR, SR1B) & BIT1) >> 1; |
| 1765 | dvp0_clk_dri = |
| 1766 | (viafb_read_reg(VIASR, SR2A) & BIT4) >> 3 | |
| 1767 | (viafb_read_reg(VIASR, SR1E) & BIT2) >> 2; |
| 1768 | dvp0 = viafb_read_reg(VIACR, CR96) & 0x0f; |
| 1769 | len += |
| 1770 | sprintf(buf + len, "%x %x %x\n", dvp0, dvp0_data_dri, dvp0_clk_dri); |
| 1771 | *eof = 1; /*Inform kernel end of data */ |
| 1772 | return len; |
| 1773 | } |
| 1774 | static int viafb_dvp0_proc_write(struct file *file, |
| 1775 | const char __user *buffer, unsigned long count, void *data) |
| 1776 | { |
| 1777 | char buf[20], *value, *pbuf; |
| 1778 | u8 reg_val = 0; |
| 1779 | unsigned long length, i; |
| 1780 | if (count < 1) |
| 1781 | return -EINVAL; |
| 1782 | length = count > 20 ? 20 : count; |
| 1783 | if (copy_from_user(&buf[0], buffer, length)) |
| 1784 | return -EFAULT; |
| 1785 | buf[length - 1] = '\0'; /*Ensure end string */ |
| 1786 | pbuf = &buf[0]; |
| 1787 | for (i = 0; i < 3; i++) { |
| 1788 | value = strsep(&pbuf, " "); |
| 1789 | if (value != NULL) { |
| 1790 | strict_strtoul(value, 0, (unsigned long *)®_val); |
| 1791 | DEBUG_MSG(KERN_INFO "DVP0:reg_val[%l]=:%x\n", i, |
| 1792 | reg_val); |
| 1793 | switch (i) { |
| 1794 | case 0: |
| 1795 | viafb_write_reg_mask(CR96, VIACR, |
| 1796 | reg_val, 0x0f); |
| 1797 | break; |
| 1798 | case 1: |
| 1799 | viafb_write_reg_mask(SR2A, VIASR, |
| 1800 | reg_val << 4, BIT5); |
| 1801 | viafb_write_reg_mask(SR1B, VIASR, |
| 1802 | reg_val << 1, BIT1); |
| 1803 | break; |
| 1804 | case 2: |
| 1805 | viafb_write_reg_mask(SR2A, VIASR, |
| 1806 | reg_val << 3, BIT4); |
| 1807 | viafb_write_reg_mask(SR1E, VIASR, |
| 1808 | reg_val << 2, BIT2); |
| 1809 | break; |
| 1810 | default: |
| 1811 | break; |
| 1812 | } |
| 1813 | } else { |
| 1814 | break; |
| 1815 | } |
| 1816 | } |
| 1817 | return count; |
| 1818 | } |
| 1819 | static int viafb_dvp1_proc_read(char *buf, char **start, off_t offset, |
| 1820 | int count, int *eof, void *data) |
| 1821 | { |
| 1822 | int len = 0; |
| 1823 | u8 dvp1 = 0, dvp1_data_dri = 0, dvp1_clk_dri = 0; |
| 1824 | dvp1 = viafb_read_reg(VIACR, CR9B) & 0x0f; |
| 1825 | dvp1_data_dri = (viafb_read_reg(VIASR, SR65) & 0x0c) >> 2; |
| 1826 | dvp1_clk_dri = viafb_read_reg(VIASR, SR65) & 0x03; |
| 1827 | len += |
| 1828 | sprintf(buf + len, "%x %x %x\n", dvp1, dvp1_data_dri, dvp1_clk_dri); |
| 1829 | *eof = 1; /*Inform kernel end of data */ |
| 1830 | return len; |
| 1831 | } |
| 1832 | static int viafb_dvp1_proc_write(struct file *file, |
| 1833 | const char __user *buffer, unsigned long count, void *data) |
| 1834 | { |
| 1835 | char buf[20], *value, *pbuf; |
| 1836 | u8 reg_val = 0; |
| 1837 | unsigned long length, i; |
| 1838 | if (count < 1) |
| 1839 | return -EINVAL; |
| 1840 | length = count > 20 ? 20 : count; |
| 1841 | if (copy_from_user(&buf[0], buffer, length)) |
| 1842 | return -EFAULT; |
| 1843 | buf[length - 1] = '\0'; /*Ensure end string */ |
| 1844 | pbuf = &buf[0]; |
| 1845 | for (i = 0; i < 3; i++) { |
| 1846 | value = strsep(&pbuf, " "); |
| 1847 | if (value != NULL) { |
| 1848 | strict_strtoul(value, 0, (unsigned long *)®_val); |
| 1849 | switch (i) { |
| 1850 | case 0: |
| 1851 | viafb_write_reg_mask(CR9B, VIACR, |
| 1852 | reg_val, 0x0f); |
| 1853 | break; |
| 1854 | case 1: |
| 1855 | viafb_write_reg_mask(SR65, VIASR, |
| 1856 | reg_val << 2, 0x0c); |
| 1857 | break; |
| 1858 | case 2: |
| 1859 | viafb_write_reg_mask(SR65, VIASR, |
| 1860 | reg_val, 0x03); |
| 1861 | break; |
| 1862 | default: |
| 1863 | break; |
| 1864 | } |
| 1865 | } else { |
| 1866 | break; |
| 1867 | } |
| 1868 | } |
| 1869 | return count; |
| 1870 | } |
| 1871 | |
| 1872 | static int viafb_dfph_proc_read(char *buf, char **start, off_t offset, |
| 1873 | int count, int *eof, void *data) |
| 1874 | { |
| 1875 | int len = 0; |
| 1876 | u8 dfp_high = 0; |
| 1877 | dfp_high = viafb_read_reg(VIACR, CR97) & 0x0f; |
| 1878 | len += sprintf(buf + len, "%x\n", dfp_high); |
| 1879 | *eof = 1; /*Inform kernel end of data */ |
| 1880 | return len; |
| 1881 | } |
| 1882 | static int viafb_dfph_proc_write(struct file *file, |
| 1883 | const char __user *buffer, unsigned long count, void *data) |
| 1884 | { |
| 1885 | char buf[20]; |
| 1886 | u8 reg_val = 0; |
| 1887 | unsigned long length; |
| 1888 | if (count < 1) |
| 1889 | return -EINVAL; |
| 1890 | length = count > 20 ? 20 : count; |
| 1891 | if (copy_from_user(&buf[0], buffer, length)) |
| 1892 | return -EFAULT; |
| 1893 | buf[length - 1] = '\0'; /*Ensure end string */ |
| 1894 | strict_strtoul(&buf[0], 0, (unsigned long *)®_val); |
| 1895 | viafb_write_reg_mask(CR97, VIACR, reg_val, 0x0f); |
| 1896 | return count; |
| 1897 | } |
| 1898 | static int viafb_dfpl_proc_read(char *buf, char **start, off_t offset, |
| 1899 | int count, int *eof, void *data) |
| 1900 | { |
| 1901 | int len = 0; |
| 1902 | u8 dfp_low = 0; |
| 1903 | dfp_low = viafb_read_reg(VIACR, CR99) & 0x0f; |
| 1904 | len += sprintf(buf + len, "%x\n", dfp_low); |
| 1905 | *eof = 1; /*Inform kernel end of data */ |
| 1906 | return len; |
| 1907 | } |
| 1908 | static int viafb_dfpl_proc_write(struct file *file, |
| 1909 | const char __user *buffer, unsigned long count, void *data) |
| 1910 | { |
| 1911 | char buf[20]; |
| 1912 | u8 reg_val = 0; |
| 1913 | unsigned long length; |
| 1914 | if (count < 1) |
| 1915 | return -EINVAL; |
| 1916 | length = count > 20 ? 20 : count; |
| 1917 | if (copy_from_user(&buf[0], buffer, length)) |
| 1918 | return -EFAULT; |
| 1919 | buf[length - 1] = '\0'; /*Ensure end string */ |
| 1920 | strict_strtoul(&buf[0], 0, (unsigned long *)®_val); |
| 1921 | viafb_write_reg_mask(CR99, VIACR, reg_val, 0x0f); |
| 1922 | return count; |
| 1923 | } |
| 1924 | static int viafb_vt1636_proc_read(char *buf, char **start, |
| 1925 | off_t offset, int count, int *eof, void *data) |
| 1926 | { |
| 1927 | int len = 0; |
| 1928 | u8 vt1636_08 = 0, vt1636_09 = 0; |
| 1929 | switch (viaparinfo->chip_info->lvds_chip_info.lvds_chip_name) { |
| 1930 | case VT1636_LVDS: |
| 1931 | vt1636_08 = |
| 1932 | viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info, |
| 1933 | &viaparinfo->chip_info->lvds_chip_info, 0x08) & 0x0f; |
| 1934 | vt1636_09 = |
| 1935 | viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info, |
| 1936 | &viaparinfo->chip_info->lvds_chip_info, 0x09) & 0x1f; |
| 1937 | len += sprintf(buf + len, "%x %x\n", vt1636_08, vt1636_09); |
| 1938 | break; |
| 1939 | default: |
| 1940 | break; |
| 1941 | } |
| 1942 | switch (viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name) { |
| 1943 | case VT1636_LVDS: |
| 1944 | vt1636_08 = |
| 1945 | viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info2, |
| 1946 | &viaparinfo->chip_info->lvds_chip_info2, 0x08) & 0x0f; |
| 1947 | vt1636_09 = |
| 1948 | viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info2, |
| 1949 | &viaparinfo->chip_info->lvds_chip_info2, 0x09) & 0x1f; |
| 1950 | len += sprintf(buf + len, " %x %x\n", vt1636_08, vt1636_09); |
| 1951 | break; |
| 1952 | default: |
| 1953 | break; |
| 1954 | } |
| 1955 | *eof = 1; /*Inform kernel end of data */ |
| 1956 | return len; |
| 1957 | } |
| 1958 | static int viafb_vt1636_proc_write(struct file *file, |
| 1959 | const char __user *buffer, unsigned long count, void *data) |
| 1960 | { |
| 1961 | char buf[30], *value, *pbuf; |
| 1962 | struct IODATA reg_val; |
| 1963 | unsigned long length, i; |
| 1964 | if (count < 1) |
| 1965 | return -EINVAL; |
| 1966 | length = count > 30 ? 30 : count; |
| 1967 | if (copy_from_user(&buf[0], buffer, length)) |
| 1968 | return -EFAULT; |
| 1969 | buf[length - 1] = '\0'; /*Ensure end string */ |
| 1970 | pbuf = &buf[0]; |
| 1971 | switch (viaparinfo->chip_info->lvds_chip_info.lvds_chip_name) { |
| 1972 | case VT1636_LVDS: |
| 1973 | for (i = 0; i < 2; i++) { |
| 1974 | value = strsep(&pbuf, " "); |
| 1975 | if (value != NULL) { |
| 1976 | strict_strtoul(value, 0, |
| 1977 | (unsigned long *)®_val.Data); |
| 1978 | switch (i) { |
| 1979 | case 0: |
| 1980 | reg_val.Index = 0x08; |
| 1981 | reg_val.Mask = 0x0f; |
| 1982 | viafb_gpio_i2c_write_mask_lvds |
| 1983 | (viaparinfo->lvds_setting_info, |
| 1984 | &viaparinfo-> |
| 1985 | chip_info->lvds_chip_info, |
| 1986 | reg_val); |
| 1987 | break; |
| 1988 | case 1: |
| 1989 | reg_val.Index = 0x09; |
| 1990 | reg_val.Mask = 0x1f; |
| 1991 | viafb_gpio_i2c_write_mask_lvds |
| 1992 | (viaparinfo->lvds_setting_info, |
| 1993 | &viaparinfo-> |
| 1994 | chip_info->lvds_chip_info, |
| 1995 | reg_val); |
| 1996 | break; |
| 1997 | default: |
| 1998 | break; |
| 1999 | } |
| 2000 | } else { |
| 2001 | break; |
| 2002 | } |
| 2003 | } |
| 2004 | break; |
| 2005 | default: |
| 2006 | break; |
| 2007 | } |
| 2008 | switch (viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name) { |
| 2009 | case VT1636_LVDS: |
| 2010 | for (i = 0; i < 2; i++) { |
| 2011 | value = strsep(&pbuf, " "); |
| 2012 | if (value != NULL) { |
| 2013 | strict_strtoul(value, 0, |
| 2014 | (unsigned long *)®_val.Data); |
| 2015 | switch (i) { |
| 2016 | case 0: |
| 2017 | reg_val.Index = 0x08; |
| 2018 | reg_val.Mask = 0x0f; |
| 2019 | viafb_gpio_i2c_write_mask_lvds |
| 2020 | (viaparinfo->lvds_setting_info2, |
| 2021 | &viaparinfo-> |
| 2022 | chip_info->lvds_chip_info2, |
| 2023 | reg_val); |
| 2024 | break; |
| 2025 | case 1: |
| 2026 | reg_val.Index = 0x09; |
| 2027 | reg_val.Mask = 0x1f; |
| 2028 | viafb_gpio_i2c_write_mask_lvds |
| 2029 | (viaparinfo->lvds_setting_info2, |
| 2030 | &viaparinfo-> |
| 2031 | chip_info->lvds_chip_info2, |
| 2032 | reg_val); |
| 2033 | break; |
| 2034 | default: |
| 2035 | break; |
| 2036 | } |
| 2037 | } else { |
| 2038 | break; |
| 2039 | } |
| 2040 | } |
| 2041 | break; |
| 2042 | default: |
| 2043 | break; |
| 2044 | } |
| 2045 | return count; |
| 2046 | } |
| 2047 | |
Bruno Prémont | c267fd7 | 2008-11-19 15:36:23 -0800 | [diff] [blame] | 2048 | static void viafb_init_proc(struct proc_dir_entry **viafb_entry) |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2049 | { |
| 2050 | struct proc_dir_entry *entry; |
Bruno Prémont | c267fd7 | 2008-11-19 15:36:23 -0800 | [diff] [blame] | 2051 | *viafb_entry = proc_mkdir("viafb", NULL); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2052 | if (viafb_entry) { |
Bruno Prémont | c267fd7 | 2008-11-19 15:36:23 -0800 | [diff] [blame] | 2053 | entry = create_proc_entry("dvp0", 0, *viafb_entry); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2054 | if (entry) { |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2055 | entry->read_proc = viafb_dvp0_proc_read; |
| 2056 | entry->write_proc = viafb_dvp0_proc_write; |
| 2057 | } |
Bruno Prémont | c267fd7 | 2008-11-19 15:36:23 -0800 | [diff] [blame] | 2058 | entry = create_proc_entry("dvp1", 0, *viafb_entry); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2059 | if (entry) { |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2060 | entry->read_proc = viafb_dvp1_proc_read; |
| 2061 | entry->write_proc = viafb_dvp1_proc_write; |
| 2062 | } |
Bruno Prémont | c267fd7 | 2008-11-19 15:36:23 -0800 | [diff] [blame] | 2063 | entry = create_proc_entry("dfph", 0, *viafb_entry); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2064 | if (entry) { |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2065 | entry->read_proc = viafb_dfph_proc_read; |
| 2066 | entry->write_proc = viafb_dfph_proc_write; |
| 2067 | } |
Bruno Prémont | c267fd7 | 2008-11-19 15:36:23 -0800 | [diff] [blame] | 2068 | entry = create_proc_entry("dfpl", 0, *viafb_entry); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2069 | if (entry) { |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2070 | entry->read_proc = viafb_dfpl_proc_read; |
| 2071 | entry->write_proc = viafb_dfpl_proc_write; |
| 2072 | } |
| 2073 | if (VT1636_LVDS == viaparinfo->chip_info->lvds_chip_info. |
| 2074 | lvds_chip_name || VT1636_LVDS == |
| 2075 | viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name) { |
Bruno Prémont | c267fd7 | 2008-11-19 15:36:23 -0800 | [diff] [blame] | 2076 | entry = create_proc_entry("vt1636", 0, *viafb_entry); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2077 | if (entry) { |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2078 | entry->read_proc = viafb_vt1636_proc_read; |
| 2079 | entry->write_proc = viafb_vt1636_proc_write; |
| 2080 | } |
| 2081 | } |
| 2082 | |
| 2083 | } |
| 2084 | } |
| 2085 | static void viafb_remove_proc(struct proc_dir_entry *viafb_entry) |
| 2086 | { |
| 2087 | /* no problem if it was not registered */ |
| 2088 | remove_proc_entry("dvp0", viafb_entry);/* parent dir */ |
| 2089 | remove_proc_entry("dvp1", viafb_entry); |
| 2090 | remove_proc_entry("dfph", viafb_entry); |
| 2091 | remove_proc_entry("dfpl", viafb_entry); |
| 2092 | remove_proc_entry("vt1636", viafb_entry); |
| 2093 | remove_proc_entry("vt1625", viafb_entry); |
Bruno Prémont | c267fd7 | 2008-11-19 15:36:23 -0800 | [diff] [blame] | 2094 | remove_proc_entry("viafb", NULL); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2095 | } |
| 2096 | |
| 2097 | static int __devinit via_pci_probe(void) |
| 2098 | { |
Harald Welte | ee1ef82 | 2009-05-12 13:19:42 -0700 | [diff] [blame] | 2099 | unsigned long default_xres, default_yres; |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2100 | char *tmpc, *tmpm; |
| 2101 | char *tmpc_sec, *tmpm_sec; |
| 2102 | int vmode_index; |
| 2103 | u32 tmds_length, lvds_length, crt_length, chip_length, viafb_par_length; |
| 2104 | |
| 2105 | DEBUG_MSG(KERN_INFO "VIAFB PCI Probe!!\n"); |
| 2106 | |
| 2107 | viafb_par_length = ALIGN(sizeof(struct viafb_par), BITS_PER_LONG/8); |
| 2108 | tmds_length = ALIGN(sizeof(struct tmds_setting_information), |
| 2109 | BITS_PER_LONG/8); |
| 2110 | lvds_length = ALIGN(sizeof(struct lvds_setting_information), |
| 2111 | BITS_PER_LONG/8); |
| 2112 | crt_length = ALIGN(sizeof(struct lvds_setting_information), |
| 2113 | BITS_PER_LONG/8); |
| 2114 | chip_length = ALIGN(sizeof(struct chip_information), BITS_PER_LONG/8); |
| 2115 | |
| 2116 | /* Allocate fb_info and ***_par here, also including some other needed |
| 2117 | * variables |
| 2118 | */ |
| 2119 | viafbinfo = framebuffer_alloc(viafb_par_length + 2 * lvds_length + |
| 2120 | tmds_length + crt_length + chip_length, NULL); |
| 2121 | if (!viafbinfo) { |
| 2122 | printk(KERN_ERR"Could not allocate memory for viafb_info.\n"); |
| 2123 | return -ENODEV; |
| 2124 | } |
| 2125 | |
| 2126 | viaparinfo = (struct viafb_par *)viafbinfo->par; |
| 2127 | viaparinfo->tmds_setting_info = (struct tmds_setting_information *) |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 2128 | ((unsigned long)viaparinfo + viafb_par_length); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2129 | viaparinfo->lvds_setting_info = (struct lvds_setting_information *) |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 2130 | ((unsigned long)viaparinfo->tmds_setting_info + tmds_length); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2131 | viaparinfo->lvds_setting_info2 = (struct lvds_setting_information *) |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 2132 | ((unsigned long)viaparinfo->lvds_setting_info + lvds_length); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2133 | viaparinfo->crt_setting_info = (struct crt_setting_information *) |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 2134 | ((unsigned long)viaparinfo->lvds_setting_info2 + lvds_length); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2135 | viaparinfo->chip_info = (struct chip_information *) |
Joseph Chan | b3a45d8 | 2008-10-15 22:03:29 -0700 | [diff] [blame] | 2136 | ((unsigned long)viaparinfo->crt_setting_info + crt_length); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2137 | |
| 2138 | if (viafb_dual_fb) |
| 2139 | viafb_SAMM_ON = 1; |
| 2140 | parse_active_dev(); |
| 2141 | parse_video_dev(); |
| 2142 | parse_lcd_port(); |
| 2143 | parse_dvi_port(); |
| 2144 | |
| 2145 | /* for dual-fb must viafb_SAMM_ON=1 and viafb_dual_fb=1 */ |
| 2146 | if (!viafb_SAMM_ON) |
| 2147 | viafb_dual_fb = 0; |
| 2148 | |
| 2149 | /* Set up I2C bus stuff */ |
| 2150 | viafb_create_i2c_bus(viaparinfo); |
| 2151 | |
| 2152 | viafb_init_chip_info(); |
| 2153 | viafb_get_fb_info(&viaparinfo->fbmem, &viaparinfo->memsize); |
| 2154 | viaparinfo->fbmem_free = viaparinfo->memsize; |
| 2155 | viaparinfo->fbmem_used = 0; |
| 2156 | viaparinfo->fbmem_virt = ioremap_nocache(viaparinfo->fbmem, |
| 2157 | viaparinfo->memsize); |
| 2158 | viafbinfo->screen_base = (char *)viaparinfo->fbmem_virt; |
| 2159 | |
| 2160 | if (!viaparinfo->fbmem_virt) { |
| 2161 | printk(KERN_INFO "ioremap failed\n"); |
| 2162 | return -1; |
| 2163 | } |
| 2164 | |
| 2165 | viafb_get_mmio_info(&viaparinfo->mmio_base, &viaparinfo->mmio_len); |
| 2166 | viaparinfo->io_virt = ioremap_nocache(viaparinfo->mmio_base, |
| 2167 | viaparinfo->mmio_len); |
| 2168 | |
| 2169 | viafbinfo->node = 0; |
| 2170 | viafbinfo->fbops = &viafb_ops; |
| 2171 | viafbinfo->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN; |
| 2172 | |
| 2173 | viafbinfo->pseudo_palette = pseudo_pal; |
| 2174 | if (viafb_accel) { |
| 2175 | viafb_init_accel(); |
| 2176 | viafb_init_2d_engine(); |
| 2177 | viafb_hw_cursor_init(); |
| 2178 | } |
| 2179 | |
| 2180 | if (viafb_second_size && (viafb_second_size < 8)) { |
| 2181 | viafb_second_offset = viaparinfo->fbmem_free - |
| 2182 | viafb_second_size * 1024 * 1024; |
| 2183 | } else { |
| 2184 | viafb_second_size = 8; |
| 2185 | viafb_second_offset = viaparinfo->fbmem_free - |
| 2186 | viafb_second_size * 1024 * 1024; |
| 2187 | } |
| 2188 | |
| 2189 | viafb_FB_MM = viaparinfo->fbmem_virt; |
| 2190 | tmpm = viafb_mode; |
| 2191 | tmpc = strsep(&tmpm, "x"); |
Harald Welte | ee1ef82 | 2009-05-12 13:19:42 -0700 | [diff] [blame] | 2192 | strict_strtoul(tmpc, 0, &default_xres); |
| 2193 | strict_strtoul(tmpm, 0, &default_yres); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2194 | |
Florian Tobias Schandinat | 5215944 | 2009-08-06 15:07:34 -0700 | [diff] [blame] | 2195 | vmode_index = viafb_get_mode_index(default_xres, default_yres); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2196 | DEBUG_MSG(KERN_INFO "0->index=%d\n", vmode_index); |
| 2197 | |
| 2198 | if (viafb_SAMM_ON == 1) { |
| 2199 | if (strcmp(viafb_mode, viafb_mode1)) { |
| 2200 | tmpm_sec = viafb_mode1; |
| 2201 | tmpc_sec = strsep(&tmpm_sec, "x"); |
| 2202 | strict_strtoul(tmpc_sec, 0, |
| 2203 | (unsigned long *)&viafb_second_xres); |
| 2204 | strict_strtoul(tmpm_sec, 0, |
| 2205 | (unsigned long *)&viafb_second_yres); |
| 2206 | } else { |
| 2207 | viafb_second_xres = default_xres; |
| 2208 | viafb_second_yres = default_yres; |
| 2209 | } |
| 2210 | if (0 == viafb_second_virtual_xres) { |
| 2211 | switch (viafb_second_xres) { |
| 2212 | case 1400: |
| 2213 | viafb_second_virtual_xres = 1408; |
| 2214 | break; |
| 2215 | default: |
| 2216 | viafb_second_virtual_xres = viafb_second_xres; |
| 2217 | break; |
| 2218 | } |
| 2219 | } |
| 2220 | if (0 == viafb_second_virtual_yres) |
| 2221 | viafb_second_virtual_yres = viafb_second_yres; |
| 2222 | } |
| 2223 | |
| 2224 | switch (viafb_bpp) { |
| 2225 | case 0 ... 8: |
| 2226 | viafb_bpp = 8; |
| 2227 | break; |
| 2228 | case 9 ... 16: |
| 2229 | viafb_bpp = 16; |
| 2230 | break; |
| 2231 | case 17 ... 32: |
| 2232 | viafb_bpp = 32; |
| 2233 | break; |
| 2234 | default: |
| 2235 | viafb_bpp = 8; |
| 2236 | } |
| 2237 | default_var.xres = default_xres; |
| 2238 | default_var.yres = default_yres; |
| 2239 | switch (default_xres) { |
| 2240 | case 1400: |
| 2241 | default_var.xres_virtual = 1408; |
| 2242 | break; |
| 2243 | default: |
| 2244 | default_var.xres_virtual = default_xres; |
| 2245 | break; |
| 2246 | } |
| 2247 | default_var.yres_virtual = default_yres; |
| 2248 | default_var.bits_per_pixel = viafb_bpp; |
| 2249 | if (default_var.bits_per_pixel == 15) |
| 2250 | default_var.bits_per_pixel = 16; |
| 2251 | default_var.pixclock = |
| 2252 | viafb_get_pixclock(default_xres, default_yres, viafb_refresh); |
| 2253 | default_var.left_margin = (default_xres >> 3) & 0xf8; |
| 2254 | default_var.right_margin = 32; |
| 2255 | default_var.upper_margin = 16; |
| 2256 | default_var.lower_margin = 4; |
| 2257 | default_var.hsync_len = default_var.left_margin; |
| 2258 | default_var.vsync_len = 4; |
| 2259 | default_var.accel_flags = 0; |
| 2260 | |
| 2261 | if (viafb_accel) { |
| 2262 | viafbinfo->flags |= |
| 2263 | (FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT | |
| 2264 | FBINFO_HWACCEL_IMAGEBLIT); |
| 2265 | default_var.accel_flags |= FB_ACCELF_TEXT; |
| 2266 | } else |
| 2267 | viafbinfo->flags |= FBINFO_HWACCEL_DISABLED; |
| 2268 | |
| 2269 | if (viafb_dual_fb) { |
| 2270 | viafbinfo1 = framebuffer_alloc(viafb_par_length, NULL); |
| 2271 | if (!viafbinfo1) { |
| 2272 | printk(KERN_ERR |
| 2273 | "allocate the second framebuffer struct error\n"); |
| 2274 | framebuffer_release(viafbinfo); |
| 2275 | return -ENOMEM; |
| 2276 | } |
| 2277 | viaparinfo1 = viafbinfo1->par; |
| 2278 | memcpy(viaparinfo1, viaparinfo, viafb_par_length); |
| 2279 | viaparinfo1->memsize = viaparinfo->memsize - |
| 2280 | viafb_second_offset; |
| 2281 | viaparinfo->memsize = viafb_second_offset; |
| 2282 | viaparinfo1->fbmem_virt = viaparinfo->fbmem_virt + |
| 2283 | viafb_second_offset; |
| 2284 | viaparinfo1->fbmem = viaparinfo->fbmem + viafb_second_offset; |
| 2285 | |
| 2286 | viaparinfo1->fbmem_used = viaparinfo->fbmem_used; |
| 2287 | viaparinfo1->fbmem_free = viaparinfo1->memsize - |
| 2288 | viaparinfo1->fbmem_used; |
| 2289 | viaparinfo->fbmem_free = viaparinfo->memsize; |
| 2290 | viaparinfo->fbmem_used = 0; |
| 2291 | if (viafb_accel) { |
| 2292 | viaparinfo1->cursor_start = |
| 2293 | viaparinfo->cursor_start - viafb_second_offset; |
| 2294 | viaparinfo1->VQ_start = viaparinfo->VQ_start - |
| 2295 | viafb_second_offset; |
| 2296 | viaparinfo1->VQ_end = viaparinfo->VQ_end - |
| 2297 | viafb_second_offset; |
| 2298 | } |
| 2299 | |
| 2300 | memcpy(viafbinfo1, viafbinfo, sizeof(struct fb_info)); |
| 2301 | viafbinfo1->screen_base = viafbinfo->screen_base + |
| 2302 | viafb_second_offset; |
| 2303 | viafbinfo1->fix.smem_start = viaparinfo1->fbmem; |
| 2304 | viafbinfo1->fix.smem_len = viaparinfo1->fbmem_free; |
| 2305 | |
| 2306 | default_var.xres = viafb_second_xres; |
| 2307 | default_var.yres = viafb_second_yres; |
| 2308 | default_var.xres_virtual = viafb_second_virtual_xres; |
| 2309 | default_var.yres_virtual = viafb_second_virtual_yres; |
| 2310 | if (viafb_bpp1 != viafb_bpp) |
| 2311 | viafb_bpp1 = viafb_bpp; |
| 2312 | default_var.bits_per_pixel = viafb_bpp1; |
| 2313 | default_var.pixclock = |
| 2314 | viafb_get_pixclock(viafb_second_xres, viafb_second_yres, |
| 2315 | viafb_refresh); |
| 2316 | default_var.left_margin = (viafb_second_xres >> 3) & 0xf8; |
| 2317 | default_var.right_margin = 32; |
| 2318 | default_var.upper_margin = 16; |
| 2319 | default_var.lower_margin = 4; |
| 2320 | default_var.hsync_len = default_var.left_margin; |
| 2321 | default_var.vsync_len = 4; |
| 2322 | |
| 2323 | viafb_setup_fixinfo(&viafbinfo1->fix, viaparinfo1); |
| 2324 | viafb_check_var(&default_var, viafbinfo1); |
| 2325 | viafbinfo1->var = default_var; |
| 2326 | viafb_update_viafb_par(viafbinfo); |
| 2327 | viafb_update_fix(&viafbinfo1->fix, viafbinfo1); |
| 2328 | } |
| 2329 | |
| 2330 | viafb_setup_fixinfo(&viafbinfo->fix, viaparinfo); |
| 2331 | viafb_check_var(&default_var, viafbinfo); |
| 2332 | viafbinfo->var = default_var; |
| 2333 | viafb_update_viafb_par(viafbinfo); |
| 2334 | viafb_update_fix(&viafbinfo->fix, viafbinfo); |
| 2335 | default_var.activate = FB_ACTIVATE_NOW; |
| 2336 | fb_alloc_cmap(&viafbinfo->cmap, 256, 0); |
| 2337 | |
| 2338 | if (viafb_dual_fb && (viafb_primary_dev == LCD_Device) |
| 2339 | && (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266)) { |
| 2340 | if (register_framebuffer(viafbinfo1) < 0) |
| 2341 | return -EINVAL; |
| 2342 | } |
| 2343 | if (register_framebuffer(viafbinfo) < 0) |
| 2344 | return -EINVAL; |
| 2345 | |
| 2346 | if (viafb_dual_fb && ((viafb_primary_dev != LCD_Device) |
| 2347 | || (viaparinfo->chip_info->gfx_chip_name != |
| 2348 | UNICHROME_CLE266))) { |
| 2349 | if (register_framebuffer(viafbinfo1) < 0) |
| 2350 | return -EINVAL; |
| 2351 | } |
| 2352 | DEBUG_MSG(KERN_INFO "fb%d: %s frame buffer device %dx%d-%dbpp\n", |
| 2353 | viafbinfo->node, viafbinfo->fix.id, default_var.xres, |
| 2354 | default_var.yres, default_var.bits_per_pixel); |
| 2355 | |
Bruno Prémont | c267fd7 | 2008-11-19 15:36:23 -0800 | [diff] [blame] | 2356 | viafb_init_proc(&viaparinfo->proc_entry); |
Joseph Chan | 29b619f | 2008-10-15 22:03:27 -0700 | [diff] [blame] | 2357 | viafb_init_dac(IGA2); |
| 2358 | return 0; |
| 2359 | } |
| 2360 | |
| 2361 | static void __devexit via_pci_remove(void) |
| 2362 | { |
| 2363 | DEBUG_MSG(KERN_INFO "via_pci_remove!\n"); |
| 2364 | fb_dealloc_cmap(&viafbinfo->cmap); |
| 2365 | unregister_framebuffer(viafbinfo); |
| 2366 | if (viafb_dual_fb) |
| 2367 | unregister_framebuffer(viafbinfo1); |
| 2368 | iounmap((void *)viaparinfo->fbmem_virt); |
| 2369 | iounmap(viaparinfo->io_virt); |
| 2370 | |
| 2371 | viafb_delete_i2c_buss(viaparinfo); |
| 2372 | |
| 2373 | framebuffer_release(viafbinfo); |
| 2374 | if (viafb_dual_fb) |
| 2375 | framebuffer_release(viafbinfo1); |
| 2376 | |
| 2377 | viafb_remove_proc(viaparinfo->proc_entry); |
| 2378 | } |
| 2379 | |
| 2380 | #ifndef MODULE |
| 2381 | static int __init viafb_setup(char *options) |
| 2382 | { |
| 2383 | char *this_opt; |
| 2384 | DEBUG_MSG(KERN_INFO "viafb_setup!\n"); |
| 2385 | |
| 2386 | if (!options || !*options) |
| 2387 | return 0; |
| 2388 | |
| 2389 | while ((this_opt = strsep(&options, ",")) != NULL) { |
| 2390 | if (!*this_opt) |
| 2391 | continue; |
| 2392 | |
| 2393 | if (!strncmp(this_opt, "viafb_mode1=", 12)) |
| 2394 | viafb_mode1 = kstrdup(this_opt + 12, GFP_KERNEL); |
| 2395 | else if (!strncmp(this_opt, "viafb_mode=", 11)) |
| 2396 | viafb_mode = kstrdup(this_opt + 11, GFP_KERNEL); |
| 2397 | else if (!strncmp(this_opt, "viafb_bpp1=", 11)) |
| 2398 | strict_strtoul(this_opt + 11, 0, |
| 2399 | (unsigned long *)&viafb_bpp1); |
| 2400 | else if (!strncmp(this_opt, "viafb_bpp=", 10)) |
| 2401 | strict_strtoul(this_opt + 10, 0, |
| 2402 | (unsigned long *)&viafb_bpp); |
| 2403 | else if (!strncmp(this_opt, "viafb_refresh1=", 15)) |
| 2404 | strict_strtoul(this_opt + 15, 0, |
| 2405 | (unsigned long *)&viafb_refresh1); |
| 2406 | else if (!strncmp(this_opt, "viafb_refresh=", 14)) |
| 2407 | strict_strtoul(this_opt + 14, 0, |
| 2408 | (unsigned long *)&viafb_refresh); |
| 2409 | else if (!strncmp(this_opt, "viafb_lcd_dsp_method=", 21)) |
| 2410 | strict_strtoul(this_opt + 21, 0, |
| 2411 | (unsigned long *)&viafb_lcd_dsp_method); |
| 2412 | else if (!strncmp(this_opt, "viafb_lcd_panel_id=", 19)) |
| 2413 | strict_strtoul(this_opt + 19, 0, |
| 2414 | (unsigned long *)&viafb_lcd_panel_id); |
| 2415 | else if (!strncmp(this_opt, "viafb_accel=", 12)) |
| 2416 | strict_strtoul(this_opt + 12, 0, |
| 2417 | (unsigned long *)&viafb_accel); |
| 2418 | else if (!strncmp(this_opt, "viafb_SAMM_ON=", 14)) |
| 2419 | strict_strtoul(this_opt + 14, 0, |
| 2420 | (unsigned long *)&viafb_SAMM_ON); |
| 2421 | else if (!strncmp(this_opt, "viafb_active_dev=", 17)) |
| 2422 | viafb_active_dev = kstrdup(this_opt + 17, GFP_KERNEL); |
| 2423 | else if (!strncmp(this_opt, |
| 2424 | "viafb_display_hardware_layout=", 30)) |
| 2425 | strict_strtoul(this_opt + 30, 0, |
| 2426 | (unsigned long *)&viafb_display_hardware_layout); |
| 2427 | else if (!strncmp(this_opt, "viafb_second_size=", 18)) |
| 2428 | strict_strtoul(this_opt + 18, 0, |
| 2429 | (unsigned long *)&viafb_second_size); |
| 2430 | else if (!strncmp(this_opt, |
| 2431 | "viafb_platform_epia_dvi=", 24)) |
| 2432 | strict_strtoul(this_opt + 24, 0, |
| 2433 | (unsigned long *)&viafb_platform_epia_dvi); |
| 2434 | else if (!strncmp(this_opt, |
| 2435 | "viafb_device_lcd_dualedge=", 26)) |
| 2436 | strict_strtoul(this_opt + 26, 0, |
| 2437 | (unsigned long *)&viafb_device_lcd_dualedge); |
| 2438 | else if (!strncmp(this_opt, "viafb_bus_width=", 16)) |
| 2439 | strict_strtoul(this_opt + 16, 0, |
| 2440 | (unsigned long *)&viafb_bus_width); |
| 2441 | else if (!strncmp(this_opt, "viafb_lcd_mode=", 15)) |
| 2442 | strict_strtoul(this_opt + 15, 0, |
| 2443 | (unsigned long *)&viafb_lcd_mode); |
| 2444 | else if (!strncmp(this_opt, "viafb_video_dev=", 16)) |
| 2445 | viafb_video_dev = kstrdup(this_opt + 16, GFP_KERNEL); |
| 2446 | else if (!strncmp(this_opt, "viafb_lcd_port=", 15)) |
| 2447 | viafb_lcd_port = kstrdup(this_opt + 15, GFP_KERNEL); |
| 2448 | else if (!strncmp(this_opt, "viafb_dvi_port=", 15)) |
| 2449 | viafb_dvi_port = kstrdup(this_opt + 15, GFP_KERNEL); |
| 2450 | } |
| 2451 | return 0; |
| 2452 | } |
| 2453 | #endif |
| 2454 | |
| 2455 | static int __init viafb_init(void) |
| 2456 | { |
| 2457 | #ifndef MODULE |
| 2458 | char *option = NULL; |
| 2459 | if (fb_get_options("viafb", &option)) |
| 2460 | return -ENODEV; |
| 2461 | viafb_setup(option); |
| 2462 | #endif |
| 2463 | printk(KERN_INFO |
| 2464 | "VIA Graphics Intergration Chipset framebuffer %d.%d initializing\n", |
| 2465 | VERSION_MAJOR, VERSION_MINOR); |
| 2466 | return via_pci_probe(); |
| 2467 | } |
| 2468 | |
| 2469 | static void __exit viafb_exit(void) |
| 2470 | { |
| 2471 | DEBUG_MSG(KERN_INFO "viafb_exit!\n"); |
| 2472 | via_pci_remove(); |
| 2473 | } |
| 2474 | |
| 2475 | static struct fb_ops viafb_ops = { |
| 2476 | .owner = THIS_MODULE, |
| 2477 | .fb_open = viafb_open, |
| 2478 | .fb_release = viafb_release, |
| 2479 | .fb_check_var = viafb_check_var, |
| 2480 | .fb_set_par = viafb_set_par, |
| 2481 | .fb_setcolreg = viafb_setcolreg, |
| 2482 | .fb_pan_display = viafb_pan_display, |
| 2483 | .fb_blank = viafb_blank, |
| 2484 | .fb_fillrect = viafb_fillrect, |
| 2485 | .fb_copyarea = viafb_copyarea, |
| 2486 | .fb_imageblit = viafb_imageblit, |
| 2487 | .fb_cursor = viafb_cursor, |
| 2488 | .fb_ioctl = viafb_ioctl, |
| 2489 | .fb_sync = viafb_sync, |
| 2490 | .fb_setcmap = viafb_setcmap, |
| 2491 | }; |
| 2492 | |
| 2493 | module_init(viafb_init); |
| 2494 | module_exit(viafb_exit); |
| 2495 | |
| 2496 | #ifdef MODULE |
| 2497 | module_param(viafb_memsize, int, 0); |
| 2498 | |
| 2499 | module_param(viafb_mode, charp, 0); |
| 2500 | MODULE_PARM_DESC(viafb_mode, "Set resolution (default=640x480)"); |
| 2501 | |
| 2502 | module_param(viafb_mode1, charp, 0); |
| 2503 | MODULE_PARM_DESC(viafb_mode1, "Set resolution (default=640x480)"); |
| 2504 | |
| 2505 | module_param(viafb_bpp, int, 0); |
| 2506 | MODULE_PARM_DESC(viafb_bpp, "Set color depth (default=32bpp)"); |
| 2507 | |
| 2508 | module_param(viafb_bpp1, int, 0); |
| 2509 | MODULE_PARM_DESC(viafb_bpp1, "Set color depth (default=32bpp)"); |
| 2510 | |
| 2511 | module_param(viafb_refresh, int, 0); |
| 2512 | MODULE_PARM_DESC(viafb_refresh, |
| 2513 | "Set CRT viafb_refresh rate (default = 60)"); |
| 2514 | |
| 2515 | module_param(viafb_refresh1, int, 0); |
| 2516 | MODULE_PARM_DESC(viafb_refresh1, |
| 2517 | "Set CRT refresh rate (default = 60)"); |
| 2518 | |
| 2519 | module_param(viafb_lcd_panel_id, int, 0); |
| 2520 | MODULE_PARM_DESC(viafb_lcd_panel_id, |
| 2521 | "Set Flat Panel type(Default=1024x768)"); |
| 2522 | |
| 2523 | module_param(viafb_lcd_dsp_method, int, 0); |
| 2524 | MODULE_PARM_DESC(viafb_lcd_dsp_method, |
| 2525 | "Set Flat Panel display scaling method.(Default=Expandsion)"); |
| 2526 | |
| 2527 | module_param(viafb_SAMM_ON, int, 0); |
| 2528 | MODULE_PARM_DESC(viafb_SAMM_ON, |
| 2529 | "Turn on/off flag of SAMM(Default=OFF)"); |
| 2530 | |
| 2531 | module_param(viafb_accel, int, 0); |
| 2532 | MODULE_PARM_DESC(viafb_accel, |
| 2533 | "Set 2D Hardware Acceleration.(Default = OFF)"); |
| 2534 | |
| 2535 | module_param(viafb_active_dev, charp, 0); |
| 2536 | MODULE_PARM_DESC(viafb_active_dev, "Specify active devices."); |
| 2537 | |
| 2538 | module_param(viafb_display_hardware_layout, int, 0); |
| 2539 | MODULE_PARM_DESC(viafb_display_hardware_layout, |
| 2540 | "Display Hardware Layout (LCD Only, DVI Only...,etc)"); |
| 2541 | |
| 2542 | module_param(viafb_second_size, int, 0); |
| 2543 | MODULE_PARM_DESC(viafb_second_size, |
| 2544 | "Set secondary device memory size"); |
| 2545 | |
| 2546 | module_param(viafb_dual_fb, int, 0); |
| 2547 | MODULE_PARM_DESC(viafb_dual_fb, |
| 2548 | "Turn on/off flag of dual framebuffer devices.(Default = OFF)"); |
| 2549 | |
| 2550 | module_param(viafb_platform_epia_dvi, int, 0); |
| 2551 | MODULE_PARM_DESC(viafb_platform_epia_dvi, |
| 2552 | "Turn on/off flag of DVI devices on EPIA board.(Default = OFF)"); |
| 2553 | |
| 2554 | module_param(viafb_device_lcd_dualedge, int, 0); |
| 2555 | MODULE_PARM_DESC(viafb_device_lcd_dualedge, |
| 2556 | "Turn on/off flag of dual edge panel.(Default = OFF)"); |
| 2557 | |
| 2558 | module_param(viafb_bus_width, int, 0); |
| 2559 | MODULE_PARM_DESC(viafb_bus_width, |
| 2560 | "Set bus width of panel.(Default = 12)"); |
| 2561 | |
| 2562 | module_param(viafb_lcd_mode, int, 0); |
| 2563 | MODULE_PARM_DESC(viafb_lcd_mode, |
| 2564 | "Set Flat Panel mode(Default=OPENLDI)"); |
| 2565 | |
| 2566 | module_param(viafb_video_dev, charp, 0); |
| 2567 | MODULE_PARM_DESC(viafb_video_dev, "Specify video devices."); |
| 2568 | |
| 2569 | module_param(viafb_lcd_port, charp, 0); |
| 2570 | MODULE_PARM_DESC(viafb_lcd_port, "Specify LCD output port."); |
| 2571 | |
| 2572 | module_param(viafb_dvi_port, charp, 0); |
| 2573 | MODULE_PARM_DESC(viafb_dvi_port, "Specify DVI output port."); |
| 2574 | |
| 2575 | MODULE_LICENSE("GPL"); |
| 2576 | #endif |