blob: ba8ce61140c9a6e99483dc525915f3d64eb60552 [file] [log] [blame]
Joseph Chan29b619f2008-10-15 22:03:27 -07001/*
2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
4
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.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
14 * for more details.
15
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22#include <linux/module.h>
23#define _MASTER_FILE
24
25#include "global.h"
26
27static int MAX_CURS = 32;
28static struct fb_var_screeninfo default_var;
29static char *viafb_name = "Via";
30static u32 pseudo_pal[17];
31
32/* video mode */
33static char *viafb_mode = "640x480";
34static char *viafb_mode1 = "640x480";
35static int viafb_resMode = VIA_RES_640X480;
36
37/* Added for specifying active devices.*/
38char *viafb_active_dev = "";
39
40/* Added for specifying video on devices.*/
41char *viafb_video_dev = "";
42
43/*Added for specify lcd output port*/
44char *viafb_lcd_port = "";
45char *viafb_dvi_port = "";
46
47static void viafb_set_device(struct device_t active_dev);
48static int apply_device_setting(struct viafb_ioctl_setting setting_info,
49 struct fb_info *info);
50static void apply_second_mode_setting(struct fb_var_screeninfo
51 *sec_var);
52static void retrieve_device_setting(struct viafb_ioctl_setting
53 *setting_info);
54static void viafb_set_video_device(u32 video_dev_info);
55static void viafb_get_video_device(u32 *video_dev_info);
56
57/* Mode information */
58static const struct viafb_modeinfo viafb_modentry[] = {
59 {480, 640, VIA_RES_480X640, "480x640"},
60 {640, 480, VIA_RES_640X480, "640x480"},
61 {800, 480, VIA_RES_800X480, "800x480"},
62 {800, 600, VIA_RES_800X600, "800x600"},
63 {1024, 768, VIA_RES_1024X768, "1024x768"},
64 {1152, 864, VIA_RES_1152X864, "1152x864"},
65 {1280, 1024, VIA_RES_1280X1024, "1280x1024"},
66 {1600, 1200, VIA_RES_1600X1200, "1600x1200"},
67 {1440, 1050, VIA_RES_1440X1050, "1440x1050"},
68 {1280, 768, VIA_RES_1280X768, "1280x768"},
69 {1280, 800, VIA_RES_1280X800, "1280x800"},
70 {1280, 960, VIA_RES_1280X960, "1280x960"},
71 {1920, 1440, VIA_RES_1920X1440, "1920x1440"},
72 {848, 480, VIA_RES_848X480, "848x480"},
73 {1400, 1050, VIA_RES_1400X1050, "1400x1050"},
74 {720, 480, VIA_RES_720X480, "720x480"},
75 {720, 576, VIA_RES_720X576, "720x576"},
76 {1024, 512, VIA_RES_1024X512, "1024x512"},
77 {1024, 576, VIA_RES_1024X576, "1024x576"},
78 {1024, 600, VIA_RES_1024X600, "1024x600"},
79 {1280, 720, VIA_RES_1280X720, "1280x720"},
80 {1920, 1080, VIA_RES_1920X1080, "1920x1080"},
81 {1366, 768, VIA_RES_1368X768, "1368x768"},
82 {1680, 1050, VIA_RES_1680X1050, "1680x1050"},
83 {960, 600, VIA_RES_960X600, "960x600"},
84 {1000, 600, VIA_RES_1000X600, "1000x600"},
85 {1024, 576, VIA_RES_1024X576, "1024x576"},
86 {1024, 600, VIA_RES_1024X600, "1024x600"},
87 {1088, 612, VIA_RES_1088X612, "1088x612"},
88 {1152, 720, VIA_RES_1152X720, "1152x720"},
89 {1200, 720, VIA_RES_1200X720, "1200x720"},
90 {1280, 600, VIA_RES_1280X600, "1280x600"},
91 {1360, 768, VIA_RES_1360X768, "1360x768"},
92 {1440, 900, VIA_RES_1440X900, "1440x900"},
93 {1600, 900, VIA_RES_1600X900, "1600x900"},
94 {1600, 1024, VIA_RES_1600X1024, "1600x1024"},
95 {1792, 1344, VIA_RES_1792X1344, "1792x1344"},
96 {1856, 1392, VIA_RES_1856X1392, "1856x1392"},
97 {1920, 1200, VIA_RES_1920X1200, "1920x1200"},
98 {2048, 1536, VIA_RES_2048X1536, "2048x1536"},
99 {0, 0, VIA_RES_INVALID, "640x480"}
100};
101
102static struct fb_ops viafb_ops;
103
104static int viafb_update_fix(struct fb_fix_screeninfo *fix, struct fb_info *info)
105{
106 struct viafb_par *ppar;
107 ppar = info->par;
108
109 DEBUG_MSG(KERN_INFO "viafb_update_fix!\n");
110
111 fix->visual =
112 ppar->bpp == 8 ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
113 fix->line_length = ppar->linelength;
114
115 return 0;
116}
117
118
119static void viafb_setup_fixinfo(struct fb_fix_screeninfo *fix,
120 struct viafb_par *viaparinfo)
121{
122 memset(fix, 0, sizeof(struct fb_fix_screeninfo));
123 strcpy(fix->id, viafb_name);
124
125 fix->smem_start = viaparinfo->fbmem;
126 fix->smem_len = viaparinfo->fbmem_free;
127 fix->mmio_start = viaparinfo->mmio_base;
128 fix->mmio_len = viaparinfo->mmio_len;
129
130 fix->type = FB_TYPE_PACKED_PIXELS;
131 fix->type_aux = 0;
132
133 fix->xpanstep = fix->ywrapstep = 0;
134 fix->ypanstep = 1;
135
136 /* Just tell the accel name */
137 viafbinfo->fix.accel = FB_ACCEL_VIA_UNICHROME;
138}
139static int viafb_open(struct fb_info *info, int user)
140{
141 DEBUG_MSG(KERN_INFO "viafb_open!\n");
142 return 0;
143}
144
145static int viafb_release(struct fb_info *info, int user)
146{
147 DEBUG_MSG(KERN_INFO "viafb_release!\n");
148 return 0;
149}
150
151static void viafb_update_viafb_par(struct fb_info *info)
152{
153 struct viafb_par *ppar;
154
155 ppar = info->par;
156 ppar->bpp = info->var.bits_per_pixel;
157 ppar->linelength = ((info->var.xres_virtual + 7) & ~7) * ppar->bpp / 8;
158 ppar->hres = info->var.xres;
159 ppar->vres = info->var.yres;
160 ppar->xoffset = info->var.xoffset;
161 ppar->yoffset = info->var.yoffset;
162}
163
164static int viafb_check_var(struct fb_var_screeninfo *var,
165 struct fb_info *info)
166{
167 int vmode_index, htotal, vtotal;
168 struct viafb_par *ppar;
169 u32 long_refresh;
170 struct viafb_par *p_viafb_par;
171 ppar = info->par;
172
173
174 DEBUG_MSG(KERN_INFO "viafb_check_var!\n");
175 /* Sanity check */
176 /* HW neither support interlacte nor double-scaned mode */
177 if (var->vmode & FB_VMODE_INTERLACED || var->vmode & FB_VMODE_DOUBLE)
178 return -EINVAL;
179
180 vmode_index = viafb_get_mode_index(var->xres, var->yres, 0);
181 if (vmode_index == VIA_RES_INVALID) {
182 DEBUG_MSG(KERN_INFO
183 "viafb: Mode %dx%dx%d not supported!!\n",
184 var->xres, var->yres, var->bits_per_pixel);
185 return -EINVAL;
186 }
187
188 if (24 == var->bits_per_pixel)
189 var->bits_per_pixel = 32;
190
191 if (var->bits_per_pixel != 8 && var->bits_per_pixel != 16 &&
192 var->bits_per_pixel != 32)
193 return -EINVAL;
194
195 if ((var->xres_virtual * (var->bits_per_pixel >> 3)) & 0x1F)
196 /*32 pixel alignment */
197 var->xres_virtual = (var->xres_virtual + 31) & ~31;
198 if (var->xres_virtual * var->yres_virtual * var->bits_per_pixel / 8 >
199 ppar->memsize)
200 return -EINVAL;
201
202 /* Based on var passed in to calculate the refresh,
203 * because our driver use some modes special.
204 */
205 htotal = var->xres + var->left_margin +
206 var->right_margin + var->hsync_len;
207 vtotal = var->yres + var->upper_margin +
208 var->lower_margin + var->vsync_len;
209 long_refresh = 1000000000UL / var->pixclock * 1000;
210 long_refresh /= (htotal * vtotal);
211
212 viafb_refresh = viafb_get_refresh(var->xres, var->yres, long_refresh);
213
214 /* Adjust var according to our driver's own table */
215 viafb_fill_var_timing_info(var, viafb_refresh, vmode_index);
216
217 /* This is indeed a patch for VT3353 */
218 if (!info->par)
219 return -1;
220 p_viafb_par = (struct viafb_par *)info->par;
221 if (p_viafb_par->chip_info->gfx_chip_name == UNICHROME_VX800)
222 var->accel_flags = 0;
223
224 return 0;
225}
226
227static int viafb_set_par(struct fb_info *info)
228{
229 int vmode_index;
230 int vmode_index1 = 0;
231 DEBUG_MSG(KERN_INFO "viafb_set_par!\n");
232
233 viafb_update_device_setting(info->var.xres, info->var.yres,
234 info->var.bits_per_pixel, viafb_refresh, 0);
235
236 vmode_index = viafb_get_mode_index(info->var.xres, info->var.yres, 0);
237
238 if (viafb_SAMM_ON == 1) {
239 DEBUG_MSG(KERN_INFO
240 "viafb_second_xres = %d, viafb_second_yres = %d, bpp = %d\n",
241 viafb_second_xres, viafb_second_yres, viafb_bpp1);
242 vmode_index1 = viafb_get_mode_index(viafb_second_xres,
243 viafb_second_yres, 1);
244 DEBUG_MSG(KERN_INFO "->viafb_SAMM_ON: index=%d\n",
245 vmode_index1);
246
247 viafb_update_device_setting(viafb_second_xres,
248 viafb_second_yres, viafb_bpp1, viafb_refresh1, 1);
249 }
250
251 if (vmode_index != VIA_RES_INVALID) {
252 viafb_setmode(vmode_index, info->var.xres, info->var.yres,
253 info->var.bits_per_pixel, vmode_index1,
254 viafb_second_xres, viafb_second_yres, viafb_bpp1);
255
256 /*We should set memory offset according virtual_x */
257 /*Fix me:put this function into viafb_setmode */
258 viafb_memory_pitch_patch(info);
259
260 /* Update ***fb_par information */
261 viafb_update_viafb_par(info);
262
263 /* Update other fixed information */
264 viafb_update_fix(&info->fix, info);
265 viafb_bpp = info->var.bits_per_pixel;
266 /* Update viafb_accel, it is necessary to our 2D accelerate */
267 viafb_accel = info->var.accel_flags;
268
269 if (viafb_accel)
270 viafb_set_2d_color_depth(info->var.bits_per_pixel);
271 }
272
273 return 0;
274}
275
276/* Set one color register */
277static int viafb_setcolreg(unsigned regno, unsigned red, unsigned green,
278unsigned blue, unsigned transp, struct fb_info *info)
279{
280 u8 sr1a, sr1b, cr67, cr6a, rev = 0, shift = 10;
281 unsigned cmap_entries = (info->var.bits_per_pixel == 8) ? 256 : 16;
282 DEBUG_MSG(KERN_INFO "viafb_setcolreg!\n");
283 if (regno >= cmap_entries)
284 return 1;
285 if (UNICHROME_CLE266 == viaparinfo->chip_info->gfx_chip_name) {
286 /*
287 * Read PCI bus 0,dev 0,function 0,index 0xF6 to get chip rev.
288 */
289 outl(0x80000000 | (0xf6 & ~3), (unsigned long)0xCF8);
290 rev = (inl((unsigned long)0xCFC) >> ((0xf6 & 3) * 8)) & 0xff;
291 }
292 switch (info->var.bits_per_pixel) {
293 case 8:
294 outb(0x1A, 0x3C4);
295 sr1a = inb(0x3C5);
296 outb(0x1B, 0x3C4);
297 sr1b = inb(0x3C5);
298 outb(0x67, 0x3D4);
299 cr67 = inb(0x3D5);
300 outb(0x6A, 0x3D4);
301 cr6a = inb(0x3D5);
302
303 /* Map the 3C6/7/8/9 to the IGA2 */
304 outb(0x1A, 0x3C4);
305 outb(sr1a | 0x01, 0x3C5);
306 /* Second Display Engine colck always on */
307 outb(0x1B, 0x3C4);
308 outb(sr1b | 0x80, 0x3C5);
309 /* Second Display Color Depth 8 */
310 outb(0x67, 0x3D4);
311 outb(cr67 & 0x3F, 0x3D5);
312 outb(0x6A, 0x3D4);
313 /* Second Display Channel Reset CR6A[6]) */
314 outb(cr6a & 0xBF, 0x3D5);
315 /* Second Display Channel Enable CR6A[7] */
316 outb(cr6a | 0x80, 0x3D5);
317 /* Second Display Channel stop reset) */
318 outb(cr6a | 0x40, 0x3D5);
319
320 /* Bit mask of palette */
321 outb(0xFF, 0x3c6);
322 /* Write one register of IGA2 */
323 outb(regno, 0x3C8);
324 if (UNICHROME_CLE266 == viaparinfo->chip_info->gfx_chip_name &&
325 rev >= 15) {
326 shift = 8;
327 viafb_write_reg_mask(CR6A, VIACR, BIT5, BIT5);
328 viafb_write_reg_mask(SR15, VIASR, BIT7, BIT7);
329 } else {
330 shift = 10;
331 viafb_write_reg_mask(CR6A, VIACR, 0, BIT5);
332 viafb_write_reg_mask(SR15, VIASR, 0, BIT7);
333 }
334 outb(red >> shift, 0x3C9);
335 outb(green >> shift, 0x3C9);
336 outb(blue >> shift, 0x3C9);
337
338 /* Map the 3C6/7/8/9 to the IGA1 */
339 outb(0x1A, 0x3C4);
340 outb(sr1a & 0xFE, 0x3C5);
341 /* Bit mask of palette */
342 outb(0xFF, 0x3c6);
343 /* Write one register of IGA1 */
344 outb(regno, 0x3C8);
345 outb(red >> shift, 0x3C9);
346 outb(green >> shift, 0x3C9);
347 outb(blue >> shift, 0x3C9);
348
349 outb(0x1A, 0x3C4);
350 outb(sr1a, 0x3C5);
351 outb(0x1B, 0x3C4);
352 outb(sr1b, 0x3C5);
353 outb(0x67, 0x3D4);
354 outb(cr67, 0x3D5);
355 outb(0x6A, 0x3D4);
356 outb(cr6a, 0x3D5);
357 break;
358 case 16:
359 ((u32 *) info->pseudo_palette)[regno] = (red & 0xF800) |
360 ((green & 0xFC00) >> 5) | ((blue & 0xF800) >> 11);
361 break;
362 case 32:
363 ((u32 *) info->pseudo_palette)[regno] =
364 ((transp & 0xFF00) << 16) |
365 ((red & 0xFF00) << 8) |
366 ((green & 0xFF00)) | ((blue & 0xFF00) >> 8);
367 break;
368 }
369
370 return 0;
371
372}
373
374/*CALLED BY: fb_set_cmap */
375/* fb_set_var, pass 256 colors */
376/*CALLED BY: fb_set_cmap */
377/* fbcon_set_palette, pass 16 colors */
378static int viafb_setcmap(struct fb_cmap *cmap, struct fb_info *info)
379{
380 u32 len = cmap->len;
381 u32 i;
382 u16 *pred = cmap->red;
383 u16 *pgreen = cmap->green;
384 u16 *pblue = cmap->blue;
385 u16 *ptransp = cmap->transp;
386 u8 sr1a, sr1b, cr67, cr6a, rev = 0, shift = 10;
387 if (len > 256)
388 return 1;
389 if (UNICHROME_CLE266 == viaparinfo->chip_info->gfx_chip_name) {
390 /*
391 * Read PCI bus 0, dev 0, function 0, index 0xF6 to get chip
392 * rev.
393 */
394 outl(0x80000000 | (0xf6 & ~3), (unsigned long)0xCF8);
395 rev = (inl((unsigned long)0xCFC) >> ((0xf6 & 3) * 8)) & 0xff;
396 }
397 switch (info->var.bits_per_pixel) {
398 case 8:
399 outb(0x1A, 0x3C4);
400 sr1a = inb(0x3C5);
401 outb(0x1B, 0x3C4);
402 sr1b = inb(0x3C5);
403 outb(0x67, 0x3D4);
404 cr67 = inb(0x3D5);
405 outb(0x6A, 0x3D4);
406 cr6a = inb(0x3D5);
407 /* Map the 3C6/7/8/9 to the IGA2 */
408 outb(0x1A, 0x3C4);
409 outb(sr1a | 0x01, 0x3C5);
410 outb(0x1B, 0x3C4);
411 /* Second Display Engine colck always on */
412 outb(sr1b | 0x80, 0x3C5);
413 outb(0x67, 0x3D4);
414 /* Second Display Color Depth 8 */
415 outb(cr67 & 0x3F, 0x3D5);
416 outb(0x6A, 0x3D4);
417 /* Second Display Channel Reset CR6A[6]) */
418 outb(cr6a & 0xBF, 0x3D5);
419 /* Second Display Channel Enable CR6A[7] */
420 outb(cr6a | 0x80, 0x3D5);
421 /* Second Display Channel stop reset) */
422 outb(cr6a | 0xC0, 0x3D5);
423
424 /* Bit mask of palette */
425 outb(0xFF, 0x3c6);
426 outb(0x00, 0x3C8);
427 if (UNICHROME_CLE266 == viaparinfo->chip_info->gfx_chip_name &&
428 rev >= 15) {
429 shift = 8;
430 viafb_write_reg_mask(CR6A, VIACR, BIT5, BIT5);
431 viafb_write_reg_mask(SR15, VIASR, BIT7, BIT7);
432 } else {
433 shift = 10;
434 viafb_write_reg_mask(CR6A, VIACR, 0, BIT5);
435 viafb_write_reg_mask(SR15, VIASR, 0, BIT7);
436 }
437 for (i = 0; i < len; i++) {
438 outb((*(pred + i)) >> shift, 0x3C9);
439 outb((*(pgreen + i)) >> shift, 0x3C9);
440 outb((*(pblue + i)) >> shift, 0x3C9);
441 }
442
443 outb(0x1A, 0x3C4);
444 /* Map the 3C6/7/8/9 to the IGA1 */
445 outb(sr1a & 0xFE, 0x3C5);
446 /* Bit mask of palette */
447 outb(0xFF, 0x3c6);
448 outb(0x00, 0x3C8);
449 for (i = 0; i < len; i++) {
450 outb((*(pred + i)) >> shift, 0x3C9);
451 outb((*(pgreen + i)) >> shift, 0x3C9);
452 outb((*(pblue + i)) >> shift, 0x3C9);
453 }
454
455 outb(0x1A, 0x3C4);
456 outb(sr1a, 0x3C5);
457 outb(0x1B, 0x3C4);
458 outb(sr1b, 0x3C5);
459 outb(0x67, 0x3D4);
460 outb(cr67, 0x3D5);
461 outb(0x6A, 0x3D4);
462 outb(cr6a, 0x3D5);
463 break;
464 case 16:
465 if (len > 17)
466 return 0; /* Because static u32 pseudo_pal[17]; */
467 for (i = 0; i < len; i++)
468 ((u32 *) info->pseudo_palette)[i] =
469 (*(pred + i) & 0xF800) |
470 ((*(pgreen + i) & 0xFC00) >> 5) |
471 ((*(pblue + i) & 0xF800) >> 11);
472 break;
473 case 32:
474 if (len > 17)
475 return 0;
476 if (ptransp) {
477 for (i = 0; i < len; i++)
478 ((u32 *) info->pseudo_palette)[i] =
479 ((*(ptransp + i) & 0xFF00) << 16) |
480 ((*(pred + i) & 0xFF00) << 8) |
481 ((*(pgreen + i) & 0xFF00)) |
482 ((*(pblue + i) & 0xFF00) >> 8);
483 } else {
484 for (i = 0; i < len; i++)
485 ((u32 *) info->pseudo_palette)[i] =
486 0x00000000 |
487 ((*(pred + i) & 0xFF00) << 8) |
488 ((*(pgreen + i) & 0xFF00)) |
489 ((*(pblue + i) & 0xFF00) >> 8);
490 }
491 break;
492 }
493 return 0;
494}
495
496static int viafb_pan_display(struct fb_var_screeninfo *var,
497 struct fb_info *info)
498{
499 unsigned int offset;
500
501 DEBUG_MSG(KERN_INFO "viafb_pan_display!\n");
502
503 offset = (var->xoffset + (var->yoffset * var->xres_virtual)) *
504 var->bits_per_pixel / 16;
505
506 DEBUG_MSG(KERN_INFO "\nviafb_pan_display,offset =%d ", offset);
507
508 viafb_write_reg_mask(0x48, 0x3d4, ((offset >> 24) & 0x3), 0x3);
509 viafb_write_reg_mask(0x34, 0x3d4, ((offset >> 16) & 0xff), 0xff);
510 viafb_write_reg_mask(0x0c, 0x3d4, ((offset >> 8) & 0xff), 0xff);
511 viafb_write_reg_mask(0x0d, 0x3d4, (offset & 0xff), 0xff);
512
513 return 0;
514}
515
516static int viafb_blank(int blank_mode, struct fb_info *info)
517{
518 DEBUG_MSG(KERN_INFO "viafb_blank!\n");
519 /* clear DPMS setting */
520
521 switch (blank_mode) {
522 case FB_BLANK_UNBLANK:
523 /* Screen: On, HSync: On, VSync: On */
524 /* control CRT monitor power management */
525 viafb_write_reg_mask(CR36, VIACR, 0x00, BIT4 + BIT5);
526 break;
527 case FB_BLANK_HSYNC_SUSPEND:
528 /* Screen: Off, HSync: Off, VSync: On */
529 /* control CRT monitor power management */
530 viafb_write_reg_mask(CR36, VIACR, 0x10, BIT4 + BIT5);
531 break;
532 case FB_BLANK_VSYNC_SUSPEND:
533 /* Screen: Off, HSync: On, VSync: Off */
534 /* control CRT monitor power management */
535 viafb_write_reg_mask(CR36, VIACR, 0x20, BIT4 + BIT5);
536 break;
537 case FB_BLANK_POWERDOWN:
538 /* Screen: Off, HSync: Off, VSync: Off */
539 /* control CRT monitor power management */
540 viafb_write_reg_mask(CR36, VIACR, 0x30, BIT4 + BIT5);
541 break;
542 }
543
544 return 0;
545}
546
547static int viafb_ioctl(struct fb_info *info, u_int cmd, u_long arg)
548{
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 u32 state_info = 0;
555 u32 viainfo_size = sizeof(struct viafb_ioctl_info);
556 u32 *viafb_gamma_table;
557 char driver_name[] = "viafb";
558
559 u32 __user *argp = (u32 __user *) arg;
560 u32 gpu32;
561 u32 video_dev_info = 0;
562 struct viafb_ioctl_setting viafb_setting = {};
563 struct device_t active_dev = {};
564
565 DEBUG_MSG(KERN_INFO "viafb_ioctl: 0x%X !!\n", cmd);
566
567 switch (cmd) {
568 case VIAFB_GET_CHIP_INFO:
569 if (copy_to_user(argp, viaparinfo->chip_info,
570 sizeof(struct chip_information)))
571 return -EFAULT;
572 break;
573 case VIAFB_GET_INFO_SIZE:
574 return put_user(viainfo_size, argp);
575 case VIAFB_GET_INFO:
576 return viafb_ioctl_get_viafb_info(arg);
577 case VIAFB_HOTPLUG:
578 return put_user(viafb_ioctl_hotplug(info->var.xres,
579 info->var.yres,
580 info->var.bits_per_pixel), argp);
581 case VIAFB_SET_HOTPLUG_FLAG:
582 if (copy_from_user(&gpu32, argp, sizeof(gpu32)))
583 return -EFAULT;
584 viafb_hotplug = (gpu32) ? 1 : 0;
585 break;
586 case VIAFB_GET_RESOLUTION:
587 viamode.xres = (u32) viafb_hotplug_Xres;
588 viamode.yres = (u32) viafb_hotplug_Yres;
589 viamode.refresh = (u32) viafb_hotplug_refresh;
590 viamode.bpp = (u32) viafb_hotplug_bpp;
591 if (viafb_SAMM_ON == 1) {
592 viamode.xres_sec = viafb_second_xres;
593 viamode.yres_sec = viafb_second_yres;
594 viamode.virtual_xres_sec = viafb_second_virtual_xres;
595 viamode.virtual_yres_sec = viafb_second_virtual_yres;
596 viamode.refresh_sec = viafb_refresh1;
597 viamode.bpp_sec = viafb_bpp1;
598 } else {
599 viamode.xres_sec = 0;
600 viamode.yres_sec = 0;
601 viamode.virtual_xres_sec = 0;
602 viamode.virtual_yres_sec = 0;
603 viamode.refresh_sec = 0;
604 viamode.bpp_sec = 0;
605 }
606 if (copy_to_user(argp, &viamode, sizeof(viamode)))
607 return -EFAULT;
608 break;
609 case VIAFB_GET_SAMM_INFO:
610 viasamm.samm_status = viafb_SAMM_ON;
611
612 if (viafb_SAMM_ON == 1) {
613 if (viafb_dual_fb) {
614 viasamm.size_prim = viaparinfo->fbmem_free;
615 viasamm.size_sec = viaparinfo1->fbmem_free;
616 } else {
617 if (viafb_second_size) {
618 viasamm.size_prim =
619 viaparinfo->fbmem_free -
620 viafb_second_size * 1024 * 1024;
621 viasamm.size_sec =
622 viafb_second_size * 1024 * 1024;
623 } else {
624 viasamm.size_prim =
625 viaparinfo->fbmem_free >> 1;
626 viasamm.size_sec =
627 (viaparinfo->fbmem_free >> 1);
628 }
629 }
630 viasamm.mem_base = viaparinfo->fbmem;
631 viasamm.offset_sec = viafb_second_offset;
632 } else {
633 viasamm.size_prim =
634 viaparinfo->memsize - viaparinfo->fbmem_used;
635 viasamm.size_sec = 0;
636 viasamm.mem_base = viaparinfo->fbmem;
637 viasamm.offset_sec = 0;
638 }
639
640 if (copy_to_user(argp, &viasamm, sizeof(viasamm)))
641 return -EFAULT;
642
643 break;
644 case VIAFB_TURN_ON_OUTPUT_DEVICE:
645 if (copy_from_user(&gpu32, argp, sizeof(gpu32)))
646 return -EFAULT;
647 if (gpu32 & CRT_Device)
648 viafb_crt_enable();
649 if (gpu32 & DVI_Device)
650 viafb_dvi_enable();
651 if (gpu32 & LCD_Device)
652 viafb_lcd_enable();
653 break;
654 case VIAFB_TURN_OFF_OUTPUT_DEVICE:
655 if (copy_from_user(&gpu32, argp, sizeof(gpu32)))
656 return -EFAULT;
657 if (gpu32 & CRT_Device)
658 viafb_crt_disable();
659 if (gpu32 & DVI_Device)
660 viafb_dvi_disable();
661 if (gpu32 & LCD_Device)
662 viafb_lcd_disable();
663 break;
664 case VIAFB_SET_DEVICE:
665 if (copy_from_user(&active_dev, (void *)argp,
666 sizeof(active_dev)))
667 return -EFAULT;
668 viafb_set_device(active_dev);
669 viafb_set_par(info);
670 break;
671 case VIAFB_GET_DEVICE:
672 active_dev.crt = viafb_CRT_ON;
673 active_dev.dvi = viafb_DVI_ON;
674 active_dev.lcd = viafb_LCD_ON;
675 active_dev.samm = viafb_SAMM_ON;
676 active_dev.primary_dev = viafb_primary_dev;
677
678 active_dev.lcd_dsp_cent = viafb_lcd_dsp_method;
679 active_dev.lcd_panel_id = viafb_lcd_panel_id;
680 active_dev.lcd_mode = viafb_lcd_mode;
681
682 active_dev.xres = viafb_hotplug_Xres;
683 active_dev.yres = viafb_hotplug_Yres;
684
685 active_dev.xres1 = viafb_second_xres;
686 active_dev.yres1 = viafb_second_yres;
687
688 active_dev.bpp = viafb_bpp;
689 active_dev.bpp1 = viafb_bpp1;
690 active_dev.refresh = viafb_refresh;
691 active_dev.refresh1 = viafb_refresh1;
692
693 active_dev.epia_dvi = viafb_platform_epia_dvi;
694 active_dev.lcd_dual_edge = viafb_device_lcd_dualedge;
695 active_dev.bus_width = viafb_bus_width;
696
697 if (copy_to_user(argp, &active_dev, sizeof(active_dev)))
698 return -EFAULT;
699 break;
700
701 case VIAFB_GET_DRIVER_VERSION:
702 driver_version.iMajorNum = VERSION_MAJOR;
703 driver_version.iKernelNum = VERSION_KERNEL;
704 driver_version.iOSNum = VERSION_OS;
705 driver_version.iMinorNum = VERSION_MINOR;
706
707 if (copy_to_user(argp, &driver_version,
708 sizeof(driver_version)))
709 return -EFAULT;
710
711 break;
712
713 case VIAFB_SET_DEVICE_INFO:
714 if (copy_from_user(&viafb_setting,
715 argp, sizeof(viafb_setting)))
716 return -EFAULT;
717 if (apply_device_setting(viafb_setting, info) < 0)
718 return -EINVAL;
719
720 break;
721
722 case VIAFB_SET_SECOND_MODE:
723 if (copy_from_user(&sec_var, argp, sizeof(sec_var)))
724 return -EFAULT;
725 apply_second_mode_setting(&sec_var);
726 break;
727
728 case VIAFB_GET_DEVICE_INFO:
729
730 retrieve_device_setting(&viafb_setting);
731
732 if (copy_to_user(argp, &viafb_setting, sizeof(viafb_setting)))
733 return -EFAULT;
734
735 break;
736
737 case VIAFB_GET_DEVICE_SUPPORT:
738 viafb_get_device_support_state(&state_info);
739 if (put_user(state_info, argp))
740 return -EFAULT;
741 break;
742
743 case VIAFB_GET_DEVICE_CONNECT:
744 viafb_get_device_connect_state(&state_info);
745 if (put_user(state_info, argp))
746 return -EFAULT;
747 break;
748
749 case VIAFB_GET_PANEL_SUPPORT_EXPAND:
750 state_info =
751 viafb_lcd_get_support_expand_state(info->var.xres,
752 info->var.yres);
753 if (put_user(state_info, argp))
754 return -EFAULT;
755 break;
756
757 case VIAFB_GET_DRIVER_NAME:
758 if (copy_to_user(argp, driver_name, sizeof(driver_name)))
759 return -EFAULT;
760 break;
761
762 case VIAFB_SET_GAMMA_LUT:
763 viafb_gamma_table = kmalloc(256 * sizeof(u32), GFP_KERNEL);
764 if (!viafb_gamma_table)
765 return -ENOMEM;
766 if (copy_from_user(viafb_gamma_table, argp,
767 sizeof(viafb_gamma_table))) {
768 kfree(viafb_gamma_table);
769 return -EFAULT;
770 }
771 viafb_set_gamma_table(viafb_bpp, viafb_gamma_table);
772 kfree(viafb_gamma_table);
773 break;
774
775 case VIAFB_GET_GAMMA_LUT:
776 viafb_gamma_table = kmalloc(256 * sizeof(u32), GFP_KERNEL);
777 if (!viafb_gamma_table)
778 return -ENOMEM;
779 viafb_get_gamma_table(viafb_gamma_table);
780 if (copy_to_user(argp, viafb_gamma_table,
781 sizeof(viafb_gamma_table))) {
782 kfree(viafb_gamma_table);
783 return -EFAULT;
784 }
785 kfree(viafb_gamma_table);
786 break;
787
788 case VIAFB_GET_GAMMA_SUPPORT_STATE:
789 viafb_get_gamma_support_state(viafb_bpp, &state_info);
790 if (put_user(state_info, argp))
791 return -EFAULT;
792 break;
793 case VIAFB_SET_VIDEO_DEVICE:
794 get_user(video_dev_info, argp);
795 viafb_set_video_device(video_dev_info);
796 break;
797 case VIAFB_GET_VIDEO_DEVICE:
798 viafb_get_video_device(&video_dev_info);
799 if (put_user(video_dev_info, argp))
800 return -EFAULT;
801 break;
802 case VIAFB_SYNC_SURFACE:
803 DEBUG_MSG(KERN_INFO "lobo VIAFB_SYNC_SURFACE\n");
804 break;
805 case VIAFB_GET_DRIVER_CAPS:
806 break;
807
808 case VIAFB_GET_PANEL_MAX_SIZE:
809 if (copy_from_user
810 (&panel_pos_size_para, argp, sizeof(panel_pos_size_para)))
811 return -EFAULT;
812 panel_pos_size_para.x = panel_pos_size_para.y = 0;
813 if (copy_to_user(argp, &panel_pos_size_para,
814 sizeof(panel_pos_size_para)))
815 return -EFAULT;
816 break;
817 case VIAFB_GET_PANEL_MAX_POSITION:
818 if (copy_from_user
819 (&panel_pos_size_para, argp, sizeof(panel_pos_size_para)))
820 return -EFAULT;
821 panel_pos_size_para.x = panel_pos_size_para.y = 0;
822 if (copy_to_user(argp, &panel_pos_size_para,
823 sizeof(panel_pos_size_para)))
824 return -EFAULT;
825 break;
826
827 case VIAFB_GET_PANEL_POSITION:
828 if (copy_from_user
829 (&panel_pos_size_para, argp, sizeof(panel_pos_size_para)))
830 return -EFAULT;
831 panel_pos_size_para.x = panel_pos_size_para.y = 0;
832 if (copy_to_user(argp, &panel_pos_size_para,
833 sizeof(panel_pos_size_para)))
834 return -EFAULT;
835 break;
836 case VIAFB_GET_PANEL_SIZE:
837 if (copy_from_user
838 (&panel_pos_size_para, argp, sizeof(panel_pos_size_para)))
839 return -EFAULT;
840 panel_pos_size_para.x = panel_pos_size_para.y = 0;
841 if (copy_to_user(argp, &panel_pos_size_para,
842 sizeof(panel_pos_size_para)))
843 return -EFAULT;
844 break;
845
846 case VIAFB_SET_PANEL_POSITION:
847 if (copy_from_user
848 (&panel_pos_size_para, argp, sizeof(panel_pos_size_para)))
849 return -EFAULT;
850 break;
851 case VIAFB_SET_PANEL_SIZE:
852 if (copy_from_user
853 (&panel_pos_size_para, argp, sizeof(panel_pos_size_para)))
854 return -EFAULT;
855 break;
856
857 default:
858 return -EINVAL;
859 }
860
861 return 0;
862}
863
864static void viafb_fillrect(struct fb_info *info,
865 const struct fb_fillrect *rect)
866{
867 u32 col = 0, rop = 0;
868 int pitch;
869
870 if (!viafb_accel)
871 return cfb_fillrect(info, rect);
872
873 if (!rect->width || !rect->height)
874 return;
875
876 switch (rect->rop) {
877 case ROP_XOR:
878 rop = 0x5A;
879 break;
880 case ROP_COPY:
881 default:
882 rop = 0xF0;
883 break;
884 }
885
886 switch (info->var.bits_per_pixel) {
887 case 8:
888 col = rect->color;
889 break;
890 case 16:
891 col = ((u32 *) (info->pseudo_palette))[rect->color];
892 break;
893 case 32:
894 col = ((u32 *) (info->pseudo_palette))[rect->color];
895 break;
896 }
897
898 /* BitBlt Source Address */
899 MMIO_OUT32(VIA_REG_SRCPOS, 0x0);
900 /* Source Base Address */
901 MMIO_OUT32(VIA_REG_SRCBASE, 0x0);
902 /* Destination Base Address */
903 /*MMIO_OUT32(VIA_REG_DSTBASE, 0x0); */
904 MMIO_OUT32(VIA_REG_DSTBASE,
905 ((u32) (info->screen_base) - (u32) viafb_FB_MM) >> 3);
906 /* Pitch */
907 pitch = (info->var.xres_virtual + 7) & ~7;
908 MMIO_OUT32(VIA_REG_PITCH,
909 VIA_PITCH_ENABLE |
910 (((pitch *
911 info->var.bits_per_pixel >> 3) >> 3) |
912 (((pitch * info->
913 var.bits_per_pixel >> 3) >> 3) << 16)));
914 /* BitBlt Destination Address */
915 MMIO_OUT32(VIA_REG_DSTPOS, ((rect->dy << 16) | rect->dx));
916 /* Dimension: width & height */
917 MMIO_OUT32(VIA_REG_DIMENSION,
918 (((rect->height - 1) << 16) | (rect->width - 1)));
919 /* Forground color or Destination color */
920 MMIO_OUT32(VIA_REG_FGCOLOR, col);
921 /* GE Command */
922 MMIO_OUT32(VIA_REG_GECMD, (0x01 | 0x2000 | (rop << 24)));
923
924}
925
926static void viafb_copyarea(struct fb_info *info,
927 const struct fb_copyarea *area)
928{
929 u32 dy = area->dy, sy = area->sy, direction = 0x0;
930 u32 sx = area->sx, dx = area->dx, width = area->width;
931 int pitch;
932
933 DEBUG_MSG(KERN_INFO "viafb_copyarea!!\n");
934
935 if (!viafb_accel)
936 return cfb_copyarea(info, area);
937
938 if (!area->width || !area->height)
939 return;
940
941 if (sy < dy) {
942 dy += area->height - 1;
943 sy += area->height - 1;
944 direction |= 0x4000;
945 }
946
947 if (sx < dx) {
948 dx += width - 1;
949 sx += width - 1;
950 direction |= 0x8000;
951 }
952
953 /* Source Base Address */
954 /*MMIO_OUT32(VIA_REG_SRCBASE, 0x0); */
955 MMIO_OUT32(VIA_REG_SRCBASE,
956 ((u32) (info->screen_base) - (u32) viafb_FB_MM) >> 3);
957 /* Destination Base Address */
958 /*MMIO_OUT32(VIA_REG_DSTBASE, 0x0); */
959 MMIO_OUT32(VIA_REG_DSTBASE,
960 ((u32) (info->screen_base) - (u32) viafb_FB_MM) >> 3);
961 /* Pitch */
962 pitch = (info->var.xres_virtual + 7) & ~7;
963 /* VIA_PITCH_ENABLE can be omitted now. */
964 MMIO_OUT32(VIA_REG_PITCH,
965 VIA_PITCH_ENABLE |
966 (((pitch *
967 info->var.bits_per_pixel >> 3) >> 3) | (((pitch *
968 info->var.
969 bits_per_pixel
970 >> 3) >> 3)
971 << 16)));
972 /* BitBlt Source Address */
973 MMIO_OUT32(VIA_REG_SRCPOS, ((sy << 16) | sx));
974 /* BitBlt Destination Address */
975 MMIO_OUT32(VIA_REG_DSTPOS, ((dy << 16) | dx));
976 /* Dimension: width & height */
977 MMIO_OUT32(VIA_REG_DIMENSION,
978 (((area->height - 1) << 16) | (area->width - 1)));
979 /* GE Command */
980 MMIO_OUT32(VIA_REG_GECMD, (0x01 | direction | (0xCC << 24)));
981
982}
983
984static void viafb_imageblit(struct fb_info *info,
985 const struct fb_image *image)
986{
987 u32 size, bg_col = 0, fg_col = 0, *udata;
988 int i;
989 int pitch;
990
991 if (!viafb_accel)
992 return cfb_imageblit(info, image);
993
994 udata = (u32 *) image->data;
995
996 switch (info->var.bits_per_pixel) {
997 case 8:
998 bg_col = image->bg_color;
999 fg_col = image->fg_color;
1000 break;
1001 case 16:
1002 bg_col = ((u32 *) (info->pseudo_palette))[image->bg_color];
1003 fg_col = ((u32 *) (info->pseudo_palette))[image->fg_color];
1004 break;
1005 case 32:
1006 bg_col = ((u32 *) (info->pseudo_palette))[image->bg_color];
1007 fg_col = ((u32 *) (info->pseudo_palette))[image->fg_color];
1008 break;
1009 }
1010 size = image->width * image->height;
1011
1012 /* Source Base Address */
1013 MMIO_OUT32(VIA_REG_SRCBASE, 0x0);
1014 /* Destination Base Address */
1015 /*MMIO_OUT32(VIA_REG_DSTBASE, 0x0); */
1016 MMIO_OUT32(VIA_REG_DSTBASE,
1017 ((u32) (info->screen_base) - (u32) viafb_FB_MM) >> 3);
1018 /* Pitch */
1019 pitch = (info->var.xres_virtual + 7) & ~7;
1020 MMIO_OUT32(VIA_REG_PITCH,
1021 VIA_PITCH_ENABLE |
1022 (((pitch *
1023 info->var.bits_per_pixel >> 3) >> 3) | (((pitch *
1024 info->var.
1025 bits_per_pixel
1026 >> 3) >> 3)
1027 << 16)));
1028 /* BitBlt Source Address */
1029 MMIO_OUT32(VIA_REG_SRCPOS, 0x0);
1030 /* BitBlt Destination Address */
1031 MMIO_OUT32(VIA_REG_DSTPOS, ((image->dy << 16) | image->dx));
1032 /* Dimension: width & height */
1033 MMIO_OUT32(VIA_REG_DIMENSION,
1034 (((image->height - 1) << 16) | (image->width - 1)));
1035 /* fb color */
1036 MMIO_OUT32(VIA_REG_FGCOLOR, fg_col);
1037 /* bg color */
1038 MMIO_OUT32(VIA_REG_BGCOLOR, bg_col);
1039 /* GE Command */
1040 MMIO_OUT32(VIA_REG_GECMD, 0xCC020142);
1041
1042 for (i = 0; i < size / 4; i++) {
1043 MMIO_OUT32(VIA_MMIO_BLTBASE, *udata);
1044 udata++;
1045 }
1046
1047}
1048
1049static int viafb_cursor(struct fb_info *info, struct fb_cursor *cursor)
1050{
1051 u8 data[CURSOR_SIZE / 8];
1052 u32 data_bak[CURSOR_SIZE / 32];
1053 u32 temp, xx, yy, bg_col = 0, fg_col = 0;
1054 int size, i, j = 0;
1055 static int hw_cursor;
1056 struct viafb_par *p_viafb_par;
1057
1058 if (viafb_accel)
1059 hw_cursor = 1;
1060
1061 if (!viafb_accel) {
1062 if (hw_cursor) {
1063 viafb_show_hw_cursor(info, HW_Cursor_OFF);
1064 hw_cursor = 0;
1065 }
1066 return -ENODEV;
1067 }
1068
1069 if ((((struct viafb_par *)(info->par))->iga_path == IGA2)
1070 && (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266))
1071 return -ENODEV;
1072
1073 /* When duoview and using lcd , use soft cursor */
1074 if (viafb_LCD_ON || ((struct viafb_par *)(info->par))->duoview)
1075 return -ENODEV;
1076
1077 viafb_show_hw_cursor(info, HW_Cursor_OFF);
1078 viacursor = *cursor;
1079
1080 if (cursor->set & FB_CUR_SETHOT) {
1081 viacursor.hot = cursor->hot;
1082 temp = ((viacursor.hot.x) << 16) + viacursor.hot.y;
1083 MMIO_OUT32(VIA_REG_CURSOR_ORG, temp);
1084 }
1085
1086 if (cursor->set & FB_CUR_SETPOS) {
1087 viacursor.image.dx = cursor->image.dx;
1088 viacursor.image.dy = cursor->image.dy;
1089 yy = cursor->image.dy - info->var.yoffset;
1090 xx = cursor->image.dx - info->var.xoffset;
1091 temp = yy & 0xFFFF;
1092 temp |= (xx << 16);
1093 MMIO_OUT32(VIA_REG_CURSOR_POS, temp);
1094 }
1095
1096 if (cursor->set & FB_CUR_SETSIZE) {
1097 temp = MMIO_IN32(VIA_REG_CURSOR_MODE);
1098
1099 if ((cursor->image.width <= 32)
1100 && (cursor->image.height <= 32)) {
1101 MAX_CURS = 32;
1102 temp |= 0x2;
1103 } else if ((cursor->image.width <= 64)
1104 && (cursor->image.height <= 64)) {
1105 MAX_CURS = 64;
1106 temp &= 0xFFFFFFFD;
1107 } else {
1108 DEBUG_MSG(KERN_INFO
1109 "The cursor image is biger than 64x64 bits...\n");
1110 return -ENXIO;
1111 }
1112 MMIO_OUT32(VIA_REG_CURSOR_MODE, temp);
1113
1114 viacursor.image.height = cursor->image.height;
1115 viacursor.image.width = cursor->image.width;
1116 }
1117
1118 if (cursor->set & FB_CUR_SETCMAP) {
1119 viacursor.image.fg_color = cursor->image.fg_color;
1120 viacursor.image.bg_color = cursor->image.bg_color;
1121
1122 switch (info->var.bits_per_pixel) {
1123 case 8:
1124 case 16:
1125 case 32:
1126 bg_col =
1127 (0xFF << 24) |
1128 (((info->cmap.red)[viacursor.image.bg_color] &
1129 0xFF00) << 8) |
1130 ((info->cmap.green)[viacursor.image.bg_color] &
1131 0xFF00) |
1132 (((info->cmap.blue)[viacursor.image.bg_color] &
1133 0xFF00) >> 8);
1134 fg_col =
1135 (0xFF << 24) |
1136 (((info->cmap.red)[viacursor.image.fg_color] &
1137 0xFF00) << 8) |
1138 ((info->cmap.green)[viacursor.image.fg_color] &
1139 0xFF00) |
1140 (((info->cmap.blue)[viacursor.image.fg_color] &
1141 0xFF00) >> 8);
1142 break;
1143 default:
1144 return 0;
1145 }
1146
1147 /* This is indeed a patch for VT3324/VT3353 */
1148 if (!info->par)
1149 return 0;
1150 p_viafb_par = (struct viafb_par *)info->par;
1151
1152 if ((p_viafb_par->chip_info->gfx_chip_name ==
1153 UNICHROME_CX700) ||
1154 ((p_viafb_par->chip_info->gfx_chip_name ==
1155 UNICHROME_VX800))) {
1156 bg_col =
1157 (((info->cmap.red)[viacursor.image.bg_color] &
1158 0xFFC0) << 14) |
1159 (((info->cmap.green)[viacursor.image.bg_color] &
1160 0xFFC0) << 4) |
1161 (((info->cmap.blue)[viacursor.image.bg_color] &
1162 0xFFC0) >> 6);
1163 fg_col =
1164 (((info->cmap.red)[viacursor.image.fg_color] &
1165 0xFFC0) << 14) |
1166 (((info->cmap.green)[viacursor.image.fg_color] &
1167 0xFFC0) << 4) |
1168 (((info->cmap.blue)[viacursor.image.fg_color] &
1169 0xFFC0) >> 6);
1170 }
1171
1172 MMIO_OUT32(VIA_REG_CURSOR_BG, bg_col);
1173 MMIO_OUT32(VIA_REG_CURSOR_FG, fg_col);
1174 }
1175
1176 if (cursor->set & FB_CUR_SETSHAPE) {
1177 size =
1178 ((viacursor.image.width + 7) >> 3) *
1179 viacursor.image.height;
1180
1181 if (MAX_CURS == 32) {
1182 for (i = 0; i < (CURSOR_SIZE / 32); i++) {
1183 data_bak[i] = 0x0;
1184 data_bak[i + 1] = 0xFFFFFFFF;
1185 i += 1;
1186 }
1187 } else if (MAX_CURS == 64) {
1188 for (i = 0; i < (CURSOR_SIZE / 32); i++) {
1189 data_bak[i] = 0x0;
1190 data_bak[i + 1] = 0x0;
1191 data_bak[i + 2] = 0xFFFFFFFF;
1192 data_bak[i + 3] = 0xFFFFFFFF;
1193 i += 3;
1194 }
1195 }
1196
1197 switch (viacursor.rop) {
1198 case ROP_XOR:
1199 for (i = 0; i < size; i++)
1200 data[i] = viacursor.mask[i];
1201 break;
1202 case ROP_COPY:
1203
1204 for (i = 0; i < size; i++)
1205 data[i] = viacursor.mask[i];
1206 break;
1207 default:
1208 break;
1209 }
1210
1211 if (MAX_CURS == 32) {
1212 for (i = 0; i < size; i++) {
1213 data_bak[j] = (u32) data[i];
1214 data_bak[j + 1] = ~data_bak[j];
1215 j += 2;
1216 }
1217 } else if (MAX_CURS == 64) {
1218 for (i = 0; i < size; i++) {
1219 data_bak[j] = (u32) data[i];
1220 data_bak[j + 1] = 0x0;
1221 data_bak[j + 2] = ~data_bak[j];
1222 data_bak[j + 3] = ~data_bak[j + 1];
1223 j += 4;
1224 }
1225 }
1226
1227 memcpy(((struct viafb_par *)(info->par))->fbmem_virt +
1228 ((struct viafb_par *)(info->par))->cursor_start,
1229 data_bak, CURSOR_SIZE);
1230 }
1231
1232 if (viacursor.enable)
1233 viafb_show_hw_cursor(info, HW_Cursor_ON);
1234
1235 return 0;
1236}
1237
1238static int viafb_sync(struct fb_info *info)
1239{
1240 if (viafb_accel)
1241 viafb_wait_engine_idle();
1242 return 0;
1243}
1244
1245int viafb_get_mode_index(int hres, int vres, int flag)
1246{
1247 u32 i;
1248 DEBUG_MSG(KERN_INFO "viafb_get_mode_index!\n");
1249
1250 for (i = 0; viafb_modentry[i].mode_index != VIA_RES_INVALID; i++)
1251 if (viafb_modentry[i].xres == hres &&
1252 viafb_modentry[i].yres == vres)
1253 break;
1254
1255 viafb_resMode = viafb_modentry[i].mode_index;
1256 if (flag)
1257 viafb_mode1 = viafb_modentry[i].mode_res;
1258 else
1259 viafb_mode = viafb_modentry[i].mode_res;
1260
1261 return viafb_resMode;
1262}
1263
1264static void check_available_device_to_enable(int device_id)
1265{
1266 int device_num = 0;
1267
1268 /* Initialize: */
1269 viafb_CRT_ON = STATE_OFF;
1270 viafb_DVI_ON = STATE_OFF;
1271 viafb_LCD_ON = STATE_OFF;
1272 viafb_LCD2_ON = STATE_OFF;
1273 viafb_DeviceStatus = None_Device;
1274
1275 if ((device_id & CRT_Device) && (device_num < MAX_ACTIVE_DEV_NUM)) {
1276 viafb_CRT_ON = STATE_ON;
1277 device_num++;
1278 viafb_DeviceStatus |= CRT_Device;
1279 }
1280
1281 if ((device_id & DVI_Device) && (device_num < MAX_ACTIVE_DEV_NUM)) {
1282 viafb_DVI_ON = STATE_ON;
1283 device_num++;
1284 viafb_DeviceStatus |= DVI_Device;
1285 }
1286
1287 if ((device_id & LCD_Device) && (device_num < MAX_ACTIVE_DEV_NUM)) {
1288 viafb_LCD_ON = STATE_ON;
1289 device_num++;
1290 viafb_DeviceStatus |= LCD_Device;
1291 }
1292
1293 if ((device_id & LCD2_Device) && (device_num < MAX_ACTIVE_DEV_NUM)) {
1294 viafb_LCD2_ON = STATE_ON;
1295 device_num++;
1296 viafb_DeviceStatus |= LCD2_Device;
1297 }
1298
1299 if (viafb_DeviceStatus == None_Device) {
1300 /* Use CRT as default active device: */
1301 viafb_CRT_ON = STATE_ON;
1302 viafb_DeviceStatus = CRT_Device;
1303 }
1304 DEBUG_MSG(KERN_INFO "Device Status:%x", viafb_DeviceStatus);
1305}
1306
1307static void viafb_set_device(struct device_t active_dev)
1308{
1309 /* Check available device to enable: */
1310 int device_id = None_Device;
1311 if (active_dev.crt)
1312 device_id |= CRT_Device;
1313 if (active_dev.dvi)
1314 device_id |= DVI_Device;
1315 if (active_dev.lcd)
1316 device_id |= LCD_Device;
1317
1318 check_available_device_to_enable(device_id);
1319
1320 /* Check property of LCD: */
1321 if (viafb_LCD_ON) {
1322 if (active_dev.lcd_dsp_cent) {
1323 viaparinfo->lvds_setting_info->display_method =
1324 viafb_lcd_dsp_method = LCD_CENTERING;
1325 } else {
1326 viaparinfo->lvds_setting_info->display_method =
1327 viafb_lcd_dsp_method = LCD_EXPANDSION;
1328 }
1329
1330 if (active_dev.lcd_mode == LCD_SPWG) {
1331 viaparinfo->lvds_setting_info->lcd_mode =
1332 viafb_lcd_mode = LCD_SPWG;
1333 } else {
1334 viaparinfo->lvds_setting_info->lcd_mode =
1335 viafb_lcd_mode = LCD_OPENLDI;
1336 }
1337
1338 if (active_dev.lcd_panel_id <= LCD_PANEL_ID_MAXIMUM) {
1339 viafb_lcd_panel_id = active_dev.lcd_panel_id;
1340 viafb_init_lcd_size();
1341 }
1342 }
1343
1344 /* Check property of mode: */
1345 if (!active_dev.xres1)
1346 viafb_second_xres = 640;
1347 else
1348 viafb_second_xres = active_dev.xres1;
1349 if (!active_dev.yres1)
1350 viafb_second_yres = 480;
1351 else
1352 viafb_second_yres = active_dev.yres1;
1353 if (active_dev.bpp != 0)
1354 viafb_bpp = active_dev.bpp;
1355 if (active_dev.bpp1 != 0)
1356 viafb_bpp1 = active_dev.bpp1;
1357 if (active_dev.refresh != 0)
1358 viafb_refresh = active_dev.refresh;
1359 if (active_dev.refresh1 != 0)
1360 viafb_refresh1 = active_dev.refresh1;
1361 if ((active_dev.samm == STATE_OFF) || (active_dev.samm == STATE_ON))
1362 viafb_SAMM_ON = active_dev.samm;
1363 viafb_primary_dev = active_dev.primary_dev;
1364
1365 viafb_set_start_addr();
1366 viafb_set_iga_path();
1367}
1368
1369static void viafb_set_video_device(u32 video_dev_info)
1370{
1371 viaparinfo->video_on_crt = STATE_OFF;
1372 viaparinfo->video_on_dvi = STATE_OFF;
1373 viaparinfo->video_on_lcd = STATE_OFF;
1374
1375 /* Check available device to enable: */
1376 if ((video_dev_info & CRT_Device) == CRT_Device)
1377 viaparinfo->video_on_crt = STATE_ON;
1378 else if ((video_dev_info & DVI_Device) == DVI_Device)
1379 viaparinfo->video_on_dvi = STATE_ON;
1380 else if ((video_dev_info & LCD_Device) == LCD_Device)
1381 viaparinfo->video_on_lcd = STATE_ON;
1382}
1383
1384static void viafb_get_video_device(u32 *video_dev_info)
1385{
1386 *video_dev_info = None_Device;
1387 if (viaparinfo->video_on_crt == STATE_ON)
1388 *video_dev_info |= CRT_Device;
1389 else if (viaparinfo->video_on_dvi == STATE_ON)
1390 *video_dev_info |= DVI_Device;
1391 else if (viaparinfo->video_on_lcd == STATE_ON)
1392 *video_dev_info |= LCD_Device;
1393}
1394
1395static int get_primary_device(void)
1396{
1397 int primary_device = 0;
1398 /* Rule: device on iga1 path are the primary device. */
1399 if (viafb_SAMM_ON) {
1400 if (viafb_CRT_ON) {
1401 if (viaparinfo->crt_setting_info->iga_path == IGA1) {
1402 DEBUG_MSG(KERN_INFO "CRT IGA Path:%d\n",
1403 viaparinfo->
1404 crt_setting_info->iga_path);
1405 primary_device = CRT_Device;
1406 }
1407 }
1408 if (viafb_DVI_ON) {
1409 if (viaparinfo->tmds_setting_info->iga_path == IGA1) {
1410 DEBUG_MSG(KERN_INFO "DVI IGA Path:%d\n",
1411 viaparinfo->
1412 tmds_setting_info->iga_path);
1413 primary_device = DVI_Device;
1414 }
1415 }
1416 if (viafb_LCD_ON) {
1417 if (viaparinfo->lvds_setting_info->iga_path == IGA1) {
1418 DEBUG_MSG(KERN_INFO "LCD IGA Path:%d\n",
1419 viaparinfo->
1420 lvds_setting_info->iga_path);
1421 primary_device = LCD_Device;
1422 }
1423 }
1424 if (viafb_LCD2_ON) {
1425 if (viaparinfo->lvds_setting_info2->iga_path == IGA1) {
1426 DEBUG_MSG(KERN_INFO "LCD2 IGA Path:%d\n",
1427 viaparinfo->
1428 lvds_setting_info2->iga_path);
1429 primary_device = LCD2_Device;
1430 }
1431 }
1432 }
1433 return primary_device;
1434}
1435
1436static u8 is_duoview(void)
1437{
1438 if (0 == viafb_SAMM_ON) {
1439 if (viafb_LCD_ON + viafb_LCD2_ON +
1440 viafb_DVI_ON + viafb_CRT_ON == 2)
1441 return true;
1442 return false;
1443 } else {
1444 return false;
1445 }
1446}
1447
1448static void apply_second_mode_setting(struct fb_var_screeninfo
1449 *sec_var)
1450{
1451 u32 htotal, vtotal, long_refresh;
1452
1453 htotal = sec_var->xres + sec_var->left_margin +
1454 sec_var->right_margin + sec_var->hsync_len;
1455 vtotal = sec_var->yres + sec_var->upper_margin +
1456 sec_var->lower_margin + sec_var->vsync_len;
1457 if ((sec_var->xres_virtual * (sec_var->bits_per_pixel >> 3)) & 0x1F) {
1458 /*Is 32 bytes alignment? */
1459 /*32 pixel alignment */
1460 sec_var->xres_virtual = (sec_var->xres_virtual + 31) & ~31;
1461 }
1462
1463 htotal = sec_var->xres + sec_var->left_margin +
1464 sec_var->right_margin + sec_var->hsync_len;
1465 vtotal = sec_var->yres + sec_var->upper_margin +
1466 sec_var->lower_margin + sec_var->vsync_len;
1467 long_refresh = 1000000000UL / sec_var->pixclock * 1000;
1468 long_refresh /= (htotal * vtotal);
1469
1470 viafb_second_xres = sec_var->xres;
1471 viafb_second_yres = sec_var->yres;
1472 viafb_second_virtual_xres = sec_var->xres_virtual;
1473 viafb_second_virtual_yres = sec_var->yres_virtual;
1474 viafb_bpp1 = sec_var->bits_per_pixel;
1475 viafb_refresh1 = viafb_get_refresh(sec_var->xres, sec_var->yres,
1476 long_refresh);
1477}
1478
1479static int apply_device_setting(struct viafb_ioctl_setting setting_info,
1480 struct fb_info *info)
1481{
1482 int need_set_mode = 0;
1483 DEBUG_MSG(KERN_INFO "apply_device_setting\n");
1484
1485 if (setting_info.device_flag) {
1486 need_set_mode = 1;
1487 check_available_device_to_enable(setting_info.device_status);
1488 }
1489
1490 /* Unlock LCD's operation according to LCD flag
1491 and check if the setting value is valid. */
1492 /* If the value is valid, apply the new setting value to the device. */
1493 if (viafb_LCD_ON) {
1494 if (setting_info.lcd_operation_flag & OP_LCD_CENTERING) {
1495 need_set_mode = 1;
1496 if (setting_info.lcd_attributes.display_center) {
1497 /* Centering */
1498 viaparinfo->lvds_setting_info->display_method =
1499 LCD_CENTERING;
1500 viafb_lcd_dsp_method = LCD_CENTERING;
1501 viaparinfo->lvds_setting_info2->display_method =
1502 viafb_lcd_dsp_method = LCD_CENTERING;
1503 } else {
1504 /* expandsion */
1505 viaparinfo->lvds_setting_info->display_method =
1506 LCD_EXPANDSION;
1507 viafb_lcd_dsp_method = LCD_EXPANDSION;
1508 viaparinfo->lvds_setting_info2->display_method =
1509 LCD_EXPANDSION;
1510 viafb_lcd_dsp_method = LCD_EXPANDSION;
1511 }
1512 }
1513
1514 if (setting_info.lcd_operation_flag & OP_LCD_MODE) {
1515 need_set_mode = 1;
1516 if (setting_info.lcd_attributes.lcd_mode ==
1517 LCD_SPWG) {
1518 viaparinfo->lvds_setting_info->lcd_mode =
1519 viafb_lcd_mode = LCD_SPWG;
1520 } else {
1521 viaparinfo->lvds_setting_info->lcd_mode =
1522 viafb_lcd_mode = LCD_OPENLDI;
1523 }
1524 viaparinfo->lvds_setting_info2->lcd_mode =
1525 viaparinfo->lvds_setting_info->lcd_mode;
1526 }
1527
1528 if (setting_info.lcd_operation_flag & OP_LCD_PANEL_ID) {
1529 need_set_mode = 1;
1530 if (setting_info.lcd_attributes.panel_id <=
1531 LCD_PANEL_ID_MAXIMUM) {
1532 viafb_lcd_panel_id =
1533 setting_info.lcd_attributes.panel_id;
1534 viafb_init_lcd_size();
1535 }
1536 }
1537 }
1538
1539 if (0 != (setting_info.samm_status & OP_SAMM)) {
1540 setting_info.samm_status =
1541 setting_info.samm_status & (~OP_SAMM);
1542 if (setting_info.samm_status == 0
1543 || setting_info.samm_status == 1) {
1544 viafb_SAMM_ON = setting_info.samm_status;
1545
1546 if (viafb_SAMM_ON)
1547 viafb_primary_dev = setting_info.primary_device;
1548
1549 viafb_set_start_addr();
1550 viafb_set_iga_path();
1551 }
1552 need_set_mode = 1;
1553 }
1554
1555 viaparinfo->duoview = is_duoview();
1556
1557 if (!need_set_mode) {
1558 ;
1559 } else {
1560 viafb_set_iga_path();
1561 viafb_set_par(info);
1562 }
1563 return true;
1564}
1565
1566static void retrieve_device_setting(struct viafb_ioctl_setting
1567 *setting_info)
1568{
1569
1570 /* get device status */
1571 if (viafb_CRT_ON == 1)
1572 setting_info->device_status = CRT_Device;
1573 if (viafb_DVI_ON == 1)
1574 setting_info->device_status |= DVI_Device;
1575 if (viafb_LCD_ON == 1)
1576 setting_info->device_status |= LCD_Device;
1577 if (viafb_LCD2_ON == 1)
1578 setting_info->device_status |= LCD2_Device;
1579 if ((viaparinfo->video_on_crt == 1) && (viafb_CRT_ON == 1)) {
1580 setting_info->video_device_status =
1581 viaparinfo->crt_setting_info->iga_path;
1582 } else if ((viaparinfo->video_on_dvi == 1) && (viafb_DVI_ON == 1)) {
1583 setting_info->video_device_status =
1584 viaparinfo->tmds_setting_info->iga_path;
1585 } else if ((viaparinfo->video_on_lcd == 1) && (viafb_LCD_ON == 1)) {
1586 setting_info->video_device_status =
1587 viaparinfo->lvds_setting_info->iga_path;
1588 } else {
1589 setting_info->video_device_status = 0;
1590 }
1591
1592 setting_info->samm_status = viafb_SAMM_ON;
1593 setting_info->primary_device = get_primary_device();
1594
1595 setting_info->first_dev_bpp = viafb_bpp;
1596 setting_info->second_dev_bpp = viafb_bpp1;
1597
1598 setting_info->first_dev_refresh = viafb_refresh;
1599 setting_info->second_dev_refresh = viafb_refresh1;
1600
1601 setting_info->first_dev_hor_res = viafb_hotplug_Xres;
1602 setting_info->first_dev_ver_res = viafb_hotplug_Yres;
1603 setting_info->second_dev_hor_res = viafb_second_xres;
1604 setting_info->second_dev_ver_res = viafb_second_yres;
1605
1606 /* Get lcd attributes */
1607 setting_info->lcd_attributes.display_center = viafb_lcd_dsp_method;
1608 setting_info->lcd_attributes.panel_id = viafb_lcd_panel_id;
1609 setting_info->lcd_attributes.lcd_mode = viafb_lcd_mode;
1610}
1611
1612static void parse_active_dev(void)
1613{
1614 viafb_CRT_ON = STATE_OFF;
1615 viafb_DVI_ON = STATE_OFF;
1616 viafb_LCD_ON = STATE_OFF;
1617 viafb_LCD2_ON = STATE_OFF;
1618 /* 1. Modify the active status of devices. */
1619 /* 2. Keep the order of devices, so we can set corresponding
1620 IGA path to devices in SAMM case. */
1621 /* Note: The previous of active_dev is primary device,
1622 and the following is secondary device. */
1623 if (!strncmp(viafb_active_dev, "CRT+DVI", 7)) {
1624 /* CRT+DVI */
1625 viafb_CRT_ON = STATE_ON;
1626 viafb_DVI_ON = STATE_ON;
1627 viafb_primary_dev = CRT_Device;
1628 } else if (!strncmp(viafb_active_dev, "DVI+CRT", 7)) {
1629 /* DVI+CRT */
1630 viafb_CRT_ON = STATE_ON;
1631 viafb_DVI_ON = STATE_ON;
1632 viafb_primary_dev = DVI_Device;
1633 } else if (!strncmp(viafb_active_dev, "CRT+LCD", 7)) {
1634 /* CRT+LCD */
1635 viafb_CRT_ON = STATE_ON;
1636 viafb_LCD_ON = STATE_ON;
1637 viafb_primary_dev = CRT_Device;
1638 } else if (!strncmp(viafb_active_dev, "LCD+CRT", 7)) {
1639 /* LCD+CRT */
1640 viafb_CRT_ON = STATE_ON;
1641 viafb_LCD_ON = STATE_ON;
1642 viafb_primary_dev = LCD_Device;
1643 } else if (!strncmp(viafb_active_dev, "DVI+LCD", 7)) {
1644 /* DVI+LCD */
1645 viafb_DVI_ON = STATE_ON;
1646 viafb_LCD_ON = STATE_ON;
1647 viafb_primary_dev = DVI_Device;
1648 } else if (!strncmp(viafb_active_dev, "LCD+DVI", 7)) {
1649 /* LCD+DVI */
1650 viafb_DVI_ON = STATE_ON;
1651 viafb_LCD_ON = STATE_ON;
1652 viafb_primary_dev = LCD_Device;
1653 } else if (!strncmp(viafb_active_dev, "LCD+LCD2", 8)) {
1654 viafb_LCD_ON = STATE_ON;
1655 viafb_LCD2_ON = STATE_ON;
1656 viafb_primary_dev = LCD_Device;
1657 } else if (!strncmp(viafb_active_dev, "LCD2+LCD", 8)) {
1658 viafb_LCD_ON = STATE_ON;
1659 viafb_LCD2_ON = STATE_ON;
1660 viafb_primary_dev = LCD2_Device;
1661 } else if (!strncmp(viafb_active_dev, "CRT", 3)) {
1662 /* CRT only */
1663 viafb_CRT_ON = STATE_ON;
1664 viafb_SAMM_ON = STATE_OFF;
1665 } else if (!strncmp(viafb_active_dev, "DVI", 3)) {
1666 /* DVI only */
1667 viafb_DVI_ON = STATE_ON;
1668 viafb_SAMM_ON = STATE_OFF;
1669 } else if (!strncmp(viafb_active_dev, "LCD", 3)) {
1670 /* LCD only */
1671 viafb_LCD_ON = STATE_ON;
1672 viafb_SAMM_ON = STATE_OFF;
1673 } else {
1674 viafb_CRT_ON = STATE_ON;
1675 viafb_SAMM_ON = STATE_OFF;
1676 }
1677 viaparinfo->duoview = is_duoview();
1678}
1679
1680static void parse_video_dev(void)
1681{
1682 viaparinfo->video_on_crt = STATE_OFF;
1683 viaparinfo->video_on_dvi = STATE_OFF;
1684 viaparinfo->video_on_lcd = STATE_OFF;
1685
1686 if (!strncmp(viafb_video_dev, "CRT", 3)) {
1687 /* Video on CRT */
1688 viaparinfo->video_on_crt = STATE_ON;
1689 } else if (!strncmp(viafb_video_dev, "DVI", 3)) {
1690 /* Video on DVI */
1691 viaparinfo->video_on_dvi = STATE_ON;
1692 } else if (!strncmp(viafb_video_dev, "LCD", 3)) {
1693 /* Video on LCD */
1694 viaparinfo->video_on_lcd = STATE_ON;
1695 }
1696}
1697
1698static int parse_port(char *opt_str, int *output_interface)
1699{
1700 if (!strncmp(opt_str, "DVP0", 4))
1701 *output_interface = INTERFACE_DVP0;
1702 else if (!strncmp(opt_str, "DVP1", 4))
1703 *output_interface = INTERFACE_DVP1;
1704 else if (!strncmp(opt_str, "DFP_HIGHLOW", 11))
1705 *output_interface = INTERFACE_DFP;
1706 else if (!strncmp(opt_str, "DFP_HIGH", 8))
1707 *output_interface = INTERFACE_DFP_HIGH;
1708 else if (!strncmp(opt_str, "DFP_LOW", 7))
1709 *output_interface = INTERFACE_DFP_LOW;
1710 else
1711 *output_interface = INTERFACE_NONE;
1712 return 0;
1713}
1714
1715static void parse_lcd_port(void)
1716{
1717 parse_port(viafb_lcd_port, &viaparinfo->chip_info->lvds_chip_info.
1718 output_interface);
1719 /*Initialize to avoid unexpected behavior */
1720 viaparinfo->chip_info->lvds_chip_info2.output_interface =
1721 INTERFACE_NONE;
1722
1723 DEBUG_MSG(KERN_INFO "parse_lcd_port: viafb_lcd_port:%s,interface:%d\n",
1724 viafb_lcd_port, viaparinfo->chip_info->lvds_chip_info.
1725 output_interface);
1726}
1727
1728static void parse_dvi_port(void)
1729{
1730 parse_port(viafb_dvi_port, &viaparinfo->chip_info->tmds_chip_info.
1731 output_interface);
1732
1733 DEBUG_MSG(KERN_INFO "parse_dvi_port: viafb_dvi_port:%s,interface:%d\n",
1734 viafb_dvi_port, viaparinfo->chip_info->tmds_chip_info.
1735 output_interface);
1736}
1737
1738/*
1739 * The proc filesystem read/write function, a simple proc implement to
1740 * get/set the value of DPA DVP0, DVP0DataDriving, DVP0ClockDriving, DVP1,
1741 * DVP1Driving, DFPHigh, DFPLow CR96, SR2A[5], SR1B[1], SR2A[4], SR1E[2],
1742 * CR9B, SR65, CR97, CR99
1743 */
1744static int viafb_dvp0_proc_read(char *buf, char **start, off_t offset,
1745int count, int *eof, void *data)
1746{
1747 int len = 0;
1748 u8 dvp0_data_dri = 0, dvp0_clk_dri = 0, dvp0 = 0;
1749 dvp0_data_dri =
1750 (viafb_read_reg(VIASR, SR2A) & BIT5) >> 4 |
1751 (viafb_read_reg(VIASR, SR1B) & BIT1) >> 1;
1752 dvp0_clk_dri =
1753 (viafb_read_reg(VIASR, SR2A) & BIT4) >> 3 |
1754 (viafb_read_reg(VIASR, SR1E) & BIT2) >> 2;
1755 dvp0 = viafb_read_reg(VIACR, CR96) & 0x0f;
1756 len +=
1757 sprintf(buf + len, "%x %x %x\n", dvp0, dvp0_data_dri, dvp0_clk_dri);
1758 *eof = 1; /*Inform kernel end of data */
1759 return len;
1760}
1761static int viafb_dvp0_proc_write(struct file *file,
1762 const char __user *buffer, unsigned long count, void *data)
1763{
1764 char buf[20], *value, *pbuf;
1765 u8 reg_val = 0;
1766 unsigned long length, i;
1767 if (count < 1)
1768 return -EINVAL;
1769 length = count > 20 ? 20 : count;
1770 if (copy_from_user(&buf[0], buffer, length))
1771 return -EFAULT;
1772 buf[length - 1] = '\0'; /*Ensure end string */
1773 pbuf = &buf[0];
1774 for (i = 0; i < 3; i++) {
1775 value = strsep(&pbuf, " ");
1776 if (value != NULL) {
1777 strict_strtoul(value, 0, (unsigned long *)&reg_val);
1778 DEBUG_MSG(KERN_INFO "DVP0:reg_val[%l]=:%x\n", i,
1779 reg_val);
1780 switch (i) {
1781 case 0:
1782 viafb_write_reg_mask(CR96, VIACR,
1783 reg_val, 0x0f);
1784 break;
1785 case 1:
1786 viafb_write_reg_mask(SR2A, VIASR,
1787 reg_val << 4, BIT5);
1788 viafb_write_reg_mask(SR1B, VIASR,
1789 reg_val << 1, BIT1);
1790 break;
1791 case 2:
1792 viafb_write_reg_mask(SR2A, VIASR,
1793 reg_val << 3, BIT4);
1794 viafb_write_reg_mask(SR1E, VIASR,
1795 reg_val << 2, BIT2);
1796 break;
1797 default:
1798 break;
1799 }
1800 } else {
1801 break;
1802 }
1803 }
1804 return count;
1805}
1806static int viafb_dvp1_proc_read(char *buf, char **start, off_t offset,
1807 int count, int *eof, void *data)
1808{
1809 int len = 0;
1810 u8 dvp1 = 0, dvp1_data_dri = 0, dvp1_clk_dri = 0;
1811 dvp1 = viafb_read_reg(VIACR, CR9B) & 0x0f;
1812 dvp1_data_dri = (viafb_read_reg(VIASR, SR65) & 0x0c) >> 2;
1813 dvp1_clk_dri = viafb_read_reg(VIASR, SR65) & 0x03;
1814 len +=
1815 sprintf(buf + len, "%x %x %x\n", dvp1, dvp1_data_dri, dvp1_clk_dri);
1816 *eof = 1; /*Inform kernel end of data */
1817 return len;
1818}
1819static int viafb_dvp1_proc_write(struct file *file,
1820 const char __user *buffer, unsigned long count, void *data)
1821{
1822 char buf[20], *value, *pbuf;
1823 u8 reg_val = 0;
1824 unsigned long length, i;
1825 if (count < 1)
1826 return -EINVAL;
1827 length = count > 20 ? 20 : count;
1828 if (copy_from_user(&buf[0], buffer, length))
1829 return -EFAULT;
1830 buf[length - 1] = '\0'; /*Ensure end string */
1831 pbuf = &buf[0];
1832 for (i = 0; i < 3; i++) {
1833 value = strsep(&pbuf, " ");
1834 if (value != NULL) {
1835 strict_strtoul(value, 0, (unsigned long *)&reg_val);
1836 switch (i) {
1837 case 0:
1838 viafb_write_reg_mask(CR9B, VIACR,
1839 reg_val, 0x0f);
1840 break;
1841 case 1:
1842 viafb_write_reg_mask(SR65, VIASR,
1843 reg_val << 2, 0x0c);
1844 break;
1845 case 2:
1846 viafb_write_reg_mask(SR65, VIASR,
1847 reg_val, 0x03);
1848 break;
1849 default:
1850 break;
1851 }
1852 } else {
1853 break;
1854 }
1855 }
1856 return count;
1857}
1858
1859static int viafb_dfph_proc_read(char *buf, char **start, off_t offset,
1860 int count, int *eof, void *data)
1861{
1862 int len = 0;
1863 u8 dfp_high = 0;
1864 dfp_high = viafb_read_reg(VIACR, CR97) & 0x0f;
1865 len += sprintf(buf + len, "%x\n", dfp_high);
1866 *eof = 1; /*Inform kernel end of data */
1867 return len;
1868}
1869static int viafb_dfph_proc_write(struct file *file,
1870 const char __user *buffer, unsigned long count, void *data)
1871{
1872 char buf[20];
1873 u8 reg_val = 0;
1874 unsigned long length;
1875 if (count < 1)
1876 return -EINVAL;
1877 length = count > 20 ? 20 : count;
1878 if (copy_from_user(&buf[0], buffer, length))
1879 return -EFAULT;
1880 buf[length - 1] = '\0'; /*Ensure end string */
1881 strict_strtoul(&buf[0], 0, (unsigned long *)&reg_val);
1882 viafb_write_reg_mask(CR97, VIACR, reg_val, 0x0f);
1883 return count;
1884}
1885static int viafb_dfpl_proc_read(char *buf, char **start, off_t offset,
1886 int count, int *eof, void *data)
1887{
1888 int len = 0;
1889 u8 dfp_low = 0;
1890 dfp_low = viafb_read_reg(VIACR, CR99) & 0x0f;
1891 len += sprintf(buf + len, "%x\n", dfp_low);
1892 *eof = 1; /*Inform kernel end of data */
1893 return len;
1894}
1895static int viafb_dfpl_proc_write(struct file *file,
1896 const char __user *buffer, unsigned long count, void *data)
1897{
1898 char buf[20];
1899 u8 reg_val = 0;
1900 unsigned long length;
1901 if (count < 1)
1902 return -EINVAL;
1903 length = count > 20 ? 20 : count;
1904 if (copy_from_user(&buf[0], buffer, length))
1905 return -EFAULT;
1906 buf[length - 1] = '\0'; /*Ensure end string */
1907 strict_strtoul(&buf[0], 0, (unsigned long *)&reg_val);
1908 viafb_write_reg_mask(CR99, VIACR, reg_val, 0x0f);
1909 return count;
1910}
1911static int viafb_vt1636_proc_read(char *buf, char **start,
1912 off_t offset, int count, int *eof, void *data)
1913{
1914 int len = 0;
1915 u8 vt1636_08 = 0, vt1636_09 = 0;
1916 switch (viaparinfo->chip_info->lvds_chip_info.lvds_chip_name) {
1917 case VT1636_LVDS:
1918 vt1636_08 =
1919 viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info,
1920 &viaparinfo->chip_info->lvds_chip_info, 0x08) & 0x0f;
1921 vt1636_09 =
1922 viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info,
1923 &viaparinfo->chip_info->lvds_chip_info, 0x09) & 0x1f;
1924 len += sprintf(buf + len, "%x %x\n", vt1636_08, vt1636_09);
1925 break;
1926 default:
1927 break;
1928 }
1929 switch (viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name) {
1930 case VT1636_LVDS:
1931 vt1636_08 =
1932 viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info2,
1933 &viaparinfo->chip_info->lvds_chip_info2, 0x08) & 0x0f;
1934 vt1636_09 =
1935 viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info2,
1936 &viaparinfo->chip_info->lvds_chip_info2, 0x09) & 0x1f;
1937 len += sprintf(buf + len, " %x %x\n", vt1636_08, vt1636_09);
1938 break;
1939 default:
1940 break;
1941 }
1942 *eof = 1; /*Inform kernel end of data */
1943 return len;
1944}
1945static int viafb_vt1636_proc_write(struct file *file,
1946 const char __user *buffer, unsigned long count, void *data)
1947{
1948 char buf[30], *value, *pbuf;
1949 struct IODATA reg_val;
1950 unsigned long length, i;
1951 if (count < 1)
1952 return -EINVAL;
1953 length = count > 30 ? 30 : count;
1954 if (copy_from_user(&buf[0], buffer, length))
1955 return -EFAULT;
1956 buf[length - 1] = '\0'; /*Ensure end string */
1957 pbuf = &buf[0];
1958 switch (viaparinfo->chip_info->lvds_chip_info.lvds_chip_name) {
1959 case VT1636_LVDS:
1960 for (i = 0; i < 2; i++) {
1961 value = strsep(&pbuf, " ");
1962 if (value != NULL) {
1963 strict_strtoul(value, 0,
1964 (unsigned long *)&reg_val.Data);
1965 switch (i) {
1966 case 0:
1967 reg_val.Index = 0x08;
1968 reg_val.Mask = 0x0f;
1969 viafb_gpio_i2c_write_mask_lvds
1970 (viaparinfo->lvds_setting_info,
1971 &viaparinfo->
1972 chip_info->lvds_chip_info,
1973 reg_val);
1974 break;
1975 case 1:
1976 reg_val.Index = 0x09;
1977 reg_val.Mask = 0x1f;
1978 viafb_gpio_i2c_write_mask_lvds
1979 (viaparinfo->lvds_setting_info,
1980 &viaparinfo->
1981 chip_info->lvds_chip_info,
1982 reg_val);
1983 break;
1984 default:
1985 break;
1986 }
1987 } else {
1988 break;
1989 }
1990 }
1991 break;
1992 default:
1993 break;
1994 }
1995 switch (viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name) {
1996 case VT1636_LVDS:
1997 for (i = 0; i < 2; i++) {
1998 value = strsep(&pbuf, " ");
1999 if (value != NULL) {
2000 strict_strtoul(value, 0,
2001 (unsigned long *)&reg_val.Data);
2002 switch (i) {
2003 case 0:
2004 reg_val.Index = 0x08;
2005 reg_val.Mask = 0x0f;
2006 viafb_gpio_i2c_write_mask_lvds
2007 (viaparinfo->lvds_setting_info2,
2008 &viaparinfo->
2009 chip_info->lvds_chip_info2,
2010 reg_val);
2011 break;
2012 case 1:
2013 reg_val.Index = 0x09;
2014 reg_val.Mask = 0x1f;
2015 viafb_gpio_i2c_write_mask_lvds
2016 (viaparinfo->lvds_setting_info2,
2017 &viaparinfo->
2018 chip_info->lvds_chip_info2,
2019 reg_val);
2020 break;
2021 default:
2022 break;
2023 }
2024 } else {
2025 break;
2026 }
2027 }
2028 break;
2029 default:
2030 break;
2031 }
2032 return count;
2033}
2034
2035static void viafb_init_proc(struct proc_dir_entry *viafb_entry)
2036{
2037 struct proc_dir_entry *entry;
2038 viafb_entry = proc_mkdir("viafb", NULL);
2039 if (viafb_entry) {
2040 entry = create_proc_entry("dvp0", 0, viafb_entry);
2041 if (entry) {
2042 entry->owner = THIS_MODULE;
2043 entry->read_proc = viafb_dvp0_proc_read;
2044 entry->write_proc = viafb_dvp0_proc_write;
2045 }
2046 entry = create_proc_entry("dvp1", 0, viafb_entry);
2047 if (entry) {
2048 entry->owner = THIS_MODULE;
2049 entry->read_proc = viafb_dvp1_proc_read;
2050 entry->write_proc = viafb_dvp1_proc_write;
2051 }
2052 entry = create_proc_entry("dfph", 0, viafb_entry);
2053 if (entry) {
2054 entry->owner = THIS_MODULE;
2055 entry->read_proc = viafb_dfph_proc_read;
2056 entry->write_proc = viafb_dfph_proc_write;
2057 }
2058 entry = create_proc_entry("dfpl", 0, viafb_entry);
2059 if (entry) {
2060 entry->owner = THIS_MODULE;
2061 entry->read_proc = viafb_dfpl_proc_read;
2062 entry->write_proc = viafb_dfpl_proc_write;
2063 }
2064 if (VT1636_LVDS == viaparinfo->chip_info->lvds_chip_info.
2065 lvds_chip_name || VT1636_LVDS ==
2066 viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name) {
2067 entry = create_proc_entry("vt1636", 0, viafb_entry);
2068 if (entry) {
2069 entry->owner = THIS_MODULE;
2070 entry->read_proc = viafb_vt1636_proc_read;
2071 entry->write_proc = viafb_vt1636_proc_write;
2072 }
2073 }
2074
2075 }
2076}
2077static void viafb_remove_proc(struct proc_dir_entry *viafb_entry)
2078{
2079 /* no problem if it was not registered */
2080 remove_proc_entry("dvp0", viafb_entry);/* parent dir */
2081 remove_proc_entry("dvp1", viafb_entry);
2082 remove_proc_entry("dfph", viafb_entry);
2083 remove_proc_entry("dfpl", viafb_entry);
2084 remove_proc_entry("vt1636", viafb_entry);
2085 remove_proc_entry("vt1625", viafb_entry);
2086}
2087
2088static int __devinit via_pci_probe(void)
2089{
2090 unsigned int default_xres, default_yres;
2091 char *tmpc, *tmpm;
2092 char *tmpc_sec, *tmpm_sec;
2093 int vmode_index;
2094 u32 tmds_length, lvds_length, crt_length, chip_length, viafb_par_length;
2095
2096 DEBUG_MSG(KERN_INFO "VIAFB PCI Probe!!\n");
2097
2098 viafb_par_length = ALIGN(sizeof(struct viafb_par), BITS_PER_LONG/8);
2099 tmds_length = ALIGN(sizeof(struct tmds_setting_information),
2100 BITS_PER_LONG/8);
2101 lvds_length = ALIGN(sizeof(struct lvds_setting_information),
2102 BITS_PER_LONG/8);
2103 crt_length = ALIGN(sizeof(struct lvds_setting_information),
2104 BITS_PER_LONG/8);
2105 chip_length = ALIGN(sizeof(struct chip_information), BITS_PER_LONG/8);
2106
2107 /* Allocate fb_info and ***_par here, also including some other needed
2108 * variables
2109 */
2110 viafbinfo = framebuffer_alloc(viafb_par_length + 2 * lvds_length +
2111 tmds_length + crt_length + chip_length, NULL);
2112 if (!viafbinfo) {
2113 printk(KERN_ERR"Could not allocate memory for viafb_info.\n");
2114 return -ENODEV;
2115 }
2116
2117 viaparinfo = (struct viafb_par *)viafbinfo->par;
2118 viaparinfo->tmds_setting_info = (struct tmds_setting_information *)
2119 ((u32)viaparinfo + viafb_par_length);
2120 viaparinfo->lvds_setting_info = (struct lvds_setting_information *)
2121 ((u32)viaparinfo->tmds_setting_info + tmds_length);
2122 viaparinfo->lvds_setting_info2 = (struct lvds_setting_information *)
2123 ((u32)viaparinfo->lvds_setting_info + lvds_length);
2124 viaparinfo->crt_setting_info = (struct crt_setting_information *)
2125 ((u32)viaparinfo->lvds_setting_info2 + lvds_length);
2126 viaparinfo->chip_info = (struct chip_information *)
2127 ((u32)viaparinfo->crt_setting_info + crt_length);
2128
2129 if (viafb_dual_fb)
2130 viafb_SAMM_ON = 1;
2131 parse_active_dev();
2132 parse_video_dev();
2133 parse_lcd_port();
2134 parse_dvi_port();
2135
2136 /* for dual-fb must viafb_SAMM_ON=1 and viafb_dual_fb=1 */
2137 if (!viafb_SAMM_ON)
2138 viafb_dual_fb = 0;
2139
2140 /* Set up I2C bus stuff */
2141 viafb_create_i2c_bus(viaparinfo);
2142
2143 viafb_init_chip_info();
2144 viafb_get_fb_info(&viaparinfo->fbmem, &viaparinfo->memsize);
2145 viaparinfo->fbmem_free = viaparinfo->memsize;
2146 viaparinfo->fbmem_used = 0;
2147 viaparinfo->fbmem_virt = ioremap_nocache(viaparinfo->fbmem,
2148 viaparinfo->memsize);
2149 viafbinfo->screen_base = (char *)viaparinfo->fbmem_virt;
2150
2151 if (!viaparinfo->fbmem_virt) {
2152 printk(KERN_INFO "ioremap failed\n");
2153 return -1;
2154 }
2155
2156 viafb_get_mmio_info(&viaparinfo->mmio_base, &viaparinfo->mmio_len);
2157 viaparinfo->io_virt = ioremap_nocache(viaparinfo->mmio_base,
2158 viaparinfo->mmio_len);
2159
2160 viafbinfo->node = 0;
2161 viafbinfo->fbops = &viafb_ops;
2162 viafbinfo->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
2163
2164 viafbinfo->pseudo_palette = pseudo_pal;
2165 if (viafb_accel) {
2166 viafb_init_accel();
2167 viafb_init_2d_engine();
2168 viafb_hw_cursor_init();
2169 }
2170
2171 if (viafb_second_size && (viafb_second_size < 8)) {
2172 viafb_second_offset = viaparinfo->fbmem_free -
2173 viafb_second_size * 1024 * 1024;
2174 } else {
2175 viafb_second_size = 8;
2176 viafb_second_offset = viaparinfo->fbmem_free -
2177 viafb_second_size * 1024 * 1024;
2178 }
2179
2180 viafb_FB_MM = viaparinfo->fbmem_virt;
2181 tmpm = viafb_mode;
2182 tmpc = strsep(&tmpm, "x");
2183 strict_strtoul(tmpc, 0, (unsigned long *)&default_xres);
2184 strict_strtoul(tmpm, 0, (unsigned long *)&default_yres);
2185
2186 vmode_index = viafb_get_mode_index(default_xres, default_yres, 0);
2187 DEBUG_MSG(KERN_INFO "0->index=%d\n", vmode_index);
2188
2189 if (viafb_SAMM_ON == 1) {
2190 if (strcmp(viafb_mode, viafb_mode1)) {
2191 tmpm_sec = viafb_mode1;
2192 tmpc_sec = strsep(&tmpm_sec, "x");
2193 strict_strtoul(tmpc_sec, 0,
2194 (unsigned long *)&viafb_second_xres);
2195 strict_strtoul(tmpm_sec, 0,
2196 (unsigned long *)&viafb_second_yres);
2197 } else {
2198 viafb_second_xres = default_xres;
2199 viafb_second_yres = default_yres;
2200 }
2201 if (0 == viafb_second_virtual_xres) {
2202 switch (viafb_second_xres) {
2203 case 1400:
2204 viafb_second_virtual_xres = 1408;
2205 break;
2206 default:
2207 viafb_second_virtual_xres = viafb_second_xres;
2208 break;
2209 }
2210 }
2211 if (0 == viafb_second_virtual_yres)
2212 viafb_second_virtual_yres = viafb_second_yres;
2213 }
2214
2215 switch (viafb_bpp) {
2216 case 0 ... 8:
2217 viafb_bpp = 8;
2218 break;
2219 case 9 ... 16:
2220 viafb_bpp = 16;
2221 break;
2222 case 17 ... 32:
2223 viafb_bpp = 32;
2224 break;
2225 default:
2226 viafb_bpp = 8;
2227 }
2228 default_var.xres = default_xres;
2229 default_var.yres = default_yres;
2230 switch (default_xres) {
2231 case 1400:
2232 default_var.xres_virtual = 1408;
2233 break;
2234 default:
2235 default_var.xres_virtual = default_xres;
2236 break;
2237 }
2238 default_var.yres_virtual = default_yres;
2239 default_var.bits_per_pixel = viafb_bpp;
2240 if (default_var.bits_per_pixel == 15)
2241 default_var.bits_per_pixel = 16;
2242 default_var.pixclock =
2243 viafb_get_pixclock(default_xres, default_yres, viafb_refresh);
2244 default_var.left_margin = (default_xres >> 3) & 0xf8;
2245 default_var.right_margin = 32;
2246 default_var.upper_margin = 16;
2247 default_var.lower_margin = 4;
2248 default_var.hsync_len = default_var.left_margin;
2249 default_var.vsync_len = 4;
2250 default_var.accel_flags = 0;
2251
2252 if (viafb_accel) {
2253 viafbinfo->flags |=
2254 (FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT |
2255 FBINFO_HWACCEL_IMAGEBLIT);
2256 default_var.accel_flags |= FB_ACCELF_TEXT;
2257 } else
2258 viafbinfo->flags |= FBINFO_HWACCEL_DISABLED;
2259
2260 if (viafb_dual_fb) {
2261 viafbinfo1 = framebuffer_alloc(viafb_par_length, NULL);
2262 if (!viafbinfo1) {
2263 printk(KERN_ERR
2264 "allocate the second framebuffer struct error\n");
2265 framebuffer_release(viafbinfo);
2266 return -ENOMEM;
2267 }
2268 viaparinfo1 = viafbinfo1->par;
2269 memcpy(viaparinfo1, viaparinfo, viafb_par_length);
2270 viaparinfo1->memsize = viaparinfo->memsize -
2271 viafb_second_offset;
2272 viaparinfo->memsize = viafb_second_offset;
2273 viaparinfo1->fbmem_virt = viaparinfo->fbmem_virt +
2274 viafb_second_offset;
2275 viaparinfo1->fbmem = viaparinfo->fbmem + viafb_second_offset;
2276
2277 viaparinfo1->fbmem_used = viaparinfo->fbmem_used;
2278 viaparinfo1->fbmem_free = viaparinfo1->memsize -
2279 viaparinfo1->fbmem_used;
2280 viaparinfo->fbmem_free = viaparinfo->memsize;
2281 viaparinfo->fbmem_used = 0;
2282 if (viafb_accel) {
2283 viaparinfo1->cursor_start =
2284 viaparinfo->cursor_start - viafb_second_offset;
2285 viaparinfo1->VQ_start = viaparinfo->VQ_start -
2286 viafb_second_offset;
2287 viaparinfo1->VQ_end = viaparinfo->VQ_end -
2288 viafb_second_offset;
2289 }
2290
2291 memcpy(viafbinfo1, viafbinfo, sizeof(struct fb_info));
2292 viafbinfo1->screen_base = viafbinfo->screen_base +
2293 viafb_second_offset;
2294 viafbinfo1->fix.smem_start = viaparinfo1->fbmem;
2295 viafbinfo1->fix.smem_len = viaparinfo1->fbmem_free;
2296
2297 default_var.xres = viafb_second_xres;
2298 default_var.yres = viafb_second_yres;
2299 default_var.xres_virtual = viafb_second_virtual_xres;
2300 default_var.yres_virtual = viafb_second_virtual_yres;
2301 if (viafb_bpp1 != viafb_bpp)
2302 viafb_bpp1 = viafb_bpp;
2303 default_var.bits_per_pixel = viafb_bpp1;
2304 default_var.pixclock =
2305 viafb_get_pixclock(viafb_second_xres, viafb_second_yres,
2306 viafb_refresh);
2307 default_var.left_margin = (viafb_second_xres >> 3) & 0xf8;
2308 default_var.right_margin = 32;
2309 default_var.upper_margin = 16;
2310 default_var.lower_margin = 4;
2311 default_var.hsync_len = default_var.left_margin;
2312 default_var.vsync_len = 4;
2313
2314 viafb_setup_fixinfo(&viafbinfo1->fix, viaparinfo1);
2315 viafb_check_var(&default_var, viafbinfo1);
2316 viafbinfo1->var = default_var;
2317 viafb_update_viafb_par(viafbinfo);
2318 viafb_update_fix(&viafbinfo1->fix, viafbinfo1);
2319 }
2320
2321 viafb_setup_fixinfo(&viafbinfo->fix, viaparinfo);
2322 viafb_check_var(&default_var, viafbinfo);
2323 viafbinfo->var = default_var;
2324 viafb_update_viafb_par(viafbinfo);
2325 viafb_update_fix(&viafbinfo->fix, viafbinfo);
2326 default_var.activate = FB_ACTIVATE_NOW;
2327 fb_alloc_cmap(&viafbinfo->cmap, 256, 0);
2328
2329 if (viafb_dual_fb && (viafb_primary_dev == LCD_Device)
2330 && (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266)) {
2331 if (register_framebuffer(viafbinfo1) < 0)
2332 return -EINVAL;
2333 }
2334 if (register_framebuffer(viafbinfo) < 0)
2335 return -EINVAL;
2336
2337 if (viafb_dual_fb && ((viafb_primary_dev != LCD_Device)
2338 || (viaparinfo->chip_info->gfx_chip_name !=
2339 UNICHROME_CLE266))) {
2340 if (register_framebuffer(viafbinfo1) < 0)
2341 return -EINVAL;
2342 }
2343 DEBUG_MSG(KERN_INFO "fb%d: %s frame buffer device %dx%d-%dbpp\n",
2344 viafbinfo->node, viafbinfo->fix.id, default_var.xres,
2345 default_var.yres, default_var.bits_per_pixel);
2346
2347 viafb_init_proc(viaparinfo->proc_entry);
2348 viafb_init_dac(IGA2);
2349 return 0;
2350}
2351
2352static void __devexit via_pci_remove(void)
2353{
2354 DEBUG_MSG(KERN_INFO "via_pci_remove!\n");
2355 fb_dealloc_cmap(&viafbinfo->cmap);
2356 unregister_framebuffer(viafbinfo);
2357 if (viafb_dual_fb)
2358 unregister_framebuffer(viafbinfo1);
2359 iounmap((void *)viaparinfo->fbmem_virt);
2360 iounmap(viaparinfo->io_virt);
2361
2362 viafb_delete_i2c_buss(viaparinfo);
2363
2364 framebuffer_release(viafbinfo);
2365 if (viafb_dual_fb)
2366 framebuffer_release(viafbinfo1);
2367
2368 viafb_remove_proc(viaparinfo->proc_entry);
2369}
2370
2371#ifndef MODULE
2372static int __init viafb_setup(char *options)
2373{
2374 char *this_opt;
2375 DEBUG_MSG(KERN_INFO "viafb_setup!\n");
2376
2377 if (!options || !*options)
2378 return 0;
2379
2380 while ((this_opt = strsep(&options, ",")) != NULL) {
2381 if (!*this_opt)
2382 continue;
2383
2384 if (!strncmp(this_opt, "viafb_mode1=", 12))
2385 viafb_mode1 = kstrdup(this_opt + 12, GFP_KERNEL);
2386 else if (!strncmp(this_opt, "viafb_mode=", 11))
2387 viafb_mode = kstrdup(this_opt + 11, GFP_KERNEL);
2388 else if (!strncmp(this_opt, "viafb_bpp1=", 11))
2389 strict_strtoul(this_opt + 11, 0,
2390 (unsigned long *)&viafb_bpp1);
2391 else if (!strncmp(this_opt, "viafb_bpp=", 10))
2392 strict_strtoul(this_opt + 10, 0,
2393 (unsigned long *)&viafb_bpp);
2394 else if (!strncmp(this_opt, "viafb_refresh1=", 15))
2395 strict_strtoul(this_opt + 15, 0,
2396 (unsigned long *)&viafb_refresh1);
2397 else if (!strncmp(this_opt, "viafb_refresh=", 14))
2398 strict_strtoul(this_opt + 14, 0,
2399 (unsigned long *)&viafb_refresh);
2400 else if (!strncmp(this_opt, "viafb_lcd_dsp_method=", 21))
2401 strict_strtoul(this_opt + 21, 0,
2402 (unsigned long *)&viafb_lcd_dsp_method);
2403 else if (!strncmp(this_opt, "viafb_lcd_panel_id=", 19))
2404 strict_strtoul(this_opt + 19, 0,
2405 (unsigned long *)&viafb_lcd_panel_id);
2406 else if (!strncmp(this_opt, "viafb_accel=", 12))
2407 strict_strtoul(this_opt + 12, 0,
2408 (unsigned long *)&viafb_accel);
2409 else if (!strncmp(this_opt, "viafb_SAMM_ON=", 14))
2410 strict_strtoul(this_opt + 14, 0,
2411 (unsigned long *)&viafb_SAMM_ON);
2412 else if (!strncmp(this_opt, "viafb_active_dev=", 17))
2413 viafb_active_dev = kstrdup(this_opt + 17, GFP_KERNEL);
2414 else if (!strncmp(this_opt,
2415 "viafb_display_hardware_layout=", 30))
2416 strict_strtoul(this_opt + 30, 0,
2417 (unsigned long *)&viafb_display_hardware_layout);
2418 else if (!strncmp(this_opt, "viafb_second_size=", 18))
2419 strict_strtoul(this_opt + 18, 0,
2420 (unsigned long *)&viafb_second_size);
2421 else if (!strncmp(this_opt,
2422 "viafb_platform_epia_dvi=", 24))
2423 strict_strtoul(this_opt + 24, 0,
2424 (unsigned long *)&viafb_platform_epia_dvi);
2425 else if (!strncmp(this_opt,
2426 "viafb_device_lcd_dualedge=", 26))
2427 strict_strtoul(this_opt + 26, 0,
2428 (unsigned long *)&viafb_device_lcd_dualedge);
2429 else if (!strncmp(this_opt, "viafb_bus_width=", 16))
2430 strict_strtoul(this_opt + 16, 0,
2431 (unsigned long *)&viafb_bus_width);
2432 else if (!strncmp(this_opt, "viafb_lcd_mode=", 15))
2433 strict_strtoul(this_opt + 15, 0,
2434 (unsigned long *)&viafb_lcd_mode);
2435 else if (!strncmp(this_opt, "viafb_video_dev=", 16))
2436 viafb_video_dev = kstrdup(this_opt + 16, GFP_KERNEL);
2437 else if (!strncmp(this_opt, "viafb_lcd_port=", 15))
2438 viafb_lcd_port = kstrdup(this_opt + 15, GFP_KERNEL);
2439 else if (!strncmp(this_opt, "viafb_dvi_port=", 15))
2440 viafb_dvi_port = kstrdup(this_opt + 15, GFP_KERNEL);
2441 }
2442 return 0;
2443}
2444#endif
2445
2446static int __init viafb_init(void)
2447{
2448#ifndef MODULE
2449 char *option = NULL;
2450 if (fb_get_options("viafb", &option))
2451 return -ENODEV;
2452 viafb_setup(option);
2453#endif
2454 printk(KERN_INFO
2455 "VIA Graphics Intergration Chipset framebuffer %d.%d initializing\n",
2456 VERSION_MAJOR, VERSION_MINOR);
2457 return via_pci_probe();
2458}
2459
2460static void __exit viafb_exit(void)
2461{
2462 DEBUG_MSG(KERN_INFO "viafb_exit!\n");
2463 via_pci_remove();
2464}
2465
2466static struct fb_ops viafb_ops = {
2467 .owner = THIS_MODULE,
2468 .fb_open = viafb_open,
2469 .fb_release = viafb_release,
2470 .fb_check_var = viafb_check_var,
2471 .fb_set_par = viafb_set_par,
2472 .fb_setcolreg = viafb_setcolreg,
2473 .fb_pan_display = viafb_pan_display,
2474 .fb_blank = viafb_blank,
2475 .fb_fillrect = viafb_fillrect,
2476 .fb_copyarea = viafb_copyarea,
2477 .fb_imageblit = viafb_imageblit,
2478 .fb_cursor = viafb_cursor,
2479 .fb_ioctl = viafb_ioctl,
2480 .fb_sync = viafb_sync,
2481 .fb_setcmap = viafb_setcmap,
2482};
2483
2484module_init(viafb_init);
2485module_exit(viafb_exit);
2486
2487#ifdef MODULE
2488module_param(viafb_memsize, int, 0);
2489
2490module_param(viafb_mode, charp, 0);
2491MODULE_PARM_DESC(viafb_mode, "Set resolution (default=640x480)");
2492
2493module_param(viafb_mode1, charp, 0);
2494MODULE_PARM_DESC(viafb_mode1, "Set resolution (default=640x480)");
2495
2496module_param(viafb_bpp, int, 0);
2497MODULE_PARM_DESC(viafb_bpp, "Set color depth (default=32bpp)");
2498
2499module_param(viafb_bpp1, int, 0);
2500MODULE_PARM_DESC(viafb_bpp1, "Set color depth (default=32bpp)");
2501
2502module_param(viafb_refresh, int, 0);
2503MODULE_PARM_DESC(viafb_refresh,
2504 "Set CRT viafb_refresh rate (default = 60)");
2505
2506module_param(viafb_refresh1, int, 0);
2507MODULE_PARM_DESC(viafb_refresh1,
2508 "Set CRT refresh rate (default = 60)");
2509
2510module_param(viafb_lcd_panel_id, int, 0);
2511MODULE_PARM_DESC(viafb_lcd_panel_id,
2512 "Set Flat Panel type(Default=1024x768)");
2513
2514module_param(viafb_lcd_dsp_method, int, 0);
2515MODULE_PARM_DESC(viafb_lcd_dsp_method,
2516 "Set Flat Panel display scaling method.(Default=Expandsion)");
2517
2518module_param(viafb_SAMM_ON, int, 0);
2519MODULE_PARM_DESC(viafb_SAMM_ON,
2520 "Turn on/off flag of SAMM(Default=OFF)");
2521
2522module_param(viafb_accel, int, 0);
2523MODULE_PARM_DESC(viafb_accel,
2524 "Set 2D Hardware Acceleration.(Default = OFF)");
2525
2526module_param(viafb_active_dev, charp, 0);
2527MODULE_PARM_DESC(viafb_active_dev, "Specify active devices.");
2528
2529module_param(viafb_display_hardware_layout, int, 0);
2530MODULE_PARM_DESC(viafb_display_hardware_layout,
2531 "Display Hardware Layout (LCD Only, DVI Only...,etc)");
2532
2533module_param(viafb_second_size, int, 0);
2534MODULE_PARM_DESC(viafb_second_size,
2535 "Set secondary device memory size");
2536
2537module_param(viafb_dual_fb, int, 0);
2538MODULE_PARM_DESC(viafb_dual_fb,
2539 "Turn on/off flag of dual framebuffer devices.(Default = OFF)");
2540
2541module_param(viafb_platform_epia_dvi, int, 0);
2542MODULE_PARM_DESC(viafb_platform_epia_dvi,
2543 "Turn on/off flag of DVI devices on EPIA board.(Default = OFF)");
2544
2545module_param(viafb_device_lcd_dualedge, int, 0);
2546MODULE_PARM_DESC(viafb_device_lcd_dualedge,
2547 "Turn on/off flag of dual edge panel.(Default = OFF)");
2548
2549module_param(viafb_bus_width, int, 0);
2550MODULE_PARM_DESC(viafb_bus_width,
2551 "Set bus width of panel.(Default = 12)");
2552
2553module_param(viafb_lcd_mode, int, 0);
2554MODULE_PARM_DESC(viafb_lcd_mode,
2555 "Set Flat Panel mode(Default=OPENLDI)");
2556
2557module_param(viafb_video_dev, charp, 0);
2558MODULE_PARM_DESC(viafb_video_dev, "Specify video devices.");
2559
2560module_param(viafb_lcd_port, charp, 0);
2561MODULE_PARM_DESC(viafb_lcd_port, "Specify LCD output port.");
2562
2563module_param(viafb_dvi_port, charp, 0);
2564MODULE_PARM_DESC(viafb_dvi_port, "Specify DVI output port.");
2565
2566MODULE_LICENSE("GPL");
2567#endif