Skip to content

Commit d09bd31

Browse files
Yaojen_Changalex3788
authored andcommitted
[eMMC]Add health and total size node for eMMC
Change-Id: If31a845a44274acb5cc00c82ee738ca2f6dc18f0 Reviewed-on: https://tp-biosrd-v02/gerrit/80974 Reviewed-by: Alex Cheng(鄭富元) <Alex_Cheng@asus.com> Tested-by: Alex Cheng(鄭富元) <Alex_Cheng@asus.com>
1 parent b1c1dd9 commit d09bd31

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

drivers/mmc/core/mmc.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,18 @@ static int mmc_decode_ext_csd(struct mmc_card *card, u8 *ext_csd)
605605
card->ext_csd.device_life_time_est_typ_b =
606606
ext_csd[EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_B];
607607
}
608+
609+
/* eMMC v5.0 or later */
610+
if (card->ext_csd.rev > 6) {
611+
card->ext_csd.health[0] = ext_csd[EXT_CSD_HEALTH + 0];
612+
card->ext_csd.health[1] = ext_csd[EXT_CSD_HEALTH + 1];
613+
card->ext_csd.health[2] = ext_csd[EXT_CSD_HEALTH + 2];
614+
}else{
615+
card->ext_csd.health[0] = 0xff;
616+
card->ext_csd.health[1] = 0xff;
617+
card->ext_csd.health[2] = 0xff;
618+
}
619+
608620
out:
609621
return err;
610622
}
@@ -720,6 +732,19 @@ static int mmc_compare_ext_csds(struct mmc_card *card, unsigned bus_width)
720732
return err;
721733
}
722734

735+
int emmc_total_size(struct mmc_card *card)
736+
{
737+
int i;
738+
i = fls(card->ext_csd.sectors);
739+
if (i > 21) {
740+
/* 4GB or above */
741+
return (int)(card->ext_csd.sectors >> (i - 1)) << (i - 21);
742+
} else {
743+
pr_err("mmc0: wrong sector count\n");
744+
return 0;
745+
}
746+
}
747+
723748
MMC_DEV_ATTR(cid, "%08x%08x%08x%08x\n", card->raw_cid[0], card->raw_cid[1],
724749
card->raw_cid[2], card->raw_cid[3]);
725750
MMC_DEV_ATTR(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1],
@@ -745,6 +770,9 @@ MMC_DEV_ATTR(enhanced_area_size, "%u\n", card->ext_csd.enhanced_area_size);
745770
MMC_DEV_ATTR(raw_rpmb_size_mult, "%#x\n", card->ext_csd.raw_rpmb_size_mult);
746771
MMC_DEV_ATTR(rel_sectors, "%#x\n", card->ext_csd.rel_sectors);
747772
MMC_DEV_ATTR(ocr, "%08x\n", card->ocr);
773+
MMC_DEV_ATTR(total_size, "%d\n", card->ext_csd.sectors / 2);
774+
MMC_DEV_ATTR(emmc_total_size, "%d\n", emmc_total_size(card));
775+
MMC_DEV_ATTR(health,"0x%x 0x%x 0x%x\n",card->ext_csd.health[0],card->ext_csd.health[1],card->ext_csd.health[2]);
748776

749777
static ssize_t mmc_fwrev_show(struct device *dev,
750778
struct device_attribute *attr,
@@ -801,6 +829,9 @@ static struct attribute *mmc_std_attrs[] = {
801829
&dev_attr_rel_sectors.attr,
802830
&dev_attr_ocr.attr,
803831
&dev_attr_dsr.attr,
832+
&dev_attr_total_size.attr,
833+
&dev_attr_emmc_total_size.attr,
834+
&dev_attr_health.attr,
804835
NULL,
805836
};
806837
ATTRIBUTE_GROUPS(mmc_std);

include/linux/mmc/card.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ struct mmc_ext_csd {
123123
u8 device_life_time_est_typ_a; /* 268 */
124124
u8 device_life_time_est_typ_b; /* 269 */
125125

126+
u8 health[3]; /* 267 - 3 bytes */
126127
unsigned int feature_support;
127128
#define MMC_DISCARD_FEATURE BIT(0) /* CMD38 feature */
128129
};

include/linux/mmc/mmc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ struct _mmc_csd {
331331
#define EXT_CSD_CACHE_SIZE 249 /* RO, 4 bytes */
332332
#define EXT_CSD_PWR_CL_DDR_200_360 253 /* RO */
333333
#define EXT_CSD_FIRMWARE_VERSION 254 /* RO, 8 bytes */
334+
#define EXT_CSD_HEALTH 267 /*RO, 3 bytes */
334335
#define EXT_CSD_PRE_EOL_INFO 267 /* RO */
335336
#define EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_A 268 /* RO */
336337
#define EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_B 269 /* RO */

0 commit comments

Comments
 (0)