示例#1
0
static int sd_welcome_card(struct sd_host *host)
{
	int retval;

	/* soft reset the card */
	retval = sd_reset_sequence(host);
	if (retval < 0 || sd_card_is_bad(host))
		goto out;

	/* read Operating Conditions Register */
	retval = sd_read_ocr(host);
	if (retval < 0)
		goto err_bad_card;

	/* refuse to drive cards reporting voltage ranges out of scope */
	if (!(host->ocr & host->ocr_avail)) {
		sd_printk(KERN_WARNING, "reported OCR (%08x)"
			  " indicates that it is not safe to use this"
			  " card with a GameCube\n", host->ocr);
		retval = -ENODEV;
		goto err_bad_card;
	}

	/* read and decode the Card Specific Data */
	retval = sd_read_csd(host);
	if (retval < 0)
		goto err_bad_card;
	mmc_decode_csd(&host->card);

	/* calculate some card access related timeouts */
	sd_calc_timeouts(host);

	/* read and decode the Card Identification Data */
	retval = sd_read_cid(host);
	if (retval < 0)
		goto err_bad_card;
	mmc_decode_cid(&host->card);

	sd_printk(KERN_INFO, "slot%d: descr \"%s\", size %luk, block %ub,"
		  " serial %08x\n",
		  to_channel(exi_get_exi_channel(host->exi_device)),
		  host->card.cid.prod_name,
		  (unsigned long)((host->card.csd.capacity *
			  (1 << host->card.csd.read_blkbits)) / 1024),
		  1 << host->card.csd.read_blkbits,
		  host->card.cid.serial);

	retval = 0;
	goto out;

err_bad_card:
	sd_card_set_bad(host);
out:
	return retval;
}
示例#2
0
/*
 * Initializes the block layer interfaces.
 */
static int sd_init_blk_dev(struct sd_host *host)
{
	struct gendisk *disk;
	struct request_queue *queue;
	int channel;
	int retval;

	channel = to_channel(exi_get_exi_channel(host->exi_device));

	/* queue */
	retval = -ENOMEM;
	spin_lock_init(&host->queue_lock);
	queue = blk_init_queue(sd_request_func, &host->queue_lock);
	if (!queue) {
		sd_printk(KERN_ERR, "error initializing queue\n");
		goto err_blk_init_queue;
	}
	blk_queue_dma_alignment(queue, EXI_DMA_ALIGN);
	blk_queue_max_phys_segments(queue, 1);
	blk_queue_max_hw_segments(queue, 1);
	blk_queue_max_sectors(queue, 8);
	queue_flag_set_unlocked(QUEUE_FLAG_NONROT, queue);
	queue->queuedata = host;
	host->queue = queue;

	/* disk */
	disk = alloc_disk(1 << MMC_SHIFT);
	if (!disk) {
		sd_printk(KERN_ERR, "error allocating disk\n");
		goto err_alloc_disk;
	}
	disk->major = SD_MAJOR;
	disk->first_minor = channel << MMC_SHIFT;
	disk->fops = &sd_fops;
	sprintf(disk->disk_name, "%s%c", SD_NAME, 'a' + channel);
	disk->private_data = host;
	disk->queue = host->queue;
	host->disk = disk;

	retval = 0;
	goto out;

err_alloc_disk:
	blk_cleanup_queue(host->queue);
	host->queue = NULL;
err_blk_init_queue:
out:
	return retval;
}
/*
 * Initializes and launches the IO thread.
 */
static int sd_init_io_thread(struct sd_host *host)
{
	int channel;
	int result = 0;

	channel = to_channel(exi_get_exi_channel(host->exi_device));

	mutex_init(&host->io_mutex);
	host->io_thread = kthread_run(sd_io_thread, host,
				      "ksdiod/%c", 'a' + channel);
	if (IS_ERR(host->io_thread)) {
		sd_printk(KERN_ERR, "error creating io thread\n");
		result = PTR_ERR(host->io_thread);
	}
	return result;
}