]> git.sur5r.net Git - u-boot/blob - board/bf548-ezkit/video.c
Merge branch 'master' of git://git.denx.de/u-boot-ppc4xx
[u-boot] / board / bf548-ezkit / video.c
1 /*
2  * video.c - run splash screen on lcd
3  *
4  * Copyright (c) 2007-2008 Analog Devices Inc.
5  *
6  * Licensed under the GPL-2 or later.
7  */
8
9 #include <stdarg.h>
10 #include <common.h>
11 #include <config.h>
12 #include <malloc.h>
13 #include <asm/blackfin.h>
14 #include <asm/mach-common/bits/dma.h>
15 #include <i2c.h>
16 #include <linux/types.h>
17 #include <stdio_dev.h>
18
19 #define DMA_SIZE16      2
20
21 #include <asm/mach-common/bits/eppi.h>
22
23 #include <asm/bfin_logo_230x230.h>
24
25 #define LCD_X_RES               480     /*Horizontal Resolution */
26 #define LCD_Y_RES               272     /* Vertical Resolution */
27
28 #define LCD_BPP                 24      /* Bit Per Pixel */
29 #define LCD_PIXEL_SIZE          (LCD_BPP / 8)
30 #define DMA_BUS_SIZE            32
31 #define ACTIVE_VIDEO_MEM_OFFSET 0
32
33 /*      -- Horizontal synchronizing --
34  *
35  * Timing characteristics taken from the SHARP LQ043T1DG01 datasheet
36  * (LCY-W-06602A Page 9 of 22)
37  *
38  * Clock Frequency      1/Tc Min 7.83 Typ 9.00 Max 9.26 MHz
39  *
40  * Period               TH - 525 - Clock
41  * Pulse width          THp - 41 - Clock
42  * Horizontal period    THd - 480 - Clock
43  * Back porch           THb - 2 - Clock
44  * Front porch          THf - 2 - Clock
45  *
46  * -- Vertical synchronizing --
47  * Period               TV - 286 - Line
48  * Pulse width          TVp - 10 - Line
49  * Vertical period      TVd - 272 - Line
50  * Back porch           TVb - 2 - Line
51  * Front porch          TVf - 2 - Line
52  */
53
54 #define LCD_CLK                 (8*1000*1000)   /* 8MHz */
55
56 /* # active data to transfer after Horizontal Delay clock */
57 #define EPPI_HCOUNT             LCD_X_RES
58
59 /* # active lines to transfer after Vertical Delay clock */
60 #define EPPI_VCOUNT             LCD_Y_RES
61
62 /* Samples per Line = 480 (active data) + 45 (padding) */
63 #define EPPI_LINE               525
64
65 /* Lines per Frame = 272 (active data) + 14 (padding) */
66 #define EPPI_FRAME              286
67
68 /* FS1 (Hsync) Width (Typical)*/
69 #define EPPI_FS1W_HBL           41
70
71 /* FS1 (Hsync) Period (Typical) */
72 #define EPPI_FS1P_AVPL          EPPI_LINE
73
74 /* Horizontal Delay clock after assertion of Hsync (Typical) */
75 #define EPPI_HDELAY             43
76
77 /* FS2 (Vsync) Width    = FS1 (Hsync) Period * 10 */
78 #define EPPI_FS2W_LVB           (EPPI_LINE * 10)
79
80  /* FS2 (Vsync) Period   = FS1 (Hsync) Period * Lines per Frame */
81 #define EPPI_FS2P_LAVF          (EPPI_LINE * EPPI_FRAME)
82
83 /* Vertical Delay after assertion of Vsync (2 Lines) */
84 #define EPPI_VDELAY             12
85
86 #define EPPI_CLIP               0xFF00FF00
87
88 /* EPPI Control register configuration value for RGB out
89  * - EPPI as Output
90  * GP 2 frame sync mode,
91  * Internal Clock generation disabled, Internal FS generation enabled,
92  * Receives samples on EPPI_CLK raising edge, Transmits samples on EPPI_CLK falling edge,
93  * FS1 & FS2 are active high,
94  * DLEN = 6 (24 bits for RGB888 out) or 5 (18 bits for RGB666 out)
95  * DMA Unpacking disabled when RGB Formating is enabled, otherwise DMA unpacking enabled
96  * Swapping Enabled,
97  * One (DMA) Channel Mode,
98  * RGB Formatting Enabled for RGB666 output, disabled for RGB888 output
99  * Regular watermark - when FIFO is 100% full,
100  * Urgent watermark - when FIFO is 75% full
101  */
102
103 #define EPPI_CONTROL            (0x20136E2E)
104
105 static inline u16 get_eppi_clkdiv(u32 target_ppi_clk)
106 {
107         u32 sclk = get_sclk();
108
109         /* EPPI_CLK = (SCLK) / (2 * (EPPI_CLKDIV[15:0] + 1)) */
110
111         return (((sclk / target_ppi_clk) / 2) - 1);
112 }
113
114 void Init_PPI(void)
115 {
116         u16 eppi_clkdiv = get_eppi_clkdiv(LCD_CLK);
117
118         bfin_write_EPPI0_FS1W_HBL(EPPI_FS1W_HBL);
119         bfin_write_EPPI0_FS1P_AVPL(EPPI_FS1P_AVPL);
120         bfin_write_EPPI0_FS2W_LVB(EPPI_FS2W_LVB);
121         bfin_write_EPPI0_FS2P_LAVF(EPPI_FS2P_LAVF);
122         bfin_write_EPPI0_CLIP(EPPI_CLIP);
123
124         bfin_write_EPPI0_FRAME(EPPI_FRAME);
125         bfin_write_EPPI0_LINE(EPPI_LINE);
126
127         bfin_write_EPPI0_HCOUNT(EPPI_HCOUNT);
128         bfin_write_EPPI0_HDELAY(EPPI_HDELAY);
129         bfin_write_EPPI0_VCOUNT(EPPI_VCOUNT);
130         bfin_write_EPPI0_VDELAY(EPPI_VDELAY);
131
132         bfin_write_EPPI0_CLKDIV(eppi_clkdiv);
133
134 /*
135  * DLEN = 6 (24 bits for RGB888 out) or 5 (18 bits for RGB666 out)
136  * RGB Formatting Enabled for RGB666 output, disabled for RGB888 output
137  */
138 #if defined(CONFIG_VIDEO_RGB666)
139                 bfin_write_EPPI0_CONTROL((EPPI_CONTROL & ~DLENGTH) | DLEN_18 |
140                                          RGB_FMT_EN);
141 #else
142                 bfin_write_EPPI0_CONTROL(((EPPI_CONTROL & ~DLENGTH) | DLEN_24) &
143                                          ~RGB_FMT_EN);
144 #endif
145
146 }
147
148 #define               DEB2_URGENT  0x2000     /* DEB2 Urgent */
149
150 void Init_DMA(void *dst)
151 {
152
153 #if defined(CONFIG_DEB_DMA_URGENT)
154         *pEBIU_DDRQUE |= DEB2_URGENT;
155 #endif
156
157         *pDMA12_START_ADDR = dst;
158
159         /* X count */
160         *pDMA12_X_COUNT = (LCD_X_RES * LCD_BPP) / DMA_BUS_SIZE;
161         *pDMA12_X_MODIFY = DMA_BUS_SIZE / 8;
162
163         /* Y count */
164         *pDMA12_Y_COUNT = LCD_Y_RES;
165         *pDMA12_Y_MODIFY = DMA_BUS_SIZE / 8;
166
167         /* DMA Config */
168         *pDMA12_CONFIG =
169                 WDSIZE_32       |       /* 32 bit DMA */
170                 DMA2D           |       /* 2D DMA */
171                 FLOW_AUTO;              /* autobuffer mode */
172 }
173
174 void Init_Ports(void)
175 {
176         *pPORTF_MUX = 0x00000000;
177         *pPORTF_FER |= 0xFFFF; /* PPI0..15 */
178
179         *pPORTG_MUX &= ~(PORT_x_MUX_0_MASK | PORT_x_MUX_1_MASK | PORT_x_MUX_2_MASK | PORT_x_MUX_3_MASK | PORT_x_MUX_4_MASK);
180         *pPORTG_FER |= PG0 | PG1 | PG2 | PG3 | PG4; /* CLK, FS1, FS2, PPI16..17  */
181
182 #if !defined(CONFIG_VIDEO_RGB666)
183         *pPORTD_MUX &= ~(PORT_x_MUX_0_MASK | PORT_x_MUX_1_MASK | PORT_x_MUX_2_MASK | PORT_x_MUX_3_MASK | PORT_x_MUX_4_MASK | PORT_x_MUX_5_MASK);
184         *pPORTD_MUX |= (PORT_x_MUX_0_FUNC_4 | PORT_x_MUX_1_FUNC_4 | PORT_x_MUX_2_FUNC_4 | PORT_x_MUX_3_FUNC_4 | PORT_x_MUX_4_FUNC_4 | PORT_x_MUX_5_FUNC_4);
185         *pPORTD_FER |= PD0 | PD1 | PD2 | PD3 | PD4 | PD5; /* PPI18..23  */
186 #endif
187
188         *pPORTE_FER &= ~PE3; /* DISP */
189         *pPORTE_DIR_SET = PE3;
190         *pPORTE_SET  = PE3;
191
192 }
193
194 void EnableDMA(void)
195 {
196         *pDMA12_CONFIG |= DMAEN;
197 }
198
199 void DisableDMA(void)
200 {
201         *pDMA12_CONFIG &= ~DMAEN;
202 }
203
204 /* enable and disable PPI functions */
205 void EnablePPI(void)
206 {
207         bfin_write_EPPI0_CONTROL(bfin_read_EPPI0_CONTROL() | EPPI_EN);
208 }
209
210 void DisablePPI(void)
211 {
212         bfin_write_EPPI0_CONTROL(bfin_read_EPPI0_CONTROL() & ~EPPI_EN);
213 }
214
215 int video_init(void *dst)
216 {
217         Init_Ports();
218         Init_DMA(dst);
219         EnableDMA();
220         Init_PPI();
221         EnablePPI();
222
223         return 0;
224 }
225
226 static void dma_bitblit(void *dst, fastimage_t *logo, int x, int y)
227 {
228         if (dcache_status())
229                 blackfin_dcache_flush_range(logo->data, logo->data + logo->size);
230
231         bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
232
233         /* Setup destination start address */
234         bfin_write_MDMA_D0_START_ADDR(dst + ((x & -2) * LCD_PIXEL_SIZE)
235                                         + (y * LCD_X_RES * LCD_PIXEL_SIZE));
236         /* Setup destination xcount */
237         bfin_write_MDMA_D0_X_COUNT(logo->width * LCD_PIXEL_SIZE / DMA_SIZE16);
238         /* Setup destination xmodify */
239         bfin_write_MDMA_D0_X_MODIFY(DMA_SIZE16);
240
241         /* Setup destination ycount */
242         bfin_write_MDMA_D0_Y_COUNT(logo->height);
243         /* Setup destination ymodify */
244         bfin_write_MDMA_D0_Y_MODIFY((LCD_X_RES - logo->width) * LCD_PIXEL_SIZE + DMA_SIZE16);
245
246
247         /* Setup Source start address */
248         bfin_write_MDMA_S0_START_ADDR(logo->data);
249         /* Setup Source xcount */
250         bfin_write_MDMA_S0_X_COUNT(logo->width * LCD_PIXEL_SIZE / DMA_SIZE16);
251         /* Setup Source xmodify */
252         bfin_write_MDMA_S0_X_MODIFY(DMA_SIZE16);
253
254         /* Setup Source ycount */
255         bfin_write_MDMA_S0_Y_COUNT(logo->height);
256         /* Setup Source ymodify */
257         bfin_write_MDMA_S0_Y_MODIFY(DMA_SIZE16);
258
259
260         /* Enable source DMA */
261         bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_16 | DMA2D);
262         SSYNC();
263         bfin_write_MDMA_D0_CONFIG(WNR | DMAEN  | WDSIZE_16 | DMA2D);
264
265         while (bfin_read_MDMA_D0_IRQ_STATUS() & DMA_RUN);
266
267         bfin_write_MDMA_S0_IRQ_STATUS(bfin_read_MDMA_S0_IRQ_STATUS() | DMA_DONE | DMA_ERR);
268         bfin_write_MDMA_D0_IRQ_STATUS(bfin_read_MDMA_D0_IRQ_STATUS() | DMA_DONE | DMA_ERR);
269
270 }
271
272 void video_putc(const char c)
273 {
274 }
275
276 void video_puts(const char *s)
277 {
278 }
279
280 int drv_video_init(void)
281 {
282         int error, devices = 1;
283         struct stdio_dev videodev;
284
285         u8 *dst;
286         u32 fbmem_size = LCD_X_RES * LCD_Y_RES * LCD_PIXEL_SIZE + ACTIVE_VIDEO_MEM_OFFSET;
287
288         dst = malloc(fbmem_size);
289
290         if (dst == NULL) {
291                 printf("Failed to alloc FB memory\n");
292                 return -1;
293         }
294
295 #ifdef EASYLOGO_ENABLE_GZIP
296         unsigned char *data = EASYLOGO_DECOMP_BUFFER;
297         unsigned long src_len = EASYLOGO_ENABLE_GZIP;
298         if (gunzip(data, bfin_logo.size, bfin_logo.data, &src_len)) {
299                 puts("Failed to decompress logo\n");
300                 free(dst);
301                 return -1;
302         }
303         bfin_logo.data = data;
304 #endif
305
306         memset(dst + ACTIVE_VIDEO_MEM_OFFSET, bfin_logo.data[0], fbmem_size - ACTIVE_VIDEO_MEM_OFFSET);
307
308         dma_bitblit(dst + ACTIVE_VIDEO_MEM_OFFSET, &bfin_logo,
309                         (LCD_X_RES - bfin_logo.width) / 2,
310                         (LCD_Y_RES - bfin_logo.height) / 2);
311
312         video_init(dst);                /* Video initialization */
313
314         memset(&videodev, 0, sizeof(videodev));
315
316         strcpy(videodev.name, "video");
317         videodev.ext = DEV_EXT_VIDEO;   /* Video extensions */
318         videodev.flags = DEV_FLAGS_SYSTEM;      /* No Output */
319         videodev.putc = video_putc;     /* 'putc' function */
320         videodev.puts = video_puts;     /* 'puts' function */
321
322         error = stdio_register(&videodev);
323
324         return (error == 0) ? devices : error;
325 }