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 | |
Rohit Vaswani | d4e3d52 | 2012-03-28 16:03:47 -0700 | [diff] [blame] | 126 | #ifdef CONFIG_PM_SLEEP |
Chuanxiao Dong | 32d317c | 2012-04-11 19:54:38 +0800 | [diff] [blame] | 127 | static int mmc_bus_suspend(struct device *dev) |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 128 | { |
| 129 | struct mmc_driver *drv = to_mmc_driver(dev->driver); |
Andy Shevchenko | 265cdc9 | 2010-09-17 20:32:25 -0400 | [diff] [blame] | 130 | struct mmc_card *card = mmc_dev_to_card(dev); |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 131 | int ret = 0; |
| 132 | |
| 133 | if (dev->driver && drv->suspend) |
Chuanxiao Dong | 32d317c | 2012-04-11 19:54:38 +0800 | [diff] [blame] | 134 | ret = drv->suspend(card); |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 135 | return ret; |
| 136 | } |
| 137 | |
| 138 | static int mmc_bus_resume(struct device *dev) |
| 139 | { |
| 140 | struct mmc_driver *drv = to_mmc_driver(dev->driver); |
Andy Shevchenko | 265cdc9 | 2010-09-17 20:32:25 -0400 | [diff] [blame] | 141 | struct mmc_card *card = mmc_dev_to_card(dev); |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 142 | int ret = 0; |
| 143 | |
| 144 | if (dev->driver && drv->resume) |
| 145 | ret = drv->resume(card); |
| 146 | return ret; |
| 147 | } |
Rohit Vaswani | d4e3d52 | 2012-03-28 16:03:47 -0700 | [diff] [blame] | 148 | #endif |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 149 | |
Ohad Ben-Cohen | 516d5cc | 2010-10-02 13:54:08 +0200 | [diff] [blame] | 150 | #ifdef CONFIG_PM_RUNTIME |
| 151 | |
| 152 | static int mmc_runtime_suspend(struct device *dev) |
| 153 | { |
| 154 | struct mmc_card *card = mmc_dev_to_card(dev); |
| 155 | |
Asutosh Das | bbc8478 | 2013-02-11 15:31:35 +0530 | [diff] [blame] | 156 | if (mmc_use_core_runtime_pm(card->host)) |
| 157 | return 0; |
| 158 | else |
| 159 | return mmc_power_save_host(card->host); |
Ohad Ben-Cohen | 516d5cc | 2010-10-02 13:54:08 +0200 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | static int mmc_runtime_resume(struct device *dev) |
| 163 | { |
| 164 | struct mmc_card *card = mmc_dev_to_card(dev); |
| 165 | |
Asutosh Das | bbc8478 | 2013-02-11 15:31:35 +0530 | [diff] [blame] | 166 | if (mmc_use_core_runtime_pm(card->host)) |
| 167 | return 0; |
| 168 | else |
| 169 | return mmc_power_restore_host(card->host); |
Ohad Ben-Cohen | 516d5cc | 2010-10-02 13:54:08 +0200 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | static int mmc_runtime_idle(struct device *dev) |
| 173 | { |
Asutosh Das | bbc8478 | 2013-02-11 15:31:35 +0530 | [diff] [blame] | 174 | struct mmc_card *card = mmc_dev_to_card(dev); |
| 175 | struct mmc_host *host = card->host; |
| 176 | int ret = 0; |
| 177 | |
| 178 | if (mmc_use_core_runtime_pm(card->host)) { |
| 179 | ret = pm_schedule_suspend(dev, card->idle_timeout); |
| 180 | if (ret) { |
| 181 | pr_err("%s: %s: pm_schedule_suspend failed: err: %d\n", |
| 182 | mmc_hostname(host), __func__, ret); |
| 183 | return ret; |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | return ret; |
Ohad Ben-Cohen | 516d5cc | 2010-10-02 13:54:08 +0200 | [diff] [blame] | 188 | } |
| 189 | |
Ohad Ben-Cohen | 516d5cc | 2010-10-02 13:54:08 +0200 | [diff] [blame] | 190 | #endif /* !CONFIG_PM_RUNTIME */ |
| 191 | |
Chuanxiao Dong | 32d317c | 2012-04-11 19:54:38 +0800 | [diff] [blame] | 192 | static const struct dev_pm_ops mmc_bus_pm_ops = { |
| 193 | SET_RUNTIME_PM_OPS(mmc_runtime_suspend, mmc_runtime_resume, |
| 194 | mmc_runtime_idle) |
| 195 | SET_SYSTEM_SLEEP_PM_OPS(mmc_bus_suspend, mmc_bus_resume) |
| 196 | }; |
| 197 | |
Asutosh Das | bbc8478 | 2013-02-11 15:31:35 +0530 | [diff] [blame] | 198 | static ssize_t show_rpm_delay(struct device *dev, struct device_attribute *attr, |
| 199 | char *buf) |
| 200 | { |
| 201 | struct mmc_card *card = mmc_dev_to_card(dev); |
| 202 | |
| 203 | if (!card) { |
| 204 | pr_err("%s: %s: card is NULL\n", dev_name(dev), __func__); |
| 205 | return -EINVAL; |
| 206 | } |
| 207 | |
| 208 | return snprintf(buf, PAGE_SIZE, "%u\n", card->idle_timeout); |
| 209 | } |
| 210 | |
| 211 | static ssize_t store_rpm_delay(struct device *dev, struct device_attribute |
| 212 | *attr, const char *buf, size_t count) |
| 213 | { |
| 214 | struct mmc_card *card = mmc_dev_to_card(dev); |
| 215 | unsigned int delay; |
| 216 | |
| 217 | if (!card) { |
| 218 | pr_err("%s: %s: card is NULL\n", dev_name(dev), __func__); |
| 219 | return -EINVAL; |
| 220 | } |
| 221 | |
| 222 | if (!kstrtou32(buf, 0, &delay)) { |
| 223 | if (delay < 2000) { |
| 224 | pr_err("%s: %s: less than 2 sec delay is unsupported\n", |
| 225 | mmc_hostname(card->host), __func__); |
| 226 | return -EINVAL; |
| 227 | } |
| 228 | card->idle_timeout = delay; |
| 229 | } |
| 230 | |
| 231 | return count; |
| 232 | } |
| 233 | |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 234 | static struct bus_type mmc_bus_type = { |
| 235 | .name = "mmc", |
| 236 | .dev_attrs = mmc_dev_attrs, |
| 237 | .match = mmc_bus_match, |
| 238 | .uevent = mmc_bus_uevent, |
| 239 | .probe = mmc_bus_probe, |
| 240 | .remove = mmc_bus_remove, |
Chuanxiao Dong | 32d317c | 2012-04-11 19:54:38 +0800 | [diff] [blame] | 241 | .pm = &mmc_bus_pm_ops, |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 242 | }; |
| 243 | |
| 244 | int mmc_register_bus(void) |
| 245 | { |
| 246 | return bus_register(&mmc_bus_type); |
| 247 | } |
| 248 | |
| 249 | void mmc_unregister_bus(void) |
| 250 | { |
| 251 | bus_unregister(&mmc_bus_type); |
| 252 | } |
| 253 | |
| 254 | /** |
| 255 | * mmc_register_driver - register a media driver |
| 256 | * @drv: MMC media driver |
| 257 | */ |
| 258 | int mmc_register_driver(struct mmc_driver *drv) |
| 259 | { |
| 260 | drv->drv.bus = &mmc_bus_type; |
| 261 | return driver_register(&drv->drv); |
| 262 | } |
| 263 | |
| 264 | EXPORT_SYMBOL(mmc_register_driver); |
| 265 | |
| 266 | /** |
| 267 | * mmc_unregister_driver - unregister a media driver |
| 268 | * @drv: MMC media driver |
| 269 | */ |
| 270 | void mmc_unregister_driver(struct mmc_driver *drv) |
| 271 | { |
| 272 | drv->drv.bus = &mmc_bus_type; |
| 273 | driver_unregister(&drv->drv); |
| 274 | } |
| 275 | |
| 276 | EXPORT_SYMBOL(mmc_unregister_driver); |
| 277 | |
| 278 | static void mmc_release_card(struct device *dev) |
| 279 | { |
Andy Shevchenko | 265cdc9 | 2010-09-17 20:32:25 -0400 | [diff] [blame] | 280 | struct mmc_card *card = mmc_dev_to_card(dev); |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 281 | |
Pierre Ossman | 1a632f8 | 2007-07-30 15:15:30 +0200 | [diff] [blame] | 282 | sdio_free_common_cis(card); |
| 283 | |
Pierre Ossman | 759bdc7 | 2007-09-19 18:42:16 +0200 | [diff] [blame] | 284 | if (card->info) |
| 285 | kfree(card->info); |
| 286 | |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 287 | kfree(card); |
| 288 | } |
| 289 | |
| 290 | /* |
| 291 | * Allocate and initialise a new MMC card structure. |
| 292 | */ |
Pierre Ossman | 51ec92e | 2008-03-21 23:54:50 +0100 | [diff] [blame] | 293 | 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] | 294 | { |
| 295 | struct mmc_card *card; |
| 296 | |
Mariusz Kozlowski | 733cb1e | 2007-08-10 14:00:47 -0700 | [diff] [blame] | 297 | card = kzalloc(sizeof(struct mmc_card), GFP_KERNEL); |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 298 | if (!card) |
| 299 | return ERR_PTR(-ENOMEM); |
| 300 | |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 301 | card->host = host; |
| 302 | |
| 303 | device_initialize(&card->dev); |
| 304 | |
| 305 | card->dev.parent = mmc_classdev(host); |
| 306 | card->dev.bus = &mmc_bus_type; |
| 307 | card->dev.release = mmc_release_card; |
Pierre Ossman | 51ec92e | 2008-03-21 23:54:50 +0100 | [diff] [blame] | 308 | card->dev.type = type; |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 309 | |
Yaniv Gardi | 4c4383f | 2012-10-11 18:29:28 +0200 | [diff] [blame] | 310 | spin_lock_init(&card->bkops_info.bkops_stats.lock); |
Tatyana Brokhman | 464fbe1 | 2012-10-07 10:33:13 +0200 | [diff] [blame] | 311 | spin_lock_init(&card->wr_pack_stats.lock); |
| 312 | |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 313 | return card; |
| 314 | } |
| 315 | |
| 316 | /* |
| 317 | * Register a new MMC card with the driver model. |
| 318 | */ |
| 319 | int mmc_add_card(struct mmc_card *card) |
| 320 | { |
| 321 | int ret; |
Pierre Ossman | 109b5be | 2007-07-23 00:12:10 +0200 | [diff] [blame] | 322 | const char *type; |
Subhash Jadavani | 6500c8e | 2012-03-30 12:10:18 +0530 | [diff] [blame] | 323 | const char *uhs_bus_speed_mode = ""; |
| 324 | static const char *const uhs_speeds[] = { |
| 325 | [UHS_SDR12_BUS_SPEED] = "SDR12 ", |
| 326 | [UHS_SDR25_BUS_SPEED] = "SDR25 ", |
| 327 | [UHS_SDR50_BUS_SPEED] = "SDR50 ", |
| 328 | [UHS_SDR104_BUS_SPEED] = "SDR104 ", |
| 329 | [UHS_DDR50_BUS_SPEED] = "DDR50 ", |
| 330 | }; |
| 331 | |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 332 | |
Kay Sievers | d1b2686 | 2008-11-08 21:37:46 +0100 | [diff] [blame] | 333 | 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] | 334 | |
Pierre Ossman | 109b5be | 2007-07-23 00:12:10 +0200 | [diff] [blame] | 335 | switch (card->type) { |
| 336 | case MMC_TYPE_MMC: |
| 337 | type = "MMC"; |
| 338 | break; |
| 339 | case MMC_TYPE_SD: |
| 340 | type = "SD"; |
Arindam Nath | 3a30351 | 2011-05-05 12:19:03 +0530 | [diff] [blame] | 341 | if (mmc_card_blockaddr(card)) { |
| 342 | if (mmc_card_ext_capacity(card)) |
| 343 | type = "SDXC"; |
| 344 | else |
| 345 | type = "SDHC"; |
| 346 | } |
Pierre Ossman | 109b5be | 2007-07-23 00:12:10 +0200 | [diff] [blame] | 347 | break; |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 348 | case MMC_TYPE_SDIO: |
| 349 | type = "SDIO"; |
| 350 | break; |
Michal Miroslaw | 7310ece | 2010-08-10 18:01:40 -0700 | [diff] [blame] | 351 | case MMC_TYPE_SD_COMBO: |
| 352 | type = "SD-combo"; |
| 353 | if (mmc_card_blockaddr(card)) |
| 354 | type = "SDHC-combo"; |
Michał Mirosław | 9bc2184 | 2011-04-09 08:16:47 +0200 | [diff] [blame] | 355 | break; |
Pierre Ossman | 109b5be | 2007-07-23 00:12:10 +0200 | [diff] [blame] | 356 | default: |
| 357 | type = "?"; |
| 358 | break; |
| 359 | } |
| 360 | |
Subhash Jadavani | 6500c8e | 2012-03-30 12:10:18 +0530 | [diff] [blame] | 361 | if (mmc_sd_card_uhs(card) && |
| 362 | (card->sd_bus_speed < ARRAY_SIZE(uhs_speeds))) |
| 363 | uhs_bus_speed_mode = uhs_speeds[card->sd_bus_speed]; |
| 364 | |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 365 | if (mmc_host_is_spi(card->host)) { |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 366 | pr_info("%s: new %s%s%s card on SPI\n", |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 367 | mmc_hostname(card->host), |
| 368 | mmc_card_highspeed(card) ? "high speed " : "", |
Adrian Hunter | 0f8d8ea | 2010-08-24 13:20:26 +0300 | [diff] [blame] | 369 | mmc_card_ddr_mode(card) ? "DDR " : "", |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 370 | type); |
| 371 | } else { |
Subhash Jadavani | 6500c8e | 2012-03-30 12:10:18 +0530 | [diff] [blame] | 372 | pr_info("%s: new %s%s%s%s%s card at address %04x\n", |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 373 | mmc_hostname(card->host), |
Philip Rakity | a303c53 | 2011-11-14 19:14:38 -0800 | [diff] [blame] | 374 | mmc_card_uhs(card) ? "ultra high speed " : |
Arindam Nath | 3a30351 | 2011-05-05 12:19:03 +0530 | [diff] [blame] | 375 | (mmc_card_highspeed(card) ? "high speed " : ""), |
Girish K S | a4924c7 | 2012-01-11 14:04:52 -0500 | [diff] [blame] | 376 | (mmc_card_hs200(card) ? "HS200 " : ""), |
Adrian Hunter | 0f8d8ea | 2010-08-24 13:20:26 +0300 | [diff] [blame] | 377 | mmc_card_ddr_mode(card) ? "DDR " : "", |
Subhash Jadavani | 6500c8e | 2012-03-30 12:10:18 +0530 | [diff] [blame] | 378 | uhs_bus_speed_mode, type, card->rca); |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 379 | } |
Pierre Ossman | 109b5be | 2007-07-23 00:12:10 +0200 | [diff] [blame] | 380 | |
Haavard Skinnemoen | f4b7f92 | 2008-07-24 14:18:58 +0200 | [diff] [blame] | 381 | #ifdef CONFIG_DEBUG_FS |
| 382 | mmc_add_card_debugfs(card); |
| 383 | #endif |
Konstantin Dorfman | 69bd0fb | 2012-12-12 16:12:08 +0200 | [diff] [blame] | 384 | mmc_init_context_info(card->host); |
Haavard Skinnemoen | f4b7f92 | 2008-07-24 14:18:58 +0200 | [diff] [blame] | 385 | |
Asutosh Das | bbc8478 | 2013-02-11 15:31:35 +0530 | [diff] [blame] | 386 | if (mmc_use_core_runtime_pm(card->host)) { |
| 387 | ret = pm_runtime_set_active(&card->dev); |
| 388 | if (ret) |
| 389 | pr_err("%s: %s: failed setting runtime active: ret: %d\n", |
| 390 | mmc_hostname(card->host), __func__, ret); |
| 391 | else |
| 392 | pm_runtime_enable(&card->dev); |
| 393 | } |
| 394 | |
Viresh Kumar | 1a2727e | 2011-01-04 12:55:14 -0500 | [diff] [blame] | 395 | ret = device_add(&card->dev); |
| 396 | if (ret) |
| 397 | return ret; |
| 398 | |
Asutosh Das | bbc8478 | 2013-02-11 15:31:35 +0530 | [diff] [blame] | 399 | if (mmc_use_core_runtime_pm(card->host)) { |
| 400 | card->rpm_attrib.show = show_rpm_delay; |
| 401 | card->rpm_attrib.store = store_rpm_delay; |
| 402 | sysfs_attr_init(&card->rpm_attrib.attr); |
| 403 | card->rpm_attrib.attr.name = "runtime_pm_timeout"; |
| 404 | card->rpm_attrib.attr.mode = S_IRUGO | S_IWUSR; |
| 405 | |
| 406 | ret = device_create_file(&card->dev, &card->rpm_attrib); |
| 407 | if (ret) |
| 408 | pr_err("%s: %s: creating runtime pm sysfs entry: failed: %d\n", |
| 409 | mmc_hostname(card->host), __func__, ret); |
| 410 | /* Default timeout is 10 seconds */ |
| 411 | card->idle_timeout = RUNTIME_SUSPEND_DELAY_MS; |
| 412 | } |
| 413 | |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 414 | mmc_card_set_present(card); |
| 415 | |
| 416 | return 0; |
| 417 | } |
| 418 | |
| 419 | /* |
| 420 | * Unregister a new MMC card with the driver model, and |
| 421 | * (eventually) free it. |
| 422 | */ |
| 423 | void mmc_remove_card(struct mmc_card *card) |
| 424 | { |
Haavard Skinnemoen | f4b7f92 | 2008-07-24 14:18:58 +0200 | [diff] [blame] | 425 | #ifdef CONFIG_DEBUG_FS |
| 426 | mmc_remove_card_debugfs(card); |
| 427 | #endif |
| 428 | |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 429 | if (mmc_card_present(card)) { |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 430 | if (mmc_host_is_spi(card->host)) { |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 431 | pr_info("%s: SPI card removed\n", |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 432 | mmc_hostname(card->host)); |
| 433 | } else { |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 434 | pr_info("%s: card %04x removed\n", |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 435 | mmc_hostname(card->host), card->rca); |
| 436 | } |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 437 | device_del(&card->dev); |
| 438 | } |
| 439 | |
Tatyana Brokhman | 464fbe1 | 2012-10-07 10:33:13 +0200 | [diff] [blame] | 440 | kfree(card->wr_pack_stats.packing_events); |
| 441 | |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 442 | put_device(&card->dev); |
| 443 | } |
| 444 | |