815 lines · 20.6 KB · C
RawDownload
/* *  linux/drivers/video/kyro/fbdev.c * *  Copyright (C) 2002 STMicroelectronics *  Copyright (C) 2003, 2004 Paul Mundt * * This file is subject to the terms and conditions of the GNU General Public * License.  See the file COPYING in the main directory of this archive * for more details. */ #include <linux/aperture.h>#include <linux/module.h>#include <linux/types.h>#include <linux/kernel.h>#include <linux/mm.h>#include <linux/errno.h>#include <linux/string.h>#include <linux/delay.h>#include <linux/fb.h>#include <linux/ioctl.h>#include <linux/init.h>#include <linux/pci.h>#include <asm/io.h>#include <linux/uaccess.h> #include <video/kyro.h> #include "STG4000Reg.h"#include "STG4000Interface.h" /* * PCI Definitions */#define PCI_VENDOR_ID_ST	0x104a#define PCI_DEVICE_ID_STG4000	0x0010 #define KHZ2PICOS(a) (1000000000UL/(a)) /****************************************************************************/static struct fb_fix_screeninfo kyro_fix = {	.id		= "ST Kyro",	.type		= FB_TYPE_PACKED_PIXELS,	.visual		= FB_VISUAL_TRUECOLOR,	.accel		= FB_ACCEL_NONE,}; static const struct fb_var_screeninfo kyro_var = {	/* 640x480, 16bpp @ 60 Hz */	.xres		= 640,	.yres		= 480,	.xres_virtual	= 640,	.yres_virtual	= 480,	.bits_per_pixel	= 16,	.red		= { 11, 5, 0 },	.green		= {  5, 6, 0 },	.blue		= {  0, 5, 0 },	.activate	= FB_ACTIVATE_NOW,	.height		= -1,	.width		= -1,	.pixclock	= KHZ2PICOS(25175),	.left_margin	= 48,	.right_margin	= 16,	.upper_margin	= 33,	.lower_margin	= 10,	.hsync_len	= 96,	.vsync_len	= 2,	.vmode		= FB_VMODE_NONINTERLACED,}; typedef struct {	STG4000REG __iomem *pSTGReg;	/* Virtual address of PCI register region */	u32 ulNextFreeVidMem;	/* Offset from start of vid mem to next free region */	u32 ulOverlayOffset;	/* Offset from start of vid mem to overlay */	u32 ulOverlayStride;	/* Interleaved YUV and 422 mode Y stride */	u32 ulOverlayUVStride;	/* 422 mode U & V stride */} device_info_t; /* global graphics card info structure (one per card) */static device_info_t deviceInfo; static char *mode_option = NULL;static int nopan = 0;static int nowrap = 1;static int nomtrr = 0; /* PCI driver prototypes */static int kyrofb_probe(struct pci_dev *pdev, const struct pci_device_id *ent);static void kyrofb_remove(struct pci_dev *pdev); static struct fb_videomode kyro_modedb[] = {	{		/* 640x350 @ 85Hz */		NULL, 85, 640, 350, KHZ2PICOS(31500),		96, 32, 60, 32, 64, 3,		FB_SYNC_HOR_HIGH_ACT, FB_VMODE_NONINTERLACED	}, {		/* 640x400 @ 85Hz */		NULL, 85, 640, 400, KHZ2PICOS(31500),		96, 32, 41, 1, 64, 3,		FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED	}, {		/* 720x400 @ 85Hz */		NULL, 85, 720, 400, KHZ2PICOS(35500),		108, 36, 42, 1, 72, 3,		FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED	}, {		/* 640x480 @ 60Hz */		NULL, 60, 640, 480, KHZ2PICOS(25175),		48, 16, 33, 10, 96, 2,		0, FB_VMODE_NONINTERLACED	}, {		/* 640x480 @ 72Hz */		NULL, 72, 640, 480, KHZ2PICOS(31500),		128, 24, 28, 9, 40, 3,		0, FB_VMODE_NONINTERLACED	}, {		/* 640x480 @ 75Hz */		NULL, 75, 640, 480, KHZ2PICOS(31500),		120, 16, 16, 1, 64, 3,		0, FB_VMODE_NONINTERLACED	}, {		/* 640x480 @ 85Hz */		NULL, 85, 640, 480, KHZ2PICOS(36000),		80, 56, 25, 1, 56, 3,		0, FB_VMODE_NONINTERLACED	}, {		/* 800x600 @ 56Hz */		NULL, 56, 800, 600, KHZ2PICOS(36000),		128, 24, 22, 1, 72, 2,		FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED	}, {		/* 800x600 @ 60Hz */		NULL, 60, 800, 600, KHZ2PICOS(40000),		88, 40, 23, 1, 128, 4,		FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED	}, {		/* 800x600 @ 72Hz */		NULL, 72, 800, 600, KHZ2PICOS(50000),		64, 56, 23, 37, 120, 6,		FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED	}, {		/* 800x600 @ 75Hz */		NULL, 75, 800, 600, KHZ2PICOS(49500),		160, 16, 21, 1, 80, 3,		FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED	}, {		/* 800x600 @ 85Hz */		NULL, 85, 800, 600, KHZ2PICOS(56250),		152, 32, 27, 1, 64, 3,		FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED	}, {		/* 1024x768 @ 60Hz */		NULL, 60, 1024, 768, KHZ2PICOS(65000),		160, 24, 29, 3, 136, 6,		0, FB_VMODE_NONINTERLACED	}, {		/* 1024x768 @ 70Hz */		NULL, 70, 1024, 768, KHZ2PICOS(75000),		144, 24, 29, 3, 136, 6,		0, FB_VMODE_NONINTERLACED	}, {		/* 1024x768 @ 75Hz */		NULL, 75, 1024, 768, KHZ2PICOS(78750),		176, 16, 28, 1, 96, 3,		FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED	}, {		/* 1024x768 @ 85Hz */		NULL, 85, 1024, 768, KHZ2PICOS(94500),		208, 48, 36, 1, 96, 3,		FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED	}, {		/* 1152x864 @ 75Hz */		NULL, 75, 1152, 864, KHZ2PICOS(108000),		256, 64, 32, 1, 128, 3,		FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED	}, {		/* 1280x960 @ 60Hz */		NULL, 60, 1280, 960, KHZ2PICOS(108000),		312, 96, 36, 1, 112, 3,		FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED	}, {		/* 1280x960 @ 85Hz */		NULL, 85, 1280, 960, KHZ2PICOS(148500),		224, 64, 47, 1, 160, 3,		FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED	}, {		/* 1280x1024 @ 60Hz */		NULL, 60, 1280, 1024, KHZ2PICOS(108000),		248, 48, 38, 1, 112, 3,		FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED	}, {		/* 1280x1024 @ 75Hz */		NULL, 75, 1280, 1024, KHZ2PICOS(135000),		248, 16, 38, 1, 144, 3,		FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED	}, {		/* 1280x1024 @ 85Hz */		NULL, 85, 1280, 1024, KHZ2PICOS(157500),		224, 64, 44, 1, 160, 3,		FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED	}, {		/* 1600x1200 @ 60Hz */		NULL, 60, 1600, 1200, KHZ2PICOS(162000),		304, 64, 46, 1, 192, 3,		FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED	}, {		/* 1600x1200 @ 65Hz */		NULL, 65, 1600, 1200, KHZ2PICOS(175500),		304, 64, 46, 1, 192, 3,		FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED	}, {		/* 1600x1200 @ 70Hz */		NULL, 70, 1600, 1200, KHZ2PICOS(189000),		304, 64, 46, 1, 192, 3,		FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED	}, {		/* 1600x1200 @ 75Hz */		NULL, 75, 1600, 1200, KHZ2PICOS(202500),		304, 64, 46, 1, 192, 3,		FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED	}, {		/* 1600x1200 @ 85Hz */		NULL, 85, 1600, 1200, KHZ2PICOS(229500),		304, 64, 46, 1, 192, 3,		FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED	}, {		/* 1792x1344 @ 60Hz */		NULL, 60, 1792, 1344, KHZ2PICOS(204750),		328, 128, 46, 1, 200, 3,		FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED	}, {		/* 1792x1344 @ 75Hz */		NULL, 75, 1792, 1344, KHZ2PICOS(261000),		352, 96, 69, 1, 216, 3,		FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED	}, {		/* 1856x1392 @ 60Hz */		NULL, 60, 1856, 1392, KHZ2PICOS(218250),		352, 96, 43, 1, 224, 3,		FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED	}, {		/* 1856x1392 @ 75Hz */		NULL, 75, 1856, 1392, KHZ2PICOS(288000),		352, 128, 104, 1, 224, 3,		FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED	}, {		/* 1920x1440 @ 60Hz */		NULL, 60, 1920, 1440, KHZ2PICOS(234000),		344, 128, 56, 1, 208, 3,		FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED	}, {		/* 1920x1440 @ 75Hz */		NULL, 75, 1920, 1440, KHZ2PICOS(297000),		352, 144, 56, 1, 224, 3,		FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED	},};#define NUM_TOTAL_MODES	ARRAY_SIZE(kyro_modedb) /* * This needs to be kept ordered corresponding to kyro_modedb. */enum {	VMODE_640_350_85,	VMODE_640_400_85,	VMODE_720_400_85,	VMODE_640_480_60,	VMODE_640_480_72,	VMODE_640_480_75,	VMODE_640_480_85,	VMODE_800_600_56,	VMODE_800_600_60,	VMODE_800_600_72,	VMODE_800_600_75,	VMODE_800_600_85,	VMODE_1024_768_60,	VMODE_1024_768_70,	VMODE_1024_768_75,	VMODE_1024_768_85,	VMODE_1152_864_75,	VMODE_1280_960_60,	VMODE_1280_960_85,	VMODE_1280_1024_60,	VMODE_1280_1024_75,	VMODE_1280_1024_85,	VMODE_1600_1200_60,	VMODE_1600_1200_65,	VMODE_1600_1200_70,	VMODE_1600_1200_75,	VMODE_1600_1200_85,	VMODE_1792_1344_60,	VMODE_1792_1344_75,	VMODE_1856_1392_60,	VMODE_1856_1392_75,	VMODE_1920_1440_60,	VMODE_1920_1440_75,}; /* Accessors */static int kyro_dev_video_mode_set(struct fb_info *info){	struct kyrofb_info *par = info->par; 	/* Turn off display */	StopVTG(deviceInfo.pSTGReg);	DisableRamdacOutput(deviceInfo.pSTGReg); 	/* Bring us out of VGA and into Hi-Res mode, if not already. */	DisableVGA(deviceInfo.pSTGReg); 	if (InitialiseRamdac(deviceInfo.pSTGReg,			     info->var.bits_per_pixel,			     info->var.xres, info->var.yres,			     par->HSP, par->VSP, &par->PIXCLK) < 0)		return -EINVAL; 	SetupVTG(deviceInfo.pSTGReg, par); 	ResetOverlayRegisters(deviceInfo.pSTGReg); 	/* Turn on display in new mode */	EnableRamdacOutput(deviceInfo.pSTGReg);	StartVTG(deviceInfo.pSTGReg); 	deviceInfo.ulNextFreeVidMem = info->var.xres * info->var.yres *				      info->var.bits_per_pixel;	deviceInfo.ulOverlayOffset = 0; 	return 0;} static int kyro_dev_overlay_create(u32 ulWidth,				   u32 ulHeight, int bLinear){	u32 offset;	u32 stride, uvStride; 	if (deviceInfo.ulOverlayOffset != 0)		/*		 * Can only create one overlay without resetting the card or		 * changing display mode		 */		return -EINVAL; 	ResetOverlayRegisters(deviceInfo.pSTGReg); 	/* Overlays are addressed in multiples of 16bytes or 32bytes, so make	 * sure the start offset is on an appropriate boundary.	 */	offset = deviceInfo.ulNextFreeVidMem;	if ((offset & 0x1f) != 0) {		offset = (offset + 32L) & 0xffffffE0L;	} 	if (CreateOverlaySurface(deviceInfo.pSTGReg, ulWidth, ulHeight,				 bLinear, offset, &stride, &uvStride) < 0)		return -EINVAL; 	deviceInfo.ulOverlayOffset = offset;	deviceInfo.ulOverlayStride = stride;	deviceInfo.ulOverlayUVStride = uvStride;	deviceInfo.ulNextFreeVidMem = offset + (ulHeight * stride) + (ulHeight * 2 * uvStride); 	SetOverlayBlendMode(deviceInfo.pSTGReg, GLOBAL_ALPHA, 0xf, 0x0); 	return 0;} static int kyro_dev_overlay_viewport_set(u32 x, u32 y, u32 ulWidth, u32 ulHeight){	if (deviceInfo.ulOverlayOffset == 0)		/* probably haven't called CreateOverlay yet */		return -EINVAL; 	if (ulWidth == 0 || ulWidth == 0xffffffff ||	    ulHeight == 0 || ulHeight == 0xffffffff ||	    (x < 2 && ulWidth + 2 == 0))		return -EINVAL; 	/* Stop Ramdac Output */	DisableRamdacOutput(deviceInfo.pSTGReg); 	SetOverlayViewPort(deviceInfo.pSTGReg,			   x, y, x + ulWidth - 1, y + ulHeight - 1); 	EnableOverlayPlane(deviceInfo.pSTGReg);	/* Start Ramdac Output */	EnableRamdacOutput(deviceInfo.pSTGReg); 	return 0;} static inline unsigned long get_line_length(int x, int bpp){	return (unsigned long)((((x*bpp)+31)&~31) >> 3);} static int kyrofb_check_var(struct fb_var_screeninfo *var, struct fb_info *info){	struct kyrofb_info *par = info->par; 	if (!var->pixclock)		return -EINVAL; 	if (var->bits_per_pixel != 16 && var->bits_per_pixel != 32) {		printk(KERN_WARNING "kyrofb: depth not supported: %u\n", var->bits_per_pixel);		return -EINVAL;	} 	switch (var->bits_per_pixel) {	case 16:		var->red.offset = 11;		var->red.length = 5;		var->green.offset = 5;		var->green.length = 6;		var->blue.length = 5;		break;	case 32:		var->transp.offset = 24;		var->red.offset = 16;		var->green.offset = 8;		var->blue.offset = 0; 		var->red.length = 8;		var->green.length = 8;		var->blue.length = 8;		var->transp.length = 8;		break;	} 	/* Height/Width of picture in mm */	var->height = var->width = -1; 	/* Timing information. All values are in picoseconds */ 	/* par->PIXCLK is in 100Hz units. Convert to picoseconds -	 * ensuring we do not exceed 32 bit precision	 */	/*	 * XXX: Enabling this really screws over the pixclock value when we	 * read it back with fbset. As such, leaving this commented out appears	 * to do the right thing (at least for now) .. bearing in mind that we	 * have infact already done the KHZ2PICOS conversion in both the modedb	 * and kyro_var. -- PFM.	 *///	var->pixclock = 1000000000 / (par->PIXCLK / 10); 	/* the header file claims we should use picoseconds	 * - nobody else does though, the all use pixels and lines	 * of h and v sizes. Both options here.	 */ 	/*	 * If we're being called by __fb_try_mode(), then we don't want to	 * override any of the var settings that we've already parsed	 * from our modedb. -- PFM.	 */	if ((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_TEST)		return 0; 	var->left_margin = par->HBP;	var->hsync_len = par->HST;	var->right_margin = par->HFP; 	var->upper_margin = par->VBP;	var->vsync_len = par->VST;	var->lower_margin = par->VFP; 	if (par->HSP == 1)		var->sync |= FB_SYNC_HOR_HIGH_ACT;	if (par->VSP == 1)		var->sync |= FB_SYNC_VERT_HIGH_ACT; 	return 0;} static int kyrofb_set_par(struct fb_info *info){	struct kyrofb_info *par = info->par;	unsigned long lineclock;	unsigned long frameclock; 	/* Actual resolution */	par->XRES = info->var.xres;	par->YRES = info->var.yres; 	/* pixel depth */	par->PIXDEPTH = info->var.bits_per_pixel; 	/* Refresh rate */	/* time for a line in ns */	lineclock = (info->var.pixclock * (info->var.xres +				    info->var.right_margin +				    info->var.hsync_len +				    info->var.left_margin)) / 1000; 	if (!lineclock)		return -EINVAL; 

Lines 1–500 of 815.