aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre Ossman <drzeus-list@drzeus.cx>2005-09-06 18:18:50 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2005-09-07 19:57:50 -0400
commit335eadf2ef6a1122a720aea98e758e5d431da87d (patch)
treeb20a0c21736cfca40a9df7ab2834b65079469992
parent328b9227865026268261a24a97a578907b280415 (diff)
[PATCH] sd: initialize SD cards
Support for the Secure Digital protocol in the MMC layer. A summary of the legal issues surrounding SD cards, as understood by yours truly: Members of the Secure Digital Association, hereafter SDA, are required to sign a NDA[1] before given access to any specifications. It has been speculated that including an SD implementation would forbid these members to redistribute Linux. This is the basic problem with SD support so it is unclear if it even is a problem since it has no effect on those of us that aren't members. The SDA doesn't seem to enforce these rules though since the patches included here are based on documentation made public by some of the members. The most complete specs[2] are actually released by Sandisk, one of the founding companies of the SDA. Because of this the NDA is considered a non-issue by most involved in the discussions concerning these patches. It might be that the SDA is only interested in protecting the so called "secure" bits of SD, which so far hasn't been found in any public spec. (The card is split into two sections, one "normal" and one "secure" which has an access scheme similar to TPM:s). (As a side note, Microsoft is working to make things easier for us since they want to be able to include the source code for a SD driver in one of their development kits. HP is making sure that the new NDA will allow a Linux implementation. So far only the SDIO specs have been opened up[3]. More will hopefully follow.) [1] http://www.sdcard.org/membership/images/ippolicy.pdf [2] http://www.sandisk.com/pdf/oem/ProdManualSDCardv1.9.pdf [3] http://www.sdcard.org/sdio/Simplified%20SDIO%20Card%20Specification.pdf This patch contains the central parts of the SD support. If no MMC cards are found on a bus then the MMC layer proceeds looking for SD cards. Helper functions are extended to handle the special needs of SD cards. Signed-off-by: Pierre Ossman <drzeus@drzeus.cx> Cc: Russell King <rmk@arm.linux.org.uk> Cc: David Brownell <david-b@pacbell.net> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r--drivers/mmc/mmc.c326
-rw-r--r--include/linux/mmc/card.h3
-rw-r--r--include/linux/mmc/host.h4
-rw-r--r--include/linux/mmc/mmc.h2
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
173EXPORT_SYMBOL(mmc_wait_for_cmd); 173EXPORT_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 */
188int 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
247EXPORT_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;