/* Select the MMC clock frequency */ static int jz_mmc_set_clock(u32 rate) { int clkrt; jz_mmc_stop_clock(); __cpm_select_msc_clk(1); /* select clock source from CPM */ clkrt = jz_mmc_calc_clkrt(1, rate); REG_MSC_CLKRT = clkrt; return MMC_NO_ERROR; }
/* init mmc/sd card we assume that the card is in the slot */ static int mmc_init(void) { int retries; u8 *resp; __gpio_as_msc(); __msc_reset(); MMC_IRQ_MASK(); __cpm_select_msc_clk(0,1); REG_MSC_CLKRT = 7; //250k resp = mmc_cmd(12, 0, 0x41, MSC_CMDAT_RESPONSE_R1); /* reset */ resp = mmc_cmd(0, 0, 0x80, 0); resp = mmc_cmd(8, 0x1aa, 0x1, MSC_CMDAT_RESPONSE_R1); resp = mmc_cmd(55, 0, 0x1, MSC_CMDAT_RESPONSE_R1); if(!(resp[0] & 0x20) && (resp[5] != 0x37)) { resp = mmc_cmd(1, 0xff8000, 0x3, MSC_CMDAT_RESPONSE_R3); retries = 500; while (retries-- && resp && !(resp[4] & 0x80)) { resp = mmc_cmd(1, 0x40300000, 0x3, MSC_CMDAT_RESPONSE_R3); udelay(1000); udelay(1000); } if (resp[4]== 0x80) serial_puts("MMC init ok\n"); else serial_puts("MMC init fail\n"); /* try to get card id */ resp = mmc_cmd(2, 0, 0x2, MSC_CMDAT_RESPONSE_R2); resp = mmc_cmd(3, 0x10, 0x1, MSC_CMDAT_RESPONSE_R1); REG_MSC_CLKRT = 2; /* 16/1 MHz */ resp = mmc_cmd(7, 0x10, 0x1, MSC_CMDAT_RESPONSE_R1); resp = mmc_cmd(6, 0x3b70101, 0x401, MSC_CMDAT_RESPONSE_R1); } else sd_init(); return 0; }
/* Select the MMC clock frequency */ static int jz_mmc_set_clock(u32 rate) { int clkrt; /* __cpm_select_msc_clk_high will select 48M clock for MMC/SD card * perhaps this will made some card with bad quality init fail,or * bad stabilization. */ if (rate > SD_CLOCK_FAST) { __cpm_select_msc_clk_high(MSC_ID,1); /* select clock source from CPM */ clkrt = jz_mmc_calc_clkrt(0, rate); } else { __cpm_select_msc_clk(MSC_ID,1); /* select clock source from CPM */ clkrt = jz_mmc_calc_clkrt(1, rate); } #ifndef CONFIG_FPGA REG_MSC_CLKRT(MSC_ID) = clkrt; #else REG_MSC_CLKRT(MSC_ID) = 7; #endif return MMC_NO_ERROR; }