# HG changeset patch # User Paul Boddie # Date 1453665875 -3600 # Node ID 5d76620989dfa217d0beadac50295ddb869dfc99 # Parent d9c40f84d6b62344223fa8d09d5f193d0c82c08b Tidied up, eliminating duplicated code, making functions static. diff -r d9c40f84d6b6 -r 5d76620989df stage2/jzlcd.c --- a/stage2/jzlcd.c Sun Jan 24 14:39:27 2016 +0100 +++ b/stage2/jzlcd.c Sun Jan 24 21:04:35 2016 +0100 @@ -2,7 +2,7 @@ * JzRISC LCD controller * * Copyright (C) Xiangfu Liu - * Copyright (C) 2015 Paul Boddie + * Copyright (C) 2015, 2016 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -35,33 +35,29 @@ extern struct jzfb_info jzfb; extern vidinfo_t panel_info; -unsigned long lcd_get_size(void) +static unsigned long lcd_get_size(vidinfo_t *vid) { - int line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8; - return line_length * panel_info.vl_row; + int line_length = (vid->vl_col * NBITS(vid->vl_bpix)) / 8; + return line_length * vid->vl_row; } -unsigned long lcd_setmem(unsigned long addr) +static unsigned long lcd_get_total_size(vidinfo_t *vid) { - unsigned long size; - - size = lcd_get_size(); - /* Round up to nearest full page, or MMU section if defined */ - size = ALIGN(size, PAGE_SIZE); - addr = ALIGN(addr - PAGE_SIZE + 1, PAGE_SIZE); + return ALIGN(lcd_get_size(vid), PAGE_SIZE); +} +static unsigned long lcd_setmem(unsigned long addr) +{ /* Allocate pages for the frame buffer. */ - addr -= size; - - return addr; + return ALIGN(addr - PAGE_SIZE + 1, PAGE_SIZE) - lcd_get_total_size(&panel_info); } static int jz_lcd_init_mem(void *lcdbase, vidinfo_t *vid); static void jz_lcd_desc_init(vidinfo_t *vid); static int jz_lcd_hw_init(vidinfo_t *vid); -void lcd_ctrl_init (void **lcdbase) +void lcd_ctrl_init(void **lcdbase) { /* Start from the top of memory and obtain a framebuffer region. */ *lcdbase = (void *) lcd_setmem(get_memory_size()); @@ -72,25 +68,24 @@ } /* - * Before enabled lcd controller, lcd registers should be configured correctly. + * Before enabling the LCD controller, LCD registers should be configured correctly. */ -void lcd_enable (void) +void lcd_enable(void) { REG_LCD_CTRL &= ~(1<<4); /* LCDCTRL.DIS */ REG_LCD_CTRL |= 1<<3; /* LCDCTRL.ENA*/ } -void lcd_disable (void) +void lcd_disable(void) { REG_LCD_CTRL |= (1<<4); /* LCDCTRL.DIS, regular disable */ - /* REG_LCD_CTRL |= (1<<3); */ /* LCDCTRL.DIS, quickly disable */ } static int jz_lcd_init_mem(void *lcdbase, vidinfo_t *vid) { unsigned long palette_mem_size; struct jz_fb_info *fbi = &vid->jz_fb; - int fb_size = vid->vl_row * (vid->vl_col * NBITS (vid->vl_bpix)) / 8; + int fb_size = lcd_get_size(vid); fbi->screen = (unsigned long)lcdbase; fbi->palette_size = 256; @@ -110,19 +105,17 @@ fbi->dmadesc_fbhigh = (struct jz_fb_dma_descriptor *)((unsigned int)fbi->palette - 2*16); fbi->dmadesc_palette = (struct jz_fb_dma_descriptor *)((unsigned int)fbi->palette - 1*16); - #define BYTES_PER_PANEL (vid->vl_col * vid->vl_row * NBITS(vid->vl_bpix) / 8) - /* populate descriptors */ fbi->dmadesc_fblow->fdadr = virt_to_phys(fbi->dmadesc_fblow); - fbi->dmadesc_fblow->fsadr = virt_to_phys((void *)(fbi->screen + BYTES_PER_PANEL)); + fbi->dmadesc_fblow->fsadr = virt_to_phys((void *)(fbi->screen + lcd_get_size(vid))); fbi->dmadesc_fblow->fidr = 0; - fbi->dmadesc_fblow->ldcmd = BYTES_PER_PANEL / 4 ; + fbi->dmadesc_fblow->ldcmd = lcd_get_size(vid) / 4 ; fbi->fdadr1 = virt_to_phys(fbi->dmadesc_fblow); /* only used in dual-panel mode */ fbi->dmadesc_fbhigh->fsadr = virt_to_phys((void *)fbi->screen); fbi->dmadesc_fbhigh->fidr = 0; - fbi->dmadesc_fbhigh->ldcmd = BYTES_PER_PANEL / 4; /* length in word */ + fbi->dmadesc_fbhigh->ldcmd = lcd_get_size(vid) / 4; /* length in word */ fbi->dmadesc_palette->fsadr = virt_to_phys((void *)fbi->palette); fbi->dmadesc_palette->fidr = 0; diff -r d9c40f84d6b6 -r 5d76620989df stage2/jzlcd.h --- a/stage2/jzlcd.h Sun Jan 24 14:39:27 2016 +0100 +++ b/stage2/jzlcd.h Sun Jan 24 21:04:35 2016 +0100 @@ -4,7 +4,7 @@ * Copyright (C) 2001 Wolfgang Denk, DENX Software Engineering, wd@denx.de. * Copyright (C) 2005-2007, Ingenic Semiconductor Inc. * Copyright (C) Xiangfu Liu - * Copyright (C) 2015 Paul Boddie + * Copyright (C) 2015, 2016 Paul Boddie * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -25,7 +25,6 @@ #ifndef __JZLCD_H__ #define __JZLCD_H__ -unsigned long lcd_get_size(void); void lcd_ctrl_init(void **lcdbase); void lcd_enable(void); void lcd_disable(void); @@ -69,6 +68,7 @@ struct jz_fb_dma_descriptor *dmadesc_fblow; struct jz_fb_dma_descriptor *dmadesc_fbhigh; struct jz_fb_dma_descriptor *dmadesc_palette; + unsigned long screen; /* address of frame buffer */ unsigned long palette; /* address of palette memory */ unsigned int palette_size;