Mike Frysinger | 3cced46 | 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 | e40de03 | 2010-06-02 19:30:01 -0400 | [diff] [blame] | 14 | #include <asm/portmux.h> |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 15 | #include <asm/mach-common/bits/dma.h> |
Michael Hennerich | e962162 | 2009-12-10 09:19:21 +0000 | [diff] [blame] | 16 | #include <spi.h> |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 17 | #include <linux/types.h> |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 18 | #include <stdio_dev.h> |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 19 | |
Mike Frysinger | 05015c0 | 2012-02-03 20:44:54 -0500 | [diff] [blame] | 20 | #include <lzma/LzmaTypes.h> |
| 21 | #include <lzma/LzmaDec.h> |
| 22 | #include <lzma/LzmaTools.h> |
| 23 | |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 24 | #include <asm/mach-common/bits/ppi.h> |
| 25 | #include <asm/mach-common/bits/timer.h> |
| 26 | |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 27 | #define LCD_X_RES 320 /* Horizontal Resolution */ |
| 28 | #define LCD_Y_RES 240 /* Vertical Resolution */ |
Michael Hennerich | e962162 | 2009-12-10 09:19:21 +0000 | [diff] [blame] | 29 | #define DMA_BUS_SIZE 16 |
| 30 | |
Mike Frysinger | 05015c0 | 2012-02-03 20:44:54 -0500 | [diff] [blame] | 31 | #include EASYLOGO_HEADER |
Michael Hennerich | e962162 | 2009-12-10 09:19:21 +0000 | [diff] [blame] | 32 | |
Mike Frysinger | 05015c0 | 2012-02-03 20:44:54 -0500 | [diff] [blame] | 33 | #ifdef CONFIG_BF527_EZKIT_REV_2_1 /* lq035q1 */ |
Michael Hennerich | e962162 | 2009-12-10 09:19:21 +0000 | [diff] [blame] | 34 | |
| 35 | /* Interface 16/18-bit TFT over an 8-bit wide PPI using a |
| 36 | * small Programmable Logic Device (CPLD) |
| 37 | * http://blackfin.uclinux.org/gf/project/stamp/frs/?action=FrsReleaseBrowse&frs_package_id=165 |
| 38 | */ |
| 39 | |
| 40 | #ifdef CONFIG_LQ035Q1_USE_RGB565_8_BIT_PPI |
Michael Hennerich | e962162 | 2009-12-10 09:19:21 +0000 | [diff] [blame] | 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 |
Michael Hennerich | e962162 | 2009-12-10 09:19:21 +0000 | [diff] [blame] | 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 |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 86 | |
Michael Hennerich | e962162 | 2009-12-10 09:19:21 +0000 | [diff] [blame] | 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) |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 89 | |
Michael Hennerich | e962162 | 2009-12-10 09:19:21 +0000 | [diff] [blame] | 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 */ |
Michael Hennerich | e962162 | 2009-12-10 09:19:21 +0000 | [diff] [blame] | 98 | |
| 99 | #define LCD_BPP 24 /* Bit Per Pixel */ |
| 100 | #define CLOCKS_PPIX 3 /* Clocks per pixel */ |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 101 | |
| 102 | /* HS and VS timing parameters (all in number of PPI clk ticks) */ |
Michael Hennerich | e962162 | 2009-12-10 09:19:21 +0000 | [diff] [blame] | 103 | #define H_ACTPIX (LCD_X_RES * CLOCKS_PPIX) /* active horizontal pixel */ |
| 104 | #define H_PERIOD (408 * CLOCKS_PPIX) /* HS period */ |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 105 | #define H_PULSE 90 /* HS pulse width */ |
| 106 | #define H_START 204 /* first valid pixel */ |
| 107 | |
| 108 | #define U_LINE 1 /* Blanking Lines */ |
| 109 | |
Michael Hennerich | e962162 | 2009-12-10 09:19:21 +0000 | [diff] [blame] | 110 | #define V_LINES (LCD_Y_RES + U_LINE) /* total vertical lines */ |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 111 | #define V_PULSE (3 * H_PERIOD) /* VS pulse width (1-5 H_PERIODs) */ |
| 112 | #define V_PERIOD (H_PERIOD * V_LINES) /* VS period */ |
| 113 | |
| 114 | #define ACTIVE_VIDEO_MEM_OFFSET (U_LINE * H_ACTPIX) |
Michael Hennerich | e962162 | 2009-12-10 09:19:21 +0000 | [diff] [blame] | 115 | #endif |
| 116 | |
| 117 | #define LCD_PIXEL_SIZE (LCD_BPP / 8) |
| 118 | #define DMA_SIZE16 2 |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 119 | |
| 120 | #define PPI_TX_MODE 0x2 |
| 121 | #define PPI_XFER_TYPE_11 0xC |
| 122 | #define PPI_PORT_CFG_01 0x10 |
| 123 | #define PPI_PACK_EN 0x80 |
| 124 | #define PPI_POLS_1 0x8000 |
| 125 | |
Wolfgang Denk | dc25d15 | 2010-10-04 19:58:00 +0200 | [diff] [blame] | 126 | #ifdef CONFIG_BF527_EZKIT_REV_2_1 |
Michael Hennerich | e962162 | 2009-12-10 09:19:21 +0000 | [diff] [blame] | 127 | static struct spi_slave *slave; |
| 128 | static int lq035q1_control(unsigned char reg, unsigned short value) |
| 129 | { |
| 130 | int ret; |
| 131 | u8 regs[3] = {LQ035_INDEX, 0, 0}; |
| 132 | u8 data[3] = {LQ035_DATA, 0, 0}; |
| 133 | u8 dummy[3]; |
| 134 | |
| 135 | regs[2] = reg; |
| 136 | data[1] = value >> 8; |
| 137 | data[2] = value & 0xFF; |
| 138 | |
| 139 | if (!slave) { |
| 140 | /* FIXME: Verify the max SCK rate */ |
| 141 | slave = spi_setup_slave(CONFIG_LQ035Q1_SPI_BUS, |
| 142 | CONFIG_LQ035Q1_SPI_CS, 20000000, |
| 143 | SPI_MODE_3); |
| 144 | if (!slave) |
| 145 | return -1; |
| 146 | } |
| 147 | |
| 148 | if (spi_claim_bus(slave)) |
| 149 | return -1; |
| 150 | |
| 151 | ret = spi_xfer(slave, 24, regs, dummy, SPI_XFER_BEGIN | SPI_XFER_END); |
| 152 | ret |= spi_xfer(slave, 24, data, dummy, SPI_XFER_BEGIN | SPI_XFER_END); |
| 153 | |
| 154 | spi_release_bus(slave); |
| 155 | |
| 156 | return ret; |
| 157 | } |
| 158 | #endif |
| 159 | |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 160 | /* enable and disable PPI functions */ |
| 161 | void EnablePPI(void) |
| 162 | { |
Mike Frysinger | 4b2b25a | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 163 | bfin_write_PPI_CONTROL(bfin_read_PPI_CONTROL() | PORT_EN); |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | void DisablePPI(void) |
| 167 | { |
Mike Frysinger | 4b2b25a | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 168 | bfin_write_PPI_CONTROL(bfin_read_PPI_CONTROL() & ~PORT_EN); |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | void Init_Ports(void) |
| 172 | { |
Mike Frysinger | e40de03 | 2010-06-02 19:30:01 -0400 | [diff] [blame] | 173 | const unsigned short pins[] = { |
| 174 | P_PPI0_D0, P_PPI0_D1, P_PPI0_D2, P_PPI0_D3, P_PPI0_D4, |
| 175 | P_PPI0_D5, P_PPI0_D6, P_PPI0_D7, P_PPI0_FS2, 0, |
| 176 | }; |
| 177 | peripheral_request_list(pins, "lcd"); |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | void Init_PPI(void) |
| 181 | { |
| 182 | |
Mike Frysinger | 4b2b25a | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 183 | bfin_write_PPI_DELAY(H_START); |
| 184 | bfin_write_PPI_COUNT(H_ACTPIX - 1); |
| 185 | bfin_write_PPI_FRAME(V_LINES); |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 186 | |
| 187 | /* PPI control, to be replaced with definitions */ |
Mike Frysinger | 4b2b25a | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 188 | bfin_write_PPI_CONTROL( |
| 189 | PPI_TX_MODE | /* output mode , PORT_DIR */ |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 190 | PPI_XFER_TYPE_11 | /* sync mode XFR_TYPE */ |
| 191 | PPI_PORT_CFG_01 | /* two frame sync PORT_CFG */ |
| 192 | PPI_PACK_EN | /* packing enabled PACK_EN */ |
Mike Frysinger | 4b2b25a | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 193 | PPI_POLS_1 /* faling edge syncs POLS */ |
| 194 | ); |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | void Init_DMA(void *dst) |
| 198 | { |
Mike Frysinger | 4b2b25a | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 199 | bfin_write_DMA0_START_ADDR(dst); |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 200 | |
| 201 | /* X count */ |
Mike Frysinger | 4b2b25a | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 202 | bfin_write_DMA0_X_COUNT(H_ACTPIX / 2); |
| 203 | bfin_write_DMA0_X_MODIFY(DMA_BUS_SIZE / 8); |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 204 | |
| 205 | /* Y count */ |
Mike Frysinger | 4b2b25a | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 206 | bfin_write_DMA0_Y_COUNT(V_LINES); |
| 207 | bfin_write_DMA0_Y_MODIFY(DMA_BUS_SIZE / 8); |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 208 | |
| 209 | /* DMA Config */ |
Mike Frysinger | 4b2b25a | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 210 | bfin_write_DMA0_CONFIG( |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 211 | WDSIZE_16 | /* 16 bit DMA */ |
| 212 | DMA2D | /* 2D DMA */ |
Mike Frysinger | 4b2b25a | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 213 | FLOW_AUTO /* autobuffer mode */ |
| 214 | ); |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 215 | } |
| 216 | |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 217 | void EnableDMA(void) |
| 218 | { |
Mike Frysinger | 4b2b25a | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 219 | bfin_write_DMA0_CONFIG(bfin_read_DMA0_CONFIG() | DMAEN); |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | void DisableDMA(void) |
| 223 | { |
Mike Frysinger | 4b2b25a | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 224 | bfin_write_DMA0_CONFIG(bfin_read_DMA0_CONFIG() & ~DMAEN); |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 225 | } |
| 226 | |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 227 | /* Init TIMER0 as Frame Sync 1 generator */ |
| 228 | void InitTIMER0(void) |
| 229 | { |
Mike Frysinger | 4b2b25a | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 230 | bfin_write_TIMER_DISABLE(TIMDIS0); /* disable Timer */ |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 231 | SSYNC(); |
Mike Frysinger | 4b2b25a | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 232 | bfin_write_TIMER_STATUS(TIMIL0 | TOVF_ERR0 | TRUN0); /* clear status */ |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 233 | SSYNC(); |
| 234 | |
Mike Frysinger | 4b2b25a | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 235 | bfin_write_TIMER0_PERIOD(H_PERIOD); |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 236 | SSYNC(); |
Mike Frysinger | 4b2b25a | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 237 | bfin_write_TIMER0_WIDTH(H_PULSE); |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 238 | SSYNC(); |
| 239 | |
Mike Frysinger | 4b2b25a | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 240 | bfin_write_TIMER0_CONFIG( |
| 241 | PWM_OUT | |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 242 | PERIOD_CNT | |
| 243 | TIN_SEL | |
| 244 | CLK_SEL | |
Mike Frysinger | 4b2b25a | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 245 | EMU_RUN |
| 246 | ); |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 247 | SSYNC(); |
| 248 | } |
| 249 | |
| 250 | void EnableTIMER0(void) |
| 251 | { |
Mike Frysinger | 4b2b25a | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 252 | bfin_write_TIMER_ENABLE(TIMEN0); |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 253 | SSYNC(); |
| 254 | } |
| 255 | |
| 256 | void DisableTIMER0(void) |
| 257 | { |
Mike Frysinger | 4b2b25a | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 258 | bfin_write_TIMER_DISABLE(TIMDIS0); |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 259 | SSYNC(); |
| 260 | } |
| 261 | |
| 262 | |
| 263 | void InitTIMER1(void) |
| 264 | { |
Mike Frysinger | 4b2b25a | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 265 | bfin_write_TIMER_DISABLE(TIMDIS1); /* disable Timer */ |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 266 | SSYNC(); |
Mike Frysinger | 4b2b25a | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 267 | bfin_write_TIMER_STATUS(TIMIL1 | TOVF_ERR1 | TRUN1); /* clear status */ |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 268 | SSYNC(); |
| 269 | |
Mike Frysinger | 4b2b25a | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 270 | bfin_write_TIMER1_PERIOD(V_PERIOD); |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 271 | SSYNC(); |
Mike Frysinger | 4b2b25a | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 272 | bfin_write_TIMER1_WIDTH(V_PULSE); |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 273 | SSYNC(); |
| 274 | |
Mike Frysinger | 4b2b25a | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 275 | bfin_write_TIMER1_CONFIG( |
| 276 | PWM_OUT | |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 277 | PERIOD_CNT | |
| 278 | TIN_SEL | |
| 279 | CLK_SEL | |
Mike Frysinger | 4b2b25a | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 280 | EMU_RUN |
| 281 | ); |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 282 | SSYNC(); |
| 283 | } |
| 284 | |
| 285 | void EnableTIMER1(void) |
| 286 | { |
Mike Frysinger | 4b2b25a | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 287 | bfin_write_TIMER_ENABLE(TIMEN1); |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 288 | SSYNC(); |
| 289 | } |
| 290 | |
| 291 | void DisableTIMER1(void) |
| 292 | { |
Mike Frysinger | 4b2b25a | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 293 | bfin_write_TIMER_DISABLE(TIMDIS1); |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 294 | SSYNC(); |
| 295 | } |
| 296 | |
Michael Hennerich | e962162 | 2009-12-10 09:19:21 +0000 | [diff] [blame] | 297 | void EnableTIMER12(void) |
| 298 | { |
Mike Frysinger | 4b2b25a | 2010-07-25 17:18:42 -0400 | [diff] [blame] | 299 | bfin_write_TIMER_ENABLE(TIMEN1 | TIMEN0); |
Michael Hennerich | e962162 | 2009-12-10 09:19:21 +0000 | [diff] [blame] | 300 | SSYNC(); |
| 301 | } |
| 302 | |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 303 | int video_init(void *dst) |
| 304 | { |
| 305 | |
Wolfgang Denk | dc25d15 | 2010-10-04 19:58:00 +0200 | [diff] [blame] | 306 | #ifdef CONFIG_BF527_EZKIT_REV_2_1 |
Michael Hennerich | e962162 | 2009-12-10 09:19:21 +0000 | [diff] [blame] | 307 | lq035q1_control(LQ035_SHUT_CTL, LQ035_ON); |
| 308 | lq035q1_control(LQ035_DRIVER_OUTPUT_CTL, (CONFIG_LQ035Q1_LCD_MODE & |
| 309 | LQ035_DRIVER_OUTPUT_MASK) | LQ035_DRIVER_OUTPUT_DEFAULT); |
| 310 | #endif |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 311 | Init_Ports(); |
| 312 | Init_DMA(dst); |
| 313 | EnableDMA(); |
| 314 | InitTIMER0(); |
| 315 | InitTIMER1(); |
| 316 | Init_PPI(); |
| 317 | EnablePPI(); |
| 318 | |
Wolfgang Denk | dc25d15 | 2010-10-04 19:58:00 +0200 | [diff] [blame] | 319 | #ifdef CONFIG_BF527_EZKIT_REV_2_1 |
Michael Hennerich | e962162 | 2009-12-10 09:19:21 +0000 | [diff] [blame] | 320 | EnableTIMER12(); |
| 321 | #else |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 322 | /* Frame sync 2 (VS) needs to start at least one PPI clk earlier */ |
| 323 | EnableTIMER1(); |
| 324 | /* Add Some Delay ... */ |
| 325 | SSYNC(); |
| 326 | SSYNC(); |
| 327 | SSYNC(); |
| 328 | SSYNC(); |
| 329 | |
| 330 | /* now start frame sync 1 */ |
| 331 | EnableTIMER0(); |
Michael Hennerich | e962162 | 2009-12-10 09:19:21 +0000 | [diff] [blame] | 332 | #endif |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 333 | |
| 334 | return 0; |
| 335 | } |
| 336 | |
| 337 | static void dma_bitblit(void *dst, fastimage_t *logo, int x, int y) |
| 338 | { |
| 339 | if (dcache_status()) |
| 340 | blackfin_dcache_flush_range(logo->data, logo->data + logo->size); |
| 341 | |
| 342 | bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR); |
| 343 | |
| 344 | /* Setup destination start address */ |
| 345 | bfin_write_MDMA_D0_START_ADDR(dst + ((x & -2) * LCD_PIXEL_SIZE) |
| 346 | + (y * LCD_X_RES * LCD_PIXEL_SIZE)); |
| 347 | /* Setup destination xcount */ |
| 348 | bfin_write_MDMA_D0_X_COUNT(logo->width * LCD_PIXEL_SIZE / DMA_SIZE16); |
| 349 | /* Setup destination xmodify */ |
| 350 | bfin_write_MDMA_D0_X_MODIFY(DMA_SIZE16); |
| 351 | |
| 352 | /* Setup destination ycount */ |
| 353 | bfin_write_MDMA_D0_Y_COUNT(logo->height); |
| 354 | /* Setup destination ymodify */ |
| 355 | bfin_write_MDMA_D0_Y_MODIFY((LCD_X_RES - logo->width) * LCD_PIXEL_SIZE + DMA_SIZE16); |
| 356 | |
| 357 | |
| 358 | /* Setup Source start address */ |
| 359 | bfin_write_MDMA_S0_START_ADDR(logo->data); |
| 360 | /* Setup Source xcount */ |
| 361 | bfin_write_MDMA_S0_X_COUNT(logo->width * LCD_PIXEL_SIZE / DMA_SIZE16); |
| 362 | /* Setup Source xmodify */ |
| 363 | bfin_write_MDMA_S0_X_MODIFY(DMA_SIZE16); |
| 364 | |
| 365 | /* Setup Source ycount */ |
| 366 | bfin_write_MDMA_S0_Y_COUNT(logo->height); |
| 367 | /* Setup Source ymodify */ |
| 368 | bfin_write_MDMA_S0_Y_MODIFY(DMA_SIZE16); |
| 369 | |
| 370 | |
| 371 | /* Enable source DMA */ |
| 372 | bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_16 | DMA2D); |
| 373 | SSYNC(); |
| 374 | bfin_write_MDMA_D0_CONFIG(WNR | DMAEN | WDSIZE_16 | DMA2D); |
| 375 | |
| 376 | while (bfin_read_MDMA_D0_IRQ_STATUS() & DMA_RUN); |
| 377 | |
| 378 | bfin_write_MDMA_S0_IRQ_STATUS(bfin_read_MDMA_S0_IRQ_STATUS() | DMA_DONE | DMA_ERR); |
| 379 | bfin_write_MDMA_D0_IRQ_STATUS(bfin_read_MDMA_D0_IRQ_STATUS() | DMA_DONE | DMA_ERR); |
| 380 | |
| 381 | } |
| 382 | |
Michael Hennerich | ae712d8 | 2009-08-07 02:47:54 +0000 | [diff] [blame] | 383 | void video_stop(void) |
| 384 | { |
| 385 | DisablePPI(); |
| 386 | DisableDMA(); |
| 387 | DisableTIMER0(); |
| 388 | DisableTIMER1(); |
Wolfgang Denk | dc25d15 | 2010-10-04 19:58:00 +0200 | [diff] [blame] | 389 | #ifdef CONFIG_BF527_EZKIT_REV_2_1 |
Michael Hennerich | ae712d8 | 2009-08-07 02:47:54 +0000 | [diff] [blame] | 390 | lq035q1_control(LQ035_SHUT_CTL, LQ035_SHUT); |
| 391 | #endif |
| 392 | } |
| 393 | |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 394 | int drv_video_init(void) |
| 395 | { |
| 396 | int error, devices = 1; |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 397 | struct stdio_dev videodev; |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 398 | |
| 399 | u8 *dst; |
| 400 | u32 fbmem_size = LCD_X_RES * LCD_Y_RES * LCD_PIXEL_SIZE + ACTIVE_VIDEO_MEM_OFFSET; |
| 401 | |
| 402 | dst = malloc(fbmem_size); |
| 403 | |
| 404 | if (dst == NULL) { |
| 405 | printf("Failed to alloc FB memory\n"); |
| 406 | return -1; |
| 407 | } |
| 408 | |
| 409 | #ifdef EASYLOGO_ENABLE_GZIP |
| 410 | unsigned char *data = EASYLOGO_DECOMP_BUFFER; |
| 411 | unsigned long src_len = EASYLOGO_ENABLE_GZIP; |
Mike Frysinger | 05015c0 | 2012-02-03 20:44:54 -0500 | [diff] [blame] | 412 | error = gunzip(data, bfin_logo.size, bfin_logo.data, &src_len); |
| 413 | bfin_logo.data = data; |
| 414 | #elif defined(EASYLOGO_ENABLE_LZMA) |
| 415 | unsigned char *data = EASYLOGO_DECOMP_BUFFER; |
| 416 | SizeT lzma_len = bfin_logo.size; |
| 417 | error = lzmaBuffToBuffDecompress(data, &lzma_len, |
| 418 | bfin_logo.data, EASYLOGO_ENABLE_LZMA); |
| 419 | bfin_logo.data = data; |
| 420 | #else |
| 421 | error = 0; |
| 422 | #endif |
| 423 | |
| 424 | if (error) { |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 425 | puts("Failed to decompress logo\n"); |
| 426 | free(dst); |
| 427 | return -1; |
| 428 | } |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 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 */ |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 443 | |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 444 | error = stdio_register(&videodev); |
Mike Frysinger | 3cced46 | 2008-10-12 20:59:12 -0400 | [diff] [blame] | 445 | |
| 446 | return (error == 0) ? devices : error; |
| 447 | } |