paul@15 | 1 | /* |
paul@15 | 2 | * Ben NanoNote LCD initialisation, based on uboot-xburst and xburst-tools. |
paul@15 | 3 | * |
paul@15 | 4 | * Copyright (C) 2015 Paul Boddie <paul@boddie.org.uk> |
paul@15 | 5 | * Copyright (C) 2001-2002 Wolfgang Denk, DENX Software Engineering, <wd@denx.de> |
paul@15 | 6 | * |
paul@15 | 7 | * This program is free software; you can redistribute it and/or modify it under |
paul@15 | 8 | * the terms of the GNU General Public License as published by the Free Software |
paul@15 | 9 | * Foundation; either version 3 of the License, or (at your option) any later |
paul@15 | 10 | * version. |
paul@15 | 11 | * |
paul@15 | 12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
paul@15 | 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@15 | 14 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@15 | 15 | * details. |
paul@15 | 16 | * |
paul@15 | 17 | * You should have received a copy of the GNU General Public License along with |
paul@15 | 18 | * this program. If not, see <http://www.gnu.org/licenses/>. |
paul@15 | 19 | */ |
paul@15 | 20 | |
paul@15 | 21 | #include "xburst_types.h" |
paul@15 | 22 | #include "nanonote_gpm940b0.h" |
paul@18 | 23 | #include "board-nanonote.h" |
paul@15 | 24 | |
paul@15 | 25 | #define ALIGN(x,a) __ALIGN_MASK((x),(typeof(x))(a)-1) |
paul@15 | 26 | #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) |
paul@15 | 27 | |
paul@15 | 28 | unsigned long lcd_setmem(unsigned long addr) |
paul@15 | 29 | { |
paul@15 | 30 | unsigned long size; |
paul@15 | 31 | |
paul@15 | 32 | size = lcd_get_size(); |
paul@15 | 33 | |
paul@15 | 34 | /* Round up to nearest full page, or MMU section if defined */ |
paul@15 | 35 | size = ALIGN(size, PAGE_SIZE); |
paul@15 | 36 | addr = ALIGN(addr - PAGE_SIZE + 1, PAGE_SIZE); |
paul@15 | 37 | |
paul@15 | 38 | /* Allocate pages for the frame buffer. */ |
paul@15 | 39 | addr -= size; |
paul@15 | 40 | |
paul@15 | 41 | return addr; |
paul@15 | 42 | } |
paul@15 | 43 | |
paul@15 | 44 | #define N_BLK_VERT 2 |
paul@15 | 45 | #define N_BLK_HOR 3 |
paul@15 | 46 | |
paul@15 | 47 | static int test_colors[N_BLK_HOR * N_BLK_VERT] = { |
paul@15 | 48 | 0x00ff0000, 0x0000ff00, 0x00ffff00, |
paul@15 | 49 | 0x000000ff, 0x00ff00ff, 0x0000ffff, |
paul@15 | 50 | }; |
paul@15 | 51 | |
paul@15 | 52 | static void test_pattern(void *lcd_base) |
paul@15 | 53 | { |
paul@15 | 54 | unsigned short v_max = panel_info.vl_row; |
paul@15 | 55 | unsigned short h_max = panel_info.vl_col; |
paul@15 | 56 | unsigned short v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT; |
paul@15 | 57 | unsigned short h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR; |
paul@15 | 58 | unsigned short v, h; |
paul@15 | 59 | unsigned char *pix = (unsigned char *)lcd_base; |
paul@15 | 60 | |
paul@15 | 61 | /* WARNING: Code silently assumes 8bit/pixel */ |
paul@15 | 62 | for (v = 0; v < v_max; ++v) { |
paul@15 | 63 | unsigned char iy = v / v_step; |
paul@15 | 64 | for (h = 0; h < h_max; ++h) { |
paul@15 | 65 | unsigned char ix = N_BLK_HOR * iy + h / h_step; |
paul@15 | 66 | *pix++ = test_colors[ix]; |
paul@15 | 67 | } |
paul@15 | 68 | } |
paul@15 | 69 | } |
paul@15 | 70 | |
paul@15 | 71 | void lcd_clear(void *lcd_base) |
paul@15 | 72 | { |
paul@15 | 73 | test_pattern(lcd_base); |
paul@15 | 74 | } |
paul@15 | 75 | |
paul@15 | 76 | /* LCD initialisation. */ |
paul@15 | 77 | |
paul@15 | 78 | static void *lcd_base; |
paul@15 | 79 | |
paul@15 | 80 | void lcd_init(void) |
paul@15 | 81 | { |
paul@20 | 82 | __lcd_display_pin_init(); |
paul@20 | 83 | __lcd_display_on(); |
paul@20 | 84 | |
paul@15 | 85 | /* Start from the top of memory and obtain a framebuffer region. */ |
paul@15 | 86 | |
paul@15 | 87 | lcd_base = (void *) lcd_setmem(get_memory_size()); |
paul@15 | 88 | lcd_ctrl_init(lcd_base); |
paul@15 | 89 | lcd_clear(lcd_base); |
paul@15 | 90 | lcd_enable(); |
paul@15 | 91 | } |