s5pc110: fb: possible memory leak (un-free'd malloc)
[kernel/u-boot.git] / drivers / video / s5p-fb.c
index 3e220e9..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));
@@ -90,18 +92,11 @@ static void read_image32(char* pImg, int x1pos, int y1pos, int x2pos,
                }
        }
 }
+#endif
 
 /* LCD Panel data */
 vidinfo_t panel_info;
 
-struct lcd_panel_operation {
-       void (*lcd_panel_init)(void);
-       void (*lcd_panel_power_on)(void);
-       void (*lcd_panel_enable)(void);
-};
-
-static struct lcd_panel_operation lcd_calls;
-
 static void s5pc_lcd_init_mem(void *lcdbase, vidinfo_t *vid)
 {
        unsigned long palette_size, palette_mem_size;
@@ -120,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)
 {
@@ -212,134 +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) >> 1);
-       y = ((panel_height - 78) >> 1) - 5;
-
-       _draw_samsung_logo(lcdbase, x, y, 298, 78, (unsigned short *) logo);
-}
-
-static void s5pc_init_panel_info(vidinfo_t *vid, struct lcd_panel_operation *calls)
-{
-       if (vid == NULL) {
-               printf("lcd info is NULL.\n");
+       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 (calls == NULL) {
-               printf("lcd calls is NULL.\n");
+       if (gunzip(dst, in_len, (uchar *)logo, &out_len) != 0) {
+               free(dst);
                return;
        }
-#if 1
-       vid->vl_freq    = 60;
-       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 */
-
-       calls->lcd_panel_init = s6e63m0_lcd_panel_init;
-       calls->lcd_panel_power_on = s6e63m0_lcd_panel_power_on;
-       calls->lcd_panel_enable = s6e63m0_lcd_panel_enable;
-#endif
-#if 0
-       vid->vl_freq    = 60;
-       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,
-
-       calls->lcd_panel_init = /* */;
-       calls->lcd_panel_power_on = /* */;
-       calls->lcd_panel_enable = /* */;
-#endif
-#if 0
-       vid->vl_freq    = 60;
-       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,
-
-       calls->lcd_panel_init = ams701ka_lcd_panel_init;
-       calls->lcd_panel_power_on = ams701ka_lcd_panel_power_on;
-       calls->lcd_panel_enable = ams701ka_lcd_panel_enable;
-#endif
-
-       panel_width = vid->vl_col;
-       panel_height = vid->vl_row;
+       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 lcd_panel_on(struct lcd_panel_operation *calls)
+static void lcd_panel_on(vidinfo_t *vid)
 {
-       if (calls == NULL) {
-               printf("lcd calls is NULL.\n");
-               return ;
-       }
+       udelay(vid->init_delay);
+
+       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();
+
+
+       if (vid->enable_ldo)
+               vid->enable_ldo(1);
 
-       if (calls->lcd_panel_init)
-               calls->lcd_panel_init();
-       if (calls->lcd_panel_power_on)
-               calls->lcd_panel_power_on();
-       if (calls->lcd_panel_enable)
-               calls->lcd_panel_enable();
 }
 
+/* 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, &lcd_calls);
+       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 {
@@ -351,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 */
@@ -362,6 +302,8 @@ void lcd_ctrl_init(void *lcdbase)
        fb_printf("Test\n");
        exit_font();
        */
+
+       /* init_onenand_ext2(); */
 }
 
 
@@ -372,7 +314,7 @@ void lcd_setcolreg(ushort regno, ushort red, ushort green, ushort blud)
 
 void lcd_enable(void)
 {
-       lcd_panel_on((struct lcd_panel_operation *) &lcd_calls);
+       lcd_panel_on(&panel_info);
 }
 
 ulong calc_fbsize(void)