summaryrefslogtreecommitdiffstats
path: root/firmware/target/mips/ingenic_jz47xx/onda_vx747/lcd-onda_vx747.c
blob: 22a67091660c33d4016d7d1a7640d935fd9cfcbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * Copyright (C) 2008 by Maurus Cuelenaere
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/

#include "config.h"
#include "jz4740.h"
#include "r61509.h"
#include "lcd.h"
#include "lcd-target.h"

#define PIN_CS_N    (32*1+17)  /* Chip select */
#define PIN_RESET_N (32*1+18)  /* Reset       */
#define LCD_PCLK    (20000000) /* LCD PCLK    */

#define my__gpio_as_lcd_16bit()         \
do {                                    \
    REG_GPIO_PXFUNS(2) = 0x001cffff;    \
    REG_GPIO_PXSELC(2) = 0x001cffff;    \
    REG_GPIO_PXPES(2)  = 0x001cffff;    \
} while (0)

#define SLEEP(x) { register int __i; for(__i=0; __i<x; __i++) asm volatile("ssnop\n ssnop\n"); }
#define DELAY    SLEEP(700000);

#if ((defined(ONDA_VX777) || defined(ONDA_VX747P)) && !defined(BOOTLOADER)) \
    || defined(USB_BOOT)
 /*
  * Onda VX777/VX747+ needs this in order to boot correctly, it looks like the
  * SPL does not correctly initialize the LCD for Rockbox to switch it on.
  */
 #define RESET_LCD
#endif

#ifdef RESET_LCD
static void _display_pin_init(void)
{
    my__gpio_as_lcd_16bit();
    __gpio_as_output(PIN_CS_N);
    __gpio_as_output(PIN_RESET_N);
    __gpio_clear_pin(PIN_CS_N);

    __gpio_set_pin(PIN_RESET_N);
    DELAY;
    __gpio_clear_pin(PIN_RESET_N);
    DELAY;
    __gpio_set_pin(PIN_RESET_N);
    DELAY;
}
#endif

#define WAIT_ON_SLCD while(REG_SLCD_STATE & SLCD_STATE_BUSY);
#define SLCD_SET_DATA(x) WAIT_ON_SLCD; REG_SLCD_DATA = (x) | SLCD_DATA_RS_DATA;
#define SLCD_SET_COMMAND(x) WAIT_ON_SLCD; REG_SLCD_DATA = (x) | SLCD_DATA_RS_COMMAND;
#define SLCD_SEND_COMMAND(cmd,val) SLCD_SET_COMMAND(cmd); SLCD_SET_DATA(val);
static void _display_init(void)
{
#ifdef RESET_LCD
    SLCD_SEND_COMMAND(REG_SOFT_RESET, SOFT_RESET(1));
    SLEEP(700000);
    SLCD_SEND_COMMAND(REG_SOFT_RESET, SOFT_RESET(0));
    SLEEP(700000);
    SLCD_SEND_COMMAND(REG_ENDIAN_CTRL, 0);

    SLCD_SEND_COMMAND(REG_DRIVER_OUTPUT, 0x100);
    SLCD_SEND_COMMAND(REG_LCD_DR_WAVE_CTRL, 0x100);
#endif

#if CONFIG_ORIENTATION == SCREEN_PORTRAIT
    SLCD_SEND_COMMAND(REG_ENTRY_MODE, (ENTRY_MODE_BGR | ENTRY_MODE_VID | ENTRY_MODE_HID));
#else
    SLCD_SEND_COMMAND(REG_ENTRY_MODE, (ENTRY_MODE_BGR | ENTRY_MODE_VID | ENTRY_MODE_AM));
#endif

#ifdef RESET_LCD
    SLCD_SEND_COMMAND(REG_DISP_CTRL2, 0x503);
    SLCD_SEND_COMMAND(REG_DISP_CTRL3, 1);
    SLCD_SEND_COMMAND(REG_LPCTRL, 0x10);
    SLCD_SEND_COMMAND(REG_EXT_DISP_CTRL1, EXT_DISP_CTRL1_RIM(1)); /* 16-bit RGB interface */
    SLCD_SEND_COMMAND(REG_EXT_DISP_CTRL2, 0);
    SLCD_SEND_COMMAND(REG_DISP_CTRL1, DISP_CTRL1_D(1));
    SLCD_SEND_COMMAND(REG_PAN_INTF_CTRL1, 0x12);
    SLCD_SEND_COMMAND(REG_PAN_INTF_CTRL2, 0x202);
    SLCD_SEND_COMMAND(REG_PAN_INTF_CTRL3, 0x300);
    SLCD_SEND_COMMAND(REG_PAN_INTF_CTRL4, 0x21e);
    SLCD_SEND_COMMAND(REG_PAN_INTF_CTRL5, 0x202);
    SLCD_SEND_COMMAND(REG_PAN_INTF_CTRL6, 0x100);
    SLCD_SEND_COMMAND(REG_FRM_MRKR_CTRL, 0x8000);
    SLCD_SEND_COMMAND(REG_PWR_CTRL1, (PWR_CTRL1_SAPE | PWR_CTRL1_BT(6) | PWR_CTRL1_APE | PWR_CTRL1_AP(3)));
    SLCD_SEND_COMMAND(REG_PWR_CTRL2, 0x147);
    SLCD_SEND_COMMAND(REG_PWR_CTRL3, 0x1bd);
    SLCD_SEND_COMMAND(REG_PWR_CTRL4, 0x2f00);
    SLCD_SEND_COMMAND(REG_PWR_CTRL5, 0);
    SLCD_SEND_COMMAND(REG_PWR_CTRL6, 1);
    SLCD_SEND_COMMAND(REG_RW_NVM, 0);
    SLCD_SEND_COMMAND(REG_VCOM_HVOLTAGE1, 6);
    SLCD_SEND_COMMAND(REG_VCOM_HVOLTAGE2, 0);
    SLCD_SEND_COMMAND(REG_GAMMA_CTRL1, 0x101);
    SLCD_SEND_COMMAND(REG_GAMMA_CTRL2, 0xb27);
    SLCD_SEND_COMMAND(REG_GAMMA_CTRL3, 0x132a);
    SLCD_SEND_COMMAND(REG_GAMMA_CTRL4, 0x2a13);
    SLCD_SEND_COMMAND(REG_GAMMA_CTRL5, 0x270b);
    SLCD_SEND_COMMAND(REG_GAMMA_CTRL6, 0x101);
    SLCD_SEND_COMMAND(REG_GAMMA_CTRL7, 0x1205);
    SLCD_SEND_COMMAND(REG_GAMMA_CTRL8, 0x512);
    SLCD_SEND_COMMAND(REG_GAMMA_CTRL9, 5);
    SLCD_SEND_COMMAND(REG_GAMMA_CTRL10, 3);
    SLCD_SEND_COMMAND(REG_GAMMA_CTRL11, 0xf04);
    SLCD_SEND_COMMAND(REG_GAMMA_CTRL12, 0xf00);
    SLCD_SEND_COMMAND(REG_GAMMA_CTRL13, 0xf);
    SLCD_SEND_COMMAND(REG_GAMMA_CTRL14, 0x40f);
    SLCD_SEND_COMMAND(0x30e, 0x300);
    SLCD_SEND_COMMAND(0x30f, 0x500);
    SLCD_SEND_COMMAND(REG_BIMG_NR_LINE, 0x3100);
    SLCD_SEND_COMMAND(REG_BIMG_DISP_CTRL, 1);
    SLCD_SEND_COMMAND(REG_BIMG_VSCROLL_CTRL, 0);
    SLCD_SEND_COMMAND(REG_PARTIMG1_POS, 0);
    SLCD_SEND_COMMAND(REG_PARTIMG1_RAM_START, 0);
    SLCD_SEND_COMMAND(REG_PARTIMG1_RAM_END, 0);
    SLCD_SEND_COMMAND(REG_PARTIMG2_POS, 0);
    SLCD_SEND_COMMAND(REG_PARTIMG2_RAM_START, 0);
    SLCD_SEND_COMMAND(REG_PARTIMG2_RAM_END, 0);
    SLCD_SEND_COMMAND(REG_ENDIAN_CTRL, 0);
    SLCD_SEND_COMMAND(REG_NVM_ACCESS_CTRL, 0);
    SLCD_SEND_COMMAND(0x7f0, 0x5420);
    SLCD_SEND_COMMAND(0x7f3, 0x288a);
    SLCD_SEND_COMMAND(0x7f4, 0x22);
    SLCD_SEND_COMMAND(0x7f5, 1);
    SLCD_SEND_COMMAND(0x7f0, 0);

    /* LCD ON */
    SLCD_SEND_COMMAND(REG_DISP_CTRL1, (DISP_CTRL1_BASEE | DISP_CTRL1_VON |
                                       DISP_CTRL1_GON   | DISP_CTRL1_DTE | DISP_CTRL1_D(3)));
    SLEEP(3500000);
    SLCD_SEND_COMMAND(REG_DISP_CTRL1, (DISP_CTRL1_BASEE | DISP_CTRL1_VON |
                                       DISP_CTRL1_GON   | DISP_CTRL1_DTE | DISP_CTRL1_D(2)));
    SLEEP(3500000);
    SLCD_SEND_COMMAND(REG_DISP_CTRL1, (DISP_CTRL1_BASEE | DISP_CTRL1_VON |
                                       DISP_CTRL1_GON   | DISP_CTRL1_DTE | DISP_CTRL1_D(3)));
    SLEEP(3500000);
#endif /* RESET_LCD */
}

static void _display_on(void)
{
    SLCD_SEND_COMMAND(REG_PWR_CTRL1, (PWR_CTRL1_SAPE | PWR_CTRL1_BT(6) | PWR_CTRL1_APE | PWR_CTRL1_AP(3)));
    SLEEP(3500000);
    SLCD_SEND_COMMAND(REG_DISP_CTRL1, (DISP_CTRL1_VON | DISP_CTRL1_GON |
                                       DISP_CTRL1_D(1)));
    SLEEP(3500000);
    SLCD_SEND_COMMAND(REG_DISP_CTRL1, (DISP_CTRL1_VON | DISP_CTRL1_GON  |
                                       DISP_CTRL1_DTE | DISP_CTRL1_D(3) |
                                       DISP_CTRL1_BASEE));
}

static void _display_off(void)
{
    SLCD_SEND_COMMAND(REG_DISP_CTRL1, (DISP_CTRL1_VON | DISP_CTRL1_GON |
                                       DISP_CTRL1_DTE | DISP_CTRL1_D(2)));
    SLEEP(3500000);
    SLCD_SEND_COMMAND(REG_DISP_CTRL1, DISP_CTRL1_D(1));
    SLEEP(3500000);
    SLCD_SEND_COMMAND(REG_DISP_CTRL1, DISP_CTRL1_D(0));
    SLEEP(3500000);
    SLCD_SEND_COMMAND(REG_PWR_CTRL1, PWR_CTRL1_SLP);
}

static void _set_lcd_bus(void)
{
    REG_LCD_CFG &= ~LCD_CFG_LCDPIN_MASK;
    REG_LCD_CFG |= LCD_CFG_LCDPIN_SLCD;

    REG_SLCD_CFG = (SLCD_CFG_BURST_8_WORD | SLCD_CFG_DWIDTH_16 | SLCD_CFG_CWIDTH_16BIT |
                    SLCD_CFG_CS_ACTIVE_LOW | SLCD_CFG_RS_CMD_LOW | SLCD_CFG_CLK_ACTIVE_FALLING |
                    SLCD_CFG_TYPE_PARALLEL);
}

static void _set_lcd_clock(void)
{
    unsigned int val;

    __cpm_stop_lcd();

    val = (__cpm_get_pllout2() / LCD_PCLK) - 1;
    if ( val > 0x1ff )
        val = 0x1ff; /* CPM_LPCDR is too large, set it to 0x1ff */
    __cpm_set_pixdiv(val);

    __cpm_start_lcd();
}

void lcd_init_controller(void)
{
    lcd_clock_enable();

#ifdef RESET_LCD
    _display_pin_init();
#endif
    _set_lcd_bus();
    _set_lcd_clock();
    SLEEP(1000);
    _display_init();

    lcd_clock_disable();
}

void lcd_set_target(int x, int y, int width, int height)
{
#if CONFIG_ORIENTATION == SCREEN_PORTRAIT
    SLCD_SEND_COMMAND(REG_RAM_HADDR_START, x);
    SLCD_SEND_COMMAND(REG_RAM_HADDR_END,   x + width  - 1);
    SLCD_SEND_COMMAND(REG_RAM_VADDR_START, y);
    SLCD_SEND_COMMAND(REG_RAM_VADDR_END,   y + height - 1);
    SLCD_SEND_COMMAND(REG_RAM_HADDR_SET,   x);
    SLCD_SEND_COMMAND(REG_RAM_VADDR_SET,   y);
#else
    SLCD_SEND_COMMAND(REG_RAM_HADDR_START, y);
    SLCD_SEND_COMMAND(REG_RAM_HADDR_END,   y + height - 1);
    SLCD_SEND_COMMAND(REG_RAM_VADDR_START, x);
    SLCD_SEND_COMMAND(REG_RAM_VADDR_END,   x + width  - 1);
    SLCD_SEND_COMMAND(REG_RAM_HADDR_SET,   y);
    SLCD_SEND_COMMAND(REG_RAM_VADDR_SET,   x);
#endif
    SLCD_SET_COMMAND(REG_RW_GRAM); /* write data to GRAM */
}

void lcd_set_flip(bool yesno)
{
    __cpm_start_lcd();
#if CONFIG_ORIENTATION == SCREEN_PORTRAIT
    if(yesno)
    {
        SLCD_SEND_COMMAND(REG_ENTRY_MODE, ENTRY_MODE_BGR);
    }
    else
    {
        SLCD_SEND_COMMAND(REG_ENTRY_MODE, (ENTRY_MODE_BGR | ENTRY_MODE_VID | ENTRY_MODE_HID));
    }
#else
    if(yesno)
    {
        SLCD_SEND_COMMAND(REG_ENTRY_MODE, (ENTRY_MODE_BGR | ENTRY_MODE_HID | ENTRY_MODE_AM));
    }
    else
    {
        SLCD_SEND_COMMAND(REG_ENTRY_MODE, (ENTRY_MODE_BGR | ENTRY_MODE_VID | ENTRY_MODE_AM));
    }
#endif
    DELAY;
    __cpm_stop_lcd();
}

void lcd_on(void)
{
    lcd_clock_enable();

    _display_on();

    lcd_clock_disable();
}

void lcd_off(void)
{
    lcd_clock_enable();

    _display_off();

    lcd_clock_disable();
}

void lcd_set_contrast(int val)
{
    (void)val;
}