blob: 87e7658b4df7a2ba460aac6fb83426b5d127fc1f [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>
Mike Frysinger22e64402010-06-02 19:30:01 -040014#include <asm/portmux.h>
Mike Frysingerd9a5d112008-10-12 20:59:12 -040015#include <asm/mach-common/bits/dma.h>
Michael Hennerich10eafa12009-12-10 09:19:21 +000016#include <spi.h>
Mike Frysingerd9a5d112008-10-12 20:59:12 -040017#include <linux/types.h>
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +020018#include <stdio_dev.h>
Mike Frysingerd9a5d112008-10-12 20:59:12 -040019
Mike Frysingerd9a5d112008-10-12 20:59:12 -040020#include <asm/mach-common/bits/ppi.h>
21#include <asm/mach-common/bits/timer.h>
22
Mike Frysingerd9a5d112008-10-12 20:59:12 -040023#define LCD_X_RES 320 /* Horizontal Resolution */
24#define LCD_Y_RES 240 /* Vertical Resolution */
Michael Hennerich10eafa12009-12-10 09:19:21 +000025#define DMA_BUS_SIZE 16
Mike Frysingerd9a5d112008-10-12 20:59:12 -040026
Michael Hennerich10eafa12009-12-10 09:19:21 +000027#ifdef CONFIG_MK_BF527_EZKIT_REV_2_1 /* lq035q1 */
Mike Frysingerd9a5d112008-10-12 20:59:12 -040028
Michael Hennerich10eafa12009-12-10 09:19:21 +000029#if !defined(CONFIG_LQ035Q1_USE_RGB888_8_BIT_PPI) && \
30 !defined(CONFIG_LQ035Q1_USE_RGB565_8_BIT_PPI)
31# define CONFIG_LQ035Q1_USE_RGB565_8_BIT_PPI
32#endif
33
34/* Interface 16/18-bit TFT over an 8-bit wide PPI using a
35 * small Programmable Logic Device (CPLD)
36 * http://blackfin.uclinux.org/gf/project/stamp/frs/?action=FrsReleaseBrowse&frs_package_id=165
37 */
38
39#ifdef CONFIG_LQ035Q1_USE_RGB565_8_BIT_PPI
40#include <asm/bfin_logo_rgb565_230x230.h>
41#define LCD_BPP 16 /* Bit Per Pixel */
42#define CLOCKS_PPIX 2 /* Clocks per pixel */
43#define CPLD_DELAY 3 /* RGB565 pipeline delay */
44#endif
45
46#ifdef CONFIG_LQ035Q1_USE_RGB888_8_BIT_PPI
47#include <asm/bfin_logo_230x230.h>
48#define LCD_BPP 24 /* Bit Per Pixel */
49#define CLOCKS_PPIX 3 /* Clocks per pixel */
50#define CPLD_DELAY 5 /* RGB888 pipeline delay */
51#endif
52
53/*
54 * HS and VS timing parameters (all in number of PPI clk ticks)
55 */
56
57#define H_ACTPIX (LCD_X_RES * CLOCKS_PPIX) /* active horizontal pixel */
58#define H_PERIOD (336 * CLOCKS_PPIX) /* HS period */
59#define H_PULSE (2 * CLOCKS_PPIX) /* HS pulse width */
60#define H_START (7 * CLOCKS_PPIX + CPLD_DELAY) /* first valid pixel */
61
62#define U_LINE 4 /* Blanking Lines */
63
64#define V_LINES (LCD_Y_RES + U_LINE) /* total vertical lines */
65#define V_PULSE (2 * CLOCKS_PPIX) /* VS pulse width (1-5 H_PERIODs) */
66#define V_PERIOD (H_PERIOD * V_LINES) /* VS period */
67
68#define ACTIVE_VIDEO_MEM_OFFSET ((U_LINE / 2) * LCD_X_RES * (LCD_BPP / 8))
69
70/*
71 * LCD Modes
72 */
73#define LQ035_RL (0 << 8) /* Right -> Left Scan */
74#define LQ035_LR (1 << 8) /* Left -> Right Scan */
75#define LQ035_TB (1 << 9) /* Top -> Botton Scan */
76#define LQ035_BT (0 << 9) /* Botton -> Top Scan */
77#define LQ035_BGR (1 << 11) /* Use BGR format */
78#define LQ035_RGB (0 << 11) /* Use RGB format */
79#define LQ035_NORM (1 << 13) /* Reversal */
80#define LQ035_REV (0 << 13) /* Reversal */
81
82#define LQ035_INDEX 0x74
83#define LQ035_DATA 0x76
84
85#define LQ035_DRIVER_OUTPUT_CTL 0x1
86#define LQ035_SHUT_CTL 0x11
87
88#define LQ035_DRIVER_OUTPUT_MASK (LQ035_LR | LQ035_TB | LQ035_BGR | LQ035_REV)
89#define LQ035_DRIVER_OUTPUT_DEFAULT (0x2AEF & ~LQ035_DRIVER_OUTPUT_MASK)
90
91#define LQ035_SHUT (1 << 0) /* Shutdown */
92#define LQ035_ON (0 << 0) /* Shutdown */
93
94#ifndef CONFIG_LQ035Q1_LCD_MODE
95#define CONFIG_LQ035Q1_LCD_MODE (LQ035_NORM | LQ035_RL | LQ035_TB | LQ035_BGR)
96#endif
97
98#else /* t350mcqb */
99#include <asm/bfin_logo_230x230.h>
100
101#define LCD_BPP 24 /* Bit Per Pixel */
102#define CLOCKS_PPIX 3 /* Clocks per pixel */
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400103
104/* HS and VS timing parameters (all in number of PPI clk ticks) */
Michael Hennerich10eafa12009-12-10 09:19:21 +0000105#define H_ACTPIX (LCD_X_RES * CLOCKS_PPIX) /* active horizontal pixel */
106#define H_PERIOD (408 * CLOCKS_PPIX) /* HS period */
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400107#define H_PULSE 90 /* HS pulse width */
108#define H_START 204 /* first valid pixel */
109
110#define U_LINE 1 /* Blanking Lines */
111
Michael Hennerich10eafa12009-12-10 09:19:21 +0000112#define V_LINES (LCD_Y_RES + U_LINE) /* total vertical lines */
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400113#define V_PULSE (3 * H_PERIOD) /* VS pulse width (1-5 H_PERIODs) */
114#define V_PERIOD (H_PERIOD * V_LINES) /* VS period */
115
116#define ACTIVE_VIDEO_MEM_OFFSET (U_LINE * H_ACTPIX)
Michael Hennerich10eafa12009-12-10 09:19:21 +0000117#endif
118
119#define LCD_PIXEL_SIZE (LCD_BPP / 8)
120#define DMA_SIZE16 2
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400121
122#define PPI_TX_MODE 0x2
123#define PPI_XFER_TYPE_11 0xC
124#define PPI_PORT_CFG_01 0x10
125#define PPI_PACK_EN 0x80
126#define PPI_POLS_1 0x8000
127
Michael Hennerich10eafa12009-12-10 09:19:21 +0000128#ifdef CONFIG_MK_BF527_EZKIT_REV_2_1
129static struct spi_slave *slave;
130static int lq035q1_control(unsigned char reg, unsigned short value)
131{
132 int ret;
133 u8 regs[3] = {LQ035_INDEX, 0, 0};
134 u8 data[3] = {LQ035_DATA, 0, 0};
135 u8 dummy[3];
136
137 regs[2] = reg;
138 data[1] = value >> 8;
139 data[2] = value & 0xFF;
140
141 if (!slave) {
142 /* FIXME: Verify the max SCK rate */
143 slave = spi_setup_slave(CONFIG_LQ035Q1_SPI_BUS,
144 CONFIG_LQ035Q1_SPI_CS, 20000000,
145 SPI_MODE_3);
146 if (!slave)
147 return -1;
148 }
149
150 if (spi_claim_bus(slave))
151 return -1;
152
153 ret = spi_xfer(slave, 24, regs, dummy, SPI_XFER_BEGIN | SPI_XFER_END);
154 ret |= spi_xfer(slave, 24, data, dummy, SPI_XFER_BEGIN | SPI_XFER_END);
155
156 spi_release_bus(slave);
157
158 return ret;
159}
160#endif
161
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400162/* enable and disable PPI functions */
163void EnablePPI(void)
164{
Mike Frysinger989ab872010-07-25 17:18:42 -0400165 bfin_write_PPI_CONTROL(bfin_read_PPI_CONTROL() | PORT_EN);
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400166}
167
168void DisablePPI(void)
169{
Mike Frysinger989ab872010-07-25 17:18:42 -0400170 bfin_write_PPI_CONTROL(bfin_read_PPI_CONTROL() & ~PORT_EN);
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400171}
172
173void Init_Ports(void)
174{
Mike Frysinger22e64402010-06-02 19:30:01 -0400175 const unsigned short pins[] = {
176 P_PPI0_D0, P_PPI0_D1, P_PPI0_D2, P_PPI0_D3, P_PPI0_D4,
177 P_PPI0_D5, P_PPI0_D6, P_PPI0_D7, P_PPI0_FS2, 0,
178 };
179 peripheral_request_list(pins, "lcd");
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400180}
181
182void Init_PPI(void)
183{
184
Mike Frysinger989ab872010-07-25 17:18:42 -0400185 bfin_write_PPI_DELAY(H_START);
186 bfin_write_PPI_COUNT(H_ACTPIX - 1);
187 bfin_write_PPI_FRAME(V_LINES);
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400188
189 /* PPI control, to be replaced with definitions */
Mike Frysinger989ab872010-07-25 17:18:42 -0400190 bfin_write_PPI_CONTROL(
191 PPI_TX_MODE | /* output mode , PORT_DIR */
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400192 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 */
Mike Frysinger989ab872010-07-25 17:18:42 -0400195 PPI_POLS_1 /* faling edge syncs POLS */
196 );
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400197}
198
199void Init_DMA(void *dst)
200{
Mike Frysinger989ab872010-07-25 17:18:42 -0400201 bfin_write_DMA0_START_ADDR(dst);
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400202
203 /* X count */
Mike Frysinger989ab872010-07-25 17:18:42 -0400204 bfin_write_DMA0_X_COUNT(H_ACTPIX / 2);
205 bfin_write_DMA0_X_MODIFY(DMA_BUS_SIZE / 8);
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400206
207 /* Y count */
Mike Frysinger989ab872010-07-25 17:18:42 -0400208 bfin_write_DMA0_Y_COUNT(V_LINES);
209 bfin_write_DMA0_Y_MODIFY(DMA_BUS_SIZE / 8);
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400210
211 /* DMA Config */
Mike Frysinger989ab872010-07-25 17:18:42 -0400212 bfin_write_DMA0_CONFIG(
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400213 WDSIZE_16 | /* 16 bit DMA */
214 DMA2D | /* 2D DMA */
Mike Frysinger989ab872010-07-25 17:18:42 -0400215 FLOW_AUTO /* autobuffer mode */
216 );
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400217}
218
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400219void EnableDMA(void)
220{
Mike Frysinger989ab872010-07-25 17:18:42 -0400221 bfin_write_DMA0_CONFIG(bfin_read_DMA0_CONFIG() | DMAEN);
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400222}
223
224void DisableDMA(void)
225{
Mike Frysinger989ab872010-07-25 17:18:42 -0400226 bfin_write_DMA0_CONFIG(bfin_read_DMA0_CONFIG() & ~DMAEN);
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400227}
228
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400229/* Init TIMER0 as Frame Sync 1 generator */
230void InitTIMER0(void)
231{
Mike Frysinger989ab872010-07-25 17:18:42 -0400232 bfin_write_TIMER_DISABLE(TIMDIS0); /* disable Timer */
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400233 SSYNC();
Mike Frysinger989ab872010-07-25 17:18:42 -0400234 bfin_write_TIMER_STATUS(TIMIL0 | TOVF_ERR0 | TRUN0); /* clear status */
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400235 SSYNC();
236
Mike Frysinger989ab872010-07-25 17:18:42 -0400237 bfin_write_TIMER0_PERIOD(H_PERIOD);
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400238 SSYNC();
Mike Frysinger989ab872010-07-25 17:18:42 -0400239 bfin_write_TIMER0_WIDTH(H_PULSE);
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400240 SSYNC();
241
Mike Frysinger989ab872010-07-25 17:18:42 -0400242 bfin_write_TIMER0_CONFIG(
243 PWM_OUT |
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400244 PERIOD_CNT |
245 TIN_SEL |
246 CLK_SEL |
Mike Frysinger989ab872010-07-25 17:18:42 -0400247 EMU_RUN
248 );
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400249 SSYNC();
250}
251
252void EnableTIMER0(void)
253{
Mike Frysinger989ab872010-07-25 17:18:42 -0400254 bfin_write_TIMER_ENABLE(TIMEN0);
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400255 SSYNC();
256}
257
258void DisableTIMER0(void)
259{
Mike Frysinger989ab872010-07-25 17:18:42 -0400260 bfin_write_TIMER_DISABLE(TIMDIS0);
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400261 SSYNC();
262}
263
264
265void InitTIMER1(void)
266{
Mike Frysinger989ab872010-07-25 17:18:42 -0400267 bfin_write_TIMER_DISABLE(TIMDIS1); /* disable Timer */
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400268 SSYNC();
Mike Frysinger989ab872010-07-25 17:18:42 -0400269 bfin_write_TIMER_STATUS(TIMIL1 | TOVF_ERR1 | TRUN1); /* clear status */
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400270 SSYNC();
271
Mike Frysinger989ab872010-07-25 17:18:42 -0400272 bfin_write_TIMER1_PERIOD(V_PERIOD);
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400273 SSYNC();
Mike Frysinger989ab872010-07-25 17:18:42 -0400274 bfin_write_TIMER1_WIDTH(V_PULSE);
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400275 SSYNC();
276
Mike Frysinger989ab872010-07-25 17:18:42 -0400277 bfin_write_TIMER1_CONFIG(
278 PWM_OUT |
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400279 PERIOD_CNT |
280 TIN_SEL |
281 CLK_SEL |
Mike Frysinger989ab872010-07-25 17:18:42 -0400282 EMU_RUN
283 );
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400284 SSYNC();
285}
286
287void EnableTIMER1(void)
288{
Mike Frysinger989ab872010-07-25 17:18:42 -0400289 bfin_write_TIMER_ENABLE(TIMEN1);
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400290 SSYNC();
291}
292
293void DisableTIMER1(void)
294{
Mike Frysinger989ab872010-07-25 17:18:42 -0400295 bfin_write_TIMER_DISABLE(TIMDIS1);
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400296 SSYNC();
297}
298
Michael Hennerich10eafa12009-12-10 09:19:21 +0000299void EnableTIMER12(void)
300{
Mike Frysinger989ab872010-07-25 17:18:42 -0400301 bfin_write_TIMER_ENABLE(TIMEN1 | TIMEN0);
Michael Hennerich10eafa12009-12-10 09:19:21 +0000302 SSYNC();
303}
304
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400305int video_init(void *dst)
306{
307
Michael Hennerich10eafa12009-12-10 09:19:21 +0000308#ifdef CONFIG_MK_BF527_EZKIT_REV_2_1
309 lq035q1_control(LQ035_SHUT_CTL, LQ035_ON);
310 lq035q1_control(LQ035_DRIVER_OUTPUT_CTL, (CONFIG_LQ035Q1_LCD_MODE &
311 LQ035_DRIVER_OUTPUT_MASK) | LQ035_DRIVER_OUTPUT_DEFAULT);
312#endif
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400313 Init_Ports();
314 Init_DMA(dst);
315 EnableDMA();
316 InitTIMER0();
317 InitTIMER1();
318 Init_PPI();
319 EnablePPI();
320
Michael Hennerich10eafa12009-12-10 09:19:21 +0000321#ifdef CONFIG_MK_BF527_EZKIT_REV_2_1
322 EnableTIMER12();
323#else
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400324 /* Frame sync 2 (VS) needs to start at least one PPI clk earlier */
325 EnableTIMER1();
326 /* Add Some Delay ... */
327 SSYNC();
328 SSYNC();
329 SSYNC();
330 SSYNC();
331
332 /* now start frame sync 1 */
333 EnableTIMER0();
Michael Hennerich10eafa12009-12-10 09:19:21 +0000334#endif
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400335
336 return 0;
337}
338
339static void dma_bitblit(void *dst, fastimage_t *logo, int x, int y)
340{
341 if (dcache_status())
342 blackfin_dcache_flush_range(logo->data, logo->data + logo->size);
343
344 bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
345
346 /* Setup destination start address */
347 bfin_write_MDMA_D0_START_ADDR(dst + ((x & -2) * LCD_PIXEL_SIZE)
348 + (y * LCD_X_RES * LCD_PIXEL_SIZE));
349 /* Setup destination xcount */
350 bfin_write_MDMA_D0_X_COUNT(logo->width * LCD_PIXEL_SIZE / DMA_SIZE16);
351 /* Setup destination xmodify */
352 bfin_write_MDMA_D0_X_MODIFY(DMA_SIZE16);
353
354 /* Setup destination ycount */
355 bfin_write_MDMA_D0_Y_COUNT(logo->height);
356 /* Setup destination ymodify */
357 bfin_write_MDMA_D0_Y_MODIFY((LCD_X_RES - logo->width) * LCD_PIXEL_SIZE + DMA_SIZE16);
358
359
360 /* Setup Source start address */
361 bfin_write_MDMA_S0_START_ADDR(logo->data);
362 /* Setup Source xcount */
363 bfin_write_MDMA_S0_X_COUNT(logo->width * LCD_PIXEL_SIZE / DMA_SIZE16);
364 /* Setup Source xmodify */
365 bfin_write_MDMA_S0_X_MODIFY(DMA_SIZE16);
366
367 /* Setup Source ycount */
368 bfin_write_MDMA_S0_Y_COUNT(logo->height);
369 /* Setup Source ymodify */
370 bfin_write_MDMA_S0_Y_MODIFY(DMA_SIZE16);
371
372
373 /* Enable source DMA */
374 bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_16 | DMA2D);
375 SSYNC();
376 bfin_write_MDMA_D0_CONFIG(WNR | DMAEN | WDSIZE_16 | DMA2D);
377
378 while (bfin_read_MDMA_D0_IRQ_STATUS() & DMA_RUN);
379
380 bfin_write_MDMA_S0_IRQ_STATUS(bfin_read_MDMA_S0_IRQ_STATUS() | DMA_DONE | DMA_ERR);
381 bfin_write_MDMA_D0_IRQ_STATUS(bfin_read_MDMA_D0_IRQ_STATUS() | DMA_DONE | DMA_ERR);
382
383}
384
Michael Hennerich5fc564e2009-08-07 02:47:54 +0000385void video_stop(void)
386{
387 DisablePPI();
388 DisableDMA();
389 DisableTIMER0();
390 DisableTIMER1();
391#ifdef CONFIG_MK_BF527_EZKIT_REV_2_1
392 lq035q1_control(LQ035_SHUT_CTL, LQ035_SHUT);
393#endif
394}
395
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400396void video_putc(const char c)
397{
398}
399
400void video_puts(const char *s)
401{
402}
403
404int drv_video_init(void)
405{
406 int error, devices = 1;
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200407 struct stdio_dev videodev;
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400408
409 u8 *dst;
410 u32 fbmem_size = LCD_X_RES * LCD_Y_RES * LCD_PIXEL_SIZE + ACTIVE_VIDEO_MEM_OFFSET;
411
412 dst = malloc(fbmem_size);
413
414 if (dst == NULL) {
415 printf("Failed to alloc FB memory\n");
416 return -1;
417 }
418
419#ifdef EASYLOGO_ENABLE_GZIP
420 unsigned char *data = EASYLOGO_DECOMP_BUFFER;
421 unsigned long src_len = EASYLOGO_ENABLE_GZIP;
422 if (gunzip(data, bfin_logo.size, bfin_logo.data, &src_len)) {
423 puts("Failed to decompress logo\n");
424 free(dst);
425 return -1;
426 }
427 bfin_logo.data = data;
428#endif
429
430 memset(dst + ACTIVE_VIDEO_MEM_OFFSET, bfin_logo.data[0], fbmem_size - ACTIVE_VIDEO_MEM_OFFSET);
431
432 dma_bitblit(dst + ACTIVE_VIDEO_MEM_OFFSET, &bfin_logo,
433 (LCD_X_RES - bfin_logo.width) / 2,
434 (LCD_Y_RES - bfin_logo.height) / 2);
435
436 video_init(dst); /* Video initialization */
437
438 memset(&videodev, 0, sizeof(videodev));
439
440 strcpy(videodev.name, "video");
441 videodev.ext = DEV_EXT_VIDEO; /* Video extensions */
442 videodev.flags = DEV_FLAGS_SYSTEM; /* No Output */
443 videodev.putc = video_putc; /* 'putc' function */
444 videodev.puts = video_puts; /* 'puts' function */
445
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200446 error = stdio_register(&videodev);
Mike Frysingerd9a5d112008-10-12 20:59:12 -0400447
448 return (error == 0) ? devices : error;
449}