| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * linux/drivers/mmc/core/host.c |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2003 Russell King, All Rights Reserved. |
|---|
| 5 | 6 | * Copyright (C) 2007-2008 Pierre Ossman |
|---|
| 6 | 7 | * Copyright (C) 2010 Linus Walleij |
|---|
| 7 | | - * |
|---|
| 8 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 9 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 10 | | - * published by the Free Software Foundation. |
|---|
| 11 | 8 | * |
|---|
| 12 | 9 | * MMC host class device management |
|---|
| 13 | 10 | */ |
|---|
| .. | .. |
|---|
| 18 | 15 | #include <linux/of.h> |
|---|
| 19 | 16 | #include <linux/of_gpio.h> |
|---|
| 20 | 17 | #include <linux/pagemap.h> |
|---|
| 18 | +#include <linux/pm_wakeup.h> |
|---|
| 21 | 19 | #include <linux/export.h> |
|---|
| 22 | 20 | #include <linux/leds.h> |
|---|
| 23 | 21 | #include <linux/slab.h> |
|---|
| .. | .. |
|---|
| 37 | 35 | |
|---|
| 38 | 36 | static DEFINE_IDA(mmc_host_ida); |
|---|
| 39 | 37 | |
|---|
| 38 | +#ifdef CONFIG_PM_SLEEP |
|---|
| 39 | +static int mmc_host_class_prepare(struct device *dev) |
|---|
| 40 | +{ |
|---|
| 41 | + struct mmc_host *host = cls_dev_to_mmc_host(dev); |
|---|
| 42 | + |
|---|
| 43 | + /* |
|---|
| 44 | + * It's safe to access the bus_ops pointer, as both userspace and the |
|---|
| 45 | + * workqueue for detecting cards are frozen at this point. |
|---|
| 46 | + */ |
|---|
| 47 | + if (!host->bus_ops) |
|---|
| 48 | + return 0; |
|---|
| 49 | + |
|---|
| 50 | + /* Validate conditions for system suspend. */ |
|---|
| 51 | + if (host->bus_ops->pre_suspend) |
|---|
| 52 | + return host->bus_ops->pre_suspend(host); |
|---|
| 53 | + |
|---|
| 54 | + return 0; |
|---|
| 55 | +} |
|---|
| 56 | + |
|---|
| 57 | +static void mmc_host_class_complete(struct device *dev) |
|---|
| 58 | +{ |
|---|
| 59 | + struct mmc_host *host = cls_dev_to_mmc_host(dev); |
|---|
| 60 | + |
|---|
| 61 | + _mmc_detect_change(host, 0, false); |
|---|
| 62 | +} |
|---|
| 63 | + |
|---|
| 64 | +static const struct dev_pm_ops mmc_host_class_dev_pm_ops = { |
|---|
| 65 | + .prepare = mmc_host_class_prepare, |
|---|
| 66 | + .complete = mmc_host_class_complete, |
|---|
| 67 | +}; |
|---|
| 68 | + |
|---|
| 69 | +#define MMC_HOST_CLASS_DEV_PM_OPS (&mmc_host_class_dev_pm_ops) |
|---|
| 70 | +#else |
|---|
| 71 | +#define MMC_HOST_CLASS_DEV_PM_OPS NULL |
|---|
| 72 | +#endif |
|---|
| 73 | + |
|---|
| 40 | 74 | static void mmc_host_classdev_release(struct device *dev) |
|---|
| 41 | 75 | { |
|---|
| 42 | 76 | struct mmc_host *host = cls_dev_to_mmc_host(dev); |
|---|
| 43 | | - ida_simple_remove(&mmc_host_ida, host->index); |
|---|
| 77 | + wakeup_source_unregister(host->ws); |
|---|
| 78 | + if (of_alias_get_id(host->parent->of_node, "mmc") < 0) |
|---|
| 79 | + ida_simple_remove(&mmc_host_ida, host->index); |
|---|
| 44 | 80 | kfree(host); |
|---|
| 81 | +} |
|---|
| 82 | + |
|---|
| 83 | +static int mmc_host_classdev_shutdown(struct device *dev) |
|---|
| 84 | +{ |
|---|
| 85 | + struct mmc_host *host = cls_dev_to_mmc_host(dev); |
|---|
| 86 | + |
|---|
| 87 | + __mmc_stop_host(host); |
|---|
| 88 | + return 0; |
|---|
| 45 | 89 | } |
|---|
| 46 | 90 | |
|---|
| 47 | 91 | static struct class mmc_host_class = { |
|---|
| 48 | 92 | .name = "mmc_host", |
|---|
| 49 | 93 | .dev_release = mmc_host_classdev_release, |
|---|
| 94 | + .shutdown_pre = mmc_host_classdev_shutdown, |
|---|
| 95 | + .pm = MMC_HOST_CLASS_DEV_PM_OPS, |
|---|
| 50 | 96 | }; |
|---|
| 51 | 97 | |
|---|
| 52 | 98 | int mmc_register_host_class(void) |
|---|
| .. | .. |
|---|
| 66 | 112 | mod_timer(&host->retune_timer, |
|---|
| 67 | 113 | jiffies + host->retune_period * HZ); |
|---|
| 68 | 114 | } |
|---|
| 69 | | -EXPORT_SYMBOL(mmc_retune_enable); |
|---|
| 70 | 115 | |
|---|
| 71 | 116 | /* |
|---|
| 72 | 117 | * Pause re-tuning for a small set of operations. The pause begins after the |
|---|
| .. | .. |
|---|
| 99 | 144 | host->retune_now = 0; |
|---|
| 100 | 145 | host->need_retune = 0; |
|---|
| 101 | 146 | } |
|---|
| 102 | | -EXPORT_SYMBOL(mmc_retune_disable); |
|---|
| 103 | 147 | |
|---|
| 104 | 148 | void mmc_retune_timer_stop(struct mmc_host *host) |
|---|
| 105 | 149 | { |
|---|
| .. | .. |
|---|
| 181 | 225 | struct device *dev = host->parent; |
|---|
| 182 | 226 | u32 bus_width, drv_type, cd_debounce_delay_ms; |
|---|
| 183 | 227 | int ret; |
|---|
| 184 | | - bool cd_cap_invert, cd_gpio_invert = false; |
|---|
| 185 | | - bool ro_cap_invert, ro_gpio_invert = false; |
|---|
| 186 | 228 | |
|---|
| 187 | 229 | if (!dev || !dev_fwnode(dev)) |
|---|
| 188 | 230 | return 0; |
|---|
| .. | .. |
|---|
| 197 | 239 | switch (bus_width) { |
|---|
| 198 | 240 | case 8: |
|---|
| 199 | 241 | host->caps |= MMC_CAP_8_BIT_DATA; |
|---|
| 200 | | - /* Hosts capable of 8-bit transfers can also do 4 bits */ |
|---|
| 242 | + fallthrough; /* Hosts capable of 8-bit can also do 4 bits */ |
|---|
| 201 | 243 | case 4: |
|---|
| 202 | 244 | host->caps |= MMC_CAP_4_BIT_DATA; |
|---|
| 203 | 245 | break; |
|---|
| .. | .. |
|---|
| 225 | 267 | */ |
|---|
| 226 | 268 | |
|---|
| 227 | 269 | /* Parse Card Detection */ |
|---|
| 270 | + |
|---|
| 228 | 271 | if (device_property_read_bool(dev, "non-removable")) { |
|---|
| 229 | 272 | host->caps |= MMC_CAP_NONREMOVABLE; |
|---|
| 230 | 273 | } else { |
|---|
| 231 | | - cd_cap_invert = device_property_read_bool(dev, "cd-inverted"); |
|---|
| 274 | + if (device_property_read_bool(dev, "cd-inverted")) |
|---|
| 275 | + host->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH; |
|---|
| 232 | 276 | |
|---|
| 233 | 277 | if (device_property_read_u32(dev, "cd-debounce-delay-ms", |
|---|
| 234 | 278 | &cd_debounce_delay_ms)) |
|---|
| .. | .. |
|---|
| 237 | 281 | if (device_property_read_bool(dev, "broken-cd")) |
|---|
| 238 | 282 | host->caps |= MMC_CAP_NEEDS_POLL; |
|---|
| 239 | 283 | |
|---|
| 240 | | - ret = mmc_gpiod_request_cd(host, "cd", 0, true, |
|---|
| 241 | | - cd_debounce_delay_ms * 1000, |
|---|
| 242 | | - &cd_gpio_invert); |
|---|
| 284 | + ret = mmc_gpiod_request_cd(host, "cd", 0, false, |
|---|
| 285 | + cd_debounce_delay_ms * 1000); |
|---|
| 243 | 286 | if (!ret) |
|---|
| 244 | 287 | dev_info(host->parent, "Got CD GPIO\n"); |
|---|
| 245 | 288 | else if (ret != -ENOENT && ret != -ENOSYS) |
|---|
| 246 | 289 | return ret; |
|---|
| 247 | | - |
|---|
| 248 | | - /* |
|---|
| 249 | | - * There are two ways to flag that the CD line is inverted: |
|---|
| 250 | | - * through the cd-inverted flag and by the GPIO line itself |
|---|
| 251 | | - * being inverted from the GPIO subsystem. This is a leftover |
|---|
| 252 | | - * from the times when the GPIO subsystem did not make it |
|---|
| 253 | | - * possible to flag a line as inverted. |
|---|
| 254 | | - * |
|---|
| 255 | | - * If the capability on the host AND the GPIO line are |
|---|
| 256 | | - * both inverted, the end result is that the CD line is |
|---|
| 257 | | - * not inverted. |
|---|
| 258 | | - */ |
|---|
| 259 | | - if (cd_cap_invert ^ cd_gpio_invert) |
|---|
| 260 | | - host->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH; |
|---|
| 261 | 290 | } |
|---|
| 262 | 291 | |
|---|
| 263 | 292 | /* Parse Write Protection */ |
|---|
| 264 | | - ro_cap_invert = device_property_read_bool(dev, "wp-inverted"); |
|---|
| 265 | 293 | |
|---|
| 266 | | - ret = mmc_gpiod_request_ro(host, "wp", 0, false, 0, &ro_gpio_invert); |
|---|
| 294 | + if (device_property_read_bool(dev, "wp-inverted")) |
|---|
| 295 | + host->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH; |
|---|
| 296 | + |
|---|
| 297 | + ret = mmc_gpiod_request_ro(host, "wp", 0, 0); |
|---|
| 267 | 298 | if (!ret) |
|---|
| 268 | 299 | dev_info(host->parent, "Got WP GPIO\n"); |
|---|
| 269 | 300 | else if (ret != -ENOENT && ret != -ENOSYS) |
|---|
| .. | .. |
|---|
| 271 | 302 | |
|---|
| 272 | 303 | if (device_property_read_bool(dev, "disable-wp")) |
|---|
| 273 | 304 | host->caps2 |= MMC_CAP2_NO_WRITE_PROTECT; |
|---|
| 274 | | - |
|---|
| 275 | | - /* See the comment on CD inversion above */ |
|---|
| 276 | | - if (ro_cap_invert ^ ro_gpio_invert) |
|---|
| 277 | | - host->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH; |
|---|
| 278 | 305 | |
|---|
| 279 | 306 | if (device_property_read_bool(dev, "cap-sd-highspeed")) |
|---|
| 280 | 307 | host->caps |= MMC_CAP_SD_HIGHSPEED; |
|---|
| .. | .. |
|---|
| 298 | 325 | host->caps |= MMC_CAP_SDIO_IRQ; |
|---|
| 299 | 326 | if (device_property_read_bool(dev, "full-pwr-cycle")) |
|---|
| 300 | 327 | host->caps2 |= MMC_CAP2_FULL_PWR_CYCLE; |
|---|
| 328 | + if (device_property_read_bool(dev, "full-pwr-cycle-in-suspend")) |
|---|
| 329 | + host->caps2 |= MMC_CAP2_FULL_PWR_CYCLE_IN_SUSPEND; |
|---|
| 301 | 330 | if (device_property_read_bool(dev, "keep-power-in-suspend")) |
|---|
| 302 | 331 | host->pm_caps |= MMC_PM_KEEP_POWER; |
|---|
| 303 | 332 | if (device_property_read_bool(dev, "wakeup-source") || |
|---|
| .. | .. |
|---|
| 325 | 354 | host->caps2 |= MMC_CAP2_NO_SD; |
|---|
| 326 | 355 | if (device_property_read_bool(dev, "no-mmc")) |
|---|
| 327 | 356 | host->caps2 |= MMC_CAP2_NO_MMC; |
|---|
| 357 | + if (device_property_read_bool(dev, "no-prescan-powerup")) |
|---|
| 358 | + host->caps2 |= MMC_CAP2_NO_PRESCAN_POWERUP; |
|---|
| 328 | 359 | |
|---|
| 329 | 360 | /* Must be after "non-removable" check */ |
|---|
| 330 | 361 | if (device_property_read_u32(dev, "fixed-emmc-driver-type", &drv_type) == 0) { |
|---|
| .. | .. |
|---|
| 334 | 365 | dev_err(host->parent, |
|---|
| 335 | 366 | "can't use fixed driver type, media is removable\n"); |
|---|
| 336 | 367 | } |
|---|
| 337 | | - |
|---|
| 338 | | - if (device_property_read_bool(dev, "supports-sd")) |
|---|
| 339 | | - host->restrict_caps |= RESTRICT_CARD_TYPE_SD; |
|---|
| 340 | | - if (device_property_read_bool(dev, "supports-sdio")) |
|---|
| 341 | | - host->restrict_caps |= RESTRICT_CARD_TYPE_SDIO; |
|---|
| 342 | | - if (device_property_read_bool(dev, "supports-emmc")) |
|---|
| 343 | | - host->restrict_caps |= RESTRICT_CARD_TYPE_EMMC; |
|---|
| 344 | | - |
|---|
| 345 | | -#ifdef CONFIG_SDIO_KEEPALIVE |
|---|
| 346 | | - host->support_chip_alive = |
|---|
| 347 | | - device_property_read_bool(dev, "supports-chip-alive"); |
|---|
| 348 | | - host->logic_remove_card = |
|---|
| 349 | | - device_property_read_bool(dev, "logic-remove-card"); |
|---|
| 350 | | -#endif |
|---|
| 351 | 368 | |
|---|
| 352 | 369 | host->dsr_req = !device_property_read_u32(dev, "dsr", &host->dsr); |
|---|
| 353 | 370 | if (host->dsr_req && (host->dsr & ~0xffff)) { |
|---|
| .. | .. |
|---|
| 364 | 381 | } |
|---|
| 365 | 382 | |
|---|
| 366 | 383 | EXPORT_SYMBOL(mmc_of_parse); |
|---|
| 384 | + |
|---|
| 385 | +/** |
|---|
| 386 | + * mmc_of_parse_voltage - return mask of supported voltages |
|---|
| 387 | + * @np: The device node need to be parsed. |
|---|
| 388 | + * @mask: mask of voltages available for MMC/SD/SDIO |
|---|
| 389 | + * |
|---|
| 390 | + * Parse the "voltage-ranges" DT property, returning zero if it is not |
|---|
| 391 | + * found, negative errno if the voltage-range specification is invalid, |
|---|
| 392 | + * or one if the voltage-range is specified and successfully parsed. |
|---|
| 393 | + */ |
|---|
| 394 | +int mmc_of_parse_voltage(struct device_node *np, u32 *mask) |
|---|
| 395 | +{ |
|---|
| 396 | + const u32 *voltage_ranges; |
|---|
| 397 | + int num_ranges, i; |
|---|
| 398 | + |
|---|
| 399 | + voltage_ranges = of_get_property(np, "voltage-ranges", &num_ranges); |
|---|
| 400 | + if (!voltage_ranges) { |
|---|
| 401 | + pr_debug("%pOF: voltage-ranges unspecified\n", np); |
|---|
| 402 | + return 0; |
|---|
| 403 | + } |
|---|
| 404 | + num_ranges = num_ranges / sizeof(*voltage_ranges) / 2; |
|---|
| 405 | + if (!num_ranges) { |
|---|
| 406 | + pr_err("%pOF: voltage-ranges empty\n", np); |
|---|
| 407 | + return -EINVAL; |
|---|
| 408 | + } |
|---|
| 409 | + |
|---|
| 410 | + for (i = 0; i < num_ranges; i++) { |
|---|
| 411 | + const int j = i * 2; |
|---|
| 412 | + u32 ocr_mask; |
|---|
| 413 | + |
|---|
| 414 | + ocr_mask = mmc_vddrange_to_ocrmask( |
|---|
| 415 | + be32_to_cpu(voltage_ranges[j]), |
|---|
| 416 | + be32_to_cpu(voltage_ranges[j + 1])); |
|---|
| 417 | + if (!ocr_mask) { |
|---|
| 418 | + pr_err("%pOF: voltage-range #%d is invalid\n", |
|---|
| 419 | + np, i); |
|---|
| 420 | + return -EINVAL; |
|---|
| 421 | + } |
|---|
| 422 | + *mask |= ocr_mask; |
|---|
| 423 | + } |
|---|
| 424 | + |
|---|
| 425 | + return 1; |
|---|
| 426 | +} |
|---|
| 427 | +EXPORT_SYMBOL(mmc_of_parse_voltage); |
|---|
| 367 | 428 | |
|---|
| 368 | 429 | /** |
|---|
| 369 | 430 | * mmc_first_nonreserved_index() - get the first index that is not reserved |
|---|
| .. | .. |
|---|
| 388 | 449 | */ |
|---|
| 389 | 450 | struct mmc_host *mmc_alloc_host(int extra, struct device *dev) |
|---|
| 390 | 451 | { |
|---|
| 391 | | - int err; |
|---|
| 452 | + int index; |
|---|
| 392 | 453 | struct mmc_host *host; |
|---|
| 393 | 454 | int alias_id, min_idx, max_idx; |
|---|
| 394 | 455 | |
|---|
| .. | .. |
|---|
| 401 | 462 | |
|---|
| 402 | 463 | alias_id = of_alias_get_id(dev->of_node, "mmc"); |
|---|
| 403 | 464 | if (alias_id >= 0) { |
|---|
| 404 | | - min_idx = alias_id; |
|---|
| 405 | | - max_idx = alias_id + 1; |
|---|
| 465 | + index = alias_id; |
|---|
| 406 | 466 | } else { |
|---|
| 407 | 467 | min_idx = mmc_first_nonreserved_index(); |
|---|
| 408 | 468 | max_idx = 0; |
|---|
| 469 | + |
|---|
| 470 | + index = ida_simple_get(&mmc_host_ida, min_idx, max_idx, GFP_KERNEL); |
|---|
| 471 | + if (index < 0) { |
|---|
| 472 | + kfree(host); |
|---|
| 473 | + return NULL; |
|---|
| 474 | + } |
|---|
| 409 | 475 | } |
|---|
| 410 | 476 | |
|---|
| 411 | | - err = ida_simple_get(&mmc_host_ida, min_idx, max_idx, GFP_KERNEL); |
|---|
| 412 | | - if (err < 0) { |
|---|
| 413 | | - kfree(host); |
|---|
| 414 | | - return NULL; |
|---|
| 415 | | - } |
|---|
| 416 | | - |
|---|
| 417 | | - host->index = err; |
|---|
| 477 | + host->index = index; |
|---|
| 418 | 478 | |
|---|
| 419 | 479 | dev_set_name(&host->class_dev, "mmc%d", host->index); |
|---|
| 480 | + host->ws = wakeup_source_register(NULL, dev_name(&host->class_dev)); |
|---|
| 420 | 481 | |
|---|
| 421 | 482 | host->parent = dev; |
|---|
| 422 | 483 | host->class_dev.parent = dev; |
|---|
| .. | .. |
|---|
| 448 | 509 | |
|---|
| 449 | 510 | host->fixed_drv_type = -EINVAL; |
|---|
| 450 | 511 | host->ios.power_delay_ms = 10; |
|---|
| 512 | + host->ios.power_mode = MMC_POWER_UNDEFINED; |
|---|
| 451 | 513 | |
|---|
| 452 | 514 | return host; |
|---|
| 453 | 515 | } |
|---|
| 454 | 516 | |
|---|
| 455 | 517 | EXPORT_SYMBOL(mmc_alloc_host); |
|---|
| 456 | 518 | |
|---|
| 457 | | -struct mmc_host *primary_sdio_host; |
|---|
| 458 | | -EXPORT_SYMBOL(primary_sdio_host); |
|---|
| 519 | +static void devm_mmc_host_release(struct device *dev, void *res) |
|---|
| 520 | +{ |
|---|
| 521 | + mmc_free_host(*(struct mmc_host **)res); |
|---|
| 522 | +} |
|---|
| 523 | + |
|---|
| 524 | +struct mmc_host *devm_mmc_alloc_host(struct device *dev, int extra) |
|---|
| 525 | +{ |
|---|
| 526 | + struct mmc_host **dr, *host; |
|---|
| 527 | + |
|---|
| 528 | + dr = devres_alloc(devm_mmc_host_release, sizeof(*dr), GFP_KERNEL); |
|---|
| 529 | + if (!dr) |
|---|
| 530 | + return ERR_PTR(-ENOMEM); |
|---|
| 531 | + |
|---|
| 532 | + host = mmc_alloc_host(extra, dev); |
|---|
| 533 | + if (IS_ERR(host)) { |
|---|
| 534 | + devres_free(dr); |
|---|
| 535 | + return host; |
|---|
| 536 | + } |
|---|
| 537 | + |
|---|
| 538 | + *dr = host; |
|---|
| 539 | + devres_add(dev, dr); |
|---|
| 540 | + |
|---|
| 541 | + return host; |
|---|
| 542 | +} |
|---|
| 543 | +EXPORT_SYMBOL(devm_mmc_alloc_host); |
|---|
| 544 | + |
|---|
| 545 | +static int mmc_validate_host_caps(struct mmc_host *host) |
|---|
| 546 | +{ |
|---|
| 547 | + if (host->caps & MMC_CAP_SDIO_IRQ && !host->ops->enable_sdio_irq) { |
|---|
| 548 | + dev_warn(host->parent, "missing ->enable_sdio_irq() ops\n"); |
|---|
| 549 | + return -EINVAL; |
|---|
| 550 | + } |
|---|
| 551 | + |
|---|
| 552 | + return 0; |
|---|
| 553 | +} |
|---|
| 459 | 554 | |
|---|
| 460 | 555 | /** |
|---|
| 461 | 556 | * mmc_add_host - initialise host hardware |
|---|
| .. | .. |
|---|
| 469 | 564 | { |
|---|
| 470 | 565 | int err; |
|---|
| 471 | 566 | |
|---|
| 472 | | - WARN_ON((host->caps & MMC_CAP_SDIO_IRQ) && |
|---|
| 473 | | - !host->ops->enable_sdio_irq); |
|---|
| 567 | + err = mmc_validate_host_caps(host); |
|---|
| 568 | + if (err) |
|---|
| 569 | + return err; |
|---|
| 474 | 570 | |
|---|
| 475 | 571 | err = device_add(&host->class_dev); |
|---|
| 476 | 572 | if (err) |
|---|
| .. | .. |
|---|
| 483 | 579 | #endif |
|---|
| 484 | 580 | |
|---|
| 485 | 581 | mmc_start_host(host); |
|---|
| 486 | | - if (!(host->pm_flags & MMC_PM_IGNORE_PM_NOTIFY)) |
|---|
| 487 | | - mmc_register_pm_notifier(host); |
|---|
| 488 | | - |
|---|
| 489 | | - if (host->restrict_caps & RESTRICT_CARD_TYPE_SDIO) |
|---|
| 490 | | - primary_sdio_host = host; |
|---|
| 491 | | - |
|---|
| 492 | 582 | return 0; |
|---|
| 493 | 583 | } |
|---|
| 494 | 584 | |
|---|
| .. | .. |
|---|
| 504 | 594 | */ |
|---|
| 505 | 595 | void mmc_remove_host(struct mmc_host *host) |
|---|
| 506 | 596 | { |
|---|
| 507 | | - if (!(host->pm_flags & MMC_PM_IGNORE_PM_NOTIFY)) |
|---|
| 508 | | - mmc_unregister_pm_notifier(host); |
|---|
| 509 | 597 | mmc_stop_host(host); |
|---|
| 510 | 598 | |
|---|
| 511 | 599 | #ifdef CONFIG_DEBUG_FS |
|---|
| .. | .. |
|---|
| 527 | 615 | */ |
|---|
| 528 | 616 | void mmc_free_host(struct mmc_host *host) |
|---|
| 529 | 617 | { |
|---|
| 530 | | - mmc_crypto_free_host(host); |
|---|
| 531 | 618 | mmc_pwrseq_free(host); |
|---|
| 532 | 619 | put_device(&host->class_dev); |
|---|
| 533 | 620 | } |
|---|
| 534 | 621 | |
|---|
| 535 | 622 | EXPORT_SYMBOL(mmc_free_host); |
|---|
| 536 | | - |
|---|
| 537 | | -/** |
|---|
| 538 | | - * mmc_host_rescan - triger software rescan flow |
|---|
| 539 | | - * @host: mmc host |
|---|
| 540 | | - * |
|---|
| 541 | | - * rescan slot attach in the assigned host. |
|---|
| 542 | | - * If @host is NULL, default rescan primary_sdio_host |
|---|
| 543 | | - * saved by mmc_add_host(). |
|---|
| 544 | | - * OR, rescan host from argument. |
|---|
| 545 | | - * |
|---|
| 546 | | - */ |
|---|
| 547 | | -int mmc_host_rescan(struct mmc_host *host, int val, int is_cap_sdio_irq) |
|---|
| 548 | | -{ |
|---|
| 549 | | - if (NULL != primary_sdio_host) { |
|---|
| 550 | | - if (!host) |
|---|
| 551 | | - host = primary_sdio_host; |
|---|
| 552 | | - else |
|---|
| 553 | | - pr_info("%s: mmc_host_rescan pass in host from argument!\n", |
|---|
| 554 | | - mmc_hostname(host)); |
|---|
| 555 | | - } else { |
|---|
| 556 | | - pr_err("sdio: host isn't initialization successfully.\n"); |
|---|
| 557 | | - return -ENOMEDIUM; |
|---|
| 558 | | - } |
|---|
| 559 | | - |
|---|
| 560 | | - pr_info("%s:mmc host rescan start!\n", mmc_hostname(host)); |
|---|
| 561 | | - |
|---|
| 562 | | - /* 0: oob 1:cap-sdio-irq */ |
|---|
| 563 | | - if (is_cap_sdio_irq == 1) { |
|---|
| 564 | | - host->caps |= MMC_CAP_SDIO_IRQ; |
|---|
| 565 | | - } else if (is_cap_sdio_irq == 0) { |
|---|
| 566 | | - host->caps &= ~MMC_CAP_SDIO_IRQ; |
|---|
| 567 | | - } else { |
|---|
| 568 | | - dev_err(&host->class_dev, "sdio: host doesn't identify oob or sdio_irq mode!\n"); |
|---|
| 569 | | - return -ENOMEDIUM; |
|---|
| 570 | | - } |
|---|
| 571 | | - |
|---|
| 572 | | - if (!(host->caps & MMC_CAP_NONREMOVABLE) && host->ops->set_sdio_status) |
|---|
| 573 | | - host->ops->set_sdio_status(host, val); |
|---|
| 574 | | - |
|---|
| 575 | | - return 0; |
|---|
| 576 | | -} |
|---|
| 577 | | -EXPORT_SYMBOL(mmc_host_rescan); |
|---|