--- kernel-source-rx-34-2.6.21.0-osso63/drivers/video/omap/lcd_mipid.c	2008-01-04 16:51:43.000000000 +0100
+++ kernel-source-rx-34-2.6.21.0-osso63.my/drivers/video/omap/lcd_mipid.c	2007-12-25 22:45:09.000000000 +0100
@@ -50,6 +50,13 @@
 
 #define to_mipid_device(p)		container_of(p, struct mipid_device, \
 						panel)
+#define	BACKLIGHT_USE_TABLE
+
+#ifdef	BACKLIGHT_USE_TABLE
+static unsigned char bklight_table[] = {3,25,50,76,101,127};
+#define BACKLIGHT_TABLE_SIZE	6
+#endif
+
 struct mipid_device {
 	int		enabled;
 	int		model;
@@ -72,6 +79,12 @@
 
 	void			(*shutdown)(struct mipid_platform_data *pdata);
 	struct mipid_platform_data *pdata;
+#ifdef	BACKLIGHT_USE_TABLE
+	unsigned char	bklight_table_src[BACKLIGHT_TABLE_SIZE];
+	unsigned char	bklight_table_dst[BACKLIGHT_TABLE_SIZE];
+	signed int	orig_bklight_level; // signed because we use -1 as uninitialized value and we need 0-127
+	unsigned char	ignore_other_levels;
+#endif
 };
 
 static void mipid_transfer(struct mipid_device *md, int cmd, const u8 *wbuf,
@@ -221,8 +234,70 @@
 {
 	struct mipid_device *md = to_mipid_device(panel);
 
+#ifndef	BACKLIGHT_USE_TABLE
 	if (level > tahvo_get_max_backlight_level())
 		return -EINVAL;
+#else
+	int prevlevel=md->orig_bklight_level; // remember for code below
+	int i,nearestidx=0;
+	if (level > tahvo_get_max_backlight_level()){
+	/*
+	values greater than valid maximum will change translation table
+	to map srclevel to dstlevel value 0x80|srclevel + (dstlevel<<8) needs to be written
+	if srclevel is 0, current active level is changed
+	if highest bit is set (0x8000) the code will try to kill fading effect = values not in table
+	will be ignored or rounded to nearest table value to avoid jumps in brightness level
+	*/
+	unsigned int srclevel,dstlevel;
+	//level -= 0x80; //1 + tahvo_get_max_backlight_level();
+	md->ignore_other_levels = ((level&0x8000) != 0);
+	level&=0x7FFF;
+	srclevel = level & 0x7F;
+	dstlevel = (level >> 8);
+	if (dstlevel > tahvo_get_max_backlight_level())
+		return -EINVAL;
+	if (srclevel == 0)
+		srclevel = md->orig_bklight_level; /* zero means change current level */
+// srclevel is used as table index, not direct value to remap
+// remove those 5 lines below to use it as direct value
+	else {
+		if (srclevel>BACKLIGHT_TABLE_SIZE)
+			return -EINVAL;
+		srclevel=md->bklight_table_src[srclevel-1];	
+	}
+//
+	for (i=0;i<BACKLIGHT_TABLE_SIZE;i++){
+		if (srclevel == md->bklight_table_src[i]){
+			/* OK, found matching src level, set destination */
+			md->bklight_table_dst[i] = dstlevel;
+			break;
+		}
+	}
+	if (srclevel != md->orig_bklight_level)
+		return 0; /* not current level */
+		
+	/* we are changing current active level, continue */	
+	level = srclevel;	
+	} else
+		md->orig_bklight_level = level;
+	/* try to translate level */
+	for (i=0;i<BACKLIGHT_TABLE_SIZE;i++){
+		if (level == md->bklight_table_src[i]){
+			level = md->bklight_table_dst[i];
+			break;
+		} else	// doesn not match, remember nearest
+			if (level>md->bklight_table_src[i]) nearestidx=i;
+	}
+	if (level && md->ignore_other_levels && i==BACKLIGHT_TABLE_SIZE) {
+		// not zero, not found in table, try to kill fading effect
+		//return 0; // simply ignore
+		// skip directly to nearest in table
+		if (level>prevlevel) // increase ?
+			level=md->bklight_table_dst[nearestidx+1];
+		else	
+			level=md->bklight_table_dst[nearestidx];
+	}
+#endif
 	if (!md->enabled) {
 		md->saved_bklight_level = level;
 		return 0;
@@ -234,7 +309,15 @@
 
 static unsigned int mipid_get_bklight_level(struct lcd_panel *panel)
 {
+#ifdef	BACKLIGHT_USE_TABLE
+	struct mipid_device *md = to_mipid_device(panel);
+	if (md->orig_bklight_level>=0)
+		return md->orig_bklight_level; // ok, orig value initialized, return it
+	else
+		return (md->orig_bklight_level=tahvo_get_backlight_level()); // read real value and initialize orig_bklight_level
+#else
 	return tahvo_get_backlight_level();
+#endif
 }
 
 static unsigned int mipid_get_bklight_max(struct lcd_panel *panel)
@@ -466,6 +549,12 @@
 	struct mipid_device *md = to_mipid_device(panel);
 
 	md->fbdev = fbdev;
+#ifdef	BACKLIGHT_USE_TABLE
+	/* initialize translation table */
+	memcpy(md->bklight_table_src,bklight_table,BACKLIGHT_TABLE_SIZE);
+	memcpy(md->bklight_table_dst,bklight_table,BACKLIGHT_TABLE_SIZE);
+	md->orig_bklight_level=-1;
+#endif
 	md->esd_wq = create_singlethread_workqueue("mipid_esd");
 	if (md->esd_wq == NULL) {
 		dev_err(&md->spi->dev, "can't create ESD workqueue\n");
