diff options
| -rw-r--r-- | drivers/mmc/mmc.c | 326 | ||||
| -rw-r--r-- | include/linux/mmc/card.h | 3 | ||||
| -rw-r--r-- | include/linux/mmc/host.h | 4 | ||||
| -rw-r--r-- | include/linux/mmc/mmc.h | 2 |
4 files changed, 262 insertions, 73 deletions
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index 0a8165974ba7..294961a102ca 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c | |||
| @@ -172,7 +172,79 @@ int mmc_wait_for_cmd(struct mmc_host *host, struct mmc_command *cmd, int retries | |||
| 172 | 172 | ||
| 173 | EXPORT_SYMBOL(mmc_wait_for_cmd); | 173 | EXPORT_SYMBOL(mmc_wait_for_cmd); |
| 174 | 174 | ||
| 175 | /** | ||
| 176 | * mmc_wait_for_app_cmd - start an application command and wait for | ||
| 177 | completion | ||
| 178 | * @host: MMC host to start command | ||
| 179 | * @rca: RCA to send MMC_APP_CMD to | ||
| 180 | * @cmd: MMC command to start | ||
| 181 | * @retries: maximum number of retries | ||
| 182 | * | ||
| 183 | * Sends a MMC_APP_CMD, checks the card response, sends the command | ||
| 184 | * in the parameter and waits for it to complete. Return any error | ||
| 185 | * that occurred while the command was executing. Do not attempt to | ||
| 186 | * parse the response. | ||
| 187 | */ | ||
| 188 | int mmc_wait_for_app_cmd(struct mmc_host *host, unsigned int rca, | ||
| 189 | struct mmc_command *cmd, int retries) | ||
| 190 | { | ||
| 191 | struct mmc_request mrq; | ||
| 192 | struct mmc_command appcmd; | ||
| 193 | |||
| 194 | int i, err; | ||
| 195 | |||
| 196 | BUG_ON(host->card_busy == NULL); | ||
| 197 | BUG_ON(retries < 0); | ||
| 198 | |||
| 199 | err = MMC_ERR_INVALID; | ||
| 200 | |||
| 201 | /* | ||
| 202 | * We have to resend MMC_APP_CMD for each attempt so | ||
| 203 | * we cannot use the retries field in mmc_command. | ||
| 204 | */ | ||
| 205 | for (i = 0;i <= retries;i++) { | ||
| 206 | memset(&mrq, 0, sizeof(struct mmc_request)); | ||
| 207 | |||
| 208 | appcmd.opcode = MMC_APP_CMD; | ||
| 209 | appcmd.arg = rca << 16; | ||
| 210 | appcmd.flags = MMC_RSP_R1; | ||
| 211 | appcmd.retries = 0; | ||
| 212 | memset(appcmd.resp, 0, sizeof(appcmd.resp)); | ||
| 213 | appcmd.data = NULL; | ||
| 214 | |||
| 215 | mrq.cmd = &appcmd; | ||
| 216 | appcmd.data = NULL; | ||
| 217 | |||
| 218 | mmc_wait_for_req(host, &mrq); | ||
| 219 | |||
| 220 | if (appcmd.error) { | ||
| 221 | err = appcmd.error; | ||
| 222 | continue; | ||
| 223 | } | ||
| 224 | |||
| 225 | /* Check that card supported application commands */ | ||
| 226 | if (!(appcmd.resp[0] & R1_APP_CMD)) | ||
| 227 | return MMC_ERR_FAILED; | ||
| 228 | |||
| 229 | memset(&mrq, 0, sizeof(struct mmc_request)); | ||
| 230 | |||
| 231 | memset(cmd->resp, 0, sizeof(cmd->resp)); | ||
| 232 | cmd->retries = 0; | ||
| 233 | |||
| 234 | mrq.cmd = cmd; | ||
| 235 | cmd->data = NULL; | ||
| 236 | |||
| 237 | mmc_wait_for_req(host, &mrq); | ||
| 175 | 238 | ||
| 239 | err = cmd->error; | ||
| 240 | if (cmd->error == MMC_ERR_NONE) | ||
| 241 | break; | ||
| 242 | } | ||
| 243 | |||
| 244 | return err; | ||
| 245 | } | ||
| 246 | |||
| 247 | EXPORT_SYMBOL(mmc_wait_for_app_cmd); | ||
| 176 | 248 | ||
| 177 | /** | 249 | /** |
| 178 | * __mmc_claim_host - exclusively claim a host | 250 | * __mmc_claim_host - exclusively claim a host |
| @@ -322,48 +394,70 @@ static void mmc_decode_cid(struct mmc_card *card) | |||
| 322 | 394 | ||
| 323 | memset(&card->cid, 0, sizeof(struct mmc_cid)); | 395 | memset(&card->cid, 0, sizeof(struct mmc_cid)); |
| 324 | 396 | ||
| 325 | /* | 397 | if (mmc_card_sd(card)) { |
| 326 | * The selection of the format here is guesswork based upon | 398 | /* |
| 327 | * information people have sent to date. | 399 | * SD doesn't currently have a version field so we will |
| 328 | */ | 400 | * have to assume we can parse this. |
| 329 | switch (card->csd.mmca_vsn) { | 401 | */ |
| 330 | case 0: /* MMC v1.? */ | 402 | card->cid.manfid = UNSTUFF_BITS(resp, 120, 8); |
| 331 | case 1: /* MMC v1.4 */ | 403 | card->cid.oemid = UNSTUFF_BITS(resp, 104, 16); |
| 332 | card->cid.manfid = UNSTUFF_BITS(resp, 104, 24); | 404 | card->cid.prod_name[0] = UNSTUFF_BITS(resp, 96, 8); |
| 333 | card->cid.prod_name[0] = UNSTUFF_BITS(resp, 96, 8); | 405 | card->cid.prod_name[1] = UNSTUFF_BITS(resp, 88, 8); |
| 334 | card->cid.prod_name[1] = UNSTUFF_BITS(resp, 88, 8); | 406 | card->cid.prod_name[2] = UNSTUFF_BITS(resp, 80, 8); |
| 335 | card->cid.prod_name[2] = UNSTUFF_BITS(resp, 80, 8); | 407 | card->cid.prod_name[3] = UNSTUFF_BITS(resp, 72, 8); |
| 336 | card->cid.prod_name[3] = UNSTUFF_BITS(resp, 72, 8); | 408 | card->cid.prod_name[4] = UNSTUFF_BITS(resp, 64, 8); |
| 337 | card->cid.prod_name[4] = UNSTUFF_BITS(resp, 64, 8); | 409 | card->cid.hwrev = UNSTUFF_BITS(resp, 60, 4); |
| 338 | card->cid.prod_name[5] = UNSTUFF_BITS(resp, 56, 8); | 410 | card->cid.fwrev = UNSTUFF_BITS(resp, 56, 4); |
| 339 | card->cid.prod_name[6] = UNSTUFF_BITS(resp, 48, 8); | 411 | card->cid.serial = UNSTUFF_BITS(resp, 24, 32); |
| 340 | card->cid.hwrev = UNSTUFF_BITS(resp, 44, 4); | 412 | card->cid.year = UNSTUFF_BITS(resp, 12, 8); |
| 341 | card->cid.fwrev = UNSTUFF_BITS(resp, 40, 4); | 413 | card->cid.month = UNSTUFF_BITS(resp, 8, 4); |
| 342 | card->cid.serial = UNSTUFF_BITS(resp, 16, 24); | 414 | |
| 343 | card->cid.month = UNSTUFF_BITS(resp, 12, 4); | 415 | card->cid.year += 2000; /* SD cards year offset */ |
| 344 | card->cid.year = UNSTUFF_BITS(resp, 8, 4) + 1997; | 416 | } |
| 345 | break; | 417 | else { |
| 346 | 418 | /* | |
| 347 | case 2: /* MMC v2.x ? */ | 419 | * The selection of the format here is based upon published |
| 348 | case 3: /* MMC v3.x ? */ | 420 | * specs from sandisk and from what people have reported. |
| 349 | card->cid.manfid = UNSTUFF_BITS(resp, 120, 8); | 421 | */ |
| 350 | card->cid.oemid = UNSTUFF_BITS(resp, 104, 16); | 422 | switch (card->csd.mmca_vsn) { |
| 351 | card->cid.prod_name[0] = UNSTUFF_BITS(resp, 96, 8); | 423 | case 0: /* MMC v1.0 - v1.2 */ |
| 352 | card->cid.prod_name[1] = UNSTUFF_BITS(resp, 88, 8); | 424 | case 1: /* MMC v1.4 */ |
| 353 | card->cid.prod_name[2] = UNSTUFF_BITS(resp, 80, 8); | 425 | card->cid.manfid = UNSTUFF_BITS(resp, 104, 24); |
| 354 | card->cid.prod_name[3] = UNSTUFF_BITS(resp, 72, 8); | 426 | card->cid.prod_name[0] = UNSTUFF_BITS(resp, 96, 8); |
| 355 | card->cid.prod_name[4] = UNSTUFF_BITS(resp, 64, 8); | 427 | card->cid.prod_name[1] = UNSTUFF_BITS(resp, 88, 8); |
| 356 | card->cid.prod_name[5] = UNSTUFF_BITS(resp, 56, 8); | 428 | card->cid.prod_name[2] = UNSTUFF_BITS(resp, 80, 8); |
| 357 | card->cid.serial = UNSTUFF_BITS(resp, 16, 32); | 429 | card->cid.prod_name[3] = UNSTUFF_BITS(resp, 72, 8); |
| 358 | card->cid.month = UNSTUFF_BITS(resp, 12, 4); | 430 | card->cid.prod_name[4] = UNSTUFF_BITS(resp, 64, 8); |
| 359 | card->cid.year = UNSTUFF_BITS(resp, 8, 4) + 1997; | 431 | card->cid.prod_name[5] = UNSTUFF_BITS(resp, 56, 8); |
| 360 | break; | 432 | card->cid.prod_name[6] = UNSTUFF_BITS(resp, 48, 8); |
| 361 | 433 | card->cid.hwrev = UNSTUFF_BITS(resp, 44, 4); | |
| 362 | default: | 434 | card->cid.fwrev = UNSTUFF_BITS(resp, 40, 4); |
| 363 | printk("%s: card has unknown MMCA version %d\n", | 435 | card->cid.serial = UNSTUFF_BITS(resp, 16, 24); |
| 364 | mmc_hostname(card->host), card->csd.mmca_vsn); | 436 | card->cid.month = UNSTUFF_BITS(resp, 12, 4); |
| 365 | mmc_card_set_bad(card); | 437 | card->cid.year = UNSTUFF_BITS(resp, 8, 4) + 1997; |
| 366 | break; | 438 | break; |
| 439 | |||
| 440 | case 2: /* MMC v2.0 - v2.2 */ | ||
| 441 | case 3: /* MMC v3.1 - v3.3 */ | ||
| 442 | card->cid.manfid = UNSTUFF_BITS(resp, 120, 8); | ||
| 443 | card->cid.oemid = UNSTUFF_BITS(resp, 104, 16); | ||
| 444 | card->cid.prod_name[0] = UNSTUFF_BITS(resp, 96, 8); | ||
| 445 | card->cid.prod_name[1] = UNSTUFF_BITS(resp, 88, 8); | ||
| 446 | card->cid.prod_name[2] = UNSTUFF_BITS(resp, 80, 8); | ||
| 447 | card->cid.prod_name[3] = UNSTUFF_BITS(resp, 72, 8); | ||
| 448 | card->cid.prod_name[4] = UNSTUFF_BITS(resp, 64, 8); | ||
| 449 | card->cid.prod_name[5] = UNSTUFF_BITS(resp, 56, 8); | ||
| 450 | card->cid.serial = UNSTUFF_BITS(resp, 16, 32); | ||
| 451 | card->cid.month = UNSTUFF_BITS(resp, 12, 4); | ||
| 452 | card->cid.year = UNSTUFF_BITS(resp, 8, 4) + 1997; | ||
| 453 | break; | ||
| 454 | |||
| 455 | default: | ||
| 456 | printk("%s: card has unknown MMCA version %d\n", | ||
| 457 | mmc_hostname(card->host), card->csd.mmca_vsn); | ||
| 458 | mmc_card_set_bad(card); | ||
| 459 | break; | ||
| 460 | } | ||
| 367 | } | 461 | } |
| 368 | } | 462 | } |
| 369 | 463 | ||
| @@ -376,34 +470,61 @@ static void mmc_decode_csd(struct mmc_card *card) | |||
| 376 | unsigned int e, m, csd_struct; | 470 | unsigned int e, m, csd_struct; |
| 377 | u32 *resp = card->raw_csd; | 471 | u32 *resp = card->raw_csd; |
| 378 | 472 | ||
| 379 | /* | 473 | if (mmc_card_sd(card)) { |
| 380 | * We only understand CSD structure v1.1 and v2. | 474 | csd_struct = UNSTUFF_BITS(resp, 126, 2); |
| 381 | * v2 has extra information in bits 15, 11 and 10. | 475 | if (csd_struct != 0) { |
| 382 | */ | 476 | printk("%s: unrecognised CSD structure version %d\n", |
| 383 | csd_struct = UNSTUFF_BITS(resp, 126, 2); | 477 | mmc_hostname(card->host), csd_struct); |
| 384 | if (csd_struct != 1 && csd_struct != 2) { | ||
