blob: 8f6ea2308f6bb49fb4cdbf0e5199367b2253a1b8 [file] [log] [blame]
Mike Frysingerd9a5d112008-10-12 20:59:12 -04001/*
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>
Michael Hennerich10eafa12009-12-10 09:19:21 +000015#include <spi.h>
Mike Frysingerd9a5d112008-10-12 20:59:12 -040016#include <linux/types.h>
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +020017#include <stdio_dev.h>
Mike Frysingerd9a5d112008-10-12 20:59:12 -040018
Mike Frysingerd9a5d112008-10-12 20:59:12 -040019#include <asm/mach-common/bits/ppi.h>
20#include <asm/mach-common/bits/timer.h>
21
Mike Frysingerd9a5d112008-10-12 20:59:12 -040022#define LCD_X_RES 320 /* Horizontal Resolution */
23#define LCD_Y_RES 240 /* Vertical Resolution */
Michael Hennerich10eafa12009-12-10 09:19:21 +000024#define DMA_BUS_SIZE 16
Mike Frysingerd9a5d112008-10-12 20:59:12 -040025
Michael Hennerich10eafa12009-12-10 09:19:21 +000026#ifdef CONFIG_MK_BF527_EZKIT_REV_2_1 /* lq035q1 */
Mike Frysingerd9a5d112008-10-12 20:59:12 -040027
Michael Hennerich10eafa12009-12-10 09:19:21 +000028#if !defined(CONFIG_LQ035Q1_USE_RGB888_8_BIT_PPI) && \
29 !defined(CONFIG_LQ035Q1_USE_RGB565_8_BIT_PPI)
30# define CONFIG_LQ035Q1_USE_RGB565_8_BIT_PPI
31#endif
32
33/* Interface 16/18-bit TFT over an 8-bit wide PPI using a
34 * small Programmable Logic Device (CPLD)
35 * http://blackfin.uclinux.org/gf/project/stamp/frs/?action=FrsReleaseBrowse&frs_package_id=165
36 */
37
38#ifdef CONFIG_LQ035Q1_USE_RGB565_8_BIT_PPI
39#include <asm/bfin_logo_rgb565_230x230.h>
40#define LCD_BPP 16 /* Bit Per Pixel */
41#define CLOCKS_PPIX 2 /* Clocks per pixel */
42#define CPLD_DELAY 3 /* RGB565 pipeline delay */
43#endif
44
45#ifdef CONFIG_LQ035Q1_USE_RGB888_8_BIT_PPI
46#include <asm/bfin_logo_230x230.h>
47#define LCD_BPP 24 /* Bit Per Pixel */
48#define CLOCKS_PPIX 3 /* Clocks per pixel */
49#define CPLD_DELAY 5 /* RGB888 pipeline delay */
50#endif
51
52/*
53 * HS and VS timing parameters (all in number of PPI clk ticks)
54 */
55
56#define H_ACTPIX (LCD_X_RES * CLOCKS_PPIX) /* active horizontal pixel */
57#define H_PERIOD (336 * CLOCKS_PPIX) /* HS period */
58#define H_PULSE (2 * CLOCKS_PPIX) /* HS pulse width */
59#define H_START (7 * CLOCKS_PPIX + CPLD_DELAY) /* first valid pixel */
60
61#define U_LINE 4 /* Blanking Lines */
62
63#define V_LINES (LCD_Y_RES + U_LINE) /* total vertical lines */
64#define V_PULSE (2 * CLOCKS_PPIX) /* VS pulse width (1-5 H_PERIODs) */
65#define V_PERIOD (H_PERIOD * V_LINES) /* VS period */
66
67#define ACTIVE_VIDEO_MEM_OFFSET ((U_LINE / 2) * LCD_X_RES * (LCD_BPP / 8))
68
69/*
70 * LCD Modes
71 */
72#define LQ035_RL (0 << 8) /* Right -> Left Scan */
73#define LQ035_LR (1 << 8) /* Left -> Right Scan */
74#define LQ035_TB (1 << 9) /* Top -> Botton Scan */
75#define LQ035_BT (0 << 9) /* Botton -> Top Scan */
76#define LQ035_BGR (1 << 11) /* Use BGR format */
77#define LQ035_RGB (0 << 11) /* Use RGB format */
78#define LQ035_NORM (1 << 13) /* Reversal */
79#define LQ035_REV (0 << 13) /* Reversal */
80
81#define LQ035_INDEX 0x74
82#define LQ035_DATA 0x76
83
84#define LQ035_DRIVER_OUTPUT_CTL 0x1
85#define LQ035_SHUT_CTL 0x11
86
87#define LQ035_DRIVER_OUTPUT_MASK (LQ035_LR | LQ035_TB | LQ035_BGR | LQ035_REV)
88#define LQ035_DRIVER_OUTPUT_DEFAULT (0x2AEF & ~LQ035_DRIVER_OUTPUT_MASK)
89
90#define LQ035_SHUT (1 << 0) /* Shutdown */
91#define LQ035_ON (0 << 0) /* Shutdown */
92
93#ifndef CONFIG_LQ035Q1_LCD_MODE
94#define CONFIG_LQ035Q1_LCD_MODE (LQ035_NORM | LQ035_RL | LQ035_TB | LQ035_BGR)
95#endif
96
97#else /* t350mcqb */
98#include <asm/bfin_logo_230x230.h>
99
100#define LCD_BPP 24 /* Bit Per Pixel */
101#define CLOCKS_PPIX 3 /* Clocks per pixel */
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400102
103/* HS and VS timing parameters (all in number of PPI clk ticks) */
Michael Hennerich10eafa12009-12-10 09:19:21 +0000104#define H_ACTPIX (LCD_X_RES * CLOCKS_PPIX) /* active horizontal pixel */
105#define H_PERIOD (408 * CLOCKS_PPIX) /* HS period */
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400106#define H_PULSE 90 /* HS pulse width */
107#define H_START 204 /* first valid pixel */
108
109#define U_LINE 1 /* Blanking Lines */
110
Michael Hennerich10eafa12009-12-10 09:19:21 +0000111#define V_LINES (LCD_Y_RES + U_LINE) /* total vertical lines */
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400112#define V_PULSE (3 * H_PERIOD) /* VS pulse width (1-5 H_PERIODs) */
113#define V_PERIOD (H_PERIOD * V_LINES) /* VS period */
114
115#define ACTIVE_VIDEO_MEM_OFFSET (U_LINE * H_ACTPIX)
Michael Hennerich10eafa12009-12-10 09:19:21 +0000116#endif
117
118#define LCD_PIXEL_SIZE (LCD_BPP / 8)
119#define DMA_SIZE16 2
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400120
121#define PPI_TX_MODE 0x2
122#define PPI_XFER_TYPE_11 0xC
123#define PPI_PORT_CFG_01 0x10
124#define PPI_PACK_EN 0x80
125#define PPI_POLS_1 0x8000
126
Michael Hennerich10eafa12009-12-10 09:19:21 +0000127#ifdef CONFIG_MK_BF527_EZKIT_REV_2_1
128static struct spi_slave *slave;
129static int lq035q1_control(unsigned char reg, unsigned short value)
130{
131 int ret;
132 u8 regs[3] = {LQ035_INDEX, 0, 0};
133 u8 data[3] = {LQ035_DATA, 0, 0};
134 u8 dummy[3];
135
136 regs[2] = reg;
137 data[1] = value >> 8;
138 data[2] = value & 0xFF;
139
140 if (!slave) {
141 /* FIXME: Verify the max SCK rate */
142 slave = spi_setup_slave(CONFIG_LQ035Q1_SPI_BUS,
143 CONFIG_LQ035Q1_SPI_CS, 20000000,
144 SPI_MODE_3);
145 if (!slave)
146 return -1;
147 }
148
149 if (spi_claim_bus(slave))
150 return -1;
151
152 ret = spi_xfer(slave, 24, regs, dummy, SPI_XFER_BEGIN | SPI_XFER_END);
153 ret |= spi_xfer(slave, 24, data, dummy, SPI_XFER_BEGIN | SPI_XFER_END);
154
155 spi_release_bus(slave);
156
157 return ret;
158}
159#endif
160
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400161/* enable and disable PPI functions */
162void EnablePPI(void)
163{
164 *pPPI_CONTROL |= PORT_EN;
165}
166
167void DisablePPI(void)
168{
169 *pPPI_CONTROL &= ~PORT_EN;
170}
171
172void Init_Ports(void)
173{
174 *pPORTF_MUX &= ~PORT_x_MUX_0_MASK;
175 *pPORTF_MUX |= PORT_x_MUX_0_FUNC_1;
176 *pPORTF_FER |= PF0 | PF1 | PF2 | PF3 | PF4 | PF5 | PF6 | PF7;
177
178 *pPORTG_MUX &= ~PORT_x_MUX_1_MASK;
179 *pPORTG_MUX |= PORT_x_MUX_1_FUNC_1;
180 *pPORTG_FER |= PG5;
181}
182
183void Init_PPI(void)
184{
185
186 *pPPI_DELAY = H_START;
187 *pPPI_COUNT = (H_ACTPIX-1);
Michael Hennerich10eafa12009-12-10 09:19:21 +0000188 *pPPI_FRAME = V_LINES;
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400189
190 /* PPI control, to be replaced with definitions */
191 *pPPI_CONTROL = PPI_TX_MODE | /* output mode , PORT_DIR */
192 PPI_XFER_TYPE_11 | /* sync mode XFR_TYPE */
193 PPI_PORT_CFG_01 | /* two frame sync PORT_CFG */
194 PPI_PACK_EN | /* packing enabled PACK_EN */
195 PPI_POLS_1; /* faling edge syncs POLS */
196}
197
198void Init_DMA(void *dst)
199{
200 *pDMA0_START_ADDR = dst;
201
202 /* X count */
203 *pDMA0_X_COUNT = H_ACTPIX / 2;
204 *pDMA0_X_MODIFY = DMA_BUS_SIZE / 8;
205
206 /* Y count */
207 *pDMA0_Y_COUNT = V_LINES;
208 *pDMA0_Y_MODIFY = DMA_BUS_SIZE / 8;
209
210 /* DMA Config */
211 *pDMA0_CONFIG =
212 WDSIZE_16 | /* 16 bit DMA */
213 DMA2D | /* 2D DMA */
214 FLOW_AUTO; /* autobuffer mode */
215}
216
217
218void EnableDMA(void)
219{
220 *pDMA0_CONFIG |= DMAEN;
221}
222
223void DisableDMA(void)
224{
225 *pDMA0_CONFIG &= ~DMAEN;
226}
227
228
229/* Init TIMER0 as Frame Sync 1 generator */
230void InitTIMER0(void)
231{
232 *pTIMER_DISABLE |= TIMDIS0; /* disable Timer */
233 SSYNC();
234 *pTIMER_STATUS |= TIMIL0 | TOVF_ERR0 | TRUN0; /* clear status */
235 SSYNC();
236
237 *pTIMER0_PERIOD = H_PERIOD;
238 SSYNC();
239 *pTIMER0_WIDTH = H_PULSE;
240 SSYNC();
241
242 *pTIMER0_CONFIG = PWM_OUT |
243 PERIOD_CNT |
244 TIN_SEL |
245 CLK_SEL |
246 EMU_RUN;
247 SSYNC();
248}
249
250void EnableTIMER0(void)
251{
252 *pTIMER_ENABLE |= TIMEN0;
253 SSYNC();
254}
255
256void DisableTIMER0(void)
257{
258 *pTIMER_DISABLE |= TIMDIS0;
259 SSYNC();
260}
261
262
263void InitTIMER1(void)
264{
265 *pTIMER_DISABLE |= TIMDIS1; /* disable Timer */
266 SSYNC();
267 *pTIMER_STATUS |= TIMIL1 | TOVF_ERR1 | TRUN1; /* clear status */
268 SSYNC();
269
270
271 *pTIMER1_PERIOD = V_PERIOD;
272 SSYNC();
273 *pTIMER1_WIDTH = V_PULSE;
274 SSYNC();
275
276 *pTIMER1_CONFIG = PWM_OUT |
277 PERIOD_CNT |
278 TIN_SEL |
279 CLK_SEL |
280 EMU_RUN;
281 SSYNC();
282}
283
284void EnableTIMER1(void)
285{
286 *pTIMER_ENABLE |= TIMEN1;
287 SSYNC();
288}
289
290void DisableTIMER1(void)
291{
292 *pTIMER_DISABLE |= TIMDIS1;
293 SSYNC();
294}
295
Michael Hennerich10eafa12009-12-10 09:19:21 +0000296void EnableTIMER12(void)
297{
298 *pTIMER_ENABLE |= TIMEN1 | TIMEN0;
299 SSYNC();
300}
301
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400302int video_init(void *dst)
303{
304
Michael Hennerich10eafa12009-12-10 09:19:21 +0000305#ifdef CONFIG_MK_BF527_EZKIT_REV_2_1
306 lq035q1_control(LQ035_SHUT_CTL, LQ035_ON);
307 lq035q1_control(LQ035_DRIVER_OUTPUT_CTL, (CONFIG_LQ035Q1_LCD_MODE &
308 LQ035_DRIVER_OUTPUT_MASK) | LQ035_DRIVER_OUTPUT_DEFAULT);
309#endif
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400310 Init_Ports();
311 Init_DMA(dst);
312 EnableDMA();
313 InitTIMER0();
314 InitTIMER1();
315 Init_PPI();
316 EnablePPI();
317
Michael Hennerich10eafa12009-12-10 09:19:21 +0000318#ifdef CONFIG_MK_BF527_EZKIT_REV_2_1
319 EnableTIMER12();
320#else
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400321 /* Frame sync 2 (VS) needs to start at least one PPI clk earlier */
322 EnableTIMER1();
323 /* Add Some Delay ... */
324 SSYNC();
325 SSYNC();
326 SSYNC();
327 SSYNC();
328
329 /* now start frame sync 1 */
330 EnableTIMER0();
Michael Hennerich10eafa12009-12-10 09:19:21 +0000331#endif
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400332
333 return 0;
334}
335
336static void dma_bitblit(void *dst, fastimage_t *logo, int x, int y)
337{
338 if (dcache_status())
339 blackfin_dcache_flush_range(logo->data, logo->data + logo->size);
340
341 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
342
343 /* Setup destination start address */
344 bfin_write_MDMA_D0_START_ADDR(dst + ((x & -2) * LCD_PIXEL_SIZE)
345 + (y * LCD_X_RES * LCD_PIXEL_SIZE));
346 /* Setup destination xcount */
347 bfin_write_MDMA_D0_X_COUNT(logo->width * LCD_PIXEL_SIZE / DMA_SIZE16);
348 /* Setup destination xmodify */
349 bfin_write_MDMA_D0_X_MODIFY(DMA_SIZE16);
350
351 /* Setup destination ycount */
352 bfin_write_MDMA_D0_Y_COUNT(logo->height);
353 /* Setup destination ymodify */
354 bfin_write_MDMA_D0_Y_MODIFY((LCD_X_RES - logo->width) * LCD_PIXEL_SIZE + DMA_SIZE16);
355
356
357 /* Setup Source start address */
358 bfin_write_MDMA_S0_START_ADDR(logo->data);
359 /* Setup Source xcount */
360 bfin_write_MDMA_S0_X_COUNT(logo->width * LCD_PIXEL_SIZE / DMA_SIZE16);
361 /* Setup Source xmodify */
362 bfin_write_MDMA_S0_X_MODIFY(DMA_SIZE16);
363
364 /* Setup Source ycount */
365 bfin_write_MDMA_S0_Y_COUNT(logo->height);
366 /* Setup Source ymodify */
367 bfin_write_MDMA_S0_Y_MODIFY(DMA_SIZE16);
368
369
370 /* Enable source DMA */
371 bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_16 | DMA2D);
372 SSYNC();
373 bfin_write_MDMA_D0_CONFIG(WNR | DMAEN | WDSIZE_16 | DMA2D);
374
375 while (bfin_read_MDMA_D0_IRQ_STATUS() & DMA_RUN);
376
377 bfin_write_MDMA_S0_IRQ_STATUS(bfin_read_MDMA_S0_IRQ_STATUS() | DMA_DONE | DMA_ERR);
378 bfin_write_MDMA_D0_IRQ_STATUS(bfin_read_MDMA_D0_IRQ_STATUS() | DMA_DONE | DMA_ERR);
379
380}
381
382void video_putc(const char c)
383{
384}
385
386void video_puts(const char *s)
387{
388}
389
390int drv_video_init(void)
391{
392 int error, devices = 1;
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200393 struct stdio_dev videodev;
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400394
395 u8 *dst;
396 u32 fbmem_size = LCD_X_RES * LCD_Y_RES * LCD_PIXEL_SIZE + ACTIVE_VIDEO_MEM_OFFSET;
397
398 dst = malloc(fbmem_size);
399
400 if (dst == NULL) {
401 printf("Failed to alloc FB memory\n");
402 return -1;
403 }
404
405#ifdef EASYLOGO_ENABLE_GZIP
406 unsigned char *data = EASYLOGO_DECOMP_BUFFER;
407 unsigned long src_len = EASYLOGO_ENABLE_GZIP;
408 if (gunzip(data, bfin_logo.size, bfin_logo.data, &src_len)) {
409 puts("Failed to decompress logo\n");
410 free(dst);
411 return -1;
412 }
413 bfin_logo.data = data;
414#endif
415
416 memset(dst + ACTIVE_VIDEO_MEM_OFFSET, bfin_logo.data[0], fbmem_size - ACTIVE_VIDEO_MEM_OFFSET);
417
418 dma_bitblit(dst + ACTIVE_VIDEO_MEM_OFFSET, &bfin_logo,
419 (LCD_X_RES - bfin_logo.width) / 2,
420 (LCD_Y_RES - bfin_logo.height) / 2);
421
422 video_init(dst); /* Video initialization */
423
424 memset(&videodev, 0, sizeof(videodev));
425
426 strcpy(videodev.name, "video");
427 videodev.ext = DEV_EXT_VIDEO; /* Video extensions */
428 videodev.flags = DEV_FLAGS_SYSTEM; /* No Output */
429 videodev.putc = video_putc; /* 'putc' function */
430 videodev.puts = video_puts; /* 'puts' function */
431
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200432 error = stdio_register(&videodev);
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400433
434 return (error == 0) ? devices : error;
435}