NanoPayload

Annotated stage2/lcd.c

97:1c164ef8cb38
2016-01-25 Paul Boddie Tidied up the memory allocation of the palette and framebuffer regions. 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@95 36
unsigned long irq_counter = 0;
paul@68 37
paul@68 38
void test_pixel(unsigned short h, unsigned short v)
paul@68 39
{
paul@68 40
	unsigned short v_max  = panel_info.vl_row;
paul@68 41
	unsigned short h_max  = panel_info.vl_col;
paul@95 42
	unsigned long *pix = (unsigned long *)lcd_base + v * h_max + h;
paul@68 43
paul@68 44
	/* NOTE: Code assumes 32 bits/pixel. */
paul@72 45
#ifdef NORMAL
paul@68 46
	*pix = (
paul@68 47
		(((255 * (h_max - h)) / (h_max - 1)) << 16) +
paul@68 48
		((((255 * h) / (h_max - 1) + (255 * (v_max - v)) / (v_max - 1)) / 2) << 8) +
paul@68 49
		((255 * v) / (v_max - 1))
paul@68 50
		);
paul@72 51
#elif HANDLER
paul@72 52
	unsigned short offset, bit;
paul@72 53
	bit = 31 - (32 * h / (h_max - 1));
paul@72 54
	offset = v / 4;
paul@95 55
	*pix = ((*((unsigned long *) 0x80000200 + offset) & (1 << bit)) >> bit) ? 0xffffffff : 0;
paul@72 56
#else
paul@72 57
	unsigned short bit;
paul@72 58
	volatile unsigned int cp0_register;
paul@72 59
	asm volatile(
paul@72 60
		"mfc0 %0, $12\n"
paul@72 61
		"nop"
paul@72 62
		: "=r"(cp0_register)
paul@72 63
		);
paul@72 64
	bit = 31 - (32 * h / (h_max - 1));
paul@72 65
	*pix = (((cp0_register & (1 << bit)) >> bit) ? 0x007f0000 : 0x0000001f) * ((bit % 2) ? 2 : 1);
paul@72 66
	/* *pix = (((irq_counter & (1 << bit)) >> bit) ? 0x007f0000 : 0x0000001f) * ((bit % 2) ? 2 : 1); */
paul@72 67
#endif
paul@68 68
}
paul@68 69
paul@68 70
void clear_pixel(unsigned short h, unsigned short v)
paul@68 71
{
paul@68 72
	unsigned short h_max  = panel_info.vl_col;
paul@95 73
	unsigned long *pix = (unsigned long *)lcd_base + v * h_max + h;
paul@68 74
paul@68 75
	*pix = 0;
paul@68 76
}
paul@40 77
paul@85 78
void test_pattern(void *lcd_base)
paul@15 79
{
paul@15 80
	unsigned short v_max  = panel_info.vl_row;
paul@15 81
	unsigned short h_max  = panel_info.vl_col;
paul@15 82
	unsigned short v, h;
paul@68 83
paul@68 84
	for (v = 0; v < v_max; v += 1) {
paul@68 85
		for (h = 0; h < h_max; h += 1) {
paul@68 86
			test_pixel(h, v);
paul@68 87
		}
paul@68 88
	}
paul@68 89
}
paul@68 90
paul@97 91
void lcd_clear(unsigned long lcd_base)
paul@68 92
{
paul@68 93
	unsigned short v_max  = panel_info.vl_row;
paul@68 94
	unsigned short h_max  = panel_info.vl_col;
paul@68 95
	unsigned short v, h;
paul@95 96
	unsigned long *pix = (unsigned long *)lcd_base;
paul@15 97
paul@22 98
	for (v = 0; v < v_max; v += 1) {
paul@22 99
		for (h = 0; h < h_max; h += 1) {
paul@68 100
			*pix++ = 0;
paul@15 101
		}
paul@15 102
	}
paul@15 103
}
paul@15 104
paul@15 105
/* LCD initialisation. */
paul@15 106
paul@15 107
void lcd_init(void)
paul@15 108
{
paul@20 109
	__lcd_display_pin_init();
paul@20 110
	__lcd_display_on();
paul@20 111
paul@97 112
	lcd_base = lcd_ctrl_init();
paul@15 113
	lcd_clear(lcd_base);
paul@15 114
	lcd_enable();
paul@15 115
}