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) |
| 29 | |
| 30 | static ssize_t mmc_type_show(struct device *dev, |
| 31 | struct device_attribute *attr, char *buf) |
| 32 | { |
Andy Shevchenko | 265cdc9 | 2010-09-17 20:32:25 -0400 | [diff] [blame] | 33 | struct mmc_card *card = mmc_dev_to_card(dev); |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 34 | |
| 35 | switch (card->type) { |
| 36 | case MMC_TYPE_MMC: |
| 37 | return sprintf(buf, "MMC\n"); |
| 38 | case MMC_TYPE_SD: |
| 39 | return sprintf(buf, "SD\n"); |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 40 | case MMC_TYPE_SDIO: |
| 41 | return sprintf(buf, "SDIO\n"); |
Michal Miroslaw | 7310ece8 | 2010-08-10 18:01:40 -0700 | [diff] [blame] | 42 | case MMC_TYPE_SD_COMBO: |
| 43 | return sprintf(buf, "SDcombo\n"); |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 44 | default: |
| 45 | return -EFAULT; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | static struct device_attribute mmc_dev_attrs[] = { |
Pierre Ossman | 51ec92e | 2008-03-21 23:54:50 +0100 | [diff] [blame] | 50 | __ATTR(type, S_IRUGO, mmc_type_show, NULL), |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 51 | __ATTR_NULL, |
| 52 | }; |
| 53 | |
| 54 | /* |
| 55 | * This currently matches any MMC driver to any MMC card - drivers |
| 56 | * themselves make the decision whether to drive this card in their |
| 57 | * probe method. |
| 58 | */ |
| 59 | static int mmc_bus_match(struct device *dev, struct device_driver *drv) |
| 60 | { |
| 61 | return 1; |
| 62 | } |
| 63 | |
| 64 | static int |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 65 | mmc_bus_uevent(struct device *dev, struct kobj_uevent_env *env) |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 66 | { |
Andy Shevchenko | 265cdc9 | 2010-09-17 20:32:25 -0400 | [diff] [blame] | 67 | struct mmc_card *card = mmc_dev_to_card(dev); |
Pierre Ossman | 9eb3a94 | 2007-06-17 11:18:46 +0200 | [diff] [blame] | 68 | const char *type; |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 69 | int retval = 0; |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 70 | |
| 71 | switch (card->type) { |
| 72 | case MMC_TYPE_MMC: |
Pierre Ossman | 9eb3a94 | 2007-06-17 11:18:46 +0200 | [diff] [blame] | 73 | type = "MMC"; |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 74 | break; |
| 75 | case MMC_TYPE_SD: |
Pierre Ossman | 9eb3a94 | 2007-06-17 11:18:46 +0200 | [diff] [blame] | 76 | type = "SD"; |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 77 | break; |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 78 | case MMC_TYPE_SDIO: |
Pierre Ossman | 9eb3a94 | 2007-06-17 11:18:46 +0200 | [diff] [blame] | 79 | type = "SDIO"; |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 80 | break; |
Michal Miroslaw | 7310ece8 | 2010-08-10 18:01:40 -0700 | [diff] [blame] | 81 | case MMC_TYPE_SD_COMBO: |
| 82 | type = "SDcombo"; |
| 83 | break; |
Pierre Ossman | 9eb3a94 | 2007-06-17 11:18:46 +0200 | [diff] [blame] | 84 | default: |
| 85 | type = NULL; |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 86 | } |
| 87 | |
Pierre Ossman | 9eb3a94 | 2007-06-17 11:18:46 +0200 | [diff] [blame] | 88 | if (type) { |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 89 | retval = add_uevent_var(env, "MMC_TYPE=%s", type); |
| 90 | if (retval) |
| 91 | return retval; |
Pierre Ossman | 9eb3a94 | 2007-06-17 11:18:46 +0200 | [diff] [blame] | 92 | } |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 93 | |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 94 | retval = add_uevent_var(env, "MMC_NAME=%s", mmc_card_name(card)); |
Andy Whitcroft | 6b0b628 | 2009-02-23 12:38:41 +0000 | [diff] [blame] | 95 | if (retval) |
| 96 | return retval; |
| 97 | |
| 98 | /* |
| 99 | * Request the mmc_block device. Note: that this is a direct request |
| 100 | * for the module it carries no information as to what is inserted. |
| 101 | */ |
| 102 | retval = add_uevent_var(env, "MODALIAS=mmc:block"); |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 103 | |
Kay Sievers | 7eff2e7 | 2007-08-14 15:15:12 +0200 | [diff] [blame] | 104 | return retval; |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | static int mmc_bus_probe(struct device *dev) |
| 108 | { |
| 109 | struct mmc_driver *drv = to_mmc_driver(dev->driver); |
Andy Shevchenko | 265cdc9 | 2010-09-17 20:32:25 -0400 | [diff] [blame] | 110 | struct mmc_card *card = mmc_dev_to_card(dev); |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 111 | |
| 112 | return drv->probe(card); |
| 113 | } |
| 114 | |
| 115 | static int mmc_bus_remove(struct device *dev) |
| 116 | { |
| 117 | struct mmc_driver *drv = to_mmc_driver(dev->driver); |
Andy Shevchenko | 265cdc9 | 2010-09-17 20:32:25 -0400 | [diff] [blame] | 118 | struct mmc_card *card = mmc_dev_to_card(dev); |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 119 | |
| 120 | drv->remove(card); |
| 121 | |
| 122 | return 0; |
| 123 | } |
| 124 | |
Ulf Hansson | 7628774 | 2013-06-10 17:03:40 +0200 | [diff] [blame] | 125 | static void mmc_bus_shutdown(struct device *dev) |
| 126 | { |
| 127 | struct mmc_driver *drv = to_mmc_driver(dev->driver); |
| 128 | struct mmc_card *card = mmc_dev_to_card(dev); |
Ulf Hansson | 6b086bd | 2013-06-10 17:03:41 +0200 | [diff] [blame] | 129 | struct mmc_host *host = card->host; |
| 130 | int ret; |
Ulf Hansson | 7628774 | 2013-06-10 17:03:40 +0200 | [diff] [blame] | 131 | |
Ulf Hansson | 203bb5a | 2013-07-02 12:53:01 +0200 | [diff] [blame] | 132 | if (dev->driver && drv->shutdown) |
| 133 | drv->shutdown(card); |
Ulf Hansson | 6b086bd | 2013-06-10 17:03:41 +0200 | [diff] [blame] | 134 | |
| 135 | if (host->bus_ops->shutdown) { |
| 136 | ret = host->bus_ops->shutdown(host); |
| 137 | if (ret) |
| 138 | pr_warn("%s: error %d during shutdown\n", |
| 139 | mmc_hostname(host), ret); |
| 140 | } |
Ulf Hansson | 7628774 | 2013-06-10 17:03:40 +0200 | [diff] [blame] | 141 | } |
| 142 | |
Chuanxiao Dong | 0dd1bfe | 2012-04-23 15:18:02 +0800 | [diff] [blame] | 143 | #ifdef CONFIG_PM_SLEEP |
Chuanxiao Dong | 32d317c | 2012-04-11 19:54:38 +0800 | [diff] [blame] | 144 | static int mmc_bus_suspend(struct device *dev) |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 145 | { |
| 146 | struct mmc_driver *drv = to_mmc_driver(dev->driver); |
Andy Shevchenko | 265cdc9 | 2010-09-17 20:32:25 -0400 | [diff] [blame] | 147 | struct mmc_card *card = mmc_dev_to_card(dev); |
Ulf Hansson | 986892c | 2013-06-10 17:03:39 +0200 | [diff] [blame] | 148 | struct mmc_host *host = card->host; |
| 149 | int ret; |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 150 | |
Ulf Hansson | 986892c | 2013-06-10 17:03:39 +0200 | [diff] [blame] | 151 | if (dev->driver && drv->suspend) { |
Chuanxiao Dong | 32d317c | 2012-04-11 19:54:38 +0800 | [diff] [blame] | 152 | ret = drv->suspend(card); |
Ulf Hansson | 986892c | 2013-06-10 17:03:39 +0200 | [diff] [blame] | 153 | if (ret) |
| 154 | return ret; |
| 155 | } |
| 156 | |
| 157 | ret = host->bus_ops->suspend(host); |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 158 | return ret; |
| 159 | } |
| 160 | |
| 161 | static int mmc_bus_resume(struct device *dev) |
| 162 | { |
| 163 | struct mmc_driver *drv = to_mmc_driver(dev->driver); |
Andy Shevchenko | 265cdc9 | 2010-09-17 20:32:25 -0400 | [diff] [blame] | 164 | struct mmc_card *card = mmc_dev_to_card(dev); |
Ulf Hansson | 986892c | 2013-06-10 17:03:39 +0200 | [diff] [blame] | 165 | struct mmc_host *host = card->host; |
| 166 | int ret; |
| 167 | |
| 168 | ret = host->bus_ops->resume(host); |
| 169 | if (ret) |
| 170 | pr_warn("%s: error %d during resume (card was removed?)\n", |
| 171 | mmc_hostname(host), ret); |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 172 | |
| 173 | if (dev->driver && drv->resume) |
| 174 | ret = drv->resume(card); |
Ulf Hansson | 986892c | 2013-06-10 17:03:39 +0200 | [diff] [blame] | 175 | |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 176 | return ret; |
| 177 | } |
Chuanxiao Dong | 0dd1bfe | 2012-04-23 15:18:02 +0800 | [diff] [blame] | 178 | #endif |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 179 | |
Ohad Ben-Cohen | 516d5cc | 2010-10-02 13:54:08 +0200 | [diff] [blame] | 180 | #ifdef CONFIG_PM_RUNTIME |
| 181 | |
| 182 | static int mmc_runtime_suspend(struct device *dev) |
| 183 | { |
| 184 | struct mmc_card *card = mmc_dev_to_card(dev); |
Ulf Hansson | 12d01d0 | 2013-05-02 14:02:37 +0200 | [diff] [blame] | 185 | struct mmc_host *host = card->host; |
| 186 | int ret = 0; |
Ohad Ben-Cohen | 516d5cc | 2010-10-02 13:54:08 +0200 | [diff] [blame] | 187 | |
Ulf Hansson | 12d01d0 | 2013-05-02 14:02:37 +0200 | [diff] [blame] | 188 | if (host->bus_ops->runtime_suspend) |
| 189 | ret = host->bus_ops->runtime_suspend(host); |
| 190 | |
| 191 | return ret; |
Ohad Ben-Cohen | 516d5cc | 2010-10-02 13:54:08 +0200 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | static int mmc_runtime_resume(struct device *dev) |
| 195 | { |
| 196 | struct mmc_card *card = mmc_dev_to_card(dev); |
Ulf Hansson | 12d01d0 | 2013-05-02 14:02:37 +0200 | [diff] [blame] | 197 | struct mmc_host *host = card->host; |
| 198 | int ret = 0; |
Ohad Ben-Cohen | 516d5cc | 2010-10-02 13:54:08 +0200 | [diff] [blame] | 199 | |
Ulf Hansson | 12d01d0 | 2013-05-02 14:02:37 +0200 | [diff] [blame] | 200 | if (host->bus_ops->runtime_resume) |
| 201 | ret = host->bus_ops->runtime_resume(host); |
| 202 | |
| 203 | return ret; |
Ohad Ben-Cohen | 516d5cc | 2010-10-02 13:54:08 +0200 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | static int mmc_runtime_idle(struct device *dev) |
| 207 | { |
Rafael J. Wysocki | 45f0a85 | 2013-06-03 21:49:52 +0200 | [diff] [blame] | 208 | return 0; |
Ohad Ben-Cohen | 516d5cc | 2010-10-02 13:54:08 +0200 | [diff] [blame] | 209 | } |
| 210 | |
Ohad Ben-Cohen | 516d5cc | 2010-10-02 13:54:08 +0200 | [diff] [blame] | 211 | #endif /* !CONFIG_PM_RUNTIME */ |
| 212 | |
Chuanxiao Dong | 32d317c | 2012-04-11 19:54:38 +0800 | [diff] [blame] | 213 | static const struct dev_pm_ops mmc_bus_pm_ops = { |
| 214 | SET_RUNTIME_PM_OPS(mmc_runtime_suspend, mmc_runtime_resume, |
| 215 | mmc_runtime_idle) |
| 216 | SET_SYSTEM_SLEEP_PM_OPS(mmc_bus_suspend, mmc_bus_resume) |
| 217 | }; |
| 218 | |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 219 | static struct bus_type mmc_bus_type = { |
| 220 | .name = "mmc", |
| 221 | .dev_attrs = mmc_dev_attrs, |
| 222 | .match = mmc_bus_match, |
| 223 | .uevent = mmc_bus_uevent, |
| 224 | .probe = mmc_bus_probe, |
| 225 | .remove = mmc_bus_remove, |
Ulf Hansson | 7628774 | 2013-06-10 17:03:40 +0200 | [diff] [blame] | 226 | .shutdown = mmc_bus_shutdown, |
Chuanxiao Dong | 32d317c | 2012-04-11 19:54:38 +0800 | [diff] [blame] | 227 | .pm = &mmc_bus_pm_ops, |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 228 | }; |
| 229 | |
| 230 | int mmc_register_bus(void) |
| 231 | { |
| 232 | return bus_register(&mmc_bus_type); |
| 233 | } |
| 234 | |
| 235 | void mmc_unregister_bus(void) |
| 236 | { |
| 237 | bus_unregister(&mmc_bus_type); |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * mmc_register_driver - register a media driver |
| 242 | * @drv: MMC media driver |
| 243 | */ |
| 244 | int mmc_register_driver(struct mmc_driver *drv) |
| 245 | { |
| 246 | drv->drv.bus = &mmc_bus_type; |
| 247 | return driver_register(&drv->drv); |
| 248 | } |
| 249 | |
| 250 | EXPORT_SYMBOL(mmc_register_driver); |
| 251 | |
| 252 | /** |
| 253 | * mmc_unregister_driver - unregister a media driver |
| 254 | * @drv: MMC media driver |
| 255 | */ |
| 256 | void mmc_unregister_driver(struct mmc_driver *drv) |
| 257 | { |
| 258 | drv->drv.bus = &mmc_bus_type; |
| 259 | driver_unregister(&drv->drv); |
| 260 | } |
| 261 | |
| 262 | EXPORT_SYMBOL(mmc_unregister_driver); |
| 263 | |
| 264 | static void mmc_release_card(struct device *dev) |
| 265 | { |
Andy Shevchenko | 265cdc9 | 2010-09-17 20:32:25 -0400 | [diff] [blame] | 266 | struct mmc_card *card = mmc_dev_to_card(dev); |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 267 | |
Pierre Ossman | 1a632f8 | 2007-07-30 15:15:30 +0200 | [diff] [blame] | 268 | sdio_free_common_cis(card); |
| 269 | |
Sachin Kamat | 8db580c | 2012-11-20 14:43:17 +0530 | [diff] [blame] | 270 | kfree(card->info); |
Pierre Ossman | 759bdc7 | 2007-09-19 18:42:16 +0200 | [diff] [blame] | 271 | |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 272 | kfree(card); |
| 273 | } |
| 274 | |
| 275 | /* |
| 276 | * Allocate and initialise a new MMC card structure. |
| 277 | */ |
Pierre Ossman | 51ec92e | 2008-03-21 23:54:50 +0100 | [diff] [blame] | 278 | 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] | 279 | { |
| 280 | struct mmc_card *card; |
| 281 | |
Mariusz Kozlowski | 733cb1e | 2007-08-10 14:00:47 -0700 | [diff] [blame] | 282 | card = kzalloc(sizeof(struct mmc_card), GFP_KERNEL); |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 283 | if (!card) |
| 284 | return ERR_PTR(-ENOMEM); |
| 285 | |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 286 | card->host = host; |
| 287 | |
| 288 | device_initialize(&card->dev); |
| 289 | |
| 290 | card->dev.parent = mmc_classdev(host); |
| 291 | card->dev.bus = &mmc_bus_type; |
| 292 | card->dev.release = mmc_release_card; |
Pierre Ossman | 51ec92e | 2008-03-21 23:54:50 +0100 | [diff] [blame] | 293 | card->dev.type = type; |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 294 | |
| 295 | return card; |
| 296 | } |
| 297 | |
| 298 | /* |
| 299 | * Register a new MMC card with the driver model. |
| 300 | */ |
| 301 | int mmc_add_card(struct mmc_card *card) |
| 302 | { |
| 303 | int ret; |
Pierre Ossman | 109b5be | 2007-07-23 00:12:10 +0200 | [diff] [blame] | 304 | const char *type; |
Subhash Jadavani | 6500c8e | 2012-03-30 12:10:18 +0530 | [diff] [blame] | 305 | const char *uhs_bus_speed_mode = ""; |
| 306 | static const char *const uhs_speeds[] = { |
| 307 | [UHS_SDR12_BUS_SPEED] = "SDR12 ", |
| 308 | [UHS_SDR25_BUS_SPEED] = "SDR25 ", |
| 309 | [UHS_SDR50_BUS_SPEED] = "SDR50 ", |
| 310 | [UHS_SDR104_BUS_SPEED] = "SDR104 ", |
| 311 | [UHS_DDR50_BUS_SPEED] = "DDR50 ", |
| 312 | }; |
| 313 | |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 314 | |
Kay Sievers | d1b2686 | 2008-11-08 21:37:46 +0100 | [diff] [blame] | 315 | 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] | 316 | |
Pierre Ossman | 109b5be | 2007-07-23 00:12:10 +0200 | [diff] [blame] | 317 | switch (card->type) { |
| 318 | case MMC_TYPE_MMC: |
| 319 | type = "MMC"; |
| 320 | break; |
| 321 | case MMC_TYPE_SD: |
| 322 | type = "SD"; |
Arindam Nath | 3a30351 | 2011-05-05 12:19:03 +0530 | [diff] [blame] | 323 | if (mmc_card_blockaddr(card)) { |
| 324 | if (mmc_card_ext_capacity(card)) |
| 325 | type = "SDXC"; |
| 326 | else |
| 327 | type = "SDHC"; |
| 328 | } |
Pierre Ossman | 109b5be | 2007-07-23 00:12:10 +0200 | [diff] [blame] | 329 | break; |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 330 | case MMC_TYPE_SDIO: |
| 331 | type = "SDIO"; |
| 332 | break; |
Michal Miroslaw | 7310ece8 | 2010-08-10 18:01:40 -0700 | [diff] [blame] | 333 | case MMC_TYPE_SD_COMBO: |
| 334 | type = "SD-combo"; |
| 335 | if (mmc_card_blockaddr(card)) |
| 336 | type = "SDHC-combo"; |
Michał Mirosław | 9bc2184 | 2011-04-09 08:16:47 +0200 | [diff] [blame] | 337 | break; |
Pierre Ossman | 109b5be | 2007-07-23 00:12:10 +0200 | [diff] [blame] | 338 | default: |
| 339 | type = "?"; |
| 340 | break; |
| 341 | } |
| 342 | |
Subhash Jadavani | 6500c8e | 2012-03-30 12:10:18 +0530 | [diff] [blame] | 343 | if (mmc_sd_card_uhs(card) && |
| 344 | (card->sd_bus_speed < ARRAY_SIZE(uhs_speeds))) |
| 345 | uhs_bus_speed_mode = uhs_speeds[card->sd_bus_speed]; |
| 346 | |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 347 | if (mmc_host_is_spi(card->host)) { |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 348 | pr_info("%s: new %s%s%s card on SPI\n", |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 349 | mmc_hostname(card->host), |
| 350 | mmc_card_highspeed(card) ? "high speed " : "", |
Adrian Hunter | 0f8d8ea | 2010-08-24 13:20:26 +0300 | [diff] [blame] | 351 | mmc_card_ddr_mode(card) ? "DDR " : "", |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 352 | type); |
| 353 | } else { |
Subhash Jadavani | 6500c8e | 2012-03-30 12:10:18 +0530 | [diff] [blame] | 354 | 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] | 355 | mmc_hostname(card->host), |
Philip Rakity | a303c53 | 2011-11-14 19:14:38 -0800 | [diff] [blame] | 356 | mmc_card_uhs(card) ? "ultra high speed " : |
Arindam Nath | 3a30351 | 2011-05-05 12:19:03 +0530 | [diff] [blame] | 357 | (mmc_card_highspeed(card) ? "high speed " : ""), |
Girish K S | a4924c7 | 2012-01-11 14:04:52 -0500 | [diff] [blame] | 358 | (mmc_card_hs200(card) ? "HS200 " : ""), |
Adrian Hunter | 0f8d8ea | 2010-08-24 13:20:26 +0300 | [diff] [blame] | 359 | mmc_card_ddr_mode(card) ? "DDR " : "", |
Subhash Jadavani | 6500c8e | 2012-03-30 12:10:18 +0530 | [diff] [blame] | 360 | uhs_bus_speed_mode, type, card->rca); |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 361 | } |
Pierre Ossman | 109b5be | 2007-07-23 00:12:10 +0200 | [diff] [blame] | 362 | |
Haavard Skinnemoen | f4b7f92 | 2008-07-24 14:18:58 +0200 | [diff] [blame] | 363 | #ifdef CONFIG_DEBUG_FS |
| 364 | mmc_add_card_debugfs(card); |
| 365 | #endif |
Konstantin Dorfman | 2220eed | 2013-01-14 14:28:17 -0500 | [diff] [blame] | 366 | mmc_init_context_info(card->host); |
Haavard Skinnemoen | f4b7f92 | 2008-07-24 14:18:58 +0200 | [diff] [blame] | 367 | |
Viresh Kumar | 1a2727e | 2011-01-04 12:55:14 -0500 | [diff] [blame] | 368 | ret = device_add(&card->dev); |
| 369 | if (ret) |
| 370 | return ret; |
| 371 | |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 372 | mmc_card_set_present(card); |
| 373 | |
| 374 | return 0; |
| 375 | } |
| 376 | |
| 377 | /* |
| 378 | * Unregister a new MMC card with the driver model, and |
| 379 | * (eventually) free it. |
| 380 | */ |
| 381 | void mmc_remove_card(struct mmc_card *card) |
| 382 | { |
Haavard Skinnemoen | f4b7f92 | 2008-07-24 14:18:58 +0200 | [diff] [blame] | 383 | #ifdef CONFIG_DEBUG_FS |
| 384 | mmc_remove_card_debugfs(card); |
| 385 | #endif |
| 386 | |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 387 | if (mmc_card_present(card)) { |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 388 | if (mmc_host_is_spi(card->host)) { |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 389 | pr_info("%s: SPI card removed\n", |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 390 | mmc_hostname(card->host)); |
| 391 | } else { |
Girish K S | a3c76eb | 2011-10-11 11:44:09 +0530 | [diff] [blame] | 392 | pr_info("%s: card %04x removed\n", |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 393 | mmc_hostname(card->host), card->rca); |
| 394 | } |
Pierre Ossman | 4101c16 | 2007-05-19 13:39:01 +0200 | [diff] [blame] | 395 | device_del(&card->dev); |
| 396 | } |
| 397 | |
| 398 | put_device(&card->dev); |
| 399 | } |
| 400 | |