s5pc110: fb: possible memory leak (un-free'd malloc)
[kernel/u-boot.git] / drivers / video / s5p-fb.c
index ab3206a..3e90e21 100644 (file)
@@ -27,6 +27,7 @@
 #include <asm/io.h>
 #include <asm/arch/cpu.h>
 #include <lcd.h>
+#include <malloc.h>
 
 #include "s5p-fb.h"
 #include "logo.h"
@@ -51,6 +52,7 @@ short console_row;
 
 static unsigned int panel_width, panel_height;
 
+#ifdef USE_LCD_TEST
 static unsigned short makepixel565(char r, char g, char b)
 {
     return (unsigned short)(((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3));
@@ -83,28 +85,24 @@ static void read_image32(char* pImg, int x1pos, int y1pos, int x2pos,
        unsigned int offset_s;
        int i, j;
 
-       for(i = y1pos; i < y2pos; i++) {
-               for(j = x1pos; j < x2pos; j++) {
+       for (i = y1pos; i < y2pos; i++) {
+               for (j = x1pos; j < x2pos; j++) {
                        offset_s = i * panel_width + j;
                        *(pDst+offset_s) = pixel;
                }
        }
 }
+#endif
 
 /* LCD Panel data */
-vidinfo_t panel_info = {
-               .vl_lbw         = 0,
-               .vl_splt        = 0,
-               .vl_clor        = 1,
-               .vl_tft         = 1,
-};
+vidinfo_t panel_info;
 
 static void s5pc_lcd_init_mem(void *lcdbase, vidinfo_t *vid)
 {
        unsigned long palette_size, palette_mem_size;
        unsigned int fb_size;
 
-       fb_size = vid->vl_row * vid->vl_col * (vid->vl_bpix / 8);
+       fb_size = vid->vl_row * vid->vl_col * (vid->vl_bpix >> 3);
 
        lcd_base = lcdbase;
 
@@ -117,34 +115,27 @@ static void s5pc_lcd_init_mem(void *lcdbase, vidinfo_t *vid)
                        fb_size, (unsigned int)lcd_base, (int)palette_size, (int)palette_mem_size);
 }
 
-static void s5pc_gpio_setup(void)
-{
-       if (cpu_is_s5pc100())
-               s5pc_c100_gpio_setup();
-       else
-               s5pc_c110_gpio_setup();
-}
-
 static void s5pc_lcd_init(vidinfo_t *vid)
 {
        s5pc_fimd_lcd_init(vid);
 }
 
-static void lcd_test(void)
+#ifdef USE_LCD_TEST
+static void lcd_test(unsigned int width, unsigned int height)
 {
+       unsigned int height_level = height / 3;
+
        /* red */
-       read_image32((char *)lcd_base, 0, 0, 480, 200,
+       read_image32((char *)lcd_base, 0, 0, width, height_level,
                        makepixel8888(0, 255, 0, 0));
        /* green */
-       read_image32((char *)lcd_base, 0, 200, 480, 400,
-                       makepixel8888(0, 0, 255, 0));
+       read_image32((char *)lcd_base, 0, height_level, width,
+               height_level * 2, makepixel8888(0, 0, 255, 0));
        /* blue */
-       read_image32((char *)lcd_base, 0, 400, 480, 600,
+       read_image32((char *)lcd_base, 0, height_level * 2, width, height,
                        makepixel8888(0, 0, 0, 255));
-       /* write */
-       read_image32((char *)lcd_base, 0, 600, 480, 800,
-                       makepixel8888(0, 255, 255, 255));
 }
+#endif
 
 int conv_rgb565_to_rgb888(unsigned short rgb565, unsigned int sw)
 {
@@ -209,103 +200,88 @@ void _draw_samsung_logo(void *lcdbase, int x, int y, int w, int h, unsigned shor
 static void draw_samsung_logo(void* lcdbase)
 {
        int x, y;
-
-       x = (panel_width - 298) / 2;
-       y = (panel_height - 78) / 2 - 5;
-
-       _draw_samsung_logo(lcdbase, x, y, 298, 78, (unsigned short *) logo);
+       unsigned int in_len, width, height;
+       unsigned long out_len;
+       void *dst = NULL;
+       width = 298;
+       height = 78;
+       x = ((panel_width - width) >> 1);
+       y = ((panel_height - height) >> 1) - 5;
+
+       in_len = width * height * 4;
+       dst = malloc(in_len);
+       if (dst == NULL) {
+               printf("Error: malloc in gunzip failed!\n");
+               return;
+       }
+       if (gunzip(dst, in_len, (uchar *)logo, &out_len) != 0) {
+               free(dst);
+               return;
+       }
+       if (out_len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)
+               printf("Image could be truncated"
+                               " (increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
+       _draw_samsung_logo(lcdbase, x, y, width, height, (unsigned short *) dst);
+       free(dst);
 }
 
-static void s5pc_init_panel_info(vidinfo_t *vid)
+static void lcd_panel_on(vidinfo_t *vid)
 {
-#if 1
-       vid->vl_col     = 480,
-       vid->vl_row     = 800,
-       vid->vl_width   = 480,
-       vid->vl_height  = 800,
-       vid->vl_clkp    = CONFIG_SYS_HIGH,
-       vid->vl_hsp     = CONFIG_SYS_LOW,
-       vid->vl_vsp     = CONFIG_SYS_LOW,
-       vid->vl_dp      = CONFIG_SYS_HIGH,
-       vid->vl_bpix    = 32,
-
-       /* S6E63M0 LCD Panel */
-       vid->vl_hpw     = 2,    /* HLW */
-       vid->vl_blw     = 16,   /* HBP */
-       vid->vl_elw     = 16,   /* HFP */
-
-       vid->vl_vpw     = 2,    /* VLW */
-       vid->vl_bfw     = 3,    /* VBP */
-       vid->vl_efw     = 28,   /* VFP */
-#endif
-#if 0
-       vid->vl_col     = 480,
-       vid->vl_row     = 800,
-       vid->vl_width   = 480,
-       vid->vl_height  = 800,
-       vid->vl_clkp    = CONFIG_SYS_HIGH,
-       vid->vl_hsp     = CONFIG_SYS_LOW,
-       vid->vl_vsp     = CONFIG_SYS_LOW,
-       vid->vl_dp      = CONFIG_SYS_HIGH,
-       vid->vl_bpix    = 32,
-
-       /* tl2796 panel. */
-       vid->vl_hpw     = 4,
-       vid->vl_blw     = 8,
-       vid->vl_elw     = 8,
-
-       vid->vl_vpw     = 4,
-       vid->vl_bfw     = 8,
-       vid->vl_efw     = 8,
-#endif
-#if 0
-       vid->vl_col     = 1024,
-       vid->vl_row     = 600,
-       vid->vl_width   = 1024,
-       vid->vl_height  = 600,
-       vid->vl_clkp    = CONFIG_SYS_HIGH,
-       vid->vl_hsp     = CONFIG_SYS_HIGH,
-       vid->vl_vsp     = CONFIG_SYS_HIGH,
-       vid->vl_dp      = CONFIG_SYS_LOW,
-       vid->vl_bpix    = 32,
-
-       /* AMS701KA AMOLED Panel. */
-       vid->vl_hpw     = 30,
-       vid->vl_blw     = 114,
-       vid->vl_elw     = 48,
-
-       vid->vl_vpw     = 2,
-       vid->vl_bfw     = 6,
-       vid->vl_efw     = 8,
-#endif
+       udelay(vid->init_delay);
 
-       panel_width = vid->vl_col;
-       panel_height = vid->vl_row;
-}
+       if (vid->cfg_gpio)
+               vid->cfg_gpio();
+
+       if (vid->lcd_power_on)
+               vid->lcd_power_on(1);
+
+       udelay(vid->power_on_delay);
+
+       if (vid->reset_lcd)
+               vid->reset_lcd();
+
+       udelay(vid->reset_delay);
+
+       if (vid->backlight_on)
+               vid->backlight_on(1);
+
+
+       if (vid->cfg_ldo)
+               vid->cfg_ldo();
 
-static void lcd_panel_on(void)
-{
-       lcd_panel_init();
-       lcd_panel_power_on();
 
-       lcd_panel_enable();
+       if (vid->enable_ldo)
+               vid->enable_ldo(1);
+
 }
 
+/* extern void init_onenand_ext2(void); */
+extern void init_panel_info(vidinfo_t *vid);
+extern int s5p_no_lcd_support(void);
+
 void lcd_ctrl_init(void *lcdbase)
 {
        char *option;
 
+       if (s5p_no_lcd_support())
+               return;
+
        s5pc_lcd_init_mem(lcdbase, &panel_info);
 
        /* initialize parameters which is specific to panel. */
-       s5pc_init_panel_info(&panel_info);
+       init_panel_info(&panel_info);
+
+       panel_width = panel_info.vl_width;
+       panel_height = panel_info.vl_height;
 
        option = getenv("lcd");
 
        /*
        if (strcmp(option, "test") == 0) {
                memset(lcdbase, 0, PANEL_WIDTH*PANEL_HEIGHT*S5P_LCD_BPP >> 3);
-               lcd_test();
+#ifdef USE_LCD_TEST
+               lcd_test(panel_width, panel_height);
+#endif
        } else if (strcmp(option, "image") == 0)
                memcpy(lcdbase, LOGO_RGB24, PANEL_WIDTH*PANEL_HEIGHT*S5P_LCD_BPP >> 3);
        else {
@@ -317,8 +293,6 @@ void lcd_ctrl_init(void *lcdbase)
        memset(lcdbase, 0, panel_width * panel_height * (32 >> 3));
        draw_samsung_logo(lcdbase);
 
-       s5pc_gpio_setup();
-
        s5pc_lcd_init(&panel_info);
 
        /* font test */
@@ -328,6 +302,8 @@ void lcd_ctrl_init(void *lcdbase)
        fb_printf("Test\n");
        exit_font();
        */
+
+       /* init_onenand_ext2(); */
 }
 
 
@@ -338,7 +314,7 @@ void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blud)
 
 void lcd_enable(void)
 {
-       lcd_panel_on();
+       lcd_panel_on(&panel_info);
 }
 
 ulong calc_fbsize(void)