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 #ifdef CYGPKG_HAL_ARM_MX31
70 #include <cyg/io/card_mx32.h>
73 #if defined(CYGPKG_HAL_ARM_MX25) || defined(CYGPKG_HAL_ARM_MX35) || \
74 defined(CYGPKG_HAL_ARM_MX37) || defined(CYGPKG_HAL_ARM_MX51)
75 #include <cyg/io/mxcmci_core.h>
78 //hardware init for MMC card
79 #ifndef MXCFLASH_SELECT_MULTI
80 int flash_hwr_init(void)
82 int mmcflash_hwr_init(void)
85 cyg_uint32 status = FAIL;
86 cyg_uint32 capacity = 0;
88 while (status != SUCCESS && i--) {
90 status = mxcmci_init(1, ESDHC1_REG_BASE);
94 diag_printf("Error: Card initialization failed!\n");
97 diag_printf("Card initialization successful!\n");
98 //set flash_info structure
99 externC struct flash_info flash_info;
100 flash_dprintf(FLASH_DEBUG_MAX,"%s: status=%d\n", __FUNCTION__, status);
101 capacity = card_get_capacity_size(); // in unit of KB
102 diag_printf("Actual capacity of the card is %dKB\n", capacity);
103 //if the capacity size is larger than 2G or equals zero, force to be 2G
104 if (capacity > 0x200000 || capacity == 0) {
107 diag_printf("Redboot uses %dKB\n", capacity);
109 flash_info.block_size = 0x20000; // = 128KB
110 flash_info.blocks = capacity / 128;
111 flash_info.start = (void *)MXC_MMC_BASE_DUMMY;
112 flash_info.end = (void *)(MXC_MMC_BASE_DUMMY + flash_info.block_size * flash_info.blocks);
118 // Read data into buffer
119 #ifndef MXCFLASH_SELECT_MULTI
120 int flash_read_buf(void* addr, void* data, int len)
122 int mmcflash_read_buf(void* addr, void* data, int len)
125 flash_dprintf(FLASH_DEBUG_MAX,"%s:Debug:1:addr=%X, data=%X, len=%d\n", __FUNCTION__, (cyg_uint32)addr, (cyg_uint32)data, len);
126 return mmc_data_read(data, len, (cyg_uint32)addr);
130 // Get CID to pointer data (should hold 4*4 byte space)
131 #ifndef MXCFLASH_SELECT_MULTI
132 void flash_query(void* data)
134 void mmcflash_query(void* data)
137 card_flash_query(data);
140 #ifndef MXCFLASH_SELECT_MULTI
141 int flash_hwr_map_error(int e)
143 int mmcflash_hwr_map_error(int e)
149 #ifndef MXCFLASH_SELECT_MULTI
150 bool flash_code_overlaps(void *start, void *end)
152 bool mmcflash_code_overlaps(void *start, void *end)
155 extern char _stext[], _etext[];
157 bool ret = ((((unsigned long)&_stext >= (unsigned long)start) &&
158 ((unsigned long)&_stext < (unsigned long)end)) ||
159 (((unsigned long)&_etext >= (unsigned long)start) &&
160 ((unsigned long)&_etext < (unsigned long)end)));
161 flash_dprintf(FLASH_DEBUG_MAX,"%s: flash code overlap::%d\n", __FUNCTION__, ret);
165 #ifndef MXCFLASH_SELECT_MULTI
166 int flash_erase_block(void* block, unsigned int size)
168 int mmcflash_erase_block(void* block, unsigned int size)
171 flash_dprintf(FLASH_DEBUG_MAX,"%s:Debug:1:block=0x%X, size=%d\n", __FUNCTION__, (cyg_uint32)block, size);
172 return mmc_data_erase((cyg_uint32)block, size);
175 #ifndef MXCFLASH_SELECT_MULTI
176 int flash_program_buf(void* addr, void* data, int len)
178 int mmcflash_program_buf(void* addr, void* data, int len)
181 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);
182 return mmc_data_write((cyg_uint32*)data, len, (cyg_uint32)addr);
185 #ifndef MXCFLASH_SELECT_MULTI
186 int flash_lock_block(void* block)
188 int mmcflash_lock_block(void* block)
195 #ifndef MXCFLASH_SELECT_MULTI
196 int flash_unlock_block(void* block, int block_size, int blocks)
198 int mmcflash_unlock_block(void* block, int block_size, int blocks)
205 void mxc_mmc_print_info(void)
207 extern card_type Card_type;
209 cyg_uint8* cmd_class[] = {
211 "reserved", //class 1
212 "block-read", //class 2
213 "reserved", //class 3
214 "block-write", //class 4
216 "write-protect", //class 6
218 "app-command", //class 8
221 "reserved" //class 11
226 diag_printf("\nBooting from [SD card, CSD Version 1.0]\n");
229 diag_printf("\nBooting from [SD card, CSD Version 2.0]\n");
232 diag_printf("\nBooting from [MMC card, CSD Version 1.0]\n");
235 diag_printf("\nBooting from [MMC card, CSD Version 1.1]\n");
238 diag_printf("\nBooting from [MMC card, CSD Version 1.2]\n");
241 diag_printf("\nBooting from [MMC card (?) ]\n");
244 diag_printf("\nBooting from [unknown version card ]\n");
247 diag_printf("Supporting Card Command Class: ");
250 diag_printf("%s, ", cmd_class[i]);