From 73ae6aecc083f7721cda97072372b2e531fa2072 Mon Sep 17 00:00:00 2001
From: Andreas Baierl <ichgeh@imkreisrum.de>
Date: Tue, 26 May 2015 09:18:46 -0400
Subject: [PATCH 1/5] arm:sunxi:disp: Fix division by zero

---
 drivers/video/sunxi/disp/disp_video.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/video/sunxi/disp/disp_video.c b/drivers/video/sunxi/disp/disp_video.c
index aa07364..765f6ec 100644
--- a/drivers/video/sunxi/disp/disp_video.c
+++ b/drivers/video/sunxi/disp/disp_video.c
@@ -71,10 +71,14 @@ static __s32 video_enhancement_start(__u32 sel, __u32 id)
 	/* !!! assume open HDMI before video start */
 	if (gdisp.screen[sel].output_type == DISP_OUTPUT_TYPE_HDMI) {
 		scaler_index = gdisp.screen[sel].layer_manage[id].scaler_index;
-		scaleuprate =
-			gdisp.screen[sel].layer_manage[id].para.scn_win.width *
-			2 /
-			gdisp.screen[sel].layer_manage[id].para.src_win.width;
+
+		if ((gdisp.screen[sel].layer_manage[id].para.scn_win.width ==
+		     gdisp.screen[sel].layer_manage[id].para.src_win.width) ||
+		    (gdisp.screen[sel].layer_manage[id].para.src_win.width < 1280))
+			scaleuprate = 0;
+		else
+			scaleuprate = gdisp.screen[sel].layer_manage[id].para.scn_win.width * 2 /
+			              gdisp.screen[sel].layer_manage[id].para.src_win.width;
 
 		switch (scaleuprate) {
 		case 0:	/* scale down, do noting */

From 7a3d2d463f562d725fc20c6133ed9ea6fea83fe0 Mon Sep 17 00:00:00 2001
From: Andreas Baierl <ichgeh@imkreisrum.de>
Date: Tue, 26 May 2015 09:20:10 -0400
Subject: [PATCH 2/5] arm:sunxi:g2d: Fix: handle noop blits

Zero area blits are technically valid noops and are requested by
libvdpau. Return 0 when blit area is zero without performing bogus
calculations.
---
 drivers/char/sunxi_g2d/g2d.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/drivers/char/sunxi_g2d/g2d.c b/drivers/char/sunxi_g2d/g2d.c
index 07d1425..02bc83c 100644
--- a/drivers/char/sunxi_g2d/g2d.c
+++ b/drivers/char/sunxi_g2d/g2d.c
@@ -156,6 +156,11 @@ int g2d_blit(g2d_blt * para)
 	}
 	else
 	{
+		if((para->src_rect.w == 0) || (para->src_rect.h == 0))
+		{
+			printk(KERN_DEBUG "User requested g2d blit on zero region\n");
+			return err;
+		}
 		if(((para->src_rect.x < 0)&&((-para->src_rect.x) < para->src_rect.w)))
 		{
 			para->src_rect.w = para->src_rect.w + para->src_rect.x;
@@ -218,6 +223,11 @@ int g2d_fill(g2d_fillrect * para)
 	}
 	else
 	{
+		if((para->dst_rect.w == 0) || (para->dst_rect.h == 0))
+		{
+			printk(KERN_DEBUG "User requested g2d fill on zero region\n");
+			return err;
+		}
 		if(((para->dst_rect.x < 0)&&((-para->dst_rect.x) < para->dst_rect.w)))
 		{
 			para->dst_rect.w = para->dst_rect.w + para->dst_rect.x;
@@ -263,6 +273,12 @@ int g2d_stretchblit(g2d_stretchblt * para)
 	}
 	else
 	{
+		if((para->dst_rect.w == 0) || (para->dst_rect.h == 0) ||
+		   (para->src_rect.w == 0) || (para->src_rect.h == 0))
+		{
+			printk(KERN_DEBUG "User requested g2d stretchblit on zero region\n");
+			return err;
+		}
 		if(((para->src_rect.x < 0)&&((-para->src_rect.x) < para->src_rect.w)))
 		{
 			para->src_rect.w = para->src_rect.w + para->src_rect.x;

From 3e42686a882e928518f13271f2469f6463c62930 Mon Sep 17 00:00:00 2001
From: Andreas Baierl <ichgeh@imkreisrum.de>
Date: Tue, 26 May 2015 09:23:00 -0400
Subject: [PATCH 3/5] arm:sunxi:disp: Fix csc calculations.

---
 drivers/video/sunxi/disp/de_fe.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/video/sunxi/disp/de_fe.c b/drivers/video/sunxi/disp/de_fe.c
index 92799a0..54dfe7f 100644
--- a/drivers/video/sunxi/disp/de_fe.c
+++ b/drivers/video/sunxi/disp/de_fe.c
@@ -1382,10 +1382,10 @@ __s32 DE_SCAL_Set_CSC_Coef_Enhance(__u8 sel, __u8 in_csc_mode,
 	__u32 i;
 	__s32 sinv, cosv; /* sin_tab: 7 bit fractional */
 
-	bright = bright * 64 / 100;
-	bright = saturation * 64 / 100;
-	bright = contrast * 64 / 100;
-	bright = hue * 64 / 100;
+	bright = DIV_ROUND_CLOSEST((clamp(bright, 0, 100) * 63), 100);
+	saturation = DIV_ROUND_CLOSEST((clamp(saturation, 0, 100) * 63), 100);
+	contrast = DIV_ROUND_CLOSEST((clamp(contrast, 0, 100) * 63), 100);
+	hue = DIV_ROUND_CLOSEST((clamp(hue, 0, 100) * 63), 100);
 
 	sinv = image_enhance_tab[8 * 12 + (hue & 0x3f)];
 	cosv = image_enhance_tab[8 * 12 + 8 * 8 + (hue & 0x3f)];

From b44b695723f7aa091688336e570639b548c5aa95 Mon Sep 17 00:00:00 2001
From: Andreas Baierl <ichgeh@imkreisrum.de>
Date: Tue, 26 May 2015 09:23:51 -0400
Subject: [PATCH 4/5] arm:sunxi:disp: Fix typo in get_src_window

---
 drivers/video/sunxi/disp/disp_layer.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/video/sunxi/disp/disp_layer.c b/drivers/video/sunxi/disp/disp_layer.c
index c5100e8..831f814 100644
--- a/drivers/video/sunxi/disp/disp_layer.c
+++ b/drivers/video/sunxi/disp/disp_layer.c
@@ -563,8 +563,8 @@ __s32 BSP_disp_layer_get_src_window(__u32 sel, __u32 hid, __disp_rect_t *regn)
 		} else {
 			regn->x = layer_man->para.src_win.x;
 			regn->y = layer_man->para.src_win.y;
-			regn->width = layer_man->para.scn_win.width;
-			regn->height = layer_man->para.scn_win.height;
+			regn->width = layer_man->para.src_win.width;
+			regn->height = layer_man->para.src_win.height;
 			return 0;
 		}
 	} else {

From 7bbe0f91d85d07f51dc81aa2a3984618cce13f25 Mon Sep 17 00:00:00 2001
From: Andreas Baierl <ichgeh@imkreisrum.de>
Date: Tue, 26 May 2015 09:36:32 -0400
Subject: [PATCH 5/5] arm:sunxi:ir: Enable IR autorepeat

---
 drivers/input/keyboard/sunxi-ir.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/input/keyboard/sunxi-ir.c b/drivers/input/keyboard/sunxi-ir.c
index 8b3c5f3e..ebc2a253 100644
--- a/drivers/input/keyboard/sunxi-ir.c
+++ b/drivers/input/keyboard/sunxi-ir.c
@@ -114,6 +114,7 @@ static u32 ir_gpio_hdle;
 #define IR_REPEAT_CODE	(0x00000000)
 #define DRV_VERSION	"1.00"
 
+#define REPORT_REPEAT_KEY_VALUE
 
 #ifdef CONFIG_HAS_EARLYSUSPEND
 struct sunxi_ir_data {
