blob: e90db7ee3378c42efc6f0e292563ad9987b420da [file] [log] [blame]
Dirk Behmeb1c3bf92008-12-14 09:47:17 +01001/*
2 * (C) Copyright 2008
3 * Texas Instruments, <www.ti.com>
4 * Syed Mohammed Khasim <khasim@ti.com>
5 *
6 * See file CREDITS for list of people who contributed to this
7 * project.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation's version 2 of
12 * the License.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 * MA 02111-1307 USA
23 */
24
25#include <config.h>
26#include <common.h>
27#include <fat.h>
28#include <mmc.h>
29#include <part.h>
30#include <i2c.h>
Dirk Behmeaba45c82009-02-20 17:51:28 +010031#include <asm/io.h>
Tom Rixe5e88c32009-02-19 16:45:43 -060032#include <asm/arch/mmc.h>
Dirk Behmeb1c3bf92008-12-14 09:47:17 +010033
34const unsigned short mmc_transspeed_val[15][4] = {
35 {CLKD(10, 1), CLKD(10, 10), CLKD(10, 100), CLKD(10, 1000)},
36 {CLKD(12, 1), CLKD(12, 10), CLKD(12, 100), CLKD(12, 1000)},
37 {CLKD(13, 1), CLKD(13, 10), CLKD(13, 100), CLKD(13, 1000)},
38 {CLKD(15, 1), CLKD(15, 10), CLKD(15, 100), CLKD(15, 1000)},
39 {CLKD(20, 1), CLKD(20, 10), CLKD(20, 100), CLKD(20, 1000)},
40 {CLKD(26, 1), CLKD(26, 10), CLKD(26, 100), CLKD(26, 1000)},
41 {CLKD(30, 1), CLKD(30, 10), CLKD(30, 100), CLKD(30, 1000)},
42 {CLKD(35, 1), CLKD(35, 10), CLKD(35, 100), CLKD(35, 1000)},
43 {CLKD(40, 1), CLKD(40, 10), CLKD(40, 100), CLKD(40, 1000)},
44 {CLKD(45, 1), CLKD(45, 10), CLKD(45, 100), CLKD(45, 1000)},
45 {CLKD(52, 1), CLKD(52, 10), CLKD(52, 100), CLKD(52, 1000)},
46 {CLKD(55, 1), CLKD(55, 10), CLKD(55, 100), CLKD(55, 1000)},
47 {CLKD(60, 1), CLKD(60, 10), CLKD(60, 100), CLKD(60, 1000)},
48 {CLKD(70, 1), CLKD(70, 10), CLKD(70, 100), CLKD(70, 1000)},
49 {CLKD(80, 1), CLKD(80, 10), CLKD(80, 100), CLKD(80, 1000)}
50};
51
52mmc_card_data cur_card_data;
53static block_dev_desc_t mmc_blk_dev;
Dirk Behmeaba45c82009-02-20 17:51:28 +010054static hsmmc_t *mmc_base = (hsmmc_t *)OMAP_HSMMC_BASE;
Dirk Behmeb1c3bf92008-12-14 09:47:17 +010055
56block_dev_desc_t *mmc_get_dev(int dev)
57{
58 return (block_dev_desc_t *) &mmc_blk_dev;
59}
60
61void twl4030_mmc_config(void)
62{
63 unsigned char data;
64
Dirk Behmeaba45c82009-02-20 17:51:28 +010065 data = DEV_GRP_P1;
66 i2c_write(PWRMGT_ADDR_ID4, VMMC1_DEV_GRP, 1, &data, 1);
67 data = VMMC1_VSEL_30;
68 i2c_write(PWRMGT_ADDR_ID4, VMMC1_DEDICATED, 1, &data, 1);
Dirk Behmeb1c3bf92008-12-14 09:47:17 +010069}
70
71unsigned char mmc_board_init(void)
72{
Dirk Behmeaba45c82009-02-20 17:51:28 +010073 t2_t *t2_base = (t2_t *)T2_BASE;
Dirk Behmeb1c3bf92008-12-14 09:47:17 +010074
75 twl4030_mmc_config();
76
Dirk Behmeaba45c82009-02-20 17:51:28 +010077 writel(readl(&t2_base->pbias_lite) | PBIASLITEPWRDNZ1 |
78 PBIASSPEEDCTRL0 | PBIASLITEPWRDNZ0,
79 &t2_base->pbias_lite);
Dirk Behmeb1c3bf92008-12-14 09:47:17 +010080
Dirk Behmeaba45c82009-02-20 17:51:28 +010081 writel(readl(&t2_base->devconf0) | MMCSDIO1ADPCLKISEL,
82 &t2_base->devconf0);
Dirk Behmeb1c3bf92008-12-14 09:47:17 +010083
84 return 1;
85}
86
87void mmc_init_stream(void)
88{
Dirk Behmeaba45c82009-02-20 17:51:28 +010089 writel(readl(&mmc_base->con) | INIT_INITSTREAM, &mmc_base->con);
Dirk Behmeb1c3bf92008-12-14 09:47:17 +010090
Dirk Behmeaba45c82009-02-20 17:51:28 +010091 writel(MMC_CMD0, &mmc_base->cmd);
92 while (!(readl(&mmc_base->stat) & CC_MASK));
Dirk Behmeb1c3bf92008-12-14 09:47:17 +010093
Dirk Behmeaba45c82009-02-20 17:51:28 +010094 writel(CC_MASK, &mmc_base->stat);
Dirk Behmeb1c3bf92008-12-14 09:47:17 +010095
Dirk Behmeaba45c82009-02-20 17:51:28 +010096 writel(MMC_CMD0, &mmc_base->cmd);
97 while (!(readl(&mmc_base->stat) & CC_MASK));
Dirk Behmeb1c3bf92008-12-14 09:47:17 +010098
Dirk Behmeaba45c82009-02-20 17:51:28 +010099 writel(readl(&mmc_base->con) & ~INIT_INITSTREAM, &mmc_base->con);
Dirk Behmeb1c3bf92008-12-14 09:47:17 +0100100}
101
102unsigned char mmc_clock_config(unsigned int iclk, unsigned short clk_div)
103{
104 unsigned int val;
105
Dirk Behmeaba45c82009-02-20 17:51:28 +0100106 mmc_reg_out(&mmc_base->sysctl, (ICE_MASK | DTO_MASK | CEN_MASK),
107 (ICE_STOP | DTO_15THDTO | CEN_DISABLE));
Dirk Behmeb1c3bf92008-12-14 09:47:17 +0100108
109 switch (iclk) {
110 case CLK_INITSEQ:
111 val = MMC_INIT_SEQ_CLK / 2;
112 break;
113 case CLK_400KHZ:
114 val = MMC_400kHz_CLK;
115 break;
116 case CLK_MISC:
117 val = clk_div;
118 break;
119 default:
120 return 0;
121 }
Dirk Behmeaba45c82009-02-20 17:51:28 +0100122 mmc_reg_out(&mmc_base->sysctl, ICE_MASK | CLKD_MASK,
123 (val << CLKD_OFFSET) | ICE_OSCILLATE);
Dirk Behmeb1c3bf92008-12-14 09:47:17 +0100124
Dirk Behmeaba45c82009-02-20 17:51:28 +0100125 while ((readl(&mmc_base->sysctl) & ICS_MASK) == ICS_NOTREADY);
Dirk Behmeb1c3bf92008-12-14 09:47:17 +0100126
Dirk Behmeaba45c82009-02-20 17:51:28 +0100127 writel(readl(&mmc_base->sysctl) | CEN_ENABLE, &mmc_base->sysctl);
Dirk Behmeb1c3bf92008-12-14 09:47:17 +0100128 return 1;
129}
130
131unsigned char mmc_init_setup(void)
132{
133 unsigned int reg_val;
134
135 mmc_board_init();
136
Dirk Behmeaba45c82009-02-20 17:51:28 +0100137 writel(readl(&mmc_base->sysconfig) | MMC_SOFTRESET,
138 &mmc_base->sysconfig);
139 while ((readl(&mmc_base->sysstatus) & RESETDONE) == 0);
Dirk Behmeb1c3bf92008-12-14 09:47:17 +0100140
Dirk Behmeaba45c82009-02-20 17:51:28 +0100141 writel(readl(&mmc_base->sysctl) | SOFTRESETALL, &mmc_base->sysctl);
142 while ((readl(&mmc_base->sysctl) & SOFTRESETALL) != 0x0);
Dirk Behmeb1c3bf92008-12-14 09:47:17 +0100143
Dirk Behmeaba45c82009-02-20 17:51:28 +0100144 writel(DTW_1_BITMODE | SDBP_PWROFF | SDVS_3V0, &mmc_base->hctl);
145 writel(readl(&mmc_base->capa) | VS30_3V0SUP | VS18_1V8SUP,
146 &mmc_base->capa);
Dirk Behmeb1c3bf92008-12-14 09:47:17 +0100147
Dirk Behmeaba45c82009-02-20 17:51:28 +0100148 reg_val = readl(&mmc_base->con) & RESERVED_MASK;
Dirk Behmeb1c3bf92008-12-14 09:47:17 +0100149
Dirk Behmeaba45c82009-02-20 17:51:28 +0100150 writel(CTPL_MMC_SD | reg_val | WPP_ACTIVEHIGH | CDP_ACTIVEHIGH |
151 MIT_CTO | DW8_1_4BITMODE | MODE_FUNC | STR_BLOCK |
152 HR_NOHOSTRESP | INIT_NOINIT | NOOPENDRAIN, &mmc_base->con);
Dirk Behmeb1c3bf92008-12-14 09:47:17 +0100153
154 mmc_clock_config(CLK_INITSEQ, 0);
Dirk Behmeaba45c82009-02-20 17:51:28 +0100155 writel(readl(&mmc_base->hctl) | SDBP_PWRON, &mmc_base->hctl);
Dirk Behmeb1c3bf92008-12-14 09:47:17 +0100156
Dirk Behmeaba45c82009-02-20 17:51:28 +0100157 writel(IE_BADA | IE_CERR | IE_DEB | IE_DCRC | IE_DTO | IE_CIE |
158 IE_CEB | IE_CCRC | IE_CTO | IE_BRR | IE_BWR | IE_TC | IE_CC,
159 &mmc_base->ie);
Dirk Behmeb1c3bf92008-12-14 09:47:17 +0100160
161 mmc_init_stream();
162 return 1;
163}
164
165unsigned char mmc_send_cmd(unsigned int cmd, unsigned int arg,
Dirk Behmeaba45c82009-02-20 17:51:28 +0100166 unsigned int *response)
Dirk Behmeb1c3bf92008-12-14 09:47:17 +0100167{
Dirk Behmeaba45c82009-02-20 17:51:28 +0100168 unsigned int mmc_stat;
Dirk Behmeb1c3bf92008-12-14 09:47:17 +0100169
Dirk Behmeaba45c82009-02-20 17:51:28 +0100170 while ((readl(&mmc_base->pstate) & DATI_MASK) == DATI_CMDDIS);
Dirk Behmeb1c3bf92008-12-14 09:47:17 +0100171
Dirk Behmeaba45c82009-02-20 17:51:28 +0100172 writel(BLEN_512BYTESLEN | NBLK_STPCNT, &mmc_base->blk);
173 writel(0xFFFFFFFF, &mmc_base->stat);
174 writel(arg, &mmc_base->arg);
175 writel(cmd | CMD_TYPE_NORMAL | CICE_NOCHECK | CCCE_NOCHECK |
176 MSBS_SGLEBLK | ACEN_DISABLE | BCE_DISABLE | DE_DISABLE,
177 &mmc_base->cmd);
Dirk Behmeb1c3bf92008-12-14 09:47:17 +0100178
179 while (1) {
180 do {
Dirk Behmeaba45c82009-02-20 17:51:28 +0100181 mmc_stat = readl(&mmc_base->stat);
Dirk Behmeb1c3bf92008-12-14 09:47:17 +0100182 } while (mmc_stat == 0);
183
184 if ((mmc_stat & ERRI_MASK) != 0)
185 return (unsigned char) mmc_stat;
186
187 if (mmc_stat & CC_MASK) {
Dirk Behmeaba45c82009-02-20 17:51:28 +0100188 writel(CC_MASK, &mmc_base->stat);
189 response[0] = readl(&mmc_base->rsp10);
Dirk Behmeb1c3bf92008-12-14 09:47:17 +0100190 if ((cmd & RSP_TYPE_MASK) == RSP_TYPE_LGHT136) {
Dirk Behmeaba45c82009-02-20 17:51:28 +0100191 response[1] = readl(&mmc_base->rsp32);
192 response[2] = readl(&mmc_base->rsp54);
193 response[3] = readl(&mmc_base->rsp76);
Dirk Behmeb1c3bf92008-12-14 09:47:17 +0100194 }
195 break;
196 }
197 }
198 return 1;
199}
200
201unsigned char mmc_read_data(unsigned int *output_buf)
202{
Dirk Behmeaba45c82009-02-20 17:51:28 +0100203 unsigned int mmc_stat;
Dirk Behmeb1c3bf92008-12-14 09:47:17 +0100204 unsigned int read_count = 0;
205
206 /*
207 * Start Polled Read
208 */
209 while (1) {
210 do {
Dirk Behmeaba45c82009-02-20 17:51:28 +0100211 mmc_stat = readl(&mmc_base->stat);
Dirk Behmeb1c3bf92008-12-14 09:47:17 +0100212 } while (mmc_stat == 0);
213
214 if ((mmc_stat & ERRI_MASK) != 0)
215 return (unsigned char) mmc_stat;
216
217 if (mmc_stat & BRR_MASK) {
218 unsigned int k;
219
Dirk Behmeaba45c82009-02-20 17:51:28 +0100220 writel(readl(&mmc_base->stat) | BRR_MASK,
221 &mmc_base->stat);
Dirk Behmeb1c3bf92008-12-14 09:47:17 +0100222 for (k = 0; k < MMCSD_SECTOR_SIZE / 4; k++) {
Dirk Behmeaba45c82009-02-20 17:51:28 +0100223 *output_buf = readl(&mmc_base->data);
Dirk Behmeb1c3bf92008-12-14 09:47:17 +0100224 output_buf++;
225 read_count += 4;
226 }
227 }
228
229 if (mmc_stat & BWR_MASK)
Dirk Behmeaba45c82009-02-20 17:51:28 +0100230 writel(readl(&mmc_base->stat) | BWR_MASK,
231 &mmc_base->stat);
Dirk Behmeb1c3bf92008-12-14 09:47:17 +0100232
233 if (mmc_stat & TC_MASK) {
Dirk Behmeaba45c82009-02-20 17:51:28 +0100234 writel(readl(&mmc_base->stat) | TC_MASK,
235 &mmc_base->stat);
Dirk Behmeb1c3bf92008-12-14 09:47:17 +0100236 break;
237 }
238 }
239 return 1;
240}
241
242unsigned char mmc_detect_card(mmc_card_data *mmc_card_cur)
243{
244 unsigned char err;
245 unsigned int argument = 0;
246 unsigned int ocr_value, ocr_recvd, ret_cmd41, hcs_val;
247 unsigned int resp[4];
248 unsigned short retry_cnt = 2000;
249
250 /* Set to Initialization Clock */
251 err = mmc_clock_config(CLK_400KHZ, 0);
252 if (err != 1)
253 return err;
254
255 mmc_card_cur->RCA = MMC_RELATIVE_CARD_ADDRESS;
256 argument = 0x00000000;
257
258 ocr_value = (0x1FF << 15);
259 err = mmc_send_cmd(MMC_CMD0, argument, resp);
260 if (err != 1)
261 return err;
262
263 argument = SD_CMD8_CHECK_PATTERN | SD_CMD8_2_7_3_6_V_RANGE;
264 err = mmc_send_cmd(MMC_SDCMD8, argument, resp);
265 hcs_val = (err == 1) ?
266 MMC_OCR_REG_HOST_CAPACITY_SUPPORT_SECTOR :
267 MMC_OCR_REG_HOST_CAPACITY_SUPPORT_BYTE;
268
269 argument = 0x0000 << 16;
270 err = mmc_send_cmd(MMC_CMD55, argument, resp);
271 if (err == 1) {
272 mmc_card_cur->card_type = SD_CARD;
273 ocr_value |= hcs_val;
274 ret_cmd41 = MMC_ACMD41;
275 } else {
276 mmc_card_cur->card_type = MMC_CARD;
277 ocr_value |= MMC_OCR_REG_ACCESS_MODE_SECTOR;
278 ret_cmd41 = MMC_CMD1;
Dirk Behmeaba45c82009-02-20 17:51:28 +0100279 writel(readl(&mmc_base->con) & ~OD, &mmc_base->con);
280 writel(readl(&mmc_base->con) | OPENDRAIN, &mmc_base->con);
Dirk Behmeb1c3bf92008-12-14 09:47:17 +0100281 }
282
283 argument = ocr_value;
284 err = mmc_send_cmd(ret_cmd41, argument, resp);
285 if (err != 1)
286 return err;
287
288 ocr_recvd = ((mmc_resp_r3 *) resp)->ocr;
289
290 while (!(ocr_recvd & (0x1 << 31)) && (retry_cnt > 0)) {
291 retry_cnt--;
292 if (mmc_card_cur->card_type == SD_CARD) {
293 argument = 0x0000 << 16;
294 err = mmc_send_cmd(MMC_CMD55, argument, resp);
295 }
296
297 argument = ocr_value;
298 err = mmc_send_cmd(ret_cmd41, argument, resp);
299 if (err != 1)
300 return err;
301 ocr_recvd = ((mmc_resp_r3 *) resp)->ocr;
302 }
303
304 if (!(ocr_recvd & (0x1 << 31)))
305 return 0;
306
307 if (mmc_card_cur->card_type == MMC_CARD) {
308 if ((ocr_recvd & MMC_OCR_REG_ACCESS_MODE_MASK) ==
309 MMC_OCR_REG_ACCESS_MODE_SECTOR) {
310 mmc_card_cur->mode = SECTOR_MODE;
311 } else {
312 mmc_card_cur->mode = BYTE_MODE;
313 }
314
315 ocr_recvd &= ~MMC_OCR_REG_ACCESS_MODE_MASK;
316 } else {
317 if ((ocr_recvd & MMC_OCR_REG_HOST_CAPACITY_SUPPORT_MASK)
318 == MMC_OCR_REG_HOST_CAPACITY_SUPPORT_SECTOR) {
319 mmc_card_cur->mode = SECTOR_MODE;
320 } else {
321 mmc_card_cur->mode = BYTE_MODE;
322 }
323 ocr_recvd &= ~MMC_OCR_REG_HOST_CAPACITY_SUPPORT_MASK;
324 }
325
326 ocr_recvd &= ~(0x1 << 31);
327 if (!(ocr_recvd & ocr_value))
328 return 0;
329
330 err = mmc_send_cmd(MMC_CMD2, argument, resp);
331 if (err != 1)
332 return err;
333
334 if (mmc_card_cur->card_type == MMC_CARD) {
335 argument = mmc_card_cur->RCA << 16;
336 err = mmc_send_cmd(MMC_CMD3, argument, resp);
337 if (err != 1)
338 return err;
339 } else {
340 argument = 0x00000000;
341 err = mmc_send_cmd(MMC_SDCMD3, argument, resp);
342 if (err != 1)
343 return err;
344
345 mmc_card_cur->RCA = ((mmc_resp_r6 *) resp)->newpublishedrca;
346 }
347
Dirk Behmeaba45c82009-02-20 17:51:28 +0100348 writel(readl(&mmc_base->con) & ~OD, &mmc_base->con);
349 writel(readl(&mmc_base->con) | NOOPENDRAIN, &mmc_base->con);
Dirk Behmeb1c3bf92008-12-14 09:47:17 +0100350 return 1;
351}
352
353unsigned char mmc_read_cardsize(mmc_card_data *mmc_dev_data,
354 mmc_csd_reg_t *cur_csd)
355{
356 mmc_extended_csd_reg_t ext_csd;
357 unsigned int size, count, blk_len, blk_no, card_size, argument;
358 unsigned char err;
359 unsigned int resp[4];
360
361 if (mmc_dev_data->mode == SECTOR_MODE) {
362 if (mmc_dev_data->card_type == SD_CARD) {
363 card_size =
364 (((mmc_sd2_csd_reg_t *) cur_csd)->
365 c_size_lsb & MMC_SD2_CSD_C_SIZE_LSB_MASK) |
366 ((((mmc_sd2_csd_reg_t *) cur_csd)->
367 c_size_msb & MMC_SD2_CSD_C_SIZE_MSB_MASK)
368 << MMC_SD2_CSD_C_SIZE_MSB_OFFSET);
369 mmc_dev_data->size = card_size * 1024;
370 if (mmc_dev_data->size == 0)
371 return 0;
372 } else {
373 argument = 0x00000000;
374 err = mmc_send_cmd(MMC_CMD8, argument, resp);
375 if (err != 1)
376 return err;
377 err = mmc_read_data((unsigned int *) &ext_csd);
378 if (err != 1)
379 return err;
380 mmc_dev_data->size = ext_csd.sectorcount;
381
382 if (mmc_dev_data->size == 0)
383 mmc_dev_data->size = 8388608;
384 }
385 } else {
386 if (cur_csd->c_size_mult >= 8)
387 return 0;
388
389 if (cur_csd->read_bl_len >= 12)
390 return 0;
391
392 /* Compute size */
393 count = 1 << (cur_csd->c_size_mult + 2);
394 card_size = (cur_csd->c_size_lsb & MMC_CSD_C_SIZE_LSB_MASK) |
395 ((cur_csd->c_size_msb & MMC_CSD_C_SIZE_MSB_MASK)
396 << MMC_CSD_C_SIZE_MSB_OFFSET);
397 blk_no = (card_size + 1) * count;
398 blk_len = 1 << cur_csd->read_bl_len;
399 size = blk_no * blk_len;
400 mmc_dev_data->size = size / MMCSD_SECTOR_SIZE;
401 if (mmc_dev_data->size == 0)
402 return 0;
403 }
404 return 1;
405}
406
407unsigned char omap_mmc_read_sect(unsigned int start_sec, unsigned int num_bytes,
408 mmc_card_data *mmc_c,
409 unsigned long *output_buf)
410{
411 unsigned char err;
412 unsigned int argument;
413 unsigned int resp[4];
414 unsigned int num_sec_val =
415 (num_bytes + (MMCSD_SECTOR_SIZE - 1)) / MMCSD_SECTOR_SIZE;
416 unsigned int sec_inc_val;
417
418 if (num_sec_val == 0)
419 return 1;
420
421 if (mmc_c->mode == SECTOR_MODE) {
422 argument = start_sec;
423 sec_inc_val = 1;
424 } else {
425 argument = start_sec * MMCSD_SECTOR_SIZE;
426 sec_inc_val = MMCSD_SECTOR_SIZE;
427 }
428
429 while (num_sec_val) {
430 err = mmc_send_cmd(MMC_CMD17, argument, resp);
431 if (err != 1)
432 return err;
433
434 err = mmc_read_data((unsigned int *) output_buf);
435 if (err != 1)
436 return err;
437
438 output_buf += (MMCSD_SECTOR_SIZE / 4);
439 argument += sec_inc_val;
440 num_sec_val--;
441 }
442 return 1;
443}
444
445unsigned char configure_mmc(mmc_card_data *mmc_card_cur)
446{
447 unsigned char ret_val;
448 unsigned int argument;
449 unsigned int resp[4];
450 unsigned int trans_clk, trans_fact, trans_unit, retries = 2;
451 mmc_csd_reg_t Card_CSD;
452 unsigned char trans_speed;
453
454 ret_val = mmc_init_setup();
455
456 if (ret_val != 1)
457 return ret_val;
458
459 do {
460 ret_val = mmc_detect_card(mmc_card_cur);
461 retries--;
462 } while ((retries > 0) && (ret_val != 1));
463
464 argument = mmc_card_cur->RCA << 16;
465 ret_val = mmc_send_cmd(MMC_CMD9, argument, resp);
466 if (ret_val != 1)
467 return ret_val;
468
469 ((unsigned int *) &Card_CSD)[3] = resp[3];
470 ((unsigned int *) &Card_CSD)[2] = resp[2];
471 ((unsigned int *) &Card_CSD)[1] = resp[1];
472 ((unsigned int *) &Card_CSD)[0] = resp[0];
473
474 if (mmc_card_cur->card_type == MMC_CARD)
475 mmc_card_cur->version = Card_CSD.spec_vers;
476
477 trans_speed = Card_CSD.tran_speed;
478
479 ret_val = mmc_send_cmd(MMC_CMD4, MMC_DSR_DEFAULT << 16, resp);
480 if (ret_val != 1)
481 return ret_val;
482
483 trans_unit = trans_speed & MMC_CSD_TRAN_SPEED_UNIT_MASK;
484 trans_fact = trans_speed & MMC_CSD_TRAN_SPEED_FACTOR_MASK;
485
486 if (trans_unit > MMC_CSD_TRAN_SPEED_UNIT_100MHZ)
487 return 0;
488
489 if ((trans_fact < MMC_CSD_TRAN_SPEED_FACTOR_1_0) ||
490 (trans_fact > MMC_CSD_TRAN_SPEED_FACTOR_8_0))
491 return 0;
492
493 trans_unit >>= 0;
494 trans_fact >>= 3;
495
496 trans_clk = mmc_transspeed_val[trans_fact - 1][trans_unit] * 2;
497 ret_val = mmc_clock_config(CLK_MISC, trans_clk);
498
499 if (ret_val != 1)
500 return ret_val;
501
502 argument = mmc_card_cur->RCA << 16;
503 ret_val = mmc_send_cmd(MMC_CMD7_SELECT, argument, resp);
504 if (ret_val != 1)
505 return ret_val;
506
507 /* Configure the block length to 512 bytes */
508 argument = MMCSD_SECTOR_SIZE;
509 ret_val = mmc_send_cmd(MMC_CMD16, argument, resp);
510 if (ret_val != 1)
511 return ret_val;
512
513 /* get the card size in sectors */
514 ret_val = mmc_read_cardsize(mmc_card_cur, &Card_CSD);
515 if (ret_val != 1)
516 return ret_val;
517
518 return 1;
519}
520unsigned long mmc_bread(int dev_num, unsigned long blknr, lbaint_t blkcnt,
521 void *dst)
522{
523 omap_mmc_read_sect(blknr, (blkcnt * MMCSD_SECTOR_SIZE), &cur_card_data,
Dirk Behmeaba45c82009-02-20 17:51:28 +0100524 (unsigned long *) dst);
Dirk Behmeb1c3bf92008-12-14 09:47:17 +0100525 return 1;
526}
527
Tom Rixe5e88c32009-02-19 16:45:43 -0600528int mmc_legacy_init(int verbose)
Dirk Behmeb1c3bf92008-12-14 09:47:17 +0100529{
530 if (configure_mmc(&cur_card_data) != 1)
531 return 1;
532
533 mmc_blk_dev.if_type = IF_TYPE_MMC;
534 mmc_blk_dev.part_type = PART_TYPE_DOS;
535 mmc_blk_dev.dev = 0;
536 mmc_blk_dev.lun = 0;
537 mmc_blk_dev.type = 0;
538
539 /* FIXME fill in the correct size (is set to 32MByte) */
540 mmc_blk_dev.blksz = MMCSD_SECTOR_SIZE;
541 mmc_blk_dev.lba = 0x10000;
542 mmc_blk_dev.removable = 0;
543 mmc_blk_dev.block_read = mmc_bread;
544
545 fat_register_device(&mmc_blk_dev, 1);
546 return 0;
547}