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 /* Mode information */
57 static const struct viafb_modeinfo viafb_modentry
[] = {
58 {480, 640, VIA_RES_480X640
},
59 {640, 480, VIA_RES_640X480
},
60 {800, 480, VIA_RES_800X480
},
61 {800, 600, VIA_RES_800X600
},
62 {1024, 768, VIA_RES_1024X768
},
63 {1152, 864, VIA_RES_1152X864
},
64 {1280, 1024, VIA_RES_1280X1024
},
65 {1600, 1200, VIA_RES_1600X1200
},
66 {1440, 1050, VIA_RES_1440X1050
},
67 {1280, 768, VIA_RES_1280X768
,},
68 {1280, 800, VIA_RES_1280X800
},
69 {1280, 960, VIA_RES_1280X960
},
70 {1920, 1440, VIA_RES_1920X1440
},
71 {848, 480, VIA_RES_848X480
},
72 {1400, 1050, VIA_RES_1400X1050
},
73 {720, 480, VIA_RES_720X480
},
74 {720, 576, VIA_RES_720X576
},
75 {1024, 512, VIA_RES_1024X512
},
76 {1024, 576, VIA_RES_1024X576
},
77 {1024, 600, VIA_RES_1024X600
},
78 {1280, 720, VIA_RES_1280X720
},
79 {1920, 1080, VIA_RES_1920X1080
},
80 {1366, 768, VIA_RES_1368X768
},
81 {1680, 1050, VIA_RES_1680X1050
},
82 {960, 600, VIA_RES_960X600
},
83 {1000, 600, VIA_RES_1000X600
},
84 {1024, 576, VIA_RES_1024X576
},
85 {1024, 600, VIA_RES_1024X600
},
86 {1088, 612, VIA_RES_1088X612
},
87 {1152, 720, VIA_RES_1152X720
},
88 {1200, 720, VIA_RES_1200X720
},
89 {1280, 600, VIA_RES_1280X600
},
90 {1360, 768, VIA_RES_1360X768
},
91 {1440, 900, VIA_RES_1440X900
},
92 {1600, 900, VIA_RES_1600X900
},
93 {1600, 1024, VIA_RES_1600X1024
},
94 {1792, 1344, VIA_RES_1792X1344
},
95 {1856, 1392, VIA_RES_1856X1392
},
96 {1920, 1200, VIA_RES_1920X1200
},
97 {2048, 1536, VIA_RES_2048X1536
},
98 {0, 0, VIA_RES_INVALID
}
101 static struct fb_ops viafb_ops
;
103 static int viafb_update_fix(struct fb_fix_screeninfo
*fix
, struct fb_info
*info
)
105 struct viafb_par
*ppar
;
108 DEBUG_MSG(KERN_INFO
"viafb_update_fix!\n");
111 ppar
->bpp
== 8 ? FB_VISUAL_PSEUDOCOLOR
: FB_VISUAL_TRUECOLOR
;
112 fix
->line_length
= ppar
->linelength
;
118 static void viafb_setup_fixinfo(struct fb_fix_screeninfo
*fix
,
119 struct viafb_par
*viaparinfo
)
121 memset(fix
, 0, sizeof(struct fb_fix_screeninfo
));
122 strcpy(fix
->id
, viafb_name
);
124 fix
->smem_start
= viaparinfo
->fbmem
;
125 fix
->smem_len
= viaparinfo
->fbmem_free
;
126 fix
->mmio_start
= viaparinfo
->mmio_base
;
127 fix
->mmio_len
= viaparinfo
->mmio_len
;
129 fix
->type
= FB_TYPE_PACKED_PIXELS
;
132 fix
->xpanstep
= fix
->ywrapstep
= 0;
135 /* Just tell the accel name */
136 viafbinfo
->fix
.accel
= FB_ACCEL_VIA_UNICHROME
;
138 static int viafb_open(struct fb_info
*info
, int user
)
140 DEBUG_MSG(KERN_INFO
"viafb_open!\n");
144 static int viafb_release(struct fb_info
*info
, int user
)
146 DEBUG_MSG(KERN_INFO
"viafb_release!\n");
150 static void viafb_update_viafb_par(struct fb_info
*info
)
152 struct viafb_par
*ppar
;
155 ppar
->bpp
= info
->var
.bits_per_pixel
;
156 ppar
->linelength
= ((info
->var
.xres_virtual
+ 7) & ~7) * ppar
->bpp
/ 8;
157 ppar
->hres
= info
->var
.xres
;
158 ppar
->vres
= info
->var
.yres
;
159 ppar
->xoffset
= info
->var
.xoffset
;
160 ppar
->yoffset
= info
->var
.yoffset
;
163 static int viafb_check_var(struct fb_var_screeninfo
*var
,
164 struct fb_info
*info
)
166 int vmode_index
, htotal
, vtotal
;
167 struct viafb_par
*ppar
;
169 struct viafb_par
*p_viafb_par
;
173 DEBUG_MSG(KERN_INFO
"viafb_check_var!\n");
175 /* HW neither support interlacte nor double-scaned mode */
176 if (var
->vmode
& FB_VMODE_INTERLACED
|| var
->vmode
& FB_VMODE_DOUBLE
)
179 vmode_index
= viafb_get_mode_index(var
->xres
, var
->yres
);
180 if (vmode_index
== VIA_RES_INVALID
) {
182 "viafb: Mode %dx%dx%d not supported!!\n",
183 var
->xres
, var
->yres
, var
->bits_per_pixel
);
187 if (24 == var
->bits_per_pixel
)
188 var
->bits_per_pixel
= 32;
190 if (var
->bits_per_pixel
!= 8 && var
->bits_per_pixel
!= 16 &&
191 var
->bits_per_pixel
!= 32)
194 if ((var
->xres_virtual
* (var
->bits_per_pixel
>> 3)) & 0x1F)
195 /*32 pixel alignment */
196 var
->xres_virtual
= (var
->xres_virtual
+ 31) & ~31;
197 if (var
->xres_virtual
* var
->yres_virtual
* var
->bits_per_pixel
/ 8 >
201 /* Based on var passed in to calculate the refresh,
202 * because our driver use some modes special.
204 htotal
= var
->xres
+ var
->left_margin
+
205 var
->right_margin
+ var
->hsync_len
;
206 vtotal
= var
->yres
+ var
->upper_margin
+
207 var
->lower_margin
+ var
->vsync_len
;
208 long_refresh
= 1000000000UL / var
->pixclock
* 1000;
209 long_refresh
/= (htotal
* vtotal
);
211 viafb_refresh
= viafb_get_refresh(var
->xres
, var
->yres
, long_refresh
);
213 /* Adjust var according to our driver's own table */
214 viafb_fill_var_timing_info(var
, viafb_refresh
, vmode_index
);
216 /* This is indeed a patch for VT3353 */
219 p_viafb_par
= (struct viafb_par
*)info
->par
;
220 if (p_viafb_par
->chip_info
->gfx_chip_name
== UNICHROME_VX800
)
221 var
->accel_flags
= 0;
226 static int viafb_set_par(struct fb_info
*info
)
229 int vmode_index1
= 0;
230 DEBUG_MSG(KERN_INFO
"viafb_set_par!\n");
232 viafb_update_device_setting(info
->var
.xres
, info
->var
.yres
,
233 info
->var
.bits_per_pixel
, viafb_refresh
, 0);
235 vmode_index
= viafb_get_mode_index(info
->var
.xres
, info
->var
.yres
);
237 if (viafb_SAMM_ON
== 1) {
239 "viafb_second_xres = %d, viafb_second_yres = %d, bpp = %d\n",
240 viafb_second_xres
, viafb_second_yres
, viafb_bpp1
);
241 vmode_index1
= viafb_get_mode_index(viafb_second_xres
,
243 DEBUG_MSG(KERN_INFO
"->viafb_SAMM_ON: index=%d\n",
246 viafb_update_device_setting(viafb_second_xres
,
247 viafb_second_yres
, viafb_bpp1
, viafb_refresh1
, 1);
250 if (vmode_index
!= VIA_RES_INVALID
) {
251 viafb_setmode(vmode_index
, info
->var
.xres
, info
->var
.yres
,
252 info
->var
.bits_per_pixel
, vmode_index1
,
253 viafb_second_xres
, viafb_second_yres
, viafb_bpp1
);
255 /*We should set memory offset according virtual_x */
256 /*Fix me:put this function into viafb_setmode */
257 viafb_memory_pitch_patch(info
);
259 /* Update ***fb_par information */
260 viafb_update_viafb_par(info
);
262 /* Update other fixed information */
263 viafb_update_fix(&info
->fix
, info
);
264 viafb_bpp
= info
->var
.bits_per_pixel
;
265 /* Update viafb_accel, it is necessary to our 2D accelerate */
266 viafb_accel
= info
->var
.accel_flags
;
269 viafb_set_2d_color_depth(info
->var
.bits_per_pixel
);
275 /* Set one color register */
276 static int viafb_setcolreg(unsigned regno
, unsigned red
, unsigned green
,
277 unsigned blue
, unsigned transp
, struct fb_info
*info
)
279 u8 sr1a
, sr1b
, cr67
, cr6a
, rev
= 0, shift
= 10;
280 unsigned cmap_entries
= (info
->var
.bits_per_pixel
== 8) ? 256 : 16;
281 DEBUG_MSG(KERN_INFO
"viafb_setcolreg!\n");
282 if (regno
>= cmap_entries
)
284 if (UNICHROME_CLE266
== viaparinfo
->chip_info
->gfx_chip_name
) {
286 * Read PCI bus 0,dev 0,function 0,index 0xF6 to get chip rev.
288 outl(0x80000000 | (0xf6 & ~3), (unsigned long)0xCF8);
289 rev
= (inl((unsigned long)0xCFC) >> ((0xf6 & 3) * 8)) & 0xff;
291 switch (info
->var
.bits_per_pixel
) {
302 /* Map the 3C6/7/8/9 to the IGA2 */
304 outb(sr1a
| 0x01, 0x3C5);
305 /* Second Display Engine colck always on */
307 outb(sr1b
| 0x80, 0x3C5);
308 /* Second Display Color Depth 8 */
310 outb(cr67
& 0x3F, 0x3D5);
312 /* Second Display Channel Reset CR6A[6]) */
313 outb(cr6a
& 0xBF, 0x3D5);
314 /* Second Display Channel Enable CR6A[7] */
315 outb(cr6a
| 0x80, 0x3D5);
316 /* Second Display Channel stop reset) */
317 outb(cr6a
| 0x40, 0x3D5);
319 /* Bit mask of palette */
321 /* Write one register of IGA2 */
323 if (UNICHROME_CLE266
== viaparinfo
->chip_info
->gfx_chip_name
&&
326 viafb_write_reg_mask(CR6A
, VIACR
, BIT5
, BIT5
);
327 viafb_write_reg_mask(SR15
, VIASR
, BIT7
, BIT7
);
330 viafb_write_reg_mask(CR6A
, VIACR
, 0, BIT5
);
331 viafb_write_reg_mask(SR15
, VIASR
, 0, BIT7
);
333 outb(red
>> shift
, 0x3C9);
334 outb(green
>> shift
, 0x3C9);
335 outb(blue
>> shift
, 0x3C9);
337 /* Map the 3C6/7/8/9 to the IGA1 */
339 outb(sr1a
& 0xFE, 0x3C5);
340 /* Bit mask of palette */
342 /* Write one register of IGA1 */
344 outb(red
>> shift
, 0x3C9);
345 outb(green
>> shift
, 0x3C9);
346 outb(blue
>> shift
, 0x3C9);
358 ((u32
*) info
->pseudo_palette
)[regno
] = (red
& 0xF800) |
359 ((green
& 0xFC00) >> 5) | ((blue
& 0xF800) >> 11);
362 ((u32
*) info
->pseudo_palette
)[regno
] =
363 ((transp
& 0xFF00) << 16) |
364 ((red
& 0xFF00) << 8) |
365 ((green
& 0xFF00)) | ((blue
& 0xFF00) >> 8);
373 /*CALLED BY: fb_set_cmap */
374 /* fb_set_var, pass 256 colors */
375 /*CALLED BY: fb_set_cmap */
376 /* fbcon_set_palette, pass 16 colors */
377 static int viafb_setcmap(struct fb_cmap
*cmap
, struct fb_info
*info
)
381 u16
*pred
= cmap
->red
;
382 u16
*pgreen
= cmap
->green
;
383 u16
*pblue
= cmap
->blue
;
384 u16
*ptransp
= cmap
->transp
;
385 u8 sr1a
, sr1b
, cr67
, cr6a
, rev
= 0, shift
= 10;
388 if (UNICHROME_CLE266
== viaparinfo
->chip_info
->gfx_chip_name
) {
390 * Read PCI bus 0, dev 0, function 0, index 0xF6 to get chip
393 outl(0x80000000 | (0xf6 & ~3), (unsigned long)0xCF8);
394 rev
= (inl((unsigned long)0xCFC) >> ((0xf6 & 3) * 8)) & 0xff;
396 switch (info
->var
.bits_per_pixel
) {
406 /* Map the 3C6/7/8/9 to the IGA2 */
408 outb(sr1a
| 0x01, 0x3C5);
410 /* Second Display Engine colck always on */
411 outb(sr1b
| 0x80, 0x3C5);
413 /* Second Display Color Depth 8 */
414 outb(cr67
& 0x3F, 0x3D5);
416 /* Second Display Channel Reset CR6A[6]) */
417 outb(cr6a
& 0xBF, 0x3D5);
418 /* Second Display Channel Enable CR6A[7] */
419 outb(cr6a
| 0x80, 0x3D5);
420 /* Second Display Channel stop reset) */
421 outb(cr6a
| 0xC0, 0x3D5);
423 /* Bit mask of palette */
426 if (UNICHROME_CLE266
== viaparinfo
->chip_info
->gfx_chip_name
&&
429 viafb_write_reg_mask(CR6A
, VIACR
, BIT5
, BIT5
);
430 viafb_write_reg_mask(SR15
, VIASR
, BIT7
, BIT7
);
433 viafb_write_reg_mask(CR6A
, VIACR
, 0, BIT5
);
434 viafb_write_reg_mask(SR15
, VIASR
, 0, BIT7
);
436 for (i
= 0; i
< len
; i
++) {
437 outb((*(pred
+ i
)) >> shift
, 0x3C9);
438 outb((*(pgreen
+ i
)) >> shift
, 0x3C9);
439 outb((*(pblue
+ i
)) >> shift
, 0x3C9);
443 /* Map the 3C6/7/8/9 to the IGA1 */
444 outb(sr1a
& 0xFE, 0x3C5);
445 /* Bit mask of palette */
448 for (i
= 0; i
< len
; i
++) {
449 outb((*(pred
+ i
)) >> shift
, 0x3C9);
450 outb((*(pgreen
+ i
)) >> shift
, 0x3C9);
451 outb((*(pblue
+ i
)) >> shift
, 0x3C9);
465 return 0; /* Because static u32 pseudo_pal[17]; */
466 for (i
= 0; i
< len
; i
++)
467 ((u32
*) info
->pseudo_palette
)[i
] =
468 (*(pred
+ i
) & 0xF800) |
469 ((*(pgreen
+ i
) & 0xFC00) >> 5) |
470 ((*(pblue
+ i
) & 0xF800) >> 11);
476 for (i
= 0; i
< len
; i
++)
477 ((u32
*) info
->pseudo_palette
)[i
] =
478 ((*(ptransp
+ i
) & 0xFF00) << 16) |
479 ((*(pred
+ i
) & 0xFF00) << 8) |
480 ((*(pgreen
+ i
) & 0xFF00)) |
481 ((*(pblue
+ i
) & 0xFF00) >> 8);
483 for (i
= 0; i
< len
; i
++)
484 ((u32
*) info
->pseudo_palette
)[i
] =
486 ((*(pred
+ i
) & 0xFF00) << 8) |
487 ((*(pgreen
+ i
) & 0xFF00)) |
488 ((*(pblue
+ i
) & 0xFF00) >> 8);
495 static int viafb_pan_display(struct fb_var_screeninfo
*var
,
496 struct fb_info
*info
)
500 DEBUG_MSG(KERN_INFO
"viafb_pan_display!\n");
502 offset
= (var
->xoffset
+ (var
->yoffset
* var
->xres_virtual
)) *
503 var
->bits_per_pixel
/ 16;
505 DEBUG_MSG(KERN_INFO
"\nviafb_pan_display,offset =%d ", offset
);
507 viafb_write_reg_mask(0x48, 0x3d4, ((offset
>> 24) & 0x3), 0x3);
508 viafb_write_reg_mask(0x34, 0x3d4, ((offset
>> 16) & 0xff), 0xff);
509 viafb_write_reg_mask(0x0c, 0x3d4, ((offset
>> 8) & 0xff), 0xff);
510 viafb_write_reg_mask(0x0d, 0x3d4, (offset
& 0xff), 0xff);
515 static int viafb_blank(int blank_mode
, struct fb_info
*info
)
517 DEBUG_MSG(KERN_INFO
"viafb_blank!\n");
518 /* clear DPMS setting */
520 switch (blank_mode
) {
521 case FB_BLANK_UNBLANK
:
522 /* Screen: On, HSync: On, VSync: On */
523 /* control CRT monitor power management */
524 viafb_write_reg_mask(CR36
, VIACR
, 0x00, BIT4
+ BIT5
);
526 case FB_BLANK_HSYNC_SUSPEND
:
527 /* Screen: Off, HSync: Off, VSync: On */
528 /* control CRT monitor power management */
529 viafb_write_reg_mask(CR36
, VIACR
, 0x10, BIT4
+ BIT5
);
531 case FB_BLANK_VSYNC_SUSPEND
:
532 /* Screen: Off, HSync: On, VSync: Off */
533 /* control CRT monitor power management */
534 viafb_write_reg_mask(CR36
, VIACR
, 0x20, BIT4
+ BIT5
);
536 case FB_BLANK_POWERDOWN
:
537 /* Screen: Off, HSync: Off, VSync: Off */
538 /* control CRT monitor power management */
539 viafb_write_reg_mask(CR36
, VIACR
, 0x30, BIT4
+ BIT5
);
546 static int viafb_ioctl(struct fb_info
*info
, u_int cmd
, u_long arg
)
549 struct viafb_ioctl_mode viamode
;
550 struct viafb_ioctl_samm viasamm
;
551 struct viafb_driver_version driver_version
;
552 struct fb_var_screeninfo sec_var
;
553 struct _panel_size_pos_info panel_pos_size_para
;
554 struct viafb_ioctl_setting viafb_setting
;
555 struct device_t active_dev
;
558 u32
*viafb_gamma_table
;
559 char driver_name
[] = "viafb";
561 u32 __user
*argp
= (u32 __user
*) arg
;
563 u32 video_dev_info
= 0;
565 DEBUG_MSG(KERN_INFO
"viafb_ioctl: 0x%X !!\n", cmd
);
566 memset(&u
, 0, sizeof(u
));
569 case VIAFB_GET_CHIP_INFO
:
570 if (copy_to_user(argp
, viaparinfo
->chip_info
,
571 sizeof(struct chip_information
)))
574 case VIAFB_GET_INFO_SIZE
:
575 return put_user((u32
)sizeof(struct viafb_ioctl_info
), argp
);
577 return viafb_ioctl_get_viafb_info(arg
);
579 return put_user(viafb_ioctl_hotplug(info
->var
.xres
,
581 info
->var
.bits_per_pixel
), argp
);
582 case VIAFB_SET_HOTPLUG_FLAG
:
583 if (copy_from_user(&gpu32
, argp
, sizeof(gpu32
)))
585 viafb_hotplug
= (gpu32
) ? 1 : 0;
587 case VIAFB_GET_RESOLUTION
:
588 u
.viamode
.xres
= (u32
) viafb_hotplug_Xres
;
589 u
.viamode
.yres
= (u32
) viafb_hotplug_Yres
;
590 u
.viamode
.refresh
= (u32
) viafb_hotplug_refresh
;
591 u
.viamode
.bpp
= (u32
) viafb_hotplug_bpp
;
592 if (viafb_SAMM_ON
== 1) {
593 u
.viamode
.xres_sec
= viafb_second_xres
;
594 u
.viamode
.yres_sec
= viafb_second_yres
;
595 u
.viamode
.virtual_xres_sec
= viafb_second_virtual_xres
;
596 u
.viamode
.virtual_yres_sec
= viafb_second_virtual_yres
;
597 u
.viamode
.refresh_sec
= viafb_refresh1
;
598 u
.viamode
.bpp_sec
= viafb_bpp1
;
600 u
.viamode
.xres_sec
= 0;
601 u
.viamode
.yres_sec
= 0;
602 u
.viamode
.virtual_xres_sec
= 0;
603 u
.viamode
.virtual_yres_sec
= 0;
604 u
.viamode
.refresh_sec
= 0;
605 u
.viamode
.bpp_sec
= 0;
607 if (copy_to_user(argp
, &u
.viamode
, sizeof(u
.viamode
)))
610 case VIAFB_GET_SAMM_INFO
:
611 u
.viasamm
.samm_status
= viafb_SAMM_ON
;
613 if (viafb_SAMM_ON
== 1) {
615 u
.viasamm
.size_prim
= viaparinfo
->fbmem_free
;
616 u
.viasamm
.size_sec
= viaparinfo1
->fbmem_free
;
618 if (viafb_second_size
) {
619 u
.viasamm
.size_prim
=
620 viaparinfo
->fbmem_free
-
621 viafb_second_size
* 1024 * 1024;
623 viafb_second_size
* 1024 * 1024;
625 u
.viasamm
.size_prim
=
626 viaparinfo
->fbmem_free
>> 1;
628 (viaparinfo
->fbmem_free
>> 1);
631 u
.viasamm
.mem_base
= viaparinfo
->fbmem
;
632 u
.viasamm
.offset_sec
= viafb_second_offset
;
634 u
.viasamm
.size_prim
=
635 viaparinfo
->memsize
- viaparinfo
->fbmem_used
;
636 u
.viasamm
.size_sec
= 0;
637 u
.viasamm
.mem_base
= viaparinfo
->fbmem
;
638 u
.viasamm
.offset_sec
= 0;
641 if (copy_to_user(argp
, &u
.viasamm
, sizeof(u
.viasamm
)))
645 case VIAFB_TURN_ON_OUTPUT_DEVICE
:
646 if (copy_from_user(&gpu32
, argp
, sizeof(gpu32
)))
648 if (gpu32
& CRT_Device
)
650 if (gpu32
& DVI_Device
)
652 if (gpu32
& LCD_Device
)
655 case VIAFB_TURN_OFF_OUTPUT_DEVICE
:
656 if (copy_from_user(&gpu32
, argp
, sizeof(gpu32
)))
658 if (gpu32
& CRT_Device
)
660 if (gpu32
& DVI_Device
)
662 if (gpu32
& LCD_Device
)
665 case VIAFB_SET_DEVICE
:
666 if (copy_from_user(&u
.active_dev
, (void *)argp
,
667 sizeof(u
.active_dev
)))
669 viafb_set_device(u
.active_dev
);
672 case VIAFB_GET_DEVICE
:
673 u
.active_dev
.crt
= viafb_CRT_ON
;
674 u
.active_dev
.dvi
= viafb_DVI_ON
;
675 u
.active_dev
.lcd
= viafb_LCD_ON
;
676 u
.active_dev
.samm
= viafb_SAMM_ON
;
677 u
.active_dev
.primary_dev
= viafb_primary_dev
;
679 u
.active_dev
.lcd_dsp_cent
= viafb_lcd_dsp_method
;
680 u
.active_dev
.lcd_panel_id
= viafb_lcd_panel_id
;
681 u
.active_dev
.lcd_mode
= viafb_lcd_mode
;
683 u
.active_dev
.xres
= viafb_hotplug_Xres
;
684 u
.active_dev
.yres
= viafb_hotplug_Yres
;
686 u
.active_dev
.xres1
= viafb_second_xres
;
687 u
.active_dev
.yres1
= viafb_second_yres
;
689 u
.active_dev
.bpp
= viafb_bpp
;
690 u
.active_dev
.bpp1
= viafb_bpp1
;
691 u
.active_dev
.refresh
= viafb_refresh
;
692 u
.active_dev
.refresh1
= viafb_refresh1
;
694 u
.active_dev
.epia_dvi
= viafb_platform_epia_dvi
;
695 u
.active_dev
.lcd_dual_edge
= viafb_device_lcd_dualedge
;
696 u
.active_dev
.bus_width
= viafb_bus_width
;
698 if (copy_to_user(argp
, &u
.active_dev
, sizeof(u
.active_dev
)))
702 case VIAFB_GET_DRIVER_VERSION
:
703 u
.driver_version
.iMajorNum
= VERSION_MAJOR
;
704 u
.driver_version
.iKernelNum
= VERSION_KERNEL
;
705 u
.driver_version
.iOSNum
= VERSION_OS
;
706 u
.driver_version
.iMinorNum
= VERSION_MINOR
;
708 if (copy_to_user(argp
, &u
.driver_version
,
709 sizeof(u
.driver_version
)))
714 case VIAFB_SET_DEVICE_INFO
:
715 if (copy_from_user(&u
.viafb_setting
,
716 argp
, sizeof(u
.viafb_setting
)))
718 if (apply_device_setting(u
.viafb_setting
, info
) < 0)
723 case VIAFB_SET_SECOND_MODE
:
724 if (copy_from_user(&u
.sec_var
, argp
, sizeof(u
.sec_var
)))
726 apply_second_mode_setting(&u
.sec_var
);
729 case VIAFB_GET_DEVICE_INFO
:
731 retrieve_device_setting(&u
.viafb_setting
);
733 if (copy_to_user(argp
, &u
.viafb_setting
,
734 sizeof(u
.viafb_setting
)))
739 case VIAFB_GET_DEVICE_SUPPORT
:
740 viafb_get_device_support_state(&state_info
);
741 if (put_user(state_info
, argp
))
745 case VIAFB_GET_DEVICE_CONNECT
:
746 viafb_get_device_connect_state(&state_info
);
747 if (put_user(state_info
, argp
))
751 case VIAFB_GET_PANEL_SUPPORT_EXPAND
:
753 viafb_lcd_get_support_expand_state(info
->var
.xres
,
755 if (put_user(state_info
, argp
))
759 case VIAFB_GET_DRIVER_NAME
:
760 if (copy_to_user(argp
, driver_name
, sizeof(driver_name
)))
764 case VIAFB_SET_GAMMA_LUT
:
765 viafb_gamma_table
= kmalloc(256 * sizeof(u32
), GFP_KERNEL
);
766 if (!viafb_gamma_table
)
768 if (copy_from_user(viafb_gamma_table
, argp
,
769 sizeof(viafb_gamma_table
))) {
770 kfree(viafb_gamma_table
);
773 viafb_set_gamma_table(viafb_bpp
, viafb_gamma_table
);
774 kfree(viafb_gamma_table
);
777 case VIAFB_GET_GAMMA_LUT
:
778 viafb_gamma_table
= kmalloc(256 * sizeof(u32
), GFP_KERNEL
);
779 if (!viafb_gamma_table
)
781 viafb_get_gamma_table(viafb_gamma_table
);
782 if (copy_to_user(argp
, viafb_gamma_table
,
783 sizeof(viafb_gamma_table
))) {
784 kfree(viafb_gamma_table
);
787 kfree(viafb_gamma_table
);
790 case VIAFB_GET_GAMMA_SUPPORT_STATE
:
791 viafb_get_gamma_support_state(viafb_bpp
, &state_info
);
792 if (put_user(state_info
, argp
))
795 case VIAFB_SET_VIDEO_DEVICE
:
796 get_user(video_dev_info
, argp
);
797 viafb_set_video_device(video_dev_info
);
799 case VIAFB_GET_VIDEO_DEVICE
:
800 viafb_get_video_device(&video_dev_info
);
801 if (put_user(video_dev_info
, argp
))
804 case VIAFB_SYNC_SURFACE
:
805 DEBUG_MSG(KERN_INFO
"lobo VIAFB_SYNC_SURFACE\n");
807 case VIAFB_GET_DRIVER_CAPS
:
810 case VIAFB_GET_PANEL_MAX_SIZE
:
811 if (copy_from_user(&u
.panel_pos_size_para
, argp
,
812 sizeof(u
.panel_pos_size_para
)))
814 u
.panel_pos_size_para
.x
= u
.panel_pos_size_para
.y
= 0;
815 if (copy_to_user(argp
, &u
.panel_pos_size_para
,
816 sizeof(u
.panel_pos_size_para
)))
819 case VIAFB_GET_PANEL_MAX_POSITION
:
820 if (copy_from_user(&u
.panel_pos_size_para
, argp
,
821 sizeof(u
.panel_pos_size_para
)))
823 u
.panel_pos_size_para
.x
= u
.panel_pos_size_para
.y
= 0;
824 if (copy_to_user(argp
, &u
.panel_pos_size_para
,
825 sizeof(u
.panel_pos_size_para
)))
829 case VIAFB_GET_PANEL_POSITION
:
830 if (copy_from_user(&u
.panel_pos_size_para
, argp
,
831 sizeof(u
.panel_pos_size_para
)))
833 u
.panel_pos_size_para
.x
= u
.panel_pos_size_para
.y
= 0;
834 if (copy_to_user(argp
, &u
.panel_pos_size_para
,
835 sizeof(u
.panel_pos_size_para
)))
838 case VIAFB_GET_PANEL_SIZE
:
839 if (copy_from_user(&u
.panel_pos_size_para
, argp
,
840 sizeof(u
.panel_pos_size_para
)))
842 u
.panel_pos_size_para
.x
= u
.panel_pos_size_para
.y
= 0;
843 if (copy_to_user(argp
, &u
.panel_pos_size_para
,
844 sizeof(u
.panel_pos_size_para
)))
848 case VIAFB_SET_PANEL_POSITION
:
849 if (copy_from_user(&u
.panel_pos_size_para
, argp
,
850 sizeof(u
.panel_pos_size_para
)))
853 case VIAFB_SET_PANEL_SIZE
:
854 if (copy_from_user(&u
.panel_pos_size_para
, argp
,
855 sizeof(u
.panel_pos_size_para
)))
866 static void viafb_fillrect(struct fb_info
*info
,
867 const struct fb_fillrect
*rect
)
869 u32 col
= 0, rop
= 0;
873 cfb_fillrect(info
, rect
);
877 if (!rect
->width
|| !rect
->height
)
890 switch (info
->var
.bits_per_pixel
) {
895 col
= ((u32
*) (info
->pseudo_palette
))[rect
->color
];
898 col
= ((u32
*) (info
->pseudo_palette
))[rect
->color
];
902 /* BitBlt Source Address */
903 writel(0x0, viaparinfo
->io_virt
+ VIA_REG_SRCPOS
);
904 /* Source Base Address */
905 writel(0x0, viaparinfo
->io_virt
+ VIA_REG_SRCBASE
);
906 /* Destination Base Address */
907 writel(((unsigned long) (info
->screen_base
) -
908 (unsigned long) viafb_FB_MM
) >> 3,
909 viaparinfo
->io_virt
+ VIA_REG_DSTBASE
);
911 pitch
= (info
->var
.xres_virtual
+ 7) & ~7;
912 writel(VIA_PITCH_ENABLE
|
914 info
->var
.bits_per_pixel
>> 3) >> 3) |
916 var
.bits_per_pixel
>> 3) >> 3) << 16)),
917 viaparinfo
->io_virt
+ VIA_REG_PITCH
);
918 /* BitBlt Destination Address */
919 writel(((rect
->dy
<< 16) | rect
->dx
),
920 viaparinfo
->io_virt
+ VIA_REG_DSTPOS
);
921 /* Dimension: width & height */
922 writel((((rect
->height
- 1) << 16) | (rect
->width
- 1)),
923 viaparinfo
->io_virt
+ VIA_REG_DIMENSION
);
924 /* Forground color or Destination color */
925 writel(col
, viaparinfo
->io_virt
+ VIA_REG_FGCOLOR
);
927 writel((0x01 | 0x2000 | (rop
<< 24)),
928 viaparinfo
->io_virt
+ VIA_REG_GECMD
);
932 static void viafb_copyarea(struct fb_info
*info
,
933 const struct fb_copyarea
*area
)
935 u32 dy
= area
->dy
, sy
= area
->sy
, direction
= 0x0;
936 u32 sx
= area
->sx
, dx
= area
->dx
, width
= area
->width
;
939 DEBUG_MSG(KERN_INFO
"viafb_copyarea!!\n");
942 cfb_copyarea(info
, area
);
946 if (!area
->width
|| !area
->height
)
950 dy
+= area
->height
- 1;
951 sy
+= area
->height
- 1;
961 /* Source Base Address */
962 writel(((unsigned long) (info
->screen_base
) -
963 (unsigned long) viafb_FB_MM
) >> 3,
964 viaparinfo
->io_virt
+ VIA_REG_SRCBASE
);
965 /* Destination Base Address */
966 writel(((unsigned long) (info
->screen_base
) -
967 (unsigned long) viafb_FB_MM
) >> 3,
968 viaparinfo
->io_virt
+ VIA_REG_DSTBASE
);
970 pitch
= (info
->var
.xres_virtual
+ 7) & ~7;
971 /* VIA_PITCH_ENABLE can be omitted now. */
972 writel(VIA_PITCH_ENABLE
|
974 info
->var
.bits_per_pixel
>> 3) >> 3) | (((pitch
*
979 viaparinfo
->io_virt
+ VIA_REG_PITCH
);
980 /* BitBlt Source Address */
981 writel(((sy
<< 16) | sx
), viaparinfo
->io_virt
+ VIA_REG_SRCPOS
);
982 /* BitBlt Destination Address */
983 writel(((dy
<< 16) | dx
), viaparinfo
->io_virt
+ VIA_REG_DSTPOS
);
984 /* Dimension: width & height */
985 writel((((area
->height
- 1) << 16) | (area
->width
- 1)),
986 viaparinfo
->io_virt
+ VIA_REG_DIMENSION
);
988 writel((0x01 | direction
| (0xCC << 24)),
989 viaparinfo
->io_virt
+ VIA_REG_GECMD
);
993 static void viafb_imageblit(struct fb_info
*info
,
994 const struct fb_image
*image
)
996 u32 size
, bg_col
= 0, fg_col
= 0, *udata
;
1001 cfb_imageblit(info
, image
);
1005 udata
= (u32
*) image
->data
;
1007 switch (info
->var
.bits_per_pixel
) {
1009 bg_col
= image
->bg_color
;
1010 fg_col
= image
->fg_color
;
1013 bg_col
= ((u32
*) (info
->pseudo_palette
))[image
->bg_color
];
1014 fg_col
= ((u32
*) (info
->pseudo_palette
))[image
->fg_color
];
1017 bg_col
= ((u32
*) (info
->pseudo_palette
))[image
->bg_color
];
1018 fg_col
= ((u32
*) (info
->pseudo_palette
))[image
->fg_color
];
1021 size
= image
->width
* image
->height
;
1023 /* Source Base Address */
1024 writel(0x0, viaparinfo
->io_virt
+ VIA_REG_SRCBASE
);
1025 /* Destination Base Address */
1026 writel(((unsigned long) (info
->screen_base
) -
1027 (unsigned long) viafb_FB_MM
) >> 3,
1028 viaparinfo
->io_virt
+ VIA_REG_DSTBASE
);
1030 pitch
= (info
->var
.xres_virtual
+ 7) & ~7;
1031 writel(VIA_PITCH_ENABLE
|
1033 info
->var
.bits_per_pixel
>> 3) >> 3) | (((pitch
*
1038 viaparinfo
->io_virt
+ VIA_REG_PITCH
);
1039 /* BitBlt Source Address */
1040 writel(0x0, viaparinfo
->io_virt
+ VIA_REG_SRCPOS
);
1041 /* BitBlt Destination Address */
1042 writel(((image
->dy
<< 16) | image
->dx
),
1043 viaparinfo
->io_virt
+ VIA_REG_DSTPOS
);
1044 /* Dimension: width & height */
1045 writel((((image
->height
- 1) << 16) | (image
->width
- 1)),
1046 viaparinfo
->io_virt
+ VIA_REG_DIMENSION
);
1048 writel(fg_col
, viaparinfo
->io_virt
+ VIA_REG_FGCOLOR
);
1050 writel(bg_col
, viaparinfo
->io_virt
+ VIA_REG_BGCOLOR
);
1052 writel(0xCC020142, viaparinfo
->io_virt
+ VIA_REG_GECMD
);
1054 for (i
= 0; i
< size
/ 4; i
++) {
1055 writel(*udata
, viaparinfo
->io_virt
+ VIA_MMIO_BLTBASE
);
1061 static int viafb_cursor(struct fb_info
*info
, struct fb_cursor
*cursor
)
1063 u32 temp
, xx
, yy
, bg_col
= 0, fg_col
= 0;
1065 static int hw_cursor
;
1066 struct viafb_par
*p_viafb_par
;
1073 viafb_show_hw_cursor(info
, HW_Cursor_OFF
);
1079 if ((((struct viafb_par
*)(info
->par
))->iga_path
== IGA2
)
1080 && (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_CLE266
))
1083 /* When duoview and using lcd , use soft cursor */
1084 if (viafb_LCD_ON
|| ((struct viafb_par
*)(info
->par
))->duoview
)
1087 viafb_show_hw_cursor(info
, HW_Cursor_OFF
);
1088 viacursor
= *cursor
;
1090 if (cursor
->set
& FB_CUR_SETHOT
) {
1091 viacursor
.hot
= cursor
->hot
;
1092 temp
= ((viacursor
.hot
.x
) << 16) + viacursor
.hot
.y
;
1093 writel(temp
, viaparinfo
->io_virt
+ VIA_REG_CURSOR_ORG
);
1096 if (cursor
->set
& FB_CUR_SETPOS
) {
1097 viacursor
.image
.dx
= cursor
->image
.dx
;
1098 viacursor
.image
.dy
= cursor
->image
.dy
;
1099 yy
= cursor
->image
.dy
- info
->var
.yoffset
;
1100 xx
= cursor
->image
.dx
- info
->var
.xoffset
;
1103 writel(temp
, viaparinfo
->io_virt
+ VIA_REG_CURSOR_POS
);
1106 if (cursor
->set
& FB_CUR_SETSIZE
) {
1107 temp
= readl(viaparinfo
->io_virt
+ VIA_REG_CURSOR_MODE
);
1109 if ((cursor
->image
.width
<= 32)
1110 && (cursor
->image
.height
<= 32)) {
1113 } else if ((cursor
->image
.width
<= 64)
1114 && (cursor
->image
.height
<= 64)) {
1119 "The cursor image is biger than 64x64 bits...\n");
1122 writel(temp
, viaparinfo
->io_virt
+ VIA_REG_CURSOR_MODE
);
1124 viacursor
.image
.height
= cursor
->image
.height
;
1125 viacursor
.image
.width
= cursor
->image
.width
;
1128 if (cursor
->set
& FB_CUR_SETCMAP
) {
1129 viacursor
.image
.fg_color
= cursor
->image
.fg_color
;
1130 viacursor
.image
.bg_color
= cursor
->image
.bg_color
;
1132 switch (info
->var
.bits_per_pixel
) {
1138 (((info
->cmap
.red
)[viacursor
.image
.bg_color
] &
1140 ((info
->cmap
.green
)[viacursor
.image
.bg_color
] &
1142 (((info
->cmap
.blue
)[viacursor
.image
.bg_color
] &
1146 (((info
->cmap
.red
)[viacursor
.image
.fg_color
] &
1148 ((info
->cmap
.green
)[viacursor
.image
.fg_color
] &
1150 (((info
->cmap
.blue
)[viacursor
.image
.fg_color
] &
1157 /* This is indeed a patch for VT3324/VT3353 */
1160 p_viafb_par
= (struct viafb_par
*)info
->par
;
1162 if ((p_viafb_par
->chip_info
->gfx_chip_name
==
1164 ((p_viafb_par
->chip_info
->gfx_chip_name
==
1165 UNICHROME_VX800
))) {
1167 (((info
->cmap
.red
)[viacursor
.image
.bg_color
] &
1169 (((info
->cmap
.green
)[viacursor
.image
.bg_color
] &
1171 (((info
->cmap
.blue
)[viacursor
.image
.bg_color
] &
1174 (((info
->cmap
.red
)[viacursor
.image
.fg_color
] &
1176 (((info
->cmap
.green
)[viacursor
.image
.fg_color
] &
1178 (((info
->cmap
.blue
)[viacursor
.image
.fg_color
] &
1182 writel(bg_col
, viaparinfo
->io_virt
+ VIA_REG_CURSOR_BG
);
1183 writel(fg_col
, viaparinfo
->io_virt
+ VIA_REG_CURSOR_FG
);
1186 if (cursor
->set
& FB_CUR_SETSHAPE
) {
1188 u8 data
[CURSOR_SIZE
/ 8];
1189 u32 bak
[CURSOR_SIZE
/ 32];
1190 } *cr_data
= kzalloc(sizeof(*cr_data
), GFP_ATOMIC
);
1192 ((viacursor
.image
.width
+ 7) >> 3) *
1193 viacursor
.image
.height
;
1195 if (cr_data
== NULL
)
1198 if (MAX_CURS
== 32) {
1199 for (i
= 0; i
< (CURSOR_SIZE
/ 32); i
++) {
1200 cr_data
->bak
[i
] = 0x0;
1201 cr_data
->bak
[i
+ 1] = 0xFFFFFFFF;
1204 } else if (MAX_CURS
== 64) {
1205 for (i
= 0; i
< (CURSOR_SIZE
/ 32); i
++) {
1206 cr_data
->bak
[i
] = 0x0;
1207 cr_data
->bak
[i
+ 1] = 0x0;
1208 cr_data
->bak
[i
+ 2] = 0xFFFFFFFF;
1209 cr_data
->bak
[i
+ 3] = 0xFFFFFFFF;
1214 switch (viacursor
.rop
) {
1216 for (i
= 0; i
< size
; i
++)
1217 cr_data
->data
[i
] = viacursor
.mask
[i
];
1221 for (i
= 0; i
< size
; i
++)
1222 cr_data
->data
[i
] = viacursor
.mask
[i
];
1228 if (MAX_CURS
== 32) {
1229 for (i
= 0; i
< size
; i
++) {
1230 cr_data
->bak
[j
] = (u32
) cr_data
->data
[i
];
1231 cr_data
->bak
[j
+ 1] = ~cr_data
->bak
[j
];
1234 } else if (MAX_CURS
== 64) {
1235 for (i
= 0; i
< size
; i
++) {
1236 cr_data
->bak
[j
] = (u32
) cr_data
->data
[i
];
1237 cr_data
->bak
[j
+ 1] = 0x0;
1238 cr_data
->bak
[j
+ 2] = ~cr_data
->bak
[j
];
1239 cr_data
->bak
[j
+ 3] = ~cr_data
->bak
[j
+ 1];
1244 memcpy(((struct viafb_par
*)(info
->par
))->fbmem_virt
+
1245 ((struct viafb_par
*)(info
->par
))->cursor_start
,
1246 cr_data
->bak
, CURSOR_SIZE
);
1251 if (viacursor
.enable
)
1252 viafb_show_hw_cursor(info
, HW_Cursor_ON
);
1257 static int viafb_sync(struct fb_info
*info
)
1260 viafb_wait_engine_idle();
1264 int viafb_get_mode_index(int hres
, int vres
)
1267 DEBUG_MSG(KERN_INFO
"viafb_get_mode_index!\n");
1269 for (i
= 0; viafb_modentry
[i
].mode_index
!= VIA_RES_INVALID
; i
++)
1270 if (viafb_modentry
[i
].xres
== hres
&&
1271 viafb_modentry
[i
].yres
== vres
)
1274 return viafb_modentry
[i
].mode_index
;
1277 static void check_available_device_to_enable(int device_id
)
1282 viafb_CRT_ON
= STATE_OFF
;
1283 viafb_DVI_ON
= STATE_OFF
;
1284 viafb_LCD_ON
= STATE_OFF
;
1285 viafb_LCD2_ON
= STATE_OFF
;
1286 viafb_DeviceStatus
= None_Device
;
1288 if ((device_id
& CRT_Device
) && (device_num
< MAX_ACTIVE_DEV_NUM
)) {
1289 viafb_CRT_ON
= STATE_ON
;
1291 viafb_DeviceStatus
|= CRT_Device
;
1294 if ((device_id
& DVI_Device
) && (device_num
< MAX_ACTIVE_DEV_NUM
)) {
1295 viafb_DVI_ON
= STATE_ON
;
1297 viafb_DeviceStatus
|= DVI_Device
;
1300 if ((device_id
& LCD_Device
) && (device_num
< MAX_ACTIVE_DEV_NUM
)) {
1301 viafb_LCD_ON
= STATE_ON
;
1303 viafb_DeviceStatus
|= LCD_Device
;
1306 if ((device_id
& LCD2_Device
) && (device_num
< MAX_ACTIVE_DEV_NUM
)) {
1307 viafb_LCD2_ON
= STATE_ON
;
1309 viafb_DeviceStatus
|= LCD2_Device
;
1312 if (viafb_DeviceStatus
== None_Device
) {
1313 /* Use CRT as default active device: */
1314 viafb_CRT_ON
= STATE_ON
;
1315 viafb_DeviceStatus
= CRT_Device
;
1317 DEBUG_MSG(KERN_INFO
"Device Status:%x", viafb_DeviceStatus
);
1320 static void viafb_set_device(struct device_t active_dev
)
1322 /* Check available device to enable: */
1323 int device_id
= None_Device
;
1325 device_id
|= CRT_Device
;
1327 device_id
|= DVI_Device
;
1329 device_id
|= LCD_Device
;
1331 check_available_device_to_enable(device_id
);
1333 /* Check property of LCD: */
1335 if (active_dev
.lcd_dsp_cent
) {
1336 viaparinfo
->lvds_setting_info
->display_method
=
1337 viafb_lcd_dsp_method
= LCD_CENTERING
;
1339 viaparinfo
->lvds_setting_info
->display_method
=
1340 viafb_lcd_dsp_method
= LCD_EXPANDSION
;
1343 if (active_dev
.lcd_mode
== LCD_SPWG
) {
1344 viaparinfo
->lvds_setting_info
->lcd_mode
=
1345 viafb_lcd_mode
= LCD_SPWG
;
1347 viaparinfo
->lvds_setting_info
->lcd_mode
=
1348 viafb_lcd_mode
= LCD_OPENLDI
;
1351 if (active_dev
.lcd_panel_id
<= LCD_PANEL_ID_MAXIMUM
) {
1352 viafb_lcd_panel_id
= active_dev
.lcd_panel_id
;
1353 viafb_init_lcd_size();
1357 /* Check property of mode: */
1358 if (!active_dev
.xres1
)
1359 viafb_second_xres
= 640;
1361 viafb_second_xres
= active_dev
.xres1
;
1362 if (!active_dev
.yres1
)
1363 viafb_second_yres
= 480;
1365 viafb_second_yres
= active_dev
.yres1
;
1366 if (active_dev
.bpp
!= 0)
1367 viafb_bpp
= active_dev
.bpp
;
1368 if (active_dev
.bpp1
!= 0)
1369 viafb_bpp1
= active_dev
.bpp1
;
1370 if (active_dev
.refresh
!= 0)
1371 viafb_refresh
= active_dev
.refresh
;
1372 if (active_dev
.refresh1
!= 0)
1373 viafb_refresh1
= active_dev
.refresh1
;
1374 if ((active_dev
.samm
== STATE_OFF
) || (active_dev
.samm
== STATE_ON
))
1375 viafb_SAMM_ON
= active_dev
.samm
;
1376 viafb_primary_dev
= active_dev
.primary_dev
;
1378 viafb_set_start_addr();
1379 viafb_set_iga_path();
1382 static void viafb_set_video_device(u32 video_dev_info
)
1384 viaparinfo
->video_on_crt
= STATE_OFF
;
1385 viaparinfo
->video_on_dvi
= STATE_OFF
;
1386 viaparinfo
->video_on_lcd
= STATE_OFF
;
1388 /* Check available device to enable: */
1389 if ((video_dev_info
& CRT_Device
) == CRT_Device
)
1390 viaparinfo
->video_on_crt
= STATE_ON
;
1391 else if ((video_dev_info
& DVI_Device
) == DVI_Device
)
1392 viaparinfo
->video_on_dvi
= STATE_ON
;
1393 else if ((video_dev_info
& LCD_Device
) == LCD_Device
)
1394 viaparinfo
->video_on_lcd
= STATE_ON
;
1397 static void viafb_get_video_device(u32
*video_dev_info
)
1399 *video_dev_info
= None_Device
;
1400 if (viaparinfo
->video_on_crt
== STATE_ON
)
1401 *video_dev_info
|= CRT_Device
;
1402 else if (viaparinfo
->video_on_dvi
== STATE_ON
)
1403 *video_dev_info
|= DVI_Device
;
1404 else if (viaparinfo
->video_on_lcd
== STATE_ON
)
1405 *video_dev_info
|= LCD_Device
;
1408 static int get_primary_device(void)
1410 int primary_device
= 0;
1411 /* Rule: device on iga1 path are the primary device. */
1412 if (viafb_SAMM_ON
) {
1414 if (viaparinfo
->crt_setting_info
->iga_path
== IGA1
) {
1415 DEBUG_MSG(KERN_INFO
"CRT IGA Path:%d\n",
1417 crt_setting_info
->iga_path
);
1418 primary_device
= CRT_Device
;
1422 if (viaparinfo
->tmds_setting_info
->iga_path
== IGA1
) {
1423 DEBUG_MSG(KERN_INFO
"DVI IGA Path:%d\n",
1425 tmds_setting_info
->iga_path
);
1426 primary_device
= DVI_Device
;
1430 if (viaparinfo
->lvds_setting_info
->iga_path
== IGA1
) {
1431 DEBUG_MSG(KERN_INFO
"LCD IGA Path:%d\n",
1433 lvds_setting_info
->iga_path
);
1434 primary_device
= LCD_Device
;
1437 if (viafb_LCD2_ON
) {
1438 if (viaparinfo
->lvds_setting_info2
->iga_path
== IGA1
) {
1439 DEBUG_MSG(KERN_INFO
"LCD2 IGA Path:%d\n",
1441 lvds_setting_info2
->iga_path
);
1442 primary_device
= LCD2_Device
;
1446 return primary_device
;
1449 static u8
is_duoview(void)
1451 if (0 == viafb_SAMM_ON
) {
1452 if (viafb_LCD_ON
+ viafb_LCD2_ON
+
1453 viafb_DVI_ON
+ viafb_CRT_ON
== 2)
1461 static void apply_second_mode_setting(struct fb_var_screeninfo
1464 u32 htotal
, vtotal
, long_refresh
;
1466 htotal
= sec_var
->xres
+ sec_var
->left_margin
+
1467 sec_var
->right_margin
+ sec_var
->hsync_len
;
1468 vtotal
= sec_var
->yres
+ sec_var
->upper_margin
+
1469 sec_var
->lower_margin
+ sec_var
->vsync_len
;
1470 if ((sec_var
->xres_virtual
* (sec_var
->bits_per_pixel
>> 3)) & 0x1F) {
1471 /*Is 32 bytes alignment? */
1472 /*32 pixel alignment */
1473 sec_var
->xres_virtual
= (sec_var
->xres_virtual
+ 31) & ~31;
1476 htotal
= sec_var
->xres
+ sec_var
->left_margin
+
1477 sec_var
->right_margin
+ sec_var
->hsync_len
;
1478 vtotal
= sec_var
->yres
+ sec_var
->upper_margin
+
1479 sec_var
->lower_margin
+ sec_var
->vsync_len
;
1480 long_refresh
= 1000000000UL / sec_var
->pixclock
* 1000;
1481 long_refresh
/= (htotal
* vtotal
);
1483 viafb_second_xres
= sec_var
->xres
;
1484 viafb_second_yres
= sec_var
->yres
;
1485 viafb_second_virtual_xres
= sec_var
->xres_virtual
;
1486 viafb_second_virtual_yres
= sec_var
->yres_virtual
;
1487 viafb_bpp1
= sec_var
->bits_per_pixel
;
1488 viafb_refresh1
= viafb_get_refresh(sec_var
->xres
, sec_var
->yres
,
1492 static int apply_device_setting(struct viafb_ioctl_setting setting_info
,
1493 struct fb_info
*info
)
1495 int need_set_mode
= 0;
1496 DEBUG_MSG(KERN_INFO
"apply_device_setting\n");
1498 if (setting_info
.device_flag
) {
1500 check_available_device_to_enable(setting_info
.device_status
);
1503 /* Unlock LCD's operation according to LCD flag
1504 and check if the setting value is valid. */
1505 /* If the value is valid, apply the new setting value to the device. */
1507 if (setting_info
.lcd_operation_flag
& OP_LCD_CENTERING
) {
1509 if (setting_info
.lcd_attributes
.display_center
) {
1511 viaparinfo
->lvds_setting_info
->display_method
=
1513 viafb_lcd_dsp_method
= LCD_CENTERING
;
1514 viaparinfo
->lvds_setting_info2
->display_method
=
1515 viafb_lcd_dsp_method
= LCD_CENTERING
;
1518 viaparinfo
->lvds_setting_info
->display_method
=
1520 viafb_lcd_dsp_method
= LCD_EXPANDSION
;
1521 viaparinfo
->lvds_setting_info2
->display_method
=
1523 viafb_lcd_dsp_method
= LCD_EXPANDSION
;
1527 if (setting_info
.lcd_operation_flag
& OP_LCD_MODE
) {
1529 if (setting_info
.lcd_attributes
.lcd_mode
==
1531 viaparinfo
->lvds_setting_info
->lcd_mode
=
1532 viafb_lcd_mode
= LCD_SPWG
;
1534 viaparinfo
->lvds_setting_info
->lcd_mode
=
1535 viafb_lcd_mode
= LCD_OPENLDI
;
1537 viaparinfo
->lvds_setting_info2
->lcd_mode
=
1538 viaparinfo
->lvds_setting_info
->lcd_mode
;
1541 if (setting_info
.lcd_operation_flag
& OP_LCD_PANEL_ID
) {
1543 if (setting_info
.lcd_attributes
.panel_id
<=
1544 LCD_PANEL_ID_MAXIMUM
) {
1545 viafb_lcd_panel_id
=
1546 setting_info
.lcd_attributes
.panel_id
;
1547 viafb_init_lcd_size();
1552 if (0 != (setting_info
.samm_status
& OP_SAMM
)) {
1553 setting_info
.samm_status
=
1554 setting_info
.samm_status
& (~OP_SAMM
);
1555 if (setting_info
.samm_status
== 0
1556 || setting_info
.samm_status
== 1) {
1557 viafb_SAMM_ON
= setting_info
.samm_status
;
1560 viafb_primary_dev
= setting_info
.primary_device
;
1562 viafb_set_start_addr();
1563 viafb_set_iga_path();
1568 viaparinfo
->duoview
= is_duoview();
1570 if (!need_set_mode
) {
1573 viafb_set_iga_path();
1574 viafb_set_par(info
);
1579 static void retrieve_device_setting(struct viafb_ioctl_setting
1583 /* get device status */
1584 if (viafb_CRT_ON
== 1)
1585 setting_info
->device_status
= CRT_Device
;
1586 if (viafb_DVI_ON
== 1)
1587 setting_info
->device_status
|= DVI_Device
;
1588 if (viafb_LCD_ON
== 1)
1589 setting_info
->device_status
|= LCD_Device
;
1590 if (viafb_LCD2_ON
== 1)
1591 setting_info
->device_status
|= LCD2_Device
;
1592 if ((viaparinfo
->video_on_crt
== 1) && (viafb_CRT_ON
== 1)) {
1593 setting_info
->video_device_status
=
1594 viaparinfo
->crt_setting_info
->iga_path
;
1595 } else if ((viaparinfo
->video_on_dvi
== 1) && (viafb_DVI_ON
== 1)) {
1596 setting_info
->video_device_status
=
1597 viaparinfo
->tmds_setting_info
->iga_path
;
1598 } else if ((viaparinfo
->video_on_lcd
== 1) && (viafb_LCD_ON
== 1)) {
1599 setting_info
->video_device_status
=
1600 viaparinfo
->lvds_setting_info
->iga_path
;
1602 setting_info
->video_device_status
= 0;
1605 setting_info
->samm_status
= viafb_SAMM_ON
;
1606 setting_info
->primary_device
= get_primary_device();
1608 setting_info
->first_dev_bpp
= viafb_bpp
;
1609 setting_info
->second_dev_bpp
= viafb_bpp1
;
1611 setting_info
->first_dev_refresh
= viafb_refresh
;
1612 setting_info
->second_dev_refresh
= viafb_refresh1
;
1614 setting_info
->first_dev_hor_res
= viafb_hotplug_Xres
;
1615 setting_info
->first_dev_ver_res
= viafb_hotplug_Yres
;
1616 setting_info
->second_dev_hor_res
= viafb_second_xres
;
1617 setting_info
->second_dev_ver_res
= viafb_second_yres
;
1619 /* Get lcd attributes */
1620 setting_info
->lcd_attributes
.display_center
= viafb_lcd_dsp_method
;
1621 setting_info
->lcd_attributes
.panel_id
= viafb_lcd_panel_id
;
1622 setting_info
->lcd_attributes
.lcd_mode
= viafb_lcd_mode
;
1625 static void parse_active_dev(void)
1627 viafb_CRT_ON
= STATE_OFF
;
1628 viafb_DVI_ON
= STATE_OFF
;
1629 viafb_LCD_ON
= STATE_OFF
;
1630 viafb_LCD2_ON
= STATE_OFF
;
1631 /* 1. Modify the active status of devices. */
1632 /* 2. Keep the order of devices, so we can set corresponding
1633 IGA path to devices in SAMM case. */
1634 /* Note: The previous of active_dev is primary device,
1635 and the following is secondary device. */
1636 if (!strncmp(viafb_active_dev
, "CRT+DVI", 7)) {
1638 viafb_CRT_ON
= STATE_ON
;
1639 viafb_DVI_ON
= STATE_ON
;
1640 viafb_primary_dev
= CRT_Device
;
1641 } else if (!strncmp(viafb_active_dev
, "DVI+CRT", 7)) {
1643 viafb_CRT_ON
= STATE_ON
;
1644 viafb_DVI_ON
= STATE_ON
;
1645 viafb_primary_dev
= DVI_Device
;
1646 } else if (!strncmp(viafb_active_dev
, "CRT+LCD", 7)) {
1648 viafb_CRT_ON
= STATE_ON
;
1649 viafb_LCD_ON
= STATE_ON
;
1650 viafb_primary_dev
= CRT_Device
;
1651 } else if (!strncmp(viafb_active_dev
, "LCD+CRT", 7)) {
1653 viafb_CRT_ON
= STATE_ON
;
1654 viafb_LCD_ON
= STATE_ON
;
1655 viafb_primary_dev
= LCD_Device
;
1656 } else if (!strncmp(viafb_active_dev
, "DVI+LCD", 7)) {
1658 viafb_DVI_ON
= STATE_ON
;
1659 viafb_LCD_ON
= STATE_ON
;
1660 viafb_primary_dev
= DVI_Device
;
1661 } else if (!strncmp(viafb_active_dev
, "LCD+DVI", 7)) {
1663 viafb_DVI_ON
= STATE_ON
;
1664 viafb_LCD_ON
= STATE_ON
;
1665 viafb_primary_dev
= LCD_Device
;
1666 } else if (!strncmp(viafb_active_dev
, "LCD+LCD2", 8)) {
1667 viafb_LCD_ON
= STATE_ON
;
1668 viafb_LCD2_ON
= STATE_ON
;
1669 viafb_primary_dev
= LCD_Device
;
1670 } else if (!strncmp(viafb_active_dev
, "LCD2+LCD", 8)) {
1671 viafb_LCD_ON
= STATE_ON
;
1672 viafb_LCD2_ON
= STATE_ON
;
1673 viafb_primary_dev
= LCD2_Device
;
1674 } else if (!strncmp(viafb_active_dev
, "CRT", 3)) {
1676 viafb_CRT_ON
= STATE_ON
;
1677 viafb_SAMM_ON
= STATE_OFF
;
1678 } else if (!strncmp(viafb_active_dev
, "DVI", 3)) {
1680 viafb_DVI_ON
= STATE_ON
;
1681 viafb_SAMM_ON
= STATE_OFF
;
1682 } else if (!strncmp(viafb_active_dev
, "LCD", 3)) {
1684 viafb_LCD_ON
= STATE_ON
;
1685 viafb_SAMM_ON
= STATE_OFF
;
1687 viafb_CRT_ON
= STATE_ON
;
1688 viafb_SAMM_ON
= STATE_OFF
;
1690 viaparinfo
->duoview
= is_duoview();
1693 static void parse_video_dev(void)
1695 viaparinfo
->video_on_crt
= STATE_OFF
;
1696 viaparinfo
->video_on_dvi
= STATE_OFF
;
1697 viaparinfo
->video_on_lcd
= STATE_OFF
;
1699 if (!strncmp(viafb_video_dev
, "CRT", 3)) {
1701 viaparinfo
->video_on_crt
= STATE_ON
;
1702 } else if (!strncmp(viafb_video_dev
, "DVI", 3)) {
1704 viaparinfo
->video_on_dvi
= STATE_ON
;
1705 } else if (!strncmp(viafb_video_dev
, "LCD", 3)) {
1707 viaparinfo
->video_on_lcd
= STATE_ON
;
1711 static int parse_port(char *opt_str
, int *output_interface
)
1713 if (!strncmp(opt_str
, "DVP0", 4))
1714 *output_interface
= INTERFACE_DVP0
;
1715 else if (!strncmp(opt_str
, "DVP1", 4))
1716 *output_interface
= INTERFACE_DVP1
;
1717 else if (!strncmp(opt_str
, "DFP_HIGHLOW", 11))
1718 *output_interface
= INTERFACE_DFP
;
1719 else if (!strncmp(opt_str
, "DFP_HIGH", 8))
1720 *output_interface
= INTERFACE_DFP_HIGH
;
1721 else if (!strncmp(opt_str
, "DFP_LOW", 7))
1722 *output_interface
= INTERFACE_DFP_LOW
;
1724 *output_interface
= INTERFACE_NONE
;
1728 static void parse_lcd_port(void)
1730 parse_port(viafb_lcd_port
, &viaparinfo
->chip_info
->lvds_chip_info
.
1732 /*Initialize to avoid unexpected behavior */
1733 viaparinfo
->chip_info
->lvds_chip_info2
.output_interface
=
1736 DEBUG_MSG(KERN_INFO
"parse_lcd_port: viafb_lcd_port:%s,interface:%d\n",
1737 viafb_lcd_port
, viaparinfo
->chip_info
->lvds_chip_info
.
1741 static void parse_dvi_port(void)
1743 parse_port(viafb_dvi_port
, &viaparinfo
->chip_info
->tmds_chip_info
.
1746 DEBUG_MSG(KERN_INFO
"parse_dvi_port: viafb_dvi_port:%s,interface:%d\n",
1747 viafb_dvi_port
, viaparinfo
->chip_info
->tmds_chip_info
.
1752 * The proc filesystem read/write function, a simple proc implement to
1753 * get/set the value of DPA DVP0, DVP0DataDriving, DVP0ClockDriving, DVP1,
1754 * DVP1Driving, DFPHigh, DFPLow CR96, SR2A[5], SR1B[1], SR2A[4], SR1E[2],
1755 * CR9B, SR65, CR97, CR99
1757 static int viafb_dvp0_proc_read(char *buf
, char **start
, off_t offset
,
1758 int count
, int *eof
, void *data
)
1761 u8 dvp0_data_dri
= 0, dvp0_clk_dri
= 0, dvp0
= 0;
1763 (viafb_read_reg(VIASR
, SR2A
) & BIT5
) >> 4 |
1764 (viafb_read_reg(VIASR
, SR1B
) & BIT1
) >> 1;
1766 (viafb_read_reg(VIASR
, SR2A
) & BIT4
) >> 3 |
1767 (viafb_read_reg(VIASR
, SR1E
) & BIT2
) >> 2;
1768 dvp0
= viafb_read_reg(VIACR
, CR96
) & 0x0f;
1770 sprintf(buf
+ len
, "%x %x %x\n", dvp0
, dvp0_data_dri
, dvp0_clk_dri
);
1771 *eof
= 1; /*Inform kernel end of data */
1774 static int viafb_dvp0_proc_write(struct file
*file
,
1775 const char __user
*buffer
, unsigned long count
, void *data
)
1777 char buf
[20], *value
, *pbuf
;
1779 unsigned long length
, i
;
1782 length
= count
> 20 ? 20 : count
;
1783 if (copy_from_user(&buf
[0], buffer
, length
))
1785 buf
[length
- 1] = '\0'; /*Ensure end string */
1787 for (i
= 0; i
< 3; i
++) {
1788 value
= strsep(&pbuf
, " ");
1789 if (value
!= NULL
) {
1790 strict_strtoul(value
, 0, (unsigned long *)®_val
);
1791 DEBUG_MSG(KERN_INFO
"DVP0:reg_val[%l]=:%x\n", i
,
1795 viafb_write_reg_mask(CR96
, VIACR
,
1799 viafb_write_reg_mask(SR2A
, VIASR
,
1800 reg_val
<< 4, BIT5
);
1801 viafb_write_reg_mask(SR1B
, VIASR
,
1802 reg_val
<< 1, BIT1
);
1805 viafb_write_reg_mask(SR2A
, VIASR
,
1806 reg_val
<< 3, BIT4
);
1807 viafb_write_reg_mask(SR1E
, VIASR
,
1808 reg_val
<< 2, BIT2
);
1819 static int viafb_dvp1_proc_read(char *buf
, char **start
, off_t offset
,
1820 int count
, int *eof
, void *data
)
1823 u8 dvp1
= 0, dvp1_data_dri
= 0, dvp1_clk_dri
= 0;
1824 dvp1
= viafb_read_reg(VIACR
, CR9B
) & 0x0f;
1825 dvp1_data_dri
= (viafb_read_reg(VIASR
, SR65
) & 0x0c) >> 2;
1826 dvp1_clk_dri
= viafb_read_reg(VIASR
, SR65
) & 0x03;
1828 sprintf(buf
+ len
, "%x %x %x\n", dvp1
, dvp1_data_dri
, dvp1_clk_dri
);
1829 *eof
= 1; /*Inform kernel end of data */
1832 static int viafb_dvp1_proc_write(struct file
*file
,
1833 const char __user
*buffer
, unsigned long count
, void *data
)
1835 char buf
[20], *value
, *pbuf
;
1837 unsigned long length
, i
;
1840 length
= count
> 20 ? 20 : count
;
1841 if (copy_from_user(&buf
[0], buffer
, length
))
1843 buf
[length
- 1] = '\0'; /*Ensure end string */
1845 for (i
= 0; i
< 3; i
++) {
1846 value
= strsep(&pbuf
, " ");
1847 if (value
!= NULL
) {
1848 strict_strtoul(value
, 0, (unsigned long *)®_val
);
1851 viafb_write_reg_mask(CR9B
, VIACR
,
1855 viafb_write_reg_mask(SR65
, VIASR
,
1856 reg_val
<< 2, 0x0c);
1859 viafb_write_reg_mask(SR65
, VIASR
,
1872 static int viafb_dfph_proc_read(char *buf
, char **start
, off_t offset
,
1873 int count
, int *eof
, void *data
)
1877 dfp_high
= viafb_read_reg(VIACR
, CR97
) & 0x0f;
1878 len
+= sprintf(buf
+ len
, "%x\n", dfp_high
);
1879 *eof
= 1; /*Inform kernel end of data */
1882 static int viafb_dfph_proc_write(struct file
*file
,
1883 const char __user
*buffer
, unsigned long count
, void *data
)
1887 unsigned long length
;
1890 length
= count
> 20 ? 20 : count
;
1891 if (copy_from_user(&buf
[0], buffer
, length
))
1893 buf
[length
- 1] = '\0'; /*Ensure end string */
1894 strict_strtoul(&buf
[0], 0, (unsigned long *)®_val
);
1895 viafb_write_reg_mask(CR97
, VIACR
, reg_val
, 0x0f);
1898 static int viafb_dfpl_proc_read(char *buf
, char **start
, off_t offset
,
1899 int count
, int *eof
, void *data
)
1903 dfp_low
= viafb_read_reg(VIACR
, CR99
) & 0x0f;
1904 len
+= sprintf(buf
+ len
, "%x\n", dfp_low
);
1905 *eof
= 1; /*Inform kernel end of data */
1908 static int viafb_dfpl_proc_write(struct file
*file
,
1909 const char __user
*buffer
, unsigned long count
, void *data
)
1913 unsigned long length
;
1916 length
= count
> 20 ? 20 : count
;
1917 if (copy_from_user(&buf
[0], buffer
, length
))
1919 buf
[length
- 1] = '\0'; /*Ensure end string */
1920 strict_strtoul(&buf
[0], 0, (unsigned long *)®_val
);
1921 viafb_write_reg_mask(CR99
, VIACR
, reg_val
, 0x0f);
1924 static int viafb_vt1636_proc_read(char *buf
, char **start
,
1925 off_t offset
, int count
, int *eof
, void *data
)
1928 u8 vt1636_08
= 0, vt1636_09
= 0;
1929 switch (viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
) {
1932 viafb_gpio_i2c_read_lvds(viaparinfo
->lvds_setting_info
,
1933 &viaparinfo
->chip_info
->lvds_chip_info
, 0x08) & 0x0f;
1935 viafb_gpio_i2c_read_lvds(viaparinfo
->lvds_setting_info
,
1936 &viaparinfo
->chip_info
->lvds_chip_info
, 0x09) & 0x1f;
1937 len
+= sprintf(buf
+ len
, "%x %x\n", vt1636_08
, vt1636_09
);
1942 switch (viaparinfo
->chip_info
->lvds_chip_info2
.lvds_chip_name
) {
1945 viafb_gpio_i2c_read_lvds(viaparinfo
->lvds_setting_info2
,
1946 &viaparinfo
->chip_info
->lvds_chip_info2
, 0x08) & 0x0f;
1948 viafb_gpio_i2c_read_lvds(viaparinfo
->lvds_setting_info2
,
1949 &viaparinfo
->chip_info
->lvds_chip_info2
, 0x09) & 0x1f;
1950 len
+= sprintf(buf
+ len
, " %x %x\n", vt1636_08
, vt1636_09
);
1955 *eof
= 1; /*Inform kernel end of data */
1958 static int viafb_vt1636_proc_write(struct file
*file
,
1959 const char __user
*buffer
, unsigned long count
, void *data
)
1961 char buf
[30], *value
, *pbuf
;
1962 struct IODATA reg_val
;
1963 unsigned long length
, i
;
1966 length
= count
> 30 ? 30 : count
;
1967 if (copy_from_user(&buf
[0], buffer
, length
))
1969 buf
[length
- 1] = '\0'; /*Ensure end string */
1971 switch (viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
) {
1973 for (i
= 0; i
< 2; i
++) {
1974 value
= strsep(&pbuf
, " ");
1975 if (value
!= NULL
) {
1976 strict_strtoul(value
, 0,
1977 (unsigned long *)®_val
.Data
);
1980 reg_val
.Index
= 0x08;
1981 reg_val
.Mask
= 0x0f;
1982 viafb_gpio_i2c_write_mask_lvds
1983 (viaparinfo
->lvds_setting_info
,
1985 chip_info
->lvds_chip_info
,
1989 reg_val
.Index
= 0x09;
1990 reg_val
.Mask
= 0x1f;
1991 viafb_gpio_i2c_write_mask_lvds
1992 (viaparinfo
->lvds_setting_info
,
1994 chip_info
->lvds_chip_info
,
2008 switch (viaparinfo
->chip_info
->lvds_chip_info2
.lvds_chip_name
) {
2010 for (i
= 0; i
< 2; i
++) {
2011 value
= strsep(&pbuf
, " ");
2012 if (value
!= NULL
) {
2013 strict_strtoul(value
, 0,
2014 (unsigned long *)®_val
.Data
);
2017 reg_val
.Index
= 0x08;
2018 reg_val
.Mask
= 0x0f;
2019 viafb_gpio_i2c_write_mask_lvds
2020 (viaparinfo
->lvds_setting_info2
,
2022 chip_info
->lvds_chip_info2
,
2026 reg_val
.Index
= 0x09;
2027 reg_val
.Mask
= 0x1f;
2028 viafb_gpio_i2c_write_mask_lvds
2029 (viaparinfo
->lvds_setting_info2
,
2031 chip_info
->lvds_chip_info2
,
2048 static void viafb_init_proc(struct proc_dir_entry
**viafb_entry
)
2050 struct proc_dir_entry
*entry
;
2051 *viafb_entry
= proc_mkdir("viafb", NULL
);
2053 entry
= create_proc_entry("dvp0", 0, *viafb_entry
);
2055 entry
->read_proc
= viafb_dvp0_proc_read
;
2056 entry
->write_proc
= viafb_dvp0_proc_write
;
2058 entry
= create_proc_entry("dvp1", 0, *viafb_entry
);
2060 entry
->read_proc
= viafb_dvp1_proc_read
;
2061 entry
->write_proc
= viafb_dvp1_proc_write
;
2063 entry
= create_proc_entry("dfph", 0, *viafb_entry
);
2065 entry
->read_proc
= viafb_dfph_proc_read
;
2066 entry
->write_proc
= viafb_dfph_proc_write
;
2068 entry
= create_proc_entry("dfpl", 0, *viafb_entry
);
2070 entry
->read_proc
= viafb_dfpl_proc_read
;
2071 entry
->write_proc
= viafb_dfpl_proc_write
;
2073 if (VT1636_LVDS
== viaparinfo
->chip_info
->lvds_chip_info
.
2074 lvds_chip_name
|| VT1636_LVDS
==
2075 viaparinfo
->chip_info
->lvds_chip_info2
.lvds_chip_name
) {
2076 entry
= create_proc_entry("vt1636", 0, *viafb_entry
);
2078 entry
->read_proc
= viafb_vt1636_proc_read
;
2079 entry
->write_proc
= viafb_vt1636_proc_write
;
2085 static void viafb_remove_proc(struct proc_dir_entry
*viafb_entry
)
2087 /* no problem if it was not registered */
2088 remove_proc_entry("dvp0", viafb_entry
);/* parent dir */
2089 remove_proc_entry("dvp1", viafb_entry
);
2090 remove_proc_entry("dfph", viafb_entry
);
2091 remove_proc_entry("dfpl", viafb_entry
);
2092 remove_proc_entry("vt1636", viafb_entry
);
2093 remove_proc_entry("vt1625", viafb_entry
);
2094 remove_proc_entry("viafb", NULL
);
2097 static int __devinit
via_pci_probe(void)
2099 unsigned long default_xres
, default_yres
;
2101 char *tmpc_sec
, *tmpm_sec
;
2103 u32 tmds_length
, lvds_length
, crt_length
, chip_length
, viafb_par_length
;
2105 DEBUG_MSG(KERN_INFO
"VIAFB PCI Probe!!\n");
2107 viafb_par_length
= ALIGN(sizeof(struct viafb_par
), BITS_PER_LONG
/8);
2108 tmds_length
= ALIGN(sizeof(struct tmds_setting_information
),
2110 lvds_length
= ALIGN(sizeof(struct lvds_setting_information
),
2112 crt_length
= ALIGN(sizeof(struct lvds_setting_information
),
2114 chip_length
= ALIGN(sizeof(struct chip_information
), BITS_PER_LONG
/8);
2116 /* Allocate fb_info and ***_par here, also including some other needed
2119 viafbinfo
= framebuffer_alloc(viafb_par_length
+ 2 * lvds_length
+
2120 tmds_length
+ crt_length
+ chip_length
, NULL
);
2122 printk(KERN_ERR
"Could not allocate memory for viafb_info.\n");
2126 viaparinfo
= (struct viafb_par
*)viafbinfo
->par
;
2127 viaparinfo
->tmds_setting_info
= (struct tmds_setting_information
*)
2128 ((unsigned long)viaparinfo
+ viafb_par_length
);
2129 viaparinfo
->lvds_setting_info
= (struct lvds_setting_information
*)
2130 ((unsigned long)viaparinfo
->tmds_setting_info
+ tmds_length
);
2131 viaparinfo
->lvds_setting_info2
= (struct lvds_setting_information
*)
2132 ((unsigned long)viaparinfo
->lvds_setting_info
+ lvds_length
);
2133 viaparinfo
->crt_setting_info
= (struct crt_setting_information
*)
2134 ((unsigned long)viaparinfo
->lvds_setting_info2
+ lvds_length
);
2135 viaparinfo
->chip_info
= (struct chip_information
*)
2136 ((unsigned long)viaparinfo
->crt_setting_info
+ crt_length
);
2145 /* for dual-fb must viafb_SAMM_ON=1 and viafb_dual_fb=1 */
2149 /* Set up I2C bus stuff */
2150 viafb_create_i2c_bus(viaparinfo
);
2152 viafb_init_chip_info();
2153 viafb_get_fb_info(&viaparinfo
->fbmem
, &viaparinfo
->memsize
);
2154 viaparinfo
->fbmem_free
= viaparinfo
->memsize
;
2155 viaparinfo
->fbmem_used
= 0;
2156 viaparinfo
->fbmem_virt
= ioremap_nocache(viaparinfo
->fbmem
,
2157 viaparinfo
->memsize
);
2158 viafbinfo
->screen_base
= (char *)viaparinfo
->fbmem_virt
;
2160 if (!viaparinfo
->fbmem_virt
) {
2161 printk(KERN_INFO
"ioremap failed\n");
2165 viafb_get_mmio_info(&viaparinfo
->mmio_base
, &viaparinfo
->mmio_len
);
2166 viaparinfo
->io_virt
= ioremap_nocache(viaparinfo
->mmio_base
,
2167 viaparinfo
->mmio_len
);
2169 viafbinfo
->node
= 0;
2170 viafbinfo
->fbops
= &viafb_ops
;
2171 viafbinfo
->flags
= FBINFO_DEFAULT
| FBINFO_HWACCEL_YPAN
;
2173 viafbinfo
->pseudo_palette
= pseudo_pal
;
2176 viafb_init_2d_engine();
2177 viafb_hw_cursor_init();
2180 if (viafb_second_size
&& (viafb_second_size
< 8)) {
2181 viafb_second_offset
= viaparinfo
->fbmem_free
-
2182 viafb_second_size
* 1024 * 1024;
2184 viafb_second_size
= 8;
2185 viafb_second_offset
= viaparinfo
->fbmem_free
-
2186 viafb_second_size
* 1024 * 1024;
2189 viafb_FB_MM
= viaparinfo
->fbmem_virt
;
2191 tmpc
= strsep(&tmpm
, "x");
2192 strict_strtoul(tmpc
, 0, &default_xres
);
2193 strict_strtoul(tmpm
, 0, &default_yres
);
2195 vmode_index
= viafb_get_mode_index(default_xres
, default_yres
);
2196 DEBUG_MSG(KERN_INFO
"0->index=%d\n", vmode_index
);
2198 if (viafb_SAMM_ON
== 1) {
2199 if (strcmp(viafb_mode
, viafb_mode1
)) {
2200 tmpm_sec
= viafb_mode1
;
2201 tmpc_sec
= strsep(&tmpm_sec
, "x");
2202 strict_strtoul(tmpc_sec
, 0,
2203 (unsigned long *)&viafb_second_xres
);
2204 strict_strtoul(tmpm_sec
, 0,
2205 (unsigned long *)&viafb_second_yres
);
2207 viafb_second_xres
= default_xres
;
2208 viafb_second_yres
= default_yres
;
2210 if (0 == viafb_second_virtual_xres
) {
2211 switch (viafb_second_xres
) {
2213 viafb_second_virtual_xres
= 1408;
2216 viafb_second_virtual_xres
= viafb_second_xres
;
2220 if (0 == viafb_second_virtual_yres
)
2221 viafb_second_virtual_yres
= viafb_second_yres
;
2224 switch (viafb_bpp
) {
2237 default_var
.xres
= default_xres
;
2238 default_var
.yres
= default_yres
;
2239 switch (default_xres
) {
2241 default_var
.xres_virtual
= 1408;
2244 default_var
.xres_virtual
= default_xres
;
2247 default_var
.yres_virtual
= default_yres
;
2248 default_var
.bits_per_pixel
= viafb_bpp
;
2249 if (default_var
.bits_per_pixel
== 15)
2250 default_var
.bits_per_pixel
= 16;
2251 default_var
.pixclock
=
2252 viafb_get_pixclock(default_xres
, default_yres
, viafb_refresh
);
2253 default_var
.left_margin
= (default_xres
>> 3) & 0xf8;
2254 default_var
.right_margin
= 32;
2255 default_var
.upper_margin
= 16;
2256 default_var
.lower_margin
= 4;
2257 default_var
.hsync_len
= default_var
.left_margin
;
2258 default_var
.vsync_len
= 4;
2259 default_var
.accel_flags
= 0;
2263 (FBINFO_HWACCEL_COPYAREA
| FBINFO_HWACCEL_FILLRECT
|
2264 FBINFO_HWACCEL_IMAGEBLIT
);
2265 default_var
.accel_flags
|= FB_ACCELF_TEXT
;
2267 viafbinfo
->flags
|= FBINFO_HWACCEL_DISABLED
;
2269 if (viafb_dual_fb
) {
2270 viafbinfo1
= framebuffer_alloc(viafb_par_length
, NULL
);
2273 "allocate the second framebuffer struct error\n");
2274 framebuffer_release(viafbinfo
);
2277 viaparinfo1
= viafbinfo1
->par
;
2278 memcpy(viaparinfo1
, viaparinfo
, viafb_par_length
);
2279 viaparinfo1
->memsize
= viaparinfo
->memsize
-
2280 viafb_second_offset
;
2281 viaparinfo
->memsize
= viafb_second_offset
;
2282 viaparinfo1
->fbmem_virt
= viaparinfo
->fbmem_virt
+
2283 viafb_second_offset
;
2284 viaparinfo1
->fbmem
= viaparinfo
->fbmem
+ viafb_second_offset
;
2286 viaparinfo1
->fbmem_used
= viaparinfo
->fbmem_used
;
2287 viaparinfo1
->fbmem_free
= viaparinfo1
->memsize
-
2288 viaparinfo1
->fbmem_used
;
2289 viaparinfo
->fbmem_free
= viaparinfo
->memsize
;
2290 viaparinfo
->fbmem_used
= 0;
2292 viaparinfo1
->cursor_start
=
2293 viaparinfo
->cursor_start
- viafb_second_offset
;
2294 viaparinfo1
->VQ_start
= viaparinfo
->VQ_start
-
2295 viafb_second_offset
;
2296 viaparinfo1
->VQ_end
= viaparinfo
->VQ_end
-
2297 viafb_second_offset
;
2300 memcpy(viafbinfo1
, viafbinfo
, sizeof(struct fb_info
));
2301 viafbinfo1
->screen_base
= viafbinfo
->screen_base
+
2302 viafb_second_offset
;
2303 viafbinfo1
->fix
.smem_start
= viaparinfo1
->fbmem
;
2304 viafbinfo1
->fix
.smem_len
= viaparinfo1
->fbmem_free
;
2306 default_var
.xres
= viafb_second_xres
;
2307 default_var
.yres
= viafb_second_yres
;
2308 default_var
.xres_virtual
= viafb_second_virtual_xres
;
2309 default_var
.yres_virtual
= viafb_second_virtual_yres
;
2310 if (viafb_bpp1
!= viafb_bpp
)
2311 viafb_bpp1
= viafb_bpp
;
2312 default_var
.bits_per_pixel
= viafb_bpp1
;
2313 default_var
.pixclock
=
2314 viafb_get_pixclock(viafb_second_xres
, viafb_second_yres
,
2316 default_var
.left_margin
= (viafb_second_xres
>> 3) & 0xf8;
2317 default_var
.right_margin
= 32;
2318 default_var
.upper_margin
= 16;
2319 default_var
.lower_margin
= 4;
2320 default_var
.hsync_len
= default_var
.left_margin
;
2321 default_var
.vsync_len
= 4;
2323 viafb_setup_fixinfo(&viafbinfo1
->fix
, viaparinfo1
);
2324 viafb_check_var(&default_var
, viafbinfo1
);
2325 viafbinfo1
->var
= default_var
;
2326 viafb_update_viafb_par(viafbinfo
);
2327 viafb_update_fix(&viafbinfo1
->fix
, viafbinfo1
);
2330 viafb_setup_fixinfo(&viafbinfo
->fix
, viaparinfo
);
2331 viafb_check_var(&default_var
, viafbinfo
);
2332 viafbinfo
->var
= default_var
;
2333 viafb_update_viafb_par(viafbinfo
);
2334 viafb_update_fix(&viafbinfo
->fix
, viafbinfo
);
2335 default_var
.activate
= FB_ACTIVATE_NOW
;
2336 fb_alloc_cmap(&viafbinfo
->cmap
, 256, 0);
2338 if (viafb_dual_fb
&& (viafb_primary_dev
== LCD_Device
)
2339 && (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_CLE266
)) {
2340 if (register_framebuffer(viafbinfo1
) < 0)
2343 if (register_framebuffer(viafbinfo
) < 0)
2346 if (viafb_dual_fb
&& ((viafb_primary_dev
!= LCD_Device
)
2347 || (viaparinfo
->chip_info
->gfx_chip_name
!=
2348 UNICHROME_CLE266
))) {
2349 if (register_framebuffer(viafbinfo1
) < 0)
2352 DEBUG_MSG(KERN_INFO
"fb%d: %s frame buffer device %dx%d-%dbpp\n",
2353 viafbinfo
->node
, viafbinfo
->fix
.id
, default_var
.xres
,
2354 default_var
.yres
, default_var
.bits_per_pixel
);
2356 viafb_init_proc(&viaparinfo
->proc_entry
);
2357 viafb_init_dac(IGA2
);
2361 static void __devexit
via_pci_remove(void)
2363 DEBUG_MSG(KERN_INFO
"via_pci_remove!\n");
2364 fb_dealloc_cmap(&viafbinfo
->cmap
);
2365 unregister_framebuffer(viafbinfo
);
2367 unregister_framebuffer(viafbinfo1
);
2368 iounmap((void *)viaparinfo
->fbmem_virt
);
2369 iounmap(viaparinfo
->io_virt
);
2371 viafb_delete_i2c_buss(viaparinfo
);
2373 framebuffer_release(viafbinfo
);
2375 framebuffer_release(viafbinfo1
);
2377 viafb_remove_proc(viaparinfo
->proc_entry
);
2381 static int __init
viafb_setup(char *options
)
2384 DEBUG_MSG(KERN_INFO
"viafb_setup!\n");
2386 if (!options
|| !*options
)
2389 while ((this_opt
= strsep(&options
, ",")) != NULL
) {
2393 if (!strncmp(this_opt
, "viafb_mode1=", 12))
2394 viafb_mode1
= kstrdup(this_opt
+ 12, GFP_KERNEL
);
2395 else if (!strncmp(this_opt
, "viafb_mode=", 11))
2396 viafb_mode
= kstrdup(this_opt
+ 11, GFP_KERNEL
);
2397 else if (!strncmp(this_opt
, "viafb_bpp1=", 11))
2398 strict_strtoul(this_opt
+ 11, 0,
2399 (unsigned long *)&viafb_bpp1
);
2400 else if (!strncmp(this_opt
, "viafb_bpp=", 10))
2401 strict_strtoul(this_opt
+ 10, 0,
2402 (unsigned long *)&viafb_bpp
);
2403 else if (!strncmp(this_opt
, "viafb_refresh1=", 15))
2404 strict_strtoul(this_opt
+ 15, 0,
2405 (unsigned long *)&viafb_refresh1
);
2406 else if (!strncmp(this_opt
, "viafb_refresh=", 14))
2407 strict_strtoul(this_opt
+ 14, 0,
2408 (unsigned long *)&viafb_refresh
);
2409 else if (!strncmp(this_opt
, "viafb_lcd_dsp_method=", 21))
2410 strict_strtoul(this_opt
+ 21, 0,
2411 (unsigned long *)&viafb_lcd_dsp_method
);
2412 else if (!strncmp(this_opt
, "viafb_lcd_panel_id=", 19))
2413 strict_strtoul(this_opt
+ 19, 0,
2414 (unsigned long *)&viafb_lcd_panel_id
);
2415 else if (!strncmp(this_opt
, "viafb_accel=", 12))
2416 strict_strtoul(this_opt
+ 12, 0,
2417 (unsigned long *)&viafb_accel
);
2418 else if (!strncmp(this_opt
, "viafb_SAMM_ON=", 14))
2419 strict_strtoul(this_opt
+ 14, 0,
2420 (unsigned long *)&viafb_SAMM_ON
);
2421 else if (!strncmp(this_opt
, "viafb_active_dev=", 17))
2422 viafb_active_dev
= kstrdup(this_opt
+ 17, GFP_KERNEL
);
2423 else if (!strncmp(this_opt
,
2424 "viafb_display_hardware_layout=", 30))
2425 strict_strtoul(this_opt
+ 30, 0,
2426 (unsigned long *)&viafb_display_hardware_layout
);
2427 else if (!strncmp(this_opt
, "viafb_second_size=", 18))
2428 strict_strtoul(this_opt
+ 18, 0,
2429 (unsigned long *)&viafb_second_size
);
2430 else if (!strncmp(this_opt
,
2431 "viafb_platform_epia_dvi=", 24))
2432 strict_strtoul(this_opt
+ 24, 0,
2433 (unsigned long *)&viafb_platform_epia_dvi
);
2434 else if (!strncmp(this_opt
,
2435 "viafb_device_lcd_dualedge=", 26))
2436 strict_strtoul(this_opt
+ 26, 0,
2437 (unsigned long *)&viafb_device_lcd_dualedge
);
2438 else if (!strncmp(this_opt
, "viafb_bus_width=", 16))
2439 strict_strtoul(this_opt
+ 16, 0,
2440 (unsigned long *)&viafb_bus_width
);
2441 else if (!strncmp(this_opt
, "viafb_lcd_mode=", 15))
2442 strict_strtoul(this_opt
+ 15, 0,
2443 (unsigned long *)&viafb_lcd_mode
);
2444 else if (!strncmp(this_opt
, "viafb_video_dev=", 16))
2445 viafb_video_dev
= kstrdup(this_opt
+ 16, GFP_KERNEL
);
2446 else if (!strncmp(this_opt
, "viafb_lcd_port=", 15))
2447 viafb_lcd_port
= kstrdup(this_opt
+ 15, GFP_KERNEL
);
2448 else if (!strncmp(this_opt
, "viafb_dvi_port=", 15))
2449 viafb_dvi_port
= kstrdup(this_opt
+ 15, GFP_KERNEL
);
2455 static int __init
viafb_init(void)
2458 char *option
= NULL
;
2459 if (fb_get_options("viafb", &option
))
2461 viafb_setup(option
);
2464 "VIA Graphics Intergration Chipset framebuffer %d.%d initializing\n",
2465 VERSION_MAJOR
, VERSION_MINOR
);
2466 return via_pci_probe();
2469 static void __exit
viafb_exit(void)
2471 DEBUG_MSG(KERN_INFO
"viafb_exit!\n");
2475 static struct fb_ops viafb_ops
= {
2476 .owner
= THIS_MODULE
,
2477 .fb_open
= viafb_open
,
2478 .fb_release
= viafb_release
,
2479 .fb_check_var
= viafb_check_var
,
2480 .fb_set_par
= viafb_set_par
,
2481 .fb_setcolreg
= viafb_setcolreg
,
2482 .fb_pan_display
= viafb_pan_display
,
2483 .fb_blank
= viafb_blank
,
2484 .fb_fillrect
= viafb_fillrect
,
2485 .fb_copyarea
= viafb_copyarea
,
2486 .fb_imageblit
= viafb_imageblit
,
2487 .fb_cursor
= viafb_cursor
,
2488 .fb_ioctl
= viafb_ioctl
,
2489 .fb_sync
= viafb_sync
,
2490 .fb_setcmap
= viafb_setcmap
,
2493 module_init(viafb_init
);
2494 module_exit(viafb_exit
);
2497 module_param(viafb_memsize
, int, 0);
2499 module_param(viafb_mode
, charp
, 0);
2500 MODULE_PARM_DESC(viafb_mode
, "Set resolution (default=640x480)");
2502 module_param(viafb_mode1
, charp
, 0);
2503 MODULE_PARM_DESC(viafb_mode1
, "Set resolution (default=640x480)");
2505 module_param(viafb_bpp
, int, 0);
2506 MODULE_PARM_DESC(viafb_bpp
, "Set color depth (default=32bpp)");
2508 module_param(viafb_bpp1
, int, 0);
2509 MODULE_PARM_DESC(viafb_bpp1
, "Set color depth (default=32bpp)");
2511 module_param(viafb_refresh
, int, 0);
2512 MODULE_PARM_DESC(viafb_refresh
,
2513 "Set CRT viafb_refresh rate (default = 60)");
2515 module_param(viafb_refresh1
, int, 0);
2516 MODULE_PARM_DESC(viafb_refresh1
,
2517 "Set CRT refresh rate (default = 60)");
2519 module_param(viafb_lcd_panel_id
, int, 0);
2520 MODULE_PARM_DESC(viafb_lcd_panel_id
,
2521 "Set Flat Panel type(Default=1024x768)");
2523 module_param(viafb_lcd_dsp_method
, int, 0);
2524 MODULE_PARM_DESC(viafb_lcd_dsp_method
,
2525 "Set Flat Panel display scaling method.(Default=Expandsion)");
2527 module_param(viafb_SAMM_ON
, int, 0);
2528 MODULE_PARM_DESC(viafb_SAMM_ON
,
2529 "Turn on/off flag of SAMM(Default=OFF)");
2531 module_param(viafb_accel
, int, 0);
2532 MODULE_PARM_DESC(viafb_accel
,
2533 "Set 2D Hardware Acceleration.(Default = OFF)");
2535 module_param(viafb_active_dev
, charp
, 0);
2536 MODULE_PARM_DESC(viafb_active_dev
, "Specify active devices.");
2538 module_param(viafb_display_hardware_layout
, int, 0);
2539 MODULE_PARM_DESC(viafb_display_hardware_layout
,
2540 "Display Hardware Layout (LCD Only, DVI Only...,etc)");
2542 module_param(viafb_second_size
, int, 0);
2543 MODULE_PARM_DESC(viafb_second_size
,
2544 "Set secondary device memory size");
2546 module_param(viafb_dual_fb
, int, 0);
2547 MODULE_PARM_DESC(viafb_dual_fb
,
2548 "Turn on/off flag of dual framebuffer devices.(Default = OFF)");
2550 module_param(viafb_platform_epia_dvi
, int, 0);
2551 MODULE_PARM_DESC(viafb_platform_epia_dvi
,
2552 "Turn on/off flag of DVI devices on EPIA board.(Default = OFF)");
2554 module_param(viafb_device_lcd_dualedge
, int, 0);
2555 MODULE_PARM_DESC(viafb_device_lcd_dualedge
,
2556 "Turn on/off flag of dual edge panel.(Default = OFF)");
2558 module_param(viafb_bus_width
, int, 0);
2559 MODULE_PARM_DESC(viafb_bus_width
,
2560 "Set bus width of panel.(Default = 12)");
2562 module_param(viafb_lcd_mode
, int, 0);
2563 MODULE_PARM_DESC(viafb_lcd_mode
,
2564 "Set Flat Panel mode(Default=OPENLDI)");
2566 module_param(viafb_video_dev
, charp
, 0);
2567 MODULE_PARM_DESC(viafb_video_dev
, "Specify video devices.");
2569 module_param(viafb_lcd_port
, charp
, 0);
2570 MODULE_PARM_DESC(viafb_lcd_port
, "Specify LCD output port.");
2572 module_param(viafb_dvi_port
, charp
, 0);
2573 MODULE_PARM_DESC(viafb_dvi_port
, "Specify DVI output port.");
2575 MODULE_LICENSE("GPL");