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