blob: 9e09434c10f550e1c0de064c45d3a07e50baf05a [file] [log] [blame]
Dirk Behme9721eda2008-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>
Tom Rix247e3c22009-06-28 12:52:31 -050031#include <twl4030.h>
Dirk Behmeddd99a12009-02-20 17:51:28 +010032#include <asm/io.h>
Tom Rix140000f2009-02-19 16:45:43 -060033#include <asm/arch/mmc.h>
Dirk Behme9721eda2008-12-14 09:47:17 +010034
35const unsigned short mmc_transspeed_val[15][4] = {
36 {CLKD(10, 1), CLKD(10, 10), CLKD(10, 100), CLKD(10, 1000)},
37 {CLKD(12, 1), CLKD(12, 10), CLKD(12, 100), CLKD(12, 1000)},
38 {CLKD(13, 1), CLKD(13, 10), CLKD(13, 100), CLKD(13, 1000)},
39 {CLKD(15, 1), CLKD(15, 10), CLKD(15, 100), CLKD(15, 1000)},
40 {CLKD(20, 1), CLKD(20, 10), CLKD(20, 100), CLKD(20, 1000)},
41 {CLKD(26, 1), CLKD(26, 10), CLKD(26, 100), CLKD(26, 1000)},
42 {CLKD(30, 1), CLKD(30, 10), CLKD(30, 100), CLKD(30, 1000)},
43 {CLKD(35, 1), CLKD(35, 10), CLKD(35, 100), CLKD(35, 1000)},
44 {CLKD(40, 1), CLKD(40, 10), CLKD(40, 100), CLKD(40, 1000)},
45 {CLKD(45, 1), CLKD(45, 10), CLKD(45, 100), CLKD(45, 1000)},
46 {CLKD(52, 1), CLKD(52, 10), CLKD(52, 100), CLKD(52, 1000)},
47 {CLKD(55, 1), CLKD(55, 10), CLKD(55, 100), CLKD(55, 1000)},
48 {CLKD(60, 1), CLKD(60, 10), CLKD(60, 100), CLKD(60, 1000)},
49 {CLKD(70, 1), CLKD(70, 10), CLKD(70, 100), CLKD(70, 1000)},
50 {CLKD(80, 1), CLKD(80, 10), CLKD(80, 100), CLKD(80, 1000)}
51};
52
53mmc_card_data cur_card_data;
54static block_dev_desc_t mmc_blk_dev;
Dirk Behmeddd99a12009-02-20 17:51:28 +010055static hsmmc_t *mmc_base = (hsmmc_t *)OMAP_HSMMC_BASE;
Dirk Behme9721eda2008-12-14 09:47:17 +010056
57block_dev_desc_t *mmc_get_dev(int dev)
58{
59 return (block_dev_desc_t *) &mmc_blk_dev;
60}
61
Dirk Behme9721eda2008-12-14 09:47:17 +010062unsigned char mmc_board_init(void)
63{
Dirk Behmeddd99a12009-02-20 17:51:28 +010064 t2_t *t2_base = (t2_t *)T2_BASE;
Dirk Behme9721eda2008-12-14 09:47:17 +010065
Tom Rix247e3c22009-06-28 12:52:31 -050066 twl4030_power_mmc_init();
Dirk Behme9721eda2008-12-14 09:47:17 +010067
Dirk Behmeddd99a12009-02-20 17:51:28 +010068 writel(readl(&t2_base->pbias_lite) | PBIASLITEPWRDNZ1 |
69 PBIASSPEEDCTRL0 | PBIASLITEPWRDNZ0,
70 &t2_base->pbias_lite);
Dirk Behme9721eda2008-12-14 09:47:17 +010071
Dirk Behmeddd99a12009-02-20 17:51:28 +010072 writel(readl(&t2_base->devconf0) | MMCSDIO1ADPCLKISEL,
73 &t2_base->devconf0);
Dirk Behme9721eda2008-12-14 09:47:17 +010074
75 return 1;
76}
77
78void mmc_init_stream(void)
79{
Dirk Behmeddd99a12009-02-20 17:51:28 +010080 writel(readl(&mmc_base->con) | INIT_INITSTREAM, &mmc_base->con);
Dirk Behme9721eda2008-12-14 09:47:17 +010081
Dirk Behmeddd99a12009-02-20 17:51:28 +010082 writel(MMC_CMD0, &mmc_base->cmd);
83 while (!(readl(&mmc_base->stat) & CC_MASK));
Dirk Behme9721eda2008-12-14 09:47:17 +010084
Dirk Behmeddd99a12009-02-20 17:51:28 +010085 writel(CC_MASK, &mmc_base->stat);
Dirk Behme9721eda2008-12-14 09:47:17 +010086
Dirk Behmeddd99a12009-02-20 17:51:28 +010087 writel(MMC_CMD0, &mmc_base->cmd);
88 while (!(readl(&mmc_base->stat) & CC_MASK));
Dirk Behme9721eda2008-12-14 09:47:17 +010089
Dirk Behmeddd99a12009-02-20 17:51:28 +010090 writel(readl(&mmc_base->con) & ~INIT_INITSTREAM, &mmc_base->con);
Dirk Behme9721eda2008-12-14 09:47:17 +010091}
92
93unsigned char mmc_clock_config(unsigned int iclk, unsigned short clk_div)
94{
95 unsigned int val;
96
Dirk Behmeddd99a12009-02-20 17:51:28 +010097 mmc_reg_out(&mmc_base->sysctl, (ICE_MASK | DTO_MASK | CEN_MASK),
98 (ICE_STOP | DTO_15THDTO | CEN_DISABLE));
Dirk Behme9721eda2008-12-14 09:47:17 +010099
100 switch (iclk) {
101 case CLK_INITSEQ:
102 val = MMC_INIT_SEQ_CLK / 2;
103 break;
104 case CLK_400KHZ:
105 val = MMC_400kHz_CLK;
106 break;
107 case CLK_MISC:
108 val = clk_div;
109 break;
110 default:
111 return 0;
112 }
Dirk Behmeddd99a12009-02-20 17:51:28 +0100113 mmc_reg_out(&mmc_base->sysctl, ICE_MASK | CLKD_MASK,
114 (val << CLKD_OFFSET) | ICE_OSCILLATE);
Dirk Behme9721eda2008-12-14 09:47:17 +0100115
Dirk Behmeddd99a12009-02-20 17:51:28 +0100116 while ((readl(&mmc_base->sysctl) & ICS_MASK) == ICS_NOTREADY);
Dirk Behme9721eda2008-12-14 09:47:17 +0100117
Dirk Behmeddd99a12009-02-20 17:51:28 +0100118 writel(readl(&mmc_base->sysctl) | CEN_ENABLE, &mmc_base->sysctl);
Dirk Behme9721eda2008-12-14 09:47:17 +0100119 return 1;
120}
121
122unsigned char mmc_init_setup(void)
123{
124 unsigned int reg_val;
125
126 mmc_board_init();
127
Dirk Behmeddd99a12009-02-20 17:51:28 +0100128 writel(readl(&mmc_base->sysconfig) | MMC_SOFTRESET,
129 &mmc_base->sysconfig);
130 while ((readl(&mmc_base->sysstatus) & RESETDONE) == 0);
Dirk Behme9721eda2008-12-14 09:47:17 +0100131
Dirk Behmeddd99a12009-02-20 17:51:28 +0100132 writel(readl(&mmc_base->sysctl) | SOFTRESETALL, &mmc_base->sysctl);
133 while ((readl(&mmc_base->sysctl) & SOFTRESETALL) != 0x0);
Dirk Behme9721eda2008-12-14 09:47:17 +0100134
Dirk Behmeddd99a12009-02-20 17:51:28 +0100135 writel(DTW_1_BITMODE | SDBP_PWROFF | SDVS_3V0, &mmc_base->hctl);
136 writel(readl(&mmc_base->capa) | VS30_3V0SUP | VS18_1V8SUP,
137 &mmc_base->capa);
Dirk Behme9721eda2008-12-14 09:47:17 +0100138
Dirk Behmeddd99a12009-02-20 17:51:28 +0100139 reg_val = readl(&mmc_base->con) & RESERVED_MASK;
Dirk Behme9721eda2008-12-14 09:47:17 +0100140
Dirk Behmeddd99a12009-02-20 17:51:28 +0100141 writel(CTPL_MMC_SD | reg_val | WPP_ACTIVEHIGH | CDP_ACTIVEHIGH |
142 MIT_CTO | DW8_1_4BITMODE | MODE_FUNC | STR_BLOCK |
143 HR_NOHOSTRESP | INIT_NOINIT | NOOPENDRAIN, &mmc_base->con);
Dirk Behme9721eda2008-12-14 09:47:17 +0100144
145 mmc_clock_config(CLK_INITSEQ, 0);
Dirk Behmeddd99a12009-02-20 17:51:28 +0100146 writel(readl(&mmc_base->hctl) | SDBP_PWRON, &mmc_base->hctl);
Dirk Behme9721eda2008-12-14 09:47:17 +0100147
Dirk Behmeddd99a12009-02-20 17:51:28 +0100148 writel(IE_BADA | IE_CERR | IE_DEB | IE_DCRC | IE_DTO | IE_CIE |
149 IE_CEB | IE_CCRC | IE_CTO | IE_BRR | IE_BWR | IE_TC | IE_CC,
150 &mmc_base->ie);
Dirk Behme9721eda2008-12-14 09:47:17 +0100151
152 mmc_init_stream();
153 return 1;
154}
155
156unsigned char mmc_send_cmd(unsigned int cmd, unsigned int arg,
Dirk Behmeddd99a12009-02-20 17:51:28 +0100157 unsigned int *response)
Dirk Behme9721eda2008-12-14 09:47:17 +0100158{
Dirk Behmeddd99a12009-02-20 17:51:28 +0100159 unsigned int mmc_stat;
Dirk Behme9721eda2008-12-14 09:47:17 +0100160
Dirk Behmeddd99a12009-02-20 17:51:28 +0100161 while ((readl(&mmc_base->pstate) & DATI_MASK) == DATI_CMDDIS);
Dirk Behme9721eda2008-12-14 09:47:17 +0100162
Dirk Behmeddd99a12009-02-20 17:51:28 +0100163 writel(BLEN_512BYTESLEN | NBLK_STPCNT, &mmc_base->blk);
164 writel(0xFFFFFFFF, &mmc_base->stat);
165 writel(arg, &mmc_base->arg);
166 writel(cmd | CMD_TYPE_NORMAL | CICE_NOCHECK | CCCE_NOCHECK |
167 MSBS_SGLEBLK | ACEN_DISABLE | BCE_DISABLE | DE_DISABLE,
168 &mmc_base->cmd);
Dirk Behme9721eda2008-12-14 09:47:17 +0100169
170 while (1) {
171 do {
Dirk Behmeddd99a12009-02-20 17:51:28 +0100172 mmc_stat = readl(&mmc_base->stat);
Dirk Behme9721eda2008-12-14 09:47:17 +0100173 } while (mmc_stat == 0);
174
175 if ((mmc_stat & ERRI_MASK) != 0)
176 return (unsigned char) mmc_stat;
177
178 if (mmc_stat & CC_MASK) {
Dirk Behmeddd99a12009-02-20 17:51:28 +0100179 writel(CC_MASK, &mmc_base->stat);
180 response[0] = readl(&mmc_base->rsp10);
Dirk Behme9721eda2008-12-14 09:47:17 +0100181 if ((cmd & RSP_TYPE_MASK) == RSP_TYPE_LGHT136) {
Dirk Behmeddd99a12009-02-20 17:51:28 +0100182 response[1] = readl(&mmc_base->rsp32);
183 response[2] = readl(&mmc_base->rsp54);
184 response[3] = readl(&mmc_base->rsp76);
Dirk Behme9721eda2008-12-14 09:47:17 +0100185 }
186 break;
187 }
188 }
189 return 1;
190}
191
192unsigned char mmc_read_data(unsigned int *output_buf)
193{
Dirk Behmeddd99a12009-02-20 17:51:28 +0100194 unsigned int mmc_stat;
Dirk Behme9721eda2008-12-14 09:47:17 +0100195 unsigned int read_count = 0;
196
197 /*
198 * Start Polled Read
199 */
200 while (1) {
201 do {
Dirk Behmeddd99a12009-02-20 17:51:28 +0100202 mmc_stat = readl(&mmc_base->stat);
Dirk Behme9721eda2008-12-14 09:47:17 +0100203 } while (mmc_stat == 0);
204
205 if ((mmc_stat & ERRI_MASK) != 0)
206 return (unsigned char) mmc_stat;
207
208 if (mmc_stat & BRR_MASK) {
209 unsigned int k;
210
Dirk Behmeddd99a12009-02-20 17:51:28 +0100211 writel(readl(&mmc_base->stat) | BRR_MASK,
212 &mmc_base->stat);
Dirk Behme9721eda2008-12-14 09:47:17 +0100213 for (k = 0; k < MMCSD_SECTOR_SIZE / 4; k++) {
Dirk Behmeddd99a12009-02-20 17:51:28 +0100214 *output_buf = readl(&mmc_base->data);
Dirk Behme9721eda2008-12-14 09:47:17 +0100215 output_buf++;
216 read_count += 4;
217 }
218 }
219
220 if (mmc_stat & BWR_MASK)
Dirk Behmeddd99a12009-02-20 17:51:28 +0100221 writel(readl(&mmc_base->stat) | BWR_MASK,
222 &mmc_base->stat);
Dirk Behme9721eda2008-12-14 09:47:17 +0100223
224 if (mmc_stat & TC_MASK) {
Dirk Behmeddd99a12009-02-20 17:51:28 +0100225 writel(readl(&mmc_base->stat) | TC_MASK,
226 &mmc_base->stat);
Dirk Behme9721eda2008-12-14 09:47:17 +0100227 break;
228 }
229 }
230 return 1;
231}
232
233unsigned char mmc_detect_card(mmc_card_data *mmc_card_cur)
234{
235 unsigned char err;
236 unsigned int argument = 0;
237 unsigned int ocr_value, ocr_recvd, ret_cmd41, hcs_val;
238 unsigned int resp[4];
239 unsigned short retry_cnt = 2000;
240
241 /* Set to Initialization Clock */
242 err = mmc_clock_config(CLK_400KHZ, 0);
243 if (err != 1)
244 return err;
245
246 mmc_card_cur->RCA = MMC_RELATIVE_CARD_ADDRESS;
247 argument = 0x00000000;
248
249 ocr_value = (0x1FF << 15);
250 err = mmc_send_cmd(MMC_CMD0, argument, resp);
251 if (err != 1)
252 return err;
253
254 argument = SD_CMD8_CHECK_PATTERN | SD_CMD8_2_7_3_6_V_RANGE;
255 err = mmc_send_cmd(MMC_SDCMD8, argument, resp);
256 hcs_val = (err == 1) ?
257 MMC_OCR_REG_HOST_CAPACITY_SUPPORT_SECTOR :
258 MMC_OCR_REG_HOST_CAPACITY_SUPPORT_BYTE;
259
260 argument = 0x0000 << 16;
261 err = mmc_send_cmd(MMC_CMD55, argument, resp);
262 if (err == 1) {
263 mmc_card_cur->card_type = SD_CARD;
264 ocr_value |= hcs_val;
265 ret_cmd41 = MMC_ACMD41;
266 } else {
267 mmc_card_cur->card_type = MMC_CARD;
268 ocr_value |= MMC_OCR_REG_ACCESS_MODE_SECTOR;
269 ret_cmd41 = MMC_CMD1;
Dirk Behmeddd99a12009-02-20 17:51:28 +0100270 writel(readl(&mmc_base->con) & ~OD, &mmc_base->con);
271 writel(readl(&mmc_base->con) | OPENDRAIN, &mmc_base->con);
Dirk Behme9721eda2008-12-14 09:47:17 +0100272 }
273
274 argument = ocr_value;
275 err = mmc_send_cmd(ret_cmd41, argument, resp);
276 if (err != 1)
277 return err;
278
279 ocr_recvd = ((mmc_resp_r3 *) resp)->ocr;
280
281 while (!(ocr_recvd & (0x1 << 31)) && (retry_cnt > 0)) {
282 retry_cnt--;
283 if (mmc_card_cur->card_type == SD_CARD) {
284 argument = 0x0000 << 16;
285 err = mmc_send_cmd(MMC_CMD55, argument, resp);
286 }
287
288 argument = ocr_value;
289 err = mmc_send_cmd(ret_cmd41, argument, resp);
290 if (err != 1)
291 return err;
292 ocr_recvd = ((mmc_resp_r3 *) resp)->ocr;
293 }
294
295 if (!(ocr_recvd & (0x1 << 31)))
296 return 0;
297
298 if (mmc_card_cur->card_type == MMC_CARD) {
299 if ((ocr_recvd & MMC_OCR_REG_ACCESS_MODE_MASK) ==
300 MMC_OCR_REG_ACCESS_MODE_SECTOR) {
301 mmc_card_cur->mode = SECTOR_MODE;
302 } else {
303 mmc_card_cur->mode = BYTE_MODE;
304 }
305
306 ocr_recvd &= ~MMC_OCR_REG_ACCESS_MODE_MASK;
307 } else {
308 if ((ocr_recvd & MMC_OCR_REG_HOST_CAPACITY_SUPPORT_MASK)
309 == MMC_OCR_REG_HOST_CAPACITY_SUPPORT_SECTOR) {
310 mmc_card_cur->mode = SECTOR_MODE;
311 } else {
312 mmc_card_cur->mode = BYTE_MODE;
313 }
314 ocr_recvd &= ~MMC_OCR_REG_HOST_CAPACITY_SUPPORT_MASK;
315 }
316
317 ocr_recvd &= ~(0x1 << 31);
318 if (!(ocr_recvd & ocr_value))
319 return 0;
320
321 err = mmc_send_cmd(MMC_CMD2, argument, resp);
322 if (err != 1)
323 return err;
324
325 if (mmc_card_cur->card_type == MMC_CARD) {
326 argument = mmc_card_cur->RCA << 16;
327 err = mmc_send_cmd(MMC_CMD3, argument, resp);
328 if (err != 1)
329 return err;
330 } else {
331 argument = 0x00000000;
332 err = mmc_send_cmd(MMC_SDCMD3, argument, resp);
333 if (err != 1)
334 return err;
335
336 mmc_card_cur->RCA = ((mmc_resp_r6 *) resp)->newpublishedrca;
337 }
338
Dirk Behmeddd99a12009-02-20 17:51:28 +0100339 writel(readl(&mmc_base->con) & ~OD, &mmc_base->con);
340 writel(readl(&mmc_base->con) | NOOPENDRAIN, &mmc_base->con);
Dirk Behme9721eda2008-12-14 09:47:17 +0100341 return 1;
342}
343
344unsigned char mmc_read_cardsize(mmc_card_data *mmc_dev_data,
345 mmc_csd_reg_t *cur_csd)
346{
347 mmc_extended_csd_reg_t ext_csd;
348 unsigned int size, count, blk_len, blk_no, card_size, argument;
349 unsigned char err;
350 unsigned int resp[4];
351
352 if (mmc_dev_data->mode == SECTOR_MODE) {
353 if (mmc_dev_data->card_type == SD_CARD) {
354 card_size =
355 (((mmc_sd2_csd_reg_t *) cur_csd)->
356 c_size_lsb & MMC_SD2_CSD_C_SIZE_LSB_MASK) |
357 ((((mmc_sd2_csd_reg_t *) cur_csd)->
358 c_size_msb & MMC_SD2_CSD_C_SIZE_MSB_MASK)
359 << MMC_SD2_CSD_C_SIZE_MSB_OFFSET);
360 mmc_dev_data->size = card_size * 1024;
361 if (mmc_dev_data->size == 0)
362 return 0;
363 } else {
364 argument = 0x00000000;
365 err = mmc_send_cmd(MMC_CMD8, argument, resp);
366 if (err != 1)
367 return err;
368 err = mmc_read_data((unsigned int *) &ext_csd);
369 if (err != 1)
370 return err;
371 mmc_dev_data->size = ext_csd.sectorcount;
372
373 if (mmc_dev_data->size == 0)
374 mmc_dev_data->size = 8388608;
375 }
376 } else {
377 if (cur_csd->c_size_mult >= 8)
378 return 0;
379
380 if (cur_csd->read_bl_len >= 12)
381 return 0;
382
383 /* Compute size */
384 count = 1 << (cur_csd->c_size_mult + 2);
385 card_size = (cur_csd->c_size_lsb & MMC_CSD_C_SIZE_LSB_MASK) |
386 ((cur_csd->c_size_msb & MMC_CSD_C_SIZE_MSB_MASK)
387 << MMC_CSD_C_SIZE_MSB_OFFSET);
388 blk_no = (card_size + 1) * count;
389 blk_len = 1 << cur_csd->read_bl_len;
390 size = blk_no * blk_len;
391 mmc_dev_data->size = size / MMCSD_SECTOR_SIZE;
392 if (mmc_dev_data->size == 0)
393 return 0;
394 }
395 return 1;
396}
397
398unsigned char omap_mmc_read_sect(unsigned int start_sec, unsigned int num_bytes,
399 mmc_card_data *mmc_c,
400 unsigned long *output_buf)
401{
402 unsigned char err;
403 unsigned int argument;
404 unsigned int resp[4];
405 unsigned int num_sec_val =
406 (num_bytes + (MMCSD_SECTOR_SIZE - 1)) / MMCSD_SECTOR_SIZE;
407 unsigned int sec_inc_val;
408
409 if (num_sec_val == 0)
410 return 1;
411
412 if (mmc_c->mode == SECTOR_MODE) {
413 argument = start_sec;
414 sec_inc_val = 1;
415 } else {
416 argument = start_sec * MMCSD_SECTOR_SIZE;
417 sec_inc_val = MMCSD_SECTOR_SIZE;
418 }
419
420 while (num_sec_val) {
421 err = mmc_send_cmd(MMC_CMD17, argument, resp);
422 if (err != 1)
423 return err;
424
425 err = mmc_read_data((unsigned int *) output_buf);
426 if (err != 1)
427 return err;
428
429 output_buf += (MMCSD_SECTOR_SIZE / 4);
430 argument += sec_inc_val;
431 num_sec_val--;
432 }
433 return 1;
434}
435
436unsigned char configure_mmc(mmc_card_data *mmc_card_cur)
437{
438 unsigned char ret_val;
439 unsigned int argument;
440 unsigned int resp[4];
441 unsigned int trans_clk, trans_fact, trans_unit, retries = 2;
442 mmc_csd_reg_t Card_CSD;
443 unsigned char trans_speed;
444
445 ret_val = mmc_init_setup();
446
447 if (ret_val != 1)
448 return ret_val;
449
450 do {
451 ret_val = mmc_detect_card(mmc_card_cur);
452 retries--;
453 } while ((retries > 0) && (ret_val != 1));
454
455 argument = mmc_card_cur->RCA << 16;
456 ret_val = mmc_send_cmd(MMC_CMD9, argument, resp);
457 if (ret_val != 1)
458 return ret_val;
459
460 ((unsigned int *) &Card_CSD)[3] = resp[3];
461 ((unsigned int *) &Card_CSD)[2] = resp[2];
462 ((unsigned int *) &Card_CSD)[1] = resp[1];
463 ((unsigned int *) &Card_CSD)[0] = resp[0];
464
465 if (mmc_card_cur->card_type == MMC_CARD)
466 mmc_card_cur->version = Card_CSD.spec_vers;
467
468 trans_speed = Card_CSD.tran_speed;
469
470 ret_val = mmc_send_cmd(MMC_CMD4, MMC_DSR_DEFAULT << 16, resp);
471 if (ret_val != 1)
472 return ret_val;
473
474 trans_unit = trans_speed & MMC_CSD_TRAN_SPEED_UNIT_MASK;
475 trans_fact = trans_speed & MMC_CSD_TRAN_SPEED_FACTOR_MASK;
476
477 if (trans_unit > MMC_CSD_TRAN_SPEED_UNIT_100MHZ)
478 return 0;
479
480 if ((trans_fact < MMC_CSD_TRAN_SPEED_FACTOR_1_0) ||
481 (trans_fact > MMC_CSD_TRAN_SPEED_FACTOR_8_0))
482 return 0;
483
484 trans_unit >>= 0;
485 trans_fact >>= 3;
486
487 trans_clk = mmc_transspeed_val[trans_fact - 1][trans_unit] * 2;
488 ret_val = mmc_clock_config(CLK_MISC, trans_clk);
489
490 if (ret_val != 1)
491 return ret_val;
492
493 argument = mmc_card_cur->RCA << 16;
494 ret_val = mmc_send_cmd(MMC_CMD7_SELECT, argument, resp);
495 if (ret_val != 1)
496 return ret_val;
497
498 /* Configure the block length to 512 bytes */
499 argument = MMCSD_SECTOR_SIZE;
500 ret_val = mmc_send_cmd(MMC_CMD16, argument, resp);
501 if (ret_val != 1)
502 return ret_val;
503
504 /* get the card size in sectors */
505 ret_val = mmc_read_cardsize(mmc_card_cur, &Card_CSD);
506 if (ret_val != 1)
507 return ret_val;
508
509 return 1;
510}
511unsigned long mmc_bread(int dev_num, unsigned long blknr, lbaint_t blkcnt,
512 void *dst)
513{
514 omap_mmc_read_sect(blknr, (blkcnt * MMCSD_SECTOR_SIZE), &cur_card_data,
Dirk Behmeddd99a12009-02-20 17:51:28 +0100515 (unsigned long *) dst);
Dirk Behme9721eda2008-12-14 09:47:17 +0100516 return 1;
517}
518
Tom Rix140000f2009-02-19 16:45:43 -0600519int mmc_legacy_init(int verbose)
Dirk Behme9721eda2008-12-14 09:47:17 +0100520{
521 if (configure_mmc(&cur_card_data) != 1)
522 return 1;
523
524 mmc_blk_dev.if_type = IF_TYPE_MMC;
525 mmc_blk_dev.part_type = PART_TYPE_DOS;
526 mmc_blk_dev.dev = 0;
527 mmc_blk_dev.lun = 0;
528 mmc_blk_dev.type = 0;
529
530 /* FIXME fill in the correct size (is set to 32MByte) */
531 mmc_blk_dev.blksz = MMCSD_SECTOR_SIZE;
532 mmc_blk_dev.lba = 0x10000;
533 mmc_blk_dev.removable = 0;
534 mmc_blk_dev.block_read = mmc_bread;
535
536 fat_register_device(&mmc_blk_dev, 1);
537 return 0;
538}