2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License as
4 * published by the Free Software Foundation; either version 2 of
5 * the License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 #include <asm/errno.h>
22 #include <asm/arch/hardware.h>
26 #include <asm/arch/spi.h>
32 static block_dev_desc_t mmc_dev;
34 /* these are filled out by a call to mmc_hw_get_parameters */
35 static int hw_size; /* in kbytes */
36 static int hw_nr_sects;
37 static int hw_sect_size; /* in bytes */
39 block_dev_desc_t * mmc_get_dev(int dev)
41 return (block_dev_desc_t *)(&mmc_dev);
44 unsigned long mmc_block_read(int dev,
50 unsigned char *p = (unsigned char *)buffer;
52 unsigned long addr = start;
55 printf("mmc_block_read: start=%lu, blkcnt=%lu\n", start,
56 (unsigned long)blkcnt);
59 for(i = 0; i < (unsigned long)blkcnt; i++) {
61 printf("mmc_read_sector: addr=%lu, buffer=%p\n", addr, p);
63 (void)mmc_read_sector(addr, p);
72 /*-----------------------------------------------------------------------------
73 * Read hardware paramterers (sector size, size, number of sectors)
75 static int mmc_hw_get_parameters(void)
77 unsigned char csddata[16];
78 unsigned int sizemult;
81 mmc_read_csd(csddata);
82 hw_sect_size = 1<<(csddata[5] & 0x0f);
83 size = ((csddata[6]&0x03)<<10)+(csddata[7]<<2)+(csddata[8]&0xc0);
84 sizemult = ((csddata[10] & 0x80)>>7)+((csddata[9] & 0x03)<<1);
85 hw_nr_sects = (size+1)*(1<<(sizemult+2));
86 hw_size = hw_nr_sects*hw_sect_size/1024;
89 printf("mmc_hw_get_parameters: hw_sect_size=%d, hw_nr_sects=%d, "
90 "hw_size=%d\n", hw_sect_size, hw_nr_sects, hw_size);
96 int mmc_legacy_init(int verbose)
101 printf("mmc_legacy_init\n");
104 /* this meeds to be done twice */
109 mmc_hw_get_parameters();
111 mmc_dev.if_type = IF_TYPE_MMC;
112 mmc_dev.part_type = PART_TYPE_DOS;
116 mmc_dev.blksz = hw_sect_size;
117 mmc_dev.lba = hw_nr_sects;
118 sprintf((char*)mmc_dev.vendor, "Unknown vendor");
119 sprintf((char*)mmc_dev.product, "Unknown product");
120 sprintf((char*)mmc_dev.revision, "N/A");
121 mmc_dev.removable = 0; /* should be true??? */
122 mmc_dev.block_read = mmc_block_read;
124 fat_register_device(&mmc_dev, 1);
131 #endif /* CONFIG_MMC */