NanoPayload

Annotated stage2/lcd.c

104:9f1741e401f6
2016-01-26 Paul Boddie Experiment with a different test pattern. 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@103 57
static u8 *get_pixel4(unsigned short h, unsigned short v)
paul@103 58
{
paul@103 59
	return (u8 *) (lcd_base + v * get_line_length()) + h / 2;
paul@103 60
}
paul@103 61
paul@103 62
static inline unsigned short div(unsigned short num, unsigned short denom, unsigned short scale)
paul@103 63
{
paul@103 64
	return (scale * num) / denom;
paul@103 65
}
paul@103 66
paul@104 67
static unsigned long pixel(u8 r, u8 g, u8 b, u8 rmax, u8 gmax, u8 bmax, u8 rshift, u8 gshift, u8 bshift)
paul@104 68
{
paul@104 69
	return (div(r, 255, rmax) << rshift) | (div(g, 255, gmax) << gshift) | (div(b, 255, bmax) << bshift);
paul@104 70
}
paul@104 71
paul@104 72
static void get_colour(unsigned short h, unsigned short v, u8 rgb[])
paul@100 73
{
paul@100 74
	unsigned short v_max = panel_info.vl_row;
paul@100 75
	unsigned short h_max = panel_info.vl_col;
paul@100 76
paul@104 77
	rgb[0] = div(h, h_max, 255);
paul@104 78
	rgb[1] = div(v, v_max, 255);
paul@104 79
	rgb[2] = (rgb[0] + rgb[1]) / 2;
paul@101 80
}
paul@101 81
paul@101 82
static void test_pixel32(unsigned short h, unsigned short v)
paul@101 83
{
paul@101 84
	u32 *pix = get_pixel32(h, v);
paul@104 85
	u8 rgb[3];
paul@104 86
paul@104 87
	get_colour(h, v, rgb);
paul@104 88
	*pix = (u32) pixel(rgb[0], rgb[1], rgb[2], 255, 255, 255, 16, 8, 0);
paul@100 89
}
paul@100 90
paul@100 91
static void test_pixel16_565(unsigned short h, unsigned short v)
paul@100 92
{
paul@100 93
	u16 *pix = get_pixel16(h, v);
paul@104 94
	u8 rgb[3];
paul@104 95
paul@104 96
	get_colour(h, v, rgb);
paul@104 97
	*pix = (u16) pixel(rgb[0], rgb[1], rgb[2], 31, 63, 31, 11, 5, 0);
paul@101 98
}
paul@100 99
paul@101 100
static void test_pixel8(unsigned short h, unsigned short v)
paul@101 101
{
paul@101 102
	u8 *pix = get_pixel8(h, v);
paul@104 103
	u8 rgb[3];
paul@104 104
paul@104 105
	get_colour(h, v, rgb);
paul@104 106
	*pix = (u8) pixel(rgb[0], rgb[1], rgb[2], 7, 7, 3, 5, 2, 0);
paul@100 107
}
paul@100 108
paul@103 109
static void test_pixel4(unsigned short h, unsigned short v)
paul@103 110
{
paul@103 111
	u8 *pix = get_pixel4(h, v);
paul@103 112
	u8 mask = h & 1 ? 0xf0 : 0x0f;
paul@104 113
	u8 rgb[3];
paul@104 114
paul@104 115
	get_colour(h, v, rgb);
paul@104 116
	*pix = (*pix & mask) | ((u8) pixel(rgb[0], rgb[1], rgb[2], 1, 2, 1, 3, 1, 0) << (h & 1 ? 0 : 4));
paul@103 117
}
paul@103 118
paul@100 119
void test_pixel(unsigned short h, unsigned short v)
paul@100 120
{
paul@100 121
	switch (panel_info.vl_bpix)
paul@100 122
	{
paul@100 123
		case LCD_COLOR32:
paul@100 124
		test_pixel32(h, v);
paul@100 125
		break;
paul@100 126
paul@101 127
		case LCD_COLOR8:
paul@101 128
		test_pixel8(h, v);
paul@101 129
		break;
paul@101 130
paul@103 131
		case LCD_COLOR4:
paul@103 132
		test_pixel4(h, v);
paul@103 133
		break;
paul@103 134
paul@101 135
		case LCD_COLOR16:
paul@100 136
		default:
paul@100 137
		test_pixel16_565(h, v);
paul@100 138
		break;
paul@100 139
	}
paul@100 140
}
paul@100 141
paul@100 142
void clear_pixel32(unsigned short h, unsigned short v)
paul@100 143
{
paul@100 144
	u32 *pix = get_pixel32(h, v);
paul@100 145
	*pix = 0;
paul@100 146
}
paul@100 147
paul@100 148
void clear_pixel16(unsigned short h, unsigned short v)
paul@100 149
{
paul@100 150
	u16 *pix = get_pixel16(h, v);
paul@100 151
	*pix = 0;
paul@68 152
}
paul@68 153
paul@101 154
void clear_pixel8(unsigned short h, unsigned short v)
paul@101 155
{
paul@101 156
	u8 *pix = get_pixel8(h, v);
paul@101 157
	*pix = 0;
paul@101 158
}
paul@101 159
paul@103 160
void clear_pixel4(unsigned short h, unsigned short v)
paul@103 161
{
paul@103 162
	u8 *pix = get_pixel4(h, v);
paul@103 163
	u8 mask = h & 1 ? 0xf0 : 0x0f;
paul@103 164
	*pix = *pix & mask;
paul@103 165
}
paul@103 166
paul@68 167
void clear_pixel(unsigned short h, unsigned short v)
paul@68 168
{
paul@100 169
	switch (panel_info.vl_bpix)
paul@100 170
	{
paul@100 171
		case LCD_COLOR32:
paul@100 172
		clear_pixel32(h, v);
paul@100 173
		break;
paul@68 174
paul@101 175
		case LCD_COLOR8:
paul@101 176
		clear_pixel8(h, v);
paul@101 177
		break;
paul@101 178
paul@103 179
		case LCD_COLOR4:
paul@103 180
		clear_pixel4(h, v);
paul@103 181
		break;
paul@103 182
paul@101 183
		case LCD_COLOR16:
paul@100 184
		default:
paul@100 185
		clear_pixel16(h, v);
paul@100 186
		break;
paul@100 187
	}
paul@68 188
}
paul@40 189
paul@100 190
void test_pattern()
paul@15 191
{
paul@15 192
	unsigned short v_max  = panel_info.vl_row;
paul@15 193
	unsigned short h_max  = panel_info.vl_col;
paul@15 194
	unsigned short v, h;
paul@68 195
paul@68 196
	for (v = 0; v < v_max; v += 1) {
paul@68 197
		for (h = 0; h < h_max; h += 1) {
paul@68 198
			test_pixel(h, v);
paul@68 199
		}
paul@68 200
	}
paul@68 201
}
paul@68 202
paul@97 203
void lcd_clear(unsigned long lcd_base)
paul@68 204
{
paul@68 205
	unsigned short v_max  = panel_info.vl_row;
paul@68 206
	unsigned short h_max  = panel_info.vl_col;
paul@68 207
	unsigned short v, h;
paul@95 208
	unsigned long *pix = (unsigned long *)lcd_base;
paul@15 209
paul@22 210
	for (v = 0; v < v_max; v += 1) {
paul@22 211
		for (h = 0; h < h_max; h += 1) {
paul@68 212
			*pix++ = 0;
paul@15 213
		}
paul@15 214
	}
paul@15 215
}
paul@15 216
paul@15 217
/* LCD initialisation. */
paul@15 218
paul@15 219
void lcd_init(void)
paul@15 220
{
paul@20 221
	__lcd_display_pin_init();
paul@20 222
	__lcd_display_on();
paul@20 223
paul@97 224
	lcd_base = lcd_ctrl_init();
paul@15 225
	lcd_clear(lcd_base);
paul@15 226
	lcd_enable();
paul@15 227
}