* Onda VX767: fix some redundant files + add some missing functions for apps/ compila...
[kugel-rb.git] / firmware / target / mips / ingenic_jz47xx / onda_vx767 / lcd-onda_vx767.c
blob3cf2586d46a8c0f975b2c3adb55743c17d378afb
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2008 by Maurus Cuelenaere
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "config.h"
23 #include "jz4740.h"
24 #include "lcd-target.h"
26 #define PIN_CS_N (32*1+17) /* Chip select */
27 #define PIN_RESET_N (32*1+18) /* Reset */
28 #define PIN_UNK_N (32*2+19)
30 #define my__gpio_as_lcd_16bit() \
31 do { \
32 REG_GPIO_PXFUNS(2) = 0x0014ffff; \
33 REG_GPIO_PXSELC(2) = 0x0014ffff; \
34 REG_GPIO_PXPES(2) = 0x0014ffff; \
35 } while (0)
38 #define SLEEP(x) for(i=0; i<x; i++) asm("nop"); asm("nop");
39 #define DELAY SLEEP(700000);
40 static void _display_pin_init(void)
42 int i;
43 my__gpio_as_lcd_16bit();
44 __gpio_as_output(PIN_UNK_N);
45 __gpio_set_pin(PIN_UNK_N);
46 __gpio_as_output(PIN_CS_N);
47 __gpio_as_output(PIN_RESET_N);
48 DELAY; /* delay_ms(10); */
50 __gpio_clear_pin(PIN_CS_N);
51 DELAY; /* delay_ms(10); */
53 __gpio_set_pin(PIN_RESET_N);
54 DELAY; /* delay_ms(10); */
55 __gpio_clear_pin(PIN_RESET_N);
56 DELAY; /* delay_ms(10); */
57 __gpio_set_pin(PIN_RESET_N);
58 DELAY; /* delay_ms(10); */
61 #define WAIT_ON_SLCD while(REG_SLCD_STATE & SLCD_STATE_BUSY);
62 #define SLCD_SET_DATA(x) REG_SLCD_DATA = (x) | SLCD_DATA_RS_DATA;
63 #define SLCD_SET_COMMAND(x) REG_SLCD_DATA = (x) | SLCD_DATA_RS_COMMAND;
65 #define SLCD_SEND_COMMAND(cmd,val) \
66 __gpio_clear_pin(PIN_UNK_N); \
67 SLCD_SET_COMMAND(cmd); \
68 WAIT_ON_SLCD; \
69 __gpio_set_pin(PIN_UNK_N); \
70 SLCD_SET_DATA(val); \
71 WAIT_ON_SLCD;
73 static void _display_init(void)
75 int i;
77 SLCD_SEND_COMMAND(0xE3, 0x8);
78 SLCD_SEND_COMMAND(0xE4, 0x1411);
79 SLCD_SEND_COMMAND(0xE5, 0x8000);
80 SLCD_SEND_COMMAND(0x0, 0x1);
81 DELAY; /* delay_ms(10); */
83 SLCD_SEND_COMMAND(0x1, 0x100);
84 SLCD_SEND_COMMAND(0x2, 0x400);
85 SLCD_SEND_COMMAND(0x3, 0x1028);
86 SLCD_SEND_COMMAND(0x4, 0);
87 SLCD_SEND_COMMAND(0x8, 0x202);
88 SLCD_SEND_COMMAND(0x9, 0);
89 SLCD_SEND_COMMAND(0xA, 0);
90 SLCD_SEND_COMMAND(0xC, 0);
91 SLCD_SEND_COMMAND(0xD, 0);
92 SLCD_SEND_COMMAND(0xF, 0);
93 SLCD_SEND_COMMAND(0x10, 0);
94 SLCD_SEND_COMMAND(0x11, 0x7);
95 SLCD_SEND_COMMAND(0x12, 0);
96 SLCD_SEND_COMMAND(0x13, 0);
97 SLCD_SEND_COMMAND(0x10, 0x17B0);
98 SLCD_SEND_COMMAND(0x11, 0x4);
99 SLCD_SEND_COMMAND(0x12, 0x13C);
100 SLCD_SEND_COMMAND(0x13, 0x1B00);
101 SLCD_SEND_COMMAND(0x29, 0x16);
102 SLCD_SEND_COMMAND(0x20, 0);
103 SLCD_SEND_COMMAND(0x21, 0);
104 SLCD_SEND_COMMAND(0x2B, 0x20);
105 SLCD_SEND_COMMAND(0x30, 0);
106 SLCD_SEND_COMMAND(0x31, 0x403);
107 SLCD_SEND_COMMAND(0x32, 0x400);
108 SLCD_SEND_COMMAND(0x35, 0x5);
109 SLCD_SEND_COMMAND(0x36, 0x6);
110 SLCD_SEND_COMMAND(0x37, 0x606);
111 SLCD_SEND_COMMAND(0x38, 0x106);
112 SLCD_SEND_COMMAND(0x39, 0x7);
113 SLCD_SEND_COMMAND(0x3C, 0x700);
114 SLCD_SEND_COMMAND(0x3D, 0x707);
115 SLCD_SEND_COMMAND(0x50, 0);
116 SLCD_SEND_COMMAND(0x51, 239);
117 SLCD_SEND_COMMAND(0x52, 0);
118 SLCD_SEND_COMMAND(0x53, 319);
119 SLCD_SEND_COMMAND(0x60, 0x2700);
120 SLCD_SEND_COMMAND(0x61, 0x1);
121 SLCD_SEND_COMMAND(0x6A, 0);
122 SLCD_SEND_COMMAND(0x80, 0);
123 SLCD_SEND_COMMAND(0x81, 0);
124 SLCD_SEND_COMMAND(0x82, 0);
125 SLCD_SEND_COMMAND(0x83, 0);
126 SLCD_SEND_COMMAND(0x84, 0);
127 SLCD_SEND_COMMAND(0x85, 0);
128 SLCD_SEND_COMMAND(0x90, 0x10);
129 SLCD_SEND_COMMAND(0x92, 0);
130 SLCD_SEND_COMMAND(0x93, 0x3);
131 SLCD_SEND_COMMAND(0x95, 0x110);
132 SLCD_SEND_COMMAND(0x97, 0);
133 SLCD_SEND_COMMAND(0x98, 0);
134 SLCD_SEND_COMMAND(0x7, 0x173);
136 __gpio_clear_pin(PIN_UNK_N);
137 SLCD_SET_COMMAND(0x22);
138 WAIT_ON_SLCD;
139 __gpio_set_pin(PIN_UNK_N);
142 static void _display_on(void)
146 static void _display_off(void)
150 static void _set_lcd_bus(void)
152 REG_LCD_CFG &= ~LCD_CFG_LCDPIN_MASK;
153 REG_LCD_CFG |= LCD_CFG_LCDPIN_SLCD;
155 REG_SLCD_CFG = (SLCD_CFG_BURST_4_WORD | SLCD_CFG_DWIDTH_18 | SLCD_CFG_CWIDTH_18BIT
156 | SLCD_CFG_CS_ACTIVE_LOW | SLCD_CFG_RS_CMD_LOW | SLCD_CFG_CLK_ACTIVE_FALLING
157 | SLCD_CFG_TYPE_PARALLEL);
159 REG_SLCD_CTRL = SLCD_CTRL_DMA_EN;
162 static void _set_lcd_clock(void)
164 unsigned int val;
165 int pll_div;
167 __cpm_stop_lcd();
168 pll_div = ( REG_CPM_CPCCR & CPM_CPCCR_PCS ); /* clock source, 0:pllout/2 1: pllout */
169 pll_div = pll_div ? 1 : 2 ;
170 val = ( __cpm_get_pllout()/pll_div ) / 336000000;
171 val--;
172 if ( val > 0x1ff )
173 val = 0x1ff; /* CPM_LPCDR is too large, set it to 0x1ff */
174 __cpm_set_pixdiv(val);
175 __cpm_start_lcd();
178 void lcd_init_controller(void)
180 int i;
181 _display_pin_init();
182 _set_lcd_bus();
183 _set_lcd_clock();
184 SLEEP(1000);
185 _display_init();
188 void lcd_set_target(short x, short y, short width, short height)
190 SLCD_SEND_COMMAND(0x50, y);
191 SLCD_SEND_COMMAND(0x51, y+height-1);
192 SLCD_SEND_COMMAND(0x52, x);
193 SLCD_SEND_COMMAND(0x53, x+width-1);
194 /* TODO */
196 __gpio_clear_pin(PIN_UNK_N);
197 SLCD_SET_COMMAND(0x22);
198 WAIT_ON_SLCD;
199 __gpio_set_pin(PIN_UNK_N);
202 void lcd_on(void)
204 _display_on();
207 void lcd_off(void)
209 _display_off();
212 void lcd_set_contrast(int val)
214 (void)val;