Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 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> |
Mike Frysinger | 22e6440 | 2010-06-02 19:30:01 -0400 | [diff] [blame] | 14 | #include <asm/portmux.h> |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 15 | #include <asm/mach-common/bits/dma.h> |
Michael Hennerich | 10eafa1 | 2009-12-10 09:19:21 +0000 | [diff] [blame] | 16 | #include <spi.h> |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 17 | #include <linux/types.h> |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 18 | #include <stdio_dev.h> |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 19 | |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 20 | #include <asm/mach-common/bits/ppi.h> |
| 21 | #include <asm/mach-common/bits/timer.h> |
| 22 | |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 23 | #define LCD_X_RES 320 /* Horizontal Resolution */ |
| 24 | #define LCD_Y_RES 240 /* Vertical Resolution */ |
Michael Hennerich | 10eafa1 | 2009-12-10 09:19:21 +0000 | [diff] [blame] | 25 | #define DMA_BUS_SIZE 16 |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 26 | |
Wolfgang Denk | d24f2d3 | 2010-10-04 19:58:00 +0200 | [diff] [blame] | 27 | #ifdef CONFIG_BF527_EZKIT_REV_2_1 /* lq035q1 */ |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 28 | |
Michael Hennerich | 10eafa1 | 2009-12-10 09:19:21 +0000 | [diff] [blame] | 29 | #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 Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 103 | |
| 104 | /* HS and VS timing parameters (all in number of PPI clk ticks) */ |
Michael Hennerich | 10eafa1 | 2009-12-10 09:19:21 +0000 | [diff] [blame] | 105 | #define H_ACTPIX (LCD_X_RES * CLOCKS_PPIX) /* active horizontal pixel */ |
| 106 | #define H_PERIOD (408 * CLOCKS_PPIX) /* HS period */ |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 107 | #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 Hennerich | 10eafa1 | 2009-12-10 09:19:21 +0000 | [diff] [blame] | 112 | #define V_LINES (LCD_Y_RES + U_LINE) /* total vertical lines */ |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 113 | #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 Hennerich | 10eafa1 | 2009-12-10 09:19:21 +0000 | [diff] [blame] | 117 | #endif |
| 118 | |
| 119 | #define LCD_PIXEL_SIZE (LCD_BPP / 8) |
| 120 | #define DMA_SIZE16 2 |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 121 | |
| 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 | |
Wolfgang Denk | d24f2d3 | 2010-10-04 19:58:00 +0200 | [diff] [blame] | 128 | #ifdef CONFIG_BF527_EZKIT_REV_2_1 |
Michael Hennerich | 10eafa1 | 2009-12-10 09:19:21 +0000 | [diff] [blame] | 129 | static struct spi_slave *slave; |
| 130 | static 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 Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 162 | /* enable and disable PPI functions */ |
| 163 | void EnablePPI(void) |
| 164 | { |
Mike Frysinger | 989ab87 | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 165 | bfin_write_PPI_CONTROL(bfin_read_PPI_CONTROL() | PORT_EN); |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | void DisablePPI(void) |
| 169 | { |
Mike Frysinger | 989ab87 | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 170 | bfin_write_PPI_CONTROL(bfin_read_PPI_CONTROL() & ~PORT_EN); |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | void Init_Ports(void) |
| 174 | { |
Mike Frysinger | 22e6440 | 2010-06-02 19:30:01 -0400 | [diff] [blame] | 175 | 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 Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | void Init_PPI(void) |
| 183 | { |
| 184 | |
Mike Frysinger | 989ab87 | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 185 | bfin_write_PPI_DELAY(H_START); |
| 186 | bfin_write_PPI_COUNT(H_ACTPIX - 1); |
| 187 | bfin_write_PPI_FRAME(V_LINES); |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 188 | |
| 189 | /* PPI control, to be replaced with definitions */ |
Mike Frysinger | 989ab87 | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 190 | bfin_write_PPI_CONTROL( |
| 191 | PPI_TX_MODE | /* output mode , PORT_DIR */ |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 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 */ |
Mike Frysinger | 989ab87 | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 195 | PPI_POLS_1 /* faling edge syncs POLS */ |
| 196 | ); |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | void Init_DMA(void *dst) |
| 200 | { |
Mike Frysinger | 989ab87 | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 201 | bfin_write_DMA0_START_ADDR(dst); |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 202 | |
| 203 | /* X count */ |
Mike Frysinger | 989ab87 | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 204 | bfin_write_DMA0_X_COUNT(H_ACTPIX / 2); |
| 205 | bfin_write_DMA0_X_MODIFY(DMA_BUS_SIZE / 8); |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 206 | |
| 207 | /* Y count */ |
Mike Frysinger | 989ab87 | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 208 | bfin_write_DMA0_Y_COUNT(V_LINES); |
| 209 | bfin_write_DMA0_Y_MODIFY(DMA_BUS_SIZE / 8); |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 210 | |
| 211 | /* DMA Config */ |
Mike Frysinger | 989ab87 | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 212 | bfin_write_DMA0_CONFIG( |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 213 | WDSIZE_16 | /* 16 bit DMA */ |
| 214 | DMA2D | /* 2D DMA */ |
Mike Frysinger | 989ab87 | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 215 | FLOW_AUTO /* autobuffer mode */ |
| 216 | ); |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 217 | } |
| 218 | |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 219 | void EnableDMA(void) |
| 220 | { |
Mike Frysinger | 989ab87 | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 221 | bfin_write_DMA0_CONFIG(bfin_read_DMA0_CONFIG() | DMAEN); |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | void DisableDMA(void) |
| 225 | { |
Mike Frysinger | 989ab87 | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 226 | bfin_write_DMA0_CONFIG(bfin_read_DMA0_CONFIG() & ~DMAEN); |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 227 | } |
| 228 | |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 229 | /* Init TIMER0 as Frame Sync 1 generator */ |
| 230 | void InitTIMER0(void) |
| 231 | { |
Mike Frysinger | 989ab87 | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 232 | bfin_write_TIMER_DISABLE(TIMDIS0); /* disable Timer */ |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 233 | SSYNC(); |
Mike Frysinger | 989ab87 | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 234 | bfin_write_TIMER_STATUS(TIMIL0 | TOVF_ERR0 | TRUN0); /* clear status */ |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 235 | SSYNC(); |
| 236 | |
Mike Frysinger | 989ab87 | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 237 | bfin_write_TIMER0_PERIOD(H_PERIOD); |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 238 | SSYNC(); |
Mike Frysinger | 989ab87 | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 239 | bfin_write_TIMER0_WIDTH(H_PULSE); |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 240 | SSYNC(); |
| 241 | |
Mike Frysinger | 989ab87 | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 242 | bfin_write_TIMER0_CONFIG( |
| 243 | PWM_OUT | |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 244 | PERIOD_CNT | |
| 245 | TIN_SEL | |
| 246 | CLK_SEL | |
Mike Frysinger | 989ab87 | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 247 | EMU_RUN |
| 248 | ); |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 249 | SSYNC(); |
| 250 | } |
| 251 | |
| 252 | void EnableTIMER0(void) |
| 253 | { |
Mike Frysinger | 989ab87 | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 254 | bfin_write_TIMER_ENABLE(TIMEN0); |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 255 | SSYNC(); |
| 256 | } |
| 257 | |
| 258 | void DisableTIMER0(void) |
| 259 | { |
Mike Frysinger | 989ab87 | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 260 | bfin_write_TIMER_DISABLE(TIMDIS0); |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 261 | SSYNC(); |
| 262 | } |
| 263 | |
| 264 | |
| 265 | void InitTIMER1(void) |
| 266 | { |
Mike Frysinger | 989ab87 | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 267 | bfin_write_TIMER_DISABLE(TIMDIS1); /* disable Timer */ |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 268 | SSYNC(); |
Mike Frysinger | 989ab87 | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 269 | bfin_write_TIMER_STATUS(TIMIL1 | TOVF_ERR1 | TRUN1); /* clear status */ |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 270 | SSYNC(); |
| 271 | |
Mike Frysinger | 989ab87 | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 272 | bfin_write_TIMER1_PERIOD(V_PERIOD); |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 273 | SSYNC(); |
Mike Frysinger | 989ab87 | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 274 | bfin_write_TIMER1_WIDTH(V_PULSE); |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 275 | SSYNC(); |
| 276 | |
Mike Frysinger | 989ab87 | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 277 | bfin_write_TIMER1_CONFIG( |
| 278 | PWM_OUT | |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 279 | PERIOD_CNT | |
| 280 | TIN_SEL | |
| 281 | CLK_SEL | |
Mike Frysinger | 989ab87 | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 282 | EMU_RUN |
| 283 | ); |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 284 | SSYNC(); |
| 285 | } |
| 286 | |
| 287 | void EnableTIMER1(void) |
| 288 | { |
Mike Frysinger | 989ab87 | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 289 | bfin_write_TIMER_ENABLE(TIMEN1); |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 290 | SSYNC(); |
| 291 | } |
| 292 | |
| 293 | void DisableTIMER1(void) |
| 294 | { |
Mike Frysinger | 989ab87 | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 295 | bfin_write_TIMER_DISABLE(TIMDIS1); |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 296 | SSYNC(); |
| 297 | } |
| 298 | |
Michael Hennerich | 10eafa1 | 2009-12-10 09:19:21 +0000 | [diff] [blame] | 299 | void EnableTIMER12(void) |
| 300 | { |
Mike Frysinger | 989ab87 | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 301 | bfin_write_TIMER_ENABLE(TIMEN1 | TIMEN0); |
Michael Hennerich | 10eafa1 | 2009-12-10 09:19:21 +0000 | [diff] [blame] | 302 | SSYNC(); |
| 303 | } |
| 304 | |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 305 | int video_init(void *dst) |
| 306 | { |
| 307 | |
Wolfgang Denk | d24f2d3 | 2010-10-04 19:58:00 +0200 | [diff] [blame] | 308 | #ifdef CONFIG_BF527_EZKIT_REV_2_1 |
Michael Hennerich | 10eafa1 | 2009-12-10 09:19:21 +0000 | [diff] [blame] | 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 Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 313 | Init_Ports(); |
| 314 | Init_DMA(dst); |
| 315 | EnableDMA(); |
| 316 | InitTIMER0(); |
| 317 | InitTIMER1(); |
| 318 | Init_PPI(); |
| 319 | EnablePPI(); |
| 320 | |
Wolfgang Denk | d24f2d3 | 2010-10-04 19:58:00 +0200 | [diff] [blame] | 321 | #ifdef CONFIG_BF527_EZKIT_REV_2_1 |
Michael Hennerich | 10eafa1 | 2009-12-10 09:19:21 +0000 | [diff] [blame] | 322 | EnableTIMER12(); |
| 323 | #else |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 324 | /* 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 Hennerich | 10eafa1 | 2009-12-10 09:19:21 +0000 | [diff] [blame] | 334 | #endif |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 335 | |
| 336 | return 0; |
| 337 | } |
| 338 | |
| 339 | static 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 Hennerich | 5fc564e | 2009-08-07 02:47:54 +0000 | [diff] [blame] | 385 | void video_stop(void) |
| 386 | { |
| 387 | DisablePPI(); |
| 388 | DisableDMA(); |
| 389 | DisableTIMER0(); |
| 390 | DisableTIMER1(); |
Wolfgang Denk | d24f2d3 | 2010-10-04 19:58:00 +0200 | [diff] [blame] | 391 | #ifdef CONFIG_BF527_EZKIT_REV_2_1 |
Michael Hennerich | 5fc564e | 2009-08-07 02:47:54 +0000 | [diff] [blame] | 392 | lq035q1_control(LQ035_SHUT_CTL, LQ035_SHUT); |
| 393 | #endif |
| 394 | } |
| 395 | |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 396 | void video_putc(const char c) |
| 397 | { |
| 398 | } |
| 399 | |
| 400 | void video_puts(const char *s) |
| 401 | { |
| 402 | } |
| 403 | |
| 404 | int drv_video_init(void) |
| 405 | { |
| 406 | int error, devices = 1; |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 407 | struct stdio_dev videodev; |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 408 | |
| 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-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 446 | error = stdio_register(&videodev); |
Mike Frysinger | d9a5d11 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 447 | |
| 448 | return (error == 0) ? devices : error; |
| 449 | } |