aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mmc
diff options
context:
space:
mode:
authorGrégory Soutadé <gsoutade@neotion.com>2014-09-15 11:47:06 -0400
committerUlf Hansson <ulf.hansson@linaro.org>2014-09-18 18:03:36 -0400
commitb4493eea4a6561bd9fa57aaa2f7d2b5ea31a1f2e (patch)
treed43c88590a9e930a356c17dbcea3450541b50717 /drivers/mmc
parent87d2163dae1f2388c7ccda5269be8d58e24382dd (diff)
mmc: Move code that manages user area and gp partitions into functions
Move code that manages user area and general purpose partitions into functions. Signed-off-by: Grégory Soutadé <gsoutade@neotion.com> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Diffstat (limited to 'drivers/mmc')
-rw-r--r--drivers/mmc/core/mmc.c162
1 files changed, 89 insertions, 73 deletions
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 69e6273ed228..5b4b969c18bf 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -299,6 +299,93 @@ static void mmc_select_card_type(struct mmc_card *card)
299 card->mmc_avail_type = avail_type; 299 card->mmc_avail_type = avail_type;
300} 300}
301 301
302static void mmc_manage_enhanced_area(struct mmc_card *card, u8 *ext_csd)
303{
304 u8 hc_erase_grp_sz = 0, hc_wp_grp_sz = 0;
305
306 /*
307 * Enhanced area feature support -- check whether the eMMC
308 * card has the Enhanced area enabled. If so, export enhanced
309 * area offset and size to user by adding sysfs interface.
310 */
311 if ((ext_csd[EXT_CSD_PARTITION_SUPPORT] & 0x2) &&
312 (ext_csd[EXT_CSD_PARTITION_ATTRIBUTE] & 0x1)) {
313 hc_erase_grp_sz =
314 ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
315 hc_wp_grp_sz =
316 ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
317
318 card->ext_csd.enhanced_area_en = 1;
319 /*
320 * calculate the enhanced data area offset, in bytes
321 */
322 card->ext_csd.enhanced_area_offset =
323 (ext_csd[139] << 24) + (ext_csd[138] << 16) +
324 (ext_csd[137] << 8) + ext_csd[136];
325 if (mmc_card_blockaddr(card))
326 card->ext_csd.enhanced_area_offset <<= 9;
327 /*
328 * calculate the enhanced data area size, in kilobytes
329 */
330 card->ext_csd.enhanced_area_size =
331 (ext_csd[142] << 16) + (ext_csd[141] << 8) +
332 ext_csd[140];
333 card->ext_csd.enhanced_area_size *=
334 (size_t)(hc_erase_grp_sz * hc_wp_grp_sz);
335 card->ext_csd.enhanced_area_size <<= 9;
336 } else {
337 /*
338 * If the enhanced area is not enabled, disable these
339 * device attributes.
340 */
341 card->ext_csd.enhanced_area_offset = -EINVAL;
342 card->ext_csd.enhanced_area_size = -EINVAL;
343 }
344}
345
346static void mmc_manage_gp_partitions(struct mmc_card *card, u8 *ext_csd)
347{
348 unsigned int part_size;
349 u8 hc_erase_grp_sz = 0, hc_wp_grp_sz = 0;
350 int idx;
351
352 /*
353 * General purpose partition feature support --
354 * If ext_csd has the size of general purpose partitions,
355 * set size, part_cfg, partition name in mmc_part.
356 */
357 if (ext_csd[EXT_CSD_PARTITION_SUPPORT] &
358 EXT_CSD_PART_SUPPORT_PART_EN) {
359 if (card->ext_csd.enhanced_area_en != 1) {
360 hc_erase_grp_sz =
361 ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
362 hc_wp_grp_sz =
363 ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
364
365 card->ext_csd.enhanced_area_en = 1;
366 }
367
368 for (idx = 0; idx < MMC_NUM_GP_PARTITION; idx++) {
369 if (!ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3] &&
370 !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 1] &&
371 !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 2])
372 continue;
373 part_size =
374 (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 2]
375 << 16) +
376 (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 1]
377 << 8) +
378 ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3];
379 part_size *= (size_t)(hc_erase_grp_sz *
380 hc_wp_grp_sz);
381 mmc_part_add(card, part_size << 19,
382 EXT_CSD_PART_CONFIG_ACC_GP0 + idx,
383 "gp%d", idx, false,
384 MMC_BLK_DATA_AREA_GP);
385 }
386 }
387}
388
302/* 389/*
303 * Decode extended CSD. 390 * Decode extended CSD.
304 */ 391 */
@@ -306,7 +393,6 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
306{ 393{
307 int err = 0, idx; 394 int err = 0, idx;
308 unsigned int part_size; 395 unsigned int part_size;
309 u8 hc_erase_grp_sz = 0, hc_wp_grp_sz = 0;
310 396
311 BUG_ON(!card); 397 BUG_ON(!card);
312 398
@@ -403,80 +489,10 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
403 ext_csd[EXT_CSD_TRIM_MULT]; 489 ext_csd[EXT_CSD_TRIM_MULT];
404 card->ext_csd.raw_partition_support = ext_csd[EXT_CSD_PARTITION_SUPPORT]; 490 card->ext_csd.raw_partition_support = ext_csd[EXT_CSD_PARTITION_SUPPORT];
405 if (card->ext_csd.rev >= 4) { 491 if (card->ext_csd.rev >= 4) {
406 /* 492 mmc_manage_enhanced_area(card, ext_csd);
407 * Enhanced area feature support -- check whether the eMMC
408 * card has the Enhanced area enabled. If so, export enhanced
409 * area offset and size to user by adding sysfs interface.
410 */
411 if ((ext_csd[EXT_CSD_PARTITION_SUPPORT] & 0x2) &&
412 (ext_csd[EXT_CSD_PARTITION_ATTRIBUTE] & 0x1)) {
413 hc_erase_grp_sz =
414 ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
415 hc_wp_grp_sz =
416 ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
417 493
418 card->ext_csd.enhanced_area_en = 1; 494 mmc_manage_gp_partitions(card, ext_csd);
419 /*
420 * calculate the enhanced data area offset, in bytes
421 */
422 card->ext_csd.enhanced_area_offset =
423 (ext_csd[139] << 24) + (ext_csd[138] << 16) +
424 (ext_csd[137] << 8) + ext_csd[136];
425 if (mmc_card_blockaddr(card))
426 card->ext_csd.enhanced_area_offset <<= 9;
427 /*
428 * calculate the enhanced data area size, in kilobytes
429 */
430 card->ext_csd.enhanced_area_size =
431 (ext_csd[142] << 16) + (ext_csd[141] << 8) +
432 ext_csd[140];
433 card->ext_csd.enhanced_area_size *=
434 (size_t)(hc_erase_grp_sz * hc_wp_grp_sz);
435 card->ext_csd.enhanced_area_size <<= 9;
436 } else {
437 /*
438 * If the enhanced area is not enabled, disable these
439 * device attributes.
440 */
441 card->ext_csd.enhanced_area_offset = -EINVAL;
442 card->ext_csd.enhanced_area_size = -EINVAL;
443 }
444 495
445 /*
446 * General purpose partition feature support --
447 * If ext_csd has the size of general purpose partitions,
448 * set size, part_cfg, partition name in mmc_part.
449 */
450 if (ext_csd[EXT_CSD_PARTITION_SUPPORT] &
451 EXT_CSD_PART_SUPPORT_PART_EN) {
452 if (card->ext_csd.enhanced_area_en != 1) {
453 hc_erase_grp_sz =
454 ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
455 hc_wp_grp_sz =
456 ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
457
458 card->ext_csd.enhanced_area_en = 1;
459 }
460
461 for (idx = 0; idx < MMC_NUM_GP_PARTITION; idx++) {
462 if (!ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3] &&
463 !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 1] &&
464 !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 2])
465 continue;
466 part_size =
467 (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 2]
468 << 16) +
469 (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 1]
470 << 8) +
471 ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3];
472 part_size *= (size_t)(hc_erase_grp_sz *
473 hc_wp_grp_sz);
474 mmc_part_add(card, part_size << 19,
475 EXT_CSD_PART_CONFIG_ACC_GP0 + idx,
476 "gp%d", idx, false,
477 MMC_BLK_DATA_AREA_GP);
478 }
479 }
480 card->ext_csd.sec_trim_mult = 496 card->ext_csd.sec_trim_mult =
481 ext_csd[EXT_CSD_SEC_TRIM_MULT]; 497 ext_csd[EXT_CSD_SEC_TRIM_MULT];
482 card->ext_csd.sec_erase_mult = 498 card->ext_csd.sec_erase_mult =