1.1 --- a/stage2/jzlcd.c Sun Jan 24 14:39:27 2016 +0100
1.2 +++ b/stage2/jzlcd.c Sun Jan 24 21:04:35 2016 +0100
1.3 @@ -2,7 +2,7 @@
1.4 * JzRISC LCD controller
1.5 *
1.6 * Copyright (C) Xiangfu Liu <xiangfu@sharism.cc>
1.7 - * Copyright (C) 2015 Paul Boddie <paul@boddie.org.uk>
1.8 + * Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk>
1.9 *
1.10 * This program is free software; you can redistribute it and/or
1.11 * modify it under the terms of the GNU General Public License as
1.12 @@ -35,33 +35,29 @@
1.13 extern struct jzfb_info jzfb;
1.14 extern vidinfo_t panel_info;
1.15
1.16 -unsigned long lcd_get_size(void)
1.17 +static unsigned long lcd_get_size(vidinfo_t *vid)
1.18 {
1.19 - int line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8;
1.20 - return line_length * panel_info.vl_row;
1.21 + int line_length = (vid->vl_col * NBITS(vid->vl_bpix)) / 8;
1.22 + return line_length * vid->vl_row;
1.23 }
1.24
1.25 -unsigned long lcd_setmem(unsigned long addr)
1.26 +static unsigned long lcd_get_total_size(vidinfo_t *vid)
1.27 {
1.28 - unsigned long size;
1.29 -
1.30 - size = lcd_get_size();
1.31 -
1.32 /* Round up to nearest full page, or MMU section if defined */
1.33 - size = ALIGN(size, PAGE_SIZE);
1.34 - addr = ALIGN(addr - PAGE_SIZE + 1, PAGE_SIZE);
1.35 + return ALIGN(lcd_get_size(vid), PAGE_SIZE);
1.36 +}
1.37
1.38 +static unsigned long lcd_setmem(unsigned long addr)
1.39 +{
1.40 /* Allocate pages for the frame buffer. */
1.41 - addr -= size;
1.42 -
1.43 - return addr;
1.44 + return ALIGN(addr - PAGE_SIZE + 1, PAGE_SIZE) - lcd_get_total_size(&panel_info);
1.45 }
1.46
1.47 static int jz_lcd_init_mem(void *lcdbase, vidinfo_t *vid);
1.48 static void jz_lcd_desc_init(vidinfo_t *vid);
1.49 static int jz_lcd_hw_init(vidinfo_t *vid);
1.50
1.51 -void lcd_ctrl_init (void **lcdbase)
1.52 +void lcd_ctrl_init(void **lcdbase)
1.53 {
1.54 /* Start from the top of memory and obtain a framebuffer region. */
1.55 *lcdbase = (void *) lcd_setmem(get_memory_size());
1.56 @@ -72,25 +68,24 @@
1.57 }
1.58
1.59 /*
1.60 - * Before enabled lcd controller, lcd registers should be configured correctly.
1.61 + * Before enabling the LCD controller, LCD registers should be configured correctly.
1.62 */
1.63 -void lcd_enable (void)
1.64 +void lcd_enable(void)
1.65 {
1.66 REG_LCD_CTRL &= ~(1<<4); /* LCDCTRL.DIS */
1.67 REG_LCD_CTRL |= 1<<3; /* LCDCTRL.ENA*/
1.68 }
1.69
1.70 -void lcd_disable (void)
1.71 +void lcd_disable(void)
1.72 {
1.73 REG_LCD_CTRL |= (1<<4); /* LCDCTRL.DIS, regular disable */
1.74 - /* REG_LCD_CTRL |= (1<<3); */ /* LCDCTRL.DIS, quickly disable */
1.75 }
1.76
1.77 static int jz_lcd_init_mem(void *lcdbase, vidinfo_t *vid)
1.78 {
1.79 unsigned long palette_mem_size;
1.80 struct jz_fb_info *fbi = &vid->jz_fb;
1.81 - int fb_size = vid->vl_row * (vid->vl_col * NBITS (vid->vl_bpix)) / 8;
1.82 + int fb_size = lcd_get_size(vid);
1.83
1.84 fbi->screen = (unsigned long)lcdbase;
1.85 fbi->palette_size = 256;
1.86 @@ -110,19 +105,17 @@
1.87 fbi->dmadesc_fbhigh = (struct jz_fb_dma_descriptor *)((unsigned int)fbi->palette - 2*16);
1.88 fbi->dmadesc_palette = (struct jz_fb_dma_descriptor *)((unsigned int)fbi->palette - 1*16);
1.89
1.90 - #define BYTES_PER_PANEL (vid->vl_col * vid->vl_row * NBITS(vid->vl_bpix) / 8)
1.91 -
1.92 /* populate descriptors */
1.93 fbi->dmadesc_fblow->fdadr = virt_to_phys(fbi->dmadesc_fblow);
1.94 - fbi->dmadesc_fblow->fsadr = virt_to_phys((void *)(fbi->screen + BYTES_PER_PANEL));
1.95 + fbi->dmadesc_fblow->fsadr = virt_to_phys((void *)(fbi->screen + lcd_get_size(vid)));
1.96 fbi->dmadesc_fblow->fidr = 0;
1.97 - fbi->dmadesc_fblow->ldcmd = BYTES_PER_PANEL / 4 ;
1.98 + fbi->dmadesc_fblow->ldcmd = lcd_get_size(vid) / 4 ;
1.99
1.100 fbi->fdadr1 = virt_to_phys(fbi->dmadesc_fblow); /* only used in dual-panel mode */
1.101
1.102 fbi->dmadesc_fbhigh->fsadr = virt_to_phys((void *)fbi->screen);
1.103 fbi->dmadesc_fbhigh->fidr = 0;
1.104 - fbi->dmadesc_fbhigh->ldcmd = BYTES_PER_PANEL / 4; /* length in word */
1.105 + fbi->dmadesc_fbhigh->ldcmd = lcd_get_size(vid) / 4; /* length in word */
1.106
1.107 fbi->dmadesc_palette->fsadr = virt_to_phys((void *)fbi->palette);
1.108 fbi->dmadesc_palette->fidr = 0;
2.1 --- a/stage2/jzlcd.h Sun Jan 24 14:39:27 2016 +0100
2.2 +++ b/stage2/jzlcd.h Sun Jan 24 21:04:35 2016 +0100
2.3 @@ -4,7 +4,7 @@
2.4 * Copyright (C) 2001 Wolfgang Denk, DENX Software Engineering, wd@denx.de.
2.5 * Copyright (C) 2005-2007, Ingenic Semiconductor Inc.
2.6 * Copyright (C) Xiangfu Liu <xiangfu@sharism.cc>
2.7 - * Copyright (C) 2015 Paul Boddie <paul@boddie.org.uk>
2.8 + * Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk>
2.9 *
2.10 * This program is free software; you can redistribute it and/or
2.11 * modify it under the terms of the GNU General Public License as
2.12 @@ -25,7 +25,6 @@
2.13 #ifndef __JZLCD_H__
2.14 #define __JZLCD_H__
2.15
2.16 -unsigned long lcd_get_size(void);
2.17 void lcd_ctrl_init(void **lcdbase);
2.18 void lcd_enable(void);
2.19 void lcd_disable(void);
2.20 @@ -69,6 +68,7 @@
2.21 struct jz_fb_dma_descriptor *dmadesc_fblow;
2.22 struct jz_fb_dma_descriptor *dmadesc_fbhigh;
2.23 struct jz_fb_dma_descriptor *dmadesc_palette;
2.24 +
2.25 unsigned long screen; /* address of frame buffer */
2.26 unsigned long palette; /* address of palette memory */
2.27 unsigned int palette_size;