summaryrefslogtreecommitdiffstats
path: root/firmware/target/arm/rk27xx/ma/lcd-ma.c
blob: a35f13ba3a8bd9817da8beb2be3f753fd23a3a70 (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
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * Copyright (C)  2013 Andrew Ryabinin
 *
 *
 * 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 "kernel.h"
#include "lcd.h"
#include "system.h"
#include "cpu.h"
#include "lcdif-rk27xx.h"

static bool display_on = false;


void lcd_display_init(void)
{
    int i;
    unsigned int x, y;

    lcd_cmd(0x00B9);
    lcd_data(0x00FF);
    lcd_data(0x0093);
    lcd_data(0x0042);

    lcd_cmd(0x0021); /* display inversion on ??? */

    /* memory access control */
    lcd_cmd(0x0036);
    lcd_data(0x00C9);

    /* set 16-bit pixel format */
    lcd_cmd(0x003A);
    lcd_data(0x0005);

    /* Setup color depth conversion lookup table */
    lcd_cmd(0x002D);
    /* red */
    for(i = 0; i < 32; i++)
        lcd_data(2*i);
    /* green */
    for(i = 0; i < 64; i++)
        lcd_data(1*i);
    /* blue */
    for(i = 0; i < 32; i++)
        lcd_data(2*i);

    /* power control settings */
    lcd_cmd(0x00C0);
    lcd_data(0x0025); /* VREG1OUT 4.70V */
    lcd_data(0x000A); /* VCOM 2.8V */

    lcd_cmd(0x00C1);
    lcd_data(0x0001);

    lcd_cmd(0x00C5);
    lcd_data(0x002F);
    lcd_data(0x0027);

    lcd_cmd(0x00C7);
    lcd_data(0x00D3);

    lcd_cmd(0x00B8);
    lcd_data(0x000B);

    /* Positive gamma correction */
    lcd_cmd(0x00E0);
    lcd_data(0x000F);
    lcd_data(0x0022);
    lcd_data(0x001D);
    lcd_data(0x000B);
    lcd_data(0x000F);
    lcd_data(0x0007);
    lcd_data(0x004C);
    lcd_data(0x0076);
    lcd_data(0x003C);
    lcd_data(0x0009);
    lcd_data(0x0016);
    lcd_data(0x0007);
    lcd_data(0x0012);
    lcd_data(0x000B);
    lcd_data(0x0008);

    /* Negative Gamma Correction */
    lcd_cmd(0x00E1);
    lcd_data(0x0008);
    lcd_data(0x001F);
    lcd_data(0x0024);
    lcd_data(0x0003);
    lcd_data(0x000E);
    lcd_data(0x0003);
    lcd_data(0x0035);
    lcd_data(0x0023);
    lcd_data(0x0045);
    lcd_data(0x0001);
    lcd_data(0x000B);
    lcd_data(0x0007);
    lcd_data(0x002F);
    lcd_data(0x0036);
    lcd_data(0x000F);

    lcd_cmd(0x00F2);
    lcd_data(0x0000);

    /* exit sleep */
    lcd_cmd(0x0011);
    udelay(5000);
    lcd_cmd(0x0029);

    lcd_cmd(0x002C);
    for (x = 0; x < LCD_WIDTH; x++)
        for(y=0; y < LCD_HEIGHT; y++)
            lcd_data(0x00);

    display_on = true;
}

void lcd_enable (bool on)
{
    if (on == display_on)
        return;

    lcdctrl_bypass(1);
    LCDC_CTRL |= RGB24B;

    if (on) {
        lcd_cmd(0x11);
    } else {
        lcd_cmd(0x10);
    }
    udelay(5000);

    display_on = on;
    LCDC_CTRL &= ~RGB24B;
}

void lcd_set_gram_area(int x_start, int y_start,
                       int x_end, int y_end)
{
    lcdctrl_bypass(1);
    LCDC_CTRL |= RGB24B;

    lcd_cmd(0x002A);
    lcd_data((x_start&0xff00)>>8);
    lcd_data(x_start&0x00ff);
    lcd_data((x_end&0xff00)>>8);
    lcd_data(x_end&0x00ff);
    lcd_cmd(0x002B);
    lcd_data((y_start&0xff00)>>8);
    lcd_data(y_start&0x00ff);
    lcd_data((y_end&0xff00)>>8);
    lcd_data(y_end&0x00ff);

    lcd_cmd(0x2c);
    LCDC_CTRL &= ~RGB24B;
}

bool lcd_active()
{
    return display_on;
}

/* Blit a YUV bitmap directly to the LCD */
void lcd_blit_yuv(unsigned char * const src[3],
                  int src_x, int src_y, int stride,
                  int x, int y, int width, int height)
{
    (void)src;
    (void)src_x;
    (void)src_y;
    (void)stride;
    (void)x;
    (void)y;
    (void)width;
    (void)height;
}