# HG changeset patch # User Paul Boddie # Date 1499540818 -7200 # Node ID b4dcc2099e0fcdd01df46b17abad2cd91ad23861 # Parent a6159a6780029090d8f30703b8510c772b963980 Eliminate redundant members in vidinfo_t, adding a member referencing the framebuffer details, and changing the descriptor member name and type name. Note that the reference to the framebuffer details needs correcting for user mode usage. diff -r a6159a678002 -r b4dcc2099e0f stage2/jzlcd.c --- a/stage2/jzlcd.c Thu Jun 29 23:26:39 2017 +0200 +++ b/stage2/jzlcd.c Sat Jul 08 21:06:58 2017 +0200 @@ -29,13 +29,13 @@ #define align4(n) (n)=((((n)+3)>>2)<<2) #define align8(n) (n)=((((n)+7)>>3)<<3) -extern struct jzfb_info jzfb; extern vidinfo_t panel_info; -static uint16_t lcd_get_panels() +static uint16_t lcd_get_panels(vidinfo_t *vid) { - return ((jzfb.cfg & MODE_MASK) == MODE_STN_MONO_DUAL) || - ((jzfb.cfg & MODE_MASK) == MODE_STN_COLOR_DUAL) ? 2 : 1; + struct jzfb_info *jzfb = vid->jz_fb; + return ((jzfb->cfg & MODE_MASK) == MODE_STN_MONO_DUAL) || + ((jzfb->cfg & MODE_MASK) == MODE_STN_COLOR_DUAL) ? 2 : 1; } @@ -45,8 +45,8 @@ static uint32_t lcd_get_size(vidinfo_t *vid) { /* Lines must be aligned to a word boundary. */ - uint32_t line_length = ALIGN((vid->vl_col * NBITS(vid->vl_bpix)) / 8, sizeof(uint32_t)); - return line_length * vid->vl_row; + uint32_t line_length = ALIGN((vid->jz_fb->w * vid->jz_fb->bpp) / 8, sizeof(uint32_t)); + return line_length * vid->jz_fb->h; } static uint32_t lcd_get_aligned_size(vidinfo_t *vid) @@ -58,8 +58,8 @@ static uint32_t lcd_get_min_size(vidinfo_t *vid) { /* Lines must be aligned to a word boundary. */ - uint32_t line_length = ALIGN((vid->vl_col * 32) / 8, sizeof(uint32_t)); - return line_length * vid->vl_row; + uint32_t line_length = ALIGN((vid->jz_fb->w * 32) / 8, sizeof(uint32_t)); + return line_length * vid->jz_fb->h; } static uint32_t lcd_get_aligned_min_size(vidinfo_t *vid) @@ -70,8 +70,8 @@ static uint32_t lcd_get_palette_size(vidinfo_t *vid) { - if (NBITS(vid->vl_bpix) < 12) - return NCOLORS(vid->vl_bpix) * sizeof(uint16_t); + if (vid->jz_fb->bpp < 12) + return (1 << (vid->jz_fb->bpp)) * sizeof(uint16_t); else return 0; } @@ -89,7 +89,7 @@ static uint32_t lcd_get_total_size(vidinfo_t *vid) { - uint32_t size = lcd_get_aligned_size(vid) * lcd_get_panels(); + uint32_t size = lcd_get_aligned_size(vid) * lcd_get_panels(vid); uint32_t min_size = lcd_get_aligned_min_size(vid); /* Round up to nearest full page, or MMU section if defined. */ @@ -100,22 +100,22 @@ /* Functions returning addresses of each data region. */ -static uint32_t lcd_get_palette(uint32_t addr) +static uint32_t lcd_get_palette(uint32_t addr, vidinfo_t *vid) { /* Allocate memory at the end of the region for the palette. */ - return addr - lcd_get_aligned_palette_size(&panel_info); + return addr - lcd_get_aligned_palette_size(vid); } -static uint32_t lcd_get_descriptors(uint32_t addr) +static uint32_t lcd_get_descriptors(uint32_t addr, vidinfo_t *vid) { /* Allocate memory before the palette for the descriptor array. */ - return lcd_get_palette(addr) - lcd_get_descriptors_size(); + return lcd_get_palette(addr, vid) - lcd_get_descriptors_size(); } -static uint32_t lcd_get_framebuffer(uint32_t addr, uint16_t panel) +static uint32_t lcd_get_framebuffer(uint32_t addr, uint16_t panel, vidinfo_t *vid) { /* Allocate pages for the frame buffer and palette. */ - return addr - lcd_get_total_size(&panel_info) + (panel * lcd_get_aligned_size(&panel_info)); + return addr - lcd_get_total_size(vid) + (panel * lcd_get_aligned_size(vid)); } @@ -125,23 +125,23 @@ static void jz_lcd_desc_init(vidinfo_t *vid) { struct jz_fb_dma_descriptor *descriptors; - struct jz_fb_info * fbi; + struct jz_mem_info * fbi; - fbi = &vid->jz_fb; + fbi = &vid->jz_mem; /* Allocate space for descriptors before the palette entries. */ - descriptors = (struct jz_fb_dma_descriptor *) lcd_get_descriptors(get_memory_size()); + descriptors = (struct jz_fb_dma_descriptor *) lcd_get_descriptors(get_memory_size(), vid); fbi->dmadesc_fblow = (struct jz_fb_dma_descriptor *) &descriptors[0]; fbi->dmadesc_fbhigh = (struct jz_fb_dma_descriptor *) &descriptors[1]; fbi->dmadesc_palette = (struct jz_fb_dma_descriptor *) &descriptors[2]; /* Populate descriptors. */ - if (lcd_get_panels() == 2) + if (lcd_get_panels(vid) == 2) { fbi->dmadesc_fblow->fdadr = fbi->dmadesc_fblow; - fbi->dmadesc_fblow->fsadr = lcd_get_framebuffer(get_memory_size(), 1); + fbi->dmadesc_fblow->fsadr = lcd_get_framebuffer(get_memory_size(), 1, vid); fbi->dmadesc_fblow->fidr = 0; fbi->dmadesc_fblow->ldcmd = lcd_get_size(vid) / 4 ; @@ -152,7 +152,7 @@ fbi->dmadesc_fbhigh->fidr = 0; fbi->dmadesc_fbhigh->ldcmd = lcd_get_size(vid) / 4; /* length in words */ - if (NBITS(vid->vl_bpix) < 12) + if (vid->jz_fb->bpp < 12) { fbi->dmadesc_palette->fsadr = fbi->palette; fbi->dmadesc_palette->fidr = 0; @@ -172,11 +172,12 @@ flush_cache_all(); } -static uint32_t jz_lcd_stn_init(uint32_t stnH) +static uint32_t jz_lcd_stn_init(uint32_t stnH, vidinfo_t *vid) { + struct jzfb_info *jzfb = vid->jz_fb; uint32_t val = 0; - switch (jzfb.bpp) { + switch (jzfb->bpp) { case 1: /* val |= LCD_CTRL_PEDN; */ case 2: @@ -191,60 +192,62 @@ break; } - switch (jzfb.cfg & STN_DAT_PINMASK) { + switch (jzfb->cfg & STN_DAT_PINMASK) { case STN_DAT_PIN1: /* Do not adjust the hori-param value. */ break; case STN_DAT_PIN2: - align2(jzfb.hsw); - align2(jzfb.elw); - align2(jzfb.blw); + align2(jzfb->hsw); + align2(jzfb->elw); + align2(jzfb->blw); break; case STN_DAT_PIN4: - align4(jzfb.hsw); - align4(jzfb.elw); - align4(jzfb.blw); + align4(jzfb->hsw); + align4(jzfb->elw); + align4(jzfb->blw); break; case STN_DAT_PIN8: - align8(jzfb.hsw); - align8(jzfb.elw); - align8(jzfb.blw); + align8(jzfb->hsw); + align8(jzfb->elw); + align8(jzfb->blw); break; } - REG_LCD_VSYNC = (0 << 16) | jzfb.vsw; - REG_LCD_HSYNC = ((jzfb.blw+jzfb.w) << 16) | (jzfb.blw+jzfb.w+jzfb.hsw); + REG_LCD_VSYNC = (0 << 16) | jzfb->vsw; + REG_LCD_HSYNC = ((jzfb->blw+jzfb->w) << 16) | (jzfb->blw+jzfb->w+jzfb->hsw); /* Screen setting */ - REG_LCD_VAT = ((jzfb.blw + jzfb.w + jzfb.hsw + jzfb.elw) << 16) | (stnH + jzfb.vsw + jzfb.bfw + jzfb.efw); - REG_LCD_DAH = (jzfb.blw << 16) | (jzfb.blw + jzfb.w); + REG_LCD_VAT = ((jzfb->blw + jzfb->w + jzfb->hsw + jzfb->elw) << 16) | (stnH + jzfb->vsw + jzfb->bfw + jzfb->efw); + REG_LCD_DAH = (jzfb->blw << 16) | (jzfb->blw + jzfb->w); REG_LCD_DAV = (0 << 16) | (stnH); /* AC BIAs signal */ - REG_LCD_PS = (0 << 16) | (stnH+jzfb.vsw+jzfb.efw+jzfb.bfw); + REG_LCD_PS = (0 << 16) | (stnH+jzfb->vsw+jzfb->efw+jzfb->bfw); return val; } -static void jz_lcd_tft_init() +static void jz_lcd_tft_init(vidinfo_t *vid) { - REG_LCD_VSYNC = (0 << 16) | jzfb.vsw; - REG_LCD_HSYNC = (0 << 16) | jzfb.hsw; - REG_LCD_DAV =((jzfb.vsw+jzfb.bfw) << 16) | (jzfb.vsw +jzfb.bfw+jzfb.h); - REG_LCD_DAH = ((jzfb.hsw + jzfb.blw) << 16) | (jzfb.hsw + jzfb.blw + jzfb.w ); - REG_LCD_VAT = (((jzfb.blw + jzfb.w + jzfb.elw + jzfb.hsw)) << 16) \ - | (jzfb.vsw + jzfb.bfw + jzfb.h + jzfb.efw); + struct jzfb_info *jzfb = vid->jz_fb; + REG_LCD_VSYNC = (0 << 16) | jzfb->vsw; + REG_LCD_HSYNC = (0 << 16) | jzfb->hsw; + REG_LCD_DAV =((jzfb->vsw+jzfb->bfw) << 16) | (jzfb->vsw +jzfb->bfw+jzfb->h); + REG_LCD_DAH = ((jzfb->hsw + jzfb->blw) << 16) | (jzfb->hsw + jzfb->blw + jzfb->w ); + REG_LCD_VAT = (((jzfb->blw + jzfb->w + jzfb->elw + jzfb->hsw)) << 16) \ + | (jzfb->vsw + jzfb->bfw + jzfb->h + jzfb->efw); } -static void jz_lcd_samsung_init(uint32_t pclk) +static void jz_lcd_samsung_init(uint32_t pclk, vidinfo_t *vid) { + struct jzfb_info *jzfb = vid->jz_fb; uint32_t total, tp_s, tp_e, ckv_s, ckv_e; uint32_t rev_s, rev_e, inv_s, inv_e; - jz_lcd_tft_init(); + jz_lcd_tft_init(vid); - total = jzfb.blw + jzfb.w + jzfb.elw + jzfb.hsw; - tp_s = jzfb.blw + jzfb.w + 1; + total = jzfb->blw + jzfb->w + jzfb->elw + jzfb->hsw; + tp_s = jzfb->blw + jzfb->w + 1; tp_e = tp_s + 1; /* ckv_s = tp_s - jz_clocks.pixclk/(1000000000/4100); */ ckv_s = tp_s - pclk/(1000000000/4100); @@ -257,17 +260,18 @@ REG_LCD_PS = (ckv_s << 16) | ckv_e; REG_LCD_SPL = (rev_s << 16) | rev_e; REG_LCD_REV = (inv_s << 16) | inv_e; - jzfb.cfg |= STFT_REVHI | STFT_SPLHI; + jzfb->cfg |= STFT_REVHI | STFT_SPLHI; } -static void jz_lcd_sharp_init() +static void jz_lcd_sharp_init(vidinfo_t *vid) { + struct jzfb_info *jzfb = vid->jz_fb; uint32_t total, cls_s, cls_e, ps_s, ps_e; uint32_t spl_s, spl_e, rev_s, rev_e; - jz_lcd_tft_init(); + jz_lcd_tft_init(vid); - total = jzfb.blw + jzfb.w + jzfb.elw + jzfb.hsw; + total = jzfb->blw + jzfb->w + jzfb->elw + jzfb->hsw; spl_s = 1; spl_e = spl_s + 1; cls_s = 0; @@ -276,40 +280,41 @@ ps_e = cls_e; rev_s = total - 40; /* > 3us (pclk = 80ns) */ rev_e = rev_s + total; - jzfb.cfg |= STFT_PSHI; + jzfb->cfg |= STFT_PSHI; REG_LCD_SPL = (spl_s << 16) | spl_e; REG_LCD_CLS = (cls_s << 16) | cls_e; REG_LCD_PS = (ps_s << 16) | ps_e; REG_LCD_REV = (rev_s << 16) | rev_e; } -static uint32_t jz_lcd_get_pixel_clock() +static uint32_t jz_lcd_get_pixel_clock(vidinfo_t *vid) { + struct jzfb_info *jzfb = vid->jz_fb; uint32_t pclk; /* Derive pixel clock from frame clock. */ - if ( (jzfb.cfg & MODE_MASK) != MODE_8BIT_SERIAL_TFT) { - pclk = jzfb.fclk * (jzfb.w + jzfb.hsw + jzfb.elw + jzfb.blw) * - (jzfb.h + jzfb.vsw + jzfb.efw + jzfb.bfw); + if ( (jzfb->cfg & MODE_MASK) != MODE_8BIT_SERIAL_TFT) { + pclk = jzfb->fclk * (jzfb->w + jzfb->hsw + jzfb->elw + jzfb->blw) * + (jzfb->h + jzfb->vsw + jzfb->efw + jzfb->bfw); } else { /* serial mode: Hsync period = 3*Width_Pixel */ - pclk = jzfb.fclk * (jzfb.w*3 + jzfb.hsw + jzfb.elw + jzfb.blw) * - (jzfb.h + jzfb.vsw + jzfb.efw + jzfb.bfw); + pclk = jzfb->fclk * (jzfb->w*3 + jzfb->hsw + jzfb->elw + jzfb->blw) * + (jzfb->h + jzfb->vsw + jzfb->efw + jzfb->bfw); } - if (((jzfb.cfg & MODE_MASK) == MODE_STN_COLOR_SINGLE) || - ((jzfb.cfg & MODE_MASK) == MODE_STN_COLOR_DUAL)) + if (((jzfb->cfg & MODE_MASK) == MODE_STN_COLOR_SINGLE) || + ((jzfb->cfg & MODE_MASK) == MODE_STN_COLOR_DUAL)) pclk = (pclk * 3); - if (((jzfb.cfg & MODE_MASK) == MODE_STN_COLOR_SINGLE) || - ((jzfb.cfg & MODE_MASK) == MODE_STN_COLOR_DUAL) || - ((jzfb.cfg & MODE_MASK) == MODE_STN_MONO_SINGLE) || - ((jzfb.cfg & MODE_MASK) == MODE_STN_MONO_DUAL)) - pclk = pclk >> ((jzfb.cfg & STN_DAT_PINMASK) >> 4); + if (((jzfb->cfg & MODE_MASK) == MODE_STN_COLOR_SINGLE) || + ((jzfb->cfg & MODE_MASK) == MODE_STN_COLOR_DUAL) || + ((jzfb->cfg & MODE_MASK) == MODE_STN_MONO_SINGLE) || + ((jzfb->cfg & MODE_MASK) == MODE_STN_MONO_DUAL)) + pclk = pclk >> ((jzfb->cfg & STN_DAT_PINMASK) >> 4); - if (((jzfb.cfg & MODE_MASK) == MODE_STN_COLOR_DUAL) || - ((jzfb.cfg & MODE_MASK) == MODE_STN_MONO_DUAL)) + if (((jzfb->cfg & MODE_MASK) == MODE_STN_COLOR_DUAL) || + ((jzfb->cfg & MODE_MASK) == MODE_STN_MONO_DUAL)) pclk >>= 1; return pclk; @@ -358,12 +363,13 @@ static int jz_lcd_hw_init(vidinfo_t *vid) { - struct jz_fb_info *fbi = &vid->jz_fb; + struct jzfb_info *jzfb = vid->jz_fb; + struct jz_mem_info *fbi = &vid->jz_mem; uint32_t val = 0; - uint32_t pclk = jz_lcd_get_pixel_clock(); + uint32_t pclk = jz_lcd_get_pixel_clock(vid); /* Setting Control register */ - switch (jzfb.bpp) { + switch (jzfb->bpp) { case 1: val |= LCD_CTRL_BPP_1; break; @@ -387,38 +393,38 @@ break; #endif default: - /* printf("jz_lcd.c The BPP %d is not supported\n", jzfb.bpp); */ + /* printf("jz_lcd.c The BPP %d is not supported\n", jzfb->bpp); */ val |= LCD_CTRL_BPP_16; break; } - switch (jzfb.cfg & MODE_MASK) { + switch (jzfb->cfg & MODE_MASK) { case MODE_STN_MONO_DUAL: case MODE_STN_COLOR_DUAL: - val |= jz_lcd_stn_init(jzfb.h >> 1); + val |= jz_lcd_stn_init(jzfb->h >> 1, vid); break; case MODE_STN_MONO_SINGLE: case MODE_STN_COLOR_SINGLE: - val |= jz_lcd_stn_init(jzfb.h); + val |= jz_lcd_stn_init(jzfb->h, vid); break; case MODE_TFT_GEN: case MODE_TFT_CASIO: case MODE_8BIT_SERIAL_TFT: case MODE_TFT_18BIT: - jz_lcd_tft_init(); + jz_lcd_tft_init(vid); break; case MODE_TFT_SAMSUNG: { - jz_lcd_samsung_init(pclk); + jz_lcd_samsung_init(pclk, vid); break; } case MODE_TFT_SHARP: { - jz_lcd_sharp_init(); + jz_lcd_sharp_init(vid); break; } @@ -431,7 +437,7 @@ val |= LCD_CTRL_BST_16; /* Burst Length is 16WORD=64Byte */ val |= LCD_CTRL_OFUP; /* OutFIFO underrun protect */ REG_LCD_CTRL = val; - REG_LCD_CFG = jzfb.cfg; + REG_LCD_CFG = jzfb->cfg; /* Timing reset. */ @@ -444,30 +450,20 @@ REG_LCD_DA0 = (uint32_t) fbi->fdadr0; /* frame descriptor */ - if (((jzfb.cfg & MODE_MASK) == MODE_STN_COLOR_DUAL) || - ((jzfb.cfg & MODE_MASK) == MODE_STN_MONO_DUAL)) + if (((jzfb->cfg & MODE_MASK) == MODE_STN_COLOR_DUAL) || + ((jzfb->cfg & MODE_MASK) == MODE_STN_MONO_DUAL)) REG_LCD_DA1 = (uint32_t) fbi->fdadr1; /* frame descriptor */ return 0; } -static inline uint8_t LCD_CODE(uint8_t bpp) -{ - uint8_t code = 0; - while (bpp && !(bpp & 1)) - { - bpp >>= 1; - code += 1; - } - return code; -} - /* Public operations. */ void lcd_set_bpp(uint8_t bpp) { - jzfb.bpp = bpp; - panel_info.vl_bpix = LCD_CODE(bpp); + vidinfo_t *vid = &panel_info; + struct jzfb_info *jzfb = vid->jz_fb; + jzfb->bpp = bpp; } void lcd_enable() @@ -500,19 +496,19 @@ static void lcd_init_palette(vidinfo_t *vid) { - uint16_t *palette = (uint16_t *) lcd_get_palette(get_memory_size()); - uint16_t *end = (uint16_t *) palette + NCOLORS(vid->vl_bpix); + uint16_t *palette = (uint16_t *) lcd_get_palette(get_memory_size(), vid); + uint16_t *end = (uint16_t *) palette + (1 << (vid->jz_fb->bpp)); uint8_t value = 0; while (palette < end) { - switch (vid->vl_bpix) + switch (vid->jz_fb->bpp) { - case LCD_COLOR4: + case 4: *palette = rgb4_to_rgb16(value); break; - case LCD_COLOR8: + case 8: default: *palette = rgb8_to_rgb16(value); break; @@ -525,18 +521,19 @@ uint32_t lcd_ctrl_init() { - struct jz_fb_info *fbi = &panel_info.jz_fb; + vidinfo_t *vid = &panel_info; + struct jz_mem_info *fbi = &vid->jz_mem; /* Start from the top of memory and obtain palette and framebuffer regions. */ - fbi->screen = lcd_get_framebuffer(get_memory_size(), 0); - fbi->palette = lcd_get_palette(get_memory_size()); + fbi->screen = lcd_get_framebuffer(get_memory_size(), 0, vid); + fbi->palette = lcd_get_palette(get_memory_size(), vid); - if (NBITS(panel_info.vl_bpix) < 12) - lcd_init_palette(&panel_info); + if (vid->jz_fb->bpp < 12) + lcd_init_palette(vid); - jz_lcd_desc_init(&panel_info); - jz_lcd_hw_init(&panel_info); + jz_lcd_desc_init(vid); + jz_lcd_hw_init(vid); return fbi->screen; } diff -r a6159a678002 -r b4dcc2099e0f stage2/jzlcd.h --- a/stage2/jzlcd.h Thu Jun 29 23:26:39 2017 +0200 +++ b/stage2/jzlcd.h Sat Jul 08 21:06:58 2017 +0200 @@ -37,9 +37,9 @@ */ struct jzfb_info { uint32_t cfg; /* panel mode and pin usage etc. */ - uint32_t w; - uint32_t h; - uint32_t bpp; /* bit per pixel */ + uint16_t w; + uint16_t h; + uint8_t bpp; /* bit per pixel */ uint32_t fclk; /* frame clk */ uint32_t hsw; /* hsync width, in pclk */ uint32_t vsw; /* vsync width, in line count */ @@ -62,7 +62,7 @@ /* * Jz LCD info */ -struct jz_fb_info { +struct jz_mem_info { struct jz_fb_dma_descriptor *fdadr0; /* physical address of frame/palette descriptor */ struct jz_fb_dma_descriptor *fdadr1; /* physical address of frame descriptor */ @@ -80,11 +80,8 @@ * Concise display characteristics with low-level structure reference */ typedef struct vidinfo { - uint16_t vl_col; /* Number of columns (i.e. 640) */ - uint16_t vl_row; /* Number of rows (i.e. 480) */ - uint8_t vl_bpix; /* Bits per pixel, 0 = 1, 1 = 2, 2 = 4, 3 = 8 */ - - struct jz_fb_info jz_fb; + struct jz_mem_info jz_mem; + struct jzfb_info *jz_fb; } vidinfo_t; /* Alignment/rounding macros. */ @@ -92,20 +89,6 @@ #define ALIGN(x,a) __ALIGN_MASK((x),(typeof(x))(a)-1) #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) -/* General values for colour depths and framebuffer characteristics. */ - -#define LCD_MONOCHROME 0 -#define LCD_COLOR2 1 -#define LCD_COLOR4 2 -#define LCD_COLOR8 3 -#define LCD_COLOR16 4 -#define LCD_COLOR32 5 - -/* Calculate number of bits per pixel and number of colours. */ - -#define NBITS(bit_code) (1 << (bit_code)) -#define NCOLORS(bit_code) (1 << NBITS(bit_code)) - /* Transfer and display types. */ #define MODE_MASK 0x0f diff -r a6159a678002 -r b4dcc2099e0f stage2/lcd.c --- a/stage2/lcd.c Thu Jun 29 23:26:39 2017 +0200 +++ b/stage2/lcd.c Sat Jul 08 21:06:58 2017 +0200 @@ -25,34 +25,35 @@ #include "board.h" extern vidinfo_t panel_info; -static unsigned long lcd_base; +extern struct jzfb_info jzfb; +static uint32_t lcd_base; -static unsigned int get_line_length() +static uint16_t get_line_length() { - return ALIGN((panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8, sizeof(uint32_t)); + return ALIGN((panel_info.jz_fb->w * panel_info.jz_fb->bpp) / 8, sizeof(uint32_t)); } -static uint32_t *get_pixel32(unsigned short h, unsigned short v) +static uint32_t *get_pixel32(uint16_t h, uint16_t v) { return (uint32_t *) (lcd_base + v * get_line_length()) + h; } -static uint16_t *get_pixel16(unsigned short h, unsigned short v) +static uint16_t *get_pixel16(uint16_t h, uint16_t v) { return (uint16_t *) (lcd_base + v * get_line_length()) + h; } -static uint8_t *get_pixel8(unsigned short h, unsigned short v) +static uint8_t *get_pixel8(uint16_t h, uint16_t v) { return (uint8_t *) (lcd_base + v * get_line_length()) + h; } -static uint8_t *get_pixel4(unsigned short h, unsigned short v) +static uint8_t *get_pixel4(uint16_t h, uint16_t v) { return (uint8_t *) (lcd_base + v * get_line_length()) + h / 2; } -static inline unsigned short div(unsigned short num, unsigned short denom, unsigned short scale) +static inline uint16_t div(uint16_t num, uint16_t denom, uint16_t scale) { return (scale * num) / denom; } @@ -62,69 +63,69 @@ return (div(r, 255, rmax) << rshift) | (div(g, 255, gmax) << gshift) | (div(b, 255, bmax) << bshift); } -uint32_t get_bitmap_value(unsigned short x, uint32_t value) +uint32_t get_bitmap_value(uint16_t x, uint32_t value) { - return (value >> (((panel_info.vl_col - 1 - x) * 32) / panel_info.vl_col)) % 2 ? 0xffffffff : 0; + return (value >> (((panel_info.jz_fb->w - 1 - x) * 32) / panel_info.jz_fb->w)) % 2 ? 0xffffffff : 0; } -static void get_colour(unsigned short h, unsigned short v, uint8_t rgb[], unsigned short pixel_type) +static void get_colour(uint16_t h, uint16_t v, uint8_t rgb[], uint16_t pixel_type) { - unsigned short v_max = panel_info.vl_row - 1; - unsigned short h_max = panel_info.vl_col - 1; + uint16_t v_max = panel_info.jz_fb->h - 1; + uint16_t h_max = panel_info.jz_fb->w - 1; rgb[(pixel_type - 1) % 3] = div(h, h_max, 255); rgb[pixel_type % 3] = div(v, v_max, 255); rgb[(pixel_type + 1) % 3] = (rgb[0] + rgb[1]) / 2; } -static void set_pixel32(unsigned short h, unsigned short v, uint32_t value) +static void set_pixel32(uint16_t h, uint16_t v, uint32_t value) { uint32_t *pix = get_pixel32(h, v); *pix = value; } -static void set_pixel16_565(unsigned short h, unsigned short v, uint32_t value) +static void set_pixel16_565(uint16_t h, uint16_t v, uint32_t value) { uint16_t *pix = get_pixel16(h, v); *pix = (uint16_t) value; } -static void set_pixel8(unsigned short h, unsigned short v, uint32_t value) +static void set_pixel8(uint16_t h, uint16_t v, uint32_t value) { uint8_t *pix = get_pixel8(h, v); *pix = (uint8_t) value; } -static void set_pixel4(unsigned short h, unsigned short v, uint32_t value) +static void set_pixel4(uint16_t h, uint16_t v, uint32_t value) { uint8_t *pix = get_pixel4(h, v); uint8_t mask = h & 1 ? 0xf0 : 0x0f; *pix = (*pix & mask) | ((uint8_t) value); } -void set_pixel(unsigned short h, unsigned short v, uint32_t value) +void set_pixel(uint16_t h, uint16_t v, uint32_t value) { - switch (panel_info.vl_bpix) + switch (panel_info.jz_fb->bpp) { - case LCD_COLOR32: + case 32: set_pixel32(h, v, value); break; - case LCD_COLOR8: + case 8: set_pixel8(h, v, value); break; - case LCD_COLOR4: + case 4: set_pixel4(h, v, value); break; - case LCD_COLOR16: + case 16: default: set_pixel16_565(h, v, value); break; } } -static void test_pixel32(unsigned short h, unsigned short v, unsigned short pixel_type) +static void test_pixel32(uint16_t h, uint16_t v, uint16_t pixel_type) { uint8_t rgb[3]; @@ -132,7 +133,7 @@ set_pixel32(h, v, pixel(rgb[0], rgb[1], rgb[2], 255, 255, 255, 16, 8, 0) | get_bitmap_value(h, pixel_type)); } -static void test_pixel16_565(unsigned short h, unsigned short v, unsigned short pixel_type) +static void test_pixel16_565(uint16_t h, uint16_t v, uint16_t pixel_type) { uint8_t rgb[3]; @@ -140,7 +141,7 @@ set_pixel16_565(h, v, pixel(rgb[0], rgb[1], rgb[2], 31, 63, 31, 11, 5, 0) | get_bitmap_value(h, pixel_type)); } -static void test_pixel8(unsigned short h, unsigned short v, unsigned short pixel_type) +static void test_pixel8(uint16_t h, uint16_t v, uint16_t pixel_type) { uint8_t rgb[3]; @@ -148,7 +149,7 @@ set_pixel8(h, v, pixel(rgb[0], rgb[1], rgb[2], 7, 7, 3, 5, 2, 0) | get_bitmap_value(h, pixel_type)); } -static void test_pixel4(unsigned short h, unsigned short v, unsigned short pixel_type) +static void test_pixel4(uint16_t h, uint16_t v, uint16_t pixel_type) { uint8_t rgb[3]; @@ -156,71 +157,71 @@ set_pixel4(h, v, pixel(rgb[0], rgb[1], rgb[2], 1, 2, 1, 3, 1, 0) | get_bitmap_value(h, pixel_type)); } -void test_pixel(unsigned short h, unsigned short v, unsigned short pixel_type) +void test_pixel(uint16_t h, uint16_t v, uint16_t pixel_type) { - switch (panel_info.vl_bpix) + switch (panel_info.jz_fb->bpp) { - case LCD_COLOR32: + case 32: test_pixel32(h, v, pixel_type); break; - case LCD_COLOR8: + case 8: test_pixel8(h, v, pixel_type); break; - case LCD_COLOR4: + case 4: test_pixel4(h, v, pixel_type); break; - case LCD_COLOR16: + case 16: default: test_pixel16_565(h, v, pixel_type); break; } } -void clear_pixel32(unsigned short h, unsigned short v) +void clear_pixel32(uint16_t h, uint16_t v) { uint32_t *pix = get_pixel32(h, v); *pix = 0; } -void clear_pixel16(unsigned short h, unsigned short v) +void clear_pixel16(uint16_t h, uint16_t v) { uint16_t *pix = get_pixel16(h, v); *pix = 0; } -void clear_pixel8(unsigned short h, unsigned short v) +void clear_pixel8(uint16_t h, uint16_t v) { uint8_t *pix = get_pixel8(h, v); *pix = 0; } -void clear_pixel4(unsigned short h, unsigned short v) +void clear_pixel4(uint16_t h, uint16_t v) { uint8_t *pix = get_pixel4(h, v); uint8_t mask = h & 1 ? 0xf0 : 0x0f; *pix = *pix & mask; } -void clear_pixel(unsigned short h, unsigned short v) +void clear_pixel(uint16_t h, uint16_t v) { - switch (panel_info.vl_bpix) + switch (panel_info.jz_fb->bpp) { - case LCD_COLOR32: + case 32: clear_pixel32(h, v); break; - case LCD_COLOR8: + case 8: clear_pixel8(h, v); break; - case LCD_COLOR4: + case 4: clear_pixel4(h, v); break; - case LCD_COLOR16: + case 16: default: clear_pixel16(h, v); break; @@ -229,9 +230,9 @@ void test_pattern() { - unsigned short v_max = panel_info.vl_row; - unsigned short h_max = panel_info.vl_col; - unsigned short v, h; + uint16_t v_max = panel_info.jz_fb->h; + uint16_t h_max = panel_info.jz_fb->w; + uint16_t v, h; for (v = 0; v < v_max; v += 1) { for (h = 0; h < h_max; h += 1) { @@ -240,12 +241,12 @@ } } -void lcd_clear(unsigned long lcd_base) +void lcd_clear(uint32_t lcd_base) { - unsigned short v_max = panel_info.vl_row; - unsigned short h_max = panel_info.vl_col; - unsigned short v, h; - unsigned long *pix = (unsigned long *)lcd_base; + uint16_t v_max = panel_info.jz_fb->h; + uint16_t h_max = panel_info.jz_fb->w; + uint16_t v, h; + uint32_t *pix = (uint32_t *)lcd_base; for (v = 0; v < v_max; v += 1) { for (h = 0; h < h_max; h += 1) { @@ -261,6 +262,10 @@ __lcd_display_pin_init(); __lcd_display_on(); + /* Initialise the member here since the address is otherwise invalid. */ + + panel_info.jz_fb = (struct jzfb_info *) ((uint32_t) &jzfb & ~0x80000000); + lcd_base = lcd_ctrl_init(); lcd_clear(lcd_base); lcd_enable(); diff -r a6159a678002 -r b4dcc2099e0f stage2/lcd.h --- a/stage2/lcd.h Thu Jun 29 23:26:39 2017 +0200 +++ b/stage2/lcd.h Sat Jul 08 21:06:58 2017 +0200 @@ -9,10 +9,10 @@ /* Output functions. */ -uint32_t get_bitmap_value(unsigned short, uint32_t); -void set_pixel(unsigned short, unsigned short, uint32_t); -void test_pixel(unsigned short, unsigned short, unsigned short); -void clear_pixel(unsigned short, unsigned short); +uint32_t get_bitmap_value(uint16_t, uint32_t); +void set_pixel(uint16_t, uint16_t, uint32_t); +void test_pixel(uint16_t, uint16_t, uint16_t); +void clear_pixel(uint16_t, uint16_t); void test_pattern(); diff -r a6159a678002 -r b4dcc2099e0f stage2/minipc_claa070vc01.c --- a/stage2/minipc_claa070vc01.c Thu Jun 29 23:26:39 2017 +0200 +++ b/stage2/minipc_claa070vc01.c Sat Jul 08 21:06:58 2017 +0200 @@ -2,7 +2,7 @@ * MiniPC screen details * * Copyright (C) 2005-2007, Ingenic Semiconductor Inc. - * Copyright (C) 2015, 2016 Paul Boddie + * Copyright (C) 2015, 2016, 2017 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 @@ -29,6 +29,4 @@ 800, 480, 32, 60, 80, 20, 0, 0, 0, 0 }; -vidinfo_t panel_info = { - 800, 480, LCD_COLOR32, -}; +vidinfo_t panel_info; diff -r a6159a678002 -r b4dcc2099e0f stage2/nanonote_gpm940b0.c --- a/stage2/nanonote_gpm940b0.c Thu Jun 29 23:26:39 2017 +0200 +++ b/stage2/nanonote_gpm940b0.c Sat Jul 08 21:06:58 2017 +0200 @@ -34,6 +34,4 @@ .efw=1, .bfw=20 /* frame limits */ }; -vidinfo_t panel_info = { - 320, 240, LCD_COLOR32, -}; +vidinfo_t panel_info; diff -r a6159a678002 -r b4dcc2099e0f stage2/tasks/example.c --- a/stage2/tasks/example.c Thu Jun 29 23:26:39 2017 +0200 +++ b/stage2/tasks/example.c Sat Jul 08 21:06:58 2017 +0200 @@ -27,10 +27,10 @@ void next_pixel(uint16_t *x, uint16_t *y) { (*x)++; - if (*x >= panel_info.vl_col) { + if (*x >= panel_info.jz_fb->w) { *x = 0; (*y)++; - if (*y >= panel_info.vl_row) + if (*y >= panel_info.jz_fb->h) *y = 0; } } @@ -50,7 +50,7 @@ void start_plot_pattern(uint8_t task) { - uint32_t args[] = {task, 0, (task * (panel_info.vl_row / 4)) % panel_info.vl_row}; + uint32_t args[] = {task, 0, (task * (panel_info.jz_fb->h / 4)) % panel_info.jz_fb->h}; start_task(task, (void (*)()) plot_pattern, args, 3); } diff -r a6159a678002 -r b4dcc2099e0f stage2/tasks/keyscan.c --- a/stage2/tasks/keyscan.c Thu Jun 29 23:26:39 2017 +0200 +++ b/stage2/tasks/keyscan.c Sat Jul 08 21:06:58 2017 +0200 @@ -30,11 +30,11 @@ uint16_t x, y; uint32_t pixel; - for (y = ymin; (y < panel_info.vl_row) && (y < ymax); y++) + for (y = ymin; (y < panel_info.jz_fb->h) && (y < ymax); y++) { pixel = (value >> (((y - ymin) * 8) / (ymax - ymin))) % 2 ? 0xffffffff : 0; - for (x = xmin; (x < panel_info.vl_col) && (x < xmax); x++) + for (x = xmin; (x < panel_info.jz_fb->w) && (x < xmax); x++) { set_pixel(x, y, pixel); }