Skip to contentSkip to conversation

mmc: meson-gx: add SDIO interrupt support

PATCH In review Heiner Kallweit 3 participants 9 messages Aug 25, 2022 – Aug 29, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v3 cover mmc: meson-gx: add SDIO interrupt support

Add SDIO interrupt support. Successfully tested on a S905X4-based system (V3 register layout) with a BRCM4334 SDIO wifi module (brcmfmac driver).

v2:
- use new SDIO interrupt API
v3:
- don't duplicate checking mmc->sdio_irq_pending

Heiner Kallweit (2):
mmc: meson: adjust and re-use constant IRQ_EN_MASK
mmc: meson-gx: add SDIO interrupt support

 drivers/mmc/host/meson-gx-mmc.c | 84 +++++++++++++++++++++++++--------
 1 file changed, 65 insertions(+), 19 deletions(-)
Signature · 1 line
2.37.2
#1 lore raw

PATCH v3 1/2 mmc: meson: adjust and re-use constant IRQ_EN_MASK

Constant IRQ_EN_MASK has no user currently. In preparation of adding SDIO interrupt support, revive it and adjust it to our needs.

---
v2:
- patch added to series

---
 drivers/mmc/host/meson-gx-mmc.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)
drivers/mmc/host/meson-gx-mmc.c +7 -11
index dbc9fac8f..9a4da2544 100644
@@ -101,8 +101,7 @@
 #define   IRQ_RESP_STATUS BIT(14)
 #define   IRQ_SDIO BIT(15)
 #define   IRQ_EN_MASK \
-	(IRQ_CRC_ERR | IRQ_TIMEOUTS | IRQ_END_OF_CHAIN | IRQ_RESP_STATUS |\
-	 IRQ_SDIO)
+	(IRQ_CRC_ERR | IRQ_TIMEOUTS | IRQ_END_OF_CHAIN)
 
 #define SD_EMMC_CMD_CFG 0x50
 #define SD_EMMC_CMD_ARG 0x54
@@ -940,17 +939,16 @@ static irqreturn_t meson_mmc_irq(int irq, void *dev_id)
 	struct meson_host *host = dev_id;
 	struct mmc_command *cmd;
 	struct mmc_data *data;
-	u32 irq_en, status, raw_status;
+	u32 status, raw_status;
 	irqreturn_t ret = IRQ_NONE;
 
-	irq_en = readl(host->regs + SD_EMMC_IRQ_EN);
 	raw_status = readl(host->regs + SD_EMMC_STATUS);
-	status = raw_status & irq_en;
+	status = raw_status & IRQ_EN_MASK;
 
 	if (!status) {
 		dev_dbg(host->dev,
-			"Unexpected IRQ! irq_en 0x%08x - status 0x%08x\n",
-			 irq_en, raw_status);
+			"Unexpected IRQ! irq_en 0x%08lx - status 0x%08x\n",
+			 IRQ_EN_MASK, raw_status);
 		return IRQ_NONE;
 	}
 
@@ -1230,10 +1228,8 @@ static int meson_mmc_probe(struct platform_device *pdev)
 
 	/* clear, ack and enable interrupts */
 	writel(0, host->regs + SD_EMMC_IRQ_EN);
-	writel(IRQ_CRC_ERR | IRQ_TIMEOUTS | IRQ_END_OF_CHAIN,
-	       host->regs + SD_EMMC_STATUS);
-	writel(IRQ_CRC_ERR | IRQ_TIMEOUTS | IRQ_END_OF_CHAIN,
-	       host->regs + SD_EMMC_IRQ_EN);
+	writel(IRQ_EN_MASK, host->regs + SD_EMMC_STATUS);
+	writel(IRQ_EN_MASK, host->regs + SD_EMMC_IRQ_EN);
 
 	ret = request_threaded_irq(host->irq, meson_mmc_irq,
 				   meson_mmc_irq_thread, IRQF_ONESHOT,
Signature · 1 line
2.37.2
#2 lore raw

PATCH v3 2/2 mmc: meson-gx: add SDIO interrupt support

In reply to Heiner Kallweit

Add SDIO interrupt support. Successfully tested on a S905X4-based system (V3 register layout) with a BRCM4334 SDIO wifi module (brcmfmac driver).

---
v2:
- use new SDIO IRQ API
v3:
- don't duplicate checking mmc->sdio_irq_pending
Device works fine w/o it.

---
 drivers/mmc/host/meson-gx-mmc.c | 70 ++++++++++++++++++++++++++++-----
 1 file changed, 60 insertions(+), 10 deletions(-)
drivers/mmc/host/meson-gx-mmc.c +60 -10
index 9a4da2544..b6afaccf7 100644
@@ -41,14 +41,17 @@
 #define   CLK_V2_TX_DELAY_MASK GENMASK(19, 16)
 #define   CLK_V2_RX_DELAY_MASK GENMASK(23, 20)
 #define   CLK_V2_ALWAYS_ON BIT(24)
+#define   CLK_V2_IRQ_SDIO_SLEEP BIT(25)
 
 #define   CLK_V3_TX_DELAY_MASK GENMASK(21, 16)
 #define   CLK_V3_RX_DELAY_MASK GENMASK(27, 22)
 #define   CLK_V3_ALWAYS_ON BIT(28)
+#define   CLK_V3_IRQ_SDIO_SLEEP BIT(29)
 
 #define   CLK_TX_DELAY_MASK(h)		(h->data->tx_delay_mask)
 #define   CLK_RX_DELAY_MASK(h)		(h->data->rx_delay_mask)
 #define   CLK_ALWAYS_ON(h)		(h->data->always_on)
+#define   CLK_IRQ_SDIO_SLEEP(h)		(h->data->irq_sdio_sleep)
 
 #define SD_EMMC_DELAY 0x4
 #define SD_EMMC_ADJUST 0x8
@@ -135,6 +138,7 @@ struct meson_mmc_data {
 	unsigned int rx_delay_mask;
 	unsigned int always_on;
 	unsigned int adjust;
+	unsigned int irq_sdio_sleep;
 };
 
 struct sd_emmc_desc {
@@ -174,6 +178,7 @@ struct meson_host {
 	bool vqmmc_enabled;
 	bool needs_pre_post_req;
 
+	spinlock_t lock;
 };
 
 #define CMD_CFG_LENGTH_MASK GENMASK(8, 0)
@@ -430,6 +435,7 @@ static int meson_mmc_clk_init(struct meson_host *host)
 	clk_reg |= FIELD_PREP(CLK_CORE_PHASE_MASK, CLK_PHASE_180);
 	clk_reg |= FIELD_PREP(CLK_TX_PHASE_MASK, CLK_PHASE_0);
 	clk_reg |= FIELD_PREP(CLK_RX_PHASE_MASK, CLK_PHASE_0);
+	clk_reg |= CLK_IRQ_SDIO_SLEEP(host);
 	writel(clk_reg, host->regs + SD_EMMC_CLOCK);
 
 	/* get the mux parents */
@@ -934,32 +940,54 @@ static void meson_mmc_read_resp(struct mmc_host *mmc, struct mmc_command *cmd)
 	}
 }
 
+static void __meson_mmc_enable_sdio_irq(struct mmc_host *mmc, int enable)
+{
+	struct meson_host *host = mmc_priv(mmc);
+	u32 reg_irqen = IRQ_EN_MASK;
+
+	if (enable)
+		reg_irqen |= IRQ_SDIO;
+	writel(reg_irqen, host->regs + SD_EMMC_IRQ_EN);
+}
+
 static irqreturn_t meson_mmc_irq(int irq, void *dev_id)
 {
 	struct meson_host *host = dev_id;
 	struct mmc_command *cmd;
-	struct mmc_data *data;
 	u32 status, raw_status;
 	irqreturn_t ret = IRQ_NONE;
 
 	raw_status = readl(host->regs + SD_EMMC_STATUS);
-	status = raw_status & IRQ_EN_MASK;
+	status = raw_status & (IRQ_EN_MASK | IRQ_SDIO);
 
 	if (!status) {
 		dev_dbg(host->dev,
 			"Unexpected IRQ! irq_en 0x%08lx - status 0x%08x\n",
-			 IRQ_EN_MASK, raw_status);
+			 IRQ_EN_MASK | IRQ_SDIO, raw_status);
 		return IRQ_NONE;
 	}
 
-	if (WARN_ON(!host) || WARN_ON(!host->cmd))
+	if (WARN_ON(!host))
 		return IRQ_NONE;
 
 	/* ack all raised interrupts */
 	writel(status, host->regs + SD_EMMC_STATUS);
 
 	cmd = host->cmd;
-	data = cmd->data;
+
+	if (status & IRQ_SDIO) {
+		spin_lock(&host->lock);
+		__meson_mmc_enable_sdio_irq(host->mmc, 0);
+		sdio_signal_irq(host->mmc);
+		spin_unlock(&host->lock);
+		status &= ~IRQ_SDIO;
+		if (!status)
+			return IRQ_HANDLED;
+	}
+
+	if (WARN_ON(!cmd))
+		return IRQ_NONE;
+
 	cmd->error = 0;
 	if (status & IRQ_CRC_ERR) {
 		dev_dbg(host->dev, "CRC Error - status 0x%08x\n", status);
@@ -977,12 +1005,9 @@ static irqreturn_t meson_mmc_irq(int irq, void *dev_id)
 
 	meson_mmc_read_resp(host->mmc, cmd);
 
-	if (status & IRQ_SDIO) {
-		dev_dbg(host->dev, "IRQ: SDIO TODO.\n");
-		ret = IRQ_HANDLED;
-	}
-
 	if (status & (IRQ_END_OF_CHAIN | IRQ_RESP_STATUS)) {
+		struct mmc_data *data = cmd->data;
+
 		if (data && !cmd->error)
 			data->bytes_xfered = data->blksz * data->blocks;
 		if (meson_mmc_bounce_buf_read(data) ||
@@ -1125,6 +1150,21 @@ static int meson_mmc_voltage_switch(struct mmc_host *mmc, struct mmc_ios *ios)
 	return -EINVAL;
 }
 
+static void meson_mmc_enable_sdio_irq(struct mmc_host *mmc, int enable)
+{
+	struct meson_host *host = mmc_priv(mmc);
+	unsigned long flags;
+
+	spin_lock_irqsave(&host->lock, flags);
+	__meson_mmc_enable_sdio_irq(mmc, enable);
+	spin_unlock_irqrestore(&host->lock, flags);
+}
+
+static void meson_mmc_ack_sdio_irq(struct mmc_host *mmc)
+{
+	meson_mmc_enable_sdio_irq(mmc, 1);
+}
+
 static const struct mmc_host_ops meson_mmc_ops = {
 	.request	= meson_mmc_request,
 	.set_ios	= meson_mmc_set_ios,
@@ -1134,6 +1174,8 @@ static const struct mmc_host_ops meson_mmc_ops = {
 	.execute_tuning = meson_mmc_resampling_tuning,
 	.card_busy	= meson_mmc_card_busy,
 	.start_signal_voltage_switch = meson_mmc_voltage_switch,
+	.enable_sdio_irq = meson_mmc_enable_sdio_irq,
+	.ack_sdio_irq	= meson_mmc_ack_sdio_irq,
 };
 
 static int meson_mmc_probe(struct platform_device *pdev)
@@ -1237,7 +1279,13 @@ static int meson_mmc_probe(struct platform_device *pdev)
 	if (ret)
 		goto err_init_clk;
 
+	spin_lock_init(&host->lock);
+
 	mmc->caps |= MMC_CAP_CMD23;
+
+	if (mmc->caps & MMC_CAP_SDIO_IRQ)
+		mmc->caps2 |= MMC_CAP2_SDIO_IRQ_NOTHREAD;
+
 	if (host->dram_access_quirk) {
 		/* Limit segments to 1 due to low available sram memory */
 		mmc->max_segs = 1;
@@ -1328,6 +1376,7 @@ static const struct meson_mmc_data meson_gx_data = {
 	.rx_delay_mask	= CLK_V2_RX_DELAY_MASK,
 	.always_on	= CLK_V2_ALWAYS_ON,
 	.adjust		= SD_EMMC_ADJUST,
+	.irq_sdio_sleep	= CLK_V2_IRQ_SDIO_SLEEP,
 };
 
 static const struct meson_mmc_data meson_axg_data = {
@@ -1335,6 +1384,7 @@ static const struct meson_mmc_data meson_axg_data = {
 	.rx_delay_mask	= CLK_V3_RX_DELAY_MASK,
 	.always_on	= CLK_V3_ALWAYS_ON,
 	.adjust		= SD_EMMC_V3_ADJUST,
+	.irq_sdio_sleep	= CLK_V3_IRQ_SDIO_SLEEP,
 };
 
 static const struct of_device_id meson_mmc_of_match[] = {
Signature · 1 line
2.37.2
#3 lore raw
In reply to Heiner Kallweit
Quoted 10 lines · Heiner Kallweit

Add SDIO interrupt support. Successfully tested on a S905X4-based system (V3 register layout) with a BRCM4334 SDIO wifi module (brcmfmac driver).

v2:
- use new SDIO interrupt API
v3:
- don't duplicate checking mmc->sdio_irq_pending

Quoted 7 lines

Heiner Kallweit (2):
mmc: meson: adjust and re-use constant IRQ_EN_MASK
mmc: meson-gx: add SDIO interrupt support

 drivers/mmc/host/meson-gx-mmc.c | 84 +++++++++++++++++++++++++--------
 1 file changed, 65 insertions(+), 19 deletions(-)

Applied for next, thanks!

Kind regards
Uffe

#4 lore raw

Hi Uffe, Heiner,

Quoted 15 lines · Ulf Hansson
Quoted 14 lines · Heiner Kallweit

Add SDIO interrupt support. Successfully tested on a S905X4-based system (V3 register layout) with a BRCM4334 SDIO wifi module (brcmfmac driver).

v2:
- use new SDIO interrupt API
v3:
- don't duplicate checking mmc->sdio_irq_pending

Heiner Kallweit (2):
mmc: meson: adjust and re-use constant IRQ_EN_MASK
mmc: meson-gx: add SDIO interrupt support

Quoted 5 lines
Quoted 3 lines
  drivers/mmc/host/meson-gx-mmc.c | 84 +++++++++++++++++++++++++--------
  1 file changed, 65 insertions(+), 19 deletions(-)

Applied for next, thanks!

Thanks for applying, but I was off (like many of reviewers) and I would have like this patchset to be tested on earlier SoCs aswell, or only enabled on S4 for now.

Neil

Quoted 3 lines

Kind regards
Uffe

#5 lore raw
Quoted 19 lines · Neil Armstrong

Hi Uffe, Heiner,

Quoted 15 lines · Ulf Hansson
Quoted 14 lines · Heiner Kallweit

Add SDIO interrupt support. Successfully tested on a S905X4-based system (V3 register layout) with a BRCM4334 SDIO wifi module (brcmfmac driver).

v2:
- use new SDIO interrupt API
v3:
- don't duplicate checking mmc->sdio_irq_pending

Heiner Kallweit (2):
mmc: meson: adjust and re-use constant IRQ_EN_MASK
mmc: meson-gx: add SDIO interrupt support

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
  drivers/mmc/host/meson-gx-mmc.c | 84 +++++++++++++++++++++++++--------
  1 file changed, 65 insertions(+), 19 deletions(-)

Applied for next, thanks!

Thanks for applying, but I was off (like many of reviewers) and I would have like this patchset to be tested on earlier SoCs aswell, or only enabled on S4 for now.

To actually make use of the new code, an update to the corresponding DTS files are needed to set the cap-sdio-irq property.

If that isn't sufficient, I prefer if we make a patch on top of the $subject series.

Kind regards
Uffe

_______________________________________________
linux-amlogic mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-amlogic

#6 lore raw
Quoted 24 lines · Ulf Hansson
Quoted 23 lines · Neil Armstrong

Hi Uffe, Heiner,

Quoted 19 lines · Ulf Hansson
Quoted 17 lines · Heiner Kallweit

Add SDIO interrupt support. Successfully tested on a S905X4-based system (V3 register layout) with a BRCM4334 SDIO wifi module (brcmfmac driver).

v2:
- use new SDIO interrupt API
v3:
- don't duplicate checking mmc->sdio_irq_pending

Heiner Kallweit (2):
mmc: meson: adjust and re-use constant IRQ_EN_MASK
mmc: meson-gx: add SDIO interrupt support

   drivers/mmc/host/meson-gx-mmc.c | 84 +++++++++++++++++++++++++--------
   1 file changed, 65 insertions(+), 19 deletions(-)
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Applied for next, thanks!

Thanks for applying, but I was off (like many of reviewers) and I would have like this patchset to be tested on earlier SoCs aswell, or only enabled on S4 for now.

To actually make use of the new code, an update to the corresponding DTS files are needed to set the cap-sdio-irq property.

I know but it changed the IRQ handling, let's hope we don't see any regressions.

Quoted 3 lines

If that isn't sufficient, I prefer if we make a patch on top of the $subject series.

OK, let's wait and see

Quoted 3 lines

Kind regards
Uffe

Thanks,
Neil

#7 lore raw
Quoted 28 lines · Neil Armstrong
Quoted 26 lines · Ulf Hansson
Quoted 25 lines · Neil Armstrong

Hi Uffe, Heiner,

Quoted 20 lines · Ulf Hansson
Quoted 10 lines · Heiner Kallweit

Add SDIO interrupt support. Successfully tested on a S905X4-based system (V3 register layout) with a BRCM4334 SDIO wifi module (brcmfmac driver).

v2:
- use new SDIO interrupt API
v3:
- don't duplicate checking mmc->sdio_irq_pending

Quoted 7 lines

Heiner Kallweit (2):
mmc: meson: adjust and re-use constant IRQ_EN_MASK
mmc: meson-gx: add SDIO interrupt support

   drivers/mmc/host/meson-gx-mmc.c | 84 +++++++++++++++++++++++++--------
   1 file changed, 65 insertions(+), 19 deletions(-)

Applied for next, thanks!

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Thanks for applying, but I was off (like many of reviewers) and I would have like this patchset to be tested on earlier SoCs aswell, or only enabled on S4 for now.

To actually make use of the new code, an update to the corresponding DTS files are needed to set the cap-sdio-irq property.

I know but it changed the IRQ handling, let's hope we don't see any regressions.

Right. Let's encourage people to test this!

I noticed that $subject patch sets the CLK_IRQ_SDIO_SLEEP bit, no matter whether the SDIO IRQs has been enabled. Don't know if that is intentional and/or could be a problem? Heiner?

[...]

Kind regards
Uffe

#8 lore raw
Quoted 35 lines · Ulf Hansson
Quoted 34 lines · Neil Armstrong
Quoted 31 lines · Ulf Hansson
Quoted 19 lines · Neil Armstrong

Hi Uffe, Heiner,

Quoted 15 lines · Ulf Hansson
Quoted 14 lines · Heiner Kallweit

Add SDIO interrupt support. Successfully tested on a S905X4-based system (V3 register layout) with a BRCM4334 SDIO wifi module (brcmfmac driver).

v2:
- use new SDIO interrupt API
v3:
- don't duplicate checking mmc->sdio_irq_pending

Heiner Kallweit (2):
mmc: meson: adjust and re-use constant IRQ_EN_MASK
mmc: meson-gx: add SDIO interrupt support

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
   drivers/mmc/host/meson-gx-mmc.c | 84 +++++++++++++++++++++++++--------
   1 file changed, 65 insertions(+), 19 deletions(-)

Applied for next, thanks!

Thanks for applying, but I was off (like many of reviewers) and I would have like this patchset to be tested on earlier SoCs aswell, or only enabled on S4 for now.

To actually make use of the new code, an update to the corresponding DTS files are needed to set the cap-sdio-irq property.

Quoted 8 lines
Quoted 1 line

I know but it changed the IRQ handling, let's hope we don't see any regressions.

Right. Let's encourage people to test this!

I noticed that $subject patch sets the CLK_IRQ_SDIO_SLEEP bit, no matter whether the SDIO IRQs has been enabled. Don't know if that is intentional and/or could be a problem? Heiner?

This bit enables SDIO interrupts in sleep mode too. I experienced no difference in behavior if SDIO interrupts aren't enabled.

Quoted 4 lines

[...]

Kind regards
Uffe