]>
git.ipfire.org Git - people/ms/u-boot.git/blob - board/bf527-ezkit/video.c
2 * video.c - run splash screen on lcd
4 * Copyright (c) 2007-2008 Analog Devices Inc.
6 * Licensed under the GPL-2 or later.
13 #include <asm/blackfin.h>
14 #include <asm/mach-common/bits/dma.h>
16 #include <linux/types.h>
17 #include <stdio_dev.h>
19 int gunzip(void *, int, unsigned char *, unsigned long *);
23 #include <asm/mach-common/bits/ppi.h>
24 #include <asm/mach-common/bits/timer.h>
26 #include <asm/bfin_logo_230x230.h>
28 #define LCD_X_RES 320 /* Horizontal Resolution */
29 #define LCD_Y_RES 240 /* Vertical Resolution */
30 #define LCD_BPP 24 /* Bit Per Pixel */
31 #define LCD_PIXEL_SIZE (LCD_BPP / 8)
33 #define DMA_BUS_SIZE 16
34 #define LCD_CLK (12*1000*1000) /* 12MHz */
36 #define CLOCKS_PER_PIX 3
38 /* HS and VS timing parameters (all in number of PPI clk ticks) */
39 #define H_ACTPIX (LCD_X_RES * CLOCKS_PER_PIX) /* active horizontal pixel */
40 #define H_PERIOD (408 * CLOCKS_PER_PIX) /* HS period */
41 #define H_PULSE 90 /* HS pulse width */
42 #define H_START 204 /* first valid pixel */
44 #define U_LINE 1 /* Blanking Lines */
46 #define V_LINES (LCD_Y_RES + U_LINE) /* total vertical lines */
47 #define V_PULSE (3 * H_PERIOD) /* VS pulse width (1-5 H_PERIODs) */
48 #define V_PERIOD (H_PERIOD * V_LINES) /* VS period */
50 #define ACTIVE_VIDEO_MEM_OFFSET (U_LINE * H_ACTPIX)
52 #define PPI_TX_MODE 0x2
53 #define PPI_XFER_TYPE_11 0xC
54 #define PPI_PORT_CFG_01 0x10
55 #define PPI_PACK_EN 0x80
56 #define PPI_POLS_1 0x8000
58 /* enable and disable PPI functions */
61 *pPPI_CONTROL
|= PORT_EN
;
66 *pPPI_CONTROL
&= ~PORT_EN
;
71 *pPORTF_MUX
&= ~PORT_x_MUX_0_MASK
;
72 *pPORTF_MUX
|= PORT_x_MUX_0_FUNC_1
;
73 *pPORTF_FER
|= PF0
| PF1
| PF2
| PF3
| PF4
| PF5
| PF6
| PF7
;
75 *pPORTG_MUX
&= ~PORT_x_MUX_1_MASK
;
76 *pPORTG_MUX
|= PORT_x_MUX_1_FUNC_1
;
83 *pPPI_DELAY
= H_START
;
84 *pPPI_COUNT
= (H_ACTPIX
-1);
87 /* PPI control, to be replaced with definitions */
88 *pPPI_CONTROL
= PPI_TX_MODE
| /* output mode , PORT_DIR */
89 PPI_XFER_TYPE_11
| /* sync mode XFR_TYPE */
90 PPI_PORT_CFG_01
| /* two frame sync PORT_CFG */
91 PPI_PACK_EN
| /* packing enabled PACK_EN */
92 PPI_POLS_1
; /* faling edge syncs POLS */
95 void Init_DMA(void *dst
)
97 *pDMA0_START_ADDR
= dst
;
100 *pDMA0_X_COUNT
= H_ACTPIX
/ 2;
101 *pDMA0_X_MODIFY
= DMA_BUS_SIZE
/ 8;
104 *pDMA0_Y_COUNT
= V_LINES
;
105 *pDMA0_Y_MODIFY
= DMA_BUS_SIZE
/ 8;
109 WDSIZE_16
| /* 16 bit DMA */
111 FLOW_AUTO
; /* autobuffer mode */
117 *pDMA0_CONFIG
|= DMAEN
;
120 void DisableDMA(void)
122 *pDMA0_CONFIG
&= ~DMAEN
;
126 /* Init TIMER0 as Frame Sync 1 generator */
127 void InitTIMER0(void)
129 *pTIMER_DISABLE
|= TIMDIS0
; /* disable Timer */
131 *pTIMER_STATUS
|= TIMIL0
| TOVF_ERR0
| TRUN0
; /* clear status */
134 *pTIMER0_PERIOD
= H_PERIOD
;
136 *pTIMER0_WIDTH
= H_PULSE
;
139 *pTIMER0_CONFIG
= PWM_OUT
|
147 void EnableTIMER0(void)
149 *pTIMER_ENABLE
|= TIMEN0
;
153 void DisableTIMER0(void)
155 *pTIMER_DISABLE
|= TIMDIS0
;
160 void InitTIMER1(void)
162 *pTIMER_DISABLE
|= TIMDIS1
; /* disable Timer */
164 *pTIMER_STATUS
|= TIMIL1
| TOVF_ERR1
| TRUN1
; /* clear status */
168 *pTIMER1_PERIOD
= V_PERIOD
;
170 *pTIMER1_WIDTH
= V_PULSE
;
173 *pTIMER1_CONFIG
= PWM_OUT
|
181 void EnableTIMER1(void)
183 *pTIMER_ENABLE
|= TIMEN1
;
187 void DisableTIMER1(void)
189 *pTIMER_DISABLE
|= TIMDIS1
;
193 int video_init(void *dst
)
204 /* Frame sync 2 (VS) needs to start at least one PPI clk earlier */
206 /* Add Some Delay ... */
212 /* now start frame sync 1 */
218 static void dma_bitblit(void *dst
, fastimage_t
*logo
, int x
, int y
)
221 blackfin_dcache_flush_range(logo
->data
, logo
->data
+ logo
->size
);
223 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE
| DMA_ERR
);
225 /* Setup destination start address */
226 bfin_write_MDMA_D0_START_ADDR(dst
+ ((x
& -2) * LCD_PIXEL_SIZE
)
227 + (y
* LCD_X_RES
* LCD_PIXEL_SIZE
));
228 /* Setup destination xcount */
229 bfin_write_MDMA_D0_X_COUNT(logo
->width
* LCD_PIXEL_SIZE
/ DMA_SIZE16
);
230 /* Setup destination xmodify */
231 bfin_write_MDMA_D0_X_MODIFY(DMA_SIZE16
);
233 /* Setup destination ycount */
234 bfin_write_MDMA_D0_Y_COUNT(logo
->height
);
235 /* Setup destination ymodify */
236 bfin_write_MDMA_D0_Y_MODIFY((LCD_X_RES
- logo
->width
) * LCD_PIXEL_SIZE
+ DMA_SIZE16
);
239 /* Setup Source start address */
240 bfin_write_MDMA_S0_START_ADDR(logo
->data
);
241 /* Setup Source xcount */
242 bfin_write_MDMA_S0_X_COUNT(logo
->width
* LCD_PIXEL_SIZE
/ DMA_SIZE16
);
243 /* Setup Source xmodify */
244 bfin_write_MDMA_S0_X_MODIFY(DMA_SIZE16
);
246 /* Setup Source ycount */
247 bfin_write_MDMA_S0_Y_COUNT(logo
->height
);
248 /* Setup Source ymodify */
249 bfin_write_MDMA_S0_Y_MODIFY(DMA_SIZE16
);
252 /* Enable source DMA */
253 bfin_write_MDMA_S0_CONFIG(DMAEN
| WDSIZE_16
| DMA2D
);
255 bfin_write_MDMA_D0_CONFIG(WNR
| DMAEN
| WDSIZE_16
| DMA2D
);
257 while (bfin_read_MDMA_D0_IRQ_STATUS() & DMA_RUN
);
259 bfin_write_MDMA_S0_IRQ_STATUS(bfin_read_MDMA_S0_IRQ_STATUS() | DMA_DONE
| DMA_ERR
);
260 bfin_write_MDMA_D0_IRQ_STATUS(bfin_read_MDMA_D0_IRQ_STATUS() | DMA_DONE
| DMA_ERR
);
264 void video_putc(const char c
)
268 void video_puts(const char *s
)
272 int drv_video_init(void)
274 int error
, devices
= 1;
275 struct stdio_dev videodev
;
278 u32 fbmem_size
= LCD_X_RES
* LCD_Y_RES
* LCD_PIXEL_SIZE
+ ACTIVE_VIDEO_MEM_OFFSET
;
280 dst
= malloc(fbmem_size
);
283 printf("Failed to alloc FB memory\n");
287 #ifdef EASYLOGO_ENABLE_GZIP
288 unsigned char *data
= EASYLOGO_DECOMP_BUFFER
;
289 unsigned long src_len
= EASYLOGO_ENABLE_GZIP
;
290 if (gunzip(data
, bfin_logo
.size
, bfin_logo
.data
, &src_len
)) {
291 puts("Failed to decompress logo\n");
295 bfin_logo
.data
= data
;
298 memset(dst
+ ACTIVE_VIDEO_MEM_OFFSET
, bfin_logo
.data
[0], fbmem_size
- ACTIVE_VIDEO_MEM_OFFSET
);
300 dma_bitblit(dst
+ ACTIVE_VIDEO_MEM_OFFSET
, &bfin_logo
,
301 (LCD_X_RES
- bfin_logo
.width
) / 2,
302 (LCD_Y_RES
- bfin_logo
.height
) / 2);
304 video_init(dst
); /* Video initialization */
306 memset(&videodev
, 0, sizeof(videodev
));
308 strcpy(videodev
.name
, "video");
309 videodev
.ext
= DEV_EXT_VIDEO
; /* Video extensions */
310 videodev
.flags
= DEV_FLAGS_SYSTEM
; /* No Output */
311 videodev
.putc
= video_putc
; /* 'putc' function */
312 videodev
.puts
= video_puts
; /* 'puts' function */
314 error
= stdio_register(&videodev
);
316 return (error
== 0) ? devices
: error
;