2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
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.
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
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
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include <linux/module.h>
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];
33 static char *viafb_mode = "640x480";
34 static char *viafb_mode1 = "640x480";
35 static int viafb_resMode = VIA_RES_640X480;
37 /* Added for specifying active devices.*/
38 char *viafb_active_dev = "";
40 /* Added for specifying video on devices.*/
41 char *viafb_video_dev = "";
43 /*Added for specify lcd output port*/
44 char *viafb_lcd_port = "";
45 char *viafb_dvi_port = "";
47 static void viafb_set_device(struct device_t active_dev);
48 static int apply_device_setting(struct viafb_ioctl_setting setting_info,
49 struct fb_info *info);
50 static void apply_second_mode_setting(struct fb_var_screeninfo
52 static void retrieve_device_setting(struct viafb_ioctl_setting
54 static void viafb_set_video_device(u32 video_dev_info);
55 static void viafb_get_video_device(u32 *video_dev_info);
57 /* Mode information */
58 static const struct viafb_modeinfo viafb_modentry[] = {
59 {480, 640, VIA_RES_480X640, "480x640"},
60 {640, 480, VIA_RES_640X480, "640x480"},
61 {800, 480, VIA_RES_800X480, "800x480"},
62 {800, 600, VIA_RES_800X600, "800x600"},
63 {1024, 768, VIA_RES_1024X768, "1024x768"},
64 {1152, 864, VIA_RES_1152X864, "1152x864"},
65 {1280, 1024, VIA_RES_1280X1024, "1280x1024"},
66 {1600, 1200, VIA_RES_1600X1200, "1600x1200"},
67 {1440, 1050, VIA_RES_1440X1050, "1440x1050"},
68 {1280, 768, VIA_RES_1280X768, "1280x768"},
69 {1280, 800, VIA_RES_1280X800, "1280x800"},
70 {1280, 960, VIA_RES_1280X960, "1280x960"},
71 {1920, 1440, VIA_RES_1920X1440, "1920x1440"},
72 {848, 480, VIA_RES_848X480, "848x480"},
73 {1400, 1050, VIA_RES_1400X1050, "1400x1050"},
74 {720, 480, VIA_RES_720X480, "720x480"},
75 {720, 576, VIA_RES_720X576, "720x576"},
76 {1024, 512, VIA_RES_1024X512, "1024x512"},
77 {1024, 576, VIA_RES_1024X576, "1024x576"},
78 {1024, 600, VIA_RES_1024X600, "1024x600"},
79 {1280, 720, VIA_RES_1280X720, "1280x720"},
80 {1920, 1080, VIA_RES_1920X1080, "1920x1080"},
81 {1366, 768, VIA_RES_1368X768, "1368x768"},
82 {1680, 1050, VIA_RES_1680X1050, "1680x1050"},
83 {960, 600, VIA_RES_960X600, "960x600"},
84 {1000, 600, VIA_RES_1000X600, "1000x600"},
85 {1024, 576, VIA_RES_1024X576, "1024x576"},
86 {1024, 600, VIA_RES_1024X600, "1024x600"},
87 {1088, 612, VIA_RES_1088X612, "1088x612"},
88 {1152, 720, VIA_RES_1152X720, "1152x720"},
89 {1200, 720, VIA_RES_1200X720, "1200x720"},
90 {1280, 600, VIA_RES_1280X600, "1280x600"},
91 {1360, 768, VIA_RES_1360X768, "1360x768"},
92 {1440, 900, VIA_RES_1440X900, "1440x900"},
93 {1600, 900, VIA_RES_1600X900, "1600x900"},
94 {1600, 1024, VIA_RES_1600X1024, "1600x1024"},
95 {1792, 1344, VIA_RES_1792X1344, "1792x1344"},
96 {1856, 1392, VIA_RES_1856X1392, "1856x1392"},
97 {1920, 1200, VIA_RES_1920X1200, "1920x1200"},
98 {2048, 1536, VIA_RES_2048X1536, "2048x1536"},
99 {0, 0, VIA_RES_INVALID, "640x480"}
102 static struct fb_ops viafb_ops;
104 static int viafb_update_fix(struct fb_fix_screeninfo *fix, struct fb_info *info)
106 struct viafb_par *ppar;
109 DEBUG_MSG(KERN_INFO "viafb_update_fix!\n");
112 ppar->bpp == 8 ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
113 fix->line_length = ppar->linelength;
119 static void viafb_setup_fixinfo(struct fb_fix_screeninfo *fix,
120 struct viafb_par *viaparinfo)
122 memset(fix, 0, sizeof(struct fb_fix_screeninfo));
123 strcpy(fix->id, viafb_name);
125 fix->smem_start = viaparinfo->fbmem;
126 fix->smem_len = viaparinfo->fbmem_free;
127 fix->mmio_start = viaparinfo->mmio_base;
128 fix->mmio_len = viaparinfo->mmio_len;
130 fix->type = FB_TYPE_PACKED_PIXELS;
133 fix->xpanstep = fix->ywrapstep = 0;
136 /* Just tell the accel name */
137 viafbinfo->fix.accel = FB_ACCEL_VIA_UNICHROME;
139 static int viafb_open(struct fb_info *info, int user)
141 DEBUG_MSG(KERN_INFO "viafb_open!\n");
145 static int viafb_release(struct fb_info *info, int user)
147 DEBUG_MSG(KERN_INFO "viafb_release!\n");
151 static void viafb_update_viafb_par(struct fb_info *info)
153 struct viafb_par *ppar;
156 ppar->bpp = info->var.bits_per_pixel;
157 ppar->linelength = ((info->var.xres_virtual + 7) & ~7) * ppar->bpp / 8;
158 ppar->hres = info->var.xres;
159 ppar->vres = info->var.yres;
160 ppar->xoffset = info->var.xoffset;
161 ppar->yoffset = info->var.yoffset;
164 static int viafb_check_var(struct fb_var_screeninfo *var,
165 struct fb_info *info)
167 int vmode_index, htotal, vtotal;
168 struct viafb_par *ppar;
170 struct viafb_par *p_viafb_par;
174 DEBUG_MSG(KERN_INFO "viafb_check_var!\n");
176 /* HW neither support interlacte nor double-scaned mode */
177 if (var->vmode & FB_VMODE_INTERLACED || var->vmode & FB_VMODE_DOUBLE)
180 vmode_index = viafb_get_mode_index(var->xres, var->yres, 0);
181 if (vmode_index == VIA_RES_INVALID) {
183 "viafb: Mode %dx%dx%d not supported!!\n",
184 var->xres, var->yres, var->bits_per_pixel);
188 if (24 == var->bits_per_pixel)
189 var->bits_per_pixel = 32;
191 if (var->bits_per_pixel != 8 && var->bits_per_pixel != 16 &&
192 var->bits_per_pixel != 32)
195 if ((var->xres_virtual * (var->bits_per_pixel >> 3)) & 0x1F)
196 /*32 pixel alignment */
197 var->xres_virtual = (var->xres_virtual + 31) & ~31;
198 if (var->xres_virtual * var->yres_virtual * var->bits_per_pixel / 8 >
202 /* Based on var passed in to calculate the refresh,
203 * because our driver use some modes special.
205 htotal = var->xres + var->left_margin +
206 var->right_margin + var->hsync_len;
207 vtotal = var->yres + var->upper_margin +
208 var->lower_margin + var->vsync_len;
209 long_refresh = 1000000000UL / var->pixclock * 1000;
210 long_refresh /= (htotal * vtotal);
212 viafb_refresh = viafb_get_refresh(var->xres, var->yres, long_refresh);
214 /* Adjust var according to our driver's own table */
215 viafb_fill_var_timing_info(var, viafb_refresh, vmode_index);
217 /* This is indeed a patch for VT3353 */
220 p_viafb_par = (struct viafb_par *)info->par;
221 if (p_viafb_par->chip_info->gfx_chip_name == UNICHROME_VX800)
222 var->accel_flags = 0;
227 static int viafb_set_par(struct fb_info *info)
230 int vmode_index1 = 0;
231 DEBUG_MSG(KERN_INFO "viafb_set_par!\n");
233 viafb_update_device_setting(info->var.xres, info->var.yres,
234 info->var.bits_per_pixel, viafb_refresh, 0);
236 vmode_index = viafb_get_mode_index(info->var.xres, info->var.yres, 0);
238 if (viafb_SAMM_ON == 1) {
240 "viafb_second_xres = %d, viafb_second_yres = %d, bpp = %d\n",
241 viafb_second_xres, viafb_second_yres, viafb_bpp1);
242 vmode_index1 = viafb_get_mode_index(viafb_second_xres,
243 viafb_second_yres, 1);
244 DEBUG_MSG(KERN_INFO "->viafb_SAMM_ON: index=%d\n",
247 viafb_update_device_setting(viafb_second_xres,
248 viafb_second_yres, viafb_bpp1, viafb_refresh1, 1);
251 if (vmode_index != VIA_RES_INVALID) {
252 viafb_setmode(vmode_index, info->var.xres, info->var.yres,
253 info->var.bits_per_pixel, vmode_index1,
254 viafb_second_xres, viafb_second_yres, viafb_bpp1);
256 /*We should set memory offset according virtual_x */
257 /*Fix me:put this function into viafb_setmode */
258 viafb_memory_pitch_patch(info);
260 /* Update ***fb_par information */
261 viafb_update_viafb_par(info);
263 /* Update other fixed information */
264 viafb_update_fix(&info->fix, info);
265 viafb_bpp = info->var.bits_per_pixel;
266 /* Update viafb_accel, it is necessary to our 2D accelerate */
267 viafb_accel = info->var.accel_flags;
270 viafb_set_2d_color_depth(info->var.bits_per_pixel);
276 /* Set one color register */
277 static int viafb_setcolreg(unsigned regno, unsigned red, unsigned green,
278 unsigned blue, unsigned transp, struct fb_info *info)
280 u8 sr1a, sr1b, cr67, cr6a, rev = 0, shift = 10;
281 unsigned cmap_entries = (info->var.bits_per_pixel == 8) ? 256 : 16;
282 DEBUG_MSG(KERN_INFO "viafb_setcolreg!\n");
283 if (regno >= cmap_entries)
285 if (UNICHROME_CLE266 == viaparinfo->chip_info->gfx_chip_name) {
287 * Read PCI bus 0,dev 0,function 0,index 0xF6 to get chip rev.
289 outl(0x80000000 | (0xf6 & ~3), (unsigned long)0xCF8);
290 rev = (inl((unsigned long)0xCFC) >> ((0xf6 & 3) * 8)) & 0xff;
292 switch (info->var.bits_per_pixel) {
303 /* Map the 3C6/7/8/9 to the IGA2 */
305 outb(sr1a | 0x01, 0x3C5);
306 /* Second Display Engine colck always on */
308 outb(sr1b | 0x80, 0x3C5);
309 /* Second Display Color Depth 8 */
311 outb(cr67 & 0x3F, 0x3D5);
313 /* Second Display Channel Reset CR6A[6]) */
314 outb(cr6a & 0xBF, 0x3D5);
315 /* Second Display Channel Enable CR6A[7] */
316 outb(cr6a | 0x80, 0x3D5);
317 /* Second Display Channel stop reset) */
318 outb(cr6a | 0x40, 0x3D5);
320 /* Bit mask of palette */
322 /* Write one register of IGA2 */
324 if (UNICHROME_CLE266 == viaparinfo->chip_info->gfx_chip_name &&
327 viafb_write_reg_mask(CR6A, VIACR, BIT5, BIT5);
328 viafb_write_reg_mask(SR15, VIASR, BIT7, BIT7);
331 viafb_write_reg_mask(CR6A, VIACR, 0, BIT5);
332 viafb_write_reg_mask(SR15, VIASR, 0, BIT7);
334 outb(red >> shift, 0x3C9);
335 outb(green >> shift, 0x3C9);
336 outb(blue >> shift, 0x3C9);
338 /* Map the 3C6/7/8/9 to the IGA1 */
340 outb(sr1a & 0xFE, 0x3C5);
341 /* Bit mask of palette */
343 /* Write one register of IGA1 */
345 outb(red >> shift, 0x3C9);
346 outb(green >> shift, 0x3C9);
347 outb(blue >> shift, 0x3C9);
359 ((u32 *) info->pseudo_palette)[regno] = (red & 0xF800) |
360 ((green & 0xFC00) >> 5) | ((blue & 0xF800) >> 11);
363 ((u32 *) info->pseudo_palette)[regno] =
364 ((transp & 0xFF00) << 16) |
365 ((red & 0xFF00) << 8) |
366 ((green & 0xFF00)) | ((blue & 0xFF00) >> 8);
374 /*CALLED BY: fb_set_cmap */
375 /* fb_set_var, pass 256 colors */
376 /*CALLED BY: fb_set_cmap */
377 /* fbcon_set_palette, pass 16 colors */
378 static int viafb_setcmap(struct fb_cmap *cmap, struct fb_info *info)
382 u16 *pred = cmap->red;
383 u16 *pgreen = cmap->green;
384 u16 *pblue = cmap->blue;
385 u16 *ptransp = cmap->transp;
386 u8 sr1a, sr1b, cr67, cr6a, rev = 0, shift = 10;
389 if (UNICHROME_CLE266 == viaparinfo->chip_info->gfx_chip_name) {
391 * Read PCI bus 0, dev 0, function 0, index 0xF6 to get chip
394 outl(0x80000000 | (0xf6 & ~3), (unsigned long)0xCF8);
395 rev = (inl((unsigned long)0xCFC) >> ((0xf6 & 3) * 8)) & 0xff;
397 switch (info->var.bits_per_pixel) {
407 /* Map the 3C6/7/8/9 to the IGA2 */
409 outb(sr1a | 0x01, 0x3C5);
411 /* Second Display Engine colck always on */
412 outb(sr1b | 0x80, 0x3C5);
414 /* Second Display Color Depth 8 */
415 outb(cr67 & 0x3F, 0x3D5);
417 /* Second Display Channel Reset CR6A[6]) */
418 outb(cr6a & 0xBF, 0x3D5);
419 /* Second Display Channel Enable CR6A[7] */
420 outb(cr6a | 0x80, 0x3D5);
421 /* Second Display Channel stop reset) */
422 outb(cr6a | 0xC0, 0x3D5);
424 /* Bit mask of palette */
427 if (UNICHROME_CLE266 == viaparinfo->chip_info->gfx_chip_name &&
430 viafb_write_reg_mask(CR6A, VIACR, BIT5, BIT5);
431 viafb_write_reg_mask(SR15, VIASR, BIT7, BIT7);
434 viafb_write_reg_mask(CR6A, VIACR, 0, BIT5);
435 viafb_write_reg_mask(SR15, VIASR, 0, BIT7);
437 for (i = 0; i < len; i++) {
438 outb((*(pred + i)) >> shift, 0x3C9);
439 outb((*(pgreen + i)) >> shift, 0x3C9);
440 outb((*(pblue + i)) >> shift, 0x3C9);
444 /* Map the 3C6/7/8/9 to the IGA1 */
445 outb(sr1a & 0xFE, 0x3C5);
446 /* Bit mask of palette */
449 for (i = 0; i < len; i++) {
450 outb((*(pred + i)) >> shift, 0x3C9);
451 outb((*(pgreen + i)) >> shift, 0x3C9);
452 outb((*(pblue + i)) >> shift, 0x3C9);
466 return 0; /* Because static u32 pseudo_pal[17]; */
467 for (i = 0; i < len; i++)
468 ((u32 *) info->pseudo_palette)[i] =
469 (*(pred + i) & 0xF800) |
470 ((*(pgreen + i) & 0xFC00) >> 5) |
471 ((*(pblue + i) & 0xF800) >> 11);
477 for (i = 0; i < len; i++)
478 ((u32 *) info->pseudo_palette)[i] =
479 ((*(ptransp + i) & 0xFF00) << 16) |
480 ((*(pred + i) & 0xFF00) << 8) |
481 ((*(pgreen + i) & 0xFF00)) |
482 ((*(pblue + i) & 0xFF00) >> 8);
484 for (i = 0; i < len; i++)
485 ((u32 *) info->pseudo_palette)[i] =
487 ((*(pred + i) & 0xFF00) << 8) |
488 ((*(pgreen + i) & 0xFF00)) |
489 ((*(pblue + i) & 0xFF00) >> 8);
496 static int viafb_pan_display(struct fb_var_screeninfo *var,
497 struct fb_info *info)
501 DEBUG_MSG(KERN_INFO "viafb_pan_display!\n");
503 offset = (var->xoffset + (var->yoffset * var->xres_virtual)) *
504 var->bits_per_pixel / 16;
506 DEBUG_MSG(KERN_INFO "\nviafb_pan_display,offset =%d ", offset);
508 viafb_write_reg_mask(0x48, 0x3d4, ((offset >> 24) & 0x3), 0x3);
509 viafb_write_reg_mask(0x34, 0x3d4, ((offset >> 16) & 0xff), 0xff);
510 viafb_write_reg_mask(0x0c, 0x3d4, ((offset >> 8) & 0xff), 0xff);
511 viafb_write_reg_mask(0x0d, 0x3d4, (offset & 0xff), 0xff);
516 static int viafb_blank(int blank_mode, struct fb_info *info)
518 DEBUG_MSG(KERN_INFO "viafb_blank!\n");
519 /* clear DPMS setting */
521 switch (blank_mode) {
522 case FB_BLANK_UNBLANK:
523 /* Screen: On, HSync: On, VSync: On */
524 /* control CRT monitor power management */
525 viafb_write_reg_mask(CR36, VIACR, 0x00, BIT4 + BIT5);
527 case FB_BLANK_HSYNC_SUSPEND:
528 /* Screen: Off, HSync: Off, VSync: On */
529 /* control CRT monitor power management */
530 viafb_write_reg_mask(CR36, VIACR, 0x10, BIT4 + BIT5);
532 case FB_BLANK_VSYNC_SUSPEND:
533 /* Screen: Off, HSync: On, VSync: Off */
534 /* control CRT monitor power management */
535 viafb_write_reg_mask(CR36, VIACR, 0x20, BIT4 + BIT5);
537 case FB_BLANK_POWERDOWN:
538 /* Screen: Off, HSync: Off, VSync: Off */
539 /* control CRT monitor power management */
540 viafb_write_reg_mask(CR36, VIACR, 0x30, BIT4 + BIT5);
547 static int viafb_ioctl(struct fb_info *info, u_int cmd, u_long arg)
550 struct viafb_ioctl_mode viamode;
551 struct viafb_ioctl_samm viasamm;
552 struct viafb_driver_version driver_version;
553 struct fb_var_screeninfo sec_var;
554 struct _panel_size_pos_info panel_pos_size_para;
555 struct viafb_ioctl_setting viafb_setting;
556 struct device_t active_dev;
559 u32 *viafb_gamma_table;
560 char driver_name[] = "viafb";
562 u32 __user *argp = (u32 __user *) arg;
564 u32 video_dev_info = 0;
566 DEBUG_MSG(KERN_INFO "viafb_ioctl: 0x%X !!\n", cmd);
567 memset(&u, 0, sizeof(u));
570 case VIAFB_GET_CHIP_INFO:
571 if (copy_to_user(argp, viaparinfo->chip_info,
572 sizeof(struct chip_information)))
575 case VIAFB_GET_INFO_SIZE:
576 return put_user((u32)sizeof(struct viafb_ioctl_info), argp);
578 return viafb_ioctl_get_viafb_info(arg);
580 return put_user(viafb_ioctl_hotplug(info->var.xres,
582 info->var.bits_per_pixel), argp);
583 case VIAFB_SET_HOTPLUG_FLAG:
584 if (copy_from_user(&gpu32, argp, sizeof(gpu32)))
586 viafb_hotplug = (gpu32) ? 1 : 0;
588 case VIAFB_GET_RESOLUTION:
589 u.viamode.xres = (u32) viafb_hotplug_Xres;
590 u.viamode.yres = (u32) viafb_hotplug_Yres;
591 u.viamode.refresh = (u32) viafb_hotplug_refresh;
592 u.viamode.bpp = (u32) viafb_hotplug_bpp;
593 if (viafb_SAMM_ON == 1) {
594 u.viamode.xres_sec = viafb_second_xres;
595 u.viamode.yres_sec = viafb_second_yres;
596 u.viamode.virtual_xres_sec = viafb_second_virtual_xres;
597 u.viamode.virtual_yres_sec = viafb_second_virtual_yres;
598 u.viamode.refresh_sec = viafb_refresh1;
599 u.viamode.bpp_sec = viafb_bpp1;
601 u.viamode.xres_sec = 0;
602 u.viamode.yres_sec = 0;
603 u.viamode.virtual_xres_sec = 0;
604 u.viamode.virtual_yres_sec = 0;
605 u.viamode.refresh_sec = 0;
606 u.viamode.bpp_sec = 0;
608 if (copy_to_user(argp, &u.viamode, sizeof(u.viamode)))
611 case VIAFB_GET_SAMM_INFO:
612 u.viasamm.samm_status = viafb_SAMM_ON;
614 if (viafb_SAMM_ON == 1) {
616 u.viasamm.size_prim = viaparinfo->fbmem_free;
617 u.viasamm.size_sec = viaparinfo1->fbmem_free;
619 if (viafb_second_size) {
620 u.viasamm.size_prim =
621 viaparinfo->fbmem_free -
622 viafb_second_size * 1024 * 1024;
624 viafb_second_size * 1024 * 1024;
626 u.viasamm.size_prim =
627 viaparinfo->fbmem_free >> 1;
629 (viaparinfo->fbmem_free >> 1);
632 u.viasamm.mem_base = viaparinfo->fbmem;
633 u.viasamm.offset_sec = viafb_second_offset;
635 u.viasamm.size_prim =
636 viaparinfo->memsize - viaparinfo->fbmem_used;
637 u.viasamm.size_sec = 0;
638 u.viasamm.mem_base = viaparinfo->fbmem;
639 u.viasamm.offset_sec = 0;
642 if (copy_to_user(argp, &u.viasamm, sizeof(u.viasamm)))
646 case VIAFB_TURN_ON_OUTPUT_DEVICE:
647 if (copy_from_user(&gpu32, argp, sizeof(gpu32)))
649 if (gpu32 & CRT_Device)
651 if (gpu32 & DVI_Device)
653 if (gpu32 & LCD_Device)
656 case VIAFB_TURN_OFF_OUTPUT_DEVICE:
657 if (copy_from_user(&gpu32, argp, sizeof(gpu32)))
659 if (gpu32 & CRT_Device)
661 if (gpu32 & DVI_Device)
663 if (gpu32 & LCD_Device)
666 case VIAFB_SET_DEVICE:
667 if (copy_from_user(&u.active_dev, (void *)argp,
668 sizeof(u.active_dev)))
670 viafb_set_device(u.active_dev);
673 case VIAFB_GET_DEVICE:
674 u.active_dev.crt = viafb_CRT_ON;
675 u.active_dev.dvi = viafb_DVI_ON;
676 u.active_dev.lcd = viafb_LCD_ON;
677 u.active_dev.samm = viafb_SAMM_ON;
678 u.active_dev.primary_dev = viafb_primary_dev;
680 u.active_dev.lcd_dsp_cent = viafb_lcd_dsp_method;
681 u.active_dev.lcd_panel_id = viafb_lcd_panel_id;
682 u.active_dev.lcd_mode = viafb_lcd_mode;
684 u.active_dev.xres = viafb_hotplug_Xres;
685 u.active_dev.yres = viafb_hotplug_Yres;
687 u.active_dev.xres1 = viafb_second_xres;
688 u.active_dev.yres1 = viafb_second_yres;
690 u.active_dev.bpp = viafb_bpp;
691 u.active_dev.bpp1 = viafb_bpp1;
692 u.active_dev.refresh = viafb_refresh;
693 u.active_dev.refresh1 = viafb_refresh1;
695 u.active_dev.epia_dvi = viafb_platform_epia_dvi;
696 u.active_dev.lcd_dual_edge = viafb_device_lcd_dualedge;
697 u.active_dev.bus_width = viafb_bus_width;
699 if (copy_to_user(argp, &u.active_dev, sizeof(u.active_dev)))
703 case VIAFB_GET_DRIVER_VERSION:
704 u.driver_version.iMajorNum = VERSION_MAJOR;
705 u.driver_version.iKernelNum = VERSION_KERNEL;
706 u.driver_version.iOSNum = VERSION_OS;
707 u.driver_version.iMinorNum = VERSION_MINOR;
709 if (copy_to_user(argp, &u.driver_version,
710 sizeof(u.driver_version)))
715 case VIAFB_SET_DEVICE_INFO:
716 if (copy_from_user(&u.viafb_setting,
717 argp, sizeof(u.viafb_setting)))
719 if (apply_device_setting(u.viafb_setting, info) < 0)
724 case VIAFB_SET_SECOND_MODE:
725 if (copy_from_user(&u.sec_var, argp, sizeof(u.sec_var)))
727 apply_second_mode_setting(&u.sec_var);
730 case VIAFB_GET_DEVICE_INFO:
732 retrieve_device_setting(&u.viafb_setting);
734 if (copy_to_user(argp, &u.viafb_setting,
735 sizeof(u.viafb_setting)))
740 case VIAFB_GET_DEVICE_SUPPORT:
741 viafb_get_device_support_state(&state_info);
742 if (put_user(state_info, argp))
746 case VIAFB_GET_DEVICE_CONNECT:
747 viafb_get_device_connect_state(&state_info);
748 if (put_user(state_info, argp))
752 case VIAFB_GET_PANEL_SUPPORT_EXPAND:
754 viafb_lcd_get_support_expand_state(info->var.xres,
756 if (put_user(state_info, argp))
760 case VIAFB_GET_DRIVER_NAME:
761 if (copy_to_user(argp, driver_name, sizeof(driver_name)))
765 case VIAFB_SET_GAMMA_LUT:
766 viafb_gamma_table = kmalloc(256 * sizeof(u32), GFP_KERNEL);
767 if (!viafb_gamma_table)
769 if (copy_from_user(viafb_gamma_table, argp,
770 sizeof(viafb_gamma_table))) {
771 kfree(viafb_gamma_table);
774 viafb_set_gamma_table(viafb_bpp, viafb_gamma_table);
775 kfree(viafb_gamma_table);
778 case VIAFB_GET_GAMMA_LUT:
779 viafb_gamma_table = kmalloc(256 * sizeof(u32), GFP_KERNEL);
780 if (!viafb_gamma_table)
782 viafb_get_gamma_table(viafb_gamma_table);
783 if (copy_to_user(argp, viafb_gamma_table,
784 sizeof(viafb_gamma_table))) {
785 kfree(viafb_gamma_table);
788 kfree(viafb_gamma_table);
791 case VIAFB_GET_GAMMA_SUPPORT_STATE:
792 viafb_get_gamma_support_state(viafb_bpp, &state_info);
793 if (put_user(state_info, argp))
796 case VIAFB_SET_VIDEO_DEVICE:
797 get_user(video_dev_info, argp);
798 viafb_set_video_device(video_dev_info);
800 case VIAFB_GET_VIDEO_DEVICE:
801 viafb_get_video_device(&video_dev_info);
802 if (put_user(video_dev_info, argp))
805 case VIAFB_SYNC_SURFACE:
806 DEBUG_MSG(KERN_INFO "lobo VIAFB_SYNC_SURFACE\n");
808 case VIAFB_GET_DRIVER_CAPS:
811 case VIAFB_GET_PANEL_MAX_SIZE:
812 if (copy_from_user(&u.panel_pos_size_para, argp,
813 sizeof(u.panel_pos_size_para)))
815 u.panel_pos_size_para.x = u.panel_pos_size_para.y = 0;
816 if (copy_to_user(argp, &u.panel_pos_size_para,
817 sizeof(u.panel_pos_size_para)))
820 case VIAFB_GET_PANEL_MAX_POSITION:
821 if (copy_from_user(&u.panel_pos_size_para, argp,
822 sizeof(u.panel_pos_size_para)))
824 u.panel_pos_size_para.x = u.panel_pos_size_para.y = 0;
825 if (copy_to_user(argp, &u.panel_pos_size_para,
826 sizeof(u.panel_pos_size_para)))
830 case VIAFB_GET_PANEL_POSITION:
831 if (copy_from_user(&u.panel_pos_size_para, argp,
832 sizeof(u.panel_pos_size_para)))
834 u.panel_pos_size_para.x = u.panel_pos_size_para.y = 0;
835 if (copy_to_user(argp, &u.panel_pos_size_para,
836 sizeof(u.panel_pos_size_para)))
839 case VIAFB_GET_PANEL_SIZE:
840 if (copy_from_user(&u.panel_pos_size_para, argp,
841 sizeof(u.panel_pos_size_para)))
843 u.panel_pos_size_para.x = u.panel_pos_size_para.y = 0;
844 if (copy_to_user(argp, &u.panel_pos_size_para,
845 sizeof(u.panel_pos_size_para)))
849 case VIAFB_SET_PANEL_POSITION:
850 if (copy_from_user(&u.panel_pos_size_para, argp,
851 sizeof(u.panel_pos_size_para)))
854 case VIAFB_SET_PANEL_SIZE:
855 if (copy_from_user(&u.panel_pos_size_para, argp,
856 sizeof(u.panel_pos_size_para)))
867 static void viafb_fillrect(struct fb_info *info,
868 const struct fb_fillrect *rect)
870 u32 col = 0, rop = 0;
874 cfb_fillrect(info, rect);
878 if (!rect->width || !rect->height)
891 switch (info->var.bits_per_pixel) {
896 col = ((u32 *) (info->pseudo_palette))[rect->color];
899 col = ((u32 *) (info->pseudo_palette))[rect->color];
903 /* BitBlt Source Address */
904 writel(0x0, viaparinfo->io_virt + VIA_REG_SRCPOS);
905 /* Source Base Address */
906 writel(0x0, viaparinfo->io_virt + VIA_REG_SRCBASE);
907 /* Destination Base Address */
908 writel(((unsigned long) (info->screen_base) -
909 (unsigned long) viafb_FB_MM) >> 3,
910 viaparinfo->io_virt + VIA_REG_DSTBASE);
912 pitch = (info->var.xres_virtual + 7) & ~7;
913 writel(VIA_PITCH_ENABLE |
915 info->var.bits_per_pixel >> 3) >> 3) |
917 var.bits_per_pixel >> 3) >> 3) << 16)),
918 viaparinfo->io_virt + VIA_REG_PITCH);
919 /* BitBlt Destination Address */
920 writel(((rect->dy << 16) | rect->dx),
921 viaparinfo->io_virt + VIA_REG_DSTPOS);
922 /* Dimension: width & height */
923 writel((((rect->height - 1) << 16) | (rect->width - 1)),
924 viaparinfo->io_virt + VIA_REG_DIMENSION);
925 /* Forground color or Destination color */
926 writel(col, viaparinfo->io_virt + VIA_REG_FGCOLOR);
928 writel((0x01 | 0x2000 | (rop << 24)),
929 viaparinfo->io_virt + VIA_REG_GECMD);
933 static void viafb_copyarea(struct fb_info *info,
934 const struct fb_copyarea *area)
936 u32 dy = area->dy, sy = area->sy, direction = 0x0;
937 u32 sx = area->sx, dx = area->dx, width = area->width;
940 DEBUG_MSG(KERN_INFO "viafb_copyarea!!\n");
943 cfb_copyarea(info, area);
947 if (!area->width || !area->height)
951 dy += area->height - 1;
952 sy += area->height - 1;
962 /* Source Base Address */
963 writel(((unsigned long) (info->screen_base) -
964 (unsigned long) viafb_FB_MM) >> 3,
965 viaparinfo->io_virt + VIA_REG_SRCBASE);
966 /* Destination Base Address */
967 writel(((unsigned long) (info->screen_base) -
968 (unsigned long) viafb_FB_MM) >> 3,
969 viaparinfo->io_virt + VIA_REG_DSTBASE);
971 pitch = (info->var.xres_virtual + 7) & ~7;
972 /* VIA_PITCH_ENABLE can be omitted now. */
973 writel(VIA_PITCH_ENABLE |
975 info->var.bits_per_pixel >> 3) >> 3) | (((pitch *
980 viaparinfo->io_virt + VIA_REG_PITCH);
981 /* BitBlt Source Address */
982 writel(((sy << 16) | sx), viaparinfo->io_virt + VIA_REG_SRCPOS);
983 /* BitBlt Destination Address */
984 writel(((dy << 16) | dx), viaparinfo->io_virt + VIA_REG_DSTPOS);
985 /* Dimension: width & height */
986 writel((((area->height - 1) << 16) | (area->width - 1)),
987 viaparinfo->io_virt + VIA_REG_DIMENSION);
989 writel((0x01 | direction | (0xCC << 24)),
990 viaparinfo->io_virt + VIA_REG_GECMD);
994 static void viafb_imageblit(struct fb_info *info,
995 const struct fb_image *image)
997 u32 size, bg_col = 0, fg_col = 0, *udata;
1002 cfb_imageblit(info, image);
1006 udata = (u32 *) image->data;
1008 switch (info->var.bits_per_pixel) {
1010 bg_col = image->bg_color;
1011 fg_col = image->fg_color;
1014 bg_col = ((u32 *) (info->pseudo_palette))[image->bg_color];
1015 fg_col = ((u32 *) (info->pseudo_palette))[image->fg_color];
1018 bg_col = ((u32 *) (info->pseudo_palette))[image->bg_color];
1019 fg_col = ((u32 *) (info->pseudo_palette))[image->fg_color];
1022 size = image->width * image->height;
1024 /* Source Base Address */
1025 writel(0x0, viaparinfo->io_virt + VIA_REG_SRCBASE);
1026 /* Destination Base Address */
1027 writel(((unsigned long) (info->screen_base) -
1028 (unsigned long) viafb_FB_MM) >> 3,
1029 viaparinfo->io_virt + VIA_REG_DSTBASE);
1031 pitch = (info->var.xres_virtual + 7) & ~7;
1032 writel(VIA_PITCH_ENABLE |
1034 info->var.bits_per_pixel >> 3) >> 3) | (((pitch *
1039 viaparinfo->io_virt + VIA_REG_PITCH);
1040 /* BitBlt Source Address */
1041 writel(0x0, viaparinfo->io_virt + VIA_REG_SRCPOS);
1042 /* BitBlt Destination Address */
1043 writel(((image->dy << 16) | image->dx),
1044 viaparinfo->io_virt + VIA_REG_DSTPOS);
1045 /* Dimension: width & height */
1046 writel((((image->height - 1) << 16) | (image->width - 1)),
1047 viaparinfo->io_virt + VIA_REG_DIMENSION);
1049 writel(fg_col, viaparinfo->io_virt + VIA_REG_FGCOLOR);
1051 writel(bg_col, viaparinfo->io_virt + VIA_REG_BGCOLOR);
1053 writel(0xCC020142, viaparinfo->io_virt + VIA_REG_GECMD);
1055 for (i = 0; i < size / 4; i++) {
1056 writel(*udata, viaparinfo->io_virt + VIA_MMIO_BLTBASE);
1062 static int viafb_cursor(struct fb_info *info, struct fb_cursor *cursor)
1064 u32 temp, xx, yy, bg_col = 0, fg_col = 0;
1066 static int hw_cursor;
1067 struct viafb_par *p_viafb_par;
1074 viafb_show_hw_cursor(info, HW_Cursor_OFF);
1080 if ((((struct viafb_par *)(info->par))->iga_path == IGA2)
1081 && (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266))
1084 /* When duoview and using lcd , use soft cursor */
1085 if (viafb_LCD_ON || ((struct viafb_par *)(info->par))->duoview)
1088 viafb_show_hw_cursor(info, HW_Cursor_OFF);
1089 viacursor = *cursor;
1091 if (cursor->set & FB_CUR_SETHOT) {
1092 viacursor.hot = cursor->hot;
1093 temp = ((viacursor.hot.x) << 16) + viacursor.hot.y;
1094 writel(temp, viaparinfo->io_virt + VIA_REG_CURSOR_ORG);
1097 if (cursor->set & FB_CUR_SETPOS) {
1098 viacursor.image.dx = cursor->image.dx;
1099 viacursor.image.dy = cursor->image.dy;
1100 yy = cursor->image.dy - info->var.yoffset;
1101 xx = cursor->image.dx - info->var.xoffset;
1104 writel(temp, viaparinfo->io_virt + VIA_REG_CURSOR_POS);
1107 if (cursor->set & FB_CUR_SETSIZE) {
1108 temp = readl(viaparinfo->io_virt + VIA_REG_CURSOR_MODE);
1110 if ((cursor->image.width <= 32)
1111 && (cursor->image.height <= 32)) {
1114 } else if ((cursor->image.width <= 64)
1115 && (cursor->image.height <= 64)) {
1120 "The cursor image is biger than 64x64 bits...\n");
1123 writel(temp, viaparinfo->io_virt + VIA_REG_CURSOR_MODE);
1125 viacursor.image.height = cursor->image.height;
1126 viacursor.image.width = cursor->image.width;
1129 if (cursor->set & FB_CUR_SETCMAP) {
1130 viacursor.image.fg_color = cursor->image.fg_color;
1131 viacursor.image.bg_color = cursor->image.bg_color;
1133 switch (info->var.bits_per_pixel) {
1139 (((info->cmap.red)[viacursor.image.bg_color] &
1141 ((info->cmap.green)[viacursor.image.bg_color] &
1143 (((info->cmap.blue)[viacursor.image.bg_color] &
1147 (((info->cmap.red)[viacursor.image.fg_color] &
1149 ((info->cmap.green)[viacursor.image.fg_color] &
1151 (((info->cmap.blue)[viacursor.image.fg_color] &
1158 /* This is indeed a patch for VT3324/VT3353 */
1161 p_viafb_par = (struct viafb_par *)info->par;
1163 if ((p_viafb_par->chip_info->gfx_chip_name ==
1165 ((p_viafb_par->chip_info->gfx_chip_name ==
1166 UNICHROME_VX800))) {
1168 (((info->cmap.red)[viacursor.image.bg_color] &
1170 (((info->cmap.green)[viacursor.image.bg_color] &
1172 (((info->cmap.blue)[viacursor.image.bg_color] &
1175 (((info->cmap.red)[viacursor.image.fg_color] &
1177 (((info->cmap.green)[viacursor.image.fg_color] &
1179 (((info->cmap.blue)[viacursor.image.fg_color] &
1183 writel(bg_col, viaparinfo->io_virt + VIA_REG_CURSOR_BG);
1184 writel(fg_col, viaparinfo->io_virt + VIA_REG_CURSOR_FG);
1187 if (cursor->set & FB_CUR_SETSHAPE) {
1189 u8 data[CURSOR_SIZE / 8];
1190 u32 bak[CURSOR_SIZE / 32];
1191 } *cr_data = kzalloc(sizeof(*cr_data), GFP_ATOMIC);
1193 ((viacursor.image.width + 7) >> 3) *
1194 viacursor.image.height;
1196 if (cr_data == NULL)
1199 if (MAX_CURS == 32) {
1200 for (i = 0; i < (CURSOR_SIZE / 32); i++) {
1201 cr_data->bak[i] = 0x0;
1202 cr_data->bak[i + 1] = 0xFFFFFFFF;
1205 } else if (MAX_CURS == 64) {
1206 for (i = 0; i < (CURSOR_SIZE / 32); i++) {
1207 cr_data->bak[i] = 0x0;
1208 cr_data->bak[i + 1] = 0x0;
1209 cr_data->bak[i + 2] = 0xFFFFFFFF;
1210 cr_data->bak[i + 3] = 0xFFFFFFFF;
1215 switch (viacursor.rop) {
1217 for (i = 0; i < size; i++)
1218 cr_data->data[i] = viacursor.mask[i];
1222 for (i = 0; i < size; i++)
1223 cr_data->data[i] = viacursor.mask[i];
1229 if (MAX_CURS == 32) {
1230 for (i = 0; i < size; i++) {
1231 cr_data->bak[j] = (u32) cr_data->data[i];
1232 cr_data->bak[j + 1] = ~cr_data->bak[j];
1235 } else if (MAX_CURS == 64) {
1236 for (i = 0; i < size; i++) {
1237 cr_data->bak[j] = (u32) cr_data->data[i];
1238 cr_data->bak[j + 1] = 0x0;
1239 cr_data->bak[j + 2] = ~cr_data->bak[j];
1240 cr_data->bak[j + 3] = ~cr_data->bak[j + 1];
1245 memcpy(((struct viafb_par *)(info->par))->fbmem_virt +
1246 ((struct viafb_par *)(info->par))->cursor_start,
1247 cr_data->bak, CURSOR_SIZE);
1252 if (viacursor.enable)
1253 viafb_show_hw_cursor(info, HW_Cursor_ON);
1258 static int viafb_sync(struct fb_info *info)
1261 viafb_wait_engine_idle();
1265 int viafb_get_mode_index(int hres, int vres, int flag)
1268 DEBUG_MSG(KERN_INFO "viafb_get_mode_index!\n");
1270 for (i = 0; viafb_modentry[i].mode_index != VIA_RES_INVALID; i++)
1271 if (viafb_modentry[i].xres == hres &&
1272 viafb_modentry[i].yres == vres)
1275 viafb_resMode = viafb_modentry[i].mode_index;
1277 viafb_mode1 = viafb_modentry[i].mode_res;
1279 viafb_mode = viafb_modentry[i].mode_res;
1281 return viafb_resMode;
1284 static void check_available_device_to_enable(int device_id)
1289 viafb_CRT_ON = STATE_OFF;
1290 viafb_DVI_ON = STATE_OFF;
1291 viafb_LCD_ON = STATE_OFF;
1292 viafb_LCD2_ON = STATE_OFF;
1293 viafb_DeviceStatus = None_Device;
1295 if ((device_id & CRT_Device) && (device_num < MAX_ACTIVE_DEV_NUM)) {
1296 viafb_CRT_ON = STATE_ON;
1298 viafb_DeviceStatus |= CRT_Device;
1301 if ((device_id & DVI_Device) && (device_num < MAX_ACTIVE_DEV_NUM)) {
1302 viafb_DVI_ON = STATE_ON;
1304 viafb_DeviceStatus |= DVI_Device;
1307 if ((device_id & LCD_Device) && (device_num < MAX_ACTIVE_DEV_NUM)) {
1308 viafb_LCD_ON = STATE_ON;
1310 viafb_DeviceStatus |= LCD_Device;
1313 if ((device_id & LCD2_Device) && (device_num < MAX_ACTIVE_DEV_NUM)) {
1314 viafb_LCD2_ON = STATE_ON;
1316 viafb_DeviceStatus |= LCD2_Device;
1319 if (viafb_DeviceStatus == None_Device) {
1320 /* Use CRT as default active device: */
1321 viafb_CRT_ON = STATE_ON;
1322 viafb_DeviceStatus = CRT_Device;
1324 DEBUG_MSG(KERN_INFO "Device Status:%x", viafb_DeviceStatus);
1327 static void viafb_set_device(struct device_t active_dev)
1329 /* Check available device to enable: */
1330 int device_id = None_Device;
1332 device_id |= CRT_Device;
1334 device_id |= DVI_Device;
1336 device_id |= LCD_Device;
1338 check_available_device_to_enable(device_id);
1340 /* Check property of LCD: */
1342 if (active_dev.lcd_dsp_cent) {
1343 viaparinfo->lvds_setting_info->display_method =
1344 viafb_lcd_dsp_method = LCD_CENTERING;
1346 viaparinfo->lvds_setting_info->display_method =
1347 viafb_lcd_dsp_method = LCD_EXPANDSION;
1350 if (active_dev.lcd_mode == LCD_SPWG) {
1351 viaparinfo->lvds_setting_info->lcd_mode =
1352 viafb_lcd_mode = LCD_SPWG;
1354 viaparinfo->lvds_setting_info->lcd_mode =
1355 viafb_lcd_mode = LCD_OPENLDI;
1358 if (active_dev.lcd_panel_id <= LCD_PANEL_ID_MAXIMUM) {
1359 viafb_lcd_panel_id = active_dev.lcd_panel_id;
1360 viafb_init_lcd_size();
1364 /* Check property of mode: */
1365 if (!active_dev.xres1)
1366 viafb_second_xres = 640;
1368 viafb_second_xres = active_dev.xres1;
1369 if (!active_dev.yres1)
1370 viafb_second_yres = 480;
1372 viafb_second_yres = active_dev.yres1;
1373 if (active_dev.bpp != 0)
1374 viafb_bpp = active_dev.bpp;
1375 if (active_dev.bpp1 != 0)
1376 viafb_bpp1 = active_dev.bpp1;
1377 if (active_dev.refresh != 0)
1378 viafb_refresh = active_dev.refresh;
1379 if (active_dev.refresh1 != 0)
1380 viafb_refresh1 = active_dev.refresh1;
1381 if ((active_dev.samm == STATE_OFF) || (active_dev.samm == STATE_ON))
1382 viafb_SAMM_ON = active_dev.samm;
1383 viafb_primary_dev = active_dev.primary_dev;
1385 viafb_set_start_addr();
1386 viafb_set_iga_path();
1389 static void viafb_set_video_device(u32 video_dev_info)
1391 viaparinfo->video_on_crt = STATE_OFF;
1392 viaparinfo->video_on_dvi = STATE_OFF;
1393 viaparinfo->video_on_lcd = STATE_OFF;
1395 /* Check available device to enable: */
1396 if ((video_dev_info & CRT_Device) == CRT_Device)
1397 viaparinfo->video_on_crt = STATE_ON;
1398 else if ((video_dev_info & DVI_Device) == DVI_Device)
1399 viaparinfo->video_on_dvi = STATE_ON;
1400 else if ((video_dev_info & LCD_Device) == LCD_Device)
1401 viaparinfo->video_on_lcd = STATE_ON;
1404 static void viafb_get_video_device(u32 *video_dev_info)
1406 *video_dev_info = None_Device;
1407 if (viaparinfo->video_on_crt == STATE_ON)
1408 *video_dev_info |= CRT_Device;
1409 else if (viaparinfo->video_on_dvi == STATE_ON)
1410 *video_dev_info |= DVI_Device;
1411 else if (viaparinfo->video_on_lcd == STATE_ON)
1412 *video_dev_info |= LCD_Device;
1415 static int get_primary_device(void)
1417 int primary_device = 0;
1418 /* Rule: device on iga1 path are the primary device. */
1419 if (viafb_SAMM_ON) {
1421 if (viaparinfo->crt_setting_info->iga_path == IGA1) {
1422 DEBUG_MSG(KERN_INFO "CRT IGA Path:%d\n",
1424 crt_setting_info->iga_path);
1425 primary_device = CRT_Device;
1429 if (viaparinfo->tmds_setting_info->iga_path == IGA1) {
1430 DEBUG_MSG(KERN_INFO "DVI IGA Path:%d\n",
1432 tmds_setting_info->iga_path);
1433 primary_device = DVI_Device;
1437 if (viaparinfo->lvds_setting_info->iga_path == IGA1) {
1438 DEBUG_MSG(KERN_INFO "LCD IGA Path:%d\n",
1440 lvds_setting_info->iga_path);
1441 primary_device = LCD_Device;
1444 if (viafb_LCD2_ON) {
1445 if (viaparinfo->lvds_setting_info2->iga_path == IGA1) {
1446 DEBUG_MSG(KERN_INFO "LCD2 IGA Path:%d\n",
1448 lvds_setting_info2->iga_path);
1449 primary_device = LCD2_Device;
1453 return primary_device;
1456 static u8 is_duoview(void)
1458 if (0 == viafb_SAMM_ON) {
1459 if (viafb_LCD_ON + viafb_LCD2_ON +
1460 viafb_DVI_ON + viafb_CRT_ON == 2)
1468 static void apply_second_mode_setting(struct fb_var_screeninfo
1471 u32 htotal, vtotal, long_refresh;
1473 htotal = sec_var->xres + sec_var->left_margin +
1474 sec_var->right_margin + sec_var->hsync_len;
1475 vtotal = sec_var->yres + sec_var->upper_margin +
1476 sec_var->lower_margin + sec_var->vsync_len;
1477 if ((sec_var->xres_virtual * (sec_var->bits_per_pixel >> 3)) & 0x1F) {
1478 /*Is 32 bytes alignment? */
1479 /*32 pixel alignment */
1480 sec_var->xres_virtual = (sec_var->xres_virtual + 31) & ~31;
1483 htotal = sec_var->xres + sec_var->left_margin +
1484 sec_var->right_margin + sec_var->hsync_len;
1485 vtotal = sec_var->yres + sec_var->upper_margin +
1486 sec_var->lower_margin + sec_var->vsync_len;
1487 long_refresh = 1000000000UL / sec_var->pixclock * 1000;
1488 long_refresh /= (htotal * vtotal);
1490 viafb_second_xres = sec_var->xres;
1491 viafb_second_yres = sec_var->yres;
1492 viafb_second_virtual_xres = sec_var->xres_virtual;
1493 viafb_second_virtual_yres = sec_var->yres_virtual;
1494 viafb_bpp1 = sec_var->bits_per_pixel;
1495 viafb_refresh1 = viafb_get_refresh(sec_var->xres, sec_var->yres,
1499 static int apply_device_setting(struct viafb_ioctl_setting setting_info,
1500 struct fb_info *info)
1502 int need_set_mode = 0;
1503 DEBUG_MSG(KERN_INFO "apply_device_setting\n");
1505 if (setting_info.device_flag) {
1507 check_available_device_to_enable(setting_info.device_status);
1510 /* Unlock LCD's operation according to LCD flag
1511 and check if the setting value is valid. */
1512 /* If the value is valid, apply the new setting value to the device. */
1514 if (setting_info.lcd_operation_flag & OP_LCD_CENTERING) {
1516 if (setting_info.lcd_attributes.display_center) {
1518 viaparinfo->lvds_setting_info->display_method =
1520 viafb_lcd_dsp_method = LCD_CENTERING;
1521 viaparinfo->lvds_setting_info2->display_method =
1522 viafb_lcd_dsp_method = LCD_CENTERING;
1525 viaparinfo->lvds_setting_info->display_method =
1527 viafb_lcd_dsp_method = LCD_EXPANDSION;
1528 viaparinfo->lvds_setting_info2->display_method =
1530 viafb_lcd_dsp_method = LCD_EXPANDSION;
1534 if (setting_info.lcd_operation_flag & OP_LCD_MODE) {
1536 if (setting_info.lcd_attributes.lcd_mode ==
1538 viaparinfo->lvds_setting_info->lcd_mode =
1539 viafb_lcd_mode = LCD_SPWG;
1541 viaparinfo->lvds_setting_info->lcd_mode =
1542 viafb_lcd_mode = LCD_OPENLDI;
1544 viaparinfo->lvds_setting_info2->lcd_mode =
1545 viaparinfo->lvds_setting_info->lcd_mode;
1548 if (setting_info.lcd_operation_flag & OP_LCD_PANEL_ID) {
1550 if (setting_info.lcd_attributes.panel_id <=
1551 LCD_PANEL_ID_MAXIMUM) {
1552 viafb_lcd_panel_id =
1553 setting_info.lcd_attributes.panel_id;
1554 viafb_init_lcd_size();
1559 if (0 != (setting_info.samm_status & OP_SAMM)) {
1560 setting_info.samm_status =
1561 setting_info.samm_status & (~OP_SAMM);
1562 if (setting_info.samm_status == 0
1563 || setting_info.samm_status == 1) {
1564 viafb_SAMM_ON = setting_info.samm_status;
1567 viafb_primary_dev = setting_info.primary_device;
1569 viafb_set_start_addr();
1570 viafb_set_iga_path();
1575 viaparinfo->duoview = is_duoview();
1577 if (!need_set_mode) {
1580 viafb_set_iga_path();
1581 viafb_set_par(info);
1586 static void retrieve_device_setting(struct viafb_ioctl_setting
1590 /* get device status */
1591 if (viafb_CRT_ON == 1)
1592 setting_info->device_status = CRT_Device;
1593 if (viafb_DVI_ON == 1)
1594 setting_info->device_status |= DVI_Device;
1595 if (viafb_LCD_ON == 1)
1596 setting_info->device_status |= LCD_Device;
1597 if (viafb_LCD2_ON == 1)
1598 setting_info->device_status |= LCD2_Device;
1599 if ((viaparinfo->video_on_crt == 1) && (viafb_CRT_ON == 1)) {
1600 setting_info->video_device_status =
1601 viaparinfo->crt_setting_info->iga_path;
1602 } else if ((viaparinfo->video_on_dvi == 1) && (viafb_DVI_ON == 1)) {
1603 setting_info->video_device_status =
1604 viaparinfo->tmds_setting_info->iga_path;
1605 } else if ((viaparinfo->video_on_lcd == 1) && (viafb_LCD_ON == 1)) {
1606 setting_info->video_device_status =
1607 viaparinfo->lvds_setting_info->iga_path;
1609 setting_info->video_device_status = 0;
1612 setting_info->samm_status = viafb_SAMM_ON;
1613 setting_info->primary_device = get_primary_device();
1615 setting_info->first_dev_bpp = viafb_bpp;
1616 setting_info->second_dev_bpp = viafb_bpp1;
1618 setting_info->first_dev_refresh = viafb_refresh;
1619 setting_info->second_dev_refresh = viafb_refresh1;
1621 setting_info->first_dev_hor_res = viafb_hotplug_Xres;
1622 setting_info->first_dev_ver_res = viafb_hotplug_Yres;
1623 setting_info->second_dev_hor_res = viafb_second_xres;
1624 setting_info->second_dev_ver_res = viafb_second_yres;
1626 /* Get lcd attributes */
1627 setting_info->lcd_attributes.display_center = viafb_lcd_dsp_method;
1628 setting_info->lcd_attributes.panel_id = viafb_lcd_panel_id;
1629 setting_info->lcd_attributes.lcd_mode = viafb_lcd_mode;
1632 static void parse_active_dev(void)
1634 viafb_CRT_ON = STATE_OFF;
1635 viafb_DVI_ON = STATE_OFF;
1636 viafb_LCD_ON = STATE_OFF;
1637 viafb_LCD2_ON = STATE_OFF;
1638 /* 1. Modify the active status of devices. */
1639 /* 2. Keep the order of devices, so we can set corresponding
1640 IGA path to devices in SAMM case. */
1641 /* Note: The previous of active_dev is primary device,
1642 and the following is secondary device. */
1643 if (!strncmp(viafb_active_dev, "CRT+DVI", 7)) {
1645 viafb_CRT_ON = STATE_ON;
1646 viafb_DVI_ON = STATE_ON;
1647 viafb_primary_dev = CRT_Device;
1648 } else if (!strncmp(viafb_active_dev, "DVI+CRT", 7)) {
1650 viafb_CRT_ON = STATE_ON;
1651 viafb_DVI_ON = STATE_ON;
1652 viafb_primary_dev = DVI_Device;
1653 } else if (!strncmp(viafb_active_dev, "CRT+LCD", 7)) {
1655 viafb_CRT_ON = STATE_ON;
1656 viafb_LCD_ON = STATE_ON;
1657 viafb_primary_dev = CRT_Device;
1658 } else if (!strncmp(viafb_active_dev, "LCD+CRT", 7)) {
1660 viafb_CRT_ON = STATE_ON;
1661 viafb_LCD_ON = STATE_ON;
1662 viafb_primary_dev = LCD_Device;
1663 } else if (!strncmp(viafb_active_dev, "DVI+LCD", 7)) {
1665 viafb_DVI_ON = STATE_ON;
1666 viafb_LCD_ON = STATE_ON;
1667 viafb_primary_dev = DVI_Device;
1668 } else if (!strncmp(viafb_active_dev, "LCD+DVI", 7)) {
1670 viafb_DVI_ON = STATE_ON;
1671 viafb_LCD_ON = STATE_ON;
1672 viafb_primary_dev = LCD_Device;
1673 } else if (!strncmp(viafb_active_dev, "LCD+LCD2", 8)) {
1674 viafb_LCD_ON = STATE_ON;
1675 viafb_LCD2_ON = STATE_ON;
1676 viafb_primary_dev = LCD_Device;
1677 } else if (!strncmp(viafb_active_dev, "LCD2+LCD", 8)) {
1678 viafb_LCD_ON = STATE_ON;
1679 viafb_LCD2_ON = STATE_ON;
1680 viafb_primary_dev = LCD2_Device;
1681 } else if (!strncmp(viafb_active_dev, "CRT", 3)) {
1683 viafb_CRT_ON = STATE_ON;
1684 viafb_SAMM_ON = STATE_OFF;
1685 } else if (!strncmp(viafb_active_dev, "DVI", 3)) {
1687 viafb_DVI_ON = STATE_ON;
1688 viafb_SAMM_ON = STATE_OFF;
1689 } else if (!strncmp(viafb_active_dev, "LCD", 3)) {
1691 viafb_LCD_ON = STATE_ON;
1692 viafb_SAMM_ON = STATE_OFF;
1694 viafb_CRT_ON = STATE_ON;
1695 viafb_SAMM_ON = STATE_OFF;
1697 viaparinfo->duoview = is_duoview();
1700 static void parse_video_dev(void)
1702 viaparinfo->video_on_crt = STATE_OFF;
1703 viaparinfo->video_on_dvi = STATE_OFF;
1704 viaparinfo->video_on_lcd = STATE_OFF;
1706 if (!strncmp(viafb_video_dev, "CRT", 3)) {
1708 viaparinfo->video_on_crt = STATE_ON;
1709 } else if (!strncmp(viafb_video_dev, "DVI", 3)) {
1711 viaparinfo->video_on_dvi = STATE_ON;
1712 } else if (!strncmp(viafb_video_dev, "LCD", 3)) {
1714 viaparinfo->video_on_lcd = STATE_ON;
1718 static int parse_port(char *opt_str, int *output_interface)
1720 if (!strncmp(opt_str, "DVP0", 4))
1721 *output_interface = INTERFACE_DVP0;
1722 else if (!strncmp(opt_str, "DVP1", 4))
1723 *output_interface = INTERFACE_DVP1;
1724 else if (!strncmp(opt_str, "DFP_HIGHLOW", 11))
1725 *output_interface = INTERFACE_DFP;
1726 else if (!strncmp(opt_str, "DFP_HIGH", 8))
1727 *output_interface = INTERFACE_DFP_HIGH;
1728 else if (!strncmp(opt_str, "DFP_LOW", 7))
1729 *output_interface = INTERFACE_DFP_LOW;
1731 *output_interface = INTERFACE_NONE;
1735 static void parse_lcd_port(void)
1737 parse_port(viafb_lcd_port, &viaparinfo->chip_info->lvds_chip_info.
1739 /*Initialize to avoid unexpected behavior */
1740 viaparinfo->chip_info->lvds_chip_info2.output_interface =
1743 DEBUG_MSG(KERN_INFO "parse_lcd_port: viafb_lcd_port:%s,interface:%d\n",
1744 viafb_lcd_port, viaparinfo->chip_info->lvds_chip_info.
1748 static void parse_dvi_port(void)
1750 parse_port(viafb_dvi_port, &viaparinfo->chip_info->tmds_chip_info.
1753 DEBUG_MSG(KERN_INFO "parse_dvi_port: viafb_dvi_port:%s,interface:%d\n",
1754 viafb_dvi_port, viaparinfo->chip_info->tmds_chip_info.
1759 * The proc filesystem read/write function, a simple proc implement to
1760 * get/set the value of DPA DVP0, DVP0DataDriving, DVP0ClockDriving, DVP1,
1761 * DVP1Driving, DFPHigh, DFPLow CR96, SR2A[5], SR1B[1], SR2A[4], SR1E[2],
1762 * CR9B, SR65, CR97, CR99
1764 static int viafb_dvp0_proc_read(char *buf, char **start, off_t offset,
1765 int count, int *eof, void *data)
1768 u8 dvp0_data_dri = 0, dvp0_clk_dri = 0, dvp0 = 0;
1770 (viafb_read_reg(VIASR, SR2A) & BIT5) >> 4 |
1771 (viafb_read_reg(VIASR, SR1B) & BIT1) >> 1;
1773 (viafb_read_reg(VIASR, SR2A) & BIT4) >> 3 |
1774 (viafb_read_reg(VIASR, SR1E) & BIT2) >> 2;
1775 dvp0 = viafb_read_reg(VIACR, CR96) & 0x0f;
1777 sprintf(buf + len, "%x %x %x\n", dvp0, dvp0_data_dri, dvp0_clk_dri);
1778 *eof = 1; /*Inform kernel end of data */
1781 static int viafb_dvp0_proc_write(struct file *file,
1782 const char __user *buffer, unsigned long count, void *data)
1784 char buf[20], *value, *pbuf;
1786 unsigned long length, i;
1789 length = count > 20 ? 20 : count;
1790 if (copy_from_user(&buf[0], buffer, length))
1792 buf[length - 1] = '\0'; /*Ensure end string */
1794 for (i = 0; i < 3; i++) {
1795 value = strsep(&pbuf, " ");
1796 if (value != NULL) {
1797 strict_strtoul(value, 0, (unsigned long *)®_val);
1798 DEBUG_MSG(KERN_INFO "DVP0:reg_val[%l]=:%x\n", i,
1802 viafb_write_reg_mask(CR96, VIACR,
1806 viafb_write_reg_mask(SR2A, VIASR,
1807 reg_val << 4, BIT5);
1808 viafb_write_reg_mask(SR1B, VIASR,
1809 reg_val << 1, BIT1);
1812 viafb_write_reg_mask(SR2A, VIASR,
1813 reg_val << 3, BIT4);
1814 viafb_write_reg_mask(SR1E, VIASR,
1815 reg_val << 2, BIT2);
1826 static int viafb_dvp1_proc_read(char *buf, char **start, off_t offset,
1827 int count, int *eof, void *data)
1830 u8 dvp1 = 0, dvp1_data_dri = 0, dvp1_clk_dri = 0;
1831 dvp1 = viafb_read_reg(VIACR, CR9B) & 0x0f;
1832 dvp1_data_dri = (viafb_read_reg(VIASR, SR65) & 0x0c) >> 2;
1833 dvp1_clk_dri = viafb_read_reg(VIASR, SR65) & 0x03;
1835 sprintf(buf + len, "%x %x %x\n", dvp1, dvp1_data_dri, dvp1_clk_dri);
1836 *eof = 1; /*Inform kernel end of data */
1839 static int viafb_dvp1_proc_write(struct file *file,
1840 const char __user *buffer, unsigned long count, void *data)
1842 char buf[20], *value, *pbuf;
1844 unsigned long length, i;
1847 length = count > 20 ? 20 : count;
1848 if (copy_from_user(&buf[0], buffer, length))
1850 buf[length - 1] = '\0'; /*Ensure end string */
1852 for (i = 0; i < 3; i++) {
1853 value = strsep(&pbuf, " ");
1854 if (value != NULL) {
1855 strict_strtoul(value, 0, (unsigned long *)®_val);
1858 viafb_write_reg_mask(CR9B, VIACR,
1862 viafb_write_reg_mask(SR65, VIASR,
1863 reg_val << 2, 0x0c);
1866 viafb_write_reg_mask(SR65, VIASR,
1879 static int viafb_dfph_proc_read(char *buf, char **start, off_t offset,
1880 int count, int *eof, void *data)
1884 dfp_high = viafb_read_reg(VIACR, CR97) & 0x0f;
1885 len += sprintf(buf + len, "%x\n", dfp_high);
1886 *eof = 1; /*Inform kernel end of data */
1889 static int viafb_dfph_proc_write(struct file *file,
1890 const char __user *buffer, unsigned long count, void *data)
1894 unsigned long length;
1897 length = count > 20 ? 20 : count;
1898 if (copy_from_user(&buf[0], buffer, length))
1900 buf[length - 1] = '\0'; /*Ensure end string */
1901 strict_strtoul(&buf[0], 0, (unsigned long *)®_val);
1902 viafb_write_reg_mask(CR97, VIACR, reg_val, 0x0f);
1905 static int viafb_dfpl_proc_read(char *buf, char **start, off_t offset,
1906 int count, int *eof, void *data)
1910 dfp_low = viafb_read_reg(VIACR, CR99) & 0x0f;
1911 len += sprintf(buf + len, "%x\n", dfp_low);
1912 *eof = 1; /*Inform kernel end of data */
1915 static int viafb_dfpl_proc_write(struct file *file,
1916 const char __user *buffer, unsigned long count, void *data)
1920 unsigned long length;
1923 length = count > 20 ? 20 : count;
1924 if (copy_from_user(&buf[0], buffer, length))
1926 buf[length - 1] = '\0'; /*Ensure end string */
1927 strict_strtoul(&buf[0], 0, (unsigned long *)®_val);
1928 viafb_write_reg_mask(CR99, VIACR, reg_val, 0x0f);
1931 static int viafb_vt1636_proc_read(char *buf, char **start,
1932 off_t offset, int count, int *eof, void *data)
1935 u8 vt1636_08 = 0, vt1636_09 = 0;
1936 switch (viaparinfo->chip_info->lvds_chip_info.lvds_chip_name) {
1939 viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info,
1940 &viaparinfo->chip_info->lvds_chip_info, 0x08) & 0x0f;
1942 viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info,
1943 &viaparinfo->chip_info->lvds_chip_info, 0x09) & 0x1f;
1944 len += sprintf(buf + len, "%x %x\n", vt1636_08, vt1636_09);
1949 switch (viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name) {
1952 viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info2,
1953 &viaparinfo->chip_info->lvds_chip_info2, 0x08) & 0x0f;
1955 viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info2,
1956 &viaparinfo->chip_info->lvds_chip_info2, 0x09) & 0x1f;
1957 len += sprintf(buf + len, " %x %x\n", vt1636_08, vt1636_09);
1962 *eof = 1; /*Inform kernel end of data */
1965 static int viafb_vt1636_proc_write(struct file *file,
1966 const char __user *buffer, unsigned long count, void *data)
1968 char buf[30], *value, *pbuf;
1969 struct IODATA reg_val;
1970 unsigned long length, i;
1973 length = count > 30 ? 30 : count;
1974 if (copy_from_user(&buf[0], buffer, length))
1976 buf[length - 1] = '\0'; /*Ensure end string */
1978 switch (viaparinfo->chip_info->lvds_chip_info.lvds_chip_name) {
1980 for (i = 0; i < 2; i++) {
1981 value = strsep(&pbuf, " ");
1982 if (value != NULL) {
1983 strict_strtoul(value, 0,
1984 (unsigned long *)®_val.Data);
1987 reg_val.Index = 0x08;
1988 reg_val.Mask = 0x0f;
1989 viafb_gpio_i2c_write_mask_lvds
1990 (viaparinfo->lvds_setting_info,
1992 chip_info->lvds_chip_info,
1996 reg_val.Index = 0x09;
1997 reg_val.Mask = 0x1f;
1998 viafb_gpio_i2c_write_mask_lvds
1999 (viaparinfo->lvds_setting_info,
2001 chip_info->lvds_chip_info,
2015 switch (viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name) {
2017 for (i = 0; i < 2; i++) {
2018 value = strsep(&pbuf, " ");
2019 if (value != NULL) {
2020 strict_strtoul(value, 0,
2021 (unsigned long *)®_val.Data);
2024 reg_val.Index = 0x08;
2025 reg_val.Mask = 0x0f;
2026 viafb_gpio_i2c_write_mask_lvds
2027 (viaparinfo->lvds_setting_info2,
2029 chip_info->lvds_chip_info2,
2033 reg_val.Index = 0x09;
2034 reg_val.Mask = 0x1f;
2035 viafb_gpio_i2c_write_mask_lvds
2036 (viaparinfo->lvds_setting_info2,
2038 chip_info->lvds_chip_info2,
2055 static void viafb_init_proc(struct proc_dir_entry **viafb_entry)
2057 struct proc_dir_entry *entry;
2058 *viafb_entry = proc_mkdir("viafb", NULL);
2060 entry = create_proc_entry("dvp0", 0, *viafb_entry);
2062 entry->owner = THIS_MODULE;
2063 entry->read_proc = viafb_dvp0_proc_read;
2064 entry->write_proc = viafb_dvp0_proc_write;
2066 entry = create_proc_entry("dvp1", 0, *viafb_entry);
2068 entry->owner = THIS_MODULE;
2069 entry->read_proc = viafb_dvp1_proc_read;
2070 entry->write_proc = viafb_dvp1_proc_write;
2072 entry = create_proc_entry("dfph", 0, *viafb_entry);
2074 entry->owner = THIS_MODULE;
2075 entry->read_proc = viafb_dfph_proc_read;
2076 entry->write_proc = viafb_dfph_proc_write;
2078 entry = create_proc_entry("dfpl", 0, *viafb_entry);
2080 entry->owner = THIS_MODULE;
2081 entry->read_proc = viafb_dfpl_proc_read;
2082 entry->write_proc = viafb_dfpl_proc_write;
2084 if (VT1636_LVDS == viaparinfo->chip_info->lvds_chip_info.
2085 lvds_chip_name || VT1636_LVDS ==
2086 viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name) {
2087 entry = create_proc_entry("vt1636", 0, *viafb_entry);
2089 entry->owner = THIS_MODULE;
2090 entry->read_proc = viafb_vt1636_proc_read;
2091 entry->write_proc = viafb_vt1636_proc_write;
2097 static void viafb_remove_proc(struct proc_dir_entry *viafb_entry)
2099 /* no problem if it was not registered */
2100 remove_proc_entry("dvp0", viafb_entry);/* parent dir */
2101 remove_proc_entry("dvp1", viafb_entry);
2102 remove_proc_entry("dfph", viafb_entry);
2103 remove_proc_entry("dfpl", viafb_entry);
2104 remove_proc_entry("vt1636", viafb_entry);
2105 remove_proc_entry("vt1625", viafb_entry);
2106 remove_proc_entry("viafb", NULL);
2109 static int __devinit via_pci_probe(void)
2111 unsigned int default_xres, default_yres;
2113 char *tmpc_sec, *tmpm_sec;
2115 u32 tmds_length, lvds_length, crt_length, chip_length, viafb_par_length;
2117 DEBUG_MSG(KERN_INFO "VIAFB PCI Probe!!\n");
2119 viafb_par_length = ALIGN(sizeof(struct viafb_par), BITS_PER_LONG/8);
2120 tmds_length = ALIGN(sizeof(struct tmds_setting_information),
2122 lvds_length = ALIGN(sizeof(struct lvds_setting_information),
2124 crt_length = ALIGN(sizeof(struct lvds_setting_information),
2126 chip_length = ALIGN(sizeof(struct chip_information), BITS_PER_LONG/8);
2128 /* Allocate fb_info and ***_par here, also including some other needed
2131 viafbinfo = framebuffer_alloc(viafb_par_length + 2 * lvds_length +
2132 tmds_length + crt_length + chip_length, NULL);
2134 printk(KERN_ERR"Could not allocate memory for viafb_info.\n");
2138 viaparinfo = (struct viafb_par *)viafbinfo->par;
2139 viaparinfo->tmds_setting_info = (struct tmds_setting_information *)
2140 ((unsigned long)viaparinfo + viafb_par_length);
2141 viaparinfo->lvds_setting_info = (struct lvds_setting_information *)
2142 ((unsigned long)viaparinfo->tmds_setting_info + tmds_length);
2143 viaparinfo->lvds_setting_info2 = (struct lvds_setting_information *)
2144 ((unsigned long)viaparinfo->lvds_setting_info + lvds_length);
2145 viaparinfo->crt_setting_info = (struct crt_setting_information *)
2146 ((unsigned long)viaparinfo->lvds_setting_info2 + lvds_length);
2147 viaparinfo->chip_info = (struct chip_information *)
2148 ((unsigned long)viaparinfo->crt_setting_info + crt_length);
2157 /* for dual-fb must viafb_SAMM_ON=1 and viafb_dual_fb=1 */
2161 /* Set up I2C bus stuff */
2162 viafb_create_i2c_bus(viaparinfo);
2164 viafb_init_chip_info();
2165 viafb_get_fb_info(&viaparinfo->fbmem, &viaparinfo->memsize);
2166 viaparinfo->fbmem_free = viaparinfo->memsize;
2167 viaparinfo->fbmem_used = 0;
2168 viaparinfo->fbmem_virt = ioremap_nocache(viaparinfo->fbmem,
2169 viaparinfo->memsize);
2170 viafbinfo->screen_base = (char *)viaparinfo->fbmem_virt;
2172 if (!viaparinfo->fbmem_virt) {
2173 printk(KERN_INFO "ioremap failed\n");
2177 viafb_get_mmio_info(&viaparinfo->mmio_base, &viaparinfo->mmio_len);
2178 viaparinfo->io_virt = ioremap_nocache(viaparinfo->mmio_base,
2179 viaparinfo->mmio_len);
2181 viafbinfo->node = 0;
2182 viafbinfo->fbops = &viafb_ops;
2183 viafbinfo->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
2185 viafbinfo->pseudo_palette = pseudo_pal;
2188 viafb_init_2d_engine();
2189 viafb_hw_cursor_init();
2192 if (viafb_second_size && (viafb_second_size < 8)) {
2193 viafb_second_offset = viaparinfo->fbmem_free -
2194 viafb_second_size * 1024 * 1024;
2196 viafb_second_size = 8;
2197 viafb_second_offset = viaparinfo->fbmem_free -
2198 viafb_second_size * 1024 * 1024;
2201 viafb_FB_MM = viaparinfo->fbmem_virt;
2203 tmpc = strsep(&tmpm, "x");
2204 strict_strtoul(tmpc, 0, (unsigned long *)&default_xres);
2205 strict_strtoul(tmpm, 0, (unsigned long *)&default_yres);
2207 vmode_index = viafb_get_mode_index(default_xres, default_yres, 0);
2208 DEBUG_MSG(KERN_INFO "0->index=%d\n", vmode_index);
2210 if (viafb_SAMM_ON == 1) {
2211 if (strcmp(viafb_mode, viafb_mode1)) {
2212 tmpm_sec = viafb_mode1;
2213 tmpc_sec = strsep(&tmpm_sec, "x");
2214 strict_strtoul(tmpc_sec, 0,
2215 (unsigned long *)&viafb_second_xres);
2216 strict_strtoul(tmpm_sec, 0,
2217 (unsigned long *)&viafb_second_yres);
2219 viafb_second_xres = default_xres;
2220 viafb_second_yres = default_yres;
2222 if (0 == viafb_second_virtual_xres) {
2223 switch (viafb_second_xres) {
2225 viafb_second_virtual_xres = 1408;
2228 viafb_second_virtual_xres = viafb_second_xres;
2232 if (0 == viafb_second_virtual_yres)
2233 viafb_second_virtual_yres = viafb_second_yres;
2236 switch (viafb_bpp) {
2249 default_var.xres = default_xres;
2250 default_var.yres = default_yres;
2251 switch (default_xres) {
2253 default_var.xres_virtual = 1408;
2256 default_var.xres_virtual = default_xres;
2259 default_var.yres_virtual = default_yres;
2260 default_var.bits_per_pixel = viafb_bpp;
2261 if (default_var.bits_per_pixel == 15)
2262 default_var.bits_per_pixel = 16;
2263 default_var.pixclock =
2264 viafb_get_pixclock(default_xres, default_yres, viafb_refresh);
2265 default_var.left_margin = (default_xres >> 3) & 0xf8;
2266 default_var.right_margin = 32;
2267 default_var.upper_margin = 16;
2268 default_var.lower_margin = 4;
2269 default_var.hsync_len = default_var.left_margin;
2270 default_var.vsync_len = 4;
2271 default_var.accel_flags = 0;
2275 (FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT |
2276 FBINFO_HWACCEL_IMAGEBLIT);
2277 default_var.accel_flags |= FB_ACCELF_TEXT;
2279 viafbinfo->flags |= FBINFO_HWACCEL_DISABLED;
2281 if (viafb_dual_fb) {
2282 viafbinfo1 = framebuffer_alloc(viafb_par_length, NULL);
2285 "allocate the second framebuffer struct error\n");
2286 framebuffer_release(viafbinfo);
2289 viaparinfo1 = viafbinfo1->par;
2290 memcpy(viaparinfo1, viaparinfo, viafb_par_length);
2291 viaparinfo1->memsize = viaparinfo->memsize -
2292 viafb_second_offset;
2293 viaparinfo->memsize = viafb_second_offset;
2294 viaparinfo1->fbmem_virt = viaparinfo->fbmem_virt +
2295 viafb_second_offset;
2296 viaparinfo1->fbmem = viaparinfo->fbmem + viafb_second_offset;
2298 viaparinfo1->fbmem_used = viaparinfo->fbmem_used;
2299 viaparinfo1->fbmem_free = viaparinfo1->memsize -
2300 viaparinfo1->fbmem_used;
2301 viaparinfo->fbmem_free = viaparinfo->memsize;
2302 viaparinfo->fbmem_used = 0;
2304 viaparinfo1->cursor_start =
2305 viaparinfo->cursor_start - viafb_second_offset;
2306 viaparinfo1->VQ_start = viaparinfo->VQ_start -
2307 viafb_second_offset;
2308 viaparinfo1->VQ_end = viaparinfo->VQ_end -
2309 viafb_second_offset;
2312 memcpy(viafbinfo1, viafbinfo, sizeof(struct fb_info));
2313 viafbinfo1->screen_base = viafbinfo->screen_base +
2314 viafb_second_offset;
2315 viafbinfo1->fix.smem_start = viaparinfo1->fbmem;
2316 viafbinfo1->fix.smem_len = viaparinfo1->fbmem_free;
2318 default_var.xres = viafb_second_xres;
2319 default_var.yres = viafb_second_yres;
2320 default_var.xres_virtual = viafb_second_virtual_xres;
2321 default_var.yres_virtual = viafb_second_virtual_yres;
2322 if (viafb_bpp1 != viafb_bpp)
2323 viafb_bpp1 = viafb_bpp;
2324 default_var.bits_per_pixel = viafb_bpp1;
2325 default_var.pixclock =
2326 viafb_get_pixclock(viafb_second_xres, viafb_second_yres,
2328 default_var.left_margin = (viafb_second_xres >> 3) & 0xf8;
2329 default_var.right_margin = 32;
2330 default_var.upper_margin = 16;
2331 default_var.lower_margin = 4;
2332 default_var.hsync_len = default_var.left_margin;
2333 default_var.vsync_len = 4;
2335 viafb_setup_fixinfo(&viafbinfo1->fix, viaparinfo1);
2336 viafb_check_var(&default_var, viafbinfo1);
2337 viafbinfo1->var = default_var;
2338 viafb_update_viafb_par(viafbinfo);
2339 viafb_update_fix(&viafbinfo1->fix, viafbinfo1);
2342 viafb_setup_fixinfo(&viafbinfo->fix, viaparinfo);
2343 viafb_check_var(&default_var, viafbinfo);
2344 viafbinfo->var = default_var;
2345 viafb_update_viafb_par(viafbinfo);
2346 viafb_update_fix(&viafbinfo->fix, viafbinfo);
2347 default_var.activate = FB_ACTIVATE_NOW;
2348 fb_alloc_cmap(&viafbinfo->cmap, 256, 0);
2350 if (viafb_dual_fb && (viafb_primary_dev == LCD_Device)
2351 && (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266)) {
2352 if (register_framebuffer(viafbinfo1) < 0)
2355 if (register_framebuffer(viafbinfo) < 0)
2358 if (viafb_dual_fb && ((viafb_primary_dev != LCD_Device)
2359 || (viaparinfo->chip_info->gfx_chip_name !=
2360 UNICHROME_CLE266))) {
2361 if (register_framebuffer(viafbinfo1) < 0)
2364 DEBUG_MSG(KERN_INFO "fb%d: %s frame buffer device %dx%d-%dbpp\n",
2365 viafbinfo->node, viafbinfo->fix.id, default_var.xres,
2366 default_var.yres, default_var.bits_per_pixel);
2368 viafb_init_proc(&viaparinfo->proc_entry);
2369 viafb_init_dac(IGA2);
2373 static void __devexit via_pci_remove(void)
2375 DEBUG_MSG(KERN_INFO "via_pci_remove!\n");
2376 fb_dealloc_cmap(&viafbinfo->cmap);
2377 unregister_framebuffer(viafbinfo);
2379 unregister_framebuffer(viafbinfo1);
2380 iounmap((void *)viaparinfo->fbmem_virt);
2381 iounmap(viaparinfo->io_virt);
2383 viafb_delete_i2c_buss(viaparinfo);
2385 framebuffer_release(viafbinfo);
2387 framebuffer_release(viafbinfo1);
2389 viafb_remove_proc(viaparinfo->proc_entry);
2393 static int __init viafb_setup(char *options)
2396 DEBUG_MSG(KERN_INFO "viafb_setup!\n");
2398 if (!options || !*options)
2401 while ((this_opt = strsep(&options, ",")) != NULL) {
2405 if (!strncmp(this_opt, "viafb_mode1=", 12))
2406 viafb_mode1 = kstrdup(this_opt + 12, GFP_KERNEL);
2407 else if (!strncmp(this_opt, "viafb_mode=", 11))
2408 viafb_mode = kstrdup(this_opt + 11, GFP_KERNEL);
2409 else if (!strncmp(this_opt, "viafb_bpp1=", 11))
2410 strict_strtoul(this_opt + 11, 0,
2411 (unsigned long *)&viafb_bpp1);
2412 else if (!strncmp(this_opt, "viafb_bpp=", 10))
2413 strict_strtoul(this_opt + 10, 0,
2414 (unsigned long *)&viafb_bpp);
2415 else if (!strncmp(this_opt, "viafb_refresh1=", 15))
2416 strict_strtoul(this_opt + 15, 0,
2417 (unsigned long *)&viafb_refresh1);
2418 else if (!strncmp(this_opt, "viafb_refresh=", 14))
2419 strict_strtoul(this_opt + 14, 0,
2420 (unsigned long *)&viafb_refresh);
2421 else if (!strncmp(this_opt, "viafb_lcd_dsp_method=", 21))
2422 strict_strtoul(this_opt + 21, 0,
2423 (unsigned long *)&viafb_lcd_dsp_method);
2424 else if (!strncmp(this_opt, "viafb_lcd_panel_id=", 19))
2425 strict_strtoul(this_opt + 19, 0,
2426 (unsigned long *)&viafb_lcd_panel_id);
2427 else if (!strncmp(this_opt, "viafb_accel=", 12))
2428 strict_strtoul(this_opt + 12, 0,
2429 (unsigned long *)&viafb_accel);
2430 else if (!strncmp(this_opt, "viafb_SAMM_ON=", 14))
2431 strict_strtoul(this_opt + 14, 0,
2432 (unsigned long *)&viafb_SAMM_ON);
2433 else if (!strncmp(this_opt, "viafb_active_dev=", 17))
2434 viafb_active_dev = kstrdup(this_opt + 17, GFP_KERNEL);
2435 else if (!strncmp(this_opt,
2436 "viafb_display_hardware_layout=", 30))
2437 strict_strtoul(this_opt + 30, 0,
2438 (unsigned long *)&viafb_display_hardware_layout);
2439 else if (!strncmp(this_opt, "viafb_second_size=", 18))
2440 strict_strtoul(this_opt + 18, 0,
2441 (unsigned long *)&viafb_second_size);
2442 else if (!strncmp(this_opt,
2443 "viafb_platform_epia_dvi=", 24))
2444 strict_strtoul(this_opt + 24, 0,
2445 (unsigned long *)&viafb_platform_epia_dvi);
2446 else if (!strncmp(this_opt,
2447 "viafb_device_lcd_dualedge=", 26))
2448 strict_strtoul(this_opt + 26, 0,
2449 (unsigned long *)&viafb_device_lcd_dualedge);
2450 else if (!strncmp(this_opt, "viafb_bus_width=", 16))
2451 strict_strtoul(this_opt + 16, 0,
2452 (unsigned long *)&viafb_bus_width);
2453 else if (!strncmp(this_opt, "viafb_lcd_mode=", 15))
2454 strict_strtoul(this_opt + 15, 0,
2455 (unsigned long *)&viafb_lcd_mode);
2456 else if (!strncmp(this_opt, "viafb_video_dev=", 16))
2457 viafb_video_dev = kstrdup(this_opt + 16, GFP_KERNEL);
2458 else if (!strncmp(this_opt, "viafb_lcd_port=", 15))
2459 viafb_lcd_port = kstrdup(this_opt + 15, GFP_KERNEL);
2460 else if (!strncmp(this_opt, "viafb_dvi_port=", 15))
2461 viafb_dvi_port = kstrdup(this_opt + 15, GFP_KERNEL);
2467 static int __init viafb_init(void)
2470 char *option = NULL;
2471 if (fb_get_options("viafb", &option))
2473 viafb_setup(option);
2476 "VIA Graphics Intergration Chipset framebuffer %d.%d initializing\n",
2477 VERSION_MAJOR, VERSION_MINOR);
2478 return via_pci_probe();
2481 static void __exit viafb_exit(void)
2483 DEBUG_MSG(KERN_INFO "viafb_exit!\n");
2487 static struct fb_ops viafb_ops = {
2488 .owner = THIS_MODULE,
2489 .fb_open = viafb_open,
2490 .fb_release = viafb_release,
2491 .fb_check_var = viafb_check_var,
2492 .fb_set_par = viafb_set_par,
2493 .fb_setcolreg = viafb_setcolreg,
2494 .fb_pan_display = viafb_pan_display,
2495 .fb_blank = viafb_blank,
2496 .fb_fillrect = viafb_fillrect,
2497 .fb_copyarea = viafb_copyarea,
2498 .fb_imageblit = viafb_imageblit,
2499 .fb_cursor = viafb_cursor,
2500 .fb_ioctl = viafb_ioctl,
2501 .fb_sync = viafb_sync,
2502 .fb_setcmap = viafb_setcmap,
2505 module_init(viafb_init);
2506 module_exit(viafb_exit);
2509 module_param(viafb_memsize, int, 0);
2511 module_param(viafb_mode, charp, 0);
2512 MODULE_PARM_DESC(viafb_mode, "Set resolution (default=640x480)");
2514 module_param(viafb_mode1, charp, 0);
2515 MODULE_PARM_DESC(viafb_mode1, "Set resolution (default=640x480)");
2517 module_param(viafb_bpp, int, 0);
2518 MODULE_PARM_DESC(viafb_bpp, "Set color depth (default=32bpp)");
2520 module_param(viafb_bpp1, int, 0);
2521 MODULE_PARM_DESC(viafb_bpp1, "Set color depth (default=32bpp)");
2523 module_param(viafb_refresh, int, 0);
2524 MODULE_PARM_DESC(viafb_refresh,
2525 "Set CRT viafb_refresh rate (default = 60)");
2527 module_param(viafb_refresh1, int, 0);
2528 MODULE_PARM_DESC(viafb_refresh1,
2529 "Set CRT refresh rate (default = 60)");
2531 module_param(viafb_lcd_panel_id, int, 0);
2532 MODULE_PARM_DESC(viafb_lcd_panel_id,
2533 "Set Flat Panel type(Default=1024x768)");
2535 module_param(viafb_lcd_dsp_method, int, 0);
2536 MODULE_PARM_DESC(viafb_lcd_dsp_method,
2537 "Set Flat Panel display scaling method.(Default=Expandsion)");
2539 module_param(viafb_SAMM_ON, int, 0);
2540 MODULE_PARM_DESC(viafb_SAMM_ON,
2541 "Turn on/off flag of SAMM(Default=OFF)");
2543 module_param(viafb_accel, int, 0);
2544 MODULE_PARM_DESC(viafb_accel,
2545 "Set 2D Hardware Acceleration.(Default = OFF)");
2547 module_param(viafb_active_dev, charp, 0);
2548 MODULE_PARM_DESC(viafb_active_dev, "Specify active devices.");
2550 module_param(viafb_display_hardware_layout, int, 0);
2551 MODULE_PARM_DESC(viafb_display_hardware_layout,
2552 "Display Hardware Layout (LCD Only, DVI Only...,etc)");
2554 module_param(viafb_second_size, int, 0);
2555 MODULE_PARM_DESC(viafb_second_size,
2556 "Set secondary device memory size");
2558 module_param(viafb_dual_fb, int, 0);
2559 MODULE_PARM_DESC(viafb_dual_fb,
2560 "Turn on/off flag of dual framebuffer devices.(Default = OFF)");
2562 module_param(viafb_platform_epia_dvi, int, 0);
2563 MODULE_PARM_DESC(viafb_platform_epia_dvi,
2564 "Turn on/off flag of DVI devices on EPIA board.(Default = OFF)");
2566 module_param(viafb_device_lcd_dualedge, int, 0);
2567 MODULE_PARM_DESC(viafb_device_lcd_dualedge,
2568 "Turn on/off flag of dual edge panel.(Default = OFF)");
2570 module_param(viafb_bus_width, int, 0);
2571 MODULE_PARM_DESC(viafb_bus_width,
2572 "Set bus width of panel.(Default = 12)");
2574 module_param(viafb_lcd_mode, int, 0);
2575 MODULE_PARM_DESC(viafb_lcd_mode,
2576 "Set Flat Panel mode(Default=OPENLDI)");
2578 module_param(viafb_video_dev, charp, 0);
2579 MODULE_PARM_DESC(viafb_video_dev, "Specify video devices.");
2581 module_param(viafb_lcd_port, charp, 0);
2582 MODULE_PARM_DESC(viafb_lcd_port, "Specify LCD output port.");
2584 module_param(viafb_dvi_port, charp, 0);
2585 MODULE_PARM_DESC(viafb_dvi_port, "Specify DVI output port.");
2587 MODULE_LICENSE("GPL");