mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Jonas Richardsen <jonasrichardsen@emlix.com>,
	Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master 2/3] mci: sdhci: retrieve host device via common helper or NULL
Date: Wed, 22 May 2024 10:07:33 +0200	[thread overview]
Message-ID: <20240522080734.1965257-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20240522080734.1965257-1-a.fatoum@pengutronix.de>

Since commit d20abb491654 ("common: console_common: handle NULL dev
gracefully in dev_printf"), it's permissible to pass NULL to the
dev_printf family of functions. Therefore define sdhci_dev, which either
return a device if mci was set or NULL otherwise.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/mci/sdhci.c | 27 ++++++++++++++++-----------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/drivers/mci/sdhci.c b/drivers/mci/sdhci.c
index da6c2ddb5879..2e8f99fc462c 100644
--- a/drivers/mci/sdhci.c
+++ b/drivers/mci/sdhci.c
@@ -21,6 +21,11 @@ enum sdhci_reset_reason {
 	SDHCI_RESET_FOR_CQE_RECOVERY,
 };
 
+static inline struct device *sdhci_dev(struct sdhci *host)
+{
+	return host->mci ? host->mci->hw_dev : NULL;
+}
+
 static void sdhci_reset_for_reason(struct sdhci *host, enum sdhci_reset_reason reason)
 {
 	if (host->quirks2 & SDHCI_QUIRK2_ISSUE_CMD_DAT_RESET_TOGETHER) {
@@ -170,7 +175,7 @@ static int __sdhci_execute_tuning(struct sdhci *host, u32 opcode)
 
 	}
 
-	dev_dbg(host->mci->hw_dev, "Tuning timeout, falling back to fixed sampling clock\n");
+	dev_dbg(sdhci_dev(host), "Tuning timeout, falling back to fixed sampling clock\n");
 	sdhci_reset_tuning(host);
 	return -EAGAIN;
 }
@@ -416,13 +421,13 @@ int sdhci_wait_for_done(struct sdhci *sdhci, u32 mask)
 			return -ETIMEDOUT;
 
 		if (stat & SDHCI_INT_ERROR) {
-			dev_err(sdhci->mci->hw_dev, "SDHCI_INT_ERROR: 0x%08x\n",
+			dev_err(sdhci_dev(sdhci), "SDHCI_INT_ERROR: 0x%08x\n",
 				stat);
 			return -EPERM;
 		}
 
 		if (is_timeout(start, 1000 * MSECOND)) {
-			dev_err(sdhci->mci->hw_dev,
+			dev_err(sdhci_dev(sdhci),
 				"SDHCI timeout while waiting for done\n");
 			return -ETIMEDOUT;
 		}
@@ -470,7 +475,7 @@ static void sdhci_config_dma(struct sdhci *host)
 void sdhci_setup_data_dma(struct sdhci *sdhci, struct mci_data *data,
 			  dma_addr_t *dma)
 {
-	struct device *dev = sdhci->mci->hw_dev;
+	struct device *dev = sdhci_dev(sdhci);
 	int nbytes;
 
 	if (!data)
@@ -502,7 +507,7 @@ void sdhci_setup_data_dma(struct sdhci *sdhci, struct mci_data *data,
 int sdhci_transfer_data_dma(struct sdhci *sdhci, struct mci_data *data,
 			    dma_addr_t dma)
 {
-	struct device *dev = sdhci->mci->hw_dev;
+	struct device *dev = sdhci_dev(sdhci);
 	u64 start;
 	int nbytes;
 	u32 irqstat;
@@ -615,7 +620,7 @@ int sdhci_transfer_data_pio(struct sdhci *sdhci, struct mci_data *data)
 
 int sdhci_transfer_data(struct sdhci *sdhci, struct mci_data *data, dma_addr_t dma)
 {
-	struct device *dev = sdhci->mci->hw_dev;
+	struct device *dev = sdhci_dev(sdhci);
 
 	if (!data)
 		return 0;
@@ -665,7 +670,7 @@ static u16 sdhci_get_preset_value(struct sdhci *host)
 		preset = sdhci_read16(host, SDHCI_PRESET_FOR_HS400);
 		break;
 	default:
-		dev_warn(host->mci->hw_dev, "Invalid UHS-I mode selected\n");
+		dev_warn(sdhci_dev(host), "Invalid UHS-I mode selected\n");
 		preset = sdhci_read16(host, SDHCI_PRESET_FOR_SDR12);
 		break;
 	}
@@ -778,7 +783,7 @@ void sdhci_enable_clk(struct sdhci *host, u16 clk)
 	while (!(sdhci_read16(host, SDHCI_CLOCK_CONTROL) &
 		SDHCI_CLOCK_INT_STABLE)) {
 		if (is_timeout(start, 150 * MSECOND)) {
-			dev_err(host->mci->hw_dev,
+			dev_err(sdhci_dev(host),
 					"SDHCI clock stable timeout\n");
 			return;
 		}
@@ -805,7 +810,7 @@ int sdhci_wait_idle(struct sdhci *host, struct mci_cmd *cmd, struct mci_data *da
 			!(sdhci_read32(host, SDHCI_PRESENT_STATE) & mask));
 
 	if (ret) {
-		dev_err(host->mci->hw_dev,
+		dev_err(sdhci_dev(host),
 				"SDHCI timeout while waiting for idle\n");
 		return -EBUSY;
 	}
@@ -827,7 +832,7 @@ int sdhci_wait_idle_data(struct sdhci *host, struct mci_cmd *cmd)
 			!(sdhci_read32(host, SDHCI_PRESENT_STATE) & mask));
 
 	if (ret) {
-		dev_err(host->mci->hw_dev,
+		dev_err(sdhci_dev(host),
 				"SDHCI timeout while waiting for idle\n");
 		return -EBUSY;
 	}
@@ -880,7 +885,7 @@ void __sdhci_read_caps(struct sdhci *host, const u16 *ver,
 	u16 v;
 	u64 dt_caps_mask = 0;
 	u64 dt_caps = 0;
-	struct device_node *np = host->mci->hw_dev->of_node;
+	struct device_node *np = dev_of_node(sdhci_dev(host));
 
 	BUG_ON(!host->mci); /* Call sdhci_setup_host() before using this */
 
-- 
2.39.2




  reply	other threads:[~2024-05-22  8:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-22  8:07 [PATCH master 1/3] mci: sdhci: use host device, not card, for debug message Ahmad Fatoum
2024-05-22  8:07 ` Ahmad Fatoum [this message]
2024-05-22  8:07 ` [PATCH master 3/3] mci: sdhci: populate struct sdhci::mci in drivers Ahmad Fatoum
2024-05-24 11:43 ` [PATCH master 1/3] mci: sdhci: use host device, not card, for debug message Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240522080734.1965257-2-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=jonasrichardsen@emlix.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox