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