Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/mmc/core/bus.c |
| 3 | * |
| 4 | * Copyright (C) 2003 Russell King, All Rights Reserved. |
| 5 | * Copyright (C) 2007 Pierre Ossman |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | * MMC card bus driver model |
| 12 | */ |
| 13 | |
Paul Gortmaker | 3ef77af | 2011-07-10 12:42:00 -0400 | [diff] [blame] | 14 | #include <linux/export.h> |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 15 | #include <linux/device.h> |
| 16 | #include <linux/err.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 17 | #include <linux/slab.h> |
Paul Gortmaker | 0205a90 | 2011-07-15 12:01:27 -0400 | [diff] [blame] | 18 | #include <linux/stat.h> |
Ohad Ben-Cohen | 516d5cc | 2010-10-02 13:54:08 +0200 | [diff] [blame] | 19 | #include <linux/pm_runtime.h> |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 20 | |
| 21 | #include <linux/mmc/card.h> |
| 22 | #include <linux/mmc/host.h> |
| 23 | |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 24 | #include "core.h" |
Pierre Ossman | 1a632f8 | 2007-07-30 15:15:30 +0200 | [diff] [blame] | 25 | #include "sdio_cis.h" |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 26 | #include "bus.h" |
| 27 | |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 28 | #define to_mmc_driver(d) container_of(d, struct mmc_driver, drv) |
Asutosh Das | bbc8478 | 2013-02-11 15:31:35 +0530 | [diff] [blame] | 29 | #define RUNTIME_SUSPEND_DELAY_MS 10000 |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 30 | |
| 31 | static ssize_t mmc_type_show(struct device *dev, |
| 32 | struct device_attribute *attr, char *buf) |
| 33 | { |
Andy Shevchenko | 265cdc9 | 2010-09-17 20:32:25 -0400 | [diff] [blame] | 34 | struct mmc_card *card = mmc_dev_to_card(dev); |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 35 | |
| 36 | switch (card->type) { |
| 37 | case MMC_TYPE_MMC: |
| 38 | return sprintf(buf, "MMC\n"); |
| 39 | case MMC_TYPE_SD: |
| 40 | return sprintf(buf, "SD\n"); |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 41 | case MMC_TYPE_SDIO: |
| 42 | return sprintf(buf, "SDIO\n"); |
Michal Miroslaw | 7310ece | 2010-08-10 18:01:40 -0700 | [diff] [blame] | 43 | case MMC_TYPE_SD_COMBO: |
| 44 | return sprintf(buf, "SDcombo\n"); |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 45 | default: |
| 46 | return -EFAULT; |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | static struct device_attribute mmc_dev_attrs[] = { |
Pierre Ossman | 51ec92e | 2008-03-21 23:54:50 +0100 | [diff] [blame] | 51 | __ATTR(type, S_IRUGO, mmc_type_show, NULL), |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 52 | __ATTR_NULL, |
| 53 | }; |
| 54 | |
| 55 | /* |
| 56 | * This currently matches any MMC driver to any MMC card - drivers |
| 57 | * themselves make the decision whether to drive this card in their |
| 58 | * probe method. |
| 59 | */ |
| 60 | static int mmc_bus_match(struct device *dev, struct device_driver *drv) |
| 61 | { |
| 62 | return 1; |
| 63 | } |
| 64 | |
| 65 | static int |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 66 | mmc_bus_uevent(struct device *dev, struct kobj_uevent_env *env) |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 67 | { |
Andy Shevchenko | 265cdc9 | 2010-09-17 20:32:25 -0400 | [diff] [blame] | 68 | struct mmc_card *card = mmc_dev_to_card(dev); |
Pierre Ossman | 9eb3a94 | 2007-06-17 11:18:46 +0200 | [diff] [blame] | 69 | const char *type; |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 70 | int retval = 0; |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 71 | |
| 72 | switch (card->type) { |
| 73 | case MMC_TYPE_MMC: |
Pierre Ossman | 9eb3a94 | 2007-06-17 11:18:46 +0200 | [diff] [blame] | 74 | type = "MMC"; |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 75 | break; |
| 76 | case MMC_TYPE_SD: |
Pierre Ossman | 9eb3a94 | 2007-06-17 11:18:46 +0200 | [diff] [blame] | 77 | type = "SD"; |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 78 | break; |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 79 | case MMC_TYPE_SDIO: |
Pierre Ossman | 9eb3a94 | 2007-06-17 11:18:46 +0200 | [diff] [blame] | 80 | type = "SDIO"; |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 81 | break; |
Michal Miroslaw | 7310ece | 2010-08-10 18:01:40 -0700 | [diff] [blame] | 82 | case MMC_TYPE_SD_COMBO: |
| 83 | type = "SDcombo"; |
| 84 | break; |
Pierre Ossman | 9eb3a94 | 2007-06-17 11:18:46 +0200 | [diff] [blame] | 85 | default: |
| 86 | type = NULL; |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 87 | } |
| 88 | |
Pierre Ossman | 9eb3a94 | 2007-06-17 11:18:46 +0200 | [diff] [blame] | 89 | if (type) { |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 90 | retval = add_uevent_var(env, "MMC_TYPE=%s", type); |
| 91 | if (retval) |
| 92 | return retval; |
Pierre Ossman | 9eb3a94 | 2007-06-17 11:18:46 +0200 | [diff] [blame] | 93 | } |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 94 | |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 95 | retval = add_uevent_var(env, "MMC_NAME=%s", mmc_card_name(card)); |
Andy Whitcroft | 6b0b628 | 2009-02-23 12:38:41 +0000 | [diff] [blame] | 96 | if (retval) |
| 97 | return retval; |
| 98 | |
| 99 | /* |
| 100 | * Request the mmc_block device. Note: that this is a direct request |
| 101 | * for the module it carries no information as to what is inserted. |
| 102 | */ |
| 103 | retval = add_uevent_var(env, "MODALIAS=mmc:block"); |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 104 | |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 105 | return retval; |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | static int mmc_bus_probe(struct device *dev) |
| 109 | { |
| 110 | struct mmc_driver *drv = to_mmc_driver(dev->driver); |
Andy Shevchenko | 265cdc9 | 2010-09-17 20:32:25 -0400 | [diff] [blame] | 111 | struct mmc_card *card = mmc_dev_to_card(dev); |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 112 | |
| 113 | return drv->probe(card); |
| 114 | } |
| 115 | |
| 116 | static int mmc_bus_remove(struct device *dev) |
| 117 | { |
| 118 | struct mmc_driver *drv = to_mmc_driver(dev->driver); |
Andy Shevchenko | 265cdc9 | 2010-09-17 20:32:25 -0400 | [diff] [blame] | 119 | struct mmc_card *card = mmc_dev_to_card(dev); |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 120 | |
| 121 | drv->remove(card); |
| 122 | |
| 123 | return 0; |
| 124 | } |
| 125 | |
Tatyana Brokhman | d812738 | 2013-05-28 09:45:17 +0300 | [diff] [blame] | 126 | static void mmc_bus_shutdown(struct device *dev) |
| 127 | { |
| 128 | struct mmc_driver *drv = to_mmc_driver(dev->driver); |
| 129 | struct mmc_card *card = mmc_dev_to_card(dev); |
| 130 | |
Eugene Yasman | bc6170f | 2013-06-12 17:55:33 +0300 | [diff] [blame] | 131 | if (!drv) { |
| 132 | pr_debug("%s: %s: drv is NULL\n", dev_name(dev), __func__); |
| 133 | return; |
| 134 | } |
| 135 | |
| 136 | if (!card) { |
| 137 | pr_debug("%s: %s: card is NULL\n", dev_name(dev), __func__); |
| 138 | return; |
| 139 | } |
| 140 | |
Tatyana Brokhman | d812738 | 2013-05-28 09:45:17 +0300 | [diff] [blame] | 141 | if (drv->shutdown) |
| 142 | drv->shutdown(card); |
| 143 | } |
| 144 | |
Rohit Vaswani | d4e3d52 | 2012-03-28 16:03:47 -0700 | [diff] [blame] | 145 | #ifdef CONFIG_PM_SLEEP |
Chuanxiao Dong | 32d317c | 2012-04-11 19:54:38 +0800 | [diff] [blame] | 146 | static int mmc_bus_suspend(struct device *dev) |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 147 | { |
| 148 | struct mmc_driver *drv = to_mmc_driver(dev->driver); |
Andy Shevchenko | 265cdc9 | 2010-09-17 20:32:25 -0400 | [diff] [blame] | 149 | struct mmc_card *card = mmc_dev_to_card(dev); |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 150 | int ret = 0; |
| 151 | |
| 152 | if (dev->driver && drv->suspend) |
Chuanxiao Dong | 32d317c | 2012-04-11 19:54:38 +0800 | [diff] [blame] | 153 | ret = drv->suspend(card); |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 154 | return ret; |
| 155 | } |
| 156 | |
| 157 | static int mmc_bus_resume(struct device *dev) |
| 158 | { |
| 159 | struct mmc_driver *drv = to_mmc_driver(dev->driver); |
Andy Shevchenko | 265cdc9 | 2010-09-17 20:32:25 -0400 | [diff] [blame] | 160 | struct mmc_card *card = mmc_dev_to_card(dev); |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 161 | int ret = 0; |
| 162 | |
| 163 | if (dev->driver && drv->resume) |
| 164 | ret = drv->resume(card); |
| 165 | return ret; |
| 166 | } |
Rohit Vaswani | d4e3d52 | 2012-03-28 16:03:47 -0700 | [diff] [blame] | 167 | #endif |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 168 | |
Ohad Ben-Cohen | 516d5cc | 2010-10-02 13:54:08 +0200 | [diff] [blame] | 169 | #ifdef CONFIG_PM_RUNTIME |
| 170 | |
| 171 | static int mmc_runtime_suspend(struct device *dev) |
| 172 | { |
| 173 | struct mmc_card *card = mmc_dev_to_card(dev); |
| 174 | |
Maya Erez | 89b35c0 | 2013-05-22 13:04:14 +0300 | [diff] [blame] | 175 | if (mmc_use_core_runtime_pm(card->host)) { |
| 176 | /* |
| 177 | * If idle time bkops is running on the card, let's not get |
| 178 | * into suspend. |
| 179 | */ |
| 180 | if (mmc_card_doing_bkops(card) && mmc_card_is_prog_state(card)) |
| 181 | return -EBUSY; |
| 182 | else |
| 183 | return 0; |
| 184 | } else { |
Asutosh Das | bbc8478 | 2013-02-11 15:31:35 +0530 | [diff] [blame] | 185 | return mmc_power_save_host(card->host); |
Maya Erez | 89b35c0 | 2013-05-22 13:04:14 +0300 | [diff] [blame] | 186 | } |
Ohad Ben-Cohen | 516d5cc | 2010-10-02 13:54:08 +0200 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | static int mmc_runtime_resume(struct device *dev) |
| 190 | { |
| 191 | struct mmc_card *card = mmc_dev_to_card(dev); |
| 192 | |
Asutosh Das | bbc8478 | 2013-02-11 15:31:35 +0530 | [diff] [blame] | 193 | if (mmc_use_core_runtime_pm(card->host)) |
| 194 | return 0; |
| 195 | else |
| 196 | return mmc_power_restore_host(card->host); |
Ohad Ben-Cohen | 516d5cc | 2010-10-02 13:54:08 +0200 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | static int mmc_runtime_idle(struct device *dev) |
| 200 | { |
Asutosh Das | bbc8478 | 2013-02-11 15:31:35 +0530 | [diff] [blame] | 201 | struct mmc_card *card = mmc_dev_to_card(dev); |
| 202 | struct mmc_host *host = card->host; |
| 203 | int ret = 0; |
| 204 | |
| 205 | if (mmc_use_core_runtime_pm(card->host)) { |
| 206 | ret = pm_schedule_suspend(dev, card->idle_timeout); |
Asutosh Das | f92aac8 | 2013-04-09 14:03:17 +0530 | [diff] [blame] | 207 | if ((ret < 0) && (dev->power.runtime_error || |
| 208 | dev->power.disable_depth > 0)) { |
| 209 | pr_err("%s: %s: %s: pm_schedule_suspend failed: err: %d\n", |
| 210 | mmc_hostname(host), __func__, dev_name(dev), |
| 211 | ret); |
Asutosh Das | bbc8478 | 2013-02-11 15:31:35 +0530 | [diff] [blame] | 212 | return ret; |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | return ret; |
Ohad Ben-Cohen | 516d5cc | 2010-10-02 13:54:08 +0200 | [diff] [blame] | 217 | } |
| 218 | |
Ohad Ben-Cohen | 516d5cc | 2010-10-02 13:54:08 +0200 | [diff] [blame] | 219 | #endif /* !CONFIG_PM_RUNTIME */ |
| 220 | |
Chuanxiao Dong | 32d317c | 2012-04-11 19:54:38 +0800 | [diff] [blame] | 221 | static const struct dev_pm_ops mmc_bus_pm_ops = { |
| 222 | SET_RUNTIME_PM_OPS(mmc_runtime_suspend, mmc_runtime_resume, |
| 223 | mmc_runtime_idle) |
| 224 | SET_SYSTEM_SLEEP_PM_OPS(mmc_bus_suspend, mmc_bus_resume) |
| 225 | }; |
| 226 | |
Asutosh Das | bbc8478 | 2013-02-11 15:31:35 +0530 | [diff] [blame] | 227 | static ssize_t show_rpm_delay(struct device *dev, struct device_attribute *attr, |
| 228 | char *buf) |
| 229 | { |
| 230 | struct mmc_card *card = mmc_dev_to_card(dev); |
| 231 | |
| 232 | if (!card) { |
| 233 | pr_err("%s: %s: card is NULL\n", dev_name(dev), __func__); |
| 234 | return -EINVAL; |
| 235 | } |
| 236 | |
| 237 | return snprintf(buf, PAGE_SIZE, "%u\n", card->idle_timeout); |
| 238 | } |
| 239 | |
| 240 | static ssize_t store_rpm_delay(struct device *dev, struct device_attribute |
| 241 | *attr, const char *buf, size_t count) |
| 242 | { |
| 243 | struct mmc_card *card = mmc_dev_to_card(dev); |
| 244 | unsigned int delay; |
| 245 | |
| 246 | if (!card) { |
| 247 | pr_err("%s: %s: card is NULL\n", dev_name(dev), __func__); |
| 248 | return -EINVAL; |
| 249 | } |
| 250 | |
| 251 | if (!kstrtou32(buf, 0, &delay)) { |
| 252 | if (delay < 2000) { |
| 253 | pr_err("%s: %s: less than 2 sec delay is unsupported\n", |
| 254 | mmc_hostname(card->host), __func__); |
| 255 | return -EINVAL; |
| 256 | } |
| 257 | card->idle_timeout = delay; |
| 258 | } |
| 259 | |
| 260 | return count; |
| 261 | } |
| 262 | |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 263 | static struct bus_type mmc_bus_type = { |
| 264 | .name = "mmc", |
| 265 | .dev_attrs = mmc_dev_attrs, |
| 266 | .match = mmc_bus_match, |
| 267 | .uevent = mmc_bus_uevent, |
| 268 | .probe = mmc_bus_probe, |
| 269 | .remove = mmc_bus_remove, |
Tatyana Brokhman | d812738 | 2013-05-28 09:45:17 +0300 | [diff] [blame] | 270 | .shutdown = mmc_bus_shutdown, |
Chuanxiao Dong | 32d317c | 2012-04-11 19:54:38 +0800 | [diff] [blame] | 271 | .pm = &mmc_bus_pm_ops, |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 272 | }; |
| 273 | |
| 274 | int mmc_register_bus(void) |
| 275 | { |
| 276 | return bus_register(&mmc_bus_type); |
| 277 | } |
| 278 | |
| 279 | void mmc_unregister_bus(void) |
| 280 | { |
| 281 | bus_unregister(&mmc_bus_type); |
| 282 | } |
| 283 | |
| 284 | /** |
| 285 | * mmc_register_driver - register a media driver |
| 286 | * @drv: MMC media driver |
| 287 | */ |
| 288 | int mmc_register_driver(struct mmc_driver *drv) |
| 289 | { |
| 290 | drv->drv.bus = &mmc_bus_type; |
| 291 | return driver_register(&drv->drv); |
| 292 | } |
| 293 | |
| 294 | EXPORT_SYMBOL(mmc_register_driver); |
| 295 | |
| 296 | /** |
| 297 | * mmc_unregister_driver - unregister a media driver |
| 298 | * @drv: MMC media driver |
| 299 | */ |
| 300 | void mmc_unregister_driver(struct mmc_driver *drv) |
| 301 | { |
| 302 | drv->drv.bus = &mmc_bus_type; |
| 303 | driver_unregister(&drv->drv); |
| 304 | } |
| 305 | |
| 306 | EXPORT_SYMBOL(mmc_unregister_driver); |
| 307 | |
| 308 | static void mmc_release_card(struct device *dev) |
| 309 | { |
Andy Shevchenko | 265cdc9 | 2010-09-17 20:32:25 -0400 | [diff] [blame] | 310 | struct mmc_card *card = mmc_dev_to_card(dev); |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 311 | |
Pierre Ossman | 1a632f8 | 2007-07-30 15:15:30 +0200 | [diff] [blame] | 312 | sdio_free_common_cis(card); |
| 313 | |
Pierre Ossman | 759bdc7 | 2007-09-19 18:42:16 +0200 | [diff] [blame] | 314 | if (card->info) |
| 315 | kfree(card->info); |
| 316 | |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 317 | kfree(card); |
| 318 | } |
| 319 | |
| 320 | /* |
| 321 | * Allocate and initialise a new MMC card structure. |
| 322 | */ |
Pierre Ossman | 51ec92e | 2008-03-21 23:54:50 +0100 | [diff] [blame] | 323 | struct mmc_card *mmc_alloc_card(struct mmc_host *host, struct device_type *type) |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 324 | { |
| 325 | struct mmc_card *card; |
| 326 | |
Mariusz Kozlowski | 733cb1e | 2007-08-10 14:00:47 -0700 | [diff] [blame] | 327 | card = kzalloc(sizeof(struct mmc_card), GFP_KERNEL); |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 328 | if (!card) |
| 329 | return ERR_PTR(-ENOMEM); |
| 330 | |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 331 | card->host = host; |
| 332 | |
| 333 | device_initialize(&card->dev); |
| 334 | |
| 335 | card->dev.parent = mmc_classdev(host); |
| 336 | card->dev.bus = &mmc_bus_type; |
| 337 | card->dev.release = mmc_release_card; |
Pierre Ossman | 51ec92e | 2008-03-21 23:54:50 +0100 | [diff] [blame] | 338 | card->dev.type = type; |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 339 | |
Yaniv Gardi | 4c4383f | 2012-10-11 18:29:28 +0200 | [diff] [blame] | 340 | spin_lock_init(&card->bkops_info.bkops_stats.lock); |
Tatyana Brokhman | 464fbe1 | 2012-10-07 10:33:13 +0200 | [diff] [blame] | 341 | spin_lock_init(&card->wr_pack_stats.lock); |
| 342 | |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 343 | return card; |
| 344 | } |
| 345 | |
| 346 | /* |
| 347 | * Register a new MMC card with the driver model. |
| 348 | */ |
| 349 | int mmc_add_card(struct mmc_card *card) |
| 350 | { |
| 351 | int ret; |
Pierre Ossman | 109b5be | 2007-07-23 00:12:10 +0200 | [diff] [blame] | 352 | const char *type; |
Subhash Jadavani | 6500c8e | 2012-03-30 12:10:18 +0530 | [diff] [blame] | 353 | const char *uhs_bus_speed_mode = ""; |
| 354 | static const char *const uhs_speeds[] = { |
| 355 | [UHS_SDR12_BUS_SPEED] = "SDR12 ", |
| 356 | [UHS_SDR25_BUS_SPEED] = "SDR25 ", |
| 357 | [UHS_SDR50_BUS_SPEED] = "SDR50 ", |
| 358 | [UHS_SDR104_BUS_SPEED] = "SDR104 ", |
| 359 | [UHS_DDR50_BUS_SPEED] = "DDR50 ", |
| 360 | }; |
| 361 | |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 362 | |
Kay Sievers | d1b2686 | 2008-11-08 21:37:46 +0100 | [diff] [blame] | 363 | dev_set_name(&card->dev, "%s:%04x", mmc_hostname(card->host), card->rca); |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 364 | |
Pierre Ossman | 109b5be | 2007-07-23 00:12:10 +0200 | [diff] [blame] | 365 | switch (card->type) { |
| 366 | case MMC_TYPE_MMC: |
| 367 | type = "MMC"; |
| 368 | break; |
| 369 | case MMC_TYPE_SD: |
| 370 | type = "SD"; |
Arindam Nath | 3a30351 | 2011-05-05 12:19:03 +0530 | [diff] [blame] | 371 | if (mmc_card_blockaddr(card)) { |
| 372 | if (mmc_card_ext_capacity(card)) |
| 373 | type = "SDXC"; |
| 374 | else |
| 375 | type = "SDHC"; |
| 376 | } |
Pierre Ossman | 109b5be | 2007-07-23 00:12:10 +0200 | [diff] [blame] | 377 | break; |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 378 | case MMC_TYPE_SDIO: |
| 379 | type = "SDIO"; |
| 380 | break; |
Michal Miroslaw | 7310ece | 2010-08-10 18:01:40 -0700 | [diff] [blame] | 381 | case MMC_TYPE_SD_COMBO: |
| 382 | type = "SD-combo"; |
| 383 | if (mmc_card_blockaddr(card)) |
| 384 | type = "SDHC-combo"; |
Michał Mirosław | 9bc2184 | 2011-04-09 08:16:47 +0200 | [diff] [blame] | 385 | break; |
Pierre Ossman | 109b5be | 2007-07-23 00:12:10 +0200 | [diff] [blame] | 386 | default: |
| 387 | type = "?"; |
| 388 | break; |
| 389 | } |
| 390 | |
Subhash Jadavani | 6500c8e | 2012-03-30 12:10:18 +0530 | [diff] [blame] | 391 | if (mmc_sd_card_uhs(card) && |
| 392 | (card->sd_bus_speed < ARRAY_SIZE(uhs_speeds))) |
| 393 | uhs_bus_speed_mode = uhs_speeds[card->sd_bus_speed]; |
| 394 | |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 395 | if (mmc_host_is_spi(card->host)) { |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 396 | pr_info("%s: new %s%s%s card on SPI\n", |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 397 | mmc_hostname(card->host), |
| 398 | mmc_card_highspeed(card) ? "high speed " : "", |
Adrian Hunter | 0f8d8ea | 2010-08-24 13:20:26 +0300 | [diff] [blame] | 399 | mmc_card_ddr_mode(card) ? "DDR " : "", |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 400 | type); |
| 401 | } else { |
Venkat Gopalakrishnan | 84600ca | 2013-03-14 11:50:25 -0700 | [diff] [blame] | 402 | pr_info("%s: new %s%s%s%s%s%s card at address %04x\n", |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 403 | mmc_hostname(card->host), |
Philip Rakity | a303c53 | 2011-11-14 19:14:38 -0800 | [diff] [blame] | 404 | mmc_card_uhs(card) ? "ultra high speed " : |
Arindam Nath | 3a30351 | 2011-05-05 12:19:03 +0530 | [diff] [blame] | 405 | (mmc_card_highspeed(card) ? "high speed " : ""), |
Venkat Gopalakrishnan | 84600ca | 2013-03-14 11:50:25 -0700 | [diff] [blame] | 406 | (mmc_card_hs400(card) ? "HS400 " : ""), |
Girish K S | a4924c7 | 2012-01-11 14:04:52 -0500 | [diff] [blame] | 407 | (mmc_card_hs200(card) ? "HS200 " : ""), |
Adrian Hunter | 0f8d8ea | 2010-08-24 13:20:26 +0300 | [diff] [blame] | 408 | mmc_card_ddr_mode(card) ? "DDR " : "", |
Subhash Jadavani | 6500c8e | 2012-03-30 12:10:18 +0530 | [diff] [blame] | 409 | uhs_bus_speed_mode, type, card->rca); |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 410 | } |
Pierre Ossman | 109b5be | 2007-07-23 00:12:10 +0200 | [diff] [blame] | 411 | |
Haavard Skinnemoen | f4b7f92 | 2008-07-24 14:18:58 +0200 | [diff] [blame] | 412 | #ifdef CONFIG_DEBUG_FS |
| 413 | mmc_add_card_debugfs(card); |
| 414 | #endif |
Konstantin Dorfman | 69bd0fb | 2012-12-12 16:12:08 +0200 | [diff] [blame] | 415 | mmc_init_context_info(card->host); |
Haavard Skinnemoen | f4b7f92 | 2008-07-24 14:18:58 +0200 | [diff] [blame] | 416 | |
Asutosh Das | 4bc8124 | 2013-09-06 11:58:12 +0530 | [diff] [blame] | 417 | ret = pm_runtime_set_active(&card->dev); |
| 418 | if (ret) |
| 419 | pr_err("%s: %s: failed setting runtime active: ret: %d\n", |
| 420 | mmc_hostname(card->host), __func__, ret); |
| 421 | else if (!mmc_card_sdio(card) && mmc_use_core_runtime_pm(card->host)) |
| 422 | pm_runtime_enable(&card->dev); |
Asutosh Das | bbc8478 | 2013-02-11 15:31:35 +0530 | [diff] [blame] | 423 | |
Asutosh Das | d4141c20 | 2013-06-03 18:29:59 +0530 | [diff] [blame] | 424 | if (mmc_card_sdio(card)) { |
| 425 | ret = device_init_wakeup(&card->dev, true); |
| 426 | if (ret) |
| 427 | pr_err("%s: %s: failed to init wakeup: %d\n", |
| 428 | mmc_hostname(card->host), __func__, ret); |
| 429 | } |
Viresh Kumar | 1a2727e | 2011-01-04 12:55:14 -0500 | [diff] [blame] | 430 | ret = device_add(&card->dev); |
| 431 | if (ret) |
| 432 | return ret; |
| 433 | |
Asutosh Das | f1310ab | 2013-04-22 18:42:51 +0530 | [diff] [blame] | 434 | if (mmc_use_core_runtime_pm(card->host) && !mmc_card_sdio(card)) { |
Asutosh Das | bbc8478 | 2013-02-11 15:31:35 +0530 | [diff] [blame] | 435 | card->rpm_attrib.show = show_rpm_delay; |
| 436 | card->rpm_attrib.store = store_rpm_delay; |
| 437 | sysfs_attr_init(&card->rpm_attrib.attr); |
| 438 | card->rpm_attrib.attr.name = "runtime_pm_timeout"; |
| 439 | card->rpm_attrib.attr.mode = S_IRUGO | S_IWUSR; |
| 440 | |
| 441 | ret = device_create_file(&card->dev, &card->rpm_attrib); |
| 442 | if (ret) |
| 443 | pr_err("%s: %s: creating runtime pm sysfs entry: failed: %d\n", |
| 444 | mmc_hostname(card->host), __func__, ret); |
| 445 | /* Default timeout is 10 seconds */ |
| 446 | card->idle_timeout = RUNTIME_SUSPEND_DELAY_MS; |
| 447 | } |
| 448 | |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 449 | mmc_card_set_present(card); |
| 450 | |
| 451 | return 0; |
| 452 | } |
| 453 | |
| 454 | /* |
| 455 | * Unregister a new MMC card with the driver model, and |
| 456 | * (eventually) free it. |
| 457 | */ |
| 458 | void mmc_remove_card(struct mmc_card *card) |
| 459 | { |
Haavard Skinnemoen | f4b7f92 | 2008-07-24 14:18:58 +0200 | [diff] [blame] | 460 | #ifdef CONFIG_DEBUG_FS |
| 461 | mmc_remove_card_debugfs(card); |
| 462 | #endif |
| 463 | |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 464 | if (mmc_card_present(card)) { |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 465 | if (mmc_host_is_spi(card->host)) { |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 466 | pr_info("%s: SPI card removed\n", |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 467 | mmc_hostname(card->host)); |
| 468 | } else { |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 469 | pr_info("%s: card %04x removed\n", |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 470 | mmc_hostname(card->host), card->rca); |
| 471 | } |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 472 | device_del(&card->dev); |
| 473 | } |
| 474 | |
Tatyana Brokhman | 464fbe1 | 2012-10-07 10:33:13 +0200 | [diff] [blame] | 475 | kfree(card->wr_pack_stats.packing_events); |
Sujit Reddy Thumma | b361687 | 2013-12-05 19:35:43 +0530 | [diff] [blame] | 476 | kfree(card->cached_ext_csd); |
Tatyana Brokhman | 464fbe1 | 2012-10-07 10:33:13 +0200 | [diff] [blame] | 477 | |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 478 | put_device(&card->dev); |
| 479 | } |
| 480 | |