mmc: litex_mmc: Set mandatory idle clocks before CMD0
Subsystems (2)
v3 cover mmc: litex_mmc: Set mandatory idle clocks before CMD0
The litex_mmc driver assumes the card is already probed in the BIOS and skip the phy initialization. This will cause the command fail like the following when the old card is unplugged and then insert a new card:
[ 62.923593] litex-mmc f0004000.mmc: Command (cmd 8) error, status -110 [ 62.949717] litex-mmc f0004000.mmc: Command (cmd 55) error, status -110 [ 62.976606] litex-mmc f0004000.mmc: Command (cmd 55) error, status -110 [ 63.002516] litex-mmc f0004000.mmc: Command (cmd 55) error, status -110 [ 63.028442] litex-mmc f0004000.mmc: Command (cmd 55) error, status -110
Add required clock settings and initialization for the CMD 0, so it can probe the new card.
Changed from v2:
- https://lore.kernel.org/linux-mmc/[email protected]/
1. Remove the added function forward reference and add a new patch for moving litex_mmc_setclk() function
Change from v1:
- https://lore.kernel.org/linux-mmc/[email protected]/
1. use fsleep to replace udelay
Inochi Amaoto (2):
mmc: litex_mmc: Move litex_mmc_setclk() to bottom for reuse
mmc: litex_mmc: Set mandatory idle clocks before CMD0
drivers/mmc/host/litex_mmc.c | 37 ++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-)
--
2.54.0
PATCH v3 1/2 mmc: litex_mmc: Move litex_mmc_setclk() to bottom for reuse
Move the litex_mmc_setclk() to the bottom of the driver, this function is needed to set the idle clock for CMD0
--- drivers/mmc/host/litex_mmc.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)
drivers/mmc/host/litex_mmc.c +14 -14
@@ -99,6 +99,20 @@ struct litex_mmc_host {bool app_cmd; }; +static void litex_mmc_setclk (struct litex_mmc_host *host,unsigned int freq) +{ +struct device *dev =mmc_dev (host->mmc); +u32 div; + + div = freq ? host->ref_clk / freq :256U ; + div =roundup_pow_of_two (div); + div =clamp (div,2U ,256U ); +dev_dbg (dev,"sd_clk_freq=%d: set to %d via div=%d\n" , + freq, host->ref_clk / div, div); +litex_write16 (host->sdphy +LITEX_PHY_CLOCKERDIV , div); + host->sd_clk = freq; +} +static int litex_mmc_sdcard_wait_done (void __iomem *reg,struct device *dev) {u8 evt;
@@ -431,20 +445,6 @@ static void litex_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq)mmc_request_done (mmc, mrq); } -static void litex_mmc_setclk (struct litex_mmc_host *host,unsigned int freq) -{ -struct device *dev =mmc_dev (host->mmc); -u32 div; - - div = freq ? host->ref_clk / freq :256U ; - div =roundup_pow_of_two (div); - div =clamp (div,2U ,256U ); -dev_dbg (dev,"sd_clk_freq=%d: set to %d via div=%d\n" , - freq, host->ref_clk / div, div); -litex_write16 (host->sdphy +LITEX_PHY_CLOCKERDIV , div); - host->sd_clk = freq; -} -static void litex_mmc_set_ios (struct mmc_host *mmc,struct mmc_ios *ios) {struct litex_mmc_host *host =mmc_priv (mmc);
Signature · 1 line
2.54.0
PATCH v3 2/2 mmc: litex_mmc: Set mandatory idle clocks before CMD0
In reply to Inochi AmaotoThe litex_mmc driver assumes the card is already probed in the BIOS and skip the phy initialization. This will cause the command fail like the following when the old card is unplugged and then insert a new card:
[ 62.923593] litex-mmc f0004000.mmc: Command (cmd 8) error, status -110 [ 62.949717] litex-mmc f0004000.mmc: Command (cmd 55) error, status -110 [ 62.976606] litex-mmc f0004000.mmc: Command (cmd 55) error, status -110 [ 63.002516] litex-mmc f0004000.mmc: Command (cmd 55) error, status -110 [ 63.028442] litex-mmc f0004000.mmc: Command (cmd 55) error, status -110
Add required clock settings and initialization for the CMD 0, so it can probe the new card.
--- drivers/mmc/host/litex_mmc.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/mmc/host/litex_mmc.c +9 -0
@@ -68,6 +68,9 @@#define SD_SLEEP_US 5#define SD_TIMEOUT_US 20000 +#define SD_INIT_DELAY_US 1000 +#define SD_INIT_CLK_HZ 400000 +#define SDIRQ_CARD_DETECT 1#define SDIRQ_SD_TO_MEM_DONE 2#define SDIRQ_MEM_TO_SD_DONE 4
@@ -142,6 +145,12 @@ static int litex_mmc_send_cmd(struct litex_mmc_host *host,int ret;u8 evt; +if (cmd ==MMC_GO_IDLE_STATE ) { +litex_mmc_setclk (host,SD_INIT_CLK_HZ ); +litex_write8 (host->sdphy +LITEX_PHY_INITIALIZE ,1 ); +fsleep (SD_INIT_DELAY_US ); + } +litex_write32 (host->sdcore +LITEX_CORE_CMDARG , arg);litex_write32 (host->sdcore +LITEX_CORE_CMDCMD , cmd <<8 | transfer <<5 | response_len);
Signature · 1 line
2.54.0
Quoted 36 lines · Inochi Amaoto
The
litex_mmcdriver assumes the card is already probed in the BIOS and skip the phy initialization. This will cause the command fail like the following when the old card is unplugged and then insert a new card:[ 62.923593] litex-mmc f0004000.mmc: Command (cmd 8) error, status -110 [ 62.949717] litex-mmc f0004000.mmc: Command (cmd 55) error, status -110 [ 62.976606] litex-mmc f0004000.mmc: Command (cmd 55) error, status -110 [ 63.002516] litex-mmc f0004000.mmc: Command (cmd 55) error, status -110 [ 63.028442] litex-mmc f0004000.mmc: Command (cmd 55) error, status -110Add required clock settings and initialization for the CMD 0, so it can probe the new card.
Fixes 92e099104729 ("mmc: Add driver for LiteX's LiteSDCard interface")Signed-off-by Inochi Amaoto <[email protected]>--- drivers/mmc/host/litex_mmc.c | 9 +++++++++ 1 file changed, 9 insertions(+)drivers/mmc/host/litex_mmc.c +3
-0@@ -68,6 +68,9 @@#define SD_SLEEP_US 5#define SD_TIMEOUT_US 20000 +#define SD_INIT_DELAY_US 1000 +#define SD_INIT_CLK_HZ 400000 +#define SDIRQ_CARD_DETECT 1#define SDIRQ_SD_TO_MEM_DONE 2#define SDIRQ_MEM_TO_SD_DONE 4
drivers/mmc/host/litex_mmc.c static int litex_mmc_send_cmd(struct litex_mmc_host *host, · line 148
Quoted 4 lines
drivers/mmc/host/litex_mmc.c +1
-0@@ -142,6 +145,12 @@ static int litex_mmc_send_cmd(struct litex_mmc_host *host,int ret;u8 evt; +if (cmd ==MMC_GO_IDLE_STATE ) {
Rather than doing this explicit check for each command being sent, we have the ->set_ios() callback where things like this belong. Please move it there instead.
Quoted 11 lines
drivers/mmc/host/litex_mmc.c +5
-1+litex_mmc_setclk (host,SD_INIT_CLK_HZ ); +litex_write8 (host->sdphy +LITEX_PHY_INITIALIZE ,1 ); +fsleep (SD_INIT_DELAY_US ); + } +litex_write32 (host->sdcore +LITEX_CORE_CMDARG , arg);litex_write32 (host->sdcore +LITEX_CORE_CMDCMD , cmd <<8 | transfer <<5 | response_len); --2.54.0
Kind regards
Uffe
Quoted 40 lines · Ulf Hansson
Quoted 39 lines · Inochi Amaoto
The
litex_mmcdriver assumes the card is already probed in the BIOS and skip the phy initialization. This will cause the command fail like the following when the old card is unplugged and then insert a new card:[ 62.923593] litex-mmc f0004000.mmc: Command (cmd 8) error, status -110 [ 62.949717] litex-mmc f0004000.mmc: Command (cmd 55) error, status -110 [ 62.976606] litex-mmc f0004000.mmc: Command (cmd 55) error, status -110 [ 63.002516] litex-mmc f0004000.mmc: Command (cmd 55) error, status -110 [ 63.028442] litex-mmc f0004000.mmc: Command (cmd 55) error, status -110Add required clock settings and initialization for the CMD 0, so it can probe the new card.
Fixes 92e099104729 ("mmc: Add driver for LiteX's LiteSDCard interface")Signed-off-by Inochi Amaoto <[email protected]>--- drivers/mmc/host/litex_mmc.c | 9 +++++++++ 1 file changed, 9 insertions(+)drivers/mmc/host/litex_mmc.c +3
-0@@ -68,6 +68,9 @@#define SD_SLEEP_US 5#define SD_TIMEOUT_US 20000 +#define SD_INIT_DELAY_US 1000 +#define SD_INIT_CLK_HZ 400000 +#define SDIRQ_CARD_DETECT 1#define SDIRQ_SD_TO_MEM_DONE 2#define SDIRQ_MEM_TO_SD_DONE 4@@ -142,6 +145,12 @@ static int litex_mmc_send_cmd(struct litex_mmc_host *host,int ret;u8 evt;
Quoted 6 lines
drivers/mmc/host/litex_mmc.c static int litex_mmc_send_cmd(struct litex_mmc_host *host, · line 148
Quoted 1 line
drivers/mmc/host/litex_mmc.c +1
-0+if (cmd ==MMC_GO_IDLE_STATE ) {Rather than doing this explicit check for each command being sent, we have the ->set_ios() callback where things like this belong. Please move it there instead.
OK, And I think the patch 1 can be removed if this got moved to set_ios(). I will prepare a new version for it.
Regards,
Inochi
Quoted 14 lines
Quoted 11 lines
drivers/mmc/host/litex_mmc.c +5
-1+litex_mmc_setclk (host,SD_INIT_CLK_HZ ); +litex_write8 (host->sdphy +LITEX_PHY_INITIALIZE ,1 ); +fsleep (SD_INIT_DELAY_US ); + } +litex_write32 (host->sdcore +LITEX_CORE_CMDARG , arg);litex_write32 (host->sdcore +LITEX_CORE_CMDCMD , cmd <<8 | transfer <<5 | response_len); --2.54.0
Kind regards
Uffe
Quoted 19 lines · Inochi Amaoto
The
litex_mmcdriver assumes the card is already probed in the BIOS and skip the phy initialization. This will cause the command fail like the following when the old card is unplugged and then insert a new card:[ 62.923593] litex-mmc f0004000.mmc: Command (cmd 8) error, status -110 [ 62.949717] litex-mmc f0004000.mmc: Command (cmd 55) error, status -110 [ 62.976606] litex-mmc f0004000.mmc: Command (cmd 55) error, status -110 [ 63.002516] litex-mmc f0004000.mmc: Command (cmd 55) error, status -110 [ 63.028442] litex-mmc f0004000.mmc: Command (cmd 55) error, status -110Add required clock settings and initialization for the CMD 0, so it can probe the new card.
Changed from v2:
- https://lore.kernel.org/linux-mmc/[email protected]/
1. Remove the added function forward reference and add a new patch for movinglitex_mmc_setclk()function
Quoted 7 lines
Change from v1:
- https://lore.kernel.org/linux-mmc/[email protected]/
1. use fsleep to replace udelayInochi Amaoto (2):
mmc:litex_mmc: Movelitex_mmc_setclk()to bottom for reuse
mmc:litex_mmc: Set mandatory idle clocks before CMD0
For the whole series:
Thanks,
--Gabriel