• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  *  linux/drivers/mmc/core/host.c
4  *
5  *  Copyright (C) 2003 Russell King, All Rights Reserved.
6  *  Copyright (C) 2007-2008 Pierre Ossman
7  *  Copyright (C) 2010 Linus Walleij
8  *
9  *  MMC host class device management
10  */
11 
12 #include <linux/device.h>
13 #include <linux/err.h>
14 #include <linux/idr.h>
15 #include <linux/of.h>
16 #include <linux/of_gpio.h>
17 #include <linux/pagemap.h>
18 #include <linux/pm_wakeup.h>
19 #include <linux/export.h>
20 #include <linux/leds.h>
21 #include <linux/slab.h>
22 
23 #include <linux/mmc/host.h>
24 #include <linux/mmc/card.h>
25 #include <linux/mmc/slot-gpio.h>
26 
27 #include "core.h"
28 #include "host.h"
29 #include "slot-gpio.h"
30 #include "pwrseq.h"
31 #include "sdio_ops.h"
32 
33 #define cls_dev_to_mmc_host(d) container_of(d, struct mmc_host, class_dev)
34 #define MMC_BUD_WIDTH_EIGHT 8
35 #define MMC_BUD_WIDTH_FOUR 4
36 #define MMC_BUD_WIDTH_ONE 1
37 #define MMC_DEBOUNCE_DELAY_MS 200
38 #define MMC_DEBOUNCE_DELAY_MS_MUL 1000
39 #define MMC_NUM_RANGES_DIV 2
40 #define MMC_MAX_BLK_SIZE 512
41 #define MMC_POWER_DELAY_MS 10
42 
43 static DEFINE_IDA(mmc_host_ida);
44 
45 #ifdef CONFIG_PM_SLEEP
mmc_host_class_prepare(struct device * dev)46 static int mmc_host_class_prepare(struct device *dev)
47 {
48     struct mmc_host *host = cls_dev_to_mmc_host(dev);
49 
50     /*
51      * It's safe to access the bus_ops pointer, as both userspace and the
52      * workqueue for detecting cards are frozen at this point.
53      */
54     if (!host->bus_ops) {
55         return 0;
56     }
57 
58     /* Validate conditions for system suspend. */
59     if (host->bus_ops->pre_suspend) {
60         return host->bus_ops->pre_suspend(host);
61     }
62 
63     return 0;
64 }
65 
mmc_host_class_complete(struct device * dev)66 static void mmc_host_class_complete(struct device *dev)
67 {
68     struct mmc_host *host = cls_dev_to_mmc_host(dev);
69 
70     _mmc_detect_change(host, 0, false);
71 }
72 
73 static const struct dev_pm_ops mmc_host_class_dev_pm_ops = {
74     .prepare = mmc_host_class_prepare,
75     .complete = mmc_host_class_complete,
76 };
77 
78 #define MMC_HOST_CLASS_DEV_PM_OPS (&mmc_host_class_dev_pm_ops)
79 #else
80 #define MMC_HOST_CLASS_DEV_PM_OPS NULL
81 #endif
82 
mmc_host_classdev_release(struct device * dev)83 static void mmc_host_classdev_release(struct device *dev)
84 {
85     struct mmc_host *host = cls_dev_to_mmc_host(dev);
86     wakeup_source_unregister(host->ws);
87     if (of_alias_get_id(host->parent->of_node, "mmc") < 0) {
88         ida_simple_remove(&mmc_host_ida, host->index);
89     }
90     kfree(host);
91 }
92 
mmc_host_classdev_shutdown(struct device * dev)93 static int mmc_host_classdev_shutdown(struct device *dev)
94 {
95     struct mmc_host *host = cls_dev_to_mmc_host(dev);
96     __mmc_stop_host(host);
97     return 0;
98 }
99 
100 static struct class mmc_host_class = {
101     .name = "mmc_host",
102     .dev_release = mmc_host_classdev_release,
103     .shutdown_pre = mmc_host_classdev_shutdown,
104     .pm = MMC_HOST_CLASS_DEV_PM_OPS,
105 };
106 
mmc_register_host_class(void)107 int mmc_register_host_class(void)
108 {
109     return class_register(&mmc_host_class);
110 }
111 
mmc_unregister_host_class(void)112 void mmc_unregister_host_class(void)
113 {
114     class_unregister(&mmc_host_class);
115 }
116 
mmc_retune_enable(struct mmc_host * host)117 void mmc_retune_enable(struct mmc_host *host)
118 {
119     host->can_retune = 1;
120     if (host->retune_period) {
121         mod_timer(&host->retune_timer, jiffies + host->retune_period * HZ);
122     }
123 }
124 
125 /*
126  * Pause re-tuning for a small set of operations.  The pause begins after the
127  * next command and after first doing re-tuning.
128  */
mmc_retune_pause(struct mmc_host * host)129 void mmc_retune_pause(struct mmc_host *host)
130 {
131     if (!host->retune_paused) {
132         host->retune_paused = 1;
133         mmc_retune_needed(host);
134         mmc_retune_hold(host);
135     }
136 }
137 EXPORT_SYMBOL(mmc_retune_pause);
138 
mmc_retune_unpause(struct mmc_host * host)139 void mmc_retune_unpause(struct mmc_host *host)
140 {
141     if (host->retune_paused) {
142         host->retune_paused = 0;
143         mmc_retune_release(host);
144     }
145 }
146 EXPORT_SYMBOL(mmc_retune_unpause);
147 
mmc_retune_disable(struct mmc_host * host)148 void mmc_retune_disable(struct mmc_host *host)
149 {
150     mmc_retune_unpause(host);
151     host->can_retune = 0;
152     del_timer_sync(&host->retune_timer);
153     host->retune_now = 0;
154     host->need_retune = 0;
155 }
156 
mmc_retune_timer_stop(struct mmc_host * host)157 void mmc_retune_timer_stop(struct mmc_host *host)
158 {
159     del_timer_sync(&host->retune_timer);
160 }
161 EXPORT_SYMBOL(mmc_retune_timer_stop);
162 
mmc_retune_hold(struct mmc_host * host)163 void mmc_retune_hold(struct mmc_host *host)
164 {
165     if (!host->hold_retune) {
166         host->retune_now = 1;
167     }
168     host->hold_retune += 1;
169 }
170 
mmc_retune_release(struct mmc_host * host)171 void mmc_retune_release(struct mmc_host *host)
172 {
173     if (host->hold_retune) {
174         host->hold_retune -= 1;
175     } else {
176         WARN_ON(1);
177     }
178 }
179 EXPORT_SYMBOL(mmc_retune_release);
180 
mmc_retune(struct mmc_host * host)181 int mmc_retune(struct mmc_host *host)
182 {
183     bool return_to_hs400 = false;
184     int err;
185 
186     if (host->retune_now) {
187         host->retune_now = 0;
188     } else {
189         return 0;
190     }
191 
192     if (!host->need_retune || host->doing_retune || !host->card) {
193         return 0;
194     }
195 
196     host->need_retune = 0;
197 
198     host->doing_retune = 1;
199 
200     if (host->ios.timing == MMC_TIMING_MMC_HS400) {
201         err = mmc_hs400_to_hs200(host->card);
202         if (err) {
203             goto out;
204         }
205 
206         return_to_hs400 = true;
207     }
208 
209     err = mmc_execute_tuning(host->card);
210     if (err) {
211         goto out;
212     }
213 
214     if (return_to_hs400) {
215         err = mmc_hs200_to_hs400(host->card);
216     }
217 out:
218     host->doing_retune = 0;
219 
220     return err;
221 }
222 
mmc_retune_timer(struct timer_list * t)223 static void mmc_retune_timer(struct timer_list *t)
224 {
225     struct mmc_host *host = from_timer(host, t, retune_timer);
226 
227     mmc_retune_needed(host);
228 }
229 
230 /**
231  *    mmc_of_parse() - parse host's device-tree node
232  *    @host: host whose node should be parsed.
233  *
234  * To keep the rest of the MMC subsystem unaware of whether DT has been
235  * used to to instantiate and configure this host instance or not, we
236  * parse the properties and set respective generic mmc-host flags and
237  * parameters.
238  */
mmc_of_parse(struct mmc_host * host)239 int mmc_of_parse(struct mmc_host *host)
240 {
241     struct device *dev = host->parent;
242     u32 bus_width, drv_type, cd_debounce_delay_ms;
243     int ret;
244 
245     if (!dev || !dev_fwnode(dev)) {
246         return 0;
247     }
248 
249     /* "bus-width" is translated to MMC_CAP_*_BIT_DATA flags */
250     if (device_property_read_u32(dev, "bus-width", &bus_width) < 0) {
251         dev_dbg(host->parent, "\"bus-width\" property is missing, assuming 1 bit.\n");
252         bus_width = 1;
253     }
254 
255     switch (bus_width) {
256         case MMC_BUD_WIDTH_EIGHT:
257             host->caps |= MMC_CAP_8_BIT_DATA;
258             fallthrough; /* Hosts capable of 8-bit can also do 4 bits */
259         case MMC_BUD_WIDTH_FOUR:
260             host->caps |= MMC_CAP_4_BIT_DATA;
261             break;
262         case MMC_BUD_WIDTH_ONE:
263             break;
264         default:
265             dev_err(host->parent, "Invalid \"bus-width\" value %u!\n", bus_width);
266             return -EINVAL;
267     }
268 
269     /* f_max is obtained from the optional "max-frequency" property */
270     device_property_read_u32(dev, "max-frequency", &host->f_max);
271 
272     /*
273      * Configure CD and WP pins. They are both by default active low to
274      * match the SDHCI spec. If GPIOs are provided for CD and / or WP, the
275      * mmc-gpio helpers are used to attach, configure and use them. If
276      * polarity inversion is specified in DT, one of MMC_CAP2_CD_ACTIVE_HIGH
277      * and MMC_CAP2_RO_ACTIVE_HIGH capability-2 flags is set. If the
278      * "broken-cd" property is provided, the MMC_CAP_NEEDS_POLL capability
279      * is set. If the "non-removable" property is found, the
280      * MMC_CAP_NONREMOVABLE capability is set and no card-detection
281      * configuration is performed.
282      */
283 
284     /* Parse Card Detection */
285 
286     if (device_property_read_bool(dev, "non-removable")) {
287         host->caps |= MMC_CAP_NONREMOVABLE;
288     } else {
289         if (device_property_read_bool(dev, "cd-inverted")) {
290             host->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH;
291         }
292 
293         if (device_property_read_u32(dev, "cd-debounce-delay-ms", &cd_debounce_delay_ms)) {
294             cd_debounce_delay_ms = MMC_DEBOUNCE_DELAY_MS;
295         }
296 
297         if (device_property_read_bool(dev, "broken-cd")) {
298             host->caps |= MMC_CAP_NEEDS_POLL;
299         }
300 
301         ret = mmc_gpiod_request_cd(host, "cd", 0, false, cd_debounce_delay_ms * MMC_DEBOUNCE_DELAY_MS_MUL);
302         if (!ret) {
303             dev_info(host->parent, "Got CD GPIO\n");
304         } else if (ret != -ENOENT && ret != -ENOSYS) {
305             return ret;
306         }
307     }
308 
309     /* Parse Write Protection */
310 
311     if (device_property_read_bool(dev, "wp-inverted")) {
312         host->caps2 |= MMC_CAP2_RO_ACTIVE_HIGH;
313     }
314 
315     ret = mmc_gpiod_request_ro(host, "wp", 0, 0);
316     if (!ret) {
317         dev_info(host->parent, "Got WP GPIO\n");
318     } else if (ret != -ENOENT && ret != -ENOSYS) {
319         return ret;
320     }
321 
322     if (device_property_read_bool(dev, "disable-wp")) {
323         host->caps2 |= MMC_CAP2_NO_WRITE_PROTECT;
324     }
325 
326     if (device_property_read_bool(dev, "cap-sd-highspeed")) {
327         host->caps |= MMC_CAP_SD_HIGHSPEED;
328     }
329     if (device_property_read_bool(dev, "cap-mmc-highspeed")) {
330         host->caps |= MMC_CAP_MMC_HIGHSPEED;
331     }
332     if (device_property_read_bool(dev, "sd-uhs-sdr12")) {
333         host->caps |= MMC_CAP_UHS_SDR12;
334     }
335     if (device_property_read_bool(dev, "sd-uhs-sdr25")) {
336         host->caps |= MMC_CAP_UHS_SDR25;
337     }
338     if (device_property_read_bool(dev, "sd-uhs-sdr50")) {
339         host->caps |= MMC_CAP_UHS_SDR50;
340     }
341     if (device_property_read_bool(dev, "sd-uhs-sdr104")) {
342         host->caps |= MMC_CAP_UHS_SDR104;
343     }
344     if (device_property_read_bool(dev, "sd-uhs-ddr50")) {
345         host->caps |= MMC_CAP_UHS_DDR50;
346     }
347     if (device_property_read_bool(dev, "cap-power-off-card")) {
348         host->caps |= MMC_CAP_POWER_OFF_CARD;
349     }
350     if (device_property_read_bool(dev, "cap-mmc-hw-reset")) {
351         host->caps |= MMC_CAP_HW_RESET;
352     }
353     if (device_property_read_bool(dev, "cap-sdio-irq")) {
354         host->caps |= MMC_CAP_SDIO_IRQ;
355     }
356     if (device_property_read_bool(dev, "full-pwr-cycle")) {
357         host->caps2 |= MMC_CAP2_FULL_PWR_CYCLE;
358     }
359     if (device_property_read_bool(dev, "full-pwr-cycle-in-suspend")) {
360         host->caps2 |= MMC_CAP2_FULL_PWR_CYCLE_IN_SUSPEND;
361     }
362     if (device_property_read_bool(dev, "keep-power-in-suspend")) {
363         host->pm_caps |= MMC_PM_KEEP_POWER;
364     }
365     if (device_property_read_bool(dev, "wakeup-source") ||
366         device_property_read_bool(dev, "enable-sdio-wakeup")) { /* legacy */
367         host->pm_caps |= MMC_PM_WAKE_SDIO_IRQ;
368     }
369     if (device_property_read_bool(dev, "mmc-ddr-3_3v")) {
370         host->caps |= MMC_CAP_3_3V_DDR;
371     }
372     if (device_property_read_bool(dev, "mmc-ddr-1_8v")) {
373         host->caps |= MMC_CAP_1_8V_DDR;
374     }
375     if (device_property_read_bool(dev, "mmc-ddr-1_2v")) {
376         host->caps |= MMC_CAP_1_2V_DDR;
377     }
378     if (device_property_read_bool(dev, "mmc-hs200-1_8v")) {
379         host->caps2 |= MMC_CAP2_HS200_1_8V_SDR;
380     }
381     if (device_property_read_bool(dev, "mmc-hs200-1_2v")) {
382         host->caps2 |= MMC_CAP2_HS200_1_2V_SDR;
383     }
384     if (device_property_read_bool(dev, "mmc-hs400-1_8v")) {
385         host->caps2 |= MMC_CAP2_HS400_1_8V | MMC_CAP2_HS200_1_8V_SDR;
386     }
387     if (device_property_read_bool(dev, "mmc-hs400-1_2v")) {
388         host->caps2 |= MMC_CAP2_HS400_1_2V | MMC_CAP2_HS200_1_2V_SDR;
389     }
390     if (device_property_read_bool(dev, "mmc-hs400-enhanced-strobe")) {
391         host->caps2 |= MMC_CAP2_HS400_ES;
392     }
393     if (device_property_read_bool(dev, "no-sdio")) {
394         host->caps2 |= MMC_CAP2_NO_SDIO;
395     }
396     if (device_property_read_bool(dev, "no-sd")) {
397         host->caps2 |= MMC_CAP2_NO_SD;
398     }
399     if (device_property_read_bool(dev, "no-mmc")) {
400         host->caps2 |= MMC_CAP2_NO_MMC;
401     }
402 
403     /* Must be after "non-removable" check */
404     if (device_property_read_u32(dev, "fixed-emmc-driver-type", &drv_type) == 0) {
405         if (host->caps & MMC_CAP_NONREMOVABLE) {
406             host->fixed_drv_type = drv_type;
407         } else {
408             dev_err(host->parent, "can't use fixed driver type, media is removable\n");
409         }
410     }
411 
412     host->dsr_req = !device_property_read_u32(dev, "dsr", &host->dsr);
413     if (host->dsr_req && (host->dsr & ~0xffff)) {
414         dev_err(host->parent, "device tree specified broken value for DSR: 0x%x, ignoring\n", host->dsr);
415         host->dsr_req = 0;
416     }
417 
418     device_property_read_u32(dev, "post-power-on-delay-ms", &host->ios.power_delay_ms);
419 
420     return mmc_pwrseq_alloc(host);
421 }
422 
423 EXPORT_SYMBOL(mmc_of_parse);
424 
425 /**
426  * mmc_of_parse_voltage - return mask of supported voltages
427  * @np: The device node need to be parsed.
428  * @mask: mask of voltages available for MMC/SD/SDIO
429  *
430  * Parse the "voltage-ranges" DT property, returning zero if it is not
431  * found, negative errno if the voltage-range specification is invalid,
432  * or one if the voltage-range is specified and successfully parsed.
433  */
mmc_of_parse_voltage(struct device_node * np,u32 * mask)434 int mmc_of_parse_voltage(struct device_node *np, u32 *mask)
435 {
436     const u32 *voltage_ranges;
437     int num_ranges, i;
438 
439     voltage_ranges = of_get_property(np, "voltage-ranges", &num_ranges);
440     if (!voltage_ranges) {
441         pr_debug("%pOF: voltage-ranges unspecified\n", np);
442         return 0;
443     }
444     num_ranges = num_ranges / sizeof(*voltage_ranges) / MMC_NUM_RANGES_DIV;
445     if (!num_ranges) {
446         pr_err("%pOF: voltage-ranges empty\n", np);
447         return -EINVAL;
448     }
449 
450     for (i = 0; i < num_ranges; i++) {
451         const int j = i * MMC_NUM_RANGES_DIV;
452         u32 ocr_mask;
453 
454         ocr_mask = mmc_vddrange_to_ocrmask(be32_to_cpu(voltage_ranges[j]), be32_to_cpu(voltage_ranges[j + 1]));
455         if (!ocr_mask) {
456             pr_err("%pOF: voltage-range #%d is invalid\n", np, i);
457             return -EINVAL;
458         }
459         *mask |= ocr_mask;
460     }
461 
462     return 1;
463 }
464 EXPORT_SYMBOL(mmc_of_parse_voltage);
465 
466 /**
467  * mmc_first_nonreserved_index() - get the first index that is not reserved
468  */
mmc_first_nonreserved_index(void)469 static int mmc_first_nonreserved_index(void)
470 {
471     int max;
472 
473     max = of_alias_get_highest_id("mmc");
474     if (max < 0) {
475         return 0;
476     }
477 
478     return max + 1;
479 }
480 
481 /**
482  *    mmc_alloc_host - initialise the per-host structure.
483  *    @extra: sizeof private data structure
484  *    @dev: pointer to host device model structure
485  *
486  *    Initialise the per-host structure.
487  */
mmc_alloc_host(int extra,struct device * dev)488 struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
489 {
490     int index;
491     struct mmc_host *host;
492     int alias_id, min_idx, max_idx;
493 
494     host = kzalloc(sizeof(struct mmc_host) + extra, GFP_KERNEL);
495     if (!host) {
496         return NULL;
497     }
498 
499     /* scanning will be enabled when we're ready */
500     host->rescan_disable = 1;
501 
502     alias_id = of_alias_get_id(dev->of_node, "mmc");
503     if (alias_id >= 0) {
504         index = alias_id;
505     } else {
506         min_idx = mmc_first_nonreserved_index();
507         max_idx = 0;
508 
509         index = ida_simple_get(&mmc_host_ida, min_idx, max_idx, GFP_KERNEL);
510         if (index < 0) {
511             kfree(host);
512             return NULL;
513         }
514     }
515 
516     host->index = index;
517 
518     dev_set_name(&host->class_dev, "mmc%d", host->index);
519     host->ws = wakeup_source_register(NULL, dev_name(&host->class_dev));
520 
521     host->parent = dev;
522     host->class_dev.parent = dev;
523     host->class_dev.class = &mmc_host_class;
524     device_initialize(&host->class_dev);
525     device_enable_async_suspend(&host->class_dev);
526 
527     if (mmc_gpio_alloc(host)) {
528         put_device(&host->class_dev);
529         return NULL;
530     }
531 
532     spin_lock_init(&host->lock);
533     init_waitqueue_head(&host->wq);
534     INIT_DELAYED_WORK(&host->detect, mmc_rescan);
535     INIT_DELAYED_WORK(&host->sdio_irq_work, sdio_irq_work);
536     timer_setup(&host->retune_timer, mmc_retune_timer, 0);
537 
538     /*
539      * By default, hosts do not support SGIO or large requests.
540      * They have to set these according to their abilities.
541      */
542     host->max_segs = 1;
543     host->max_seg_size = PAGE_SIZE;
544 
545     host->max_req_size = PAGE_SIZE;
546     host->max_blk_size = MMC_MAX_BLK_SIZE;
547     host->max_blk_count = PAGE_SIZE / MMC_MAX_BLK_SIZE;
548 
549     host->fixed_drv_type = -EINVAL;
550     host->ios.power_delay_ms = MMC_POWER_DELAY_MS;
551     host->ios.power_mode = MMC_POWER_UNDEFINED;
552 
553     return host;
554 }
555 
556 EXPORT_SYMBOL(mmc_alloc_host);
557 
mmc_validate_host_caps(struct mmc_host * host)558 static int mmc_validate_host_caps(struct mmc_host *host)
559 {
560     if ((host->caps & MMC_CAP_SDIO_IRQ) && (!host->ops->enable_sdio_irq)) {
561         dev_warn(host->parent, "missing ->enable_sdio_irq() ops\n");
562         return -EINVAL;
563     }
564 
565     return 0;
566 }
567 
568 struct mmc_host *primary_sdio_host;
569 EXPORT_SYMBOL(primary_sdio_host);
570 
571 /**
572  *    mmc_add_host - initialise host hardware
573  *    @host: mmc host
574  *
575  *    Register the host with the driver model. The host must be
576  *    prepared to start servicing requests before this function
577  *    completes.
578  */
mmc_add_host(struct mmc_host * host)579 int mmc_add_host(struct mmc_host *host)
580 {
581     int err;
582     err = mmc_validate_host_caps(host);
583     if (err) {
584         return err;
585     }
586 
587     err = device_add(&host->class_dev);
588     if (err) {
589         return err;
590     }
591 
592     led_trigger_register_simple(dev_name(&host->class_dev), &host->led);
593 
594 #ifdef CONFIG_DEBUG_FS
595     mmc_add_host_debugfs(host);
596 #endif
597 
598     mmc_start_host(host);
599     return 0;
600 }
601 
602 EXPORT_SYMBOL(mmc_add_host);
603 
604 /**
605  *    mmc_remove_host - remove host hardware
606  *    @host: mmc host
607  *
608  *    Unregister and remove all cards associated with this host,
609  *    and power down the MMC bus. No new requests will be issued
610  *    after this function has returned.
611  */
mmc_remove_host(struct mmc_host * host)612 void mmc_remove_host(struct mmc_host *host)
613 {
614     mmc_stop_host(host);
615 
616 #ifdef CONFIG_DEBUG_FS
617     mmc_remove_host_debugfs(host);
618 #endif
619 
620     device_del(&host->class_dev);
621 
622     led_trigger_unregister_simple(host->led);
623 }
624 
625 EXPORT_SYMBOL(mmc_remove_host);
626 
627 /**
628  *    mmc_free_host - free the host structure
629  *    @host: mmc host
630  *
631  *    Free the host once all references to it have been dropped.
632  */
mmc_free_host(struct mmc_host * host)633 void mmc_free_host(struct mmc_host *host)
634 {
635     mmc_pwrseq_free(host);
636     put_device(&host->class_dev);
637 }
638 
639 EXPORT_SYMBOL(mmc_free_host);
640 
641 /**
642  * mmc_host_rescan - triger software rescan flow
643  * @host: mmc host
644  *
645  * rescan slot attach in the assigned host.
646  * If @host is NULL, default rescan primary_sdio_host
647  * saved by mmc_add_host().
648  * OR, rescan host from argument.
649  *
650  */
mmc_host_rescan(struct mmc_host * host,int val,int is_cap_sdio_irq)651 int mmc_host_rescan(struct mmc_host *host, int val, int is_cap_sdio_irq)
652 {
653     if (primary_sdio_host != NULL) {
654         if (!host) {
655             host = primary_sdio_host;
656         } else {
657             pr_info("%s: mmc_host_rescan pass in host from argument!\n", mmc_hostname(host));
658         }
659     } else {
660         pr_err("sdio: host isn't  initialization successfully.\n");
661         return -ENOMEDIUM;
662     }
663 
664     pr_info("%s:mmc host rescan start!\n", mmc_hostname(host));
665 
666     /*  0: oob  1:cap-sdio-irq */
667     if (is_cap_sdio_irq == 1) {
668         host->caps |= MMC_CAP_SDIO_IRQ;
669     } else if (is_cap_sdio_irq == 0) {
670         host->caps &= ~MMC_CAP_SDIO_IRQ;
671     } else {
672         dev_err(&host->class_dev, "sdio: host doesn't identify oob or sdio_irq mode!\n");
673         return -ENOMEDIUM;
674     }
675 
676     if (!(host->caps & MMC_CAP_NONREMOVABLE) && host->ops->set_sdio_status) {
677         host->ops->set_sdio_status(host, val);
678     }
679 
680     return 0;
681 }
682 EXPORT_SYMBOL(mmc_host_rescan);
683