1.1 --- a/stage2/jzlcd.c Thu Jun 29 23:26:39 2017 +0200
1.2 +++ b/stage2/jzlcd.c Sat Jul 08 21:06:58 2017 +0200
1.3 @@ -29,13 +29,13 @@
1.4 #define align4(n) (n)=((((n)+3)>>2)<<2)
1.5 #define align8(n) (n)=((((n)+7)>>3)<<3)
1.6
1.7 -extern struct jzfb_info jzfb;
1.8 extern vidinfo_t panel_info;
1.9
1.10 -static uint16_t lcd_get_panels()
1.11 +static uint16_t lcd_get_panels(vidinfo_t *vid)
1.12 {
1.13 - return ((jzfb.cfg & MODE_MASK) == MODE_STN_MONO_DUAL) ||
1.14 - ((jzfb.cfg & MODE_MASK) == MODE_STN_COLOR_DUAL) ? 2 : 1;
1.15 + struct jzfb_info *jzfb = vid->jz_fb;
1.16 + return ((jzfb->cfg & MODE_MASK) == MODE_STN_MONO_DUAL) ||
1.17 + ((jzfb->cfg & MODE_MASK) == MODE_STN_COLOR_DUAL) ? 2 : 1;
1.18 }
1.19
1.20
1.21 @@ -45,8 +45,8 @@
1.22 static uint32_t lcd_get_size(vidinfo_t *vid)
1.23 {
1.24 /* Lines must be aligned to a word boundary. */
1.25 - uint32_t line_length = ALIGN((vid->vl_col * NBITS(vid->vl_bpix)) / 8, sizeof(uint32_t));
1.26 - return line_length * vid->vl_row;
1.27 + uint32_t line_length = ALIGN((vid->jz_fb->w * vid->jz_fb->bpp) / 8, sizeof(uint32_t));
1.28 + return line_length * vid->jz_fb->h;
1.29 }
1.30
1.31 static uint32_t lcd_get_aligned_size(vidinfo_t *vid)
1.32 @@ -58,8 +58,8 @@
1.33 static uint32_t lcd_get_min_size(vidinfo_t *vid)
1.34 {
1.35 /* Lines must be aligned to a word boundary. */
1.36 - uint32_t line_length = ALIGN((vid->vl_col * 32) / 8, sizeof(uint32_t));
1.37 - return line_length * vid->vl_row;
1.38 + uint32_t line_length = ALIGN((vid->jz_fb->w * 32) / 8, sizeof(uint32_t));
1.39 + return line_length * vid->jz_fb->h;
1.40 }
1.41
1.42 static uint32_t lcd_get_aligned_min_size(vidinfo_t *vid)
1.43 @@ -70,8 +70,8 @@
1.44
1.45 static uint32_t lcd_get_palette_size(vidinfo_t *vid)
1.46 {
1.47 - if (NBITS(vid->vl_bpix) < 12)
1.48 - return NCOLORS(vid->vl_bpix) * sizeof(uint16_t);
1.49 + if (vid->jz_fb->bpp < 12)
1.50 + return (1 << (vid->jz_fb->bpp)) * sizeof(uint16_t);
1.51 else
1.52 return 0;
1.53 }
1.54 @@ -89,7 +89,7 @@
1.55
1.56 static uint32_t lcd_get_total_size(vidinfo_t *vid)
1.57 {
1.58 - uint32_t size = lcd_get_aligned_size(vid) * lcd_get_panels();
1.59 + uint32_t size = lcd_get_aligned_size(vid) * lcd_get_panels(vid);
1.60 uint32_t min_size = lcd_get_aligned_min_size(vid);
1.61
1.62 /* Round up to nearest full page, or MMU section if defined. */
1.63 @@ -100,22 +100,22 @@
1.64
1.65 /* Functions returning addresses of each data region. */
1.66
1.67 -static uint32_t lcd_get_palette(uint32_t addr)
1.68 +static uint32_t lcd_get_palette(uint32_t addr, vidinfo_t *vid)
1.69 {
1.70 /* Allocate memory at the end of the region for the palette. */
1.71 - return addr - lcd_get_aligned_palette_size(&panel_info);
1.72 + return addr - lcd_get_aligned_palette_size(vid);
1.73 }
1.74
1.75 -static uint32_t lcd_get_descriptors(uint32_t addr)
1.76 +static uint32_t lcd_get_descriptors(uint32_t addr, vidinfo_t *vid)
1.77 {
1.78 /* Allocate memory before the palette for the descriptor array. */
1.79 - return lcd_get_palette(addr) - lcd_get_descriptors_size();
1.80 + return lcd_get_palette(addr, vid) - lcd_get_descriptors_size();
1.81 }
1.82
1.83 -static uint32_t lcd_get_framebuffer(uint32_t addr, uint16_t panel)
1.84 +static uint32_t lcd_get_framebuffer(uint32_t addr, uint16_t panel, vidinfo_t *vid)
1.85 {
1.86 /* Allocate pages for the frame buffer and palette. */
1.87 - return addr - lcd_get_total_size(&panel_info) + (panel * lcd_get_aligned_size(&panel_info));
1.88 + return addr - lcd_get_total_size(vid) + (panel * lcd_get_aligned_size(vid));
1.89 }
1.90
1.91
1.92 @@ -125,23 +125,23 @@
1.93 static void jz_lcd_desc_init(vidinfo_t *vid)
1.94 {
1.95 struct jz_fb_dma_descriptor *descriptors;
1.96 - struct jz_fb_info * fbi;
1.97 + struct jz_mem_info * fbi;
1.98
1.99 - fbi = &vid->jz_fb;
1.100 + fbi = &vid->jz_mem;
1.101
1.102 /* Allocate space for descriptors before the palette entries. */
1.103
1.104 - descriptors = (struct jz_fb_dma_descriptor *) lcd_get_descriptors(get_memory_size());
1.105 + descriptors = (struct jz_fb_dma_descriptor *) lcd_get_descriptors(get_memory_size(), vid);
1.106 fbi->dmadesc_fblow = (struct jz_fb_dma_descriptor *) &descriptors[0];
1.107 fbi->dmadesc_fbhigh = (struct jz_fb_dma_descriptor *) &descriptors[1];
1.108 fbi->dmadesc_palette = (struct jz_fb_dma_descriptor *) &descriptors[2];
1.109
1.110 /* Populate descriptors. */
1.111
1.112 - if (lcd_get_panels() == 2)
1.113 + if (lcd_get_panels(vid) == 2)
1.114 {
1.115 fbi->dmadesc_fblow->fdadr = fbi->dmadesc_fblow;
1.116 - fbi->dmadesc_fblow->fsadr = lcd_get_framebuffer(get_memory_size(), 1);
1.117 + fbi->dmadesc_fblow->fsadr = lcd_get_framebuffer(get_memory_size(), 1, vid);
1.118 fbi->dmadesc_fblow->fidr = 0;
1.119 fbi->dmadesc_fblow->ldcmd = lcd_get_size(vid) / 4 ;
1.120
1.121 @@ -152,7 +152,7 @@
1.122 fbi->dmadesc_fbhigh->fidr = 0;
1.123 fbi->dmadesc_fbhigh->ldcmd = lcd_get_size(vid) / 4; /* length in words */
1.124
1.125 - if (NBITS(vid->vl_bpix) < 12)
1.126 + if (vid->jz_fb->bpp < 12)
1.127 {
1.128 fbi->dmadesc_palette->fsadr = fbi->palette;
1.129 fbi->dmadesc_palette->fidr = 0;
1.130 @@ -172,11 +172,12 @@
1.131 flush_cache_all();
1.132 }
1.133
1.134 -static uint32_t jz_lcd_stn_init(uint32_t stnH)
1.135 +static uint32_t jz_lcd_stn_init(uint32_t stnH, vidinfo_t *vid)
1.136 {
1.137 + struct jzfb_info *jzfb = vid->jz_fb;
1.138 uint32_t val = 0;
1.139
1.140 - switch (jzfb.bpp) {
1.141 + switch (jzfb->bpp) {
1.142 case 1:
1.143 /* val |= LCD_CTRL_PEDN; */
1.144 case 2:
1.145 @@ -191,60 +192,62 @@
1.146 break;
1.147 }
1.148
1.149 - switch (jzfb.cfg & STN_DAT_PINMASK) {
1.150 + switch (jzfb->cfg & STN_DAT_PINMASK) {
1.151 case STN_DAT_PIN1:
1.152 /* Do not adjust the hori-param value. */
1.153 break;
1.154 case STN_DAT_PIN2:
1.155 - align2(jzfb.hsw);
1.156 - align2(jzfb.elw);
1.157 - align2(jzfb.blw);
1.158 + align2(jzfb->hsw);
1.159 + align2(jzfb->elw);
1.160 + align2(jzfb->blw);
1.161 break;
1.162 case STN_DAT_PIN4:
1.163 - align4(jzfb.hsw);
1.164 - align4(jzfb.elw);
1.165 - align4(jzfb.blw);
1.166 + align4(jzfb->hsw);
1.167 + align4(jzfb->elw);
1.168 + align4(jzfb->blw);
1.169 break;
1.170 case STN_DAT_PIN8:
1.171 - align8(jzfb.hsw);
1.172 - align8(jzfb.elw);
1.173 - align8(jzfb.blw);
1.174 + align8(jzfb->hsw);
1.175 + align8(jzfb->elw);
1.176 + align8(jzfb->blw);
1.177 break;
1.178 }
1.179
1.180 - REG_LCD_VSYNC = (0 << 16) | jzfb.vsw;
1.181 - REG_LCD_HSYNC = ((jzfb.blw+jzfb.w) << 16) | (jzfb.blw+jzfb.w+jzfb.hsw);
1.182 + REG_LCD_VSYNC = (0 << 16) | jzfb->vsw;
1.183 + REG_LCD_HSYNC = ((jzfb->blw+jzfb->w) << 16) | (jzfb->blw+jzfb->w+jzfb->hsw);
1.184
1.185 /* Screen setting */
1.186 - REG_LCD_VAT = ((jzfb.blw + jzfb.w + jzfb.hsw + jzfb.elw) << 16) | (stnH + jzfb.vsw + jzfb.bfw + jzfb.efw);
1.187 - REG_LCD_DAH = (jzfb.blw << 16) | (jzfb.blw + jzfb.w);
1.188 + REG_LCD_VAT = ((jzfb->blw + jzfb->w + jzfb->hsw + jzfb->elw) << 16) | (stnH + jzfb->vsw + jzfb->bfw + jzfb->efw);
1.189 + REG_LCD_DAH = (jzfb->blw << 16) | (jzfb->blw + jzfb->w);
1.190 REG_LCD_DAV = (0 << 16) | (stnH);
1.191
1.192 /* AC BIAs signal */
1.193 - REG_LCD_PS = (0 << 16) | (stnH+jzfb.vsw+jzfb.efw+jzfb.bfw);
1.194 + REG_LCD_PS = (0 << 16) | (stnH+jzfb->vsw+jzfb->efw+jzfb->bfw);
1.195
1.196 return val;
1.197 }
1.198
1.199 -static void jz_lcd_tft_init()
1.200 +static void jz_lcd_tft_init(vidinfo_t *vid)
1.201 {
1.202 - REG_LCD_VSYNC = (0 << 16) | jzfb.vsw;
1.203 - REG_LCD_HSYNC = (0 << 16) | jzfb.hsw;
1.204 - REG_LCD_DAV =((jzfb.vsw+jzfb.bfw) << 16) | (jzfb.vsw +jzfb.bfw+jzfb.h);
1.205 - REG_LCD_DAH = ((jzfb.hsw + jzfb.blw) << 16) | (jzfb.hsw + jzfb.blw + jzfb.w );
1.206 - REG_LCD_VAT = (((jzfb.blw + jzfb.w + jzfb.elw + jzfb.hsw)) << 16) \
1.207 - | (jzfb.vsw + jzfb.bfw + jzfb.h + jzfb.efw);
1.208 + struct jzfb_info *jzfb = vid->jz_fb;
1.209 + REG_LCD_VSYNC = (0 << 16) | jzfb->vsw;
1.210 + REG_LCD_HSYNC = (0 << 16) | jzfb->hsw;
1.211 + REG_LCD_DAV =((jzfb->vsw+jzfb->bfw) << 16) | (jzfb->vsw +jzfb->bfw+jzfb->h);
1.212 + REG_LCD_DAH = ((jzfb->hsw + jzfb->blw) << 16) | (jzfb->hsw + jzfb->blw + jzfb->w );
1.213 + REG_LCD_VAT = (((jzfb->blw + jzfb->w + jzfb->elw + jzfb->hsw)) << 16) \
1.214 + | (jzfb->vsw + jzfb->bfw + jzfb->h + jzfb->efw);
1.215 }
1.216
1.217 -static void jz_lcd_samsung_init(uint32_t pclk)
1.218 +static void jz_lcd_samsung_init(uint32_t pclk, vidinfo_t *vid)
1.219 {
1.220 + struct jzfb_info *jzfb = vid->jz_fb;
1.221 uint32_t total, tp_s, tp_e, ckv_s, ckv_e;
1.222 uint32_t rev_s, rev_e, inv_s, inv_e;
1.223
1.224 - jz_lcd_tft_init();
1.225 + jz_lcd_tft_init(vid);
1.226
1.227 - total = jzfb.blw + jzfb.w + jzfb.elw + jzfb.hsw;
1.228 - tp_s = jzfb.blw + jzfb.w + 1;
1.229 + total = jzfb->blw + jzfb->w + jzfb->elw + jzfb->hsw;
1.230 + tp_s = jzfb->blw + jzfb->w + 1;
1.231 tp_e = tp_s + 1;
1.232 /* ckv_s = tp_s - jz_clocks.pixclk/(1000000000/4100); */
1.233 ckv_s = tp_s - pclk/(1000000000/4100);
1.234 @@ -257,17 +260,18 @@
1.235 REG_LCD_PS = (ckv_s << 16) | ckv_e;
1.236 REG_LCD_SPL = (rev_s << 16) | rev_e;
1.237 REG_LCD_REV = (inv_s << 16) | inv_e;
1.238 - jzfb.cfg |= STFT_REVHI | STFT_SPLHI;
1.239 + jzfb->cfg |= STFT_REVHI | STFT_SPLHI;
1.240 }
1.241
1.242 -static void jz_lcd_sharp_init()
1.243 +static void jz_lcd_sharp_init(vidinfo_t *vid)
1.244 {
1.245 + struct jzfb_info *jzfb = vid->jz_fb;
1.246 uint32_t total, cls_s, cls_e, ps_s, ps_e;
1.247 uint32_t spl_s, spl_e, rev_s, rev_e;
1.248
1.249 - jz_lcd_tft_init();
1.250 + jz_lcd_tft_init(vid);
1.251
1.252 - total = jzfb.blw + jzfb.w + jzfb.elw + jzfb.hsw;
1.253 + total = jzfb->blw + jzfb->w + jzfb->elw + jzfb->hsw;
1.254 spl_s = 1;
1.255 spl_e = spl_s + 1;
1.256 cls_s = 0;
1.257 @@ -276,40 +280,41 @@
1.258 ps_e = cls_e;
1.259 rev_s = total - 40; /* > 3us (pclk = 80ns) */
1.260 rev_e = rev_s + total;
1.261 - jzfb.cfg |= STFT_PSHI;
1.262 + jzfb->cfg |= STFT_PSHI;
1.263 REG_LCD_SPL = (spl_s << 16) | spl_e;
1.264 REG_LCD_CLS = (cls_s << 16) | cls_e;
1.265 REG_LCD_PS = (ps_s << 16) | ps_e;
1.266 REG_LCD_REV = (rev_s << 16) | rev_e;
1.267 }
1.268
1.269 -static uint32_t jz_lcd_get_pixel_clock()
1.270 +static uint32_t jz_lcd_get_pixel_clock(vidinfo_t *vid)
1.271 {
1.272 + struct jzfb_info *jzfb = vid->jz_fb;
1.273 uint32_t pclk;
1.274
1.275 /* Derive pixel clock from frame clock. */
1.276
1.277 - if ( (jzfb.cfg & MODE_MASK) != MODE_8BIT_SERIAL_TFT) {
1.278 - pclk = jzfb.fclk * (jzfb.w + jzfb.hsw + jzfb.elw + jzfb.blw) *
1.279 - (jzfb.h + jzfb.vsw + jzfb.efw + jzfb.bfw);
1.280 + if ( (jzfb->cfg & MODE_MASK) != MODE_8BIT_SERIAL_TFT) {
1.281 + pclk = jzfb->fclk * (jzfb->w + jzfb->hsw + jzfb->elw + jzfb->blw) *
1.282 + (jzfb->h + jzfb->vsw + jzfb->efw + jzfb->bfw);
1.283 } else {
1.284 /* serial mode: Hsync period = 3*Width_Pixel */
1.285 - pclk = jzfb.fclk * (jzfb.w*3 + jzfb.hsw + jzfb.elw + jzfb.blw) *
1.286 - (jzfb.h + jzfb.vsw + jzfb.efw + jzfb.bfw);
1.287 + pclk = jzfb->fclk * (jzfb->w*3 + jzfb->hsw + jzfb->elw + jzfb->blw) *
1.288 + (jzfb->h + jzfb->vsw + jzfb->efw + jzfb->bfw);
1.289 }
1.290
1.291 - if (((jzfb.cfg & MODE_MASK) == MODE_STN_COLOR_SINGLE) ||
1.292 - ((jzfb.cfg & MODE_MASK) == MODE_STN_COLOR_DUAL))
1.293 + if (((jzfb->cfg & MODE_MASK) == MODE_STN_COLOR_SINGLE) ||
1.294 + ((jzfb->cfg & MODE_MASK) == MODE_STN_COLOR_DUAL))
1.295 pclk = (pclk * 3);
1.296
1.297 - if (((jzfb.cfg & MODE_MASK) == MODE_STN_COLOR_SINGLE) ||
1.298 - ((jzfb.cfg & MODE_MASK) == MODE_STN_COLOR_DUAL) ||
1.299 - ((jzfb.cfg & MODE_MASK) == MODE_STN_MONO_SINGLE) ||
1.300 - ((jzfb.cfg & MODE_MASK) == MODE_STN_MONO_DUAL))
1.301 - pclk = pclk >> ((jzfb.cfg & STN_DAT_PINMASK) >> 4);
1.302 + if (((jzfb->cfg & MODE_MASK) == MODE_STN_COLOR_SINGLE) ||
1.303 + ((jzfb->cfg & MODE_MASK) == MODE_STN_COLOR_DUAL) ||
1.304 + ((jzfb->cfg & MODE_MASK) == MODE_STN_MONO_SINGLE) ||
1.305 + ((jzfb->cfg & MODE_MASK) == MODE_STN_MONO_DUAL))
1.306 + pclk = pclk >> ((jzfb->cfg & STN_DAT_PINMASK) >> 4);
1.307
1.308 - if (((jzfb.cfg & MODE_MASK) == MODE_STN_COLOR_DUAL) ||
1.309 - ((jzfb.cfg & MODE_MASK) == MODE_STN_MONO_DUAL))
1.310 + if (((jzfb->cfg & MODE_MASK) == MODE_STN_COLOR_DUAL) ||
1.311 + ((jzfb->cfg & MODE_MASK) == MODE_STN_MONO_DUAL))
1.312 pclk >>= 1;
1.313
1.314 return pclk;
1.315 @@ -358,12 +363,13 @@
1.316
1.317 static int jz_lcd_hw_init(vidinfo_t *vid)
1.318 {
1.319 - struct jz_fb_info *fbi = &vid->jz_fb;
1.320 + struct jzfb_info *jzfb = vid->jz_fb;
1.321 + struct jz_mem_info *fbi = &vid->jz_mem;
1.322 uint32_t val = 0;
1.323 - uint32_t pclk = jz_lcd_get_pixel_clock();
1.324 + uint32_t pclk = jz_lcd_get_pixel_clock(vid);
1.325
1.326 /* Setting Control register */
1.327 - switch (jzfb.bpp) {
1.328 + switch (jzfb->bpp) {
1.329 case 1:
1.330 val |= LCD_CTRL_BPP_1;
1.331 break;
1.332 @@ -387,38 +393,38 @@
1.333 break;
1.334 #endif
1.335 default:
1.336 - /* printf("jz_lcd.c The BPP %d is not supported\n", jzfb.bpp); */
1.337 + /* printf("jz_lcd.c The BPP %d is not supported\n", jzfb->bpp); */
1.338 val |= LCD_CTRL_BPP_16;
1.339 break;
1.340 }
1.341
1.342 - switch (jzfb.cfg & MODE_MASK) {
1.343 + switch (jzfb->cfg & MODE_MASK) {
1.344 case MODE_STN_MONO_DUAL:
1.345 case MODE_STN_COLOR_DUAL:
1.346 - val |= jz_lcd_stn_init(jzfb.h >> 1);
1.347 + val |= jz_lcd_stn_init(jzfb->h >> 1, vid);
1.348 break;
1.349
1.350 case MODE_STN_MONO_SINGLE:
1.351 case MODE_STN_COLOR_SINGLE:
1.352 - val |= jz_lcd_stn_init(jzfb.h);
1.353 + val |= jz_lcd_stn_init(jzfb->h, vid);
1.354 break;
1.355
1.356 case MODE_TFT_GEN:
1.357 case MODE_TFT_CASIO:
1.358 case MODE_8BIT_SERIAL_TFT:
1.359 case MODE_TFT_18BIT:
1.360 - jz_lcd_tft_init();
1.361 + jz_lcd_tft_init(vid);
1.362 break;
1.363
1.364 case MODE_TFT_SAMSUNG:
1.365 {
1.366 - jz_lcd_samsung_init(pclk);
1.367 + jz_lcd_samsung_init(pclk, vid);
1.368 break;
1.369 }
1.370
1.371 case MODE_TFT_SHARP:
1.372 {
1.373 - jz_lcd_sharp_init();
1.374 + jz_lcd_sharp_init(vid);
1.375 break;
1.376 }
1.377
1.378 @@ -431,7 +437,7 @@
1.379 val |= LCD_CTRL_BST_16; /* Burst Length is 16WORD=64Byte */
1.380 val |= LCD_CTRL_OFUP; /* OutFIFO underrun protect */
1.381 REG_LCD_CTRL = val;
1.382 - REG_LCD_CFG = jzfb.cfg;
1.383 + REG_LCD_CFG = jzfb->cfg;
1.384
1.385 /* Timing reset. */
1.386
1.387 @@ -444,30 +450,20 @@
1.388
1.389 REG_LCD_DA0 = (uint32_t) fbi->fdadr0; /* frame descriptor */
1.390
1.391 - if (((jzfb.cfg & MODE_MASK) == MODE_STN_COLOR_DUAL) ||
1.392 - ((jzfb.cfg & MODE_MASK) == MODE_STN_MONO_DUAL))
1.393 + if (((jzfb->cfg & MODE_MASK) == MODE_STN_COLOR_DUAL) ||
1.394 + ((jzfb->cfg & MODE_MASK) == MODE_STN_MONO_DUAL))
1.395 REG_LCD_DA1 = (uint32_t) fbi->fdadr1; /* frame descriptor */
1.396
1.397 return 0;
1.398 }
1.399
1.400 -static inline uint8_t LCD_CODE(uint8_t bpp)
1.401 -{
1.402 - uint8_t code = 0;
1.403 - while (bpp && !(bpp & 1))
1.404 - {
1.405 - bpp >>= 1;
1.406 - code += 1;
1.407 - }
1.408 - return code;
1.409 -}
1.410 -
1.411 /* Public operations. */
1.412
1.413 void lcd_set_bpp(uint8_t bpp)
1.414 {
1.415 - jzfb.bpp = bpp;
1.416 - panel_info.vl_bpix = LCD_CODE(bpp);
1.417 + vidinfo_t *vid = &panel_info;
1.418 + struct jzfb_info *jzfb = vid->jz_fb;
1.419 + jzfb->bpp = bpp;
1.420 }
1.421
1.422 void lcd_enable()
1.423 @@ -500,19 +496,19 @@
1.424
1.425 static void lcd_init_palette(vidinfo_t *vid)
1.426 {
1.427 - uint16_t *palette = (uint16_t *) lcd_get_palette(get_memory_size());
1.428 - uint16_t *end = (uint16_t *) palette + NCOLORS(vid->vl_bpix);
1.429 + uint16_t *palette = (uint16_t *) lcd_get_palette(get_memory_size(), vid);
1.430 + uint16_t *end = (uint16_t *) palette + (1 << (vid->jz_fb->bpp));
1.431 uint8_t value = 0;
1.432
1.433 while (palette < end)
1.434 {
1.435 - switch (vid->vl_bpix)
1.436 + switch (vid->jz_fb->bpp)
1.437 {
1.438 - case LCD_COLOR4:
1.439 + case 4:
1.440 *palette = rgb4_to_rgb16(value);
1.441 break;
1.442
1.443 - case LCD_COLOR8:
1.444 + case 8:
1.445 default:
1.446 *palette = rgb8_to_rgb16(value);
1.447 break;
1.448 @@ -525,18 +521,19 @@
1.449
1.450 uint32_t lcd_ctrl_init()
1.451 {
1.452 - struct jz_fb_info *fbi = &panel_info.jz_fb;
1.453 + vidinfo_t *vid = &panel_info;
1.454 + struct jz_mem_info *fbi = &vid->jz_mem;
1.455
1.456 /* Start from the top of memory and obtain palette and framebuffer regions. */
1.457
1.458 - fbi->screen = lcd_get_framebuffer(get_memory_size(), 0);
1.459 - fbi->palette = lcd_get_palette(get_memory_size());
1.460 + fbi->screen = lcd_get_framebuffer(get_memory_size(), 0, vid);
1.461 + fbi->palette = lcd_get_palette(get_memory_size(), vid);
1.462
1.463 - if (NBITS(panel_info.vl_bpix) < 12)
1.464 - lcd_init_palette(&panel_info);
1.465 + if (vid->jz_fb->bpp < 12)
1.466 + lcd_init_palette(vid);
1.467
1.468 - jz_lcd_desc_init(&panel_info);
1.469 - jz_lcd_hw_init(&panel_info);
1.470 + jz_lcd_desc_init(vid);
1.471 + jz_lcd_hw_init(vid);
1.472
1.473 return fbi->screen;
1.474 }
2.1 --- a/stage2/jzlcd.h Thu Jun 29 23:26:39 2017 +0200
2.2 +++ b/stage2/jzlcd.h Sat Jul 08 21:06:58 2017 +0200
2.3 @@ -37,9 +37,9 @@
2.4 */
2.5 struct jzfb_info {
2.6 uint32_t cfg; /* panel mode and pin usage etc. */
2.7 - uint32_t w;
2.8 - uint32_t h;
2.9 - uint32_t bpp; /* bit per pixel */
2.10 + uint16_t w;
2.11 + uint16_t h;
2.12 + uint8_t bpp; /* bit per pixel */
2.13 uint32_t fclk; /* frame clk */
2.14 uint32_t hsw; /* hsync width, in pclk */
2.15 uint32_t vsw; /* vsync width, in line count */
2.16 @@ -62,7 +62,7 @@
2.17 /*
2.18 * Jz LCD info
2.19 */
2.20 -struct jz_fb_info {
2.21 +struct jz_mem_info {
2.22
2.23 struct jz_fb_dma_descriptor *fdadr0; /* physical address of frame/palette descriptor */
2.24 struct jz_fb_dma_descriptor *fdadr1; /* physical address of frame descriptor */
2.25 @@ -80,11 +80,8 @@
2.26 * Concise display characteristics with low-level structure reference
2.27 */
2.28 typedef struct vidinfo {
2.29 - uint16_t vl_col; /* Number of columns (i.e. 640) */
2.30 - uint16_t vl_row; /* Number of rows (i.e. 480) */
2.31 - uint8_t vl_bpix; /* Bits per pixel, 0 = 1, 1 = 2, 2 = 4, 3 = 8 */
2.32 -
2.33 - struct jz_fb_info jz_fb;
2.34 + struct jz_mem_info jz_mem;
2.35 + struct jzfb_info *jz_fb;
2.36 } vidinfo_t;
2.37
2.38 /* Alignment/rounding macros. */
2.39 @@ -92,20 +89,6 @@
2.40 #define ALIGN(x,a) __ALIGN_MASK((x),(typeof(x))(a)-1)
2.41 #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
2.42
2.43 -/* General values for colour depths and framebuffer characteristics. */
2.44 -
2.45 -#define LCD_MONOCHROME 0
2.46 -#define LCD_COLOR2 1
2.47 -#define LCD_COLOR4 2
2.48 -#define LCD_COLOR8 3
2.49 -#define LCD_COLOR16 4
2.50 -#define LCD_COLOR32 5
2.51 -
2.52 -/* Calculate number of bits per pixel and number of colours. */
2.53 -
2.54 -#define NBITS(bit_code) (1 << (bit_code))
2.55 -#define NCOLORS(bit_code) (1 << NBITS(bit_code))
2.56 -
2.57 /* Transfer and display types. */
2.58
2.59 #define MODE_MASK 0x0f
3.1 --- a/stage2/lcd.c Thu Jun 29 23:26:39 2017 +0200
3.2 +++ b/stage2/lcd.c Sat Jul 08 21:06:58 2017 +0200
3.3 @@ -25,34 +25,35 @@
3.4 #include "board.h"
3.5
3.6 extern vidinfo_t panel_info;
3.7 -static unsigned long lcd_base;
3.8 +extern struct jzfb_info jzfb;
3.9 +static uint32_t lcd_base;
3.10
3.11 -static unsigned int get_line_length()
3.12 +static uint16_t get_line_length()
3.13 {
3.14 - return ALIGN((panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8, sizeof(uint32_t));
3.15 + return ALIGN((panel_info.jz_fb->w * panel_info.jz_fb->bpp) / 8, sizeof(uint32_t));
3.16 }
3.17
3.18 -static uint32_t *get_pixel32(unsigned short h, unsigned short v)
3.19 +static uint32_t *get_pixel32(uint16_t h, uint16_t v)
3.20 {
3.21 return (uint32_t *) (lcd_base + v * get_line_length()) + h;
3.22 }
3.23
3.24 -static uint16_t *get_pixel16(unsigned short h, unsigned short v)
3.25 +static uint16_t *get_pixel16(uint16_t h, uint16_t v)
3.26 {
3.27 return (uint16_t *) (lcd_base + v * get_line_length()) + h;
3.28 }
3.29
3.30 -static uint8_t *get_pixel8(unsigned short h, unsigned short v)
3.31 +static uint8_t *get_pixel8(uint16_t h, uint16_t v)
3.32 {
3.33 return (uint8_t *) (lcd_base + v * get_line_length()) + h;
3.34 }
3.35
3.36 -static uint8_t *get_pixel4(unsigned short h, unsigned short v)
3.37 +static uint8_t *get_pixel4(uint16_t h, uint16_t v)
3.38 {
3.39 return (uint8_t *) (lcd_base + v * get_line_length()) + h / 2;
3.40 }
3.41
3.42 -static inline unsigned short div(unsigned short num, unsigned short denom, unsigned short scale)
3.43 +static inline uint16_t div(uint16_t num, uint16_t denom, uint16_t scale)
3.44 {
3.45 return (scale * num) / denom;
3.46 }
3.47 @@ -62,69 +63,69 @@
3.48 return (div(r, 255, rmax) << rshift) | (div(g, 255, gmax) << gshift) | (div(b, 255, bmax) << bshift);
3.49 }
3.50
3.51 -uint32_t get_bitmap_value(unsigned short x, uint32_t value)
3.52 +uint32_t get_bitmap_value(uint16_t x, uint32_t value)
3.53 {
3.54 - return (value >> (((panel_info.vl_col - 1 - x) * 32) / panel_info.vl_col)) % 2 ? 0xffffffff : 0;
3.55 + return (value >> (((panel_info.jz_fb->w - 1 - x) * 32) / panel_info.jz_fb->w)) % 2 ? 0xffffffff : 0;
3.56 }
3.57
3.58 -static void get_colour(unsigned short h, unsigned short v, uint8_t rgb[], unsigned short pixel_type)
3.59 +static void get_colour(uint16_t h, uint16_t v, uint8_t rgb[], uint16_t pixel_type)
3.60 {
3.61 - unsigned short v_max = panel_info.vl_row - 1;
3.62 - unsigned short h_max = panel_info.vl_col - 1;
3.63 + uint16_t v_max = panel_info.jz_fb->h - 1;
3.64 + uint16_t h_max = panel_info.jz_fb->w - 1;
3.65
3.66 rgb[(pixel_type - 1) % 3] = div(h, h_max, 255);
3.67 rgb[pixel_type % 3] = div(v, v_max, 255);
3.68 rgb[(pixel_type + 1) % 3] = (rgb[0] + rgb[1]) / 2;
3.69 }
3.70
3.71 -static void set_pixel32(unsigned short h, unsigned short v, uint32_t value)
3.72 +static void set_pixel32(uint16_t h, uint16_t v, uint32_t value)
3.73 {
3.74 uint32_t *pix = get_pixel32(h, v);
3.75 *pix = value;
3.76 }
3.77
3.78 -static void set_pixel16_565(unsigned short h, unsigned short v, uint32_t value)
3.79 +static void set_pixel16_565(uint16_t h, uint16_t v, uint32_t value)
3.80 {
3.81 uint16_t *pix = get_pixel16(h, v);
3.82 *pix = (uint16_t) value;
3.83 }
3.84
3.85 -static void set_pixel8(unsigned short h, unsigned short v, uint32_t value)
3.86 +static void set_pixel8(uint16_t h, uint16_t v, uint32_t value)
3.87 {
3.88 uint8_t *pix = get_pixel8(h, v);
3.89 *pix = (uint8_t) value;
3.90 }
3.91
3.92 -static void set_pixel4(unsigned short h, unsigned short v, uint32_t value)
3.93 +static void set_pixel4(uint16_t h, uint16_t v, uint32_t value)
3.94 {
3.95 uint8_t *pix = get_pixel4(h, v);
3.96 uint8_t mask = h & 1 ? 0xf0 : 0x0f;
3.97 *pix = (*pix & mask) | ((uint8_t) value);
3.98 }
3.99
3.100 -void set_pixel(unsigned short h, unsigned short v, uint32_t value)
3.101 +void set_pixel(uint16_t h, uint16_t v, uint32_t value)
3.102 {
3.103 - switch (panel_info.vl_bpix)
3.104 + switch (panel_info.jz_fb->bpp)
3.105 {
3.106 - case LCD_COLOR32:
3.107 + case 32:
3.108 set_pixel32(h, v, value);
3.109 break;
3.110
3.111 - case LCD_COLOR8:
3.112 + case 8:
3.113 set_pixel8(h, v, value);
3.114 break;
3.115
3.116 - case LCD_COLOR4:
3.117 + case 4:
3.118 set_pixel4(h, v, value);
3.119 break;
3.120
3.121 - case LCD_COLOR16:
3.122 + case 16:
3.123 default:
3.124 set_pixel16_565(h, v, value);
3.125 break;
3.126 }
3.127 }
3.128 -static void test_pixel32(unsigned short h, unsigned short v, unsigned short pixel_type)
3.129 +static void test_pixel32(uint16_t h, uint16_t v, uint16_t pixel_type)
3.130 {
3.131 uint8_t rgb[3];
3.132
3.133 @@ -132,7 +133,7 @@
3.134 set_pixel32(h, v, pixel(rgb[0], rgb[1], rgb[2], 255, 255, 255, 16, 8, 0) | get_bitmap_value(h, pixel_type));
3.135 }
3.136
3.137 -static void test_pixel16_565(unsigned short h, unsigned short v, unsigned short pixel_type)
3.138 +static void test_pixel16_565(uint16_t h, uint16_t v, uint16_t pixel_type)
3.139 {
3.140 uint8_t rgb[3];
3.141
3.142 @@ -140,7 +141,7 @@
3.143 set_pixel16_565(h, v, pixel(rgb[0], rgb[1], rgb[2], 31, 63, 31, 11, 5, 0) | get_bitmap_value(h, pixel_type));
3.144 }
3.145
3.146 -static void test_pixel8(unsigned short h, unsigned short v, unsigned short pixel_type)
3.147 +static void test_pixel8(uint16_t h, uint16_t v, uint16_t pixel_type)
3.148 {
3.149 uint8_t rgb[3];
3.150
3.151 @@ -148,7 +149,7 @@
3.152 set_pixel8(h, v, pixel(rgb[0], rgb[1], rgb[2], 7, 7, 3, 5, 2, 0) | get_bitmap_value(h, pixel_type));
3.153 }
3.154
3.155 -static void test_pixel4(unsigned short h, unsigned short v, unsigned short pixel_type)
3.156 +static void test_pixel4(uint16_t h, uint16_t v, uint16_t pixel_type)
3.157 {
3.158 uint8_t rgb[3];
3.159
3.160 @@ -156,71 +157,71 @@
3.161 set_pixel4(h, v, pixel(rgb[0], rgb[1], rgb[2], 1, 2, 1, 3, 1, 0) | get_bitmap_value(h, pixel_type));
3.162 }
3.163
3.164 -void test_pixel(unsigned short h, unsigned short v, unsigned short pixel_type)
3.165 +void test_pixel(uint16_t h, uint16_t v, uint16_t pixel_type)
3.166 {
3.167 - switch (panel_info.vl_bpix)
3.168 + switch (panel_info.jz_fb->bpp)
3.169 {
3.170 - case LCD_COLOR32:
3.171 + case 32:
3.172 test_pixel32(h, v, pixel_type);
3.173 break;
3.174
3.175 - case LCD_COLOR8:
3.176 + case 8:
3.177 test_pixel8(h, v, pixel_type);
3.178 break;
3.179
3.180 - case LCD_COLOR4:
3.181 + case 4:
3.182 test_pixel4(h, v, pixel_type);
3.183 break;
3.184
3.185 - case LCD_COLOR16:
3.186 + case 16:
3.187 default:
3.188 test_pixel16_565(h, v, pixel_type);
3.189 break;
3.190 }
3.191 }
3.192
3.193 -void clear_pixel32(unsigned short h, unsigned short v)
3.194 +void clear_pixel32(uint16_t h, uint16_t v)
3.195 {
3.196 uint32_t *pix = get_pixel32(h, v);
3.197 *pix = 0;
3.198 }
3.199
3.200 -void clear_pixel16(unsigned short h, unsigned short v)
3.201 +void clear_pixel16(uint16_t h, uint16_t v)
3.202 {
3.203 uint16_t *pix = get_pixel16(h, v);
3.204 *pix = 0;
3.205 }
3.206
3.207 -void clear_pixel8(unsigned short h, unsigned short v)
3.208 +void clear_pixel8(uint16_t h, uint16_t v)
3.209 {
3.210 uint8_t *pix = get_pixel8(h, v);
3.211 *pix = 0;
3.212 }
3.213
3.214 -void clear_pixel4(unsigned short h, unsigned short v)
3.215 +void clear_pixel4(uint16_t h, uint16_t v)
3.216 {
3.217 uint8_t *pix = get_pixel4(h, v);
3.218 uint8_t mask = h & 1 ? 0xf0 : 0x0f;
3.219 *pix = *pix & mask;
3.220 }
3.221
3.222 -void clear_pixel(unsigned short h, unsigned short v)
3.223 +void clear_pixel(uint16_t h, uint16_t v)
3.224 {
3.225 - switch (panel_info.vl_bpix)
3.226 + switch (panel_info.jz_fb->bpp)
3.227 {
3.228 - case LCD_COLOR32:
3.229 + case 32:
3.230 clear_pixel32(h, v);
3.231 break;
3.232
3.233 - case LCD_COLOR8:
3.234 + case 8:
3.235 clear_pixel8(h, v);
3.236 break;
3.237
3.238 - case LCD_COLOR4:
3.239 + case 4:
3.240 clear_pixel4(h, v);
3.241 break;
3.242
3.243 - case LCD_COLOR16:
3.244 + case 16:
3.245 default:
3.246 clear_pixel16(h, v);
3.247 break;
3.248 @@ -229,9 +230,9 @@
3.249
3.250 void test_pattern()
3.251 {
3.252 - unsigned short v_max = panel_info.vl_row;
3.253 - unsigned short h_max = panel_info.vl_col;
3.254 - unsigned short v, h;
3.255 + uint16_t v_max = panel_info.jz_fb->h;
3.256 + uint16_t h_max = panel_info.jz_fb->w;
3.257 + uint16_t v, h;
3.258
3.259 for (v = 0; v < v_max; v += 1) {
3.260 for (h = 0; h < h_max; h += 1) {
3.261 @@ -240,12 +241,12 @@
3.262 }
3.263 }
3.264
3.265 -void lcd_clear(unsigned long lcd_base)
3.266 +void lcd_clear(uint32_t lcd_base)
3.267 {
3.268 - unsigned short v_max = panel_info.vl_row;
3.269 - unsigned short h_max = panel_info.vl_col;
3.270 - unsigned short v, h;
3.271 - unsigned long *pix = (unsigned long *)lcd_base;
3.272 + uint16_t v_max = panel_info.jz_fb->h;
3.273 + uint16_t h_max = panel_info.jz_fb->w;
3.274 + uint16_t v, h;
3.275 + uint32_t *pix = (uint32_t *)lcd_base;
3.276
3.277 for (v = 0; v < v_max; v += 1) {
3.278 for (h = 0; h < h_max; h += 1) {
3.279 @@ -261,6 +262,10 @@
3.280 __lcd_display_pin_init();
3.281 __lcd_display_on();
3.282
3.283 + /* Initialise the member here since the address is otherwise invalid. */
3.284 +
3.285 + panel_info.jz_fb = (struct jzfb_info *) ((uint32_t) &jzfb & ~0x80000000);
3.286 +
3.287 lcd_base = lcd_ctrl_init();
3.288 lcd_clear(lcd_base);
3.289 lcd_enable();
4.1 --- a/stage2/lcd.h Thu Jun 29 23:26:39 2017 +0200
4.2 +++ b/stage2/lcd.h Sat Jul 08 21:06:58 2017 +0200
4.3 @@ -9,10 +9,10 @@
4.4
4.5 /* Output functions. */
4.6
4.7 -uint32_t get_bitmap_value(unsigned short, uint32_t);
4.8 -void set_pixel(unsigned short, unsigned short, uint32_t);
4.9 -void test_pixel(unsigned short, unsigned short, unsigned short);
4.10 -void clear_pixel(unsigned short, unsigned short);
4.11 +uint32_t get_bitmap_value(uint16_t, uint32_t);
4.12 +void set_pixel(uint16_t, uint16_t, uint32_t);
4.13 +void test_pixel(uint16_t, uint16_t, uint16_t);
4.14 +void clear_pixel(uint16_t, uint16_t);
4.15
4.16 void test_pattern();
4.17
5.1 --- a/stage2/minipc_claa070vc01.c Thu Jun 29 23:26:39 2017 +0200
5.2 +++ b/stage2/minipc_claa070vc01.c Sat Jul 08 21:06:58 2017 +0200
5.3 @@ -2,7 +2,7 @@
5.4 * MiniPC screen details
5.5 *
5.6 * Copyright (C) 2005-2007, Ingenic Semiconductor Inc.
5.7 - * Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk>
5.8 + * Copyright (C) 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
5.9 *
5.10 * This program is free software; you can redistribute it and/or
5.11 * modify it under the terms of the GNU General Public License as
5.12 @@ -29,6 +29,4 @@
5.13 800, 480, 32, 60, 80, 20, 0, 0, 0, 0
5.14 };
5.15
5.16 -vidinfo_t panel_info = {
5.17 - 800, 480, LCD_COLOR32,
5.18 -};
5.19 +vidinfo_t panel_info;
6.1 --- a/stage2/nanonote_gpm940b0.c Thu Jun 29 23:26:39 2017 +0200
6.2 +++ b/stage2/nanonote_gpm940b0.c Sat Jul 08 21:06:58 2017 +0200
6.3 @@ -34,6 +34,4 @@
6.4 .efw=1, .bfw=20 /* frame limits */
6.5 };
6.6
6.7 -vidinfo_t panel_info = {
6.8 - 320, 240, LCD_COLOR32,
6.9 -};
6.10 +vidinfo_t panel_info;
7.1 --- a/stage2/tasks/example.c Thu Jun 29 23:26:39 2017 +0200
7.2 +++ b/stage2/tasks/example.c Sat Jul 08 21:06:58 2017 +0200
7.3 @@ -27,10 +27,10 @@
7.4 void next_pixel(uint16_t *x, uint16_t *y)
7.5 {
7.6 (*x)++;
7.7 - if (*x >= panel_info.vl_col) {
7.8 + if (*x >= panel_info.jz_fb->w) {
7.9 *x = 0;
7.10 (*y)++;
7.11 - if (*y >= panel_info.vl_row)
7.12 + if (*y >= panel_info.jz_fb->h)
7.13 *y = 0;
7.14 }
7.15 }
7.16 @@ -50,7 +50,7 @@
7.17
7.18 void start_plot_pattern(uint8_t task)
7.19 {
7.20 - uint32_t args[] = {task, 0, (task * (panel_info.vl_row / 4)) % panel_info.vl_row};
7.21 + uint32_t args[] = {task, 0, (task * (panel_info.jz_fb->h / 4)) % panel_info.jz_fb->h};
7.22
7.23 start_task(task, (void (*)()) plot_pattern, args, 3);
7.24 }
8.1 --- a/stage2/tasks/keyscan.c Thu Jun 29 23:26:39 2017 +0200
8.2 +++ b/stage2/tasks/keyscan.c Sat Jul 08 21:06:58 2017 +0200
8.3 @@ -30,11 +30,11 @@
8.4 uint16_t x, y;
8.5 uint32_t pixel;
8.6
8.7 - for (y = ymin; (y < panel_info.vl_row) && (y < ymax); y++)
8.8 + for (y = ymin; (y < panel_info.jz_fb->h) && (y < ymax); y++)
8.9 {
8.10 pixel = (value >> (((y - ymin) * 8) / (ymax - ymin))) % 2 ? 0xffffffff : 0;
8.11
8.12 - for (x = xmin; (x < panel_info.vl_col) && (x < xmax); x++)
8.13 + for (x = xmin; (x < panel_info.jz_fb->w) && (x < xmax); x++)
8.14 {
8.15 set_pixel(x, y, pixel);
8.16 }