# HG changeset patch # User Paul Boddie # Date 1453679212 -3600 # Node ID 1c164ef8cb38165bc6f69d1758559d7cbdd0608c # Parent d2f7bb50475c3cbe7ee6be432e23e27467fd2c08 Tidied up the memory allocation of the palette and framebuffer regions. diff -r d2f7bb50475c -r 1c164ef8cb38 stage2/jzlcd.c --- a/stage2/jzlcd.c Mon Jan 25 00:28:55 2016 +0100 +++ b/stage2/jzlcd.c Mon Jan 25 00:46:52 2016 +0100 @@ -41,30 +41,56 @@ return line_length * vid->vl_row; } +static unsigned long lcd_get_palette_size(vidinfo_t *vid) +{ + return 256 * sizeof(u16); +} + +static unsigned long lcd_get_aligned_size(vidinfo_t *vid) +{ + return ALIGN(lcd_get_size(vid), PAGE_SIZE); +} + +static unsigned long lcd_get_aligned_palette_size(vidinfo_t *vid) +{ + return ALIGN(lcd_get_palette_size(vid), PAGE_SIZE); +} + static unsigned long lcd_get_total_size(vidinfo_t *vid) { /* Round up to nearest full page, or MMU section if defined */ - return ALIGN(lcd_get_size(vid), PAGE_SIZE); + return lcd_get_aligned_size(vid) + lcd_get_aligned_palette_size(vid); } -static unsigned long lcd_setmem(unsigned long addr) +static unsigned long lcd_get_palette(unsigned long addr) { - /* Allocate pages for the frame buffer. */ - return ALIGN(addr - PAGE_SIZE + 1, PAGE_SIZE) - lcd_get_total_size(&panel_info); + /* Allocate memory at the end of a page for the palette. */ + return addr - lcd_get_palette_size(&panel_info); } -static int jz_lcd_init_mem(unsigned long lcdbase, vidinfo_t *vid); +static unsigned long lcd_get_framebuffer(unsigned long addr) +{ + /* Allocate pages for the frame buffer and palette. */ + return addr - lcd_get_total_size(&panel_info); +} + static void jz_lcd_desc_init(vidinfo_t *vid); static int jz_lcd_hw_init(vidinfo_t *vid); -void lcd_ctrl_init(unsigned long *lcdbase) +unsigned long lcd_ctrl_init() { - /* Start from the top of memory and obtain a framebuffer region. */ - *lcdbase = lcd_setmem(get_memory_size()); + struct jz_fb_info *fbi = &panel_info.jz_fb; + + /* Start from the top of memory and obtain palette and framebuffer regions. */ - jz_lcd_init_mem(*lcdbase, &panel_info); + fbi->screen = lcd_get_framebuffer(get_memory_size()); + fbi->palette = lcd_get_palette(get_memory_size()); + fbi->palette_size = 256; + jz_lcd_desc_init(&panel_info); jz_lcd_hw_init(&panel_info); + + return fbi->screen; } /* @@ -81,22 +107,6 @@ REG_LCD_CTRL |= (1<<4); /* LCDCTRL.DIS, regular disable */ } -static int jz_lcd_init_mem(unsigned long lcdbase, vidinfo_t *vid) -{ - unsigned long palette_mem_size; - struct jz_fb_info *fbi = &vid->jz_fb; - unsigned long fb_size = lcd_get_size(vid); - - fbi->screen = lcdbase; - fbi->palette_size = 256; - palette_mem_size = fbi->palette_size * sizeof(u16); - - /* locate palette and descs at end of page following fb */ - fbi->palette = lcdbase + fb_size + PAGE_SIZE - palette_mem_size; - - return 0; -} - static void jz_lcd_desc_init(vidinfo_t *vid) { struct jz_fb_dma_descriptor *descriptors; diff -r d2f7bb50475c -r 1c164ef8cb38 stage2/jzlcd.h --- a/stage2/jzlcd.h Mon Jan 25 00:28:55 2016 +0100 +++ b/stage2/jzlcd.h Mon Jan 25 00:46:52 2016 +0100 @@ -25,7 +25,7 @@ #ifndef __JZLCD_H__ #define __JZLCD_H__ -void lcd_ctrl_init(unsigned long *lcdbase); +unsigned long lcd_ctrl_init(); void lcd_enable(void); void lcd_disable(void); diff -r d2f7bb50475c -r 1c164ef8cb38 stage2/lcd.c --- a/stage2/lcd.c Mon Jan 25 00:28:55 2016 +0100 +++ b/stage2/lcd.c Mon Jan 25 00:46:52 2016 +0100 @@ -88,7 +88,7 @@ } } -void lcd_clear(void *lcd_base) +void lcd_clear(unsigned long lcd_base) { unsigned short v_max = panel_info.vl_row; unsigned short h_max = panel_info.vl_col; @@ -109,7 +109,7 @@ __lcd_display_pin_init(); __lcd_display_on(); - lcd_ctrl_init(&lcd_base); + lcd_base = lcd_ctrl_init(); lcd_clear(lcd_base); lcd_enable(); }