Preparations to support SD UHS-II cards
v4 cover Preparations to support SD UHS-II cards
Series [1] that has been posted by Ulf Hansson which provided some
guidance and an overall structure.
Series [2] focused on UHS-II card control side to address Ulf's intention
regarding to "modularising" sd_uhs2.c.
Series [3] is based on series [2] and adopt most of Ulf's comments.
Series [4] is based on series [3] and refined by Ulf Hanssion.
This series is the successor version of post [4], which is base on Ulf's
"wip_uhs_v3" branch:
1. Implement call back functions in sd_uhs2_ops.
2. Adopt Ulf's comments for V3.
[1]
https://patchwork.kernel.org/project/linux-mmc/list/?series=438509
[2]
https://patchwork.kernel.org/project/linux-mmc/list/?series=589827
[3]
https://patchwork.kernel.org/project/linux-mmc/list/?series=606241
[4]
https://git.kernel.org/pub/scm/linux/kernel/git/ulfh/mmc.git/log/?h=wip_uhs_v3
Jason Lai (2):
mmc: core: Add definitions for SD UHS-II cards mmc:core: Support UHS-II card control and access
Ulf Hansson (4):
mmc: core: Cleanup printing of speed mode at card insertion
mmc: core: Prepare to support SD UHS-II cards
mmc: core: Announce successful insertion of an SD UHS-II card
mmc: core: Extend support for mmc regulators with a vqmmc2
drivers/mmc/core/Makefile | 2 +- drivers/mmc/core/block.c | 5 +- drivers/mmc/core/bus.c | 38 +- drivers/mmc/core/core.c | 33 +- drivers/mmc/core/core.h | 1 + drivers/mmc/core/host.h | 4 + drivers/mmc/core/mmc_ops.c | 24 +- drivers/mmc/core/mmc_ops.h | 1 + drivers/mmc/core/regulator.c | 34 + drivers/mmc/core/sd.c | 11 +- drivers/mmc/core/sd.h | 3 + drivers/mmc/core/sd_ops.c | 9 + drivers/mmc/core/sd_ops.h | 3 + drivers/mmc/core/sd_uhs2.c | 1377 ++++++++++++++++++++++++++++++++++ include/linux/mmc/card.h | 47 ++ include/linux/mmc/core.h | 13 + include/linux/mmc/host.h | 83 ++ include/linux/mmc/sd_uhs2.h | 263 +++++++ 18 files changed, 1916 insertions(+), 35 deletions(-) create mode 100644 drivers/mmc/core/sd_uhs2.c create mode 100644 include/linux/mmc/sd_uhs2.h
Signature · 1 line
2.35.1
PATCH v4 1/6 mmc: core: Cleanup printing of speed mode at card insertion
From: Ulf Hansson <[email protected]>
The current print of the bus speed mode in mmc_add_card() has grown over the years and is now difficult to parse. Let's clean up the code and also take the opportunity to properly announce "DDR" for eMMCs as "high speed DDR", which is according to the eMMC spec.
--- drivers/mmc/core/bus.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-)
drivers/mmc/core/bus.c +20 -16
@@ -299,6 +299,7 @@ int mmc_add_card(struct mmc_card *card) {int ret;const char *type; +const char *speed_mode ="" ;const char *uhs_bus_speed_mode ="" ;static const char *const uhs_speeds[] = { [UHS_SDR12_BUS_SPEED ] ="SDR12 " ,
@@ -337,27 +338,30 @@ int mmc_add_card(struct mmc_card *card)break ; } +if (mmc_card_hs (card)) + speed_mode ="high speed " ; +else if (mmc_card_uhs (card)) + speed_mode ="ultra high speed " ; +else if (mmc_card_ddr52 (card)) + speed_mode ="high speed DDR " ; +else if (mmc_card_hs200 (card)) + speed_mode ="HS200 " ; +else if (mmc_card_hs400es (card)) + speed_mode ="HS400 Enhanced strobe " ; +else if (mmc_card_hs400 (card)) + speed_mode ="HS400 " ; +if (mmc_card_uhs (card) && (card->sd_bus_speed <ARRAY_SIZE (uhs_speeds))) uhs_bus_speed_mode = uhs_speeds[card->sd_bus_speed]; -if (mmc_host_is_spi (card->host)) { -pr_info ("%s: new %s%s%s card on SPI\n" , -mmc_hostname (card->host), -mmc_card_hs (card) ?"high speed " :"" , -mmc_card_ddr52 (card) ?"DDR " :"" , - type); - }else { -pr_info ("%s: new %s%s%s%s%s%s card at address %04x\n" , -mmc_hostname (card->host), -mmc_card_uhs (card) ?"ultra high speed " : - (mmc_card_hs (card) ?"high speed " :"" ), -mmc_card_hs400 (card) ?"HS400 " : - (mmc_card_hs200 (card) ?"HS200 " :"" ), -mmc_card_hs400es (card) ?"Enhanced strobe " :"" , -mmc_card_ddr52 (card) ?"DDR " :"" , +if (mmc_host_is_spi (card->host)) +pr_info ("%s: new %s%s card on SPI\n" , +mmc_hostname (card->host), speed_mode, type); +else +pr_info ("%s: new %s%s%s card at address %04x\n" , +mmc_hostname (card->host), speed_mode, uhs_bus_speed_mode, type, card->rca); - }#ifdef CONFIG_DEBUG_FS mmc_add_card_debugfs (card);
Signature · 1 line
2.35.1
PATCH v4 2/6 mmc: core: Prepare to support SD UHS-II cards
In reply to Jason LaiFrom: Ulf Hansson <[email protected]>
Updates in V4:
- Re-based, updated a comment and removed white-space.
- Moved MMC_VQMMC2_VOLTAGE_180 into a later patch in the series.
Update in previous version:
The SD UHS-II interface was introduced to the SD spec v4.00 several years ago. The interface is fundamentally different from an electrical and a protocol point of view, comparing to the legacy SD interface.
However, the legacy SD protocol is supported through a specific transport layer (SD-TRAN) defined in the UHS-II addendum of the spec. This allows the SD card to be managed in a very similar way as a legacy SD card, hence a lot of code can be re-used to support these new types of cards through the mmc subsystem.
Moreover, an SD card that supports the UHS-II interface shall also be backwards compatible with the legacy SD interface, which allows a UHS-II card to be inserted into a legacy slot. As a matter of fact, this is already supported by mmc subsystem as of today.
To prepare to add support for UHS-II, this change puts the basic foundation in the mmc core in place, allowing it to be more easily reviewed before subsequent changes implements the actual support.
Basically, the approach here adds a new UHS-II bus_ops type and adds a separate initialization path for the UHS-II card. The intent is to avoid us from sprinkling the legacy initialization path, but also to simplify implementation of the UHS-II specific bits.
At this point, there is only one new host ops added to manage the various ios settings needed for UHS-II. Additional host ops that are needed, are being added from subsequent changes.
--- drivers/mmc/core/Makefile | 2 +- drivers/mmc/core/core.c | 17 ++- drivers/mmc/core/core.h | 1 + drivers/mmc/core/sd_uhs2.c | 289 +++++++++++++++++++++++++++++++++++++ include/linux/mmc/card.h | 7 + include/linux/mmc/host.h | 19 +++ 6 files changed, 333 insertions(+), 2 deletions(-) create mode 100644 drivers/mmc/core/sd_uhs2.c
drivers/mmc/core/Makefile +1 -1
@@ -7,7 +7,7 @@ obj-$(CONFIG_MMC) += mmc_core.o mmc_core-y := core.o bus.o host.o \ mmc.o mmc_ops.o sd.o sd_ops.o \ sdio.o sdio_ops.o sdio_bus.o \ - sdio_cis.o sdio_io.o sdio_irq.o \ + sdio_cis.o sdio_io.o sdio_irq.o sd_uhs2.o\ slot-gpio.o regulator.o mmc_core-$(CONFIG_OF) += pwrseq.o obj-$(CONFIG_PWRSEQ_SIMPLE) += pwrseq_simple.o
drivers/mmc/core/core.c +16 -1
@@ -2230,6 +2230,18 @@ void mmc_rescan(struct work_struct *work) goto out; } +/* +* Ideally we should favor initialization of legacy SD cards and defer +* UHS-II enumeration. However, it seems like cards doesn't reliably +* announce their support for UHS-II in the response to the ACMD41, +* while initializing the legacy SD interface. Therefore, let's start +* with UHS-II for now. +*/ +if (!mmc_attach_sd_uhs2 (host)) { +mmc_release_host (host); + goto out; + } +for (i =0 ; i <ARRAY_SIZE (freqs); i++) {unsigned int freq = freqs[i];if (freq > host->f_max) {
@@ -2251,10 +2263,13 @@ void mmc_rescan(struct work_struct *work)void mmc_start_host (struct mmc_host *host) { +bool power_up = !(host->caps2 & + (MMC_CAP2_NO_PRESCAN_POWERUP |MMC_CAP2_SD_UHS2 )); + host->f_init =max (min (freqs[0 ], host->f_max), host->f_min); host->rescan_disable =0 ; -if (!(host->caps2 &MMC_CAP2_NO_PRESCAN_POWERUP )) { +if (power_up) {mmc_claim_host (host);mmc_power_up (host, host->ocr_avail);mmc_release_host (host);
drivers/mmc/core/core.h +1 -0
@@ -81,6 +81,7 @@ int mmc_detect_card_removed(struct mmc_host *host);int mmc_attach_mmc (struct mmc_host *host);int mmc_attach_sd (struct mmc_host *host);int mmc_attach_sdio (struct mmc_host *host); +int mmc_attach_sd_uhs2 (struct mmc_host *host);/* Module parameters */ extern bool use_spi_crc;
drivers/mmc/core/sd_uhs2.c new file +289 -0
289 lines not on this page · raw message
include/linux/mmc/card.h +7 -0
@@ -211,6 +211,11 @@ struct sd_ext_reg {#define SD_EXT_PERF_CMD_QUEUE (1<<4) }; +struct sd_uhs2_config { +u32 node_id; +/* TODO: Extend with more register configs. */ +}; +struct sdio_cccr {unsigned int sdio_vsn;unsigned int sd_vsn;
@@ -315,6 +320,8 @@ struct mmc_card {struct sd_ext_reg ext_power;/* SD extension reg for PM */ struct sd_ext_reg ext_perf;/* SD extension reg for PERF */ +struct sd_uhs2_config uhs2_config;/* SD UHS-II config */ +unsigned int sdio_funcs;/* number of SDIO functions */ atomic_t sdio_funcs_probed;/* number of probed SDIO funcs */ struct sdio_cccr cccr;/* common card info */
include/linux/mmc/host.h +19 -0
@@ -63,6 +63,7 @@ struct mmc_ios {#define MMC_TIMING_MMC_HS400 10#define MMC_TIMING_SD_EXP 11#define MMC_TIMING_SD_EXP_1_2V 12 +#define MMC_TIMING_SD_UHS2 13unsigned char signal_voltage;/* signalling voltage (1.8V or 3.3V) */
@@ -91,6 +92,10 @@ struct mmc_clk_phase_map {struct mmc_clk_phase phase[MMC_NUM_CLK_PHASES ]; }; +struct sd_uhs2_caps { +/* TODO: Add UHS-II capabilities for the host. */ +}; +struct mmc_host ;struct mmc_host_ops {
@@ -126,6 +131,17 @@ struct mmc_host_ops {*/ void (*set_ios)(struct mmc_host *host,struct mmc_ios *ios); +/* +* The uhs2_set_ios callback is mandatory to implement for hosts that +* supports the SD UHS-II interface (MMC_CAP2_SD_UHS2), while the +* callback is unused for the other cases. Note that, the struct +* mmc_ios is being re-used for this as well. +* +* Expected return values for the uhs2_set_ios callback are a negative +* errno in case of a failure or zero for success. +*/ +int (*uhs2_set_ios)(struct mmc_host *host,struct mmc_ios *ios); +/* * Return values for the get_ro callback should be: * 0 for a read/write card
@@ -377,6 +393,7 @@ struct mmc_host { MMC_CAP2_HS200_1_2V_SDR)#define MMC_CAP2_SD_EXP (1 << 7)/* SD express via PCIe */ #define MMC_CAP2_SD_EXP_1_2V (1 << 8)/* SD express 1.2V */ +#define MMC_CAP2_SD_UHS2 (1 << 9)/* SD UHS-II support */ #define MMC_CAP2_CD_ACTIVE_HIGH (1 << 10)/* Card-detect signal active high */ #define MMC_CAP2_RO_ACTIVE_HIGH (1 << 11)/* Write-protect signal active high */ #define MMC_CAP2_NO_PRESCAN_POWERUP (1 << 14)/* Don't power up before scan */
@@ -403,6 +420,8 @@ struct mmc_host {#endif #define MMC_CAP2_ALT_GPT_TEGRA (1 << 28)/* Host with eMMC that has GPT entry at a non-standard location */ +struct sd_uhs2_caps uhs2_caps;/* Host UHS-II capabilities */ +int fixed_drv_type;/* fixed driver type for non-removable media */ mmc_pm_flag_t pm_caps;/* supported pm features */
Signature · 1 line
2.35.1
PATCH v4 3/6 mmc: core: Announce successful insertion of an SD UHS-II card
In reply to Jason LaiFrom: Ulf Hansson <[email protected]>
Updates in V4:
- Make mmc_card_uhs2() take struct mmc_host* as in-param.
Update in previous version:
To inform the users about SD UHS-II cards, let's extend the print at card insertion with a "UHS-II" substring. Within this change, it seems reasonable to convert from using "ultra high speed" into "UHS-I speed", for the UHS-I type, as it should makes it more clear.
Note that, the new print for UHS-II cards doesn't include the actual selected speed mode. Instead, this is going to be added from subsequent change.
--- drivers/mmc/core/bus.c | 4 +++- drivers/mmc/core/host.h | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-)
drivers/mmc/core/bus.c +3 -1
@@ -341,7 +341,9 @@ int mmc_add_card(struct mmc_card *card)if (mmc_card_hs (card)) speed_mode ="high speed " ;else if (mmc_card_uhs (card)) - speed_mode ="ultra high speed " ; + speed_mode ="UHS-I speed " ; +else if (mmc_card_uhs2 (card->host)) + speed_mode ="UHS-II speed " ;else if (mmc_card_ddr52 (card)) speed_mode ="high speed DDR " ;else if (mmc_card_hs200 (card))
drivers/mmc/core/host.h +4 -0
@@ -89,5 +89,9 @@ static inline bool mmc_card_sd_express(struct mmc_host *host) host->ios.timing == MMC_TIMING_SD_EXP_1_2V; } +static inline bool mmc_card_uhs2 (struct mmc_host *host) +{ +return host->ios.timing ==MMC_TIMING_SD_UHS2 ; +}#endif
Signature · 1 line
2.35.1
PATCH v4 4/6 mmc: core: Extend support for mmc regulators with a vqmmc2
In reply to Jason LaiFrom: Ulf Hansson <[email protected]>
Updates in V4:
- Moved the voltage defines into this patch.
Update in previous version:
To allow an additional external regulator to be controlled by an mmc host driver, let's add support for a vqmmc2 regulator to the mmc core.
For an SD UHS-II interface the vqmmc2 regulator may correspond to the so called vdd2 supply, as described by the SD spec. Initially, only 1.8V is needed, hence limit the new helper function, mmc_regulator_set_vqmmc2() to this too.
Note that, to allow for flexibility mmc host drivers need to manage the enable/disable of the vqmmc2 regulator themselves, while the regulator is looked up through the common mmc_regulator_get_supply().
--- drivers/mmc/core/regulator.c | 34 ++++++++++++++++++++++++++++++++++ include/linux/mmc/host.h | 11 +++++++++++ 2 files changed, 45 insertions(+)
drivers/mmc/core/regulator.c +34 -0
@@ -223,6 +223,33 @@ int mmc_regulator_set_vqmmc(struct mmc_host *mmc, struct mmc_ios *ios) }EXPORT_SYMBOL_GPL (mmc_regulator_set_vqmmc); +/** +* mmc_regulator_set_vqmmc2 - Set vqmmc2 as per the ios->vqmmc2_voltage +* @mmc: The mmc host to regulate +* @ios: The io bus settings +* +* Sets a new voltage level for the vqmmc2 regulator, which may correspond to +* the vdd2 regulator for an SD UHS-II interface. This function is expected to +* be called by mmc host drivers. +* +* Returns a negative error code on failure, zero if the voltage level was +* changed successfully or a positive value if the level didn't need to change. +*/ +int mmc_regulator_set_vqmmc2 (struct mmc_host *mmc,struct mmc_ios *ios) +{ +if (IS_ERR (mmc->supply.vqmmc2)) +return -EINVAL ; + +switch (ios->vqmmc2_voltage) { +case MMC_VQMMC2_VOLTAGE_180 : +return mmc_regulator_set_voltage_if_supported ( + mmc->supply.vqmmc2,1700000 ,1800000 ,1950000 ); +default : +return -EINVAL ; + } +} +EXPORT_SYMBOL_GPL (mmc_regulator_set_vqmmc2); +#else static inline int mmc_regulator_get_ocrmask (struct regulator *supply)
@@ -249,6 +276,7 @@ int mmc_regulator_get_supply(struct mmc_host *mmc) mmc->supply.vmmc =devm_regulator_get_optional (dev,"vmmc" ); mmc->supply.vqmmc =devm_regulator_get_optional (dev,"vqmmc" ); + mmc->supply.vqmmc2 =devm_regulator_get_optional (dev,"vqmmc2" );if (IS_ERR (mmc->supply.vmmc)) {if (PTR_ERR (mmc->supply.vmmc) == -EPROBE_DEFER )
@@ -268,6 +296,12 @@ int mmc_regulator_get_supply(struct mmc_host *mmc)dev_dbg (dev,"No vqmmc regulator found\n" ); } +if (IS_ERR (mmc->supply.vqmmc2)) { +if (PTR_ERR (mmc->supply.vqmmc2) == -EPROBE_DEFER ) +return -EPROBE_DEFER ; +dev_dbg (dev,"No vqmmc2 regulator found\n" ); + } +return 0 ; }EXPORT_SYMBOL_GPL (mmc_regulator_get_supply);
include/linux/mmc/host.h +11 -0
@@ -71,6 +71,9 @@ struct mmc_ios {#define MMC_SIGNAL_VOLTAGE_180 1#define MMC_SIGNAL_VOLTAGE_120 2 +unsigned char vqmmc2_voltage; +#define MMC_VQMMC2_VOLTAGE_180 0 +unsigned char drv_type;/* driver type (A, B, C, D) */ #define MMC_SET_DRIVER_TYPE_B 0
@@ -302,6 +305,7 @@ struct mmc_pwrseq;struct mmc_supply {struct regulator *vmmc;/* Card power supply */ struct regulator *vqmmc;/* Optional Vccq supply */ +struct regulator *vqmmc2;/* Optional supply for phy */ };struct mmc_ctx {
@@ -580,6 +584,7 @@ int mmc_regulator_set_ocr(struct mmc_host *mmc,struct regulator *supply, unsigned short vdd_bit);int mmc_regulator_set_vqmmc (struct mmc_host *mmc,struct mmc_ios *ios); +int mmc_regulator_set_vqmmc2 (struct mmc_host *mmc,struct mmc_ios *ios);#else static inline int mmc_regulator_set_ocr(struct mmc_host *mmc, struct regulator *supply,
@@ -593,6 +598,12 @@ static inline int mmc_regulator_set_vqmmc(struct mmc_host *mmc, {return -EINVAL ; } + +static inline int mmc_regulator_set_vqmmc2 (struct mmc_host *mmc, +struct mmc_ios *ios) +{ +return -EINVAL ; +}#endif int mmc_regulator_get_supply (struct mmc_host *mmc);
Signature · 1 line
2.35.1
PATCH v4 5/6 mmc: core: Add definitions for SD UHS-II cards
In reply to Jason LaiFrom: Jason Lai <[email protected]>
Add UHS-II specific data structures for commands and defines for registers, as described in Part 1 UHS-II Addendum Version 1.01.
UHS-II related definitions are listed below:
1. UHS-II card capability: sd_uhs2_caps{}
2. UHS-II configuration: sd_uhs2_config{}
3. UHS-II Command structure: uhs2_command{}
4. UHS-II register I/O address and register field definitions: sd_uhs2.h
--- include/linux/mmc/card.h | 42 +++++- include/linux/mmc/core.h | 13 ++ include/linux/mmc/host.h | 55 +++++++- include/linux/mmc/sd_uhs2.h | 263 ++++++++++++++++++++++++++++++++++++ 4 files changed, 371 insertions(+), 2 deletions(-) create mode 100644 include/linux/mmc/sd_uhs2.h
include/linux/mmc/card.h +41 -1
@@ -190,6 +190,13 @@ struct sd_switch_caps {#define SD_MAX_CURRENT_400 (1 << SD_SET_CURRENT_LIMIT_400)#define SD_MAX_CURRENT_600 (1 << SD_SET_CURRENT_LIMIT_600)#define SD_MAX_CURRENT_800 (1 << SD_SET_CURRENT_LIMIT_800) +unsigned int sd4_curr_limit; +#define SD4_SET_POWER_LIMIT_0_72W 0 +#define SD4_SET_POWER_LIMIT_1_44W 1 +#define SD4_SET_POWER_LIMIT_2_16W 2 +#define SD4_SET_POWER_LIMIT_2_88W 3 +#define SD4_SET_POWER_LIMIT_1_80W 4 +#define SD4_SET_POWER_NO_CHANGE (-1) };struct sd_ext_reg {
@@ -213,7 +220,35 @@ struct sd_ext_reg {struct sd_uhs2_config {u32 node_id; -/* TODO: Extend with more register configs. */ + +u32 dap; +u32 gap; +u32 n_fcu; +u32 maxblk_len; +u8 n_lanes; +u8 dadr_len; +u8 app_type; +u8 phy_minor_rev; +u8 phy_major_rev; +u8 can_hibernate; +u8 n_lss_sync; +u8 n_lss_dir; +u8 link_minor_rev; +u8 link_major_rev; +u8 dev_type; +u8 n_data_gap; + +u32 n_fcu_set; +u32 maxblk_len_set; +u8 n_lanes_set; +u8 speed_range_set; +u8 n_lss_sync_set; +u8 n_lss_dir_set; +u8 n_data_gap_set; +u8 pwrctrl_mode_set; +u8 max_retry_set; + +u8 cfg_complete; };struct sdio_cccr {
@@ -321,6 +356,9 @@ struct mmc_card {struct sd_ext_reg ext_perf;/* SD extension reg for PERF */ struct sd_uhs2_config uhs2_config;/* SD UHS-II config */ +u8 uhs2_state;/* SD UHS-II states */ +#define MMC_UHS2_INITIALIZED BIT(1) +#define MMC_UHS2_SPEED_B BIT(2)unsigned int sdio_funcs;/* number of SDIO functions */ atomic_t sdio_funcs_probed;/* number of probed SDIO funcs */
@@ -356,4 +394,6 @@ bool mmc_card_is_blockaddr(struct mmc_card *card);#define mmc_card_sd (c) ((c)->type == MMC_TYPE_SD)#define mmc_card_sdio (c) ((c)->type == MMC_TYPE_SDIO) +#define mmc_card_can_poweroff_notify (c) ((c)->ext_power.feature_support & SD_EXT_POWER_OFF_NOTIFY) +#endif /* LINUX_MMC_CARD_H */
include/linux/mmc/core.h +13 -0
@@ -23,6 +23,14 @@ enum mmc_blk_status { MMC_BLK_NEW_REQUEST, }; +struct uhs2_command { +u16 header; +u16 arg; +__be32 *payload; +u32 payload_len; +u32 packet_len; +}; +struct mmc_command {u32 opcode;u32 arg;
@@ -109,6 +117,11 @@ struct mmc_command {unsigned int busy_timeout;/* busy detect timeout in ms */ struct mmc_data *data;/* data segment associated with cmd */ struct mmc_request *mrq;/* associated request */ + +struct uhs2_command *uhs2_cmd;/* UHS2 command */ +u8 *uhs2_resp;/* UHS2 native cmd resp */ +u8 uhs2_resp_len;/* UHS2 native cmd resp len */ +u8 uhs2_tmode0_flag;/* UHS2 transfer mode flag */ };struct mmc_data {
include/linux/mmc/host.h +54 -1
77 lines not on this page · raw message
include/linux/mmc/sd_uhs2.h new file +263 -0
263 lines not on this page · raw message
Signature · 1 line
2.35.1
PATCH v4 6/6 mmc: core: Support UHS-II card control and access
In reply to Jason LaiFrom: Jason Lai <[email protected]>
Update in V4:
1. Rename sd_uhs2_prepare_cmd() into mmc_uhs2_prepare_cmd().
2. Rename ->uhs2_host_operation() into ->uhs2_control().
3. Declare ->uhs2_set_ios() which should be implemented in
mmc/host/sdhci-uhs2.c.
4. Implement call back functions in sd_uhs2_ops.
5. Replace variables which are used as constant with constant
definition.
6. Change data type of uhs2_cmd->payload from u32 to __be32 because of
the use of cpu_to_be32(). 7. Add comments to explain format of UHS-II CMD Header and Argument.
8. Add comments to explain format of UHS-II CMD response.
9. Remove unnecessary debug info.
10. Use sd_uhs2_select_voltage() to replace mmc_select_voltage().
11. Use __mmc_poll_for_busy() to replace while loop.
12. Add processing of uhs2_cmd when starting request.
13. Use macro 'mmc_card_can_poweroff_notify' to replace function "sd_can_poweroff_notify()" and put it to include/linux/mmc/card.h.
14. Embed UHS-II access functionality into the MMC request processing flow.
Update in V3:
UHS-II card initialization flow is divided into 2 categories: PHY & Card. Part 1 - PHY Initialization:
Every host controller may need their own avtivation operation to establish LINK between controller and card. So we add a new member function(uhs2_detect_init) in struct mmc_host_ops for host controller use.
Part 2 - Card Initialization:
This part can be divided into 6 substeps.
1. Send UHS-II CCMD DEVICE_INIT to card.
2. Send UHS-II CCMD ENUMERATE to card.
3. Send UHS-II Native Read CCMD to obtain capabilities in CFG_REG of card.
4. Host compares capabilities of host controller and card, then write the negotiated values to Setting field in CFG_REG of card through UHS-II Native Write CCMD.
5. Switch host controller's clock to Range B if it is supported by both host controller and card.
6. Execute legacy SD initialization flow.
Part 3 - Provide a function to tranaform legacy SD command packet into
UHS-II SD-TRAN DCMD packet.
Most of the code added above came from Intel's original patch[5].
[5]
https://patchwork.kernel.org/project/linux-mmc/patch/1419672479-30852-2-
[email protected]/
--- drivers/mmc/core/block.c | 5 +- drivers/mmc/core/core.c | 16 + drivers/mmc/core/mmc_ops.c | 24 +- drivers/mmc/core/mmc_ops.h | 1 + drivers/mmc/core/sd.c | 11 +- drivers/mmc/core/sd.h | 3 + drivers/mmc/core/sd_ops.c | 9 + drivers/mmc/core/sd_ops.h | 3 + drivers/mmc/core/sd_uhs2.c | 1146 +++++++++++++++++++++++++++++++++++- 9 files changed, 1172 insertions(+), 46 deletions(-)
drivers/mmc/core/block.c +4 -1
@@ -1582,6 +1582,9 @@ static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq,struct request *req =mmc_queue_req_to_req (mqrq);struct mmc_blk_data *md = mq->blkdata;bool do_rel_wr, do_data_tag; +bool do_multi; + + do_multi = (card->uhs2_state &MMC_UHS2_INITIALIZED ) ? true : false;mmc_blk_data_prep (mq, mqrq, disable_multi, &do_rel_wr, &do_data_tag);
@@ -1592,7 +1595,7 @@ static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq, brq->cmd.arg <<=9 ; brq->cmd.flags =MMC_RSP_SPI_R1 |MMC_RSP_R1 |MMC_CMD_ADTC ; -if (brq->data.blocks >1 || do_rel_wr) { +if (brq->data.blocks >1 || do_rel_wr || do_multi) {/* SPI multiblock writes terminate using a special * token, not a STOP_TRANSMISSION request. */
drivers/mmc/core/core.c +16 -0
@@ -335,6 +335,8 @@ static int mmc_mrq_prep(struct mmc_host *host, struct mmc_request *mrq)int mmc_start_request (struct mmc_host *host,struct mmc_request *mrq) { +struct uhs2_command uhs2_cmd; +__be32 payload[4 ];/* for maximum size */ int err;init_completion (&mrq->cmd_completion);
@@ -352,6 +354,12 @@ int mmc_start_request(struct mmc_host *host, struct mmc_request *mrq)if (err)return err; +if (host->card->uhs2_state &MMC_UHS2_INITIALIZED ) { + uhs2_cmd.payload = payload; + mrq->cmd->uhs2_cmd = &uhs2_cmd; +mmc_uhs2_prepare_cmd (host, mrq); + } +led_trigger_event (host->led,LED_FULL );__mmc_start_request (host, mrq);
@@ -431,6 +439,8 @@ EXPORT_SYMBOL(mmc_wait_for_req_done);*/ int mmc_cqe_start_req (struct mmc_host *host,struct mmc_request *mrq) { +struct uhs2_command uhs2_cmd; +__be32 payload[4 ];/* for maximum size */ int err;/*
@@ -451,6 +461,12 @@ int mmc_cqe_start_req(struct mmc_host *host, struct mmc_request *mrq)if (err) goto out_err; +if (host->card->uhs2_state &MMC_UHS2_INITIALIZED ) { + uhs2_cmd.payload = payload; + mrq->cmd->uhs2_cmd = &uhs2_cmd; +mmc_uhs2_prepare_cmd (host, mrq); + } + err = host->cqe_ops->cqe_request (host, mrq);if (err) goto out_err;
drivers/mmc/core/mmc_ops.c +16 -8
@@ -144,10 +144,24 @@ int mmc_set_dsr(struct mmc_host *host)return mmc_wait_for_cmd (host, &cmd,MMC_CMD_RETRIES ); } +int __mmc_go_idle (struct mmc_host *host) +{ +struct mmc_command cmd = {}; +int err; + + cmd.opcode =MMC_GO_IDLE_STATE ; + cmd.arg =0 ; + cmd.flags =MMC_RSP_SPI_R1 |MMC_RSP_NONE |MMC_CMD_BC ; + + err =mmc_wait_for_cmd (host, &cmd,0 ); +mmc_delay (1 ); + +return err; +} +int mmc_go_idle (struct mmc_host *host) {int err; -struct mmc_command cmd = {};/* * Non-SPI hosts need to prevent chipselect going active during
@@ -163,13 +177,7 @@ int mmc_go_idle(struct mmc_host *host)mmc_delay (1 ); } - cmd.opcode =MMC_GO_IDLE_STATE ; - cmd.arg =0 ; - cmd.flags =MMC_RSP_SPI_R1 |MMC_RSP_NONE |MMC_CMD_BC ; - - err =mmc_wait_for_cmd (host, &cmd,0 ); - -mmc_delay (1 ); + err =__mmc_go_idle (host);if (!mmc_host_is_spi (host)) {mmc_set_chip_select (host,MMC_CS_DONTCARE );
drivers/mmc/core/mmc_ops.h +1 -0
@@ -25,6 +25,7 @@ struct mmc_command;int mmc_select_card (struct mmc_card *card);int mmc_deselect_cards (struct mmc_host *host);int mmc_set_dsr (struct mmc_host *host); +int __mmc_go_idle (struct mmc_host *host);int mmc_go_idle (struct mmc_host *host);int mmc_send_op_cond (struct mmc_host *host,u32 ocr,u32 *rocr);int mmc_set_relative_addr (struct mmc_card *card);
drivers/mmc/core/sd.c +3 -8
@@ -200,7 +200,7 @@ static int mmc_decode_csd(struct mmc_card *card)/* * Given a 64-bit response, decode to our card SCR structure. */ -static int mmc_decode_scr (struct mmc_card *card) +int mmc_decode_scr (struct mmc_card *card) {struct sd_scr *scr = &card->scr;unsigned int scr_struct;
@@ -1613,11 +1613,6 @@ static void mmc_sd_detect(struct mmc_host *host) } } -static int sd_can_poweroff_notify (struct mmc_card *card) -{ -return card->ext_power.feature_support &SD_EXT_POWER_OFF_NOTIFY ; -} -static int sd_busy_poweroff_notify_cb (void *cb_data,bool *busy) {struct sd_busy_data *data = cb_data;
@@ -1641,7 +1636,7 @@ static int sd_busy_poweroff_notify_cb(void *cb_data, bool *busy)return 0 ; } -static int sd_poweroff_notify (struct mmc_card *card) +int sd_poweroff_notify (struct mmc_card *card) {struct sd_busy_data cb_data;u8 *reg_buf;
@@ -1689,7 +1684,7 @@ static int _mmc_sd_suspend(struct mmc_host *host)if (mmc_card_suspended (card)) goto out; -if (sd_can_poweroff_notify (card)) +if (mmc_card_can_poweroff_notify (card)) err =sd_poweroff_notify (card);else if (!mmc_host_is_spi (host)) err =mmc_deselect_cards (host);
drivers/mmc/core/sd.h +3 -0
@@ -17,4 +17,7 @@ int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card,unsigned mmc_sd_get_max_clock (struct mmc_card *card);int mmc_sd_switch_hs (struct mmc_card *card); +/* These call back functions were also used by UHS2 sd card */ +int sd_poweroff_notify (struct mmc_card *card); +#endif
drivers/mmc/core/sd_ops.c +9 -0
@@ -27,6 +27,15 @@ int mmc_app_cmd(struct mmc_host *host, struct mmc_card *card)if (WARN_ON (card && card->host != host))return -EINVAL ; +/* +* UHS2 packet has APP bit so only set APP_CMD flag here. +* Will set the APP bit when assembling UHS2 packet. +*/ +if (card->uhs2_state &MMC_UHS2_INITIALIZED ) { + host->uhs2_ios.is_APP_CMD = true; +return 0 ; + } + cmd.opcode =MMC_APP_CMD ;if (card) {
drivers/mmc/core/sd_ops.h +3 -0
@@ -11,6 +11,7 @@#include <linux/types.h> struct mmc_card ; +struct mmc_command ;struct mmc_host ;int mmc_app_set_bus_width (struct mmc_card *card,int width);
@@ -19,10 +20,12 @@ int mmc_send_if_cond(struct mmc_host *host, u32 ocr);int mmc_send_if_cond_pcie (struct mmc_host *host,u32 ocr);int mmc_send_relative_addr (struct mmc_host *host,unsigned int *rca);int mmc_app_send_scr (struct mmc_card *card); +int mmc_decode_scr (struct mmc_card *card);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,void *ssr);int mmc_app_cmd (struct mmc_host *host,struct mmc_card *card); +void mmc_uhs2_prepare_cmd (struct mmc_host *host,struct mmc_request *mrq);#endif
drivers/mmc/core/sd_uhs2.c +1117 -29
1,319 lines not on this page · raw message
Signature · 1 line
2.35.1
Hi Ulf,
Do you have any comments for this patch set?
If you think this patch set is ok, we will proceed to integrate UHS2 host part of code with this patch set.
kind regards,
Jason Lai
Quoted 64 lines · Jason Lai
Series [1] that has been posted by Ulf Hansson which provided some
guidance and an overall structure.Series [2] focused on UHS-II card control side to address Ulf's intention
regarding to "modularising"sd_uhs2.c.Series [3] is based on series [2] and adopt most of Ulf's comments.
Series [4] is based on series [3] and refined by Ulf Hanssion.
This series is the successor version of post [4], which is base on Ulf's
"wip_uhs_v3" branch:
1. Implement call back functions insd_uhs2_ops.
2. Adopt Ulf's comments for V3.[1]
https://patchwork.kernel.org/project/linux-mmc/list/?series=438509[2]
https://patchwork.kernel.org/project/linux-mmc/list/?series=589827[3]
https://patchwork.kernel.org/project/linux-mmc/list/?series=606241[4]
https://git.kernel.org/pub/scm/linux/kernel/git/ulfh/mmc.git/log/?h=wip_uhs_v3Jason Lai (2):
mmc: core: Add definitions for SD UHS-II cards mmc:core: Support UHS-II card control and accessUlf Hansson (4):
mmc: core: Cleanup printing of speed mode at card insertion
mmc: core: Prepare to support SD UHS-II cards
mmc: core: Announce successful insertion of an SD UHS-II card
mmc: core: Extend support for mmc regulators with a vqmmc2drivers/mmc/core/Makefile | 2 +- drivers/mmc/core/block.c | 5 +- drivers/mmc/core/bus.c | 38 +- drivers/mmc/core/core.c | 33 +- drivers/mmc/core/core.h | 1 + drivers/mmc/core/host.h | 4 + drivers/mmc/core/mmc_ops.c | 24 +- drivers/mmc/core/mmc_ops.h | 1 + drivers/mmc/core/regulator.c | 34 + drivers/mmc/core/sd.c | 11 +- drivers/mmc/core/sd.h | 3 + drivers/mmc/core/sd_ops.c | 9 + drivers/mmc/core/sd_ops.h | 3 + drivers/mmc/core/sd_uhs2.c | 1377 ++++++++++++++++++++++++++++++++++ include/linux/mmc/card.h | 47 ++ include/linux/mmc/core.h | 13 + include/linux/mmc/host.h | 83 ++ include/linux/mmc/sd_uhs2.h | 263 +++++++ 18 files changed, 1916 insertions(+), 35 deletions(-) create mode 100644 drivers/mmc/core/sd_uhs2.c create mode 100644 include/linux/mmc/sd_uhs2.h--
2.35.1
Quoted 9 lines · Lai Jason
Hi Ulf,
Do you have any comments for this patch set?
If you think this patch set is ok, we will proceed to integrate UHS2 host part of code with this patch set.kind regards,
Jason Lai
Hi Jason,
My apologies for the delays. Unfortunately I need some additional time to review this, it has been a busy time for me lately.
Note that, as I said during the earlier review, it looks like it's time to rebase the host series and thus include that as a part of a complete series. The reason is simply that I would like to get a better understanding of how the host driver deployment would look like too.
I plan to complete the review of the $subject series next week, although please don't wait for my review if you already have a complete series ready to be posted, as I would rather review that instead.
[...]
Kind regards
Uffe