blob: 924177cc814e0bb5207f8990b6228aee5f52daf8 [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";
Joseph Chan29b619f2008-10-15 22:03:27 -070035
36/* Added for specifying active devices.*/
37char *viafb_active_dev = "";
38
Joseph Chan29b619f2008-10-15 22:03:27 -070039/*Added for specify lcd output port*/
40char *viafb_lcd_port = "";
41char *viafb_dvi_port = "";
42
43static void viafb_set_device(struct device_t active_dev);
44static int apply_device_setting(struct viafb_ioctl_setting setting_info,
45 struct fb_info *info);
46static void apply_second_mode_setting(struct fb_var_screeninfo
47 *sec_var);
48static void retrieve_device_setting(struct viafb_ioctl_setting
49 *setting_info);
Joseph Chan29b619f2008-10-15 22:03:27 -070050
Joseph Chan29b619f2008-10-15 22:03:27 -070051static struct fb_ops viafb_ops;
52
Florian Tobias Schandinat81228a32009-09-22 16:47:13 -070053
54static void viafb_update_fix(struct fb_info *info)
Joseph Chan29b619f2008-10-15 22:03:27 -070055{
Florian Tobias Schandinat81228a32009-09-22 16:47:13 -070056 u32 bpp = info->var.bits_per_pixel;
Joseph Chan29b619f2008-10-15 22:03:27 -070057
Florian Tobias Schandinat81228a32009-09-22 16:47:13 -070058 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;
Joseph Chan29b619f2008-10-15 22:03:27 -070062}
63
Joseph Chan29b619f2008-10-15 22:03:27 -070064static 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 fix->mmio_start = viaparinfo->mmio_base;
73 fix->mmio_len = viaparinfo->mmio_len;
74
75 fix->type = FB_TYPE_PACKED_PIXELS;
76 fix->type_aux = 0;
77
78 fix->xpanstep = fix->ywrapstep = 0;
79 fix->ypanstep = 1;
80
81 /* Just tell the accel name */
82 viafbinfo->fix.accel = FB_ACCEL_VIA_UNICHROME;
83}
84static int viafb_open(struct fb_info *info, int user)
85{
86 DEBUG_MSG(KERN_INFO "viafb_open!\n");
87 return 0;
88}
89
90static int viafb_release(struct fb_info *info, int user)
91{
92 DEBUG_MSG(KERN_INFO "viafb_release!\n");
93 return 0;
94}
95
Joseph Chan29b619f2008-10-15 22:03:27 -070096static int viafb_check_var(struct fb_var_screeninfo *var,
97 struct fb_info *info)
98{
99 int vmode_index, htotal, vtotal;
100 struct viafb_par *ppar;
101 u32 long_refresh;
102 struct viafb_par *p_viafb_par;
103 ppar = info->par;
104
105
106 DEBUG_MSG(KERN_INFO "viafb_check_var!\n");
107 /* Sanity check */
108 /* HW neither support interlacte nor double-scaned mode */
109 if (var->vmode & FB_VMODE_INTERLACED || var->vmode & FB_VMODE_DOUBLE)
110 return -EINVAL;
111
Florian Tobias Schandinat52159442009-08-06 15:07:34 -0700112 vmode_index = viafb_get_mode_index(var->xres, var->yres);
Joseph Chan29b619f2008-10-15 22:03:27 -0700113 if (vmode_index == VIA_RES_INVALID) {
114 DEBUG_MSG(KERN_INFO
115 "viafb: Mode %dx%dx%d not supported!!\n",
116 var->xres, var->yres, var->bits_per_pixel);
117 return -EINVAL;
118 }
119
120 if (24 == var->bits_per_pixel)
121 var->bits_per_pixel = 32;
122
123 if (var->bits_per_pixel != 8 && var->bits_per_pixel != 16 &&
124 var->bits_per_pixel != 32)
125 return -EINVAL;
126
127 if ((var->xres_virtual * (var->bits_per_pixel >> 3)) & 0x1F)
128 /*32 pixel alignment */
129 var->xres_virtual = (var->xres_virtual + 31) & ~31;
130 if (var->xres_virtual * var->yres_virtual * var->bits_per_pixel / 8 >
131 ppar->memsize)
132 return -EINVAL;
133
134 /* Based on var passed in to calculate the refresh,
135 * because our driver use some modes special.
136 */
137 htotal = var->xres + var->left_margin +
138 var->right_margin + var->hsync_len;
139 vtotal = var->yres + var->upper_margin +
140 var->lower_margin + var->vsync_len;
141 long_refresh = 1000000000UL / var->pixclock * 1000;
142 long_refresh /= (htotal * vtotal);
143
144 viafb_refresh = viafb_get_refresh(var->xres, var->yres, long_refresh);
145
146 /* Adjust var according to our driver's own table */
147 viafb_fill_var_timing_info(var, viafb_refresh, vmode_index);
148
149 /* This is indeed a patch for VT3353 */
150 if (!info->par)
151 return -1;
152 p_viafb_par = (struct viafb_par *)info->par;
153 if (p_viafb_par->chip_info->gfx_chip_name == UNICHROME_VX800)
154 var->accel_flags = 0;
155
156 return 0;
157}
158
159static int viafb_set_par(struct fb_info *info)
160{
161 int vmode_index;
162 int vmode_index1 = 0;
163 DEBUG_MSG(KERN_INFO "viafb_set_par!\n");
164
165 viafb_update_device_setting(info->var.xres, info->var.yres,
166 info->var.bits_per_pixel, viafb_refresh, 0);
167
Florian Tobias Schandinat52159442009-08-06 15:07:34 -0700168 vmode_index = viafb_get_mode_index(info->var.xres, info->var.yres);
Joseph Chan29b619f2008-10-15 22:03:27 -0700169
170 if (viafb_SAMM_ON == 1) {
171 DEBUG_MSG(KERN_INFO
172 "viafb_second_xres = %d, viafb_second_yres = %d, bpp = %d\n",
173 viafb_second_xres, viafb_second_yres, viafb_bpp1);
174 vmode_index1 = viafb_get_mode_index(viafb_second_xres,
Florian Tobias Schandinat52159442009-08-06 15:07:34 -0700175 viafb_second_yres);
Joseph Chan29b619f2008-10-15 22:03:27 -0700176 DEBUG_MSG(KERN_INFO "->viafb_SAMM_ON: index=%d\n",
177 vmode_index1);
178
179 viafb_update_device_setting(viafb_second_xres,
180 viafb_second_yres, viafb_bpp1, viafb_refresh1, 1);
181 }
182
183 if (vmode_index != VIA_RES_INVALID) {
184 viafb_setmode(vmode_index, info->var.xres, info->var.yres,
185 info->var.bits_per_pixel, vmode_index1,
186 viafb_second_xres, viafb_second_yres, viafb_bpp1);
187
188 /*We should set memory offset according virtual_x */
189 /*Fix me:put this function into viafb_setmode */
190 viafb_memory_pitch_patch(info);
Florian Tobias Schandinat81228a32009-09-22 16:47:13 -0700191 viafb_update_fix(info);
Joseph Chan29b619f2008-10-15 22:03:27 -0700192 viafb_bpp = info->var.bits_per_pixel;
193 /* Update viafb_accel, it is necessary to our 2D accelerate */
194 viafb_accel = info->var.accel_flags;
195
196 if (viafb_accel)
197 viafb_set_2d_color_depth(info->var.bits_per_pixel);
198 }
199
200 return 0;
201}
202
203/* Set one color register */
204static int viafb_setcolreg(unsigned regno, unsigned red, unsigned green,
205unsigned blue, unsigned transp, struct fb_info *info)
206{
207 u8 sr1a, sr1b, cr67, cr6a, rev = 0, shift = 10;
208 unsigned cmap_entries = (info->var.bits_per_pixel == 8) ? 256 : 16;
209 DEBUG_MSG(KERN_INFO "viafb_setcolreg!\n");
210 if (regno >= cmap_entries)
211 return 1;
212 if (UNICHROME_CLE266 == viaparinfo->chip_info->gfx_chip_name) {
213 /*
214 * Read PCI bus 0,dev 0,function 0,index 0xF6 to get chip rev.
215 */
216 outl(0x80000000 | (0xf6 & ~3), (unsigned long)0xCF8);
217 rev = (inl((unsigned long)0xCFC) >> ((0xf6 & 3) * 8)) & 0xff;
218 }
219 switch (info->var.bits_per_pixel) {
220 case 8:
221 outb(0x1A, 0x3C4);
222 sr1a = inb(0x3C5);
223 outb(0x1B, 0x3C4);
224 sr1b = inb(0x3C5);
225 outb(0x67, 0x3D4);
226 cr67 = inb(0x3D5);
227 outb(0x6A, 0x3D4);
228 cr6a = inb(0x3D5);
229
230 /* Map the 3C6/7/8/9 to the IGA2 */
231 outb(0x1A, 0x3C4);
232 outb(sr1a | 0x01, 0x3C5);
233 /* Second Display Engine colck always on */
234 outb(0x1B, 0x3C4);
235 outb(sr1b | 0x80, 0x3C5);
236 /* Second Display Color Depth 8 */
237 outb(0x67, 0x3D4);
238 outb(cr67 & 0x3F, 0x3D5);
239 outb(0x6A, 0x3D4);
240 /* Second Display Channel Reset CR6A[6]) */
241 outb(cr6a & 0xBF, 0x3D5);
242 /* Second Display Channel Enable CR6A[7] */
243 outb(cr6a | 0x80, 0x3D5);
244 /* Second Display Channel stop reset) */
245 outb(cr6a | 0x40, 0x3D5);
246
247 /* Bit mask of palette */
248 outb(0xFF, 0x3c6);
249 /* Write one register of IGA2 */
250 outb(regno, 0x3C8);
251 if (UNICHROME_CLE266 == viaparinfo->chip_info->gfx_chip_name &&
252 rev >= 15) {
253 shift = 8;
254 viafb_write_reg_mask(CR6A, VIACR, BIT5, BIT5);
255 viafb_write_reg_mask(SR15, VIASR, BIT7, BIT7);
256 } else {
257 shift = 10;
258 viafb_write_reg_mask(CR6A, VIACR, 0, BIT5);
259 viafb_write_reg_mask(SR15, VIASR, 0, BIT7);
260 }
261 outb(red >> shift, 0x3C9);
262 outb(green >> shift, 0x3C9);
263 outb(blue >> shift, 0x3C9);
264
265 /* Map the 3C6/7/8/9 to the IGA1 */
266 outb(0x1A, 0x3C4);
267 outb(sr1a & 0xFE, 0x3C5);
268 /* Bit mask of palette */
269 outb(0xFF, 0x3c6);
270 /* Write one register of IGA1 */
271 outb(regno, 0x3C8);
272 outb(red >> shift, 0x3C9);
273 outb(green >> shift, 0x3C9);
274 outb(blue >> shift, 0x3C9);
275
276 outb(0x1A, 0x3C4);
277 outb(sr1a, 0x3C5);
278 outb(0x1B, 0x3C4);
279 outb(sr1b, 0x3C5);
280 outb(0x67, 0x3D4);
281 outb(cr67, 0x3D5);
282 outb(0x6A, 0x3D4);
283 outb(cr6a, 0x3D5);
284 break;
285 case 16:
286 ((u32 *) info->pseudo_palette)[regno] = (red & 0xF800) |
287 ((green & 0xFC00) >> 5) | ((blue & 0xF800) >> 11);
288 break;
289 case 32:
290 ((u32 *) info->pseudo_palette)[regno] =
291 ((transp & 0xFF00) << 16) |
292 ((red & 0xFF00) << 8) |
293 ((green & 0xFF00)) | ((blue & 0xFF00) >> 8);
294 break;
295 }
296
297 return 0;
298
299}
300
301/*CALLED BY: fb_set_cmap */
302/* fb_set_var, pass 256 colors */
303/*CALLED BY: fb_set_cmap */
304/* fbcon_set_palette, pass 16 colors */
305static int viafb_setcmap(struct fb_cmap *cmap, struct fb_info *info)
306{
307 u32 len = cmap->len;
308 u32 i;
309 u16 *pred = cmap->red;
310 u16 *pgreen = cmap->green;
311 u16 *pblue = cmap->blue;
312 u16 *ptransp = cmap->transp;
313 u8 sr1a, sr1b, cr67, cr6a, rev = 0, shift = 10;
314 if (len > 256)
315 return 1;
316 if (UNICHROME_CLE266 == viaparinfo->chip_info->gfx_chip_name) {
317 /*
318 * Read PCI bus 0, dev 0, function 0, index 0xF6 to get chip
319 * rev.
320 */
321 outl(0x80000000 | (0xf6 & ~3), (unsigned long)0xCF8);
322 rev = (inl((unsigned long)0xCFC) >> ((0xf6 & 3) * 8)) & 0xff;
323 }
324 switch (info->var.bits_per_pixel) {
325 case 8:
326 outb(0x1A, 0x3C4);
327 sr1a = inb(0x3C5);
328 outb(0x1B, 0x3C4);
329 sr1b = inb(0x3C5);
330 outb(0x67, 0x3D4);
331 cr67 = inb(0x3D5);
332 outb(0x6A, 0x3D4);
333 cr6a = inb(0x3D5);
334 /* Map the 3C6/7/8/9 to the IGA2 */
335 outb(0x1A, 0x3C4);
336 outb(sr1a | 0x01, 0x3C5);
337 outb(0x1B, 0x3C4);
338 /* Second Display Engine colck always on */
339 outb(sr1b | 0x80, 0x3C5);
340 outb(0x67, 0x3D4);
341 /* Second Display Color Depth 8 */
342 outb(cr67 & 0x3F, 0x3D5);
343 outb(0x6A, 0x3D4);
344 /* Second Display Channel Reset CR6A[6]) */
345 outb(cr6a & 0xBF, 0x3D5);
346 /* Second Display Channel Enable CR6A[7] */
347 outb(cr6a | 0x80, 0x3D5);
348 /* Second Display Channel stop reset) */
349 outb(cr6a | 0xC0, 0x3D5);
350
351 /* Bit mask of palette */
352 outb(0xFF, 0x3c6);
353 outb(0x00, 0x3C8);
354 if (UNICHROME_CLE266 == viaparinfo->chip_info->gfx_chip_name &&
355 rev >= 15) {
356 shift = 8;
357 viafb_write_reg_mask(CR6A, VIACR, BIT5, BIT5);
358 viafb_write_reg_mask(SR15, VIASR, BIT7, BIT7);
359 } else {
360 shift = 10;
361 viafb_write_reg_mask(CR6A, VIACR, 0, BIT5);
362 viafb_write_reg_mask(SR15, VIASR, 0, BIT7);
363 }
364 for (i = 0; i < len; i++) {
365 outb((*(pred + i)) >> shift, 0x3C9);
366 outb((*(pgreen + i)) >> shift, 0x3C9);
367 outb((*(pblue + i)) >> shift, 0x3C9);
368 }
369
370 outb(0x1A, 0x3C4);
371 /* Map the 3C6/7/8/9 to the IGA1 */
372 outb(sr1a & 0xFE, 0x3C5);
373 /* Bit mask of palette */
374 outb(0xFF, 0x3c6);
375 outb(0x00, 0x3C8);
376 for (i = 0; i < len; i++) {
377 outb((*(pred + i)) >> shift, 0x3C9);
378 outb((*(pgreen + i)) >> shift, 0x3C9);
379 outb((*(pblue + i)) >> shift, 0x3C9);
380 }
381
382 outb(0x1A, 0x3C4);
383 outb(sr1a, 0x3C5);
384 outb(0x1B, 0x3C4);
385 outb(sr1b, 0x3C5);
386 outb(0x67, 0x3D4);
387 outb(cr67, 0x3D5);
388 outb(0x6A, 0x3D4);
389 outb(cr6a, 0x3D5);
390 break;
391 case 16:
392 if (len > 17)
393 return 0; /* Because static u32 pseudo_pal[17]; */
394 for (i = 0; i < len; i++)
395 ((u32 *) info->pseudo_palette)[i] =
396 (*(pred + i) & 0xF800) |
397 ((*(pgreen + i) & 0xFC00) >> 5) |
398 ((*(pblue + i) & 0xF800) >> 11);
399 break;
400 case 32:
401 if (len > 17)
402 return 0;
403 if (ptransp) {
404 for (i = 0; i < len; i++)
405 ((u32 *) info->pseudo_palette)[i] =
406 ((*(ptransp + i) & 0xFF00) << 16) |
407 ((*(pred + i) & 0xFF00) << 8) |
408 ((*(pgreen + i) & 0xFF00)) |
409 ((*(pblue + i) & 0xFF00) >> 8);
410 } else {
411 for (i = 0; i < len; i++)
412 ((u32 *) info->pseudo_palette)[i] =
413 0x00000000 |
414 ((*(pred + i) & 0xFF00) << 8) |
415 ((*(pgreen + i) & 0xFF00)) |
416 ((*(pblue + i) & 0xFF00) >> 8);
417 }
418 break;
419 }
420 return 0;
421}
422
423static int viafb_pan_display(struct fb_var_screeninfo *var,
424 struct fb_info *info)
425{
426 unsigned int offset;
427
428 DEBUG_MSG(KERN_INFO "viafb_pan_display!\n");
429
430 offset = (var->xoffset + (var->yoffset * var->xres_virtual)) *
431 var->bits_per_pixel / 16;
432
433 DEBUG_MSG(KERN_INFO "\nviafb_pan_display,offset =%d ", offset);
Florian Tobias Schandinat09cf1182009-09-22 16:47:14 -0700434 viafb_set_primary_address(offset);
Joseph Chan29b619f2008-10-15 22:03:27 -0700435 return 0;
436}
437
438static int viafb_blank(int blank_mode, struct fb_info *info)
439{
440 DEBUG_MSG(KERN_INFO "viafb_blank!\n");
441 /* clear DPMS setting */
442
443 switch (blank_mode) {
444 case FB_BLANK_UNBLANK:
445 /* Screen: On, HSync: On, VSync: On */
446 /* control CRT monitor power management */
447 viafb_write_reg_mask(CR36, VIACR, 0x00, BIT4 + BIT5);
448 break;
449 case FB_BLANK_HSYNC_SUSPEND:
450 /* Screen: Off, HSync: Off, VSync: On */
451 /* control CRT monitor power management */
452 viafb_write_reg_mask(CR36, VIACR, 0x10, BIT4 + BIT5);
453 break;
454 case FB_BLANK_VSYNC_SUSPEND:
455 /* Screen: Off, HSync: On, VSync: Off */
456 /* control CRT monitor power management */
457 viafb_write_reg_mask(CR36, VIACR, 0x20, BIT4 + BIT5);
458 break;
459 case FB_BLANK_POWERDOWN:
460 /* Screen: Off, HSync: Off, VSync: Off */
461 /* control CRT monitor power management */
462 viafb_write_reg_mask(CR36, VIACR, 0x30, BIT4 + BIT5);
463 break;
464 }
465
466 return 0;
467}
468
469static int viafb_ioctl(struct fb_info *info, u_int cmd, u_long arg)
470{
Bruno Prémonte687d692009-01-04 13:11:54 -0800471 union {
472 struct viafb_ioctl_mode viamode;
473 struct viafb_ioctl_samm viasamm;
474 struct viafb_driver_version driver_version;
475 struct fb_var_screeninfo sec_var;
476 struct _panel_size_pos_info panel_pos_size_para;
477 struct viafb_ioctl_setting viafb_setting;
478 struct device_t active_dev;
479 } u;
Joseph Chan29b619f2008-10-15 22:03:27 -0700480 u32 state_info = 0;
Joseph Chan29b619f2008-10-15 22:03:27 -0700481 u32 *viafb_gamma_table;
482 char driver_name[] = "viafb";
483
484 u32 __user *argp = (u32 __user *) arg;
485 u32 gpu32;
Joseph Chan29b619f2008-10-15 22:03:27 -0700486
487 DEBUG_MSG(KERN_INFO "viafb_ioctl: 0x%X !!\n", cmd);
Bruno Prémonte687d692009-01-04 13:11:54 -0800488 memset(&u, 0, sizeof(u));
Joseph Chan29b619f2008-10-15 22:03:27 -0700489
490 switch (cmd) {
491 case VIAFB_GET_CHIP_INFO:
492 if (copy_to_user(argp, viaparinfo->chip_info,
493 sizeof(struct chip_information)))
494 return -EFAULT;
495 break;
496 case VIAFB_GET_INFO_SIZE:
Bruno Prémonte687d692009-01-04 13:11:54 -0800497 return put_user((u32)sizeof(struct viafb_ioctl_info), argp);
Joseph Chan29b619f2008-10-15 22:03:27 -0700498 case VIAFB_GET_INFO:
499 return viafb_ioctl_get_viafb_info(arg);
500 case VIAFB_HOTPLUG:
501 return put_user(viafb_ioctl_hotplug(info->var.xres,
502 info->var.yres,
503 info->var.bits_per_pixel), argp);
504 case VIAFB_SET_HOTPLUG_FLAG:
505 if (copy_from_user(&gpu32, argp, sizeof(gpu32)))
506 return -EFAULT;
507 viafb_hotplug = (gpu32) ? 1 : 0;
508 break;
509 case VIAFB_GET_RESOLUTION:
Bruno Prémonte687d692009-01-04 13:11:54 -0800510 u.viamode.xres = (u32) viafb_hotplug_Xres;
511 u.viamode.yres = (u32) viafb_hotplug_Yres;
512 u.viamode.refresh = (u32) viafb_hotplug_refresh;
513 u.viamode.bpp = (u32) viafb_hotplug_bpp;
Joseph Chan29b619f2008-10-15 22:03:27 -0700514 if (viafb_SAMM_ON == 1) {
Bruno Prémonte687d692009-01-04 13:11:54 -0800515 u.viamode.xres_sec = viafb_second_xres;
516 u.viamode.yres_sec = viafb_second_yres;
517 u.viamode.virtual_xres_sec = viafb_second_virtual_xres;
518 u.viamode.virtual_yres_sec = viafb_second_virtual_yres;
519 u.viamode.refresh_sec = viafb_refresh1;
520 u.viamode.bpp_sec = viafb_bpp1;
Joseph Chan29b619f2008-10-15 22:03:27 -0700521 } else {
Bruno Prémonte687d692009-01-04 13:11:54 -0800522 u.viamode.xres_sec = 0;
523 u.viamode.yres_sec = 0;
524 u.viamode.virtual_xres_sec = 0;
525 u.viamode.virtual_yres_sec = 0;
526 u.viamode.refresh_sec = 0;
527 u.viamode.bpp_sec = 0;
Joseph Chan29b619f2008-10-15 22:03:27 -0700528 }
Bruno Prémonte687d692009-01-04 13:11:54 -0800529 if (copy_to_user(argp, &u.viamode, sizeof(u.viamode)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700530 return -EFAULT;
531 break;
532 case VIAFB_GET_SAMM_INFO:
Bruno Prémonte687d692009-01-04 13:11:54 -0800533 u.viasamm.samm_status = viafb_SAMM_ON;
Joseph Chan29b619f2008-10-15 22:03:27 -0700534
535 if (viafb_SAMM_ON == 1) {
536 if (viafb_dual_fb) {
Bruno Prémonte687d692009-01-04 13:11:54 -0800537 u.viasamm.size_prim = viaparinfo->fbmem_free;
538 u.viasamm.size_sec = viaparinfo1->fbmem_free;
Joseph Chan29b619f2008-10-15 22:03:27 -0700539 } else {
540 if (viafb_second_size) {
Bruno Prémonte687d692009-01-04 13:11:54 -0800541 u.viasamm.size_prim =
Joseph Chan29b619f2008-10-15 22:03:27 -0700542 viaparinfo->fbmem_free -
543 viafb_second_size * 1024 * 1024;
Bruno Prémonte687d692009-01-04 13:11:54 -0800544 u.viasamm.size_sec =
Joseph Chan29b619f2008-10-15 22:03:27 -0700545 viafb_second_size * 1024 * 1024;
546 } else {
Bruno Prémonte687d692009-01-04 13:11:54 -0800547 u.viasamm.size_prim =
Joseph Chan29b619f2008-10-15 22:03:27 -0700548 viaparinfo->fbmem_free >> 1;
Bruno Prémonte687d692009-01-04 13:11:54 -0800549 u.viasamm.size_sec =
Joseph Chan29b619f2008-10-15 22:03:27 -0700550 (viaparinfo->fbmem_free >> 1);
551 }
552 }
Bruno Prémonte687d692009-01-04 13:11:54 -0800553 u.viasamm.mem_base = viaparinfo->fbmem;
554 u.viasamm.offset_sec = viafb_second_offset;
Joseph Chan29b619f2008-10-15 22:03:27 -0700555 } else {
Bruno Prémonte687d692009-01-04 13:11:54 -0800556 u.viasamm.size_prim =
Joseph Chan29b619f2008-10-15 22:03:27 -0700557 viaparinfo->memsize - viaparinfo->fbmem_used;
Bruno Prémonte687d692009-01-04 13:11:54 -0800558 u.viasamm.size_sec = 0;
559 u.viasamm.mem_base = viaparinfo->fbmem;
560 u.viasamm.offset_sec = 0;
Joseph Chan29b619f2008-10-15 22:03:27 -0700561 }
562
Bruno Prémonte687d692009-01-04 13:11:54 -0800563 if (copy_to_user(argp, &u.viasamm, sizeof(u.viasamm)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700564 return -EFAULT;
565
566 break;
567 case VIAFB_TURN_ON_OUTPUT_DEVICE:
568 if (copy_from_user(&gpu32, argp, sizeof(gpu32)))
569 return -EFAULT;
570 if (gpu32 & CRT_Device)
571 viafb_crt_enable();
572 if (gpu32 & DVI_Device)
573 viafb_dvi_enable();
574 if (gpu32 & LCD_Device)
575 viafb_lcd_enable();
576 break;
577 case VIAFB_TURN_OFF_OUTPUT_DEVICE:
578 if (copy_from_user(&gpu32, argp, sizeof(gpu32)))
579 return -EFAULT;
580 if (gpu32 & CRT_Device)
581 viafb_crt_disable();
582 if (gpu32 & DVI_Device)
583 viafb_dvi_disable();
584 if (gpu32 & LCD_Device)
585 viafb_lcd_disable();
586 break;
587 case VIAFB_SET_DEVICE:
Bruno Prémonte687d692009-01-04 13:11:54 -0800588 if (copy_from_user(&u.active_dev, (void *)argp,
589 sizeof(u.active_dev)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700590 return -EFAULT;
Bruno Prémonte687d692009-01-04 13:11:54 -0800591 viafb_set_device(u.active_dev);
Joseph Chan29b619f2008-10-15 22:03:27 -0700592 viafb_set_par(info);
593 break;
594 case VIAFB_GET_DEVICE:
Bruno Prémonte687d692009-01-04 13:11:54 -0800595 u.active_dev.crt = viafb_CRT_ON;
596 u.active_dev.dvi = viafb_DVI_ON;
597 u.active_dev.lcd = viafb_LCD_ON;
598 u.active_dev.samm = viafb_SAMM_ON;
599 u.active_dev.primary_dev = viafb_primary_dev;
Joseph Chan29b619f2008-10-15 22:03:27 -0700600
Bruno Prémonte687d692009-01-04 13:11:54 -0800601 u.active_dev.lcd_dsp_cent = viafb_lcd_dsp_method;
602 u.active_dev.lcd_panel_id = viafb_lcd_panel_id;
603 u.active_dev.lcd_mode = viafb_lcd_mode;
Joseph Chan29b619f2008-10-15 22:03:27 -0700604
Bruno Prémonte687d692009-01-04 13:11:54 -0800605 u.active_dev.xres = viafb_hotplug_Xres;
606 u.active_dev.yres = viafb_hotplug_Yres;
Joseph Chan29b619f2008-10-15 22:03:27 -0700607
Bruno Prémonte687d692009-01-04 13:11:54 -0800608 u.active_dev.xres1 = viafb_second_xres;
609 u.active_dev.yres1 = viafb_second_yres;
Joseph Chan29b619f2008-10-15 22:03:27 -0700610
Bruno Prémonte687d692009-01-04 13:11:54 -0800611 u.active_dev.bpp = viafb_bpp;
612 u.active_dev.bpp1 = viafb_bpp1;
613 u.active_dev.refresh = viafb_refresh;
614 u.active_dev.refresh1 = viafb_refresh1;
Joseph Chan29b619f2008-10-15 22:03:27 -0700615
Bruno Prémonte687d692009-01-04 13:11:54 -0800616 u.active_dev.epia_dvi = viafb_platform_epia_dvi;
617 u.active_dev.lcd_dual_edge = viafb_device_lcd_dualedge;
618 u.active_dev.bus_width = viafb_bus_width;
Joseph Chan29b619f2008-10-15 22:03:27 -0700619
Bruno Prémonte687d692009-01-04 13:11:54 -0800620 if (copy_to_user(argp, &u.active_dev, sizeof(u.active_dev)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700621 return -EFAULT;
622 break;
623
624 case VIAFB_GET_DRIVER_VERSION:
Bruno Prémonte687d692009-01-04 13:11:54 -0800625 u.driver_version.iMajorNum = VERSION_MAJOR;
626 u.driver_version.iKernelNum = VERSION_KERNEL;
627 u.driver_version.iOSNum = VERSION_OS;
628 u.driver_version.iMinorNum = VERSION_MINOR;
Joseph Chan29b619f2008-10-15 22:03:27 -0700629
Bruno Prémonte687d692009-01-04 13:11:54 -0800630 if (copy_to_user(argp, &u.driver_version,
631 sizeof(u.driver_version)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700632 return -EFAULT;
633
634 break;
635
636 case VIAFB_SET_DEVICE_INFO:
Bruno Prémonte687d692009-01-04 13:11:54 -0800637 if (copy_from_user(&u.viafb_setting,
638 argp, sizeof(u.viafb_setting)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700639 return -EFAULT;
Bruno Prémonte687d692009-01-04 13:11:54 -0800640 if (apply_device_setting(u.viafb_setting, info) < 0)
Joseph Chan29b619f2008-10-15 22:03:27 -0700641 return -EINVAL;
642
643 break;
644
645 case VIAFB_SET_SECOND_MODE:
Bruno Prémonte687d692009-01-04 13:11:54 -0800646 if (copy_from_user(&u.sec_var, argp, sizeof(u.sec_var)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700647 return -EFAULT;
Bruno Prémonte687d692009-01-04 13:11:54 -0800648 apply_second_mode_setting(&u.sec_var);
Joseph Chan29b619f2008-10-15 22:03:27 -0700649 break;
650
651 case VIAFB_GET_DEVICE_INFO:
652
Bruno Prémonte687d692009-01-04 13:11:54 -0800653 retrieve_device_setting(&u.viafb_setting);
Joseph Chan29b619f2008-10-15 22:03:27 -0700654
Bruno Prémonte687d692009-01-04 13:11:54 -0800655 if (copy_to_user(argp, &u.viafb_setting,
656 sizeof(u.viafb_setting)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700657 return -EFAULT;
658
659 break;
660
661 case VIAFB_GET_DEVICE_SUPPORT:
662 viafb_get_device_support_state(&state_info);
663 if (put_user(state_info, argp))
664 return -EFAULT;
665 break;
666
667 case VIAFB_GET_DEVICE_CONNECT:
668 viafb_get_device_connect_state(&state_info);
669 if (put_user(state_info, argp))
670 return -EFAULT;
671 break;
672
673 case VIAFB_GET_PANEL_SUPPORT_EXPAND:
674 state_info =
675 viafb_lcd_get_support_expand_state(info->var.xres,
676 info->var.yres);
677 if (put_user(state_info, argp))
678 return -EFAULT;
679 break;
680
681 case VIAFB_GET_DRIVER_NAME:
682 if (copy_to_user(argp, driver_name, sizeof(driver_name)))
683 return -EFAULT;
684 break;
685
686 case VIAFB_SET_GAMMA_LUT:
687 viafb_gamma_table = kmalloc(256 * sizeof(u32), GFP_KERNEL);
688 if (!viafb_gamma_table)
689 return -ENOMEM;
690 if (copy_from_user(viafb_gamma_table, argp,
691 sizeof(viafb_gamma_table))) {
692 kfree(viafb_gamma_table);
693 return -EFAULT;
694 }
695 viafb_set_gamma_table(viafb_bpp, viafb_gamma_table);
696 kfree(viafb_gamma_table);
697 break;
698
699 case VIAFB_GET_GAMMA_LUT:
700 viafb_gamma_table = kmalloc(256 * sizeof(u32), GFP_KERNEL);
701 if (!viafb_gamma_table)
702 return -ENOMEM;
703 viafb_get_gamma_table(viafb_gamma_table);
704 if (copy_to_user(argp, viafb_gamma_table,
705 sizeof(viafb_gamma_table))) {
706 kfree(viafb_gamma_table);
707 return -EFAULT;
708 }
709 kfree(viafb_gamma_table);
710 break;
711
712 case VIAFB_GET_GAMMA_SUPPORT_STATE:
713 viafb_get_gamma_support_state(viafb_bpp, &state_info);
714 if (put_user(state_info, argp))
715 return -EFAULT;
716 break;
Joseph Chan29b619f2008-10-15 22:03:27 -0700717 case VIAFB_SYNC_SURFACE:
718 DEBUG_MSG(KERN_INFO "lobo VIAFB_SYNC_SURFACE\n");
719 break;
720 case VIAFB_GET_DRIVER_CAPS:
721 break;
722
723 case VIAFB_GET_PANEL_MAX_SIZE:
Bruno Prémonte687d692009-01-04 13:11:54 -0800724 if (copy_from_user(&u.panel_pos_size_para, argp,
725 sizeof(u.panel_pos_size_para)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700726 return -EFAULT;
Bruno Prémonte687d692009-01-04 13:11:54 -0800727 u.panel_pos_size_para.x = u.panel_pos_size_para.y = 0;
728 if (copy_to_user(argp, &u.panel_pos_size_para,
729 sizeof(u.panel_pos_size_para)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700730 return -EFAULT;
731 break;
732 case VIAFB_GET_PANEL_MAX_POSITION:
Bruno Prémonte687d692009-01-04 13:11:54 -0800733 if (copy_from_user(&u.panel_pos_size_para, argp,
734 sizeof(u.panel_pos_size_para)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700735 return -EFAULT;
Bruno Prémonte687d692009-01-04 13:11:54 -0800736 u.panel_pos_size_para.x = u.panel_pos_size_para.y = 0;
737 if (copy_to_user(argp, &u.panel_pos_size_para,
738 sizeof(u.panel_pos_size_para)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700739 return -EFAULT;
740 break;
741
742 case VIAFB_GET_PANEL_POSITION:
Bruno Prémonte687d692009-01-04 13:11:54 -0800743 if (copy_from_user(&u.panel_pos_size_para, argp,
744 sizeof(u.panel_pos_size_para)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700745 return -EFAULT;
Bruno Prémonte687d692009-01-04 13:11:54 -0800746 u.panel_pos_size_para.x = u.panel_pos_size_para.y = 0;
747 if (copy_to_user(argp, &u.panel_pos_size_para,
748 sizeof(u.panel_pos_size_para)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700749 return -EFAULT;
750 break;
751 case VIAFB_GET_PANEL_SIZE:
Bruno Prémonte687d692009-01-04 13:11:54 -0800752 if (copy_from_user(&u.panel_pos_size_para, argp,
753 sizeof(u.panel_pos_size_para)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700754 return -EFAULT;
Bruno Prémonte687d692009-01-04 13:11:54 -0800755 u.panel_pos_size_para.x = u.panel_pos_size_para.y = 0;
756 if (copy_to_user(argp, &u.panel_pos_size_para,
757 sizeof(u.panel_pos_size_para)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700758 return -EFAULT;
759 break;
760
761 case VIAFB_SET_PANEL_POSITION:
Bruno Prémonte687d692009-01-04 13:11:54 -0800762 if (copy_from_user(&u.panel_pos_size_para, argp,
763 sizeof(u.panel_pos_size_para)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700764 return -EFAULT;
765 break;
766 case VIAFB_SET_PANEL_SIZE:
Bruno Prémonte687d692009-01-04 13:11:54 -0800767 if (copy_from_user(&u.panel_pos_size_para, argp,
768 sizeof(u.panel_pos_size_para)))
Joseph Chan29b619f2008-10-15 22:03:27 -0700769 return -EFAULT;
770 break;
771
772 default:
773 return -EINVAL;
774 }
775
776 return 0;
777}
778
779static void viafb_fillrect(struct fb_info *info,
780 const struct fb_fillrect *rect)
781{
782 u32 col = 0, rop = 0;
783 int pitch;
784
Hannes Eder2899bb02009-01-06 14:42:32 -0800785 if (!viafb_accel) {
786 cfb_fillrect(info, rect);
787 return;
788 }
Joseph Chan29b619f2008-10-15 22:03:27 -0700789
790 if (!rect->width || !rect->height)
791 return;
792
793 switch (rect->rop) {
794 case ROP_XOR:
795 rop = 0x5A;
796 break;
797 case ROP_COPY:
798 default:
799 rop = 0xF0;
800 break;
801 }
802
803 switch (info->var.bits_per_pixel) {
804 case 8:
805 col = rect->color;
806 break;
807 case 16:
808 col = ((u32 *) (info->pseudo_palette))[rect->color];
809 break;
810 case 32:
811 col = ((u32 *) (info->pseudo_palette))[rect->color];
812 break;
813 }
814
815 /* BitBlt Source Address */
Joseph Chanb3a45d82008-10-15 22:03:29 -0700816 writel(0x0, viaparinfo->io_virt + VIA_REG_SRCPOS);
Joseph Chan29b619f2008-10-15 22:03:27 -0700817 /* Source Base Address */
Joseph Chanb3a45d82008-10-15 22:03:29 -0700818 writel(0x0, viaparinfo->io_virt + VIA_REG_SRCBASE);
Joseph Chan29b619f2008-10-15 22:03:27 -0700819 /* Destination Base Address */
Florian Tobias Schandinatdb88e382009-09-22 16:47:20 -0700820 writel((info->fix.smem_start - viafbinfo->fix.smem_start) >> 3,
Joseph Chanb3a45d82008-10-15 22:03:29 -0700821 viaparinfo->io_virt + VIA_REG_DSTBASE);
Joseph Chan29b619f2008-10-15 22:03:27 -0700822 /* Pitch */
823 pitch = (info->var.xres_virtual + 7) & ~7;
Joseph Chanb3a45d82008-10-15 22:03:29 -0700824 writel(VIA_PITCH_ENABLE |
Joseph Chan29b619f2008-10-15 22:03:27 -0700825 (((pitch *
826 info->var.bits_per_pixel >> 3) >> 3) |
827 (((pitch * info->
Joseph Chanb3a45d82008-10-15 22:03:29 -0700828 var.bits_per_pixel >> 3) >> 3) << 16)),
829 viaparinfo->io_virt + VIA_REG_PITCH);
Joseph Chan29b619f2008-10-15 22:03:27 -0700830 /* BitBlt Destination Address */
Joseph Chanb3a45d82008-10-15 22:03:29 -0700831 writel(((rect->dy << 16) | rect->dx),
832 viaparinfo->io_virt + VIA_REG_DSTPOS);
Joseph Chan29b619f2008-10-15 22:03:27 -0700833 /* Dimension: width & height */
Joseph Chanb3a45d82008-10-15 22:03:29 -0700834 writel((((rect->height - 1) << 16) | (rect->width - 1)),
835 viaparinfo->io_virt + VIA_REG_DIMENSION);
Joseph Chan29b619f2008-10-15 22:03:27 -0700836 /* Forground color or Destination color */
Joseph Chanb3a45d82008-10-15 22:03:29 -0700837 writel(col, viaparinfo->io_virt + VIA_REG_FGCOLOR);
Joseph Chan29b619f2008-10-15 22:03:27 -0700838 /* GE Command */
Joseph Chanb3a45d82008-10-15 22:03:29 -0700839 writel((0x01 | 0x2000 | (rop << 24)),
840 viaparinfo->io_virt + VIA_REG_GECMD);
Joseph Chan29b619f2008-10-15 22:03:27 -0700841
842}
843
844static void viafb_copyarea(struct fb_info *info,
845 const struct fb_copyarea *area)
846{
847 u32 dy = area->dy, sy = area->sy, direction = 0x0;
848 u32 sx = area->sx, dx = area->dx, width = area->width;
849 int pitch;
850
851 DEBUG_MSG(KERN_INFO "viafb_copyarea!!\n");
852
Hannes Eder2899bb02009-01-06 14:42:32 -0800853 if (!viafb_accel) {
854 cfb_copyarea(info, area);
855 return;
856 }
Joseph Chan29b619f2008-10-15 22:03:27 -0700857
858 if (!area->width || !area->height)
859 return;
860
861 if (sy < dy) {
862 dy += area->height - 1;
863 sy += area->height - 1;
864 direction |= 0x4000;
865 }
866
867 if (sx < dx) {
868 dx += width - 1;
869 sx += width - 1;
870 direction |= 0x8000;
871 }
872
873 /* Source Base Address */
Florian Tobias Schandinatdb88e382009-09-22 16:47:20 -0700874 writel((info->fix.smem_start - viafbinfo->fix.smem_start) >> 3,
Joseph Chanb3a45d82008-10-15 22:03:29 -0700875 viaparinfo->io_virt + VIA_REG_SRCBASE);
Joseph Chan29b619f2008-10-15 22:03:27 -0700876 /* Destination Base Address */
Florian Tobias Schandinatdb88e382009-09-22 16:47:20 -0700877 writel((info->fix.smem_start - viafbinfo->fix.smem_start) >> 3,
Joseph Chanb3a45d82008-10-15 22:03:29 -0700878 viaparinfo->io_virt + VIA_REG_DSTBASE);
Joseph Chan29b619f2008-10-15 22:03:27 -0700879 /* Pitch */
880 pitch = (info->var.xres_virtual + 7) & ~7;
881 /* VIA_PITCH_ENABLE can be omitted now. */
Joseph Chanb3a45d82008-10-15 22:03:29 -0700882 writel(VIA_PITCH_ENABLE |
Joseph Chan29b619f2008-10-15 22:03:27 -0700883 (((pitch *
884 info->var.bits_per_pixel >> 3) >> 3) | (((pitch *
885 info->var.
886 bits_per_pixel
887 >> 3) >> 3)
Joseph Chanb3a45d82008-10-15 22:03:29 -0700888 << 16)),
889 viaparinfo->io_virt + VIA_REG_PITCH);
Joseph Chan29b619f2008-10-15 22:03:27 -0700890 /* BitBlt Source Address */
Joseph Chanb3a45d82008-10-15 22:03:29 -0700891 writel(((sy << 16) | sx), viaparinfo->io_virt + VIA_REG_SRCPOS);
Joseph Chan29b619f2008-10-15 22:03:27 -0700892 /* BitBlt Destination Address */
Joseph Chanb3a45d82008-10-15 22:03:29 -0700893 writel(((dy << 16) | dx), viaparinfo->io_virt + VIA_REG_DSTPOS);
Joseph Chan29b619f2008-10-15 22:03:27 -0700894 /* Dimension: width & height */
Joseph Chanb3a45d82008-10-15 22:03:29 -0700895 writel((((area->height - 1) << 16) | (area->width - 1)),
896 viaparinfo->io_virt + VIA_REG_DIMENSION);
Joseph Chan29b619f2008-10-15 22:03:27 -0700897 /* GE Command */
Joseph Chanb3a45d82008-10-15 22:03:29 -0700898 writel((0x01 | direction | (0xCC << 24)),
899 viaparinfo->io_virt + VIA_REG_GECMD);
Joseph Chan29b619f2008-10-15 22:03:27 -0700900
901}
902
903static void viafb_imageblit(struct fb_info *info,
904 const struct fb_image *image)
905{
906 u32 size, bg_col = 0, fg_col = 0, *udata;
907 int i;
908 int pitch;
909
Hannes Eder2899bb02009-01-06 14:42:32 -0800910 if (!viafb_accel) {
911 cfb_imageblit(info, image);
912 return;
913 }
Joseph Chan29b619f2008-10-15 22:03:27 -0700914
915 udata = (u32 *) image->data;
916
917 switch (info->var.bits_per_pixel) {
918 case 8:
919 bg_col = image->bg_color;
920 fg_col = image->fg_color;
921 break;
922 case 16:
923 bg_col = ((u32 *) (info->pseudo_palette))[image->bg_color];
924 fg_col = ((u32 *) (info->pseudo_palette))[image->fg_color];
925 break;
926 case 32:
927 bg_col = ((u32 *) (info->pseudo_palette))[image->bg_color];
928 fg_col = ((u32 *) (info->pseudo_palette))[image->fg_color];
929 break;
930 }
931 size = image->width * image->height;
932
933 /* Source Base Address */
Joseph Chanb3a45d82008-10-15 22:03:29 -0700934 writel(0x0, viaparinfo->io_virt + VIA_REG_SRCBASE);
Joseph Chan29b619f2008-10-15 22:03:27 -0700935 /* Destination Base Address */
Florian Tobias Schandinatdb88e382009-09-22 16:47:20 -0700936 writel((info->fix.smem_start - viafbinfo->fix.smem_start) >> 3,
Joseph Chanb3a45d82008-10-15 22:03:29 -0700937 viaparinfo->io_virt + VIA_REG_DSTBASE);
Joseph Chan29b619f2008-10-15 22:03:27 -0700938 /* Pitch */
939 pitch = (info->var.xres_virtual + 7) & ~7;
Joseph Chanb3a45d82008-10-15 22:03:29 -0700940 writel(VIA_PITCH_ENABLE |
Joseph Chan29b619f2008-10-15 22:03:27 -0700941 (((pitch *
942 info->var.bits_per_pixel >> 3) >> 3) | (((pitch *
943 info->var.
944 bits_per_pixel
945 >> 3) >> 3)
Joseph Chanb3a45d82008-10-15 22:03:29 -0700946 << 16)),
947 viaparinfo->io_virt + VIA_REG_PITCH);
Joseph Chan29b619f2008-10-15 22:03:27 -0700948 /* BitBlt Source Address */
Joseph Chanb3a45d82008-10-15 22:03:29 -0700949 writel(0x0, viaparinfo->io_virt + VIA_REG_SRCPOS);
Joseph Chan29b619f2008-10-15 22:03:27 -0700950 /* BitBlt Destination Address */
Joseph Chanb3a45d82008-10-15 22:03:29 -0700951 writel(((image->dy << 16) | image->dx),
952 viaparinfo->io_virt + VIA_REG_DSTPOS);
Joseph Chan29b619f2008-10-15 22:03:27 -0700953 /* Dimension: width & height */
Joseph Chanb3a45d82008-10-15 22:03:29 -0700954 writel((((image->height - 1) << 16) | (image->width - 1)),
955 viaparinfo->io_virt + VIA_REG_DIMENSION);
Joseph Chan29b619f2008-10-15 22:03:27 -0700956 /* fb color */
Joseph Chanb3a45d82008-10-15 22:03:29 -0700957 writel(fg_col, viaparinfo->io_virt + VIA_REG_FGCOLOR);
Joseph Chan29b619f2008-10-15 22:03:27 -0700958 /* bg color */
Joseph Chanb3a45d82008-10-15 22:03:29 -0700959 writel(bg_col, viaparinfo->io_virt + VIA_REG_BGCOLOR);
Joseph Chan29b619f2008-10-15 22:03:27 -0700960 /* GE Command */
Joseph Chanb3a45d82008-10-15 22:03:29 -0700961 writel(0xCC020142, viaparinfo->io_virt + VIA_REG_GECMD);
Joseph Chan29b619f2008-10-15 22:03:27 -0700962
963 for (i = 0; i < size / 4; i++) {
Joseph Chanb3a45d82008-10-15 22:03:29 -0700964 writel(*udata, viaparinfo->io_virt + VIA_MMIO_BLTBASE);
Joseph Chan29b619f2008-10-15 22:03:27 -0700965 udata++;
966 }
967
968}
969
970static int viafb_cursor(struct fb_info *info, struct fb_cursor *cursor)
971{
Joseph Chan29b619f2008-10-15 22:03:27 -0700972 u32 temp, xx, yy, bg_col = 0, fg_col = 0;
Bruno Prémonte687d692009-01-04 13:11:54 -0800973 int i, j = 0;
Joseph Chan29b619f2008-10-15 22:03:27 -0700974 static int hw_cursor;
975 struct viafb_par *p_viafb_par;
976
977 if (viafb_accel)
978 hw_cursor = 1;
979
980 if (!viafb_accel) {
981 if (hw_cursor) {
982 viafb_show_hw_cursor(info, HW_Cursor_OFF);
983 hw_cursor = 0;
984 }
985 return -ENODEV;
986 }
987
988 if ((((struct viafb_par *)(info->par))->iga_path == IGA2)
989 && (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266))
990 return -ENODEV;
991
992 /* When duoview and using lcd , use soft cursor */
Florian Tobias Schandinatb008c64b2009-09-22 16:47:18 -0700993 if (viafb_LCD_ON || (!viafb_SAMM_ON &&
994 viafb_LCD2_ON + viafb_DVI_ON + viafb_CRT_ON == 2))
Joseph Chan29b619f2008-10-15 22:03:27 -0700995 return -ENODEV;
996
997 viafb_show_hw_cursor(info, HW_Cursor_OFF);
998 viacursor = *cursor;
999
1000 if (cursor->set & FB_CUR_SETHOT) {
1001 viacursor.hot = cursor->hot;
1002 temp = ((viacursor.hot.x) << 16) + viacursor.hot.y;
Joseph Chanb3a45d82008-10-15 22:03:29 -07001003 writel(temp, viaparinfo->io_virt + VIA_REG_CURSOR_ORG);
Joseph Chan29b619f2008-10-15 22:03:27 -07001004 }
1005
1006 if (cursor->set & FB_CUR_SETPOS) {
1007 viacursor.image.dx = cursor->image.dx;
1008 viacursor.image.dy = cursor->image.dy;
1009 yy = cursor->image.dy - info->var.yoffset;
1010 xx = cursor->image.dx - info->var.xoffset;
1011 temp = yy & 0xFFFF;
1012 temp |= (xx << 16);
Joseph Chanb3a45d82008-10-15 22:03:29 -07001013 writel(temp, viaparinfo->io_virt + VIA_REG_CURSOR_POS);
Joseph Chan29b619f2008-10-15 22:03:27 -07001014 }
1015
1016 if (cursor->set & FB_CUR_SETSIZE) {
Joseph Chanb3a45d82008-10-15 22:03:29 -07001017 temp = readl(viaparinfo->io_virt + VIA_REG_CURSOR_MODE);
Joseph Chan29b619f2008-10-15 22:03:27 -07001018
1019 if ((cursor->image.width <= 32)
1020 && (cursor->image.height <= 32)) {
1021 MAX_CURS = 32;
1022 temp |= 0x2;
1023 } else if ((cursor->image.width <= 64)
1024 && (cursor->image.height <= 64)) {
1025 MAX_CURS = 64;
1026 temp &= 0xFFFFFFFD;
1027 } else {
1028 DEBUG_MSG(KERN_INFO
1029 "The cursor image is biger than 64x64 bits...\n");
1030 return -ENXIO;
1031 }
Joseph Chanb3a45d82008-10-15 22:03:29 -07001032 writel(temp, viaparinfo->io_virt + VIA_REG_CURSOR_MODE);
Joseph Chan29b619f2008-10-15 22:03:27 -07001033
1034 viacursor.image.height = cursor->image.height;
1035 viacursor.image.width = cursor->image.width;
1036 }
1037
1038 if (cursor->set & FB_CUR_SETCMAP) {
1039 viacursor.image.fg_color = cursor->image.fg_color;
1040 viacursor.image.bg_color = cursor->image.bg_color;
1041
1042 switch (info->var.bits_per_pixel) {
1043 case 8:
1044 case 16:
1045 case 32:
1046 bg_col =
1047 (0xFF << 24) |
1048 (((info->cmap.red)[viacursor.image.bg_color] &
1049 0xFF00) << 8) |
1050 ((info->cmap.green)[viacursor.image.bg_color] &
1051 0xFF00) |
1052 (((info->cmap.blue)[viacursor.image.bg_color] &
1053 0xFF00) >> 8);
1054 fg_col =
1055 (0xFF << 24) |
1056 (((info->cmap.red)[viacursor.image.fg_color] &
1057 0xFF00) << 8) |
1058 ((info->cmap.green)[viacursor.image.fg_color] &
1059 0xFF00) |
1060 (((info->cmap.blue)[viacursor.image.fg_color] &
1061 0xFF00) >> 8);
1062 break;
1063 default:
1064 return 0;
1065 }
1066
1067 /* This is indeed a patch for VT3324/VT3353 */
1068 if (!info->par)
1069 return 0;
1070 p_viafb_par = (struct viafb_par *)info->par;
1071
1072 if ((p_viafb_par->chip_info->gfx_chip_name ==
1073 UNICHROME_CX700) ||
1074 ((p_viafb_par->chip_info->gfx_chip_name ==
1075 UNICHROME_VX800))) {
1076 bg_col =
1077 (((info->cmap.red)[viacursor.image.bg_color] &
1078 0xFFC0) << 14) |
1079 (((info->cmap.green)[viacursor.image.bg_color] &
1080 0xFFC0) << 4) |
1081 (((info->cmap.blue)[viacursor.image.bg_color] &
1082 0xFFC0) >> 6);
1083 fg_col =
1084 (((info->cmap.red)[viacursor.image.fg_color] &
1085 0xFFC0) << 14) |
1086 (((info->cmap.green)[viacursor.image.fg_color] &
1087 0xFFC0) << 4) |
1088 (((info->cmap.blue)[viacursor.image.fg_color] &
1089 0xFFC0) >> 6);
1090 }
1091
Joseph Chanb3a45d82008-10-15 22:03:29 -07001092 writel(bg_col, viaparinfo->io_virt + VIA_REG_CURSOR_BG);
1093 writel(fg_col, viaparinfo->io_virt + VIA_REG_CURSOR_FG);
Joseph Chan29b619f2008-10-15 22:03:27 -07001094 }
1095
1096 if (cursor->set & FB_CUR_SETSHAPE) {
Bruno Prémonte687d692009-01-04 13:11:54 -08001097 struct {
1098 u8 data[CURSOR_SIZE / 8];
1099 u32 bak[CURSOR_SIZE / 32];
1100 } *cr_data = kzalloc(sizeof(*cr_data), GFP_ATOMIC);
1101 int size =
Joseph Chan29b619f2008-10-15 22:03:27 -07001102 ((viacursor.image.width + 7) >> 3) *
1103 viacursor.image.height;
1104
Bruno Prémonte687d692009-01-04 13:11:54 -08001105 if (cr_data == NULL)
1106 goto out;
1107
Joseph Chan29b619f2008-10-15 22:03:27 -07001108 if (MAX_CURS == 32) {
1109 for (i = 0; i < (CURSOR_SIZE / 32); i++) {
Bruno Prémonte687d692009-01-04 13:11:54 -08001110 cr_data->bak[i] = 0x0;
1111 cr_data->bak[i + 1] = 0xFFFFFFFF;
Joseph Chan29b619f2008-10-15 22:03:27 -07001112 i += 1;
1113 }
1114 } else if (MAX_CURS == 64) {
1115 for (i = 0; i < (CURSOR_SIZE / 32); i++) {
Bruno Prémonte687d692009-01-04 13:11:54 -08001116 cr_data->bak[i] = 0x0;
1117 cr_data->bak[i + 1] = 0x0;
1118 cr_data->bak[i + 2] = 0xFFFFFFFF;
1119 cr_data->bak[i + 3] = 0xFFFFFFFF;
Joseph Chan29b619f2008-10-15 22:03:27 -07001120 i += 3;
1121 }
1122 }
1123
1124 switch (viacursor.rop) {
1125 case ROP_XOR:
1126 for (i = 0; i < size; i++)
Bruno Prémonte687d692009-01-04 13:11:54 -08001127 cr_data->data[i] = viacursor.mask[i];
Joseph Chan29b619f2008-10-15 22:03:27 -07001128 break;
1129 case ROP_COPY:
1130
1131 for (i = 0; i < size; i++)
Bruno Prémonte687d692009-01-04 13:11:54 -08001132 cr_data->data[i] = viacursor.mask[i];
Joseph Chan29b619f2008-10-15 22:03:27 -07001133 break;
1134 default:
1135 break;
1136 }
1137
1138 if (MAX_CURS == 32) {
1139 for (i = 0; i < size; i++) {
Bruno Prémonte687d692009-01-04 13:11:54 -08001140 cr_data->bak[j] = (u32) cr_data->data[i];
1141 cr_data->bak[j + 1] = ~cr_data->bak[j];
Joseph Chan29b619f2008-10-15 22:03:27 -07001142 j += 2;
1143 }
1144 } else if (MAX_CURS == 64) {
1145 for (i = 0; i < size; i++) {
Bruno Prémonte687d692009-01-04 13:11:54 -08001146 cr_data->bak[j] = (u32) cr_data->data[i];
1147 cr_data->bak[j + 1] = 0x0;
1148 cr_data->bak[j + 2] = ~cr_data->bak[j];
1149 cr_data->bak[j + 3] = ~cr_data->bak[j + 1];
Joseph Chan29b619f2008-10-15 22:03:27 -07001150 j += 4;
1151 }
1152 }
1153
Florian Tobias Schandinatdb88e382009-09-22 16:47:20 -07001154 memcpy(viafbinfo->screen_base +
Joseph Chan29b619f2008-10-15 22:03:27 -07001155 ((struct viafb_par *)(info->par))->cursor_start,
Bruno Prémonte687d692009-01-04 13:11:54 -08001156 cr_data->bak, CURSOR_SIZE);
1157out:
1158 kfree(cr_data);
Joseph Chan29b619f2008-10-15 22:03:27 -07001159 }
1160
1161 if (viacursor.enable)
1162 viafb_show_hw_cursor(info, HW_Cursor_ON);
1163
1164 return 0;
1165}
1166
1167static int viafb_sync(struct fb_info *info)
1168{
1169 if (viafb_accel)
1170 viafb_wait_engine_idle();
1171 return 0;
1172}
1173
Florian Tobias Schandinat52159442009-08-06 15:07:34 -07001174int viafb_get_mode_index(int hres, int vres)
Joseph Chan29b619f2008-10-15 22:03:27 -07001175{
1176 u32 i;
1177 DEBUG_MSG(KERN_INFO "viafb_get_mode_index!\n");
1178
Florian Tobias Schandinat13147f22009-09-22 16:47:17 -07001179 for (i = 0; i < NUM_TOTAL_MODETABLE; i++)
1180 if (CLE266Modes[i].mode_array &&
1181 CLE266Modes[i].crtc[0].crtc.hor_addr == hres &&
1182 CLE266Modes[i].crtc[0].crtc.ver_addr == vres)
Joseph Chan29b619f2008-10-15 22:03:27 -07001183 break;
1184
Florian Tobias Schandinat13147f22009-09-22 16:47:17 -07001185 if (i == NUM_TOTAL_MODETABLE)
1186 return VIA_RES_INVALID;
1187
1188 return CLE266Modes[i].ModeIndex;
Joseph Chan29b619f2008-10-15 22:03:27 -07001189}
1190
1191static void check_available_device_to_enable(int device_id)
1192{
1193 int device_num = 0;
1194
1195 /* Initialize: */
1196 viafb_CRT_ON = STATE_OFF;
1197 viafb_DVI_ON = STATE_OFF;
1198 viafb_LCD_ON = STATE_OFF;
1199 viafb_LCD2_ON = STATE_OFF;
1200 viafb_DeviceStatus = None_Device;
1201
1202 if ((device_id & CRT_Device) && (device_num < MAX_ACTIVE_DEV_NUM)) {
1203 viafb_CRT_ON = STATE_ON;
1204 device_num++;
1205 viafb_DeviceStatus |= CRT_Device;
1206 }
1207
1208 if ((device_id & DVI_Device) && (device_num < MAX_ACTIVE_DEV_NUM)) {
1209 viafb_DVI_ON = STATE_ON;
1210 device_num++;
1211 viafb_DeviceStatus |= DVI_Device;
1212 }
1213
1214 if ((device_id & LCD_Device) && (device_num < MAX_ACTIVE_DEV_NUM)) {
1215 viafb_LCD_ON = STATE_ON;
1216 device_num++;
1217 viafb_DeviceStatus |= LCD_Device;
1218 }
1219
1220 if ((device_id & LCD2_Device) && (device_num < MAX_ACTIVE_DEV_NUM)) {
1221 viafb_LCD2_ON = STATE_ON;
1222 device_num++;
1223 viafb_DeviceStatus |= LCD2_Device;
1224 }
1225
1226 if (viafb_DeviceStatus == None_Device) {
1227 /* Use CRT as default active device: */
1228 viafb_CRT_ON = STATE_ON;
1229 viafb_DeviceStatus = CRT_Device;
1230 }
1231 DEBUG_MSG(KERN_INFO "Device Status:%x", viafb_DeviceStatus);
1232}
1233
1234static void viafb_set_device(struct device_t active_dev)
1235{
1236 /* Check available device to enable: */
1237 int device_id = None_Device;
1238 if (active_dev.crt)
1239 device_id |= CRT_Device;
1240 if (active_dev.dvi)
1241 device_id |= DVI_Device;
1242 if (active_dev.lcd)
1243 device_id |= LCD_Device;
1244
1245 check_available_device_to_enable(device_id);
1246
1247 /* Check property of LCD: */
1248 if (viafb_LCD_ON) {
1249 if (active_dev.lcd_dsp_cent) {
1250 viaparinfo->lvds_setting_info->display_method =
1251 viafb_lcd_dsp_method = LCD_CENTERING;
1252 } else {
1253 viaparinfo->lvds_setting_info->display_method =
1254 viafb_lcd_dsp_method = LCD_EXPANDSION;
1255 }
1256
1257 if (active_dev.lcd_mode == LCD_SPWG) {
1258 viaparinfo->lvds_setting_info->lcd_mode =
1259 viafb_lcd_mode = LCD_SPWG;
1260 } else {
1261 viaparinfo->lvds_setting_info->lcd_mode =
1262 viafb_lcd_mode = LCD_OPENLDI;
1263 }
1264
1265 if (active_dev.lcd_panel_id <= LCD_PANEL_ID_MAXIMUM) {
1266 viafb_lcd_panel_id = active_dev.lcd_panel_id;
1267 viafb_init_lcd_size();
1268 }
1269 }
1270
1271 /* Check property of mode: */
1272 if (!active_dev.xres1)
1273 viafb_second_xres = 640;
1274 else
1275 viafb_second_xres = active_dev.xres1;
1276 if (!active_dev.yres1)
1277 viafb_second_yres = 480;
1278 else
1279 viafb_second_yres = active_dev.yres1;
1280 if (active_dev.bpp != 0)
1281 viafb_bpp = active_dev.bpp;
1282 if (active_dev.bpp1 != 0)
1283 viafb_bpp1 = active_dev.bpp1;
1284 if (active_dev.refresh != 0)
1285 viafb_refresh = active_dev.refresh;
1286 if (active_dev.refresh1 != 0)
1287 viafb_refresh1 = active_dev.refresh1;
1288 if ((active_dev.samm == STATE_OFF) || (active_dev.samm == STATE_ON))
1289 viafb_SAMM_ON = active_dev.samm;
1290 viafb_primary_dev = active_dev.primary_dev;
1291
Florian Tobias Schandinat09cf1182009-09-22 16:47:14 -07001292 viafb_set_primary_address(0);
1293 viafb_set_secondary_address(viafb_SAMM_ON ? viafb_second_offset : 0);
Joseph Chan29b619f2008-10-15 22:03:27 -07001294 viafb_set_iga_path();
1295}
1296
Joseph Chan29b619f2008-10-15 22:03:27 -07001297static int get_primary_device(void)
1298{
1299 int primary_device = 0;
1300 /* Rule: device on iga1 path are the primary device. */
1301 if (viafb_SAMM_ON) {
1302 if (viafb_CRT_ON) {
1303 if (viaparinfo->crt_setting_info->iga_path == IGA1) {
1304 DEBUG_MSG(KERN_INFO "CRT IGA Path:%d\n",
1305 viaparinfo->
1306 crt_setting_info->iga_path);
1307 primary_device = CRT_Device;
1308 }
1309 }
1310 if (viafb_DVI_ON) {
1311 if (viaparinfo->tmds_setting_info->iga_path == IGA1) {
1312 DEBUG_MSG(KERN_INFO "DVI IGA Path:%d\n",
1313 viaparinfo->
1314 tmds_setting_info->iga_path);
1315 primary_device = DVI_Device;
1316 }
1317 }
1318 if (viafb_LCD_ON) {
1319 if (viaparinfo->lvds_setting_info->iga_path == IGA1) {
1320 DEBUG_MSG(KERN_INFO "LCD IGA Path:%d\n",
1321 viaparinfo->
1322 lvds_setting_info->iga_path);
1323 primary_device = LCD_Device;
1324 }
1325 }
1326 if (viafb_LCD2_ON) {
1327 if (viaparinfo->lvds_setting_info2->iga_path == IGA1) {
1328 DEBUG_MSG(KERN_INFO "LCD2 IGA Path:%d\n",
1329 viaparinfo->
1330 lvds_setting_info2->iga_path);
1331 primary_device = LCD2_Device;
1332 }
1333 }
1334 }
1335 return primary_device;
1336}
1337
Joseph Chan29b619f2008-10-15 22:03:27 -07001338static void apply_second_mode_setting(struct fb_var_screeninfo
1339 *sec_var)
1340{
1341 u32 htotal, vtotal, long_refresh;
1342
1343 htotal = sec_var->xres + sec_var->left_margin +
1344 sec_var->right_margin + sec_var->hsync_len;
1345 vtotal = sec_var->yres + sec_var->upper_margin +
1346 sec_var->lower_margin + sec_var->vsync_len;
1347 if ((sec_var->xres_virtual * (sec_var->bits_per_pixel >> 3)) & 0x1F) {
1348 /*Is 32 bytes alignment? */
1349 /*32 pixel alignment */
1350 sec_var->xres_virtual = (sec_var->xres_virtual + 31) & ~31;
1351 }
1352
1353 htotal = sec_var->xres + sec_var->left_margin +
1354 sec_var->right_margin + sec_var->hsync_len;
1355 vtotal = sec_var->yres + sec_var->upper_margin +
1356 sec_var->lower_margin + sec_var->vsync_len;
1357 long_refresh = 1000000000UL / sec_var->pixclock * 1000;
1358 long_refresh /= (htotal * vtotal);
1359
1360 viafb_second_xres = sec_var->xres;
1361 viafb_second_yres = sec_var->yres;
1362 viafb_second_virtual_xres = sec_var->xres_virtual;
1363 viafb_second_virtual_yres = sec_var->yres_virtual;
1364 viafb_bpp1 = sec_var->bits_per_pixel;
1365 viafb_refresh1 = viafb_get_refresh(sec_var->xres, sec_var->yres,
1366 long_refresh);
1367}
1368
1369static int apply_device_setting(struct viafb_ioctl_setting setting_info,
1370 struct fb_info *info)
1371{
1372 int need_set_mode = 0;
1373 DEBUG_MSG(KERN_INFO "apply_device_setting\n");
1374
1375 if (setting_info.device_flag) {
1376 need_set_mode = 1;
1377 check_available_device_to_enable(setting_info.device_status);
1378 }
1379
1380 /* Unlock LCD's operation according to LCD flag
1381 and check if the setting value is valid. */
1382 /* If the value is valid, apply the new setting value to the device. */
1383 if (viafb_LCD_ON) {
1384 if (setting_info.lcd_operation_flag & OP_LCD_CENTERING) {
1385 need_set_mode = 1;
1386 if (setting_info.lcd_attributes.display_center) {
1387 /* Centering */
1388 viaparinfo->lvds_setting_info->display_method =
1389 LCD_CENTERING;
1390 viafb_lcd_dsp_method = LCD_CENTERING;
1391 viaparinfo->lvds_setting_info2->display_method =
1392 viafb_lcd_dsp_method = LCD_CENTERING;
1393 } else {
1394 /* expandsion */
1395 viaparinfo->lvds_setting_info->display_method =
1396 LCD_EXPANDSION;
1397 viafb_lcd_dsp_method = LCD_EXPANDSION;
1398 viaparinfo->lvds_setting_info2->display_method =
1399 LCD_EXPANDSION;
1400 viafb_lcd_dsp_method = LCD_EXPANDSION;
1401 }
1402 }
1403
1404 if (setting_info.lcd_operation_flag & OP_LCD_MODE) {
1405 need_set_mode = 1;
1406 if (setting_info.lcd_attributes.lcd_mode ==
1407 LCD_SPWG) {
1408 viaparinfo->lvds_setting_info->lcd_mode =
1409 viafb_lcd_mode = LCD_SPWG;
1410 } else {
1411 viaparinfo->lvds_setting_info->lcd_mode =
1412 viafb_lcd_mode = LCD_OPENLDI;
1413 }
1414 viaparinfo->lvds_setting_info2->lcd_mode =
1415 viaparinfo->lvds_setting_info->lcd_mode;
1416 }
1417
1418 if (setting_info.lcd_operation_flag & OP_LCD_PANEL_ID) {
1419 need_set_mode = 1;
1420 if (setting_info.lcd_attributes.panel_id <=
1421 LCD_PANEL_ID_MAXIMUM) {
1422 viafb_lcd_panel_id =
1423 setting_info.lcd_attributes.panel_id;
1424 viafb_init_lcd_size();
1425 }
1426 }
1427 }
1428
1429 if (0 != (setting_info.samm_status & OP_SAMM)) {
1430 setting_info.samm_status =
1431 setting_info.samm_status & (~OP_SAMM);
1432 if (setting_info.samm_status == 0
1433 || setting_info.samm_status == 1) {
1434 viafb_SAMM_ON = setting_info.samm_status;
1435
1436 if (viafb_SAMM_ON)
1437 viafb_primary_dev = setting_info.primary_device;
1438
Florian Tobias Schandinat09cf1182009-09-22 16:47:14 -07001439 viafb_set_primary_address(0);
1440 viafb_set_secondary_address(viafb_SAMM_ON ? viafb_second_offset : 0);
Joseph Chan29b619f2008-10-15 22:03:27 -07001441 viafb_set_iga_path();
1442 }
1443 need_set_mode = 1;
1444 }
1445
Joseph Chan29b619f2008-10-15 22:03:27 -07001446 if (!need_set_mode) {
1447 ;
1448 } else {
1449 viafb_set_iga_path();
1450 viafb_set_par(info);
1451 }
1452 return true;
1453}
1454
1455static void retrieve_device_setting(struct viafb_ioctl_setting
1456 *setting_info)
1457{
1458
1459 /* get device status */
1460 if (viafb_CRT_ON == 1)
1461 setting_info->device_status = CRT_Device;
1462 if (viafb_DVI_ON == 1)
1463 setting_info->device_status |= DVI_Device;
1464 if (viafb_LCD_ON == 1)
1465 setting_info->device_status |= LCD_Device;
1466 if (viafb_LCD2_ON == 1)
1467 setting_info->device_status |= LCD2_Device;
Joseph Chan29b619f2008-10-15 22:03:27 -07001468
1469 setting_info->samm_status = viafb_SAMM_ON;
1470 setting_info->primary_device = get_primary_device();
1471
1472 setting_info->first_dev_bpp = viafb_bpp;
1473 setting_info->second_dev_bpp = viafb_bpp1;
1474
1475 setting_info->first_dev_refresh = viafb_refresh;
1476 setting_info->second_dev_refresh = viafb_refresh1;
1477
1478 setting_info->first_dev_hor_res = viafb_hotplug_Xres;
1479 setting_info->first_dev_ver_res = viafb_hotplug_Yres;
1480 setting_info->second_dev_hor_res = viafb_second_xres;
1481 setting_info->second_dev_ver_res = viafb_second_yres;
1482
1483 /* Get lcd attributes */
1484 setting_info->lcd_attributes.display_center = viafb_lcd_dsp_method;
1485 setting_info->lcd_attributes.panel_id = viafb_lcd_panel_id;
1486 setting_info->lcd_attributes.lcd_mode = viafb_lcd_mode;
1487}
1488
1489static void parse_active_dev(void)
1490{
1491 viafb_CRT_ON = STATE_OFF;
1492 viafb_DVI_ON = STATE_OFF;
1493 viafb_LCD_ON = STATE_OFF;
1494 viafb_LCD2_ON = STATE_OFF;
1495 /* 1. Modify the active status of devices. */
1496 /* 2. Keep the order of devices, so we can set corresponding
1497 IGA path to devices in SAMM case. */
1498 /* Note: The previous of active_dev is primary device,
1499 and the following is secondary device. */
1500 if (!strncmp(viafb_active_dev, "CRT+DVI", 7)) {
1501 /* CRT+DVI */
1502 viafb_CRT_ON = STATE_ON;
1503 viafb_DVI_ON = STATE_ON;
1504 viafb_primary_dev = CRT_Device;
1505 } else if (!strncmp(viafb_active_dev, "DVI+CRT", 7)) {
1506 /* DVI+CRT */
1507 viafb_CRT_ON = STATE_ON;
1508 viafb_DVI_ON = STATE_ON;
1509 viafb_primary_dev = DVI_Device;
1510 } else if (!strncmp(viafb_active_dev, "CRT+LCD", 7)) {
1511 /* CRT+LCD */
1512 viafb_CRT_ON = STATE_ON;
1513 viafb_LCD_ON = STATE_ON;
1514 viafb_primary_dev = CRT_Device;
1515 } else if (!strncmp(viafb_active_dev, "LCD+CRT", 7)) {
1516 /* LCD+CRT */
1517 viafb_CRT_ON = STATE_ON;
1518 viafb_LCD_ON = STATE_ON;
1519 viafb_primary_dev = LCD_Device;
1520 } else if (!strncmp(viafb_active_dev, "DVI+LCD", 7)) {
1521 /* DVI+LCD */
1522 viafb_DVI_ON = STATE_ON;
1523 viafb_LCD_ON = STATE_ON;
1524 viafb_primary_dev = DVI_Device;
1525 } else if (!strncmp(viafb_active_dev, "LCD+DVI", 7)) {
1526 /* LCD+DVI */
1527 viafb_DVI_ON = STATE_ON;
1528 viafb_LCD_ON = STATE_ON;
1529 viafb_primary_dev = LCD_Device;
1530 } else if (!strncmp(viafb_active_dev, "LCD+LCD2", 8)) {
1531 viafb_LCD_ON = STATE_ON;
1532 viafb_LCD2_ON = STATE_ON;
1533 viafb_primary_dev = LCD_Device;
1534 } else if (!strncmp(viafb_active_dev, "LCD2+LCD", 8)) {
1535 viafb_LCD_ON = STATE_ON;
1536 viafb_LCD2_ON = STATE_ON;
1537 viafb_primary_dev = LCD2_Device;
1538 } else if (!strncmp(viafb_active_dev, "CRT", 3)) {
1539 /* CRT only */
1540 viafb_CRT_ON = STATE_ON;
1541 viafb_SAMM_ON = STATE_OFF;
1542 } else if (!strncmp(viafb_active_dev, "DVI", 3)) {
1543 /* DVI only */
1544 viafb_DVI_ON = STATE_ON;
1545 viafb_SAMM_ON = STATE_OFF;
1546 } else if (!strncmp(viafb_active_dev, "LCD", 3)) {
1547 /* LCD only */
1548 viafb_LCD_ON = STATE_ON;
1549 viafb_SAMM_ON = STATE_OFF;
1550 } else {
1551 viafb_CRT_ON = STATE_ON;
1552 viafb_SAMM_ON = STATE_OFF;
1553 }
Joseph Chan29b619f2008-10-15 22:03:27 -07001554}
1555
Joseph Chan29b619f2008-10-15 22:03:27 -07001556static int parse_port(char *opt_str, int *output_interface)
1557{
1558 if (!strncmp(opt_str, "DVP0", 4))
1559 *output_interface = INTERFACE_DVP0;
1560 else if (!strncmp(opt_str, "DVP1", 4))
1561 *output_interface = INTERFACE_DVP1;
1562 else if (!strncmp(opt_str, "DFP_HIGHLOW", 11))
1563 *output_interface = INTERFACE_DFP;
1564 else if (!strncmp(opt_str, "DFP_HIGH", 8))
1565 *output_interface = INTERFACE_DFP_HIGH;
1566 else if (!strncmp(opt_str, "DFP_LOW", 7))
1567 *output_interface = INTERFACE_DFP_LOW;
1568 else
1569 *output_interface = INTERFACE_NONE;
1570 return 0;
1571}
1572
1573static void parse_lcd_port(void)
1574{
1575 parse_port(viafb_lcd_port, &viaparinfo->chip_info->lvds_chip_info.
1576 output_interface);
1577 /*Initialize to avoid unexpected behavior */
1578 viaparinfo->chip_info->lvds_chip_info2.output_interface =
1579 INTERFACE_NONE;
1580
1581 DEBUG_MSG(KERN_INFO "parse_lcd_port: viafb_lcd_port:%s,interface:%d\n",
1582 viafb_lcd_port, viaparinfo->chip_info->lvds_chip_info.
1583 output_interface);
1584}
1585
1586static void parse_dvi_port(void)
1587{
1588 parse_port(viafb_dvi_port, &viaparinfo->chip_info->tmds_chip_info.
1589 output_interface);
1590
1591 DEBUG_MSG(KERN_INFO "parse_dvi_port: viafb_dvi_port:%s,interface:%d\n",
1592 viafb_dvi_port, viaparinfo->chip_info->tmds_chip_info.
1593 output_interface);
1594}
1595
1596/*
1597 * The proc filesystem read/write function, a simple proc implement to
1598 * get/set the value of DPA DVP0, DVP0DataDriving, DVP0ClockDriving, DVP1,
1599 * DVP1Driving, DFPHigh, DFPLow CR96, SR2A[5], SR1B[1], SR2A[4], SR1E[2],
1600 * CR9B, SR65, CR97, CR99
1601 */
1602static int viafb_dvp0_proc_read(char *buf, char **start, off_t offset,
1603int count, int *eof, void *data)
1604{
1605 int len = 0;
1606 u8 dvp0_data_dri = 0, dvp0_clk_dri = 0, dvp0 = 0;
1607 dvp0_data_dri =
1608 (viafb_read_reg(VIASR, SR2A) & BIT5) >> 4 |
1609 (viafb_read_reg(VIASR, SR1B) & BIT1) >> 1;
1610 dvp0_clk_dri =
1611 (viafb_read_reg(VIASR, SR2A) & BIT4) >> 3 |
1612 (viafb_read_reg(VIASR, SR1E) & BIT2) >> 2;
1613 dvp0 = viafb_read_reg(VIACR, CR96) & 0x0f;
1614 len +=
1615 sprintf(buf + len, "%x %x %x\n", dvp0, dvp0_data_dri, dvp0_clk_dri);
1616 *eof = 1; /*Inform kernel end of data */
1617 return len;
1618}
1619static int viafb_dvp0_proc_write(struct file *file,
1620 const char __user *buffer, unsigned long count, void *data)
1621{
1622 char buf[20], *value, *pbuf;
1623 u8 reg_val = 0;
1624 unsigned long length, i;
1625 if (count < 1)
1626 return -EINVAL;
1627 length = count > 20 ? 20 : count;
1628 if (copy_from_user(&buf[0], buffer, length))
1629 return -EFAULT;
1630 buf[length - 1] = '\0'; /*Ensure end string */
1631 pbuf = &buf[0];
1632 for (i = 0; i < 3; i++) {
1633 value = strsep(&pbuf, " ");
1634 if (value != NULL) {
1635 strict_strtoul(value, 0, (unsigned long *)&reg_val);
1636 DEBUG_MSG(KERN_INFO "DVP0:reg_val[%l]=:%x\n", i,
1637 reg_val);
1638 switch (i) {
1639 case 0:
1640 viafb_write_reg_mask(CR96, VIACR,
1641 reg_val, 0x0f);
1642 break;
1643 case 1:
1644 viafb_write_reg_mask(SR2A, VIASR,
1645 reg_val << 4, BIT5);
1646 viafb_write_reg_mask(SR1B, VIASR,
1647 reg_val << 1, BIT1);
1648 break;
1649 case 2:
1650 viafb_write_reg_mask(SR2A, VIASR,
1651 reg_val << 3, BIT4);
1652 viafb_write_reg_mask(SR1E, VIASR,
1653 reg_val << 2, BIT2);
1654 break;
1655 default:
1656 break;
1657 }
1658 } else {
1659 break;
1660 }
1661 }
1662 return count;
1663}
1664static int viafb_dvp1_proc_read(char *buf, char **start, off_t offset,
1665 int count, int *eof, void *data)
1666{
1667 int len = 0;
1668 u8 dvp1 = 0, dvp1_data_dri = 0, dvp1_clk_dri = 0;
1669 dvp1 = viafb_read_reg(VIACR, CR9B) & 0x0f;
1670 dvp1_data_dri = (viafb_read_reg(VIASR, SR65) & 0x0c) >> 2;
1671 dvp1_clk_dri = viafb_read_reg(VIASR, SR65) & 0x03;
1672 len +=
1673 sprintf(buf + len, "%x %x %x\n", dvp1, dvp1_data_dri, dvp1_clk_dri);
1674 *eof = 1; /*Inform kernel end of data */
1675 return len;
1676}
1677static int viafb_dvp1_proc_write(struct file *file,
1678 const char __user *buffer, unsigned long count, void *data)
1679{
1680 char buf[20], *value, *pbuf;
1681 u8 reg_val = 0;
1682 unsigned long length, i;
1683 if (count < 1)
1684 return -EINVAL;
1685 length = count > 20 ? 20 : count;
1686 if (copy_from_user(&buf[0], buffer, length))
1687 return -EFAULT;
1688 buf[length - 1] = '\0'; /*Ensure end string */
1689 pbuf = &buf[0];
1690 for (i = 0; i < 3; i++) {
1691 value = strsep(&pbuf, " ");
1692 if (value != NULL) {
1693 strict_strtoul(value, 0, (unsigned long *)&reg_val);
1694 switch (i) {
1695 case 0:
1696 viafb_write_reg_mask(CR9B, VIACR,
1697 reg_val, 0x0f);
1698 break;
1699 case 1:
1700 viafb_write_reg_mask(SR65, VIASR,
1701 reg_val << 2, 0x0c);
1702 break;
1703 case 2:
1704 viafb_write_reg_mask(SR65, VIASR,
1705 reg_val, 0x03);
1706 break;
1707 default:
1708 break;
1709 }
1710 } else {
1711 break;
1712 }
1713 }
1714 return count;
1715}
1716
1717static int viafb_dfph_proc_read(char *buf, char **start, off_t offset,
1718 int count, int *eof, void *data)
1719{
1720 int len = 0;
1721 u8 dfp_high = 0;
1722 dfp_high = viafb_read_reg(VIACR, CR97) & 0x0f;
1723 len += sprintf(buf + len, "%x\n", dfp_high);
1724 *eof = 1; /*Inform kernel end of data */
1725 return len;
1726}
1727static int viafb_dfph_proc_write(struct file *file,
1728 const char __user *buffer, unsigned long count, void *data)
1729{
1730 char buf[20];
1731 u8 reg_val = 0;
1732 unsigned long length;
1733 if (count < 1)
1734 return -EINVAL;
1735 length = count > 20 ? 20 : count;
1736 if (copy_from_user(&buf[0], buffer, length))
1737 return -EFAULT;
1738 buf[length - 1] = '\0'; /*Ensure end string */
1739 strict_strtoul(&buf[0], 0, (unsigned long *)&reg_val);
1740 viafb_write_reg_mask(CR97, VIACR, reg_val, 0x0f);
1741 return count;
1742}
1743static int viafb_dfpl_proc_read(char *buf, char **start, off_t offset,
1744 int count, int *eof, void *data)
1745{
1746 int len = 0;
1747 u8 dfp_low = 0;
1748 dfp_low = viafb_read_reg(VIACR, CR99) & 0x0f;
1749 len += sprintf(buf + len, "%x\n", dfp_low);
1750 *eof = 1; /*Inform kernel end of data */
1751 return len;
1752}
1753static int viafb_dfpl_proc_write(struct file *file,
1754 const char __user *buffer, unsigned long count, void *data)
1755{
1756 char buf[20];
1757 u8 reg_val = 0;
1758 unsigned long length;
1759 if (count < 1)
1760 return -EINVAL;
1761 length = count > 20 ? 20 : count;
1762 if (copy_from_user(&buf[0], buffer, length))
1763 return -EFAULT;
1764 buf[length - 1] = '\0'; /*Ensure end string */
1765 strict_strtoul(&buf[0], 0, (unsigned long *)&reg_val);
1766 viafb_write_reg_mask(CR99, VIACR, reg_val, 0x0f);
1767 return count;
1768}
1769static int viafb_vt1636_proc_read(char *buf, char **start,
1770 off_t offset, int count, int *eof, void *data)
1771{
1772 int len = 0;
1773 u8 vt1636_08 = 0, vt1636_09 = 0;
1774 switch (viaparinfo->chip_info->lvds_chip_info.lvds_chip_name) {
1775 case VT1636_LVDS:
1776 vt1636_08 =
1777 viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info,
1778 &viaparinfo->chip_info->lvds_chip_info, 0x08) & 0x0f;
1779 vt1636_09 =
1780 viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info,
1781 &viaparinfo->chip_info->lvds_chip_info, 0x09) & 0x1f;
1782 len += sprintf(buf + len, "%x %x\n", vt1636_08, vt1636_09);
1783 break;
1784 default:
1785 break;
1786 }
1787 switch (viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name) {
1788 case VT1636_LVDS:
1789 vt1636_08 =
1790 viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info2,
1791 &viaparinfo->chip_info->lvds_chip_info2, 0x08) & 0x0f;
1792 vt1636_09 =
1793 viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info2,
1794 &viaparinfo->chip_info->lvds_chip_info2, 0x09) & 0x1f;
1795 len += sprintf(buf + len, " %x %x\n", vt1636_08, vt1636_09);
1796 break;
1797 default:
1798 break;
1799 }
1800 *eof = 1; /*Inform kernel end of data */
1801 return len;
1802}
1803static int viafb_vt1636_proc_write(struct file *file,
1804 const char __user *buffer, unsigned long count, void *data)
1805{
1806 char buf[30], *value, *pbuf;
1807 struct IODATA reg_val;
1808 unsigned long length, i;
1809 if (count < 1)
1810 return -EINVAL;
1811 length = count > 30 ? 30 : count;
1812 if (copy_from_user(&buf[0], buffer, length))
1813 return -EFAULT;
1814 buf[length - 1] = '\0'; /*Ensure end string */
1815 pbuf = &buf[0];
1816 switch (viaparinfo->chip_info->lvds_chip_info.lvds_chip_name) {
1817 case VT1636_LVDS:
1818 for (i = 0; i < 2; i++) {
1819 value = strsep(&pbuf, " ");
1820 if (value != NULL) {
1821 strict_strtoul(value, 0,
1822 (unsigned long *)&reg_val.Data);
1823 switch (i) {
1824 case 0:
1825 reg_val.Index = 0x08;
1826 reg_val.Mask = 0x0f;
1827 viafb_gpio_i2c_write_mask_lvds
1828 (viaparinfo->lvds_setting_info,
1829 &viaparinfo->
1830 chip_info->lvds_chip_info,
1831 reg_val);
1832 break;
1833 case 1:
1834 reg_val.Index = 0x09;
1835 reg_val.Mask = 0x1f;
1836 viafb_gpio_i2c_write_mask_lvds
1837 (viaparinfo->lvds_setting_info,
1838 &viaparinfo->
1839 chip_info->lvds_chip_info,
1840 reg_val);
1841 break;
1842 default:
1843 break;
1844 }
1845 } else {
1846 break;
1847 }
1848 }
1849 break;
1850 default:
1851 break;
1852 }
1853 switch (viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name) {
1854 case VT1636_LVDS:
1855 for (i = 0; i < 2; i++) {
1856 value = strsep(&pbuf, " ");
1857 if (value != NULL) {
1858 strict_strtoul(value, 0,
1859 (unsigned long *)&reg_val.Data);
1860 switch (i) {
1861 case 0:
1862 reg_val.Index = 0x08;
1863 reg_val.Mask = 0x0f;
1864 viafb_gpio_i2c_write_mask_lvds
1865 (viaparinfo->lvds_setting_info2,
1866 &viaparinfo->
1867 chip_info->lvds_chip_info2,
1868 reg_val);
1869 break;
1870 case 1:
1871 reg_val.Index = 0x09;
1872 reg_val.Mask = 0x1f;
1873 viafb_gpio_i2c_write_mask_lvds
1874 (viaparinfo->lvds_setting_info2,
1875 &viaparinfo->
1876 chip_info->lvds_chip_info2,
1877 reg_val);
1878 break;
1879 default:
1880 break;
1881 }
1882 } else {
1883 break;
1884 }
1885 }
1886 break;
1887 default:
1888 break;
1889 }
1890 return count;
1891}
1892
Bruno Prémontc267fd72008-11-19 15:36:23 -08001893static void viafb_init_proc(struct proc_dir_entry **viafb_entry)
Joseph Chan29b619f2008-10-15 22:03:27 -07001894{
1895 struct proc_dir_entry *entry;
Bruno Prémontc267fd72008-11-19 15:36:23 -08001896 *viafb_entry = proc_mkdir("viafb", NULL);
Joseph Chan29b619f2008-10-15 22:03:27 -07001897 if (viafb_entry) {
Bruno Prémontc267fd72008-11-19 15:36:23 -08001898 entry = create_proc_entry("dvp0", 0, *viafb_entry);
Joseph Chan29b619f2008-10-15 22:03:27 -07001899 if (entry) {
Joseph Chan29b619f2008-10-15 22:03:27 -07001900 entry->read_proc = viafb_dvp0_proc_read;
1901 entry->write_proc = viafb_dvp0_proc_write;
1902 }
Bruno Prémontc267fd72008-11-19 15:36:23 -08001903 entry = create_proc_entry("dvp1", 0, *viafb_entry);
Joseph Chan29b619f2008-10-15 22:03:27 -07001904 if (entry) {
Joseph Chan29b619f2008-10-15 22:03:27 -07001905 entry->read_proc = viafb_dvp1_proc_read;
1906 entry->write_proc = viafb_dvp1_proc_write;
1907 }
Bruno Prémontc267fd72008-11-19 15:36:23 -08001908 entry = create_proc_entry("dfph", 0, *viafb_entry);
Joseph Chan29b619f2008-10-15 22:03:27 -07001909 if (entry) {
Joseph Chan29b619f2008-10-15 22:03:27 -07001910 entry->read_proc = viafb_dfph_proc_read;
1911 entry->write_proc = viafb_dfph_proc_write;
1912 }
Bruno Prémontc267fd72008-11-19 15:36:23 -08001913 entry = create_proc_entry("dfpl", 0, *viafb_entry);
Joseph Chan29b619f2008-10-15 22:03:27 -07001914 if (entry) {
Joseph Chan29b619f2008-10-15 22:03:27 -07001915 entry->read_proc = viafb_dfpl_proc_read;
1916 entry->write_proc = viafb_dfpl_proc_write;
1917 }
1918 if (VT1636_LVDS == viaparinfo->chip_info->lvds_chip_info.
1919 lvds_chip_name || VT1636_LVDS ==
1920 viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name) {
Bruno Prémontc267fd72008-11-19 15:36:23 -08001921 entry = create_proc_entry("vt1636", 0, *viafb_entry);
Joseph Chan29b619f2008-10-15 22:03:27 -07001922 if (entry) {
Joseph Chan29b619f2008-10-15 22:03:27 -07001923 entry->read_proc = viafb_vt1636_proc_read;
1924 entry->write_proc = viafb_vt1636_proc_write;
1925 }
1926 }
1927
1928 }
1929}
1930static void viafb_remove_proc(struct proc_dir_entry *viafb_entry)
1931{
1932 /* no problem if it was not registered */
1933 remove_proc_entry("dvp0", viafb_entry);/* parent dir */
1934 remove_proc_entry("dvp1", viafb_entry);
1935 remove_proc_entry("dfph", viafb_entry);
1936 remove_proc_entry("dfpl", viafb_entry);
1937 remove_proc_entry("vt1636", viafb_entry);
1938 remove_proc_entry("vt1625", viafb_entry);
Bruno Prémontc267fd72008-11-19 15:36:23 -08001939 remove_proc_entry("viafb", NULL);
Joseph Chan29b619f2008-10-15 22:03:27 -07001940}
1941
1942static int __devinit via_pci_probe(void)
1943{
Harald Welteee1ef822009-05-12 13:19:42 -07001944 unsigned long default_xres, default_yres;
Joseph Chan29b619f2008-10-15 22:03:27 -07001945 char *tmpc, *tmpm;
1946 char *tmpc_sec, *tmpm_sec;
1947 int vmode_index;
1948 u32 tmds_length, lvds_length, crt_length, chip_length, viafb_par_length;
1949
1950 DEBUG_MSG(KERN_INFO "VIAFB PCI Probe!!\n");
1951
1952 viafb_par_length = ALIGN(sizeof(struct viafb_par), BITS_PER_LONG/8);
1953 tmds_length = ALIGN(sizeof(struct tmds_setting_information),
1954 BITS_PER_LONG/8);
1955 lvds_length = ALIGN(sizeof(struct lvds_setting_information),
1956 BITS_PER_LONG/8);
1957 crt_length = ALIGN(sizeof(struct lvds_setting_information),
1958 BITS_PER_LONG/8);
1959 chip_length = ALIGN(sizeof(struct chip_information), BITS_PER_LONG/8);
1960
1961 /* Allocate fb_info and ***_par here, also including some other needed
1962 * variables
1963 */
1964 viafbinfo = framebuffer_alloc(viafb_par_length + 2 * lvds_length +
1965 tmds_length + crt_length + chip_length, NULL);
1966 if (!viafbinfo) {
1967 printk(KERN_ERR"Could not allocate memory for viafb_info.\n");
1968 return -ENODEV;
1969 }
1970
1971 viaparinfo = (struct viafb_par *)viafbinfo->par;
1972 viaparinfo->tmds_setting_info = (struct tmds_setting_information *)
Joseph Chanb3a45d82008-10-15 22:03:29 -07001973 ((unsigned long)viaparinfo + viafb_par_length);
Joseph Chan29b619f2008-10-15 22:03:27 -07001974 viaparinfo->lvds_setting_info = (struct lvds_setting_information *)
Joseph Chanb3a45d82008-10-15 22:03:29 -07001975 ((unsigned long)viaparinfo->tmds_setting_info + tmds_length);
Joseph Chan29b619f2008-10-15 22:03:27 -07001976 viaparinfo->lvds_setting_info2 = (struct lvds_setting_information *)
Joseph Chanb3a45d82008-10-15 22:03:29 -07001977 ((unsigned long)viaparinfo->lvds_setting_info + lvds_length);
Joseph Chan29b619f2008-10-15 22:03:27 -07001978 viaparinfo->crt_setting_info = (struct crt_setting_information *)
Joseph Chanb3a45d82008-10-15 22:03:29 -07001979 ((unsigned long)viaparinfo->lvds_setting_info2 + lvds_length);
Joseph Chan29b619f2008-10-15 22:03:27 -07001980 viaparinfo->chip_info = (struct chip_information *)
Joseph Chanb3a45d82008-10-15 22:03:29 -07001981 ((unsigned long)viaparinfo->crt_setting_info + crt_length);
Joseph Chan29b619f2008-10-15 22:03:27 -07001982
1983 if (viafb_dual_fb)
1984 viafb_SAMM_ON = 1;
1985 parse_active_dev();
Joseph Chan29b619f2008-10-15 22:03:27 -07001986 parse_lcd_port();
1987 parse_dvi_port();
1988
1989 /* for dual-fb must viafb_SAMM_ON=1 and viafb_dual_fb=1 */
1990 if (!viafb_SAMM_ON)
1991 viafb_dual_fb = 0;
1992
1993 /* Set up I2C bus stuff */
1994 viafb_create_i2c_bus(viaparinfo);
1995
1996 viafb_init_chip_info();
1997 viafb_get_fb_info(&viaparinfo->fbmem, &viaparinfo->memsize);
1998 viaparinfo->fbmem_free = viaparinfo->memsize;
1999 viaparinfo->fbmem_used = 0;
Florian Tobias Schandinatdb88e382009-09-22 16:47:20 -07002000 viafbinfo->screen_base = ioremap_nocache(viaparinfo->fbmem,
Joseph Chan29b619f2008-10-15 22:03:27 -07002001 viaparinfo->memsize);
Florian Tobias Schandinatdb88e382009-09-22 16:47:20 -07002002 if (!viafbinfo->screen_base) {
Joseph Chan29b619f2008-10-15 22:03:27 -07002003 printk(KERN_INFO "ioremap failed\n");
Florian Tobias Schandinatbc6932b2009-09-22 16:47:15 -07002004 return -ENOMEM;
Joseph Chan29b619f2008-10-15 22:03:27 -07002005 }
2006
2007 viafb_get_mmio_info(&viaparinfo->mmio_base, &viaparinfo->mmio_len);
2008 viaparinfo->io_virt = ioremap_nocache(viaparinfo->mmio_base,
2009 viaparinfo->mmio_len);
Florian Tobias Schandinatbc6932b2009-09-22 16:47:15 -07002010 if (!viaparinfo->io_virt) {
2011 printk(KERN_WARNING "ioremap failed: hardware acceleration disabled\n");
2012 viafb_accel = 0;
2013 }
Joseph Chan29b619f2008-10-15 22:03:27 -07002014
2015 viafbinfo->node = 0;
2016 viafbinfo->fbops = &viafb_ops;
2017 viafbinfo->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
2018
2019 viafbinfo->pseudo_palette = pseudo_pal;
2020 if (viafb_accel) {
2021 viafb_init_accel();
2022 viafb_init_2d_engine();
2023 viafb_hw_cursor_init();
2024 }
2025
2026 if (viafb_second_size && (viafb_second_size < 8)) {
2027 viafb_second_offset = viaparinfo->fbmem_free -
2028 viafb_second_size * 1024 * 1024;
2029 } else {
2030 viafb_second_size = 8;
2031 viafb_second_offset = viaparinfo->fbmem_free -
2032 viafb_second_size * 1024 * 1024;
2033 }
2034
Joseph Chan29b619f2008-10-15 22:03:27 -07002035 tmpm = viafb_mode;
2036 tmpc = strsep(&tmpm, "x");
Harald Welteee1ef822009-05-12 13:19:42 -07002037 strict_strtoul(tmpc, 0, &default_xres);
2038 strict_strtoul(tmpm, 0, &default_yres);
Joseph Chan29b619f2008-10-15 22:03:27 -07002039
Florian Tobias Schandinat52159442009-08-06 15:07:34 -07002040 vmode_index = viafb_get_mode_index(default_xres, default_yres);
Joseph Chan29b619f2008-10-15 22:03:27 -07002041 DEBUG_MSG(KERN_INFO "0->index=%d\n", vmode_index);
2042
2043 if (viafb_SAMM_ON == 1) {
2044 if (strcmp(viafb_mode, viafb_mode1)) {
2045 tmpm_sec = viafb_mode1;
2046 tmpc_sec = strsep(&tmpm_sec, "x");
2047 strict_strtoul(tmpc_sec, 0,
2048 (unsigned long *)&viafb_second_xres);
2049 strict_strtoul(tmpm_sec, 0,
2050 (unsigned long *)&viafb_second_yres);
2051 } else {
2052 viafb_second_xres = default_xres;
2053 viafb_second_yres = default_yres;
2054 }
2055 if (0 == viafb_second_virtual_xres) {
2056 switch (viafb_second_xres) {
2057 case 1400:
2058 viafb_second_virtual_xres = 1408;
2059 break;
2060 default:
2061 viafb_second_virtual_xres = viafb_second_xres;
2062 break;
2063 }
2064 }
2065 if (0 == viafb_second_virtual_yres)
2066 viafb_second_virtual_yres = viafb_second_yres;
2067 }
2068
2069 switch (viafb_bpp) {
2070 case 0 ... 8:
2071 viafb_bpp = 8;
2072 break;
2073 case 9 ... 16:
2074 viafb_bpp = 16;
2075 break;
2076 case 17 ... 32:
2077 viafb_bpp = 32;
2078 break;
2079 default:
2080 viafb_bpp = 8;
2081 }
2082 default_var.xres = default_xres;
2083 default_var.yres = default_yres;
2084 switch (default_xres) {
2085 case 1400:
2086 default_var.xres_virtual = 1408;
2087 break;
2088 default:
2089 default_var.xres_virtual = default_xres;
2090 break;
2091 }
2092 default_var.yres_virtual = default_yres;
2093 default_var.bits_per_pixel = viafb_bpp;
2094 if (default_var.bits_per_pixel == 15)
2095 default_var.bits_per_pixel = 16;
2096 default_var.pixclock =
2097 viafb_get_pixclock(default_xres, default_yres, viafb_refresh);
2098 default_var.left_margin = (default_xres >> 3) & 0xf8;
2099 default_var.right_margin = 32;
2100 default_var.upper_margin = 16;
2101 default_var.lower_margin = 4;
2102 default_var.hsync_len = default_var.left_margin;
2103 default_var.vsync_len = 4;
2104 default_var.accel_flags = 0;
2105
2106 if (viafb_accel) {
2107 viafbinfo->flags |=
2108 (FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT |
2109 FBINFO_HWACCEL_IMAGEBLIT);
2110 default_var.accel_flags |= FB_ACCELF_TEXT;
2111 } else
2112 viafbinfo->flags |= FBINFO_HWACCEL_DISABLED;
2113
2114 if (viafb_dual_fb) {
2115 viafbinfo1 = framebuffer_alloc(viafb_par_length, NULL);
2116 if (!viafbinfo1) {
2117 printk(KERN_ERR
2118 "allocate the second framebuffer struct error\n");
2119 framebuffer_release(viafbinfo);
2120 return -ENOMEM;
2121 }
2122 viaparinfo1 = viafbinfo1->par;
2123 memcpy(viaparinfo1, viaparinfo, viafb_par_length);
2124 viaparinfo1->memsize = viaparinfo->memsize -
2125 viafb_second_offset;
2126 viaparinfo->memsize = viafb_second_offset;
Joseph Chan29b619f2008-10-15 22:03:27 -07002127 viaparinfo1->fbmem = viaparinfo->fbmem + viafb_second_offset;
2128
2129 viaparinfo1->fbmem_used = viaparinfo->fbmem_used;
2130 viaparinfo1->fbmem_free = viaparinfo1->memsize -
2131 viaparinfo1->fbmem_used;
2132 viaparinfo->fbmem_free = viaparinfo->memsize;
2133 viaparinfo->fbmem_used = 0;
2134 if (viafb_accel) {
2135 viaparinfo1->cursor_start =
2136 viaparinfo->cursor_start - viafb_second_offset;
2137 viaparinfo1->VQ_start = viaparinfo->VQ_start -
2138 viafb_second_offset;
2139 viaparinfo1->VQ_end = viaparinfo->VQ_end -
2140 viafb_second_offset;
2141 }
2142
Florian Tobias Schandinat09cf1182009-09-22 16:47:14 -07002143 viaparinfo->iga_path = IGA1;
2144 viaparinfo1->iga_path = IGA2;
Joseph Chan29b619f2008-10-15 22:03:27 -07002145 memcpy(viafbinfo1, viafbinfo, sizeof(struct fb_info));
2146 viafbinfo1->screen_base = viafbinfo->screen_base +
2147 viafb_second_offset;
Joseph Chan29b619f2008-10-15 22:03:27 -07002148
2149 default_var.xres = viafb_second_xres;
2150 default_var.yres = viafb_second_yres;
2151 default_var.xres_virtual = viafb_second_virtual_xres;
2152 default_var.yres_virtual = viafb_second_virtual_yres;
2153 if (viafb_bpp1 != viafb_bpp)
2154 viafb_bpp1 = viafb_bpp;
2155 default_var.bits_per_pixel = viafb_bpp1;
2156 default_var.pixclock =
2157 viafb_get_pixclock(viafb_second_xres, viafb_second_yres,
2158 viafb_refresh);
2159 default_var.left_margin = (viafb_second_xres >> 3) & 0xf8;
2160 default_var.right_margin = 32;
2161 default_var.upper_margin = 16;
2162 default_var.lower_margin = 4;
2163 default_var.hsync_len = default_var.left_margin;
2164 default_var.vsync_len = 4;
2165
2166 viafb_setup_fixinfo(&viafbinfo1->fix, viaparinfo1);
2167 viafb_check_var(&default_var, viafbinfo1);
2168 viafbinfo1->var = default_var;
Florian Tobias Schandinat81228a32009-09-22 16:47:13 -07002169 viafb_update_fix(viafbinfo1);
Joseph Chan29b619f2008-10-15 22:03:27 -07002170 }
2171
2172 viafb_setup_fixinfo(&viafbinfo->fix, viaparinfo);
2173 viafb_check_var(&default_var, viafbinfo);
2174 viafbinfo->var = default_var;
Florian Tobias Schandinat81228a32009-09-22 16:47:13 -07002175 viafb_update_fix(viafbinfo);
Joseph Chan29b619f2008-10-15 22:03:27 -07002176 default_var.activate = FB_ACTIVATE_NOW;
2177 fb_alloc_cmap(&viafbinfo->cmap, 256, 0);
2178
2179 if (viafb_dual_fb && (viafb_primary_dev == LCD_Device)
2180 && (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266)) {
2181 if (register_framebuffer(viafbinfo1) < 0)
2182 return -EINVAL;
2183 }
2184 if (register_framebuffer(viafbinfo) < 0)
2185 return -EINVAL;
2186
2187 if (viafb_dual_fb && ((viafb_primary_dev != LCD_Device)
2188 || (viaparinfo->chip_info->gfx_chip_name !=
2189 UNICHROME_CLE266))) {
2190 if (register_framebuffer(viafbinfo1) < 0)
2191 return -EINVAL;
2192 }
2193 DEBUG_MSG(KERN_INFO "fb%d: %s frame buffer device %dx%d-%dbpp\n",
2194 viafbinfo->node, viafbinfo->fix.id, default_var.xres,
2195 default_var.yres, default_var.bits_per_pixel);
2196
Bruno Prémontc267fd72008-11-19 15:36:23 -08002197 viafb_init_proc(&viaparinfo->proc_entry);
Joseph Chan29b619f2008-10-15 22:03:27 -07002198 viafb_init_dac(IGA2);
2199 return 0;
2200}
2201
2202static void __devexit via_pci_remove(void)
2203{
2204 DEBUG_MSG(KERN_INFO "via_pci_remove!\n");
2205 fb_dealloc_cmap(&viafbinfo->cmap);
2206 unregister_framebuffer(viafbinfo);
2207 if (viafb_dual_fb)
2208 unregister_framebuffer(viafbinfo1);
Florian Tobias Schandinatdb88e382009-09-22 16:47:20 -07002209 iounmap((void *)viafbinfo->screen_base);
Joseph Chan29b619f2008-10-15 22:03:27 -07002210 iounmap(viaparinfo->io_virt);
2211
2212 viafb_delete_i2c_buss(viaparinfo);
2213
2214 framebuffer_release(viafbinfo);
2215 if (viafb_dual_fb)
2216 framebuffer_release(viafbinfo1);
2217
2218 viafb_remove_proc(viaparinfo->proc_entry);
2219}
2220
2221#ifndef MODULE
2222static int __init viafb_setup(char *options)
2223{
2224 char *this_opt;
2225 DEBUG_MSG(KERN_INFO "viafb_setup!\n");
2226
2227 if (!options || !*options)
2228 return 0;
2229
2230 while ((this_opt = strsep(&options, ",")) != NULL) {
2231 if (!*this_opt)
2232 continue;
2233
2234 if (!strncmp(this_opt, "viafb_mode1=", 12))
2235 viafb_mode1 = kstrdup(this_opt + 12, GFP_KERNEL);
2236 else if (!strncmp(this_opt, "viafb_mode=", 11))
2237 viafb_mode = kstrdup(this_opt + 11, GFP_KERNEL);
2238 else if (!strncmp(this_opt, "viafb_bpp1=", 11))
2239 strict_strtoul(this_opt + 11, 0,
2240 (unsigned long *)&viafb_bpp1);
2241 else if (!strncmp(this_opt, "viafb_bpp=", 10))
2242 strict_strtoul(this_opt + 10, 0,
2243 (unsigned long *)&viafb_bpp);
2244 else if (!strncmp(this_opt, "viafb_refresh1=", 15))
2245 strict_strtoul(this_opt + 15, 0,
2246 (unsigned long *)&viafb_refresh1);
2247 else if (!strncmp(this_opt, "viafb_refresh=", 14))
2248 strict_strtoul(this_opt + 14, 0,
2249 (unsigned long *)&viafb_refresh);
2250 else if (!strncmp(this_opt, "viafb_lcd_dsp_method=", 21))
2251 strict_strtoul(this_opt + 21, 0,
2252 (unsigned long *)&viafb_lcd_dsp_method);
2253 else if (!strncmp(this_opt, "viafb_lcd_panel_id=", 19))
2254 strict_strtoul(this_opt + 19, 0,
2255 (unsigned long *)&viafb_lcd_panel_id);
2256 else if (!strncmp(this_opt, "viafb_accel=", 12))
2257 strict_strtoul(this_opt + 12, 0,
2258 (unsigned long *)&viafb_accel);
2259 else if (!strncmp(this_opt, "viafb_SAMM_ON=", 14))
2260 strict_strtoul(this_opt + 14, 0,
2261 (unsigned long *)&viafb_SAMM_ON);
2262 else if (!strncmp(this_opt, "viafb_active_dev=", 17))
2263 viafb_active_dev = kstrdup(this_opt + 17, GFP_KERNEL);
2264 else if (!strncmp(this_opt,
2265 "viafb_display_hardware_layout=", 30))
2266 strict_strtoul(this_opt + 30, 0,
2267 (unsigned long *)&viafb_display_hardware_layout);
2268 else if (!strncmp(this_opt, "viafb_second_size=", 18))
2269 strict_strtoul(this_opt + 18, 0,
2270 (unsigned long *)&viafb_second_size);
2271 else if (!strncmp(this_opt,
2272 "viafb_platform_epia_dvi=", 24))
2273 strict_strtoul(this_opt + 24, 0,
2274 (unsigned long *)&viafb_platform_epia_dvi);
2275 else if (!strncmp(this_opt,
2276 "viafb_device_lcd_dualedge=", 26))
2277 strict_strtoul(this_opt + 26, 0,
2278 (unsigned long *)&viafb_device_lcd_dualedge);
2279 else if (!strncmp(this_opt, "viafb_bus_width=", 16))
2280 strict_strtoul(this_opt + 16, 0,
2281 (unsigned long *)&viafb_bus_width);
2282 else if (!strncmp(this_opt, "viafb_lcd_mode=", 15))
2283 strict_strtoul(this_opt + 15, 0,
2284 (unsigned long *)&viafb_lcd_mode);
Joseph Chan29b619f2008-10-15 22:03:27 -07002285 else if (!strncmp(this_opt, "viafb_lcd_port=", 15))
2286 viafb_lcd_port = kstrdup(this_opt + 15, GFP_KERNEL);
2287 else if (!strncmp(this_opt, "viafb_dvi_port=", 15))
2288 viafb_dvi_port = kstrdup(this_opt + 15, GFP_KERNEL);
2289 }
2290 return 0;
2291}
2292#endif
2293
2294static int __init viafb_init(void)
2295{
2296#ifndef MODULE
2297 char *option = NULL;
2298 if (fb_get_options("viafb", &option))
2299 return -ENODEV;
2300 viafb_setup(option);
2301#endif
2302 printk(KERN_INFO
2303 "VIA Graphics Intergration Chipset framebuffer %d.%d initializing\n",
2304 VERSION_MAJOR, VERSION_MINOR);
2305 return via_pci_probe();
2306}
2307
2308static void __exit viafb_exit(void)
2309{
2310 DEBUG_MSG(KERN_INFO "viafb_exit!\n");
2311 via_pci_remove();
2312}
2313
2314static struct fb_ops viafb_ops = {
2315 .owner = THIS_MODULE,
2316 .fb_open = viafb_open,
2317 .fb_release = viafb_release,
2318 .fb_check_var = viafb_check_var,
2319 .fb_set_par = viafb_set_par,
2320 .fb_setcolreg = viafb_setcolreg,
2321 .fb_pan_display = viafb_pan_display,
2322 .fb_blank = viafb_blank,
2323 .fb_fillrect = viafb_fillrect,
2324 .fb_copyarea = viafb_copyarea,
2325 .fb_imageblit = viafb_imageblit,
2326 .fb_cursor = viafb_cursor,
2327 .fb_ioctl = viafb_ioctl,
2328 .fb_sync = viafb_sync,
2329 .fb_setcmap = viafb_setcmap,
2330};
2331
2332module_init(viafb_init);
2333module_exit(viafb_exit);
2334
2335#ifdef MODULE
2336module_param(viafb_memsize, int, 0);
2337
2338module_param(viafb_mode, charp, 0);
2339MODULE_PARM_DESC(viafb_mode, "Set resolution (default=640x480)");
2340
2341module_param(viafb_mode1, charp, 0);
2342MODULE_PARM_DESC(viafb_mode1, "Set resolution (default=640x480)");
2343
2344module_param(viafb_bpp, int, 0);
2345MODULE_PARM_DESC(viafb_bpp, "Set color depth (default=32bpp)");
2346
2347module_param(viafb_bpp1, int, 0);
2348MODULE_PARM_DESC(viafb_bpp1, "Set color depth (default=32bpp)");
2349
2350module_param(viafb_refresh, int, 0);
2351MODULE_PARM_DESC(viafb_refresh,
2352 "Set CRT viafb_refresh rate (default = 60)");
2353
2354module_param(viafb_refresh1, int, 0);
2355MODULE_PARM_DESC(viafb_refresh1,
2356 "Set CRT refresh rate (default = 60)");
2357
2358module_param(viafb_lcd_panel_id, int, 0);
2359MODULE_PARM_DESC(viafb_lcd_panel_id,
2360 "Set Flat Panel type(Default=1024x768)");
2361
2362module_param(viafb_lcd_dsp_method, int, 0);
2363MODULE_PARM_DESC(viafb_lcd_dsp_method,
2364 "Set Flat Panel display scaling method.(Default=Expandsion)");
2365
2366module_param(viafb_SAMM_ON, int, 0);
2367MODULE_PARM_DESC(viafb_SAMM_ON,
2368 "Turn on/off flag of SAMM(Default=OFF)");
2369
2370module_param(viafb_accel, int, 0);
2371MODULE_PARM_DESC(viafb_accel,
2372 "Set 2D Hardware Acceleration.(Default = OFF)");
2373
2374module_param(viafb_active_dev, charp, 0);
2375MODULE_PARM_DESC(viafb_active_dev, "Specify active devices.");
2376
2377module_param(viafb_display_hardware_layout, int, 0);
2378MODULE_PARM_DESC(viafb_display_hardware_layout,
2379 "Display Hardware Layout (LCD Only, DVI Only...,etc)");
2380
2381module_param(viafb_second_size, int, 0);
2382MODULE_PARM_DESC(viafb_second_size,
2383 "Set secondary device memory size");
2384
2385module_param(viafb_dual_fb, int, 0);
2386MODULE_PARM_DESC(viafb_dual_fb,
2387 "Turn on/off flag of dual framebuffer devices.(Default = OFF)");
2388
2389module_param(viafb_platform_epia_dvi, int, 0);
2390MODULE_PARM_DESC(viafb_platform_epia_dvi,
2391 "Turn on/off flag of DVI devices on EPIA board.(Default = OFF)");
2392
2393module_param(viafb_device_lcd_dualedge, int, 0);
2394MODULE_PARM_DESC(viafb_device_lcd_dualedge,
2395 "Turn on/off flag of dual edge panel.(Default = OFF)");
2396
2397module_param(viafb_bus_width, int, 0);
2398MODULE_PARM_DESC(viafb_bus_width,
2399 "Set bus width of panel.(Default = 12)");
2400
2401module_param(viafb_lcd_mode, int, 0);
2402MODULE_PARM_DESC(viafb_lcd_mode,
2403 "Set Flat Panel mode(Default=OPENLDI)");
2404
Joseph Chan29b619f2008-10-15 22:03:27 -07002405module_param(viafb_lcd_port, charp, 0);
2406MODULE_PARM_DESC(viafb_lcd_port, "Specify LCD output port.");
2407
2408module_param(viafb_dvi_port, charp, 0);
2409MODULE_PARM_DESC(viafb_dvi_port, "Specify DVI output port.");
2410
2411MODULE_LICENSE("GPL");
2412#endif