NanoPayload

Annotated stage2/lcd.c

101:0faa0818756c
2016-01-25 Paul Boddie Added support for 8bpp output with a simple 332 8-bit RGB palette mapping. Reordered various driver functions. stage2-non-pic
paul@15 1
/*
paul@15 2
 * Ben NanoNote LCD initialisation, based on uboot-xburst and xburst-tools.
paul@15 3
 *
paul@33 4
 * Copyright (C) 2001-2002 Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
paul@90 5
 * Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk>
paul@15 6
 *
paul@63 7
 * This program is free software: you can redistribute it and/or modify
paul@63 8
 * it under the terms of the GNU General Public License as published by
paul@63 9
 * the Free Software Foundation, either version 3 of the License, or
paul@63 10
 * (at your option) any later version.
paul@15 11
 *
paul@63 12
 * This program is distributed in the hope that it will be useful,
paul@63 13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
paul@63 14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
paul@63 15
 * GNU General Public License for more details.
paul@15 16
 *
paul@63 17
 * You should have received a copy of the GNU General Public License
paul@63 18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
paul@15 19
 */
paul@15 20
paul@34 21
#ifdef CONFIG_CPU_JZ4730_MINIPC
paul@34 22
#include "minipc_claa070vc01.h"
paul@40 23
#include "minipc.h"
paul@34 24
#else
paul@34 25
#include "nanonote_gpm940b0.h"
paul@40 26
#include "nanonote.h"
paul@34 27
#endif
paul@34 28
paul@15 29
#include "xburst_types.h"
paul@33 30
#include "jzlcd.h"
paul@33 31
#include "sdram.h"
paul@33 32
#include "board.h"
paul@15 33
paul@40 34
extern vidinfo_t panel_info;
paul@95 35
static unsigned long lcd_base;
paul@68 36
paul@100 37
static unsigned int get_line_length()
paul@100 38
{
paul@100 39
	return ALIGN((panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8, sizeof(u32));
paul@100 40
}
paul@100 41
paul@100 42
static u32 *get_pixel32(unsigned short h, unsigned short v)
paul@68 43
{
paul@100 44
	return (u32 *) (lcd_base + v * get_line_length()) + h;
paul@100 45
}
paul@68 46
paul@100 47
static u16 *get_pixel16(unsigned short h, unsigned short v)
paul@100 48
{
paul@100 49
	return (u16 *) (lcd_base + v * get_line_length()) + h;
paul@100 50
}
paul@100 51
paul@101 52
static u8 *get_pixel8(unsigned short h, unsigned short v)
paul@101 53
{
paul@101 54
	return (u8 *) (lcd_base + v * get_line_length()) + h;
paul@101 55
}
paul@101 56
paul@101 57
static unsigned long pixel(unsigned short h, unsigned short v, u8 rmax, u8 gmax, u8 bmax, u8 rshift, u8 gshift, u8 bshift)
paul@100 58
{
paul@100 59
	unsigned short v_max = panel_info.vl_row;
paul@100 60
	unsigned short h_max = panel_info.vl_col;
paul@100 61
paul@101 62
	return (((rmax * (h_max - h - 1)) / h_max) << rshift) |
paul@101 63
		((((gmax * h) / (h_max - 1) + (gmax * (v_max - v - 1)) / v_max) / 2) << gshift) |
paul@101 64
		(((bmax * v) / (v_max - 1)) << bshift);
paul@101 65
}
paul@101 66
paul@101 67
static void test_pixel32(unsigned short h, unsigned short v)
paul@101 68
{
paul@101 69
	u32 *pix = get_pixel32(h, v);
paul@101 70
	*pix = (u32) pixel(h, v, 255, 255, 255, 16, 8, 0);
paul@100 71
}
paul@100 72
paul@100 73
static void test_pixel16_565(unsigned short h, unsigned short v)
paul@100 74
{
paul@100 75
	u16 *pix = get_pixel16(h, v);
paul@101 76
	*pix = (u16) pixel(h, v, 31, 63, 31, 11, 5, 0);
paul@101 77
}
paul@100 78
paul@101 79
static void test_pixel8(unsigned short h, unsigned short v)
paul@101 80
{
paul@101 81
	u8 *pix = get_pixel8(h, v);
paul@101 82
	*pix = (u8) pixel(h, v, 7, 7, 3, 5, 2, 0);
paul@100 83
}
paul@100 84
paul@100 85
void test_pixel(unsigned short h, unsigned short v)
paul@100 86
{
paul@100 87
	switch (panel_info.vl_bpix)
paul@100 88
	{
paul@100 89
		case LCD_COLOR32:
paul@100 90
		test_pixel32(h, v);
paul@100 91
		break;
paul@100 92
paul@101 93
		case LCD_COLOR8:
paul@101 94
		test_pixel8(h, v);
paul@101 95
		break;
paul@101 96
paul@101 97
		case LCD_COLOR16:
paul@100 98
		default:
paul@100 99
		test_pixel16_565(h, v);
paul@100 100
		break;
paul@100 101
	}
paul@100 102
}
paul@100 103
paul@100 104
void clear_pixel32(unsigned short h, unsigned short v)
paul@100 105
{
paul@100 106
	u32 *pix = get_pixel32(h, v);
paul@100 107
	*pix = 0;
paul@100 108
}
paul@100 109
paul@100 110
void clear_pixel16(unsigned short h, unsigned short v)
paul@100 111
{
paul@100 112
	u16 *pix = get_pixel16(h, v);
paul@100 113
	*pix = 0;
paul@68 114
}
paul@68 115
paul@101 116
void clear_pixel8(unsigned short h, unsigned short v)
paul@101 117
{
paul@101 118
	u8 *pix = get_pixel8(h, v);
paul@101 119
	*pix = 0;
paul@101 120
}
paul@101 121
paul@68 122
void clear_pixel(unsigned short h, unsigned short v)
paul@68 123
{
paul@100 124
	switch (panel_info.vl_bpix)
paul@100 125
	{
paul@100 126
		case LCD_COLOR32:
paul@100 127
		clear_pixel32(h, v);
paul@100 128
		break;
paul@68 129
paul@101 130
		case LCD_COLOR8:
paul@101 131
		clear_pixel8(h, v);
paul@101 132
		break;
paul@101 133
paul@101 134
		case LCD_COLOR16:
paul@100 135
		default:
paul@100 136
		clear_pixel16(h, v);
paul@100 137
		break;
paul@100 138
	}
paul@68 139
}
paul@40 140
paul@100 141
void test_pattern()
paul@15 142
{
paul@15 143
	unsigned short v_max  = panel_info.vl_row;
paul@15 144
	unsigned short h_max  = panel_info.vl_col;
paul@15 145
	unsigned short v, h;
paul@68 146
paul@68 147
	for (v = 0; v < v_max; v += 1) {
paul@68 148
		for (h = 0; h < h_max; h += 1) {
paul@68 149
			test_pixel(h, v);
paul@68 150
		}
paul@68 151
	}
paul@68 152
}
paul@68 153
paul@97 154
void lcd_clear(unsigned long lcd_base)
paul@68 155
{
paul@68 156
	unsigned short v_max  = panel_info.vl_row;
paul@68 157
	unsigned short h_max  = panel_info.vl_col;
paul@68 158
	unsigned short v, h;
paul@95 159
	unsigned long *pix = (unsigned long *)lcd_base;
paul@15 160
paul@22 161
	for (v = 0; v < v_max; v += 1) {
paul@22 162
		for (h = 0; h < h_max; h += 1) {
paul@68 163
			*pix++ = 0;
paul@15 164
		}
paul@15 165
	}
paul@15 166
}
paul@15 167
paul@15 168
/* LCD initialisation. */
paul@15 169
paul@15 170
void lcd_init(void)
paul@15 171
{
paul@20 172
	__lcd_display_pin_init();
paul@20 173
	__lcd_display_on();
paul@20 174
paul@97 175
	lcd_base = lcd_ctrl_init();
paul@15 176
	lcd_clear(lcd_base);
paul@15 177
	lcd_enable();
paul@15 178
}