Pierre Ossman | b93931a | 2007-05-19 14:06:24 +0200 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/mmc/core/host.c |
| 3 | * |
| 4 | * Copyright (C) 2003 Russell King, All Rights Reserved. |
Pierre Ossman | ff3112f | 2008-03-08 23:43:19 +0100 | [diff] [blame] | 5 | * Copyright (C) 2007-2008 Pierre Ossman |
Linus Walleij | 0456683 | 2010-11-08 21:36:50 -0500 | [diff] [blame] | 6 | * Copyright (C) 2010 Linus Walleij |
Pierre Ossman | b93931a | 2007-05-19 14:06:24 +0200 | [diff] [blame] | 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 | * |
| 12 | * MMC host class device management |
| 13 | */ |
| 14 | |
| 15 | #include <linux/device.h> |
| 16 | #include <linux/err.h> |
| 17 | #include <linux/idr.h> |
Guennadi Liakhovetski | 6c56e7a | 2013-02-16 16:21:16 +0100 | [diff] [blame] | 18 | #include <linux/of.h> |
| 19 | #include <linux/of_gpio.h> |
Pierre Ossman | b93931a | 2007-05-19 14:06:24 +0200 | [diff] [blame] | 20 | #include <linux/pagemap.h> |
Paul Gortmaker | 3ef77af | 2011-07-10 12:42:00 -0400 | [diff] [blame] | 21 | #include <linux/export.h> |
Pierre Ossman | af8350c | 2007-09-24 07:15:48 +0200 | [diff] [blame] | 22 | #include <linux/leds.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 23 | #include <linux/slab.h> |
Pierre Ossman | b93931a | 2007-05-19 14:06:24 +0200 | [diff] [blame] | 24 | |
| 25 | #include <linux/mmc/host.h> |
Linus Walleij | 0456683 | 2010-11-08 21:36:50 -0500 | [diff] [blame] | 26 | #include <linux/mmc/card.h> |
Guennadi Liakhovetski | 6c56e7a | 2013-02-16 16:21:16 +0100 | [diff] [blame] | 27 | #include <linux/mmc/slot-gpio.h> |
Pierre Ossman | b93931a | 2007-05-19 14:06:24 +0200 | [diff] [blame] | 28 | |
| 29 | #include "core.h" |
| 30 | #include "host.h" |
Ulf Hansson | df8aca1 | 2014-12-18 15:44:36 +0100 | [diff] [blame] | 31 | #include "slot-gpio.h" |
Ulf Hansson | 3aa8793 | 2014-11-28 14:38:36 +0100 | [diff] [blame] | 32 | #include "pwrseq.h" |
Pierre Ossman | b93931a | 2007-05-19 14:06:24 +0200 | [diff] [blame] | 33 | |
Ulf Hansson | 5674a9b | 2016-04-07 11:40:59 +0200 | [diff] [blame] | 34 | static DEFINE_IDA(mmc_host_ida); |
Ulf Hansson | e2d1926 | 2014-12-18 15:44:35 +0100 | [diff] [blame] | 35 | static DEFINE_SPINLOCK(mmc_host_lock); |
| 36 | |
Pierre Ossman | b93931a | 2007-05-19 14:06:24 +0200 | [diff] [blame] | 37 | static void mmc_host_classdev_release(struct device *dev) |
| 38 | { |
| 39 | struct mmc_host *host = cls_dev_to_mmc_host(dev); |
Ulf Hansson | e2d1926 | 2014-12-18 15:44:35 +0100 | [diff] [blame] | 40 | spin_lock(&mmc_host_lock); |
Ulf Hansson | 5674a9b | 2016-04-07 11:40:59 +0200 | [diff] [blame] | 41 | ida_remove(&mmc_host_ida, host->index); |
Ulf Hansson | e2d1926 | 2014-12-18 15:44:35 +0100 | [diff] [blame] | 42 | spin_unlock(&mmc_host_lock); |
Pierre Ossman | b93931a | 2007-05-19 14:06:24 +0200 | [diff] [blame] | 43 | kfree(host); |
| 44 | } |
| 45 | |
| 46 | static struct class mmc_host_class = { |
| 47 | .name = "mmc_host", |
| 48 | .dev_release = mmc_host_classdev_release, |
| 49 | }; |
| 50 | |
| 51 | int mmc_register_host_class(void) |
| 52 | { |
| 53 | return class_register(&mmc_host_class); |
| 54 | } |
| 55 | |
| 56 | void mmc_unregister_host_class(void) |
| 57 | { |
| 58 | class_unregister(&mmc_host_class); |
| 59 | } |
| 60 | |
Subhash Jadavani | dff3126 | 2016-04-19 16:21:16 -0700 | [diff] [blame] | 61 | #ifdef CONFIG_MMC_CLKGATE |
| 62 | static ssize_t clkgate_delay_show(struct device *dev, |
| 63 | struct device_attribute *attr, char *buf) |
| 64 | { |
| 65 | struct mmc_host *host = cls_dev_to_mmc_host(dev); |
| 66 | return snprintf(buf, PAGE_SIZE, "%lu\n", host->clkgate_delay); |
| 67 | } |
| 68 | |
| 69 | static ssize_t clkgate_delay_store(struct device *dev, |
| 70 | struct device_attribute *attr, const char *buf, size_t count) |
| 71 | { |
| 72 | struct mmc_host *host = cls_dev_to_mmc_host(dev); |
| 73 | unsigned long flags, value; |
| 74 | |
| 75 | if (kstrtoul(buf, 0, &value)) |
| 76 | return -EINVAL; |
| 77 | |
| 78 | spin_lock_irqsave(&host->clk_lock, flags); |
| 79 | host->clkgate_delay = value; |
| 80 | spin_unlock_irqrestore(&host->clk_lock, flags); |
| 81 | return count; |
| 82 | } |
| 83 | |
| 84 | /* |
| 85 | * Enabling clock gating will make the core call out to the host |
| 86 | * once up and once down when it performs a request or card operation |
| 87 | * intermingled in any fashion. The driver will see this through |
| 88 | * set_ios() operations with ios.clock field set to 0 to gate (disable) |
| 89 | * the block clock, and to the old frequency to enable it again. |
| 90 | */ |
| 91 | static void mmc_host_clk_gate_delayed(struct mmc_host *host) |
| 92 | { |
| 93 | unsigned long tick_ns; |
| 94 | unsigned long freq = host->ios.clock; |
| 95 | unsigned long flags; |
| 96 | |
| 97 | if (!freq) { |
| 98 | pr_debug("%s: frequency set to 0 in disable function, " |
| 99 | "this means the clock is already disabled.\n", |
| 100 | mmc_hostname(host)); |
| 101 | return; |
| 102 | } |
| 103 | /* |
| 104 | * New requests may have appeared while we were scheduling, |
| 105 | * then there is no reason to delay the check before |
| 106 | * clk_disable(). |
| 107 | */ |
| 108 | spin_lock_irqsave(&host->clk_lock, flags); |
| 109 | |
| 110 | /* |
| 111 | * Delay n bus cycles (at least 8 from MMC spec) before attempting |
| 112 | * to disable the MCI block clock. The reference count may have |
| 113 | * gone up again after this delay due to rescheduling! |
| 114 | */ |
| 115 | if (!host->clk_requests) { |
| 116 | spin_unlock_irqrestore(&host->clk_lock, flags); |
| 117 | tick_ns = DIV_ROUND_UP(1000000000, freq); |
| 118 | ndelay(host->clk_delay * tick_ns); |
| 119 | } else { |
| 120 | /* New users appeared while waiting for this work */ |
| 121 | spin_unlock_irqrestore(&host->clk_lock, flags); |
| 122 | return; |
| 123 | } |
| 124 | mutex_lock(&host->clk_gate_mutex); |
| 125 | spin_lock_irqsave(&host->clk_lock, flags); |
| 126 | if (!host->clk_requests) { |
| 127 | spin_unlock_irqrestore(&host->clk_lock, flags); |
| 128 | /* This will set host->ios.clock to 0 */ |
| 129 | mmc_gate_clock(host); |
| 130 | spin_lock_irqsave(&host->clk_lock, flags); |
| 131 | pr_debug("%s: gated MCI clock\n", mmc_hostname(host)); |
| 132 | } |
| 133 | spin_unlock_irqrestore(&host->clk_lock, flags); |
| 134 | mutex_unlock(&host->clk_gate_mutex); |
| 135 | } |
| 136 | |
| 137 | /* |
| 138 | * Internal work. Work to disable the clock at some later point. |
| 139 | */ |
| 140 | static void mmc_host_clk_gate_work(struct work_struct *work) |
| 141 | { |
| 142 | struct mmc_host *host = container_of(work, struct mmc_host, |
| 143 | clk_gate_work.work); |
| 144 | |
| 145 | mmc_host_clk_gate_delayed(host); |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * mmc_host_clk_hold - ungate hardware MCI clocks |
| 150 | * @host: host to ungate. |
| 151 | * |
| 152 | * Makes sure the host ios.clock is restored to a non-zero value |
| 153 | * past this call. Increase clock reference count and ungate clock |
| 154 | * if we're the first user. |
| 155 | */ |
| 156 | void mmc_host_clk_hold(struct mmc_host *host) |
| 157 | { |
| 158 | unsigned long flags; |
| 159 | |
| 160 | /* cancel any clock gating work scheduled by mmc_host_clk_release() */ |
| 161 | cancel_delayed_work_sync(&host->clk_gate_work); |
| 162 | mutex_lock(&host->clk_gate_mutex); |
| 163 | spin_lock_irqsave(&host->clk_lock, flags); |
| 164 | if (host->clk_gated) { |
| 165 | spin_unlock_irqrestore(&host->clk_lock, flags); |
| 166 | mmc_ungate_clock(host); |
| 167 | spin_lock_irqsave(&host->clk_lock, flags); |
| 168 | pr_debug("%s: ungated MCI clock\n", mmc_hostname(host)); |
| 169 | } |
| 170 | host->clk_requests++; |
| 171 | spin_unlock_irqrestore(&host->clk_lock, flags); |
| 172 | mutex_unlock(&host->clk_gate_mutex); |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * mmc_host_may_gate_card - check if this card may be gated |
| 177 | * @card: card to check. |
| 178 | */ |
| 179 | static bool mmc_host_may_gate_card(struct mmc_card *card) |
| 180 | { |
| 181 | /* If there is no card we may gate it */ |
| 182 | if (!card) |
| 183 | return true; |
| 184 | /* |
| 185 | * Don't gate SDIO cards! These need to be clocked at all times |
| 186 | * since they may be independent systems generating interrupts |
| 187 | * and other events. The clock requests counter from the core will |
| 188 | * go down to zero since the core does not need it, but we will not |
| 189 | * gate the clock, because there is somebody out there that may still |
| 190 | * be using it. |
| 191 | */ |
| 192 | return !(card->quirks & MMC_QUIRK_BROKEN_CLK_GATING); |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * mmc_host_clk_release - gate off hardware MCI clocks |
| 197 | * @host: host to gate. |
| 198 | * |
| 199 | * Calls the host driver with ios.clock set to zero as often as possible |
| 200 | * in order to gate off hardware MCI clocks. Decrease clock reference |
| 201 | * count and schedule disabling of clock. |
| 202 | */ |
| 203 | void mmc_host_clk_release(struct mmc_host *host) |
| 204 | { |
| 205 | unsigned long flags; |
| 206 | |
| 207 | spin_lock_irqsave(&host->clk_lock, flags); |
| 208 | host->clk_requests--; |
| 209 | if (mmc_host_may_gate_card(host->card) && |
| 210 | !host->clk_requests) |
| 211 | schedule_delayed_work(&host->clk_gate_work, |
| 212 | msecs_to_jiffies(host->clkgate_delay)); |
| 213 | spin_unlock_irqrestore(&host->clk_lock, flags); |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * mmc_host_clk_rate - get current clock frequency setting |
| 218 | * @host: host to get the clock frequency for. |
| 219 | * |
| 220 | * Returns current clock frequency regardless of gating. |
| 221 | */ |
| 222 | unsigned int mmc_host_clk_rate(struct mmc_host *host) |
| 223 | { |
| 224 | unsigned long freq; |
| 225 | unsigned long flags; |
| 226 | |
| 227 | spin_lock_irqsave(&host->clk_lock, flags); |
| 228 | if (host->clk_gated) |
| 229 | freq = host->clk_old; |
| 230 | else |
| 231 | freq = host->ios.clock; |
| 232 | spin_unlock_irqrestore(&host->clk_lock, flags); |
| 233 | return freq; |
| 234 | } |
| 235 | |
| 236 | /** |
| 237 | * mmc_host_clk_init - set up clock gating code |
| 238 | * @host: host with potential clock to control |
| 239 | */ |
| 240 | static inline void mmc_host_clk_init(struct mmc_host *host) |
| 241 | { |
| 242 | host->clk_requests = 0; |
| 243 | /* Hold MCI clock for 8 cycles by default */ |
| 244 | host->clk_delay = 8; |
| 245 | /* |
| 246 | * Default clock gating delay is 0ms to avoid wasting power. |
| 247 | * This value can be tuned by writing into sysfs entry. |
| 248 | */ |
| 249 | host->clkgate_delay = 0; |
| 250 | host->clk_gated = false; |
| 251 | INIT_DELAYED_WORK(&host->clk_gate_work, mmc_host_clk_gate_work); |
| 252 | spin_lock_init(&host->clk_lock); |
| 253 | mutex_init(&host->clk_gate_mutex); |
| 254 | } |
| 255 | |
| 256 | /** |
| 257 | * mmc_host_clk_exit - shut down clock gating code |
| 258 | * @host: host with potential clock to control |
| 259 | */ |
| 260 | static inline void mmc_host_clk_exit(struct mmc_host *host) |
| 261 | { |
| 262 | /* |
| 263 | * Wait for any outstanding gate and then make sure we're |
| 264 | * ungated before exiting. |
| 265 | */ |
| 266 | if (cancel_delayed_work_sync(&host->clk_gate_work)) |
| 267 | mmc_host_clk_gate_delayed(host); |
| 268 | if (host->clk_gated) |
| 269 | mmc_host_clk_hold(host); |
| 270 | /* There should be only one user now */ |
| 271 | WARN_ON(host->clk_requests > 1); |
| 272 | } |
| 273 | |
| 274 | static inline void mmc_host_clk_sysfs_init(struct mmc_host *host) |
| 275 | { |
| 276 | host->clkgate_delay_attr.show = clkgate_delay_show; |
| 277 | host->clkgate_delay_attr.store = clkgate_delay_store; |
| 278 | sysfs_attr_init(&host->clkgate_delay_attr.attr); |
| 279 | host->clkgate_delay_attr.attr.name = "clkgate_delay"; |
| 280 | host->clkgate_delay_attr.attr.mode = S_IRUGO | S_IWUSR; |
| 281 | if (device_create_file(&host->class_dev, &host->clkgate_delay_attr)) |
| 282 | pr_err("%s: Failed to create clkgate_delay sysfs entry\n", |
| 283 | mmc_hostname(host)); |
| 284 | } |
| 285 | #else |
| 286 | |
| 287 | static inline void mmc_host_clk_init(struct mmc_host *host) |
| 288 | { |
| 289 | } |
| 290 | |
| 291 | static inline void mmc_host_clk_exit(struct mmc_host *host) |
| 292 | { |
| 293 | } |
| 294 | |
| 295 | static inline void mmc_host_clk_sysfs_init(struct mmc_host *host) |
| 296 | { |
| 297 | } |
| 298 | |
Sahitya Tummala | 043744a | 2013-06-24 09:55:33 +0530 | [diff] [blame^] | 299 | bool mmc_host_may_gate_card(struct mmc_card *card) |
| 300 | { |
| 301 | return false; |
| 302 | } |
Subhash Jadavani | dff3126 | 2016-04-19 16:21:16 -0700 | [diff] [blame] | 303 | #endif |
| 304 | |
Adrian Hunter | dfa13eb | 2015-05-07 13:10:12 +0300 | [diff] [blame] | 305 | void mmc_retune_enable(struct mmc_host *host) |
| 306 | { |
| 307 | host->can_retune = 1; |
| 308 | if (host->retune_period) |
| 309 | mod_timer(&host->retune_timer, |
| 310 | jiffies + host->retune_period * HZ); |
| 311 | } |
| 312 | |
Adrian Hunter | 7ff2760 | 2016-05-16 15:35:24 +0300 | [diff] [blame] | 313 | /* |
| 314 | * Pause re-tuning for a small set of operations. The pause begins after the |
| 315 | * next command and after first doing re-tuning. |
| 316 | */ |
| 317 | void mmc_retune_pause(struct mmc_host *host) |
| 318 | { |
| 319 | if (!host->retune_paused) { |
| 320 | host->retune_paused = 1; |
| 321 | mmc_retune_needed(host); |
| 322 | mmc_retune_hold(host); |
| 323 | } |
| 324 | } |
| 325 | EXPORT_SYMBOL(mmc_retune_pause); |
| 326 | |
| 327 | void mmc_retune_unpause(struct mmc_host *host) |
| 328 | { |
| 329 | if (host->retune_paused) { |
| 330 | host->retune_paused = 0; |
| 331 | mmc_retune_release(host); |
| 332 | } |
| 333 | } |
| 334 | EXPORT_SYMBOL(mmc_retune_unpause); |
| 335 | |
Adrian Hunter | dfa13eb | 2015-05-07 13:10:12 +0300 | [diff] [blame] | 336 | void mmc_retune_disable(struct mmc_host *host) |
| 337 | { |
Adrian Hunter | 7ff2760 | 2016-05-16 15:35:24 +0300 | [diff] [blame] | 338 | mmc_retune_unpause(host); |
Adrian Hunter | dfa13eb | 2015-05-07 13:10:12 +0300 | [diff] [blame] | 339 | host->can_retune = 0; |
| 340 | del_timer_sync(&host->retune_timer); |
| 341 | host->retune_now = 0; |
| 342 | host->need_retune = 0; |
| 343 | } |
| 344 | |
| 345 | void mmc_retune_timer_stop(struct mmc_host *host) |
| 346 | { |
| 347 | del_timer_sync(&host->retune_timer); |
| 348 | } |
| 349 | EXPORT_SYMBOL(mmc_retune_timer_stop); |
| 350 | |
| 351 | void mmc_retune_hold(struct mmc_host *host) |
| 352 | { |
| 353 | if (!host->hold_retune) |
| 354 | host->retune_now = 1; |
| 355 | host->hold_retune += 1; |
| 356 | } |
| 357 | |
| 358 | void mmc_retune_release(struct mmc_host *host) |
| 359 | { |
| 360 | if (host->hold_retune) |
| 361 | host->hold_retune -= 1; |
| 362 | else |
| 363 | WARN_ON(1); |
| 364 | } |
| 365 | |
| 366 | int mmc_retune(struct mmc_host *host) |
| 367 | { |
Adrian Hunter | 6376f69 | 2015-05-07 13:10:20 +0300 | [diff] [blame] | 368 | bool return_to_hs400 = false; |
Adrian Hunter | dfa13eb | 2015-05-07 13:10:12 +0300 | [diff] [blame] | 369 | int err; |
| 370 | |
| 371 | if (host->retune_now) |
| 372 | host->retune_now = 0; |
| 373 | else |
| 374 | return 0; |
| 375 | |
| 376 | if (!host->need_retune || host->doing_retune || !host->card) |
| 377 | return 0; |
| 378 | |
| 379 | host->need_retune = 0; |
| 380 | |
| 381 | host->doing_retune = 1; |
| 382 | |
Adrian Hunter | 6376f69 | 2015-05-07 13:10:20 +0300 | [diff] [blame] | 383 | if (host->ios.timing == MMC_TIMING_MMC_HS400) { |
| 384 | err = mmc_hs400_to_hs200(host->card); |
| 385 | if (err) |
| 386 | goto out; |
Adrian Hunter | dfa13eb | 2015-05-07 13:10:12 +0300 | [diff] [blame] | 387 | |
Adrian Hunter | 6376f69 | 2015-05-07 13:10:20 +0300 | [diff] [blame] | 388 | return_to_hs400 = true; |
| 389 | |
| 390 | if (host->ops->prepare_hs400_tuning) |
| 391 | host->ops->prepare_hs400_tuning(host, &host->ios); |
| 392 | } |
| 393 | |
| 394 | err = mmc_execute_tuning(host->card); |
| 395 | if (err) |
| 396 | goto out; |
| 397 | |
| 398 | if (return_to_hs400) |
| 399 | err = mmc_hs200_to_hs400(host->card); |
| 400 | out: |
Adrian Hunter | dfa13eb | 2015-05-07 13:10:12 +0300 | [diff] [blame] | 401 | host->doing_retune = 0; |
| 402 | |
| 403 | return err; |
| 404 | } |
| 405 | |
| 406 | static void mmc_retune_timer(unsigned long data) |
| 407 | { |
| 408 | struct mmc_host *host = (struct mmc_host *)data; |
| 409 | |
| 410 | mmc_retune_needed(host); |
| 411 | } |
| 412 | |
Pierre Ossman | b93931a | 2007-05-19 14:06:24 +0200 | [diff] [blame] | 413 | /** |
Guennadi Liakhovetski | 6c56e7a | 2013-02-16 16:21:16 +0100 | [diff] [blame] | 414 | * mmc_of_parse() - parse host's device-tree node |
| 415 | * @host: host whose node should be parsed. |
| 416 | * |
| 417 | * To keep the rest of the MMC subsystem unaware of whether DT has been |
| 418 | * used to to instantiate and configure this host instance or not, we |
| 419 | * parse the properties and set respective generic mmc-host flags and |
| 420 | * parameters. |
| 421 | */ |
Simon Baatz | ec0a751 | 2013-06-09 22:14:11 +0200 | [diff] [blame] | 422 | int mmc_of_parse(struct mmc_host *host) |
Guennadi Liakhovetski | 6c56e7a | 2013-02-16 16:21:16 +0100 | [diff] [blame] | 423 | { |
| 424 | struct device_node *np; |
| 425 | u32 bus_width; |
Sergei Shtylyov | 90614cd | 2015-08-07 01:06:48 +0300 | [diff] [blame] | 426 | int ret; |
Kristina Martsenko | a31b0c6 | 2014-11-05 02:22:41 +0200 | [diff] [blame] | 427 | bool cd_cap_invert, cd_gpio_invert = false; |
| 428 | bool ro_cap_invert, ro_gpio_invert = false; |
Guennadi Liakhovetski | 6c56e7a | 2013-02-16 16:21:16 +0100 | [diff] [blame] | 429 | |
| 430 | if (!host->parent || !host->parent->of_node) |
Simon Baatz | ec0a751 | 2013-06-09 22:14:11 +0200 | [diff] [blame] | 431 | return 0; |
Guennadi Liakhovetski | 6c56e7a | 2013-02-16 16:21:16 +0100 | [diff] [blame] | 432 | |
| 433 | np = host->parent->of_node; |
| 434 | |
| 435 | /* "bus-width" is translated to MMC_CAP_*_BIT_DATA flags */ |
| 436 | if (of_property_read_u32(np, "bus-width", &bus_width) < 0) { |
| 437 | dev_dbg(host->parent, |
| 438 | "\"bus-width\" property is missing, assuming 1 bit.\n"); |
| 439 | bus_width = 1; |
| 440 | } |
| 441 | |
| 442 | switch (bus_width) { |
| 443 | case 8: |
| 444 | host->caps |= MMC_CAP_8_BIT_DATA; |
| 445 | /* Hosts capable of 8-bit transfers can also do 4 bits */ |
| 446 | case 4: |
| 447 | host->caps |= MMC_CAP_4_BIT_DATA; |
| 448 | break; |
| 449 | case 1: |
| 450 | break; |
| 451 | default: |
| 452 | dev_err(host->parent, |
Alexander Shiyan | 1c279f4 | 2014-02-15 15:40:58 +0400 | [diff] [blame] | 453 | "Invalid \"bus-width\" value %u!\n", bus_width); |
Simon Baatz | ec0a751 | 2013-06-09 22:14:11 +0200 | [diff] [blame] | 454 | return -EINVAL; |
Guennadi Liakhovetski | 6c56e7a | 2013-02-16 16:21:16 +0100 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | /* f_max is obtained from the optional "max-frequency" property */ |
| 458 | of_property_read_u32(np, "max-frequency", &host->f_max); |
| 459 | |
| 460 | /* |
| 461 | * Configure CD and WP pins. They are both by default active low to |
| 462 | * match the SDHCI spec. If GPIOs are provided for CD and / or WP, the |
| 463 | * mmc-gpio helpers are used to attach, configure and use them. If |
| 464 | * polarity inversion is specified in DT, one of MMC_CAP2_CD_ACTIVE_HIGH |
| 465 | * and MMC_CAP2_RO_ACTIVE_HIGH capability-2 flags is set. If the |
| 466 | * "broken-cd" property is provided, the MMC_CAP_NEEDS_POLL capability |
| 467 | * is set. If the "non-removable" property is found, the |
| 468 | * MMC_CAP_NONREMOVABLE capability is set and no card-detection |
| 469 | * configuration is performed. |
| 470 | */ |
| 471 | |
| 472 | /* Parse Card Detection */ |
Sergei Shtylyov | 90614cd | 2015-08-07 01:06:48 +0300 | [diff] [blame] | 473 | if (of_property_read_bool(np, "non-removable")) { |
Guennadi Liakhovetski | 6c56e7a | 2013-02-16 16:21:16 +0100 | [diff] [blame] | 474 | host->caps |= MMC_CAP_NONREMOVABLE; |
| 475 | } else { |
Kristina Martsenko | a31b0c6 | 2014-11-05 02:22:41 +0200 | [diff] [blame] | 476 | cd_cap_invert = of_property_read_bool(np, "cd-inverted"); |
Guennadi Liakhovetski | 6c56e7a | 2013-02-16 16:21:16 +0100 | [diff] [blame] | 477 | |
Sergei Shtylyov | 90614cd | 2015-08-07 01:06:48 +0300 | [diff] [blame] | 478 | if (of_property_read_bool(np, "broken-cd")) |
Guennadi Liakhovetski | 6c56e7a | 2013-02-16 16:21:16 +0100 | [diff] [blame] | 479 | host->caps |= MMC_CAP_NEEDS_POLL; |
| 480 | |
Linus Walleij | 89168b4 | 2014-10-02 09:08:46 +0200 | [diff] [blame] | 481 | ret = mmc_gpiod_request_cd(host, "cd", 0, true, |
Kristina Martsenko | a31b0c6 | 2014-11-05 02:22:41 +0200 | [diff] [blame] | 482 | 0, &cd_gpio_invert); |
Ulf Hansson | 9116752 | 2014-12-18 10:41:44 +0100 | [diff] [blame] | 483 | if (!ret) |
Linus Walleij | 98e90de | 2014-08-27 13:00:52 +0200 | [diff] [blame] | 484 | dev_info(host->parent, "Got CD GPIO\n"); |
Ulf Hansson | 43934ec | 2015-09-14 12:18:55 +0200 | [diff] [blame] | 485 | else if (ret != -ENOENT && ret != -ENOSYS) |
Ulf Hansson | 9116752 | 2014-12-18 10:41:44 +0100 | [diff] [blame] | 486 | return ret; |
Linus Walleij | 89168b4 | 2014-10-02 09:08:46 +0200 | [diff] [blame] | 487 | |
| 488 | /* |
| 489 | * There are two ways to flag that the CD line is inverted: |
| 490 | * through the cd-inverted flag and by the GPIO line itself |
| 491 | * being inverted from the GPIO subsystem. This is a leftover |
| 492 | * from the times when the GPIO subsystem did not make it |
| 493 | * possible to flag a line as inverted. |
| 494 | * |
| 495 | * If the capability on the host AND the GPIO line are |
| 496 | * both inverted, the end result is that the CD line is |
| 497 | * not inverted. |
| 498 | */ |
Kristina Martsenko | a31b0c6 | 2014-11-05 02:22:41 +0200 | [diff] [blame] | 499 | if (cd_cap_invert ^ cd_gpio_invert) |
Linus Walleij | 89168b4 | 2014-10-02 09:08:46 +0200 | [diff] [blame] | 500 | host->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH; |
Guennadi Liakhovetski | 6c56e7a | 2013-02-16 16:21:16 +0100 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | /* Parse Write Protection */ |
Kristina Martsenko | a31b0c6 | 2014-11-05 02:22:41 +0200 | [diff] [blame] | 504 | ro_cap_invert = of_property_read_bool(np, "wp-inverted"); |
Guennadi Liakhovetski | 2fdb6e2 | 2013-02-15 16:14:01 +0100 | [diff] [blame] | 505 | |
Kristina Martsenko | a31b0c6 | 2014-11-05 02:22:41 +0200 | [diff] [blame] | 506 | ret = mmc_gpiod_request_ro(host, "wp", 0, false, 0, &ro_gpio_invert); |
Ulf Hansson | 9116752 | 2014-12-18 10:41:44 +0100 | [diff] [blame] | 507 | if (!ret) |
Linus Walleij | 98e90de | 2014-08-27 13:00:52 +0200 | [diff] [blame] | 508 | dev_info(host->parent, "Got WP GPIO\n"); |
Ulf Hansson | 43934ec | 2015-09-14 12:18:55 +0200 | [diff] [blame] | 509 | else if (ret != -ENOENT && ret != -ENOSYS) |
Ulf Hansson | 9116752 | 2014-12-18 10:41:44 +0100 | [diff] [blame] | 510 | return ret; |
Linus Walleij | 98e90de | 2014-08-27 13:00:52 +0200 | [diff] [blame] | 511 | |
Lars-Peter Clausen | 19f4424 | 2015-05-06 20:31:20 +0200 | [diff] [blame] | 512 | if (of_property_read_bool(np, "disable-wp")) |
| 513 | host->caps2 |= MMC_CAP2_NO_WRITE_PROTECT; |
| 514 | |
Linus Walleij | 89168b4 | 2014-10-02 09:08:46 +0200 | [diff] [blame] | 515 | /* See the comment on CD inversion above */ |
Kristina Martsenko | a31b0c6 | 2014-11-05 02:22:41 +0200 | [diff] [blame] | 516 | if (ro_cap_invert ^ ro_gpio_invert) |
Linus Walleij | 89168b4 | 2014-10-02 09:08:46 +0200 | [diff] [blame] | 517 | host->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH; |
| 518 | |
Sergei Shtylyov | 90614cd | 2015-08-07 01:06:48 +0300 | [diff] [blame] | 519 | if (of_property_read_bool(np, "cap-sd-highspeed")) |
Guennadi Liakhovetski | 2fdb6e2 | 2013-02-15 16:14:01 +0100 | [diff] [blame] | 520 | host->caps |= MMC_CAP_SD_HIGHSPEED; |
Sergei Shtylyov | 90614cd | 2015-08-07 01:06:48 +0300 | [diff] [blame] | 521 | if (of_property_read_bool(np, "cap-mmc-highspeed")) |
Guennadi Liakhovetski | 2fdb6e2 | 2013-02-15 16:14:01 +0100 | [diff] [blame] | 522 | host->caps |= MMC_CAP_MMC_HIGHSPEED; |
Sergei Shtylyov | 90614cd | 2015-08-07 01:06:48 +0300 | [diff] [blame] | 523 | if (of_property_read_bool(np, "sd-uhs-sdr12")) |
Ulf Hansson | b66bd0e | 2014-02-14 13:27:07 +0100 | [diff] [blame] | 524 | host->caps |= MMC_CAP_UHS_SDR12; |
Sergei Shtylyov | 90614cd | 2015-08-07 01:06:48 +0300 | [diff] [blame] | 525 | if (of_property_read_bool(np, "sd-uhs-sdr25")) |
Ulf Hansson | b66bd0e | 2014-02-14 13:27:07 +0100 | [diff] [blame] | 526 | host->caps |= MMC_CAP_UHS_SDR25; |
Sergei Shtylyov | 90614cd | 2015-08-07 01:06:48 +0300 | [diff] [blame] | 527 | if (of_property_read_bool(np, "sd-uhs-sdr50")) |
Ulf Hansson | b66bd0e | 2014-02-14 13:27:07 +0100 | [diff] [blame] | 528 | host->caps |= MMC_CAP_UHS_SDR50; |
Sergei Shtylyov | 90614cd | 2015-08-07 01:06:48 +0300 | [diff] [blame] | 529 | if (of_property_read_bool(np, "sd-uhs-sdr104")) |
Ulf Hansson | b66bd0e | 2014-02-14 13:27:07 +0100 | [diff] [blame] | 530 | host->caps |= MMC_CAP_UHS_SDR104; |
Sergei Shtylyov | 90614cd | 2015-08-07 01:06:48 +0300 | [diff] [blame] | 531 | if (of_property_read_bool(np, "sd-uhs-ddr50")) |
Ulf Hansson | b66bd0e | 2014-02-14 13:27:07 +0100 | [diff] [blame] | 532 | host->caps |= MMC_CAP_UHS_DDR50; |
Sergei Shtylyov | 90614cd | 2015-08-07 01:06:48 +0300 | [diff] [blame] | 533 | if (of_property_read_bool(np, "cap-power-off-card")) |
Guennadi Liakhovetski | 2fdb6e2 | 2013-02-15 16:14:01 +0100 | [diff] [blame] | 534 | host->caps |= MMC_CAP_POWER_OFF_CARD; |
Chaotian Jing | 794f157 | 2015-10-27 14:24:21 +0800 | [diff] [blame] | 535 | if (of_property_read_bool(np, "cap-mmc-hw-reset")) |
| 536 | host->caps |= MMC_CAP_HW_RESET; |
Sergei Shtylyov | 90614cd | 2015-08-07 01:06:48 +0300 | [diff] [blame] | 537 | if (of_property_read_bool(np, "cap-sdio-irq")) |
Guennadi Liakhovetski | 2fdb6e2 | 2013-02-15 16:14:01 +0100 | [diff] [blame] | 538 | host->caps |= MMC_CAP_SDIO_IRQ; |
Sergei Shtylyov | 90614cd | 2015-08-07 01:06:48 +0300 | [diff] [blame] | 539 | if (of_property_read_bool(np, "full-pwr-cycle")) |
Ulf Hansson | 5a36d6b | 2013-06-10 17:03:47 +0200 | [diff] [blame] | 540 | host->caps2 |= MMC_CAP2_FULL_PWR_CYCLE; |
Sergei Shtylyov | 90614cd | 2015-08-07 01:06:48 +0300 | [diff] [blame] | 541 | if (of_property_read_bool(np, "keep-power-in-suspend")) |
Guennadi Liakhovetski | 2fdb6e2 | 2013-02-15 16:14:01 +0100 | [diff] [blame] | 542 | host->pm_caps |= MMC_PM_KEEP_POWER; |
Sudeep Holla | 0dbcdc0 | 2015-10-21 11:10:02 +0100 | [diff] [blame] | 543 | if (of_property_read_bool(np, "wakeup-source") || |
| 544 | of_property_read_bool(np, "enable-sdio-wakeup")) /* legacy */ |
Guennadi Liakhovetski | 2fdb6e2 | 2013-02-15 16:14:01 +0100 | [diff] [blame] | 545 | host->pm_caps |= MMC_PM_WAKE_SDIO_IRQ; |
Sergei Shtylyov | 90614cd | 2015-08-07 01:06:48 +0300 | [diff] [blame] | 546 | if (of_property_read_bool(np, "mmc-ddr-1_8v")) |
Ulf Hansson | c0baf84 | 2014-02-14 13:27:08 +0100 | [diff] [blame] | 547 | host->caps |= MMC_CAP_1_8V_DDR; |
Sergei Shtylyov | 90614cd | 2015-08-07 01:06:48 +0300 | [diff] [blame] | 548 | if (of_property_read_bool(np, "mmc-ddr-1_2v")) |
Ulf Hansson | c0baf84 | 2014-02-14 13:27:08 +0100 | [diff] [blame] | 549 | host->caps |= MMC_CAP_1_2V_DDR; |
Sergei Shtylyov | 90614cd | 2015-08-07 01:06:48 +0300 | [diff] [blame] | 550 | if (of_property_read_bool(np, "mmc-hs200-1_8v")) |
Jaehoon Chung | 321bd41 | 2014-02-14 13:27:09 +0100 | [diff] [blame] | 551 | host->caps2 |= MMC_CAP2_HS200_1_8V_SDR; |
Sergei Shtylyov | 90614cd | 2015-08-07 01:06:48 +0300 | [diff] [blame] | 552 | if (of_property_read_bool(np, "mmc-hs200-1_2v")) |
Jaehoon Chung | 321bd41 | 2014-02-14 13:27:09 +0100 | [diff] [blame] | 553 | host->caps2 |= MMC_CAP2_HS200_1_2V_SDR; |
Sergei Shtylyov | 90614cd | 2015-08-07 01:06:48 +0300 | [diff] [blame] | 554 | if (of_property_read_bool(np, "mmc-hs400-1_8v")) |
Seungwon Jeon | c373eb4 | 2014-04-23 17:15:08 +0900 | [diff] [blame] | 555 | host->caps2 |= MMC_CAP2_HS400_1_8V | MMC_CAP2_HS200_1_8V_SDR; |
Sergei Shtylyov | 90614cd | 2015-08-07 01:06:48 +0300 | [diff] [blame] | 556 | if (of_property_read_bool(np, "mmc-hs400-1_2v")) |
Seungwon Jeon | c373eb4 | 2014-04-23 17:15:08 +0900 | [diff] [blame] | 557 | host->caps2 |= MMC_CAP2_HS400_1_2V | MMC_CAP2_HS200_1_2V_SDR; |
Shawn Lin | ef29c0e | 2016-05-26 09:56:12 +0800 | [diff] [blame] | 558 | if (of_property_read_bool(np, "mmc-hs400-enhanced-strobe")) |
| 559 | host->caps2 |= MMC_CAP2_HS400_ES; |
Shawn Lin | 6ae3e53 | 2016-07-14 16:26:04 +0800 | [diff] [blame] | 560 | if (of_property_read_bool(np, "no-sdio")) |
| 561 | host->caps2 |= MMC_CAP2_NO_SDIO; |
| 562 | if (of_property_read_bool(np, "no-sd")) |
| 563 | host->caps2 |= MMC_CAP2_NO_SD; |
| 564 | if (of_property_read_bool(np, "no-mmc")) |
| 565 | host->caps2 |= MMC_CAP2_NO_MMC; |
Simon Baatz | ec0a751 | 2013-06-09 22:14:11 +0200 | [diff] [blame] | 566 | |
Sascha Hauer | 3d705d1 | 2014-08-19 10:45:51 +0200 | [diff] [blame] | 567 | host->dsr_req = !of_property_read_u32(np, "dsr", &host->dsr); |
| 568 | if (host->dsr_req && (host->dsr & ~0xffff)) { |
| 569 | dev_err(host->parent, |
| 570 | "device tree specified broken value for DSR: 0x%x, ignoring\n", |
| 571 | host->dsr); |
| 572 | host->dsr_req = 0; |
| 573 | } |
| 574 | |
Ulf Hansson | 3aa8793 | 2014-11-28 14:38:36 +0100 | [diff] [blame] | 575 | return mmc_pwrseq_alloc(host); |
Guennadi Liakhovetski | 6c56e7a | 2013-02-16 16:21:16 +0100 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | EXPORT_SYMBOL(mmc_of_parse); |
| 579 | |
| 580 | /** |
Pierre Ossman | b93931a | 2007-05-19 14:06:24 +0200 | [diff] [blame] | 581 | * mmc_alloc_host - initialise the per-host structure. |
| 582 | * @extra: sizeof private data structure |
| 583 | * @dev: pointer to host device model structure |
| 584 | * |
| 585 | * Initialise the per-host structure. |
| 586 | */ |
| 587 | struct mmc_host *mmc_alloc_host(int extra, struct device *dev) |
| 588 | { |
Pierre Ossman | ff3112f | 2008-03-08 23:43:19 +0100 | [diff] [blame] | 589 | int err; |
Pierre Ossman | b93931a | 2007-05-19 14:06:24 +0200 | [diff] [blame] | 590 | struct mmc_host *host; |
| 591 | |
Mariusz Kozlowski | be760a9 | 2007-08-10 14:00:50 -0700 | [diff] [blame] | 592 | host = kzalloc(sizeof(struct mmc_host) + extra, GFP_KERNEL); |
Pierre Ossman | b93931a | 2007-05-19 14:06:24 +0200 | [diff] [blame] | 593 | if (!host) |
| 594 | return NULL; |
| 595 | |
Guennadi Liakhovetski | d9adcc1 | 2012-06-14 10:17:39 +0200 | [diff] [blame] | 596 | /* scanning will be enabled when we're ready */ |
| 597 | host->rescan_disable = 1; |
Ulf Hansson | 5674a9b | 2016-04-07 11:40:59 +0200 | [diff] [blame] | 598 | |
| 599 | again: |
| 600 | if (!ida_pre_get(&mmc_host_ida, GFP_KERNEL)) { |
| 601 | kfree(host); |
| 602 | return NULL; |
| 603 | } |
| 604 | |
Pierre Ossman | ff3112f | 2008-03-08 23:43:19 +0100 | [diff] [blame] | 605 | spin_lock(&mmc_host_lock); |
Ulf Hansson | 5674a9b | 2016-04-07 11:40:59 +0200 | [diff] [blame] | 606 | err = ida_get_new(&mmc_host_ida, &host->index); |
Pierre Ossman | ff3112f | 2008-03-08 23:43:19 +0100 | [diff] [blame] | 607 | spin_unlock(&mmc_host_lock); |
Ulf Hansson | 5674a9b | 2016-04-07 11:40:59 +0200 | [diff] [blame] | 608 | |
| 609 | if (err == -EAGAIN) { |
| 610 | goto again; |
| 611 | } else if (err) { |
Ulf Hansson | df8aca1 | 2014-12-18 15:44:36 +0100 | [diff] [blame] | 612 | kfree(host); |
| 613 | return NULL; |
| 614 | } |
Pierre Ossman | ff3112f | 2008-03-08 23:43:19 +0100 | [diff] [blame] | 615 | |
Kay Sievers | d1b2686 | 2008-11-08 21:37:46 +0100 | [diff] [blame] | 616 | dev_set_name(&host->class_dev, "mmc%d", host->index); |
Pierre Ossman | ff3112f | 2008-03-08 23:43:19 +0100 | [diff] [blame] | 617 | |
Pierre Ossman | b93931a | 2007-05-19 14:06:24 +0200 | [diff] [blame] | 618 | host->parent = dev; |
| 619 | host->class_dev.parent = dev; |
| 620 | host->class_dev.class = &mmc_host_class; |
| 621 | device_initialize(&host->class_dev); |
Fu, Zhonghui | ccf7bfd | 2016-01-22 11:32:18 +0800 | [diff] [blame] | 622 | device_enable_async_suspend(&host->class_dev); |
Pierre Ossman | b93931a | 2007-05-19 14:06:24 +0200 | [diff] [blame] | 623 | |
Ulf Hansson | df8aca1 | 2014-12-18 15:44:36 +0100 | [diff] [blame] | 624 | if (mmc_gpio_alloc(host)) { |
| 625 | put_device(&host->class_dev); |
| 626 | return NULL; |
| 627 | } |
Linus Walleij | 0456683 | 2010-11-08 21:36:50 -0500 | [diff] [blame] | 628 | |
Subhash Jadavani | dff3126 | 2016-04-19 16:21:16 -0700 | [diff] [blame] | 629 | mmc_host_clk_init(host); |
| 630 | |
Pierre Ossman | b93931a | 2007-05-19 14:06:24 +0200 | [diff] [blame] | 631 | spin_lock_init(&host->lock); |
| 632 | init_waitqueue_head(&host->wq); |
| 633 | INIT_DELAYED_WORK(&host->detect, mmc_rescan); |
Adrian Hunter | dfa13eb | 2015-05-07 13:10:12 +0300 | [diff] [blame] | 634 | setup_timer(&host->retune_timer, mmc_retune_timer, (unsigned long)host); |
Pierre Ossman | b93931a | 2007-05-19 14:06:24 +0200 | [diff] [blame] | 635 | |
| 636 | /* |
| 637 | * By default, hosts do not support SGIO or large requests. |
| 638 | * They have to set these according to their abilities. |
| 639 | */ |
Martin K. Petersen | a36274e | 2010-09-10 01:33:59 -0400 | [diff] [blame] | 640 | host->max_segs = 1; |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 641 | host->max_seg_size = PAGE_SIZE; |
Pierre Ossman | b93931a | 2007-05-19 14:06:24 +0200 | [diff] [blame] | 642 | |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 643 | host->max_req_size = PAGE_SIZE; |
Pierre Ossman | b93931a | 2007-05-19 14:06:24 +0200 | [diff] [blame] | 644 | host->max_blk_size = 512; |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 645 | host->max_blk_count = PAGE_SIZE / 512; |
Pierre Ossman | b93931a | 2007-05-19 14:06:24 +0200 | [diff] [blame] | 646 | |
| 647 | return host; |
| 648 | } |
| 649 | |
| 650 | EXPORT_SYMBOL(mmc_alloc_host); |
| 651 | |
| 652 | /** |
| 653 | * mmc_add_host - initialise host hardware |
| 654 | * @host: mmc host |
Pierre Ossman | 67a61c4 | 2007-07-11 20:22:11 +0200 | [diff] [blame] | 655 | * |
| 656 | * Register the host with the driver model. The host must be |
| 657 | * prepared to start servicing requests before this function |
| 658 | * completes. |
Pierre Ossman | b93931a | 2007-05-19 14:06:24 +0200 | [diff] [blame] | 659 | */ |
| 660 | int mmc_add_host(struct mmc_host *host) |
| 661 | { |
| 662 | int err; |
| 663 | |
Nicolas Pitre | 17b759a | 2007-07-24 02:09:39 -0400 | [diff] [blame] | 664 | WARN_ON((host->caps & MMC_CAP_SDIO_IRQ) && |
| 665 | !host->ops->enable_sdio_irq); |
| 666 | |
Pierre Ossman | b93931a | 2007-05-19 14:06:24 +0200 | [diff] [blame] | 667 | err = device_add(&host->class_dev); |
| 668 | if (err) |
| 669 | return err; |
| 670 | |
Wolfram Sang | f317dfe | 2011-04-11 06:11:29 +0200 | [diff] [blame] | 671 | led_trigger_register_simple(dev_name(&host->class_dev), &host->led); |
| 672 | |
Haavard Skinnemoen | 6edd8ee | 2008-07-24 14:18:57 +0200 | [diff] [blame] | 673 | #ifdef CONFIG_DEBUG_FS |
| 674 | mmc_add_host_debugfs(host); |
| 675 | #endif |
Subhash Jadavani | dff3126 | 2016-04-19 16:21:16 -0700 | [diff] [blame] | 676 | mmc_host_clk_sysfs_init(host); |
Haavard Skinnemoen | 6edd8ee | 2008-07-24 14:18:57 +0200 | [diff] [blame] | 677 | |
Mohan Srinivasan | e2d8878 | 2016-12-14 15:55:36 -0800 | [diff] [blame] | 678 | #ifdef CONFIG_BLOCK |
| 679 | mmc_latency_hist_sysfs_init(host); |
| 680 | #endif |
| 681 | |
Pierre Ossman | b93931a | 2007-05-19 14:06:24 +0200 | [diff] [blame] | 682 | mmc_start_host(host); |
Dmitry Shmidt | 6fc8bec | 2010-10-07 14:39:16 -0700 | [diff] [blame] | 683 | if (!(host->pm_flags & MMC_PM_IGNORE_PM_NOTIFY)) |
| 684 | mmc_register_pm_notifier(host); |
Pierre Ossman | b93931a | 2007-05-19 14:06:24 +0200 | [diff] [blame] | 685 | |
| 686 | return 0; |
| 687 | } |
| 688 | |
| 689 | EXPORT_SYMBOL(mmc_add_host); |
| 690 | |
| 691 | /** |
| 692 | * mmc_remove_host - remove host hardware |
| 693 | * @host: mmc host |
| 694 | * |
| 695 | * Unregister and remove all cards associated with this host, |
Pierre Ossman | 67a61c4 | 2007-07-11 20:22:11 +0200 | [diff] [blame] | 696 | * and power down the MMC bus. No new requests will be issued |
| 697 | * after this function has returned. |
Pierre Ossman | b93931a | 2007-05-19 14:06:24 +0200 | [diff] [blame] | 698 | */ |
| 699 | void mmc_remove_host(struct mmc_host *host) |
| 700 | { |
Dmitry Shmidt | 6fc8bec | 2010-10-07 14:39:16 -0700 | [diff] [blame] | 701 | if (!(host->pm_flags & MMC_PM_IGNORE_PM_NOTIFY)) |
| 702 | mmc_unregister_pm_notifier(host); |
Pierre Ossman | b93931a | 2007-05-19 14:06:24 +0200 | [diff] [blame] | 703 | mmc_stop_host(host); |
| 704 | |
Haavard Skinnemoen | 6edd8ee | 2008-07-24 14:18:57 +0200 | [diff] [blame] | 705 | #ifdef CONFIG_DEBUG_FS |
| 706 | mmc_remove_host_debugfs(host); |
| 707 | #endif |
| 708 | |
Mohan Srinivasan | e2d8878 | 2016-12-14 15:55:36 -0800 | [diff] [blame] | 709 | #ifdef CONFIG_BLOCK |
| 710 | mmc_latency_hist_sysfs_exit(host); |
| 711 | #endif |
| 712 | |
Pierre Ossman | b93931a | 2007-05-19 14:06:24 +0200 | [diff] [blame] | 713 | device_del(&host->class_dev); |
| 714 | |
Pierre Ossman | 77f1fd6 | 2007-10-12 22:48:46 +0200 | [diff] [blame] | 715 | led_trigger_unregister_simple(host->led); |
Subhash Jadavani | dff3126 | 2016-04-19 16:21:16 -0700 | [diff] [blame] | 716 | |
| 717 | mmc_host_clk_exit(host); |
Pierre Ossman | b93931a | 2007-05-19 14:06:24 +0200 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | EXPORT_SYMBOL(mmc_remove_host); |
| 721 | |
| 722 | /** |
| 723 | * mmc_free_host - free the host structure |
| 724 | * @host: mmc host |
| 725 | * |
| 726 | * Free the host once all references to it have been dropped. |
| 727 | */ |
| 728 | void mmc_free_host(struct mmc_host *host) |
| 729 | { |
Ulf Hansson | 3aa8793 | 2014-11-28 14:38:36 +0100 | [diff] [blame] | 730 | mmc_pwrseq_free(host); |
Pierre Ossman | b93931a | 2007-05-19 14:06:24 +0200 | [diff] [blame] | 731 | put_device(&host->class_dev); |
| 732 | } |
| 733 | |
| 734 | EXPORT_SYMBOL(mmc_free_host); |