Skip to content

Commit 254e175

Browse files
palistorulf
authored andcommitted
mmc: core: Export device/vendor ids from Common CIS for SDIO cards
Device/vendor ids from Common CIS (Card Information Structure) may be different as device/vendor ids from CIS on particular SDIO function. Kernel currently exports only device/vendor ids from SDIO functions and not "main" device/vendor ids from Common CIS. This patch exports "main" device/vendor ids for SDIO and SD combo cards at top level mmc device in sysfs hierarchy. Userspace can use e.g. udev rules to correctly match whole SDIO card based on Common CIS device/vendor id and not only one particular SDIO function. Having this information in userspace also helps developers to debug whole SDIO card as e.g. kernel mmc quirks use device/vendor ids from Common CIS and not from particular SDIO function. Also it allows to write userspace applications which list all connected SDIO cards based on CIS ids. Signed-off-by: Pali Rohár <[email protected]> Reviewed-by: Marek Behún <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ulf Hansson <[email protected]>
1 parent c03ac5e commit 254e175

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

drivers/mmc/core/bus.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ mmc_bus_uevent(struct device *dev, struct kobj_uevent_env *env)
9393
return retval;
9494
}
9595

96+
if (card->type == MMC_TYPE_SDIO || card->type == MMC_TYPE_SD_COMBO) {
97+
retval = add_uevent_var(env, "SDIO_ID=%04X:%04X",
98+
card->cis.vendor, card->cis.device);
99+
if (retval)
100+
return retval;
101+
}
102+
96103
/*
97104
* SDIO (non-combo) cards are not handled by mmc_block driver and do not
98105
* have accessible CID register which used by mmc_card_name() function.

drivers/mmc/core/sd.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,12 @@ static ssize_t mmc_dsr_show(struct device *dev,
707707

708708
static DEVICE_ATTR(dsr, S_IRUGO, mmc_dsr_show, NULL);
709709

710+
MMC_DEV_ATTR(vendor, "0x%04x\n", card->cis.vendor);
711+
MMC_DEV_ATTR(device, "0x%04x\n", card->cis.device);
712+
710713
static struct attribute *sd_std_attrs[] = {
714+
&dev_attr_vendor.attr,
715+
&dev_attr_device.attr,
711716
&dev_attr_cid.attr,
712717
&dev_attr_csd.attr,
713718
&dev_attr_scr.attr,
@@ -726,7 +731,26 @@ static struct attribute *sd_std_attrs[] = {
726731
&dev_attr_dsr.attr,
727732
NULL,
728733
};
729-
ATTRIBUTE_GROUPS(sd_std);
734+
735+
static umode_t sd_std_is_visible(struct kobject *kobj, struct attribute *attr,
736+
int index)
737+
{
738+
struct device *dev = container_of(kobj, struct device, kobj);
739+
struct mmc_card *card = mmc_dev_to_card(dev);
740+
741+
/* CIS vendor and device ids are available only for Combo cards */
742+
if ((attr == &dev_attr_vendor.attr || attr == &dev_attr_device.attr) &&
743+
card->type != MMC_TYPE_SD_COMBO)
744+
return 0;
745+
746+
return attr->mode;
747+
}
748+
749+
static const struct attribute_group sd_std_group = {
750+
.attrs = sd_std_attrs,
751+
.is_visible = sd_std_is_visible,
752+
};
753+
__ATTRIBUTE_GROUPS(sd_std);
730754

731755
struct device_type sd_type = {
732756
.groups = sd_std_groups,

drivers/mmc/core/sdio.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,24 @@
2727
#include "sdio_ops.h"
2828
#include "sdio_cis.h"
2929

30+
MMC_DEV_ATTR(vendor, "0x%04x\n", card->cis.vendor);
31+
MMC_DEV_ATTR(device, "0x%04x\n", card->cis.device);
32+
MMC_DEV_ATTR(ocr, "0x%08x\n", card->ocr);
33+
MMC_DEV_ATTR(rca, "0x%04x\n", card->rca);
34+
35+
static struct attribute *sdio_std_attrs[] = {
36+
&dev_attr_vendor.attr,
37+
&dev_attr_device.attr,
38+
&dev_attr_ocr.attr,
39+
&dev_attr_rca.attr,
40+
NULL,
41+
};
42+
ATTRIBUTE_GROUPS(sdio_std);
43+
44+
static struct device_type sdio_type = {
45+
.groups = sdio_std_groups,
46+
};
47+
3048
static int sdio_read_fbr(struct sdio_func *func)
3149
{
3250
int ret;
@@ -618,7 +636,7 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
618636
/*
619637
* Allocate card structure.
620638
*/
621-
card = mmc_alloc_card(host, NULL);
639+
card = mmc_alloc_card(host, &sdio_type);
622640
if (IS_ERR(card))
623641
return PTR_ERR(card);
624642

0 commit comments

Comments
 (0)