2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Block driver for media (i.e., flash cards)
|
|
|
|
*
|
|
|
|
* Copyright 2002 Hewlett-Packard Company
|
|
|
|
*
|
|
|
|
* Use consistent with the GNU GPL is permitted,
|
|
|
|
* provided that this copyright notice is
|
|
|
|
* preserved in its entirety in all copies and derived works.
|
|
|
|
*
|
|
|
|
* HEWLETT-PACKARD COMPANY MAKES NO WARRANTIES, EXPRESSED OR IMPLIED,
|
|
|
|
* AS TO THE USEFULNESS OR CORRECTNESS OF THIS CODE OR ITS
|
|
|
|
* FITNESS FOR ANY PARTICULAR PURPOSE.
|
|
|
|
*
|
|
|
|
* Many thanks to Alessandro Rubini and Jonathan Corbet!
|
|
|
|
*
|
|
|
|
* Author: Andrew Christian
|
|
|
|
* 28 May 2002
|
|
|
|
*/
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/hdreg.h>
|
|
|
|
#include <linux/kdev_t.h>
|
|
|
|
#include <linux/blkdev.h>
|
2006-01-13 02:43:35 +08:00
|
|
|
#include <linux/mutex.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include <linux/mmc/card.h>
|
2006-06-18 20:34:37 +08:00
|
|
|
#include <linux/mmc/host.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/mmc/protocol.h>
|
2006-08-30 22:14:56 +08:00
|
|
|
#include <linux/mmc/host.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include <asm/system.h>
|
|
|
|
#include <asm/uaccess.h>
|
|
|
|
|
|
|
|
#include "mmc_queue.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* max 8 partitions per card
|
|
|
|
*/
|
|
|
|
#define MMC_SHIFT 3
|
|
|
|
|
|
|
|
static int major;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* There is one mmc_blk_data per slot.
|
|
|
|
*/
|
|
|
|
struct mmc_blk_data {
|
|
|
|
spinlock_t lock;
|
|
|
|
struct gendisk *disk;
|
|
|
|
struct mmc_queue queue;
|
|
|
|
|
|
|
|
unsigned int usage;
|
|
|
|
unsigned int block_bits;
|
2006-01-04 06:38:44 +08:00
|
|
|
unsigned int read_only;
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2006-01-13 02:43:35 +08:00
|
|
|
static DEFINE_MUTEX(open_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static struct mmc_blk_data *mmc_blk_get(struct gendisk *disk)
|
|
|
|
{
|
|
|
|
struct mmc_blk_data *md;
|
|
|
|
|
2006-01-13 02:43:35 +08:00
|
|
|
mutex_lock(&open_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
md = disk->private_data;
|
|
|
|
if (md && md->usage == 0)
|
|
|
|
md = NULL;
|
|
|
|
if (md)
|
|
|
|
md->usage++;
|
2006-01-13 02:43:35 +08:00
|
|
|
mutex_unlock(&open_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return md;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mmc_blk_put(struct mmc_blk_data *md)
|
|
|
|
{
|
2006-01-13 02:43:35 +08:00
|
|
|
mutex_lock(&open_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
md->usage--;
|
|
|
|
if (md->usage == 0) {
|
|
|
|
put_disk(md->disk);
|
|
|
|
mmc_cleanup_queue(&md->queue);
|
|
|
|
kfree(md);
|
|
|
|
}
|
2006-01-13 02:43:35 +08:00
|
|
|
mutex_unlock(&open_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_blk_open(struct inode *inode, struct file *filp)
|
|
|
|
{
|
|
|
|
struct mmc_blk_data *md;
|
|
|
|
int ret = -ENXIO;
|
|
|
|
|
|
|
|
md = mmc_blk_get(inode->i_bdev->bd_disk);
|
|
|
|
if (md) {
|
|
|
|
if (md->usage == 2)
|
|
|
|
check_disk_change(inode->i_bdev);
|
|
|
|
ret = 0;
|
2005-09-07 06:18:52 +08:00
|
|
|
|
2006-01-04 06:38:44 +08:00
|
|
|
if ((filp->f_mode & FMODE_WRITE) && md->read_only)
|
2005-09-07 06:18:52 +08:00
|
|
|
ret = -EROFS;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_blk_release(struct inode *inode, struct file *filp)
|
|
|
|
{
|
|
|
|
struct mmc_blk_data *md = inode->i_bdev->bd_disk->private_data;
|
|
|
|
|
|
|
|
mmc_blk_put(md);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-01-08 17:02:50 +08:00
|
|
|
mmc_blk_getgeo(struct block_device *bdev, struct hd_geometry *geo)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-01-08 17:02:50 +08:00
|
|
|
geo->cylinders = get_capacity(bdev->bd_disk) / (4 * 16);
|
|
|
|
geo->heads = 4;
|
|
|
|
geo->sectors = 16;
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct block_device_operations mmc_bdops = {
|
|
|
|
.open = mmc_blk_open,
|
|
|
|
.release = mmc_blk_release,
|
2006-01-08 17:02:50 +08:00
|
|
|
.getgeo = mmc_blk_getgeo,
|
2005-04-17 06:20:36 +08:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mmc_blk_request {
|
|
|
|
struct mmc_request mrq;
|
|
|
|
struct mmc_command cmd;
|
|
|
|
struct mmc_command stop;
|
|
|
|
struct mmc_data data;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int mmc_blk_prep_rq(struct mmc_queue *mq, struct request *req)
|
|
|
|
{
|
|
|
|
struct mmc_blk_data *md = mq->data;
|
|
|
|
int stat = BLKPREP_OK;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we have no device, we haven't finished initialising.
|
|
|
|
*/
|
|
|
|
if (!md || !mq->card) {
|
|
|
|
printk(KERN_ERR "%s: killing request - no device/host\n",
|
|
|
|
req->rq_disk->disk_name);
|
|
|
|
stat = BLKPREP_KILL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
|
|
|
|
{
|
|
|
|
struct mmc_blk_data *md = mq->data;
|
|
|
|
struct mmc_card *card = md->queue.card;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (mmc_card_claim_host(card))
|
|
|
|
goto cmd_err;
|
|
|
|
|
|
|
|
do {
|
|
|
|
struct mmc_blk_request brq;
|
|
|
|
struct mmc_command cmd;
|
2006-08-30 22:14:56 +08:00
|
|
|
u32 readcmd, writecmd;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
memset(&brq, 0, sizeof(struct mmc_blk_request));
|
|
|
|
brq.mrq.cmd = &brq.cmd;
|
|
|
|
brq.mrq.data = &brq.data;
|
|
|
|
|
|
|
|
brq.cmd.arg = req->sector << 9;
|
2006-02-02 20:23:12 +08:00
|
|
|
brq.cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC;
|
2006-05-20 04:48:03 +08:00
|
|
|
brq.data.blksz = 1 << md->block_bits;
|
2005-04-17 06:20:36 +08:00
|
|
|
brq.data.blocks = req->nr_sectors >> (md->block_bits - 9);
|
|
|
|
brq.stop.opcode = MMC_STOP_TRANSMISSION;
|
|
|
|
brq.stop.arg = 0;
|
2006-02-02 20:23:12 +08:00
|
|
|
brq.stop.flags = MMC_RSP_R1B | MMC_CMD_AC;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-09-07 22:57:12 +08:00
|
|
|
mmc_set_data_timeout(&brq.data, card, rq_data_dir(req) != READ);
|
2006-06-18 20:34:37 +08:00
|
|
|
|
2006-08-30 22:14:56 +08:00
|
|
|
/*
|
|
|
|
* If the host doesn't support multiple block writes, force
|
|
|
|
* block writes to single block.
|
|
|
|
*/
|
|
|
|
if (rq_data_dir(req) != READ &&
|
|
|
|
!(card->host->caps & MMC_CAP_MULTIWRITE))
|
2005-04-17 06:20:36 +08:00
|
|
|
brq.data.blocks = 1;
|
2006-01-10 05:12:17 +08:00
|
|
|
|
|
|
|
if (brq.data.blocks > 1) {
|
|
|
|
brq.data.flags |= MMC_DATA_MULTI;
|
|
|
|
brq.mrq.stop = &brq.stop;
|
2006-08-30 22:14:56 +08:00
|
|
|
readcmd = MMC_READ_MULTIPLE_BLOCK;
|
|
|
|
writecmd = MMC_WRITE_MULTIPLE_BLOCK;
|
2006-01-10 05:12:17 +08:00
|
|
|
} else {
|
|
|
|
brq.mrq.stop = NULL;
|
2006-08-30 22:14:56 +08:00
|
|
|
readcmd = MMC_READ_SINGLE_BLOCK;
|
|
|
|
writecmd = MMC_WRITE_BLOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rq_data_dir(req) == READ) {
|
|
|
|
brq.cmd.opcode = readcmd;
|
|
|
|
brq.data.flags |= MMC_DATA_READ;
|
|
|
|
} else {
|
|
|
|
brq.cmd.opcode = writecmd;
|
|
|
|
brq.data.flags |= MMC_DATA_WRITE;
|
2006-01-10 05:12:17 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
brq.data.sg = mq->sg;
|
|
|
|
brq.data.sg_len = blk_rq_map_sg(req->q, req, brq.data.sg);
|
|
|
|
|
|
|
|
mmc_wait_for_req(card->host, &brq.mrq);
|
|
|
|
if (brq.cmd.error) {
|
|
|
|
printk(KERN_ERR "%s: error %d sending read/write command\n",
|
|
|
|
req->rq_disk->disk_name, brq.cmd.error);
|
|
|
|
goto cmd_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (brq.data.error) {
|
|
|
|
printk(KERN_ERR "%s: error %d transferring data\n",
|
|
|
|
req->rq_disk->disk_name, brq.data.error);
|
|
|
|
goto cmd_err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (brq.stop.error) {
|
|
|
|
printk(KERN_ERR "%s: error %d sending stop command\n",
|
|
|
|
req->rq_disk->disk_name, brq.stop.error);
|
|
|
|
goto cmd_err;
|
|
|
|
}
|
|
|
|
|
2006-09-24 17:46:43 +08:00
|
|
|
if (rq_data_dir(req) != READ) {
|
|
|
|
do {
|
|
|
|
int err;
|
|
|
|
|
|
|
|
cmd.opcode = MMC_SEND_STATUS;
|
|
|
|
cmd.arg = card->rca << 16;
|
|
|
|
cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
|
|
|
|
err = mmc_wait_for_cmd(card->host, &cmd, 5);
|
|
|
|
if (err) {
|
|
|
|
printk(KERN_ERR "%s: error %d requesting status\n",
|
|
|
|
req->rq_disk->disk_name, err);
|
|
|
|
goto cmd_err;
|
|
|
|
}
|
|
|
|
} while (!(cmd.resp[0] & R1_READY_FOR_DATA));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#if 0
|
2006-09-24 17:46:43 +08:00
|
|
|
if (cmd.resp[0] & ~0x00000900)
|
|
|
|
printk(KERN_ERR "%s: status = %08x\n",
|
|
|
|
req->rq_disk->disk_name, cmd.resp[0]);
|
|
|
|
if (mmc_decode_status(cmd.resp))
|
|
|
|
goto cmd_err;
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
2006-09-24 17:46:43 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* A block was successfully transferred.
|
|
|
|
*/
|
|
|
|
spin_lock_irq(&md->lock);
|
|
|
|
ret = end_that_request_chunk(req, 1, brq.data.bytes_xfered);
|
|
|
|
if (!ret) {
|
|
|
|
/*
|
|
|
|
* The whole request completed successfully.
|
|
|
|
*/
|
|
|
|
add_disk_randomness(req->rq_disk);
|
|
|
|
blkdev_dequeue_request(req);
|
2006-01-06 16:49:03 +08:00
|
|
|
end_that_request_last(req, 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
spin_unlock_irq(&md->lock);
|
|
|
|
} while (ret);
|
|
|
|
|
|
|
|
mmc_card_release_host(card);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
cmd_err:
|
|
|
|
mmc_card_release_host(card);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is a little draconian, but until we get proper
|
|
|
|
* error handling sorted out here, its the best we can
|
|
|
|
* do - especially as some hosts have no idea how much
|
|
|
|
* data was transferred before the error occurred.
|
|
|
|
*/
|
|
|
|
spin_lock_irq(&md->lock);
|
|
|
|
do {
|
|
|
|
ret = end_that_request_chunk(req, 0,
|
|
|
|
req->current_nr_sectors << 9);
|
|
|
|
} while (ret);
|
|
|
|
|
|
|
|
add_disk_randomness(req->rq_disk);
|
|
|
|
blkdev_dequeue_request(req);
|
2006-01-06 16:49:03 +08:00
|
|
|
end_that_request_last(req, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock_irq(&md->lock);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MMC_NUM_MINORS (256 >> MMC_SHIFT)
|
|
|
|
|
|
|
|
static unsigned long dev_use[MMC_NUM_MINORS/(8*sizeof(unsigned long))];
|
|
|
|
|
2006-01-04 06:38:44 +08:00
|
|
|
static inline int mmc_blk_readonly(struct mmc_card *card)
|
|
|
|
{
|
|
|
|
return mmc_card_readonly(card) ||
|
|
|
|
!(card->csd.cmdclass & CCC_BLOCK_WRITE);
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static struct mmc_blk_data *mmc_blk_alloc(struct mmc_card *card)
|
|
|
|
{
|
|
|
|
struct mmc_blk_data *md;
|
|
|
|
int devidx, ret;
|
|
|
|
|
|
|
|
devidx = find_first_zero_bit(dev_use, MMC_NUM_MINORS);
|
|
|
|
if (devidx >= MMC_NUM_MINORS)
|
|
|
|
return ERR_PTR(-ENOSPC);
|
|
|
|
__set_bit(devidx, dev_use);
|
|
|
|
|
|
|
|
md = kmalloc(sizeof(struct mmc_blk_data), GFP_KERNEL);
|
2006-01-04 06:38:44 +08:00
|
|
|
if (!md) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-01-04 06:38:44 +08:00
|
|
|
memset(md, 0, sizeof(struct mmc_blk_data));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-01-04 06:38:44 +08:00
|
|
|
/*
|
|
|
|
* Set the read-only status based on the supported commands
|
|
|
|
* and the write protect switch.
|
|
|
|
*/
|
|
|
|
md->read_only = mmc_blk_readonly(card);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-01-04 06:38:44 +08:00
|
|
|
/*
|
2006-09-07 23:01:30 +08:00
|
|
|
* Both SD and MMC specifications state (although a bit
|
|
|
|
* unclearly in the MMC case) that a block size of 512
|
|
|
|
* bytes must always be supported by the card.
|
2006-01-04 06:38:44 +08:00
|
|
|
*/
|
2006-09-07 23:01:30 +08:00
|
|
|
md->block_bits = 9;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-01-04 06:38:44 +08:00
|
|
|
md->disk = alloc_disk(1 << MMC_SHIFT);
|
|
|
|
if (md->disk == NULL) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err_kfree;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-01-04 06:38:44 +08:00
|
|
|
spin_lock_init(&md->lock);
|
|
|
|
md->usage = 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-01-04 06:38:44 +08:00
|
|
|
ret = mmc_init_queue(&md->queue, card, &md->lock);
|
|
|
|
if (ret)
|
|
|
|
goto err_putdisk;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-01-04 06:38:44 +08:00
|
|
|
md->queue.prep_fn = mmc_blk_prep_rq;
|
|
|
|
md->queue.issue_fn = mmc_blk_issue_rq;
|
|
|
|
md->queue.data = md;
|
2005-12-23 07:21:38 +08:00
|
|
|
|
2006-01-04 06:38:44 +08:00
|
|
|
md->disk->major = major;
|
|
|
|
md->disk->first_minor = devidx << MMC_SHIFT;
|
|
|
|
md->disk->fops = &mmc_bdops;
|
|
|
|
md->disk->private_data = md;
|
|
|
|
md->disk->queue = md->queue.queue;
|
|
|
|
md->disk->driverfs_dev = &card->dev;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* As discussed on lkml, GENHD_FL_REMOVABLE should:
|
|
|
|
*
|
|
|
|
* - be set for removable media with permanent block devices
|
|
|
|
* - be unset for removable block devices with permanent media
|
|
|
|
*
|
|
|
|
* Since MMC block devices clearly fall under the second
|
|
|
|
* case, we do not set GENHD_FL_REMOVABLE. Userspace
|
|
|
|
* should use the block device creation/destruction hotplug
|
|
|
|
* messages to tell when the card is present.
|
|
|
|
*/
|
|
|
|
|
|
|
|
sprintf(md->disk->disk_name, "mmcblk%d", devidx);
|
|
|
|
|
|
|
|
blk_queue_hardsect_size(md->queue.queue, 1 << md->block_bits);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The CSD capacity field is in units of read_blkbits.
|
|
|
|
* set_capacity takes units of 512 bytes.
|
|
|
|
*/
|
|
|
|
set_capacity(md->disk, card->csd.capacity << (card->csd.read_blkbits - 9));
|
2005-04-17 06:20:36 +08:00
|
|
|
return md;
|
2006-01-04 06:38:44 +08:00
|
|
|
|
|
|
|
err_putdisk:
|
|
|
|
put_disk(md->disk);
|
|
|
|
err_kfree:
|
|
|
|
kfree(md);
|
|
|
|
out:
|
|
|
|
return ERR_PTR(ret);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mmc_blk_set_blksize(struct mmc_blk_data *md, struct mmc_card *card)
|
|
|
|
{
|
|
|
|
struct mmc_command cmd;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
mmc_card_claim_host(card);
|
|
|
|
cmd.opcode = MMC_SET_BLOCKLEN;
|
2005-12-23 07:21:38 +08:00
|
|
|
cmd.arg = 1 << md->block_bits;
|
2006-02-02 20:23:12 +08:00
|
|
|
cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
|
2005-04-17 06:20:36 +08:00
|
|
|
err = mmc_wait_for_cmd(card->host, &cmd, 5);
|
|
|
|
mmc_card_release_host(card);
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
printk(KERN_ERR "%s: unable to set block size to %d: %d\n",
|
|
|
|
md->disk->disk_name, cmd.arg, err);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_blk_probe(struct mmc_card *card)
|
|
|
|
{
|
|
|
|
struct mmc_blk_data *md;
|
|
|
|
int err;
|
|
|
|
|
2005-05-21 17:27:02 +08:00
|
|
|
/*
|
|
|
|
* Check that the card supports the command class(es) we need.
|
|
|
|
*/
|
|
|
|
if (!(card->csd.cmdclass & CCC_BLOCK_READ))
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
md = mmc_blk_alloc(card);
|
|
|
|
if (IS_ERR(md))
|
|
|
|
return PTR_ERR(md);
|
|
|
|
|
|
|
|
err = mmc_blk_set_blksize(md, card);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
2006-01-14 05:44:18 +08:00
|
|
|
printk(KERN_INFO "%s: %s %s %lluKiB %s\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
md->disk->disk_name, mmc_card_id(card), mmc_card_name(card),
|
2006-01-14 05:44:18 +08:00
|
|
|
(unsigned long long)(get_capacity(md->disk) >> 1),
|
|
|
|
md->read_only ? "(ro)" : "");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
mmc_set_drvdata(card, md);
|
|
|
|
add_disk(md->disk);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
out:
|
|
|
|
mmc_blk_put(md);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mmc_blk_remove(struct mmc_card *card)
|
|
|
|
{
|
|
|
|
struct mmc_blk_data *md = mmc_get_drvdata(card);
|
|
|
|
|
|
|
|
if (md) {
|
|
|
|
int devidx;
|
|
|
|
|
|
|
|
del_gendisk(md->disk);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* I think this is needed.
|
|
|
|
*/
|
|
|
|
md->disk->queue = NULL;
|
|
|
|
|
|
|
|
devidx = md->disk->first_minor >> MMC_SHIFT;
|
|
|
|
__clear_bit(devidx, dev_use);
|
|
|
|
|
|
|
|
mmc_blk_put(md);
|
|
|
|
}
|
|
|
|
mmc_set_drvdata(card, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM
|
|
|
|
static int mmc_blk_suspend(struct mmc_card *card, pm_message_t state)
|
|
|
|
{
|
|
|
|
struct mmc_blk_data *md = mmc_get_drvdata(card);
|
|
|
|
|
|
|
|
if (md) {
|
|
|
|
mmc_queue_suspend(&md->queue);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mmc_blk_resume(struct mmc_card *card)
|
|
|
|
{
|
|
|
|
struct mmc_blk_data *md = mmc_get_drvdata(card);
|
|
|
|
|
|
|
|
if (md) {
|
|
|
|
mmc_blk_set_blksize(md, card);
|
|
|
|
mmc_queue_resume(&md->queue);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define mmc_blk_suspend NULL
|
|
|
|
#define mmc_blk_resume NULL
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static struct mmc_driver mmc_driver = {
|
|
|
|
.drv = {
|
|
|
|
.name = "mmcblk",
|
|
|
|
},
|
|
|
|
.probe = mmc_blk_probe,
|
|
|
|
.remove = mmc_blk_remove,
|
|
|
|
.suspend = mmc_blk_suspend,
|
|
|
|
.resume = mmc_blk_resume,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init mmc_blk_init(void)
|
|
|
|
{
|
|
|
|
int res = -ENOMEM;
|
|
|
|
|
|
|
|
res = register_blkdev(major, "mmc");
|
|
|
|
if (res < 0) {
|
|
|
|
printk(KERN_WARNING "Unable to get major %d for MMC media: %d\n",
|
|
|
|
major, res);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (major == 0)
|
|
|
|
major = res;
|
|
|
|
|
|
|
|
return mmc_register_driver(&mmc_driver);
|
|
|
|
|
|
|
|
out:
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit mmc_blk_exit(void)
|
|
|
|
{
|
|
|
|
mmc_unregister_driver(&mmc_driver);
|
|
|
|
unregister_blkdev(major, "mmc");
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(mmc_blk_init);
|
|
|
|
module_exit(mmc_blk_exit);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_DESCRIPTION("Multimedia Card (MMC) block device driver");
|
|
|
|
|
|
|
|
module_param(major, int, 0444);
|
|
|
|
MODULE_PARM_DESC(major, "specify the major device number for MMC block driver");
|