viafbdev.c 60.0 KB
Newer Older
J
Joseph Chan 已提交
1
/*
2
 * Copyright 1998-2009 VIA Technologies, Inc. All Rights Reserved.
J
Joseph Chan 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.

 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation;
 * either version 2, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
 * the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE.See the GNU General Public License
 * for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc.,
 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include <linux/module.h>
A
Alexey Dobriyan 已提交
23
#include <linux/seq_file.h>
24
#include <linux/slab.h>
25
#include <linux/stat.h>
26
#include <linux/via-core.h>
J
Joseph Chan 已提交
27

28
#define _MASTER_FILE
J
Joseph Chan 已提交
29 30 31 32 33 34
#include "global.h"

static char *viafb_name = "Via";
static u32 pseudo_pal[17];

/* video mode */
35 36
static char *viafb_mode;
static char *viafb_mode1;
37 38 39 40 41
static int viafb_bpp = 32;
static int viafb_bpp1 = 32;

static unsigned int viafb_second_offset;
static int viafb_second_size;
J
Joseph Chan 已提交
42

43 44
static int viafb_accel = 1;

J
Joseph Chan 已提交
45
/* Added for specifying active devices.*/
46
char *viafb_active_dev;
J
Joseph Chan 已提交
47 48 49 50 51 52 53 54 55 56 57 58

/*Added for specify lcd output port*/
char *viafb_lcd_port = "";
char *viafb_dvi_port = "";

static void viafb_set_device(struct device_t active_dev);
static int apply_device_setting(struct viafb_ioctl_setting setting_info,
			 struct fb_info *info);
static void apply_second_mode_setting(struct fb_var_screeninfo
	*sec_var);
static void retrieve_device_setting(struct viafb_ioctl_setting
	*setting_info);
59 60
static int viafb_pan_display(struct fb_var_screeninfo *var,
	struct fb_info *info);
J
Joseph Chan 已提交
61 62 63 64

static struct fb_ops viafb_ops;


65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
static void viafb_fill_var_color_info(struct fb_var_screeninfo *var, u8 depth)
{
	var->grayscale = 0;
	var->red.msb_right = 0;
	var->green.msb_right = 0;
	var->blue.msb_right = 0;
	var->transp.offset = 0;
	var->transp.length = 0;
	var->transp.msb_right = 0;
	var->nonstd = 0;
	switch (depth) {
	case 8:
		var->bits_per_pixel = 8;
		var->red.offset = 0;
		var->green.offset = 0;
		var->blue.offset = 0;
81 82 83
		var->red.length = 8;
		var->green.length = 8;
		var->blue.length = 8;
84
		break;
85 86 87 88 89 90 91 92 93
	case 15:
		var->bits_per_pixel = 16;
		var->red.offset = 10;
		var->green.offset = 5;
		var->blue.offset = 0;
		var->red.length = 5;
		var->green.length = 5;
		var->blue.length = 5;
		break;
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
	case 16:
		var->bits_per_pixel = 16;
		var->red.offset = 11;
		var->green.offset = 5;
		var->blue.offset = 0;
		var->red.length = 5;
		var->green.length = 6;
		var->blue.length = 5;
		break;
	case 24:
		var->bits_per_pixel = 32;
		var->red.offset = 16;
		var->green.offset = 8;
		var->blue.offset = 0;
		var->red.length = 8;
		var->green.length = 8;
		var->blue.length = 8;
		break;
112 113 114 115 116 117 118 119 120
	case 30:
		var->bits_per_pixel = 32;
		var->red.offset = 20;
		var->green.offset = 10;
		var->blue.offset = 0;
		var->red.length = 10;
		var->green.length = 10;
		var->blue.length = 10;
		break;
121 122 123
	}
}

124 125 126
static void viafb_update_fix(struct fb_info *info)
{
	u32 bpp = info->var.bits_per_pixel;
J
Joseph Chan 已提交
127

128 129
	info->fix.visual =
		bpp == 8 ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
130
	info->fix.line_length = (info->var.xres_virtual * bpp / 8 + 7) & ~7;
J
Joseph Chan 已提交
131 132 133 134 135 136 137 138 139 140 141 142 143
}

static void viafb_setup_fixinfo(struct fb_fix_screeninfo *fix,
	struct viafb_par *viaparinfo)
{
	memset(fix, 0, sizeof(struct fb_fix_screeninfo));
	strcpy(fix->id, viafb_name);

	fix->smem_start = viaparinfo->fbmem;
	fix->smem_len = viaparinfo->fbmem_free;

	fix->type = FB_TYPE_PACKED_PIXELS;
	fix->type_aux = 0;
144
	fix->visual = FB_VISUAL_TRUECOLOR;
J
Joseph Chan 已提交
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166

	fix->xpanstep = fix->ywrapstep = 0;
	fix->ypanstep = 1;

	/* Just tell the accel name */
	viafbinfo->fix.accel = FB_ACCEL_VIA_UNICHROME;
}
static int viafb_open(struct fb_info *info, int user)
{
	DEBUG_MSG(KERN_INFO "viafb_open!\n");
	return 0;
}

static int viafb_release(struct fb_info *info, int user)
{
	DEBUG_MSG(KERN_INFO "viafb_release!\n");
	return 0;
}

static int viafb_check_var(struct fb_var_screeninfo *var,
	struct fb_info *info)
{
167
	int htotal, vtotal, depth;
168
	struct VideoModeTable *vmode_entry;
169
	struct viafb_par *ppar = info->par;
170
	u32 long_refresh, line;
J
Joseph Chan 已提交
171 172 173 174 175 176 177

	DEBUG_MSG(KERN_INFO "viafb_check_var!\n");
	/* Sanity check */
	/* HW neither support interlacte nor double-scaned mode */
	if (var->vmode & FB_VMODE_INTERLACED || var->vmode & FB_VMODE_DOUBLE)
		return -EINVAL;

178 179
	vmode_entry = viafb_get_mode(var->xres, var->yres);
	if (!vmode_entry) {
J
Joseph Chan 已提交
180 181 182 183 184 185
		DEBUG_MSG(KERN_INFO
			  "viafb: Mode %dx%dx%d not supported!!\n",
			  var->xres, var->yres, var->bits_per_pixel);
		return -EINVAL;
	}

186 187 188
	depth = fb_get_color_depth(var, &info->fix);
	if (!depth)
		depth = var->bits_per_pixel;
J
Joseph Chan 已提交
189

190
	if (depth < 0 || depth > 32)
J
Joseph Chan 已提交
191
		return -EINVAL;
192 193
	else if (!depth)
		depth = 24;
194 195 196 197
	else if (depth == 15 && viafb_dual_fb && ppar->iga_path == IGA1)
		depth = 15;
	else if (depth == 30)
		depth = 30;
198 199 200 201 202 203 204 205
	else if (depth <= 8)
		depth = 8;
	else if (depth <= 16)
		depth = 16;
	else
		depth = 24;

	viafb_fill_var_color_info(var, depth);
206 207
	line = (var->xres_virtual * var->bits_per_pixel / 8 + 7) & ~7;
	if (line * var->yres_virtual > ppar->memsize)
J
Joseph Chan 已提交
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
		return -EINVAL;

	/* Based on var passed in to calculate the refresh,
	 * because our driver use some modes special.
	 */
	htotal = var->xres + var->left_margin +
	var->right_margin + var->hsync_len;
	vtotal = var->yres + var->upper_margin +
		var->lower_margin + var->vsync_len;
	long_refresh = 1000000000UL / var->pixclock * 1000;
	long_refresh /= (htotal * vtotal);

	viafb_refresh = viafb_get_refresh(var->xres, var->yres, long_refresh);

	/* Adjust var according to our driver's own table */
223
	viafb_fill_var_timing_info(var, viafb_refresh, vmode_entry);
224
	if (info->var.accel_flags & FB_ACCELF_TEXT &&
225
		!ppar->shared->vdev->engine_mmio)
226
		info->var.accel_flags = 0;
J
Joseph Chan 已提交
227 228 229 230 231 232

	return 0;
}

static int viafb_set_par(struct fb_info *info)
{
233
	struct viafb_par *viapar = info->par;
234
	struct VideoModeTable *vmode_entry, *vmode_entry1 = NULL;
J
Joseph Chan 已提交
235 236
	DEBUG_MSG(KERN_INFO "viafb_set_par!\n");

237
	viafb_update_fix(info);
238
	viapar->depth = fb_get_color_depth(&info->var, &info->fix);
239 240 241 242 243 244 245 246 247 248 249
	viafb_update_device_setting(viafbinfo->var.xres, viafbinfo->var.yres,
		viafbinfo->var.bits_per_pixel, viafb_refresh, 0);

	vmode_entry = viafb_get_mode(viafbinfo->var.xres, viafbinfo->var.yres);
	if (viafb_dual_fb) {
		vmode_entry1 = viafb_get_mode(viafbinfo1->var.xres,
			viafbinfo1->var.yres);
		viafb_update_device_setting(viafbinfo1->var.xres,
			viafbinfo1->var.yres, viafbinfo1->var.bits_per_pixel,
			viafb_refresh1, 1);
	} else if (viafb_SAMM_ON == 1) {
J
Joseph Chan 已提交
250 251 252
		DEBUG_MSG(KERN_INFO
		"viafb_second_xres = %d, viafb_second_yres = %d, bpp = %d\n",
			  viafb_second_xres, viafb_second_yres, viafb_bpp1);
253
		vmode_entry1 = viafb_get_mode(viafb_second_xres,
F
Florian Tobias Schandinat 已提交
254
			viafb_second_yres);
J
Joseph Chan 已提交
255 256 257 258 259

		viafb_update_device_setting(viafb_second_xres,
			viafb_second_yres, viafb_bpp1, viafb_refresh1, 1);
	}

260
	if (vmode_entry) {
261 262 263 264 265
		if (viafb_dual_fb && viapar->iga_path == IGA2)
			viafb_bpp1 = info->var.bits_per_pixel;
		else
			viafb_bpp = info->var.bits_per_pixel;

266 267 268 269
		if (info->var.accel_flags & FB_ACCELF_TEXT)
			info->flags &= ~FBINFO_HWACCEL_DISABLED;
		else
			info->flags |= FBINFO_HWACCEL_DISABLED;
270 271
		viafb_setmode(vmode_entry, info->var.bits_per_pixel,
			vmode_entry1, viafb_bpp1);
272
		viafb_pan_display(&info->var, info);
J
Joseph Chan 已提交
273 274 275 276 277 278 279 280 281
	}

	return 0;
}

/* Set one color register */
static int viafb_setcolreg(unsigned regno, unsigned red, unsigned green,
unsigned blue, unsigned transp, struct fb_info *info)
{
282 283
	struct viafb_par *viapar = info->par;
	u32 r, g, b;
J
Joseph Chan 已提交
284

285 286 287
	if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR) {
		if (regno > 255)
			return -EINVAL;
J
Joseph Chan 已提交
288

289 290 291
		if (!viafb_dual_fb || viapar->iga_path == IGA1)
			viafb_set_primary_color_register(regno, red >> 8,
				green >> 8, blue >> 8);
J
Joseph Chan 已提交
292

293 294 295 296 297 298
		if (!viafb_dual_fb || viapar->iga_path == IGA2)
			viafb_set_secondary_color_register(regno, red >> 8,
				green >> 8, blue >> 8);
	} else {
		if (regno > 15)
			return -EINVAL;
J
Joseph Chan 已提交
299

300 301 302 303 304 305 306
		r = (red >> (16 - info->var.red.length))
			<< info->var.red.offset;
		b = (blue >> (16 - info->var.blue.length))
			<< info->var.blue.offset;
		g = (green >> (16 - info->var.green.length))
			<< info->var.green.offset;
		((u32 *) info->pseudo_palette)[regno] = r | g | b;
J
Joseph Chan 已提交
307
	}
308

J
Joseph Chan 已提交
309 310 311 312 313 314
	return 0;
}

static int viafb_pan_display(struct fb_var_screeninfo *var,
	struct fb_info *info)
{
315 316 317 318 319 320
	struct viafb_par *viapar = info->par;
	u32 vram_addr = (var->yoffset * var->xres_virtual + var->xoffset)
		* (var->bits_per_pixel / 8) + viapar->vram_addr;

	DEBUG_MSG(KERN_DEBUG "viafb_pan_display, address = %d\n", vram_addr);
	if (!viafb_dual_fb) {
321 322
		via_set_primary_address(vram_addr);
		via_set_secondary_address(vram_addr);
323
	} else if (viapar->iga_path == IGA1)
324
		via_set_primary_address(vram_addr);
325
	else
326
		via_set_secondary_address(vram_addr);
J
Joseph Chan 已提交
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363

	return 0;
}

static int viafb_blank(int blank_mode, struct fb_info *info)
{
	DEBUG_MSG(KERN_INFO "viafb_blank!\n");
	/* clear DPMS setting */

	switch (blank_mode) {
	case FB_BLANK_UNBLANK:
		/* Screen: On, HSync: On, VSync: On */
		/* control CRT monitor power management */
		viafb_write_reg_mask(CR36, VIACR, 0x00, BIT4 + BIT5);
		break;
	case FB_BLANK_HSYNC_SUSPEND:
		/* Screen: Off, HSync: Off, VSync: On */
		/* control CRT monitor power management */
		viafb_write_reg_mask(CR36, VIACR, 0x10, BIT4 + BIT5);
		break;
	case FB_BLANK_VSYNC_SUSPEND:
		/* Screen: Off, HSync: On, VSync: Off */
		/* control CRT monitor power management */
		viafb_write_reg_mask(CR36, VIACR, 0x20, BIT4 + BIT5);
		break;
	case FB_BLANK_POWERDOWN:
		/* Screen: Off, HSync: Off, VSync: Off */
		/* control CRT monitor power management */
		viafb_write_reg_mask(CR36, VIACR, 0x30, BIT4 + BIT5);
		break;
	}

	return 0;
}

static int viafb_ioctl(struct fb_info *info, u_int cmd, u_long arg)
{
364 365 366 367 368 369 370 371 372
	union {
		struct viafb_ioctl_mode viamode;
		struct viafb_ioctl_samm viasamm;
		struct viafb_driver_version driver_version;
		struct fb_var_screeninfo sec_var;
		struct _panel_size_pos_info panel_pos_size_para;
		struct viafb_ioctl_setting viafb_setting;
		struct device_t active_dev;
	} u;
J
Joseph Chan 已提交
373 374 375 376 377 378 379 380
	u32 state_info = 0;
	u32 *viafb_gamma_table;
	char driver_name[] = "viafb";

	u32 __user *argp = (u32 __user *) arg;
	u32 gpu32;

	DEBUG_MSG(KERN_INFO "viafb_ioctl: 0x%X !!\n", cmd);
381
	printk(KERN_WARNING "viafb_ioctl: Please avoid this interface as it is unstable and might change or vanish at any time!\n");
382
	memset(&u, 0, sizeof(u));
J
Joseph Chan 已提交
383 384 385 386 387 388 389 390

	switch (cmd) {
	case VIAFB_GET_CHIP_INFO:
		if (copy_to_user(argp, viaparinfo->chip_info,
				sizeof(struct chip_information)))
			return -EFAULT;
		break;
	case VIAFB_GET_INFO_SIZE:
391
		return put_user((u32)sizeof(struct viafb_ioctl_info), argp);
J
Joseph Chan 已提交
392 393 394 395 396 397 398 399 400 401 402 403
	case VIAFB_GET_INFO:
		return viafb_ioctl_get_viafb_info(arg);
	case VIAFB_HOTPLUG:
		return put_user(viafb_ioctl_hotplug(info->var.xres,
					      info->var.yres,
					      info->var.bits_per_pixel), argp);
	case VIAFB_SET_HOTPLUG_FLAG:
		if (copy_from_user(&gpu32, argp, sizeof(gpu32)))
			return -EFAULT;
		viafb_hotplug = (gpu32) ? 1 : 0;
		break;
	case VIAFB_GET_RESOLUTION:
404 405 406 407
		u.viamode.xres = (u32) viafb_hotplug_Xres;
		u.viamode.yres = (u32) viafb_hotplug_Yres;
		u.viamode.refresh = (u32) viafb_hotplug_refresh;
		u.viamode.bpp = (u32) viafb_hotplug_bpp;
J
Joseph Chan 已提交
408
		if (viafb_SAMM_ON == 1) {
409 410 411 412 413 414
			u.viamode.xres_sec = viafb_second_xres;
			u.viamode.yres_sec = viafb_second_yres;
			u.viamode.virtual_xres_sec = viafb_second_virtual_xres;
			u.viamode.virtual_yres_sec = viafb_second_virtual_yres;
			u.viamode.refresh_sec = viafb_refresh1;
			u.viamode.bpp_sec = viafb_bpp1;
J
Joseph Chan 已提交
415
		} else {
416 417 418 419 420 421
			u.viamode.xres_sec = 0;
			u.viamode.yres_sec = 0;
			u.viamode.virtual_xres_sec = 0;
			u.viamode.virtual_yres_sec = 0;
			u.viamode.refresh_sec = 0;
			u.viamode.bpp_sec = 0;
J
Joseph Chan 已提交
422
		}
423
		if (copy_to_user(argp, &u.viamode, sizeof(u.viamode)))
J
Joseph Chan 已提交
424 425 426
			return -EFAULT;
		break;
	case VIAFB_GET_SAMM_INFO:
427
		u.viasamm.samm_status = viafb_SAMM_ON;
J
Joseph Chan 已提交
428 429 430

		if (viafb_SAMM_ON == 1) {
			if (viafb_dual_fb) {
431 432
				u.viasamm.size_prim = viaparinfo->fbmem_free;
				u.viasamm.size_sec = viaparinfo1->fbmem_free;
J
Joseph Chan 已提交
433 434
			} else {
				if (viafb_second_size) {
435
					u.viasamm.size_prim =
J
Joseph Chan 已提交
436 437
					    viaparinfo->fbmem_free -
					    viafb_second_size * 1024 * 1024;
438
					u.viasamm.size_sec =
J
Joseph Chan 已提交
439 440
					    viafb_second_size * 1024 * 1024;
				} else {
441
					u.viasamm.size_prim =
J
Joseph Chan 已提交
442
					    viaparinfo->fbmem_free >> 1;
443
					u.viasamm.size_sec =
J
Joseph Chan 已提交
444 445 446
					    (viaparinfo->fbmem_free >> 1);
				}
			}
447 448
			u.viasamm.mem_base = viaparinfo->fbmem;
			u.viasamm.offset_sec = viafb_second_offset;
J
Joseph Chan 已提交
449
		} else {
450
			u.viasamm.size_prim =
J
Joseph Chan 已提交
451
			    viaparinfo->memsize - viaparinfo->fbmem_used;
452 453 454
			u.viasamm.size_sec = 0;
			u.viasamm.mem_base = viaparinfo->fbmem;
			u.viasamm.offset_sec = 0;
J
Joseph Chan 已提交
455 456
		}

457
		if (copy_to_user(argp, &u.viasamm, sizeof(u.viasamm)))
J
Joseph Chan 已提交
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481
			return -EFAULT;

		break;
	case VIAFB_TURN_ON_OUTPUT_DEVICE:
		if (copy_from_user(&gpu32, argp, sizeof(gpu32)))
			return -EFAULT;
		if (gpu32 & CRT_Device)
			viafb_crt_enable();
		if (gpu32 & DVI_Device)
			viafb_dvi_enable();
		if (gpu32 & LCD_Device)
			viafb_lcd_enable();
		break;
	case VIAFB_TURN_OFF_OUTPUT_DEVICE:
		if (copy_from_user(&gpu32, argp, sizeof(gpu32)))
			return -EFAULT;
		if (gpu32 & CRT_Device)
			viafb_crt_disable();
		if (gpu32 & DVI_Device)
			viafb_dvi_disable();
		if (gpu32 & LCD_Device)
			viafb_lcd_disable();
		break;
	case VIAFB_SET_DEVICE:
482 483
		if (copy_from_user(&u.active_dev, (void *)argp,
			sizeof(u.active_dev)))
J
Joseph Chan 已提交
484
			return -EFAULT;
485
		viafb_set_device(u.active_dev);
J
Joseph Chan 已提交
486 487 488
		viafb_set_par(info);
		break;
	case VIAFB_GET_DEVICE:
489 490 491 492 493
		u.active_dev.crt = viafb_CRT_ON;
		u.active_dev.dvi = viafb_DVI_ON;
		u.active_dev.lcd = viafb_LCD_ON;
		u.active_dev.samm = viafb_SAMM_ON;
		u.active_dev.primary_dev = viafb_primary_dev;
J
Joseph Chan 已提交
494

495 496 497
		u.active_dev.lcd_dsp_cent = viafb_lcd_dsp_method;
		u.active_dev.lcd_panel_id = viafb_lcd_panel_id;
		u.active_dev.lcd_mode = viafb_lcd_mode;
J
Joseph Chan 已提交
498

499 500
		u.active_dev.xres = viafb_hotplug_Xres;
		u.active_dev.yres = viafb_hotplug_Yres;
J
Joseph Chan 已提交
501

502 503
		u.active_dev.xres1 = viafb_second_xres;
		u.active_dev.yres1 = viafb_second_yres;
J
Joseph Chan 已提交
504

505 506 507 508
		u.active_dev.bpp = viafb_bpp;
		u.active_dev.bpp1 = viafb_bpp1;
		u.active_dev.refresh = viafb_refresh;
		u.active_dev.refresh1 = viafb_refresh1;
J
Joseph Chan 已提交
509

510 511 512
		u.active_dev.epia_dvi = viafb_platform_epia_dvi;
		u.active_dev.lcd_dual_edge = viafb_device_lcd_dualedge;
		u.active_dev.bus_width = viafb_bus_width;
J
Joseph Chan 已提交
513

514
		if (copy_to_user(argp, &u.active_dev, sizeof(u.active_dev)))
J
Joseph Chan 已提交
515 516 517 518
			return -EFAULT;
		break;

	case VIAFB_GET_DRIVER_VERSION:
519 520 521 522
		u.driver_version.iMajorNum = VERSION_MAJOR;
		u.driver_version.iKernelNum = VERSION_KERNEL;
		u.driver_version.iOSNum = VERSION_OS;
		u.driver_version.iMinorNum = VERSION_MINOR;
J
Joseph Chan 已提交
523

524 525
		if (copy_to_user(argp, &u.driver_version,
			sizeof(u.driver_version)))
J
Joseph Chan 已提交
526 527 528 529 530
			return -EFAULT;

		break;

	case VIAFB_SET_DEVICE_INFO:
531 532
		if (copy_from_user(&u.viafb_setting,
			argp, sizeof(u.viafb_setting)))
J
Joseph Chan 已提交
533
			return -EFAULT;
534
		if (apply_device_setting(u.viafb_setting, info) < 0)
J
Joseph Chan 已提交
535 536 537 538 539
			return -EINVAL;

		break;

	case VIAFB_SET_SECOND_MODE:
540
		if (copy_from_user(&u.sec_var, argp, sizeof(u.sec_var)))
J
Joseph Chan 已提交
541
			return -EFAULT;
542
		apply_second_mode_setting(&u.sec_var);
J
Joseph Chan 已提交
543 544 545 546
		break;

	case VIAFB_GET_DEVICE_INFO:

547
		retrieve_device_setting(&u.viafb_setting);
J
Joseph Chan 已提交
548

549 550
		if (copy_to_user(argp, &u.viafb_setting,
				 sizeof(u.viafb_setting)))
J
Joseph Chan 已提交
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580
			return -EFAULT;

		break;

	case VIAFB_GET_DEVICE_SUPPORT:
		viafb_get_device_support_state(&state_info);
		if (put_user(state_info, argp))
			return -EFAULT;
		break;

	case VIAFB_GET_DEVICE_CONNECT:
		viafb_get_device_connect_state(&state_info);
		if (put_user(state_info, argp))
			return -EFAULT;
		break;

	case VIAFB_GET_PANEL_SUPPORT_EXPAND:
		state_info =
		    viafb_lcd_get_support_expand_state(info->var.xres,
						 info->var.yres);
		if (put_user(state_info, argp))
			return -EFAULT;
		break;

	case VIAFB_GET_DRIVER_NAME:
		if (copy_to_user(argp, driver_name, sizeof(driver_name)))
			return -EFAULT;
		break;

	case VIAFB_SET_GAMMA_LUT:
581 582 583
		viafb_gamma_table = memdup_user(argp, 256 * sizeof(u32));
		if (IS_ERR(viafb_gamma_table))
			return PTR_ERR(viafb_gamma_table);
J
Joseph Chan 已提交
584 585 586 587 588 589 590 591 592 593
		viafb_set_gamma_table(viafb_bpp, viafb_gamma_table);
		kfree(viafb_gamma_table);
		break;

	case VIAFB_GET_GAMMA_LUT:
		viafb_gamma_table = kmalloc(256 * sizeof(u32), GFP_KERNEL);
		if (!viafb_gamma_table)
			return -ENOMEM;
		viafb_get_gamma_table(viafb_gamma_table);
		if (copy_to_user(argp, viafb_gamma_table,
594
			256 * sizeof(u32))) {
J
Joseph Chan 已提交
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612
			kfree(viafb_gamma_table);
			return -EFAULT;
		}
		kfree(viafb_gamma_table);
		break;

	case VIAFB_GET_GAMMA_SUPPORT_STATE:
		viafb_get_gamma_support_state(viafb_bpp, &state_info);
		if (put_user(state_info, argp))
			return -EFAULT;
		break;
	case VIAFB_SYNC_SURFACE:
		DEBUG_MSG(KERN_INFO "lobo VIAFB_SYNC_SURFACE\n");
		break;
	case VIAFB_GET_DRIVER_CAPS:
		break;

	case VIAFB_GET_PANEL_MAX_SIZE:
613 614
		if (copy_from_user(&u.panel_pos_size_para, argp,
				   sizeof(u.panel_pos_size_para)))
J
Joseph Chan 已提交
615
			return -EFAULT;
616 617 618
		u.panel_pos_size_para.x = u.panel_pos_size_para.y = 0;
		if (copy_to_user(argp, &u.panel_pos_size_para,
		     sizeof(u.panel_pos_size_para)))
J
Joseph Chan 已提交
619 620 621
			return -EFAULT;
		break;
	case VIAFB_GET_PANEL_MAX_POSITION:
622 623
		if (copy_from_user(&u.panel_pos_size_para, argp,
				   sizeof(u.panel_pos_size_para)))
J
Joseph Chan 已提交
624
			return -EFAULT;
625 626 627
		u.panel_pos_size_para.x = u.panel_pos_size_para.y = 0;
		if (copy_to_user(argp, &u.panel_pos_size_para,
				 sizeof(u.panel_pos_size_para)))
J
Joseph Chan 已提交
628 629 630 631
			return -EFAULT;
		break;

	case VIAFB_GET_PANEL_POSITION:
632 633
		if (copy_from_user(&u.panel_pos_size_para, argp,
				   sizeof(u.panel_pos_size_para)))
J
Joseph Chan 已提交
634
			return -EFAULT;
635 636 637
		u.panel_pos_size_para.x = u.panel_pos_size_para.y = 0;
		if (copy_to_user(argp, &u.panel_pos_size_para,
				 sizeof(u.panel_pos_size_para)))
J
Joseph Chan 已提交
638 639 640
			return -EFAULT;
		break;
	case VIAFB_GET_PANEL_SIZE:
641 642
		if (copy_from_user(&u.panel_pos_size_para, argp,
				   sizeof(u.panel_pos_size_para)))
J
Joseph Chan 已提交
643
			return -EFAULT;
644 645 646
		u.panel_pos_size_para.x = u.panel_pos_size_para.y = 0;
		if (copy_to_user(argp, &u.panel_pos_size_para,
				 sizeof(u.panel_pos_size_para)))
J
Joseph Chan 已提交
647 648 649 650
			return -EFAULT;
		break;

	case VIAFB_SET_PANEL_POSITION:
651 652
		if (copy_from_user(&u.panel_pos_size_para, argp,
				   sizeof(u.panel_pos_size_para)))
J
Joseph Chan 已提交
653 654 655
			return -EFAULT;
		break;
	case VIAFB_SET_PANEL_SIZE:
656 657
		if (copy_from_user(&u.panel_pos_size_para, argp,
				   sizeof(u.panel_pos_size_para)))
J
Joseph Chan 已提交
658 659 660 661 662 663 664 665 666 667 668 669 670
			return -EFAULT;
		break;

	default:
		return -EINVAL;
	}

	return 0;
}

static void viafb_fillrect(struct fb_info *info,
	const struct fb_fillrect *rect)
{
671
	struct viafb_par *viapar = info->par;
672
	struct viafb_shared *shared = viapar->shared;
673 674
	u32 fg_color;
	u8 rop;
J
Joseph Chan 已提交
675

676
	if (info->flags & FBINFO_HWACCEL_DISABLED || !shared->hw_bitblt) {
H
Hannes Eder 已提交
677 678 679
		cfb_fillrect(info, rect);
		return;
	}
J
Joseph Chan 已提交
680 681 682 683

	if (!rect->width || !rect->height)
		return;

684 685 686 687 688 689
	if (info->fix.visual == FB_VISUAL_TRUECOLOR)
		fg_color = ((u32 *)info->pseudo_palette)[rect->color];
	else
		fg_color = rect->color;

	if (rect->rop == ROP_XOR)
J
Joseph Chan 已提交
690
		rop = 0x5A;
691
	else
J
Joseph Chan 已提交
692 693
		rop = 0xF0;

694
	DEBUG_MSG(KERN_DEBUG "viafb 2D engine: fillrect\n");
695
	if (shared->hw_bitblt(shared->vdev->engine_mmio, VIA_BITBLT_FILL,
696 697 698 699
		rect->width, rect->height, info->var.bits_per_pixel,
		viapar->vram_addr, info->fix.line_length, rect->dx, rect->dy,
		NULL, 0, 0, 0, 0, fg_color, 0, rop))
		cfb_fillrect(info, rect);
J
Joseph Chan 已提交
700 701 702 703 704
}

static void viafb_copyarea(struct fb_info *info,
	const struct fb_copyarea *area)
{
705
	struct viafb_par *viapar = info->par;
706
	struct viafb_shared *shared = viapar->shared;
J
Joseph Chan 已提交
707

708
	if (info->flags & FBINFO_HWACCEL_DISABLED || !shared->hw_bitblt) {
H
Hannes Eder 已提交
709 710 711
		cfb_copyarea(info, area);
		return;
	}
J
Joseph Chan 已提交
712 713 714 715

	if (!area->width || !area->height)
		return;

716
	DEBUG_MSG(KERN_DEBUG "viafb 2D engine: copyarea\n");
717
	if (shared->hw_bitblt(shared->vdev->engine_mmio, VIA_BITBLT_COLOR,
718 719 720 721 722
		area->width, area->height, info->var.bits_per_pixel,
		viapar->vram_addr, info->fix.line_length, area->dx, area->dy,
		NULL, viapar->vram_addr, info->fix.line_length,
		area->sx, area->sy, 0, 0, 0))
		cfb_copyarea(info, area);
J
Joseph Chan 已提交
723 724 725 726 727
}

static void viafb_imageblit(struct fb_info *info,
	const struct fb_image *image)
{
728
	struct viafb_par *viapar = info->par;
729
	struct viafb_shared *shared = viapar->shared;
730 731
	u32 fg_color = 0, bg_color = 0;
	u8 op;
J
Joseph Chan 已提交
732

733
	if (info->flags & FBINFO_HWACCEL_DISABLED || !shared->hw_bitblt ||
734
		(image->depth != 1 && image->depth != viapar->depth)) {
H
Hannes Eder 已提交
735 736 737
		cfb_imageblit(info, image);
		return;
	}
J
Joseph Chan 已提交
738

739 740 741 742 743 744 745 746 747 748 749 750 751
	if (image->depth == 1) {
		op = VIA_BITBLT_MONO;
		if (info->fix.visual == FB_VISUAL_TRUECOLOR) {
			fg_color =
				((u32 *)info->pseudo_palette)[image->fg_color];
			bg_color =
				((u32 *)info->pseudo_palette)[image->bg_color];
		} else {
			fg_color = image->fg_color;
			bg_color = image->bg_color;
		}
	} else
		op = VIA_BITBLT_COLOR;
J
Joseph Chan 已提交
752

753
	DEBUG_MSG(KERN_DEBUG "viafb 2D engine: imageblit\n");
754
	if (shared->hw_bitblt(shared->vdev->engine_mmio, op,
755 756 757 758
		image->width, image->height, info->var.bits_per_pixel,
		viapar->vram_addr, info->fix.line_length, image->dx, image->dy,
		(u32 *)image->data, 0, 0, 0, 0, fg_color, bg_color, 0))
		cfb_imageblit(info, image);
J
Joseph Chan 已提交
759 760 761 762
}

static int viafb_cursor(struct fb_info *info, struct fb_cursor *cursor)
{
763
	struct viafb_par *viapar = info->par;
764
	void __iomem *engine = viapar->shared->vdev->engine_mmio;
765 766 767
	u32 temp, xx, yy, bg_color = 0, fg_color = 0,
		chip_name = viapar->shared->chip_info.gfx_chip_name;
	int i, j = 0, cur_size = 64;
J
Joseph Chan 已提交
768

769
	if (info->flags & FBINFO_HWACCEL_DISABLED || info != viafbinfo)
J
Joseph Chan 已提交
770 771
		return -ENODEV;

772 773 774
	/* LCD ouput does not support hw cursors (at least on VN896) */
	if ((chip_name == UNICHROME_CLE266 && viapar->iga_path == IGA2) ||
		viafb_LCD_ON)
J
Joseph Chan 已提交
775 776 777 778 779
		return -ENODEV;

	viafb_show_hw_cursor(info, HW_Cursor_OFF);

	if (cursor->set & FB_CUR_SETHOT) {
780
		temp = (cursor->hot.x << 16) + cursor->hot.y;
781
		writel(temp, engine + VIA_REG_CURSOR_ORG);
J
Joseph Chan 已提交
782 783 784 785 786 787 788
	}

	if (cursor->set & FB_CUR_SETPOS) {
		yy = cursor->image.dy - info->var.yoffset;
		xx = cursor->image.dx - info->var.xoffset;
		temp = yy & 0xFFFF;
		temp |= (xx << 16);
789
		writel(temp, engine + VIA_REG_CURSOR_POS);
J
Joseph Chan 已提交
790 791
	}

792 793 794 795 796 797 798 799 800
	if (cursor->image.width <= 32 && cursor->image.height <= 32)
		cur_size = 32;
	else if (cursor->image.width <= 64 && cursor->image.height <= 64)
		cur_size = 64;
	else {
		printk(KERN_WARNING "viafb_cursor: The cursor is too large "
			"%dx%d", cursor->image.width, cursor->image.height);
		return -ENXIO;
	}
J
Joseph Chan 已提交
801

802
	if (cursor->set & FB_CUR_SETSIZE) {
803
		temp = readl(engine + VIA_REG_CURSOR_MODE);
804
		if (cur_size == 32)
J
Joseph Chan 已提交
805
			temp |= 0x2;
806 807
		else
			temp &= ~0x2;
J
Joseph Chan 已提交
808

809
		writel(temp, engine + VIA_REG_CURSOR_MODE);
J
Joseph Chan 已提交
810 811 812
	}

	if (cursor->set & FB_CUR_SETCMAP) {
813 814 815
		fg_color = cursor->image.fg_color;
		bg_color = cursor->image.bg_color;
		if (chip_name == UNICHROME_CX700 ||
816 817
			chip_name == UNICHROME_VX800 ||
			chip_name == UNICHROME_VX855) {
818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834
			fg_color =
				((info->cmap.red[fg_color] & 0xFFC0) << 14) |
				((info->cmap.green[fg_color] & 0xFFC0) << 4) |
				((info->cmap.blue[fg_color] & 0xFFC0) >> 6);
			bg_color =
				((info->cmap.red[bg_color] & 0xFFC0) << 14) |
				((info->cmap.green[bg_color] & 0xFFC0) << 4) |
				((info->cmap.blue[bg_color] & 0xFFC0) >> 6);
		} else {
			fg_color =
				((info->cmap.red[fg_color] & 0xFF00) << 8) |
				(info->cmap.green[fg_color] & 0xFF00) |
				((info->cmap.blue[fg_color] & 0xFF00) >> 8);
			bg_color =
				((info->cmap.red[bg_color] & 0xFF00) << 8) |
				(info->cmap.green[bg_color] & 0xFF00) |
				((info->cmap.blue[bg_color] & 0xFF00) >> 8);
J
Joseph Chan 已提交
835 836
		}

837 838
		writel(bg_color, engine + VIA_REG_CURSOR_BG);
		writel(fg_color, engine + VIA_REG_CURSOR_FG);
J
Joseph Chan 已提交
839 840 841
	}

	if (cursor->set & FB_CUR_SETSHAPE) {
842
		struct {
843 844
			u8 data[CURSOR_SIZE];
			u32 bak[CURSOR_SIZE / 4];
845
		} *cr_data = kzalloc(sizeof(*cr_data), GFP_ATOMIC);
846 847
		int size = ((cursor->image.width + 7) >> 3) *
			cursor->image.height;
J
Joseph Chan 已提交
848

849 850
		if (!cr_data)
			return -ENOMEM;
851

852 853
		if (cur_size == 32) {
			for (i = 0; i < (CURSOR_SIZE / 4); i++) {
854 855
				cr_data->bak[i] = 0x0;
				cr_data->bak[i + 1] = 0xFFFFFFFF;
J
Joseph Chan 已提交
856 857
				i += 1;
			}
858 859
		} else {
			for (i = 0; i < (CURSOR_SIZE / 4); i++) {
860 861 862 863
				cr_data->bak[i] = 0x0;
				cr_data->bak[i + 1] = 0x0;
				cr_data->bak[i + 2] = 0xFFFFFFFF;
				cr_data->bak[i + 3] = 0xFFFFFFFF;
J
Joseph Chan 已提交
864 865 866 867
				i += 3;
			}
		}

868
		switch (cursor->rop) {
J
Joseph Chan 已提交
869 870
		case ROP_XOR:
			for (i = 0; i < size; i++)
871
				cr_data->data[i] = cursor->mask[i];
J
Joseph Chan 已提交
872 873 874 875
			break;
		case ROP_COPY:

			for (i = 0; i < size; i++)
876
				cr_data->data[i] = cursor->mask[i];
J
Joseph Chan 已提交
877 878 879 880 881
			break;
		default:
			break;
		}

882
		if (cur_size == 32) {
J
Joseph Chan 已提交
883
			for (i = 0; i < size; i++) {
884 885
				cr_data->bak[j] = (u32) cr_data->data[i];
				cr_data->bak[j + 1] = ~cr_data->bak[j];
J
Joseph Chan 已提交
886 887
				j += 2;
			}
888
		} else {
J
Joseph Chan 已提交
889
			for (i = 0; i < size; i++) {
890 891 892 893
				cr_data->bak[j] = (u32) cr_data->data[i];
				cr_data->bak[j + 1] = 0x0;
				cr_data->bak[j + 2] = ~cr_data->bak[j];
				cr_data->bak[j + 3] = ~cr_data->bak[j + 1];
J
Joseph Chan 已提交
894 895 896 897
				j += 4;
			}
		}

898 899
		memcpy_toio(viafbinfo->screen_base + viapar->shared->
			cursor_vram_addr, cr_data->bak, CURSOR_SIZE);
900
		kfree(cr_data);
J
Joseph Chan 已提交
901 902
	}

903
	if (cursor->enable)
J
Joseph Chan 已提交
904 905 906 907 908 909 910
		viafb_show_hw_cursor(info, HW_Cursor_ON);

	return 0;
}

static int viafb_sync(struct fb_info *info)
{
911 912
	if (!(info->flags & FBINFO_HWACCEL_DISABLED))
		viafb_wait_engine_idle(info);
J
Joseph Chan 已提交
913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016
	return 0;
}

static void check_available_device_to_enable(int device_id)
{
	int device_num = 0;

	/* Initialize: */
	viafb_CRT_ON = STATE_OFF;
	viafb_DVI_ON = STATE_OFF;
	viafb_LCD_ON = STATE_OFF;
	viafb_LCD2_ON = STATE_OFF;
	viafb_DeviceStatus = None_Device;

	if ((device_id & CRT_Device) && (device_num < MAX_ACTIVE_DEV_NUM)) {
		viafb_CRT_ON = STATE_ON;
		device_num++;
		viafb_DeviceStatus |= CRT_Device;
	}

	if ((device_id & DVI_Device) && (device_num < MAX_ACTIVE_DEV_NUM)) {
		viafb_DVI_ON = STATE_ON;
		device_num++;
		viafb_DeviceStatus |= DVI_Device;
	}

	if ((device_id & LCD_Device) && (device_num < MAX_ACTIVE_DEV_NUM)) {
		viafb_LCD_ON = STATE_ON;
		device_num++;
		viafb_DeviceStatus |= LCD_Device;
	}

	if ((device_id & LCD2_Device) && (device_num < MAX_ACTIVE_DEV_NUM)) {
		viafb_LCD2_ON = STATE_ON;
		device_num++;
		viafb_DeviceStatus |= LCD2_Device;
	}

	if (viafb_DeviceStatus == None_Device) {
		/* Use CRT as default active device: */
		viafb_CRT_ON = STATE_ON;
		viafb_DeviceStatus = CRT_Device;
	}
	DEBUG_MSG(KERN_INFO "Device Status:%x", viafb_DeviceStatus);
}

static void viafb_set_device(struct device_t active_dev)
{
	/* Check available device to enable: */
	int device_id = None_Device;
	if (active_dev.crt)
		device_id |= CRT_Device;
	if (active_dev.dvi)
		device_id |= DVI_Device;
	if (active_dev.lcd)
		device_id |= LCD_Device;

	check_available_device_to_enable(device_id);

	/* Check property of LCD: */
	if (viafb_LCD_ON) {
		if (active_dev.lcd_dsp_cent) {
			viaparinfo->lvds_setting_info->display_method =
				viafb_lcd_dsp_method = LCD_CENTERING;
		} else {
			viaparinfo->lvds_setting_info->display_method =
				viafb_lcd_dsp_method = LCD_EXPANDSION;
		}

		if (active_dev.lcd_mode == LCD_SPWG) {
			viaparinfo->lvds_setting_info->lcd_mode =
				viafb_lcd_mode = LCD_SPWG;
		} else {
			viaparinfo->lvds_setting_info->lcd_mode =
				viafb_lcd_mode = LCD_OPENLDI;
		}

		if (active_dev.lcd_panel_id <= LCD_PANEL_ID_MAXIMUM) {
			viafb_lcd_panel_id = active_dev.lcd_panel_id;
			viafb_init_lcd_size();
		}
	}

	/* Check property of mode: */
	if (!active_dev.xres1)
		viafb_second_xres = 640;
	else
		viafb_second_xres = active_dev.xres1;
	if (!active_dev.yres1)
		viafb_second_yres = 480;
	else
		viafb_second_yres = active_dev.yres1;
	if (active_dev.bpp != 0)
		viafb_bpp = active_dev.bpp;
	if (active_dev.bpp1 != 0)
		viafb_bpp1 = active_dev.bpp1;
	if (active_dev.refresh != 0)
		viafb_refresh = active_dev.refresh;
	if (active_dev.refresh1 != 0)
		viafb_refresh1 = active_dev.refresh1;
	if ((active_dev.samm == STATE_OFF) || (active_dev.samm == STATE_ON))
		viafb_SAMM_ON = active_dev.samm;
	viafb_primary_dev = active_dev.primary_dev;

1017 1018
	via_set_primary_address(0);
	via_set_secondary_address(viafb_SAMM_ON ? viafb_second_offset : 0);
J
Joseph Chan 已提交
1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163
	viafb_set_iga_path();
}

static int get_primary_device(void)
{
	int primary_device = 0;
	/* Rule: device on iga1 path are the primary device. */
	if (viafb_SAMM_ON) {
		if (viafb_CRT_ON) {
			if (viaparinfo->crt_setting_info->iga_path == IGA1) {
				DEBUG_MSG(KERN_INFO "CRT IGA Path:%d\n",
					viaparinfo->
					crt_setting_info->iga_path);
				primary_device = CRT_Device;
			}
		}
		if (viafb_DVI_ON) {
			if (viaparinfo->tmds_setting_info->iga_path == IGA1) {
				DEBUG_MSG(KERN_INFO "DVI IGA Path:%d\n",
					viaparinfo->
					tmds_setting_info->iga_path);
				primary_device = DVI_Device;
			}
		}
		if (viafb_LCD_ON) {
			if (viaparinfo->lvds_setting_info->iga_path == IGA1) {
				DEBUG_MSG(KERN_INFO "LCD IGA Path:%d\n",
					viaparinfo->
					lvds_setting_info->iga_path);
				primary_device = LCD_Device;
			}
		}
		if (viafb_LCD2_ON) {
			if (viaparinfo->lvds_setting_info2->iga_path == IGA1) {
				DEBUG_MSG(KERN_INFO "LCD2 IGA Path:%d\n",
					viaparinfo->
					lvds_setting_info2->iga_path);
				primary_device = LCD2_Device;
			}
		}
	}
	return primary_device;
}

static void apply_second_mode_setting(struct fb_var_screeninfo
	*sec_var)
{
	u32 htotal, vtotal, long_refresh;

	htotal = sec_var->xres + sec_var->left_margin +
		sec_var->right_margin + sec_var->hsync_len;
	vtotal = sec_var->yres + sec_var->upper_margin +
		sec_var->lower_margin + sec_var->vsync_len;
	if ((sec_var->xres_virtual * (sec_var->bits_per_pixel >> 3)) & 0x1F) {
		/*Is 32 bytes alignment? */
		/*32 pixel alignment */
		sec_var->xres_virtual = (sec_var->xres_virtual + 31) & ~31;
	}

	htotal = sec_var->xres + sec_var->left_margin +
		sec_var->right_margin + sec_var->hsync_len;
	vtotal = sec_var->yres + sec_var->upper_margin +
		sec_var->lower_margin + sec_var->vsync_len;
	long_refresh = 1000000000UL / sec_var->pixclock * 1000;
	long_refresh /= (htotal * vtotal);

	viafb_second_xres = sec_var->xres;
	viafb_second_yres = sec_var->yres;
	viafb_second_virtual_xres = sec_var->xres_virtual;
	viafb_second_virtual_yres = sec_var->yres_virtual;
	viafb_bpp1 = sec_var->bits_per_pixel;
	viafb_refresh1 = viafb_get_refresh(sec_var->xres, sec_var->yres,
		long_refresh);
}

static int apply_device_setting(struct viafb_ioctl_setting setting_info,
	struct fb_info *info)
{
	int need_set_mode = 0;
	DEBUG_MSG(KERN_INFO "apply_device_setting\n");

	if (setting_info.device_flag) {
		need_set_mode = 1;
		check_available_device_to_enable(setting_info.device_status);
	}

	/* Unlock LCD's operation according to LCD flag
	   and check if the setting value is valid. */
	/* If the value is valid, apply the new setting value to the device. */
	if (viafb_LCD_ON) {
		if (setting_info.lcd_operation_flag & OP_LCD_CENTERING) {
			need_set_mode = 1;
			if (setting_info.lcd_attributes.display_center) {
				/* Centering */
				viaparinfo->lvds_setting_info->display_method =
				    LCD_CENTERING;
				viafb_lcd_dsp_method = LCD_CENTERING;
				viaparinfo->lvds_setting_info2->display_method =
				    viafb_lcd_dsp_method = LCD_CENTERING;
			} else {
				/* expandsion */
				viaparinfo->lvds_setting_info->display_method =
				    LCD_EXPANDSION;
				viafb_lcd_dsp_method = LCD_EXPANDSION;
				viaparinfo->lvds_setting_info2->display_method =
				    LCD_EXPANDSION;
				viafb_lcd_dsp_method = LCD_EXPANDSION;
			}
		}

		if (setting_info.lcd_operation_flag & OP_LCD_MODE) {
			need_set_mode = 1;
			if (setting_info.lcd_attributes.lcd_mode ==
				LCD_SPWG) {
				viaparinfo->lvds_setting_info->lcd_mode =
					viafb_lcd_mode = LCD_SPWG;
			} else {
				viaparinfo->lvds_setting_info->lcd_mode =
					viafb_lcd_mode = LCD_OPENLDI;
			}
			viaparinfo->lvds_setting_info2->lcd_mode =
			    viaparinfo->lvds_setting_info->lcd_mode;
		}

		if (setting_info.lcd_operation_flag & OP_LCD_PANEL_ID) {
			need_set_mode = 1;
			if (setting_info.lcd_attributes.panel_id <=
			    LCD_PANEL_ID_MAXIMUM) {
				viafb_lcd_panel_id =
				    setting_info.lcd_attributes.panel_id;
				viafb_init_lcd_size();
			}
		}
	}

	if (0 != (setting_info.samm_status & OP_SAMM)) {
		setting_info.samm_status =
		    setting_info.samm_status & (~OP_SAMM);
		if (setting_info.samm_status == 0
		    || setting_info.samm_status == 1) {
			viafb_SAMM_ON = setting_info.samm_status;

			if (viafb_SAMM_ON)
				viafb_primary_dev = setting_info.primary_device;

1164 1165 1166
			via_set_primary_address(0);
			via_set_secondary_address(viafb_SAMM_ON ?
				viafb_second_offset : 0);
J
Joseph Chan 已提交
1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214
			viafb_set_iga_path();
		}
		need_set_mode = 1;
	}

	if (!need_set_mode) {
		;
	} else {
		viafb_set_iga_path();
		viafb_set_par(info);
	}
	return true;
}

static void retrieve_device_setting(struct viafb_ioctl_setting
	*setting_info)
{

	/* get device status */
	if (viafb_CRT_ON == 1)
		setting_info->device_status = CRT_Device;
	if (viafb_DVI_ON == 1)
		setting_info->device_status |= DVI_Device;
	if (viafb_LCD_ON == 1)
		setting_info->device_status |= LCD_Device;
	if (viafb_LCD2_ON == 1)
		setting_info->device_status |= LCD2_Device;

	setting_info->samm_status = viafb_SAMM_ON;
	setting_info->primary_device = get_primary_device();

	setting_info->first_dev_bpp = viafb_bpp;
	setting_info->second_dev_bpp = viafb_bpp1;

	setting_info->first_dev_refresh = viafb_refresh;
	setting_info->second_dev_refresh = viafb_refresh1;

	setting_info->first_dev_hor_res = viafb_hotplug_Xres;
	setting_info->first_dev_ver_res = viafb_hotplug_Yres;
	setting_info->second_dev_hor_res = viafb_second_xres;
	setting_info->second_dev_ver_res = viafb_second_yres;

	/* Get lcd attributes */
	setting_info->lcd_attributes.display_center = viafb_lcd_dsp_method;
	setting_info->lcd_attributes.panel_id = viafb_lcd_panel_id;
	setting_info->lcd_attributes.lcd_mode = viafb_lcd_mode;
}

1215
static int parse_active_dev(void)
J
Joseph Chan 已提交
1216 1217 1218 1219 1220 1221 1222 1223 1224 1225
{
	viafb_CRT_ON = STATE_OFF;
	viafb_DVI_ON = STATE_OFF;
	viafb_LCD_ON = STATE_OFF;
	viafb_LCD2_ON = STATE_OFF;
	/* 1. Modify the active status of devices. */
	/* 2. Keep the order of devices, so we can set corresponding
	   IGA path to devices in SAMM case. */
	/*    Note: The previous of active_dev is primary device,
	   and the following is secondary device. */
1226 1227 1228 1229
	if (!viafb_active_dev) {
		viafb_CRT_ON = STATE_ON;
		viafb_SAMM_ON = STATE_OFF;
	} else if (!strcmp(viafb_active_dev, "CRT+DVI")) {
J
Joseph Chan 已提交
1230 1231 1232 1233
		/* CRT+DVI */
		viafb_CRT_ON = STATE_ON;
		viafb_DVI_ON = STATE_ON;
		viafb_primary_dev = CRT_Device;
1234
	} else if (!strcmp(viafb_active_dev, "DVI+CRT")) {
J
Joseph Chan 已提交
1235 1236 1237 1238
		/* DVI+CRT */
		viafb_CRT_ON = STATE_ON;
		viafb_DVI_ON = STATE_ON;
		viafb_primary_dev = DVI_Device;
1239
	} else if (!strcmp(viafb_active_dev, "CRT+LCD")) {
J
Joseph Chan 已提交
1240 1241 1242 1243
		/* CRT+LCD */
		viafb_CRT_ON = STATE_ON;
		viafb_LCD_ON = STATE_ON;
		viafb_primary_dev = CRT_Device;
1244
	} else if (!strcmp(viafb_active_dev, "LCD+CRT")) {
J
Joseph Chan 已提交
1245 1246 1247 1248
		/* LCD+CRT */
		viafb_CRT_ON = STATE_ON;
		viafb_LCD_ON = STATE_ON;
		viafb_primary_dev = LCD_Device;
1249
	} else if (!strcmp(viafb_active_dev, "DVI+LCD")) {
J
Joseph Chan 已提交
1250 1251 1252 1253
		/* DVI+LCD */
		viafb_DVI_ON = STATE_ON;
		viafb_LCD_ON = STATE_ON;
		viafb_primary_dev = DVI_Device;
1254
	} else if (!strcmp(viafb_active_dev, "LCD+DVI")) {
J
Joseph Chan 已提交
1255 1256 1257 1258
		/* LCD+DVI */
		viafb_DVI_ON = STATE_ON;
		viafb_LCD_ON = STATE_ON;
		viafb_primary_dev = LCD_Device;
1259
	} else if (!strcmp(viafb_active_dev, "LCD+LCD2")) {
J
Joseph Chan 已提交
1260 1261 1262
		viafb_LCD_ON = STATE_ON;
		viafb_LCD2_ON = STATE_ON;
		viafb_primary_dev = LCD_Device;
1263
	} else if (!strcmp(viafb_active_dev, "LCD2+LCD")) {
J
Joseph Chan 已提交
1264 1265 1266
		viafb_LCD_ON = STATE_ON;
		viafb_LCD2_ON = STATE_ON;
		viafb_primary_dev = LCD2_Device;
1267
	} else if (!strcmp(viafb_active_dev, "CRT")) {
J
Joseph Chan 已提交
1268 1269 1270
		/* CRT only */
		viafb_CRT_ON = STATE_ON;
		viafb_SAMM_ON = STATE_OFF;
1271
	} else if (!strcmp(viafb_active_dev, "DVI")) {
J
Joseph Chan 已提交
1272 1273 1274
		/* DVI only */
		viafb_DVI_ON = STATE_ON;
		viafb_SAMM_ON = STATE_OFF;
1275
	} else if (!strcmp(viafb_active_dev, "LCD")) {
J
Joseph Chan 已提交
1276 1277 1278
		/* LCD only */
		viafb_LCD_ON = STATE_ON;
		viafb_SAMM_ON = STATE_OFF;
1279 1280 1281 1282
	} else
		return -EINVAL;

	return 0;
J
Joseph Chan 已提交
1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324
}

static int parse_port(char *opt_str, int *output_interface)
{
	if (!strncmp(opt_str, "DVP0", 4))
		*output_interface = INTERFACE_DVP0;
	else if (!strncmp(opt_str, "DVP1", 4))
		*output_interface = INTERFACE_DVP1;
	else if (!strncmp(opt_str, "DFP_HIGHLOW", 11))
		*output_interface = INTERFACE_DFP;
	else if (!strncmp(opt_str, "DFP_HIGH", 8))
		*output_interface = INTERFACE_DFP_HIGH;
	else if (!strncmp(opt_str, "DFP_LOW", 7))
		*output_interface = INTERFACE_DFP_LOW;
	else
		*output_interface = INTERFACE_NONE;
	return 0;
}

static void parse_lcd_port(void)
{
	parse_port(viafb_lcd_port, &viaparinfo->chip_info->lvds_chip_info.
		output_interface);
	/*Initialize to avoid unexpected behavior */
	viaparinfo->chip_info->lvds_chip_info2.output_interface =
	INTERFACE_NONE;

	DEBUG_MSG(KERN_INFO "parse_lcd_port: viafb_lcd_port:%s,interface:%d\n",
		  viafb_lcd_port, viaparinfo->chip_info->lvds_chip_info.
		  output_interface);
}

static void parse_dvi_port(void)
{
	parse_port(viafb_dvi_port, &viaparinfo->chip_info->tmds_chip_info.
		output_interface);

	DEBUG_MSG(KERN_INFO "parse_dvi_port: viafb_dvi_port:%s,interface:%d\n",
		  viafb_dvi_port, viaparinfo->chip_info->tmds_chip_info.
		  output_interface);
}

1325 1326
#ifdef CONFIG_FB_VIA_DIRECT_PROCFS

J
Joseph Chan 已提交
1327 1328 1329 1330 1331 1332
/*
 * The proc filesystem read/write function, a simple proc implement to
 * get/set the value of DPA  DVP0,   DVP0DataDriving,  DVP0ClockDriving, DVP1,
 * DVP1Driving, DFPHigh, DFPLow CR96,   SR2A[5], SR1B[1], SR2A[4], SR1E[2],
 * CR9B,    SR65,    CR97,    CR99
 */
A
Alexey Dobriyan 已提交
1333
static int viafb_dvp0_proc_show(struct seq_file *m, void *v)
J
Joseph Chan 已提交
1334 1335 1336 1337 1338 1339 1340 1341 1342
{
	u8 dvp0_data_dri = 0, dvp0_clk_dri = 0, dvp0 = 0;
	dvp0_data_dri =
	    (viafb_read_reg(VIASR, SR2A) & BIT5) >> 4 |
	    (viafb_read_reg(VIASR, SR1B) & BIT1) >> 1;
	dvp0_clk_dri =
	    (viafb_read_reg(VIASR, SR2A) & BIT4) >> 3 |
	    (viafb_read_reg(VIASR, SR1E) & BIT2) >> 2;
	dvp0 = viafb_read_reg(VIACR, CR96) & 0x0f;
A
Alexey Dobriyan 已提交
1343 1344
	seq_printf(m, "%x %x %x\n", dvp0, dvp0_data_dri, dvp0_clk_dri);
	return 0;
J
Joseph Chan 已提交
1345
}
A
Alexey Dobriyan 已提交
1346 1347 1348 1349 1350 1351 1352 1353

static int viafb_dvp0_proc_open(struct inode *inode, struct file *file)
{
	return single_open(file, viafb_dvp0_proc_show, NULL);
}

static ssize_t viafb_dvp0_proc_write(struct file *file,
	const char __user *buffer, size_t count, loff_t *pos)
J
Joseph Chan 已提交
1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396
{
	char buf[20], *value, *pbuf;
	u8 reg_val = 0;
	unsigned long length, i;
	if (count < 1)
		return -EINVAL;
	length = count > 20 ? 20 : count;
	if (copy_from_user(&buf[0], buffer, length))
		return -EFAULT;
	buf[length - 1] = '\0';	/*Ensure end string */
	pbuf = &buf[0];
	for (i = 0; i < 3; i++) {
		value = strsep(&pbuf, " ");
		if (value != NULL) {
			strict_strtoul(value, 0, (unsigned long *)&reg_val);
			DEBUG_MSG(KERN_INFO "DVP0:reg_val[%l]=:%x\n", i,
				  reg_val);
			switch (i) {
			case 0:
				viafb_write_reg_mask(CR96, VIACR,
					reg_val, 0x0f);
				break;
			case 1:
				viafb_write_reg_mask(SR2A, VIASR,
					reg_val << 4, BIT5);
				viafb_write_reg_mask(SR1B, VIASR,
					reg_val << 1, BIT1);
				break;
			case 2:
				viafb_write_reg_mask(SR2A, VIASR,
					reg_val << 3, BIT4);
				viafb_write_reg_mask(SR1E, VIASR,
					reg_val << 2, BIT2);
				break;
			default:
				break;
			}
		} else {
			break;
		}
	}
	return count;
}
A
Alexey Dobriyan 已提交
1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407

static const struct file_operations viafb_dvp0_proc_fops = {
	.owner		= THIS_MODULE,
	.open		= viafb_dvp0_proc_open,
	.read		= seq_read,
	.llseek		= seq_lseek,
	.release	= single_release,
	.write		= viafb_dvp0_proc_write,
};

static int viafb_dvp1_proc_show(struct seq_file *m, void *v)
J
Joseph Chan 已提交
1408 1409 1410 1411 1412
{
	u8 dvp1 = 0, dvp1_data_dri = 0, dvp1_clk_dri = 0;
	dvp1 = viafb_read_reg(VIACR, CR9B) & 0x0f;
	dvp1_data_dri = (viafb_read_reg(VIASR, SR65) & 0x0c) >> 2;
	dvp1_clk_dri = viafb_read_reg(VIASR, SR65) & 0x03;
A
Alexey Dobriyan 已提交
1413 1414
	seq_printf(m, "%x %x %x\n", dvp1, dvp1_data_dri, dvp1_clk_dri);
	return 0;
J
Joseph Chan 已提交
1415
}
A
Alexey Dobriyan 已提交
1416 1417 1418 1419 1420 1421 1422 1423

static int viafb_dvp1_proc_open(struct inode *inode, struct file *file)
{
	return single_open(file, viafb_dvp1_proc_show, NULL);
}

static ssize_t viafb_dvp1_proc_write(struct file *file,
	const char __user *buffer, size_t count, loff_t *pos)
J
Joseph Chan 已提交
1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461
{
	char buf[20], *value, *pbuf;
	u8 reg_val = 0;
	unsigned long length, i;
	if (count < 1)
		return -EINVAL;
	length = count > 20 ? 20 : count;
	if (copy_from_user(&buf[0], buffer, length))
		return -EFAULT;
	buf[length - 1] = '\0';	/*Ensure end string */
	pbuf = &buf[0];
	for (i = 0; i < 3; i++) {
		value = strsep(&pbuf, " ");
		if (value != NULL) {
			strict_strtoul(value, 0, (unsigned long *)&reg_val);
			switch (i) {
			case 0:
				viafb_write_reg_mask(CR9B, VIACR,
					reg_val, 0x0f);
				break;
			case 1:
				viafb_write_reg_mask(SR65, VIASR,
					reg_val << 2, 0x0c);
				break;
			case 2:
				viafb_write_reg_mask(SR65, VIASR,
					reg_val, 0x03);
				break;
			default:
				break;
			}
		} else {
			break;
		}
	}
	return count;
}

A
Alexey Dobriyan 已提交
1462 1463 1464 1465 1466 1467 1468 1469 1470 1471
static const struct file_operations viafb_dvp1_proc_fops = {
	.owner		= THIS_MODULE,
	.open		= viafb_dvp1_proc_open,
	.read		= seq_read,
	.llseek		= seq_lseek,
	.release	= single_release,
	.write		= viafb_dvp1_proc_write,
};

static int viafb_dfph_proc_show(struct seq_file *m, void *v)
J
Joseph Chan 已提交
1472 1473 1474
{
	u8 dfp_high = 0;
	dfp_high = viafb_read_reg(VIACR, CR97) & 0x0f;
A
Alexey Dobriyan 已提交
1475 1476
	seq_printf(m, "%x\n", dfp_high);
	return 0;
J
Joseph Chan 已提交
1477
}
A
Alexey Dobriyan 已提交
1478 1479 1480 1481 1482 1483 1484 1485

static int viafb_dfph_proc_open(struct inode *inode, struct file *file)
{
	return single_open(file, viafb_dfph_proc_show, NULL);
}

static ssize_t viafb_dfph_proc_write(struct file *file,
	const char __user *buffer, size_t count, loff_t *pos)
J
Joseph Chan 已提交
1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499
{
	char buf[20];
	u8 reg_val = 0;
	unsigned long length;
	if (count < 1)
		return -EINVAL;
	length = count > 20 ? 20 : count;
	if (copy_from_user(&buf[0], buffer, length))
		return -EFAULT;
	buf[length - 1] = '\0';	/*Ensure end string */
	strict_strtoul(&buf[0], 0, (unsigned long *)&reg_val);
	viafb_write_reg_mask(CR97, VIACR, reg_val, 0x0f);
	return count;
}
A
Alexey Dobriyan 已提交
1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510

static const struct file_operations viafb_dfph_proc_fops = {
	.owner		= THIS_MODULE,
	.open		= viafb_dfph_proc_open,
	.read		= seq_read,
	.llseek		= seq_lseek,
	.release	= single_release,
	.write		= viafb_dfph_proc_write,
};

static int viafb_dfpl_proc_show(struct seq_file *m, void *v)
J
Joseph Chan 已提交
1511 1512 1513
{
	u8 dfp_low = 0;
	dfp_low = viafb_read_reg(VIACR, CR99) & 0x0f;
A
Alexey Dobriyan 已提交
1514 1515 1516 1517 1518 1519 1520
	seq_printf(m, "%x\n", dfp_low);
	return 0;
}

static int viafb_dfpl_proc_open(struct inode *inode, struct file *file)
{
	return single_open(file, viafb_dfpl_proc_show, NULL);
J
Joseph Chan 已提交
1521
}
A
Alexey Dobriyan 已提交
1522 1523 1524

static ssize_t viafb_dfpl_proc_write(struct file *file,
	const char __user *buffer, size_t count, loff_t *pos)
J
Joseph Chan 已提交
1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538
{
	char buf[20];
	u8 reg_val = 0;
	unsigned long length;
	if (count < 1)
		return -EINVAL;
	length = count > 20 ? 20 : count;
	if (copy_from_user(&buf[0], buffer, length))
		return -EFAULT;
	buf[length - 1] = '\0';	/*Ensure end string */
	strict_strtoul(&buf[0], 0, (unsigned long *)&reg_val);
	viafb_write_reg_mask(CR99, VIACR, reg_val, 0x0f);
	return count;
}
A
Alexey Dobriyan 已提交
1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549

static const struct file_operations viafb_dfpl_proc_fops = {
	.owner		= THIS_MODULE,
	.open		= viafb_dfpl_proc_open,
	.read		= seq_read,
	.llseek		= seq_lseek,
	.release	= single_release,
	.write		= viafb_dfpl_proc_write,
};

static int viafb_vt1636_proc_show(struct seq_file *m, void *v)
J
Joseph Chan 已提交
1550 1551 1552 1553 1554 1555 1556 1557 1558 1559
{
	u8 vt1636_08 = 0, vt1636_09 = 0;
	switch (viaparinfo->chip_info->lvds_chip_info.lvds_chip_name) {
	case VT1636_LVDS:
		vt1636_08 =
		    viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info,
		    &viaparinfo->chip_info->lvds_chip_info, 0x08) & 0x0f;
		vt1636_09 =
		    viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info,
		    &viaparinfo->chip_info->lvds_chip_info, 0x09) & 0x1f;
A
Alexey Dobriyan 已提交
1560
		seq_printf(m, "%x %x\n", vt1636_08, vt1636_09);
J
Joseph Chan 已提交
1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572
		break;
	default:
		break;
	}
	switch (viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name) {
	case VT1636_LVDS:
		vt1636_08 =
		    viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info2,
			&viaparinfo->chip_info->lvds_chip_info2, 0x08) & 0x0f;
		vt1636_09 =
		    viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info2,
			&viaparinfo->chip_info->lvds_chip_info2, 0x09) & 0x1f;
A
Alexey Dobriyan 已提交
1573
		seq_printf(m, " %x %x\n", vt1636_08, vt1636_09);
J
Joseph Chan 已提交
1574 1575 1576 1577
		break;
	default:
		break;
	}
A
Alexey Dobriyan 已提交
1578
	return 0;
J
Joseph Chan 已提交
1579
}
A
Alexey Dobriyan 已提交
1580 1581 1582 1583 1584 1585 1586 1587

static int viafb_vt1636_proc_open(struct inode *inode, struct file *file)
{
	return single_open(file, viafb_vt1636_proc_show, NULL);
}

static ssize_t viafb_vt1636_proc_write(struct file *file,
	const char __user *buffer, size_t count, loff_t *pos)
J
Joseph Chan 已提交
1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675
{
	char buf[30], *value, *pbuf;
	struct IODATA reg_val;
	unsigned long length, i;
	if (count < 1)
		return -EINVAL;
	length = count > 30 ? 30 : count;
	if (copy_from_user(&buf[0], buffer, length))
		return -EFAULT;
	buf[length - 1] = '\0';	/*Ensure end string */
	pbuf = &buf[0];
	switch (viaparinfo->chip_info->lvds_chip_info.lvds_chip_name) {
	case VT1636_LVDS:
		for (i = 0; i < 2; i++) {
			value = strsep(&pbuf, " ");
			if (value != NULL) {
				strict_strtoul(value, 0,
					(unsigned long *)&reg_val.Data);
				switch (i) {
				case 0:
					reg_val.Index = 0x08;
					reg_val.Mask = 0x0f;
					viafb_gpio_i2c_write_mask_lvds
					    (viaparinfo->lvds_setting_info,
					    &viaparinfo->
					    chip_info->lvds_chip_info,
					     reg_val);
					break;
				case 1:
					reg_val.Index = 0x09;
					reg_val.Mask = 0x1f;
					viafb_gpio_i2c_write_mask_lvds
					    (viaparinfo->lvds_setting_info,
					    &viaparinfo->
					    chip_info->lvds_chip_info,
					     reg_val);
					break;
				default:
					break;
				}
			} else {
				break;
			}
		}
		break;
	default:
		break;
	}
	switch (viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name) {
	case VT1636_LVDS:
		for (i = 0; i < 2; i++) {
			value = strsep(&pbuf, " ");
			if (value != NULL) {
				strict_strtoul(value, 0,
					(unsigned long *)&reg_val.Data);
				switch (i) {
				case 0:
					reg_val.Index = 0x08;
					reg_val.Mask = 0x0f;
					viafb_gpio_i2c_write_mask_lvds
					    (viaparinfo->lvds_setting_info2,
					    &viaparinfo->
					    chip_info->lvds_chip_info2,
					     reg_val);
					break;
				case 1:
					reg_val.Index = 0x09;
					reg_val.Mask = 0x1f;
					viafb_gpio_i2c_write_mask_lvds
					    (viaparinfo->lvds_setting_info2,
					    &viaparinfo->
					    chip_info->lvds_chip_info2,
					     reg_val);
					break;
				default:
					break;
				}
			} else {
				break;
			}
		}
		break;
	default:
		break;
	}
	return count;
}

A
Alexey Dobriyan 已提交
1676 1677 1678 1679 1680 1681 1682 1683 1684
static const struct file_operations viafb_vt1636_proc_fops = {
	.owner		= THIS_MODULE,
	.open		= viafb_vt1636_proc_open,
	.read		= seq_read,
	.llseek		= seq_lseek,
	.release	= single_release,
	.write		= viafb_vt1636_proc_write,
};

1685
static void viafb_init_proc(struct proc_dir_entry **viafb_entry)
J
Joseph Chan 已提交
1686
{
1687
	*viafb_entry = proc_mkdir("viafb", NULL);
1688
	if (*viafb_entry) {
A
Alexey Dobriyan 已提交
1689 1690 1691 1692
		proc_create("dvp0", 0, *viafb_entry, &viafb_dvp0_proc_fops);
		proc_create("dvp1", 0, *viafb_entry, &viafb_dvp1_proc_fops);
		proc_create("dfph", 0, *viafb_entry, &viafb_dfph_proc_fops);
		proc_create("dfpl", 0, *viafb_entry, &viafb_dfpl_proc_fops);
J
Joseph Chan 已提交
1693 1694 1695
		if (VT1636_LVDS == viaparinfo->chip_info->lvds_chip_info.
			lvds_chip_name || VT1636_LVDS ==
		    viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name) {
A
Alexey Dobriyan 已提交
1696
			proc_create("vt1636", 0, *viafb_entry, &viafb_vt1636_proc_fops);
J
Joseph Chan 已提交
1697 1698 1699 1700 1701 1702
		}

	}
}
static void viafb_remove_proc(struct proc_dir_entry *viafb_entry)
{
1703 1704
	struct chip_information *chip_info = &viaparinfo->shared->chip_info;

J
Joseph Chan 已提交
1705 1706 1707 1708
	remove_proc_entry("dvp0", viafb_entry);/* parent dir */
	remove_proc_entry("dvp1", viafb_entry);
	remove_proc_entry("dfph", viafb_entry);
	remove_proc_entry("dfpl", viafb_entry);
1709 1710 1711 1712
	if (chip_info->lvds_chip_info.lvds_chip_name == VT1636_LVDS
		|| chip_info->lvds_chip_info2.lvds_chip_name == VT1636_LVDS)
		remove_proc_entry("vt1636", viafb_entry);

1713
	remove_proc_entry("viafb", NULL);
J
Joseph Chan 已提交
1714 1715
}

1716 1717
#endif /* CONFIG_FB_VIA_DIRECT_PROCFS */

1718
static int parse_mode(const char *str, u32 *xres, u32 *yres)
1719 1720 1721
{
	char *ptr;

1722 1723 1724 1725 1726 1727
	if (!str) {
		*xres = 640;
		*yres = 480;
		return 0;
	}

1728 1729
	*xres = simple_strtoul(str, &ptr, 10);
	if (ptr[0] != 'x')
1730
		return -EINVAL;
1731 1732 1733

	*yres = simple_strtoul(&ptr[1], &ptr, 10);
	if (ptr[0])
1734
		return -EINVAL;
1735

1736
	return 0;
1737 1738
}

1739

1740
int __devinit via_fb_pci_probe(struct viafb_dev *vdev)
J
Joseph Chan 已提交
1741
{
1742
	u32 default_xres, default_yres;
1743
	struct VideoModeTable *vmode_entry;
1744
	struct fb_var_screeninfo default_var;
1745
	int rc;
1746
	u32 viafb_par_length;
J
Joseph Chan 已提交
1747 1748

	DEBUG_MSG(KERN_INFO "VIAFB PCI Probe!!\n");
1749
	memset(&default_var, 0, sizeof(default_var));
J
Joseph Chan 已提交
1750 1751 1752 1753 1754
	viafb_par_length = ALIGN(sizeof(struct viafb_par), BITS_PER_LONG/8);

	/* Allocate fb_info and ***_par here, also including some other needed
	 * variables
	*/
1755
	viafbinfo = framebuffer_alloc(viafb_par_length +
1756
		ALIGN(sizeof(struct viafb_shared), BITS_PER_LONG/8),
1757
		&vdev->pdev->dev);
J
Joseph Chan 已提交
1758 1759
	if (!viafbinfo) {
		printk(KERN_ERR"Could not allocate memory for viafb_info.\n");
1760
		return -ENOMEM;
J
Joseph Chan 已提交
1761 1762 1763
	}

	viaparinfo = (struct viafb_par *)viafbinfo->par;
1764
	viaparinfo->shared = viafbinfo->par + viafb_par_length;
1765
	viaparinfo->shared->vdev = vdev;
1766
	viaparinfo->vram_addr = 0;
1767 1768 1769 1770 1771 1772
	viaparinfo->tmds_setting_info = &viaparinfo->shared->tmds_setting_info;
	viaparinfo->lvds_setting_info = &viaparinfo->shared->lvds_setting_info;
	viaparinfo->lvds_setting_info2 =
		&viaparinfo->shared->lvds_setting_info2;
	viaparinfo->crt_setting_info = &viaparinfo->shared->crt_setting_info;
	viaparinfo->chip_info = &viaparinfo->shared->chip_info;
J
Joseph Chan 已提交
1773 1774 1775 1776 1777 1778 1779 1780 1781 1782

	if (viafb_dual_fb)
		viafb_SAMM_ON = 1;
	parse_lcd_port();
	parse_dvi_port();

	/* for dual-fb must viafb_SAMM_ON=1 and viafb_dual_fb=1 */
	if (!viafb_SAMM_ON)
		viafb_dual_fb = 0;

1783 1784 1785 1786 1787 1788 1789 1790
	viafb_init_chip_info(vdev->chip_type);
	/*
	 * The framebuffer will have been successfully mapped by
	 * the core (or we'd not be here), but we still need to
	 * set up our own accounting.
	 */
	viaparinfo->fbmem = vdev->fbmem_start;
	viaparinfo->memsize = vdev->fbmem_len;
J
Joseph Chan 已提交
1791 1792
	viaparinfo->fbmem_free = viaparinfo->memsize;
	viaparinfo->fbmem_used = 0;
1793
	viafbinfo->screen_base = vdev->fbmem;
J
Joseph Chan 已提交
1794

1795 1796
	viafbinfo->fix.mmio_start = vdev->engine_start;
	viafbinfo->fix.mmio_len = vdev->engine_len;
J
Joseph Chan 已提交
1797 1798 1799 1800 1801
	viafbinfo->node = 0;
	viafbinfo->fbops = &viafb_ops;
	viafbinfo->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;

	viafbinfo->pseudo_palette = pseudo_pal;
1802 1803 1804 1805 1806 1807 1808
	if (viafb_accel && !viafb_init_engine(viafbinfo)) {
		viafbinfo->flags |= FBINFO_HWACCEL_COPYAREA |
			FBINFO_HWACCEL_FILLRECT |  FBINFO_HWACCEL_IMAGEBLIT;
		default_var.accel_flags = FB_ACCELF_TEXT;
	} else {
		viafbinfo->flags |= FBINFO_HWACCEL_DISABLED;
		default_var.accel_flags = 0;
J
Joseph Chan 已提交
1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819
	}

	if (viafb_second_size && (viafb_second_size < 8)) {
		viafb_second_offset = viaparinfo->fbmem_free -
			viafb_second_size * 1024 * 1024;
	} else {
		viafb_second_size = 8;
		viafb_second_offset = viaparinfo->fbmem_free -
			viafb_second_size * 1024 * 1024;
	}

1820
	parse_mode(viafb_mode, &default_xres, &default_yres);
1821
	vmode_entry = viafb_get_mode(default_xres, default_yres);
J
Joseph Chan 已提交
1822
	if (viafb_SAMM_ON == 1) {
1823 1824 1825
		parse_mode(viafb_mode1, &viafb_second_xres,
			&viafb_second_yres);

J
Joseph Chan 已提交
1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859
		if (0 == viafb_second_virtual_xres) {
			switch (viafb_second_xres) {
			case 1400:
				viafb_second_virtual_xres = 1408;
				break;
			default:
				viafb_second_virtual_xres = viafb_second_xres;
				break;
			}
		}
		if (0 == viafb_second_virtual_yres)
			viafb_second_virtual_yres = viafb_second_yres;
	}

	default_var.xres = default_xres;
	default_var.yres = default_yres;
	switch (default_xres) {
	case 1400:
		default_var.xres_virtual = 1408;
		break;
	default:
		default_var.xres_virtual = default_xres;
		break;
	}
	default_var.yres_virtual = default_yres;
	default_var.bits_per_pixel = viafb_bpp;
	default_var.pixclock =
	    viafb_get_pixclock(default_xres, default_yres, viafb_refresh);
	default_var.left_margin = (default_xres >> 3) & 0xf8;
	default_var.right_margin = 32;
	default_var.upper_margin = 16;
	default_var.lower_margin = 4;
	default_var.hsync_len = default_var.left_margin;
	default_var.vsync_len = 4;
1860 1861
	viafb_setup_fixinfo(&viafbinfo->fix, viaparinfo);
	viafbinfo->var = default_var;
J
Joseph Chan 已提交
1862 1863

	if (viafb_dual_fb) {
1864 1865
		viafbinfo1 = framebuffer_alloc(viafb_par_length,
				&vdev->pdev->dev);
J
Joseph Chan 已提交
1866 1867 1868
		if (!viafbinfo1) {
			printk(KERN_ERR
			"allocate the second framebuffer struct error\n");
1869
			rc = -ENOMEM;
1870
			goto out_fb_release;
J
Joseph Chan 已提交
1871 1872 1873
		}
		viaparinfo1 = viafbinfo1->par;
		memcpy(viaparinfo1, viaparinfo, viafb_par_length);
1874
		viaparinfo1->vram_addr = viafb_second_offset;
J
Joseph Chan 已提交
1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885
		viaparinfo1->memsize = viaparinfo->memsize -
			viafb_second_offset;
		viaparinfo->memsize = viafb_second_offset;
		viaparinfo1->fbmem = viaparinfo->fbmem + viafb_second_offset;

		viaparinfo1->fbmem_used = viaparinfo->fbmem_used;
		viaparinfo1->fbmem_free = viaparinfo1->memsize -
			viaparinfo1->fbmem_used;
		viaparinfo->fbmem_free = viaparinfo->memsize;
		viaparinfo->fbmem_used = 0;

1886 1887
		viaparinfo->iga_path = IGA1;
		viaparinfo1->iga_path = IGA2;
J
Joseph Chan 已提交
1888
		memcpy(viafbinfo1, viafbinfo, sizeof(struct fb_info));
1889
		viafbinfo1->par = viaparinfo1;
J
Joseph Chan 已提交
1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910
		viafbinfo1->screen_base = viafbinfo->screen_base +
			viafb_second_offset;

		default_var.xres = viafb_second_xres;
		default_var.yres = viafb_second_yres;
		default_var.xres_virtual = viafb_second_virtual_xres;
		default_var.yres_virtual = viafb_second_virtual_yres;
		default_var.bits_per_pixel = viafb_bpp1;
		default_var.pixclock =
		    viafb_get_pixclock(viafb_second_xres, viafb_second_yres,
		    viafb_refresh);
		default_var.left_margin = (viafb_second_xres >> 3) & 0xf8;
		default_var.right_margin = 32;
		default_var.upper_margin = 16;
		default_var.lower_margin = 4;
		default_var.hsync_len = default_var.left_margin;
		default_var.vsync_len = 4;

		viafb_setup_fixinfo(&viafbinfo1->fix, viaparinfo1);
		viafb_check_var(&default_var, viafbinfo1);
		viafbinfo1->var = default_var;
1911
		viafb_update_fix(viafbinfo1);
1912 1913
		viaparinfo1->depth = fb_get_color_depth(&viafbinfo1->var,
			&viafbinfo1->fix);
J
Joseph Chan 已提交
1914 1915
	}

1916
	viafb_check_var(&viafbinfo->var, viafbinfo);
1917
	viafb_update_fix(viafbinfo);
1918 1919
	viaparinfo->depth = fb_get_color_depth(&viafbinfo->var,
		&viafbinfo->fix);
J
Joseph Chan 已提交
1920
	default_var.activate = FB_ACTIVATE_NOW;
1921 1922 1923
	rc = fb_alloc_cmap(&viafbinfo->cmap, 256, 0);
	if (rc)
		goto out_fb1_release;
J
Joseph Chan 已提交
1924 1925 1926

	if (viafb_dual_fb && (viafb_primary_dev == LCD_Device)
	    && (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266)) {
1927 1928 1929
		rc = register_framebuffer(viafbinfo1);
		if (rc)
			goto out_dealloc_cmap;
J
Joseph Chan 已提交
1930
	}
1931 1932 1933
	rc = register_framebuffer(viafbinfo);
	if (rc)
		goto out_fb1_unreg_lcd_cle266;
J
Joseph Chan 已提交
1934 1935 1936 1937

	if (viafb_dual_fb && ((viafb_primary_dev != LCD_Device)
			|| (viaparinfo->chip_info->gfx_chip_name !=
			UNICHROME_CLE266))) {
1938 1939 1940
		rc = register_framebuffer(viafbinfo1);
		if (rc)
			goto out_fb_unreg;
J
Joseph Chan 已提交
1941 1942 1943 1944 1945
	}
	DEBUG_MSG(KERN_INFO "fb%d: %s frame buffer device %dx%d-%dbpp\n",
		  viafbinfo->node, viafbinfo->fix.id, default_var.xres,
		  default_var.yres, default_var.bits_per_pixel);

1946
#ifdef CONFIG_FB_VIA_DIRECT_PROCFS
1947
	viafb_init_proc(&viaparinfo->shared->proc_entry);
1948
#endif
J
Joseph Chan 已提交
1949 1950
	viafb_init_dac(IGA2);
	return 0;
1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965

out_fb_unreg:
	unregister_framebuffer(viafbinfo);
out_fb1_unreg_lcd_cle266:
	if (viafb_dual_fb && (viafb_primary_dev == LCD_Device)
	    && (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266))
		unregister_framebuffer(viafbinfo1);
out_dealloc_cmap:
	fb_dealloc_cmap(&viafbinfo->cmap);
out_fb1_release:
	if (viafbinfo1)
		framebuffer_release(viafbinfo1);
out_fb_release:
	framebuffer_release(viafbinfo);
	return rc;
J
Joseph Chan 已提交
1966 1967
}

1968
void __devexit via_fb_pci_remove(struct pci_dev *pdev)
J
Joseph Chan 已提交
1969 1970 1971 1972 1973 1974
{
	DEBUG_MSG(KERN_INFO "via_pci_remove!\n");
	fb_dealloc_cmap(&viafbinfo->cmap);
	unregister_framebuffer(viafbinfo);
	if (viafb_dual_fb)
		unregister_framebuffer(viafbinfo1);
1975
#ifdef CONFIG_FB_VIA_DIRECT_PROCFS
1976
	viafb_remove_proc(viaparinfo->shared->proc_entry);
1977
#endif
J
Joseph Chan 已提交
1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055
	framebuffer_release(viafbinfo);
	if (viafb_dual_fb)
		framebuffer_release(viafbinfo1);
}

#ifndef MODULE
static int __init viafb_setup(char *options)
{
	char *this_opt;
	DEBUG_MSG(KERN_INFO "viafb_setup!\n");

	if (!options || !*options)
		return 0;

	while ((this_opt = strsep(&options, ",")) != NULL) {
		if (!*this_opt)
			continue;

		if (!strncmp(this_opt, "viafb_mode1=", 12))
			viafb_mode1 = kstrdup(this_opt + 12, GFP_KERNEL);
		else if (!strncmp(this_opt, "viafb_mode=", 11))
			viafb_mode = kstrdup(this_opt + 11, GFP_KERNEL);
		else if (!strncmp(this_opt, "viafb_bpp1=", 11))
			strict_strtoul(this_opt + 11, 0,
				(unsigned long *)&viafb_bpp1);
		else if (!strncmp(this_opt, "viafb_bpp=", 10))
			strict_strtoul(this_opt + 10, 0,
				(unsigned long *)&viafb_bpp);
		else if (!strncmp(this_opt, "viafb_refresh1=", 15))
			strict_strtoul(this_opt + 15, 0,
				(unsigned long *)&viafb_refresh1);
		else if (!strncmp(this_opt, "viafb_refresh=", 14))
			strict_strtoul(this_opt + 14, 0,
				(unsigned long *)&viafb_refresh);
		else if (!strncmp(this_opt, "viafb_lcd_dsp_method=", 21))
			strict_strtoul(this_opt + 21, 0,
				(unsigned long *)&viafb_lcd_dsp_method);
		else if (!strncmp(this_opt, "viafb_lcd_panel_id=", 19))
			strict_strtoul(this_opt + 19, 0,
				(unsigned long *)&viafb_lcd_panel_id);
		else if (!strncmp(this_opt, "viafb_accel=", 12))
			strict_strtoul(this_opt + 12, 0,
				(unsigned long *)&viafb_accel);
		else if (!strncmp(this_opt, "viafb_SAMM_ON=", 14))
			strict_strtoul(this_opt + 14, 0,
				(unsigned long *)&viafb_SAMM_ON);
		else if (!strncmp(this_opt, "viafb_active_dev=", 17))
			viafb_active_dev = kstrdup(this_opt + 17, GFP_KERNEL);
		else if (!strncmp(this_opt,
			"viafb_display_hardware_layout=", 30))
			strict_strtoul(this_opt + 30, 0,
			(unsigned long *)&viafb_display_hardware_layout);
		else if (!strncmp(this_opt, "viafb_second_size=", 18))
			strict_strtoul(this_opt + 18, 0,
				(unsigned long *)&viafb_second_size);
		else if (!strncmp(this_opt,
			"viafb_platform_epia_dvi=", 24))
			strict_strtoul(this_opt + 24, 0,
				(unsigned long *)&viafb_platform_epia_dvi);
		else if (!strncmp(this_opt,
			"viafb_device_lcd_dualedge=", 26))
			strict_strtoul(this_opt + 26, 0,
				(unsigned long *)&viafb_device_lcd_dualedge);
		else if (!strncmp(this_opt, "viafb_bus_width=", 16))
			strict_strtoul(this_opt + 16, 0,
				(unsigned long *)&viafb_bus_width);
		else if (!strncmp(this_opt, "viafb_lcd_mode=", 15))
			strict_strtoul(this_opt + 15, 0,
				(unsigned long *)&viafb_lcd_mode);
		else if (!strncmp(this_opt, "viafb_lcd_port=", 15))
			viafb_lcd_port = kstrdup(this_opt + 15, GFP_KERNEL);
		else if (!strncmp(this_opt, "viafb_dvi_port=", 15))
			viafb_dvi_port = kstrdup(this_opt + 15, GFP_KERNEL);
	}
	return 0;
}
#endif

2056 2057 2058 2059
/*
 * These are called out of via-core for now.
 */
int __init viafb_init(void)
J
Joseph Chan 已提交
2060
{
2061
	u32 dummy;
J
Joseph Chan 已提交
2062 2063 2064 2065 2066 2067
#ifndef MODULE
	char *option = NULL;
	if (fb_get_options("viafb", &option))
		return -ENODEV;
	viafb_setup(option);
#endif
2068 2069
	if (parse_mode(viafb_mode, &dummy, &dummy)
		|| parse_mode(viafb_mode1, &dummy, &dummy)
2070 2071
		|| viafb_bpp < 0 || viafb_bpp > 32
		|| viafb_bpp1 < 0 || viafb_bpp1 > 32
2072 2073 2074
		|| parse_active_dev())
		return -EINVAL;

J
Joseph Chan 已提交
2075 2076 2077
	printk(KERN_INFO
       "VIA Graphics Intergration Chipset framebuffer %d.%d initializing\n",
	       VERSION_MAJOR, VERSION_MINOR);
2078
	return 0;
J
Joseph Chan 已提交
2079 2080
}

2081
void __exit viafb_exit(void)
J
Joseph Chan 已提交
2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104
{
	DEBUG_MSG(KERN_INFO "viafb_exit!\n");
}

static struct fb_ops viafb_ops = {
	.owner = THIS_MODULE,
	.fb_open = viafb_open,
	.fb_release = viafb_release,
	.fb_check_var = viafb_check_var,
	.fb_set_par = viafb_set_par,
	.fb_setcolreg = viafb_setcolreg,
	.fb_pan_display = viafb_pan_display,
	.fb_blank = viafb_blank,
	.fb_fillrect = viafb_fillrect,
	.fb_copyarea = viafb_copyarea,
	.fb_imageblit = viafb_imageblit,
	.fb_cursor = viafb_cursor,
	.fb_ioctl = viafb_ioctl,
	.fb_sync = viafb_sync,
};


#ifdef MODULE
2105
module_param(viafb_mode, charp, S_IRUSR);
J
Joseph Chan 已提交
2106 2107
MODULE_PARM_DESC(viafb_mode, "Set resolution (default=640x480)");

2108
module_param(viafb_mode1, charp, S_IRUSR);
J
Joseph Chan 已提交
2109 2110
MODULE_PARM_DESC(viafb_mode1, "Set resolution (default=640x480)");

2111
module_param(viafb_bpp, int, S_IRUSR);
J
Joseph Chan 已提交
2112 2113
MODULE_PARM_DESC(viafb_bpp, "Set color depth (default=32bpp)");

2114
module_param(viafb_bpp1, int, S_IRUSR);
J
Joseph Chan 已提交
2115 2116
MODULE_PARM_DESC(viafb_bpp1, "Set color depth (default=32bpp)");

2117
module_param(viafb_refresh, int, S_IRUSR);
J
Joseph Chan 已提交
2118 2119 2120
MODULE_PARM_DESC(viafb_refresh,
	"Set CRT viafb_refresh rate (default = 60)");

2121
module_param(viafb_refresh1, int, S_IRUSR);
J
Joseph Chan 已提交
2122 2123 2124
MODULE_PARM_DESC(viafb_refresh1,
	"Set CRT refresh rate (default = 60)");

2125
module_param(viafb_lcd_panel_id, int, S_IRUSR);
J
Joseph Chan 已提交
2126 2127 2128
MODULE_PARM_DESC(viafb_lcd_panel_id,
	"Set Flat Panel type(Default=1024x768)");

2129
module_param(viafb_lcd_dsp_method, int, S_IRUSR);
J
Joseph Chan 已提交
2130 2131 2132
MODULE_PARM_DESC(viafb_lcd_dsp_method,
	"Set Flat Panel display scaling method.(Default=Expandsion)");

2133
module_param(viafb_SAMM_ON, int, S_IRUSR);
J
Joseph Chan 已提交
2134 2135 2136
MODULE_PARM_DESC(viafb_SAMM_ON,
	"Turn on/off flag of SAMM(Default=OFF)");

2137
module_param(viafb_accel, int, S_IRUSR);
J
Joseph Chan 已提交
2138
MODULE_PARM_DESC(viafb_accel,
2139
	"Set 2D Hardware Acceleration: 0 = OFF, 1 = ON (default)");
J
Joseph Chan 已提交
2140

2141
module_param(viafb_active_dev, charp, S_IRUSR);
J
Joseph Chan 已提交
2142 2143
MODULE_PARM_DESC(viafb_active_dev, "Specify active devices.");

2144
module_param(viafb_display_hardware_layout, int, S_IRUSR);
J
Joseph Chan 已提交
2145 2146 2147
MODULE_PARM_DESC(viafb_display_hardware_layout,
	"Display Hardware Layout (LCD Only, DVI Only...,etc)");

2148
module_param(viafb_second_size, int, S_IRUSR);
J
Joseph Chan 已提交
2149 2150 2151
MODULE_PARM_DESC(viafb_second_size,
	"Set secondary device memory size");

2152
module_param(viafb_dual_fb, int, S_IRUSR);
J
Joseph Chan 已提交
2153 2154 2155
MODULE_PARM_DESC(viafb_dual_fb,
	"Turn on/off flag of dual framebuffer devices.(Default = OFF)");

2156
module_param(viafb_platform_epia_dvi, int, S_IRUSR);
J
Joseph Chan 已提交
2157 2158 2159
MODULE_PARM_DESC(viafb_platform_epia_dvi,
	"Turn on/off flag of DVI devices on EPIA board.(Default = OFF)");

2160
module_param(viafb_device_lcd_dualedge, int, S_IRUSR);
J
Joseph Chan 已提交
2161 2162 2163
MODULE_PARM_DESC(viafb_device_lcd_dualedge,
	"Turn on/off flag of dual edge panel.(Default = OFF)");

2164
module_param(viafb_bus_width, int, S_IRUSR);
J
Joseph Chan 已提交
2165 2166 2167
MODULE_PARM_DESC(viafb_bus_width,
	"Set bus width of panel.(Default = 12)");

2168
module_param(viafb_lcd_mode, int, S_IRUSR);
J
Joseph Chan 已提交
2169 2170 2171
MODULE_PARM_DESC(viafb_lcd_mode,
	"Set Flat Panel mode(Default=OPENLDI)");

2172
module_param(viafb_lcd_port, charp, S_IRUSR);
J
Joseph Chan 已提交
2173 2174
MODULE_PARM_DESC(viafb_lcd_port, "Specify LCD output port.");

2175
module_param(viafb_dvi_port, charp, S_IRUSR);
J
Joseph Chan 已提交
2176 2177 2178 2179
MODULE_PARM_DESC(viafb_dvi_port, "Specify DVI output port.");

MODULE_LICENSE("GPL");
#endif