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