1.1 --- a/stage2/jzlcd.c Mon Jan 25 00:28:55 2016 +0100
1.2 +++ b/stage2/jzlcd.c Mon Jan 25 00:46:52 2016 +0100
1.3 @@ -41,30 +41,56 @@
1.4 return line_length * vid->vl_row;
1.5 }
1.6
1.7 +static unsigned long lcd_get_palette_size(vidinfo_t *vid)
1.8 +{
1.9 + return 256 * sizeof(u16);
1.10 +}
1.11 +
1.12 +static unsigned long lcd_get_aligned_size(vidinfo_t *vid)
1.13 +{
1.14 + return ALIGN(lcd_get_size(vid), PAGE_SIZE);
1.15 +}
1.16 +
1.17 +static unsigned long lcd_get_aligned_palette_size(vidinfo_t *vid)
1.18 +{
1.19 + return ALIGN(lcd_get_palette_size(vid), PAGE_SIZE);
1.20 +}
1.21 +
1.22 static unsigned long lcd_get_total_size(vidinfo_t *vid)
1.23 {
1.24 /* Round up to nearest full page, or MMU section if defined */
1.25 - return ALIGN(lcd_get_size(vid), PAGE_SIZE);
1.26 + return lcd_get_aligned_size(vid) + lcd_get_aligned_palette_size(vid);
1.27 }
1.28
1.29 -static unsigned long lcd_setmem(unsigned long addr)
1.30 +static unsigned long lcd_get_palette(unsigned long addr)
1.31 {
1.32 - /* Allocate pages for the frame buffer. */
1.33 - return ALIGN(addr - PAGE_SIZE + 1, PAGE_SIZE) - lcd_get_total_size(&panel_info);
1.34 + /* Allocate memory at the end of a page for the palette. */
1.35 + return addr - lcd_get_palette_size(&panel_info);
1.36 }
1.37
1.38 -static int jz_lcd_init_mem(unsigned long lcdbase, vidinfo_t *vid);
1.39 +static unsigned long lcd_get_framebuffer(unsigned long addr)
1.40 +{
1.41 + /* Allocate pages for the frame buffer and palette. */
1.42 + return addr - lcd_get_total_size(&panel_info);
1.43 +}
1.44 +
1.45 static void jz_lcd_desc_init(vidinfo_t *vid);
1.46 static int jz_lcd_hw_init(vidinfo_t *vid);
1.47
1.48 -void lcd_ctrl_init(unsigned long *lcdbase)
1.49 +unsigned long lcd_ctrl_init()
1.50 {
1.51 - /* Start from the top of memory and obtain a framebuffer region. */
1.52 - *lcdbase = lcd_setmem(get_memory_size());
1.53 + struct jz_fb_info *fbi = &panel_info.jz_fb;
1.54 +
1.55 + /* Start from the top of memory and obtain palette and framebuffer regions. */
1.56
1.57 - jz_lcd_init_mem(*lcdbase, &panel_info);
1.58 + fbi->screen = lcd_get_framebuffer(get_memory_size());
1.59 + fbi->palette = lcd_get_palette(get_memory_size());
1.60 + fbi->palette_size = 256;
1.61 +
1.62 jz_lcd_desc_init(&panel_info);
1.63 jz_lcd_hw_init(&panel_info);
1.64 +
1.65 + return fbi->screen;
1.66 }
1.67
1.68 /*
1.69 @@ -81,22 +107,6 @@
1.70 REG_LCD_CTRL |= (1<<4); /* LCDCTRL.DIS, regular disable */
1.71 }
1.72
1.73 -static int jz_lcd_init_mem(unsigned long lcdbase, vidinfo_t *vid)
1.74 -{
1.75 - unsigned long palette_mem_size;
1.76 - struct jz_fb_info *fbi = &vid->jz_fb;
1.77 - unsigned long fb_size = lcd_get_size(vid);
1.78 -
1.79 - fbi->screen = lcdbase;
1.80 - fbi->palette_size = 256;
1.81 - palette_mem_size = fbi->palette_size * sizeof(u16);
1.82 -
1.83 - /* locate palette and descs at end of page following fb */
1.84 - fbi->palette = lcdbase + fb_size + PAGE_SIZE - palette_mem_size;
1.85 -
1.86 - return 0;
1.87 -}
1.88 -
1.89 static void jz_lcd_desc_init(vidinfo_t *vid)
1.90 {
1.91 struct jz_fb_dma_descriptor *descriptors;
2.1 --- a/stage2/jzlcd.h Mon Jan 25 00:28:55 2016 +0100
2.2 +++ b/stage2/jzlcd.h Mon Jan 25 00:46:52 2016 +0100
2.3 @@ -25,7 +25,7 @@
2.4 #ifndef __JZLCD_H__
2.5 #define __JZLCD_H__
2.6
2.7 -void lcd_ctrl_init(unsigned long *lcdbase);
2.8 +unsigned long lcd_ctrl_init();
2.9 void lcd_enable(void);
2.10 void lcd_disable(void);
2.11
3.1 --- a/stage2/lcd.c Mon Jan 25 00:28:55 2016 +0100
3.2 +++ b/stage2/lcd.c Mon Jan 25 00:46:52 2016 +0100
3.3 @@ -88,7 +88,7 @@
3.4 }
3.5 }
3.6
3.7 -void lcd_clear(void *lcd_base)
3.8 +void lcd_clear(unsigned long lcd_base)
3.9 {
3.10 unsigned short v_max = panel_info.vl_row;
3.11 unsigned short h_max = panel_info.vl_col;
3.12 @@ -109,7 +109,7 @@
3.13 __lcd_display_pin_init();
3.14 __lcd_display_on();
3.15
3.16 - lcd_ctrl_init(&lcd_base);
3.17 + lcd_base = lcd_ctrl_init();
3.18 lcd_clear(lcd_base);
3.19 lcd_enable();
3.20 }