Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 1 | /* |
| 2 | * linux/drivers/mmc/sdio.c |
| 3 | * |
| 4 | * Copyright 2006-2007 Pierre Ossman |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or (at |
| 9 | * your option) any later version. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/err.h> |
Ohad Ben-Cohen | 81968561 | 2010-10-02 13:54:10 +0200 | [diff] [blame] | 13 | #include <linux/pm_runtime.h> |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 14 | |
| 15 | #include <linux/mmc/host.h> |
| 16 | #include <linux/mmc/card.h> |
Pierre Ossman | 35c66c1 | 2007-06-11 20:25:43 +0200 | [diff] [blame] | 17 | #include <linux/mmc/sdio.h> |
Pierre Ossman | e29a7d7 | 2007-05-26 13:48:18 +0200 | [diff] [blame] | 18 | #include <linux/mmc/sdio_func.h> |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 19 | |
| 20 | #include "core.h" |
| 21 | #include "bus.h" |
Michal Miroslaw | 71578a1 | 2010-08-10 18:01:40 -0700 | [diff] [blame] | 22 | #include "sd.h" |
Pierre Ossman | e29a7d7 | 2007-05-26 13:48:18 +0200 | [diff] [blame] | 23 | #include "sdio_bus.h" |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 24 | #include "mmc_ops.h" |
| 25 | #include "sd_ops.h" |
| 26 | #include "sdio_ops.h" |
Nicolas Pitre | b726126 | 2007-06-16 02:04:16 -0400 | [diff] [blame] | 27 | #include "sdio_cis.h" |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 28 | |
Pierre Ossman | 0597007 | 2007-06-11 21:01:00 +0200 | [diff] [blame] | 29 | static int sdio_read_fbr(struct sdio_func *func) |
| 30 | { |
| 31 | int ret; |
| 32 | unsigned char data; |
| 33 | |
| 34 | ret = mmc_io_rw_direct(func->card, 0, 0, |
David Vrabel | 7616ee9 | 2007-08-08 14:23:05 +0100 | [diff] [blame] | 35 | SDIO_FBR_BASE(func->num) + SDIO_FBR_STD_IF, 0, &data); |
Pierre Ossman | 0597007 | 2007-06-11 21:01:00 +0200 | [diff] [blame] | 36 | if (ret) |
| 37 | goto out; |
| 38 | |
| 39 | data &= 0x0f; |
| 40 | |
| 41 | if (data == 0x0f) { |
| 42 | ret = mmc_io_rw_direct(func->card, 0, 0, |
David Vrabel | 7616ee9 | 2007-08-08 14:23:05 +0100 | [diff] [blame] | 43 | SDIO_FBR_BASE(func->num) + SDIO_FBR_STD_IF_EXT, 0, &data); |
Pierre Ossman | 0597007 | 2007-06-11 21:01:00 +0200 | [diff] [blame] | 44 | if (ret) |
| 45 | goto out; |
| 46 | } |
| 47 | |
| 48 | func->class = data; |
| 49 | |
| 50 | out: |
| 51 | return ret; |
| 52 | } |
| 53 | |
Pierre Ossman | e29a7d7 | 2007-05-26 13:48:18 +0200 | [diff] [blame] | 54 | static int sdio_init_func(struct mmc_card *card, unsigned int fn) |
| 55 | { |
Pierre Ossman | 0597007 | 2007-06-11 21:01:00 +0200 | [diff] [blame] | 56 | int ret; |
Pierre Ossman | e29a7d7 | 2007-05-26 13:48:18 +0200 | [diff] [blame] | 57 | struct sdio_func *func; |
| 58 | |
| 59 | BUG_ON(fn > SDIO_MAX_FUNCS); |
| 60 | |
| 61 | func = sdio_alloc_func(card); |
| 62 | if (IS_ERR(func)) |
| 63 | return PTR_ERR(func); |
| 64 | |
| 65 | func->num = fn; |
| 66 | |
Grazvydas Ignotas | 6f51be3 | 2010-08-10 18:01:50 -0700 | [diff] [blame] | 67 | if (!(card->quirks & MMC_QUIRK_NONSTD_SDIO)) { |
| 68 | ret = sdio_read_fbr(func); |
| 69 | if (ret) |
| 70 | goto fail; |
Pierre Ossman | 0597007 | 2007-06-11 21:01:00 +0200 | [diff] [blame] | 71 | |
Grazvydas Ignotas | 6f51be3 | 2010-08-10 18:01:50 -0700 | [diff] [blame] | 72 | ret = sdio_read_func_cis(func); |
| 73 | if (ret) |
| 74 | goto fail; |
| 75 | } else { |
| 76 | func->vendor = func->card->cis.vendor; |
| 77 | func->device = func->card->cis.device; |
| 78 | func->max_blksize = func->card->cis.blksize; |
| 79 | } |
Nicolas Pitre | b726126 | 2007-06-16 02:04:16 -0400 | [diff] [blame] | 80 | |
Pierre Ossman | e29a7d7 | 2007-05-26 13:48:18 +0200 | [diff] [blame] | 81 | card->sdio_func[fn - 1] = func; |
| 82 | |
| 83 | return 0; |
Pierre Ossman | 0597007 | 2007-06-11 21:01:00 +0200 | [diff] [blame] | 84 | |
| 85 | fail: |
| 86 | /* |
| 87 | * It is okay to remove the function here even though we hold |
| 88 | * the host lock as we haven't registered the device yet. |
| 89 | */ |
| 90 | sdio_remove_func(func); |
| 91 | return ret; |
Pierre Ossman | e29a7d7 | 2007-05-26 13:48:18 +0200 | [diff] [blame] | 92 | } |
| 93 | |
Pierre Ossman | 35c66c1 | 2007-06-11 20:25:43 +0200 | [diff] [blame] | 94 | static int sdio_read_cccr(struct mmc_card *card) |
| 95 | { |
| 96 | int ret; |
| 97 | int cccr_vsn; |
| 98 | unsigned char data; |
| 99 | |
| 100 | memset(&card->cccr, 0, sizeof(struct sdio_cccr)); |
| 101 | |
| 102 | ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_CCCR, 0, &data); |
| 103 | if (ret) |
| 104 | goto out; |
| 105 | |
| 106 | cccr_vsn = data & 0x0f; |
| 107 | |
| 108 | if (cccr_vsn > SDIO_CCCR_REV_1_20) { |
| 109 | printk(KERN_ERR "%s: unrecognised CCCR structure version %d\n", |
| 110 | mmc_hostname(card->host), cccr_vsn); |
| 111 | return -EINVAL; |
| 112 | } |
| 113 | |
| 114 | card->cccr.sdio_vsn = (data & 0xf0) >> 4; |
| 115 | |
| 116 | ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_CAPS, 0, &data); |
| 117 | if (ret) |
| 118 | goto out; |
| 119 | |
| 120 | if (data & SDIO_CCCR_CAP_SMB) |
| 121 | card->cccr.multi_block = 1; |
| 122 | if (data & SDIO_CCCR_CAP_LSC) |
| 123 | card->cccr.low_speed = 1; |
| 124 | if (data & SDIO_CCCR_CAP_4BLS) |
| 125 | card->cccr.wide_bus = 1; |
| 126 | |
| 127 | if (cccr_vsn >= SDIO_CCCR_REV_1_10) { |
| 128 | ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_POWER, 0, &data); |
| 129 | if (ret) |
| 130 | goto out; |
| 131 | |
| 132 | if (data & SDIO_POWER_SMPC) |
| 133 | card->cccr.high_power = 1; |
| 134 | } |
| 135 | |
| 136 | if (cccr_vsn >= SDIO_CCCR_REV_1_20) { |
| 137 | ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_SPEED, 0, &data); |
| 138 | if (ret) |
| 139 | goto out; |
| 140 | |
| 141 | if (data & SDIO_SPEED_SHS) |
| 142 | card->cccr.high_speed = 1; |
| 143 | } |
| 144 | |
| 145 | out: |
| 146 | return ret; |
| 147 | } |
| 148 | |
Pierre Ossman | 4ff6471 | 2007-07-30 18:23:53 +0200 | [diff] [blame] | 149 | static int sdio_enable_wide(struct mmc_card *card) |
| 150 | { |
| 151 | int ret; |
| 152 | u8 ctrl; |
| 153 | |
| 154 | if (!(card->host->caps & MMC_CAP_4_BIT_DATA)) |
| 155 | return 0; |
| 156 | |
| 157 | if (card->cccr.low_speed && !card->cccr.wide_bus) |
| 158 | return 0; |
| 159 | |
| 160 | ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_IF, 0, &ctrl); |
| 161 | if (ret) |
| 162 | return ret; |
| 163 | |
| 164 | ctrl |= SDIO_BUS_WIDTH_4BIT; |
| 165 | |
| 166 | ret = mmc_io_rw_direct(card, 1, 0, SDIO_CCCR_IF, ctrl, NULL); |
| 167 | if (ret) |
| 168 | return ret; |
| 169 | |
Michal Miroslaw | 7310ece8 | 2010-08-10 18:01:40 -0700 | [diff] [blame] | 170 | return 1; |
Pierre Ossman | 4ff6471 | 2007-07-30 18:23:53 +0200 | [diff] [blame] | 171 | } |
| 172 | |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 173 | /* |
Ohad Ben-Cohen | 006ebd5 | 2009-09-22 16:45:07 -0700 | [diff] [blame] | 174 | * If desired, disconnect the pull-up resistor on CD/DAT[3] (pin 1) |
| 175 | * of the card. This may be required on certain setups of boards, |
| 176 | * controllers and embedded sdio device which do not need the card's |
| 177 | * pull-up. As a result, card detection is disabled and power is saved. |
| 178 | */ |
| 179 | static int sdio_disable_cd(struct mmc_card *card) |
| 180 | { |
| 181 | int ret; |
| 182 | u8 ctrl; |
| 183 | |
| 184 | if (!card->cccr.disable_cd) |
| 185 | return 0; |
| 186 | |
| 187 | ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_IF, 0, &ctrl); |
| 188 | if (ret) |
| 189 | return ret; |
| 190 | |
| 191 | ctrl |= SDIO_BUS_CD_DISABLE; |
| 192 | |
| 193 | return mmc_io_rw_direct(card, 1, 0, SDIO_CCCR_IF, ctrl, NULL); |
| 194 | } |
| 195 | |
| 196 | /* |
Daniel Drake | 6b5eda3 | 2010-03-05 13:43:34 -0800 | [diff] [blame] | 197 | * Devices that remain active during a system suspend are |
| 198 | * put back into 1-bit mode. |
| 199 | */ |
| 200 | static int sdio_disable_wide(struct mmc_card *card) |
| 201 | { |
| 202 | int ret; |
| 203 | u8 ctrl; |
| 204 | |
| 205 | if (!(card->host->caps & MMC_CAP_4_BIT_DATA)) |
| 206 | return 0; |
| 207 | |
| 208 | if (card->cccr.low_speed && !card->cccr.wide_bus) |
| 209 | return 0; |
| 210 | |
| 211 | ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_IF, 0, &ctrl); |
| 212 | if (ret) |
| 213 | return ret; |
| 214 | |
| 215 | if (!(ctrl & SDIO_BUS_WIDTH_4BIT)) |
| 216 | return 0; |
| 217 | |
| 218 | ctrl &= ~SDIO_BUS_WIDTH_4BIT; |
| 219 | ctrl |= SDIO_BUS_ASYNC_INT; |
| 220 | |
| 221 | ret = mmc_io_rw_direct(card, 1, 0, SDIO_CCCR_IF, ctrl, NULL); |
| 222 | if (ret) |
| 223 | return ret; |
| 224 | |
| 225 | mmc_set_bus_width(card->host, MMC_BUS_WIDTH_1); |
| 226 | |
| 227 | return 0; |
| 228 | } |
| 229 | |
Michal Miroslaw | 7310ece8 | 2010-08-10 18:01:40 -0700 | [diff] [blame] | 230 | |
| 231 | static int sdio_enable_4bit_bus(struct mmc_card *card) |
| 232 | { |
| 233 | int err; |
| 234 | |
| 235 | if (card->type == MMC_TYPE_SDIO) |
| 236 | return sdio_enable_wide(card); |
| 237 | |
| 238 | if ((card->host->caps & MMC_CAP_4_BIT_DATA) && |
| 239 | (card->scr.bus_widths & SD_SCR_BUS_WIDTH_4)) { |
| 240 | err = mmc_app_set_bus_width(card, MMC_BUS_WIDTH_4); |
| 241 | if (err) |
| 242 | return err; |
| 243 | } else |
| 244 | return 0; |
| 245 | |
| 246 | err = sdio_enable_wide(card); |
| 247 | if (err <= 0) |
| 248 | mmc_app_set_bus_width(card, MMC_BUS_WIDTH_1); |
| 249 | |
| 250 | return err; |
| 251 | } |
| 252 | |
| 253 | |
Daniel Drake | 6b5eda3 | 2010-03-05 13:43:34 -0800 | [diff] [blame] | 254 | /* |
Pierre Ossman | d16f577 | 2008-08-31 17:22:46 +0200 | [diff] [blame] | 255 | * Test if the card supports high-speed mode and, if so, switch to it. |
| 256 | */ |
Michal Miroslaw | 7310ece8 | 2010-08-10 18:01:40 -0700 | [diff] [blame] | 257 | static int mmc_sdio_switch_hs(struct mmc_card *card, int enable) |
Pierre Ossman | d16f577 | 2008-08-31 17:22:46 +0200 | [diff] [blame] | 258 | { |
| 259 | int ret; |
| 260 | u8 speed; |
| 261 | |
| 262 | if (!(card->host->caps & MMC_CAP_SD_HIGHSPEED)) |
| 263 | return 0; |
| 264 | |
| 265 | if (!card->cccr.high_speed) |
| 266 | return 0; |
| 267 | |
| 268 | ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_SPEED, 0, &speed); |
| 269 | if (ret) |
| 270 | return ret; |
| 271 | |
Michal Miroslaw | 7310ece8 | 2010-08-10 18:01:40 -0700 | [diff] [blame] | 272 | if (enable) |
| 273 | speed |= SDIO_SPEED_EHS; |
| 274 | else |
| 275 | speed &= ~SDIO_SPEED_EHS; |
Pierre Ossman | d16f577 | 2008-08-31 17:22:46 +0200 | [diff] [blame] | 276 | |
| 277 | ret = mmc_io_rw_direct(card, 1, 0, SDIO_CCCR_SPEED, speed, NULL); |
| 278 | if (ret) |
| 279 | return ret; |
| 280 | |
Michal Miroslaw | 71578a1 | 2010-08-10 18:01:40 -0700 | [diff] [blame] | 281 | return 1; |
| 282 | } |
Pierre Ossman | d16f577 | 2008-08-31 17:22:46 +0200 | [diff] [blame] | 283 | |
Michal Miroslaw | 7310ece8 | 2010-08-10 18:01:40 -0700 | [diff] [blame] | 284 | /* |
| 285 | * Enable SDIO/combo card's high-speed mode. Return 0/1 if [not]supported. |
| 286 | */ |
| 287 | static int sdio_enable_hs(struct mmc_card *card) |
| 288 | { |
| 289 | int ret; |
| 290 | |
| 291 | ret = mmc_sdio_switch_hs(card, true); |
| 292 | if (ret <= 0 || card->type == MMC_TYPE_SDIO) |
| 293 | return ret; |
| 294 | |
| 295 | ret = mmc_sd_switch_hs(card); |
| 296 | if (ret <= 0) |
| 297 | mmc_sdio_switch_hs(card, false); |
| 298 | |
| 299 | return ret; |
| 300 | } |
| 301 | |
Michal Miroslaw | 71578a1 | 2010-08-10 18:01:40 -0700 | [diff] [blame] | 302 | static unsigned mmc_sdio_get_max_clock(struct mmc_card *card) |
| 303 | { |
| 304 | unsigned max_dtr; |
| 305 | |
| 306 | if (mmc_card_highspeed(card)) { |
| 307 | /* |
| 308 | * The SDIO specification doesn't mention how |
| 309 | * the CIS transfer speed register relates to |
| 310 | * high-speed, but it seems that 50 MHz is |
| 311 | * mandatory. |
| 312 | */ |
| 313 | max_dtr = 50000000; |
| 314 | } else { |
| 315 | max_dtr = card->cis.max_dtr; |
| 316 | } |
| 317 | |
Michal Miroslaw | 7310ece8 | 2010-08-10 18:01:40 -0700 | [diff] [blame] | 318 | if (card->type == MMC_TYPE_SD_COMBO) |
| 319 | max_dtr = min(max_dtr, mmc_sd_get_max_clock(card)); |
| 320 | |
Michal Miroslaw | 71578a1 | 2010-08-10 18:01:40 -0700 | [diff] [blame] | 321 | return max_dtr; |
Pierre Ossman | d16f577 | 2008-08-31 17:22:46 +0200 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | /* |
Nicolas Pitre | 17d33e1 | 2009-09-22 16:45:28 -0700 | [diff] [blame] | 325 | * Handle the detection and initialisation of a card. |
| 326 | * |
| 327 | * In the case of a resume, "oldcard" will contain the card |
| 328 | * we're trying to reinitialise. |
| 329 | */ |
| 330 | static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr, |
Chris Ball | 3bca4cf7 | 2010-03-05 13:43:33 -0800 | [diff] [blame] | 331 | struct mmc_card *oldcard, int powered_resume) |
Nicolas Pitre | 17d33e1 | 2009-09-22 16:45:28 -0700 | [diff] [blame] | 332 | { |
| 333 | struct mmc_card *card; |
| 334 | int err; |
| 335 | |
| 336 | BUG_ON(!host); |
| 337 | WARN_ON(!host->claimed); |
| 338 | |
| 339 | /* |
| 340 | * Inform the card of the voltage |
| 341 | */ |
Chris Ball | 3bca4cf7 | 2010-03-05 13:43:33 -0800 | [diff] [blame] | 342 | if (!powered_resume) { |
| 343 | err = mmc_send_io_op_cond(host, host->ocr, &ocr); |
| 344 | if (err) |
| 345 | goto err; |
| 346 | } |
Nicolas Pitre | 17d33e1 | 2009-09-22 16:45:28 -0700 | [diff] [blame] | 347 | |
| 348 | /* |
| 349 | * For SPI, enable CRC as appropriate. |
| 350 | */ |
| 351 | if (mmc_host_is_spi(host)) { |
| 352 | err = mmc_spi_set_crc(host, use_spi_crc); |
| 353 | if (err) |
| 354 | goto err; |
| 355 | } |
| 356 | |
| 357 | /* |
| 358 | * Allocate card structure. |
| 359 | */ |
| 360 | card = mmc_alloc_card(host, NULL); |
| 361 | if (IS_ERR(card)) { |
| 362 | err = PTR_ERR(card); |
| 363 | goto err; |
| 364 | } |
| 365 | |
David Vrabel | f3c65b2 | 2010-09-09 16:37:24 -0700 | [diff] [blame] | 366 | if (ocr & R4_MEMORY_PRESENT |
| 367 | && mmc_sd_get_cid(host, host->ocr & ocr, card->raw_cid) == 0) { |
Michal Miroslaw | 7310ece8 | 2010-08-10 18:01:40 -0700 | [diff] [blame] | 368 | card->type = MMC_TYPE_SD_COMBO; |
| 369 | |
| 370 | if (oldcard && (oldcard->type != MMC_TYPE_SD_COMBO || |
| 371 | memcmp(card->raw_cid, oldcard->raw_cid, sizeof(card->raw_cid)) != 0)) { |
| 372 | mmc_remove_card(card); |
| 373 | return -ENOENT; |
| 374 | } |
| 375 | } else { |
| 376 | card->type = MMC_TYPE_SDIO; |
| 377 | |
| 378 | if (oldcard && oldcard->type != MMC_TYPE_SDIO) { |
| 379 | mmc_remove_card(card); |
| 380 | return -ENOENT; |
| 381 | } |
| 382 | } |
Nicolas Pitre | 17d33e1 | 2009-09-22 16:45:28 -0700 | [diff] [blame] | 383 | |
| 384 | /* |
Daniel Mack | 3fcb027 | 2010-04-01 10:03:25 +0200 | [diff] [blame] | 385 | * Call the optional HC's init_card function to handle quirks. |
| 386 | */ |
| 387 | if (host->ops->init_card) |
| 388 | host->ops->init_card(host, card); |
| 389 | |
| 390 | /* |
Nicolas Pitre | 17d33e1 | 2009-09-22 16:45:28 -0700 | [diff] [blame] | 391 | * For native busses: set card RCA and quit open drain mode. |
| 392 | */ |
Chris Ball | 3bca4cf7 | 2010-03-05 13:43:33 -0800 | [diff] [blame] | 393 | if (!powered_resume && !mmc_host_is_spi(host)) { |
Nicolas Pitre | 17d33e1 | 2009-09-22 16:45:28 -0700 | [diff] [blame] | 394 | err = mmc_send_relative_addr(host, &card->rca); |
| 395 | if (err) |
| 396 | goto remove; |
| 397 | |
| 398 | mmc_set_bus_mode(host, MMC_BUSMODE_PUSHPULL); |
| 399 | } |
| 400 | |
| 401 | /* |
Michal Miroslaw | 7310ece8 | 2010-08-10 18:01:40 -0700 | [diff] [blame] | 402 | * Read CSD, before selecting the card |
| 403 | */ |
| 404 | if (!oldcard && card->type == MMC_TYPE_SD_COMBO) { |
| 405 | err = mmc_sd_get_csd(host, card); |
| 406 | if (err) |
| 407 | return err; |
| 408 | |
| 409 | mmc_decode_cid(card); |
| 410 | } |
| 411 | |
| 412 | /* |
Nicolas Pitre | 17d33e1 | 2009-09-22 16:45:28 -0700 | [diff] [blame] | 413 | * Select card, as all following commands rely on that. |
| 414 | */ |
Chris Ball | 3bca4cf7 | 2010-03-05 13:43:33 -0800 | [diff] [blame] | 415 | if (!powered_resume && !mmc_host_is_spi(host)) { |
Nicolas Pitre | 17d33e1 | 2009-09-22 16:45:28 -0700 | [diff] [blame] | 416 | err = mmc_select_card(card); |
| 417 | if (err) |
| 418 | goto remove; |
| 419 | } |
| 420 | |
Grazvydas Ignotas | 6f51be3 | 2010-08-10 18:01:50 -0700 | [diff] [blame] | 421 | if (card->quirks & MMC_QUIRK_NONSTD_SDIO) { |
| 422 | /* |
| 423 | * This is non-standard SDIO device, meaning it doesn't |
| 424 | * have any CIA (Common I/O area) registers present. |
| 425 | * It's host's responsibility to fill cccr and cis |
| 426 | * structures in init_card(). |
| 427 | */ |
| 428 | mmc_set_clock(host, card->cis.max_dtr); |
| 429 | |
| 430 | if (card->cccr.high_speed) { |
| 431 | mmc_card_set_highspeed(card); |
| 432 | mmc_set_timing(card->host, MMC_TIMING_SD_HS); |
| 433 | } |
| 434 | |
| 435 | goto finish; |
| 436 | } |
| 437 | |
Nicolas Pitre | 17d33e1 | 2009-09-22 16:45:28 -0700 | [diff] [blame] | 438 | /* |
| 439 | * Read the common registers. |
| 440 | */ |
| 441 | err = sdio_read_cccr(card); |
| 442 | if (err) |
| 443 | goto remove; |
| 444 | |
| 445 | /* |
| 446 | * Read the common CIS tuples. |
| 447 | */ |
| 448 | err = sdio_read_common_cis(card); |
| 449 | if (err) |
| 450 | goto remove; |
| 451 | |
| 452 | if (oldcard) { |
| 453 | int same = (card->cis.vendor == oldcard->cis.vendor && |
| 454 | card->cis.device == oldcard->cis.device); |
| 455 | mmc_remove_card(card); |
Michal Miroslaw | 7310ece8 | 2010-08-10 18:01:40 -0700 | [diff] [blame] | 456 | if (!same) |
| 457 | return -ENOENT; |
| 458 | |
Nicolas Pitre | 17d33e1 | 2009-09-22 16:45:28 -0700 | [diff] [blame] | 459 | card = oldcard; |
| 460 | } |
| 461 | |
Michal Miroslaw | 7310ece8 | 2010-08-10 18:01:40 -0700 | [diff] [blame] | 462 | if (card->type == MMC_TYPE_SD_COMBO) { |
| 463 | err = mmc_sd_setup_card(host, card, oldcard != NULL); |
| 464 | /* handle as SDIO-only card if memory init failed */ |
| 465 | if (err) { |
| 466 | mmc_go_idle(host); |
| 467 | if (mmc_host_is_spi(host)) |
| 468 | /* should not fail, as it worked previously */ |
| 469 | mmc_spi_set_crc(host, use_spi_crc); |
| 470 | card->type = MMC_TYPE_SDIO; |
| 471 | } else |
| 472 | card->dev.type = &sd_type; |
| 473 | } |
| 474 | |
| 475 | /* |
| 476 | * If needed, disconnect card detection pull-up resistor. |
| 477 | */ |
| 478 | err = sdio_disable_cd(card); |
| 479 | if (err) |
| 480 | goto remove; |
| 481 | |
Nicolas Pitre | 17d33e1 | 2009-09-22 16:45:28 -0700 | [diff] [blame] | 482 | /* |
| 483 | * Switch to high-speed (if supported). |
| 484 | */ |
| 485 | err = sdio_enable_hs(card); |
Michal Miroslaw | 71578a1 | 2010-08-10 18:01:40 -0700 | [diff] [blame] | 486 | if (err > 0) |
| 487 | mmc_sd_go_highspeed(card); |
| 488 | else if (err) |
Nicolas Pitre | 17d33e1 | 2009-09-22 16:45:28 -0700 | [diff] [blame] | 489 | goto remove; |
| 490 | |
| 491 | /* |
| 492 | * Change to the card's maximum speed. |
| 493 | */ |
Michal Miroslaw | 71578a1 | 2010-08-10 18:01:40 -0700 | [diff] [blame] | 494 | mmc_set_clock(host, mmc_sdio_get_max_clock(card)); |
Nicolas Pitre | 17d33e1 | 2009-09-22 16:45:28 -0700 | [diff] [blame] | 495 | |
| 496 | /* |
| 497 | * Switch to wider bus (if supported). |
| 498 | */ |
Michal Miroslaw | 7310ece8 | 2010-08-10 18:01:40 -0700 | [diff] [blame] | 499 | err = sdio_enable_4bit_bus(card); |
| 500 | if (err > 0) |
| 501 | mmc_set_bus_width(card->host, MMC_BUS_WIDTH_4); |
| 502 | else if (err) |
Nicolas Pitre | 17d33e1 | 2009-09-22 16:45:28 -0700 | [diff] [blame] | 503 | goto remove; |
| 504 | |
Grazvydas Ignotas | 6f51be3 | 2010-08-10 18:01:50 -0700 | [diff] [blame] | 505 | finish: |
Nicolas Pitre | 17d33e1 | 2009-09-22 16:45:28 -0700 | [diff] [blame] | 506 | if (!oldcard) |
| 507 | host->card = card; |
| 508 | return 0; |
| 509 | |
| 510 | remove: |
| 511 | if (!oldcard) |
| 512 | mmc_remove_card(card); |
| 513 | |
| 514 | err: |
| 515 | return err; |
| 516 | } |
| 517 | |
| 518 | /* |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 519 | * Host is being removed. Free up the current card. |
| 520 | */ |
| 521 | static void mmc_sdio_remove(struct mmc_host *host) |
| 522 | { |
Pierre Ossman | e29a7d7 | 2007-05-26 13:48:18 +0200 | [diff] [blame] | 523 | int i; |
| 524 | |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 525 | BUG_ON(!host); |
| 526 | BUG_ON(!host->card); |
| 527 | |
Pierre Ossman | e29a7d7 | 2007-05-26 13:48:18 +0200 | [diff] [blame] | 528 | for (i = 0;i < host->card->sdio_funcs;i++) { |
| 529 | if (host->card->sdio_func[i]) { |
| 530 | sdio_remove_func(host->card->sdio_func[i]); |
| 531 | host->card->sdio_func[i] = NULL; |
| 532 | } |
| 533 | } |
| 534 | |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 535 | mmc_remove_card(host->card); |
| 536 | host->card = NULL; |
| 537 | } |
| 538 | |
| 539 | /* |
| 540 | * Card detection callback from host. |
| 541 | */ |
| 542 | static void mmc_sdio_detect(struct mmc_host *host) |
| 543 | { |
| 544 | int err; |
| 545 | |
| 546 | BUG_ON(!host); |
| 547 | BUG_ON(!host->card); |
| 548 | |
Ohad Ben-Cohen | 87973ba | 2010-10-02 13:54:12 +0200 | [diff] [blame] | 549 | /* Make sure card is powered before detecting it */ |
Ohad Ben-Cohen | ed919b0 | 2010-11-19 09:29:09 +0200 | [diff] [blame] | 550 | if (host->caps & MMC_CAP_POWER_OFF_CARD) { |
| 551 | err = pm_runtime_get_sync(&host->card->dev); |
| 552 | if (err < 0) |
| 553 | goto out; |
| 554 | } |
Ohad Ben-Cohen | 87973ba | 2010-10-02 13:54:12 +0200 | [diff] [blame] | 555 | |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 556 | mmc_claim_host(host); |
| 557 | |
| 558 | /* |
| 559 | * Just check if our card has been removed. |
| 560 | */ |
| 561 | err = mmc_select_card(host->card); |
| 562 | |
| 563 | mmc_release_host(host); |
| 564 | |
Ohad Ben-Cohen | 4d0812c | 2010-11-14 12:40:33 +0200 | [diff] [blame] | 565 | /* |
| 566 | * Tell PM core it's OK to power off the card now. |
| 567 | * |
| 568 | * The _sync variant is used in order to ensure that the card |
| 569 | * is left powered off in case an error occurred, and the card |
| 570 | * is going to be removed. |
| 571 | * |
| 572 | * Since there is no specific reason to believe a new user |
| 573 | * is about to show up at this point, the _sync variant is |
| 574 | * desirable anyway. |
| 575 | */ |
Ohad Ben-Cohen | ed919b0 | 2010-11-19 09:29:09 +0200 | [diff] [blame] | 576 | if (host->caps & MMC_CAP_POWER_OFF_CARD) |
| 577 | pm_runtime_put_sync(&host->card->dev); |
Ohad Ben-Cohen | 4d0812c | 2010-11-14 12:40:33 +0200 | [diff] [blame] | 578 | |
Ohad Ben-Cohen | 87973ba | 2010-10-02 13:54:12 +0200 | [diff] [blame] | 579 | out: |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 580 | if (err) { |
| 581 | mmc_sdio_remove(host); |
| 582 | |
| 583 | mmc_claim_host(host); |
| 584 | mmc_detach_bus(host); |
| 585 | mmc_release_host(host); |
| 586 | } |
| 587 | } |
| 588 | |
Nicolas Pitre | 17d33e1 | 2009-09-22 16:45:28 -0700 | [diff] [blame] | 589 | /* |
| 590 | * SDIO suspend. We need to suspend all functions separately. |
| 591 | * Therefore all registered functions must have drivers with suspend |
| 592 | * and resume methods. Failing that we simply remove the whole card. |
| 593 | */ |
Nicolas Pitre | 95cdfb7 | 2009-09-22 16:45:29 -0700 | [diff] [blame] | 594 | static int mmc_sdio_suspend(struct mmc_host *host) |
Nicolas Pitre | 17d33e1 | 2009-09-22 16:45:28 -0700 | [diff] [blame] | 595 | { |
Nicolas Pitre | 95cdfb7 | 2009-09-22 16:45:29 -0700 | [diff] [blame] | 596 | int i, err = 0; |
Nicolas Pitre | 17d33e1 | 2009-09-22 16:45:28 -0700 | [diff] [blame] | 597 | |
Nicolas Pitre | 17d33e1 | 2009-09-22 16:45:28 -0700 | [diff] [blame] | 598 | for (i = 0; i < host->card->sdio_funcs; i++) { |
| 599 | struct sdio_func *func = host->card->sdio_func[i]; |
| 600 | if (func && sdio_func_present(func) && func->dev.driver) { |
| 601 | const struct dev_pm_ops *pmops = func->dev.driver->pm; |
| 602 | if (!pmops || !pmops->suspend || !pmops->resume) { |
Nicolas Pitre | 95cdfb7 | 2009-09-22 16:45:29 -0700 | [diff] [blame] | 603 | /* force removal of entire card in that case */ |
| 604 | err = -ENOSYS; |
| 605 | } else |
| 606 | err = pmops->suspend(&func->dev); |
| 607 | if (err) |
| 608 | break; |
Nicolas Pitre | 17d33e1 | 2009-09-22 16:45:28 -0700 | [diff] [blame] | 609 | } |
| 610 | } |
Nicolas Pitre | 95cdfb7 | 2009-09-22 16:45:29 -0700 | [diff] [blame] | 611 | while (err && --i >= 0) { |
Nicolas Pitre | 17d33e1 | 2009-09-22 16:45:28 -0700 | [diff] [blame] | 612 | struct sdio_func *func = host->card->sdio_func[i]; |
| 613 | if (func && sdio_func_present(func) && func->dev.driver) { |
| 614 | const struct dev_pm_ops *pmops = func->dev.driver->pm; |
| 615 | pmops->resume(&func->dev); |
| 616 | } |
| 617 | } |
Nicolas Pitre | 95cdfb7 | 2009-09-22 16:45:29 -0700 | [diff] [blame] | 618 | |
Daniel Drake | 6b5eda3 | 2010-03-05 13:43:34 -0800 | [diff] [blame] | 619 | if (!err && host->pm_flags & MMC_PM_KEEP_POWER) { |
| 620 | mmc_claim_host(host); |
| 621 | sdio_disable_wide(host->card); |
| 622 | mmc_release_host(host); |
| 623 | } |
| 624 | |
Nicolas Pitre | 95cdfb7 | 2009-09-22 16:45:29 -0700 | [diff] [blame] | 625 | return err; |
| 626 | } |
| 627 | |
| 628 | static int mmc_sdio_resume(struct mmc_host *host) |
| 629 | { |
Ohad Ben-Cohen | 080bc97 | 2010-11-28 07:21:29 +0200 | [diff] [blame] | 630 | int i, err = 0; |
Nicolas Pitre | 95cdfb7 | 2009-09-22 16:45:29 -0700 | [diff] [blame] | 631 | |
| 632 | BUG_ON(!host); |
| 633 | BUG_ON(!host->card); |
| 634 | |
| 635 | /* Basic card reinitialization. */ |
| 636 | mmc_claim_host(host); |
Ohad Ben-Cohen | 080bc97 | 2010-11-28 07:21:29 +0200 | [diff] [blame] | 637 | |
| 638 | /* No need to reinitialize powered-resumed nonremovable cards */ |
| 639 | if (mmc_card_is_removable(host) || !mmc_card_is_powered_resumed(host)) |
| 640 | err = mmc_sdio_init_card(host, host->ocr, host->card, |
Chris Ball | 3bca4cf7 | 2010-03-05 13:43:33 -0800 | [diff] [blame] | 641 | (host->pm_flags & MMC_PM_KEEP_POWER)); |
Ohad Ben-Cohen | 080bc97 | 2010-11-28 07:21:29 +0200 | [diff] [blame] | 642 | else if (mmc_card_is_powered_resumed(host)) { |
| 643 | /* We may have switched to 1-bit mode during suspend */ |
| 644 | err = sdio_enable_4bit_bus(host->card); |
| 645 | if (err > 0) { |
| 646 | mmc_set_bus_width(host, MMC_BUS_WIDTH_4); |
| 647 | err = 0; |
| 648 | } |
| 649 | } |
| 650 | |
Nicolas Pitre | 4021684 | 2010-03-05 13:43:34 -0800 | [diff] [blame] | 651 | if (!err && host->sdio_irqs) |
| 652 | mmc_signal_sdio_irq(host); |
Nicolas Pitre | 95cdfb7 | 2009-09-22 16:45:29 -0700 | [diff] [blame] | 653 | mmc_release_host(host); |
| 654 | |
| 655 | /* |
| 656 | * If the card looked to be the same as before suspending, then |
| 657 | * we proceed to resume all card functions. If one of them returns |
| 658 | * an error then we simply return that error to the core and the |
| 659 | * card will be redetected as new. It is the responsibility of |
| 660 | * the function driver to perform further tests with the extra |
| 661 | * knowledge it has of the card to confirm the card is indeed the |
| 662 | * same as before suspending (same MAC address for network cards, |
| 663 | * etc.) and return an error otherwise. |
| 664 | */ |
| 665 | for (i = 0; !err && i < host->card->sdio_funcs; i++) { |
| 666 | struct sdio_func *func = host->card->sdio_func[i]; |
| 667 | if (func && sdio_func_present(func) && func->dev.driver) { |
| 668 | const struct dev_pm_ops *pmops = func->dev.driver->pm; |
| 669 | err = pmops->resume(&func->dev); |
| 670 | } |
| 671 | } |
| 672 | |
| 673 | return err; |
Nicolas Pitre | 17d33e1 | 2009-09-22 16:45:28 -0700 | [diff] [blame] | 674 | } |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 675 | |
Ohad Ben-Cohen | d3fe37b | 2010-10-02 13:54:07 +0200 | [diff] [blame] | 676 | static int mmc_sdio_power_restore(struct mmc_host *host) |
| 677 | { |
| 678 | int ret; |
| 679 | |
| 680 | BUG_ON(!host); |
| 681 | BUG_ON(!host->card); |
| 682 | |
| 683 | mmc_claim_host(host); |
| 684 | ret = mmc_sdio_init_card(host, host->ocr, host->card, |
| 685 | (host->pm_flags & MMC_PM_KEEP_POWER)); |
| 686 | if (!ret && host->sdio_irqs) |
| 687 | mmc_signal_sdio_irq(host); |
| 688 | mmc_release_host(host); |
| 689 | |
| 690 | return ret; |
| 691 | } |
| 692 | |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 693 | static const struct mmc_bus_ops mmc_sdio_ops = { |
| 694 | .remove = mmc_sdio_remove, |
| 695 | .detect = mmc_sdio_detect, |
Nicolas Pitre | 17d33e1 | 2009-09-22 16:45:28 -0700 | [diff] [blame] | 696 | .suspend = mmc_sdio_suspend, |
| 697 | .resume = mmc_sdio_resume, |
Ohad Ben-Cohen | d3fe37b | 2010-10-02 13:54:07 +0200 | [diff] [blame] | 698 | .power_restore = mmc_sdio_power_restore, |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 699 | }; |
| 700 | |
| 701 | |
| 702 | /* |
| 703 | * Starting point for SDIO card init. |
| 704 | */ |
Andy Ross | 807e8e4 | 2011-01-03 10:36:56 -0800 | [diff] [blame] | 705 | int mmc_attach_sdio(struct mmc_host *host) |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 706 | { |
Andy Ross | 807e8e4 | 2011-01-03 10:36:56 -0800 | [diff] [blame] | 707 | int err, i, funcs; |
| 708 | u32 ocr; |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 709 | struct mmc_card *card; |
| 710 | |
| 711 | BUG_ON(!host); |
Pierre Ossman | d84075c8 | 2007-08-09 13:23:56 +0200 | [diff] [blame] | 712 | WARN_ON(!host->claimed); |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 713 | |
Andy Ross | 807e8e4 | 2011-01-03 10:36:56 -0800 | [diff] [blame] | 714 | err = mmc_send_io_op_cond(host, 0, &ocr); |
| 715 | if (err) |
| 716 | return err; |
| 717 | |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 718 | mmc_attach_bus(host, &mmc_sdio_ops); |
Takashi Iwai | 8f230f4 | 2010-12-08 10:04:30 +0100 | [diff] [blame] | 719 | if (host->ocr_avail_sdio) |
| 720 | host->ocr_avail = host->ocr_avail_sdio; |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 721 | |
| 722 | /* |
| 723 | * Sanity check the voltages that the card claims to |
| 724 | * support. |
| 725 | */ |
| 726 | if (ocr & 0x7F) { |
| 727 | printk(KERN_WARNING "%s: card claims to support voltages " |
| 728 | "below the defined range. These will be ignored.\n", |
| 729 | mmc_hostname(host)); |
| 730 | ocr &= ~0x7F; |
| 731 | } |
| 732 | |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 733 | host->ocr = mmc_select_voltage(host, ocr); |
| 734 | |
| 735 | /* |
| 736 | * Can we support the voltage(s) of the card(s)? |
| 737 | */ |
| 738 | if (!host->ocr) { |
| 739 | err = -EINVAL; |
| 740 | goto err; |
| 741 | } |
| 742 | |
| 743 | /* |
Nicolas Pitre | 17d33e1 | 2009-09-22 16:45:28 -0700 | [diff] [blame] | 744 | * Detect and init the card. |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 745 | */ |
Chris Ball | 3bca4cf7 | 2010-03-05 13:43:33 -0800 | [diff] [blame] | 746 | err = mmc_sdio_init_card(host, host->ocr, NULL, 0); |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 747 | if (err) |
| 748 | goto err; |
Nicolas Pitre | 17d33e1 | 2009-09-22 16:45:28 -0700 | [diff] [blame] | 749 | card = host->card; |
David Brownell | af51715 | 2007-08-08 09:11:32 -0700 | [diff] [blame] | 750 | |
| 751 | /* |
Ohad Ben-Cohen | ed919b0 | 2010-11-19 09:29:09 +0200 | [diff] [blame] | 752 | * Enable runtime PM only if supported by host+card+board |
Ohad Ben-Cohen | 81968561 | 2010-10-02 13:54:10 +0200 | [diff] [blame] | 753 | */ |
Ohad Ben-Cohen | ed919b0 | 2010-11-19 09:29:09 +0200 | [diff] [blame] | 754 | if (host->caps & MMC_CAP_POWER_OFF_CARD) { |
| 755 | /* |
| 756 | * Let runtime PM core know our card is active |
| 757 | */ |
| 758 | err = pm_runtime_set_active(&card->dev); |
| 759 | if (err) |
| 760 | goto remove; |
Ohad Ben-Cohen | 81968561 | 2010-10-02 13:54:10 +0200 | [diff] [blame] | 761 | |
Ohad Ben-Cohen | ed919b0 | 2010-11-19 09:29:09 +0200 | [diff] [blame] | 762 | /* |
| 763 | * Enable runtime PM for this card |
| 764 | */ |
| 765 | pm_runtime_enable(&card->dev); |
| 766 | } |
Ohad Ben-Cohen | 81968561 | 2010-10-02 13:54:10 +0200 | [diff] [blame] | 767 | |
| 768 | /* |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 769 | * The number of functions on the card is encoded inside |
| 770 | * the ocr. |
| 771 | */ |
Matt Fleming | e881279 | 2009-12-17 15:27:18 -0800 | [diff] [blame] | 772 | funcs = (ocr & 0x70000000) >> 28; |
| 773 | card->sdio_funcs = 0; |
Pierre Ossman | 4ff6471 | 2007-07-30 18:23:53 +0200 | [diff] [blame] | 774 | |
| 775 | /* |
Pierre Ossman | e29a7d7 | 2007-05-26 13:48:18 +0200 | [diff] [blame] | 776 | * Initialize (but don't add) all present functions. |
| 777 | */ |
Matt Fleming | e881279 | 2009-12-17 15:27:18 -0800 | [diff] [blame] | 778 | for (i = 0; i < funcs; i++, card->sdio_funcs++) { |
Pierre Ossman | e29a7d7 | 2007-05-26 13:48:18 +0200 | [diff] [blame] | 779 | err = sdio_init_func(host->card, i + 1); |
| 780 | if (err) |
| 781 | goto remove; |
Ohad Ben-Cohen | 40bba0c | 2010-10-02 13:54:11 +0200 | [diff] [blame] | 782 | |
| 783 | /* |
Ohad Ben-Cohen | ed919b0 | 2010-11-19 09:29:09 +0200 | [diff] [blame] | 784 | * Enable Runtime PM for this func (if supported) |
Ohad Ben-Cohen | 40bba0c | 2010-10-02 13:54:11 +0200 | [diff] [blame] | 785 | */ |
Ohad Ben-Cohen | ed919b0 | 2010-11-19 09:29:09 +0200 | [diff] [blame] | 786 | if (host->caps & MMC_CAP_POWER_OFF_CARD) |
| 787 | pm_runtime_enable(&card->sdio_func[i]->dev); |
Pierre Ossman | e29a7d7 | 2007-05-26 13:48:18 +0200 | [diff] [blame] | 788 | } |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 789 | |
Pierre Ossman | e29a7d7 | 2007-05-26 13:48:18 +0200 | [diff] [blame] | 790 | /* |
| 791 | * First add the card to the driver model... |
| 792 | */ |
Andy Ross | 807e8e4 | 2011-01-03 10:36:56 -0800 | [diff] [blame] | 793 | mmc_release_host(host); |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 794 | err = mmc_add_card(host->card); |
| 795 | if (err) |
Pierre Ossman | e29a7d7 | 2007-05-26 13:48:18 +0200 | [diff] [blame] | 796 | goto remove_added; |
| 797 | |
| 798 | /* |
| 799 | * ...then the SDIO functions. |
| 800 | */ |
| 801 | for (i = 0;i < funcs;i++) { |
| 802 | err = sdio_add_func(host->card->sdio_func[i]); |
| 803 | if (err) |
| 804 | goto remove_added; |
| 805 | } |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 806 | |
Dmitry Shmidt | 3449791 | 2011-03-03 17:40:10 -0500 | [diff] [blame] | 807 | mmc_claim_host(host); |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 808 | return 0; |
| 809 | |
Pierre Ossman | e29a7d7 | 2007-05-26 13:48:18 +0200 | [diff] [blame] | 810 | |
| 811 | remove_added: |
| 812 | /* Remove without lock if the device has been added. */ |
| 813 | mmc_sdio_remove(host); |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 814 | mmc_claim_host(host); |
Pierre Ossman | e29a7d7 | 2007-05-26 13:48:18 +0200 | [diff] [blame] | 815 | remove: |
| 816 | /* And with lock if it hasn't been added. */ |
Andy Ross | 807e8e4 | 2011-01-03 10:36:56 -0800 | [diff] [blame] | 817 | mmc_release_host(host); |
Pierre Ossman | e29a7d7 | 2007-05-26 13:48:18 +0200 | [diff] [blame] | 818 | if (host->card) |
| 819 | mmc_sdio_remove(host); |
Andy Ross | 807e8e4 | 2011-01-03 10:36:56 -0800 | [diff] [blame] | 820 | mmc_claim_host(host); |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 821 | err: |
| 822 | mmc_detach_bus(host); |
Pierre Ossman | 5c4e6f1 | 2007-05-21 20:23:20 +0200 | [diff] [blame] | 823 | |
| 824 | printk(KERN_ERR "%s: error %d whilst initialising SDIO card\n", |
| 825 | mmc_hostname(host), err); |
| 826 | |
| 827 | return err; |
| 828 | } |
| 829 | |