1.1 --- a/stage2/jzlcd.c Mon Jan 25 22:07:23 2016 +0100
1.2 +++ b/stage2/jzlcd.c Mon Jan 25 22:18:53 2016 +0100
1.3 @@ -38,6 +38,10 @@
1.4 ((jzfb.cfg & MODE_MASK) == MODE_STN_COLOR_DUAL) ? 2 : 1;
1.5 }
1.6
1.7 +
1.8 +
1.9 +/* Functions returning region sizes. */
1.10 +
1.11 static unsigned long lcd_get_size(vidinfo_t *vid)
1.12 {
1.13 /* Lines must be aligned to a word boundary. */
1.14 @@ -64,15 +68,18 @@
1.15 return ALIGN(lcd_get_min_size(vid), 16 * sizeof(u32));
1.16 }
1.17
1.18 -static unsigned long lcd_get_palette_size()
1.19 +static unsigned long lcd_get_palette_size(vidinfo_t *vid)
1.20 {
1.21 - return 256 * sizeof(u16);
1.22 + if (NBITS(vid->vl_bpix) < 12)
1.23 + return NCOLORS(vid->vl_bpix) * sizeof(u16);
1.24 + else
1.25 + return 0;
1.26 }
1.27
1.28 -static unsigned long lcd_get_aligned_palette_size()
1.29 +static unsigned long lcd_get_aligned_palette_size(vidinfo_t *vid)
1.30 {
1.31 /* LCD_CTRL_BST_16 requires 16-word alignment. */
1.32 - return ALIGN(lcd_get_palette_size(), 16 * sizeof(u32));
1.33 + return ALIGN(lcd_get_palette_size(vid), 16 * sizeof(u32));
1.34 }
1.35
1.36 static unsigned long lcd_get_descriptors_size()
1.37 @@ -86,13 +93,17 @@
1.38 unsigned long min_size = lcd_get_aligned_min_size(vid);
1.39
1.40 /* Round up to nearest full page, or MMU section if defined. */
1.41 - return ALIGN((size >= min_size ? size : min_size) + lcd_get_aligned_palette_size() + lcd_get_descriptors_size(), PAGE_SIZE);
1.42 + return ALIGN((size >= min_size ? size : min_size) + lcd_get_aligned_palette_size(vid) + lcd_get_descriptors_size(), PAGE_SIZE);
1.43 }
1.44
1.45 +
1.46 +
1.47 +/* Functions returning addresses of each data region. */
1.48 +
1.49 static unsigned long lcd_get_palette(unsigned long addr)
1.50 {
1.51 /* Allocate memory at the end of the region for the palette. */
1.52 - return addr - lcd_get_aligned_palette_size();
1.53 + return addr - lcd_get_aligned_palette_size(&panel_info);
1.54 }
1.55
1.56 static unsigned long lcd_get_descriptors(unsigned long addr)
1.57 @@ -107,6 +118,10 @@
1.58 return addr - lcd_get_total_size(&panel_info) + (panel * lcd_get_aligned_size(&panel_info));
1.59 }
1.60
1.61 +
1.62 +
1.63 +/* Initialisation functions. */
1.64 +
1.65 static void jz_lcd_desc_init(vidinfo_t *vid)
1.66 {
1.67 struct jz_fb_dma_descriptor *descriptors;
1.68 @@ -141,7 +156,7 @@
1.69 {
1.70 fbi->dmadesc_palette->fsadr = fbi->palette;
1.71 fbi->dmadesc_palette->fidr = 0;
1.72 - fbi->dmadesc_palette->ldcmd = (lcd_get_palette_size() / 4) | (1<<28);
1.73 + fbi->dmadesc_palette->ldcmd = (lcd_get_palette_size(vid) / 4) | (1<<28);
1.74
1.75 /* assume any mode with <12 bpp is palette driven */
1.76 fbi->dmadesc_palette->fdadr = fbi->dmadesc_fbhigh;
1.77 @@ -157,25 +172,6 @@
1.78 flush_cache_all();
1.79 }
1.80
1.81 -static inline u16 rgb8_to_rgb16(u8 rgb)
1.82 -{
1.83 - return ((rgb & 0xe0) << 8) | ((rgb & 0x1c) << 6) | ((rgb & 0x03) << 3);
1.84 -}
1.85 -
1.86 -static void lcd_init_palette()
1.87 -{
1.88 - u16 *palette = (u16 *) lcd_get_palette(get_memory_size());
1.89 - u16 *end = (u16 *) ((unsigned long) palette + lcd_get_palette_size());
1.90 - u16 value = 0;
1.91 -
1.92 - while (palette < end)
1.93 - {
1.94 - *palette = rgb8_to_rgb16(value);
1.95 - value++;
1.96 - palette++;
1.97 - }
1.98 -}
1.99 -
1.100 static unsigned int jz_lcd_stn_init(unsigned int stnH)
1.101 {
1.102 unsigned int val = 0;
1.103 @@ -445,18 +441,43 @@
1.104 return 0;
1.105 }
1.106
1.107 -/*
1.108 - * Before enabling the LCD controller, LCD registers should be configured correctly.
1.109 - */
1.110 +/* Public operations. */
1.111 +
1.112 void lcd_enable(void)
1.113 {
1.114 - REG_LCD_CTRL &= ~(1<<4); /* LCDCTRL.DIS */
1.115 - REG_LCD_CTRL |= 1<<3; /* LCDCTRL.ENA*/
1.116 + /* Clear the disable bit and set the enable bit. */
1.117 +
1.118 + REG_LCD_CTRL &= ~(1<<4); /* LCDCTRL.DIS */
1.119 + REG_LCD_CTRL |= 1<<3; /* LCDCTRL.ENA*/
1.120 }
1.121
1.122 void lcd_disable(void)
1.123 {
1.124 - REG_LCD_CTRL |= (1<<4); /* LCDCTRL.DIS, regular disable */
1.125 + REG_LCD_CTRL |= (1<<4); /* LCDCTRL.DIS, regular disable */
1.126 +}
1.127 +
1.128 +void lcd_quick_disable(void)
1.129 +{
1.130 + REG_LCD_CTRL &= ~(1<<4); /* LCDCTRL.ENA, quick disable */
1.131 +}
1.132 +
1.133 +static inline u16 rgb8_to_rgb16(u8 rgb)
1.134 +{
1.135 + return ((rgb & 0xe0) << 8) | ((rgb & 0x1c) << 6) | ((rgb & 0x03) << 3);
1.136 +}
1.137 +
1.138 +static void lcd_init_palette(vidinfo_t *vid)
1.139 +{
1.140 + u16 *palette = (u16 *) lcd_get_palette(get_memory_size());
1.141 + u16 *end = (u16 *) ((unsigned long) palette + lcd_get_palette_size(vid));
1.142 + u16 value = 0;
1.143 +
1.144 + while (palette < end)
1.145 + {
1.146 + *palette = rgb8_to_rgb16(value);
1.147 + value++;
1.148 + palette++;
1.149 + }
1.150 }
1.151
1.152 unsigned long lcd_ctrl_init()
1.153 @@ -469,7 +490,7 @@
1.154 fbi->palette = lcd_get_palette(get_memory_size());
1.155
1.156 if (NBITS(panel_info.vl_bpix) < 12)
1.157 - lcd_init_palette();
1.158 + lcd_init_palette(&panel_info);
1.159
1.160 jz_lcd_desc_init(&panel_info);
1.161 jz_lcd_hw_init(&panel_info);