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