Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c4cda98f authored by San Mehat's avatar San Mehat Committed by Ruchi Kandoi
Browse files

mmc: core: Hold a wake lock accross delayed work + mmc rescan



Signed-off-by: default avatarSan Mehat <san@android.com>

mmc: core: Rework mmc_delayed_work wakelock so that the wakelock is only extended if a card is added or removed.

Signed-off-by: default avatarSan Mehat <san@google.com>
parent 12e626dd
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@
#include <linux/random.h>
#include <linux/slab.h>
#include <linux/of.h>
#include <linux/wakelock.h>

#include <linux/mmc/card.h>
#include <linux/mmc/host.h>
@@ -55,6 +56,7 @@
#define MMC_BKOPS_MAX_TIMEOUT	(4 * 60 * 1000) /* max time to wait in ms */

static struct workqueue_struct *workqueue;
static struct wake_lock mmc_delayed_work_wake_lock;
static const unsigned freqs[] = { 400000, 300000, 200000, 100000 };

/*
@@ -71,6 +73,7 @@ module_param(use_spi_crc, bool, 0);
static int mmc_schedule_delayed_work(struct delayed_work *work,
				     unsigned long delay)
{
	wake_lock(&mmc_delayed_work_wake_lock);
	return queue_delayed_work(workqueue, work, delay);
}

@@ -2411,6 +2414,7 @@ void mmc_rescan(struct work_struct *work)
	struct mmc_host *host =
		container_of(work, struct mmc_host, detect.work);
	int i;
	bool extend_wakelock = false;

	if (host->trigger_card_event && host->ops->card_event) {
		host->ops->card_event(host);
@@ -2466,14 +2470,20 @@ void mmc_rescan(struct work_struct *work)

	mmc_claim_host(host);
	for (i = 0; i < ARRAY_SIZE(freqs); i++) {
		if (!mmc_rescan_try_freq(host, max(freqs[i], host->f_min)))
		if (!mmc_rescan_try_freq(host, max(freqs[i], host->f_min))) {
			extend_wakelock = true;
			break;
		}
		if (freqs[i] <= host->f_min)
			break;
	}
	mmc_release_host(host);

 out:
	if (extend_wakelock)
		wake_lock_timeout(&mmc_delayed_work_wake_lock, HZ / 2);
	else
		wake_unlock(&mmc_delayed_work_wake_lock);
	if (host->caps & MMC_CAP_NEEDS_POLL)
		mmc_schedule_delayed_work(&host->detect, HZ);
}
@@ -2694,6 +2704,9 @@ static int __init mmc_init(void)
	if (!workqueue)
		return -ENOMEM;

	wake_lock_init(&mmc_delayed_work_wake_lock, WAKE_LOCK_SUSPEND,
		       "mmc_delayed_work");

	ret = mmc_register_bus();
	if (ret)
		goto destroy_workqueue;
@@ -2714,6 +2727,7 @@ unregister_bus:
	mmc_unregister_bus();
destroy_workqueue:
	destroy_workqueue(workqueue);
	wake_lock_destroy(&mmc_delayed_work_wake_lock);

	return ret;
}
@@ -2724,6 +2738,7 @@ static void __exit mmc_exit(void)
	mmc_unregister_host_class();
	mmc_unregister_bus();
	destroy_workqueue(workqueue);
	wake_lock_destroy(&mmc_delayed_work_wake_lock);
}

subsys_initcall(mmc_init);