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
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
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include <linux/module.h>
23 #include <linux/seq_file.h>
28 static struct fb_var_screeninfo default_var
;
29 static char *viafb_name
= "Via";
30 static u32 pseudo_pal
[17];
33 static char *viafb_mode
= "640x480";
34 static char *viafb_mode1
= "640x480";
36 /* Added for specifying active devices.*/
37 char *viafb_active_dev
= "";
39 /*Added for specify lcd output port*/
40 char *viafb_lcd_port
= "";
41 char *viafb_dvi_port
= "";
43 static void viafb_set_device(struct device_t active_dev
);
44 static int apply_device_setting(struct viafb_ioctl_setting setting_info
,
45 struct fb_info
*info
);
46 static void apply_second_mode_setting(struct fb_var_screeninfo
48 static void retrieve_device_setting(struct viafb_ioctl_setting
51 static struct fb_ops viafb_ops
;
54 static void viafb_update_fix(struct fb_info
*info
)
56 u32 bpp
= info
->var
.bits_per_pixel
;
59 bpp
== 8 ? FB_VISUAL_PSEUDOCOLOR
: FB_VISUAL_TRUECOLOR
;
60 info
->fix
.line_length
=
61 ((info
->var
.xres_virtual
+ 7) & ~7) * bpp
/ 8;
64 static void viafb_setup_fixinfo(struct fb_fix_screeninfo
*fix
,
65 struct viafb_par
*viaparinfo
)
67 memset(fix
, 0, sizeof(struct fb_fix_screeninfo
));
68 strcpy(fix
->id
, viafb_name
);
70 fix
->smem_start
= viaparinfo
->fbmem
;
71 fix
->smem_len
= viaparinfo
->fbmem_free
;
73 fix
->type
= FB_TYPE_PACKED_PIXELS
;
76 fix
->xpanstep
= fix
->ywrapstep
= 0;
79 /* Just tell the accel name */
80 viafbinfo
->fix
.accel
= FB_ACCEL_VIA_UNICHROME
;
82 static int viafb_open(struct fb_info
*info
, int user
)
84 DEBUG_MSG(KERN_INFO
"viafb_open!\n");
88 static int viafb_release(struct fb_info
*info
, int user
)
90 DEBUG_MSG(KERN_INFO
"viafb_release!\n");
94 static int viafb_check_var(struct fb_var_screeninfo
*var
,
97 int vmode_index
, htotal
, vtotal
;
98 struct viafb_par
*ppar
= info
->par
;
101 DEBUG_MSG(KERN_INFO
"viafb_check_var!\n");
103 /* HW neither support interlacte nor double-scaned mode */
104 if (var
->vmode
& FB_VMODE_INTERLACED
|| var
->vmode
& FB_VMODE_DOUBLE
)
107 vmode_index
= viafb_get_mode_index(var
->xres
, var
->yres
);
108 if (vmode_index
== VIA_RES_INVALID
) {
110 "viafb: Mode %dx%dx%d not supported!!\n",
111 var
->xres
, var
->yres
, var
->bits_per_pixel
);
115 if (24 == var
->bits_per_pixel
)
116 var
->bits_per_pixel
= 32;
118 if (var
->bits_per_pixel
!= 8 && var
->bits_per_pixel
!= 16 &&
119 var
->bits_per_pixel
!= 32)
122 if ((var
->xres_virtual
* (var
->bits_per_pixel
>> 3)) & 0x1F)
123 /*32 pixel alignment */
124 var
->xres_virtual
= (var
->xres_virtual
+ 31) & ~31;
125 if (var
->xres_virtual
* var
->yres_virtual
* var
->bits_per_pixel
/ 8 >
129 /* Based on var passed in to calculate the refresh,
130 * because our driver use some modes special.
132 htotal
= var
->xres
+ var
->left_margin
+
133 var
->right_margin
+ var
->hsync_len
;
134 vtotal
= var
->yres
+ var
->upper_margin
+
135 var
->lower_margin
+ var
->vsync_len
;
136 long_refresh
= 1000000000UL / var
->pixclock
* 1000;
137 long_refresh
/= (htotal
* vtotal
);
139 viafb_refresh
= viafb_get_refresh(var
->xres
, var
->yres
, long_refresh
);
141 /* Adjust var according to our driver's own table */
142 viafb_fill_var_timing_info(var
, viafb_refresh
, vmode_index
);
147 static int viafb_set_par(struct fb_info
*info
)
149 struct viafb_par
*viapar
= info
->par
;
151 int vmode_index1
= 0;
152 DEBUG_MSG(KERN_INFO
"viafb_set_par!\n");
154 viapar
->depth
= fb_get_color_depth(&info
->var
, &info
->fix
);
155 viafb_update_device_setting(info
->var
.xres
, info
->var
.yres
,
156 info
->var
.bits_per_pixel
, viafb_refresh
, 0);
158 vmode_index
= viafb_get_mode_index(info
->var
.xres
, info
->var
.yres
);
160 if (viafb_SAMM_ON
== 1) {
162 "viafb_second_xres = %d, viafb_second_yres = %d, bpp = %d\n",
163 viafb_second_xres
, viafb_second_yres
, viafb_bpp1
);
164 vmode_index1
= viafb_get_mode_index(viafb_second_xres
,
166 DEBUG_MSG(KERN_INFO
"->viafb_SAMM_ON: index=%d\n",
169 viafb_update_device_setting(viafb_second_xres
,
170 viafb_second_yres
, viafb_bpp1
, viafb_refresh1
, 1);
173 if (vmode_index
!= VIA_RES_INVALID
) {
174 viafb_setmode(vmode_index
, info
->var
.xres
, info
->var
.yres
,
175 info
->var
.bits_per_pixel
, vmode_index1
,
176 viafb_second_xres
, viafb_second_yres
, viafb_bpp1
);
178 /*We should set memory offset according virtual_x */
179 /*Fix me:put this function into viafb_setmode */
180 viafb_memory_pitch_patch(info
);
181 viafb_update_fix(info
);
182 viafb_bpp
= info
->var
.bits_per_pixel
;
183 /* Update viafb_accel, it is necessary to our 2D accelerate */
184 viafb_accel
= info
->var
.accel_flags
;
190 /* Set one color register */
191 static int viafb_setcolreg(unsigned regno
, unsigned red
, unsigned green
,
192 unsigned blue
, unsigned transp
, struct fb_info
*info
)
194 u8 sr1a
, sr1b
, cr67
, cr6a
, rev
= 0, shift
= 10;
195 unsigned cmap_entries
= (info
->var
.bits_per_pixel
== 8) ? 256 : 16;
196 DEBUG_MSG(KERN_INFO
"viafb_setcolreg!\n");
197 if (regno
>= cmap_entries
)
199 if (UNICHROME_CLE266
== viaparinfo
->chip_info
->gfx_chip_name
) {
201 * Read PCI bus 0,dev 0,function 0,index 0xF6 to get chip rev.
203 outl(0x80000000 | (0xf6 & ~3), (unsigned long)0xCF8);
204 rev
= (inl((unsigned long)0xCFC) >> ((0xf6 & 3) * 8)) & 0xff;
206 switch (info
->var
.bits_per_pixel
) {
217 /* Map the 3C6/7/8/9 to the IGA2 */
219 outb(sr1a
| 0x01, 0x3C5);
220 /* Second Display Engine colck always on */
222 outb(sr1b
| 0x80, 0x3C5);
223 /* Second Display Color Depth 8 */
225 outb(cr67
& 0x3F, 0x3D5);
227 /* Second Display Channel Reset CR6A[6]) */
228 outb(cr6a
& 0xBF, 0x3D5);
229 /* Second Display Channel Enable CR6A[7] */
230 outb(cr6a
| 0x80, 0x3D5);
231 /* Second Display Channel stop reset) */
232 outb(cr6a
| 0x40, 0x3D5);
234 /* Bit mask of palette */
236 /* Write one register of IGA2 */
238 if (UNICHROME_CLE266
== viaparinfo
->chip_info
->gfx_chip_name
&&
241 viafb_write_reg_mask(CR6A
, VIACR
, BIT5
, BIT5
);
242 viafb_write_reg_mask(SR15
, VIASR
, BIT7
, BIT7
);
245 viafb_write_reg_mask(CR6A
, VIACR
, 0, BIT5
);
246 viafb_write_reg_mask(SR15
, VIASR
, 0, BIT7
);
248 outb(red
>> shift
, 0x3C9);
249 outb(green
>> shift
, 0x3C9);
250 outb(blue
>> shift
, 0x3C9);
252 /* Map the 3C6/7/8/9 to the IGA1 */
254 outb(sr1a
& 0xFE, 0x3C5);
255 /* Bit mask of palette */
257 /* Write one register of IGA1 */
259 outb(red
>> shift
, 0x3C9);
260 outb(green
>> shift
, 0x3C9);
261 outb(blue
>> shift
, 0x3C9);
273 ((u32
*) info
->pseudo_palette
)[regno
] = (red
& 0xF800) |
274 ((green
& 0xFC00) >> 5) | ((blue
& 0xF800) >> 11);
277 ((u32
*) info
->pseudo_palette
)[regno
] =
278 ((transp
& 0xFF00) << 16) |
279 ((red
& 0xFF00) << 8) |
280 ((green
& 0xFF00)) | ((blue
& 0xFF00) >> 8);
288 /*CALLED BY: fb_set_cmap */
289 /* fb_set_var, pass 256 colors */
290 /*CALLED BY: fb_set_cmap */
291 /* fbcon_set_palette, pass 16 colors */
292 static int viafb_setcmap(struct fb_cmap
*cmap
, struct fb_info
*info
)
296 u16
*pred
= cmap
->red
;
297 u16
*pgreen
= cmap
->green
;
298 u16
*pblue
= cmap
->blue
;
299 u16
*ptransp
= cmap
->transp
;
300 u8 sr1a
, sr1b
, cr67
, cr6a
, rev
= 0, shift
= 10;
303 if (UNICHROME_CLE266
== viaparinfo
->chip_info
->gfx_chip_name
) {
305 * Read PCI bus 0, dev 0, function 0, index 0xF6 to get chip
308 outl(0x80000000 | (0xf6 & ~3), (unsigned long)0xCF8);
309 rev
= (inl((unsigned long)0xCFC) >> ((0xf6 & 3) * 8)) & 0xff;
311 switch (info
->var
.bits_per_pixel
) {
321 /* Map the 3C6/7/8/9 to the IGA2 */
323 outb(sr1a
| 0x01, 0x3C5);
325 /* Second Display Engine colck always on */
326 outb(sr1b
| 0x80, 0x3C5);
328 /* Second Display Color Depth 8 */
329 outb(cr67
& 0x3F, 0x3D5);
331 /* Second Display Channel Reset CR6A[6]) */
332 outb(cr6a
& 0xBF, 0x3D5);
333 /* Second Display Channel Enable CR6A[7] */
334 outb(cr6a
| 0x80, 0x3D5);
335 /* Second Display Channel stop reset) */
336 outb(cr6a
| 0xC0, 0x3D5);
338 /* Bit mask of palette */
341 if (UNICHROME_CLE266
== viaparinfo
->chip_info
->gfx_chip_name
&&
344 viafb_write_reg_mask(CR6A
, VIACR
, BIT5
, BIT5
);
345 viafb_write_reg_mask(SR15
, VIASR
, BIT7
, BIT7
);
348 viafb_write_reg_mask(CR6A
, VIACR
, 0, BIT5
);
349 viafb_write_reg_mask(SR15
, VIASR
, 0, BIT7
);
351 for (i
= 0; i
< len
; i
++) {
352 outb((*(pred
+ i
)) >> shift
, 0x3C9);
353 outb((*(pgreen
+ i
)) >> shift
, 0x3C9);
354 outb((*(pblue
+ i
)) >> shift
, 0x3C9);
358 /* Map the 3C6/7/8/9 to the IGA1 */
359 outb(sr1a
& 0xFE, 0x3C5);
360 /* Bit mask of palette */
363 for (i
= 0; i
< len
; i
++) {
364 outb((*(pred
+ i
)) >> shift
, 0x3C9);
365 outb((*(pgreen
+ i
)) >> shift
, 0x3C9);
366 outb((*(pblue
+ i
)) >> shift
, 0x3C9);
380 return 0; /* Because static u32 pseudo_pal[17]; */
381 for (i
= 0; i
< len
; i
++)
382 ((u32
*) info
->pseudo_palette
)[i
] =
383 (*(pred
+ i
) & 0xF800) |
384 ((*(pgreen
+ i
) & 0xFC00) >> 5) |
385 ((*(pblue
+ i
) & 0xF800) >> 11);
391 for (i
= 0; i
< len
; i
++)
392 ((u32
*) info
->pseudo_palette
)[i
] =
393 ((*(ptransp
+ i
) & 0xFF00) << 16) |
394 ((*(pred
+ i
) & 0xFF00) << 8) |
395 ((*(pgreen
+ i
) & 0xFF00)) |
396 ((*(pblue
+ i
) & 0xFF00) >> 8);
398 for (i
= 0; i
< len
; i
++)
399 ((u32
*) info
->pseudo_palette
)[i
] =
401 ((*(pred
+ i
) & 0xFF00) << 8) |
402 ((*(pgreen
+ i
) & 0xFF00)) |
403 ((*(pblue
+ i
) & 0xFF00) >> 8);
410 static int viafb_pan_display(struct fb_var_screeninfo
*var
,
411 struct fb_info
*info
)
415 DEBUG_MSG(KERN_INFO
"viafb_pan_display!\n");
417 offset
= (var
->xoffset
+ (var
->yoffset
* var
->xres_virtual
)) *
418 var
->bits_per_pixel
/ 16;
420 DEBUG_MSG(KERN_INFO
"\nviafb_pan_display,offset =%d ", offset
);
421 viafb_set_primary_address(offset
);
425 static int viafb_blank(int blank_mode
, struct fb_info
*info
)
427 DEBUG_MSG(KERN_INFO
"viafb_blank!\n");
428 /* clear DPMS setting */
430 switch (blank_mode
) {
431 case FB_BLANK_UNBLANK
:
432 /* Screen: On, HSync: On, VSync: On */
433 /* control CRT monitor power management */
434 viafb_write_reg_mask(CR36
, VIACR
, 0x00, BIT4
+ BIT5
);
436 case FB_BLANK_HSYNC_SUSPEND
:
437 /* Screen: Off, HSync: Off, VSync: On */
438 /* control CRT monitor power management */
439 viafb_write_reg_mask(CR36
, VIACR
, 0x10, BIT4
+ BIT5
);
441 case FB_BLANK_VSYNC_SUSPEND
:
442 /* Screen: Off, HSync: On, VSync: Off */
443 /* control CRT monitor power management */
444 viafb_write_reg_mask(CR36
, VIACR
, 0x20, BIT4
+ BIT5
);
446 case FB_BLANK_POWERDOWN
:
447 /* Screen: Off, HSync: Off, VSync: Off */
448 /* control CRT monitor power management */
449 viafb_write_reg_mask(CR36
, VIACR
, 0x30, BIT4
+ BIT5
);
456 static int viafb_ioctl(struct fb_info
*info
, u_int cmd
, u_long arg
)
459 struct viafb_ioctl_mode viamode
;
460 struct viafb_ioctl_samm viasamm
;
461 struct viafb_driver_version driver_version
;
462 struct fb_var_screeninfo sec_var
;
463 struct _panel_size_pos_info panel_pos_size_para
;
464 struct viafb_ioctl_setting viafb_setting
;
465 struct device_t active_dev
;
468 u32
*viafb_gamma_table
;
469 char driver_name
[] = "viafb";
471 u32 __user
*argp
= (u32 __user
*) arg
;
474 DEBUG_MSG(KERN_INFO
"viafb_ioctl: 0x%X !!\n", cmd
);
475 memset(&u
, 0, sizeof(u
));
478 case VIAFB_GET_CHIP_INFO
:
479 if (copy_to_user(argp
, viaparinfo
->chip_info
,
480 sizeof(struct chip_information
)))
483 case VIAFB_GET_INFO_SIZE
:
484 return put_user((u32
)sizeof(struct viafb_ioctl_info
), argp
);
486 return viafb_ioctl_get_viafb_info(arg
);
488 return put_user(viafb_ioctl_hotplug(info
->var
.xres
,
490 info
->var
.bits_per_pixel
), argp
);
491 case VIAFB_SET_HOTPLUG_FLAG
:
492 if (copy_from_user(&gpu32
, argp
, sizeof(gpu32
)))
494 viafb_hotplug
= (gpu32
) ? 1 : 0;
496 case VIAFB_GET_RESOLUTION
:
497 u
.viamode
.xres
= (u32
) viafb_hotplug_Xres
;
498 u
.viamode
.yres
= (u32
) viafb_hotplug_Yres
;
499 u
.viamode
.refresh
= (u32
) viafb_hotplug_refresh
;
500 u
.viamode
.bpp
= (u32
) viafb_hotplug_bpp
;
501 if (viafb_SAMM_ON
== 1) {
502 u
.viamode
.xres_sec
= viafb_second_xres
;
503 u
.viamode
.yres_sec
= viafb_second_yres
;
504 u
.viamode
.virtual_xres_sec
= viafb_second_virtual_xres
;
505 u
.viamode
.virtual_yres_sec
= viafb_second_virtual_yres
;
506 u
.viamode
.refresh_sec
= viafb_refresh1
;
507 u
.viamode
.bpp_sec
= viafb_bpp1
;
509 u
.viamode
.xres_sec
= 0;
510 u
.viamode
.yres_sec
= 0;
511 u
.viamode
.virtual_xres_sec
= 0;
512 u
.viamode
.virtual_yres_sec
= 0;
513 u
.viamode
.refresh_sec
= 0;
514 u
.viamode
.bpp_sec
= 0;
516 if (copy_to_user(argp
, &u
.viamode
, sizeof(u
.viamode
)))
519 case VIAFB_GET_SAMM_INFO
:
520 u
.viasamm
.samm_status
= viafb_SAMM_ON
;
522 if (viafb_SAMM_ON
== 1) {
524 u
.viasamm
.size_prim
= viaparinfo
->fbmem_free
;
525 u
.viasamm
.size_sec
= viaparinfo1
->fbmem_free
;
527 if (viafb_second_size
) {
528 u
.viasamm
.size_prim
=
529 viaparinfo
->fbmem_free
-
530 viafb_second_size
* 1024 * 1024;
532 viafb_second_size
* 1024 * 1024;
534 u
.viasamm
.size_prim
=
535 viaparinfo
->fbmem_free
>> 1;
537 (viaparinfo
->fbmem_free
>> 1);
540 u
.viasamm
.mem_base
= viaparinfo
->fbmem
;
541 u
.viasamm
.offset_sec
= viafb_second_offset
;
543 u
.viasamm
.size_prim
=
544 viaparinfo
->memsize
- viaparinfo
->fbmem_used
;
545 u
.viasamm
.size_sec
= 0;
546 u
.viasamm
.mem_base
= viaparinfo
->fbmem
;
547 u
.viasamm
.offset_sec
= 0;
550 if (copy_to_user(argp
, &u
.viasamm
, sizeof(u
.viasamm
)))
554 case VIAFB_TURN_ON_OUTPUT_DEVICE
:
555 if (copy_from_user(&gpu32
, argp
, sizeof(gpu32
)))
557 if (gpu32
& CRT_Device
)
559 if (gpu32
& DVI_Device
)
561 if (gpu32
& LCD_Device
)
564 case VIAFB_TURN_OFF_OUTPUT_DEVICE
:
565 if (copy_from_user(&gpu32
, argp
, sizeof(gpu32
)))
567 if (gpu32
& CRT_Device
)
569 if (gpu32
& DVI_Device
)
571 if (gpu32
& LCD_Device
)
574 case VIAFB_SET_DEVICE
:
575 if (copy_from_user(&u
.active_dev
, (void *)argp
,
576 sizeof(u
.active_dev
)))
578 viafb_set_device(u
.active_dev
);
581 case VIAFB_GET_DEVICE
:
582 u
.active_dev
.crt
= viafb_CRT_ON
;
583 u
.active_dev
.dvi
= viafb_DVI_ON
;
584 u
.active_dev
.lcd
= viafb_LCD_ON
;
585 u
.active_dev
.samm
= viafb_SAMM_ON
;
586 u
.active_dev
.primary_dev
= viafb_primary_dev
;
588 u
.active_dev
.lcd_dsp_cent
= viafb_lcd_dsp_method
;
589 u
.active_dev
.lcd_panel_id
= viafb_lcd_panel_id
;
590 u
.active_dev
.lcd_mode
= viafb_lcd_mode
;
592 u
.active_dev
.xres
= viafb_hotplug_Xres
;
593 u
.active_dev
.yres
= viafb_hotplug_Yres
;
595 u
.active_dev
.xres1
= viafb_second_xres
;
596 u
.active_dev
.yres1
= viafb_second_yres
;
598 u
.active_dev
.bpp
= viafb_bpp
;
599 u
.active_dev
.bpp1
= viafb_bpp1
;
600 u
.active_dev
.refresh
= viafb_refresh
;
601 u
.active_dev
.refresh1
= viafb_refresh1
;
603 u
.active_dev
.epia_dvi
= viafb_platform_epia_dvi
;
604 u
.active_dev
.lcd_dual_edge
= viafb_device_lcd_dualedge
;
605 u
.active_dev
.bus_width
= viafb_bus_width
;
607 if (copy_to_user(argp
, &u
.active_dev
, sizeof(u
.active_dev
)))
611 case VIAFB_GET_DRIVER_VERSION
:
612 u
.driver_version
.iMajorNum
= VERSION_MAJOR
;
613 u
.driver_version
.iKernelNum
= VERSION_KERNEL
;
614 u
.driver_version
.iOSNum
= VERSION_OS
;
615 u
.driver_version
.iMinorNum
= VERSION_MINOR
;
617 if (copy_to_user(argp
, &u
.driver_version
,
618 sizeof(u
.driver_version
)))
623 case VIAFB_SET_DEVICE_INFO
:
624 if (copy_from_user(&u
.viafb_setting
,
625 argp
, sizeof(u
.viafb_setting
)))
627 if (apply_device_setting(u
.viafb_setting
, info
) < 0)
632 case VIAFB_SET_SECOND_MODE
:
633 if (copy_from_user(&u
.sec_var
, argp
, sizeof(u
.sec_var
)))
635 apply_second_mode_setting(&u
.sec_var
);
638 case VIAFB_GET_DEVICE_INFO
:
640 retrieve_device_setting(&u
.viafb_setting
);
642 if (copy_to_user(argp
, &u
.viafb_setting
,
643 sizeof(u
.viafb_setting
)))
648 case VIAFB_GET_DEVICE_SUPPORT
:
649 viafb_get_device_support_state(&state_info
);
650 if (put_user(state_info
, argp
))
654 case VIAFB_GET_DEVICE_CONNECT
:
655 viafb_get_device_connect_state(&state_info
);
656 if (put_user(state_info
, argp
))
660 case VIAFB_GET_PANEL_SUPPORT_EXPAND
:
662 viafb_lcd_get_support_expand_state(info
->var
.xres
,
664 if (put_user(state_info
, argp
))
668 case VIAFB_GET_DRIVER_NAME
:
669 if (copy_to_user(argp
, driver_name
, sizeof(driver_name
)))
673 case VIAFB_SET_GAMMA_LUT
:
674 viafb_gamma_table
= kmalloc(256 * sizeof(u32
), GFP_KERNEL
);
675 if (!viafb_gamma_table
)
677 if (copy_from_user(viafb_gamma_table
, argp
,
678 sizeof(viafb_gamma_table
))) {
679 kfree(viafb_gamma_table
);
682 viafb_set_gamma_table(viafb_bpp
, viafb_gamma_table
);
683 kfree(viafb_gamma_table
);
686 case VIAFB_GET_GAMMA_LUT
:
687 viafb_gamma_table
= kmalloc(256 * sizeof(u32
), GFP_KERNEL
);
688 if (!viafb_gamma_table
)
690 viafb_get_gamma_table(viafb_gamma_table
);
691 if (copy_to_user(argp
, viafb_gamma_table
,
692 sizeof(viafb_gamma_table
))) {
693 kfree(viafb_gamma_table
);
696 kfree(viafb_gamma_table
);
699 case VIAFB_GET_GAMMA_SUPPORT_STATE
:
700 viafb_get_gamma_support_state(viafb_bpp
, &state_info
);
701 if (put_user(state_info
, argp
))
704 case VIAFB_SYNC_SURFACE
:
705 DEBUG_MSG(KERN_INFO
"lobo VIAFB_SYNC_SURFACE\n");
707 case VIAFB_GET_DRIVER_CAPS
:
710 case VIAFB_GET_PANEL_MAX_SIZE
:
711 if (copy_from_user(&u
.panel_pos_size_para
, argp
,
712 sizeof(u
.panel_pos_size_para
)))
714 u
.panel_pos_size_para
.x
= u
.panel_pos_size_para
.y
= 0;
715 if (copy_to_user(argp
, &u
.panel_pos_size_para
,
716 sizeof(u
.panel_pos_size_para
)))
719 case VIAFB_GET_PANEL_MAX_POSITION
:
720 if (copy_from_user(&u
.panel_pos_size_para
, argp
,
721 sizeof(u
.panel_pos_size_para
)))
723 u
.panel_pos_size_para
.x
= u
.panel_pos_size_para
.y
= 0;
724 if (copy_to_user(argp
, &u
.panel_pos_size_para
,
725 sizeof(u
.panel_pos_size_para
)))
729 case VIAFB_GET_PANEL_POSITION
:
730 if (copy_from_user(&u
.panel_pos_size_para
, argp
,
731 sizeof(u
.panel_pos_size_para
)))
733 u
.panel_pos_size_para
.x
= u
.panel_pos_size_para
.y
= 0;
734 if (copy_to_user(argp
, &u
.panel_pos_size_para
,
735 sizeof(u
.panel_pos_size_para
)))
738 case VIAFB_GET_PANEL_SIZE
:
739 if (copy_from_user(&u
.panel_pos_size_para
, argp
,
740 sizeof(u
.panel_pos_size_para
)))
742 u
.panel_pos_size_para
.x
= u
.panel_pos_size_para
.y
= 0;
743 if (copy_to_user(argp
, &u
.panel_pos_size_para
,
744 sizeof(u
.panel_pos_size_para
)))
748 case VIAFB_SET_PANEL_POSITION
:
749 if (copy_from_user(&u
.panel_pos_size_para
, argp
,
750 sizeof(u
.panel_pos_size_para
)))
753 case VIAFB_SET_PANEL_SIZE
:
754 if (copy_from_user(&u
.panel_pos_size_para
, argp
,
755 sizeof(u
.panel_pos_size_para
)))
766 static void viafb_fillrect(struct fb_info
*info
,
767 const struct fb_fillrect
*rect
)
769 struct viafb_par
*viapar
= info
->par
;
773 if (!viapar
->shared
->hw_bitblt
) {
774 cfb_fillrect(info
, rect
);
778 if (!rect
->width
|| !rect
->height
)
781 if (info
->fix
.visual
== FB_VISUAL_TRUECOLOR
)
782 fg_color
= ((u32
*)info
->pseudo_palette
)[rect
->color
];
784 fg_color
= rect
->color
;
786 if (rect
->rop
== ROP_XOR
)
791 DEBUG_MSG(KERN_DEBUG
"viafb 2D engine: fillrect\n");
792 if (viapar
->shared
->hw_bitblt(viapar
->io_virt
, VIA_BITBLT_FILL
,
793 rect
->width
, rect
->height
, info
->var
.bits_per_pixel
,
794 viapar
->vram_addr
, info
->fix
.line_length
, rect
->dx
, rect
->dy
,
795 NULL
, 0, 0, 0, 0, fg_color
, 0, rop
))
796 cfb_fillrect(info
, rect
);
799 static void viafb_copyarea(struct fb_info
*info
,
800 const struct fb_copyarea
*area
)
802 struct viafb_par
*viapar
= info
->par
;
804 if (!viapar
->shared
->hw_bitblt
) {
805 cfb_copyarea(info
, area
);
809 if (!area
->width
|| !area
->height
)
812 DEBUG_MSG(KERN_DEBUG
"viafb 2D engine: copyarea\n");
813 if (viapar
->shared
->hw_bitblt(viapar
->io_virt
, VIA_BITBLT_COLOR
,
814 area
->width
, area
->height
, info
->var
.bits_per_pixel
,
815 viapar
->vram_addr
, info
->fix
.line_length
, area
->dx
, area
->dy
,
816 NULL
, viapar
->vram_addr
, info
->fix
.line_length
,
817 area
->sx
, area
->sy
, 0, 0, 0))
818 cfb_copyarea(info
, area
);
821 static void viafb_imageblit(struct fb_info
*info
,
822 const struct fb_image
*image
)
824 struct viafb_par
*viapar
= info
->par
;
825 u32 fg_color
= 0, bg_color
= 0;
828 if (!viapar
->shared
->hw_bitblt
||
829 (image
->depth
!= 1 && image
->depth
!= viapar
->depth
)) {
830 cfb_imageblit(info
, image
);
834 if (image
->depth
== 1) {
835 op
= VIA_BITBLT_MONO
;
836 if (info
->fix
.visual
== FB_VISUAL_TRUECOLOR
) {
838 ((u32
*)info
->pseudo_palette
)[image
->fg_color
];
840 ((u32
*)info
->pseudo_palette
)[image
->bg_color
];
842 fg_color
= image
->fg_color
;
843 bg_color
= image
->bg_color
;
846 op
= VIA_BITBLT_COLOR
;
848 DEBUG_MSG(KERN_DEBUG
"viafb 2D engine: imageblit\n");
849 if (viapar
->shared
->hw_bitblt(viapar
->io_virt
, op
,
850 image
->width
, image
->height
, info
->var
.bits_per_pixel
,
851 viapar
->vram_addr
, info
->fix
.line_length
, image
->dx
, image
->dy
,
852 (u32
*)image
->data
, 0, 0, 0, 0, fg_color
, bg_color
, 0))
853 cfb_imageblit(info
, image
);
856 static int viafb_cursor(struct fb_info
*info
, struct fb_cursor
*cursor
)
858 struct viafb_par
*viapar
= info
->par
;
859 u32 temp
, xx
, yy
, bg_color
= 0, fg_color
= 0,
860 chip_name
= viapar
->shared
->chip_info
.gfx_chip_name
;
861 int i
, j
= 0, cur_size
= 64;
863 if (info
->flags
& FBINFO_HWACCEL_DISABLED
|| info
!= viafbinfo
)
866 if (chip_name
== UNICHROME_CLE266
&& viapar
->iga_path
== IGA2
)
869 viafb_show_hw_cursor(info
, HW_Cursor_OFF
);
871 if (cursor
->set
& FB_CUR_SETHOT
) {
872 temp
= (cursor
->hot
.x
<< 16) + cursor
->hot
.y
;
873 writel(temp
, viapar
->io_virt
+ VIA_REG_CURSOR_ORG
);
876 if (cursor
->set
& FB_CUR_SETPOS
) {
877 yy
= cursor
->image
.dy
- info
->var
.yoffset
;
878 xx
= cursor
->image
.dx
- info
->var
.xoffset
;
881 writel(temp
, viapar
->io_virt
+ VIA_REG_CURSOR_POS
);
884 if (cursor
->image
.width
<= 32 && cursor
->image
.height
<= 32)
886 else if (cursor
->image
.width
<= 64 && cursor
->image
.height
<= 64)
889 printk(KERN_WARNING
"viafb_cursor: The cursor is too large "
890 "%dx%d", cursor
->image
.width
, cursor
->image
.height
);
894 if (cursor
->set
& FB_CUR_SETSIZE
) {
895 temp
= readl(viapar
->io_virt
+ VIA_REG_CURSOR_MODE
);
901 writel(temp
, viapar
->io_virt
+ VIA_REG_CURSOR_MODE
);
904 if (cursor
->set
& FB_CUR_SETCMAP
) {
905 fg_color
= cursor
->image
.fg_color
;
906 bg_color
= cursor
->image
.bg_color
;
907 if (chip_name
== UNICHROME_CX700
||
908 chip_name
== UNICHROME_VX800
) {
910 ((info
->cmap
.red
[fg_color
] & 0xFFC0) << 14) |
911 ((info
->cmap
.green
[fg_color
] & 0xFFC0) << 4) |
912 ((info
->cmap
.blue
[fg_color
] & 0xFFC0) >> 6);
914 ((info
->cmap
.red
[bg_color
] & 0xFFC0) << 14) |
915 ((info
->cmap
.green
[bg_color
] & 0xFFC0) << 4) |
916 ((info
->cmap
.blue
[bg_color
] & 0xFFC0) >> 6);
919 ((info
->cmap
.red
[fg_color
] & 0xFF00) << 8) |
920 (info
->cmap
.green
[fg_color
] & 0xFF00) |
921 ((info
->cmap
.blue
[fg_color
] & 0xFF00) >> 8);
923 ((info
->cmap
.red
[bg_color
] & 0xFF00) << 8) |
924 (info
->cmap
.green
[bg_color
] & 0xFF00) |
925 ((info
->cmap
.blue
[bg_color
] & 0xFF00) >> 8);
928 writel(bg_color
, viapar
->io_virt
+ VIA_REG_CURSOR_BG
);
929 writel(fg_color
, viapar
->io_virt
+ VIA_REG_CURSOR_FG
);
932 if (cursor
->set
& FB_CUR_SETSHAPE
) {
934 u8 data
[CURSOR_SIZE
];
935 u32 bak
[CURSOR_SIZE
/ 4];
936 } *cr_data
= kzalloc(sizeof(*cr_data
), GFP_ATOMIC
);
937 int size
= ((cursor
->image
.width
+ 7) >> 3) *
938 cursor
->image
.height
;
943 if (cur_size
== 32) {
944 for (i
= 0; i
< (CURSOR_SIZE
/ 4); i
++) {
945 cr_data
->bak
[i
] = 0x0;
946 cr_data
->bak
[i
+ 1] = 0xFFFFFFFF;
950 for (i
= 0; i
< (CURSOR_SIZE
/ 4); i
++) {
951 cr_data
->bak
[i
] = 0x0;
952 cr_data
->bak
[i
+ 1] = 0x0;
953 cr_data
->bak
[i
+ 2] = 0xFFFFFFFF;
954 cr_data
->bak
[i
+ 3] = 0xFFFFFFFF;
959 switch (cursor
->rop
) {
961 for (i
= 0; i
< size
; i
++)
962 cr_data
->data
[i
] = cursor
->mask
[i
];
966 for (i
= 0; i
< size
; i
++)
967 cr_data
->data
[i
] = cursor
->mask
[i
];
973 if (cur_size
== 32) {
974 for (i
= 0; i
< size
; i
++) {
975 cr_data
->bak
[j
] = (u32
) cr_data
->data
[i
];
976 cr_data
->bak
[j
+ 1] = ~cr_data
->bak
[j
];
980 for (i
= 0; i
< size
; i
++) {
981 cr_data
->bak
[j
] = (u32
) cr_data
->data
[i
];
982 cr_data
->bak
[j
+ 1] = 0x0;
983 cr_data
->bak
[j
+ 2] = ~cr_data
->bak
[j
];
984 cr_data
->bak
[j
+ 3] = ~cr_data
->bak
[j
+ 1];
989 memcpy_toio(viafbinfo
->screen_base
+ viapar
->shared
->
990 cursor_vram_addr
, cr_data
->bak
, CURSOR_SIZE
);
995 viafb_show_hw_cursor(info
, HW_Cursor_ON
);
1000 static int viafb_sync(struct fb_info
*info
)
1003 viafb_wait_engine_idle();
1007 int viafb_get_mode_index(int hres
, int vres
)
1010 DEBUG_MSG(KERN_INFO
"viafb_get_mode_index!\n");
1012 for (i
= 0; i
< NUM_TOTAL_MODETABLE
; i
++)
1013 if (CLE266Modes
[i
].mode_array
&&
1014 CLE266Modes
[i
].crtc
[0].crtc
.hor_addr
== hres
&&
1015 CLE266Modes
[i
].crtc
[0].crtc
.ver_addr
== vres
)
1018 if (i
== NUM_TOTAL_MODETABLE
)
1019 return VIA_RES_INVALID
;
1021 return CLE266Modes
[i
].ModeIndex
;
1024 static void check_available_device_to_enable(int device_id
)
1029 viafb_CRT_ON
= STATE_OFF
;
1030 viafb_DVI_ON
= STATE_OFF
;
1031 viafb_LCD_ON
= STATE_OFF
;
1032 viafb_LCD2_ON
= STATE_OFF
;
1033 viafb_DeviceStatus
= None_Device
;
1035 if ((device_id
& CRT_Device
) && (device_num
< MAX_ACTIVE_DEV_NUM
)) {
1036 viafb_CRT_ON
= STATE_ON
;
1038 viafb_DeviceStatus
|= CRT_Device
;
1041 if ((device_id
& DVI_Device
) && (device_num
< MAX_ACTIVE_DEV_NUM
)) {
1042 viafb_DVI_ON
= STATE_ON
;
1044 viafb_DeviceStatus
|= DVI_Device
;
1047 if ((device_id
& LCD_Device
) && (device_num
< MAX_ACTIVE_DEV_NUM
)) {
1048 viafb_LCD_ON
= STATE_ON
;
1050 viafb_DeviceStatus
|= LCD_Device
;
1053 if ((device_id
& LCD2_Device
) && (device_num
< MAX_ACTIVE_DEV_NUM
)) {
1054 viafb_LCD2_ON
= STATE_ON
;
1056 viafb_DeviceStatus
|= LCD2_Device
;
1059 if (viafb_DeviceStatus
== None_Device
) {
1060 /* Use CRT as default active device: */
1061 viafb_CRT_ON
= STATE_ON
;
1062 viafb_DeviceStatus
= CRT_Device
;
1064 DEBUG_MSG(KERN_INFO
"Device Status:%x", viafb_DeviceStatus
);
1067 static void viafb_set_device(struct device_t active_dev
)
1069 /* Check available device to enable: */
1070 int device_id
= None_Device
;
1072 device_id
|= CRT_Device
;
1074 device_id
|= DVI_Device
;
1076 device_id
|= LCD_Device
;
1078 check_available_device_to_enable(device_id
);
1080 /* Check property of LCD: */
1082 if (active_dev
.lcd_dsp_cent
) {
1083 viaparinfo
->lvds_setting_info
->display_method
=
1084 viafb_lcd_dsp_method
= LCD_CENTERING
;
1086 viaparinfo
->lvds_setting_info
->display_method
=
1087 viafb_lcd_dsp_method
= LCD_EXPANDSION
;
1090 if (active_dev
.lcd_mode
== LCD_SPWG
) {
1091 viaparinfo
->lvds_setting_info
->lcd_mode
=
1092 viafb_lcd_mode
= LCD_SPWG
;
1094 viaparinfo
->lvds_setting_info
->lcd_mode
=
1095 viafb_lcd_mode
= LCD_OPENLDI
;
1098 if (active_dev
.lcd_panel_id
<= LCD_PANEL_ID_MAXIMUM
) {
1099 viafb_lcd_panel_id
= active_dev
.lcd_panel_id
;
1100 viafb_init_lcd_size();
1104 /* Check property of mode: */
1105 if (!active_dev
.xres1
)
1106 viafb_second_xres
= 640;
1108 viafb_second_xres
= active_dev
.xres1
;
1109 if (!active_dev
.yres1
)
1110 viafb_second_yres
= 480;
1112 viafb_second_yres
= active_dev
.yres1
;
1113 if (active_dev
.bpp
!= 0)
1114 viafb_bpp
= active_dev
.bpp
;
1115 if (active_dev
.bpp1
!= 0)
1116 viafb_bpp1
= active_dev
.bpp1
;
1117 if (active_dev
.refresh
!= 0)
1118 viafb_refresh
= active_dev
.refresh
;
1119 if (active_dev
.refresh1
!= 0)
1120 viafb_refresh1
= active_dev
.refresh1
;
1121 if ((active_dev
.samm
== STATE_OFF
) || (active_dev
.samm
== STATE_ON
))
1122 viafb_SAMM_ON
= active_dev
.samm
;
1123 viafb_primary_dev
= active_dev
.primary_dev
;
1125 viafb_set_primary_address(0);
1126 viafb_set_secondary_address(viafb_SAMM_ON
? viafb_second_offset
: 0);
1127 viafb_set_iga_path();
1130 static int get_primary_device(void)
1132 int primary_device
= 0;
1133 /* Rule: device on iga1 path are the primary device. */
1134 if (viafb_SAMM_ON
) {
1136 if (viaparinfo
->crt_setting_info
->iga_path
== IGA1
) {
1137 DEBUG_MSG(KERN_INFO
"CRT IGA Path:%d\n",
1139 crt_setting_info
->iga_path
);
1140 primary_device
= CRT_Device
;
1144 if (viaparinfo
->tmds_setting_info
->iga_path
== IGA1
) {
1145 DEBUG_MSG(KERN_INFO
"DVI IGA Path:%d\n",
1147 tmds_setting_info
->iga_path
);
1148 primary_device
= DVI_Device
;
1152 if (viaparinfo
->lvds_setting_info
->iga_path
== IGA1
) {
1153 DEBUG_MSG(KERN_INFO
"LCD IGA Path:%d\n",
1155 lvds_setting_info
->iga_path
);
1156 primary_device
= LCD_Device
;
1159 if (viafb_LCD2_ON
) {
1160 if (viaparinfo
->lvds_setting_info2
->iga_path
== IGA1
) {
1161 DEBUG_MSG(KERN_INFO
"LCD2 IGA Path:%d\n",
1163 lvds_setting_info2
->iga_path
);
1164 primary_device
= LCD2_Device
;
1168 return primary_device
;
1171 static void apply_second_mode_setting(struct fb_var_screeninfo
1174 u32 htotal
, vtotal
, long_refresh
;
1176 htotal
= sec_var
->xres
+ sec_var
->left_margin
+
1177 sec_var
->right_margin
+ sec_var
->hsync_len
;
1178 vtotal
= sec_var
->yres
+ sec_var
->upper_margin
+
1179 sec_var
->lower_margin
+ sec_var
->vsync_len
;
1180 if ((sec_var
->xres_virtual
* (sec_var
->bits_per_pixel
>> 3)) & 0x1F) {
1181 /*Is 32 bytes alignment? */
1182 /*32 pixel alignment */
1183 sec_var
->xres_virtual
= (sec_var
->xres_virtual
+ 31) & ~31;
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 long_refresh
= 1000000000UL / sec_var
->pixclock
* 1000;
1191 long_refresh
/= (htotal
* vtotal
);
1193 viafb_second_xres
= sec_var
->xres
;
1194 viafb_second_yres
= sec_var
->yres
;
1195 viafb_second_virtual_xres
= sec_var
->xres_virtual
;
1196 viafb_second_virtual_yres
= sec_var
->yres_virtual
;
1197 viafb_bpp1
= sec_var
->bits_per_pixel
;
1198 viafb_refresh1
= viafb_get_refresh(sec_var
->xres
, sec_var
->yres
,
1202 static int apply_device_setting(struct viafb_ioctl_setting setting_info
,
1203 struct fb_info
*info
)
1205 int need_set_mode
= 0;
1206 DEBUG_MSG(KERN_INFO
"apply_device_setting\n");
1208 if (setting_info
.device_flag
) {
1210 check_available_device_to_enable(setting_info
.device_status
);
1213 /* Unlock LCD's operation according to LCD flag
1214 and check if the setting value is valid. */
1215 /* If the value is valid, apply the new setting value to the device. */
1217 if (setting_info
.lcd_operation_flag
& OP_LCD_CENTERING
) {
1219 if (setting_info
.lcd_attributes
.display_center
) {
1221 viaparinfo
->lvds_setting_info
->display_method
=
1223 viafb_lcd_dsp_method
= LCD_CENTERING
;
1224 viaparinfo
->lvds_setting_info2
->display_method
=
1225 viafb_lcd_dsp_method
= LCD_CENTERING
;
1228 viaparinfo
->lvds_setting_info
->display_method
=
1230 viafb_lcd_dsp_method
= LCD_EXPANDSION
;
1231 viaparinfo
->lvds_setting_info2
->display_method
=
1233 viafb_lcd_dsp_method
= LCD_EXPANDSION
;
1237 if (setting_info
.lcd_operation_flag
& OP_LCD_MODE
) {
1239 if (setting_info
.lcd_attributes
.lcd_mode
==
1241 viaparinfo
->lvds_setting_info
->lcd_mode
=
1242 viafb_lcd_mode
= LCD_SPWG
;
1244 viaparinfo
->lvds_setting_info
->lcd_mode
=
1245 viafb_lcd_mode
= LCD_OPENLDI
;
1247 viaparinfo
->lvds_setting_info2
->lcd_mode
=
1248 viaparinfo
->lvds_setting_info
->lcd_mode
;
1251 if (setting_info
.lcd_operation_flag
& OP_LCD_PANEL_ID
) {
1253 if (setting_info
.lcd_attributes
.panel_id
<=
1254 LCD_PANEL_ID_MAXIMUM
) {
1255 viafb_lcd_panel_id
=
1256 setting_info
.lcd_attributes
.panel_id
;
1257 viafb_init_lcd_size();
1262 if (0 != (setting_info
.samm_status
& OP_SAMM
)) {
1263 setting_info
.samm_status
=
1264 setting_info
.samm_status
& (~OP_SAMM
);
1265 if (setting_info
.samm_status
== 0
1266 || setting_info
.samm_status
== 1) {
1267 viafb_SAMM_ON
= setting_info
.samm_status
;
1270 viafb_primary_dev
= setting_info
.primary_device
;
1272 viafb_set_primary_address(0);
1273 viafb_set_secondary_address(viafb_SAMM_ON
? viafb_second_offset
: 0);
1274 viafb_set_iga_path();
1279 if (!need_set_mode
) {
1282 viafb_set_iga_path();
1283 viafb_set_par(info
);
1288 static void retrieve_device_setting(struct viafb_ioctl_setting
1292 /* get device status */
1293 if (viafb_CRT_ON
== 1)
1294 setting_info
->device_status
= CRT_Device
;
1295 if (viafb_DVI_ON
== 1)
1296 setting_info
->device_status
|= DVI_Device
;
1297 if (viafb_LCD_ON
== 1)
1298 setting_info
->device_status
|= LCD_Device
;
1299 if (viafb_LCD2_ON
== 1)
1300 setting_info
->device_status
|= LCD2_Device
;
1302 setting_info
->samm_status
= viafb_SAMM_ON
;
1303 setting_info
->primary_device
= get_primary_device();
1305 setting_info
->first_dev_bpp
= viafb_bpp
;
1306 setting_info
->second_dev_bpp
= viafb_bpp1
;
1308 setting_info
->first_dev_refresh
= viafb_refresh
;
1309 setting_info
->second_dev_refresh
= viafb_refresh1
;
1311 setting_info
->first_dev_hor_res
= viafb_hotplug_Xres
;
1312 setting_info
->first_dev_ver_res
= viafb_hotplug_Yres
;
1313 setting_info
->second_dev_hor_res
= viafb_second_xres
;
1314 setting_info
->second_dev_ver_res
= viafb_second_yres
;
1316 /* Get lcd attributes */
1317 setting_info
->lcd_attributes
.display_center
= viafb_lcd_dsp_method
;
1318 setting_info
->lcd_attributes
.panel_id
= viafb_lcd_panel_id
;
1319 setting_info
->lcd_attributes
.lcd_mode
= viafb_lcd_mode
;
1322 static void parse_active_dev(void)
1324 viafb_CRT_ON
= STATE_OFF
;
1325 viafb_DVI_ON
= STATE_OFF
;
1326 viafb_LCD_ON
= STATE_OFF
;
1327 viafb_LCD2_ON
= STATE_OFF
;
1328 /* 1. Modify the active status of devices. */
1329 /* 2. Keep the order of devices, so we can set corresponding
1330 IGA path to devices in SAMM case. */
1331 /* Note: The previous of active_dev is primary device,
1332 and the following is secondary device. */
1333 if (!strncmp(viafb_active_dev
, "CRT+DVI", 7)) {
1335 viafb_CRT_ON
= STATE_ON
;
1336 viafb_DVI_ON
= STATE_ON
;
1337 viafb_primary_dev
= CRT_Device
;
1338 } else if (!strncmp(viafb_active_dev
, "DVI+CRT", 7)) {
1340 viafb_CRT_ON
= STATE_ON
;
1341 viafb_DVI_ON
= STATE_ON
;
1342 viafb_primary_dev
= DVI_Device
;
1343 } else if (!strncmp(viafb_active_dev
, "CRT+LCD", 7)) {
1345 viafb_CRT_ON
= STATE_ON
;
1346 viafb_LCD_ON
= STATE_ON
;
1347 viafb_primary_dev
= CRT_Device
;
1348 } else if (!strncmp(viafb_active_dev
, "LCD+CRT", 7)) {
1350 viafb_CRT_ON
= STATE_ON
;
1351 viafb_LCD_ON
= STATE_ON
;
1352 viafb_primary_dev
= LCD_Device
;
1353 } else if (!strncmp(viafb_active_dev
, "DVI+LCD", 7)) {
1355 viafb_DVI_ON
= STATE_ON
;
1356 viafb_LCD_ON
= STATE_ON
;
1357 viafb_primary_dev
= DVI_Device
;
1358 } else if (!strncmp(viafb_active_dev
, "LCD+DVI", 7)) {
1360 viafb_DVI_ON
= STATE_ON
;
1361 viafb_LCD_ON
= STATE_ON
;
1362 viafb_primary_dev
= LCD_Device
;
1363 } else if (!strncmp(viafb_active_dev
, "LCD+LCD2", 8)) {
1364 viafb_LCD_ON
= STATE_ON
;
1365 viafb_LCD2_ON
= STATE_ON
;
1366 viafb_primary_dev
= LCD_Device
;
1367 } else if (!strncmp(viafb_active_dev
, "LCD2+LCD", 8)) {
1368 viafb_LCD_ON
= STATE_ON
;
1369 viafb_LCD2_ON
= STATE_ON
;
1370 viafb_primary_dev
= LCD2_Device
;
1371 } else if (!strncmp(viafb_active_dev
, "CRT", 3)) {
1373 viafb_CRT_ON
= STATE_ON
;
1374 viafb_SAMM_ON
= STATE_OFF
;
1375 } else if (!strncmp(viafb_active_dev
, "DVI", 3)) {
1377 viafb_DVI_ON
= STATE_ON
;
1378 viafb_SAMM_ON
= STATE_OFF
;
1379 } else if (!strncmp(viafb_active_dev
, "LCD", 3)) {
1381 viafb_LCD_ON
= STATE_ON
;
1382 viafb_SAMM_ON
= STATE_OFF
;
1384 viafb_CRT_ON
= STATE_ON
;
1385 viafb_SAMM_ON
= STATE_OFF
;
1389 static int parse_port(char *opt_str
, int *output_interface
)
1391 if (!strncmp(opt_str
, "DVP0", 4))
1392 *output_interface
= INTERFACE_DVP0
;
1393 else if (!strncmp(opt_str
, "DVP1", 4))
1394 *output_interface
= INTERFACE_DVP1
;
1395 else if (!strncmp(opt_str
, "DFP_HIGHLOW", 11))
1396 *output_interface
= INTERFACE_DFP
;
1397 else if (!strncmp(opt_str
, "DFP_HIGH", 8))
1398 *output_interface
= INTERFACE_DFP_HIGH
;
1399 else if (!strncmp(opt_str
, "DFP_LOW", 7))
1400 *output_interface
= INTERFACE_DFP_LOW
;
1402 *output_interface
= INTERFACE_NONE
;
1406 static void parse_lcd_port(void)
1408 parse_port(viafb_lcd_port
, &viaparinfo
->chip_info
->lvds_chip_info
.
1410 /*Initialize to avoid unexpected behavior */
1411 viaparinfo
->chip_info
->lvds_chip_info2
.output_interface
=
1414 DEBUG_MSG(KERN_INFO
"parse_lcd_port: viafb_lcd_port:%s,interface:%d\n",
1415 viafb_lcd_port
, viaparinfo
->chip_info
->lvds_chip_info
.
1419 static void parse_dvi_port(void)
1421 parse_port(viafb_dvi_port
, &viaparinfo
->chip_info
->tmds_chip_info
.
1424 DEBUG_MSG(KERN_INFO
"parse_dvi_port: viafb_dvi_port:%s,interface:%d\n",
1425 viafb_dvi_port
, viaparinfo
->chip_info
->tmds_chip_info
.
1430 * The proc filesystem read/write function, a simple proc implement to
1431 * get/set the value of DPA DVP0, DVP0DataDriving, DVP0ClockDriving, DVP1,
1432 * DVP1Driving, DFPHigh, DFPLow CR96, SR2A[5], SR1B[1], SR2A[4], SR1E[2],
1433 * CR9B, SR65, CR97, CR99
1435 static int viafb_dvp0_proc_show(struct seq_file
*m
, void *v
)
1437 u8 dvp0_data_dri
= 0, dvp0_clk_dri
= 0, dvp0
= 0;
1439 (viafb_read_reg(VIASR
, SR2A
) & BIT5
) >> 4 |
1440 (viafb_read_reg(VIASR
, SR1B
) & BIT1
) >> 1;
1442 (viafb_read_reg(VIASR
, SR2A
) & BIT4
) >> 3 |
1443 (viafb_read_reg(VIASR
, SR1E
) & BIT2
) >> 2;
1444 dvp0
= viafb_read_reg(VIACR
, CR96
) & 0x0f;
1445 seq_printf(m
, "%x %x %x\n", dvp0
, dvp0_data_dri
, dvp0_clk_dri
);
1449 static int viafb_dvp0_proc_open(struct inode
*inode
, struct file
*file
)
1451 return single_open(file
, viafb_dvp0_proc_show
, NULL
);
1454 static ssize_t
viafb_dvp0_proc_write(struct file
*file
,
1455 const char __user
*buffer
, size_t count
, loff_t
*pos
)
1457 char buf
[20], *value
, *pbuf
;
1459 unsigned long length
, i
;
1462 length
= count
> 20 ? 20 : count
;
1463 if (copy_from_user(&buf
[0], buffer
, length
))
1465 buf
[length
- 1] = '\0'; /*Ensure end string */
1467 for (i
= 0; i
< 3; i
++) {
1468 value
= strsep(&pbuf
, " ");
1469 if (value
!= NULL
) {
1470 strict_strtoul(value
, 0, (unsigned long *)®_val
);
1471 DEBUG_MSG(KERN_INFO
"DVP0:reg_val[%l]=:%x\n", i
,
1475 viafb_write_reg_mask(CR96
, VIACR
,
1479 viafb_write_reg_mask(SR2A
, VIASR
,
1480 reg_val
<< 4, BIT5
);
1481 viafb_write_reg_mask(SR1B
, VIASR
,
1482 reg_val
<< 1, BIT1
);
1485 viafb_write_reg_mask(SR2A
, VIASR
,
1486 reg_val
<< 3, BIT4
);
1487 viafb_write_reg_mask(SR1E
, VIASR
,
1488 reg_val
<< 2, BIT2
);
1500 static const struct file_operations viafb_dvp0_proc_fops
= {
1501 .owner
= THIS_MODULE
,
1502 .open
= viafb_dvp0_proc_open
,
1504 .llseek
= seq_lseek
,
1505 .release
= single_release
,
1506 .write
= viafb_dvp0_proc_write
,
1509 static int viafb_dvp1_proc_show(struct seq_file
*m
, void *v
)
1511 u8 dvp1
= 0, dvp1_data_dri
= 0, dvp1_clk_dri
= 0;
1512 dvp1
= viafb_read_reg(VIACR
, CR9B
) & 0x0f;
1513 dvp1_data_dri
= (viafb_read_reg(VIASR
, SR65
) & 0x0c) >> 2;
1514 dvp1_clk_dri
= viafb_read_reg(VIASR
, SR65
) & 0x03;
1515 seq_printf(m
, "%x %x %x\n", dvp1
, dvp1_data_dri
, dvp1_clk_dri
);
1519 static int viafb_dvp1_proc_open(struct inode
*inode
, struct file
*file
)
1521 return single_open(file
, viafb_dvp1_proc_show
, NULL
);
1524 static ssize_t
viafb_dvp1_proc_write(struct file
*file
,
1525 const char __user
*buffer
, size_t count
, loff_t
*pos
)
1527 char buf
[20], *value
, *pbuf
;
1529 unsigned long length
, i
;
1532 length
= count
> 20 ? 20 : count
;
1533 if (copy_from_user(&buf
[0], buffer
, length
))
1535 buf
[length
- 1] = '\0'; /*Ensure end string */
1537 for (i
= 0; i
< 3; i
++) {
1538 value
= strsep(&pbuf
, " ");
1539 if (value
!= NULL
) {
1540 strict_strtoul(value
, 0, (unsigned long *)®_val
);
1543 viafb_write_reg_mask(CR9B
, VIACR
,
1547 viafb_write_reg_mask(SR65
, VIASR
,
1548 reg_val
<< 2, 0x0c);
1551 viafb_write_reg_mask(SR65
, VIASR
,
1564 static const struct file_operations viafb_dvp1_proc_fops
= {
1565 .owner
= THIS_MODULE
,
1566 .open
= viafb_dvp1_proc_open
,
1568 .llseek
= seq_lseek
,
1569 .release
= single_release
,
1570 .write
= viafb_dvp1_proc_write
,
1573 static int viafb_dfph_proc_show(struct seq_file
*m
, void *v
)
1576 dfp_high
= viafb_read_reg(VIACR
, CR97
) & 0x0f;
1577 seq_printf(m
, "%x\n", dfp_high
);
1581 static int viafb_dfph_proc_open(struct inode
*inode
, struct file
*file
)
1583 return single_open(file
, viafb_dfph_proc_show
, NULL
);
1586 static ssize_t
viafb_dfph_proc_write(struct file
*file
,
1587 const char __user
*buffer
, size_t count
, loff_t
*pos
)
1591 unsigned long length
;
1594 length
= count
> 20 ? 20 : count
;
1595 if (copy_from_user(&buf
[0], buffer
, length
))
1597 buf
[length
- 1] = '\0'; /*Ensure end string */
1598 strict_strtoul(&buf
[0], 0, (unsigned long *)®_val
);
1599 viafb_write_reg_mask(CR97
, VIACR
, reg_val
, 0x0f);
1603 static const struct file_operations viafb_dfph_proc_fops
= {
1604 .owner
= THIS_MODULE
,
1605 .open
= viafb_dfph_proc_open
,
1607 .llseek
= seq_lseek
,
1608 .release
= single_release
,
1609 .write
= viafb_dfph_proc_write
,
1612 static int viafb_dfpl_proc_show(struct seq_file
*m
, void *v
)
1615 dfp_low
= viafb_read_reg(VIACR
, CR99
) & 0x0f;
1616 seq_printf(m
, "%x\n", dfp_low
);
1620 static int viafb_dfpl_proc_open(struct inode
*inode
, struct file
*file
)
1622 return single_open(file
, viafb_dfpl_proc_show
, NULL
);
1625 static ssize_t
viafb_dfpl_proc_write(struct file
*file
,
1626 const char __user
*buffer
, size_t count
, loff_t
*pos
)
1630 unsigned long length
;
1633 length
= count
> 20 ? 20 : count
;
1634 if (copy_from_user(&buf
[0], buffer
, length
))
1636 buf
[length
- 1] = '\0'; /*Ensure end string */
1637 strict_strtoul(&buf
[0], 0, (unsigned long *)®_val
);
1638 viafb_write_reg_mask(CR99
, VIACR
, reg_val
, 0x0f);
1642 static const struct file_operations viafb_dfpl_proc_fops
= {
1643 .owner
= THIS_MODULE
,
1644 .open
= viafb_dfpl_proc_open
,
1646 .llseek
= seq_lseek
,
1647 .release
= single_release
,
1648 .write
= viafb_dfpl_proc_write
,
1651 static int viafb_vt1636_proc_show(struct seq_file
*m
, void *v
)
1653 u8 vt1636_08
= 0, vt1636_09
= 0;
1654 switch (viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
) {
1657 viafb_gpio_i2c_read_lvds(viaparinfo
->lvds_setting_info
,
1658 &viaparinfo
->chip_info
->lvds_chip_info
, 0x08) & 0x0f;
1660 viafb_gpio_i2c_read_lvds(viaparinfo
->lvds_setting_info
,
1661 &viaparinfo
->chip_info
->lvds_chip_info
, 0x09) & 0x1f;
1662 seq_printf(m
, "%x %x\n", vt1636_08
, vt1636_09
);
1667 switch (viaparinfo
->chip_info
->lvds_chip_info2
.lvds_chip_name
) {
1670 viafb_gpio_i2c_read_lvds(viaparinfo
->lvds_setting_info2
,
1671 &viaparinfo
->chip_info
->lvds_chip_info2
, 0x08) & 0x0f;
1673 viafb_gpio_i2c_read_lvds(viaparinfo
->lvds_setting_info2
,
1674 &viaparinfo
->chip_info
->lvds_chip_info2
, 0x09) & 0x1f;
1675 seq_printf(m
, " %x %x\n", vt1636_08
, vt1636_09
);
1683 static int viafb_vt1636_proc_open(struct inode
*inode
, struct file
*file
)
1685 return single_open(file
, viafb_vt1636_proc_show
, NULL
);
1688 static ssize_t
viafb_vt1636_proc_write(struct file
*file
,
1689 const char __user
*buffer
, size_t count
, loff_t
*pos
)
1691 char buf
[30], *value
, *pbuf
;
1692 struct IODATA reg_val
;
1693 unsigned long length
, i
;
1696 length
= count
> 30 ? 30 : count
;
1697 if (copy_from_user(&buf
[0], buffer
, length
))
1699 buf
[length
- 1] = '\0'; /*Ensure end string */
1701 switch (viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
) {
1703 for (i
= 0; i
< 2; i
++) {
1704 value
= strsep(&pbuf
, " ");
1705 if (value
!= NULL
) {
1706 strict_strtoul(value
, 0,
1707 (unsigned long *)®_val
.Data
);
1710 reg_val
.Index
= 0x08;
1711 reg_val
.Mask
= 0x0f;
1712 viafb_gpio_i2c_write_mask_lvds
1713 (viaparinfo
->lvds_setting_info
,
1715 chip_info
->lvds_chip_info
,
1719 reg_val
.Index
= 0x09;
1720 reg_val
.Mask
= 0x1f;
1721 viafb_gpio_i2c_write_mask_lvds
1722 (viaparinfo
->lvds_setting_info
,
1724 chip_info
->lvds_chip_info
,
1738 switch (viaparinfo
->chip_info
->lvds_chip_info2
.lvds_chip_name
) {
1740 for (i
= 0; i
< 2; i
++) {
1741 value
= strsep(&pbuf
, " ");
1742 if (value
!= NULL
) {
1743 strict_strtoul(value
, 0,
1744 (unsigned long *)®_val
.Data
);
1747 reg_val
.Index
= 0x08;
1748 reg_val
.Mask
= 0x0f;
1749 viafb_gpio_i2c_write_mask_lvds
1750 (viaparinfo
->lvds_setting_info2
,
1752 chip_info
->lvds_chip_info2
,
1756 reg_val
.Index
= 0x09;
1757 reg_val
.Mask
= 0x1f;
1758 viafb_gpio_i2c_write_mask_lvds
1759 (viaparinfo
->lvds_setting_info2
,
1761 chip_info
->lvds_chip_info2
,
1778 static const struct file_operations viafb_vt1636_proc_fops
= {
1779 .owner
= THIS_MODULE
,
1780 .open
= viafb_vt1636_proc_open
,
1782 .llseek
= seq_lseek
,
1783 .release
= single_release
,
1784 .write
= viafb_vt1636_proc_write
,
1787 static void viafb_init_proc(struct proc_dir_entry
**viafb_entry
)
1789 *viafb_entry
= proc_mkdir("viafb", NULL
);
1791 proc_create("dvp0", 0, *viafb_entry
, &viafb_dvp0_proc_fops
);
1792 proc_create("dvp1", 0, *viafb_entry
, &viafb_dvp1_proc_fops
);
1793 proc_create("dfph", 0, *viafb_entry
, &viafb_dfph_proc_fops
);
1794 proc_create("dfpl", 0, *viafb_entry
, &viafb_dfpl_proc_fops
);
1795 if (VT1636_LVDS
== viaparinfo
->chip_info
->lvds_chip_info
.
1796 lvds_chip_name
|| VT1636_LVDS
==
1797 viaparinfo
->chip_info
->lvds_chip_info2
.lvds_chip_name
) {
1798 proc_create("vt1636", 0, *viafb_entry
, &viafb_vt1636_proc_fops
);
1803 static void viafb_remove_proc(struct proc_dir_entry
*viafb_entry
)
1805 /* no problem if it was not registered */
1806 remove_proc_entry("dvp0", viafb_entry
);/* parent dir */
1807 remove_proc_entry("dvp1", viafb_entry
);
1808 remove_proc_entry("dfph", viafb_entry
);
1809 remove_proc_entry("dfpl", viafb_entry
);
1810 remove_proc_entry("vt1636", viafb_entry
);
1811 remove_proc_entry("vt1625", viafb_entry
);
1812 remove_proc_entry("viafb", NULL
);
1815 static int __devinit
via_pci_probe(void)
1817 unsigned long default_xres
, default_yres
;
1819 char *tmpc_sec
, *tmpm_sec
;
1821 u32 viafb_par_length
;
1823 DEBUG_MSG(KERN_INFO
"VIAFB PCI Probe!!\n");
1825 viafb_par_length
= ALIGN(sizeof(struct viafb_par
), BITS_PER_LONG
/8);
1827 /* Allocate fb_info and ***_par here, also including some other needed
1830 viafbinfo
= framebuffer_alloc(viafb_par_length
+
1831 ALIGN(sizeof(struct viafb_shared
), BITS_PER_LONG
/8), NULL
);
1833 printk(KERN_ERR
"Could not allocate memory for viafb_info.\n");
1837 viaparinfo
= (struct viafb_par
*)viafbinfo
->par
;
1838 viaparinfo
->shared
= viafbinfo
->par
+ viafb_par_length
;
1839 viaparinfo
->vram_addr
= 0;
1840 viaparinfo
->tmds_setting_info
= &viaparinfo
->shared
->tmds_setting_info
;
1841 viaparinfo
->lvds_setting_info
= &viaparinfo
->shared
->lvds_setting_info
;
1842 viaparinfo
->lvds_setting_info2
=
1843 &viaparinfo
->shared
->lvds_setting_info2
;
1844 viaparinfo
->crt_setting_info
= &viaparinfo
->shared
->crt_setting_info
;
1845 viaparinfo
->chip_info
= &viaparinfo
->shared
->chip_info
;
1853 /* for dual-fb must viafb_SAMM_ON=1 and viafb_dual_fb=1 */
1857 /* Set up I2C bus stuff */
1858 viafb_create_i2c_bus(viaparinfo
);
1860 viafb_init_chip_info();
1861 viafb_get_fb_info(&viaparinfo
->fbmem
, &viaparinfo
->memsize
);
1862 viaparinfo
->fbmem_free
= viaparinfo
->memsize
;
1863 viaparinfo
->fbmem_used
= 0;
1864 viafbinfo
->screen_base
= ioremap_nocache(viaparinfo
->fbmem
,
1865 viaparinfo
->memsize
);
1866 if (!viafbinfo
->screen_base
) {
1867 printk(KERN_INFO
"ioremap failed\n");
1871 viafb_get_mmio_info(&viafbinfo
->fix
.mmio_start
,
1872 &viafbinfo
->fix
.mmio_len
);
1873 viaparinfo
->io_virt
= ioremap_nocache(viafbinfo
->fix
.mmio_start
,
1874 viafbinfo
->fix
.mmio_len
);
1875 if (!viaparinfo
->io_virt
) {
1876 printk(KERN_WARNING
"ioremap failed: hardware acceleration disabled\n");
1880 viafbinfo
->node
= 0;
1881 viafbinfo
->fbops
= &viafb_ops
;
1882 viafbinfo
->flags
= FBINFO_DEFAULT
| FBINFO_HWACCEL_YPAN
;
1884 viafbinfo
->pseudo_palette
= pseudo_pal
;
1886 viafb_init_accel(viaparinfo
->shared
);
1887 viafb_init_2d_engine();
1888 viafb_hw_cursor_init();
1891 if (viafb_second_size
&& (viafb_second_size
< 8)) {
1892 viafb_second_offset
= viaparinfo
->fbmem_free
-
1893 viafb_second_size
* 1024 * 1024;
1895 viafb_second_size
= 8;
1896 viafb_second_offset
= viaparinfo
->fbmem_free
-
1897 viafb_second_size
* 1024 * 1024;
1901 tmpc
= strsep(&tmpm
, "x");
1902 strict_strtoul(tmpc
, 0, &default_xres
);
1903 strict_strtoul(tmpm
, 0, &default_yres
);
1905 vmode_index
= viafb_get_mode_index(default_xres
, default_yres
);
1906 DEBUG_MSG(KERN_INFO
"0->index=%d\n", vmode_index
);
1908 if (viafb_SAMM_ON
== 1) {
1909 if (strcmp(viafb_mode
, viafb_mode1
)) {
1910 tmpm_sec
= viafb_mode1
;
1911 tmpc_sec
= strsep(&tmpm_sec
, "x");
1912 strict_strtoul(tmpc_sec
, 0,
1913 (unsigned long *)&viafb_second_xres
);
1914 strict_strtoul(tmpm_sec
, 0,
1915 (unsigned long *)&viafb_second_yres
);
1917 viafb_second_xres
= default_xres
;
1918 viafb_second_yres
= default_yres
;
1920 if (0 == viafb_second_virtual_xres
) {
1921 switch (viafb_second_xres
) {
1923 viafb_second_virtual_xres
= 1408;
1926 viafb_second_virtual_xres
= viafb_second_xres
;
1930 if (0 == viafb_second_virtual_yres
)
1931 viafb_second_virtual_yres
= viafb_second_yres
;
1934 switch (viafb_bpp
) {
1947 default_var
.xres
= default_xres
;
1948 default_var
.yres
= default_yres
;
1949 switch (default_xres
) {
1951 default_var
.xres_virtual
= 1408;
1954 default_var
.xres_virtual
= default_xres
;
1957 default_var
.yres_virtual
= default_yres
;
1958 default_var
.bits_per_pixel
= viafb_bpp
;
1959 if (default_var
.bits_per_pixel
== 15)
1960 default_var
.bits_per_pixel
= 16;
1961 default_var
.pixclock
=
1962 viafb_get_pixclock(default_xres
, default_yres
, viafb_refresh
);
1963 default_var
.left_margin
= (default_xres
>> 3) & 0xf8;
1964 default_var
.right_margin
= 32;
1965 default_var
.upper_margin
= 16;
1966 default_var
.lower_margin
= 4;
1967 default_var
.hsync_len
= default_var
.left_margin
;
1968 default_var
.vsync_len
= 4;
1969 default_var
.accel_flags
= 0;
1973 (FBINFO_HWACCEL_COPYAREA
| FBINFO_HWACCEL_FILLRECT
|
1974 FBINFO_HWACCEL_IMAGEBLIT
);
1975 default_var
.accel_flags
|= FB_ACCELF_TEXT
;
1977 viafbinfo
->flags
|= FBINFO_HWACCEL_DISABLED
;
1979 if (viafb_dual_fb
) {
1980 viafbinfo1
= framebuffer_alloc(viafb_par_length
, NULL
);
1983 "allocate the second framebuffer struct error\n");
1984 framebuffer_release(viafbinfo
);
1987 viaparinfo1
= viafbinfo1
->par
;
1988 memcpy(viaparinfo1
, viaparinfo
, viafb_par_length
);
1989 viaparinfo1
->vram_addr
= viafb_second_offset
;
1990 viaparinfo1
->memsize
= viaparinfo
->memsize
-
1991 viafb_second_offset
;
1992 viaparinfo
->memsize
= viafb_second_offset
;
1993 viaparinfo1
->fbmem
= viaparinfo
->fbmem
+ viafb_second_offset
;
1995 viaparinfo1
->fbmem_used
= viaparinfo
->fbmem_used
;
1996 viaparinfo1
->fbmem_free
= viaparinfo1
->memsize
-
1997 viaparinfo1
->fbmem_used
;
1998 viaparinfo
->fbmem_free
= viaparinfo
->memsize
;
1999 viaparinfo
->fbmem_used
= 0;
2001 viaparinfo1
->VQ_start
= viaparinfo
->VQ_start
-
2002 viafb_second_offset
;
2003 viaparinfo1
->VQ_end
= viaparinfo
->VQ_end
-
2004 viafb_second_offset
;
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
,
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
,
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
,
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)
2053 if (register_framebuffer(viafbinfo
) < 0)
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)
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
);
2071 static void __devexit
via_pci_remove(void)
2073 DEBUG_MSG(KERN_INFO
"via_pci_remove!\n");
2074 fb_dealloc_cmap(&viafbinfo
->cmap
);
2075 unregister_framebuffer(viafbinfo
);
2077 unregister_framebuffer(viafbinfo1
);
2078 iounmap((void *)viafbinfo
->screen_base
);
2079 iounmap(viaparinfo
->io_virt
);
2081 viafb_delete_i2c_buss(viaparinfo
);
2083 framebuffer_release(viafbinfo
);
2085 framebuffer_release(viafbinfo1
);
2087 viafb_remove_proc(viaparinfo
->shared
->proc_entry
);
2091 static int __init
viafb_setup(char *options
)
2094 DEBUG_MSG(KERN_INFO
"viafb_setup!\n");
2096 if (!options
|| !*options
)
2099 while ((this_opt
= strsep(&options
, ",")) != NULL
) {
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
);
2163 static int __init
viafb_init(void)
2166 char *option
= NULL
;
2167 if (fb_get_options("viafb", &option
))
2169 viafb_setup(option
);
2172 "VIA Graphics Intergration Chipset framebuffer %d.%d initializing\n",
2173 VERSION_MAJOR
, VERSION_MINOR
);
2174 return via_pci_probe();
2177 static void __exit
viafb_exit(void)
2179 DEBUG_MSG(KERN_INFO
"viafb_exit!\n");
2183 static struct fb_ops viafb_ops
= {
2184 .owner
= THIS_MODULE
,
2185 .fb_open
= viafb_open
,
2186 .fb_release
= viafb_release
,
2187 .fb_check_var
= viafb_check_var
,
2188 .fb_set_par
= viafb_set_par
,
2189 .fb_setcolreg
= viafb_setcolreg
,
2190 .fb_pan_display
= viafb_pan_display
,
2191 .fb_blank
= viafb_blank
,
2192 .fb_fillrect
= viafb_fillrect
,
2193 .fb_copyarea
= viafb_copyarea
,
2194 .fb_imageblit
= viafb_imageblit
,
2195 .fb_cursor
= viafb_cursor
,
2196 .fb_ioctl
= viafb_ioctl
,
2197 .fb_sync
= viafb_sync
,
2198 .fb_setcmap
= viafb_setcmap
,
2201 module_init(viafb_init
);
2202 module_exit(viafb_exit
);
2205 module_param(viafb_memsize
, int, 0);
2207 module_param(viafb_mode
, charp
, 0);
2208 MODULE_PARM_DESC(viafb_mode
, "Set resolution (default=640x480)");
2210 module_param(viafb_mode1
, charp
, 0);
2211 MODULE_PARM_DESC(viafb_mode1
, "Set resolution (default=640x480)");
2213 module_param(viafb_bpp
, int, 0);
2214 MODULE_PARM_DESC(viafb_bpp
, "Set color depth (default=32bpp)");
2216 module_param(viafb_bpp1
, int, 0);
2217 MODULE_PARM_DESC(viafb_bpp1
, "Set color depth (default=32bpp)");
2219 module_param(viafb_refresh
, int, 0);
2220 MODULE_PARM_DESC(viafb_refresh
,
2221 "Set CRT viafb_refresh rate (default = 60)");
2223 module_param(viafb_refresh1
, int, 0);
2224 MODULE_PARM_DESC(viafb_refresh1
,
2225 "Set CRT refresh rate (default = 60)");
2227 module_param(viafb_lcd_panel_id
, int, 0);
2228 MODULE_PARM_DESC(viafb_lcd_panel_id
,
2229 "Set Flat Panel type(Default=1024x768)");
2231 module_param(viafb_lcd_dsp_method
, int, 0);
2232 MODULE_PARM_DESC(viafb_lcd_dsp_method
,
2233 "Set Flat Panel display scaling method.(Default=Expandsion)");
2235 module_param(viafb_SAMM_ON
, int, 0);
2236 MODULE_PARM_DESC(viafb_SAMM_ON
,
2237 "Turn on/off flag of SAMM(Default=OFF)");
2239 module_param(viafb_accel
, int, 0);
2240 MODULE_PARM_DESC(viafb_accel
,
2241 "Set 2D Hardware Acceleration.(Default = OFF)");
2243 module_param(viafb_active_dev
, charp
, 0);
2244 MODULE_PARM_DESC(viafb_active_dev
, "Specify active devices.");
2246 module_param(viafb_display_hardware_layout
, int, 0);
2247 MODULE_PARM_DESC(viafb_display_hardware_layout
,
2248 "Display Hardware Layout (LCD Only, DVI Only...,etc)");
2250 module_param(viafb_second_size
, int, 0);
2251 MODULE_PARM_DESC(viafb_second_size
,
2252 "Set secondary device memory size");
2254 module_param(viafb_dual_fb
, int, 0);
2255 MODULE_PARM_DESC(viafb_dual_fb
,
2256 "Turn on/off flag of dual framebuffer devices.(Default = OFF)");
2258 module_param(viafb_platform_epia_dvi
, int, 0);
2259 MODULE_PARM_DESC(viafb_platform_epia_dvi
,
2260 "Turn on/off flag of DVI devices on EPIA board.(Default = OFF)");
2262 module_param(viafb_device_lcd_dualedge
, int, 0);
2263 MODULE_PARM_DESC(viafb_device_lcd_dualedge
,
2264 "Turn on/off flag of dual edge panel.(Default = OFF)");
2266 module_param(viafb_bus_width
, int, 0);
2267 MODULE_PARM_DESC(viafb_bus_width
,
2268 "Set bus width of panel.(Default = 12)");
2270 module_param(viafb_lcd_mode
, int, 0);
2271 MODULE_PARM_DESC(viafb_lcd_mode
,
2272 "Set Flat Panel mode(Default=OPENLDI)");
2274 module_param(viafb_lcd_port
, charp
, 0);
2275 MODULE_PARM_DESC(viafb_lcd_port
, "Specify LCD output port.");
2277 module_param(viafb_dvi_port
, charp
, 0);
2278 MODULE_PARM_DESC(viafb_dvi_port
, "Specify DVI output port.");
2280 MODULE_LICENSE("GPL");