/* * Starting point for SD card init. */ int mmc_attach_sd(struct mmc_host *host, u32 ocr) { int err; #ifdef CONFIG_MMC_PARANOID_SD_INIT int retries; #endif BUG_ON(!host); WARN_ON(!host->claimed); mmc_attach_bus(host, &mmc_sd_ops); /* * We need to get OCR a different way for SPI. */ if (mmc_host_is_spi(host)) { mmc_go_idle(host); err = mmc_spi_read_ocr(host, 0, &ocr); if (err) goto err; } /* * Sanity check the voltages that the card claims to * support. */ if (ocr & 0x7F) { printk(KERN_WARNING "%s: card claims to support voltages " "below the defined range. These will be ignored.\n", mmc_hostname(host)); ocr &= ~0x7F; } if (ocr & MMC_VDD_165_195) { printk(KERN_WARNING "%s: SD card claims to support the " "incompletely defined 'low voltage range'. This " "will be ignored.\n", mmc_hostname(host)); ocr &= ~MMC_VDD_165_195; } host->ocr = mmc_select_voltage(host, ocr); /* * Can we support the voltage(s) of the card(s)? */ if (!host->ocr) { err = -EINVAL; goto err; } /* * Detect and init the card. */ #ifdef CONFIG_MMC_PARANOID_SD_INIT retries = 5; while (retries) { err = mmc_sd_init_card(host, host->ocr, NULL); if (err) { retries--; continue; } break; } if (!retries) { printk(KERN_ERR "%s: mmc_sd_init_card() failure (err = %d)\n", mmc_hostname(host), err); goto err; } #else err = mmc_sd_init_card(host, host->ocr, NULL); if (err) goto err; #endif mmc_release_host(host); #ifdef CONFIG_ARCH_EMXX err = mmc_add_card(host->card[0]); #else err = mmc_add_card(host->card); #endif if (err) goto remove_card; return 0; remove_card: #ifdef CONFIG_ARCH_EMXX mmc_remove_card(host->card[0]); host->card[0] = NULL; #else mmc_remove_card(host->card); host->card = NULL; #endif mmc_claim_host(host); err: mmc_detach_bus(host); mmc_release_host(host); printk(KERN_ERR "%s: error %d whilst initialising SD card\n", mmc_hostname(host), err); return err; }
static void mmc_sd_attach_bus_ops(struct mmc_host *host) { mmc_attach_bus(host, &mmc_sd_ops); }
/* * Starting point for MMC card init. */ int mmc_attach_mmc(struct mmc_host *host, u32 ocr) { int err; BUG_ON(!host); WARN_ON(!host->claimed); mmc_attach_bus(host, &mmc_ops); /* * We need to get OCR a different way for SPI. */ if (mmc_host_is_spi(host)) { err = mmc_spi_read_ocr(host, 1, &ocr); if (err) goto err; } /* * Sanity check the voltages that the card claims to * support. */ if (ocr & 0x7F) { printk(KERN_WARNING "%s: card claims to support voltages " "below the defined range. These will be ignored.\n", mmc_hostname(host)); ocr &= ~0x7F; } host->ocr = mmc_select_voltage(host, ocr); /* * Can we support the voltage of the card? */ if (!host->ocr) { err = -EINVAL; goto err; } /* * Detect and init the card. */ err = mmc_init_card(host, host->ocr, NULL); if (err) goto err; mmc_release_host(host); err = mmc_add_card(host->card); if (err) goto remove_card; return 0; remove_card: mmc_remove_card(host->card); host->card = NULL; mmc_claim_host(host); err: mmc_detach_bus(host); mmc_release_host(host); printk(KERN_ERR "%s: error %d whilst initialising MMC card\n", mmc_hostname(host), err); return err; }