mmc: sdhci: UHS-II support, add hooks for additional operations
RFC PATCH v3 12/21 mmc: sdhci: UHS-II support, add hooks for additional operations
From: Ben Chuang <[email protected]>
In this commit, UHS-II related operations will be called via a function pointer array, sdhci_uhs2_ops, in order to make UHS-II support as a kernel module.
This array will be initialized only if CONFIG_MMC_SDHCI_UHS2 is enabled and when the UHS-II module is loaded. Otherwise, all the functions stay void.
--- drivers/mmc/host/sdhci.c | 152 ++++++++++++++++++++++++++++++++++----- 1 file changed, 136 insertions(+), 16 deletions(-)
drivers/mmc/host/sdhci.c +136 -16
@@ -32,8 +32,12 @@#include <linux/mmc/card.h> #include <linux/mmc/sdio.h> #include <linux/mmc/slot-gpio.h> +#include <linux/mmc/uhs2.h> +#include <linux/pci.h> #include "sdhci.h" +#include "sdhci-uhs2.h" +#include "sdhci-pci.h" #define DRIVER_NAME "sdhci"
@@ -45,6 +49,11 @@#define MAX_TUNING_LOOP 40 +#if IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) +struct sdhci_uhs2_ops sdhci_uhs2_ops; +EXPORT_SYMBOL_GPL (sdhci_uhs2_ops); +#endif +static unsigned int debug_quirks =0 ;static unsigned int debug_quirks2;
@@ -1041,8 +1050,11 @@ EXPORT_SYMBOL_GPL(sdhci_set_data_timeout_irq);void __sdhci_set_timeout (struct sdhci_host *host,struct mmc_command *cmd) { +u8 count; +bool too_big = false; -u8 count =sdhci_calc_timeout (host, cmd, &too_big); + + count =sdhci_calc_timeout (host, cmd, &too_big);if (too_big && host->quirks2 &SDHCI_QUIRK2_DISABLE_HW_TIMEOUT ) {
@@ -1053,6 +1065,11 @@ void __sdhci_set_timeout(struct sdhci_host *host, struct mmc_command *cmd) }sdhci_writeb (host, count,SDHCI_TIMEOUT_CONTROL ); + +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->mmc->flags &MMC_UHS2_SUPPORT && + sdhci_uhs2_ops.set_timeout) + sdhci_uhs2_ops.set_timeout (host); }EXPORT_SYMBOL_GPL (__sdhci_set_timeout);
@@ -1191,7 +1208,14 @@ static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_command *cmd)sdhci_set_transfer_irqs (host); -sdhci_set_block_info (host, data); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->mmc->flags &MMC_UHS2_SUPPORT && + host->mmc->flags &MMC_UHS2_INITIALIZED ) { +sdhci_writew (host, data->blksz,SDHCI_UHS2_BLOCK_SIZE ); +sdhci_writew (host, data->blocks,SDHCI_UHS2_BLOCK_COUNT ); + }else { +sdhci_set_block_info (host, data); + } }#if IS_ENABLED (CONFIG_MMC_SDHCI_EXTERNAL_DMA )
@@ -1439,6 +1463,13 @@ static void sdhci_set_transfer_mode(struct sdhci_host *host,u16 mode =0 ;struct mmc_data *data = cmd->data; +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->mmc->flags &MMC_UHS2_SUPPORT ) { +if (sdhci_uhs2_ops.set_transfer_mode) + sdhci_uhs2_ops.set_transfer_mode (host, cmd); +return ; + } +if (data ==NULL ) {if (host->quirks2 &SDHCI_QUIRK2_CLEAR_TRANSFERMODE_REG_BEFORE_CMD ) {
@@ -1570,6 +1601,12 @@ static void __sdhci_finish_data(struct sdhci_host *host, bool sw_data_timeout)else data->bytes_xfered = data->blksz * data->blocks; +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->mmc->flags &MMC_UHS2_INITIALIZED ) { +__sdhci_finish_mrq (host, data->mrq); +return ; + } +/* * Need to send CMD12 if - * a) open-ended multiblock transfer not using auto CMD12 (no CMD23)
@@ -1654,7 +1691,8 @@ static bool sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)sdhci_prepare_data (host, cmd); } -sdhci_writel (host, cmd->arg,SDHCI_ARGUMENT ); +if (!IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 )) +sdhci_writel (host, cmd->arg,SDHCI_ARGUMENT );sdhci_set_transfer_mode (host, cmd);
@@ -1699,6 +1737,17 @@ static bool sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)if (host->use_external_dma)sdhci_external_dma_pre_transfer (host, cmd); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + (host->mmc->flags &MMC_UHS2_SUPPORT )) { +if (sdhci_uhs2_ops.send_command) + sdhci_uhs2_ops.send_command (host, cmd); + +return true; + } + +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 )) +sdhci_writel (host, cmd->arg,SDHCI_ARGUMENT ); +sdhci_writew (host,SDHCI_MAKE_CMD (cmd->opcode, flags),SDHCI_COMMAND );return true;
@@ -1780,13 +1829,20 @@ static void sdhci_finish_command(struct sdhci_host *host) {struct mmc_command *cmd = host->cmd; - host->cmd =NULL ; +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->mmc->flags &MMC_UHS2_SUPPORT ) { +if (sdhci_uhs2_ops.finish_command) + sdhci_uhs2_ops.finish_command (host); + }else { + host->cmd =NULL ; -if (cmd->flags &MMC_RSP_PRESENT ) { -if (cmd->flags &MMC_RSP_136 ) { -sdhci_read_rsp_136 (host, cmd); - }else { - cmd->resp[0 ] =sdhci_readl (host,SDHCI_RESPONSE ); +if (cmd->flags &MMC_RSP_PRESENT ) { +if (cmd->flags &MMC_RSP_136 ) { +sdhci_read_rsp_136 (host, cmd); + }else { + cmd->resp[0 ] =sdhci_readl (host, +SDHCI_RESPONSE ); + } } }
@@ -1809,6 +1865,7 @@ static void sdhci_finish_command(struct sdhci_host *host) }else if (!(host->quirks &SDHCI_QUIRK_NO_BUSY_IRQ ) && cmd == host->data_cmd) {/* Command complete before busy is ended */ + host->cmd =NULL ;return ; } }
@@ -1828,6 +1885,8 @@ static void sdhci_finish_command(struct sdhci_host *host)if (!cmd->data)__sdhci_finish_mrq (host, cmd->mrq); } + + host->cmd =NULL ; }static u16 sdhci_get_preset_value (struct sdhci_host *host)
@@ -1855,6 +1914,11 @@ static u16 sdhci_get_preset_value(struct sdhci_host *host)case MMC_TIMING_MMC_HS400 : preset =sdhci_readw (host,SDHCI_PRESET_FOR_HS400 );break ; +#if IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) +case MMC_TIMING_UHS2 : + preset =sdhci_readw (host,SDHCI_PRESET_FOR_UHS2 ); +break ; +#endif default :pr_warn ("%s: Invalid UHS-I mode selected\n" ,mmc_hostname (host->mmc));
@@ -2095,7 +2159,6 @@ void sdhci_set_power_noreg(struct sdhci_host *host, unsigned char mode,sdhci_writeb (host, pwr,SDHCI_POWER_CONTROL ); pwr |=SDHCI_POWER_ON ; -sdhci_writeb (host, pwr,SDHCI_POWER_CONTROL );if (host->quirks2 &SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON )
@@ -2261,6 +2324,7 @@ void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) {struct sdhci_host *host =mmc_priv (mmc);u8 ctrl; +u16 ctrl_2;if (ios->power_mode ==MMC_POWER_UNDEFINED )return ;
@@ -2287,6 +2351,10 @@ void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)sdhci_enable_preset_value (host, false);if (!ios->clock || ios->clock != host->clock) { +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + ios->timing ==MMC_TIMING_UHS2 ) + host->timing = ios->timing; + host->ops->set_clock (host, ios->clock); host->clock = ios->clock;
@@ -2308,6 +2376,18 @@ void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)else sdhci_set_power (host, ios->power_mode, ios->vdd); +/* 4.0 host support */ +if (host->version >=SDHCI_SPEC_400 ) { +/* UHS2 Support */ +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->mmc->flags &MMC_UHS2_SUPPORT && + host->mmc->caps &MMC_CAP_UHS2 ) { +if (sdhci_uhs2_ops.do_set_ios) + sdhci_uhs2_ops.do_set_ios (host, ios); +return ; + } + } +if (host->ops->platform_send_init_74_clocks) host->ops->platform_send_init_74_clocks (host, ios->power_mode);
@@ -2331,7 +2411,7 @@ void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) }if (host->version >=SDHCI_SPEC_300 ) { -u16 clk, ctrl_2; +u16 clk;if (!host->preset_enabled) {sdhci_writeb (host, ctrl,SDHCI_HOST_CONTROL );
@@ -3173,11 +3253,19 @@ static bool sdhci_request_done(struct sdhci_host *host)/* This is to force an update */ host->ops->set_clock (host, host->clock); -/* Spec says we should do both at the same time, but Ricoh -controllers do not like that. */ -sdhci_do_reset (host,SDHCI_RESET_CMD ); -sdhci_do_reset (host,SDHCI_RESET_DATA ); - +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->mmc->flags &MMC_UHS2_INITIALIZED ) { +if (sdhci_uhs2_ops.reset) + sdhci_uhs2_ops.reset (host, +SDHCI_UHS2_SW_RESET_SD ); + }else { +/* +* Spec says we should do both at the same time, but +* Ricoh controllers do not like that. +*/ +sdhci_do_reset (host,SDHCI_RESET_CMD ); +sdhci_do_reset (host,SDHCI_RESET_DATA ); + } host->pending_reset = false; }
@@ -3532,6 +3620,13 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id) SDHCI_INT_BUS_POWER);sdhci_writel (host, mask,SDHCI_INT_STATUS ); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + intmask &SDHCI_INT_ERROR && + host->mmc->flags &MMC_UHS2_SUPPORT ) { +if (sdhci_uhs2_ops.irq) + sdhci_uhs2_ops.irq (host); + } +if (intmask & (SDHCI_INT_CARD_INSERT |SDHCI_INT_CARD_REMOVE )) {u32 present =sdhci_readl (host,SDHCI_PRESENT_STATE ) &SDHCI_CARD_PRESENT ;
@@ -4717,6 +4812,14 @@ int sdhci_setup_host(struct sdhci_host *host)/* This may alter mmc->*_blk_* parameters */ sdhci_allocate_bounce_buffer (host); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->version >=SDHCI_SPEC_400 && + sdhci_uhs2_ops.add_host) { + ret = sdhci_uhs2_ops.add_host (host, host->caps1); +if (ret) + goto unreg; + } +return 0 ; unreg:
@@ -4738,6 +4841,8 @@ void sdhci_cleanup_host(struct sdhci_host *host) {struct mmc_host *mmc = host->mmc; +/* FIXME: Do we have to do some cleanup for UHS2 here? */ +if (!IS_ERR (mmc->supply.vqmmc))regulator_disable (mmc->supply.vqmmc);
@@ -4766,6 +4871,14 @@ int __sdhci_add_host(struct sdhci_host *host) mmc->cqe_ops =NULL ; } +if ((mmc->caps &MMC_CAP_UHS2 ) && !host->v4_mode) { +/* host doesn't want to enable UHS2 support */ + mmc->caps &= ~MMC_CAP_UHS2 ; + mmc->flags &= ~MMC_UHS2_SUPPORT ; + +/* FIXME: Do we have to do some cleanup here? */ + } + host->complete_wq =alloc_workqueue ("sdhci" , flags,0 );if (!host->complete_wq)return -ENOMEM ;
@@ -4812,6 +4925,9 @@ int __sdhci_add_host(struct sdhci_host *host) unled:sdhci_led_unregister (host); unirq: +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + sdhci_uhs2_ops.remove_host) + sdhci_uhs2_ops.remove_host (host,0 );sdhci_do_reset (host,SDHCI_RESET_ALL );sdhci_writel (host,0 ,SDHCI_INT_ENABLE );sdhci_writel (host,0 ,SDHCI_SIGNAL_ENABLE );
@@ -4869,6 +4985,10 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)sdhci_led_unregister (host); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + sdhci_uhs2_ops.remove_host) + sdhci_uhs2_ops.remove_host (host, dead); +if (!dead)sdhci_do_reset (host,SDHCI_RESET_ALL );
Signature · 1 line
2.27.0
Adrian Hunter
maintainerQuoted 20 lines · Ben Chuang
From: Ben Chuang <[email protected]>
In this commit, UHS-II related operations will be called via a function pointer array,
sdhci_uhs2_ops, in order to make UHS-II support as a kernel module.
This array will be initialized only ifCONFIG_MMC_SDHCI_UHS2is enabled and when the UHS-II module is loaded. Otherwise, all the functions stay void.Signed-off-by Ben Chuang <[email protected]>Signed-off-by AKASHI Takahiro <[email protected]>--- drivers/mmc/host/sdhci.c | 152 ++++++++++++++++++++++++++++++++++----- 1 file changed, 136 insertions(+), 16 deletions(-)drivers/mmc/host/sdhci.c +0
-0
drivers/mmc/host/sdhci.c line 35
Quoted 4 lines
drivers/mmc/host/sdhci.c +1
-0@@ -32,8 +32,12 @@#include <linux/mmc/card.h> #include <linux/mmc/sdio.h> #include <linux/mmc/slot-gpio.h> +#include <linux/mmc/uhs2.h>
Ideally, we wouldn't need to use any UHS-II definitions in sdhci.c
drivers/mmc/host/sdhci.c line 36
Quoted 1 line
drivers/mmc/host/sdhci.c +1
-0+#include <linux/pci.h>
And never PCI. Please remove
drivers/mmc/host/sdhci.c line 39
Quoted 3 lines
drivers/mmc/host/sdhci.c +1
-0#include "sdhci.h" +#include "sdhci-uhs2.h"
sdhci-uhs2.h must not be included because the point of having it is to separate UHS-II from SD mode, so please remove
drivers/mmc/host/sdhci.c line 40
Quoted 1 line
drivers/mmc/host/sdhci.c +1
-0+#include "sdhci-pci.h"
Also this include must be removed
drivers/mmc/host/sdhci.c line 55
Quoted 11 lines
drivers/mmc/host/sdhci.c +4
-0#define DRIVER_NAME "sdhci"@@ -45,6 +49,11 @@#define MAX_TUNING_LOOP 40 +#if IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) +struct sdhci_uhs2_ops sdhci_uhs2_ops; +EXPORT_SYMBOL_GPL (sdhci_uhs2_ops); +#endif
As I mentioned in a previous patch, please add to sdhci_ops instead.
Quoted 5 lines
drivers/mmc/host/sdhci.c +1
-0+static unsigned int debug_quirks =0 ;static unsigned int debug_quirks2;
drivers/mmc/host/sdhci.c EXPORT_SYMBOL_GPL(sdhci_set_data_timeout_irq); · line 1057
Quoted 9 lines
drivers/mmc/host/sdhci.c +4
-1@@ -1041,8 +1050,11 @@ EXPORT_SYMBOL_GPL(sdhci_set_data_timeout_irq);void __sdhci_set_timeout (struct sdhci_host *host,struct mmc_command *cmd) { +u8 count; +bool too_big = false; -u8 count =sdhci_calc_timeout (host, cmd, &too_big); + + count =sdhci_calc_timeout (host, cmd, &too_big);
Last 2 chunks do nothing. Please remove
drivers/mmc/host/sdhci.c void __sdhci_set_timeout(struct sdhci_host *host, struct mmc_command *cmd) · line 1072
Quoted 12 lines
drivers/mmc/host/sdhci.c +5
-0if (too_big && host->quirks2 &SDHCI_QUIRK2_DISABLE_HW_TIMEOUT ) {@@ -1053,6 +1065,11 @@ void __sdhci_set_timeout(struct sdhci_host *host, struct mmc_command *cmd) }sdhci_writeb (host, count,SDHCI_TIMEOUT_CONTROL ); + +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->mmc->flags &MMC_UHS2_SUPPORT && + sdhci_uhs2_ops.set_timeout) + sdhci_uhs2_ops.set_timeout (host);
This is the kind of thing I want to avoid. We already have a ->set_timeout() callback. I would suggest creating something like:
static void __uhs2_set_timeout(struct sdhci_host *host, struct mmc_command *cmd) {
<whatever>
}
void uhs2_set_timeout(struct sdhci_host *host, struct mmc_command *cmd)
{
if (host->uhs2_mode)
__uhs2_set_timeout(host, cmd);
else
__sdhci_set_timeout(host, cmd);
}EXPORT_SYMBOL_GPL(uhs2_set_timeout);
Then uhs2 drivers need to set:
.set_timeout = uhs2_set_timeout,
Quoted 6 lines
drivers/mmc/host/sdhci.c +0
-0}EXPORT_SYMBOL_GPL (__sdhci_set_timeout);@@ -1191,7 +1208,14 @@ static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_command *cmd)sdhci_set_transfer_irqs (host);
drivers/mmc/host/sdhci.c static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_command *cmd) · line 1218
Quoted 10 lines
drivers/mmc/host/sdhci.c +8
-1-sdhci_set_block_info (host, data); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->mmc->flags &MMC_UHS2_SUPPORT && + host->mmc->flags &MMC_UHS2_INITIALIZED ) { +sdhci_writew (host, data->blksz,SDHCI_UHS2_BLOCK_SIZE ); +sdhci_writew (host, data->blocks,SDHCI_UHS2_BLOCK_COUNT ); + }else { +sdhci_set_block_info (host, data); + }
Again, this is what I want to avoid. I would like to have 3 kinds of functions:
- SD mode only
- UHS-II only
- SD functions with no UHS-II code, that can also be used by UHS-II
i.e. I don't want to mix UHS-II code and SD mode code in the same function.
I think sdhci-uhs2.c should provide a request function and a send_command function. I would start by removing everything you may not need, and then see if you have any problems. e.g.
void uhs2_request(struct mmc_host *mmc, struct mmc_request *mrq)
{
struct sdhci_host *host = mmc_priv(mmc);
struct mmc_command *cmd;
unsigned long flags;
if (!host->uhs2_mode) {
sdhci_request(mmc, mrq);
return;
}
spin_lock_irqsave(&host->lock, flags);
uhs2_send_command(host, cmd);
spin_unlock_irqrestore(&host->lock, flags);
}EXPORT_SYMBOL_GPL(uhs2_request);
For sdhci_prepare_data(), I would factor out the dma part, so
static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_command *cmd)
{
struct mmc_data *data = cmd->data;
sdhci_initialize_data(host, data);
sdhci_prepare_dma(host, data);
sdhci_set_block_info(host, data);
}The you could export sdhci_initialize_data() and sdhci_prepare_dma() for uhs2.
Quoted 4 lines
drivers/mmc/host/sdhci.c +0
-0}#if IS_ENABLED (CONFIG_MMC_SDHCI_EXTERNAL_DMA )
drivers/mmc/host/sdhci.c static void sdhci_set_transfer_mode(struct sdhci_host *host, · line 1472
Quoted 10 lines
drivers/mmc/host/sdhci.c +7
-0@@ -1439,6 +1463,13 @@ static void sdhci_set_transfer_mode(struct sdhci_host *host,u16 mode =0 ;struct mmc_data *data = cmd->data; +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->mmc->flags &MMC_UHS2_SUPPORT ) { +if (sdhci_uhs2_ops.set_transfer_mode) + sdhci_uhs2_ops.set_transfer_mode (host, cmd); +return ; + } +
Once you provide uhs2_request() and uhs2_send_command(), the transfer mode setting can be done in sdhci-uhs2.c
drivers/mmc/host/sdhci.c static void __sdhci_finish_data(struct sdhci_host *host, bool sw_data_timeout) · line 1608
Quoted 12 lines
drivers/mmc/host/sdhci.c +5
-0if (data ==NULL ) {if (host->quirks2 &SDHCI_QUIRK2_CLEAR_TRANSFERMODE_REG_BEFORE_CMD ) {@@ -1570,6 +1601,12 @@ static void __sdhci_finish_data(struct sdhci_host *host, bool sw_data_timeout)else data->bytes_xfered = data->blksz * data->blocks; +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->mmc->flags &MMC_UHS2_INITIALIZED ) { +__sdhci_finish_mrq (host, data->mrq); +return ; + }
At least to start with, I think it would be better to handle UHS-II cmd and data interrupts completely in sdhci-uhs2.c
drivers/mmc/host/sdhci.c static bool sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd) · line 1695
Quoted 11 lines
drivers/mmc/host/sdhci.c +3
-1+/* * Need to send CMD12 if - * a) open-ended multiblock transfer not using auto CMD12 (no CMD23) @@ -1654,7 +1691,8 @@ static bool sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)sdhci_prepare_data (host, cmd); } -sdhci_writel (host, cmd->arg,SDHCI_ARGUMENT ); +if (!IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 )) +sdhci_writel (host, cmd->arg,SDHCI_ARGUMENT );
Not needed when instead you provide uhs2_send_command()
Quoted 7 lines
drivers/mmc/host/sdhci.c +0
-0sdhci_set_transfer_mode (host, cmd);@@ -1699,6 +1737,17 @@ static bool sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)if (host->use_external_dma)sdhci_external_dma_pre_transfer (host, cmd);
drivers/mmc/host/sdhci.c static bool sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd) · line 1749
Quoted 10 lines
drivers/mmc/host/sdhci.c +10
-0+if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + (host->mmc->flags &MMC_UHS2_SUPPORT )) { +if (sdhci_uhs2_ops.send_command) + sdhci_uhs2_ops.send_command (host, cmd); + +return true; + } + +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 )) +sdhci_writel (host, cmd->arg,SDHCI_ARGUMENT );
Not needed when instead you provide uhs2_send_command()
Quoted 18 lines
drivers/mmc/host/sdhci.c +7
-3+sdhci_writew (host,SDHCI_MAKE_CMD (cmd->opcode, flags),SDHCI_COMMAND );return true;@@ -1780,13 +1829,20 @@ static void sdhci_finish_command(struct sdhci_host *host) {struct mmc_command *cmd = host->cmd; - host->cmd =NULL ; +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->mmc->flags &MMC_UHS2_SUPPORT ) { +if (sdhci_uhs2_ops.finish_command) + sdhci_uhs2_ops.finish_command (host); + }else { + host->cmd =NULL ; -if (cmd->flags &MMC_RSP_PRESENT ) { -if (cmd->flags &MMC_RSP_136 ) {
drivers/mmc/host/sdhci.c static void sdhci_finish_command(struct sdhci_host *host) · line 1845
Quoted 10 lines
drivers/mmc/host/sdhci.c +7
-3-sdhci_read_rsp_136 (host, cmd); - }else { - cmd->resp[0 ] =sdhci_readl (host,SDHCI_RESPONSE ); +if (cmd->flags &MMC_RSP_PRESENT ) { +if (cmd->flags &MMC_RSP_136 ) { +sdhci_read_rsp_136 (host, cmd); + }else { + cmd->resp[0 ] =sdhci_readl (host, +SDHCI_RESPONSE ); + }
At least to start with, I think it would be better to handle UHS-II cmd and data interrupts completely in sdhci-uhs2.c
drivers/mmc/host/sdhci.c static void sdhci_finish_command(struct sdhci_host *host) · line 1868
Quoted 8 lines
drivers/mmc/host/sdhci.c +1
-0} }@@ -1809,6 +1865,7 @@ static void sdhci_finish_command(struct sdhci_host *host) }else if (!(host->quirks &SDHCI_QUIRK_NO_BUSY_IRQ ) && cmd == host->data_cmd) {/* Command complete before busy is ended */ + host->cmd =NULL ;
host->cmd is set to NULL at the start of this function, so this is not needed.
drivers/mmc/host/sdhci.c static void sdhci_finish_command(struct sdhci_host *host) · line 1889
Quoted 9 lines
drivers/mmc/host/sdhci.c +2
-0return ; } }@@ -1828,6 +1885,8 @@ static void sdhci_finish_command(struct sdhci_host *host)if (!cmd->data)__sdhci_finish_mrq (host, cmd->mrq); } + + host->cmd =NULL ;
host->cmd is set to NULL at the start of this function, so this is not needed.
drivers/mmc/host/sdhci.c static u16 sdhci_get_preset_value(struct sdhci_host *host) · line 1917
Quoted 8 lines
drivers/mmc/host/sdhci.c +1
-0}static u16 sdhci_get_preset_value (struct sdhci_host *host)@@ -1855,6 +1914,11 @@ static u16 sdhci_get_preset_value(struct sdhci_host *host)case MMC_TIMING_MMC_HS400 : preset =sdhci_readw (host,SDHCI_PRESET_FOR_HS400 );break ; +#if IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 )
Shouldn't need conditional compilation for this
drivers/mmc/host/sdhci.c void sdhci_set_power_noreg(struct sdhci_host *host, unsigned char mode, · line 2098
Quoted 12 lines
drivers/mmc/host/sdhci.c +4
-1+case MMC_TIMING_UHS2 : + preset =sdhci_readw (host,SDHCI_PRESET_FOR_UHS2 ); +break ; +#endif default :pr_warn ("%s: Invalid UHS-I mode selected\n" ,mmc_hostname (host->mmc));@@ -2095,7 +2159,6 @@ void sdhci_set_power_noreg(struct sdhci_host *host, unsigned char mode,sdhci_writeb (host, pwr,SDHCI_POWER_CONTROL ); pwr |=SDHCI_POWER_ON ; -
No white space changes mixed in please
Quoted 28 lines
drivers/mmc/host/sdhci.c +7
-0sdhci_writeb (host, pwr,SDHCI_POWER_CONTROL );if (host->quirks2 &SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON )@@ -2261,6 +2324,7 @@ void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) {struct sdhci_host *host =mmc_priv (mmc);u8 ctrl; +u16 ctrl_2;if (ios->power_mode ==MMC_POWER_UNDEFINED )return ;@@ -2287,6 +2351,10 @@ void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)sdhci_enable_preset_value (host, false);if (!ios->clock || ios->clock != host->clock) { +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + ios->timing ==MMC_TIMING_UHS2 ) + host->timing = ios->timing; + host->ops->set_clock (host, ios->clock); host->clock = ios->clock;@@ -2308,6 +2376,18 @@ void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)else sdhci_set_power (host, ios->power_mode, ios->vdd); +/* 4.0 host support */ +if (host->version >=SDHCI_SPEC_400 ) {
drivers/mmc/host/sdhci.c void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) · line 2390
Quoted 10 lines
drivers/mmc/host/sdhci.c +10
-0+/* UHS2 Support */ +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->mmc->flags &MMC_UHS2_SUPPORT && + host->mmc->caps &MMC_CAP_UHS2 ) { +if (sdhci_uhs2_ops.do_set_ios) + sdhci_uhs2_ops.do_set_ios (host, ios); +return ; + } + } +
Please look at using existing callbacks instead, maybe creating uhs2_set_ios(), uhs2_set_clock(), uhs2_set_power()
Quoted 24 lines
drivers/mmc/host/sdhci.c +4
-6if (host->ops->platform_send_init_74_clocks) host->ops->platform_send_init_74_clocks (host, ios->power_mode);@@ -2331,7 +2411,7 @@ void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) }if (host->version >=SDHCI_SPEC_300 ) { -u16 clk, ctrl_2; +u16 clk;if (!host->preset_enabled) {sdhci_writeb (host, ctrl,SDHCI_HOST_CONTROL );@@ -3173,11 +3253,19 @@ static bool sdhci_request_done(struct sdhci_host *host)/* This is to force an update */ host->ops->set_clock (host, host->clock); -/* Spec says we should do both at the same time, but Ricoh -controllers do not like that. */ -sdhci_do_reset (host,SDHCI_RESET_CMD ); -sdhci_do_reset (host,SDHCI_RESET_DATA ); - +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->mmc->flags &MMC_UHS2_INITIALIZED ) { +if (sdhci_uhs2_ops.reset)
drivers/mmc/host/sdhci.c static bool sdhci_request_done(struct sdhci_host *host) · line 3268
Quoted 10 lines
drivers/mmc/host/sdhci.c +10
-0+ sdhci_uhs2_ops.reset (host, +SDHCI_UHS2_SW_RESET_SD ); + }else { +/* +* Spec says we should do both at the same time, but +* Ricoh controllers do not like that. +*/ +sdhci_do_reset (host,SDHCI_RESET_CMD ); +sdhci_do_reset (host,SDHCI_RESET_DATA ); + }
Please look at using the existing ->reset() sdhci host op instead.
Quoted 4 lines
drivers/mmc/host/sdhci.c +0
-0host->pending_reset = false; }
drivers/mmc/host/sdhci.c static irqreturn_t sdhci_irq(int irq, void *dev_id) · line 3629
Quoted 10 lines
drivers/mmc/host/sdhci.c +7
-0@@ -3532,6 +3620,13 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id) SDHCI_INT_BUS_POWER);sdhci_writel (host, mask,SDHCI_INT_STATUS ); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + intmask &SDHCI_INT_ERROR && + host->mmc->flags &MMC_UHS2_SUPPORT ) { +if (sdhci_uhs2_ops.irq) + sdhci_uhs2_ops.irq (host); + } +
Please look at using the existing ->irq() sdhci host op instead
Quoted 5 lines
drivers/mmc/host/sdhci.c +0
-0if (intmask & (SDHCI_INT_CARD_INSERT |SDHCI_INT_CARD_REMOVE )) {u32 present =sdhci_readl (host,SDHCI_PRESENT_STATE ) &SDHCI_CARD_PRESENT ;@@ -4717,6 +4812,14 @@ int sdhci_setup_host(struct sdhci_host *host)/* This may alter mmc->*_blk_* parameters */
drivers/mmc/host/sdhci.c int sdhci_setup_host(struct sdhci_host *host) · line 4822
Quoted 10 lines
drivers/mmc/host/sdhci.c +8
-0sdhci_allocate_bounce_buffer (host); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->version >=SDHCI_SPEC_400 && + sdhci_uhs2_ops.add_host) { + ret = sdhci_uhs2_ops.add_host (host, host->caps1); +if (ret) + goto unreg; + } +
I think you should look at creating uhs2_add_host() instead
Quoted 38 lines
drivers/mmc/host/sdhci.c +13
-0return 0 ; unreg:@@ -4738,6 +4841,8 @@ void sdhci_cleanup_host(struct sdhci_host *host) {struct mmc_host *mmc = host->mmc; +/* FIXME: Do we have to do some cleanup for UHS2 here? */ +if (!IS_ERR (mmc->supply.vqmmc))regulator_disable (mmc->supply.vqmmc);@@ -4766,6 +4871,14 @@ int __sdhci_add_host(struct sdhci_host *host) mmc->cqe_ops =NULL ; } +if ((mmc->caps &MMC_CAP_UHS2 ) && !host->v4_mode) { +/* host doesn't want to enable UHS2 support */ + mmc->caps &= ~MMC_CAP_UHS2 ; + mmc->flags &= ~MMC_UHS2_SUPPORT ; + +/* FIXME: Do we have to do some cleanup here? */ + } + host->complete_wq =alloc_workqueue ("sdhci" , flags,0 );if (!host->complete_wq)return -ENOMEM ;@@ -4812,6 +4925,9 @@ int __sdhci_add_host(struct sdhci_host *host) unled:sdhci_led_unregister (host); unirq: +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + sdhci_uhs2_ops.remove_host) + sdhci_uhs2_ops.remove_host (host,0 );sdhci_do_reset (host,SDHCI_RESET_ALL );sdhci_writel (host,0 ,SDHCI_INT_ENABLE );sdhci_writel (host,0 ,SDHCI_SIGNAL_ENABLE );
drivers/mmc/host/sdhci.c void sdhci_remove_host(struct sdhci_host *host, int dead) · line 4991
Quoted 7 lines
drivers/mmc/host/sdhci.c +4
-0@@ -4869,6 +4985,10 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)sdhci_led_unregister (host); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + sdhci_uhs2_ops.remove_host) + sdhci_uhs2_ops.remove_host (host, dead); +
I think you should look at creating uhs2_remove_host() instead
Quoted 4 lines
drivers/mmc/host/sdhci.c +0
-0if (!dead)sdhci_do_reset (host,SDHCI_RESET_ALL );
Adrian,
Your comments are scattered over various functions, and so I would like to address them in separate replies.
First, I'd like to discuss sdhci_[add|remove]_host().
Quoted 13 lines · Adrian Hunter
Quoted 12 lines · Ben Chuang
From: Ben Chuang <[email protected]>
In this commit, UHS-II related operations will be called via a function pointer array,
sdhci_uhs2_ops, in order to make UHS-II support as a kernel module.
This array will be initialized only ifCONFIG_MMC_SDHCI_UHS2is enabled and when the UHS-II module is loaded. Otherwise, all the functions stay void.Signed-off-by Ben Chuang <[email protected]>Signed-off-by AKASHI Takahiro <[email protected]>---
(snip)
Quoted 57 lines
Quoted 5 lines
drivers/mmc/host/sdhci.c +0
-0if (intmask & (SDHCI_INT_CARD_INSERT |SDHCI_INT_CARD_REMOVE )) {u32 present =sdhci_readl (host,SDHCI_PRESENT_STATE ) &SDHCI_CARD_PRESENT ;@@ -4717,6 +4812,14 @@ int sdhci_setup_host(struct sdhci_host *host)/* This may alter mmc->*_blk_* parameters */ drivers/mmc/host/sdhci.c int sdhci_setup_host(struct sdhci_host *host) · line 4822
Quoted 10 lines
drivers/mmc/host/sdhci.c +8
-0sdhci_allocate_bounce_buffer (host); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->version >=SDHCI_SPEC_400 && + sdhci_uhs2_ops.add_host) { + ret = sdhci_uhs2_ops.add_host (host, host->caps1); +if (ret) + goto unreg; + } +I think you should look at creating
uhs2_add_host()insteadQuoted 39 lines
drivers/mmc/host/sdhci.c +13
-0return 0 ; unreg:@@ -4738,6 +4841,8 @@ void sdhci_cleanup_host(struct sdhci_host *host) {struct mmc_host *mmc = host->mmc; +/* FIXME: Do we have to do some cleanup for UHS2 here? */ +if (!IS_ERR (mmc->supply.vqmmc))regulator_disable (mmc->supply.vqmmc);@@ -4766,6 +4871,14 @@ int __sdhci_add_host(struct sdhci_host *host) mmc->cqe_ops =NULL ; } +if ((mmc->caps &MMC_CAP_UHS2 ) && !host->v4_mode) { +/* host doesn't want to enable UHS2 support */ + mmc->caps &= ~MMC_CAP_UHS2 ; + mmc->flags &= ~MMC_UHS2_SUPPORT ; + +/* FIXME: Do we have to do some cleanup here? */ + } + host->complete_wq =alloc_workqueue ("sdhci" , flags,0 );if (!host->complete_wq)return -ENOMEM ;@@ -4812,6 +4925,9 @@ int __sdhci_add_host(struct sdhci_host *host) unled:sdhci_led_unregister (host); unirq: +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + sdhci_uhs2_ops.remove_host) + sdhci_uhs2_ops.remove_host (host,0 );sdhci_do_reset (host,SDHCI_RESET_ALL );sdhci_writel (host,0 ,SDHCI_INT_ENABLE );sdhci_writel (host,0 ,SDHCI_SIGNAL_ENABLE );@@ -4869,6 +4985,10 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)
Quoted 8 lines
drivers/mmc/host/sdhci.c void sdhci_remove_host(struct sdhci_host *host, int dead) · line 4991
Quoted 6 lines
drivers/mmc/host/sdhci.c +4
-0sdhci_led_unregister (host); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + sdhci_uhs2_ops.remove_host) + sdhci_uhs2_ops.remove_host (host, dead); +I think you should look at creating
uhs2_remove_host()instead
You suggest that we will have separate sdhci_uhs2_[add|remove]_host(), but I don't think it's always convenient.
UHS-II capable host will be set to call sdhci_uhs2_add_host() explicitly, but we can't do that in case of pci and pltfm based drivers as they utilize common helper functions, sdhci_pci_probe() and sdhci_pltfm_register(), respectively.
Therefore, we inevitably have to call sdhci_uhs2_add_host() there.
If so, why should we distinguish sdhci_uhs2_add_host from sdhci_uhs_add_host? I don't see any good reason.
Moreover, as a result, there exists a mixed usage of sdhci_ interfaces and sdhci_uhs2_ interfaces in sdhci-pci-core.c and sdhci-pltfm.c.
It sounds odd to me.
-Takahiro Akashi
Quoted 6 lines
Quoted 5 lines
drivers/mmc/host/sdhci.c +0
-0if (!dead)sdhci_do_reset (host,SDHCI_RESET_ALL );
Adrian Hunter
maintainerQuoted 90 lines · AKASHI Takahiro
Adrian,
Your comments are scattered over various functions, and so I would like to address them in separate replies.
First, I'd like to discuss sdhci_[add|remove]_host().
Quoted 13 lines · Adrian Hunter
Quoted 12 lines · Ben Chuang
From: Ben Chuang <[email protected]>
In this commit, UHS-II related operations will be called via a function pointer array,
sdhci_uhs2_ops, in order to make UHS-II support as a kernel module.
This array will be initialized only ifCONFIG_MMC_SDHCI_UHS2is enabled and when the UHS-II module is loaded. Otherwise, all the functions stay void.Signed-off-by Ben Chuang <[email protected]>Signed-off-by AKASHI Takahiro <[email protected]>---
(snip)
Quoted 57 lines
Quoted 5 lines
drivers/mmc/host/sdhci.c +0
-0if (intmask & (SDHCI_INT_CARD_INSERT |SDHCI_INT_CARD_REMOVE )) {u32 present =sdhci_readl (host,SDHCI_PRESENT_STATE ) &SDHCI_CARD_PRESENT ;@@ -4717,6 +4812,14 @@ int sdhci_setup_host(struct sdhci_host *host)/* This may alter mmc->*_blk_* parameters */ drivers/mmc/host/sdhci.c int sdhci_setup_host(struct sdhci_host *host) · line 4822
Quoted 10 lines
drivers/mmc/host/sdhci.c +8
-0sdhci_allocate_bounce_buffer (host); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->version >=SDHCI_SPEC_400 && + sdhci_uhs2_ops.add_host) { + ret = sdhci_uhs2_ops.add_host (host, host->caps1); +if (ret) + goto unreg; + } +I think you should look at creating
uhs2_add_host()insteadQuoted 39 lines
drivers/mmc/host/sdhci.c +13
-0return 0 ; unreg:@@ -4738,6 +4841,8 @@ void sdhci_cleanup_host(struct sdhci_host *host) {struct mmc_host *mmc = host->mmc; +/* FIXME: Do we have to do some cleanup for UHS2 here? */ +if (!IS_ERR (mmc->supply.vqmmc))regulator_disable (mmc->supply.vqmmc);@@ -4766,6 +4871,14 @@ int __sdhci_add_host(struct sdhci_host *host) mmc->cqe_ops =NULL ; } +if ((mmc->caps &MMC_CAP_UHS2 ) && !host->v4_mode) { +/* host doesn't want to enable UHS2 support */ + mmc->caps &= ~MMC_CAP_UHS2 ; + mmc->flags &= ~MMC_UHS2_SUPPORT ; + +/* FIXME: Do we have to do some cleanup here? */ + } + host->complete_wq =alloc_workqueue ("sdhci" , flags,0 );if (!host->complete_wq)return -ENOMEM ;@@ -4812,6 +4925,9 @@ int __sdhci_add_host(struct sdhci_host *host) unled:sdhci_led_unregister (host); unirq: +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + sdhci_uhs2_ops.remove_host) + sdhci_uhs2_ops.remove_host (host,0 );sdhci_do_reset (host,SDHCI_RESET_ALL );sdhci_writel (host,0 ,SDHCI_INT_ENABLE );sdhci_writel (host,0 ,SDHCI_SIGNAL_ENABLE );@@ -4869,6 +4985,10 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)Quoted 8 lines
drivers/mmc/host/sdhci.c void sdhci_remove_host(struct sdhci_host *host, int dead) · line 4991
Quoted 6 lines
drivers/mmc/host/sdhci.c +4
-0sdhci_led_unregister (host); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + sdhci_uhs2_ops.remove_host) + sdhci_uhs2_ops.remove_host (host, dead); +I think you should look at creating
uhs2_remove_host()instead
Quoted 7 lines
You suggest that we will have separate sdhci_uhs2_[add|remove]_host(), but I don't think it's always convenient.
UHS-II capable host will be set to call
sdhci_uhs2_add_host()explicitly, but we can't do that in case of pci and pltfm based drivers as they utilize common helper functions,sdhci_pci_probe()andsdhci_pltfm_register(), respectively.
sdhci-pci has an add_host op
sdhci_pltfm_init can be used instead of sdhci_pltfm_register
Quoted 8 lines
Therefore, we inevitably have to call
sdhci_uhs2_add_host()there.If so, why should we distinguish
sdhci_uhs2_add_hostfromsdhci_uhs_add_host? I don't see any good reason.
Moreover, as a result, there exists a mixed usage ofsdhci_interfaces andsdhci_uhs2_interfaces insdhci-pci-core.candsdhci-pltfm.c.It sounds odd to me.
It is already done that way for cqhci.
Quoted 10 lines
-Takahiro Akashi
Quoted 6 lines
Quoted 5 lines
drivers/mmc/host/sdhci.c +0
-0if (!dead)sdhci_do_reset (host,SDHCI_RESET_ALL );
Adrian,
Quoted 106 lines · Adrian Hunter
Quoted 90 lines · AKASHI Takahiro
Adrian,
Your comments are scattered over various functions, and so I would like to address them in separate replies.
First, I'd like to discuss sdhci_[add|remove]_host().
Quoted 13 lines · Adrian Hunter
Quoted 12 lines · Ben Chuang
From: Ben Chuang <[email protected]>
In this commit, UHS-II related operations will be called via a function pointer array,
sdhci_uhs2_ops, in order to make UHS-II support as a kernel module.
This array will be initialized only ifCONFIG_MMC_SDHCI_UHS2is enabled and when the UHS-II module is loaded. Otherwise, all the functions stay void.Signed-off-by Ben Chuang <[email protected]>Signed-off-by AKASHI Takahiro <[email protected]>---
(snip)
Quoted 57 lines
Quoted 5 lines
drivers/mmc/host/sdhci.c +0
-0if (intmask & (SDHCI_INT_CARD_INSERT |SDHCI_INT_CARD_REMOVE )) {u32 present =sdhci_readl (host,SDHCI_PRESENT_STATE ) &SDHCI_CARD_PRESENT ;@@ -4717,6 +4812,14 @@ int sdhci_setup_host(struct sdhci_host *host)/* This may alter mmc->*_blk_* parameters */ drivers/mmc/host/sdhci.c int sdhci_setup_host(struct sdhci_host *host) · line 4822
Quoted 10 lines
drivers/mmc/host/sdhci.c +8
-0sdhci_allocate_bounce_buffer (host); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->version >=SDHCI_SPEC_400 && + sdhci_uhs2_ops.add_host) { + ret = sdhci_uhs2_ops.add_host (host, host->caps1); +if (ret) + goto unreg; + } +I think you should look at creating
uhs2_add_host()insteadQuoted 39 lines
drivers/mmc/host/sdhci.c +13
-0return 0 ; unreg:@@ -4738,6 +4841,8 @@ void sdhci_cleanup_host(struct sdhci_host *host) {struct mmc_host *mmc = host->mmc; +/* FIXME: Do we have to do some cleanup for UHS2 here? */ +if (!IS_ERR (mmc->supply.vqmmc))regulator_disable (mmc->supply.vqmmc);@@ -4766,6 +4871,14 @@ int __sdhci_add_host(struct sdhci_host *host) mmc->cqe_ops =NULL ; } +if ((mmc->caps &MMC_CAP_UHS2 ) && !host->v4_mode) { +/* host doesn't want to enable UHS2 support */ + mmc->caps &= ~MMC_CAP_UHS2 ; + mmc->flags &= ~MMC_UHS2_SUPPORT ; + +/* FIXME: Do we have to do some cleanup here? */ + } + host->complete_wq =alloc_workqueue ("sdhci" , flags,0 );if (!host->complete_wq)return -ENOMEM ;@@ -4812,6 +4925,9 @@ int __sdhci_add_host(struct sdhci_host *host) unled:sdhci_led_unregister (host); unirq: +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + sdhci_uhs2_ops.remove_host) + sdhci_uhs2_ops.remove_host (host,0 );sdhci_do_reset (host,SDHCI_RESET_ALL );sdhci_writel (host,0 ,SDHCI_INT_ENABLE );sdhci_writel (host,0 ,SDHCI_SIGNAL_ENABLE );@@ -4869,6 +4985,10 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)Quoted 8 lines
drivers/mmc/host/sdhci.c void sdhci_remove_host(struct sdhci_host *host, int dead) · line 4991
Quoted 6 lines
drivers/mmc/host/sdhci.c +4
-0sdhci_led_unregister (host); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + sdhci_uhs2_ops.remove_host) + sdhci_uhs2_ops.remove_host (host, dead); +I think you should look at creating
uhs2_remove_host()insteadQuoted 7 lines
You suggest that we will have separate sdhci_uhs2_[add|remove]_host(), but I don't think it's always convenient.
UHS-II capable host will be set to call
sdhci_uhs2_add_host()explicitly, but we can't do that in case of pci and pltfm based drivers as they utilize common helper functions,sdhci_pci_probe()andsdhci_pltfm_register(), respectively.sdhci-pci has an
add_hostop
sdhci_pltfm_initcan be used instead ofsdhci_pltfm_registerQuoted 2 lines
Therefore, we inevitably have to call
sdhci_uhs2_add_host()there.
Quoted 8 lines
Quoted 6 lines
If so, why should we distinguish
sdhci_uhs2_add_hostfromsdhci_uhs_add_host? I don't see any good reason.
Moreover, as a result, there exists a mixed usage ofsdhci_interfaces andsdhci_uhs2_interfaces insdhci-pci-core.candsdhci-pltfm.c.It sounds odd to me.
It is already done that way for cqhci.
Okay, if it is your policy, I will follow that.
Then, I'm going to add
- remove_host field to struct sdhci_pci_fixes
- a controller specific helper function to each driver (only pci-gli for now) even though it looks quite generic.
sdhci_gli_[add|remove]_host(struct sdhci_pci_slot *slot)
{
return sdhci_uhs2_[add|remove]_host(slot->host);
}# Or do you want to create a file like sdhci-uhs2-pci.c for those functions?
-Takahiro Akashi
Quoted 11 lines
Quoted 10 lines
-Takahiro Akashi
Quoted 6 lines
Quoted 5 lines
drivers/mmc/host/sdhci.c +0
-0if (!dead)sdhci_do_reset (host,SDHCI_RESET_ALL );
Adrian Hunter
maintainerQuoted 116 lines · AKASHI Takahiro
Adrian,
Quoted 113 lines · Adrian Hunter
Quoted 90 lines · AKASHI Takahiro
Adrian,
Your comments are scattered over various functions, and so I would like to address them in separate replies.
First, I'd like to discuss sdhci_[add|remove]_host().
Quoted 13 lines · Adrian Hunter
Quoted 12 lines · Ben Chuang
From: Ben Chuang <[email protected]>
In this commit, UHS-II related operations will be called via a function pointer array,
sdhci_uhs2_ops, in order to make UHS-II support as a kernel module.
This array will be initialized only ifCONFIG_MMC_SDHCI_UHS2is enabled and when the UHS-II module is loaded. Otherwise, all the functions stay void.Signed-off-by Ben Chuang <[email protected]>Signed-off-by AKASHI Takahiro <[email protected]>---
(snip)
Quoted 57 lines
Quoted 5 lines
drivers/mmc/host/sdhci.c +0
-0if (intmask & (SDHCI_INT_CARD_INSERT |SDHCI_INT_CARD_REMOVE )) {u32 present =sdhci_readl (host,SDHCI_PRESENT_STATE ) &SDHCI_CARD_PRESENT ;@@ -4717,6 +4812,14 @@ int sdhci_setup_host(struct sdhci_host *host)/* This may alter mmc->*_blk_* parameters */ drivers/mmc/host/sdhci.c int sdhci_setup_host(struct sdhci_host *host) · line 4822
Quoted 10 lines
drivers/mmc/host/sdhci.c +8
-0sdhci_allocate_bounce_buffer (host); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->version >=SDHCI_SPEC_400 && + sdhci_uhs2_ops.add_host) { + ret = sdhci_uhs2_ops.add_host (host, host->caps1); +if (ret) + goto unreg; + } +I think you should look at creating
uhs2_add_host()insteadQuoted 39 lines
drivers/mmc/host/sdhci.c +13
-0return 0 ; unreg:@@ -4738,6 +4841,8 @@ void sdhci_cleanup_host(struct sdhci_host *host) {struct mmc_host *mmc = host->mmc; +/* FIXME: Do we have to do some cleanup for UHS2 here? */ +if (!IS_ERR (mmc->supply.vqmmc))regulator_disable (mmc->supply.vqmmc);@@ -4766,6 +4871,14 @@ int __sdhci_add_host(struct sdhci_host *host) mmc->cqe_ops =NULL ; } +if ((mmc->caps &MMC_CAP_UHS2 ) && !host->v4_mode) { +/* host doesn't want to enable UHS2 support */ + mmc->caps &= ~MMC_CAP_UHS2 ; + mmc->flags &= ~MMC_UHS2_SUPPORT ; + +/* FIXME: Do we have to do some cleanup here? */ + } + host->complete_wq =alloc_workqueue ("sdhci" , flags,0 );if (!host->complete_wq)return -ENOMEM ;@@ -4812,6 +4925,9 @@ int __sdhci_add_host(struct sdhci_host *host) unled:sdhci_led_unregister (host); unirq: +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + sdhci_uhs2_ops.remove_host) + sdhci_uhs2_ops.remove_host (host,0 );sdhci_do_reset (host,SDHCI_RESET_ALL );sdhci_writel (host,0 ,SDHCI_INT_ENABLE );sdhci_writel (host,0 ,SDHCI_SIGNAL_ENABLE );@@ -4869,6 +4985,10 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)Quoted 8 lines
drivers/mmc/host/sdhci.c void sdhci_remove_host(struct sdhci_host *host, int dead) · line 4991
Quoted 6 lines
drivers/mmc/host/sdhci.c +4
-0sdhci_led_unregister (host); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + sdhci_uhs2_ops.remove_host) + sdhci_uhs2_ops.remove_host (host, dead); +I think you should look at creating
uhs2_remove_host()insteadQuoted 7 lines
You suggest that we will have separate sdhci_uhs2_[add|remove]_host(), but I don't think it's always convenient.
UHS-II capable host will be set to call
sdhci_uhs2_add_host()explicitly, but we can't do that in case of pci and pltfm based drivers as they utilize common helper functions,sdhci_pci_probe()andsdhci_pltfm_register(), respectively.sdhci-pci has an
add_hostop
sdhci_pltfm_initcan be used instead ofsdhci_pltfm_registerQuoted 8 lines
Therefore, we inevitably have to call
sdhci_uhs2_add_host()there.If so, why should we distinguish
sdhci_uhs2_add_hostfromsdhci_uhs_add_host? I don't see any good reason.
Moreover, as a result, there exists a mixed usage ofsdhci_interfaces andsdhci_uhs2_interfaces insdhci-pci-core.candsdhci-pltfm.c.It sounds odd to me.
Quoted 7 lines
Quoted 1 line
It is already done that way for cqhci.
Okay, if it is your policy, I will follow that.
Then, I'm going to add
-remove_hostfield to structsdhci_pci_fixes
- a controller specific helper function to each driver (only pci-gli for now) even though it looks quite generic.
If they seem generic then consider naming them sdhci_pci_uhs2_[add|remove]_host and putting them in sdhci-pci-core.c
Quoted 7 lines
sdhci_gli_[add|remove]_host(struct sdhci_pci_slot *slot) { return sdhci_uhs2_[add|remove]_host(slot->host); }# Or do you want to create a file like
sdhci-uhs2-pci.cfor those functions?
No
Quoted 14 lines
-Takahiro Akashi
Quoted 11 lines
Quoted 10 lines
-Takahiro Akashi
Quoted 6 lines
Quoted 5 lines
drivers/mmc/host/sdhci.c +0
-0if (!dead)sdhci_do_reset (host,SDHCI_RESET_ALL );
Quoted 119 lines · Adrian Hunter
Quoted 118 lines · AKASHI Takahiro
Adrian,
Quoted 114 lines · Adrian Hunter
Quoted 90 lines · AKASHI Takahiro
Adrian,
Your comments are scattered over various functions, and so I would like to address them in separate replies.
First, I'd like to discuss sdhci_[add|remove]_host().
Quoted 13 lines · Adrian Hunter
Quoted 12 lines · Ben Chuang
From: Ben Chuang <[email protected]>
In this commit, UHS-II related operations will be called via a function pointer array,
sdhci_uhs2_ops, in order to make UHS-II support as a kernel module.
This array will be initialized only ifCONFIG_MMC_SDHCI_UHS2is enabled and when the UHS-II module is loaded. Otherwise, all the functions stay void.Signed-off-by Ben Chuang <[email protected]>Signed-off-by AKASHI Takahiro <[email protected]>---
(snip)
Quoted 57 lines
Quoted 5 lines
drivers/mmc/host/sdhci.c +0
-0if (intmask & (SDHCI_INT_CARD_INSERT |SDHCI_INT_CARD_REMOVE )) {u32 present =sdhci_readl (host,SDHCI_PRESENT_STATE ) &SDHCI_CARD_PRESENT ;@@ -4717,6 +4812,14 @@ int sdhci_setup_host(struct sdhci_host *host)/* This may alter mmc->*_blk_* parameters */ drivers/mmc/host/sdhci.c int sdhci_setup_host(struct sdhci_host *host) · line 4822
Quoted 10 lines
drivers/mmc/host/sdhci.c +8
-0sdhci_allocate_bounce_buffer (host); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->version >=SDHCI_SPEC_400 && + sdhci_uhs2_ops.add_host) { + ret = sdhci_uhs2_ops.add_host (host, host->caps1); +if (ret) + goto unreg; + } +I think you should look at creating
uhs2_add_host()insteadQuoted 39 lines
drivers/mmc/host/sdhci.c +13
-0return 0 ; unreg:@@ -4738,6 +4841,8 @@ void sdhci_cleanup_host(struct sdhci_host *host) {struct mmc_host *mmc = host->mmc; +/* FIXME: Do we have to do some cleanup for UHS2 here? */ +if (!IS_ERR (mmc->supply.vqmmc))regulator_disable (mmc->supply.vqmmc);@@ -4766,6 +4871,14 @@ int __sdhci_add_host(struct sdhci_host *host) mmc->cqe_ops =NULL ; } +if ((mmc->caps &MMC_CAP_UHS2 ) && !host->v4_mode) { +/* host doesn't want to enable UHS2 support */ + mmc->caps &= ~MMC_CAP_UHS2 ; + mmc->flags &= ~MMC_UHS2_SUPPORT ; + +/* FIXME: Do we have to do some cleanup here? */ + } + host->complete_wq =alloc_workqueue ("sdhci" , flags,0 );if (!host->complete_wq)return -ENOMEM ;@@ -4812,6 +4925,9 @@ int __sdhci_add_host(struct sdhci_host *host) unled:sdhci_led_unregister (host); unirq: +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + sdhci_uhs2_ops.remove_host) + sdhci_uhs2_ops.remove_host (host,0 );sdhci_do_reset (host,SDHCI_RESET_ALL );sdhci_writel (host,0 ,SDHCI_INT_ENABLE );sdhci_writel (host,0 ,SDHCI_SIGNAL_ENABLE );@@ -4869,6 +4985,10 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)Quoted 8 lines
drivers/mmc/host/sdhci.c void sdhci_remove_host(struct sdhci_host *host, int dead) · line 4991
Quoted 6 lines
drivers/mmc/host/sdhci.c +4
-0sdhci_led_unregister (host); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + sdhci_uhs2_ops.remove_host) + sdhci_uhs2_ops.remove_host (host, dead); +I think you should look at creating
uhs2_remove_host()insteadQuoted 7 lines
You suggest that we will have separate sdhci_uhs2_[add|remove]_host(), but I don't think it's always convenient.
UHS-II capable host will be set to call
sdhci_uhs2_add_host()explicitly, but we can't do that in case of pci and pltfm based drivers as they utilize common helper functions,sdhci_pci_probe()andsdhci_pltfm_register(), respectively.sdhci-pci has an
add_hostop
sdhci_pltfm_initcan be used instead ofsdhci_pltfm_registerQuoted 8 lines
Therefore, we inevitably have to call
sdhci_uhs2_add_host()there.If so, why should we distinguish
sdhci_uhs2_add_hostfromsdhci_uhs_add_host? I don't see any good reason.
Moreover, as a result, there exists a mixed usage ofsdhci_interfaces andsdhci_uhs2_interfaces insdhci-pci-core.candsdhci-pltfm.c.It sounds odd to me.
It is already done that way for cqhci.
Quoted 8 lines
Quoted 5 lines
Okay, if it is your policy, I will follow that.
Then, I'm going to add
-remove_hostfield to structsdhci_pci_fixes
- a controller specific helper function to each driver (only pci-gli for now) even though it looks quite generic.If they seem generic then consider naming them sdhci_pci_uhs2_[add|remove]_host and putting them in
sdhci-pci-core.c
So you don't mind that UHS-I and UHS-II code are mixed in sdhci-pci-core.c, do you?
-Takahiro Akashi
Quoted 25 lines
Quoted 7 lines
sdhci_gli_[add|remove]_host(struct sdhci_pci_slot *slot) { return sdhci_uhs2_[add|remove]_host(slot->host); }# Or do you want to create a file like
sdhci-uhs2-pci.cfor those functions?No
Quoted 14 lines
-Takahiro Akashi
Quoted 11 lines
Quoted 10 lines
-Takahiro Akashi
Quoted 6 lines
Quoted 5 lines
drivers/mmc/host/sdhci.c +0
-0if (!dead)sdhci_do_reset (host,SDHCI_RESET_ALL );
Adrian, Ben,
Regarding _reset() function,
Quoted 16 lines · Adrian Hunter
Quoted 15 lines · Ben Chuang
From: Ben Chuang <[email protected]>
In this commit, UHS-II related operations will be called via a function pointer array,
sdhci_uhs2_ops, in order to make UHS-II support as a kernel module.
This array will be initialized only ifCONFIG_MMC_SDHCI_UHS2is enabled and when the UHS-II module is loaded. Otherwise, all the functions stay void.Signed-off-by Ben Chuang <[email protected]>Signed-off-by AKASHI Takahiro <[email protected]>--- drivers/mmc/host/sdhci.c | 152 ++++++++++++++++++++++++++++++++++----- 1 file changed, 136 insertions(+), 16 deletions(-)
(snip)
Quoted 28 lines
Quoted 28 lines
drivers/mmc/host/sdhci.c +8
-6if (host->ops->platform_send_init_74_clocks) host->ops->platform_send_init_74_clocks (host, ios->power_mode);@@ -2331,7 +2411,7 @@ void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) }if (host->version >=SDHCI_SPEC_300 ) { -u16 clk, ctrl_2; +u16 clk;if (!host->preset_enabled) {sdhci_writeb (host, ctrl,SDHCI_HOST_CONTROL );@@ -3173,11 +3253,19 @@ static bool sdhci_request_done(struct sdhci_host *host)/* This is to force an update */ host->ops->set_clock (host, host->clock); -/* Spec says we should do both at the same time, but Ricoh -controllers do not like that. */ -sdhci_do_reset (host,SDHCI_RESET_CMD ); -sdhci_do_reset (host,SDHCI_RESET_DATA ); - +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->mmc->flags &MMC_UHS2_INITIALIZED ) { +if (sdhci_uhs2_ops.reset) + sdhci_uhs2_ops.reset (host, +SDHCI_UHS2_SW_RESET_SD ); + }else { +/*
Quoted 8 lines
drivers/mmc/host/sdhci.c static bool sdhci_request_done(struct sdhci_host *host) · line 3268
Quoted 6 lines
drivers/mmc/host/sdhci.c +6
-0+* Spec says we should do both at the same time, but +* Ricoh controllers do not like that. +*/ +sdhci_do_reset (host,SDHCI_RESET_CMD ); +sdhci_do_reset (host,SDHCI_RESET_DATA ); + }Please look at using the existing ->reset() sdhci host op instead.
Well, the second argument to those reset functions is a bit-wise value to different "reset" registers, SDHCI_SOFTWARE_RESET and SDHCI_UHS2_SW_RESET, respectively.
This fact raises a couple of questions to me:
1) Does it make sense to merge two functionality into one, i.e. sdhci_do_reset(), which is set to call ->reset hook?
-> Adrian
2) UHS2_SW_RESET_SD is done only at this place while there are many callsites of reset(RESET_CMD|RESET_DATA) in sdhci.c.
Why does the current code work?
I found, in sdhci-pci-gli.c,
sdhci_gl9755_reset()
/* reset sd-tran on UHS2 mode if need to reset cmd/data */
if ((mask & SDHCI_RESET_CMD) | (mask & SDHCI_RESET_DATA))
gl9755_uhs2_reset_sd_tran(host); Is this the trick to avoid the issue?
(It looks redundant in terms of the hack above in sdhci_request_done() and even quite dirty to me. Moreover, no corresponding code for gl9750 and gl9763.)
-> Ben
3) (More or less SD specification issue)
In UHS-II mode, do we have to call reset(SHCI_RESET_ALL) along with reset(UHS2_SW_RESET_FULL)?
Under the current implementation, both will be called at the end.
-> Adrian, Ben
4) (Not directly linked to UHS-II support)
In some places, we see the sequence:
sdhci_do_reset(host, SDHCI_RESET_CMD);
sdhci_do_reset(host, SDHCI_RESET_DATA);
while in other places,
sdhci_do_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA);If the statement below is true,
Quoted 2 lines
drivers/mmc/host/sdhci.c static bool sdhci_request_done(struct sdhci_host *host) · line 3177
Quoted 2 lines
drivers/mmc/host/sdhci.c +0
-2-/* Spec says we should do both at the same time, but Ricoh -controllers do not like that. */
the latter should be wrong.
-> Adrian
-Takahiro Akashi
Quoted 88 lines
Quoted 4 lines
drivers/mmc/host/sdhci.c +0
-0host->pending_reset = false; }drivers/mmc/host/sdhci.c static irqreturn_t sdhci_irq(int irq, void *dev_id) · line 3629
Quoted 10 lines
drivers/mmc/host/sdhci.c +7
-0@@ -3532,6 +3620,13 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id) SDHCI_INT_BUS_POWER);sdhci_writel (host, mask,SDHCI_INT_STATUS ); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + intmask &SDHCI_INT_ERROR && + host->mmc->flags &MMC_UHS2_SUPPORT ) { +if (sdhci_uhs2_ops.irq) + sdhci_uhs2_ops.irq (host); + } +Please look at using the existing ->irq() sdhci host op instead
Quoted 5 lines
drivers/mmc/host/sdhci.c +0
-0if (intmask & (SDHCI_INT_CARD_INSERT |SDHCI_INT_CARD_REMOVE )) {u32 present =sdhci_readl (host,SDHCI_PRESENT_STATE ) &SDHCI_CARD_PRESENT ;@@ -4717,6 +4812,14 @@ int sdhci_setup_host(struct sdhci_host *host)/* This may alter mmc->*_blk_* parameters */ drivers/mmc/host/sdhci.c int sdhci_setup_host(struct sdhci_host *host) · line 4822
Quoted 10 lines
drivers/mmc/host/sdhci.c +8
-0sdhci_allocate_bounce_buffer (host); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->version >=SDHCI_SPEC_400 && + sdhci_uhs2_ops.add_host) { + ret = sdhci_uhs2_ops.add_host (host, host->caps1); +if (ret) + goto unreg; + } +I think you should look at creating
uhs2_add_host()insteadQuoted 38 lines
drivers/mmc/host/sdhci.c +13
-0return 0 ; unreg:@@ -4738,6 +4841,8 @@ void sdhci_cleanup_host(struct sdhci_host *host) {struct mmc_host *mmc = host->mmc; +/* FIXME: Do we have to do some cleanup for UHS2 here? */ +if (!IS_ERR (mmc->supply.vqmmc))regulator_disable (mmc->supply.vqmmc);@@ -4766,6 +4871,14 @@ int __sdhci_add_host(struct sdhci_host *host) mmc->cqe_ops =NULL ; } +if ((mmc->caps &MMC_CAP_UHS2 ) && !host->v4_mode) { +/* host doesn't want to enable UHS2 support */ + mmc->caps &= ~MMC_CAP_UHS2 ; + mmc->flags &= ~MMC_UHS2_SUPPORT ; + +/* FIXME: Do we have to do some cleanup here? */ + } + host->complete_wq =alloc_workqueue ("sdhci" , flags,0 );if (!host->complete_wq)return -ENOMEM ;@@ -4812,6 +4925,9 @@ int __sdhci_add_host(struct sdhci_host *host) unled:sdhci_led_unregister (host); unirq: +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + sdhci_uhs2_ops.remove_host) + sdhci_uhs2_ops.remove_host (host,0 );sdhci_do_reset (host,SDHCI_RESET_ALL );sdhci_writel (host,0 ,SDHCI_INT_ENABLE );sdhci_writel (host,0 ,SDHCI_SIGNAL_ENABLE );drivers/mmc/host/sdhci.c void sdhci_remove_host(struct sdhci_host *host, int dead) · line 4991
Quoted 7 lines
drivers/mmc/host/sdhci.c +4
-0@@ -4869,6 +4985,10 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)sdhci_led_unregister (host); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + sdhci_uhs2_ops.remove_host) + sdhci_uhs2_ops.remove_host (host, dead); +I think you should look at creating
uhs2_remove_host()insteadQuoted 4 lines
drivers/mmc/host/sdhci.c +0
-0if (!dead)sdhci_do_reset (host,SDHCI_RESET_ALL );
Hi Takahiro,
Quoted 79 lines · AKASHI Takahiro
Adrian, Ben,
Regarding
_reset()function,Quoted 16 lines · Adrian Hunter
Quoted 15 lines · Ben Chuang
From: Ben Chuang <[email protected]>
In this commit, UHS-II related operations will be called via a function pointer array,
sdhci_uhs2_ops, in order to make UHS-II support as a kernel module.
This array will be initialized only ifCONFIG_MMC_SDHCI_UHS2is enabled and when the UHS-II module is loaded. Otherwise, all the functions stay void.Signed-off-by Ben Chuang <[email protected]>Signed-off-by AKASHI Takahiro <[email protected]>--- drivers/mmc/host/sdhci.c | 152 ++++++++++++++++++++++++++++++++++----- 1 file changed, 136 insertions(+), 16 deletions(-)(snip)
Quoted 28 lines
Quoted 28 lines
if (host->ops->platform_send_init_74_clocks) host->ops->platform_send_init_74_clocks(host, ios->power_mode);drivers/mmc/host/sdhci.c +8
-6@@ -2331,7 +2411,7 @@ void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) }if (host->version >=SDHCI_SPEC_300 ) { -u16 clk, ctrl_2; +u16 clk;if (!host->preset_enabled) {sdhci_writeb (host, ctrl,SDHCI_HOST_CONTROL );@@ -3173,11 +3253,19 @@ static bool sdhci_request_done(struct sdhci_host *host)/* This is to force an update */ host->ops->set_clock (host, host->clock); -/* Spec says we should do both at the same time, but Ricoh -controllers do not like that. */ -sdhci_do_reset (host,SDHCI_RESET_CMD ); -sdhci_do_reset (host,SDHCI_RESET_DATA ); - +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->mmc->flags &MMC_UHS2_INITIALIZED ) { +if (sdhci_uhs2_ops.reset) + sdhci_uhs2_ops.reset (host, +SDHCI_UHS2_SW_RESET_SD ); + }else { +/* Quoted 8 lines
drivers/mmc/host/sdhci.c static bool sdhci_request_done(struct sdhci_host *host) · line 3268
Quoted 6 lines
drivers/mmc/host/sdhci.c +6
-0+* Spec says we should do both at the same time, but +* Ricoh controllers do not like that. +*/ +sdhci_do_reset (host,SDHCI_RESET_CMD ); +sdhci_do_reset (host,SDHCI_RESET_DATA ); + }Please look at using the existing ->reset() sdhci host op instead.
Well, the second argument to those reset functions is a bit-wise value to different "reset" registers,
SDHCI_SOFTWARE_RESETandSDHCI_UHS2_SW_RESET, respectively.This fact raises a couple of questions to me:
1) Does it make sense to merge two functionality into one, i.e.
sdhci_do_reset(), which is set to call ->reset hook?-> Adrian2)
UHS2_SW_RESET_SDis done only at this place while there are many callsites ofreset(RESET_CMD|RESET_DATA)insdhci.c.
Why does the current code work?I found, in
sdhci-pci-gli.c,
sdhci_gl9755_reset()
Quoted 8 lines
/* reset sd-tran on UHS2 mode if need to reset cmd/data */ if ((mask & SDHCI_RESET_CMD) | (mask & SDHCI_RESET_DATA)) gl9755_uhs2_reset_sd_tran(host);Is this the trick to avoid the issue?
(It looks redundant in terms of the hack above insdhci_request_done()and even quite dirty to me. Moreover, no corresponding code for gl9750 and gl9763.)
GL9755 currently does SD reset and UHS-II reset together. There is no UHS-II interface on gl9750 and gl9763e.
Quoted 8 lines
-> Ben3) (More or less SD specification issue)
In UHS-II mode, do we have to callreset(SHCI_RESET_ALL)along withreset(UHS2_SW_RESET_FULL)?
Under the current implementation, both will be called at the end.
As I know, the UHS2_SW_RESET_FULL is only for UHS-II. Can you list the lines that reset(SHCI_RESET_ALL) and reset(UHS2_SW_RESET_FULL) are both called?
Quoted 108 lines
-> Adrian, Ben4) (Not directly linked to UHS-II support)
In some places, we see the sequence:sdhci_do_reset(host, SDHCI_RESET_CMD); sdhci_do_reset(host, SDHCI_RESET_DATA); while in other places, sdhci_do_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA);If the statement below is true,
Quoted 2 lines
drivers/mmc/host/sdhci.c static bool sdhci_request_done(struct sdhci_host *host) · line 3177
Quoted 2 lines
drivers/mmc/host/sdhci.c +0
-2-/* Spec says we should do both at the same time, but Ricoh -controllers do not like that. */ the latter should be wrong.
-> Adrian-Takahiro Akashi
Quoted 88 lines
Quoted 4 lines
drivers/mmc/host/sdhci.c +0
-0host->pending_reset = false; }drivers/mmc/host/sdhci.c static irqreturn_t sdhci_irq(int irq, void *dev_id) · line 3629
Quoted 10 lines
drivers/mmc/host/sdhci.c +7
-0@@ -3532,6 +3620,13 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id) SDHCI_INT_BUS_POWER);sdhci_writel (host, mask,SDHCI_INT_STATUS ); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + intmask &SDHCI_INT_ERROR && + host->mmc->flags &MMC_UHS2_SUPPORT ) { +if (sdhci_uhs2_ops.irq) + sdhci_uhs2_ops.irq (host); + } +Please look at using the existing ->irq() sdhci host op instead
Quoted 5 lines
drivers/mmc/host/sdhci.c +0
-0if (intmask & (SDHCI_INT_CARD_INSERT |SDHCI_INT_CARD_REMOVE )) {u32 present =sdhci_readl (host,SDHCI_PRESENT_STATE ) &SDHCI_CARD_PRESENT ;@@ -4717,6 +4812,14 @@ int sdhci_setup_host(struct sdhci_host *host)/* This may alter mmc->*_blk_* parameters */ drivers/mmc/host/sdhci.c int sdhci_setup_host(struct sdhci_host *host) · line 4822
Quoted 10 lines
drivers/mmc/host/sdhci.c +8
-0sdhci_allocate_bounce_buffer (host); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->version >=SDHCI_SPEC_400 && + sdhci_uhs2_ops.add_host) { + ret = sdhci_uhs2_ops.add_host (host, host->caps1); +if (ret) + goto unreg; + } +I think you should look at creating
uhs2_add_host()insteadQuoted 38 lines
drivers/mmc/host/sdhci.c +13
-0return 0 ; unreg:@@ -4738,6 +4841,8 @@ void sdhci_cleanup_host(struct sdhci_host *host) {struct mmc_host *mmc = host->mmc; +/* FIXME: Do we have to do some cleanup for UHS2 here? */ +if (!IS_ERR (mmc->supply.vqmmc))regulator_disable (mmc->supply.vqmmc);@@ -4766,6 +4871,14 @@ int __sdhci_add_host(struct sdhci_host *host) mmc->cqe_ops =NULL ; } +if ((mmc->caps &MMC_CAP_UHS2 ) && !host->v4_mode) { +/* host doesn't want to enable UHS2 support */ + mmc->caps &= ~MMC_CAP_UHS2 ; + mmc->flags &= ~MMC_UHS2_SUPPORT ; + +/* FIXME: Do we have to do some cleanup here? */ + } + host->complete_wq =alloc_workqueue ("sdhci" , flags,0 );if (!host->complete_wq)return -ENOMEM ;@@ -4812,6 +4925,9 @@ int __sdhci_add_host(struct sdhci_host *host) unled:sdhci_led_unregister (host); unirq: +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + sdhci_uhs2_ops.remove_host) + sdhci_uhs2_ops.remove_host (host,0 );sdhci_do_reset (host,SDHCI_RESET_ALL );sdhci_writel (host,0 ,SDHCI_INT_ENABLE );sdhci_writel (host,0 ,SDHCI_SIGNAL_ENABLE );drivers/mmc/host/sdhci.c void sdhci_remove_host(struct sdhci_host *host, int dead) · line 4991
Quoted 7 lines
drivers/mmc/host/sdhci.c +4
-0@@ -4869,6 +4985,10 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)sdhci_led_unregister (host); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + sdhci_uhs2_ops.remove_host) + sdhci_uhs2_ops.remove_host (host, dead); +I think you should look at creating
uhs2_remove_host()insteadQuoted 4 lines
drivers/mmc/host/sdhci.c +0
-0if (!dead)sdhci_do_reset (host,SDHCI_RESET_ALL );
Ben,
Quoted 86 lines · Ben Chuang
Hi Takahiro,
Quoted 82 lines · AKASHI Takahiro
Adrian, Ben,
Regarding
_reset()function,Quoted 16 lines · Adrian Hunter
Quoted 15 lines · Ben Chuang
From: Ben Chuang <[email protected]>
In this commit, UHS-II related operations will be called via a function pointer array,
sdhci_uhs2_ops, in order to make UHS-II support as a kernel module.
This array will be initialized only ifCONFIG_MMC_SDHCI_UHS2is enabled and when the UHS-II module is loaded. Otherwise, all the functions stay void.Signed-off-by Ben Chuang <[email protected]>Signed-off-by AKASHI Takahiro <[email protected]>--- drivers/mmc/host/sdhci.c | 152 ++++++++++++++++++++++++++++++++++----- 1 file changed, 136 insertions(+), 16 deletions(-)(snip)
Quoted 28 lines
Quoted 28 lines
if (host->ops->platform_send_init_74_clocks) host->ops->platform_send_init_74_clocks(host, ios->power_mode);drivers/mmc/host/sdhci.c +8
-6@@ -2331,7 +2411,7 @@ void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) }if (host->version >=SDHCI_SPEC_300 ) { -u16 clk, ctrl_2; +u16 clk;if (!host->preset_enabled) {sdhci_writeb (host, ctrl,SDHCI_HOST_CONTROL );@@ -3173,11 +3253,19 @@ static bool sdhci_request_done(struct sdhci_host *host)/* This is to force an update */ host->ops->set_clock (host, host->clock); -/* Spec says we should do both at the same time, but Ricoh -controllers do not like that. */ -sdhci_do_reset (host,SDHCI_RESET_CMD ); -sdhci_do_reset (host,SDHCI_RESET_DATA ); - +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->mmc->flags &MMC_UHS2_INITIALIZED ) { +if (sdhci_uhs2_ops.reset) + sdhci_uhs2_ops.reset (host, +SDHCI_UHS2_SW_RESET_SD ); + }else { +/* Quoted 8 lines
drivers/mmc/host/sdhci.c static bool sdhci_request_done(struct sdhci_host *host) · line 3268
Quoted 6 lines
drivers/mmc/host/sdhci.c +6
-0+* Spec says we should do both at the same time, but +* Ricoh controllers do not like that. +*/ +sdhci_do_reset (host,SDHCI_RESET_CMD ); +sdhci_do_reset (host,SDHCI_RESET_DATA ); + }Please look at using the existing ->reset() sdhci host op instead.
Well, the second argument to those reset functions is a bit-wise value to different "reset" registers,
SDHCI_SOFTWARE_RESETandSDHCI_UHS2_SW_RESET, respectively.This fact raises a couple of questions to me:
1) Does it make sense to merge two functionality into one, i.e.
sdhci_do_reset(), which is set to call ->reset hook?-> Adrian2)
UHS2_SW_RESET_SDis done only at this place while there are many callsites ofreset(RESET_CMD|RESET_DATA)insdhci.c.
Why does the current code work?I found, in sdhci-pci-gli.c, sdhci_gl9755_reset() /* reset sd-tran on UHS2 mode if need to reset cmd/data */ if ((mask & SDHCI_RESET_CMD) | (mask & SDHCI_RESET_DATA)) gl9755_uhs2_reset_sd_tran(host);
(A)
Quoted 7 lines
Quoted 5 lines
Is this the trick to avoid the issue?
(It looks redundant in terms of the hack above insdhci_request_done()and even quite dirty to me. Moreover, no corresponding code for gl9750 and gl9763.)GL9755 currently does SD reset and UHS-II reset together.
Do you mean that, in UHS-II operations, you need only the reset on SDHCI_UHS2_SW_RESET register?
But the hunk above (A) does the UHS-II reset along with UHS-I reset.
Quoted 11 lines
There is no UHS-II interface on gl9750 and gl9763e.
Quoted 8 lines
-> Ben3) (More or less SD specification issue)
In UHS-II mode, do we have to callreset(SHCI_RESET_ALL)along withreset(UHS2_SW_RESET_FULL)?
Under the current implementation, both will be called at the end.
Quoted 3 lines
As I know, the
UHS2_SW_RESET_FULLis only for UHS-II. Can you list the lines thatreset(SHCI_RESET_ALL)andreset(UHS2_SW_RESET_FULL)are both called?
I was not clear here. (The above is also another example.)
Look at sdhci_remove_host() and shdci_uhs2_remote_host(). If the argument 'dead' is 0, we will do both of the resets for UHS-II.
-Takahiro Akashi
Quoted 108 lines
Quoted 108 lines
-> Adrian, Ben4) (Not directly linked to UHS-II support)
In some places, we see the sequence:sdhci_do_reset(host, SDHCI_RESET_CMD); sdhci_do_reset(host, SDHCI_RESET_DATA); while in other places, sdhci_do_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA);If the statement below is true,
Quoted 2 lines
drivers/mmc/host/sdhci.c static bool sdhci_request_done(struct sdhci_host *host) · line 3177
Quoted 2 lines
drivers/mmc/host/sdhci.c +0
-2-/* Spec says we should do both at the same time, but Ricoh -controllers do not like that. */ the latter should be wrong.
-> Adrian-Takahiro Akashi
Quoted 88 lines
Quoted 4 lines
drivers/mmc/host/sdhci.c +0
-0host->pending_reset = false; }drivers/mmc/host/sdhci.c static irqreturn_t sdhci_irq(int irq, void *dev_id) · line 3629
Quoted 10 lines
drivers/mmc/host/sdhci.c +7
-0@@ -3532,6 +3620,13 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id) SDHCI_INT_BUS_POWER);sdhci_writel (host, mask,SDHCI_INT_STATUS ); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + intmask &SDHCI_INT_ERROR && + host->mmc->flags &MMC_UHS2_SUPPORT ) { +if (sdhci_uhs2_ops.irq) + sdhci_uhs2_ops.irq (host); + } +Please look at using the existing ->irq() sdhci host op instead
Quoted 5 lines
drivers/mmc/host/sdhci.c +0
-0if (intmask & (SDHCI_INT_CARD_INSERT |SDHCI_INT_CARD_REMOVE )) {u32 present =sdhci_readl (host,SDHCI_PRESENT_STATE ) &SDHCI_CARD_PRESENT ;@@ -4717,6 +4812,14 @@ int sdhci_setup_host(struct sdhci_host *host)/* This may alter mmc->*_blk_* parameters */ drivers/mmc/host/sdhci.c int sdhci_setup_host(struct sdhci_host *host) · line 4822
Quoted 10 lines
drivers/mmc/host/sdhci.c +8
-0sdhci_allocate_bounce_buffer (host); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->version >=SDHCI_SPEC_400 && + sdhci_uhs2_ops.add_host) { + ret = sdhci_uhs2_ops.add_host (host, host->caps1); +if (ret) + goto unreg; + } +I think you should look at creating
uhs2_add_host()insteadQuoted 38 lines
drivers/mmc/host/sdhci.c +13
-0return 0 ; unreg:@@ -4738,6 +4841,8 @@ void sdhci_cleanup_host(struct sdhci_host *host) {struct mmc_host *mmc = host->mmc; +/* FIXME: Do we have to do some cleanup for UHS2 here? */ +if (!IS_ERR (mmc->supply.vqmmc))regulator_disable (mmc->supply.vqmmc);@@ -4766,6 +4871,14 @@ int __sdhci_add_host(struct sdhci_host *host) mmc->cqe_ops =NULL ; } +if ((mmc->caps &MMC_CAP_UHS2 ) && !host->v4_mode) { +/* host doesn't want to enable UHS2 support */ + mmc->caps &= ~MMC_CAP_UHS2 ; + mmc->flags &= ~MMC_UHS2_SUPPORT ; + +/* FIXME: Do we have to do some cleanup here? */ + } + host->complete_wq =alloc_workqueue ("sdhci" , flags,0 );if (!host->complete_wq)return -ENOMEM ;@@ -4812,6 +4925,9 @@ int __sdhci_add_host(struct sdhci_host *host) unled:sdhci_led_unregister (host); unirq: +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + sdhci_uhs2_ops.remove_host) + sdhci_uhs2_ops.remove_host (host,0 );sdhci_do_reset (host,SDHCI_RESET_ALL );sdhci_writel (host,0 ,SDHCI_INT_ENABLE );sdhci_writel (host,0 ,SDHCI_SIGNAL_ENABLE );drivers/mmc/host/sdhci.c void sdhci_remove_host(struct sdhci_host *host, int dead) · line 4991
Quoted 7 lines
drivers/mmc/host/sdhci.c +4
-0@@ -4869,6 +4985,10 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)sdhci_led_unregister (host); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + sdhci_uhs2_ops.remove_host) + sdhci_uhs2_ops.remove_host (host, dead); +I think you should look at creating
uhs2_remove_host()insteadQuoted 4 lines
drivers/mmc/host/sdhci.c +0
-0if (!dead)sdhci_do_reset (host,SDHCI_RESET_ALL );
Quoted 99 lines · AKASHI Takahiro
Ben,
Quoted 86 lines · Ben Chuang
Hi Takahiro,
Quoted 82 lines · AKASHI Takahiro
Adrian, Ben,
Regarding
_reset()function,Quoted 16 lines · Adrian Hunter
Quoted 15 lines · Ben Chuang
From: Ben Chuang <[email protected]>
In this commit, UHS-II related operations will be called via a function pointer array,
sdhci_uhs2_ops, in order to make UHS-II support as a kernel module.
This array will be initialized only ifCONFIG_MMC_SDHCI_UHS2is enabled and when the UHS-II module is loaded. Otherwise, all the functions stay void.Signed-off-by Ben Chuang <[email protected]>Signed-off-by AKASHI Takahiro <[email protected]>--- drivers/mmc/host/sdhci.c | 152 ++++++++++++++++++++++++++++++++++----- 1 file changed, 136 insertions(+), 16 deletions(-)(snip)
Quoted 28 lines
Quoted 28 lines
if (host->ops->platform_send_init_74_clocks) host->ops->platform_send_init_74_clocks(host, ios->power_mode);drivers/mmc/host/sdhci.c +8
-6@@ -2331,7 +2411,7 @@ void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) }if (host->version >=SDHCI_SPEC_300 ) { -u16 clk, ctrl_2; +u16 clk;if (!host->preset_enabled) {sdhci_writeb (host, ctrl,SDHCI_HOST_CONTROL );@@ -3173,11 +3253,19 @@ static bool sdhci_request_done(struct sdhci_host *host)/* This is to force an update */ host->ops->set_clock (host, host->clock); -/* Spec says we should do both at the same time, but Ricoh -controllers do not like that. */ -sdhci_do_reset (host,SDHCI_RESET_CMD ); -sdhci_do_reset (host,SDHCI_RESET_DATA ); - +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->mmc->flags &MMC_UHS2_INITIALIZED ) { +if (sdhci_uhs2_ops.reset) + sdhci_uhs2_ops.reset (host, +SDHCI_UHS2_SW_RESET_SD ); + }else { +/* Quoted 8 lines
drivers/mmc/host/sdhci.c static bool sdhci_request_done(struct sdhci_host *host) · line 3268
Quoted 6 lines
drivers/mmc/host/sdhci.c +6
-0+* Spec says we should do both at the same time, but +* Ricoh controllers do not like that. +*/ +sdhci_do_reset (host,SDHCI_RESET_CMD ); +sdhci_do_reset (host,SDHCI_RESET_DATA ); + }Please look at using the existing ->reset() sdhci host op instead.
Well, the second argument to those reset functions is a bit-wise value to different "reset" registers,
SDHCI_SOFTWARE_RESETandSDHCI_UHS2_SW_RESET, respectively.This fact raises a couple of questions to me:
1) Does it make sense to merge two functionality into one, i.e.
sdhci_do_reset(), which is set to call ->reset hook?-> Adrian2)
UHS2_SW_RESET_SDis done only at this place while there are many callsites ofreset(RESET_CMD|RESET_DATA)insdhci.c.
Why does the current code work?I found, in sdhci-pci-gli.c, sdhci_gl9755_reset() /* reset sd-tran on UHS2 mode if need to reset cmd/data */ if ((mask & SDHCI_RESET_CMD) | (mask & SDHCI_RESET_DATA)) gl9755_uhs2_reset_sd_tran(host);(A)
Quoted 6 lines
Quoted 5 lines
Is this the trick to avoid the issue?
(It looks redundant in terms of the hack above insdhci_request_done()and even quite dirty to me. Moreover, no corresponding code for gl9750 and gl9763.)
Quoted 4 lines
Quoted 1 line
GL9755 currently does SD reset and UHS-II reset together.
Do you mean that, in UHS-II operations, you need only the reset on
SDHCI_UHS2_SW_RESETregister?
No, GL9755 does SD reset and UHS-II reset together.
Quoted 13 lines
But the hunk above (A) does the UHS-II reset along with UHS-I reset.
Quoted 11 lines
There is no UHS-II interface on gl9750 and gl9763e.
Quoted 8 lines
-> Ben3) (More or less SD specification issue)
In UHS-II mode, do we have to callreset(SHCI_RESET_ALL)along withreset(UHS2_SW_RESET_FULL)?
Under the current implementation, both will be called at the end.
Quoted 8 lines
Quoted 3 lines
As I know, the
UHS2_SW_RESET_FULLis only for UHS-II. Can you list the lines thatreset(SHCI_RESET_ALL)andreset(UHS2_SW_RESET_FULL)are both called?I was not clear here. (The above is also another example.)
Look at
sdhci_remove_host()andshdci_uhs2_remote_host(). If the argument 'dead' is 0, we will do both of the resets for UHS-II.
Do UHS2_SW_RESET_FULL in sdhci_uhs2_remove_host() and then doSDHCI_RESET_ALL in sdhci_remove_host() is ok.
Quoted 111 lines
-Takahiro Akashi
Quoted 108 lines
Quoted 108 lines
-> Adrian, Ben4) (Not directly linked to UHS-II support)
In some places, we see the sequence:sdhci_do_reset(host, SDHCI_RESET_CMD); sdhci_do_reset(host, SDHCI_RESET_DATA); while in other places, sdhci_do_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA);If the statement below is true,
Quoted 2 lines
drivers/mmc/host/sdhci.c static bool sdhci_request_done(struct sdhci_host *host) · line 3177
Quoted 2 lines
drivers/mmc/host/sdhci.c +0
-2-/* Spec says we should do both at the same time, but Ricoh -controllers do not like that. */ the latter should be wrong.
-> Adrian-Takahiro Akashi
Quoted 88 lines
Quoted 4 lines
drivers/mmc/host/sdhci.c +0
-0host->pending_reset = false; }drivers/mmc/host/sdhci.c static irqreturn_t sdhci_irq(int irq, void *dev_id) · line 3629
Quoted 10 lines
drivers/mmc/host/sdhci.c +7
-0@@ -3532,6 +3620,13 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id) SDHCI_INT_BUS_POWER);sdhci_writel (host, mask,SDHCI_INT_STATUS ); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + intmask &SDHCI_INT_ERROR && + host->mmc->flags &MMC_UHS2_SUPPORT ) { +if (sdhci_uhs2_ops.irq) + sdhci_uhs2_ops.irq (host); + } +Please look at using the existing ->irq() sdhci host op instead
Quoted 5 lines
drivers/mmc/host/sdhci.c +0
-0if (intmask & (SDHCI_INT_CARD_INSERT |SDHCI_INT_CARD_REMOVE )) {u32 present =sdhci_readl (host,SDHCI_PRESENT_STATE ) &SDHCI_CARD_PRESENT ;@@ -4717,6 +4812,14 @@ int sdhci_setup_host(struct sdhci_host *host)/* This may alter mmc->*_blk_* parameters */ drivers/mmc/host/sdhci.c int sdhci_setup_host(struct sdhci_host *host) · line 4822
Quoted 10 lines
drivers/mmc/host/sdhci.c +8
-0sdhci_allocate_bounce_buffer (host); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->version >=SDHCI_SPEC_400 && + sdhci_uhs2_ops.add_host) { + ret = sdhci_uhs2_ops.add_host (host, host->caps1); +if (ret) + goto unreg; + } +I think you should look at creating
uhs2_add_host()insteadQuoted 38 lines
drivers/mmc/host/sdhci.c +13
-0return 0 ; unreg:@@ -4738,6 +4841,8 @@ void sdhci_cleanup_host(struct sdhci_host *host) {struct mmc_host *mmc = host->mmc; +/* FIXME: Do we have to do some cleanup for UHS2 here? */ +if (!IS_ERR (mmc->supply.vqmmc))regulator_disable (mmc->supply.vqmmc);@@ -4766,6 +4871,14 @@ int __sdhci_add_host(struct sdhci_host *host) mmc->cqe_ops =NULL ; } +if ((mmc->caps &MMC_CAP_UHS2 ) && !host->v4_mode) { +/* host doesn't want to enable UHS2 support */ + mmc->caps &= ~MMC_CAP_UHS2 ; + mmc->flags &= ~MMC_UHS2_SUPPORT ; + +/* FIXME: Do we have to do some cleanup here? */ + } + host->complete_wq =alloc_workqueue ("sdhci" , flags,0 );if (!host->complete_wq)return -ENOMEM ;@@ -4812,6 +4925,9 @@ int __sdhci_add_host(struct sdhci_host *host) unled:sdhci_led_unregister (host); unirq: +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + sdhci_uhs2_ops.remove_host) + sdhci_uhs2_ops.remove_host (host,0 );sdhci_do_reset (host,SDHCI_RESET_ALL );sdhci_writel (host,0 ,SDHCI_INT_ENABLE );sdhci_writel (host,0 ,SDHCI_SIGNAL_ENABLE );drivers/mmc/host/sdhci.c void sdhci_remove_host(struct sdhci_host *host, int dead) · line 4991
Quoted 7 lines
drivers/mmc/host/sdhci.c +4
-0@@ -4869,6 +4985,10 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)sdhci_led_unregister (host); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + sdhci_uhs2_ops.remove_host) + sdhci_uhs2_ops.remove_host (host, dead); +I think you should look at creating
uhs2_remove_host()insteadQuoted 4 lines
drivers/mmc/host/sdhci.c +0
-0if (!dead)sdhci_do_reset (host,SDHCI_RESET_ALL );
Ben,
Quoted 101 lines · Ben Chuang
Quoted 99 lines · AKASHI Takahiro
Ben,
Quoted 86 lines · Ben Chuang
Hi Takahiro,
Quoted 82 lines · AKASHI Takahiro
Adrian, Ben,
Regarding
_reset()function,Quoted 16 lines · Adrian Hunter
Quoted 15 lines · Ben Chuang
From: Ben Chuang <[email protected]>
In this commit, UHS-II related operations will be called via a function pointer array,
sdhci_uhs2_ops, in order to make UHS-II support as a kernel module.
This array will be initialized only ifCONFIG_MMC_SDHCI_UHS2is enabled and when the UHS-II module is loaded. Otherwise, all the functions stay void.Signed-off-by Ben Chuang <[email protected]>Signed-off-by AKASHI Takahiro <[email protected]>--- drivers/mmc/host/sdhci.c | 152 ++++++++++++++++++++++++++++++++++----- 1 file changed, 136 insertions(+), 16 deletions(-)(snip)
Quoted 28 lines
Quoted 28 lines
if (host->ops->platform_send_init_74_clocks) host->ops->platform_send_init_74_clocks(host, ios->power_mode);drivers/mmc/host/sdhci.c +8
-6@@ -2331,7 +2411,7 @@ void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) }if (host->version >=SDHCI_SPEC_300 ) { -u16 clk, ctrl_2; +u16 clk;if (!host->preset_enabled) {sdhci_writeb (host, ctrl,SDHCI_HOST_CONTROL );@@ -3173,11 +3253,19 @@ static bool sdhci_request_done(struct sdhci_host *host)/* This is to force an update */ host->ops->set_clock (host, host->clock); -/* Spec says we should do both at the same time, but Ricoh -controllers do not like that. */ -sdhci_do_reset (host,SDHCI_RESET_CMD ); -sdhci_do_reset (host,SDHCI_RESET_DATA ); - +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->mmc->flags &MMC_UHS2_INITIALIZED ) { +if (sdhci_uhs2_ops.reset) + sdhci_uhs2_ops.reset (host, +SDHCI_UHS2_SW_RESET_SD ); + }else { +/* Quoted 8 lines
drivers/mmc/host/sdhci.c static bool sdhci_request_done(struct sdhci_host *host) · line 3268
Quoted 6 lines
drivers/mmc/host/sdhci.c +6
-0+* Spec says we should do both at the same time, but +* Ricoh controllers do not like that. +*/ +sdhci_do_reset (host,SDHCI_RESET_CMD ); +sdhci_do_reset (host,SDHCI_RESET_DATA ); + }Please look at using the existing ->reset() sdhci host op instead.
Well, the second argument to those reset functions is a bit-wise value to different "reset" registers,
SDHCI_SOFTWARE_RESETandSDHCI_UHS2_SW_RESET, respectively.This fact raises a couple of questions to me:
1) Does it make sense to merge two functionality into one, i.e.
sdhci_do_reset(), which is set to call ->reset hook?-> Adrian2)
UHS2_SW_RESET_SDis done only at this place while there are many callsites ofreset(RESET_CMD|RESET_DATA)insdhci.c.
Why does the current code work?I found, in sdhci-pci-gli.c, sdhci_gl9755_reset() /* reset sd-tran on UHS2 mode if need to reset cmd/data */ if ((mask & SDHCI_RESET_CMD) | (mask & SDHCI_RESET_DATA)) gl9755_uhs2_reset_sd_tran(host);(A)
Quoted 6 lines
Quoted 5 lines
Is this the trick to avoid the issue?
(It looks redundant in terms of the hack above insdhci_request_done()and even quite dirty to me. Moreover, no corresponding code for gl9750 and gl9763.)
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
GL9755 currently does SD reset and UHS-II reset together.
Do you mean that, in UHS-II operations, you need only the reset on
SDHCI_UHS2_SW_RESETregister?No, GL9755 does SD reset and UHS-II reset together.
Is this also true for all sdhci controller drivers in general? As I said, I didn't find any precise description about this in SD specification.
-Takahiro Akashi
Quoted 137 lines
Quoted 13 lines
But the hunk above (A) does the UHS-II reset along with UHS-I reset.
Quoted 11 lines
There is no UHS-II interface on gl9750 and gl9763e.
Quoted 8 lines
-> Ben3) (More or less SD specification issue)
In UHS-II mode, do we have to callreset(SHCI_RESET_ALL)along withreset(UHS2_SW_RESET_FULL)?
Under the current implementation, both will be called at the end.Quoted 8 lines
Quoted 3 lines
As I know, the
UHS2_SW_RESET_FULLis only for UHS-II. Can you list the lines thatreset(SHCI_RESET_ALL)andreset(UHS2_SW_RESET_FULL)are both called?I was not clear here. (The above is also another example.)
Look at
sdhci_remove_host()andshdci_uhs2_remote_host(). If the argument 'dead' is 0, we will do both of the resets for UHS-II.Do
UHS2_SW_RESET_FULLinsdhci_uhs2_remove_host()and then doSDHCI_RESET_ALLinsdhci_remove_host()is ok.Quoted 111 lines
-Takahiro Akashi
Quoted 108 lines
Quoted 108 lines
-> Adrian, Ben4) (Not directly linked to UHS-II support)
In some places, we see the sequence:sdhci_do_reset(host, SDHCI_RESET_CMD); sdhci_do_reset(host, SDHCI_RESET_DATA); while in other places, sdhci_do_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA);If the statement below is true,
Quoted 2 lines
drivers/mmc/host/sdhci.c static bool sdhci_request_done(struct sdhci_host *host) · line 3177
Quoted 2 lines
drivers/mmc/host/sdhci.c +0
-2-/* Spec says we should do both at the same time, but Ricoh -controllers do not like that. */ the latter should be wrong.
-> Adrian-Takahiro Akashi
Quoted 88 lines
Quoted 4 lines
drivers/mmc/host/sdhci.c +0
-0host->pending_reset = false; }drivers/mmc/host/sdhci.c static irqreturn_t sdhci_irq(int irq, void *dev_id) · line 3629
Quoted 10 lines
drivers/mmc/host/sdhci.c +7
-0@@ -3532,6 +3620,13 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id) SDHCI_INT_BUS_POWER);sdhci_writel (host, mask,SDHCI_INT_STATUS ); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + intmask &SDHCI_INT_ERROR && + host->mmc->flags &MMC_UHS2_SUPPORT ) { +if (sdhci_uhs2_ops.irq) + sdhci_uhs2_ops.irq (host); + } +Please look at using the existing ->irq() sdhci host op instead
Quoted 5 lines
drivers/mmc/host/sdhci.c +0
-0if (intmask & (SDHCI_INT_CARD_INSERT |SDHCI_INT_CARD_REMOVE )) {u32 present =sdhci_readl (host,SDHCI_PRESENT_STATE ) &SDHCI_CARD_PRESENT ;@@ -4717,6 +4812,14 @@ int sdhci_setup_host(struct sdhci_host *host)/* This may alter mmc->*_blk_* parameters */ drivers/mmc/host/sdhci.c int sdhci_setup_host(struct sdhci_host *host) · line 4822
Quoted 10 lines
drivers/mmc/host/sdhci.c +8
-0sdhci_allocate_bounce_buffer (host); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->version >=SDHCI_SPEC_400 && + sdhci_uhs2_ops.add_host) { + ret = sdhci_uhs2_ops.add_host (host, host->caps1); +if (ret) + goto unreg; + } +I think you should look at creating
uhs2_add_host()insteadQuoted 38 lines
drivers/mmc/host/sdhci.c +13
-0return 0 ; unreg:@@ -4738,6 +4841,8 @@ void sdhci_cleanup_host(struct sdhci_host *host) {struct mmc_host *mmc = host->mmc; +/* FIXME: Do we have to do some cleanup for UHS2 here? */ +if (!IS_ERR (mmc->supply.vqmmc))regulator_disable (mmc->supply.vqmmc);@@ -4766,6 +4871,14 @@ int __sdhci_add_host(struct sdhci_host *host) mmc->cqe_ops =NULL ; } +if ((mmc->caps &MMC_CAP_UHS2 ) && !host->v4_mode) { +/* host doesn't want to enable UHS2 support */ + mmc->caps &= ~MMC_CAP_UHS2 ; + mmc->flags &= ~MMC_UHS2_SUPPORT ; + +/* FIXME: Do we have to do some cleanup here? */ + } + host->complete_wq =alloc_workqueue ("sdhci" , flags,0 );if (!host->complete_wq)return -ENOMEM ;@@ -4812,6 +4925,9 @@ int __sdhci_add_host(struct sdhci_host *host) unled:sdhci_led_unregister (host); unirq: +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + sdhci_uhs2_ops.remove_host) + sdhci_uhs2_ops.remove_host (host,0 );sdhci_do_reset (host,SDHCI_RESET_ALL );sdhci_writel (host,0 ,SDHCI_INT_ENABLE );sdhci_writel (host,0 ,SDHCI_SIGNAL_ENABLE );drivers/mmc/host/sdhci.c void sdhci_remove_host(struct sdhci_host *host, int dead) · line 4991
Quoted 7 lines
drivers/mmc/host/sdhci.c +4
-0@@ -4869,6 +4985,10 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)sdhci_led_unregister (host); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + sdhci_uhs2_ops.remove_host) + sdhci_uhs2_ops.remove_host (host, dead); +I think you should look at creating
uhs2_remove_host()insteadQuoted 4 lines
drivers/mmc/host/sdhci.c +0
-0if (!dead)sdhci_do_reset (host,SDHCI_RESET_ALL );
Takahiro,
Quoted 107 lines · AKASHI Takahiro
Ben,
Quoted 103 lines · Ben Chuang
Quoted 101 lines · AKASHI Takahiro
Ben,
Quoted 86 lines · Ben Chuang
Hi Takahiro,
Quoted 82 lines · AKASHI Takahiro
Adrian, Ben,
Regarding
_reset()function,Quoted 16 lines · Adrian Hunter
Quoted 15 lines · Ben Chuang
From: Ben Chuang <[email protected]>
In this commit, UHS-II related operations will be called via a function pointer array,
sdhci_uhs2_ops, in order to make UHS-II support as a kernel module.
This array will be initialized only ifCONFIG_MMC_SDHCI_UHS2is enabled and when the UHS-II module is loaded. Otherwise, all the functions stay void.Signed-off-by Ben Chuang <[email protected]>Signed-off-by AKASHI Takahiro <[email protected]>--- drivers/mmc/host/sdhci.c | 152 ++++++++++++++++++++++++++++++++++----- 1 file changed, 136 insertions(+), 16 deletions(-)(snip)
Quoted 28 lines
Quoted 28 lines
if (host->ops->platform_send_init_74_clocks) host->ops->platform_send_init_74_clocks(host, ios->power_mode);(quoted diff) +8
-6@@ -2331,7 +2411,7 @@ void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) } if (host->version >= SDHCI_SPEC_300) { - u16 clk, ctrl_2; + u16 clk; if (!host->preset_enabled) { sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);@@ -3173,11 +3253,19 @@ static bool sdhci_request_done(struct sdhci_host *host) /* This is to force an update */ host->ops->set_clock(host, host->clock); - /* Spec says we should do both at the same time, but Ricoh - controllers do not like that. */ - sdhci_do_reset(host, SDHCI_RESET_CMD); - sdhci_do_reset(host, SDHCI_RESET_DATA); - + if (IS_ENABLED(CONFIG_MMC_SDHCI_UHS2) && + host->mmc->flags & MMC_UHS2_INITIALIZED) { + if (sdhci_uhs2_ops.reset) + sdhci_uhs2_ops.reset(host, + SDHCI_UHS2_SW_RESET_SD); + } else { + /*Quoted 8 lines
Review static bool sdhci_request_done(struct sdhci_host *host) · line 3268
Quoted 6 lines
(quoted diff) +6
-0+ * Spec says we should do both at the same time, but + * Ricoh controllers do not like that. + */ + sdhci_do_reset(host, SDHCI_RESET_CMD); + sdhci_do_reset(host, SDHCI_RESET_DATA); + }Please look at using the existing ->reset() sdhci host op instead.
Well, the second argument to those reset functions is a bit-wise value to different "reset" registers,
SDHCI_SOFTWARE_RESETandSDHCI_UHS2_SW_RESET, respectively.This fact raises a couple of questions to me:
1) Does it make sense to merge two functionality into one, i.e.
sdhci_do_reset(), which is set to call ->reset hook?-> Adrian2)
UHS2_SW_RESET_SDis done only at this place while there are many callsites ofreset(RESET_CMD|RESET_DATA)insdhci.c.
Why does the current code work?I found, in sdhci-pci-gli.c, sdhci_gl9755_reset() /* reset sd-tran on UHS2 mode if need to reset cmd/data */ if ((mask & SDHCI_RESET_CMD) | (mask & SDHCI_RESET_DATA)) gl9755_uhs2_reset_sd_tran(host);(A)
Quoted 7 lines
Quoted 5 lines
Is this the trick to avoid the issue?
(It looks redundant in terms of the hack above insdhci_request_done()and even quite dirty to me. Moreover, no corresponding code for gl9750 and gl9763.)GL9755 currently does SD reset and UHS-II reset together.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Do you mean that, in UHS-II operations, you need only the reset on
SDHCI_UHS2_SW_RESETregister?No, GL9755 does SD reset and UHS-II reset together.
Is this also true for all sdhci controller drivers in general? As I said, I didn't find any precise description about this in SD specification.
No, sdhci_gl9755_reset() is only for GL9755.
Quoted 140 lines
-Takahiro Akashi
Quoted 137 lines
Quoted 13 lines
But the hunk above (A) does the UHS-II reset along with UHS-I reset.
Quoted 11 lines
There is no UHS-II interface on gl9750 and gl9763e.
Quoted 8 lines
-> Ben3) (More or less SD specification issue)
In UHS-II mode, do we have to callreset(SHCI_RESET_ALL)along withreset(UHS2_SW_RESET_FULL)?
Under the current implementation, both will be called at the end.Quoted 8 lines
Quoted 3 lines
As I know, the
UHS2_SW_RESET_FULLis only for UHS-II. Can you list the lines thatreset(SHCI_RESET_ALL)andreset(UHS2_SW_RESET_FULL)are both called?I was not clear here. (The above is also another example.)
Look at
sdhci_remove_host()andshdci_uhs2_remote_host(). If the argument 'dead' is 0, we will do both of the resets for UHS-II.Do
UHS2_SW_RESET_FULLinsdhci_uhs2_remove_host()and then doSDHCI_RESET_ALLinsdhci_remove_host()is ok.Quoted 111 lines
-Takahiro Akashi
Quoted 108 lines
Quoted 108 lines
-> Adrian, Ben4) (Not directly linked to UHS-II support)
In some places, we see the sequence:sdhci_do_reset(host, SDHCI_RESET_CMD); sdhci_do_reset(host, SDHCI_RESET_DATA); while in other places, sdhci_do_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA);If the statement below is true,
Quoted 2 lines
Review static bool sdhci_request_done(struct sdhci_host *host) · line 3182
Quoted 2 lines
(quoted diff) +0
-2- /* Spec says we should do both at the same time, but Ricoh - controllers do not like that. */the latter should be wrong.
-> Adrian-Takahiro Akashi
Quoted 88 lines
Quoted 4 lines
(quoted diff) +0
-0host->pending_reset = false; }Review static irqreturn_t sdhci_irq(int irq, void *dev_id) · line 3629
Quoted 10 lines
(quoted diff) +7
-0@@ -3532,6 +3620,13 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id) SDHCI_INT_BUS_POWER); sdhci_writel(host, mask, SDHCI_INT_STATUS); + if (IS_ENABLED(CONFIG_MMC_SDHCI_UHS2) && + intmask & SDHCI_INT_ERROR && + host->mmc->flags & MMC_UHS2_SUPPORT) { + if (sdhci_uhs2_ops.irq) + sdhci_uhs2_ops.irq(host); + } +Please look at using the existing ->irq() sdhci host op instead
Quoted 5 lines
(quoted diff) +0
-0if (intmask & (SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE)) { u32 present = sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT;@@ -4717,6 +4812,14 @@ int sdhci_setup_host(struct sdhci_host *host) /* This may alter mmc->*_blk_* parameters */Review int sdhci_setup_host(struct sdhci_host *host) · line 4822
Quoted 10 lines
(quoted diff) +8
-0sdhci_allocate_bounce_buffer(host); + if (IS_ENABLED(CONFIG_MMC_SDHCI_UHS2) && + host->version >= SDHCI_SPEC_400 && + sdhci_uhs2_ops.add_host) { + ret = sdhci_uhs2_ops.add_host(host, host->caps1); + if (ret) + goto unreg; + } +I think you should look at creating
uhs2_add_host()insteadQuoted 38 lines
(quoted diff) +13
-0return 0; unreg:@@ -4738,6 +4841,8 @@ void sdhci_cleanup_host(struct sdhci_host *host) { struct mmc_host *mmc = host->mmc; + /* FIXME: Do we have to do some cleanup for UHS2 here? */ + if (!IS_ERR(mmc->supply.vqmmc)) regulator_disable(mmc->supply.vqmmc);@@ -4766,6 +4871,14 @@ int __sdhci_add_host(struct sdhci_host *host) mmc->cqe_ops = NULL; } + if ((mmc->caps & MMC_CAP_UHS2) && !host->v4_mode) { + /* host doesn't want to enable UHS2 support */ + mmc->caps &= ~MMC_CAP_UHS2; + mmc->flags &= ~MMC_UHS2_SUPPORT; + + /* FIXME: Do we have to do some cleanup here? */ + } + host->complete_wq = alloc_workqueue("sdhci", flags, 0); if (!host->complete_wq) return -ENOMEM;@@ -4812,6 +4925,9 @@ int __sdhci_add_host(struct sdhci_host *host) unled: sdhci_led_unregister(host); unirq: + if (IS_ENABLED(CONFIG_MMC_SDHCI_UHS2) && + sdhci_uhs2_ops.remove_host) + sdhci_uhs2_ops.remove_host(host, 0); sdhci_do_reset(host, SDHCI_RESET_ALL); sdhci_writel(host, 0, SDHCI_INT_ENABLE); sdhci_writel(host, 0, SDHCI_SIGNAL_ENABLE);Review void sdhci_remove_host(struct sdhci_host *host, int dead) · line 4991
Quoted 7 lines
(quoted diff) +4
-0@@ -4869,6 +4985,10 @@ void sdhci_remove_host(struct sdhci_host *host, int dead) sdhci_led_unregister(host); + if (IS_ENABLED(CONFIG_MMC_SDHCI_UHS2) && + sdhci_uhs2_ops.remove_host) + sdhci_uhs2_ops.remove_host(host, dead); +I think you should look at creating
uhs2_remove_host()insteadQuoted 4 lines
(quoted diff) +0
-0if (!dead) sdhci_do_reset(host, SDHCI_RESET_ALL);
Adrian, Ben,
Regarding _set_ios() function,
Quoted 12 lines · Adrian Hunter
Quoted 11 lines · Ben Chuang
From: Ben Chuang <[email protected]>
In this commit, UHS-II related operations will be called via a function pointer array,
sdhci_uhs2_ops, in order to make UHS-II support as a kernel module.
This array will be initialized only ifCONFIG_MMC_SDHCI_UHS2is enabled and when the UHS-II module is loaded. Otherwise, all the functions stay void.Signed-off-by Ben Chuang <[email protected]>Signed-off-by AKASHI Takahiro <[email protected]>
(snip)
Quoted 23 lines
Quoted 23 lines
drivers/mmc/host/sdhci.c +5
-0@@ -2261,6 +2324,7 @@ void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) {struct sdhci_host *host =mmc_priv (mmc);u8 ctrl; +u16 ctrl_2;if (ios->power_mode ==MMC_POWER_UNDEFINED )return ;@@ -2287,6 +2351,10 @@ void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)sdhci_enable_preset_value (host, false);if (!ios->clock || ios->clock != host->clock) { +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + ios->timing ==MMC_TIMING_UHS2 ) + host->timing = ios->timing; + host->ops->set_clock (host, ios->clock); host->clock = ios->clock;@@ -2308,6 +2376,18 @@ void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)else sdhci_set_power (host, ios->power_mode, ios->vdd);
Quoted 14 lines
drivers/mmc/host/sdhci.c void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) · line 2390
Quoted 12 lines
drivers/mmc/host/sdhci.c +12
-0+/* 4.0 host support */ +if (host->version >=SDHCI_SPEC_400 ) { +/* UHS2 Support */ +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->mmc->flags &MMC_UHS2_SUPPORT && + host->mmc->caps &MMC_CAP_UHS2 ) { +if (sdhci_uhs2_ops.do_set_ios) + sdhci_uhs2_ops.do_set_ios (host, ios); +return ; + } + } +Please look at using existing callbacks instead, maybe creating
uhs2_set_ios(),uhs2_set_clock(),uhs2_set_power()
I think that we will create uhs2_set_ios() (and uhs2_set_power() as we discussed on patch#15/21), but not uhs_set_clock().
Since we have a hook only in struct mmc_host_ops, but not in struct sdhci_ops, all the drivers who want to support UHS-II need to set host->mmc_host_ops->set_ios to sdhci_uhs2_set_ios explicitly in their own init (or probe) function.
(Again, sdhci_uhs2_set_ios() seems to be generic though.)
Is this okay for you?
-> Adrian
During refactoring the code, I found that sdhci_set_power() is called twice in sdhci_set_ios():
sdhci_set_ios(host, power_mode, vdd1, -1); in sdhci_set_ios(), and sdhci_set_ios(host, power_mode, vdd1, vdd2) in ush2_do_set_ios()
Can you please confirm that those are redundant?
-> Ben
I also wonder why we need spin locks in uhs2_do_set_ios() while not in sdhci_set_ios().
-> Ben
-Takahiro Akashi
Quoted 69 lines · AKASHI Takahiro
Adrian, Ben,
Regarding
_set_ios()function,Quoted 12 lines · Adrian Hunter
Quoted 11 lines · Ben Chuang
From: Ben Chuang <[email protected]>
In this commit, UHS-II related operations will be called via a function pointer array,
sdhci_uhs2_ops, in order to make UHS-II support as a kernel module.
This array will be initialized only ifCONFIG_MMC_SDHCI_UHS2is enabled and when the UHS-II module is loaded. Otherwise, all the functions stay void.Signed-off-by Ben Chuang <[email protected]>Signed-off-by AKASHI Takahiro <[email protected]>(snip)
Quoted 23 lines
Quoted 23 lines
drivers/mmc/host/sdhci.c +5
-0@@ -2261,6 +2324,7 @@ void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) {struct sdhci_host *host =mmc_priv (mmc);u8 ctrl; +u16 ctrl_2;if (ios->power_mode ==MMC_POWER_UNDEFINED )return ;@@ -2287,6 +2351,10 @@ void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)sdhci_enable_preset_value (host, false);if (!ios->clock || ios->clock != host->clock) { +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + ios->timing ==MMC_TIMING_UHS2 ) + host->timing = ios->timing; + host->ops->set_clock (host, ios->clock); host->clock = ios->clock;@@ -2308,6 +2376,18 @@ void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)else sdhci_set_power (host, ios->power_mode, ios->vdd);Quoted 14 lines
drivers/mmc/host/sdhci.c void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) · line 2390
Quoted 12 lines
drivers/mmc/host/sdhci.c +12
-0+/* 4.0 host support */ +if (host->version >=SDHCI_SPEC_400 ) { +/* UHS2 Support */ +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->mmc->flags &MMC_UHS2_SUPPORT && + host->mmc->caps &MMC_CAP_UHS2 ) { +if (sdhci_uhs2_ops.do_set_ios) + sdhci_uhs2_ops.do_set_ios (host, ios); +return ; + } + } +Please look at using existing callbacks instead, maybe creating
uhs2_set_ios(),uhs2_set_clock(),uhs2_set_power()I think that we will create
uhs2_set_ios()(anduhs2_set_power()as we discussed on patch#15/21), but notuhs_set_clock().Since we have a hook only in struct
mmc_host_ops, but not in structsdhci_ops, all the drivers who want to support UHS-II need to sethost->mmc_host_ops->set_iostosdhci_uhs2_set_iosexplicitly in their own init (or probe) function.
(Again,sdhci_uhs2_set_ios()seems to be generic though.)Is this okay for you?
Quoted 8 lines
-> AdrianDuring refactoring the code, I found that
sdhci_set_power()is called twice insdhci_set_ios():
sdhci_set_ios(host, power_mode, vdd1, -1); insdhci_set_ios(), andsdhci_set_ios(host, power_mode, vdd1, vdd2)inush2_do_set_ios()Can you please confirm that those are redundant?
Yes, uhs2 set power is independent with uhs1. But set uhs2 power process should meet uhs2 spec.
Quoted 4 lines
-> BenI also wonder why we need spin locks in
uhs2_do_set_ios()while not insdhci_set_ios().
You can check if spin locks in uhs2_do_set_ios() is necessary. If set/clear irq can be execute safely without spin locks, you can remove spin locks.
Quoted 4 lines
-> Ben-Takahiro Akashi
Ben,
Quoted 78 lines · Ben Chuang
Quoted 76 lines · AKASHI Takahiro
Adrian, Ben,
Regarding
_set_ios()function,Quoted 12 lines · Adrian Hunter
Quoted 11 lines · Ben Chuang
From: Ben Chuang <[email protected]>
In this commit, UHS-II related operations will be called via a function pointer array,
sdhci_uhs2_ops, in order to make UHS-II support as a kernel module.
This array will be initialized only ifCONFIG_MMC_SDHCI_UHS2is enabled and when the UHS-II module is loaded. Otherwise, all the functions stay void.Signed-off-by Ben Chuang <[email protected]>Signed-off-by AKASHI Takahiro <[email protected]>(snip)
Quoted 23 lines
Quoted 23 lines
drivers/mmc/host/sdhci.c +5
-0@@ -2261,6 +2324,7 @@ void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) {struct sdhci_host *host =mmc_priv (mmc);u8 ctrl; +u16 ctrl_2;if (ios->power_mode ==MMC_POWER_UNDEFINED )return ;@@ -2287,6 +2351,10 @@ void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)sdhci_enable_preset_value (host, false);if (!ios->clock || ios->clock != host->clock) { +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + ios->timing ==MMC_TIMING_UHS2 ) + host->timing = ios->timing; + host->ops->set_clock (host, ios->clock); host->clock = ios->clock;@@ -2308,6 +2376,18 @@ void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)else sdhci_set_power (host, ios->power_mode, ios->vdd);Quoted 14 lines
drivers/mmc/host/sdhci.c void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) · line 2390
Quoted 12 lines
drivers/mmc/host/sdhci.c +12
-0+/* 4.0 host support */ +if (host->version >=SDHCI_SPEC_400 ) { +/* UHS2 Support */ +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->mmc->flags &MMC_UHS2_SUPPORT && + host->mmc->caps &MMC_CAP_UHS2 ) { +if (sdhci_uhs2_ops.do_set_ios) + sdhci_uhs2_ops.do_set_ios (host, ios); +return ; + } + } +Please look at using existing callbacks instead, maybe creating
uhs2_set_ios(),uhs2_set_clock(),uhs2_set_power()I think that we will create
uhs2_set_ios()(anduhs2_set_power()as we discussed on patch#15/21), but notuhs_set_clock().Since we have a hook only in struct
mmc_host_ops, but not in structsdhci_ops, all the drivers who want to support UHS-II need to sethost->mmc_host_ops->set_iostosdhci_uhs2_set_iosexplicitly in their own init (or probe) function.
(Again,sdhci_uhs2_set_ios()seems to be generic though.)Is this okay for you?
-> AdrianDuring refactoring the code, I found that
sdhci_set_power()is called twice insdhci_set_ios():
sdhci_set_ios(host, power_mode, vdd1, -1); insdhci_set_ios(), andsdhci_set_ios(host, power_mode, vdd1, vdd2)inush2_do_set_ios()
Quoted 4 lines
Quoted 1 line
Can you please confirm that those are redundant?
Yes, uhs2 set power is independent with uhs1. But set uhs2 power process should meet uhs2 spec.
Can you elaborate a bit more about the last sentence, please?
What I meant above is that
sdhci_set_ios(host, power_mode, vdd1, vdd2) in ush2_do_set_ios()
this code will 'set_power' both vdd and vdd2 anyway and so
sdhci_set_ios(host, power_mode, vdd1, -1); in sdhci_set_ios(), and
is just redundant.
Quoted 6 lines
Quoted 4 lines
-> BenI also wonder why we need spin locks in
uhs2_do_set_ios()while not insdhci_set_ios().You can check if spin locks in
uhs2_do_set_ios()is necessary.
I'm asking you.
While calling set_ios() doesn't require spin locks, are you aware of any cases where we need spin locks in calling set_ios() for uhs-2? (I mean that callers/contexts are the same either for uhs or uhs-2.)
-Takahiro Akashi
Quoted 7 lines
If set/clear irq can be execute safely without spin locks, you can remove spin locks.
Quoted 4 lines
-> Ben-Takahiro Akashi
Takahiro,
Quoted 87 lines · AKASHI Takahiro
Ben,
Quoted 78 lines · Ben Chuang
Quoted 76 lines · AKASHI Takahiro
Adrian, Ben,
Regarding
_set_ios()function,Quoted 12 lines · Adrian Hunter
Quoted 11 lines · Ben Chuang
From: Ben Chuang <[email protected]>
In this commit, UHS-II related operations will be called via a function pointer array,
sdhci_uhs2_ops, in order to make UHS-II support as a kernel module.
This array will be initialized only ifCONFIG_MMC_SDHCI_UHS2is enabled and when the UHS-II module is loaded. Otherwise, all the functions stay void.Signed-off-by Ben Chuang <[email protected]>Signed-off-by AKASHI Takahiro <[email protected]>(snip)
Quoted 23 lines
Quoted 23 lines
drivers/mmc/host/sdhci.c +5
-0@@ -2261,6 +2324,7 @@ void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) {struct sdhci_host *host =mmc_priv (mmc);u8 ctrl; +u16 ctrl_2;if (ios->power_mode ==MMC_POWER_UNDEFINED )return ;@@ -2287,6 +2351,10 @@ void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)sdhci_enable_preset_value (host, false);if (!ios->clock || ios->clock != host->clock) { +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + ios->timing ==MMC_TIMING_UHS2 ) + host->timing = ios->timing; + host->ops->set_clock (host, ios->clock); host->clock = ios->clock;@@ -2308,6 +2376,18 @@ void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)else sdhci_set_power (host, ios->power_mode, ios->vdd);Quoted 14 lines
drivers/mmc/host/sdhci.c void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) · line 2390
Quoted 12 lines
drivers/mmc/host/sdhci.c +12
-0+/* 4.0 host support */ +if (host->version >=SDHCI_SPEC_400 ) { +/* UHS2 Support */ +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->mmc->flags &MMC_UHS2_SUPPORT && + host->mmc->caps &MMC_CAP_UHS2 ) { +if (sdhci_uhs2_ops.do_set_ios) + sdhci_uhs2_ops.do_set_ios (host, ios); +return ; + } + } +Please look at using existing callbacks instead, maybe creating
uhs2_set_ios(),uhs2_set_clock(),uhs2_set_power()I think that we will create
uhs2_set_ios()(anduhs2_set_power()as we discussed on patch#15/21), but notuhs_set_clock().Since we have a hook only in struct
mmc_host_ops, but not in structsdhci_ops, all the drivers who want to support UHS-II need to sethost->mmc_host_ops->set_iostosdhci_uhs2_set_iosexplicitly in their own init (or probe) function.
(Again,sdhci_uhs2_set_ios()seems to be generic though.)Is this okay for you?
-> AdrianDuring refactoring the code, I found that
sdhci_set_power()is called twice insdhci_set_ios():
sdhci_set_ios(host, power_mode, vdd1, -1); insdhci_set_ios(), andsdhci_set_ios(host, power_mode, vdd1, vdd2)inush2_do_set_ios()Quoted 4 lines
Quoted 1 line
Can you please confirm that those are redundant?
Yes, uhs2 set power is independent with uhs1. But set uhs2 power process should meet uhs2 spec.
Quoted 9 lines
Can you elaborate a bit more about the last sentence, please?
What I meant above is that
sdhci_set_ios(host, power_mode, vdd1, vdd2)inush2_do_set_ios()this code will '
set_power' both vdd and vdd2 anyway and sosdhci_set_ios(host, power_mode, vdd1, -1); in sdhci_set_ios(), andis just redundant.
Yes, for uhs-2 flow, sdhci_set_ios(host, power_mode, vdd1, -1) is redundant.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
-> BenI also wonder why we need spin locks in
uhs2_do_set_ios()while not insdhci_set_ios().
Quoted 7 lines
Quoted 1 line
You can check if spin locks in
uhs2_do_set_ios()is necessary.I'm asking you.
While calling
set_ios()doesn't require spin locks, are you aware of any cases where we need spin locks in callingset_ios()for uhs-2? (I mean that callers/contexts are the same either for uhs or uhs-2.)
I agree that it can be removed. I just didn't modify intel's original codes.
Quoted 10 lines
-Takahiro Akashi
Quoted 7 lines
If set/clear irq can be execute safely without spin locks, you can remove spin locks.
Quoted 4 lines
-> Ben-Takahiro Akashi
Adrian,
This is, hopefully, my last reply to your comments on this patch#12.
Regarding _request() and _send_command() (and more),
Quoted 10 lines · Adrian Hunter
Quoted 9 lines · Ben Chuang
From: Ben Chuang <[email protected]>
In this commit, UHS-II related operations will be called via a function pointer array,
sdhci_uhs2_ops, in order to make UHS-II support as a kernel module.
This array will be initialized only ifCONFIG_MMC_SDHCI_UHS2is enabled and when the UHS-II module is loaded. Otherwise, all the functions stay void.
(snip)
Quoted 49 lines
Again, this is what I want to avoid. I would like to have 3 kinds of functions:
- SD mode only
- UHS-II only
- SD functions with no UHS-II code, that can also be used by UHS-II
i.e. I don't want to mix UHS-II code and SD mode code in the same function.I think
sdhci-uhs2.cshould provide a request function and asend_commandfunction. I would start by removing everything you may not need, and then see if you have any problems. e.g.void
uhs2_request(struct mmc_host *mmc, struct mmc_request *mrq){ struct sdhci_host *host = mmc_priv(mmc); struct mmc_command *cmd; unsigned long flags; if (!host->uhs2_mode) { sdhci_request(mmc, mrq); return; } spin_lock_irqsave(&host->lock, flags); uhs2_send_command(host, cmd); spin_unlock_irqrestore(&host->lock, flags); }
EXPORT_SYMBOL_GPL(uhs2_request);For
sdhci_prepare_data(), I would factor out the dma part, sostatic void
sdhci_prepare_data(struct sdhci_host *host, struct mmc_command *cmd){ struct mmc_data *data = cmd->data; sdhci_initialize_data(host, data); sdhci_prepare_dma(host, data); sdhci_set_block_info(host, data); }The you could export
sdhci_initialize_data()andsdhci_prepare_dma()for uhs2.Quoted 7 lines
}
#if
IS_ENABLED(CONFIG_MMC_SDHCI_EXTERNAL_DMA)drivers/mmc/host/sdhci.c +0
-0@@ -1439,6 +1463,13 @@ static void sdhci_set_transfer_mode(struct sdhci_host *host,u16 mode =0 ;struct mmc_data *data = cmd->data;
Quoted 9 lines
drivers/mmc/host/sdhci.c static void sdhci_set_transfer_mode(struct sdhci_host *host, · line 1472
Quoted 7 lines
drivers/mmc/host/sdhci.c +7
-0+if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->mmc->flags &MMC_UHS2_SUPPORT ) { +if (sdhci_uhs2_ops.set_transfer_mode) + sdhci_uhs2_ops.set_transfer_mode (host, cmd); +return ; + } +Once you provide
uhs2_request()anduhs2_send_command(), the transfer mode setting can be done insdhci-uhs2.c
If I try to make changes as you suggested above, a lot of other uhs2-flavored functions will also be created due to calling dependency/sequences and for "completeness" compared to uhs counterparts.
They probably include
sdhci_uhs2_prepare_data()
sdhci_uhs2_external_dma_prepare_data()
sdhci_uhs2_send_command()
sdhci_uhs2_send_command_try()
sdhci_uhs2_send_tuning()
sdhci_uhs2_request()
sdhci_uhs2_request_atomic()
sdhci_uhs2_thread_irq()
sdhci_uhs2_irq()
sdhci_uhs2_cmd_irq()
sdhci_uhs2_finish_command()
sdhci_uhs2_resume_host()
__sdhci_uhs2_add_host()
sdhci_uhs2_add_host()(Some may not be used under the current drivers.)
In addition, a bunch of functions in sdhci.c will also have to be exported to uhs2 as "global" functions instead of "static."
Is this all that you expect to see?
-Takahiro Akashi
Quoted 294 lines
drivers/mmc/host/sdhci.c static void __sdhci_finish_data(struct sdhci_host *host, bool sw_data_timeout) · line 1608
Quoted 12 lines
drivers/mmc/host/sdhci.c +5
-0if (data ==NULL ) {if (host->quirks2 &SDHCI_QUIRK2_CLEAR_TRANSFERMODE_REG_BEFORE_CMD ) {@@ -1570,6 +1601,12 @@ static void __sdhci_finish_data(struct sdhci_host *host, bool sw_data_timeout)else data->bytes_xfered = data->blksz * data->blocks; +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->mmc->flags &MMC_UHS2_INITIALIZED ) { +__sdhci_finish_mrq (host, data->mrq); +return ; + }At least to start with, I think it would be better to handle UHS-II cmd and data interrupts completely in
sdhci-uhs2.cdrivers/mmc/host/sdhci.c static bool sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd) · line 1695
Quoted 11 lines
drivers/mmc/host/sdhci.c +3
-1+/* * Need to send CMD12 if - * a) open-ended multiblock transfer not using auto CMD12 (no CMD23) @@ -1654,7 +1691,8 @@ static bool sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)sdhci_prepare_data (host, cmd); } -sdhci_writel (host, cmd->arg,SDHCI_ARGUMENT ); +if (!IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 )) +sdhci_writel (host, cmd->arg,SDHCI_ARGUMENT );Not needed when instead you provide
uhs2_send_command()Quoted 7 lines
drivers/mmc/host/sdhci.c +0
-0sdhci_set_transfer_mode (host, cmd);@@ -1699,6 +1737,17 @@ static bool sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)if (host->use_external_dma)sdhci_external_dma_pre_transfer (host, cmd);drivers/mmc/host/sdhci.c static bool sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd) · line 1749
Quoted 10 lines
drivers/mmc/host/sdhci.c +10
-0+if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + (host->mmc->flags &MMC_UHS2_SUPPORT )) { +if (sdhci_uhs2_ops.send_command) + sdhci_uhs2_ops.send_command (host, cmd); + +return true; + } + +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 )) +sdhci_writel (host, cmd->arg,SDHCI_ARGUMENT );Not needed when instead you provide
uhs2_send_command()Quoted 18 lines
drivers/mmc/host/sdhci.c +7
-3+sdhci_writew (host,SDHCI_MAKE_CMD (cmd->opcode, flags),SDHCI_COMMAND );return true;@@ -1780,13 +1829,20 @@ static void sdhci_finish_command(struct sdhci_host *host) {struct mmc_command *cmd = host->cmd; - host->cmd =NULL ; +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->mmc->flags &MMC_UHS2_SUPPORT ) { +if (sdhci_uhs2_ops.finish_command) + sdhci_uhs2_ops.finish_command (host); + }else { + host->cmd =NULL ; -if (cmd->flags &MMC_RSP_PRESENT ) { -if (cmd->flags &MMC_RSP_136 ) {drivers/mmc/host/sdhci.c static void sdhci_finish_command(struct sdhci_host *host) · line 1845
Quoted 10 lines
drivers/mmc/host/sdhci.c +7
-3-sdhci_read_rsp_136 (host, cmd); - }else { - cmd->resp[0 ] =sdhci_readl (host,SDHCI_RESPONSE ); +if (cmd->flags &MMC_RSP_PRESENT ) { +if (cmd->flags &MMC_RSP_136 ) { +sdhci_read_rsp_136 (host, cmd); + }else { + cmd->resp[0 ] =sdhci_readl (host, +SDHCI_RESPONSE ); + }At least to start with, I think it would be better to handle UHS-II cmd and data interrupts completely in
sdhci-uhs2.cdrivers/mmc/host/sdhci.c static void sdhci_finish_command(struct sdhci_host *host) · line 1868
Quoted 8 lines
drivers/mmc/host/sdhci.c +1
-0} }@@ -1809,6 +1865,7 @@ static void sdhci_finish_command(struct sdhci_host *host) }else if (!(host->quirks &SDHCI_QUIRK_NO_BUSY_IRQ ) && cmd == host->data_cmd) {/* Command complete before busy is ended */ + host->cmd =NULL ;
host->cmdis set to NULL at the start of this function, so this is not needed.drivers/mmc/host/sdhci.c static void sdhci_finish_command(struct sdhci_host *host) · line 1889
Quoted 9 lines
drivers/mmc/host/sdhci.c +2
-0return ; } }@@ -1828,6 +1885,8 @@ static void sdhci_finish_command(struct sdhci_host *host)if (!cmd->data)__sdhci_finish_mrq (host, cmd->mrq); } + + host->cmd =NULL ;
host->cmdis set to NULL at the start of this function, so this is not needed.drivers/mmc/host/sdhci.c static u16 sdhci_get_preset_value(struct sdhci_host *host) · line 1917
Quoted 8 lines
drivers/mmc/host/sdhci.c +1
-0}static u16 sdhci_get_preset_value (struct sdhci_host *host)@@ -1855,6 +1914,11 @@ static u16 sdhci_get_preset_value(struct sdhci_host *host)case MMC_TIMING_MMC_HS400 : preset =sdhci_readw (host,SDHCI_PRESET_FOR_HS400 );break ; +#if IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 )Shouldn't need conditional compilation for this
drivers/mmc/host/sdhci.c void sdhci_set_power_noreg(struct sdhci_host *host, unsigned char mode, · line 2098
Quoted 12 lines
drivers/mmc/host/sdhci.c +4
-1+case MMC_TIMING_UHS2 : + preset =sdhci_readw (host,SDHCI_PRESET_FOR_UHS2 ); +break ; +#endif default :pr_warn ("%s: Invalid UHS-I mode selected\n" ,mmc_hostname (host->mmc));@@ -2095,7 +2159,6 @@ void sdhci_set_power_noreg(struct sdhci_host *host, unsigned char mode,sdhci_writeb (host, pwr,SDHCI_POWER_CONTROL ); pwr |=SDHCI_POWER_ON ; -No white space changes mixed in please
Quoted 28 lines
drivers/mmc/host/sdhci.c +7
-0sdhci_writeb (host, pwr,SDHCI_POWER_CONTROL );if (host->quirks2 &SDHCI_QUIRK2_CARD_ON_NEEDS_BUS_ON )@@ -2261,6 +2324,7 @@ void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) {struct sdhci_host *host =mmc_priv (mmc);u8 ctrl; +u16 ctrl_2;if (ios->power_mode ==MMC_POWER_UNDEFINED )return ;@@ -2287,6 +2351,10 @@ void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)sdhci_enable_preset_value (host, false);if (!ios->clock || ios->clock != host->clock) { +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + ios->timing ==MMC_TIMING_UHS2 ) + host->timing = ios->timing; + host->ops->set_clock (host, ios->clock); host->clock = ios->clock;@@ -2308,6 +2376,18 @@ void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)else sdhci_set_power (host, ios->power_mode, ios->vdd); +/* 4.0 host support */ +if (host->version >=SDHCI_SPEC_400 ) {drivers/mmc/host/sdhci.c void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) · line 2390
Quoted 10 lines
drivers/mmc/host/sdhci.c +10
-0+/* UHS2 Support */ +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->mmc->flags &MMC_UHS2_SUPPORT && + host->mmc->caps &MMC_CAP_UHS2 ) { +if (sdhci_uhs2_ops.do_set_ios) + sdhci_uhs2_ops.do_set_ios (host, ios); +return ; + } + } +Please look at using existing callbacks instead, maybe creating
uhs2_set_ios(),uhs2_set_clock(),uhs2_set_power()Quoted 24 lines
drivers/mmc/host/sdhci.c +4
-6if (host->ops->platform_send_init_74_clocks) host->ops->platform_send_init_74_clocks (host, ios->power_mode);@@ -2331,7 +2411,7 @@ void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) }if (host->version >=SDHCI_SPEC_300 ) { -u16 clk, ctrl_2; +u16 clk;if (!host->preset_enabled) {sdhci_writeb (host, ctrl,SDHCI_HOST_CONTROL );@@ -3173,11 +3253,19 @@ static bool sdhci_request_done(struct sdhci_host *host)/* This is to force an update */ host->ops->set_clock (host, host->clock); -/* Spec says we should do both at the same time, but Ricoh -controllers do not like that. */ -sdhci_do_reset (host,SDHCI_RESET_CMD ); -sdhci_do_reset (host,SDHCI_RESET_DATA ); - +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->mmc->flags &MMC_UHS2_INITIALIZED ) { +if (sdhci_uhs2_ops.reset)drivers/mmc/host/sdhci.c static bool sdhci_request_done(struct sdhci_host *host) · line 3268
Quoted 10 lines
drivers/mmc/host/sdhci.c +10
-0+ sdhci_uhs2_ops.reset (host, +SDHCI_UHS2_SW_RESET_SD ); + }else { +/* +* Spec says we should do both at the same time, but +* Ricoh controllers do not like that. +*/ +sdhci_do_reset (host,SDHCI_RESET_CMD ); +sdhci_do_reset (host,SDHCI_RESET_DATA ); + }Please look at using the existing ->reset() sdhci host op instead.
Quoted 4 lines
drivers/mmc/host/sdhci.c +0
-0host->pending_reset = false; }drivers/mmc/host/sdhci.c static irqreturn_t sdhci_irq(int irq, void *dev_id) · line 3629
Quoted 10 lines
drivers/mmc/host/sdhci.c +7
-0@@ -3532,6 +3620,13 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id) SDHCI_INT_BUS_POWER);sdhci_writel (host, mask,SDHCI_INT_STATUS ); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + intmask &SDHCI_INT_ERROR && + host->mmc->flags &MMC_UHS2_SUPPORT ) { +if (sdhci_uhs2_ops.irq) + sdhci_uhs2_ops.irq (host); + } +Please look at using the existing ->irq() sdhci host op instead
Quoted 5 lines
drivers/mmc/host/sdhci.c +0
-0if (intmask & (SDHCI_INT_CARD_INSERT |SDHCI_INT_CARD_REMOVE )) {u32 present =sdhci_readl (host,SDHCI_PRESENT_STATE ) &SDHCI_CARD_PRESENT ;@@ -4717,6 +4812,14 @@ int sdhci_setup_host(struct sdhci_host *host)/* This may alter mmc->*_blk_* parameters */ drivers/mmc/host/sdhci.c int sdhci_setup_host(struct sdhci_host *host) · line 4822
Quoted 10 lines
drivers/mmc/host/sdhci.c +8
-0sdhci_allocate_bounce_buffer (host); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->version >=SDHCI_SPEC_400 && + sdhci_uhs2_ops.add_host) { + ret = sdhci_uhs2_ops.add_host (host, host->caps1); +if (ret) + goto unreg; + } +I think you should look at creating
uhs2_add_host()insteadQuoted 38 lines
drivers/mmc/host/sdhci.c +13
-0return 0 ; unreg:@@ -4738,6 +4841,8 @@ void sdhci_cleanup_host(struct sdhci_host *host) {struct mmc_host *mmc = host->mmc; +/* FIXME: Do we have to do some cleanup for UHS2 here? */ +if (!IS_ERR (mmc->supply.vqmmc))regulator_disable (mmc->supply.vqmmc);@@ -4766,6 +4871,14 @@ int __sdhci_add_host(struct sdhci_host *host) mmc->cqe_ops =NULL ; } +if ((mmc->caps &MMC_CAP_UHS2 ) && !host->v4_mode) { +/* host doesn't want to enable UHS2 support */ + mmc->caps &= ~MMC_CAP_UHS2 ; + mmc->flags &= ~MMC_UHS2_SUPPORT ; + +/* FIXME: Do we have to do some cleanup here? */ + } + host->complete_wq =alloc_workqueue ("sdhci" , flags,0 );if (!host->complete_wq)return -ENOMEM ;@@ -4812,6 +4925,9 @@ int __sdhci_add_host(struct sdhci_host *host) unled:sdhci_led_unregister (host); unirq: +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + sdhci_uhs2_ops.remove_host) + sdhci_uhs2_ops.remove_host (host,0 );sdhci_do_reset (host,SDHCI_RESET_ALL );sdhci_writel (host,0 ,SDHCI_INT_ENABLE );sdhci_writel (host,0 ,SDHCI_SIGNAL_ENABLE );drivers/mmc/host/sdhci.c void sdhci_remove_host(struct sdhci_host *host, int dead) · line 4991
Quoted 7 lines
drivers/mmc/host/sdhci.c +4
-0@@ -4869,6 +4985,10 @@ void sdhci_remove_host(struct sdhci_host *host, int dead)sdhci_led_unregister (host); +if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + sdhci_uhs2_ops.remove_host) + sdhci_uhs2_ops.remove_host (host, dead); +I think you should look at creating
uhs2_remove_host()insteadQuoted 4 lines
drivers/mmc/host/sdhci.c +0
-0if (!dead)sdhci_do_reset (host,SDHCI_RESET_ALL );
Adrian Hunter
maintainerQuoted 96 lines · AKASHI Takahiro
Adrian,
This is, hopefully, my last reply to your comments on this patch#12.
Regarding
_request()and_send_command()(and more),Quoted 10 lines · Adrian Hunter
Quoted 9 lines · Ben Chuang
From: Ben Chuang <[email protected]>
In this commit, UHS-II related operations will be called via a function pointer array,
sdhci_uhs2_ops, in order to make UHS-II support as a kernel module.
This array will be initialized only ifCONFIG_MMC_SDHCI_UHS2is enabled and when the UHS-II module is loaded. Otherwise, all the functions stay void.(snip)
Quoted 49 lines
Again, this is what I want to avoid. I would like to have 3 kinds of functions:
- SD mode only
- UHS-II only
- SD functions with no UHS-II code, that can also be used by UHS-II
i.e. I don't want to mix UHS-II code and SD mode code in the same function.I think
sdhci-uhs2.cshould provide a request function and asend_commandfunction. I would start by removing everything you may not need, and then see if you have any problems. e.g.void
uhs2_request(struct mmc_host *mmc, struct mmc_request *mrq){ struct sdhci_host *host = mmc_priv(mmc); struct mmc_command *cmd; unsigned long flags; if (!host->uhs2_mode) { sdhci_request(mmc, mrq); return; } spin_lock_irqsave(&host->lock, flags); uhs2_send_command(host, cmd); spin_unlock_irqrestore(&host->lock, flags); }
EXPORT_SYMBOL_GPL(uhs2_request);For
sdhci_prepare_data(), I would factor out the dma part, sostatic void
sdhci_prepare_data(struct sdhci_host *host, struct mmc_command *cmd){ struct mmc_data *data = cmd->data; sdhci_initialize_data(host, data); sdhci_prepare_dma(host, data); sdhci_set_block_info(host, data); }The you could export
sdhci_initialize_data()andsdhci_prepare_dma()for uhs2.Quoted 7 lines
}
#if
IS_ENABLED(CONFIG_MMC_SDHCI_EXTERNAL_DMA)drivers/mmc/host/sdhci.c +0
-0@@ -1439,6 +1463,13 @@ static void sdhci_set_transfer_mode(struct sdhci_host *host,u16 mode =0 ;struct mmc_data *data = cmd->data;Quoted 9 lines
drivers/mmc/host/sdhci.c static void sdhci_set_transfer_mode(struct sdhci_host *host, · line 1472
Quoted 7 lines
drivers/mmc/host/sdhci.c +7
-0+if (IS_ENABLED (CONFIG_MMC_SDHCI_UHS2 ) && + host->mmc->flags &MMC_UHS2_SUPPORT ) { +if (sdhci_uhs2_ops.set_transfer_mode) + sdhci_uhs2_ops.set_transfer_mode (host, cmd); +return ; + } +Once you provide
uhs2_request()anduhs2_send_command(), the transfer mode setting can be done insdhci-uhs2.cIf I try to make changes as you suggested above, a lot of other uhs2-flavored functions will also be created due to calling dependency/sequences and for "completeness" compared to uhs counterparts.
They probably includesdhci_uhs2_prepare_data() sdhci_uhs2_external_dma_prepare_data() sdhci_uhs2_send_command() sdhci_uhs2_send_command_try() sdhci_uhs2_send_tuning() sdhci_uhs2_request() sdhci_uhs2_request_atomic() sdhci_uhs2_thread_irq() sdhci_uhs2_irq() sdhci_uhs2_cmd_irq() sdhci_uhs2_finish_command() sdhci_uhs2_resume_host() __sdhci_uhs2_add_host() sdhci_uhs2_add_host()
Quoted 6 lines
(Some may not be used under the current drivers.)
In addition, a bunch of functions in
sdhci.cwill also have to be exported to uhs2 as "global" functions instead of "static."Is this all that you expect to see?
Yes. Add what you need.