[PATCH 1/2] mmc: dw_mmc: extract ctrl_id lookup to a function

From: John Keeping
Date: Tue Nov 16 2021 - 14:02:58 EST


An upcoming commit will change the logic to use the standard "mmc" stem
for looking up the alias, while keeping the nonstandard "mshc" stem for
backwards compatibility. In preparation for this, extract a common
function to replace the two places that currently replicate this lookup.

There is no functional change intended here.

Signed-off-by: John Keeping <john@xxxxxxxxxxxx>
---
drivers/mmc/host/dw_mmc-k3.c | 4 +---
drivers/mmc/host/dw_mmc.c | 24 ++++++++++++++++++------
drivers/mmc/host/dw_mmc.h | 2 ++
3 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/drivers/mmc/host/dw_mmc-k3.c b/drivers/mmc/host/dw_mmc-k3.c
index 0311a37dd4ab..0d82e6f54cca 100644
--- a/drivers/mmc/host/dw_mmc-k3.c
+++ b/drivers/mmc/host/dw_mmc-k3.c
@@ -127,9 +127,7 @@ static int dw_mci_hi6220_parse_dt(struct dw_mci *host)
if (IS_ERR(priv->reg))
priv->reg = NULL;

- priv->ctrl_id = of_alias_get_id(host->dev->of_node, "mshc");
- if (priv->ctrl_id < 0)
- priv->ctrl_id = 0;
+ priv->ctrl_id = dw_mci_of_alias_get_id(host);

if (priv->ctrl_id >= TIMING_MODE)
return -EINVAL;
diff --git a/drivers/mmc/host/dw_mmc.c b/drivers/mmc/host/dw_mmc.c
index 1bedef827138..37af1245304b 100644
--- a/drivers/mmc/host/dw_mmc.c
+++ b/drivers/mmc/host/dw_mmc.c
@@ -105,6 +105,21 @@ struct idmac_desc {
/* Each descriptor can transfer up to 4KB of data in chained mode */
#define DW_MCI_DESC_DATA_LENGTH 0x1000

+int dw_mci_of_alias_get_id(struct dw_mci *host)
+{
+ int ctrl_id;
+
+ if (WARN_ON(!host->dev->of_node))
+ return 0;
+
+ ctrl_id = of_alias_get_id(host->dev->of_node, "mshc");
+
+ if (ctrl_id < 0)
+ ctrl_id = 0;
+
+ return ctrl_id;
+}
+
#if defined(CONFIG_DEBUG_FS)
static int dw_mci_req_show(struct seq_file *s, void *v)
{
@@ -2855,13 +2870,10 @@ static int dw_mci_init_slot_caps(struct dw_mci_slot *slot)
if (host->pdata->pm_caps)
mmc->pm_caps = host->pdata->pm_caps;

- if (host->dev->of_node) {
- ctrl_id = of_alias_get_id(host->dev->of_node, "mshc");
- if (ctrl_id < 0)
- ctrl_id = 0;
- } else {
+ if (host->dev->of_node)
+ ctrl_id = dw_mci_of_alias_get_id(host);
+ else
ctrl_id = to_platform_device(host->dev)->id;
- }

if (drv_data && drv_data->caps) {
if (ctrl_id >= drv_data->num_caps) {
diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
index ce05d81477d9..9e643d7fe90b 100644
--- a/drivers/mmc/host/dw_mmc.h
+++ b/drivers/mmc/host/dw_mmc.h
@@ -508,6 +508,8 @@ extern int dw_mci_runtime_suspend(struct device *device);
extern int dw_mci_runtime_resume(struct device *device);
#endif

+extern int dw_mci_of_alias_get_id(struct dw_mci *host);
+
/**
* struct dw_mci_slot - MMC slot state
* @mmc: The mmc_host representing this slot.
--
2.34.0