host.c 17.9 KB
Newer Older
1 2 3 4
/*
 *  linux/drivers/mmc/core/host.c
 *
 *  Copyright (C) 2003 Russell King, All Rights Reserved.
P
Pierre Ossman 已提交
5
 *  Copyright (C) 2007-2008 Pierre Ossman
6
 *  Copyright (C) 2010 Linus Walleij
7 8 9 10 11 12 13 14 15 16 17
 *
 * 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>
18 19
#include <linux/of.h>
#include <linux/of_gpio.h>
20
#include <linux/pagemap.h>
21
#include <linux/export.h>
P
Pierre Ossman 已提交
22
#include <linux/leds.h>
23
#include <linux/slab.h>
24
#include <linux/suspend.h>
25 26

#include <linux/mmc/host.h>
27
#include <linux/mmc/card.h>
28
#include <linux/mmc/slot-gpio.h>
29 30 31

#include "core.h"
#include "host.h"
32
#include "slot-gpio.h"
33
#include "pwrseq.h"
34 35 36

#define cls_dev_to_mmc_host(d)	container_of(d, struct mmc_host, class_dev)

37 38 39
static DEFINE_IDR(mmc_host_idr);
static DEFINE_SPINLOCK(mmc_host_lock);

40 41 42
static void mmc_host_classdev_release(struct device *dev)
{
	struct mmc_host *host = cls_dev_to_mmc_host(dev);
43 44 45
	spin_lock(&mmc_host_lock);
	idr_remove(&mmc_host_idr, host->index);
	spin_unlock(&mmc_host_lock);
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
	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);
}

64
#ifdef CONFIG_MMC_CLKGATE
65 66 67 68
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);
69
	return snprintf(buf, PAGE_SIZE, "%lu\n", host->clkgate_delay);
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
}

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;
}
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126

/*
 * 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;
	}
127
	mutex_lock(&host->clk_gate_mutex);
128 129 130 131 132 133 134 135 136
	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);
137
	mutex_unlock(&host->clk_gate_mutex);
138 139 140 141 142 143 144 145
}

/*
 * 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,
146
					      clk_gate_work.work);
147 148 149 150 151

	mmc_host_clk_gate_delayed(host);
}

/**
152
 *	mmc_host_clk_hold - ungate hardware MCI clocks
153 154 155 156 157 158
 *	@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.
 */
159
void mmc_host_clk_hold(struct mmc_host *host)
160 161 162
{
	unsigned long flags;

163 164
	/* cancel any clock gating work scheduled by mmc_host_clk_release() */
	cancel_delayed_work_sync(&host->clk_gate_work);
165
	mutex_lock(&host->clk_gate_mutex);
166 167 168 169 170 171 172 173 174
	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);
175
	mutex_unlock(&host->clk_gate_mutex);
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
}

/**
 *	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.
	 */
195
	return !(card->quirks & MMC_QUIRK_BROKEN_CLK_GATING);
196 197 198
}

/**
199
 *	mmc_host_clk_release - gate off hardware MCI clocks
200 201 202 203 204 205
 *	@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.
 */
206
void mmc_host_clk_release(struct mmc_host *host)
207 208 209 210 211 212 213
{
	unsigned long flags;

	spin_lock_irqsave(&host->clk_lock, flags);
	host->clk_requests--;
	if (mmc_host_may_gate_card(host->card) &&
	    !host->clk_requests)
214 215
		schedule_delayed_work(&host->clk_gate_work,
				      msecs_to_jiffies(host->clkgate_delay));
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
	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;
248
	/*
249
	 * Default clock gating delay is 0ms to avoid wasting power.
250 251
	 * This value can be tuned by writing into sysfs entry.
	 */
252
	host->clkgate_delay = 0;
253
	host->clk_gated = false;
254
	INIT_DELAYED_WORK(&host->clk_gate_work, mmc_host_clk_gate_work);
255
	spin_lock_init(&host->clk_lock);
256
	mutex_init(&host->clk_gate_mutex);
257 258 259 260 261 262 263 264 265 266 267 268
}

/**
 *	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.
	 */
269
	if (cancel_delayed_work_sync(&host->clk_gate_work))
270 271
		mmc_host_clk_gate_delayed(host);
	if (host->clk_gated)
272
		mmc_host_clk_hold(host);
273 274
	/* There should be only one user now */
	WARN_ON(host->clk_requests > 1);
275 276
}

277 278 279 280 281 282 283 284 285 286 287
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));
}
288 289 290 291 292 293 294 295 296 297
#else

static inline void mmc_host_clk_init(struct mmc_host *host)
{
}

static inline void mmc_host_clk_exit(struct mmc_host *host)
{
}

298 299 300 301
static inline void mmc_host_clk_sysfs_init(struct mmc_host *host)
{
}

302 303
#endif

304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
void mmc_retune_enable(struct mmc_host *host)
{
	host->can_retune = 1;
	if (host->retune_period)
		mod_timer(&host->retune_timer,
			  jiffies + host->retune_period * HZ);
}

void mmc_retune_disable(struct mmc_host *host)
{
	host->can_retune = 0;
	del_timer_sync(&host->retune_timer);
	host->retune_now = 0;
	host->need_retune = 0;
}

void mmc_retune_timer_stop(struct mmc_host *host)
{
	del_timer_sync(&host->retune_timer);
}
EXPORT_SYMBOL(mmc_retune_timer_stop);

void mmc_retune_hold(struct mmc_host *host)
{
	if (!host->hold_retune)
		host->retune_now = 1;
	host->hold_retune += 1;
}

void mmc_retune_release(struct mmc_host *host)
{
	if (host->hold_retune)
		host->hold_retune -= 1;
	else
		WARN_ON(1);
}

int mmc_retune(struct mmc_host *host)
{
343
	bool return_to_hs400 = false;
344 345 346 347 348 349 350 351 352 353 354 355 356 357
	int err;

	if (host->retune_now)
		host->retune_now = 0;
	else
		return 0;

	if (!host->need_retune || host->doing_retune || !host->card)
		return 0;

	host->need_retune = 0;

	host->doing_retune = 1;

358 359 360 361 362 363 364 365 366 367 368
	if (host->ios.timing == MMC_TIMING_MMC_HS400) {
		err = mmc_hs400_to_hs200(host->card);
		if (err)
			goto out;

		return_to_hs400 = true;

		if (host->ops->prepare_hs400_tuning)
			host->ops->prepare_hs400_tuning(host, &host->ios);
	}

369
	err = mmc_execute_tuning(host->card);
370 371
	if (err)
		goto out;
372

373 374 375
	if (return_to_hs400)
		err = mmc_hs200_to_hs400(host->card);
out:
376 377 378 379 380 381 382 383 384 385 386 387
	host->doing_retune = 0;

	return err;
}

static void mmc_retune_timer(unsigned long data)
{
	struct mmc_host *host = (struct mmc_host *)data;

	mmc_retune_needed(host);
}

388 389 390 391 392 393 394 395 396
/**
 *	mmc_of_parse() - parse host's device-tree node
 *	@host: host whose node should be parsed.
 *
 * To keep the rest of the MMC subsystem unaware of whether DT has been
 * used to to instantiate and configure this host instance or not, we
 * parse the properties and set respective generic mmc-host flags and
 * parameters.
 */
397
int mmc_of_parse(struct mmc_host *host)
398 399 400
{
	struct device_node *np;
	u32 bus_width;
401
	int len, ret;
402 403
	bool cd_cap_invert, cd_gpio_invert = false;
	bool ro_cap_invert, ro_gpio_invert = false;
404 405

	if (!host->parent || !host->parent->of_node)
406
		return 0;
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427

	np = host->parent->of_node;

	/* "bus-width" is translated to MMC_CAP_*_BIT_DATA flags */
	if (of_property_read_u32(np, "bus-width", &bus_width) < 0) {
		dev_dbg(host->parent,
			"\"bus-width\" property is missing, assuming 1 bit.\n");
		bus_width = 1;
	}

	switch (bus_width) {
	case 8:
		host->caps |= MMC_CAP_8_BIT_DATA;
		/* Hosts capable of 8-bit transfers can also do 4 bits */
	case 4:
		host->caps |= MMC_CAP_4_BIT_DATA;
		break;
	case 1:
		break;
	default:
		dev_err(host->parent,
428
			"Invalid \"bus-width\" value %u!\n", bus_width);
429
		return -EINVAL;
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450
	}

	/* f_max is obtained from the optional "max-frequency" property */
	of_property_read_u32(np, "max-frequency", &host->f_max);

	/*
	 * Configure CD and WP pins. They are both by default active low to
	 * match the SDHCI spec. If GPIOs are provided for CD and / or WP, the
	 * mmc-gpio helpers are used to attach, configure and use them. If
	 * polarity inversion is specified in DT, one of MMC_CAP2_CD_ACTIVE_HIGH
	 * and MMC_CAP2_RO_ACTIVE_HIGH capability-2 flags is set. If the
	 * "broken-cd" property is provided, the MMC_CAP_NEEDS_POLL capability
	 * is set. If the "non-removable" property is found, the
	 * MMC_CAP_NONREMOVABLE capability is set and no card-detection
	 * configuration is performed.
	 */

	/* Parse Card Detection */
	if (of_find_property(np, "non-removable", &len)) {
		host->caps |= MMC_CAP_NONREMOVABLE;
	} else {
451
		cd_cap_invert = of_property_read_bool(np, "cd-inverted");
452 453 454 455

		if (of_find_property(np, "broken-cd", &len))
			host->caps |= MMC_CAP_NEEDS_POLL;

456
		ret = mmc_gpiod_request_cd(host, "cd", 0, true,
457
					   0, &cd_gpio_invert);
458
		if (!ret)
459
			dev_info(host->parent, "Got CD GPIO\n");
460 461
		else if (ret != -ENOENT)
			return ret;
462 463 464 465 466 467 468 469 470 471 472 473

		/*
		 * There are two ways to flag that the CD line is inverted:
		 * through the cd-inverted flag and by the GPIO line itself
		 * being inverted from the GPIO subsystem. This is a leftover
		 * from the times when the GPIO subsystem did not make it
		 * possible to flag a line as inverted.
		 *
		 * If the capability on the host AND the GPIO line are
		 * both inverted, the end result is that the CD line is
		 * not inverted.
		 */
474
		if (cd_cap_invert ^ cd_gpio_invert)
475
			host->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH;
476 477 478
	}

	/* Parse Write Protection */
479
	ro_cap_invert = of_property_read_bool(np, "wp-inverted");
480

481
	ret = mmc_gpiod_request_ro(host, "wp", 0, false, 0, &ro_gpio_invert);
482
	if (!ret)
483
		dev_info(host->parent, "Got WP GPIO\n");
484 485
	else if (ret != -ENOENT)
		return ret;
486

487 488 489
	if (of_property_read_bool(np, "disable-wp"))
		host->caps2 |= MMC_CAP2_NO_WRITE_PROTECT;

490
	/* See the comment on CD inversion above */
491
	if (ro_cap_invert ^ ro_gpio_invert)
492 493
		host->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH;

494 495 496 497
	if (of_find_property(np, "cap-sd-highspeed", &len))
		host->caps |= MMC_CAP_SD_HIGHSPEED;
	if (of_find_property(np, "cap-mmc-highspeed", &len))
		host->caps |= MMC_CAP_MMC_HIGHSPEED;
498 499 500 501 502 503 504 505 506 507
	if (of_find_property(np, "sd-uhs-sdr12", &len))
		host->caps |= MMC_CAP_UHS_SDR12;
	if (of_find_property(np, "sd-uhs-sdr25", &len))
		host->caps |= MMC_CAP_UHS_SDR25;
	if (of_find_property(np, "sd-uhs-sdr50", &len))
		host->caps |= MMC_CAP_UHS_SDR50;
	if (of_find_property(np, "sd-uhs-sdr104", &len))
		host->caps |= MMC_CAP_UHS_SDR104;
	if (of_find_property(np, "sd-uhs-ddr50", &len))
		host->caps |= MMC_CAP_UHS_DDR50;
508 509 510 511
	if (of_find_property(np, "cap-power-off-card", &len))
		host->caps |= MMC_CAP_POWER_OFF_CARD;
	if (of_find_property(np, "cap-sdio-irq", &len))
		host->caps |= MMC_CAP_SDIO_IRQ;
512 513
	if (of_find_property(np, "full-pwr-cycle", &len))
		host->caps2 |= MMC_CAP2_FULL_PWR_CYCLE;
514 515 516 517
	if (of_find_property(np, "keep-power-in-suspend", &len))
		host->pm_caps |= MMC_PM_KEEP_POWER;
	if (of_find_property(np, "enable-sdio-wakeup", &len))
		host->pm_caps |= MMC_PM_WAKE_SDIO_IRQ;
518 519 520 521
	if (of_find_property(np, "mmc-ddr-1_8v", &len))
		host->caps |= MMC_CAP_1_8V_DDR;
	if (of_find_property(np, "mmc-ddr-1_2v", &len))
		host->caps |= MMC_CAP_1_2V_DDR;
522 523 524 525
	if (of_find_property(np, "mmc-hs200-1_8v", &len))
		host->caps2 |= MMC_CAP2_HS200_1_8V_SDR;
	if (of_find_property(np, "mmc-hs200-1_2v", &len))
		host->caps2 |= MMC_CAP2_HS200_1_2V_SDR;
526 527 528 529
	if (of_find_property(np, "mmc-hs400-1_8v", &len))
		host->caps2 |= MMC_CAP2_HS400_1_8V | MMC_CAP2_HS200_1_8V_SDR;
	if (of_find_property(np, "mmc-hs400-1_2v", &len))
		host->caps2 |= MMC_CAP2_HS400_1_2V | MMC_CAP2_HS200_1_2V_SDR;
530

531 532 533 534 535 536 537 538
	host->dsr_req = !of_property_read_u32(np, "dsr", &host->dsr);
	if (host->dsr_req && (host->dsr & ~0xffff)) {
		dev_err(host->parent,
			"device tree specified broken value for DSR: 0x%x, ignoring\n",
			host->dsr);
		host->dsr_req = 0;
	}

539
	return mmc_pwrseq_alloc(host);
540 541 542 543
}

EXPORT_SYMBOL(mmc_of_parse);

544 545 546 547 548 549 550 551 552
/**
 *	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)
{
P
Pierre Ossman 已提交
553
	int err;
554 555
	struct mmc_host *host;

556
	host = kzalloc(sizeof(struct mmc_host) + extra, GFP_KERNEL);
557 558 559
	if (!host)
		return NULL;

560 561
	/* scanning will be enabled when we're ready */
	host->rescan_disable = 1;
T
Tejun Heo 已提交
562
	idr_preload(GFP_KERNEL);
P
Pierre Ossman 已提交
563
	spin_lock(&mmc_host_lock);
T
Tejun Heo 已提交
564 565 566
	err = idr_alloc(&mmc_host_idr, host, 0, 0, GFP_NOWAIT);
	if (err >= 0)
		host->index = err;
P
Pierre Ossman 已提交
567
	spin_unlock(&mmc_host_lock);
T
Tejun Heo 已提交
568
	idr_preload_end();
569 570 571 572
	if (err < 0) {
		kfree(host);
		return NULL;
	}
P
Pierre Ossman 已提交
573

574
	dev_set_name(&host->class_dev, "mmc%d", host->index);
P
Pierre Ossman 已提交
575

576 577 578 579 580
	host->parent = dev;
	host->class_dev.parent = dev;
	host->class_dev.class = &mmc_host_class;
	device_initialize(&host->class_dev);

581 582 583 584
	if (mmc_gpio_alloc(host)) {
		put_device(&host->class_dev);
		return NULL;
	}
585

586
	mmc_host_clk_init(host);
587

588 589 590
	spin_lock_init(&host->lock);
	init_waitqueue_head(&host->wq);
	INIT_DELAYED_WORK(&host->detect, mmc_rescan);
591
#ifdef CONFIG_PM
592
	host->pm_notify.notifier_call = mmc_pm_notify;
593
#endif
594
	setup_timer(&host->retune_timer, mmc_retune_timer, (unsigned long)host);
595 596 597 598 599

	/*
	 * By default, hosts do not support SGIO or large requests.
	 * They have to set these according to their abilities.
	 */
600
	host->max_segs = 1;
601 602 603 604 605 606 607 608 609 610 611 612 613 614
	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;
}

EXPORT_SYMBOL(mmc_alloc_host);

/**
 *	mmc_add_host - initialise host hardware
 *	@host: mmc host
P
Pierre Ossman 已提交
615 616 617 618
 *
 *	Register the host with the driver model. The host must be
 *	prepared to start servicing requests before this function
 *	completes.
619 620 621 622 623
 */
int mmc_add_host(struct mmc_host *host)
{
	int err;

624 625 626
	WARN_ON((host->caps & MMC_CAP_SDIO_IRQ) &&
		!host->ops->enable_sdio_irq);

627 628 629 630
	err = device_add(&host->class_dev);
	if (err)
		return err;

631 632
	led_trigger_register_simple(dev_name(&host->class_dev), &host->led);

633 634 635
#ifdef CONFIG_DEBUG_FS
	mmc_add_host_debugfs(host);
#endif
636
	mmc_host_clk_sysfs_init(host);
637

638
	mmc_start_host(host);
639
	register_pm_notifier(&host->pm_notify);
640 641 642 643 644 645 646 647 648 649 650

	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,
P
Pierre Ossman 已提交
651 652
 *	and power down the MMC bus. No new requests will be issued
 *	after this function has returned.
653 654 655
 */
void mmc_remove_host(struct mmc_host *host)
{
656
	unregister_pm_notifier(&host->pm_notify);
657 658
	mmc_stop_host(host);

659 660 661 662
#ifdef CONFIG_DEBUG_FS
	mmc_remove_host_debugfs(host);
#endif

663 664
	device_del(&host->class_dev);

665
	led_trigger_unregister_simple(host->led);
666 667

	mmc_host_clk_exit(host);
668 669 670 671 672 673 674 675 676 677 678 679
}

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)
{
680
	mmc_pwrseq_free(host);
681 682 683 684
	put_device(&host->class_dev);
}

EXPORT_SYMBOL(mmc_free_host);