Implementation for knowing speed_class of inserted SD card from user space
PATCH 1/1 Implementation for knowing speed_class of inserted SD card from user space
Dear All,
The below patch allows an application to know the speed_class of the inserted SD card. Since the MMC cards do not specify speed_class, I'm making the speed_class to indicate as 0xFF. The coding of the speed_class is same as present in the SD Simplified specification.
simplified SD spec:
http://www.sdcard.org/developers/tech/sdcard/pls/Simplified_Physical_Layer_Spec.pdf
See page 65 and 66
SPEED_CLASS
This 8-bit field indicates the Speed Class and the value can be calculated by Pw/2.SPEED_CLASS Value Definition
00h Class 0
01h Class 2
02h Class 4
03h Class 6
04h – FFh Reserved
Table 4-38: Speed Class Code Field
The changes were tested in our platform, which displayed the proper speed_class for inserted SD cards (6 of them were tested) and one MMCMobile card.
The speed_class can be known by looking at sysfs entries at :
/sys/devices/platform/nx_sdiomc.0/mmc_host/mmc0/mmc0:XXXX/speed_class
This file contains the speed class of the SD/MMC card that is
inserted. Please note that, speed_class is not applicable for MMC cards. This file contains a hexadecimal number. Interpretation shall be like as below:0x00 à Class 00x01 à Class 20x02 à Class 40x03 à Class 60x04 to 0xFF à Reserved (currently, for MMC based cards, it is 0xFF)
(where in nx_sdiomc.0 is our platform driver for sdhci)
Let me know if you have any comments/suggestions?
Regards,
Mahadev K Cholachagudda
diff -urNd linux-orig/drivers/mmc/core/mmc.clinux-current/drivers/mmc/core/mmc.c
drivers/mmc/core/mmc.c +8 -0
@@ -258,6 +258,7 @@MMC_DEV_ATTR (name,"%s\n" , card->cid.prod_name);MMC_DEV_ATTR (oemid,"0x%04x\n" , card->cid.oemid);MMC_DEV_ATTR (serial,"0x%08x\n" , card->cid.serial); +MMC_DEV_ATTR (speed_class,"0x%02x\n" , card->speed_class);static struct attribute *mmc_std_attrs[] = { &dev_attr_cid.attr,
@@ -269,6 +270,7 @@ &dev_attr_name.attr, &dev_attr_oemid.attr, &dev_attr_serial.attr, + &dev_attr_speed_class.attr, NULL, };
@@ -454,6 +456,12 @@mmc_set_bus_width (card->host, bus_width); } +/* +* to indicate speed_class reserved, as MMC card do not indicate +* any speed_class +* */ + card->speed_class =0xFF ; +if (!oldcard) host->card = card;
drivers/mmc/core/sd.c +16 -0
@@ -294,6 +294,7 @@MMC_DEV_ATTR (name,"%s\n" , card->cid.prod_name);MMC_DEV_ATTR (oemid,"0x%04x\n" , card->cid.oemid);MMC_DEV_ATTR (serial,"0x%08x\n" , card->cid.serial); +MMC_DEV_ATTR (speed_class,"0x%02x\n" , card->speed_class);static struct attribute *sd_std_attrs[] = {
@@ -307,6 +308,7 @@ &dev_attr_name.attr, &dev_attr_oemid.attr, &dev_attr_serial.attr, + &dev_attr_speed_class.attr, NULL, };
@@ -508,6 +510,20 @@ } } +if (!oldcard) { +/* get the speed class */ +u8 *sd_status; + sd_status =kmalloc (64 ,GFP_KERNEL ); +if (!sd_status) + goto free_card; + + err =mmc_app_sd_status (card, sd_status); + card->speed_class = sd_status[8 ]; +kfree (sd_status); +if (err) + goto free_card; + } +if (!oldcard) host->card = card;
diff -urNd linux-orig/drivers/mmc/core/sd_ops.clinux-current/drivers/mmc/core/sd_ops.c
drivers/mmc/core/sd_ops.c +47 -0
50 lines not on this page · raw message
diff -urNd linux-orig/drivers/mmc/core/sd_ops.hlinux-current/drivers/mmc/core/sd_ops.h
drivers/mmc/core/sd_ops.h +1 -0
@@ -19,6 +19,7 @@int mmc_app_send_scr (struct mmc_card *card,u32 *scr);int mmc_sd_switch (struct mmc_card *card,int mode,int group,u8 value,u8 *resp); +int mmc_app_sd_status (struct mmc_card *card,u8 *sd_status);#endif
diff -urNd linux-orig/include/linux/mmc/card.hlinux-current/include/linux/mmc/card.h
include/linux/mmc/card.h +1 -0
@@ -111,6 +111,7 @@unsigned num_info;/* number of info strings */ const char **info;/* info strings */ struct sdio_func_tuple *tuples;/* unknown common tuples */ +u32 speed_class;/* speed_class for SD cards, for MMC, it is always
reserved */
struct dentry *debugfs_root;
};
Quoted 3 lines · On Wed, 30 Sep 2009 17:22:14 +0530 Mahadev Cholachagudda <[email protected]>…
Let me know if you have any comments/suggestions?
I have a few:
1. The obvious one; why? When does user space need to know the speed rating, and is the speed rating still meaningful after all the layers in the kernel? Userspace ABI stuff should be added with great care.
2. I think it's better to not show the attribute when it isn't relevant rather than return 0xFF.
3. Isn't this a SD 2.0 feature? So you should check the version of the card before populating/showing this field.
Rgds
Signature · 6 lines
-- Pierre Ossman WARNING: This correspondence is being monitored by the Swedish government. Make sure your server uses encryption for SMTP traffic and consider using PGP for end-to-end encryption.