
From: Ralf Baechle <ralf@linux-mips.org>

Mostly reformatting to get the sometimes random formatting style of the LCD
driver to something Linux compliant.  Use module_init/exit for module
initialization and cleanup.

Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
---

 25-akpm/arch/mips/Kconfig                  |    5 
 25-akpm/arch/mips/configs/cobalt_defconfig |    2 
 25-akpm/drivers/char/Kconfig               |    7 
 25-akpm/drivers/char/Makefile              |    1 
 25-akpm/drivers/char/lcd.c                 |  702 +++++++++++++++--------------
 25-akpm/drivers/char/lcd.h                 |  184 +++++++
 6 files changed, 568 insertions(+), 333 deletions(-)

diff -puN arch/mips/configs/cobalt_defconfig~cobalt-lcd-driver-update arch/mips/configs/cobalt_defconfig
--- 25/arch/mips/configs/cobalt_defconfig~cobalt-lcd-driver-update	2004-06-19 14:25:04.688827632 -0700
+++ 25-akpm/arch/mips/configs/cobalt_defconfig	2004-06-19 14:25:04.703825352 -0700
@@ -80,7 +80,6 @@ CONFIG_I8259=y
 CONFIG_CPU_LITTLE_ENDIAN=y
 CONFIG_IRQ_CPU=y
 CONFIG_MIPS_GT64111=y
-CONFIG_COBALT_LCD=y
 CONFIG_MIPS_L1_CACHE_SHIFT=5
 # CONFIG_FB is not set
 
@@ -432,6 +431,7 @@ CONFIG_LEGACY_PTY_COUNT=256
 #
 # CONFIG_WATCHDOG is not set
 CONFIG_RTC=y
+CONFIG_COBALT_LCD=y
 # CONFIG_DTLK is not set
 # CONFIG_R3964 is not set
 # CONFIG_APPLICOM is not set
diff -puN arch/mips/Kconfig~cobalt-lcd-driver-update arch/mips/Kconfig
--- 25/arch/mips/Kconfig~cobalt-lcd-driver-update	2004-06-19 14:25:04.689827480 -0700
+++ 25-akpm/arch/mips/Kconfig	2004-06-19 14:25:04.702825504 -0700
@@ -932,11 +932,6 @@ config AU1000_USB_DEVICE
 	depends on MIPS_PB1500 || MIPS_PB1100 || MIPS_PB1000
 	default n
 
-config COBALT_LCD
-	bool
-	depends on MIPS_COBALT
-	default y
-
 config MIPS_GT96100
 	bool
 	depends on MIPS_EV96100
diff -puN drivers/char/Kconfig~cobalt-lcd-driver-update drivers/char/Kconfig
--- 25/drivers/char/Kconfig~cobalt-lcd-driver-update	2004-06-19 14:25:04.691827176 -0700
+++ 25-akpm/drivers/char/Kconfig	2004-06-19 14:25:04.704825200 -0700
@@ -793,6 +793,13 @@ config EFI_RTC
 	bool "EFI Real Time Clock Services"
 	depends on IA64
 
+config COBALT_LCD
+	bool "Support for Cobalt LCD"
+	depends on MIPS_COBALT
+	help
+	  This option enables support for the LCD display and buttons found
+	  on Cobalt systems through a misc device.
+
 config H8
 	bool "Tadpole ANA H8 Support (OBSOLETE)"
 	depends on OBSOLETE && ALPHA_BOOK1
diff -puN drivers/char/lcd.c~cobalt-lcd-driver-update drivers/char/lcd.c
--- 25/drivers/char/lcd.c~cobalt-lcd-driver-update	2004-06-19 14:25:04.693826872 -0700
+++ 25-akpm/drivers/char/lcd.c	2004-06-19 14:25:04.709824440 -0700
@@ -12,7 +12,7 @@
  *
  */
 
-#define RTC_IO_EXTENT	0x10    /*Only really two ports, but...	*/
+#define RTC_IO_EXTENT	0x10	/*Only really two ports, but... */
 
 #include <linux/config.h>
 #include <linux/types.h>
@@ -32,8 +32,8 @@
 
 #include "lcd.h"
 
-static int lcd_ioctl(struct inode *inode, struct file *file, unsigned int cmd, 
-                     unsigned long arg);
+static int lcd_ioctl(struct inode *inode, struct file *file,
+		     unsigned int cmd, unsigned long arg);
 
 static int lcd_present = 1;
 
@@ -57,8 +57,8 @@ int lcd_register_linkcheck_func(int ifac
 }
 #endif
 
-static int lcd_ioctl(struct inode *inode, struct file *file, unsigned int cmd, 
-			unsigned long arg)
+static int lcd_ioctl(struct inode *inode, struct file *file,
+		     unsigned int cmd, unsigned long arg)
 {
 	struct lcd_display button_display;
 	unsigned long address, a;
@@ -69,7 +69,7 @@ static int lcd_ioctl(struct inode *inode
 		udelay(150);
 		BusyCheck();
 		LCDWriteInst(0x0F);
-		break;		
+		break;
 
 	case LCD_Off:
 		udelay(150);
@@ -95,7 +95,7 @@ static int lcd_ioctl(struct inode *inode
 	case LCD_Clear:
 		udelay(150);
 		BusyCheck();
-       		LCDWriteInst(0x01);     
+		LCDWriteInst(0x01);
 		break;
 
 	case LCD_Cursor_Left:
@@ -108,86 +108,95 @@ static int lcd_ioctl(struct inode *inode
 		udelay(150);
 		BusyCheck();
 		LCDWriteInst(0x14);
-		break;	
+		break;
 
 	case LCD_Cursor_Off:
 		udelay(150);
-                BusyCheck();
-                LCDWriteInst(0x0C);
-	        break;
-
-        case LCD_Cursor_On:
-                udelay(150);
-                BusyCheck();
-                LCDWriteInst(0x0F);
-                break;
-
-        case LCD_Blink_Off:
-                udelay(150);
-                BusyCheck();
-                LCDWriteInst(0x0E);
-                break;
-
-	case LCD_Get_Cursor_Pos:{
-                struct lcd_display display;
+		BusyCheck();
+		LCDWriteInst(0x0C);
+		break;
 
+	case LCD_Cursor_On:
 		udelay(150);
-                BusyCheck();
-		display.cursor_address = ( LCDReadInst ); 
-		display.cursor_address = ( display.cursor_address & 0x07F );
-		if(copy_to_user((struct lcd_display*)arg, &display, sizeof(struct lcd_display)))
-		  return -EFAULT;
+		BusyCheck();
+		LCDWriteInst(0x0F);
+		break;
 
+	case LCD_Blink_Off:
+		udelay(150);
+		BusyCheck();
+		LCDWriteInst(0x0E);
 		break;
+
+	case LCD_Get_Cursor_Pos:{
+			struct lcd_display display;
+
+			udelay(150);
+			BusyCheck();
+			display.cursor_address = (LCDReadInst);
+			display.cursor_address =
+			    (display.cursor_address & 0x07F);
+			if (copy_to_user
+			    ((struct lcd_display *) arg, &display,
+			     sizeof(struct lcd_display)))
+				return -EFAULT;
+
+			break;
 		}
 
 
-	case LCD_Set_Cursor_Pos: {
-                struct lcd_display display;
+	case LCD_Set_Cursor_Pos:{
+			struct lcd_display display;
 
-                if(copy_from_user(&display, (struct lcd_display*)arg, sizeof(struct lcd_display)))
-		  return -EFAULT;
+			if (copy_from_user
+			    (&display, (struct lcd_display *) arg,
+			     sizeof(struct lcd_display)))
+				return -EFAULT;
 
-		a = (display.cursor_address | kLCD_Addr ); 
+			a = (display.cursor_address | kLCD_Addr);
 
-                udelay(150);
-                BusyCheck();    
-                LCDWriteInst( a );
+			udelay(150);
+			BusyCheck();
+			LCDWriteInst(a);
 
-                break;
+			break;
 		}
-	
-	case LCD_Get_Cursor: {
-                struct lcd_display display;
 
-                udelay(150);
-                BusyCheck();    
-		display.character = LCDReadData;	
+	case LCD_Get_Cursor:{
+			struct lcd_display display;
 
-		if(copy_to_user((struct lcd_display*)arg, &display, sizeof(struct lcd_display)))
-		  return -EFAULT;
-                udelay(150);
-                BusyCheck();
-                LCDWriteInst(0x10);
+			udelay(150);
+			BusyCheck();
+			display.character = LCDReadData;
 
-		break;
+			if (copy_to_user
+			    ((struct lcd_display *) arg, &display,
+			     sizeof(struct lcd_display)))
+				return -EFAULT;
+			udelay(150);
+			BusyCheck();
+			LCDWriteInst(0x10);
+
+			break;
 		}
 
 	case LCD_Set_Cursor:{
-                struct lcd_display display;
-   
-                if(copy_from_user(&display, (struct lcd_display*)arg, sizeof(struct lcd_display)))
-		  return -EFAULT;
-
-                udelay(150);
-		BusyCheck();    
-                LCDWriteData( display.character );
-                udelay(150);
-                BusyCheck();
-                LCDWriteInst(0x10);
+			struct lcd_display display;
 
-                break;
-                }
+			if (copy_from_user
+			    (&display, (struct lcd_display *) arg,
+			     sizeof(struct lcd_display)))
+				return -EFAULT;
+
+			udelay(150);
+			BusyCheck();
+			LCDWriteData(display.character);
+			udelay(150);
+			BusyCheck();
+			LCDWriteInst(0x10);
+
+			break;
+		}
 
 
 	case LCD_Disp_Left:
@@ -208,294 +217,330 @@ static int lcd_ioctl(struct inode *inode
 		LCDWriteInst(0x02);
 		break;
 
-	case LCD_Write: {
-		struct lcd_display display;
-   
+	case LCD_Write:{
+			struct lcd_display display;
+
+
+			if (copy_from_user
+			    (&display, (struct lcd_display *) arg,
+			     sizeof(struct lcd_display)))
+				return -EFAULT;
 
-                if(copy_from_user(&display, (struct lcd_display*)arg, sizeof(struct lcd_display)))
-		  return -EFAULT;
- 
-		udelay(150);
-                BusyCheck();    
-                LCDWriteInst(0x80);
-		udelay(150);
-		BusyCheck();
-	
-		for (index = 0; index < (display.size1); index++) {
 			udelay(150);
-			BusyCheck();	
-			LCDWriteData( display.line1[index]);
-			BusyCheck();	
-		}		
-		
-		udelay(150);
-		BusyCheck();	
-		LCDWriteInst(0xC0);	
-		udelay(150);
-		BusyCheck();	
-                for (index = 0; index < (display.size2); index++) {
-                        udelay(150);
-                        BusyCheck();    
-                        LCDWriteData( display.line2[index]);
-		}
- 
-		break;	
-	}
-	
-	case LCD_Read: {	
-        	struct lcd_display display;
+			BusyCheck();
+			LCDWriteInst(0x80);
+			udelay(150);
+			BusyCheck();
 
-		BusyCheck();
-		for (address = kDD_R00; address <= kDD_R01; address++) {
-			a = (address | kLCD_Addr );	
+			for (index = 0; index < (display.size1); index++) {
+				udelay(150);
+				BusyCheck();
+				LCDWriteData(display.line1[index]);
+				BusyCheck();
+			}
 
 			udelay(150);
 			BusyCheck();
-			LCDWriteInst( a );
+			LCDWriteInst(0xC0);
 			udelay(150);
 			BusyCheck();
-			display.line1[address] = LCDReadData;
+			for (index = 0; index < (display.size2); index++) {
+				udelay(150);
+				BusyCheck();
+				LCDWriteData(display.line2[index]);
+			}
+
+			break;
 		}
 
-		display.line1[ 0x27 ] = '\0';
-	
-		for (address = kDD_R10; address <= kDD_R11; address++) {
-			a = (address | kLCD_Addr );     
-        
-			udelay(150);
-	 		BusyCheck();
-        		LCDWriteInst( a );
-       
-        		udelay(150);
-	 		BusyCheck();
-        		display.line2[address - 0x40 ] = LCDReadData;
-		 }
-
-		display.line2[ 0x27 ] = '\0';
-
-		if(copy_to_user((struct lcd_display*)arg, &display,
-				sizeof(struct lcd_display)))
-		  return -EFAULT;
-		break;
-	}
+	case LCD_Read:{
+			struct lcd_display display;
+
+			BusyCheck();
+			for (address = kDD_R00; address <= kDD_R01;
+			     address++) {
+				a = (address | kLCD_Addr);
+
+				udelay(150);
+				BusyCheck();
+				LCDWriteInst(a);
+				udelay(150);
+				BusyCheck();
+				display.line1[address] = LCDReadData;
+			}
 
-//  set all GPIO leds to led_display.leds 
+			display.line1[0x27] = '\0';
 
-	case LED_Set: {	
-		struct lcd_display led_display;
-	
+			for (address = kDD_R10; address <= kDD_R11;
+			     address++) {
+				a = (address | kLCD_Addr);
+
+				udelay(150);
+				BusyCheck();
+				LCDWriteInst(a);
+
+				udelay(150);
+				BusyCheck();
+				display.line2[address - 0x40] =
+				    LCDReadData;
+			}
+
+			display.line2[0x27] = '\0';
 
-	        if(copy_from_user(&led_display, (struct lcd_display*)arg,
-				  sizeof(struct lcd_display)))
-		  return -EFAULT;
+			if (copy_to_user
+			    ((struct lcd_display *) arg, &display,
+			     sizeof(struct lcd_display)))
+				return -EFAULT;
+			break;
+		}
 
-		led_state = led_display.leds;
-		LEDSet(led_state);
+//  set all GPIO leds to led_display.leds
 
-        	break;
-	}
+	case LED_Set:{
+			struct lcd_display led_display;
+
+
+			if (copy_from_user
+			    (&led_display, (struct lcd_display *) arg,
+			     sizeof(struct lcd_display)))
+				return -EFAULT;
+
+			led_state = led_display.leds;
+			LEDSet(led_state);
+
+			break;
+		}
 
 
 //  set only bit led_display.leds
 
-        case LED_Bit_Set: {
-                int i;
-		int bit=1;
-                struct lcd_display led_display;
+	case LED_Bit_Set:{
+			int i;
+			int bit = 1;
+			struct lcd_display led_display;
 
 
-                if(copy_from_user(&led_display, (struct lcd_display*)arg,
-				  sizeof(struct lcd_display)))
-		  return -EFAULT;
+			if (copy_from_user
+			    (&led_display, (struct lcd_display *) arg,
+			     sizeof(struct lcd_display)))
+				return -EFAULT;
 
-		for (i=0;i<(int)led_display.leds;i++)
-			{
-				bit = 2*bit;	
+			for (i = 0; i < (int) led_display.leds; i++) {
+				bit = 2 * bit;
 			}
 
-		led_state = led_state | bit;
-                LEDSet(led_state);
-                break;
-        }
+			led_state = led_state | bit;
+			LEDSet(led_state);
+			break;
+		}
 
 //  clear only bit led_display.leds
 
-        case LED_Bit_Clear: {
-                int i;
-		int bit=1;
-                struct lcd_display led_display;
-
-
-                if(copy_from_user(&led_display, (struct lcd_display*)arg,
-				  sizeof(struct lcd_display)))
-		  return -EFAULT;
-
-                for (i=0;i<(int)led_display.leds;i++)
-                        {
-                                bit = 2*bit;
-                        }
-
-		led_state = led_state &  ~bit;
-                LEDSet(led_state);
-                break;
-        }
-
-
-	case BUTTON_Read: {
-		button_display.buttons = GPIRead;
-                if(copy_to_user((struct lcd_display*)arg, &button_display, sizeof(struct lcd_display)))
-		  return -EFAULT;
-		break;
-	}
+	case LED_Bit_Clear:{
+			int i;
+			int bit = 1;
+			struct lcd_display led_display;
 
-        case LINK_Check: {
-                button_display.buttons = *((volatile unsigned long *) (0xB0100060) );
-                if(copy_to_user((struct lcd_display*)arg, &button_display, sizeof(struct lcd_display)))
-		  return -EFAULT;
-                break;
-        }
-
-	case LINK_Check_2: {
-		int iface_num;
-
-		/* panel-utils should pass in the desired interface status is wanted for
-		 * in "buttons" of the structure.  We will set this to non-zero if the
-		 * link is in fact up for the requested interface.  --DaveM
-		 */
-		if(copy_from_user(&button_display, (struct lcd_display *)arg, sizeof(button_display)))
-		  return -EFAULT;
-		iface_num = button_display.buttons;
-#if defined(CONFIG_TULIP) && 0
-		if (iface_num >= 0 &&
-		    iface_num < MAX_INTERFACES &&
-		    linkcheck_callbacks[iface_num] != NULL) {
-			button_display.buttons =
-				linkcheck_callbacks[iface_num](linkcheck_cookies[iface_num]);
-		} else
-#endif
-			button_display.buttons = 0;
-
-                if(__copy_to_user((struct lcd_display*)arg, &button_display, sizeof(struct lcd_display)))
-		  return -EFAULT;
-                break;
-	}
 
-//  Erase the flash
+			if (copy_from_user
+			    (&led_display, (struct lcd_display *) arg,
+			     sizeof(struct lcd_display)))
+				return -EFAULT;
 
-	case FLASH_Erase: {
+			for (i = 0; i < (int) led_display.leds; i++) {
+				bit = 2 * bit;
+			}
 
-		int ctr=0;
+			led_state = led_state & ~bit;
+			LEDSet(led_state);
+			break;
+		}
 
-		    // Chip Erase Sequence
-		WRITE_FLASH( kFlash_Addr1, kFlash_Data1 );
-		WRITE_FLASH( kFlash_Addr2, kFlash_Data2 );
-		WRITE_FLASH( kFlash_Addr1, kFlash_Erase3 );
-		WRITE_FLASH( kFlash_Addr1, kFlash_Data1 );
-		WRITE_FLASH( kFlash_Addr2, kFlash_Data2 );
-		WRITE_FLASH( kFlash_Addr1, kFlash_Erase6 );
 
-		printk( "Erasing Flash.\n");
+	case BUTTON_Read:{
+			button_display.buttons = GPIRead;
+			if (copy_to_user
+			    ((struct lcd_display *) arg, &button_display,
+			     sizeof(struct lcd_display)))
+				return -EFAULT;
+			break;
+		}
 
-		while ( (!dqpoll(0x00000000,0xFF)) && (!timeout(0x00000000)) ) {
-		    ctr++;
+	case LINK_Check:{
+			button_display.buttons =
+			    *((volatile unsigned long *) (0xB0100060));
+			if (copy_to_user
+			    ((struct lcd_display *) arg, &button_display,
+			     sizeof(struct lcd_display)))
+				return -EFAULT;
+			break;
 		}
 
-		printk("\n");
-		printk("\n");
-		printk("\n");
+	case LINK_Check_2:{
+			int iface_num;
 
-		if (READ_FLASH(0x07FFF0)==0xFF) { printk("Erase Successful\r\n"); }
-		else if (timeout) { printk("Erase Timed Out\r\n"); }
+			/* panel-utils should pass in the desired interface status is wanted for
+			 * in "buttons" of the structure.  We will set this to non-zero if the
+			 * link is in fact up for the requested interface.  --DaveM
+			 */
+			if (copy_from_user
+			    (&button_display, (struct lcd_display *) arg,
+			     sizeof(button_display)))
+				return -EFAULT;
+			iface_num = button_display.buttons;
+#if defined(CONFIG_TULIP) && 0
+			if (iface_num >= 0 &&
+			    iface_num < MAX_INTERFACES &&
+			    linkcheck_callbacks[iface_num] != NULL) {
+				button_display.buttons =
+				    linkcheck_callbacks[iface_num]
+				    (linkcheck_cookies[iface_num]);
+			} else
+#endif
+				button_display.buttons = 0;
 
-	break;
-	}
+			if (__copy_to_user
+			    ((struct lcd_display *) arg, &button_display,
+			     sizeof(struct lcd_display)))
+				return -EFAULT;
+			break;
+		}
 
-// burn the flash 
+//  Erase the flash
 
-	case FLASH_Burn: {
+	case FLASH_Erase:{
 
-		volatile unsigned long burn_addr;
-		unsigned long flags;
-		int i;
-		unsigned char *rom;
-		
-
-                struct lcd_display display;
-
-                if(copy_from_user(&display, (struct lcd_display*)arg, sizeof(struct lcd_display)))
-		  return -EFAULT;
-		rom = (unsigned char *) kmalloc((128),GFP_ATOMIC);
-                if ( rom == NULL ) {
-                       printk ("broken\n");
-                       return 1;
-                   }
-
-		printk("Churning and Burning -");
-		save_flags(flags);
-		for (i=0; i<FLASH_SIZE; i=i+128) {
-
-		        if(copy_from_user(rom, display.RomImage + i, 128))
-			   return -EFAULT;
-			burn_addr = kFlashBase + i;
-			cli();
-			for ( index = 0; index < ( 128 ) ; index++ ) 
-		  	  {
-
-				WRITE_FLASH( kFlash_Addr1, kFlash_Data1 );
-		 	    	WRITE_FLASH( kFlash_Addr2, kFlash_Data2 );
-		 	    	WRITE_FLASH( kFlash_Addr1, kFlash_Prog );
-		 	    	*((volatile unsigned char *)burn_addr) = (volatile unsigned char) rom[index];
-
-		   	 	 while ( (!dqpoll(burn_addr,(volatile unsigned char) rom[index])) && (!timeout(burn_addr)) ) {
-		  	   		}
-		  	   	burn_addr++;
-		  	  }
-			restore_flags(flags);
-                	if ( *((volatile unsigned char *)(burn_addr-1)) == (volatile unsigned char) rom[index-1]  ) {
-               		 } else if (timeout) {
-                	    printk("Program timed out\r\n");
-               		 }
+			int ctr = 0;
 
+			// Chip Erase Sequence
+			WRITE_FLASH(kFlash_Addr1, kFlash_Data1);
+			WRITE_FLASH(kFlash_Addr2, kFlash_Data2);
+			WRITE_FLASH(kFlash_Addr1, kFlash_Erase3);
+			WRITE_FLASH(kFlash_Addr1, kFlash_Data1);
+			WRITE_FLASH(kFlash_Addr2, kFlash_Data2);
+			WRITE_FLASH(kFlash_Addr1, kFlash_Erase6);
+
+			printk("Erasing Flash.\n");
+
+			while ((!dqpoll(0x00000000, 0xFF))
+			       && (!timeout(0x00000000))) {
+				ctr++;
+			}
+
+			printk("\n");
+			printk("\n");
+			printk("\n");
+
+			if (READ_FLASH(0x07FFF0) == 0xFF) {
+				printk("Erase Successful\r\n");
+			} else if (timeout) {
+				printk("Erase Timed Out\r\n");
+			}
 
+			break;
 		}
-		kfree(rom);
 
-	break;
-	}
+// burn the flash
 
-//  read the flash all at once 
-	
-	case FLASH_Read: {
+	case FLASH_Burn:{
 
-		unsigned char *user_bytes;
-                volatile unsigned long read_addr;
-                int i;
+			volatile unsigned long burn_addr;
+			unsigned long flags;
+			int i;
+			unsigned char *rom;
+
+
+			struct lcd_display display;
+
+			if (copy_from_user
+			    (&display, (struct lcd_display *) arg,
+			     sizeof(struct lcd_display)))
+				return -EFAULT;
+			rom = (unsigned char *) kmalloc((128), GFP_ATOMIC);
+			if (rom == NULL) {
+				printk("broken\n");
+				return 1;
+			}
 
-		user_bytes = &(((struct lcd_display *)arg)->RomImage[0]);
+			printk("Churning and Burning -");
+			save_flags(flags);
+			for (i = 0; i < FLASH_SIZE; i = i + 128) {
+
+				if (copy_from_user
+				    (rom, display.RomImage + i, 128))
+					return -EFAULT;
+				burn_addr = kFlashBase + i;
+				cli();
+				for (index = 0; index < (128); index++) {
+
+					WRITE_FLASH(kFlash_Addr1,
+						    kFlash_Data1);
+					WRITE_FLASH(kFlash_Addr2,
+						    kFlash_Data2);
+					WRITE_FLASH(kFlash_Addr1,
+						    kFlash_Prog);
+					*((volatile unsigned char *)
+					  burn_addr) =
+		 (volatile unsigned char) rom[index];
+
+					while ((!dqpoll
+						(burn_addr,
+						 (volatile unsigned char)
+						 rom[index]))
+					       && (!timeout(burn_addr))) {
+					}
+					burn_addr++;
+				}
+				restore_flags(flags);
+				if (*
+				    ((volatile unsigned char *) (burn_addr
+								 - 1)) ==
+				    (volatile unsigned char) rom[index -
+								 1]) {
+				} else if (timeout) {
+					printk("Program timed out\r\n");
+				}
 
-		if(!access_ok(VERIFY_WRITE, user_bytes, FLASH_SIZE))
-                         return -EFAULT;
 
-		printk("Reading Flash");
-		for (i=0; i<FLASH_SIZE; i++) {
-			unsigned char tmp_byte;
-			read_addr = kFlashBase + i;
-			tmp_byte = *((volatile unsigned char *)read_addr);
-			if(__put_user (tmp_byte, &user_bytes[i]))
-			  return -EFAULT;
-		}
+			}
+			kfree(rom);
 
+			break;
+		}
 
-	break;
-	}
+//  read the flash all at once
 
+	case FLASH_Read:{
 
+			unsigned char *user_bytes;
+			volatile unsigned long read_addr;
+			int i;
+
+			user_bytes =
+			    &(((struct lcd_display *) arg)->RomImage[0]);
+
+			if (!access_ok
+			    (VERIFY_WRITE, user_bytes, FLASH_SIZE))
+				return -EFAULT;
+
+			printk("Reading Flash");
+			for (i = 0; i < FLASH_SIZE; i++) {
+				unsigned char tmp_byte;
+				read_addr = kFlashBase + i;
+				tmp_byte =
+				    *((volatile unsigned char *)
+				      read_addr);
+				if (__put_user(tmp_byte, &user_bytes[i]))
+					return -EFAULT;
+			}
 
 
+			break;
+		}
 
 	default:
 		return 0;
-	break;
+		break;
 
 	}
 
@@ -517,7 +562,8 @@ static inline int button_pressed(void)
 {
 	unsigned long buttons = GPIRead;
 
-	if ( (buttons == BUTTON_Next) || (buttons == BUTTON_Next_B) || (buttons == BUTTON_Reset_B) )
+	if ((buttons == BUTTON_Next) || (buttons == BUTTON_Next_B)
+	    || (buttons == BUTTON_Reset_B))
 		return buttons;
 	return 0;
 }
@@ -526,22 +572,23 @@ static inline int button_pressed(void)
 
 static int lcd_waiters = 0;
 
-static long lcd_read(struct inode *inode, struct file *file, char *buf, unsigned long count)
+static long lcd_read(struct inode *inode, struct file *file, char *buf,
+		     unsigned long count)
 {
 	long buttons_now;
 
-	if(lcd_waiters > 0)
+	if (lcd_waiters > 0)
 		return -EINVAL;
 
 	lcd_waiters++;
-	while(((buttons_now = (long)button_pressed()) == 0) &&
-	      !(signal_pending(current))) {
+	while (((buttons_now = (long) button_pressed()) == 0) &&
+	       !(signal_pending(current))) {
 		current->state = TASK_INTERRUPTIBLE;
 		schedule_timeout(2 * HZ);
 	}
 	lcd_waiters--;
 
-	if(signal_pending(current))
+	if (signal_pending(current))
 		return -ERESTARTSYS;
 	return buttons_now;
 }
@@ -551,21 +598,20 @@ static long lcd_read(struct inode *inode
  */
 
 static struct file_operations lcd_fops = {
-	.read		= lcd_read,
-	.ioctl		= lcd_ioctl,
-	.open		= lcd_open,
+	.read = lcd_read,
+	.ioctl = lcd_ioctl,
+	.open = lcd_open,
 };
 
-static struct miscdevice lcd_dev=
-{
-	LCD_MINOR,
+static struct miscdevice lcd_dev = {
+	MISC_DYNAMIC_MINOR,
 	"lcd",
 	&lcd_fops
 };
 
-int lcd_init(void)
+static int lcd_init(void)
 {
-unsigned long data;
+	unsigned long data;
 
 	printk("%s\n", LCD_DRIVER);
 	misc_register(&lcd_dev);
@@ -575,19 +621,22 @@ unsigned long data;
 
 	udelay(150);
 	data = LCDReadData;
-	if ( (data & 0x000000FF) == (0x00) ) {
+	if ((data & 0x000000FF) == (0x00)) {
 		lcd_present = 0;
 		printk("LCD Not Present\n");
-	        }
-	else {
+	} else {
 		lcd_present = 1;
-		WRITE_GAL( kGal_DevBank2PReg, kGal_DevBank2Cfg );
-		WRITE_GAL( kGal_DevBank3PReg, kGal_DevBank3Cfg );
-		}
+		WRITE_GAL(kGal_DevBank2PReg, kGal_DevBank2Cfg);
+		WRITE_GAL(kGal_DevBank3PReg, kGal_DevBank3Cfg);
+	}
 
 	return 0;
 }
 
+static void __exit lcd_exit(void)
+{
+	misc_deregister(&lcd_dev);
+}
 
 //
 // Function: dqpoll
@@ -600,17 +649,15 @@ unsigned long data;
 //
 //
 
-int dqpoll( volatile unsigned long address, volatile unsigned char data ) {
-
-volatile unsigned char dq7;
-
-dq7 = data & 0x80;
+static int dqpoll(volatile unsigned long address, volatile unsigned char data)
+{
+	volatile unsigned char dq7;
 
-return ( (READ_FLASH(address) & 0x80) == dq7  );
+	dq7 = data & 0x80;
 
+	return ((READ_FLASH(address) & 0x80) == dq7);
 }
 
-
 //
 // Function: timeout
 //
@@ -622,12 +669,13 @@ return ( (READ_FLASH(address) & 0x80) ==
 //
 // Out: 0 = not timed out, 1 = timed out
 
-int timeout( volatile unsigned long address ) {
-
-
-return (  (READ_FLASH(address) & 0x20) ==  0x20 );
-
+static int timeout(volatile unsigned long address)
+{
+	return (READ_FLASH(address) & 0x20) == 0x20;
 }
 
+module_init(lcd_init);
+module_exit(lcd_exit);
 
-
+MODULE_AUTHOR("Andrew Bose");
+MODULE_LICENSE("GPL");
diff -puN /dev/null drivers/char/lcd.h
--- /dev/null	2003-09-15 06:40:47.000000000 -0700
+++ 25-akpm/drivers/char/lcd.h	2004-06-19 14:25:04.710824288 -0700
@@ -0,0 +1,184 @@
+/*
+ * LED, LCD and Button panel driver for Cobalt
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ *
+ * Copyright (C) 1996, 1997 by Andrew Bose
+ *
+ * Linux kernel version history:
+ *       March 2001: Ported from 2.0.34  by Liam Davies
+ *
+ */
+
+// function headers
+
+static int dqpoll(volatile unsigned long, volatile unsigned char );
+static int timeout(volatile unsigned long);
+
+#define LCD_CHARS_PER_LINE 40
+#define FLASH_SIZE 524288
+#define MAX_IDLE_TIME 120
+
+struct lcd_display {
+        unsigned long buttons;
+        int size1;
+        int size2;
+        unsigned char line1[LCD_CHARS_PER_LINE];
+        unsigned char line2[LCD_CHARS_PER_LINE];
+        unsigned char cursor_address;
+        unsigned char character;
+        unsigned char leds;
+        unsigned char *RomImage;
+};
+
+
+
+#define LCD_DRIVER	"Cobalt LCD Driver v2.10"
+
+#define kLCD_IR		0x0F000000
+#define kLCD_DR		0x0F000010
+#define kGPI		0x0D000000
+#define kLED		0x0C000000
+
+#define kDD_R00         0x00
+#define kDD_R01         0x27
+#define kDD_R10         0x40
+#define kDD_R11         0x67
+
+#define kLCD_Addr       0x00000080
+
+#define LCDTimeoutValue	0xfff
+
+
+// Flash definitions AMD 29F040
+#define kFlashBase	0x0FC00000
+
+#define kFlash_Addr1    0x5555
+#define kFlash_Addr2    0x2AAA
+#define kFlash_Data1    0xAA
+#define kFlash_Data2    0x55
+#define kFlash_Prog     0xA0
+#define kFlash_Erase3   0x80
+#define kFlash_Erase6   0x10
+#define kFlash_Read     0xF0
+
+#define kFlash_ID       0x90
+#define kFlash_VenAddr  0x00
+#define kFlash_DevAddr  0x01
+#define kFlash_VenID    0x01
+#define kFlash_DevID    0xA4    // 29F040
+//#define kFlash_DevID  0xAD    // 29F016
+
+
+// Macros
+
+#define LCDWriteData(x)	outl((x << 24), kLCD_DR)
+#define LCDWriteInst(x)	outl((x << 24), kLCD_IR)
+
+#define LCDReadData	(inl(kLCD_DR) >> 24)
+#define LCDReadInst	(inl(kLCD_IR) >> 24)
+
+#define GPIRead		(inl(kGPI) >> 24)
+
+#define LEDSet(x)	outb((char)x, kLED)
+
+#define WRITE_GAL(x,y)	outl(y, 0x04000000 | (x))
+#define BusyCheck()	while ((LCDReadInst & 0x80) == 0x80)
+
+#define WRITE_FLASH(x,y) outb((char)y, kFlashBase | (x))
+#define READ_FLASH(x)	(inb(kFlashBase | (x)))
+
+
+
+/*
+ * Function command codes for io_ctl.
+ */
+#define LCD_On			1
+#define LCD_Off			2
+#define LCD_Clear		3
+#define LCD_Reset		4
+#define LCD_Cursor_Left		5
+#define LCD_Cursor_Right	6
+#define LCD_Disp_Left		7
+#define LCD_Disp_Right		8
+#define LCD_Get_Cursor		9
+#define LCD_Set_Cursor		10
+#define LCD_Home		11
+#define LCD_Read		12
+#define LCD_Write		13
+#define LCD_Cursor_Off		14
+#define LCD_Cursor_On		15
+#define LCD_Get_Cursor_Pos	16
+#define LCD_Set_Cursor_Pos	17
+#define LCD_Blink_Off           18
+
+#define LED_Set			40
+#define LED_Bit_Set		41
+#define LED_Bit_Clear		42
+
+
+//  Button defs
+#define BUTTON_Read             50
+
+//  Flash command codes
+#define FLASH_Erase		60
+#define FLASH_Burn		61
+#define FLASH_Read		62
+
+
+// Ethernet LINK check hackaroo
+#define LINK_Check              90
+#define LINK_Check_2		91
+
+//  Button patterns  _B - single layer lcd boards
+
+#define BUTTON_NONE               0x3F
+#define BUTTON_NONE_B             0xFE
+
+#define BUTTON_Left               0x3B
+#define BUTTON_Left_B             0xFA
+
+#define BUTTON_Right              0x37
+#define BUTTON_Right_B            0xDE
+
+#define BUTTON_Up                 0x2F
+#define BUTTON_Up_B               0xF6
+
+#define BUTTON_Down               0x1F
+#define BUTTON_Down_B             0xEE
+
+#define BUTTON_Next               0x3D
+#define BUTTON_Next_B             0x7E
+
+#define BUTTON_Enter              0x3E
+#define BUTTON_Enter_B            0xBE
+
+#define BUTTON_Reset_B            0xFC
+
+
+// debounce constants
+
+#define BUTTON_SENSE            160000
+#define BUTTON_DEBOUNCE		5000
+
+
+//  Galileo register stuff
+
+#define kGal_DevBank2Cfg        0x1466DB33
+#define kGal_DevBank2PReg       0x464
+#define kGal_DevBank3Cfg        0x146FDFFB
+#define kGal_DevBank3PReg       0x468
+
+// Network
+
+#define kIPADDR			1
+#define kNETMASK		2
+#define kGATEWAY		3
+#define kDNS			4
+
+#define kClassA			5
+#define kClassB			6
+#define kClassC			7
+
diff -puN drivers/char/Makefile~cobalt-lcd-driver-update drivers/char/Makefile
--- 25/drivers/char/Makefile~cobalt-lcd-driver-update	2004-06-19 14:25:04.695826568 -0700
+++ 25-akpm/drivers/char/Makefile	2004-06-19 14:25:04.705825048 -0700
@@ -68,6 +68,7 @@ obj-$(CONFIG_DS1620) += ds1620.o
 obj-$(CONFIG_HW_RANDOM) += hw_random.o
 obj-$(CONFIG_QIC02_TAPE) += tpqic02.o
 obj-$(CONFIG_FTAPE) += ftape/
+obj-$(CONFIG_COBALT_LCD) += lcd.o
 obj-$(CONFIG_H8) += h8.o
 obj-$(CONFIG_PPDEV) += ppdev.o
 obj-$(CONFIG_NWBUTTON) += nwbutton.o
_
