## Automatically generated incremental diff
## From:   linux-2.4.19-pre9
## To:     linux-2.4.19-pre10
## Robot:  $Id: make-incremental-diff,v 1.11 2002/02/20 02:59:33 hpa Exp $

diff -urN linux-2.4.19-pre9/CREDITS linux-2.4.19-pre10/CREDITS
--- linux-2.4.19-pre9/CREDITS	Mon Jun  3 18:50:45 2002
+++ linux-2.4.19-pre10/CREDITS	Mon Jun  3 18:50:52 2002
@@ -1514,6 +1514,13 @@
 S: 602 00 Brno
 S: Czech Republic
 
+N: Jakob Kemi
+E: jakob.kemi@telia.com
+D: V4L W9966 Webcam driver
+S: Forsbyvägen 33
+S: 74143 Knivsta
+S: Sweden
+
 N: Fred N. van Kempen
 E: waltje@linux.com
 D: NET-2
@@ -1684,13 +1691,6 @@
 S: 80-283 Gdansk
 S: Poland
 
-N: Jakob Kemi
-E: jakob.kemi@telia.com
-D: V4L W9966 Webcam driver
-S: Forsbyvägen 33
-S: 74143 Knivsta
-S: Sweden
-
 N: Gero Kuhlmann
 E: gero@gkminix.han.de
 D: mounting root via NFS
diff -urN linux-2.4.19-pre9/Documentation/DMA-mapping.txt linux-2.4.19-pre10/Documentation/DMA-mapping.txt
--- linux-2.4.19-pre9/Documentation/DMA-mapping.txt	Mon Feb 25 11:37:51 2002
+++ linux-2.4.19-pre10/Documentation/DMA-mapping.txt	Mon Jun  3 18:50:52 2002
@@ -8,7 +8,7 @@
 Most of the 64bit platforms have special hardware that translates bus
 addresses (DMA addresses) into physical addresses.  This is similar to
 how page tables and/or a TLB translates virtual addresses to physical
-addresses on a cpu.  This is needed so that e.g. PCI devices can
+addresses on a CPU.  This is needed so that e.g. PCI devices can
 access with a Single Address Cycle (32bit DMA address) any page in the
 64bit physical address space.  Previously in Linux those 64bit
 platforms had to set artificial limits on the maximum RAM size in the
@@ -37,7 +37,7 @@
 			 What memory is DMA'able?
 
 The first piece of information you must know is what kernel memory can
-be used with the DMA mapping facilitites.  There has been an unwritten
+be used with the DMA mapping facilities.  There has been an unwritten
 set of rules regarding this, and this text is an attempt to finally
 write them down.
 
@@ -106,7 +106,7 @@
 3) Ignore this device and do not initialize it.
 
 It is recommended that your driver print a kernel KERN_WARNING message
-when you end up performing either #2 or #2.  In this manner, if a user
+when you end up performing either #2 or #3.  In this manner, if a user
 of your driver reports that performance is bad or that the device is not
 even detected, you can ask them for the kernel messages to find out
 exactly why.
@@ -146,7 +146,7 @@
 If your 64-bit device is going to be an enormous consumer of DMA
 mappings, this can be problematic since the DMA mappings are a
 finite resource on many platforms.  Please see the "DAC Addressing
-for Address Space Hungry Devices" setion near the end of this
+for Address Space Hungry Devices" section near the end of this
 document for how to handle this case.
 
 Finally, if your device can only drive the low 24-bits of
@@ -205,7 +205,7 @@
 
 - Consistent DMA mappings which are usually mapped at driver
   initialization, unmapped at the end and for which the hardware should
-  guarantee that the device and the cpu can access the data
+  guarantee that the device and the CPU can access the data
   in parallel and will see updates made by each other without any
   explicit software flushing.
 
@@ -222,12 +222,12 @@
 	- Device firmware microcode executed out of
 	  main memory.
 
-  The invariant these examples all require is that any cpu store
+  The invariant these examples all require is that any CPU store
   to memory is immediately visible to the device, and vice
   versa.  Consistent mappings guarantee this.
 
   IMPORTANT: Consistent DMA memory does not preclude the usage of
-             proper memory barriers.  The cpu may reorder stores to
+             proper memory barriers.  The CPU may reorder stores to
 	     consistent memory just as it may normal memory.  Example:
 	     if it is important for the device to see the first word
 	     of a descriptor updated before the second, you must do
@@ -284,7 +284,7 @@
 the pci_pool interface, described below.
 
 The consistent DMA mapping interfaces, for non-NULL dev, will always
-return a DMA address which is SAC (Single Address Cycle) addressible.
+return a DMA address which is SAC (Single Address Cycle) addressable.
 Even if the device indicates (via PCI dma mask) that it may address
 the upper 32-bits and thus perform DAC cycles, consistent allocation
 will still only return 32-bit PCI addresses for DMA.  This is true
@@ -484,7 +484,7 @@
 of sg entries it mapped them to.
 
 Then you should loop count times (note: this can be less than nents times)
-and use sg_dma_address() and sg_dma_length() macros where you previously
+and use sg_dma_address() and sg_dma_len() macros where you previously
 accessed sg->address and sg->length as shown above.
 
 To unmap a scatterlist, just call:
@@ -622,7 +622,7 @@
 Note that for streaming type mappings you must either use these
 interfaces, or the dynamic mapping interfaces above.  You may not mix
 usage of both for the same device.  Such an act is illegal and is
-guarenteed to put a banana in your tailpipe.
+guaranteed to put a banana in your tailpipe.
 
 However, consistent mappings may in fact be used in conjunction with
 these interfaces.  Remember that, as defined, consistent mappings are
@@ -637,7 +637,7 @@
 use the following interfaces if this routine fails.
 
 Next, DMA addresses using this API are kept track of using the
-dma64_addr_t type.  It is guarenteed to be big enough to hold any
+dma64_addr_t type.  It is guaranteed to be big enough to hold any
 DAC address the platform layer will give to you from the following
 routines.  If you have consistent mappings as well, you still
 use plain dma_addr_t to keep track of those.
@@ -745,7 +745,7 @@
 			 PCI_DMA_FROMDEVICE);
 
 It really should be self-explanatory.  We treat the ADDR and LEN
-seperately, because it is possible for an implementation to only
+separately, because it is possible for an implementation to only
 need the address in order to perform the unmap operation.
 
 			Platform Issues
diff -urN linux-2.4.19-pre9/Documentation/DocBook/kernel-api.tmpl linux-2.4.19-pre10/Documentation/DocBook/kernel-api.tmpl
--- linux-2.4.19-pre9/Documentation/DocBook/kernel-api.tmpl	Mon Jun  3 18:50:46 2002
+++ linux-2.4.19-pre10/Documentation/DocBook/kernel-api.tmpl	Mon Jun  3 18:50:52 2002
@@ -272,7 +272,7 @@
 !Edrivers/video/fbcmap.c
      </sect1>
      <sect1><title>Frame Buffer Generic Functions</title>
-!Idrivers/video/fbgen.c
+!Edrivers/video/fbgen.c
      </sect1>
      <sect1><title>Frame Buffer Video Mode Database</title>
 !Idrivers/video/modedb.c
diff -urN linux-2.4.19-pre9/Documentation/fb/README-sstfb.txt linux-2.4.19-pre10/Documentation/fb/README-sstfb.txt
--- linux-2.4.19-pre9/Documentation/fb/README-sstfb.txt	Fri Sep  7 09:28:38 2001
+++ linux-2.4.19-pre10/Documentation/fb/README-sstfb.txt	Mon Jun  3 18:50:52 2002
@@ -9,12 +9,12 @@
 	combinations and it seems that it works.
 	  The main page is located at <http://sstfb.sourceforge.net>, and if
 	you want the latest version, check out the CVS, as the driver is a work
-	in progress, i feel incomfortable with releasing tarballs of something
+	in progress, I feel incomfortable with releasing tarballs of something
 	not completely working...Don't worry, it's still more than useable
 	(I eat my own dog food)
 
 	  Please read the Bug section, and report any success or failure to me
-	(Ghozlane Toumi <gtoumi@messel.emse.fr>).
+	(Ghozlane Toumi <gtoumi@laposte.net>).
 	  BTW, If you have only one monitor , and you don't feel like playing
 	with the vga passthrou cable, I can only suggest borrowing a screen
 	somewhere... 
@@ -22,8 +22,9 @@
 
 Installation 
 
-	  This driver (should) work on ix86, with any 2.2.x kernel (tested
+	  This driver (should) work on ix86, with "late" 2.2.x kernel (tested
 	with x = 19) and "recent" 2.4.x kernel, as a module or compiled in.
+	  It has been included in mainstream kernel since the infamous 2.4.10.
 	  You can apply the patches found in sstfb/kernel/*-2.{2|4}.x.patch,
 	and copy sstfb.c to linux/drivers/video/, or apply a single patch, 
 	sstfb/patch-2.{2|4}.x-sstfb-yymmdd to your linux source tree.
@@ -41,7 +42,7 @@
 	  module, the 3dfx takes control of the output, so you'll have to
 	  plug the monitor to the "normal" video board in order to issue
 	  the commands, or you can blindly use sst_dbg_vgapass
-          in the tools directory (See Tools). The latest option is pass the
+          in the tools directory (See Tools). The latest solution is pass the
 	  parameter vgapass=1 when insmodding the driver. (See Kernel/Modules
 	  Options)
 
@@ -77,36 +78,39 @@
 	in kernel :  video=sstfb:option1,option2:value2,option3 ...
 	
 	sstfb supports the folowing options :
-	module		kernel		description
 
-	vgapass=1	vgapass		enable or disable VGA passthrou cable
-	vgapass=0	vganopass	when enabled, the monitor will
-					get the signal from the VGA board
-					and not from the voodoo. default nopass
-
-	mem=x		mem:x		force frame buffer memory in MiB
-					allowed values: 1, 2, 4. default detect
-
-	inverse=1	inverse		suposed to enable inverse console.
-					doesn't work ...
-
-	clipping=1	clipping	enable or disable clipping . with
-	clipping=0	noclipping	clipping enabled, all offscreen reads
-					and writes are disgarded. default:
-					enable clipping.
-
-	gfxclk=x	gfxclk:x	force graphic clock frequency (in MHz)
-					becarefull with this option .
-					default is 50Mhz for voodoo1, 75MHz
-					for voodoo2. Be carefull, this one is
-					dangerous. default=auto
-
-	slowpci=0	slowpci		enable or disable fast PCI read/writes
-	slowpci=1	fastpci		default : fastpci
-
-	dev=x		dev:x		attach the driver to device number x
-					0 is the first compatible board (in 
-					lspci order)
+Module		Kernel		Description
+
+vgapass=0	vganopass	Enable or disable VGA passthrou cable.
+vgapass=1	vgapass		When enabled, the monitor will get the signal
+				from the VGA board and not from the voodoo.
+				Default: nopass
+
+mem=x		mem:x		Force frame buffer memory in MiB
+				allowed values: 0, 1, 2, 4.
+				Default: 0 (= autodetect)
+
+inverse=1	inverse		Supposed to enable inverse console.
+				doesn't work yet...
+
+clipping=1	clipping	Enable or disable clipping.
+clipping=0	noclipping	With clipping enabled, all offscreen
+				reads and writes are disgarded.
+				Default: enable clipping.
+
+gfxclk=x	gfxclk:x	Force graphic clock frequency (in MHz).
+				Be carefull with this option, it may be
+				DANGEROUS.
+				Default: auto 
+					50Mhz for Voodoo 1,
+					75MHz for Voodoo 2. 
+
+slowpci=1	fastpci		Enable or disable fast PCI read/writes.
+slowpci=1	slowpci		Default : fastpci
+
+dev=x		dev:x		Attach the driver to device number x.
+				0 is the first compatible board (in 
+				lspci order)
 
 Tools
 
@@ -126,8 +130,8 @@
 
 	- DO NOT use glide while the sstfb module is in, you'll most likely
 	hang your computer.
-	- if you see some artefacts (pixels not cleaning and stuff like that), 
-	try turning off clipping (clipping=0)
+	- If you see some artefacts (pixels not cleaning and stuff like that), 
+	try turning off clipping (clipping=0), and/or using slowpci
 	- the driver don't detect the 4Mb frame buffer voodoos, it seems that
 	the 2 last Mbs wrap around. looking into that .
 	- The driver is 16 bpp only, 24/32 won't work.
@@ -137,8 +141,8 @@
 	patterns at the border of your windows (the pixels loose the lowest
 	byte -> basicaly the blue component nd some of the green) . I'm unable
 	to reproduce this with XFree86-3.3, but one of the testers has this
-	problem with XFree86-4. I don't know yet if this is the drivers fault
-	or X's (most likely the driver, of course).
+	problem with XFree86-4. apparently recent Xfree86-4.x solve this
+	problem.
 	- I didn't really test changing the palette, so you may find some weird
 	things when playing with that.
 	- Sometimes the driver will not recognise the DAC , and the
@@ -147,6 +151,9 @@
 	contact me .
 	- the 24/32 is not likely to work anytime soon , knowing that the
 	hardware does ... unusual thigs in 24/32 bpp
+	- When used with anther video board, current limitations of linux
+	console subsystem can cause some troubles, specificaly, you should
+	disable software scrollback , as it can oops badly ...
 
 Todo
 
@@ -154,14 +161,14 @@
 	- Buy more coffee.
 	- test/port to other arch.
 	- try to add panning using tweeks with front and back buffer .
-	- try to implement accel en voodoo2 , this board can actualy do a 
+	- try to implement accel on voodoo2 , this board can actualy do a 
 	  lot in 2D even if it was sold as a 3D only board ...
 
 ghoz.
 
 -- 
-Ghozlane Toumi <gtoumi@messel.emse.fr>
+Ghozlane Toumi <gtoumi@laposte.net>
 
 
-$Date: 2001/08/29 00:21:11 $
+$Date: 2002/05/09 20:11:45 $
 http://sstfb.sourceforge.net/README
diff -urN linux-2.4.19-pre9/Documentation/networking/8139too.txt linux-2.4.19-pre10/Documentation/networking/8139too.txt
--- linux-2.4.19-pre9/Documentation/networking/8139too.txt	Mon Feb 25 11:37:51 2002
+++ linux-2.4.19-pre10/Documentation/networking/8139too.txt	Mon Jun  3 18:50:52 2002
@@ -98,6 +98,7 @@
 Lantech FastNet TX
 Ovislink Fast Ethernet
 Planet ENW-9504 (V.4) 10/100
+SDT Jeoun Fast PCI-TX
 SMC EZNET 10/100
 UNEX NexNIC ND012C
 
diff -urN linux-2.4.19-pre9/Documentation/networking/cs89x0.txt linux-2.4.19-pre10/Documentation/networking/cs89x0.txt
--- linux-2.4.19-pre9/Documentation/networking/cs89x0.txt	Sun Mar 25 18:24:31 2001
+++ linux-2.4.19-pre10/Documentation/networking/cs89x0.txt	Mon Jun  3 18:50:52 2002
@@ -51,7 +51,7 @@
     6.2 Information Required Before Contacting Technical Support
     6.3 Obtaining the Latest Driver Version
     6.4 Current maintainer
-
+    6.5 Kernel boot parameters
 
 
 1.0 CIRRUS LOGIC LAN CS8900/CS8920 ETHERNET ADAPTERS
@@ -690,4 +690,14 @@
 6.4 Current maintainer
 
 In February 2000 the maintenance of this driver was assumed by Andrew
-Morton <andrewm@uow.edu.au>
+Morton <akpm@zip.com.au>
+
+6.5 Kernel module parameters
+
+For use in embedded environments with no cs89x0 EEPROM, the kernel boot
+parameter `cs89x0_media=' has been implemented.  Usage is:
+
+	cs89x0_media=rj45    or
+	cs89x0_media=aui     or
+	cs89x0_media=bnc
+
diff -urN linux-2.4.19-pre9/Documentation/video4linux/API.html linux-2.4.19-pre10/Documentation/video4linux/API.html
--- linux-2.4.19-pre9/Documentation/video4linux/API.html	Thu Jan  6 14:46:18 2000
+++ linux-2.4.19-pre10/Documentation/video4linux/API.html	Mon Jun  3 18:50:52 2002
@@ -105,7 +105,7 @@
 <TR><TD><b>height</b><TD>The height of the image capture.</TD>
 <TR><TD><b>chromakey</b><TD>A host order RGB32 value for the chroma key.</TD>
 <TR><TD><b>flags</b><TD>Additional capture flags.</TD>
-<TR><TD><b>clips</b><TD>A list of clipping rectangles. <em>(Set only)</em)</TD>
+<TR><TD><b>clips</b><TD>A list of clipping rectangles. <em>(Set only)</em></TD>
 <TR><TD><b>clipcount</b><TD>The number of clipping rectangles. <em>(Set only)</em></TD>
 </TABLE>
 <P>
@@ -120,6 +120,7 @@
 </TABLE>
 <P>
 Merely setting the window does not enable capturing. Overlay capturing
+(i.e. PCI-PCI transfer to the frame buffer of the video card)
 is activated by passing the <b>VIDIOCCAPTURE</b> ioctl a value of 1, and
 disabled by passing it a value of 0. 
 <P>
@@ -310,9 +311,10 @@
 </TABLE>
 <P>
 <H3>Reading Images</H3>
-Each call to the <b>read</b> syscall returns the next available image from
-the device. It is up to the caller to set the format and then to pass a 
-suitable size buffer and length to the function. Not all devices will support
+Each call to the <b>read</b> syscall returns the next available image
+from the device. It is up to the caller to set format and size (using
+the VIDIOCSPICT and VIDIOCSWIN ioctls) and then to pass a suitable
+size buffer and length to the function. Not all devices will support
 read operations.
 <P>
 A second way to handle image capture is via the mmap interface if supported.
@@ -329,16 +331,39 @@
 <TR><TD><b>offsets</b><TD>The offset of each frame</TD>
 </TABLE>
 <P>
-Once the mmap has been made the VIDIOCMCAPTURE ioctl sets the image size
-you wish to use (which should match or be below the initial query size).
-Having done so it will begin capturing to the memory mapped buffer. Whenever
-a buffer is "used" by the program it should called VIDIOCSYNC to free this
-frame up and continue. <em>to add:</em>VIDIOCSYNC takes the frame number
-you are freeing as its argument. When the buffer is unmapped or all the
-buffers are full capture ceases. While capturing to memory the driver will
-make a "best effort" attempt to capture to screen as well if requested. This
-normally means all frames that "miss" memory mapped capture will go to the
-display.
+Once the mmap has been made the VIDIOCMCAPTURE ioctl starts the
+capture to a frame using the format and image size specified in the
+video_mmap (which should match or be below the initial query size).
+When the VIDIOCMCAPTURE ioctl returns the frame is <em>not</em>
+captured yet, the driver just instructed the hardware to start the
+capture.  The application has to use the VIDIOCSYNC ioctl to wait
+until the capture of a frame is finished.  VIDIOCSYNC takes the frame
+number you want to wait for as argument.
+<p>
+It is allowed to call VIDIOCMCAPTURE multiple times (with different
+frame numbers in video_mmap->frame of course) and thus have multiple
+outstanding capture requests.  A simple way do to double-buffering
+using this feature looks like this:
+<pre>
+/* setup everything */
+VIDIOCMCAPTURE(0)
+while (whatever) {
+   VIDIOCMCAPTURE(1)
+   VIDIOCSYNC(0)
+   /* process frame 0 while the hardware captures frame 1 */
+   VIDIOCMCAPTURE(0)
+   VIDIOCSYNC(1)
+   /* process frame 1 while the hardware captures frame 0 */
+}
+</pre>
+Note that you are <em>not</em> limited to only two frames.  The API
+allows up to 32 frames, the VIDIOCGMBUF ioctl returns the number of
+frames the driver granted.  Thus it is possible to build deeper queues
+to avoid loosing frames on load peaks.
+<p>
+While capturing to memory the driver will make a "best effort" attempt
+to capture to screen as well if requested. This normally means all
+frames that "miss" memory mapped capture will go to the display.
 <P>
 A final ioctl exists to allow a device to obtain related devices if a
 driver has multiple components (for example video0 may not be associated
diff -urN linux-2.4.19-pre9/Makefile linux-2.4.19-pre10/Makefile
--- linux-2.4.19-pre9/Makefile	Mon Jun  3 18:50:46 2002
+++ linux-2.4.19-pre10/Makefile	Mon Jun  3 18:50:52 2002
@@ -1,7 +1,7 @@
 VERSION = 2
 PATCHLEVEL = 4
 SUBLEVEL = 19
-EXTRAVERSION = -pre9
+EXTRAVERSION = -pre10
 
 KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 
diff -urN linux-2.4.19-pre9/arch/i386/kernel/pci-pc.c linux-2.4.19-pre10/arch/i386/kernel/pci-pc.c
--- linux-2.4.19-pre9/arch/i386/kernel/pci-pc.c	Mon Jun  3 18:50:46 2002
+++ linux-2.4.19-pre10/arch/i386/kernel/pci-pc.c	Mon Jun  3 18:50:53 2002
@@ -1135,6 +1135,18 @@
 		d->resource[i].flags |= PCI_BASE_ADDRESS_SPACE_IO;
 }
 
+static void __devinit  pci_fixup_ncr53c810(struct pci_dev *d)
+{
+	/*
+	 * NCR 53C810 returns class code 0 (at least on some systems).
+	 * Fix class to be PCI_CLASS_STORAGE_SCSI
+	 */
+	if (!d->class) {
+		printk("PCI: fixing NCR 53C810 class code for %s\n", d->slot_name);
+		d->class = PCI_CLASS_STORAGE_SCSI << 8;
+	}
+}
+
 static void __devinit pci_fixup_ide_bases(struct pci_dev *d)
 {
 	int i;
@@ -1246,6 +1258,7 @@
 	{ PCI_FIXUP_HEADER,	PCI_VENDOR_ID_VIA,	PCI_DEVICE_ID_VIA_8622,	        pci_fixup_via_northbridge_bug },
 	{ PCI_FIXUP_HEADER,	PCI_VENDOR_ID_VIA,	PCI_DEVICE_ID_VIA_8361,	        pci_fixup_via_northbridge_bug },
 	{ PCI_FIXUP_HEADER,	PCI_VENDOR_ID_VIA,	PCI_DEVICE_ID_VIA_8367_0,	pci_fixup_via_northbridge_bug },
+	{ PCI_FIXUP_HEADER,	PCI_VENDOR_ID_NCR,	PCI_DEVICE_ID_NCR_53C810,	pci_fixup_ncr53c810 },
 	{ 0 }
 };
 
diff -urN linux-2.4.19-pre9/arch/i386/kernel/signal.c linux-2.4.19-pre10/arch/i386/kernel/signal.c
--- linux-2.4.19-pre9/arch/i386/kernel/signal.c	Mon Jun  3 18:50:46 2002
+++ linux-2.4.19-pre10/arch/i386/kernel/signal.c	Mon Jun  3 18:50:53 2002
@@ -658,7 +658,7 @@
 				continue;
 
 			switch (signr) {
-			case SIGCONT: case SIGCHLD: case SIGWINCH:
+			case SIGCONT: case SIGCHLD: case SIGWINCH: case SIGURG:
 				continue;
 
 			case SIGTSTP: case SIGTTIN: case SIGTTOU:
diff -urN linux-2.4.19-pre9/arch/mips64/kernel/linux32.c linux-2.4.19-pre10/arch/mips64/kernel/linux32.c
--- linux-2.4.19-pre9/arch/mips64/kernel/linux32.c	Mon Jun  3 18:50:47 2002
+++ linux-2.4.19-pre10/arch/mips64/kernel/linux32.c	Mon Jun  3 18:50:53 2002
@@ -1611,7 +1611,9 @@
 	if (!p)
 		return -ENOMEM;
 	err = get_user (p->mtype, &up->mtype);
-	err |= __copy_from_user (p->mtext, &up->mtext, second);
+	if (err)
+		goto out;
+	err = __copy_from_user (p->mtext, &up->mtext, second);
 	if (err)
 		goto out;
 	old_fs = get_fs ();
diff -urN linux-2.4.19-pre9/arch/ppc/kernel/cputable.c linux-2.4.19-pre10/arch/ppc/kernel/cputable.c
--- linux-2.4.19-pre9/arch/ppc/kernel/cputable.c	Mon Jun  3 18:50:47 2002
+++ linux-2.4.19-pre10/arch/ppc/kernel/cputable.c	Mon Jun  3 18:50:53 2002
@@ -143,6 +143,14 @@
 	32, 32,
 	__setup_cpu_750
     },
+    {	/* 750FX (All revs for now) */
+    	0xffff0000, 0x70000000, "750FX",
+    	CPU_FTR_SPLIT_ID_CACHE | CPU_FTR_CAN_DOZE | CPU_FTR_USE_TB |
+	CPU_FTR_L2CR | CPU_FTR_TAU | CPU_FTR_HPTE_TABLE | CPU_FTR_CAN_NAP,
+	COMMON_PPC,
+	32, 32,
+	__setup_cpu_750
+    },
     {	/* 740/750 (L2CR bit need fixup for 740) */
     	0xffff0000, 0x00080000, "740/750",
     	CPU_FTR_SPLIT_ID_CACHE | CPU_FTR_CAN_DOZE | CPU_FTR_USE_TB |
diff -urN linux-2.4.19-pre9/arch/ppc/kernel/irq.c linux-2.4.19-pre10/arch/ppc/kernel/irq.c
--- linux-2.4.19-pre9/arch/ppc/kernel/irq.c	Mon Feb 25 11:37:55 2002
+++ linux-2.4.19-pre10/arch/ppc/kernel/irq.c	Mon Jun  3 18:50:53 2002
@@ -1,5 +1,5 @@
 /*
- * BK Id: SCCS/s.irq.c 1.34 12/01/01 20:09:06 benh
+ * BK Id: %F% %I% %G% %U% %#%
  */
 /*
  *  arch/ppc/kernel/irq.c
@@ -985,7 +985,7 @@
 	struct proc_dir_entry *entry;
 	char name [MAX_NAMELEN];
 
-	if (!root_irq_dir || (irq_desc[irq].handler == NULL))
+	if (!root_irq_dir || (irq_desc[irq].handler == NULL) || irq_dir[irq])
 		return;
 
 	memset(name, 0, MAX_NAMELEN);
diff -urN linux-2.4.19-pre9/arch/ppc/kernel/pmac_feature.c linux-2.4.19-pre10/arch/ppc/kernel/pmac_feature.c
--- linux-2.4.19-pre9/arch/ppc/kernel/pmac_feature.c	Mon Jun  3 18:50:47 2002
+++ linux-2.4.19-pre10/arch/ppc/kernel/pmac_feature.c	Mon Jun  3 18:50:53 2002
@@ -199,7 +199,7 @@
 	unsigned long		chan_mask;
 	unsigned long		fcr;
 	unsigned long		flags;
-	int			htw;
+	int			htw, trans;
 	unsigned long		rmask;
 	
 	macio = macio_find(node, 0);
@@ -214,6 +214,9 @@
 
 	htw = (macio->type == macio_heathrow || macio->type == macio_paddington
 		|| macio->type == macio_gatwick);
+	/* On these machines, the HRW_SCC_TRANS_EN_N bit mustn't be touched */
+	trans = (pmac_mb.model_id != PMAC_TYPE_YOSEMITE &&
+	    	 pmac_mb.model_id != PMAC_TYPE_YIKES);
 	if (value) {
 #ifdef CONFIG_ADB_PMU
 		if ((param & 0xfff) == PMAC_SCC_IRDA)
@@ -225,7 +228,13 @@
 		if (!(fcr & OH_SCC_ENABLE)) {
 			fcr |= OH_SCC_ENABLE;
 			if (htw) {
-				fcr &= ~HRW_SCC_TRANS_EN_N;
+				/* Side effect: this will also power up the
+				 * modem, but it's too messy to figure out on which
+				 * ports this controls the tranceiver and on which
+				 * it controls the modem
+				 */
+				if (trans)
+					fcr &= ~HRW_SCC_TRANS_EN_N;
 				MACIO_OUT32(OHARE_FCR, fcr);
 				fcr |= (rmask = HRW_RESET_SCC);
 				MACIO_OUT32(OHARE_FCR, fcr);
@@ -261,7 +270,7 @@
 		MACIO_OUT32(OHARE_FCR, fcr);
 		if ((fcr & (OH_SCCA_IO | OH_SCCB_IO)) == 0) {
 			fcr &= ~OH_SCC_ENABLE;
-			if (htw)
+			if (htw && trans)
 				fcr |= HRW_SCC_TRANS_EN_N;
 			MACIO_OUT32(OHARE_FCR, fcr);
 		}
@@ -333,9 +342,9 @@
 
 	if ((pmac_mb.board_flags & PMAC_MB_CAN_SLEEP) == 0)
 		return -EPERM;
-	if (value) {
+	if (value == 1) {
 		MACIO_BIC(OHARE_FCR, OH_IOBUS_ENABLE);
-	} else {
+	} else if (value == 0) {
 		MACIO_BIS(OHARE_FCR, OH_IOBUS_ENABLE);
 	}
 	
@@ -1644,6 +1653,10 @@
 		PMAC_TYPE_PANGEA_IMAC,		pangea_features,
 		PMAC_MB_CAN_SLEEP
 	},
+	{	"PowerBook4,3",			"iBook 2 with 14\" LCD",
+		PMAC_TYPE_IBOOK2,		pangea_features,
+		PMAC_MB_CAN_SLEEP | PMAC_MB_HAS_FW_POWER
+	},
 	{	"PowerBook4,2",			"iBook 2 with 14\" LCD",
 		PMAC_TYPE_IBOOK2,		pangea_features,
 		PMAC_MB_CAN_SLEEP | PMAC_MB_HAS_FW_POWER
@@ -1715,6 +1728,10 @@
 		PMAC_TYPE_TITANIUM2,		core99_features,
 		PMAC_MB_CAN_SLEEP | PMAC_MB_HAS_FW_POWER
 	},
+	{	"PowerBook3,4",			"PowerBook Titanium III",
+		PMAC_TYPE_TITANIUM3,		core99_features,
+		PMAC_MB_CAN_SLEEP | PMAC_MB_HAS_FW_POWER
+	},
 };
 
 /*
diff -urN linux-2.4.19-pre9/arch/s390/kernel/debug.c linux-2.4.19-pre10/arch/s390/kernel/debug.c
--- linux-2.4.19-pre9/arch/s390/kernel/debug.c	Mon Feb 25 11:37:56 2002
+++ linux-2.4.19-pre10/arch/s390/kernel/debug.c	Mon Jun  3 18:50:54 2002
@@ -443,7 +443,6 @@
 {
 	size_t count = 0;
 	size_t entry_offset, size = 0;
-	int rc;
 	file_private_info_t *p_info;
 
 	p_info = ((file_private_info_t *) file->private_data);
@@ -459,9 +458,9 @@
 		size = MIN((len - count), (size - entry_offset));
 
 		if(size){
-			if ((rc = copy_to_user(user_buf + count, 
-					p_info->temp_buf + entry_offset, size)))
-			return rc;
+			if (copy_to_user(user_buf + count, 
+					p_info->temp_buf + entry_offset, size))
+				return count ? count: -EFAULT;
 		}
 		count += size;
 		entry_offset = 0;
diff -urN linux-2.4.19-pre9/arch/s390/kernel/ptrace.c linux-2.4.19-pre10/arch/s390/kernel/ptrace.c
--- linux-2.4.19-pre9/arch/s390/kernel/ptrace.c	Mon Feb 25 11:37:56 2002
+++ linux-2.4.19-pre10/arch/s390/kernel/ptrace.c	Mon Jun  3 18:50:54 2002
@@ -341,9 +341,11 @@
 		break;
 	case PTRACE_PEEKUSR_AREA:
 	case PTRACE_POKEUSR_AREA:
-		if((ret=copy_from_user(&parea,(void *)addr,sizeof(parea)))==0)  
-		   ret=copy_user(child,parea.kernel_addr,parea.process_addr,
+		if(copy_from_user(&parea,(void *)addr,sizeof(parea))==0)  
+			ret=copy_user(child,parea.kernel_addr,parea.process_addr,
 				 parea.len,1,(request==PTRACE_POKEUSR_AREA));
+		else
+			ret = -EFAULT;
 		break;
 	default:
 		ret = -EIO;
diff -urN linux-2.4.19-pre9/arch/s390x/kernel/debug.c linux-2.4.19-pre10/arch/s390x/kernel/debug.c
--- linux-2.4.19-pre9/arch/s390x/kernel/debug.c	Mon Feb 25 11:37:56 2002
+++ linux-2.4.19-pre10/arch/s390x/kernel/debug.c	Mon Jun  3 18:50:54 2002
@@ -443,7 +443,6 @@
 {
 	size_t count = 0;
 	size_t entry_offset, size = 0;
-	int rc;
 	file_private_info_t *p_info;
 
 	p_info = ((file_private_info_t *) file->private_data);
@@ -459,9 +458,9 @@
 		size = MIN((len - count), (size - entry_offset));
 
 		if(size){
-			if ((rc = copy_to_user(user_buf + count, 
-					p_info->temp_buf + entry_offset, size)))
-			return rc;
+			if (copy_to_user(user_buf + count, 
+					p_info->temp_buf + entry_offset, size))
+				return count ? count : -EFAULT;
 		}
 		count += size;
 		entry_offset = 0;
diff -urN linux-2.4.19-pre9/arch/s390x/kernel/ptrace.c linux-2.4.19-pre10/arch/s390x/kernel/ptrace.c
--- linux-2.4.19-pre9/arch/s390x/kernel/ptrace.c	Mon Feb 25 11:37:56 2002
+++ linux-2.4.19-pre10/arch/s390x/kernel/ptrace.c	Mon Jun  3 18:50:54 2002
@@ -357,9 +357,10 @@
 
 	case PTRACE_PEEKUSR_AREA:
 	case PTRACE_POKEUSR_AREA:
-		if((ret=copy_from_user(&parea,(void *)addr,sizeof(parea)))==0)  
-		   ret=copy_user(child,parea.kernel_addr,parea.process_addr,
+		if(copy_from_user(&parea,(void *)addr,sizeof(parea)) == 0)  
+			ret=copy_user(child,parea.kernel_addr,parea.process_addr,
 				 parea.len,1,(request==PTRACE_POKEUSR_AREA));
+		else ret = -EFAULT;
 		break;
 	default:
 		ret = -EIO;
diff -urN linux-2.4.19-pre9/drivers/acorn/block/mfmhd.c linux-2.4.19-pre10/drivers/acorn/block/mfmhd.c
--- linux-2.4.19-pre9/drivers/acorn/block/mfmhd.c	Thu Oct 25 13:58:35 2001
+++ linux-2.4.19-pre10/drivers/acorn/block/mfmhd.c	Mon Jun  3 18:50:54 2002
@@ -1369,9 +1369,6 @@
  */
 static int mfm_probecontroller (unsigned int mfm_addr)
 {
-	if (check_region (mfm_addr, 10))
-		return 0;
-
 	if (inw (MFM_STATUS) & STAT_BSY) {
 		outw (CMD_ABT, MFM_COMMAND);
 		udelay (50);
@@ -1429,15 +1426,19 @@
 		ecard_claim(ecs);
 	}
 
+	printk("mfm: found at address %08X, interrupt %d\n", mfm_addr, mfm_irq);
+	if (!request_region (mfm_addr, 10, "mfm")) {
+		ecard_release(ecs);
+		return -1;
+	}
+
 	if (register_blkdev(MAJOR_NR, "mfm", &mfm_fops)) {
 		printk("mfm_init: unable to get major number %d\n", MAJOR_NR);
 		ecard_release(ecs);
+		release_region(mfm_addr, 10);
 		return -1;
 	}
 
-	printk("mfm: found at address %08X, interrupt %d\n", mfm_addr, mfm_irq);
-	request_region (mfm_addr, 10, "mfm");
-
 	/* Stuff for the assembler routines to get to */
 	hdc63463_baseaddress	= ioaddr(mfm_addr);
 	hdc63463_irqpolladdress	= mfm_IRQPollLoc;
diff -urN linux-2.4.19-pre9/drivers/atm/horizon.c linux-2.4.19-pre10/drivers/atm/horizon.c
--- linux-2.4.19-pre9/drivers/atm/horizon.c	Thu Sep 13 15:21:32 2001
+++ linux-2.4.19-pre10/drivers/atm/horizon.c	Mon Jun  3 18:50:54 2002
@@ -2765,15 +2765,13 @@
     u32 * membase = bus_to_virt (pci_resource_start (pci_dev, 1));
     u8 irq = pci_dev->irq;
     
-    // check IO region
-    if (check_region (iobase, HRZ_IO_EXTENT)) {
-      PRINTD (DBG_WARN, "IO range already in use");
-      continue;
-    }
+    /* XXX DEV_LABEL is a guess */
+    if (!request_region (iobase, HRZ_IO_EXTENT, DEV_LABEL))
+  	  continue;
 
     if (pci_enable_device (pci_dev))
       continue;
-
+    
     dev = kmalloc (sizeof(hrz_dev), GFP_KERNEL);
     if (!dev) {
       // perhaps we should be nice: deregister all adapters and abort?
@@ -2807,9 +2805,6 @@
 	dev->atm_dev->dev_data = (void *) dev;
 	dev->pci_dev = pci_dev; 
 	
-	/* XXX DEV_LABEL is a guess */
-	request_region (iobase, HRZ_IO_EXTENT, DEV_LABEL);
-	
 	// enable bus master accesses
 	pci_set_master (pci_dev);
 	
@@ -2901,8 +2896,10 @@
 	atm_dev_deregister (dev->atm_dev);
       } /* atm_dev_register */
       free_irq (irq, dev);
+	
     } /* request_irq */
     kfree (dev);
+    release_region(iobase, HRZ_IO_EXTENT);
   } /* kmalloc and while */
   return devs;
 }
diff -urN linux-2.4.19-pre9/drivers/block/paride/bpck6.c linux-2.4.19-pre10/drivers/block/paride/bpck6.c
--- linux-2.4.19-pre9/drivers/block/paride/bpck6.c	Mon Jun  3 18:50:47 2002
+++ linux-2.4.19-pre10/drivers/block/paride/bpck6.c	Mon Jun  3 18:50:54 2002
@@ -225,8 +225,6 @@
 
 static void bpck6_init_proto(PIA *pi)
 {
-	int i;
-
 	/* allocate a state structure for this item */
 	pi->privptr=kmalloc(sizeof(PPC_STORAGE),GFP_KERNEL);
 
diff -urN linux-2.4.19-pre9/drivers/block/paride/paride.c linux-2.4.19-pre10/drivers/block/paride/paride.c
--- linux-2.4.19-pre9/drivers/block/paride/paride.c	Thu Oct 11 09:04:57 2001
+++ linux-2.4.19-pre10/drivers/block/paride/paride.c	Mon Jun  3 18:50:54 2002
@@ -276,9 +276,6 @@
 		range = 3;
 		if (pi->mode >= pi->proto->epp_first) range = 8;
 		if ((range == 8) && (pi->port % 8)) return 0;
-#ifndef CONFIG_PARPORT
-		if (check_region(pi->port,range)) return 0;
-#endif /* !CONFIG_PARPORT */
 		pi->reserved = range;
 		return (!pi_test_proto(pi,scratch,verbose));
 	}
@@ -287,9 +284,6 @@
 		range = 3;
 		if (pi->mode >= pi->proto->epp_first) range = 8;
 		if ((range == 8) && (pi->port % 8)) break;
-#ifndef CONFIG_PARPORT
-		if (check_region(pi->port,range)) break;
-#endif /* !CONFIG_PARPORT */
 		pi->reserved = range;
 		if (!pi_test_proto(pi,scratch,verbose)) best = pi->mode;
 	}
@@ -311,10 +305,6 @@
 	if (!pi_register_parport(pi,verbose))
 	  return 0;
 
-#ifndef CONFIG_PARPORT
-	if (check_region(pi->port,3)) return 0;
-#endif /* !CONFIG_PARPORT */
-
 	if (pi->proto->test_port) {
 		pi_claim(pi);
 		max = pi->proto->test_port(pi);
@@ -404,7 +394,11 @@
 	}
 
 #ifndef CONFIG_PARPORT
-	request_region(pi->port,pi->reserved,pi->device);
+	if (!request_region(pi->port,pi->reserved,pi->device))
+		{
+		printk(KERN_WARNING"paride: Unable to request region 0x%x\n", pi->port);
+		return 0;
+		}
 #endif /* !CONFIG_PARPORT */
 
 	if (pi->parname)
diff -urN linux-2.4.19-pre9/drivers/block/paride/pg.c linux-2.4.19-pre10/drivers/block/paride/pg.c
--- linux-2.4.19-pre9/drivers/block/paride/pg.c	Fri Dec 21 09:41:53 2001
+++ linux-2.4.19-pre10/drivers/block/paride/pg.c	Mon Jun  3 18:50:54 2002
@@ -628,7 +628,8 @@
 	if (PG.busy) return -EBUSY;
 	if (count < hs) return -EINVAL;
 	
-	copy_from_user((char *)&hdr,buf,hs);
+	if (copy_from_user((char *)&hdr, buf, hs))
+		return -EFAULT;
 
 	if (hdr.magic != PG_MAGIC) return -EINVAL;
 	if (hdr.dlen > PG_MAX_DATA) return -EINVAL;
@@ -652,8 +653,8 @@
 
 	PG.busy = 1;
 
-	copy_from_user(PG.bufptr,buf+hs,count-hs);
-
+	if (copy_from_user(PG.bufptr, buf + hs, count - hs))
+		return -EFAULT;
 	return count;
 }
 
@@ -687,9 +688,11 @@
 	hdr.duration = (jiffies - PG.start + HZ/2) / HZ;
 	hdr.scsi = PG.status & 0x0f;
 
-	copy_to_user(buf,(char *)&hdr,hs);
-	if (copy > 0) copy_to_user(buf+hs,PG.bufptr,copy);
-	
+	if (copy_to_user(buf, (char *)&hdr, hs))
+		return -EFAULT;
+	if (copy > 0)
+		if (copy_to_user(buf+hs,PG.bufptr,copy))
+			return -EFAULT;
 	return copy+hs;
 }
 
diff -urN linux-2.4.19-pre9/drivers/block/paride/pt.c linux-2.4.19-pre10/drivers/block/paride/pt.c
--- linux-2.4.19-pre9/drivers/block/paride/pt.c	Fri Dec 21 09:41:53 2001
+++ linux-2.4.19-pre10/drivers/block/paride/pt.c	Mon Jun  3 18:50:54 2002
@@ -864,7 +864,10 @@
 		    n -= k;
 		    b = k;
 		    if (b > count) b = count;
-		    copy_to_user(buf+t,PT.bufptr,b);
+		    if (copy_to_user(buf + t, PT.bufptr, b)) {
+	    		pi_disconnect(PI);
+			return -EFAULT;
+		    }
 		    t += b;
 		    count -= b;
 	        }
@@ -948,7 +951,10 @@
 		    if (k > PT_BUFSIZE) k = PT_BUFSIZE;
 		    b = k;
 		    if (b > count) b = count;
-		    copy_from_user(PT.bufptr,buf+t,b);
+		    if (copy_from_user(PT.bufptr, buf + t, b)) {
+			pi_disconnect(PI);
+			return -EFAULT;
+		    }
                     pi_write_block(PI,PT.bufptr,k);
 		    t += b;
 		    count -= b;
diff -urN linux-2.4.19-pre9/drivers/block/swim3.c linux-2.4.19-pre10/drivers/block/swim3.c
--- linux-2.4.19-pre9/drivers/block/swim3.c	Mon Jun  3 18:50:47 2002
+++ linux-2.4.19-pre10/drivers/block/swim3.c	Mon Jun  3 18:50:54 2002
@@ -839,9 +839,10 @@
 		err = fd_eject(fs);
 		return err;
 	case FDGETPRM:
-	        err = copy_to_user((void *) param, (void *) &floppy_type,
-				   sizeof(struct floppy_struct));
-		return err;
+	        if (copy_to_user((void *) param, (void *)&floppy_type,
+				 sizeof(struct floppy_struct)))
+			return -EFAULT;
+		return 0;
 	}
 	return -ENOTTY;
 }
diff -urN linux-2.4.19-pre9/drivers/block/swim_iop.c linux-2.4.19-pre10/drivers/block/swim_iop.c
--- linux-2.4.19-pre9/drivers/block/swim_iop.c	Sat May 19 17:43:05 2001
+++ linux-2.4.19-pre10/drivers/block/swim_iop.c	Mon Jun  3 18:50:54 2002
@@ -359,9 +359,10 @@
 		err = swimiop_eject(fs);
 		return err;
 	case FDGETPRM:
-	        err = copy_to_user((void *) param, (void *) &floppy_type,
-				   sizeof(struct floppy_struct));
-		return err;
+	        if (copy_to_user((void *) param, (void *) &floppy_type,
+				 sizeof(struct floppy_struct)))
+			return -EFAULT;
+		return 0;
 	}
 	return -ENOTTY;
 }
diff -urN linux-2.4.19-pre9/drivers/block/umem.c linux-2.4.19-pre10/drivers/block/umem.c
--- linux-2.4.19-pre9/drivers/block/umem.c	Mon Jun  3 18:50:47 2002
+++ linux-2.4.19-pre10/drivers/block/umem.c	Mon Jun  3 18:50:54 2002
@@ -339,8 +339,9 @@
 	offset = ((char*)desc) - ((char*)page->desc);
 	writel(cpu_to_le32((page->page_dma+offset)&0xffffffff),
 	       card->csr_remap + DMA_DESCRIPTOR_ADDR);
-	/* if sizeof(dma_addr_t) == 32, this will generate a warning, sorry */
-	writel(cpu_to_le32((page->page_dma)>>32),
+	/* Force the valiue to u64 before shifting otherwise >> 32 is undefined C
+	   and on some ports will do nothing ! */
+	writel(((u64)cpu_to_le32((page->page_dma)>>32)),
 	       card->csr_remap + DMA_DESCRIPTOR_ADDR + 4);
 
 	/* Go, go, go */
diff -urN linux-2.4.19-pre9/drivers/char/epca.c linux-2.4.19-pre10/drivers/char/epca.c
--- linux-2.4.19-pre9/drivers/char/epca.c	Fri Oct 12 13:48:42 2001
+++ linux-2.4.19-pre10/drivers/char/epca.c	Mon Jun  3 18:50:54 2002
@@ -908,7 +908,9 @@
 				
 				----------------------------------------------------------------- */
 
-				copy_from_user(ch->tmp_buf, buf, bytesAvailable);
+				if (copy_from_user(ch->tmp_buf, buf,
+						   bytesAvailable))
+					return -EFAULT;
 
 			} /* End if area verified */
 
@@ -3000,7 +3002,8 @@
 				di.port = boards[brd].port ;
 				di.membase = boards[brd].membase ;
 
-				copy_to_user((char *)arg, &di, sizeof (di));
+				if (copy_to_user((char *)arg, &di, sizeof (di)))
+					return -EFAULT;
 				break;
 
 			} /* End case DIGI_GETINFO */
@@ -3069,14 +3072,9 @@
 	{ /* Begin switch cmd */
 
 		case TCGETS:
-			retval = verify_area(VERIFY_WRITE, (void *)arg,
-                              sizeof(struct termios));
-			
-			if (retval)
-				return(retval);
-
-			copy_to_user((struct termios *)arg, 
-			             tty->termios, sizeof(struct termios));
+			if (copy_to_user((struct termios *)arg, 
+					 tty->termios, sizeof(struct termios)))
+				return -EFAULT;
 			return(0);
 
 		case TCGETA:
@@ -3236,14 +3234,9 @@
 			break;
 
 		case DIGI_GETA:
-			if ((error=
-				verify_area(VERIFY_WRITE, (char*)arg, sizeof(digi_t))))
-			{
-				printk(KERN_ERR "<Error> - Digi GETA failed\n");
-				return(error);
-			}
-
-			copy_to_user((char*)arg, &ch->digiext, sizeof(digi_t));
+			if (copy_to_user((char*)arg, &ch->digiext,
+					 sizeof(digi_t)))
+				return -EFAULT;
 			break;
 
 		case DIGI_SETAW:
@@ -3264,11 +3257,9 @@
 			/* Fall Thru */
 
 		case DIGI_SETA:
-			if ((error =
-				verify_area(VERIFY_READ, (char*)arg,sizeof(digi_t))))
-				return(error);
-
-			copy_from_user(&ch->digiext, (char*)arg, sizeof(digi_t));
+			if (copy_from_user(&ch->digiext, (char*)arg,
+					   sizeof(digi_t)))
+				return -EFAULT;
 			
 			if (ch->digiext.digi_flags & DIGI_ALTPIN) 
 			{
@@ -3311,10 +3302,8 @@
 			memoff(ch);
 			restore_flags(flags);
 
-			if ((error = verify_area(VERIFY_WRITE, (char*)arg,sizeof(dflow))))
-				return(error);
-
-			copy_to_user((char*)arg, &dflow, sizeof(dflow));
+			if (copy_to_user((char*)arg, &dflow, sizeof(dflow)))
+				return -EFAULT;
 			break;
 
 		case DIGI_SETAFLOW:
@@ -3330,10 +3319,8 @@
 				stopc = ch->stopca;
 			}
 
-			if ((error = verify_area(VERIFY_READ, (char*)arg,sizeof(dflow))))
-				return(error);
-
-			copy_from_user(&dflow, (char*)arg, sizeof(dflow));
+			if (copy_from_user(&dflow, (char*)arg, sizeof(dflow)))
+				return -EFAULT;
 
 			if (dflow.startc != startc || dflow.stopc != stopc) 
 			{ /* Begin  if setflow toggled */
diff -urN linux-2.4.19-pre9/drivers/char/istallion.c linux-2.4.19-pre10/drivers/char/istallion.c
--- linux-2.4.19-pre9/drivers/char/istallion.c	Thu Oct 25 13:53:47 2001
+++ linux-2.4.19-pre10/drivers/char/istallion.c	Mon Jun  3 18:50:54 2002
@@ -2022,7 +2022,8 @@
 	printk("stli_setserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
 #endif
 
-	copy_from_user(&sio, sp, sizeof(struct serial_struct));
+	if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
+		return -EFAULT;
 	if (!capable(CAP_SYS_ADMIN)) {
 		if ((sio.baud_base != portp->baud_base) ||
 		    (sio.close_delay != portp->close_delay) ||
@@ -4878,11 +4879,15 @@
 	while (size > 0) {
 		memptr = (void *) EBRDGETMEMPTR(brdp, fp->f_pos);
 		n = MIN(size, (brdp->pagesize - (((unsigned long) fp->f_pos) % brdp->pagesize)));
-		copy_to_user(buf, memptr, n);
+		if (copy_to_user(buf, memptr, n)) {
+			count = -EFAULT;
+			goto out;
+		}
 		fp->f_pos += n;
 		buf += n;
 		size -= n;
 	}
+out:
 	EBRDDISABLE(brdp);
 	restore_flags(flags);
 
@@ -4930,11 +4935,15 @@
 	while (size > 0) {
 		memptr = (void *) EBRDGETMEMPTR(brdp, fp->f_pos);
 		n = MIN(size, (brdp->pagesize - (((unsigned long) fp->f_pos) % brdp->pagesize)));
-		copy_from_user(memptr, chbuf, n);
+		if (copy_from_user(memptr, chbuf, n)) {
+			count = -EFAULT;
+			goto out;
+		}
 		fp->f_pos += n;
 		chbuf += n;
 		size -= n;
 	}
+out:
 	EBRDDISABLE(brdp);
 	restore_flags(flags);
 
diff -urN linux-2.4.19-pre9/drivers/char/machzwd.c linux-2.4.19-pre10/drivers/char/machzwd.c
--- linux-2.4.19-pre9/drivers/char/machzwd.c	Thu Sep 13 15:21:32 2001
+++ linux-2.4.19-pre10/drivers/char/machzwd.c	Mon Jun  3 18:50:54 2002
@@ -348,20 +348,15 @@
 static int zf_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
 	unsigned long arg)
 {
-	int ret;
-		
 	switch(cmd){
 		case WDIOC_GETSUPPORT:
-			ret = copy_to_user((struct watchdog_info *)arg, 
-						&zf_info, sizeof(zf_info));
-			if(ret)
+			if (copy_to_user((struct watchdog_info *)arg, 
+					 &zf_info, sizeof(zf_info)))
 				return -EFAULT;
 			break;
 	  
 		case WDIOC_GETSTATUS:
-			ret = copy_to_user((int *)arg, &zf_is_open,
-								sizeof(int));
-			if(ret)
+			if (copy_to_user((int *)arg, &zf_is_open, sizeof(int)))
 				return -EFAULT;
 			break;
 
diff -urN linux-2.4.19-pre9/drivers/char/mxser.c linux-2.4.19-pre10/drivers/char/mxser.c
--- linux-2.4.19-pre9/drivers/char/mxser.c	Mon Jun  3 18:50:48 2002
+++ linux-2.4.19-pre10/drivers/char/mxser.c	Mon Jun  3 18:50:54 2002
@@ -2176,8 +2176,7 @@
 	tmp.closing_wait = info->closing_wait;
 	tmp.custom_divisor = info->custom_divisor;
 	tmp.hub6 = 0;
-	copy_to_user(retinfo, &tmp, sizeof(*retinfo));
-	return (0);
+	return copy_to_user(retinfo, &tmp, sizeof(*retinfo)) ? -EFAULT : 0;
 }
 
 static int mxser_set_serial_info(struct mxser_struct *info,
@@ -2189,7 +2188,8 @@
 
 	if (!new_info || !info->base)
 		return (-EFAULT);
-	copy_from_user(&new_serial, new_info, sizeof(new_serial));
+	if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
+		return -EFAULT;
 
 	if ((new_serial.irq != info->irq) ||
 	    (new_serial.port != info->base) ||
diff -urN linux-2.4.19-pre9/drivers/char/n_tty.c linux-2.4.19-pre10/drivers/char/n_tty.c
--- linux-2.4.19-pre9/drivers/char/n_tty.c	Fri Apr  6 10:42:55 2001
+++ linux-2.4.19-pre10/drivers/char/n_tty.c	Mon Jun  3 18:50:54 2002
@@ -23,6 +23,11 @@
  * 2000/01/20   Fixed SMP locking on put_tty_queue using bits of 
  *		the patch by Andrew J. Kroll <ag784@freenet.buffalo.edu>
  *		who actually finally proved there really was a race.
+ *
+ * 2002/03/18   Implemented n_tty_wakeup to send SIGIO POLL_OUTs to
+ *		waiting writing processes-Sapan Bhatia <sapan@corewars.org>.
+ *		Also fixed a bug in BLOCKING mode where write_chan returns
+ *		EAGAIN
  */
 
 #include <linux/types.h>
@@ -711,6 +716,22 @@
 	return 0;
 }
 
+/*
+ * Required for the ptys, serial driver etc. since processes
+ * that attach themselves to the master and rely on ASYNC
+ * IO must be woken up
+ */
+
+static void n_tty_write_wakeup(struct tty_struct *tty)
+{
+	if (tty->fasync)
+	{
+ 		set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
+		kill_fasync(&tty->fasync, SIGIO, POLL_OUT);
+	}
+	return;
+}
+
 static void n_tty_receive_buf(struct tty_struct *tty, const unsigned char *cp,
 			      char *fp, int count)
 {
@@ -1157,6 +1178,8 @@
 			while (nr > 0) {
 				ssize_t num = opost_block(tty, b, nr);
 				if (num < 0) {
+					if (num == -EAGAIN)
+						break;
 					retval = num;
 					goto break_out;
 				}
@@ -1236,6 +1259,6 @@
 	normal_poll,		/* poll */
 	n_tty_receive_buf,	/* receive_buf */
 	n_tty_receive_room,	/* receive_room */
-	0			/* write_wakeup */
+	n_tty_write_wakeup	/* write_wakeup */
 };
 
diff -urN linux-2.4.19-pre9/drivers/char/pcwd.c linux-2.4.19-pre10/drivers/char/pcwd.c
--- linux-2.4.19-pre9/drivers/char/pcwd.c	Mon Jun  3 18:50:48 2002
+++ linux-2.4.19-pre10/drivers/char/pcwd.c	Mon Jun  3 18:50:54 2002
@@ -40,57 +40,67 @@
  *		fairly useless proc entry.
  * 990610	removed said useless proc code for the merge <alan>
  * 000403	Removed last traces of proc code. <davej>
- * 020210	Backported 2.5 open_allowed changes, and got rid of a useless
- *		variable <rob@osinvestor.com>
+ * 011214	Added nowayout module option to override CONFIG_WATCHDOG_NOWAYOUT <Matt_Domsch@dell.com>
+ * 020210       Backported 2.5 open_allowed changes, and got rid of a useless
+ *              variable <rob@osinvestor.com>
+ *              Added timeout module option to override default
+ * 020306	Support the PCI version [Lindsay Harris <lindsay@bluegum.com>]
  */
 
+/*
+ *  A bells and whistles driver is available from http://www.pcwd.de/
+ */
 #include <linux/module.h>
 
 #include <linux/types.h>
-#include <linux/errno.h>
-#include <linux/sched.h>
-#include <linux/tty.h>
-#include <linux/timer.h>
-#include <linux/config.h>
-#include <linux/kernel.h>
-#include <linux/wait.h>
-#include <linux/string.h>
-#include <linux/slab.h>
-#include <linux/ioport.h>
 #include <linux/delay.h>
 #include <linux/miscdevice.h>
-#include <linux/fs.h>
-#include <linux/mm.h>
 #include <linux/watchdog.h>
 #include <linux/init.h>
-#include <linux/proc_fs.h>
-#include <linux/spinlock.h>
-#include <linux/smp_lock.h>
 
 #include <asm/uaccess.h>
 #include <asm/io.h>
 
-/*
- * These are the auto-probe addresses available.
- *
- * Revision A only uses ports 0x270 and 0x370.  Revision C introduced 0x350.
- * Revision A has an address range of 2 addresses, while Revision C has 3.
- */
-static int pcwd_ioports[] = { 0x270, 0x350, 0x370, 0x000 };
-
-#define WD_VER                  "1.10 (06/05/99)"
+#include <linux/notifier.h>
+#include <linux/reboot.h>
+#include <linux/pci.h>
+
+#define WD_VER                  "1.13 (03/06/2002)"
+
+/*  Stuff for the PCI version  */
+#ifndef	PCI_VENDOR_ID_QUICKLOGIC
+#define	PCI_VENDOR_ID_QUICKLOGIC	0x11e3
+#endif
+#ifndef	PCI_DEVICE_ID_BERKSHIRE
+#define	PCI_DEVICE_ID_BERKSHIRE	0x5030
+#endif
 
 /*
- * It should be noted that PCWD_REVISION_B was removed because A and B
+ * It should be noted that PCWD_REV_B was removed because A and B
  * are essentially the same types of card, with the exception that B
  * has temperature reporting.  Since I didn't receive a Rev.B card,
  * the Rev.B card is not supported.  (It's a good thing too, as they
  * are no longer in production.)
  */
-#define	PCWD_REVISION_A		1
-#define	PCWD_REVISION_C		2
+#define	PCWD_REV_A	0
+#define	PCWD_REV_C	1
+#define	PCWD_REV_PCI	2
+
+static int timeout_val;
+static int timeout = 2;
+
+MODULE_PARM (timeout, "i");
+MODULE_PARM_DESC (timeout, "Watchdog timeout in seconds (default=2)");
+
+#ifdef CONFIG_WATCHDOG_NOWAYOUT
+static int nowayout = 1;
+#else
+static int nowayout = 0;
+#endif
 
-#define	WD_TIMEOUT		3	/* 1 1/2 seconds for a timeout */
+MODULE_PARM (nowayout, "i");
+MODULE_PARM_DESC (nowayout,
+		  "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
 
 /*
  * These are the defines for the PC Watchdog card, revision A.
@@ -101,333 +111,316 @@
 #define WD_RLY2                 0x08	/* External relay triggered */
 #define WD_SRLY2                0x80	/* Software external relay triggered */
 
-static int current_readport, revision, temp_panic;
-static atomic_t open_allowed = ATOMIC_INIT(1);
-static int initial_status, supports_temp, mode_debug;
-static spinlock_t io_lock;
-
 /*
- * PCWD_CHECKCARD
- *
- * This routine checks the "current_readport" to see if the card lies there.
- * If it does, it returns accordingly.
+ *  Differences between cards regarding how they perform some operations
+ *  are handled by an array of structs, with per card functions for the
+ *  incompatible operations.  It's all defined here.
  */
-static int __init pcwd_checkcard(void)
-{
-	int card_dat, prev_card_dat, found = 0, count = 0, done = 0;
 
-	/* As suggested by Alan Cox - this is a safety measure. */
-	if (check_region(current_readport, 4)) {
-		printk("pcwd: Port 0x%x unavailable.\n", current_readport);
-		return 0;
-	}
+/*  ENABLE/DISABLE the card  */
+typedef int (*fn_enable) (int);	/* Enable/disable card */
 
-	card_dat = 0x00;
-	prev_card_dat = 0x00;
+static int pcwd_enable_card (int enable);	/* Actually works */
+static int pcwd_enable_nop (int enable);	/* NOP - REV A cannot */
 
-	prev_card_dat = inb(current_readport);
-	if (prev_card_dat == 0xFF)
-		return 0;
+/* Obtain firmware version, if possible */
+#define	PCWD_FIRMWARE_BSZ	16	/* Version buffer size */
+typedef void (*fn_firmware) (char *bp);
+
+static void pcwd_firmware_ver_none (char *bp);	/* REV A can't do it */
+static void pcwd_firmware_ver_revc (char *bp);	/* REV C boards can */
+static void pcwd_firmware_ver_pci (char *bp);	/* PCI boards can too */
+
+/*  Tickle the watchdog timer */
+typedef void (*fn_tickle) (void);
+
+static void pcwd_tickle_reva (void);	/* Rev A only */
+static void pcwd_tickle (void);	/* Rev C, PCI */
+
+/*  Determine reboot and temperature status */
+typedef int (*fn_status) (int reset_boot);
+
+static int pcwd_get_stat_reva (int reset_boot);
+static int pcwd_get_stat (int reset_boot);
+
+/*  Per card type specifications */
+typedef struct {
+	fn_tickle wd_tickle;	/* Reset the watchdog */
+	fn_enable enable_card;	/* Enable/disable card, if possible */
+	fn_firmware firmware_ver;	/* Get firmware version, if possible */
+	fn_status wd_status;	/* Card reset and/or over temp */
+	int io_size;		/* I/O space used */
+	const char *name;	/* Nice name to display */
+} PCWD_CARD_INFO;
 
-	while(count < WD_TIMEOUT) {
-
-	/* Read the raw card data from the port, and strip off the
-	   first 4 bits */
-
-		card_dat = inb_p(current_readport);
-		card_dat &= 0x000F;
-
-	/* Sleep 1/2 second (or 500000 microseconds :) */
-
-		mdelay(500);
-		done = 0;
+/* Per card information, indexed by card version ID */
+static PCWD_CARD_INFO pcwd_card_info[] = {
+	{
+	 pcwd_tickle_reva,
+	 pcwd_enable_nop,
+	 pcwd_firmware_ver_none,
+	 pcwd_get_stat_reva,
+	 2,
+	 "Berkshire Products PC Watchdog (REV A)",
+	 },
+	{
+	 pcwd_tickle,
+	 pcwd_enable_card,
+	 pcwd_firmware_ver_revc,
+	 pcwd_get_stat,
+	 4,
+	 "Berkshire Products PC Watchdog (REV C)",
+	 },
+	{
+	 pcwd_tickle,
+	 pcwd_enable_card,
+	 pcwd_firmware_ver_pci,
+	 pcwd_get_stat,
+	 8,
+	 "Berkshire Products PC Watchdog (PCI)",
+	 },
+};
 
-	/* If there's a heart beat in both instances, then this means we
-	   found our card.  This also means that either the card was
-	   previously reset, or the computer was power-cycled. */
+/*  Overall driver information, including per card pointer */
+static struct {
+	PCWD_CARD_INFO *card_info;	/* Points to one of the above */
+	atomic_t open_allowed;	/* Watchdog is single open */
+	int flags;		/* Defined below */
+	int boot_status;	/* Card status at boot time */
+	int io_addr;		/* Card's base address */
+} pcwd_info = {
+NULL, ATOMIC_INIT (1), 0, 0, 0};
+
+/*  Bits allocated in flags above. */
+#define	PCWD_HAS_TEMP	0x0001	/* Set when thermometer available */
+#define	PCWD_PCI_REG	0x0002	/* Set if PCI register code worked */
+#define	PCWD_TEMP_PANIC	0x0004	/* Panic when over temperature */
 
-		if ((card_dat & WD_HRTBT) && (prev_card_dat & WD_HRTBT) &&
-			(!done)) {
-			found = 1;
-			done = 1;
-			break;
-		}
+static spinlock_t io_lock;
 
-	/* If the card data is exactly the same as the previous card data,
-	   it's safe to assume that we should check again.  The manual says
-	   that the heart beat will change every second (or the bit will
-	   toggle), and this can be used to see if the card is there.  If
-	   the card was powered up with a cold boot, then the card will
-	   not start blinking until 2.5 minutes after a reboot, so this
-	   bit will stay at 1. */
-
-		if ((card_dat == prev_card_dat) && (!done)) {
-			count++;
-			done = 1;
-		}
+/* D E T E R M I N E   C A R D   S T A T U S   F U N C T I O N S  */
+/*   Rev A cards return status information from the base register,
+ * which is used for the temperature in other cards.  */
+
+static int
+pcwd_get_stat_reva (int reset_boot)
+{
+	int retval;
+	int status;
+
+	spin_lock (&io_lock);
+	status = inb_p (pcwd_info.io_addr);
+	spin_unlock (&io_lock);
+
+	/* Transform the card register to the ioctl bits we use internally */
+	retval = 0;
+	if (status & WD_WDRST)
+		retval |= WDIOF_CARDRESET;
+	if (status & WD_T110)
+		retval |= WDIOF_OVERHEAT;
 
-	/* If the card data is toggling any bits, this means that the heart
-	   beat was detected, or something else about the card is set. */
+	return retval;
+}
 
-		if ((card_dat != prev_card_dat) && (!done)) {
-			done = 1;
-			found = 1;
-			break;
-		}
+/*
+ *  Rev C and PCI cards return card status in the base address + 1 register.
+ *  And use different bits to indicate a card initiated reset, and
+ *  an over-temperature condition.  And the reboot status can be reset.
+ */
 
-	/* Otherwise something else strange happened. */
+static int
+pcwd_get_stat (int reset_boot)
+{
+	int retval;
+	int status;
 
-		if (!done)
-			count++;
+	spin_lock (&io_lock);
+	status = inb_p (pcwd_info.io_addr + 1);
+	if (reset_boot) {
+		/*  NOTE:  the REV C card clears the "card caused reboot"
+		 * flag when writing ANY value to this port.  However,
+		 * the PCI card requires writing a 1 to bit 0.  */
+		outb_p (0x01, pcwd_info.io_addr + 1);
 	}
+	spin_unlock (&io_lock);
 
-	return((found) ? 1 : 0);
-}
-
-void pcwd_showprevstate(void)
-{
-	int card_status = 0x0000;
+	retval = 0;
+	if (status & 0x01)
+		retval |= WDIOF_CARDRESET;
+	if (status & 0x04)
+		retval |= WDIOF_OVERHEAT;
 
-	if (revision == PCWD_REVISION_A)
-		initial_status = card_status = inb(current_readport);
-	else {
-		initial_status = card_status = inb(current_readport + 1);
-		outb_p(0x00, current_readport + 1); /* clear reset status */
-	}
+	return retval;
+}
 
-	if (revision == PCWD_REVISION_A) {
-		if (card_status & WD_WDRST)
-			printk("pcwd: Previous reboot was caused by the card.\n");
+/*  W A T C H D O G   T I M E R   R E S E T   F U N C T I O N S   */
+/*  Rev A cards are reset by setting a specific bit in register 1.  */
 
-		if (card_status & WD_T110) {
-			printk("pcwd: Card senses a CPU Overheat.  Panicking!\n");
-			panic("pcwd: CPU Overheat.\n");
-		}
+static void
+pcwd_tickle_reva (void)
+{
+	int wdrst_stat;
 
-		if ((!(card_status & WD_WDRST)) &&
-		    (!(card_status & WD_T110)))
-			printk("pcwd: Cold boot sense.\n");
-	} else {
-		if (card_status & 0x01)
-			printk("pcwd: Previous reboot was caused by the card.\n");
+	spin_lock (&io_lock);
+	wdrst_stat = inb_p (pcwd_info.io_addr);
+	wdrst_stat = (wdrst_stat & 0x0F) | WD_WDRST;
 
-		if (card_status & 0x04) {
-			printk("pcwd: Card senses a CPU Overheat.  Panicking!\n");
-			panic("pcwd: CPU Overheat.\n");
-		}
+	outb_p (wdrst_stat, pcwd_info.io_addr + 1);
+	spin_unlock (&io_lock);
 
-		if ((!(card_status & 0x01)) &&
-		    (!(card_status & 0x04)))
-			printk("pcwd: Cold boot sense.\n");
-	}
+	return;
 }
 
-static void pcwd_send_heartbeat(void)
-{
-	int wdrst_stat;
-
-	wdrst_stat = inb_p(current_readport);
-	wdrst_stat &= 0x0F;
+/*  Other cards are reset by writing anything to the base register.  */
 
-	wdrst_stat |= WD_WDRST;
+static void
+pcwd_tickle (void)
+{
+	spin_lock (&io_lock);
+	outb_p (0x42, pcwd_info.io_addr);
+	spin_unlock (&io_lock);
 
-	if (revision == PCWD_REVISION_A)
-		outb_p(wdrst_stat, current_readport + 1);
-	else
-		outb_p(wdrst_stat, current_readport);
+	return;
 }
 
-static int pcwd_ioctl(struct inode *inode, struct file *file,
-		      unsigned int cmd, unsigned long arg)
+static int
+pcwd_ioctl (struct inode *inode, struct file *file,
+	    unsigned int cmd, unsigned long arg)
 {
-	int cdat, rv;
-	static struct watchdog_info ident=
-	{
-		WDIOF_OVERHEAT|WDIOF_CARDRESET,
+	int rv;
+	int retval;
+
+	static struct watchdog_info ident = {
+		WDIOF_OVERHEAT | WDIOF_CARDRESET,
 		1,
 		"PCWD"
 	};
 
-	switch(cmd) {
-	default:
-		return -ENOTTY;
-
+	switch (cmd) {
 	case WDIOC_GETSUPPORT:
-		if(copy_to_user((void*)arg, &ident, sizeof(ident)))
-			return -EFAULT;
-		return 0;
+		rv = copy_to_user ((void *) arg, &ident, sizeof (ident));
+		return rv ? -EFAULT : 0;
 
 	case WDIOC_GETSTATUS:
-		spin_lock(&io_lock);
-		if (revision == PCWD_REVISION_A) 
-			cdat = inb(current_readport);
-		else
-			cdat = inb(current_readport + 1 );
-		spin_unlock(&io_lock);
-		rv = 0;
-
-		if (revision == PCWD_REVISION_A) 
-		{
-			if (cdat & WD_WDRST)
-				rv |= WDIOF_CARDRESET;
-
-			if (cdat & WD_T110) 
-			{
-				rv |= WDIOF_OVERHEAT;
+		rv = pcwd_info.card_info->wd_status (0);
 
-				if (temp_panic)
-					panic("pcwd: Temperature overheat trip!\n");
-			}
+		if (rv & WDIOF_OVERHEAT) {
+			if (pcwd_info.flags & PCWD_TEMP_PANIC)
+				panic ("pcwd: Temperature overheat trip!\n");
 		}
-		else 
-		{
-			if (cdat & 0x01)
-				rv |= WDIOF_CARDRESET;
-
-			if (cdat & 0x04) 
-			{
-				rv |= WDIOF_OVERHEAT;
 
-				if (temp_panic)
-					panic("pcwd: Temperature overheat trip!\n");
-			}
-		}
-
-		if(put_user(rv, (int *) arg))
+		if (put_user (rv, (int *) arg))
 			return -EFAULT;
 		return 0;
 
 	case WDIOC_GETBOOTSTATUS:
-		rv = 0;
+		rv = pcwd_info.boot_status;
 
-		if (revision == PCWD_REVISION_A) 
-		{
-			if (initial_status & WD_WDRST)
-				rv |= WDIOF_CARDRESET;
-
-			if (initial_status & WD_T110)
-				rv |= WDIOF_OVERHEAT;
-		}
-		else
-		{
-			if (initial_status & 0x01)
-				rv |= WDIOF_CARDRESET;
-
-			if (initial_status & 0x04)
-				rv |= WDIOF_OVERHEAT;
-		}
-
-		if(put_user(rv, (int *) arg))
+		if (put_user (rv, (int *) arg))
 			return -EFAULT;
 		return 0;
 
 	case WDIOC_GETTEMP:
-
 		rv = 0;
-		if ((supports_temp) && (mode_debug == 0)) 
-		{
-			spin_lock(&io_lock);
-			rv = inb(current_readport);
-			spin_unlock(&io_lock);
-			if(put_user(rv, (int*) arg))
-				return -EFAULT;
-		} else if(put_user(rv, (int*) arg))
-				return -EFAULT;
+		if (pcwd_info.flags & PCWD_HAS_TEMP) {
+			spin_lock (&io_lock);
+			rv = inb_p (pcwd_info.io_addr);
+			spin_unlock (&io_lock);
+		}
+		if (put_user (rv, (int *) arg))
+			return -EFAULT;
 		return 0;
 
 	case WDIOC_SETOPTIONS:
-		if (revision == PCWD_REVISION_C) 
-		{
-			if(copy_from_user(&rv, (int*) arg, sizeof(int)))
-				return -EFAULT;
-
-			if (rv & WDIOS_DISABLECARD) 
-			{
-				spin_lock(&io_lock);
-				outb_p(0xA5, current_readport + 3);
-				outb_p(0xA5, current_readport + 3);
-				cdat = inb_p(current_readport + 2);
-				spin_unlock(&io_lock);
-				if ((cdat & 0x10) == 0) 
-				{
-					printk("pcwd: Could not disable card.\n");
-					return -EIO;
-				}
+		if (copy_from_user (&rv, (int *) arg, sizeof (int)))
+			return -EFAULT;
 
-				return 0;
-			}
+		retval = -EINVAL;
 
-			if (rv & WDIOS_ENABLECARD) 
-			{
-				spin_lock(&io_lock);
-				outb_p(0x00, current_readport + 3);
-				cdat = inb_p(current_readport + 2);
-				spin_unlock(&io_lock);
-				if (cdat & 0x10) 
-				{
-					printk("pcwd: Could not enable card.\n");
-					return -EIO;
-				}
-				return 0;
+		if (rv & WDIOS_DISABLECARD) {
+			if (!pcwd_info.card_info->enable_card (0)) {
+				printk (KERN_EMERG
+					"pcwd: Could not disable card\n");
+				return -EIO;
 			}
 
-			if (rv & WDIOS_TEMPPANIC) 
-			{
-				temp_panic = 1;
+			retval = 0;
+		}
+
+		if (rv & WDIOS_ENABLECARD) {
+			if (!pcwd_info.card_info->enable_card (1)) {
+				printk (KERN_EMERG
+					"pcwd: Could not enable card\n");
+				return -EIO;
 			}
+			retval = 0;
+		}
+
+		if (rv & WDIOS_TEMPPANIC) {
+			pcwd_info.flags |= PCWD_TEMP_PANIC;
+
+			retval = 0;
 		}
-		return -EINVAL;
-		
+
+		return retval;
+
 	case WDIOC_KEEPALIVE:
-		pcwd_send_heartbeat();
+		pcwd_info.card_info->wd_tickle ();
 		return 0;
+
+	default:
+		return -ENOTTY;
 	}
 
 	return 0;
 }
 
-static ssize_t pcwd_write(struct file *file, const char *buf, size_t len,
-			  loff_t *ppos)
+/*   Write:  only for the watchdog device (thermometer is read-only).  */
+
+static ssize_t
+pcwd_write (struct file *file, const char *buf, size_t len, loff_t * ppos)
 {
 	/*  Can't seek (pwrite) on this device  */
 	if (ppos != &file->f_pos)
 		return -ESPIPE;
 
-	if (len)
-	{
-		pcwd_send_heartbeat();
+	if (len) {
+		pcwd_info.card_info->wd_tickle ();
 		return 1;
 	}
 	return 0;
 }
 
-static int pcwd_open(struct inode *ino, struct file *filep)
+static int
+pcwd_open (struct inode *ino, struct file *filep)
 {
-        switch (MINOR(ino->i_rdev))
-        {
-                case WATCHDOG_MINOR:
-                    if (!atomic_dec_and_test(&open_allowed)){
-                        atomic_inc(&open_allowed);
-                        return -EBUSY;
-                    }
-                    MOD_INC_USE_COUNT;
-                    /*  Enable the port  */
-                    if (revision == PCWD_REVISION_C)
-                    {
-                    	spin_lock(&io_lock);
-                    	outb_p(0x00, current_readport + 3);
-                    	spin_unlock(&io_lock);
-                    }
-                    return(0);
-                case TEMP_MINOR:
-                    return(0);
-                default:
-                    return (-ENODEV);
-        }
+	switch (MINOR (ino->i_rdev)) {
+	case WATCHDOG_MINOR:
+		if (!atomic_dec_and_test (&pcwd_info.open_allowed)) {
+			atomic_inc (&pcwd_info.open_allowed);
+			return -EBUSY;
+		}
+
+		/*  Enable the card  */
+		pcwd_info.card_info->enable_card (1);
+		pcwd_info.card_info->wd_tickle ();
+
+		return 0;
+
+	case TEMP_MINOR:
+		if (pcwd_info.flags & PCWD_HAS_TEMP) {
+			return 0;
+		}
+		return -ENODEV;
+
+	default:
+		return -ENODEV;
+	}
 }
 
-static ssize_t pcwd_read(struct file *file, char *buf, size_t count,
-			 loff_t *ppos)
+/*	Read:  applies only to the thermometer (watchdog is write only).  */
+static ssize_t
+pcwd_read (struct file *file, char *buf, size_t count, loff_t * ppos)
 {
 	unsigned short c;
 	unsigned char cp;
@@ -435,124 +428,279 @@
 	/*  Can't seek (pread) on this device  */
 	if (ppos != &file->f_pos)
 		return -ESPIPE;
-	switch(MINOR(file->f_dentry->d_inode->i_rdev)) 
-	{
-		case TEMP_MINOR:
-			/*
-			 * Convert metric to Fahrenheit, since this was
-			 * the decided 'standard' for this return value.
-			 */
-			
-			c = inb(current_readport);
-			cp = (c * 9 / 5) + 32;
-			if(copy_to_user(buf, &cp, 1))
-				return -EFAULT;
-			return 1;
-		default:
-			return -EINVAL;
+
+	/*
+	 * Convert celsius to fahrenheit, since this was
+	 * the decided 'standard' for this return value.
+	 */
+
+	spin_lock (&io_lock);
+	c = inb_p (pcwd_info.io_addr);
+	spin_unlock (&io_lock);
+
+	cp = (c * 9 / 5) + 32;
+	if (copy_to_user (buf, &cp, 1))
+		return -EFAULT;
+
+	return 1;
+}
+
+static int
+pcwd_close (struct inode *ino, struct file *filep)
+{
+	switch (MINOR (ino->i_rdev)) {
+	case WATCHDOG_MINOR:
+		if (!nowayout)
+			pcwd_info.card_info->enable_card (0);
+
+		atomic_inc (&pcwd_info.open_allowed);
+		break;
+
+	case TEMP_MINOR:
+		break;
 	}
+	return 0;
 }
 
-static int pcwd_close(struct inode *ino, struct file *filep)
+/*
+ *  System is shutting down, so disable the card.  Otherwise the timeout
+ * may expire during shutdown.  Of course, this means a hang during
+ * shutdown will not be reset, but somebody is probably nearby and will
+ * notice.  The alternative is to have the shutdown aborted when the
+ * watchdog expires and hits reset.
+ */
+
+static int
+pcwd_notify_sys (struct notifier_block *this, unsigned long code, void *unused)
 {
-	if (MINOR(ino->i_rdev)==WATCHDOG_MINOR)
-	{
-#ifndef CONFIG_WATCHDOG_NOWAYOUT
-		/*  Disable the board  */
-		if (revision == PCWD_REVISION_C) {
-			spin_lock(&io_lock);
-			outb_p(0xA5, current_readport + 3);
-			outb_p(0xA5, current_readport + 3);
-			spin_unlock(&io_lock);
-		}
-#endif
-		atomic_inc(&open_allowed);
+	if (code == SYS_DOWN || code == SYS_HALT) {
+		/*
+		 *  If initialisation is still in progress, the device pointer
+		 * may not be valid, so check, just to make sure.
+		 */
+
+		if (pcwd_info.card_info)
+			pcwd_info.card_info->enable_card (0);
 	}
+
+	return NOTIFY_DONE;
+}
+
+/*  C A R D   E N A B L E / D I S A B L E   F U N C T I O N S  */
+/*  Enable/disable the card, not REV A.  The two writes are required by card */
+
+static int
+pcwd_enable_card (int enable)
+{
+	int stat_reg;
+
+	spin_lock (&io_lock);
+	if (enable) {
+		outb_p (0x00, pcwd_info.io_addr + 3);
+	} else {
+		outb_p (0xA5, pcwd_info.io_addr + 3);
+		outb_p (0xA5, pcwd_info.io_addr + 3);
+	}
+	stat_reg = inb_p (pcwd_info.io_addr + 2);
+	spin_unlock (&io_lock);
+
+	stat_reg &= 0x10;	/* "disabled when set" bit */
+	if (enable) {
+		stat_reg ^= 0x10;
+	}
+
+	return stat_reg;
+}
+
+static int
+pcwd_enable_nop (int enable)
+{
 	return 0;
 }
 
-static inline void get_support(void)
+static void __init
+set_card_type (int is_pci)
 {
-	if (inb(current_readport) != 0xF0)
-		supports_temp = 1;
+
+	if (is_pci) {
+		pcwd_info.card_info = &pcwd_card_info[PCWD_REV_PCI];
+		pcwd_info.flags |= PCWD_PCI_REG;
+	} else {
+		pcwd_info.card_info = &pcwd_card_info[PCWD_REV_C];
+
+		/* REV A cards use only 2 io ports; test
+		 * presumes a floating bus reads as 0xff.  */
+		if ((inb (pcwd_info.io_addr + 2) == 0xFF) ||
+		    (inb (pcwd_info.io_addr + 3) == 0xFF)) {
+			pcwd_info.card_info = &pcwd_card_info[PCWD_REV_A];
+		}
+	}
+
+	return;
+}
+
+/* G E T    F I R M W A R E   V E R S I O N   F U N C T I O N S    */
+/* REV A can't do it */
+static void __init
+pcwd_firmware_ver_none (char *bp)
+{
+	strncpy (bp, "<unavailable>", PCWD_FIRMWARE_BSZ);
+
+	return;
 }
 
-static inline int get_revision(void)
+/* PCI boards can too */
+static void __init
+pcwd_firmware_ver_pci (char *bp)
 {
-	int r = PCWD_REVISION_C;
-	
-	spin_lock(&io_lock);
-	if ((inb(current_readport + 2) == 0xFF) ||
-	    (inb(current_readport + 3) == 0xFF))
-		r=PCWD_REVISION_A;
-	spin_unlock(&io_lock);
+	int count;
+
+	/* Write the 'Get Firmware Version' command to port 6 and wait */
+	outb (0x08, pcwd_info.io_addr + 6);
+
+	/* Card sets bit 0x40 (WRSP) bit in port 2.  Can take 10ms! */
+	for (count = 0; count < 15; ++count) {
+		mdelay (1);	/* Board responds slowly */
+
+		if (inb (pcwd_info.io_addr + 2) & 0x40) {
+			/* Board says data now valid */
+
+			snprintf (bp, PCWD_FIRMWARE_BSZ, "%u.%u",
+				  inb (pcwd_info.io_addr + 5),
+				  inb (pcwd_info.io_addr + 4));
 
-	return r;
+			return;
+		}
+	}
+	strncpy (bp, "<card no answer>", PCWD_FIRMWARE_BSZ);
+
+	return;
 }
 
-static int __init send_command(int cmd)
+/*
+ *   REV C boards read diagnostic (including firmware version) data
+ * from the register 0.  To do this, the card is put into diagnostic
+ * mode, then the command is submitted and data read from register 0.
+ * NOTE:  the onboard processor writes 4 bits at a time to the register,
+ * so it's necessary to wait for the data to stabilise before
+ * accepting it.
+ */
+
+static int __init
+send_command (int cmd)
 {
-	int i;
+	int ii;
+
+	int reg0, last_reg0;	/* Double read for stabilising */
 
-	outb_p(cmd, current_readport + 2);
-	mdelay(1);
+	outb (cmd, pcwd_info.io_addr + 2);
+	/*
+	 *    The following delay need only be 200 microseconds according
+	 *  to the spec I have.  But my card seems slower, as waiting
+	 *  250 microseconds returns valid data, but NOT from this
+	 *  command.  The 1000 value may be excessive, but is reliable.
+	 */
+	mdelay (1);
 
-	i = inb(current_readport);
-	i = inb(current_readport);
+	reg0 = inb (pcwd_info.io_addr);
+	for (ii = 0; ii < 25; ++ii) {
+		last_reg0 = reg0;
+		reg0 = inb (pcwd_info.io_addr);
 
-	return(i);
+		if (reg0 == last_reg0)
+			break;	/* Data is stable */
+
+		udelay (250);
+	}
+
+	return reg0;
 }
 
-static inline char *get_firmware(void)
+/*  REV C board function to retrieve firmware version */
+static void __init
+pcwd_firmware_ver_revc (char *bp)
 {
-	int i, found = 0, count = 0, one, ten, hund, minor;
-	char *ret;
+	int i, found = 0, count = 0;
 
-	ret = kmalloc(6, GFP_KERNEL);
-	if(ret == NULL)
-		return NULL;
+	/*  Set the card into debug mode to find firmware version */
+	outb_p (0x00, pcwd_info.io_addr + 2);	/* Spec says to do this */
+	udelay (500);
 
-	while((count < 3) && (!found)) {
-		outb_p(0x80, current_readport + 2);
-		i = inb(current_readport);
+	while ((count < 3) && (!found)) {
+		i = send_command (0x80);
 
-		if (i == 0x00)
+		if (i == 0x00) {
 			found = 1;
-		else if (i == 0xF3)
-			outb_p(0x00, current_readport + 2);
-
-		udelay(400L);
+			break;
+		} else if (i == 0xF3) {
+			/* Card does not like what we've done to it */
+			outb_p (0x00, pcwd_info.io_addr + 2);
+			udelay (1200);	/* Spec says wait 1ms */
+			outb_p (0x00, pcwd_info.io_addr + 2);
+			udelay (500);
+		}
 		count++;
 	}
 
 	if (found) {
-		mode_debug = 1;
 
-		one = send_command(0x81);
-		ten = send_command(0x82);
-		hund = send_command(0x83);
-		minor = send_command(0x84);
-		sprintf(ret, "%c.%c%c%c", one, ten, hund, minor);
-	}
-	else
-		sprintf(ret, "ERROR");
+		*bp++ = send_command (0x81);
+		*bp++ = '.';
+		*bp++ = send_command (0x82);
+		*bp++ = send_command (0x83);
+		*bp++ = send_command (0x84);
+		*bp++ = '\0';
 
-	return(ret);
+		/* Out of debug mode */
+		outb (0x00, pcwd_info.io_addr + 2);
+	} else
+		strncpy (bp, "<err - no go>", PCWD_FIRMWARE_BSZ);
+
+	return;
 }
 
-static void debug_off(void)
+/*   Initialisation function called ONLY from the PCI layer.  */
+
+static int __init
+pcwd_init_one (struct pci_dev *dev, const struct pci_device_id *ent)
 {
-	outb_p(0x00, current_readport + 2);
-	mode_debug = 0;
+	static int devices = 0;
+
+	++devices;
+	if (devices > 1) {
+		printk (KERN_ERR "pcwd: Driver supports only ONE device\n");
+
+		return -ENODEV;
+	}
+
+	pcwd_info.io_addr = pci_resource_start (dev, 0);
+
+	if (pcwd_info.io_addr == 0 || pci_enable_device (dev))
+		return -ENODEV;
+
+	return 0;
 }
 
+static struct pci_device_id pcwd_pci_tbl[] __initdata = {
+	{PCI_VENDOR_ID_QUICKLOGIC, PCI_DEVICE_ID_BERKSHIRE,
+	 PCI_ANY_ID, PCI_ANY_ID,},
+	{0},			/* End of list */
+};
+
+MODULE_DEVICE_TABLE (pci, pcwd_pci_tbl);
+
+static struct pci_driver pcwd_driver = {
+	name:"pcwd",
+	id_table:pcwd_pci_tbl,
+	probe:pcwd_init_one,
+};
+
 static struct file_operations pcwd_fops = {
-	owner:		THIS_MODULE,
-	read:		pcwd_read,
-	write:		pcwd_write,
-	ioctl:		pcwd_ioctl,
-	open:		pcwd_open,
-	release:	pcwd_close,
+	owner:THIS_MODULE,
+	write:pcwd_write,
+	ioctl:pcwd_ioctl,
+	open:pcwd_open,
+	release:pcwd_close,
 };
 
 static struct miscdevice pcwd_miscdev = {
@@ -561,104 +709,224 @@
 	&pcwd_fops
 };
 
+static struct file_operations pcwd_temp_fops = {
+	owner:THIS_MODULE,
+	read:pcwd_read,
+	open:pcwd_open,
+	release:pcwd_close,
+};
+
 static struct miscdevice temp_miscdev = {
 	TEMP_MINOR,
 	"temperature",
-	&pcwd_fops
+	&pcwd_temp_fops
 };
- 
-static int __init pcwatchdog_init(void)
+
+/* Need to know about shutdown to kill the timer - may reset during shutdown! */
+    static struct notifier_block pcwd_notifier =
 {
-	int i, found = 0;
-	spin_lock_init(&io_lock);
-	
-	revision = PCWD_REVISION_A;
-
-	printk("pcwd: v%s Ken Hollis (kenji@bitgate.com)\n", WD_VER);
-
-	/* Initial variables */
-	supports_temp = 0;
-	mode_debug = 0;
-	temp_panic = 0;
-	initial_status = 0x0000;
-
-#ifndef	PCWD_BLIND
-	for (i = 0; pcwd_ioports[i] != 0; i++) {
-		current_readport = pcwd_ioports[i];
+	pcwd_notify_sys,
+	NULL,
+	0,
+};
 
-		if (pcwd_checkcard()) {
-			found = 1;
-			break;
+/*
+ *   The ISA cards have a heartbeat bit in one of the registers, which
+ *  register is card dependent.  The heartbeat bit is monitored, and if
+ *  found, is considered proof that a Berkshire card has been found.
+ *  The initial rate is once per second at board start up, then twice
+ *  per second for normal operation.
+ */
+static int __init
+check_isa_card (int base_addr)
+{
+	int reg0, last_reg0;	/* Reg 0, in case it's REV A */
+	int reg1, last_reg1;	/* Register 1 for REV C cards */
+	int ii;
+	int retval;
+
+	/* As suggested by Alan Cox - this is a safety measure. */
+	if (!request_region (base_addr, 4, "pcwd-isa")) {
+		printk (KERN_INFO "pcwd: Port 0x%x unavailable\n", base_addr);
+		return 0;
+	}
+
+	retval = 0;
+
+	reg0 = inb_p (base_addr);	/* For REV A boards */
+	reg1 = inb (base_addr + 1);	/* For REV C boards */
+	if (reg0 != 0xff || reg1 != 0xff) {
+		/* Not an 'ff' from a floating bus, so must be a card! */
+		for (ii = 0; ii < timeout_val; ++ii) {
+
+			set_current_state (TASK_INTERRUPTIBLE);
+			schedule_timeout (HZ / 2);
+
+			last_reg0 = reg0;
+			last_reg1 = reg1;
+
+			reg0 = inb_p (base_addr);
+			reg1 = inb (base_addr + 1);
+
+			/* Has either hearbeat bit changed?  */
+			if ((reg0 ^ last_reg0) & WD_HRTBT ||
+			    (reg1 ^ last_reg1) & 0x02) {
+
+				retval = 1;
+				break;
+			}
 		}
 	}
+	release_region (base_addr, 4);
 
-	if (!found) {
-		printk("pcwd: No card detected, or port not available.\n");
-		return(-EIO);
+	return retval;
+}
+
+static int __init
+pcwd_card_init (void)
+{
+	int retval;
+	char fvbuf[PCWD_FIRMWARE_BSZ];
+
+	pcwd_info.card_info->firmware_ver (fvbuf);
+
+	printk (KERN_INFO "pcwd: %s at port 0x%03x (Firmware: %s)\n",
+		pcwd_info.card_info->name, pcwd_info.io_addr, fvbuf);
+
+	/* Returns 0xf0 in temperature register if no thermometer */
+	if (inb (pcwd_info.io_addr) != 0xF0) {
+		pcwd_info.flags |= PCWD_HAS_TEMP;
+		printk (KERN_INFO "pcwd: Temperature option detected\n");
 	}
-#endif
 
-#ifdef	PCWD_BLIND
-	current_readport = PCWD_BLIND;
-#endif
+	if (nowayout)
+		printk (KERN_INFO
+			"pcwd: Watchdog cannot be stopped once started\n");
 
-	get_support();
-	revision = get_revision();
+	/* Record the power up status of "card did reset" and/or temp trip */
+	pcwd_info.boot_status = pcwd_info.card_info->wd_status (1);
 
-	if (revision == PCWD_REVISION_A)
-		printk("pcwd: PC Watchdog (REV.A) detected at port 0x%03x\n", current_readport);
-	else if (revision == PCWD_REVISION_C)
-		printk("pcwd: PC Watchdog (REV.C) detected at port 0x%03x (Firmware version: %s)\n",
-			current_readport, get_firmware());
-	else {
-		/* Should NEVER happen, unless get_revision() fails. */
-		printk("pcwd: Unable to get revision.\n");
-		return -1;
+	if (pcwd_info.boot_status & WDIOF_CARDRESET)
+		printk (KERN_INFO
+			"pcwd: Previous reboot was caused by the card\n");
+
+	if (pcwd_info.boot_status & WDIOF_OVERHEAT) {
+		printk (KERN_EMERG
+			"pcwd: Card senses a CPU Overheat.  Panicking!\n");
+		panic ("pcwd: CPU Overheat\n");
 	}
 
-	if (supports_temp)
-		printk("pcwd: Temperature Option Detected.\n");
+	if (pcwd_info.boot_status == 0)
+		printk (KERN_INFO "pcwd: Cold boot sense\n");
 
-	debug_off();
+	pcwd_info.card_info->enable_card (0);
 
-	pcwd_showprevstate();
+	retval = 0;
+	if (!request_region (pcwd_info.io_addr,
+			     pcwd_info.card_info->io_size,
+			     pcwd_info.card_info->name)) {
+		printk (KERN_ERR "pcwd: I/0 %d is not free\n",
+			pcwd_info.io_addr);
 
-	/*  Disable the board  */
-	if (revision == PCWD_REVISION_C) {
-		outb_p(0xA5, current_readport + 3);
-		outb_p(0xA5, current_readport + 3);
+		return retval;
 	}
 
-	if (revision == PCWD_REVISION_A)
-		request_region(current_readport, 2, "PCWD Rev.A (Berkshire)");
-	else
-		request_region(current_readport, 4, "PCWD Rev.C (Berkshire)");
+	retval = misc_register (&pcwd_miscdev);
+	if (retval) {
+		release_region (pcwd_info.io_addr,
+				pcwd_info.card_info->io_size);
+		printk (KERN_ERR "pcwd: can't misc_register on minor %d\n",
+			WATCHDOG_MINOR);
+		return retval;
+	}
 
-	misc_register(&pcwd_miscdev);
+	if (pcwd_info.flags & PCWD_HAS_TEMP) {
+		if (misc_register (&temp_miscdev)) {
+			printk (KERN_ERR
+				"pwcd: can't misc_register thermometer - disabling it\n");
+			pcwd_info.flags &= ~PCWD_HAS_TEMP;
+		}
+	}
 
-	if (supports_temp)
-		misc_register(&temp_miscdev);
+	retval = register_reboot_notifier (&pcwd_notifier);
+	if (retval) {
+		if (pcwd_info.flags & PCWD_HAS_TEMP)
+			misc_deregister (&temp_miscdev);
+		misc_deregister (&pcwd_miscdev);
+		release_region (pcwd_info.io_addr,
+				pcwd_info.card_info->io_size);
+	}
 
-	return 0;
+	return retval;
 }
 
-static void __exit pcwatchdog_exit(void)
+static int __init
+pcwatchdog_init (void)
 {
-	misc_deregister(&pcwd_miscdev);
-	/*  Disable the board  */
-	if (revision == PCWD_REVISION_C) {
-		outb_p(0xA5, current_readport + 3);
-		outb_p(0xA5, current_readport + 3);
+	int i, found = 0;
+	/*
+	 * ISA card auto-probe addresses available.  Last one is only
+	 * available on REV C cards.
+	 */
+	static int pcwd_ioports[] = { 0x270, 0x350, 0x370 };
+#define	PCWD_NUM_ADDR	(sizeof(pcwd_ioports)/sizeof(pcwd_ioports[0]))
+
+	timeout_val = timeout * 2;
+
+	spin_lock_init (&io_lock);
+
+	printk (KERN_INFO "pcwd: v%s Ken Hollis (kenji@bitgate.com)\n", WD_VER);
+
+	if (pci_register_driver (&pcwd_driver) > 0) {
+		found = 1;
+		set_card_type (1);	/* Set to PCI card model */
+	} else {
+		/* No PCI entry, try the ISA addresses.  */
+		for (i = 0; i < PCWD_NUM_ADDR; i++) {
+
+			if (check_isa_card (pcwd_ioports[i])) {
+				found = 1;
+
+				pcwd_info.io_addr = pcwd_ioports[i];
+
+				set_card_type (0);
+				break;
+			}
+		}
 	}
-	if (supports_temp)
-		misc_deregister(&temp_miscdev);
 
-	release_region(current_readport, (revision == PCWD_REVISION_A) ? 2 : 4);
+	if (!found) {
+		printk (KERN_INFO
+			"pcwd: No card detected, or port not available\n");
+		return -EIO;
+	}
+
+	return pcwd_card_init ();
+}
+
+static void __exit
+pcwatchdog_exit (void)
+{
+	unregister_reboot_notifier (&pcwd_notifier);
+	misc_deregister (&pcwd_miscdev);
+
+	if (!nowayout)
+		pcwd_info.card_info->enable_card (0);
+
+	if (pcwd_info.flags & PCWD_HAS_TEMP)
+		misc_deregister (&temp_miscdev);
+
+	release_region (pcwd_info.io_addr, pcwd_info.card_info->io_size);
+
+	if (pcwd_info.flags & PCWD_PCI_REG)
+		pci_unregister_driver (&pcwd_driver);
+
+	return;
 }
 
-module_init(pcwatchdog_init);
-module_exit(pcwatchdog_exit);
+module_init (pcwatchdog_init);
+module_exit (pcwatchdog_exit);
 
-MODULE_LICENSE("GPL");
+MODULE_LICENSE ("GPL");
 
 EXPORT_NO_SYMBOLS;
diff -urN linux-2.4.19-pre9/drivers/char/pty.c linux-2.4.19-pre10/drivers/char/pty.c
--- linux-2.4.19-pre9/drivers/char/pty.c	Fri Dec 21 09:41:54 2001
+++ linux-2.4.19-pre10/drivers/char/pty.c	Mon Jun  3 18:50:54 2002
@@ -5,6 +5,10 @@
  *
  *  Added support for a Unix98-style ptmx device.
  *    -- C. Scott Ananian <cananian@alumni.princeton.edu>, 14-Jan-1998
+ *  Added TTY_DO_WRITE_WAKEUP to enable n_tty to send POLL_OUT to
+ *      waiting writers -- Sapan Bhatia <sapan@corewars.org>
+ *
+ *
  */
 
 #include <linux/config.h>
@@ -331,6 +335,8 @@
 	clear_bit(TTY_OTHER_CLOSED, &tty->link->flags);
 	wake_up_interruptible(&pty->open_wait);
 	set_bit(TTY_THROTTLED, &tty->flags);
+	set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
+
 	/*  Register a slave for the master  */
 	if (tty->driver.major == PTY_MASTER_MAJOR)
 		tty_register_devfs(&tty->link->driver,
diff -urN linux-2.4.19-pre9/drivers/char/rtc.c linux-2.4.19-pre10/drivers/char/rtc.c
--- linux-2.4.19-pre9/drivers/char/rtc.c	Mon Jun  3 18:50:48 2002
+++ linux-2.4.19-pre10/drivers/char/rtc.c	Mon Jun  3 18:50:54 2002
@@ -755,7 +755,7 @@
 	}
 no_irq:
 #else
-	if (check_region (RTC_PORT (0), RTC_IO_EXTENT))
+	if (!request_region(RTC_PORT(0), RTC_IO_EXTENT, "rtc"))
 	{
 		printk(KERN_ERR "rtc: I/O port %d is not free.\n", RTC_PORT (0));
 		return -EIO;
@@ -766,11 +766,11 @@
 	{
 		/* Yeah right, seeing as irq 8 doesn't even hit the bus. */
 		printk(KERN_ERR "rtc: IRQ %d is not free.\n", RTC_IRQ);
+		release_region(RTC_PORT(0), RTC_IO_EXTENT);
 		return -EIO;
 	}
 #endif
 
-	request_region(RTC_PORT(0), RTC_IO_EXTENT, "rtc");
 #endif /* __sparc__ vs. others */
 
 	misc_register(&rtc_dev);
diff -urN linux-2.4.19-pre9/drivers/char/stallion.c linux-2.4.19-pre10/drivers/char/stallion.c
--- linux-2.4.19-pre9/drivers/char/stallion.c	Mon Jun  3 18:50:48 2002
+++ linux-2.4.19-pre10/drivers/char/stallion.c	Mon Jun  3 18:50:54 2002
@@ -1541,7 +1541,8 @@
 	printk("stl_setserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
 #endif
 
-	copy_from_user(&sio, sp, sizeof(struct serial_struct));
+	if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
+		return -EFAULT;
 	if (!capable(CAP_SYS_ADMIN)) {
 		if ((sio.baud_base != portp->baud_base) ||
 		    (sio.close_delay != portp->close_delay) ||
@@ -2898,7 +2899,8 @@
 	stlpanel_t	*panelp;
 	int		i;
 
-	copy_from_user(&stl_brdstats, bp, sizeof(combrd_t));
+	if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t)))
+		return -EFAULT;
 	if (stl_brdstats.brd >= STL_MAXBRDS)
 		return(-ENODEV);
 	brdp = stl_brds[stl_brdstats.brd];
@@ -2922,8 +2924,7 @@
 		stl_brdstats.panels[i].nrports = panelp->nrports;
 	}
 
-	copy_to_user(bp, &stl_brdstats, sizeof(combrd_t));
-	return(0);
+	return copy_to_user(bp, &stl_brdstats, sizeof(combrd_t)) ? -EFAULT : 0;
 }
 
 /*****************************************************************************/
@@ -2966,7 +2967,8 @@
 	unsigned long	flags;
 
 	if (portp == (stlport_t *) NULL) {
-		copy_from_user(&stl_comstats, cp, sizeof(comstats_t));
+		if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
+			return -EFAULT;
 		portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
 			stl_comstats.port);
 		if (portp == (stlport_t *) NULL)
@@ -3007,8 +3009,8 @@
 
 	portp->stats.signals = (unsigned long) stl_getsignals(portp);
 
-	copy_to_user(cp, &portp->stats, sizeof(comstats_t));
-	return(0);
+	return copy_to_user(cp, &portp->stats,
+			    sizeof(comstats_t)) ? -EFAULT : 0;
 }
 
 /*****************************************************************************/
@@ -3020,7 +3022,8 @@
 static int stl_clrportstats(stlport_t *portp, comstats_t *cp)
 {
 	if (portp == (stlport_t *) NULL) {
-		copy_from_user(&stl_comstats, cp, sizeof(comstats_t));
+		if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
+			return -EFAULT;
 		portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
 			stl_comstats.port);
 		if (portp == (stlport_t *) NULL)
@@ -3031,8 +3034,8 @@
 	portp->stats.brd = portp->brdnr;
 	portp->stats.panel = portp->panelnr;
 	portp->stats.port = portp->portnr;
-	copy_to_user(cp, &portp->stats, sizeof(comstats_t));
-	return(0);
+	return copy_to_user(cp, &portp->stats,
+			    sizeof(comstats_t)) ? -EFAULT : 0;
 }
 
 /*****************************************************************************/
@@ -3045,13 +3048,14 @@
 {
 	stlport_t	*portp;
 
-	copy_from_user(&stl_dummyport, (void *) arg, sizeof(stlport_t));
+	if (copy_from_user(&stl_dummyport, (void *) arg, sizeof(stlport_t)))
+		return -EFAULT;
 	portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
 		 stl_dummyport.portnr);
 	if (portp == (stlport_t *) NULL)
 		return(-ENODEV);
-	copy_to_user((void *) arg, portp, sizeof(stlport_t));
-	return(0);
+	return copy_to_user((void *)arg, portp,
+			    sizeof(stlport_t)) ? -EFAULT : 0;
 }
 
 /*****************************************************************************/
@@ -3064,14 +3068,14 @@
 {
 	stlbrd_t	*brdp;
 
-	copy_from_user(&stl_dummybrd, (void *) arg, sizeof(stlbrd_t));
+	if (copy_from_user(&stl_dummybrd, (void *) arg, sizeof(stlbrd_t)))
+		return -EFAULT;
 	if ((stl_dummybrd.brdnr < 0) || (stl_dummybrd.brdnr >= STL_MAXBRDS))
 		return(-ENODEV);
 	brdp = stl_brds[stl_dummybrd.brdnr];
 	if (brdp == (stlbrd_t *) NULL)
 		return(-ENODEV);
-	copy_to_user((void *) arg, brdp, sizeof(stlbrd_t));
-	return(0);
+	return copy_to_user((void *)arg, brdp, sizeof(stlbrd_t)) ? -EFAULT : 0;
 }
 
 /*****************************************************************************/
diff -urN linux-2.4.19-pre9/drivers/char/sx.c linux-2.4.19-pre10/drivers/char/sx.c
--- linux-2.4.19-pre9/drivers/char/sx.c	Mon Jun  3 18:50:48 2002
+++ linux-2.4.19-pre10/drivers/char/sx.c	Mon Jun  3 18:50:54 2002
@@ -1731,8 +1731,11 @@
 		Get_user (data,	 descr++);
 		while (nbytes && data) {
 			for (i=0;i<nbytes;i += SX_CHUNK_SIZE) {
-				copy_from_user (tmp, (char *)data+i, 
-				                (i+SX_CHUNK_SIZE>nbytes)?nbytes-i:SX_CHUNK_SIZE);
+				if (copy_from_user(tmp, (char *)data + i, 
+						   (i + SX_CHUNK_SIZE >
+						    nbytes) ? nbytes - i :
+						   	      SX_CHUNK_SIZE))
+					return -EFAULT;
 				memcpy_toio    ((char *) (board->base2 + offset + i), tmp, 
 				                (i+SX_CHUNK_SIZE>nbytes)?nbytes-i:SX_CHUNK_SIZE);
 			}
diff -urN linux-2.4.19-pre9/drivers/char/tpqic02.c linux-2.4.19-pre10/drivers/char/tpqic02.c
--- linux-2.4.19-pre9/drivers/char/tpqic02.c	Mon Jun  3 18:50:48 2002
+++ linux-2.4.19-pre10/drivers/char/tpqic02.c	Mon Jun  3 18:50:54 2002
@@ -1944,12 +1944,8 @@
 			}
 			/* copy buffer to user-space in one go */
 			if (bytes_done > 0) {
-				err =
-				    copy_to_user(buf, buffaddr,
-						 bytes_done);
-				if (err) {
+				if (copy_to_user(buf, buffaddr, bytes_done))
 					return -EFAULT;
-				}
 			}
 #if 1
 			/* Checks Ton's patch below */
@@ -2085,10 +2081,8 @@
 
 		/* copy from user to DMA buffer and initiate transfer. */
 		if (bytes_todo > 0) {
-			err = copy_from_user(buffaddr, buf, bytes_todo);
-			if (err) {
+			if (copy_from_user(buffaddr, buf, bytes_todo))
 				return -EFAULT;
-			}
 
 /****************** similar problem with read() at FM could happen here at EOT.
  ******************/
diff -urN linux-2.4.19-pre9/drivers/hotplug/Config.in linux-2.4.19-pre10/drivers/hotplug/Config.in
--- linux-2.4.19-pre9/drivers/hotplug/Config.in	Mon Jun  3 18:50:48 2002
+++ linux-2.4.19-pre10/drivers/hotplug/Config.in	Mon Jun  3 18:50:54 2002
@@ -4,7 +4,7 @@
 mainmenu_option next_comment
 comment 'PCI Hotplug Support'
 
-dep_tristate 'Support for PCI Hotplug (EXPERIMENTAL)' CONFIG_HOTPLUG_PCI $CONFIG_EXPERIMENTAL
+dep_tristate 'Support for PCI Hotplug (EXPERIMENTAL)' CONFIG_HOTPLUG_PCI $CONFIG_EXPERIMENTAL $CONFIG_PCI
 
 dep_tristate '  Compaq PCI Hotplug driver' CONFIG_HOTPLUG_PCI_COMPAQ $CONFIG_HOTPLUG_PCI $CONFIG_X86
 dep_mbool '    Save configuration into NVRAM on Compaq servers' CONFIG_HOTPLUG_PCI_COMPAQ_NVRAM $CONFIG_HOTPLUG_PCI_COMPAQ
diff -urN linux-2.4.19-pre9/drivers/ide/ide-floppy.c linux-2.4.19-pre10/drivers/ide/ide-floppy.c
--- linux-2.4.19-pre9/drivers/ide/ide-floppy.c	Mon Jun  3 18:50:48 2002
+++ linux-2.4.19-pre10/drivers/ide/ide-floppy.c	Mon Jun  3 18:50:54 2002
@@ -68,7 +68,7 @@
  * Ver 0.94  Oct 27 00   Tidied up to remove strstr(Clik) everywhere
  * Ver 0.95  Nov  7 00   Brought across to kernel 2.4
  * Ver 0.96  Jan  7 01   Actually in line with release version of 2.4.0
- *                       including set_bit patch from Rusty Russel
+ *                       including set_bit patch from Rusty Russell
  * Ver 0.97  Jul 22 01   Merge 0.91-0.96 onto 0.9.sv for ac series
  * Ver 0.97.sv Aug 3 01  Backported from 2.4.7-ac3
  * Ver 0.98  Oct 26 01   Split idefloppy_transfer_pc into two pieces to
diff -urN linux-2.4.19-pre9/drivers/input/joydev.c linux-2.4.19-pre10/drivers/input/joydev.c
--- linux-2.4.19-pre9/drivers/input/joydev.c	Mon Jun  3 18:50:48 2002
+++ linux-2.4.19-pre10/drivers/input/joydev.c	Mon Jun  3 18:50:54 2002
@@ -363,7 +363,7 @@
 			return copy_to_user((struct js_corr *) arg, joydev->corr,
 						sizeof(struct js_corr) * joydev->nabs) ? -EFAULT : 0;
 		case JSIOCSAXMAP:
-			if (copy_from_user((__u8 *) arg, joydev->abspam, sizeof(__u8) * ABS_MAX))
+			if (copy_from_user(joydev->abspam, (__u8 *) arg, sizeof(__u8) * ABS_MAX))
 				return -EFAULT;
 			for (i = 0; i < ABS_MAX; i++) {
 				if (joydev->abspam[i] > ABS_MAX) return -EINVAL;
@@ -374,7 +374,7 @@
 			return copy_to_user((__u8 *) arg, joydev->abspam,
 						sizeof(__u8) * ABS_MAX) ? -EFAULT : 0;
 		case JSIOCSBTNMAP:
-			if (copy_from_user((__u16 *) arg, joydev->absmap, sizeof(__u16) * (KEY_MAX - BTN_MISC)))
+			if (copy_from_user(joydev->absmap, (__u16 *) arg, sizeof(__u16) * (KEY_MAX - BTN_MISC)))
 				return -EFAULT;
 			for (i = 0; i < KEY_MAX - BTN_MISC; i++); {
 				if (joydev->keypam[i] > KEY_MAX || joydev->keypam[i] < BTN_MISC) return -EINVAL;
diff -urN linux-2.4.19-pre9/drivers/macintosh/via-pmu.c linux-2.4.19-pre10/drivers/macintosh/via-pmu.c
--- linux-2.4.19-pre9/drivers/macintosh/via-pmu.c	Mon Jun  3 18:50:48 2002
+++ linux-2.4.19-pre10/drivers/macintosh/via-pmu.c	Mon Jun  3 18:50:54 2002
@@ -2584,7 +2584,7 @@
 			disable_kernel_backlight--;
 			spin_unlock_irqrestore(&pmu_lock, flags);
 		}
-#endif defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT)
+#endif /* defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT) */
 		kfree(pp);
 	}
 	unlock_kernel();
diff -urN linux-2.4.19-pre9/drivers/net/3c509.c linux-2.4.19-pre10/drivers/net/3c509.c
--- linux-2.4.19-pre9/drivers/net/3c509.c	Mon Jun  3 18:50:48 2002
+++ linux-2.4.19-pre10/drivers/net/3c509.c	Mon Jun  3 18:50:54 2002
@@ -47,10 +47,12 @@
 			- ethtool support
 		v1.18b 1Mar2002 Zwane Mwaikambo <zwane@commfireservices.com>
 			- Power Management support
+                v1.18c 1Mar2002 David Ruggiero <jdr@farfalle.com>
+                        - Full duplex support
 */
 
 #define DRV_NAME	"3c509"
-#define DRV_VERSION	"1.18b"
+#define DRV_VERSION	"1.18c"
 #define DRV_RELDATE	"1Mar2002"
 
 /* A few values that may be tweaked. */
@@ -141,6 +143,8 @@
 #define WN0_IRQ		0x08		/* Window 0: Set IRQ line in bits 12-15. */
 #define WN4_MEDIA	0x0A		/* Window 4: Various transcvr/media bits. */
 #define  MEDIA_TP	0x00C0		/* Enable link beat and jabber for 10baseT. */
+#define WN4_NETDIAG	0x06		/* Window 4: Net diagnostic */
+#define FD_ENABLE	0x8000		/* Enable full-duplex ("external loopback") */  
 
 /*
  * Must be a power of two (we use a binary and in the
@@ -500,12 +504,18 @@
 	memcpy(dev->dev_addr, phys_addr, sizeof(phys_addr));
 	dev->base_addr = ioaddr;
 	dev->irq = irq;
-	dev->if_port = (dev->mem_start & 0x1f) ? dev->mem_start & 3 : if_port;
+        
+	if (dev->mem_start & 0x05) { /* xcvr codes 1/3/4/12 */
+		dev->if_port = (dev->mem_start & 0x0f);
+        } else { /* xcvr codes 0/8 */
+		/* use eeprom value, but save user's full-duplex selection */
+		dev->if_port = (if_port | (dev->mem_start & 0x08) );
+	}
 
 	{
 		const char *if_names[] = {"10baseT", "AUI", "undefined", "BNC"};
 		printk("%s: 3c5x9 at %#3.3lx, %s port, address ",
-			   dev->name, dev->base_addr, if_names[dev->if_port]);
+			dev->name, dev->base_addr, if_names[(dev->if_port & 0x03)]);
 	}
 
 	/* Read in the station address. */
@@ -557,7 +567,7 @@
 /* Read a word from the EEPROM using the regular EEPROM access register.
    Assume that we are in register window zero.
  */
-static ushort __init read_eeprom(int ioaddr, int index)
+static ushort read_eeprom(int ioaddr, int index)
 {
 	outw(EEPROM_READ + index, ioaddr + 10);
 	/* Pause for at least 162 us. for the read to take place. */
@@ -1083,7 +1093,7 @@
 
 static void el3_up(struct net_device *dev)
 {
-	int i;
+	int i, sw_info, net_diag;
 	int ioaddr = dev->base_addr;
 	
 	/* Activating the board required and does no harm otherwise */
@@ -1098,12 +1108,44 @@
 	for (i = 0; i < 6; i++)
 		outb(dev->dev_addr[i], ioaddr + i);
 
-	if (dev->if_port == 3)
+	if ((dev->if_port & 0x03) == 3) /* BNC interface */
 		/* Start the thinnet transceiver. We should really wait 50ms...*/
 		outw(StartCoax, ioaddr + EL3_CMD);
-	else if (dev->if_port == 0) {
-		/* 10baseT interface, enabled link beat and jabber check. */
+	else if ((dev->if_port & 0x03) == 0) { /* 10baseT interface */
+		/* Combine secondary sw_info word (the adapter level) and primary
+			sw_info word (duplex setting plus other useless bits) */
+		EL3WINDOW(0);
+		sw_info = (read_eeprom(ioaddr, 0x14) & 0x400f) | 
+			(read_eeprom(ioaddr, 0x0d) & 0xBff0);
+
 		EL3WINDOW(4);
+		net_diag = inw(ioaddr + WN4_NETDIAG);
+		net_diag = (net_diag | FD_ENABLE); /* temporarily assume full-duplex will be set */
+		printk("%s: ", dev->name);
+		switch (dev->if_port & 0x0c) {
+			case 12:
+				/* force full-duplex mode if 3c5x9b */
+				if (sw_info & 0x000f) {
+					printk("Forcing 3c5x9b full-duplex mode");
+					break;
+				}
+			case 8:
+				/* set full-duplex mode based on eeprom config setting */
+				if ((sw_info & 0x000f) && (sw_info & 0x8000)) {
+					printk("Setting 3c5x9b full-duplex mode (from EEPROM configuration bit)");
+					break;
+				}
+			default:
+				/* xcvr=(0 || 4) OR user has an old 3c5x9 non "B" model */
+				printk("Setting 3c5x9/3c5x9B half-duplex mode");
+				net_diag = (net_diag & ~FD_ENABLE); /* disable full duplex */
+		}
+
+		outw(net_diag, ioaddr + WN4_NETDIAG);
+		printk(" if_port: %d, sw_info: %4.4x\n", dev->if_port, sw_info);
+		if (el3_debug > 3)
+			printk("%s: 3c5x9 net diag word is now: %4.4x.\n", dev->name, net_diag);
+		/* Enable link beat and jabber check. */
 		outw(inw(ioaddr + WN4_MEDIA) | MEDIA_TP, ioaddr + WN4_MEDIA);
 	}
 
@@ -1208,11 +1250,11 @@
 /* Parameters that may be passed into the module. */
 static int debug = -1;
 static int irq[] = {-1, -1, -1, -1, -1, -1, -1, -1};
-static int xcvr[] = {-1, -1, -1, -1, -1, -1, -1, -1};
+static int xcvr[] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
 
 MODULE_PARM(debug,"i");
 MODULE_PARM(irq,"1-8i");
-MODULE_PARM(xcvr,"1-8i");
+MODULE_PARM(xcvr,"1-12i");
 MODULE_PARM(max_interrupt_work, "i");
 MODULE_PARM_DESC(debug, "debug level (0-6)");
 MODULE_PARM_DESC(irq, "IRQ number(s) (assigned)");
diff -urN linux-2.4.19-pre9/drivers/net/3c59x.c linux-2.4.19-pre10/drivers/net/3c59x.c
--- linux-2.4.19-pre9/drivers/net/3c59x.c	Mon Jun  3 18:50:48 2002
+++ linux-2.4.19-pre10/drivers/net/3c59x.c	Fri Dec 21 09:41:54 2001
@@ -166,15 +166,7 @@
     - Rename wait_for_completion() to issue_and_wait() to avoid completion.h
       clash.
 
-   LK1.1.17 18Dec01 akpm
-    - PCI ID 9805 is a Python-T, not a dual-port Cyclone.  Apparently.
-      And it has NWAY.
-    - Mask our advertised modes (vp->advertising) with our capabilities
-	  (MII reg5) when deciding which duplex mode to use.
-    - Add `global_options' as default for options[].  Ditto global_enable_wol,
-      global_full_duplex.
-
-    - See http://www.zip.com.au/~akpm/linux/#3c59x-2.3 for more details.
+    - See http://www.uow.edu.au/~andrewm/linux/#3c59x-2.3 for more details.
     - Also see Documentation/networking/vortex.txt
 */
 
@@ -189,8 +181,8 @@
 
 
 #define DRV_NAME	"3c59x"
-#define DRV_VERSION	"LK1.1.17"
-#define DRV_RELDATE	"18 Dec 2001"
+#define DRV_VERSION	"LK1.1.16"
+#define DRV_RELDATE	"19 July 2001"
 
 
 
@@ -278,13 +270,10 @@
 MODULE_LICENSE("GPL");
 
 MODULE_PARM(debug, "i");
-MODULE_PARM(global_options, "i");
 MODULE_PARM(options, "1-" __MODULE_STRING(8) "i");
-MODULE_PARM(global_full_duplex, "i");
 MODULE_PARM(full_duplex, "1-" __MODULE_STRING(8) "i");
 MODULE_PARM(hw_checksums, "1-" __MODULE_STRING(8) "i");
 MODULE_PARM(flow_ctrl, "1-" __MODULE_STRING(8) "i");
-MODULE_PARM(global_enable_wol, "i");
 MODULE_PARM(enable_wol, "1-" __MODULE_STRING(8) "i");
 MODULE_PARM(rx_copybreak, "i");
 MODULE_PARM(max_interrupt_work, "i");
@@ -294,13 +283,10 @@
 MODULE_PARM(watchdog, "i");
 MODULE_PARM_DESC(debug, "3c59x debug level (0-6)");
 MODULE_PARM_DESC(options, "3c59x: Bits 0-3: media type, bit 4: bus mastering, bit 9: full duplex");
-MODULE_PARM_DESC(global_options, "3c59x: same as options, but applies to all NICs if options is unset");
 MODULE_PARM_DESC(full_duplex, "3c59x full duplex setting(s) (1)");
-MODULE_PARM_DESC(global_full_duplex, "3c59x: same as full_duplex, but applies to all NICs if options is unset");
 MODULE_PARM_DESC(hw_checksums, "3c59x Hardware checksum checking by adapter(s) (0-1)");
 MODULE_PARM_DESC(flow_ctrl, "3c59x 802.3x flow control usage (PAUSE only) (0-1)");
 MODULE_PARM_DESC(enable_wol, "3c59x: Turn on Wake-on-LAN for adapter(s) (0-1)");
-MODULE_PARM_DESC(global_enable_wol, "3c59x: same as enable_wol, but applies to all NICs if options is unset");
 MODULE_PARM_DESC(rx_copybreak, "3c59x copy breakpoint for copy-only-tiny-frames");
 MODULE_PARM_DESC(max_interrupt_work, "3c59x maximum events handled per interrupt");
 MODULE_PARM_DESC(compaq_ioaddr, "3c59x PCI I/O base address (Compaq BIOS problem workaround)");
@@ -487,7 +473,7 @@
 	{"3c900 Boomerang 10Mbps Combo",
 	 PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG, 64, },
 	{"3c900 Cyclone 10Mbps TPO",						/* AKPM: from Don's 0.99M */
-	 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_HWCKSM, 128, },
+	 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_HWCKSM, 128, },
 	{"3c900 Cyclone 10Mbps Combo",
 	 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_HWCKSM, 128, },
 
@@ -510,8 +496,8 @@
 	 PCI_USES_IO|PCI_USES_MASTER, IS_TORNADO|HAS_NWAY|HAS_HWCKSM, 128, },
 	{"3c980 Cyclone",
 	 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_HWCKSM, 128, },
-	{"3c980C Python-T",
-	 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_HWCKSM, 128, },
+	{"3c982 Dual Port Server Cyclone",
+	 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_HWCKSM, 128, },
 
 	{"3cSOHO100-TX Hurricane",
 	 PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_HWCKSM, 128, },
@@ -867,9 +853,6 @@
 static int hw_checksums[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
 static int flow_ctrl[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
 static int enable_wol[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
-static int global_options = -1;
-static int global_full_duplex = -1;
-static int global_enable_wol = -1;
 
 /* #define dev_alloc_skb dev_alloc_skb_debug */
 
@@ -1012,8 +995,6 @@
 	SET_MODULE_OWNER(dev);
 	vp = dev->priv;
 
-	option = global_options;
-
 	/* The lower four bits are the media type. */
 	if (dev->mem_start) {
 		/*
@@ -1022,10 +1003,10 @@
 		 */
 		option = dev->mem_start;
 	}
-	else if (card_idx < MAX_UNITS) {
-		if (options[card_idx] >= 0)
-			option = options[card_idx];
-	}
+	else if (card_idx < MAX_UNITS)
+		option = options[card_idx];
+	else
+		option = -1;
 
 	if (option > 0) {
 		if (option & 0x8000)
@@ -1118,11 +1099,6 @@
 		vp->bus_master = (option & 16) ? 1 : 0;
 	}
 
-	if (global_full_duplex > 0)
-		vp->full_duplex = 1;
-	if (global_enable_wol > 0)
-		vp->enable_wol = 1;
-
 	if (card_idx < MAX_UNITS) {
 		if (full_duplex[card_idx] > 0)
 			vp->full_duplex = 1;
@@ -1268,12 +1244,11 @@
 	} else
 		dev->if_port = vp->default_media;
 
-	if ((vp->available_media & 0x4b) || (vci->drv_flags & HAS_NWAY) ||
-		dev->if_port == XCVR_MII || dev->if_port == XCVR_NWAY) {
+	if (dev->if_port == XCVR_MII || dev->if_port == XCVR_NWAY) {
 		int phy, phy_idx = 0;
 		EL3WINDOW(4);
 		mii_preamble_required++;
-		mdio_sync(ioaddr, 32);
+		mii_preamble_required++;
 		mdio_read(dev, 24, 1);
 		for (phy = 0; phy < 32 && phy_idx < 1; phy++) {
 			int mii_status, phyx;
@@ -1289,8 +1264,6 @@
 			else
 				phyx = phy;
 			mii_status = mdio_read(dev, phyx, 1);
-		printk("phy=%d, phyx=%d, mii_status=0x%04x\n",
-			phy, phyx, mii_status);
 			if (mii_status  &&  mii_status != 0xffff) {
 				vp->phys[phy_idx++] = phyx;
 				if (print_info) {
@@ -1471,14 +1444,11 @@
 		/* Read BMSR (reg1) only to clear old status. */
 		mii_reg1 = mdio_read(dev, vp->phys[0], 1);
 		mii_reg5 = mdio_read(dev, vp->phys[0], 5);
-		if (mii_reg5 == 0xffff  ||  mii_reg5 == 0x0000) {
+		if (mii_reg5 == 0xffff  ||  mii_reg5 == 0x0000)
 			;					/* No MII device or no link partner report */
-		} else {
-			mii_reg5 &= vp->advertising;
-			if ((mii_reg5 & 0x0100) != 0	/* 100baseTx-FD */
+		else if ((mii_reg5 & 0x0100) != 0	/* 100baseTx-FD */
 				 || (mii_reg5 & 0x00C0) == 0x0040) /* 10T-FD, but not 100-HD */
 			vp->full_duplex = 1;
-		}
 		vp->partner_flow_ctrl = ((mii_reg5 & 0x0400) != 0);
 		if (vortex_debug > 1)
 			printk(KERN_INFO "%s: MII #%d status %4.4x, link partner capability %4.4x,"
@@ -1699,10 +1669,8 @@
 			if (mii_status & 0x0004) {
 				int mii_reg5 = mdio_read(dev, vp->phys[0], 5);
 				if (! vp->force_fd  &&  mii_reg5 != 0xffff) {
-					int duplex;
-
-					mii_reg5 &= vp->advertising;
-					duplex = (mii_reg5&0x0100) || (mii_reg5 & 0x01C0) == 0x0040;
+					int duplex = (mii_reg5&0x0100) ||
+						(mii_reg5 & 0x01C0) == 0x0040;
 					if (vp->full_duplex != duplex) {
 						vp->full_duplex = duplex;
 						printk(KERN_INFO "%s: Setting %s-duplex based on MII "
@@ -1785,11 +1753,9 @@
 		   dev->name, inb(ioaddr + TxStatus),
 		   inw(ioaddr + EL3_STATUS));
 	EL3WINDOW(4);
-	printk(KERN_ERR "  diagnostics: net %04x media %04x dma %08x fifo %04x\n",
-			inw(ioaddr + Wn4_NetDiag),
-			inw(ioaddr + Wn4_Media),
-			inl(ioaddr + PktStatus),
-			inw(ioaddr + Wn4_FIFODiag));
+	printk(KERN_ERR "  diagnostics: net %04x media %04x dma %8.8x.\n",
+		   inw(ioaddr + Wn4_NetDiag), inw(ioaddr + Wn4_Media),
+		   inl(ioaddr + PktStatus));
 	/* Slight code bloat to be user friendly. */
 	if ((inb(ioaddr + TxStatus) & 0x88) == 0x88)
 		printk(KERN_ERR "%s: Transmitter encountered 16 collisions --"
@@ -2572,6 +2538,7 @@
 			((vp->drv_flags & HAS_HWCKSM) == 0) &&
 			(hw_checksums[vp->card_idx] == -1)) {
 		printk(KERN_WARNING "%s supports hardware checksums, and we're not using them!\n", dev->name);
+		printk(KERN_WARNING "Please see http://www.uow.edu.au/~andrewm/zerocopy.html\n");
 	}
 #endif
 		
diff -urN linux-2.4.19-pre9/drivers/net/8139too.c linux-2.4.19-pre10/drivers/net/8139too.c
--- linux-2.4.19-pre9/drivers/net/8139too.c	Mon Jun  3 18:50:48 2002
+++ linux-2.4.19-pre10/drivers/net/8139too.c	Mon Jun  3 18:50:54 2002
@@ -2329,7 +2329,7 @@
 
 	if (cmd != SIOCETHTOOL) {
 		/* With SIOCETHTOOL, this would corrupt the pointer.  */
-		data->phy_id &= 0x1f;
+		data->phy_id &= 0x3f;
 		data->reg_num &= 0x1f;
 	}
 
diff -urN linux-2.4.19-pre9/drivers/net/acenic.c linux-2.4.19-pre10/drivers/net/acenic.c
--- linux-2.4.19-pre9/drivers/net/acenic.c	Mon Jun  3 18:50:48 2002
+++ linux-2.4.19-pre10/drivers/net/acenic.c	Mon Jun  3 18:50:54 2002
@@ -120,6 +120,10 @@
 #ifndef PCI_DEVICE_ID_FARALLON_PN9000SX
 #define PCI_DEVICE_ID_FARALLON_PN9000SX	0x1a
 #endif
+#ifndef PCI_DEVICE_ID_FARALLON_PN9100T
+#define PCI_DEVICE_ID_FARALLON_PN9100T  0xfa
+#endif
+
 #ifndef PCI_VENDOR_ID_SGI
 #define PCI_VENDOR_ID_SGI		0x10a9
 #endif
@@ -144,6 +148,9 @@
 	 */
 	{ PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_FARALLON_PN9000SX,
 	  PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, },
+	{ PCI_VENDOR_ID_ALTEON, PCI_DEVICE_ID_FARALLON_PN9100T,
+	  PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, },
+
 	{ PCI_VENDOR_ID_SGI, PCI_DEVICE_ID_SGI_ACENIC,
 	  PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NETWORK_ETHERNET << 8, 0xffff00, },
 	{ }
@@ -611,6 +618,8 @@
 		 */
 		    !((pdev->vendor == PCI_VENDOR_ID_DEC) &&
 		      (pdev->device == PCI_DEVICE_ID_FARALLON_PN9000SX)) &&
+		    !((pdev->vendor == PCI_VENDOR_ID_ALTEON) &&
+		      (pdev->device == PCI_DEVICE_ID_FARALLON_PN9100T)) &&
 		    !((pdev->vendor == PCI_VENDOR_ID_SGI) &&
 		      (pdev->device == PCI_DEVICE_ID_SGI_ACENIC)))
 			continue;
@@ -708,6 +717,13 @@
 
 		switch(pdev->vendor) {
 		case PCI_VENDOR_ID_ALTEON:
+			if (pdev->device == PCI_DEVICE_ID_FARALLON_PN9100T) {
+				strncpy(ap->name, "Farallon PN9100-T "
+					"Gigabit Ethernet", sizeof (ap->name));
+				printk(KERN_INFO "%s: Farallon PN9100-T ",
+				       dev->name);
+				break;
+			}
 			strncpy(ap->name, "AceNIC Gigabit Ethernet",
 				sizeof (ap->name));
 			printk(KERN_INFO "%s: Alteon AceNIC ", dev->name);
diff -urN linux-2.4.19-pre9/drivers/net/cs89x0.c linux-2.4.19-pre10/drivers/net/cs89x0.c
--- linux-2.4.19-pre9/drivers/net/cs89x0.c	Mon Feb 25 11:37:59 2002
+++ linux-2.4.19-pre10/drivers/net/cs89x0.c	Mon Jun  3 18:50:54 2002
@@ -81,6 +81,9 @@
                     : Make `version[]' __initdata
                     : Uninlined the read/write reg/word functions.
 
+  Oskar Schirmer    : oskar@scara.com
+                    : HiCO.SH4 (superh) support added (irq#1, cs89x0_media=)
+
 */
 
 /* Always include 'config.h' first in case the user wants to turn on
@@ -156,6 +159,10 @@
 static unsigned int netcard_portlist[] __initdata =
    { 0x80090303, 0x300, 0x320, 0x340, 0x360, 0x200, 0x220, 0x240, 0x260, 0x280, 0x2a0, 0x2c0, 0x2e0, 0};
 static unsigned int cs8900_irq_map[] = {12,0,0,0};
+#elif defined(CONFIG_SH_HICOSH4)
+static unsigned int netcard_portlist[] __initdata =
+   { 0x0300, 0};
+static unsigned int cs8900_irq_map[] = {1,0,0,0};
 #else
 static unsigned int netcard_portlist[] __initdata =
    { 0x300, 0x320, 0x340, 0x360, 0x200, 0x220, 0x240, 0x260, 0x280, 0x2a0, 0x2c0, 0x2e0, 0};
@@ -247,6 +254,20 @@
 __setup("cs89x0_dma=", dma_fn);
 #endif	/* !defined(MODULE) && (ALLOW_DMA != 0) */
 
+#ifndef MODULE
+static int g_cs89x0_media__force;
+
+static int __init media_fn(char *str)
+{
+	if (!strcmp(str, "rj45")) g_cs89x0_media__force = FORCE_RJ45;
+	else if (!strcmp(str, "aui")) g_cs89x0_media__force = FORCE_AUI;
+	else if (!strcmp(str, "bnc")) g_cs89x0_media__force = FORCE_BNC;
+	return 1;
+}
+
+__setup("cs89x0_media=", media_fn);
+#endif
+
 
 /* Check for a network adaptor of this type, and return '0' iff one exists.
    If dev->base_addr == 0, probe all likely locations.
@@ -383,6 +404,9 @@
 			lp->dmasize = 16;	/* Could make this an option... */
 		}
 #endif
+#ifndef MODULE
+		lp->force = g_cs89x0_media__force;
+#endif
         }
 	lp = (struct net_local *)dev->priv;
 
@@ -394,6 +418,12 @@
 		goto out1;
 	}
 
+#ifdef CONFIG_SH_HICOSH4
+	/* truely reset the chip */
+	outw(0x0114, ioaddr + ADD_PORT);
+	outw(0x0040, ioaddr + DATA_PORT);
+#endif
+
 	/* if they give us an odd I/O address, then do ONE write to
            the address port, to get it back to address zero, where we
            expect to find the EISA signature word. An IO with a base of 0x3
@@ -413,7 +443,7 @@
 	}
 printk("PP_addr=0x%x\n", inw(ioaddr + ADD_PORT));
 
-        if (inw(ioaddr + DATA_PORT) != CHIP_EISA_ID_SIG) {
+	if (inw(ioaddr + DATA_PORT) != CHIP_EISA_ID_SIG) {
 		printk(KERN_ERR "%s: incorrect signature 0x%x\n",
 			dev->name, inw(ioaddr + DATA_PORT));
   		retval = -ENODEV;
@@ -454,6 +484,39 @@
 	   EEPROM read on reset. So, if the chip says it read the EEPROM
 	   the driver will always do *something* instead of complain that
 	   adapter_cnf is 0. */
+
+#ifdef CONFIG_SH_HICOSH4
+	if (1) {
+		/* For the HiCO.SH4 board, things are different: we don't
+		   have EEPROM, but there is some data in flash, so we go
+		   get it there directly (MAC). */
+		__u16 *confd;
+		short cnt;
+		if (((* (volatile __u32 *) 0xa0013ff0) & 0x00ffffff)
+			== 0x006c3000) {
+			confd = (__u16*) 0xa0013fc0;
+		} else {
+			confd = (__u16*) 0xa001ffc0;
+		}
+		cnt = (*confd++ & 0x00ff) >> 1;
+		while (--cnt > 0) {
+			__u16 j = *confd++;
+			
+			switch (j & 0x0fff) {
+			case PP_IA:
+				for (i = 0; i < ETH_ALEN/2; i++) {
+					dev->dev_addr[i*2] = confd[i] & 0xFF;
+					dev->dev_addr[i*2+1] = confd[i] >> 8;
+				}
+				break;
+			}
+			j = (j >> 12) + 1;
+			confd += j;
+			cnt -= j;
+		}
+	} else
+#endif
+
         if ((readreg(dev, PP_SelfST) & (EEPROM_OK | EEPROM_PRESENT)) == 
 	      (EEPROM_OK|EEPROM_PRESENT)) {
 	        /* Load the MAC. */
@@ -507,6 +570,11 @@
         printk("\n");
    
 	/* First check to see if an EEPROM is attached. */
+#ifdef CONFIG_SH_HICOSH4 /* no EEPROM on HiCO, don't hazzle with it here */
+	if (1) {
+		printk(KERN_NOTICE "cs89x0: No EEPROM on HiCO.SH4\n");
+	} else
+#endif
 	if ((readreg(dev, PP_SelfST) & EEPROM_PRESENT) == 0)
 		printk(KERN_WARNING "cs89x0: No EEPROM, relying on command line....\n");
 	else if (get_eeprom_data(dev, START_EEPROM_DATA,CHKSUM_LEN,eeprom_buff) < 0) {
@@ -616,10 +684,10 @@
 	}
 
 	/* print the ethernet address. */
-	printk(", MAC ");
+	printk(", MAC");
 	for (i = 0; i < ETH_ALEN; i++)
 	{
-		printk("%s%02x", i ? ":" : "", dev->dev_addr[i]);
+		printk("%c%02x", i ? ':' : ' ', dev->dev_addr[i]);
 	}
 
 	dev->open		= net_open;
@@ -1046,6 +1114,7 @@
 	int i;
 	int ret;
 
+#ifndef CONFIG_SH_HICOSH4 /* uses irq#1, so this wont work */
 	if (dev->irq < 2) {
 		/* Allow interrupts to be generated by the chip */
 /* Cirrus' release had this: */
@@ -1056,7 +1125,7 @@
 		writereg(dev, PP_BusCTL, ENABLE_IRQ | MEMORY_ON);
 
 		for (i = 2; i < CS8920_NO_INTS; i++) {
-			if ((1 << dev->irq) & lp->irq_map) {
+			if ((1 << i) & lp->irq_map) {
 				if (request_irq(i, net_interrupt, 0, dev->name, dev) == 0) {
 					dev->irq = i;
 					write_irq(dev, lp->chip_type, i);
@@ -1072,7 +1141,10 @@
 			ret = -EAGAIN;
 			goto bad_out;
 		}
-	} else {
+	}
+	else
+#endif
+	{
 		if (((1 << dev->irq) & lp->irq_map) == 0) {
 			printk(KERN_ERR "%s: IRQ %d is not in our map of allowable IRQs, which is %x\n",
                                dev->name, dev->irq, lp->irq_map);
diff -urN linux-2.4.19-pre9/drivers/net/cs89x0.h linux-2.4.19-pre10/drivers/net/cs89x0.h
--- linux-2.4.19-pre9/drivers/net/cs89x0.h	Fri Mar  3 12:56:13 2000
+++ linux-2.4.19-pre10/drivers/net/cs89x0.h	Mon Jun  3 18:50:54 2002
@@ -437,7 +437,11 @@
 #define IRQ_MAP_EEPROM_DATA 0x0046 /*  Offset into eeprom for the IRQ map */
 #define IRQ_MAP_LEN 0x0004 /*  No of bytes to read for the IRQ map */
 #define PNP_IRQ_FRMT 0x0022 /*  PNP small item IRQ format */
+#ifdef CONFIG_SH_HICOSH4
+#define CS8900_IRQ_MAP 0x0002 /* HiCO-SH4 board has its IRQ on #1 */
+#else
 #define CS8900_IRQ_MAP 0x1c20 /*  This IRQ map is fixed */
+#endif
 
 #define CS8920_NO_INTS 0x0F   /*  Max CS8920 interrupt select # */
 
diff -urN linux-2.4.19-pre9/drivers/net/de4x5.c linux-2.4.19-pre10/drivers/net/de4x5.c
--- linux-2.4.19-pre9/drivers/net/de4x5.c	Mon Jun  3 18:50:48 2002
+++ linux-2.4.19-pre10/drivers/net/de4x5.c	Mon Jun  3 18:50:54 2002
@@ -866,7 +866,7 @@
 ** offsets in the PCI and EISA boards. Also note that the ethernet address
 ** PROM is accessed differently.
 */
-static struct bus_type {
+static struct de4x5_bus_type {
     int bus;
     int bus_num;
     int device;
@@ -967,10 +967,10 @@
 static int     test_ans(struct net_device *dev, s32 irqs, s32 irq_mask, s32 msec);
 static int     test_tp(struct net_device *dev, s32 msec);
 static int     EISA_signature(char *name, s32 eisa_id);
-static int     PCI_signature(char *name, struct bus_type *lp);
+static int     PCI_signature(char *name, struct de4x5_bus_type *lp);
 static void    DevicePresent(u_long iobase);
 static void    enet_addr_rst(u_long aprom_addr);
-static int     de4x5_bad_srom(struct bus_type *lp);
+static int     de4x5_bad_srom(struct de4x5_bus_type *lp);
 static short   srom_rd(u_long address, u_char offset);
 static void    srom_latch(u_int command, u_long address);
 static void    srom_command(u_int command, u_long address);
@@ -998,7 +998,7 @@
 static int     get_hw_addr(struct net_device *dev);
 static void    srom_repair(struct net_device *dev, int card);
 static int     test_bad_enet(struct net_device *dev, int status);
-static int     an_exception(struct bus_type *lp);
+static int     an_exception(struct de4x5_bus_type *lp);
 #if !defined(__sparc_v9__) && !defined(__powerpc__) && !defined(__alpha__)
 static void    eisa_probe(struct net_device *dev, u_long iobase);
 #endif
@@ -1143,7 +1143,7 @@
 static int __init 
 de4x5_hw_init(struct net_device *dev, u_long iobase, struct pci_dev *pdev)
 {
-    struct bus_type *lp = &bus;
+    struct de4x5_bus_type *lp = &bus;
     int i, status=0;
     char *tmp;
     
@@ -2105,7 +2105,7 @@
     u_short vendor;
     u32 cfid;
     u_long iobase;
-    struct bus_type *lp = &bus;
+    struct de4x5_bus_type *lp = &bus;
     char name[DE4X5_STRLEN];
 
     if (lastEISA == MAX_EISA_SLOTS) return;/* No more EISA devices to search */
@@ -2186,7 +2186,7 @@
     u_short vendor, index, status;
     u_int irq = 0, device, class = DE4X5_CLASS_CODE;
     u_long iobase = 0;                     /* Clear upper 32 bits in Alphas */
-    struct bus_type *lp = &bus;
+    struct de4x5_bus_type *lp = &bus;
 
     if (lastPCI == NO_MORE_PCI) return;
 
@@ -2299,7 +2299,7 @@
     u_int irq = 0, device;
     u_long iobase = 0;                     /* Clear upper 32 bits in Alphas */
     int i, j;
-    struct bus_type *lp = &bus;
+    struct de4x5_bus_type *lp = &bus;
     struct list_head *walk = &dev->bus_list;
 
     for (walk = walk->next; walk != &dev->bus_list; walk = walk->next) {
@@ -3992,7 +3992,7 @@
 ** Look for a particular board name in the PCI configuration space
 */
 static int
-PCI_signature(char *name, struct bus_type *lp)
+PCI_signature(char *name, struct de4x5_bus_type *lp)
 {
     static c_char *de4x5_signatures[] = DE4X5_SIGNATURE;
     int i, status = 0, siglen = sizeof(de4x5_signatures)/sizeof(c_char *);
@@ -4041,7 +4041,7 @@
 DevicePresent(u_long aprom_addr)
 {
     int i, j=0;
-    struct bus_type *lp = &bus;
+    struct de4x5_bus_type *lp = &bus;
     
     if (lp->chipset == DC21040) {
 	if (lp->bus == EISA) {
@@ -4122,7 +4122,7 @@
     u_long iobase = dev->base_addr;
     int broken, i, k, tmp, status = 0;
     u_short j,chksum;
-    struct bus_type *lp = &bus;
+    struct de4x5_bus_type *lp = &bus;
 
     broken = de4x5_bad_srom(lp);
 
@@ -4203,7 +4203,7 @@
 ** didn't seem to work here...?
 */
 static int
-de4x5_bad_srom(struct bus_type *lp)
+de4x5_bad_srom(struct de4x5_bus_type *lp)
 {
     int i, status = 0;
 
@@ -4237,7 +4237,7 @@
 static void
 srom_repair(struct net_device *dev, int card)
 {
-    struct bus_type *lp = &bus;
+    struct de4x5_bus_type *lp = &bus;
 
     switch(card) {
       case SMC:
@@ -4258,7 +4258,7 @@
 static int
 test_bad_enet(struct net_device *dev, int status)
 {
-    struct bus_type *lp = &bus;
+    struct de4x5_bus_type *lp = &bus;
     int i, tmp;
 
     for (tmp=0,i=0; i<ETH_ALEN; i++) tmp += (u_char)dev->dev_addr[i];
@@ -4291,7 +4291,7 @@
 ** List of board exceptions with correctly wired IRQs
 */
 static int
-an_exception(struct bus_type *lp)
+an_exception(struct de4x5_bus_type *lp)
 {
     if ((*(u_short *)lp->srom.sub_vendor_id == 0x00c0) && 
 	(*(u_short *)lp->srom.sub_system_id == 0x95e0)) {
diff -urN linux-2.4.19-pre9/drivers/net/dl2k.c linux-2.4.19-pre10/drivers/net/dl2k.c
--- linux-2.4.19-pre9/drivers/net/dl2k.c	Mon Jun  3 18:50:48 2002
+++ linux-2.4.19-pre10/drivers/net/dl2k.c	Mon Jun  3 18:50:54 2002
@@ -29,24 +29,28 @@
     1.08	2002/01/17	Fixed the multicast bug.
     1.09	2002/03/07	Move rx-poll-now to re-fill loop.	
     				Added rio_timer() to watch rx buffers. 
+    1.10	2002/04/16	Fixed miscount of carrier error.
+    1.11	2002/05/23	Added ISR schedule scheme.
+    				Fixed miscount of rx frame error for DGE-550SX.
+    				Fixed VLAN bug.
  */
 
 #include "dl2k.h"
 
 static char version[] __devinitdata =
-    KERN_INFO "D-Link DL2000-based linux driver v1.09 2002/03/07\n";
+    KERN_INFO "D-Link DL2000-based linux driver v1.11 2002/05/23\n";
 
 #define MAX_UNITS 8
 static int mtu[MAX_UNITS];
 static int vlan[MAX_UNITS];
 static int jumbo[MAX_UNITS];
 static char *media[MAX_UNITS];
-static int tx_flow[MAX_UNITS];
-static int rx_flow[MAX_UNITS];
+static int tx_flow=-1;
+static int rx_flow=-1;
 static int copy_thresh;
-static int rx_coalesce;			/* Rx frame count each interrupt */
-static int rx_timeout; 			/* Rx DMA wait time in 64ns increments */
-static int tx_coalesce = DEFAULT_TXC; 	/* HW xmit count each TxComplete [1-8] */
+static int rx_coalesce=10;	/* Rx frame count each interrupt */
+static int rx_timeout=200;	/* Rx DMA wait time in 640ns increments */
+static int tx_coalesce=16;	/* HW xmit count each TxDMAComplete */
 
 
 MODULE_AUTHOR ("Edward Peng");
@@ -56,16 +60,16 @@
 MODULE_PARM (media, "1-" __MODULE_STRING (MAX_UNITS) "s");
 MODULE_PARM (vlan, "1-" __MODULE_STRING (MAX_UNITS) "i");
 MODULE_PARM (jumbo, "1-" __MODULE_STRING (MAX_UNITS) "i");
-MODULE_PARM (tx_flow, "1-" __MODULE_STRING (MAX_UNITS) "i");
-MODULE_PARM (rx_flow, "1-" __MODULE_STRING (MAX_UNITS) "i");
+MODULE_PARM (tx_flow, "i");
+MODULE_PARM (rx_flow, "i");
 MODULE_PARM (copy_thresh, "i");
 MODULE_PARM (rx_coalesce, "i");	/* Rx frame count each interrupt */
 MODULE_PARM (rx_timeout, "i");	/* Rx DMA wait time in 64ns increments */
-MODULE_PARM (tx_coalesce, "i"); /* HW xmit count each TxComplete [1-8] */
+MODULE_PARM (tx_coalesce, "i"); /* HW xmit count each TxDMAComplete */
 
 
 /* Enable the default interrupts */
-#define DEFAULT_INTR (RxDMAComplete | HostError | IntRequested | TxComplete| \
+#define DEFAULT_INTR (RxDMAComplete | HostError | IntRequested | TxDMAComplete| \
        UpdateStats | LinkEvent)
 #define EnableInt() \
 writew(DEFAULT_INTR, ioaddr + IntEnable)
@@ -75,16 +79,18 @@
 
 static int rio_open (struct net_device *dev);
 static void rio_timer (unsigned long data);
-static void tx_timeout (struct net_device *dev);
+static void rio_tx_timeout (struct net_device *dev);
 static void alloc_list (struct net_device *dev);
 static int start_xmit (struct sk_buff *skb, struct net_device *dev);
 static void rio_interrupt (int irq, void *dev_instance, struct pt_regs *regs);
+static void rio_free_tx (struct net_device *dev, int irq);
 static void tx_error (struct net_device *dev, int tx_status);
 static int receive_packet (struct net_device *dev);
 static void rio_error (struct net_device *dev, int int_status);
 static int change_mtu (struct net_device *dev, int new_mtu);
 static void set_multicast (struct net_device *dev);
 static struct net_device_stats *get_stats (struct net_device *dev);
+static int clear_stats (struct net_device *dev);
 static int rio_ioctl (struct net_device *dev, struct ifreq *rq, int cmd);
 static int rio_close (struct net_device *dev);
 static int find_miiphy (struct net_device *dev);
@@ -98,9 +104,6 @@
 static int mii_read (struct net_device *dev, int phy_addr, int reg_num);
 static int mii_write (struct net_device *dev, int phy_addr, int reg_num,
 		      u16 data);
-#ifdef RIO_DEBUG
-static int rio_ioctl_ext (struct net_device *dev, struct ioctl_data *iodata);
-#endif
 
 static int __devinit
 rio_probe1 (struct pci_dev *pdev, const struct pci_device_id *ent)
@@ -109,7 +112,7 @@
 	struct netdev_private *np;
 	static int card_idx;
 	int chip_idx = ent->driver_data;
-	int err, irq = pdev->irq;
+	int err, irq;
 	long ioaddr;
 	static int version_printed;
 	void *ring_space;
@@ -122,6 +125,7 @@
 	if (err)
 		return err;
 
+	irq = pdev->irq;
 	err = pci_request_regions (pdev, "dl2k");
 	if (err)
 		goto err_out_disable;
@@ -149,7 +153,7 @@
 	np = dev->priv;
 	np->chip_id = chip_idx;
 	np->pdev = pdev;
-	spin_lock_init (&np->lock);
+	spin_lock_init (&np->tx_lock);
 	spin_lock_init (&np->rx_lock);
 
 	/* Parse manual configuration */
@@ -199,17 +203,18 @@
 		}
 		np->vlan = (vlan[card_idx] > 0 && vlan[card_idx] < 4096) ?
 		    vlan[card_idx] : 0;
-		if (rx_coalesce != 0 && rx_timeout != 0) {
+		if (rx_coalesce > 0 && rx_timeout > 0) {
 			np->rx_coalesce = rx_coalesce;
 			np->rx_timeout = rx_timeout;
 			np->coalesce = 1;
 		}
-		np->tx_flow = (tx_flow[card_idx]) ? 1 : 0;
-		np->rx_flow = (rx_flow[card_idx]) ? 1 : 0;
+		np->tx_flow = (tx_flow == 0) ? 0 : 1;
+		np->rx_flow = (rx_flow == 0) ? 0 : 1;
+
 		if (tx_coalesce < 1)
 			tx_coalesce = 1;
-		if (tx_coalesce > 8)
-			tx_coalesce = 8;
+		if (tx_coalesce > TX_RING_SIZE-1)
+			tx_coalesce = TX_RING_SIZE - 1;
 	}
 	dev->open = &rio_open;
 	dev->hard_start_xmit = &start_xmit;
@@ -217,7 +222,7 @@
 	dev->get_stats = &get_stats;
 	dev->set_multicast_list = &set_multicast;
 	dev->do_ioctl = &rio_ioctl;
-	dev->tx_timeout = &tx_timeout;
+	dev->tx_timeout = &rio_tx_timeout;
 	dev->watchdog_timeo = TX_TIMEOUT;
 	dev->change_mtu = &change_mtu;
 #if 0
@@ -247,6 +252,7 @@
 	
 	/* Fiber device? */
 	np->phy_media = (readw(ioaddr + ASICCtrl) & PhyMedia) ? 1 : 0;
+	np->link_status = 0;
 	/* Set media and reset PHY */
 	if (np->phy_media) {
 		/* default 1000mbps_fd for fiber deivices */
@@ -281,6 +287,15 @@
 		dev->name, np->name,
 		dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
 		dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5], irq);
+	if (tx_coalesce > 1)
+		printk(KERN_INFO "tx_coalesce:\t%d packets\n", 
+				tx_coalesce);
+	if (np->coalesce)
+		printk(KERN_INFO "rx_coalesce:\t%d packets\n"
+		       KERN_INFO "rx_timeout: \t%d ns\n", 
+				np->rx_coalesce, np->rx_timeout*640);
+	if (np->vlan)
+		printk(KERN_INFO "vlan(id):\t%d\n", np->vlan);
 	return 0;
 
       err_out_unmap_rx:
@@ -327,7 +342,7 @@
 	return 0;
 }
 
-static int __devinit
+int
 parse_eeprom (struct net_device *dev)
 {
 	int i, j;
@@ -346,7 +361,7 @@
 	}
 
 	/* Check CRC */
- 	crc = ~ether_crc_le(256 - 4, sromdata);
+	crc = ~ether_crc_le(256 - 4, sromdata);
 	if (psrom->crc != crc) {
 		printk (KERN_ERR "%s: EEPROM data CRC error.\n", dev->name);
 		return -1;
@@ -431,8 +446,10 @@
 	writeb (0xff, ioaddr + TxDMAPollPeriod);
 	writeb (0x30, ioaddr + RxDMABurstThresh);
 	writeb (0x30, ioaddr + RxDMAUrgentThresh);
-	netif_start_queue (dev);
-	writel (StatsEnable | RxEnable | TxEnable, ioaddr + MACCtrl);
+
+	/* clear statistics */
+	clear_stats (dev);
+
 	/* VLAN supported */
 	if (np->vlan) {
 		/* priority field in RxDMAIntCtrl  */
@@ -451,15 +468,20 @@
 	/* Enable default interrupts */
 	EnableInt ();
 
-	/* clear statistics */
-	get_stats (dev);
 	init_timer (&np->timer);
 	np->timer.expires = jiffies + 1*HZ;
 	np->timer.data = (unsigned long) dev;
 	np->timer.function = &rio_timer;
 	add_timer (&np->timer);
+
+	/* Start Tx/Rx */
+	writel (readl (ioaddr + MACCtrl) | StatsEnable | RxEnable | TxEnable, 
+			ioaddr + MACCtrl);
+
+	netif_start_queue (dev);
 	return 0;
 }
+
 static void 
 rio_timer (unsigned long data)
 {
@@ -469,10 +491,10 @@
 	int next_tick = 1*HZ;
 	unsigned long flags;
 
+	spin_lock_irqsave(&np->rx_lock, flags);
 	/* Recover rx ring exhausted error */
 	if (np->cur_rx - np->old_rx >= RX_RING_SIZE) {
 		printk(KERN_INFO "Try to recover rx ring exhausted...\n");
-		spin_lock_irqsave(&np->rx_lock, flags);
 		/* Re-allocate skbuffs to fill the descriptor ring */
 		for (; np->cur_rx - np->old_rx > 0; np->old_rx++) {
 			struct sk_buff *skb;
@@ -500,43 +522,22 @@
 			    cpu_to_le64 (np->rx_buf_sz) << 48;
 			np->rx_ring[entry].status = 0;
 		} /* end for */
-		spin_unlock_irqrestore (&np->rx_lock, flags);
 	} /* end if */
+	spin_unlock_irqrestore (&np->rx_lock, flags);
 	np->timer.expires = jiffies + next_tick;
 	add_timer(&np->timer);
 }
 	
 static void
-tx_timeout (struct net_device *dev)
+rio_tx_timeout (struct net_device *dev)
 {
-	struct netdev_private *np = dev->priv;
 	long ioaddr = dev->base_addr;
 
 	printk (KERN_INFO "%s: Tx timed out (%4.4x), is buffer full?\n",
 		dev->name, readl (ioaddr + TxStatus));
-	/* Free used tx skbuffs */
-	for (; np->cur_tx - np->old_tx > 0; np->old_tx++) {
-		int entry = np->old_tx % TX_RING_SIZE;
-		struct sk_buff *skb;
-
-		if (!(np->tx_ring[entry].status & TFDDone))
-			break;
-		skb = np->tx_skbuff[entry];
-		pci_unmap_single (np->pdev,
-				  np->tx_ring[entry].fraginfo,
-				  skb->len, PCI_DMA_TODEVICE);
-		dev_kfree_skb_irq (skb);
-		np->tx_skbuff[entry] = 0;
-	}
+	rio_free_tx(dev, 0);
 	dev->if_port = 0;
 	dev->trans_start = jiffies;
-	np->stats.tx_errors++;
-	/* If the ring is no longer full, clear tx_full and 
-	   call netif_wake_queue() */
-	if (np->tx_full && np->cur_tx - np->old_tx < TX_QUEUE_LEN - 1) {
-		np->tx_full = 0;
-		netif_wake_queue (dev);
-	}
 }
 
  /* allocate and initialize Tx and Rx descriptors */
@@ -546,7 +547,6 @@
 	struct netdev_private *np = dev->priv;
 	int i;
 
-	np->tx_full = 0;
 	np->cur_rx = np->cur_tx = 0;
 	np->old_rx = np->old_tx = 0;
 	np->rx_buf_sz = (dev->mtu <= 1500 ? PACKET_SIZE : dev->mtu + 32);
@@ -605,18 +605,17 @@
 	struct netdev_desc *txdesc;
 	unsigned entry;
 	u32 ioaddr;
-	int tx_shift;
-	unsigned long flags;
+	u64 tfc_vlan_tag = 0;
 
+	if (np->link_status == 0) {	/* Link Down */
+		dev_kfree_skb(skb);
+		return 0;
+	}
 	ioaddr = dev->base_addr;
 	entry = np->cur_tx % TX_RING_SIZE;
 	np->tx_skbuff[entry] = skb;
 	txdesc = &np->tx_ring[entry];
 
-	/* Set TFDDone to avoid TxDMA gather this descriptor */
-	txdesc->status = cpu_to_le64 (TFDDone);
-	txdesc->status |=
-	    cpu_to_le64 (entry | WordAlignDisable | (1 << FragCountShift));
 #if 0
 	if (skb->ip_summed == CHECKSUM_HW) {
 		txdesc->status |=
@@ -630,31 +629,33 @@
 		    (cpu_to_le64 (np->vlan) << 32) |
 		    (cpu_to_le64 (skb->priority) << 45);
 	}
-
-	/* Send one packet each time at 10Mbps mode */
-	/* Tx coalescing loop do not exceed 8 */
-	if (entry % tx_coalesce == 0 || np->speed == 10)
-		txdesc->status |= cpu_to_le64 (TxIndicate);
 	txdesc->fraginfo = cpu_to_le64 (pci_map_single (np->pdev, skb->data,
 							skb->len,
 							PCI_DMA_TODEVICE));
 	txdesc->fraginfo |= cpu_to_le64 (skb->len) << 48;
 
-	/* Clear TFDDone, then TxDMA start to send this descriptor */
-	txdesc->status &= ~cpu_to_le64 (TFDDone);
-
-	DEBUG_TFD_DUMP (np);
+	/* DL2K bug: DMA fails to get next descriptor ptr in 10Mbps mode
+	 * Work around: Always use 1 descriptor in 10Mbps mode */
+	if (entry % tx_coalesce == 0 || np->speed == 10)
+		txdesc->status = cpu_to_le64 (entry | tfc_vlan_tag |
+					      WordAlignDisable | 
+					      TxDMAIndicate |
+					      (1 << FragCountShift));
+	else
+		txdesc->status = cpu_to_le64 (entry | tfc_vlan_tag |
+					      WordAlignDisable | 
+					      (1 << FragCountShift));
 
 	/* TxDMAPollNow */
 	writel (readl (ioaddr + DMACtrl) | 0x00001000, ioaddr + DMACtrl);
-	np->cur_tx++;
-	if (np->cur_tx - np->old_tx < TX_QUEUE_LEN - 1 && np->speed != 10) {
+	/* Schedule ISR */
+	writel(10000, ioaddr + CountDown);
+	np->cur_tx = (np->cur_tx + 1) % TX_RING_SIZE;
+	if ((np->cur_tx - np->old_tx + TX_RING_SIZE) % TX_RING_SIZE
+			< TX_QUEUE_LEN - 1 && np->speed != 10) {
 		/* do nothing */
-	} else {
-		spin_lock_irqsave(&np->lock, flags);
-		np->tx_full = 1;
+	} else if (!netif_queue_stopped(dev)) {
 		netif_stop_queue (dev);
-		spin_unlock_irqrestore (&np->lock, flags);
 	}
 
 	/* The first TFDListPtr */
@@ -664,14 +665,6 @@
 		writel (0, dev->base_addr + TFDListPtr1);
 	}
 	
-	if (np->old_tx > TX_RING_SIZE) {
-		spin_lock_irqsave (&np->lock, flags);
-		tx_shift = TX_RING_SIZE;
-		np->old_tx -= tx_shift;
-		np->cur_tx -= tx_shift;
-		spin_unlock_irqrestore (&np->lock, flags);
-	}
-	
 	/* NETDEV WATCHDOG timer */
 	dev->trans_start = jiffies;
 	return 0;
@@ -688,61 +681,79 @@
 
 	ioaddr = dev->base_addr;
 	np = dev->priv;
-	spin_lock(&np->lock);
 	while (1) {
 		int_status = readw (ioaddr + IntStatus); 
 		writew (int_status, ioaddr + IntStatus);
 		int_status &= DEFAULT_INTR;
-		if (int_status == 0)
+		if (int_status == 0 || --cnt < 0)
 			break;
 		/* Processing received packets */
 		if (int_status & RxDMAComplete)
 			receive_packet (dev);
-		/* TxComplete interrupt */
-		if ((int_status & TxComplete) || np->tx_full) {
+		/* TxDMAComplete interrupt */
+		if ((int_status & (TxDMAComplete|IntRequested))) {
 			int tx_status;
 			tx_status = readl (ioaddr + TxStatus);
 			if (tx_status & 0x01)
 				tx_error (dev, tx_status);
 			/* Free used tx skbuffs */
-			for (;np->cur_tx - np->old_tx > 0; np->old_tx++) {
-				int entry = np->old_tx % TX_RING_SIZE;
-				struct sk_buff *skb;
-
-				if (!(np->tx_ring[entry].status & TFDDone))
-					break;
-				skb = np->tx_skbuff[entry];
-				pci_unmap_single (np->pdev,
-						  np->tx_ring[entry].fraginfo,
-						  skb->len, PCI_DMA_TODEVICE);
-				dev_kfree_skb_irq (skb);
-				np->tx_skbuff[entry] = 0;
-			}
-		}
-		/* If the ring is no longer full, clear tx_full and 
-		   call netif_wake_queue() */
-		if (np->tx_full && np->cur_tx - np->old_tx < TX_QUEUE_LEN - 1) {
-			if (np->speed != 10 || int_status & TxComplete) {
-				np->tx_full = 0;
-				netif_wake_queue (dev);
-			}
+			rio_free_tx (dev, 1);		
 		}
 
 		/* Handle uncommon events */
 		if (int_status &
-		    (IntRequested | HostError | LinkEvent | UpdateStats))
+		    (HostError | LinkEvent | UpdateStats))
 			rio_error (dev, int_status);
-		/* If too much interrupts here, disable all interrupts except 
-		   IntRequest. When CountDown down to 0, IntRequest will 
-		   be caught by rio_error() to recovery the interrupts */
-		if (--cnt < 0) {
-			get_stats (dev);
-			writel (1, ioaddr + CountDown);
-			writew (IntRequested, ioaddr + IntEnable);
+	}
+	if (np->cur_tx != np->old_tx)
+		writel (100, ioaddr + CountDown);
+}
+
+static void 
+rio_free_tx (struct net_device *dev, int irq) 
+{
+	struct netdev_private *np = (struct netdev_private *) dev->priv;
+	int entry = np->old_tx % TX_RING_SIZE;
+	int tx_use = 0;
+	long flag = 0;
+	
+	if (irq)
+		spin_lock_irqsave(&np->tx_lock, flag);
+	else
+		spin_lock(&np->tx_lock);
+	/* Free used tx skbuffs */
+	while (entry != np->cur_tx) {
+		struct sk_buff *skb;
+
+		if (!(np->tx_ring[entry].status & TFDDone))
 			break;
-		}
+		skb = np->tx_skbuff[entry];
+		pci_unmap_single (np->pdev,
+				  np->tx_ring[entry].fraginfo,
+				  skb->len, PCI_DMA_TODEVICE);
+		if (irq)
+			dev_kfree_skb_irq (skb);
+		else
+			dev_kfree_skb (skb);
+
+		np->tx_skbuff[entry] = 0;
+		entry = (entry + 1) % TX_RING_SIZE;
+		tx_use++;
+	}
+	if (irq)
+		spin_unlock_irqrestore(&np->tx_lock, flag);
+	else
+		spin_unlock(&np->tx_lock);
+	np->old_tx = entry;
+
+	/* If the ring is no longer full, clear tx_full and 
+	   call netif_wake_queue() */
+
+	if (netif_queue_stopped(dev) &&
+	    ((np->cur_tx - np->old_tx + TX_RING_SIZE) % TX_RING_SIZE 
+	    < TX_QUEUE_LEN - 1 || np->speed == 10)) {
+		netif_wake_queue (dev);
 	}
-	spin_unlock(&np->lock);
 }
 
 static void
@@ -755,11 +766,10 @@
 
 	np = dev->priv;
 
-	frame_id = (tx_status & 0xffff0000) >> 16;
+	frame_id = (tx_status & 0xffff0000);
 	printk (KERN_ERR "%s: Transmit error, TxStatus %4.4x, FrameId %d.\n",
 		dev->name, tx_status, frame_id);
 	np->stats.tx_errors++;
-	np->stats.tx_dropped++;
 	/* Ttransmit Underrun */
 	if (tx_status & 0x10) {
 		np->stats.tx_fifo_errors++;
@@ -774,20 +784,7 @@
 				break;
 			mdelay (1);
 		}
-		/* Free completed descriptors */
-		for (; np->cur_tx - np->old_tx > 0; np->old_tx++) {
-			int entry = np->old_tx % TX_RING_SIZE;
-			struct sk_buff *skb;
-			if (!(np->tx_ring[entry].status & TFDDone))
-				break;
-
-			skb = np->tx_skbuff[entry];
-			pci_unmap_single (np->pdev, np->tx_ring[entry].fraginfo,
-					  skb->len, PCI_DMA_TODEVICE);
-			dev_kfree_skb_irq (skb);
-			np->tx_skbuff[entry] = 0;
-		}
-
+		rio_free_tx (dev, 1);
 		/* Reset TFDListPtr */
 		writel (np->tx_ring_dma +
 			np->old_tx * sizeof (struct netdev_desc),
@@ -810,14 +807,13 @@
 		/* Let TxStartThresh stay default value */
 	}
 	/* Maximum Collisions */
-#ifdef ETHER_STATS
-	if (tx_status & 0x08)
+#ifdef ETHER_STATS	
+	if (tx_status & 0x08) 
 		np->stats.collisions16++;
 #else
-	if (tx_status & 0x08)
+	if (tx_status & 0x08) 
 		np->stats.collisions++;
 #endif
-
 	/* Restart the Tx */
 	writel (readw (dev->base_addr + MACCtrl) | TxEnable, ioaddr + MACCtrl);
 }
@@ -827,16 +823,8 @@
 {
 	struct netdev_private *np = (struct netdev_private *) dev->priv;
 	int entry = np->cur_rx % RX_RING_SIZE;
-	int cnt = np->old_rx + RX_RING_SIZE - np->cur_rx;
-	int rx_shift;
+	int cnt = 30;
 
-	spin_lock (&np->rx_lock);
-	if (np->old_rx > RX_RING_SIZE) {
-		rx_shift = RX_RING_SIZE;
-		np->old_rx -= rx_shift;
-		np->cur_rx -= rx_shift;
-	}
-	DEBUG_RFD_DUMP (np, 1);
 	/* If RFDDone, FrameStart and FrameEnd set, there is a new packet in. */
 	while (1) {
 		struct netdev_desc *desc = &np->rx_ring[entry];
@@ -852,20 +840,19 @@
 		frame_status = le64_to_cpu (desc->status);
 		if (--cnt < 0)
 			break;
-		DEBUG_PKT_DUMP (np, pkt_len);
 		pci_dma_sync_single (np->pdev, desc->fraginfo, np->rx_buf_sz,
 				     PCI_DMA_FROMDEVICE);
 		/* Update rx error statistics, drop packet. */
-		if (frame_status & 0x003f0000) {
+		if (frame_status & RFS_Errors) {
 			np->stats.rx_errors++;
-			if (frame_status & 0x00300000)
+			if (frame_status & (RxRuntFrame | RxLengthError))
 				np->stats.rx_length_errors++;
-			if (frame_status & 0x00010000)
-	 			np->stats.rx_fifo_errors++;
-			if (frame_status & 0x00060000)
-				np->stats.rx_frame_errors++;
-			if (frame_status & 0x00080000)
+			if (frame_status & RxFCSError)
 				np->stats.rx_crc_errors++;
+			if (frame_status & RxAlignmentError && np->speed != 1000)
+				np->stats.rx_frame_errors++;
+			if (frame_status & RxFIFOOverrun)
+	 			np->stats.rx_fifo_errors++;
 		} else {
 			struct sk_buff *skb;
 
@@ -893,17 +880,17 @@
 				skb->ip_summed = CHECKSUM_UNNECESSARY;
 			} 
 #endif
-					
 			netif_rx (skb);
 			dev->last_rx = jiffies;
 		}
-		entry = (++np->cur_rx) % RX_RING_SIZE;
-
+		entry = (entry + 1) % RX_RING_SIZE;
 	}
+	spin_lock(&np->rx_lock);
+	np->cur_rx = entry;
 	/* Re-allocate skbuffs to fill the descriptor ring */
-	for (; np->cur_rx - np->old_rx > 0; np->old_rx++) {
+	entry = np->old_rx;
+	while (entry != np->cur_rx) {
 		struct sk_buff *skb;
-		entry = np->old_rx % RX_RING_SIZE;
 		/* Dropped packets don't need to re-allocate */
 		if (np->rx_skbuff[entry] == NULL) {
 			skb = dev_alloc_skb (np->rx_buf_sz);
@@ -927,11 +914,9 @@
 		np->rx_ring[entry].fraginfo |=
 		    cpu_to_le64 (np->rx_buf_sz) << 48;
 		np->rx_ring[entry].status = 0;
-		/* RxDMAPollNow */
-		writel (readl (dev->base_addr + DMACtrl) | 0x00000010,
-			dev->base_addr + DMACtrl);
+		entry = (entry + 1) % RX_RING_SIZE;
 	}
-	DEBUG_RFD_DUMP (np, 2);
+	np->old_rx = entry;
 	spin_unlock(&np->rx_lock);
 	return 0;
 }
@@ -943,14 +928,6 @@
 	struct netdev_private *np = dev->priv;
 	u16 macctrl;
 
-	/* Stop the down counter and recovery the interrupt */
-	if (int_status & IntRequested) {
-		writew (0, ioaddr + IntEnable);
-		writel (0, ioaddr + CountDown);
-		/* Enable default interrupts */
-		EnableInt ();
-	}
-
 	/* Link change event */
 	if (int_status & LinkEvent) {
 		if (mii_wait_link (dev, 10) == 0) {
@@ -960,14 +937,19 @@
 			else
 				mii_get_media (dev);
 			macctrl = 0;
+			macctrl |= (np->vlan) ? AutoVLANuntagging : 0;
 			macctrl |= (np->full_duplex) ? DuplexSelect : 0;
 			macctrl |= (np->tx_flow) ? 
 				TxFlowControlEnable : 0;
 			macctrl |= (np->rx_flow) ? 
 				RxFlowControlEnable : 0;
 			writew(macctrl,	ioaddr + MACCtrl);
+			np->link_status = 1;
+			netif_carrier_on(dev);
 		} else {
 			printk (KERN_INFO "%s: Link off\n", dev->name);
+			np->link_status = 0;
+			netif_carrier_off(dev);
 		}
 	}
 
@@ -991,41 +973,100 @@
 {
 	long ioaddr = dev->base_addr;
 	struct netdev_private *np = dev->priv;
-	u16 temp1;
-	u16 temp2;
 	int i;
+	unsigned int stat_reg;
+
 	/* All statistics registers need to be acknowledged,
 	   else statistic overflow could cause problems */
+	
 	np->stats.rx_packets += readl (ioaddr + FramesRcvOk);
 	np->stats.tx_packets += readl (ioaddr + FramesXmtOk);
 	np->stats.rx_bytes += readl (ioaddr + OctetRcvOk);
 	np->stats.tx_bytes += readl (ioaddr + OctetXmtOk);
-	temp1 = readw (ioaddr + FrameLostRxError);
-	np->stats.rx_errors += temp1;
-	np->stats.rx_missed_errors += temp1;
-	np->stats.tx_dropped += readw (ioaddr + FramesAbortXSColls);
-	temp1 = readl (ioaddr + SingleColFrames) +
-	    readl (ioaddr + MultiColFrames) + readl (ioaddr + LateCollisions);
-	temp2 = readw (ioaddr + CarrierSenseErrors);
-	np->stats.tx_carrier_errors += temp2;
-	np->stats.tx_errors += readw (ioaddr + FramesWEXDeferal) +
-	    readl (ioaddr + FramesWDeferredXmt) + temp2;
-
-	/* detailed rx_error */
-	np->stats.rx_length_errors += readw (ioaddr + FrameTooLongErrors);
-	np->stats.rx_crc_errors += readw (ioaddr + FrameCheckSeqError);
+
+	np->stats.multicast = readl (ioaddr + McstFramesRcvdOk);
+	np->stats.collisions += readl (ioaddr + SingleColFrames) 
+			     +  readl (ioaddr + MultiColFrames); 
+	
+	/* detailed tx errors */
+	stat_reg = readw (ioaddr + FramesAbortXSColls);
+	np->stats.tx_aborted_errors += stat_reg;
+	np->stats.tx_errors += stat_reg;
+
+	stat_reg = readw (ioaddr + CarrierSenseErrors);
+	np->stats.tx_carrier_errors += stat_reg;
+	np->stats.tx_errors += stat_reg;
 
 	/* Clear all other statistic register. */
-	readw (ioaddr + InRangeLengthErrors);
-	readw (ioaddr + MacControlFramesXmtd);
+	readl (ioaddr + McstOctetXmtOk);
 	readw (ioaddr + BcstFramesXmtdOk);
 	readl (ioaddr + McstFramesXmtdOk);
+	readw (ioaddr + BcstFramesRcvdOk);
+	readw (ioaddr + MacControlFramesRcvd);
+	readw (ioaddr + FrameTooLongErrors);
+	readw (ioaddr + InRangeLengthErrors);
+	readw (ioaddr + FramesCheckSeqErrors);
+	readw (ioaddr + FramesLostRxErrors);
+	readl (ioaddr + McstOctetXmtOk);
 	readl (ioaddr + BcstOctetXmtOk);
+	readl (ioaddr + McstFramesXmtdOk);
+	readl (ioaddr + FramesWDeferredXmt);
+	readl (ioaddr + LateCollisions);
+	readw (ioaddr + BcstFramesXmtdOk);
+	readw (ioaddr + MacControlFramesXmtd);
+	readw (ioaddr + FramesWEXDeferal);
+
+
+	for (i = 0x100; i <= 0x150; i += 4)
+		readl (ioaddr + i);
+	readw (ioaddr + TxJumboFrames);
+	readw (ioaddr + RxJumboFrames);
+	readw (ioaddr + TCPCheckSumErrors);
+	readw (ioaddr + UDPCheckSumErrors);
+	readw (ioaddr + IPCheckSumErrors);
+	return &np->stats;
+}
+
+static int
+clear_stats (struct net_device *dev)
+{
+	long ioaddr = dev->base_addr;
+	int i;
+
+	/* All statistics registers need to be acknowledged,
+	   else statistic overflow could cause problems */
+	readl (ioaddr + FramesRcvOk);
+	readl (ioaddr + FramesXmtOk);
+	readl (ioaddr + OctetRcvOk);
+	readl (ioaddr + OctetXmtOk);
+
+	readl (ioaddr + McstFramesRcvdOk);
+	readl (ioaddr + SingleColFrames);
+	readl (ioaddr + MultiColFrames);
+	readl (ioaddr + LateCollisions);
+	/* detailed rx errors */		
+	readw (ioaddr + FrameTooLongErrors);
+	readw (ioaddr + InRangeLengthErrors);
+	readw (ioaddr + FramesCheckSeqErrors);
+	readw (ioaddr + FramesLostRxErrors);
+
+	/* detailed tx errors */
+	readw (ioaddr + FramesAbortXSColls);
+	readw (ioaddr + CarrierSenseErrors);
+
+	/* Clear all other statistic register. */
 	readl (ioaddr + McstOctetXmtOk);
+	readw (ioaddr + BcstFramesXmtdOk);
+	readl (ioaddr + McstFramesXmtdOk);
+	readw (ioaddr + BcstFramesRcvdOk);
 	readw (ioaddr + MacControlFramesRcvd);
-	readw (ioaddr + BcstFramesRcvOk);
-	readl (ioaddr + McstFramesRcvOk);
-	readl (ioaddr + BcstOctetRcvOk);
+	readl (ioaddr + McstOctetXmtOk);
+	readl (ioaddr + BcstOctetXmtOk);
+	readl (ioaddr + McstFramesXmtdOk);
+	readl (ioaddr + FramesWDeferredXmt);
+	readw (ioaddr + BcstFramesXmtdOk);
+	readw (ioaddr + MacControlFramesXmtd);
+	readw (ioaddr + FramesWEXDeferal);
 
 	for (i = 0x100; i <= 0x150; i += 4)
 		readl (ioaddr + i);
@@ -1034,9 +1075,10 @@
 	readw (ioaddr + TCPCheckSumErrors);
 	readw (ioaddr + UDPCheckSumErrors);
 	readw (ioaddr + IPCheckSumErrors);
-	return &np->stats;
+	return 0;
 }
 
+
 int
 change_mtu (struct net_device *dev, int new_mtu)
 {
@@ -1111,51 +1153,35 @@
 	int phy_addr;
 	struct netdev_private *np = dev->priv;
 	struct mii_data *miidata = (struct mii_data *) &rq->ifr_data;
-#ifdef RIO_DEBUG
-	struct ioctl_data *iodata = (struct ioctl_data *) (rq->ifr_data);
-#endif
-	u16 *data = (u16 *) & rq->ifr_data;
+	
 	struct netdev_desc *desc;
 	int i;
 
 	phy_addr = np->phy_addr;
 	switch (cmd) {
 	case SIOCDEVPRIVATE:
-#ifdef RIO_DEBUG
-		if (rio_ioctl_ext (dev, iodata) != 0)
-			return -EOPNOTSUPP;
 		break;
-#else
-		return -EOPNOTSUPP;
-#endif
+	
 	case SIOCDEVPRIVATE + 1:
 		miidata->out_value = mii_read (dev, phy_addr, miidata->reg_num);
 		break;
 	case SIOCDEVPRIVATE + 2:
-		if (!capable(CAP_NET_ADMIN))
-			return -EPERM;
 		mii_write (dev, phy_addr, miidata->reg_num, miidata->in_value);
 		break;
 	case SIOCDEVPRIVATE + 3:
-		np->rx_debug = (data[0] <= 7) ? data[0] : 0;
-		printk ("rx_debug = %d\n", np->rx_debug);
 		break;
 	case SIOCDEVPRIVATE + 4:
-		np->tx_debug = (data[0] <= 7) ? data[0] : 0;
-		printk ("tx_debug = %d\n", np->tx_debug);
 		break;
 	case SIOCDEVPRIVATE + 5:
-		np->tx_full = 1;
 		netif_stop_queue (dev);
 		break;
 	case SIOCDEVPRIVATE + 6:
-		np->tx_full = 0;
 		netif_wake_queue (dev);
 		break;
 	case SIOCDEVPRIVATE + 7:
 		printk
 		    ("tx_full=%x cur_tx=%lx old_tx=%lx cur_rx=%lx old_rx=%lx\n",
-		     np->tx_full, np->cur_tx, np->old_tx, np->cur_rx,
+		     netif_queue_stopped(dev), np->cur_tx, np->old_tx, np->cur_rx,
 		     np->old_rx);
 		break;
 	case SIOCDEVPRIVATE + 8:
@@ -1163,7 +1189,8 @@
 		for (i = 0; i < TX_RING_SIZE; i++) {
 			desc = &np->tx_ring[i];
 			printk
-			    ("cur:%08x next:%08x status:%08x frag1:%08x frag0:%08x",
+			    ("%02x:cur:%08x next:%08x status:%08x frag1:%08x frag0:%08x",
+			     i,
 			     (u32) (np->tx_ring_dma + i * sizeof (*desc)),
 			     (u32) desc->next_desc,
 			     (u32) desc->status, (u32) (desc->fraginfo >> 32),
@@ -1172,110 +1199,17 @@
 		}
 		printk ("\n");
 		break;
-	default:
-		return -EOPNOTSUPP;
-	}
-	return 0;
-}
-
-#ifdef RIO_DEBUG
-int
-rio_ioctl_ext (struct net_device *dev, struct ioctl_data *iodata)
-{
-	struct netdev_private *np = dev->priv;
-	int phy_addr = np->phy_addr;
-	u32 hi, lo;
-	int i;
-	BMCR_t bmcr;
-	BMSR_t bmsr;
-
-	if (iodata == NULL)
-		goto invalid_cmd;
-	if (strcmp (iodata->signature, "rio") != 0)
-		goto invalid_cmd;
-
-	switch (iodata->cmd) {
-	case 0:
-		for (i = 0; i < TX_RING_SIZE; i++) {
-			hi = np->tx_ring[i].status >> 32;
-			lo = np->tx_ring[i].status;
-			printk ("TFC=%08x %08x \n", hi, lo);
-
-		}
-		break;
-	case 1:
-		for (i = 0; i < RX_RING_SIZE; i++) {
-			hi = np->rx_ring[i].status >> 32;
-			lo = np->rx_ring[i].status;
-			printk ("RFS=%08x %08x \n", hi, lo);
-		}
-		break;
-	case 2:
-		break;
-	case 3:
-		if (iodata->data != NULL)
-			np->tx_debug = iodata->data[0];
-		break;
-	case 4:
-		/* Soft reset PHY */
-		mii_write (dev, phy_addr, MII_BMCR, MII_BMCR_RESET);
-		bmcr.image = 0;
-		bmcr.bits.an_enable = 1;
-		bmcr.bits.reset = 1;
-		mii_write (dev, phy_addr, MII_BMCR, bmcr.image);
-		break;
-	case 5:
-		mii_write (dev, phy_addr, MII_BMCR, 0x1940);
-		mdelay (10);
-		mii_write (dev, phy_addr, MII_BMCR, 0x1940);
-		mdelay (100);	/* wait a certain time */
-		break;
-	case 6:
-		/* 5) Set media and Power Up */
-		bmcr.image = 0;
-		bmcr.bits.power_down = 1;
-		if (np->an_enable) {
-			bmcr.bits.an_enable = 1;
-		} else {
-			if (np->speed == 100) {
-				bmcr.bits.speed100 = 1;
-				bmcr.bits.speed1000 = 0;
-				printk ("Manual 100 Mbps, ");
-			} else if (np->speed == 10) {
-				bmcr.bits.speed100 = 0;
-				bmcr.bits.speed1000 = 0;
-				printk ("Manual 10 Mbps, ");
-			}
-			if (np->full_duplex) {
-				bmcr.bits.duplex_mode = 1;
-				printk ("Full duplex. \n");
-			} else {
-				bmcr.bits.duplex_mode = 0;
-				printk ("Half duplex.\n");
-			}
-		}
-		mii_write (dev, phy_addr, MII_BMCR, bmcr.image);
-		break;
-	case 7:
-		bmcr.image = mii_read (dev, phy_addr, MII_BMCR);
-		bmsr.image = mii_read (dev, phy_addr, MII_BMSR);
-		printk ("BMCR=%x BMSR=%x LinkUp=%d\n",
-			bmcr.image, bmsr.image, bmsr.bits.link_status);
-		break;
 
 	default:
 		return -EOPNOTSUPP;
 	}
 	return 0;
-
-      invalid_cmd:
-	return -1;
 }
-#endif
+
 #define EEP_READ 0x0200
 #define EEP_BUSY 0x8000
 /* Read the EEPROM word */
-static int __devinit
+int
 read_eeprom (long ioaddr, int eep_addr)
 {
 	int i = 1000;
@@ -1441,10 +1375,11 @@
 			printk (KERN_INFO "Auto 10 Mbps, Half duplex\n");
 		}
 		if (negotiate.bits.pause) {
-			np->tx_flow = 1;
-			np->rx_flow = 1;
+			np->tx_flow &= 1;
+			np->rx_flow &= 1;
 		} else if (negotiate.bits.asymmetric) {
-			np->rx_flow = 1;
+			np->tx_flow = 0;
+			np->rx_flow &= 1;
 		}
 		/* else tx_flow, rx_flow = user select  */
 	} else {
@@ -1593,10 +1528,11 @@
 			np->full_duplex = 0;
 		}
 		if (negotiate.bits.pause) {
-			np->tx_flow = 1;
-			np->rx_flow = 1;
+			np->tx_flow &= 1;
+			np->rx_flow &= 1;
 		} else if (negotiate.bits.asymmetric) {
-			np->rx_flow = 1;
+			np->tx_flow = 0;
+			np->rx_flow &= 1;
 		}
 		/* else tx_flow, rx_flow = user select  */
 	} else {
diff -urN linux-2.4.19-pre9/drivers/net/dl2k.h linux-2.4.19-pre10/drivers/net/dl2k.h
--- linux-2.4.19-pre9/drivers/net/dl2k.h	Mon Jun  3 18:50:48 2002
+++ linux-2.4.19-pre10/drivers/net/dl2k.h	Mon Jun  3 18:50:54 2002
@@ -119,13 +119,13 @@
 	McstOctetRcvOk = 0xac,
 	BcstOctetRcvOk = 0xb0,
 	FramesRcvOk = 0xb4,
-	McstFramesRcvOk = 0xb8,
-	BcstFramesRcvOk = 0xbe,
+	McstFramesRcvdOk = 0xb8,
+	BcstFramesRcvdOk = 0xbe,
 	MacControlFramesRcvd = 0xc6,
 	FrameTooLongErrors = 0xc8,
 	InRangeLengthErrors = 0xca,
-	FrameCheckSeqError = 0xcc,
-	FrameLostRxError = 0xce,
+	FramesCheckSeqErrors = 0xcc,
+	FramesLostRxErrors = 0xce,
 	OctetXmtOk = 0xd0,
 	McstOctetXmtOk = 0xd4,
 	BcstOctetXmtOk = 0xd8,
@@ -264,6 +264,7 @@
 	FrameEnd = 0x40000000,
 	RFDDone = 0x80000000,
 	TCIShift = 32,
+	RFS_Errors = 0x003f0000,
 };
 
 #define MII_RESET_TIME_OUT		10000
@@ -648,7 +649,7 @@
 	dma_addr_t tx_ring_dma;
 	dma_addr_t rx_ring_dma;
 	struct pci_dev *pdev;
-	spinlock_t lock;
+	spinlock_t tx_lock;
 	spinlock_t rx_lock;
 	struct net_device_stats stats;
 	unsigned int rx_buf_sz;		/* Based on MTU+slack. */
@@ -657,7 +658,6 @@
 	unsigned int chip_id;		/* PCI table chip id */
 	unsigned int rx_coalesce; 	/* Maximum frames each RxDMAComplete intr */
 	unsigned int rx_timeout; 	/* Wait time between RxDMAComplete intr */
-	unsigned int tx_full:1;		/* The Tx queue is full. */
 	unsigned int full_duplex:1;	/* Full-duplex operation requested. */
 	unsigned int an_enable:2;	/* Auto-Negotiated Enable */
 	unsigned int jumbo:1;		/* Jumbo frame enable */
@@ -665,6 +665,7 @@
 	unsigned int tx_flow:1;		/* Tx flow control enable */
 	unsigned int rx_flow:1;		/* Rx flow control enable */
 	unsigned int phy_media:1;	/* 1: fiber, 0: copper */
+	unsigned int link_status:1;	/* Current link status */
 	unsigned char pci_rev_id;	/* PCI revision ID */
 	struct netdev_desc *last_tx;	/* Last Tx descriptor used. */
 	unsigned long cur_rx, old_rx;	/* Producer/consumer ring indices */
@@ -677,8 +678,6 @@
 	u16 advertising;	/* NWay media advertisement */
 	u16 negotiate;		/* Negotiated media */
 	int phy_addr;		/* PHY addresses. */
-	int tx_debug;
-	int rx_debug;
 };
 
 /* The station address location in the EEPROM. */
@@ -707,113 +706,4 @@
 #define DEFAULT_RXT		750
 #define DEFAULT_TXC		1
 #define MAX_TXC			8
-#ifdef RIO_DEBUG
-#define DEBUG_TFD_DUMP(x) debug_tfd_dump(x)
-#define DEBUG_RFD_DUMP(x,flag) debug_rfd_dump(x,flag)
-#define DEBUG_PKT_DUMP(x,len) debug_pkt_dump(x,len)
-#define DEBUG_PRINT printk
-
-static inline void
-debug_tfd_dump (struct netdev_private *np)
-{
-	int i;
-	struct netdev_desc *desc;
-
-	if (np->tx_debug == 6) {
-		printk ("TFDone Dump: ");
-		for (i = 0; i < TX_RING_SIZE; i++) {
-			desc = &np->tx_ring[i];
-			if ((desc->fraginfo & 0xffffffffff) == 0)
-				printk ("X");
-			else
-				printk ("%d", (desc->status & TFDDone) ? 1 : 0);
-		}
-		printk ("\n");
-	}
-	if (np->tx_debug == 5) {
-		for (i = 0; i < TX_RING_SIZE; i++) {
-			desc = &np->tx_ring[i];
-			printk
-			    ("cur:%08x next:%08x status:%08x frag1:%08x frag0:%08x",
-			     (u32) np->tx_ring_dma + i * sizeof (*desc),
-			     (u32) desc->next_desc, (u32) desc->status,
-			     (u32) (desc->fraginfo >> 32),
-			     (u32) desc->fraginfo);
-			printk ("\n");
-		}
-		printk ("\n");
-	}
-}
-static inline void
-debug_rfd_dump (struct netdev_private *np, int flag)
-{
-	int i;
-	struct netdev_desc *desc;
-	int entry = np->cur_rx % RX_RING_SIZE;
-
-	if (np->rx_debug == 5) {
-		for (i = 0; i < RX_RING_SIZE; i++) {
-			desc = &np->rx_ring[i];
-			printk
-			    ("cur:%08x next:%08x status:%08x frag1:%08x frag0:%08x",
-			     (u32) np->rx_ring_dma + i * sizeof (*desc),
-			     (u32) desc->next_desc, (u32) desc->status,
-			     (u32) (desc->fraginfo >> 32),
-			     (u32) desc->fraginfo);
-			printk ("\n");
-		}
-		printk ("\n");
-	}
-
-	if (np->rx_debug == 6) {
-		if (flag == 1)
-			printk ("RFDone Dump: ");
-		else if (flag == 2)
-			printk ("Re-Filling:  ");
-		for (i = 0; i < RX_RING_SIZE; i++) {
-			desc = &np->rx_ring[i];
-			printk ("%d", (desc->status & RFDDone) ? 1 : 0);
-		}
-		printk ("\n");
-	}
-	if (np->rx_debug == 7) {
-		printk (" In rcv_pkt(), entry %d status %4.4x %4.4x.\n",
-			entry, (u32) (np->rx_ring[entry].status >> 32),
-			(u32) np->rx_ring[entry].status);
-	}
-
-}
-
-static inline void
-debug_pkt_dump (struct netdev_private *np, int pkt_len)
-{
-	int entry = np->cur_rx % RX_RING_SIZE;
-	struct netdev_desc *desc = &np->rx_ring[entry];
-	u64 frame_status = le64_to_cpu (desc->status);
-	unsigned char *pchar;
-	unsigned char *phead;
-	int i;
-
-	if (np->rx_debug == 4) {
-		printk ("  rcv_pkt: status was %4.4x %4.4x.\n",
-			(u32) (frame_status >> 32), (u32) frame_status);
-	}
-	if (np->rx_debug == 7) {
-
-		phead =
-		    bus_to_virt (le64_to_cpu (desc->fraginfo & 0xffffffffff));
-		for (pchar = phead, i = 0; i < pkt_len; i++, pchar++) {
-			printk ("%02x ", *pchar);
-			if ((i + 1) % 20 == 0)
-				printk ("\n");
-		}
-	}
-}
-#else
-#define DEBUG_TFD_DUMP(x) {}
-#define DEBUG_RFD_DUMP(x,flag) {}
-#define DEBUG_PKT_DUMP(x,len) {}
-#define DEBUG_PRINT() {}
-#endif
-
 #endif				/* __DL2K_H__ */
diff -urN linux-2.4.19-pre9/drivers/net/eepro100.c linux-2.4.19-pre10/drivers/net/eepro100.c
--- linux-2.4.19-pre9/drivers/net/eepro100.c	Mon Jun  3 18:50:48 2002
+++ linux-2.4.19-pre10/drivers/net/eepro100.c	Mon Jun  3 18:50:54 2002
@@ -524,10 +524,8 @@
 static int eepro100_init_one(struct pci_dev *pdev,
 		const struct pci_device_id *ent);
 static void eepro100_remove_one (struct pci_dev *pdev);
-#ifdef CONFIG_PM
 static int eepro100_suspend (struct pci_dev *pdev, u32 state);
 static int eepro100_resume (struct pci_dev *pdev);
-#endif
 
 static int do_eeprom_cmd(long ioaddr, int cmd, int cmd_len);
 static int mdio_read(long ioaddr, int phy_id, int location);
diff -urN linux-2.4.19-pre9/drivers/net/fc/iph5526.c linux-2.4.19-pre10/drivers/net/fc/iph5526.c
--- linux-2.4.19-pre9/drivers/net/fc/iph5526.c	Mon Jun  3 18:50:48 2002
+++ linux-2.4.19-pre10/drivers/net/fc/iph5526.c	Mon Jun  3 18:50:54 2002
@@ -2984,8 +2984,7 @@
 	 */
 	if ((type == ETH_P_ARP) || (status == 0))
 		dev_kfree_skb(skb);
-	else
-		netif_wake_queue(dev);
+	netif_wake_queue(dev);
 	LEAVE("iph5526_send_packet");
 	return 0;
 }
diff -urN linux-2.4.19-pre9/drivers/net/mii.c linux-2.4.19-pre10/drivers/net/mii.c
--- linux-2.4.19-pre9/drivers/net/mii.c	Mon Feb 25 11:37:59 2002
+++ linux-2.4.19-pre10/drivers/net/mii.c	Mon Jun  3 18:50:55 2002
@@ -146,6 +146,8 @@
 
 int mii_link_ok (struct mii_if_info *mii)
 {
+	/* first, a dummy read, needed to latch some MII phys */
+	mii->mdio_read(mii->dev, mii->phy_id, MII_BMSR);
 	if (mii->mdio_read(mii->dev, mii->phy_id, MII_BMSR) & BMSR_LSTATUS)
 		return 1;
 	return 0;
diff -urN linux-2.4.19-pre9/drivers/net/pcnet32.c linux-2.4.19-pre10/drivers/net/pcnet32.c
--- linux-2.4.19-pre9/drivers/net/pcnet32.c	Mon Jun  3 18:50:48 2002
+++ linux-2.4.19-pre10/drivers/net/pcnet32.c	Mon Jun  3 18:50:55 2002
@@ -511,7 +511,6 @@
 		struct pci_dev *pdev)
 {
     struct pcnet32_private *lp;
-    struct resource *res;
     dma_addr_t lp_dma_addr;
     int i, media;
     int fdx, mii, fset, dxsuflo, ltint;
@@ -689,13 +688,12 @@
     }
 
     dev->base_addr = ioaddr;
-    res = request_region(ioaddr, PCNET32_TOTAL_SIZE, chipname);
-    if (!res)
+    if (request_region(ioaddr, PCNET32_TOTAL_SIZE, chipname) == NULL)
 	return -EBUSY;
     
     /* pci_alloc_consistent returns page-aligned memory, so we do not have to check the alignment */
     if ((lp = pci_alloc_consistent(pdev, sizeof(*lp), &lp_dma_addr)) == NULL) {
-	release_resource(res);
+	release_region(ioaddr, PCNET32_TOTAL_SIZE);
 	return -ENOMEM;
     }
 
@@ -727,7 +725,7 @@
     if (!a) {
       printk(KERN_ERR PFX "No access methods\n");
       pci_free_consistent(lp->pci_dev, sizeof(*lp), lp, lp->dma_addr);
-      release_resource(res);
+      release_region(ioaddr, PCNET32_TOTAL_SIZE);
       return -ENODEV;
     }
     lp->a = *a;
@@ -775,7 +773,7 @@
 	else {
 	    printk(", failed to detect IRQ line.\n");
 	    pci_free_consistent(lp->pci_dev, sizeof(*lp), lp, lp->dma_addr);
-	    release_resource(res);
+	    release_region(ioaddr, PCNET32_TOTAL_SIZE);
 	    return -ENODEV;
 	}
     }
@@ -847,8 +845,9 @@
 	    if (lp->options == (PCNET32_PORT_FD | PCNET32_PORT_AUI))
 		val |= 2;
 	} else if (lp->options & PCNET32_PORT_ASEL) {
-	/* workaround for xSeries250 */
-	    val |= 3;
+	/* workaround of xSeries250, turn on for 79C975 only */
+	    i = ((lp->a.read_csr(ioaddr, 88) | (lp->a.read_csr(ioaddr,89) << 16)) >> 12) & 0xffff;
+	    if (i == 0x2627) val |= 3;
 	}
 	lp->a.write_bcr (ioaddr, 9, val);
     }
diff -urN linux-2.4.19-pre9/drivers/net/tg3.c linux-2.4.19-pre10/drivers/net/tg3.c
--- linux-2.4.19-pre9/drivers/net/tg3.c	Mon Jun  3 18:50:48 2002
+++ linux-2.4.19-pre10/drivers/net/tg3.c	Mon Jun  3 18:50:55 2002
@@ -152,6 +152,8 @@
 	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
 	{ PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC1000,
 	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
+	{ PCI_VENDOR_ID_ALTIMA, PCI_DEVICE_ID_ALTIMA_AC9100,
+	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
 	{ 0, }
 };
 
@@ -956,6 +958,17 @@
 		     tp->link_config.active_speed == SPEED_10))
 			tp->mac_mode |= MAC_MODE_LINK_POLARITY;
 	}
+
+	/* ??? Without this setting Netgear GA302T PHY does not
+	 * ??? send/receive packets...
+	 */
+	if ((tp->phy_id & PHY_ID_MASK) == PHY_ID_BCM5411 &&
+	    tp->pci_chip_rev_id == CHIPREV_ID_5700_ALTIMA) {
+		tp->mi_mode |= MAC_MI_MODE_AUTO_POLL;
+		tw32(MAC_MI_MODE, tp->mi_mode);
+		udelay(40);
+	}
+
 	tw32(MAC_MODE, tp->mac_mode);
 
 	if (tp->tg3_flags & TG3_FLAG_USE_LINKCHG_REG) {
@@ -1200,7 +1213,7 @@
 		if (ap->rxconfig & ANEG_CFG_FD)
 			ap->flags |= MR_LP_ADV_FULL_DUPLEX;
 		if (ap->rxconfig & ANEG_CFG_HD)
-			ap->flags |= MR_LP_ADV_FULL_DUPLEX;
+			ap->flags |= MR_LP_ADV_HALF_DUPLEX;
 		if (ap->rxconfig & ANEG_CFG_PS1)
 			ap->flags |= MR_LP_ADV_SYM_PAUSE;
 		if (ap->rxconfig & ANEG_CFG_PS2)
@@ -5671,7 +5684,8 @@
 	    grc_misc_cfg != GRC_MISC_CFG_BOARD_ID_5701 &&
 	    grc_misc_cfg != GRC_MISC_CFG_BOARD_ID_5702FE &&
 	    grc_misc_cfg != GRC_MISC_CFG_BOARD_ID_5703 &&
-	    grc_misc_cfg != GRC_MISC_CFG_BOARD_ID_5703S)
+	    grc_misc_cfg != GRC_MISC_CFG_BOARD_ID_5703S &&
+	    grc_misc_cfg != GRC_MISC_CFG_BOARD_ID_AC91002A1)
 		return -ENODEV;
 
 	/* ROFL, you should see Broadcom's driver code implementing
diff -urN linux-2.4.19-pre9/drivers/net/tg3.h linux-2.4.19-pre10/drivers/net/tg3.h
--- linux-2.4.19-pre9/drivers/net/tg3.h	Mon Jun  3 18:50:48 2002
+++ linux-2.4.19-pre10/drivers/net/tg3.h	Mon Jun  3 18:50:55 2002
@@ -100,6 +100,7 @@
 #define  CHIPREV_ID_5700_B0		 0x7100
 #define  CHIPREV_ID_5700_B1		 0x7101
 #define  CHIPREV_ID_5700_B3		 0x7102
+#define  CHIPREV_ID_5700_ALTIMA		 0x7104
 #define  CHIPREV_ID_5700_C0		 0x7200
 #define  CHIPREV_ID_5701_A0		 0x0000
 #define  CHIPREV_ID_5701_B0		 0x0100
@@ -1125,6 +1126,7 @@
 #define  GRC_MISC_CFG_BOARD_ID_5702FE	0x00004000
 #define  GRC_MISC_CFG_BOARD_ID_5703	0x00000000
 #define  GRC_MISC_CFG_BOARD_ID_5703S	0x00002000
+#define  GRC_MISC_CFG_BOARD_ID_AC91002A1 0x00001800
 #define GRC_LOCAL_CTRL			0x00006808
 #define  GRC_LCLCTRL_INT_ACTIVE		0x00000001
 #define  GRC_LCLCTRL_CLEARINT		0x00000002
@@ -1844,6 +1846,7 @@
 #define PHY_REV_BCM5401_B0		0x1
 #define PHY_REV_BCM5401_B2		0x3
 #define PHY_REV_BCM5401_C0		0x6
+#define PHY_REV_BCM5411_X0		0x1 /* Found on Netgear GA302T */
 
 	enum phy_led_mode		led_mode;
 
diff -urN linux-2.4.19-pre9/drivers/net/tulip/21142.c linux-2.4.19-pre10/drivers/net/tulip/21142.c
--- linux-2.4.19-pre9/drivers/net/tulip/21142.c	Fri Nov  9 13:45:35 2001
+++ linux-2.4.19-pre10/drivers/net/tulip/21142.c	Mon Jun  3 18:50:55 2002
@@ -167,8 +167,9 @@
 			int i;
 			for (i = 0; i < tp->mtable->leafcount; i++)
 				if (tp->mtable->mleaf[i].media == dev->if_port) {
+					int startup = ! ((tp->chip_id == DC21143 && tp->revision == 65));
 					tp->cur_index = i;
-					tulip_select_media(dev, 1);
+					tulip_select_media(dev, startup);
 					setup_done = 1;
 					break;
 				}
diff -urN linux-2.4.19-pre9/drivers/net/tulip/ChangeLog linux-2.4.19-pre10/drivers/net/tulip/ChangeLog
--- linux-2.4.19-pre9/drivers/net/tulip/ChangeLog	Mon Jun  3 18:50:48 2002
+++ linux-2.4.19-pre10/drivers/net/tulip/ChangeLog	Mon Jun  3 18:50:55 2002
@@ -1,3 +1,13 @@
+2002-05-11  Juan Quintela  <quintela@mandrakesoft.com>
+
+	* 21142.c (t21142_lnk_change): Revert earlier patch
+	to always reset phy; only conditionally do so now.
+
+2002-05-03  Jeff Garzik  <jgarzik@mandrakesoft.com>
+
+	* tulip_core (tulip_pci_tbl): Add new "comet"
+	pci id.  Contributed by Ohta Kyuma.
+
 2002-03-07  Jeff Garzik  <jgarzik@mandrakesoft.com>
 
 	* tulip_core (tulip_mwi_config): Use new PCI API functions
diff -urN linux-2.4.19-pre9/drivers/net/tulip/tulip_core.c linux-2.4.19-pre10/drivers/net/tulip/tulip_core.c
--- linux-2.4.19-pre9/drivers/net/tulip/tulip_core.c	Mon Jun  3 18:50:48 2002
+++ linux-2.4.19-pre10/drivers/net/tulip/tulip_core.c	Mon Jun  3 18:50:55 2002
@@ -15,8 +15,8 @@
 */
 
 #define DRV_NAME	"tulip"
-#define DRV_VERSION	"0.9.15-pre10"
-#define DRV_RELDATE	"Mar 8, 2002"
+#define DRV_VERSION	"0.9.15-pre11"
+#define DRV_RELDATE	"May 11, 2002"
 
 #include <linux/config.h>
 #include <linux/module.h>
@@ -208,6 +208,7 @@
 	{ 0x1317, 0x0981, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
 	{ 0x1317, 0x0985, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
 	{ 0x1317, 0x1985, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
+	{ 0x1317, 0x9511, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
 	{ 0x13D1, 0xAB02, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
 	{ 0x13D1, 0xAB03, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
 	{ 0x13D1, 0xAB08, PCI_ANY_ID, PCI_ANY_ID, 0, 0, COMET },
diff -urN linux-2.4.19-pre9/drivers/net/via-rhine.c linux-2.4.19-pre10/drivers/net/via-rhine.c
--- linux-2.4.19-pre9/drivers/net/via-rhine.c	Mon Jun  3 18:50:48 2002
+++ linux-2.4.19-pre10/drivers/net/via-rhine.c	Mon Jun  3 18:50:55 2002
@@ -9,8 +9,8 @@
 	a complete program and may only be used when the entire operating
 	system is licensed under the GPL.
 
-	This driver is designed for the VIA VT86c100A Rhine-II PCI Fast Ethernet
-	controller.  It also works with the older 3043 Rhine-I chip.
+	This driver is designed for the VIA VT86C100A Rhine-I. 
+	It also works with the 6102 Rhine-II, and 6105/6105M Rhine-III.   
 
 	The author may be reached as becker@scyld.com, or C/O
 	Scyld Computing Corporation
@@ -81,11 +81,24 @@
 	- Add ethtool support
 	- Replace some MII-related magic numbers with constants
 	
+	LK1.1.14 (Ivan G.):
+ 	- fixes comments for Rhine-III
+	- removes W_MAX_TIMEOUT (unused)
+	- adds HasDavicomPhy for Rhine-I (basis: linuxfet driver; my card
+	  is R-I and has Davicom chip, flag is referenced in kernel driver)
+	- sends chip_id as a parameter to wait_for_reset since np is not
+	  initialized on first call
+	- changes mmio "else if (chip_id==VT6102)" to "else" so it will work
+	  for Rhine-III's (documentation says same bit is correct)		
+	- transmit frame queue message is off by one - fixed
+	- adds IntrNormalSummary to "Something Wicked" exclusion list
+	  so normal interrupts will not trigger the message (src: Donald Becker)
+
 */
 
 #define DRV_NAME	"via-rhine"
-#define DRV_VERSION	"1.1.13"
-#define DRV_RELDATE	"Nov-17-2001"
+#define DRV_VERSION	"1.1.14"
+#define DRV_RELDATE	"May-3-2002"
 
 
 /* A few user-configurable values.
@@ -136,9 +149,6 @@
 
 #define PKT_BUF_SZ		1536			/* Size of each temporary Rx buffer.*/
 
-/* max time out delay time */
-#define W_MAX_TIMEOUT	0x0FFFU
-
 #if !defined(__OPTIMIZE__)  ||  !defined(__KERNEL__)
 #warning  You must compile this file with the correct options!
 #warning  See the last lines of the source file.
@@ -343,7 +353,7 @@
 static struct via_rhine_chip_info via_rhine_chip_info[] __devinitdata =
 {
 	{ "VIA VT86C100A Rhine", RHINE_IOTYPE, 128,
-	  CanHaveMII | ReqTxAlign },
+	  CanHaveMII | ReqTxAlign | HasDavicomPhy },
 	{ "VIA VT6102 Rhine-II", RHINE_IOTYPE, 256,
 	  CanHaveMII | HasWOL },
 	{ "VIA VT6105 Rhine-III", RHINE_IOTYPE, 256,
@@ -376,6 +386,11 @@
 	StickyHW=0x83, WOLcrClr=0xA4, WOLcgClr=0xA7, PwrcsrClr=0xAC,
 };
 
+/* Bits in ConfigD (select backoff algorithm (Ethernet capture effect)) */
+enum backoff_bits {
+	BackOpt=0x01, BackAMD=0x02, BackDEC=0x04, BackRandom=0x08
+};
+
 #ifdef USE_MEM
 /* Registers we check that mmio and reg are the same. */
 int mmio_verify_registers[] = {
@@ -424,11 +439,11 @@
 	u32 next_desc;
 };
 
-/* Bits in *_desc.status */
 enum rx_status_bits {
 	RxOK=0x8000, RxWholePkt=0x0300, RxErr=0x008F
 };
 
+/* Bits in *_desc.status */
 enum desc_status_bits {
 	DescOwn=0x80000000, DescEndPacket=0x4000, DescIntr=0x1000,
 };
@@ -476,13 +491,10 @@
 	u16 chip_cmd;						/* Current setting for ChipCmd */
 
 	/* These values are keep track of the transceiver/media in use. */
-	unsigned int full_duplex:1;			/* Full-duplex operation requested. */
-	unsigned int duplex_lock:1;
 	unsigned int default_port:4;		/* Last dev->if_port value. */
 	u8 tx_thresh, rx_thresh;
 
 	/* MII transceiver section. */
-	u16 advertising;					/* NWay media advertisement */
 	unsigned char phys[MAX_MII_CNT];			/* MII device addresses. */
 	unsigned int mii_cnt;			/* number of MIIs found, but only the first one is used */
 	u16 mii_status;						/* last read MII status */
@@ -506,14 +518,12 @@
 static int  via_rhine_close(struct net_device *dev);
 static inline void clear_tally_counters(long ioaddr);
 
-static void wait_for_reset(struct net_device *dev, char *name)
+static void wait_for_reset(struct net_device *dev, int chip_id, char *name)
 {
-	struct netdev_private *np = dev->priv;
 	long ioaddr = dev->base_addr;
-	int chip_id = np->chip_id;
 	int i;
 
-	/* 3043 may need long delay after reset (dlink) */
+	/* VT86C100A may need long delay after reset (dlink) */
 	if (chip_id == VT86C100A)
 		udelay(100);
 
@@ -539,7 +549,7 @@
 		/* More recent docs say that this bit is reserved ... */
 		n = inb(ioaddr + ConfigA) | 0x20;
 		outb(n, ioaddr + ConfigA);
-	} else if (chip_id == VT6102) {
+	} else {
 		n = inb(ioaddr + ConfigD) | 0x80;
 		outb(n, ioaddr + ConfigD);
 	}
@@ -663,7 +673,7 @@
 	writew(CmdReset, ioaddr + ChipCmd);
 
 	dev->base_addr = ioaddr;
-	wait_for_reset(dev, shortname);
+	wait_for_reset(dev, chip_id, shortname);
 
 	/* Reload the station address from the EEPROM. */
 #ifdef USE_IO
@@ -784,7 +794,7 @@
 				   (option & 0x300 ? 100 : 10),
 				   (option & 0x220 ? "full" : "half"));
 			if (np->mii_cnt)
-				mdio_write(dev, np->phys[0], 0,
+				mdio_write(dev, np->phys[0], MII_BMCR,
 						   ((option & 0x300) ? 0x2000 : 0) |  /* 100mbps? */
 						   ((option & 0x220) ? 0x0100 : 0));  /* Full duplex? */
 		}
@@ -968,9 +978,9 @@
 		writeb(dev->dev_addr[i], ioaddr + StationAddr + i);
 
 	/* Initialize other registers. */
-	writew(0x0006, ioaddr + PCIBusConfig);	/* Tune configuration??? */
-	/* Configure the FIFO thresholds. */
-	writeb(0x20, ioaddr + TxConfig);	/* Initial threshold 32 bytes */
+	writew(0x0006, ioaddr + PCIBusConfig);	/* Store & forward */
+	/* Configure initial FIFO thresholds. */
+	writeb(0x20, ioaddr + TxConfig);
 	np->tx_thresh = 0x20;
 	np->rx_thresh = 0x60;			/* Written in via_rhine_set_rx_mode(). */
 
@@ -1029,13 +1039,13 @@
 
 	if (phy_id == np->phys[0]) {
 		switch (regnum) {
-		case 0:							/* Is user forcing speed/duplex? */
+		case MII_BMCR:					/* Is user forcing speed/duplex? */
 			if (value & 0x9000)			/* Autonegotiation. */
 				np->mii_if.duplex_lock = 0;
 			else
 				np->mii_if.full_duplex = (value & 0x0100) ? 1 : 0;
 			break;
-		case 4:
+		case MII_ADVERTISE:
 			np->mii_if.advertising = value;
 			break;
 		}
@@ -1074,7 +1084,7 @@
 		return i;
 	alloc_rbufs(dev);
 	alloc_tbufs(dev);
-	wait_for_reset(dev, dev->name);
+	wait_for_reset(dev, np->chip_id, dev->name);
 	init_registers(dev);
 	if (debug > 2)
 		printk(KERN_DEBUG "%s: Done via_rhine_open(), status %4.4x "
@@ -1181,7 +1191,7 @@
 	alloc_rbufs(dev);
 
 	/* Reinitialize the hardware. */
-	wait_for_reset(dev, dev->name);
+	wait_for_reset(dev, np->chip_id, dev->name);
 	init_registers(dev);
 	
 	spin_unlock(&np->lock);
@@ -1251,7 +1261,7 @@
 
 	if (debug > 4) {
 		printk(KERN_DEBUG "%s: Transmit frame #%d queued in slot %d.\n",
-			   dev->name, np->cur_tx, entry);
+			   dev->name, np->cur_tx-1, entry);
 	}
 	return 0;
 }
@@ -1502,8 +1512,8 @@
 			printk(KERN_INFO "%s: Transmitter underrun, increasing Tx "
 				   "threshold setting to %2.2x.\n", dev->name, np->tx_thresh);
 	}
-	if ((intr_status & ~( IntrLinkChange | IntrStatsMax |
-						  IntrTxAbort | IntrTxAborted))) {
+	if (intr_status & ~( IntrLinkChange | IntrStatsMax |
+ 						 IntrTxAbort | IntrTxAborted | IntrNormalSummary)) {
 		if (debug > 1)
 			printk(KERN_ERR "%s: Something Wicked happened! %4.4x.\n",
 			   dev->name, intr_status);
diff -urN linux-2.4.19-pre9/drivers/net/wan/8253x/8253xmac.c linux-2.4.19-pre10/drivers/net/wan/8253x/8253xmac.c
--- linux-2.4.19-pre9/drivers/net/wan/8253x/8253xmac.c	Mon Jun  3 18:50:48 2002
+++ linux-2.4.19-pre10/drivers/net/wan/8253x/8253xmac.c	Wed Dec 31 16:00:00 1969
@@ -1,205 +0,0 @@
-/* 
- * Copyright (C) 2001 By Joachim Martillo, Telford Tools, Inc.
- *
- * 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 of the License, or (at your option) any later version.
- *
- **/
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include "ring.h"
-#include <linux/socket.h>
-#include <net/if.h>
-
-				/* This application sets a pseudo mac address that */
-				/* can be used when using the synchronous port in */
-				/* synchronous serial ethnernet emulation mode */
-
-int main(int argc, char **argv)
-{
-  int fd;
-  struct ifreq request;
-  PSEUDOMAC pmac;
-  char buffer[200];
-  int count;
-  unsigned int uppernib;
-  unsigned int lowernib;
-
-  
-  if(argc != 3)
-    {
-      fprintf(stderr, "Syntax: %s {ifname} {macaddr}.\n", *argv);
-      fflush(stdout);
-      exit(-1);
-    }
-  fd = socket(AF_INET, SOCK_DGRAM, 0);
-  if(fd < 0)
-    {
-      perror("socket failed.");
-      fflush(stdout);
-      exit(-2);
-    }
-
-  strcpy(request.ifr_ifrn.ifrn_name, argv[1]); /* requests go through the socket layer */
-
-  request.ifr_ifru.ifru_data = (char*) &pmac;
-
-  if(ioctl(fd, SAB8253XGETMAC, &request) < 0)
-    {
-      perror("ioctl failed.");
-      fflush(stdout);
-      exit(-3);
-    }
-  for(count = 0; count < 6; ++count)
-    {
-      buffer[2*count] = (pmac.addr[count] >> 4);
-      buffer[2*count] &= 0x0F;
-      if(buffer[2*count] < 10)
-	{
-	  buffer[2*count] += '0';
-	}
-      else
-	{
-	  buffer[2*count] += 'a';
-	}
-      buffer[(2*count)+1] = (pmac.addr[count] & 0x0F);
-      if(buffer[(2*count)+1] < 10)
-	{
-	  buffer[(2*count)+1] += '0';
-	}
-      else
-	{
-	  buffer[(2*count)+1] += 'a';
-	}
-    }
-  buffer[12] = 0;
-  printf("Old mac addres is %s.\n", buffer);
-  if(strlen(argv[2]) != 12)
-    {
-      printf("Bad size mac address %s.\n", argv[2]);
-      fflush(stdout);
-      exit(-1);
-    }
-  for(count = 0; count < 6; ++ count)
-    {
-      uppernib = argv[2][2*count];
-      lowernib = argv[2][(2*count)+1];
-      
-      switch(uppernib)
-	{
-	case '0':
-	case '1':
-	case '2':
-	case '3':
-	case '4':
-	case '5':
-	case '6':
-	case '7':
-	case '8':
-	case '9':
-	  uppernib -= '0';
-	  break;
-	case 'a':
-	case 'b':
-	case 'c':
-	case 'd':
-	case 'e':
-	case 'f':
-	  uppernib -= 'a';
-	  break;
-	case 'A':
-	case 'B':
-	case 'C':
-	case 'D':
-	case 'E':
-	case 'F':
-	  uppernib -= 'A';
-	  break;
-	default:
-	  uppernib = 0;
-	  break;
-	}
-      switch(lowernib)
-	{
-	case '0':
-	case '1':
-	case '2':
-	case '3':
-	case '4':
-	case '5':
-	case '6':
-	case '7':
-	case '8':
-	case '9':
-	  lowernib -= '0';
-	  break;
-	case 'a':
-	case 'b':
-	case 'c':
-	case 'd':
-	case 'e':
-	case 'f':
-	  lowernib -= 'a';
-	  break;
-	case 'A':
-	case 'B':
-	case 'C':
-	case 'D':
-	case 'E':
-	case 'F':
-	  lowernib -= 'A';
-	  break;
-	default:
-	  lowernib = 0;
-	  break;
-	}
-      pmac.addr[count] = ((uppernib << 4) | lowernib);
-    }
-    
-
-  if(ioctl(fd, SAB8253XSETMAC, &request) < 0) /* actually setting the mac address */
-    {
-      perror("ioctl failed.");
-      fflush(stdout);
-      exit(-2);
-    }
-
-  if(ioctl(fd, SAB8253XGETMAC, &request) < 0) /* getting it back so that value can be verified */
-    {
-      perror("ioctl failed.");
-      exit(-3);
-    }
-  for(count = 0; count < 6; ++count)
-    {
-      buffer[2*count] = (pmac.addr[count] >> 4);
-      buffer[2*count] &= 0x0F;
-      if(buffer[2*count] < 10)
-	{
-	  buffer[2*count] += '0';
-	}
-      else
-	{
-	  buffer[2*count] += 'a';
-	}
-      buffer[(2*count)+1] = (pmac.addr[count] & 0x0F);
-      if(buffer[(2*count)+1] < 10)
-	{
-	  buffer[(2*count)+1] += '0';
-	}
-      else
-	{
-	  buffer[(2*count)+1] += 'a';
-	}
-    }
-  buffer[12] = 0;
-  printf("New mac addres is %s.\n", buffer);
-  fflush(stdout);
-  exit(0);
-}
diff -urN linux-2.4.19-pre9/drivers/net/wan/8253x/8253xpeer.c linux-2.4.19-pre10/drivers/net/wan/8253x/8253xpeer.c
--- linux-2.4.19-pre9/drivers/net/wan/8253x/8253xpeer.c	Mon Jun  3 18:50:48 2002
+++ linux-2.4.19-pre10/drivers/net/wan/8253x/8253xpeer.c	Wed Dec 31 16:00:00 1969
@@ -1,113 +0,0 @@
-/* -*- linux-c -*- */
-/* 
- * Copyright (C) 2001 By Joachim Martillo, Telford Tools, Inc.
- *
- * 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 of the License, or (at your option) any later version.
- *
- **/
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include "8253xioc.h"
-#include <sys/poll.h>
-
-struct pollfd pollarray[2];
-
-/* This application sets up synchronous character mode and loosely
- * emulates putmsg/getmsg use with read and write. */
-
-char buffer[8192];
-
-int main(int argc, char **argv)
-{
-	int fd;
-	int status;
-	int prompt = 1;
-	int count;
-	
-	if(argc != 2)
-	{
-		fprintf(stderr, "Syntax: %s {portname}\n", *argv);
-		exit(-1);
-	}
-	fd = open(argv[1], O_RDWR);
-	if(fd < 0)
-	{
-		perror("open failed.");
-		exit(-2);
-	}
-	do
-	{
-		if(prompt)
-		{
-			printf("Enter data: ");
-			fflush(stdout);
-			prompt = 0;
-		}
-		pollarray[0].fd = 0;
-		pollarray[0].events = POLLIN;
-		pollarray[0].revents = 0;
-		pollarray[1].fd = fd;
-		pollarray[1].events = POLLIN|POLLOUT;
-		pollarray[1].revents = 0;
-		status = poll(pollarray, 2, 10);
-		switch(status)
-		{
-		case 0:
-			break;
-			
-		case 1:
-		case 2:
-			if(pollarray[0].revents == POLLIN)
-			{
-				if(count = read(0, buffer, 150), count <= 0)
-				{
-					perror("unable to read stdio.\n");
-					exit(0);
-				}
-				buffer[count] = '\0';
-				if(count)
-				{
-					if(pollarray[1].revents & POLLOUT)
-					{
-						if(write(pollarray[1].fd, buffer, count) <= 0)
-						{
-							perror("unable to write protodevice.\n");
-							exit(-1);
-						}
-					}
-					else
-					{
-						printf("Write of protodevice would block.\n");
-						fflush(stdout);
-					}
-				}
-				prompt = 1;
-			}
-			if(pollarray[1].revents & POLLIN)
-			{
-				if(count = read(pollarray[1].fd, buffer, 8192), count <= 0)
-				{
-					perror("unable to read protodevice.\n");
-					exit(0);
-				}
-				buffer[count] = '\0';
-				printf("\nRead: %s", buffer);
-				fflush(stdout);
-				prompt = 1;
-			}
-			break;
-			
-		default:
-			break;
-		}
-	}
-	while(status >= 0);
-}
-
diff -urN linux-2.4.19-pre9/drivers/net/wan/8253x/8253xspeed.c linux-2.4.19-pre10/drivers/net/wan/8253x/8253xspeed.c
--- linux-2.4.19-pre9/drivers/net/wan/8253x/8253xspeed.c	Mon Jun  3 18:50:48 2002
+++ linux-2.4.19-pre10/drivers/net/wan/8253x/8253xspeed.c	Wed Dec 31 16:00:00 1969
@@ -1,91 +0,0 @@
-/* -*- linux-c -*- */
-/* 
- * Copyright (C) 2001 By Joachim Martillo, Telford Tools, Inc.
- *
- * 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 of the License, or (at your option) any later version.
- *
- **/
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include "8253xioc.h"
-
-
-/* This application shows how to set custom speeds/baudrates */
-
-int main(int argc, char **argv)
-{
-	int fd;
-	unsigned long oldspeed, newspeed;
-	char buffer[200];
-	int count;
-	long value;
-	int noprompt = 0;
-	int epromindex;
-	
-	if(argc < 2)
-	{
-		fprintf(stderr, "Syntax: %s {portname} [-n] {new speed}.\n", *argv);
-		exit(-1);
-	}
-	fd = open(argv[1], O_RDWR);
-	if(fd < 0)
-	{
-		perror("open failed.");
-		exit(-2);
-	}
-	
-	if((argc > 2) && !strcmp("-n", argv[2]))
-	{
-		noprompt = 1;
-	}
-	
-	/* get the current values */
-	if(ioctl(fd, ATIS_IOCGSPEED, &oldspeed) < 0)
-	{
-		perror("ioctl failed.");
-		exit(-3);
-	}
-	/* set up the existing values as defaults */
-	newspeed = oldspeed;
-	/* gather all new values from the command line */
-	/* or via tty input.*/
-	if(argc == (noprompt + 3))
-	{
-		newspeed = atoi(argv[count]);
-	}
-	
-	fprintf(stderr, "speed [%ld/%ld]: ", oldspeed, newspeed);
-	
-	if(!noprompt)
-	{
-		if(count = read(0, buffer, 150), count <= 0)
-		{
-			exit(0);
-		}
-		buffer[count] = '\0';
-		if(buffer[0] != '\n')
-		{
-			sscanf(buffer, "%ld", &newspeed);
-		}
-	}
-	else
-	{
-		fprintf(stderr, "\n");
-	}
-	
-	/* This ioctl does the actual register load. */
-	if(ioctl(fd, ATIS_IOCSSPEED, &newspeed) < 0)
-	{
-		perror("ioctl failed.");
-		exit(-3);
-	}
-	
-	fflush(stdout);
-}
diff -urN linux-2.4.19-pre9/drivers/net/wan/8253x/8253xutl.c linux-2.4.19-pre10/drivers/net/wan/8253x/8253xutl.c
--- linux-2.4.19-pre9/drivers/net/wan/8253x/8253xutl.c	Mon Jun  3 18:50:48 2002
+++ linux-2.4.19-pre10/drivers/net/wan/8253x/8253xutl.c	Mon Jun  3 18:50:55 2002
@@ -1344,7 +1344,6 @@
 	while ((Sab8253xCountTransmit(port) > 0) || !port->all_sent) 
 	{
 		current->state = TASK_INTERRUPTIBLE;
-		current->counter = 0;
 		schedule_timeout(char_time);
 		if (signal_pending(current))
 		{
@@ -1355,10 +1354,6 @@
 			break;
 		}
 	}
-	
-#if 0
-	current->state = TASK_RUNNING; /* probably not necessary in 2.4.* */
-#endif
 }
 
 void sab8253x_flush_buffer(struct tty_struct *tty)
diff -urN linux-2.4.19-pre9/drivers/net/wan/8253x/Makefile linux-2.4.19-pre10/drivers/net/wan/8253x/Makefile
--- linux-2.4.19-pre9/drivers/net/wan/8253x/Makefile	Mon Jun  3 18:50:48 2002
+++ linux-2.4.19-pre10/drivers/net/wan/8253x/Makefile	Mon Jun  3 18:50:55 2002
@@ -26,19 +26,3 @@
 clean:
 	rm -f core *.o *.a *.s 8253xcfg 8253xmac eprom9050 *~
 
-8253xcfg: 8253xcfg.c
-	$(CC)  -o 8253xcfg $(EXTRA_CFLAGS) -U__KERNEL__ 8253xcfg.c
-
-8253xmac: 8253xmac.c
-	$(CC)  -o 8253xmac $(EXTRA_CFLAGS) -U__KERNEL__ 8253xmac.c
-
-8253xspeed: 8253xspeed.c
-	$(CC)  -o 8253xspeed $(EXTRA_CFLAGS) -U__KERNEL__ 8253xspeed.c
-
-8253xpeer: 8253xpeer.c
-	$(CC)  -o 8253xpeer $(EXTRA_CFLAGS) -U__KERNEL__ 8253xpeer.c
-
-eprom9050: eprom9050.c
-	$(CC)  -o eprom9050 $(EXTRA_CFLAGS) -U__KERNEL__ eprom9050.c
-
-
diff -urN linux-2.4.19-pre9/drivers/net/wan/8253x/eprom9050.c linux-2.4.19-pre10/drivers/net/wan/8253x/eprom9050.c
--- linux-2.4.19-pre9/drivers/net/wan/8253x/eprom9050.c	Mon Jun  3 18:50:48 2002
+++ linux-2.4.19-pre10/drivers/net/wan/8253x/eprom9050.c	Wed Dec 31 16:00:00 1969
@@ -1,100 +0,0 @@
-/* -*- linux-c -*- */
-/* 
- * Copyright (C) 2001 By Joachim Martillo, Telford Tools, Inc.
- *
- * 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 of the License, or (at your option) any later version.
- *
- **/
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include "8253xioc.h"
-#include "Reg9050.h"
-
-
-/* This application reprograms the eprom associated with the 9050 */
-
-int main(int argc, char **argv)
-{
-	int fd;
-	unsigned short oldeeprom[EPROM9050_SIZE], neweeprom[EPROM9050_SIZE];
-	char buffer[200];
-	int count;
-	int value;
-	unsigned short *pointer;
-	unsigned short *pointerold;
-	int noprompt = 0;
-	int epromindex;
-	
-	if(argc < 2)
-	{
-		fprintf(stderr, "Syntax: %s {portname} [-n] {prom values}.\n", *argv);
-		exit(-1);
-	}
-	fd = open(argv[1], O_RDWR);
-	if(fd < 0)
-	{
-		perror("open failed.");
-		exit(-2);
-	}
-	
-	if((argc > 2) && !strcmp("-n", argv[2]))
-	{
-		noprompt = 1;
-	}
-	
-	/* get the current values */
-	if(ioctl(fd, ATIS_IOCGSEP9050, &oldeeprom) < 0)
-	{
-		perror("ioctl failed.");
-		exit(-3);
-	}
-	/* set up the existing values as defaults */
-	memcpy(neweeprom, oldeeprom, sizeof(oldeeprom));
-	/* gather all new values from the command line */
-	/* or via tty input.*/
-	for(count = (2+noprompt), pointer = neweeprom; count < argc; ++count, ++pointer)
-	{
-		*pointer = atoi(argv[count]);
-	}
-	pointer = neweeprom;
-	pointerold = oldeeprom;
-	for(epromindex = 0; epromindex < EPROM9050_SIZE; ++epromindex)
-	{
-		fprintf(stderr, "LOCATION %i [%4.4x/%4.4x]: ", epromindex, *pointerold, *pointer);
-		
-		if(!noprompt)
-		{
-			if(count = read(0, buffer, 150), count <= 0)
-			{
-				exit(0);
-			}
-			buffer[count] = '\0';
-			if(buffer[0] != '\n')
-			{
-				sscanf(buffer, "%x", &value);
-				*pointer = (unsigned short) value;
-			}
-		}
-		else
-		{
-			fprintf(stderr, "\n");
-		}
-		++pointerold;
-		++pointer;
-	}
-	/* This ioctl does the actual register load. */
-	if(ioctl(fd, ATIS_IOCSSEP9050, neweeprom) < 0)
-	{
-		perror("ioctl failed.");
-		exit(-3);
-	}
-	
-	fflush(stdout);
-}
diff -urN linux-2.4.19-pre9/drivers/net/wan/sdla_fr.c linux-2.4.19-pre10/drivers/net/wan/sdla_fr.c
--- linux-2.4.19-pre9/drivers/net/wan/sdla_fr.c	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/net/wan/sdla_fr.c	Mon Jun  3 18:50:55 2002
@@ -2815,7 +2815,7 @@
 				chan->name, NIPQUAD(chan->ip_remote));
 
 		}else {
-			printk(KERN_INFO "%s: Route Added Successfully: %u.%u.%u.%U\n",
+			printk(KERN_INFO "%s: Route Added Successfully: %u.%u.%u.%u\n",
 				card->devname,NIPQUAD(chan->ip_remote));
 			chan->route_flag = ROUTE_ADDED;
 		}
@@ -4348,9 +4348,9 @@
 					card->devname,NIPQUAD(arphdr->ar_sip));
 
 			printk(KERN_INFO "%s: mask %u.%u.%u.%u\n", 
-				card->devname, NIPQUAD(in_dev->ida_list->ifa_mask));
+				card->devname, NIPQUAD(in_dev->ifa_list->ifa_mask));
 				printk(KERN_INFO "%s: local %u.%u.%u.%u\n", 
-				card->devname,NIPQUAD(in_dev->ida_list->ifa_local));
+				card->devname,NIPQUAD(in_dev->ifa_list->ifa_local));
 			return -1;
 		}
 
diff -urN linux-2.4.19-pre9/drivers/pci/pci.ids linux-2.4.19-pre10/drivers/pci/pci.ids
--- linux-2.4.19-pre9/drivers/pci/pci.ids	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/pci/pci.ids	Mon Jun  3 18:50:55 2002
@@ -5256,6 +5256,7 @@
 170c  YottaYotta Inc.
 173b  Altima (nee BroadCom)
 	03e8  AC1000 Gigabit Ethernet
+	03ea  AC9100 Gigabit Ethernet
 1743  Peppercon AG
 	8139  ROL/F-100 Fast Ethernet Adapter with ROL
 1813  Ambient Technologies Inc
diff -urN linux-2.4.19-pre9/drivers/pci/quirks.c linux-2.4.19-pre10/drivers/pci/quirks.c
--- linux-2.4.19-pre9/drivers/pci/quirks.c	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/pci/quirks.c	Mon Jun  3 18:50:55 2002
@@ -90,8 +90,8 @@
  *	VIA Apollo KT133 needs PCI latency patch
  *	Made according to a windows driver based patch by George E. Breese
  *	see PCI Latency Adjust on http://www.viahardware.com/download/viatweak.shtm
- *      Also see http://home.tiscalinet.de/au-ja/review-kt133a-1-en.html for
- *      the info on which Mr Breese based his work.
+ *      Also see http://www.au-ja.org/review-kt133a-1-en.phtml for the info on which 
+ *	Mr Breese based his work.
  *
  *	Updated based on further information from the site and also on
  *	information provided by VIA 
diff -urN linux-2.4.19-pre9/drivers/scsi/aha152x.c linux-2.4.19-pre10/drivers/scsi/aha152x.c
--- linux-2.4.19-pre9/drivers/scsi/aha152x.c	Fri Nov  9 14:05:06 2001
+++ linux-2.4.19-pre10/drivers/scsi/aha152x.c	Mon Jun  3 18:50:55 2002
@@ -13,9 +13,14 @@
  * General Public License for more details.
  *
  *
- * $Id: aha152x.c,v 2.4 2000/12/16 12:53:56 fischer Exp $
+ * $Id: aha152x.c,v 2.5 2002/04/14 11:24:53 fischer Exp $
  *
  * $Log: aha152x.c,v $
+ * Revision 2.5  2002/04/14 11:24:53  fischer
+ * - isapnp support
+ * - abort fixed
+ * - 2.5 support
+ *
  * Revision 2.4  2000/12/16 12:53:56  fischer
  * - allow REQUEST SENSE to be queued
  * - handle shared PCI interrupts
@@ -222,7 +227,9 @@
 #endif
 
 #include <linux/sched.h>
+#include <asm/irq.h>
 #include <asm/io.h>
+#include <linux/version.h>
 #include <linux/blk.h>
 #include "scsi.h"
 #include "sd.h"
@@ -306,15 +313,17 @@
 
 #define DELAY_DEFAULT 1000
 
-/* possible irq range */
 #if defined(PCMCIA)
 #define IRQ_MIN 0
 #define IRQ_MAX 16
 #else
 #define IRQ_MIN 9
+#if defined(__PPC)
+#define IRQ_MAX (NR_IRQS-1)
+#else
 #define IRQ_MAX 12
 #endif
-#define IRQS    IRQ_MAX-IRQ_MIN+1
+#endif
 
 enum {
 	not_issued	= 0x0001,	/* command not yet issued */
@@ -417,7 +426,7 @@
 	char *conf;
 } setup[2];
 
-static struct Scsi_Host *aha152x_host[IRQS];
+static struct Scsi_Host *aha152x_host[2];
 
 /*
  * internal states of the host
@@ -593,6 +602,7 @@
 #define SCDONE(SCpnt)		SCDATA(SCpnt)->done
 #define SCSEM(SCpnt)		SCDATA(SCpnt)->sem
 
+#define SG_ADDRESS(buffer)	((char *) (page_address((buffer)->page)+(buffer)->offset))
 
 /* state handling */
 static void seldi_run(struct Scsi_Host *shpnt);
@@ -668,7 +678,6 @@
 
 /* possible i/o addresses for the AIC-6260; default first */
 static unsigned short ports[] = { 0x340, 0x140 };
-#define PORT_COUNT (sizeof(ports) / sizeof(unsigned short))
 
 #if !defined(SKIP_BIOSTEST)
 /* possible locations for the Adaptec BIOS; defaults first */
@@ -684,7 +693,6 @@
 	0xeb800,		/* VTech Platinum SMP */
 	0xf0000,
 };
-#define ADDRESS_COUNT (sizeof(addresses) / sizeof(unsigned int))
 
 /* signatures for various AIC-6[23]60 based controllers.
    The point in detecting signatures is to avoid useless and maybe
@@ -726,8 +734,6 @@
 	{ "DTC3520A Host Adapter BIOS", 0x318a, 26 },
 		/* DTC 3520A ISA SCSI */
 };
-
-#define SIGNATURE_COUNT (sizeof(signatures) / sizeof(struct signature))
 #endif
 
 
@@ -806,7 +812,7 @@
 #if defined(PCMCIA) || !defined(MODULE)
 void aha152x_setup(char *str, int *ints)
 {
-	if(setup_count>2) {
+	if(setup_count>=ARRAY_SIZE(setup)) {
 		printk(KERN_ERR "aha152x: you can only configure up to two controllers\n");
 		return;
 	}
@@ -849,7 +855,7 @@
 #endif
 	int count=setup_count;
 
-	get_options(str, sizeof(ints)/sizeof(int), ints);
+	get_options(str, ARRAY_SIZE(ints), ints);
 	aha152x_setup(str,ints);
 
 	return count<setup_count;
@@ -903,10 +909,10 @@
 
 #if !defined(PCMCIA)
 	int i;
-	for (i = 0; i < PORT_COUNT && (setup->io_port != ports[i]); i++)
+	for (i = 0; i < ARRAY_SIZE(ports) && (setup->io_port != ports[i]); i++)
 		;
 
-	if (i == PORT_COUNT)
+	if (i == ARRAY_SIZE(ports))
 		return 0;
 #endif
 
@@ -939,12 +945,25 @@
 	return 1;
 }
 
+static inline struct Scsi_Host *lookup_irq(int irqno)
+{
+	int i;
+
+	for(i=0; i<ARRAY_SIZE(aha152x_host); i++)
+		if(aha152x_host[i] && aha152x_host[i]->irq==irqno)
+			return aha152x_host[i];
+
+	return 0;
+}
+
 static void swintr(int irqno, void *dev_id, struct pt_regs *regs)
 {
-	struct Scsi_Host *shpnt = aha152x_host[irqno - IRQ_MIN];
+	struct Scsi_Host *shpnt = lookup_irq(irqno);
 
-	if (!shpnt)
-        	printk(KERN_ERR "aha152x%d: catched software interrupt for unknown controller.\n", HOSTNO);
+	if (!shpnt) {
+        	printk(KERN_ERR "aha152x%d: catched software interrupt %d for unknown controller.\n", HOSTNO, irqno);
+		return;
+	}
 
 	HOSTDATA(shpnt)->swint++;
 
@@ -966,7 +985,7 @@
 #endif
 	tpnt->proc_name = "aha152x"; 
 
-	for (i = 0; i < IRQS; i++)
+	for (i = 0; i < ARRAY_SIZE(aha152x_host); i++)
 		aha152x_host[i] = (struct Scsi_Host *) NULL;
 
 	if (setup_count) {
@@ -981,7 +1000,7 @@
 	}
 
 #if defined(SETUP0)
-	if (setup_count < 2) {
+	if (setup_count < ARRAY_SIZE(setup)) {
 		struct aha152x_setup override = SETUP0;
 
 		if (setup_count == 0 || (override.io_port != setup[0].io_port)) {
@@ -1002,7 +1021,7 @@
 #endif
 
 #if defined(SETUP1)
-	if (setup_count < 2) {
+	if (setup_count < ARRAY_SIZE(setup)) {
 		struct aha152x_setup override = SETUP1;
 
 		if (setup_count == 0 || (override.io_port != setup[0].io_port)) {
@@ -1023,7 +1042,7 @@
 #endif
 
 #if defined(MODULE)
-	if (setup_count<2 && (aha152x[0]!=0 || io[0]!=0 || irq[0]!=0)) {
+	if (setup_count<ARRAY_SIZE(setup) && (aha152x[0]!=0 || io[0]!=0 || irq[0]!=0)) {
 		if(aha152x[0]!=0) {
 			setup[setup_count].conf        = "";
 			setup[setup_count].io_port     = aha152x[0];
@@ -1066,7 +1085,7 @@
 			       setup[setup_count].ext_trans);
 	}
 
-	if (setup_count < 2 && (aha152x1[0]!=0 || io[1]!=0 || irq[1]!=0)) {
+	if (setup_count<ARRAY_SIZE(setup) && (aha152x1[0]!=0 || io[1]!=0 || irq[1]!=0)) {
 		if(aha152x1[0]!=0) {
 			setup[setup_count].conf        = "";
 			setup[setup_count].io_port     = aha152x1[0];
@@ -1110,7 +1129,7 @@
 #endif
 
 #ifdef __ISAPNP__
-	while ( setup_count<2 && (dev=isapnp_find_dev(NULL, ISAPNP_VENDOR('A','D','P'), ISAPNP_FUNCTION(0x1505), dev)) ) {
+	while ( setup_count<ARRAY_SIZE(setup) && (dev=isapnp_find_dev(NULL, ISAPNP_VENDOR('A','D','P'), ISAPNP_FUNCTION(0x1505), dev)) ) {
 		if (dev->prepare(dev) < 0)
 			continue;
 		if (dev->active)
@@ -1145,11 +1164,11 @@
 
 
 #if defined(AUTOCONF)
-	if (setup_count < 2) {
+	if (setup_count<ARRAY_SIZE(setup)) {
 #if !defined(SKIP_BIOSTEST)
 		ok = 0;
-		for (i = 0; i < ADDRESS_COUNT && !ok; i++)
-			for (j = 0; (j < SIGNATURE_COUNT) && !ok; j++)
+		for (i = 0; i < ARRAY_SIZE(addresses) && !ok; i++)
+			for (j = 0; j<ARRAY_SIZE(signatures) && !ok; j++)
 				ok = isa_check_signature(addresses[i] + signatures[j].sig_offset,
 								signatures[j].signature, signatures[j].sig_length);
 
@@ -1162,7 +1181,7 @@
 #endif				/* !SKIP_BIOSTEST */
 
 		ok = 0;
-		for (i = 0; i < PORT_COUNT && setup_count < 2; i++) {
+		for (i = 0; i < ARRAY_SIZE(ports) && setup_count < 2; i++) {
 			if ((setup_count == 1) && (setup[0].io_port == ports[i]))
 				continue;
 
@@ -1217,7 +1236,7 @@
 	for (i=0; i<setup_count; i++) {
 		struct Scsi_Host *shpnt;
 
-		aha152x_host[setup[i].irq - IRQ_MIN] = shpnt =
+		aha152x_host[registered_count] = shpnt =
 		    scsi_register(tpnt, sizeof(struct aha152x_hostdata));
 
 		if(!shpnt) {
@@ -1341,7 +1360,7 @@
 			scsi_unregister(shpnt);
 			registered_count--;
 			release_region(shpnt->io_port, IO_RANGE);
-			aha152x_host[shpnt->irq - IRQ_MIN] = 0;
+			aha152x_host[registered_count] = 0;
 			shpnt = 0;
 			continue;
 		}
@@ -1349,9 +1368,7 @@
 
 		printk(KERN_INFO "aha152x%d: trying software interrupt, ", HOSTNO);
 		SETPORT(DMACNTRL0, SWINT|INTEN);
-		spin_unlock_irq(&io_request_lock);
 		mdelay(1000);
-		spin_lock_irq(&io_request_lock);
 		free_irq(shpnt->irq, shpnt);
 
 		if (!HOSTDATA(shpnt)->swint) {
@@ -1367,7 +1384,7 @@
 
 			registered_count--;
 			release_region(shpnt->io_port, IO_RANGE);
-			aha152x_host[shpnt->irq - IRQ_MIN] = 0;
+			aha152x_host[registered_count] = 0;
 			scsi_unregister(shpnt);
 			shpnt=NULL;
 			continue;
@@ -1382,10 +1399,11 @@
 		if (request_irq(shpnt->irq, intr, SA_INTERRUPT|SA_SHIRQ, "aha152x", shpnt) < 0) {
 			printk(KERN_ERR "aha152x%d: failed to reassign interrupt.\n", HOSTNO);
 
-			scsi_unregister(shpnt);
 			registered_count--;
 			release_region(shpnt->io_port, IO_RANGE);
-			shpnt = aha152x_host[shpnt->irq - IRQ_MIN] = 0;
+			aha152x_host[registered_count] = 0;
+			scsi_unregister(shpnt);
+			shpnt=NULL;
 			continue;
 		}
 	}
@@ -1494,7 +1512,7 @@
 	   SCp.phase            : current state of the command */
 	if (SCpnt->use_sg) {
 		SCpnt->SCp.buffer           = (struct scatterlist *) SCpnt->request_buffer;
-		SCpnt->SCp.ptr              = SCpnt->SCp.buffer->address;
+		SCpnt->SCp.ptr              = SG_ADDRESS(SCpnt->SCp.buffer);
 		SCpnt->SCp.this_residual    = SCpnt->SCp.buffer->length;
 		SCpnt->SCp.buffers_residual = SCpnt->use_sg - 1;
 	} else {
@@ -1584,7 +1602,6 @@
 	if(HOSTDATA(shpnt)->debug & debug_eh) {
 		printk(DEBUG_LEAD "abort(%p)", CMDINFO(SCpnt), SCpnt);
 		show_queues(shpnt);
-		mdelay(1000);
 	}
 #endif
 
@@ -1622,9 +1639,19 @@
 
 static void timer_expired(unsigned long p)
 {
-	struct semaphore *sem = (void *)p;
+	Scsi_Cmnd	 *SCp   = (Scsi_Cmnd *)p;
+	struct semaphore *sem   = SCSEM(SCp);
+	struct Scsi_Host *shpnt = SCp->host;
+
+	/* remove command from issue queue */
+	if(remove_SC(&ISSUE_SC, SCp)) {
+		printk(KERN_INFO "aha152x: ABORT timed out - removed from issue queue\n");
+		kfree(SCp->host_scribble);
+		SCp->host_scribble=0;
+	} else {
+		printk(KERN_INFO "aha152x: ABORT timed out - not on issue queue\n");
+	}
 
-	printk(KERN_INFO "aha152x: timer expired\n");
 	up(sem);
 }
 
@@ -1645,7 +1672,6 @@
 	if(HOSTDATA(shpnt)->debug & debug_eh) {
 		printk(INFO_LEAD "aha152x_device_reset(%p)", CMDINFO(SCpnt), SCpnt);
 		show_queues(shpnt);
-		mdelay(1000);
 	}
 #endif
 
@@ -1663,13 +1689,13 @@
 	cmnd.request_bufflen = 0;
 
 	init_timer(&timer);
-	timer.data     = (unsigned long) &sem;
+	timer.data     = (unsigned long) &cmnd;
 	timer.expires  = jiffies + 100*HZ;   /* 10s */
 	timer.function = (void (*)(unsigned long)) timer_expired;
-	add_timer(&timer);
 
 	aha152x_internal_queue(&cmnd, &sem, resetting, 0, internal_done);
 
+	add_timer(&timer);
 	down(&sem);
 
 	del_timer(&timer);
@@ -1719,7 +1745,6 @@
 	if(HOSTDATA(shpnt)->debug & debug_eh) {
 		printk(DEBUG_LEAD "aha152x_bus_reset(%p)", CMDINFO(SCpnt), SCpnt);
 		show_queues(shpnt);
-		mdelay(1000);
 	}
 #endif
 
@@ -1878,7 +1903,7 @@
 static void run(void)
 {
 	int i;
-	for (i = 0; i < IRQS; i++) {
+	for (i = 0; i<ARRAY_SIZE(aha152x_host); i++) {
 		struct Scsi_Host *shpnt = aha152x_host[i];
 		if (shpnt && HOSTDATA(shpnt)->service) {
 			HOSTDATA(shpnt)->service=0;
@@ -1894,10 +1919,10 @@
 
 static void intr(int irqno, void *dev_id, struct pt_regs *regs)
 {
-	struct Scsi_Host *shpnt = aha152x_host[irqno - IRQ_MIN];
+	struct Scsi_Host *shpnt = lookup_irq(irqno);
 
 	if (!shpnt) {
-		printk(KERN_ERR "aha152x: catched interrupt for unknown controller.\n");
+		printk(KERN_ERR "aha152x: catched interrupt %d for unknown controller.\n", irqno);
 		return;
 	}
 
@@ -2681,7 +2706,7 @@
                                		/* advance to next buffer */
                                		CURRENT_SC->SCp.buffers_residual--;
                                		CURRENT_SC->SCp.buffer++;
-                               		CURRENT_SC->SCp.ptr           = CURRENT_SC->SCp.buffer->address;
+                               		CURRENT_SC->SCp.ptr           = SG_ADDRESS(CURRENT_SC->SCp.buffer);
                                		CURRENT_SC->SCp.this_residual = CURRENT_SC->SCp.buffer->length;
 				} 
                 	}
@@ -2791,7 +2816,7 @@
 			/* advance to next buffer */
 			CURRENT_SC->SCp.buffers_residual--;
 			CURRENT_SC->SCp.buffer++;
-			CURRENT_SC->SCp.ptr           = CURRENT_SC->SCp.buffer->address;
+			CURRENT_SC->SCp.ptr           = SG_ADDRESS(CURRENT_SC->SCp.buffer);
 			CURRENT_SC->SCp.this_residual = CURRENT_SC->SCp.buffer->length;
 		}
 
@@ -2821,13 +2846,13 @@
 		CURRENT_SC->resid += data_count;
 
 		if(CURRENT_SC->use_sg) {
-			data_count -= CURRENT_SC->SCp.ptr - CURRENT_SC->SCp.buffer->address;
+			data_count -= CURRENT_SC->SCp.ptr - SG_ADDRESS(CURRENT_SC->SCp.buffer);
 			while(data_count>0) {
 				CURRENT_SC->SCp.buffer--;
 				CURRENT_SC->SCp.buffers_residual++;
 				data_count -= CURRENT_SC->SCp.buffer->length;
 			}
-			CURRENT_SC->SCp.ptr           = CURRENT_SC->SCp.buffer->address - data_count;
+			CURRENT_SC->SCp.ptr           = SG_ADDRESS(CURRENT_SC->SCp.buffer) - data_count;
 			CURRENT_SC->SCp.this_residual = CURRENT_SC->SCp.buffer->length + data_count;
 		} else {
 			CURRENT_SC->SCp.ptr           -= data_count;
@@ -2955,10 +2980,9 @@
 	int pending;
 
 	DO_LOCK(flags);
-	if(HOSTDATA(shpnt)->in_intr!=0)
-	{
+	if(HOSTDATA(shpnt)->in_intr!=0) {
 		DO_UNLOCK(flags);
-		/* _error never returns.. */
+		/* aha152x_error never returns.. */
 		aha152x_error(shpnt, "bottom-half already running!?");
 	}
 	HOSTDATA(shpnt)->in_intr++;
@@ -3765,7 +3789,7 @@
 	unsigned long flags;
 	int thislength;
 
-	for (i = 0, shpnt = (struct Scsi_Host *) NULL; i < IRQS; i++)
+	for (i = 0, shpnt = (struct Scsi_Host *) NULL; i<ARRAY_SIZE(aha152x_host); i++)
 		if (aha152x_host[i] && aha152x_host[i]->host_no == hostno)
 			shpnt = aha152x_host[i];
 
diff -urN linux-2.4.19-pre9/drivers/scsi/aha152x.h linux-2.4.19-pre10/drivers/scsi/aha152x.h
--- linux-2.4.19-pre9/drivers/scsi/aha152x.h	Thu Jul 19 21:08:07 2001
+++ linux-2.4.19-pre10/drivers/scsi/aha152x.h	Mon Jun  3 18:50:55 2002
@@ -2,7 +2,7 @@
 #define _AHA152X_H
 
 /*
- * $Id: aha152x.h,v 2.4 2000/12/16 12:48:48 fischer Exp $
+ * $Id: aha152x.h,v 2.5 2002/04/14 11:24:12 fischer Exp $
  */
 
 #if defined(__KERNEL__)
@@ -27,7 +27,7 @@
    (unless we support more than 1 cmd_per_lun this should do) */
 #define AHA152X_MAXQUEUE 7
 
-#define AHA152X_REVID "Adaptec 152x SCSI driver; $Revision: 2.4 $"
+#define AHA152X_REVID "Adaptec 152x SCSI driver; $Revision: 2.5 $"
 
 /* Initial value of Scsi_Host entry */
 #define AHA152X { proc_name:			"aha152x",		\
diff -urN linux-2.4.19-pre9/drivers/scsi/ips.c linux-2.4.19-pre10/drivers/scsi/ips.c
--- linux-2.4.19-pre9/drivers/scsi/ips.c	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/scsi/ips.c	Mon Jun  3 18:50:55 2002
@@ -545,8 +545,6 @@
    return (1);
 }
 
-__setup("ips=", ips_setup);
-
 #else
 
   char      *p;
@@ -1641,6 +1639,10 @@
 
 }
 
+#if LINUX_VERSION_CODE >= LinuxVersionCode(2,4,0)
+__setup("ips=", ips_setup);
+#endif
+
 /****************************************************************************/
 /*                                                                          */
 /* Routine Name: ips_queue                                                  */
diff -urN linux-2.4.19-pre9/drivers/scsi/qlogicfc.c linux-2.4.19-pre10/drivers/scsi/qlogicfc.c
--- linux-2.4.19-pre9/drivers/scsi/qlogicfc.c	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/scsi/qlogicfc.c	Mon Jun  3 18:50:55 2002
@@ -1343,18 +1343,11 @@
 
 	num_free = QLOGICFC_REQ_QUEUE_LEN - REQ_QUEUE_DEPTH(in_ptr, out_ptr);
 	num_free = (num_free > 2) ? num_free - 2 : 0;
-	host->can_queue = hostdata->queued + num_free;
+	host->can_queue = host->host_busy + num_free;
 	if (host->can_queue > QLOGICFC_REQ_QUEUE_LEN)
 		host->can_queue = QLOGICFC_REQ_QUEUE_LEN;
 	host->sg_tablesize = QLOGICFC_MAX_SG(num_free);
 
-	/* this is really gross */
-	if (host->can_queue <= host->host_busy){
-	        if (host->can_queue+2 < host->host_busy) 
-			DEBUG(printk("qlogicfc%d.c crosses its fingers.\n", hostdata->host_id));
-		host->can_queue = host->host_busy + 1;
-	}
-
 	LEAVE("isp2x00_queuecommand");
 
 	return 0;
@@ -1623,17 +1616,11 @@
 
 	num_free = QLOGICFC_REQ_QUEUE_LEN - REQ_QUEUE_DEPTH(in_ptr, out_ptr);
 	num_free = (num_free > 2) ? num_free - 2 : 0;
-	host->can_queue = hostdata->queued + num_free;
+	host->can_queue = host->host_busy + num_free;
 	if (host->can_queue > QLOGICFC_REQ_QUEUE_LEN)
 		host->can_queue = QLOGICFC_REQ_QUEUE_LEN;
 	host->sg_tablesize = QLOGICFC_MAX_SG(num_free);
 
-	if (host->can_queue <= host->host_busy){
-	        if (host->can_queue+2 < host->host_busy) 
-		        DEBUG(printk("qlogicfc%d : crosses its fingers.\n", hostdata->host_id));
-		host->can_queue = host->host_busy + 1;
-	}
-
 	outw(HCCR_CLEAR_RISC_INTR, host->io_port + HOST_HCCR);
 	LEAVE_INTR("isp2x00_intr_handler");
 }
diff -urN linux-2.4.19-pre9/drivers/scsi/scsi_ioctl.c linux-2.4.19-pre10/drivers/scsi/scsi_ioctl.c
--- linux-2.4.19-pre9/drivers/scsi/scsi_ioctl.c	Wed Aug 15 01:22:16 2001
+++ linux-2.4.19-pre10/drivers/scsi/scsi_ioctl.c	Mon Jun  3 18:50:55 2002
@@ -377,9 +377,12 @@
 scsi_ioctl_get_pci(Scsi_Device * dev, void *arg)
 {
 
-        if (!dev->host->pci_dev) return -ENXIO;
-        return copy_to_user(arg, dev->host->pci_dev->slot_name,
-                            sizeof(dev->host->pci_dev->slot_name));
+        if (!dev->host->pci_dev)
+        	return -ENXIO;
+        if(copy_to_user(arg, dev->host->pci_dev->slot_name,
+                            sizeof(dev->host->pci_dev->slot_name)))
+		return -EFAULT;
+	return 0;
 }
 
 
diff -urN linux-2.4.19-pre9/drivers/scsi/scsi_scan.c linux-2.4.19-pre10/drivers/scsi/scsi_scan.c
--- linux-2.4.19-pre9/drivers/scsi/scsi_scan.c	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/scsi/scsi_scan.c	Mon Jun  3 18:50:55 2002
@@ -117,6 +117,8 @@
 	{"YAMAHA", "CRW6416S", "1.0c", BLIST_NOLUN},		/* Locks up if polled for lun != 0 */
 	{"MITSUMI", "CD-R CR-2201CS", "6119", BLIST_NOLUN},	/* Locks up if polled for lun != 0 */
 	{"RELISYS", "Scorpio", "*", BLIST_NOLUN},		/* responds to all LUN */
+	{"RELISYS", "VM3530+", "*", BLIST_NOLUN},		/* responds to all LUN */
+	{"ACROSS", "", "*", BLIST_NOLUN},			/* responds to all LUN */
 	{"MICROTEK", "ScanMaker II", "5.61", BLIST_NOLUN},	/* responds to all LUN */
 
 /*
diff -urN linux-2.4.19-pre9/drivers/scsi/sg.c linux-2.4.19-pre10/drivers/scsi/sg.c
--- linux-2.4.19-pre9/drivers/scsi/sg.c	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/scsi/sg.c	Mon Jun  3 18:50:55 2002
@@ -7,7 +7,7 @@
  * Original driver (sg.c):
  *        Copyright (C) 1992 Lawrence Foard
  * Version 2 and 3 extensions to driver:
- *        Copyright (C) 1998 - 2001 Douglas Gilbert
+ *        Copyright (C) 1998 - 2002 Douglas Gilbert
  *
  *  Modified  19-JAN-1998  Richard Gooch <rgooch@atnf.csiro.au>  Devfs support
  *
@@ -19,9 +19,9 @@
  */
 #include <linux/config.h>
 #ifdef CONFIG_PROC_FS
- static char sg_version_str[] = "Version: 3.1.23 (20020318)";
+ static char * sg_version_str = "Version: 3.1.24 (20020505)";
 #endif
- static int sg_version_num = 30123; /* 2 digits for each component */
+ static int sg_version_num = 30124; /* 2 digits for each component */
 /*
  *  D. P. Gilbert (dgilbert@interlog.com, dougg@triode.net.au), notes:
  *      - scsi logging is available via SCSI_LOG_TIMEOUT macros. First
@@ -1884,8 +1884,11 @@
 	    res = sg_u_iovec(hp, iovec_count, j, 1, &usglen, &up);
 	    if (res) return res;
 
-	    for (; (k < schp->k_use_sg) && p;
-		 ++k, ++sclp, ksglen = (int)sclp->length, p = sclp->address) {
+	    for (; k < schp->k_use_sg; ++k, ++sclp) {
+		ksglen = (int)sclp->length;
+		p = sclp->address;
+		if (NULL == p)
+		    break;
 		ok = (SG_USER_MEM != mem_src_arr[k]);
 		if (usglen <= 0)
 		    break;
@@ -2037,8 +2040,11 @@
 	    res = sg_u_iovec(hp, iovec_count, j, 0, &usglen, &up);
 	    if (res) return res;
 
-	    for (; (k < schp->k_use_sg) && p;
-		 ++k, ++sclp, ksglen = (int)sclp->length, p = sclp->address) {
+	    for (; k < schp->k_use_sg; ++k, ++sclp) {
+		ksglen = (int)sclp->length;
+		p = sclp->address;
+		if (NULL == p)
+		    break;
 		ok = (SG_USER_MEM != mem_src_arr[k]);
 		if (usglen <= 0)
 		    break;
@@ -2452,7 +2458,11 @@
         return resp;
     if (SG_HEAP_KMAL == mem_src) {
         resp = kmalloc(rqSz, page_mask);
-        if (resp && retSzp) *retSzp = rqSz;
+	if (resp) {
+	    if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
+	    	memset(resp, 0, rqSz);
+	    if (retSzp) *retSzp = rqSz;
+	}
         return resp;
     }
     if (SG_HEAP_POOL == mem_src) {
@@ -2469,6 +2479,8 @@
                 (scsi_dma_free_sectors > (SG_LOW_POOL_THRESHHOLD + num_sect))) {
                 resp = scsi_malloc(rqSz);
                 if (resp) {
+		    if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
+			memset(resp, 0, rqSz);
                     if (retSzp) *retSzp = rqSz;
                     sg_pool_secs_avail -= num_sect;
                     return resp;
@@ -2494,7 +2506,11 @@
             resp = (char *)__get_free_pages(page_mask, order); /* try half */
             resSz = a_size;
         }
-        if (retSzp) *retSzp = resSz;
+	if (resp) {
+	    if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
+                memset(resp, 0, resSz);
+	    if (retSzp) *retSzp = resSz;
+	}
     }
     else
         printk(KERN_ERR "sg_low_malloc: bad mem_src=%d, rqSz=%df\n", 
diff -urN linux-2.4.19-pre9/drivers/sgi/char/sgiserial.c linux-2.4.19-pre10/drivers/sgi/char/sgiserial.c
--- linux-2.4.19-pre9/drivers/sgi/char/sgiserial.c	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/sgi/char/sgiserial.c	Mon Jun  3 18:50:55 2002
@@ -1235,7 +1235,7 @@
 	tmp.close_delay = info->close_delay;
 	tmp.closing_wait = info->closing_wait;
 	tmp.custom_divisor = info->custom_divisor;
-	return copy_to_user(retinfo,&tmp,sizeof(*retinfo));
+	return copy_to_user(retinfo,&tmp,sizeof(*retinfo)) ? -EFAULT: 0;
 }
 
 static int set_serial_info(struct sgi_serial * info,
diff -urN linux-2.4.19-pre9/drivers/sound/Config.in linux-2.4.19-pre10/drivers/sound/Config.in
--- linux-2.4.19-pre9/drivers/sound/Config.in	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/sound/Config.in	Mon Jun  3 18:50:55 2002
@@ -6,7 +6,7 @@
 
 # Prompt user for primary drivers.
 
-dep_tristate '  BT878 audio dma' CONFIG_SOUND_BT878 $CONFIG_SOUND
+dep_tristate '  BT878 audio dma' CONFIG_SOUND_BT878 $CONFIG_SOUND $CONFIG_PCI
 dep_tristate '  C-Media PCI (CMI8338/8738)' CONFIG_SOUND_CMPCI $CONFIG_SOUND $CONFIG_PCI
 if [ "$CONFIG_SOUND_CMPCI" = "y" -o "$CONFIG_SOUND_CMPCI" = "m" ]; then
     bool '    Enable legacy FM' CONFIG_SOUND_CMPCI_FM
@@ -32,22 +32,22 @@
 fi
 dep_tristate '  Creative SBLive! (EMU10K1)' CONFIG_SOUND_EMU10K1 $CONFIG_SOUND $CONFIG_PCI
 dep_mbool    '    Creative SBLive! MIDI' CONFIG_MIDI_EMU10K1 $CONFIG_SOUND_EMU10K1 $CONFIG_EXPERIMENTAL
-dep_tristate '  Crystal SoundFusion (CS4280/461x)' CONFIG_SOUND_FUSION $CONFIG_SOUND
-dep_tristate '  Crystal Sound CS4281' CONFIG_SOUND_CS4281 $CONFIG_SOUND
+dep_tristate '  Crystal SoundFusion (CS4280/461x)' CONFIG_SOUND_FUSION $CONFIG_SOUND $CONFIG_PCI
+dep_tristate '  Crystal Sound CS4281' CONFIG_SOUND_CS4281 $CONFIG_SOUND $CONFIG_PCI
 if [ "$CONFIG_SIBYTE_SB1250" = "y" -a "$CONFIG_REMOTE_DEBUG" != "y" ]; then
     dep_tristate '  Crystal Sound CS4297a (for Swarm)' CONFIG_SOUND_BCM_CS4297A $CONFIG_SOUND
 fi
 dep_tristate '  Ensoniq AudioPCI (ES1370)' CONFIG_SOUND_ES1370 $CONFIG_SOUND $CONFIG_PCI
 dep_tristate '  Creative Ensoniq AudioPCI 97 (ES1371)' CONFIG_SOUND_ES1371 $CONFIG_SOUND $CONFIG_PCI
-dep_tristate '  ESS Technology Solo1' CONFIG_SOUND_ESSSOLO1 $CONFIG_SOUND
-dep_tristate '  ESS Maestro, Maestro2, Maestro2E driver' CONFIG_SOUND_MAESTRO $CONFIG_SOUND
+dep_tristate '  ESS Technology Solo1' CONFIG_SOUND_ESSSOLO1 $CONFIG_SOUND $CONFIG_PCI
+dep_tristate '  ESS Maestro, Maestro2, Maestro2E driver' CONFIG_SOUND_MAESTRO $CONFIG_SOUND $CONFIG_PCI
 dep_tristate '  ESS Maestro3/Allegro driver (EXPERIMENTAL)' CONFIG_SOUND_MAESTRO3 $CONFIG_SOUND $CONFIG_PCI $CONFIG_EXPERIMENTAL
-dep_tristate '  Intel ICH (i8xx) audio support' CONFIG_SOUND_ICH $CONFIG_PCI
+dep_tristate '  Intel ICH (i8xx), SiS 7012, NVidia nForce Audio or AMD 768' CONFIG_SOUND_ICH $CONFIG_PCI
 if [ "$CONFIG_MIPS_ITE8172" = "y" -o "$CONFIG_MIPS_IVR" = "y" ]; then
     dep_tristate '  IT8172G Sound' CONFIG_SOUND_IT8172 $CONFIG_SOUND
 fi
 dep_tristate '  RME Hammerfall (RME96XX) support' CONFIG_SOUND_RME96XX $CONFIG_SOUND $CONFIG_PCI $CONFIG_EXPERIMENTAL
-dep_tristate '  S3 SonicVibes' CONFIG_SOUND_SONICVIBES $CONFIG_SOUND
+dep_tristate '  S3 SonicVibes' CONFIG_SOUND_SONICVIBES $CONFIG_SOUND $CONFIG_PCI
 if [ "$CONFIG_VISWS" = "y" ]; then
     dep_tristate '  SGI Visual Workstation sound' CONFIG_SOUND_VWSND $CONFIG_SOUND
 fi
@@ -65,7 +65,7 @@
     dep_tristate '  Au1000 Sound' CONFIG_SOUND_AU1000 $CONFIG_SOUND
 fi
 
-dep_tristate '  Trident 4DWave DX/NX, SiS 7018 or ALi 5451 PCI Audio Core' CONFIG_SOUND_TRIDENT $CONFIG_SOUND
+dep_tristate '  Trident 4DWave DX/NX, SiS 7018 or ALi 5451 PCI Audio Core' CONFIG_SOUND_TRIDENT $CONFIG_SOUND $CONFIG_PCI
 
 dep_tristate '  Support for Turtle Beach MultiSound Classic, Tahiti, Monterey' CONFIG_SOUND_MSNDCLAS $CONFIG_SOUND
 if [ "$CONFIG_SOUND_MSNDCLAS" = "y" -o "$CONFIG_SOUND_MSNDCLAS" = "m" ]; then
diff -urN linux-2.4.19-pre9/drivers/sound/ac97_codec.c linux-2.4.19-pre10/drivers/sound/ac97_codec.c
--- linux-2.4.19-pre9/drivers/sound/ac97_codec.c	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/sound/ac97_codec.c	Mon Jun  3 18:50:55 2002
@@ -113,7 +113,7 @@
 	{0x41445340, "Analog Devices AD1881",	&null_ops},
 	{0x41445348, "Analog Devices AD1881A",	&null_ops},
 	{0x41445360, "Analog Devices AD1885",	&default_ops},
-	{0x41445361, "Analog Devices AD1886",	&default_ops},
+	{0x41445361, "Analog Devices AD1886",	&ad1886_ops},
 	{0x41445460, "Analog Devices AD1885",	&default_ops},
 	{0x41445461, "Analog Devices AD1886",	&ad1886_ops},
 	{0x414B4D00, "Asahi Kasei AK4540",	&null_ops},
@@ -746,10 +746,10 @@
 
 	/* detect bit resolution */
 	codec->codec_write(codec, AC97_MASTER_VOL_STEREO, 0x2020);
-	if(codec->codec_read(codec, AC97_MASTER_VOL_STEREO) == 0x1f1f)
-		codec->bit_resolution = 5;
-	else
+	if(codec->codec_read(codec, AC97_MASTER_VOL_STEREO) == 0x2020)
 		codec->bit_resolution = 6;
+	else
+		codec->bit_resolution = 5;
 
 	/* generic OSS to AC97 wrapper */
 	codec->read_mixer = ac97_read_mixer;
@@ -917,7 +917,7 @@
 
 /* 
  *	Presario700 workaround 
- * 	for Jack Sense/SPDIF Register misetting causing
+ * 	for Jack Sense/SPDIF Register mis-setting causing
  *	no audible output
  *	by Santiago Nullo 04/05/2002
  */
diff -urN linux-2.4.19-pre9/drivers/sound/ad1848.c linux-2.4.19-pre10/drivers/sound/ad1848.c
--- linux-2.4.19-pre9/drivers/sound/ad1848.c	Fri Dec 21 09:41:55 2001
+++ linux-2.4.19-pre10/drivers/sound/ad1848.c	Mon Jun  3 18:50:55 2002
@@ -33,6 +33,7 @@
  * Alan Cox		: Added CS4236->4239 identification
  * Daniel T. Cobra	: Alernate config/mixer for later chips
  * Alan Cox		: Merged chip idents and config code
+ * Zwane Mwaikambo	: Fix ISA PnP scan
  *
  * TODO
  *		APM save restore assist code on IBM thinkpad
@@ -3003,11 +3004,10 @@
 	return(dev);
 }
 
-static struct pci_dev *ad1848_init_generic(struct pci_bus *bus, struct address_info *hw_config, int slot)
+static struct pci_dev *ad1848_init_generic(struct pci_dev *dev, struct address_info *hw_config, int slot)
 {
-
-	/* Configure Audio device */
-	if((ad1848_dev = isapnp_find_dev(bus, ad1848_isapnp_list[slot].vendor, ad1848_isapnp_list[slot].function, NULL)))
+	/* Configure Audio device, point ad1848_dev to device found */
+	if((ad1848_dev = dev))
 	{
 		int ret;
 		ret = ad1848_dev->prepare(ad1848_dev);
@@ -3038,25 +3038,25 @@
 	return(ad1848_dev);
 }
 
-static int __init ad1848_isapnp_init(struct address_info *hw_config, struct pci_bus *bus, int slot)
+static int __init ad1848_isapnp_init(struct address_info *hw_config, struct pci_dev *dev, int slot)
 {
-	char *busname = bus->name[0] ? bus->name : ad1848_isapnp_list[slot].name;
+	char *devname = dev->name[0] ? dev->name : ad1848_isapnp_list[slot].name;
 
-	printk(KERN_INFO "ad1848: %s detected\n", busname);
+	printk(KERN_INFO "ad1848: %s detected\n", devname);
 
 	/* Initialize this baby. */
 
-	if(ad1848_init_generic(bus, hw_config, slot)) {
+	if(ad1848_init_generic(dev, hw_config, slot)) {
 		/* We got it. */
 
 		printk(KERN_NOTICE "ad1848: ISAPnP reports '%s' at i/o %#x, irq %d, dma %d, %d\n",
-		       busname,
+		       devname,
 		       hw_config->io_base, hw_config->irq, hw_config->dma,
 		       hw_config->dma2);
 		return 1;
 	}
 	else
-		printk(KERN_INFO "ad1848: Failed to initialize %s\n", busname);
+		printk(KERN_INFO "ad1848: Failed to initialize %s\n", devname);
 
 	return 0;
 }
@@ -3080,14 +3080,14 @@
 		i = isapnpjump;
 	first = 0;
 	while(ad1848_isapnp_list[i].card_vendor != 0) {
-		static struct pci_bus *bus = NULL;
-
-		while ((bus = isapnp_find_card(
-				ad1848_isapnp_list[i].card_vendor,
-				ad1848_isapnp_list[i].card_device,
-				bus))) {
+		static struct pci_dev *dev = NULL;
 
-			if(ad1848_isapnp_init(hw_config, bus, i)) {
+		while ((dev = isapnp_find_dev(NULL,
+				ad1848_isapnp_list[i].vendor,
+				ad1848_isapnp_list[i].function,
+				NULL))) {
+			
+			if(ad1848_isapnp_init(hw_config, dev, i)) {
 				isapnpjump = i; /* start next search from here */
 				return 0;
 			}
diff -urN linux-2.4.19-pre9/drivers/sound/au1000.c linux-2.4.19-pre10/drivers/sound/au1000.c
--- linux-2.4.19-pre9/drivers/sound/au1000.c	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/sound/au1000.c	Mon Jun  3 18:50:55 2002
@@ -1659,7 +1659,7 @@
 		if (count < 0)
 			count = 0;
 		cinfo.blocks = count >> s->dma_adc.fragshift;
-		return copy_to_user((void *) arg, &cinfo, sizeof(cinfo));
+		return copy_to_user((void *) arg, &cinfo, sizeof(cinfo))?-EFAULT:0;
 
 	case SNDCTL_DSP_GETOPTR:
 		if (!(file->f_mode & FMODE_READ))
@@ -1682,7 +1682,7 @@
 		if (count < 0)
 			count = 0;
 		cinfo.blocks = count >> s->dma_dac.fragshift;
-		return copy_to_user((void *) arg, &cinfo, sizeof(cinfo));
+		return copy_to_user((void *) arg, &cinfo, sizeof(cinfo))?-EFAULT:0;
 
 	case SNDCTL_DSP_GETBLKSIZE:
 		if (file->f_mode & FMODE_WRITE)
diff -urN linux-2.4.19-pre9/drivers/sound/dmasound/dmasound_core.c linux-2.4.19-pre10/drivers/sound/dmasound/dmasound_core.c
--- linux-2.4.19-pre9/drivers/sound/dmasound/dmasound_core.c	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/sound/dmasound/dmasound_core.c	Mon Jun  3 18:50:55 2002
@@ -1250,6 +1250,8 @@
 		} else
 			return -EINVAL ;
 		break ;
+	case SOUND_PCM_READ_CHANNELS:
+		return IOCTL_OUT(arg, dmasound.soft.stereo+1);
 	case SNDCTL_DSP_SETFMT:
 		if (shared_resources_are_mine(file->f_mode) &&
 		    queues_are_quiescent()) {
@@ -1260,8 +1262,6 @@
 			result = IOCTL_OUT(arg, format);
 			if (result < 0)
 				return result;
-			if (format != data)
-				return -EINVAL;
 			return 0;
 		} else
 			return -EINVAL ;
diff -urN linux-2.4.19-pre9/drivers/sound/i810_audio.c linux-2.4.19-pre10/drivers/sound/i810_audio.c
--- linux-2.4.19-pre9/drivers/sound/i810_audio.c	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/sound/i810_audio.c	Mon Jun  3 18:50:55 2002
@@ -101,6 +101,9 @@
 #ifndef PCI_DEVICE_ID_INTEL_ICH3
 #define PCI_DEVICE_ID_INTEL_ICH3	0x2485
 #endif
+#ifndef PCI_DEVICE_ID_INTEL_ICH4
+#define PCI_DEVICE_ID_INTEL_ICH4	0x24c5
+#endif
 #ifndef PCI_DEVICE_ID_INTEL_440MX
 #define PCI_DEVICE_ID_INTEL_440MX	0x7195
 #endif
@@ -233,6 +236,7 @@
 	INTEL440MX,
 	INTELICH2,
 	INTELICH3,
+	INTELICH4,
 	SI7012,
 	NVIDIA_NFORCE,
 	AMD768
@@ -244,6 +248,7 @@
 	"Intel 440MX",
 	"Intel ICH2",
 	"Intel ICH3",
+	"Intel ICH4",
 	"SiS 7012",
 	"NVIDIA nForce Audio",
 	"AMD 768"
@@ -260,6 +265,8 @@
 	 PCI_ANY_ID, PCI_ANY_ID, 0, 0, INTELICH2},
 	{PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH3,
 	 PCI_ANY_ID, PCI_ANY_ID, 0, 0, INTELICH3},
+	{PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH4,
+	 PCI_ANY_ID, PCI_ANY_ID, 0, 0, INTELICH4},
 	{PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_7012,
 	 PCI_ANY_ID, PCI_ANY_ID, 0, 0, SI7012},
 	{PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_MCP1_AUDIO,
@@ -2669,7 +2676,7 @@
 		codec->codec_write = i810_ac97_set;
 	
 		if(!i810_ac97_probe_and_powerup(card,codec)) {
-			printk("i810_audio: timed out waiting for codec %d analog ready", num_ac97);
+			printk("i810_audio: timed out waiting for codec %d analog ready.\n", num_ac97);
 			kfree(codec);
 			break;	/* it didn't work */
 		}
diff -urN linux-2.4.19-pre9/drivers/sound/ite8172.c linux-2.4.19-pre10/drivers/sound/ite8172.c
--- linux-2.4.19-pre9/drivers/sound/ite8172.c	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/sound/ite8172.c	Mon Jun  3 18:50:55 2002
@@ -1647,7 +1647,7 @@
 		if (count < 0)
 			count = 0;
 		cinfo.blocks = count >> s->dma_adc.fragshift;
-		return copy_to_user((void *)arg, &cinfo, sizeof(cinfo));
+		return copy_to_user((void *)arg, &cinfo, sizeof(cinfo))?-EFAULT:0;
 
 	case SNDCTL_DSP_GETOPTR:
 		if (!(file->f_mode & FMODE_READ))
@@ -1670,7 +1670,7 @@
 		if (count < 0)
 			count = 0;
 		cinfo.blocks = count >> s->dma_dac.fragshift;
-		return copy_to_user((void *)arg, &cinfo, sizeof(cinfo));
+		return copy_to_user((void *)arg, &cinfo, sizeof(cinfo))?-EFAULT:0;
 
 	case SNDCTL_DSP_GETBLKSIZE:
 		if (file->f_mode & FMODE_WRITE)
diff -urN linux-2.4.19-pre9/drivers/sound/mpu401.c linux-2.4.19-pre10/drivers/sound/mpu401.c
--- linux-2.4.19-pre9/drivers/sound/mpu401.c	Mon Feb 25 11:38:06 2002
+++ linux-2.4.19-pre10/drivers/sound/mpu401.c	Mon Jun  3 18:50:55 2002
@@ -15,6 +15,7 @@
  * Alan Cox		modularisation, use normal request_irq, use dev_id
  * Bartlomiej Zolnierkiewicz	removed some __init to allow using many drivers
  * Chris Rankin		Update the module-usage counter for the coprocessor
+ * Zwane Mwaikambo	Changed attach/unload resource freeing
  */
 
 #include <linux/module.h>
@@ -77,7 +78,7 @@
 
 static void mpu401_close(int dev);
 
-static int mpu401_status(struct mpu_config *devc)
+static inline int mpu401_status(struct mpu_config *devc)
 {
 	return inb(STATPORT(devc->base));
 }
@@ -85,17 +86,17 @@
 #define input_avail(devc)		(!(mpu401_status(devc)&INPUT_AVAIL))
 #define output_ready(devc)		(!(mpu401_status(devc)&OUTPUT_READY))
 
-static void write_command(struct mpu_config *devc, unsigned char cmd)
+static inline void write_command(struct mpu_config *devc, unsigned char cmd)
 {
 	outb(cmd, COMDPORT(devc->base));
 }
 
-static int read_data(struct mpu_config *devc)
+static inline int read_data(struct mpu_config *devc)
 {
 	return inb(DATAPORT(devc->base));
 }
 
-static void write_data(struct mpu_config *devc, unsigned char byte)
+static inline void write_data(struct mpu_config *devc, unsigned char byte)
 {
 	outb(byte, DATAPORT(devc->base));
 }
@@ -965,12 +966,12 @@
 	restore_flags(flags);
 }
 
-void attach_mpu401(struct address_info *hw_config, struct module *owner)
+int attach_mpu401(struct address_info *hw_config, struct module *owner)
 {
 	unsigned long flags;
 	char revision_char;
 
-	int m;
+	int m, ret;
 	struct mpu_config *devc;
 
 	hw_config->slots[1] = -1;
@@ -978,7 +979,8 @@
 	if (m == -1)
 	{
 		printk(KERN_WARNING "MPU-401: Too many midi devices detected\n");
-		return;
+		ret = -ENOMEM;
+		goto out_err;
 	}
 	devc = &dev_conf[m];
 	devc->base = hw_config->io_base;
@@ -1008,16 +1010,16 @@
 		if (!reset_mpu401(devc))
 		{
 			printk(KERN_WARNING "mpu401: Device didn't respond\n");
-			sound_unload_mididev(m);
-			return;
+			ret = -ENODEV;
+			goto out_mididev;
 		}
 		if (!devc->shared_irq)
 		{
 			if (request_irq(devc->irq, mpuintr, 0, "mpu401", (void *)m) < 0)
 			{
 				printk(KERN_WARNING "mpu401: Failed to allocate IRQ%d\n", devc->irq);
-				sound_unload_mididev(m);
-				return;
+				ret = -ENOMEM;
+				goto out_mididev;
 			}
 		}
 		save_flags(flags);
@@ -1027,7 +1029,12 @@
 			mpu401_chk_version(m, devc);
 		restore_flags(flags);
 	}
-	request_region(hw_config->io_base, 2, "mpu401");
+
+	if (!request_region(hw_config->io_base, 2, "mpu401"))
+	{
+		ret = -ENOMEM;
+		goto out_irq;
+	}	
 
 	if (devc->version != 0)
 		if (mpu_cmd(m, 0xC5, 0) >= 0)	/* Set timebase OK */
@@ -1039,9 +1046,9 @@
 
 	if (mpu401_synth_operations[m] == NULL)
 	{
-		sound_unload_mididev(m);
 		printk(KERN_ERR "mpu401: Can't allocate memory\n");
-		return;
+		ret = -ENOMEM;
+		goto out_resource;
 	}
 	if (!(devc->capabilities & MPU_CAP_INTLG))	/* No intelligent mode */
 	{
@@ -1120,6 +1127,17 @@
 
 	hw_config->slots[1] = m;
 	sequencer_init();
+	
+	return 0;
+
+out_resource:
+	release_region(hw_config->io_base, 2);
+out_irq:
+	free_irq(devc->irq, (void *)m);
+out_mididev:
+	sound_unload_mididev(m);
+out_err:
+	return ret;
 }
 
 static int reset_mpu401(struct mpu_config *devc)
@@ -1231,15 +1249,17 @@
 {
 	void *p;
 	int n=hw_config->slots[1];
-	
-	release_region(hw_config->io_base, 2);
-	if (hw_config->always_detect == 0 && hw_config->irq > 0)
-		free_irq(hw_config->irq, (void *)n);
-	p=mpu401_synth_operations[n];
-	sound_unload_mididev(n);
-	sound_unload_timerdev(hw_config->slots[2]);
-	if(p)
-		kfree(p);
+		
+	if (n != -1) {
+		release_region(hw_config->io_base, 2);
+		if (hw_config->always_detect == 0 && hw_config->irq > 0)
+			free_irq(hw_config->irq, (void *)n);
+		p=mpu401_synth_operations[n];
+		sound_unload_mididev(n);
+		sound_unload_timerdev(hw_config->slots[2]);
+		if(p)
+			kfree(p);
+	}
 }
 
 /*****************************************************
@@ -1754,6 +1774,7 @@
 
 int __init init_mpu401(void)
 {
+	int ret;
 	/* Can be loaded either for module use or to provide functions
 	   to others */
 	if (io != -1 && irq != -1) {
@@ -1761,7 +1782,8 @@
 		cfg.io_base = io;
 		if (probe_mpu401(&cfg) == 0)
 			return -ENODEV;
-		attach_mpu401(&cfg, THIS_MODULE);
+		if ((ret = attach_mpu401(&cfg, THIS_MODULE)))
+			return ret;
 	}
 	
 	return 0;
diff -urN linux-2.4.19-pre9/drivers/sound/mpu401.h linux-2.4.19-pre10/drivers/sound/mpu401.h
--- linux-2.4.19-pre9/drivers/sound/mpu401.h	Mon Feb 25 11:38:06 2002
+++ linux-2.4.19-pre10/drivers/sound/mpu401.h	Mon Jun  3 18:50:55 2002
@@ -7,7 +7,7 @@
 
 /*	From mpu401.c */
 int probe_mpu401(struct address_info *hw_config);
-void attach_mpu401(struct address_info * hw_config, struct module *owner);
+int attach_mpu401(struct address_info * hw_config, struct module *owner);
 void unload_mpu401(struct address_info *hw_info);
 
 int intchk_mpu401(void *dev_id);
diff -urN linux-2.4.19-pre9/drivers/sound/msnd_pinnacle.c linux-2.4.19-pre10/drivers/sound/msnd_pinnacle.c
--- linux-2.4.19-pre9/drivers/sound/msnd_pinnacle.c	Sun Sep 30 12:26:08 2001
+++ linux-2.4.19-pre10/drivers/sound/msnd_pinnacle.c	Mon Jun  3 18:50:55 2002
@@ -564,11 +564,11 @@
 		mixer_info info;
 		set_mixer_info();
 		info.modify_counter = dev.mixer_mod_count;
-		return copy_to_user((void *)arg, &info, sizeof(info));
+		return copy_to_user((void *)arg, &info, sizeof(info))?-EFAULT:0;
 	} else if (cmd == SOUND_OLD_MIXER_INFO) {
 		_old_mixer_info info;
 		set_mixer_info();
-		return copy_to_user((void *)arg, &info, sizeof(info));
+		return copy_to_user((void *)arg, &info, sizeof(info))?-EFAULT:0;
 	} else if (cmd == SOUND_MIXER_PRIVATE1) {
 		dev.nresets = 0;
 		dsp_full_reset();
diff -urN linux-2.4.19-pre9/drivers/sound/opl3sa2.c linux-2.4.19-pre10/drivers/sound/opl3sa2.c
--- linux-2.4.19-pre9/drivers/sound/opl3sa2.c	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/sound/opl3sa2.c	Mon Jun  3 18:50:55 2002
@@ -641,7 +641,7 @@
 	if(!request_region(hw_config->io_base, 2, OPL3SA2_MODULE_NAME)) {
 		printk(KERN_ERR PFX "Control I/O port %#x not free\n",
 		       hw_config->io_base);
-		return 0;
+		goto out_nodev;
 	}
 
 	/*
@@ -654,7 +654,7 @@
 	if(tmp != misc) {
 		printk(KERN_ERR PFX "Control I/O port %#x is not a YMF7xx chipset!\n",
 		       hw_config->io_base);
-		return 0;
+		goto out_region;
 	}
 
 	/*
@@ -667,7 +667,7 @@
 		printk(KERN_ERR
 		       PFX "Control I/O port %#x is not a YMF7xx chipset!\n",
 		       hw_config->io_base);
-		return 0;
+		goto out_region;
 	}
 	opl3sa2_write(hw_config->io_base, OPL3SA2_MIC, tmp);
 
@@ -714,9 +714,13 @@
 	if(opl3sa2_state[card].chipset != CHIPSET_UNKNOWN) {
 		/* Generate a pretty name */
 		opl3sa2_state[card].chipset_name = (char *)CHIPSET_TABLE[opl3sa2_state[card].chipset];
-		return 1;
+		return 0;
 	}
-	return 0;
+
+out_region:
+	release_region(hw_config->io_base, 2);
+out_nodev:
+	return -ENODEV;
 }
 
 
@@ -975,7 +979,7 @@
 
 static int opl3sa2_pm_callback(struct pm_dev *pdev, pm_request_t rqst, void *data)
 {
-	unsigned char mode = (unsigned  char)data;
+	unsigned char mode = (unsigned  long)data;
 
 	switch (rqst) {
 		case PM_SUSPEND:
@@ -1061,7 +1065,7 @@
 			opl3sa2_clear_slots(&opl3sa2_state[card].cfg_mpu);
 		}
 
-		if(!probe_opl3sa2(&opl3sa2_state[card].cfg, card) ||
+		if(probe_opl3sa2(&opl3sa2_state[card].cfg, card) ||
 		   !probe_opl3sa2_mss(&opl3sa2_state[card].cfg_mss)) {
 			/*
 			 * If one or more cards are already registered, don't
diff -urN linux-2.4.19-pre9/drivers/sound/sb_card.c linux-2.4.19-pre10/drivers/sound/sb_card.c
--- linux-2.4.19-pre9/drivers/sound/sb_card.c	Mon Feb 25 11:38:06 2002
+++ linux-2.4.19-pre10/drivers/sound/sb_card.c	Mon Jun  3 18:50:55 2002
@@ -373,6 +373,11 @@
 		0,0,0,0,
 		0,1,1,-1},
 	{"Sound Blaster AWE 32",
+		ISAPNP_VENDOR('C','T','L'), ISAPNP_DEVICE(0x0046),
+		ISAPNP_VENDOR('C','T','L'), ISAPNP_FUNCTION(0x0031),
+		0,0,0,0,
+		0,1,1,-1},
+	{"Sound Blaster AWE 32",
 		ISAPNP_VENDOR('C','T','L'), ISAPNP_DEVICE(0x0047),
 		ISAPNP_VENDOR('C','T','L'), ISAPNP_FUNCTION(0x0031),
 		0,0,0,0,
diff -urN linux-2.4.19-pre9/drivers/sound/swarm_cs4297a.c linux-2.4.19-pre10/drivers/sound/swarm_cs4297a.c
--- linux-2.4.19-pre9/drivers/sound/swarm_cs4297a.c	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/sound/swarm_cs4297a.c	Mon Jun  3 18:50:55 2002
@@ -2250,7 +2250,7 @@
 		if (s->dma_adc.mapped)
 			s->dma_adc.count &= s->dma_adc.fragsize - 1;
 		spin_unlock_irqrestore(&s->lock, flags);
-		return copy_to_user((void *) arg, &cinfo, sizeof(cinfo));
+		return copy_to_user((void *) arg, &cinfo, sizeof(cinfo))?-EFAULT:0;
 
 	case SNDCTL_DSP_GETOPTR:
 		if (!(file->f_mode & FMODE_WRITE))
@@ -2274,7 +2274,7 @@
 		if (s->dma_dac.mapped)
 			s->dma_dac.count &= s->dma_dac.fragsize - 1;
 		spin_unlock_irqrestore(&s->lock, flags);
-		return copy_to_user((void *) arg, &cinfo, sizeof(cinfo));
+		return copy_to_user((void *) arg, &cinfo, sizeof(cinfo))?-EFAULT:0;
 
 	case SNDCTL_DSP_GETBLKSIZE:
 		if (file->f_mode & FMODE_WRITE) {
diff -urN linux-2.4.19-pre9/drivers/sound/trident.c linux-2.4.19-pre10/drivers/sound/trident.c
--- linux-2.4.19-pre9/drivers/sound/trident.c	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/sound/trident.c	Mon Jun  3 18:50:55 2002
@@ -2447,7 +2447,7 @@
 		if (dmabuf->mapped)
 			dmabuf->count &= dmabuf->fragsize-1;
 		spin_unlock_irqrestore(&state->card->lock, flags);
-		ret = copy_to_user((void *)arg, &cinfo, sizeof(cinfo));
+		ret = copy_to_user((void *)arg, &cinfo, sizeof(cinfo))?-EFAULT:0;
 		break;
 
 	case SNDCTL_DSP_GETOPTR:
@@ -3297,11 +3297,18 @@
 			ali_ac97_write(card->ac97_codec[0], 0x02, 8080);
 			ali_ac97_write(card->ac97_codec[0], 0x36, 0);
 			ali_ac97_write(card->ac97_codec[0], 0x38, 0);
-			ali_ac97_write(card->ac97_codec[1], 0x36, 0);
-			ali_ac97_write(card->ac97_codec[1], 0x38, 0);
-			ali_ac97_write(card->ac97_codec[1], 0x02, 0x0606);
-			ali_ac97_write(card->ac97_codec[1], 0x18, 0x0303);
-			ali_ac97_write(card->ac97_codec[1], 0x74, 0x3);
+			/*
+			 *	On a board with a single codec you won't get the
+			 *	surround. On other boards configure it.
+			 */
+			if(card->ac97_codec[1]!=NULL)
+			{
+				ali_ac97_write(card->ac97_codec[1], 0x36, 0);
+				ali_ac97_write(card->ac97_codec[1], 0x38, 0);
+				ali_ac97_write(card->ac97_codec[1], 0x02, 0x0606);
+				ali_ac97_write(card->ac97_codec[1], 0x18, 0x0303);
+				ali_ac97_write(card->ac97_codec[1], 0x74, 0x3);
+			}
 			return 1;
 		}
 	}
diff -urN linux-2.4.19-pre9/drivers/sound/via82cxxx_audio.c linux-2.4.19-pre10/drivers/sound/via82cxxx_audio.c
--- linux-2.4.19-pre9/drivers/sound/via82cxxx_audio.c	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/sound/via82cxxx_audio.c	Mon Jun  3 18:50:55 2002
@@ -2526,7 +2526,7 @@
 		info.fragments,
 		info.bytes);
 
-	return copy_to_user (arg, &info, sizeof (info));
+	return copy_to_user (arg, &info, sizeof (info))?-EFAULT:0;
 }
 
 
@@ -2570,7 +2570,7 @@
 		info.blocks,
 		info.ptr);
 
-	return copy_to_user (arg, &info, sizeof (info));
+	return copy_to_user (arg, &info, sizeof (info))?-EFAULT:0;
 }
 
 
diff -urN linux-2.4.19-pre9/drivers/usb/Makefile linux-2.4.19-pre10/drivers/usb/Makefile
--- linux-2.4.19-pre9/drivers/usb/Makefile	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/usb/Makefile	Mon Jun  3 18:50:55 2002
@@ -10,7 +10,7 @@
 
 # Objects that export symbols.
 
-export-objs		:= usb.o ov511.o pwc-uncompress.o
+export-objs		:= hcd.o usb.o ov511.o pwc-uncompress.o
 
 # Multipart objects.
 
@@ -54,9 +54,8 @@
 obj-$(CONFIG_USB_UHCI_ALT)	+= uhci.o
 obj-$(CONFIG_USB_OHCI)		+= usb-ohci.o
 
-ifneq ($(CONFIG_EHCI_HCD),n)
+ifneq ($(CONFIG_USB_EHCI_HCD),n)
 	usbcore-objs		+= hcd.o
-	export-objs		+= hcd.o
 endif
 subdir-$(CONFIG_USB_EHCI_HCD)	+= hcd
 
diff -urN linux-2.4.19-pre9/drivers/usb/auerswald.c linux-2.4.19-pre10/drivers/usb/auerswald.c
--- linux-2.4.19-pre9/drivers/usb/auerswald.c	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/usb/auerswald.c	Mon Jun  3 18:50:55 2002
@@ -1546,7 +1546,7 @@
 		if (u > devinfo.bsize) {
 			u = devinfo.bsize;
 		}
-		ret = copy_to_user(devinfo.buf, cp->dev_desc, u);
+		ret = copy_to_user(devinfo.buf, cp->dev_desc, u)?-EFAULT:0;
 		break;
 
 	/* get the max. string descriptor length */
diff -urN linux-2.4.19-pre9/drivers/video/fbmem.c linux-2.4.19-pre10/drivers/video/fbmem.c
--- linux-2.4.19-pre9/drivers/video/fbmem.c	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/video/fbmem.c	Mon Jun  3 18:50:56 2002
@@ -224,6 +224,9 @@
 #ifdef CONFIG_FB_TRIDENT
 	{ "trident", tridentfb_init, tridentfb_setup },
 #endif
+#ifdef CONFIG_FB_VOODOO1
+	{ "sst", sstfb_init, sstfb_setup },
+#endif
 
 	/*
 	 * Generic drivers that are used as fallbacks
@@ -301,9 +304,6 @@
 #ifdef CONFIG_FB_PMAG_BA
 	{ "pmagbafb", pmagbafb_init, NULL },
 #endif
-#ifdef CONFIG_FB_VOODOO1
-	{ "sst", sstfb_init, sstfb_setup },
-#endif
 #ifdef CONFIG_FB_PMAGB_B
 	{ "pmagbbfb", pmagbbfb_init, NULL },
 #endif
diff -urN linux-2.4.19-pre9/drivers/video/riva/accel.c linux-2.4.19-pre10/drivers/video/riva/accel.c
--- linux-2.4.19-pre9/drivers/video/riva/accel.c	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/video/riva/accel.c	Mon Jun  3 18:50:56 2002
@@ -110,9 +110,9 @@
 static inline void fbcon_reverse_order(u32 *l)
 {
 	u8 *a = (u8 *)l;
-	*a++ = byte_rev[*a];
-/*	*a++ = byte_rev[*a];
-	*a++ = byte_rev[*a];*/
+	*a = byte_rev[*a], a++;
+/*	*a = byte_rev[*a], a++;
+	*a = byte_rev[*a], a++;*/
 	*a = byte_rev[*a];
 }
 
diff -urN linux-2.4.19-pre9/drivers/video/sis/300vtbl.h linux-2.4.19-pre10/drivers/video/sis/300vtbl.h
--- linux-2.4.19-pre9/drivers/video/sis/300vtbl.h	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/video/sis/300vtbl.h	Mon Jun  3 18:50:56 2002
@@ -1,53 +1,55 @@
 
-/* Comments and changes marked with "TW" by Thomas Winischhofer <tw@webit.com> */
+/* Comments and changes marked with "TW" by Thomas Winischhofer <thomas@winischhofer.net> */
 
 typedef struct _SiS300_StStruct
 {
-UCHAR St_ModeID;
-USHORT St_ModeFlag;
-UCHAR St_StTableIndex;
-UCHAR St_CRT2CRTC;
-UCHAR St_ResInfo;
-UCHAR VB_StTVFlickerIndex;
-UCHAR VB_StTVEdgeIndex;
-UCHAR VB_StTVYFilterIndex;
+	UCHAR St_ModeID;
+	USHORT St_ModeFlag;
+	UCHAR St_StTableIndex;
+	UCHAR St_CRT2CRTC;
+	UCHAR St_ResInfo;
+	UCHAR VB_StTVFlickerIndex;
+	UCHAR VB_StTVEdgeIndex;
+	UCHAR VB_StTVYFilterIndex;
 } SiS300_StStruct;
 SiS300_StStruct  SiS300_SModeIDTable[]=
-{ {0x01,0x9208,0x01,0x00,0x00,0x00,0x00,0x00},
-  {0x01,0x1210,0x14,0x01,0x01,0x00,0x00,0x00},
-  {0x01,0x1010,0x17,0x02,0x02,0x00,0x00,0x00},
-  {0x03,0x8208,0x03,0x00,0x00,0x00,0x00,0x00},
-  {0x03,0x0210,0x16,0x01,0x01,0x00,0x00,0x00},
-  {0x03,0x0010,0x18,0x02,0x02,0x00,0x00,0x00},
-  {0x05,0x9209,0x05,0x00,0x00,0x00,0x00,0x00},
-  {0x06,0x8209,0x06,0x00,0x00,0x00,0x00,0x00},
-  {0x07,0x0000,0x07,0x03,0x03,0x00,0x00,0x00},
-  {0x07,0x0000,0x19,0x02,0x02,0x00,0x00,0x00},
-  {0x0d,0x920a,0x0d,0x00,0x00,0x00,0x00,0x00},
-  {0x0e,0x820a,0x0e,0x00,0x00,0x00,0x00,0x00},
-  {0x0f,0x0202,0x11,0x01,0x01,0x00,0x00,0x00},
-  {0x10,0x0212,0x12,0x01,0x01,0x00,0x00,0x00},
-  {0x11,0x0212,0x1a,0x04,0x04,0x00,0x00,0x00},
-  {0x12,0x0212,0x1b,0x04,0x04,0x00,0x00,0x00},
-  {0x13,0x021b,0x1c,0x00,0x00,0x00,0x00,0x00},
-  /* {0x12,0x0210,0x18,0x00,0x00,0x00,0x00,0x00}, */  /* <--- Different in BIOS */
-     {0x12,0x0010,0x18,0x02,0x02,0x00,0x00,0x00},
-  {0x12,0x0210,0x18,0x01,0x01,0x00,0x00,0x00},
-  {0xff,0,0,0,0,0,0,0}
+{
+	{0x01,0x9208,0x01,0x00,0x00,0x00,0x00,0x00},
+	{0x01,0x1210,0x14,0x01,0x01,0x00,0x00,0x00},
+	{0x01,0x1010,0x17,0x02,0x02,0x00,0x00,0x00},
+	{0x03,0x8208,0x03,0x00,0x00,0x00,0x00,0x00},
+	{0x03,0x0210,0x16,0x01,0x01,0x00,0x00,0x00},
+	{0x03,0x0010,0x18,0x02,0x02,0x00,0x00,0x00},
+	{0x05,0x9209,0x05,0x00,0x00,0x00,0x00,0x00},
+	{0x06,0x8209,0x06,0x00,0x00,0x00,0x00,0x00},
+	{0x07,0x0000,0x07,0x03,0x03,0x00,0x00,0x00},
+	{0x07,0x0000,0x19,0x02,0x02,0x00,0x00,0x00},
+	{0x0d,0x920a,0x0d,0x00,0x00,0x00,0x00,0x00},
+	{0x0e,0x820a,0x0e,0x00,0x00,0x00,0x00,0x00},
+	{0x0f,0x0202,0x11,0x01,0x01,0x00,0x00,0x00},
+	{0x10,0x0212,0x12,0x01,0x01,0x00,0x00,0x00},
+	{0x11,0x0212,0x1a,0x04,0x04,0x00,0x00,0x00},
+	{0x12,0x0212,0x1b,0x04,0x04,0x00,0x00,0x00},
+	{0x13,0x021b,0x1c,0x00,0x00,0x00,0x00,0x00},
+	/* {0x12,0x0210,0x18,0x00,0x00,0x00,0x00,0x00}, */  /* <--- Different in BIOS */
+	{0x12,0x0010,0x18,0x02,0x02,0x00,0x00,0x00},
+	{0x12,0x0210,0x18,0x01,0x01,0x00,0x00,0x00},
+	{0xff,0,0,0,0,0,0,0}
 };
 
 typedef struct _SiS300_StandTableStruct
 {
-UCHAR CRT_COLS;
-UCHAR ROWS;
-UCHAR CHAR_HEIGHT;
-USHORT CRT_LEN;
-UCHAR SR[4];
-UCHAR MISC;
-UCHAR CRTC[0x19];
-UCHAR ATTR[0x14];
-UCHAR GRC[9];
+	UCHAR CRT_COLS;
+	UCHAR ROWS;
+	UCHAR CHAR_HEIGHT;
+	USHORT CRT_LEN;
+	UCHAR SR[4];
+	UCHAR MISC;
+	UCHAR CRTC[0x19];
+	UCHAR ATTR[0x14];
+	UCHAR GRC[9];
 } SiS300_StandTableStruct;
+
 SiS300_StandTableStruct  SiS300_StandTable[]=
 { /* TW: @ 0x38d4 in BIOS */
  {0x28,0x18,0x08,0x0800,
@@ -406,24 +408,27 @@
 
 typedef struct _SiS300_ExtStruct
 {
-UCHAR Ext_ModeID;
-USHORT Ext_ModeFlag;
-USHORT Ext_ModeInfo;
-USHORT Ext_Point;
-USHORT Ext_VESAID;
-UCHAR Ext_VESAMEMSize;
-UCHAR Ext_RESINFO;
-UCHAR VB_ExtTVFlickerIndex;
-UCHAR VB_ExtTVEdgeIndex;
-UCHAR VB_ExtTVYFilterIndex;
-UCHAR REFindex;
+	UCHAR Ext_ModeID;
+	USHORT Ext_ModeFlag;
+	USHORT Ext_ModeInfo;
+	USHORT Ext_Point;
+	USHORT Ext_VESAID;
+	UCHAR Ext_VESAMEMSize;
+	UCHAR Ext_RESINFO;
+	UCHAR VB_ExtTVFlickerIndex;
+	UCHAR VB_ExtTVEdgeIndex;
+	UCHAR VB_ExtTVYFilterIndex;
+	UCHAR REFindex;
 } SiS300_ExtStruct;
+
 SiS300_ExtStruct  SiS300_EModeIDTable[]=
 { /* TW: Table is identical to BIOS */		/* TW: BIOS offset to Ext2Struct: */
  {0x6a,0x2212,0x47,0x3563,0x0102,0x08,0x07,0x00,0x00,0x00,0x00},  /* 37ed */
- {0x2e,0x0a1b,0x36,0x3539,0x0101,0x08,0x06,0x00,0x00,0x00,0x08},  /* 37c3 */
+ {0x2e,0x0a1b,0x36,0x3539,0x0101,0x08,0x06,0x00,0x00,0x00,0x08},  /* 37c3 */ /* 8bpp bug? */
+ /* {0x2e,0x021b,0x36,0x3539,0x0101,0x08,0x06,0x00,0x00,0x00,0x08},  */ /* 37c3 */
  {0x2f,0x021b,0x35,0x3532,0x0100,0x08,0x05,0x00,0x00,0x00,0x10},  /* 37bc */
- {0x30,0x2a1b,0x47,0x3563,0x0103,0x08,0x07,0x00,0x00,0x00,0x00},  /* 37ed */
+ {0x30,0x2a1b,0x47,0x3563,0x0103,0x08,0x07,0x00,0x00,0x00,0x00},  /* 37ed */ /* 8bpp bug? */
+ /* {0x30,0x221b,0x47,0x3563,0x0103,0x08,0x07,0x00,0x00,0x00,0x00}, */ /* 37ed */
  {0x31,0x0a1b,0xad,0x3630,0x0000,0x08,0x0c,0x00,0x00,0x00,0x11},  /* 38ba */
  {0x32,0x2a1b,0xae,0x3637,0x0000,0x08,0x0d,0x00,0x00,0x00,0x12},  /* 38c1 */
  {0x33,0x0a1d,0xad,0x3630,0x0000,0x08,0x0c,0x00,0x00,0x00,0x11},  /* 38ba */
@@ -431,8 +436,10 @@
  {0x35,0x0a1f,0xad,0x3630,0x0000,0x08,0x0c,0x00,0x00,0x00,0x11},  /* 38ba */
  {0x36,0x2a1f,0xae,0x3637,0x0000,0x08,0x0d,0x00,0x00,0x00,0x12},  /* 38c1 */
  {0x37,0x0212,0x58,0x358d,0x0104,0x08,0x08,0x00,0x00,0x00,0x13},  /* 3817 */
- {0x38,0x0a1b,0x58,0x358d,0x0105,0x08,0x08,0x00,0x00,0x00,0x13},  /* 3817 */
- {0x3a,0x0e3b,0x69,0x35be,0x0107,0x08,0x09,0x00,0x00,0x00,0x1a},  /* 3848 */
+ {0x38,0x0a1b,0x58,0x358d,0x0105,0x08,0x08,0x00,0x00,0x00,0x13},  /* 3817 */ /* 8bpp bug? */
+ /* {0x38,0x021b,0x58,0x358d,0x0105,0x08,0x08,0x00,0x00,0x00,0x13}, */ /* 3817 */
+ {0x3a,0x0e3b,0x69,0x35be,0x0107,0x08,0x09,0x00,0x00,0x00,0x1a},  /* 3848 */ /* 8bpp bug? */
+ /* {0x3a,0x063b,0x69,0x35be,0x0107,0x08,0x09,0x00,0x00,0x00,0x1a}, */ /* 3848 */
  {0x3c,0x063b,0x7a,0x35d4,0x0130,0x08,0x0a,0x00,0x00,0x00,0x1e},  /* 385e */
  {0x3d,0x067d,0x7a,0x35d4,0x0131,0x08,0x0a,0x00,0x00,0x00,0x1e},  /* 385e */
  {0x40,0x921c,0x00,0x3516,0x010d,0x08,0x00,0x00,0x00,0x00,0x23},  /* 37a0 */
@@ -474,18 +481,18 @@
 
 typedef struct _SiS300_Ext2Struct
 {
-USHORT Ext_InfoFlag;
-UCHAR Ext_CRT1CRTC;  /* TW: Index in SiS300_CRT1Table */
-UCHAR Ext_CRTVCLK;
-UCHAR Ext_CRT2CRTC;  /* TW: Index in LCD Paneltype arrays (&3f) */
-UCHAR  ModeID;
-USHORT XRes;
-USHORT YRes;
-USHORT ROM_OFFSET;
+	USHORT Ext_InfoFlag;
+	UCHAR Ext_CRT1CRTC;  /* TW: Index in SiS300_CRT1Table */
+	UCHAR Ext_CRTVCLK;
+	UCHAR Ext_CRT2CRTC;  /* TW: Index in LCD Paneltype arrays (&3f) */
+	UCHAR  ModeID;
+	USHORT XRes;
+	USHORT YRes;
+	USHORT ROM_OFFSET;
 } SiS300_Ext2Struct;
+
 SiS300_Ext2Struct  SiS300_RefIndex[]=
 { /* TW: Don't ever insert anything here, table is indexed */
- /* TW: 800x600 values identical to BIOS */
  {0x085f,0x0d,0x03,0x05,0x6a, 800, 600,0x3563},
  {0x0467,0x0e,0x44,0x05,0x6a, 800, 600,0x3568},
  {0x0067,0x4f,0x07,0x48,0x6a, 800, 600,0x356d},
@@ -494,7 +501,6 @@
  {0x0147,0x12,0x0c,0x00,0x6a, 800, 600,0x357c},
  {0x0047,0x51,0x4e,0x00,0x6a, 800, 600,0x3581},
  {0x0047,0x11,0x13,0x00,0x6a, 800, 600,0x3586},
- /* TW: 640x480 identical to BIOS */
  {0xc85f,0x05,0x00,0x04,0x2e, 640, 480,0x3539},
  {0xc067,0x06,0x02,0x04,0x2e, 640, 480,0x353e},
  {0xc067,0x07,0x02,0x47,0x2e, 640, 480,0x3543},
@@ -503,13 +509,9 @@
  {0xc047,0x0a,0x08,0x00,0x2e, 640, 480,0x3552},
  {0xc047,0x0b,0x0a,0x00,0x2e, 640, 480,0x3557},
  {0xc047,0x0c,0x10,0x00,0x2e, 640, 480,0x355c},
- /* TW: 640x400 identical to BIOS */
  {0x487f,0x04,0x00,0x00,0x2f, 640, 400,0x3532},
- /* TW: 2048x1536 identical to BIOS */
  {0xc00f,0x31,0x01,0x06,0x31,2048,1536,0x3630},
- /* TW: 720x480 identical to BIOS */
  {0x000f,0x32,0x03,0x06,0x32, 720, 480,0x3637},
- /* TW: 1024x768 identical except for line 2 */
  {0x0187,0x15,0x05,0x00,0x37,1024, 768,0x358d},
  /* {0xc877,0x16,0x09,0x06,0x37,1024, 768,0x3592}, <--- different in BIOS */
  {0xc077,0x16,0x09,0x06,0x37,1024, 768,0x3592},
@@ -518,31 +520,22 @@
  {0x0047,0x59,0x11,0x8c,0x37,1024, 768,0x35a1},
  {0x0047,0x1a,0x52,0x00,0x37,1024, 768,0x35a6},
  {0x0047,0x5b,0x16,0x00,0x37,1024, 768,0x35ab},
- /* TW: 1280x1024 identical to BIOS */
  {0x0387,0x5c,0x4d,0x00,0x3a,1280,1024,0x35be},
  {0x0077,0x1d,0x14,0x07,0x3a,1280,1024,0x35c3},
  {0x0047,0x1e,0x17,0x00,0x3a,1280,1024,0x35c8},
  {0x0007,0x1f,0x98,0x00,0x3a,1280,1024,0x35cd},
- /* TW: 1600x1200 identical to BIOS */
  {0x0007,0x60,0x59,0x00,0x3c,1600,1200,0x35d4},
  {0x0007,0x21,0x5a,0x00,0x3c,1600,1200,0x35d9},
  {0x0007,0x22,0x1b,0x00,0x3c,1600,1200,0x35de},
  {0x0007,0x63,0x1d,0x00,0x3c,1600,1200,0x35e3},
  {0x0007,0x24,0x1e,0x00,0x3c,1600,1200,0x35e8},
  /* TW: No 1600x1200 LCD mode? */
- /* TW: 320x200 identical to BIOS */
  {0x407f,0x00,0x00,0x00,0x40, 320, 200,0x3516},
- /* TW: 320x240 identical to BIOS */
  {0xc07f,0x01,0x00,0x04,0x50, 320, 240,0x351d},
- /* TW: 400x300 identical to BIOS */
  {0x0077,0x02,0x04,0x05,0x51, 400, 300,0x3524},
- /* TW: 512x384 identical to BIOS */
  {0xc077,0x03,0x09,0x06,0x52, 512, 384,0x352b},
- /* TW: 1920x1440 identical to BIOS */
  {0x8207,0x25,0x1f,0x00,0x68,1920,1440,0x35ef},
- /* TW: 2048x1536 identical to BIOS */
  {0x0007,0x26,0x20,0x00,0x6c,2048,1536,0x35f6},
- /* TW: 720x576 identical to BIOS */
  {0x0027,0x27,0x14,0x08,0x6e, 720, 576,0x35b2},
  {0x0027,0x27,0x14,0x08,0x6e, 720, 576,0x35b7},
  /* TW: 1280x960 identical to BIOS */
@@ -578,76 +571,78 @@
 /*add for 300 oem util*/
 typedef struct _SiS_VBModeIDTableStruct
 {
-UCHAR  ModeID;
-UCHAR  VB_TVDelayIndex;
-UCHAR  VB_TVFlickerIndex;
-UCHAR  VB_TVPhaseIndex;
-UCHAR  VB_TVYFilterIndex;
-UCHAR  VB_LCDDelayIndex;
-UCHAR  _VB_LCDHIndex;
-UCHAR  _VB_LCDVIndex;
+	UCHAR  ModeID;
+	UCHAR  VB_TVDelayIndex;
+	UCHAR  VB_TVFlickerIndex;
+	UCHAR  VB_TVPhaseIndex;
+	UCHAR  VB_TVYFilterIndex;
+	UCHAR  VB_LCDDelayIndex;
+	UCHAR  _VB_LCDHIndex;
+	UCHAR  _VB_LCDVIndex;
 }SiS_VBModeIDTableStruct;
+
 SiS_VBModeIDTableStruct  SiS300_VBModeIDTable[]=
 {
- {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
- {0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01},
- {0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x02},
- {0x03,0x00,0x00,0x00,0x02,0x00,0x02,0x00},
- {0x03,0x00,0x00,0x00,0x02,0x00,0x02,0x01},
- {0x03,0x00,0x00,0x00,0x03,0x00,0x03,0x02},
- {0x05,0x00,0x00,0x01,0x04,0x00,0x00,0x00},
- {0x06,0x00,0x00,0x01,0x05,0x00,0x02,0x00},
- {0x07,0x00,0x00,0x00,0x03,0x00,0x03,0x01},
- {0x07,0x00,0x00,0x00,0x03,0x00,0x03,0x02},
- {0x0d,0x00,0x00,0x01,0x04,0x00,0x00,0x00},
- {0x0e,0x00,0x00,0x01,0x05,0x00,0x02,0x00},
- {0x0f,0x00,0x00,0x01,0x05,0x00,0x02,0x01},
- {0x10,0x00,0x00,0x01,0x05,0x00,0x02,0x01},
- {0x11,0x00,0x00,0x01,0x05,0x00,0x02,0x03},
- {0x12,0x00,0x00,0x01,0x05,0x00,0x02,0x03},
- {0x13,0x00,0x00,0x01,0x04,0x00,0x04,0x00},
- {0x6a,0x00,0x00,0x01,0x07,0x00,0x08,0x0a},
- {0x2e,0x00,0x00,0x01,0x05,0x00,0x06,0x08},
- {0x2f,0x00,0x00,0x01,0x05,0x00,0x06,0x06},
- {0x30,0x00,0x00,0x01,0x07,0x00,0x08,0x0a},
- {0x31,0x00,0x00,0x01,0x06,0x00,0x00,0x00},
- {0x32,0x00,0x00,0x01,0x06,0x00,0x00,0x00},
- {0x37,0x00,0x00,0x01,0x00,0x00,0x0a,0x0c},
- {0x38,0x00,0x00,0x01,0x00,0x00,0x0a,0x0c},
- {0x3a,0x00,0x00,0x01,0x00,0x00,0x0b,0x0d},
- {0x40,0x00,0x00,0x01,0x04,0x00,0x05,0x05},
- {0x41,0x00,0x00,0x01,0x04,0x00,0x05,0x05},
- {0x43,0x00,0x00,0x01,0x05,0x00,0x06,0x08},
- {0x44,0x00,0x00,0x01,0x05,0x00,0x06,0x08},
- {0x46,0x00,0x00,0x01,0x07,0x00,0x08,0x0a},
- {0x47,0x00,0x00,0x01,0x07,0x00,0x08,0x0a},
- {0x49,0x00,0x00,0x01,0x00,0x00,0x0a,0x0c},
- {0x4a,0x00,0x00,0x01,0x00,0x00,0x0a,0x0c},
- {0x4c,0x00,0x00,0x01,0x00,0x00,0x0b,0x0d},
- {0x4d,0x00,0x00,0x01,0x00,0x00,0x0b,0x0d},
- {0x50,0x00,0x00,0x01,0x04,0x00,0x05,0x07},
- {0x51,0x00,0x00,0x01,0x07,0x00,0x07,0x09},
- {0x52,0x00,0x00,0x01,0x00,0x00,0x09,0x0b},
- {0x56,0x00,0x00,0x01,0x04,0x00,0x05,0x07},
- {0x57,0x00,0x00,0x01,0x07,0x00,0x07,0x09},
- {0x58,0x00,0x00,0x01,0x00,0x00,0x09,0x0b},
- {0x59,0x00,0x00,0x01,0x04,0x00,0x05,0x05},
- {0x5d,0x00,0x00,0x01,0x07,0x00,0x06,0x06},
- {0x62,0x00,0x00,0x01,0x05,0x00,0x06,0x08},
- {0x63,0x00,0x00,0x01,0x07,0x00,0x08,0x0a},
- {0x64,0x00,0x00,0x01,0x00,0x00,0x0a,0x0c},
- {0x65,0x00,0x00,0x01,0x00,0x00,0x0b,0x0d},
- {0x6e,0x00,0x00,0x01,0x00,0x00,0x0b,0x0d},
- {0x6f,0x00,0x00,0x01,0x00,0x00,0x0b,0x0d},
- {0x7b,0x00,0x00,0x01,0x00,0x00,0x0b,0x0d}
+	{0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
+	{0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01},
+	{0x01,0x00,0x00,0x00,0x01,0x00,0x01,0x02},
+	{0x03,0x00,0x00,0x00,0x02,0x00,0x02,0x00},
+	{0x03,0x00,0x00,0x00,0x02,0x00,0x02,0x01},
+	{0x03,0x00,0x00,0x00,0x03,0x00,0x03,0x02},
+	{0x05,0x00,0x00,0x01,0x04,0x00,0x00,0x00},
+	{0x06,0x00,0x00,0x01,0x05,0x00,0x02,0x00},
+	{0x07,0x00,0x00,0x00,0x03,0x00,0x03,0x01},
+	{0x07,0x00,0x00,0x00,0x03,0x00,0x03,0x02},
+	{0x0d,0x00,0x00,0x01,0x04,0x00,0x00,0x00},
+	{0x0e,0x00,0x00,0x01,0x05,0x00,0x02,0x00},
+	{0x0f,0x00,0x00,0x01,0x05,0x00,0x02,0x01},
+	{0x10,0x00,0x00,0x01,0x05,0x00,0x02,0x01},
+	{0x11,0x00,0x00,0x01,0x05,0x00,0x02,0x03},
+	{0x12,0x00,0x00,0x01,0x05,0x00,0x02,0x03},
+	{0x13,0x00,0x00,0x01,0x04,0x00,0x04,0x00},
+	{0x6a,0x00,0x00,0x01,0x07,0x00,0x08,0x0a},
+	{0x2e,0x00,0x00,0x01,0x05,0x00,0x06,0x08},
+	{0x2f,0x00,0x00,0x01,0x05,0x00,0x06,0x06},
+	{0x30,0x00,0x00,0x01,0x07,0x00,0x08,0x0a},
+	{0x31,0x00,0x00,0x01,0x06,0x00,0x00,0x00},
+	{0x32,0x00,0x00,0x01,0x06,0x00,0x00,0x00},
+	{0x37,0x00,0x00,0x01,0x00,0x00,0x0a,0x0c},
+	{0x38,0x00,0x00,0x01,0x00,0x00,0x0a,0x0c},
+	{0x3a,0x00,0x00,0x01,0x00,0x00,0x0b,0x0d},
+	{0x40,0x00,0x00,0x01,0x04,0x00,0x05,0x05},
+	{0x41,0x00,0x00,0x01,0x04,0x00,0x05,0x05},
+	{0x43,0x00,0x00,0x01,0x05,0x00,0x06,0x08},
+	{0x44,0x00,0x00,0x01,0x05,0x00,0x06,0x08},
+	{0x46,0x00,0x00,0x01,0x07,0x00,0x08,0x0a},
+	{0x47,0x00,0x00,0x01,0x07,0x00,0x08,0x0a},
+	{0x49,0x00,0x00,0x01,0x00,0x00,0x0a,0x0c},
+	{0x4a,0x00,0x00,0x01,0x00,0x00,0x0a,0x0c},
+	{0x4c,0x00,0x00,0x01,0x00,0x00,0x0b,0x0d},
+	{0x4d,0x00,0x00,0x01,0x00,0x00,0x0b,0x0d},
+	{0x50,0x00,0x00,0x01,0x04,0x00,0x05,0x07},
+	{0x51,0x00,0x00,0x01,0x07,0x00,0x07,0x09},
+	{0x52,0x00,0x00,0x01,0x00,0x00,0x09,0x0b},
+	{0x56,0x00,0x00,0x01,0x04,0x00,0x05,0x07},
+	{0x57,0x00,0x00,0x01,0x07,0x00,0x07,0x09},
+	{0x58,0x00,0x00,0x01,0x00,0x00,0x09,0x0b},
+	{0x59,0x00,0x00,0x01,0x04,0x00,0x05,0x05},
+	{0x5d,0x00,0x00,0x01,0x07,0x00,0x06,0x06},
+	{0x62,0x00,0x00,0x01,0x05,0x00,0x06,0x08},
+	{0x63,0x00,0x00,0x01,0x07,0x00,0x08,0x0a},
+	{0x64,0x00,0x00,0x01,0x00,0x00,0x0a,0x0c},
+	{0x65,0x00,0x00,0x01,0x00,0x00,0x0b,0x0d},
+	{0x6e,0x00,0x00,0x01,0x00,0x00,0x0b,0x0d},
+	{0x6f,0x00,0x00,0x01,0x00,0x00,0x0b,0x0d},
+	{0x7b,0x00,0x00,0x01,0x00,0x00,0x0b,0x0d}
 };
 /*end*/
 
 /* TW: The following table is (now) identical to BIOS */
 typedef struct _SiS300_CRT1TableStruct
 {
-UCHAR CR[17];
+	UCHAR CR[17];
 } SiS300_CRT1TableStruct;
+
 SiS300_CRT1TableStruct  SiS300_CRT1Table[]=
 { /* at 0x4014 in BIOS */
  {{0x2d,0x27,0x28,0x90,/*0x2b*/ 0x2c,0x80,0xbf,0x1f,  /* <--- was different to BIOS */
@@ -761,9 +756,9 @@
  {{0x09,0xc7,0xc7,0x8d,0xd3,0x0b,0xe0,0x10,  /* 36: 1600x1200x85Hz */
   0xb0,0x83,0xaf,0xaf,0xe1,0x2f,0x01,0x04,
   0x00}},
- {{0x3f,0xef,0xef,0x83,0xfd,0x1a,0xda,0x1f,
+ {{0x3f,0xef,0xef,0x83,0xfd,0x1a,0xda,0x1f,  /* 37: 1920x1440x60Hz */
   0xa0,0x84,0x9f,0x9f,0xdb,0x1f,0x01,0x01,
-  0x00}},
+  0x00}},  /* TW: TEST, should be 0x30? */
  {{0x55,0xff,0xff,0x99,0x0d,0x0c,0x3e,0xba,
   0x00,0x84,0xff,0xff,0x3f,0x0f,0x41,0x05,
   0x00}},
@@ -814,158 +809,167 @@
 
 typedef struct _SiS300_MCLKDataStruct
 {
-UCHAR SR28,SR29,SR2A;
-USHORT CLOCK;
+	UCHAR SR28,SR29,SR2A;
+	USHORT CLOCK;
 } SiS300_MCLKDataStruct;
+
 SiS300_MCLKDataStruct  SiS300_MCLKData[]=
 { /* TW: at 0x54 in BIOS */
- { 0x5a,0x64,0x80, 66},
- { 0xb3,0x45,0x80, 83},
- { 0x37,0x61,0x80,100},
- { 0x37,0x22,0x80,133},
- { 0x37,0x61,0x80,100},
- { 0x37,0x61,0x80,100},
- { 0x37,0x61,0x80,100},
- { 0x37,0x61,0x80,100}
+	{ 0x5a,0x64,0x80, 66},
+	{ 0xb3,0x45,0x80, 83},
+	{ 0x37,0x61,0x80,100},
+	{ 0x37,0x22,0x80,133},
+	{ 0x37,0x61,0x80,100},
+	{ 0x37,0x61,0x80,100},
+	{ 0x37,0x61,0x80,100},
+	{ 0x37,0x61,0x80,100}
 };
 
 typedef struct _SiS300_ECLKDataStruct
 {
-UCHAR SR2E,SR2F,SR30;
-USHORT CLOCK;
+	UCHAR SR2E,SR2F,SR30;
+	USHORT CLOCK;
 } SiS300_ECLKDataStruct;
+
 SiS300_ECLKDataStruct  SiS300_ECLKData[]=
 { /* TW: at 0x7c in BIOS */
- { 0x54,0x43,0x80,100},
- { 0x53,0x43,0x80,100},
- { 0x55,0x43,0x80,100},
- { 0x52,0x43,0x80,100},
- { 0x3f,0x42,0x80,100},
- { 0x54,0x43,0x80,100},
- { 0x54,0x43,0x80,100},
- { 0x54,0x43,0x80,100}
+	{ 0x54,0x43,0x80,100},
+	{ 0x53,0x43,0x80,100},
+	{ 0x55,0x43,0x80,100},
+	{ 0x52,0x43,0x80,100},
+	{ 0x3f,0x42,0x80,100},
+	{ 0x54,0x43,0x80,100},
+	{ 0x54,0x43,0x80,100},
+	{ 0x54,0x43,0x80,100}
 };
 
 typedef struct _SiS300_VCLKDataStruct
 {
-UCHAR SR2B,SR2C;
-USHORT CLOCK;
+	UCHAR SR2B,SR2C;
+	USHORT CLOCK;
 } SiS300_VCLKDataStruct;
+
 SiS300_VCLKDataStruct  SiS300_VCLKData[]=
 { /* TW: At 0x484e in BIOS */
- { 0x1b,0xe1, 25},
- { 0x4e,0xe4, 28},
- { 0x57,0xe4, 32},
- { 0xc3,0xc8, 36},
- { 0x42,0xc3, 40},
- { 0x5d,0xc4, 45},
- { 0x52,0x65, 50},
- { 0x53,0x65, 50},
- { 0x6d,0x66, 56},
- { 0x5a,0x64, 65},
- { 0x46,0x44, 68},
- { 0x3e,0x43, 75},
- { 0x6d,0x46, 76},
- { 0x41,0x43, 79},
- { 0x31,0x42, 79},
- { 0x46,0x25, 85},
- { 0x78,0x29, 87},
- { 0x62,0x44, 95},
- { 0x2b,0x22,105},
- { 0x49,0x24,106},
- { 0xc3,0x28,108},
- { 0x3c,0x23,109},
- { 0xf7,0x2c,132},
- { 0xd4,0x28,136},
- { 0x41,0x05,158},
- { 0x43,0x05,162},
- { 0xe1,0x0f,175},
- { 0xfc,0x12,189},
- { 0xde,0x26,194},
- { 0x54,0x05,203},
- { 0x3f,0x03,230},
- { 0x30,0x02,234},
- { 0x24,0x01,266},
- { 0x52,0x2a, 54},
- { 0x52,0x6a, 27},
- { 0x62,0x24, 70},
- { 0x62,0x64, 70},
- { 0xa8,0x4c, 30},
- { 0x20,0x26, 33},
- { 0x31,0xc2, 39},
- { 0xbf,0xc8, 35},
- { 0x60,0x36, 30},
- { 0x40,0x4a, 28},
- { 0x9f,0x46, 44},
- { 0x97,0x2c, 26},
- { 0x44,0xe4, 25},
- { 0x7e,0x32, 47},
- { 0x8a,0x24, 31},
- { 0x97,0x2c, 26},
- { 0xce,0x3c, 39},
- { 0x52,0x4a, 36},
- { 0x34,0x61, 95},
- { 0x78,0x27,108},
- { 0xce,0x25,189},  /* TW: This was missing */
- { 0xff,0x1b,6625}
+	{ 0x1b,0xe1, 25},
+	{ 0x4e,0xe4, 28},
+	{ 0x57,0xe4, 32},
+	{ 0xc3,0xc8, 36},
+	{ 0x42,0xc3, 40},
+	{ 0x5d,0xc4, 45},
+	{ 0x52,0x65, 50},
+	{ 0x53,0x65, 50},
+	{ 0x6d,0x66, 56},
+	{ 0x5a,0x64, 65},
+	{ 0x46,0x44, 68},
+	{ 0x3e,0x43, 75},
+	{ 0x6d,0x46, 76},
+	{ 0x41,0x43, 79},
+	{ 0x31,0x42, 79},
+	{ 0x46,0x25, 85},
+	{ 0x78,0x29, 87},
+	{ 0x62,0x44, 95},
+	{ 0x2b,0x22,105},
+	{ 0x49,0x24,106},
+	{ 0xc3,0x28,108},
+	{ 0x3c,0x23,109},
+	{ 0xf7,0x2c,132},
+	{ 0xd4,0x28,136},
+	{ 0x41,0x05,158},
+	{ 0x43,0x05,162},
+	{ 0xe1,0x0f,175},
+	{ 0xfc,0x12,189},
+	{ 0xde,0x26,194},
+	{ 0x54,0x05,203},
+	{ 0x3f,0x03,230},
+	{ 0x30,0x02,234},  /* 0x1f - 1920x1440 */
+	{ 0x24,0x01,266},  /* 0x20 - 2048x1536 */
+	{ 0x52,0x2a, 54},
+	{ 0x52,0x6a, 27},
+	{ 0x62,0x24, 70},
+	{ 0x62,0x64, 70},
+	{ 0xa8,0x4c, 30},
+	{ 0x20,0x26, 33},
+	{ 0x31,0xc2, 39},
+	{ 0xbf,0xc8, 35},  /* 0x28 - 1280x960 ??? that can't be right */
+	{ 0x60,0x36, 30},
+	{ 0x40,0x4a, 28},
+	{ 0x9f,0x46, 44},
+	{ 0x97,0x2c, 26},
+	{ 0x44,0xe4, 25},
+	{ 0x7e,0x32, 47},
+	{ 0x8a,0x24, 31},
+	{ 0x97,0x2c, 26},
+	{ 0xce,0x3c, 39},
+	{ 0x52,0x4a, 36},
+	{ 0x34,0x61, 95},
+	{ 0x78,0x27,108},
+	{ 0xce,0x25,189},  /* TW: This was missing */
+	{ 0xff,0x1b,6625}
 };
 
 /* TW: at 0x377d in BIOS */
-UCHAR SiS300_ScreenOffset[]={ 0x14,0x19,0x20,0x28,0x32,0x40,0x50,0x64,0x78,0x80,0x2d,0x35,0xff };
+UCHAR SiS300_ScreenOffset[]=
+{
+	0x14,0x19,0x20,0x28,0x32,0x40,0x50,
+        0x64,0x78,0x80,0x2d,0x35,0xff
+};
 
 typedef struct _SiS300_StResInfoStruct
 {
-USHORT HTotal;
-USHORT VTotal;
+	USHORT HTotal;
+	USHORT VTotal;
 } SiS300_StResInfoStruct;
+
 SiS300_StResInfoStruct  SiS300_StResInfo[]=
 {
- { 640,400},
- { 640,350},
- { 720,400},
- { 720,350},
- { 640,480}
+	{ 640,400},
+	{ 640,350},
+	{ 720,400},
+	{ 720,350},
+	{ 640,480}
 };
 
 typedef struct _SiS300_ModeResInfoStruct
 {
-USHORT HTotal;
-USHORT VTotal;
-UCHAR  XChar;
-UCHAR  YChar;
+	USHORT HTotal;
+	USHORT VTotal;
+	UCHAR  XChar;
+	UCHAR  YChar;
 } SiS300_ModeResInfoStruct;
+
 SiS300_ModeResInfoStruct  SiS300_ModeResInfo[]=
 { /* TW: At 0x5957 in BIOS */
- {  320, 200, 8, 8},
- {  320, 240, 8, 8},
- {  320, 400, 8, 8},
- {  400, 300, 8, 8},
- {  512, 384, 8, 8},
- {  640, 400, 8,16},
- {  640, 480, 8,16},
- {  800, 600, 8,16},
- { 1024, 768, 8,16},
- { 1280,1024, 8,16},
- { 1600,1200, 8,16},
- { 1920,1440, 8,16},
- { 2048,1536, 8,16},   /* TW: this was missing here, wasn't it? (not in BIOS) */
- {  720, 480, 8,16},   /*     (otherwise RESINFO index is wrong!) */
- {  720, 576, 8,16},
- { 1280, 960, 8,16}
+	{  320, 200, 8, 8},
+	{  320, 240, 8, 8},
+	{  320, 400, 8, 8},
+	{  400, 300, 8, 8},
+	{  512, 384, 8, 8},
+	{  640, 400, 8,16},
+	{  640, 480, 8,16},
+	{  800, 600, 8,16},
+	{ 1024, 768, 8,16},
+	{ 1280,1024, 8,16},
+	{ 1600,1200, 8,16},
+	{ 1920,1440, 8,16},
+	{ 2048,1536, 8,16},   /* TW: this was missing here, wasn't it? (not in BIOS) */
+	{  720, 480, 8,16},   /*     (otherwise RESINFO index is wrong!) */
+	{  720, 576, 8,16},
+	{ 1280, 960, 8,16}
 };
 
 UCHAR SiS300_OutputSelect =0x40;
 UCHAR SiS300_SoftSetting = 30;
 UCHAR SiS300_SR07=0x10;
 UCHAR SiS300_SR15[8][4]={
- {0x1,0x9,0xa3,0x0},
- {0x43,0x43,0x43,0x0},
- {0x1e,0x1e,0x1e,0x0},
- {0x2a,0x2a,0x2a,0x0},
- {0x6,0x6,0x6,0x0},
- {0x0,0x0,0x0,0x0},
- {0x0,0x0,0x0,0x0},
- {0x0,0x0,0x0,0x0}
+	{0x1,0x9,0xa3,0x0},
+	{0x43,0x43,0x43,0x0},
+	{0x1e,0x1e,0x1e,0x0},
+	{0x2a,0x2a,0x2a,0x0},
+	{0x6,0x6,0x6,0x0},
+	{0x0,0x0,0x0,0x0},
+	{0x0,0x0,0x0,0x0},
+	{0x0,0x0,0x0,0x0}
 };
 UCHAR SiS300_SR1F=0x0;
 UCHAR SiS300_SR21=0x16;
@@ -989,240 +993,245 @@
 
 UCHAR SiS300_CR40[5][4];
 UCHAR SiS300_CR49[2];
-UCHAR SiS300_NTSCPhase[] = {0x21,0xed,0x8a,0x8};
-UCHAR SiS300_PALPhase[] = {0x2a,0x5,0xd3,0x0};
+UCHAR SiS300_NTSCPhase[]  = {0x21,0xed,0x8a,0x08};
+UCHAR SiS300_PALPhase[]   = {0x2a,0x05,0xd3,0x00};
 UCHAR SiS300_NTSCPhase2[] = {0x21,0xF0,0x7B,0xD6};/*301b*/
-UCHAR SiS300_PALPhase2[] = {0x2a,0x09,0x86,0xe9};
-UCHAR SiS300_PALMPhase[] = {0x21,0xE4,0x2E,0x9B};   /*palmn*/
-UCHAR SiS300_PALNPhase[] = {0x21,0xF4,0x3E,0xBA};
+UCHAR SiS300_PALPhase2[]  = {0x2a,0x09,0x86,0xe9};
+UCHAR SiS300_PALMPhase[]  = {0x21,0xE4,0x2E,0x9B};   /*palmn*/
+UCHAR SiS300_PALNPhase[]  = {0x21,0xF4,0x3E,0xBA};
 
 typedef struct _SiS300_PanelDelayTblStruct
 {
-UCHAR timer[2];
+	UCHAR timer[2];
 } SiS300_PanelDelayTblStruct;
+
 SiS300_PanelDelayTblStruct SiS300_PanelDelayTbl[]=
 {
- {{0x05,0xaa}},
- {{0x05,0x14}},
- {{0x05,0x36}},
- {{0x05,0x14}},
- {{0x05,0x14}},
- {{0x05,0x14}},
- {{0x05,0x90}},
- {{0x05,0x90}},
- {{0x05,0x14}},
- {{0x05,0x14}},
- {{0x05,0x14}},
- {{0x05,0x14}},
- {{0x05,0x64}},
- {{0x05,0x14}},
- {{0x05,0x14}},
- {{0x05,0x14}}
+	{{0x05,0xaa}},
+	{{0x05,0x14}},
+	{{0x05,0x36}},
+	{{0x05,0x14}},
+	{{0x05,0x14}},
+	{{0x05,0x14}},
+	{{0x05,0x90}},
+	{{0x05,0x90}},
+	{{0x05,0x14}},
+	{{0x05,0x14}},
+	{{0x05,0x14}},
+	{{0x05,0x14}},
+	{{0x05,0x64}},
+	{{0x05,0x14}},
+	{{0x05,0x14}},
+	{{0x05,0x14}}
 };
 
 typedef struct _SiS300_LCDDataStruct
 {
-USHORT RVBHCMAX;
-USHORT RVBHCFACT;
-USHORT VGAHT;
-USHORT VGAVT;
-USHORT LCDHT;
-USHORT LCDVT;
+	USHORT RVBHCMAX;
+	USHORT RVBHCFACT;
+	USHORT VGAHT;
+	USHORT VGAVT;
+	USHORT LCDHT;
+	USHORT LCDVT;
 } SiS300_LCDDataStruct;
+
 SiS300_LCDDataStruct  SiS300_StLCD1024x768Data[]=
 {
- {   66,  31, 992, 510,1320, 816},
- {   66,  31, 992, 510,1320, 816},
- {  176,  75, 900, 510,1320, 816},
- {  176,  75, 900, 510,1320, 816},
- {   66,  31, 992, 510,1320, 816},
- {   27,  16,1024, 650,1350, 832},
- {    1,   1,1344, 806,1344, 806}
+	{   66,  31, 992, 510,1320, 816},
+	{   66,  31, 992, 510,1320, 816},
+	{  176,  75, 900, 510,1320, 816},
+	{  176,  75, 900, 510,1320, 816},
+	{   66,  31, 992, 510,1320, 816},
+	{   27,  16,1024, 650,1350, 832},
+	{    1,   1,1344, 806,1344, 806}
 };
 
 SiS300_LCDDataStruct  SiS300_ExtLCD1024x768Data[]=
 {
- {   12,   5, 896, 512,1344, 806},
- {   12,   5, 896, 510,1344, 806},
- {   32,  15,1008, 505,1344, 806},
- {   32,  15,1008, 514,1344, 806},
- {   12,   5, 896, 500,1344, 806},
- {   42,  25,1024, 625,1344, 806},
- {    1,   1,1344, 806,1344, 806},
- {   12,   5, 896, 500,1344, 806},
- {   42,  25,1024, 625,1344, 806},
- {    1,   1,1344, 806,1344, 806},
- {   12,   5, 896, 500,1344, 806},
- {   42,  25,1024, 625,1344, 806},
- {    1,   1,1344, 806,1344, 806}
+	{   12,   5, 896, 512,1344, 806},
+	{   12,   5, 896, 510,1344, 806},
+	{   32,  15,1008, 505,1344, 806},
+	{   32,  15,1008, 514,1344, 806},
+	{   12,   5, 896, 500,1344, 806},
+	{   42,  25,1024, 625,1344, 806},
+	{    1,   1,1344, 806,1344, 806},
+	{   12,   5, 896, 500,1344, 806},
+	{   42,  25,1024, 625,1344, 806},
+	{    1,   1,1344, 806,1344, 806},
+	{   12,   5, 896, 500,1344, 806},
+	{   42,  25,1024, 625,1344, 806},
+	{    1,   1,1344, 806,1344, 806}
 };
 
 SiS300_LCDDataStruct  SiS300_St2LCD1024x768Data[]=
 {
- {   62,  25, 800, 546,1344, 806},
- {   32,  15, 930, 546,1344, 806},
- {   32,  15, 930, 546,1344, 806},
- {  104,  45, 945, 496,1344, 806},
- {   62,  25, 800, 546,1344, 806},
- {   31,  18,1008, 624,1344, 806},
- {    1,   1,1344, 806,1344, 806}
+	{   62,  25, 800, 546,1344, 806},
+	{   32,  15, 930, 546,1344, 806},
+	{   32,  15, 930, 546,1344, 806},
+	{  104,  45, 945, 496,1344, 806},
+	{   62,  25, 800, 546,1344, 806},
+	{   31,  18,1008, 624,1344, 806},
+	{    1,   1,1344, 806,1344, 806}
 };
 
 SiS300_LCDDataStruct  SiS300_StLCD1280x1024Data[]=
 {
- {    4,   1, 880, 510,1650,1088},
- {    4,   1, 880, 510,1650,1088},
- {  176,  45, 900, 510,1650,1088},
- {  176,  45, 900, 510,1650,1088},
- {    4,   1, 880, 510,1650,1088},
- {   13,   5,1024, 675,1560,1152},
- {   16,   9,1266, 804,1688,1072},
- {    1,   1,1688,1066,1688,1066}
+	{    4,   1, 880, 510,1650,1088},
+	{    4,   1, 880, 510,1650,1088},
+	{  176,  45, 900, 510,1650,1088},
+	{  176,  45, 900, 510,1650,1088},
+	{    4,   1, 880, 510,1650,1088},
+	{   13,   5,1024, 675,1560,1152},
+	{   16,   9,1266, 804,1688,1072},
+	{    1,   1,1688,1066,1688,1066}
 };
 
 SiS300_LCDDataStruct  SiS300_ExtLCD1280x1024Data[]=
 {
- {  211,  60,1024, 501,1688,1066},
- {  211,  60,1024, 508,1688,1066},
- {  211,  60,1024, 501,1688,1066},
- {  211,  60,1024, 508,1688,1066},
- {  211,  60,1024, 500,1688,1066},
- {  211,  75,1024, 625,1688,1066},
- {  211, 120,1280, 798,1688,1066},
- {    1,   1,1688,1066,1688,1066}
+	{  211,  60,1024, 501,1688,1066},
+	{  211,  60,1024, 508,1688,1066},
+	{  211,  60,1024, 501,1688,1066},
+	{  211,  60,1024, 508,1688,1066},
+	{  211,  60,1024, 500,1688,1066},
+	{  211,  75,1024, 625,1688,1066},
+	{  211, 120,1280, 798,1688,1066},
+	{    1,   1,1688,1066,1688,1066}
 };
 
 SiS300_LCDDataStruct  SiS300_St2LCD1280x1024Data[]=
 {
- {   22,   5, 800, 510,1650,1088},
- {   22,   5, 800, 510,1650,1088},
- {  176,  45, 900, 510,1650,1088},
- {  176,  45, 900, 510,1650,1088},
- {   22,   5, 800, 510,1650,1088},
- {   13,   5,1024, 675,1560,1152},
- {   16,   9,1266, 804,1688,1072},
- {    1,   1,1688,1066,1688,1066}
+	{   22,   5, 800, 510,1650,1088},
+	{   22,   5, 800, 510,1650,1088},
+	{  176,  45, 900, 510,1650,1088},
+	{  176,  45, 900, 510,1650,1088},
+	{   22,   5, 800, 510,1650,1088},
+	{   13,   5,1024, 675,1560,1152},
+	{   16,   9,1266, 804,1688,1072},
+	{    1,   1,1688,1066,1688,1066}
 };
 
 SiS300_LCDDataStruct  SiS300_NoScaleData[]=
 {
- {    1,   1, 800, 449, 800, 449},
- {    1,   1, 800, 449, 800, 449},
- {    1,   1, 900, 449, 900, 449},
- {    1,   1, 900, 449, 900, 449},
- {    1,   1, 800, 525, 800, 525},
- {    1,   1,1056, 628,1056, 628},
- {    1,   1,1344, 806,1344, 806},
- {    1,   1,1688,1066,1688,1066}
+	{    1,   1, 800, 449, 800, 449},
+	{    1,   1, 800, 449, 800, 449},
+	{    1,   1, 900, 449, 900, 449},
+	{    1,   1, 900, 449, 900, 449},
+	{    1,   1, 800, 525, 800, 525},
+	{    1,   1,1056, 628,1056, 628},
+	{    1,   1,1344, 806,1344, 806},
+	{    1,   1,1688,1066,1688,1066}
 };
 
 SiS300_LCDDataStruct  SiS300_LCD1280x960Data[]=
 {
- {    9,   2, 800, 500,1800,1000},
- {    9,   2, 800, 500,1800,1000},
- {    4,   1, 900, 500,1800,1000},
- {    4,   1, 900, 500,1800,1000},
- {    9,   2, 800, 500,1800,1000},
- {   30,  11,1056, 625,1800,1000},
- {    5,   3,1350, 800,1800,1000},
- {    1,   1,1576,1050,1576,1050},
- {    1,   1,1800,1000,1800,1000}
+	{    9,   2, 800, 500,1800,1000},
+	{    9,   2, 800, 500,1800,1000},
+	{    4,   1, 900, 500,1800,1000},
+	{    4,   1, 900, 500,1800,1000},
+	{    9,   2, 800, 500,1800,1000},
+	{   30,  11,1056, 625,1800,1000},
+	{    5,   3,1350, 800,1800,1000},
+	{    1,   1,1576,1050,1576,1050},
+	{    1,   1,1800,1000,1800,1000}
 };
 
 typedef struct _SiS300_TVDataStruct
 {
-USHORT RVBHCMAX;
-USHORT RVBHCFACT;
-USHORT VGAHT;
-USHORT VGAVT;
-USHORT TVHDE;
-USHORT TVVDE;
-USHORT RVBHRS;
-UCHAR FlickerMode;
-USHORT HALFRVBHRS;
-UCHAR RY1COE;
-UCHAR RY2COE;
-UCHAR RY3COE;
-UCHAR RY4COE;
+	USHORT RVBHCMAX;
+	USHORT RVBHCFACT;
+	USHORT VGAHT;
+	USHORT VGAVT;
+	USHORT TVHDE;
+	USHORT TVVDE;
+	USHORT RVBHRS;
+	UCHAR FlickerMode;
+	USHORT HALFRVBHRS;
+	UCHAR RY1COE;
+	UCHAR RY2COE;
+	UCHAR RY3COE;
+	UCHAR RY4COE;
 } SiS300_TVDataStruct;
+
 SiS300_TVDataStruct  SiS300_StPALData[]=
 {
- {    1,   1, 864, 525,1270, 400, 100,   0, 760,0xf4,0xff,0x1c,0x22},
- {    1,   1, 864, 525,1270, 350, 100,   0, 760,0xf4,0xff,0x1c,0x22},
- {    1,   1, 864, 525,1270, 400,   0,   0, 720,0xf1,0x04,0x1f,0x18},
- {    1,   1, 864, 525,1270, 350,   0,   0, 720,0xf4,0x0b,0x1c,0x0a},
- {    1,   1, 864, 525,1270, 480,  50,   0, 760,0xf4,0xff,0x1c,0x22},
- {    1,   1, 864, 525,1270, 600,  50,   0,   0,0xf4,0xff,0x1c,0x22}
+	{    1,   1, 864, 525,1270, 400, 100,   0, 760,0xf4,0xff,0x1c,0x22},
+	{    1,   1, 864, 525,1270, 350, 100,   0, 760,0xf4,0xff,0x1c,0x22},
+	{    1,   1, 864, 525,1270, 400,   0,   0, 720,0xf1,0x04,0x1f,0x18},
+	{    1,   1, 864, 525,1270, 350,   0,   0, 720,0xf4,0x0b,0x1c,0x0a},
+	{    1,   1, 864, 525,1270, 480,  50,   0, 760,0xf4,0xff,0x1c,0x22},
+	{    1,   1, 864, 525,1270, 600,  50,   0,   0,0xf4,0xff,0x1c,0x22}
 };
 
 SiS300_TVDataStruct  SiS300_ExtPALData[]=
 {
- {   27,  10, 848, 448,1270, 530,  50,   0,  50,0xf4,0xff,0x1c,0x22},
- {  108,  35, 848, 398,1270, 530,  50,   0,  50,0xf4,0xff,0x1c,0x22},
- {   12,   5, 954, 448,1270, 530,  50,   0,  50,0xf1,0x04,0x1f,0x18},
- {    9,   4, 960, 463,1644, 438,  50,   0,  50,0xf4,0x0b,0x1c,0x0a},
- {    9,   4, 848, 528,1270, 530,   0,   0,  50,0xf5,0xfb,0x1b,0x2a},
- {   36,  25,1060, 648,1316, 530, 438,   0, 438,0xeb,0x05,0x25,0x16},
- {    3,   2,1080, 619,1270, 540, 438,   0, 438,0xf3,0x00,0x1d,0x20},
- {    1,   1,1170, 821,1270, 520, 686,   0, 686,0xF3,0x00,0x1D,0x20}     /*301b*/
+	{   27,  10, 848, 448,1270, 530,  50,   0,  50,0xf4,0xff,0x1c,0x22},
+	{  108,  35, 848, 398,1270, 530,  50,   0,  50,0xf4,0xff,0x1c,0x22},
+	{   12,   5, 954, 448,1270, 530,  50,   0,  50,0xf1,0x04,0x1f,0x18},
+	{    9,   4, 960, 463,1644, 438,  50,   0,  50,0xf4,0x0b,0x1c,0x0a},
+	{    9,   4, 848, 528,1270, 530,   0,   0,  50,0xf5,0xfb,0x1b,0x2a},
+	{   36,  25,1060, 648,1316, 530, 438,   0, 438,0xeb,0x05,0x25,0x16},
+	{    3,   2,1080, 619,1270, 540, 438,   0, 438,0xf3,0x00,0x1d,0x20},
+	{    1,   1,1170, 821,1270, 520, 686,   0, 686,0xF3,0x00,0x1D,0x20}     /*301b*/
 
 };
 
 SiS300_TVDataStruct  SiS300_StNTSCData[]=
 {
- {    1,   1, 858, 525,1270, 400,  50,   0, 760,0xf1,0x04,0x1f,0x18},
- {    1,   1, 858, 525,1270, 350,  50,   0, 640,0xf1,0x04,0x1f,0x18},
- {    1,   1, 858, 525,1270, 400,   0,   0, 720,0xf1,0x04,0x1f,0x18},
- {    1,   1, 858, 525,1270, 350,   0,   0, 720,0xf4,0x0b,0x1c,0x0a},
- {    1,   1, 858, 525,1270, 480,   0,   0, 760,0xf1,0x04,0x1f,0x18}
+	{    1,   1, 858, 525,1270, 400,  50,   0, 760,0xf1,0x04,0x1f,0x18},
+	{    1,   1, 858, 525,1270, 350,  50,   0, 640,0xf1,0x04,0x1f,0x18},
+	{    1,   1, 858, 525,1270, 400,   0,   0, 720,0xf1,0x04,0x1f,0x18},
+	{    1,   1, 858, 525,1270, 350,   0,   0, 720,0xf4,0x0b,0x1c,0x0a},
+	{    1,   1, 858, 525,1270, 480,   0,   0, 760,0xf1,0x04,0x1f,0x18}
 };
 
 SiS300_TVDataStruct  SiS300_ExtNTSCData[]=
 {
- {  143,  65, 858, 443,1270, 440, 171,   0, 171,0xf1,0x04,0x1f,0x18},
- {   88,  35, 858, 393,1270, 440, 171,   0, 171,0xf1,0x04,0x1f,0x18},
- {  143,  70, 924, 443,1270, 440,  92,   0,  92,0xf1,0x04,0x1f,0x18},
- {  143,  70, 924, 393,1270, 440,  92,   0,  92,0xf4,0x0b,0x1c,0x0a},
- {  143,  76, 836, 523,1270, 440, 224,   0,   0,0xf1,0x05,0x1f,0x16},
- {  143, 120,1056, 643,1270, 440,   0, 128,   0,0xf4,0x10,0x1c,0x00},
- {  143,  76, 836, 523,1270, 440,   0, 128,   0,0xee,0x0c,0x22,0x08},
- {   65,  64,1056, 791,1270, 480, 638,   0,   0,0xf1,0x04,0x1f,0x18} /*301b*/     
+	{  143,  65, 858, 443,1270, 440, 171,   0, 171,0xf1,0x04,0x1f,0x18},
+	{   88,  35, 858, 393,1270, 440, 171,   0, 171,0xf1,0x04,0x1f,0x18},
+	{  143,  70, 924, 443,1270, 440,  92,   0,  92,0xf1,0x04,0x1f,0x18},
+	{  143,  70, 924, 393,1270, 440,  92,   0,  92,0xf4,0x0b,0x1c,0x0a},
+	{  143,  76, 836, 523,1270, 440, 224,   0,   0,0xf1,0x05,0x1f,0x16},
+	{  143, 120,1056, 643,1270, 440,   0, 128,   0,0xf4,0x10,0x1c,0x00},
+	{  143,  76, 836, 523,1270, 440,   0, 128,   0,0xee,0x0c,0x22,0x08},
+	{   65,  64,1056, 791,1270, 480, 638,   0,   0,0xf1,0x04,0x1f,0x18} /*301b*/
 };
 
 SiS_TVDataStruct  SiS300_St1HiTVData[]=
 {
- {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}
+ 	{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}
 };
 
 SiS_TVDataStruct  SiS300_St2HiTVData[]=
 {
- {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}
+ 	{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}
 };
 
 SiS_TVDataStruct  SiS300_ExtHiTVData[]=
 {
- {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}
+ 	{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}
 };
 
 UCHAR SiS300_NTSCTiming[] = {
-  0x17,0x1d,0x03,0x09,0x05,0x06,0x0c,0x0c,
-  0x94,0x49,0x01,0x0a,0x06,0x0d,0x04,0x0a,
-  0x06,0x14,0x0d,0x04,0x0a,0x00,0x85,0x1b,
-  0x0c,0x50,0x00,0x97,0x00,0xda,0x4a,0x17,
-  0x7d,0x05,0x4b,0x00,0x00,0xe2,0x00,0x02,
-  0x03,0x0a,0x65,0x9d,0x08,0x92,0x8f,0x40,
-  0x60,0x80,0x14,0x90,0x8c,0x60,0x14,0x50,
-  0x00,0x40,0x44,0x00,0xdb,0x02,0x3b,0x00};
+	0x17,0x1d,0x03,0x09,0x05,0x06,0x0c,0x0c,
+	0x94,0x49,0x01,0x0a,0x06,0x0d,0x04,0x0a,
+	0x06,0x14,0x0d,0x04,0x0a,0x00,0x85,0x1b,
+	0x0c,0x50,0x00,0x97,0x00,0xda,0x4a,0x17,
+	0x7d,0x05,0x4b,0x00,0x00,0xe2,0x00,0x02,
+	0x03,0x0a,0x65,0x9d,0x08,0x92,0x8f,0x40,
+	0x60,0x80,0x14,0x90,0x8c,0x60,0x14,0x50,
+	0x00,0x40,0x44,0x00,0xdb,0x02,0x3b,0x00
+};
 
 UCHAR SiS300_PALTiming[] = {
-  0x19,0x52,0x35,0x6e,0x04,0x38,0x3d,0x70,
-  0x94,0x49,0x01,0x12,0x06,0x3e,0x35,0x6d,
-  0x06,0x14,0x3e,0x35,0x6d,0x00,0x45,0x2b,
-  0x70,0x50,0x00,0x9b,0x00,0xd9,0x5d,0x17,
-  0x7d,0x05,0x45,0x00,0x00,0xe8,0x00,0x02,
-  0x0d,0x00,0x68,0xb0,0x0b,0x92,0x8f,0x40,
-  0x60,0x80,0x14,0x90,0x8c,0x60,0x14,0x63,
-  0x00,0x40,0x3e,0x00,0xe1,0x02,0x28,0x00};
+	0x19,0x52,0x35,0x6e,0x04,0x38,0x3d,0x70,
+	0x94,0x49,0x01,0x12,0x06,0x3e,0x35,0x6d,
+	0x06,0x14,0x3e,0x35,0x6d,0x00,0x45,0x2b,
+	0x70,0x50,0x00,0x9b,0x00,0xd9,0x5d,0x17,
+	0x7d,0x05,0x45,0x00,0x00,0xe8,0x00,0x02,
+	0x0d,0x00,0x68,0xb0,0x0b,0x92,0x8f,0x40,
+	0x60,0x80,0x14,0x90,0x8c,0x60,0x14,0x63,
+	0x00,0x40,0x3e,0x00,0xe1,0x02,0x28,0x00
+};
 
 UCHAR SiS300_HiTVExtTiming[] = {0x00};
 
@@ -1240,1054 +1249,1074 @@
 
 typedef struct _SiS300_LVDSDataStruct
 {
-USHORT VGAHT;
-USHORT VGAVT;
-USHORT LCDHT;
-USHORT LCDVT;
+	USHORT VGAHT;
+	USHORT VGAVT;
+	USHORT LCDHT;
+	USHORT LCDVT;
 } SiS300_LVDSDataStruct;
+
 SiS300_LVDSDataStruct  SiS300_LVDS800x600Data_1[]=
 {
- {848, 433,1060, 629},
- {848, 389,1060, 629},
- {848, 433,1060, 629},
- {848, 389,1060, 629},
- {848, 518,1060, 629},
- {1056, 628,1056, 628},
- {1056, 628,1056, 628},
- {800, 449,1000, 644},
- {800, 525,1000, 635}
+	{848, 433,1060, 629},
+	{848, 389,1060, 629},
+	{848, 433,1060, 629},
+	{848, 389,1060, 629},
+	{848, 518,1060, 629},
+	{1056, 628,1056, 628},
+	{1056, 628,1056, 628},
+	{800, 449,1000, 644},
+	{800, 525,1000, 635}
 };
 
 SiS300_LVDSDataStruct  SiS300_LVDS800x600Data_2[]=
 {
- {1056, 628,1056, 628},
- {1056, 628,1056, 628},
- {1056, 628,1056, 628},
- {1056, 628,1056, 628},
- {1056, 628,1056, 628},
- {1056, 628,1056, 628},
- {1056, 628,1056, 628},
- {800, 449,1000, 644},
- {800, 525,1000, 635}
+	{1056, 628,1056, 628},
+	{1056, 628,1056, 628},
+	{1056, 628,1056, 628},
+	{1056, 628,1056, 628},
+	{1056, 628,1056, 628},
+	{1056, 628,1056, 628},
+	{1056, 628,1056, 628},
+	{800, 449,1000, 644},
+	{800, 525,1000, 635}
 };
 
 SiS300_LVDSDataStruct  SiS300_LVDS1024x768Data_1[]=
 {
- {840, 438,1344, 806},
- {840, 409,1344, 806},
- {840, 438,1344, 806},
- {840, 409,1344, 806},
- {840, 518,1344, 806},
- {1050, 638,1344, 806},
- {1344, 806,1344, 806},
- {800, 449,1280, 801},
- {800, 525,1280, 813}
+	{840, 438,1344, 806},
+	{840, 409,1344, 806},
+	{840, 438,1344, 806},
+	{840, 409,1344, 806},
+	{840, 518,1344, 806},
+	{1050, 638,1344, 806},
+	{1344, 806,1344, 806},
+	{800, 449,1280, 801},
+	{800, 525,1280, 813}
 };
 
 SiS300_LVDSDataStruct  SiS300_LVDS1024x768Data_2[]=
 {
- {1344, 806,1344, 806},
- {1344, 806,1344, 806},
- {1344, 806,1344, 806},
- {1344, 806,1344, 806},
- {1344, 806,1344, 806},
- {1344, 806,1344, 806},
- {1344, 806,1344, 806},
- {800, 449,1280, 801},
- {800, 525,1280, 813}
+	{1344, 806,1344, 806},
+	{1344, 806,1344, 806},
+	{1344, 806,1344, 806},
+	{1344, 806,1344, 806},
+	{1344, 806,1344, 806},
+	{1344, 806,1344, 806},
+	{1344, 806,1344, 806},
+	{800, 449,1280, 801},
+	{800, 525,1280, 813}
 };
 
 SiS300_LVDSDataStruct  SiS300_LVDS1280x1024Data_1[]=
 {
- {840, 438,1344, 806},
- {840, 409,1344, 806},
- {840, 438,1344, 806},
- {840, 409,1344, 806},
- {840, 518,1344, 806},
- {1050, 638,1344, 806},
- {1344, 806,1344, 806},
- {800, 449,1280, 801},
- {800, 525,1280, 813}
+	{840, 438,1344, 806},
+	{840, 409,1344, 806},
+	{840, 438,1344, 806},
+	{840, 409,1344, 806},
+	{840, 518,1344, 806},
+	{1050, 638,1344, 806},
+	{1344, 806,1344, 806},
+	{800, 449,1280, 801},
+	{800, 525,1280, 813}
 };
 
 SiS300_LVDSDataStruct  SiS300_LVDS1280x1024Data_2[]=
 {
- {1344, 806,1344, 806},
- {1344, 806,1344, 806},
- {1344, 806,1344, 806},
- {1344, 806,1344, 806},
- {1344, 806,1344, 806},
- {1344, 806,1344, 806},
- {1344, 806,1344, 806},
- {800, 449,1280, 801},
- {800, 525,1280, 813}
+	{1344, 806,1344, 806},
+	{1344, 806,1344, 806},
+	{1344, 806,1344, 806},
+	{1344, 806,1344, 806},
+	{1344, 806,1344, 806},
+	{1344, 806,1344, 806},
+	{1344, 806,1344, 806},
+	{800, 449,1280, 801},
+	{800, 525,1280, 813}
 };
 
 SiS300_LVDSDataStruct  SiS300_LVDS640x480Data_1[]=
 {
- {800, 449, 800, 449},
- {800, 449, 800, 449},
- {800, 449, 800, 449},
- {800, 449, 800, 449},
- {800, 525, 800, 525},
- {1056, 628,1056, 628},
- {1056, 628,1056, 628},
- {1056, 628,1056, 628},
- {1056, 628,1056, 628}
+	{800, 449, 800, 449},
+	{800, 449, 800, 449},
+	{800, 449, 800, 449},
+	{800, 449, 800, 449},
+	{800, 525, 800, 525},
+	{1056, 628,1056, 628},
+	{1056, 628,1056, 628},
+	{1056, 628,1056, 628},
+	{1056, 628,1056, 628}
 };
 
+/* TW: New: */
 SiS300_LVDSDataStruct  SiS300_CHTVUNTSCData[]=
 {
- {840, 600, 840, 600},
- {840, 600, 840, 600},
- {840, 600, 840, 600},
- {840, 600, 840, 600},
- {784, 600, 784, 600},
- {1064, 750,1064, 750}
+	{840, 600, 840, 600},
+	{840, 600, 840, 600},
+	{840, 600, 840, 600},
+	{840, 600, 840, 600},
+	{784, 600, 784, 600},
+	{1064, 750,1064, 750}
 };
 
 SiS300_LVDSDataStruct  SiS300_CHTVONTSCData[]=
 {
- {840, 525, 840, 525},
- {840, 525, 840, 525},
- {840, 525, 840, 525},
- {840, 525, 840, 525},
- {784, 525, 784, 525},
- {1040, 700,1040, 700}
+	{840, 525, 840, 525},
+	{840, 525, 840, 525},
+	{840, 525, 840, 525},
+	{840, 525, 840, 525},
+	{784, 525, 784, 525},
+	{1040, 700,1040, 700}
 };
 
 SiS300_LVDSDataStruct  SiS300_CHTVUPALData[]=
 {
- {1008, 625,1008, 625},
- {1008, 625,1008, 625},
- {1008, 625,1008, 625},
- {1008, 625,1008, 625},
- {840, 750, 840, 750},
- {936, 836, 936, 836}
+	{1008, 625,1008, 625},
+	{1008, 625,1008, 625},
+	{1008, 625,1008, 625},
+	{1008, 625,1008, 625},
+	{840, 750, 840, 750},
+	{936, 836, 936, 836}
 };
 
 SiS300_LVDSDataStruct  SiS300_CHTVOPALData[]=
 {
- {1008, 625,1008, 625},
- {1008, 625,1008, 625},
- {1008, 625,1008, 625},
- {1008, 625,1008, 625},
- {840, 625, 840, 625},
- {960, 750, 960, 750}
+	{1008, 625,1008, 625},
+	{1008, 625,1008, 625},
+	{1008, 625,1008, 625},
+	{1008, 625,1008, 625},
+	{840, 625, 840, 625},
+	{960, 750, 960, 750}
 };
+/* TW: new end */
 
 typedef struct _SiS300_LVDSDesStruct
 {
-USHORT LCDHDES;
-USHORT LCDVDES;
+	USHORT LCDHDES;
+	USHORT LCDVDES;
 } SiS300_LVDSDesStruct;
+
 SiS300_LVDSDesStruct  SiS300_PanelType00_1[]=
 {
- {0, 626},
- {0, 624},
- {0, 626},
- {0, 624},
- {0, 624},
- { 0, 627},
- { 0, 627},
- { 0,   0},
- { 0,   0}
+	{0, 626},
+	{0, 624},
+	{0, 626},
+	{0, 624},
+	{0, 624},
+	{ 0, 627},
+	{ 0, 627},
+	{ 0,   0},
+	{ 0,   0}
 };
 
 SiS300_LVDSDesStruct  SiS300_PanelType01_1[]=
 {
- {1343, 798},
- {1343, 794},
- {1343, 798},
- {1343, 794},
- {1343,   0},
- {1343,   0},
- { 0, 805},
- { 0, 794},
- { 0,   0}
+	{1343, 798},
+	{1343, 794},
+	{1343, 798},
+	{1343, 794},
+	{1343,   0},
+	{1343,   0},
+	{ 0, 805},
+	{ 0, 794},
+	{ 0,   0}
 };
 
 SiS300_LVDSDesStruct  SiS300_PanelType02_1[]=
 {
- {0, 626},
- {0, 624},
- {0, 626},
- {0, 624},
- {0, 624},
- { 0, 627},
- { 0, 627},
- { 0,   0},
- { 0,   0}
+	{0, 626},
+	{0, 624},
+	{0, 626},
+	{0, 624},
+	{0, 624},
+	{ 0, 627},
+	{ 0, 627},
+	{ 0,   0},
+	{ 0,   0}
 };
 
 SiS300_LVDSDesStruct  SiS300_PanelType03_1[]=
 {
- { 8, 436},
- { 8, 440},
- { 8, 436},
- { 8, 440},
- { 8, 512},
- {1343, 798},
- {1343, 794},
- {1343, 798},
- {1343, 794}
+	{ 8, 436},
+	{ 8, 440},
+	{ 8, 436},
+	{ 8, 440},
+	{ 8, 512},
+	{1343, 798},
+	{1343, 794},
+	{1343, 798},
+	{1343, 794}
 };
 
 SiS300_LVDSDesStruct  SiS300_PanelType04_1[]=
 {
- {1343, 798},
- {1343, 794},
- {1343, 798},
- {1343, 794},
- {1343,   0},
- {1343,   0},
- { 0, 805},
- { 0, 794},
- { 0,   0}
+	{1343, 798},
+	{1343, 794},
+	{1343, 798},
+	{1343, 794},
+	{1343,   0},
+	{1343,   0},
+	{ 0, 805},
+	{ 0, 794},
+	{ 0,   0}
 };
 
 SiS300_LVDSDesStruct  SiS300_PanelType05_1[]=
 {
- {1343, 798},
- {1343, 794},
- {1343, 798},
- {1343, 794},
- {1343,   0},
- {1343,   0},
- { 0, 805},
- { 0, 794},
- { 0,   0}
+	{1343, 798},
+	{1343, 794},
+	{1343, 798},
+	{1343, 794},
+	{1343,   0},
+	{1343,   0},
+	{ 0, 805},
+	{ 0, 794},
+	{ 0,   0}
 };
 
 SiS300_LVDSDesStruct  SiS300_PanelType06_1[]=
 {
- {1343, 798},
- {1343, 794},
- {1343, 798},
- {1343, 794},
- {1343,   0},
- {1343,   0},
- { 0, 805},
- { 0, 794},
- { 0,   0}
+	{1343, 798},
+	{1343, 794},
+	{1343, 798},
+	{1343, 794},
+	{1343,   0},
+	{1343,   0},
+	{ 0, 805},
+	{ 0, 794},
+	{ 0,   0}
 };
 
 SiS300_LVDSDesStruct  SiS300_PanelType07_1[]=
 {
- {1343, 798},
- {1343, 794},
- {1343, 798},
- {1343, 794},
- {1343,   0},
- {1343,   0},
- { 0, 805},
- { 0, 794},
- { 0,   0}
+	{1343, 798},
+	{1343, 794},
+	{1343, 798},
+	{1343, 794},
+	{1343,   0},
+	{1343,   0},
+	{ 0, 805},
+	{ 0, 794},
+	{ 0,   0}
 };
 
 SiS300_LVDSDesStruct  SiS300_PanelType08_1[]=
 {
- {1059, 626},
- {1059, 624},
- {1059, 626},
- {1059, 624},
- {1059, 624},
- { 0, 627},
- { 0, 627},
- { 0,   0},
- { 0,   0}
+	{1059, 626},
+	{1059, 624},
+	{1059, 626},
+	{1059, 624},
+	{1059, 624},
+	{ 0, 627},
+	{ 0, 627},
+	{ 0,   0},
+	{ 0,   0}
 };
 
 SiS300_LVDSDesStruct  SiS300_PanelType09_1[]=
 {
- {1343, 798},
- {1343, 794},
- {1343, 798},
- {1343, 794},
- {1343,   0},
- {1343,   0},
- { 0, 805},
- { 0, 794},
- { 0,   0}
+	{1343, 798},
+	{1343, 794},
+	{1343, 798},
+	{1343, 794},
+	{1343,   0},
+	{1343,   0},
+	{ 0, 805},
+	{ 0, 794},
+	{ 0,   0}
 };
 
 SiS300_LVDSDesStruct  SiS300_PanelType0a_1[]=
 {
- {1059, 626},
- {1059, 624},
- {1059, 626},
- {1059, 624},
- {1059, 624},
- { 0, 627},
- { 0, 627},
- { 0,   0},
- { 0,   0}
+	{1059, 626},
+	{1059, 624},
+	{1059, 626},
+	{1059, 624},
+	{1059, 624},
+	{ 0, 627},
+	{ 0, 627},
+	{ 0,   0},
+	{ 0,   0}
 };
 
 SiS300_LVDSDesStruct  SiS300_PanelType0b_1[]=
 {
- {1343, 798},
- {1343, 794},
- {1343, 798},
- {1343, 794},
- {1343,   0},
- {1343,   0},
- { 0, 805},
- { 0, 794},
- { 0,   0}
+	{1343, 798},
+	{1343, 794},
+	{1343, 798},
+	{1343, 794},
+	{1343,   0},
+	{1343,   0},
+	{ 0, 805},
+	{ 0, 794},
+	{ 0,   0}
 };
 
 SiS300_LVDSDesStruct  SiS300_PanelType0c_1[]=
 {
- {1343, 798},
- {1343, 794},
- {1343, 798},
- {1343, 794},
- {1343,   0},
- {1343,   0},
- { 0, 805},
- { 0, 794},
- { 0,   0}
+	{1343, 798},
+	{1343, 794},
+	{1343, 798},
+	{1343, 794},
+	{1343,   0},
+	{1343,   0},
+	{ 0, 805},
+	{ 0, 794},
+	{ 0,   0}
 };
 
 SiS300_LVDSDesStruct  SiS300_PanelType0d_1[]=
 {
- {1343, 798},
- {1343, 794},
- {1343, 798},
- {1343, 794},
- {1343,   0},
- {1343,   0},
- { 0, 805},
- { 0, 794},
- { 0,   0}
+	{1343, 798},
+	{1343, 794},
+	{1343, 798},
+	{1343, 794},
+	{1343,   0},
+	{1343,   0},
+	{ 0, 805},
+	{ 0, 794},
+	{ 0,   0}
 };
 
 SiS300_LVDSDesStruct  SiS300_PanelType0e_1[]=
 {
- {1343, 798},
- {1343, 794},
- {1343, 798},
- {1343, 794},
- {1343,   0},
- {1343,   0},
- { 0, 805},
- { 0, 794},
- { 0,   0}
+	{1343, 798},
+	{1343, 794},
+	{1343, 798},
+	{1343, 794},
+	{1343,   0},
+	{1343,   0},
+	{ 0, 805},
+	{ 0, 794},
+	{ 0,   0}
 };
 
 SiS300_LVDSDesStruct  SiS300_PanelType0f_1[]=
 {
-{1343, 798},
- {1343, 794},
- {1343, 798},
- {1343, 794},
- {1343,   0},
- {1343,   0},
- { 0, 805},
- { 0, 794},
- { 0,   0}
+	{1343, 798},
+	{1343, 794},
+	{1343, 798},
+	{1343, 794},
+	{1343,   0},
+	{1343,   0},
+	{ 0, 805},
+	{ 0, 794},
+	{ 0,   0}
 };
 
 SiS300_LVDSDesStruct  SiS300_PanelType00_2[]=
 {
- {976, 527},
- {976, 502},
- {976, 527},
- {976, 502},
- {976, 567},
- { 0, 627},
- { 0, 627},
- { 0,   0},
- { 0,   0}
+	{976, 527},
+	{976, 502},
+	{976, 527},
+	{976, 502},
+	{976, 567},
+	{ 0, 627},
+	{ 0, 627},
+	{ 0,   0},
+	{ 0,   0}
 };
 
 SiS300_LVDSDesStruct  SiS300_PanelType01_2[]=
 {
- {1152, 622},
- {1152, 597},
- {1152, 622},
- {1152, 597},
- {1152, 662},
- {1232, 722},
- { 0, 805},
- { 0, 794},
- { 0,   0}
+	{1152, 622},
+	{1152, 597},
+	{1152, 622},
+	{1152, 597},
+	{1152, 662},
+	{1232, 722},
+	{ 0, 805},
+	{ 0, 794},
+	{ 0,   0}
 };
 
 SiS300_LVDSDesStruct  SiS300_PanelType02_2[]=
 {
- {976, 527},
- {976, 502},
- {976, 527},
- {976, 502},
- {976, 567},
- { 0, 627},
- { 0, 627},
- { 0,   0},
- { 0,   0}
+	{976, 527},
+	{976, 502},
+	{976, 527},
+	{976, 502},
+	{976, 567},
+	{ 0, 627},
+	{ 0, 627},
+	{ 0,   0},
+	{ 0,   0}
 };
 
 SiS300_LVDSDesStruct  SiS300_PanelType03_2[]=
 {
- {1152, 622},
- {1152, 597},
- {1152, 622},
- {1152, 597},
- {1152, 662},
- {1232, 722},
- {   0, 805},
- {1152, 622},
- {1152, 597}
+	{1152, 622},
+	{1152, 597},
+	{1152, 622},
+	{1152, 597},
+	{1152, 662},
+	{1232, 722},
+	{   0, 805},
+	{1152, 622},
+	{1152, 597}
 };
 
 SiS300_LVDSDesStruct  SiS300_PanelType04_2[]=
 {
- {1152, 622},
- {1152, 597},
- {1152, 622},
- {1152, 597},
- {1152, 662},
- {1232, 722},
- {   0, 805},
- {   0, 794},
- {   0,   0}
+	{1152, 622},
+	{1152, 597},
+	{1152, 622},
+	{1152, 597},
+	{1152, 662},
+	{1232, 722},
+	{   0, 805},
+	{   0, 794},
+	{   0,   0}
 };
 
 SiS300_LVDSDesStruct  SiS300_PanelType05_2[]=
 {
- {1152, 622},
- {1152, 597},
- {1152, 622},
- {1152, 597},
- {1152, 662},
- {1232, 722},
- {   0, 805},
- {   0, 794},
- {   0,   0}
+	{1152, 622},
+	{1152, 597},
+	{1152, 622},
+	{1152, 597},
+	{1152, 662},
+	{1232, 722},
+	{   0, 805},
+	{   0, 794},
+	{   0,   0}
 };
 
 SiS300_LVDSDesStruct  SiS300_PanelType06_2[]=
 {
- {1152, 622},
- {1152, 597},
- {1152, 622},
- {1152, 597},
- {1152, 662},
- {1232, 722},
- {   0, 805},
- {   0, 794},
- {   0,   0}
+	{1152, 622},
+	{1152, 597},
+	{1152, 622},
+	{1152, 597},
+	{1152, 662},
+	{1232, 722},
+	{   0, 805},
+	{   0, 794},
+	{   0,   0}
 };
 
 SiS300_LVDSDesStruct  SiS300_PanelType07_2[]=
 {
- {1152, 622},
- {1152, 597},
- {1152, 622},
- {1152, 597},
- {1152, 662},
- {1232, 722},
- {   0, 805},
- {   0, 794},
- {   0,   0}
+ 	{1152, 622},
+ 	{1152, 597},
+ 	{1152, 622},
+ 	{1152, 597},
+ 	{1152, 662},
+ 	{1232, 722},
+	{   0, 805},
+	{   0, 794},
+	{   0,   0}
 };
 
 SiS300_LVDSDesStruct  SiS300_PanelType08_2[]=
 {
- {976, 527},
- {976, 502},
- {976, 527},
- {976, 502},
- {976, 567},
- {  0, 627},
- {  0, 627},
- {  0,   0},
- {  0,   0}
+ 	{976, 527},
+ 	{976, 502},
+ 	{976, 527},
+ 	{976, 502},
+ 	{976, 567},
+ 	{  0, 627},
+ 	{  0, 627},
+ 	{  0,   0},
+ 	{  0,   0}
 };
 
 SiS300_LVDSDesStruct  SiS300_PanelType09_2[]=
 {
- {1152, 622},
- {1152, 597},
- {1152, 622},
- {1152, 597},
- {1152, 662},
- {1232, 722},
- {   0, 805},
- {   0, 794},
- {   0,   0}
+ 	{1152, 622},
+ 	{1152, 597},
+ 	{1152, 622},
+ 	{1152, 597},
+ 	{1152, 662},
+ 	{1232, 722},
+ 	{   0, 805},
+ 	{   0, 794},
+ 	{   0,   0}
 };
 
 SiS300_LVDSDesStruct  SiS300_PanelType0a_2[]=
 {
- {976, 527},
- {976, 502},
- {976, 527},
- {976, 502},
- {976, 567},
- {  0, 627},
- {  0, 627},
- {  0,   0},
- {  0,   0}
+ 	{976, 527},
+ 	{976, 502},
+ 	{976, 527},
+ 	{976, 502},
+ 	{976, 567},
+ 	{  0, 627},
+ 	{  0, 627},
+ 	{  0,   0},
+ 	{  0,   0}
 };
 
 SiS300_LVDSDesStruct  SiS300_PanelType0b_2[]=
 {
- {1152, 622},
- {1152, 597},
- {1152, 622},
- {1152, 597},
- {1152, 662},
- {1232, 722},
- {   0, 805},
- {   0, 794},
- {   0,   0}
+ 	{1152, 622},
+ 	{1152, 597},
+ 	{1152, 622},
+ 	{1152, 597},
+ 	{1152, 662},
+ 	{1232, 722},
+ 	{   0, 805},
+ 	{   0, 794},
+ 	{   0,   0}
 };
 
 SiS300_LVDSDesStruct  SiS300_PanelType0c_2[]=
 {
- {1152, 622},
- {1152, 597},
- {1152, 622},
- {1152, 597},
- {1152, 662},
- {1232, 722},
- {   0, 805},
- {   0, 794},
- {   0,   0}
+ 	{1152, 622},
+ 	{1152, 597},
+ 	{1152, 622},
+ 	{1152, 597},
+ 	{1152, 662},
+ 	{1232, 722},
+ 	{   0, 805},
+ 	{   0, 794},
+ 	{   0,   0}
 };
 
 SiS300_LVDSDesStruct  SiS300_PanelType0d_2[]=
 {
- {1152, 622},
- {1152, 597},
- {1152, 622},
- {1152, 597},
- {1152, 662},
- {1232, 722},
- {   0, 805},
- {   0, 794},
- {   0,   0}
+ 	{1152, 622},
+ 	{1152, 597},
+ 	{1152, 622},
+ 	{1152, 597},
+ 	{1152, 662},
+ 	{1232, 722},
+ 	{   0, 805},
+ 	{   0, 794},
+ 	{   0,   0}
 };
 
 SiS300_LVDSDesStruct  SiS300_PanelType0e_2[]=
 {
- {1152, 622},
- {1152, 597},
- {1152, 622},
- {1152, 597},
- {1152, 662},
- {1232, 722},
- {   0, 805},
- {   0, 794},
- {   0,   0}
+ 	{1152, 622},
+ 	{1152, 597},
+ 	{1152, 622},
+ 	{1152, 597},
+ 	{1152, 662},
+ 	{1232, 722},
+ 	{   0, 805},
+ 	{   0, 794},
+ 	{   0,   0}
 };
 
 SiS300_LVDSDesStruct  SiS300_PanelType0f_2[]=
 {
- {1152, 622},
- {1152, 597},
- {1152, 622},
- {1152, 597},
- {1152, 662},
- {1232, 722},
- {   0, 805},
- {   0, 794},
- {   0,   0}
+ 	{1152, 622},
+ 	{1152, 597},
+ 	{1152, 622},
+ 	{1152, 597},
+ 	{1152, 662},
+ 	{1232, 722},
+ 	{   0, 805},
+ 	{   0, 794},
+ 	{   0,   0}
 };
 
 /*301b*/
 SiS300_LVDSDesStruct SiS300_PanelType1076_1[]=
 {
-{0x00,0x00}
+	{0x00,0x00}
 };
 SiS300_LVDSDesStruct SiS300_PanelType1210_1[]=
 {
-{0x00,0x00}
+	{0x00,0x00}
 };
 SiS300_LVDSDesStruct SiS300_PanelType1296_1[]=
 {
-{0x00,0x00}
+	{0x00,0x00}
 };
 SiS300_LVDSDesStruct SiS300_PanelType1076_2[]=
 {
-{0x00,0x00}
+	{0x00,0x00}
 };
 SiS300_LVDSDesStruct SiS300_PanelType1210_2[]=
 {
-{0x00,0x00}
+	{0x00,0x00}
 };
 SiS300_LVDSDesStruct SiS300_PanelType1296_2[]=
 {
-{0x00,0x00}
+	{0x00,0x00}
 };
 /*end 301b*/
 
-/* TW: TV won't work unless these tables are filled with data */
+/* TW: New */
 SiS300_LVDSDesStruct  SiS300_CHTVUNTSCDesData[]=
 {
- {0x00,0x00},
- {0x00,0x00},
- {0x00,0x00},
- {0x00,0x00},
- {0x00,0x00},
- {0x00,0x00},
- {0x00,0x00},
- {0x00,0x00},
- {0x00,0x00}
+ 	{ 0,   0},
+ 	{ 0,   0},
+ 	{ 0,   0},
+ 	{ 0,   0},
+ 	{ 0,   0},
+ 	{ 0,   0}
 };
 
 SiS300_LVDSDesStruct  SiS300_CHTVONTSCDesData[]=
 {
- {0x00,0x00},
- {0x00,0x00},
- {0x00,0x00},
- {0x00,0x00},
- {0x00,0x00},
- {0x00,0x00},
- {0x00,0x00},
- {0x00,0x00},
- {0x00,0x00}
+ 	{ 0,   0},
+ 	{ 0,   0},
+ 	{ 0,   0},
+ 	{ 0,   0},
+ 	{ 0,   0},
+ 	{ 0,   0}
 };
 
 SiS300_LVDSDesStruct  SiS300_CHTVUPALDesData[]=
 {
- {0x00,0x00},
- {0x00,0x00},
- {0x00,0x00},
- {0x00,0x00},
- {0x00,0x00},
- {0x00,0x00},
- {0x00,0x00},
- {0x00,0x00},
- {0x00,0x00}
+ 	{256,   0},
+ 	{256,   0},
+ 	{256,   0},
+ 	{256,   0},
+ 	{  0,   0},
+ 	{  0,   0}
 };
 
 SiS300_LVDSDesStruct  SiS300_CHTVOPALDesData[]=
 {
- {0x00,0x00},
- {0x00,0x00},
- {0x00,0x00},
- {0x00,0x00},
- {0x00,0x00},
- {0x00,0x00},
- {0x00,0x00},
- {0x00,0x00},
- {0x00,0x00}
+ 	{256,   0},
+ 	{256,   0},
+ 	{256,   0},
+ 	{256,   0},
+ 	{  0,   0},
+ 	{  0,   0}
 };
+/* TW: New end */
 
 typedef struct _SiS300_LVDSCRT1DataStruct
 {
 UCHAR CR[15];
 } SiS300_LVDSCRT1DataStruct;
+
 SiS300_LVDSCRT1DataStruct  SiS300_LVDSCRT1800x600_1[]=
 {
- {{0x65,0x4f,0x89,0x56,0x83,0xaf,0x1f,
-   0x90,0x85,0x8f,0xab,0x30,0x00,0x05,
-   0x00 }},
- {{0x65,0x4f,0x89,0x56,0x83,0x83,0x1f,
-   0x5e,0x83,0x5d,0x79,0x10,0x00,0x05,
-   0x00 }},
- {{0x65,0x4f,0x89,0x56,0x83,0xaf,0x1f,
-   0x90,0x85,0x8f,0xab,0x30,0x00,0x05,
-   0x00 }},
- {{0x65,0x4f,0x89,0x56,0x83,0x83,0x1f,
-   0x5e,0x83,0x5d,0x79,0x10,0x00,0x05,
-   0x00 }},
- {{0x65,0x4f,0x89,0x56,0x83,0x04,0x3e,
-   0xe0,0x85,0xdf,0xfb,0x10,0x00,0x05,
-   0x00 }},
- {{0x7f,0x63,0x83,0x6c,0x1c,0x72,0xf0,
-   0x58,0x8c,0x57,0x73,0x20,0x00,0x06,
-   0x01 }}
+	{{0x65,0x4f,0x89,0x56,0x83,0xaf,0x1f,
+	  0x90,0x85,0x8f,0xab,0x30,0x00,0x05,
+	  0x00 }},
+	{{0x65,0x4f,0x89,0x56,0x83,0x83,0x1f,
+	  0x5e,0x83,0x5d,0x79,0x10,0x00,0x05,
+	  0x00 }},
+	{{0x65,0x4f,0x89,0x56,0x83,0xaf,0x1f,
+	  0x90,0x85,0x8f,0xab,0x30,0x00,0x05,
+	  0x00 }},
+	{{0x65,0x4f,0x89,0x56,0x83,0x83,0x1f,
+	  0x5e,0x83,0x5d,0x79,0x10,0x00,0x05,
+	  0x00 }},
+	{{0x65,0x4f,0x89,0x56,0x83,0x04,0x3e,
+	  0xe0,0x85,0xdf,0xfb,0x10,0x00,0x05,
+	  0x00 }},
+	{{0x7f,0x63,0x83,0x6c,0x1c,0x72,0xf0,
+	  0x58,0x8c,0x57,0x73,0x20,0x00,0x06,
+	  0x01 }}
 };
 
 SiS300_LVDSCRT1DataStruct  SiS300_LVDSCRT11024x768_1[]=
 { 
- {{0x64,0x4f,0x88,0x54,0x9f,0xc4,0x1f,
-   0x92,0x89,0x8f,0xb5,0x30,0x00,0x01,
-   0x00}},
- {{0x64,0x4f,0x88,0x54,0x9f,0x97,0x1f,
-   0x60,0x87,0x5d,0x83,0x10,0x00,0x01,
-   0x00}},
- {{0x64,0x4f,0x88,0x54,0x9f,0xc4,0x1f,
-   0x92,0x89,0x8f,0xb5,0x30,0x00,0x01,
-   0x00}},
- {{0x64,0x4f,0x88,0x54,0x9f,0x97,0x1f,
-   0x60,0x87,0x5d,0x83,0x10,0x00,0x01,
-   0x00}},
- {{0x64,0x4f,0x88,0x54,0x9f,0x04,0x3e,
-   0xe2,0x89,0xdf,0x05,0x00,0x00,0x01,
-   0x00}},
- {{0x7e,0x63,0x82,0x68,0x15,0x7c,0xf0,
-   0x5a,0x8f,0x57,0x7d,0x20,0x00,0x26,
-   0x01}},
- {{0xa3,0x7f,0x87,0x86,0x97,0x24,0xf5,
-   0x02,0x88,0xff,0x25,0x10,0x00,0x02,
-   0x01} }
+	{{0x64,0x4f,0x88,0x54,0x9f,0xc4,0x1f,
+	  0x92,0x89,0x8f,0xb5,0x30,0x00,0x01,
+	  0x00}},
+	{{0x64,0x4f,0x88,0x54,0x9f,0x97,0x1f,
+	  0x60,0x87,0x5d,0x83,0x10,0x00,0x01,
+	  0x00}},
+	{{0x64,0x4f,0x88,0x54,0x9f,0xc4,0x1f,
+	  0x92,0x89,0x8f,0xb5,0x30,0x00,0x01,
+	  0x00}},
+	{{0x64,0x4f,0x88,0x54,0x9f,0x97,0x1f,
+	  0x60,0x87,0x5d,0x83,0x10,0x00,0x01,
+	  0x00}},
+	{{0x64,0x4f,0x88,0x54,0x9f,0x04,0x3e,
+	  0xe2,0x89,0xdf,0x05,0x00,0x00,0x01,
+	  0x00}},
+	{{0x7e,0x63,0x82,0x68,0x15,0x7c,0xf0,
+	  0x5a,0x8f,0x57,0x7d,0x20,0x00,0x26,
+	  0x01}},
+	{{0xa3,0x7f,0x87,0x86,0x97,0x24,0xf5,
+	  0x02,0x88,0xff,0x25,0x10,0x00,0x02,
+	  0x01} }
 };
 
 SiS300_LVDSCRT1DataStruct  SiS300_LVDSCRT11280x1024_1[]=
 {
- {{0x63,0x4f,0x87,0x54,0x9f,0xb4,0x1f,
-   0x92,0x89,0x8f,0xb5,0x30,0x00,0x01,
-   0x00 }},
- {{0x63,0x4f,0x87,0x54,0x9f,0x82,0x1f,
-   0x60,0x87,0x5d,0x83,0x10,0x00,0x01,
-   0x00 }},
- {{0x63,0x4f,0x87,0x54,0x9f,0xb4,0x1f,
-   0x92,0x89,0x8f,0xb5,0x30,0x00,0x01,
-   0x00 }},
- {{0x63,0x4f,0x87,0x54,0x9f,0x82,0x1f,
-   0x60,0x87,0x5d,0x83,0x10,0x00,0x01,
-   0x00 }},
- {{0x63,0x4f,0x87,0x54,0x9f,0x04,0x3e,
-   0xe2,0x89,0xdf,0x05,0x00,0x00,0x01,
-   0x00 }},
- {{0x7e,0x63,0x82,0x68,0x15,0x7c,0xf0,
-   0x5a,0x8f,0x57,0x7d,0x20,0x00,0x26,
-   0x01 }},
- {{0xa3,0x7f,0x87,0x86,0x97,0x24,0xf5,
-   0x02,0x88,0xff,0x25,0x10,0x00,0x02,
-   0x01 }}
+	{{0x63,0x4f,0x87,0x54,0x9f,0xb4,0x1f,
+	  0x92,0x89,0x8f,0xb5,0x30,0x00,0x01,
+	  0x00 }},
+	{{0x63,0x4f,0x87,0x54,0x9f,0x82,0x1f,
+	  0x60,0x87,0x5d,0x83,0x10,0x00,0x01,
+	  0x00 }},
+	{{0x63,0x4f,0x87,0x54,0x9f,0xb4,0x1f,
+	  0x92,0x89,0x8f,0xb5,0x30,0x00,0x01,
+	  0x00 }},
+	{{0x63,0x4f,0x87,0x54,0x9f,0x82,0x1f,
+	  0x60,0x87,0x5d,0x83,0x10,0x00,0x01,
+	  0x00 }},
+	{{0x63,0x4f,0x87,0x54,0x9f,0x04,0x3e,
+	  0xe2,0x89,0xdf,0x05,0x00,0x00,0x01,
+	  0x00 }},
+	{{0x7e,0x63,0x82,0x68,0x15,0x7c,0xf0,
+	  0x5a,0x8f,0x57,0x7d,0x20,0x00,0x26,
+	  0x01 }},
+	{{0xa3,0x7f,0x87,0x86,0x97,0x24,0xf5,
+	  0x02,0x88,0xff,0x25,0x10,0x00,0x02,
+	  0x01 }}
 };
 
 SiS300_LVDSCRT1DataStruct  SiS300_LVDSCRT1800x600_1_H[]=
 {
- {{0x30,0x27,0x94,0x2c,0x92,0xaf,0x1f,
-   0x90,0x85,0x8f,0xab,0x30,0x00,0x04,
-   0x00 }},
- {{0x30,0x27,0x94,0x2c,0x92,0x83,0x1f,
-   0x5e,0x83,0x5d,0x79,0x10,0x00,0x04,
-   0x00 }},
- {{0x30,0x27,0x94,0x2c,0x92,0xaf,0x1f,
-   0x90,0x85,0x8f,0xab,0x30,0x00,0x04,
-   0x00 }},
- {{0x30,0x27,0x94,0x2c,0x92,0x83,0x1f,
-   0x5e,0x83,0x5d,0x79,0x10,0x00,0x04,
-   0x00 }},
- {{0x30,0x27,0x94,0x2c,0x92,0x04,0x3e,
-   0xe0,0x85,0xdf,0xfb,0x10,0x00,0x04,
-   0x00 }},
- {{0x3d,0x31,0x81,0x37,0x1f,0x72,0xf0,
-   0x58,0x8c,0x57,0x73,0x20,0x00,0x05,
-   0x01 }}
+	{{0x30,0x27,0x94,0x2c,0x92,0xaf,0x1f,
+	  0x90,0x85,0x8f,0xab,0x30,0x00,0x04,
+	  0x00 }},
+	{{0x30,0x27,0x94,0x2c,0x92,0x83,0x1f,
+	  0x5e,0x83,0x5d,0x79,0x10,0x00,0x04,
+	  0x00 }},
+	{{0x30,0x27,0x94,0x2c,0x92,0xaf,0x1f,
+	  0x90,0x85,0x8f,0xab,0x30,0x00,0x04,
+	  0x00 }},
+	{{0x30,0x27,0x94,0x2c,0x92,0x83,0x1f,
+	  0x5e,0x83,0x5d,0x79,0x10,0x00,0x04,
+	  0x00 }},
+	{{0x30,0x27,0x94,0x2c,0x92,0x04,0x3e,
+	  0xe0,0x85,0xdf,0xfb,0x10,0x00,0x04,
+	  0x00 }},
+	{{0x3d,0x31,0x81,0x37,0x1f,0x72,0xf0,
+	  0x58,0x8c,0x57,0x73,0x20,0x00,0x05,
+	  0x01 }}
 };
 
 SiS300_LVDSCRT1DataStruct  SiS300_LVDSCRT11024x768_1_H[]=
 {
- {{0x37,0x27,0x9B,0x2b,0x94,0xc4,0x1f,
-   0x92,0x89,0x8f,0xb5,0x30,0x00,0x44,
-   0x00 }},
- {{0x37,0x27,0x9B,0x2b,0x94,0x97,0x1f,
-   0x60,0x87,0x5D,0x83,0x01,0x00,0x44,
-   0x00}},
- {{0x37,0x27,0x9B,0x2b,0x94,0xc4,0x1f,
-   0x92,0x89,0x8f,0xb5,0x30,0x00,0x44,
-   0x00}},
- {{0x37,0x27,0x9B,0x2b,0x94,0x97,0x1f,
-   0x60,0x87,0x5D,0x83,0x01,0x00,0x44,
-   0x00}},
- {{0x37,0x27,0x9B,0x2b,0x94,0x04,0x3e,
-   0xE2,0x89,0xDf,0x05,0x00,0x00,0x44,
-   0x00}},
- {{0x41,0x31,0x85,0x35,0x1d,0x7c,0xf0,
-   0x5A,0x8F,0x57,0x7D,0x20,0x00,0x55,
-   0x01}},
- {{0x4f,0x3F,0x93,0x45,0x0D,0x24,0xf5,
-   0x02,0x88,0xFf,0x25,0x10,0x00,0x01,
-   0x01 }}
+	{{0x37,0x27,0x9B,0x2b,0x94,0xc4,0x1f,
+	  0x92,0x89,0x8f,0xb5,0x30,0x00,0x44,
+	  0x00 }},
+	{{0x37,0x27,0x9B,0x2b,0x94,0x97,0x1f,
+	  0x60,0x87,0x5D,0x83,0x01,0x00,0x44,
+	  0x00}},
+	{{0x37,0x27,0x9B,0x2b,0x94,0xc4,0x1f,
+	  0x92,0x89,0x8f,0xb5,0x30,0x00,0x44,
+	  0x00}},
+	{{0x37,0x27,0x9B,0x2b,0x94,0x97,0x1f,
+	  0x60,0x87,0x5D,0x83,0x01,0x00,0x44,
+	  0x00}},
+	{{0x37,0x27,0x9B,0x2b,0x94,0x04,0x3e,
+	  0xE2,0x89,0xDf,0x05,0x00,0x00,0x44,
+	  0x00}},
+	{{0x41,0x31,0x85,0x35,0x1d,0x7c,0xf0,
+	  0x5A,0x8F,0x57,0x7D,0x20,0x00,0x55,
+	  0x01}},
+	{{0x4f,0x3F,0x93,0x45,0x0D,0x24,0xf5,
+	  0x02,0x88,0xFf,0x25,0x10,0x00,0x01,
+	  0x01 }}
 };
 
 SiS300_LVDSCRT1DataStruct  SiS300_LVDSCRT11280x1024_1_H[]=
 {
- {{0x2f,0x27,0x93,0x2b,0x90,0xb4,0x1f,
-   0x92,0x89,0x8f,0xb5,0x30,0x00,0x04,
-   0x00 }},
- {{0x2f,0x27,0x93,0x2b,0x90,0x82,0x1f,
-   0x60,0x87,0x5d,0x83,0x10,0x00,0x04,
-   0x00 }},
- {{0x2f,0x27,0x93,0x2b,0x90,0xb4,0x1f,
-   0x92,0x89,0x8f,0xb5,0x30,0x00,0x04,
-   0x00 }},
- {{0x2f,0x27,0x93,0x2b,0x90,0x82,0x1f,
-   0x60,0x87,0x5d,0x83,0x10,0x00,0x04,
-   0x00 }},
- {{0x2f,0x27,0x93,0x2b,0x90,0x04,0x3e,
-   0xe2,0x89,0xdf,0x05,0x00,0x00,0x04,
-   0x00 }},
- {{0x3c,0x31,0x80,0x35,0x1c,0x7c,0xf0,
-   0x5a,0x8f,0x57,0x7d,0x20,0x00,0x55,
-   0x01 }},
- {{0x4f,0x3f,0x93,0x45,0x0d,0x24,0xf5,
-   0x02,0x88,0xff,0x25,0x10,0x00,0x01,
-   0x01 }}
+	{{0x2f,0x27,0x93,0x2b,0x90,0xb4,0x1f,
+	  0x92,0x89,0x8f,0xb5,0x30,0x00,0x04,
+	  0x00 }},
+	{{0x2f,0x27,0x93,0x2b,0x90,0x82,0x1f,
+	  0x60,0x87,0x5d,0x83,0x10,0x00,0x04,
+	  0x00 }},
+	{{0x2f,0x27,0x93,0x2b,0x90,0xb4,0x1f,
+	  0x92,0x89,0x8f,0xb5,0x30,0x00,0x04,
+	  0x00 }},
+	{{0x2f,0x27,0x93,0x2b,0x90,0x82,0x1f,
+	  0x60,0x87,0x5d,0x83,0x10,0x00,0x04,
+	  0x00 }},
+	{{0x2f,0x27,0x93,0x2b,0x90,0x04,0x3e,
+	  0xe2,0x89,0xdf,0x05,0x00,0x00,0x04,
+	  0x00 }},
+	{{0x3c,0x31,0x80,0x35,0x1c,0x7c,0xf0,
+	  0x5a,0x8f,0x57,0x7d,0x20,0x00,0x55,
+	  0x01 }},
+	{{0x4f,0x3f,0x93,0x45,0x0d,0x24,0xf5,
+	  0x02,0x88,0xff,0x25,0x10,0x00,0x01,
+	  0x01 }}
 };
 
 SiS300_LVDSCRT1DataStruct  SiS300_LVDSCRT1800x600_2[]=
 {
- {{0x7f,0x4f,0x83,0x62,0x12,0x72,0x3e,
-   0xf4,0x88,0x8f,0x73,0x20,0x00,0x06,
-   0x00 }},
- {{0x7f,0x4f,0x83,0x62,0x12,0x72,0x3e,
-   0xdb,0x8f,0x5d,0x73,0x20,0x00,0x06,
-   0x00 }},
- {{0x7f,0x4f,0x83,0x62,0x12,0x72,0x3e,
-   0xf4,0x88,0x8f,0x73,0x20,0x00,0x06,
-   0x00 }},
- {{0x7f,0x4f,0x83,0x62,0x12,0x72,0x3e,
-   0xdb,0x8f,0x5d,0x73,0x20,0x00,0x06,
-   0x00 }},
- {{0x7f,0x4f,0x83,0x62,0x12,0x72,0xba,
-   0x1c,0x80,0xdf,0x73,0x00,0x00,0x06,
-   0x00 }},
- {{0x7f,0x63,0x83,0x6c,0x1c,0x72,0xf0,
-   0x58,0x8c,0x57,0x73,0x20,0x00,0x06,
-   0x01 }}
+	{{0x7f,0x4f,0x83,0x62,0x12,0x72,0x3e,
+	  0xf4,0x88,0x8f,0x73,0x20,0x00,0x06,
+	  0x00 }},
+	{{0x7f,0x4f,0x83,0x62,0x12,0x72,0x3e,
+	  0xdb,0x8f,0x5d,0x73,0x20,0x00,0x06,
+	  0x00 }},
+	{{0x7f,0x4f,0x83,0x62,0x12,0x72,0x3e,
+	  0xf4,0x88,0x8f,0x73,0x20,0x00,0x06,
+	  0x00 }},
+	{{0x7f,0x4f,0x83,0x62,0x12,0x72,0x3e,
+	  0xdb,0x8f,0x5d,0x73,0x20,0x00,0x06,
+	  0x00 }},
+	{{0x7f,0x4f,0x83,0x62,0x12,0x72,0xba,
+	  0x1c,0x80,0xdf,0x73,0x00,0x00,0x06,
+	  0x00 }},
+	{{0x7f,0x63,0x83,0x6c,0x1c,0x72,0xf0,
+	  0x58,0x8c,0x57,0x73,0x20,0x00,0x06,
+	  0x01 }}
 };
 
 SiS300_LVDSCRT1DataStruct  SiS300_LVDSCRT11024x768_2[]=
 {
- {{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
-   0x4a,0x80,0x8f,0x25,0x30,0x00,0x06,
-   0x00 }},
- {{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
-   0x31,0x87,0x5d,0x25,0x30,0x00,0x06,
-   0x00 }},
- {{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
-   0x4a,0x80,0x8f,0x25,0x30,0x00,0x06,
-   0x00 }},
- {{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
-   0x31,0x87,0x5d,0x25,0x30,0x00,0x06,
-   0x00 }},
- {{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
-   0x72,0x88,0xdf,0x25,0x30,0x00,0x06,
-   0x00 }},
- {{0xa3,0x63,0x87,0x78,0x89,0x24,0xf1,
-   0xae,0x84,0x57,0x25,0x30,0x00,0x02,
-   0x01 }},
- {{0xa3,0x7f,0x87,0x86,0x97,0x24,0xf5,
-   0x02,0x88,0xff,0x25,0x10,0x00,0x02,
-   0x01 }}
+	{{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
+	  0x4a,0x80,0x8f,0x25,0x30,0x00,0x06,
+	  0x00 }},
+	{{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
+	  0x31,0x87,0x5d,0x25,0x30,0x00,0x06,
+	  0x00 }},
+	{{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
+	  0x4a,0x80,0x8f,0x25,0x30,0x00,0x06,
+	  0x00 }},
+	{{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
+	  0x31,0x87,0x5d,0x25,0x30,0x00,0x06,
+	  0x00 }},
+	{{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
+	  0x72,0x88,0xdf,0x25,0x30,0x00,0x06,
+	  0x00 }},
+	{{0xa3,0x63,0x87,0x78,0x89,0x24,0xf1,
+	  0xae,0x84,0x57,0x25,0x30,0x00,0x02,
+	  0x01 }},
+	{{0xa3,0x7f,0x87,0x86,0x97,0x24,0xf5,
+	  0x02,0x88,0xff,0x25,0x10,0x00,0x02,
+	  0x01 }}
 };
 
 SiS300_LVDSCRT1DataStruct  SiS300_LVDSCRT11280x1024_2[]=
 {
- {{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
-   0x4a,0x80,0x8f,0x25,0x30,0x00,0x06,
-   0x00 }},
- {{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
-   0x31,0x87,0x5d,0x25,0x30,0x00,0x06,
-   0x00 }},
- {{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
-   0x4a,0x80,0x8f,0x25,0x30,0x00,0x06,
-   0x00 }},
- {{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
-   0x31,0x87,0x5d,0x25,0x30,0x00,0x06,
-   0x00 }},
- {{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
-   0x72,0x88,0xdf,0x25,0x30,0x00,0x06,
-   0x00 }},
- {{0xa3,0x63,0x87,0x78,0x89,0x24,0xf1,
-   0xae,0x84,0x57,0x25,0x30,0x00,0x02,
-   0x01 }},
- {{0xa3,0x7f,0x87,0x86,0x97,0x24,0xf5,
-   0x02,0x88,0xff,0x25,0x10,0x00,0x02,
-   0x01 }}
+	{{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
+	  0x4a,0x80,0x8f,0x25,0x30,0x00,0x06,
+	  0x00 }},
+	{{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
+	  0x31,0x87,0x5d,0x25,0x30,0x00,0x06,
+	  0x00 }},
+	{{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
+	  0x4a,0x80,0x8f,0x25,0x30,0x00,0x06,
+	  0x00 }},
+	{{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
+	  0x31,0x87,0x5d,0x25,0x30,0x00,0x06,
+	  0x00 }},
+	{{0xa3,0x4f,0x87,0x6e,0x9f,0x24,0xbb,
+	  0x72,0x88,0xdf,0x25,0x30,0x00,0x06,
+	  0x00 }},
+	{{0xa3,0x63,0x87,0x78,0x89,0x24,0xf1,
+	  0xae,0x84,0x57,0x25,0x30,0x00,0x02,
+	  0x01 }},
+	{{0xa3,0x7f,0x87,0x86,0x97,0x24,0xf5,
+	  0x02,0x88,0xff,0x25,0x10,0x00,0x02,
+	  0x01 }}
 };
 
 SiS300_LVDSCRT1DataStruct  SiS300_LVDSCRT1800x600_2_H[]=
 {
- {{0x3d,0x27,0x81,0x32,0x1a,0x72,0x3e,
-   0xf4,0x88,0x8f,0x73,0x20,0x00,0x05,
-   0x00 }},
- {{0x3d,0x27,0x81,0x32,0x1a,0x72,0x3e,
-   0xdb,0x8f,0x5d,0x73,0x20,0x00,0x05,
-   0x00 }},
- {{0x3d,0x27,0x81,0x32,0x1a,0x72,0x3e,
-   0xf4,0x88,0x8f,0x73,0x20,0x00,0x05,
-   0x00 }},
- {{0x3d,0x27,0x81,0x3a,0x1a,0x72,0x3e,
-   0xdb,0x8f,0x5d,0x73,0x20,0x00,0x05,
-   0x00 }},
- {{0x3d,0x27,0x81,0x32,0x1a,0x72,0xba,
-   0x1c,0x80,0xdf,0x73,0x00,0x00,0x05,
-   0x00 }},
- {{0x3d,0x31,0x81,0x37,0x1f,0x72,0xf0,
-   0x58,0x8c,0x57,0x73,0x20,0x00,0x05,
-   0x01 }}
+	{{0x3d,0x27,0x81,0x32,0x1a,0x72,0x3e,
+	  0xf4,0x88,0x8f,0x73,0x20,0x00,0x05,
+	  0x00 }},
+	{{0x3d,0x27,0x81,0x32,0x1a,0x72,0x3e,
+	  0xdb,0x8f,0x5d,0x73,0x20,0x00,0x05,
+	  0x00 }},
+	{{0x3d,0x27,0x81,0x32,0x1a,0x72,0x3e,
+	  0xf4,0x88,0x8f,0x73,0x20,0x00,0x05,
+	  0x00 }},
+	{{0x3d,0x27,0x81,0x3a,0x1a,0x72,0x3e,
+	  0xdb,0x8f,0x5d,0x73,0x20,0x00,0x05,
+	  0x00 }},
+	{{0x3d,0x27,0x81,0x32,0x1a,0x72,0xba,
+	  0x1c,0x80,0xdf,0x73,0x00,0x00,0x05,
+	  0x00 }},
+	{{0x3d,0x31,0x81,0x37,0x1f,0x72,0xf0,
+	  0x58,0x8c,0x57,0x73,0x20,0x00,0x05,
+	  0x01 }}
 };
 
 SiS300_LVDSCRT1DataStruct  SiS300_LVDSCRT11024x768_2_H[]=
 {
- {{0x4f,0x27,0x93,0x39,0x01,0x24,0xbb,
-   0x4a,0x80,0x8f,0x25,0x30,0x00,0x01,
-   0x00 }},
- {{0x4f,0x27,0x93,0x39,0x01,0x24,0xbb,
-   0x31,0x87,0x5d,0x25,0x30,0x00,0x01,
-   0x00 }},
- {{0x4f,0x27,0x93,0x39,0x01,0x24,0xbb,
-   0x4a,0x80,0x8f,0x25,0x30,0x00,0x01,
-   0x00 }},
- {{0x4f,0x27,0x93,0x39,0x01,0x24,0xbb,
-   0x31,0x87,0x5d,0x25,0x30,0x00,0x01,
-   0x00 }},
- {{0x4f,0x27,0x93,0x39,0x01,0x24,0xbb,
-   0x72,0x88,0xdf,0x25,0x30,0x00,0x01,
-   0x00 }},
- {{0x4f,0x31,0x93,0x3e,0x06,0x24,0xf1,
-   0xae,0x84,0x57,0x25,0x30,0x00,0x01,
-   0x01 }},
- {{0x4f,0x3f,0x93,0x45,0x0d,0x24,0xf5,
-   0x02,0x88,0xff,0x25,0x10,0x00,0x01,
-   0x01 }}
+	{{0x4f,0x27,0x93,0x39,0x01,0x24,0xbb,
+	  0x4a,0x80,0x8f,0x25,0x30,0x00,0x01,
+	  0x00 }},
+	{{0x4f,0x27,0x93,0x39,0x01,0x24,0xbb,
+	  0x31,0x87,0x5d,0x25,0x30,0x00,0x01,
+	  0x00 }},
+	{{0x4f,0x27,0x93,0x39,0x01,0x24,0xbb,
+	  0x4a,0x80,0x8f,0x25,0x30,0x00,0x01,
+	  0x00 }},
+	{{0x4f,0x27,0x93,0x39,0x01,0x24,0xbb,
+	  0x31,0x87,0x5d,0x25,0x30,0x00,0x01,
+	  0x00 }},
+	{{0x4f,0x27,0x93,0x39,0x01,0x24,0xbb,
+	  0x72,0x88,0xdf,0x25,0x30,0x00,0x01,
+	  0x00 }},
+	{{0x4f,0x31,0x93,0x3e,0x06,0x24,0xf1,
+	  0xae,0x84,0x57,0x25,0x30,0x00,0x01,
+	  0x01 }},
+	{{0x4f,0x3f,0x93,0x45,0x0d,0x24,0xf5,
+	  0x02,0x88,0xff,0x25,0x10,0x00,0x01,
+	  0x01 }}
 };
 
 SiS300_LVDSCRT1DataStruct  SiS300_LVDSCRT11280x1024_2_H[]=
 {
- {{0x4f,0x27,0x93,0x39,0x81,0x24,0xbb,
-   0x4a,0x80,0x8f,0x25,0x30,0x00,0x01,
-   0x00 }},
- {{0x4f,0x27,0x93,0x39,0x81,0x24,0xbb,
-   0x31,0x87,0x5d,0x25,0x30,0x00,0x01,
-   0x00 }},
- {{0x4f,0x27,0x93,0x39,0x81,0x24,0xbb,
-   0x4a,0x80,0x8f,0x25,0x30,0x00,0x01,
-   0x00 }},
- {{0x4f,0x27,0x93,0x39,0x81,0x24,0xbb,
-   0x31,0x87,0x5d,0x25,0x30,0x00,0x01,
-   0x00 }},
- {{0x4f,0x27,0x93,0x39,0x81,0x24,0xbb,
-   0x72,0x88,0xdf,0x25,0x30,0x00,0x01,
-   0x00 }},
- {{0x4f,0x31,0x93,0x3e,0x86,0x24,0xf1,
-   0xae,0x84,0x57,0x25,0x30,0x00,0x01,
-   0x01 }},
- {{0x4f,0x3f,0x93,0x45,0x0d,0x24,0xf5,
-   0x02,0x88,0xff,0x25,0x10,0x00,0x01,
-   0x01}}
+	{{0x4f,0x27,0x93,0x39,0x81,0x24,0xbb,
+	  0x4a,0x80,0x8f,0x25,0x30,0x00,0x01,
+	  0x00 }},
+	{{0x4f,0x27,0x93,0x39,0x81,0x24,0xbb,
+	  0x31,0x87,0x5d,0x25,0x30,0x00,0x01,
+	  0x00 }},
+	{{0x4f,0x27,0x93,0x39,0x81,0x24,0xbb,
+	  0x4a,0x80,0x8f,0x25,0x30,0x00,0x01,
+	  0x00 }},
+	{{0x4f,0x27,0x93,0x39,0x81,0x24,0xbb,
+	  0x31,0x87,0x5d,0x25,0x30,0x00,0x01,
+	  0x00 }},
+	{{0x4f,0x27,0x93,0x39,0x81,0x24,0xbb,
+	  0x72,0x88,0xdf,0x25,0x30,0x00,0x01,
+	  0x00 }},
+	{{0x4f,0x31,0x93,0x3e,0x86,0x24,0xf1,
+	  0xae,0x84,0x57,0x25,0x30,0x00,0x01,
+	  0x01 }},
+	{{0x4f,0x3f,0x93,0x45,0x0d,0x24,0xf5,
+	  0x02,0x88,0xff,0x25,0x10,0x00,0x01,
+	  0x01}}
 };
 
+/* TW: New */
 SiS300_LVDSCRT1DataStruct  SiS300_CHTVCRT1UNTSC[]=
 {
- {{0x64,0x4f,0x88,0x56,0x9f,0x56,0x3e,
-   0xe8,0x84,0x8f,0x57,0x20,0x00,0x01,
-   0x00 }},
- {{0x64,0x4f,0x88,0x56,0x9f,0x56,0x3e,
-   0xd0,0x82,0x5d,0x57,0x00,0x00,0x01,
-   0x00 }},
- {{0x64,0x4f,0x88,0x56,0x9f,0x56,0x3e,
-   0xe8,0x84,0x8f,0x57,0x20,0x00,0x01,
-   0x00 }},
- {{0x64,0x4f,0x88,0x56,0x9f,0x56,0x3e,
-   0xd0,0x82,0x5d,0x57,0x00,0x00,0x01,
-   0x00 }},
- {{0x5d,0x4f,0x81,0x53,0x9c,0x56,0xba,
-   0x18,0x84,0xdf,0x57,0x00,0x00,0x01,
-   0x00 }},
- {{0x80,0x63,0x84,0x6c,0x17,0xec,0xf0,
-   0x90,0x8c,0x57,0xed,0x20,0x00,0x06,
-   0x01 }}
+	{{0x64,0x4f,0x88,0x56,0x9f,0x56,0x3e,
+	  0xe8,0x84,0x8f,0x57,0x20,0x00,0x01,
+	  0x00 }},
+	{{0x64,0x4f,0x88,0x56,0x9f,0x56,0x3e,
+	  0xd0,0x82,0x5d,0x57,0x00,0x00,0x01,
+	  0x00 }},
+	{{0x64,0x4f,0x88,0x56,0x9f,0x56,0x3e,
+	  0xe8,0x84,0x8f,0x57,0x20,0x00,0x01,
+	  0x00 }},
+	{{0x64,0x4f,0x88,0x56,0x9f,0x56,0x3e,
+	  0xd0,0x82,0x5d,0x57,0x00,0x00,0x01,
+	  0x00 }},
+	{{0x5d,0x4f,0x81,0x53,0x9c,0x56,0xba,
+	  0x18,0x84,0xdf,0x57,0x00,0x00,0x01,
+	  0x00 }},
+	{{0x80,0x63,0x84,0x6c,0x17,0xec,0xf0,
+	  0x90,0x8c,0x57,0xed,0x20,0x00,0x06,
+	  0x01 }}
 };
 
 SiS300_LVDSCRT1DataStruct  SiS300_CHTVCRT1ONTSC[]=
 {
- {{0x64,0x4f,0x88,0x5a,0x9f,0x0b,0x3e,
-   0xc0,0x84,0x8f,0x0c,0x20,0x00,0x01,
-   0x00 }},
- {{0x64,0x4f,0x88,0x5a,0x9f,0x0b,0x3e,
-   0xb0,0x8d,0x5d,0x0c,0x00,0x00,0x01,
-   0x00 }},
- {{0x64,0x4f,0x88,0x5a,0x9f,0x0b,0x3e,
-   0xc0,0x84,0x8f,0x0c,0x20,0x00,0x01,
-   0x00 }},
- {{0x64,0x4f,0x88,0x5a,0x9f,0x0b,0x3e,
-   0xb0,0x8d,0x5d,0x0c,0x00,0x00,0x01,
-   0x00 }},
- {{0x5d,0x4f,0x81,0x56,0x9c,0x0b,0x3e,
-   0xe8,0x84,0xdf,0x0c,0x00,0x00,0x01,
-   0x00 }},
- {{0x7d,0x63,0x81,0x6a,0x16,0xba,0xf0,
-   0x7f,0x86,0x57,0xbb,0x00,0x00,0x06,
-   0x01 }}
+	{{0x64,0x4f,0x88,0x5a,0x9f,0x0b,0x3e,
+	  0xc0,0x84,0x8f,0x0c,0x20,0x00,0x01,
+	  0x00 }},
+	{{0x64,0x4f,0x88,0x5a,0x9f,0x0b,0x3e,
+	  0xb0,0x8d,0x5d,0x0c,0x00,0x00,0x01,
+	  0x00 }},
+	{{0x64,0x4f,0x88,0x5a,0x9f,0x0b,0x3e,
+	  0xc0,0x84,0x8f,0x0c,0x20,0x00,0x01,
+	  0x00 }},
+	{{0x64,0x4f,0x88,0x5a,0x9f,0x0b,0x3e,
+	  0xb0,0x8d,0x5d,0x0c,0x00,0x00,0x01,
+	  0x00 }},
+	{{0x5d,0x4f,0x81,0x56,0x9c,0x0b,0x3e,
+	  0xe8,0x84,0xdf,0x0c,0x00,0x00,0x01,
+	  0x00 }},
+	{{0x7d,0x63,0x81,0x6a,0x16,0xba,0xf0,
+	  0x7f,0x86,0x57,0xbb,0x00,0x00,0x06,
+	  0x01 }}
 };
 
 SiS300_LVDSCRT1DataStruct  SiS300_CHTVCRT1UPAL[]=
 {
- {{0x79,0x4f,0x9d,0x5a,0x90,0x6f,0x3e,
-   0xf8,0x83,0x8f,0x70,0x20,0x00,0x05,
-   0x00 }},
- {{0x79,0x4f,0x9d,0x5a,0x90,0x6f,0x3e,
-   0xde,0x81,0x5d,0x70,0x00,0x00,0x05,
-   0x00 }},
- {{0x79,0x4f,0x9d,0x5a,0x90,0x6f,0x3e,
-   0xf8,0x83,0x8f,0x70,0x20,0x00,0x05,
-   0x00 }},
- {{0x79,0x4f,0x9d,0x5a,0x90,0x6f,0x3e,
-   0xde,0x81,0x5d,0x70,0x00,0x00,0x05,
-   0x00 }},
- {{0x64,0x4f,0x88,0x55,0x80,0xec,0xba,
-   0x50,0x84,0xdf,0xed,0x00,0x00,0x05,
-   0x00 }},
- {{0x70,0x63,0x94,0x68,0x8d,0x42,0xf1,
-   0xc8,0x8c,0x57,0xe9,0x20,0x00,0x05,
-   0x01 }}
+	{{0x79,0x4f,0x9d,0x5a,0x90,0x6f,0x3e,
+	  0xf8,0x83,0x8f,0x70,0x20,0x00,0x05,
+	  0x00 }},
+	{{0x79,0x4f,0x9d,0x5a,0x90,0x6f,0x3e,
+	  0xde,0x81,0x5d,0x70,0x00,0x00,0x05,
+	  0x00 }},
+	{{0x79,0x4f,0x9d,0x5a,0x90,0x6f,0x3e,
+	  0xf8,0x83,0x8f,0x70,0x20,0x00,0x05,
+	  0x00 }},
+	{{0x79,0x4f,0x9d,0x5a,0x90,0x6f,0x3e,
+	  0xde,0x81,0x5d,0x70,0x00,0x00,0x05,
+	  0x00 }},
+	{{0x64,0x4f,0x88,0x55,0x80,0xec,0xba,
+	  0x50,0x84,0xdf,0xed,0x00,0x00,0x05,
+	  0x00 }},
+	{{0x70,0x63,0x94,0x68,0x8d,0x42,0xf1,
+	  0xc8,0x8c,0x57,0xe9,0x20,0x00,0x05,
+	  0x01 }}
 };
 
 SiS300_LVDSCRT1DataStruct  SiS300_CHTVCRT1OPAL[]=
 {
- {{0x79,0x4f,0x9d,0x5a,0x90,0x6f,0x3e,
-   0xf0,0x83,0x8f,0x70,0x20,0x00,0x05,
-   0x00 }},
- {{0x79,0x4f,0x9d,0x5a,0x90,0x6f,0x3e,
-   0xde,0x81,0x5d,0x70,0x00,0x00,0x05,
-   0x00 }},
- {{0x79,0x4f,0x9d,0x5a,0x90,0x6f,0x3e,
-   0xf0,0x83,0x8f,0x70,0x20,0x00,0x05,
-   0x00 }},
- {{0x79,0x4f,0x9d,0x5a,0x90,0x6f,0x3e,
-   0xde,0x81,0x5d,0x70,0x00,0x00,0x05,
-   0x00 }},
- {{0x64,0x4f,0x88,0x55,0x80,0x6f,0xba,
-   0x20,0x83,0xdf,0x70,0x00,0x00,0x05,
-   0x00 }},
- {{0x73,0x63,0x97,0x69,0x8e,0xec,0xf0,
-   0x90,0x8c,0x57,0xed,0x20,0x00,0x05,
-   0x01 }}
+	{{0x79,0x4f,0x9d,0x5a,0x90,0x6f,0x3e,
+	  0xf0,0x83,0x8f,0x70,0x20,0x00,0x05,
+	  0x00 }},
+	{{0x79,0x4f,0x9d,0x5a,0x90,0x6f,0x3e,
+	  0xde,0x81,0x5d,0x70,0x00,0x00,0x05,
+	  0x00 }},
+	{{0x79,0x4f,0x9d,0x5a,0x90,0x6f,0x3e,
+	  0xf0,0x83,0x8f,0x70,0x20,0x00,0x05,
+	  0x00 }},
+	{{0x79,0x4f,0x9d,0x5a,0x90,0x6f,0x3e,
+	  0xde,0x81,0x5d,0x70,0x00,0x00,0x05,
+	  0x00 }},
+	{{0x64,0x4f,0x88,0x55,0x80,0x6f,0xba,
+	  0x20,0x83,0xdf,0x70,0x00,0x00,0x05,
+	  0x00 }},
+	{{0x73,0x63,0x97,0x69,0x8e,0xec,0xf0,
+	  0x90,0x8c,0x57,0xed,0x20,0x00,0x05,
+	  0x01 }}
 };
+/* TW: New end */
 
-
-/* TW: TV won't work until these tables are filled with data */
+/* TW: New */
 typedef struct _SiS300_CHTVRegDataStruct
 {
-UCHAR Reg[5];
+	UCHAR Reg[5];
 } SiS300_CHTVRegDataStruct;
-SiS300_CHTVRegDataStruct SiS300_CHTVReg_UNTSC[] =
-{
- {{0x00,0x00,0x00,0x00,0x00}}
-};
 
-SiS300_CHTVRegDataStruct SiS300_CHTVReg_ONTSC[] = 
-{
- {{0x00,0x00,0x00,0x00,0x00}}
-};
-
-SiS300_CHTVRegDataStruct SiS300_CHTVReg_UPAL[] = 
-{
- {{0x00,0x00,0x00,0x00,0x00}}
-};
-
-SiS300_CHTVRegDataStruct SiS300_CHTVReg_OPAL[] = 
-{
- {{0x00,0x00,0x00,0x00,0x00}}
-};
+SiS300_CHTVRegDataStruct SiS300_CHTVReg_UNTSC[] = {
+	{{0x4a,0x94,0x00,0x48,0xfe}},
+	{{0x4a,0x94,0x00,0x48,0xfe}},
+	{{0x4a,0x94,0x00,0x48,0xfe}},
+	{{0x4a,0x94,0x00,0x48,0xfe}},
+	{{0x6a,0x6a,0x00,0x2d,0xfa}}, /* Mode 17: 640x480 NTSC 7/8  */
+	{{0x8d,0xc4,0x00,0x3b,0xfb}}  /* Mode 24: 800x600 NTSC 7/10 */
+};
+
+SiS300_CHTVRegDataStruct SiS300_CHTVReg_ONTSC[] = {
+	{{0x49,0x94,0x00,0x34,0xfe}},
+	{{0x49,0x94,0x00,0x34,0xfe}},
+	{{0x49,0x94,0x00,0x34,0xfe}},
+	{{0x49,0x94,0x00,0x34,0xfe}},
+	{{0x69,0x6a,0x00,0x1e,0xfd}}, /* Mode 16: 640x480 NTSC 1/1 */
+	{{0x8c,0xb4,0x00,0x32,0xf9}}  /* Mode 23: 800x600 NTSC 3/4 */
+};
+
+SiS300_CHTVRegDataStruct SiS300_CHTVReg_UPAL[] = {
+	{{0x41,0x12,0x01,0x50,0x34}},
+	{{0x41,0x12,0x00,0x50,0x00}},
+	{{0x41,0x12,0x01,0x50,0x34}},
+	{{0x41,0x12,0x00,0x50,0x00}},
+	{{0x63,0x94,0x01,0x50,0x30}}, /* Mode 15: 640x480 PAL 5/6 */
+	/* TW: For 800x600, 3/4 is VERY underscan */
+	{{0x84,0x64,0x01,0x4e,0x2f}}  /* Mode 21: 800x600 PAL 3/4 */
+	/* TW: Mode 20 is still underscan, use it instead? */
+	/* {{0x83,0x76,0x01,0x40,0x31}} */ /* Mode 20: 800x600 PAL 5/6 */
+};
+
+SiS300_CHTVRegDataStruct SiS300_CHTVReg_OPAL[] = {
+	{{0x41,0x12,0x01,0x50,0x34}}, /* Mode 9: 640x400 PAL 1/1 */
+	{{0x41,0x12,0x00,0x50,0x00}},
+	{{0x41,0x12,0x01,0x50,0x34}},
+	{{0x41,0x12,0x00,0x50,0x00}},
+	{{0x61,0x94,0x01,0x36,0x30}}, /* Mode 14: 640x480 PAL 1/1 */
+	{{0x83,0x76,0x01,0x40,0x31}}  /* Mode 20: 800x600 PAL 5/6 */
+	/* {{0x81,0x12,0x01,0x50,0x34}}  */ /* TW: (test) Mode 19: 800x600 PAL 1/1 */
+};
+/* TW: New end */
+
+/* TW: New */
+UCHAR SiS300_CHTVVCLKUNTSC[] = {0x29,0x29,0x29,0x29,0x2a,0x2e};
 
-UCHAR SiS300_CHTVVCLKUNTSC[]={0x00 };
+UCHAR SiS300_CHTVVCLKONTSC[] = {0x2c,0x2c,0x2c,0x2c,0x2d,0x2b};
 
-UCHAR SiS300_CHTVVCLKONTSC[]={0x00 };
+UCHAR SiS300_CHTVVCLKUPAL[]  = {0x2f,0x2f,0x2f,0x2f,0x2f,0x31};
 
-UCHAR SiS300_CHTVVCLKUPAL[]={0x00 };
+UCHAR SiS300_CHTVVCLKOPAL[]  = {0x2f,0x2f,0x2f,0x2f,0x30,0x32};
+/* TW: New end */
 
-UCHAR SiS300_CHTVVCLKOPAL[]={0x00 };
 
diff -urN linux-2.4.19-pre9/drivers/video/sis/310vtbl.h linux-2.4.19-pre10/drivers/video/sis/310vtbl.h
--- linux-2.4.19-pre9/drivers/video/sis/310vtbl.h	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/video/sis/310vtbl.h	Mon Jun  3 18:50:56 2002
@@ -1,49 +1,52 @@
 typedef struct _SiS310_StStruct
 {
- UCHAR St_ModeID;
- USHORT St_ModeFlag;
- UCHAR St_StTableIndex;
- UCHAR St_CRT2CRTC;
- UCHAR St_ResInfo;
- UCHAR VB_StTVFlickerIndex;
- UCHAR VB_StTVEdgeIndex;
- UCHAR VB_StTVYFilterIndex;
+	UCHAR St_ModeID;
+	USHORT St_ModeFlag;
+	UCHAR St_StTableIndex;
+	UCHAR St_CRT2CRTC;
+	UCHAR St_ResInfo;
+	UCHAR VB_StTVFlickerIndex;
+	UCHAR VB_StTVEdgeIndex;
+	UCHAR VB_StTVYFilterIndex;
 } SiS310_StStruct;
+
 SiS310_StStruct SiS310_SModeIDTable[]=
-{ {0x01,0x9208,0x01,0x00,0x00,0x00,0x01,0x00},
- {0x01,0x1210,0x14,0x01,0x01,0x00,0x01,0x00},
- {0x01,0x1010,0x17,0x02,0x02,0x00,0x01,0x01},
- {0x03,0x8208,0x03,0x00,0x00,0x00,0x01,0x02},
- {0x03,0x0210,0x16,0x01,0x01,0x00,0x01,0x02},
- {0x03,0x0010,0x18,0x02,0x02,0x00,0x01,0x03},
- {0x05,0x9209,0x05,0x00,0x00,0x00,0x00,0x04},
- {0x06,0x8209,0x06,0x00,0x00,0x00,0x00,0x05},
- {0x07,0x0000,0x07,0x03,0x03,0x00,0x01,0x03},
- {0x07,0x0000,0x19,0x02,0x02,0x00,0x01,0x03},
- {0x0d,0x920a,0x0d,0x00,0x00,0x00,0x00,0x04},
- {0x0e,0x820a,0x0e,0x00,0x00,0x00,0x00,0x05},
- {0x0f,0x0202,0x11,0x01,0x01,0x00,0x00,0x05},
- {0x10,0x0212,0x12,0x01,0x01,0x00,0x00,0x05},
- {0x11,0x0212,0x1a,0x04,0x04,0x00,0x00,0x05},
- {0x12,0x0212,0x1b,0x04,0x04,0x00,0x00,0x05},
- {0x13,0x021b,0x1c,0x00,0x00,0x00,0x00,0x04},
- {0x12,0x0010,0x18,0x02,0x02,0x00,0x00,0x05},
- {0x12,0x0210,0x18,0x01,0x01,0x00,0x00,0x05},
- {0xff,0x0000,0x00,0x00,0x00,0x00,0x00,0x00}
+{
+	{0x01,0x9208,0x01,0x00,0x00,0x00,0x01,0x00},
+	{0x01,0x1210,0x14,0x01,0x01,0x00,0x01,0x00},
+	{0x01,0x1010,0x17,0x02,0x02,0x00,0x01,0x01},
+	{0x03,0x8208,0x03,0x00,0x00,0x00,0x01,0x02},
+	{0x03,0x0210,0x16,0x01,0x01,0x00,0x01,0x02},
+	{0x03,0x0010,0x18,0x02,0x02,0x00,0x01,0x03},
+	{0x05,0x9209,0x05,0x00,0x00,0x00,0x00,0x04},
+	{0x06,0x8209,0x06,0x00,0x00,0x00,0x00,0x05},
+	{0x07,0x0000,0x07,0x03,0x03,0x00,0x01,0x03},
+	{0x07,0x0000,0x19,0x02,0x02,0x00,0x01,0x03},
+	{0x0d,0x920a,0x0d,0x00,0x00,0x00,0x00,0x04},
+	{0x0e,0x820a,0x0e,0x00,0x00,0x00,0x00,0x05},
+	{0x0f,0x0202,0x11,0x01,0x01,0x00,0x00,0x05},
+	{0x10,0x0212,0x12,0x01,0x01,0x00,0x00,0x05},
+	{0x11,0x0212,0x1a,0x04,0x04,0x00,0x00,0x05},
+	{0x12,0x0212,0x1b,0x04,0x04,0x00,0x00,0x05},
+	{0x13,0x021b,0x1c,0x00,0x00,0x00,0x00,0x04},
+	{0x12,0x0010,0x18,0x02,0x02,0x00,0x00,0x05},
+	{0x12,0x0210,0x18,0x01,0x01,0x00,0x00,0x05},
+	{0xff,0x0000,0x00,0x00,0x00,0x00,0x00,0x00}
 };
 
 typedef struct _SiS310_StandTableStruct
 {
- UCHAR CRT_COLS;
- UCHAR ROWS;
- UCHAR CHAR_HEIGHT;
- USHORT CRT_LEN;
- UCHAR SR[4];
- UCHAR MISC;
- UCHAR CRTC[0x19];
- UCHAR ATTR[0x14];
- UCHAR GRC[9];
+	UCHAR CRT_COLS;
+	UCHAR ROWS;
+	UCHAR CHAR_HEIGHT;
+	USHORT CRT_LEN;
+	UCHAR SR[4];
+	UCHAR MISC;
+	UCHAR CRTC[0x19];
+	UCHAR ATTR[0x14];
+	UCHAR GRC[9];
 } SiS310_StandTableStruct;
+
 SiS310_StandTableStruct SiS310_StandTable[]=
 {
 /* MD_0_200 */
@@ -484,164 +487,166 @@
 
 typedef struct _SiS310_ExtStruct
 {
- UCHAR Ext_ModeID;
- USHORT Ext_ModeFlag;
- USHORT Ext_ModeInfo;
- USHORT Ext_Point;
- USHORT Ext_VESAID;
- UCHAR Ext_VESAMEMSize;
- UCHAR Ext_RESINFO;
- UCHAR VB_ExtTVFlickerIndex;
- UCHAR VB_ExtTVEdgeIndex;
- UCHAR VB_ExtTVYFilterIndex;
- UCHAR REFindex;
+	UCHAR Ext_ModeID;
+	USHORT Ext_ModeFlag;
+	USHORT Ext_ModeInfo;
+	USHORT Ext_Point;
+	USHORT Ext_VESAID;
+	UCHAR Ext_VESAMEMSize;
+	UCHAR Ext_RESINFO;
+	UCHAR VB_ExtTVFlickerIndex;
+	UCHAR VB_ExtTVEdgeIndex;
+	UCHAR VB_ExtTVYFilterIndex;
+	UCHAR REFindex;
 } SiS310_ExtStruct;
+
 SiS310_ExtStruct  SiS310_EModeIDTable[]=
 {
- {0x6a,0x2212,0x0407,0x3a81,0x0102,0x08,0x07,0x00,0x00,0x07,0x00},
- {0x2e,0x0a1b,0x0306,0x3a57,0x0101,0x08,0x06,0x00,0x00,0x05,0x08},
- {0x2f,0x0a1b,0x0305,0x3a50,0x0100,0x08,0x05,0x00,0x00,0x05,0x10},
- {0x30,0x2a1b,0x0407,0x3a81,0x0103,0x08,0x07,0x00,0x00,0x07,0x00},
- {0x31,0x0a1b,0x030d,0x3b85,0x0000,0x08,0x0d,0x00,0x00,0x06,0x11},
- {0x32,0x0a1b,0x0a0e,0x3b8c,0x0000,0x08,0x0e,0x00,0x00,0x06,0x12},
- {0x33,0x0a1d,0x0a0d,0x3b85,0x0000,0x08,0x0d,0x00,0x00,0x06,0x11},
- {0x34,0x2a1d,0x0a0e,0x3b8c,0x0000,0x08,0x0e,0x00,0x00,0x06,0x12},
- {0x35,0x0a1f,0x0a0d,0x3b85,0x0000,0x08,0x0d,0x00,0x00,0x06,0x11},
- {0x36,0x2a1f,0x0a0e,0x3b8c,0x0000,0x08,0x0e,0x00,0x00,0x06,0x12},
- {0x37,0x0212,0x0508,0x3aab,0x0104,0x08,0x08,0x00,0x00,0x00,0x13},
- {0x38,0x0a1b,0x0508,0x3aab,0x0105,0x08,0x08,0x00,0x00,0x00,0x13},
- {0x3a,0x0e3b,0x0609,0x3adc,0x0107,0x08,0x09,0x00,0x00,0x00,0x1a},
- {0x3c,0x063b,0x070a,0x3af2,0x0130,0x08,0x0a,0x00,0x00,0x00,0x1e},
- {0x3d,0x067d,0x070a,0x3af2,0x0131,0x08,0x0a,0x00,0x00,0x00,0x1e},
- {0x40,0x9a1c,0x0000,0x3a34,0x010d,0x08,0x00,0x00,0x00,0x04,0x25},
- {0x41,0x9a1d,0x0000,0x3a34,0x010e,0x08,0x00,0x00,0x00,0x04,0x25},
- {0x43,0x0a1c,0x0306,0x3a57,0x0110,0x08,0x06,0x00,0x00,0x05,0x08},
- {0x44,0x0a1d,0x0306,0x3a57,0x0111,0x08,0x06,0x00,0x00,0x05,0x08},
- {0x46,0x2a1c,0x0407,0x3a81,0x0113,0x08,0x07,0x00,0x00,0x07,0x00},
- {0x47,0x2a1d,0x0407,0x3a81,0x0114,0x08,0x07,0x00,0x00,0x07,0x00},
- {0x49,0x0a3c,0x0508,0x3aab,0x0116,0x08,0x08,0x00,0x00,0x00,0x13},
- {0x4a,0x0a3d,0x0508,0x3aab,0x0117,0x08,0x08,0x00,0x00,0x00,0x13},
- {0x4c,0x0e7c,0x0609,0x3adc,0x0119,0x08,0x09,0x00,0x00,0x00,0x1a},
- {0x4d,0x0e7d,0x0609,0x3adc,0x011a,0x08,0x09,0x00,0x00,0x00,0x1a},
- {0x50,0x9a1b,0x0001,0x3a3b,0x0132,0x08,0x01,0x00,0x00,0x04,0x26},
- {0x51,0xba1b,0x0103,0x3a42,0x0133,0x08,0x03,0x00,0x00,0x07,0x27},
- {0x52,0x9a1b,0x0204,0x3a49,0x0134,0x08,0x04,0x00,0x00,0x00,0x28},
- {0x56,0x9a1d,0x0001,0x3a3b,0x0135,0x08,0x01,0x00,0x00,0x04,0x26},
- {0x57,0xba1d,0x0103,0x3a42,0x0136,0x08,0x03,0x00,0x00,0x07,0x27},
- {0x58,0x9a1d,0x0204,0x3a49,0x0137,0x08,0x04,0x00,0x00,0x00,0x28},
- {0x59,0x9a1b,0x0000,0x3a34,0x0138,0x08,0x00,0x00,0x00,0x04,0x25},
- {0x5A,0x021b,0x0014,0x3b83,0x0138,0x08,0x01,0x00,0x00,0x04,0x3f}, /*fstn add new mode*/
- {0x5B,0x0a1d,0x0014,0x3b83,0x0135,0x08,0x01,0x00,0x00,0x04,0x3f}, /*fstn add new mode*/
- {0x5d,0x0a1d,0x0305,0x3a50,0x0139,0x08,0x05,0x00,0x00,0x07,0x10},
- {0x62,0x0a3f,0x0306,0x3a57,0x013a,0x08,0x06,0x00,0x00,0x05,0x08},
- {0x63,0x2a3f,0x0407,0x3a81,0x013b,0x08,0x07,0x00,0x00,0x07,0x00},
- {0x64,0x0a7f,0x0508,0x3aab,0x013c,0x08,0x08,0x00,0x00,0x00,0x13},
- {0x65,0x0eff,0x0609,0x3adc,0x013d,0x08,0x09,0x00,0x00,0x00,0x1a},
- {0x66,0x06ff,0x070a,0x3af2,0x013e,0x08,0x0a,0x00,0x00,0x00,0x1e},
- {0x68,0x067b,0x080b,0x3b17,0x013f,0x08,0x0b,0x00,0x00,0x00,0x29},
- {0x69,0x06fd,0x080b,0x3b17,0x0140,0x08,0x0b,0x00,0x00,0x00,0x29},
- {0x6b,0x07ff,0x080b,0x3b17,0x0141,0x10,0x0b,0x00,0x00,0x00,0x29},
- {0x6c,0x067b,0x090c,0x3b37,0x0000,0x08,0x0c,0x00,0x00,0x00,0x2f},
- {0x6d,0x06fd,0x090c,0x3b37,0x0000,0x10,0x0c,0x00,0x00,0x00,0x2f},
- {0x6e,0x07ff,0x090c,0x3b37,0x0000,0x10,0x0c,0x00,0x00,0x00,0x2f},
- {0x70,0x2a1b,0x0410,0x3b52,0x0000,0x08,0x10,0x00,0x00,0x07,0x34},
- {0x71,0x0a1b,0x0511,0x3b63,0x0000,0x08,0x11,0x00,0x00,0x00,0x37},
- {0x74,0x0a1d,0x0511,0x3b63,0x0000,0x08,0x11,0x00,0x00,0x00,0x37},
- {0x75,0x0a3d,0x0612,0x3b74,0x0000,0x08,0x12,0x00,0x00,0x00,0x3a},
- {0x76,0x2a1f,0x0410,0x3b52,0x0000,0x08,0x10,0x00,0x00,0x07,0x34},
- {0x77,0x0a1f,0x0511,0x3b63,0x0000,0x08,0x11,0x00,0x00,0x00,0x37},
- {0x78,0x0a3f,0x0612,0x3b74,0x0000,0x08,0x12,0x00,0x00,0x00,0x3a},
- {0x79,0x0a3b,0x0612,0x3b74,0x0000,0x08,0x12,0x00,0x00,0x00,0x3a},
- {0x7a,0x2a1d,0x0410,0x3b52,0x0000,0x08,0x10,0x00,0x00,0x07,0x34},
- {0x7b,0x0e3b,0x060f,0x3ad0,0x0000,0x08,0x0f,0x00,0x00,0x00,0x3d},
- {0x7c,0x0e7d,0x060f,0x3ad0,0x0000,0x08,0x0f,0x00,0x00,0x00,0x3d},
- {0x7d,0x0eff,0x060f,0x3ad0,0x0000,0x08,0x0f,0x00,0x00,0x00,0x3d},
- {0xff,0x0000,0x0000,0x0000,0x0000,0x00,0x00,0x00,0x00,0x00,0x00}
+	{0x6a,0x2212,0x0407,0x3a81,0x0102,0x08,0x07,0x00,0x00,0x07,0x00},
+	{0x2e,0x0a1b,0x0306,0x3a57,0x0101,0x08,0x06,0x00,0x00,0x05,0x08},
+	{0x2f,0x0a1b,0x0305,0x3a50,0x0100,0x08,0x05,0x00,0x00,0x05,0x10},
+	{0x30,0x2a1b,0x0407,0x3a81,0x0103,0x08,0x07,0x00,0x00,0x07,0x00},
+	{0x31,0x0a1b,0x030d,0x3b85,0x0000,0x08,0x0d,0x00,0x00,0x06,0x11},
+	{0x32,0x0a1b,0x0a0e,0x3b8c,0x0000,0x08,0x0e,0x00,0x00,0x06,0x12},
+	{0x33,0x0a1d,0x0a0d,0x3b85,0x0000,0x08,0x0d,0x00,0x00,0x06,0x11},
+	{0x34,0x2a1d,0x0a0e,0x3b8c,0x0000,0x08,0x0e,0x00,0x00,0x06,0x12},
+	{0x35,0x0a1f,0x0a0d,0x3b85,0x0000,0x08,0x0d,0x00,0x00,0x06,0x11},
+	{0x36,0x2a1f,0x0a0e,0x3b8c,0x0000,0x08,0x0e,0x00,0x00,0x06,0x12},
+	{0x37,0x0212,0x0508,0x3aab,0x0104,0x08,0x08,0x00,0x00,0x00,0x13},
+	{0x38,0x0a1b,0x0508,0x3aab,0x0105,0x08,0x08,0x00,0x00,0x00,0x13},
+	{0x3a,0x0e3b,0x0609,0x3adc,0x0107,0x08,0x09,0x00,0x00,0x00,0x1a},
+	{0x3c,0x063b,0x070a,0x3af2,0x0130,0x08,0x0a,0x00,0x00,0x00,0x1e},
+	{0x3d,0x067d,0x070a,0x3af2,0x0131,0x08,0x0a,0x00,0x00,0x00,0x1e},
+	{0x40,0x9a1c,0x0000,0x3a34,0x010d,0x08,0x00,0x00,0x00,0x04,0x25},
+	{0x41,0x9a1d,0x0000,0x3a34,0x010e,0x08,0x00,0x00,0x00,0x04,0x25},
+	{0x43,0x0a1c,0x0306,0x3a57,0x0110,0x08,0x06,0x00,0x00,0x05,0x08},
+	{0x44,0x0a1d,0x0306,0x3a57,0x0111,0x08,0x06,0x00,0x00,0x05,0x08},
+	{0x46,0x2a1c,0x0407,0x3a81,0x0113,0x08,0x07,0x00,0x00,0x07,0x00},
+	{0x47,0x2a1d,0x0407,0x3a81,0x0114,0x08,0x07,0x00,0x00,0x07,0x00},
+	{0x49,0x0a3c,0x0508,0x3aab,0x0116,0x08,0x08,0x00,0x00,0x00,0x13},
+	{0x4a,0x0a3d,0x0508,0x3aab,0x0117,0x08,0x08,0x00,0x00,0x00,0x13},
+	{0x4c,0x0e7c,0x0609,0x3adc,0x0119,0x08,0x09,0x00,0x00,0x00,0x1a},
+	{0x4d,0x0e7d,0x0609,0x3adc,0x011a,0x08,0x09,0x00,0x00,0x00,0x1a},
+	{0x50,0x9a1b,0x0001,0x3a3b,0x0132,0x08,0x01,0x00,0x00,0x04,0x26},
+	{0x51,0xba1b,0x0103,0x3a42,0x0133,0x08,0x03,0x00,0x00,0x07,0x27},
+	{0x52,0x9a1b,0x0204,0x3a49,0x0134,0x08,0x04,0x00,0x00,0x00,0x28},
+	{0x56,0x9a1d,0x0001,0x3a3b,0x0135,0x08,0x01,0x00,0x00,0x04,0x26},
+	{0x57,0xba1d,0x0103,0x3a42,0x0136,0x08,0x03,0x00,0x00,0x07,0x27},
+	{0x58,0x9a1d,0x0204,0x3a49,0x0137,0x08,0x04,0x00,0x00,0x00,0x28},
+	{0x59,0x9a1b,0x0000,0x3a34,0x0138,0x08,0x00,0x00,0x00,0x04,0x25},
+	{0x5A,0x021b,0x0014,0x3b83,0x0138,0x08,0x01,0x00,0x00,0x04,0x3f}, /*fstn add new mode*/
+	{0x5B,0x0a1d,0x0014,0x3b83,0x0135,0x08,0x01,0x00,0x00,0x04,0x3f}, /*fstn add new mode*/
+	{0x5d,0x0a1d,0x0305,0x3a50,0x0139,0x08,0x05,0x00,0x00,0x07,0x10},
+	{0x62,0x0a3f,0x0306,0x3a57,0x013a,0x08,0x06,0x00,0x00,0x05,0x08},
+	{0x63,0x2a3f,0x0407,0x3a81,0x013b,0x08,0x07,0x00,0x00,0x07,0x00},
+	{0x64,0x0a7f,0x0508,0x3aab,0x013c,0x08,0x08,0x00,0x00,0x00,0x13},
+	{0x65,0x0eff,0x0609,0x3adc,0x013d,0x08,0x09,0x00,0x00,0x00,0x1a},
+	{0x66,0x06ff,0x070a,0x3af2,0x013e,0x08,0x0a,0x00,0x00,0x00,0x1e},
+	{0x68,0x067b,0x080b,0x3b17,0x013f,0x08,0x0b,0x00,0x00,0x00,0x29},
+	{0x69,0x06fd,0x080b,0x3b17,0x0140,0x08,0x0b,0x00,0x00,0x00,0x29},
+	{0x6b,0x07ff,0x080b,0x3b17,0x0141,0x10,0x0b,0x00,0x00,0x00,0x29},
+	{0x6c,0x067b,0x090c,0x3b37,0x0000,0x08,0x0c,0x00,0x00,0x00,0x2f},
+	{0x6d,0x06fd,0x090c,0x3b37,0x0000,0x10,0x0c,0x00,0x00,0x00,0x2f},
+	{0x6e,0x07ff,0x090c,0x3b37,0x0000,0x10,0x0c,0x00,0x00,0x00,0x2f},
+	{0x70,0x2a1b,0x0410,0x3b52,0x0000,0x08,0x10,0x00,0x00,0x07,0x34},
+	{0x71,0x0a1b,0x0511,0x3b63,0x0000,0x08,0x11,0x00,0x00,0x00,0x37},
+	{0x74,0x0a1d,0x0511,0x3b63,0x0000,0x08,0x11,0x00,0x00,0x00,0x37},
+	{0x75,0x0a3d,0x0612,0x3b74,0x0000,0x08,0x12,0x00,0x00,0x00,0x3a},
+	{0x76,0x2a1f,0x0410,0x3b52,0x0000,0x08,0x10,0x00,0x00,0x07,0x34},
+	{0x77,0x0a1f,0x0511,0x3b63,0x0000,0x08,0x11,0x00,0x00,0x00,0x37},
+	{0x78,0x0a3f,0x0612,0x3b74,0x0000,0x08,0x12,0x00,0x00,0x00,0x3a},
+	{0x79,0x0a3b,0x0612,0x3b74,0x0000,0x08,0x12,0x00,0x00,0x00,0x3a},
+	{0x7a,0x2a1d,0x0410,0x3b52,0x0000,0x08,0x10,0x00,0x00,0x07,0x34},
+	{0x7b,0x0e3b,0x060f,0x3ad0,0x0000,0x08,0x0f,0x00,0x00,0x00,0x3d},
+	{0x7c,0x0e7d,0x060f,0x3ad0,0x0000,0x08,0x0f,0x00,0x00,0x00,0x3d},
+	{0x7d,0x0eff,0x060f,0x3ad0,0x0000,0x08,0x0f,0x00,0x00,0x00,0x3d},
+	{0xff,0x0000,0x0000,0x0000,0x0000,0x00,0x00,0x00,0x00,0x00,0x00}
 };
 
 typedef struct _SiS310_Ext2Struct
 {
- USHORT Ext_InfoFlag;
- UCHAR Ext_CRT1CRTC;
- UCHAR Ext_CRTVCLK;
- UCHAR Ext_CRT2CRTC;
- UCHAR  ModeID;
- USHORT XRes;
- USHORT YRes;
- USHORT ROM_OFFSET;
+	USHORT Ext_InfoFlag;
+	UCHAR Ext_CRT1CRTC;
+	UCHAR Ext_CRTVCLK;
+	UCHAR Ext_CRT2CRTC;
+	UCHAR  ModeID;
+	USHORT XRes;
+	USHORT YRes;
+	USHORT ROM_OFFSET;
 } SiS310_Ext2Struct;
+
 SiS310_Ext2Struct SiS310_RefIndex[]=
 {
- {0x005f,0x0d,0x03,0x05,0x6a, 800, 600,0x3a81}, /* 0x0 */
- {0x0467,0x0e,0x04,0x05,0x6a, 800, 600,0x3a86}, /* 0x1 */
- {0x0067,0x0f,0x08,0x48,0x6a, 800, 600,0x3a8b}, /* 0x2 */
- {0x0067,0x10,0x07,0x8b,0x6a, 800, 600,0x3a90}, /* 0x3 */
- {0x0147,0x11,0x0a,0x00,0x6a, 800, 600,0x3a95}, /* 0x4 */
- {0x4147,0x12,0x0d,0x00,0x6a, 800, 600,0x3a9a}, /* 0x5 */
- {0x4047,0x13,0x13,0x00,0x6a, 800, 600,0x3a9f}, /* 0x6 */
- {0x4047,0x14,0x1c,0x00,0x6a, 800, 600,0x3aa4}, /* 0x7 */
- {0xc05f,0x05,0x00,0x04,0x2e, 640, 480,0x3a57}, /* 0x8 */
- {0xc067,0x06,0x02,0x04,0x2e, 640, 480,0x3a5c}, /* 0x9 */
- {0xc067,0x07,0x02,0x47,0x2e, 640, 480,0x3a61}, /* 0xa */
- {0xc067,0x08,0x03,0x8a,0x2e, 640, 480,0x3a66}, /* 0xb */
- {0x4047,0x09,0x05,0x00,0x2e, 640, 480,0x3a6b}, /* 0xc */
- {0x4047,0x0a,0x09,0x00,0x2e, 640, 480,0x3a70}, /* 0xd */
- {0x4047,0x0b,0x0e,0x00,0x2e, 640, 480,0x3a75}, /* 0xe */
- {0xc047,0x0c,0x15,0x00,0x2e, 640, 480,0x3a7a}, /* 0xf */
- {0x407f,0x04,0x00,0x00,0x2f, 640, 400,0x3a50}, /* 0x10 */
- {0xc00f,0x3c,0x01,0x06,0x31, 720, 480,0x3b85}, /* 0x11 */
- {0x000f,0x3d,0x03,0x06,0x32, 720, 576,0x3b8c}, /* 0x12 */
- {0x0187,0x15,0x06,0x00,0x37,1024, 768,0x3aab}, /* 0x13 */
- {0xc877,0x16,0x0b,0x06,0x37,1024, 768,0x3ab0}, /* 0x14 301b TV1024x768*/
- {0xc067,0x17,0x0f,0x49,0x37,1024, 768,0x3ab5}, /* 0x15 */
- {0x0267,0x18,0x11,0x00,0x37,1024, 768,0x3aba}, /* 0x16 */
- {0x0047,0x19,0x16,0x8c,0x37,1024, 768,0x3abf}, /* 0x17 */
- {0x4047,0x1a,0x1b,0x00,0x37,1024, 768,0x3ac4}, /* 0x18 */
- {0x4047,0x1b,0x1f,0x00,0x37,1024, 768,0x3ac9}, /* 0x19 */
- {0x0387,0x1c,0x11,0x00,0x3a,1280,1024,0x3adc}, /* 0x1a */
- {0x0077,0x1d,0x19,0x07,0x3a,1280,1024,0x3ae1}, /* 0x1b */
- {0x0047,0x1e,0x1e,0x00,0x3a,1280,1024,0x3ae6}, /* 0x1c */
- {0x0007,0x1f,0x20,0x00,0x3a,1280,1024,0x3aeb}, /* 0x1d */
- {0x0007,0x20,0x21,0x00,0x3c,1600,1200,0x3af2}, /* 0x1e */
- {0x0007,0x21,0x22,0x00,0x3c,1600,1200,0x3af7}, /* 0x1f */
- {0x0007,0x22,0x23,0x00,0x3c,1600,1200,0x3afc}, /* 0x20 */
- {0x0007,0x23,0x25,0x00,0x3c,1600,1200,0x3b01}, /* 0x21 */
- {0x0007,0x24,0x26,0x00,0x3c,1600,1200,0x3b06}, /* 0x22 */
- {0x0007,0x25,0x2c,0x00,0x3c,1600,1200,0x3b0b}, /* 0x23 */
- {0x0007,0x26,0x34,0x00,0x3c,1600,1200,0x3b10}, /* 0x24 */
- {0x407f,0x00,0x00,0x00,0x40, 320, 200,0x3a34}, /* 0x25 */
- {0xc07f,0x01,0x00,0x04,0x50, 320, 240,0x3a3b}, /* 0x26 */
- {0x007f,0x02,0x04,0x05,0x51, 400, 300,0x3a42}, /* 0x27 */
- {0xc077,0x03,0x0b,0x06,0x52, 512, 384,0x3a49}, /* 0x28 */
- {0x8007,0x27,0x27,0x00,0x68,1920,1440,0x3b17}, /* 0x29 */
- {0x4007,0x28,0x29,0x00,0x68,1920,1440,0x3b1c}, /* 0x2a */
- {0x4007,0x29,0x2e,0x00,0x68,1920,1440,0x3b21}, /* 0x2b */
- {0x4007,0x2a,0x30,0x00,0x68,1920,1440,0x3b26}, /* 0x2c */
- {0x4007,0x2b,0x35,0x00,0x68,1920,1440,0x3b2b}, /* 0x2d */
- {0x4005,0x2c,0x39,0x00,0x68,1920,1440,0x3b30}, /* 0x2e */
- {0x4007,0x2d,0x2b,0x00,0x6c,2048,1536,0x3b37}, /* 0x2f */
- {0x4007,0x2e,0x31,0x00,0x6c,2048,1536,0x3b3c}, /* 0x30 */
- {0x4007,0x2f,0x33,0x00,0x6c,2048,1536,0x3b41}, /* 0x31 */
- {0x4007,0x30,0x37,0x00,0x6c,2048,1536,0x3b46}, /* 0x32 */
- {0x4005,0x31,0x38,0x00,0x6c,2048,1536,0x3b4b}, /* 0x33 */
- {0x0057,0x32,0x40,0x08,0x70, 800, 480,0x3b52}, /* 0x34 */
- {0x0047,0x33,0x07,0x08,0x70, 800, 480,0x3b57}, /* 0x35 */
- {0x0047,0x34,0x0a,0x08,0x70, 800, 480,0x3b5c}, /* 0x36 */
- {0x0057,0x35,0x0b,0x09,0x71,1024, 576,0x3b63}, /* 0x37 */
- {0x0047,0x36,0x11,0x09,0x71,1024, 576,0x3b68}, /* 0x38 */
- {0x0047,0x37,0x16,0x09,0x71,1024, 576,0x3b6d}, /* 0x39 */
- {0x0057,0x38,0x19,0x0a,0x75,1280, 720,0x3b74}, /* 0x3a */
- {0x0047,0x39,0x1e,0x0a,0x75,1280, 720,0x3b79}, /* 0x3b */
- {0x0047,0x3a,0x20,0x0a,0x75,1280, 720,0x3b7e}, /* 0x3c */
- {0x0027,0x3b,0x19,0x08,0x7b,1280, 960,0x3ad0}, /* 0x3d */
- {0x0027,0x3b,0x19,0x08,0x7b,1280, 960,0x3ad5}, /* 0x3e */
- {0xc07f,0x01,0x00,0x06,0x5a, 320, 480,0x3b83}, /* 0x3f */    /*fstn add new mode */
- {0xffff,0x00,0x00,0x00,0x00,0000,0000,0x0000}
+	{0x005f,0x0d,0x03,0x05,0x6a, 800, 600,0x3a81}, /* 0x0 */
+	{0x0467,0x0e,0x04,0x05,0x6a, 800, 600,0x3a86}, /* 0x1 */
+	{0x0067,0x0f,0x08,0x48,0x6a, 800, 600,0x3a8b}, /* 0x2 */
+	{0x0067,0x10,0x07,0x8b,0x6a, 800, 600,0x3a90}, /* 0x3 */
+	{0x0147,0x11,0x0a,0x00,0x6a, 800, 600,0x3a95}, /* 0x4 */
+	{0x4147,0x12,0x0d,0x00,0x6a, 800, 600,0x3a9a}, /* 0x5 */
+	{0x4047,0x13,0x13,0x00,0x6a, 800, 600,0x3a9f}, /* 0x6 */
+	{0x4047,0x14,0x1c,0x00,0x6a, 800, 600,0x3aa4}, /* 0x7 */
+	{0xc05f,0x05,0x00,0x04,0x2e, 640, 480,0x3a57}, /* 0x8 */
+	{0xc067,0x06,0x02,0x04,0x2e, 640, 480,0x3a5c}, /* 0x9 */
+	{0xc067,0x07,0x02,0x47,0x2e, 640, 480,0x3a61}, /* 0xa */
+	{0xc067,0x08,0x03,0x8a,0x2e, 640, 480,0x3a66}, /* 0xb */
+	{0x4047,0x09,0x05,0x00,0x2e, 640, 480,0x3a6b}, /* 0xc */
+	{0x4047,0x0a,0x09,0x00,0x2e, 640, 480,0x3a70}, /* 0xd */
+	{0x4047,0x0b,0x0e,0x00,0x2e, 640, 480,0x3a75}, /* 0xe */
+	{0xc047,0x0c,0x15,0x00,0x2e, 640, 480,0x3a7a}, /* 0xf */
+	{0x407f,0x04,0x00,0x00,0x2f, 640, 400,0x3a50}, /* 0x10 */
+	{0xc00f,0x3c,0x01,0x06,0x31, 720, 480,0x3b85}, /* 0x11 */
+	{0x000f,0x3d,0x03,0x06,0x32, 720, 576,0x3b8c}, /* 0x12 */
+	{0x0187,0x15,0x06,0x00,0x37,1024, 768,0x3aab}, /* 0x13 */
+	{0xc877,0x16,0x0b,0x06,0x37,1024, 768,0x3ab0}, /* 0x14 301b TV1024x768*/
+	{0xc067,0x17,0x0f,0x49,0x37,1024, 768,0x3ab5}, /* 0x15 */
+	{0x0267,0x18,0x11,0x00,0x37,1024, 768,0x3aba}, /* 0x16 */
+	{0x0047,0x19,0x16,0x8c,0x37,1024, 768,0x3abf}, /* 0x17 */
+	{0x4047,0x1a,0x1b,0x00,0x37,1024, 768,0x3ac4}, /* 0x18 */
+	{0x4047,0x1b,0x1f,0x00,0x37,1024, 768,0x3ac9}, /* 0x19 */
+	{0x0387,0x1c,0x11,0x00,0x3a,1280,1024,0x3adc}, /* 0x1a */
+	{0x0077,0x1d,0x19,0x07,0x3a,1280,1024,0x3ae1}, /* 0x1b */
+	{0x0047,0x1e,0x1e,0x00,0x3a,1280,1024,0x3ae6}, /* 0x1c */
+	{0x0007,0x1f,0x20,0x00,0x3a,1280,1024,0x3aeb}, /* 0x1d */
+	{0x0007,0x20,0x21,0x00,0x3c,1600,1200,0x3af2}, /* 0x1e */
+	{0x0007,0x21,0x22,0x00,0x3c,1600,1200,0x3af7}, /* 0x1f */
+	{0x0007,0x22,0x23,0x00,0x3c,1600,1200,0x3afc}, /* 0x20 */
+	{0x0007,0x23,0x25,0x00,0x3c,1600,1200,0x3b01}, /* 0x21 */
+	{0x0007,0x24,0x26,0x00,0x3c,1600,1200,0x3b06}, /* 0x22 */
+	{0x0007,0x25,0x2c,0x00,0x3c,1600,1200,0x3b0b}, /* 0x23 */
+	{0x0007,0x26,0x34,0x00,0x3c,1600,1200,0x3b10}, /* 0x24 */
+	{0x407f,0x00,0x00,0x00,0x40, 320, 200,0x3a34}, /* 0x25 */
+	{0xc07f,0x01,0x00,0x04,0x50, 320, 240,0x3a3b}, /* 0x26 */
+	{0x007f,0x02,0x04,0x05,0x51, 400, 300,0x3a42}, /* 0x27 */
+	{0xc077,0x03,0x0b,0x06,0x52, 512, 384,0x3a49}, /* 0x28 */
+	{0x8007,0x27,0x27,0x00,0x68,1920,1440,0x3b17}, /* 0x29 */
+	{0x4007,0x28,0x29,0x00,0x68,1920,1440,0x3b1c}, /* 0x2a */
+	{0x4007,0x29,0x2e,0x00,0x68,1920,1440,0x3b21}, /* 0x2b */
+	{0x4007,0x2a,0x30,0x00,0x68,1920,1440,0x3b26}, /* 0x2c */
+	{0x4007,0x2b,0x35,0x00,0x68,1920,1440,0x3b2b}, /* 0x2d */
+	{0x4005,0x2c,0x39,0x00,0x68,1920,1440,0x3b30}, /* 0x2e */
+	{0x4007,0x2d,0x2b,0x00,0x6c,2048,1536,0x3b37}, /* 0x2f */
+	{0x4007,0x2e,0x31,0x00,0x6c,2048,1536,0x3b3c}, /* 0x30 */
+	{0x4007,0x2f,0x33,0x00,0x6c,2048,1536,0x3b41}, /* 0x31 */
+	{0x4007,0x30,0x37,0x00,0x6c,2048,1536,0x3b46}, /* 0x32 */
+	{0x4005,0x31,0x38,0x00,0x6c,2048,1536,0x3b4b}, /* 0x33 */
+	{0x0057,0x32,0x40,0x08,0x70, 800, 480,0x3b52}, /* 0x34 */
+	{0x0047,0x33,0x07,0x08,0x70, 800, 480,0x3b57}, /* 0x35 */
+	{0x0047,0x34,0x0a,0x08,0x70, 800, 480,0x3b5c}, /* 0x36 */
+	{0x0057,0x35,0x0b,0x09,0x71,1024, 576,0x3b63}, /* 0x37 */
+	{0x0047,0x36,0x11,0x09,0x71,1024, 576,0x3b68}, /* 0x38 */
+	{0x0047,0x37,0x16,0x09,0x71,1024, 576,0x3b6d}, /* 0x39 */
+	{0x0057,0x38,0x19,0x0a,0x75,1280, 720,0x3b74}, /* 0x3a */
+	{0x0047,0x39,0x1e,0x0a,0x75,1280, 720,0x3b79}, /* 0x3b */
+	{0x0047,0x3a,0x20,0x0a,0x75,1280, 720,0x3b7e}, /* 0x3c */
+	{0x0027,0x3b,0x19,0x08,0x7b,1280, 960,0x3ad0}, /* 0x3d */
+	{0x0027,0x3b,0x19,0x08,0x7b,1280, 960,0x3ad5}, /* 0x3e */
+	{0xc07f,0x01,0x00,0x06,0x5a, 320, 480,0x3b83}, /* 0x3f */    /*fstn add new mode */
+	{0xffff,0x00,0x00,0x00,0x00,0000,0000,0x0000}
 };
 
 typedef struct _SiS310_CRT1TableStruct
 {
- UCHAR CR[17];
+ 	UCHAR CR[17];
 } SiS310_CRT1TableStruct;
 SiS310_CRT1TableStruct SiS310_CRT1Table[]=
 {
@@ -844,244 +849,255 @@
 
 typedef struct _SiS310_MCLKDataStruct
 {
- UCHAR SR28,SR29,SR2A;
- USHORT CLOCK;
+	UCHAR SR28,SR29,SR2A;
+	USHORT CLOCK;
 } SiS310_MCLKDataStruct;
+
 SiS310_MCLKDataStruct SiS310_MCLKData[]=
 {
- { 0x5c,0x23,0x01,166},
- { 0x5c,0x23,0x01,166},
- { 0x5c,0x23,0x01,166},
- { 0x5c,0x23,0x01,166}
+	{ 0x5c,0x23,0x01,166},
+	{ 0x5c,0x23,0x01,166},
+	{ 0x5c,0x23,0x01,166},
+	{ 0x5c,0x23,0x01,166}
 };
 
 typedef struct _SiS310_ECLKDataStruct
 {
- UCHAR SR2E,SR2F,SR30;
- USHORT CLOCK;
+ 	UCHAR SR2E,SR2F,SR30;
+ 	USHORT CLOCK;
 } SiS310_ECLKDataStruct;
 SiS310_ECLKDataStruct SiS310_ECLKData[]=
 {
- { 0x5c,0x23,0x01,166},
- { 0x5c,0x23,0x01,166},
- { 0x5c,0x23,0x01,166},
- { 0x5c,0x23,0x01,166}
+	{ 0x5c,0x23,0x01,166},
+	{ 0x5c,0x23,0x01,166},
+	{ 0x5c,0x23,0x01,166},
+	{ 0x5c,0x23,0x01,166}
 };
 
 typedef struct _SiS310_VCLKDataStruct
 {
- UCHAR SR2B,SR2C;
- USHORT CLOCK;
+	UCHAR SR2B,SR2C;
+	USHORT CLOCK;
 } SiS310_VCLKDataStruct;
+
 SiS310_VCLKDataStruct SiS310_VCLKData[]=
 {
- { 0x1b,0xe1, 25}, /* 0x0 */
- { 0x4e,0xe4, 28}, /* 0x1 */
- { 0x57,0xe4, 31}, /* 0x2 */
- { 0xc3,0xc8, 36}, /* 0x3 */
- { 0x42,0xe2, 40}, /* 0x4 */
- { 0xfe,0xcd, 43}, /* 0x5 */
- { 0x5d,0xc4, 44}, /* 0x6 */
- { 0x52,0xe2, 49}, /* 0x7 */
- { 0x53,0xe2, 50}, /* 0x8 */
- { 0x74,0x67, 52}, /* 0x9 */
- { 0x6d,0x66, 56}, /* 0xa */
- { 0x6c,0xc3, 65}, /* 0xb */
- { 0x46,0x44, 67}, /* 0xc */
- { 0xb1,0x46, 68}, /* 0xd */
- { 0xd3,0x4a, 72}, /* 0xe */
- { 0x29,0x61, 75}, /* 0xf */
- { 0x6e,0x46, 76}, /* 0x10 */
- { 0x2b,0x61, 78}, /* 0x11 */
- { 0x31,0x42, 79}, /* 0x12 */
- { 0xab,0x44, 83}, /* 0x13 */
- { 0x46,0x25, 84}, /* 0x14 */
- { 0x78,0x29, 86}, /* 0x15 */
- { 0x62,0x44, 94}, /* 0x16 */
- { 0x2b,0x41,104}, /* 0x17 */
- { 0x3a,0x23,105}, /* 0x18 */
- { 0x70,0x44,108}, /* 0x19 */
- { 0x3c,0x23,109}, /* 0x1a */
- { 0x5e,0x43,113}, /* 0x1b */
- { 0xbc,0x44,116}, /* 0x1c */
- { 0xe0,0x46,132}, /* 0x1d */
- { 0x54,0x42,135}, /* 0x1e */
- { 0xea,0x2a,139}, /* 0x1f */
- { 0x41,0x22,157}, /* 0x20 */
- { 0x70,0x24,162}, /* 0x21 */
- { 0x30,0x21,175}, /* 0x22 */
- { 0x4e,0x22,189}, /* 0x23 */
- { 0xde,0x26,194}, /* 0x24 */
- { 0x62,0x06,202}, /* 0x25 */
- { 0x3f,0x03,229}, /* 0x26 */
- { 0xb8,0x06,234}, /* 0x27 */
- { 0x34,0x02,253}, /* 0x28 */
- { 0x58,0x04,255}, /* 0x29 */
- { 0x24,0x01,265}, /* 0x2a */
- { 0x9b,0x02,267}, /* 0x2b */
- { 0x70,0x05,270}, /* 0x2c */
- { 0x25,0x01,272}, /* 0x2d */
- { 0x9c,0x02,277}, /* 0x2e */
- { 0x27,0x01,286}, /* 0x2f */
- { 0x3c,0x02,291}, /* 0x30 */
- { 0xef,0x0a,292}, /* 0x31 */
- { 0xf6,0x0a,310}, /* 0x32 */
- { 0x95,0x01,315}, /* 0x33 */
- { 0xf0,0x09,324}, /* 0x34 */
- { 0xfe,0x0a,331}, /* 0x35 */
- { 0xf3,0x09,332}, /* 0x36 */
- { 0xea,0x08,340}, /* 0x37 */
- { 0xe8,0x07,376}, /* 0x38 */
- { 0xde,0x06,389}, /* 0x39 */
- { 0x52,0x2a, 54}, /* 0x3a */
- { 0x52,0x6a, 27}, /* 0x3b */
- { 0x62,0x24, 70}, /* 0x3c */
- { 0x62,0x64, 70}, /* 0x3d */
- { 0xa8,0x4c, 30}, /* 0x3e */
- { 0x20,0x26, 33}, /* 0x3f */
- { 0x31,0xc2, 39} /* 0x40 */
+	{ 0x1b,0xe1, 25}, /* 0x0 */
+	{ 0x4e,0xe4, 28}, /* 0x1 */
+	{ 0x57,0xe4, 31}, /* 0x2 */
+	{ 0xc3,0xc8, 36}, /* 0x3 */
+	{ 0x42,0xe2, 40}, /* 0x4 */
+	{ 0xfe,0xcd, 43}, /* 0x5 */
+	{ 0x5d,0xc4, 44}, /* 0x6 */
+	{ 0x52,0xe2, 49}, /* 0x7 */
+	{ 0x53,0xe2, 50}, /* 0x8 */
+	{ 0x74,0x67, 52}, /* 0x9 */
+	{ 0x6d,0x66, 56}, /* 0xa */
+	{ 0x6c,0xc3, 65}, /* 0xb */
+	{ 0x46,0x44, 67}, /* 0xc */
+	{ 0xb1,0x46, 68}, /* 0xd */
+	{ 0xd3,0x4a, 72}, /* 0xe */
+	{ 0x29,0x61, 75}, /* 0xf */
+	{ 0x6e,0x46, 76}, /* 0x10 */
+	{ 0x2b,0x61, 78}, /* 0x11 */
+	{ 0x31,0x42, 79}, /* 0x12 */
+	{ 0xab,0x44, 83}, /* 0x13 */
+	{ 0x46,0x25, 84}, /* 0x14 */
+	{ 0x78,0x29, 86}, /* 0x15 */
+	{ 0x62,0x44, 94}, /* 0x16 */
+	{ 0x2b,0x41,104}, /* 0x17 */
+	{ 0x3a,0x23,105}, /* 0x18 */
+	{ 0x70,0x44,108}, /* 0x19 */
+	{ 0x3c,0x23,109}, /* 0x1a */
+	{ 0x5e,0x43,113}, /* 0x1b */
+	{ 0xbc,0x44,116}, /* 0x1c */
+	{ 0xe0,0x46,132}, /* 0x1d */
+	{ 0x54,0x42,135}, /* 0x1e */
+	{ 0xea,0x2a,139}, /* 0x1f */
+	{ 0x41,0x22,157}, /* 0x20 */
+	{ 0x70,0x24,162}, /* 0x21 */
+	{ 0x30,0x21,175}, /* 0x22 */
+	{ 0x4e,0x22,189}, /* 0x23 */
+	{ 0xde,0x26,194}, /* 0x24 */
+	{ 0x62,0x06,202}, /* 0x25 */
+	{ 0x3f,0x03,229}, /* 0x26 */
+	{ 0xb8,0x06,234}, /* 0x27 */
+	{ 0x34,0x02,253}, /* 0x28 */
+	{ 0x58,0x04,255}, /* 0x29 */
+	{ 0x24,0x01,265}, /* 0x2a */
+	{ 0x9b,0x02,267}, /* 0x2b */
+	{ 0x70,0x05,270}, /* 0x2c */
+	{ 0x25,0x01,272}, /* 0x2d */
+	{ 0x9c,0x02,277}, /* 0x2e */
+	{ 0x27,0x01,286}, /* 0x2f */
+	{ 0x3c,0x02,291}, /* 0x30 */
+	{ 0xef,0x0a,292}, /* 0x31 */
+	{ 0xf6,0x0a,310}, /* 0x32 */
+	{ 0x95,0x01,315}, /* 0x33 */
+	{ 0xf0,0x09,324}, /* 0x34 */
+	{ 0xfe,0x0a,331}, /* 0x35 */
+	{ 0xf3,0x09,332}, /* 0x36 */
+	{ 0xea,0x08,340}, /* 0x37 */
+	{ 0xe8,0x07,376}, /* 0x38 */
+	{ 0xde,0x06,389}, /* 0x39 */
+	{ 0x52,0x2a, 54}, /* 0x3a */
+	{ 0x52,0x6a, 27}, /* 0x3b */
+	{ 0x62,0x24, 70}, /* 0x3c */
+	{ 0x62,0x64, 70}, /* 0x3d */
+	{ 0xa8,0x4c, 30}, /* 0x3e */
+	{ 0x20,0x26, 33}, /* 0x3f */
+	{ 0x31,0xc2, 39}  /* 0x40 */
 };
 
 typedef struct _SiS310_VBVCLKDataStruct
 {
- UCHAR Part4_A,Part4_B;
- USHORT CLOCK;
+	UCHAR Part4_A,Part4_B;
+	USHORT CLOCK;
 } SiS310_VBVCLKDataStruct;
+
 SiS310_VBVCLKDataStruct SiS310_VBVCLKData[]=
 {
- { 0x1b,0xe1, 25}, /* 0x0 */
- { 0x4e,0xe4, 28}, /* 0x1 */
- { 0x57,0xe4, 31}, /* 0x2 */
- { 0xc3,0xc8, 36}, /* 0x3 */
- { 0x42,0x47, 40}, /* 0x4 */
- { 0xfe,0xcd, 43}, /* 0x5 */
- { 0x5d,0xc4, 44}, /* 0x6 */
- { 0x52,0x47, 49}, /* 0x7 */
- { 0x53,0x47, 50}, /* 0x8 */
- { 0x74,0x67, 52}, /* 0x9 */
- { 0x6d,0x66, 56}, /* 0xa */
- { 0x5a,0x64, 65}, /* 0xb */
- { 0x46,0x44, 67}, /* 0xc */
- { 0xb1,0x46, 68}, /* 0xd */
- { 0xd3,0x4a, 72}, /* 0xe */
- { 0x29,0x61, 75}, /* 0xf */
- { 0x6d,0x46, 75}, /* 0x10 */
- { 0x41,0x43, 78}, /* 0x11 */
- { 0x31,0x42, 79}, /* 0x12 */
- { 0xab,0x44, 83}, /* 0x13 */
- { 0x46,0x25, 84}, /* 0x14 */
- { 0x78,0x29, 86}, /* 0x15 */
- { 0x62,0x44, 94}, /* 0x16 */
- { 0x2b,0x22,104}, /* 0x17 */
- { 0x49,0x24,105}, /* 0x18 */
- { 0xf8,0x2f,108}, /* 0x19 */
- { 0x3c,0x23,109}, /* 0x1a */
- { 0x5e,0x43,113}, /* 0x1b */
- { 0xbc,0x44,116}, /* 0x1c */
- { 0xe0,0x46,132}, /* 0x1d */
- { 0xd4,0x28,135}, /* 0x1e */
- { 0xea,0x2a,139}, /* 0x1f */
- { 0x41,0x22,157}, /* 0x20 */
- { 0x70,0x24,162}, /* 0x21 */
- { 0x30,0x21,175}, /* 0x22 */
- { 0x4e,0x22,189}, /* 0x23 */
- { 0xde,0x26,194}, /* 0x24 */
- { 0x70,0x07,202}, /* 0x25 */
- { 0x3f,0x03,229}, /* 0x26 */
- { 0xb8,0x06,234}, /* 0x27 */
- { 0x34,0x02,253}, /* 0x28 */
- { 0x58,0x04,255}, /* 0x29 */
- { 0x24,0x01,265}, /* 0x2a */
- { 0x9b,0x02,267}, /* 0x2b */
- { 0x70,0x05,270}, /* 0x2c */
- { 0x25,0x01,272}, /* 0x2d */
- { 0x9c,0x02,277}, /* 0x2e */
- { 0x27,0x01,286}, /* 0x2f */
- { 0x3c,0x02,291}, /* 0x30 */
- { 0xef,0x0a,292}, /* 0x31 */
- { 0xf6,0x0a,310}, /* 0x32 */
- { 0x95,0x01,315}, /* 0x33 */
- { 0xf0,0x09,324}, /* 0x34 */
- { 0xfe,0x0a,331}, /* 0x35 */
- { 0xf3,0x09,332}, /* 0x36 */
- { 0xea,0x08,340}, /* 0x37 */
- { 0xe8,0x07,376}, /* 0x38 */
- { 0xde,0x06,389}, /* 0x39 */
- { 0x52,0x2a, 54}, /* 0x3a */
- { 0x52,0x6a, 27}, /* 0x3b */
- { 0x62,0x24, 70}, /* 0x3c */
- { 0x62,0x64, 70}, /* 0x3d */
- { 0xa8,0x4c, 30}, /* 0x3e */
- { 0x20,0x26, 33}, /* 0x3f */
- { 0x31,0xc2, 39} /* 0x40 */
+	{ 0x1b,0xe1, 25}, /* 0x0 */
+	{ 0x4e,0xe4, 28}, /* 0x1 */
+	{ 0x57,0xe4, 31}, /* 0x2 */
+	{ 0xc3,0xc8, 36}, /* 0x3 */
+	{ 0x42,0x47, 40}, /* 0x4 */
+	{ 0xfe,0xcd, 43}, /* 0x5 */
+	{ 0x5d,0xc4, 44}, /* 0x6 */
+	{ 0x52,0x47, 49}, /* 0x7 */
+	{ 0x53,0x47, 50}, /* 0x8 */
+	{ 0x74,0x67, 52}, /* 0x9 */
+	{ 0x6d,0x66, 56}, /* 0xa */
+	{ 0x5a,0x64, 65}, /* 0xb */
+	{ 0x46,0x44, 67}, /* 0xc */
+	{ 0xb1,0x46, 68}, /* 0xd */
+	{ 0xd3,0x4a, 72}, /* 0xe */
+	{ 0x29,0x61, 75}, /* 0xf */
+	{ 0x6d,0x46, 75}, /* 0x10 */
+	{ 0x41,0x43, 78}, /* 0x11 */
+	{ 0x31,0x42, 79}, /* 0x12 */
+	{ 0xab,0x44, 83}, /* 0x13 */
+	{ 0x46,0x25, 84}, /* 0x14 */
+	{ 0x78,0x29, 86}, /* 0x15 */
+	{ 0x62,0x44, 94}, /* 0x16 */
+	{ 0x2b,0x22,104}, /* 0x17 */
+	{ 0x49,0x24,105}, /* 0x18 */
+	{ 0xf8,0x2f,108}, /* 0x19 */
+	{ 0x3c,0x23,109}, /* 0x1a */
+	{ 0x5e,0x43,113}, /* 0x1b */
+	{ 0xbc,0x44,116}, /* 0x1c */
+	{ 0xe0,0x46,132}, /* 0x1d */
+	{ 0xd4,0x28,135}, /* 0x1e */
+	{ 0xea,0x2a,139}, /* 0x1f */
+	{ 0x41,0x22,157}, /* 0x20 */
+	{ 0x70,0x24,162}, /* 0x21 */
+	{ 0x30,0x21,175}, /* 0x22 */
+	{ 0x4e,0x22,189}, /* 0x23 */
+	{ 0xde,0x26,194}, /* 0x24 */
+	{ 0x70,0x07,202}, /* 0x25 */
+	{ 0x3f,0x03,229}, /* 0x26 */
+	{ 0xb8,0x06,234}, /* 0x27 */
+	{ 0x34,0x02,253}, /* 0x28 */
+	{ 0x58,0x04,255}, /* 0x29 */
+	{ 0x24,0x01,265}, /* 0x2a */
+	{ 0x9b,0x02,267}, /* 0x2b */
+	{ 0x70,0x05,270}, /* 0x2c */
+	{ 0x25,0x01,272}, /* 0x2d */
+	{ 0x9c,0x02,277}, /* 0x2e */
+	{ 0x27,0x01,286}, /* 0x2f */
+	{ 0x3c,0x02,291}, /* 0x30 */
+	{ 0xef,0x0a,292}, /* 0x31 */
+	{ 0xf6,0x0a,310}, /* 0x32 */
+	{ 0x95,0x01,315}, /* 0x33 */
+	{ 0xf0,0x09,324}, /* 0x34 */
+	{ 0xfe,0x0a,331}, /* 0x35 */
+	{ 0xf3,0x09,332}, /* 0x36 */
+	{ 0xea,0x08,340}, /* 0x37 */
+	{ 0xe8,0x07,376}, /* 0x38 */
+	{ 0xde,0x06,389}, /* 0x39 */
+	{ 0x52,0x2a, 54}, /* 0x3a */
+	{ 0x52,0x6a, 27}, /* 0x3b */
+	{ 0x62,0x24, 70}, /* 0x3c */
+	{ 0x62,0x64, 70}, /* 0x3d */
+	{ 0xa8,0x4c, 30}, /* 0x3e */
+	{ 0x20,0x26, 33}, /* 0x3f */
+	{ 0x31,0xc2, 39}  /* 0x40 */
 };
 
-UCHAR SiS310_ScreenOffset[]={ 0x14,0x19,0x20,0x28,0x32,0x40,0x50,0x64,0x78,0x80,0x2d,0x35 };
+UCHAR SiS310_ScreenOffset[]= { 0x14,0x19,0x20,0x28,0x32,0x40,
+                               0x50,0x64,0x78,0x80,0x2d,0x35};
 
 typedef struct _SiS310_StResInfoStruct
 {
- USHORT HTotal;
- USHORT VTotal;
+	USHORT HTotal;
+	USHORT VTotal;
 } SiS310_StResInfoStruct;
+
 SiS310_StResInfoStruct SiS310_StResInfo[]=
 {
- { 640,400},
- { 640,350},
- { 720,400},
- { 720,350},
- { 640,480}
+	{ 640,400},
+	{ 640,350},
+	{ 720,400},
+	{ 720,350},
+	{ 640,480}
 };
 
 typedef struct _SiS310_ModeResInfoStruct
 {
- USHORT HTotal;
- USHORT VTotal;
- UCHAR  XChar;
- UCHAR  YChar;
+	USHORT HTotal;
+	USHORT VTotal;
+	UCHAR  XChar;
+	UCHAR  YChar;
 } SiS310_ModeResInfoStruct;
+
 SiS310_ModeResInfoStruct SiS310_ModeResInfo[]=
 {
- {  320, 200, 8, 8},
- {  320, 240, 8, 8},
- {  320, 400, 8, 8},
- {  400, 300, 8, 8},
- {  512, 384, 8, 8},
- {  640, 400, 8,16},
- {  640, 480, 8,16},
- {  800, 600, 8,16},
- { 1024, 768, 8,16},
- { 1280,1024, 8,16},
- { 1600,1200, 8,16},
- { 1920,1440, 8,16},
- { 2048,1536, 8,16},
- {  720, 480, 8,16},
- {  720, 576, 8,16},
- { 1280, 960, 8,16},
- {  800, 480, 8,16},
- { 1024, 576, 8,16},
- { 1280, 720, 8,16}
+	{  320, 200, 8, 8},
+	{  320, 240, 8, 8},
+	{  320, 400, 8, 8},
+	{  400, 300, 8, 8},
+	{  512, 384, 8, 8},
+	{  640, 400, 8,16},
+	{  640, 480, 8,16},
+	{  800, 600, 8,16},
+	{ 1024, 768, 8,16},
+	{ 1280,1024, 8,16},
+	{ 1600,1200, 8,16},
+	{ 1920,1440, 8,16},
+	{ 2048,1536, 8,16},
+	{  720, 480, 8,16},
+	{  720, 576, 8,16},
+	{ 1280, 960, 8,16},
+	{  800, 480, 8,16},
+	{ 1024, 576, 8,16},
+	{ 1280, 720, 8,16}
 };
 
 UCHAR SiS310_OutputSelect =0x40;
+
 UCHAR SiS310_SoftSetting = 30;
+
 UCHAR SiS310_SR07=0x18;
+
 UCHAR SiS310_SR15[8][4]={
-{0x0,0x4,0x60,0x60},
-{0xf,0xf,0xf,0xf},
-{0xba,0xba,0xba,0xba},
-{0xa9,0xa9,0xac,0xac},
-{0xa0,0xa0,0xa0,0xa8},
-{0x0,0x0,0x2,0x2},
-{0x30,0x30,0x40,0x40},
-{0x0,0xa5,0xfb,0xf6}
+	{0x00,0x04,0x60,0x60},
+	{0x0f,0x0f,0x0f,0x0f},
+	{0xba,0xba,0xba,0xba},
+	{0xa9,0xa9,0xac,0xac},
+	{0xa0,0xa0,0xa0,0xa8},
+	{0x00,0x00,0x02,0x02},
+	{0x30,0x30,0x40,0x40},
+	{0x00,0xa5,0xfb,0xf6}
 };
+
 UCHAR SiS310_CR40[5][4]={
-{0x77,0x77,0x33,0x33},
-{0x77,0x77,0x33,0x33},
-{0x0,0x0,0x0,0x0},
-{0x5b,0x5b,0x3,0x3},
-{0x0,0x0,0xf0,0xf8}
+	{0x77,0x77,0x33,0x33},
+	{0x77,0x77,0x33,0x33},
+	{0x00,0x00,0x00,0x00},
+	{0x5b,0x5b,0x03,0x03},
+	{0x00,0x00,0xf0,0xf8}
 };
+
 UCHAR SiS310_CR49[]={0xaa,0x88};
 UCHAR SiS310_SR1F=0x0;
 UCHAR SiS310_SR21=0xa5;
@@ -1111,129 +1127,131 @@
 
 typedef struct _SiS310_LCDDataStruct
 {
- USHORT RVBHCMAX;
- USHORT RVBHCFACT;
- USHORT VGAHT;
- USHORT VGAVT;
- USHORT LCDHT;
- USHORT LCDVT;
+	USHORT RVBHCMAX;
+	USHORT RVBHCFACT;
+	USHORT VGAHT;
+	USHORT VGAVT;
+	USHORT LCDHT;
+	USHORT LCDVT;
 } SiS310_LCDDataStruct;
+
 SiS310_LCDDataStruct  SiS310_StLCD1024x768Data[]=
 {
- {   62,  25, 800, 546,1344, 806},
- {   32,  15, 930, 546,1344, 806},
- {   32,  15, 930, 546,1344, 806},
- {  104,  45, 945, 496,1344, 806},
- {   62,  25, 800, 546,1344, 806},
- {   31,  18,1008, 624,1344, 806},
- {    1,   1,1344, 806,1344, 806}
+	{   62,  25, 800, 546,1344, 806},
+	{   32,  15, 930, 546,1344, 806},
+	{   32,  15, 930, 546,1344, 806},
+	{  104,  45, 945, 496,1344, 806},
+	{   62,  25, 800, 546,1344, 806},
+	{   31,  18,1008, 624,1344, 806},
+	{    1,   1,1344, 806,1344, 806}
 };
 
 SiS310_LCDDataStruct  SiS310_ExtLCD1024x768Data[]=
 {
- {   12,   5, 896, 512,1344, 806},
- {   12,   5, 896, 510,1344, 806},
- {   32,  15,1008, 505,1344, 806},
- {   32,  15,1008, 514,1344, 806},
- {   12,   5, 896, 500,1344, 806},
- {   42,  25,1024, 625,1344, 806},
- {    1,   1,1344, 806,1344, 806},
- {   12,   5, 896, 500,1344, 806},
- {   42,  25,1024, 625,1344, 806},
- {    1,   1,1344, 806,1344, 806},
- {   12,   5, 896, 500,1344, 806},
- {   42,  25,1024, 625,1344, 806},
- {    1,   1,1344, 806,1344, 806}
+	{   12,   5, 896, 512,1344, 806},
+	{   12,   5, 896, 510,1344, 806},
+	{   32,  15,1008, 505,1344, 806},
+	{   32,  15,1008, 514,1344, 806},
+	{   12,   5, 896, 500,1344, 806},
+	{   42,  25,1024, 625,1344, 806},
+	{    1,   1,1344, 806,1344, 806},
+	{   12,   5, 896, 500,1344, 806},
+	{   42,  25,1024, 625,1344, 806},
+	{    1,   1,1344, 806,1344, 806},
+	{   12,   5, 896, 500,1344, 806},
+	{   42,  25,1024, 625,1344, 806},
+	{    1,   1,1344, 806,1344, 806}
 };
 
 SiS310_LCDDataStruct  SiS310_St2LCD1024x768Data[]=
 {
- {   62,  25, 800, 546,1344, 806},
- {   32,  15, 930, 546,1344, 806},
- {   32,  15, 930, 546,1344, 806},
- {  104,  45, 945, 496,1344, 806},
- {   62,  25, 800, 546,1344, 806},
- {   31,  18,1008, 624,1344, 806},
- {    1,   1,1344, 806,1344, 806}
+	{   62,  25, 800, 546,1344, 806},
+	{   32,  15, 930, 546,1344, 806},
+	{   32,  15, 930, 546,1344, 806},
+	{  104,  45, 945, 496,1344, 806},
+	{   62,  25, 800, 546,1344, 806},
+	{   31,  18,1008, 624,1344, 806},
+	{    1,   1,1344, 806,1344, 806}
 };
 
 SiS310_LCDDataStruct  SiS310_StLCD1280x1024Data[]=
 {
- {   22,   5, 800, 510,1650,1088},
- {   22,   5, 800, 510,1650,1088},
- {  176,  45, 900, 510,1650,1088},
- {  176,  45, 900, 510,1650,1088},
- {   22,   5, 800, 510,1650,1088},
- {   13,   5,1024, 675,1560,1152},
- {   16,   9,1266, 804,1688,1072},
- {    1,   1,1688,1066,1688,1066}
+	{   22,   5, 800, 510,1650,1088},
+	{   22,   5, 800, 510,1650,1088},
+	{  176,  45, 900, 510,1650,1088},
+	{  176,  45, 900, 510,1650,1088},
+	{   22,   5, 800, 510,1650,1088},
+	{   13,   5,1024, 675,1560,1152},
+	{   16,   9,1266, 804,1688,1072},
+	{    1,   1,1688,1066,1688,1066}
 };
 
 SiS310_LCDDataStruct  SiS310_ExtLCD1280x1024Data[]=
 {
- {  211,  60,1024, 501,1688,1066},
- {  211,  60,1024, 508,1688,1066},
- {  211,  60,1024, 501,1688,1066},
- {  211,  60,1024, 508,1688,1066},
- {  211,  60,1024, 500,1688,1066},
- {  211,  75,1024, 625,1688,1066},
- {  211, 120,1280, 798,1688,1066},
- {    1,   1,1688,1066,1688,1066}
+	{  211,  60,1024, 501,1688,1066},
+	{  211,  60,1024, 508,1688,1066},
+	{  211,  60,1024, 501,1688,1066},
+	{  211,  60,1024, 508,1688,1066},
+	{  211,  60,1024, 500,1688,1066},
+	{  211,  75,1024, 625,1688,1066},
+	{  211, 120,1280, 798,1688,1066},
+	{    1,   1,1688,1066,1688,1066}
 };
 
 SiS310_LCDDataStruct  SiS310_St2LCD1280x1024Data[]=
 {
- {   22,   5, 800, 510,1650,1088},
- {   22,   5, 800, 510,1650,1088},
- {  176,  45, 900, 510,1650,1088},
- {  176,  45, 900, 510,1650,1088},
- {   22,   5, 800, 510,1650,1088},
- {   13,   5,1024, 675,1560,1152},
- {   16,   9,1266, 804,1688,1072},
- {    1,   1,1688,1066,1688,1066}
+	{   22,   5, 800, 510,1650,1088},
+	{   22,   5, 800, 510,1650,1088},
+	{  176,  45, 900, 510,1650,1088},
+	{  176,  45, 900, 510,1650,1088},
+	{   22,   5, 800, 510,1650,1088},
+	{   13,   5,1024, 675,1560,1152},
+	{   16,   9,1266, 804,1688,1072},
+	{    1,   1,1688,1066,1688,1066}
 };
 
 SiS310_LCDDataStruct  SiS310_NoScaleData[]=
 {
- {    1,   1, 800, 449, 800, 449},
- {    1,   1, 800, 449, 800, 449},
- {    1,   1, 900, 449, 900, 449},
- {    1,   1, 900, 449, 900, 449},
- {    1,   1, 800, 525, 800, 525},
- {    1,   1,1056, 628,1056, 628},
- {    1,   1,1344, 806,1344, 806},
- {    1,   1,1688,1066,1688,1066}
+	{    1,   1, 800, 449, 800, 449},
+	{    1,   1, 800, 449, 800, 449},
+	{    1,   1, 900, 449, 900, 449},
+	{    1,   1, 900, 449, 900, 449},
+	{    1,   1, 800, 525, 800, 525},
+	{    1,   1,1056, 628,1056, 628},
+	{    1,   1,1344, 806,1344, 806},
+	{    1,   1,1688,1066,1688,1066}
 };
 
 SiS310_LCDDataStruct  SiS310_LCD1280x960Data[]=
 {
- {    9,   2, 800, 500,1800,1000},
- {    9,   2, 800, 500,1800,1000},
- {    4,   1, 900, 500,1800,1000},
- {    4,   1, 900, 500,1800,1000},
- {    9,   2, 800, 500,1800,1000},
- {   30,  11,1056, 625,1800,1000},
- {    5,   3,1350, 800,1800,1000},
- {    1,   1,1576,1050,1576,1050},
- {    1,   1,1800,1000,1800,1000}
+	{    9,   2, 800, 500,1800,1000},
+	{    9,   2, 800, 500,1800,1000},
+	{    4,   1, 900, 500,1800,1000},
+	{    4,   1, 900, 500,1800,1000},
+	{    9,   2, 800, 500,1800,1000},
+	{   30,  11,1056, 625,1800,1000},
+	{    5,   3,1350, 800,1800,1000},
+	{    1,   1,1576,1050,1576,1050},
+	{    1,   1,1800,1000,1800,1000}
 };
 
 typedef struct _SiS310_TVDataStruct
 {
- USHORT RVBHCMAX;
- USHORT RVBHCFACT;
- USHORT VGAHT;
- USHORT VGAVT;
- USHORT TVHDE;
- USHORT TVVDE;
- USHORT RVBHRS;
- UCHAR FlickerMode;
- USHORT HALFRVBHRS;
- UCHAR RY1COE;
- UCHAR RY2COE;
- UCHAR RY3COE;
- UCHAR RY4COE;
+	USHORT RVBHCMAX;
+	USHORT RVBHCFACT;
+	USHORT VGAHT;
+	USHORT VGAVT;
+	USHORT TVHDE;
+	USHORT TVVDE;
+	USHORT RVBHRS;
+	UCHAR FlickerMode;
+	USHORT HALFRVBHRS;
+	UCHAR RY1COE;
+	UCHAR RY2COE;
+	UCHAR RY3COE;
+	UCHAR RY4COE;
 } SiS310_TVDataStruct;
+
 SiS310_TVDataStruct  SiS310_StPALData[]=
 {
  {    1,   1, 864, 525,1270, 400, 100,   0, 760,0xf4,0xff,0x1c,0x22},
@@ -1279,38 +1297,40 @@
 
 SiS310_TVDataStruct  SiS310_St1HiTVData[]=
 {
-{0x00}
+	{0x00}
 };
 
 SiS310_TVDataStruct  SiS310_St2HiTVData[]=
 {
-{0x00}
+	{0x00}
 };
 
 SiS310_TVDataStruct  SiS310_ExtHiTVData[]=
 {
-{0x00}
+	{0x00}
 };
 
 UCHAR SiS310_NTSCTiming[] = {
-  0x17,0x1d,0x03,0x09,0x05,0x06,0x0c,0x0c,
-  0x94,0x49,0x01,0x0a,0x06,0x0d,0x04,0x0a,
-  0x06,0x14,0x0d,0x04,0x0a,0x00,0x85,0x1b,
-  0x0c,0x50,0x00,0x97,0x00,0xda,0x4a,0x17,
-  0x7d,0x05,0x4b,0x00,0x00,0xe2,0x00,0x02,
-  0x03,0x0a,0x65,0x9d,0x08,0x92,0x8f,0x40,
-  0x60,0x80,0x14,0x90,0x8c,0x60,0x14,0x50,
-  0x00,0x40,0x44,0x00,0xdb,0x02,0x3b,0x00};
+	0x17,0x1d,0x03,0x09,0x05,0x06,0x0c,0x0c,
+	0x94,0x49,0x01,0x0a,0x06,0x0d,0x04,0x0a,
+	0x06,0x14,0x0d,0x04,0x0a,0x00,0x85,0x1b,
+	0x0c,0x50,0x00,0x97,0x00,0xda,0x4a,0x17,
+	0x7d,0x05,0x4b,0x00,0x00,0xe2,0x00,0x02,
+	0x03,0x0a,0x65,0x9d,0x08,0x92,0x8f,0x40,
+	0x60,0x80,0x14,0x90,0x8c,0x60,0x14,0x50,
+	0x00,0x40,0x44,0x00,0xdb,0x02,0x3b,0x00
+};
 
 UCHAR SiS310_PALTiming[] = {
-  0x19,0x52,0x35,0x6e,0x04,0x38,0x3d,0x70,
-  0x94,0x49,0x01,0x12,0x06,0x3e,0x35,0x6d,
-  0x06,0x14,0x3e,0x35,0x6d,0x00,0x45,0x2b,
-  0x70,0x50,0x00,0x9b,0x00,0xd9,0x5d,0x17,
-  0x7d,0x05,0x45,0x00,0x00,0xe8,0x00,0x02,
-  0x0d,0x00,0x68,0xb0,0x0b,0x92,0x8f,0x40,
-  0x60,0x80,0x14,0x90,0x8c,0x60,0x14,0x63,
-  0x00,0x40,0x3e,0x00,0xe1,0x02,0x28,0x00};
+	0x19,0x52,0x35,0x6e,0x04,0x38,0x3d,0x70,
+	0x94,0x49,0x01,0x12,0x06,0x3e,0x35,0x6d,
+	0x06,0x14,0x3e,0x35,0x6d,0x00,0x45,0x2b,
+	0x70,0x50,0x00,0x9b,0x00,0xd9,0x5d,0x17,
+	0x7d,0x05,0x45,0x00,0x00,0xe8,0x00,0x02,
+	0x0d,0x00,0x68,0xb0,0x0b,0x92,0x8f,0x40,
+	0x60,0x80,0x14,0x90,0x8c,0x60,0x14,0x63,
+	0x00,0x40,0x3e,0x00,0xe1,0x02,0x28,0x00
+};
 
 UCHAR SiS310_HiTVExtTiming[] = {0x00};
 
@@ -1328,672 +1348,675 @@
 
 typedef struct _SiS310_PanelDelayTblStruct
 {
- UCHAR timer[2];
+ 	UCHAR timer[2];
 } SiS310_PanelDelayTblStruct;
+
 SiS310_PanelDelayTblStruct SiS310_PanelDelayTbl[]=
 {
-{{0x00,0x00}},
-{{0x00,0x00}},
-{{0x00,0x00}},
-{{0x00,0x00}},
-{{0x00,0x00}},
-{{0x00,0x00}},
-{{0x00,0x00}},
-{{0x00,0x00}},
-{{0x00,0x00}},
-{{0x00,0x00}},
-{{0x00,0x00}},
-{{0x00,0x00}},
-{{0x00,0x00}},
-{{0x00,0x00}},
-{{0x00,0x00}},
-{{0x00,0x00}}
+	{{0x00,0x00}},
+	{{0x00,0x00}},
+	{{0x00,0x00}},
+	{{0x00,0x00}},
+	{{0x00,0x00}},
+	{{0x00,0x00}},
+	{{0x00,0x00}},
+	{{0x00,0x00}},
+	{{0x00,0x00}},
+	{{0x00,0x00}},
+	{{0x00,0x00}},
+	{{0x00,0x00}},
+	{{0x00,0x00}},
+	{{0x00,0x00}},
+	{{0x00,0x00}},
+	{{0x00,0x00}}
 };
 
 typedef struct _SiS310_LVDSDataStruct
 {
- USHORT VGAHT;
- USHORT VGAVT;
- USHORT LCDHT;
- USHORT LCDVT;
+	USHORT VGAHT;
+	USHORT VGAVT;
+	USHORT LCDHT;
+	USHORT LCDVT;
 } SiS310_LVDSDataStruct;
 
 SiS310_LVDSDataStruct  SiS310_LVDS320x480Data_1[]=
 {
- {848, 433,400,525},
- {848, 389,400,525},
- {848, 433,400,525},
- {848, 389,400,525},
- {848, 518,400, 525},
- {1056, 628,400,525},
- {400, 525,400,525},
- {800, 449,1000, 644},
- {800, 525,1000, 635}
+	{848, 433,400,525},
+	{848, 389,400,525},
+	{848, 433,400,525},
+	{848, 389,400,525},
+	{848, 518,400, 525},
+	{1056, 628,400,525},
+	{400, 525,400,525},
+	{800, 449,1000, 644},
+	{800, 525,1000, 635}
 };
 SiS310_LVDSDataStruct  SiS310_LVDS800x600Data_1[]=
 {
- {848, 433,1060, 629},
- {848, 389,1060, 629},
- {848, 433,1060, 629},
- {848, 389,1060, 629},
- {848, 518,1060, 629},
- {1056, 628,1056, 628},
- {1056, 628,1056, 628},
- {800, 449,1000, 644},
- {800, 525,1000, 635}
+	{848, 433,1060, 629},
+	{848, 389,1060, 629},
+	{848, 433,1060, 629},
+	{848, 389,1060, 629},
+	{848, 518,1060, 629},
+	{1056, 628,1056, 628},
+	{1056, 628,1056, 628},
+	{800, 449,1000, 644},
+	{800, 525,1000, 635}
 };
 
 SiS310_LVDSDataStruct  SiS310_LVDS800x600Data_2[]=
 {
- {1056, 628,1056, 628},
- {1056, 628,1056, 628},
- {1056, 628,1056, 628},
- {1056, 628,1056, 628},
- {1056, 628,1056, 628},
- {1056, 628,1056, 628},
- {1056, 628,1056, 628},
- {800, 449,1000, 644},
- {800, 525,1000, 635}
+	{1056, 628,1056, 628},
+	{1056, 628,1056, 628},
+	{1056, 628,1056, 628},
+	{1056, 628,1056, 628},
+	{1056, 628,1056, 628},
+	{1056, 628,1056, 628},
+	{1056, 628,1056, 628},
+	{800, 449,1000, 644},
+	{800, 525,1000, 635}
 };
 
 SiS310_LVDSDataStruct  SiS310_LVDS1024x768Data_1[]=
 {
- {840, 438,1344, 806},
- {840, 409,1344, 806},
- {840, 438,1344, 806},
- {840, 409,1344, 806},
- {840, 518,1344, 806},
- {1050, 638,1344, 806},
- {1344, 806,1344, 806},
- {800, 449,1280, 801},
- {800, 525,1280, 813}
+	{840, 438,1344, 806},
+	{840, 409,1344, 806},
+	{840, 438,1344, 806},
+	{840, 409,1344, 806},
+	{840, 518,1344, 806},
+	{1050, 638,1344, 806},
+	{1344, 806,1344, 806},
+	{800, 449,1280, 801},
+	{800, 525,1280, 813}
 };
 
 SiS310_LVDSDataStruct  SiS310_LVDS1024x768Data_2[]=
 {
- {1344, 806,1344, 806},
- {1344, 806,1344, 806},
- {1344, 806,1344, 806},
- {1344, 806,1344, 806},
- {1344, 806,1344, 806},
- {1344, 806,1344, 806},
- {1344, 806,1344, 806},
- {800, 449,1280, 801},
- {800, 525,1280, 813}
+	{1344, 806,1344, 806},
+	{1344, 806,1344, 806},
+	{1344, 806,1344, 806},
+	{1344, 806,1344, 806},
+	{1344, 806,1344, 806},
+	{1344, 806,1344, 806},
+	{1344, 806,1344, 806},
+	{800, 449,1280, 801},
+	{800, 525,1280, 813}
 };
 
 SiS310_LVDSDataStruct  SiS310_LVDS1280x1024Data_1[]=
 {
- {840, 438,1344, 806},
- {840, 409,1344, 806},
- {840, 438,1344, 806},
- {840, 409,1344, 806},
- {840, 518,1344, 806},
- {1050, 638,1344, 806},
- {1344, 806,1344, 806},
- {800, 449,1280, 801},
- {800, 525,1280, 813}
+	{840, 438,1344, 806},
+	{840, 409,1344, 806},
+	{840, 438,1344, 806},
+	{840, 409,1344, 806},
+	{840, 518,1344, 806},
+	{1050, 638,1344, 806},
+	{1344, 806,1344, 806},
+	{800, 449,1280, 801},
+	{800, 525,1280, 813}
 };
 
 SiS310_LVDSDataStruct  SiS310_LVDS1280x1024Data_2[]=
 {
- {1344, 806,1344, 806},
- {1344, 806,1344, 806},
- {1344, 806,1344, 806},
- {1344, 806,1344, 806},
- {1344, 806,1344, 806},
- {1344, 806,1344, 806},
- {1344, 806,1344, 806},
- {800, 449,1280, 801},
- {800, 525,1280, 813}
+	{1344, 806,1344, 806},
+	{1344, 806,1344, 806},
+	{1344, 806,1344, 806},
+	{1344, 806,1344, 806},
+	{1344, 806,1344, 806},
+	{1344, 806,1344, 806},
+	{1344, 806,1344, 806},
+	{800, 449,1280, 801},
+	{800, 525,1280, 813}
 };
 
 SiS310_LVDSDataStruct  SiS310_LVDS640x480Data_1[]=
 {
- {800, 449, 800, 449},
- {800, 449, 800, 449},
- {800, 449, 800, 449},
- {800, 449, 800, 449},
- {800, 525, 800, 525},
- {1056, 628,1056, 628},
- {1056, 628,1056, 628},
- {1056, 628,1056, 628},
- {1056, 628,1056, 628}
+	{800, 449, 800, 449},
+	{800, 449, 800, 449},
+	{800, 449, 800, 449},
+	{800, 449, 800, 449},
+	{800, 525, 800, 525},
+	{1056, 628,1056, 628},
+	{1056, 628,1056, 628},
+	{1056, 628,1056, 628},
+	{1056, 628,1056, 628}
 };
 
 SiS310_LVDSDataStruct  SiS310_CHTVUNTSCData[]=
 {
- {840, 600, 840, 600},
- {840, 600, 840, 600},
- {840, 600, 840, 600},
- {840, 600, 840, 600},
- {784, 600, 784, 600},
- {1064, 750,1064, 750}
+	{840, 600, 840, 600},
+	{840, 600, 840, 600},
+	{840, 600, 840, 600},
+	{840, 600, 840, 600},
+	{784, 600, 784, 600},
+	{1064, 750,1064, 750}
 };
 
 SiS310_LVDSDataStruct  SiS310_CHTVONTSCData[]=
 {
- {840, 525, 840, 525},
- {840, 525, 840, 525},
- {840, 525, 840, 525},
- {840, 525, 840, 525},
- {784, 525, 784, 525},
- {1040, 700,1040, 700}
+	{840, 525, 840, 525},
+	{840, 525, 840, 525},
+	{840, 525, 840, 525},
+	{840, 525, 840, 525},
+	{784, 525, 784, 525},
+	{1040, 700,1040, 700}
 };
 
 SiS310_LVDSDataStruct  SiS310_CHTVUPALData[]=
 {
- {1008, 625,1008, 625},
- {1008, 625,1008, 625},
- {1008, 625,1008, 625},
- {1008, 625,1008, 625},
- {840, 750, 840, 750},
- {936, 836, 936, 836}
+	{1008, 625,1008, 625},
+	{1008, 625,1008, 625},
+	{1008, 625,1008, 625},
+	{1008, 625,1008, 625},
+	{840, 750, 840, 750},
+	{936, 836, 936, 836}
 };
 
 SiS310_LVDSDataStruct  SiS310_CHTVOPALData[]=
 {
- {1008, 625,1008, 625},
- {1008, 625,1008, 625},
- {1008, 625,1008, 625},
- {1008, 625,1008, 625},
- {840, 625, 840, 625},
- {960, 750, 960, 750}
+	{1008, 625,1008, 625},
+	{1008, 625,1008, 625},
+	{1008, 625,1008, 625},
+	{1008, 625,1008, 625},
+	{840, 625, 840, 625},
+	{960, 750, 960, 750}
 };
 
 typedef struct _SiS310_LVDSDesStruct
 {
- USHORT LCDHDES;
- USHORT LCDVDES;
+	USHORT LCDHDES;
+	USHORT LCDVDES;
 } SiS310_LVDSDesStruct;
+
 SiS310_LVDSDesStruct  SiS310_PanelType00_1[]=
 {
- {0, 626},
- {0, 624},
- {0, 626},
- {0, 624},
- {0, 624},
- { 0, 627},
- { 0, 627},
- { 0,   0},
- { 0,   0}
+	{0, 626},
+	{0, 624},
+	{0, 626},
+	{0, 624},
+	{0, 624},
+	{ 0, 627},
+	{ 0, 627},
+	{ 0,   0},
+	{ 0,   0}
 };
 
 SiS310_LVDSDesStruct  SiS310_PanelType01_1[]=
 {
- {1343, 798},
- {1343, 794},
- {1343, 798},
- {1343, 794},
- {1343,   0},
- {1343,   0},
- { 0, 805},
- { 0, 794},
- { 0,   0}
+	{1343, 798},
+	{1343, 794},
+	{1343, 798},
+	{1343, 794},
+	{1343,   0},
+	{1343,   0},
+	{ 0, 805},
+	{ 0, 794},
+	{ 0,   0}
 };
 
 SiS310_LVDSDesStruct  SiS310_PanelType02_1[]=
 {
- {0, 626},
- {0, 624},
- {0, 626},
- {0, 624},
- {0, 624},
- { 0, 627},
- { 8, 523},
- { 0,   0},
- { 0,   0}
+	{0, 626},
+	{0, 624},
+	{0, 626},
+	{0, 624},
+	{0, 624},
+	{ 0, 627},
+	{ 8, 523},
+	{ 0,   0},
+	{ 0,   0}
 };
 
 
 SiS310_LVDSDesStruct  SiS310_PanelType03_1[]=
 {
- { 8, 436},
- { 8, 440},
- { 8, 436},
- { 8, 440},
- { 8, 512},
- {1343, 798},
- {1343, 794},
- {1343, 798},
- {1343, 794}
+	{ 8, 436},
+	{ 8, 440},
+	{ 8, 436},
+	{ 8, 440},
+	{ 8, 512},
+	{1343, 798},
+	{1343, 794},
+	{1343, 798},
+	{1343, 794}
 };
 
 SiS310_LVDSDesStruct  SiS310_PanelType04_1[]=
 {
- {1343, 798},
- {1343, 794},
- {1343, 798},
- {1343, 794},
- {1343,   0},
- {1343,   0},
- { 0, 805},
- { 0, 794},
- { 0,   0}
+	{1343, 798},
+	{1343, 794},
+	{1343, 798},
+	{1343, 794},
+	{1343,   0},
+	{1343,   0},
+	{ 0, 805},
+	{ 0, 794},
+	{ 0,   0}
 };
 
 SiS310_LVDSDesStruct  SiS310_PanelType05_1[]=
 {
- {1343, 798},
- {1343, 794},
- {1343, 798},
- {1343, 794},
- {1343,   0},
- {1343,   0},
- { 0, 805},
- { 0, 794},
- { 0,   0}
+	{1343, 798},
+	{1343, 794},
+	{1343, 798},
+	{1343, 794},
+	{1343,   0},
+	{1343,   0},
+	{ 0, 805},
+	{ 0, 794},
+	{ 0,   0}
 };
 
 SiS310_LVDSDesStruct  SiS310_PanelType06_1[]=
 {
- {1343, 798},
- {1343, 794},
- {1343, 798},
- {1343, 794},
- {1343,   0},
- {1343,   0},
- { 0, 805},
- { 0, 794},
- { 0,   0}
+	{1343, 798},
+	{1343, 794},
+	{1343, 798},
+	{1343, 794},
+	{1343,   0},
+	{1343,   0},
+	{ 0, 805},
+	{ 0, 794},
+	{ 0,   0}
 };
 
 SiS310_LVDSDesStruct  SiS310_PanelType07_1[]=
 {
- {1343, 798},
- {1343, 794},
- {1343, 798},
- {1343, 794},
- {1343,   0},
- {1343,   0},
- { 0, 805},
- { 0, 794},
- { 0,   0}
+	{1343, 798},
+	{1343, 794},
+	{1343, 798},
+	{1343, 794},
+	{1343,   0},
+	{1343,   0},
+	{ 0, 805},
+	{ 0, 794},
+	{ 0,   0}
 };
 
 SiS310_LVDSDesStruct  SiS310_PanelType08_1[]=
 {
- {1059, 626},
- {1059, 624},
- {1059, 626},
- {1059, 624},
- {1059, 624},
- { 0, 627},
- { 0, 627},
- { 0,   0},
- { 0,   0}
+	{1059, 626},
+	{1059, 624},
+	{1059, 626},
+	{1059, 624},
+	{1059, 624},
+	{ 0, 627},
+	{ 0, 627},
+	{ 0,   0},
+	{ 0,   0}
 };
 
 SiS310_LVDSDesStruct  SiS310_PanelType09_1[]=
 {
- {1343, 798},
- {1343, 794},
- {1343, 798},
- {1343, 794},
- {1343,   0},
- {1343,   0},
- { 0, 805},
- { 0, 794},
- { 0,   0}
+	{1343, 798},
+	{1343, 794},
+	{1343, 798},
+	{1343, 794},
+	{1343,   0},
+	{1343,   0},
+	{ 0, 805},
+	{ 0, 794},
+	{ 0,   0}
 };
 
 SiS310_LVDSDesStruct  SiS310_PanelType0a_1[]=
 {
- {1059, 626},
- {1059, 624},
- {1059, 626},
- {1059, 624},
- {1059, 624},
- { 0, 627},
- { 0, 627},
- { 0,   0},
- { 0,   0}
+	{1059, 626},
+	{1059, 624},
+	{1059, 626},
+	{1059, 624},
+	{1059, 624},
+	{ 0, 627},
+	{ 0, 627},
+	{ 0,   0},
+	{ 0,   0}
 };
 
 SiS310_LVDSDesStruct  SiS310_PanelType0b_1[]=
 {
- {1343, 798},
- {1343, 794},
- {1343, 798},
- {1343, 794},
- {1343,   0},
- {1343,   0},
- { 0, 805},
- { 0, 794},
- { 0,   0}
+	{1343, 798},
+	{1343, 794},
+	{1343, 798},
+	{1343, 794},
+	{1343,   0},
+	{1343,   0},
+	{ 0, 805},
+	{ 0, 794},
+	{ 0,   0}
 };
 
 SiS310_LVDSDesStruct  SiS310_PanelType0c_1[]=
 {
- {1343, 798},
- {1343, 794},
- {1343, 798},
- {1343, 794},
- {1343,   0},
- {1343,   0},
- { 0, 805},
- { 0, 794},
- { 0,   0}
+	{1343, 798},
+	{1343, 794},
+	{1343, 798},
+	{1343, 794},
+	{1343,   0},
+	{1343,   0},
+	{ 0, 805},
+	{ 0, 794},
+	{ 0,   0}
 };
 
 SiS310_LVDSDesStruct  SiS310_PanelType0d_1[]=
 {
- {1343, 798},
- {1343, 794},
- {1343, 798},
- {1343, 794},
- {1343,   0},
- {1343,   0},
- { 0, 805},
- { 0, 794},
- { 0,   0}
+	{1343, 798},
+	{1343, 794},
+	{1343, 798},
+	{1343, 794},
+	{1343,   0},
+	{1343,   0},
+	{ 0, 805},
+	{ 0, 794},
+	{ 0,   0}
 };
 
 SiS310_LVDSDesStruct  SiS310_PanelType0e_1[]=
 {
- {1343, 798},
- {1343, 794},
- {1343, 798},
- {1343, 794},
- {1343,   0},
- {1343,   0},
- { 0, 805},
- { 0, 794},
- { 0,   0}
+	{1343, 798},
+	{1343, 794},
+	{1343, 798},
+	{1343, 794},
+	{1343,   0},
+	{1343,   0},
+	{ 0, 805},
+	{ 0, 794},
+	{ 0,   0}
 };
 
 SiS310_LVDSDesStruct  SiS310_PanelType0f_1[]=
 {
- {1343, 798},
- {1343, 794},
- {1343, 798},
- {1343, 794},
- {1343,   0},
- {1343,   0},
- { 0, 805},
- { 0, 794},
- { 0,   0}
+	{1343, 798},
+	{1343, 794},
+	{1343, 798},
+	{1343, 794},
+	{1343,   0},
+	{1343,   0},
+	{ 0, 805},
+	{ 0, 794},
+	{ 0,   0}
 };
 
 SiS310_LVDSDesStruct  SiS310_PanelType00_2[]=
 {
- {976, 527},
- {976, 502},
- {976, 527},
- {976, 502},
- {976, 567},
- { 0, 627},
- { 0, 627},
- { 0,   0},
- { 0,   0}
+	{976, 527},
+	{976, 502},
+	{976, 527},
+	{976, 502},
+	{976, 567},
+	{ 0, 627},
+	{ 0, 627},
+	{ 0,   0},
+	{ 0,   0}
 };
 
 SiS310_LVDSDesStruct  SiS310_PanelType01_2[]=
 {
- {1152, 622},
- {1152, 597},
- {1152, 622},
- {1152, 597},
- {1152, 662},
- {1232, 722},
- { 0, 805},
- { 0, 794},
- { 0,   0}
+	{1152, 622},
+	{1152, 597},
+	{1152, 622},
+	{1152, 597},
+	{1152, 662},
+	{1232, 722},
+	{ 0, 805},
+	{ 0, 794},
+	{ 0,   0}
 };
 
 SiS310_LVDSDesStruct  SiS310_PanelType02_2[]=
 {
- {976, 527},
- {976, 502},
- {976, 527},
- {976, 502},
- {976, 567},
- { 0, 627},
- { 0, 627},
- { 0,   0},
- { 0,   0}
+	{976, 527},
+	{976, 502},
+	{976, 527},
+	{976, 502},
+	{976, 567},
+	{ 0, 627},
+	{ 0, 627},
+	{ 0,   0},
+	{ 0,   0}
 };
 
 SiS310_LVDSDesStruct  SiS310_PanelType03_2[]=
 {
- {1152, 622},
- {1152, 597},
- {1152, 622},
- {1152, 597},
- {1152, 662},
- {1232, 722},
- { 0, 805},
- {1152, 622},
- {1152, 597}
+	{1152, 622},
+	{1152, 597},
+	{1152, 622},
+	{1152, 597},
+	{1152, 662},
+	{1232, 722},
+	{ 0, 805},
+	{1152, 622},
+	{1152, 597}
 };
 
 SiS310_LVDSDesStruct  SiS310_PanelType04_2[]=
 {
- {1152, 622},
- {1152, 597},
- {1152, 622},
- {1152, 597},
- {1152, 662},
- {1232, 722},
- { 0, 805},
- { 0, 794},
- { 0,   0}
+	{1152, 622},
+	{1152, 597},
+	{1152, 622},
+	{1152, 597},
+	{1152, 662},
+	{1232, 722},
+	{ 0, 805},
+	{ 0, 794},
+	{ 0,   0}
 };
 
 SiS310_LVDSDesStruct  SiS310_PanelType05_2[]=
 {
- {1152, 622},
- {1152, 597},
- {1152, 622},
- {1152, 597},
- {1152, 662},
- {1232, 722},
- { 0, 805},
- { 0, 794},
- { 0,   0}
+	{1152, 622},
+	{1152, 597},
+	{1152, 622},
+	{1152, 597},
+	{1152, 662},
+	{1232, 722},
+	{ 0, 805},
+	{ 0, 794},
+	{ 0,   0}
 };
 
 SiS310_LVDSDesStruct  SiS310_PanelType06_2[]=
 {
- {1152, 622},
- {1152, 597},
- {1152, 622},
- {1152, 597},
- {1152, 662},
- {1232, 722},
- { 0, 805},
- { 0, 794},
- { 0,   0}
+	{1152, 622},
+	{1152, 597},
+	{1152, 622},
+	{1152, 597},
+	{1152, 662},
+	{1232, 722},
+	{ 0, 805},
+	{ 0, 794},
+	{ 0,   0}
 };
 
 SiS310_LVDSDesStruct  SiS310_PanelType07_2[]=
 {
- {1152, 622},
- {1152, 597},
- {1152, 622},
- {1152, 597},
- {1152, 662},
- {1232, 722},
- { 0, 805},
- { 0, 794},
- { 0,   0}
+	{1152, 622},
+	{1152, 597},
+	{1152, 622},
+	{1152, 597},
+	{1152, 662},
+	{1232, 722},
+	{ 0, 805},
+	{ 0, 794},
+	{ 0,   0}
 };
 
 SiS310_LVDSDesStruct  SiS310_PanelType08_2[]=
 {
- {976, 527},
- {976, 502},
- {976, 527},
- {976, 502},
- {976, 567},
- { 0, 627},
- { 0, 627},
- { 0,   0},
- { 0,   0}
+	{976, 527},
+	{976, 502},
+	{976, 527},
+	{976, 502},
+	{976, 567},
+	{ 0, 627},
+	{ 0, 627},
+	{ 0,   0},
+	{ 0,   0}
 };
 
 SiS310_LVDSDesStruct  SiS310_PanelType09_2[]=
 {
- {1152, 622},
- {1152, 597},
- {1152, 622},
- {1152, 597},
- {1152, 662},
- {1232, 722},
- { 0, 805},
- { 0, 794},
- { 0,   0}
+	{1152, 622},
+	{1152, 597},
+	{1152, 622},
+	{1152, 597},
+	{1152, 662},
+	{1232, 722},
+	{ 0, 805},
+	{ 0, 794},
+ 	{ 0,   0}
 };
 
 SiS310_LVDSDesStruct  SiS310_PanelType0a_2[]=
 {
- {976, 527},
- {976, 502},
- {976, 527},
- {976, 502},
- {976, 567},
- { 0, 627},
- { 0, 627},
- { 0,   0},
- { 0,   0}
+	{976, 527},
+	{976, 502},
+	{976, 527},
+	{976, 502},
+	{976, 567},
+	{ 0, 627},
+	{ 0, 627},
+	{ 0,   0},
+	{ 0,   0}
 };
 
 SiS310_LVDSDesStruct  SiS310_PanelType0b_2[]=
 {
- {1152, 622},
- {1152, 597},
- {1152, 622},
- {1152, 597},
- {1152, 662},
- {1232, 722},
- { 0, 805},
- { 0, 794},
- { 0,   0}
+	{1152, 622},
+	{1152, 597},
+	{1152, 622},
+	{1152, 597},
+	{1152, 662},
+	{1232, 722},
+	{ 0, 805},
+	{ 0, 794},
+	{ 0,   0}
 };
 
 SiS310_LVDSDesStruct  SiS310_PanelType0c_2[]=
 {
- {1152, 622},
- {1152, 597},
- {1152, 622},
- {1152, 597},
- {1152, 662},
- {1232, 722},
- { 0, 805},
- { 0, 794},
- { 0,   0}
+	{1152, 622},
+	{1152, 597},
+	{1152, 622},
+	{1152, 597},
+	{1152, 662},
+	{1232, 722},
+	{ 0, 805},
+	{ 0, 794},
+	{ 0,   0}
 };
 
 SiS310_LVDSDesStruct  SiS310_PanelType0d_2[]=
 {
- {1152, 622},
- {1152, 597},
- {1152, 622},
- {1152, 597},
- {1152, 662},
- {1232, 722},
- { 0, 805},
- { 0, 794},
- { 0,   0}
+	{1152, 622},
+	{1152, 597},
+	{1152, 622},
+	{1152, 597},
+	{1152, 662},
+	{1232, 722},
+	{ 0, 805},
+	{ 0, 794},
+	{ 0,   0}
 };
 
 SiS310_LVDSDesStruct  SiS310_PanelType0e_2[]=
 {
- {1152, 622},
- {1152, 597},
- {1152, 622},
- {1152, 597},
- {1152, 662},
- {1232, 722},
- { 0, 805},
- { 0, 794},
- { 0,   0}
+	{1152, 622},
+	{1152, 597},
+	{1152, 622},
+	{1152, 597},
+	{1152, 662},
+	{1232, 722},
+	{ 0, 805},
+	{ 0, 794},
+	{ 0,   0}
 };
 
 SiS310_LVDSDesStruct  SiS310_PanelType0f_2[]=
 {
- {1152, 622},
- {1152, 597},
- {1152, 622},
- {1152, 597},
- {1152, 662},
- {1232, 722},
- { 0, 805},
- { 0, 794},
- { 0,   0}
+	{1152, 622},
+	{1152, 597},
+	{1152, 622},
+	{1152, 597},
+	{1152, 662},
+	{1232, 722},
+	{ 0, 805},
+	{ 0, 794},
+	{ 0,   0}
 };
 /*301b*/
 SiS310_LVDSDesStruct SiS310_PanelType1076_1[]=
 {
-{0x00,0x00}
+	{0x00,0x00}
 };
 SiS310_LVDSDesStruct SiS310_PanelType1210_1[]=
 {
-{0x00,0x00}
+	{0x00,0x00}
 };
 SiS310_LVDSDesStruct SiS310_PanelType1296_1[]=
 {
-{0x00,0x00}
+	{0x00,0x00}
 };
 SiS310_LVDSDesStruct SiS310_PanelType1076_2[]=
 {
-{0x00,0x00}
+	{0x00,0x00}
 };
 SiS310_LVDSDesStruct SiS310_PanelType1210_2[]=
 {
-{0x00,0x00}
+	{0x00,0x00}
 };
 SiS310_LVDSDesStruct SiS310_PanelType1296_2[]=
 {
-{0x00,0x00}
+	{0x00,0x00}
 };
 /*end 301b*/
 
 SiS310_LVDSDesStruct  SiS310_CHTVUNTSCDesData[]=
 {
- { 0,   0},
- { 0,   0},
- { 0,   0},
- { 0,   0},
- { 0,   0},
- { 0,   0}
+	{ 0,   0},
+	{ 0,   0},
+	{ 0,   0},
+	{ 0,   0},
+	{ 0,   0},
+	{ 0,   0}
 };
 
 SiS310_LVDSDesStruct  SiS310_CHTVONTSCDesData[]=
 {
- { 0,   0},
- { 0,   0},
- { 0,   0},
- { 0,   0},
- { 0,   0},
- { 0,   0}
+	{ 0,   0},
+	{ 0,   0},
+	{ 0,   0},
+	{ 0,   0},
+	{ 0,   0},
+	{ 0,   0}
 };
 
 SiS310_LVDSDesStruct  SiS310_CHTVUPALDesData[]=
 {
- {256,   0},
- {256,   0},
- {256,   0},
- {256,   0},
- { 0,   0},
- { 0,   0}
+	{256,   0},
+	{256,   0},
+	{256,   0},
+	{256,   0},
+	{ 0,   0},
+	{ 0,   0}
 };
 
 SiS310_LVDSDesStruct  SiS310_CHTVOPALDesData[]=
 {
- {256,   0},
- {256,   0},
- {256,   0},
- {256,   0},
- { 0,   0},
- { 0,   0}
+	{256,   0},
+	{256,   0},
+	{256,   0},
+	{256,   0},
+	{ 0,   0},
+	{ 0,   0}
 };
 
 /*add for LCDA*/
 typedef struct _SiS310_LCDACRT1DataStruct
 {
- UCHAR CR[17];
+ 	UCHAR CR[17];
 }SiS310_LCDACRT1DataStruct;
+
 SiS310_LCDACRT1DataStruct  SiS310_LCDACRT1800x600_1[]=
 {
 {{0x65,0x4f,0x89,0x56,0x83,0xaf,0x1f,
@@ -2284,8 +2307,9 @@
 
 typedef struct _SiS310_LVDSCRT1DataStruct
 {
- UCHAR CR[15];
+ 	UCHAR CR[15];
 } SiS310_LVDSCRT1DataStruct;
+
 SiS310_LVDSCRT1DataStruct  SiS310_LVDSCRT1320x480_1[]=
 {
 {{0x65,0x4f,0x89,0x56,0x83,0xaa,0x1f,
@@ -2688,22 +2712,23 @@
 
 typedef struct _SiS310_CHTVRegDataStruct
 {
- UCHAR Reg[5];
+ 	UCHAR Reg[5];
 } SiS310_CHTVRegDataStruct;
+
 SiS310_CHTVRegDataStruct SiS310_CHTVReg_UNTSC[] = {
-{{0x00}}
+	{{0x00}}
  };
 
 SiS310_CHTVRegDataStruct SiS310_CHTVReg_ONTSC[] = {
-{{0x00}}
+	{{0x00}}
  };
 
 SiS310_CHTVRegDataStruct SiS310_CHTVReg_UPAL[] = {
-{{0x00}}
+	{{0x00}}
  };
 
 SiS310_CHTVRegDataStruct SiS310_CHTVReg_OPAL[] = {
-{{0x00}}
+	{{0x00}}
  };
 
 UCHAR SiS310_CHTVVCLKUNTSC[]={0x00 };
diff -urN linux-2.4.19-pre9/drivers/video/sis/Makefile linux-2.4.19-pre10/drivers/video/sis/Makefile
--- linux-2.4.19-pre9/drivers/video/sis/Makefile	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/video/sis/Makefile	Fri Nov  9 14:11:14 2001
@@ -3,17 +3,12 @@
 #
 
 O_TARGET := sisfb.o
-obj-y    := sis_main.o init.o init301.o
 
-# All of the (potential) objects that export symbols.
+export-objs := sis_main.o
 
-export-objs    :=  sis_main.o
-
-# Each configuration option enables a list of files.
-
-obj-m    := $(O_TARGET)
+obj-y  := sis_main.o init.o init301.o
+obj-m  := $(O_TARGET)
 
 include $(TOPDIR)/Rules.make
 
-clean:
-	rm -f core *.o
+
diff -urN linux-2.4.19-pre9/drivers/video/sis/init.c linux-2.4.19-pre10/drivers/video/sis/init.c
--- linux-2.4.19-pre9/drivers/video/sis/init.c	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/video/sis/init.c	Mon Jun  3 18:50:56 2002
@@ -1,7 +1,12 @@
-/* Function: Support NT X.0  MM function  */
-/* Version : V 0.80      [ynlai] 04/12/98 */
-
-/* Comments and changes marked with "TW" by Thomas Winischhofer <tw@webit.com> */
+/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/sis/init.c,v 1.3 2000/12/02 01:16:16 dawes Exp $ */
+/*
+ * Mode switching code (CRT1 section) for SiS 300/540/630/730/315/550/650/740
+ * (Universal module for Linux kernel framebuffer, XFree86 4.x)
+ *
+ * Comments and changes marked with "TW" by Thomas Winischhofer <thomer@winischhofer.net>
+ *
+ * (Version : V 0.80      [ynlai] 04/12/98)
+ */
 
 /*
 #ifdef WINCE_HEADER
@@ -26,7 +31,6 @@
 #include "dderror.h"
 #include "devioctl.h"
 #include "miniport.h"
-
 #include "ntddvdeo.h"
 #include "video.h"
 #include "sisv.h"
@@ -43,7 +47,7 @@
 #ifdef LINUX_XF86
 BOOLEAN SiSBIOSSetMode(PSIS_HW_DEVICE_INFO HwDeviceExtension,
                        ScrnInfoPtr pScrn, DisplayModePtr mode);
-#ifdef SISDUALHEAD
+#ifdef SISDUALHEAD /* TW: For dual head */
 BOOLEAN SiSBIOSSetModeCRT1(PSIS_HW_DEVICE_INFO HwDeviceExtension,
                        ScrnInfoPtr pScrn, DisplayModePtr mode);
 BOOLEAN SiSBIOSSetModeCRT2(PSIS_HW_DEVICE_INFO HwDeviceExtension,
@@ -51,7 +55,9 @@
 #endif /* dual head */
 #endif /* linux_xf86 */
 
+#ifndef LINUX_XF86
 BOOLEAN SiSInit(PSIS_HW_DEVICE_INFO HwDeviceExtension);
+#endif
 
 #ifdef LINUX_XF86
 BOOLEAN SiSSetMode(PSIS_HW_DEVICE_INFO HwDeviceExtension,
@@ -60,7 +66,6 @@
 BOOLEAN SiSSetMode(PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT ModeNo);
 #endif
 
-
 #if defined(ALLOC_PRAGMA)
 #pragma alloc_text(PAGE,SiSSetMode)
 #pragma alloc_text(PAGE,SiSInit)
@@ -79,6 +84,7 @@
 void DebugCode(UCHAR code);
 
 #ifdef LINUX_XF86
+/* TW: Mode table for X driver */
 UShort  ModeIndex_640x480[]   = {0x2E, 0x44, 0x45, 0x62};
 UShort  ModeIndex_720x480[]   = {0x31, 0x33, 0x00, 0x35};
 UShort  ModeIndex_720x576[]   = {0x32, 0x34, 0x00, 0x36};
@@ -130,7 +136,7 @@
 InitTo300Pointer(void)
 {
    SiS_SModeIDTable = (SiS_StStruct *) SiS300_SModeIDTable;
-   SiS_VBModeIDTable = (SiS_VBModeStruct *) SiS300_VBModeIDTable;/*add for 300 oem util*/
+   SiS_VBModeIDTable = (SiS_VBModeStruct *) SiS300_VBModeIDTable;	/*add for 300 oem util*/
    SiS_StandTable = (SiS_StandTableStruct *) SiS300_StandTable;
    SiS_EModeIDTable = (SiS_ExtStruct *) SiS300_EModeIDTable;
    SiS_RefIndex = (SiS_Ext2Struct *) SiS300_RefIndex;
@@ -451,6 +457,7 @@
 }
 #endif
 
+#ifndef LINUX_XF86
 /* -------------- SiSInit -----------------*/
 BOOLEAN
 SiSInit(PSIS_HW_DEVICE_INFO HwDeviceExtension)
@@ -467,7 +474,6 @@
    UCHAR   SR12=0,SR13=0,SR14=0,SR16=0,SR17=0,SR18=0,SR19=0,SR1A=0;
 
 #ifdef SIS315H
-   /* ULONG   j, k;   */
    UCHAR   CR37=0,CR38=0,CR79=0,CR7A=0,CR7B=0,CR7C=0;
    UCHAR   SR1B=0,SR15=0;
    PSIS_DSReg  pSR;
@@ -475,7 +481,6 @@
 #endif
    UCHAR   VBIOSVersion[5];
 
-/* if(ROMAddr==0)   return (FALSE);*/
    if(FBAddr==0)    return (FALSE);
    if(BaseAddr==0)  return (FALSE);
 
@@ -483,14 +488,13 @@
 
 #ifdef SIS315H
    /*if(HwDeviceExtension->jChipType > SIS_315H)*/
-   if(HwDeviceExtension->jChipType > SIS_315PRO)
-   {
-     if(!HwDeviceExtension->bIntegratedMMEnabled)  return (FALSE);  /* alan  */
+   if(HwDeviceExtension->jChipType > SIS_315PRO) {
+     if(!HwDeviceExtension->bIntegratedMMEnabled)
+     	return (FALSE);  /* alan  */
    }
 #endif
 
    SiS_MemoryCopy(VBIOSVersion,HwDeviceExtension->szVBIOSVer,4);
-
    VBIOSVersion[4]= 0x0;
    /* 09/07/99 modify by domao */
 
@@ -500,7 +504,7 @@
       (HwDeviceExtension->jChipType == SIS_550)||   /* 05/02/01 ynlai for 550 */
       (HwDeviceExtension->jChipType == SIS_640)||   /* 08/20/01 chiawen for 640/740 */
       (HwDeviceExtension->jChipType == SIS_740)||   /* 09/03/01 chiawen for 640/740 */
-      (HwDeviceExtension->jChipType == SIS_650))   /* 09/03/01 chiawen for 650 */
+      (HwDeviceExtension->jChipType == SIS_650))    /* 09/03/01 chiawen for 650 */
      InitTo310Pointer();
 #endif
 
@@ -512,29 +516,17 @@
      InitTo300Pointer();
 #endif
 
-   SiS_P3c4=BaseAddr+0x14;
-   SiS_P3d4=BaseAddr+0x24;
-   SiS_P3c0=BaseAddr+0x10;
-   SiS_P3ce=BaseAddr+0x1e;
-   SiS_P3c2=BaseAddr+0x12;
-   SiS_P3ca=BaseAddr+0x1a;
-   SiS_P3c6=BaseAddr+0x16;
-   SiS_P3c7=BaseAddr+0x17;
-   SiS_P3c8=BaseAddr+0x18;
-   SiS_P3c9=BaseAddr+0x19;
-   SiS_P3da=BaseAddr+0x2A;
-   SiS_Part1Port=BaseAddr+SIS_CRT2_PORT_04;
-   SiS_Part2Port=BaseAddr+SIS_CRT2_PORT_10;
-   SiS_Part3Port=BaseAddr+SIS_CRT2_PORT_12;
-   SiS_Part4Port=BaseAddr+SIS_CRT2_PORT_14;
-   SiS_Part5Port=BaseAddr+SIS_CRT2_PORT_14+2;
-   SiS_Set_LVDS_TRUMPION(HwDeviceExtension); /*2/29/00 by Mars Wen for LVDS and Trumpion  */
+   /* TW: Set SiS Register globals */
+   SiSRegInit(BaseAddr);
+
+   /* TW: Determine LVDS/CH7005/TRUMPION */
+   SiS_Set_LVDS_TRUMPION(HwDeviceExtension);
 
-   SiS_SetReg1(SiS_P3c4,0x05,0x86);                     /* 1.Openkey  */
+   SiS_SetReg1(SiS_P3c4,0x05,0x86);                     /* 1.Openkey - unlock registers */
 
 #ifdef LINUX_KERNEL
 
-#ifdef SIS300                                         /* add to set SR14*/
+#ifdef SIS300                                         	/* add to set SR14*/
    if((HwDeviceExtension->jChipType==SIS_540)||
       (HwDeviceExtension->jChipType==SIS_630)||
       (HwDeviceExtension->jChipType==SIS_730)) {
@@ -554,12 +546,11 @@
       	SR14=(0x10000000)|SR14;
      else
       	SR14=(0x01000000)|SR14;
-    }
+   }
 #endif
 
 #ifdef SIS315H                                         /* add to set SR14*/
-   if((HwDeviceExtension->jChipType==SIS_550))
-   {
+   if(HwDeviceExtension->jChipType==SIS_550) {
      base=0x80000060;
      OutPortLong(base,0xcf8);
      temp1=InPortLong(0xcfc);
@@ -576,50 +567,36 @@
       SR14=(0x10000000)|SR14;
      else
       SR14=(0x01000000)|SR14;
-    }
- 
-  if((HwDeviceExtension->jChipType == SIS_640)||   /* 08/20/01 chiawen for 640/740 */
-     (HwDeviceExtension->jChipType == SIS_740)||   /* 09/03/01 chiawen for 640/740 */
-     (HwDeviceExtension->jChipType == SIS_650))   /* 09/03/01 chiawen for 650 */
-   {
+   }
+
+   if((HwDeviceExtension->jChipType == SIS_640)||   /* 08/20/01 chiawen for 640/740 */
+      (HwDeviceExtension->jChipType == SIS_740)||   /* 09/03/01 chiawen for 640/740 */
+      (HwDeviceExtension->jChipType == SIS_650)) {  /* 09/03/01 chiawen for 650 */
      base=0x80000064;
      OutPortLong(base,0xcf8);
      temp1=InPortLong(0xcfc);
      temp1=temp>>4;
      temp1=temp1&(0x07);
-     if(temp1 > 2 )
-     {
+     if(temp1 > 2 ) {
        temp = temp1;
        switch(temp) {
-       case 3:
-	 temp1=0x07;
-       break;
-       case 4:
-	 temp1=0x0F;
-       break;
-       case 5:
-	 temp1=0x1F;
-       break;
-       case 6:
-	 temp1=0x05;
-       break;
-       case 7:
-	 temp1=0x17;
-       break;
-       case 8:
-       break;
-       case 9:
-       break;
-      }
-    }
+        case 3: temp1=0x07;  break;
+        case 4: temp1=0x0F;  break;
+        case 5: temp1=0x1F;  break;
+        case 6: temp1=0x05;  break;
+        case 7: temp1=0x17;  break;
+        case 8: break;
+        case 9: break;
+       }
+     }
      SR14=temp1;
      base=0x8000007C;
      OutPortLong(base,0xcf8);
      temp1=InPortLong(0xcfc);
      temp1=temp1&(0x00000020);
      if(temp1)
-      SR14=(0x10000000)|SR14;
-  }
+       SR14=(0x10000000)|SR14;
+   }
 #endif
 
 #endif  /* Linux kernel */
@@ -636,8 +613,7 @@
      SR18 = (UCHAR)SiS_GetReg1(SiS_P3c4,0x18);
      SR19 = (UCHAR)SiS_GetReg1(SiS_P3c4,0x19);
      SR1A = (UCHAR)SiS_GetReg1(SiS_P3c4,0x1A);
-   }
-   else {
+   } else if(HwDeviceExtension->jChipType == SIS_300){
      SR13 = (UCHAR)SiS_GetReg1(SiS_P3c4,0x13);
      SR14 = (UCHAR)SiS_GetReg1(SiS_P3c4,0x14);
    }
@@ -648,7 +624,7 @@
       (HwDeviceExtension->jChipType == SIS_740)||   /* 09/03/01 chiawen for 640/740 */
       (HwDeviceExtension->jChipType == SIS_650)) {  /* 09/03/01 chiawen for 650 */
      SR19 = (UCHAR)SiS_GetReg1(SiS_P3c4,0x19);
-     SR19 = (SR19)||0x01;
+     SR19 = (SR19)||0x01;  /* TW: ??? || ??? */
      if(SR19==0x00) {
      	SR13 = 0x22;
      	SR14 = 0x00;
@@ -657,9 +633,7 @@
      	SR17 = 0x00;
      	SR1A = 0x00;
      	SR1B = 0x00;
-
      	CR37 = 0x00;
-
      	CR38 = 0x00;
      	CR79 = 0x00;
      	CR7A = 0x00;
@@ -673,9 +647,7 @@
      	SR17 = (UCHAR)SiS_GetReg1(SiS_P3c4,0x17);
      	SR1A = (UCHAR)SiS_GetReg1(SiS_P3c4,0x1A);
      	SR1B = (UCHAR)SiS_GetReg1(SiS_P3c4,0x1B);
-
      	CR37 = 0x02;/*(UCHAR)SiS_GetReg1(SiS_P3d4,0x37);*/
-
      	CR38 = (UCHAR)SiS_GetReg1(SiS_P3d4,0x38);
      	CR79 = (UCHAR)SiS_GetReg1(SiS_P3d4,0x79);
      	CR7A = (UCHAR)SiS_GetReg1(SiS_P3d4,0x7A);
@@ -685,13 +657,19 @@
    }
 #endif
 
-/* ResetExtReg begin */
+/* ResetExtReg begin: Reset extended registers */
+
    for(i=0x06;i< 0x20;i++) SiS_SetReg1(SiS_P3c4,i,0);   /* 2.Reset Extended register */
    for(i=0x21;i<=0x27;i++) SiS_SetReg1(SiS_P3c4,i,0);   /*   Reset Extended register */
    for(i=0x31;i<=0x3D;i++) SiS_SetReg1(SiS_P3c4,i,0);
 
-#ifdef SIS300H /* TW: 300H ? */
-   for(i=0x38;i<=0x3F;i++) SiS_SetReg1(SiS_P3d4,i,0);
+#ifdef SIS300
+   if((HwDeviceExtension->jChipType == SIS_540)||
+      (HwDeviceExtension->jChipType == SIS_630)||
+      (HwDeviceExtension->jChipType == SIS_730)||
+      (HwDeviceExtension->jChipType == SIS_300)) {
+     	for(i=0x38;i<=0x3F;i++) SiS_SetReg1(SiS_P3d4,i,0);
+   }
 #endif
 
 #ifdef SIS315H
@@ -711,14 +689,14 @@
    if((HwDeviceExtension->jChipType == SIS_540)||
       (HwDeviceExtension->jChipType == SIS_630)||
       (HwDeviceExtension->jChipType == SIS_730)) {
-       SiS_SetReg1(SiS_P3c4,0x12,SR12);
-       SiS_SetReg1(SiS_P3c4,0x13,SR13);
-       SiS_SetReg1(SiS_P3c4,0x14,SR14);
-       SiS_SetReg1(SiS_P3c4,0x16,SR16);
-       SiS_SetReg1(SiS_P3c4,0x17,SR17);
-       SiS_SetReg1(SiS_P3c4,0x18,SR18);
-       SiS_SetReg1(SiS_P3c4,0x19,SR19);
-       SiS_SetReg1(SiS_P3c4,0x1A,SR1A);
+     SiS_SetReg1(SiS_P3c4,0x12,SR12);
+     SiS_SetReg1(SiS_P3c4,0x13,SR13);
+     SiS_SetReg1(SiS_P3c4,0x14,SR14);
+     SiS_SetReg1(SiS_P3c4,0x16,SR16);
+     SiS_SetReg1(SiS_P3c4,0x17,SR17);
+     SiS_SetReg1(SiS_P3c4,0x18,SR18);
+     SiS_SetReg1(SiS_P3c4,0x19,SR19);
+     SiS_SetReg1(SiS_P3c4,0x1A,SR1A);
    }
 #endif
 
@@ -726,50 +704,48 @@
    if((HwDeviceExtension->jChipType == SIS_550)||
       (HwDeviceExtension->jChipType == SIS_640)||   /* 08/20/01 chiawen for 640/740 */
       (HwDeviceExtension->jChipType == SIS_740)||   /* 09/03/01 chiawen for 640/740 */
-      (HwDeviceExtension->jChipType == SIS_650))   /* 09/03/01 chiawen for 650 */
-     {
-       SiS_SetReg1(SiS_P3c4,0x13,SR13);
-       SiS_SetReg1(SiS_P3c4,0x14,SR14);
-       SiS_SetReg1(SiS_P3c4,0x15,SR15);
-       SiS_SetReg1(SiS_P3c4,0x16,SR16);
-       SiS_SetReg1(SiS_P3c4,0x17,SR17);
-       SiS_SetReg1(SiS_P3c4,0x19,SR19);
-       SiS_SetReg1(SiS_P3c4,0x1A,SR1A);
-       SiS_SetReg1(SiS_P3c4,0x1B,SR1B);
-
-       SiS_SetReg1(SiS_P3d4,0x37,CR37);
-       SiS_SetReg1(SiS_P3d4,0x38,CR38);
-       SiS_SetReg1(SiS_P3d4,0x79,CR79);
-       SiS_SetReg1(SiS_P3d4,0x7A,CR7A);
-       SiS_SetReg1(SiS_P3d4,0x7B,CR7B);
-       SiS_SetReg1(SiS_P3d4,0x7C,CR7C);
+      (HwDeviceExtension->jChipType == SIS_650)) {  /* 09/03/01 chiawen for 650 */
+     SiS_SetReg1(SiS_P3c4,0x13,SR13);
+     SiS_SetReg1(SiS_P3c4,0x14,SR14);
+     SiS_SetReg1(SiS_P3c4,0x15,SR15);
+     SiS_SetReg1(SiS_P3c4,0x16,SR16);
+     SiS_SetReg1(SiS_P3c4,0x17,SR17);
+     SiS_SetReg1(SiS_P3c4,0x19,SR19);
+     SiS_SetReg1(SiS_P3c4,0x1A,SR1A);
+     SiS_SetReg1(SiS_P3c4,0x1B,SR1B);
+     SiS_SetReg1(SiS_P3d4,0x37,CR37);
+     SiS_SetReg1(SiS_P3d4,0x38,CR38);
+     SiS_SetReg1(SiS_P3d4,0x79,CR79);
+     SiS_SetReg1(SiS_P3d4,0x7A,CR7A);
+     SiS_SetReg1(SiS_P3d4,0x7B,CR7B);
+     SiS_SetReg1(SiS_P3d4,0x7C,CR7C);
    }
 #endif
 
-/* detect ExtChip Type */
-   SiS_Set_LVDS_TRUMPION(HwDeviceExtension); /*2/29/00 by Mars Wen for LVDS and Trumpion  */
-
 #ifdef SIS300
    if((HwDeviceExtension->jChipType==SIS_540)||
       (HwDeviceExtension->jChipType==SIS_630)||
-      (HwDeviceExtension->jChipType==SIS_730))  {
+      (HwDeviceExtension->jChipType==SIS_730)) {
      	temp=(UCHAR)SR1A;
+   } else if(HwDeviceExtension->jChipType==SIS_300) {
+        /* TW: Nothing */
    } else
 #endif
    {
       	if((*pSiS_SoftSetting&SoftDRAMType)==0){
           	temp=(UCHAR)SiS_GetReg1(SiS_P3c4,0x3A);
-      }
+        }
    }
 
    SiS_RAMType=temp&0x03;
    SiS_SetMemoryClock(ROMAddr);
 
-/* SetDefExt1Regs  begin */
-   SiS_SetReg1(SiS_P3c4,0x07,*pSiS_SR07);
-   if((HwDeviceExtension->jChipType!=SIS_540)&&
-      (HwDeviceExtension->jChipType!=SIS_630)&&
-      (HwDeviceExtension->jChipType!=SIS_730)){
+/* SetDefExt1Regs begin: Set default register contents */
+
+   SiS_SetReg1(SiS_P3c4,0x07,*pSiS_SR07); 		/* DAC speed */
+   if((HwDeviceExtension->jChipType != SIS_540)&&
+      (HwDeviceExtension->jChipType != SIS_630)&&
+      (HwDeviceExtension->jChipType != SIS_730)){
      	for(i=0x15;i<0x1C;i++) {
        		SiS_SetReg1(SiS_P3c4,i,SiS_SR15[i-0x15][SiS_RAMType]);
      	}
@@ -787,7 +763,7 @@
    }
 #endif
 
-   SiS_SetReg1(SiS_P3c4,0x1F,*pSiS_SR1F);
+   SiS_SetReg1(SiS_P3c4,0x1F,*pSiS_SR1F); 	/* DAC pedestal */
    /*SiS_SetReg1(SiS_P3c4,0x20,0x20);*/
    SiS_SetReg1(SiS_P3c4,0x20,0xA0); /* alan, 2001/6/26 Frame buffer can read/write*/
    SiS_SetReg1(SiS_P3c4,0x23,*pSiS_SR23);
@@ -802,7 +778,7 @@
 #endif
 
    SR11=0x0F;
-   SiS_SetReg1(SiS_P3c4,0x11,SR11);
+   SiS_SetReg1(SiS_P3c4,0x11,SR11);	/* Power Management */
 
    SiS_UnLockCRT2(HwDeviceExtension, BaseAddr);
    SiS_SetReg1(SiS_Part1Port,0x00,0x00);
@@ -815,7 +791,6 @@
       (HwDeviceExtension->jChipType == SIS_640)||   /* 08/20/01 chiawen for 640/740 */
       (HwDeviceExtension->jChipType == SIS_740)||   /* 09/03/01 chiawen for 640/740 */
       (HwDeviceExtension->jChipType == SIS_650))    /* 09/03/01 chiawen for 650 */
-
      	SiS_SetReg1(SiS_Part1Port,0x2E,0x08); /* use VB */
 #endif
 
@@ -828,20 +803,19 @@
 #ifdef SIS315H
    if ((HwDeviceExtension->jChipType == SIS_315H) ||
        (HwDeviceExtension->jChipType == SIS_315PRO)) {
+     HwDeviceExtension->pQueryVGAConfigSpace(HwDeviceExtension,0x50,0,&Temp);  /* Get */
+     Temp >>= 20;
+     Temp &= 0xF;
+     if (Temp!=1) {
+     	SiS_SetReg1(SiS_P3c4,0x25,SiS_SR25[1]);
+     	SiS_SetReg1(SiS_P3d4,0x49,SiS_CR49[1]);
+     }
 
-     	HwDeviceExtension->pQueryVGAConfigSpace(HwDeviceExtension,0x50,0,&Temp);  /* Get */
-	Temp >>= 20;
-     	Temp &= 0xF;
-     	if (Temp!=1) {
-       		SiS_SetReg1(SiS_P3c4,0x25,SiS_SR25[1]);
-       		SiS_SetReg1(SiS_P3d4,0x49,SiS_CR49[1]);
-     	}
-
-     	SiS_SetReg1(SiS_P3c4,0x27,0x1F);
-   
-     	SiS_SetReg1(SiS_P3c4,0x31,*pSiS_SR31);
-     	SiS_SetReg1(SiS_P3c4,0x32,*pSiS_SR32);
-     	SiS_SetReg1(SiS_P3c4,0x33,*pSiS_SR33);
+     SiS_SetReg1(SiS_P3c4,0x27,0x1F);
+
+     SiS_SetReg1(SiS_P3c4,0x31,*pSiS_SR31);
+     SiS_SetReg1(SiS_P3c4,0x32,*pSiS_SR32);
+     SiS_SetReg1(SiS_P3c4,0x33,*pSiS_SR33);
    }
 #endif
 
@@ -861,7 +835,6 @@
 #ifdef SIS315H
    if ((HwDeviceExtension->jChipType==SIS_315H)||
        (HwDeviceExtension->jChipType==SIS_315PRO)) { /* 05/02/01 ynlai */
-       	/* For SiS 300,310 Chip  */
        	if (HwDeviceExtension->bSkipDramSizing==TRUE) {
          	SiS_SetDRAMModeRegister(ROMAddr);
          	pSR = HwDeviceExtension->pSR;
@@ -871,7 +844,7 @@
              			pSR++;
            		}
          	}
-       } else 	SiS_SetDRAMSize_310(HwDeviceExtension);
+       } else SiS_SetDRAMSize_310(HwDeviceExtension);
    }
 #endif
 
@@ -963,45 +936,15 @@
   if ((HwDeviceExtension->jChipType == SIS_540)||
       (HwDeviceExtension->jChipType == SIS_630)||
       (HwDeviceExtension->jChipType == SIS_730)) {
-        /* TW: Read POWER_ON_TRAP and copy to CR34 */
+        /* TW: Read POWER_ON_TRAP and copy to CR37 */
     	temp = (UCHAR)SiS_GetReg1(SiS_P3c4,0x1A);
     	temp=(temp&0xE0)>>4;
    	SiS_SetRegANDOR(SiS_P3d4,0x37,0xF1,temp);
-    	temp=temp>>1;
    }
 #endif
 
-#ifdef SiS315
-  if ((HwDeviceExtension->jChipType == SIS_550)||
-      (HwDeviceExtension->jChipType == SIS_640)||   /* 08/20/01 chiawen for 640/740 */
-      (HwDeviceExtension->jChipType == SIS_740)||   /* 09/03/01 chiawen for 640/740 */
-      (HwDeviceExtension->jChipType == SIS_650)) {  /* 09/03/01 chiawen for 650 */
-  	temp = (UCHAR)SiS_GetReg1(SiS_P3d4,0x37);
-    	temp=(temp&0x0E)>>1;
-  }
-#endif
-  if ((HwDeviceExtension->jChipType == SIS_540)||
-      (HwDeviceExtension->jChipType == SIS_630)||
-      (HwDeviceExtension->jChipType == SIS_730)||
-      (HwDeviceExtension->jChipType == SIS_550)||
-      (HwDeviceExtension->jChipType == SIS_640)||   /* 08/20/01 chiawen for 640/740 */
-      (HwDeviceExtension->jChipType == SIS_740)||   /* 09/03/01 chiawen for 640/740 */
-      (HwDeviceExtension->jChipType == SIS_650)) {
-    	if((temp==0)||(temp==1))  {   /* for 301 */
-      		SiS_IF_DEF_LVDS=0;
-      		SiS_IF_DEF_CH7005=0;
-      		SiS_IF_DEF_TRUMPION=0;
-    	}
-    	if((temp>=2)&&(temp<=5))  {
-      		SiS_IF_DEF_LVDS=1;
-    	}
-    	if(temp==3) SiS_IF_DEF_TRUMPION=1;
-    	if((temp==4)||(temp==5)) SiS_IF_DEF_CH7005=1;
-  } else {
-    	SiS_IF_DEF_LVDS=0;
-    	SiS_IF_DEF_TRUMPION=0;
-    	SiS_IF_DEF_CH7005=0;
-  }
+   /* Set globals SiS_IF_DEF... */
+   SiSSetLVDSetc(HwDeviceExtension, 0);
 }
 
 /* ===============  for 300 dram sizing begin  =============== */
@@ -1023,11 +966,8 @@
    /*int PageCapacity,PhysicalAdrHigh,PhysicalAdrHalfPage,PhysicalAdrAnotherPage;*/
    int PageCapacity,PhysicalAdrHigh,PhysicalAdrHalfPage;
 
-#ifdef LINUX_XF86
-   SiSSetMode(HwDeviceExtension,NULL,0x2e);
-#else
    SiSSetMode(HwDeviceExtension,0x2e);
-#endif
+
    data=SiS_GetReg1(SiS_P3c4,0x1);
    data=data|0x20;
    SiS_SetReg1(SiS_P3c4,0x01,data);                    /* Turn OFF Display  */
@@ -1124,24 +1064,10 @@
 
 /* ===============  for 300 dram sizing end    =============== */
 
-/* =============== 301 dram sizing begin ===================== */
+/* ===============  310 dram sizing begin ==================== */
 #ifdef SIS315H
-UCHAR
-SiS_Get310DRAMType(ULONG   ROMAddr)
-{
-   UCHAR   data;
 
-  /* 
-  index=SiS_GetReg1(SiS_P3c4,0x1A);
-  index=index&07;
-  */
-   if (*pSiS_SoftSetting&SoftDRAMType)
-     data = *pSiS_SoftSetting & 0x03;
-   else
-     data=SiS_GetReg1(SiS_P3c4,0x3a) & 0x03;
-
-   return data;
-}
+/* TW: Moved Get310DRAMType further down */
 
 void
 SiS_Delay15us(ULONG ulMicrsoSec)
@@ -1187,8 +1113,7 @@
    data &= 0x0F;
    data |= 0x20;
    SiS_SetReg1(SiS_P3c4,0x16,data);
-   if (!(SiS_SR15[1][SiS_RAMType] & 0x10))
-   {
+   if (!(SiS_SR15[1][SiS_RAMType] & 0x10)) {
      data &= 0x0F;
    }
    /* SR16 D7=1 */
@@ -1200,12 +1125,9 @@
 SiS_SetDRAMModeRegister(ULONG ROMAddr)
 {
 
-    if (SiS_Get310DRAMType(ROMAddr)<2)
-    {
+    if (SiS_Get310DRAMType(ROMAddr)<2) {
       SiS_SDR_MRS();
-    }
-    else
-    {
+    } else {
       /* SR16 <- 0F,CF,0F,8F */
       SiS_DDR_MRS();
     }
@@ -1242,17 +1164,13 @@
    data &= 0x1F;
    switch (SiS_DDRDRAM_TYPE[index][3])
    {
-     case 64:
-              data |= 0;
+     case 64: data |= 0;
               break;
-     case 32:
-              data |= 0x20;
+     case 32: data |= 0x20;
               break;
-     case 16:
-              data |= 0x40;
+     case 16: data |= 0x40;
               break;
-     case 4:
-              data |= 0x60;
+     case 4:  data |= 0x60;
               break;
    }
    SiS_SetReg1(SiS_P3c4,0x15,data);
@@ -1293,8 +1211,7 @@
      pVideoMemory[5] = 0x55555555L;
      pVideoMemory[6] = 0xFFFFFFFFL;
      pVideoMemory[7] = 0xFFFFFFFFL;
-     if ((pVideoMemory[3]!=0xCDEF0123L) || (pVideoMemory[2] != 0x89ABCDEFL))
-     {
+     if ((pVideoMemory[3]!=0xCDEF0123L) || (pVideoMemory[2] != 0x89ABCDEFL)) {
        /*ChannelA64Bit */
        SiS_DataBusWidth = 64;
        SiS_ChannelAB = 0;
@@ -1302,8 +1219,7 @@
        SiS_SetReg1(SiS_P3c4,  0x14, (USHORT) (data & 0xFD));
      }
 
-     if ((pVideoMemory[1]!=0x456789ABL) || (pVideoMemory[0] != 0x01234567L))
-     {
+     if ((pVideoMemory[1]!=0x456789ABL) || (pVideoMemory[0] != 0x01234567L)) {
        /*ChannelB64Bit */
        SiS_DataBusWidth = 64;
        SiS_ChannelAB = 1;
@@ -1312,9 +1228,7 @@
      }
      return;
 
-   }
-   else
-   {
+   } else {
      /* DDR Dual channel */
      SiS_SetReg1(SiS_P3c4,0x13,0x00);
      SiS_SetReg1(SiS_P3c4,0x14,0x02); /* Channel A, 64bit */
@@ -1332,24 +1246,18 @@
      pVideoMemory[6] = 0xAAAAAAAAL;
      pVideoMemory[7] = 0xAAAAAAAAL;
 
-     if (pVideoMemory[1] == 0x456789ABL)
-     {
-       if (pVideoMemory[0] == 0x01234567L)
-       {
+     if (pVideoMemory[1] == 0x456789ABL) {
+       if (pVideoMemory[0] == 0x01234567L) {
          /* Channel A 64bit */
          return;
        }
-     }
-     else
-     {
-       if (pVideoMemory[0] == 0x01234567L)
-       {
+     } else {
+       if (pVideoMemory[0] == 0x01234567L) {
          /* Channel A 32bit */
          SiS_DataBusWidth = 32;
          SiS_SetReg1(SiS_P3c4,0x14,0x00);
          return;
        }
-
      }
 
      SiS_SetReg1(SiS_P3c4,0x14,0x03); /* Channel B, 64bit */
@@ -1365,29 +1273,20 @@
      pVideoMemory[5] = 0x55555555L;
      pVideoMemory[6] = 0xAAAAAAAAL;
      pVideoMemory[7] = 0xAAAAAAAAL;
-     if (pVideoMemory[1] == 0x456789ABL)
-     {
+     if (pVideoMemory[1] == 0x456789ABL) {
        /* Channel B 64 */
-       if (pVideoMemory[0] == 0x01234567L)
-       {
+       if (pVideoMemory[0] == 0x01234567L) {
          /* Channel B 64bit */
          return;
-       }
-       else
-       {
+       } else {
          /* error */
        }
-     }
-     else
-     {
-       if (pVideoMemory[0] == 0x01234567L)
-       {
+     } else {
+       if (pVideoMemory[0] == 0x01234567L) {
          /* Channel B 32 */
          SiS_DataBusWidth = 32;
          SiS_SetReg1(SiS_P3c4,0x14,0x01);
-       }
-       else
-       {
+       } else {
          /* error */
        }
      }
@@ -1405,11 +1304,9 @@
 
   RankSize = DRAMTYPE_TABLE[index][3]/2 * SiS_DataBusWidth/32;
 
-  if (RankNo*RankSize<=128)
-  {
+  if (RankNo*RankSize<=128) {
     data = 0;
-    while ((RankSize>>=1)>0)
-    {
+    while ((RankSize>>=1)>0) {
       data+=0x10;
     }
     data |= (RankNo-1)<<2;
@@ -1419,24 +1316,22 @@
     /* should delay */
     SiS_SDR_MRS();
     return 1;
-  }
-  else
+  } else
     return 0;
 }
 
 int
-SiS_SetDDRChannel(int index,UCHAR ChannelNo,UCHAR SiS_ChannelAB,USHORT DRAMTYPE_TABLE[][5])
+SiS_SetDDRChannel(int index,UCHAR ChannelNo,UCHAR SiS_ChannelAB,
+                  USHORT DRAMTYPE_TABLE[][5])
 {
   USHORT  data;
   int RankSize;
 
   RankSize = DRAMTYPE_TABLE[index][3]/2 * SiS_DataBusWidth/32;
   /* RankSize = DRAMTYPE_TABLE[index][3]; */
-  if (ChannelNo*RankSize<=128)
-  {
+  if (ChannelNo*RankSize<=128) {
     data = 0;
-    while ((RankSize>>=1)>0)
-    {
+    while ((RankSize>>=1)>0) {
       data+=0x10;
     }
     if (ChannelNo==2)
@@ -1448,8 +1343,7 @@
     /* should delay */
     SiS_DDR_MRS();
     return 1;
-  }
-  else
+  } else
     return 0;
 }
 
@@ -1462,14 +1356,12 @@
   /*Increment = 1<<(DRAMTYPE_TABLE[index][2] + SiS_DataBusWidth / 64 + 1); */
   Increment = 1<<(10 + SiS_DataBusWidth / 64);
 
-  for (i=0,Position=0;i<2;i++)
-  {
+  for (i=0,Position=0;i<2;i++) {
          *((PULONG)(FBAddress+Position))=Position;
          Position += Increment;
   }
 
-  for (i=0,Position=0;i<2;i++)
-  {
+  for (i=0,Position=0;i<2;i++) {
 /*    if (FBAddress[Position]!=Position) */
          if ( (*(PULONG) (FBAddress + Position)) !=Position)
                 return 0;
@@ -1485,15 +1377,13 @@
   ULONG Increment,Position;
   Increment = 1<<(DRAMTYPE_TABLE[index][2] + SiS_DataBusWidth / 64 + 2);
 
-  for (i=0,Position=0;i<4;i++)
-  {
+  for (i=0,Position=0;i<4;i++) {
 /*    FBAddress[Position]=Position; */
     *((PULONG)(FBAddress+Position))=Position;
     Position += Increment;
   }
 
-  for (i=0,Position=0;i<4;i++)
-  {
+  for (i=0,Position=0;i<4;i++) {
 /*    if (FBAddress[Position]!=Position) */
     if ( (*(PULONG) (FBAddress + Position)) !=Position)
       return 0;
@@ -1510,16 +1400,14 @@
   Increment = 1<<(DRAMTYPE_TABLE[index][2] + DRAMTYPE_TABLE[index][1] +
                   DRAMTYPE_TABLE[index][0] + SiS_DataBusWidth / 64 + RankNo);
 
-  for (i=0,Position=0;i<2;i++)
-  {
+  for (i=0,Position=0;i<2;i++) {
 /*    FBAddress[Position]=Position; */
     *((PULONG)(FBAddress+Position))=Position;
     /* *((PULONG)(FBAddress))=Position; */
     Position += Increment;
   }
 
-  for (i=0,Position=0;i<2;i++)
-  {
+  for (i=0,Position=0;i<2;i++) {
 /*    if (FBAddress[Position]!=Position) */
          if ( (*(PULONG) (FBAddress + Position)) !=Position)
     /*if ( (*(PULONG) (FBAddress )) !=Position) */
@@ -1570,8 +1458,7 @@
 {
   int r;
 
-  for (r=RankNo;r>=1;r--)
-  {
+  for (r=RankNo;r>=1;r--) {
     if (!SiS_CheckRank(r,index,DRAMTYPE_TABLE,FBAddress))
       return 0;
   }
@@ -1588,8 +1475,7 @@
 {
   int r;
 
-  for (r=RankNo;r>=1;r--)
-  {
+  for (r=RankNo;r>=1;r--) {
     if (!SiS_CheckDDRRank(r,index,DRAMTYPE_TABLE,FBAddress))
       return 0;
   }
@@ -1607,16 +1493,12 @@
   int    i;
   UCHAR  j;
 
-  for (i=0;i<13;i++)
-  {
+  for (i=0;i<13;i++) {
     SiS_SetDRAMSizingType(i, SiS_SDRDRAM_TYPE);
-    for (j=2;j>0;j--)
-    {
-
+    for (j=2;j>0;j--) {
       if (!SiS_SetRank(i,(UCHAR) j, SiS_ChannelAB,SiS_SDRDRAM_TYPE))
         continue;
-      else
-      {
+      else {
         if (SiS_CheckRanks(j,i,SiS_SDRDRAM_TYPE, FBAddress))
           return 1;
       }
@@ -1632,17 +1514,14 @@
   int    i;
   UCHAR  j;
 
-  for (i=0;i<4;i++)
-  {
+  for (i=0;i<4;i++){
     SiS_SetDRAMSizingType(i,SiS_DDRDRAM_TYPE);
     SiS_DisableChannelInterleaving(i,SiS_DDRDRAM_TYPE);
-    for (j=2;j>0;j--)
-    {
+    for (j=2;j>0;j--) {
       SiS_SetDDRChannel(i, j, SiS_ChannelAB, SiS_DDRDRAM_TYPE);
       if (!SiS_SetRank(i,(UCHAR) j, SiS_ChannelAB,SiS_DDRDRAM_TYPE))
         continue;
-      else
-      {
+      else {
         if (SiS_CheckDDRRanks(j,i,SiS_DDRDRAM_TYPE, FBAddress))
           return 1;
       }
@@ -1665,10 +1544,8 @@
    pVideoMemory[0]=0xaa; /* alan */
    pVideoMemory[16]=0x55; /* note: PCI read cache is off */
 
-   if ((pVideoMemory[0]!=0xaa)||(pVideoMemory[16]!=0x55))
-   {
-     for (i=0,j=16;i<2;i++,j+=16)
-     {
+   if ((pVideoMemory[0]!=0xaa)||(pVideoMemory[16]!=0x55)) {
+     for (i=0,j=16;i<2;i++,j+=16)  {
        SR21 = SiS_GetReg1(SiS_P3c4, 0x21);
        Temp = SR21 & 0xFB;     /* disable PCI post write buffer empty gating */
        SiS_SetReg1(SiS_P3c4, 0x21, Temp);
@@ -1682,8 +1559,7 @@
        SiS_SetReg1(SiS_P3c4, 0x21, SR21);
 
        pVideoMemory[16+j] = j;
-       if (pVideoMemory[16+j]==j)
-       {
+       if (pVideoMemory[16+j]==j)  {
          pVideoMemory[j] = j;
          break;
        }
@@ -1691,6 +1567,7 @@
    }
 }
 
+/* TW: Is this a 315E? */
 int
 Is315E(void)
 {
@@ -1701,6 +1578,7 @@
    else return 0;
 }
 
+/* TW: For 315 only */
 void
 SiS_SetDRAMSize_310(PSIS_HW_DEVICE_INFO HwDeviceExtension)
 {
@@ -1709,20 +1587,16 @@
    /*USHORT  BaseAddr = (USHORT)HwDeviceExtension->ulIOAddress;*/
    USHORT  data;
 
-#ifdef SIS301	/* SIS301 ??? */
+#ifdef SIS301	/* TW: SIS301 ??? */
    /*SiS_SetReg1(SiS_P3d4,0x30,0x40);   */
 #endif
-#ifdef SIS302   /* SIS302 ??? */
+#ifdef SIS302   /* TW: SIS302 ??? */
    SiS_SetReg1(SiS_P3d4,0x30,0x4D);  /* alan,should change value */
    SiS_SetReg1(SiS_P3d4,0x31,0xc0);  /* alan,should change value */
    SiS_SetReg1(SiS_P3d4,0x34,0x3F);  /* alan,should change value */
 #endif
 
-#ifdef LINUX_XF86
-   SiSSetMode(HwDeviceExtension,NULL,0x2e);
-#else
    SiSSetMode(HwDeviceExtension,0x2e);
-#endif
 
    data=SiS_GetReg1(SiS_P3c4,0x21);
    SiS_SetReg1(SiS_P3c4,0x21,(USHORT) (data&0xDF));      /* disable read cache */
@@ -1740,30 +1614,22 @@
 
    SiS_VerifyMclk(FBAddr); /* alan 2000/7/3 */
 
-
-   if (SiS_Get310DRAMType(ROMAddr)<2)
-   {
+   if (SiS_Get310DRAMType(ROMAddr)<2) {
      SiS_SDRSizing(FBAddr);
-   }
-   else
-   {
+   } else {
      SiS_DDRSizing(FBAddr);
    }
    
-   if (Is315E())
-   {
+   if (Is315E()) {
      data=SiS_GetReg1(SiS_P3c4,0x14);
      if ((data&0x0C)==0x0C) /* dual channel */
      {
      	if ((data&0xF0)>0x40)
      	  data = (data & 0x0F) | 0x40;
-     }
-     else /* single channel */
-     {
+     } else { /* single channel */
      	if ((data&0xF0)>0x50)
      	  data = (data & 0x0F) | 0x50;
      }
-   	
    }
    
    SiS_SetReg1(SiS_P3c4,0x16,SiS_SR15[1][SiS_RAMType]);  /* restore SR16 */
@@ -1771,7 +1637,6 @@
    SiS_EnableRefresh(ROMAddr);
    data=SiS_GetReg1(SiS_P3c4,0x21);
    SiS_SetReg1(SiS_P3c4,0x21,(USHORT) (data|0x20));      /* enable read cache */
-
 }
 #endif
 
@@ -1786,8 +1651,7 @@
    SiS_SetReg1(SiS_P3c4,0x30,SiS_ECLKData[SiS_RAMType].SR30);
 
 #ifdef SIS315H
-   if (Is315E())
-   {
+   if (Is315E()) {
      SiS_SetReg1(SiS_P3c4,0x28,0x3B); /* 143 */
      SiS_SetReg1(SiS_P3c4,0x29,0x22);
      SiS_SetReg1(SiS_P3c4,0x2E,0x3B); /* 143 */
@@ -1796,7 +1660,29 @@
 #endif
 }
 
+#endif /* ifndef LINUX_XF86 */
+
+#ifdef SIS315H
+UCHAR
+SiS_Get310DRAMType(ULONG   ROMAddr)
+{
+   UCHAR   data;
+
+   /*
+   index=SiS_GetReg1(SiS_P3c4,0x1A);
+   index=index&07;
+   */
+   if (*pSiS_SoftSetting&SoftDRAMType)
+     data = *pSiS_SoftSetting & 0x03;
+   else
+     data=SiS_GetReg1(SiS_P3c4,0x3a) & 0x03;
+
+   return data;
+}
+#endif
+
 /* SiSInit END */
+
 /* ----------------------------------------- */
 
 void SiSRegInit(USHORT BaseAddr)
@@ -1817,6 +1703,7 @@
    SiS_Part3Port=BaseAddr+SIS_CRT2_PORT_12;
    SiS_Part4Port=BaseAddr+SIS_CRT2_PORT_14;
    SiS_Part5Port=BaseAddr+SIS_CRT2_PORT_14+2;
+   SiS_DDC_Port=BaseAddr+0x14;  /* 0x3c4; */
 }
 
 void
@@ -1827,18 +1714,23 @@
        (HwDeviceExtension->jChipType == SIS_630)||
        (HwDeviceExtension->jChipType == SIS_730)||
        (HwDeviceExtension->jChipType == SIS_300)) {
-       /* TW: Enable PCI adressing (0x80) & MMIO enable (0x1) & ? (0x40) */
-       SiS_SetReg1(SiS_P3c4, 0x20, 0xa1);
+       /* TW: Set - PCI LINEAR ADDRESSING ENABLE (0x80)
+		  - PCI IO ENABLE  (0x20)
+		  - MMIO ENABLE (0x1)
+  	*/
+       SiS_SetReg1(SiS_P3c4,0x20,0xa1);
        /* TW: Enable 2D (0x42) & 3D accelerator (0x18) */
-       SiS_SetReg1(SiS_P3c4, 0x1E, 0x5A);
+       SiS_SetReg1(SiS_P3c4,0x1E,0x5A);
    }
-   if((HwDeviceExtension->jChipType == SIS_315H)||  /* 05/02/01 ynlai for sis550 */
+   if((HwDeviceExtension->jChipType == SIS_315H)||
       (HwDeviceExtension->jChipType == SIS_315PRO)||
       (HwDeviceExtension->jChipType == SIS_550)||
-      (HwDeviceExtension->jChipType == SIS_640)||   /* 08/20/01 chiawen for 640/740 */
-      (HwDeviceExtension->jChipType == SIS_740)||   /* 09/03/01 chiawen for 640/740 */
+      (HwDeviceExtension->jChipType == SIS_640)||
+      (HwDeviceExtension->jChipType == SIS_740)||
       (HwDeviceExtension->jChipType == SIS_650)) {
-      /* TW: How do we do that on these chipsets? */
+      /* TW: This seems to be done the same way on these chipsets */
+      SiS_SetReg1(SiS_P3c4,0x20,0xa1);
+      SiS_SetReg1(SiS_P3c4,0x1E,0x5A);
    }
 #endif
 }
@@ -1853,7 +1745,7 @@
    SiS_IF_DEF_HiVision=0;
    SiS_IF_DEF_DSTN=0;
    SiS_IF_DEF_FSTN=0;
-   if((ModeNo==0x5a)||(ModeNo==0x5b)){
+   if((ModeNo==0x5a)||(ModeNo==0x5b)) {
    	SiS_IF_DEF_DSTN=1;   /* for 550 dstn */
    	SiS_IF_DEF_FSTN=1;   /* for fstn */
    }
@@ -1866,8 +1758,7 @@
       (HwDeviceExtension->jChipType == SIS_650))    /* 09/03/01 chiawen for 650 */
     {
       	if (SiS_IF_DEF_FSTN) {                               /*fstn setCR37=0x04;*/
-        	temp=0x04;
-        	SiS_SetReg1(SiS_P3d4,0x37,temp);
+        	SiS_SetReg1(SiS_P3d4,0x37,0x04);
       	}
       	temp=SiS_GetReg1(SiS_P3d4,0x37);
       	temp=(temp&0x0E)>>1;
@@ -1876,15 +1767,13 @@
         	SiS_IF_DEF_CH7005=0;
         	SiS_IF_DEF_TRUMPION=0;
       	}
-      	if((temp>=2)&&(temp<=5)) {
-        	SiS_IF_DEF_LVDS=1;
-      	}
+      	if((temp>=2)&&(temp<=5)) SiS_IF_DEF_LVDS=1;
       	if(temp==3) SiS_IF_DEF_TRUMPION=1;
-      	if((temp==4)||(temp==5)) SiS_IF_DEF_CH7005=1;
-   } else {
-     	SiS_IF_DEF_LVDS=0;
-     	SiS_IF_DEF_TRUMPION=0;
-     	SiS_IF_DEF_CH7005=0;
+      	if((temp==4)||(temp==5)) {
+		/* TW: Save power status */
+		SiS_Backup7005 = SiS_GetCH7005(0x0e);
+		SiS_IF_DEF_CH7005=1;
+        }
    }
 }
 
@@ -1911,9 +1800,9 @@
 }
 
 /*
- =========================================
- ======== SiS SetMode Function  ==========
- =========================================
+ 	=========================================
+ 	======== SiS SetMode Function  ==========
+ 	=========================================
 */
 #ifdef LINUX_XF86
 /* TW: This is used for non-Dual-Head mode from X */
@@ -1926,7 +1815,7 @@
    ModeNo = SiS_CalcModeIndex(pScrn, mode);
    if (!ModeNo) return FALSE;
 
-   xf86DrvMsg(0, X_PROBED, "Setting mode 0x%x\n", ModeNo);
+   xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "Setting mode 0x%x\n", ModeNo);
 
    return(SiSSetMode(HwDeviceExtension, pScrn, ModeNo));
 }
@@ -1949,7 +1838,7 @@
    ModeNo = SiS_CalcModeIndex(pScrn, mode);
    if (!ModeNo) return FALSE;
 
-   xf86DrvMsg(0, X_PROBED, "Setting mode 0x%x on CRT1\n", ModeNo);
+   xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "Setting mode 0x%x on CRT1\n", ModeNo);
 
    SiSInitPtr(HwDeviceExtension);
 
@@ -1969,16 +1858,12 @@
    temp = SiS_SearchModeID(ROMAddr,ModeNo,&ModeIdIndex);        		/* 2.Get ModeID Table  */
    if(temp==0)  return(0);
 
-   /*301b*/
+   /* TW: Determine VBType (301,301B,301LV,302B,302LV) */
    SiS_GetVBType(BaseAddr);
-   /*end 301b*/
 
    SiS_GetVBInfo301(BaseAddr,ROMAddr,ModeNo,ModeIdIndex,HwDeviceExtension);   	/*add for CRT2 */
    SiS_GetLCDResInfo301(ROMAddr,SiS_P3d4,ModeNo,ModeIdIndex);   		/*add for CRT2 */
 
-   xf86DrvMsg(0, X_PROBED, "VBFlags = %lx, LCDInfo = %d, SetFlag %x\n",
-   				SiS_VBInfo, SiS_LCDInfo, SiS_SetFlag);
-
    SiS_SetCRT1Group(ROMAddr,HwDeviceExtension,ModeNo,ModeIdIndex);
 
    pSiSEnt->CRT1ModeNo = ModeNo;
@@ -1993,34 +1878,6 @@
 				pSiSEnt->CRT2ModeNo);
 	SiSBIOSSetModeCRT2(HwDeviceExtension, pSiSEnt->pScrn_1,
 				pSiSEnt->CRT2DMode);
-#if 0
-    	if(SiS_VBInfo&(SetSimuScanMode|SwitchToCRT2|SetCRT2ToLCDA)) {	/*301b*/
-     		switch (HwDeviceExtension->ujVBChipID)
-     		{
-     		case VB_CHIP_301:
-     		case VB_CHIP_301B:    /*for Linux & WinCE to open*/
-        		SiS_SetCRT2Group301(BaseAddr,ROMAddr,pSiSEnt->CRT2ModeNo,
-					HwDeviceExtension);      /*add for CRT2 */
-        		break;
-     		case VB_CHIP_302:
-        		SiS_SetCRT2Group301(BaseAddr,ROMAddr,pSiSEnt->CRT2ModeNo,
-					HwDeviceExtension);
-        		break;
-     		case VB_CHIP_303:
-			/*  SetCRT2Group302(BaseAddr,ROMAddr,pSiSEnt->CRT2ModeNo,
-					HwDeviceExtension);                add for CRT2   */
-        		break;
-     		case VB_CHIP_UNKNOWN:                                                                                                 /*add for lvds ch7005*/
-        		temp=SiS_GetReg1(SiS_P3d4,0x37);
-        		if(temp&(ExtChipLVDS|ExtChipTrumpion|ExtChipCH7005)){
-             			SiS_SetCRT2Group301(BaseAddr,ROMAddr,pSiSEnt->CRT2ModeNo,
-						HwDeviceExtension);
-        		}
-        		break;
-     		}
-   	}
-	SiS_SetPitchCRT2(pSiSEnt->pScrn_1, BaseAddr);
-#endif
    }
 
    /* Backup/Set ModeNo in MMIO */
@@ -2079,30 +1936,22 @@
    temp = SiS_SearchModeID(ROMAddr,ModeNo,&ModeIdIndex);        		/* 2.Get ModeID Table  */
    if(temp==0)  return(0);
 
-   /*301b*/
+   /* TW: Determine VBType (301,301B,301LV,302B,302LV) */
    SiS_GetVBType(BaseAddr);
-   /*end 301b*/
 
    SiS_GetVBInfo301(BaseAddr,ROMAddr,ModeNo,ModeIdIndex,HwDeviceExtension);   	/*add for CRT2 */
    SiS_GetLCDResInfo301(ROMAddr,SiS_P3d4,ModeNo,ModeIdIndex);   		/*add for CRT2 */
 
-#if 0
-   xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "VBFlags = %lx, LCDInfo = %d, SetFlag %x\n",
-   				SiS_VBInfo, SiS_LCDInfo, SiS_SetFlag);
-#endif
-
-   if(SiS_VBInfo&(SetSimuScanMode|SwitchToCRT2|SetCRT2ToLCDA)) {	/*301b*/
-     switch (HwDeviceExtension->ujVBChipID)
-     {
+   switch (HwDeviceExtension->ujVBChipID) {
      case VB_CHIP_301:
      case VB_CHIP_301B:    /*for Linux & WinCE to open*/
-        SiS_SetCRT2Group301(BaseAddr,ROMAddr,ModeNo,HwDeviceExtension);                     /*add for CRT2 */
+        SiS_SetCRT2Group301(BaseAddr,ROMAddr,ModeNo,HwDeviceExtension);         /*add for CRT2 */
         break;
      case VB_CHIP_302:
         SiS_SetCRT2Group301(BaseAddr,ROMAddr,ModeNo,HwDeviceExtension);
         break;
      case VB_CHIP_303:
-/*      SetCRT2Group302(BaseAddr,ROMAddr,ModeNo, HwDeviceExtension);                       add for CRT2   */
+/*      SetCRT2Group302(BaseAddr,ROMAddr,ModeNo, HwDeviceExtension);            add for CRT2   */
         break;
      case VB_CHIP_UNKNOWN:                                                                                                 /*add for lvds ch7005*/
         temp=SiS_GetReg1(SiS_P3d4,0x37);
@@ -2110,7 +1959,6 @@
              	SiS_SetCRT2Group301(BaseAddr,ROMAddr,ModeNo,HwDeviceExtension);
         }
         break;
-     }
    }
 
    /* TW: SetPitch: Adapt to virtual size & position */
@@ -2127,7 +1975,6 @@
 #endif /* Dualhead */
 #endif /* Linux_XF86 */
 
-
 #ifdef LINUX_XF86
 /* TW: We need pScrn for setting the pitch correctly */
 BOOLEAN
@@ -2169,18 +2016,12 @@
    temp = SiS_SearchModeID(ROMAddr,ModeNo,&ModeIdIndex);        		/* 2.Get ModeID Table  */
    if(temp==0)  return(0);
 
-   /*301b*/
+   /* TW: Determine VBType (301,301B,301LV,302B,302LV) */
    SiS_GetVBType(BaseAddr);
-   /*end 301b*/
 
    SiS_GetVBInfo301(BaseAddr,ROMAddr,ModeNo,ModeIdIndex,HwDeviceExtension);   	/*add for CRT2 */
    SiS_GetLCDResInfo301(ROMAddr,SiS_P3d4,ModeNo,ModeIdIndex);   		/*add for CRT2 */
 
-#ifdef LINUX_XF86
-   xf86DrvMsg(0, X_PROBED, "VBFlags = %lx, LCDInfo = %d, SetFlag %x\n",
-   				SiS_VBInfo, SiS_LCDInfo, SiS_SetFlag);
-#endif
-
    temp=SiS_CheckMemorySize(ROMAddr,HwDeviceExtension,ModeNo,ModeIdIndex);    	/*3.Check memory size */
    if(temp==0) return(0);
    if(SiS_VBInfo&(SetSimuScanMode|SetCRT2ToLCDA)) {				/*301b*/
@@ -2191,18 +2032,17 @@
      }
    }
 
-   if(SiS_VBInfo&(SetSimuScanMode|SwitchToCRT2|SetCRT2ToLCDA)) {	/*301b*/
-     switch (HwDeviceExtension->ujVBChipID)
-     {
+   if(SiS_VBInfo&(SetSimuScanMode|SwitchToCRT2|SetCRT2ToLCDA)) {		/*301b*/
+     switch (HwDeviceExtension->ujVBChipID) {
      case VB_CHIP_301:
      case VB_CHIP_301B:    /*for Linux & WinCE to open*/
-        SiS_SetCRT2Group301(BaseAddr,ROMAddr,ModeNo,HwDeviceExtension);                     /*add for CRT2 */
+        SiS_SetCRT2Group301(BaseAddr,ROMAddr,ModeNo,HwDeviceExtension);        /*add for CRT2 */
         break;
      case VB_CHIP_302:
         SiS_SetCRT2Group301(BaseAddr,ROMAddr,ModeNo,HwDeviceExtension);
         break;
      case VB_CHIP_303:
-/*      SetCRT2Group302(BaseAddr,ROMAddr,ModeNo, HwDeviceExtension);                       add for CRT2   */
+/*      SetCRT2Group302(BaseAddr,ROMAddr,ModeNo, HwDeviceExtension);             add for CRT2   */
         break;
      case VB_CHIP_UNKNOWN:                                                                                                 /*add for lvds ch7005*/
         temp=SiS_GetReg1(SiS_P3d4,0x37);
@@ -2220,14 +2060,16 @@
    SiS_GetSetModeID(pScrn,ModeNo);
 #endif
 
-   if(KeepLockReg==0xA1) SiS_SetReg1(SiS_P3c4,0x05,0x86); /* 05/02/01 ynlai */
+#ifndef LINUX_XF86  /* TW: We never lock registers in XF86 */
+   if(KeepLockReg==0xA1) SiS_SetReg1(SiS_P3c4,0x05,0x86);
    else SiS_SetReg1(SiS_P3c4,0x05,0x00);
+#endif
 
    return TRUE;
 }
 
 void
-SetEnableDstn()
+SetEnableDstn()		/* TW: Called from sis_main.c */
 {
    SiS_IF_DEF_DSTN=1;   /*for 550 dstn*/
 }
@@ -2241,7 +2083,7 @@
 
   /*SiS_SetReg1(SiS_P3d4,0x34,ModeNo);*/
   SiS_CRT1Mode = ModeNo;
-  /* set CR34->CRT1 ModeNofor CRT2 FIFO */
+  /* set CR34->CRT1 ModeNo for CRT2 FIFO */
   StandTableIndex = SiS_GetModePtr(ROMAddr,ModeNo,ModeIdIndex); /* 4.GetModePtr  */
   SiS_SetSeqRegs(ROMAddr,StandTableIndex);                      /* 5.SetSeqRegs  */
   SiS_SetMiscRegs(ROMAddr,StandTableIndex);                     /* 6.SetMiscRegs */
@@ -2252,23 +2094,27 @@
   temp=~ProgrammingCRT2;                                        /* 11.GetRatePtr  */
   SiS_SetFlag=SiS_SetFlag&temp;
   SiS_SelectCRT2Rate=0;
+
+#ifdef LINUX_XF86
+  xf86DrvMsg(0, X_INFO, "VBType = %x, LVDS=%d, VBInfo=%x\n",
+                    SiS_VBType, SiS_IF_DEF_LVDS, SiS_VBInfo);
+#endif
+
   /*301b*/
   if( (SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV))) {
       if(SiS_VBInfo&SetCRT2ToLCDA) {
-	 	SiS_SetFlag=SiS_SetFlag|ProgrammingCRT2;
+	 SiS_SetFlag=SiS_SetFlag|ProgrammingCRT2;
       }
   }
   /*end 301b*/
 
   RefreshRateTableIndex=SiS_GetRatePtrCRT2(ROMAddr,ModeNo,ModeIdIndex);   /* 11.GetRatePtr */
 
-  /*301b*/
   if( (SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV))) {
       if(!(SiS_VBInfo&SetCRT2ToLCDA)) {
 	 SiS_SetFlag=SiS_SetFlag&(~ProgrammingCRT2);
       }
   }
-  /*end 301b*/
 
   if (RefreshRateTableIndex!=0xFFFF) {
     SiS_SetSync(ROMAddr,RefreshRateTableIndex);                          /* 12.SetSync */
@@ -2323,12 +2169,8 @@
 {
     SISPtr pSiS = SISPTR(pScrn);
     ULong  HDisplay,temp;
-    /* UShort al,ah; */
 
     HDisplay = pSiS->scrnOffset / 8;
-
-    /* xf86DrvMsg(0, X_PROBED, "SetPitchCRT1: scrnoffset = %x\n", pSiS->scrnOffset); */
-
     SiS_SetReg1(SiS_P3d4, 0x13, (HDisplay & 0xFF));
     temp = (SiS_GetReg1(SiS_P3c4, 0x0E) & 0xF0) | (HDisplay>>8);
     SiS_SetReg1(SiS_P3c4, 0x0E, temp);
@@ -2339,12 +2181,8 @@
 {
     SISPtr pSiS = SISPTR(pScrn);
     ULong  HDisplay,temp;
-    /* UShort al,ah; */
 
     HDisplay = pSiS->scrnOffset / 8;
-
-    /* xf86DrvMsg(0, X_PROBED, "SetPitchCRT2: scrnoffset = %x\n", pSiS->scrnOffset); */
-
     SiS_SetReg1(SiS_Part1Port, 0x24, 1);
     SiS_SetReg1(SiS_Part1Port, 0x07, HDisplay);
     temp = (SiS_GetReg1(SiS_Part1Port, 0x09) & 0xF0) | (HDisplay>>8);
@@ -2359,10 +2197,7 @@
 
   flag=SiS_GetReg1(SiS_Part4Port,0x00);
   /* TW: On pure LVDS, Part4 is not assigned and returns 0xff */
-#ifdef LINUX_KERNEL
-  printk(KERN_INFO "VBType: Part4Port 0: %d\n", flag);
-#endif
-  if (flag == 0xff) return;
+  if (flag >= 4) return;
   /* TW end */
   if (flag >= 2) {
   	flag=SiS_GetReg1(SiS_Part4Port,0x01);
@@ -2466,61 +2301,44 @@
 #endif
   return ((BOOLEAN)ModeIdIndex);
 }
+/*end oem util */
 
-/*end*/
-
-/* win2000 MM adapter not support standard mode!  */
 BOOLEAN
 SiS_CheckMemorySize(ULONG ROMAddr,PSIS_HW_DEVICE_INFO HwDeviceExtension,
                     USHORT ModeNo,USHORT ModeIdIndex)
 {
-  USHORT memorysize;
-  USHORT modeflag;
-  USHORT temp;
+  USHORT memorysize,modeflag,temp;
 
   if((HwDeviceExtension->jChipType == SIS_550)||   /* 05/02/01 ynlai for sis550 */
      (HwDeviceExtension->jChipType == SIS_640)||   /* 08/20/01 chiawen for 640/740 */
      (HwDeviceExtension->jChipType == SIS_740)||   /* 09/03/01 chiawen for 640/740 */
      (HwDeviceExtension->jChipType == SIS_650))    /* 09/03/01 chiawen for 650 */
-  {
     return(TRUE);
-  }
 
   if (ModeNo<=0x13) {
     modeflag = SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
-  }
-  else  {
+  } else {
     modeflag = SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
   }
 
-/*  ModeType=modeflag&ModeInfoFlag;                           Get mode type  */
+/*  ModeType=modeflag&ModeInfoFlag;                           	   Get mode type  */
 
   memorysize=modeflag&MemoryInfoFlag;
   memorysize=memorysize>MemorySizeShift;
-  memorysize++;                                        /* Get memory size */
+  memorysize++;                                        		/* Get memory size */
 
-  temp=SiS_GetReg1(SiS_P3c4,0x14);                             /* Get DRAM Size    */
+  temp=SiS_GetReg1(SiS_P3c4,0x14);                             	/* Get DRAM Size    */
   if((HwDeviceExtension->jChipType == SIS_315H)||
-     (HwDeviceExtension->jChipType == SIS_315PRO))
-  {
-    temp=1 << ((temp&0x0F0)>>4);
-    if ((temp&0x0c)==0x08) /* DDR asymetric */
-    {
+     (HwDeviceExtension->jChipType == SIS_315PRO)) {
+    temp= 1 << ((temp&0x0F0)>>4);				/* 315 */
+    if ((temp&0x0c)==0x08) { /* DDR asymetric */
       temp += temp/2;
+    } else {
+      if ((temp&0x0c)!=0) temp <<= 1;
     }
-    else
-    {
-      if ((temp&0x0c)!=0)
-      {
-        temp <<= 1;
-      }
-    }
-  }  
-  else /* 300, 540 , 630 */
-  {
+  } else { 							/* 300, 540, 630, 730 */
     temp=temp&0x3F;
     temp++;
-  /*  temp=1 << ((temp&0x0F0)>>4);*/
   }
 
   if(temp<memorysize) return(FALSE);
@@ -2534,8 +2352,7 @@
 
    if(ModeNo<=0x13) {
      	index = SiS_SModeIDTable[ModeIdIndex].St_StTableIndex;
-   }
-   else {
+   } else {
      	if(SiS_ModeType <= 0x02) index=0x1B;    /* 02 -> ModeEGA  */
      	else index=0x0F;
    }
@@ -2550,13 +2367,12 @@
 
    SiS_SetReg1(SiS_P3c4,0x00,0x03);           /* Set SR0  */
    SRdata=SiS_StandTable[StandTableIndex].SR[0];
-   /*301b*/
+
    if(SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV)) {
       	if(SiS_VBInfo&SetCRT2ToLCDA) {
         	SRdata=SRdata|0x01;
         }
    }
-   /*end 301b*/
 
    if(SiS_IF_DEF_LVDS==1) {
      if(SiS_IF_DEF_CH7005==1) {
@@ -2587,13 +2403,11 @@
    UCHAR Miscdata;
 
    Miscdata = SiS_StandTable[StandTableIndex].MISC;    /* Get Misc from file */
-   /*301b*/
    if( (SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV))) {
       if(SiS_VBInfo&SetCRT2ToLCDA) {
         Miscdata=Miscdata|0x0C;
       }
     }
-   /*end 301b*/
    SiS_SetReg3(SiS_P3c2,Miscdata);                         /* Set Misc(3c2) */
 }
 
@@ -2608,13 +2422,12 @@
   CRTCdata=CRTCdata&0x7f;
   SiS_SetReg1(SiS_P3d4,0x11,CRTCdata);                     /* Unlock CRTC */
 
-  for(i=0;i<=0x18;i++)
-  {
-     CRTCdata=SiS_StandTable[StandTableIndex].CRTC[i]; /* Get CRTC from file */
+  for(i=0;i<=0x18;i++) {
+     CRTCdata=SiS_StandTable[StandTableIndex].CRTC[i];     /* Get CRTC from file */
      SiS_SetReg1(SiS_P3d4,i,CRTCdata);                     /* Set CRTC(3d4) */
   }
   if((HwDeviceExtension->jChipType==SIS_630)&&
-     (HwDeviceExtension->jChipRevision==0x30)) {       /* for 630S0 */
+     (HwDeviceExtension->jChipRevision==0x30)) {           /* for 630S0 */
     if(SiS_VBInfo&SetInSlaveMode) {
       if(SiS_VBInfo&(SetCRT2ToLCD|SetCRT2ToTV)) {
         SiS_SetReg1(SiS_P3d4,0x18,0xFE);
@@ -2630,32 +2443,24 @@
    USHORT i;
 
    for(i=0;i<=0x13;i++) {
-     ARdata = SiS_StandTable[StandTableIndex].ATTR[i];     /* Get AR for file  */
-    /*301b*/ /* TW: added LVDS check */
+    ARdata = SiS_StandTable[StandTableIndex].ATTR[i];     /* Get AR for file  */
     if(SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV)) {
-      if(SiS_VBInfo&SetCRT2ToLCDA){
-         if(i==0x13) {
-               ARdata=0;
-             }
-        }
+      if(SiS_VBInfo&SetCRT2ToLCDA) {
+         if(i==0x13) ARdata=0;
+      }
     }
-    /*end 301b*/
-     if (SiS_IF_DEF_LVDS==1) {                             /*for LVDS  */
+    if (SiS_IF_DEF_LVDS==1) {                             /*for LVDS  */
        if(SiS_IF_DEF_CH7005==1) {
          if(SiS_VBInfo&SetCRT2ToTV) {
            if(SiS_VBInfo&SetInSlaveMode) {
-             if(i==0x13) {
-               ARdata=0;
-             }
+             if(i==0x13) ARdata=0;
            }
          }
        }
        if(SiS_VBInfo&SetCRT2ToLCD) {
          if(SiS_VBInfo&SetInSlaveMode) {
            if(SiS_LCDInfo&LCDNonExpanding) {
-             if(i==0x13) {
-               ARdata=0;
-             }
+             if(i==0x13) ARdata=0;
            }
          }
        }
@@ -2679,13 +2484,13 @@
    USHORT i;
 
    for(i=0;i<=0x08;i++) {
-     GRdata = SiS_StandTable[StandTableIndex].GRC[i]; /* Get GR from file */
+     GRdata = SiS_StandTable[StandTableIndex].GRC[i]; 	  /* Get GR from file */
      SiS_SetReg1(SiS_P3ce,i,GRdata);                      /* Set GR(3ce) */
    }
 
    if(SiS_ModeType>ModeVGA) {
      GRdata=(UCHAR)SiS_GetReg1(SiS_P3ce,0x05);
-     GRdata=GRdata&0xBF;                          /* 256 color disable */
+     GRdata=GRdata&0xBF;                                  /* 256 color disable */
      SiS_SetReg1(SiS_P3ce,0x05,GRdata);
    }
 }
@@ -2723,12 +2528,11 @@
   SiS_LCDACRT1DataStruct *LCDACRT1Ptr=NULL;
 
   if((SiS_VBType&VB_SIS302B)&&(SiS_VBInfo&SetCRT2ToLCDA)
-  	&& (SiS_IF_DEF_LVDS==0) ) {
-    /*add crt1ptr*/
+  	&& (SiS_IF_DEF_LVDS==0) ) { /* TW: Added LVDS check */
+     /*add crt1ptr*/
      if(ModeNo<=0x13) {
        modeflag = SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;      /* si+St_ResInfo */
-     }
-     else {
+     } else {
        modeflag = SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;     /* si+Ext_ResInfo */
      }
      temp= SiS_GetLCDACRT1Ptr(ROMAddr,ModeNo,ModeIdIndex,RefreshRateTableIndex,
@@ -2747,7 +2551,7 @@
       case 9 : LCDACRT1Ptr = SiS_LCDACRT1800x600_2_H;         break;
       case 10: LCDACRT1Ptr = SiS_LCDACRT11024x768_2_H;        break;
       case 11: LCDACRT1Ptr = SiS_LCDACRT11280x1024_2_H;       break;
-      /*case 12: LCDACRT1Ptr = SiS_CHTVCRT1UNTSC;               break;
+      /*case 12: LCDACRT1Ptr = SiS_CHTVCRT1UNTSC;             break;
       case 13: LCDACRT1Ptr = SiS_CHTVCRT1ONTSC;               break;
       case 14: LCDACRT1Ptr = SiS_CHTVCRT1UPAL;                break;
       case 15: LCDACRT1Ptr = SiS_CHTVCRT1OPAL;                break;*/
@@ -2762,10 +2566,10 @@
        tempah = (LCDACRT1Ptr+ResInfo)->CR[j];
        SiS_SetReg1(SiS_P3d4,i,tempah);
      }
-/* for(i=0x06,j=5;i<=0x07;i++,j++){
-   tempah = (LCDACRT1Ptr+ResInfo)->CR[j];
-    SiS_SetReg1(SiS_P3d4,i,tempah);
-  }*/
+     /* for(i=0x06,j=5;i<=0x07;i++,j++){
+       tempah = (LCDACRT1Ptr+ResInfo)->CR[j];
+       SiS_SetReg1(SiS_P3d4,i,tempah);
+     }*/
      for(i=0x10,j=8;i<=0x12;i++,j++){
        tempah = (LCDACRT1Ptr+ResInfo)->CR[j];
        SiS_SetReg1(SiS_P3d4,i,tempah);
@@ -2774,7 +2578,6 @@
        tempah =(LCDACRT1Ptr+ResInfo)->CR[j];
        SiS_SetReg1(SiS_P3d4,i,tempah);
      }
-
      for(i=0x0A,j=13;i<=0x0C;i++,j++){
        tempah = (LCDACRT1Ptr+ResInfo)->CR[j];
        SiS_SetReg1(SiS_P3c4,i,tempah);
@@ -2794,24 +2597,22 @@
      if(SiS_ModeType>0x03) SiS_SetReg1(SiS_P3d4,0x14,0x4F);
   /*end 301b*/
   }
-  else{  /* LVDS */
-     index=SiS_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;  /* Get index */
-     index= index&0x3F;
-       /*fstn*/
-     if(SiS_IF_DEF_FSTN){
-        index= index&0x7F;	/* TW: ??? */
+  else {  /* LVDS */
+     index=SiS_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;  		/* Get index */
+     index=index&0x3F;
+
+     if(SiS_IF_DEF_FSTN) {						/*fstn*/
+        index=index&0x7F;	/* TW: First AND it with 3F, now with 7F ??? */
      }
      data=(UCHAR)SiS_GetReg1(SiS_P3d4,0x11);
      data=data&0x7F;
-     SiS_SetReg1(SiS_P3d4,0x11,data);                             /* Unlock CRTC */
+     SiS_SetReg1(SiS_P3d4,0x11,data);                             	/* Unlock CRTC */
 
-     for(i=0,j=0;i<=07;i++,j++)
-     {
+     for(i=0,j=0;i<=07;i++,j++) {
        data=SiS_CRT1Table[index].CR[i];
        SiS_SetReg1(SiS_P3d4,j,data);
      }
-     for(j=0x10;i<=10;i++,j++)
-     {
+     for(j=0x10;i<=10;i++,j++) {
        data=SiS_CRT1Table[index].CR[i];
        SiS_SetReg1(SiS_P3d4,j,data);
      }
@@ -2819,8 +2620,7 @@
        data=SiS_CRT1Table[index].CR[i];
        SiS_SetReg1(SiS_P3d4,j,data);
      }
-     for(j=0x0A;i<=15;i++,j++)
-     {
+     for(j=0x0A;i<=15;i++,j++) {
        data=SiS_CRT1Table[index].CR[i];
        SiS_SetReg1(SiS_P3c4,j,data);
      }
@@ -2863,8 +2663,7 @@
    temp = SiS_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
    if(HwDeviceExtension->jChipType >= SIS_315H) {
      temp=temp>>8;         /* sis310 */
-   }
-   else {
+   } else {
      temp=temp>>4;         /* sis300 */
    }
    temp=SiS_ScreenOffset[temp];
@@ -2930,7 +2729,7 @@
    *     This functions could make one believe that LVDS is 0 for these. But
    *     in this case SetGroup1_LVDS doesn't make sense (see init301.c)
    *     So my conclusion is that LVDS = 1 for some of the SiS bridges as
-   *     well, i just don't know which one...
+   *     well, i just don't know which ones...
    */
 
   if(SiS_IF_DEF_LVDS==1) {
@@ -2938,34 +2737,35 @@
         /* TW: Do this if IF_DEF_LVDS is 1 */
 
     	index = SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
+
     	/*if(HwDeviceExtension->jChipType < SIS_315H) { */
     	index=index&0x3F;
     	/*}*/
-    	data = SiS_GetReg1(SiS_P3c4,0x31);
-	data &= 0xCF;
+    	data = SiS_GetReg1(SiS_P3c4,0x31) & 0xCF;
 	SiS_SetReg1(SiS_P3c4,0x31,data);
 	/* SiS_SetReg1(SiS_P3c4,0x31,0x00); 	     */                 /* for300 */
 
     	SiS_SetReg1(SiS_P3c4,0x2B,SiS_VCLKData[index].SR2B);
     	SiS_SetReg1(SiS_P3c4,0x2C,SiS_VCLKData[index].SR2C);
+	
     	if(HwDeviceExtension->jChipType < SIS_315H)
       		SiS_SetReg1(SiS_P3c4,0x2D,0x80);                        /* for300 series */
-   	 else
+   	else
       		SiS_SetReg1(SiS_P3c4,0x2D,0x01);                        /* for310 series */
   }
 
   else if( (SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV))
-               && (SiS_VBInfo&SetCRT2ToLCDA) ){
+               && (SiS_VBInfo&SetCRT2ToLCDA)
+	       && (SiS_IF_DEF_LVDS==0) ){  /* TW: I did NOT include this here */
 
         /* TW: Do this if bridge type is 301B/302B/301LV/302LV
-	 *     This can only be called if LVDS is 0... 
+	 *     (This can only be called if LVDS is 0...)
 	 */
 	 
     	vclkindex = SiS_GetVCLK2Ptr(ROMAddr,ModeNo,ModeIdIndex,
 	                     RefreshRateTableIndex,HwDeviceExtension);
     	data = SiS_GetReg1(SiS_P3c4,0x31) & 0xCF;
     	SiS_SetReg1(SiS_P3c4,0x31,data);
-    	/*SiS_SetReg1(SiS_P3c4,0x31,0x00); */                       	/* for300 */
 
     	data = SiS_VBVCLKData[vclkindex].Part4_A;
     	SiS_SetReg1(SiS_P3c4,0x2B,data);
@@ -2981,6 +2781,7 @@
 
 	/* TW: Do this if LVDS is 0 and the brigde type is NOT
 	 *     301B/302B/301LV/302LV. This leaves only 301...
+	 *     (or 301B/.. if not LCDA)
 	 */
 
     	index = SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
@@ -3038,7 +2839,7 @@
     	modeflag = SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;    /* si+St_ModeFlag */
   }
 
-  SiS_SetRegANDOR(SiS_P3c4,0x1F,0x3F,0x00);
+  SiS_SetRegANDOR(SiS_P3c4,0x1F,0x3F,0x00); 	/* DAC pedestal */
 
   if(ModeNo>0x13) data=infoflag;
   else data=0;
@@ -3059,11 +2860,10 @@
      (HwDeviceExtension->jChipType==SIS_540)||
      (HwDeviceExtension->jChipType==SIS_730)) {
     resindex=SiS_GetResInfo(ROMAddr,ModeNo,ModeIdIndex);
-    if(ModeNo<=0x13){
+    if(ModeNo<=0x13)
       	xres=SiS_StResInfo[resindex].HTotal;
-    }else{
+    else
       	xres=SiS_ModeResInfo[resindex].HTotal;                         /* xres->ax */
-    }
     data=0x0000;
     if(infoflag&InterlaceMode) {
       if(xres==1024) data=0x0035;
@@ -3082,13 +2882,16 @@
   if((HwDeviceExtension->jChipType==SIS_630)||
      (HwDeviceExtension->jChipType==SIS_540)||
      (HwDeviceExtension->jChipType==SIS_730)){
-     /* TW: Nothing */
-  }
-  else {
+     /* TW: This was missing here for modes > 1024x768: */
     if(modeflag&LineCompareOff) {
       SiS_SetRegANDOR(SiS_P3c4,0x0F,0xF7,0x08);
+    } else {
+      SiS_SetRegANDOR(SiS_P3c4,0x0F,0xF7,0x00);
     }
-    else {
+  } else {
+    if(modeflag&LineCompareOff) {
+      SiS_SetRegANDOR(SiS_P3c4,0x0F,0xF7,0x08);
+    } else {
       SiS_SetRegANDOR(SiS_P3c4,0x0F,0xF7,0x00);
     }
   }
@@ -3112,37 +2915,31 @@
    UCHAR  index=0;
 
   if (ModeNo<=0x13) VCLK=0;
-  else
-  {
+  else {
     index = SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
     /*if(HwDeviceExtension->jChipType < SIS_315H) { */
     index=index&0x3F;
     /*}*/
     VCLK = SiS_VCLKData[index].CLOCK;
   }
-#ifdef LINUX_KERNEL
-  printk(KERN_INFO "sisfb: VCLK %d (index %d)\n", VCLK, index);
-#endif
-  if(HwDeviceExtension->jChipType < SIS_315H)
-  {
+
+  if(HwDeviceExtension->jChipType < SIS_315H) {
     data2=0x00;
     if(VCLK>150) data2=data2|0x80;
-    SiS_SetRegANDOR(SiS_P3c4,0x07,0x7B,data2);
+    SiS_SetRegANDOR(SiS_P3c4,0x07,0x7B,data2); 	/* DAC speed */
 
     data2=0x00;
-    if(VCLK>=150) data2=data2|0x08;       /* VCLK > 150 */
+    if(VCLK>=150) data2=data2|0x08;       	/* VCLK > 150 */
     SiS_SetRegANDOR(SiS_P3c4,0x32,0xF7,data2);
-  }
-  else  /* 310 series */
-  {
-   data=SiS_GetReg1(SiS_P3c4,0x32);
-   data=data&0xf3;
-   if(VCLK>=200) data=data|0x0c;  /* VCLK > 200 */
-   SiS_SetReg1(SiS_P3c4,0x32,data);
-   data=SiS_GetReg1(SiS_P3c4,0x1F);
-   data &= 0xE7;
-   if(VCLK<200) data |= 0x10;
-   SiS_SetReg1(SiS_P3c4,0x1F,data);
+  } else { /* 310 series */
+    data=SiS_GetReg1(SiS_P3c4,0x32);
+    data=data&0xf3;
+    if(VCLK>=200) data=data|0x0c;         	/* VCLK > 200 */
+    SiS_SetReg1(SiS_P3c4,0x32,data);
+    data=SiS_GetReg1(SiS_P3c4,0x1F);	  	/* DAC pedestal */
+    data &= 0xE7;
+    if(VCLK<200) data |= 0x10;
+    SiS_SetReg1(SiS_P3c4,0x1F,data);	  	/* DAC pedestal */
   }
 
   if(VCLK<135) data2=0x03;
@@ -3153,7 +2950,7 @@
   if(HwDeviceExtension->jChipType==SIS_540) {
     	if((VCLK==203)||(VCLK<234)) data2=0x02;
   }
-  SiS_SetRegANDOR(SiS_P3c4,0x07,0xFC,data2);
+  SiS_SetRegANDOR(SiS_P3c4,0x07,0xFC,data2);  	/* DAC speed */
 }
 
 void
@@ -3166,8 +2963,10 @@
    USHORT al,ah,dh;
    USHORT *table=NULL;
 
-   if (ModeNo<=0x13) data = SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
-   else data = SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
+   if (ModeNo<=0x13)
+        data = SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
+   else
+        data = SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
 
    data=data&DACInfoFlag;
    time=64;
@@ -3244,8 +3043,7 @@
        temp=bl;
        bl=dh;
        dh=temp;
-    }
-    else {
+    } else {
        temp=bl;
        bl=bh;
        bh=temp;
@@ -3267,7 +3065,7 @@
 #ifdef SIS315H
   if ((HwDeviceExtension->jChipType == SIS_315H)||
       (HwDeviceExtension->jChipType == SIS_315PRO)) {
-    	counter = SiS_GetReg1(SiS_P3c4,0x14)&0xF0; /*get memory size*/
+    	counter = SiS_GetReg1(SiS_P3c4,0x14)&0xF0; 	/*get memory size*/
     	counter >>= 4;
     	AdapterMemorySize= 1 << counter;
     	AdapterMemorySize *= 1024*1024;
@@ -3280,6 +3078,12 @@
       		counter++;
       		AdapterMemorySize = counter * 4;
       		AdapterMemorySize *= 1024*1024;
+		/* TW: FIXME: Some 550 BIOSes don't set up SR14 correctly. We
+		 * will have to read PCI configuration for a correct memory
+		 * size. (However, this is checked in framebuffer driver;
+		 * X does not use this function but if it ever will, this will
+		 * become an issue.)
+		 */
     	}
   }
 #endif
@@ -3307,30 +3111,21 @@
   PUSHORT pBuffer;
   int i;
 
-  if (SiS_ModeType>=ModeEGA)
-  {
-    if (ModeNo>0x13)
-    {
+  if (SiS_ModeType>=ModeEGA) {
+    if (ModeNo>0x13) {
       AdapterMemorySize=GetDRAMSize(HwDeviceExtension);
       SiS_SetMemory(VideoMemoryAddress,AdapterMemorySize,0);
-    }
-    else
-    {
+    } else {
       pBuffer = VideoMemoryAddress;
       for (i=0;i<0x4000;i++)
         pBuffer[i]=0x0000;
     }
-  }
-  else
-  {
+  } else {
     pBuffer = VideoMemoryAddress;
-    if (SiS_ModeType<ModeCGA)
-    {
+    if (SiS_ModeType<ModeCGA) {
       for (i=0;i<0x4000;i++)
         pBuffer[i]=0x0720;
-    }
-    else
-    {
+    } else {
       SiS_SetMemory(VideoMemoryAddress,0x8000,0);
     }
   }
@@ -3537,11 +3332,9 @@
 {
    int i;
 
-
    OutPortByte(port, 0);
    port++;
-   for (i=0;i<256*3;i++)
-   {
+   for (i=0;i<256*3;i++) {
       OutPortByte(port, 0);
    }
 
@@ -3587,8 +3380,7 @@
   data=SiS_GetReg1(SiS_P3c4,0x3D);
   data &= 0xfe;
   SiS_SetReg1(SiS_P3c4,0x3D,data);  /* diable auto-threshold */
-  if (ModeNo>0x13)
-  {
+  if (ModeNo>0x13) {
     SiS_SetReg1(SiS_P3c4,0x08,0x34);
     data=SiS_GetReg1(SiS_P3c4,0x09);
     data &= 0xF0;
@@ -3597,9 +3389,7 @@
     data=SiS_GetReg1(SiS_P3c4,0x3D);
     data |= 0x01;
     SiS_SetReg1(SiS_P3c4,0x3D,data);
-  }
-  else
-  {
+  } else {
     SiS_SetReg1(SiS_P3c4,0x08,0xAE);
     data=SiS_GetReg1(SiS_P3c4,0x09);
     data &= 0xF0;
@@ -3628,8 +3418,7 @@
   if(key==0) {
     temp0=(USHORT)ThLowA[data];
     temp1=(USHORT)ThLowA[data+1];
-  }
-  else {
+  } else {
     temp0=(USHORT)ThLowB[data];
     temp1=(USHORT)ThLowB[data+1];
   }
@@ -3649,54 +3438,53 @@
                  USHORT RefreshRateTableIndex)
 {
   USHORT  i,index,data,VCLK,data2,MCLK,colorth=0;
-  USHORT  ah,bl,B;
-  ULONG   eax;
+  ULONG   B,eax,ah,bl;
   USHORT  ThresholdLow=0;
-  UCHAR   FQBQData[]= { 0x01,0x21,0x41,0x61,0x81,
+  UCHAR   FQBQData[]= { 0x01,0x21,0x41,0x61,0x81,  /* TW: in BIOS at 0xf85 - identical */
                         0x31,0x51,0x71,0x91,0xb1,
                         0x00,0x20,0x40,0x60,0x80,
                         0x30,0x50,0x70,0x90,0xb0,0xFF};
 
   if(ModeNo>=0x13) {
     index=SiS_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
-    if(HwDeviceExtension->jChipType < SIS_315H) { /* for300 serial*/
+    if(HwDeviceExtension->jChipType < SIS_315H) { /* for300 series */
       index=index&0x3F;
     }
     VCLK=SiS_VCLKData[index].CLOCK;           /* Get VCLK  */
     index=SiS_GetReg1(SiS_P3c4,0x1A);
     index=index&07;
     MCLK=SiS_MCLKData[index].CLOCK;           /* Get MCLK  */
+
     data2=SiS_ModeType-0x02;
       switch (data2) {
-        case 0 : colorth=1; break;
-        case 1 : colorth=2; break;
-        case 2 : colorth=4; break;
-        case 3 : colorth=4; break;
-        case 4 : colorth=6; break;
-        case 5 : colorth=8; break;
+        case 0 : colorth=1; break;  /* 1 */
+        case 1 : colorth=1; break;  /* 2 */
+        case 2 : colorth=2; break;  /* 4 */
+        case 3 : colorth=2; break;  /* 4 */
+        case 4 : colorth=3; break;  /* 6 */
+        case 5 : colorth=4; break;  /* 8 */
       }
 
     i=0;
     do{
        B=(SiS_CalcDelay2(ROMAddr,FQBQData[i])*VCLK*colorth);
+
        bl=B/(16*MCLK);
        if (B==bl*16*MCLK) {
          bl=bl+1;
-       }
-       else {
-         bl=bl+1;
+       } else {
+         bl=bl+2;  /* TW: was +1 */
        }
 
        if(bl>0x13) {
           if(FQBQData[i+1]==0xFF) {
-            ThresholdLow=0x13;
-            break;
+             ThresholdLow=0x13;
+             break;
           }
           i++;
-       }
-       else {
-         ThresholdLow=bl;
-         break;
+       } else {
+          ThresholdLow=bl;
+          break;
        }
     } while(FQBQData[i]!=0xFF);
   }
@@ -3710,7 +3498,7 @@
 
   SiS_SetReg4(0xcf8,0x80000050);
   eax=SiS_GetReg3(0xcfc);
-  eax=eax&0x0f0ffffff;
+  eax=eax&0xf0ffffff;
   eax=eax|data2;
   SiS_SetReg4(0xcfc,eax);
 
@@ -3723,6 +3511,7 @@
   data=data&0x10;
   data=data<<1;
   SiS_SetRegANDOR(SiS_P3c4,0x0F,0xDF,data);
+
   SiS_SetReg1(SiS_P3c4,0x3B,0x09);
 
   data=ThresholdLow+3;
@@ -3733,7 +3522,7 @@
 USHORT
 SiS_CalcDelay2(ULONG ROMAddr,UCHAR key)
 {
-  USHORT data,index;
+  USHORT data,index;	   /* TW: in BIOS at 0x1029 - identical */
   UCHAR  LatencyFactor[] ={ 97, 88, 86, 79, 77, 00,       /*; 64  bit    BQ=2   */
                             00, 87, 85, 78, 76, 54,       /*; 64  bit    BQ=1   */
                             97, 88, 86, 79, 77, 00,       /*; 128 bit    BQ=2   */
@@ -3759,9 +3548,9 @@
   USHORT  temp1;
   USHORT  Part1Port;
   Part1Port=BaseAddr+SIS_CRT2_PORT_04;
-  temp1=SiS_GetReg1(SiS_Part1Port,0x1);
+  temp1=SiS_GetReg1(SiS_Part1Port,0x01);
   temp1 |= 0x40;
-  SiS_SetReg1(SiS_Part1Port,0x1,temp1);
+  SiS_SetReg1(SiS_Part1Port,0x01,temp1);
 }
 
 /* =============  ynlai ============== */
@@ -3772,7 +3561,7 @@
   UCHAR  DAC_CLR_PARMS[]={0x00,0x00,0x00};
   USHORT SR1F;
 
-  SR1F=SiS_GetReg1(SiS_P3c4,0x1F);
+  SR1F=SiS_GetReg1(SiS_P3c4,0x1F);		/* DAC pedestal */
   SiS_SetRegANDOR(SiS_P3c4,0x1F,0xFF,0x04);
   if(SiS_IF_DEF_LVDS==0) {
     if(SiS_BridgeIsOn(BaseAddr)) {
@@ -3838,16 +3627,14 @@
     temp=temp|SiS_SenseCHTV();
     tempbx=~(LCDSense|AVIDEOSense|SVIDEOSense);
     SiS_SetRegANDOR(SiS_P3d4,0x32,tempbx,temp);
-  }
-  else {       /* for 301 */
+  } else {       /* for 301 */
     if(SiS_IF_DEF_HiVision==1) {  /* for HiVision */
       tempax=SiS_GetReg1(SiS_P3c4,0x38);
       temp=tempax&0x01;
       tempax=SiS_GetReg1(SiS_P3c4,0x3A);
       temp=temp|(tempax&0x02);
       SiS_SetRegANDOR(SiS_P3d4,0x32,0xA0,temp);
-    }
-    else {
+    } else {
       if(SiS_BridgeIsOn(BaseAddr)) {
         P2reg0 = SiS_GetReg1(SiS_Part2Port,0x00);
         if(!SiS_BridgeIsEnable(BaseAddr,HwDeviceExtension)) {
@@ -3891,7 +3678,7 @@
 
         if(OutputSelect&BoardTVType){
           tempbx=*pSiS_VideoSenseData;
-            /*301b*/
+        /*301b*/
         if(!(SiS_Is301B(BaseAddr))){
              tempbx=*pSiS_VideoSenseData2;
         }
@@ -3902,14 +3689,14 @@
               tempax=tempax|AVIDEOSense;
             }
           }
-        }else{
+        } else {
           if(!(tempax&SVIDEOSense)){
             tempbx=*pSiS_VideoSenseData;
-         /*301b*/
-        if(!(SiS_Is301B(BaseAddr))){
+            /*301b*/
+            if(!(SiS_Is301B(BaseAddr))){
               tempbx=*pSiS_VideoSenseData2;
-        }
-        /*end 301b*/  
+            }
+            /*end 301b*/
             tempcx=0x0804;
             if(SiS_Sense(SiS_Part4Port,tempbx,tempcx)){
               if(SiS_Sense(SiS_Part4Port,tempbx,tempcx)){
@@ -3928,9 +3715,9 @@
       tempcx=0;
       SiS_Sense(SiS_Part4Port,tempbx,tempcx);
   
-   if((SiS_VBType&VB_SIS301LV)||(SiS_VBType&VB_SIS302LV)){
-     tempax=tempax&0x00ef;   				/* 301lv to disable CRT2*/
-      }  
+      if((SiS_VBType&VB_SIS301LV)||(SiS_VBType&VB_SIS302LV)){
+         tempax=tempax&0x00ef;   				/* 301lv to disable CRT2*/
+      }
       SiS_SetRegANDOR(SiS_P3d4,0x32,~0xDF,tempax);
       SiS_SetReg1(SiS_Part2Port,0x00,P2reg0);
       if(!(P2reg0&0x20)) {
@@ -3957,7 +3744,7 @@
   tempch=(tempcx&0x7F00)>>8;      /*   ynlai [05/22/2001]  */
   temp=SiS_GetReg1(SiS_Part4Port,0x03);
   temp=temp^(0x0E);
-  temp=temp&tempch;             /*   ynlai [05/22/2001]  */
+  temp=temp&tempch;               /*   ynlai [05/22/2001]  */
   if(temp>0) return 1;
   else return 0;
 }
@@ -3978,7 +3765,7 @@
 {
   USHORT temp;
   /*add lcd sense*/
-  if(HwDeviceExtension->ulCRT2LCDType== LCD_UNKNOWN)
+  if(HwDeviceExtension->ulCRT2LCDType==LCD_UNKNOWN)
     	return 0;
   else{
      	temp=(USHORT)HwDeviceExtension->ulCRT2LCDType;
diff -urN linux-2.4.19-pre9/drivers/video/sis/init.h linux-2.4.19-pre10/drivers/video/sis/init.h
--- linux-2.4.19-pre9/drivers/video/sis/init.h	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/video/sis/init.h	Mon Jun  3 18:50:56 2002
@@ -125,15 +125,17 @@
 USHORT      SiS_CRT1Mode;
 
 USHORT   flag_clearbuffer;         /*0: no clear frame buffer 1:clear frame buffer  */
-int      SiS_RAMType;                  /*int      ModeIDOffset,StandTable,CRT1Table,ScreenOffset,REFIndex;*/
+int      SiS_RAMType;              /*int      ModeIDOffset,StandTable,CRT1Table,ScreenOffset,REFIndex;*/
 USHORT   SiS_ModeType;
 USHORT   SiS_IF_DEF_LVDS,SiS_IF_DEF_TRUMPION,SiS_IF_DEF_DSTN,SiS_IF_DEF_FSTN;    /*add for dstn*/
 USHORT   SiS_IF_DEF_CH7005,SiS_IF_DEF_HiVision;
+USHORT	 SiS_Backup7005=0xff;	/* TW: Backup for power-status */
 USHORT   SiS_VBInfo,SiS_LCDResInfo,SiS_LCDTypeInfo,SiS_LCDInfo, SiS_VBType;/*301b*/
-USHORT   SiS_VBExtInfo; /*301lv*/
+USHORT   SiS_VBExtInfo;  /*301lv*/
 USHORT   SiS_SelectCRT2Rate;
 
 extern   USHORT   SiS_SetFlag;
+extern   USHORT   SiS_DDC_Port;
 
 void     SiS_SetMemoryClock(ULONG ROMAddr);
 void     SiS_SetDRAMModeRegister(ULONG   ROMAddr);
@@ -161,17 +163,17 @@
 void SiS_DisableChannelInterleaving(int index,USHORT SiS_DDRDRAM_TYPE[][5]);
 void SiS_SetDRAMSizingType(int index,USHORT DRAMTYPE_TABLE[][5]);
 void SiS_CheckBusWidth_310(ULONG ROMAddress,ULONG FBAddress);
-int SiS_SetRank(int index,UCHAR RankNo,UCHAR SiS_ChannelAB,USHORT DRAMTYPE_TABLE[][5]);
-int SiS_SetDDRChannel(int index,UCHAR ChannelNo,UCHAR SiS_ChannelAB,USHORT DRAMTYPE_TABLE[][5]);
-int SiS_CheckColumn(int index,USHORT DRAMTYPE_TABLE[][5],ULONG FBAddress);
-int SiS_CheckBanks(int index,USHORT DRAMTYPE_TABLE[][5],ULONG FBAddress);
-int SiS_CheckRank(int RankNo,int index,USHORT DRAMTYPE_TABLE[][5],ULONG FBAddress);
-int SiS_CheckDDRRank(int RankNo,int index,USHORT DRAMTYPE_TABLE[][5],ULONG FBAddress);
-int SiS_CheckRanks(int RankNo,int index,USHORT DRAMTYPE_TABLE[][5],ULONG FBAddress);
-int SiS_CheckDDRRanks(int RankNo,int index,USHORT DRAMTYPE_TABLE[][5],ULONG FBAddress);
-int SiS_SDRSizing(ULONG FBAddress);
-int SiS_DDRSizing(ULONG FBAddress);
-int Is315E(void);
+int  SiS_SetRank(int index,UCHAR RankNo,UCHAR SiS_ChannelAB,USHORT DRAMTYPE_TABLE[][5]);
+int  SiS_SetDDRChannel(int index,UCHAR ChannelNo,UCHAR SiS_ChannelAB,USHORT DRAMTYPE_TABLE[][5]);
+int  SiS_CheckColumn(int index,USHORT DRAMTYPE_TABLE[][5],ULONG FBAddress);
+int  SiS_CheckBanks(int index,USHORT DRAMTYPE_TABLE[][5],ULONG FBAddress);
+int  SiS_CheckRank(int RankNo,int index,USHORT DRAMTYPE_TABLE[][5],ULONG FBAddress);
+int  SiS_CheckDDRRank(int RankNo,int index,USHORT DRAMTYPE_TABLE[][5],ULONG FBAddress);
+int  SiS_CheckRanks(int RankNo,int index,USHORT DRAMTYPE_TABLE[][5],ULONG FBAddress);
+int  SiS_CheckDDRRanks(int RankNo,int index,USHORT DRAMTYPE_TABLE[][5],ULONG FBAddress);
+int  SiS_SDRSizing(ULONG FBAddress);
+int  SiS_DDRSizing(ULONG FBAddress);
+int  Is315E(void);
 void SiS_VerifyMclk(ULONG FBAddr);
 #endif
 
@@ -181,7 +183,8 @@
 extern void SetEnableDstn(void);
 void     SiS_Delay15us(ULONG);
 BOOLEAN  SiS_SearchModeID(ULONG ROMAddr, USHORT ModeNo,USHORT  *ModeIdIndex);
-BOOLEAN  SiS_CheckMemorySize(ULONG ROMAddr,PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT ModeNo,USHORT ModeIdIndex);
+BOOLEAN  SiS_CheckMemorySize(ULONG ROMAddr,PSIS_HW_DEVICE_INFO HwDeviceExtension,
+                             USHORT ModeNo,USHORT ModeIdIndex);
 UCHAR    SiS_GetModePtr(ULONG ROMAddr, USHORT ModeNo,USHORT ModeIdIndex);
 void     SiS_SetSeqRegs(ULONG,USHORT StandTableIndex);
 void     SiS_SetMiscRegs(ULONG,USHORT StandTableIndex);
@@ -191,12 +194,14 @@
 void     SiS_ClearExt1Regs(void);
 void     SiS_SetSync(ULONG ROMAddr,USHORT RefreshRateTableIndex);
 void     SiS_SetCRT1CRTC(ULONG ROMAddr,USHORT ModeNo,USHORT ModeIdIndex,USHORT RefreshRateTableIndex);
-void     SiS_SetCRT1VCLK(ULONG ROMAddr,USHORT ModeNo,USHORT ModeIdIndex,PSIS_HW_DEVICE_INFO,USHORT RefreshRateTableIndex);
+void     SiS_SetCRT1VCLK(ULONG ROMAddr,USHORT ModeNo,USHORT ModeIdIndex,PSIS_HW_DEVICE_INFO,
+                         USHORT RefreshRateTableIndex);
 void     SiS_SetVCLKState(ULONG ROMAddr,PSIS_HW_DEVICE_INFO, USHORT ModeNo,USHORT RefreshRateTableIndex);
 void     SiS_LoadDAC(ULONG ROMAddr,USHORT ModeNo,USHORT ModeIdIndex);
 void     SiS_DisplayOn(void);
 void 	 SiS_DisplayOff(void);
-void     SiS_SetCRT1ModeRegs(ULONG ROMAddr,PSIS_HW_DEVICE_INFO,USHORT ModeNo,USHORT ModeIdIndex,USHORT RefreshRateTableIndex);
+void     SiS_SetCRT1ModeRegs(ULONG ROMAddr,PSIS_HW_DEVICE_INFO,USHORT ModeNo,
+                             USHORT ModeIdIndex,USHORT RefreshRateTableIndex);
 void     SiS_WriteDAC(USHORT, USHORT, USHORT, USHORT);
 void     SiS_GetVBType(USHORT BaseAddr);/*301b*/
 USHORT   SiS_ChkBUSWidth(ULONG);
@@ -211,7 +216,8 @@
 void     SiS_SetCRT1FIFO2(ULONG,USHORT ModeNo,PSIS_HW_DEVICE_INFO,USHORT RefreshRateTableIndex);
 void     SiS_CRT2AutoThreshold(USHORT  BaseAddr);
 void     SiS_ClearBuffer(PSIS_HW_DEVICE_INFO,USHORT ModeNo);
-void     SiS_SetCRT1Group(ULONG ROMAddr,PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT ModeNo,USHORT ModeIdIndex);
+void     SiS_SetCRT1Group(ULONG ROMAddr,PSIS_HW_DEVICE_INFO HwDeviceExtension,
+                          USHORT ModeNo,USHORT ModeIdIndex);
 void     SiS_DetectMonitor(PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT BaseAddr);
 void     SiS_GetSenseStatus(PSIS_HW_DEVICE_INFO HwDeviceExtension,ULONG ROMAddr);
 USHORT   SiS_TestMonitorType(UCHAR R_DAC,UCHAR G_DAC,UCHAR B_DAC);
@@ -226,19 +232,19 @@
 void     SiSInitPCIetc(PSIS_HW_DEVICE_INFO HwDeviceExtension);
 
 #ifdef LINUX_XF86
-USHORT  SiS_CalcModeIndex(ScrnInfoPtr pScrn, DisplayModePtr mode);
-void    SiS_SetPitch(ScrnInfoPtr pScrn, UShort BaseAddr);
-void    SiS_SetPitchCRT1(ScrnInfoPtr pScrn, UShort BaseAddr);
-void    SiS_SetPitchCRT2(ScrnInfoPtr pScrn, UShort BaseAddr);
-unsigned char SiS_GetSetModeID(ScrnInfoPtr pScrn, unsigned char id);
+USHORT  	SiS_CalcModeIndex(ScrnInfoPtr pScrn, DisplayModePtr mode);
+void    	SiS_SetPitch(ScrnInfoPtr pScrn, UShort BaseAddr);
+void    	SiS_SetPitchCRT1(ScrnInfoPtr pScrn, UShort BaseAddr);
+void    	SiS_SetPitchCRT2(ScrnInfoPtr pScrn, UShort BaseAddr);
+unsigned char 	SiS_GetSetModeID(ScrnInfoPtr pScrn, unsigned char id);
 #endif
 
-extern   BOOLEAN SiS_SetCRT2Group301(USHORT BaseAddr,ULONG ROMAddr,USHORT ModeNo,
+extern BOOLEAN   SiS_SetCRT2Group301(USHORT BaseAddr,ULONG ROMAddr,USHORT ModeNo,
                                      PSIS_HW_DEVICE_INFO HwDeviceExtension);
-extern   void    SiS_PresetScratchregister(USHORT SiS_P3d4,
+extern void      SiS_PresetScratchregister(USHORT SiS_P3d4,
                                            PSIS_HW_DEVICE_INFO HwDeviceExtension);
-extern   void    SiS_UnLockCRT2(PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT BaseAddr);
-extern   void    SiS_LockCRT2(PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT BaseAddr);
+extern void      SiS_UnLockCRT2(PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT BaseAddr);
+extern void      SiS_LockCRT2(PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT BaseAddr);
 extern BOOLEAN   SiS_BridgeIsOn(USHORT BaseAddr);
 extern BOOLEAN   SiS_BridgeIsEnable(USHORT BaseAddr,PSIS_HW_DEVICE_INFO );
 extern void      SiS_SetTVSystem301(VOID);
@@ -268,7 +274,7 @@
 extern USHORT    SiS_GetVCLK2Ptr(ULONG ROMAddr,USHORT ModeNo,USHORT ModeIdIndex,
                                  USHORT RefreshRateTableIndex,
 				 PSIS_HW_DEVICE_INFO HwDeviceExtension);
-extern BOOLEAN  SiS_Is301B(USHORT BaseAddr);/*301b*/
+extern BOOLEAN   SiS_Is301B(USHORT BaseAddr);/*301b*/
 
 #endif
 
diff -urN linux-2.4.19-pre9/drivers/video/sis/init301.c linux-2.4.19-pre10/drivers/video/sis/init301.c
--- linux-2.4.19-pre9/drivers/video/sis/init301.c	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/video/sis/init301.c	Mon Jun  3 18:50:56 2002
@@ -1,6 +1,14 @@
 /* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/sis/init301.c,v 1.3 2000/12/02 01:16:16 dawes Exp $ */
 
-/* Comments and changes marked with "TW" by Thomas Winischhofer <tw@webit.com> */
+/*
+ * Mode switching code (CRT2 section) for SiS 300/540/630/730/315/550/650/740
+ * (Universal module for Linux kernel framebuffer, XFree86 4.x)
+ *
+ * Comments and changes marked with "TW" by Thomas Winischhofer <thomer@winischhofer.net>
+ *
+ */
+
+/* DEBUG: GetVCLK2Ptr (Mitac bug) - reverted */
 
 /*
 #ifdef WINCE_HEADER
@@ -37,11 +45,11 @@
      SiS_DisplayOn();
      return(FALSE);
    }
-/* SetDefCRT2ExtRegs(BaseAddr);   */
+   /* SetDefCRT2ExtRegs(BaseAddr);   */
    SiS_GetCRT2Data(ROMAddr,ModeNo,ModeIdIndex,RefreshRateTableIndex);
-   /*301b*/ /* TW: Added LVDS test */
+   /*301b*/
    if( ((SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS301LV))
-           && (SiS_VBInfo&SetCRT2ToLCDA)) /* && (SiS_IF_DEF_LVDS==0) */ ){
+           && (SiS_VBInfo&SetCRT2ToLCDA)) ){
 	SiS_GetLVDSDesData(ROMAddr,ModeNo,ModeIdIndex,RefreshRateTableIndex);
    }
    /*end 301b*/
@@ -52,12 +60,14 @@
    SiS_SetGroup1(BaseAddr,ROMAddr,ModeNo,ModeIdIndex,
                  HwDeviceExtension,RefreshRateTableIndex);
 
-    /*301b*/ /* TW: Added LVDS test */
-   if( (SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS301LV)) &&
-                  (SiS_VBInfo&SetCRT2ToLCDA) /* && (SiS_IF_DEF_LVDS==0) */ ) {
+   /*301b*/
+   if( (SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS301LV))
+   		&& (SiS_VBInfo&SetCRT2ToLCDA)
+		&& (SiS_IF_DEF_LVDS == 0) ) {
      	if( (SiS_VBType&(VB_SIS301LV|VB_SIS302LV)) && (SiS_VBInfo&SetCRT2ToLCDA) ){
              	SiS_SetReg1(SiS_Part4Port,0x24,0x0e);
     	}
+   /* end 301b */
    } else if((SiS_IF_DEF_LVDS==0) && (!(SiS_VBInfo&SetCRT2ToLCDA))) {
       	SiS_SetGroup2(BaseAddr,ROMAddr,ModeNo,ModeIdIndex,
 	              RefreshRateTableIndex,HwDeviceExtension);
@@ -68,11 +78,12 @@
       	SiS_SetGroup5(BaseAddr,ROMAddr,ModeNo,ModeIdIndex);
    } else {
      	if(SiS_IF_DEF_CH7005==1) {
+	    if(SiS_VBInfo&SetCRT2ToTV)
+	        /* TW: Set Chrontel registers only if CRT2 is TV */
        		SiS_SetCHTVReg(ROMAddr,ModeNo,ModeIdIndex,
 		               RefreshRateTableIndex);
      	}
-/*     	if(!SiS_LCDResInfo==Panel640x480){   */   /*bainy for panel640x480*/
-     	if(!(SiS_LCDResInfo==Panel640x480)){   /* TW: Shouldn't you be called "Brainy" instead?! */
+     	if(!(SiS_LCDResInfo==Panel640x480)){
     	 	SiS_ModCRT1CRTC(ROMAddr,ModeNo,ModeIdIndex,
 		                RefreshRateTableIndex);
          	if(!SiS_IF_DEF_FSTN)  /*fstn*/
@@ -103,6 +114,15 @@
 #endif
 
    SiS_EnableBridge(HwDeviceExtension,BaseAddr);
+   if(SiS_IF_DEF_CH7005==1) {
+	if(SiS_VBInfo&SetCRT2ToTV) {
+	     /* TW: Disable LCD panel when using TV */
+	     SiS_SetRegANDOR(SiS_P3c4,0x11,0xFF,0x0C);
+	} else {
+	     /* TW: Disable TV when using LCD */
+	     SiS_SetCHTVRegANDOR(0x010E,0xF8);
+	}
+   }
    SiS_DisplayOn();
    SiS_LockCRT2(HwDeviceExtension, BaseAddr);
    return 1;
@@ -124,7 +144,7 @@
     	resinfo = SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
   }
 
-  /*301b*/ /* TW: Added LVDS test */
+  /*301b*/ 
   if( (SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV))
          && (SiS_VBInfo&SetCRT2ToLCDA) ) {
 	   /* TW: Do nothing for these bridge types here */
@@ -142,15 +162,14 @@
                      RefreshRateTableIndex);
   }
 
-  if (ModeNo<=0x13) {
+  if (ModeNo<=0x13)
     	modeflag = SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
-  } else {
+  else
     	modeflag = SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
-  }
 
-   /*301b*/ /* TW: Added LVDS test */
+  /*301b*/
   if( (SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV))
-   	&& (SiS_VBInfo&SetCRT2ToLCDA) /* && (SiS_IF_DEF_LVDS==0) */ ) {
+   					&& (SiS_VBInfo&SetCRT2ToLCDA) ) {
      	SiS_SetGroup1_LCDA(BaseAddr,ROMAddr,ModeNo,ModeIdIndex,
      	                   HwDeviceExtension,RefreshRateTableIndex);
   /*end 301b*/
@@ -275,24 +294,26 @@
 
   /* TW: The following is done for all bridge/chip types/series */
 
-#if 0
+#if 1
   tempax = (tempax&0x00FF)|(tempbx&0xFF00); /* TW: tempax not used above!!!*/
   tempbx=pushbx;
   tempbx=(tempbx&0x00FF)|((tempbx&0xFF00)<<4);
   tempax=tempax|(tempbx&0xFF00);
   temp=(tempax&0xFF00)>>8;
 #endif
-  /* TW: Different code: */
+#if 0
+  /* TW: new code: */
   tempax=(tempbx&0xFF00)>>8;
   tempbx=(((pushbx&0xFF00)>>8)<<4)&0xFF;
   temp=tempax|tempbx;
+#endif
   SiS_SetReg1(SiS_Part1Port,0x0C,temp); 		/* <------------------- */
   temp=tempcx&0x00FF;
   SiS_SetReg1(SiS_Part1Port,0x0D,temp); 		/* <------------------- */
-  tempcx=(SiS_VGAVT-1);
+  tempcx=SiS_VGAVT-1;
   temp=tempcx&0x00FF;
   if(SiS_IF_DEF_CH7005==1) {
-    	if(SiS_VBInfo&0x0C) {
+    	if(SiS_VBInfo&SetCRT2ToTV) {
       		temp--;
     	}
   }
@@ -315,7 +336,7 @@
       		tempbx = SiS_CRT1Table[CRT1Index].CR[8];
       		temp = SiS_CRT1Table[CRT1Index].CR[7];
       		if(temp&0x04) tempbx=tempbx|0x0100;
-      		if(temp&0x080) tempbx=tempbx|0x0200;
+      		if(temp&0x80) tempbx=tempbx|0x0200;
       		temp = SiS_CRT1Table[CRT1Index].CR[13];
       		if(temp&0x08) tempbx=tempbx|0x0400;
       		temp = SiS_CRT1Table[CRT1Index].CR[9];
@@ -341,13 +362,19 @@
   }
 
   if (HwDeviceExtension->jChipType < SIS_315H ) {
-     /* ---------- 300 series -------------- */
+    /* ---------- 300 series -------------- */
 
-    SiS_SetRegANDOR(SiS_Part1Port,0x13,~0x03C,temp); 	/* <------------------- */
+    SiS_SetRegANDOR(SiS_Part1Port,0x13,~0x03C,temp); 	/* <----------------- */
+	/* TW: This register will be adapted according to LCD
+	 *     panel type later in the OEM setup functions.
+	 *     (Various panel types require a different delay
+	 *     such as Clevo 2202; however, on most panels,
+	 *     0x20 does nicely.)
+	 */
 
   } else {
     /* ----------- 310 series ---------------*/
-    temp >>=2;
+    temp >>=2;    /* TW: This is typical SiS code: First calulate temp, then overwrite it... */
     temp = 0x11;    						/*  ynlai 05/30/2001 for delay compenation  */
     SiS_SetReg1(SiS_Part1Port,0x2D,temp);
     /*SiS_SetRegANDOR(SiS_Part1Port,0x2D,~0x00F,temp);*/
@@ -359,10 +386,10 @@
     SiS_SetRegANDOR(SiS_Part1Port,0x2C,~0x0C0,tempax);
   }
 
-  if(SiS_IF_DEF_LVDS==0) {  	/*  301   */
+  if(SiS_IF_DEF_LVDS==0) {
     	SiS_SetGroup1_301(BaseAddr,ROMAddr,ModeNo,ModeIdIndex,
 	                  HwDeviceExtension,RefreshRateTableIndex);
-  } else {                    	/*  LVDS  */
+  } else {
     	SiS_SetGroup1_LVDS(BaseAddr,ROMAddr,ModeNo,ModeIdIndex,
 	                   HwDeviceExtension,RefreshRateTableIndex);
   }
@@ -390,15 +417,15 @@
   if(!(SiS_VBInfo&SetInSlaveMode))  return;
 
   tempax=0xFFFF;
-  if(!(SiS_VBInfo&SetCRT2ToTV)){
+  if(!(SiS_VBInfo&SetCRT2ToTV)) {
     	tempax=SiS_GetVGAHT2();
   }
   if(modeflag&Charx8Dot) tempcx=0x08;
   else tempcx=0x09;
-  if(tempax>=SiS_VGAHT){
+  if(tempax>=SiS_VGAHT) {
     	tempax=SiS_VGAHT;
   }
-  if(modeflag&HalfDCLK){
+  if(modeflag&HalfDCLK) {
     	tempax=tempax>>1;
   }
   tempax=(tempax/tempcx)-5;
@@ -432,8 +459,7 @@
         if(ModeNo>0x13) temp=temp-10;
       }
     }
-  }
-  else {
+  } else {
     tempcx=tempbx&0x00FF;
     tempbx=(tempbx&0xFF00)>>8;
     tempcx=(tempcx+tempbx)>>1;
@@ -448,8 +474,7 @@
             }
           }
         }
-    }
-    else{
+    } else {
        if(!(modeflag&HalfDCLK)){
          temp=temp-4;
          if(SiS_LCDResInfo!=Panel1280x960) {
@@ -479,10 +504,8 @@
   SiS_SetReg1(SiS_Part1Port,0x07,temp);                       	/* 0x07 Horizontal Retrace Start */
   SiS_SetReg1(SiS_Part1Port,0x08,0);                            /* 0x08 Horizontal Retrace End   */
   
-  if(SiS_VBInfo&SetCRT2ToTV)
-  {
-        if(SiS_SetFlag&TVSimuMode) 
-        {
+  if(SiS_VBInfo&SetCRT2ToTV) {
+        if(SiS_SetFlag&TVSimuMode) {
             if((ModeNo==0x06)||(ModeNo==0x10)||(ModeNo==0x11)||(ModeNo==0x13)||(ModeNo==0x0F)){
              	SiS_SetReg1(SiS_Part1Port,0x07,0x5b);
              	SiS_SetReg1(SiS_Part1Port,0x08,0x03);
@@ -649,7 +672,7 @@
  *     which confuses me. In init.c, there is code for these bridges
  *     which is executed ONLY if IF_DEF_LVDS is 0. The following
  *     is being called only if IF_DEF_LVDS is NOT 0, and it contains
- *     code for 301B et al as well. Is LVDS now 0 or 1 on
+ *     code for 301B et al as well. Is IF_DEF_LVDS now 0 or 1 on
  *     301B/302B/301LV/302LV?
  */
 void SiS_SetGroup1_LVDS(USHORT  BaseAddr,ULONG ROMAddr,USHORT ModeNo,
@@ -672,6 +695,7 @@
   tempax=SiS_LCDHDES;
   tempbx=SiS_HDE;
   tempcx=SiS_HT;
+
   tempcx=tempcx-tempbx;                                    		/* HT-HDE  */
   if(SiS_LCDInfo&LCDNonExpanding) {
     	if(SiS_LCDResInfo==Panel640x480)  tempbx=640;
@@ -684,14 +708,12 @@
   if(tempax>=tempbx){
     	tempax=tempax-tempbx;
   }
-  push2=tempax;
-                                                           		/* push ax   lcdhdee  */
+  push2=tempax;	                                                       	/* push ax   lcdhdee  */
   tempcx=tempcx>>2;                                        		/* temp  */
   tempcx=tempcx+tempax;                                    		/* lcdhrs  */
   if(tempcx>=tempbx){
     	tempcx=tempcx-tempbx;
-  }
-                                                           		/* v ah,cl  */
+  }									/* v ah,cl  */
   tempax=tempcx;
   tempax=tempax>>3;                                        		/* BPLHRS */
   temp=tempax&0x00FF;
@@ -715,21 +737,22 @@
   tempcx=tempcx>>3;                                        			/* BPLHDES */
   temp=(tempcx&0x00FF);
   if(ModeNo==0x5b){                            					/*fix fstn mode=5b*/
-      	temp=temp-1;
+      	temp--;
   }
   SiS_SetReg1(SiS_Part1Port,0x16,temp);    	/* <------------------- */      /* Part1_16h  */
   if(tempbx&0x07) tempbx=tempbx+8;
   tempbx=tempbx>>3;                                        			/* BPLHDEE  */
   temp=tempbx&0x00FF;
   if(ModeNo==0x5b){                            					/*fix fstn mode=5b*/
-      	temp=temp-1;
+      	temp--;
   }
   SiS_SetReg1(SiS_Part1Port,0x17,temp);   	/* <------------------- */      /* Part1_17h  */
 
   tempcx=SiS_VGAVT;
   tempbx=SiS_VGAVDE;
   tempcx=tempcx-tempbx;                                    			/* GAVT-VGAVDE  */
-  tempbx=SiS_LCDVDES;                                          			/* VGAVDES  */
+  tempbx=SiS_LCDVDES;			                    			/* VGAVDES  */
+
   push1=tempbx;                                        				/* push bx temppush1 */
   if(SiS_IF_DEF_TRUMPION==0){
     	if(SiS_IF_DEF_CH7005==1) {
@@ -776,12 +799,6 @@
   if(SiS_SetFlag&EnableLVDSDDA) {
     	temp=temp|0x40;
   }
-  /* TW: This causes "jitter" in letters at 8bpp,
-   * however, it does no harm to other modes; maybe
-   * this is good for some kind of anti-aliasing.
-   * (The 8bpp modes don't work at the time of
-   * this writing; dark and black&white on LCD)
-   */
   if(SiS_LCDInfo&LCDRGB18Bit) {
     	temp=temp|0x80;
   }
@@ -799,25 +816,22 @@
   }
   tempebx=tempeax;                                        			/* BPLVCFACT  */
 
-  /* TW: This part was commented; without it, LCD on
-   *     LVDS is not initialized correctly. Don't do it
-   *     for the SiS bridges.
-   */
-  if (!(SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV))) {
-  	if(SiS_SetFlag&EnableLVDSDDA){
+  /* TW: Modified according to info from SiS - might be wrong */
+  /* if (!(SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV))) { */
+  if ((HwDeviceExtension->jChipType == SIS_540)||
+      (HwDeviceExtension->jChipType == SIS_630)||
+      (HwDeviceExtension->jChipType == SIS_730)||
+      (HwDeviceExtension->jChipType == SIS_300)) {
+
+  	if(SiS_SetFlag&EnableLVDSDDA) {
     		tempebx=tempebx&0x003F;
   	}
   	temp=(USHORT)(tempebx&0x00FF);
-  	SiS_SetReg1(SiS_Part1Port,0x1E,temp);                          		/* Part1_1Eh */
-  }
+  	SiS_SetReg1(SiS_Part1Port,0x1E,temp);                       		/* Part1_1Eh */
 
+  }
   /*add for 301b different 301*/
-  /* TW: Added LVDS test - but this seems wrong; SetGroup1_LVDS is only
-   *     being called if LVDS==1,  so it must be 1 for some of these
-   *     bridges as well...
-   */
-  if((SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV))
-  			 /* && (SiS_IF_DEF_LVDS==0) */ ) {
+  else if(SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV)) {
     	tempecx=SiS_VGAVT;
     	tempebx=SiS_VDE;
     	tempeax=SiS_VGAVDE;
@@ -825,9 +839,7 @@
     	tempeax=tempeax<<18;
     	temp=(USHORT)(tempeax%tempebx);
     	tempeax=tempeax/tempebx;
-    	if(temp!=0) {
-      		tempeax++;
-    	}
+    	if(temp!=0) tempeax++;
     	tempebx=tempeax;                                        		/* BPLVCFACT  */
     	tempvcfact=tempeax;       /*301b*/
     	temp=(USHORT)(tempebx&0x00FF);
@@ -835,16 +847,13 @@
     	temp=(USHORT)((tempebx&0x00FF00)>>8);
     	SiS_SetReg1(SiS_Part1Port,0x36,temp);
     	temp=(USHORT)((tempebx&0x00030000)>>16);
-    	if(SiS_VDE==SiS_VGAVDE)
-    	{
-      		temp=temp|0x04;
-    	}
+    	if(SiS_VDE==SiS_VGAVDE)	temp=temp|0x04;
     	SiS_SetReg1(SiS_Part1Port,0x35,temp);
   }
   /*end for 301b*/
   
   tempbx=push2;                                        				/* p bx temppush2 BPLVDEE  */
-  tempcx=push1;                                        				/* pop cx temppush1 NPLVDES */
+  tempcx=push1;			/* pop cx temppush1 NPLVDES */
   push1=(USHORT)(tempeax&0xFFFF);
   if(!(SiS_VBInfo&SetInSlaveMode)) {
    	if(!SiS_IF_DEF_DSTN){
@@ -874,16 +883,14 @@
   tempecx=SiS_VGAHDE;
   tempebx=SiS_HDE;
   tempeax=tempecx;
-  tempeax=tempeax<<6;
-  tempeax=tempeax<<10;
+  tempeax=tempeax<<16;
   tempeax=tempeax/tempebx;
   if(tempebx==tempecx){
-    	tempeax=65535;
+    	tempeax=0xFFFF;
   }
   tempecx=tempeax;
-  tempeax=SiS_VGAHDE; /* TW: 2test: no effect */ 				/*change VGAHT->VGAHDE*/
-  tempeax=tempeax<<6;
-  tempeax=tempeax<<10;
+  tempeax=SiS_VGAHT; /* TW: Was SiS_VGAHDE;  - WRONG! - old (wrong) comment: "change VGAHT->VGAHDE"*/
+  tempeax=tempeax<<16;
   tempeax=tempeax/tempecx;
   tempecx=tempecx<<16;
   tempeax=tempeax-1;
@@ -898,10 +905,11 @@
   	tempeax=tempeax/tempvcfact;
   	tempbx=(USHORT) (tempeax&0x0FFFF);
   }
+
   if(SiS_LCDResInfo==Panel1024x768) tempbx--;
-  if(SiS_SetFlag&EnableLVDSDDA) {
-    	tempbx=1;
-  }
+
+  if(SiS_SetFlag&EnableLVDSDDA) tempbx=1;
+
   temp=((tempbx&0xFF00)>>8)<<3;
   temp=temp|(USHORT)(((tempecx&0x0000FF00)>>8)&0x07);
   SiS_SetReg1(SiS_Part1Port,0x20,temp);  	/* <------------------- */    	/* Part1_20h */
@@ -1015,13 +1023,13 @@
   USHORT modeflag,resinfo;
   USHORT push1,push2,tempax,tempbx,tempcx,temp;
   ULONG tempeax=0,tempebx,tempecx,tempvcfact;/*301b*/
-   SiS_SetRegOR(SiS_Part1Port,0x2D,0x20);
+
+  SiS_SetRegOR(SiS_Part1Port,0x2D,0x20);
   
   if(ModeNo<=0x13) {
     modeflag = SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;      /* si+St_ResInfo */
     resinfo = SiS_SModeIDTable[ModeIdIndex].St_ResInfo;
-  }
-  else {
+  } else {
     modeflag = SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;     /* si+Ext_ResInfo */
     resinfo = SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
   }
@@ -1034,47 +1042,47 @@
     	if(SiS_LCDResInfo==Panel1280x1024) tempbx=1280;
     	if(SiS_LCDResInfo==Panel1024x768) tempbx=1024;
   }
-  tempcx=tempcx-tempbx;                                    /* HT-HDE  */
+  tempcx=tempcx-tempbx;                                    	/* HT-HDE  */
   push1=tempax;
-  tempax=tempax+tempbx;                                    /* lcdhdee  */
+  tempax=tempax+tempbx;                                    	/* lcdhdee  */
   tempbx=SiS_HT;
   if(tempax>=tempbx){
    	tempax=tempax-tempbx;
   }
   push2=tempax;
-                                                           /* push ax   lcdhdee  */
-  tempcx=tempcx>>2;                                        /* temp  */
-  tempcx=tempcx+tempax;                                    /* lcdhrs  */
+                                                           	/* push ax   lcdhdee  */
+  tempcx=tempcx>>2;                                        	/* temp  */
+  tempcx=tempcx+tempax;                                    	/* lcdhrs  */
   if(tempcx>=tempbx){
     	tempcx=tempcx-tempbx;
   }
-                                                           /* v ah,cl  */
+                                                           	/* v ah,cl  */
   tempax=tempcx;
-  tempax=tempax>>3;                                        /* BPLHRS */
+  tempax=tempax>>3;                                        	/* BPLHRS */
   temp=tempax&0x00FF;
-  SiS_SetReg1(SiS_Part1Port,0x14,temp);                          /* Part1_14h  */
+  SiS_SetReg1(SiS_Part1Port,0x14,temp);                         /* Part1_14h  */
   temp=(tempax&0x00FF)+10;
   temp=temp&0x01F;
   temp=temp|(((tempcx&0x00ff)&0x07)<<5);
-  SiS_SetReg1(SiS_Part1Port,0x15,temp);                          /* Part1_15h  */
-  tempbx=push2;                                          /* lcdhdee  */
-  tempcx=push1;                                          /* lcdhdes  */
+  SiS_SetReg1(SiS_Part1Port,0x15,temp);                         /* Part1_15h  */
+  tempbx=push2;                                          	/* lcdhdee  */
+  tempcx=push1;                                          	/* lcdhdes  */
   temp=(tempcx&0x00FF);
-  temp=temp&0x07;                                      /* BPLHDESKEW  */
-  SiS_SetReg1(SiS_Part1Port,0x1A,temp);                          /* Part1_1Ah  */
-  tempcx=tempcx>>3;                                        /* BPLHDES */
+  temp=temp&0x07;                                      		/* BPLHDESKEW  */
+  SiS_SetReg1(SiS_Part1Port,0x1A,temp);                         /* Part1_1Ah  */
+  tempcx=tempcx>>3;                                        	/* BPLHDES */
   temp=(tempcx&0x00FF);
-  SiS_SetReg1(SiS_Part1Port,0x16,temp);                          /* Part1_16h  */
+  SiS_SetReg1(SiS_Part1Port,0x16,temp);                         /* Part1_16h  */
   if(tempbx&0x07) tempbx=tempbx+8;
-  tempbx=tempbx>>3;                                        /* BPLHDEE  */
+  tempbx=tempbx>>3;                                        	/* BPLHDEE  */
   temp=tempbx&0x00FF;
-  SiS_SetReg1(SiS_Part1Port,0x17,temp);                          /* Part1_17h  */
+  SiS_SetReg1(SiS_Part1Port,0x17,temp);                        	/* Part1_17h  */
 
   tempcx=SiS_VGAVT;
   tempbx=SiS_VGAVDE;
-  tempcx=tempcx-tempbx;                                    /* GAVT-VGAVDE  */
-  tempbx=SiS_LCDVDES;                                          /* VGAVDES  */
-  push1=tempbx;                                        /* push bx temppush1 */
+  tempcx=tempcx-tempbx;                                    	/* GAVT-VGAVDE  */
+  tempbx=SiS_LCDVDES;                                          	/* VGAVDES  */
+  push1=tempbx;                                        		/* push bx temppush1 */
   if(SiS_IF_DEF_TRUMPION==0){
     if(SiS_IF_DEF_CH7005==1) {
       if(SiS_VBInfo&SetCRT2ToTV) {
@@ -1086,28 +1094,28 @@
   }
   else tempax=SiS_VGAVDE;
   tempbx=tempbx+tempax;
-  tempax=SiS_VT;                                               /* VT  */
+  tempax=SiS_VT;                                               	/* VT  */
   if(tempbx>=SiS_VT){
     tempbx=tempbx-tempax;
   }
-  push2=tempbx;                                        /* push bx  temppush2  */
+  push2=tempbx;                                        		/* push bx  temppush2  */
   tempcx=tempcx>>1;
   tempbx=tempbx+tempcx;
-  tempbx++;                                                /* BPLVRS  */
+  tempbx++;                                                	/* BPLVRS  */
   if(tempbx>=tempax){
     tempbx=tempbx-tempax;
   }
   temp=tempbx&0x00FF;
-  SiS_SetReg1(SiS_Part1Port,0x18,temp);                          /* Part1_18h  */
+  SiS_SetReg1(SiS_Part1Port,0x18,temp);                         /* Part1_18h  */
   tempcx=tempcx>>3;
   tempcx=tempcx+tempbx;
-  tempcx++;                                                /* BPLVRE  */
+  tempcx++;                                                	/* BPLVRE  */
   temp=tempcx&0x00FF;
   temp=temp&0x0F;
   SiS_SetRegANDOR(SiS_Part1Port,0x19,~0x00F,temp);               /* Part1_19h  */
   temp=(tempbx&0xFF00)>>8;
   temp=temp&0x07;
-  temp=temp<<3;                                 /* BPLDESKEW =0 */
+  temp=temp<<3;                                 		/* BPLDESKEW =0 */
   tempbx=SiS_VGAVDE;
   if(tempbx!=SiS_VDE){
     temp=temp|0x40;
@@ -1118,17 +1126,16 @@
   if(SiS_LCDInfo&LCDRGB18Bit) {
     temp=temp|0x80;
   }
-  SiS_SetRegANDOR(SiS_Part1Port,0x1A,0x07,temp);                 /* Part1_1Ah */
+  SiS_SetRegANDOR(SiS_Part1Port,0x1A,0x07,temp);             	/* Part1_1Ah */
   
-  tempbx=push2;                                        /* p bx temppush2 BPLVDEE  */
-  tempcx=push1;                                        /* pop cx temppush1 NPLVDES */
+  tempbx=push2;                                        		/* p bx temppush2 BPLVDEE  */
+  tempcx=push1;                                        		/* pop cx temppush1 NPLVDES */
   push1=(USHORT)(tempeax&0xFFFF);
     
   if(!(SiS_VBInfo&SetInSlaveMode)) {
     if(SiS_LCDResInfo==Panel800x600) {
       if(resinfo==7) tempcx++;
-    }
-    else {
+    } else {
       if(SiS_LCDResInfo==Panel1024x768) {
         if(resinfo==8) tempcx++;
       }
@@ -1148,24 +1155,23 @@
   tempecx=SiS_VGAVT;
   tempebx=SiS_VDE;
   tempeax=SiS_VGAVDE;
-  tempecx=tempecx-tempeax;                                 /* VGAVT-VGAVDE  */
+  tempecx=tempecx-tempeax;                                 	/* VGAVT-VGAVDE  */
   tempeax=tempeax<<18;
   temp=(USHORT)(tempeax%tempebx);
   tempeax=tempeax/tempebx;
   if(temp!=0){
     tempeax++;
   }
-  tempebx=tempeax;                                        /* BPLVCFACT  */
+  tempebx=tempeax;                                        	/* BPLVCFACT  */
   tempvcfact=tempeax;       /*301b*/
   temp=(USHORT)(tempebx&0x00FF);
   SiS_SetReg1(SiS_Part1Port,0x37,temp);   
   temp=(USHORT)((tempebx&0x00FF00)>>8);
   SiS_SetReg1(SiS_Part1Port,0x36,temp);   
   temp=(USHORT)((tempebx&0x00030000)>>16);
-  if(SiS_VDE==SiS_VGAVDE)
-    {
+  if(SiS_VDE==SiS_VGAVDE) {
       temp=temp|0x04;
-    }   
+  }
   
   SiS_SetReg1(SiS_Part1Port,0x35,temp);   
   
@@ -1176,7 +1182,7 @@
   tempeax=tempeax<<10;
   tempeax=tempeax/tempebx;
   if(tempebx==tempecx){
-    tempeax=65535;
+    	tempeax=0xFFFF;
   }
   tempecx=tempeax;
   tempeax=SiS_VGAHDE;  /*301b to change HT->HDE*/
@@ -1195,17 +1201,17 @@
   tempbx=(USHORT) (tempeax&0x0FFFF);
   if(SiS_LCDResInfo==Panel1024x768) tempbx--;
   if(SiS_SetFlag&EnableLVDSDDA){
-    tempbx=1;
+    	tempbx=1;
   }
   temp=((tempbx&0xFF00)>>8)<<3;
   temp=temp|(USHORT)(((tempecx&0x0000FF00)>>8)&0x07);
-  SiS_SetReg1(SiS_Part1Port,0x20,temp);                          /* Part1_20h */
+  SiS_SetReg1(SiS_Part1Port,0x20,temp);                         /* Part1_20h */
   temp=tempbx&0x00FF;
-  SiS_SetReg1(SiS_Part1Port,0x21,temp);                          /* Part1_21h */
-  tempecx=tempecx>>16;                                     /* BPLHCFACT  */
+  SiS_SetReg1(SiS_Part1Port,0x21,temp);                         /* Part1_21h */
+  tempecx=tempecx>>16;                                     	/* BPLHCFACT  */
  
   temp=(USHORT)((tempecx&0x0000FF00)>>8);
-  SiS_SetReg1(SiS_Part1Port,0x22,temp);                          /* Part1_22h */
+  SiS_SetReg1(SiS_Part1Port,0x22,temp);                         /* Part1_22h */
   temp=(USHORT)(tempecx&0x000000FF);
   SiS_SetReg1(SiS_Part1Port,0x23,temp);
   
@@ -1228,9 +1234,8 @@
   USHORT offset;
   UCHAR temp;
 
-  if(SiS_VBInfo&SetInSlaveMode) {
-    return;
-  }
+  if(SiS_VBInfo&SetInSlaveMode) return;
+
   offset=SiS_GetOffset(ROMAddr,ModeNo,ModeIdIndex,RefreshRateTableIndex,
                        HwDeviceExtension);
   temp=(UCHAR)(offset&0xFF);
@@ -1247,7 +1252,7 @@
 {
   USHORT temp,colordepth;
   USHORT modeinfo,index,infoflag;
-  USHORT ColorDepth[]={0x02,0x04,0x08};  /* TWB: Was 1,2,4 */
+  USHORT ColorDepth[]={0x02,0x04,0x08};  /* TW: Was 1,2,4 */
 
   modeinfo = SiS_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
   infoflag = SiS_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
@@ -1265,6 +1270,7 @@
   colordepth=SiS_GetColorDepth(ROMAddr,ModeNo,ModeIdIndex);
 
   if((ModeNo>=0x7C)&&(ModeNo<=0x7E)) {
+  	/* TW: For 1280x960 */
     	temp=ModeNo-0x7C;
     	colordepth=ColorDepth[temp];
     	temp=0x6B;
@@ -1323,8 +1329,8 @@
 {
   USHORT temp,index;
   USHORT modeidindex,refreshratetableindex;
-  USHORT VCLK,MCLK,colorth=0,data,data2;
-  ULONG eax;
+  USHORT VCLK,MCLK,colorth=0,data2;
+  ULONG  data,eax;
   UCHAR  LatencyFactor[] ={
   	97, 88, 86, 79, 77, 00,       /*; 64  bit    BQ=2   */
         00, 87, 85, 78, 76, 54,       /*; 64  bit    BQ=1   */
@@ -1348,20 +1354,15 @@
     MCLK=SiS_MCLKData[index].CLOCK;           /* Get MCLK  */
     data2=SiS_ModeType-0x02;
     switch (data2) {
-      case 0 : 	colorth=1;
-      		break;
-      case 1 : 	colorth=1;
-      		break;
-      case 2 : 	colorth=2;
-      		break;
-      case 3 : 	colorth=2;
-      		break;
-      case 4 : 	colorth=3;
-      		break;
-      case 5 : 	colorth=4;
-      		break;
+      case 0 : 	colorth=1; break;
+      case 1 : 	colorth=1; break;
+      case 2 : 	colorth=2; break;
+      case 3 : 	colorth=2; break;
+      case 4 : 	colorth=3; break;
+      case 5 : 	colorth=4; break;
     }
-    data2=(data2*VCLK)/MCLK;     /*  bx */
+    /* data2=(data2*VCLK)/MCLK;   */  /*  bx */
+    data2=(colorth*VCLK)/MCLK;  /* TW */
 
     temp = SiS_GetReg1(SiS_P3c4,0x14);
     temp = ((temp&0x00FF)>>6)<<1;
@@ -1369,17 +1370,24 @@
     temp=temp<<2;
 
     data2=temp-data2;
-    if(data2%(28*16)) {
-      data2=data2/(28*16);
-      data2++;
-    }
-    else {
-      data2=data2/(28*16);
+
+/*  if(data2%(28*16)) {		 TW: WRONG
+      	data2=data2/(28*16);
+      	data2++;
+    } else {
+      	data2=data2/(28*16);
+    } */
+    if((28*16)%data2) {		/* TW */
+      	data2=(28*16)/data2;
+      	data2++;
+    } else {
+      	data2=(28*16)/data2;
     }
 
     index=0;
     temp = SiS_GetReg1(SiS_P3c4,0x14);
     if(temp&0x0080) index=index+12;
+
     SiS_SetReg4(0xcf8,0x800000A0);
     eax=SiS_GetReg3(0xcfc);
     temp=(USHORT)(eax>>24);
@@ -1389,32 +1397,55 @@
     eax=SiS_GetReg3(0xcfc);
     temp=(USHORT)(eax>>24);
     if(temp&0x01) index=index+6;
+
     temp=(temp&0x0F)>>1;
     index=index+temp;
     data=LatencyFactor[index];
     data=data+15;
     temp = SiS_GetReg1(SiS_P3c4,0x14);
     if(!(temp&0x80)) data=data+5;
+
     data=data+data2;
 
     SiS_SetFlag=SiS_SetFlag|ProgrammingCRT2;
     data=data*VCLK*colorth;
     if(data%(MCLK<<4)) {
-      data=data/(MCLK<<4);
-      data++;
-    }
-    else {
-      data=data/(MCLK<<4);
+      	data=data/(MCLK<<4);
+      	data++;
+    } else {
+      	data=data/(MCLK<<4);
     }
 
-/* TW: The following makes all the calculations above void... */
+/* TW: The following made all the calculations above void... */
 
+#if 0
     temp=0x16;
 /*  Revision ID  */
     temp=0x13;
 /*  Revision ID  */
     SiS_SetRegANDOR(SiS_Part1Port,0x01,~0x01F,temp);
     SiS_SetRegANDOR(SiS_Part1Port,0x02,~0x01F,temp);
+#endif
+
+   /* TW: We do this instead: */
+
+   temp = SiS_GetReg1(SiS_Part1Port,0x01);
+   if( (HwDeviceExtension->jChipType == SIS_630 ) &&
+	    ((HwDeviceExtension->jChipRevision & 0xf0) == 0x30) ) /* 630s */
+   {
+	temp = (temp & (~0x1F)) | 0x1b;  	/* TW: VESA sets 1b, prev. 0x19 */
+   } else {
+	temp = (temp & (~0x1F)) | 0x16;
+   }
+   SiS_SetReg1(SiS_Part1Port,0x01,temp);  	/* FIFO HIGH? */
+
+   if(data <= 6) data = 6;
+   if(data > 0x14) data = 0x14;
+   if (SiS_IF_DEF_LVDS==1) {			/* TW: LVDS doesn't like 0x14 */
+	if(data > 0x13) data = 0x13;
+   }
+   SiS_SetRegANDOR(SiS_Part1Port,0x02,~0x01F,data);  /* FIFO LOW? */
+  /* TW end */
   }
 }
 
@@ -1453,16 +1484,16 @@
 
   temp=SiS_GetReg1(SiS_P3c4,0x14);
   if (temp&0x02)
-   temp=16;
+   	temp=16;
   else
-    temp=8;
+    	temp=8;
 
   temp = temp - temp1*temp2/temp3; /* 16-DRamBus - DCLK*BytePerPixel/MCLK */
 
   if ((52*16 % temp)==0)
-    temp = 52*16/temp +40;
+    	temp = 52*16/temp +40;
   else
-    temp = 52*16/temp +40 + 1;
+    	temp = 52*16/temp +40 + 1;
 
   /* get DRAM latency */
   temp1=(SiS_GetReg1(SiS_P3c4,0x17)>>3)&0x7; /* SR17[5:3] DRAM Queue depth */
@@ -1493,7 +1524,6 @@
 
   temp +=  temp3; /* CRT1 Request Period */
 
-
   CRT2ModeNo = ModeNo; /* get CRT2 ModeNo */
   SiS_SearchModeID(ROMAddr,CRT2ModeNo,&ModeIdIndex);    /* Get ModeID Table */
   SiS_SetFlag=SiS_SetFlag|ProgrammingCRT2;
@@ -1510,7 +1540,7 @@
   temp3=SiS_MCLKData[index].CLOCK;           /* Get MCLK  */
  
   if ((temp*temp1*temp2)%(16*temp3)==0)
-    temp = temp*temp1*temp2/(16*temp3); /* CRT1 Request period * TCLK*BytePerPixel/(MCLK*16) */
+    temp = temp*temp1*temp2/(16*temp3);   /* CRT1 Request period * TCLK*BytePerPixel/(MCLK*16) */
   else 
     temp = temp*temp1*temp2/(16*temp3)+1; /* CRT1 Request period * TCLK*BytePerPixel/(MCLK*16) */
 
@@ -1528,11 +1558,8 @@
   USHORT PanelIndex,ResIndex;
   SiS_LVDSDesStruct  *PanelDesPtr=NULL;
 
-  /* TW: added LVDS check - but this seems wrong; LVDS is possibly 1 even for
-   *     301B et al
-   */
-  if( /* (SiS_IF_DEF_LVDS==0) && */
-      (SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV))) {  /*301b*//*for test*/
+  if((SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV))
+       && (SiS_IF_DEF_LVDS == 0) ) {  /*301b*//*for test*/
      SiS_GetLVDSDesPtrA(ROMAddr,ModeNo,ModeIdIndex,RefreshRateTableIndex,
                         &PanelIndex,&ResIndex);
      switch (PanelIndex)
@@ -1548,7 +1575,8 @@
      SiS_GetLVDSDesPtr(ROMAddr,ModeNo,ModeIdIndex,RefreshRateTableIndex,
                        &PanelIndex,&ResIndex);
 #ifdef LINUX_KERNEL
-     printk(KERN_INFO "sisfb: LVDS-LCD panel type %d (Resindex %d)\n", PanelIndex, ResIndex);
+     if (PanelIndex < 32)	/* >=32 = TV */
+         printk(KERN_INFO "sisfb: LVDS-LCD panel type %d (Resindex %d)\n", PanelIndex, ResIndex);
 #endif
      switch (PanelIndex)
      {
@@ -1566,7 +1594,7 @@
      	case 11: PanelDesPtr = SiS_PanelType0b_1;   break;
      	case 12: PanelDesPtr = SiS_PanelType0c_1;   break;	/* TW: Clevo 2202   */
      	case 13: PanelDesPtr = SiS_PanelType0d_1;   break;
-     	case 14: PanelDesPtr = SiS_PanelType0e_1;   break;	/* TW: Uniwill 5002 */
+     	case 14: PanelDesPtr = SiS_PanelType0e_1;   break;	/* TW: Uniwill N271S2 */
      	case 15: PanelDesPtr = SiS_PanelType0f_1;   break;
      	case 16: PanelDesPtr = SiS_PanelType00_2;   break;
      	case 17: PanelDesPtr = SiS_PanelType01_2;   break;
@@ -1592,9 +1620,6 @@
   }
   SiS_LCDHDES = (PanelDesPtr+ResIndex)->LCDHDES;
   SiS_LCDVDES = (PanelDesPtr+ResIndex)->LCDVDES;
-#ifdef LINUX_KERNEL
-  printk(KERN_INFO "sisfb: LCDHDES=0x%x LCDVDES=0x%x\n", SiS_LCDHDES, SiS_LCDVDES);
-#endif
 
   if(SiS_LCDInfo&LCDNonExpanding){
     if(SiS_LCDResInfo>=Panel1024x768){
@@ -1646,19 +1671,17 @@
                    USHORT RefreshRateTableIndex,USHORT *PanelIndex,
 		   USHORT *ResIndex)
 {
-  USHORT tempbx,tempal;
+  USHORT tempbx=0,tempal;
 
-  tempbx=0;
-      tempbx=SiS_LCDResInfo;
-      tempbx=tempbx-Panel1024x768;
-    if(SiS_LCDInfo&LCDNonExpanding){
+  tempbx=SiS_LCDResInfo-Panel1024x768;
+  if(SiS_LCDInfo&LCDNonExpanding){
       tempbx=tempbx+3;
-    }
- 
+  }
+
   if(ModeNo<=0x13){
-    tempal = SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
-  }else{
-    tempal = SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
+    	tempal = SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
+  } else {
+    	tempal = SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
   }
   tempal=tempal&0x1F;
   *PanelIndex=tempbx;
@@ -1666,7 +1689,6 @@
 }
 /*end 301b*/
 
-/* TW: check for 8bpp bug */
 void
 SiS_SetCRT2ModeRegs(USHORT BaseAddr,USHORT ModeNo,
                     PSIS_HW_DEVICE_INFO HwDeviceExtension)
@@ -1676,16 +1698,16 @@
 
   SiS_SetReg1(SiS_Part1Port,0x03,0x00);   /*fix write part1 index 0  BTDRAM bit Bug*/
 
-  /*301b*/ /* TW: added LVDS check */
+  /*301b*/
   if( (SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV))
-  	/* && (SiS_IF_DEF_LVDS==0)*/ && (SiS_VBInfo&SetCRT2ToLCDA) ) {
+  				&& (SiS_VBInfo&SetCRT2ToLCDA) ) {
 
 	/* TW:   1. for 301B/302B/301LV/302LV (on some of which
 	 *          IF_DEF_LVDS seems to be 1 as well)
 	 */
 
-      SiS_SetRegANDOR(SiS_Part1Port,0x00,~0x050,0x40);
-      SiS_SetRegAND(SiS_Part1Port,0x2E,0xF7) ;
+      SiS_SetRegANDOR(SiS_Part1Port,0x00,~0x050,0x40); /* FUNCTION CONTROL */
+      SiS_SetRegAND(SiS_Part1Port,0x2E,0xF7);
       SiS_SetRegANDOR(SiS_Part1Port,0x13,0xFB,0x04);
       SiS_SetRegANDOR(SiS_Part1Port,0x2c,0xCF,0x30);
       SiS_SetRegANDOR(SiS_Part4Port,0x21,0x3F,0xC0);
@@ -1729,7 +1751,7 @@
     if(SiS_VBInfo&CRT2DisplayFlag){
       	tempah=0;
     }
-    SiS_SetReg1(SiS_Part1Port,0x00,tempah);  /* <------------------- */
+    SiS_SetReg1(SiS_Part1Port,0x00,tempah);  /* FUNCTION CONTROL */
 
     if(SiS_IF_DEF_LVDS==0) {    /* ifdef 301*/
 
@@ -1817,21 +1839,18 @@
     	/* TW: 3. for LVDS, _not_ 301B/302B/301LV/302LV */
 
     	tempah=0;
-#if 1  /* TW6 */
+
     	if((!(SiS_VBInfo&SetInSlaveMode)) &&
           	    (ModeNo!=0x2e)&&(ModeNo!=0x30)&&(ModeNo!=0x38)&&(ModeNo!=0x3A)) {
-#else
-	if(!(SiS_VBInfo&SetInSlaveMode)) {  /* TW: 2test - no effect */
-#endif
       			tempah=tempah|0x02;
     	}
     	SiS_SetRegANDOR(SiS_Part1Port,0x2e,0xF0,tempah); /* <------------------- */
     }
   }
 
-  /*301b*/	/* TW: added LVDS test */
+  /*301b*/
   if( (SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV))
- 	/* && (SiS_IF_DEF_LVDS==0) */ && (!(SiS_VBInfo&SetCRT2ToLCDA))){
+ 				&& (!(SiS_VBInfo&SetCRT2ToLCDA))){
       if(SiS_IsDualEdge(BaseAddr))
          SiS_SetRegANDOR(SiS_Part1Port,0x13,0xFB,0x00);
       else
@@ -1863,8 +1882,7 @@
           SiS_GetCRT2DataLVDS(ROMAddr,ModeNo,ModeIdIndex,RefreshRateTableIndex);
         else
           SiS_GetCRT2Data301(ROMAddr,ModeNo,ModeIdIndex,RefreshRateTableIndex);
-     }
-     else
+     } else
      	SiS_GetCRT2Data301(ROMAddr,ModeNo,ModeIdIndex,RefreshRateTableIndex);
      return;
   } else {  /* LVDS */
@@ -1946,7 +1964,7 @@
          } else if(SiS_LCDResInfo==Panel1024x768){
            tempax=1024;
            tempbx=768;
-         } else{
+         } else {
            tempax=1280;
            tempbx=1024;
          }
@@ -2225,10 +2243,9 @@
      	tempal=tempal&0x3F;
      	/*301b*/
       	if((SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV))
-             					&& (SiS_VBInfo&SetCRT2ToTV)) {
+       					&& (SiS_VBInfo&SetCRT2ToTV)) {
         	/*look*/
-      		if(tempal==0x06)
-          		tempal=0x07;
+      		if(tempal==0x06) tempal=0x07;
         }
    	/*end 301b*/
      	if((0x31<=ModeNo)&&(ModeNo<=0x35)) tempal=6;
@@ -2364,6 +2381,7 @@
 
   RefreshRateTableIndex = SiS_EModeIDTable[ModeIdIndex].REFindex;
   ModeNo = SiS_RefIndex[RefreshRateTableIndex].ModeID;
+
   i=0;
   do {
     	if (SiS_RefIndex[RefreshRateTableIndex+i].ModeID!=ModeNo) break;
@@ -2384,7 +2402,7 @@
   }
   i--;
 
-  if((SiS_SetFlag & ProgrammingCRT2)) {
+  if((SiS_SetFlag & ProgrammingCRT2) && (!(SiS_VBInfo & DisableCRT2Display))) {
     	backup_i = i;
     	if (!(SiS_AdjustCRT2Rate(ROMAddr,ModeNo,ModeIdIndex,
 	                             RefreshRateTableIndex,&i))) {
@@ -2398,6 +2416,7 @@
 #endif
 	}
   }
+
   return(RefreshRateTableIndex+i);                			/*return(0x01|(temp1<<1));   */
 }
 
@@ -2465,7 +2484,7 @@
       		}
     	}
   } else {
-  	/* TW: for LVDS ? (And which ones of the SiS bridges?) */
+  	/* TW: for LVDS (and which ones of the SiS bridges?) */
     	if(SiS_IF_DEF_CH7005==1) {
       		if(SiS_VBInfo&SetCRT2ToTV) {
         		tempax=tempax|SupportCHTV;
@@ -2604,11 +2623,19 @@
     	if(!(tempbx&DriverMode)){
       		tempbx=tempbx|SetSimuScanMode;
     	}
+	/* TW: LVDS bridge can only be slave in 8bpp modes */
+	if ((SiS_IF_DEF_LVDS==1) &&
+		(ModeNo == 0x2e || ModeNo == 0x30 ||
+			ModeNo == 0x38 || ModeNo == 0x3a)) {
+		tempbx=tempbx|SetSimuScanMode|SetInSlaveMode;
+	}
+	/* TW end */
     	if(!(tempbx&SetSimuScanMode)){
       		if(tempbx&SwitchToCRT2) {
         		if(!(modeflag&CRT2Mode)) {
             			tempbx=tempbx|SetSimuScanMode;
         		}
+
       		} else {
         		if(!(SiS_BridgeIsEnable(BaseAddr,HwDeviceExtension))) {
           			if(!(tempbx&DriverMode)) {
@@ -2687,7 +2714,10 @@
   }
   SiS_VBInfo=tempbx;
 #ifdef LINUX_KERNEL
-  printk(KERN_INFO "sisfb: VBInfo = %x\n", SiS_VBInfo);
+  printk(KERN_INFO "sisfb: (VBInfo = %x)\n", SiS_VBInfo);
+#endif
+#ifdef LINUX_XF86
+  xf86DrvMsg(0, X_INFO, "(init301.c: VBInfo = %x)\n", SiS_VBInfo);
 #endif
 }
 
@@ -2711,7 +2741,7 @@
     	temp1=SiS_StandTable[StandTableIndex].CRTC[7];
   } else {
     if( (SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV))
-        && (SiS_VBInfo&SetCRT2ToLCDA) ) {
+        			&& (SiS_VBInfo&SetCRT2ToLCDA) ) {
     	/*add crt1ptr*/
     	temp=SiS_GetLVDSCRT1Ptr(ROMAddr,ModeNo,ModeIdIndex,
 			RefreshRateTableIndex,&ResInfo,&DisplayType);
@@ -2808,32 +2838,30 @@
 
   SiS_SetRegANDOR(SiS_P3c4,0x11,0xF7,0x08);
 
-/*SetPanelDelay(1);  */
-  temp1=0x01;  /* TW: added LVDS check */
-  if( (SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV))
-  	/* && (SiS_IF_DEF_LVDS==0) */ )  {  /*301b*/
+  /*SetPanelDelay(1); */
+  temp1=0x01;
+  if( (SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV)))  {  /*301b*/
     	if((SiS_IsVAMode(BaseAddr)))
-       		temp1=0x00 ;			/*no disable vb*/
+       		temp1=0x00;			/*no disable vb*/
   }
 
   if(SiS_IF_DEF_LVDS==0) {
-   if(!temp1){              /*301b*/
+   if(!(temp1)){              /*301b*/
     SiS_SetRegANDOR(SiS_Part2Port,0x00,0x0DF,0x00);   /* disable VB */
     SiS_DisplayOff();
-    if(HwDeviceExtension->jChipType >= SIS_315H) /* 310 series */
-    {
-      SiS_SetRegOR(SiS_Part1Port,0x00,0x80);  /* alan,BScreenOff */
+    if(HwDeviceExtension->jChipType >= SIS_315H) { /* 310 series */
+      SiS_SetRegOR(SiS_Part1Port,0x00,0x80);  /* FUNCTION CTRL | alan,BScreenOff */
     }
     SiS_SetRegANDOR(SiS_P3c4,0x32,0xDF,0x00);
     
     temp = SiS_GetReg1(SiS_Part1Port,0); 
-    SiS_SetRegOR(SiS_Part1Port,0x00,0x10);  /* alan,BScreenOff */
+    SiS_SetRegOR(SiS_Part1Port,0x00,0x10);  /* FUNCTION CTRL | alan,BScreenOff */
 /*
      if(HwDeviceExtension->jChipType >= SIS_315H)
      {
-      SiS_SetRegAND(SiS_Part1Port,0x2E,0x7F);  
+      	SiS_SetRegAND(SiS_Part1Port,0x2E,0x7F);
      }
-     */
+*/
      SiS_SetRegANDOR(SiS_P3c4,0x1E,0xDF,0x00);
      SiS_SetReg1(SiS_Part1Port,0,temp);
     }
@@ -2854,16 +2882,17 @@
     }
   }
   else { /* LVDS */
-    if(SiS_IF_DEF_CH7005) {
+    if(SiS_IF_DEF_CH7005==1) {
+      SiS_Backup7005 = SiS_GetCH7005(0x0e);
       SiS_SetCH7005(0x090E);
     }
     SiS_DisplayOff();
     SiS_SetRegANDOR(SiS_P3c4,0x32,0xDF,0x00);
     SiS_SetRegANDOR(SiS_P3c4,0x1E,0xDF,0x00);
     SiS_UnLockCRT2(HwDeviceExtension,BaseAddr);
-    SiS_SetRegANDOR(SiS_Part1Port,0x01,0xFF,0x80); /* TW: removed - TW9 &&& */
+    SiS_SetRegANDOR(SiS_Part1Port,0x01,0xFF,0x80);
     SiS_SetRegANDOR(SiS_Part1Port,0x02,0xFF,0x40);
-   }
+  }
   /*SetPanelDelay(0);  */
   SiS_SetRegANDOR(SiS_P3c4,0x11,0xFB,0x04);
 }
@@ -2891,20 +2920,19 @@
       }
       SiS_SetReg1(SiS_P3c4,0x32,temp);
       SiS_SetRegANDOR(SiS_P3c4,0x1E,0xFF,0x20);
-      if(HwDeviceExtension->jChipType >= SIS_315H) /* 310 series */
-      {
+
+      if(HwDeviceExtension->jChipType >= SIS_315H) { /* 310 series */
         temp=SiS_GetReg1(SiS_Part1Port,0x2E);
         if (!(temp&0x80))
           SiS_SetRegOR(SiS_Part1Port,0x2E,0x80);          /* by alan,BVBDOENABLE=1 */
-  
       }
+
       SiS_SetRegANDOR(SiS_Part2Port,0x00,0x1F,0x20);
-    
-      if(HwDeviceExtension->jChipType >= SIS_315H) /* 310 series */
-      {
-      temp=SiS_GetReg1(SiS_Part1Port,0x2E);
-      if (!(temp&0x80))
-        SiS_SetRegOR(SiS_Part1Port,0x2E,0x80);          /* by alan,BVBDOENABLE=1 */
+
+      if(HwDeviceExtension->jChipType >= SIS_315H) { /* 310 series */
+      	temp=SiS_GetReg1(SiS_Part1Port,0x2E);
+     	if (!(temp&0x80))
+            SiS_SetRegOR(SiS_Part1Port,0x2E,0x80);          /* by alan,BVBDOENABLE=1 */
       }
    
       SiS_SetRegANDOR(SiS_Part2Port,0x00,0x1F,0x20);
@@ -2917,14 +2945,14 @@
       if(!(SiS_Is301B(BaseAddr))){  
         temp=SiS_GetReg1(SiS_Part1Port,0x2E);
         if(!(temp&0x80))
-          SiS_SetRegOR(SiS_Part1Port,0x2E,0x80);     
+           SiS_SetRegOR(SiS_Part1Port,0x2E,0x80);
         if((!(SiS_IsDualEdge(BaseAddr)))&&(!(SiS_IsVAMode(BaseAddr))))
-        tempah=0x80;
+           tempah=0x80;
         else if((!(SiS_IsDualEdge(BaseAddr)))&&(SiS_IsVAMode(BaseAddr)))
-        tempah=0x40;
+           tempah=0x40;
         else
-        tempah=0xC0;
-        SiS_SetRegOR(SiS_Part4Port,0x1F,tempah);           
+           tempah=0xC0;
+        SiS_SetRegOR(SiS_Part4Port,0x1F,tempah);
       }
      }  
   /*end 301b*/
@@ -2935,15 +2963,17 @@
     SiS_SetRegANDOR(SiS_Part1Port,0x02,0xBF,0x00);
     if(SiS_BridgeInSlave()) {
       	SiS_SetRegANDOR(SiS_Part1Port,0x01,0x1F,0x00);
-    }
-    else {
+    } else {
       	SiS_SetRegANDOR(SiS_Part1Port,0x01,0x1F,0x40);
     }
     if(SiS_IF_DEF_CH7005) {
-      	SiS_SetCH7005(0x0B0E);
+        if (SiS_Backup7005 != 0xff) {
+		SiS_SetCH7005(((SiS_Backup7005<<8)|0x0E));
+		SiS_Backup7005 = 0xff;
+	} else SiS_SetCH7005(0x0B0E);
     }
   }
-/*SetPanelDelay(1);  */
+  /*SetPanelDelay(1);  */
   SiS_SetRegANDOR(SiS_P3c4,0x11,0xF7,0x00);
 }
 
@@ -3125,9 +3155,13 @@
   SiS_LCDInfo=temp;
 
 #ifdef LINUX_KERNEL
-  printk(KERN_INFO "sisfb: LCDInfo = 0x%x LCDResInfo = 0x%x LCDTypeInfo = 0x%x\n",
+  printk(KERN_INFO "sisfb: (LCDInfo = 0x%x LCDResInfo = 0x%x LCDTypeInfo = 0x%x)\n",
                    SiS_LCDInfo, SiS_LCDResInfo, SiS_LCDTypeInfo);
 #endif
+#ifdef LINUX_XF86
+  xf86DrvMsg(0, X_INFO, "(init301.c: LCDInfo = 0x%x LCDResInfo = 0x%x LCDTypeInfo = 0x%x)\n",
+			SiS_LCDInfo, SiS_LCDResInfo, SiS_LCDTypeInfo);
+#endif
 
   if(SiS_IF_DEF_LVDS==1){
      if(modeflag&HalfDCLK){
@@ -3213,8 +3247,7 @@
           if(!(tempal&0x08)) {
             break;
           }
-        }
-        else {                 /* VBWaitMode1  */
+        } else {                 /* VBWaitMode1  */
           if(!(tempal&0x08)) {
             continue;
           }
@@ -3225,8 +3258,7 @@
       }
       temp=temp^0x01;
     }
-  }
-  else {
+  } else {
     SiS_LongWait();
   }
   return;
@@ -3239,7 +3271,7 @@
 
 return 0;
 
-  temp=SiS_GetReg1(SiS_Part1Port,0x00);
+  temp=SiS_GetReg1(SiS_Part1Port,0x00); /* FUNCTION CTRL */
   if(!(temp&0x80)){
     return 0;
   }
@@ -3285,7 +3317,7 @@
 }
 
 void
-SiS_SetGroup2(USHORT  BaseAddr,ULONG ROMAddr, USHORT ModeNo,
+SiS_SetGroup2(USHORT BaseAddr,ULONG ROMAddr, USHORT ModeNo,
                    USHORT ModeIdIndex,USHORT RefreshRateTableIndex,
 		   PSIS_HW_DEVICE_INFO HwDeviceExtension)
 {
@@ -3327,10 +3359,8 @@
         if(modeflag&Charx8Dot) TimingPoint = SiS_HiTVSt1Timing;
         else TimingPoint = SiS_HiTVTextTiming;
       }
-    }
-    else  TimingPoint = SiS_HiTVExtTiming;
-  }
-  else {
+    } else TimingPoint = SiS_HiTVExtTiming;
+  } else {
     if(SiS_VBInfo&SetPALTV){
       if(SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV))
          PhasePoint = SiS_PALPhase2;              /* PALPhase */
@@ -3338,8 +3368,7 @@
          PhasePoint = SiS_PALPhase;  
      
          TimingPoint = SiS_PALTiming;
-    }
-    else{
+    } else {
         temp=temp|0x10;
         if(SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV))
         	PhasePoint = SiS_NTSCPhase2;             /* PALPhase */
@@ -3349,7 +3378,7 @@
         TimingPoint = SiS_NTSCTiming;
     }
   }
-  SiS_SetReg1(SiS_Part2Port,0x0,temp);
+  SiS_SetReg1(SiS_Part2Port,0x00,temp);
 
 #ifdef SIS300
   /*add PALMN*/
@@ -3361,7 +3390,7 @@
              if(temp) {
                   temp1=SiS_GetReg1(SiS_P3d4,0x35);        
                   temp1=temp1&0x40; 
-                   if(temp1)
+                  if(temp1)
                      	PhasePoint = SiS_PALMPhase;
                   temp1=SiS_GetReg1(SiS_P3d4,0x35);        
                   temp1=temp1&0x80;
@@ -3381,20 +3410,20 @@
        (HwDeviceExtension->jChipType==SIS_640) ||
        (HwDeviceExtension->jChipType==SIS_740) ||
        (HwDeviceExtension->jChipType==SIS_650)) {
-            if(SiS_VBInfo&SetCRT2ToTV) {
-             temp=SiS_GetReg1(SiS_P3d4,0x31);   
-             temp=temp&0x01; 
+           if(SiS_VBInfo&SetCRT2ToTV) {
+              temp=SiS_GetReg1(SiS_P3d4,0x31);
+              temp=temp&0x01;
               if(temp) {
-                  temp1=SiS_GetReg1(SiS_P3d4,0x38);        
-                  temp1=temp1&0x40; 
-                   if(temp1)
-                     PhasePoint = SiS_PALMPhase;        
-                  temp1=SiS_GetReg1(SiS_P3d4,0x38);        
+                  temp1=SiS_GetReg1(SiS_P3d4,0x38);
+                  temp1=temp1&0x40;
+                  if(temp1)
+                     PhasePoint = SiS_PALMPhase;
+                  temp1=SiS_GetReg1(SiS_P3d4,0x38);
                   temp1=temp1&0x80;
-                   if(temp1)
-                     PhasePoint = SiS_PALNPhase;           
-                }    
-             }
+                  if(temp1)
+                     PhasePoint = SiS_PALNPhase;
+              }
+           }
   }
   /*end add*/
 #endif
@@ -3421,17 +3450,17 @@
   SiS_SetReg1(SiS_Part2Port,0x48,SiS_RY2COE);
   SiS_SetReg1(SiS_Part2Port,0x49,SiS_RY3COE);
   SiS_SetReg1(SiS_Part2Port,0x4a,SiS_RY4COE);
-/*add to change 630+301b filter*/
 
-    resindex=SiS_GetResInfo(ROMAddr,ModeNo,ModeIdIndex);
-    if(ModeNo<=0x13){
+  /*add to change 630+301b filter*/
+  resindex=SiS_GetResInfo(ROMAddr,ModeNo,ModeIdIndex);
+  if(ModeNo<=0x13) {
       xres=SiS_StResInfo[resindex].HTotal;
-    }else{
+  } else {
       xres=SiS_ModeResInfo[resindex].HTotal;                         /* xres->ax */
-    }
+  }
   if(xres==640){SiS_RY1COE=0xFF;SiS_RY2COE=0x03;SiS_RY3COE=0x02;SiS_RY4COE=0xF6;
                          SiS_RY5COE=0xFC;SiS_RY6COE=0x27;SiS_RY7COE=0x46;}
- if(xres==800){SiS_RY1COE=0x01;SiS_RY2COE=0x01;SiS_RY3COE=0xFC;SiS_RY4COE=0xF8;
+  if(xres==800){SiS_RY1COE=0x01;SiS_RY2COE=0x01;SiS_RY3COE=0xFC;SiS_RY4COE=0xF8;
                          SiS_RY5COE=0x08;SiS_RY6COE=0x26;SiS_RY7COE=0x38;}                        
   if(xres==1024){SiS_RY1COE=0xFF;SiS_RY2COE=0xFF;SiS_RY3COE=0xFC;SiS_RY4COE=0x00;
                          SiS_RY5COE=0x0F;SiS_RY6COE=0x22;SiS_RY7COE=0x28;}
@@ -3444,8 +3473,7 @@
   SiS_SetReg1(SiS_Part2Port,0x48,SiS_RY5COE);
   SiS_SetReg1(SiS_Part2Port,0x49,SiS_RY6COE);
   SiS_SetReg1(SiS_Part2Port,0x4a,SiS_RY7COE);
- 
-/*end add*/  
+  /*end add*/
 
   if(SiS_VBInfo&SetCRT2ToHiVisionTV) tempax=950;
   else {
@@ -3468,20 +3496,17 @@
   /*301b*/
   if( (SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV))
         && (SiS_VBInfo&SetCRT2ToTV) && (SiS_VGAHDE==1024) ) {
-      if(SiS_VBInfo&SetPALTV)
-      {     
+      if(SiS_VBInfo&SetPALTV) {
        SiS_SetReg1(SiS_Part2Port,0x01,0x19);
        SiS_SetReg1(SiS_Part2Port,0x02,0x52);
-       }  
-      else
-      {
-      SiS_SetReg1(SiS_Part2Port,0x01,0x0B);
-      SiS_SetReg1(SiS_Part2Port,0x02,0x11);
+      } else {
+       SiS_SetReg1(SiS_Part2Port,0x01,0x0B);
+       SiS_SetReg1(SiS_Part2Port,0x02,0x11);
       } 
     }
     
   tempcx=SiS_HT-1;
-   /*301b*/
+  /*301b*/
   if(SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV)) {
      tempcx=tempcx-1;   
   }
@@ -3547,7 +3572,7 @@
     tempcx=tempax-1;
   }
   temp=tempcx&0x00FF;
-  SiS_SetReg1(SiS_Part2Port,0x2E,temp);
+  SiS_SetReg1(SiS_Part2Port,0x2E,temp);	/* TW: BIOS 0x48, here 0x3f @@@ */
 
   tempbx=SiS_VDE;
   if(SiS_VGAVDE==360) tempbx=746;
@@ -3573,8 +3598,9 @@
       temp=temp|0x20;
     }
   }
-  SiS_SetReg1(SiS_Part2Port,0x30,temp);
- /*301b*/
+  SiS_SetReg1(SiS_Part2Port,0x30,temp);  /* TW: BIOS sets 0xb8, here (or somewhere else) 0xb5 */
+
+  /*301b*/
   if(SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV)) {      /*tv gatingno*/
     tempbx=SiS_VDE;
     if(SiS_VBInfo&SetCRT2ToTV) {
@@ -3628,76 +3654,74 @@
     if(temp2!=0){
       tempeax=tempeax+1;
     }
-     tempax=(USHORT)tempeax;
-     /*301b*/
-     if(SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV)) {
+    tempax=(USHORT)tempeax;
+    /*301b*/
+    if(SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV)) {
      	tempcx=((tempax&0xFF00)>>5)>>8;
-     }
+    }
     /*end 301b*/
     tempbx=push1;
     tempbx=(USHORT) ( ((tempeax&0x0000FF00)&0x1F00)|(tempbx&0x00FF) );
     tempax=(USHORT) ( ((tempeax&0x000000FF)<<8)|(tempax&0x00FF) );
     temp=(tempax&0xFF00)>>8;
-  }
-  else {
+  } else {
     temp=(tempax&0x00FF)>>8;
   }
   SiS_SetReg1(SiS_Part2Port,0x44,temp);
   temp=(tempbx&0xFF00)>>8;
   SiS_SetRegANDOR(SiS_Part2Port,0x45,~0x03F,temp);
   /*301b*/
-      if(SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV)) {
+  if(SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV)) {
        if((tempcx&0x00FF)==0x01)
     		tempcx=0x00;
        SiS_SetRegANDOR(SiS_Part2Port,0x46,~0x007,tempcx);
        SiS_SetRegOR(SiS_Part2Port,0x46,0x18);
-               if(SiS_VBInfo&SetPALTV){
+               if(SiS_VBInfo&SetPALTV) {
                    tempbx=0x0364;
-                   tempcx=0x009c; 
-                }
-               else{
+                   tempcx=0x009c;
+               } else {
                    tempbx=0x0346;
                    tempcx=0x0078;
-                } 
-       temp=(tempbx&0x00FF) ;        
-       SiS_SetReg1(SiS_Part2Port,0x4B,temp);         
+               }
+       temp=(tempbx&0x00FF) ;
+       SiS_SetReg1(SiS_Part2Port,0x4B,temp);
        temp=(tempcx&0x00FF) ;
-       SiS_SetReg1(SiS_Part2Port,0x4C,temp);         
-       tempbx=(tempbx&0x0300); 
+       SiS_SetReg1(SiS_Part2Port,0x4C,temp);
+       tempbx=(tempbx&0x0300);
        temp=(tempcx&0xFF00)>>8 ;
        temp=(temp&0x0003)<<2;
        temp=temp|(tempbx>>8);
-       SiS_SetReg1(SiS_Part2Port,0x4D,temp);  
-       
+       SiS_SetReg1(SiS_Part2Port,0x4D,temp);
+
        temp=SiS_GetReg1(SiS_Part2Port,0x43); /*301b change */
-       SiS_SetReg1(SiS_Part2Port,0x43,(USHORT)(temp-3));  
-      }
-/*end 301b*/        
+       SiS_SetReg1(SiS_Part2Port,0x43,(USHORT)(temp-3));
+  }
+  /*end 301b*/
 
 #ifdef SIS300
-/*add PALMN*/
+  /*add PALMN*/
   if((HwDeviceExtension->jChipType==SIS_630)||
      (HwDeviceExtension->jChipType==SIS_730)) {
-           if(SiS_VBInfo&SetCRT2ToTV) {
-             temp=SiS_GetReg1(SiS_P3d4,0x31);   
-             temp=temp&0x01; 
-              if(temp) {
-                  temp1=SiS_GetReg1(SiS_P3d4,0x35);        
-                  temp1=temp1&0x40; 
-                   if(temp1){
+          if(SiS_VBInfo&SetCRT2ToTV) {
+             temp=SiS_GetReg1(SiS_P3d4,0x31);
+             temp=temp&0x01;
+             if(temp) {
+                  temp1=SiS_GetReg1(SiS_P3d4,0x35);
+                  temp1=temp1&0x40;
+                  if(temp1){
                            SiS_SetRegANDOR(SiS_Part2Port,0x00,0xEF,0x00);
                            temp3=SiS_GetReg1(SiS_Part2Port,0x01);
                            temp3=temp3-1;
-                           SiS_SetReg1(SiS_Part2Port,0x01,temp3);  
-                }    
+                           SiS_SetReg1(SiS_Part2Port,0x01,temp3);
+                  }
              }
-          } 
-      }	
-    /*end add*/
+          }
+  }
+  /*end add*/
 #endif
 
 #ifdef SIS315H
-/*add PALMN*/
+  /*add PALMN*/
   if ( (HwDeviceExtension->jChipType==SIS_315H)||
        (HwDeviceExtension->jChipType==SIS_315PRO)||
        (HwDeviceExtension->jChipType==SIS_550) ||
@@ -3706,7 +3730,7 @@
        (HwDeviceExtension->jChipType==SIS_650)) {
         	if(SiS_VBInfo&SetCRT2ToTV) {
              		temp=SiS_GetReg1(SiS_P3d4,0x31);
-            		 temp=temp&0x01;
+            		temp=temp&0x01;
               		if(temp) {
                   		temp1=SiS_GetReg1(SiS_P3d4,0x38);
                  		temp1=temp1&0x40;
@@ -3731,6 +3755,8 @@
     return;
   }
 
+  /* TW: From here: LCD Part2 group */
+
   tempbx=SiS_HDE-1;         /* RHACTE=HDE-1 */
   temp=tempbx&0x00FF;
   SiS_SetReg1(SiS_Part2Port,0x2C,temp);
@@ -3781,15 +3807,15 @@
   if(SiS_LCDResInfo!=Panel1024x768) {
     tempbx=1024;
     if(SiS_LCDResInfo!=Panel1280x1024) {
-        tempbx=1200;     /*301b */
+         tempbx=1200;     /*301b */
          if(SiS_LCDResInfo!=Panel1600x1200) {
             if(tempbx!=SiS_VDE) {
                tempbx=960;
-      }
+            }
+         }
     }
   }
- }
-   if(SiS_LCDInfo&LCDNonExpanding) {
+  if(SiS_LCDInfo&LCDNonExpanding) {
     tempbx=SiS_VDE;
     tempbx--;
     tempcx--;
@@ -3801,16 +3827,14 @@
       if(tempax<SiS_VDE) {
         tempax=0;
         tempcx=0;
-      }
-      else {
+      } else {
         tempax=tempax-SiS_VDE;
       }
       tempax=tempax>>1;
     }
     tempcx=tempcx-tempax; /* lcdvdes */
     tempbx=tempbx-tempax; /* lcdvdee */
-  }
-  else {
+  } else {
     tempax=tempax>>1;
     tempcx=tempcx-tempax; /* lcdvdes */
     tempbx=tempbx-tempax; /* lcdvdee */
@@ -3821,23 +3845,43 @@
   temp=tempbx&0x00FF;   /* RVEQ2EQ=lcdvdee */
   SiS_SetReg1(SiS_Part2Port,0x06,temp);
 
-  temp=(tempbx&0xFF00)>>8;
-  temp=temp<<3;
-  temp=temp|((tempcx&0xFF00)>>8);
-  SiS_SetReg1(SiS_Part2Port,0x02,temp);
+  /* TW new @@@ */
+  if(SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV)) {
+        /* TW: BIOS sets Part2 0x02 to 0x18. The old caluculation (in else statement)
+	 *     resulted in 0x13. Do it this way for 301B?
+	 */
+        temp=(((tempcx&0xFF00)>>8)<<3);   /* 0x325 & ff00 = 300 >> 8 = 3 << 3 = 0x18 */
+	SiS_SetReg1(SiS_Part2Port,0x02,temp);
+  } else {
+  /* TW end */
+  	temp=(tempbx&0xFF00)>>8;
+  	temp=temp<<3;
+  	temp=temp|((tempcx&0xFF00)>>8);
+  	SiS_SetReg1(SiS_Part2Port,0x02,temp);
+  }
 
-  tempbx=push2;
-  tempax=push1;
+  tempbx=push2;  	/* SiS_VT = 0x326  - - - (TW DEBUG REMARKS)*/
+  tempax=push1;  	/* SiS_VDE = 0x300 */
   tempcx=tempbx;
-  tempcx=tempcx-tempax;
-  tempcx=tempcx>>4;
-  tempbx=tempbx+tempax;
-  tempbx=tempbx>>1;
+  tempcx=tempcx-tempax; /* -> 0x26 */
+  tempcx=tempcx>>4;     /* -> 0x02 */
+  tempbx=tempbx+tempax; /* -> 0x626 */
+  tempbx=tempbx>>1;     /* -> 0x313 */
   if(SiS_LCDInfo&LCDNonExpanding) {
-    tempbx=tempbx-10;
+     tempbx=tempbx-10;
+  }
+  /* TW new @@@ */
+  if(SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV)) {
+  	/* TW: BIOS sets Part2 0x04 to 0x02. The old caluculation (in else statement)
+	 *     resulted in 0x13. Do it this way for 301B?
+	 */
+        temp=tempcx&0x00FF;
+	SiS_SetReg1(SiS_Part2Port,0x04,temp);
+  } else {
+  /* TW end */
+    	temp=tempbx&0x00FF;   		/* RTVACTEE=lcdvrs */
+  	SiS_SetReg1(SiS_Part2Port,0x04,temp);   /* TW: BIOS: 0x02, here 0x13 */
   }
-  temp=tempbx&0x00FF;   /* RTVACTEE=lcdvrs */
-  SiS_SetReg1(SiS_Part2Port,0x04,temp);
 
  temp=(tempbx&0xFF00)>>8;
  temp=temp<<4;
@@ -3852,8 +3896,7 @@
          SiS_SetReg1(SiS_Part2Port,0x04,0xB9);
          SiS_SetReg1(SiS_Part2Port,0x05,0xCC);
          SiS_SetReg1(SiS_Part2Port,0x06,0xA6);
-       }
-       else {
+       } else {
          temp=crt2crtc&0x3F;
          if(temp==4) {
            SiS_SetReg1(SiS_Part2Port,0x01,0x2B);
@@ -3870,14 +3913,14 @@
  SiS_SetRegANDOR(SiS_Part2Port,0x09,0xF0,0x00);
  SiS_SetRegANDOR(SiS_Part2Port,0x0A,0xF0,0x00);
 
- tempcx=(SiS_HT-SiS_HDE)>>2;    /* (HT-HDE)>>2     */
- tempbx=(SiS_HDE+7);        /* lcdhdee         */
+ tempcx=(SiS_HT-SiS_HDE)>>2;    		/* (HT-HDE)>>2     */
+ tempbx=(SiS_HDE+7);            		/* lcdhdee         */
  /*301b*/
  if(SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV)) {
     tempbx=tempbx+2;
  }
  push1=tempbx;
- temp=tempbx&0x00FF;    /* RHEQPLE=lcdhdee */
+ temp=tempbx&0x00FF;    			/* RHEQPLE=lcdhdee */
  SiS_SetReg1(SiS_Part2Port,0x23,temp);
  temp=(tempbx&0xFF00)>>8;
  SiS_SetRegANDOR(SiS_Part2Port,0x25,~0x0F,temp);
@@ -3886,12 +3929,12 @@
  if(SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV)) {
     temp=temp+2;
  }
- SiS_SetReg1(SiS_Part2Port,0x1F,temp);  /* RHBLKE=lcdhdes */
+ SiS_SetReg1(SiS_Part2Port,0x1F,temp);  	/* RHBLKE=lcdhdes */
  SiS_SetRegANDOR(SiS_Part2Port,0x20,0x0F,0x00);
 
  tempbx=tempbx+tempcx;
  push2=tempbx;
- temp=tempbx&0xFF;            /* RHBURSTS=lcdhrs */
+ temp=tempbx&0xFF;            			/* RHBURSTS=lcdhrs */
  if(SiS_LCDResInfo==Panel1280x1024) {
    if(!(SiS_LCDInfo&LCDNonExpanding)) {
      if(SiS_HDE==1280) {
@@ -3907,7 +3950,7 @@
  tempbx=push2;
  tempcx=tempcx<<1;
  tempbx=tempbx+tempcx;
- temp=tempbx&0x00FF;            /* RHSYEXP2S=lcdhre */
+ temp=tempbx&0x00FF;            		/* RHSYEXP2S=lcdhre */
  SiS_SetReg1(SiS_Part2Port,0x21,temp);
 
  SiS_SetRegANDOR(SiS_Part2Port,0x17,0xFB,0x00);
@@ -3915,18 +3958,16 @@
 
  if(!(SiS_SetFlag&LCDVESATiming)) {
    if(SiS_VGAVDE==525) {
-    if(SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV)) {  /*301b*/
+     if(SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV))   /*301b*/
     	temp=0xC6;
-    }
-    else
+     else
        	temp=0xC4;
-     	SiS_SetReg1(SiS_Part2Port,0x2f,temp);
-     	SiS_SetReg1(SiS_Part2Port,0x30,0xB3);
-    }
+     SiS_SetReg1(SiS_Part2Port,0x2f,temp);
+     SiS_SetReg1(SiS_Part2Port,0x30,0xB3);
+   }
    if(SiS_VGAVDE==420) {
-     if(SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV)) {
+     if(SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV))
     	temp=0x4F;
-     }
      else
        	temp=0x4E;
      SiS_SetReg1(SiS_Part2Port,0x2f,temp);
@@ -3955,17 +3996,15 @@
 
   if(ModeNo<=0x13) {
     	modeflag = SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;      /* si+St_ResInfo */
-  }
-  else {
+  } else {
     	modeflag = SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;     /* si+Ext_ResInfo */
   }
 
   SiS_SetReg1(SiS_Part3Port,0x00,0x00);
-  if(SiS_VBInfo&SetPALTV){
+  if(SiS_VBInfo&SetPALTV) {
     SiS_SetReg1(SiS_Part3Port,0x13,0xFA);
     SiS_SetReg1(SiS_Part3Port,0x14,0xC8);
-  }
-  else {
+  } else {
     SiS_SetReg1(SiS_Part3Port,0x13,0xF6);
     SiS_SetReg1(SiS_Part3Port,0x14,0xBF);
   }
@@ -3974,16 +4013,16 @@
   if((HwDeviceExtension->jChipType==SIS_630)||
      (HwDeviceExtension->jChipType==SIS_730)) {
            if(SiS_VBInfo&SetCRT2ToTV) {
-             temp=SiS_GetReg1(SiS_P3d4,0x31);   
-             temp=temp&0x01; 
+              temp=SiS_GetReg1(SiS_P3d4,0x31);
+              temp=temp&0x01;
               if(temp) {
-                  temp1=SiS_GetReg1(SiS_P3d4,0x35);        
-                  temp1=temp1&0x40; 
+                  temp1=SiS_GetReg1(SiS_P3d4,0x35);
+                  temp1=temp1&0x40;
                    if(temp1){
-                          SiS_SetReg1(SiS_Part3Port,0x13,0xFA); 
-                          SiS_SetReg1(SiS_Part3Port,0x14,0xC8); 
+                          SiS_SetReg1(SiS_Part3Port,0x13,0xFA);
+                          SiS_SetReg1(SiS_Part3Port,0x14,0xC8);
                           SiS_SetReg1(SiS_Part3Port,0x3D,0xA8);
-                }    
+                }
              }
           } 
       }	
@@ -4070,21 +4109,19 @@
     tempbx=tempbx>>1;
   }
   if(tempcx&SetCRT2ToHiVisionTV) {
-    temp=0xA0;
-    if(tempbx!=1024) {
-       temp=0xC0;
-       if(tempbx!=1280) temp=0;
-    }
-  }
-  else if((tempcx&SetCRT2ToTV)&&(SiS_VGAHDE==1024)) {       /*301b*/
- temp=0xA0; 
-  }
-  else {
-    temp=0x80;
-    if(SiS_VBInfo&SetCRT2ToLCD){
-      temp=0;
-      if(tempbx>800) temp=0x60;
-    }
+       temp=0xA0;
+       if(tempbx!=1024) {
+           temp=0xC0;
+           if(tempbx!=1280) temp=0;
+       }
+  } else if((tempcx&SetCRT2ToTV)&&(SiS_VGAHDE==1024)) {       /*301b*/
+       temp=0xA0;
+  } else {
+       temp=0x80;
+       if(SiS_VBInfo&SetCRT2ToLCD){
+          temp=0;
+          if(tempbx>800) temp=0x60;
+       }
   }
   if(SiS_LCDResInfo!=Panel1280x1024) temp=temp|0x0A;
   SiS_SetRegANDOR(SiS_Part4Port,0x0E,~0xEF,temp);
@@ -4130,9 +4167,9 @@
   temp=temp<<4;
   temp=temp|((tempcx&0xFF00)>>8);
   SiS_SetReg1(SiS_Part4Port,0x19,temp);
-  /*301b*/
 
-      if(SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV)) {
+  /*301b*/
+  if(SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV)) {
          temp=0x0028;
          SiS_SetReg1(SiS_Part4Port,0x1C,temp);
          tempax=SiS_VGAHDE;
@@ -4156,30 +4193,31 @@
          }
          temp=(tempax&0xFF00)>>8;
          temp=((temp&0x0003)<<4);
-          SiS_SetReg1(SiS_Part4Port,0x1E,temp);      
+         SiS_SetReg1(SiS_Part4Port,0x1E,temp);
          temp=(tempax&0x00FF);
-         SiS_SetReg1(SiS_Part4Port,0x1D,temp);       
+         SiS_SetReg1(SiS_Part4Port,0x1D,temp);
    
          if(SiS_VBInfo&(SetCRT2ToTV|SetCRT2ToHiVisionTV)) {
-          if(SiS_VGAHDE>800){
-          SiS_SetRegOR(SiS_Part4Port,0x1E,0x08);      
-          } 
+            if(SiS_VGAHDE>800){
+               SiS_SetRegOR(SiS_Part4Port,0x1E,0x08);
+            }
          }
          temp=0x0036;
          if(SiS_VBInfo&SetCRT2ToTV) {
-           temp=temp|0x0001;     
-          }
-          SiS_SetRegANDOR(SiS_Part4Port,0x1F,0x00C0,temp);
-          tempbx=(SiS_HT/2)-2;
-          temp=((tempbx&0x0700)>>8)<<3;
-          SiS_SetRegANDOR(SiS_Part4Port,0x21,0x00C0,temp);
-          temp=tempbx&0x00FF;
-          SiS_SetReg1(SiS_Part4Port,0x22,temp);
-          if( (SiS_VBType&(VB_SIS301LV|VB_SIS302LV)) && (SiS_VBInfo&SetCRT2ToLCD) ) {
+             temp=temp|0x0001;
+         }
+         SiS_SetRegANDOR(SiS_Part4Port,0x1F,0x00C0,temp);
+         tempbx=(SiS_HT/2)-2;
+         temp=((tempbx&0x0700)>>8)<<3;
+         SiS_SetRegANDOR(SiS_Part4Port,0x21,0x00C0,temp);
+         temp=tempbx&0x00FF;
+         SiS_SetReg1(SiS_Part4Port,0x22,temp);
+         if( (SiS_VBType&(VB_SIS301LV|VB_SIS302LV)) && (SiS_VBInfo&SetCRT2ToLCD) ) {
              SiS_SetReg1(SiS_Part4Port,0x24,0x0e);
-	  }
-	  }
-/*end 301b*/
+	 }
+  }
+  /*end 301b*/
+
   SiS_SetCRT2VCLK(BaseAddr,ROMAddr,ModeNo,ModeIdIndex,RefreshRateTableIndex,HwDeviceExtension);
 }
 
@@ -4342,11 +4380,23 @@
   } else {       /*   LVDS  */
     	if(ModeNo<=0x13) VCLKIndex = CRT2Index;
     	else VCLKIndex = CRT2Index;
-
+#ifdef LINUX_XF86
+	xf86DrvMsg(0, X_INFO, "CRT2Index = %d\n", CRT2Index);
+#endif
 	/* TW: This does not make sense: If CH7005 is there but CRT2 is set to
-	       LCD, VCLKindex is returned untouched... */
-    	if(SiS_IF_DEF_CH7005==1) {
+	 *     LCD, VCLKindex is returned untouched...
+	 *     (Inserted SlaveMode check for 8bpp modes later)
+	 */
+
+#if 1
+    	if((SiS_IF_DEF_CH7005==1) && (!(SiS_VBInfo&SetInSlaveMode))) {
       		if(!(SiS_VBInfo&SetCRT2ToLCD)) {
+#else
+
+/* 	TW: If we do it this way instead, some machines (MITAC) have problems 		*/
+	if((SiS_IF_DEF_CH7005==1) && (SiS_VBInfo&SetCRT2ToTV)) {
+#endif
+
         		VCLKIndex = VCLKIndex&0x1f;
         		tempbx=0;
         		if(SiS_VBInfo&SetPALTV) tempbx=tempbx+2;
@@ -4362,7 +4412,7 @@
 					break;
         		}
         		VCLKIndex=CHTVVCLKPtr[VCLKIndex];
-      		}
+      		}  
     	} else {
      		VCLKIndex = VCLKIndex>>6;
      		if((SiS_LCDResInfo==Panel800x600)||(SiS_LCDResInfo==Panel320x480))
@@ -4501,6 +4551,8 @@
   SiS_SetReg3(Pdata,(USHORT)bl);
 }
 
+/* TW: Start of Chrontel 7005 functions ---------------------------- */
+
 void
 SiS_SetCHTVReg(ULONG ROMAddr,USHORT ModeNo,USHORT ModeIdIndex,
                USHORT RefreshRateTableIndex)
@@ -4511,64 +4563,92 @@
   SiS_CHTVRegDataStruct *CHTVRegData=NULL;
 
   if(ModeNo<=0x13){
-    tempcl = SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
+    	tempcl = SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
   }else{
-    tempcl = SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
+    	tempcl = SiS_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
   }
   TVType = 0;
   if(SiS_VBInfo&SetPALTV) TVType=TVType+2;
   if(SiS_VBInfo&SetCHTVOverScan) TVType=TVType+1;
   switch(TVType) {
-    case 0: CHTVRegData = SiS_CHTVReg_UNTSC; break;
-    case 1: CHTVRegData = SiS_CHTVReg_ONTSC; break;
-    case 2: CHTVRegData = SiS_CHTVReg_UPAL; break;
-    case 3: CHTVRegData = SiS_CHTVReg_OPAL; break;
+    	case 0: CHTVRegData = SiS_CHTVReg_UNTSC; break;
+    	case 1: CHTVRegData = SiS_CHTVReg_ONTSC; break;
+    	case 2: CHTVRegData = SiS_CHTVReg_UPAL;  break;
+    	case 3: CHTVRegData = SiS_CHTVReg_OPAL;  break;
   }
   resindex=tempcl&0x3F;
 
+  /* TW: We don't support modes >800x600 */
+  if (resindex > 5) return;
+
   if(SiS_VBInfo&SetPALTV) {
-    SiS_SetCH7005(0x4304);
-    SiS_SetCH7005(0x6909);
-  } 
-  else {
-    SiS_SetCH7005(0x0304);
-    SiS_SetCH7005(0x7109);
+    	SiS_SetCH7005(0x4304);  /* TW: 0x40=76uA (PAL); 0x03=15bit non-multi RGB*/
+    	SiS_SetCH7005(0x6909);	/* TW: Black level for PAL (105)*/
+  } else {
+    	SiS_SetCH7005(0x0304);  /* TW: upper nibble=71uA (NTSC), 0x03=15bit non-multi RGB*/
+    	SiS_SetCH7005(0x7109);	/* TW: Black level for NTSC (113)*/
   }
 
   temp = CHTVRegData[resindex].Reg[0];
-  tempbx=((temp&0x00FF)<<8)|0x00;
+  tempbx=((temp&0x00FF)<<8)|0x00;	/* TW: Mode register */
   SiS_SetCH7005(tempbx);
   temp = CHTVRegData[resindex].Reg[1];
-  tempbx=((temp&0x00FF)<<8)|0x07;
+  tempbx=((temp&0x00FF)<<8)|0x07;	/* TW: Start active video register */
   SiS_SetCH7005(tempbx);
   temp = CHTVRegData[resindex].Reg[2];
-  tempbx=((temp&0x00FF)<<8)|0x08;
+  tempbx=((temp&0x00FF)<<8)|0x08;	/* TW: Position overflow register */
   SiS_SetCH7005(tempbx);
   temp = CHTVRegData[resindex].Reg[3];
-  tempbx=((temp&0x00FF)<<8)|0x0A;
+  tempbx=((temp&0x00FF)<<8)|0x0A;	/* TW: Horiz Position register */
   SiS_SetCH7005(tempbx);
   temp = CHTVRegData[resindex].Reg[4];
-  tempbx=((temp&0x00FF)<<8)|0x0B;
+  tempbx=((temp&0x00FF)<<8)|0x0B;	/* TW: Vertical Position register */
   SiS_SetCH7005(tempbx);
 
+  /* TW: Set minimum flicker filter for Luma channel (SR1-0=00),
+             minimum text enhancement (S3-2=10),
+	     maximum flicker filter for Chroma channel (S5-4=10)
+	     =00101000=0x28 (When reading, S1-0->S3-2, and S3-2->S1-0!)
+   */
   SiS_SetCH7005(0x2801);
-  SiS_SetCH7005(0x3103);
-  SiS_SetCH7005(0x003D);
+
+  /* TW: Set video bandwidth
+         High bandwith Luma composite video filter(S0=1)
+         low bandwith Luma S-video filter (S2-1=00)
+	 disable peak filter in S-video channel (S3=0)
+	 high bandwidth Chroma Filter (S5-4=11)
+	 =00110001=0x31
+  */
+  SiS_SetCH7005(0xb103);       /* old: 3103 */
+
+  /* TW: Register 0x3D does not exist in non-macrovision register map
+         (Maybe this is a macrovision register?)
+   */
+  /* SiS_SetCH7005(0x003D); */
+
+  /* TW: Register 0x10 only contains 1 writable bit (S0) for sensing,
+         all other bits a read-only. Macrovision?
+   */
   SiS_SetCHTVRegANDOR(0x0010,0x1F);
+
+  /* TW: Register 0x11 only contains 3 writable bits (S0-S2) for
+         contrast enhancement (set to 010 -> gain 2 Yout = 9/8*(Yin-57) )
+   */
   SiS_SetCHTVRegANDOR(0x0211,0xF8);
+
+  /* TW: Clear DSEN
+   */
   SiS_SetCHTVRegANDOR(0x001C,0xEF);
-  
-  if(!(SiS_VBInfo&SetPALTV)) {
-    /* tempcl=CRT2CRTC;*/
+
+  if(!(SiS_VBInfo&SetPALTV)) {		/* ---- NTSC ---- */
     tempcl=tempcl&0x3F;
     if(SiS_VBInfo&SetCHTVOverScan) {
-      if(tempcl==0x04) {   /* 640x480   underscan */
-        SiS_SetCHTVRegANDOR(0x0020,0xEF);
-        SiS_SetCHTVRegANDOR(0x0121,0xFE);
-      }
-      else {
-        if(tempcl==0x05) {    /* 800x600  underscan */    
-          SiS_SetCHTVRegANDOR(0x0118,0xF0);
+      if(tempcl==0x04) {   			/* 640x480 overscan: Mode 16 */
+      	SiS_SetCHTVRegANDOR(0x0020,0xEF);   	/* loop filter off */
+        SiS_SetCHTVRegANDOR(0x0121,0xFE);       /* ACIV on, no need to set FSCI */
+      } else {
+        if(tempcl==0x05) {    			/* 800x600 overscan: Mode 23 */
+          SiS_SetCHTVRegANDOR(0x0118,0xF0);	/* 0x18-0x1f: FSCI 469,762,048 */
           SiS_SetCHTVRegANDOR(0x0C19,0xF0);
           SiS_SetCHTVRegANDOR(0x001A,0xF0);
           SiS_SetCHTVRegANDOR(0x001B,0xF0);
@@ -4576,31 +4656,38 @@
           SiS_SetCHTVRegANDOR(0x001D,0xF0);
           SiS_SetCHTVRegANDOR(0x001E,0xF0);
           SiS_SetCHTVRegANDOR(0x001F,0xF0);
-          SiS_SetCHTVRegANDOR(0x0120,0xEF);
-          SiS_SetCHTVRegANDOR(0x0021,0xFE);
+          SiS_SetCHTVRegANDOR(0x1020,0xEF);     /* Loop filter on for mode 23 */
+          SiS_SetCHTVRegANDOR(0x0021,0xFE);     /* ACIV off, need to set FSCI */
         }
       }
-    }
-    else {
-      if(tempcl==0x04) {     /* 640x480   overscan  */
-        SiS_SetCHTVRegANDOR(0x0020,0xEF);
+    } else {
+      if(tempcl==0x04) {     			/* ----- 640x480 underscan; Mode 17 */
+        SiS_SetCHTVRegANDOR(0x0020,0xEF); 	/* loop filter off */
         SiS_SetCHTVRegANDOR(0x0121,0xFE);
-      }
-      else {
-        if(tempcl==0x05) {   /* 800x600   overscan */
-          SiS_SetCHTVRegANDOR(0x0118,0xF0);
-          SiS_SetCHTVRegANDOR(0x0F19,0xF0);
-          SiS_SetCHTVRegANDOR(0x011A,0xF0);
-          SiS_SetCHTVRegANDOR(0x0C1B,0xF0);
-          SiS_SetCHTVRegANDOR(0x071C,0xF0);
-          SiS_SetCHTVRegANDOR(0x011D,0xF0);
-          SiS_SetCHTVRegANDOR(0x0C1E,0xF0);
-          SiS_SetCHTVRegANDOR(0x071F,0xF0);
-          SiS_SetCHTVRegANDOR(0x0120,0xEF);
-          SiS_SetCHTVRegANDOR(0x0021,0xFE);
+      } else {
+        if(tempcl==0x05) {   			/* ----- 800x600 underscan: Mode 24 */
+          SiS_SetCHTVRegANDOR(0x0118,0xF0);     /* (FSCI was 0x1f1c71c7 - this is for mode 22) */
+          SiS_SetCHTVRegANDOR(0x0919,0xF0);	/* FSCI for mode 24 is 428,554,851 */
+          SiS_SetCHTVRegANDOR(0x081A,0xF0);
+          SiS_SetCHTVRegANDOR(0x0b1B,0xF0);
+          SiS_SetCHTVRegANDOR(0x031C,0xF0);
+          SiS_SetCHTVRegANDOR(0x0a1D,0xF0);
+          SiS_SetCHTVRegANDOR(0x061E,0xF0);
+          SiS_SetCHTVRegANDOR(0x031F,0xF0);
+          SiS_SetCHTVRegANDOR(0x0020,0xEF);     /* loop filter off for mode 24 */
+          SiS_SetCHTVRegANDOR(0x0021,0xFE);	/* ACIV off, need to set FSCI */
         }
       }
     }
+  } else {				/* ---- PAL ---- */
+        /* TW: We don't play around with FSCI in PAL mode */
+      if (tempcl==0x04) {
+        SiS_SetCHTVRegANDOR(0x0020,0xEF); 	/* loop filter off */
+        SiS_SetCHTVRegANDOR(0x0121,0xFE);       /* ACIV on */
+      } else {
+        SiS_SetCHTVRegANDOR(0x0020,0xEF); 	/* loop filter off */
+        SiS_SetCHTVRegANDOR(0x0121,0xFE);       /* ACIV on */
+      }
   }
 }
 
@@ -4616,63 +4703,67 @@
   SiS_SetCH7005(tempbl);
 }
 
+/* TW: Write to Chrontel 7005 */
+/* Parameter is [Data (S15-S8) | Register no (S7-S0)] */
 void
 SiS_SetCH7005(USHORT tempbx)
 {
-  USHORT tempah,temp;
+  USHORT tempah,temp,i;
 
-  SiS_DDC_Port=0x3c4;
-  SiS_DDC_Index=0x11;
+  /* TW: This has to be relative to BaseAddr */
+  /* SiS_DDC_Port=0x3c4; */
+  SiS_DDC_Index=0x11;			/* TW: Bit 0 = SC;  Bit 1 = SD */
   SiS_DDC_DataShift=0x00;
-  SiS_DDC_DeviceAddr=0xEA;
+  SiS_DDC_DeviceAddr=0xEA;  		/* TW: DAB (Device Address Byte) */
 
-  temp=1;
-  for(;temp!=0;) {
+  for(i=0;i<50;i++) {	/* TW: Do only 50 attempts to write */
     SiS_SetSwitchDDC2();
-    SiS_SetStart();
+    SiS_SetStart();			/* TW: Set start condition */
     tempah=SiS_DDC_DeviceAddr;
-    temp=SiS_WriteDDC2Data(tempah);
-    if(temp) continue;
+    temp=SiS_WriteDDC2Data(tempah);	/* TW: Write DAB (S0=0=write) */
+    if(temp) continue;			/* TW:    (ERROR: no ack) */
     tempah=tempbx&0x00FF;
-    temp=SiS_WriteDDC2Data(tempah);
-    if(temp) continue;
+    temp=SiS_WriteDDC2Data(tempah);	/* TW: Write RAB */
+    if(temp) continue;			/* TW:    (ERROR: no ack) */
     tempah=(tempbx&0xFF00)>>8;
-    temp=SiS_WriteDDC2Data(tempah);
-    if(temp) continue;
-    SiS_SetStop();
+    temp=SiS_WriteDDC2Data(tempah);	/* TW: Write data */
+    if(temp) continue;			/* TW:    (ERROR: no ack) */
+    SiS_SetStop();			/* TW: Set stop condition */
+    return;
   }
 }
 
 USHORT
 SiS_GetCH7005(USHORT tempbx)
 {
-  USHORT tempah,temp;
+  USHORT tempah,temp,i;
 
-  SiS_DDC_Port=0x3c4;
-  SiS_DDC_Index=0x11;
+  /* TW: This has to be relative to BaseAddr, set by RegInit */
+  /* SiS_DDC_Port=0x3c4; */
+  SiS_DDC_Index=0x11;			/* TW: Bit 0 = SC;  Bit 1 = SD */
   SiS_DDC_DataShift=0x00;
-  SiS_DDC_DeviceAddr=0xEA;
+  SiS_DDC_DeviceAddr=0xEA;		/* TW: DAB */
   SiS_DDC_ReadAddr=tempbx;
 
-  for(;;) {
+  for(i=0;i<50;i++) {	/* TW: Do only 50 attempts to write */
     SiS_SetSwitchDDC2();
-    SiS_SetStart();
+    SiS_SetStart();			/* TW: Set start condition */
     tempah=SiS_DDC_DeviceAddr;
+    temp=SiS_WriteDDC2Data(tempah);	/* TW: Write DAB (S0=0=write) */
+    if(temp) continue;			/* TW:        (ERROR: no ack) */
+    tempah=SiS_DDC_ReadAddr;		/* TW: Write RAB */
     temp=SiS_WriteDDC2Data(tempah);
-    if(temp) continue;
-    tempah=SiS_DDC_ReadAddr;
-    temp=SiS_WriteDDC2Data(tempah);
-    if(temp) continue;
-
-    SiS_SetStart();
+    if(temp) continue;			/* TW:        (ERROR: no ack) */
+    SiS_SetStart();			/* TW: Re-start */
     tempah=SiS_DDC_DeviceAddr;
     tempah=tempah|0x01;
-    temp=SiS_WriteDDC2Data(tempah);
-    if(temp) continue;
-    tempah=SiS_ReadDDC2Data(tempah);
-    SiS_SetStop();
+    temp=SiS_WriteDDC2Data(tempah);	/* TW: DAB (S0=1=read) */
+    if(temp) continue;			/* TW:        (ERROR: no ack) */
+    tempah=SiS_ReadDDC2Data(tempah);	/* TW: Read byte */
+    SiS_SetStop();			/* TW: Stop condition */
     return(tempah);
   }
+  return(tempah);
 }
 
 void
@@ -4690,26 +4781,31 @@
   }
 }
 
+/* TW: Set Chrontel 7005 start condition */
+/* TW: This is done by a SD high-to-low transition while SC is high */
 void
 SiS_SetStart(void)
 {
-  SiS_SetSCLKLow();
-  SiS_SetRegANDOR(SiS_DDC_Port,SiS_DDC_Index,0xFD,0x02);     /*  SetSDA(0x01); */
-  SiS_SetSCLKHigh();
-  SiS_SetRegANDOR(SiS_DDC_Port,SiS_DDC_Index,0xFD,0x00);      /* SetSDA(0x00); */
-  SiS_SetSCLKHigh();
+  SiS_SetSCLKLow();					  /* TW: (SC->low)  */
+  SiS_SetRegANDOR(SiS_DDC_Port,SiS_DDC_Index,0xFD,0x02);  /* TW: SD->high */
+  SiS_SetSCLKHigh();					  /* TW: SC->high */
+  SiS_SetRegANDOR(SiS_DDC_Port,SiS_DDC_Index,0xFD,0x00);  /* TW: SD->low = start condition */
+  SiS_SetSCLKHigh();					  /* TW: (SC->low) */
 }
 
+/* TW: Set Chrontel 7005 stop condition */
+/* TW: This is done by a SD low-to-high transition while SC is high */
 void
 SiS_SetStop(void)
 {
-  SiS_SetSCLKLow();
-  SiS_SetRegANDOR(SiS_DDC_Port,SiS_DDC_Index,0xFD,0x00);    /*  SetSDA(0x00); */
-  SiS_SetSCLKHigh();
-  SiS_SetRegANDOR(SiS_DDC_Port,SiS_DDC_Index,0xFD,0x02);      /* SetSDA(0x01); */
-  SiS_SetSCLKHigh();
+  SiS_SetSCLKLow();					  /* TW: (SC->low) */
+  SiS_SetRegANDOR(SiS_DDC_Port,SiS_DDC_Index,0xFD,0x00);  /* TW: SD->low   */
+  SiS_SetSCLKHigh();					  /* TW: SC->high  */
+  SiS_SetRegANDOR(SiS_DDC_Port,SiS_DDC_Index,0xFD,0x02);  /* TW: SD->high = stop condition */   
+  SiS_SetSCLKHigh();					  /* TW: (SC->high) */
 }
 
+/* TW: Write 8 bits of data */
 USHORT
 SiS_WriteDDC2Data(USHORT tempax)
 {
@@ -4717,17 +4813,16 @@
 
   flag=0x80;
   for(i=0;i<8;i++) {
-    SiS_SetSCLKLow();
+    SiS_SetSCLKLow();					     /* TW: SC->low */
     if(tempax&flag) {
-      SiS_SetRegANDOR(SiS_DDC_Port,SiS_DDC_Index,0xFD,0x02);
-    }
-    else {
-      SiS_SetRegANDOR(SiS_DDC_Port,SiS_DDC_Index,0xFD,0x00);
+      SiS_SetRegANDOR(SiS_DDC_Port,SiS_DDC_Index,0xFD,0x02); /* TW: Write bit (1) to SD */
+    } else {
+      SiS_SetRegANDOR(SiS_DDC_Port,SiS_DDC_Index,0xFD,0x00); /* TW: Write bit (0) to SD */
     }
-    SiS_SetSCLKHigh();
+    SiS_SetSCLKHigh();					     /* TW: SC->high */
     flag=flag>>1;
   }
-  temp=SiS_CheckACK();
+  temp=SiS_CheckACK();					     /* TW: Check acknowledge */
   return(temp);
 }
 
@@ -4782,20 +4877,24 @@
   }
 }
 
+/* TW: Check acknowledge */
+/* Returns 0 if ack ok, non-0 if ack not ok */
 USHORT
 SiS_CheckACK(void)
 {
   USHORT tempah;
 
-  SiS_SetSCLKLow();
-  SiS_SetRegANDOR(SiS_DDC_Port,SiS_DDC_Index,0xFD,0x02);
-  SiS_SetSCLKHigh();
-  tempah=SiS_GetReg1(SiS_DDC_Port,SiS_DDC_Index);
-  SiS_SetSCLKLow();
-  if(tempah&0x02) return(1);
+  SiS_SetSCLKLow();					  /* TW: (SC->low) */
+  SiS_SetRegANDOR(SiS_DDC_Port,SiS_DDC_Index,0xFD,0x02);  /* TW: (SD->high) */
+  SiS_SetSCLKHigh();					  /* TW: SC->high = clock impulse for ack */
+  tempah=SiS_GetReg1(SiS_DDC_Port,SiS_DDC_Index);	  /* TW: Read SD */
+  SiS_SetSCLKLow();					  /* TW: SC->low = end of clock impulse */
+  if(tempah&0x02) return(1);				  /* TW: Ack OK if bit = 0 */
   else return(0);
 }
 
+/* TW: End of Chrontel 7005 functions ---------------------------- */
+
 void
 SiS_ModCRT1CRTC(ULONG ROMAddr,USHORT ModeNo,USHORT ModeIdIndex,
                 USHORT RefreshRateTableIndex)
@@ -5059,7 +5158,7 @@
   }
   tempal=0x02B;
   if(!(SiS_VBInfo&SetInSlaveMode)){
-    	tempal=tempal+3; 
+    	tempal=tempal+3;
   }
   SiS_SetReg1(SiS_P3c4,0x05,0x86);
   tempah = SiS_VCLKData[vclkindex].SR2B;
@@ -5366,8 +5465,6 @@
     for SIS300 O.E.M.
 */
 
-#ifdef SIS300                                         /* add to set SR14*/
-
 USHORT
 GetRevisionID(PSIS_HW_DEVICE_INFO HwDeviceExtension)
 {
@@ -5386,38 +5483,6 @@
    }
    return 0;
 }
-#endif
-
-USHORT
-GetOEMLCDPtr(PSIS_HW_DEVICE_INFO HwDeviceExtension)
-{
-  USHORT temp,tempbx=0,tempax;
-  if(SiS_IF_DEF_LVDS==0) {
-    	if(SiS_VBInfo&SetCRT2ToLCD) {              /* LCD */
-      		tempax=SiS_LCDResInfo;
-      		tempbx=SiS_LCDResInfo;
-      		tempbx=tempbx-Panel1024x768;
-     		if(!(SiS_SetFlag&LCDVESATiming)) {
-        		tempbx+=4;
-        		temp=GetRevisionID(HwDeviceExtension);
-          		if((HwDeviceExtension->jChipType == SIS_540)&&(temp<1))
-            			tempbx+=4;
-          		if((HwDeviceExtension->jChipType == SIS_630)&&(temp<3))
-             			tempbx+=4;
-       		}
-     		if((tempax==Panel1024x768)&&(SiS_LCDInfo==LCDNonExpanding)){
-         		tempbx=tempbx+3;
-       		}
-     		/*add OEMLCDPanelIDSupport*/
-        	tempbx=SiS_LCDTypeInfo;
-        	tempbx=tempbx<<1;
-        	if(!(SiS_SetFlag&LCDVESATiming))
-           		tempbx=tempbx+1;
-      	}
-  }
-  tempbx*=2;
-  return tempbx;
-}
 
 USHORT
 GetOEMTVPtr(void)
@@ -5441,6 +5506,7 @@
   return index;
 }
 
+/* TW: This is not for LVDS/Chrontel */
 void
 SetOEMTVDelay(PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT BaseAddr,
               ULONG ROMAddr,USHORT ModeNo)
@@ -5457,6 +5523,61 @@
   SiS_SetRegANDOR(Part1Port,0x13,~0x3C,temp);  /* index 0A D[6:4] */
 }
 
+USHORT
+GetOEMLCDPtr(PSIS_HW_DEVICE_INFO HwDeviceExtension)
+{
+  /* USHORT temp,tempax; */
+  USHORT tempbx=0;
+
+  if(SiS_IF_DEF_LVDS==0) {
+#if 0
+  	tempax=tempbx=SiS_LCDResInfo;
+      	tempbx=tempbx-Panel1024x768;
+     	if(!(SiS_SetFlag&LCDVESATiming)) {
+        	tempbx+=4;
+        	temp=GetRevisionID(HwDeviceExtension);
+        	if((HwDeviceExtension->jChipType == SIS_540)&&(temp<1))
+        		tempbx+=4;
+        	if((HwDeviceExtension->jChipType == SIS_630)&&(temp<3))
+        		tempbx+=4;
+       	}
+     	if((tempax==Panel1024x768)&&(SiS_LCDInfo&LCDNonExpanding)){
+        	tempbx=tempbx+3;
+       	}
+#endif
+
+	/* TW: This is total bullshit. First, we calculate tempbx, now
+	 *     we overwrite it?! (Therefore commented code above)
+	 */
+
+     	/*add OEMLCDPanelIDSupport*/
+        tempbx=SiS_LCDTypeInfo;
+
+#if 0   /* TW: Commented for DEBUG: */
+        tempbx=tempbx<<1;
+        if(!(SiS_SetFlag&LCDVESATiming))
+        	tempbx=tempbx+1;
+	tempbx*=2;
+	/* TW: The above code results in eg. 0xc * 2 * 2 = 48, but Delay2 table has
+	 *     only 32 entries. Thus, this can't work */
+#endif
+        /* TW: Don't think that 301(B) bridges need different LCD delay... */
+  	tempbx = SiS_LCDTypeInfo;
+	if(SiS_LCDInfo&LCDNonExpanding){
+      		tempbx=tempbx+16;
+	}
+  } else {  /* TW: Added LVDS code */
+  	tempbx = SiS_LCDTypeInfo;
+	if(SiS_LCDInfo&LCDNonExpanding){
+      		tempbx=tempbx+16;
+	}
+  }
+  return tempbx;
+}
+
+#if 0
+/* TW: Original code - can't work (eg. exceeds arrays by re-using temp,
+       writes to Part2(!)Port unlike TVDelay, etc...) */
 void
 SetOEMLCDDelay(PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT BaseAddr,
                ULONG ROMAddr,USHORT ModeNo)
@@ -5468,11 +5589,54 @@
   temp = GetOEMLCDPtr(HwDeviceExtension);
   index = SiS_VBModeIDTable[ModeIdIndex].VB_LCDDelayIndex;
   temp = SiS300_OEMLCDDelay1[temp][index];
-   /*add OEMLCDPanelIDSupport*/  
-  temp= SiS300_OEMLCDDelay2[temp][index];
+   /*add OEMLCDPanelIDSupport*/
+  temp = SiS300_OEMLCDDelay2[temp][index];
   temp=temp&0x3c;
   SiS_SetRegANDOR(Part2Port,0x13,~0x3C,temp);  /* index 0A D[6:4] */
 }
+#endif
+
+/* TW: Although I assume that the code above does not work correctly,
+ *     I won't change it for non-LVDS machines until someone tells me so.
+ */
+void
+SetOEMLCDDelay(PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT BaseAddr,
+               ULONG ROMAddr,USHORT ModeNo)
+{
+  USHORT Part1Port, Part2Port;
+  USHORT index,temp,ModeIdIndex;
+
+  Part1Port=BaseAddr+SIS_CRT2_PORT_04;
+  Part2Port=BaseAddr+SIS_CRT2_PORT_10;
+
+  ModeIdIndex=SiS_SearchVBModeID(ROMAddr,ModeNo);
+  temp = GetOEMLCDPtr(HwDeviceExtension);
+  index = SiS_VBModeIDTable[ModeIdIndex].VB_LCDDelayIndex; /* TW: Always zero... */
+  if (SiS_IF_DEF_LVDS == 1) {
+  	/* TW: Added for LVDS: Assuming Part_1!!!_Port to be the correct one */
+    	temp = SiS300_OEMLCDDelay3[temp][index];
+	temp=temp&0x3c;
+  	SiS_SetRegANDOR(Part1Port,0x13,~0x3C,temp);  /* index 0A D[6:4] */
+  } else {
+        /* temp = SiS300_OEMLCDDelay1[temp][index];  */
+	/*  TW: This must be wrong: temp is eg. 48 and
+		thus exceeds array size of Delay2 table! */
+
+        /*add OEMLCDPanelIDSupport*/
+
+#if 0  /* TW: Commented for DEBUG */
+	temp = SiS300_OEMLCDDelay2[temp][index];
+	temp=temp&0x3c;
+  	SiS_SetRegANDOR(Part2Port,0x13,~0x3C,temp);  /* index 0A D[6:4] */
+#endif
+
+        /* TW: 301B reported not working. Maybe because of the above bullshit? */
+	/*     Do it like for LVDS now. 0x13 seems to be the LCD delay anyway */
+        temp = SiS300_OEMLCDDelay3[temp][index];
+	temp=temp&0x3c;
+  	SiS_SetRegANDOR(Part1Port,0x13,~0x3C,temp);  /* index 0A D[6:4] */
+  }
+}
 
 /*
 */
@@ -5483,6 +5647,7 @@
   USHORT Part2Port;
   USHORT index,temp;
   USHORT ModeIdIndex;
+
   Part2Port=BaseAddr+SIS_CRT2_PORT_10;
   ModeIdIndex=SiS_SearchVBModeID(ROMAddr,ModeNo);
   temp = GetOEMTVPtr();
@@ -5623,21 +5788,19 @@
 }
 
 void
-SiS_OEM300Setting(PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT BaseAddr,ULONG ROMAddr,USHORT ModeNo)
+SiS_OEM300Setting(PSIS_HW_DEVICE_INFO HwDeviceExtension,
+		  USHORT BaseAddr,ULONG ROMAddr,USHORT ModeNo)
 {
-  if(SiS_VBInfo&SetCRT2ToLCD) {
-     if( (SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV))
-     						|| (SiS_IF_DEF_LVDS==0))  {
+  if (SiS_VBInfo & SetCRT2ToLCD) {
        SetOEMLCDDelay(HwDeviceExtension,BaseAddr,ROMAddr,ModeNo);
-     }
   }
-  if (SiS_VBInfo&SetCRT2ToTV) {
-       SetOEMTVDelay(HwDeviceExtension,BaseAddr,ROMAddr,ModeNo);
+  if (SiS_VBInfo & SetCRT2ToTV) {
        /* TW: (Added LVDS check) - done this way now because LVDS
         * seems to be 1 for some of the SiS bridges as well
 	*/
        if( (SiS_VBType&(VB_SIS301B|VB_SIS302B|VB_SIS301LV|VB_SIS302LV))
        						|| (SiS_IF_DEF_LVDS==0))  {
+	        SetOEMTVDelay(HwDeviceExtension,BaseAddr,ROMAddr,ModeNo);
        		SetOEMAntiFlicker(HwDeviceExtension,BaseAddr,ROMAddr,ModeNo);
     		/* SetOEMPhaseIncr(HwDeviceExtension,BaseAddr,ROMAddr,ModeNo);*/
        		SetOEMYFilter(HwDeviceExtension,BaseAddr,ROMAddr,ModeNo);
diff -urN linux-2.4.19-pre9/drivers/video/sis/init301.h linux-2.4.19-pre10/drivers/video/sis/init301.h
--- linux-2.4.19-pre9/drivers/video/sis/init301.h	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/video/sis/init301.h	Mon Jun  3 18:50:56 2002
@@ -75,6 +75,7 @@
 extern   USHORT   SiS_IF_DEF_LVDS;
 extern   USHORT   SiS_IF_DEF_TRUMPION;
 extern   USHORT   SiS_IF_DEF_CH7005;
+extern   USHORT   SiS_Backup7005;
 extern   USHORT   SiS_IF_DEF_HiVision;
 extern   USHORT   SiS_IF_DEF_DSTN;   /*add for dstn*/
 extern   USHORT   SiS_IF_DEF_FSTN;   /*add for fstn*/
diff -urN linux-2.4.19-pre9/drivers/video/sis/initdef.h linux-2.4.19-pre10/drivers/video/sis/initdef.h
--- linux-2.4.19-pre9/drivers/video/sis/initdef.h	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/video/sis/initdef.h	Mon Jun  3 18:50:56 2002
@@ -1,6 +1,6 @@
 /* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/sis/initdef.h,v 1.4 2000/12/02 01:16:17 dawes Exp $ */
 
-/* Comments and changes marked with "TW" by Thomas Winischhofer <tw@webit.com> */
+/* Comments and changes marked with "TW" by Thomas Winischhofer <thomas@winischhofer.net> */
 
 #ifndef _INITDEF_
 #define _INITDEF_
@@ -122,14 +122,17 @@
 #define Panel1600x1200          0x06 /*301b*/
 #define Panel320x480            0x07 /*fstn*/
 
-#define LCDRGB18Bit             0x01
 #define ExtChipType             0x0e
 #define ExtChip301              0x02
 #define ExtChipLVDS             0x04
 #define ExtChipTrumpion         0x06
 #define ExtChipCH7005           0x08
 #define ExtChipMitacTV          0x0a
+
+/* LCDInfo */
+#define LCDRGB18Bit             0x01
 #define LCDNonExpanding         0x10
+
 #define LCDNonExpandingShift    4
 #define LCDSync                 0x20
 #define LCDSyncBit              0xe0
diff -urN linux-2.4.19-pre9/drivers/video/sis/oem300.h linux-2.4.19-pre10/drivers/video/sis/oem300.h
--- linux-2.4.19-pre9/drivers/video/sis/oem300.h	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/video/sis/oem300.h	Mon Jun  3 18:50:56 2002
@@ -1,73 +1,112 @@
 
 UCHAR SiS300_OEMTVDelay[8][4]={
-{0x08,0x08,0x08,0x08},
-{0x08,0x08,0x08,0x08},
-{0x08,0x08,0x08,0x08},
-{0x2c,0x2c,0x2c,0x2c},
-{0x08,0x08,0x08,0x08},
-{0x08,0x08,0x08,0x08},
-{0x08,0x08,0x08,0x08},
-{0x20,0x20,0x20,0x20}};
+	{0x08,0x08,0x08,0x08},
+	{0x08,0x08,0x08,0x08},
+	{0x08,0x08,0x08,0x08},
+	{0x2c,0x2c,0x2c,0x2c},
+	{0x08,0x08,0x08,0x08},
+	{0x08,0x08,0x08,0x08},
+	{0x08,0x08,0x08,0x08},
+	{0x20,0x20,0x20,0x20}
+};
 
 UCHAR SiS300_OEMTVFlicker[8][4]={
-{0x00,0x00,0x00,0x00},
-{0x00,0x00,0x00,0x00},
-{0x00,0x00,0x00,0x00},
-{0x00,0x00,0x00,0x00},
-{0x00,0x00,0x00,0x00},
-{0x00,0x00,0x00,0x00},
-{0x00,0x00,0x00,0x00},
-{0x00,0x00,0x00,0x00}};
+	{0x00,0x00,0x00,0x00},
+	{0x00,0x00,0x00,0x00},
+	{0x00,0x00,0x00,0x00},
+	{0x00,0x00,0x00,0x00},
+	{0x00,0x00,0x00,0x00},
+	{0x00,0x00,0x00,0x00},
+	{0x00,0x00,0x00,0x00},
+	{0x00,0x00,0x00,0x00}
+};
 
 UCHAR SiS300_OEMLCDDelay1[12][4]={
-{0x2c,0x2c,0x2c,0x2c},
-{0x20,0x20,0x20,0x20},
-{0x20,0x20,0x20,0x20},
-{0x2c,0x2c,0x2c,0x2c},
-{0x2c,0x2c,0x2c,0x2c},
-{0x20,0x20,0x20,0x20},
-{0x20,0x20,0x20,0x20},
-{0x24,0x24,0x24,0x24},
-{0x24,0x24,0x24,0x24},
-{0x20,0x20,0x20,0x20},
-{0x20,0x20,0x20,0x20},
-{0x24,0x24,0x24,0x24}};
+	{0x2c,0x2c,0x2c,0x2c},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x2c,0x2c,0x2c,0x2c},
+	{0x2c,0x2c,0x2c,0x2c},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x24,0x24,0x24,0x24},
+	{0x24,0x24,0x24,0x24},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x24,0x24,0x24,0x24}
+};
 
 
 UCHAR SiS300_OEMLCDDelay2[32][4]={
-{0x20,0x20,0x20,0x20},
-{0x20,0x20,0x20,0x20},
-{0x20,0x20,0x20,0x20},
-{0x20,0x20,0x20,0x20},
-{0x20,0x20,0x20,0x20},
-{0x20,0x20,0x20,0x20},
-{0x20,0x20,0x20,0x20},
-{0x20,0x20,0x20,0x20},
-{0x20,0x20,0x20,0x20},
-{0x20,0x20,0x20,0x20},
-{0x20,0x20,0x20,0x20},
-{0x20,0x20,0x20,0x20},
-{0x20,0x20,0x20,0x20},
-{0x20,0x20,0x20,0x20},
-{0x20,0x20,0x20,0x20},
-{0x20,0x20,0x20,0x20},
-{0x20,0x20,0x20,0x20},
-{0x20,0x20,0x20,0x20},
-{0x20,0x20,0x20,0x20},
-{0x20,0x20,0x20,0x20},
-{0x20,0x20,0x20,0x20},
-{0x20,0x20,0x20,0x20},
-{0x20,0x20,0x20,0x20},
-{0x20,0x20,0x20,0x20},
-{0x20,0x20,0x20,0x20},
-{0x20,0x20,0x20,0x20},
-{0x20,0x20,0x20,0x20},
-{0x20,0x20,0x20,0x20},
-{0x20,0x20,0x20,0x20},
-{0x20,0x20,0x20,0x20},
-{0x20,0x20,0x20,0x20},
-{0x20,0x20,0x20,0x20}};
-
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20}
+};
+
+/* TW: Added for LVDS */
+UCHAR SiS300_OEMLCDDelay3[32][4]={
+	{0x20,0x20,0x20,0x20},  /* --- Expanding panels */
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x04,0x04,0x04,0x04},		/* Clevo 2202, Mitac (PanelType 12)*/
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},  	/* Uniwill N241S2 (PanelType 14)*/
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},  /* ---- NonExpanding panels */
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20},
+	{0x20,0x20,0x20,0x20}
+};
 
 /*
 UCHAR SiS300_StNTSCDelay[]={0x08,0x08,0x08,0x08,0xff};
@@ -87,346 +126,406 @@
 UCHAR SiS300_ExtSCARTFlicker[]={0x00,0x00,0x00,0x00,0xff};
 UCHAR SiS300_ExtHiTVFlicker[]={0x00,0x00,0x00,0x00,0xff};
 */
+
 #if 0
 //typedef struct _SiS_OEMTVPhasestruct  {
 //UCHAR Index[4];
 //} SiS_OEMTVPhasestruct;
 //SiS_OEMTVPhasestruct
 #endif
+
 UCHAR SiS300_StNTSCPhase[6][4]={
-{0x21,0xed,0x00,0x08},
-{0x21,0xed,0x8a,0x08},
-{0x21,0xed,0x8a,0x08},
-{0x21,0xed,0x8a,0x08},
-{0x21,0xed,0x8a,0x08},
-{0xff,0xff,0xff,0xff}};
+	{0x21,0xed,0x00,0x08},
+	{0x21,0xed,0x8a,0x08},
+	{0x21,0xed,0x8a,0x08},
+	{0x21,0xed,0x8a,0x08},
+	{0x21,0xed,0x8a,0x08},
+	{0xff,0xff,0xff,0xff}
+};
+
 #if 0
 //SiS_OEMTVPhasestruct
 #endif
+
 UCHAR SiS300_StPALPhase[6][4]={
-{0x2a,0x05,0xd3,0x00},
-{0x2a,0x05,0xd3,0x00},
-{0x2a,0x05,0xd3,0x00},
-{0x2a,0x05,0xd3,0x00},
-{0x2a,0x05,0xd3,0x00},
-{0xff,0xff,0xff,0xff}};
+	{0x2a,0x05,0xd3,0x00},
+	{0x2a,0x05,0xd3,0x00},
+	{0x2a,0x05,0xd3,0x00},
+	{0x2a,0x05,0xd3,0x00},
+	{0x2a,0x05,0xd3,0x00},
+	{0xff,0xff,0xff,0xff}
+};
+
 #if 0
 //SiS_OEMTVPhasestruct
 #endif
+
 UCHAR SiS300_StSCARTPhase[6][4]={
-{0x2a,0x05,0xd3,0x00},
-{0x2a,0x05,0xd3,0x00},
-{0x2a,0x05,0xd3,0x00},
-{0x2a,0x05,0xd3,0x00},
-{0x2a,0x05,0xd3,0x00},
-{0xff,0xff,0xff,0xff}};
+	{0x2a,0x05,0xd3,0x00},
+	{0x2a,0x05,0xd3,0x00},
+	{0x2a,0x05,0xd3,0x00},
+	{0x2a,0x05,0xd3,0x00},
+	{0x2a,0x05,0xd3,0x00},
+	{0xff,0xff,0xff,0xff}
+};
+
 #if 0
 //SiS_OEMTVPhasestruct
 #endif
+
 UCHAR SiS300_StHiTVPhase[6][4]={
-{0x2a,0x05,0xd3,0x00},
-{0x2a,0x05,0xd3,0x00},
-{0x2a,0x05,0xd3,0x00},
-{0x2a,0x05,0xd3,0x00},
-{0x2a,0x05,0xd3,0x00},
-{0xff,0xff,0xff,0xff}};
+	{0x2a,0x05,0xd3,0x00},
+	{0x2a,0x05,0xd3,0x00},
+	{0x2a,0x05,0xd3,0x00},
+	{0x2a,0x05,0xd3,0x00},
+	{0x2a,0x05,0xd3,0x00},
+	{0xff,0xff,0xff,0xff}
+};
+
 #if 0
 //SiS_OEMTVPhasestruct
 #endif
+
 UCHAR SiS300_ExtNTSCPhase[6][4]={
-{0x21,0xed,0x00,0x08},
-{0x21,0xed,0x8a,0x08},
-{0x21,0xed,0x8a,0x08},
-{0x21,0xed,0x8a,0x08},
-{0x21,0xed,0x8a,0x08},
-{0xff,0xff,0xff,0xff}};
+	{0x21,0xed,0x00,0x08},
+	{0x21,0xed,0x8a,0x08},
+	{0x21,0xed,0x8a,0x08},
+	{0x21,0xed,0x8a,0x08},
+	{0x21,0xed,0x8a,0x08},
+	{0xff,0xff,0xff,0xff}
+};
+
 #if 0
 //SiS_OEMTVPhasestruct
 #endif
+
 UCHAR SiS300_ExtPALPhase[6][4]={
-{0x2a,0x05,0xd3,0x00},
-{0x2a,0x05,0xd3,0x00},
-{0x2a,0x05,0xd3,0x00},
-{0x2a,0x05,0xd3,0x00},
-{0x2a,0x05,0xd3,0x00},
-{0xff,0xff,0xff,0xff}};
+	{0x2a,0x05,0xd3,0x00},
+	{0x2a,0x05,0xd3,0x00},
+	{0x2a,0x05,0xd3,0x00},
+	{0x2a,0x05,0xd3,0x00},
+	{0x2a,0x05,0xd3,0x00},
+	{0xff,0xff,0xff,0xff}
+};
+
 #if 0
 //SiS_OEMTVPhasestruct
 #endif
+
 UCHAR SiS300_ExtSCARTPhase[6][4]={
-{0x2a,0x05,0xd3,0x00},
-{0x2a,0x05,0xd3,0x00},
-{0x2a,0x05,0xd3,0x00},
-{0x2a,0x05,0xd3,0x00},
-{0x2a,0x05,0xd3,0x00},
-{0xff,0xff,0xff,0xff}};
+	{0x2a,0x05,0xd3,0x00},
+	{0x2a,0x05,0xd3,0x00},
+	{0x2a,0x05,0xd3,0x00},
+	{0x2a,0x05,0xd3,0x00},
+	{0x2a,0x05,0xd3,0x00},
+	{0xff,0xff,0xff,0xff}
+};
+
 #if 0
 //SiS_OEMTVPhasestruct
 #endif
+
 UCHAR SiS300_ExtHiTVPhase[6][4]={
-{0x2a,0x05,0xd3,0x00},
-{0x2a,0x05,0xd3,0x00},
-{0x2a,0x05,0xd3,0x00},
-{0x2a,0x05,0xd3,0x00},
-{0x2a,0x05,0xd3,0x00},
-{0xff,0xff,0xff,0xff}};
+	{0x2a,0x05,0xd3,0x00},
+	{0x2a,0x05,0xd3,0x00},
+	{0x2a,0x05,0xd3,0x00},
+	{0x2a,0x05,0xd3,0x00},
+	{0x2a,0x05,0xd3,0x00},
+	{0xff,0xff,0xff,0xff}
+};
+
 #if 0
 //typedef struct _SiS_OEMTVFilterstruct{
 //UCHAR Index[4];
 //} SiS_OEMTVFilterstruct;
 //SiS_OEMTVFilterstruct
 #endif
+
 UCHAR SiS300_StNTSCFilter[17][4]={
-{0x00,0xf4,0x10,0x38},
-{0x00,0xf4,0x10,0x38},
-{0xeb,0x04,0x10,0x18},
-{0xf7,0x06,0x19,0x14},
-{0x00,0xf4,0x10,0x38},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x15,0x25,0xf6},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xff,0xff,0xff,0xff}};
+	{0x00,0xf4,0x10,0x38},
+	{0x00,0xf4,0x10,0x38},
+	{0xeb,0x04,0x10,0x18},
+	{0xf7,0x06,0x19,0x14},
+	{0x00,0xf4,0x10,0x38},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x15,0x25,0xf6},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xff,0xff,0xff,0xff}
+};
+
 #if 0
 //SiS_OEMTVFilterstruct
 #endif
+
 UCHAR SiS300_StPALFilter[17][4]={
-{0x00,0xf4,0x10,0x38},
-{0x00,0xf4,0x10,0x38},
-{0xf1,0xf7,0x10,0x32},
-{0xf3,0x00,0x1d,0x20},
-{0x00,0xf4,0x10,0x38},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xfc,0xfb,0x14,0x2a},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xff,0xff,0xff,0xff}};
+	{0x00,0xf4,0x10,0x38},
+	{0x00,0xf4,0x10,0x38},
+	{0xf1,0xf7,0x10,0x32},
+	{0xf3,0x00,0x1d,0x20},
+	{0x00,0xf4,0x10,0x38},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xfc,0xfb,0x14,0x2a},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xff,0xff,0xff,0xff}
+};
+
 #if 0
 //SiS_OEMTVFilterstruct
 #endif
+
 UCHAR SiS300_StSCARTFilter[17][4]={
-{0x00,0xf4,0x10,0x38},
-{0x00,0xf4,0x10,0x38},
-{0xf1,0xf7,0x10,0x32},
-{0xf3,0x00,0x1d,0x20},
-{0x00,0xf4,0x10,0x38},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xfc,0xfb,0x14,0x2a},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xff,0xff,0xff,0xff}};
+	{0x00,0xf4,0x10,0x38},
+	{0x00,0xf4,0x10,0x38},
+	{0xf1,0xf7,0x10,0x32},
+	{0xf3,0x00,0x1d,0x20},
+	{0x00,0xf4,0x10,0x38},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xfc,0xfb,0x14,0x2a},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xff,0xff,0xff,0xff}
+};
+
 #if 0
 //SiS_OEMTVFilterstruct
 #endif
+
 UCHAR SiS300_StHiTVFilter[17][4]={
-{0x00,0xf4,0x10,0x38},
-{0x00,0xf4,0x10,0x38},
-{0xf1,0xf7,0x10,0x32},
-{0xf3,0x00,0x1d,0x20},
-{0x00,0xf4,0x10,0x38},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xfc,0xfb,0x14,0x2a},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xff,0xff,0xff,0xff}};
+	{0x00,0xf4,0x10,0x38},
+	{0x00,0xf4,0x10,0x38},
+	{0xf1,0xf7,0x10,0x32},
+	{0xf3,0x00,0x1d,0x20},
+	{0x00,0xf4,0x10,0x38},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xfc,0xfb,0x14,0x2a},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xff,0xff,0xff,0xff}
+};
+
 #if 0
 //SiS_OEMTVFilterstruct
 #endif
+
 UCHAR SiS300_ExtNTSCFilter[17][4]={
-{0x00,0xf4,0x10,0x38},
-{0x00,0xf4,0x10,0x38},
-{0xeb,0x04,0x10,0x18},
-{0xf7,0x06,0x19,0x14},
-{0x00,0xf4,0x10,0x38},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x15,0x25,0xf6},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xff,0xff,0xff,0xff}};
+	{0x00,0xf4,0x10,0x38},
+	{0x00,0xf4,0x10,0x38},
+	{0xeb,0x04,0x10,0x18},
+	{0xf7,0x06,0x19,0x14},
+	{0x00,0xf4,0x10,0x38},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x15,0x25,0xf6},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xff,0xff,0xff,0xff}
+};
+
 #if 0
 //SiS_OEMTVFilterstruct
 #endif
+
 UCHAR SiS300_ExtPALFilter[17][4]={
-{0x00,0xf4,0x10,0x38},
-{0x00,0xf4,0x10,0x38},
-{0xf1,0xf7,0x10,0x32},
-{0xf3,0x00,0x1d,0x20},
-{0x00,0xf4,0x10,0x38},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xfc,0xfb,0x14,0x2a},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xff,0xff,0xff,0xff}};
+	{0x00,0xf4,0x10,0x38},
+	{0x00,0xf4,0x10,0x38},
+	{0xf1,0xf7,0x10,0x32},
+	{0xf3,0x00,0x1d,0x20},
+	{0x00,0xf4,0x10,0x38},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xfc,0xfb,0x14,0x2a},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xff,0xff,0xff,0xff}
+};
+
 #if 0
 //SiS_OEMTVFilterstruct
 #endif
+
 UCHAR SiS300_ExtSCARTFilter[17][4]={
-{0x00,0xf4,0x10,0x38},
-{0x00,0xf4,0x10,0x38},
-{0xf1,0xf7,0x10,0x32},
-{0xf3,0x00,0x1d,0x20},
-{0x00,0xf4,0x10,0x38},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xfc,0xfb,0x14,0x2a},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xff,0xff,0xff,0xff}};
+	{0x00,0xf4,0x10,0x38},
+	{0x00,0xf4,0x10,0x38},
+	{0xf1,0xf7,0x10,0x32},
+	{0xf3,0x00,0x1d,0x20},
+	{0x00,0xf4,0x10,0x38},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xfc,0xfb,0x14,0x2a},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xff,0xff,0xff,0xff}
+};
+
 #if 0
 //SiS_OEMTVFilterstruct
 #endif
+
 UCHAR SiS300_ExtHiTVFilter[17][4]={
-{0x00,0xf4,0x10,0x38},
-{0x00,0xf4,0x10,0x38},
-{0xf1,0xf7,0x10,0x32},
-{0xf3,0x00,0x1d,0x20},
-{0x00,0xf4,0x10,0x38},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xfc,0xfb,0x14,0x2a},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xf1,0xf7,0x1f,0x32},
-{0xff,0xff,0xff,0xff}};
+	{0x00,0xf4,0x10,0x38},
+	{0x00,0xf4,0x10,0x38},
+	{0xf1,0xf7,0x10,0x32},
+	{0xf3,0x00,0x1d,0x20},
+	{0x00,0xf4,0x10,0x38},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xfc,0xfb,0x14,0x2a},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xf1,0xf7,0x1f,0x32},
+	{0xff,0xff,0xff,0xff}
+};
+
 #if 0
 //typedef struct _SiS_OEMTVFilter2struct{
 //UCHAR Index[7];
 //} SiS_OEMTVFilter2struct;
 //SiS_OEMTVFilter2struct
 #endif
+
 UCHAR SiS300_NTSCFilter2[9][7]={
-{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
-{0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
-{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
-{0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
-{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
-{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
-{0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
-{0x01,0x01,0xFC,0xF8,0x08,0x26,0x38},
-{0xFF,0xFF,0xFC,0x00,0x0F,0x22,0x28}};
+	{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
+	{0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
+	{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
+	{0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
+	{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
+	{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
+	{0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
+	{0x01,0x01,0xFC,0xF8,0x08,0x26,0x38},
+	{0xFF,0xFF,0xFC,0x00,0x0F,0x22,0x28}
+};
+
 #if 0
 //SiS_OEMTVFilter2struct
 #endif
+
 UCHAR SiS300_PALFilter2[9][7]={
-{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
-{0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
-{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
-{0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
-{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
-{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
-{0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
-{0x01,0x01,0xFC,0xF8,0x08,0x26,0x38},
-{0xFF,0xFF,0xFC,0x00,0x0F,0x22,0x28}};
+	{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
+	{0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
+	{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
+	{0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
+	{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
+	{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
+	{0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
+	{0x01,0x01,0xFC,0xF8,0x08,0x26,0x38},
+	{0xFF,0xFF,0xFC,0x00,0x0F,0x22,0x28}
+};
 
 UCHAR SiS300_PALMFilter[17][4]={
-{0x00,0xf4,0x10,0x38},
-{0x00,0xf4,0x10,0x38},
-{0xeb,0x04,0x10,0x18},
-{0xf7,0x06,0x19,0x14},
-{0x00,0xf4,0x10,0x38},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x15,0x25,0xf6},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xff,0xff,0xff,0xff}};
+	{0x00,0xf4,0x10,0x38},
+	{0x00,0xf4,0x10,0x38},
+	{0xeb,0x04,0x10,0x18},
+	{0xf7,0x06,0x19,0x14},
+	{0x00,0xf4,0x10,0x38},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x15,0x25,0xf6},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xff,0xff,0xff,0xff}
+};
+
 UCHAR SiS300_PALNFilter[17][4]={
-{0x00,0xf4,0x10,0x38},
-{0x00,0xf4,0x10,0x38},
-{0xeb,0x04,0x10,0x18},
-{0xf7,0x06,0x19,0x14},
-{0x00,0xf4,0x10,0x38},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x15,0x25,0xf6},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xff,0xff,0xff,0xff}};
+	{0x00,0xf4,0x10,0x38},
+	{0x00,0xf4,0x10,0x38},
+	{0xeb,0x04,0x10,0x18},
+	{0xf7,0x06,0x19,0x14},
+	{0x00,0xf4,0x10,0x38},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x15,0x25,0xf6},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xff,0xff,0xff,0xff}
+};
 
 
 UCHAR SiS300_PALMFilter2[9][7]={
-{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
-{0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
-{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
-{0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
-{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
-{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
-{0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
-{0x01,0x01,0xFC,0xF8,0x08,0x26,0x38},
-{0xFF,0xFF,0xFC,0x00,0x0F,0x22,0x28}};
+	{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
+	{0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
+	{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
+	{0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
+	{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
+	{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
+	{0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
+	{0x01,0x01,0xFC,0xF8,0x08,0x26,0x38},
+	{0xFF,0xFF,0xFC,0x00,0x0F,0x22,0x28}
+};
 
 UCHAR SiS300_PALNFilter2[9][7]={
-{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
-{0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
-{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
-{0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
-{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
-{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
-{0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
-{0x01,0x01,0xFC,0xF8,0x08,0x26,0x38},
-{0xFF,0xFF,0xFC,0x00,0x0F,0x22,0x28}};
+	{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
+	{0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
+	{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
+	{0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
+	{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
+	{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
+	{0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
+	{0x01,0x01,0xFC,0xF8,0x08,0x26,0x38},
+	{0xFF,0xFF,0xFC,0x00,0x0F,0x22,0x28}
+};
+
diff -urN linux-2.4.19-pre9/drivers/video/sis/oem310.h linux-2.4.19-pre10/drivers/video/sis/oem310.h
--- linux-2.4.19-pre9/drivers/video/sis/oem310.h	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/video/sis/oem310.h	Mon Jun  3 18:50:56 2002
@@ -1,9 +1,13 @@
 
 UCHAR SiS310_CRT2DelayCompensation1=0x4; /* 301A */
-UCHAR SiS310_LCDDelayCompensation1[]={0x0,0x0,0x0,0xb,0xb,0xb,0x8,0x8,0x8,0x8,0x8,0x8,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0};
+UCHAR SiS310_LCDDelayCompensation1[]=
+		{0x0,0x0,0x0,0xb,0xb,0xb,0x8,0x8,0x8,0x8,0x8,0x8,
+		 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0};
 UCHAR SiS310_TVDelayCompensation1[]={0x2,0x2,0x2,0x2,0x8,0xb};
 UCHAR SiS310_CRT2DelayCompensation2=0xC; /* 301B */
-UCHAR SiS310_LCDDelayCompensation2[]={0x0,0x0,0x0,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x8,0x8,0x8,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0};
+UCHAR SiS310_LCDDelayCompensation2[]=
+		{0x0,0x0,0x0,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x8,
+		 0x8,0x8,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0};
 UCHAR SiS310_TVDelayCompensation2[]={0x3,0x3,0x3,0x3,0x8,0xb};
 UCHAR SiS310_TVAntiFlick1[3][2]={{0x4,0x0},{0x4,0x8},{0x0,0x0}};
 
@@ -80,66 +84,72 @@
  }
 };
 /*end 301b*/
+
 /*add PALMN*/
 UCHAR SiS310_PALMFilter[17][4]={
-{0x00,0xf4,0x10,0x38},
-{0x00,0xf4,0x10,0x38},
-{0xeb,0x04,0x10,0x18},
-{0xf7,0x06,0x19,0x14},
-{0x00,0xf4,0x10,0x38},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x15,0x25,0xf6},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xff,0xff,0xff,0xff}};
+	{0x00,0xf4,0x10,0x38},
+	{0x00,0xf4,0x10,0x38},
+	{0xeb,0x04,0x10,0x18},
+	{0xf7,0x06,0x19,0x14},
+	{0x00,0xf4,0x10,0x38},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x15,0x25,0xf6},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xff,0xff,0xff,0xff}
+};
+
 UCHAR SiS310_PALNFilter[17][4]={
-{0x00,0xf4,0x10,0x38},
-{0x00,0xf4,0x10,0x38},
-{0xeb,0x04,0x10,0x18},
-{0xf7,0x06,0x19,0x14},
-{0x00,0xf4,0x10,0x38},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x15,0x25,0xf6},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xeb,0x04,0x25,0x18},
-{0xff,0xff,0xff,0xff}};
+	{0x00,0xf4,0x10,0x38},
+	{0x00,0xf4,0x10,0x38},
+	{0xeb,0x04,0x10,0x18},
+	{0xf7,0x06,0x19,0x14},
+	{0x00,0xf4,0x10,0x38},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x15,0x25,0xf6},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xeb,0x04,0x25,0x18},
+	{0xff,0xff,0xff,0xff}
+};
 
 
 UCHAR SiS310_PALMFilter2[9][7]={
-{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
-{0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
-{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
-{0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
-{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
-{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
-{0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
-{0x01,0x01,0xFC,0xF8,0x08,0x26,0x38},
-{0xFF,0xFF,0xFC,0x00,0x0F,0x22,0x28}};
+	{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
+	{0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
+	{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
+	{0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
+	{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
+	{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
+	{0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
+	{0x01,0x01,0xFC,0xF8,0x08,0x26,0x38},
+	{0xFF,0xFF,0xFC,0x00,0x0F,0x22,0x28}
+};
 
 UCHAR SiS310_PALNFilter2[9][7]={
-{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
-{0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
-{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
-{0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
-{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
-{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
-{0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
-{0x01,0x01,0xFC,0xF8,0x08,0x26,0x38},
-{0xFF,0xFF,0xFC,0x00,0x0F,0x22,0x28}};
+	{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
+	{0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
+	{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
+	{0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
+	{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
+	{0xFF,0x03,0x02,0xF6,0xFC,0x27,0x46},
+	{0x01,0x02,0xFE,0xF7,0x03,0x27,0x3C},
+	{0x01,0x01,0xFC,0xF8,0x08,0x26,0x38},
+	{0xFF,0xFF,0xFC,0x00,0x0F,0x22,0x28}
+};
 
 /*end PALMN*/
 UCHAR SiS310_TVPhaseIncr1[3][2][4]=
diff -urN linux-2.4.19-pre9/drivers/video/sis/sis_main.c linux-2.4.19-pre10/drivers/video/sis/sis_main.c
--- linux-2.4.19-pre9/drivers/video/sis/sis_main.c	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/video/sis/sis_main.c	Mon Jun  3 18:50:56 2002
@@ -1,16 +1,23 @@
-/* * SiS 300/630/540/315H/315 frame buffer device For Kernal 2.4.x
+/*
+ * SiS 300/630/730/540/315/550/650/740 frame buffer device
+ * for Linux kernels 2.4.x and 2.5.x
  *
- * This driver is partly based on the VBE 2.0 compliant graphic 
- * boards framebuffer driver, which is 
- * 
- * (c) 1998 Gerd Knorr <kraxel@goldbach.in-berlin.de>
+ * Partly based on the VBE 2.0 compliant graphic boards framebuffer driver,
+ * which is (c) 1998 Gerd Knorr <kraxel@goldbach.in-berlin.de>
  *
- * Comments and changes marked with "TW" by Thomas Winischhofer <tw@webit.com>
+ * Authors:   	SiS (www.sis.com.tw)
+ *		(Various others)
+ *		Thomas Winischhofer <thomas@winischhofer.net>:
+ *			- many fixes and enhancements for 630 & 310 series,
+ *			- extended bridge handling, TV output for Chrontel
+ *			- memory queue handling enhancements,
+ *			- everything marked with "TW"
+ *			(see http://www.winischhofer.net/linuxsis630.shtml
+ *			for more information and updates)
  */
 
-//#undef SISFBDEBUG
-
 #include <linux/config.h>
+#include <linux/version.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
@@ -29,10 +36,9 @@
 #include <linux/capability.h>
 #include <linux/fs.h>
 #include <linux/agp_backend.h>
-// Eden Chen
+
 #include <linux/types.h>
 #include <linux/sisfb.h>
-// ~Eden Chen
 
 #include <asm/io.h>
 #include <asm/mtrr.h>
@@ -43,11 +49,8 @@
 #include <video/fbcon-cfb24.h>
 #include <video/fbcon-cfb32.h>
 
-// Eden Chen
-//#include "sis.h"
 #include "osdef.h"
 #include "vgatypes.h"
-// ~Eden Chen
 #include "sis_main.h"
 //#ifdef LINUXBIOS
 //#include "bios.h"
@@ -105,7 +108,6 @@
 	u8 data;
 
 	data = inb(port);
-
 	return (data);
 }
 
@@ -145,14 +147,14 @@
 	static unsigned char init = 0, valid_pdev = 0;
 
 	if (!set)
-		DPRINTK("Get VGA offset 0x%lx\n", offset);
+		DPRINTK("sisfb: Get VGA offset 0x%lx\n", offset);
 	else
-		DPRINTK("Set offset 0x%lx to 0x%lx\n", offset, *value);
+		DPRINTK("sisfb: Set offset 0x%lx to 0x%lx\n", offset, *value);
 
 	if (!init) {
 		init = TRUE;
 		pci_for_each_dev(pdev) {
-			DPRINTK("Current: 0x%x, target: 0x%x\n",
+			DPRINTK("sisfb: Current: 0x%x, target: 0x%x\n",
 			         pdev->device, ivideo.chip_id);
 			if ((pdev->vendor == PCI_VENDOR_ID_SI)
 			           && (pdev->device == ivideo.chip_id)) {
@@ -163,7 +165,7 @@
 	}
 
 	if (!valid_pdev) {
-		printk(KERN_DEBUG "Can't find SiS %d VGA device.\n",
+		printk(KERN_DEBUG "sisfb: Can't find SiS %d VGA device.\n",
 				ivideo.chip_id);
 		return FALSE;
 	}
@@ -218,7 +220,7 @@
 	}
 
 	if (!valid_pdev) {
-		printk(KERN_DEBUG "Can't find SiS %d North Bridge device.\n",
+		printk(KERN_DEBUG "sisfb: Can't find SiS %d North Bridge device.\n",
 				nbridge_id);
 		return FALSE;
 	}
@@ -294,17 +296,15 @@
 		}
 		i++;
 	}
-
 	if (sisfb_mode_idx < 0)
-		DPRINTK("Invalid user mode : %s\n", name);
+		printk(KERN_INFO "sisfb: Invalid mode '%s'\n", name);
 }
 
 static void sisfb_validate_mode(void)
 {
 	switch (ivideo.disp_state & DISPTYPE_DISP2) {
 	case DISPTYPE_LCD:
-// Eden Chen
-		switch (sishw_ext.ulCRT2LCDType) {
+	    switch (sishw_ext.ulCRT2LCDType) {
 		case LCD_1024x768:
 			if (sisbios_mode[sisfb_mode_idx].xres > 1024)
 				sisfb_mode_idx = -1;
@@ -334,15 +334,18 @@
 			if (sisbios_mode[sisfb_mode_idx].xres > 640)
 				sisfb_mode_idx = -1;
 			break;
+		case LCD_320x480:	/* TW: FSTN */
+			if (sisbios_mode[sisfb_mode_idx].xres > 320)
+				sisfb_mode_idx = -1;
+			break;
 		default:
 			sisfb_mode_idx = -1;
 		}
-// ~Eden Chen
 		if (sisbios_mode[sisfb_mode_idx].xres == 720)
 			sisfb_mode_idx = -1;
 		break;
 	case DISPTYPE_TV:
-		switch (sisbios_mode[sisfb_mode_idx].xres) {
+	    switch (sisbios_mode[sisfb_mode_idx].xres) {
 		case 800:
 		case 640:
 			break;
@@ -354,14 +357,24 @@
 				if (sisbios_mode[sisfb_mode_idx].yres != 576)
 					sisfb_mode_idx = -1;
 			}
+			/* TW: LVDS/CHRONTEL only supports 640 and 800 */
+			if (ivideo.hasVB == HASVB_LVDS_CHRONTEL ||
+						ivideo.hasVB == HASVB_CHRONTEL)
+					sisfb_mode_idx = -1;
 			break;
-		/*karl*/
 		case 1024:
 			if (ivideo.TV_type == TVMODE_NTSC) {
 				if(sisbios_mode[sisfb_mode_idx].bpp == 32)
 				       sisfb_mode_idx = -1; /* TW; was -= 1 */
-			}
-			 break;
+				       /* TW: Should this mean a switch-back to
+				        *     16bpp or simply 'illegal mode'?
+					*/
+			}
+			/* TW: LVDS/CHRONTEL only supports 640 and 800 */
+			if (ivideo.hasVB == HASVB_LVDS_CHRONTEL ||
+						ivideo.hasVB == HASVB_CHRONTEL)
+					sisfb_mode_idx = -1;
+			break;
 		default:
 			sisfb_mode_idx = -1;
 		}
@@ -369,6 +382,42 @@
 	}
 }
 
+static void sisfb_search_crt2type(const char *name)
+{
+	int i = 0;
+
+	if (name == NULL)
+		return;
+
+	while (sis_crt2type[i].type_no != -1) {
+		if (!strcmp(name, sis_crt2type[i].name)) {
+			sisfb_crt2type = sis_crt2type[i].type_no;
+			break;
+		}
+		i++;
+	}
+	if (sisfb_crt2type < 0)
+		printk(KERN_INFO "sisfb: Invalid CRT2 type: %s\n", name);
+}
+
+static void sisfb_search_queuemode(const char *name)
+{
+	int i = 0;
+
+	if (name == NULL)
+		return;
+
+	while (sis_queuemode[i].type_no != -1) {
+		if (!strcmp(name, sis_queuemode[i].name)) {
+			sisfb_queuemode = sis_queuemode[i].type_no;
+			break;
+		}
+		i++;
+	}
+	if (sisfb_queuemode < 0)
+		printk(KERN_INFO "sisfb: Invalid queuemode type: %s\n", name);
+}
+
 static u8 sisfb_search_refresh_rate(unsigned int rate)
 {
 	u16 xres, yres;
@@ -385,13 +434,13 @@
 				break;
 			} else if (sisfb_vrate[i].refresh > rate) {
 				if ((sisfb_vrate[i].refresh - rate) <= 2) {
-					DPRINTK("Adjust rate from %d up to %d\n",
+					DPRINTK("sisfb: Adjusting rate from %d up to %d\n",
 						rate, sisfb_vrate[i].refresh);
 					sisfb_rate_idx = sisfb_vrate[i].idx;
 					ivideo.refresh_rate = sisfb_vrate[i].refresh;
 				} else if (((rate - sisfb_vrate[i-1].refresh) <= 2)
 						&& (sisfb_vrate[i].idx != 1)) {
-					DPRINTK("Adjust rate from %d down to %d\n",
+					DPRINTK("sisfb: Adjusting rate from %d down to %d\n",
 						rate, sisfb_vrate[i-1].refresh);
 					sisfb_rate_idx = sisfb_vrate[i-1].idx;
 					ivideo.refresh_rate = sisfb_vrate[i-1].refresh;
@@ -401,14 +450,13 @@
 		}
 		i++;
 	}
-
 	if (sisfb_rate_idx > 0) {
 		return sisfb_rate_idx;
 	} else {
-		DPRINTK("Unsupported rate %d for %dx%d mode\n", rate, xres, yres);
+		printk(KERN_INFO
+			"sisfb: Unsupported rate %d for %dx%d\n", rate, xres, yres);
 		return 0;
 	}
-
 }
 
 static int sis_getcolreg(unsigned regno, unsigned *red, unsigned *green, unsigned *blue,
@@ -427,7 +475,6 @@
 static int sis_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue,
 			 unsigned transp, struct fb_info *fb_info)
 {
-
 	if (regno >= video_cmap_len)
 		return 1;
 
@@ -509,7 +556,7 @@
 		         var->vsync_len;
 
 	if (!(htotal) || !(vtotal)) {
-		DPRINTK("Invalid 'var' Information!\n");
+		DPRINTK("sisfb: Invalid 'var' information\n");
 		return -EINVAL;
 	}
 
@@ -517,7 +564,7 @@
 	hrate = drate / htotal;
 	ivideo.refresh_rate = (unsigned int) (hrate / vtotal * 2 + 0.5);
 
-	DPRINTK("Change mode to %dx%dx%d-%dMHz\n",
+	DPRINTK("sisfb: Change mode to %dx%dx%d-%dMHz\n",
 		var->xres,var->yres,var->bits_per_pixel,ivideo.refresh_rate);
 
 	old_mode = sisfb_mode_idx;
@@ -541,7 +588,7 @@
 		sisfb_mode_idx = -1;
 
        	if (sisfb_mode_idx < 0) {
-		DPRINTK("sisfb does not support mode %dx%d-%d\n", var->xres,
+		DPRINTK("sisfb: sisfb does not support mode %dx%d-%d\n", var->xres,
 		       var->yres, var->bits_per_pixel);
 		sisfb_mode_idx = old_mode;
 		return -EINVAL;
@@ -556,35 +603,19 @@
 
 		sisfb_pre_setmode();
 
-// Eden Chen
-/*
-#ifdef CONFIG_FB_SIS_300
-		if (SiSSetMode(&sishw_ext, sisfb_mode_no)) {
-			DPRINTK("set mode[0x%x]: failed\n", sisfb_mode_no);
-			return -1;
-		}
-#endif
-
-#ifdef CONFIG_FB_SIS_315
-		if (SiSSetMode310(&sishw_ext, sisfb_mode_no)) {
-			DPRINTK("set mode[0x%x]: failed\n", sisfb_mode_no);
-			return -1;
-		}
-
-#endif
-*/
 		if (SiSSetMode(&sishw_ext, sisfb_mode_no) == 0) {
-			DPRINTK("set mode[0x%x]: failed\n", sisfb_mode_no);
+			DPRINTK("sisfb: Setting mode[0x%x]: failed\n", sisfb_mode_no);
 			return -1;
 		}
 
 		vgawb(SEQ_ADR, IND_SIS_PASSWORD);
 		vgawb(SEQ_DATA, SIS_PASSWORD);
-// ~Eden Chen
+
 		sisfb_post_setmode();
 
-		DPRINTK("Set new mode : %dx%dx%d-%d \n", sisbios_mode[sisfb_mode_idx].xres,
-			sisbios_mode[sisfb_mode_idx].yres, sisbios_mode[sisfb_mode_idx].bpp, ivideo.refresh_rate);
+		DPRINTK("sisfb: Set new mode: %dx%dx%d-%d \n", sisbios_mode[sisfb_mode_idx].xres,
+			sisbios_mode[sisfb_mode_idx].yres, sisbios_mode[sisfb_mode_idx].bpp,
+			ivideo.refresh_rate);
 
 		ivideo.video_bpp = sisbios_mode[sisfb_mode_idx].bpp;
 		ivideo.video_vwidth = ivideo.video_width = sisbios_mode[sisfb_mode_idx].xres;
@@ -592,7 +623,6 @@
 		ivideo.org_x = ivideo.org_y = 0;
 		video_linelength =
 		    ivideo.video_width * (ivideo.video_bpp >> 3);
-
 	}
 	return 0;
 }
@@ -626,30 +656,30 @@
 	save_flags(flags);
 	switch (ivideo.video_bpp) {
 #ifdef FBCON_HAS_CFB8
-	case 8:
+	   case 8:
 		sw = &fbcon_cfb8;
 		break;
 #endif
 #ifdef FBCON_HAS_CFB16
-	case 15:
-	case 16:
+	   case 15:
+	   case 16:
 		sw = &fbcon_cfb16;
 		display->dispsw_data = fbcon_cmap.cfb16;
 		break;
 #endif
 #ifdef FBCON_HAS_CFB24
-	case 24:
+	   case 24:
 		sw = &fbcon_cfb24;
 		display->dispsw_data = fbcon_cmap.cfb24;
 		break;
 #endif
 #ifdef FBCON_HAS_CFB32
-	case 32:
+	   case 32:
 		sw = &fbcon_cfb32;
 		display->dispsw_data = fbcon_cmap.cfb32;
 		break;
 #endif
-	default:
+	   default:
 		sw = &fbcon_dummy;
 		return;
 	}
@@ -685,29 +715,28 @@
 	u16 nbridge_id;
 
 	switch (ivideo.chip) {
-	case SIS_540:
+	   case SIS_540:
 		nbridge_id = PCI_DEVICE_ID_SI_540;
 		break;
-	case SIS_630:
+	   case SIS_630:
 		nbridge_id = PCI_DEVICE_ID_SI_630;
 		break;
-	case SIS_730:
+	   case SIS_730:
 		nbridge_id = PCI_DEVICE_ID_SI_730;
 		break;
-	default:
+	   default:
 		nbridge_id = 0;
 		break;
 	}
 
-	if (nbridge_id == 0) {
+	if (nbridge_id == 0) {  /* 300 */
 		vgawb(SEQ_ADR, IND_SIS_DRAM_SIZE);
 		ivideo.video_size =
 		        ((unsigned int) ((vgarb(SEQ_DATA) & SIS_DRAM_SIZE_MASK) + 1) << 20);
-	} else {
+	} else {		/* 540, 630, 730 */
 		pci_for_each_dev(pdev) {
 			if ((pdev->vendor == PCI_VENDOR_ID_SI) 
 				&& (pdev->device == nbridge_id)) {
-				//&& (pdev->device == PCI_DEVICE_ID_SI_630)) {
 				pci_read_config_byte(pdev, IND_BRI_DRAM_STATUS, &pci_data);
 				pci_data = (pci_data & BRI_DRAM_SIZE_MASK) >> 4;
 				ivideo.video_size = (unsigned int)(1 << (pci_data+21));
@@ -716,22 +745,22 @@
 				reg = SIS_DATA_BUS_64 << 6;
 				vgawb(SEQ_ADR, IND_SIS_DRAM_SIZE);
 				switch (pci_data) {
-				case BRI_DRAM_SIZE_2MB:
+				   case BRI_DRAM_SIZE_2MB:
 					reg |= SIS_DRAM_SIZE_2MB;
 					break;
-				case BRI_DRAM_SIZE_4MB:
+				   case BRI_DRAM_SIZE_4MB:
 					reg |= SIS_DRAM_SIZE_4MB;
 					break;
-				case BRI_DRAM_SIZE_8MB: 
+				   case BRI_DRAM_SIZE_8MB:
 					reg |= SIS_DRAM_SIZE_8MB;
 					break;
-				case BRI_DRAM_SIZE_16MB:
+				   case BRI_DRAM_SIZE_16MB:
 					reg |= SIS_DRAM_SIZE_16MB;
 					break;
-				case BRI_DRAM_SIZE_32MB:
+				   case BRI_DRAM_SIZE_32MB:
 					reg |= SIS_DRAM_SIZE_32MB;
 					break;
-				case BRI_DRAM_SIZE_64MB:
+				   case BRI_DRAM_SIZE_64MB:
 					reg |= SIS_DRAM_SIZE_64MB;
 					break;
 				}
@@ -743,7 +772,6 @@
 		if (!pdev_valid)
 			return -1;
 	}
-
 	return 0;
 }
 
@@ -766,71 +794,94 @@
 			else
 				sisfb_crt1off = 0;
 		}
-		
-		if (sr17 & 0x08 )
+
+		if (sisfb_crt2type != -1)
+			/* TW: override detected CRT2 type */
+			ivideo.disp_state = sisfb_crt2type;
+		else if (sr17 & 0x08 )
 			ivideo.disp_state = DISPTYPE_CRT2;
 		else if (sr17 & 0x02)
 			ivideo.disp_state = DISPTYPE_LCD;
-		else if (sr17 & 0x04) {
+		else if (sr17 & 0x04)
 			ivideo.disp_state = DISPTYPE_TV;
-			if (sr17 & 0x20)
-				ivideo.TV_plug = TVPLUG_SVIDEO;
-			else if (sr17 & 0x10)
-				ivideo.TV_plug = TVPLUG_COMPOSITE;
-
-			vgawb(SEQ_ADR, IND_SIS_SCRATCH_REG_16);
-			sr16 = vgarb(SEQ_DATA);
-			if (sr16 & 0x20)
-				ivideo.TV_type = TVMODE_PAL;
-			else
-				ivideo.TV_type = TVMODE_NTSC;
-		} else
+		else
 			ivideo.disp_state = 0;
+
+		if (sr17 & 0x20)
+			ivideo.TV_plug = TVPLUG_SVIDEO;
+		else if (sr17 & 0x10)
+			ivideo.TV_plug = TVPLUG_COMPOSITE;
+
+		vgawb(SEQ_ADR, IND_SIS_SCRATCH_REG_16);
+		sr16 = vgarb(SEQ_DATA);
+		if (sr16 & 0x20)
+			ivideo.TV_type = TVMODE_PAL;
+		else
+			ivideo.TV_type = TVMODE_NTSC;
 	} else {
 		if ((cr32 & SIS_CRT1) && !sisfb_crt1off)
 			sisfb_crt1off = 0;
 		else {
-			if (cr32 & 0x5F)   
+			if (cr32 & 0x5F)
 				sisfb_crt1off = 1;
 			else
 				sisfb_crt1off = 0;
 		}
 
-		if (cr32 & SIS_VB_CRT2)
+		if (sisfb_crt2type != -1)
+			/* TW: override detected CRT2 type */
+			ivideo.disp_state = sisfb_crt2type;
+		else if (cr32 & SIS_VB_CRT2)
 			ivideo.disp_state = DISPTYPE_CRT2;
 		else if (cr32 & SIS_VB_LCD)
 			ivideo.disp_state = DISPTYPE_LCD;
-		else if (cr32 & SIS_VB_TV) {
+		else if (cr32 & SIS_VB_TV)
 			ivideo.disp_state = DISPTYPE_TV;
-			if (cr32 & SIS_VB_HIVISION) {
-				ivideo.TV_type = TVMODE_HIVISION;
-				ivideo.TV_plug = TVPLUG_SVIDEO;
-			}
-			else if (cr32 & SIS_VB_SVIDEO)
-				ivideo.TV_plug = TVPLUG_SVIDEO;
-			else if (cr32 & SIS_VB_COMPOSITE)
-				ivideo.TV_plug = TVPLUG_COMPOSITE;
-			else if (cr32 & SIS_VB_SCART)
-				ivideo.TV_plug = TVPLUG_SCART;
+		else
+			ivideo.disp_state = 0;
 
-			if (ivideo.TV_type == 0) {
-				// Eden Chen
-				//temp = *((u8 *)(sishw_ext.VirtualRomBase+0x52));
-				//if (temp&0x40) {
-				//	temp=*((u8 *)(sishw_ext.VirtualRomBase+0x53));
+		/* TW: Detect TV plug & type anyway */
+		if (cr32 & SIS_VB_HIVISION) {
+			ivideo.TV_type = TVMODE_HIVISION;
+			ivideo.TV_plug = TVPLUG_SVIDEO;
+		}
+		else if (cr32 & SIS_VB_SVIDEO)
+			ivideo.TV_plug = TVPLUG_SVIDEO;
+		else if (cr32 & SIS_VB_COMPOSITE)
+			ivideo.TV_plug = TVPLUG_COMPOSITE;
+		else if (cr32 & SIS_VB_SCART)
+			ivideo.TV_plug = TVPLUG_SCART;
+
+		if (ivideo.TV_type == 0) {
+			// Eden Chen
+			//temp = *((u8 *)(sishw_ext.VirtualRomBase+0x52));
+			//if (temp&0x40) {
+			//	temp=*((u8 *)(sishw_ext.VirtualRomBase+0x53));
 				//} else {
-				vgawb(SEQ_ADR, IND_SIS_POWER_ON_TRAP);
-				temp = vgarb(SEQ_DATA);
-				//}
-				// ~Eden Chen
-				if (temp & 0x01)
-					ivideo.TV_type = TVMODE_PAL;
-				else
-					ivideo.TV_type = TVMODE_NTSC;
-			}
-		} else
-			ivideo.disp_state = 0;
+			vgawb(SEQ_ADR, IND_SIS_POWER_ON_TRAP);
+			temp = vgarb(SEQ_DATA);
+			//}
+			// ~Eden Chen
+			if (temp & 0x01)
+				ivideo.TV_type = TVMODE_PAL;
+			else
+				ivideo.TV_type = TVMODE_NTSC;
+		}
 	}
+
+	/* TW: Copy forceCRT1 option to CRT1off if option is given */
+    	if (sisfb_forcecrt1 != -1) {
+		vgawb(SEQ_ADR, IND_SIS_SCRATCH_REG_17);
+    		sr17 = vgarb(SEQ_DATA);
+    		if (sisfb_forcecrt1) {
+			sisfb_crt1off=0;
+			sr17 |= 0x80;
+		} else {
+			sisfb_crt1off=1;
+			sr17 &= ~0x80;
+		}
+		vgawb(SEQ_DATA, sr17);
+    	}
 }
 
 static void sisfb_get_VB_type_300(void)
@@ -843,29 +894,28 @@
 			reg = vgarb(CRTC_DATA);
 
 			switch ((reg & SIS_EXTERNAL_CHIP_MASK) >> 1) {
-			case SIS_EXTERNAL_CHIP_SIS301:
+			   case SIS_EXTERNAL_CHIP_SIS301:
 				ivideo.hasVB = HASVB_301;
 				break;
-			case SIS_EXTERNAL_CHIP_LVDS:
+			   case SIS_EXTERNAL_CHIP_LVDS:
 				ivideo.hasVB = HASVB_LVDS;
 				break;
-			case SIS_EXTERNAL_CHIP_TRUMPION:
+			   case SIS_EXTERNAL_CHIP_TRUMPION:
 				ivideo.hasVB = HASVB_TRUMPION;
 				break;
-			case SIS_EXTERNAL_CHIP_LVDS_CHRONTEL:
+			   case SIS_EXTERNAL_CHIP_LVDS_CHRONTEL:
 				ivideo.hasVB = HASVB_LVDS_CHRONTEL;
 				break;
-			case SIS_EXTERNAL_CHIP_CHRONTEL:
+			   case SIS_EXTERNAL_CHIP_CHRONTEL:
 				ivideo.hasVB = HASVB_CHRONTEL;
 				break;
-			default:
+			   default:
 				break;
 			}
 		}
 	} else {
 		sisfb_has_VB_300();
 	}
-
 	//sishw_ext.hasVB = ivideo.hasVB;
 }
 
@@ -883,16 +933,16 @@
 	vb_chipid = vgarb(VB_PART4_DATA);
         
 	switch (vb_chipid) {
-	case 0x01:
+	   case 0x01:
 		ivideo.hasVB = HASVB_301;
 		break;
-	case 0x02:
+	   case 0x02:
 		ivideo.hasVB = HASVB_302;
 		break;
-	case 0x03:
+	   case 0x03:
 		ivideo.hasVB = HASVB_303;
 		break;
-	default:
+	   default:
 		ivideo.hasVB = HASVB_NONE;
 		return FALSE;
 	}
@@ -920,57 +970,56 @@
 
 	// ~Eden Chen
 }
-
 #endif  /* CONFIG_FB_SIS_300 */
 
-#ifdef CONFIG_FB_SIS_315    /* for SiS 315H/315 */
+#ifdef CONFIG_FB_SIS_315    /* for SiS 315H/315PRO/550/650/740 */
 static int sisfb_get_dram_size_315(void)
 {
-#ifdef LINUXBIOS
 	struct pci_dev *pdev = NULL;
 	int pdev_valid = 0;
 	u8  pci_data;
-#endif
 	u8  reg = 0;
 
 	if (ivideo.chip == SIS_550 || ivideo.chip == SIS_650) {
 #ifdef LINUXBIOS
 		pci_for_each_dev(pdev) {
-			if ((pdev->vendor == PCI_VENDOR_ID_SI) 
-				&& (pdev->device == PCI_DEVICE_ID_SI_550)) {
+			if ( (pdev->vendor == PCI_VENDOR_ID_SI)
+				&& ( (pdev->device == PCI_DEVICE_ID_SI_550)
+				  || (pdev->device == PCI_DEVICE_ID_SI_650))) {
 				pci_read_config_byte(pdev, IND_BRI_DRAM_STATUS,
 				                     &pci_data);
 				pci_data = (pci_data & BRI_DRAM_SIZE_MASK) >> 4;
 				ivideo.video_size =
 				    (unsigned int)(1 << (pci_data+21));
 				pdev_valid = 1;
-	
+
+				/* TW: Initialize SR14 "by hand" */
 				vgawb(SEQ_ADR, IND_SIS_DRAM_SIZE);
 				reg = vgarb(SEQ_DATA) & 0xC0;
 
 				switch (pci_data) {
 				//case BRI_DRAM_SIZE_2MB:
 				//	reg |= (SIS315_DRAM_SIZE_2MB << 4); break;
-				case BRI_DRAM_SIZE_4MB:
+				   case BRI_DRAM_SIZE_4MB:
 					reg |= SIS550_DRAM_SIZE_4MB;
 					break;
-				case BRI_DRAM_SIZE_8MB: 
+				   case BRI_DRAM_SIZE_8MB:
 					reg |= SIS550_DRAM_SIZE_8MB;
 					break;
-				case BRI_DRAM_SIZE_16MB:
+				   case BRI_DRAM_SIZE_16MB:
 					reg |= SIS550_DRAM_SIZE_16MB;
 					break;
-				case BRI_DRAM_SIZE_32MB:
+				   case BRI_DRAM_SIZE_32MB:
 					reg |= SIS550_DRAM_SIZE_32MB;
 					break;
-				case BRI_DRAM_SIZE_64MB:
+				   case BRI_DRAM_SIZE_64MB:
 					reg |= SIS550_DRAM_SIZE_64MB;
 					break;
-				/* case BRI_DRAM_SIZE_128MB:
+				   /* case BRI_DRAM_SIZE_128MB:
 					reg |= (SIS315_DRAM_SIZE_128MB << 4); break; */
 				}
 
-			     /* TODO : set Dual channel and bus width bits here */
+			        /* TODO : set Dual channel and bus width bits here */
 
 				vgawb(SEQ_DATA, reg);
 				break;
@@ -983,64 +1032,101 @@
 		vgawb(SEQ_ADR, IND_SIS_DRAM_SIZE);
 		reg = vgarb(SEQ_DATA);
 		switch (reg & SIS550_DRAM_SIZE_MASK) {
-		case SIS550_DRAM_SIZE_4MB:
-			ivideo.video_size = 0x400000;
-			break;
-		case SIS550_DRAM_SIZE_8MB:
-			ivideo.video_size = 0x800000;
-			break;
-		case SIS550_DRAM_SIZE_16MB:
-			ivideo.video_size = 0x1000000;
-			break;
-		case SIS550_DRAM_SIZE_24MB:
-			ivideo.video_size = 0x1800000;
-			break;
-		case SIS550_DRAM_SIZE_32MB:
-			ivideo.video_size = 0x2000000;
-			break;
-		case SIS550_DRAM_SIZE_64MB:
-			ivideo.video_size = 0x4000000;
-			break;
-		case SIS550_DRAM_SIZE_96MB:
-			ivideo.video_size = 0x6000000;
-			break;
-		case SIS550_DRAM_SIZE_128MB:
-			ivideo.video_size = 0x8000000;
-			break;
-		case SIS550_DRAM_SIZE_256MB:
-			ivideo.video_size = 0x10000000;
-			break;
-		default:
-			return -1;
+		   case SIS550_DRAM_SIZE_4MB:
+			ivideo.video_size = 0x400000;   break;
+		   case SIS550_DRAM_SIZE_8MB:
+			ivideo.video_size = 0x800000;   break;
+		   case SIS550_DRAM_SIZE_16MB:
+			ivideo.video_size = 0x1000000;  break;
+		   case SIS550_DRAM_SIZE_24MB:
+			ivideo.video_size = 0x1800000;  break;
+		   case SIS550_DRAM_SIZE_32MB:
+			ivideo.video_size = 0x2000000;	break;
+		   case SIS550_DRAM_SIZE_64MB:
+			ivideo.video_size = 0x4000000;	break;
+		   case SIS550_DRAM_SIZE_96MB:
+			ivideo.video_size = 0x6000000;	break;
+		   case SIS550_DRAM_SIZE_128MB:
+			ivideo.video_size = 0x8000000;	break;
+		   case SIS550_DRAM_SIZE_256MB:
+			ivideo.video_size = 0x10000000;	break;
+		   default:
+		        /* TW: Some 550 BIOSes don't seem to initialize SR14 correctly (if at all),
+			 *     do it the hard way ourselves in this case. Unfortunately, we don't
+			 *     support 24, 48, 96 and other "odd" amounts here. I don't know if
+			 *     this work-around is required for 650/740 as well, but do it in case
+			 *     for now.
+			 */
+		        printk(KERN_INFO
+			       "sisfb: Warning: Could not determine memory size, "
+			       "now reading from PCI config\n");
+			pdev_valid = 0;
+			pci_for_each_dev(pdev) {
+			   if ( (pdev->vendor == PCI_VENDOR_ID_SI)
+			         && (    (pdev->device == PCI_DEVICE_ID_SI_550)
+				      || (pdev->device == PCI_DEVICE_ID_SI_650) ) ) {
+				pci_read_config_byte(pdev, IND_BRI_DRAM_STATUS,
+				                     &pci_data);
+				pci_data = (pci_data & BRI_DRAM_SIZE_MASK) >> 4;
+				ivideo.video_size = (unsigned int)(1 << (pci_data+21));
+				pdev_valid = 1;
+				/* TW: Initialize SR14=IND_SIS_DRAM_SIZE */
+				vgawb(SEQ_ADR, IND_SIS_DRAM_SIZE);
+				reg = vgarb(SEQ_DATA) & 0xC0;
+				switch (pci_data) {
+				   case BRI_DRAM_SIZE_4MB:
+					reg |= SIS550_DRAM_SIZE_4MB;  break;
+				   case BRI_DRAM_SIZE_8MB:
+					reg |= SIS550_DRAM_SIZE_8MB;  break;
+				   case BRI_DRAM_SIZE_16MB:
+					reg |= SIS550_DRAM_SIZE_16MB; break;
+				   case BRI_DRAM_SIZE_32MB:
+					reg |= SIS550_DRAM_SIZE_32MB; break;
+				   case BRI_DRAM_SIZE_64MB:
+					reg |= SIS550_DRAM_SIZE_64MB; break;
+				   /* case BRI_DRAM_SIZE_128MB:
+					reg |= (SIS315_DRAM_SIZE_128MB << 4); break; */
+				   default:
+				   	printk(KERN_INFO "sisfb: Unable to determine memory size, giving up.\n");
+					return -1;
+				}
+				vgawb(SEQ_DATA, reg);
+			   }
+			}
+			if (!pdev_valid) {
+				printk(KERN_INFO "sisfb: Total confusion - No SiS PCI VGA device found?!\n");
+				return -1;
+			}
+			return 0;
 		}
 #endif
 		return 0;
-	} else {
+	} else {	/* 315 */
 		vgawb(SEQ_ADR, IND_SIS_DRAM_SIZE);
 		reg = vgarb(SEQ_DATA);
 		switch ((reg & SIS315_DRAM_SIZE_MASK) >> 4) {
-		case SIS315_DRAM_SIZE_2MB:   
+		   case SIS315_DRAM_SIZE_2MB:
 			ivideo.video_size = 0x200000;
 			break;
-		case SIS315_DRAM_SIZE_4MB:   
+		   case SIS315_DRAM_SIZE_4MB:
 			ivideo.video_size = 0x400000;
 			break;
-		case SIS315_DRAM_SIZE_8MB:   
+		   case SIS315_DRAM_SIZE_8MB:
 			ivideo.video_size = 0x800000;
 			break;
-		case SIS315_DRAM_SIZE_16MB:
+		   case SIS315_DRAM_SIZE_16MB:
 			ivideo.video_size = 0x1000000;
 			break;
-		case SIS315_DRAM_SIZE_32MB:   
+		   case SIS315_DRAM_SIZE_32MB:
 			ivideo.video_size = 0x2000000;
 			break;
-		case SIS315_DRAM_SIZE_64MB:   
+		   case SIS315_DRAM_SIZE_64MB:
 			ivideo.video_size = 0x4000000;
 			break;
-		case SIS315_DRAM_SIZE_128MB:   
+		   case SIS315_DRAM_SIZE_128MB:
 			ivideo.video_size = 0x8000000;
 			break;
-		default:
+		   default:
 			return -1;
 		}
 	}
@@ -1048,12 +1134,15 @@
 	reg &= SIS315_DUAL_CHANNEL_MASK;
 	reg >>= 2;
 	switch (reg) {
-	case SIS315_SINGLE_CHANNEL_2_RANK:  
+	   case SIS315_SINGLE_CHANNEL_2_RANK:
 		ivideo.video_size <<= 1;
 		break;
-	case SIS315_DUAL_CHANNEL_1_RANK:  
+	   case SIS315_DUAL_CHANNEL_1_RANK:
 		ivideo.video_size <<= 1;
 		break;
+	   case SIS315_ASYM_DDR:		/* TW: DDR asymentric */
+		ivideo.video_size += ivideo.video_size/2;
+		break;
 	}
 
 	return 0;
@@ -1061,7 +1150,7 @@
 
 static void sisfb_detect_VB_connect_315(void)
 {
-	u8 cr32, temp;
+	u8 sr17, cr32, temp;
 
 	vgawb(CRTC_ADR, IND_SIS_SCRATCH_REG_CR32);
 	cr32 = vgarb(CRTC_DATA);
@@ -1076,58 +1165,112 @@
 			sisfb_crt1off = 0;
 	}
 
-	if (cr32 & SIS_VB_CRT2)
+	if (sisfb_crt2type != -1)
+		/* TW: Override with option */
+		ivideo.disp_state = sisfb_crt2type;
+	else if (cr32 & SIS_VB_CRT2)
 		ivideo.disp_state = DISPTYPE_CRT2;
 	else if (cr32 & SIS_VB_LCD)
 		ivideo.disp_state = DISPTYPE_LCD;
-	else if (cr32 & SIS_VB_TV) {
+	else if (cr32 & SIS_VB_TV)
 		ivideo.disp_state = DISPTYPE_TV;
-		if (cr32 & SIS_VB_HIVISION) {
-			ivideo.TV_type = TVMODE_HIVISION;
-			ivideo.TV_plug = TVPLUG_SVIDEO;
-		} else if (cr32 & SIS_VB_SVIDEO)
-			ivideo.TV_plug = TVPLUG_SVIDEO;
-		else if (cr32 & SIS_VB_COMPOSITE)
-			ivideo.TV_plug = TVPLUG_COMPOSITE;
-		else if (cr32 & SIS_VB_SCART)
-			ivideo.TV_plug = TVPLUG_SCART;
+	else
+		ivideo.disp_state = 0;
 
-		if (ivideo.TV_type == 0) {
-			vgawb(SEQ_ADR, IND_SIS_POWER_ON_TRAP);
-			temp = vgarb(SEQ_DATA);
+	if (cr32 & SIS_VB_HIVISION) {
+		ivideo.TV_type = TVMODE_HIVISION;
+		ivideo.TV_plug = TVPLUG_SVIDEO;
+	} else if (cr32 & SIS_VB_SVIDEO)
+		ivideo.TV_plug = TVPLUG_SVIDEO;
+	else if (cr32 & SIS_VB_COMPOSITE)
+		ivideo.TV_plug = TVPLUG_COMPOSITE;
+	else if (cr32 & SIS_VB_SCART)
+		ivideo.TV_plug = TVPLUG_SCART;
+
+	if (ivideo.TV_type == 0) {
+		vgawb(SEQ_ADR, IND_SIS_POWER_ON_TRAP);
+		temp = vgarb(SEQ_DATA);
+		if (temp & 0x01)
+			ivideo.TV_type = TVMODE_PAL;
+		else
+			ivideo.TV_type = TVMODE_NTSC;
+	}
 
-			if (temp & 0x01)
-				ivideo.TV_type = TVMODE_PAL;
-			else
-				ivideo.TV_type = TVMODE_NTSC;
+	/* TW: Copy forceCRT1 option to CRT1off if option is given */
+    	if (sisfb_forcecrt1 != -1) {
+		vgawb(SEQ_ADR, IND_SIS_SCRATCH_REG_17);
+    		sr17 = vgarb(SEQ_DATA);
+    		if (sisfb_forcecrt1) {
+			sisfb_crt1off=0;
+			sr17 |= 0x80;
+		} else {
+			sisfb_crt1off=1;
+			sr17 &= ~0x80;
 		}
-	} else 
-		ivideo.disp_state = 0;
+		vgawb(SEQ_DATA, sr17);
+    	}
 }
 
 static void sisfb_get_VB_type_315(void)
 {
+	u8 reg;
+
+	/* 550 has LVDS-like FSTN bridge (?) */
+	if (ivideo.chip == SIS_550) {
+		if (!sisfb_has_VB_315()) {
+			vgawb(CRTC_ADR, IND_SIS_SCRATCH_REG_CR37);
+			reg = vgarb(CRTC_DATA);
+
+			switch ((reg & SIS_EXTERNAL_CHIP_MASK) >> 1) {
+			   case SIS_EXTERNAL_CHIP_SIS301:
+				ivideo.hasVB = HASVB_301;
+				break;
+			   case SIS_EXTERNAL_CHIP_LVDS:
+				ivideo.hasVB = HASVB_LVDS;
+				break;
+			   case SIS_EXTERNAL_CHIP_TRUMPION:
+				ivideo.hasVB = HASVB_TRUMPION;
+				break;
+			   case SIS_EXTERNAL_CHIP_LVDS_CHRONTEL:
+				ivideo.hasVB = HASVB_LVDS_CHRONTEL;
+				break;
+			   case SIS_EXTERNAL_CHIP_CHRONTEL:
+				ivideo.hasVB = HASVB_CHRONTEL;
+				break;
+			   default:
+				break;
+			}
+		}
+	} else {
+		sisfb_has_VB_315();
+	}
+}
+
+static int sisfb_has_VB_315(void)
+{
 	u8 vb_chipid;
 
 	vgawb(VB_PART4_ADR, 0x0);
 	vb_chipid = vgarb(VB_PART4_DATA);
 
 	switch (vb_chipid) {
-	case 0x01:
+	   case 0x01:
 		ivideo.hasVB = HASVB_301;
 		break;
-	case 0x02:
+	   case 0x02:
 		ivideo.hasVB = HASVB_302;
 		break;
-	case 0x03:
+	   case 0x03:
 		ivideo.hasVB = HASVB_303;
 		break;
-	default:
+	   default:
 		ivideo.hasVB = HASVB_NONE;
+		return FALSE;
 	}
 	// Eden Chen
 	//sishw_ext.hasVB = ivideo.hasVB;
 	// ~Eden Chen
+	return TRUE;
 }
 #endif   /* CONFIG_FB_SIS_315 */
 
@@ -1153,8 +1296,8 @@
 /* TW: If more than 8MB videoRAM detected, let our heap start at 8MB. If
  *     there is less RAM available, let it start at 4MB. This can be overruled
  *     by mem parameter.
- *     This is for avoiding a clash with X driver which uses beginning
- *     of videoRAM. To limit size of X framebuffer, use Option MaxXFBMem
+ *     This is for avoiding a clash with X driver which uses the beginning
+ *     of the videoRAM. To limit size of X framebuffer, use Option MaxXFBMem
  *     in XF86Config-4.
  *     The heap start can also be specified by parameter "mem" when starting the sisfb
  *     driver. sisfb mem=1024 lets heap starts at 1MB, etc.
@@ -1181,6 +1324,37 @@
 
 #ifdef CONFIG_FB_SIS_315
      if (sisvga_engine == SIS_315_VGA) {
+        /* TW: Now initlalize the 310 series' command queue mode.
+	 * On 310, there are three queue modes available which
+	 *     are chosen by setting bits 7:5 in SR26:
+	 * 1. MMIO queue mode (bit 5, 0x20). The hardware will keep
+	 *    track of the queue, the FIFO, command parsing and so
+	 *    on. This is the one comparable to the 300 series.
+	 * 2. VRAM queue mode (bit 6, 0x40). In this case, one will
+	 *    have to do queue management himself. Register 0x85c4 will
+	 *    hold the location of the next free queue slot, 0x85c8
+	 *    is the "queue read pointer" whose way of working is
+	 *    unknown to me. Anyway, this mode would require a
+	 *    translation of the MMIO commands to some kind of
+	 *    accelerator assembly and writing these commands
+	 *    to the memory location pointed to by 0x85c4.
+	 *    We will not use this, as nobody knows how this
+	 *    "assembly" works, and as it would require a complete
+	 *    re-write of the accelerator code.
+	 * 3. AGP queue mode (bit 7, 0x80). Works as 2., but keeps the
+	 *    queue in AGP memory space.
+	 *
+	 * SR26 bit 4 is called "Bypass H/W queue".
+	 * SR26 bit 1 is called "Enable Command Queue Auto Correction"
+	 * SR26 bit 0 resets the queue
+	 * Size of queue memory is encoded in bits 3:2 like this:
+	 *    00  (0x00)  512K
+	 *    01  (0x04)  1M
+	 *    10  (0x08)  2M
+	 *    11  (0x0C)  4M
+	 * The queue location is to be written to 0x85C0.
+	 *
+         */
 	cmdq_baseport = (unsigned long *)(ivideo.mmio_vbase + MMIO_QUEUE_PHYBASE);
 	write_port    = (unsigned long *)(ivideo.mmio_vbase + MMIO_QUEUE_WRITEPORT);
 	read_port     = (unsigned long *)(ivideo.mmio_vbase + MMIO_QUEUE_READPORT);
@@ -1190,55 +1364,65 @@
 	agp_size  = COMMAND_QUEUE_AREA_SIZE;
 
 #ifndef AGPOFF
-
-	agp_info = vmalloc(sizeof(agp_kern_info));
-	memset((void*)agp_info, 0x00, sizeof(agp_kern_info));
-	agp_copy_info(agp_info);
-
-	agp_backend_acquire();
-
-	agp = agp_allocate_memory(COMMAND_QUEUE_AREA_SIZE/PAGE_SIZE, AGP_NORMAL_MEMORY);
-	if (agp == NULL) {
-		DPRINTK("Allocate AGP buffer failed.\n");
-		agp_enabled = 0;
-	} else {
-		if (agp_bind_memory(agp, agp->pg_start) != 0) {
-			DPRINTK("AGP : can not bind memory\n");
+	if (sisfb_queuemode == AGP_CMD_QUEUE) {
+		agp_info = vmalloc(sizeof(agp_kern_info));
+		memset((void*)agp_info, 0x00, sizeof(agp_kern_info));
+		agp_copy_info(agp_info);
+
+		agp_backend_acquire();
+
+		agp = agp_allocate_memory(COMMAND_QUEUE_AREA_SIZE/PAGE_SIZE,
+					  AGP_NORMAL_MEMORY);
+		if (agp == NULL) {
+			DPRINTK("sisfb: Allocating AGP buffer failed.\n");
 			agp_enabled = 0;
 		} else {
-			agp_enable(0);
+			if (agp_bind_memory(agp, agp->pg_start) != 0) {
+				DPRINTK("sisfb: AGP: Failed to bind memory\n");
+				/* TODO: Free AGP memory here */
+				agp_enabled = 0;
+			} else {
+				agp_enable(0);
+			}
 		}
 	}
-
 #else
 	agp_enabled= 0;
 #endif
-	if (agp_enabled)
+
+	/* TW: Now select the queue mode */
+
+	if ((agp_enabled) && (sisfb_queuemode == AGP_CMD_QUEUE)) {
 		cmd_type = AGP_CMD_QUEUE;
-	else if (sisfb_heap_size >= COMMAND_QUEUE_AREA_SIZE)
+		printk(KERN_INFO "sisfb: Using AGP queue mode\n");
+/*	} else if (sisfb_heap_size >= COMMAND_QUEUE_AREA_SIZE)  */
+        } else if (sisfb_queuemode == VM_CMD_QUEUE) {
 		cmd_type = VM_CMD_QUEUE;
-	else
+		printk(KERN_INFO "sisfb: Using VRAM queue mode\n");
+	} else {
+		printk(KERN_INFO "sisfb: Using MMIO queue mode\n");
 		cmd_type = MMIO_CMD;
+	}
 
 	switch (agp_size) {
-	case 0x80000:
+	   case 0x80000:
 		temp = SIS_CMD_QUEUE_SIZE_512k;
 		break;
-	case 0x100000:
+	   case 0x100000:
 		temp = SIS_CMD_QUEUE_SIZE_1M;
 		break;
-	case 0x200000:
+	   case 0x200000:
 		temp = SIS_CMD_QUEUE_SIZE_2M;
 		break;
-	case 0x400000:	
+	   case 0x400000:
 		temp = SIS_CMD_QUEUE_SIZE_4M;
 		break;
 	}
 
 	switch (cmd_type) {
-	case AGP_CMD_QUEUE:
+	   case AGP_CMD_QUEUE:
 #ifndef AGPOFF
-		DPRINTK("AGP buffer base:0x%lx, offset:0x%x, size is %dK\n", 
+		DPRINTK("sisfb: AGP buffer base:0x%lx, offset:0x%x, size: %dK\n",
 			agp_info->aper_base, agp->physical, agp_size/1024);
 
 		agp_phys = agp_info->aper_base + agp->physical;
@@ -1265,7 +1449,7 @@
 #endif
 		break;
 
-	case VM_CMD_QUEUE:
+	   case VM_CMD_QUEUE:
 		sisfb_heap_end -= COMMAND_QUEUE_AREA_SIZE;
 		sisfb_heap_size -= COMMAND_QUEUE_AREA_SIZE;
 
@@ -1285,12 +1469,37 @@
 
 		sisfb_caps |= VM_CMD_QUEUE_CAP;
 
-		DPRINTK("VM Cmd Queue offset = 0x%lx, size is %dK\n", 
+		DPRINTK("sisfb: VM Cmd Queue offset = 0x%lx, size is %dK\n",
 			*cmdq_baseport, COMMAND_QUEUE_AREA_SIZE/1024);
 		break;
-	default:
+
+	   default:  /* MMIO */
+	   	/* TW: This previously only wrote SIS_MMIO_CMD_ENABLE
+		 * to IND_SIS_CMDQUEUE_SET. I doubt that this is
+		 * enough. Reserve memory in any way.
+		 */
+	   	sisfb_heap_end -= COMMAND_QUEUE_AREA_SIZE;
+		sisfb_heap_size -= COMMAND_QUEUE_AREA_SIZE;
+
+		vgawb(SEQ_ADR, IND_SIS_CMDQUEUE_THRESHOLD);
+		vgawb(SEQ_DATA, COMMAND_QUEUE_THRESHOLD);
+
 		vgawb(SEQ_ADR, IND_SIS_CMDQUEUE_SET);
-		vgawb(SEQ_DATA, SIS_MMIO_CMD_ENABLE);
+		vgawb(SEQ_DATA, SIS_CMD_QUEUE_RESET);
+
+		*write_port = *read_port;
+
+		/* TW: Set Auto_Correction bit; this works in sisfb lite,
+		 * so why not.
+		 */
+		temp |= (SIS_MMIO_CMD_ENABLE | SIS_CMD_AUTO_CORR);
+		vgawb(SEQ_ADR, IND_SIS_CMDQUEUE_SET);
+		vgawb(SEQ_DATA, temp);
+
+		*cmdq_baseport = ivideo.video_size - COMMAND_QUEUE_AREA_SIZE;
+
+		DPRINTK("sisfb: MMIO Cmd Queue offset = 0x%lx, size is %dK\n",
+			*cmdq_baseport, COMMAND_QUEUE_AREA_SIZE/1024);
 		break;
 	}
      } /* sisvga_engine = 315 */
@@ -1298,8 +1507,8 @@
 
 #ifdef CONFIG_FB_SIS_300
      if (sisvga_engine == SIS_300_VGA) {
-  	    /* TW: Now initialize TurboQueue. TB is always located at the very top of the
-       		   videoRAM. */
+  	    /* TW: Now initialize TurboQueue. TB is always located at the very
+	     * top of the video RAM. */
 	    if (sisfb_heap_size >= TURBO_QUEUE_AREA_SIZE) {
 		unsigned int  tqueue_pos;
 		u8 tq_state;
@@ -1320,12 +1529,12 @@
 
 		sisfb_heap_end -= TURBO_QUEUE_AREA_SIZE;
 		sisfb_heap_size -= TURBO_QUEUE_AREA_SIZE;
-		DPRINTK("Turbo Queue: start at 0x%lx, size is %dK\n",
+		DPRINTK("sisfb: TurboQueue start at 0x%lx, size is %dK\n",
 			sisfb_heap_end, TURBO_QUEUE_AREA_SIZE/1024);
 	    }
      }
 #endif
-        /* TW: Now reserve memory for the HWCursow. It is always located at the very
+        /* TW: Now reserve memory for the HWCursor. It is always located at the very
                top of the videoRAM, right below the TB memory area (if used). */
 	if (sisfb_heap_size >= sisfb_hwcursor_size) {
 		sisfb_heap_end -= sisfb_hwcursor_size;
@@ -1334,7 +1543,7 @@
 
 		sisfb_caps |= HW_CURSOR_CAP;
 
-		DPRINTK("Hardware Cursor: start at 0x%lx, size is %dK\n",
+		DPRINTK("sisfb: Hardware Cursor start at 0x%lx, size is %dK\n",
 			sisfb_heap_end, sisfb_hwcursor_size/1024);
 	}
 
@@ -1351,11 +1560,11 @@
 	poh->size = sisfb_heap_end - sisfb_heap_start + 1;
 	poh->offset = sisfb_heap_start - (unsigned long) ivideo.video_vbase;
 
-	DPRINTK("sisfb:Heap start:0x%p, end:0x%p, len=%dk\n",
+	DPRINTK("sisfb: Heap start:0x%p, end:0x%p, len=%dk\n",
 		(char *) sisfb_heap_start, (char *) sisfb_heap_end,
 		(unsigned int) poh->size / 1024);
 
-	DPRINTK("sisfb:First Node offset:0x%x, size:%dk\n",
+	DPRINTK("sisfb: First Node offset:0x%x, size:%dk\n",
 		(unsigned int) poh->offset, (unsigned int) poh->size / 1024);
 	
 	sisfb_heap.oh_free.poh_next = poh;
@@ -1576,9 +1785,9 @@
 	if (poh == NULL) {
 		req->offset = 0;
 		req->size = 0;
-		DPRINTK("sisfb: VMEM Allocation Failed\n");
+		DPRINTK("sisfb: Video RAM allocation failed\n");
 	} else {
-		DPRINTK("sisfb: VMEM Allocation Successed : 0x%p\n",
+		DPRINTK("sisfb: Video RAM allocation succeeded: 0x%p\n",
 			(char *) (poh->offset +
 				  (unsigned long) ivideo.video_vbase));
 
@@ -1610,15 +1819,18 @@
 	cr31 = vgarb(CRTC_DATA) & ~0x60;
 
 	switch (ivideo.disp_state & DISPTYPE_DISP2) {
-	case DISPTYPE_CRT2:
+	   case DISPTYPE_CRT2:
+		printk(KERN_INFO "sisfb: CRT2 type is VGA\n");
 		cr30 = (SIS_VB_OUTPUT_CRT2 | SIS_SIMULTANEOUS_VIEW_ENABLE);
-		cr31 |= SIS_DRIVER_MODE; 
+		cr31 |= SIS_DRIVER_MODE;
 		break;
-	case DISPTYPE_LCD:
+	   case DISPTYPE_LCD:
+		printk(KERN_INFO "sisfb: CRT2 type is LCD\n");
 		cr30  = (SIS_VB_OUTPUT_LCD | SIS_SIMULTANEOUS_VIEW_ENABLE);
 		cr31 |= SIS_DRIVER_MODE;
 		break;
-	case DISPTYPE_TV:
+	   case DISPTYPE_TV:
+		printk(KERN_INFO "sisfb: CRT2 type is TV\n");
 		if (ivideo.TV_type == TVMODE_HIVISION)
 			cr30 = (SIS_VB_OUTPUT_HIVISION | SIS_SIMULTANEOUS_VIEW_ENABLE);
 		else if (ivideo.TV_plug == TVPLUG_SVIDEO)
@@ -1627,15 +1839,16 @@
 			cr30 = (SIS_VB_OUTPUT_COMPOSITE | SIS_SIMULTANEOUS_VIEW_ENABLE);
 		else if (ivideo.TV_plug == TVPLUG_SCART)
 			cr30 = (SIS_VB_OUTPUT_SCART | SIS_SIMULTANEOUS_VIEW_ENABLE);
-		cr31 |= SIS_DRIVER_MODE;  
-
-               /*karl*/
-	        if (sisfb_tvmode == 1)
+		cr31 |= SIS_DRIVER_MODE;
+		cr31 &= ~0x04; /* TW: No Slavemode by default  */
+                /*karl*/
+	        if (sisfb_tvmode == 1 || ivideo.TV_type == TVMODE_PAL)
 			cr31 |= 0x1;
-                if (sisfb_tvmode == 2)
+                if (sisfb_tvmode == 2 || ivideo.TV_type == TVMODE_NTSC)
                         cr31 &= ~0x1;
 		break;
-	default:	/* CRT2 disable */
+	   default:	/* CRT2 disable */
+		printk(KERN_INFO "sisfb: CRT2 is disabled\n");
 		cr30 = 0x00;
 		cr31 |= (SIS_DRIVER_MODE | SIS_VB_OUTPUT_DISABLE);
 	}
@@ -1644,6 +1857,7 @@
 	vgawb(CRTC_DATA, cr30);
 	vgawb(CRTC_ADR, IND_SIS_SCRATCH_REG_CR31);
 	vgawb(CRTC_DATA, cr31);
+	/* printk(KERN_INFO "sisfb: 0x30=%x 0x31=%x\n", cr30, cr31); */
 	vgawb(CRTC_ADR, IND_SIS_SCRATCH_REG_CR33);
 /*
 	if (ivideo.disp_state & DISPTYPE_CRT2) {
@@ -1688,19 +1902,19 @@
            {	
 		// Eden Chen
 		switch (ivideo.video_width) {
-		case 320:
+		   case 320:
 			filter_tb = (ivideo.TV_type == TVMODE_NTSC) ? 4 : 12;
 			break;
-		case 640:
+		   case 640:
 			filter_tb = (ivideo.TV_type == TVMODE_NTSC) ? 5 : 13;
 			break;
-		case 720:
+		   case 720:
 			filter_tb = (ivideo.TV_type == TVMODE_NTSC) ? 6 : 14;
 			break;
-		case 800:
+		   case 800:
 			filter_tb = (ivideo.TV_type == TVMODE_NTSC) ? 7 : 15;
 			break;
-		default:
+		   default:
 			filter = -1;
 			break;
 		}
@@ -1903,25 +2117,25 @@
 		var->vmode = FB_VMODE_NONINTERLACED;
 
 	switch ((sr_data & 0x1C) >> 2) {
-	case SIS_8BPP_COLOR_MODE:
+	   case SIS_8BPP_COLOR_MODE:
 		var->bits_per_pixel = 8;
 		break;
-	case SIS_16BPP_COLOR_MODE:
+	   case SIS_16BPP_COLOR_MODE:
 		var->bits_per_pixel = 16;
 		break;
-	case SIS_32BPP_COLOR_MODE:
+	   case SIS_32BPP_COLOR_MODE:
 		var->bits_per_pixel = 32;
 		break;
 	}
 
 	switch (var->bits_per_pixel) {
-	case 8:
+	   case 8:
 		var->red.length = 6;
 		var->green.length = 6;
 		var->blue.length = 6;
 		video_cmap_len = 256;
 		break;
-	case 16:		
+	   case 16:
 		var->red.offset = 11;
 		var->red.length = 5;
 		var->green.offset = 5;
@@ -1932,7 +2146,7 @@
 		var->transp.length = 0;
 		video_cmap_len = 16;
 		break;
-	case 24:		
+	   case 24:
 		var->red.offset = 16;
 		var->red.length = 8;
 		var->green.offset = 8;
@@ -1943,7 +2157,7 @@
 		var->transp.length = 0;
 		video_cmap_len = 16;
 		break;
-	case 32:
+	   case 32:
 		var->red.offset = 16;
 		var->red.length = 8;
 		var->green.offset = 8;
@@ -2202,20 +2416,20 @@
 		       struct fb_info *info)
 {
 	switch (cmd) {
-	case FBIO_ALLOC:
+	   case FBIO_ALLOC:
 		if (!capable(CAP_SYS_RAWIO))
 			return -EPERM;
 		sis_malloc((struct sis_memreq *) arg);
 		break;
-	case FBIO_FREE:
+	   case FBIO_FREE:
 		if (!capable(CAP_SYS_RAWIO))
 			return -EPERM;
 		sis_free(*(unsigned long *) arg);
 		break;
-	case FBIOGET_GLYPH:
+	   case FBIOGET_GLYPH:
 		sis_get_glyph((SIS_GLYINFO *) arg);
 		break;
-	case FBIOGET_HWCINFO:
+	   case FBIOGET_HWCINFO:
 		{
 			unsigned long *hwc_offset = (unsigned long *) arg;
 
@@ -2227,7 +2441,7 @@
 
 			break;
 		}
-	case FBIOPUT_MODEINFO:
+	   case FBIOPUT_MODEINFO:
 		{
 			struct mode_info *x = (struct mode_info *)arg;
 			
@@ -2242,10 +2456,10 @@
 			
 			break;
 		}
-	case FBIOGET_DISPINFO:
+	   case FBIOGET_DISPINFO:
 		sis_dispinfo((struct ap_data *)arg);
 		break;
-	default:
+	   default:
 		return -EINVAL;
 	}
 	return 0;
@@ -2286,8 +2500,13 @@
 	if (boot_cpu_data.x86 > 3)
 		pgprot_val(vma->vm_page_prot) |= _PAGE_PCD;
 #endif
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
 	if (io_remap_page_range(vma->vm_start, off, vma->vm_end - vma->vm_start,
-				vma->vm_page_prot)) 
+				vma->vm_page_prot))
+#else	/* TW: 2.5 API */
+	if (io_remap_page_range(vma, vma->vm_start, off, vma->vm_end - vma->vm_start,
+				vma->vm_page_prot))
+#endif
 		return -EAGAIN;
 	return 0;
 
@@ -2341,10 +2560,8 @@
 	sisfb_update_var(con, info);
 
 	return 1;
-
 }
 
-
 static void sisfb_blank(int blank, struct fb_info *info)
 {
 	u8 reg;
@@ -2371,8 +2588,11 @@
 	if (!options || !*options)
 		return 0;
 
+#if 0	/* TW (Alex Tribble): Change for 2.5 series */
 	for (this_opt = strtok(options, ","); this_opt;
 	     this_opt = strtok(NULL, ",")) {
+#endif
+	while((this_opt = strsep(&options, ","))) {
 		if (!*this_opt)
 			continue;
 
@@ -2386,7 +2606,6 @@
 		} else if (!strncmp(this_opt, "vrate:", 6)) {
 			ivideo.refresh_rate =
 			    simple_strtoul(this_opt + 6, NULL, 0);
-		/* TW: This is for consistency with module paramaters */
 		} else if (!strncmp(this_opt, "rate:", 5)) {
 			ivideo.refresh_rate =
 			    simple_strtoul(this_opt + 5, NULL, 0);
@@ -2396,9 +2615,12 @@
 			sisfb_crt1off = 1;
 		} else if (!strncmp(this_opt, "filter:", 7)) {
 			filter = (int)simple_strtoul(this_opt + 7, NULL, 0);
-		}
+		} else if (!strncmp(this_opt, "forcecrt2type:", 14)) {
+			sisfb_search_crt2type(this_opt + 14);
+		} else if (!strncmp(this_opt, "forcecrt1:", 10)) {
+			sisfb_forcecrt1 = (int)simple_strtoul(this_opt + 10, NULL, 0);
                   /*karl*/
-                  else if (!strncmp(this_opt, "tvmode:",7)) {
+                } else if (!strncmp(this_opt, "tvmode:",7)) {
                         if (!strncmp(this_opt + 7, "pal",3))
                          	sisfb_tvmode = 1;
                         if (!strncmp(this_opt + 7, "ntsc",4))
@@ -2413,8 +2635,12 @@
 			enable_dstn = simple_strtoul(this_opt + 5, NULL, 0);
 		}
 		/* ~JennyLee 20011211 */
+		else if (!strncmp(this_opt, "queuemode:", 10)) {
+			sisfb_search_queuemode(this_opt + 10);
+		}
+
 		else
-			printk("sisfb: Invalid parameter %s\n", this_opt);
+			printk(KERN_INFO "sisfb: Invalid parameter %s\n", this_opt);
 	}
 	return 0;
 }
@@ -2428,7 +2654,7 @@
 	u32 reg32;
 	u16 reg16;
 	u8  reg;
-	int nRes;
+	int temp1, temp2;
 
 	outb(0x77, 0x80);
 
@@ -2476,13 +2702,13 @@
 
 // Eden Chen
 	switch (ivideo.chip_id) {
-	case PCI_DEVICE_ID_SI_300:
+	   case PCI_DEVICE_ID_SI_300:
 		ivideo.chip = SIS_300;
 		sisvga_engine = SIS_300_VGA;
 		sisfb_hwcursor_size = HW_CURSOR_AREA_SIZE_300;
 		sisfb_CRT2_write_enable = IND_SIS_CRT2_WRITE_ENABLE_300;
 		break;
-	case PCI_DEVICE_ID_SI_630_VGA:
+	   case PCI_DEVICE_ID_SI_630_VGA:
 		{
 			sisfb_set_reg4(0xCF8, 0x80000000);
 			reg32 = sisfb_get_reg3(0xCFC);
@@ -2497,37 +2723,37 @@
 			sisfb_CRT2_write_enable = IND_SIS_CRT2_WRITE_ENABLE_300;
 			break;
 		}
-	case PCI_DEVICE_ID_SI_540_VGA:
+	   case PCI_DEVICE_ID_SI_540_VGA:
 		ivideo.chip = SIS_540;
 		sisvga_engine = SIS_300_VGA;
 		sisfb_hwcursor_size = HW_CURSOR_AREA_SIZE_300;
 		sisfb_CRT2_write_enable = IND_SIS_CRT2_WRITE_ENABLE_300;
 		break;
-	case PCI_DEVICE_ID_SI_315H:
+	   case PCI_DEVICE_ID_SI_315H:
 		ivideo.chip = SIS_315H;
 		sisvga_engine = SIS_315_VGA;
 		sisfb_hwcursor_size = HW_CURSOR_AREA_SIZE_315;
 		sisfb_CRT2_write_enable = IND_SIS_CRT2_WRITE_ENABLE_315;
 		break;
-	case PCI_DEVICE_ID_SI_315:
+	   case PCI_DEVICE_ID_SI_315:
 		ivideo.chip = SIS_315;
 		sisvga_engine = SIS_315_VGA;
 		sisfb_hwcursor_size = HW_CURSOR_AREA_SIZE_315;
 		sisfb_CRT2_write_enable = IND_SIS_CRT2_WRITE_ENABLE_315;
 		break;
-	case PCI_DEVICE_ID_SI_315PRO:
+	   case PCI_DEVICE_ID_SI_315PRO:
 		ivideo.chip = SIS_315PRO;
 		sisvga_engine = SIS_315_VGA;
 		sisfb_hwcursor_size = HW_CURSOR_AREA_SIZE_315;
 		sisfb_CRT2_write_enable = IND_SIS_CRT2_WRITE_ENABLE_315;
 		break;
-	case PCI_DEVICE_ID_SI_550_VGA:
+	   case PCI_DEVICE_ID_SI_550_VGA:
 		ivideo.chip = SIS_550;
 		sisvga_engine = SIS_315_VGA;
 		sisfb_hwcursor_size = HW_CURSOR_AREA_SIZE_315;
 		sisfb_CRT2_write_enable = IND_SIS_CRT2_WRITE_ENABLE_315;
 		break;
-	case PCI_DEVICE_ID_SI_650_VGA:
+	   case PCI_DEVICE_ID_SI_650_VGA:
 		ivideo.chip = SIS_650;
 		sisvga_engine = SIS_315_VGA;
 		sisfb_hwcursor_size = HW_CURSOR_AREA_SIZE_315;
@@ -2551,7 +2777,7 @@
 	// Eden Chen
 	//sishw_ext.IOAddress = (unsigned short) ivideo.vga_base 
 	//	= pci_resource_start(pdev, 2) + 0x30;
-	sishw_ext.ulIOAddress = (unsigned short) ivideo.vga_base 
+	sishw_ext.ulIOAddress = (unsigned short) ivideo.vga_base
 		= pci_resource_start(pdev, 2) + 0x30;
 	// ~Eden Chen
 
@@ -2608,12 +2834,12 @@
 
 	if (sisvga_engine == SIS_315_VGA) {
 		switch (ivideo.chip) {
-		case SIS_315H:
-		case SIS_315:
+		   case SIS_315H:
+		   case SIS_315:
 			sishw_ext.bIntegratedMMEnabled = TRUE;
 			break;
-		case SIS_550:
-		case SIS_650:
+		   case SIS_550:
+		   case SIS_650:
 			// Eden Chen
 			//vgawb(SEQ_ADR, IND_SIS_SCRATCH_REG_1A);
 			//reg = vgarb(SEQ_DATA);
@@ -2625,7 +2851,7 @@
 			sishw_ext.bIntegratedMMEnabled = TRUE;
 			// ~Eden Chen
 			break;
-		default:
+		   default:
 			break;
 		}
 	} else if (sisvga_engine == SIS_300_VGA) {
@@ -2651,19 +2877,21 @@
 	strcpy(sishw_ext.szVBIOSVer, "0.84");
 
 	sishw_ext.pSR = vmalloc(sizeof(SIS_DSReg) * SR_BUFFER_SIZE);
-	if (sishw_ext.pSR == NULL)
-		printk(KERN_DEBUG "Allocated SRReg space fail.\n");
+	if (sishw_ext.pSR == NULL) {
+		printk(KERN_INFO "sisfb: Fatal error: Allocating SRReg space failed.\n");
+		return -ENODEV;
+	}
 	sishw_ext.pSR[0].jIdx = sishw_ext.pSR[0].jVal = 0xFF;
 
 	sishw_ext.pCR = vmalloc(sizeof(SIS_DSReg) * CR_BUFFER_SIZE);
-	if (sishw_ext.pCR == NULL)
-		printk(KERN_DEBUG "Allocated CRReg space fail.\n");
+	if (sishw_ext.pCR == NULL) {
+		printk(KERN_INFO "sisfb: Fatal error: Allocating CRReg space failed.\n");
+		return -ENODEV;
+	}
 	sishw_ext.pCR[0].jIdx = sishw_ext.pCR[0].jVal = 0xFF;
 	// ~Eden Chen
 
-
 #ifdef CONFIG_FB_SIS_300
-
 	if (sisvga_engine == SIS_300_VGA) {
 		if (!sisvga_enabled) {
 			// Eden Chen
@@ -2679,16 +2907,12 @@
 		}
 #ifdef LINUXBIOS
 		else {
-			// Eden Chen
-			sishw_ext.pjVideoMemoryAddress 
+			sishw_ext.pjVideoMemoryAddress
 				= ioremap(ivideo.video_base, 0x2000000);
 			if ((sisbios_mode[sisfb_mode_idx].mode_no) != 0xFF) {   /* TW: for mode "none" */
-				//SiSInit300(&sishw_ext);
-			
 				SiSInit(&sishw_ext);
 				vgawb(SEQ_ADR, IND_SIS_PASSWORD);
 				vgawb(SEQ_DATA, SIS_PASSWORD);
-				// ~Eden Chen
 			}
 		}
 		if ((sisbios_mode[sisfb_mode_idx].mode_no) != 0xFF) {   /* TW: for mode "none" */
@@ -2698,12 +2922,14 @@
 			vgawb(SEQ_DATA, reg);
 		}
 #endif
-		sisfb_get_dram_size_300();
+		if (sisfb_get_dram_size_300()) {
+			printk(KERN_INFO "sisfb: Fatal error: Unable to determine RAM size\n");
+			return -ENODEV;
+		}
 	}
 #endif
 
 #ifdef CONFIG_FB_SIS_315
-
 	if (sisvga_engine == SIS_315_VGA) {
 		if (!sisvga_enabled) {
 			/* Mapping Max FB Size for 315 Init */
@@ -2712,7 +2938,6 @@
 			sishw_ext.pjVideoMemoryAddress 
 				= ioremap(ivideo.video_base, 0x8000000);
 			if ((sisbios_mode[sisfb_mode_idx].mode_no) != 0xFF) {   /* TW: for mode "none" */
-				//SiSInit310(&sishw_ext);
 				SiSInit(&sishw_ext);
 
 				vgawb(SEQ_ADR, IND_SIS_PASSWORD);
@@ -2727,7 +2952,6 @@
 				sishw_ext.pSR[1].jVal = vgarb(SEQ_DATA);
 				sishw_ext.pSR[2].jIdx = 0xFF;
 				sishw_ext.pSR[2].jVal = 0xFF;
-				// Eden Chen
 			}
 		}
 #ifdef LINUXBIOS
@@ -2751,20 +2975,23 @@
 			}
 		}
 #endif
-		sisfb_get_dram_size_315();
+		if (sisfb_get_dram_size_315()) {
+			printk(KERN_INFO "sisfb: Fatal error: Unable to determine RAM size.\n");
+			return -ENODEV;
+		}
 	}
 #endif
 	if ((sisbios_mode[sisfb_mode_idx].mode_no) != 0xFF) {   /* TW: for mode "none" */
 		//Eden Chen
 		vgawb(SEQ_ADR, IND_SIS_PCI_ADDRESS_SET);
 		reg = vgarb(SEQ_DATA);
-		reg |= SIS_PCI_ADDR_ENABLE;
-		reg |= SIS_MEM_MAP_IO_ENABLE;
+		reg |= SIS_PCI_ADDR_ENABLE;    	/* Enable PCI_LINEAR_ADDRESSING */
+		reg |= SIS_MEM_MAP_IO_ENABLE;  	/* Enable MMIO_ENABLE */
 		vgawb(SEQ_DATA, reg);
 
 		vgawb(SEQ_ADR, IND_SIS_MODULE_ENABLE);
 		reg = vgarb(SEQ_DATA);
-		reg |= SIS_ENABLE_2D;
+		reg |= SIS_ENABLE_2D;		/* Enable 2D accelerator engine */
 		vgawb(SEQ_DATA, reg);
 		//~Eden Chen
 	}
@@ -2773,12 +3000,12 @@
 	sishw_ext.ulVideoMemorySize = ivideo.video_size;
 	// ~Eden Chen
 	if (!request_mem_region(ivideo.video_base, ivideo.video_size, "sisfb FB")) {
-		printk(KERN_ERR "sisfb: cannot reserve frame buffer memory\n");
+		printk(KERN_ERR "sisfb: Fatal error: Unable to reserve frame buffer memory\n");
 		return -ENODEV;
 	}
 
 	if (!request_mem_region(ivideo.mmio_base, sisfb_mmio_size, "sisfb MMIO")) {
-		printk(KERN_ERR "sisfb: cannot reserve MMIO region\n");
+		printk(KERN_ERR "sisfb: Fatal error: Unable to reserve MMIO region\n");
 		release_mem_region(ivideo.video_base, ivideo.video_size);
 		return -ENODEV;
 	}
@@ -2790,7 +3017,7 @@
 	ivideo.mmio_vbase = ioremap(ivideo.mmio_base, sisfb_mmio_size);
 
 	printk(KERN_INFO
-	       "sisfb: framebuffer at 0x%lx, mapped to 0x%p, size %dk\n",
+	       "sisfb: Framebuffer at 0x%lx, mapped to 0x%p, size %dk\n",
 	       ivideo.video_base, ivideo.video_vbase,
 	       ivideo.video_size / 1024);
 
@@ -2804,8 +3031,7 @@
 #ifdef CONFIG_FB_SIS_300
 		if (sisvga_engine == SIS_300_VGA) {
 			sisfb_get_VB_type_300();
-			if (ivideo.hasVB != HASVB_NONE)
-			{
+			if (ivideo.hasVB != HASVB_NONE) {
 				sisfb_detect_VB_connect_300();
 			}
 		}
@@ -2814,8 +3040,7 @@
 #ifdef CONFIG_FB_SIS_315
 		if (sisvga_engine == SIS_315_VGA) {
 			sisfb_get_VB_type_315();
-			if (ivideo.hasVB != HASVB_NONE)
-			{
+			if (ivideo.hasVB != HASVB_NONE) {
 				sisfb_detect_VB_connect_315();
 			}
 		}
@@ -2828,50 +3053,97 @@
 		switch (ivideo.hasVB) {
 
 		case HASVB_301:
-		/*karl*/
+			/*karl*/
 			vgawb(VB_PART4_ADR,0x01);
 			reg = vgarb(VB_PART4_DATA);
-	  		if ((reg != 0xB1) && (reg != 0xB0))
-			{
-				sishw_ext.ujVBChipID = VB_CHIP_301;
-				printk(KERN_INFO "sisfb: SiS301 bridge detected\n");
-			}
-	  		else
-			{
+			if (reg >= 0xD0) {
+				sishw_ext.ujVBChipID = VB_CHIP_301B;
+				printk(KERN_INFO "sisfb: SiS301LV bridge detected\n");
+	  		} else if (reg >= 0xB0) {
 				sishw_ext.ujVBChipID = VB_CHIP_301B;
 				printk(KERN_INFO "sisfb: SiS301B bridge detected\n");
+			} else {
+				sishw_ext.ujVBChipID = VB_CHIP_301;
+				printk(KERN_INFO "sisfb: SiS301 bridge detected\n");
 			}
 			break;
 		case HASVB_302:
+			vgawb(VB_PART4_ADR,0x01);
+			reg = vgarb(VB_PART4_DATA);
 			sishw_ext.ujVBChipID = VB_CHIP_302;
-			printk (KERN_INFO "sisfb: SiS302 bridge detected\n");  /* TW */
+			if (reg >= 0xD0) {
+				printk(KERN_INFO "sisfb: SiS302LV bridge detected\n");
+	  		} else if (reg >= 0xB0) {
+				printk(KERN_INFO "sisfb: SiS302B bridge detected\n");
+			} else {
+				printk(KERN_INFO "sisfb: SiS302 bridge detected\n");
+			}
 			break;
 		case HASVB_303:
 			sishw_ext.ujVBChipID = VB_CHIP_303;
-			printk (KERN_INFO "sisfb: SiS303 bridge detected\n");  /* TW */
+			printk(KERN_INFO "sisfb: SiS303 bridge detected (not supported)\n");
 			break;
 		case HASVB_LVDS:
 			sishw_ext.usExternalChip = 0x1;
-			printk (KERN_INFO "sisfb: LVDS bridge detected\n");  /* TW */
+			printk(KERN_INFO "sisfb: LVDS bridge detected\n");
 			break;
 		case HASVB_TRUMPION:
 			sishw_ext.usExternalChip = 0x2;
-			printk (KERN_INFO "sisfb: TRUMPION TV converter detected\n");  /* TW */
+			printk(KERN_INFO "sisfb: TRUMPION TV converter detected\n");
 			break;
 		case HASVB_CHRONTEL:
 			sishw_ext.usExternalChip = 0x4;
-			printk (KERN_INFO "sisfb: CHRONTEL TV converter detected\n");  /* TW */
+			printk(KERN_INFO "sisfb: Chrontel TV converter detected\n");
 			break;
 		case HASVB_LVDS_CHRONTEL:
 			sishw_ext.usExternalChip = 0x5;
-			printk (KERN_INFO "sisfb: LVDS bridge and CHRONTEL TV converter detected\n");  /* TW */
+			printk(KERN_INFO "sisfb: LVDS bridge and Chrontel TV converter detected\n");
 			break;
 		default:
-			printk (KERN_INFO "sisfb: unknown bridge or TV converter detected\n");  /* TW */
+			printk(KERN_INFO "sisfb: No or unknown bridge type detected\n");
 			break;
 		}
 		// ~Eden Chen
 
+		/* TW: Determine and detect attached TV's on Chrontel */
+		if (sishw_ext.usExternalChip == 0x04 || sishw_ext.usExternalChip == 0x05) {
+		    SiSRegInit(sishw_ext.ulIOAddress);
+		    temp1=SiS_GetCH7005(0x25);
+		    if ((temp1 >= 50) && (temp1 <= 100)) {
+	    		/* TW: Read power status */
+	    		temp1 = SiS_GetCH7005(0x0e);
+	    		if ((temp1&0x03)!=0x03) {
+		        	/* TW: Power all outputs */
+	        		SiS_SetCHTVRegANDOR(0x030E,0xF8);
+	    		}
+			/* TW: Sense connected TV devices */
+	    		SiS_SetCH7005(0x0110);
+	    		SiS_SetCH7005(0x0010);
+	    		temp1 = SiS_GetCH7005(0x10);
+	    		if (!(temp1 & 0x08)) {
+				/* TW: So we can be sure that there IS a SVHS output */
+				printk(KERN_INFO
+				   "sisfb: Chrontel: Detected TV connected to SVHS output\n");
+				ivideo.TV_plug = TVPLUG_SVIDEO;
+				vgawb(CRTC_ADR, 0x32);
+				temp2 = vgarb(CRTC_DATA) | 0x02;
+				vgawb(CRTC_DATA, temp2);
+			} else if (!(temp1 & 0x02)) {
+				/* TW: So we can be sure that there IS a CVBS output */
+				printk(KERN_INFO
+				   "sisfb: Chrontel: Detected TV connected to CVBS output\n");
+				ivideo.TV_plug = TVPLUG_COMPOSITE;
+				vgawb(CRTC_ADR, 0x32);
+				temp2 = vgarb(CRTC_DATA) | 0x01;
+				vgawb(CRTC_DATA, temp2);
+	    		} else {
+		    		SiS_SetCHTVRegANDOR(0x010E,0xF8);
+	    		}
+		    } else if (temp1==0) {
+	    		        SiS_SetCHTVRegANDOR(0x010E,0xF8);
+	    	    }
+	    	}
+
 		if (ivideo.disp_state & DISPTYPE_DISP2) {
 			if (sisfb_crt1off)
 				ivideo.disp_state |= DISPMODE_SINGLE;
@@ -2885,27 +3157,30 @@
 			reg = vgarb(CRTC_DATA);
 			// Eden Chen
 			switch (reg) {
-				case SIS_LCD_PANEL_800X600:
-					sishw_ext.ulCRT2LCDType = LCD_800x600;
-					break;
-				case SIS_LCD_PANEL_1024X768:
-					sishw_ext.ulCRT2LCDType = LCD_1024x768;
-					break;
-				case SIS_LCD_PANEL_1280X1024:
-					sishw_ext.ulCRT2LCDType = LCD_1280x1024;
-					break;
-				case SIS_LCD_PANEL_640X480:
-					sishw_ext.ulCRT2LCDType = LCD_640x480;
-					break;
-				case SIS_LCD_PANEL_1280X960:
-					sishw_ext.ulCRT2LCDType = LCD_1280x960;
-					break;
-				case SIS_LCD_PANEL_1600x1200: /* TW */
-					sishw_ext.ulCRT2LCDType = LCD_1600x1200;
-					break;
-				default:
-					sishw_ext.ulCRT2LCDType = LCD_1024x768;
-					break;
+			   case SIS_LCD_PANEL_800X600:
+				sishw_ext.ulCRT2LCDType = LCD_800x600;
+				break;
+			   case SIS_LCD_PANEL_1024X768:
+				sishw_ext.ulCRT2LCDType = LCD_1024x768;
+				break;
+			   case SIS_LCD_PANEL_1280X1024:
+				sishw_ext.ulCRT2LCDType = LCD_1280x1024;
+				break;
+			   case SIS_LCD_PANEL_640X480:
+				sishw_ext.ulCRT2LCDType = LCD_640x480;
+				break;
+			   case SIS_LCD_PANEL_1280X960:
+				sishw_ext.ulCRT2LCDType = LCD_1280x960;
+				break;
+			   case SIS_LCD_PANEL_1600x1200: /* TW */
+				sishw_ext.ulCRT2LCDType = LCD_1600x1200;
+				break;
+			   case SIS_LCD_PANEL_320x480:   /* TW: FSTN */
+				sishw_ext.ulCRT2LCDType = LCD_320x480;
+				break;
+			   default:
+				sishw_ext.ulCRT2LCDType = LCD_1024x768;
+				break;
 			}
 			// ~Eden Chen
 		}
@@ -2915,15 +3190,15 @@
 
 		if (sisfb_mode_idx < 0) {
 			switch (ivideo.disp_state & DISPTYPE_DISP2) {
-				case DISPTYPE_LCD:
-					sisfb_mode_idx = DEFAULT_LCDMODE;
-					break;
-				case DISPTYPE_TV:
-					sisfb_mode_idx = DEFAULT_TVMODE;
-					break;
-				default:
-					sisfb_mode_idx = DEFAULT_MODE;
-					break;
+			   case DISPTYPE_LCD:
+				sisfb_mode_idx = DEFAULT_LCDMODE;
+				break;
+			   case DISPTYPE_TV:
+				sisfb_mode_idx = DEFAULT_TVMODE;
+				break;
+			   default:
+				sisfb_mode_idx = DEFAULT_MODE;
+				break;
 			}
 		}
 
@@ -2943,7 +3218,7 @@
 		ivideo.org_x = ivideo.org_y = 0;
 		video_linelength = ivideo.video_width * (ivideo.video_bpp >> 3);
 
-		printk(KERN_INFO "sisfb: mode is %dx%dx%d (%dHz), linelength=%d\n",
+		printk(KERN_INFO "sisfb: Mode is %dx%dx%d (%dHz), linelength=%d\n",
 	       		ivideo.video_width, ivideo.video_height, ivideo.video_bpp,
 			ivideo.refresh_rate, video_linelength);
 
@@ -2960,26 +3235,8 @@
 		DPRINTK("bIntegratedMMEnabled=%d\n", sishw_ext.bIntegratedMMEnabled);
 		// ~Eden Chen
 
-		/*karl3*/
-  		//      sisfb_mode_no = 0x5A;
 		sisfb_pre_setmode();
 
-// Eden Chen
-//#ifdef CONFIG_FB_SIS_300
-//		if (sisvga_engine == SIS_300_VGA)
-//			if (SiSSetMode(&sishw_ext, sisfb_mode_no)) {
-//				DPRINTK("set mode[0x%x]: failed\n", sisfb_mode_no);
-//				return -1;
-//			}
-//#endif
-//
-//#ifdef CONFIG_FB_SIS_315
-//		if (sisvga_engine == SIS_315_VGA)
-//			if (SiSSetMode310(&sishw_ext, sisfb_mode_no)) {
-//				DPRINTK("set mode[0x%x]: failed\n", sisfb_mode_no);
-//				return -1;
-//			}
-//#endif
 		if (SiSSetMode(&sishw_ext, sisfb_mode_no) == 0) {
 			DPRINTK("set mode[0x%x]: failed\n", sisfb_mode_no);
 			return -1;
@@ -2987,14 +3244,17 @@
 
 		vgawb(SEQ_ADR, IND_SIS_PASSWORD);
 		vgawb(SEQ_DATA, SIS_PASSWORD);
-// Eden Chen
 
 		sisfb_post_setmode();
 
 		sisfb_crtc_to_var(&default_var);
 
 		fb_info.changevar = NULL;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
 		fb_info.node = -1;
+#else
+		fb_info.node = NODEV;
+#endif
 		fb_info.fbops = &sisfb_ops;
 		fb_info.disp = &disp;
 		fb_info.switch_con = &sisfb_switch;
@@ -3007,28 +3267,28 @@
 	} /* TW: if mode = "none" */
 
 	if (sisfb_heap_init()) {
-		printk("sisfb: Failed to enable offscreen heap\n");
+		printk("sisfb: Failed to initialize offscreen memory heap\n");
 	}
-         
+
+        ivideo.mtrr = (unsigned int) 0;
 	if ((sisbios_mode[sisfb_mode_idx].mode_no) != 0xFF) {   /* TW: for mode "none" */
          	/*H.C.*/
-		nRes = mtrr_add((unsigned int) ivideo.video_base, (unsigned int) ivideo.video_size, MTRR_TYPE_WRCOMB, 1);
+		ivideo.mtrr = mtrr_add((unsigned int) ivideo.video_base,
+				(unsigned int) ivideo.video_size,
+				MTRR_TYPE_WRCOMB, 1);
       		/*
-			if (nRes >= 0)
-      			{
+			if (ivideo.mtrr >= 0) {
            		printk(KERN_INFO "Succeed to turn on Write-Combining on VideoMemory %08XH, Size: %08XH\n",
 					ivideo.video_base, ivideo.video_size);
-      			}
-      			else
-      			{
+      			} else	{
            		printk(KERN_INFO "Fail to turn on Write-Combining on Video Memory 0x%08X, Size: 0x%08X\n",
 					ivideo.video_base, ivideo.video_size);
       			}
-        		*/
+        	*/
 		vc_resize_con(1, 1, 0);
 
 		if (register_framebuffer(&fb_info) < 0)
-		return -EINVAL;
+			return -EINVAL;
 
 		printk(KERN_INFO "fb%d: %s frame buffer device, Version %d.%d.%02d\n",
 	       		GET_FB_IDX(fb_info.node), fb_info.modename, VER_MAJOR, VER_MINOR,
@@ -3042,18 +3302,76 @@
 
 static char *mode = NULL;
 static unsigned int rate = 0;
-static unsigned int crt1 = 1;
+static unsigned int crt1off = 1;
 static unsigned int mem = 0;
 static unsigned int dstn = 0;
+static char *forcecrt2type = NULL;
+static int forcecrt1 = -1;
+static char *queuemode = NULL;
+
+MODULE_DESCRIPTION("SiS 300/540/630/730/315/550/650/740 framebuffer driver");
+MODULE_LICENSE("GPL");    /* TW (Code is officially open says SiS) */
+MODULE_AUTHOR("Various; SiS; Some parts by Thomas Winischhofer <thomas@winischhofer.net>");
+
+MODULE_PARM(mode, "s");
+MODULE_PARM_DESC(mode,
+       "Selects the desired display mode in the format [X]x[Y]x[Depth], eg. 800x600x16 "
+       "(default: none; this leaves the console untouched and the driver will only do "
+       "the video memory management for eg. DRM/DRI)");
+
+MODULE_PARM(rate, "i");
+MODULE_PARM_DESC(rate,
+	"Selects the desired vertical refresh rate for CRT1 (external VGA) in Hz. "
+	"(default: 60)");
+
+MODULE_PARM(crt1off,   "i");
+MODULE_PARM_DESC(crt1off,
+	"If this option is set, the driver will switch off CRT1 (external VGA). "
+	"(Deprecated, please use forcecrt1)");
 
-MODULE_PARM(mode,   "s");
-MODULE_PARM(rate,   "i");
-MODULE_PARM(crt1,   "i");
 MODULE_PARM(filter, "i");
-MODULE_PARM(mem,    "i"); /* TW */
+MODULE_PARM_DESC(filter,
+	"Selects TV flicker filter type (only for SiS30x video bridges). "
+	"(Possible values 0-7, default: [no filter])");
+
 MODULE_PARM(dstn,   "i"); /* JennyLee 20011211 */
+MODULE_PARM_DESC(dstn,
+	"Selects DSTN display mode (1=ON, 0=OFF) (default: 0)");
 
-MODULE_LICENSE("GPL");    /* TW (Code is officially open says SiS) */
+MODULE_PARM(queuemode,   "s");
+MODULE_PARM_DESC(queuemode,
+	"Selects the queue mode on 315/550/650/740. Possible choices are AGP, VRAM "
+	"or MMIO. AGP is only available if the kernel has AGP support. "
+	"The queue mode is important to programs using the 2D/3D accelerator of "
+	"the SiS chip. The modes require a totally different way of programming "
+	"the engines. On 300/540/630/730, this option is ignored. (default: MMIO)");
+
+/* TW: "Import" the options from the X driver */
+MODULE_PARM(mem,    "i");
+MODULE_PARM_DESC(mem,
+	"Determines the beginning of the video memory heap in KB. This heap is used for "
+	"video RAM management for eg. DRM/DRI. The default depends on the amount of video "
+	"memory available. If 8MB of video RAM or less is available, "
+	"the heap starts at 4096KB, otherwise at 8192KB. The value is to be specified "
+	"without 'KB' and should match MaxXFBMem setting for XFree 4.x (x>=2). "
+	"See http://www.winischhofer.net/linuxsis630.shtml for a closer description.");
+
+MODULE_PARM(forcecrt2type, "s");
+MODULE_PARM_DESC(forcecrt2type,
+	"If this option is omitted, the driver autodetects CRT2 output devices, such as LCD, "
+	"TV or secondary VGA (in this order; so if eg. an LCD is there, it will be used regardless "
+	"of a connected TV set). With this option, this autodetection can be overridden. "
+	"Possible parameters are LCD, TV, VGA or NONE. NONE disables CRT2 and makes it "
+	"possible to use higher resolutions on CRT1 than eg. your LCD panel supports. TV "
+	"selects TV output (only resolutions 640x480 and 800x600 are supported for TV!). "
+	"VGA refers to _secondary_ VGA which is unlikely to be available; the VGA plug found "
+	"on most machines is CRT1. (default: [autodetected])");
+
+MODULE_PARM(forcecrt1, "i");
+MODULE_PARM_DESC(forcecrt1,
+	"Normally, the driver autodetects whether or not CRT1 (external VGA) is connected. "
+	"With this option, the detection can be overridden (1=CRT1 ON, 0=CRT1 off) "
+	"(default: [autodetected])");
 
 int init_module(void)
 {
@@ -3064,16 +3382,28 @@
 
 	ivideo.refresh_rate = rate;
 
-	if (crt1 == 0)
+	if (forcecrt2type)
+		sisfb_search_crt2type(forcecrt2type);
+
+	if (crt1off == 0)
 		sisfb_crt1off = 1;
 	else
 		sisfb_crt1off = 0;
 
-	 if (mem)
+	sisfb_forcecrt1 = forcecrt1;
+	if (forcecrt1 == 1)
+		sisfb_crt1off = 0;
+	else if (forcecrt1 == 0)
+		sisfb_crt1off = 1;
+
+	if (mem)
 		sisfb_mem = mem;
 
 	enable_dstn = dstn; /* JennyLee 20011211 */
 
+	if (queuemode)
+		sisfb_search_queuemode(queuemode);
+
 	sisfb_init();
 
 	return 0;
@@ -3081,11 +3411,19 @@
 
 void cleanup_module(void)
 {
+	/* TW: Release mem regions */
+	release_mem_region(ivideo.video_base, ivideo.video_size);
+	release_mem_region(ivideo.mmio_base, sisfb_mmio_size);
+	/* TW: Release MTRR region */
+	if (ivideo.mtrr) mtrr_del(ivideo.mtrr, 
+			      (unsigned int)ivideo.video_base,
+	                      (unsigned int)ivideo.video_size);
+	/* Unregister the framebuffer */
 	unregister_framebuffer(&fb_info);
+	printk(KERN_INFO "sisfb: Module unloaded\n");
 }
 #endif
 
-
 EXPORT_SYMBOL(sis_malloc);
 EXPORT_SYMBOL(sis_free);
 EXPORT_SYMBOL(sis_dispinfo);
diff -urN linux-2.4.19-pre9/drivers/video/sis/sis_main.h linux-2.4.19-pre10/drivers/video/sis/sis_main.h
--- linux-2.4.19-pre9/drivers/video/sis/sis_main.h	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/video/sis/sis_main.h	Mon Jun  3 18:50:56 2002
@@ -10,7 +10,7 @@
 
 #define VER_MAJOR                 1
 #define VER_MINOR                 3
-#define VER_LEVEL                 11 
+#define VER_LEVEL                 13 
 
 /* TW: To be included in pci_ids.h */
 #ifndef PCI_DEVICE_ID_SI_650_VGA
@@ -92,7 +92,7 @@
 #define IND_SIS_SCRATCH_REG_CR37  0x37
 #define IND_SIS_AGP_IO_PAD        0x48
 
-#define IND_BRI_DRAM_STATUS       0x63
+#define IND_BRI_DRAM_STATUS       0x63 /* PCI memory size offset */
 
 #define MMIO_QUEUE_PHYBASE        0x85C0
 #define MMIO_QUEUE_WRITEPORT      0x85C4
@@ -121,7 +121,8 @@
 #define SIS_DATA_BUS_32           0x00
 #define SIS_DATA_BUS_64           0x01
 #define SIS_DATA_BUS_128          0x02
-#define SIS315_DRAM_SIZE_MASK     0xF0  /* 315 SR14 */
+
+#define SIS315_DRAM_SIZE_MASK     0xF0  /* 315/640?/740? SR14 */
 #define SIS315_DRAM_SIZE_2MB      0x01
 #define SIS315_DRAM_SIZE_4MB      0x02
 #define SIS315_DRAM_SIZE_8MB      0x03
@@ -133,10 +134,12 @@
 #define SIS315_DATA_BUS_64        0x00
 #define SIS315_DATA_BUS_128       0x01
 #define SIS315_DUAL_CHANNEL_MASK  0x0C
-#define SIS315_SINGLE_CHANNEL_1_RANK  0x0
-#define SIS315_SINGLE_CHANNEL_2_RANK  0x1
-#define SIS315_DUAL_CHANNEL_1_RANK    0x3
-#define SIS550_DRAM_SIZE_MASK     0x3F  /* 550 SR14 */
+#define SIS315_SINGLE_CHANNEL_1_RANK  	0x0
+#define SIS315_SINGLE_CHANNEL_2_RANK  	0x1
+#define SIS315_ASYM_DDR		  	0x02
+#define SIS315_DUAL_CHANNEL_1_RANK    	0x3
+
+#define SIS550_DRAM_SIZE_MASK     0x3F  /* 550/650 SR14 */
 #define SIS550_DRAM_SIZE_4MB      0x00
 #define SIS550_DRAM_SIZE_8MB      0x01
 #define SIS550_DRAM_SIZE_16MB     0x03
@@ -148,17 +151,22 @@
 #define SIS550_DRAM_SIZE_256MB    0x3F
 
 #define SIS_SCRATCH_REG_1A_MASK   0x10
+
 #define SIS_ENABLE_2D             0x40  /* SR1E */
+
 #define SIS_MEM_MAP_IO_ENABLE     0x01  /* SR20 */
 #define SIS_PCI_ADDR_ENABLE       0x80
+
 #define SIS_AGP_CMDQUEUE_ENABLE   0x80  /* 315 SR26 */
-#define SIS_VRAM_CMDQUEUE_ENABLE  0x40 
+#define SIS_VRAM_CMDQUEUE_ENABLE  0x40
 #define SIS_MMIO_CMD_ENABLE       0x20
 #define SIS_CMD_QUEUE_SIZE_512k   0x00
 #define SIS_CMD_QUEUE_SIZE_1M     0x04
 #define SIS_CMD_QUEUE_SIZE_2M     0x08
 #define SIS_CMD_QUEUE_SIZE_4M     0x0C
-#define SIS_CMD_QUEUE_RESET       0x01 
+#define SIS_CMD_QUEUE_RESET       0x01
+#define SIS_CMD_AUTO_CORR	  0x02
+
 #define SIS_SIMULTANEOUS_VIEW_ENABLE  0x01  /* CR30 */
 #define SIS_MODE_SELECT_CRT2      0x02
 #define SIS_VB_OUTPUT_COMPOSITE   0x04
@@ -184,6 +192,7 @@
 #define SIS_LCD_PANEL_1280X960    0x4
 #define SIS_LCD_PANEL_640X480     0x5
 #define SIS_LCD_PANEL_1600x1200   0x6  /* TW */
+#define SIS_LCD_PANEL_320x480	  0x7  /* TW: FSTN */
 #define SIS_EXTERNAL_CHIP_MASK    0x0E  /* CR37 */
 #define SIS_EXTERNAL_CHIP_SIS301        0x01
 #define SIS_EXTERNAL_CHIP_LVDS          0x02  
@@ -253,6 +262,7 @@
 /* display status */
 static int sisfb_off = 0;
 static int sisfb_crt1off = 0;
+static int sisfb_forcecrt1 = -1;
 static int sisfb_inverse = 0;
 static int sisvga_enabled = 0;
 static int currcon = 0;
@@ -275,6 +285,10 @@
 u8  sisfb_mode_no = 0;
 u8  sisfb_rate_idx = 0;
 
+int sisfb_crt2type = -1;	/* TW: CRT2 type (for overriding autodetection) */
+
+int sisfb_queuemode = -1; 	/* TW: Use MMIO queue mode by default (310 series only) */
+
 /* data for sis components*/
 struct video_info ivideo;
 
@@ -330,7 +344,7 @@
 	{"320x480x16",   0x5B,  320,  480, 16, 1,  40, 30},
 	{"640x480x8",    0x2E,  640,  480,  8, 1,  80, 30},
 	{"640x480x16",   0x44,  640,  480, 16, 1,  80, 30},
-	{"640x480x24",   0x62,  640,  480, 32, 1,  80, 30}, /* TW: That's for people you mix up color- and fb depth */
+	{"640x480x24",   0x62,  640,  480, 32, 1,  80, 30}, /* TW: That's for people who mix up color- and fb depth */
 	{"640x480x32",   0x62,  640,  480, 32, 1,  80, 30},
 	{"720x480x8",    0x31,  720,  480,  8, 1,  90, 30},
 	{"720x480x16",   0x33,  720,  480, 16, 1,  90, 30},
@@ -367,6 +381,34 @@
 	{"\0", 0x00, 0, 0, 0, 0, 0, 0}
 };
 
+static const struct _sis_crt2type {
+	char name[6];
+	int type_no;
+} sis_crt2type[] = {
+	{"NONE", 0},
+	{"LCD",  DISPTYPE_LCD},
+	{"TV",   DISPTYPE_TV},
+	{"VGA",  DISPTYPE_CRT2},
+	{"none", 0},	/* TW: make it fool-proof */
+	{"lcd",  DISPTYPE_LCD},
+	{"tv",   DISPTYPE_TV},
+	{"vga",  DISPTYPE_CRT2},
+	{"\0",  -1}
+};
+
+static const struct _sis_queuemode {
+	char name[6];
+	int type_no;
+} sis_queuemode[] = {
+	{"AGP",  AGP_CMD_QUEUE},
+	{"VRAM", VM_CMD_QUEUE},
+	{"MMIO", MMIO_CMD},
+	{"agp",  AGP_CMD_QUEUE},
+	{"vram", VM_CMD_QUEUE},
+	{"mmio", MMIO_CMD},
+	{"\0",  -1}
+};
+
 static struct _sis_vrate {
 	u16 idx;
 	u16 xres;
@@ -645,6 +687,7 @@
 //extern BOOLEAN SiSInit310(PHW_DEVICE_EXTENSION HwDeviceExtension);
 static void sisfb_detect_VB_connect_315(void);
 static void sisfb_get_VB_type_315(void);
+static int sisfb_has_VB_315(void);
 //extern BOOLEAN SiSSetMode310(PHW_DEVICE_EXTENSION HwDeviceExtension, USHORT ModeNo);
 #endif
 
@@ -656,6 +699,11 @@
 extern void SetEnableDstn(void);
 // ~Eden Chen
 
+extern void 	SiSRegInit(USHORT BaseAddr);
+extern USHORT 	SiS_GetCH7005(USHORT tempbx);
+extern void 	SiS_SetCH7005(USHORT tempbx);
+extern void     SiS_SetCHTVRegANDOR(USHORT tempax,USHORT tempbh);
+
 static void sisfb_pre_setmode(void);
 static void sisfb_post_setmode(void);
 static void sisfb_crtc_to_var(struct fb_var_screeninfo *var);
diff -urN linux-2.4.19-pre9/drivers/video/sis/vgatypes.h linux-2.4.19-pre10/drivers/video/sis/vgatypes.h
--- linux-2.4.19-pre9/drivers/video/sis/vgatypes.h	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/video/sis/vgatypes.h	Mon Jun  3 18:50:56 2002
@@ -135,13 +135,12 @@
     LCD_1600x1200,
     LCD_1920x1440,
     LCD_2048x1536,
+    LCD_320x480,    /* TW: FSTN */
     LCD_UNKNOWN
 } SIS_LCD_TYPE;
 #endif
 #endif
 
-
-
 #ifndef WIN2000 /* mark by Paul ,Move definition to sisv.h*/
 #ifndef PSIS_DSReg
 typedef struct _SIS_DSReg
@@ -151,9 +150,6 @@
 } SIS_DSReg, *PSIS_DSReg;
 #endif
 
-
-
-
 #ifndef SIS_HW_DEVICE_INFO
 
 typedef struct _SIS_HW_DEVICE_INFO  SIS_HW_DEVICE_INFO, *PSIS_HW_DEVICE_INFO;
diff -urN linux-2.4.19-pre9/drivers/video/sstfb.c linux-2.4.19-pre10/drivers/video/sstfb.c
--- linux-2.4.19-pre9/drivers/video/sstfb.c	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/video/sstfb.c	Mon Jun  3 18:50:56 2002
@@ -1,20 +1,16 @@
 /*
  * linux/drivers/video/sstfb.c -- voodoo graphics frame buffer
  *
- *     Copyright (c) 2000,2001 Ghozlane Toumi <gtoumi@messel.emse.fr>
+ *     Copyright (c) 2000-2002 Ghozlane Toumi <gtoumi@laposte.net>
  *
  *     Created 15 Jan 2000 by Ghozlane Toumi
  *
- *     NOTE: I have been unable to reach Ghozlane through the eMail-address
- *     given above for more than 3 months, same with another address of him
- *     which I found on the web. - Urs
- *
  * Contributions (and many thanks) :
  *
  * 03/2001 James Simmons   <jsimmons@linux-fbdev.org>
  * 04/2001 Paul Mundt      <lethal@chaoticdreams.org>
  * 05/2001 Urs Ganse       <ursg@uni.de>
- *     (initial work on voodoo2 port, added interlace support)
+ *     (initial work on voodoo2 port, interlace)
  *
  *
  * $Id: sstfb.c,v 1.26.4.1 2001/08/29 01:30:37 ghoz Exp $
@@ -31,40 +27,22 @@
  * misc notes, TODOs, toASKs, and deep thoughts
 
 -TODO: at one time or another test that the mode is acceptable by the monitor
--ASK: I can choose different ordering for the color bitfields (rgba argb ...) 
-      wich one should i use ? is there any preferred one ? It seems ARGB is 
+-ASK: I can choose different ordering for the color bitfields (rgba argb ...)
+      wich one should i use ? is there any preferred one ? It seems ARGB is
       the one ...
 -ASK: later: how to cope with endianness ? the fbi chip has builtin functions
       to do byte swizling /swapping, maybe use that ...
--TODO: check the error paths . if something get wrong, the error doesn't seem 
-      to be very well handled...if handled at all.. not good. 
--ASK: ioremap ou ioremap_nocache ? : nocache is safe
+-TODO: check the error paths . if something get wrong, the error doesn't seem
+      to be very well handled...if handled at all.. not good.
 -TODO: in  set_var check the validity of timings (hsync vsync)...
--FIXME: I'm not sure i like all the functions with no parameters.. change them 
-        to use a sstfb_par or sstfb_info or something like that.
--TODO: check and recheck the use of sst_wait_idle : we dont flush the fifo via 
-       a nop command . so it's ok as long as the commands we pass don't go 
-       through the fifo. warning: issuing a nop command seems to need pci_fifo 
-       enabled
--ASK: the 24 bits mode is NOT packed . how do i differenciate from a packed mode ?
-      set a pseudo alpha value not used ?
--ASK: how does the 32 bpp work ? should i enable the pipeline so alpha values 
-      are used ?
--TODO: check how the voodoo graphics can cope with 24/32 bpp (engine is 16bpp 
-       only)
--ASK: Do i ioremap the complete area devoted to the lfb (4Mb), or check the 
-      real size, then unmap and remap to the real size of the lfb ? 
-      ... map all the area.
--FIXME: in case of failure in the init sequence, be sure we return to a safe 
+-TODO: check and recheck the use of sst_wait_idle : we dont flush the fifo via
+       a nop command . so it's ok as long as the commands we pass don't go
+       through the fifo. warning: issuing a nop command seems to need pci_fifo
+-FIXME: in case of failure in the init sequence, be sure we return to a safe
         state.
 -FIXME: 4MB boards have banked memory (FbiInit2 bits 1 & 20)
 -ASK: I stole "inverse" but seems it doesn't work... check what it realy does...
-Notes
 -TODO: change struct sst_info fb_info from static to array/dynamic
-  TTT comments is for code i've put there for debuging the "weird peinguin 
-  	syndrome", it should disapear soon
--FIXME: Some uninitialized variable causes sporadic crashes when setting a video
-       mode for the first time.
 
  *
  */
@@ -125,6 +103,7 @@
 #include <linux/delay.h>
 #include <linux/init.h>
 #include <linux/version.h>
+#include <linux/slab.h>
 
 #include <asm/io.h>
 #include <asm/ioctl.h>
@@ -138,52 +117,11 @@
 
 #include "sstfb.h"
 
-/* void Dump_regs(void); */
-
-/* sst default init registers */
-#define FBIINIT0_DEFAULT EN_VGA_PASSTHROUGH
-
-#define FBIINIT1_DEFAULT 	\
-	(			\
-	  FAST_PCI_WRITES	\
-/*	  SLOW_PCI_WRITES*/	\
-	| VIDEO_RESET		\
-	| 10 << TILES_IN_X_SHIFT\
-	| SEL_SOURCE_VCLK_2X_SEL\
-	| EN_LFB_READ		\
-	)
-
-#define FBIINIT2_DEFAULT	\
-	(			\
-	 SWAP_DACVSYNC		\
-	| EN_DRAM_OE		\
-	| DRAM_REFRESH_16	\
-	| EN_DRAM_REFRESH	\
-	| EN_FAST_RAS_READ	\
-	| EN_RD_AHEAD_FIFO	\
-	| EN_FAST_RD_AHEAD_WR	\
-	)
-
-#define FBIINIT3_DEFAULT 	\
-	( DISABLE_TEXTURE )
-
-#define FBIINIT4_DEFAULT	\
-	(			\
-	  FAST_PCI_READS	\
-/*	  SLOW_PCI_READS*/	\
-	| LFB_READ_AHEAD	\
-	)
-/* Careful with this one : writing back the data just read will trash the DAC
-   reading some fields give logic value on pins, but setting this field will
-   set the source signal driving the pin. conclusion : just use the default
-   as a base before writing back .
-*/
-#define FBIINIT6_DEFAULT	(0x0)
+/* void __Dump_regs(struct sstfb_info *);
+#define Dump_regs __Dump_regs(sst_info) */
 
 /********/
 
-int currcon; /* =0 */
-int num_sst; /* =0*/		/* number of initialized boards */
 
 /* initialized by setup */
 static int inverse; /* =0 */	/* invert colormap */
@@ -192,31 +130,17 @@
 static int clipping = 1;	/* use clipping (slower, safer) */
 static int gfxclk;  /* =0 */	/* force FBI freq in Mhz . Dangerous */
 static int slowpci; /* =0 */	/* slow PCI settings */
-static int dev = -1;		/* specify device (0..n) */
+static int dev = -2;		/* specify device (0..n) -2=all -1=none*/
+
 static char * mode_option ;
 
 
-#if defined(FBCON_HAS_CFB16) || defined(FBCON_HAS_CFB24) || defined(FBCON_HAS_CFB32)
-union {
-#  ifdef FBCON_HAS_CFB16
-	u16 cfb16[16];
-#  endif
-#ifdef EN_24_32_BPP
-#  if defined (FBCON_HAS_CFB24) || defined(FBCON_HAS_CFB32)
-	u32 cfb32[16];
-#  endif
-#endif
-	} fbcon_cmap;
-#endif
-static struct { u_int red, green, blue, transp; } palette[16];
-static struct sstfb_info fb_info;
-static struct display disp;
-
 /********/
 
-/* Interface to the world  */
 int sstfb_init(void);
 int sstfb_setup(char *options);
+static int __devinit sstfb_probe(struct pci_dev *pdev, const struct pci_device_id *id);
+static void __devexit sstfb_remove(struct pci_dev *pdev);
 
 
 /* Framebuffer API */
@@ -266,21 +190,20 @@
 #endif
 
 /* Low level routines */
-static int sst_get_memsize(u_long *memsize);
-static int sst_wait_idle(void);
-static int sst_detect_dactype(void);
-static int sst_detect_att(void);
-static int sst_detect_ti(void);
-static int sst_detect_ics(void);
+static int sst_get_memsize(struct sstfb_info *sst_info, u_long *memsize);
+static int __sst_wait_idle(u_long vbase);
+#define sst_wait_idle()	 __sst_wait_idle(sst_info->mmio.vbase)
+static int sst_detect_dactype(struct sstfb_info *sst_info);
+static int sst_detect_att(struct sstfb_info *sst_info);
+static int sst_detect_ti(struct sstfb_info *sst_info);
+static int sst_detect_ics(struct sstfb_info *sst_info);
 static int sst_calc_pll(const int freq, int *freq_out, struct pll_timing *t);
-static int sst_set_pll_att_ti(const struct pll_timing *t, const int clock);
-static int sst_set_pll_ics(const struct pll_timing *t, const int clock);
-static void sst_set_vidmod_att_ti(const int bpp);
-static void sst_set_vidmod_ics(const int bpp);
-static int sst_init(void);
-#ifdef MODULE
-static void sst_shutdown(void);
-#endif
+static int sst_set_pll_att_ti(struct sstfb_info *sst_info, const struct pll_timing *t, const int clock);
+static int sst_set_pll_ics(struct sstfb_info *sst_info, const struct pll_timing *t, const int clock);
+static void sst_set_vidmod_att_ti(struct sstfb_info *sst_info, const int bpp);
+static void sst_set_vidmod_ics(struct sstfb_info *sst_info, const int bpp);
+static int sst_init(struct sstfb_info *sst_info);
+static void sst_shutdown(struct sstfb_info *sst_info);
 
 static struct fb_ops sstfb_ops = {
 	owner : THIS_MODULE,
@@ -295,9 +218,37 @@
 	fb_ioctl:	sstfb_ioctl,
 };
 
-#ifndef DEFAULT_MODE
-#  define DEFAULT_MODE 0
-#endif
+enum {
+	ID_VOODOO1 = 0,
+	ID_VOODOO2 = 1,
+};
+
+#define IS_VOODOO2(info) ((info)->type == ID_VOODOO2 )
+
+static struct sst_spec voodoo_spec[] __devinitdata = {
+	{ name : "Voodoo Graphics",
+	default_gfx_clock : 50000,
+	max_gfxclk : 60, },
+	{ name : "Voodoo2",
+	default_gfx_clock : 75000,
+	max_gfxclk : 85, },
+};
+
+static struct pci_device_id sstfb_id_tbl[] __devinitdata = {
+	{ PCI_VENDOR_ID_3DFX, PCI_DEVICE_ID_3DFX_VOODOO,
+	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, ID_VOODOO1 },
+	{ PCI_VENDOR_ID_3DFX, PCI_DEVICE_ID_3DFX_VOODOO2,
+	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, ID_VOODOO2 },
+	{ 0 },
+};
+
+static struct pci_driver sstfb_driver = {
+	name:		"sstfb",
+	id_table:	sstfb_id_tbl,
+	probe:          sstfb_probe,
+	remove:		__devexit_p(sstfb_remove),
+};
+
 static struct fb_var_screeninfo	sstfb_default =
 #if ( DEFAULT_MODE == 0 )
     { /* 800x600@60, 16 bpp .borowed from glide/sst1/include/sst1init.h */
@@ -332,7 +283,7 @@
     0, FB_VMODE_NONINTERLACED };
 #endif
 
-static struct dac_switch dacs[] = {
+static struct dac_switch dacs[] __devinitdata = {
 	{	name:		"TI TVP3409",
 		detect:		sst_detect_ti,
 		set_pll:	sst_set_pll_att_ti,
@@ -348,17 +299,6 @@
 		set_vidmod:	sst_set_vidmod_ics },
 };
 
-static struct sst_spec voodoo1_spec = {
-	name : "Voodoo Graphics",
-	default_gfx_clock : 50000,
-	max_gfxclk : 60,
-};
-
-static struct sst_spec voodoo2_spec = {
-	name : "Voodoo2",
-	default_gfx_clock : 75000,
-	max_gfxclk : 85,
-};
 
 /*
  *
@@ -390,8 +330,8 @@
 }
 #endif /* (SST_DEBUG_VAR > 0) */
 
+#if (SST_DEBUG_REG > 0)
 static void sst_dbg_print_read_reg (u32 reg, u32 val) {
-#if (SST_DEBUG_REG > 0) /* i need the init registers :) */
 	char * regname =NULL;
 	switch (reg) {
 	case FBIINIT0: regname="FbiInit0"; break;
@@ -399,17 +339,16 @@
 	case FBIINIT2: regname="FbiInit2"; break;
 	case FBIINIT3: regname="FbiInit3"; break;
 	case FBIINIT4: regname="FbiInit4"; break;
+	case FBIINIT5: regname="FbiInit5"; break;
 	case FBIINIT6: regname="FbiInit6"; break;
 	}
 	if (regname == NULL)
 		r_ddprintk("sst_read(%#x): %#x\n", reg, val);
 	else
 		r_dprintk(" sst_read(%s): %#x\n", regname, val);
-#endif /*  (SST_DEBUG_REG > 0) */
 }
 
 static void sst_dbg_print_write_reg (u32 reg, u32 val) {
-#if (SST_DEBUG_REG > 0) /* i need the init registers :) */
 	char * regname = NULL;
 
 	switch (reg) {
@@ -418,92 +357,104 @@
 	case FBIINIT2: regname="FbiInit2"; break;
 	case FBIINIT3: regname="FbiInit3"; break;
 	case FBIINIT4: regname="FbiInit4"; break;
+	case FBIINIT5: regname="FbiInit5"; break;
 	case FBIINIT6: regname="FbiInit6"; break;
 	}
 	if (regname == NULL)
 		r_ddprintk("sst_write(%#x, %#x)\n", reg, val);
 	else
 		r_dprintk(" sst_write(%s, %#x)\n", regname, val);
-#endif /*  (SST_DEBUG_REG > 0) */
 }
+#else /*  (SST_DEBUG_REG > 0) */
+#  define sst_dbg_print_read_reg(reg, val)	do {}while(0)
+#  define sst_dbg_print_write_reg(reg, val)	do {}while(0)
+#endif /*  (SST_DEBUG_REG > 0) */
 
 /* register access */
-static inline u32 sst_read(u32 reg)
+#define sst_read(reg)		__sst_read(sst_info->mmio.vbase, reg)
+#define sst_write(reg,val)	__sst_write(sst_info->mmio.vbase, reg, val)
+#define sst_set_bits(reg,val)	__sst_set_bits(sst_info->mmio.vbase, reg, val)
+#define sst_unset_bits(reg,val)	__sst_unset_bits(sst_info->mmio.vbase, reg, val)
+#define sst_dac_read(reg)	__sst_dac_read(sst_info->mmio.vbase, reg)
+#define sst_dac_write(reg,val)	__sst_dac_write(sst_info->mmio.vbase, reg, val)
+#define dac_i_read(reg)		__dac_i_read(sst_info->mmio.vbase, reg)
+#define dac_i_write(reg,val)	__dac_i_write(sst_info->mmio.vbase, reg, val)
+
+static inline u32 __sst_read(u_long vbase, u32 reg)
 {
 	u32 ret;
 
-	ret = readl(fb_info.mmio.vbase + reg);
+	ret = readl(vbase + reg);
 	sst_dbg_print_read_reg(reg, ret);
 	return ret;
 }
 
-static inline void sst_write(u32 reg, u32 val)
+static inline void __sst_write(u_long vbase, u32 reg, u32 val)
 {
 	sst_dbg_print_write_reg(reg, val);
-	writel(val, fb_info.mmio.vbase + reg);
+	writel(val, vbase + reg);
 }
 
-static inline void sst_set_bits(u32 reg, u32 val)
+static inline void __sst_set_bits(u_long vbase, u32 reg, u32 val)
 {
 	r_dprintk("sst_set_bits(%#x, %#x)\n", reg, val);
-	sst_write(reg, sst_read(reg) | val);
+	__sst_write(vbase, reg, __sst_read(vbase, reg) | val);
 }
 
-static inline void sst_unset_bits(u32 reg, u32 val)
+static inline void __sst_unset_bits(u_long vbase, u32 reg, u32 val)
 {
 	r_dprintk("sst_unset_bits(%#x, %#x)\n", reg, val);
-	sst_write(reg, sst_read(reg) & ~val);
+	__sst_write(vbase, reg, __sst_read(vbase, reg) & ~val);
 }
 
 /* dac access */
 /* dac_read should be remaped to FbiInit2 (via the pci reg init_enable) */
-static u8 sst_dac_read(u8 reg)
+static u8 __sst_dac_read(u_long vbase, u8 reg)
 {
 	u8 ret;
 
 #ifdef SST_DEBUG
 	if ((reg & 0x07) != reg) {
-		dprintk("bug line %d: register adress '%d' is to high\n",
+		dprintk("bug line %d: register adress '%d' is too high\n",
 		         __LINE__,reg);
 	}
 #endif
 	reg &= 0x07;
-	sst_write(DAC_DATA, ((u32)reg << 8) | DAC_READ_CMD );
-	sst_wait_idle();
+	__sst_write(vbase, DAC_DATA, ((u32)reg << 8) | DAC_READ_CMD );
+	__sst_wait_idle(vbase);
 	/*udelay(10);*/
-	ret=(sst_read(DAC_READ) & 0xff);
+	ret=(__sst_read(vbase, DAC_READ) & 0xff);
 	r_dprintk("sst_dac_read(%#x): %#x\n", reg, ret);
 	return (u8)ret;
 }
 
-static void sst_dac_write(u8 reg, u8 val)
+static void __sst_dac_write(u_long vbase, u8 reg, u8 val)
 {
 	r_dprintk("sst_dac_write(%#x, %#x)\n", reg, val);
 #ifdef SST_DEBUG
 	if ((reg & 0x07) != reg)
-		dprintk("bug line %d: register adress '%d' is to high\n",
+		dprintk("bug line %d: register adress '%d' is too high\n",
 		         __LINE__,reg);
 #endif
 	reg &= 0x07;
-	sst_write(DAC_DATA,(((u32)reg << 8)) | (u32)val);
+	__sst_write(vbase, DAC_DATA,(((u32)reg << 8)) | (u32)val);
 }
 
 /* indexed access to ti/att dacs */
-static inline u32 dac_i_read(u8 reg)
+static u32 __dac_i_read(u_long vbase, u8 reg)
 {
 	u32 ret;
 
-	sst_dac_write(DACREG_ADDR_I, reg);
-	ret = sst_dac_read(DACREG_DATA_I);
+	__sst_dac_write(vbase, DACREG_ADDR_I, reg);
+	ret = __sst_dac_read(vbase, DACREG_DATA_I);
 	r_dprintk("sst_dac_read_i(%#x): %#x\n", reg, ret);
 	return ret;
 }
-
-static inline void dac_i_write(u8 reg,u8 val)
+static void __dac_i_write(u_long vbase, u8 reg,u8 val)
 {
 	r_dprintk("sst_dac_write_i(%#x, %#x)\n", reg, val);
-	sst_dac_write(DACREG_ADDR_I, reg);
-	sst_dac_write(DACREG_DATA_I, val);
+	__sst_dac_write(vbase, DACREG_ADDR_I, reg);
+	__sst_dac_write(vbase, DACREG_DATA_I, val);
 }
 
 /*
@@ -514,9 +465,10 @@
 
 static void sstfb_install_cmap(int con, struct fb_info *info)
 {
+#define sst_info	((struct sstfb_info *) info)
 	f_dprintk("sstfb_install_cmap(con: %d)\n",con);
-	f_ddprintk("currcon: %d\n", currcon);
-	if (con != currcon)
+	f_ddprintk("currcon: %d\n", sst_info->currcon);
+	if (con != sst_info->currcon)
 		return;
 	if (fb_display[con].cmap.len)
 		fb_set_cmap(&fb_display[con].cmap, 1, sstfb_setcolreg, info);
@@ -524,71 +476,80 @@
 		fb_set_cmap(
 			fb_default_cmap(1<<fb_display[con].var.bits_per_pixel),
 			1, sstfb_setcolreg, info);
+#undef sst_info
 }
 
 static int sstfb_getcolreg(u_int regno, u_int *red, u_int *green, u_int *blue,
                            u_int *transp, struct fb_info *info)
 {
-	f_ddprintk("sstfb_getcolreg\n");
+#define sst_info	((struct sstfb_info *) info)
+	f_dddprintk("sstfb_getcolreg\n");
 	if (regno >= 16) return 1;
 
-	*red    = palette[regno].red;
-	*green  = palette[regno].green;
-	*blue   = palette[regno].blue;
-	*transp = palette[regno].transp;
+	*red    = sst_info->palette[regno].red;
+	*green  = sst_info->palette[regno].green;
+	*blue   = sst_info->palette[regno].blue;
+	*transp = sst_info->palette[regno].transp;
 	f_dddprintk("%-2d rvba: %#x, %#x, %#x, %#x\n",
 	            regno,*red, *green, *blue, *transp);
 	return 0;
+#undef sst_info
 }
 
 static int sstfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
                            u_int transp, struct fb_info *info)
 {
+#define sst_info	((struct sstfb_info *) info)
 	u32 col;
+	struct display * disp;
 
-	f_ddprintk("sstfb_setcolreg\n");
+	f_dddprintk("sstfb_setcolreg\n");
 	f_dddprintk("%-2d rvba: %#x, %#x, %#x, %#x\n",
 	            regno, red, green, blue, transp);
 	if (regno >= 16) return 1;
-	palette[regno].red   = red;
-	palette[regno].green = green;
-	palette[regno].blue  = blue;
-
-	red    >>= (16 - disp.var.red.length);
-	green  >>= (16 - disp.var.green.length);
-	blue   >>= (16 - disp.var.blue.length);
-	transp >>= (16 - disp.var.transp.length);
-	col = (red << disp.var.red.offset)
-		| (green << disp.var.green.offset)
-		| (blue  << disp.var.blue.offset)
-		| (transp << disp.var.transp.offset);
 
-	switch(disp.var.bits_per_pixel) {
+	sst_info->palette[regno].red   = red;
+	sst_info->palette[regno].green = green;
+	sst_info->palette[regno].blue  = blue;
+	sst_info->palette[regno].transp= transp;
+
+	disp=&sst_info->disp;
+	red    >>= (16 - disp->var.red.length);
+	green  >>= (16 - disp->var.green.length);
+	blue   >>= (16 - disp->var.blue.length);
+	transp >>= (16 - disp->var.transp.length);
+	col = (red << disp->var.red.offset)
+	    | (green << disp->var.green.offset)
+	    | (blue  << disp->var.blue.offset)
+	    | (transp << disp->var.transp.offset);
+
+	switch(disp->var.bits_per_pixel) {
 #ifdef FBCON_HAS_CFB16
 	case 16:
-		fbcon_cmap.cfb16[regno]=(u16)col;
+		sst_info->fbcon_cmap.cfb16[regno]=(u16)col;
 		break;
 #endif
 #ifdef EN_24_32_BPP
 #ifdef FBCON_HAS_CFB24
 	case 24:
-		fbcon_cmap.cfb32[regno]=col;
+		sst_info->fbcon_cmap.cfb32[regno]=col;
 		break;
 #endif
 #ifdef FBCON_HAS_CFB32
 	case 32:
-		fbcon_cmap.cfb32[regno]=col;
+		sst_info->fbcon_cmap.cfb32[regno]=col;
 		break;
 #endif
 #endif
 	default:
 		eprintk("bug line %d: bad depth '%u'\n",__LINE__,
-			disp.var.bits_per_pixel);
+			disp->var.bits_per_pixel);
 		break;
 	}
 	f_dddprintk("bpp: %d . encoded color: %#x\n",
-	            disp.var.bits_per_pixel, col);
+	            disp->var.bits_per_pixel, col);
 	return 0;
+#undef sst_info
 }
 
 /* set par according to var ( checks var ) */
@@ -600,16 +561,7 @@
 
 	f_dprintk("sstfb_decode_var\n");
 	/* Check var validity */
-	if ((var->xres > 1024) || (!var->xres) || (!var->xres)) {
-		eprintk ("Unsupported resolution %dx%d\n",
-		         var->xres, var->yres);
-		return -EINVAL;
-	}
-	if((var->vmode & FB_VMODE_MASK) && !sst_info->is_voodoo2 ){
-		eprintk ("Interlace modes not supported on Voodoo 1 hardware.\n");
-		return -EINVAL;
-	}
-
+	par->valid=0;
 
 	memset(par, 0, sizeof(par));
 	par->xDim       = var->xres;
@@ -620,17 +572,25 @@
 	par->vSyncOn    = var->vsync_len;
 	par->vSyncOff   = var->yres + var->lower_margin + var->upper_margin;
 	par->vBackPorch = var->upper_margin;
-	
-	par->flags      = 0;
-	if (var->vmode & FB_VMODE_INTERLACED) {
-//		printk(KERN_DEBUG "sstfb: This is an interlace mode.\n");
-		par->flags|=FB_VMODE_INTERLACED;
-	}
-	if(var->vmode & FB_VMODE_DOUBLE) {
-//		printk(KERN_DEBUG "sstfb: This is a doublescan mode.\n");
-		par->flags|=FB_VMODE_DOUBLE;
+
+	if(sst_calc_pll (PS2KHZ(var->pixclock), &par->freq, &par->pll)) {
+		eprintk("Pixclock %d out of range\n", var->pixclock);
+		return -EINVAL; //XXX
+	}
+
+	par->sync=var->sync & (FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT);
+	par->vmode=var->vmode & (FB_VMODE_INTERLACED | FB_VMODE_DOUBLE);
+
+	/* in laced mode, vBackPorch should be even. odd -> funky display */
+	if (par->vmode & FB_VMODE_INTERLACED)
+		par->vBackPorch += (par->vBackPorch % 2);
+	if (par->vmode & FB_VMODE_DOUBLE) {
+		par->vBackPorch <<= 1;
+		par->yDim <<=1;
+		par->vSyncOn <<=1;
+		par->vSyncOff <<=1;
 	}
-		
+
 	switch (var->bits_per_pixel) {
 	case 0 ... 16 :
 		par->bpp = 16;
@@ -649,7 +609,7 @@
 		break;
 	}
 
-	if (sst_info->is_voodoo2) {
+	if (IS_VOODOO2(sst_info)) {
 		/* voodoo2 has 32 pixel wide tiles , BUT stange things
 		 happen with odd number of tiles */
 		par->tiles_in_X= (par->xDim + 63 ) / 64 * 2;
@@ -658,23 +618,68 @@
 		par->tiles_in_X= (par->xDim + 63 ) / 64;
 	}
 
-	/*
-	 *  mem check
-	 */
+	/* validity tests */
+	if((par->xDim <= 1) || (par->yDim <= 0 )
+	   || (par->hSyncOn <= 1)
+	   || (par->hSyncOff <= 1)
+	   || (par->hBackPorch <= 2)
+	   || (par->vSyncOn <= 0)
+	   || (par->vSyncOff <= 0)
+	   || (par->vBackPorch <= 0)
+	   || (par->tiles_in_X <= 0)) {
+		return -EINVAL;
+	}
+	if (IS_VOODOO2(sst_info)) {
+		/* Voodoo 2 limits */
+		if(((par->xDim-1) >= POW2(11)) || (par->yDim >= POW2(11))) {
+			eprintk ("Unsupported resolution %dx%d\n",
+			         var->xres, var->yres);
+			return -EINVAL;
+		}
+		if (((par->hSyncOn-1) >= POW2(9))
+		   || ((par->hSyncOff-1) >= POW2(11))
+		   || ((par->hBackPorch-2) >= POW2(9))
+		   || (par->vSyncOn >= POW2(13))
+		   || (par->vSyncOff >= POW2(13))
+		   || (par->vBackPorch >= POW2(9))
+		   || (par->tiles_in_X >= POW2(6))) {
+			eprintk ("Unsupported Timing\n");
+			return -EINVAL;
+		}
+	} else {
+		/* Voodoo limits */
+		if (par->vmode) {
+			eprintk("Interlace/Doublescan not supported %#x\n",
+				par->vmode);
+			return -EINVAL;
+		}
+		if(((par->xDim-1) >= POW2(10)) || (par->yDim >= POW2(10))) {
+			eprintk ("Unsupported resolution %dx%d\n",
+			         var->xres, var->yres);
+			return -EINVAL;
+		}
+		if (((par->hSyncOn-1) >= POW2(8))
+		   || ((par->hSyncOff-1) >= POW2(10))
+		   || ((par->hBackPorch-2) >= POW2(8))
+		   || (par->vSyncOn >= POW2(12))
+		   || (par->vSyncOff >= POW2(12))
+		   || (par->vBackPorch >= POW2(8))
+		   || (par->tiles_in_X >= POW2(4))) {
+			eprintk ("Unsupported Timings\n");
+			return -EINVAL;
+		}
+	}
+
 	/* it seems that the fbi uses tiles of 64x16 pixels to "map" the mem*/
 	/* FIXME: i don't like this... looks wrong*/
-	real_length = par->tiles_in_X  * (sst_info->is_voodoo2 ? 32 : 64 )
+	real_length = par->tiles_in_X  * (IS_VOODOO2(sst_info) ? 32 : 64 )
 	              * ((par->bpp == 16) ? 2 : 4);
-/*shoud this function change var ? for instance with yvirt > yres  ?*/
 
-	if ((real_length * var->yres) > fb_info.video.len) {
+	if ((real_length * var->yres) > sst_info->video.len) {
 		eprintk ("Not enough video memory\n");
 		return -ENOMEM;
 	}
-
-	par->freq = PS2KHZ(var->pixclock);
-	
-	/* TODO add checks for timings */
+	par->valid=1;
 	return 0;
 }
 
@@ -700,7 +705,15 @@
 	var->lower_margin   = par->vSyncOff - par->yDim - par->vBackPorch;
 	var->hsync_len      = par->hSyncOn;
 	var->vsync_len      = par->vSyncOn;
-	var->vmode          = par->flags;
+	var->sync           = par->sync;
+	var->vmode          = par->vmode;
+	if (var->vmode & FB_VMODE_DOUBLE) {
+		var->yres           >>=1;
+		var->yres_virtual   >>=1;
+		var->vsync_len      >>=1;
+		var->upper_margin   >>=1;
+		var->lower_margin   >>=1;
+	}
 
 	/*
 	 * correct the color bit fields
@@ -747,14 +760,12 @@
 static int sstfb_open(struct fb_info *info, int user)
 {
 	f_dprintk("sstfb_open(user: %d)\n",user);
-	MOD_INC_USE_COUNT;
 	return 0;
 }
 
 static int sstfb_release(struct fb_info *info, int user)
 {
 	f_dprintk("sstfb_release(user: %d)\n",user);
-	MOD_DEC_USE_COUNT;
 	return 0;
 }
 
@@ -767,7 +778,7 @@
 
 	f_dprintk("sstfb_get_fix(con: %d)\n",con);
 	if (con == -1)
-		var = &sstfb_default;
+		sstfb_encode_var(var, &sst_info->current_par, sst_info);
 	else
 		var = &fb_display[con].var;
 
@@ -790,21 +801,23 @@
 static int sstfb_get_var(struct fb_var_screeninfo *var,
                          int con, struct fb_info *info)
 {
+#define sst_info	((struct sstfb_info *) info)
 	f_dprintk("sstfb_get_var(con: %d)\n",con);
 	if (con == -1)
-		*var = sstfb_default;
+		sstfb_encode_var(var, &sst_info->current_par, sst_info);
 	else
 		*var = fb_display[con].var;
 	print_var(var, "var");
 	return 0;
+#undef sst_info
  }
 
 static int sstfb_set_var(struct fb_var_screeninfo *var,
                          int con, struct fb_info *info)
 {
-#define sst_info	((struct sstfb_info *) info)	
+#define sst_info	((struct sstfb_info *) info)
 
-	struct sstfb_par par;	
+	struct sstfb_par par;
 	struct display *display;
 	int err;
 	int old_bpp,old_xres,old_yres;
@@ -815,15 +828,14 @@
 		 var->xres,var->yres,var->xres_virtual,var->yres_virtual,
 		 var->bits_per_pixel,var->activate);
 	if (con < 0)
-		display = &disp;
+		display = &sst_info->disp;
 	else
 		display = &fb_display[con];
 
-	err = sstfb_decode_var(var, &par, sst_info);
-	if (err)
+	if ((err = sstfb_decode_var(var, &par, sst_info)))
 		return err;
 	sstfb_encode_var (var, &par, sst_info);
-	
+
 	switch (var->activate & FB_ACTIVATE_MASK) {
 		case FB_ACTIVATE_TEST:
 			return 0;
@@ -853,7 +865,7 @@
 #ifdef FBCON_HAS_CFB16
 		case 16:
 			display->dispsw = &fbcon_cfb16;
-			display->dispsw_data = fbcon_cmap.cfb16;
+			display->dispsw_data = sst_info->fbcon_cmap.cfb16;
 			break;
 #endif
 #ifdef EN_24_32_BPP
@@ -861,7 +873,7 @@
 		case 24: /*24bpp non packed <=> 32 bpp */
 		case 32:
 			display->dispsw = &fbcon_cfb32;
-			display->dispsw_data = fbcon_cmap.cfb32;
+			display->dispsw_data = sst_info->fbcon_cmap.cfb32;
 			break;
 #endif
 #endif
@@ -879,7 +891,7 @@
 		}
 	}
 
-	if ((con <0) || (con==currcon)) {
+	if ((con == -1) || (con==sst_info->currcon)) {
 		sstfb_set_par (&par, sst_info);
 	}
 	print_var(var, "var");
@@ -899,34 +911,37 @@
 static int sstfb_set_cmap(struct fb_cmap *cmap, int kspc,
                           int con, struct fb_info *info)
 {
+#define sst_info	((struct sstfb_info *) info)
 	struct display *d = (con<0) ? info->disp : fb_display + con;
 
 	f_dprintk("sstfb_set_cmap\n");
 	f_ddprintk("con: %d, currcon: %d, d->cmap.len %d\n",
-		 con, currcon, d->cmap.len);
+		 con, sst_info->currcon, d->cmap.len);
 
 	if (d->cmap.len != 16 ) {	/* or test if cmap.len == 0 ? */
 		int err;
 		err = fb_alloc_cmap(&d->cmap, 16, 0); /* cmap size=16 */
 		if (err) return err;
 	}
-	if (con == currcon) {
+	if (con == sst_info->currcon) {
 		return fb_set_cmap(cmap, kspc, sstfb_setcolreg, info);
 	} else {
 		fb_copy_cmap(cmap, &d->cmap, kspc ? 0 : 1);
 	}
 	return 0;
+#undef sst_info
 }
 
 static int sstfb_get_cmap(struct fb_cmap *cmap, int kspc,
                           int con, struct fb_info *info)
 {
+#define sst_info	((struct sstfb_info *) info)
 	f_dprintk("sstfb_get_cmap\n");
 	f_ddprintk("con %d, curcon %d, cmap.len %d\n",
-		 con, currcon, fb_display[con].cmap.len);
+		 con, sst_info->currcon, fb_display[con].cmap.len);
 
 	/* FIXME: check if con = -1 ? cf sstfb_set_cmap...  */
-	if (con == currcon)
+	if (con == sst_info->currcon)
 		return fb_get_cmap(cmap, kspc, sstfb_getcolreg, info);
 	else if (fb_display[con].cmap.len)
 		fb_copy_cmap(&fb_display[con].cmap, cmap, kspc ? 0 : 2);
@@ -935,6 +950,7 @@
 			fb_default_cmap(1<<fb_display[con].var.bits_per_pixel),
 			cmap, kspc ? 0 : 2);
 	return 0;
+#undef sst_info
 }
 
 /* TODO */
@@ -949,7 +965,7 @@
                        u_int cmd, u_long arg, int con,
                        struct fb_info *info)
 {
-#define sst_info	((struct sstfb_info *) info)	
+#define sst_info	((struct sstfb_info *) info)
 #if (SST_DEBUG_IOCTL >0)
 	int i;
 	u_long p;
@@ -996,11 +1012,10 @@
 		return 0;
 	case _IO('F', 0xde):		/* 0x46de */
 		f_dprintk("test color display\n");
-		f_ddprintk("currcon: %d, bpp %d\n",
-			  currcon, fb_display[currcon].var.bits_per_pixel);
+		f_ddprintk("currcon: %d, bpp %d\n", sst_info->currcon,
+			  sst_info->current_par.bpp);
 		memset_io(sst_info->video.vbase, 0, sst_info->video.len);
-	switch (fb_display[currcon].var.bits_per_pixel) {
-/* FIXME broken : if we call this ioctl from a tty not bound to the fb, we use its depth and not the current one ... */
+	switch (sst_info->current_par.bpp) {
 	       	case 16:
 			sstfb_test16(sst_info);
 			break;
@@ -1012,7 +1027,7 @@
 #  endif
 		default:
 			dprintk("bug line %d: bad depth '%u'\n", __LINE__,
-			        fb_display[currcon].var.bits_per_pixel);
+			        sst_info->current_par.bpp);
 			}
 		return 0;
 	}
@@ -1028,9 +1043,9 @@
 
 /* get lfb size */
 
-static int sst_get_memsize(u_long *memsize)
+static int __devinit sst_get_memsize(struct sstfb_info *sst_info, u_long *memsize)
 {
-	u32 fbbase_virt = fb_info.video.vbase;
+	u_long fbbase_virt = sst_info->video.vbase;
 	f_dprintk("sst_get_memsize\n");
 
 	/* force memsize */
@@ -1073,13 +1088,13 @@
  * in a row a "idle" answer to our requests
  */
 
-static int sst_wait_idle(void)
+static int __sst_wait_idle(u_long vbase)
 {
 	int count = 0;
 
 	f_ddprintk("sst_wait_idle\n");
 	while(1) {
-		if (sst_read(STATUS) & STATUS_FBI_BUSY) {
+		if (__sst_read(vbase, STATUS) & STATUS_FBI_BUSY) {
 			f_dddprintk("status: busy\n");
 /* FIXME basicaly, this is a busy wait. maybe not that good. oh well; this is a small loop after all ...*/
 			count = 0;
@@ -1088,6 +1103,7 @@
 			f_dddprintk("status: idle(%d)\n", count);
 		}
 		if (count >= 5) return 1;
+//XXX  do something to avoid hanging the machine if the voodoo is out
 	}
 }
 
@@ -1097,25 +1113,25 @@
  * dram refresh disabled, FbiInit remaped.
  * TODO: mmh.. maybe i shoud put the "prerequisite" in the func ...
  */
-static int __init sst_detect_dactype(void)
+static int __devinit sst_detect_dactype(struct sstfb_info * sst_info)
 {
 	int ret=0,i;
 	f_dprintk("sst_detect_dactype\n");
 	for (i=0; i< sizeof(dacs)/sizeof(dacs[0]) ; i++) {
-		ret = dacs[i].detect();
+		ret = dacs[i].detect(sst_info);
 		if (ret) break;
 	}
 	if (!ret)
 		return 0;
 	f_dprintk("found %s\n", dacs[i].name);
-	fb_info.dac_sw=&dacs[i];
+	sst_info->dac_sw=dacs[i];
 	return 1;
 }
 
 /* fbi should be idle, and fifo emty and mem disabled */
 /* supposed to detect AT&T ATT20C409 and Ti TVP3409 ramdacs */
 
-static int __init (sst_detect_att(void))
+static int __devinit sst_detect_att(struct sstfb_info * sst_info)
 {
 	int i, mir, dir;
 
@@ -1140,7 +1156,7 @@
 	return 0;
 }
 
-static int __init (sst_detect_ti(void))
+static int __devinit sst_detect_ti(struct sstfb_info * sst_info)
 {
 	int i, mir, dir;
 
@@ -1176,7 +1192,7 @@
  * touched...
  * is it realy safe ? how can i reset this ramdac ? geee...
  */
-static int __init sst_detect_ics(void)
+static int __devinit sst_detect_ics(struct sstfb_info * sst_info)
 {
 	int i;
 	int m_clk0_1, m_clk0_7, m_clk1_b;
@@ -1262,7 +1278,7 @@
  * see detect_dac
  */
 
-static int sst_set_pll_att_ti(const struct pll_timing *t, const int clock)
+static int sst_set_pll_att_ti(struct sstfb_info * sst_info, const struct pll_timing *t, const int clock)
 {
 	u8 cr0, cc;
 	f_dprintk("sst_set_pll_att_ti\n");
@@ -1316,7 +1332,7 @@
 	return 1;
 }
 
-static int sst_set_pll_ics(const struct pll_timing *t, const int clock)
+static int sst_set_pll_ics(struct sstfb_info * sst_info, const struct pll_timing *t, const int clock)
 {
 	u8 pll_ctrl;
 
@@ -1356,11 +1372,9 @@
 
 static int sstfb_set_par(const struct sstfb_par * par, struct sstfb_info * sst_info)
 {
-	u32 lfbmode, fbiinit1, fbiinit2, fbiinit3, fbiinit6=0;
+	u32 lfbmode, fbiinit1, fbiinit2, fbiinit3, fbiinit5, fbiinit6=0;
 	int ntiles;
-	struct pll_timing pll;
-	int fout;
-	struct pci_dev  * sst_dev = sst_info->dev;
+	struct pci_dev * sst_dev = sst_info->dev;
 
 	f_dprintk("sst_set_par(%dx%d)\n", par->xDim, par->yDim);
 	f_ddprintk("hSyncOn hSyncOff vSyncOn vSyncOff\n");
@@ -1372,9 +1386,10 @@
 	           par->hBackPorch, par->vBackPorch,
 	           par->xDim, par->yDim, par->freq);
 
-
-	sst_calc_pll (par->freq, &fout, &pll);
-
+	if (!par->valid) {
+		BUG();
+		return -1;
+	}
 	sst_write(NOPCMD, 0);
 	sst_wait_idle();
 	pci_write_config_dword(sst_dev, PCI_INIT_ENABLE, PCI_EN_INIT_WR);
@@ -1385,22 +1400,11 @@
 
 	/*sst_unset_bits (FBIINIT0, FBI_RESET); / reenable FBI ? */
 
-	sst_write(BACKPORCH,       par->vBackPorch << 16 | (par->hBackPorch-2));
-	sst_write(VIDEODIMENSIONS, (par->yDim - 1) << 16 | (par->xDim - 1));
-	sst_write(HSYNC,         (par->hSyncOff-1) << 16 | (par->hSyncOn-1));
-	sst_write(VSYNC,             par->vSyncOff << 16 | par->vSyncOn);
-
-	/* Interlace or Doublescan */
-	if(par->flags & FB_VMODE_INTERLACED)
-		sst_set_bits(FBIINIT5,1>>26);
-	else
-		sst_unset_bits(FBIINIT5,1>>26);
-	
-	if(par->flags & FB_VMODE_DOUBLE)
-		sst_set_bits(FBIINIT5,1>>20);
-	else
-		sst_unset_bits(FBIINIT5,1>>20);
-	
+	sst_write(BACKPORCH, par->vBackPorch << 16 | (par->hBackPorch - 2));
+	sst_write(VIDEODIMENSIONS, par->yDim << 16 | (par->xDim - 1));
+	sst_write(HSYNC, (par->hSyncOff - 1) << 16 | (par->hSyncOn - 1));
+	sst_write(VSYNC,       par->vSyncOff << 16 | par->vSyncOn);
+
 	fbiinit2=sst_read(FBIINIT2);
 	fbiinit3=sst_read(FBIINIT3);
 
@@ -1408,12 +1412,15 @@
 	pci_write_config_dword(sst_dev, PCI_INIT_ENABLE,
 	                       PCI_EN_INIT_WR | PCI_REMAP_DAC );
 
-	sst_info->dac_sw->set_vidmod(par->bpp);
+	sst_info->dac_sw.set_vidmod(sst_info, par->bpp);
+
 	/* set video clock */
-	sst_info->dac_sw->set_pll(&pll, VID_CLOCK);
+	sst_info->dac_sw.set_pll(sst_info, &par->pll, VID_CLOCK);
+
 	/* disable fbiinit2/3 remap */
 	pci_write_config_dword(sst_dev, PCI_INIT_ENABLE,
 	                       PCI_EN_INIT_WR);
+
 	/* restore fbiinit2/3 */
 	sst_write(FBIINIT2,fbiinit2);
 	sst_write(FBIINIT3,fbiinit3);
@@ -1436,7 +1443,7 @@
 */
 
 	ntiles = par->tiles_in_X;
-	if (sst_info->is_voodoo2) {
+	if (IS_VOODOO2(sst_info)) {
 		fbiinit1 |= ((ntiles & 0x20) >> 5) << TILES_IN_X_MSB_SHIFT
 		            | ((ntiles & 0x1e) >> 1) << TILES_IN_X_SHIFT ;
 /* as the only value of importance for us in fbiinit6 is tiles in X (lsb),
@@ -1466,8 +1473,19 @@
 		break;
 	}
 	sst_write(FBIINIT1, fbiinit1);
-	if (sst_info->is_voodoo2)
+	if (IS_VOODOO2(sst_info)) {
 		sst_write(FBIINIT6, fbiinit6);
+		fbiinit5=sst_read(FBIINIT5) & FBIINIT5_MASK ;
+		if (par->vmode & FB_VMODE_INTERLACED)
+			fbiinit5 |= INTERLACE;
+		if (par->vmode & FB_VMODE_DOUBLE )
+			fbiinit5 |= VDOUBLESCAN;
+		if (par->sync & FB_SYNC_HOR_HIGH_ACT)
+			fbiinit5 |= HSYNC_HIGH;
+		if (par->sync & FB_SYNC_VERT_HIGH_ACT)
+			fbiinit5 |= VSYNC_HIGH;
+		sst_write(FBIINIT5, fbiinit5);
+	}
 	sst_wait_idle();
 	sst_unset_bits(FBIINIT1, VIDEO_RESET);
 	sst_unset_bits(FBIINIT0, FBI_RESET | FIFO_RESET);
@@ -1510,9 +1528,6 @@
 		f_ddprintk("setting clipping dimensions 0..%d, 0..%d\n",
 		            par->xDim-1, par->yDim-1);
 
-/* warning the fields are 9bits wide on voodoo1 , 11 (or 10) on voodoo2,
-   make sure we check the values before playing with the registers.. */
-
 		sst_write(CLIP_LEFT_RIGHT, par->xDim );
 		sst_write(CLIP_LOWY_HIGHY, par->yDim );
 		sst_set_bits(FBZMODE, EN_CLIPPING | EN_RGB_WRITE);
@@ -1525,7 +1540,7 @@
 	return 1;
 }
 
-static void sst_set_vidmod_att_ti(const int bpp)
+static void sst_set_vidmod_att_ti(struct sstfb_info * sst_info, const int bpp)
 {
 	u8 cr0;
 
@@ -1561,7 +1576,7 @@
 	}
 }
 
-static void sst_set_vidmod_ics(const int bpp)
+static void sst_set_vidmod_ics(struct sstfb_info * sst_info, const int bpp)
 {
 	f_dprintk("sst_set_vidmod_ics(bpp: %d)\n", bpp);
 	switch(bpp) {
@@ -1580,14 +1595,15 @@
 	}
 }
 
-static int __init sst_init(void)
+static int __devinit sst_init(struct sstfb_info *sst_info)
 {
 	struct pll_timing gfx_timings;
+	struct sst_spec * spec;
+	struct pci_dev * sst_dev = sst_info->dev;
 	int Fout;
-	int dac_ok;
 	u32 fbiinit0, fbiinit1, fbiinit4;
-	struct pci_dev * sst_dev = fb_info.dev; /* or define a macro ?*/
 
+	spec = &voodoo_spec[sst_info->type];
 	f_dprintk("sst_init\n");
 	f_ddprintk(" fbiinit0   fbiinit1   fbiinit2   fbiinit3   fbiinit4  "
 	           " fbiinit6\n");
@@ -1620,25 +1636,24 @@
 	pci_write_config_dword(sst_dev, PCI_INIT_ENABLE,
 	                               PCI_EN_INIT_WR | PCI_REMAP_DAC );
 	/* detect dac type */
-	dac_ok = sst_detect_dactype();
-	if (!dac_ok) {
+	if (!sst_detect_dactype(sst_info)) {
 		eprintk("Unknown dac type\n");
+		//FIXME watch it : we are not in a safe state , bad bad bad .
 		return 0;
 	}
 
 	/* set graphic clock */
-	if (dac_ok) {
-		fb_info.gfx_clock = fb_info.spec->default_gfx_clock;
-		if ((gfxclk >10 ) && (gfxclk < fb_info.spec->max_gfxclk)) {
-			iprintk ("Using supplied graphic freq : %dMHz\n", gfxclk);
-			 fb_info.gfx_clock = gfxclk *1000;
-		} else if (gfxclk) {
-			wprintk ("You fool, %dMhz is way out of spec! Using default\n", gfxclk);
-		}
-
-		sst_calc_pll(fb_info.gfx_clock, &Fout, &gfx_timings);
-		fb_info.dac_sw->set_pll(&gfx_timings, GFX_CLOCK);
+	sst_info->gfx_clock = spec->default_gfx_clock;
+	if ((gfxclk >10 ) && (gfxclk < spec->max_gfxclk)) {
+		iprintk ("Using supplied graphic freq : %dMHz\n", gfxclk);
+		 sst_info->gfx_clock = gfxclk *1000;
+	} else if (gfxclk) {
+		wprintk ("You fool, %dMhz is way out of spec! Using default\n", gfxclk);
 	}
+
+	sst_calc_pll(sst_info->gfx_clock, &Fout, &gfx_timings);
+	sst_info->dac_sw.set_pll(sst_info, &gfx_timings, GFX_CLOCK);
+
 	/* disable fbiinit remap */
 	pci_write_config_dword(sst_dev, PCI_INIT_ENABLE,
 	                       PCI_EN_INIT_WR| PCI_EN_FIFO_WR );
@@ -1668,7 +1683,7 @@
 	sst_wait_idle();
 	sst_write(FBIINIT4, fbiinit4);
 	sst_wait_idle();
-	if (fb_info.is_voodoo2) {
+	if (IS_VOODOO2(sst_info)) {
 		sst_write(FBIINIT6, FBIINIT6_DEFAULT);
 		sst_wait_idle();
 	}
@@ -1676,16 +1691,14 @@
 	pci_write_config_dword(sst_dev, PCI_INIT_ENABLE, PCI_EN_FIFO_WR );
 	pci_write_config_dword(sst_dev, PCI_VCLK_ENABLE, 0);
 
-	return dac_ok;
+	return 1;
 }
 
-#ifdef MODULE
-
-static void  __exit sst_shutdown(void)
+static void  __exit sst_shutdown(struct sstfb_info *sst_info)
 {
+	struct pci_dev * sst_dev = sst_info->dev;
 	struct pll_timing gfx_timings;
 	int Fout;
-	struct pci_dev * sst_dev = fb_info.dev;
 
 	f_dprintk("sst_shutdown\n");
 	/* reset video, gfx, fifo, disable dram + remap fbiinit2/3 */
@@ -1698,7 +1711,7 @@
 	                       PCI_EN_INIT_WR | PCI_REMAP_DAC );
 	/*set 20Mhz gfx clock */
 	sst_calc_pll(20000, &Fout, &gfx_timings);
-	fb_info.dac_sw->set_pll(&gfx_timings, GFX_CLOCK);
+	sst_info->dac_sw.set_pll(sst_info, &gfx_timings, GFX_CLOCK);
 	/* TODO maybe shutdown the dac, vrefresh and so on... */
 	pci_write_config_dword(sst_dev, PCI_INIT_ENABLE,
 	                       PCI_EN_INIT_WR);
@@ -1708,7 +1721,6 @@
 	pci_write_config_dword(sst_dev, PCI_INIT_ENABLE, 0);
 
 }
-#endif /* MODULE */
 
 /*
  * Interface to the world
@@ -1723,7 +1735,9 @@
 	if (!options || !*options)
 		return 0;
 
-	while ((this_opt = strsep(&options, ",")) != NULL) {
+	for(this_opt = strtok(options, ","); this_opt;
+		this_opt = strtok(NULL, ",")) { //XXX
+//XXX	while ((this_opt = strsep(&options, ",")) != NULL) {
 		if (!*this_opt) continue;
 
 		f_ddprintk("option %s\n", this_opt);
@@ -1756,116 +1770,173 @@
 	return 0;
 }
 
-int __init sstfb_init(void)
+int __devinit sstfb_init(void)
 {
-	struct pci_dev * pdev;
-	struct fb_var_screeninfo var;
-#define sst_dev	(fb_info.dev)
 	f_dprintk("sstfb_init\n");
 	dprintk("Compile date: "__DATE__" "__TIME__"\n");
+	return pci_module_init(&sstfb_driver);
+}
 
-	memset (&fb_info, 0, sizeof(fb_info));
-	pci_for_each_dev(pdev) {
-		if (pdev->vendor != PCI_VENDOR_ID_3DFX) continue;
-		if (pdev->device == PCI_DEVICE_ID_3DFX_VOODOO) {
-			fb_info.is_voodoo2=0;
-			fb_info.spec=&voodoo1_spec;
-		}
-		else if (pdev->device == PCI_DEVICE_ID_3DFX_VOODOO2) {
-			fb_info.is_voodoo2=1;
-			fb_info.spec=&voodoo2_spec;
-		}
-		else
-			continue;
-		if (dev > 0) {
-			dev--;
-			continue;
-		}
-		f_ddprintk("found device : %s\n", fb_info.spec->name);
-		fb_info.dev = pdev;
-		fb_info.mmio.base = sst_dev->resource[0].start;
-		pci_read_config_byte(sst_dev,
-		                     PCI_REVISION_ID, &fb_info.revision);
-
-		fb_info.mmio.vbase = (u32) ioremap_nocache(fb_info.mmio.base, 0x400000);
-		if (!fb_info.mmio.vbase) {
-			eprintk("cannot remap register area %#lx\n",
-			        fb_info.mmio.base);
-			return -ENXIO;
-		}
-		fb_info.video.base = fb_info.mmio.base+0x400000;
-		fb_info.video.vbase = (u32) ioremap_nocache(fb_info.video.base,
-					            0x400000);
-		if (!fb_info.video.vbase) {
-			eprintk("cannot remap framebuffer %#lx\n",
-			        fb_info.video.base);
-			iounmap((void*) fb_info.mmio.vbase);
-			return -ENXIO;
-		}
-		if(!sst_init()) {
-			eprintk("Init failed\n");
-			iounmap((void*)fb_info.mmio.vbase);
-			iounmap((void*)fb_info.video.vbase);
-			return -ENXIO;
-		}
-		sst_get_memsize(&fb_info.video.len);
-		fb_info.configured = 1;
-		strncpy(fb_info.info.modename, fb_info.spec->name, 16);
-
-		iprintk("%s with %s dac\n", fb_info.info.modename, fb_info.dac_sw->name);
-		iprintk("framebuffer at %#lx, mapped to %#lx,"
-		        " size %ldMb\n",
-		        fb_info.video.base, fb_info.video.vbase,
-		        fb_info.video.len >> 20);
-
-		f_ddprintk("revision: %d\n", fb_info.revision);
-		f_ddprintk("regbase_virt: %#lx\n", fb_info.mmio.vbase);
-		f_ddprintk("membase_phys: %#lx\n", fb_info.video.base);
-		f_ddprintk("fbbase_virt: %#lx\n", fb_info.video.vbase);
-
-		fb_info.info.node       = -1 ;
-		fb_info.info.flags      = FBINFO_FLAG_DEFAULT;
-		fb_info.info.fbops      = &sstfb_ops;
-		fb_info.info.disp       = &disp;
-		fb_info.info.changevar  = NULL;
-		fb_info.info.switch_con = &sstfbcon_switch;
-		fb_info.info.updatevar  = &sstfbcon_updatevar;
-		fb_info.info.blank      = &sstfbcon_blank;
-		if ( !mode_option &&
-	             !fb_find_mode(&var, &fb_info.info, mode_option,
-		                   NULL, 0, NULL, 16)) {
-			var = sstfb_default;
-		}
-		if (sstfb_set_var(&var, -1, &fb_info.info)) {
+void __devexit sstfb_exit(void)
+{
+	f_dprintk("sstfb_exit\n");
+	pci_unregister_driver(&sstfb_driver);
+}
+
+#ifdef MODULE
+module_init(sstfb_init);
+module_exit(sstfb_exit);
+#endif
+
+static int __devinit sstfb_probe(struct pci_dev *pdev, const struct pci_device_id *id)
+{
+	struct fb_var_screeninfo var;
+	struct sstfb_info * sst_info;
+	struct sst_spec * spec;
+	int tmp,err;
+	f_dprintk("sstfb_probe\n");
+
+	/* dev >  0  the device is not the one asked for.   skip */
+	/* dev == 0  this is the device the user asked.     init */
+	/* dev == -1 we already inited the asked device.    skip */
+	/* dev < -1  init all devices. including this one.  init */
+	if ((dev == -1 ) || (dev-- > 0))
+		return -1;
+
+	if ((err=pci_enable_device(pdev))) {
+		eprintk("cannot enable device\n");
+		return err;
+	}
+
+	sst_info = (struct sstfb_info*)kmalloc(sizeof(*sst_info), GFP_KERNEL);
+	if (!sst_info)
+		goto fail_kmalloc;
+	pci_set_drvdata(pdev, sst_info);
+	sst_info->type = id->driver_data;
+	spec = &voodoo_spec[sst_info->type];
+	f_ddprintk("found device : %s\n", spec->name);
+
+	sst_info->dev = pdev;
+	pci_read_config_byte(pdev, PCI_REVISION_ID, &sst_info->revision);
+
+	sst_info->mmio.base = pci_resource_start(pdev,0);
+	sst_info->video.base = sst_info->mmio.base+0x400000;
+
+	if (!request_mem_region(sst_info->mmio.base,0x400000,"sstfb MMIO")) {
+		eprintk ("cannot reserve mmio memory\n");
+		goto fail_mmio_mem;
+	}
+
+	if (!request_mem_region(sst_info->video.base,0x400000,"sstfb FB")) {
+		eprintk ("cannot reserve fb memory\n");
+		goto fail_fb_mem;
+	}
+
+	sst_info->mmio.vbase = (u_long) ioremap_nocache(sst_info->mmio.base, 0x400000);
+	if (!sst_info->mmio.vbase) {
+		eprintk("cannot remap register area %#lx\n",
+		        sst_info->mmio.base);
+		goto fail_mmio_remap;
+	}
+	sst_info->video.vbase = (u_long) ioremap_nocache(sst_info->video.base, 0x400000);
+	if (!sst_info->video.vbase) {
+		eprintk("cannot remap framebuffer %#lx\n",
+		        sst_info->video.base);
+		goto fail_fb_remap;
+	}
+
+	if(!sst_init(sst_info)) {
+		eprintk("Init failed\n");
+		goto fail;
+	}
+	sst_get_memsize(sst_info, &sst_info->video.len);
+	strncpy(sst_info->info.modename, spec->name, 16);
+
+	iprintk("%s with %s dac\n", sst_info->info.modename, sst_info->dac_sw.name);
+	iprintk("framebuffer at %#lx, mapped to %#lx,"
+	        " size %ldMb\n",
+	        sst_info->video.base, sst_info->video.vbase,
+	        sst_info->video.len >> 20);
+
+	f_ddprintk("revision: %d\n", sst_info->revision);
+	f_ddprintk("regbase_virt: %#lx\n", sst_info->mmio.vbase);
+	f_ddprintk("membase_phys: %#lx\n", sst_info->video.base);
+	f_ddprintk("fbbase_virt: %#lx\n", sst_info->video.vbase);
+
+	sst_info->info.node       = -1 ;
+	sst_info->info.flags      = FBINFO_FLAG_DEFAULT;
+	sst_info->info.fbops      = &sstfb_ops;
+	sst_info->info.disp       = &sst_info->disp;
+	sst_info->info.changevar  = NULL;
+	sst_info->info.switch_con = &sstfbcon_switch;
+	sst_info->info.updatevar  = &sstfbcon_updatevar;
+	sst_info->info.blank      = &sstfbcon_blank;
+
+	tmp=0;
+	var = sstfb_default;
+	if ( mode_option  &&
+	     fb_find_mode(&var, &sst_info->info, mode_option,
+	                   NULL, 0, NULL, 16)) {
+		if (sstfb_set_var(&var, -1, &sst_info->info)) {
 			eprintk("can't set supplied video mode. Using default\n");
 			var = sstfb_default;
-			if (sstfb_set_var(&var, -1, &fb_info.info)) {
-				eprintk("can't set default video mode.\n");
-				return -ENXIO;
-			}
-		}
-		/*clear fb */
-		memset_io(fb_info.video.vbase, 0, fb_info.video.len);
-		/* print some squares ... */
-		sstfb_test16(&fb_info); /* FIXME this is only for 16bpp */
-
-		/* register fb */
-		if (register_framebuffer(&fb_info.info) < 0) {
-			eprintk("can't register framebuffer.\n");
-			return -ENXIO;
+		} else {
+			/* set the new default */
+			sstfb_default = var;
+			tmp=1;  /* no need to set the mode. */
 		}
-		printk(KERN_INFO "fb%d: %s frame buffer device\n",
-		       GET_FB_IDX(fb_info.info.node),fb_info.info.modename);
+	}
 
-		num_sst++;
+	if (!tmp && sstfb_set_var(&var, -1, &sst_info->info)) {
+		eprintk("can't set default video mode.\n");
+		goto fail;
+	}
+	/*clear fb */
+	memset_io(sst_info->video.vbase, 0, sst_info->video.len);
+	/* print some squares ... */
+	sstfb_test16(sst_info); /* FIXME this is only for 16bpp */
 
-		if (dev <= 0)	/* we use the first card only for now (==0) */
-			return 0;
+	/* register fb */
+	if (register_framebuffer(&sst_info->info) < 0) {
+		eprintk("can't register framebuffer.\n");
+		goto fail;
 	}
+	printk(KERN_INFO "fb%d: %s frame buffer device\n",
+	       GET_FB_IDX(sst_info->info.node),sst_info->info.modename);
+
+	return 0;
+
+fail:
+	iounmap((void *)sst_info->video.base);
+fail_fb_remap:
+	iounmap((void *)sst_info->mmio.base);
+fail_mmio_remap:
+	release_mem_region(sst_info->video.base,0x400000);
+fail_fb_mem:
+	release_mem_region(sst_info->mmio.base,0x400000);
+fail_mmio_mem:
+	kfree(sst_info);
+fail_kmalloc:
 	return -ENXIO; 	/* no voodoo detected */
-#undef sst_dev
 }
 
+static void __devexit sstfb_remove(struct pci_dev *pdev)
+{
+	struct sstfb_info * sst_info;
+
+	f_dprintk("sstfb_remove\n");
+	sst_info=pci_get_drvdata(pdev);
+	sst_shutdown(sst_info);
+
+	unregister_framebuffer(&sst_info->info);
+	iounmap((void*)sst_info->video.vbase);
+	iounmap((void*)sst_info->mmio.vbase);
+	release_mem_region(sst_info->video.base,0x400000);
+	release_mem_region(sst_info->mmio.base,0x400000);
+	kfree(sst_info);
+}
+
+
 /*
  * console driver
  */
@@ -1875,15 +1946,15 @@
 	struct sstfb_par par;
 
 	f_dprintk("sstfbcon_switch(con: %d)\n",con);
-	f_ddprintk("currcon: %d\n", currcon);
-	v_dprintk("currcon: %d\n", currcon);
+	f_ddprintk("currcon: %d\n", sst_info->currcon);
+	v_dprintk("currcon: %d\n", sst_info->currcon);
 
-	if (currcon >=  0) {
-		if (fb_display[currcon].cmap.len)
-			fb_get_cmap(&fb_display[currcon].cmap, 1,
+	if (sst_info->currcon >=  0) {
+		if (fb_display[sst_info->currcon].cmap.len)
+			fb_get_cmap(&fb_display[sst_info->currcon].cmap, 1,
 			            sstfb_getcolreg, info);
 	}
-	currcon = con;
+	sst_info->currcon = con;
 	fb_display[con].var.activate = FB_ACTIVATE_NOW;
 
 	print_var(&fb_display[con].var, "&fb_display[con: %d].var",con);
@@ -1956,7 +2027,7 @@
 {
 	int i,j;
 	u_long p;
-	u32 fbbase_virt = sst_info->video.vbase;
+	u_long fbbase_virt = sst_info->video.vbase;
 
 	f_dprintk("sstfb_test32\n");
 	/* rect blanc 20x100+200+0 */
@@ -1994,31 +2065,7 @@
 }
 #endif /* EN_24_32_BPP */
 
-#ifdef MODULE
-
-int init_module(void)
-{
-	f_dprintk("init_module\n");
-	sstfb_init();
-	if (num_sst == 0 )
-		return -ENXIO;
-	return 0;
-}
-
-void cleanup_module(void)
-{
-	f_dprintk("cleanup_module\n");
-	f_ddprintk("conf %d\n",fb_info.configured);
-
-	if (fb_info.configured) {
-		sst_shutdown();
-		iounmap((void*)fb_info.mmio.vbase);
-		iounmap((void*)fb_info.video.vbase);
-		unregister_framebuffer(&fb_info.info);
-	}
-}
-
-MODULE_AUTHOR("(c) 2000,2001 Ghozlane Toumi <gtoumi@messel.emse.fr>");
+MODULE_AUTHOR("(c) 2000,2002 Ghozlane Toumi <gtoumi@laposte.net>");
 MODULE_DESCRIPTION("FBDev driver for 3dfx Voodoo Graphics and Voodoo2 based video boards");
 MODULE_LICENSE("GPL");
 
@@ -2036,7 +2083,6 @@
 MODULE_PARM_DESC(slowpci, "Uses slow PCI settings (0 or 1) (default=0)");
 MODULE_PARM(dev,"i");
 MODULE_PARM_DESC(dev , "Attach to device ID (0..n) (default=1st device)");
-#endif	/* MODULE */
 
 /*
  * Overrides for Emacs so that we follow Linus's tabbing style.
@@ -2047,12 +2093,12 @@
  */
 
 #if 0
-void Dump_regs ( void)
+void __Dump_regs (struct sstfb_info * sst_info)
 {
 	struct { u32 reg ; char * reg_name;}  pci_regs [] =  {
 		{ PCI_INIT_ENABLE, "initenable"},
-		{ PCI_VCLK_ENABLE, "enable vclk"}, 
-		{ PCI_VCLK_DISABLE, "disable vclk"}, 
+		{ PCI_VCLK_ENABLE, "enable vclk"},
+		{ PCI_VCLK_DISABLE, "disable vclk"},
 	};
 
 	struct { u32 reg ; char * reg_name;}  sst_regs [] =  {
@@ -2067,25 +2113,27 @@
 		{LFBMODE,"lfbmode"},
 		{FBZMODE,"fbzmode"},
 	};
-	u32 pci_res[sizeof(pci_regs)/sizeof(pci_regs[0])];
-	u32 sst_res[sizeof(sst_regs)/sizeof(sst_regs[0])];
+	int pci_s = sizeof(pci_regs)/sizeof(*pci_regs);
+	int sst_s = sizeof(sst_regs)/sizeof(*sst_regs);
+	u32 pci_res[pci_s];
+	u32 sst_res[sst_s];
 
-	struct pci_dev * dev = fb_info.dev;
+	struct pci_dev * dev = sst_info->dev;
 
 	int i;
 
-	for (i=0; i<(sizeof(pci_regs)/sizeof(pci_regs[0])) ; i++ ) {
+	for (i=0; i < pci_s ; i++ ) {
 		pci_read_config_dword ( dev, pci_regs[i].reg , &pci_res[i]) ;
 	}
-	for (i=0; i<(sizeof(sst_regs)/sizeof(sst_regs[0])) ; i++ ) {
+	for (i=0; i < sst_s ; i++ ) {
 		sst_res[i]=sst_read(sst_regs[i].reg);
 	}
 
 	dprintk ("Dump regs\n");
-	for (i=0; i<(sizeof(pci_regs)/sizeof(pci_regs[0])) ; i++ ) {
+	for (i=0; i < pci_s ; i++ ) {
 		dprintk("%s = %0#10x\n", pci_regs[i].reg_name , pci_res[i]) ;
 	}
-	for (i=0; i<(sizeof(sst_regs)/sizeof(sst_regs[0])) ; i++ ) {
+	for (i=0; i < sst_s ; i++ ) {
 		dprintk("%s = %0#10x\n", sst_regs[i].reg_name , sst_res[i]) ;
 	}
 }
diff -urN linux-2.4.19-pre9/drivers/video/sstfb.h linux-2.4.19-pre10/drivers/video/sstfb.h
--- linux-2.4.19-pre9/drivers/video/sstfb.h	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/drivers/video/sstfb.h	Mon Jun  3 18:50:56 2002
@@ -11,7 +11,7 @@
 
 #ifndef _SSTFB_H_
 #define _SSTFB_H_
- 
+
 /*
  *
  *  Debug Stuff
@@ -72,9 +72,10 @@
 #define iprintk(X...)	printk(KERN_INFO "sstfb: " X)
 #define wprintk(X...)	printk(KERN_WARNING "sstfb: " X)
 
-#define BIT(x)		(1ul << (x))
+#define BIT(x)		(1ul<<(x))
 #define PS2KHZ(a)	(1000000000UL/(a))	/* picoseconds to KHz */
 #define KHZ2PS(a)	(1000000000UL/(a))
+#define POW2(x)		(1ul<<(x))
 
 #ifndef ABS
 # define ABS(x)		(((x)<0)?-(x):(x))
@@ -170,9 +171,15 @@
 #define DAC_DATA		0x022c
 #  define DAC_READ_CMD		  BIT(11)	/* set read dacreg mode */
 #define FBIINIT5		0x0244		/* v2 specific */
+#  define FBIINIT5_MASK		  0xfa40ffff    /* mask video bits*/
+#  define HDOUBLESCAN		  BIT(20)
+#  define VDOUBLESCAN		  BIT(21)
+#  define HSYNC_HIGH 		  BIT(23)
+#  define VSYNC_HIGH 		  BIT(24)
+#  define INTERLACE		  BIT(26)
 #define FBIINIT6		0x0248		/* v2 specific */
-#define FBIINIT7		0x024c		/* v2 specific */
 #  define TILES_IN_X_LSB_SHIFT	  30		/* v2 */
+#define FBIINIT7		0x024c		/* v2 specific */
 
 /* Dac Registers */
 #define DACREG_WMA		0x0	/* pixel write mode address */
@@ -275,30 +282,32 @@
  */
 
 /* used to know witch clock to set */
-#define VID_CLOCK	0
-#define GFX_CLOCK	1
+enum {
+	VID_CLOCK=0,
+	GFX_CLOCK=1,
+};
 
 /* freq max */
 #define DAC_FREF	14318	/* DAC reference freq (Khz) */
 #define VCO_MAX		260000
 
 /*
- *
- *  Declarations
- *
+ *  driver structs
  */
 
 struct pll_timing {
-	u8 m;
-	u8 n;
-	u8 p;
+	unsigned int m;
+	unsigned int n;
+	unsigned int p;
 };
 
+struct sstfb_info;
+
 struct dac_switch {
 	char * name;
-	int (*detect) (void);
-	int (*set_pll) (const struct pll_timing *t, const int clock);
-	void (*set_vidmod) (const int bpp);
+	int (*detect) (struct sstfb_info *sst_info);
+	int (*set_pll) (struct sstfb_info *sst_info, const struct pll_timing *t, const int clock);
+	void (*set_vidmod) (struct sstfb_info *sst_info, const int bpp);
 };
 
 struct sst_spec {
@@ -317,9 +326,12 @@
 	unsigned int vSyncOn;
 	unsigned int vSyncOff;
 	unsigned int vBackPorch;
-	unsigned int flags;	/* Doublescan, Interlace etc. */
-	unsigned int freq;	/* freq in picoseconds */
-	unsigned int tiles_in_X; /* num of tiles in X res */
+	unsigned int freq;	/* freq in kHz */
+	struct pll_timing pll;
+	unsigned int tiles_in_X;/* num of tiles in X res */
+	unsigned int vmode;     /* doublescan/interlaced */
+	unsigned int sync;      /* H/V sync polarity */
+	unsigned int valid;	/* par is correct (fool proof) */
 };
 
 struct sstfb_info {
@@ -337,18 +349,34 @@
 		unsigned long	vbase;
 	} mmio;				/* registers memory info */
 
-	struct dac_switch *	dac_sw;	/* dac specific functions */
-	struct sst_spec *	spec;
+	struct dac_switch 	dac_sw;	/* dac specific functions */
 
-	int	is_voodoo2;
+	int	type;
 	u8	revision;
 
 	/* status */
-	int	configured;
-/*	int	indexed_mode;
+/*XXX	int	configured;
+	int	indexed_mode;
 	int	vgapass;
 	int	clipping; */
 	int	gfx_clock;
+
+	int	currcon;
+	struct display  	disp; /* current display */
+	struct { u_int red, green, blue, transp; } palette[16];
+
+	union {
+#ifdef FBCON_HAS_CFB16
+		u16 cfb16[16];
+#endif
+#ifdef EN_24_32_BPP
+#if defined (FBCON_HAS_CFB24) || defined(FBCON_HAS_CFB32)
+		u32 cfb32[16];
+#endif
+#endif
+	} fbcon_cmap;
+
 };
 
+
 #endif /* _SSTFB_H_ */
diff -urN linux-2.4.19-pre9/fs/binfmt_misc.c linux-2.4.19-pre10/fs/binfmt_misc.c
--- linux-2.4.19-pre9/fs/binfmt_misc.c	Sat Oct 20 19:14:42 2001
+++ linux-2.4.19-pre10/fs/binfmt_misc.c	Mon Jun  3 18:50:56 2002
@@ -38,7 +38,7 @@
 
 typedef struct {
 	struct list_head list;
-	int flags;			/* type, status, etc. */
+	unsigned long flags;		/* type, status, etc. */
 	int offset;			/* offset of magic */
 	int size;			/* size of magic/mask */
 	char *magic;			/* magic or filename extension */
diff -urN linux-2.4.19-pre9/fs/coda/cnode.c linux-2.4.19-pre10/fs/coda/cnode.c
--- linux-2.4.19-pre9/fs/coda/cnode.c	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/fs/coda/cnode.c	Mon Jun  3 18:50:56 2002
@@ -57,6 +57,7 @@
         } else if (S_ISLNK(inode->i_mode)) {
 		inode->i_op = &coda_symlink_inode_operations;
 		inode->i_data.a_ops = &coda_symlink_aops;
+		inode->i_mapping = &inode->i_data;
 	} else
                 init_special_inode(inode, inode->i_mode, attr->va_rdev);
 }
@@ -67,11 +68,14 @@
 	struct inode *inode;
 	struct coda_inode_info *cii;
 	ino_t ino = coda_f2i(fid);
+	struct coda_sb_info *sbi = coda_sbp(sb);
 
+	down(&sbi->sbi_iget4_mutex);
 	inode = iget4(sb, ino, coda_inocmp, fid);
 
 	if ( !inode ) { 
 		CDEBUG(D_CNODE, "coda_iget: no inode\n");
+		up(&sbi->sbi_iget4_mutex);
 		return ERR_PTR(-ENOMEM);
 	}
 
@@ -80,6 +84,7 @@
 	if (coda_isnullfid(&cii->c_fid))
 		/* new, empty inode found... initializing */
 		cii->c_fid = *fid;
+	up(&sbi->sbi_iget4_mutex);
 
 	/* always replace the attributes, type might have changed */
 	coda_fill_inode(inode, attr);
@@ -144,6 +149,7 @@
 	ino_t nr;
 	struct inode *inode;
 	struct coda_inode_info *cii;
+	struct coda_sb_info *sbi;
 
 	if ( !sb ) {
 		printk("coda_fid_to_inode: no sb!\n");
@@ -152,12 +158,14 @@
 
 	CDEBUG(D_INODE, "%s\n", coda_f2s(fid));
 
+	sbi = coda_sbp(sb);
 	nr = coda_f2i(fid);
+	down(&sbi->sbi_iget4_mutex);
 	inode = iget4(sb, nr, coda_inocmp, fid);
 	if ( !inode ) {
 		printk("coda_fid_to_inode: null from iget, sb %p, nr %ld.\n",
 		       sb, (long)nr);
-		return NULL;
+		goto out_unlock;
 	}
 
 	cii = ITOC(inode);
@@ -166,11 +174,16 @@
 	if (coda_isnullfid(&cii->c_fid)) {
 		inode->i_nlink = 0;
 		iput(inode);
-		return NULL;
+		goto out_unlock;
 	}
 
         CDEBUG(D_INODE, "found %ld\n", inode->i_ino);
+	up(&sbi->sbi_iget4_mutex);
 	return inode;
+
+out_unlock:
+	up(&sbi->sbi_iget4_mutex);
+	return NULL;
 }
 
 /* the CONTROL inode is made without asking attributes from Venus */
diff -urN linux-2.4.19-pre9/fs/coda/file.c linux-2.4.19-pre10/fs/coda/file.c
--- linux-2.4.19-pre9/fs/coda/file.c	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/fs/coda/file.c	Mon Jun  3 18:50:56 2002
@@ -76,7 +76,9 @@
 coda_file_mmap(struct file *coda_file, struct vm_area_struct *vma)
 {
 	struct coda_file_info *cfi;
+	struct coda_inode_info *cii;
 	struct file *host_file;
+	struct inode *coda_inode, *host_inode;
 
 	cfi = CODA_FTOC(coda_file);
 	if (!cfi || cfi->cfi_magic != CODA_MAGIC) BUG();
@@ -85,6 +87,21 @@
 	if (!host_file->f_op || !host_file->f_op->mmap)
 		return -ENODEV;
 
+	coda_inode = coda_file->f_dentry->d_inode;
+	host_inode = host_file->f_dentry->d_inode;
+	if (coda_inode->i_mapping == &coda_inode->i_data)
+		coda_inode->i_mapping = host_inode->i_mapping;
+
+	/* only allow additional mmaps as long as userspace isn't changing
+	 * the container file on us! */
+	else if (coda_inode->i_mapping != host_inode->i_mapping)
+		return -EBUSY;
+
+	/* keep track of how often the coda_inode/host_file has been mmapped */
+	cii = ITOC(coda_inode);
+	cii->c_mapcount++;
+	cfi->cfi_mapcount++;
+ 
 	return host_file->f_op->mmap(host_file, vma);
 }
 
@@ -118,6 +135,7 @@
 	host_file->f_flags |= coda_file->f_flags & (O_APPEND | O_SYNC);
 
 	cfi->cfi_magic = CODA_MAGIC;
+	cfi->cfi_mapcount = 0;
 	cfi->cfi_container = host_file;
 	coda_load_creds(&cfi->cfi_cred);
 
@@ -182,6 +200,8 @@
 	unsigned short flags = (coda_file->f_flags) & (~O_EXCL);
 	unsigned short coda_flags = coda_flags_to_cflags(flags);
 	struct coda_file_info *cfi;
+	struct coda_inode_info *cii;
+	struct inode *host_inode;
 	int err = 0;
 
 	lock_kernel();
@@ -203,6 +223,16 @@
 		err = venus_close(coda_inode->i_sb, coda_i2f(coda_inode),
 				  coda_flags, &cfi->cfi_cred);
 
+	host_inode = cfi->cfi_container->f_dentry->d_inode;
+	cii = ITOC(coda_inode);
+
+	/* did we mmap this file? */
+	if (coda_inode->i_mapping == &host_inode->i_data) {
+		cii->c_mapcount -= cfi->cfi_mapcount;
+		if (!cii->c_mapcount)
+			coda_inode->i_mapping = &coda_inode->i_data;
+	}
+
 	coda_inode->i_mapping = &coda_inode->i_data;
 	fput(cfi->cfi_container);
 
diff -urN linux-2.4.19-pre9/fs/coda/inode.c linux-2.4.19-pre10/fs/coda/inode.c
--- linux-2.4.19-pre9/fs/coda/inode.c	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/fs/coda/inode.c	Mon Jun  3 18:50:56 2002
@@ -128,6 +128,7 @@
 	sbi->sbi_sb = sb;
 	sbi->sbi_vcomm = vc;
 	INIT_LIST_HEAD(&sbi->sbi_cihead);
+	init_MUTEX(&sbi->sbi_iget4_mutex);
 
         sb->u.generic_sbp = sbi;
         sb->s_blocksize = 1024;	/* XXXXX  what do we put here?? */
@@ -194,6 +195,7 @@
             return;
         }
 
+	cii->c_mapcount = 0;
 	list_add(&cii->c_cilist, &sbi->sbi_cihead);
 }
 
diff -urN linux-2.4.19-pre9/fs/dcache.c linux-2.4.19-pre10/fs/dcache.c
--- linux-2.4.19-pre9/fs/dcache.c	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/fs/dcache.c	Mon Jun  3 18:50:56 2002
@@ -67,7 +67,7 @@
 }
 
 /*
- * Release the dentry's inode, using the fileystem
+ * Release the dentry's inode, using the filesystem
  * d_iput() operation if defined.
  * Called with dcache_lock held, drops it.
  */
diff -urN linux-2.4.19-pre9/fs/intermezzo/ext_attr.c linux-2.4.19-pre10/fs/intermezzo/ext_attr.c
--- linux-2.4.19-pre9/fs/intermezzo/ext_attr.c	Sun Nov 11 10:20:21 2001
+++ linux-2.4.19-pre10/fs/intermezzo/ext_attr.c	Mon Jun  3 18:50:56 2002
@@ -106,9 +106,8 @@
                         printk("InterMezzo: out of memory!!!\n");
                         return -ENOMEM;
                 }
-                error = copy_from_user(buf, buffer, buffer_len);
-                if (error) 
-                        return error;
+                if (copy_from_user(buf, buffer, buffer_len))
+                        return -EFAULT;
             } else 
                 buf = buffer;
         } else
diff -urN linux-2.4.19-pre9/fs/intermezzo/kml.c linux-2.4.19-pre10/fs/intermezzo/kml.c
--- linux-2.4.19-pre9/fs/intermezzo/kml.c	Sun Nov 11 10:20:21 2001
+++ linux-2.4.19-pre10/fs/intermezzo/kml.c	Mon Jun  3 18:50:56 2002
@@ -31,10 +31,9 @@
 
         ENTRY;
         /* allocate buffer & copy it to kernel space */
-        error = copy_from_user(&input, (char *)arg, sizeof(input));
-        if ( error ) {
+        if (copy_from_user(&input, (char *)arg, sizeof(input))) {
                 EXIT;
-                return error;
+                return -EFAULT;
         }
 
         if (input.reclen > kml_fsdata->kml_maxsize)
@@ -45,11 +44,10 @@
                 EXIT;
                 return -ENOMEM;
         }
-        error = copy_from_user(path, input.volname, input.namelen);
-        if ( error ) {
+        if (copy_from_user(path, input.volname, input.namelen)) {
                 PRESTO_FREE(path, input.namelen + 1);
                 EXIT;
-                return error;
+                return -EFAULT;
         }
         path[input.namelen] = '\0';
         fset = kml_getfset (path);
@@ -57,10 +55,9 @@
 
         kml_fsdata = FSET_GET_KMLDATA(fset);
         /* read the buf from user memory here */
-        error = copy_from_user(kml_fsdata->kml_buf, input.recbuf, input.reclen);
-        if ( error ) {
+        if (copy_from_user(kml_fsdata->kml_buf, input.recbuf, input.reclen)) {
                 EXIT;
-                return error;
+                return -EFAULT;
         }
         kml_fsdata->kml_len = input.reclen;
 
@@ -94,21 +91,19 @@
         struct presto_file_set *fset;
 
         ENTRY;
-        error = copy_from_user(&input, (char *)arg, sizeof(input));
-        if ( error ) {
+        if (copy_from_user(&input, (char *)arg, sizeof(input))) {
                 EXIT;
-                return error;
+                return -EFAULT;
         }
         PRESTO_ALLOC(path, char *, input.namelen + 1);
         if ( !path ) {
                 EXIT;
                 return -ENOMEM;
         }
-        error = copy_from_user(path, input.volname, input.namelen);
-        if ( error ) {
+        if (copy_from_user(path, input.volname, input.namelen)) {
                 PRESTO_FREE(path, input.namelen + 1);
                 EXIT;
-                return error;
+                return -EFAULT;
         }
         path[input.namelen] = '\0';
         fset = kml_getfset (path);
@@ -138,7 +133,8 @@
                                 strlen (close->path) + 1, input.pathlen);
                         error = -ENOMEM;
                 }
-                copy_to_user((char *)arg, &input, sizeof (input));
+                if (copy_to_user((char *)arg, &input, sizeof (input)))
+			return -EFAULT;
         }
         return error;
 }
@@ -161,10 +157,9 @@
         char *path;
 
         ENTRY;
-        error = copy_from_user(&input, (char *)arg, sizeof(input));
-        if ( error ) {
+        if (copy_from_user(&input, (char *)arg, sizeof(input))) { 
                EXIT;
-               return error;
+               return -EFAULT;
         }
 
         PRESTO_ALLOC(path, char *, input.namelen + 1);
@@ -172,11 +167,11 @@
                 EXIT;
                 return -ENOMEM;
         }
-        error = copy_from_user(path, input.volname, input.namelen);
+        if (copy_from_user(path, input.volname, input.namelen)) {
         if ( error ) {
                 PRESTO_FREE(path, input.namelen + 1);
                 EXIT;
-                return error;
+                return -EFAULT;
         }
         path[input.namelen] = '\0';
         fset = kml_getfset (path);
@@ -193,7 +188,8 @@
 #if 0
         input.newpos = kml_upc->newpos;
         input.count = kml_upc->count;
-        copy_to_user((char *)arg, &input, sizeof (input));
+        if (copy_to_user((char *)arg, &input, sizeof (input)))
+		return -EFAULT;
 #endif
         return error;
 }
diff -urN linux-2.4.19-pre9/fs/intermezzo/psdev.c linux-2.4.19-pre10/fs/intermezzo/psdev.c
--- linux-2.4.19-pre9/fs/intermezzo/psdev.c	Mon Jun  3 18:50:49 2002
+++ linux-2.4.19-pre10/fs/intermezzo/psdev.c	Mon Jun  3 18:50:56 2002
@@ -134,7 +134,6 @@
         struct upc_req *tmp;
         struct list_head *lh;
         struct lento_down_hdr hdr;
-        int error;
 
         if ( ! (upccom = presto_psdev_f2u(file)) ) {
                 kdev_t dev = file->f_dentry->d_inode->i_rdev;
@@ -148,9 +147,8 @@
                 return -EINVAL;
         }
 
-        error = copy_from_user(&hdr, buf, sizeof(hdr));
-        if ( error )
-                return error;
+        if (copy_from_user(&hdr, buf, sizeof(hdr)))
+                return -EFAULT;
 
         CDEBUG(D_PSDEV, "(process,opc,uniq)=(%d,%d,%d)\n",
                current->pid, hdr.opcode, hdr.unique);
@@ -182,9 +180,8 @@
                        req->rq_bufsize, count, hdr.opcode, hdr.unique);
                 count = req->rq_bufsize; /* don't have more space! */
         }
-        error = copy_from_user(req->rq_data, buf, count);
-        if ( error )
-                return error;
+        if (copy_from_user(req->rq_data, buf, count))
+                return -EFAULT;
 
         /* adjust outsize: good upcalls can be aware of this */
         req->rq_rep_size = count;
@@ -277,16 +274,12 @@
                 struct readmount readmount;
                 struct readmount *user_readmount = (struct readmount *) arg;
                 char * tmp;
-                int error;
+                int error = 0;
 
-                error = copy_from_user(&readmount, (void *)arg,
-                                       sizeof(readmount));
-                if ( error )  {
-                        printk("psdev: can't copy %Zd bytes from %p to %p\n",
-                                sizeof(readmount), (struct readmount *) arg,
-                                &readmount);
+                if (copy_from_user(&readmount, (void *)arg, sizeof(readmount)))
+                {
                         EXIT;
-                        return error;
+                        return -EFAULT;
                 }
 
                 len = readmount.io_len;
@@ -306,15 +299,16 @@
                  * I mean, let's let the compiler do a little work ...
                  * gcc suggested the extra ()
                  */
-                error = copy_to_user(readmount.io_string, tmp, outlen);
-                if ( error ) {
+                if (copy_to_user(readmount.io_string, tmp, outlen)) {
                         CDEBUG(D_PSDEV, "Copy_to_user string 0x%p failed\n",
                                readmount.io_string);
+			error = -EFAULT;
                 }
-                if ((!error) && (error = copy_to_user(&(user_readmount->io_len),
-                                                      &outlen, sizeof(int))) ) {
+                if (!error && copy_to_user(&(user_readmount->io_len),
+                                           &outlen, sizeof(int))) {
                         CDEBUG(D_PSDEV, "Copy_to_user len @0x%p failed\n",
                                &(user_readmount->io_len));
+			error = -EFAULT;
                 }
 
                 PRESTO_FREE(tmp, len);
@@ -359,10 +353,9 @@
                         int   path_len;
                 } input;
 
-                error = copy_from_user(&input, (char *)arg, sizeof(input));
-                if ( error ) {
+                if (copy_from_user(&input, (char *)arg, sizeof(input))) {
                         EXIT;
-                        return error;
+                        return -EFAULT;
                 }
 
                 PRESTO_ALLOC(path, char *, input.path_len + 1);
@@ -370,11 +363,10 @@
                         EXIT;
                         return -ENOMEM;
                 }
-                error = copy_from_user(path, input.path, input.path_len);
-                if ( error ) {
+                if (copy_from_user(path, input.path, input.path_len)) {
                         PRESTO_FREE(path, input.path_len + 1);
                         EXIT;
-                        return error;
+                        return -EFAULT;
                 }
                 path[input.path_len] = '\0';
                 CDEBUG(D_PSDEV, "clear_fsetroot: path %s\n", path);
@@ -400,10 +392,9 @@
                         int   path_len;
                 } input;
 
-                error = copy_from_user(&input, (char *)arg, sizeof(input));
-                if ( error ) {
+                if (copy_from_user(&input, (char *)arg, sizeof(input))) {
                         EXIT;
-                        return error;
+                        return -EFAULT;
                 }
 
                 PRESTO_ALLOC(path, char *, input.path_len + 1);
@@ -411,11 +402,10 @@
                         EXIT;
                         return -ENOMEM;
                 }
-                error = copy_from_user(path, input.path, input.path_len);
-                if ( error ) {
+                if (copy_from_user(path, input.path, input.path_len)) {
                         PRESTO_FREE(path, input.path_len + 1);
                         EXIT;
-                        return error;
+                        return -EFAULT;
                 }
                 path[input.path_len] = '\0';
                 CDEBUG(D_PSDEV, "clear_all_fsetroot: path %s\n", path);
@@ -439,10 +429,9 @@
                         int   path_len;
                 } input;
 
-                error = copy_from_user(&input, (char *)arg, sizeof(input));
-                if ( error ) {
+                if (copy_from_user(&input, (char *)arg, sizeof(input))) {
                         EXIT;
-                        return error;
+                        return -EFAULT;
                 }
 
                 PRESTO_ALLOC(path, char *, input.path_len + 1);
@@ -450,11 +439,10 @@
                         EXIT;
                         return -ENOMEM;
                 }
-                error = copy_from_user(path, input.path, input.path_len);
-                if ( error ) {
+                if (copy_from_user(path, input.path, input.path_len)) {
                         PRESTO_FREE(path, input.path_len + 1);
                         EXIT;
-                        return error;
+                        return -EFAULT;
                 }
                 path[input.path_len] = '\0';
                 CDEBUG(D_PSDEV, "get_kmlsize: len %d path %s\n", 
@@ -473,7 +461,9 @@
                 CDEBUG(D_PSDEV, "get_kmlsize: size = %Zd\n", size);
 
                 EXIT;
-                return copy_to_user((char *)arg, &input, sizeof(input));
+                if (copy_to_user((char *)arg, &input, sizeof(input)))
+			return -EFAULT;
+		return 0;
         }
 
         case PRESTO_GET_RECNO: {
@@ -487,10 +477,9 @@
                         int   path_len;
                 } input;
 
-                error = copy_from_user(&input, (char *)arg, sizeof(input));
-                if ( error ) {
+                if (copy_from_user(&input, (char *)arg, sizeof(input))) {
                         EXIT;
-                        return error;
+                        return -EFAULT;
                 }
 
                 PRESTO_ALLOC(path, char *, input.path_len + 1);
@@ -498,11 +487,10 @@
                         EXIT;
                         return -ENOMEM;
                 }
-                error = copy_from_user(path, input.path, input.path_len);
-                if ( error ) {
+                if (copy_from_user(path, input.path, input.path_len)) {
                         PRESTO_FREE(path, input.path_len + 1);
                         EXIT;
-                        return error;
+                        return -EFAULT;
                 }
                 path[input.path_len] = '\0';
                 CDEBUG(D_PSDEV, "get_recno: len %d path %s\n", 
@@ -521,7 +509,9 @@
                 CDEBUG(D_PSDEV, "get_recno: recno = %d\n", (int) recno);
 
                 EXIT;
-                return copy_to_user((char *)arg, &input, sizeof(input));
+                if (copy_to_user((char *)arg, &input, sizeof(input)))
+			return -EFAULT;
+		return 0;
         }
 
         case PRESTO_SET_FSETROOT: {
@@ -542,10 +532,9 @@
                         int   flags;
                 } input;
 
-                error = copy_from_user(&input, (char *)arg, sizeof(input));
-                if ( error ) {
+                if (copy_from_user(&input, (char *)arg, sizeof(input))) {
                         EXIT;
-                        return error;
+                        return -EFAULT;
                 }
 
                 PRESTO_ALLOC(path, char *, input.path_len + 1);
@@ -553,9 +542,9 @@
                         EXIT;
                         return -ENOMEM;
                 }
-                error = copy_from_user(path, input.path, input.path_len);
-                if ( error ) {
+                if (copy_from_user(path, input.path, input.path_len)) {
                         EXIT;
+			error = -EFAULT;
                         goto exit_free_path;
                 }
                 path[input.path_len] = '\0';
@@ -566,9 +555,9 @@
                         EXIT;
                         goto exit_free_path;
                 }
-                error = copy_from_user(fsetname, input.name, input.name_len);
-                if ( error ) {
+                if (copy_from_user(fsetname, input.name, input.name_len)) {
                         EXIT;
+			error = -EFAULT;
                         goto exit_free_fsetname;
                 }
                 fsetname[input.name_len] = '\0';
@@ -617,15 +606,14 @@
                 int dogetopt(int, struct psdev_opt *);
                 int minor = 0;
                 struct psdev_opt kopt;
+                int error = 0;
                 struct psdev_opt *user_opt = (struct psdev_opt *) arg;
-                int error;
 
-                error = copy_from_user(&kopt, (void *)arg, sizeof(kopt));
-                if ( error )  {
+                if (copy_from_user(&kopt, (void *)arg, sizeof(kopt))) {
                         printk("psdev: can't copyin %Zd bytes from %p to %p\n",
                                sizeof(kopt), (struct kopt *) arg, &kopt);
                         EXIT;
-                        return error;
+                        return -EFAULT;
                 }
                 minor = MINOR(dev);
                 if (cmd == PRESTO_SETOPT)
@@ -649,12 +637,11 @@
                         return error;
                 }
 
-                error = copy_to_user(user_opt, &kopt, sizeof(kopt));
-                if ( error ) {
+                if (copy_to_user(user_opt, &kopt, sizeof(kopt))) {
                         CDEBUG(D_PSDEV, "Copy_to_user opt 0x%p failed\n",
                                user_opt);
                         EXIT;
-                        return error;
+                        return -EFAULT;
                 }
                 CDEBUG(D_PSDEV, "dosetopt minor %d, opt %d, val %d return %d\n",
                          minor, kopt.optname, kopt.optval, error);
@@ -667,10 +654,9 @@
                 struct lento_input_attr input;
                 struct iattr iattr;
 
-                error = copy_from_user(&input, (char *)arg, sizeof(input));
-                if ( error ) {
+                if (copy_from_user(&input, (char *)arg, sizeof(input))) {
                         EXIT;
-                        return error;
+                        return -EFAULT;
                 }
                 iattr.ia_valid = input.valid;
                 iattr.ia_mode  = (umode_t)input.mode;
@@ -691,10 +677,9 @@
                 int error;
                 struct lento_input_mode input;
 
-                error = copy_from_user(&input, (char *)arg, sizeof(input));
-                if ( error ) {
+                if (copy_from_user(&input, (char *)arg, sizeof(input))) {
                         EXIT;
-                        return error;
+                        return -EFAULT;
                 }
 
                 error = lento_create(input.name, input.mode, &input.info);
@@ -706,10 +691,9 @@
                 int error;
                 struct lento_input_old_new input;
 
-                error = copy_from_user(&input, (char *)arg, sizeof(input));
-                if ( error ) {
+                if (copy_from_user(&input, (char *)arg, sizeof(input))) {
                         EXIT;
-                        return error;
+                        return -EFAULT;
                 }
 
                 error = lento_link(input.oldname, input.newname, &input.info);
@@ -721,10 +705,9 @@
                 int error;
                 struct lento_input input;
 
-                error = copy_from_user(&input, (char *)arg, sizeof(input));
-                if ( error ) {
+                if (copy_from_user(&input, (char *)arg, sizeof(input))) {
                         EXIT;
-                        return error;
+                        return -EFAULT;
                 }
 
                 error = lento_unlink(input.name, &input.info);
@@ -736,10 +719,9 @@
                 int error;
                 struct lento_input_old_new input;
 
-                error = copy_from_user(&input, (char *)arg, sizeof(input));
-                if ( error ) {
+                if (copy_from_user(&input, (char *)arg, sizeof(input))) {
                         EXIT;
-                        return error;
+                        return -EFAULT;
                 }
 
                 error = lento_symlink(input.oldname, input.newname,&input.info);
@@ -751,10 +733,9 @@
                 int error;
                 struct lento_input_mode input;
 
-                error = copy_from_user(&input, (char *)arg, sizeof(input));
-                if ( error ) {
+                if (copy_from_user(&input, (char *)arg, sizeof(input))) {
                         EXIT;
-                        return error;
+                        return -EFAULT;
                 }
 
                 error = lento_mkdir(input.name, input.mode, &input.info);
@@ -766,10 +747,9 @@
                 int error;
                 struct lento_input input;
 
-                error = copy_from_user(&input, (char *)arg, sizeof(input));
-                if ( error ) {
+                if (copy_from_user(&input, (char *)arg, sizeof(input))) {
                         EXIT;
-                        return error;
+                        return -EFAULT;
                 }
 
                 error = lento_rmdir(input.name, &input.info);
@@ -781,10 +761,9 @@
                 int error;
                 struct lento_input_dev input;
 
-                error = copy_from_user(&input, (char *)arg, sizeof(input));
-                if ( error ) {
+                if (copy_from_user(&input, (char *)arg, sizeof(input))) {
                         EXIT;
-                        return error;
+                        return -EFAULT;
                 }
 
                 error = lento_mknod(input.name, input.mode,
@@ -797,10 +776,9 @@
                 int error;
                 struct lento_input_old_new input;
 
-                error = copy_from_user(&input, (char *)arg, sizeof(input));
-                if ( error ) {
+                if (copy_from_user(&input, (char *)arg, sizeof(input))) {
                         EXIT;
-                        return error;
+                        return -EFAULT;
                 }
 
                 error = lento_rename(input.oldname, input.newname, &input.info);
@@ -816,30 +794,27 @@
                 char *name;
                 char *buffer;
 
-                error = copy_from_user(&input, (char *)arg, sizeof(input));
-                if ( error ) { 
+                if (copy_from_user(&input, (char *)arg, sizeof(input))) {
                     EXIT;
-                    return error;
+                    return -EFAULT;
                 }
 
                 /* Now setup the input parameters */
                 PRESTO_ALLOC(name, char *, input.name_len+1);
                 /* We need null terminated strings for attr names */
                 name[input.name_len] = '\0';
-                error=copy_from_user(name, input.name, input.name_len);
-                if ( error ) { 
+                if (copy_from_user(name, input.name, input.name_len)) {
                     EXIT;
                     PRESTO_FREE(name,input.name_len+1);
-                    return error;
+                    return -EFAULT;
                 }
 
                 PRESTO_ALLOC(buffer, char *, input.buffer_len+1);
-                error=copy_from_user(buffer, input.buffer, input.buffer_len);
-                if ( error ) { 
+                if (copy_from_user(buffer, input.buffer, input.buffer_len)) {
                     EXIT;
                     PRESTO_FREE(name,input.name_len+1);
                     PRESTO_FREE(buffer,input.buffer_len+1);
-                    return error;
+                    return -EFAULT;
                 }
                 /* Make null terminated for easy printing */
                 buffer[input.buffer_len]='\0';
@@ -868,21 +843,19 @@
                 struct lento_input_ext_attr input;
                 char *name;
 
-                error = copy_from_user(&input, (char *)arg, sizeof(input));
-                if ( error ) { 
+                if (copy_from_user(&input, (char *)arg, sizeof(input))) {
                     EXIT;
-                    return error;
+                    return -EFAULT;
                 }
 
                 /* Now setup the input parameters */
                 PRESTO_ALLOC(name, char *, input.name_len+1);
                 /* We need null terminated strings for attr names */
                 name[input.name_len] = '\0';
-                error=copy_from_user(name, input.name, input.name_len);
-                if ( error ) { 
+                if (copy_from_user(name, input.name, input.name_len)) {
                     EXIT;
                     PRESTO_FREE(name,input.name_len+1);
-                    return error;
+                    return -EFAULT;
                 }
 
                 CDEBUG(D_PSDEV," delextattr params: name %s,"
@@ -904,12 +877,10 @@
 
         case PRESTO_VFS_IOPEN: {
                 struct lento_input_iopen input;
-                int error;
 
-                error = copy_from_user(&input, (char *)arg, sizeof(input));
-                if ( error ) {
+                if (copy_from_user(&input, (char *)arg, sizeof(input))) {
                         EXIT;
-                        return error;
+                        return -EFAULT;
                 }
 
                 input.fd = lento_iopen(input.name, (ino_t)input.ino,
@@ -920,17 +891,18 @@
                         return input.fd;
                 }
                 EXIT;
-                return copy_to_user((char *)arg, &input, sizeof(input));
+                if (copy_to_user((char *)arg, &input, sizeof(input)))
+			return -EFAULT;
+		return 0;
         }
 
         case PRESTO_VFS_CLOSE: {
                 int error;
                 struct lento_input_close input;
 
-                error = copy_from_user(&input, (char *)arg, sizeof(input));
-                if ( error ) {
+                if (copy_from_user(&input, (char *)arg, sizeof(input))) {
                         EXIT;
-                        return error;
+                        return -EFAULT;
                 }
 
                 CDEBUG(D_PIOCTL, "lento_close file descriptor: %d\n", input.fd);
@@ -941,7 +913,6 @@
 
         case PRESTO_BACKFETCH_LML: {
                 char *user_path;
-                int error;
                 struct lml_arg {
                         char *path;
                         __u32 path_len;
@@ -951,10 +922,9 @@
                         struct presto_version remote_file_version;
                 } input;
 
-                error = copy_from_user(&input, (char *)arg, sizeof(input));
-                if ( error ) {
+                if (copy_from_user(&input, (char *)arg, sizeof(input))) {
                         EXIT;
-                        return error;
+                        return -EFAULT;
                 }
                 user_path = input.path;
 
@@ -963,11 +933,10 @@
                         EXIT;
                         return -ENOMEM;
                 }
-                error = copy_from_user(input.path, user_path, input.path_len);
-                if ( error ) {
+                if (copy_from_user(input.path, user_path, input.path_len)) {
                         EXIT;
                         PRESTO_FREE(input.path, input.path_len + 1);
-                        return error;
+                        return -EFAULT;
                 }
                 input.path[input.path_len] = '\0';
 
@@ -984,7 +953,6 @@
 
         case PRESTO_CANCEL_LML: {
                 char *user_path;
-                int error;
                 struct lml_arg {
                         char *path;
                         __u64 lml_offset; 
@@ -995,10 +963,9 @@
                         struct lento_vfs_context info;
                 } input;
 
-                error = copy_from_user(&input, (char *)arg, sizeof(input));
-                if ( error ) {
+                if (copy_from_user(&input, (char *)arg, sizeof(input))) {
                         EXIT;
-                        return error;
+                        return -EFAULT;
                 }
                 user_path = input.path;
 
@@ -1007,11 +974,10 @@
                         EXIT;
                         return -ENOMEM;
                 }
-                error = copy_from_user(input.path, user_path, input.path_len);
-                if ( error ) {
+                if (copy_from_user(input.path, user_path, input.path_len)) {
                         EXIT;
                         PRESTO_FREE(input.path, input.path_len + 1);
-                        return error;
+                        return -EFAULT;
                 }
                 input.path[input.path_len] = '\0';
 
@@ -1034,10 +1000,9 @@
                         __u32 path_len;
                 } input;
 
-                error = copy_from_user(&input, (char *)arg, sizeof(input));
-                if ( error ) {
+                if (copy_from_user(&input, (char *)arg, sizeof(input))) {
                         EXIT;
-                        return error;
+                        return -EFAULT;
                 }
                 user_path = input.path;
 
@@ -1046,11 +1011,10 @@
                         EXIT;
                         return -ENOMEM;
                 }
-                error = copy_from_user(input.path, user_path, input.path_len);
-                if ( error ) {
+                if (copy_from_user(input.path, user_path, input.path_len)) {
                         EXIT;
                         PRESTO_FREE(input.path, input.path_len + 1);
-                        return error;
+                        return -EFAULT;
                 }
                 input.path[input.path_len] = '\0';
 
@@ -1063,7 +1027,6 @@
 
         case PRESTO_RESET_FSET: {
                 char *user_path;
-                int error;
                 struct lml_arg {
                         char *path;
                         __u32 path_len;
@@ -1071,10 +1034,9 @@
                         __u32 recno;
                 } input;
 
-                error = copy_from_user(&input, (char *)arg, sizeof(input));
-                if ( error ) {
+                if (copy_from_user(&input, (char *)arg, sizeof(input))) {
                         EXIT;
-                        return error;
+                        return -EFAULT;
                 }
                 user_path = input.path;
 
@@ -1083,11 +1045,10 @@
                         EXIT;
                         return -ENOMEM;
                 }
-                error = copy_from_user(input.path, user_path, input.path_len);
-                if ( error ) {
+                if (copy_from_user(input.path, user_path, input.path_len)) {
                         EXIT;
                         PRESTO_FREE(input.path, input.path_len + 1);
-                        return error;
+                        return -EFAULT;
                 }
                 input.path[input.path_len] = '\0';
 
@@ -1110,10 +1071,9 @@
                         char *path;
                 } input;
 
-                error = copy_from_user(&input, (char *)arg, sizeof(input));
-                if ( error ) {
+                if (copy_from_user(&input, (char *)arg, sizeof(input))) {
                         EXIT;
-                        return error;
+                        return -EFAULT;
                 }
                 user_path = input.path;
 
@@ -1122,11 +1082,10 @@
                         EXIT;
                         return -ENOMEM;
                 }
-                error = copy_from_user(input.path, user_path, input.path_len);
-                if ( error ) {
+                if (copy_from_user(input.path, user_path, input.path_len)) {
                         EXIT;
                         PRESTO_FREE(input.path, input.path_len + 1);
-                        return error;
+                        return -EFAULT;
                 }
                 input.path[input.path_len] = '\0';
 
@@ -1189,7 +1148,9 @@
                 }
                 /* return the correct cookie to wait for */
                 input.mark_what = res;
-                return copy_to_user((char *)arg, &input, sizeof(input));
+                if (copy_to_user((char *)arg, &input, sizeof(input)))
+			return -EFAULT;
+		return 0;
         }
 
 #ifdef  CONFIG_KREINT
@@ -1210,11 +1171,10 @@
                         char *path;
                 } permit;
                 
-                error = copy_from_user(&permit, (char *)arg, sizeof(permit));
-                if ( error ) {
+                if (copy_from_user(&permit, (char *)arg, sizeof(permit))) {
                         EXIT;
-                        return error;
-                        }
+                        return -EFAULT;
+		}
                 user_path = permit.path;
                 
                 PRESTO_ALLOC(permit.path, char *, permit.path_len + 1);
@@ -1222,11 +1182,10 @@
                         EXIT;
                         return -ENOMEM;
                 }
-                error = copy_from_user(permit.path, user_path, permit.path_len);
-                if ( error ) {
+                if (copy_from_user(permit.path, user_path, permit.path_len)) {
                         EXIT;
                         PRESTO_FREE(permit.path, permit.path_len + 1);
-                        return error;
+                        return -EFAULT;
                 }
                 permit.path[permit.path_len] = '\0';
                 
@@ -1240,7 +1199,9 @@
                         return error;
                 }
                 /* return the correct cookie to wait for */
-                return copy_to_user((char *)arg, &permit, sizeof(permit));
+                if (copy_to_user((char *)arg, &permit, sizeof(permit)))
+			return -EFAULT;
+		return 0;
         }
         
         default:
diff -urN linux-2.4.19-pre9/fs/nls/nls_koi8-ru.c linux-2.4.19-pre10/fs/nls/nls_koi8-ru.c
--- linux-2.4.19-pre9/fs/nls/nls_koi8-ru.c	Fri Dec 21 09:42:03 2001
+++ linux-2.4.19-pre10/fs/nls/nls_koi8-ru.c	Mon Jun  3 18:50:56 2002
@@ -22,13 +22,14 @@
 	if ((uni & 0xffaf) == 0x040e || (uni & 0xffce) == 0x254c) {
 		/* koi8-ru and koi8-u differ only on two characters */
 		if (uni == 0x040e)
-			return 0xbe;
+			out[0] = 0xbe;
 		else if (uni == 0x045e)
-			return 0xae;
+			out[0] = 0xae;
 		else if (uni == 0x255d || uni == 0x256c)
 			return 0;
 		else
 			return p_nls->uni2char(uni, out, boundlen);
+		return 1;
 	}
 	else
 		/* fast path */
diff -urN linux-2.4.19-pre9/fs/proc/array.c linux-2.4.19-pre10/fs/proc/array.c
--- linux-2.4.19-pre9/fs/proc/array.c	Thu Oct 11 09:00:01 2001
+++ linux-2.4.19-pre10/fs/proc/array.c	Mon Jun  3 18:50:56 2002
@@ -226,6 +226,8 @@
 	sigemptyset(ign);
 	sigemptyset(catch);
 
+	spin_lock_irq(&p->sigmask_lock);
+
 	if (p->sig) {
 		k = p->sig->action;
 		for (i = 1; i <= _NSIG; ++i, ++k) {
@@ -235,6 +237,7 @@
 				sigaddset(catch, i);
 		}
 	}
+	spin_unlock_irq(&p->sigmask_lock);
 }
 
 static inline char * task_sig(struct task_struct *p, char *buffer)
diff -urN linux-2.4.19-pre9/fs/proc/proc_misc.c linux-2.4.19-pre10/fs/proc/proc_misc.c
--- linux-2.4.19-pre9/fs/proc/proc_misc.c	Mon Jun  3 18:50:50 2002
+++ linux-2.4.19-pre10/fs/proc/proc_misc.c	Mon Jun  3 18:50:56 2002
@@ -275,6 +275,20 @@
 };
 #endif
 
+extern struct seq_operations slabinfo_op;
+extern ssize_t slabinfo_write(struct file *, const char *, size_t, loff_t *);
+static int slabinfo_open(struct inode *inode, struct file *file)
+{
+	return seq_open(file, &slabinfo_op);
+}
+static struct file_operations proc_slabinfo_operations = {
+	open:		slabinfo_open,
+	read:		seq_read,
+	write:		slabinfo_write,
+	llseek:		seq_lseek,
+	release:	seq_release,
+};
+
 static int kstat_read_proc(char *page, char **start, off_t off,
 				 int count, int *eof, void *data)
 {
@@ -574,6 +588,7 @@
 	if (entry)
 		entry->proc_fops = &proc_kmsg_operations;
 	create_seq_entry("cpuinfo", 0, &proc_cpuinfo_operations);
+	create_seq_entry("slabinfo",S_IWUSR|S_IRUGO,&proc_slabinfo_operations);
 #ifdef CONFIG_MODULES
 	create_seq_entry("ksyms", 0, &proc_ksyms_operations);
 #endif
@@ -598,8 +613,4 @@
 			entry->proc_fops = &ppc_htab_operations;
 	}
 #endif
-	entry = create_proc_read_entry("slabinfo", S_IWUSR | S_IRUGO, NULL,
-				       slabinfo_read_proc, NULL);
-	if (entry)
-		entry->write_proc = slabinfo_write_proc;
 }
diff -urN linux-2.4.19-pre9/fs/ufs/super.c linux-2.4.19-pre10/fs/ufs/super.c
--- linux-2.4.19-pre9/fs/ufs/super.c	Mon Jun  3 18:50:50 2002
+++ linux-2.4.19-pre10/fs/ufs/super.c	Mon Jun  3 18:50:56 2002
@@ -658,32 +658,32 @@
 	uspi->s_fshift = fs32_to_cpu(sb, usb1->fs_fshift);
 
 	if (uspi->s_fsize & (uspi->s_fsize - 1)) {
-		printk("ufs_read_super: fragment size %u is not a power of 2\n",
+		printk(KERN_ERR "ufs_read_super: fragment size %u is not a power of 2\n",
 			uspi->s_fsize);
 		goto failed;
 	}
-	if (uspi->s_fsize < 512) {
-		printk("ufs_read_super: fragment size %u is too small\n",
+	if (uspi->s_bsize < 512) {
+		printk(KERN_ERR "ufs_read_super: fragment size %u is too small\n",
 			uspi->s_fsize);
 		goto failed;
 	}
-	if (uspi->s_fsize > 4096) {
-		printk("ufs_read_super: fragment size %u is too large\n",
+	if (uspi->s_bsize > 4096) {
+		printk(KERN_ERR "ufs_read_super: fragment size %u is too large\n",
 			uspi->s_fsize);
 		goto failed;
 	}
 	if (uspi->s_bsize & (uspi->s_bsize - 1)) {
-		printk("ufs_read_super: block size %u is not a power of 2\n",
+		printk(KERN_ERR "ufs_read_super: block size %u is not a power of 2\n",
 			uspi->s_bsize);
 		goto failed;
 	}
 	if (uspi->s_bsize < 4096) {
-		printk("ufs_read_super: block size %u is too small\n",
+		printk(KERN_ERR "ufs_read_super: block size %u is too small\n",
 			uspi->s_fsize);
 		goto failed;
 	}
 	if (uspi->s_bsize / uspi->s_fsize > 8) {
-		printk("ufs_read_super: too many fragments per block (%u)\n",
+		printk(KERN_ERR "ufs_read_super: too many fragments per block (%u)\n",
 			uspi->s_bsize / uspi->s_fsize);
 		goto failed;
 	}
diff -urN linux-2.4.19-pre9/include/asm-ppc/pmac_feature.h linux-2.4.19-pre10/include/asm-ppc/pmac_feature.h
--- linux-2.4.19-pre9/include/asm-ppc/pmac_feature.h	Mon Jun  3 18:50:50 2002
+++ linux-2.4.19-pre10/include/asm-ppc/pmac_feature.h	Mon Jun  3 18:50:56 2002
@@ -86,6 +86,7 @@
 #define PMAC_TYPE_PISMO			0x46	/* Pismo PowerBook */
 #define PMAC_TYPE_TITANIUM		0x47	/* Titanium PowerBook */
 #define PMAC_TYPE_TITANIUM2		0x48	/* Titanium II PowerBook */
+#define PMAC_TYPE_TITANIUM3		0x49	/* Titanium III PowerBook (with L3) */
 #define PMAC_TYPE_UNKNOWN_CORE99	0x5f
 
 /* MacRISC2 machines based on the Pangea chipset
diff -urN linux-2.4.19-pre9/include/asm-sparc/ide.h linux-2.4.19-pre10/include/asm-sparc/ide.h
--- linux-2.4.19-pre9/include/asm-sparc/ide.h	Mon Jun  3 18:50:50 2002
+++ linux-2.4.19-pre10/include/asm-sparc/ide.h	Mon Jun  3 18:50:57 2002
@@ -215,79 +215,93 @@
 	/* __flush_dcache_range((unsigned long)src, end); */ /* P3 see hme */
 }
 
-#define T_CHAR          (0x0000)        /* char:  don't touch  */
-#define T_SHORT         (0x4000)        /* short: 12 -> 21     */
-#define T_INT           (0x8000)        /* int:   1234 -> 4321 */
-#define T_TEXT          (0xc000)        /* text:  12 -> 21     */
-
-#define T_MASK_TYPE     (0xc000)
-#define T_MASK_COUNT    (0x3fff)
-
-#define D_CHAR(cnt)     (T_CHAR  | (cnt))
-#define D_SHORT(cnt)    (T_SHORT | (cnt))
-#define D_INT(cnt)      (T_INT   | (cnt))
-#define D_TEXT(cnt)     (T_TEXT  | (cnt))
-
-static u_short driveid_types[] = {
-	D_SHORT(10),	/* config - vendor2 */
-	D_TEXT(20),	/* serial_no */
-	D_SHORT(3),	/* buf_type - ecc_bytes */
-	D_TEXT(48),	/* fw_rev - model */
-	D_CHAR(2),	/* max_multsect - vendor3 */
-	D_SHORT(1),	/* dword_io */
-	D_CHAR(2),	/* vendor4 - capability */
-	D_SHORT(1),	/* reserved50 */
-	D_CHAR(4),	/* vendor5 - tDMA */
-	D_SHORT(4),	/* field_valid - cur_sectors */
-	D_INT(1),	/* cur_capacity */
-	D_CHAR(2),	/* multsect - multsect_valid */
-	D_INT(1),	/* lba_capacity */
-	D_SHORT(194)	/* dma_1word - reservedyy */
-};
-
-#define num_driveid_types       (sizeof(driveid_types)/sizeof(*driveid_types))
-
 static __inline__ void ide_fix_driveid(struct hd_driveid *id)
 {
-	u_char *p = (u_char *)id;
-	int i, j, cnt;
-	u_char t;
+	int i;
+	u16 *stringcast;
 
-	for (i = 0; i < num_driveid_types; i++) {
-		cnt = driveid_types[i] & T_MASK_COUNT;
-		switch (driveid_types[i] & T_MASK_TYPE) {
-		case T_CHAR:
-			p += cnt;
-			break;
-		case T_SHORT:
-			for (j = 0; j < cnt; j++) {
-				t = p[0];
-				p[0] = p[1];
-				p[1] = t;
-				p += 2;
-			}
-			break;
-		case T_INT:
-			for (j = 0; j < cnt; j++) {
-				t = p[0];
-				p[0] = p[3];
-				p[3] = t;
-				t = p[1];
-				p[1] = p[2];
-				p[2] = t;
-				p += 4;
-			}
-			break;
-		case T_TEXT:
-			for (j = 0; j < cnt; j += 2) {
-				t = p[0];
-				p[0] = p[1];
-				p[1] = t;
-				p += 2;
-			}
-			break;
-		};
-	}
+	id->config         = __le16_to_cpu(id->config);
+	id->cyls           = __le16_to_cpu(id->cyls);
+	id->reserved2      = __le16_to_cpu(id->reserved2);
+	id->heads          = __le16_to_cpu(id->heads);
+	id->track_bytes    = __le16_to_cpu(id->track_bytes);
+	id->sector_bytes   = __le16_to_cpu(id->sector_bytes);
+	id->sectors        = __le16_to_cpu(id->sectors);
+	id->vendor0        = __le16_to_cpu(id->vendor0);
+	id->vendor1        = __le16_to_cpu(id->vendor1);
+	id->vendor2        = __le16_to_cpu(id->vendor2);
+	stringcast = (u16 *)&id->serial_no[0];
+	for (i = 0; i < (20/2); i++)
+	        stringcast[i] = __le16_to_cpu(stringcast[i]);
+	id->buf_type       = __le16_to_cpu(id->buf_type);
+	id->buf_size       = __le16_to_cpu(id->buf_size);
+	id->ecc_bytes      = __le16_to_cpu(id->ecc_bytes);
+	stringcast = (u16 *)&id->fw_rev[0];
+	for (i = 0; i < (8/2); i++)
+	        stringcast[i] = __le16_to_cpu(stringcast[i]);
+	stringcast = (u16 *)&id->model[0];
+	for (i = 0; i < (40/2); i++)
+	        stringcast[i] = __le16_to_cpu(stringcast[i]);
+	id->dword_io       = __le16_to_cpu(id->dword_io);
+	id->reserved50     = __le16_to_cpu(id->reserved50);
+	id->field_valid    = __le16_to_cpu(id->field_valid);
+	id->cur_cyls       = __le16_to_cpu(id->cur_cyls);
+	id->cur_heads      = __le16_to_cpu(id->cur_heads);
+	id->cur_sectors    = __le16_to_cpu(id->cur_sectors);
+	id->cur_capacity0  = __le16_to_cpu(id->cur_capacity0);
+	id->cur_capacity1  = __le16_to_cpu(id->cur_capacity1);
+	id->lba_capacity   = __le32_to_cpu(id->lba_capacity);
+	id->dma_1word      = __le16_to_cpu(id->dma_1word);
+	id->dma_mword      = __le16_to_cpu(id->dma_mword);
+	id->eide_pio_modes = __le16_to_cpu(id->eide_pio_modes);
+	id->eide_dma_min   = __le16_to_cpu(id->eide_dma_min);
+	id->eide_dma_time  = __le16_to_cpu(id->eide_dma_time);
+	id->eide_pio       = __le16_to_cpu(id->eide_pio);
+	id->eide_pio_iordy = __le16_to_cpu(id->eide_pio_iordy);
+	for (i = 0; i < 2; i++)
+		id->words69_70[i] = __le16_to_cpu(id->words69_70[i]);
+        for (i = 0; i < 4; i++)
+                id->words71_74[i] = __le16_to_cpu(id->words71_74[i]);
+	id->queue_depth	   = __le16_to_cpu(id->queue_depth);
+	for (i = 0; i < 4; i++)
+		id->words76_79[i] = __le16_to_cpu(id->words76_79[i]);
+	id->major_rev_num  = __le16_to_cpu(id->major_rev_num);
+	id->minor_rev_num  = __le16_to_cpu(id->minor_rev_num);
+	id->command_set_1  = __le16_to_cpu(id->command_set_1);
+	id->command_set_2  = __le16_to_cpu(id->command_set_2);
+	id->cfsse          = __le16_to_cpu(id->cfsse);
+	id->cfs_enable_1   = __le16_to_cpu(id->cfs_enable_1);
+	id->cfs_enable_2   = __le16_to_cpu(id->cfs_enable_2);
+	id->csf_default    = __le16_to_cpu(id->csf_default);
+	id->dma_ultra      = __le16_to_cpu(id->dma_ultra);
+	id->word89         = __le16_to_cpu(id->word89);
+	id->word90         = __le16_to_cpu(id->word90);
+	id->CurAPMvalues   = __le16_to_cpu(id->CurAPMvalues);
+	id->word92         = __le16_to_cpu(id->word92);
+	id->hw_config      = __le16_to_cpu(id->hw_config);
+	id->acoustic       = __le16_to_cpu(id->acoustic);
+	for (i = 0; i < 5; i++)
+		id->words95_99[i]  = __le16_to_cpu(id->words95_99[i]);
+	id->lba_capacity_2 = __le64_to_cpu(id->lba_capacity_2);
+	for (i = 0; i < 22; i++)
+		id->words104_125[i]   = __le16_to_cpu(id->words104_125[i]);
+	id->last_lun       = __le16_to_cpu(id->last_lun);
+	id->word127        = __le16_to_cpu(id->word127);
+	id->dlf            = __le16_to_cpu(id->dlf);
+	id->csfo           = __le16_to_cpu(id->csfo);
+	for (i = 0; i < 26; i++)
+		id->words130_155[i] = __le16_to_cpu(id->words130_155[i]);
+	id->word156        = __le16_to_cpu(id->word156);
+	for (i = 0; i < 3; i++)
+		id->words157_159[i] = __le16_to_cpu(id->words157_159[i]);
+	id->cfa_power      = __le16_to_cpu(id->cfa_power);
+	for (i = 0; i < 14; i++)
+		id->words161_175[i] = __le16_to_cpu(id->words161_175[i]);
+	for (i = 0; i < 31; i++)
+		id->words176_205[i] = __le16_to_cpu(id->words176_205[i]);
+	for (i = 0; i < 48; i++)
+		id->words206_254[i] = __le16_to_cpu(id->words206_254[i]);
+	id->integrity_word  = __le16_to_cpu(id->integrity_word);
 }
 
 /*
diff -urN linux-2.4.19-pre9/include/asm-sparc64/ide.h linux-2.4.19-pre10/include/asm-sparc64/ide.h
--- linux-2.4.19-pre9/include/asm-sparc64/ide.h	Mon Jun  3 18:50:50 2002
+++ linux-2.4.19-pre10/include/asm-sparc64/ide.h	Mon Jun  3 18:50:57 2002
@@ -232,79 +232,93 @@
 #endif
 }
 
-#define T_CHAR          (0x0000)        /* char:  don't touch  */
-#define T_SHORT         (0x4000)        /* short: 12 -> 21     */
-#define T_INT           (0x8000)        /* int:   1234 -> 4321 */
-#define T_TEXT          (0xc000)        /* text:  12 -> 21     */
-
-#define T_MASK_TYPE     (0xc000)
-#define T_MASK_COUNT    (0x3fff)
-
-#define D_CHAR(cnt)     (T_CHAR  | (cnt))
-#define D_SHORT(cnt)    (T_SHORT | (cnt))
-#define D_INT(cnt)      (T_INT   | (cnt))
-#define D_TEXT(cnt)     (T_TEXT  | (cnt))
-
-static u_short driveid_types[] = {
-	D_SHORT(10),	/* config - vendor2 */
-	D_TEXT(20),	/* serial_no */
-	D_SHORT(3),	/* buf_type - ecc_bytes */
-	D_TEXT(48),	/* fw_rev - model */
-	D_CHAR(2),	/* max_multsect - vendor3 */
-	D_SHORT(1),	/* dword_io */
-	D_CHAR(2),	/* vendor4 - capability */
-	D_SHORT(1),	/* reserved50 */
-	D_CHAR(4),	/* vendor5 - tDMA */
-	D_SHORT(4),	/* field_valid - cur_sectors */
-	D_INT(1),	/* cur_capacity */
-	D_CHAR(2),	/* multsect - multsect_valid */
-	D_INT(1),	/* lba_capacity */
-	D_SHORT(194)	/* dma_1word - reservedyy */
-};
-
-#define num_driveid_types       (sizeof(driveid_types)/sizeof(*driveid_types))
-
 static __inline__ void ide_fix_driveid(struct hd_driveid *id)
 {
-	u_char *p = (u_char *)id;
-	int i, j, cnt;
-	u_char t;
+	int i;
+	u16 *stringcast;
 
-	for (i = 0; i < num_driveid_types; i++) {
-		cnt = driveid_types[i] & T_MASK_COUNT;
-		switch (driveid_types[i] & T_MASK_TYPE) {
-		case T_CHAR:
-			p += cnt;
-			break;
-		case T_SHORT:
-			for (j = 0; j < cnt; j++) {
-				t = p[0];
-				p[0] = p[1];
-				p[1] = t;
-				p += 2;
-			}
-			break;
-		case T_INT:
-			for (j = 0; j < cnt; j++) {
-				t = p[0];
-				p[0] = p[3];
-				p[3] = t;
-				t = p[1];
-				p[1] = p[2];
-				p[2] = t;
-				p += 4;
-			}
-			break;
-		case T_TEXT:
-			for (j = 0; j < cnt; j += 2) {
-				t = p[0];
-				p[0] = p[1];
-				p[1] = t;
-				p += 2;
-			}
-			break;
-		};
-	}
+	id->config         = __le16_to_cpu(id->config);
+	id->cyls           = __le16_to_cpu(id->cyls);
+	id->reserved2      = __le16_to_cpu(id->reserved2);
+	id->heads          = __le16_to_cpu(id->heads);
+	id->track_bytes    = __le16_to_cpu(id->track_bytes);
+	id->sector_bytes   = __le16_to_cpu(id->sector_bytes);
+	id->sectors        = __le16_to_cpu(id->sectors);
+	id->vendor0        = __le16_to_cpu(id->vendor0);
+	id->vendor1        = __le16_to_cpu(id->vendor1);
+	id->vendor2        = __le16_to_cpu(id->vendor2);
+	stringcast = (u16 *)&id->serial_no[0];
+	for (i = 0; i < (20/2); i++)
+	        stringcast[i] = __le16_to_cpu(stringcast[i]);
+	id->buf_type       = __le16_to_cpu(id->buf_type);
+	id->buf_size       = __le16_to_cpu(id->buf_size);
+	id->ecc_bytes      = __le16_to_cpu(id->ecc_bytes);
+	stringcast = (u16 *)&id->fw_rev[0];
+	for (i = 0; i < (8/2); i++)
+	        stringcast[i] = __le16_to_cpu(stringcast[i]);
+	stringcast = (u16 *)&id->model[0];
+	for (i = 0; i < (40/2); i++)
+	        stringcast[i] = __le16_to_cpu(stringcast[i]);
+	id->dword_io       = __le16_to_cpu(id->dword_io);
+	id->reserved50     = __le16_to_cpu(id->reserved50);
+	id->field_valid    = __le16_to_cpu(id->field_valid);
+	id->cur_cyls       = __le16_to_cpu(id->cur_cyls);
+	id->cur_heads      = __le16_to_cpu(id->cur_heads);
+	id->cur_sectors    = __le16_to_cpu(id->cur_sectors);
+	id->cur_capacity0  = __le16_to_cpu(id->cur_capacity0);
+	id->cur_capacity1  = __le16_to_cpu(id->cur_capacity1);
+	id->lba_capacity   = __le32_to_cpu(id->lba_capacity);
+	id->dma_1word      = __le16_to_cpu(id->dma_1word);
+	id->dma_mword      = __le16_to_cpu(id->dma_mword);
+	id->eide_pio_modes = __le16_to_cpu(id->eide_pio_modes);
+	id->eide_dma_min   = __le16_to_cpu(id->eide_dma_min);
+	id->eide_dma_time  = __le16_to_cpu(id->eide_dma_time);
+	id->eide_pio       = __le16_to_cpu(id->eide_pio);
+	id->eide_pio_iordy = __le16_to_cpu(id->eide_pio_iordy);
+	for (i = 0; i < 2; i++)
+		id->words69_70[i] = __le16_to_cpu(id->words69_70[i]);
+        for (i = 0; i < 4; i++)
+                id->words71_74[i] = __le16_to_cpu(id->words71_74[i]);
+	id->queue_depth	   = __le16_to_cpu(id->queue_depth);
+	for (i = 0; i < 4; i++)
+		id->words76_79[i] = __le16_to_cpu(id->words76_79[i]);
+	id->major_rev_num  = __le16_to_cpu(id->major_rev_num);
+	id->minor_rev_num  = __le16_to_cpu(id->minor_rev_num);
+	id->command_set_1  = __le16_to_cpu(id->command_set_1);
+	id->command_set_2  = __le16_to_cpu(id->command_set_2);
+	id->cfsse          = __le16_to_cpu(id->cfsse);
+	id->cfs_enable_1   = __le16_to_cpu(id->cfs_enable_1);
+	id->cfs_enable_2   = __le16_to_cpu(id->cfs_enable_2);
+	id->csf_default    = __le16_to_cpu(id->csf_default);
+	id->dma_ultra      = __le16_to_cpu(id->dma_ultra);
+	id->word89         = __le16_to_cpu(id->word89);
+	id->word90         = __le16_to_cpu(id->word90);
+	id->CurAPMvalues   = __le16_to_cpu(id->CurAPMvalues);
+	id->word92         = __le16_to_cpu(id->word92);
+	id->hw_config      = __le16_to_cpu(id->hw_config);
+	id->acoustic       = __le16_to_cpu(id->acoustic);
+	for (i = 0; i < 5; i++)
+		id->words95_99[i]  = __le16_to_cpu(id->words95_99[i]);
+	id->lba_capacity_2 = __le64_to_cpu(id->lba_capacity_2);
+	for (i = 0; i < 22; i++)
+		id->words104_125[i]   = __le16_to_cpu(id->words104_125[i]);
+	id->last_lun       = __le16_to_cpu(id->last_lun);
+	id->word127        = __le16_to_cpu(id->word127);
+	id->dlf            = __le16_to_cpu(id->dlf);
+	id->csfo           = __le16_to_cpu(id->csfo);
+	for (i = 0; i < 26; i++)
+		id->words130_155[i] = __le16_to_cpu(id->words130_155[i]);
+	id->word156        = __le16_to_cpu(id->word156);
+	for (i = 0; i < 3; i++)
+		id->words157_159[i] = __le16_to_cpu(id->words157_159[i]);
+	id->cfa_power      = __le16_to_cpu(id->cfa_power);
+	for (i = 0; i < 14; i++)
+		id->words161_175[i] = __le16_to_cpu(id->words161_175[i]);
+	for (i = 0; i < 31; i++)
+		id->words176_205[i] = __le16_to_cpu(id->words176_205[i]);
+	for (i = 0; i < 48; i++)
+		id->words206_254[i] = __le16_to_cpu(id->words206_254[i]);
+	id->integrity_word  = __le16_to_cpu(id->integrity_word);
 }
 
 /*
diff -urN linux-2.4.19-pre9/include/linux/coda_fs_i.h linux-2.4.19-pre10/include/linux/coda_fs_i.h
--- linux-2.4.19-pre9/include/linux/coda_fs_i.h	Mon Jun  3 18:50:50 2002
+++ linux-2.4.19-pre10/include/linux/coda_fs_i.h	Mon Jun  3 18:50:57 2002
@@ -20,6 +20,7 @@
         struct ViceFid     c_fid;	/* Coda identifier */
         u_short	           c_flags;     /* flags (see below) */
 	struct list_head   c_cilist;    /* list of all coda inodes */
+	int		   c_mapcount;	/* how often is this inode mmapped */
         struct coda_cred   c_cached_cred; /* credentials of cached perms */
         unsigned int       c_cached_perm; /* cached access permissions */
 };
@@ -30,6 +31,7 @@
 #define CODA_MAGIC 0xC0DAC0DA
 struct coda_file_info {
 	int		 cfi_magic;	/* magic number */
+	int		 cfi_mapcount;  /* how often this file is mapped */
 	struct file	*cfi_container;	/* container file for this cnode */
 	struct coda_cred cfi_cred;	/* credentials of opener */
 };
diff -urN linux-2.4.19-pre9/include/linux/coda_psdev.h linux-2.4.19-pre10/include/linux/coda_psdev.h
--- linux-2.4.19-pre9/include/linux/coda_psdev.h	Wed Apr 25 16:18:54 2001
+++ linux-2.4.19-pre10/include/linux/coda_psdev.h	Mon Jun  3 18:50:57 2002
@@ -11,6 +11,7 @@
 	struct venus_comm * sbi_vcomm;
 	struct super_block *sbi_sb;
 	struct list_head    sbi_cihead;
+	struct semaphore    sbi_iget4_mutex;
 };
 
 /* communication pending/processing queues */
diff -urN linux-2.4.19-pre9/include/linux/ethtool.h linux-2.4.19-pre10/include/linux/ethtool.h
--- linux-2.4.19-pre9/include/linux/ethtool.h	Mon Jun  3 18:50:50 2002
+++ linux-2.4.19-pre10/include/linux/ethtool.h	Mon Jun  3 18:50:57 2002
@@ -4,6 +4,9 @@
  * Copyright (C) 1998 David S. Miller (davem@redhat.com)
  * Copyright 2001 Jeff Garzik <jgarzik@mandrakesoft.com>
  * Portions Copyright 2001 Sun Microsystems (thockin@sun.com)
+ * Portions Copyright 2002 Intel (eli.kupermann@intel.com,
+ *                                christopher.leech@intel.com,
+ *                                scott.feldman@intel.com)
  */
 
 #ifndef _LINUX_ETHTOOL_H
@@ -36,7 +39,8 @@
 	char	bus_info[ETHTOOL_BUSINFO_LEN];	/* Bus info for this IF. */
 				/* For PCI devices, use pci_dev->slot_name. */
 	char	reserved1[32];
-	char	reserved2[24];
+	char	reserved2[20];
+	u32	testinfo_len;
 	u32	eedump_len;	/* Size of data from ETHTOOL_GEEPROM (bytes) */
 	u32	regdump_len;	/* Size of data from ETHTOOL_GREGS (bytes) */
 };
@@ -167,8 +171,6 @@
 	 * measured in seconds.  Must not be zero.
 	 */
 	u32	rate_sample_interval;
-
-	u32	reserved[16];
 };
 
 /* for configuring RX/TX ring parameters */
@@ -191,14 +193,6 @@
 	u32	rx_mini_pending;
 	u32	rx_jumbo_pending;
 	u32	tx_pending;
-
-	/* Ideas:
-	 * 1) Allow user to specify TX ring threshold for when
-	 *    to call netif_wake_queue.
-	 * 2) Allow user to specify minimum RX ring entries to
-	 *    post to the chip at a time.
-	 */
-	u32	reserved[16];
 };
 
 /* for configuring link flow control parameters */
@@ -218,13 +212,34 @@
 	u32	autoneg;
 	u32	rx_pause;
 	u32	tx_pause;
+};
 
-	/* Ideas:
-	 * 1) Allow user to specify pause time field in XOFF frame.
-	 * 2) Allow user to specify XOFF/XON emission thresholds
-	 *    in terms of space left in chip FIFOs.
-	 */
-	u32	reserved[8];
+#define ETH_GSTRING_LEN		32
+enum ethtool_stringset {
+	ETH_SS_TEST		= 0,
+	ETH_SS_STATS,
+};
+
+/* for passing string sets for data tagging */
+struct ethtool_gstrings {
+	u32	cmd;		/* ETHTOOL_GSTRINGS */
+	u32	string_set;	/* string set id e.c. ETH_SS_TEST, etc*/
+	u32	len;		/* number of strings in the string set */
+	u8	data[0];
+};
+
+enum ethtool_test_flags {
+	ETH_TEST_FL_OFFLINE	= (1 << 0),	/* online / offline */
+	ETH_TEST_FL_FAILED	= (1 << 1),	/* test passed / failed */
+};
+
+/* for requesting NIC test and getting results*/
+struct ethtool_test {
+	u32	cmd;		/* ETHTOOL_TEST */
+	u32	flags;		/* ETH_TEST_FL_xxx */
+	u32	reserved;
+	u32	len;		/* result length, in number of u64 elements */
+	u64	data[0];
 };
 
 /* CMDs currently supported */
@@ -239,13 +254,13 @@
 #define ETHTOOL_NWAY_RST	0x00000009 /* Restart autonegotiation, priv. */
 #define ETHTOOL_GLINK		0x0000000a /* Get link status (ethtool_value) */
 #define ETHTOOL_GEEPROM		0x0000000b /* Get EEPROM data */
-#define ETHTOOL_SEEPROM		0x0000000c /* Set EEPROM data */
+#define ETHTOOL_SEEPROM		0x0000000c /* Set EEPROM data, priv. */
 #define ETHTOOL_GCOALESCE	0x0000000e /* Get coalesce config */
-#define ETHTOOL_SCOALESCE	0x0000000f /* Set coalesce config */
+#define ETHTOOL_SCOALESCE	0x0000000f /* Set coalesce config, priv. */
 #define ETHTOOL_GRINGPARAM	0x00000010 /* Get ring parameters */
-#define ETHTOOL_SRINGPARAM	0x00000011 /* Set ring parameters */
+#define ETHTOOL_SRINGPARAM	0x00000011 /* Set ring parameters, priv. */
 #define ETHTOOL_GPAUSEPARAM	0x00000012 /* Get pause parameters */
-#define ETHTOOL_SPAUSEPARAM	0x00000013 /* Set pause parameters */
+#define ETHTOOL_SPAUSEPARAM	0x00000013 /* Set pause parameters, priv. */
 #define ETHTOOL_GRXCSUM		0x00000014 /* Get RX hw csum enable (ethtool_value) */
 #define ETHTOOL_SRXCSUM		0x00000015 /* Set RX hw csum enable (ethtool_value) */
 #define ETHTOOL_GTXCSUM		0x00000016 /* Get TX hw csum enable (ethtool_value) */
@@ -253,7 +268,10 @@
 #define ETHTOOL_GSG		0x00000018 /* Get scatter-gather enable
 					    * (ethtool_value) */
 #define ETHTOOL_SSG		0x00000019 /* Set scatter-gather enable
-					    * (ethtool_value) */
+					    * (ethtool_value), priv. */
+#define ETHTOOL_TEST		0x0000001a /* execute NIC self-test, priv. */
+#define ETHTOOL_GSTRINGS	0x0000001b /* get specified string set */
+#define ETHTOOL_PHYS_ID		0x0000001c /* identify the NIC */
 
 /* compatibility with older code */
 #define SPARC_ETH_GSET		ETHTOOL_GSET
diff -urN linux-2.4.19-pre9/include/linux/irq.h linux-2.4.19-pre10/include/linux/irq.h
--- linux-2.4.19-pre9/include/linux/irq.h	Thu Nov 22 11:46:19 2001
+++ linux-2.4.19-pre10/include/linux/irq.h	Mon Jun  3 18:50:57 2002
@@ -76,4 +76,4 @@
 
 #endif
 
-#endif /* __asm_h */
+#endif /* __irq_h */
diff -urN linux-2.4.19-pre9/include/linux/pci_ids.h linux-2.4.19-pre10/include/linux/pci_ids.h
--- linux-2.4.19-pre9/include/linux/pci_ids.h	Mon Jun  3 18:50:51 2002
+++ linux-2.4.19-pre10/include/linux/pci_ids.h	Mon Jun  3 18:50:57 2002
@@ -1539,6 +1539,7 @@
 
 #define PCI_VENDOR_ID_ALTIMA		0x173b
 #define PCI_DEVICE_ID_ALTIMA_AC1000	0x03e8
+#define PCI_DEVICE_ID_ALTIMA_AC9100	0x03ea
 
 #define PCI_VENDOR_ID_SYMPHONY		0x1c1c
 #define PCI_DEVICE_ID_SYMPHONY_101	0x0001
diff -urN linux-2.4.19-pre9/include/linux/slab.h linux-2.4.19-pre10/include/linux/slab.h
--- linux-2.4.19-pre9/include/linux/slab.h	Fri Dec 21 09:42:04 2001
+++ linux-2.4.19-pre10/include/linux/slab.h	Mon Jun  3 18:50:57 2002
@@ -62,10 +62,6 @@
 extern void kfree(const void *);
 
 extern int FASTCALL(kmem_cache_reap(int));
-extern int slabinfo_read_proc(char *page, char **start, off_t off,
-				 int count, int *eof, void *data);
-extern int slabinfo_write_proc(struct file *file, const char *buffer,
-			   unsigned long count, void *data);
 
 /* System wide caches */
 extern kmem_cache_t	*vm_area_cachep;
diff -urN linux-2.4.19-pre9/include/net/pkt_sched.h linux-2.4.19-pre10/include/net/pkt_sched.h
--- linux-2.4.19-pre9/include/net/pkt_sched.h	Mon Jun  3 18:50:51 2002
+++ linux-2.4.19-pre10/include/net/pkt_sched.h	Mon Jun  3 18:50:57 2002
@@ -8,6 +8,7 @@
 #define PSCHED_CLOCK_SOURCE	PSCHED_JIFFIES
 
 #include <linux/config.h>
+#include <linux/types.h>
 #include <linux/pkt_sched.h>
 #include <net/pkt_cls.h>
 
@@ -221,7 +222,7 @@
 
 #define PSCHED_EXPORTLIST_2
 
-#if ~0UL == 0xFFFFFFFF
+#if BITS_PER_LONG <= 32
 
 #define PSCHED_WATCHER unsigned long
 
diff -urN linux-2.4.19-pre9/include/net/route.h linux-2.4.19-pre10/include/net/route.h
--- linux-2.4.19-pre9/include/net/route.h	Mon Feb 25 11:38:13 2002
+++ linux-2.4.19-pre10/include/net/route.h	Mon Jun  3 18:50:57 2002
@@ -110,6 +110,10 @@
         unsigned int out_hit;
         unsigned int out_slow_tot;
         unsigned int out_slow_mc;
+        unsigned int gc_total;
+        unsigned int gc_ignored;
+        unsigned int gc_goal_miss;
+        unsigned int gc_dst_overflow;
 } ____cacheline_aligned_in_smp;
 
 extern struct ip_rt_acct *ip_rt_acct;
diff -urN linux-2.4.19-pre9/ipc/sem.c linux-2.4.19-pre10/ipc/sem.c
--- linux-2.4.19-pre9/ipc/sem.c	Sun Sep 30 12:26:42 2001
+++ linux-2.4.19-pre10/ipc/sem.c	Mon Jun  3 18:50:57 2002
@@ -643,6 +643,7 @@
 		for (un = sma->undo; un; un = un->id_next)
 			un->semadj[semnum] = 0;
 		curr->semval = val;
+		curr->sempid = current->pid;
 		sma->sem_ctime = CURRENT_TIME;
 		/* maybe some queued-up processes were waiting for this */
 		update_queue(sma);
diff -urN linux-2.4.19-pre9/kernel/exit.c linux-2.4.19-pre10/kernel/exit.c
--- linux-2.4.19-pre9/kernel/exit.c	Mon Jun  3 18:50:51 2002
+++ linux-2.4.19-pre10/kernel/exit.c	Mon Jun  3 18:50:57 2002
@@ -152,7 +152,7 @@
 
 /*
  * When we die, we re-parent all our children.
- * Try to give them to another thread in our process
+ * Try to give them to another thread in our thread
  * group, and if no such member exists, give it to
  * the global child reaper process (ie "init")
  */
@@ -162,8 +162,14 @@
 
 	read_lock(&tasklist_lock);
 
-	/* Next in our thread group */
-	reaper = next_thread(father);
+	/* Next in our thread group, if they're not already exiting */
+	reaper = father;
+	do {
+		reaper = next_thread(reaper);
+		if (!(reaper->flags & PF_EXITING))
+			break;
+	} while (reaper != father);
+
 	if (reaper == father)
 		reaper = child_reaper;
 
diff -urN linux-2.4.19-pre9/lib/vsprintf.c linux-2.4.19-pre10/lib/vsprintf.c
--- linux-2.4.19-pre9/lib/vsprintf.c	Mon Jun  3 18:50:51 2002
+++ linux-2.4.19-pre10/lib/vsprintf.c	Thu Oct 11 11:17:22 2001
@@ -172,41 +172,50 @@
 	if (!(type&(ZEROPAD+LEFT))) {
 		while(size-->0) {
 			if (buf <= end)
-				*buf++ = ' ';
+				*buf = ' ';
+			++buf;
 		}
 	}
 	if (sign) {
 		if (buf <= end)
-			*buf++ = sign;
+			*buf = sign;
+		++buf;
 	}
 	if (type & SPECIAL) {
 		if (base==8) {
 			if (buf <= end)
-				*buf++ = '0';
+				*buf = '0';
+			++buf;
 		} else if (base==16) {
 			if (buf <= end)
-				*buf++ = '0';
+				*buf = '0';
+			++buf;
 			if (buf <= end)
-				*buf++ = digits[33];
+				*buf = digits[33];
+			++buf;
 		}
 	}
 	if (!(type & LEFT)) {
 		while (size-- > 0) {
 			if (buf <= end)
-				*buf++ = c;
+				*buf = c;
+			++buf;
 		}
 	}
 	while (i < precision--) {
 		if (buf <= end)
-			*buf++ = '0';
+			*buf = '0';
+		++buf;
 	}
 	while (i-- > 0) {
 		if (buf <= end)
-			*buf++ = tmp[i];
+			*buf = tmp[i];
+		++buf;
 	}
 	while (size-- > 0) {
 		if (buf <= end)
-			*buf++ = ' ';
+			*buf = ' ';
+		++buf;
 	}
 	return buf;
 }
@@ -238,10 +247,6 @@
 				/* 'z' support added 23/7/1999 S.H.    */
 				/* 'z' changed to 'Z' --davidm 1/25/99 */
 
-	/* Enforce absolute minimum size: one character + the trailing 0 */
-	if (size < 2)
-		return 0;
-
 	str = buf;
 	end = buf + size - 1;
 
@@ -253,7 +258,8 @@
 	for (; *fmt ; ++fmt) {
 		if (*fmt != '%') {
 			if (str <= end)
-				*str++ = *fmt;
+				*str = *fmt;
+			++str;
 			continue;
 		}
 
@@ -317,15 +323,18 @@
 				if (!(flags & LEFT)) {
 					while (--field_width > 0) {
 						if (str <= end)
-							*str++ = ' ';
+							*str = ' ';
+						++str;
 					}
 				}
 				c = (unsigned char) va_arg(args, int);
 				if (str <= end)
-					*str++ = c;
+					*str = c;
+				++str;
 				while (--field_width > 0) {
 					if (str <= end)
-						*str++ = ' ';
+						*str = ' ';
+					++str;
 				}
 				continue;
 
@@ -339,16 +348,19 @@
 				if (!(flags & LEFT)) {
 					while (len < field_width--) {
 						if (str <= end)
-							*str++ = ' ';
+							*str = ' ';
+						++str;
 					}
 				}
 				for (i = 0; i < len; ++i) {
 					if (str <= end)
-						*str++ = *s++;
+						*str = *s;
+					++str; ++s;
 				}
 				while (len < field_width--) {
 					if (str <= end)
-						*str++ = ' ';
+						*str = ' ';
+					++str;
 				}
 				continue;
 
@@ -380,7 +392,8 @@
 
 			case '%':
 				if (str <= end)
-					*str++ = '%';
+					*str = '%';
+				++str;
 				continue;
 
 				/* integer number formats - set up the flags and "break" */
@@ -402,10 +415,12 @@
 
 			default:
 				if (str <= end)
-					*str++ = '%';
+					*str = '%';
+				++str;
 				if (*fmt) {
 					if (str <= end)
-						*str++ = *fmt;
+						*str = *fmt;
+					++str;
 				} else {
 					--fmt;
 				}
diff -urN linux-2.4.19-pre9/mm/bootmem.c linux-2.4.19-pre10/mm/bootmem.c
--- linux-2.4.19-pre9/mm/bootmem.c	Fri Dec 21 09:42:04 2001
+++ linux-2.4.19-pre10/mm/bootmem.c	Mon Jun  3 18:50:57 2002
@@ -18,6 +18,7 @@
 #include <linux/bootmem.h>
 #include <linux/mmzone.h>
 #include <asm/dma.h>
+#include <asm/io.h>
 
 /*
  * Access to this subsystem has to be serialized externally. (this is
diff -urN linux-2.4.19-pre9/mm/slab.c linux-2.4.19-pre10/mm/slab.c
--- linux-2.4.19-pre9/mm/slab.c	Mon Jun  3 18:50:51 2002
+++ linux-2.4.19-pre10/mm/slab.c	Mon Jun  3 18:50:57 2002
@@ -72,6 +72,8 @@
 #include	<linux/slab.h>
 #include	<linux/interrupt.h>
 #include	<linux/init.h>
+#include	<linux/compiler.h>
+#include	<linux/seq_file.h>
 #include	<asm/uaccess.h>
 
 /*
@@ -1849,31 +1851,56 @@
 }
 
 #ifdef CONFIG_PROC_FS
-/* /proc/slabinfo
- *	cache-name num-active-objs total-objs
- *	obj-size num-active-slabs total-slabs
- *	num-pages-per-slab
- */
-#define FIXUP(t)				\
-	do {					\
-		if (len <= off) {		\
-			off -= len;		\
-			len = 0;		\
-		} else {			\
-			if (len-off >= count)	\
-				goto t;		\
-		}				\
-	} while (0)
 
-static int proc_getdata (char*page, char**start, off_t off, int count)
+static void *s_start(struct seq_file *m, loff_t *pos)
 {
+	loff_t n = *pos;
 	struct list_head *p;
-	int len = 0;
 
-	/* Output format version, so at least we can change it without _too_
-	 * many complaints.
-	 */
-	len += snprintf(page+len, PAGE_SIZE-len, "slabinfo - version: 1.1"
+	down(&cache_chain_sem);
+	if (!n)
+		return (void *)1;
+	p = &cache_cache.next;
+	while (--n) {
+		p = p->next;
+		if (p == &cache_cache.next)
+			return NULL;
+	}
+	return list_entry(p, kmem_cache_t, next);
+}
+
+static void *s_next(struct seq_file *m, void *p, loff_t *pos)
+{
+	kmem_cache_t *cachep = p;
+	++*pos;
+	if (p == (void *)1)
+		return &cache_cache;
+	cachep = list_entry(cachep->next.next, kmem_cache_t, next);
+	return cachep == &cache_cache ? NULL : cachep;
+}
+
+static void s_stop(struct seq_file *m, void *p)
+{
+	up(&cache_chain_sem);
+}
+
+static int s_show(struct seq_file *m, void *p)
+{
+	kmem_cache_t *cachep = p;
+	struct list_head *q;
+	slab_t		*slabp;
+	unsigned long	active_objs;
+	unsigned long	num_objs;
+	unsigned long	active_slabs = 0;
+	unsigned long	num_slabs;
+	const char *name; 
+
+	if (p == (void*)1) {
+		/*
+		 * Output format version, so at least we can change it
+		 * without _too_ many complaints.
+		 */
+		seq_puts(m, "slabinfo - version: 1.1"
 #if STATS
 				" (statistics)"
 #endif
@@ -1881,117 +1908,91 @@
 				" (SMP)"
 #endif
 				"\n");
-	FIXUP(got_data);
-
-	down(&cache_chain_sem);
-	p = &cache_cache.next;
-	do {
-		kmem_cache_t	*cachep;
-		struct list_head *q;
-		slab_t		*slabp;
-		unsigned long	active_objs;
-		unsigned long	num_objs;
-		unsigned long	active_slabs = 0;
-		unsigned long	num_slabs;
-		cachep = list_entry(p, kmem_cache_t, next);
+		return 0;
+	}
 
-		spin_lock_irq(&cachep->spinlock);
-		active_objs = 0;
-		num_slabs = 0;
-		list_for_each(q,&cachep->slabs_full) {
-			slabp = list_entry(q, slab_t, list);
-			if (slabp->inuse != cachep->num)
-				BUG();
-			active_objs += cachep->num;
-			active_slabs++;
-		}
-		list_for_each(q,&cachep->slabs_partial) {
-			slabp = list_entry(q, slab_t, list);
-			if (slabp->inuse == cachep->num || !slabp->inuse)
-				BUG();
-			active_objs += slabp->inuse;
-			active_slabs++;
-		}
-		list_for_each(q,&cachep->slabs_free) {
-			slabp = list_entry(q, slab_t, list);
-			if (slabp->inuse)
-				BUG();
-			num_slabs++;
-		}
-		num_slabs+=active_slabs;
-		num_objs = num_slabs*cachep->num;
+	spin_lock_irq(&cachep->spinlock);
+	active_objs = 0;
+	num_slabs = 0;
+	list_for_each(q,&cachep->slabs_full) {
+		slabp = list_entry(q, slab_t, list);
+		if (slabp->inuse != cachep->num)
+			BUG();
+		active_objs += cachep->num;
+		active_slabs++;
+	}
+	list_for_each(q,&cachep->slabs_partial) {
+		slabp = list_entry(q, slab_t, list);
+		if (slabp->inuse == cachep->num || !slabp->inuse)
+			BUG();
+		active_objs += slabp->inuse;
+		active_slabs++;
+	}
+	list_for_each(q,&cachep->slabs_free) {
+		slabp = list_entry(q, slab_t, list);
+		if (slabp->inuse)
+			BUG();
+		num_slabs++;
+	}
+	num_slabs+=active_slabs;
+	num_objs = num_slabs*cachep->num;
 
-		len += snprintf(page+len, PAGE_SIZE-len,
-			"%-17s %6lu %6lu %6u %4lu %4lu %4u",
-			cachep->name, active_objs, num_objs, cachep->objsize,
-			active_slabs, num_slabs, (1<<cachep->gfporder));
+	name = cachep->name; 
+	{
+	char tmp; 
+	if (__get_user(tmp, name)) 
+		name = "broken"; 
+	}       
+
+	seq_printf(m, "%-17s %6lu %6lu %6u %4lu %4lu %4u",
+		name, active_objs, num_objs, cachep->objsize,
+		active_slabs, num_slabs, (1<<cachep->gfporder));
 
 #if STATS
-		{
-			unsigned long errors = cachep->errors;
-			unsigned long high = cachep->high_mark;
-			unsigned long grown = cachep->grown;
-			unsigned long reaped = cachep->reaped;
-			unsigned long allocs = cachep->num_allocations;
-
-			len += snprintf(page+len, PAGE_SIZE-len,
-					" : %6lu %7lu %5lu %4lu %4lu",
-					high, allocs, grown, reaped, errors);
-		}
+	{
+		unsigned long errors = cachep->errors;
+		unsigned long high = cachep->high_mark;
+		unsigned long grown = cachep->grown;
+		unsigned long reaped = cachep->reaped;
+		unsigned long allocs = cachep->num_allocations;
+
+		seq_printf(m, " : %6lu %7lu %5lu %4lu %4lu",
+				high, allocs, grown, reaped, errors);
+	}
 #endif
 #ifdef CONFIG_SMP
-		{
-			cpucache_t *cc = cc_data(cachep);
-			unsigned int batchcount = cachep->batchcount;
-			unsigned int limit;
-
-			if (cc)
-				limit = cc->limit;
-			else
-				limit = 0;
-			len += snprintf(page+len, PAGE_SIZE-len, " : %4u %4u",
-					limit, batchcount);
-		}
+	{
+		cpucache_t *cc = cc_data(cachep);
+		unsigned int batchcount = cachep->batchcount;
+		unsigned int limit;
+
+		if (cc)
+			limit = cc->limit;
+		else
+			limit = 0;
+		seq_printf(m, " : %4u %4u",
+				limit, batchcount);
+	}
 #endif
 #if STATS && defined(CONFIG_SMP)
-		{
-			unsigned long allochit = atomic_read(&cachep->allochit);
-			unsigned long allocmiss = atomic_read(&cachep->allocmiss);
-			unsigned long freehit = atomic_read(&cachep->freehit);
-			unsigned long freemiss = atomic_read(&cachep->freemiss);
-			len += snprintf(page+len, PAGE_SIZE-len,
-					" : %6lu %6lu %6lu %6lu",
-					allochit, allocmiss, freehit, freemiss);
-		}
-#endif
-		len += snprintf(page+len, PAGE_SIZE-len, "\n");
-		spin_unlock_irq(&cachep->spinlock);
-		FIXUP(got_data_up);
-		p = cachep->next.next;
-		if (len > PAGE_SIZE - 512)
-			break;
-	} while (p != &cache_cache.next);
-got_data_up:
-	up(&cache_chain_sem);
-
-got_data:
-	if (off < len) {
-		*start = page+off;
-		return len;
+	{
+		unsigned long allochit = atomic_read(&cachep->allochit);
+		unsigned long allocmiss = atomic_read(&cachep->allocmiss);
+		unsigned long freehit = atomic_read(&cachep->freehit);
+		unsigned long freemiss = atomic_read(&cachep->freemiss);
+		seq_printf(m, " : %6lu %6lu %6lu %6lu",
+				allochit, allocmiss, freehit, freemiss);
 	}
+#endif
+	spin_unlock_irq(&cachep->spinlock);
+	seq_putc(m, '\n');
 	return 0;
 }
 
 /**
- * slabinfo_read_proc - generates /proc/slabinfo
- * @page: scratch area, one page long
- * @start: pointer to the pointer to the output buffer
- * @off: offset within /proc/slabinfo the caller is interested in
- * @count: requested len in bytes
- * @eof: eof marker
- * @data: unused
+ * slabinfo_op - iterator that generates /proc/slabinfo
  *
- * The contents of the buffer are
+ * Output layout:
  * cache-name
  * num-active-objs
  * total-objs
@@ -2001,28 +2002,24 @@
  * num-pages-per-slab
  * + further values on SMP and with statistics enabled
  */
-int slabinfo_read_proc (char *page, char **start, off_t off,
-				 int count, int *eof, void *data)
-{
-	int len = proc_getdata(page, start, off, count);
-	len -= (*start-page);
-	if (len <= count)
-		*eof = 1;
-	if (len>count) len = count;
-	if (len<0) len = 0;
-	return len;
-}
+
+struct seq_operations slabinfo_op = {
+	start:	s_start,
+	next:	s_next,
+	stop:	s_stop,
+	show:	s_show
+};
 
 #define MAX_SLABINFO_WRITE 128
 /**
- * slabinfo_write_proc - SMP tuning for the slab allocator
+ * slabinfo_write - SMP tuning for the slab allocator
  * @file: unused
  * @buffer: user buffer
  * @count: data len
  * @data: unused
  */
-int slabinfo_write_proc (struct file *file, const char *buffer,
-				unsigned long count, void *data)
+ssize_t slabinfo_write(struct file *file, const char *buffer,
+				size_t count, loff_t *ppos)
 {
 #ifdef CONFIG_SMP
 	char kbuf[MAX_SLABINFO_WRITE+1], *tmp;
diff -urN linux-2.4.19-pre9/net/core/neighbour.c linux-2.4.19-pre10/net/core/neighbour.c
--- linux-2.4.19-pre9/net/core/neighbour.c	Mon Jun  3 18:50:51 2002
+++ linux-2.4.19-pre10/net/core/neighbour.c	Mon Jun  3 18:50:57 2002
@@ -54,12 +54,6 @@
 static int neigh_glbl_allocs;
 static struct neigh_table *neigh_tables;
 
-#if defined(__i386__) && defined(CONFIG_SMP)
-#define ASSERT_WL(n) if ((int)((n)->lock.lock) > 0) { printk("WL assertion failed at " __FILE__ "(%d):" __FUNCTION__ "\n", __LINE__); }
-#else
-#define ASSERT_WL(n) do { } while(0)
-#endif
-
 /*
    Neighbour hash table buckets are protected with rwlock tbl->lock.
 
@@ -484,8 +478,6 @@
 
 	NEIGH_PRINTK2("neigh %p is suspecteded.\n", neigh);
 
-	ASSERT_WL(neigh);
-
 	neigh->output = neigh->ops->output;
 
 	for (hh = neigh->hh; hh; hh = hh->hh_next)
@@ -503,8 +495,6 @@
 
 	NEIGH_PRINTK2("neigh %p is connected.\n", neigh);
 
-	ASSERT_WL(neigh);
-
 	neigh->output = neigh->ops->connected_output;
 
 	for (hh = neigh->hh; hh; hh = hh->hh_next)
@@ -529,7 +519,6 @@
 	unsigned long now = jiffies;
 	u8 state = n->nud_state;
 
-	ASSERT_WL(n);
 	if (state&(NUD_NOARP|NUD_PERMANENT))
 		return;
 	if (state&NUD_REACHABLE) {
diff -urN linux-2.4.19-pre9/net/core/sock.c linux-2.4.19-pre10/net/core/sock.c
--- linux-2.4.19-pre9/net/core/sock.c	Mon Jun  3 18:50:51 2002
+++ linux-2.4.19-pre10/net/core/sock.c	Mon Jun  3 18:50:57 2002
@@ -627,7 +627,7 @@
 		sysctl_wmem_max = 32767;
 		sysctl_rmem_max = 32767;
 		sysctl_wmem_default = 32767;
-		sysctl_wmem_default = 32767;
+		sysctl_rmem_default = 32767;
 	} else if (num_physpages >= 131072) {
 		sysctl_wmem_max = 131071;
 		sysctl_rmem_max = 131071;
diff -urN linux-2.4.19-pre9/net/ipv4/ip_output.c linux-2.4.19-pre10/net/ipv4/ip_output.c
--- linux-2.4.19-pre9/net/ipv4/ip_output.c	Mon Jun  3 18:50:51 2002
+++ linux-2.4.19-pre10/net/ipv4/ip_output.c	Mon Jun  3 18:50:57 2002
@@ -321,7 +321,8 @@
 		/* Reject packet ONLY if TCP might fragment
 		 * it itself, if were careful enough.
 		 */
-		NETDEBUG(printk(KERN_DEBUG "sending pkt_too_big to self\n"));
+		NETDEBUG(printk(KERN_DEBUG "sending pkt_too_big (len[%u] pmtu[%u]) to self\n",
+				skb->len, rt->u.dst.pmtu));
 
 		icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED,
 			  htonl(rt->u.dst.pmtu));
diff -urN linux-2.4.19-pre9/net/ipv4/netfilter/ipchains_core.c linux-2.4.19-pre10/net/ipv4/netfilter/ipchains_core.c
--- linux-2.4.19-pre9/net/ipv4/netfilter/ipchains_core.c	Mon Feb 25 11:38:14 2002
+++ linux-2.4.19-pre10/net/ipv4/netfilter/ipchains_core.c	Mon Jun  3 18:50:57 2002
@@ -549,7 +549,7 @@
 			strcpy(outskb->data+sizeof(__u32)*2, rif);
 			memcpy(outskb->data+sizeof(__u32)*2+IFNAMSIZ, ip,
 			       len-(sizeof(__u32)*2+IFNAMSIZ));
-			netlink_broadcast(ipfwsk, outskb, 0, ~0, GFP_KERNEL);
+			netlink_broadcast(ipfwsk, outskb, 0, ~0, GFP_ATOMIC);
 		}
 		else {
 #endif
diff -urN linux-2.4.19-pre9/net/ipv4/netfilter/ipt_ULOG.c linux-2.4.19-pre10/net/ipv4/netfilter/ipt_ULOG.c
--- linux-2.4.19-pre9/net/ipv4/netfilter/ipt_ULOG.c	Mon Jun  3 18:50:51 2002
+++ linux-2.4.19-pre10/net/ipv4/netfilter/ipt_ULOG.c	Mon Jun  3 18:50:57 2002
@@ -29,7 +29,7 @@
  *   Specify, after how many clock ticks (intel: 100 per second) the queue
  * should be flushed even if it is not full yet.
  *
- * ipt_ULOG.c,v 1.15 2002/01/18 21:33:19 laforge Exp
+ * ipt_ULOG.c,v 1.18 2002/04/16 07:33:00 laforge Exp
  */
 
 #include <linux/module.h>
@@ -339,10 +339,28 @@
 
 static void __exit fini(void)
 {
+	ulog_buff_t *ub;
+	int i;
+
 	DEBUGP("ipt_ULOG: cleanup_module\n");
 
 	ipt_unregister_target(&ipt_ulog_reg);
 	sock_release(nflognl->socket);
+
+	/* remove pending timers and free allocated skb's */
+	for (i = 0; i < ULOG_MAXNLGROUPS; i++) {
+		ub = &ulog_buffers[i];
+		if (timer_pending(&ub->timer)) {
+			DEBUGP("timer was pending, deleting\n");
+			del_timer(&ub->timer);
+		}
+
+		if (ub->skb) {
+			kfree_skb(ub->skb);
+			ub->skb = NULL;
+		}
+	}
+
 }
 
 module_init(init);
diff -urN linux-2.4.19-pre9/net/ipv4/route.c linux-2.4.19-pre10/net/ipv4/route.c
--- linux-2.4.19-pre9/net/ipv4/route.c	Mon Jun  3 18:50:51 2002
+++ linux-2.4.19-pre10/net/ipv4/route.c	Mon Jun  3 18:50:57 2002
@@ -286,7 +286,7 @@
         for (lcpu = 0; lcpu < smp_num_cpus; lcpu++) {
                 i = cpu_logical_map(lcpu);
 
-		len += sprintf(buffer+len, "%08x  %08x %08x %08x %08x %08x %08x %08x  %08x %08x %08x\n",
+		len += sprintf(buffer+len, "%08x  %08x %08x %08x %08x %08x %08x %08x  %08x %08x %08x %08x %08x %08x %08x \n",
 			       dst_entries,		       
 			       rt_cache_stat[i].in_hit,
 			       rt_cache_stat[i].in_slow_tot,
@@ -298,7 +298,13 @@
 
 			       rt_cache_stat[i].out_hit,
 			       rt_cache_stat[i].out_slow_tot,
-			       rt_cache_stat[i].out_slow_mc
+			       rt_cache_stat[i].out_slow_mc, 
+
+			       rt_cache_stat[i].gc_total,
+			       rt_cache_stat[i].gc_ignored,
+			       rt_cache_stat[i].gc_goal_miss,
+			       rt_cache_stat[i].gc_dst_overflow
+
 			);
 	}
 	len -= offset;
@@ -499,9 +505,14 @@
 	 * Garbage collection is pretty expensive,
 	 * do not make it too frequently.
 	 */
+
+	rt_cache_stat[smp_processor_id()].gc_total++;
+
 	if (now - last_gc < ip_rt_gc_min_interval &&
-	    atomic_read(&ipv4_dst_ops.entries) < ip_rt_max_size)
+	    atomic_read(&ipv4_dst_ops.entries) < ip_rt_max_size) {
+		rt_cache_stat[smp_processor_id()].gc_ignored++;
 		goto out;
+	}
 
 	/* Calculate number of entries, which we want to expire now. */
 	goal = atomic_read(&ipv4_dst_ops.entries) -
@@ -567,6 +578,8 @@
 		     We will not spin here for long time in any case.
 		 */
 
+		rt_cache_stat[smp_processor_id()].gc_goal_miss++;
+
 		if (expire == 0)
 			break;
 
@@ -584,6 +597,7 @@
 		goto out;
 	if (net_ratelimit())
 		printk(KERN_WARNING "dst cache overflow\n");
+	rt_cache_stat[smp_processor_id()].gc_dst_overflow++;
 	return 1;
 
 work_done:
diff -urN linux-2.4.19-pre9/net/ipv4/syncookies.c linux-2.4.19-pre10/net/ipv4/syncookies.c
--- linux-2.4.19-pre9/net/ipv4/syncookies.c	Tue Oct 30 15:08:12 2001
+++ linux-2.4.19-pre10/net/ipv4/syncookies.c	Mon Jun  3 18:50:57 2002
@@ -14,8 +14,6 @@
  *  Missing: IPv6 support. 
  */
 
-#include <linux/config.h>
-#if defined(CONFIG_SYN_COOKIES) 
 #include <linux/tcp.h>
 #include <linux/slab.h>
 #include <linux/random.h>
@@ -192,4 +190,3 @@
 	ret = get_cookie_sock(sk, skb, req, &rt->u.dst);
 out:	return ret;
 }
-#endif
diff -urN linux-2.4.19-pre9/net/ipv4/tcp.c linux-2.4.19-pre10/net/ipv4/tcp.c
--- linux-2.4.19-pre9/net/ipv4/tcp.c	Mon Jun  3 18:50:51 2002
+++ linux-2.4.19-pre10/net/ipv4/tcp.c	Mon Jun  3 18:50:57 2002
@@ -1662,6 +1662,12 @@
 				}
 			}
 		}
+		if ((flags & MSG_PEEK) && peek_seq != tp->copied_seq) {
+			if (net_ratelimit())
+				printk(KERN_DEBUG "TCP(%s:%d): Application bug, race in MSG_PEEK.\n",
+				       current->comm, current->pid);
+			peek_seq = tp->copied_seq;
+		}
 		continue;
 
 	found_ok_skb:
diff -urN linux-2.4.19-pre9/net/ipv4/tcp_input.c linux-2.4.19-pre10/net/ipv4/tcp_input.c
--- linux-2.4.19-pre9/net/ipv4/tcp_input.c	Mon Jun  3 18:50:51 2002
+++ linux-2.4.19-pre10/net/ipv4/tcp_input.c	Mon Jun  3 18:50:57 2002
@@ -464,7 +464,7 @@
 	} else {
 		/* no previous measure. */
 		tp->srtt = m<<3;	/* take the measured time to be rtt */
-		tp->mdev = m<<2;	/* make sure rto = 3*rtt */
+		tp->mdev = m<<1;	/* make sure rto = 3*rtt */
 		tp->mdev_max = tp->rttvar = max(tp->mdev, TCP_RTO_MIN);
 		tp->rtt_seq = tp->snd_nxt;
 	}
diff -urN linux-2.4.19-pre9/net/ipv4/tcp_ipv4.c linux-2.4.19-pre10/net/ipv4/tcp_ipv4.c
--- linux-2.4.19-pre9/net/ipv4/tcp_ipv4.c	Mon Jun  3 18:50:51 2002
+++ linux-2.4.19-pre10/net/ipv4/tcp_ipv4.c	Mon Jun  3 18:50:57 2002
@@ -1499,7 +1499,6 @@
 			NETDEBUG(if (net_ratelimit()) \
 				printk(KERN_DEBUG "TCP: drop open request from %u.%u.%u.%u/%u\n", \
 					NIPQUAD(saddr), ntohs(skb->h.th->source)));
-			TCP_INC_STATS_BH(TcpAttemptFails);
 			dst_release(dst);
 			goto drop_and_free;
 		}
diff -urN linux-2.4.19-pre9/net/ipv6/raw.c linux-2.4.19-pre10/net/ipv6/raw.c
--- linux-2.4.19-pre9/net/ipv6/raw.c	Mon Jun  3 18:50:51 2002
+++ linux-2.4.19-pre10/net/ipv6/raw.c	Mon Jun  3 18:50:57 2002
@@ -11,6 +11,7 @@
  *
  *	Fixes:
  *	Hideaki YOSHIFUJI	:	sin6_scope_id support
+ *	YOSHIFUJI,H.@USAGI	:	raw checksum (RFC2292(bis) compliance) 
  *
  *	This program is free software; you can redistribute it and/or
  *      modify it under the terms of the GNU General Public License
@@ -480,11 +481,18 @@
 		hdr->cksum = csum_ipv6_magic(addr, daddr, hdr->len,
 					     hdr->proto, hdr->cksum);
 		
-		if (opt->offset < len) {
+		if (opt->offset + 1 < len) {
 			__u16 *csum;
 
 			csum = (__u16 *) (buff + opt->offset);
-			*csum = hdr->cksum;
+			if (*csum) {
+				/* in case cksum was not initialized */
+				__u32 sum = hdr->cksum;
+				sum += *csum;
+				*csum = hdr->cksum = (sum + (sum>>16));
+			} else {
+				*csum = hdr->cksum;
+			}
 		} else {
 			if (net_ratelimit())
 				printk(KERN_DEBUG "icmp: cksum offset too big\n");
@@ -712,6 +720,10 @@
 
 	switch (optname) {
 		case IPV6_CHECKSUM:
+			/* You may get strange result with a positive odd offset;
+			   RFC2292bis agrees with me. */
+			if (val > 0 && (val&1))
+				return(-EINVAL);
 			if (val < 0) {
 				opt->checksum = 0;
 			} else {
@@ -809,6 +821,11 @@
 
 static int rawv6_init_sk(struct sock *sk)
 {
+	if (sk->num == IPPROTO_ICMPV6){
+		struct raw6_opt *opt = &sk->tp_pinfo.tp_raw;
+		opt->checksum = 1;
+		opt->offset = 2;
+	}
 	return(0);
 }
 
diff -urN linux-2.4.19-pre9/net/sched/sch_api.c linux-2.4.19-pre10/net/sched/sch_api.c
--- linux-2.4.19-pre9/net/sched/sch_api.c	Fri Dec 21 09:42:06 2001
+++ linux-2.4.19-pre10/net/sched/sch_api.c	Mon Jun  3 18:50:57 2002
@@ -1117,7 +1117,7 @@
 	psched_timer.expires = jiffies + 1*HZ;
 #else
 	unsigned long now = jiffies;
-	psched_time_base = ((u64)now)<<PSCHED_JSCALE;
+	psched_time_base += ((u64)(now-psched_time_mark))<<PSCHED_JSCALE;
 	psched_time_mark = now;
 	psched_timer.expires = now + 60*60*HZ;
 #endif
diff -urN linux-2.4.19-pre9/net/sched/sch_ingress.c linux-2.4.19-pre10/net/sched/sch_ingress.c
--- linux-2.4.19-pre9/net/sched/sch_ingress.c	Mon Jun  3 18:50:51 2002
+++ linux-2.4.19-pre10/net/sched/sch_ingress.c	Mon Jun  3 18:50:57 2002
@@ -146,8 +146,8 @@
 	 * Unlike normal "enqueue" functions, ingress_enqueue returns a
 	 * firewall FW_* code.
 	 */
-	switch (result) {
 #ifdef CONFIG_NET_CLS_POLICE
+	switch (result) {
 		case TC_POLICE_SHOT:
 			result = NF_DROP;
 			sch->stats.drops++;
@@ -160,7 +160,7 @@
 			sch->stats.bytes += skb->len;
 			result = NF_ACCEPT;
 			break;
-	}
+	};
 #else
 	sch->stats.packets++;
 	sch->stats.bytes += skb->len;
diff -urN linux-2.4.19-pre9/scripts/mkspec linux-2.4.19-pre10/scripts/mkspec
--- linux-2.4.19-pre9/scripts/mkspec	Mon Jun  3 18:50:51 2002
+++ linux-2.4.19-pre10/scripts/mkspec	Mon Jun  3 18:50:57 2002
@@ -6,6 +6,16 @@
 #	The only gothic bit here is redefining install_post to avoid 
 #	stripping the symbols from files in the kernel which we want
 #
+#	Patched for non-x86 by Opencon (L) 2002 <opencon@rio.skydome.net>
+#
+# That's the voodoo to see if it's a x86.
+ISX86=`arch | grep -ie i.86`
+if [ ! -z $ISX86 ]; then
+	PC=1
+else
+	PC=0
+fi
+# starting to output the spec
 if [ "`grep CONFIG_DRM=y .config | cut -f2 -d\=`" = "y" ]; then
 	PROVIDES=kernel-drm
 fi
@@ -35,12 +45,24 @@
 echo "%setup -q"
 echo ""
 echo "%build"
-echo "make oldconfig dep clean bzImage modules"
+# This is the first 'disagreement' between x86 and other archs.
+if [ $PC = 1 ]; then 
+	echo "make oldconfig dep clean bzImage modules"
+else
+	echo "make oldconfig dep clean vmlinux modules"
+fi
+# Back on track
 echo ""
 echo "%install"
 echo 'mkdir -p $RPM_BUILD_ROOT/boot $RPM_BUILD_ROOT/lib $RPM_BUILD_ROOT/lib/modules'
 echo 'INSTALL_MOD_PATH=$RPM_BUILD_ROOT make modules_install'
-echo 'cp arch/i386/boot/bzImage $RPM_BUILD_ROOT'"/boot/vmlinuz-$VERSION.$PATCHLEVEL.$SUBLEVEL$EXTRAVERSION"
+# And that's the second
+if [ $PC = 1 ]; then
+	echo 'cp arch/i386/boot/bzImage $RPM_BUILD_ROOT'"/boot/vmlinuz-$VERSION.$PATCHLEVEL.$SUBLEVEL$EXTRAVERSION"
+else
+	echo 'cp vmlinux $RPM_BUILD_ROOT'"/boot/vmlinux-$VERSION.$PATCHLEVEL.$SUBLEVEL$EXTRAVERSION"
+fi
+# Back on track, again
 echo 'cp System.map $RPM_BUILD_ROOT'"/boot/System.map-$VERSION.$PATCHLEVEL.$SUBLEVEL$EXTRAVERSION"
 echo 'cp .config $RPM_BUILD_ROOT'"/boot/config-$VERSION.$PATCHLEVEL.$SUBLEVEL$EXTRAVERSION"
 echo ""
