Skip to content

Commit caa30d7

Browse files
committed
Merge branch 'for-next/mmc' into next
2 parents 29f39dc + cd74c16 commit caa30d7

File tree

1 file changed

+108
-27
lines changed

1 file changed

+108
-27
lines changed

drivers/mci/mci-core.c

Lines changed: 108 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -936,15 +936,15 @@ static void mci_set_bus_width(struct mci *mci, enum mci_bus_width width)
936936
/**
937937
* Extract card's version from its CSD
938938
* @param mci MCI instance
939-
* @return 0 on success
940939
*/
941940
static void mci_detect_version_from_csd(struct mci *mci)
942941
{
943942
int version;
944943

945944
if (mci->version == MMC_VERSION_UNKNOWN) {
946-
/* the version is coded in the bits 127:126 (left aligned) */
947-
version = (mci->csd[0] >> 26) & 0xf; /* FIXME why other width? */
945+
/* this should only apply to MMC card, JESD84-B51 defines
946+
* bits 125:122 as SPEC_VER (reserved bits in CSD) */
947+
version = (mci->csd[0] >> 26) & 0xf;
948948

949949
switch (version) {
950950
case 0:
@@ -1070,8 +1070,12 @@ static void mci_extract_block_lengths_from_csd(struct mci *mci)
10701070
{
10711071
mci->read_bl_len = 1 << UNSTUFF_BITS(mci->csd, 80, 4);
10721072

1073+
/* Quoting Physical Layer Simplified Specification Version 9.10:
1074+
* Note that in an SD Memory Card the WRITE_BL_LEN is always
1075+
* equal to READ_BL_LEN.
1076+
*/
10731077
if (IS_SD(mci))
1074-
mci->write_bl_len = mci->read_bl_len; /* FIXME why? */
1078+
mci->write_bl_len = mci->read_bl_len;
10751079
else
10761080
mci->write_bl_len = 1 << ((mci->csd[3] >> 22) & 0xf);
10771081

@@ -1619,7 +1623,7 @@ static int mci_startup(struct mci *mci)
16191623

16201624
/*
16211625
* For MMC cards, set the Relative Address.
1622-
* For SD cards, get the Relatvie Address.
1626+
* For SD cards, get the Relative Address.
16231627
* This also puts the cards into Standby State
16241628
*/
16251629
if (!mmc_host_is_spi(host)) { /* cmd not supported in spi */
@@ -1655,7 +1659,7 @@ static int mci_startup(struct mci *mci)
16551659
mci_extract_block_lengths_from_csd(mci);
16561660
mci_extract_card_dsr_imp_from_csd(mci);
16571661

1658-
/* sanitiy? */
1662+
/* sanity? */
16591663
if (mci->read_bl_len > SECTOR_SIZE) {
16601664
mci->read_bl_len = SECTOR_SIZE;
16611665
dev_dbg(&mci->dev, "Limiting max. read block size down to %u\n",
@@ -1917,33 +1921,78 @@ static unsigned extract_mid(struct mci *mci)
19171921
return UNSTUFF_BITS(mci->cid, 120, 8);
19181922
}
19191923

1924+
/**
1925+
* Extract the CBX from the CID
1926+
* @param mci Instance data
1927+
*
1928+
* The 'CBX' is encoded in bit 113:112 in the CID and only present in MMC cards
1929+
*/
1930+
static unsigned extract_cbx(struct mci *mci)
1931+
{
1932+
return UNSTUFF_BITS(mci->cid, 112, 2);
1933+
}
1934+
19201935
/**
19211936
* Extract the OEM/Application ID from the CID
19221937
* @param mci Instance data
19231938
*
1924-
* The 'OID' is encoded in bit 119:104 in the CID
1939+
* The 'OID' is encoded in bit 119:104 in the CID for SD cards and 111:104 for
1940+
* MMC cards
19251941
*/
1926-
static unsigned extract_oid(struct mci *mci)
1942+
static void extract_oid(struct mci *mci, char oid[static 5])
19271943
{
1928-
return (mci->cid[0] >> 8) & 0xffff;
1944+
if (IS_SD(mci)) {
1945+
// SD cards have a 2 character long OEM ID
1946+
snprintf(oid, 5, "%c%c", UNSTUFF_BITS(mci->cid, 112, 8), UNSTUFF_BITS(mci->cid, 104, 8));
1947+
} else {
1948+
// MMC cards have a 8-bit binary number as OEM ID
1949+
snprintf(oid, 5, "0x%02X", UNSTUFF_BITS(mci->cid, 104, 8));
1950+
}
1951+
}
1952+
1953+
/**
1954+
* Extract the product name from the CID
1955+
* @param mci Instance data
1956+
*
1957+
* The 'PNM' is encoded in bit 103:64 in the CID for SD cards and 103:56 for
1958+
* MMC cards
1959+
*/
1960+
static void extract_pnm(struct mci *mci, char pnm[static 7])
1961+
{
1962+
pnm[0] = UNSTUFF_BITS(mci->cid, 96, 8);
1963+
pnm[1] = UNSTUFF_BITS(mci->cid, 88, 8);
1964+
pnm[2] = UNSTUFF_BITS(mci->cid, 80, 8);
1965+
pnm[3] = UNSTUFF_BITS(mci->cid, 72, 8);
1966+
pnm[4] = UNSTUFF_BITS(mci->cid, 64, 8);
1967+
1968+
if (IS_SD(mci)) {
1969+
// SD cards have a 5 character long product name
1970+
pnm[5] = '\0';
1971+
} else {
1972+
// MMC cards have a 6 character long product name
1973+
pnm[5] = UNSTUFF_BITS(mci->cid, 56, 8);
1974+
pnm[6] = '\0';
1975+
}
19291976
}
19301977

19311978
/**
19321979
* Extract the product revision from the CID
19331980
* @param mci Instance data
19341981
*
1935-
* The 'PRV' is encoded in bit 63:56 in the CID
1982+
* The 'PRV' is encoded in bit 63:56 in the CID for SD cards and 55:48 for MMC cards
19361983
*/
1937-
static unsigned extract_prv(struct mci *mci)
1984+
static void extract_prv(struct mci *mci, char prv[static 8])
19381985
{
1939-
return mci->cid[2] >> 24;
1986+
unsigned prv_bcd = IS_SD(mci) ? UNSTUFF_BITS(mci->cid, 56, 8) : UNSTUFF_BITS(mci->cid, 48, 8);
1987+
1988+
snprintf(prv, 8,"%u.%u", prv_bcd >> 4, prv_bcd & 0xf);
19401989
}
19411990

19421991
/**
19431992
* Extract the product serial number from the CID
19441993
* @param mci Instance data
19451994
*
1946-
* The 'PSN' is encoded in bit 55:24 in the CID
1995+
* The 'PSN' is encoded in bit 55:24 in the CID for SD cards and 47:16 for MMC cards
19471996
*/
19481997
static unsigned extract_psn(struct mci *mci)
19491998
{
@@ -1962,9 +2011,9 @@ static unsigned extract_psn(struct mci *mci)
19622011
* Extract the month of the manufacturing date from the CID
19632012
* @param mci Instance data
19642013
*
1965-
* The 'MTD' is encoded in bit 19:8 in the CID, month in 11:8
2014+
* The 'MDT' is encoded in bit 19:8 in the CID, month in 11:8
19662015
*/
1967-
static unsigned extract_mtd_month(struct mci *mci)
2016+
static unsigned extract_mdt_month(struct mci *mci)
19682017
{
19692018
if (IS_SD(mci))
19702019
return UNSTUFF_BITS(mci->cid, 8, 4);
@@ -1976,10 +2025,10 @@ static unsigned extract_mtd_month(struct mci *mci)
19762025
* Extract the year of the manufacturing date from the CID
19772026
* @param mci Instance data
19782027
*
1979-
* The 'MTD' is encoded in bit 19:8 in the CID, year in 19:12
2028+
* The 'MDT' is encoded in bit 19:8 in the CID, year in 19:12
19802029
* An encoded 0 means the year 2000
19812030
*/
1982-
static unsigned extract_mtd_year(struct mci *mci)
2031+
static unsigned extract_mdt_year(struct mci *mci)
19832032
{
19842033
unsigned year;
19852034
if (IS_SD(mci))
@@ -1994,6 +2043,20 @@ static unsigned extract_mtd_year(struct mci *mci)
19942043
return year;
19952044
}
19962045

2046+
/**
2047+
* Extract the manufacturing date from the CID
2048+
* @param mci Instance data
2049+
*
2050+
* The 'MDT' is encoded in bit 19:8 in the CID
2051+
*/
2052+
static void extract_mdt(struct mci *mci, char mdt[static 8])
2053+
{
2054+
unsigned month = extract_mdt_month(mci);
2055+
unsigned year = extract_mdt_year(mci);
2056+
2057+
snprintf(mdt, 8, "%u.%u", year, month);
2058+
}
2059+
19972060
static const char *mci_timing_tostr(unsigned timing)
19982061
{
19992062
switch (timing) {
@@ -2069,16 +2132,32 @@ static void mci_info(struct device *dev)
20692132
mci->csd[2], mci->csd[3]);
20702133
printf(" Max. transfer speed: %u Hz\n", mci->tran_speed);
20712134
mci_print_caps(mci->card_caps);
2072-
printf(" Manufacturer ID: 0x%02X\n", extract_mid(mci));
2073-
printf(" OEM/Application ID: 0x%04X\n", extract_oid(mci));
2074-
printf(" Product name: '%c%c%c%c%c'\n", mci->cid[0] & 0xff,
2075-
(mci->cid[1] >> 24), (mci->cid[1] >> 16) & 0xff,
2076-
(mci->cid[1] >> 8) & 0xff, mci->cid[1] & 0xff);
2077-
printf(" Product revision: %u.%u\n", extract_prv(mci) >> 4,
2078-
extract_prv(mci) & 0xf);
2079-
printf(" Serial no: %0u\n", extract_psn(mci));
2080-
printf(" Manufacturing date: %u.%u\n", extract_mtd_month(mci),
2081-
extract_mtd_year(mci));
2135+
printf(" Manufacturer ID: %s\n", dev_get_param(dev, "cid_mid"));
2136+
printf(" OEM/Application ID: %s\n", dev_get_param(dev, "cid_oid"));
2137+
if (!IS_SD(mci))
2138+
printf(" CBX: %s\n", dev_get_param(dev, "cid_cbx"));
2139+
printf(" Product name: '%s'\n", dev_get_param(dev, "cid_pnm"));
2140+
printf(" Product revision: %s\n", dev_get_param(dev, "cid_prv"));
2141+
printf(" Serial no: %s\n", dev_get_param(dev, "cid_psn"));
2142+
printf(" Manufacturing date: %s\n", dev_get_param(dev, "cid_mdt"));
2143+
}
2144+
2145+
static void mci_parse_cid(struct mci *mci) {
2146+
struct device *dev = &mci->dev;
2147+
char buffer[8];
2148+
2149+
dev_add_param_uint32_fixed(dev, "cid_mid", extract_mid(mci), "0x%02X");
2150+
extract_oid(mci, buffer);
2151+
dev_add_param_string_fixed(dev, "cid_oid", buffer);
2152+
if (!IS_SD(mci))
2153+
dev_add_param_uint32_fixed(dev, "cid_cbx", extract_cbx(mci), "%u");
2154+
extract_pnm(mci, buffer);
2155+
dev_add_param_string_fixed(dev, "cid_pnm", buffer);
2156+
extract_prv(mci, buffer);
2157+
dev_add_param_string_fixed(dev, "cid_prv", buffer);
2158+
dev_add_param_uint32_fixed(dev, "cid_psn", extract_psn(mci), "%0u");
2159+
extract_mdt(mci, buffer);
2160+
dev_add_param_string_fixed(dev, "cid_mdt", buffer);
20822161
}
20832162

20842163
/**
@@ -2356,6 +2435,8 @@ static int mci_card_probe(struct mci *mci)
23562435
dev_add_param_bool_fixed(&mci->dev, "partitioning_completed", ret);
23572436
}
23582437

2438+
mci_parse_cid(mci);
2439+
23592440
dev_dbg(&mci->dev, "SD Card successfully added\n");
23602441

23612442
on_error:

0 commit comments

Comments
 (0)