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