Dirk Behme | 9721eda | 2008-12-14 09:47:17 +0100 | [diff] [blame] | 1 | /* |
| 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> |
| 31 | |
| 32 | const unsigned short mmc_transspeed_val[15][4] = { |
| 33 | {CLKD(10, 1), CLKD(10, 10), CLKD(10, 100), CLKD(10, 1000)}, |
| 34 | {CLKD(12, 1), CLKD(12, 10), CLKD(12, 100), CLKD(12, 1000)}, |
| 35 | {CLKD(13, 1), CLKD(13, 10), CLKD(13, 100), CLKD(13, 1000)}, |
| 36 | {CLKD(15, 1), CLKD(15, 10), CLKD(15, 100), CLKD(15, 1000)}, |
| 37 | {CLKD(20, 1), CLKD(20, 10), CLKD(20, 100), CLKD(20, 1000)}, |
| 38 | {CLKD(26, 1), CLKD(26, 10), CLKD(26, 100), CLKD(26, 1000)}, |
| 39 | {CLKD(30, 1), CLKD(30, 10), CLKD(30, 100), CLKD(30, 1000)}, |
| 40 | {CLKD(35, 1), CLKD(35, 10), CLKD(35, 100), CLKD(35, 1000)}, |
| 41 | {CLKD(40, 1), CLKD(40, 10), CLKD(40, 100), CLKD(40, 1000)}, |
| 42 | {CLKD(45, 1), CLKD(45, 10), CLKD(45, 100), CLKD(45, 1000)}, |
| 43 | {CLKD(52, 1), CLKD(52, 10), CLKD(52, 100), CLKD(52, 1000)}, |
| 44 | {CLKD(55, 1), CLKD(55, 10), CLKD(55, 100), CLKD(55, 1000)}, |
| 45 | {CLKD(60, 1), CLKD(60, 10), CLKD(60, 100), CLKD(60, 1000)}, |
| 46 | {CLKD(70, 1), CLKD(70, 10), CLKD(70, 100), CLKD(70, 1000)}, |
| 47 | {CLKD(80, 1), CLKD(80, 10), CLKD(80, 100), CLKD(80, 1000)} |
| 48 | }; |
| 49 | |
| 50 | mmc_card_data cur_card_data; |
| 51 | static block_dev_desc_t mmc_blk_dev; |
| 52 | |
| 53 | block_dev_desc_t *mmc_get_dev(int dev) |
| 54 | { |
| 55 | return (block_dev_desc_t *) &mmc_blk_dev; |
| 56 | } |
| 57 | |
| 58 | void twl4030_mmc_config(void) |
| 59 | { |
| 60 | unsigned char data; |
| 61 | |
| 62 | data = 0x20; |
| 63 | i2c_write(0x4B, 0x82, 1, &data, 1); |
| 64 | data = 0x2; |
| 65 | i2c_write(0x4B, 0x85, 1, &data, 1); |
| 66 | } |
| 67 | |
| 68 | unsigned char mmc_board_init(void) |
| 69 | { |
| 70 | unsigned int value = 0; |
| 71 | |
| 72 | twl4030_mmc_config(); |
| 73 | |
| 74 | value = CONTROL_PBIAS_LITE; |
| 75 | CONTROL_PBIAS_LITE = value | (1 << 2) | (1 << 1) | (1 << 9); |
| 76 | |
| 77 | value = CONTROL_DEV_CONF0; |
| 78 | CONTROL_DEV_CONF0 = value | (1 << 24); |
| 79 | |
| 80 | return 1; |
| 81 | } |
| 82 | |
| 83 | void mmc_init_stream(void) |
| 84 | { |
| 85 | volatile unsigned int mmc_stat; |
| 86 | |
| 87 | OMAP_HSMMC_CON |= INIT_INITSTREAM; |
| 88 | |
| 89 | OMAP_HSMMC_CMD = MMC_CMD0; |
| 90 | do { |
| 91 | mmc_stat = OMAP_HSMMC_STAT; |
| 92 | } while (!(mmc_stat & CC_MASK)); |
| 93 | |
| 94 | OMAP_HSMMC_STAT = CC_MASK; |
| 95 | |
| 96 | OMAP_HSMMC_CMD = MMC_CMD0; |
| 97 | do { |
| 98 | mmc_stat = OMAP_HSMMC_STAT; |
| 99 | } while (!(mmc_stat & CC_MASK)); |
| 100 | |
| 101 | OMAP_HSMMC_STAT = OMAP_HSMMC_STAT; |
| 102 | OMAP_HSMMC_CON &= ~INIT_INITSTREAM; |
| 103 | } |
| 104 | |
| 105 | unsigned char mmc_clock_config(unsigned int iclk, unsigned short clk_div) |
| 106 | { |
| 107 | unsigned int val; |
| 108 | |
| 109 | mmc_reg_out(OMAP_HSMMC_SYSCTL, (ICE_MASK | DTO_MASK | CEN_MASK), |
| 110 | (ICE_STOP | DTO_15THDTO | CEN_DISABLE)); |
| 111 | |
| 112 | switch (iclk) { |
| 113 | case CLK_INITSEQ: |
| 114 | val = MMC_INIT_SEQ_CLK / 2; |
| 115 | break; |
| 116 | case CLK_400KHZ: |
| 117 | val = MMC_400kHz_CLK; |
| 118 | break; |
| 119 | case CLK_MISC: |
| 120 | val = clk_div; |
| 121 | break; |
| 122 | default: |
| 123 | return 0; |
| 124 | } |
| 125 | mmc_reg_out(OMAP_HSMMC_SYSCTL, |
| 126 | ICE_MASK | CLKD_MASK, (val << CLKD_OFFSET) | ICE_OSCILLATE); |
| 127 | |
| 128 | while ((OMAP_HSMMC_SYSCTL & ICS_MASK) == ICS_NOTREADY) ; |
| 129 | |
| 130 | OMAP_HSMMC_SYSCTL |= CEN_ENABLE; |
| 131 | return 1; |
| 132 | } |
| 133 | |
| 134 | unsigned char mmc_init_setup(void) |
| 135 | { |
| 136 | unsigned int reg_val; |
| 137 | |
| 138 | mmc_board_init(); |
| 139 | |
| 140 | OMAP_HSMMC_SYSCONFIG |= MMC_SOFTRESET; |
| 141 | while ((OMAP_HSMMC_SYSSTATUS & RESETDONE) == 0) ; |
| 142 | |
| 143 | OMAP_HSMMC_SYSCTL |= SOFTRESETALL; |
| 144 | while ((OMAP_HSMMC_SYSCTL & SOFTRESETALL) != 0x0) ; |
| 145 | |
| 146 | OMAP_HSMMC_HCTL = DTW_1_BITMODE | SDBP_PWROFF | SDVS_3V0; |
| 147 | OMAP_HSMMC_CAPA |= VS30_3V0SUP | VS18_1V8SUP; |
| 148 | |
| 149 | reg_val = OMAP_HSMMC_CON & RESERVED_MASK; |
| 150 | |
| 151 | OMAP_HSMMC_CON = CTPL_MMC_SD | reg_val | WPP_ACTIVEHIGH | |
| 152 | CDP_ACTIVEHIGH | MIT_CTO | DW8_1_4BITMODE | MODE_FUNC | |
| 153 | STR_BLOCK | HR_NOHOSTRESP | INIT_NOINIT | NOOPENDRAIN; |
| 154 | |
| 155 | mmc_clock_config(CLK_INITSEQ, 0); |
| 156 | OMAP_HSMMC_HCTL |= SDBP_PWRON; |
| 157 | |
| 158 | OMAP_HSMMC_IE = 0x307f0033; |
| 159 | |
| 160 | mmc_init_stream(); |
| 161 | return 1; |
| 162 | } |
| 163 | |
| 164 | unsigned char mmc_send_cmd(unsigned int cmd, unsigned int arg, |
| 165 | unsigned int *response) |
| 166 | { |
| 167 | volatile unsigned int mmc_stat; |
| 168 | |
| 169 | while ((OMAP_HSMMC_PSTATE & DATI_MASK) == DATI_CMDDIS) ; |
| 170 | |
| 171 | OMAP_HSMMC_BLK = BLEN_512BYTESLEN | NBLK_STPCNT; |
| 172 | OMAP_HSMMC_STAT = 0xFFFFFFFF; |
| 173 | OMAP_HSMMC_ARG = arg; |
| 174 | OMAP_HSMMC_CMD = cmd | CMD_TYPE_NORMAL | CICE_NOCHECK | |
| 175 | CCCE_NOCHECK | MSBS_SGLEBLK | ACEN_DISABLE | BCE_DISABLE | |
| 176 | DE_DISABLE; |
| 177 | |
| 178 | while (1) { |
| 179 | do { |
| 180 | mmc_stat = OMAP_HSMMC_STAT; |
| 181 | } while (mmc_stat == 0); |
| 182 | |
| 183 | if ((mmc_stat & ERRI_MASK) != 0) |
| 184 | return (unsigned char) mmc_stat; |
| 185 | |
| 186 | if (mmc_stat & CC_MASK) { |
| 187 | OMAP_HSMMC_STAT = CC_MASK; |
| 188 | response[0] = OMAP_HSMMC_RSP10; |
| 189 | if ((cmd & RSP_TYPE_MASK) == RSP_TYPE_LGHT136) { |
| 190 | response[1] = OMAP_HSMMC_RSP32; |
| 191 | response[2] = OMAP_HSMMC_RSP54; |
| 192 | response[3] = OMAP_HSMMC_RSP76; |
| 193 | } |
| 194 | break; |
| 195 | } |
| 196 | } |
| 197 | return 1; |
| 198 | } |
| 199 | |
| 200 | unsigned char mmc_read_data(unsigned int *output_buf) |
| 201 | { |
| 202 | volatile unsigned int mmc_stat; |
| 203 | unsigned int read_count = 0; |
| 204 | |
| 205 | /* |
| 206 | * Start Polled Read |
| 207 | */ |
| 208 | while (1) { |
| 209 | do { |
| 210 | mmc_stat = OMAP_HSMMC_STAT; |
| 211 | } while (mmc_stat == 0); |
| 212 | |
| 213 | if ((mmc_stat & ERRI_MASK) != 0) |
| 214 | return (unsigned char) mmc_stat; |
| 215 | |
| 216 | if (mmc_stat & BRR_MASK) { |
| 217 | unsigned int k; |
| 218 | |
| 219 | OMAP_HSMMC_STAT |= BRR_MASK; |
| 220 | for (k = 0; k < MMCSD_SECTOR_SIZE / 4; k++) { |
| 221 | *output_buf = OMAP_HSMMC_DATA; |
| 222 | output_buf++; |
| 223 | read_count += 4; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | if (mmc_stat & BWR_MASK) |
| 228 | OMAP_HSMMC_STAT |= BWR_MASK; |
| 229 | |
| 230 | if (mmc_stat & TC_MASK) { |
| 231 | OMAP_HSMMC_STAT |= TC_MASK; |
| 232 | break; |
| 233 | } |
| 234 | } |
| 235 | return 1; |
| 236 | } |
| 237 | |
| 238 | unsigned char mmc_detect_card(mmc_card_data *mmc_card_cur) |
| 239 | { |
| 240 | unsigned char err; |
| 241 | unsigned int argument = 0; |
| 242 | unsigned int ocr_value, ocr_recvd, ret_cmd41, hcs_val; |
| 243 | unsigned int resp[4]; |
| 244 | unsigned short retry_cnt = 2000; |
| 245 | |
| 246 | /* Set to Initialization Clock */ |
| 247 | err = mmc_clock_config(CLK_400KHZ, 0); |
| 248 | if (err != 1) |
| 249 | return err; |
| 250 | |
| 251 | mmc_card_cur->RCA = MMC_RELATIVE_CARD_ADDRESS; |
| 252 | argument = 0x00000000; |
| 253 | |
| 254 | ocr_value = (0x1FF << 15); |
| 255 | err = mmc_send_cmd(MMC_CMD0, argument, resp); |
| 256 | if (err != 1) |
| 257 | return err; |
| 258 | |
| 259 | argument = SD_CMD8_CHECK_PATTERN | SD_CMD8_2_7_3_6_V_RANGE; |
| 260 | err = mmc_send_cmd(MMC_SDCMD8, argument, resp); |
| 261 | hcs_val = (err == 1) ? |
| 262 | MMC_OCR_REG_HOST_CAPACITY_SUPPORT_SECTOR : |
| 263 | MMC_OCR_REG_HOST_CAPACITY_SUPPORT_BYTE; |
| 264 | |
| 265 | argument = 0x0000 << 16; |
| 266 | err = mmc_send_cmd(MMC_CMD55, argument, resp); |
| 267 | if (err == 1) { |
| 268 | mmc_card_cur->card_type = SD_CARD; |
| 269 | ocr_value |= hcs_val; |
| 270 | ret_cmd41 = MMC_ACMD41; |
| 271 | } else { |
| 272 | mmc_card_cur->card_type = MMC_CARD; |
| 273 | ocr_value |= MMC_OCR_REG_ACCESS_MODE_SECTOR; |
| 274 | ret_cmd41 = MMC_CMD1; |
| 275 | OMAP_HSMMC_CON &= ~OD; |
| 276 | OMAP_HSMMC_CON |= OPENDRAIN; |
| 277 | } |
| 278 | |
| 279 | argument = ocr_value; |
| 280 | err = mmc_send_cmd(ret_cmd41, argument, resp); |
| 281 | if (err != 1) |
| 282 | return err; |
| 283 | |
| 284 | ocr_recvd = ((mmc_resp_r3 *) resp)->ocr; |
| 285 | |
| 286 | while (!(ocr_recvd & (0x1 << 31)) && (retry_cnt > 0)) { |
| 287 | retry_cnt--; |
| 288 | if (mmc_card_cur->card_type == SD_CARD) { |
| 289 | argument = 0x0000 << 16; |
| 290 | err = mmc_send_cmd(MMC_CMD55, argument, resp); |
| 291 | } |
| 292 | |
| 293 | argument = ocr_value; |
| 294 | err = mmc_send_cmd(ret_cmd41, argument, resp); |
| 295 | if (err != 1) |
| 296 | return err; |
| 297 | ocr_recvd = ((mmc_resp_r3 *) resp)->ocr; |
| 298 | } |
| 299 | |
| 300 | if (!(ocr_recvd & (0x1 << 31))) |
| 301 | return 0; |
| 302 | |
| 303 | if (mmc_card_cur->card_type == MMC_CARD) { |
| 304 | if ((ocr_recvd & MMC_OCR_REG_ACCESS_MODE_MASK) == |
| 305 | MMC_OCR_REG_ACCESS_MODE_SECTOR) { |
| 306 | mmc_card_cur->mode = SECTOR_MODE; |
| 307 | } else { |
| 308 | mmc_card_cur->mode = BYTE_MODE; |
| 309 | } |
| 310 | |
| 311 | ocr_recvd &= ~MMC_OCR_REG_ACCESS_MODE_MASK; |
| 312 | } else { |
| 313 | if ((ocr_recvd & MMC_OCR_REG_HOST_CAPACITY_SUPPORT_MASK) |
| 314 | == MMC_OCR_REG_HOST_CAPACITY_SUPPORT_SECTOR) { |
| 315 | mmc_card_cur->mode = SECTOR_MODE; |
| 316 | } else { |
| 317 | mmc_card_cur->mode = BYTE_MODE; |
| 318 | } |
| 319 | ocr_recvd &= ~MMC_OCR_REG_HOST_CAPACITY_SUPPORT_MASK; |
| 320 | } |
| 321 | |
| 322 | ocr_recvd &= ~(0x1 << 31); |
| 323 | if (!(ocr_recvd & ocr_value)) |
| 324 | return 0; |
| 325 | |
| 326 | err = mmc_send_cmd(MMC_CMD2, argument, resp); |
| 327 | if (err != 1) |
| 328 | return err; |
| 329 | |
| 330 | if (mmc_card_cur->card_type == MMC_CARD) { |
| 331 | argument = mmc_card_cur->RCA << 16; |
| 332 | err = mmc_send_cmd(MMC_CMD3, argument, resp); |
| 333 | if (err != 1) |
| 334 | return err; |
| 335 | } else { |
| 336 | argument = 0x00000000; |
| 337 | err = mmc_send_cmd(MMC_SDCMD3, argument, resp); |
| 338 | if (err != 1) |
| 339 | return err; |
| 340 | |
| 341 | mmc_card_cur->RCA = ((mmc_resp_r6 *) resp)->newpublishedrca; |
| 342 | } |
| 343 | |
| 344 | OMAP_HSMMC_CON &= ~OD; |
| 345 | OMAP_HSMMC_CON |= NOOPENDRAIN; |
| 346 | return 1; |
| 347 | } |
| 348 | |
| 349 | unsigned char mmc_read_cardsize(mmc_card_data *mmc_dev_data, |
| 350 | mmc_csd_reg_t *cur_csd) |
| 351 | { |
| 352 | mmc_extended_csd_reg_t ext_csd; |
| 353 | unsigned int size, count, blk_len, blk_no, card_size, argument; |
| 354 | unsigned char err; |
| 355 | unsigned int resp[4]; |
| 356 | |
| 357 | if (mmc_dev_data->mode == SECTOR_MODE) { |
| 358 | if (mmc_dev_data->card_type == SD_CARD) { |
| 359 | card_size = |
| 360 | (((mmc_sd2_csd_reg_t *) cur_csd)-> |
| 361 | c_size_lsb & MMC_SD2_CSD_C_SIZE_LSB_MASK) | |
| 362 | ((((mmc_sd2_csd_reg_t *) cur_csd)-> |
| 363 | c_size_msb & MMC_SD2_CSD_C_SIZE_MSB_MASK) |
| 364 | << MMC_SD2_CSD_C_SIZE_MSB_OFFSET); |
| 365 | mmc_dev_data->size = card_size * 1024; |
| 366 | if (mmc_dev_data->size == 0) |
| 367 | return 0; |
| 368 | } else { |
| 369 | argument = 0x00000000; |
| 370 | err = mmc_send_cmd(MMC_CMD8, argument, resp); |
| 371 | if (err != 1) |
| 372 | return err; |
| 373 | err = mmc_read_data((unsigned int *) &ext_csd); |
| 374 | if (err != 1) |
| 375 | return err; |
| 376 | mmc_dev_data->size = ext_csd.sectorcount; |
| 377 | |
| 378 | if (mmc_dev_data->size == 0) |
| 379 | mmc_dev_data->size = 8388608; |
| 380 | } |
| 381 | } else { |
| 382 | if (cur_csd->c_size_mult >= 8) |
| 383 | return 0; |
| 384 | |
| 385 | if (cur_csd->read_bl_len >= 12) |
| 386 | return 0; |
| 387 | |
| 388 | /* Compute size */ |
| 389 | count = 1 << (cur_csd->c_size_mult + 2); |
| 390 | card_size = (cur_csd->c_size_lsb & MMC_CSD_C_SIZE_LSB_MASK) | |
| 391 | ((cur_csd->c_size_msb & MMC_CSD_C_SIZE_MSB_MASK) |
| 392 | << MMC_CSD_C_SIZE_MSB_OFFSET); |
| 393 | blk_no = (card_size + 1) * count; |
| 394 | blk_len = 1 << cur_csd->read_bl_len; |
| 395 | size = blk_no * blk_len; |
| 396 | mmc_dev_data->size = size / MMCSD_SECTOR_SIZE; |
| 397 | if (mmc_dev_data->size == 0) |
| 398 | return 0; |
| 399 | } |
| 400 | return 1; |
| 401 | } |
| 402 | |
| 403 | unsigned char omap_mmc_read_sect(unsigned int start_sec, unsigned int num_bytes, |
| 404 | mmc_card_data *mmc_c, |
| 405 | unsigned long *output_buf) |
| 406 | { |
| 407 | unsigned char err; |
| 408 | unsigned int argument; |
| 409 | unsigned int resp[4]; |
| 410 | unsigned int num_sec_val = |
| 411 | (num_bytes + (MMCSD_SECTOR_SIZE - 1)) / MMCSD_SECTOR_SIZE; |
| 412 | unsigned int sec_inc_val; |
| 413 | |
| 414 | if (num_sec_val == 0) |
| 415 | return 1; |
| 416 | |
| 417 | if (mmc_c->mode == SECTOR_MODE) { |
| 418 | argument = start_sec; |
| 419 | sec_inc_val = 1; |
| 420 | } else { |
| 421 | argument = start_sec * MMCSD_SECTOR_SIZE; |
| 422 | sec_inc_val = MMCSD_SECTOR_SIZE; |
| 423 | } |
| 424 | |
| 425 | while (num_sec_val) { |
| 426 | err = mmc_send_cmd(MMC_CMD17, argument, resp); |
| 427 | if (err != 1) |
| 428 | return err; |
| 429 | |
| 430 | err = mmc_read_data((unsigned int *) output_buf); |
| 431 | if (err != 1) |
| 432 | return err; |
| 433 | |
| 434 | output_buf += (MMCSD_SECTOR_SIZE / 4); |
| 435 | argument += sec_inc_val; |
| 436 | num_sec_val--; |
| 437 | } |
| 438 | return 1; |
| 439 | } |
| 440 | |
| 441 | unsigned char configure_mmc(mmc_card_data *mmc_card_cur) |
| 442 | { |
| 443 | unsigned char ret_val; |
| 444 | unsigned int argument; |
| 445 | unsigned int resp[4]; |
| 446 | unsigned int trans_clk, trans_fact, trans_unit, retries = 2; |
| 447 | mmc_csd_reg_t Card_CSD; |
| 448 | unsigned char trans_speed; |
| 449 | |
| 450 | ret_val = mmc_init_setup(); |
| 451 | |
| 452 | if (ret_val != 1) |
| 453 | return ret_val; |
| 454 | |
| 455 | do { |
| 456 | ret_val = mmc_detect_card(mmc_card_cur); |
| 457 | retries--; |
| 458 | } while ((retries > 0) && (ret_val != 1)); |
| 459 | |
| 460 | argument = mmc_card_cur->RCA << 16; |
| 461 | ret_val = mmc_send_cmd(MMC_CMD9, argument, resp); |
| 462 | if (ret_val != 1) |
| 463 | return ret_val; |
| 464 | |
| 465 | ((unsigned int *) &Card_CSD)[3] = resp[3]; |
| 466 | ((unsigned int *) &Card_CSD)[2] = resp[2]; |
| 467 | ((unsigned int *) &Card_CSD)[1] = resp[1]; |
| 468 | ((unsigned int *) &Card_CSD)[0] = resp[0]; |
| 469 | |
| 470 | if (mmc_card_cur->card_type == MMC_CARD) |
| 471 | mmc_card_cur->version = Card_CSD.spec_vers; |
| 472 | |
| 473 | trans_speed = Card_CSD.tran_speed; |
| 474 | |
| 475 | ret_val = mmc_send_cmd(MMC_CMD4, MMC_DSR_DEFAULT << 16, resp); |
| 476 | if (ret_val != 1) |
| 477 | return ret_val; |
| 478 | |
| 479 | trans_unit = trans_speed & MMC_CSD_TRAN_SPEED_UNIT_MASK; |
| 480 | trans_fact = trans_speed & MMC_CSD_TRAN_SPEED_FACTOR_MASK; |
| 481 | |
| 482 | if (trans_unit > MMC_CSD_TRAN_SPEED_UNIT_100MHZ) |
| 483 | return 0; |
| 484 | |
| 485 | if ((trans_fact < MMC_CSD_TRAN_SPEED_FACTOR_1_0) || |
| 486 | (trans_fact > MMC_CSD_TRAN_SPEED_FACTOR_8_0)) |
| 487 | return 0; |
| 488 | |
| 489 | trans_unit >>= 0; |
| 490 | trans_fact >>= 3; |
| 491 | |
| 492 | trans_clk = mmc_transspeed_val[trans_fact - 1][trans_unit] * 2; |
| 493 | ret_val = mmc_clock_config(CLK_MISC, trans_clk); |
| 494 | |
| 495 | if (ret_val != 1) |
| 496 | return ret_val; |
| 497 | |
| 498 | argument = mmc_card_cur->RCA << 16; |
| 499 | ret_val = mmc_send_cmd(MMC_CMD7_SELECT, argument, resp); |
| 500 | if (ret_val != 1) |
| 501 | return ret_val; |
| 502 | |
| 503 | /* Configure the block length to 512 bytes */ |
| 504 | argument = MMCSD_SECTOR_SIZE; |
| 505 | ret_val = mmc_send_cmd(MMC_CMD16, argument, resp); |
| 506 | if (ret_val != 1) |
| 507 | return ret_val; |
| 508 | |
| 509 | /* get the card size in sectors */ |
| 510 | ret_val = mmc_read_cardsize(mmc_card_cur, &Card_CSD); |
| 511 | if (ret_val != 1) |
| 512 | return ret_val; |
| 513 | |
| 514 | return 1; |
| 515 | } |
| 516 | unsigned long mmc_bread(int dev_num, unsigned long blknr, lbaint_t blkcnt, |
| 517 | void *dst) |
| 518 | { |
| 519 | omap_mmc_read_sect(blknr, (blkcnt * MMCSD_SECTOR_SIZE), &cur_card_data, |
| 520 | (unsigned long *) dst); |
| 521 | return 1; |
| 522 | } |
| 523 | |
| 524 | int mmc_init(int verbose) |
| 525 | { |
| 526 | if (configure_mmc(&cur_card_data) != 1) |
| 527 | return 1; |
| 528 | |
| 529 | mmc_blk_dev.if_type = IF_TYPE_MMC; |
| 530 | mmc_blk_dev.part_type = PART_TYPE_DOS; |
| 531 | mmc_blk_dev.dev = 0; |
| 532 | mmc_blk_dev.lun = 0; |
| 533 | mmc_blk_dev.type = 0; |
| 534 | |
| 535 | /* FIXME fill in the correct size (is set to 32MByte) */ |
| 536 | mmc_blk_dev.blksz = MMCSD_SECTOR_SIZE; |
| 537 | mmc_blk_dev.lba = 0x10000; |
| 538 | mmc_blk_dev.removable = 0; |
| 539 | mmc_blk_dev.block_read = mmc_bread; |
| 540 | |
| 541 | fat_register_device(&mmc_blk_dev, 1); |
| 542 | return 0; |
| 543 | } |
| 544 | |
| 545 | int mmc_read(ulong src, uchar *dst, int size) |
| 546 | { |
| 547 | return 0; |
| 548 | } |
| 549 | |
| 550 | int mmc_write(uchar *src, ulong dst, int size) |
| 551 | { |
| 552 | return 0; |
| 553 | } |
| 554 | |
| 555 | int mmc2info(ulong addr) |
| 556 | { |
| 557 | return 0; |
| 558 | } |