Add DesignWare Mobile mmc driver
Subsystems (3)
cover Add DesignWare Mobile mmc driver
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
We added Synopsys DesignWare mmc cmdq driver and also added Realtek mmc driver to make good use of it.
Jyan Chou (3):
[01/03] mmc: solve DMA boundary limitation of CQHCI driver [02/03] mmc: Add Synopsys DesignWare mmc cmdq host driver [03/03] mmc: Add dw mobile mmc cmdq rtk driver
drivers/mmc/host/Kconfig | 22 + drivers/mmc/host/Makefile | 2 + drivers/mmc/host/cqhci-core.c | 5 + drivers/mmc/host/cqhci.h | 2 + drivers/mmc/host/dw_mmc_cqe-rtk.c | 998 ++++++++++++++++++ drivers/mmc/host/dw_mmc_cqe-rtk.h | 159 +++ drivers/mmc/host/dw_mmc_cqe.c | 1634 +++++++++++++++++++++++++++++ drivers/mmc/host/dw_mmc_cqe.h | 443 ++++++++ 8 files changed, 3265 insertions(+) create mode 100644 drivers/mmc/host/dw_mmc_cqe-rtk.c create mode 100644 drivers/mmc/host/dw_mmc_cqe-rtk.h create mode 100644 drivers/mmc/host/dw_mmc_cqe.c create mode 100644 drivers/mmc/host/dw_mmc_cqe.h
Signature · 1 line
2.42.0
PATCH 1/3 mmc: solve DMA boundary limitation of CQHCI driver
Due to synopsys data book's description, it had a limitation while using DMA that buffer size and start address must not exceed 128 MB.
We add an option setup_tran_desc to make tran_desc setting flexible.
---
v0 to v1 change:
1. Separate different patch supports into single patch.
--- drivers/mmc/host/cqhci-core.c | 5 +++++ drivers/mmc/host/cqhci.h | 2 ++ 2 files changed, 7 insertions(+)
drivers/mmc/host/cqhci-core.c +5 -0
@@ -516,6 +516,11 @@ static int cqhci_prep_tran_desc(struct mmc_request *mrq, desc =get_trans_desc (cq_host, tag); +if (cq_host->ops->setup_tran_desc) { + cq_host->ops->setup_tran_desc (data, cq_host, desc, sg_count); +return 0 ; + } +for_each_sg (data->sg, sg, sg_count, i) { addr =sg_dma_address (sg); len =sg_dma_len (sg);
drivers/mmc/host/cqhci.h +2 -0
@@ -289,6 +289,8 @@ struct cqhci_host_ops { u64 *data);void (*pre_enable)(struct mmc_host *mmc);void (*post_disable)(struct mmc_host *mmc); +void (*setup_tran_desc)(struct mmc_data *data, +struct cqhci_host *cq_host,u8 *desc,int sg_count);#ifdef CONFIG_MMC_CRYPTO int (*program_key)(struct cqhci_host *cq_host,const union cqhci_crypto_cfg_entry *cfg,int slot);
Signature · 1 line
2.42.0
PATCH 3/3 mmc: Add dw mobile mmc cmdq rtk driver
In reply to Jyan ChouAdd Realtek mmc driver to make good use Synopsys DesignWare mmc cmdq host driver.
---
v0 to v1 change:
1. Seperate different support into single patch.
2. Fix the compiler complains.
--- drivers/mmc/host/Kconfig | 9 + drivers/mmc/host/Makefile | 1 + drivers/mmc/host/dw_mmc_cqe-rtk.c | 998 ++++++++++++++++++++++++++++++ drivers/mmc/host/dw_mmc_cqe-rtk.h | 159 +++++ 4 files changed, 1167 insertions(+) create mode 100644 drivers/mmc/host/dw_mmc_cqe-rtk.c create mode 100644 drivers/mmc/host/dw_mmc_cqe-rtk.h
drivers/mmc/host/Kconfig +9 -0
@@ -775,6 +775,15 @@ config MMC_DW_CQE If unsure, say Y. +config MMC_DW_CQE_RTK + tristate "Realtek Soc's specific extensions for Synopsys DW Memory Card Interface" + depends on MMC_DW_CQE + select REGULATOR_FIXED_VOLTAGE + help + This selects support for Realtek SoC specific extensions to the + Synopsys DesignWare Memory Card Interface driver. Select this option + for platforms after RTD16xxb SoC's. + config MMC_DW_BLUEFIELD tristate "BlueField specific extensions for Synopsys DW Memory Card Interface" depends on MMC_DW
drivers/mmc/host/Makefile +1 -0
@@ -56,6 +56,7 @@ obj-$(CONFIG_MMC_DW_PCI) += dw_mmc-pci.o obj-$(CONFIG_MMC_DW_ROCKCHIP) += dw_mmc-rockchip.o obj-$(CONFIG_MMC_DW_STARFIVE) += dw_mmc-starfive.o obj-$(CONFIG_MMC_DW_CQE) += dw_mmc_cqe.o +obj-$(CONFIG_MMC_DW_CQE_RTK) += dw_mmc_cqe-rtk.o obj-$(CONFIG_MMC_SH_MMCIF) += sh_mmcif.o obj-$(CONFIG_MMC_JZ4740) += jz4740_mmc.o obj-$(CONFIG_MMC_VUB300) += vub300.o
drivers/mmc/host/dw_mmc_cqe-rtk.c new file +998 -0
998 lines not on this page · raw message
drivers/mmc/host/dw_mmc_cqe-rtk.h new file +159 -0
159 lines not on this page · raw message
Signature · 1 line
2.42.0
PATCH 2/3 mmc: Add Synopsys DesignWare mmc cmdq host driver
In reply to Jyan ChouWe implemented cmdq feature on Synopsys DesignWare mmc driver. The difference between dw_mmc.c and dw_mmc_cqe.c were distinct register definitions and the addition of cmdq.
More over, the flow of abort command sequence had change. We added a wait status function to satisfy synopsys user guide's description, since this flow might be specific in synopsys host driver only.
—
v0 to v1 change:
1. Seperate different support into single patch.
2. Fix the compiler complains.
--- drivers/mmc/host/Kconfig | 13 + drivers/mmc/host/Makefile | 1 + drivers/mmc/host/dw_mmc_cqe.c | 1634 +++++++++++++++++++++++++++++++++ drivers/mmc/host/dw_mmc_cqe.h | 443 +++++++++ 4 files changed, 2091 insertions(+) create mode 100644 drivers/mmc/host/dw_mmc_cqe.c create mode 100644 drivers/mmc/host/dw_mmc_cqe.h
drivers/mmc/host/Kconfig +13 -0
@@ -762,6 +762,19 @@ config MMC_DW_PLTFM If unsure, say Y. +config MMC_DW_CQE + tristate "Synopsys DesignWare Memory Card with CQE Interface" + depends on ARC || ARM || ARM64 || MIPS || COMPILE_TEST + select MMC_CQHCI + help + This selects support for the Synopsys DesignWare Mobile Storage IP + block after JEDEC Standard version 5.1. Select this option for SD and + MMC interfaces that use command queue. + + If you have a controller with this interface, say Y or M here. + + If unsure, say Y. + config MMC_DW_BLUEFIELD tristate "BlueField specific extensions for Synopsys DW Memory Card Interface" depends on MMC_DW
drivers/mmc/host/Makefile +1 -0
@@ -55,6 +55,7 @@ obj-$(CONFIG_MMC_DW_K3) += dw_mmc-k3.o obj-$(CONFIG_MMC_DW_PCI) += dw_mmc-pci.o obj-$(CONFIG_MMC_DW_ROCKCHIP) += dw_mmc-rockchip.o obj-$(CONFIG_MMC_DW_STARFIVE) += dw_mmc-starfive.o +obj-$(CONFIG_MMC_DW_CQE) += dw_mmc_cqe.o obj-$(CONFIG_MMC_SH_MMCIF) += sh_mmcif.o obj-$(CONFIG_MMC_JZ4740) += jz4740_mmc.o obj-$(CONFIG_MMC_VUB300) += vub300.o
drivers/mmc/host/dw_mmc_cqe.c new file +1634 -0
1,634 lines not on this page · raw message
drivers/mmc/host/dw_mmc_cqe.h new file +443 -0
443 lines not on this page · raw message
Signature · 1 line
2.42.0
Adrian Hunter
maintainerRe: [PATCH 2/3] [02/03] mmc: Add Synopsys DesignWare mmc cmdq host driver
Please put version numbers in the patch subject. Refer to:
https://www.kernel.org/doc/html/latest/process/submitting-patches.html
Quoted 3 lines · Jyan Chou
We implemented cmdq feature on Synopsys DesignWare mmc driver. The difference between
dw_mmc.canddw_mmc_cqe.cwere distinct register definitions and the addition of cmdq.
Register differences can be abstracted away, for example by providing callbacks for reading / writing registers. So this still needs much more explanation.
Quoted 12 lines
More over, the flow of abort command sequence had change. We added a wait status function to satisfy synopsys user guide's description, since this flow might be specific in synopsys host driver only.
Signed-off-by Jyan Chou <[email protected]>—
v0 to v1 change:
1. Seperate different support into single patch.
2. Fix the compiler complains.
Quoted 8 lines
--- drivers/mmc/host/Kconfig | 13 + drivers/mmc/host/Makefile | 1 + drivers/mmc/host/dw_mmc_cqe.c | 1634 +++++++++++++++++++++++++++++++++ drivers/mmc/host/dw_mmc_cqe.h | 443 +++++++++ 4 files changed, 2091 insertions(+) create mode 100644 drivers/mmc/host/dw_mmc_cqe.c create mode 100644 drivers/mmc/host/dw_mmc_cqe.h
My comments pertain only to the use of cqhci.
[SNIP]
Quoted 61 lines
drivers/mmc/host/dw_mmc_cqe.c new file +61
-0+static void dw_mci_cqe_set_tran_desc (u8 *desc, +dma_addr_t addr, +int len, +bool end, +bool dma64) +{ +__le32 *attr = (__le32 __force *)desc; + + *attr = (CQHCI_VALID (1 ) | +CQHCI_END (end ?1 :0 ) | +CQHCI_INT (0 ) | +CQHCI_ACT (0x4 ) | +CQHCI_DAT_LENGTH (len)); + +if (dma64) { +__le64 *dataddr = (__le64 __force *)(desc +4 ); + + dataddr[0 ] =cpu_to_le64 (addr); + }else { +__le32 *dataddr = (__le32 __force *)(desc +4 ); + + dataddr[0 ] =cpu_to_le32 (addr); + } +} + +static void dw_mci_cqe_setup_tran_desc (struct mmc_data *data, +struct cqhci_host *cq_host, +u8 *desc, +int sg_count) +{ +struct scatterlist *sg; +u32 cur_blk_cnt, remain_blk_cnt; +unsigned int begin, end; +int i, len; +bool last = false; +bool dma64 = cq_host->dma64; +dma_addr_t addr; + +for_each_sg (data->sg, sg, sg_count, i) { + addr =sg_dma_address (sg); + len =sg_dma_len (sg); + remain_blk_cnt = len >>9 ; + +while (remain_blk_cnt) { +/*DW_MCI_MAX_SCRIPT_BLK is tha max for each descriptor record*/ +if (remain_blk_cnt >DW_MCI_MAX_SCRIPT_BLK ) + cur_blk_cnt =DW_MCI_MAX_SCRIPT_BLK ; +else + cur_blk_cnt = remain_blk_cnt; + +/* In Synopsys DesignWare Databook Page 84, +* They mentioned the DMA 128MB restriction +*/ + begin = addr /SZ_128M ; + end = (addr + cur_blk_cnt *SZ_512 ) /SZ_128M ; + +if (begin != end) + cur_blk_cnt = (end *SZ_128M - addr) /SZ_512 ; + +if ((i+1 ) == sg_count && (remain_blk_cnt == cur_blk_cnt)) + last = true;
drivers/mmc/host/dw_mmc_cqe.c line 189
Quoted 10 lines
drivers/mmc/host/dw_mmc_cqe.c new file +10
-0+ +dw_mci_cqe_set_tran_desc (desc, addr, + (cur_blk_cnt <<9 ), last, dma64); + + addr = addr + (cur_blk_cnt <<9 ); + remain_blk_cnt -= cur_blk_cnt; + desc += cq_host->trans_desc_len; + } + } +}
It would be preferable to use a callback only for setting the descriptor.
Please see comments about dwcmshc_cqhci_set_tran_desc() and dwcmshc_cqhci_prep_tran_desc() made here:
https://lore.kernel.org/linux-mmc/[email protected]/
[SNIP]
Quoted 20 lines
drivers/mmc/host/dw_mmc_cqe.c new file +20
-0+static void dw_mci_cqe_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); + +/* +* The check for card presence and queueing of the request must be +* atomic, otherwise the card could be removed in between and the +* request wouldn't fail until another card was inserted. +*/ + +if (!dw_mci_cqe_get_cd (mmc)) { + mrq->cmd->error = -ENOMEDIUM ; +mmc_request_done (mmc, mrq); +return ; + } + +down_write (&host->cr_rw_sem);
drivers/mmc/host/dw_mmc_cqe.c line 950
Quoted 10 lines
drivers/mmc/host/dw_mmc_cqe.c new file +10
-0+ +/*cmdq case needs extra check*/ +if (host->pdata && (host->pdata->caps2 &MMC_CAP2_CQE )) { +if ((host->cqe) ==NULL ) { +dev_err (host->dev,"dw_mci_request_cqe not done yet\n" ); +mdelay (2 ); + } + +if (mmc->cqe_on == false && host->cqe->activated == true) +cqhci_deactivate (mmc);
This should not be necessary. Instead, please try to use ->pre_enable() and ->post_disable() like in mtk-sd.c
[SNIP]
RE: [PATCH 2/3] [02/03] mmc: Add Synopsys DesignWare mmc cmdq host driver
Hi Adrian,
Thanks for your review and advice.
We had updated our new version patches and corrected our code to your suggestions.
https://patchwork.kernel.org/project/linux-mmc/patch/[email protected]/
https://patchwork.kernel.org/project/linux-mmc/patch/[email protected]/
https://patchwork.kernel.org/project/linux-mmc/patch/[email protected]/
https://patchwork.kernel.org/project/linux-mmc/patch/[email protected]/
Quoted 1 line
Quoted 1 line
Please put version numbers in the patch subject.
We modified version numbers this time, thanks.
Quoted 2 lines
Register differences can be abstracted away, for example by providing callbacks for reading / writing registers. So this still needs much more explanation.
We had added more description to explain.
Quoted 3 lines
It would be preferable to use a callback only for setting the descriptor.
Please see comments aboutdwcmshc_cqhci_set_tran_desc()anddwcmshc_cqhci_prep_tran_desc()made here:
https://lore.kernel.org/linux-mmc/[email protected]/
We EXPORT cqhci_set_tran_desc and used it to replace dw_mci_cqe_set_tran_desc, thanks.
Quoted 2 lines
This should not be necessary. Instead, please try to use ->pre_enable() and ->post_disable() like in
mtk-sd.c
Thanks for your advice, we had removed unnecessary check code and added cqhci_host_ops callback function.
Best Regards,
Jyan
-----Original Message-----
From: Adrian Hunter <[email protected]>
Sent: Tuesday, October 10, 2023 3:04 PM
To: Jyan Chou [周芷安] <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; [email protected]; James Tai [戴志峰] <[email protected]>
Subject: Re: [PATCH 2/3] [02/03] mmc: Add Synopsys DesignWare mmc cmdq host driver
External mail.
Please put version numbers in the patch subject. Refer to:
https://www.kernel.org/doc/html/latest/process/submitting-patches.html
Quoted 3 lines · Jyan Chou
We implemented cmdq feature on Synopsys DesignWare mmc driver. The difference between
dw_mmc.canddw_mmc_cqe.cwere distinct register definitions and the addition of cmdq.
Register differences can be abstracted away, for example by providing callbacks for reading / writing registers. So this still needs much more explanation.
Quoted 20 lines
More over, the flow of abort command sequence had change. We added a wait status function to satisfy synopsys user guide's description, since this flow might be specific in synopsys host driver only.
Signed-off-by Jyan Chou <[email protected]>—
v0 to v1 change:
1. Seperate different support into single patch.
2. Fix the compiler complains.--- drivers/mmc/host/Kconfig | 13 + drivers/mmc/host/Makefile | 1 + drivers/mmc/host/dw_mmc_cqe.c | 1634 +++++++++++++++++++++++++++++++++ drivers/mmc/host/dw_mmc_cqe.h | 443 +++++++++ 4 files changed, 2091 insertions(+) create mode 100644 drivers/mmc/host/dw_mmc_cqe.c create mode 100644
Quoted 1 line
drivers/mmc/host/dw_mmc_cqe.h
My comments pertain only to the use of cqhci.
[SNIP]
Quoted 61 lines
drivers/mmc/host/dw_mmc_cqe.c new file +61
-0+static void dw_mci_cqe_set_tran_desc (u8 *desc, +dma_addr_t addr, +int len, +bool end, +bool dma64) { +__le32 *attr = (__le32 __force *)desc; + + *attr = (CQHCI_VALID (1 ) | +CQHCI_END (end ?1 :0 ) | +CQHCI_INT (0 ) | +CQHCI_ACT (0x4 ) | +CQHCI_DAT_LENGTH (len)); + +if (dma64) { +__le64 *dataddr = (__le64 __force *)(desc +4 ); + + dataddr[0 ] =cpu_to_le64 (addr); + }else { +__le32 *dataddr = (__le32 __force *)(desc +4 ); + + dataddr[0 ] =cpu_to_le32 (addr); + } +} + +static void dw_mci_cqe_setup_tran_desc (struct mmc_data *data, +struct cqhci_host *cq_host, +u8 *desc, +int sg_count) { +struct scatterlist *sg; +u32 cur_blk_cnt, remain_blk_cnt; +unsigned int begin, end; +int i, len; +bool last = false; +bool dma64 = cq_host->dma64; +dma_addr_t addr; + +for_each_sg (data->sg, sg, sg_count, i) { + addr =sg_dma_address (sg); + len =sg_dma_len (sg); + remain_blk_cnt = len >>9 ; + +while (remain_blk_cnt) { +/*DW_MCI_MAX_SCRIPT_BLK is tha max for each descriptor record*/ +if (remain_blk_cnt >DW_MCI_MAX_SCRIPT_BLK ) + cur_blk_cnt =DW_MCI_MAX_SCRIPT_BLK ; +else + cur_blk_cnt = remain_blk_cnt; + +/* In Synopsys DesignWare Databook Page 84, +* They mentioned the DMA 128MB restriction +*/ + begin = addr /SZ_128M ; + end = (addr + cur_blk_cnt *SZ_512 ) /SZ_128M ; + +if (begin != end) + cur_blk_cnt = (end *SZ_128M - addr) / +SZ_512 ; + +if ((i+1 ) == sg_count && (remain_blk_cnt == cur_blk_cnt)) + last = true; +
drivers/mmc/host/dw_mmc_cqe.c line 189
Quoted 10 lines
drivers/mmc/host/dw_mmc_cqe.c new file +10
-0+dw_mci_cqe_set_tran_desc (desc, addr, + (cur_blk_cnt <<9 ), last, + dma64); + + addr = addr + (cur_blk_cnt <<9 ); + remain_blk_cnt -= cur_blk_cnt; + desc += cq_host->trans_desc_len; + } + } +}
It would be preferable to use a callback only for setting the descriptor.
Please see comments about dwcmshc_cqhci_set_tran_desc() and dwcmshc_cqhci_prep_tran_desc() made here:
https://lore.kernel.org/linux-mmc/[email protected]/
[SNIP]
Quoted 20 lines
drivers/mmc/host/dw_mmc_cqe.c new file +20
-0+static void dw_mci_cqe_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); + +/* +* The check for card presence and queueing of the request must be +* atomic, otherwise the card could be removed in between and the +* request wouldn't fail until another card was inserted. +*/ + +if (!dw_mci_cqe_get_cd (mmc)) { + mrq->cmd->error = -ENOMEDIUM ; +mmc_request_done (mmc, mrq); +return ; + } + +down_write (&host->cr_rw_sem);
drivers/mmc/host/dw_mmc_cqe.c line 950
Quoted 10 lines
drivers/mmc/host/dw_mmc_cqe.c new file +10
-0+ +/*cmdq case needs extra check*/ +if (host->pdata && (host->pdata->caps2 &MMC_CAP2_CQE )) { +if ((host->cqe) ==NULL ) { +dev_err (host->dev,"dw_mci_request_cqe not done yet\n" ); +mdelay (2 ); + } + +if (mmc->cqe_on == false && host->cqe->activated == true) +cqhci_deactivate (mmc);
This should not be necessary. Instead, please try to use ->pre_enable() and ->post_disable() like in mtk-sd.c
[SNIP]