2 * Copyright 1998-2009 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include <linux/module.h>
23 #include <linux/seq_file.h>
24 #include <linux/slab.h>
25 #include <linux/stat.h>
26 #include <linux/via-core.h>
31 static char *viafb_name
= "Via";
32 static u32 pseudo_pal
[17];
35 static char *viafb_mode
;
36 static char *viafb_mode1
;
37 static int viafb_bpp
= 32;
38 static int viafb_bpp1
= 32;
40 static unsigned int viafb_second_offset
;
41 static int viafb_second_size
;
43 static int viafb_accel
= 1;
45 /* Added for specifying active devices.*/
46 char *viafb_active_dev
;
48 /*Added for specify lcd output port*/
49 char *viafb_lcd_port
= "";
50 char *viafb_dvi_port
= "";
52 static void retrieve_device_setting(struct viafb_ioctl_setting
54 static int viafb_pan_display(struct fb_var_screeninfo
*var
,
55 struct fb_info
*info
);
57 static struct fb_ops viafb_ops
;
60 static void viafb_fill_var_color_info(struct fb_var_screeninfo
*var
, u8 depth
)
63 var
->red
.msb_right
= 0;
64 var
->green
.msb_right
= 0;
65 var
->blue
.msb_right
= 0;
66 var
->transp
.offset
= 0;
67 var
->transp
.length
= 0;
68 var
->transp
.msb_right
= 0;
72 var
->bits_per_pixel
= 8;
74 var
->green
.offset
= 0;
77 var
->green
.length
= 8;
81 var
->bits_per_pixel
= 16;
83 var
->green
.offset
= 5;
86 var
->green
.length
= 5;
90 var
->bits_per_pixel
= 16;
92 var
->green
.offset
= 5;
95 var
->green
.length
= 6;
99 var
->bits_per_pixel
= 32;
100 var
->red
.offset
= 16;
101 var
->green
.offset
= 8;
102 var
->blue
.offset
= 0;
104 var
->green
.length
= 8;
105 var
->blue
.length
= 8;
108 var
->bits_per_pixel
= 32;
109 var
->red
.offset
= 20;
110 var
->green
.offset
= 10;
111 var
->blue
.offset
= 0;
112 var
->red
.length
= 10;
113 var
->green
.length
= 10;
114 var
->blue
.length
= 10;
119 static void viafb_update_fix(struct fb_info
*info
)
121 u32 bpp
= info
->var
.bits_per_pixel
;
124 bpp
== 8 ? FB_VISUAL_PSEUDOCOLOR
: FB_VISUAL_TRUECOLOR
;
125 info
->fix
.line_length
= (info
->var
.xres_virtual
* bpp
/ 8 + 7) & ~7;
128 static void viafb_setup_fixinfo(struct fb_fix_screeninfo
*fix
,
129 struct viafb_par
*viaparinfo
)
131 memset(fix
, 0, sizeof(struct fb_fix_screeninfo
));
132 strcpy(fix
->id
, viafb_name
);
134 fix
->smem_start
= viaparinfo
->fbmem
;
135 fix
->smem_len
= viaparinfo
->fbmem_free
;
137 fix
->type
= FB_TYPE_PACKED_PIXELS
;
139 fix
->visual
= FB_VISUAL_TRUECOLOR
;
141 fix
->xpanstep
= fix
->ywrapstep
= 0;
144 /* Just tell the accel name */
145 viafbinfo
->fix
.accel
= FB_ACCEL_VIA_UNICHROME
;
147 static int viafb_open(struct fb_info
*info
, int user
)
149 DEBUG_MSG(KERN_INFO
"viafb_open!\n");
153 static int viafb_release(struct fb_info
*info
, int user
)
155 DEBUG_MSG(KERN_INFO
"viafb_release!\n");
159 static int viafb_check_var(struct fb_var_screeninfo
*var
,
160 struct fb_info
*info
)
162 int htotal
, vtotal
, depth
;
163 struct VideoModeTable
*vmode_entry
;
164 struct viafb_par
*ppar
= info
->par
;
165 u32 long_refresh
, line
;
167 DEBUG_MSG(KERN_INFO
"viafb_check_var!\n");
169 /* HW neither support interlacte nor double-scaned mode */
170 if (var
->vmode
& FB_VMODE_INTERLACED
|| var
->vmode
& FB_VMODE_DOUBLE
)
173 vmode_entry
= viafb_get_mode(var
->xres
, var
->yres
);
176 "viafb: Mode %dx%dx%d not supported!!\n",
177 var
->xres
, var
->yres
, var
->bits_per_pixel
);
181 depth
= fb_get_color_depth(var
, &info
->fix
);
183 depth
= var
->bits_per_pixel
;
185 if (depth
< 0 || depth
> 32)
189 else if (depth
== 15 && viafb_dual_fb
&& ppar
->iga_path
== IGA1
)
191 else if (depth
== 30)
195 else if (depth
<= 16)
200 viafb_fill_var_color_info(var
, depth
);
201 line
= (var
->xres_virtual
* var
->bits_per_pixel
/ 8 + 7) & ~7;
202 if (line
* var
->yres_virtual
> ppar
->memsize
)
205 /* Based on var passed in to calculate the refresh,
206 * because our driver use some modes special.
208 htotal
= var
->xres
+ var
->left_margin
+
209 var
->right_margin
+ var
->hsync_len
;
210 vtotal
= var
->yres
+ var
->upper_margin
+
211 var
->lower_margin
+ var
->vsync_len
;
212 long_refresh
= 1000000000UL / var
->pixclock
* 1000;
213 long_refresh
/= (htotal
* vtotal
);
215 viafb_refresh
= viafb_get_refresh(var
->xres
, var
->yres
, long_refresh
);
217 /* Adjust var according to our driver's own table */
218 viafb_fill_var_timing_info(var
, viafb_refresh
, vmode_entry
);
219 if (var
->accel_flags
& FB_ACCELF_TEXT
&&
220 !ppar
->shared
->vdev
->engine_mmio
)
221 var
->accel_flags
= 0;
226 static int viafb_set_par(struct fb_info
*info
)
228 struct viafb_par
*viapar
= info
->par
;
229 struct VideoModeTable
*vmode_entry
, *vmode_entry1
= NULL
;
230 DEBUG_MSG(KERN_INFO
"viafb_set_par!\n");
232 viafb_update_fix(info
);
233 viapar
->depth
= fb_get_color_depth(&info
->var
, &info
->fix
);
234 viafb_update_device_setting(viafbinfo
->var
.xres
, viafbinfo
->var
.yres
,
235 viafbinfo
->var
.bits_per_pixel
, viafb_refresh
, 0);
237 vmode_entry
= viafb_get_mode(viafbinfo
->var
.xres
, viafbinfo
->var
.yres
);
239 vmode_entry1
= viafb_get_mode(viafbinfo1
->var
.xres
,
240 viafbinfo1
->var
.yres
);
241 viafb_update_device_setting(viafbinfo1
->var
.xres
,
242 viafbinfo1
->var
.yres
, viafbinfo1
->var
.bits_per_pixel
,
244 } else if (viafb_SAMM_ON
== 1) {
246 "viafb_second_xres = %d, viafb_second_yres = %d, bpp = %d\n",
247 viafb_second_xres
, viafb_second_yres
, viafb_bpp1
);
248 vmode_entry1
= viafb_get_mode(viafb_second_xres
,
251 viafb_update_device_setting(viafb_second_xres
,
252 viafb_second_yres
, viafb_bpp1
, viafb_refresh1
, 1);
256 if (viafb_dual_fb
&& viapar
->iga_path
== IGA2
)
257 viafb_bpp1
= info
->var
.bits_per_pixel
;
259 viafb_bpp
= info
->var
.bits_per_pixel
;
261 if (info
->var
.accel_flags
& FB_ACCELF_TEXT
)
262 info
->flags
&= ~FBINFO_HWACCEL_DISABLED
;
264 info
->flags
|= FBINFO_HWACCEL_DISABLED
;
265 viafb_setmode(vmode_entry
, info
->var
.bits_per_pixel
,
266 vmode_entry1
, viafb_bpp1
);
267 viafb_pan_display(&info
->var
, info
);
273 /* Set one color register */
274 static int viafb_setcolreg(unsigned regno
, unsigned red
, unsigned green
,
275 unsigned blue
, unsigned transp
, struct fb_info
*info
)
277 struct viafb_par
*viapar
= info
->par
;
280 if (info
->fix
.visual
== FB_VISUAL_PSEUDOCOLOR
) {
284 if (!viafb_dual_fb
|| viapar
->iga_path
== IGA1
)
285 viafb_set_primary_color_register(regno
, red
>> 8,
286 green
>> 8, blue
>> 8);
288 if (!viafb_dual_fb
|| viapar
->iga_path
== IGA2
)
289 viafb_set_secondary_color_register(regno
, red
>> 8,
290 green
>> 8, blue
>> 8);
295 r
= (red
>> (16 - info
->var
.red
.length
))
296 << info
->var
.red
.offset
;
297 b
= (blue
>> (16 - info
->var
.blue
.length
))
298 << info
->var
.blue
.offset
;
299 g
= (green
>> (16 - info
->var
.green
.length
))
300 << info
->var
.green
.offset
;
301 ((u32
*) info
->pseudo_palette
)[regno
] = r
| g
| b
;
307 static int viafb_pan_display(struct fb_var_screeninfo
*var
,
308 struct fb_info
*info
)
310 struct viafb_par
*viapar
= info
->par
;
311 u32 vram_addr
= (var
->yoffset
* var
->xres_virtual
+ var
->xoffset
)
312 * (var
->bits_per_pixel
/ 8) + viapar
->vram_addr
;
314 DEBUG_MSG(KERN_DEBUG
"viafb_pan_display, address = %d\n", vram_addr
);
315 if (!viafb_dual_fb
) {
316 via_set_primary_address(vram_addr
);
317 via_set_secondary_address(vram_addr
);
318 } else if (viapar
->iga_path
== IGA1
)
319 via_set_primary_address(vram_addr
);
321 via_set_secondary_address(vram_addr
);
326 static int viafb_blank(int blank_mode
, struct fb_info
*info
)
328 DEBUG_MSG(KERN_INFO
"viafb_blank!\n");
329 /* clear DPMS setting */
331 switch (blank_mode
) {
332 case FB_BLANK_UNBLANK
:
333 /* Screen: On, HSync: On, VSync: On */
334 /* control CRT monitor power management */
335 viafb_write_reg_mask(CR36
, VIACR
, 0x00, BIT4
+ BIT5
);
337 case FB_BLANK_HSYNC_SUSPEND
:
338 /* Screen: Off, HSync: Off, VSync: On */
339 /* control CRT monitor power management */
340 viafb_write_reg_mask(CR36
, VIACR
, 0x10, BIT4
+ BIT5
);
342 case FB_BLANK_VSYNC_SUSPEND
:
343 /* Screen: Off, HSync: On, VSync: Off */
344 /* control CRT monitor power management */
345 viafb_write_reg_mask(CR36
, VIACR
, 0x20, BIT4
+ BIT5
);
347 case FB_BLANK_POWERDOWN
:
348 /* Screen: Off, HSync: Off, VSync: Off */
349 /* control CRT monitor power management */
350 viafb_write_reg_mask(CR36
, VIACR
, 0x30, BIT4
+ BIT5
);
357 static int viafb_ioctl(struct fb_info
*info
, u_int cmd
, u_long arg
)
360 struct viafb_ioctl_mode viamode
;
361 struct viafb_ioctl_samm viasamm
;
362 struct viafb_driver_version driver_version
;
363 struct fb_var_screeninfo sec_var
;
364 struct _panel_size_pos_info panel_pos_size_para
;
365 struct viafb_ioctl_setting viafb_setting
;
366 struct device_t active_dev
;
369 u32
*viafb_gamma_table
;
370 char driver_name
[] = "viafb";
372 u32 __user
*argp
= (u32 __user
*) arg
;
375 DEBUG_MSG(KERN_INFO
"viafb_ioctl: 0x%X !!\n", cmd
);
376 printk(KERN_WARNING
"viafb_ioctl: Please avoid this interface as it is unstable and might change or vanish at any time!\n");
377 memset(&u
, 0, sizeof(u
));
380 case VIAFB_GET_CHIP_INFO
:
381 if (copy_to_user(argp
, viaparinfo
->chip_info
,
382 sizeof(struct chip_information
)))
385 case VIAFB_GET_INFO_SIZE
:
386 return put_user((u32
)sizeof(struct viafb_ioctl_info
), argp
);
388 return viafb_ioctl_get_viafb_info(arg
);
390 return put_user(viafb_ioctl_hotplug(info
->var
.xres
,
392 info
->var
.bits_per_pixel
), argp
);
393 case VIAFB_SET_HOTPLUG_FLAG
:
394 if (copy_from_user(&gpu32
, argp
, sizeof(gpu32
)))
396 viafb_hotplug
= (gpu32
) ? 1 : 0;
398 case VIAFB_GET_RESOLUTION
:
399 u
.viamode
.xres
= (u32
) viafb_hotplug_Xres
;
400 u
.viamode
.yres
= (u32
) viafb_hotplug_Yres
;
401 u
.viamode
.refresh
= (u32
) viafb_hotplug_refresh
;
402 u
.viamode
.bpp
= (u32
) viafb_hotplug_bpp
;
403 if (viafb_SAMM_ON
== 1) {
404 u
.viamode
.xres_sec
= viafb_second_xres
;
405 u
.viamode
.yres_sec
= viafb_second_yres
;
406 u
.viamode
.virtual_xres_sec
= viafb_second_virtual_xres
;
407 u
.viamode
.virtual_yres_sec
= viafb_second_virtual_yres
;
408 u
.viamode
.refresh_sec
= viafb_refresh1
;
409 u
.viamode
.bpp_sec
= viafb_bpp1
;
411 u
.viamode
.xres_sec
= 0;
412 u
.viamode
.yres_sec
= 0;
413 u
.viamode
.virtual_xres_sec
= 0;
414 u
.viamode
.virtual_yres_sec
= 0;
415 u
.viamode
.refresh_sec
= 0;
416 u
.viamode
.bpp_sec
= 0;
418 if (copy_to_user(argp
, &u
.viamode
, sizeof(u
.viamode
)))
421 case VIAFB_GET_SAMM_INFO
:
422 u
.viasamm
.samm_status
= viafb_SAMM_ON
;
424 if (viafb_SAMM_ON
== 1) {
426 u
.viasamm
.size_prim
= viaparinfo
->fbmem_free
;
427 u
.viasamm
.size_sec
= viaparinfo1
->fbmem_free
;
429 if (viafb_second_size
) {
430 u
.viasamm
.size_prim
=
431 viaparinfo
->fbmem_free
-
432 viafb_second_size
* 1024 * 1024;
434 viafb_second_size
* 1024 * 1024;
436 u
.viasamm
.size_prim
=
437 viaparinfo
->fbmem_free
>> 1;
439 (viaparinfo
->fbmem_free
>> 1);
442 u
.viasamm
.mem_base
= viaparinfo
->fbmem
;
443 u
.viasamm
.offset_sec
= viafb_second_offset
;
445 u
.viasamm
.size_prim
=
446 viaparinfo
->memsize
- viaparinfo
->fbmem_used
;
447 u
.viasamm
.size_sec
= 0;
448 u
.viasamm
.mem_base
= viaparinfo
->fbmem
;
449 u
.viasamm
.offset_sec
= 0;
452 if (copy_to_user(argp
, &u
.viasamm
, sizeof(u
.viasamm
)))
456 case VIAFB_TURN_ON_OUTPUT_DEVICE
:
457 if (copy_from_user(&gpu32
, argp
, sizeof(gpu32
)))
459 if (gpu32
& CRT_Device
)
461 if (gpu32
& DVI_Device
)
463 if (gpu32
& LCD_Device
)
466 case VIAFB_TURN_OFF_OUTPUT_DEVICE
:
467 if (copy_from_user(&gpu32
, argp
, sizeof(gpu32
)))
469 if (gpu32
& CRT_Device
)
471 if (gpu32
& DVI_Device
)
473 if (gpu32
& LCD_Device
)
476 case VIAFB_GET_DEVICE
:
477 u
.active_dev
.crt
= viafb_CRT_ON
;
478 u
.active_dev
.dvi
= viafb_DVI_ON
;
479 u
.active_dev
.lcd
= viafb_LCD_ON
;
480 u
.active_dev
.samm
= viafb_SAMM_ON
;
481 u
.active_dev
.primary_dev
= viafb_primary_dev
;
483 u
.active_dev
.lcd_dsp_cent
= viafb_lcd_dsp_method
;
484 u
.active_dev
.lcd_panel_id
= viafb_lcd_panel_id
;
485 u
.active_dev
.lcd_mode
= viafb_lcd_mode
;
487 u
.active_dev
.xres
= viafb_hotplug_Xres
;
488 u
.active_dev
.yres
= viafb_hotplug_Yres
;
490 u
.active_dev
.xres1
= viafb_second_xres
;
491 u
.active_dev
.yres1
= viafb_second_yres
;
493 u
.active_dev
.bpp
= viafb_bpp
;
494 u
.active_dev
.bpp1
= viafb_bpp1
;
495 u
.active_dev
.refresh
= viafb_refresh
;
496 u
.active_dev
.refresh1
= viafb_refresh1
;
498 u
.active_dev
.epia_dvi
= viafb_platform_epia_dvi
;
499 u
.active_dev
.lcd_dual_edge
= viafb_device_lcd_dualedge
;
500 u
.active_dev
.bus_width
= viafb_bus_width
;
502 if (copy_to_user(argp
, &u
.active_dev
, sizeof(u
.active_dev
)))
506 case VIAFB_GET_DRIVER_VERSION
:
507 u
.driver_version
.iMajorNum
= VERSION_MAJOR
;
508 u
.driver_version
.iKernelNum
= VERSION_KERNEL
;
509 u
.driver_version
.iOSNum
= VERSION_OS
;
510 u
.driver_version
.iMinorNum
= VERSION_MINOR
;
512 if (copy_to_user(argp
, &u
.driver_version
,
513 sizeof(u
.driver_version
)))
518 case VIAFB_GET_DEVICE_INFO
:
520 retrieve_device_setting(&u
.viafb_setting
);
522 if (copy_to_user(argp
, &u
.viafb_setting
,
523 sizeof(u
.viafb_setting
)))
528 case VIAFB_GET_DEVICE_SUPPORT
:
529 viafb_get_device_support_state(&state_info
);
530 if (put_user(state_info
, argp
))
534 case VIAFB_GET_DEVICE_CONNECT
:
535 viafb_get_device_connect_state(&state_info
);
536 if (put_user(state_info
, argp
))
540 case VIAFB_GET_PANEL_SUPPORT_EXPAND
:
542 viafb_lcd_get_support_expand_state(info
->var
.xres
,
544 if (put_user(state_info
, argp
))
548 case VIAFB_GET_DRIVER_NAME
:
549 if (copy_to_user(argp
, driver_name
, sizeof(driver_name
)))
553 case VIAFB_SET_GAMMA_LUT
:
554 viafb_gamma_table
= memdup_user(argp
, 256 * sizeof(u32
));
555 if (IS_ERR(viafb_gamma_table
))
556 return PTR_ERR(viafb_gamma_table
);
557 viafb_set_gamma_table(viafb_bpp
, viafb_gamma_table
);
558 kfree(viafb_gamma_table
);
561 case VIAFB_GET_GAMMA_LUT
:
562 viafb_gamma_table
= kmalloc(256 * sizeof(u32
), GFP_KERNEL
);
563 if (!viafb_gamma_table
)
565 viafb_get_gamma_table(viafb_gamma_table
);
566 if (copy_to_user(argp
, viafb_gamma_table
,
567 256 * sizeof(u32
))) {
568 kfree(viafb_gamma_table
);
571 kfree(viafb_gamma_table
);
574 case VIAFB_GET_GAMMA_SUPPORT_STATE
:
575 viafb_get_gamma_support_state(viafb_bpp
, &state_info
);
576 if (put_user(state_info
, argp
))
579 case VIAFB_SYNC_SURFACE
:
580 DEBUG_MSG(KERN_INFO
"lobo VIAFB_SYNC_SURFACE\n");
582 case VIAFB_GET_DRIVER_CAPS
:
585 case VIAFB_GET_PANEL_MAX_SIZE
:
586 if (copy_from_user(&u
.panel_pos_size_para
, argp
,
587 sizeof(u
.panel_pos_size_para
)))
589 u
.panel_pos_size_para
.x
= u
.panel_pos_size_para
.y
= 0;
590 if (copy_to_user(argp
, &u
.panel_pos_size_para
,
591 sizeof(u
.panel_pos_size_para
)))
594 case VIAFB_GET_PANEL_MAX_POSITION
:
595 if (copy_from_user(&u
.panel_pos_size_para
, argp
,
596 sizeof(u
.panel_pos_size_para
)))
598 u
.panel_pos_size_para
.x
= u
.panel_pos_size_para
.y
= 0;
599 if (copy_to_user(argp
, &u
.panel_pos_size_para
,
600 sizeof(u
.panel_pos_size_para
)))
604 case VIAFB_GET_PANEL_POSITION
:
605 if (copy_from_user(&u
.panel_pos_size_para
, argp
,
606 sizeof(u
.panel_pos_size_para
)))
608 u
.panel_pos_size_para
.x
= u
.panel_pos_size_para
.y
= 0;
609 if (copy_to_user(argp
, &u
.panel_pos_size_para
,
610 sizeof(u
.panel_pos_size_para
)))
613 case VIAFB_GET_PANEL_SIZE
:
614 if (copy_from_user(&u
.panel_pos_size_para
, argp
,
615 sizeof(u
.panel_pos_size_para
)))
617 u
.panel_pos_size_para
.x
= u
.panel_pos_size_para
.y
= 0;
618 if (copy_to_user(argp
, &u
.panel_pos_size_para
,
619 sizeof(u
.panel_pos_size_para
)))
623 case VIAFB_SET_PANEL_POSITION
:
624 if (copy_from_user(&u
.panel_pos_size_para
, argp
,
625 sizeof(u
.panel_pos_size_para
)))
628 case VIAFB_SET_PANEL_SIZE
:
629 if (copy_from_user(&u
.panel_pos_size_para
, argp
,
630 sizeof(u
.panel_pos_size_para
)))
641 static void viafb_fillrect(struct fb_info
*info
,
642 const struct fb_fillrect
*rect
)
644 struct viafb_par
*viapar
= info
->par
;
645 struct viafb_shared
*shared
= viapar
->shared
;
649 if (info
->flags
& FBINFO_HWACCEL_DISABLED
|| !shared
->hw_bitblt
) {
650 cfb_fillrect(info
, rect
);
654 if (!rect
->width
|| !rect
->height
)
657 if (info
->fix
.visual
== FB_VISUAL_TRUECOLOR
)
658 fg_color
= ((u32
*)info
->pseudo_palette
)[rect
->color
];
660 fg_color
= rect
->color
;
662 if (rect
->rop
== ROP_XOR
)
667 DEBUG_MSG(KERN_DEBUG
"viafb 2D engine: fillrect\n");
668 if (shared
->hw_bitblt(shared
->vdev
->engine_mmio
, VIA_BITBLT_FILL
,
669 rect
->width
, rect
->height
, info
->var
.bits_per_pixel
,
670 viapar
->vram_addr
, info
->fix
.line_length
, rect
->dx
, rect
->dy
,
671 NULL
, 0, 0, 0, 0, fg_color
, 0, rop
))
672 cfb_fillrect(info
, rect
);
675 static void viafb_copyarea(struct fb_info
*info
,
676 const struct fb_copyarea
*area
)
678 struct viafb_par
*viapar
= info
->par
;
679 struct viafb_shared
*shared
= viapar
->shared
;
681 if (info
->flags
& FBINFO_HWACCEL_DISABLED
|| !shared
->hw_bitblt
) {
682 cfb_copyarea(info
, area
);
686 if (!area
->width
|| !area
->height
)
689 DEBUG_MSG(KERN_DEBUG
"viafb 2D engine: copyarea\n");
690 if (shared
->hw_bitblt(shared
->vdev
->engine_mmio
, VIA_BITBLT_COLOR
,
691 area
->width
, area
->height
, info
->var
.bits_per_pixel
,
692 viapar
->vram_addr
, info
->fix
.line_length
, area
->dx
, area
->dy
,
693 NULL
, viapar
->vram_addr
, info
->fix
.line_length
,
694 area
->sx
, area
->sy
, 0, 0, 0))
695 cfb_copyarea(info
, area
);
698 static void viafb_imageblit(struct fb_info
*info
,
699 const struct fb_image
*image
)
701 struct viafb_par
*viapar
= info
->par
;
702 struct viafb_shared
*shared
= viapar
->shared
;
703 u32 fg_color
= 0, bg_color
= 0;
706 if (info
->flags
& FBINFO_HWACCEL_DISABLED
|| !shared
->hw_bitblt
||
707 (image
->depth
!= 1 && image
->depth
!= viapar
->depth
)) {
708 cfb_imageblit(info
, image
);
712 if (image
->depth
== 1) {
713 op
= VIA_BITBLT_MONO
;
714 if (info
->fix
.visual
== FB_VISUAL_TRUECOLOR
) {
716 ((u32
*)info
->pseudo_palette
)[image
->fg_color
];
718 ((u32
*)info
->pseudo_palette
)[image
->bg_color
];
720 fg_color
= image
->fg_color
;
721 bg_color
= image
->bg_color
;
724 op
= VIA_BITBLT_COLOR
;
726 DEBUG_MSG(KERN_DEBUG
"viafb 2D engine: imageblit\n");
727 if (shared
->hw_bitblt(shared
->vdev
->engine_mmio
, op
,
728 image
->width
, image
->height
, info
->var
.bits_per_pixel
,
729 viapar
->vram_addr
, info
->fix
.line_length
, image
->dx
, image
->dy
,
730 (u32
*)image
->data
, 0, 0, 0, 0, fg_color
, bg_color
, 0))
731 cfb_imageblit(info
, image
);
734 static int viafb_cursor(struct fb_info
*info
, struct fb_cursor
*cursor
)
736 struct viafb_par
*viapar
= info
->par
;
737 void __iomem
*engine
= viapar
->shared
->vdev
->engine_mmio
;
738 u32 temp
, xx
, yy
, bg_color
= 0, fg_color
= 0,
739 chip_name
= viapar
->shared
->chip_info
.gfx_chip_name
;
740 int i
, j
= 0, cur_size
= 64;
742 if (info
->flags
& FBINFO_HWACCEL_DISABLED
|| info
!= viafbinfo
)
745 /* LCD ouput does not support hw cursors (at least on VN896) */
746 if ((chip_name
== UNICHROME_CLE266
&& viapar
->iga_path
== IGA2
) ||
750 viafb_show_hw_cursor(info
, HW_Cursor_OFF
);
752 if (cursor
->set
& FB_CUR_SETHOT
) {
753 temp
= (cursor
->hot
.x
<< 16) + cursor
->hot
.y
;
754 writel(temp
, engine
+ VIA_REG_CURSOR_ORG
);
757 if (cursor
->set
& FB_CUR_SETPOS
) {
758 yy
= cursor
->image
.dy
- info
->var
.yoffset
;
759 xx
= cursor
->image
.dx
- info
->var
.xoffset
;
762 writel(temp
, engine
+ VIA_REG_CURSOR_POS
);
765 if (cursor
->image
.width
<= 32 && cursor
->image
.height
<= 32)
767 else if (cursor
->image
.width
<= 64 && cursor
->image
.height
<= 64)
770 printk(KERN_WARNING
"viafb_cursor: The cursor is too large "
771 "%dx%d", cursor
->image
.width
, cursor
->image
.height
);
775 if (cursor
->set
& FB_CUR_SETSIZE
) {
776 temp
= readl(engine
+ VIA_REG_CURSOR_MODE
);
782 writel(temp
, engine
+ VIA_REG_CURSOR_MODE
);
785 if (cursor
->set
& FB_CUR_SETCMAP
) {
786 fg_color
= cursor
->image
.fg_color
;
787 bg_color
= cursor
->image
.bg_color
;
788 if (chip_name
== UNICHROME_CX700
||
789 chip_name
== UNICHROME_VX800
||
790 chip_name
== UNICHROME_VX855
) {
792 ((info
->cmap
.red
[fg_color
] & 0xFFC0) << 14) |
793 ((info
->cmap
.green
[fg_color
] & 0xFFC0) << 4) |
794 ((info
->cmap
.blue
[fg_color
] & 0xFFC0) >> 6);
796 ((info
->cmap
.red
[bg_color
] & 0xFFC0) << 14) |
797 ((info
->cmap
.green
[bg_color
] & 0xFFC0) << 4) |
798 ((info
->cmap
.blue
[bg_color
] & 0xFFC0) >> 6);
801 ((info
->cmap
.red
[fg_color
] & 0xFF00) << 8) |
802 (info
->cmap
.green
[fg_color
] & 0xFF00) |
803 ((info
->cmap
.blue
[fg_color
] & 0xFF00) >> 8);
805 ((info
->cmap
.red
[bg_color
] & 0xFF00) << 8) |
806 (info
->cmap
.green
[bg_color
] & 0xFF00) |
807 ((info
->cmap
.blue
[bg_color
] & 0xFF00) >> 8);
810 writel(bg_color
, engine
+ VIA_REG_CURSOR_BG
);
811 writel(fg_color
, engine
+ VIA_REG_CURSOR_FG
);
814 if (cursor
->set
& FB_CUR_SETSHAPE
) {
816 u8 data
[CURSOR_SIZE
];
817 u32 bak
[CURSOR_SIZE
/ 4];
818 } *cr_data
= kzalloc(sizeof(*cr_data
), GFP_ATOMIC
);
819 int size
= ((cursor
->image
.width
+ 7) >> 3) *
820 cursor
->image
.height
;
825 if (cur_size
== 32) {
826 for (i
= 0; i
< (CURSOR_SIZE
/ 4); i
++) {
827 cr_data
->bak
[i
] = 0x0;
828 cr_data
->bak
[i
+ 1] = 0xFFFFFFFF;
832 for (i
= 0; i
< (CURSOR_SIZE
/ 4); i
++) {
833 cr_data
->bak
[i
] = 0x0;
834 cr_data
->bak
[i
+ 1] = 0x0;
835 cr_data
->bak
[i
+ 2] = 0xFFFFFFFF;
836 cr_data
->bak
[i
+ 3] = 0xFFFFFFFF;
841 switch (cursor
->rop
) {
843 for (i
= 0; i
< size
; i
++)
844 cr_data
->data
[i
] = cursor
->mask
[i
];
848 for (i
= 0; i
< size
; i
++)
849 cr_data
->data
[i
] = cursor
->mask
[i
];
855 if (cur_size
== 32) {
856 for (i
= 0; i
< size
; i
++) {
857 cr_data
->bak
[j
] = (u32
) cr_data
->data
[i
];
858 cr_data
->bak
[j
+ 1] = ~cr_data
->bak
[j
];
862 for (i
= 0; i
< size
; i
++) {
863 cr_data
->bak
[j
] = (u32
) cr_data
->data
[i
];
864 cr_data
->bak
[j
+ 1] = 0x0;
865 cr_data
->bak
[j
+ 2] = ~cr_data
->bak
[j
];
866 cr_data
->bak
[j
+ 3] = ~cr_data
->bak
[j
+ 1];
871 memcpy_toio(viafbinfo
->screen_base
+ viapar
->shared
->
872 cursor_vram_addr
, cr_data
->bak
, CURSOR_SIZE
);
877 viafb_show_hw_cursor(info
, HW_Cursor_ON
);
882 static int viafb_sync(struct fb_info
*info
)
884 if (!(info
->flags
& FBINFO_HWACCEL_DISABLED
))
885 viafb_wait_engine_idle(info
);
889 static int get_primary_device(void)
891 int primary_device
= 0;
892 /* Rule: device on iga1 path are the primary device. */
895 if (viaparinfo
->crt_setting_info
->iga_path
== IGA1
) {
896 DEBUG_MSG(KERN_INFO
"CRT IGA Path:%d\n",
898 crt_setting_info
->iga_path
);
899 primary_device
= CRT_Device
;
903 if (viaparinfo
->tmds_setting_info
->iga_path
== IGA1
) {
904 DEBUG_MSG(KERN_INFO
"DVI IGA Path:%d\n",
906 tmds_setting_info
->iga_path
);
907 primary_device
= DVI_Device
;
911 if (viaparinfo
->lvds_setting_info
->iga_path
== IGA1
) {
912 DEBUG_MSG(KERN_INFO
"LCD IGA Path:%d\n",
914 lvds_setting_info
->iga_path
);
915 primary_device
= LCD_Device
;
919 if (viaparinfo
->lvds_setting_info2
->iga_path
== IGA1
) {
920 DEBUG_MSG(KERN_INFO
"LCD2 IGA Path:%d\n",
922 lvds_setting_info2
->iga_path
);
923 primary_device
= LCD2_Device
;
927 return primary_device
;
930 static void retrieve_device_setting(struct viafb_ioctl_setting
934 /* get device status */
935 if (viafb_CRT_ON
== 1)
936 setting_info
->device_status
= CRT_Device
;
937 if (viafb_DVI_ON
== 1)
938 setting_info
->device_status
|= DVI_Device
;
939 if (viafb_LCD_ON
== 1)
940 setting_info
->device_status
|= LCD_Device
;
941 if (viafb_LCD2_ON
== 1)
942 setting_info
->device_status
|= LCD2_Device
;
944 setting_info
->samm_status
= viafb_SAMM_ON
;
945 setting_info
->primary_device
= get_primary_device();
947 setting_info
->first_dev_bpp
= viafb_bpp
;
948 setting_info
->second_dev_bpp
= viafb_bpp1
;
950 setting_info
->first_dev_refresh
= viafb_refresh
;
951 setting_info
->second_dev_refresh
= viafb_refresh1
;
953 setting_info
->first_dev_hor_res
= viafb_hotplug_Xres
;
954 setting_info
->first_dev_ver_res
= viafb_hotplug_Yres
;
955 setting_info
->second_dev_hor_res
= viafb_second_xres
;
956 setting_info
->second_dev_ver_res
= viafb_second_yres
;
958 /* Get lcd attributes */
959 setting_info
->lcd_attributes
.display_center
= viafb_lcd_dsp_method
;
960 setting_info
->lcd_attributes
.panel_id
= viafb_lcd_panel_id
;
961 setting_info
->lcd_attributes
.lcd_mode
= viafb_lcd_mode
;
964 static int parse_active_dev(void)
966 viafb_CRT_ON
= STATE_OFF
;
967 viafb_DVI_ON
= STATE_OFF
;
968 viafb_LCD_ON
= STATE_OFF
;
969 viafb_LCD2_ON
= STATE_OFF
;
970 /* 1. Modify the active status of devices. */
971 /* 2. Keep the order of devices, so we can set corresponding
972 IGA path to devices in SAMM case. */
973 /* Note: The previous of active_dev is primary device,
974 and the following is secondary device. */
975 if (!viafb_active_dev
) {
976 viafb_CRT_ON
= STATE_ON
;
977 viafb_SAMM_ON
= STATE_OFF
;
978 } else if (!strcmp(viafb_active_dev
, "CRT+DVI")) {
980 viafb_CRT_ON
= STATE_ON
;
981 viafb_DVI_ON
= STATE_ON
;
982 viafb_primary_dev
= CRT_Device
;
983 } else if (!strcmp(viafb_active_dev
, "DVI+CRT")) {
985 viafb_CRT_ON
= STATE_ON
;
986 viafb_DVI_ON
= STATE_ON
;
987 viafb_primary_dev
= DVI_Device
;
988 } else if (!strcmp(viafb_active_dev
, "CRT+LCD")) {
990 viafb_CRT_ON
= STATE_ON
;
991 viafb_LCD_ON
= STATE_ON
;
992 viafb_primary_dev
= CRT_Device
;
993 } else if (!strcmp(viafb_active_dev
, "LCD+CRT")) {
995 viafb_CRT_ON
= STATE_ON
;
996 viafb_LCD_ON
= STATE_ON
;
997 viafb_primary_dev
= LCD_Device
;
998 } else if (!strcmp(viafb_active_dev
, "DVI+LCD")) {
1000 viafb_DVI_ON
= STATE_ON
;
1001 viafb_LCD_ON
= STATE_ON
;
1002 viafb_primary_dev
= DVI_Device
;
1003 } else if (!strcmp(viafb_active_dev
, "LCD+DVI")) {
1005 viafb_DVI_ON
= STATE_ON
;
1006 viafb_LCD_ON
= STATE_ON
;
1007 viafb_primary_dev
= LCD_Device
;
1008 } else if (!strcmp(viafb_active_dev
, "LCD+LCD2")) {
1009 viafb_LCD_ON
= STATE_ON
;
1010 viafb_LCD2_ON
= STATE_ON
;
1011 viafb_primary_dev
= LCD_Device
;
1012 } else if (!strcmp(viafb_active_dev
, "LCD2+LCD")) {
1013 viafb_LCD_ON
= STATE_ON
;
1014 viafb_LCD2_ON
= STATE_ON
;
1015 viafb_primary_dev
= LCD2_Device
;
1016 } else if (!strcmp(viafb_active_dev
, "CRT")) {
1018 viafb_CRT_ON
= STATE_ON
;
1019 viafb_SAMM_ON
= STATE_OFF
;
1020 } else if (!strcmp(viafb_active_dev
, "DVI")) {
1022 viafb_DVI_ON
= STATE_ON
;
1023 viafb_SAMM_ON
= STATE_OFF
;
1024 } else if (!strcmp(viafb_active_dev
, "LCD")) {
1026 viafb_LCD_ON
= STATE_ON
;
1027 viafb_SAMM_ON
= STATE_OFF
;
1034 static int parse_port(char *opt_str
, int *output_interface
)
1036 if (!strncmp(opt_str
, "DVP0", 4))
1037 *output_interface
= INTERFACE_DVP0
;
1038 else if (!strncmp(opt_str
, "DVP1", 4))
1039 *output_interface
= INTERFACE_DVP1
;
1040 else if (!strncmp(opt_str
, "DFP_HIGHLOW", 11))
1041 *output_interface
= INTERFACE_DFP
;
1042 else if (!strncmp(opt_str
, "DFP_HIGH", 8))
1043 *output_interface
= INTERFACE_DFP_HIGH
;
1044 else if (!strncmp(opt_str
, "DFP_LOW", 7))
1045 *output_interface
= INTERFACE_DFP_LOW
;
1047 *output_interface
= INTERFACE_NONE
;
1051 static void parse_lcd_port(void)
1053 parse_port(viafb_lcd_port
, &viaparinfo
->chip_info
->lvds_chip_info
.
1055 /*Initialize to avoid unexpected behavior */
1056 viaparinfo
->chip_info
->lvds_chip_info2
.output_interface
=
1059 DEBUG_MSG(KERN_INFO
"parse_lcd_port: viafb_lcd_port:%s,interface:%d\n",
1060 viafb_lcd_port
, viaparinfo
->chip_info
->lvds_chip_info
.
1064 static void parse_dvi_port(void)
1066 parse_port(viafb_dvi_port
, &viaparinfo
->chip_info
->tmds_chip_info
.
1069 DEBUG_MSG(KERN_INFO
"parse_dvi_port: viafb_dvi_port:%s,interface:%d\n",
1070 viafb_dvi_port
, viaparinfo
->chip_info
->tmds_chip_info
.
1074 #ifdef CONFIG_FB_VIA_DIRECT_PROCFS
1077 * The proc filesystem read/write function, a simple proc implement to
1078 * get/set the value of DPA DVP0, DVP0DataDriving, DVP0ClockDriving, DVP1,
1079 * DVP1Driving, DFPHigh, DFPLow CR96, SR2A[5], SR1B[1], SR2A[4], SR1E[2],
1080 * CR9B, SR65, CR97, CR99
1082 static int viafb_dvp0_proc_show(struct seq_file
*m
, void *v
)
1084 u8 dvp0_data_dri
= 0, dvp0_clk_dri
= 0, dvp0
= 0;
1086 (viafb_read_reg(VIASR
, SR2A
) & BIT5
) >> 4 |
1087 (viafb_read_reg(VIASR
, SR1B
) & BIT1
) >> 1;
1089 (viafb_read_reg(VIASR
, SR2A
) & BIT4
) >> 3 |
1090 (viafb_read_reg(VIASR
, SR1E
) & BIT2
) >> 2;
1091 dvp0
= viafb_read_reg(VIACR
, CR96
) & 0x0f;
1092 seq_printf(m
, "%x %x %x\n", dvp0
, dvp0_data_dri
, dvp0_clk_dri
);
1096 static int viafb_dvp0_proc_open(struct inode
*inode
, struct file
*file
)
1098 return single_open(file
, viafb_dvp0_proc_show
, NULL
);
1101 static ssize_t
viafb_dvp0_proc_write(struct file
*file
,
1102 const char __user
*buffer
, size_t count
, loff_t
*pos
)
1104 char buf
[20], *value
, *pbuf
;
1106 unsigned long length
, i
;
1109 length
= count
> 20 ? 20 : count
;
1110 if (copy_from_user(&buf
[0], buffer
, length
))
1112 buf
[length
- 1] = '\0'; /*Ensure end string */
1114 for (i
= 0; i
< 3; i
++) {
1115 value
= strsep(&pbuf
, " ");
1116 if (value
!= NULL
) {
1117 strict_strtoul(value
, 0, (unsigned long *)®_val
);
1118 DEBUG_MSG(KERN_INFO
"DVP0:reg_val[%l]=:%x\n", i
,
1122 viafb_write_reg_mask(CR96
, VIACR
,
1126 viafb_write_reg_mask(SR2A
, VIASR
,
1127 reg_val
<< 4, BIT5
);
1128 viafb_write_reg_mask(SR1B
, VIASR
,
1129 reg_val
<< 1, BIT1
);
1132 viafb_write_reg_mask(SR2A
, VIASR
,
1133 reg_val
<< 3, BIT4
);
1134 viafb_write_reg_mask(SR1E
, VIASR
,
1135 reg_val
<< 2, BIT2
);
1147 static const struct file_operations viafb_dvp0_proc_fops
= {
1148 .owner
= THIS_MODULE
,
1149 .open
= viafb_dvp0_proc_open
,
1151 .llseek
= seq_lseek
,
1152 .release
= single_release
,
1153 .write
= viafb_dvp0_proc_write
,
1156 static int viafb_dvp1_proc_show(struct seq_file
*m
, void *v
)
1158 u8 dvp1
= 0, dvp1_data_dri
= 0, dvp1_clk_dri
= 0;
1159 dvp1
= viafb_read_reg(VIACR
, CR9B
) & 0x0f;
1160 dvp1_data_dri
= (viafb_read_reg(VIASR
, SR65
) & 0x0c) >> 2;
1161 dvp1_clk_dri
= viafb_read_reg(VIASR
, SR65
) & 0x03;
1162 seq_printf(m
, "%x %x %x\n", dvp1
, dvp1_data_dri
, dvp1_clk_dri
);
1166 static int viafb_dvp1_proc_open(struct inode
*inode
, struct file
*file
)
1168 return single_open(file
, viafb_dvp1_proc_show
, NULL
);
1171 static ssize_t
viafb_dvp1_proc_write(struct file
*file
,
1172 const char __user
*buffer
, size_t count
, loff_t
*pos
)
1174 char buf
[20], *value
, *pbuf
;
1176 unsigned long length
, i
;
1179 length
= count
> 20 ? 20 : count
;
1180 if (copy_from_user(&buf
[0], buffer
, length
))
1182 buf
[length
- 1] = '\0'; /*Ensure end string */
1184 for (i
= 0; i
< 3; i
++) {
1185 value
= strsep(&pbuf
, " ");
1186 if (value
!= NULL
) {
1187 strict_strtoul(value
, 0, (unsigned long *)®_val
);
1190 viafb_write_reg_mask(CR9B
, VIACR
,
1194 viafb_write_reg_mask(SR65
, VIASR
,
1195 reg_val
<< 2, 0x0c);
1198 viafb_write_reg_mask(SR65
, VIASR
,
1211 static const struct file_operations viafb_dvp1_proc_fops
= {
1212 .owner
= THIS_MODULE
,
1213 .open
= viafb_dvp1_proc_open
,
1215 .llseek
= seq_lseek
,
1216 .release
= single_release
,
1217 .write
= viafb_dvp1_proc_write
,
1220 static int viafb_dfph_proc_show(struct seq_file
*m
, void *v
)
1223 dfp_high
= viafb_read_reg(VIACR
, CR97
) & 0x0f;
1224 seq_printf(m
, "%x\n", dfp_high
);
1228 static int viafb_dfph_proc_open(struct inode
*inode
, struct file
*file
)
1230 return single_open(file
, viafb_dfph_proc_show
, NULL
);
1233 static ssize_t
viafb_dfph_proc_write(struct file
*file
,
1234 const char __user
*buffer
, size_t count
, loff_t
*pos
)
1238 unsigned long length
;
1241 length
= count
> 20 ? 20 : count
;
1242 if (copy_from_user(&buf
[0], buffer
, length
))
1244 buf
[length
- 1] = '\0'; /*Ensure end string */
1245 strict_strtoul(&buf
[0], 0, (unsigned long *)®_val
);
1246 viafb_write_reg_mask(CR97
, VIACR
, reg_val
, 0x0f);
1250 static const struct file_operations viafb_dfph_proc_fops
= {
1251 .owner
= THIS_MODULE
,
1252 .open
= viafb_dfph_proc_open
,
1254 .llseek
= seq_lseek
,
1255 .release
= single_release
,
1256 .write
= viafb_dfph_proc_write
,
1259 static int viafb_dfpl_proc_show(struct seq_file
*m
, void *v
)
1262 dfp_low
= viafb_read_reg(VIACR
, CR99
) & 0x0f;
1263 seq_printf(m
, "%x\n", dfp_low
);
1267 static int viafb_dfpl_proc_open(struct inode
*inode
, struct file
*file
)
1269 return single_open(file
, viafb_dfpl_proc_show
, NULL
);
1272 static ssize_t
viafb_dfpl_proc_write(struct file
*file
,
1273 const char __user
*buffer
, size_t count
, loff_t
*pos
)
1277 unsigned long length
;
1280 length
= count
> 20 ? 20 : count
;
1281 if (copy_from_user(&buf
[0], buffer
, length
))
1283 buf
[length
- 1] = '\0'; /*Ensure end string */
1284 strict_strtoul(&buf
[0], 0, (unsigned long *)®_val
);
1285 viafb_write_reg_mask(CR99
, VIACR
, reg_val
, 0x0f);
1289 static const struct file_operations viafb_dfpl_proc_fops
= {
1290 .owner
= THIS_MODULE
,
1291 .open
= viafb_dfpl_proc_open
,
1293 .llseek
= seq_lseek
,
1294 .release
= single_release
,
1295 .write
= viafb_dfpl_proc_write
,
1298 static int viafb_vt1636_proc_show(struct seq_file
*m
, void *v
)
1300 u8 vt1636_08
= 0, vt1636_09
= 0;
1301 switch (viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
) {
1304 viafb_gpio_i2c_read_lvds(viaparinfo
->lvds_setting_info
,
1305 &viaparinfo
->chip_info
->lvds_chip_info
, 0x08) & 0x0f;
1307 viafb_gpio_i2c_read_lvds(viaparinfo
->lvds_setting_info
,
1308 &viaparinfo
->chip_info
->lvds_chip_info
, 0x09) & 0x1f;
1309 seq_printf(m
, "%x %x\n", vt1636_08
, vt1636_09
);
1314 switch (viaparinfo
->chip_info
->lvds_chip_info2
.lvds_chip_name
) {
1317 viafb_gpio_i2c_read_lvds(viaparinfo
->lvds_setting_info2
,
1318 &viaparinfo
->chip_info
->lvds_chip_info2
, 0x08) & 0x0f;
1320 viafb_gpio_i2c_read_lvds(viaparinfo
->lvds_setting_info2
,
1321 &viaparinfo
->chip_info
->lvds_chip_info2
, 0x09) & 0x1f;
1322 seq_printf(m
, " %x %x\n", vt1636_08
, vt1636_09
);
1330 static int viafb_vt1636_proc_open(struct inode
*inode
, struct file
*file
)
1332 return single_open(file
, viafb_vt1636_proc_show
, NULL
);
1335 static ssize_t
viafb_vt1636_proc_write(struct file
*file
,
1336 const char __user
*buffer
, size_t count
, loff_t
*pos
)
1338 char buf
[30], *value
, *pbuf
;
1339 struct IODATA reg_val
;
1340 unsigned long length
, i
;
1343 length
= count
> 30 ? 30 : count
;
1344 if (copy_from_user(&buf
[0], buffer
, length
))
1346 buf
[length
- 1] = '\0'; /*Ensure end string */
1348 switch (viaparinfo
->chip_info
->lvds_chip_info
.lvds_chip_name
) {
1350 for (i
= 0; i
< 2; i
++) {
1351 value
= strsep(&pbuf
, " ");
1352 if (value
!= NULL
) {
1353 strict_strtoul(value
, 0,
1354 (unsigned long *)®_val
.Data
);
1357 reg_val
.Index
= 0x08;
1358 reg_val
.Mask
= 0x0f;
1359 viafb_gpio_i2c_write_mask_lvds
1360 (viaparinfo
->lvds_setting_info
,
1362 chip_info
->lvds_chip_info
,
1366 reg_val
.Index
= 0x09;
1367 reg_val
.Mask
= 0x1f;
1368 viafb_gpio_i2c_write_mask_lvds
1369 (viaparinfo
->lvds_setting_info
,
1371 chip_info
->lvds_chip_info
,
1385 switch (viaparinfo
->chip_info
->lvds_chip_info2
.lvds_chip_name
) {
1387 for (i
= 0; i
< 2; i
++) {
1388 value
= strsep(&pbuf
, " ");
1389 if (value
!= NULL
) {
1390 strict_strtoul(value
, 0,
1391 (unsigned long *)®_val
.Data
);
1394 reg_val
.Index
= 0x08;
1395 reg_val
.Mask
= 0x0f;
1396 viafb_gpio_i2c_write_mask_lvds
1397 (viaparinfo
->lvds_setting_info2
,
1399 chip_info
->lvds_chip_info2
,
1403 reg_val
.Index
= 0x09;
1404 reg_val
.Mask
= 0x1f;
1405 viafb_gpio_i2c_write_mask_lvds
1406 (viaparinfo
->lvds_setting_info2
,
1408 chip_info
->lvds_chip_info2
,
1425 static const struct file_operations viafb_vt1636_proc_fops
= {
1426 .owner
= THIS_MODULE
,
1427 .open
= viafb_vt1636_proc_open
,
1429 .llseek
= seq_lseek
,
1430 .release
= single_release
,
1431 .write
= viafb_vt1636_proc_write
,
1434 static void viafb_init_proc(struct proc_dir_entry
**viafb_entry
)
1436 *viafb_entry
= proc_mkdir("viafb", NULL
);
1438 proc_create("dvp0", 0, *viafb_entry
, &viafb_dvp0_proc_fops
);
1439 proc_create("dvp1", 0, *viafb_entry
, &viafb_dvp1_proc_fops
);
1440 proc_create("dfph", 0, *viafb_entry
, &viafb_dfph_proc_fops
);
1441 proc_create("dfpl", 0, *viafb_entry
, &viafb_dfpl_proc_fops
);
1442 if (VT1636_LVDS
== viaparinfo
->chip_info
->lvds_chip_info
.
1443 lvds_chip_name
|| VT1636_LVDS
==
1444 viaparinfo
->chip_info
->lvds_chip_info2
.lvds_chip_name
) {
1445 proc_create("vt1636", 0, *viafb_entry
, &viafb_vt1636_proc_fops
);
1450 static void viafb_remove_proc(struct proc_dir_entry
*viafb_entry
)
1452 struct chip_information
*chip_info
= &viaparinfo
->shared
->chip_info
;
1454 remove_proc_entry("dvp0", viafb_entry
);/* parent dir */
1455 remove_proc_entry("dvp1", viafb_entry
);
1456 remove_proc_entry("dfph", viafb_entry
);
1457 remove_proc_entry("dfpl", viafb_entry
);
1458 if (chip_info
->lvds_chip_info
.lvds_chip_name
== VT1636_LVDS
1459 || chip_info
->lvds_chip_info2
.lvds_chip_name
== VT1636_LVDS
)
1460 remove_proc_entry("vt1636", viafb_entry
);
1462 remove_proc_entry("viafb", NULL
);
1465 #endif /* CONFIG_FB_VIA_DIRECT_PROCFS */
1467 static int parse_mode(const char *str
, u32
*xres
, u32
*yres
)
1477 *xres
= simple_strtoul(str
, &ptr
, 10);
1481 *yres
= simple_strtoul(&ptr
[1], &ptr
, 10);
1489 int __devinit
via_fb_pci_probe(struct viafb_dev
*vdev
)
1491 u32 default_xres
, default_yres
;
1492 struct VideoModeTable
*vmode_entry
;
1493 struct fb_var_screeninfo default_var
;
1495 u32 viafb_par_length
;
1497 DEBUG_MSG(KERN_INFO
"VIAFB PCI Probe!!\n");
1498 memset(&default_var
, 0, sizeof(default_var
));
1499 viafb_par_length
= ALIGN(sizeof(struct viafb_par
), BITS_PER_LONG
/8);
1501 /* Allocate fb_info and ***_par here, also including some other needed
1504 viafbinfo
= framebuffer_alloc(viafb_par_length
+
1505 ALIGN(sizeof(struct viafb_shared
), BITS_PER_LONG
/8),
1508 printk(KERN_ERR
"Could not allocate memory for viafb_info.\n");
1512 viaparinfo
= (struct viafb_par
*)viafbinfo
->par
;
1513 viaparinfo
->shared
= viafbinfo
->par
+ viafb_par_length
;
1514 viaparinfo
->shared
->vdev
= vdev
;
1515 viaparinfo
->vram_addr
= 0;
1516 viaparinfo
->tmds_setting_info
= &viaparinfo
->shared
->tmds_setting_info
;
1517 viaparinfo
->lvds_setting_info
= &viaparinfo
->shared
->lvds_setting_info
;
1518 viaparinfo
->lvds_setting_info2
=
1519 &viaparinfo
->shared
->lvds_setting_info2
;
1520 viaparinfo
->crt_setting_info
= &viaparinfo
->shared
->crt_setting_info
;
1521 viaparinfo
->chip_info
= &viaparinfo
->shared
->chip_info
;
1528 viafb_init_chip_info(vdev
->chip_type
);
1530 * The framebuffer will have been successfully mapped by
1531 * the core (or we'd not be here), but we still need to
1532 * set up our own accounting.
1534 viaparinfo
->fbmem
= vdev
->fbmem_start
;
1535 viaparinfo
->memsize
= vdev
->fbmem_len
;
1536 viaparinfo
->fbmem_free
= viaparinfo
->memsize
;
1537 viaparinfo
->fbmem_used
= 0;
1538 viafbinfo
->screen_base
= vdev
->fbmem
;
1540 viafbinfo
->fix
.mmio_start
= vdev
->engine_start
;
1541 viafbinfo
->fix
.mmio_len
= vdev
->engine_len
;
1542 viafbinfo
->node
= 0;
1543 viafbinfo
->fbops
= &viafb_ops
;
1544 viafbinfo
->flags
= FBINFO_DEFAULT
| FBINFO_HWACCEL_YPAN
;
1546 viafbinfo
->pseudo_palette
= pseudo_pal
;
1547 if (viafb_accel
&& !viafb_init_engine(viafbinfo
)) {
1548 viafbinfo
->flags
|= FBINFO_HWACCEL_COPYAREA
|
1549 FBINFO_HWACCEL_FILLRECT
| FBINFO_HWACCEL_IMAGEBLIT
;
1550 default_var
.accel_flags
= FB_ACCELF_TEXT
;
1552 viafbinfo
->flags
|= FBINFO_HWACCEL_DISABLED
;
1553 default_var
.accel_flags
= 0;
1556 if (viafb_second_size
&& (viafb_second_size
< 8)) {
1557 viafb_second_offset
= viaparinfo
->fbmem_free
-
1558 viafb_second_size
* 1024 * 1024;
1560 viafb_second_size
= 8;
1561 viafb_second_offset
= viaparinfo
->fbmem_free
-
1562 viafb_second_size
* 1024 * 1024;
1565 parse_mode(viafb_mode
, &default_xres
, &default_yres
);
1566 vmode_entry
= viafb_get_mode(default_xres
, default_yres
);
1567 if (viafb_SAMM_ON
== 1) {
1568 parse_mode(viafb_mode1
, &viafb_second_xres
,
1569 &viafb_second_yres
);
1571 viafb_second_virtual_xres
= viafb_second_xres
;
1572 viafb_second_virtual_yres
= viafb_second_yres
;
1575 default_var
.xres
= default_xres
;
1576 default_var
.yres
= default_yres
;
1577 default_var
.xres_virtual
= default_xres
;
1578 default_var
.yres_virtual
= default_yres
;
1579 default_var
.bits_per_pixel
= viafb_bpp
;
1580 default_var
.pixclock
=
1581 viafb_get_pixclock(default_xres
, default_yres
, viafb_refresh
);
1582 default_var
.left_margin
= (default_xres
>> 3) & 0xf8;
1583 default_var
.right_margin
= 32;
1584 default_var
.upper_margin
= 16;
1585 default_var
.lower_margin
= 4;
1586 default_var
.hsync_len
= default_var
.left_margin
;
1587 default_var
.vsync_len
= 4;
1588 viafb_setup_fixinfo(&viafbinfo
->fix
, viaparinfo
);
1589 viafbinfo
->var
= default_var
;
1591 if (viafb_dual_fb
) {
1592 viafbinfo1
= framebuffer_alloc(viafb_par_length
,
1596 "allocate the second framebuffer struct error\n");
1598 goto out_fb_release
;
1600 viaparinfo1
= viafbinfo1
->par
;
1601 memcpy(viaparinfo1
, viaparinfo
, viafb_par_length
);
1602 viaparinfo1
->vram_addr
= viafb_second_offset
;
1603 viaparinfo1
->memsize
= viaparinfo
->memsize
-
1604 viafb_second_offset
;
1605 viaparinfo
->memsize
= viafb_second_offset
;
1606 viaparinfo1
->fbmem
= viaparinfo
->fbmem
+ viafb_second_offset
;
1608 viaparinfo1
->fbmem_used
= viaparinfo
->fbmem_used
;
1609 viaparinfo1
->fbmem_free
= viaparinfo1
->memsize
-
1610 viaparinfo1
->fbmem_used
;
1611 viaparinfo
->fbmem_free
= viaparinfo
->memsize
;
1612 viaparinfo
->fbmem_used
= 0;
1614 viaparinfo
->iga_path
= IGA1
;
1615 viaparinfo1
->iga_path
= IGA2
;
1616 memcpy(viafbinfo1
, viafbinfo
, sizeof(struct fb_info
));
1617 viafbinfo1
->par
= viaparinfo1
;
1618 viafbinfo1
->screen_base
= viafbinfo
->screen_base
+
1619 viafb_second_offset
;
1621 default_var
.xres
= viafb_second_xres
;
1622 default_var
.yres
= viafb_second_yres
;
1623 default_var
.xres_virtual
= viafb_second_virtual_xres
;
1624 default_var
.yres_virtual
= viafb_second_virtual_yres
;
1625 default_var
.bits_per_pixel
= viafb_bpp1
;
1626 default_var
.pixclock
=
1627 viafb_get_pixclock(viafb_second_xres
, viafb_second_yres
,
1629 default_var
.left_margin
= (viafb_second_xres
>> 3) & 0xf8;
1630 default_var
.right_margin
= 32;
1631 default_var
.upper_margin
= 16;
1632 default_var
.lower_margin
= 4;
1633 default_var
.hsync_len
= default_var
.left_margin
;
1634 default_var
.vsync_len
= 4;
1636 viafb_setup_fixinfo(&viafbinfo1
->fix
, viaparinfo1
);
1637 viafb_check_var(&default_var
, viafbinfo1
);
1638 viafbinfo1
->var
= default_var
;
1639 viafb_update_fix(viafbinfo1
);
1640 viaparinfo1
->depth
= fb_get_color_depth(&viafbinfo1
->var
,
1644 viafb_check_var(&viafbinfo
->var
, viafbinfo
);
1645 viafb_update_fix(viafbinfo
);
1646 viaparinfo
->depth
= fb_get_color_depth(&viafbinfo
->var
,
1648 default_var
.activate
= FB_ACTIVATE_NOW
;
1649 rc
= fb_alloc_cmap(&viafbinfo
->cmap
, 256, 0);
1651 goto out_fb1_release
;
1653 if (viafb_dual_fb
&& (viafb_primary_dev
== LCD_Device
)
1654 && (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_CLE266
)) {
1655 rc
= register_framebuffer(viafbinfo1
);
1657 goto out_dealloc_cmap
;
1659 rc
= register_framebuffer(viafbinfo
);
1661 goto out_fb1_unreg_lcd_cle266
;
1663 if (viafb_dual_fb
&& ((viafb_primary_dev
!= LCD_Device
)
1664 || (viaparinfo
->chip_info
->gfx_chip_name
!=
1665 UNICHROME_CLE266
))) {
1666 rc
= register_framebuffer(viafbinfo1
);
1670 DEBUG_MSG(KERN_INFO
"fb%d: %s frame buffer device %dx%d-%dbpp\n",
1671 viafbinfo
->node
, viafbinfo
->fix
.id
, default_var
.xres
,
1672 default_var
.yres
, default_var
.bits_per_pixel
);
1674 #ifdef CONFIG_FB_VIA_DIRECT_PROCFS
1675 viafb_init_proc(&viaparinfo
->shared
->proc_entry
);
1677 viafb_init_dac(IGA2
);
1681 unregister_framebuffer(viafbinfo
);
1682 out_fb1_unreg_lcd_cle266
:
1683 if (viafb_dual_fb
&& (viafb_primary_dev
== LCD_Device
)
1684 && (viaparinfo
->chip_info
->gfx_chip_name
== UNICHROME_CLE266
))
1685 unregister_framebuffer(viafbinfo1
);
1687 fb_dealloc_cmap(&viafbinfo
->cmap
);
1690 framebuffer_release(viafbinfo1
);
1692 framebuffer_release(viafbinfo
);
1696 void __devexit
via_fb_pci_remove(struct pci_dev
*pdev
)
1698 DEBUG_MSG(KERN_INFO
"via_pci_remove!\n");
1699 fb_dealloc_cmap(&viafbinfo
->cmap
);
1700 unregister_framebuffer(viafbinfo
);
1702 unregister_framebuffer(viafbinfo1
);
1703 #ifdef CONFIG_FB_VIA_DIRECT_PROCFS
1704 viafb_remove_proc(viaparinfo
->shared
->proc_entry
);
1706 framebuffer_release(viafbinfo
);
1708 framebuffer_release(viafbinfo1
);
1712 static int __init
viafb_setup(char *options
)
1715 DEBUG_MSG(KERN_INFO
"viafb_setup!\n");
1717 if (!options
|| !*options
)
1720 while ((this_opt
= strsep(&options
, ",")) != NULL
) {
1724 if (!strncmp(this_opt
, "viafb_mode1=", 12))
1725 viafb_mode1
= kstrdup(this_opt
+ 12, GFP_KERNEL
);
1726 else if (!strncmp(this_opt
, "viafb_mode=", 11))
1727 viafb_mode
= kstrdup(this_opt
+ 11, GFP_KERNEL
);
1728 else if (!strncmp(this_opt
, "viafb_bpp1=", 11))
1729 strict_strtoul(this_opt
+ 11, 0,
1730 (unsigned long *)&viafb_bpp1
);
1731 else if (!strncmp(this_opt
, "viafb_bpp=", 10))
1732 strict_strtoul(this_opt
+ 10, 0,
1733 (unsigned long *)&viafb_bpp
);
1734 else if (!strncmp(this_opt
, "viafb_refresh1=", 15))
1735 strict_strtoul(this_opt
+ 15, 0,
1736 (unsigned long *)&viafb_refresh1
);
1737 else if (!strncmp(this_opt
, "viafb_refresh=", 14))
1738 strict_strtoul(this_opt
+ 14, 0,
1739 (unsigned long *)&viafb_refresh
);
1740 else if (!strncmp(this_opt
, "viafb_lcd_dsp_method=", 21))
1741 strict_strtoul(this_opt
+ 21, 0,
1742 (unsigned long *)&viafb_lcd_dsp_method
);
1743 else if (!strncmp(this_opt
, "viafb_lcd_panel_id=", 19))
1744 strict_strtoul(this_opt
+ 19, 0,
1745 (unsigned long *)&viafb_lcd_panel_id
);
1746 else if (!strncmp(this_opt
, "viafb_accel=", 12))
1747 strict_strtoul(this_opt
+ 12, 0,
1748 (unsigned long *)&viafb_accel
);
1749 else if (!strncmp(this_opt
, "viafb_SAMM_ON=", 14))
1750 strict_strtoul(this_opt
+ 14, 0,
1751 (unsigned long *)&viafb_SAMM_ON
);
1752 else if (!strncmp(this_opt
, "viafb_active_dev=", 17))
1753 viafb_active_dev
= kstrdup(this_opt
+ 17, GFP_KERNEL
);
1754 else if (!strncmp(this_opt
,
1755 "viafb_display_hardware_layout=", 30))
1756 strict_strtoul(this_opt
+ 30, 0,
1757 (unsigned long *)&viafb_display_hardware_layout
);
1758 else if (!strncmp(this_opt
, "viafb_second_size=", 18))
1759 strict_strtoul(this_opt
+ 18, 0,
1760 (unsigned long *)&viafb_second_size
);
1761 else if (!strncmp(this_opt
,
1762 "viafb_platform_epia_dvi=", 24))
1763 strict_strtoul(this_opt
+ 24, 0,
1764 (unsigned long *)&viafb_platform_epia_dvi
);
1765 else if (!strncmp(this_opt
,
1766 "viafb_device_lcd_dualedge=", 26))
1767 strict_strtoul(this_opt
+ 26, 0,
1768 (unsigned long *)&viafb_device_lcd_dualedge
);
1769 else if (!strncmp(this_opt
, "viafb_bus_width=", 16))
1770 strict_strtoul(this_opt
+ 16, 0,
1771 (unsigned long *)&viafb_bus_width
);
1772 else if (!strncmp(this_opt
, "viafb_lcd_mode=", 15))
1773 strict_strtoul(this_opt
+ 15, 0,
1774 (unsigned long *)&viafb_lcd_mode
);
1775 else if (!strncmp(this_opt
, "viafb_lcd_port=", 15))
1776 viafb_lcd_port
= kstrdup(this_opt
+ 15, GFP_KERNEL
);
1777 else if (!strncmp(this_opt
, "viafb_dvi_port=", 15))
1778 viafb_dvi_port
= kstrdup(this_opt
+ 15, GFP_KERNEL
);
1785 * These are called out of via-core for now.
1787 int __init
viafb_init(void)
1791 char *option
= NULL
;
1792 if (fb_get_options("viafb", &option
))
1794 viafb_setup(option
);
1796 if (parse_mode(viafb_mode
, &dummy
, &dummy
)
1797 || parse_mode(viafb_mode1
, &dummy
, &dummy
)
1798 || viafb_bpp
< 0 || viafb_bpp
> 32
1799 || viafb_bpp1
< 0 || viafb_bpp1
> 32
1800 || parse_active_dev())
1804 "VIA Graphics Intergration Chipset framebuffer %d.%d initializing\n",
1805 VERSION_MAJOR
, VERSION_MINOR
);
1809 void __exit
viafb_exit(void)
1811 DEBUG_MSG(KERN_INFO
"viafb_exit!\n");
1814 static struct fb_ops viafb_ops
= {
1815 .owner
= THIS_MODULE
,
1816 .fb_open
= viafb_open
,
1817 .fb_release
= viafb_release
,
1818 .fb_check_var
= viafb_check_var
,
1819 .fb_set_par
= viafb_set_par
,
1820 .fb_setcolreg
= viafb_setcolreg
,
1821 .fb_pan_display
= viafb_pan_display
,
1822 .fb_blank
= viafb_blank
,
1823 .fb_fillrect
= viafb_fillrect
,
1824 .fb_copyarea
= viafb_copyarea
,
1825 .fb_imageblit
= viafb_imageblit
,
1826 .fb_cursor
= viafb_cursor
,
1827 .fb_ioctl
= viafb_ioctl
,
1828 .fb_sync
= viafb_sync
,
1833 module_param(viafb_mode
, charp
, S_IRUSR
);
1834 MODULE_PARM_DESC(viafb_mode
, "Set resolution (default=640x480)");
1836 module_param(viafb_mode1
, charp
, S_IRUSR
);
1837 MODULE_PARM_DESC(viafb_mode1
, "Set resolution (default=640x480)");
1839 module_param(viafb_bpp
, int, S_IRUSR
);
1840 MODULE_PARM_DESC(viafb_bpp
, "Set color depth (default=32bpp)");
1842 module_param(viafb_bpp1
, int, S_IRUSR
);
1843 MODULE_PARM_DESC(viafb_bpp1
, "Set color depth (default=32bpp)");
1845 module_param(viafb_refresh
, int, S_IRUSR
);
1846 MODULE_PARM_DESC(viafb_refresh
,
1847 "Set CRT viafb_refresh rate (default = 60)");
1849 module_param(viafb_refresh1
, int, S_IRUSR
);
1850 MODULE_PARM_DESC(viafb_refresh1
,
1851 "Set CRT refresh rate (default = 60)");
1853 module_param(viafb_lcd_panel_id
, int, S_IRUSR
);
1854 MODULE_PARM_DESC(viafb_lcd_panel_id
,
1855 "Set Flat Panel type(Default=1024x768)");
1857 module_param(viafb_lcd_dsp_method
, int, S_IRUSR
);
1858 MODULE_PARM_DESC(viafb_lcd_dsp_method
,
1859 "Set Flat Panel display scaling method.(Default=Expandsion)");
1861 module_param(viafb_SAMM_ON
, int, S_IRUSR
);
1862 MODULE_PARM_DESC(viafb_SAMM_ON
,
1863 "Turn on/off flag of SAMM(Default=OFF)");
1865 module_param(viafb_accel
, int, S_IRUSR
);
1866 MODULE_PARM_DESC(viafb_accel
,
1867 "Set 2D Hardware Acceleration: 0 = OFF, 1 = ON (default)");
1869 module_param(viafb_active_dev
, charp
, S_IRUSR
);
1870 MODULE_PARM_DESC(viafb_active_dev
, "Specify active devices.");
1872 module_param(viafb_display_hardware_layout
, int, S_IRUSR
);
1873 MODULE_PARM_DESC(viafb_display_hardware_layout
,
1874 "Display Hardware Layout (LCD Only, DVI Only...,etc)");
1876 module_param(viafb_second_size
, int, S_IRUSR
);
1877 MODULE_PARM_DESC(viafb_second_size
,
1878 "Set secondary device memory size");
1880 module_param(viafb_dual_fb
, int, S_IRUSR
);
1881 MODULE_PARM_DESC(viafb_dual_fb
,
1882 "Turn on/off flag of dual framebuffer devices.(Default = OFF)");
1884 module_param(viafb_platform_epia_dvi
, int, S_IRUSR
);
1885 MODULE_PARM_DESC(viafb_platform_epia_dvi
,
1886 "Turn on/off flag of DVI devices on EPIA board.(Default = OFF)");
1888 module_param(viafb_device_lcd_dualedge
, int, S_IRUSR
);
1889 MODULE_PARM_DESC(viafb_device_lcd_dualedge
,
1890 "Turn on/off flag of dual edge panel.(Default = OFF)");
1892 module_param(viafb_bus_width
, int, S_IRUSR
);
1893 MODULE_PARM_DESC(viafb_bus_width
,
1894 "Set bus width of panel.(Default = 12)");
1896 module_param(viafb_lcd_mode
, int, S_IRUSR
);
1897 MODULE_PARM_DESC(viafb_lcd_mode
,
1898 "Set Flat Panel mode(Default=OPENLDI)");
1900 module_param(viafb_lcd_port
, charp
, S_IRUSR
);
1901 MODULE_PARM_DESC(viafb_lcd_port
, "Specify LCD output port.");
1903 module_param(viafb_dvi_port
, charp
, S_IRUSR
);
1904 MODULE_PARM_DESC(viafb_dvi_port
, "Specify DVI output port.");
1906 MODULE_LICENSE("GPL");