1.1 --- a/stage2/jzlcd.c Mon Jan 25 18:04:21 2016 +0100
1.2 +++ b/stage2/jzlcd.c Mon Jan 25 22:07:23 2016 +0100
1.3 @@ -107,38 +107,6 @@
1.4 return addr - lcd_get_total_size(&panel_info) + (panel * lcd_get_aligned_size(&panel_info));
1.5 }
1.6
1.7 -static void jz_lcd_desc_init(vidinfo_t *vid);
1.8 -static int jz_lcd_hw_init(vidinfo_t *vid);
1.9 -
1.10 -unsigned long lcd_ctrl_init()
1.11 -{
1.12 - struct jz_fb_info *fbi = &panel_info.jz_fb;
1.13 -
1.14 - /* Start from the top of memory and obtain palette and framebuffer regions. */
1.15 -
1.16 - fbi->screen = lcd_get_framebuffer(get_memory_size(), 0);
1.17 - fbi->palette = lcd_get_palette(get_memory_size());
1.18 -
1.19 - jz_lcd_desc_init(&panel_info);
1.20 - jz_lcd_hw_init(&panel_info);
1.21 -
1.22 - return fbi->screen;
1.23 -}
1.24 -
1.25 -/*
1.26 - * Before enabling the LCD controller, LCD registers should be configured correctly.
1.27 - */
1.28 -void lcd_enable(void)
1.29 -{
1.30 - REG_LCD_CTRL &= ~(1<<4); /* LCDCTRL.DIS */
1.31 - REG_LCD_CTRL |= 1<<3; /* LCDCTRL.ENA*/
1.32 -}
1.33 -
1.34 -void lcd_disable(void)
1.35 -{
1.36 - REG_LCD_CTRL |= (1<<4); /* LCDCTRL.DIS, regular disable */
1.37 -}
1.38 -
1.39 static void jz_lcd_desc_init(vidinfo_t *vid)
1.40 {
1.41 struct jz_fb_dma_descriptor *descriptors;
1.42 @@ -169,12 +137,12 @@
1.43 fbi->dmadesc_fbhigh->fidr = 0;
1.44 fbi->dmadesc_fbhigh->ldcmd = lcd_get_size(vid) / 4; /* length in words */
1.45
1.46 - fbi->dmadesc_palette->fsadr = fbi->palette;
1.47 - fbi->dmadesc_palette->fidr = 0;
1.48 - fbi->dmadesc_palette->ldcmd = (lcd_get_palette_size() / 4) | (1<<28);
1.49 -
1.50 if (NBITS(vid->vl_bpix) < 12)
1.51 {
1.52 + fbi->dmadesc_palette->fsadr = fbi->palette;
1.53 + fbi->dmadesc_palette->fidr = 0;
1.54 + fbi->dmadesc_palette->ldcmd = (lcd_get_palette_size() / 4) | (1<<28);
1.55 +
1.56 /* assume any mode with <12 bpp is palette driven */
1.57 fbi->dmadesc_palette->fdadr = fbi->dmadesc_fbhigh;
1.58 fbi->dmadesc_fbhigh->fdadr = fbi->dmadesc_palette;
1.59 @@ -189,6 +157,25 @@
1.60 flush_cache_all();
1.61 }
1.62
1.63 +static inline u16 rgb8_to_rgb16(u8 rgb)
1.64 +{
1.65 + return ((rgb & 0xe0) << 8) | ((rgb & 0x1c) << 6) | ((rgb & 0x03) << 3);
1.66 +}
1.67 +
1.68 +static void lcd_init_palette()
1.69 +{
1.70 + u16 *palette = (u16 *) lcd_get_palette(get_memory_size());
1.71 + u16 *end = (u16 *) ((unsigned long) palette + lcd_get_palette_size());
1.72 + u16 value = 0;
1.73 +
1.74 + while (palette < end)
1.75 + {
1.76 + *palette = rgb8_to_rgb16(value);
1.77 + value++;
1.78 + palette++;
1.79 + }
1.80 +}
1.81 +
1.82 static unsigned int jz_lcd_stn_init(unsigned int stnH)
1.83 {
1.84 unsigned int val = 0;
1.85 @@ -458,10 +445,34 @@
1.86 return 0;
1.87 }
1.88
1.89 -void lcd_setcolreg (unsigned short regno, unsigned short red, unsigned short green, unsigned short blue)
1.90 +/*
1.91 + * Before enabling the LCD controller, LCD registers should be configured correctly.
1.92 + */
1.93 +void lcd_enable(void)
1.94 {
1.95 + REG_LCD_CTRL &= ~(1<<4); /* LCDCTRL.DIS */
1.96 + REG_LCD_CTRL |= 1<<3; /* LCDCTRL.ENA*/
1.97 +}
1.98 +
1.99 +void lcd_disable(void)
1.100 +{
1.101 + REG_LCD_CTRL |= (1<<4); /* LCDCTRL.DIS, regular disable */
1.102 }
1.103
1.104 -void lcd_initcolregs (void)
1.105 +unsigned long lcd_ctrl_init()
1.106 {
1.107 + struct jz_fb_info *fbi = &panel_info.jz_fb;
1.108 +
1.109 + /* Start from the top of memory and obtain palette and framebuffer regions. */
1.110 +
1.111 + fbi->screen = lcd_get_framebuffer(get_memory_size(), 0);
1.112 + fbi->palette = lcd_get_palette(get_memory_size());
1.113 +
1.114 + if (NBITS(panel_info.vl_bpix) < 12)
1.115 + lcd_init_palette();
1.116 +
1.117 + jz_lcd_desc_init(&panel_info);
1.118 + jz_lcd_hw_init(&panel_info);
1.119 +
1.120 + return fbi->screen;
1.121 }
2.1 --- a/stage2/lcd.c Mon Jan 25 18:04:21 2016 +0100
2.2 +++ b/stage2/lcd.c Mon Jan 25 22:07:23 2016 +0100
2.3 @@ -49,30 +49,37 @@
2.4 return (u16 *) (lcd_base + v * get_line_length()) + h;
2.5 }
2.6
2.7 -static void test_pixel32(unsigned short h, unsigned short v)
2.8 +static u8 *get_pixel8(unsigned short h, unsigned short v)
2.9 +{
2.10 + return (u8 *) (lcd_base + v * get_line_length()) + h;
2.11 +}
2.12 +
2.13 +static unsigned long pixel(unsigned short h, unsigned short v, u8 rmax, u8 gmax, u8 bmax, u8 rshift, u8 gshift, u8 bshift)
2.14 {
2.15 unsigned short v_max = panel_info.vl_row;
2.16 unsigned short h_max = panel_info.vl_col;
2.17 - u32 *pix = get_pixel32(h, v);
2.18
2.19 - *pix = (
2.20 - (((255 * (h_max - h)) / (h_max - 1)) << 16) +
2.21 - ((((255 * h) / (h_max - 1) + (255 * (v_max - v)) / (v_max - 1)) / 2) << 8) +
2.22 - ((255 * v) / (v_max - 1))
2.23 - );
2.24 + return (((rmax * (h_max - h - 1)) / h_max) << rshift) |
2.25 + ((((gmax * h) / (h_max - 1) + (gmax * (v_max - v - 1)) / v_max) / 2) << gshift) |
2.26 + (((bmax * v) / (v_max - 1)) << bshift);
2.27 +}
2.28 +
2.29 +static void test_pixel32(unsigned short h, unsigned short v)
2.30 +{
2.31 + u32 *pix = get_pixel32(h, v);
2.32 + *pix = (u32) pixel(h, v, 255, 255, 255, 16, 8, 0);
2.33 }
2.34
2.35 static void test_pixel16_565(unsigned short h, unsigned short v)
2.36 {
2.37 - unsigned short v_max = panel_info.vl_row;
2.38 - unsigned short h_max = panel_info.vl_col;
2.39 u16 *pix = get_pixel16(h, v);
2.40 + *pix = (u16) pixel(h, v, 31, 63, 31, 11, 5, 0);
2.41 +}
2.42
2.43 - *pix = (
2.44 - (((31 * (h_max - h)) / (h_max - 1)) << 11) +
2.45 - ((((63 * h) / (h_max - 1) + (63 * (v_max - v)) / (v_max - 1)) / 2) << 5) +
2.46 - ((31 * v) / (v_max - 1))
2.47 - );
2.48 +static void test_pixel8(unsigned short h, unsigned short v)
2.49 +{
2.50 + u8 *pix = get_pixel8(h, v);
2.51 + *pix = (u8) pixel(h, v, 7, 7, 3, 5, 2, 0);
2.52 }
2.53
2.54 void test_pixel(unsigned short h, unsigned short v)
2.55 @@ -83,6 +90,11 @@
2.56 test_pixel32(h, v);
2.57 break;
2.58
2.59 + case LCD_COLOR8:
2.60 + test_pixel8(h, v);
2.61 + break;
2.62 +
2.63 + case LCD_COLOR16:
2.64 default:
2.65 test_pixel16_565(h, v);
2.66 break;
2.67 @@ -101,6 +113,12 @@
2.68 *pix = 0;
2.69 }
2.70
2.71 +void clear_pixel8(unsigned short h, unsigned short v)
2.72 +{
2.73 + u8 *pix = get_pixel8(h, v);
2.74 + *pix = 0;
2.75 +}
2.76 +
2.77 void clear_pixel(unsigned short h, unsigned short v)
2.78 {
2.79 switch (panel_info.vl_bpix)
2.80 @@ -109,6 +127,11 @@
2.81 clear_pixel32(h, v);
2.82 break;
2.83
2.84 + case LCD_COLOR8:
2.85 + clear_pixel8(h, v);
2.86 + break;
2.87 +
2.88 + case LCD_COLOR16:
2.89 default:
2.90 clear_pixel16(h, v);
2.91 break;