1 // ==========================================================================
6 // MMC card driver for MXC platform
8 // ==========================================================================
9 //####ECOSGPLCOPYRIGHTBEGIN####
10 // -------------------------------------------
11 // This file is part of eCos, the Embedded Configurable Operating System.
12 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
14 // eCos is free software; you can redistribute it and/or modify it under
15 // the terms of the GNU General Public License as published by the Free
16 // Software Foundation; either version 2 or (at your option) any later version.
18 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
19 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 // You should have received a copy of the GNU General Public License along
24 // with eCos; if not, write to the Free Software Foundation, Inc.,
25 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
27 // As a special exception, if other files instantiate templates or use macros
28 // or inline functions from this file, or you compile this file and link it
29 // with other works to produce a work based on this file, this file does not
30 // by itself cause the resulting work to be covered by the GNU General Public
31 // License. However the source code for this file must still be made available
32 // in accordance with section (3) of the GNU General Public License.
34 // This exception does not invalidate any other reasons why a work based on
35 // this file might be covered by the GNU General Public License.
37 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
38 // at http://sources.redhat.com/ecos/ecos-license/
39 // -------------------------------------------
40 //####ECOSGPLCOPYRIGHTEND####
41 //==========================================================================
42 //#####DESCRIPTIONBEGIN####
44 // Author(s): Lewis Liu <weizhi.liu@freescale.com>
45 // Contributors: Lewis Liu <weizhi.liu@freescale.com>
46 // Date: 2008-05-13 Initial version
49 // Support SD/MMC cards based on eSDHC controller.
50 // only base functionality is implemented: Card init, read and write.
51 // Erase and write protection are not supported so far.
53 //####DESCRIPTIONEND####
55 //==========================================================================
57 #include <pkgconf/hal.h>
58 #include <cyg/infra/diag.h>
59 #include <cyg/hal/hal_arch.h>
60 #include <cyg/hal/hal_cache.h>
61 #ifdef CYGPKG_REDBOOT_HAL_OPTIONS
65 #define _FLASH_PRIVATE_
66 #include <cyg/io/flash.h>
67 #include <cyg/io/mxc_mmc.h>
69 #if defined(CYGPKG_HAL_ARM_MX31ADS) || defined(CYGPKG_HAL_ARM_MX31_3STACK)
70 #include <cyg/io/card_mx32.h>
73 #if defined(CYGPKG_HAL_ARM_MX25_3STACK) || defined(CYGPKG_HAL_ARM_MX35_3STACK) || defined(CYGPKG_HAL_ARM_MX37_3STACK) || defined(CYGPKG_HAL_ARM_MX51)
74 #include <cyg/io/mxcmci_core.h>
77 //hardware init for MMC card
78 #ifndef MXCFLASH_SELECT_MULTI
79 int flash_hwr_init(void)
81 int mmcflash_hwr_init(void)
84 cyg_uint32 status = FAIL;
85 cyg_uint32 capacity = 0;
87 while (status != SUCCESS && i--) {
89 status = mxcmci_init(1, ESDHC1_REG_BASE);
93 diag_printf("Error: Card initialization failed!\n");
96 diag_printf("Card initialization successful!\n");
97 //set flash_info structure
98 externC struct flash_info flash_info;
99 flash_dprintf(FLASH_DEBUG_MAX,"%s: status=%d\n", __FUNCTION__, status);
100 capacity = card_get_capacity_size(); // in unit of KB
101 diag_printf("Actual capacity of the card is %dKB\n", capacity);
102 //if the capacity size is larger than 2G or equals zero, force to be 2G
103 if (capacity > 0x200000 || capacity == 0) {
106 diag_printf("Redboot uses %dKB\n", capacity);
108 flash_info.block_size = 0x20000; // = 128KB
109 flash_info.blocks = capacity / 128;
110 flash_info.start = (void *)MXC_MMC_BASE_DUMMY;
111 flash_info.end = (void *)(MXC_MMC_BASE_DUMMY + flash_info.block_size * flash_info.blocks);
117 // Read data into buffer
118 #ifndef MXCFLASH_SELECT_MULTI
119 int flash_read_buf(void* addr, void* data, int len)
121 int mmcflash_read_buf(void* addr, void* data, int len)
124 flash_dprintf(FLASH_DEBUG_MAX,"%s:Debug:1:addr=%X, data=%X, len=%d\n", __FUNCTION__, (cyg_uint32)addr, (cyg_uint32)data, len);
125 return mmc_data_read(data, len, (cyg_uint32)addr);
129 // Get CID to pointer data (should hold 4*4 byte space)
130 #ifndef MXCFLASH_SELECT_MULTI
131 void flash_query(void* data)
133 void mmcflash_query(void* data)
136 card_flash_query(data);
139 #ifndef MXCFLASH_SELECT_MULTI
140 int flash_hwr_map_error(int e)
142 int mmcflash_hwr_map_error(int e)
148 #ifndef MXCFLASH_SELECT_MULTI
149 bool flash_code_overlaps(void *start, void *end)
151 bool mmcflash_code_overlaps(void *start, void *end)
154 extern char _stext[], _etext[];
156 bool ret = ((((unsigned long)&_stext >= (unsigned long)start) &&
157 ((unsigned long)&_stext < (unsigned long)end)) ||
158 (((unsigned long)&_etext >= (unsigned long)start) &&
159 ((unsigned long)&_etext < (unsigned long)end)));
160 flash_dprintf(FLASH_DEBUG_MAX,"%s: flash code overlap::%d\n", __FUNCTION__, ret);
164 #ifndef MXCFLASH_SELECT_MULTI
165 int flash_erase_block(void* block, unsigned int size)
167 int mmcflash_erase_block(void* block, unsigned int size)
170 flash_dprintf(FLASH_DEBUG_MAX,"%s:Debug:1:block=0x%X, size=%d\n", __FUNCTION__, (cyg_uint32)block, size);
171 return mmc_data_erase((cyg_uint32)block, size);
174 #ifndef MXCFLASH_SELECT_MULTI
175 int flash_program_buf(void* addr, void* data, int len)
177 int mmcflash_program_buf(void* addr, void* data, int len)
180 flash_dprintf(FLASH_DEBUG_MAX,"%s:Debug:1:addr=0x%X, data=0x%X, len=%d\n", __FUNCTION__, (cyg_uint32)addr, (cyg_uint32)data, len);
181 return mmc_data_write((cyg_uint32*)data, len, (cyg_uint32)addr);
184 #ifndef MXCFLASH_SELECT_MULTI
185 int flash_lock_block(void* block)
187 int mmcflash_lock_block(void* block)
194 #ifndef MXCFLASH_SELECT_MULTI
195 int flash_unlock_block(void* block, int block_size, int blocks)
197 int mmcflash_unlock_block(void* block, int block_size, int blocks)
204 void mxc_mmc_print_info(void)
206 extern card_type Card_type;
208 cyg_uint8* cmd_class[] = {
210 "reserved", //class 1
211 "block-read", //class 2
212 "reserved", //class 3
213 "block-write", //class 4
215 "write-protect", //class 6
217 "app-command", //class 8
220 "reserved" //class 11
225 diag_printf("\nBooting from [SD card, CSD Version 1.0]\n");
228 diag_printf("\nBooting from [SD card, CSD Version 2.0]\n");
231 diag_printf("\nBooting from [MMC card, CSD Version 1.0]\n");
234 diag_printf("\nBooting from [MMC card, CSD Version 1.1]\n");
237 diag_printf("\nBooting from [MMC card, CSD Version 1.2]\n");
240 diag_printf("\nBooting from [MMC card (?) ]\n");
243 diag_printf("\nBooting from [unknown version card ]\n");
246 diag_printf("Supporting Card Command Class: ");
249 diag_printf("%s, ", cmd_class[i]);