Commit 7584d276 authored by Jarkko Lavinen's avatar Jarkko Lavinen Committed by Pierre Ossman

MMC: OMAP: Use tasklet instead of workqueue for cover switch notification

The cover waitqueue is occasionally scheduled twice from timer
and the interrupt and oops follows. It would have been possible
to fix this problem with spinlocks but using tasklet was a dropin
solution with no need for locking.

This path also adds some cleanups.
Signed-off-by: default avatarJarkko Lavinen <jarkko.lavinen@nokia.com>
Signed-off-by: default avatarHiroshi DOYU <Hiroshi.DOYU@nokia.com>
Signed-off-by: default avatarPierre Ossman <drzeus@drzeus.cx>
parent 8348f002
...@@ -94,7 +94,7 @@ ...@@ -94,7 +94,7 @@
/* Specifies how often in millisecs to poll for card status changes /* Specifies how often in millisecs to poll for card status changes
* when the cover switch is open */ * when the cover switch is open */
#define OMAP_MMC_SWITCH_POLL_DELAY 500 #define OMAP_MMC_COVER_POLL_DELAY 500
struct mmc_omap_host; struct mmc_omap_host;
...@@ -106,8 +106,8 @@ struct mmc_omap_slot { ...@@ -106,8 +106,8 @@ struct mmc_omap_slot {
unsigned int fclk_freq; unsigned int fclk_freq;
unsigned powered:1; unsigned powered:1;
struct work_struct switch_work; struct tasklet_struct cover_tasklet;
struct timer_list switch_timer; struct timer_list cover_timer;
unsigned cover_open; unsigned cover_open;
struct mmc_request *mrq; struct mmc_request *mrq;
...@@ -740,40 +740,51 @@ static irqreturn_t mmc_omap_irq(int irq, void *dev_id) ...@@ -740,40 +740,51 @@ static irqreturn_t mmc_omap_irq(int irq, void *dev_id)
return IRQ_HANDLED; return IRQ_HANDLED;
} }
void omap_mmc_notify_cover_event(struct device *dev, int slot, int is_closed) void omap_mmc_notify_cover_event(struct device *dev, int num, int is_closed)
{ {
int cover_open;
struct mmc_omap_host *host = dev_get_drvdata(dev); struct mmc_omap_host *host = dev_get_drvdata(dev);
struct mmc_omap_slot *slot = host->slots[num];
BUG_ON(slot >= host->nr_slots); BUG_ON(num >= host->nr_slots);
/* Other subsystems can call in here before we're initialised. */ /* Other subsystems can call in here before we're initialised. */
if (host->nr_slots == 0 || !host->slots[slot]) if (host->nr_slots == 0 || !host->slots[num])
return; return;
schedule_work(&host->slots[slot]->switch_work); cover_open = mmc_omap_cover_is_open(slot);
if (cover_open != slot->cover_open) {
slot->cover_open = cover_open;
sysfs_notify(&slot->mmc->class_dev.kobj, NULL, "cover_switch");
}
tasklet_hi_schedule(&slot->cover_tasklet);
} }
static void mmc_omap_switch_timer(unsigned long arg) static void mmc_omap_cover_timer(unsigned long arg)
{ {
struct mmc_omap_slot *slot = (struct mmc_omap_slot *) arg; struct mmc_omap_slot *slot = (struct mmc_omap_slot *) arg;
tasklet_schedule(&slot->cover_tasklet);
schedule_work(&slot->switch_work);
} }
static void mmc_omap_cover_handler(struct work_struct *work) static void mmc_omap_cover_handler(unsigned long param)
{ {
struct mmc_omap_slot *slot = container_of(work, struct mmc_omap_slot, struct mmc_omap_slot *slot = (struct mmc_omap_slot *)param;
switch_work); int cover_open = mmc_omap_cover_is_open(slot);
int cover_open;
cover_open = mmc_omap_cover_is_open(slot); mmc_detect_change(slot->mmc, 0);
if (cover_open != slot->cover_open) { if (!cover_open)
sysfs_notify(&slot->mmc->class_dev.kobj, NULL, "cover_switch"); return;
slot->cover_open = cover_open;
dev_info(mmc_dev(slot->mmc), "cover is now %s\n", /*
cover_open ? "open" : "closed"); * If no card is inserted, we postpone polling until
} * the cover has been closed.
mmc_detect_change(slot->mmc, slot->id); */
if (slot->mmc->card == NULL || !mmc_card_present(slot->mmc->card))
return;
mod_timer(&slot->cover_timer,
jiffies + msecs_to_jiffies(OMAP_MMC_COVER_POLL_DELAY));
} }
/* Prepare to transfer the next segment of a scatterlist */ /* Prepare to transfer the next segment of a scatterlist */
...@@ -1237,10 +1248,11 @@ static int __init mmc_omap_new_slot(struct mmc_omap_host *host, int id) ...@@ -1237,10 +1248,11 @@ static int __init mmc_omap_new_slot(struct mmc_omap_host *host, int id)
if (r < 0) if (r < 0)
goto err_remove_slot_name; goto err_remove_slot_name;
INIT_WORK(&slot->switch_work, mmc_omap_cover_handler); setup_timer(&slot->cover_timer, mmc_omap_cover_timer,
setup_timer(&slot->switch_timer, mmc_omap_switch_timer, (unsigned long)slot);
(unsigned long) slot); tasklet_init(&slot->cover_tasklet, mmc_omap_cover_handler,
schedule_work(&slot->switch_work); (unsigned long)slot);
tasklet_schedule(&slot->cover_tasklet);
} }
return 0; return 0;
...@@ -1263,7 +1275,8 @@ static void mmc_omap_remove_slot(struct mmc_omap_slot *slot) ...@@ -1263,7 +1275,8 @@ static void mmc_omap_remove_slot(struct mmc_omap_slot *slot)
if (slot->pdata->get_cover_state != NULL) if (slot->pdata->get_cover_state != NULL)
device_remove_file(&mmc->class_dev, &dev_attr_cover_switch); device_remove_file(&mmc->class_dev, &dev_attr_cover_switch);
del_timer_sync(&slot->switch_timer); tasklet_kill(&slot->cover_tasklet);
del_timer_sync(&slot->cover_timer);
flush_scheduled_work(); flush_scheduled_work();
mmc_remove_host(mmc); mmc_remove_host(mmc);
......
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