1.1 --- a/include/minipc.h Mon Jan 25 18:01:52 2016 +0100
1.2 +++ b/include/minipc.h Mon Jan 25 18:04:21 2016 +0100
1.3 @@ -3,7 +3,7 @@
1.4 *
1.5 * Copyright (C) 2009 Qi Hardware Inc.
1.6 * Authors: Xiangfu Liu <xiangfu@openmobilefree.net>
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 modify
1.11 * it under the terms of the GNU General Public License as published by
1.12 @@ -23,11 +23,6 @@
1.13 #define __MINIPC_H__
1.14
1.15 /*
1.16 - * Display configuration
1.17 - */
1.18 -#define LCD_BPP LCD_COLOR32
1.19 -
1.20 -/*
1.21 * GPIO definition
1.22 */
1.23 #define GPIO_LED_EN 92
2.1 --- a/include/nanonote.h Mon Jan 25 18:01:52 2016 +0100
2.2 +++ b/include/nanonote.h Mon Jan 25 18:04:21 2016 +0100
2.3 @@ -3,7 +3,7 @@
2.4 *
2.5 * Copyright (C) 2009 Qi Hardware Inc.
2.6 * Authors: Xiangfu Liu <xiangfu@openmobilefree.net>
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 modify
2.11 * it under the terms of the GNU General Public License as published by
2.12 @@ -23,11 +23,6 @@
2.13 #define __NANONOTE_H__
2.14
2.15 /*
2.16 - * Display configuration
2.17 - */
2.18 -#define LCD_BPP LCD_COLOR32
2.19 -
2.20 -/*
2.21 * GPIO definition
2.22 * See: http://en.qi-hardware.com/wiki/Hardware_basics
2.23 */
3.1 --- a/stage2/jzlcd.c Mon Jan 25 18:01:52 2016 +0100
3.2 +++ b/stage2/jzlcd.c Mon Jan 25 18:04:21 2016 +0100
3.3 @@ -25,9 +25,6 @@
3.4 #include "cpu.h"
3.5 #include "board.h"
3.6
3.7 -#define ALIGN(x,a) __ALIGN_MASK((x),(typeof(x))(a)-1)
3.8 -#define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
3.9 -
3.10 #define align2(n) (n)=((((n)+1)>>1)<<1)
3.11 #define align4(n) (n)=((((n)+3)>>2)<<2)
3.12 #define align8(n) (n)=((((n)+7)>>3)<<3)
3.13 @@ -35,44 +32,79 @@
3.14 extern struct jzfb_info jzfb;
3.15 extern vidinfo_t panel_info;
3.16
3.17 +static unsigned short lcd_get_panels()
3.18 +{
3.19 + return ((jzfb.cfg & MODE_MASK) == MODE_STN_MONO_DUAL) ||
3.20 + ((jzfb.cfg & MODE_MASK) == MODE_STN_COLOR_DUAL) ? 2 : 1;
3.21 +}
3.22 +
3.23 static unsigned long lcd_get_size(vidinfo_t *vid)
3.24 {
3.25 - int line_length = (vid->vl_col * NBITS(vid->vl_bpix)) / 8;
3.26 + /* Lines must be aligned to a word boundary. */
3.27 + unsigned long line_length = ALIGN((vid->vl_col * NBITS(vid->vl_bpix)) / 8, sizeof(u32));
3.28 return line_length * vid->vl_row;
3.29 }
3.30
3.31 +static unsigned long lcd_get_aligned_size(vidinfo_t *vid)
3.32 +{
3.33 + /* LCD_CTRL_BST_16 requires 16-word alignment. */
3.34 + return ALIGN(lcd_get_size(vid), 16 * sizeof(u32));
3.35 +}
3.36 +
3.37 +static unsigned long lcd_get_min_size(vidinfo_t *vid)
3.38 +{
3.39 + /* Lines must be aligned to a word boundary. */
3.40 + unsigned long line_length = ALIGN((vid->vl_col * 32) / 8, sizeof(u32));
3.41 + return line_length * vid->vl_row;
3.42 +}
3.43 +
3.44 +static unsigned long lcd_get_aligned_min_size(vidinfo_t *vid)
3.45 +{
3.46 + /* LCD_CTRL_BST_16 requires 16-word alignment. */
3.47 + return ALIGN(lcd_get_min_size(vid), 16 * sizeof(u32));
3.48 +}
3.49 +
3.50 static unsigned long lcd_get_palette_size()
3.51 {
3.52 return 256 * sizeof(u16);
3.53 }
3.54
3.55 +static unsigned long lcd_get_aligned_palette_size()
3.56 +{
3.57 + /* LCD_CTRL_BST_16 requires 16-word alignment. */
3.58 + return ALIGN(lcd_get_palette_size(), 16 * sizeof(u32));
3.59 +}
3.60 +
3.61 static unsigned long lcd_get_descriptors_size()
3.62 {
3.63 return 3 * sizeof(struct jz_fb_dma_descriptor);
3.64 }
3.65
3.66 -static unsigned long lcd_get_aligned_size(vidinfo_t *vid)
3.67 +static unsigned long lcd_get_total_size(vidinfo_t *vid)
3.68 {
3.69 - /* Round up to nearest full page, or MMU section if defined */
3.70 - return ALIGN(lcd_get_size(vid) + lcd_get_palette_size() + lcd_get_descriptors_size(), PAGE_SIZE);
3.71 + unsigned long size = lcd_get_aligned_size(vid) * lcd_get_panels();
3.72 + unsigned long min_size = lcd_get_aligned_min_size(vid);
3.73 +
3.74 + /* Round up to nearest full page, or MMU section if defined. */
3.75 + return ALIGN((size >= min_size ? size : min_size) + lcd_get_aligned_palette_size() + lcd_get_descriptors_size(), PAGE_SIZE);
3.76 }
3.77
3.78 static unsigned long lcd_get_palette(unsigned long addr)
3.79 {
3.80 /* Allocate memory at the end of the region for the palette. */
3.81 - return addr - lcd_get_palette_size();
3.82 + return addr - lcd_get_aligned_palette_size();
3.83 }
3.84
3.85 static unsigned long lcd_get_descriptors(unsigned long addr)
3.86 {
3.87 /* Allocate memory before the palette for the descriptor array. */
3.88 - return addr - lcd_get_palette_size() - lcd_get_descriptors_size();
3.89 + return lcd_get_palette(addr) - lcd_get_descriptors_size();
3.90 }
3.91
3.92 -static unsigned long lcd_get_framebuffer(unsigned long addr)
3.93 +static unsigned long lcd_get_framebuffer(unsigned long addr, unsigned short panel)
3.94 {
3.95 /* Allocate pages for the frame buffer and palette. */
3.96 - return addr - lcd_get_aligned_size(&panel_info);
3.97 + return addr - lcd_get_total_size(&panel_info) + (panel * lcd_get_aligned_size(&panel_info));
3.98 }
3.99
3.100 static void jz_lcd_desc_init(vidinfo_t *vid);
3.101 @@ -84,9 +116,8 @@
3.102
3.103 /* Start from the top of memory and obtain palette and framebuffer regions. */
3.104
3.105 - fbi->screen = lcd_get_framebuffer(get_memory_size());
3.106 + fbi->screen = lcd_get_framebuffer(get_memory_size(), 0);
3.107 fbi->palette = lcd_get_palette(get_memory_size());
3.108 - fbi->palette_size = 256;
3.109
3.110 jz_lcd_desc_init(&panel_info);
3.111 jz_lcd_hw_init(&panel_info);
3.112 @@ -124,22 +155,25 @@
3.113
3.114 /* Populate descriptors. */
3.115
3.116 - fbi->dmadesc_fblow->fdadr = fbi->dmadesc_fblow;
3.117 - fbi->dmadesc_fblow->fsadr = fbi->screen + lcd_get_size(vid);
3.118 - fbi->dmadesc_fblow->fidr = 0;
3.119 - fbi->dmadesc_fblow->ldcmd = lcd_get_size(vid) / 4 ;
3.120 + if (lcd_get_panels() == 2)
3.121 + {
3.122 + fbi->dmadesc_fblow->fdadr = fbi->dmadesc_fblow;
3.123 + fbi->dmadesc_fblow->fsadr = lcd_get_framebuffer(get_memory_size(), 1);
3.124 + fbi->dmadesc_fblow->fidr = 0;
3.125 + fbi->dmadesc_fblow->ldcmd = lcd_get_size(vid) / 4 ;
3.126
3.127 - fbi->fdadr1 = fbi->dmadesc_fblow; /* only used in dual-panel mode */
3.128 + fbi->fdadr1 = fbi->dmadesc_fblow; /* only used in dual-panel mode */
3.129 + }
3.130
3.131 fbi->dmadesc_fbhigh->fsadr = fbi->screen;
3.132 fbi->dmadesc_fbhigh->fidr = 0;
3.133 - fbi->dmadesc_fbhigh->ldcmd = lcd_get_size(vid) / 4; /* length in word */
3.134 + fbi->dmadesc_fbhigh->ldcmd = lcd_get_size(vid) / 4; /* length in words */
3.135
3.136 fbi->dmadesc_palette->fsadr = fbi->palette;
3.137 fbi->dmadesc_palette->fidr = 0;
3.138 - fbi->dmadesc_palette->ldcmd = (fbi->palette_size * 2)/4 | (1<<28);
3.139 + fbi->dmadesc_palette->ldcmd = (lcd_get_palette_size() / 4) | (1<<28);
3.140
3.141 - if(NBITS(vid->vl_bpix) < 12)
3.142 + if (NBITS(vid->vl_bpix) < 12)
3.143 {
3.144 /* assume any mode with <12 bpp is palette driven */
3.145 fbi->dmadesc_palette->fdadr = fbi->dmadesc_fbhigh;
4.1 --- a/stage2/jzlcd.h Mon Jan 25 18:01:52 2016 +0100
4.2 +++ b/stage2/jzlcd.h Mon Jan 25 18:04:21 2016 +0100
4.3 @@ -71,7 +71,6 @@
4.4
4.5 unsigned long screen; /* address of frame buffer */
4.6 unsigned long palette; /* address of palette memory */
4.7 - unsigned int palette_size;
4.8 };
4.9
4.10 /*
4.11 @@ -85,6 +84,11 @@
4.12 struct jz_fb_info jz_fb;
4.13 } vidinfo_t;
4.14
4.15 +/* Alignment/rounding macros. */
4.16 +
4.17 +#define ALIGN(x,a) __ALIGN_MASK((x),(typeof(x))(a)-1)
4.18 +#define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
4.19 +
4.20 /* General values for colour depths and framebuffer characteristics. */
4.21
4.22 #define LCD_MONOCHROME 0
5.1 --- a/stage2/lcd.c Mon Jan 25 18:01:52 2016 +0100
5.2 +++ b/stage2/lcd.c Mon Jan 25 18:04:21 2016 +0100
5.3 @@ -33,49 +33,89 @@
5.4
5.5 extern vidinfo_t panel_info;
5.6 static unsigned long lcd_base;
5.7 -unsigned long irq_counter = 0;
5.8
5.9 -void test_pixel(unsigned short h, unsigned short v)
5.10 +static unsigned int get_line_length()
5.11 +{
5.12 + return ALIGN((panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8, sizeof(u32));
5.13 +}
5.14 +
5.15 +static u32 *get_pixel32(unsigned short h, unsigned short v)
5.16 {
5.17 - unsigned short v_max = panel_info.vl_row;
5.18 - unsigned short h_max = panel_info.vl_col;
5.19 - unsigned long *pix = (unsigned long *)lcd_base + v * h_max + h;
5.20 + return (u32 *) (lcd_base + v * get_line_length()) + h;
5.21 +}
5.22
5.23 - /* NOTE: Code assumes 32 bits/pixel. */
5.24 -#ifdef NORMAL
5.25 +static u16 *get_pixel16(unsigned short h, unsigned short v)
5.26 +{
5.27 + return (u16 *) (lcd_base + v * get_line_length()) + h;
5.28 +}
5.29 +
5.30 +static void test_pixel32(unsigned short h, unsigned short v)
5.31 +{
5.32 + unsigned short v_max = panel_info.vl_row;
5.33 + unsigned short h_max = panel_info.vl_col;
5.34 + u32 *pix = get_pixel32(h, v);
5.35 +
5.36 *pix = (
5.37 (((255 * (h_max - h)) / (h_max - 1)) << 16) +
5.38 ((((255 * h) / (h_max - 1) + (255 * (v_max - v)) / (v_max - 1)) / 2) << 8) +
5.39 ((255 * v) / (v_max - 1))
5.40 );
5.41 -#elif HANDLER
5.42 - unsigned short offset, bit;
5.43 - bit = 31 - (32 * h / (h_max - 1));
5.44 - offset = v / 4;
5.45 - *pix = ((*((unsigned long *) 0x80000200 + offset) & (1 << bit)) >> bit) ? 0xffffffff : 0;
5.46 -#else
5.47 - unsigned short bit;
5.48 - volatile unsigned int cp0_register;
5.49 - asm volatile(
5.50 - "mfc0 %0, $12\n"
5.51 - "nop"
5.52 - : "=r"(cp0_register)
5.53 +}
5.54 +
5.55 +static void test_pixel16_565(unsigned short h, unsigned short v)
5.56 +{
5.57 + unsigned short v_max = panel_info.vl_row;
5.58 + unsigned short h_max = panel_info.vl_col;
5.59 + u16 *pix = get_pixel16(h, v);
5.60 +
5.61 + *pix = (
5.62 + (((31 * (h_max - h)) / (h_max - 1)) << 11) +
5.63 + ((((63 * h) / (h_max - 1) + (63 * (v_max - v)) / (v_max - 1)) / 2) << 5) +
5.64 + ((31 * v) / (v_max - 1))
5.65 );
5.66 - bit = 31 - (32 * h / (h_max - 1));
5.67 - *pix = (((cp0_register & (1 << bit)) >> bit) ? 0x007f0000 : 0x0000001f) * ((bit % 2) ? 2 : 1);
5.68 - /* *pix = (((irq_counter & (1 << bit)) >> bit) ? 0x007f0000 : 0x0000001f) * ((bit % 2) ? 2 : 1); */
5.69 -#endif
5.70 +}
5.71 +
5.72 +void test_pixel(unsigned short h, unsigned short v)
5.73 +{
5.74 + switch (panel_info.vl_bpix)
5.75 + {
5.76 + case LCD_COLOR32:
5.77 + test_pixel32(h, v);
5.78 + break;
5.79 +
5.80 + default:
5.81 + test_pixel16_565(h, v);
5.82 + break;
5.83 + }
5.84 +}
5.85 +
5.86 +void clear_pixel32(unsigned short h, unsigned short v)
5.87 +{
5.88 + u32 *pix = get_pixel32(h, v);
5.89 + *pix = 0;
5.90 +}
5.91 +
5.92 +void clear_pixel16(unsigned short h, unsigned short v)
5.93 +{
5.94 + u16 *pix = get_pixel16(h, v);
5.95 + *pix = 0;
5.96 }
5.97
5.98 void clear_pixel(unsigned short h, unsigned short v)
5.99 {
5.100 - unsigned short h_max = panel_info.vl_col;
5.101 - unsigned long *pix = (unsigned long *)lcd_base + v * h_max + h;
5.102 + switch (panel_info.vl_bpix)
5.103 + {
5.104 + case LCD_COLOR32:
5.105 + clear_pixel32(h, v);
5.106 + break;
5.107
5.108 - *pix = 0;
5.109 + default:
5.110 + clear_pixel16(h, v);
5.111 + break;
5.112 + }
5.113 }
5.114
5.115 -void test_pattern(void *lcd_base)
5.116 +void test_pattern()
5.117 {
5.118 unsigned short v_max = panel_info.vl_row;
5.119 unsigned short h_max = panel_info.vl_col;
6.1 --- a/stage2/minipc_claa070vc01.c Mon Jan 25 18:01:52 2016 +0100
6.2 +++ b/stage2/minipc_claa070vc01.c Mon Jan 25 18:04:21 2016 +0100
6.3 @@ -2,7 +2,7 @@
6.4 * MiniPC screen details
6.5 *
6.6 * Copyright (C) 2005-2007, Ingenic Semiconductor Inc.
6.7 - * Copyright (C) 2015 Paul Boddie <paul@boddie.org.uk>
6.8 + * Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk>
6.9 *
6.10 * This program is free software; you can redistribute it and/or
6.11 * modify it under the terms of the GNU General Public License as
6.12 @@ -30,5 +30,5 @@
6.13 };
6.14
6.15 vidinfo_t panel_info = {
6.16 - 800, 480, LCD_BPP,
6.17 + 800, 480, LCD_COLOR32,
6.18 };
7.1 --- a/stage2/nanonote_gpm940b0.c Mon Jan 25 18:01:52 2016 +0100
7.2 +++ b/stage2/nanonote_gpm940b0.c Mon Jan 25 18:04:21 2016 +0100
7.3 @@ -2,7 +2,7 @@
7.4 * Ben NanoNote screen details
7.5 *
7.6 * Copyright (C) Xiangfu Liu <xiangfu@sharism.cc>
7.7 - * Copyright (C) 2015 Paul Boddie <paul@boddie.org.uk>
7.8 + * Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk>
7.9 *
7.10 * This program is free software; you can redistribute it and/or
7.11 * modify it under the terms of the GNU General Public License as
7.12 @@ -30,5 +30,5 @@
7.13 };
7.14
7.15 vidinfo_t panel_info = {
7.16 - 320, 240, LCD_BPP,
7.17 + 320, 240, LCD_COLOR32,
7.18 };