/*
 * Initializes a host.
 */
static int sd_init(struct sd_host *host)
{
	int retval;

	spin_lock_init(&host->lock);

	host->refcnt = 0;
	set_bit(__SD_MEDIA_CHANGED, &host->flags);

	host->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
	sd_set_clock(host, SD_SPI_CLK);
	sd_calc_timeouts(host);

	retval = sd_init_blk_dev(host);
	if (!retval) {
		retval = sd_revalidate_disk(host->disk);
		if (retval < 0 || !mmc_card_present(&host->card)) {
			retval = -ENODEV;
			goto err_blk_dev;
		}

		retval = sd_init_io_thread(host);
		if (retval)
			goto err_blk_dev;

		add_disk(host->disk);
	}

	return retval;

err_blk_dev:
	sd_exit_blk_dev(host);
	return retval;
}
Example #2
0
int sd_init(void)
{
	int err;

	fd = ios_open("/dev/sdio/slot0", 0);
	if (fd < 0)
		return fd;

	err = sd_reset_card();
	if (err) {
		goto out;
	}

	// now in standby state

	err = sd_select();
	if (err)
		goto out;

	// now in transfer state

	// Some broken cards require this:
	err = sd_set_blocklength(0x200);
	if (err)
		goto out;

	err = sd_set_bus_width(4);	// XXX: Should check in SCR first.
	if (err)
		goto out;

	err = sd_set_clock();	// XXX: Should check.
	if (err)
		goto out;

	return 0;

 out:
	sd_close();

	return err;
}