2001-10-21 17:30:28 +00:00
|
|
|
//#define CRTC2
|
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
// YUY2 support (see config.format) added by A'rpi/ESP-team
|
2001-03-08 01:06:59 +00:00
|
|
|
// double buffering added by A'rpi/ESP-team
|
2002-04-14 23:14:26 +00:00
|
|
|
// brightness/contrast introduced by eyck
|
2001-03-08 01:06:59 +00:00
|
|
|
|
|
|
|
// Set this value, if autodetection fails! (video ram size in megabytes)
|
2001-03-11 23:01:14 +00:00
|
|
|
// #define MGA_MEMORY_SIZE 16
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2001-03-10 02:27:50 +00:00
|
|
|
//#define MGA_ALLOW_IRQ
|
|
|
|
|
|
|
|
#define MGA_VSYNC_POS 2
|
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* mga_vid.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999 Aaron Holtzman
|
|
|
|
*
|
|
|
|
* Module skeleton based on gutted agpgart module by Jeff Hartmann
|
|
|
|
* <slicer@ionet.net>
|
|
|
|
*
|
|
|
|
* Matrox MGA G200/G400 YUV Video Interface module Version 0.1.0
|
|
|
|
*
|
|
|
|
* BES == Back End Scaler
|
|
|
|
*
|
|
|
|
* This software has been released under the terms of the GNU Public
|
|
|
|
* license. See http://www.gnu.org/copyleft/gpl.html for details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
//It's entirely possible this major conflicts with something else
|
2003-03-21 17:59:15 +00:00
|
|
|
//use the 'major' parameter to override the default major number (178)
|
2001-02-24 20:28:24 +00:00
|
|
|
/* mknod /dev/mga_vid c 178 0 */
|
|
|
|
|
|
|
|
#include <linux/config.h>
|
|
|
|
#include <linux/version.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/errno.h>
|
2001-11-25 23:34:37 +00:00
|
|
|
|
|
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,10)
|
2001-02-24 20:28:24 +00:00
|
|
|
#include <linux/malloc.h>
|
2001-11-25 23:34:37 +00:00
|
|
|
#else
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#endif
|
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
#include <linux/pci.h>
|
2001-03-09 00:43:02 +00:00
|
|
|
#include <linux/ioport.h>
|
2001-02-24 20:28:24 +00:00
|
|
|
#include <linux/init.h>
|
|
|
|
|
|
|
|
#include "mga_vid.h"
|
|
|
|
|
|
|
|
#ifdef CONFIG_MTRR
|
|
|
|
#include <asm/mtrr.h>
|
|
|
|
#endif
|
|
|
|
|
2002-04-16 20:19:47 +00:00
|
|
|
#ifdef CONFIG_DEVFS_FS
|
|
|
|
#include <linux/devfs_fs_kernel.h>
|
|
|
|
#endif
|
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
#include <asm/uaccess.h>
|
|
|
|
#include <asm/system.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
|
|
|
|
#define TRUE 1
|
|
|
|
#define FALSE 0
|
|
|
|
|
2003-03-21 17:59:15 +00:00
|
|
|
#define DEFAULT_MGA_VID_MAJOR 178
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2001-03-08 01:06:59 +00:00
|
|
|
//#define MGA_VIDMEM_SIZE mga_ram_size
|
2001-02-24 20:28:24 +00:00
|
|
|
|
|
|
|
#ifndef PCI_DEVICE_ID_MATROX_G200_PCI
|
|
|
|
#define PCI_DEVICE_ID_MATROX_G200_PCI 0x0520
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef PCI_DEVICE_ID_MATROX_G200_AGP
|
|
|
|
#define PCI_DEVICE_ID_MATROX_G200_AGP 0x0521
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef PCI_DEVICE_ID_MATROX_G400
|
|
|
|
#define PCI_DEVICE_ID_MATROX_G400 0x0525
|
|
|
|
#endif
|
|
|
|
|
2001-09-27 17:00:35 +00:00
|
|
|
#ifndef PCI_DEVICE_ID_MATROX_G550
|
|
|
|
#define PCI_DEVICE_ID_MATROX_G550 0x2527
|
|
|
|
#endif
|
|
|
|
|
2003-03-02 21:21:56 +00:00
|
|
|
#ifndef PCI_SUBSYSTEM_ID_MATROX_G400_DH_16MB
|
|
|
|
#define PCI_SUBSYSTEM_ID_MATROX_G400_DH_16MB 0x2159
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef PCI_SUBSYSTEM_ID_MATROX_G400_16MB_SGRAM
|
|
|
|
#define PCI_SUBSYSTEM_ID_MATROX_G400_16MB_SGRAM 0x19d8
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef PCI_SUBSYSTEM_ID_MATROX_G400_16MB_SDRAM
|
|
|
|
#define PCI_SUBSYSTEM_ID_MATROX_G400_16MB_SDRAM 0x0328
|
|
|
|
#endif
|
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
MODULE_AUTHOR("Aaron Holtzman <aholtzma@engr.uvic.ca>");
|
2001-10-18 20:52:33 +00:00
|
|
|
#ifdef MODULE_LICENSE
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
#endif
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2002-02-02 20:49:52 +00:00
|
|
|
#define PARAM_BRIGHTNESS "brightness="
|
2002-02-02 23:38:35 +00:00
|
|
|
#define PARAM_CONTRAST "contrast="
|
2002-02-02 20:49:52 +00:00
|
|
|
#define PARAM_BLACKIE "blackie="
|
2002-02-02 21:39:25 +00:00
|
|
|
|
|
|
|
#define PARAM_BUFF_SIZE 4096
|
|
|
|
static uint8_t *mga_param_buff = NULL;
|
|
|
|
static uint32_t mga_param_buff_size=0;
|
|
|
|
static uint32_t mga_param_buff_len=0;
|
|
|
|
|
2002-04-21 15:07:44 +00:00
|
|
|
#ifndef min
|
2002-03-10 03:36:16 +00:00
|
|
|
#define min(x,y) (((x)<(y))?(x):(y))
|
2002-04-21 15:07:44 +00:00
|
|
|
#endif
|
2002-03-10 03:36:16 +00:00
|
|
|
|
2002-02-02 23:38:35 +00:00
|
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
|
|
|
|
#include <linux/ctype.h>
|
|
|
|
|
2002-04-28 17:22:40 +00:00
|
|
|
static unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base)
|
2002-02-02 23:38:35 +00:00
|
|
|
{
|
|
|
|
unsigned long result = 0,value;
|
|
|
|
|
|
|
|
if (!base) {
|
|
|
|
base = 10;
|
|
|
|
if (*cp == '0') {
|
|
|
|
base = 8;
|
|
|
|
cp++;
|
|
|
|
if ((*cp == 'x') && isxdigit(cp[1])) {
|
|
|
|
cp++;
|
|
|
|
base = 16;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp-'0' : (islower(*cp)
|
|
|
|
? toupper(*cp) : *cp)-'A'+10) < base) {
|
|
|
|
result = result*base + value;
|
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
if (endp)
|
|
|
|
*endp = (char *)cp;
|
|
|
|
return result;
|
|
|
|
}
|
2002-06-28 16:35:37 +00:00
|
|
|
#endif
|
2002-02-02 23:38:35 +00:00
|
|
|
|
2002-06-28 16:35:37 +00:00
|
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0) || LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,5)
|
2002-04-28 17:22:40 +00:00
|
|
|
static long simple_strtol(const char *cp,char **endp,unsigned int base)
|
2002-02-02 23:38:35 +00:00
|
|
|
{
|
|
|
|
if(*cp=='-')
|
|
|
|
return -simple_strtoul(cp+1,endp,base);
|
|
|
|
return simple_strtoul(cp,endp,base);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-02-02 20:49:52 +00:00
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
typedef struct bes_registers_s
|
|
|
|
{
|
|
|
|
//BES Control
|
|
|
|
uint32_t besctl;
|
|
|
|
//BES Global control
|
|
|
|
uint32_t besglobctl;
|
|
|
|
//Luma control (brightness and contrast)
|
|
|
|
uint32_t beslumactl;
|
|
|
|
//Line pitch
|
|
|
|
uint32_t bespitch;
|
|
|
|
|
|
|
|
//Buffer A-1 Chroma 3 plane org
|
|
|
|
uint32_t besa1c3org;
|
|
|
|
//Buffer A-1 Chroma org
|
|
|
|
uint32_t besa1corg;
|
|
|
|
//Buffer A-1 Luma org
|
|
|
|
uint32_t besa1org;
|
|
|
|
|
|
|
|
//Buffer A-2 Chroma 3 plane org
|
|
|
|
uint32_t besa2c3org;
|
|
|
|
//Buffer A-2 Chroma org
|
|
|
|
uint32_t besa2corg;
|
|
|
|
//Buffer A-2 Luma org
|
|
|
|
uint32_t besa2org;
|
|
|
|
|
|
|
|
//Buffer B-1 Chroma 3 plane org
|
|
|
|
uint32_t besb1c3org;
|
|
|
|
//Buffer B-1 Chroma org
|
|
|
|
uint32_t besb1corg;
|
|
|
|
//Buffer B-1 Luma org
|
|
|
|
uint32_t besb1org;
|
|
|
|
|
|
|
|
//Buffer B-2 Chroma 3 plane org
|
|
|
|
uint32_t besb2c3org;
|
|
|
|
//Buffer B-2 Chroma org
|
|
|
|
uint32_t besb2corg;
|
|
|
|
//Buffer B-2 Luma org
|
|
|
|
uint32_t besb2org;
|
|
|
|
|
|
|
|
//BES Horizontal coord
|
|
|
|
uint32_t beshcoord;
|
|
|
|
//BES Horizontal inverse scaling [5.14]
|
|
|
|
uint32_t beshiscal;
|
|
|
|
//BES Horizontal source start [10.14] (for scaling)
|
|
|
|
uint32_t beshsrcst;
|
|
|
|
//BES Horizontal source ending [10.14] (for scaling)
|
|
|
|
uint32_t beshsrcend;
|
|
|
|
//BES Horizontal source last
|
|
|
|
uint32_t beshsrclst;
|
|
|
|
|
|
|
|
|
|
|
|
//BES Vertical coord
|
|
|
|
uint32_t besvcoord;
|
|
|
|
//BES Vertical inverse scaling [5.14]
|
|
|
|
uint32_t besviscal;
|
|
|
|
//BES Field 1 vertical source last position
|
|
|
|
uint32_t besv1srclst;
|
|
|
|
//BES Field 1 weight start
|
|
|
|
uint32_t besv1wght;
|
|
|
|
//BES Field 2 vertical source last position
|
|
|
|
uint32_t besv2srclst;
|
|
|
|
//BES Field 2 weight start
|
|
|
|
uint32_t besv2wght;
|
|
|
|
|
2002-02-02 20:49:52 +00:00
|
|
|
|
|
|
|
//configurable stuff
|
|
|
|
int blackie;
|
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
} bes_registers_t;
|
|
|
|
|
|
|
|
static bes_registers_t regs;
|
2001-10-21 17:28:04 +00:00
|
|
|
#ifdef CRTC2
|
|
|
|
typedef struct crtc2_registers_s
|
|
|
|
{
|
|
|
|
uint32_t c2ctl;
|
|
|
|
uint32_t c2datactl;
|
|
|
|
uint32_t c2misc;
|
|
|
|
uint32_t c2hparam;
|
|
|
|
uint32_t c2hsync;
|
|
|
|
uint32_t c2offset;
|
|
|
|
uint32_t c2pl2startadd0;
|
|
|
|
uint32_t c2pl2startadd1;
|
|
|
|
uint32_t c2pl3startadd0;
|
|
|
|
uint32_t c2pl3startadd1;
|
|
|
|
uint32_t c2preload;
|
|
|
|
uint32_t c2spicstartadd0;
|
|
|
|
uint32_t c2spicstartadd1;
|
|
|
|
uint32_t c2startadd0;
|
|
|
|
uint32_t c2startadd1;
|
|
|
|
uint32_t c2subpiclut;
|
|
|
|
uint32_t c2vcount;
|
|
|
|
uint32_t c2vparam;
|
|
|
|
uint32_t c2vsync;
|
|
|
|
} crtc2_registers_t;
|
|
|
|
static crtc2_registers_t cregs;
|
|
|
|
#endif
|
2001-02-24 20:28:24 +00:00
|
|
|
static uint32_t mga_vid_in_use = 0;
|
|
|
|
static uint32_t is_g400 = 0;
|
|
|
|
static uint32_t vid_src_ready = 0;
|
|
|
|
static uint32_t vid_overlay_on = 0;
|
|
|
|
|
|
|
|
static uint8_t *mga_mmio_base = 0;
|
|
|
|
static uint32_t mga_mem_base = 0;
|
|
|
|
|
2001-03-08 01:06:59 +00:00
|
|
|
static int mga_src_base = 0; // YUV buffer position in video memory
|
|
|
|
|
|
|
|
static uint32_t mga_ram_size = 0; // how much megabytes videoram we have
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2002-02-07 02:07:29 +00:00
|
|
|
static uint32_t mga_top_reserved = 0; // reserved space for console font (matroxfb + fastfont)
|
|
|
|
|
2002-02-16 19:58:39 +00:00
|
|
|
static int mga_brightness = 0; // initial brightness
|
|
|
|
static int mga_contrast = 0; // initial contrast
|
2003-03-21 16:29:04 +00:00
|
|
|
static int mga_number = 0; // which device/card is taken
|
2003-03-21 17:59:15 +00:00
|
|
|
static int major = DEFAULT_MGA_VID_MAJOR;
|
2002-02-16 19:58:39 +00:00
|
|
|
|
2001-03-12 01:57:14 +00:00
|
|
|
//static int mga_force_memsize = 0;
|
2001-03-11 22:24:03 +00:00
|
|
|
|
2001-03-12 01:57:14 +00:00
|
|
|
MODULE_PARM(mga_ram_size, "i");
|
2002-02-07 02:07:29 +00:00
|
|
|
MODULE_PARM(mga_top_reserved, "i");
|
2002-02-16 19:58:39 +00:00
|
|
|
MODULE_PARM(mga_brightness, "i");
|
|
|
|
MODULE_PARM(mga_contrast, "i");
|
2003-03-21 16:29:04 +00:00
|
|
|
MODULE_PARM(mga_number, "i");
|
|
|
|
MODULE_PARM_DESC(mga_number, "selects matrox device/card (0=first)");
|
2003-03-21 17:59:15 +00:00
|
|
|
MODULE_PARM(major, "i");
|
2001-03-11 22:24:03 +00:00
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
static struct pci_dev *pci_dev;
|
|
|
|
|
|
|
|
static mga_vid_config_t mga_config;
|
|
|
|
|
2002-04-16 20:19:47 +00:00
|
|
|
#ifdef CONFIG_DEVFS_FS
|
|
|
|
static devfs_handle_t dev_handle = NULL;
|
|
|
|
#endif
|
|
|
|
|
2001-10-04 22:25:13 +00:00
|
|
|
static int colkey_saved=0;
|
|
|
|
static int colkey_on=0;
|
|
|
|
static unsigned char colkey_color[4];
|
|
|
|
static unsigned char colkey_mask[4];
|
|
|
|
|
2001-03-07 01:12:18 +00:00
|
|
|
static int mga_irq = -1;
|
2001-02-24 20:28:24 +00:00
|
|
|
|
|
|
|
//All register offsets are converted to word aligned offsets (32 bit)
|
|
|
|
//because we want all our register accesses to be 32 bits
|
|
|
|
#define VCOUNT 0x1e20
|
|
|
|
|
|
|
|
#define PALWTADD 0x3c00 // Index register for X_DATAREG port
|
|
|
|
#define X_DATAREG 0x3c0a
|
|
|
|
|
|
|
|
#define XMULCTRL 0x19
|
|
|
|
#define BPP_8 0x00
|
|
|
|
#define BPP_15 0x01
|
|
|
|
#define BPP_16 0x02
|
|
|
|
#define BPP_24 0x03
|
|
|
|
#define BPP_32_DIR 0x04
|
|
|
|
#define BPP_32_PAL 0x07
|
|
|
|
|
|
|
|
#define XCOLMSK 0x40
|
|
|
|
#define X_COLKEY 0x42
|
|
|
|
#define XKEYOPMODE 0x51
|
|
|
|
#define XCOLMSK0RED 0x52
|
|
|
|
#define XCOLMSK0GREEN 0x53
|
|
|
|
#define XCOLMSK0BLUE 0x54
|
|
|
|
#define XCOLKEY0RED 0x55
|
|
|
|
#define XCOLKEY0GREEN 0x56
|
|
|
|
#define XCOLKEY0BLUE 0x57
|
|
|
|
|
2001-10-21 17:28:04 +00:00
|
|
|
#ifdef CRTC2
|
|
|
|
|
|
|
|
/*CRTC2 registers*/
|
|
|
|
#define XMISCCTRL 0x1e
|
|
|
|
#define C2CTL 0x3c10
|
|
|
|
#define C2DATACTL 0x3c4c
|
|
|
|
#define C2MISC 0x3c44
|
|
|
|
#define C2HPARAM 0x3c14
|
|
|
|
#define C2HSYNC 0x3c18
|
|
|
|
#define C2OFFSET 0x3c40
|
|
|
|
#define C2PL2STARTADD0 0x3c30 // like BESA1CORG
|
|
|
|
#define C2PL2STARTADD1 0x3c34 // like BESA2CORG
|
|
|
|
#define C2PL3STARTADD0 0x3c38 // like BESA1C3ORG
|
|
|
|
#define C2PL3STARTADD1 0x3c3c // like BESA2C3ORG
|
|
|
|
#define C2PRELOAD 0x3c24
|
|
|
|
#define C2SPICSTARTADD0 0x3c54
|
|
|
|
#define C2SPICSTARTADD1 0x3c58
|
|
|
|
#define C2STARTADD0 0x3c28 // like BESA1ORG
|
|
|
|
#define C2STARTADD1 0x3c2c // like BESA2ORG
|
|
|
|
#define C2SUBPICLUT 0x3c50
|
|
|
|
#define C2VCOUNT 0x3c48
|
|
|
|
#define C2VPARAM 0x3c1c
|
|
|
|
#define C2VSYNC 0x3c20
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
// Backend Scaler registers
|
|
|
|
#define BESCTL 0x3d20
|
|
|
|
#define BESGLOBCTL 0x3dc0
|
|
|
|
#define BESLUMACTL 0x3d40
|
|
|
|
#define BESPITCH 0x3d24
|
2001-03-07 01:12:18 +00:00
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
#define BESA1C3ORG 0x3d60
|
|
|
|
#define BESA1CORG 0x3d10
|
|
|
|
#define BESA1ORG 0x3d00
|
2001-03-07 01:12:18 +00:00
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
#define BESA2C3ORG 0x3d64
|
|
|
|
#define BESA2CORG 0x3d14
|
|
|
|
#define BESA2ORG 0x3d04
|
2001-03-07 01:12:18 +00:00
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
#define BESB1C3ORG 0x3d68
|
|
|
|
#define BESB1CORG 0x3d18
|
|
|
|
#define BESB1ORG 0x3d08
|
2001-03-07 01:12:18 +00:00
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
#define BESB2C3ORG 0x3d6C
|
|
|
|
#define BESB2CORG 0x3d1C
|
|
|
|
#define BESB2ORG 0x3d0C
|
2001-03-07 01:12:18 +00:00
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
#define BESHCOORD 0x3d28
|
|
|
|
#define BESHISCAL 0x3d30
|
|
|
|
#define BESHSRCEND 0x3d3C
|
|
|
|
#define BESHSRCLST 0x3d50
|
|
|
|
#define BESHSRCST 0x3d38
|
|
|
|
#define BESV1WGHT 0x3d48
|
|
|
|
#define BESV2WGHT 0x3d4c
|
|
|
|
#define BESV1SRCLST 0x3d54
|
|
|
|
#define BESV2SRCLST 0x3d58
|
|
|
|
#define BESVISCAL 0x3d34
|
|
|
|
#define BESVCOORD 0x3d2c
|
|
|
|
#define BESSTATUS 0x3dc4
|
|
|
|
|
2001-03-07 01:12:18 +00:00
|
|
|
#define CRTCX 0x1fd4
|
|
|
|
#define CRTCD 0x1fd5
|
|
|
|
#define IEN 0x1e1c
|
|
|
|
#define ICLEAR 0x1e18
|
|
|
|
#define STATUS 0x1e14
|
|
|
|
|
|
|
|
static int mga_next_frame=0;
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2001-10-21 17:28:04 +00:00
|
|
|
#ifdef CRTC2
|
|
|
|
static void crtc2_frame_sel(int frame)
|
|
|
|
{
|
|
|
|
switch(frame) {
|
|
|
|
case 0:
|
|
|
|
cregs.c2pl2startadd0=regs.besa1corg;
|
|
|
|
cregs.c2pl3startadd0=regs.besa1c3org;
|
|
|
|
cregs.c2startadd0=regs.besa1org;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
cregs.c2pl2startadd0=regs.besa2corg;
|
|
|
|
cregs.c2pl3startadd0=regs.besa2c3org;
|
|
|
|
cregs.c2startadd0=regs.besa2org;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
cregs.c2pl2startadd0=regs.besb1corg;
|
|
|
|
cregs.c2pl3startadd0=regs.besb1c3org;
|
|
|
|
cregs.c2startadd0=regs.besb1org;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
cregs.c2pl2startadd0=regs.besb2corg;
|
|
|
|
cregs.c2pl3startadd0=regs.besb2c3org;
|
|
|
|
cregs.c2startadd0=regs.besb2org;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
writel(cregs.c2startadd0, mga_mmio_base + C2STARTADD0);
|
|
|
|
writel(cregs.c2pl2startadd0, mga_mmio_base + C2PL2STARTADD0);
|
|
|
|
writel(cregs.c2pl3startadd0, mga_mmio_base + C2PL3STARTADD0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
static void mga_vid_frame_sel(int frame)
|
|
|
|
{
|
2001-03-07 01:12:18 +00:00
|
|
|
if ( mga_irq != -1 ) {
|
|
|
|
mga_next_frame=frame;
|
|
|
|
} else {
|
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
//we don't need the vcount protection as we're only hitting
|
|
|
|
//one register (and it doesn't seem to be double buffered)
|
|
|
|
regs.besctl = (regs.besctl & ~0x07000000) + (frame << 25);
|
|
|
|
writel( regs.besctl, mga_mmio_base + BESCTL );
|
2001-03-10 02:27:50 +00:00
|
|
|
|
|
|
|
// writel( regs.besglobctl + ((readl(mga_mmio_base + VCOUNT)+2)<<16),
|
|
|
|
writel( regs.besglobctl + (MGA_VSYNC_POS<<16),
|
|
|
|
mga_mmio_base + BESGLOBCTL);
|
2001-10-21 17:28:04 +00:00
|
|
|
#ifdef CRTC2
|
|
|
|
crtc2_frame_sel(frame);
|
|
|
|
#endif
|
2001-03-10 02:27:50 +00:00
|
|
|
|
2001-03-07 01:12:18 +00:00
|
|
|
}
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-04 22:25:13 +00:00
|
|
|
static void mga_vid_write_regs(int restore)
|
2001-02-24 20:28:24 +00:00
|
|
|
{
|
|
|
|
//Make sure internal registers don't get updated until we're done
|
|
|
|
writel( (readl(mga_mmio_base + VCOUNT)-1)<<16,
|
|
|
|
mga_mmio_base + BESGLOBCTL);
|
|
|
|
|
|
|
|
// color or coordinate keying
|
2001-10-04 22:25:13 +00:00
|
|
|
|
|
|
|
if(restore && colkey_saved){
|
|
|
|
// restore it
|
|
|
|
colkey_saved=0;
|
|
|
|
|
2002-04-14 23:14:26 +00:00
|
|
|
#ifdef MP_DEBUG
|
2001-10-04 22:25:13 +00:00
|
|
|
printk("mga_vid: Restoring colorkey (ON: %d %02X:%02X:%02X)\n",
|
|
|
|
colkey_on,colkey_color[0],colkey_color[1],colkey_color[2]);
|
2002-04-14 23:14:26 +00:00
|
|
|
#endif
|
2001-10-04 22:25:13 +00:00
|
|
|
|
|
|
|
// Set color key registers:
|
|
|
|
writeb( XKEYOPMODE, mga_mmio_base + PALWTADD);
|
|
|
|
writeb( colkey_on, mga_mmio_base + X_DATAREG);
|
|
|
|
|
|
|
|
writeb( XCOLKEY0RED, mga_mmio_base + PALWTADD);
|
|
|
|
writeb( colkey_color[0], mga_mmio_base + X_DATAREG);
|
|
|
|
writeb( XCOLKEY0GREEN, mga_mmio_base + PALWTADD);
|
|
|
|
writeb( colkey_color[1], mga_mmio_base + X_DATAREG);
|
|
|
|
writeb( XCOLKEY0BLUE, mga_mmio_base + PALWTADD);
|
|
|
|
writeb( colkey_color[2], mga_mmio_base + X_DATAREG);
|
|
|
|
writeb( X_COLKEY, mga_mmio_base + PALWTADD);
|
|
|
|
writeb( colkey_color[3], mga_mmio_base + X_DATAREG);
|
|
|
|
|
|
|
|
writeb( XCOLMSK0RED, mga_mmio_base + PALWTADD);
|
|
|
|
writeb( colkey_mask[0], mga_mmio_base + X_DATAREG);
|
|
|
|
writeb( XCOLMSK0GREEN, mga_mmio_base + PALWTADD);
|
|
|
|
writeb( colkey_mask[1], mga_mmio_base + X_DATAREG);
|
|
|
|
writeb( XCOLMSK0BLUE, mga_mmio_base + PALWTADD);
|
|
|
|
writeb( colkey_mask[2], mga_mmio_base + X_DATAREG);
|
|
|
|
writeb( XCOLMSK, mga_mmio_base + PALWTADD);
|
|
|
|
writeb( colkey_mask[3], mga_mmio_base + X_DATAREG);
|
|
|
|
|
|
|
|
} else if(!colkey_saved){
|
|
|
|
// save it
|
|
|
|
colkey_saved=1;
|
|
|
|
// Get color key registers:
|
|
|
|
writeb( XKEYOPMODE, mga_mmio_base + PALWTADD);
|
|
|
|
colkey_on=(unsigned char)readb(mga_mmio_base + X_DATAREG) & 1;
|
|
|
|
|
|
|
|
writeb( XCOLKEY0RED, mga_mmio_base + PALWTADD);
|
|
|
|
colkey_color[0]=(unsigned char)readb(mga_mmio_base + X_DATAREG);
|
|
|
|
writeb( XCOLKEY0GREEN, mga_mmio_base + PALWTADD);
|
|
|
|
colkey_color[1]=(unsigned char)readb(mga_mmio_base + X_DATAREG);
|
|
|
|
writeb( XCOLKEY0BLUE, mga_mmio_base + PALWTADD);
|
|
|
|
colkey_color[2]=(unsigned char)readb(mga_mmio_base + X_DATAREG);
|
|
|
|
writeb( X_COLKEY, mga_mmio_base + PALWTADD);
|
|
|
|
colkey_color[3]=(unsigned char)readb(mga_mmio_base + X_DATAREG);
|
|
|
|
|
|
|
|
writeb( XCOLMSK0RED, mga_mmio_base + PALWTADD);
|
|
|
|
colkey_mask[0]=(unsigned char)readb(mga_mmio_base + X_DATAREG);
|
|
|
|
writeb( XCOLMSK0GREEN, mga_mmio_base + PALWTADD);
|
|
|
|
colkey_mask[1]=(unsigned char)readb(mga_mmio_base + X_DATAREG);
|
|
|
|
writeb( XCOLMSK0BLUE, mga_mmio_base + PALWTADD);
|
|
|
|
colkey_mask[2]=(unsigned char)readb(mga_mmio_base + X_DATAREG);
|
|
|
|
writeb( XCOLMSK, mga_mmio_base + PALWTADD);
|
|
|
|
colkey_mask[3]=(unsigned char)readb(mga_mmio_base + X_DATAREG);
|
|
|
|
|
2002-04-14 23:14:26 +00:00
|
|
|
#ifdef MP_DEBUG
|
2001-10-04 22:25:13 +00:00
|
|
|
printk("mga_vid: Saved colorkey (ON: %d %02X:%02X:%02X)\n",
|
|
|
|
colkey_on,colkey_color[0],colkey_color[1],colkey_color[2]);
|
2002-04-14 23:14:26 +00:00
|
|
|
#endif
|
2001-10-04 22:25:13 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!restore){
|
2001-02-24 20:28:24 +00:00
|
|
|
writeb( XKEYOPMODE, mga_mmio_base + PALWTADD);
|
|
|
|
writeb( mga_config.colkey_on, mga_mmio_base + X_DATAREG);
|
|
|
|
if ( mga_config.colkey_on )
|
|
|
|
{
|
|
|
|
uint32_t r=0, g=0, b=0;
|
|
|
|
|
|
|
|
writeb( XMULCTRL, mga_mmio_base + PALWTADD);
|
|
|
|
switch (readb (mga_mmio_base + X_DATAREG))
|
|
|
|
{
|
|
|
|
case BPP_8:
|
|
|
|
/* Need to look up the color index, just using
|
|
|
|
color 0 for now. */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BPP_15:
|
|
|
|
r = mga_config.colkey_red >> 3;
|
|
|
|
g = mga_config.colkey_green >> 3;
|
|
|
|
b = mga_config.colkey_blue >> 3;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BPP_16:
|
|
|
|
r = mga_config.colkey_red >> 3;
|
|
|
|
g = mga_config.colkey_green >> 2;
|
|
|
|
b = mga_config.colkey_blue >> 3;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BPP_24:
|
|
|
|
case BPP_32_DIR:
|
|
|
|
case BPP_32_PAL:
|
|
|
|
r = mga_config.colkey_red;
|
|
|
|
g = mga_config.colkey_green;
|
|
|
|
b = mga_config.colkey_blue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disable color keying on alpha channel
|
|
|
|
writeb( XCOLMSK, mga_mmio_base + PALWTADD);
|
|
|
|
writeb( 0x00, mga_mmio_base + X_DATAREG);
|
|
|
|
writeb( X_COLKEY, mga_mmio_base + PALWTADD);
|
|
|
|
writeb( 0x00, mga_mmio_base + X_DATAREG);
|
|
|
|
|
2001-10-04 22:25:13 +00:00
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
// Set up color key registers
|
|
|
|
writeb( XCOLKEY0RED, mga_mmio_base + PALWTADD);
|
|
|
|
writeb( r, mga_mmio_base + X_DATAREG);
|
|
|
|
writeb( XCOLKEY0GREEN, mga_mmio_base + PALWTADD);
|
|
|
|
writeb( g, mga_mmio_base + X_DATAREG);
|
|
|
|
writeb( XCOLKEY0BLUE, mga_mmio_base + PALWTADD);
|
|
|
|
writeb( b, mga_mmio_base + X_DATAREG);
|
|
|
|
|
|
|
|
// Set up color key mask registers
|
|
|
|
writeb( XCOLMSK0RED, mga_mmio_base + PALWTADD);
|
|
|
|
writeb( 0xff, mga_mmio_base + X_DATAREG);
|
|
|
|
writeb( XCOLMSK0GREEN, mga_mmio_base + PALWTADD);
|
|
|
|
writeb( 0xff, mga_mmio_base + X_DATAREG);
|
|
|
|
writeb( XCOLMSK0BLUE, mga_mmio_base + PALWTADD);
|
|
|
|
writeb( 0xff, mga_mmio_base + X_DATAREG);
|
|
|
|
}
|
|
|
|
|
2001-10-04 22:25:13 +00:00
|
|
|
}
|
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
// Backend Scaler
|
|
|
|
writel( regs.besctl, mga_mmio_base + BESCTL);
|
|
|
|
if(is_g400)
|
|
|
|
writel( regs.beslumactl, mga_mmio_base + BESLUMACTL);
|
|
|
|
writel( regs.bespitch, mga_mmio_base + BESPITCH);
|
|
|
|
|
|
|
|
writel( regs.besa1org, mga_mmio_base + BESA1ORG);
|
|
|
|
writel( regs.besa1corg, mga_mmio_base + BESA1CORG);
|
2001-03-07 01:12:18 +00:00
|
|
|
writel( regs.besa2org, mga_mmio_base + BESA2ORG);
|
|
|
|
writel( regs.besa2corg, mga_mmio_base + BESA2CORG);
|
2001-02-24 20:28:24 +00:00
|
|
|
writel( regs.besb1org, mga_mmio_base + BESB1ORG);
|
|
|
|
writel( regs.besb1corg, mga_mmio_base + BESB1CORG);
|
2001-03-07 01:12:18 +00:00
|
|
|
writel( regs.besb2org, mga_mmio_base + BESB2ORG);
|
|
|
|
writel( regs.besb2corg, mga_mmio_base + BESB2CORG);
|
2001-02-24 20:28:24 +00:00
|
|
|
if(is_g400)
|
|
|
|
{
|
|
|
|
writel( regs.besa1c3org, mga_mmio_base + BESA1C3ORG);
|
2001-03-07 01:12:18 +00:00
|
|
|
writel( regs.besa2c3org, mga_mmio_base + BESA2C3ORG);
|
2001-02-24 20:28:24 +00:00
|
|
|
writel( regs.besb1c3org, mga_mmio_base + BESB1C3ORG);
|
2001-03-07 01:12:18 +00:00
|
|
|
writel( regs.besb2c3org, mga_mmio_base + BESB2C3ORG);
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
writel( regs.beshcoord, mga_mmio_base + BESHCOORD);
|
|
|
|
writel( regs.beshiscal, mga_mmio_base + BESHISCAL);
|
|
|
|
writel( regs.beshsrcst, mga_mmio_base + BESHSRCST);
|
|
|
|
writel( regs.beshsrcend, mga_mmio_base + BESHSRCEND);
|
|
|
|
writel( regs.beshsrclst, mga_mmio_base + BESHSRCLST);
|
|
|
|
|
|
|
|
writel( regs.besvcoord, mga_mmio_base + BESVCOORD);
|
|
|
|
writel( regs.besviscal, mga_mmio_base + BESVISCAL);
|
2001-03-07 01:12:18 +00:00
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
writel( regs.besv1srclst, mga_mmio_base + BESV1SRCLST);
|
|
|
|
writel( regs.besv1wght, mga_mmio_base + BESV1WGHT);
|
2001-03-07 01:12:18 +00:00
|
|
|
writel( regs.besv2srclst, mga_mmio_base + BESV2SRCLST);
|
|
|
|
writel( regs.besv2wght, mga_mmio_base + BESV2WGHT);
|
2001-02-24 20:28:24 +00:00
|
|
|
|
|
|
|
//update the registers somewhere between 1 and 2 frames from now.
|
|
|
|
writel( regs.besglobctl + ((readl(mga_mmio_base + VCOUNT)+2)<<16),
|
|
|
|
mga_mmio_base + BESGLOBCTL);
|
|
|
|
|
2001-03-11 00:13:43 +00:00
|
|
|
#if 0
|
2001-03-09 00:31:22 +00:00
|
|
|
printk(KERN_DEBUG "mga_vid: wrote BES registers\n");
|
|
|
|
printk(KERN_DEBUG "mga_vid: BESCTL = 0x%08x\n",
|
2001-02-24 20:28:24 +00:00
|
|
|
readl(mga_mmio_base + BESCTL));
|
2001-03-09 00:31:22 +00:00
|
|
|
printk(KERN_DEBUG "mga_vid: BESGLOBCTL = 0x%08x\n",
|
2001-02-24 20:28:24 +00:00
|
|
|
readl(mga_mmio_base + BESGLOBCTL));
|
2001-03-09 00:31:22 +00:00
|
|
|
printk(KERN_DEBUG "mga_vid: BESSTATUS= 0x%08x\n",
|
2001-02-24 20:28:24 +00:00
|
|
|
readl(mga_mmio_base + BESSTATUS));
|
2001-03-11 00:13:43 +00:00
|
|
|
#endif
|
2001-10-21 17:28:04 +00:00
|
|
|
#ifdef CRTC2
|
|
|
|
// printk("c2ctl:0x%08x c2datactl:0x%08x\n",readl(mga_mmio_base + C2CTL),readl(mga_mmio_base + C2DATACTL));
|
|
|
|
// printk("c2misc:0x%08x\n",readl(mga_mmio_base + C2MISC));
|
|
|
|
// printk("c2ctl:0x%08x c2datactl:0x%08x\n",cregs.c2ctl,cregs.c2datactl);
|
|
|
|
|
|
|
|
// writel(cregs.c2ctl, mga_mmio_base + C2CTL);
|
|
|
|
|
|
|
|
writel(((readl(mga_mmio_base + C2CTL) & ~0x03e00000) + (cregs.c2ctl & 0x03e00000)), mga_mmio_base + C2CTL);
|
|
|
|
writel(((readl(mga_mmio_base + C2DATACTL) & ~0x000000ff) + (cregs.c2datactl & 0x000000ff)), mga_mmio_base + C2DATACTL);
|
|
|
|
// ctrc2
|
|
|
|
// disable CRTC2 acording to specs
|
|
|
|
// writel(cregs.c2ctl & 0xfffffff0, mga_mmio_base + C2CTL);
|
|
|
|
// je to treba ???
|
|
|
|
// writeb((readb(mga_mmio_base + XMISCCTRL) & 0x19) | 0xa2, mga_mmio_base + XMISCCTRL); // MAFC - mfcsel & vdoutsel
|
|
|
|
// writeb((readb(mga_mmio_base + XMISCCTRL) & 0x19) | 0x92, mga_mmio_base + XMISCCTRL);
|
|
|
|
// writeb((readb(mga_mmio_base + XMISCCTRL) & ~0xe9) + 0xa2, mga_mmio_base + XMISCCTRL);
|
|
|
|
// writel(cregs.c2datactl, mga_mmio_base + C2DATACTL);
|
|
|
|
// writel(cregs.c2hparam, mga_mmio_base + C2HPARAM);
|
|
|
|
// writel(cregs.c2hsync, mga_mmio_base + C2HSYNC);
|
|
|
|
// writel(cregs.c2vparam, mga_mmio_base + C2VPARAM);
|
|
|
|
// writel(cregs.c2vsync, mga_mmio_base + C2VSYNC);
|
|
|
|
writel(cregs.c2misc, mga_mmio_base + C2MISC);
|
|
|
|
|
2002-04-14 23:14:26 +00:00
|
|
|
#ifdef MP_DEBUG
|
2001-10-21 17:28:04 +00:00
|
|
|
printk("c2offset = %d\n",cregs.c2offset);
|
2002-04-14 23:14:26 +00:00
|
|
|
#endif
|
2001-10-21 17:28:04 +00:00
|
|
|
|
|
|
|
writel(cregs.c2offset, mga_mmio_base + C2OFFSET);
|
|
|
|
writel(cregs.c2startadd0, mga_mmio_base + C2STARTADD0);
|
|
|
|
// writel(cregs.c2startadd1, mga_mmio_base + C2STARTADD1);
|
|
|
|
writel(cregs.c2pl2startadd0, mga_mmio_base + C2PL2STARTADD0);
|
|
|
|
// writel(cregs.c2pl2startadd1, mga_mmio_base + C2PL2STARTADD1);
|
|
|
|
writel(cregs.c2pl3startadd0, mga_mmio_base + C2PL3STARTADD0);
|
|
|
|
// writel(cregs.c2pl3startadd1, mga_mmio_base + C2PL3STARTADD1);
|
|
|
|
writel(cregs.c2spicstartadd0, mga_mmio_base + C2SPICSTARTADD0);
|
|
|
|
// writel(cregs.c2spicstartadd1, mga_mmio_base + C2SPICSTARTADD1);
|
|
|
|
// writel(cregs.c2subpiclut, mga_mmio_base + C2SUBPICLUT);
|
|
|
|
// writel(cregs.c2preload, mga_mmio_base + C2PRELOAD);
|
|
|
|
// finaly enable everything
|
|
|
|
// writel(cregs.c2ctl, mga_mmio_base + C2CTL);
|
|
|
|
// printk("c2ctl:0x%08x c2datactl:0x%08x\n",readl(mga_mmio_base + C2CTL),readl(mga_mmio_base + C2DATACTL));
|
|
|
|
// printk("c2misc:0x%08x\n", readl(mga_mmio_base + C2MISC));
|
|
|
|
#endif
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mga_vid_set_config(mga_vid_config_t *config)
|
|
|
|
{
|
|
|
|
int x, y, sw, sh, dw, dh;
|
|
|
|
int besleft, bestop, ifactor, ofsleft, ofstop, baseadrofs, weight, weights;
|
2001-03-08 01:06:59 +00:00
|
|
|
int frame_size=config->frame_size;
|
2001-10-21 17:28:04 +00:00
|
|
|
#ifdef CRTC2
|
|
|
|
#define right_margin 0
|
|
|
|
#define left_margin 18
|
|
|
|
#define hsync_len 46
|
|
|
|
#define lower_margin 10
|
|
|
|
#define vsync_len 4
|
|
|
|
#define upper_margin 39
|
|
|
|
|
|
|
|
unsigned int hdispend = (config->src_width + 31) & ~31;
|
|
|
|
unsigned int hsyncstart = hdispend + (right_margin & ~7);
|
|
|
|
unsigned int hsyncend = hsyncstart + (hsync_len & ~7);
|
|
|
|
unsigned int htotal = hsyncend + (left_margin & ~7);
|
|
|
|
unsigned int vdispend = config->src_height;
|
|
|
|
unsigned int vsyncstart = vdispend + lower_margin;
|
|
|
|
unsigned int vsyncend = vsyncstart + vsync_len;
|
|
|
|
unsigned int vtotal = vsyncend + upper_margin;
|
|
|
|
#endif
|
2001-02-24 20:28:24 +00:00
|
|
|
x = config->x_org;
|
|
|
|
y = config->y_org;
|
|
|
|
sw = config->src_width;
|
|
|
|
sh = config->src_height;
|
|
|
|
dw = config->dest_width;
|
|
|
|
dh = config->dest_height;
|
|
|
|
|
2002-04-14 23:14:26 +00:00
|
|
|
#ifdef MP_DEBUG
|
2001-03-09 00:31:22 +00:00
|
|
|
printk(KERN_DEBUG "mga_vid: Setting up a %dx%d+%d+%d video window (src %dx%d) format %X\n",
|
2001-02-24 20:28:24 +00:00
|
|
|
dw, dh, x, y, sw, sh, config->format);
|
2002-04-14 23:14:26 +00:00
|
|
|
#endif
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2002-01-02 23:38:16 +00:00
|
|
|
if(sw<4 || sh<4 || dw<4 || dh<4){
|
|
|
|
printk(KERN_ERR "mga_vid: Invalid src/dest dimenstions\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
//FIXME check that window is valid and inside desktop
|
|
|
|
|
|
|
|
//FIXME figure out a better way to allocate memory on card
|
|
|
|
//allocate 2 megs
|
|
|
|
//mga_src_base = mga_mem_base + (MGA_VIDMEM_SIZE-2) * 0x100000;
|
2001-03-08 01:06:59 +00:00
|
|
|
//mga_src_base = (MGA_VIDMEM_SIZE-3) * 0x100000;
|
2001-02-24 20:28:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
//Setup the BES registers for a three plane 4:2:0 video source
|
|
|
|
|
2001-04-16 01:26:08 +00:00
|
|
|
regs.besglobctl = 0;
|
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
switch(config->format){
|
|
|
|
case MGA_VID_FORMAT_YV12:
|
2001-04-16 03:33:35 +00:00
|
|
|
case MGA_VID_FORMAT_I420:
|
|
|
|
case MGA_VID_FORMAT_IYUV:
|
2001-02-24 20:28:24 +00:00
|
|
|
regs.besctl = 1 // BES enabled
|
|
|
|
+ (0<<6) // even start polarity
|
|
|
|
+ (1<<10) // x filtering enabled
|
|
|
|
+ (1<<11) // y filtering enabled
|
|
|
|
+ (1<<16) // chroma upsampling
|
|
|
|
+ (1<<17) // 4:2:0 mode
|
|
|
|
+ (1<<18); // dither enabled
|
2001-04-16 01:26:08 +00:00
|
|
|
#if 0
|
2001-02-24 20:28:24 +00:00
|
|
|
if(is_g400)
|
|
|
|
{
|
|
|
|
//zoom disabled, zoom filter disabled, 420 3 plane format, proc amp
|
|
|
|
//disabled, rgb mode disabled
|
|
|
|
regs.besglobctl = (1<<5);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//zoom disabled, zoom filter disabled, Cb samples in 0246, Cr
|
|
|
|
//in 1357, BES register update on besvcnt
|
2001-04-16 01:26:08 +00:00
|
|
|
regs.besglobctl = 0;
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
2001-04-16 01:26:08 +00:00
|
|
|
#endif
|
2001-02-24 20:28:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MGA_VID_FORMAT_YUY2:
|
|
|
|
regs.besctl = 1 // BES enabled
|
|
|
|
+ (0<<6) // even start polarity
|
|
|
|
+ (1<<10) // x filtering enabled
|
|
|
|
+ (1<<11) // y filtering enabled
|
|
|
|
+ (1<<16) // chroma upsampling
|
|
|
|
+ (0<<17) // 4:2:2 mode
|
|
|
|
+ (1<<18); // dither enabled
|
|
|
|
|
|
|
|
regs.besglobctl = 0; // YUY2 format selected
|
|
|
|
break;
|
2001-04-16 01:26:08 +00:00
|
|
|
|
|
|
|
case MGA_VID_FORMAT_UYVY:
|
|
|
|
regs.besctl = 1 // BES enabled
|
|
|
|
+ (0<<6) // even start polarity
|
|
|
|
+ (1<<10) // x filtering enabled
|
|
|
|
+ (1<<11) // y filtering enabled
|
|
|
|
+ (1<<16) // chroma upsampling
|
|
|
|
+ (0<<17) // 4:2:2 mode
|
|
|
|
+ (1<<18); // dither enabled
|
|
|
|
|
|
|
|
regs.besglobctl = 1<<6; // UYVY format selected
|
|
|
|
break;
|
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
default:
|
2001-03-09 00:31:22 +00:00
|
|
|
printk(KERN_ERR "mga_vid: Unsupported pixel format: 0x%X\n",config->format);
|
2001-02-24 20:28:24 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2002-02-02 20:49:52 +00:00
|
|
|
// setting black&white mode
|
2002-02-02 21:39:25 +00:00
|
|
|
regs.besctl|=(regs.blackie<<20);
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2002-02-02 20:49:52 +00:00
|
|
|
//Enable contrast and brightness control
|
2001-04-16 01:26:08 +00:00
|
|
|
regs.besglobctl |= (1<<5) + (1<<7);
|
2002-02-02 20:49:52 +00:00
|
|
|
|
2002-07-25 21:34:24 +00:00
|
|
|
// brightness (-128..127) && contrast (0..255)
|
|
|
|
regs.beslumactl = (mga_brightness << 16) | ((mga_contrast+0x80)&0xFFFF);
|
2001-02-24 20:28:24 +00:00
|
|
|
|
|
|
|
//Setup destination window boundaries
|
|
|
|
besleft = x > 0 ? x : 0;
|
|
|
|
bestop = y > 0 ? y : 0;
|
|
|
|
regs.beshcoord = (besleft<<16) + (x + dw-1);
|
|
|
|
regs.besvcoord = (bestop<<16) + (y + dh-1);
|
|
|
|
|
|
|
|
//Setup source dimensions
|
|
|
|
regs.beshsrclst = (sw - 1) << 16;
|
|
|
|
regs.bespitch = (sw + 31) & ~31 ;
|
|
|
|
|
|
|
|
//Setup horizontal scaling
|
|
|
|
ifactor = ((sw-1)<<14)/(dw-1);
|
|
|
|
ofsleft = besleft - x;
|
|
|
|
|
|
|
|
regs.beshiscal = ifactor<<2;
|
|
|
|
regs.beshsrcst = (ofsleft*ifactor)<<2;
|
|
|
|
regs.beshsrcend = regs.beshsrcst + (((dw - ofsleft - 1) * ifactor) << 2);
|
|
|
|
|
|
|
|
//Setup vertical scaling
|
|
|
|
ifactor = ((sh-1)<<14)/(dh-1);
|
|
|
|
ofstop = bestop - y;
|
|
|
|
|
|
|
|
regs.besviscal = ifactor<<2;
|
|
|
|
|
|
|
|
baseadrofs = ((ofstop*regs.besviscal)>>16)*regs.bespitch;
|
2001-03-08 01:06:59 +00:00
|
|
|
//frame_size = ((sw + 31) & ~31) * sh + (((sw + 31) & ~31) * sh) / 2;
|
2001-02-24 20:28:24 +00:00
|
|
|
regs.besa1org = (uint32_t) mga_src_base + baseadrofs;
|
2001-03-07 01:12:18 +00:00
|
|
|
regs.besa2org = (uint32_t) mga_src_base + baseadrofs + 1*frame_size;
|
|
|
|
regs.besb1org = (uint32_t) mga_src_base + baseadrofs + 2*frame_size;
|
|
|
|
regs.besb2org = (uint32_t) mga_src_base + baseadrofs + 3*frame_size;
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2001-04-16 03:33:35 +00:00
|
|
|
if(config->format==MGA_VID_FORMAT_YV12
|
|
|
|
||config->format==MGA_VID_FORMAT_IYUV
|
|
|
|
||config->format==MGA_VID_FORMAT_I420
|
|
|
|
){
|
2001-03-08 01:06:59 +00:00
|
|
|
// planar YUV frames:
|
2001-02-24 20:28:24 +00:00
|
|
|
if (is_g400)
|
|
|
|
baseadrofs = (((ofstop*regs.besviscal)/4)>>16)*regs.bespitch;
|
|
|
|
else
|
|
|
|
baseadrofs = (((ofstop*regs.besviscal)/2)>>16)*regs.bespitch;
|
|
|
|
|
2002-03-25 16:22:15 +00:00
|
|
|
if(config->format==MGA_VID_FORMAT_YV12 || !is_g400){
|
2001-02-24 20:28:24 +00:00
|
|
|
regs.besa1corg = (uint32_t) mga_src_base + baseadrofs + regs.bespitch * sh ;
|
2001-03-07 01:12:18 +00:00
|
|
|
regs.besa2corg = (uint32_t) mga_src_base + baseadrofs + 1*frame_size + regs.bespitch * sh;
|
|
|
|
regs.besb1corg = (uint32_t) mga_src_base + baseadrofs + 2*frame_size + regs.bespitch * sh;
|
|
|
|
regs.besb2corg = (uint32_t) mga_src_base + baseadrofs + 3*frame_size + regs.bespitch * sh;
|
2001-02-24 20:28:24 +00:00
|
|
|
regs.besa1c3org = regs.besa1corg + ((regs.bespitch * sh) / 4);
|
2001-03-07 01:12:18 +00:00
|
|
|
regs.besa2c3org = regs.besa2corg + ((regs.bespitch * sh) / 4);
|
2001-02-24 20:28:24 +00:00
|
|
|
regs.besb1c3org = regs.besb1corg + ((regs.bespitch * sh) / 4);
|
2001-03-07 01:12:18 +00:00
|
|
|
regs.besb2c3org = regs.besb2corg + ((regs.bespitch * sh) / 4);
|
2001-04-16 03:33:35 +00:00
|
|
|
} else {
|
|
|
|
regs.besa1c3org = (uint32_t) mga_src_base + baseadrofs + regs.bespitch * sh ;
|
|
|
|
regs.besa2c3org = (uint32_t) mga_src_base + baseadrofs + 1*frame_size + regs.bespitch * sh;
|
|
|
|
regs.besb1c3org = (uint32_t) mga_src_base + baseadrofs + 2*frame_size + regs.bespitch * sh;
|
|
|
|
regs.besb2c3org = (uint32_t) mga_src_base + baseadrofs + 3*frame_size + regs.bespitch * sh;
|
|
|
|
regs.besa1corg = regs.besa1c3org + ((regs.bespitch * sh) / 4);
|
|
|
|
regs.besa2corg = regs.besa2c3org + ((regs.bespitch * sh) / 4);
|
|
|
|
regs.besb1corg = regs.besb1c3org + ((regs.bespitch * sh) / 4);
|
|
|
|
regs.besb2corg = regs.besb2c3org + ((regs.bespitch * sh) / 4);
|
|
|
|
}
|
|
|
|
|
2001-03-08 01:06:59 +00:00
|
|
|
}
|
2001-02-24 20:28:24 +00:00
|
|
|
|
|
|
|
weight = ofstop * (regs.besviscal >> 2);
|
|
|
|
weights = weight < 0 ? 1 : 0;
|
2001-03-07 01:12:18 +00:00
|
|
|
regs.besv2wght = regs.besv1wght = (weights << 16) + ((weight & 0x3FFF) << 2);
|
|
|
|
regs.besv2srclst = regs.besv1srclst = sh - 1 - (((ofstop * regs.besviscal) >> 16) & 0x03FF);
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2001-10-21 17:28:04 +00:00
|
|
|
#ifdef CRTC2
|
|
|
|
// pridat hlavni registry - tj. casovani ...
|
|
|
|
|
|
|
|
|
|
|
|
switch(config->format){
|
|
|
|
case MGA_VID_FORMAT_YV12:
|
|
|
|
case MGA_VID_FORMAT_I420:
|
|
|
|
case MGA_VID_FORMAT_IYUV:
|
|
|
|
cregs.c2ctl = 1 // CRTC2 enabled
|
|
|
|
+ (1<<1) // external clock
|
|
|
|
+ (0<<2) // external clock
|
|
|
|
+ (1<<3) // pixel clock enable - not needed ???
|
|
|
|
+ (0<<4) // high prioryty req
|
|
|
|
+ (1<<5) // high prioryty req
|
|
|
|
+ (0<<6) // high prioryty req
|
|
|
|
+ (1<<8) // high prioryty req max
|
|
|
|
+ (0<<9) // high prioryty req max
|
|
|
|
+ (0<<10) // high prioryty req max
|
|
|
|
+ (0<<20) // CRTC1 to DAC
|
|
|
|
+ (1<<21) // 420 mode
|
|
|
|
+ (1<<22) // 420 mode
|
|
|
|
+ (1<<23) // 420 mode
|
|
|
|
+ (0<<24) // single chroma line for 420 mode - need to be corrected
|
|
|
|
+ (0<<25) /*/ interlace mode - need to be corrected*/
|
|
|
|
+ (0<<26) // field legth polariry
|
|
|
|
+ (0<<27) // field identification polariry
|
|
|
|
+ (1<<28) // VIDRST detection mode
|
|
|
|
+ (0<<29) // VIDRST detection mode
|
|
|
|
+ (1<<30) // Horizontal counter preload
|
|
|
|
+ (1<<31) // Vertical counter preload
|
|
|
|
;
|
|
|
|
cregs.c2datactl = 1 // disable dither - propably not needed, we are already in YUV mode
|
|
|
|
+ (1<<1) // Y filter enable
|
|
|
|
+ (1<<2) // CbCr filter enable
|
|
|
|
+ (0<<3) // subpicture enable (disabled)
|
|
|
|
+ (0<<4) // NTSC enable (disabled - PAL)
|
|
|
|
+ (0<<5) // C2 static subpicture enable (disabled)
|
|
|
|
+ (0<<6) // C2 subpicture offset division (disabled)
|
|
|
|
+ (0<<7) // 422 subformat selection !
|
|
|
|
/* + (0<<8) // 15 bpp high alpha
|
|
|
|
+ (0<<9) // 15 bpp high alpha
|
|
|
|
+ (0<<10) // 15 bpp high alpha
|
|
|
|
+ (0<<11) // 15 bpp high alpha
|
|
|
|
+ (0<<12) // 15 bpp high alpha
|
|
|
|
+ (0<<13) // 15 bpp high alpha
|
|
|
|
+ (0<<14) // 15 bpp high alpha
|
|
|
|
+ (0<<15) // 15 bpp high alpha
|
|
|
|
+ (0<<16) // 15 bpp low alpha
|
|
|
|
+ (0<<17) // 15 bpp low alpha
|
|
|
|
+ (0<<18) // 15 bpp low alpha
|
|
|
|
+ (0<<19) // 15 bpp low alpha
|
|
|
|
+ (0<<20) // 15 bpp low alpha
|
|
|
|
+ (0<<21) // 15 bpp low alpha
|
|
|
|
+ (0<<22) // 15 bpp low alpha
|
|
|
|
+ (0<<23) // 15 bpp low alpha
|
|
|
|
+ (0<<24) // static subpicture key
|
|
|
|
+ (0<<25) // static subpicture key
|
|
|
|
+ (0<<26) // static subpicture key
|
|
|
|
+ (0<<27) // static subpicture key
|
|
|
|
+ (0<<28) // static subpicture key
|
|
|
|
*/ ;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MGA_VID_FORMAT_YUY2:
|
|
|
|
cregs.c2ctl = 1 // CRTC2 enabled
|
|
|
|
+ (1<<1) // external clock
|
|
|
|
+ (0<<2) // external clock
|
|
|
|
+ (1<<3) // pixel clock enable - not needed ???
|
|
|
|
+ (0<<4) // high prioryty req - acc to spec
|
|
|
|
+ (1<<5) // high prioryty req
|
|
|
|
+ (0<<6) // high prioryty req
|
|
|
|
// 7 reserved
|
|
|
|
+ (1<<8) // high prioryty req max
|
|
|
|
+ (0<<9) // high prioryty req max
|
|
|
|
+ (0<<10) // high prioryty req max
|
|
|
|
// 11-19 reserved
|
|
|
|
+ (0<<20) // CRTC1 to DAC
|
|
|
|
+ (1<<21) // 422 mode
|
|
|
|
+ (0<<22) // 422 mode
|
|
|
|
+ (1<<23) // 422 mode
|
|
|
|
+ (0<<24) // single chroma line for 420 mode - need to be corrected
|
|
|
|
+ (0<<25) /*/ interlace mode - need to be corrected*/
|
|
|
|
+ (0<<26) // field legth polariry
|
|
|
|
+ (0<<27) // field identification polariry
|
|
|
|
+ (1<<28) // VIDRST detection mode
|
|
|
|
+ (0<<29) // VIDRST detection mode
|
|
|
|
+ (1<<30) // Horizontal counter preload
|
|
|
|
+ (1<<31) // Vertical counter preload
|
|
|
|
;
|
|
|
|
cregs.c2datactl = 1 // disable dither - propably not needed, we are already in YUV mode
|
|
|
|
+ (1<<1) // Y filter enable
|
|
|
|
+ (1<<2) // CbCr filter enable
|
|
|
|
+ (0<<3) // subpicture enable (disabled)
|
|
|
|
+ (0<<4) // NTSC enable (disabled - PAL)
|
|
|
|
+ (0<<5) // C2 static subpicture enable (disabled)
|
|
|
|
+ (0<<6) // C2 subpicture offset division (disabled)
|
|
|
|
+ (0<<7) // 422 subformat selection !
|
|
|
|
/* + (0<<8) // 15 bpp high alpha
|
|
|
|
+ (0<<9) // 15 bpp high alpha
|
|
|
|
+ (0<<10) // 15 bpp high alpha
|
|
|
|
+ (0<<11) // 15 bpp high alpha
|
|
|
|
+ (0<<12) // 15 bpp high alpha
|
|
|
|
+ (0<<13) // 15 bpp high alpha
|
|
|
|
+ (0<<14) // 15 bpp high alpha
|
|
|
|
+ (0<<15) // 15 bpp high alpha
|
|
|
|
+ (0<<16) // 15 bpp low alpha
|
|
|
|
+ (0<<17) // 15 bpp low alpha
|
|
|
|
+ (0<<18) // 15 bpp low alpha
|
|
|
|
+ (0<<19) // 15 bpp low alpha
|
|
|
|
+ (0<<20) // 15 bpp low alpha
|
|
|
|
+ (0<<21) // 15 bpp low alpha
|
|
|
|
+ (0<<22) // 15 bpp low alpha
|
|
|
|
+ (0<<23) // 15 bpp low alpha
|
|
|
|
+ (0<<24) // static subpicture key
|
|
|
|
+ (0<<25) // static subpicture key
|
|
|
|
+ (0<<26) // static subpicture key
|
|
|
|
+ (0<<27) // static subpicture key
|
|
|
|
+ (0<<28) // static subpicture key
|
|
|
|
*/ ;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MGA_VID_FORMAT_UYVY:
|
|
|
|
cregs.c2ctl = 1 // CRTC2 enabled
|
|
|
|
+ (1<<1) // external clock
|
|
|
|
+ (0<<2) // external clock
|
|
|
|
+ (1<<3) // pixel clock enable - not needed ???
|
|
|
|
+ (0<<4) // high prioryty req
|
|
|
|
+ (1<<5) // high prioryty req
|
|
|
|
+ (0<<6) // high prioryty req
|
|
|
|
+ (1<<8) // high prioryty req max
|
|
|
|
+ (0<<9) // high prioryty req max
|
|
|
|
+ (0<<10) // high prioryty req max
|
|
|
|
+ (0<<20) // CRTC1 to DAC
|
|
|
|
+ (1<<21) // 422 mode
|
|
|
|
+ (0<<22) // 422 mode
|
|
|
|
+ (1<<23) // 422 mode
|
|
|
|
+ (1<<24) // single chroma line for 420 mode - need to be corrected
|
|
|
|
+ (1<<25) /*/ interlace mode - need to be corrected*/
|
|
|
|
+ (0<<26) // field legth polariry
|
|
|
|
+ (0<<27) // field identification polariry
|
|
|
|
+ (1<<28) // VIDRST detection mode
|
|
|
|
+ (0<<29) // VIDRST detection mode
|
|
|
|
+ (1<<30) // Horizontal counter preload
|
|
|
|
+ (1<<31) // Vertical counter preload
|
|
|
|
;
|
|
|
|
cregs.c2datactl = 0 // enable dither - propably not needed, we are already in YUV mode
|
|
|
|
+ (1<<1) // Y filter enable
|
|
|
|
+ (1<<2) // CbCr filter enable
|
|
|
|
+ (0<<3) // subpicture enable (disabled)
|
|
|
|
+ (0<<4) // NTSC enable (disabled - PAL)
|
|
|
|
+ (0<<5) // C2 static subpicture enable (disabled)
|
|
|
|
+ (0<<6) // C2 subpicture offset division (disabled)
|
|
|
|
+ (1<<7) // 422 subformat selection !
|
|
|
|
/* + (0<<8) // 15 bpp high alpha
|
|
|
|
+ (0<<9) // 15 bpp high alpha
|
|
|
|
+ (0<<10) // 15 bpp high alpha
|
|
|
|
+ (0<<11) // 15 bpp high alpha
|
|
|
|
+ (0<<12) // 15 bpp high alpha
|
|
|
|
+ (0<<13) // 15 bpp high alpha
|
|
|
|
+ (0<<14) // 15 bpp high alpha
|
|
|
|
+ (0<<15) // 15 bpp high alpha
|
|
|
|
+ (0<<16) // 15 bpp low alpha
|
|
|
|
+ (0<<17) // 15 bpp low alpha
|
|
|
|
+ (0<<18) // 15 bpp low alpha
|
|
|
|
+ (0<<19) // 15 bpp low alpha
|
|
|
|
+ (0<<20) // 15 bpp low alpha
|
|
|
|
+ (0<<21) // 15 bpp low alpha
|
|
|
|
+ (0<<22) // 15 bpp low alpha
|
|
|
|
+ (0<<23) // 15 bpp low alpha
|
|
|
|
+ (0<<24) // static subpicture key
|
|
|
|
+ (0<<25) // static subpicture key
|
|
|
|
+ (0<<26) // static subpicture key
|
|
|
|
+ (0<<27) // static subpicture key
|
|
|
|
+ (0<<28) // static subpicture key
|
|
|
|
*/ ;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printk(KERN_ERR "mga_vid: Unsupported pixel format: 0x%X\n",config->format);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
cregs.c2hparam=((hdispend - 8) << 16) | (htotal - 8);
|
|
|
|
cregs.c2hsync=((hsyncend - 8) << 16) | (hsyncstart - 8);
|
|
|
|
|
|
|
|
cregs.c2misc=0 // CRTCV2 656 togg f0
|
|
|
|
+(0<<1) // CRTCV2 656 togg f0
|
|
|
|
+(0<<2) // CRTCV2 656 togg f0
|
|
|
|
+(0<<4) // CRTCV2 656 togg f1
|
|
|
|
+(0<<5) // CRTCV2 656 togg f1
|
|
|
|
+(0<<6) // CRTCV2 656 togg f1
|
|
|
|
+(0<<8) // Hsync active high
|
|
|
|
+(0<<9) // Vsync active high
|
|
|
|
// 16-27 c2vlinecomp - nevim co tam dat
|
|
|
|
;
|
|
|
|
cregs.c2offset=(regs.bespitch << 1);
|
|
|
|
|
|
|
|
cregs.c2pl2startadd0=regs.besa1corg;
|
|
|
|
// cregs.c2pl2startadd1=regs.besa2corg;
|
|
|
|
cregs.c2pl3startadd0=regs.besa1c3org;
|
|
|
|
// cregs.c2pl3startadd1=regs.besa2c3org;
|
|
|
|
|
|
|
|
cregs.c2preload=(vsyncstart << 16) | (hsyncstart); // from
|
|
|
|
|
|
|
|
cregs.c2spicstartadd0=0; // not used
|
|
|
|
// cregs.c2spicstartadd1=0; // not used
|
|
|
|
|
|
|
|
cregs.c2startadd0=regs.besa1org;
|
|
|
|
// cregs.c2startadd1=regs.besa2org;
|
|
|
|
|
|
|
|
cregs.c2subpiclut=0; //not used
|
|
|
|
|
|
|
|
cregs.c2vparam=((vdispend - 1) << 16) | (vtotal - 1);
|
|
|
|
cregs.c2vsync=((vsyncend - 1) << 16) | (vsyncstart - 1);
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2001-10-04 22:25:13 +00:00
|
|
|
mga_vid_write_regs(0);
|
2001-02-24 20:28:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-03-10 02:27:50 +00:00
|
|
|
#ifdef MGA_ALLOW_IRQ
|
|
|
|
|
2001-03-07 01:12:18 +00:00
|
|
|
static void enable_irq(){
|
|
|
|
long int cc;
|
|
|
|
|
|
|
|
cc = readl(mga_mmio_base + IEN);
|
2001-03-09 00:43:02 +00:00
|
|
|
// printk(KERN_ALERT "*** !!! IRQREG = %d\n", (int)(cc&0xff));
|
2001-03-07 01:12:18 +00:00
|
|
|
|
|
|
|
writeb( 0x11, mga_mmio_base + CRTCX);
|
|
|
|
|
|
|
|
writeb(0x20, mga_mmio_base + CRTCD ); /* clear 0, enable off */
|
|
|
|
writeb(0x00, mga_mmio_base + CRTCD ); /* enable on */
|
|
|
|
writeb(0x10, mga_mmio_base + CRTCD ); /* clear = 1 */
|
|
|
|
|
|
|
|
writel( regs.besglobctl , mga_mmio_base + BESGLOBCTL);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void disable_irq(){
|
|
|
|
|
|
|
|
writeb( 0x11, mga_mmio_base + CRTCX);
|
|
|
|
writeb(0x20, mga_mmio_base + CRTCD ); /* clear 0, enable off */
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2002-04-28 17:22:40 +00:00
|
|
|
static void mga_handle_irq(int irq, void *dev_id, struct pt_regs *pregs) {
|
2001-03-07 01:12:18 +00:00
|
|
|
// static int frame=0;
|
2001-05-23 19:51:52 +00:00
|
|
|
// static int counter=0;
|
2001-03-07 01:12:18 +00:00
|
|
|
long int cc;
|
|
|
|
// if ( ! mga_enabled_flag ) return;
|
|
|
|
|
2001-03-10 02:27:50 +00:00
|
|
|
// printk(KERN_DEBUG "vcount = %d\n",readl(mga_mmio_base + VCOUNT));
|
|
|
|
|
2001-03-07 01:12:18 +00:00
|
|
|
//printk("mga_interrupt #%d\n", irq);
|
|
|
|
|
|
|
|
if ( irq != -1 ) {
|
|
|
|
|
|
|
|
cc = readl(mga_mmio_base + STATUS);
|
|
|
|
if ( ! (cc & 0x10) ) return; /* vsyncpen */
|
|
|
|
// debug_irqcnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if ( debug_irqignore ) {
|
|
|
|
// debug_irqignore = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
if ( mga_conf_deinterlace ) {
|
|
|
|
if ( mga_first_field ) {
|
|
|
|
// printk("mga_interrupt first field\n");
|
|
|
|
if ( syncfb_interrupt() )
|
|
|
|
mga_first_field = 0;
|
|
|
|
} else {
|
|
|
|
// printk("mga_interrupt second field\n");
|
|
|
|
mga_select_buffer( mga_current_field | 2 );
|
|
|
|
mga_first_field = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
syncfb_interrupt();
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
// frame=(frame+1)&1;
|
|
|
|
regs.besctl = (regs.besctl & ~0x07000000) + (mga_next_frame << 25);
|
|
|
|
writel( regs.besctl, mga_mmio_base + BESCTL );
|
2001-10-21 17:28:04 +00:00
|
|
|
|
|
|
|
#ifdef CRTC2
|
|
|
|
// sem pridat vyber obrazku !!!!
|
|
|
|
crtc2_frame_sel(mga_next_frame);
|
|
|
|
#endif
|
2001-03-07 01:12:18 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
++counter;
|
|
|
|
if(!(counter&63)){
|
|
|
|
printk("mga irq counter = %d\n",counter);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
// debug_irqignore = 1;
|
|
|
|
// }
|
|
|
|
|
|
|
|
if ( irq != -1 ) {
|
|
|
|
writeb( 0x11, mga_mmio_base + CRTCX);
|
|
|
|
writeb( 0, mga_mmio_base + CRTCD );
|
|
|
|
writeb( 0x10, mga_mmio_base + CRTCD );
|
|
|
|
}
|
|
|
|
|
|
|
|
// writel( regs.besglobctl, mga_mmio_base + BESGLOBCTL);
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-03-10 02:27:50 +00:00
|
|
|
#endif
|
2001-02-24 20:28:24 +00:00
|
|
|
|
|
|
|
static int mga_vid_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
|
|
|
int frame;
|
2002-03-10 03:36:16 +00:00
|
|
|
uint32_t tmp;
|
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
|
|
|
|
switch(cmd)
|
|
|
|
{
|
|
|
|
case MGA_VID_CONFIG:
|
|
|
|
//FIXME remove
|
2001-03-10 02:27:50 +00:00
|
|
|
// printk(KERN_DEBUG "vcount = %d\n",readl(mga_mmio_base + VCOUNT));
|
2002-04-14 23:14:26 +00:00
|
|
|
#ifdef MP_DEBUG
|
2001-03-09 00:31:22 +00:00
|
|
|
printk(KERN_DEBUG "mga_mmio_base = %p\n",mga_mmio_base);
|
2001-05-23 19:51:52 +00:00
|
|
|
printk(KERN_DEBUG "mga_mem_base = %08x\n",mga_mem_base);
|
2001-02-24 20:28:24 +00:00
|
|
|
//FIXME remove
|
|
|
|
|
2001-03-09 00:31:22 +00:00
|
|
|
printk(KERN_DEBUG "mga_vid: Received configuration\n");
|
2002-04-14 23:14:26 +00:00
|
|
|
#endif
|
2001-02-24 20:28:24 +00:00
|
|
|
|
|
|
|
if(copy_from_user(&mga_config,(mga_vid_config_t*) arg,sizeof(mga_vid_config_t)))
|
|
|
|
{
|
2001-03-09 00:31:22 +00:00
|
|
|
printk(KERN_ERR "mga_vid: failed copy from userspace\n");
|
2001-02-24 20:28:24 +00:00
|
|
|
return(-EFAULT);
|
|
|
|
}
|
2001-03-08 01:06:59 +00:00
|
|
|
if(mga_config.version != MGA_VID_VERSION){
|
2001-03-09 00:31:22 +00:00
|
|
|
printk(KERN_ERR "mga_vid: incompatible version! driver: %X requested: %X\n",MGA_VID_VERSION,mga_config.version);
|
2001-03-08 01:06:59 +00:00
|
|
|
return(-EFAULT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mga_config.frame_size==0 || mga_config.frame_size>1024*768*2){
|
2001-03-09 00:31:22 +00:00
|
|
|
printk(KERN_ERR "mga_vid: illegal frame_size: %d\n",mga_config.frame_size);
|
2001-03-08 01:06:59 +00:00
|
|
|
return(-EFAULT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mga_config.num_frames<1 || mga_config.num_frames>4){
|
2001-03-09 00:31:22 +00:00
|
|
|
printk(KERN_ERR "mga_vid: illegal num_frames: %d\n",mga_config.num_frames);
|
2001-03-08 01:06:59 +00:00
|
|
|
return(-EFAULT);
|
|
|
|
}
|
|
|
|
|
2002-02-07 02:07:29 +00:00
|
|
|
mga_src_base = (mga_ram_size*0x100000-mga_config.num_frames*mga_config.frame_size-mga_top_reserved);
|
2001-03-08 01:06:59 +00:00
|
|
|
if(mga_src_base<0){
|
2001-03-09 00:31:22 +00:00
|
|
|
printk(KERN_ERR "mga_vid: not enough memory for frames!\n");
|
2001-03-08 01:06:59 +00:00
|
|
|
return(-EFAULT);
|
|
|
|
}
|
|
|
|
mga_src_base &= (~0xFFFF); // 64k boundary
|
2002-04-14 23:14:26 +00:00
|
|
|
#ifdef MP_DEBUG
|
2001-03-09 00:31:22 +00:00
|
|
|
printk(KERN_DEBUG "mga YUV buffer base: 0x%X\n", mga_src_base);
|
2002-04-14 23:14:26 +00:00
|
|
|
#endif
|
2001-03-08 01:06:59 +00:00
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
if (is_g400)
|
|
|
|
mga_config.card_type = MGA_G400;
|
|
|
|
else
|
|
|
|
mga_config.card_type = MGA_G200;
|
|
|
|
|
|
|
|
mga_config.ram_size = mga_ram_size;
|
|
|
|
|
|
|
|
if (copy_to_user((mga_vid_config_t *) arg, &mga_config, sizeof(mga_vid_config_t)))
|
|
|
|
{
|
2001-03-09 00:31:22 +00:00
|
|
|
printk(KERN_ERR "mga_vid: failed copy to userspace\n");
|
2001-02-24 20:28:24 +00:00
|
|
|
return(-EFAULT);
|
|
|
|
}
|
|
|
|
return mga_vid_set_config(&mga_config);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MGA_VID_ON:
|
2002-04-14 23:14:26 +00:00
|
|
|
#ifdef MP_DEBUG
|
2001-03-09 00:31:22 +00:00
|
|
|
printk(KERN_DEBUG "mga_vid: Video ON\n");
|
2002-04-14 23:14:26 +00:00
|
|
|
#endif
|
2001-02-24 20:28:24 +00:00
|
|
|
vid_src_ready = 1;
|
|
|
|
if(vid_overlay_on)
|
|
|
|
{
|
|
|
|
regs.besctl |= 1;
|
2001-10-04 22:25:13 +00:00
|
|
|
mga_vid_write_regs(0);
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
2001-03-10 02:27:50 +00:00
|
|
|
#ifdef MGA_ALLOW_IRQ
|
2001-03-07 01:12:18 +00:00
|
|
|
if ( mga_irq != -1 ) enable_irq();
|
2001-03-10 02:27:50 +00:00
|
|
|
#endif
|
2001-03-07 01:12:18 +00:00
|
|
|
mga_next_frame=0;
|
2001-02-24 20:28:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MGA_VID_OFF:
|
2002-04-14 23:14:26 +00:00
|
|
|
#ifdef MP_DEBUG
|
2001-03-12 01:44:07 +00:00
|
|
|
printk(KERN_DEBUG "mga_vid: Video OFF (ioctl)\n");
|
2002-04-14 23:14:26 +00:00
|
|
|
#endif
|
2001-02-24 20:28:24 +00:00
|
|
|
vid_src_ready = 0;
|
2001-03-10 02:27:50 +00:00
|
|
|
#ifdef MGA_ALLOW_IRQ
|
2001-03-07 01:12:18 +00:00
|
|
|
if ( mga_irq != -1 ) disable_irq();
|
2001-03-10 02:27:50 +00:00
|
|
|
#endif
|
2001-02-24 20:28:24 +00:00
|
|
|
regs.besctl &= ~1;
|
2001-04-16 01:26:08 +00:00
|
|
|
regs.besglobctl &= ~(1<<6); // UYVY format selected
|
2001-10-04 22:25:13 +00:00
|
|
|
mga_vid_write_regs(0);
|
2001-02-24 20:28:24 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MGA_VID_FSEL:
|
|
|
|
if(copy_from_user(&frame,(int *) arg,sizeof(int)))
|
|
|
|
{
|
2001-03-09 00:31:22 +00:00
|
|
|
printk(KERN_ERR "mga_vid: FSEL failed copy from userspace\n");
|
2001-02-24 20:28:24 +00:00
|
|
|
return(-EFAULT);
|
|
|
|
}
|
|
|
|
|
|
|
|
mga_vid_frame_sel(frame);
|
|
|
|
break;
|
|
|
|
|
2002-03-10 03:36:16 +00:00
|
|
|
case MGA_VID_GET_LUMA:
|
2002-07-25 21:34:24 +00:00
|
|
|
//tmp = regs.beslumactl;
|
|
|
|
//tmp = (tmp&0xFFFF0000) | (((tmp&0xFFFF) - 0x80)&0xFFFF);
|
|
|
|
tmp = (mga_brightness << 16) | (mga_contrast&0xFFFF);
|
|
|
|
|
2002-03-10 03:36:16 +00:00
|
|
|
if (copy_to_user((uint32_t *) arg, &tmp, sizeof(uint32_t)))
|
|
|
|
{
|
|
|
|
printk(KERN_ERR "mga_vid: failed copy %p to userspace %p\n",
|
|
|
|
&tmp, (uint32_t *) arg);
|
|
|
|
return(-EFAULT);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MGA_VID_SET_LUMA:
|
|
|
|
tmp = arg;
|
2002-07-25 21:34:24 +00:00
|
|
|
mga_brightness=tmp>>16; mga_contrast=tmp&0xFFFF;
|
|
|
|
//regs.beslumactl = (tmp&0xFFFF0000) | ((tmp + 0x80)&0xFFFF);
|
|
|
|
regs.beslumactl = (mga_brightness << 16) | ((mga_contrast+0x80)&0xFFFF);
|
2002-03-10 03:36:16 +00:00
|
|
|
mga_vid_write_regs(0);
|
|
|
|
break;
|
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
default:
|
2001-03-09 00:31:22 +00:00
|
|
|
printk(KERN_ERR "mga_vid: Invalid ioctl\n");
|
2001-02-24 20:28:24 +00:00
|
|
|
return (-EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int mga_vid_find_card(void)
|
|
|
|
{
|
|
|
|
struct pci_dev *dev = NULL;
|
2001-05-23 19:51:52 +00:00
|
|
|
unsigned int card_option;
|
2003-03-21 16:29:04 +00:00
|
|
|
char *mga_dev_name;
|
|
|
|
int num_found = 0;
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2003-03-21 16:29:04 +00:00
|
|
|
while((dev = pci_find_device(PCI_VENDOR_ID_MATROX, PCI_ANY_ID, dev)))
|
2001-09-27 17:00:35 +00:00
|
|
|
{
|
2003-03-21 16:29:04 +00:00
|
|
|
mga_dev_name = "";
|
|
|
|
num_found++;
|
|
|
|
switch(dev->device) {
|
|
|
|
case PCI_DEVICE_ID_MATROX_G550:
|
|
|
|
is_g400 = 1;
|
|
|
|
mga_dev_name = "MGA G550";
|
|
|
|
break;
|
|
|
|
case PCI_DEVICE_ID_MATROX_G400:
|
|
|
|
is_g400 = 1;
|
|
|
|
mga_dev_name = "MGA G400/G450";
|
|
|
|
break;
|
|
|
|
case PCI_DEVICE_ID_MATROX_G200_AGP:
|
|
|
|
is_g400 = 0;
|
|
|
|
mga_dev_name = "MGA G200 AGP";
|
|
|
|
break;
|
|
|
|
case PCI_DEVICE_ID_MATROX_G200_PCI:
|
|
|
|
is_g400 = 0;
|
|
|
|
mga_dev_name = "MGA G200";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
num_found--;
|
|
|
|
printk(KERN_INFO "mga_vid: ignoring matrox device (%d) at %s [%s]\n", dev->device, dev->slot_name, dev->name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(num_found == mga_number+1)
|
|
|
|
break;
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
2003-03-21 16:29:04 +00:00
|
|
|
|
|
|
|
if(!dev)
|
2001-02-24 20:28:24 +00:00
|
|
|
{
|
2003-03-21 16:29:04 +00:00
|
|
|
if(num_found==0)
|
|
|
|
printk(KERN_ERR "mga_vid: No supported cards found\n");
|
|
|
|
else
|
|
|
|
printk(KERN_ERR "mga_vid: Only %d supported cards found\n", num_found);
|
2001-02-24 20:28:24 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2003-03-21 16:29:04 +00:00
|
|
|
printk(KERN_INFO "mga_vid: Found %s at %s [%s]\n", mga_dev_name, dev->slot_name, dev->name);
|
2001-02-24 20:28:24 +00:00
|
|
|
|
|
|
|
pci_dev = dev;
|
2001-03-07 01:12:18 +00:00
|
|
|
|
|
|
|
mga_irq = pci_dev->irq;
|
2001-02-24 20:28:24 +00:00
|
|
|
|
|
|
|
#if LINUX_VERSION_CODE >= 0x020300
|
|
|
|
mga_mmio_base = ioremap_nocache(dev->resource[1].start,0x4000);
|
|
|
|
mga_mem_base = dev->resource[0].start;
|
|
|
|
#else
|
|
|
|
mga_mmio_base = ioremap_nocache(dev->base_address[1] & PCI_BASE_ADDRESS_MEM_MASK,0x4000);
|
|
|
|
mga_mem_base = dev->base_address[0] & PCI_BASE_ADDRESS_MEM_MASK;
|
|
|
|
#endif
|
2001-05-23 19:51:52 +00:00
|
|
|
printk(KERN_INFO "mga_vid: MMIO at 0x%p IRQ: %d framebuffer: 0x%08X\n", mga_mmio_base, mga_irq, mga_mem_base);
|
2001-02-24 20:28:24 +00:00
|
|
|
|
|
|
|
pci_read_config_dword(dev, 0x40, &card_option);
|
2001-03-11 00:13:43 +00:00
|
|
|
printk(KERN_INFO "mga_vid: OPTION word: 0x%08X mem: 0x%02X %s\n", card_option,
|
|
|
|
(card_option>>10)&0x17, ((card_option>>14)&1)?"SGRAM":"SDRAM");
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2001-03-08 01:06:59 +00:00
|
|
|
// temp = (card_option >> 10) & 0x17;
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2001-03-12 01:57:14 +00:00
|
|
|
if (mga_ram_size) {
|
|
|
|
printk(KERN_INFO "mga_vid: RAMSIZE forced to %d MB\n", mga_ram_size);
|
2001-03-11 23:01:14 +00:00
|
|
|
} else {
|
2001-03-11 22:24:03 +00:00
|
|
|
|
2001-03-13 00:23:52 +00:00
|
|
|
#ifdef MGA_MEMORY_SIZE
|
|
|
|
mga_ram_size = MGA_MEMORY_SIZE;
|
|
|
|
printk(KERN_INFO "mga_vid: hard-coded RAMSIZE is %d MB\n", (unsigned int) mga_ram_size);
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2001-03-12 01:57:14 +00:00
|
|
|
if (is_g400){
|
2001-03-10 23:53:27 +00:00
|
|
|
switch((card_option>>10)&0x17){
|
|
|
|
// SDRAM:
|
|
|
|
case 0x00:
|
|
|
|
case 0x04: mga_ram_size = 16; break;
|
2002-02-09 00:49:38 +00:00
|
|
|
case 0x03:
|
|
|
|
case 0x05: mga_ram_size = 32; break;
|
2001-03-10 23:53:27 +00:00
|
|
|
// SGRAM:
|
|
|
|
case 0x10:
|
|
|
|
case 0x14: mga_ram_size = 32; break;
|
|
|
|
case 0x11:
|
|
|
|
case 0x12: mga_ram_size = 16; break;
|
|
|
|
default:
|
|
|
|
mga_ram_size = 16;
|
|
|
|
printk(KERN_INFO "mga_vid: Couldn't detect RAMSIZE, assuming 16MB!");
|
|
|
|
}
|
2003-03-02 21:21:56 +00:00
|
|
|
/* Check for buggy 16MB cards reporting 32 MB */
|
|
|
|
if(mga_ram_size != 16 &&
|
|
|
|
(pci_dev->subsystem_device == PCI_SUBSYSTEM_ID_MATROX_G400_16MB_SDRAM ||
|
|
|
|
pci_dev->subsystem_device == PCI_SUBSYSTEM_ID_MATROX_G400_16MB_SGRAM ||
|
|
|
|
pci_dev->subsystem_device == PCI_SUBSYSTEM_ID_MATROX_G400_DH_16MB))
|
|
|
|
{
|
|
|
|
printk(KERN_INFO "mga_vid: Detected 16MB card reporting %d MB RAMSIZE, overriding\n", mga_ram_size);
|
|
|
|
mga_ram_size = 16;
|
|
|
|
}
|
2001-03-12 01:57:14 +00:00
|
|
|
}else{
|
2001-04-29 20:24:38 +00:00
|
|
|
switch((card_option>>10)&0x17){
|
|
|
|
// case 0x10:
|
|
|
|
// case 0x13: mga_ram_size = 8; break;
|
|
|
|
default: mga_ram_size = 8;
|
2001-03-09 00:49:37 +00:00
|
|
|
}
|
2001-03-12 01:57:14 +00:00
|
|
|
}
|
2001-03-09 00:49:37 +00:00
|
|
|
#if 0
|
2001-03-12 01:57:14 +00:00
|
|
|
// printk("List resources -----------\n");
|
|
|
|
for(temp=0;temp<DEVICE_COUNT_RESOURCE;temp++){
|
|
|
|
struct resource *res=&pci_dev->resource[temp];
|
|
|
|
if(res->flags){
|
|
|
|
int size=(1+res->end-res->start)>>20;
|
|
|
|
printk(KERN_DEBUG "res %d: start: 0x%X end: 0x%X (%d MB) flags=0x%X\n",temp,res->start,res->end,size,res->flags);
|
|
|
|
if(res->flags&(IORESOURCE_MEM|IORESOURCE_PREFETCH)){
|
|
|
|
if(size>mga_ram_size && size<=64) mga_ram_size=size;
|
|
|
|
}
|
|
|
|
}
|
2001-03-08 01:06:59 +00:00
|
|
|
}
|
2001-03-09 00:49:37 +00:00
|
|
|
#endif
|
2001-03-12 01:57:14 +00:00
|
|
|
printk(KERN_INFO "mga_vid: detected RAMSIZE is %d MB\n", (unsigned int) mga_ram_size);
|
2001-03-13 00:23:52 +00:00
|
|
|
#endif
|
2001-03-12 01:57:14 +00:00
|
|
|
}
|
2001-03-08 01:06:59 +00:00
|
|
|
|
2001-03-07 01:12:18 +00:00
|
|
|
|
2001-03-10 02:27:50 +00:00
|
|
|
#ifdef MGA_ALLOW_IRQ
|
2001-03-07 01:12:18 +00:00
|
|
|
if ( mga_irq != -1 ) {
|
|
|
|
int tmp = request_irq(mga_irq, mga_handle_irq, SA_INTERRUPT | SA_SHIRQ, "Syncfb Time Base", &mga_irq);
|
|
|
|
if ( tmp ) {
|
2001-03-09 00:31:22 +00:00
|
|
|
printk(KERN_INFO "syncfb (mga): cannot register irq %d (Err: %d)\n", mga_irq, tmp);
|
2001-03-07 01:12:18 +00:00
|
|
|
mga_irq=-1;
|
|
|
|
} else {
|
2001-03-09 00:31:22 +00:00
|
|
|
printk(KERN_DEBUG "syncfb (mga): registered irq %d\n", mga_irq);
|
2001-03-07 01:12:18 +00:00
|
|
|
}
|
|
|
|
} else {
|
2001-03-09 00:31:22 +00:00
|
|
|
printk(KERN_INFO "syncfb (mga): No valid irq was found\n");
|
2001-03-07 01:12:18 +00:00
|
|
|
mga_irq=-1;
|
|
|
|
}
|
2001-03-10 02:27:50 +00:00
|
|
|
#else
|
|
|
|
printk(KERN_INFO "syncfb (mga): IRQ disabled in mga_vid.c\n");
|
|
|
|
mga_irq=-1;
|
|
|
|
#endif
|
2001-03-07 01:12:18 +00:00
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2002-02-02 21:39:25 +00:00
|
|
|
static void mga_param_buff_fill( void )
|
|
|
|
{
|
|
|
|
unsigned len;
|
|
|
|
len = 0;
|
2003-02-17 06:46:31 +00:00
|
|
|
len += snprintf(&mga_param_buff[len],PARAM_BUFF_SIZE-len,"Interface version: %04X\n",MGA_VID_VERSION);
|
|
|
|
len += snprintf(&mga_param_buff[len],PARAM_BUFF_SIZE-len,"Memory: %x:%dM\n",mga_mem_base,(unsigned int) mga_ram_size);
|
|
|
|
len += snprintf(&mga_param_buff[len],PARAM_BUFF_SIZE-len,"MMIO: %p\n",mga_mmio_base);
|
|
|
|
len += snprintf(&mga_param_buff[len],PARAM_BUFF_SIZE-len,"Configurable stuff:\n");
|
|
|
|
len += snprintf(&mga_param_buff[len],PARAM_BUFF_SIZE-len,"~~~~~~~~~~~~~~~~~~~\n");
|
|
|
|
len += snprintf(&mga_param_buff[len],PARAM_BUFF_SIZE-len,PARAM_BRIGHTNESS"%d\n",mga_brightness);
|
|
|
|
len += snprintf(&mga_param_buff[len],PARAM_BUFF_SIZE-len,PARAM_CONTRAST"%d\n",mga_contrast);
|
|
|
|
len += snprintf(&mga_param_buff[len],PARAM_BUFF_SIZE-len,PARAM_BLACKIE"%s\n",regs.blackie?"on":"off");
|
2002-02-02 21:39:25 +00:00
|
|
|
mga_param_buff_len = len;
|
2002-02-04 16:05:37 +00:00
|
|
|
// check boundaries of mga_param_buff before writing to it!!!
|
2002-02-02 21:39:25 +00:00
|
|
|
}
|
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
|
|
|
|
static ssize_t mga_vid_read(struct file *file, char *buf, size_t count, loff_t *ppos)
|
|
|
|
{
|
2002-02-02 21:39:25 +00:00
|
|
|
uint32_t size;
|
|
|
|
if(!mga_param_buff) return -ESPIPE;
|
|
|
|
if(!(*ppos)) mga_param_buff_fill();
|
|
|
|
if(*ppos >= mga_param_buff_len) return 0;
|
|
|
|
size = min(count,mga_param_buff_len-(uint32_t)(*ppos));
|
|
|
|
memcpy(buf,mga_param_buff,size);
|
|
|
|
*ppos += size;
|
|
|
|
return size;
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t mga_vid_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
|
|
|
|
{
|
2002-02-02 20:49:52 +00:00
|
|
|
if(memcmp(buf,PARAM_BRIGHTNESS,min(count,strlen(PARAM_BRIGHTNESS))) == 0)
|
|
|
|
{
|
|
|
|
short brightness;
|
|
|
|
brightness=simple_strtol(&buf[strlen(PARAM_BRIGHTNESS)],NULL,10);
|
|
|
|
if (brightness>127 || brightness<-128) { brightness=0;}
|
|
|
|
// printk(KERN_DEBUG "mga_vid: brightness modified ( %d ) \n",brightness);
|
2002-02-16 19:58:39 +00:00
|
|
|
mga_brightness=brightness;
|
2002-02-02 20:49:52 +00:00
|
|
|
} else
|
2002-02-02 23:38:35 +00:00
|
|
|
if(memcmp(buf,PARAM_CONTRAST,min(count,strlen(PARAM_CONTRAST))) == 0)
|
|
|
|
{
|
|
|
|
short contrast;
|
|
|
|
contrast=simple_strtol(&buf[strlen(PARAM_CONTRAST)],NULL,10);
|
|
|
|
if (contrast>127 || contrast<-128) { contrast=0;}
|
|
|
|
// printk(KERN_DEBUG "mga_vid: contrast modified ( %d ) \n",contrast);
|
2002-02-16 19:58:39 +00:00
|
|
|
mga_contrast=contrast;
|
2002-02-02 23:38:35 +00:00
|
|
|
} else
|
|
|
|
|
2002-02-02 20:49:52 +00:00
|
|
|
if(memcmp(buf,PARAM_BLACKIE,min(count,strlen(PARAM_BLACKIE))) == 0)
|
|
|
|
{
|
|
|
|
short blackie;
|
|
|
|
blackie=simple_strtol(&buf[strlen(PARAM_BLACKIE)],NULL,10);
|
|
|
|
// printk(KERN_DEBUG "mga_vid: shadow mode: ( %d ) \n",blackie);
|
|
|
|
regs.blackie=(blackie>0)?1:0;
|
|
|
|
} else count = -EIO;
|
|
|
|
// TODO: reset settings
|
|
|
|
return count;
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mga_vid_mmap(struct file *file, struct vm_area_struct *vma)
|
|
|
|
{
|
|
|
|
|
2002-04-14 23:14:26 +00:00
|
|
|
#ifdef MP_DEBUG
|
2001-03-09 00:31:22 +00:00
|
|
|
printk(KERN_DEBUG "mga_vid: mapping video memory into userspace\n");
|
2002-04-14 23:14:26 +00:00
|
|
|
#endif
|
2002-06-28 16:35:37 +00:00
|
|
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,3)
|
|
|
|
if(remap_page_range(vma, vma->vm_start, mga_mem_base + mga_src_base,
|
|
|
|
vma->vm_end - vma->vm_start, vma->vm_page_prot))
|
|
|
|
#else
|
2001-03-08 01:06:59 +00:00
|
|
|
if(remap_page_range(vma->vm_start, mga_mem_base + mga_src_base,
|
2001-02-24 20:28:24 +00:00
|
|
|
vma->vm_end - vma->vm_start, vma->vm_page_prot))
|
2002-06-28 16:35:37 +00:00
|
|
|
#endif
|
2001-02-24 20:28:24 +00:00
|
|
|
{
|
2001-03-09 00:43:02 +00:00
|
|
|
printk(KERN_ERR "mga_vid: error mapping video memory\n");
|
2001-02-24 20:28:24 +00:00
|
|
|
return(-EAGAIN);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mga_vid_release(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
//Close the window just in case
|
2002-04-14 23:14:26 +00:00
|
|
|
#ifdef MP_DEBUG
|
2001-03-12 01:44:07 +00:00
|
|
|
printk(KERN_DEBUG "mga_vid: Video OFF (release)\n");
|
2002-04-14 23:14:26 +00:00
|
|
|
#endif
|
2001-03-12 01:44:07 +00:00
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
vid_src_ready = 0;
|
|
|
|
regs.besctl &= ~1;
|
2001-04-16 01:26:08 +00:00
|
|
|
regs.besglobctl &= ~(1<<6); // UYVY format selected
|
2001-10-04 22:25:13 +00:00
|
|
|
// mga_config.colkey_on=0; //!!!
|
|
|
|
mga_vid_write_regs(1);
|
2001-02-24 20:28:24 +00:00
|
|
|
mga_vid_in_use = 0;
|
|
|
|
|
2001-03-12 01:35:48 +00:00
|
|
|
MOD_DEC_USE_COUNT;
|
2001-02-24 20:28:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static long long mga_vid_lseek(struct file *file, long long offset, int origin)
|
|
|
|
{
|
|
|
|
return -ESPIPE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mga_vid_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
2002-06-28 16:35:37 +00:00
|
|
|
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,2)
|
|
|
|
int minor = MINOR(inode->i_rdev.value);
|
|
|
|
#else
|
2001-02-24 20:28:24 +00:00
|
|
|
int minor = MINOR(inode->i_rdev);
|
2002-06-28 16:35:37 +00:00
|
|
|
#endif
|
2001-02-24 20:28:24 +00:00
|
|
|
|
|
|
|
if(minor != 0)
|
|
|
|
return(-ENXIO);
|
|
|
|
|
|
|
|
if(mga_vid_in_use == 1)
|
|
|
|
return(-EBUSY);
|
|
|
|
|
|
|
|
mga_vid_in_use = 1;
|
2001-03-12 01:35:48 +00:00
|
|
|
MOD_INC_USE_COUNT;
|
2001-02-24 20:28:24 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if LINUX_VERSION_CODE >= 0x020400
|
|
|
|
static struct file_operations mga_vid_fops =
|
|
|
|
{
|
|
|
|
llseek: mga_vid_lseek,
|
|
|
|
read: mga_vid_read,
|
|
|
|
write: mga_vid_write,
|
|
|
|
ioctl: mga_vid_ioctl,
|
|
|
|
mmap: mga_vid_mmap,
|
|
|
|
open: mga_vid_open,
|
|
|
|
release: mga_vid_release
|
|
|
|
};
|
|
|
|
#else
|
|
|
|
static struct file_operations mga_vid_fops =
|
|
|
|
{
|
|
|
|
mga_vid_lseek,
|
|
|
|
mga_vid_read,
|
|
|
|
mga_vid_write,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
mga_vid_ioctl,
|
|
|
|
mga_vid_mmap,
|
|
|
|
mga_vid_open,
|
|
|
|
NULL,
|
|
|
|
mga_vid_release
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Main Initialization Function
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int mga_vid_initialize(void)
|
|
|
|
{
|
|
|
|
mga_vid_in_use = 0;
|
|
|
|
|
2001-03-11 00:13:43 +00:00
|
|
|
// printk(KERN_INFO "Matrox MGA G200/G400 YUV Video interface v0.01 (c) Aaron Holtzman \n");
|
2002-02-09 00:49:38 +00:00
|
|
|
printk(KERN_INFO "Matrox MGA G200/G400/G450/G550 YUV Video interface v2.01 (c) Aaron Holtzman & A'rpi\n");
|
2001-03-11 22:24:03 +00:00
|
|
|
|
2001-03-12 01:57:14 +00:00
|
|
|
if (mga_ram_size) {
|
|
|
|
if (mga_ram_size<4 || mga_ram_size>64) {
|
|
|
|
printk(KERN_ERR "mga_vid: invalid RAMSIZE: %d MB\n", mga_ram_size);
|
2001-03-11 22:24:03 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
2002-04-16 20:19:47 +00:00
|
|
|
#ifdef CONFIG_DEVFS_FS
|
2002-04-18 16:44:21 +00:00
|
|
|
/*
|
|
|
|
from 2.4.17/2.4.18 linux/devfs_fs_kernel.h:
|
|
|
|
extern devfs_handle_t devfs_register (devfs_handle_t dir, const char *name,
|
|
|
|
unsigned int flags,
|
|
|
|
unsigned int major, unsigned int minor,
|
|
|
|
umode_t mode, void *ops, void *info);
|
|
|
|
*/
|
2002-04-16 20:19:47 +00:00
|
|
|
if ((dev_handle = devfs_register(
|
|
|
|
NULL,
|
2002-04-18 16:44:21 +00:00
|
|
|
"mga_vid", DEVFS_FL_NONE,
|
2003-03-21 17:59:15 +00:00
|
|
|
major, 0,
|
2002-04-16 20:19:47 +00:00
|
|
|
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IFCHR,
|
|
|
|
&mga_vid_fops, NULL)) == NULL)
|
2002-04-21 15:07:44 +00:00
|
|
|
{
|
2003-03-21 17:59:15 +00:00
|
|
|
printk(KERN_ERR "mga_vid: unable to get major: %d (devfs) => fallback to non-devfs mode\n", major);
|
2002-05-13 22:10:11 +00:00
|
|
|
// return -EIO;
|
2002-04-21 15:07:44 +00:00
|
|
|
}
|
2002-04-16 20:19:47 +00:00
|
|
|
#endif
|
2003-03-21 17:59:15 +00:00
|
|
|
if(register_chrdev(major, "mga_vid", &mga_vid_fops))
|
2001-02-24 20:28:24 +00:00
|
|
|
{
|
2003-03-21 17:59:15 +00:00
|
|
|
printk(KERN_ERR "mga_vid: unable to get major: %d\n", major);
|
2001-02-24 20:28:24 +00:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mga_vid_find_card())
|
|
|
|
{
|
2001-03-09 00:31:22 +00:00
|
|
|
printk(KERN_ERR "mga_vid: no supported devices found\n");
|
2002-04-16 20:19:47 +00:00
|
|
|
#ifdef CONFIG_DEVFS_FS
|
2002-05-13 22:10:11 +00:00
|
|
|
if(dev_handle) devfs_unregister(dev_handle);
|
2002-04-16 20:19:47 +00:00
|
|
|
#endif
|
2003-03-21 17:59:15 +00:00
|
|
|
unregister_chrdev(major, "mga_vid");
|
2001-02-24 20:28:24 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2002-02-02 21:39:25 +00:00
|
|
|
mga_param_buff = kmalloc(PARAM_BUFF_SIZE,GFP_KERNEL);
|
|
|
|
if(mga_param_buff) mga_param_buff_size = PARAM_BUFF_SIZE;
|
2001-02-24 20:28:24 +00:00
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int init_module(void)
|
|
|
|
{
|
|
|
|
return mga_vid_initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cleanup_module(void)
|
|
|
|
{
|
2001-03-07 01:12:18 +00:00
|
|
|
|
2001-03-10 02:27:50 +00:00
|
|
|
#ifdef MGA_ALLOW_IRQ
|
2001-03-07 01:12:18 +00:00
|
|
|
if ( mga_irq != -1)
|
|
|
|
free_irq(mga_irq, &mga_irq);
|
2001-03-10 02:27:50 +00:00
|
|
|
#endif
|
2001-03-07 01:12:18 +00:00
|
|
|
|
2001-02-24 20:28:24 +00:00
|
|
|
if(mga_mmio_base)
|
|
|
|
iounmap(mga_mmio_base);
|
2002-02-03 19:19:39 +00:00
|
|
|
if(mga_param_buff)
|
|
|
|
kfree(mga_param_buff);
|
2001-02-24 20:28:24 +00:00
|
|
|
|
|
|
|
//FIXME turn off BES
|
2001-03-09 00:43:02 +00:00
|
|
|
printk(KERN_INFO "mga_vid: Cleaning up module\n");
|
2002-04-16 20:19:47 +00:00
|
|
|
#ifdef CONFIG_DEVFS_FS
|
2002-05-13 22:10:11 +00:00
|
|
|
if(dev_handle) devfs_unregister(dev_handle);
|
2002-04-16 20:19:47 +00:00
|
|
|
#endif
|
2003-03-21 17:59:15 +00:00
|
|
|
unregister_chrdev(major, "mga_vid");
|
2001-02-24 20:28:24 +00:00
|
|
|
}
|
|
|
|
|