summaryrefslogtreecommitdiffstats
path: root/firmware/target/arm/s5l8700/yps3/lcd-yps3.c
blob: 2445198c651c64cb3c055495e8e8b957bcdd16e9 (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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * Copyright (C) 2009 by Bertrik Sikken
 *
 * 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 "s5l87xx.h"
#include "lcd.h"

/*  LCD driver for the Samsung YP-S3

    It appears that this player can contain two display types.
    Detection of the display type is done by looking at the level of pin P0.4.
    Currently only display "type 2" has been implemented and tested.
    
    This driver could use DMA to do the screen updates, but currently writes
    the data to the LCD using the processor instead.
*/


static int lcd_type = 0;


static void lcd_delay(int delay)
{
    volatile int i;
    for (i = 0; i < delay; i++);
}

static void lcd_reset_delay(void)
{
    lcd_delay(10000);
}

static void lcd_reset(void)
{
    LCD_CON = 0xDB8;
    LCD_PHTIME = 0x22;
    LCD_RST_TIME = 0x7FFF;
    
    lcd_reset_delay();
    LCD_DRV_RST = 0;
    lcd_reset_delay();
    LCD_DRV_RST = 1;
    lcd_reset_delay();
    LCD_DRV_RST = 0;
    lcd_reset_delay();
    LCD_DRV_RST = 1;
    
    LCD_INTCON = 0;
}

static void lcd_wcmd(unsigned int cmd)
{
    while ((LCD_STATUS & 0x10) != 0);
    LCD_WCMD = cmd;
}

static void lcd_wdata(unsigned int data)
{
    while ((LCD_STATUS & 0x10) != 0);
    LCD_WDATA = data;
}

static void lcd_wcmd_data(unsigned int cmd, unsigned int data)
{
    lcd_wcmd(cmd);
    lcd_wdata(data);
}

static void lcd_init1(void)
{
    lcd_wcmd(0x11);
    lcd_delay(10000);
    
    lcd_wcmd(0xF0);
    lcd_wdata(0x5A);
    
    lcd_wcmd(0xC0);
    lcd_wdata(0x05);
    lcd_wdata(0x01);
    
    lcd_wcmd(0xC1);
    lcd_wdata(0x04);
    
    lcd_wcmd(0xC5);
    lcd_wdata(0xB0);
    
    lcd_wcmd(0xC6);
    lcd_wdata(0x0);
    
    lcd_wcmd(0xB1);
    lcd_wdata(0x02);
    lcd_wdata(0x0E);
    lcd_wdata(0x00);
    
    lcd_wcmd(0xF2);
    lcd_wdata(0x01);
    
    lcd_wcmd(0xE0);
    lcd_wdata(0x09);
    lcd_wdata(0x00);
    lcd_wdata(0x06);
    lcd_wdata(0x2E);
    lcd_wdata(0x2B);
    lcd_wdata(0x0B);
    lcd_wdata(0x1A);
    lcd_wdata(0x02);
    lcd_wdata(0x06);
    lcd_wdata(0x0C);
    lcd_wdata(0x0D);
    lcd_wdata(0x00);
    lcd_wdata(0x05);
    lcd_wdata(0x02);
    lcd_wdata(0x05);
    
    lcd_wcmd(0xE1);
    lcd_wdata(0x06);
    lcd_wdata(0x23);
    lcd_wdata(0x25);
    lcd_wdata(0x0F);
    lcd_wdata(0x0A);
    lcd_wdata(0x04);
    lcd_wdata(0x02);
    lcd_wdata(0x1A);
    lcd_wdata(0x05);
    lcd_wdata(0x03);
    lcd_wdata(0x06);
    lcd_wdata(0x01);
    lcd_wdata(0x0C);
    lcd_wdata(0x0B);
    lcd_wdata(0x05);
    lcd_wdata(0x05);
    
    lcd_wcmd(0x3A);
    lcd_wdata(0x05);
    
    lcd_wcmd(0x29);
    
    lcd_wcmd(0x2C);
}

static void lcd_init2(void)
{
    lcd_wcmd_data(0x00, 0x0001);
    lcd_delay(50000);
    
    lcd_wcmd_data(0x07, 0x0000);
    lcd_wcmd_data(0x12, 0x0000);
    lcd_delay(10000);
    
    lcd_wcmd(0);
    lcd_wcmd(0);
    lcd_wcmd(0);
    lcd_wcmd(0);

    lcd_wcmd_data(0xA4, 0x0001);
    lcd_delay(10000);

    lcd_wcmd_data(0x70, 0x1B00);
    lcd_wcmd_data(0x08, 0x030A);
    lcd_wcmd_data(0x30, 0x0000);
    lcd_wcmd_data(0x31, 0x0305);
    lcd_wcmd_data(0x32, 0x0304);
    lcd_wcmd_data(0x33, 0x0107);
    lcd_wcmd_data(0x34, 0x0304);

    lcd_wcmd_data(0x35, 0x0204);
    lcd_wcmd_data(0x36, 0x0707);
    lcd_wcmd_data(0x37, 0x0701);
    lcd_wcmd_data(0x38, 0x1B08);
    lcd_wcmd_data(0x39, 0x030F);
    lcd_wcmd_data(0x3A, 0x0E0E);

    lcd_wcmd_data(0x07, 0x0001);
    lcd_delay(50000);

    lcd_wcmd_data(0x18, 0x0001);
    lcd_wcmd_data(0x10, 0x12B0);
    lcd_wcmd_data(0x11, 0x0001);

    lcd_wcmd_data(0x12, 0x0114);
    lcd_wcmd_data(0x13, 0x8D0F);
    lcd_wcmd_data(0x12, 0x0134);
    lcd_delay(1000);
    lcd_wcmd_data(0x01, 0x0100);
    lcd_wcmd_data(0x02, 0x0700);
    lcd_wcmd_data(0x03, 0x5030);

    lcd_wcmd_data(0x04, 0x0000);
    lcd_wcmd_data(0x09, 0x0000);
    lcd_wcmd_data(0x0C, 0x0000);
    lcd_wcmd_data(0x0F, 0x0000);

    lcd_wcmd_data(0x14, 0x8000);
    lcd_wcmd_data(0x20, 0x0000);
    lcd_wcmd_data(0x21, 0x0000);
    lcd_wcmd_data(0x71, 0x0001);
    lcd_wcmd_data(0x7A, 0x0000);
    lcd_wcmd_data(0x90, 0x0000);
    lcd_wcmd_data(0x91, 0x0100);
    lcd_wcmd_data(0x92, 0x0000);
    lcd_wcmd_data(0x98, 0x0001);
    lcd_wcmd_data(0x99, 0x030C);
    lcd_wcmd_data(0x9A, 0x030C);
    
    lcd_delay(50000);
    lcd_wcmd_data(0x07, 0x0001);
    lcd_delay(30000);
    lcd_wcmd_data(0x07, 0x0021);
    
    lcd_wcmd_data(0x12, 0x1134);
    lcd_delay(10000);
    
    lcd_wcmd_data(0x07, 0x0233);
    lcd_delay(30000);
}


static void lcd_set_window1(int x, int y, int width, int height)
{
    (void)x;
    (void)width;

    lcd_wcmd(0x2A);
    lcd_wdata(0);
    lcd_wdata(y);
    lcd_wdata(0);

    lcd_wcmd(0x2B);
    lcd_wdata(0);
    lcd_wdata(y + height - 1);
    lcd_wdata(0);
}

static void lcd_set_window2(int x, int y, int width, int height)
{
    lcd_wcmd_data(0x50, x);
    lcd_wcmd_data(0x51, x + width - 1);
    lcd_wcmd_data(0x52, y);
    lcd_wcmd_data(0x53, y + height - 1);
}


static void lcd_set_position1(int x, int y)
{
    (void)x;
    (void)y;
}

static void lcd_set_position2(int x, int y)
{
    lcd_wcmd_data(0x20, x);
    lcd_wcmd_data(0x21, y);
    lcd_wcmd(0x22);
}

void lcd_init_device(void)
{
    /* enable LCD clock */
    PWRCON &= ~(1 << 18);

    /* configure LCD pins */
    PCON0 &= ~(3 << 8);
    PCON7 = (PCON7 & ~(0x000000FF)) | 0x00000033;
    PCON_ASRAM = 2;

    lcd_reset();
    
    /* detect LCD type on P0.4 */
    lcd_type = (PDAT0 & (1 << 4)) ? 1 : 2;
    
    /* initialise display */
    if (lcd_type == 1) {
        lcd_init1();
    } else {
        lcd_init2();
    }
}

void lcd_update_rect(int x, int y, int width, int height)
{
    fb_data* p;
    int h, w;

    void* (*fbaddr)(int x, int y) = FB_CURRENTVP_BUFFER->get_address_fn;
    if (lcd_type == 1) {
        /* TODO implement and test */
        lcd_set_window1(x, y, width, height);
        lcd_set_position1(x, y);

        for (h = 0; h < height; h++) {
            p = fbaddr(0,y);
            for (w = 0; w < LCD_WIDTH; w++) {
                while (LCD_STATUS & 0x10);
                LCD_WDATA = *p++;
            }
            y++;
        }
    }
    else {
        lcd_set_window2(x, y, width, height);
        lcd_set_position2(x, y);

        for (h = 0; h < height; h++) {
            p = fbaddr(x,y);
            for (w = 0; w < width; w++) {
                while (LCD_STATUS & 0x10);
                LCD_WDATA = *p++;
            }
            y++;
        }
    }
}

void lcd_update(void)
{
    lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT);
}