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