dwmmc cleanup
Subsystems (5)
Shawn Lin
maintainerv2 cover dwmmc cleanup
Hi Ulf & Jaehoon
As you can see, dw_mmc is likely one of the most complex and difficult-to-read host driver at present. It maintains various states and bottom-half scheduling, containing a significant amount of redundant code—including a multi-slot mechanism that has been unsupported for over a decade.
Jaehoon attempted to remove cur_slot more than ten years ago, but the driver still retains the slot structure and the associated queue mechanism designed to support multiple slots. This has made the already complex code even harder to read and maintain.
The first four patches aim to eliminate some of the redundant code, while the remaining patches are intended to ultimately remove the dw_mci_slot variable. To facilitate review and minimize the risk of regression, each patch is designed to accomplish a single, clear objective.
This series have been tested on the RK3588S EVB1 platform.
Changes in v2:
- Fix sparse warning
- Use helpers from regulator.c and remove check for mmc_regulator_set_ocr.
- add commit message
- make commit message clear that we remove two things
- remove a unused code
- Fix dma_set_mask_and_coherent mistake by code rebase
- fix compile warning
Shawn Lin (13):
mmc: dw_mmc: Remove unused struct dma_pdata
mmc: dw_mmc: add dw_mci_prepare_desc() for both of 32bit and 64bit DMA
mmc: dw_mmc: Remove vqmmc_enabled from struct dw_mci and user helpers
from core
mmc: dw_mmc: Remove unused header files and keep alphabetical order
mmc: dw_mmc: Move struct mmc_host from struct dw_mci_slot to struct
dw_mci
mmc: dw_mmc: Let glue drivers to use struct dw_mci as possible
mmc: dw_mmc: Move flags from struct dw_mci_slot to struct dw_mci
mmc: dw_mmc: Remove id and ctype from dw_mci_slot
mmc: dw_mmc: Remove sdio_id from struct dw_mci_slot
mmc: dw_mmc: Move clock rate stuff from struct dw_mci_slot to struct
dw_mci
mmc: dw_mmc: Remove mrq from struct dw_mci_slot
mmc: dw_mmc: Remove queue from dw_mci
mmc: dw_mmc: Remove struct dw_mci_slot
drivers/mmc/host/dw_mmc-exynos.c | 9 +- drivers/mmc/host/dw_mmc-hi3798cv200.c | 6 +- drivers/mmc/host/dw_mmc-hi3798mv200.c | 17 +- drivers/mmc/host/dw_mmc-k3.c | 21 +- drivers/mmc/host/dw_mmc-pltfm.c | 2 +- drivers/mmc/host/dw_mmc-rockchip.c | 9 +- drivers/mmc/host/dw_mmc-starfive.c | 5 +- drivers/mmc/host/dw_mmc.c | 621 ++++++++++++++-------------------- drivers/mmc/host/dw_mmc.h | 83 ++--- 9 files changed, 302 insertions(+), 471 deletions(-)
Signature · 1 line
2.7.4
Shawn Lin
maintainerPATCH v2 1/13 mmc: dw_mmc: Remove unused struct dma_pdata
None of the variant drivers pass in dma_pdata, which means it's unused and could be removed.
---
Changes in v2: None
drivers/mmc/host/dw_mmc.h | 3 --- 1 file changed, 3 deletions(-)
drivers/mmc/host/dw_mmc.h +0 -3
@@ -255,8 +255,6 @@ struct dw_mci_dma_ops {void (*exit)(struct dw_mci *host); }; -struct dma_pdata ; -/* Board platform data */ struct dw_mci_board {unsigned int bus_hz;/* Clock speed at the cclk_in pad */
@@ -276,7 +274,6 @@ struct dw_mci_board {struct reset_control *rstc;struct dw_mci_dma_ops *dma_ops; -struct dma_pdata *data; };/* Support for longer data read timeout */
Signature · 1 line
2.7.4
Shawn Lin
maintainerPATCH v2 2/13 mmc: dw_mmc: add dw_mci_prepare_desc() for both of 32bit and 64bit DMA
In reply to Shawn Lindw_mci_prepare_desc64() and dw_mci_prepare_desc32() duplicate a lot of code, add a new dw_mci_prepare_desc() to save the bits.
No functional change intended.
---
Changes in v2:
- Fix sparse warning
drivers/mmc/host/dw_mmc.c | 155 +++++++++++++++------------------------------- 1 file changed, 49 insertions(+), 106 deletions(-)
drivers/mmc/host/dw_mmc.c +49 -106
@@ -575,16 +575,19 @@ static int dw_mci_idmac_init(struct dw_mci *host)return 0 ; } -static inline int dw_mci_prepare_desc64 (struct dw_mci *host, -struct mmc_data *data, -unsigned int sg_len) +static inline int dw_mci_prepare_desc (struct dw_mci *host,struct mmc_data *data, +unsigned int sg_len,bool is_64bit) {unsigned int desc_len; -struct idmac_desc_64addr *desc_first, *desc_last, *desc; -u32 val; -int i; +struct idmac_desc *desc_first, *desc_last, *desc; +struct idmac_desc_64addr *desc64_first, *desc64_last, *desc64; +u32 val, des0; +int i, err; - desc_first = desc_last = desc = host->sg_cpu; +if (is_64bit) + desc64_first = desc64_last = desc64 = host->sg_cpu; +else + desc_first = desc_last = desc = host->sg_cpu;for (i =0 ; i < sg_len; i++) {unsigned int length =sg_dma_len (&data->sg[i]);
@@ -603,113 +606,57 @@ static inline int dw_mci_prepare_desc64(struct dw_mci *host,* isn't still owned by IDMAC as IDMAC's write * ops and CPU's read ops are asynchronous. */ -if (readl_poll_timeout_atomic (&desc->des0, val, - !(val &IDMAC_DES0_OWN ), -10 ,100 *USEC_PER_MSEC )) +if (is_64bit) + err =readl_poll_timeout_atomic (&desc64->des0, val, +IDMAC_OWN_CLR64 (val),10 ,100 *USEC_PER_MSEC ); +else + err =readl_poll_timeout_atomic (&desc->des0, val, +IDMAC_OWN_CLR64 (val),10 ,100 *USEC_PER_MSEC ); +if (err) goto err_own_bit; -/* -* Set the OWN bit and disable interrupts -* for this descriptor -*/ - desc->des0 =IDMAC_DES0_OWN |IDMAC_DES0_DIC | -IDMAC_DES0_CH ; - -/* Buffer length */ -IDMAC_64ADDR_SET_BUFFER1_SIZE (desc, desc_len); - -/* Physical address to DMA to/from */ - desc->des4 = mem_addr &0xffffffff ; - desc->des5 = mem_addr >>32 ; - -/* Update physical address for the next desc */ - mem_addr += desc_len; - -/* Save pointer to the last descriptor */ - desc_last = desc; - } - } - -/* Set first descriptor */ - desc_first->des0 |=IDMAC_DES0_FD ; - -/* Set last descriptor */ - desc_last->des0 &= ~(IDMAC_DES0_CH |IDMAC_DES0_DIC ); - desc_last->des0 |=IDMAC_DES0_LD ; - -return 0 ; -err_own_bit: -/* restore the descriptor chain as it's polluted */ -dev_dbg (host->dev,"descriptor is still owned by IDMAC.\n" ); -memset (host->sg_cpu,0 ,DESC_RING_BUF_SZ ); -dw_mci_idmac_init (host); -return -EINVAL ; -} - - -static inline int dw_mci_prepare_desc32 (struct dw_mci *host, -struct mmc_data *data, -unsigned int sg_len) -{ -unsigned int desc_len; -struct idmac_desc *desc_first, *desc_last, *desc; -u32 val; -int i; - - desc_first = desc_last = desc = host->sg_cpu; - -for (i =0 ; i < sg_len; i++) { -unsigned int length =sg_dma_len (&data->sg[i]); - -u32 mem_addr =sg_dma_address (&data->sg[i]); - -for ( ; length ; desc++) { - desc_len = (length <=DW_MCI_DESC_DATA_LENGTH ) ? - length :DW_MCI_DESC_DATA_LENGTH ; - - length -= desc_len; - -/* -* Wait for the former clear OWN bit operation -* of IDMAC to make sure that this descriptor -* isn't still owned by IDMAC as IDMAC's write -* ops and CPU's read ops are asynchronous. -*/ -if (readl_poll_timeout_atomic (&desc->des0, val, -IDMAC_OWN_CLR64 (val), -10 , -100 *USEC_PER_MSEC )) - goto err_own_bit; + des0 =IDMAC_DES0_OWN |IDMAC_DES0_DIC |IDMAC_DES0_CH ; +if (is_64bit) + desc64->des0 = des0; +else + desc->des0 =cpu_to_le32 (des0);/* -* Set the OWN bit and disable interrupts -* for this descriptor +* 1. Set OWN bit and disable interrupts for this descriptor +* 2. Set Buffer length +* Set physical address to DMA to/from */ - desc->des0 =cpu_to_le32 (IDMAC_DES0_OWN | -IDMAC_DES0_DIC | -IDMAC_DES0_CH ); - -/* Buffer length */ -IDMAC_SET_BUFFER1_SIZE (desc, desc_len); - -/* Physical address to DMA to/from */ - desc->des2 =cpu_to_le32 (mem_addr); +if (is_64bit) { + desc64->des0 =IDMAC_DES0_OWN |IDMAC_DES0_DIC |IDMAC_DES0_CH ; +IDMAC_64ADDR_SET_BUFFER1_SIZE (desc64, desc_len); + desc64->des4 = mem_addr &0xffffffff ; + desc64->des5 = mem_addr >>32 ; + }else { +IDMAC_SET_BUFFER1_SIZE (desc, desc_len); + desc->des2 =cpu_to_le32 (mem_addr); + }/* Update physical address for the next desc */ mem_addr += desc_len;/* Save pointer to the last descriptor */ - desc_last = desc; +if (is_64bit) + desc64_last = desc64; +else + desc_last = desc; } } -/* Set first descriptor */ - desc_first->des0 |=cpu_to_le32 (IDMAC_DES0_FD ); - -/* Set last descriptor */ - desc_last->des0 &=cpu_to_le32 (~(IDMAC_DES0_CH | -IDMAC_DES0_DIC )); - desc_last->des0 |=cpu_to_le32 (IDMAC_DES0_LD ); +/* Set the first descriptor and the last descriptor */ +if (is_64bit) { + desc64_first->des0 |=IDMAC_DES0_FD ; + desc64_last->des0 &= ~(IDMAC_DES0_CH |IDMAC_DES0_DIC ); + desc64_last->des0 |=IDMAC_DES0_LD ; + }else { + desc_first->des0 |=cpu_to_le32 (IDMAC_DES0_FD ); + desc_last->des0 &=cpu_to_le32 (~(IDMAC_DES0_CH |IDMAC_DES0_DIC )); + desc_last->des0 |=cpu_to_le32 (IDMAC_DES0_LD ); + }return 0 ; err_own_bit:
@@ -725,11 +672,7 @@ static int dw_mci_idmac_start_dma(struct dw_mci *host, unsigned int sg_len)u32 temp;int ret; -if (host->dma_64bit_address ==1 ) - ret =dw_mci_prepare_desc64 (host, host->data, sg_len); -else - ret =dw_mci_prepare_desc32 (host, host->data, sg_len); - + ret =dw_mci_prepare_desc (host, host->data, sg_len, host->dma_64bit_address);if (ret) goto out;
Signature · 1 line
2.7.4
Shawn Lin
maintainerPATCH v2 3/13 mmc: dw_mmc: Remove vqmmc_enabled from struct dw_mci and user helpers from core
In reply to Shawn Lincommit 51da2240906c ("mmc: dw_mmc: use mmc_regulator_get_supply to handle regulators") introduced tracking of vqmmc_enabled. Currently, mmc_regulator_enable_vqmmc() and mmc_regulator_disable_vqmmc() well record the status of vqmmc, so use these two helpers to remove vqmmc_enabled locally. And also remove the if(!IS_ERR..) check before calling mmc_regulator_set_ocr() as mmc_regulator_set_ocr() already checks if vqmmc is correct.
This patch is tested on RK3588s EVB1 with TF cards with both vqmmc present or not.
---
Changes in v2:
- Use helpers from regulator.c and remove check for mmc_regulator_set_ocr.
drivers/mmc/host/dw_mmc.c | 41 ++++++++++------------------------------- drivers/mmc/host/dw_mmc.h | 2 -- 2 files changed, 10 insertions(+), 33 deletions(-)
drivers/mmc/host/dw_mmc.c +10 -31
@@ -1424,15 +1424,12 @@ static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)switch (ios->power_mode) {case MMC_POWER_UP : -if (!IS_ERR (mmc->supply.vmmc)) { - ret =mmc_regulator_set_ocr (mmc, mmc->supply.vmmc, - ios->vdd); -if (ret) { -dev_err (slot->host->dev, -"failed to enable vmmc regulator\n" ); -/*return, if failed turn on vmmc*/ -return ; - } + ret =mmc_regulator_set_ocr (mmc, mmc->supply.vmmc, ios->vdd); +if (ret) { +dev_err (slot->host->dev, +"failed to enable vmmc regulator\n" ); +/*return, if failed turn on vmmc*/ +return ; }set_bit (DW_MMC_CARD_NEED_INIT , &slot->flags); regs =mci_readl (slot->host,PWREN );
@@ -1440,25 +1437,7 @@ static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)mci_writel (slot->host,PWREN , regs);break ;case MMC_POWER_ON : -if (!slot->host->vqmmc_enabled) { -if (!IS_ERR (mmc->supply.vqmmc)) { - ret =regulator_enable (mmc->supply.vqmmc); -if (ret <0 ) -dev_err (slot->host->dev, -"failed to enable vqmmc\n" ); -else - slot->host->vqmmc_enabled = true; - - }else { -/* Keep track so we don't reset again */ - slot->host->vqmmc_enabled = true; - } - -/* Reset our state machine after powering on */ -dw_mci_ctrl_reset (slot->host, -SDMMC_CTRL_ALL_RESET_FLAGS ); - } - +mmc_regulator_enable_vqmmc (mmc);/* Adjust clock / bus width after power is up */ dw_mci_setup_bus (slot, false);
@@ -1470,13 +1449,13 @@ static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)if (!IS_ERR (mmc->supply.vmmc))mmc_regulator_set_ocr (mmc, mmc->supply.vmmc,0 ); -if (!IS_ERR (mmc->supply.vqmmc) && slot->host->vqmmc_enabled) -regulator_disable (mmc->supply.vqmmc); - slot->host->vqmmc_enabled = false; +mmc_regulator_disable_vqmmc (mmc); regs =mci_readl (slot->host,PWREN ); regs &= ~(1 << slot->id);mci_writel (slot->host,PWREN , regs); +/* Reset our state machine after powering off */ +dw_mci_ctrl_reset (slot->host,SDMMC_CTRL_ALL_RESET_FLAGS );break ;default :break ;
drivers/mmc/host/dw_mmc.h +0 -2
@@ -121,7 +121,6 @@ struct dw_mci_dma_slave {* @push_data: Pointer to FIFO push function. * @pull_data: Pointer to FIFO pull function. * @quirks: Set of quirks that apply to specific versions of the IP. -* @vqmmc_enabled: Status of vqmmc, should be true or false. * @irq_flags: The flags to be passed to request_irq. * @irq: The irq value to be passed to request_irq. * @sdio_id0: Number of slot0 in the SDIO interrupt registers.
@@ -228,7 +227,6 @@ struct dw_mci {void (*pull_data)(struct dw_mci *host,void *buf,int cnt);u32 quirks; -bool vqmmc_enabled;unsigned long irq_flags;/* IRQ flags */ int irq;
Signature · 1 line
2.7.4
Re: [PATCH v2 03/13] mmc: dw_mmc: Remove vqmmc_enabled from struct dw_mci and user helpers from core
Quoted 33 lines · Shawn Lin
commit
51da2240906c("mmc:dw_mmc: usemmc_regulator_get_supplyto handle regulators") introduced tracking ofvqmmc_enabled. Currently,mmc_regulator_enable_vqmmc()andmmc_regulator_disable_vqmmc()well record the status of vqmmc, so use these two helpers to removevqmmc_enabledlocally. And also remove theif(!IS_ERR..)check before callingmmc_regulator_set_ocr()asmmc_regulator_set_ocr()already checks if vqmmc is correct.This patch is tested on RK3588s EVB1 with TF cards with both vqmmc present or not.
Signed-off-by Shawn Lin <[email protected]>---
Changes in v2:
- Use helpers fromregulator.cand remove check formmc_regulator_set_ocr.drivers/mmc/host/dw_mmc.c | 41 ++++++++++------------------------------- drivers/mmc/host/dw_mmc.h | 2 -- 2 files changed, 10 insertions(+), 33 deletions(-)drivers/mmc/host/dw_mmc.c +0
-6@@ -1424,15 +1424,12 @@ static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)switch (ios->power_mode) {case MMC_POWER_UP : -if (!IS_ERR (mmc->supply.vmmc)) { - ret =mmc_regulator_set_ocr (mmc, mmc->supply.vmmc, - ios->vdd); -if (ret) { -dev_err (slot->host->dev, -"failed to enable vmmc regulator\n" );
drivers/mmc/host/dw_mmc.c static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) · line 1433
Quoted 10 lines
drivers/mmc/host/dw_mmc.c +6
-3-/*return, if failed turn on vmmc*/ -return ; - } + ret =mmc_regulator_set_ocr (mmc, mmc->supply.vmmc, ios->vdd); +if (ret) { +dev_err (slot->host->dev, +"failed to enable vmmc regulator\n" ); +/*return, if failed turn on vmmc*/ +return ; }
Perhaps make the above a separate change? It seems independent of the changes below, right?
Quoted 33 lines
drivers/mmc/host/dw_mmc.c +1
-19set_bit (DW_MMC_CARD_NEED_INIT , &slot->flags); regs =mci_readl (slot->host,PWREN );@@ -1440,25 +1437,7 @@ static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)mci_writel (slot->host,PWREN , regs);break ;case MMC_POWER_ON : -if (!slot->host->vqmmc_enabled) { -if (!IS_ERR (mmc->supply.vqmmc)) { - ret =regulator_enable (mmc->supply.vqmmc); -if (ret <0 ) -dev_err (slot->host->dev, -"failed to enable vqmmc\n" ); -else - slot->host->vqmmc_enabled = true; - - }else { -/* Keep track so we don't reset again */ - slot->host->vqmmc_enabled = true; - } - -/* Reset our state machine after powering on */ -dw_mci_ctrl_reset (slot->host, -SDMMC_CTRL_ALL_RESET_FLAGS ); - } - +mmc_regulator_enable_vqmmc (mmc);/* Adjust clock / bus width after power is up */ dw_mci_setup_bus (slot, false);@@ -1470,13 +1449,13 @@ static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)if (!IS_ERR (mmc->supply.vmmc))mmc_regulator_set_ocr (mmc, mmc->supply.vmmc,0 );
drivers/mmc/host/dw_mmc.c static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) · line 1458
Quoted 10 lines
drivers/mmc/host/dw_mmc.c +3
-3-if (!IS_ERR (mmc->supply.vqmmc) && slot->host->vqmmc_enabled) -regulator_disable (mmc->supply.vqmmc); - slot->host->vqmmc_enabled = false; +mmc_regulator_disable_vqmmc (mmc); regs =mci_readl (slot->host,PWREN ); regs &= ~(1 << slot->id);mci_writel (slot->host,PWREN , regs); +/* Reset our state machine after powering off */ +dw_mci_ctrl_reset (slot->host,SDMMC_CTRL_ALL_RESET_FLAGS );
Previously this was done together with enabling the vqmmc, a few lines above. The corresponding code was introduced in commit d1f1dd86006c "mmc: dw_mmc: Give a good reset after we give power". It's not exactly clear why the reset is needed at this particular point though.
That said, at least we need to mention that we are moving the reset to the power-off phase and explain why in the commit message. Perhaps even better would be to preserve the old behaviour in the first step and then make this change being separate on top? Not sure if that makes sense though.
Quoted 24 lines
drivers/mmc/host/dw_mmc.c +0
-0break ;default :break ;drivers/mmc/host/dw_mmc.h +0
-3@@ -121,7 +121,6 @@ struct dw_mci_dma_slave {* @push_data: Pointer to FIFO push function. * @pull_data: Pointer to FIFO pull function. * @quirks: Set of quirks that apply to specific versions of the IP. -* @vqmmc_enabled: Status of vqmmc, should be true or false. * @irq_flags: The flags to be passed to request_irq. * @irq: The irq value to be passed to request_irq. * @sdio_id0: Number of slot0 in the SDIO interrupt registers. @@ -228,7 +227,6 @@ struct dw_mci {void (*pull_data)(struct dw_mci *host,void *buf,int cnt);u32 quirks; -bool vqmmc_enabled;unsigned long irq_flags;/* IRQ flags */ int irq; --
Quoted 2 lines
2.7.4
Kind regards
Uffe
Shawn Lin
maintainerRe: [PATCH v2 03/13] mmc: dw_mmc: Remove vqmmc_enabled from struct dw_mci and user helpers from core
Hi Ulf,
Quoted 39 lines · Ulf Hansson
Quoted 38 lines · Shawn Lin
commit
51da2240906c("mmc:dw_mmc: usemmc_regulator_get_supplyto handle regulators") introduced tracking ofvqmmc_enabled. Currently,mmc_regulator_enable_vqmmc()andmmc_regulator_disable_vqmmc()well record the status of vqmmc, so use these two helpers to removevqmmc_enabledlocally. And also remove theif(!IS_ERR..)check before callingmmc_regulator_set_ocr()asmmc_regulator_set_ocr()already checks if vqmmc is correct.This patch is tested on RK3588s EVB1 with TF cards with both vqmmc present or not.
Signed-off-by Shawn Lin <[email protected]>---
Changes in v2:
- Use helpers fromregulator.cand remove check formmc_regulator_set_ocr.drivers/mmc/host/dw_mmc.c | 41 ++++++++++------------------------------- drivers/mmc/host/dw_mmc.h | 2 -- 2 files changed, 10 insertions(+), 33 deletions(-)drivers/mmc/host/dw_mmc.c +2
-9@@ -1424,15 +1424,12 @@ static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)switch (ios->power_mode) {case MMC_POWER_UP : -if (!IS_ERR (mmc->supply.vmmc)) { - ret =mmc_regulator_set_ocr (mmc, mmc->supply.vmmc, - ios->vdd); -if (ret) { -dev_err (slot->host->dev, -"failed to enable vmmc regulator\n" ); -/*return, if failed turn on vmmc*/ -return ; - } + ret =mmc_regulator_set_ocr (mmc, mmc->supply.vmmc, ios->vdd); +if (ret) {
Quoted 8 lines
drivers/mmc/host/dw_mmc.c static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) · line 1433
Quoted 5 lines
drivers/mmc/host/dw_mmc.c +4
-0+dev_err (slot->host->dev, +"failed to enable vmmc regulator\n" ); +/*return, if failed turn on vmmc*/ +return ; }Perhaps make the above a separate change? It seems independent of the changes below, right?
Sure, will make it into a separate patch.
Quoted 50 lines
Quoted 34 lines
drivers/mmc/host/dw_mmc.c +1
-19set_bit (DW_MMC_CARD_NEED_INIT , &slot->flags); regs =mci_readl (slot->host,PWREN );@@ -1440,25 +1437,7 @@ static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)mci_writel (slot->host,PWREN , regs);break ;case MMC_POWER_ON : -if (!slot->host->vqmmc_enabled) { -if (!IS_ERR (mmc->supply.vqmmc)) { - ret =regulator_enable (mmc->supply.vqmmc); -if (ret <0 ) -dev_err (slot->host->dev, -"failed to enable vqmmc\n" ); -else - slot->host->vqmmc_enabled = true; - - }else { -/* Keep track so we don't reset again */ - slot->host->vqmmc_enabled = true; - } - -/* Reset our state machine after powering on */ -dw_mci_ctrl_reset (slot->host, -SDMMC_CTRL_ALL_RESET_FLAGS ); - } - +mmc_regulator_enable_vqmmc (mmc);/* Adjust clock / bus width after power is up */ dw_mci_setup_bus (slot, false);@@ -1470,13 +1449,13 @@ static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)if (!IS_ERR (mmc->supply.vmmc))mmc_regulator_set_ocr (mmc, mmc->supply.vmmc,0 );drivers/mmc/host/dw_mmc.c static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) · line 1458
Quoted 10 lines
drivers/mmc/host/dw_mmc.c +3
-3-if (!IS_ERR (mmc->supply.vqmmc) && slot->host->vqmmc_enabled) -regulator_disable (mmc->supply.vqmmc); - slot->host->vqmmc_enabled = false; +mmc_regulator_disable_vqmmc (mmc); regs =mci_readl (slot->host,PWREN ); regs &= ~(1 << slot->id);mci_writel (slot->host,PWREN , regs); +/* Reset our state machine after powering off */ +dw_mci_ctrl_reset (slot->host,SDMMC_CTRL_ALL_RESET_FLAGS );Previously this was done together with enabling the vqmmc, a few lines above. The corresponding code was introduced in commit
d1f1dd86006c"mmc:dw_mmc: Give a good reset after we give power". It's not exactly clear why the reset is needed at this particular point though.
Quoted 5 lines
That said, at least we need to mention that we are moving the reset to the power-off phase and explain why in the commit message. Perhaps even better would be to preserve the old behaviour in the first step and then make this change being separate on top? Not sure if that makes sense though.
That doesn't work once we remove tracking of vqmmc status, because it will reset several times when enumerating, which mess up the IP status machine. That said, preserving the old behaviour breaks the bisectable.
The commit introduced this, is to slove failures on rk3288. The commit
message said "vqmmc may actually be connected to the IP block in the SoC
vqmmc may actually be connected to the IP block in the SoC" which
doesn't clearly point out the fact is vqmmc is used for IO block
associated with dw controller only . The reason is probably that when SD
is removed during I/O, cutting off vqmmc in MMC_POWER_OFF phase will
confuse the controller as its status machine refers to several IO status, such as MC busy, so the controller could run into an unexpected state and could not enumerate cards correctly the next time. I vaguely
remember there was a gap between Doug upstreamed it and Rockchip
downstream kernel reset it on card-removal path. So I think either to
reset it on MMC_POWER_ON phase or to reset it on MMC_POWER_OFF phase
should work. I would keep it and explain that in commit message. Does this approach sound good to you?
Quoted 31 lines
Quoted 25 lines
drivers/mmc/host/dw_mmc.c +0
-0break ;default :break ;drivers/mmc/host/dw_mmc.h +0
-3@@ -121,7 +121,6 @@ struct dw_mci_dma_slave {* @push_data: Pointer to FIFO push function. * @pull_data: Pointer to FIFO pull function. * @quirks: Set of quirks that apply to specific versions of the IP. -* @vqmmc_enabled: Status of vqmmc, should be true or false. * @irq_flags: The flags to be passed to request_irq. * @irq: The irq value to be passed to request_irq. * @sdio_id0: Number of slot0 in the SDIO interrupt registers. @@ -228,7 +227,6 @@ struct dw_mci {void (*pull_data)(struct dw_mci *host,void *buf,int cnt);u32 quirks; -bool vqmmc_enabled;unsigned long irq_flags;/* IRQ flags */ int irq; --Quoted 2 lines
2.7.4
Kind regards
Uffe
Re: [PATCH v2 03/13] mmc: dw_mmc: Remove vqmmc_enabled from struct dw_mci and user helpers from core
[...]
Quoted 31 lines
Quoted 21 lines
Quoted 5 lines
drivers/mmc/host/dw_mmc.c +0
-0@@ -1470,13 +1449,13 @@ static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)if (!IS_ERR (mmc->supply.vmmc))mmc_regulator_set_ocr (mmc, mmc->supply.vmmc,0 );drivers/mmc/host/dw_mmc.c static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) · line 1458
Quoted 10 lines
drivers/mmc/host/dw_mmc.c +3
-3-if (!IS_ERR (mmc->supply.vqmmc) && slot->host->vqmmc_enabled) -regulator_disable (mmc->supply.vqmmc); - slot->host->vqmmc_enabled = false; +mmc_regulator_disable_vqmmc (mmc); regs =mci_readl (slot->host,PWREN ); regs &= ~(1 << slot->id);mci_writel (slot->host,PWREN , regs); +/* Reset our state machine after powering off */ +dw_mci_ctrl_reset (slot->host,SDMMC_CTRL_ALL_RESET_FLAGS );Previously this was done together with enabling the vqmmc, a few lines above. The corresponding code was introduced in commit
d1f1dd86006c"mmc:dw_mmc: Give a good reset after we give power". It's not exactly clear why the reset is needed at this particular point though.Quoted 5 lines
That said, at least we need to mention that we are moving the reset to the power-off phase and explain why in the commit message. Perhaps even better would be to preserve the old behaviour in the first step and then make this change being separate on top? Not sure if that makes sense though.
That doesn't work once we remove tracking of vqmmc status, because it will reset several times when enumerating, which mess up the IP status machine. That said, preserving the old behaviour breaks the bisectable.
Quoted 14 lines
The commit introduced this, is to slove failures on rk3288. The commit message said "vqmmc may actually be connected to the IP block in the SoC vqmmc may actually be connected to the IP block in the SoC" which doesn't clearly point out the fact is vqmmc is used for IO block associated with dw controller only . The reason is probably that when SD is removed during I/O, cutting off vqmmc in
MMC_POWER_OFFphase will confuse the controller as its status machine refers to several IO status, such as MC busy, so the controller could run into an unexpected state and could not enumerate cards correctly the next time. I vaguely remember there was a gap between Doug upstreamed it and Rockchip downstream kernel reset it on card-removal path. So I think either to reset it onMMC_POWER_ONphase or to reset it onMMC_POWER_OFFphase should work. I would keep it and explain that in commit message. Does this approach sound good to you?
Yes, this works for me, thanks for clarifying!
[...]
Kind regards
Uffe
Shawn Lin
maintainerPATCH v2 4/13 mmc: dw_mmc: Remove unused header files and keep alphabetical order
In reply to Shawn LinSome header files are not needed and they are out of order, this patch remove unused header files and re-order them alphabetically.
---
Changes in v2:
- add commit message
drivers/mmc/host/dw_mmc.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-)
drivers/mmc/host/dw_mmc.c +8 -15
@@ -7,35 +7,28 @@* Copyright (C) 2009, 2010 Imagination Technologies Ltd. */ -#include <linux/blkdev.h> +#include <linux/bitops.h> #include <linux/clk.h> #include <linux/debugfs.h> +#include <linux/delay.h> #include <linux/device.h> #include <linux/dma-mapping.h> #include <linux/err.h> -#include <linux/init.h> #include <linux/interrupt.h> #include <linux/iopoll.h> -#include <linux/ioport.h> -#include <linux/ktime.h> -#include <linux/module.h> -#include <linux/platform_device.h> -#include <linux/pm_runtime.h> -#include <linux/prandom.h> -#include <linux/seq_file.h> -#include <linux/slab.h> -#include <linux/stat.h> -#include <linux/delay.h> #include <linux/irq.h> +#include <linux/ktime.h> #include <linux/mmc/card.h> #include <linux/mmc/host.h> #include <linux/mmc/mmc.h> #include <linux/mmc/sd.h> #include <linux/mmc/sdio.h> -#include <linux/bitops.h> -#include <linux/regulator/consumer.h> -#include <linux/of.h> #include <linux/mmc/slot-gpio.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/pm_runtime.h> +#include <linux/regulator/consumer.h> #include "dw_mmc.h"
Signature · 1 line
2.7.4
Shawn Lin
maintainerPATCH v2 5/13 mmc: dw_mmc: Move struct mmc_host from struct dw_mci_slot to struct dw_mci
In reply to Shawn LinMove struct mmc_host to struct dw_mci in preparation for removing dw_mci_slot. No functional change intended.
---
Changes in v2: None
drivers/mmc/host/dw_mmc-exynos.c | 2 +- drivers/mmc/host/dw_mmc-hi3798cv200.c | 2 +- drivers/mmc/host/dw_mmc-hi3798mv200.c | 2 +- drivers/mmc/host/dw_mmc-k3.c | 2 +- drivers/mmc/host/dw_mmc-rockchip.c | 2 +- drivers/mmc/host/dw_mmc-starfive.c | 2 +- drivers/mmc/host/dw_mmc.c | 62 +++++++++++++++++------------------ drivers/mmc/host/dw_mmc.h | 4 +-- 8 files changed, 38 insertions(+), 40 deletions(-)
drivers/mmc/host/dw_mmc-exynos.c +1 -1
@@ -534,7 +534,7 @@ static int dw_mci_exynos_execute_tuning(struct dw_mci_slot *slot, u32 opcode) {struct dw_mci *host = slot->host;struct dw_mci_exynos_priv_data *priv = host->priv; -struct mmc_host *mmc = slot->mmc; +struct mmc_host *mmc = host->mmc;u8 start_smpl, smpl, candidates =0 ;s8 found;int ret =0 ;
drivers/mmc/host/dw_mmc-hi3798cv200.c +1 -1
@@ -72,7 +72,7 @@ static int dw_mci_hi3798cv200_execute_tuning(struct dw_mci_slot *slot,clk_set_phase (priv->sample_clk, degrees[i]);mci_writel (host,RINTSTS ,ALL_INT_CLR ); - err =mmc_send_tuning (slot->mmc, opcode,NULL ); + err =mmc_send_tuning (host->mmc, opcode,NULL );if (!err) found =1 ;
drivers/mmc/host/dw_mmc-hi3798mv200.c +1 -1
@@ -115,7 +115,7 @@ static int dw_mci_hi3798mv200_execute_tuning_mix_mode(struct dw_mci_slot *slot,* * Treat edge(flip) found as an error too. */ - err =mmc_send_tuning (slot->mmc, opcode,NULL ); + err =mmc_send_tuning (host->mmc, opcode,NULL ); regval =mci_readl (host,TUNING_CTRL );if (err || (regval &SDMMC_TUNING_FIND_EDGE )) err =1 ;
drivers/mmc/host/dw_mmc-k3.c +1 -1
@@ -368,7 +368,7 @@ static int dw_mci_hi3660_execute_tuning(struct dw_mci_slot *slot, u32 opcode) {int i =0 ;struct dw_mci *host = slot->host; -struct mmc_host *mmc = slot->mmc; +struct mmc_host *mmc = host->mmc;int smpl_phase =0 ;u32 tuning_sample_flag =0 ;int best_clksmpl =0 ;
drivers/mmc/host/dw_mmc-rockchip.c +1 -1
@@ -286,7 +286,7 @@ static int dw_mci_rk3288_execute_tuning(struct dw_mci_slot *slot, u32 opcode) {struct dw_mci *host = slot->host;struct dw_mci_rockchip_priv_data *priv = host->priv; -struct mmc_host *mmc = slot->mmc; +struct mmc_host *mmc = host->mmc;int ret =0 ;int i;bool v, prev_v =0 , first_v;
drivers/mmc/host/dw_mmc-starfive.c +1 -1
@@ -65,7 +65,7 @@ static int dw_mci_starfive_execute_tuning(struct dw_mci_slot *slot,dw_mci_starfive_set_sample_phase (host, smpl_phase);mci_writel (host,RINTSTS ,ALL_INT_CLR ); - ret =mmc_send_tuning (slot->mmc, opcode,NULL ); + ret =mmc_send_tuning (host->mmc, opcode,NULL );if (!ret && smpl_raise <0 ) { smpl_raise = smpl_phase;
drivers/mmc/host/dw_mmc.c +30 -32
207 lines not on this page · raw message
drivers/mmc/host/dw_mmc.h +2 -2
@@ -127,6 +127,7 @@ struct dw_mci_dma_slave {* @cmd11_timer: Timer for SD3.0 voltage switch over scheme. * @cto_timer: Timer for broken command transfer over scheme. * @dto_timer: Timer for broken data transfer over scheme. +* @mmc: The mmc_host representing this dw_mci. * * Locking * =======
@@ -240,6 +241,7 @@ struct dw_mci {struct fault_attr fail_data_crc;struct hrtimer fault_timer;#endif +struct mmc_host *mmc; };/* DMA ops for Internal/External DMAC interface */
@@ -543,7 +545,6 @@ static inline int dw_mci_runtime_resume(struct device *device) { return -EOPNOTS/** * struct dw_mci_slot - MMC slot state -* @mmc: The mmc_host representing this slot. * @host: The MMC controller this slot is using. * @ctype: Card type for this slot. * @mrq: mmc_request currently being processed or waiting to be
@@ -558,7 +559,6 @@ static inline int dw_mci_runtime_resume(struct device *device) { return -EOPNOTS* @sdio_id: Number of this slot in the SDIO interrupt registers. */ struct dw_mci_slot { -struct mmc_host *mmc;struct dw_mci *host;u32 ctype;
Signature · 1 line
2.7.4
Shawn Lin
maintainerPATCH v2 6/13 mmc: dw_mmc: Let glue drivers to use struct dw_mci as possible
In reply to Shawn LinThis patch changes the callbacks of switch_voltage() and execute_tuning() in order for glue drivers to avoid accessing to struct dw_mci_slot.
---
Changes in v2: None
drivers/mmc/host/dw_mmc-exynos.c | 3 +-- drivers/mmc/host/dw_mmc-hi3798cv200.c | 4 +--- drivers/mmc/host/dw_mmc-hi3798mv200.c | 15 +++++++-------- drivers/mmc/host/dw_mmc-k3.c | 19 +++++++------------ drivers/mmc/host/dw_mmc-rockchip.c | 3 +-- drivers/mmc/host/dw_mmc-starfive.c | 3 +-- drivers/mmc/host/dw_mmc.c | 4 ++-- drivers/mmc/host/dw_mmc.h | 4 ++-- 8 files changed, 22 insertions(+), 33 deletions(-)
drivers/mmc/host/dw_mmc-exynos.c +1 -2
@@ -530,9 +530,8 @@ static s8 dw_mci_exynos_get_best_clksmpl(u8 candidates)return loc; } -static int dw_mci_exynos_execute_tuning (struct dw_mci_slot *slot,u32 opcode) +static int dw_mci_exynos_execute_tuning (struct dw_mci *host,u32 opcode) { -struct dw_mci *host = slot->host;struct dw_mci_exynos_priv_data *priv = host->priv;struct mmc_host *mmc = host->mmc;u8 start_smpl, smpl, candidates =0 ;
drivers/mmc/host/dw_mmc-hi3798cv200.c +1 -3
@@ -57,11 +57,9 @@ static void dw_mci_hi3798cv200_set_ios(struct dw_mci *host, struct mmc_ios *ios)clk_set_phase (priv->drive_clk,135 ); } -static int dw_mci_hi3798cv200_execute_tuning (struct dw_mci_slot *slot, -u32 opcode) +static int dw_mci_hi3798cv200_execute_tuning (struct dw_mci *host,u32 opcode) {static const int degrees[] = {0 ,45 ,90 ,135 ,180 ,225 ,270 ,315 }; -struct dw_mci *host = slot->host;struct hi3798cv200_priv *priv = host->priv;int raise_point =-1 , fall_point =-1 ;int err, prev_err =-1 ;
drivers/mmc/host/dw_mmc-hi3798mv200.c +7 -8
@@ -74,25 +74,24 @@ static void dw_mci_hi3798mv200_set_ios(struct dw_mci *host, struct mmc_ios *ios) } } -static inline int dw_mci_hi3798mv200_enable_tuning (struct dw_mci_slot *slot) +static inline int dw_mci_hi3798mv200_enable_tuning (struct dw_mci *host) { -struct dw_mci_hi3798mv200_priv *priv = slot->host->priv; +struct dw_mci_hi3798mv200_priv *priv = host->priv;return regmap_clear_bits (priv->crg_reg, priv->sap_dll_offset,SAP_DLL_CTRL_DLLMODE ); } -static inline int dw_mci_hi3798mv200_disable_tuning (struct dw_mci_slot *slot) +static inline int dw_mci_hi3798mv200_disable_tuning (struct dw_mci *host) { -struct dw_mci_hi3798mv200_priv *priv = slot->host->priv; +struct dw_mci_hi3798mv200_priv *priv = host->priv;return regmap_set_bits (priv->crg_reg, priv->sap_dll_offset,SAP_DLL_CTRL_DLLMODE ); } -static int dw_mci_hi3798mv200_execute_tuning_mix_mode (struct dw_mci_slot *slot, +static int dw_mci_hi3798mv200_execute_tuning_mix_mode (struct dw_mci *host,u32 opcode) {static const int degrees[] = {0 ,45 ,90 ,135 ,180 ,225 ,270 ,315 }; -struct dw_mci *host = slot->host;struct dw_mci_hi3798mv200_priv *priv = host->priv;int raise_point =-1 , fall_point =-1 , mid;int err, prev_err =-1 ;
@@ -101,7 +100,7 @@ static int dw_mci_hi3798mv200_execute_tuning_mix_mode(struct dw_mci_slot *slot,int i;int ret; - ret =dw_mci_hi3798mv200_enable_tuning (slot); + ret =dw_mci_hi3798mv200_enable_tuning (host);if (ret <0 )return ret;
@@ -136,7 +135,7 @@ static int dw_mci_hi3798mv200_execute_tuning_mix_mode(struct dw_mci_slot *slot, } tuning_out: - ret =dw_mci_hi3798mv200_disable_tuning (slot); + ret =dw_mci_hi3798mv200_disable_tuning (host);if (ret <0 )return ret;
drivers/mmc/host/dw_mmc-k3.c +7 -12
@@ -138,15 +138,13 @@ static int dw_mci_hi6220_parse_dt(struct dw_mci *host)return 0 ; } -static int dw_mci_hi6220_switch_voltage (struct mmc_host *mmc,struct mmc_ios *ios) +static int dw_mci_hi6220_switch_voltage (struct dw_mci *host,struct mmc_ios *ios) { -struct dw_mci_slot *slot =mmc_priv (mmc);struct k3_priv *priv; -struct dw_mci *host; +struct mmc_host *mmc = host->mmc;int min_uv, max_uv;int ret; - host = slot->host; priv = host->priv;if (!priv || !priv->reg)
@@ -199,7 +197,7 @@ static void dw_mci_hi6220_set_ios(struct dw_mci *host, struct mmc_ios *ios) host->bus_hz =clk_get_rate (host->biu_clk); } -static int dw_mci_hi6220_execute_tuning (struct dw_mci_slot *slot,u32 opcode) +static int dw_mci_hi6220_execute_tuning (struct dw_mci *host,u32 opcode) {return 0 ; }
@@ -364,10 +362,9 @@ static int dw_mci_get_best_clksmpl(unsigned int sample_flag)return middle_range; } -static int dw_mci_hi3660_execute_tuning (struct dw_mci_slot *slot,u32 opcode) +static int dw_mci_hi3660_execute_tuning (struct dw_mci *host,u32 opcode) {int i =0 ; -struct dw_mci *host = slot->host;struct mmc_host *mmc = host->mmc;int smpl_phase =0 ;u32 tuning_sample_flag =0 ;
@@ -398,15 +395,13 @@ static int dw_mci_hi3660_execute_tuning(struct dw_mci_slot *slot, u32 opcode)return 0 ; } -static int dw_mci_hi3660_switch_voltage (struct mmc_host *mmc, +static int dw_mci_hi3660_switch_voltage (struct dw_mci *host,struct mmc_ios *ios) { -int ret =0 ; -struct dw_mci_slot *slot =mmc_priv (mmc);struct k3_priv *priv; -struct dw_mci *host; +struct mmc_host *mmc = host->mmc; +int ret =0 ; - host = slot->host; priv = host->priv;if (!priv || !priv->reg)
drivers/mmc/host/dw_mmc-rockchip.c +1 -2
@@ -282,9 +282,8 @@ static void dw_mci_rk3288_set_ios(struct dw_mci *host, struct mmc_ios *ios)#define TUNING_ITERATION_TO_PHASE (i, num_phases) \ (DIV_ROUND_UP((i) * 360, num_phases)) -static int dw_mci_rk3288_execute_tuning (struct dw_mci_slot *slot,u32 opcode) +static int dw_mci_rk3288_execute_tuning (struct dw_mci *host,u32 opcode) { -struct dw_mci *host = slot->host;struct dw_mci_rockchip_priv_data *priv = host->priv;struct mmc_host *mmc = host->mmc;int ret =0 ;
drivers/mmc/host/dw_mmc-starfive.c +1 -2
@@ -53,11 +53,10 @@ static void dw_mci_starfive_set_sample_phase(struct dw_mci *host, u32 smpl_phasemdelay (1 ); } -static int dw_mci_starfive_execute_tuning (struct dw_mci_slot *slot, +static int dw_mci_starfive_execute_tuning (struct dw_mci *host,u32 opcode) {static const int grade =MAX_DELAY_CHAIN ; -struct dw_mci *host = slot->host;int smpl_phase, smpl_raise =-1 , smpl_fall =-1 ;int ret;
drivers/mmc/host/dw_mmc.c +2 -2
@@ -1482,7 +1482,7 @@ static int dw_mci_switch_voltage(struct mmc_host *mmc, struct mmc_ios *ios)int ret;if (drv_data && drv_data->switch_voltage) -return drv_data->switch_voltage (mmc, ios); +return drv_data->switch_voltage (host, ios);/* * Program the voltage. Note that some instances of dw_mmc may use
@@ -1640,7 +1640,7 @@ static int dw_mci_execute_tuning(struct mmc_host *mmc, u32 opcode)int err = -EINVAL ;if (drv_data && drv_data->execute_tuning) - err = drv_data->execute_tuning (slot, opcode); + err = drv_data->execute_tuning (host, opcode);return err; }
drivers/mmc/host/dw_mmc.h +2 -2
@@ -604,10 +604,10 @@ struct dw_mci_drv_data {int (*init)(struct dw_mci *host);void (*set_ios)(struct dw_mci *host,struct mmc_ios *ios);int (*parse_dt)(struct dw_mci *host); -int (*execute_tuning)(struct dw_mci_slot *slot,u32 opcode); +int (*execute_tuning)(struct dw_mci *host,u32 opcode);int (*prepare_hs400_tuning)(struct dw_mci *host,struct mmc_ios *ios); -int (*switch_voltage)(struct mmc_host *mmc, +int (*switch_voltage)(struct dw_mci *host,struct mmc_ios *ios);void (*set_data_timeout)(struct dw_mci *host,unsigned int timeout_ns);
Signature · 1 line
2.7.4
Shawn Lin
maintainerPATCH v2 7/13 mmc: dw_mmc: Move flags from struct dw_mci_slot to struct dw_mci
In reply to Shawn LinWith this, dw_mmc-exynos.c will not need to access slot. BTW, the host->slot is always present when calling dw_mci_exynos_set_clksel_timing(), so remove it together.
---
Changes in v2: None
drivers/mmc/host/dw_mmc-exynos.c | 4 ++-- drivers/mmc/host/dw_mmc.c | 26 +++++++++++++------------- drivers/mmc/host/dw_mmc.h | 14 +++++++------- 3 files changed, 22 insertions(+), 22 deletions(-)
drivers/mmc/host/dw_mmc-exynos.c +2 -2
@@ -185,8 +185,8 @@ static void dw_mci_exynos_set_clksel_timing(struct dw_mci *host, u32 timing)* HOLD register should be bypassed in case there is no phase shift * applied on CMD/DATA that is sent to the card. */ -if (!SDMMC_CLKSEL_GET_DRV_WD3 (clksel) && host->slot) -set_bit (DW_MMC_CARD_NO_USE_HOLD , &host->slot->flags); +if (!SDMMC_CLKSEL_GET_DRV_WD3 (clksel)) +set_bit (DW_MMC_CARD_NO_USE_HOLD , &host->flags); }static int dw_mci_exynos_runtime_resume (struct device *dev)
drivers/mmc/host/dw_mmc.c +13 -13
@@ -304,7 +304,7 @@ static u32 dw_mci_prepare_command(struct mmc_host *mmc, struct mmc_command *cmd) cmdr |=SDMMC_CMD_DAT_WR ; } -if (!test_bit (DW_MMC_CARD_NO_USE_HOLD , &slot->flags)) +if (!test_bit (DW_MMC_CARD_NO_USE_HOLD , &host->flags)) cmdr |=SDMMC_CMD_USE_HOLD_REG ;return cmdr;
@@ -343,7 +343,7 @@ static u32 dw_mci_prep_stop_abort(struct dw_mci *host, struct mmc_command *cmd) cmdr = stop->opcode |SDMMC_CMD_STOP |SDMMC_CMD_RESP_CRC |SDMMC_CMD_RESP_EXP ; -if (!test_bit (DW_MMC_CARD_NO_USE_HOLD , &host->slot->flags)) +if (!test_bit (DW_MMC_CARD_NO_USE_HOLD , &host->flags)) cmdr |=SDMMC_CMD_USE_HOLD_REG ;return cmdr;
@@ -893,7 +893,7 @@ static int dw_mci_get_cd(struct mmc_host *mmc) || !mmc_card_is_removable(mmc))) { present =1 ; -if (!test_bit (DW_MMC_CARD_PRESENT , &slot->flags)) { +if (!test_bit (DW_MMC_CARD_PRESENT , &host->flags)) {if (mmc->caps &MMC_CAP_NEEDS_POLL ) {dev_info (&mmc->class_dev,"card is polling.\n" );
@@ -901,7 +901,7 @@ static int dw_mci_get_cd(struct mmc_host *mmc)dev_info (&mmc->class_dev,"card is non-removable.\n" ); } -set_bit (DW_MMC_CARD_PRESENT , &slot->flags); +set_bit (DW_MMC_CARD_PRESENT , &host->flags); }return present;
@@ -912,10 +912,10 @@ static int dw_mci_get_cd(struct mmc_host *mmc) == 0 ? 1 : 0;spin_lock_bh (&host->lock); -if (present && !test_and_set_bit (DW_MMC_CARD_PRESENT , &slot->flags)) +if (present && !test_and_set_bit (DW_MMC_CARD_PRESENT , &host->flags))dev_dbg (&mmc->class_dev,"card is present\n" );else if (!present && - !test_and_clear_bit (DW_MMC_CARD_PRESENT , &slot->flags)) + !test_and_clear_bit (DW_MMC_CARD_PRESENT , &host->flags))dev_dbg (&mmc->class_dev,"card is not present\n" );spin_unlock_bh (&host->lock);
@@ -1165,7 +1165,7 @@ static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit) div = (host->bus_hz != clock) ?DIV_ROUND_UP (div,2 ) :0 ;if ((clock != slot->__clk_old && - !test_bit (DW_MMC_CARD_NEEDS_POLL , &slot->flags)) || + !test_bit (DW_MMC_CARD_NEEDS_POLL , &host->flags)) || force_clkinit) {/* Silent the verbose log if calling from PM context */ if (!force_clkinit)
@@ -1181,7 +1181,7 @@ static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit)*/ if (host->mmc->caps &MMC_CAP_NEEDS_POLL && host->mmc->f_min == clock) -set_bit (DW_MMC_CARD_NEEDS_POLL , &slot->flags); +set_bit (DW_MMC_CARD_NEEDS_POLL , &host->flags); }/* disable clock */
@@ -1199,7 +1199,7 @@ static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit)/* enable clock; only low power if no SDIO */ clk_en_a =SDMMC_CLKEN_ENABLE << slot->id; -if (!test_bit (DW_MMC_CARD_NO_LOW_PWR , &slot->flags)) +if (!test_bit (DW_MMC_CARD_NO_LOW_PWR , &host->flags)) clk_en_a |=SDMMC_CLKEN_LOW_PWR << slot->id;mci_writel (host,CLKENA , clk_en_a);
@@ -1277,7 +1277,7 @@ static void __dw_mci_start_request(struct dw_mci *host, cmdflags =dw_mci_prepare_command (host->mmc, cmd);/* this is the first command, send the initialization clock */ -if (test_and_clear_bit (DW_MMC_CARD_NEED_INIT , &slot->flags)) +if (test_and_clear_bit (DW_MMC_CARD_NEED_INIT , &host->flags)) cmdflags |=SDMMC_CMD_INIT ;if (data) {
@@ -1424,7 +1424,7 @@ static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)/*return, if failed turn on vmmc*/ return ; } -set_bit (DW_MMC_CARD_NEED_INIT , &slot->flags); +set_bit (DW_MMC_CARD_NEED_INIT , &slot->host->flags); regs =mci_readl (slot->host,PWREN ); regs |= (1 << slot->id);mci_writel (slot->host,PWREN , regs);
@@ -1577,10 +1577,10 @@ static void dw_mci_prepare_sdio_irq(struct dw_mci_slot *slot, bool prepare) clk_en_a_old =mci_readl (host,CLKENA );if (prepare) { -set_bit (DW_MMC_CARD_NO_LOW_PWR , &slot->flags); +set_bit (DW_MMC_CARD_NO_LOW_PWR , &host->flags); clk_en_a = clk_en_a_old & ~clken_low_pwr; }else { -clear_bit (DW_MMC_CARD_NO_LOW_PWR , &slot->flags); +clear_bit (DW_MMC_CARD_NO_LOW_PWR , &host->flags); clk_en_a = clk_en_a_old | clken_low_pwr; }
drivers/mmc/host/dw_mmc.h +7 -7
@@ -128,6 +128,7 @@ struct dw_mci_dma_slave {* @cto_timer: Timer for broken command transfer over scheme. * @dto_timer: Timer for broken data transfer over scheme. * @mmc: The mmc_host representing this dw_mci. +* @flags: Random state bits associated with the host. * * Locking * =======
@@ -242,6 +243,12 @@ struct dw_mci {struct hrtimer fault_timer;#endif struct mmc_host *mmc; +unsigned long flags; +#define DW_MMC_CARD_PRESENT 0 +#define DW_MMC_CARD_NEED_INIT 1 +#define DW_MMC_CARD_NO_LOW_PWR 2 +#define DW_MMC_CARD_NO_USE_HOLD 3 +#define DW_MMC_CARD_NEEDS_POLL 4 };/* DMA ops for Internal/External DMAC interface */
@@ -554,7 +561,6 @@ static inline int dw_mci_runtime_resume(struct device *device) { return -EOPNOTS* @clock: Clock rate configured by set_ios(). Protected by host->lock. * @__clk_old: The last clock value that was requested from core. * Keeping track of this helps us to avoid spamming the console. -* @flags: Random state bits associated with the slot. * @id: Number of this slot. * @sdio_id: Number of this slot in the SDIO interrupt registers. */
@@ -569,12 +575,6 @@ struct dw_mci_slot {unsigned int clock;unsigned int __clk_old; -unsigned long flags; -#define DW_MMC_CARD_PRESENT 0 -#define DW_MMC_CARD_NEED_INIT 1 -#define DW_MMC_CARD_NO_LOW_PWR 2 -#define DW_MMC_CARD_NO_USE_HOLD 3 -#define DW_MMC_CARD_NEEDS_POLL 4int id;int sdio_id; };
Signature · 1 line
2.7.4
Shawn Lin
maintainerPATCH v2 8/13 mmc: dw_mmc: Remove id and ctype from dw_mci_slot
In reply to Shawn LinThere is only one slot support, id should be zero. So no need to keep it in track, and move ctype associated together.
---
Changes in v2:
- make commit message clear that we remove two things
drivers/mmc/host/dw_mmc.c | 41 ++++++++++++++++++++--------------------- drivers/mmc/host/dw_mmc.h | 7 ++----- 2 files changed, 22 insertions(+), 26 deletions(-)
drivers/mmc/host/dw_mmc.c +20 -21
@@ -282,7 +282,7 @@ static u32 dw_mci_prepare_command(struct mmc_host *mmc, struct mmc_command *cmd)* until the voltage change is all done. */ clk_en_a =mci_readl (host,CLKENA ); - clk_en_a &= ~(SDMMC_CLKEN_LOW_PWR << slot->id); + clk_en_a &= ~SDMMC_CLKEN_LOW_PWR ;mci_writel (host,CLKENA , clk_en_a);mci_send_cmd (slot,SDMMC_CMD_UPD_CLK |SDMMC_CMD_PRV_DAT_WAIT ,0 );
@@ -908,7 +908,7 @@ static int dw_mci_get_cd(struct mmc_host *mmc) }else if (gpio_cd >=0 ) present = gpio_cd;else - present = (mci_readl (slot->host,CDETECT ) & (1 << slot->id)) + present = (mci_readl (slot->host,CDETECT ) &BIT (0 )) ==0 ?1 :0 ;spin_lock_bh (&host->lock);
@@ -1170,8 +1170,8 @@ static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit)/* Silent the verbose log if calling from PM context */ if (!force_clkinit)dev_info (&host->mmc->class_dev, -"Bus speed (slot %d) = %dHz (slot req %dHz, actual %dHZ div = %d)\n" , - slot->id, host->bus_hz, clock, +"Bus speed = %dHz (slot req %dHz, actual %dHZ div = %d)\n" , + host->bus_hz, clock, div ? ((host->bus_hz / div) >>1 ) : host->bus_hz, div);
@@ -1198,9 +1198,9 @@ static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit)mci_send_cmd (slot, sdmmc_cmd_bits,0 );/* enable clock; only low power if no SDIO */ - clk_en_a =SDMMC_CLKEN_ENABLE << slot->id; + clk_en_a =SDMMC_CLKEN_ENABLE ;if (!test_bit (DW_MMC_CARD_NO_LOW_PWR , &host->flags)) - clk_en_a |=SDMMC_CLKEN_LOW_PWR << slot->id; + clk_en_a |=SDMMC_CLKEN_LOW_PWR ;mci_writel (host,CLKENA , clk_en_a);/* inform CIU */
@@ -1215,7 +1215,7 @@ static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit) host->current_speed = clock;/* Set the current slot bus width */ -mci_writel (host,CTYPE , (slot->ctype << slot->id)); +mci_writel (host,CTYPE , host->ctype); } static void dw_mci_set_data_timeout(struct dw_mci *host,
@@ -1383,14 +1383,14 @@ static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)switch (ios->bus_width) {case MMC_BUS_WIDTH_4 : - slot->ctype =SDMMC_CTYPE_4BIT ; + slot->host->ctype =SDMMC_CTYPE_4BIT ;break ;case MMC_BUS_WIDTH_8 : - slot->ctype =SDMMC_CTYPE_8BIT ; + slot->host->ctype =SDMMC_CTYPE_8BIT ;break ;default :/* set default 1 bit mode */ - slot->ctype =SDMMC_CTYPE_1BIT ; + slot->host->ctype =SDMMC_CTYPE_1BIT ; } regs =mci_readl (slot->host,UHS_REG );
@@ -1399,9 +1399,9 @@ static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)if (ios->timing ==MMC_TIMING_MMC_DDR52 || ios->timing ==MMC_TIMING_UHS_DDR50 || ios->timing ==MMC_TIMING_MMC_HS400 ) - regs |= ((0x1 << slot->id) <<16 ); + regs |=BIT (16 );else - regs &= ~((0x1 << slot->id) <<16 ); + regs &= ~BIT (16 );mci_writel (slot->host,UHS_REG , regs); slot->host->timing = ios->timing;
@@ -1426,7 +1426,7 @@ static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) }set_bit (DW_MMC_CARD_NEED_INIT , &slot->host->flags); regs =mci_readl (slot->host,PWREN ); - regs |= (1 << slot->id); + regs |=BIT (0 );mci_writel (slot->host,PWREN , regs);break ;case MMC_POWER_ON :
@@ -1445,7 +1445,7 @@ static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)mmc_regulator_disable_vqmmc (mmc); regs =mci_readl (slot->host,PWREN ); - regs &= ~(1 << slot->id); + regs &= ~BIT (0 );mci_writel (slot->host,PWREN , regs);/* Reset our state machine after powering off */ dw_mci_ctrl_reset (slot->host,SDMMC_CTRL_ALL_RESET_FLAGS );
@@ -1478,7 +1478,7 @@ static int dw_mci_switch_voltage(struct mmc_host *mmc, struct mmc_ios *ios)struct dw_mci *host = slot->host;const struct dw_mci_drv_data *drv_data = host->drv_data;u32 uhs; -u32 v18 =SDMMC_UHS_18V << slot->id; +u32 v18 =SDMMC_UHS_18V ;int ret;if (drv_data && drv_data->switch_voltage)
@@ -1520,7 +1520,7 @@ static int dw_mci_get_ro(struct mmc_host *mmc) read_only = gpio_ro; else read_only = -mci_readl (slot->host,WRTPRT ) & (1 << slot->id) ?1 :0 ; +mci_readl (slot->host,WRTPRT ) &BIT (0 ) ?1 :0 ;dev_dbg (&mmc->class_dev,"card is %s\n" , read_only ?"read-only" :"read-write" );
@@ -1554,10 +1554,10 @@ static void dw_mci_hw_reset(struct mmc_host *mmc)* tRSTH >= 1us: RST_n high period */ reset =mci_readl (host,RST_N ); - reset &= ~(SDMMC_RST_HWACTIVE << slot->id); + reset &= ~SDMMC_RST_HWACTIVE ;mci_writel (host,RST_N , reset);usleep_range (1 ,2 ); - reset |=SDMMC_RST_HWACTIVE << slot->id; + reset |=SDMMC_RST_HWACTIVE ;mci_writel (host,RST_N , reset);usleep_range (200 ,300 ); }
@@ -1565,7 +1565,7 @@ static void dw_mci_hw_reset(struct mmc_host *mmc)static void dw_mci_prepare_sdio_irq (struct dw_mci_slot *slot,bool prepare) {struct dw_mci *host = slot->host; -const u32 clken_low_pwr =SDMMC_CLKEN_LOW_PWR << slot->id; +const u32 clken_low_pwr =SDMMC_CLKEN_LOW_PWR ;u32 clk_en_a_old;u32 clk_en_a;
@@ -2926,8 +2926,7 @@ static int dw_mci_init_slot(struct dw_mci *host)return -ENOMEM ; slot =mmc_priv (mmc); - slot->id =0 ; - slot->sdio_id = host->sdio_id0 + slot->id; + slot->sdio_id = host->sdio_id0; host->mmc = mmc; slot->host = host; host->slot = slot;
drivers/mmc/host/dw_mmc.h +2 -5
@@ -129,6 +129,7 @@ struct dw_mci_dma_slave {* @dto_timer: Timer for broken data transfer over scheme. * @mmc: The mmc_host representing this dw_mci. * @flags: Random state bits associated with the host. +* @ctype: Card type for this host. * * Locking * =======
@@ -249,6 +250,7 @@ struct dw_mci {#define DW_MMC_CARD_NO_LOW_PWR 2#define DW_MMC_CARD_NO_USE_HOLD 3#define DW_MMC_CARD_NEEDS_POLL 4 +u32 ctype; };/* DMA ops for Internal/External DMAC interface */
@@ -553,7 +555,6 @@ static inline int dw_mci_runtime_resume(struct device *device) { return -EOPNOTS/** * struct dw_mci_slot - MMC slot state * @host: The MMC controller this slot is using. -* @ctype: Card type for this slot. * @mrq: mmc_request currently being processed or waiting to be * processed, or NULL when the slot is idle. * @queue_node: List node for placing this node in the @queue list of
@@ -561,21 +562,17 @@ static inline int dw_mci_runtime_resume(struct device *device) { return -EOPNOTS* @clock: Clock rate configured by set_ios(). Protected by host->lock. * @__clk_old: The last clock value that was requested from core. * Keeping track of this helps us to avoid spamming the console. -* @id: Number of this slot. * @sdio_id: Number of this slot in the SDIO interrupt registers. */ struct dw_mci_slot {struct dw_mci *host; -u32 ctype; -struct mmc_request *mrq;struct list_head queue_node;unsigned int clock;unsigned int __clk_old; -int id;int sdio_id; };
Signature · 1 line
2.7.4
Shawn Lin
maintainerPATCH v2 9/13 mmc: dw_mmc: Remove sdio_id from struct dw_mci_slot
In reply to Shawn LinThere is only one slot support, the sdio_id is used to indicate the SDIO slot and where is the irq located. So it's pointless now, remove it. Given sdio_id0 is only used by Rockchip to inform dwc core the irq is located with a offset, rename sdio_id0 to sdio_irq to reflect the fact.
---
Changes in v2: None
drivers/mmc/host/dw_mmc-rockchip.c | 4 ++-- drivers/mmc/host/dw_mmc.c | 9 ++++----- drivers/mmc/host/dw_mmc.h | 7 ++----- 3 files changed, 8 insertions(+), 12 deletions(-)
drivers/mmc/host/dw_mmc-rockchip.c +2 -2
@@ -474,8 +474,8 @@ static int dw_mci_rockchip_init(struct dw_mci *host)struct dw_mci_rockchip_priv_data *priv = host->priv;int ret, i; -/* It is slot 8 on Rockchip SoCs */ - host->sdio_id0 =8 ; +/* SDIO irq is the 8th on Rockchip SoCs */ + host->sdio_irq =8 ;if (of_device_is_compatible (host->dev->of_node,"rockchip,rk3288-dw-mshc" )) { host->bus_hz /=RK3288_CLKGEN_DIV ;
drivers/mmc/host/dw_mmc.c +4 -5
@@ -1602,9 +1602,9 @@ static void __dw_mci_enable_sdio_irq(struct dw_mci_slot *slot, int enb)/* Enable/disable Slot Specific SDIO interrupt */ int_mask =mci_readl (host,INTMASK );if (enb) - int_mask |=SDMMC_INT_SDIO (slot->sdio_id); + int_mask |=SDMMC_INT_SDIO (host->sdio_irq);else - int_mask &= ~SDMMC_INT_SDIO (slot->sdio_id); + int_mask &= ~SDMMC_INT_SDIO (host->sdio_irq);mci_writel (host,INTMASK , int_mask);spin_unlock_irqrestore (&host->irq_lock, irqflags);
@@ -2827,9 +2827,9 @@ static irqreturn_t dw_mci_interrupt(int irq, void *dev_id)dw_mci_handle_cd (host); } -if (pending &SDMMC_INT_SDIO (slot->sdio_id)) { +if (pending &SDMMC_INT_SDIO (host->sdio_irq)) {mci_writel (host,RINTSTS , -SDMMC_INT_SDIO (slot->sdio_id)); +SDMMC_INT_SDIO (host->sdio_irq));__dw_mci_enable_sdio_irq (slot,0 );sdio_signal_irq (host->mmc); }
@@ -2926,7 +2926,6 @@ static int dw_mci_init_slot(struct dw_mci *host)return -ENOMEM ; slot =mmc_priv (mmc); - slot->sdio_id = host->sdio_id0; host->mmc = mmc; slot->host = host; host->slot = slot;
drivers/mmc/host/dw_mmc.h +2 -5
@@ -123,7 +123,7 @@ struct dw_mci_dma_slave {* @quirks: Set of quirks that apply to specific versions of the IP. * @irq_flags: The flags to be passed to request_irq. * @irq: The irq value to be passed to request_irq. -* @sdio_id0: Number of slot0 in the SDIO interrupt registers. +* @sdio_irq: SDIO interrupt bit in interrupt registers. * @cmd11_timer: Timer for SD3.0 voltage switch over scheme. * @cto_timer: Timer for broken command transfer over scheme. * @dto_timer: Timer for broken data transfer over scheme.
@@ -233,7 +233,7 @@ struct dw_mci {unsigned long irq_flags;/* IRQ flags */ int irq; -int sdio_id0; +int sdio_irq;struct timer_list cmd11_timer;struct timer_list cto_timer;
@@ -562,7 +562,6 @@ static inline int dw_mci_runtime_resume(struct device *device) { return -EOPNOTS* @clock: Clock rate configured by set_ios(). Protected by host->lock. * @__clk_old: The last clock value that was requested from core. * Keeping track of this helps us to avoid spamming the console. -* @sdio_id: Number of this slot in the SDIO interrupt registers. */ struct dw_mci_slot {struct dw_mci *host;
@@ -572,8 +571,6 @@ struct dw_mci_slot {unsigned int clock;unsigned int __clk_old; - -int sdio_id; };/**
Signature · 1 line
2.7.4
Shawn Lin
maintainerPATCH v2 10/13 mmc: dw_mmc: Move clock rate stuff from struct dw_mci_slot to struct dw_mci
In reply to Shawn LinExcept for moving them, this patch also renames __clk_old to clk_old.
---
Changes in v2: None
drivers/mmc/host/dw_mmc.c | 8 ++++---- drivers/mmc/host/dw_mmc.h | 9 ++++----- 2 files changed, 8 insertions(+), 9 deletions(-)
drivers/mmc/host/dw_mmc.c +4 -4
@@ -1139,7 +1139,7 @@ static void dw_mci_submit_data(struct dw_mci *host, struct mmc_data *data)static void dw_mci_setup_bus (struct dw_mci_slot *slot,bool force_clkinit) {struct dw_mci *host = slot->host; -unsigned int clock = slot->clock; +unsigned int clock = host->clock;u32 div;u32 clk_en_a;u32 sdmmc_cmd_bits =SDMMC_CMD_UPD_CLK |SDMMC_CMD_PRV_DAT_WAIT ;
@@ -1164,7 +1164,7 @@ static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit) div = (host->bus_hz != clock) ?DIV_ROUND_UP (div,2 ) :0 ; -if ((clock != slot->__clk_old && +if ((clock != host->clk_old && !test_bit (DW_MMC_CARD_NEEDS_POLL , &host->flags)) || force_clkinit) {/* Silent the verbose log if calling from PM context */
@@ -1207,7 +1207,7 @@ static void dw_mci_setup_bus(struct dw_mci_slot *slot, bool force_clkinit)mci_send_cmd (slot, sdmmc_cmd_bits,0 );/* keep the last clock value that was requested from core */ - slot->__clk_old = clock; + host->clk_old = clock; host->mmc->actual_clock = div ? ((host->bus_hz / div) >>1 ) : host->bus_hz; }
@@ -1410,7 +1410,7 @@ static void dw_mci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)* Use mirror of ios->clock to prevent race with mmc * core ios update when finding the minimum. */ - slot->clock = ios->clock; + slot->host->clock = ios->clock;if (drv_data && drv_data->set_ios) drv_data->set_ios (slot->host, ios);
drivers/mmc/host/dw_mmc.h +4 -5
@@ -130,6 +130,8 @@ struct dw_mci_dma_slave {* @mmc: The mmc_host representing this dw_mci. * @flags: Random state bits associated with the host. * @ctype: Card type for this host. +* @clock: Clock rate configured by set_ios(). Protected by host->lock. +* @clk_old: The last clock value that was requested from core. * * Locking * =======
@@ -251,6 +253,8 @@ struct dw_mci {#define DW_MMC_CARD_NO_USE_HOLD 3#define DW_MMC_CARD_NEEDS_POLL 4u32 ctype; +unsigned int clock; +unsigned int clk_old; };/* DMA ops for Internal/External DMAC interface */
@@ -559,8 +563,6 @@ static inline int dw_mci_runtime_resume(struct device *device) { return -EOPNOTS* processed, or NULL when the slot is idle. * @queue_node: List node for placing this node in the @queue list of * &struct dw_mci. -* @clock: Clock rate configured by set_ios(). Protected by host->lock. -* @__clk_old: The last clock value that was requested from core. * Keeping track of this helps us to avoid spamming the console. */ struct dw_mci_slot {
@@ -568,9 +570,6 @@ struct dw_mci_slot {struct mmc_request *mrq;struct list_head queue_node; - -unsigned int clock; -unsigned int __clk_old; };/**
Signature · 1 line
2.7.4
Shawn Lin
maintainerPATCH v2 11/13 mmc: dw_mmc: Remove mrq from struct dw_mci_slot
In reply to Shawn Linstruct dw_mci has already kept mrq, so removing keeping mrq again from struct dw_mci_slot.
---
Changes in v2: None
drivers/mmc/host/dw_mmc.c | 11 +++++------ drivers/mmc/host/dw_mmc.h | 4 +--- 2 files changed, 6 insertions(+), 9 deletions(-)
drivers/mmc/host/dw_mmc.c +5 -6
@@ -108,7 +108,7 @@ static int dw_mci_req_show(struct seq_file *s, void *v)/* Make sure we get a consistent snapshot */ spin_lock_bh (&slot->host->lock); - mrq = slot->mrq; + mrq = slot->host->mrq;if (mrq) { cmd = mrq->cmd;
@@ -1257,7 +1257,7 @@ static void __dw_mci_start_request(struct dw_mci *host,struct mmc_data *data;u32 cmdflags; - mrq = slot->mrq; + mrq = host->mrq; host->mrq = mrq;
@@ -1313,7 +1313,7 @@ static void __dw_mci_start_request(struct dw_mci *host,static void dw_mci_start_request (struct dw_mci *host,struct dw_mci_slot *slot) { -struct mmc_request *mrq = slot->mrq; +struct mmc_request *mrq = host->mrq;struct mmc_command *cmd; cmd = mrq->sbc ? mrq->sbc : mrq->cmd;
@@ -1327,7 +1327,7 @@ static void dw_mci_queue_request(struct dw_mci *host, struct dw_mci_slot *slot,dev_vdbg (&host->mmc->class_dev,"queue request: state=%d\n" , host->state); - slot->mrq = mrq; + host->mrq = mrq;if (host->state ==STATE_WAITING_CMD11_DONE ) { dev_warn(&host->mmc->class_dev,
@@ -1353,7 +1353,7 @@ static void dw_mci_request(struct mmc_host *mmc, struct mmc_request *mrq)struct dw_mci_slot *slot =mmc_priv (mmc);struct dw_mci *host = slot->host; -WARN_ON (slot->mrq); +WARN_ON (host->mrq);/* * The check for card presence and queueing of the request must be
@@ -1815,7 +1815,6 @@ static void dw_mci_request_end(struct dw_mci *host, struct mmc_request *mrq)WARN_ON (host->cmd || host->data); - host->slot->mrq =NULL ; host->mrq =NULL ;if (!list_empty (&host->queue)) { slot = list_entry(host->queue.next,
drivers/mmc/host/dw_mmc.h +1 -3
@@ -64,7 +64,7 @@ struct dw_mci_dma_slave {* @fifo_reg: Pointer to MMIO registers for data FIFO * @sg: Scatterlist entry currently being processed by PIO code, if any. * @sg_miter: PIO mapping scatterlist iterator. -* @mrq: The request currently being processed on @slot, +* @mrq: The request currently being processed on @host, * or NULL if the controller is idle. * @cmd: The command currently being sent to the card, or NULL. * @data: The data currently being transferred, or NULL if no data
@@ -559,7 +559,6 @@ static inline int dw_mci_runtime_resume(struct device *device) { return -EOPNOTS/** * struct dw_mci_slot - MMC slot state * @host: The MMC controller this slot is using. -* @mrq: mmc_request currently being processed or waiting to be * processed, or NULL when the slot is idle. * @queue_node: List node for placing this node in the @queue list of * &struct dw_mci.
@@ -568,7 +567,6 @@ static inline int dw_mci_runtime_resume(struct device *device) { return -EOPNOTSstruct dw_mci_slot {struct dw_mci *host; -struct mmc_request *mrq;struct list_head queue_node; };
Signature · 1 line
2.7.4
Shawn Lin
maintainerPATCH v2 12/13 mmc: dw_mmc: Remove queue from dw_mci
In reply to Shawn LinIt's pointless to use a queue if only one slot is supported.
---
Changes in v2:
- remove a unused code
drivers/mmc/host/dw_mmc.c | 23 ++++------------------- drivers/mmc/host/dw_mmc.h | 9 ++------- 2 files changed, 6 insertions(+), 26 deletions(-)
drivers/mmc/host/dw_mmc.c +4 -19
@@ -1343,8 +1343,6 @@ static void dw_mci_queue_request(struct dw_mci *host, struct dw_mci_slot *slot,if (host->state ==STATE_IDLE ) { host->state =STATE_SENDING_CMD ;dw_mci_start_request (host, slot); - }else { -list_add_tail (&slot->queue_node, &host->queue); } }
@@ -1810,28 +1808,16 @@ static void dw_mci_request_end(struct dw_mci *host, struct mmc_request *mrq) __releases(&host->lock) __acquires(&host->lock) { -struct dw_mci_slot *slot;struct mmc_host *prev_mmc = host->mmc;WARN_ON (host->cmd || host->data); host->mrq =NULL ; -if (!list_empty (&host->queue)) { - slot =list_entry (host->queue.next, - struct dw_mci_slot, queue_node); -list_del (&slot->queue_node); -dev_vdbg (host->dev,"list not empty: %s is next\n" , -mmc_hostname (host->mmc)); - host->state =STATE_SENDING_CMD ; -dw_mci_start_request (host, slot); - }else { -dev_vdbg (host->dev,"list empty\n" ); -if (host->state ==STATE_SENDING_CMD11 ) - host->state =STATE_WAITING_CMD11_DONE ; -else - host->state =STATE_IDLE ; - } +if (host->state ==STATE_SENDING_CMD11 ) + host->state =STATE_WAITING_CMD11_DONE ; +else + host->state =STATE_IDLE ;spin_unlock (&host->lock);mmc_request_done (prev_mmc, mrq);
@@ -3352,7 +3338,6 @@ int dw_mci_probe(struct dw_mci *host)spin_lock_init (&host->lock);spin_lock_init (&host->irq_lock); -INIT_LIST_HEAD (&host->queue);dw_mci_init_fault (host);
drivers/mmc/host/dw_mmc.h +2 -7
@@ -96,7 +96,6 @@ struct dw_mci_dma_slave {* @completed_events: Bitmask of events which the state machine has * processed. * @state: BH work state. -* @queue: List of slots waiting for access to the controller. * @bus_hz: The rate of @mck in Hz. This forms the basis for MMC bus * rate and timeout calculations. * @current_speed: Configured rate of the controller.
@@ -136,12 +135,12 @@ struct dw_mci_dma_slave {* Locking * ======= * -* @lock is a softirq-safe spinlock protecting @queue as well as +* @lock is a softirq-safe spinlock protecting as well as * @slot, @mrq and @state. These must always be updated * at the same time while holding @lock. * The @mrq field of struct dw_mci_slot is also protected by @lock, * and must always be written at the same time as the slot is added to -* @queue. +* @host. * * @irq_lock is an irq-safe spinlock protecting the INTMASK register * to allow the interrupt handler to modify it directly. Held for only long
@@ -203,7 +202,6 @@ struct dw_mci {unsigned long pending_events;unsigned long completed_events;enum dw_mci_state state; -struct list_head queue;u32 bus_hz;u32 current_speed;
@@ -560,14 +558,11 @@ static inline int dw_mci_runtime_resume(struct device *device) { return -EOPNOTS* struct dw_mci_slot - MMC slot state * @host: The MMC controller this slot is using. * processed, or NULL when the slot is idle. -* @queue_node: List node for placing this node in the @queue list of * &struct dw_mci. * Keeping track of this helps us to avoid spamming the console. */ struct dw_mci_slot {struct dw_mci *host; - -struct list_head queue_node; };/**
Signature · 1 line
2.7.4
Shawn Lin
maintainerPATCH v2 13/13 mmc: dw_mmc: Remove struct dw_mci_slot
In reply to Shawn LinThis patch sets struct dw_mci as mmc_host's private data by copying struct dw_mci passing to dw_mci_probe() in order to achieve with mminimal changes. Then we remove slot everywhere.
---
Changes in v2:
- Fix dma_set_mask_and_coherent mistake by code rebase
- fix compile warning
drivers/mmc/host/dw_mmc-pltfm.c | 2 +- drivers/mmc/host/dw_mmc.c | 250 ++++++++++++++++++---------------------- drivers/mmc/host/dw_mmc.h | 22 +--- 3 files changed, 120 insertions(+), 154 deletions(-)
drivers/mmc/host/dw_mmc-pltfm.c +1 -1
@@ -45,6 +45,7 @@ int dw_mci_pltfm_register(struct platform_device *pdev, host->dev = &pdev->dev; host->irq_flags =0 ; host->pdata = pdev->dev.platform_data; + host->pdev = pdev; host->regs =devm_platform_get_and_ioremap_resource (pdev,0 , ®s);if (IS_ERR (host->regs))
@@ -53,7 +54,6 @@ int dw_mci_pltfm_register(struct platform_device *pdev,/* Get registers' physical base address */ host->phy_regs = regs->start; -platform_set_drvdata (pdev, host);return dw_mci_probe (host); }EXPORT_SYMBOL_GPL (dw_mci_pltfm_register);
drivers/mmc/host/dw_mmc.c +115 -135
699 lines not on this page · raw message
drivers/mmc/host/dw_mmc.h +4 -18
@@ -57,7 +57,7 @@ struct dw_mci_dma_slave { };/** -* struct dw_mci - MMC controller state shared between all slots +* struct dw_mci - MMC controller state * @lock: Spinlock protecting the queue and associated data. * @irq_lock: Spinlock protecting the INTMASK setting. * @regs: Pointer to MMIO registers.
@@ -108,7 +108,6 @@ struct dw_mci_dma_slave {* @priv: Implementation defined private data. * @biu_clk: Pointer to bus interface unit clock instance. * @ciu_clk: Pointer to card interface unit clock instance. -* @slot: Slots sharing this MMC controller. * @fifo_depth: depth of FIFO. * @data_addr_override: override fifo reg offset with this value. * @wm_aligned: force fifo watermark equal with data length in PIO mode.
@@ -131,16 +130,14 @@ struct dw_mci_dma_slave {* @ctype: Card type for this host. * @clock: Clock rate configured by set_ios(). Protected by host->lock. * @clk_old: The last clock value that was requested from core. +* @pdev: platform_device registered * * Locking * ======= * * @lock is a softirq-safe spinlock protecting as well as -* @slot, @mrq and @state. These must always be updated +* @mrq and @state. These must always be updated * at the same time while holding @lock. -* The @mrq field of struct dw_mci_slot is also protected by @lock, -* and must always be written at the same time as the slot is added to -* @host. * * @irq_lock is an irq-safe spinlock protecting the INTMASK register * to allow the interrupt handler to modify it directly. Held for only long
@@ -214,7 +211,6 @@ struct dw_mci {void *priv;struct clk *biu_clk;struct clk *ciu_clk; -struct dw_mci_slot *slot;/* FIFO push and pull */ int fifo_depth;
@@ -253,6 +249,7 @@ struct dw_mci {u32 ctype;unsigned int clock;unsigned int clk_old; +struct platform_device *pdev; };/* DMA ops for Internal/External DMAC interface */
@@ -555,17 +552,6 @@ static inline int dw_mci_runtime_resume(struct device *device) { return -EOPNOTS#endif /** -* struct dw_mci_slot - MMC slot state -* @host: The MMC controller this slot is using. -* processed, or NULL when the slot is idle. -* &struct dw_mci. -* Keeping track of this helps us to avoid spamming the console. -*/ -struct dw_mci_slot { -struct dw_mci *host; -}; - -/** * dw_mci driver data - dw-mshc implementation specific driver data. * @caps: mmc subsystem specified capabilities of the controller(s). * @num_caps: number of capabilities specified by @caps.
Signature · 1 line
2.7.4
Quoted 59 lines · Shawn Lin
Hi Ulf & Jaehoon
As you can see,
dw_mmcis likely one of the most complex and difficult-to-read host driver at present. It maintains various states and bottom-half scheduling, containing a significant amount of redundant code—including a multi-slot mechanism that has been unsupported for over a decade.Jaehoon attempted to remove
cur_slotmore than ten years ago, but the driver still retains the slot structure and the associated queue mechanism designed to support multiple slots. This has made the already complex code even harder to read and maintain.The first four patches aim to eliminate some of the redundant code, while the remaining patches are intended to ultimately remove the
dw_mci_slotvariable. To facilitate review and minimize the risk of regression, each patch is designed to accomplish a single, clear objective.This series have been tested on the RK3588S EVB1 platform.
Changes in v2:
- Fix sparse warning
- Use helpers fromregulator.cand remove check formmc_regulator_set_ocr.
- add commit message
- make commit message clear that we remove two things
- remove a unused code
- Fixdma_set_mask_and_coherentmistake by code rebase
- fix compile warningShawn Lin (13):
mmc:dw_mmc: Remove unused structdma_pdata
mmc:dw_mmc: adddw_mci_prepare_desc()for both of 32bit and 64bit DMA
mmc:dw_mmc: Removevqmmc_enabledfrom structdw_mciand user helpers
from core
mmc:dw_mmc: Remove unused header files and keep alphabetical order
mmc:dw_mmc: Move structmmc_hostfrom structdw_mci_slotto struct
dw_mci
mmc:dw_mmc: Let glue drivers to use structdw_mcias possible
mmc:dw_mmc: Move flags from structdw_mci_slotto structdw_mci
mmc:dw_mmc: Remove id and ctype fromdw_mci_slot
mmc:dw_mmc: Removesdio_idfrom structdw_mci_slot
mmc:dw_mmc: Move clock rate stuff from structdw_mci_slotto struct
dw_mci
mmc:dw_mmc: Remove mrq from structdw_mci_slot
mmc:dw_mmc: Remove queue fromdw_mci
mmc:dw_mmc: Remove structdw_mci_slotdrivers/mmc/host/dw_mmc-exynos.c | 9 +- drivers/mmc/host/dw_mmc-hi3798cv200.c | 6 +- drivers/mmc/host/dw_mmc-hi3798mv200.c | 17 +- drivers/mmc/host/dw_mmc-k3.c | 21 +- drivers/mmc/host/dw_mmc-pltfm.c | 2 +- drivers/mmc/host/dw_mmc-rockchip.c | 9 +- drivers/mmc/host/dw_mmc-starfive.c | 5 +- drivers/mmc/host/dw_mmc.c | 621 ++++++++++++++-------------------- drivers/mmc/host/dw_mmc.h | 83 ++--- 9 files changed, 302 insertions(+), 471 deletions(-)
Quoted 3 lines
--
2.7.4
To start moving forward, I decided to apply patch1 and patch2 for next, thanks!
Kind regards
Uffe