]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/devs/ipu/arm/imx/v1_0/src/ipu_common.c
0f3bde620fdc5520e178e076327b0a588b957940
[karo-tx-redboot.git] / packages / devs / ipu / arm / imx / v1_0 / src / ipu_common.c
1 /***************************************************************************
2 *
3 *                                                     IPU_COMMON.C
4 *
5 * Copyright 2005-2006 by Freescale Semiconductor, Inc.
6 * All modifications are confidential and proprietary information
7 * of Freescale Semiconductor, Inc. ALL RIGHTS RESERVED.
8 *
9 ***************************************************************************
10 *
11 * Author(s)             :               Ray Sun-B17777 <Yanfei.Sun@freescale.com>
12 * Create Date   :               2008-11-10
13 * Description   :               common functions definition for IPU API.
14 *
15 ***************************************************************************/
16 #include <cyg/io/ipu_common.h>
17 #ifdef CYGPKG_REDBOOT
18 #include <redboot.h>
19 #endif
20 #include <cyg/io/flash.h>
21 #ifdef CYGSEM_REDBOOT_FLASH_CONFIG
22 #include <flash_config.h>
23 #endif
24 #ifdef CYGOPT_REDBOOT_FIS
25 #include <fis.h>
26 #endif
27
28 /*
29 * write bit fields of special IPU regs
30 */
31 void ipu_write_field(unsigned int id_addr, unsigned int id_mask, unsigned int data)
32 {
33         unsigned int rdata;
34
35         id_addr += IPU_CTRL_BASE_ADDR;
36         rdata = readl(id_addr);
37         rdata &= ~id_mask;
38         rdata |= (data * (id_mask & -id_mask)) & id_mask;
39         writel(rdata, id_addr);
40 }
41
42 /*
43 *       enable ipu display
44 */
45 void ipu_enable_display(void)
46 {
47         //enable DI0 (display interface 1)
48         ipu_write_field(IPU_IPU_CONF__DP_EN, 1);
49         ipu_write_field(IPU_IPU_CONF__DC_EN, 1);
50         ipu_write_field(IPU_IPU_CONF__DMFC_EN, 1);
51         ipu_write_field(IPU_IPU_CONF__DI0_EN, 1);
52         ipu_write_field(IPU_IPU_CONF__DI1_EN, 1);
53 #ifdef CYGPKG_HAL_ARM_MX51_3STACK
54         ipu_write_field(IPU_IPU_CONF__CSI1_EN, 1);
55 #endif
56 }
57
58 /*
59 *       disable ipu display
60 */
61 void ipu_disable_display(void)
62 {
63         ipu_write_field(IPU_IPU_CONF__DI0_EN, 0);
64         ipu_write_field(IPU_IPU_CONF__DI1_EN, 0);
65         ipu_write_field(IPU_IPU_CONF__DP_EN, 0);
66         ipu_write_field(IPU_IPU_CONF__DC_EN, 0);
67         ipu_write_field(IPU_IPU_CONF__DMFC_EN, 0);
68         ipu_write_field(IPU_IPU_CONF__IC_EN, 0);
69 #ifdef CYGPKG_HAL_ARM_MX51_3STACK
70         ipu_write_field(IPU_IPU_CONF__CSI0_EN, 0);
71         ipu_write_field(IPU_IPU_CONF__CSI1_EN, 0);
72         ipu_write_field(IPU_IPU_CONF__SMFC_EN, 0);
73 #endif
74         ipu_write_field(IPU_IC_CONF__PP_EN, 0);
75         ipu_write_field(IPU_IC_CONF__PRPVF_EN, 0);
76         ipu_write_field(IPU_IC_CONF__PRPENC_EN, 0);
77 }
78
79 #ifdef CYGHWR_MX51_LCD_LOGO
80 static display_buffer_info_t display_buffer;
81
82 /*!
83 * load the logo from nand flash to memory.
84 */
85 static bool do_logo_load(void)
86 {
87         void *fis_addr;
88         int ret = 0xFF;
89         void *err_addr;
90         unsigned int logo_size;
91         struct fis_image_desc *img;
92
93         /* Read the logo from storage media */
94         if ((img = fis_lookup("logo", NULL)) == NULL) {
95                 diag_printf("No logo partition found in the fis table, logo not loaded\n");
96                 return false;
97         }
98
99         fis_addr = (void *)img->flash_base;
100         logo_size = img->size;
101         ret = FLASH_READ(fis_addr, DISPLAY_BUFFER_ADDR, logo_size, &err_addr);
102         if (ret != 0) {
103                 diag_printf("Loading logo from FLASH to MEMORY failed. error code: %d", ret);
104         }
105         return true;
106 }
107
108 /*!
109 * this function is used to reset ipu by SRC(system reset controller)
110 * the return value should be negative if resetting timeout
111 */
112 #define IPU_RESET       (1 << 3)
113 static int ipu_sw_reset(int timeout)
114 {
115         int tmpVal;
116
117         tmpVal = readl(SRC_BASE_ADDR);
118         writel(tmpVal | IPU_RESET, SRC_BASE_ADDR);
119         while (timeout > 0) {
120                 if (!(readl(SRC_BASE_ADDR) & IPU_RESET))
121                         return 0;
122                 timeout--;
123         }
124         diag_printf("Error: ipu software reset timed out\n");
125         return -1;
126 }
127
128 static void redboot_fastlogo_display(void)
129 {
130         bool fastlogo_feature_enable;
131         int ok;
132
133         ok = CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET,
134                                                                         "fastlogo_enable", &fastlogo_feature_enable, CONFIG_BOOL);
135
136         if (ok && fastlogo_feature_enable) {
137                 display_buffer.startAddr = (CYG_ADDRESS)DISPLAY_BUFFER_ADDR;
138                 display_buffer.width = 640;
139                 display_buffer.height = 480;
140                 display_buffer.dataFormat = RGB565;
141                 display_buffer.bpp = 16; // bit per pixel
142                 display_buffer.channel = 28;
143
144                 ipu_sw_reset(0x10000);
145                 if (!do_logo_load()) {
146                         return;
147                 }
148                 //mxc_ipu_iomux_config();
149                 //lcd_backlit_on();
150                 //lcd_config();
151                 fastlogo_init(&display_buffer);
152                 fastlogo_dma();
153                 fastlogo_dmfc();
154                 fastlogo_dc();
155                 fastlogo_di();
156                 ipu_enable_display();
157                 ipu_idmac_channel_buf_ready(display_buffer.channel, 0);
158         }
159 }
160
161 #ifdef CYGPKG_REDBOOT
162 RedBoot_init(redboot_fastlogo_display, RedBoot_INIT_SECOND);
163 #endif
164
165 RedBoot_config_option("Enable fast logo display at boot",
166                                         fastlogo_enable,
167                                         ALWAYS_ENABLED, true,
168                                         CONFIG_BOOL,
169                                         false
170         );
171 #endif