Commit 17017d8d authored by Alex Dubov's avatar Alex Dubov Committed by Linus Torvalds

memstick: add "start" and "stop" methods to memstick device

In some cases it may be desirable to ensure that associated driver is not
going to access the media in some period of time.  "start" and "stop"
methods are provided therefore to allow it.
Signed-off-by: default avatarAlex Dubov <oakad@yahoo.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent b7789998
...@@ -433,8 +433,11 @@ static void memstick_check(struct work_struct *work) ...@@ -433,8 +433,11 @@ static void memstick_check(struct work_struct *work)
dev_dbg(&host->dev, "memstick_check started\n"); dev_dbg(&host->dev, "memstick_check started\n");
mutex_lock(&host->lock); mutex_lock(&host->lock);
if (!host->card) if (!host->card) {
memstick_power_on(host); if (memstick_power_on(host))
goto out_power_off;
} else
host->card->stop(host->card);
card = memstick_alloc_card(host); card = memstick_alloc_card(host);
...@@ -452,7 +455,8 @@ static void memstick_check(struct work_struct *work) ...@@ -452,7 +455,8 @@ static void memstick_check(struct work_struct *work)
|| !(host->card->check(host->card))) { || !(host->card->check(host->card))) {
device_unregister(&host->card->dev); device_unregister(&host->card->dev);
host->card = NULL; host->card = NULL;
} } else
host->card->start(host->card);
} }
if (!host->card) { if (!host->card) {
...@@ -465,6 +469,7 @@ static void memstick_check(struct work_struct *work) ...@@ -465,6 +469,7 @@ static void memstick_check(struct work_struct *work)
kfree(card); kfree(card);
} }
out_power_off:
if (!host->card) if (!host->card)
host->set_param(host, MEMSTICK_POWER, MEMSTICK_POWER_OFF); host->set_param(host, MEMSTICK_POWER, MEMSTICK_POWER_OFF);
......
...@@ -752,6 +752,37 @@ static int mspro_block_has_request(struct mspro_block_data *msb) ...@@ -752,6 +752,37 @@ static int mspro_block_has_request(struct mspro_block_data *msb)
return rc; return rc;
} }
static void mspro_block_stop(struct memstick_dev *card)
{
struct mspro_block_data *msb = memstick_get_drvdata(card);
int rc = 0;
unsigned long flags;
while (1) {
spin_lock_irqsave(&msb->q_lock, flags);
if (!msb->has_request) {
blk_stop_queue(msb->queue);
rc = 1;
}
spin_unlock_irqrestore(&msb->q_lock, flags);
if (rc)
break;
wait_for_completion(&card->mrq_complete);
}
}
static void mspro_block_start(struct memstick_dev *card)
{
struct mspro_block_data *msb = memstick_get_drvdata(card);
unsigned long flags;
spin_lock_irqsave(&msb->q_lock, flags);
blk_start_queue(msb->queue);
spin_unlock_irqrestore(&msb->q_lock, flags);
}
static int mspro_block_queue_thread(void *data) static int mspro_block_queue_thread(void *data)
{ {
struct memstick_dev *card = data; struct memstick_dev *card = data;
...@@ -1272,6 +1303,8 @@ static int mspro_block_probe(struct memstick_dev *card) ...@@ -1272,6 +1303,8 @@ static int mspro_block_probe(struct memstick_dev *card)
rc = mspro_block_init_disk(card); rc = mspro_block_init_disk(card);
if (!rc) { if (!rc) {
card->check = mspro_block_check_card; card->check = mspro_block_check_card;
card->stop = mspro_block_stop;
card->start = mspro_block_start;
return 0; return 0;
} }
......
...@@ -263,6 +263,10 @@ struct memstick_dev { ...@@ -263,6 +263,10 @@ struct memstick_dev {
/* Get next request from the media driver. */ /* Get next request from the media driver. */
int (*next_request)(struct memstick_dev *card, int (*next_request)(struct memstick_dev *card,
struct memstick_request **mrq); struct memstick_request **mrq);
/* Tell the media driver to stop doing things */
void (*stop)(struct memstick_dev *card);
/* Allow the media driver to continue */
void (*start)(struct memstick_dev *card);
struct device dev; struct device dev;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment