2007-05-19 12:06:24 +00:00
|
|
|
/*
|
|
|
|
* linux/drivers/mmc/core/host.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2003 Russell King, All Rights Reserved.
|
2008-03-08 22:43:19 +00:00
|
|
|
* Copyright (C) 2007-2008 Pierre Ossman
|
2010-11-09 02:36:50 +00:00
|
|
|
* Copyright (C) 2010 Linus Walleij
|
2007-05-19 12:06:24 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* MMC host class device management
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/idr.h>
|
|
|
|
#include <linux/pagemap.h>
|
2011-07-10 16:42:00 +00:00
|
|
|
#include <linux/export.h>
|
2007-09-24 05:15:48 +00:00
|
|
|
#include <linux/leds.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
mmc: fix all hangs related to mmc/sd card insert/removal during suspend/resume
If you don't use CONFIG_MMC_UNSAFE_RESUME, as soon as you attempt to
suspend, the card will be removed, therefore this patch doesn't change the
behavior of this option.
However the removal will be done by pm notifier, which runs while
userspace is still not frozen and thus can freely use del_gendisk, without
the risk of deadlock which would happen otherwise.
Card detect workqueue is now disabled while userspace is frozen, Therefore
if you do use CONFIG_MMC_UNSAFE_RESUME, and remove the card during
suspend, the removal will be detected as soon as userspace is unfrozen,
again at the moment it is safe to call del_gendisk.
Tested with and without CONFIG_MMC_UNSAFE_RESUME with suspend and hibernate.
[akpm@linux-foundation.org: clean up function prototype]
[akpm@linux-foundation.org: fix CONFIG_PM-n linkage, small cleanups]
[akpm@linux-foundation.org: coding-style fixes]
Signed-off-by: Maxim Levitsky <maximlevitsky@gmail.com>
Cc: David Brownell <david-b@pacbell.net>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: <linux-mmc@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2010-08-11 01:01:41 +00:00
|
|
|
#include <linux/suspend.h>
|
2007-05-19 12:06:24 +00:00
|
|
|
|
|
|
|
#include <linux/mmc/host.h>
|
2010-11-09 02:36:50 +00:00
|
|
|
#include <linux/mmc/card.h>
|
2007-05-19 12:06:24 +00:00
|
|
|
|
|
|
|
#include "core.h"
|
|
|
|
#include "host.h"
|
|
|
|
|
|
|
|
#define cls_dev_to_mmc_host(d) container_of(d, struct mmc_host, class_dev)
|
|
|
|
|
|
|
|
static void mmc_host_classdev_release(struct device *dev)
|
|
|
|
{
|
|
|
|
struct mmc_host *host = cls_dev_to_mmc_host(dev);
|
|
|
|
kfree(host);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct class mmc_host_class = {
|
|
|
|
.name = "mmc_host",
|
|
|
|
.dev_release = mmc_host_classdev_release,
|
|
|
|
};
|
|
|
|
|
|
|
|
int mmc_register_host_class(void)
|
|
|
|
{
|
|
|
|
return class_register(&mmc_host_class);
|
|
|
|
}
|
|
|
|
|
|
|
|
void mmc_unregister_host_class(void)
|
|
|
|
{
|
|
|
|
class_unregister(&mmc_host_class);
|
|
|
|
}
|
|
|
|
|
|
|
|
static DEFINE_IDR(mmc_host_idr);
|
|
|
|
static DEFINE_SPINLOCK(mmc_host_lock);
|
|
|
|
|
2010-11-09 02:36:50 +00:00
|
|
|
#ifdef CONFIG_MMC_CLKGATE
|
2011-11-14 08:23:29 +00:00
|
|
|
static ssize_t clkgate_delay_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct mmc_host *host = cls_dev_to_mmc_host(dev);
|
2011-12-05 18:28:44 +00:00
|
|
|
return snprintf(buf, PAGE_SIZE, "%lu\n", host->clkgate_delay);
|
2011-11-14 08:23:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t clkgate_delay_store(struct device *dev,
|
|
|
|
struct device_attribute *attr, const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
struct mmc_host *host = cls_dev_to_mmc_host(dev);
|
|
|
|
unsigned long flags, value;
|
|
|
|
|
|
|
|
if (kstrtoul(buf, 0, &value))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&host->clk_lock, flags);
|
|
|
|
host->clkgate_delay = value;
|
|
|
|
spin_unlock_irqrestore(&host->clk_lock, flags);
|
|
|
|
return count;
|
|
|
|
}
|
2010-11-09 02:36:50 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Enabling clock gating will make the core call out to the host
|
|
|
|
* once up and once down when it performs a request or card operation
|
|
|
|
* intermingled in any fashion. The driver will see this through
|
|
|
|
* set_ios() operations with ios.clock field set to 0 to gate (disable)
|
|
|
|
* the block clock, and to the old frequency to enable it again.
|
|
|
|
*/
|
|
|
|
static void mmc_host_clk_gate_delayed(struct mmc_host *host)
|
|
|
|
{
|
|
|
|
unsigned long tick_ns;
|
|
|
|
unsigned long freq = host->ios.clock;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (!freq) {
|
|
|
|
pr_debug("%s: frequency set to 0 in disable function, "
|
|
|
|
"this means the clock is already disabled.\n",
|
|
|
|
mmc_hostname(host));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* New requests may have appeared while we were scheduling,
|
|
|
|
* then there is no reason to delay the check before
|
|
|
|
* clk_disable().
|
|
|
|
*/
|
|
|
|
spin_lock_irqsave(&host->clk_lock, flags);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Delay n bus cycles (at least 8 from MMC spec) before attempting
|
|
|
|
* to disable the MCI block clock. The reference count may have
|
|
|
|
* gone up again after this delay due to rescheduling!
|
|
|
|
*/
|
|
|
|
if (!host->clk_requests) {
|
|
|
|
spin_unlock_irqrestore(&host->clk_lock, flags);
|
|
|
|
tick_ns = DIV_ROUND_UP(1000000000, freq);
|
|
|
|
ndelay(host->clk_delay * tick_ns);
|
|
|
|
} else {
|
|
|
|
/* New users appeared while waiting for this work */
|
|
|
|
spin_unlock_irqrestore(&host->clk_lock, flags);
|
|
|
|
return;
|
|
|
|
}
|
2011-05-16 15:32:26 +00:00
|
|
|
mutex_lock(&host->clk_gate_mutex);
|
2010-11-09 02:36:50 +00:00
|
|
|
spin_lock_irqsave(&host->clk_lock, flags);
|
|
|
|
if (!host->clk_requests) {
|
|
|
|
spin_unlock_irqrestore(&host->clk_lock, flags);
|
|
|
|
/* This will set host->ios.clock to 0 */
|
|
|
|
mmc_gate_clock(host);
|
|
|
|
spin_lock_irqsave(&host->clk_lock, flags);
|
|
|
|
pr_debug("%s: gated MCI clock\n", mmc_hostname(host));
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&host->clk_lock, flags);
|
2011-05-16 15:32:26 +00:00
|
|
|
mutex_unlock(&host->clk_gate_mutex);
|
2010-11-09 02:36:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Internal work. Work to disable the clock at some later point.
|
|
|
|
*/
|
|
|
|
static void mmc_host_clk_gate_work(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct mmc_host *host = container_of(work, struct mmc_host,
|
2011-11-14 08:23:29 +00:00
|
|
|
clk_gate_work.work);
|
2010-11-09 02:36:50 +00:00
|
|
|
|
|
|
|
mmc_host_clk_gate_delayed(host);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-08-18 12:23:47 +00:00
|
|
|
* mmc_host_clk_hold - ungate hardware MCI clocks
|
2010-11-09 02:36:50 +00:00
|
|
|
* @host: host to ungate.
|
|
|
|
*
|
|
|
|
* Makes sure the host ios.clock is restored to a non-zero value
|
|
|
|
* past this call. Increase clock reference count and ungate clock
|
|
|
|
* if we're the first user.
|
|
|
|
*/
|
2011-08-18 12:23:47 +00:00
|
|
|
void mmc_host_clk_hold(struct mmc_host *host)
|
2010-11-09 02:36:50 +00:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
2011-11-14 08:23:29 +00:00
|
|
|
/* cancel any clock gating work scheduled by mmc_host_clk_release() */
|
|
|
|
cancel_delayed_work_sync(&host->clk_gate_work);
|
2011-05-16 15:32:26 +00:00
|
|
|
mutex_lock(&host->clk_gate_mutex);
|
2010-11-09 02:36:50 +00:00
|
|
|
spin_lock_irqsave(&host->clk_lock, flags);
|
|
|
|
if (host->clk_gated) {
|
|
|
|
spin_unlock_irqrestore(&host->clk_lock, flags);
|
|
|
|
mmc_ungate_clock(host);
|
|
|
|
spin_lock_irqsave(&host->clk_lock, flags);
|
|
|
|
pr_debug("%s: ungated MCI clock\n", mmc_hostname(host));
|
|
|
|
}
|
|
|
|
host->clk_requests++;
|
|
|
|
spin_unlock_irqrestore(&host->clk_lock, flags);
|
2011-05-16 15:32:26 +00:00
|
|
|
mutex_unlock(&host->clk_gate_mutex);
|
2010-11-09 02:36:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mmc_host_may_gate_card - check if this card may be gated
|
|
|
|
* @card: card to check.
|
|
|
|
*/
|
|
|
|
static bool mmc_host_may_gate_card(struct mmc_card *card)
|
|
|
|
{
|
|
|
|
/* If there is no card we may gate it */
|
|
|
|
if (!card)
|
|
|
|
return true;
|
|
|
|
/*
|
|
|
|
* Don't gate SDIO cards! These need to be clocked at all times
|
|
|
|
* since they may be independent systems generating interrupts
|
|
|
|
* and other events. The clock requests counter from the core will
|
|
|
|
* go down to zero since the core does not need it, but we will not
|
|
|
|
* gate the clock, because there is somebody out there that may still
|
|
|
|
* be using it.
|
|
|
|
*/
|
2011-02-06 18:03:47 +00:00
|
|
|
return !(card->quirks & MMC_QUIRK_BROKEN_CLK_GATING);
|
2010-11-09 02:36:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-08-18 12:23:47 +00:00
|
|
|
* mmc_host_clk_release - gate off hardware MCI clocks
|
2010-11-09 02:36:50 +00:00
|
|
|
* @host: host to gate.
|
|
|
|
*
|
|
|
|
* Calls the host driver with ios.clock set to zero as often as possible
|
|
|
|
* in order to gate off hardware MCI clocks. Decrease clock reference
|
|
|
|
* count and schedule disabling of clock.
|
|
|
|
*/
|
2011-08-18 12:23:47 +00:00
|
|
|
void mmc_host_clk_release(struct mmc_host *host)
|
2010-11-09 02:36:50 +00:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&host->clk_lock, flags);
|
|
|
|
host->clk_requests--;
|
|
|
|
if (mmc_host_may_gate_card(host->card) &&
|
|
|
|
!host->clk_requests)
|
2011-11-14 08:23:29 +00:00
|
|
|
queue_delayed_work(system_nrt_wq, &host->clk_gate_work,
|
|
|
|
msecs_to_jiffies(host->clkgate_delay));
|
2010-11-09 02:36:50 +00:00
|
|
|
spin_unlock_irqrestore(&host->clk_lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mmc_host_clk_rate - get current clock frequency setting
|
|
|
|
* @host: host to get the clock frequency for.
|
|
|
|
*
|
|
|
|
* Returns current clock frequency regardless of gating.
|
|
|
|
*/
|
|
|
|
unsigned int mmc_host_clk_rate(struct mmc_host *host)
|
|
|
|
{
|
|
|
|
unsigned long freq;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&host->clk_lock, flags);
|
|
|
|
if (host->clk_gated)
|
|
|
|
freq = host->clk_old;
|
|
|
|
else
|
|
|
|
freq = host->ios.clock;
|
|
|
|
spin_unlock_irqrestore(&host->clk_lock, flags);
|
|
|
|
return freq;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mmc_host_clk_init - set up clock gating code
|
|
|
|
* @host: host with potential clock to control
|
|
|
|
*/
|
|
|
|
static inline void mmc_host_clk_init(struct mmc_host *host)
|
|
|
|
{
|
|
|
|
host->clk_requests = 0;
|
|
|
|
/* Hold MCI clock for 8 cycles by default */
|
|
|
|
host->clk_delay = 8;
|
2011-11-14 08:23:29 +00:00
|
|
|
/*
|
2012-02-23 10:22:29 +00:00
|
|
|
* Default clock gating delay is 0ms to avoid wasting power.
|
2011-11-14 08:23:29 +00:00
|
|
|
* This value can be tuned by writing into sysfs entry.
|
|
|
|
*/
|
2012-02-23 10:22:29 +00:00
|
|
|
host->clkgate_delay = 0;
|
2010-11-09 02:36:50 +00:00
|
|
|
host->clk_gated = false;
|
2011-11-14 08:23:29 +00:00
|
|
|
INIT_DELAYED_WORK(&host->clk_gate_work, mmc_host_clk_gate_work);
|
2010-11-09 02:36:50 +00:00
|
|
|
spin_lock_init(&host->clk_lock);
|
2011-05-16 15:32:26 +00:00
|
|
|
mutex_init(&host->clk_gate_mutex);
|
2010-11-09 02:36:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mmc_host_clk_exit - shut down clock gating code
|
|
|
|
* @host: host with potential clock to control
|
|
|
|
*/
|
|
|
|
static inline void mmc_host_clk_exit(struct mmc_host *host)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Wait for any outstanding gate and then make sure we're
|
|
|
|
* ungated before exiting.
|
|
|
|
*/
|
2011-11-14 08:23:29 +00:00
|
|
|
if (cancel_delayed_work_sync(&host->clk_gate_work))
|
2010-11-09 02:36:50 +00:00
|
|
|
mmc_host_clk_gate_delayed(host);
|
|
|
|
if (host->clk_gated)
|
2011-08-18 12:23:47 +00:00
|
|
|
mmc_host_clk_hold(host);
|
2010-12-22 08:50:12 +00:00
|
|
|
/* There should be only one user now */
|
|
|
|
WARN_ON(host->clk_requests > 1);
|
2010-11-09 02:36:50 +00:00
|
|
|
}
|
|
|
|
|
2011-11-14 08:23:29 +00:00
|
|
|
static inline void mmc_host_clk_sysfs_init(struct mmc_host *host)
|
|
|
|
{
|
|
|
|
host->clkgate_delay_attr.show = clkgate_delay_show;
|
|
|
|
host->clkgate_delay_attr.store = clkgate_delay_store;
|
|
|
|
sysfs_attr_init(&host->clkgate_delay_attr.attr);
|
|
|
|
host->clkgate_delay_attr.attr.name = "clkgate_delay";
|
|
|
|
host->clkgate_delay_attr.attr.mode = S_IRUGO | S_IWUSR;
|
|
|
|
if (device_create_file(&host->class_dev, &host->clkgate_delay_attr))
|
|
|
|
pr_err("%s: Failed to create clkgate_delay sysfs entry\n",
|
|
|
|
mmc_hostname(host));
|
|
|
|
}
|
2010-11-09 02:36:50 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
static inline void mmc_host_clk_init(struct mmc_host *host)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void mmc_host_clk_exit(struct mmc_host *host)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-11-14 08:23:29 +00:00
|
|
|
static inline void mmc_host_clk_sysfs_init(struct mmc_host *host)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-11-09 02:36:50 +00:00
|
|
|
#endif
|
|
|
|
|
2007-05-19 12:06:24 +00:00
|
|
|
/**
|
|
|
|
* mmc_alloc_host - initialise the per-host structure.
|
|
|
|
* @extra: sizeof private data structure
|
|
|
|
* @dev: pointer to host device model structure
|
|
|
|
*
|
|
|
|
* Initialise the per-host structure.
|
|
|
|
*/
|
|
|
|
struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
|
|
|
|
{
|
2008-03-08 22:43:19 +00:00
|
|
|
int err;
|
2007-05-19 12:06:24 +00:00
|
|
|
struct mmc_host *host;
|
|
|
|
|
2008-03-08 22:43:19 +00:00
|
|
|
if (!idr_pre_get(&mmc_host_idr, GFP_KERNEL))
|
|
|
|
return NULL;
|
|
|
|
|
2007-08-10 21:00:50 +00:00
|
|
|
host = kzalloc(sizeof(struct mmc_host) + extra, GFP_KERNEL);
|
2007-05-19 12:06:24 +00:00
|
|
|
if (!host)
|
|
|
|
return NULL;
|
|
|
|
|
2008-03-08 22:43:19 +00:00
|
|
|
spin_lock(&mmc_host_lock);
|
|
|
|
err = idr_get_new(&mmc_host_idr, host, &host->index);
|
|
|
|
spin_unlock(&mmc_host_lock);
|
|
|
|
if (err)
|
|
|
|
goto free;
|
|
|
|
|
2008-11-08 20:37:46 +00:00
|
|
|
dev_set_name(&host->class_dev, "mmc%d", host->index);
|
2008-03-08 22:43:19 +00:00
|
|
|
|
2007-05-19 12:06:24 +00:00
|
|
|
host->parent = dev;
|
|
|
|
host->class_dev.parent = dev;
|
|
|
|
host->class_dev.class = &mmc_host_class;
|
|
|
|
device_initialize(&host->class_dev);
|
|
|
|
|
2010-11-09 02:36:50 +00:00
|
|
|
mmc_host_clk_init(host);
|
|
|
|
|
2007-05-19 12:06:24 +00:00
|
|
|
spin_lock_init(&host->lock);
|
|
|
|
init_waitqueue_head(&host->wq);
|
|
|
|
INIT_DELAYED_WORK(&host->detect, mmc_rescan);
|
2010-08-18 16:25:38 +00:00
|
|
|
#ifdef CONFIG_PM
|
mmc: fix all hangs related to mmc/sd card insert/removal during suspend/resume
If you don't use CONFIG_MMC_UNSAFE_RESUME, as soon as you attempt to
suspend, the card will be removed, therefore this patch doesn't change the
behavior of this option.
However the removal will be done by pm notifier, which runs while
userspace is still not frozen and thus can freely use del_gendisk, without
the risk of deadlock which would happen otherwise.
Card detect workqueue is now disabled while userspace is frozen, Therefore
if you do use CONFIG_MMC_UNSAFE_RESUME, and remove the card during
suspend, the removal will be detected as soon as userspace is unfrozen,
again at the moment it is safe to call del_gendisk.
Tested with and without CONFIG_MMC_UNSAFE_RESUME with suspend and hibernate.
[akpm@linux-foundation.org: clean up function prototype]
[akpm@linux-foundation.org: fix CONFIG_PM-n linkage, small cleanups]
[akpm@linux-foundation.org: coding-style fixes]
Signed-off-by: Maxim Levitsky <maximlevitsky@gmail.com>
Cc: David Brownell <david-b@pacbell.net>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: <linux-mmc@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2010-08-11 01:01:41 +00:00
|
|
|
host->pm_notify.notifier_call = mmc_pm_notify;
|
2010-08-18 16:25:38 +00:00
|
|
|
#endif
|
2007-05-19 12:06:24 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* By default, hosts do not support SGIO or large requests.
|
|
|
|
* They have to set these according to their abilities.
|
|
|
|
*/
|
2010-09-10 05:33:59 +00:00
|
|
|
host->max_segs = 1;
|
2007-05-19 12:06:24 +00:00
|
|
|
host->max_seg_size = PAGE_CACHE_SIZE;
|
|
|
|
|
|
|
|
host->max_req_size = PAGE_CACHE_SIZE;
|
|
|
|
host->max_blk_size = 512;
|
|
|
|
host->max_blk_count = PAGE_CACHE_SIZE / 512;
|
|
|
|
|
|
|
|
return host;
|
2008-03-08 22:43:19 +00:00
|
|
|
|
|
|
|
free:
|
|
|
|
kfree(host);
|
|
|
|
return NULL;
|
2007-05-19 12:06:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(mmc_alloc_host);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mmc_add_host - initialise host hardware
|
|
|
|
* @host: mmc host
|
2007-07-11 18:22:11 +00:00
|
|
|
*
|
|
|
|
* Register the host with the driver model. The host must be
|
|
|
|
* prepared to start servicing requests before this function
|
|
|
|
* completes.
|
2007-05-19 12:06:24 +00:00
|
|
|
*/
|
|
|
|
int mmc_add_host(struct mmc_host *host)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
2007-07-24 06:09:39 +00:00
|
|
|
WARN_ON((host->caps & MMC_CAP_SDIO_IRQ) &&
|
|
|
|
!host->ops->enable_sdio_irq);
|
|
|
|
|
2007-05-19 12:06:24 +00:00
|
|
|
err = device_add(&host->class_dev);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2011-04-11 04:11:29 +00:00
|
|
|
led_trigger_register_simple(dev_name(&host->class_dev), &host->led);
|
|
|
|
|
2008-07-24 12:18:57 +00:00
|
|
|
#ifdef CONFIG_DEBUG_FS
|
|
|
|
mmc_add_host_debugfs(host);
|
|
|
|
#endif
|
2011-11-14 08:23:29 +00:00
|
|
|
mmc_host_clk_sysfs_init(host);
|
2008-07-24 12:18:57 +00:00
|
|
|
|
2007-05-19 12:06:24 +00:00
|
|
|
mmc_start_host(host);
|
mmc: fix all hangs related to mmc/sd card insert/removal during suspend/resume
If you don't use CONFIG_MMC_UNSAFE_RESUME, as soon as you attempt to
suspend, the card will be removed, therefore this patch doesn't change the
behavior of this option.
However the removal will be done by pm notifier, which runs while
userspace is still not frozen and thus can freely use del_gendisk, without
the risk of deadlock which would happen otherwise.
Card detect workqueue is now disabled while userspace is frozen, Therefore
if you do use CONFIG_MMC_UNSAFE_RESUME, and remove the card during
suspend, the removal will be detected as soon as userspace is unfrozen,
again at the moment it is safe to call del_gendisk.
Tested with and without CONFIG_MMC_UNSAFE_RESUME with suspend and hibernate.
[akpm@linux-foundation.org: clean up function prototype]
[akpm@linux-foundation.org: fix CONFIG_PM-n linkage, small cleanups]
[akpm@linux-foundation.org: coding-style fixes]
Signed-off-by: Maxim Levitsky <maximlevitsky@gmail.com>
Cc: David Brownell <david-b@pacbell.net>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: <linux-mmc@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2010-08-11 01:01:41 +00:00
|
|
|
register_pm_notifier(&host->pm_notify);
|
2007-05-19 12:06:24 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(mmc_add_host);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mmc_remove_host - remove host hardware
|
|
|
|
* @host: mmc host
|
|
|
|
*
|
|
|
|
* Unregister and remove all cards associated with this host,
|
2007-07-11 18:22:11 +00:00
|
|
|
* and power down the MMC bus. No new requests will be issued
|
|
|
|
* after this function has returned.
|
2007-05-19 12:06:24 +00:00
|
|
|
*/
|
|
|
|
void mmc_remove_host(struct mmc_host *host)
|
|
|
|
{
|
mmc: fix all hangs related to mmc/sd card insert/removal during suspend/resume
If you don't use CONFIG_MMC_UNSAFE_RESUME, as soon as you attempt to
suspend, the card will be removed, therefore this patch doesn't change the
behavior of this option.
However the removal will be done by pm notifier, which runs while
userspace is still not frozen and thus can freely use del_gendisk, without
the risk of deadlock which would happen otherwise.
Card detect workqueue is now disabled while userspace is frozen, Therefore
if you do use CONFIG_MMC_UNSAFE_RESUME, and remove the card during
suspend, the removal will be detected as soon as userspace is unfrozen,
again at the moment it is safe to call del_gendisk.
Tested with and without CONFIG_MMC_UNSAFE_RESUME with suspend and hibernate.
[akpm@linux-foundation.org: clean up function prototype]
[akpm@linux-foundation.org: fix CONFIG_PM-n linkage, small cleanups]
[akpm@linux-foundation.org: coding-style fixes]
Signed-off-by: Maxim Levitsky <maximlevitsky@gmail.com>
Cc: David Brownell <david-b@pacbell.net>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: <linux-mmc@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2010-08-11 01:01:41 +00:00
|
|
|
unregister_pm_notifier(&host->pm_notify);
|
2007-05-19 12:06:24 +00:00
|
|
|
mmc_stop_host(host);
|
|
|
|
|
2008-07-24 12:18:57 +00:00
|
|
|
#ifdef CONFIG_DEBUG_FS
|
|
|
|
mmc_remove_host_debugfs(host);
|
|
|
|
#endif
|
|
|
|
|
2007-05-19 12:06:24 +00:00
|
|
|
device_del(&host->class_dev);
|
|
|
|
|
2007-10-12 20:48:46 +00:00
|
|
|
led_trigger_unregister_simple(host->led);
|
2010-11-09 02:36:50 +00:00
|
|
|
|
|
|
|
mmc_host_clk_exit(host);
|
2007-05-19 12:06:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(mmc_remove_host);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mmc_free_host - free the host structure
|
|
|
|
* @host: mmc host
|
|
|
|
*
|
|
|
|
* Free the host once all references to it have been dropped.
|
|
|
|
*/
|
|
|
|
void mmc_free_host(struct mmc_host *host)
|
|
|
|
{
|
2008-03-08 22:43:19 +00:00
|
|
|
spin_lock(&mmc_host_lock);
|
|
|
|
idr_remove(&mmc_host_idr, host->index);
|
|
|
|
spin_unlock(&mmc_host_lock);
|
|
|
|
|
2007-05-19 12:06:24 +00:00
|
|
|
put_device(&host->class_dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(mmc_free_host);
|