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>
27 static int MAX_CURS
= 32;
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 specifying video on devices.*/
40 char *viafb_video_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
51 static void retrieve_device_setting(struct viafb_ioctl_setting
53 static void viafb_set_video_device(u32 video_dev_info
);
54 static void viafb_get_video_device(u32
*video_dev_info
);
56 static struct fb_ops viafb_ops
;
59 static void viafb_update_fix(struct fb_info
*info
)
61 u32 bpp
= info
->var
.bits_per_pixel
;
64 bpp
== 8 ? FB_VISUAL_PSEUDOCOLOR
: FB_VISUAL_TRUECOLOR
;
65 info
->fix
.line_length
=
66 ((info
->var
.xres_virtual
+ 7) & ~7) * bpp
/ 8;
69 static void viafb_setup_fixinfo(struct fb_fix_screeninfo
*fix
,
70 struct viafb_par
*viaparinfo
)
72 memset(fix
, 0, sizeof(struct fb_fix_screeninfo
));
73 strcpy(fix
->id
, viafb_name
);
75 fix
->smem_start
= viaparinfo
->fbmem
;
76 fix
->smem_len
= viaparinfo
->fbmem_free
;
77 fix
->mmio_start
= viaparinfo
->mmio_base
;
78 fix
->mmio_len
= viaparinfo
->mmio_len
;
80 fix
->type
= FB_TYPE_PACKED_PIXELS
;
83 fix
->xpanstep
= fix
->ywrapstep
= 0;
86 /* Just tell the accel name */
87 viafbinfo
->fix
.accel
= FB_ACCEL_VIA_UNICHROME
;
89 static int viafb_open(struct fb_info
*info
, int user
)
91 DEBUG_MSG(KERN_INFO
"viafb_open!\n");
95 static int viafb_release(struct fb_info
*info
, int user
)
97 DEBUG_MSG(KERN_INFO
"viafb_release!\n");
101 static int viafb_check_var(struct fb_var_screeninfo
*var
,
102 struct fb_info
*info
)
104 int vmode_index
, htotal
, vtotal
;
105 struct viafb_par
*ppar
;
107 struct viafb_par
*p_viafb_par
;
111 DEBUG_MSG(KERN_INFO
"viafb_check_var!\n");
113 /* HW neither support interlacte nor double-scaned mode */
114 if (var
->vmode
& FB_VMODE_INTERLACED
|| var
->vmode
& FB_VMODE_DOUBLE
)
117 vmode_index
= viafb_get_mode_index(var
->xres
, var
->yres
);
118 if (vmode_index
== VIA_RES_INVALID
) {
120 "viafb: Mode %dx%dx%d not supported!!\n",
121 var
->xres
, var
->yres
, var
->bits_per_pixel
);
125 if (24 == var
->bits_per_pixel
)
126 var
->bits_per_pixel
= 32;
128 if (var
->bits_per_pixel
!= 8 && var
->bits_per_pixel
!= 16 &&
129 var
->bits_per_pixel
!= 32)
132 if ((var
->xres_virtual
* (var
->bits_per_pixel
>> 3)) & 0x1F)
133 /*32 pixel alignment */
134 var
->xres_virtual
= (var
->xres_virtual
+ 31) & ~31;
135 if (var
->xres_virtual
* var
->yres_virtual
* var
->bits_per_pixel
/ 8 >
139 /* Based on var passed in to calculate the refresh,
140 * because our driver use some modes special.
142 htotal
= var
->xres
+ var
->left_margin
+
143 var
->right_margin
+ var
->hsync_len
;
144 vtotal
= var
->yres
+ var
->upper_margin
+
145 var
->lower_margin
+ var
->vsync_len
;
146 long_refresh
= 1000000000UL / var
->pixclock
* 1000;
147 long_refresh
/= (htotal
* vtotal
);
149 viafb_refresh
= viafb_get_refresh(var
->xres
, var
->yres
, long_refresh
);
151 /* Adjust var according to our driver's own table */
152 viafb_fill_var_timing_info(var
, viafb_refresh
, vmode_index
);
154 /* This is indeed a patch for VT3353 */
157 p_viafb_par
= (struct viafb_par
*)info
->par
;
158 if (p_viafb_par
->chip_info
->gfx_chip_name
== UNICHROME_VX800
)
159 var
->accel_flags
= 0;
164 static int viafb_set_par(struct fb_info
*info
)
167 int vmode_index1
= 0;
168 DEBUG_MSG(KERN_INFO
"viafb_set_par!\n");
170 viafb_update_device_setting(info
->var
.xres
, info
->var
.yres
,
171 info
->var
.bits_per_pixel
, viafb_refresh
, 0);
173 vmode_index
= viafb_get_mode_index(info
->var
.xres
, info
->var
.yres
);
175 if (viafb_SAMM_ON
== 1) {
177 "viafb_second_xres = %d, viafb_second_yres = %d, bpp = %d\n",
178 viafb_second_xres
, viafb_second_yres
, viafb_bpp1
);
179 vmode_index1
= viafb_get_mode_index(viafb_second_xres
,
181 DEBUG_MSG(KERN_INFO
"->viafb_SAMM_ON: index=%d\n",
184 viafb_update_device_setting(viafb_second_xres
,
185 viafb_second_yres
, viafb_bpp1
, viafb_refresh1
, 1);
188 if (vmode_index
!= VIA_RES_INVALID
) {
189 viafb_setmode(vmode_index
, info
->var
.xres
, info
->var
.yres
,
190 info
->var
.bits_per_pixel
, vmode_index1
,
191 viafb_second_xres
, viafb_second_yres
, viafb_bpp1
);
193 /*We should set memory offset according virtual_x */
194 /*Fix me:put this function into viafb_setmode */
195 viafb_memory_pitch_patch(info
);
196 viafb_update_fix(info
);
197 viafb_bpp
= info
->var
.bits_per_pixel
;
198 /* Update viafb_accel, it is necessary to our 2D accelerate */
199 viafb_accel
= info
->var
.accel_flags
;
202 viafb_set_2d_color_depth(info
->var
.bits_per_pixel
);
208 /* Set one color register */
209 static int viafb_setcolreg(unsigned regno
, unsigned red
, unsigned green
,
210 unsigned blue
, unsigned transp
, struct fb_info
*info
)
212 u8 sr1a
, sr1b
, cr67
, cr6a
, rev
= 0, shift
= 10;
213 unsigned cmap_entries
= (info
->var
.bits_per_pixel
== 8) ? 256 : 16;
214 DEBUG_MSG(KERN_INFO
"viafb_setcolreg!\n");
215 if (regno
>= cmap_entries
)
217 if (UNICHROME_CLE266
== viaparinfo
->chip_info
->gfx_chip_name
) {
219 * Read PCI bus 0,dev 0,function 0,index 0xF6 to get chip rev.
221 outl(0x80000000 | (0xf6 & ~3), (unsigned long)0xCF8);
222 rev
= (inl((unsigned long)0xCFC) >> ((0xf6 & 3) * 8)) & 0xff;
224 switch (info
->var
.bits_per_pixel
) {
235 /* Map the 3C6/7/8/9 to the IGA2 */
237 outb(sr1a
| 0x01, 0x3C5);
238 /* Second Display Engine colck always on */
240 outb(sr1b
| 0x80, 0x3C5);
241 /* Second Display Color Depth 8 */
243 outb(cr67
& 0x3F, 0x3D5);
245 /* Second Display Channel Reset CR6A[6]) */
246 outb(cr6a
& 0xBF, 0x3D5);
247 /* Second Display Channel Enable CR6A[7] */
248 outb(cr6a
| 0x80, 0x3D5);
249 /* Second Display Channel stop reset) */
250 outb(cr6a
| 0x40, 0x3D5);
252 /* Bit mask of palette */
254 /* Write one register of IGA2 */
256 if (UNICHROME_CLE266
== viaparinfo
->chip_info
->gfx_chip_name
&&
259 viafb_write_reg_mask(CR6A
, VIACR
, BIT5
, BIT5
);
260 viafb_write_reg_mask(SR15
, VIASR
, BIT7
, BIT7
);
263 viafb_write_reg_mask(CR6A
, VIACR
, 0, BIT5
);
264 viafb_write_reg_mask(SR15
, VIASR
, 0, BIT7
);
266 outb(red
>> shift
, 0x3C9);
267 outb(green
>> shift
, 0x3C9);
268 outb(blue
>> shift
, 0x3C9);
270 /* Map the 3C6/7/8/9 to the IGA1 */
272 outb(sr1a
& 0xFE, 0x3C5);
273 /* Bit mask of palette */
275 /* Write one register of IGA1 */
277 outb(red
>> shift
, 0x3C9);
278 outb(green
>> shift
, 0x3C9);
279 outb(blue
>> shift
, 0x3C9);
291 ((u32
*) info
->pseudo_palette
)[regno
] = (red
& 0xF800) |
292 ((green
& 0xFC00) >> 5) | ((blue
& 0xF800) >> 11);
295 ((u32
*) info
->pseudo_palette
)[regno
] =
296 ((transp
& 0xFF00) << 16) |
297 ((red
& 0xFF00) << 8) |
298 ((green
& 0xFF00)) | ((blue
& 0xFF00) >> 8);
306 /*CALLED BY: fb_set_cmap */
307 /* fb_set_var, pass 256 colors */
308 /*CALLED BY: fb_set_cmap */
309 /* fbcon_set_palette, pass 16 colors */
310 static int viafb_setcmap(struct fb_cmap
*cmap
, struct fb_info
*info
)
314 u16
*pred
= cmap
->red
;
315 u16
*pgreen
= cmap
->green
;
316 u16
*pblue
= cmap
->blue
;
317 u16
*ptransp
= cmap
->transp
;
318 u8 sr1a
, sr1b
, cr67
, cr6a
, rev
= 0, shift
= 10;
321 if (UNICHROME_CLE266
== viaparinfo
->chip_info
->gfx_chip_name
) {
323 * Read PCI bus 0, dev 0, function 0, index 0xF6 to get chip
326 outl(0x80000000 | (0xf6 & ~3), (unsigned long)0xCF8);
327 rev
= (inl((unsigned long)0xCFC) >> ((0xf6 & 3) * 8)) & 0xff;
329 switch (info
->var
.bits_per_pixel
) {
339 /* Map the 3C6/7/8/9 to the IGA2 */
341 outb(sr1a
| 0x01, 0x3C5);
343 /* Second Display Engine colck always on */
344 outb(sr1b
| 0x80, 0x3C5);
346 /* Second Display Color Depth 8 */
347 outb(cr67
& 0x3F, 0x3D5);
349 /* Second Display Channel Reset CR6A[6]) */
350 outb(cr6a
& 0xBF, 0x3D5);
351 /* Second Display Channel Enable CR6A[7] */
352 outb(cr6a
| 0x80, 0x3D5);
353 /* Second Display Channel stop reset) */
354 outb(cr6a
| 0xC0, 0x3D5);
356 /* Bit mask of palette */
359 if (UNICHROME_CLE266
== viaparinfo
->chip_info
->gfx_chip_name
&&
362 viafb_write_reg_mask(CR6A
, VIACR
, BIT5
, BIT5
);
363 viafb_write_reg_mask(SR15
, VIASR
, BIT7
, BIT7
);
366 viafb_write_reg_mask(CR6A
, VIACR
, 0, BIT5
);
367 viafb_write_reg_mask(SR15
, VIASR
, 0, BIT7
);
369 for (i
= 0; i
< len
; i
++) {
370 outb((*(pred
+ i
)) >> shift
, 0x3C9);
371 outb((*(pgreen
+ i
)) >> shift
, 0x3C9);
372 outb((*(pblue
+ i
)) >> shift
, 0x3C9);
376 /* Map the 3C6/7/8/9 to the IGA1 */
377 outb(sr1a
& 0xFE, 0x3C5);
378 /* Bit mask of palette */
381 for (i
= 0; i
< len
; i
++) {
382 outb((*(pred
+ i
)) >> shift
, 0x3C9);
383 outb((*(pgreen
+ i
)) >> shift
, 0x3C9);
384 outb((*(pblue
+ i
)) >> shift
, 0x3C9);
398 return 0; /* Because static u32 pseudo_pal[17]; */
399 for (i
= 0; i
< len
; i
++)
400 ((u32
*) info
->pseudo_palette
)[i
] =
401 (*(pred
+ i
) & 0xF800) |
402 ((*(pgreen
+ i
) & 0xFC00) >> 5) |
403 ((*(pblue
+ i
) & 0xF800) >> 11);
409 for (i
= 0; i
< len
; i
++)
410 ((u32
*) info
->pseudo_palette
)[i
] =
411 ((*(ptransp
+ i
) & 0xFF00) << 16) |
412 ((*(pred
+ i
) & 0xFF00) << 8) |
413 ((*(pgreen
+ i
) & 0xFF00)) |
414 ((*(pblue
+ i
) & 0xFF00) >> 8);
416 for (i
= 0; i
< len
; i
++)
417 ((u32
*) info
->pseudo_palette
)[i
] =
419 ((*(pred
+ i
) & 0xFF00) << 8) |
420 ((*(pgreen
+ i
) & 0xFF00)) |
421 ((*(pblue
+ i
) & 0xFF00) >> 8);
428 static int viafb_pan_display(struct fb_var_screeninfo
*var
,
429 struct fb_info
*info
)
433 DEBUG_MSG(KERN_INFO
"viafb_pan_display!\n");
435 offset
= (var
->xoffset
+ (var
->yoffset
* var
->xres_virtual
)) *
436 var
->bits_per_pixel
/ 16;
438 DEBUG_MSG(KERN_INFO
"\nviafb_pan_display,offset =%d ", offset
);
439 viafb_set_primary_address(offset
);
443 static int viafb_blank(int blank_mode
, struct fb_info
*info
)
445 DEBUG_MSG(KERN_INFO
"viafb_blank!\n");
446 /* clear DPMS setting */
448 switch (blank_mode
) {
449 case FB_BLANK_UNBLANK
:
450 /* Screen: On, HSync: On, VSync: On */
451 /* control CRT monitor power management */
452 viafb_write_reg_mask(CR36
, VIACR
, 0x00, BIT4
+ BIT5
);
454 case FB_BLANK_HSYNC_SUSPEND
:
455 /* Screen: Off, HSync: Off, VSync: On */
456 /* control CRT monitor power management */
457 viafb_write_reg_mask(CR36
, VIACR
, 0x10, BIT4
+ BIT5
);
459 case FB_BLANK_VSYNC_SUSPEND
:
460 /* Screen: Off, HSync: On, VSync: Off */
461 /* control CRT monitor power management */
462 viafb_write_reg_mask(CR36
, VIACR
, 0x20, BIT4
+ BIT5
);
464 case FB_BLANK_POWERDOWN
:
465 /* Screen: Off, HSync: Off, VSync: Off */
466 /* control CRT monitor power management */
467 viafb_write_reg_mask(CR36
, VIACR
, 0x30, BIT4
+ BIT5
);
474 static int viafb_ioctl(struct fb_info
*info
, u_int cmd
, u_long arg
)
477 struct viafb_ioctl_mode viamode
;
478 struct viafb_ioctl_samm viasamm
;
479 struct viafb_driver_version driver_version
;
480 struct fb_var_screeninfo sec_var
;
481 struct _panel_size_pos_info panel_pos_size_para
;
482 struct viafb_ioctl_setting viafb_setting
;
483 struct device_t active_dev
;
486 u32
*viafb_gamma_table
;
487 char driver_name
[] = "viafb";
489 u32 __user
*argp
= (u32 __user
*) arg
;
491 u32 video_dev_info
= 0;
493 DEBUG_MSG(KERN_INFO
"viafb_ioctl: 0x%X !!\n", cmd
);
494 memset(&u
, 0, sizeof(u
));
497 case VIAFB_GET_CHIP_INFO
:
498 if (copy_to_user(argp
, viaparinfo
->chip_info
,
499 sizeof(struct chip_information
)))
502 case VIAFB_GET_INFO_SIZE
:
503 return put_user((u32
)sizeof(struct viafb_ioctl_info
), argp
);
505 return viafb_ioctl_get_viafb_info(arg
);
507 return put_user(viafb_ioctl_hotplug(info
->var
.xres
,
509 info
->var
.bits_per_pixel
), argp
);
510 case VIAFB_SET_HOTPLUG_FLAG
:
511 if (copy_from_user(&gpu32
, argp
, sizeof(gpu32
)))
513 viafb_hotplug
= (gpu32
) ? 1 : 0;
515 case VIAFB_GET_RESOLUTION
:
516 u
.viamode
.xres
= (u32
) viafb_hotplug_Xres
;
517 u
.viamode
.yres
= (u32
) viafb_hotplug_Yres
;
518 u
.viamode
.refresh
= (u32
) viafb_hotplug_refresh
;
519 u
.viamode
.bpp
= (u32
) viafb_hotplug_bpp
;
520 if (viafb_SAMM_ON
== 1) {
521 u
.viamode
.xres_sec
= viafb_second_xres
;
522 u
.viamode
.yres_sec
= viafb_second_yres
;
523 u
.viamode
.virtual_xres_sec
= viafb_second_virtual_xres
;
524 u
.viamode
.virtual_yres_sec
= viafb_second_virtual_yres
;
525 u
.viamode
.refresh_sec
= viafb_refresh1
;
526 u
.viamode
.bpp_sec
= viafb_bpp1
;
528 u
.viamode
.xres_sec
= 0;
529 u
.viamode
.yres_sec
= 0;
530 u
.viamode
.virtual_xres_sec
= 0;
531 u
.viamode
.virtual_yres_sec
= 0;
532 u
.viamode
.refresh_sec
= 0;
533 u
.viamode
.bpp_sec
= 0;
535 if (copy_to_user(argp
, &u
.viamode
, sizeof(u
.viamode
)))
538 case VIAFB_GET_SAMM_INFO
:
539 u
.viasamm
.samm_status
= viafb_SAMM_ON
;
541 if (viafb_SAMM_ON
== 1) {
543 u
.viasamm
.size_prim
= viaparinfo
->fbmem_free
;
544 u
.viasamm
.size_sec
= viaparinfo1
->fbmem_free
;
546 if (viafb_second_size
) {
547 u
.viasamm
.size_prim
=
548 viaparinfo
->fbmem_free
-
549 viafb_second_size
* 1024 * 1024;
551 viafb_second_size
* 1024 * 1024;
553 u
.viasamm
.size_prim
=
554 viaparinfo
->fbmem_free
>> 1;
556 (viaparinfo
->fbmem_free
>> 1);
559 u
.viasamm
.mem_base
= viaparinfo
->fbmem
;
560 u
.viasamm
.offset_sec
= viafb_second_offset
;
562 u
.viasamm
.size_prim
=
563 viaparinfo
->memsize
- viaparinfo
->fbmem_used
;
564 u
.viasamm
.size_sec
= 0;
565 u
.viasamm
.mem_base
= viaparinfo
->fbmem
;
566 u
.viasamm
.offset_sec
= 0;
569 if (copy_to_user(argp
, &u
.viasamm
, sizeof(u
.viasamm
)))
573 case VIAFB_TURN_ON_OUTPUT_DEVICE
:
574 if (copy_from_user(&gpu32
, argp
, sizeof(gpu32
)))
576 if (gpu32
& CRT_Device
)
578 if (gpu32
& DVI_Device
)
580 if (gpu32
& LCD_Device
)
583 case VIAFB_TURN_OFF_OUTPUT_DEVICE
:
584 if (copy_from_user(&gpu32
, argp
, sizeof(gpu32
)))
586 if (gpu32
& CRT_Device
)
588 if (gpu32
& DVI_Device
)
590 if (gpu32
& LCD_Device
)
593 case VIAFB_SET_DEVICE
:
594 if (copy_from_user(&u
.active_dev
, (void *)argp
,
595 sizeof(u
.active_dev
)))
597 viafb_set_device(u
.active_dev
);
600 case VIAFB_GET_DEVICE
:
601 u
.active_dev
.crt
= viafb_CRT_ON
;
602 u
.active_dev
.dvi
= viafb_DVI_ON
;
603 u
.active_dev
.lcd
= viafb_LCD_ON
;
604 u
.active_dev
.samm
= viafb_SAMM_ON
;
605 u
.active_dev
.primary_dev
= viafb_primary_dev
;
607 u
.active_dev
.lcd_dsp_cent
= viafb_lcd_dsp_method
;
608 u
.active_dev
.lcd_panel_id
= viafb_lcd_panel_id
;
609 u
.active_dev
.lcd_mode
= viafb_lcd_mode
;
611 u
.active_dev
.xres
= viafb_hotplug_Xres
;
612 u
.active_dev
.yres
= viafb_hotplug_Yres
;
614 u
.active_dev
.xres1
= viafb_second_xres
;
615 u
.active_dev
.yres1
= viafb_second_yres
;
617 u
.active_dev
.bpp
= viafb_bpp
;
618 u
.active_dev
.bpp1
= viafb_bpp1
;
619 u
.active_dev
.refresh
= viafb_refresh
;
620 u
.active_dev
.refresh1
= viafb_refresh1
;
622 u
.active_dev
.epia_dvi
= viafb_platform_epia_dvi
;
623 u
.active_dev
.lcd_dual_edge
= viafb_device_lcd_dualedge
;
624 u
.active_dev
.bus_width
= viafb_bus_width
;
626 if (copy_to_user(argp
, &u
.active_dev
, sizeof(u
.active_dev
)))
630 case VIAFB_GET_DRIVER_VERSION
:
631 u
.driver_version
.iMajorNum
= VERSION_MAJOR
;
632 u
.driver_version
.iKernelNum
= VERSION_KERNEL
;
633 u
.driver_version
.iOSNum
= VERSION_OS
;
634 u
.driver_version
.iMinorNum
= VERSION_MINOR
;
636 if (copy_to_user(argp
, &u
.driver_version
,
637 sizeof(u
.driver_version
)))
642 case VIAFB_SET_DEVICE_INFO
:
643 if (copy_from_user(&u
.viafb_setting
,
644 argp
, sizeof(u
.viafb_setting
)))
646 if (apply_device_setting(u
.viafb_setting
, info
) < 0)
651 case VIAFB_SET_SECOND_MODE
:
652 if (copy_from_user(&u
.sec_var
, argp
, sizeof(u
.sec_var
)))
654 apply_second_mode_setting(&u
.sec_var
);
657 case VIAFB_GET_DEVICE_INFO
:
659 retrieve_device_setting(&u
.viafb_setting
);
661 if (copy_to_user(argp
, &u
.viafb_setting
,
662 sizeof(u
.viafb_setting
)))
667 case VIAFB_GET_DEVICE_SUPPORT
:
668 viafb_get_device_support_state(&state_info
);
669 if (put_user(state_info
, argp
))
673 case VIAFB_GET_DEVICE_CONNECT
:
674 viafb_get_device_connect_state(&state_info
);
675 if (put_user(state_info
, argp
))
679 case VIAFB_GET_PANEL_SUPPORT_EXPAND
:
681 viafb_lcd_get_support_expand_state(info
->var
.xres
,
683 if (put_user(state_info
, argp
))
687 case VIAFB_GET_DRIVER_NAME
:
688 if (copy_to_user(argp
, driver_name
, sizeof(driver_name
)))
692 case VIAFB_SET_GAMMA_LUT
:
693 viafb_gamma_table
= kmalloc(256 * sizeof(u32
), GFP_KERNEL
);
694 if (!viafb_gamma_table
)
696 if (copy_from_user(viafb_gamma_table
, argp
,
697 sizeof(viafb_gamma_table
))) {
698 kfree(viafb_gamma_table
);
701 viafb_set_gamma_table(viafb_bpp
, viafb_gamma_table
);
702 kfree(viafb_gamma_table
);
705 case VIAFB_GET_GAMMA_LUT
:
706 viafb_gamma_table
= kmalloc(256 * sizeof(u32
), GFP_KERNEL
);
707 if (!viafb_gamma_table
)
709 viafb_get_gamma_table(viafb_gamma_table
);
710 if (copy_to_user(argp
, viafb_gamma_table
,
711 sizeof(viafb_gamma_table
))) {
712 kfree(viafb_gamma_table
);
715 kfree(viafb_gamma_table
);
718 case VIAFB_GET_GAMMA_SUPPORT_STATE
:
719 viafb_get_gamma_support_state(viafb_bpp
, &state_info
);
720 if (put_user(state_info
, argp
))
723 case VIAFB_SET_VIDEO_DEVICE
:
724 get_user(video_dev_info
, argp
);
725 viafb_set_video_device(video_dev_info
);
727 case VIAFB_GET_VIDEO_DEVICE
:
728 viafb_get_video_device(&video_dev_info
);
729 if (put_user(video_dev_info
, argp
))
732 case VIAFB_SYNC_SURFACE
:
733 DEBUG_MSG(KERN_INFO
"lobo VIAFB_SYNC_SURFACE\n");
735 case VIAFB_GET_DRIVER_CAPS
:
738 case VIAFB_GET_PANEL_MAX_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
)))
747 case VIAFB_GET_PANEL_MAX_POSITION
:
748 if (copy_from_user(&u
.panel_pos_size_para
, argp
,
749 sizeof(u
.panel_pos_size_para
)))
751 u
.panel_pos_size_para
.x
= u
.panel_pos_size_para
.y
= 0;
752 if (copy_to_user(argp
, &u
.panel_pos_size_para
,
753 sizeof(u
.panel_pos_size_para
)))
757 case VIAFB_GET_PANEL_POSITION
:
758 if (copy_from_user(&u
.panel_pos_size_para
, argp
,
759 sizeof(u
.panel_pos_size_para
)))
761 u
.panel_pos_size_para
.x
= u
.panel_pos_size_para
.y
= 0;
762 if (copy_to_user(argp
, &u
.panel_pos_size_para
,
763 sizeof(u
.panel_pos_size_para
)))
766 case VIAFB_GET_PANEL_SIZE
:
767 if (copy_from_user(&u
.panel_pos_size_para
, argp
,
768 sizeof(u
.panel_pos_size_para
)))
770 u
.panel_pos_size_para
.x
= u
.panel_pos_size_para
.y
= 0;
771 if (copy_to_user(argp
, &u
.panel_pos_size_para
,
772 sizeof(u
.panel_pos_size_para
)))
776 case VIAFB_SET_PANEL_POSITION
:
777 if (copy_from_user(&u
.panel_pos_size_para
, argp
,
778 sizeof(u
.panel_pos_size_para
)))
781 case VIAFB_SET_PANEL_SIZE
:
782 if (copy_from_user(&u
.panel_pos_size_para
, argp
,
783 sizeof(u
.panel_pos_size_para
)))
794 static void viafb_fillrect(struct fb_info
*info
,
795 const struct fb_fillrect
*rect
)
797 u32 col
= 0, rop
= 0;
801 cfb_fillrect(info
, rect
);
805 if (!rect
->width
|| !rect
->height
)
818 switch (info
->var
.bits_per_pixel
) {
823 col
= ((u32
*) (info
->pseudo_palette
))[rect
->color
];
826 col
= ((u32
*) (info
->pseudo_palette
))[rect
->color
];
830 /* BitBlt Source Address */
831 writel(0x0, viaparinfo
->io_virt
+ VIA_REG_SRCPOS
);
832 /* Source Base Address */
833 writel(0x0, viaparinfo
->io_virt
+ VIA_REG_SRCBASE
);
834 /* Destination Base Address */
835 writel(((unsigned long) (info
->screen_base
) -
836 (unsigned long) viafb_FB_MM
) >> 3,
837 viaparinfo
->io_virt
+ VIA_REG_DSTBASE
);
839 pitch
= (info
->var
.xres_virtual
+ 7) & ~7;
840 writel(VIA_PITCH_ENABLE
|
842 info
->var
.bits_per_pixel
>> 3) >> 3) |
844 var
.bits_per_pixel
>> 3) >> 3) << 16)),
845 viaparinfo
->io_virt
+ VIA_REG_PITCH
);
846 /* BitBlt Destination Address */
847 writel(((rect
->dy
<< 16) | rect
->dx
),
848 viaparinfo
->io_virt
+ VIA_REG_DSTPOS
);
849 /* Dimension: width & height */
850 writel((((rect
->height
- 1) << 16) | (rect
->width
- 1)),
851 viaparinfo
->io_virt
+ VIA_REG_DIMENSION
);
852 /* Forground color or Destination color */
853 writel(col
, viaparinfo
->io_virt
+ VIA_REG_FGCOLOR
);
855 writel((0x01 | 0x2000 | (rop
<< 24)),
856 viaparinfo
->io_virt
+ VIA_REG_GECMD
);
860 static void viafb_copyarea(struct fb_info
*info
,
861 const struct fb_copyarea
*area
)
863 u32 dy
= area
->dy
, sy
= area
->sy
, direction
= 0x0;
864 u32 sx
= area
->sx
, dx
= area
->dx
, width
= area
->width
;
867 DEBUG_MSG(KERN_INFO
"viafb_copyarea!!\n");
870 cfb_copyarea(info
, area
);
874 if (!area
->width
|| !area
->height
)
878 dy
+= area
->height
- 1;
879 sy
+= area
->height
- 1;
889 /* Source Base Address */
890 writel(((unsigned long) (info
->screen_base
) -
891 (unsigned long) viafb_FB_MM
) >> 3,
892 viaparinfo
->io_virt
+ VIA_REG_SRCBASE
);
893 /* Destination Base Address */
894 writel(((unsigned long) (info
->screen_base
) -
895 (unsigned long) viafb_FB_MM
) >> 3,
896 viaparinfo
->io_virt
+ VIA_REG_DSTBASE
);
898 pitch
= (info
->var
.xres_virtual
+ 7) & ~7;
899 /* VIA_PITCH_ENABLE can be omitted now. */
900 writel(VIA_PITCH_ENABLE
|
902 info
->var
.bits_per_pixel
>> 3) >> 3) | (((pitch
*
907 viaparinfo
->io_virt
+ VIA_REG_PITCH
);
908 /* BitBlt Source Address */
909 writel(((sy
<< 16) | sx
), viaparinfo
->io_virt
+ VIA_REG_SRCPOS
);
910 /* BitBlt Destination Address */
911 writel(((dy
<< 16) | dx
), viaparinfo
->io_virt
+ VIA_REG_DSTPOS
);
912 /* Dimension: width & height */
913 writel((((area
->height
- 1) << 16) | (area
->width
- 1)),
914 viaparinfo
->io_virt
+ VIA_REG_DIMENSION
);
916 writel((0x01 | direction
| (0xCC << 24)),
917 viaparinfo
->io_virt
+ VIA_REG_GECMD
);
921 static void viafb_imageblit(struct fb_info
*info
,
922 const struct fb_image
*image
)
924 u32 size
, bg_col
= 0, fg_col
= 0, *udata
;
929 cfb_imageblit(info
, image
);
933 udata
= (u32
*) image
->data
;
935 switch (info
->var
.bits_per_pixel
) {
937 bg_col
= image
->bg_color
;
938 fg_col
= image
->fg_color
;
941 bg_col
= ((u32
*) (info
->pseudo_palette
))[image
->bg_color
];
942 fg_col
= ((u32
*) (info
->pseudo_palette
))[image
->fg_color
];
945 bg_col
= ((u32
*) (info
->pseudo_palette
))[image
->bg_color
];
946 fg_col
= ((u32
*) (info
->pseudo_palette
))[image
->fg_color
];
949 size
= image
->width
* image
->height
;
951 /* Source Base Address */
952 writel(0x0, viaparinfo
->io_virt
+ VIA_REG_SRCBASE
);
953 /* Destination Base Address */
954 writel(((unsigned long) (info
->screen_base
) -
955 (unsigned long) viafb_FB_MM
) >> 3,
956 viaparinfo
->io_virt
+ VIA_REG_DSTBASE
);
958 pitch
= (info
->var
.xres_virtual
+ 7) & ~7;
959 writel(VIA_PITCH_ENABLE
|
961 info
->var
.bits_per_pixel
>> 3) >> 3) | (((pitch
*
966 viaparinfo
->io_virt
+ VIA_REG_PITCH
);
967 /* BitBlt Source Address */
968 writel(0x0, viaparinfo
->io_virt
+ VIA_REG_SRCPOS
);
969 /* BitBlt Destination Address */
970 writel(((image
->dy
<< 16) | image
->dx
),
971 viaparinfo
->io_virt
+ VIA_REG_DSTPOS
);
972 /* Dimension: width & height */
973 writel((((image
->height
- 1) << 16) | (image
->width
- 1)),
974 viaparinfo
->io_virt
+ VIA_REG_DIMENSION
);
976 writel(fg_col
, viaparinfo
->io_virt
+ VIA_REG_FGCOLOR
);
978 writel(bg_col
, viaparinfo
->io_virt
+ VIA_REG_BGCOLOR
);
980 writel(0xCC020142, viaparinfo
->io_virt
+ VIA_REG_GECMD
);
982 for (i
= 0; i
< size
/ 4; i
++) {
983 writel(*udata
, viaparinfo
->io_virt
+ VIA_MMIO_BLTBASE
);
989 static int viafb_cursor(struct fb_info
*info
, struct fb_cursor
*cursor
)
991 u32 temp
, xx
, yy
, bg_col
= 0, fg_col
= 0;
993 static int hw_cursor
;
994 struct viafb_par
*p_viafb_par
;
1001 viafb_show_hw_cursor(info
, HW_Cursor_OFF
);
1007 if ((((struct viafb_par
*)(info
->par
))->iga_path
== IGA2
)
1008 && (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_CLE266
))
1011 /* When duoview and using lcd , use soft cursor */
1012 if (viafb_LCD_ON
|| (!viafb_SAMM_ON
&&
1013 viafb_LCD2_ON
+ viafb_DVI_ON
+ viafb_CRT_ON
== 2))
1016 viafb_show_hw_cursor(info
, HW_Cursor_OFF
);
1017 viacursor
= *cursor
;
1019 if (cursor
->set
& FB_CUR_SETHOT
) {
1020 viacursor
.hot
= cursor
->hot
;
1021 temp
= ((viacursor
.hot
.x
) << 16) + viacursor
.hot
.y
;
1022 writel(temp
, viaparinfo
->io_virt
+ VIA_REG_CURSOR_ORG
);
1025 if (cursor
->set
& FB_CUR_SETPOS
) {
1026 viacursor
.image
.dx
= cursor
->image
.dx
;
1027 viacursor
.image
.dy
= cursor
->image
.dy
;
1028 yy
= cursor
->image
.dy
- info
->var
.yoffset
;
1029 xx
= cursor
->image
.dx
- info
->var
.xoffset
;
1032 writel(temp
, viaparinfo
->io_virt
+ VIA_REG_CURSOR_POS
);
1035 if (cursor
->set
& FB_CUR_SETSIZE
) {
1036 temp
= readl(viaparinfo
->io_virt
+ VIA_REG_CURSOR_MODE
);
1038 if ((cursor
->image
.width
<= 32)
1039 && (cursor
->image
.height
<= 32)) {
1042 } else if ((cursor
->image
.width
<= 64)
1043 && (cursor
->image
.height
<= 64)) {
1048 "The cursor image is biger than 64x64 bits...\n");
1051 writel(temp
, viaparinfo
->io_virt
+ VIA_REG_CURSOR_MODE
);
1053 viacursor
.image
.height
= cursor
->image
.height
;
1054 viacursor
.image
.width
= cursor
->image
.width
;
1057 if (cursor
->set
& FB_CUR_SETCMAP
) {
1058 viacursor
.image
.fg_color
= cursor
->image
.fg_color
;
1059 viacursor
.image
.bg_color
= cursor
->image
.bg_color
;
1061 switch (info
->var
.bits_per_pixel
) {
1067 (((info
->cmap
.red
)[viacursor
.image
.bg_color
] &
1069 ((info
->cmap
.green
)[viacursor
.image
.bg_color
] &
1071 (((info
->cmap
.blue
)[viacursor
.image
.bg_color
] &
1075 (((info
->cmap
.red
)[viacursor
.image
.fg_color
] &
1077 ((info
->cmap
.green
)[viacursor
.image
.fg_color
] &
1079 (((info
->cmap
.blue
)[viacursor
.image
.fg_color
] &
1086 /* This is indeed a patch for VT3324/VT3353 */
1089 p_viafb_par
= (struct viafb_par
*)info
->par
;
1091 if ((p_viafb_par
->chip_info
->gfx_chip_name
==
1093 ((p_viafb_par
->chip_info
->gfx_chip_name
==
1094 UNICHROME_VX800
))) {
1096 (((info
->cmap
.red
)[viacursor
.image
.bg_color
] &
1098 (((info
->cmap
.green
)[viacursor
.image
.bg_color
] &
1100 (((info
->cmap
.blue
)[viacursor
.image
.bg_color
] &
1103 (((info
->cmap
.red
)[viacursor
.image
.fg_color
] &
1105 (((info
->cmap
.green
)[viacursor
.image
.fg_color
] &
1107 (((info
->cmap
.blue
)[viacursor
.image
.fg_color
] &
1111 writel(bg_col
, viaparinfo
->io_virt
+ VIA_REG_CURSOR_BG
);
1112 writel(fg_col
, viaparinfo
->io_virt
+ VIA_REG_CURSOR_FG
);
1115 if (cursor
->set
& FB_CUR_SETSHAPE
) {
1117 u8 data
[CURSOR_SIZE
/ 8];
1118 u32 bak
[CURSOR_SIZE
/ 32];
1119 } *cr_data
= kzalloc(sizeof(*cr_data
), GFP_ATOMIC
);
1121 ((viacursor
.image
.width
+ 7) >> 3) *
1122 viacursor
.image
.height
;
1124 if (cr_data
== NULL
)
1127 if (MAX_CURS
== 32) {
1128 for (i
= 0; i
< (CURSOR_SIZE
/ 32); i
++) {
1129 cr_data
->bak
[i
] = 0x0;
1130 cr_data
->bak
[i
+ 1] = 0xFFFFFFFF;
1133 } else if (MAX_CURS
== 64) {
1134 for (i
= 0; i
< (CURSOR_SIZE
/ 32); i
++) {
1135 cr_data
->bak
[i
] = 0x0;
1136 cr_data
->bak
[i
+ 1] = 0x0;
1137 cr_data
->bak
[i
+ 2] = 0xFFFFFFFF;
1138 cr_data
->bak
[i
+ 3] = 0xFFFFFFFF;
1143 switch (viacursor
.rop
) {
1145 for (i
= 0; i
< size
; i
++)
1146 cr_data
->data
[i
] = viacursor
.mask
[i
];
1150 for (i
= 0; i
< size
; i
++)
1151 cr_data
->data
[i
] = viacursor
.mask
[i
];
1157 if (MAX_CURS
== 32) {
1158 for (i
= 0; i
< size
; i
++) {
1159 cr_data
->bak
[j
] = (u32
) cr_data
->data
[i
];
1160 cr_data
->bak
[j
+ 1] = ~cr_data
->bak
[j
];
1163 } else if (MAX_CURS
== 64) {
1164 for (i
= 0; i
< size
; i
++) {
1165 cr_data
->bak
[j
] = (u32
) cr_data
->data
[i
];
1166 cr_data
->bak
[j
+ 1] = 0x0;
1167 cr_data
->bak
[j
+ 2] = ~cr_data
->bak
[j
];
1168 cr_data
->bak
[j
+ 3] = ~cr_data
->bak
[j
+ 1];
1173 memcpy(((struct viafb_par
*)(info
->par
))->fbmem_virt
+
1174 ((struct viafb_par
*)(info
->par
))->cursor_start
,
1175 cr_data
->bak
, CURSOR_SIZE
);
1180 if (viacursor
.enable
)
1181 viafb_show_hw_cursor(info
, HW_Cursor_ON
);
1186 static int viafb_sync(struct fb_info
*info
)
1189 viafb_wait_engine_idle();
1193 int viafb_get_mode_index(int hres
, int vres
)
1196 DEBUG_MSG(KERN_INFO
"viafb_get_mode_index!\n");
1198 for (i
= 0; i
< NUM_TOTAL_MODETABLE
; i
++)
1199 if (CLE266Modes
[i
].mode_array
&&
1200 CLE266Modes
[i
].crtc
[0].crtc
.hor_addr
== hres
&&
1201 CLE266Modes
[i
].crtc
[0].crtc
.ver_addr
== vres
)
1204 if (i
== NUM_TOTAL_MODETABLE
)
1205 return VIA_RES_INVALID
;
1207 return CLE266Modes
[i
].ModeIndex
;
1210 static void check_available_device_to_enable(int device_id
)
1215 viafb_CRT_ON
= STATE_OFF
;
1216 viafb_DVI_ON
= STATE_OFF
;
1217 viafb_LCD_ON
= STATE_OFF
;
1218 viafb_LCD2_ON
= STATE_OFF
;
1219 viafb_DeviceStatus
= None_Device
;
1221 if ((device_id
& CRT_Device
) && (device_num
< MAX_ACTIVE_DEV_NUM
)) {
1222 viafb_CRT_ON
= STATE_ON
;
1224 viafb_DeviceStatus
|= CRT_Device
;
1227 if ((device_id
& DVI_Device
) && (device_num
< MAX_ACTIVE_DEV_NUM
)) {
1228 viafb_DVI_ON
= STATE_ON
;
1230 viafb_DeviceStatus
|= DVI_Device
;
1233 if ((device_id
& LCD_Device
) && (device_num
< MAX_ACTIVE_DEV_NUM
)) {
1234 viafb_LCD_ON
= STATE_ON
;
1236 viafb_DeviceStatus
|= LCD_Device
;
1239 if ((device_id
& LCD2_Device
) && (device_num
< MAX_ACTIVE_DEV_NUM
)) {
1240 viafb_LCD2_ON
= STATE_ON
;
1242 viafb_DeviceStatus
|= LCD2_Device
;
1245 if (viafb_DeviceStatus
== None_Device
) {
1246 /* Use CRT as default active device: */
1247 viafb_CRT_ON
= STATE_ON
;
1248 viafb_DeviceStatus
= CRT_Device
;
1250 DEBUG_MSG(KERN_INFO
"Device Status:%x", viafb_DeviceStatus
);
1253 static void viafb_set_device(struct device_t active_dev
)
1255 /* Check available device to enable: */
1256 int device_id
= None_Device
;
1258 device_id
|= CRT_Device
;
1260 device_id
|= DVI_Device
;
1262 device_id
|= LCD_Device
;
1264 check_available_device_to_enable(device_id
);
1266 /* Check property of LCD: */
1268 if (active_dev
.lcd_dsp_cent
) {
1269 viaparinfo
->lvds_setting_info
->display_method
=
1270 viafb_lcd_dsp_method
= LCD_CENTERING
;
1272 viaparinfo
->lvds_setting_info
->display_method
=
1273 viafb_lcd_dsp_method
= LCD_EXPANDSION
;
1276 if (active_dev
.lcd_mode
== LCD_SPWG
) {
1277 viaparinfo
->lvds_setting_info
->lcd_mode
=
1278 viafb_lcd_mode
= LCD_SPWG
;
1280 viaparinfo
->lvds_setting_info
->lcd_mode
=
1281 viafb_lcd_mode
= LCD_OPENLDI
;
1284 if (active_dev
.lcd_panel_id
<= LCD_PANEL_ID_MAXIMUM
) {
1285 viafb_lcd_panel_id
= active_dev
.lcd_panel_id
;
1286 viafb_init_lcd_size();
1290 /* Check property of mode: */
1291 if (!active_dev
.xres1
)
1292 viafb_second_xres
= 640;
1294 viafb_second_xres
= active_dev
.xres1
;
1295 if (!active_dev
.yres1
)
1296 viafb_second_yres
= 480;
1298 viafb_second_yres
= active_dev
.yres1
;
1299 if (active_dev
.bpp
!= 0)
1300 viafb_bpp
= active_dev
.bpp
;
1301 if (active_dev
.bpp1
!= 0)
1302 viafb_bpp1
= active_dev
.bpp1
;
1303 if (active_dev
.refresh
!= 0)
1304 viafb_refresh
= active_dev
.refresh
;
1305 if (active_dev
.refresh1
!= 0)
1306 viafb_refresh1
= active_dev
.refresh1
;
1307 if ((active_dev
.samm
== STATE_OFF
) || (active_dev
.samm
== STATE_ON
))
1308 viafb_SAMM_ON
= active_dev
.samm
;
1309 viafb_primary_dev
= active_dev
.primary_dev
;
1311 viafb_set_primary_address(0);
1312 viafb_set_secondary_address(viafb_SAMM_ON
? viafb_second_offset
: 0);
1313 viafb_set_iga_path();
1316 static void viafb_set_video_device(u32 video_dev_info
)
1318 viaparinfo
->video_on_crt
= STATE_OFF
;
1319 viaparinfo
->video_on_dvi
= STATE_OFF
;
1320 viaparinfo
->video_on_lcd
= STATE_OFF
;
1322 /* Check available device to enable: */
1323 if ((video_dev_info
& CRT_Device
) == CRT_Device
)
1324 viaparinfo
->video_on_crt
= STATE_ON
;
1325 else if ((video_dev_info
& DVI_Device
) == DVI_Device
)
1326 viaparinfo
->video_on_dvi
= STATE_ON
;
1327 else if ((video_dev_info
& LCD_Device
) == LCD_Device
)
1328 viaparinfo
->video_on_lcd
= STATE_ON
;
1331 static void viafb_get_video_device(u32
*video_dev_info
)
1333 *video_dev_info
= None_Device
;
1334 if (viaparinfo
->video_on_crt
== STATE_ON
)
1335 *video_dev_info
|= CRT_Device
;
1336 else if (viaparinfo
->video_on_dvi
== STATE_ON
)
1337 *video_dev_info
|= DVI_Device
;
1338 else if (viaparinfo
->video_on_lcd
== STATE_ON
)
1339 *video_dev_info
|= LCD_Device
;
1342 static int get_primary_device(void)
1344 int primary_device
= 0;
1345 /* Rule: device on iga1 path are the primary device. */
1346 if (viafb_SAMM_ON
) {
1348 if (viaparinfo
->crt_setting_info
->iga_path
== IGA1
) {
1349 DEBUG_MSG(KERN_INFO
"CRT IGA Path:%d\n",
1351 crt_setting_info
->iga_path
);
1352 primary_device
= CRT_Device
;
1356 if (viaparinfo
->tmds_setting_info
->iga_path
== IGA1
) {
1357 DEBUG_MSG(KERN_INFO
"DVI IGA Path:%d\n",
1359 tmds_setting_info
->iga_path
);
1360 primary_device
= DVI_Device
;
1364 if (viaparinfo
->lvds_setting_info
->iga_path
== IGA1
) {
1365 DEBUG_MSG(KERN_INFO
"LCD IGA Path:%d\n",
1367 lvds_setting_info
->iga_path
);
1368 primary_device
= LCD_Device
;
1371 if (viafb_LCD2_ON
) {
1372 if (viaparinfo
->lvds_setting_info2
->iga_path
== IGA1
) {
1373 DEBUG_MSG(KERN_INFO
"LCD2 IGA Path:%d\n",
1375 lvds_setting_info2
->iga_path
);
1376 primary_device
= LCD2_Device
;
1380 return primary_device
;
1383 static void apply_second_mode_setting(struct fb_var_screeninfo
1386 u32 htotal
, vtotal
, long_refresh
;
1388 htotal
= sec_var
->xres
+ sec_var
->left_margin
+
1389 sec_var
->right_margin
+ sec_var
->hsync_len
;
1390 vtotal
= sec_var
->yres
+ sec_var
->upper_margin
+
1391 sec_var
->lower_margin
+ sec_var
->vsync_len
;
1392 if ((sec_var
->xres_virtual
* (sec_var
->bits_per_pixel
>> 3)) & 0x1F) {
1393 /*Is 32 bytes alignment? */
1394 /*32 pixel alignment */
1395 sec_var
->xres_virtual
= (sec_var
->xres_virtual
+ 31) & ~31;
1398 htotal
= sec_var
->xres
+ sec_var
->left_margin
+
1399 sec_var
->right_margin
+ sec_var
->hsync_len
;
1400 vtotal
= sec_var
->yres
+ sec_var
->upper_margin
+
1401 sec_var
->lower_margin
+ sec_var
->vsync_len
;
1402 long_refresh
= 1000000000UL / sec_var
->pixclock
* 1000;
1403 long_refresh
/= (htotal
* vtotal
);
1405 viafb_second_xres
= sec_var
->xres
;
1406 viafb_second_yres
= sec_var
->yres
;
1407 viafb_second_virtual_xres
= sec_var
->xres_virtual
;
1408 viafb_second_virtual_yres
= sec_var
->yres_virtual
;
1409 viafb_bpp1
= sec_var
->bits_per_pixel
;
1410 viafb_refresh1
= viafb_get_refresh(sec_var
->xres
, sec_var
->yres
,
1414 static int apply_device_setting(struct viafb_ioctl_setting setting_info
,
1415 struct fb_info
*info
)
1417 int need_set_mode
= 0;
1418 DEBUG_MSG(KERN_INFO
"apply_device_setting\n");
1420 if (setting_info
.device_flag
) {
1422 check_available_device_to_enable(setting_info
.device_status
);
1425 /* Unlock LCD's operation according to LCD flag
1426 and check if the setting value is valid. */
1427 /* If the value is valid, apply the new setting value to the device. */
1429 if (setting_info
.lcd_operation_flag
& OP_LCD_CENTERING
) {
1431 if (setting_info
.lcd_attributes
.display_center
) {
1433 viaparinfo
->lvds_setting_info
->display_method
=
1435 viafb_lcd_dsp_method
= LCD_CENTERING
;
1436 viaparinfo
->lvds_setting_info2
->display_method
=
1437 viafb_lcd_dsp_method
= LCD_CENTERING
;
1440 viaparinfo
->lvds_setting_info
->display_method
=
1442 viafb_lcd_dsp_method
= LCD_EXPANDSION
;
1443 viaparinfo
->lvds_setting_info2
->display_method
=
1445 viafb_lcd_dsp_method
= LCD_EXPANDSION
;
1449 if (setting_info
.lcd_operation_flag
& OP_LCD_MODE
) {
1451 if (setting_info
.lcd_attributes
.lcd_mode
==
1453 viaparinfo
->lvds_setting_info
->lcd_mode
=
1454 viafb_lcd_mode
= LCD_SPWG
;
1456 viaparinfo
->lvds_setting_info
->lcd_mode
=
1457 viafb_lcd_mode
= LCD_OPENLDI
;
1459 viaparinfo
->lvds_setting_info2
->lcd_mode
=
1460 viaparinfo
->lvds_setting_info
->lcd_mode
;
1463 if (setting_info
.lcd_operation_flag
& OP_LCD_PANEL_ID
) {
1465 if (setting_info
.lcd_attributes
.panel_id
<=
1466 LCD_PANEL_ID_MAXIMUM
) {
1467 viafb_lcd_panel_id
=
1468 setting_info
.lcd_attributes
.panel_id
;
1469 viafb_init_lcd_size();
1474 if (0 != (setting_info
.samm_status
& OP_SAMM
)) {
1475 setting_info
.samm_status
=
1476 setting_info
.samm_status
& (~OP_SAMM
);
1477 if (setting_info
.samm_status
== 0
1478 || setting_info
.samm_status
== 1) {
1479 viafb_SAMM_ON
= setting_info
.samm_status
;
1482 viafb_primary_dev
= setting_info
.primary_device
;
1484 viafb_set_primary_address(0);
1485 viafb_set_secondary_address(viafb_SAMM_ON
? viafb_second_offset
: 0);
1486 viafb_set_iga_path();
1491 if (!need_set_mode
) {
1494 viafb_set_iga_path();
1495 viafb_set_par(info
);
1500 static void retrieve_device_setting(struct viafb_ioctl_setting
1504 /* get device status */
1505 if (viafb_CRT_ON
== 1)
1506 setting_info
->device_status
= CRT_Device
;
1507 if (viafb_DVI_ON
== 1)
1508 setting_info
->device_status
|= DVI_Device
;
1509 if (viafb_LCD_ON
== 1)
1510 setting_info
->device_status
|= LCD_Device
;
1511 if (viafb_LCD2_ON
== 1)
1512 setting_info
->device_status
|= LCD2_Device
;
1513 if ((viaparinfo
->video_on_crt
== 1) && (viafb_CRT_ON
== 1)) {
1514 setting_info
->video_device_status
=
1515 viaparinfo
->crt_setting_info
->iga_path
;
1516 } else if ((viaparinfo
->video_on_dvi
== 1) && (viafb_DVI_ON
== 1)) {
1517 setting_info
->video_device_status
=
1518 viaparinfo
->tmds_setting_info
->iga_path
;
1519 } else if ((viaparinfo
->video_on_lcd
== 1) && (viafb_LCD_ON
== 1)) {
1520 setting_info
->video_device_status
=
1521 viaparinfo
->lvds_setting_info
->iga_path
;
1523 setting_info
->video_device_status
= 0;
1526 setting_info
->samm_status
= viafb_SAMM_ON
;
1527 setting_info
->primary_device
= get_primary_device();
1529 setting_info
->first_dev_bpp
= viafb_bpp
;
1530 setting_info
->second_dev_bpp
= viafb_bpp1
;
1532 setting_info
->first_dev_refresh
= viafb_refresh
;
1533 setting_info
->second_dev_refresh
= viafb_refresh1
;
1535 setting_info
->first_dev_hor_res
= viafb_hotplug_Xres
;
1536 setting_info
->first_dev_ver_res
= viafb_hotplug_Yres
;
1537 setting_info
->second_dev_hor_res
= viafb_second_xres
;
1538 setting_info
->second_dev_ver_res
= viafb_second_yres
;
1540 /* Get lcd attributes */
1541 setting_info
->lcd_attributes
.display_center
= viafb_lcd_dsp_method
;
1542 setting_info
->lcd_attributes
.panel_id
= viafb_lcd_panel_id
;
1543 setting_info
->lcd_attributes
.lcd_mode
= viafb_lcd_mode
;
1546 static void parse_active_dev(void)
1548 viafb_CRT_ON
= STATE_OFF
;
1549 viafb_DVI_ON
= STATE_OFF
;
1550 viafb_LCD_ON
= STATE_OFF
;
1551 viafb_LCD2_ON
= STATE_OFF
;
1552 /* 1. Modify the active status of devices. */
1553 /* 2. Keep the order of devices, so we can set corresponding
1554 IGA path to devices in SAMM case. */
1555 /* Note: The previous of active_dev is primary device,
1556 and the following is secondary device. */
1557 if (!strncmp(viafb_active_dev
, "CRT+DVI", 7)) {
1559 viafb_CRT_ON
= STATE_ON
;
1560 viafb_DVI_ON
= STATE_ON
;
1561 viafb_primary_dev
= CRT_Device
;
1562 } else if (!strncmp(viafb_active_dev
, "DVI+CRT", 7)) {
1564 viafb_CRT_ON
= STATE_ON
;
1565 viafb_DVI_ON
= STATE_ON
;
1566 viafb_primary_dev
= DVI_Device
;
1567 } else if (!strncmp(viafb_active_dev
, "CRT+LCD", 7)) {
1569 viafb_CRT_ON
= STATE_ON
;
1570 viafb_LCD_ON
= STATE_ON
;
1571 viafb_primary_dev
= CRT_Device
;
1572 } else if (!strncmp(viafb_active_dev
, "LCD+CRT", 7)) {
1574 viafb_CRT_ON
= STATE_ON
;
1575 viafb_LCD_ON
= STATE_ON
;
1576 viafb_primary_dev
= LCD_Device
;
1577 } else if (!strncmp(viafb_active_dev
, "DVI+LCD", 7)) {
1579 viafb_DVI_ON
= STATE_ON
;
1580 viafb_LCD_ON
= STATE_ON
;
1581 viafb_primary_dev
= DVI_Device
;
1582 } else if (!strncmp(viafb_active_dev
, "LCD+DVI", 7)) {
1584 viafb_DVI_ON
= STATE_ON
;
1585 viafb_LCD_ON
= STATE_ON
;
1586 viafb_primary_dev
= LCD_Device
;
1587 } else if (!strncmp(viafb_active_dev
, "LCD+LCD2", 8)) {
1588 viafb_LCD_ON
= STATE_ON
;
1589 viafb_LCD2_ON
= STATE_ON
;
1590 viafb_primary_dev
= LCD_Device
;
1591 } else if (!strncmp(viafb_active_dev
, "LCD2+LCD", 8)) {
1592 viafb_LCD_ON
= STATE_ON
;
1593 viafb_LCD2_ON
= STATE_ON
;
1594 viafb_primary_dev
= LCD2_Device
;
1595 } else if (!strncmp(viafb_active_dev
, "CRT", 3)) {
1597 viafb_CRT_ON
= STATE_ON
;
1598 viafb_SAMM_ON
= STATE_OFF
;
1599 } else if (!strncmp(viafb_active_dev
, "DVI", 3)) {
1601 viafb_DVI_ON
= STATE_ON
;
1602 viafb_SAMM_ON
= STATE_OFF
;
1603 } else if (!strncmp(viafb_active_dev
, "LCD", 3)) {
1605 viafb_LCD_ON
= STATE_ON
;
1606 viafb_SAMM_ON
= STATE_OFF
;
1608 viafb_CRT_ON
= STATE_ON
;
1609 viafb_SAMM_ON
= STATE_OFF
;
1613 static void parse_video_dev(void)
1615 viaparinfo
->video_on_crt
= STATE_OFF
;
1616 viaparinfo
->video_on_dvi
= STATE_OFF
;
1617 viaparinfo
->video_on_lcd
= STATE_OFF
;
1619 if (!strncmp(viafb_video_dev
, "CRT", 3)) {
1621 viaparinfo
->video_on_crt
= STATE_ON
;
1622 } else if (!strncmp(viafb_video_dev
, "DVI", 3)) {
1624 viaparinfo
->video_on_dvi
= STATE_ON
;
1625 } else if (!strncmp(viafb_video_dev
, "LCD", 3)) {
1627 viaparinfo
->video_on_lcd
= STATE_ON
;
1631 static int parse_port(char *opt_str
, int *output_interface
)
1633 if (!strncmp(opt_str
, "DVP0", 4))
1634 *output_interface
= INTERFACE_DVP0
;
1635 else if (!strncmp(opt_str
, "DVP1", 4))
1636 *output_interface
= INTERFACE_DVP1
;
1637 else if (!strncmp(opt_str
, "DFP_HIGHLOW", 11))
1638 *output_interface
= INTERFACE_DFP
;
1639 else if (!strncmp(opt_str
, "DFP_HIGH", 8))
1640 *output_interface
= INTERFACE_DFP_HIGH
;
1641 else if (!strncmp(opt_str
, "DFP_LOW", 7))
1642 *output_interface
= INTERFACE_DFP_LOW
;
1644 *output_interface
= INTERFACE_NONE
;
1648 static void parse_lcd_port(void)
1650 parse_port(viafb_lcd_port
, &viaparinfo
->chip_info
->lvds_chip_info
.
1652 /*Initialize to avoid unexpected behavior */
1653 viaparinfo
->chip_info
->lvds_chip_info2
.output_interface
=
1656 DEBUG_MSG(KERN_INFO
"parse_lcd_port: viafb_lcd_port:%s,interface:%d\n",
1657 viafb_lcd_port
, viaparinfo
->chip_info
->lvds_chip_info
.
1661 static void parse_dvi_port(void)
1663 parse_port(viafb_dvi_port
, &viaparinfo
->chip_info
->tmds_chip_info
.
1666 DEBUG_MSG(KERN_INFO
"parse_dvi_port: viafb_dvi_port:%s,interface:%d\n",
1667 viafb_dvi_port
, viaparinfo
->chip_info
->tmds_chip_info
.
1672 * The proc filesystem read/write function, a simple proc implement to
1673 * get/set the value of DPA DVP0, DVP0DataDriving, DVP0ClockDriving, DVP1,
1674 * DVP1Driving, DFPHigh, DFPLow CR96, SR2A[5], SR1B[1], SR2A[4], SR1E[2],
1675 * CR9B, SR65, CR97, CR99
1677 static int viafb_dvp0_proc_read(char *buf
, char **start
, off_t offset
,
1678 int count
, int *eof
, void *data
)
1681 u8 dvp0_data_dri
= 0, dvp0_clk_dri
= 0, dvp0
= 0;
1683 (viafb_read_reg(VIASR
, SR2A
) & BIT5
) >> 4 |
1684 (viafb_read_reg(VIASR
, SR1B
) & BIT1
) >> 1;
1686 (viafb_read_reg(VIASR
, SR2A
) & BIT4
) >> 3 |
1687 (viafb_read_reg(VIASR
, SR1E
) & BIT2
) >> 2;
1688 dvp0
= viafb_read_reg(VIACR
, CR96
) & 0x0f;
1690 sprintf(buf
+ len
, "%x %x %x\n", dvp0
, dvp0_data_dri
, dvp0_clk_dri
);
1691 *eof
= 1; /*Inform kernel end of data */
1694 static int viafb_dvp0_proc_write(struct file
*file
,
1695 const char __user
*buffer
, unsigned long count
, void *data
)
1697 char buf
[20], *value
, *pbuf
;
1699 unsigned long length
, i
;
1702 length
= count
> 20 ? 20 : count
;
1703 if (copy_from_user(&buf
[0], buffer
, length
))
1705 buf
[length
- 1] = '\0'; /*Ensure end string */
1707 for (i
= 0; i
< 3; i
++) {
1708 value
= strsep(&pbuf
, " ");
1709 if (value
!= NULL
) {
1710 strict_strtoul(value
, 0, (unsigned long *)®_val
);
1711 DEBUG_MSG(KERN_INFO
"DVP0:reg_val[%l]=:%x\n", i
,
1715 viafb_write_reg_mask(CR96
, VIACR
,
1719 viafb_write_reg_mask(SR2A
, VIASR
,
1720 reg_val
<< 4, BIT5
);
1721 viafb_write_reg_mask(SR1B
, VIASR
,
1722 reg_val
<< 1, BIT1
);
1725 viafb_write_reg_mask(SR2A
, VIASR
,
1726 reg_val
<< 3, BIT4
);
1727 viafb_write_reg_mask(SR1E
, VIASR
,
1728 reg_val
<< 2, BIT2
);
1739 static int viafb_dvp1_proc_read(char *buf
, char **start
, off_t offset
,
1740 int count
, int *eof
, void *data
)
1743 u8 dvp1
= 0, dvp1_data_dri
= 0, dvp1_clk_dri
= 0;
1744 dvp1
= viafb_read_reg(VIACR
, CR9B
) & 0x0f;
1745 dvp1_data_dri
= (viafb_read_reg(VIASR
, SR65
) & 0x0c) >> 2;
1746 dvp1_clk_dri
= viafb_read_reg(VIASR
, SR65
) & 0x03;
1748 sprintf(buf
+ len
, "%x %x %x\n", dvp1
, dvp1_data_dri
, dvp1_clk_dri
);
1749 *eof
= 1; /*Inform kernel end of data */
1752 static int viafb_dvp1_proc_write(struct file
*file
,
1753 const char __user
*buffer
, unsigned long count
, void *data
)
1755 char buf
[20], *value
, *pbuf
;
1757 unsigned long length
, i
;
1760 length
= count
> 20 ? 20 : count
;
1761 if (copy_from_user(&buf
[0], buffer
, length
))
1763 buf
[length
- 1] = '\0'; /*Ensure end string */
1765 for (i
= 0; i
< 3; i
++) {
1766 value
= strsep(&pbuf
, " ");
1767 if (value
!= NULL
) {
1768 strict_strtoul(value
, 0, (unsigned long *)®_val
);
1771 viafb_write_reg_mask(CR9B
, VIACR
,
1775 viafb_write_reg_mask(SR65
, VIASR
,
1776 reg_val
<< 2, 0x0c);
1779 viafb_write_reg_mask(SR65
, VIASR
,
1792 static int viafb_dfph_proc_read(char *buf
, char **start
, off_t offset
,
1793 int count
, int *eof
, void *data
)
1797 dfp_high
= viafb_read_reg(VIACR
, CR97
) & 0x0f;
1798 len
+= sprintf(buf
+ len
, "%x\n", dfp_high
);
1799 *eof
= 1; /*Inform kernel end of data */
1802 static int viafb_dfph_proc_write(struct file
*file
,
1803 const char __user
*buffer
, unsigned long count
, void *data
)
1807 unsigned long length
;
1810 length
= count
> 20 ? 20 : count
;
1811 if (copy_from_user(&buf
[0], buffer
, length
))
1813 buf
[length
- 1] = '\0'; /*Ensure end string */
1814 strict_strtoul(&buf
[0], 0, (unsigned long *)®_val
);
1815 viafb_write_reg_mask(CR97
, VIACR
, reg_val
, 0x0f);
1818 static int viafb_dfpl_proc_read(char *buf
, char **start
, off_t offset
,
1819 int count
, int *eof
, void *data
)
1823 dfp_low
= viafb_read_reg(VIACR
, CR99
) & 0x0f;
1824 len
+= sprintf(buf
+ len
, "%x\n", dfp_low
);
1825 *eof
= 1; /*Inform kernel end of data */
1828 static int viafb_dfpl_proc_write(struct file
*file
,
1829 const char __user
*buffer
, unsigned long count
, void *data
)
1833 unsigned long length
;
1836 length
= count
> 20 ? 20 : count
;
1837 if (copy_from_user(&buf
[0], buffer
, length
))
1839 buf
[length
- 1] = '\0'; /*Ensure end string */
1840 strict_strtoul(&buf
[0], 0, (unsigned long *)®_val
);
1841 viafb_write_reg_mask(CR99
, VIACR
, reg_val
, 0x0f);
1844 static int viafb_vt1636_proc_read(char *buf
, char **start
,
1845 off_t offset
, int count
, int *eof
, void *data
)
1848 u8 vt1636_08
= 0, vt1636_09
= 0;
1849 switch (viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
) {
1852 viafb_gpio_i2c_read_lvds(viaparinfo
->lvds_setting_info
,
1853 &viaparinfo
->chip_info
->lvds_chip_info
, 0x08) & 0x0f;
1855 viafb_gpio_i2c_read_lvds(viaparinfo
->lvds_setting_info
,
1856 &viaparinfo
->chip_info
->lvds_chip_info
, 0x09) & 0x1f;
1857 len
+= sprintf(buf
+ len
, "%x %x\n", vt1636_08
, vt1636_09
);
1862 switch (viaparinfo
->chip_info
->lvds_chip_info2
.lvds_chip_name
) {
1865 viafb_gpio_i2c_read_lvds(viaparinfo
->lvds_setting_info2
,
1866 &viaparinfo
->chip_info
->lvds_chip_info2
, 0x08) & 0x0f;
1868 viafb_gpio_i2c_read_lvds(viaparinfo
->lvds_setting_info2
,
1869 &viaparinfo
->chip_info
->lvds_chip_info2
, 0x09) & 0x1f;
1870 len
+= sprintf(buf
+ len
, " %x %x\n", vt1636_08
, vt1636_09
);
1875 *eof
= 1; /*Inform kernel end of data */
1878 static int viafb_vt1636_proc_write(struct file
*file
,
1879 const char __user
*buffer
, unsigned long count
, void *data
)
1881 char buf
[30], *value
, *pbuf
;
1882 struct IODATA reg_val
;
1883 unsigned long length
, i
;
1886 length
= count
> 30 ? 30 : count
;
1887 if (copy_from_user(&buf
[0], buffer
, length
))
1889 buf
[length
- 1] = '\0'; /*Ensure end string */
1891 switch (viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
) {
1893 for (i
= 0; i
< 2; i
++) {
1894 value
= strsep(&pbuf
, " ");
1895 if (value
!= NULL
) {
1896 strict_strtoul(value
, 0,
1897 (unsigned long *)®_val
.Data
);
1900 reg_val
.Index
= 0x08;
1901 reg_val
.Mask
= 0x0f;
1902 viafb_gpio_i2c_write_mask_lvds
1903 (viaparinfo
->lvds_setting_info
,
1905 chip_info
->lvds_chip_info
,
1909 reg_val
.Index
= 0x09;
1910 reg_val
.Mask
= 0x1f;
1911 viafb_gpio_i2c_write_mask_lvds
1912 (viaparinfo
->lvds_setting_info
,
1914 chip_info
->lvds_chip_info
,
1928 switch (viaparinfo
->chip_info
->lvds_chip_info2
.lvds_chip_name
) {
1930 for (i
= 0; i
< 2; i
++) {
1931 value
= strsep(&pbuf
, " ");
1932 if (value
!= NULL
) {
1933 strict_strtoul(value
, 0,
1934 (unsigned long *)®_val
.Data
);
1937 reg_val
.Index
= 0x08;
1938 reg_val
.Mask
= 0x0f;
1939 viafb_gpio_i2c_write_mask_lvds
1940 (viaparinfo
->lvds_setting_info2
,
1942 chip_info
->lvds_chip_info2
,
1946 reg_val
.Index
= 0x09;
1947 reg_val
.Mask
= 0x1f;
1948 viafb_gpio_i2c_write_mask_lvds
1949 (viaparinfo
->lvds_setting_info2
,
1951 chip_info
->lvds_chip_info2
,
1968 static void viafb_init_proc(struct proc_dir_entry
**viafb_entry
)
1970 struct proc_dir_entry
*entry
;
1971 *viafb_entry
= proc_mkdir("viafb", NULL
);
1973 entry
= create_proc_entry("dvp0", 0, *viafb_entry
);
1975 entry
->read_proc
= viafb_dvp0_proc_read
;
1976 entry
->write_proc
= viafb_dvp0_proc_write
;
1978 entry
= create_proc_entry("dvp1", 0, *viafb_entry
);
1980 entry
->read_proc
= viafb_dvp1_proc_read
;
1981 entry
->write_proc
= viafb_dvp1_proc_write
;
1983 entry
= create_proc_entry("dfph", 0, *viafb_entry
);
1985 entry
->read_proc
= viafb_dfph_proc_read
;
1986 entry
->write_proc
= viafb_dfph_proc_write
;
1988 entry
= create_proc_entry("dfpl", 0, *viafb_entry
);
1990 entry
->read_proc
= viafb_dfpl_proc_read
;
1991 entry
->write_proc
= viafb_dfpl_proc_write
;
1993 if (VT1636_LVDS
== viaparinfo
->chip_info
->lvds_chip_info
.
1994 lvds_chip_name
|| VT1636_LVDS
==
1995 viaparinfo
->chip_info
->lvds_chip_info2
.lvds_chip_name
) {
1996 entry
= create_proc_entry("vt1636", 0, *viafb_entry
);
1998 entry
->read_proc
= viafb_vt1636_proc_read
;
1999 entry
->write_proc
= viafb_vt1636_proc_write
;
2005 static void viafb_remove_proc(struct proc_dir_entry
*viafb_entry
)
2007 /* no problem if it was not registered */
2008 remove_proc_entry("dvp0", viafb_entry
);/* parent dir */
2009 remove_proc_entry("dvp1", viafb_entry
);
2010 remove_proc_entry("dfph", viafb_entry
);
2011 remove_proc_entry("dfpl", viafb_entry
);
2012 remove_proc_entry("vt1636", viafb_entry
);
2013 remove_proc_entry("vt1625", viafb_entry
);
2014 remove_proc_entry("viafb", NULL
);
2017 static int __devinit
via_pci_probe(void)
2019 unsigned long default_xres
, default_yres
;
2021 char *tmpc_sec
, *tmpm_sec
;
2023 u32 tmds_length
, lvds_length
, crt_length
, chip_length
, viafb_par_length
;
2025 DEBUG_MSG(KERN_INFO
"VIAFB PCI Probe!!\n");
2027 viafb_par_length
= ALIGN(sizeof(struct viafb_par
), BITS_PER_LONG
/8);
2028 tmds_length
= ALIGN(sizeof(struct tmds_setting_information
),
2030 lvds_length
= ALIGN(sizeof(struct lvds_setting_information
),
2032 crt_length
= ALIGN(sizeof(struct lvds_setting_information
),
2034 chip_length
= ALIGN(sizeof(struct chip_information
), BITS_PER_LONG
/8);
2036 /* Allocate fb_info and ***_par here, also including some other needed
2039 viafbinfo
= framebuffer_alloc(viafb_par_length
+ 2 * lvds_length
+
2040 tmds_length
+ crt_length
+ chip_length
, NULL
);
2042 printk(KERN_ERR
"Could not allocate memory for viafb_info.\n");
2046 viaparinfo
= (struct viafb_par
*)viafbinfo
->par
;
2047 viaparinfo
->tmds_setting_info
= (struct tmds_setting_information
*)
2048 ((unsigned long)viaparinfo
+ viafb_par_length
);
2049 viaparinfo
->lvds_setting_info
= (struct lvds_setting_information
*)
2050 ((unsigned long)viaparinfo
->tmds_setting_info
+ tmds_length
);
2051 viaparinfo
->lvds_setting_info2
= (struct lvds_setting_information
*)
2052 ((unsigned long)viaparinfo
->lvds_setting_info
+ lvds_length
);
2053 viaparinfo
->crt_setting_info
= (struct crt_setting_information
*)
2054 ((unsigned long)viaparinfo
->lvds_setting_info2
+ lvds_length
);
2055 viaparinfo
->chip_info
= (struct chip_information
*)
2056 ((unsigned long)viaparinfo
->crt_setting_info
+ crt_length
);
2065 /* for dual-fb must viafb_SAMM_ON=1 and viafb_dual_fb=1 */
2069 /* Set up I2C bus stuff */
2070 viafb_create_i2c_bus(viaparinfo
);
2072 viafb_init_chip_info();
2073 viafb_get_fb_info(&viaparinfo
->fbmem
, &viaparinfo
->memsize
);
2074 viaparinfo
->fbmem_free
= viaparinfo
->memsize
;
2075 viaparinfo
->fbmem_used
= 0;
2076 viaparinfo
->fbmem_virt
= ioremap_nocache(viaparinfo
->fbmem
,
2077 viaparinfo
->memsize
);
2078 viafbinfo
->screen_base
= (char *)viaparinfo
->fbmem_virt
;
2080 if (!viaparinfo
->fbmem_virt
) {
2081 printk(KERN_INFO
"ioremap failed\n");
2085 viafb_get_mmio_info(&viaparinfo
->mmio_base
, &viaparinfo
->mmio_len
);
2086 viaparinfo
->io_virt
= ioremap_nocache(viaparinfo
->mmio_base
,
2087 viaparinfo
->mmio_len
);
2088 if (!viaparinfo
->io_virt
) {
2089 printk(KERN_WARNING
"ioremap failed: hardware acceleration disabled\n");
2093 viafbinfo
->node
= 0;
2094 viafbinfo
->fbops
= &viafb_ops
;
2095 viafbinfo
->flags
= FBINFO_DEFAULT
| FBINFO_HWACCEL_YPAN
;
2097 viafbinfo
->pseudo_palette
= pseudo_pal
;
2100 viafb_init_2d_engine();
2101 viafb_hw_cursor_init();
2104 if (viafb_second_size
&& (viafb_second_size
< 8)) {
2105 viafb_second_offset
= viaparinfo
->fbmem_free
-
2106 viafb_second_size
* 1024 * 1024;
2108 viafb_second_size
= 8;
2109 viafb_second_offset
= viaparinfo
->fbmem_free
-
2110 viafb_second_size
* 1024 * 1024;
2113 viafb_FB_MM
= viaparinfo
->fbmem_virt
;
2115 tmpc
= strsep(&tmpm
, "x");
2116 strict_strtoul(tmpc
, 0, &default_xres
);
2117 strict_strtoul(tmpm
, 0, &default_yres
);
2119 vmode_index
= viafb_get_mode_index(default_xres
, default_yres
);
2120 DEBUG_MSG(KERN_INFO
"0->index=%d\n", vmode_index
);
2122 if (viafb_SAMM_ON
== 1) {
2123 if (strcmp(viafb_mode
, viafb_mode1
)) {
2124 tmpm_sec
= viafb_mode1
;
2125 tmpc_sec
= strsep(&tmpm_sec
, "x");
2126 strict_strtoul(tmpc_sec
, 0,
2127 (unsigned long *)&viafb_second_xres
);
2128 strict_strtoul(tmpm_sec
, 0,
2129 (unsigned long *)&viafb_second_yres
);
2131 viafb_second_xres
= default_xres
;
2132 viafb_second_yres
= default_yres
;
2134 if (0 == viafb_second_virtual_xres
) {
2135 switch (viafb_second_xres
) {
2137 viafb_second_virtual_xres
= 1408;
2140 viafb_second_virtual_xres
= viafb_second_xres
;
2144 if (0 == viafb_second_virtual_yres
)
2145 viafb_second_virtual_yres
= viafb_second_yres
;
2148 switch (viafb_bpp
) {
2161 default_var
.xres
= default_xres
;
2162 default_var
.yres
= default_yres
;
2163 switch (default_xres
) {
2165 default_var
.xres_virtual
= 1408;
2168 default_var
.xres_virtual
= default_xres
;
2171 default_var
.yres_virtual
= default_yres
;
2172 default_var
.bits_per_pixel
= viafb_bpp
;
2173 if (default_var
.bits_per_pixel
== 15)
2174 default_var
.bits_per_pixel
= 16;
2175 default_var
.pixclock
=
2176 viafb_get_pixclock(default_xres
, default_yres
, viafb_refresh
);
2177 default_var
.left_margin
= (default_xres
>> 3) & 0xf8;
2178 default_var
.right_margin
= 32;
2179 default_var
.upper_margin
= 16;
2180 default_var
.lower_margin
= 4;
2181 default_var
.hsync_len
= default_var
.left_margin
;
2182 default_var
.vsync_len
= 4;
2183 default_var
.accel_flags
= 0;
2187 (FBINFO_HWACCEL_COPYAREA
| FBINFO_HWACCEL_FILLRECT
|
2188 FBINFO_HWACCEL_IMAGEBLIT
);
2189 default_var
.accel_flags
|= FB_ACCELF_TEXT
;
2191 viafbinfo
->flags
|= FBINFO_HWACCEL_DISABLED
;
2193 if (viafb_dual_fb
) {
2194 viafbinfo1
= framebuffer_alloc(viafb_par_length
, NULL
);
2197 "allocate the second framebuffer struct error\n");
2198 framebuffer_release(viafbinfo
);
2201 viaparinfo1
= viafbinfo1
->par
;
2202 memcpy(viaparinfo1
, viaparinfo
, viafb_par_length
);
2203 viaparinfo1
->memsize
= viaparinfo
->memsize
-
2204 viafb_second_offset
;
2205 viaparinfo
->memsize
= viafb_second_offset
;
2206 viaparinfo1
->fbmem_virt
= viaparinfo
->fbmem_virt
+
2207 viafb_second_offset
;
2208 viaparinfo1
->fbmem
= viaparinfo
->fbmem
+ viafb_second_offset
;
2210 viaparinfo1
->fbmem_used
= viaparinfo
->fbmem_used
;
2211 viaparinfo1
->fbmem_free
= viaparinfo1
->memsize
-
2212 viaparinfo1
->fbmem_used
;
2213 viaparinfo
->fbmem_free
= viaparinfo
->memsize
;
2214 viaparinfo
->fbmem_used
= 0;
2216 viaparinfo1
->cursor_start
=
2217 viaparinfo
->cursor_start
- viafb_second_offset
;
2218 viaparinfo1
->VQ_start
= viaparinfo
->VQ_start
-
2219 viafb_second_offset
;
2220 viaparinfo1
->VQ_end
= viaparinfo
->VQ_end
-
2221 viafb_second_offset
;
2224 viaparinfo
->iga_path
= IGA1
;
2225 viaparinfo1
->iga_path
= IGA2
;
2226 memcpy(viafbinfo1
, viafbinfo
, sizeof(struct fb_info
));
2227 viafbinfo1
->screen_base
= viafbinfo
->screen_base
+
2228 viafb_second_offset
;
2229 viafbinfo1
->fix
.smem_start
= viaparinfo1
->fbmem
;
2230 viafbinfo1
->fix
.smem_len
= viaparinfo1
->fbmem_free
;
2232 default_var
.xres
= viafb_second_xres
;
2233 default_var
.yres
= viafb_second_yres
;
2234 default_var
.xres_virtual
= viafb_second_virtual_xres
;
2235 default_var
.yres_virtual
= viafb_second_virtual_yres
;
2236 if (viafb_bpp1
!= viafb_bpp
)
2237 viafb_bpp1
= viafb_bpp
;
2238 default_var
.bits_per_pixel
= viafb_bpp1
;
2239 default_var
.pixclock
=
2240 viafb_get_pixclock(viafb_second_xres
, viafb_second_yres
,
2242 default_var
.left_margin
= (viafb_second_xres
>> 3) & 0xf8;
2243 default_var
.right_margin
= 32;
2244 default_var
.upper_margin
= 16;
2245 default_var
.lower_margin
= 4;
2246 default_var
.hsync_len
= default_var
.left_margin
;
2247 default_var
.vsync_len
= 4;
2249 viafb_setup_fixinfo(&viafbinfo1
->fix
, viaparinfo1
);
2250 viafb_check_var(&default_var
, viafbinfo1
);
2251 viafbinfo1
->var
= default_var
;
2252 viafb_update_fix(viafbinfo1
);
2255 viafb_setup_fixinfo(&viafbinfo
->fix
, viaparinfo
);
2256 viafb_check_var(&default_var
, viafbinfo
);
2257 viafbinfo
->var
= default_var
;
2258 viafb_update_fix(viafbinfo
);
2259 default_var
.activate
= FB_ACTIVATE_NOW
;
2260 fb_alloc_cmap(&viafbinfo
->cmap
, 256, 0);
2262 if (viafb_dual_fb
&& (viafb_primary_dev
== LCD_Device
)
2263 && (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_CLE266
)) {
2264 if (register_framebuffer(viafbinfo1
) < 0)
2267 if (register_framebuffer(viafbinfo
) < 0)
2270 if (viafb_dual_fb
&& ((viafb_primary_dev
!= LCD_Device
)
2271 || (viaparinfo
->chip_info
->gfx_chip_name
!=
2272 UNICHROME_CLE266
))) {
2273 if (register_framebuffer(viafbinfo1
) < 0)
2276 DEBUG_MSG(KERN_INFO
"fb%d: %s frame buffer device %dx%d-%dbpp\n",
2277 viafbinfo
->node
, viafbinfo
->fix
.id
, default_var
.xres
,
2278 default_var
.yres
, default_var
.bits_per_pixel
);
2280 viafb_init_proc(&viaparinfo
->proc_entry
);
2281 viafb_init_dac(IGA2
);
2285 static void __devexit
via_pci_remove(void)
2287 DEBUG_MSG(KERN_INFO
"via_pci_remove!\n");
2288 fb_dealloc_cmap(&viafbinfo
->cmap
);
2289 unregister_framebuffer(viafbinfo
);
2291 unregister_framebuffer(viafbinfo1
);
2292 iounmap((void *)viaparinfo
->fbmem_virt
);
2293 iounmap(viaparinfo
->io_virt
);
2295 viafb_delete_i2c_buss(viaparinfo
);
2297 framebuffer_release(viafbinfo
);
2299 framebuffer_release(viafbinfo1
);
2301 viafb_remove_proc(viaparinfo
->proc_entry
);
2305 static int __init
viafb_setup(char *options
)
2308 DEBUG_MSG(KERN_INFO
"viafb_setup!\n");
2310 if (!options
|| !*options
)
2313 while ((this_opt
= strsep(&options
, ",")) != NULL
) {
2317 if (!strncmp(this_opt
, "viafb_mode1=", 12))
2318 viafb_mode1
= kstrdup(this_opt
+ 12, GFP_KERNEL
);
2319 else if (!strncmp(this_opt
, "viafb_mode=", 11))
2320 viafb_mode
= kstrdup(this_opt
+ 11, GFP_KERNEL
);
2321 else if (!strncmp(this_opt
, "viafb_bpp1=", 11))
2322 strict_strtoul(this_opt
+ 11, 0,
2323 (unsigned long *)&viafb_bpp1
);
2324 else if (!strncmp(this_opt
, "viafb_bpp=", 10))
2325 strict_strtoul(this_opt
+ 10, 0,
2326 (unsigned long *)&viafb_bpp
);
2327 else if (!strncmp(this_opt
, "viafb_refresh1=", 15))
2328 strict_strtoul(this_opt
+ 15, 0,
2329 (unsigned long *)&viafb_refresh1
);
2330 else if (!strncmp(this_opt
, "viafb_refresh=", 14))
2331 strict_strtoul(this_opt
+ 14, 0,
2332 (unsigned long *)&viafb_refresh
);
2333 else if (!strncmp(this_opt
, "viafb_lcd_dsp_method=", 21))
2334 strict_strtoul(this_opt
+ 21, 0,
2335 (unsigned long *)&viafb_lcd_dsp_method
);
2336 else if (!strncmp(this_opt
, "viafb_lcd_panel_id=", 19))
2337 strict_strtoul(this_opt
+ 19, 0,
2338 (unsigned long *)&viafb_lcd_panel_id
);
2339 else if (!strncmp(this_opt
, "viafb_accel=", 12))
2340 strict_strtoul(this_opt
+ 12, 0,
2341 (unsigned long *)&viafb_accel
);
2342 else if (!strncmp(this_opt
, "viafb_SAMM_ON=", 14))
2343 strict_strtoul(this_opt
+ 14, 0,
2344 (unsigned long *)&viafb_SAMM_ON
);
2345 else if (!strncmp(this_opt
, "viafb_active_dev=", 17))
2346 viafb_active_dev
= kstrdup(this_opt
+ 17, GFP_KERNEL
);
2347 else if (!strncmp(this_opt
,
2348 "viafb_display_hardware_layout=", 30))
2349 strict_strtoul(this_opt
+ 30, 0,
2350 (unsigned long *)&viafb_display_hardware_layout
);
2351 else if (!strncmp(this_opt
, "viafb_second_size=", 18))
2352 strict_strtoul(this_opt
+ 18, 0,
2353 (unsigned long *)&viafb_second_size
);
2354 else if (!strncmp(this_opt
,
2355 "viafb_platform_epia_dvi=", 24))
2356 strict_strtoul(this_opt
+ 24, 0,
2357 (unsigned long *)&viafb_platform_epia_dvi
);
2358 else if (!strncmp(this_opt
,
2359 "viafb_device_lcd_dualedge=", 26))
2360 strict_strtoul(this_opt
+ 26, 0,
2361 (unsigned long *)&viafb_device_lcd_dualedge
);
2362 else if (!strncmp(this_opt
, "viafb_bus_width=", 16))
2363 strict_strtoul(this_opt
+ 16, 0,
2364 (unsigned long *)&viafb_bus_width
);
2365 else if (!strncmp(this_opt
, "viafb_lcd_mode=", 15))
2366 strict_strtoul(this_opt
+ 15, 0,
2367 (unsigned long *)&viafb_lcd_mode
);
2368 else if (!strncmp(this_opt
, "viafb_video_dev=", 16))
2369 viafb_video_dev
= kstrdup(this_opt
+ 16, GFP_KERNEL
);
2370 else if (!strncmp(this_opt
, "viafb_lcd_port=", 15))
2371 viafb_lcd_port
= kstrdup(this_opt
+ 15, GFP_KERNEL
);
2372 else if (!strncmp(this_opt
, "viafb_dvi_port=", 15))
2373 viafb_dvi_port
= kstrdup(this_opt
+ 15, GFP_KERNEL
);
2379 static int __init
viafb_init(void)
2382 char *option
= NULL
;
2383 if (fb_get_options("viafb", &option
))
2385 viafb_setup(option
);
2388 "VIA Graphics Intergration Chipset framebuffer %d.%d initializing\n",
2389 VERSION_MAJOR
, VERSION_MINOR
);
2390 return via_pci_probe();
2393 static void __exit
viafb_exit(void)
2395 DEBUG_MSG(KERN_INFO
"viafb_exit!\n");
2399 static struct fb_ops viafb_ops
= {
2400 .owner
= THIS_MODULE
,
2401 .fb_open
= viafb_open
,
2402 .fb_release
= viafb_release
,
2403 .fb_check_var
= viafb_check_var
,
2404 .fb_set_par
= viafb_set_par
,
2405 .fb_setcolreg
= viafb_setcolreg
,
2406 .fb_pan_display
= viafb_pan_display
,
2407 .fb_blank
= viafb_blank
,
2408 .fb_fillrect
= viafb_fillrect
,
2409 .fb_copyarea
= viafb_copyarea
,
2410 .fb_imageblit
= viafb_imageblit
,
2411 .fb_cursor
= viafb_cursor
,
2412 .fb_ioctl
= viafb_ioctl
,
2413 .fb_sync
= viafb_sync
,
2414 .fb_setcmap
= viafb_setcmap
,
2417 module_init(viafb_init
);
2418 module_exit(viafb_exit
);
2421 module_param(viafb_memsize
, int, 0);
2423 module_param(viafb_mode
, charp
, 0);
2424 MODULE_PARM_DESC(viafb_mode
, "Set resolution (default=640x480)");
2426 module_param(viafb_mode1
, charp
, 0);
2427 MODULE_PARM_DESC(viafb_mode1
, "Set resolution (default=640x480)");
2429 module_param(viafb_bpp
, int, 0);
2430 MODULE_PARM_DESC(viafb_bpp
, "Set color depth (default=32bpp)");
2432 module_param(viafb_bpp1
, int, 0);
2433 MODULE_PARM_DESC(viafb_bpp1
, "Set color depth (default=32bpp)");
2435 module_param(viafb_refresh
, int, 0);
2436 MODULE_PARM_DESC(viafb_refresh
,
2437 "Set CRT viafb_refresh rate (default = 60)");
2439 module_param(viafb_refresh1
, int, 0);
2440 MODULE_PARM_DESC(viafb_refresh1
,
2441 "Set CRT refresh rate (default = 60)");
2443 module_param(viafb_lcd_panel_id
, int, 0);
2444 MODULE_PARM_DESC(viafb_lcd_panel_id
,
2445 "Set Flat Panel type(Default=1024x768)");
2447 module_param(viafb_lcd_dsp_method
, int, 0);
2448 MODULE_PARM_DESC(viafb_lcd_dsp_method
,
2449 "Set Flat Panel display scaling method.(Default=Expandsion)");
2451 module_param(viafb_SAMM_ON
, int, 0);
2452 MODULE_PARM_DESC(viafb_SAMM_ON
,
2453 "Turn on/off flag of SAMM(Default=OFF)");
2455 module_param(viafb_accel
, int, 0);
2456 MODULE_PARM_DESC(viafb_accel
,
2457 "Set 2D Hardware Acceleration.(Default = OFF)");
2459 module_param(viafb_active_dev
, charp
, 0);
2460 MODULE_PARM_DESC(viafb_active_dev
, "Specify active devices.");
2462 module_param(viafb_display_hardware_layout
, int, 0);
2463 MODULE_PARM_DESC(viafb_display_hardware_layout
,
2464 "Display Hardware Layout (LCD Only, DVI Only...,etc)");
2466 module_param(viafb_second_size
, int, 0);
2467 MODULE_PARM_DESC(viafb_second_size
,
2468 "Set secondary device memory size");
2470 module_param(viafb_dual_fb
, int, 0);
2471 MODULE_PARM_DESC(viafb_dual_fb
,
2472 "Turn on/off flag of dual framebuffer devices.(Default = OFF)");
2474 module_param(viafb_platform_epia_dvi
, int, 0);
2475 MODULE_PARM_DESC(viafb_platform_epia_dvi
,
2476 "Turn on/off flag of DVI devices on EPIA board.(Default = OFF)");
2478 module_param(viafb_device_lcd_dualedge
, int, 0);
2479 MODULE_PARM_DESC(viafb_device_lcd_dualedge
,
2480 "Turn on/off flag of dual edge panel.(Default = OFF)");
2482 module_param(viafb_bus_width
, int, 0);
2483 MODULE_PARM_DESC(viafb_bus_width
,
2484 "Set bus width of panel.(Default = 12)");
2486 module_param(viafb_lcd_mode
, int, 0);
2487 MODULE_PARM_DESC(viafb_lcd_mode
,
2488 "Set Flat Panel mode(Default=OPENLDI)");
2490 module_param(viafb_video_dev
, charp
, 0);
2491 MODULE_PARM_DESC(viafb_video_dev
, "Specify video devices.");
2493 module_param(viafb_lcd_port
, charp
, 0);
2494 MODULE_PARM_DESC(viafb_lcd_port
, "Specify LCD output port.");
2496 module_param(viafb_dvi_port
, charp
, 0);
2497 MODULE_PARM_DESC(viafb_dvi_port
, "Specify DVI output port.");
2499 MODULE_LICENSE("GPL");