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