Skip to contentSkip to conversation

mmc: meson-gx: support platform interrupt as card detect interrupt

PATCH In review Heiner Kallweit 3 participants 9 messages Jan 29, 2023 – Feb 14, 2023

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

cover mmc: meson-gx: support platform interrupt as card detect interrupt

On certain platforms like Amlogic Meson gpiod_to_irq() isn't supported due to the design of gpio / interrupt controller. Therefore provide an option to specify the cd interrupt e.g. by device tree. The host controller can store the interrupt in cd_irq for use by mmc_gpiod_request_cd_irq().

Heiner Kallweit (2):
mmc: core: support platform interrupt as card detect interrupt
mmc: meson-gx: support platform interrupt as card detect interrupt

 drivers/mmc/core/slot-gpio.c    | 2 +-
 drivers/mmc/host/meson-gx-mmc.c | 3 +++
 include/linux/mmc/host.h        | 1 +
 3 files changed, 5 insertions(+), 1 deletion(-)
Signature · 1 line
2.39.1
#1 lore raw

PATCH 1/2 mmc: core: support platform interrupt as card detect interrupt

On certain platforms like Amlogic Meson gpiod_to_irq() isn't supported due to the design of gpio / interrupt controller. Therefore provide an option to specify the cd interrupt e.g. by device tree. The host controller can store the interrupt in cd_irq for use by mmc_gpiod_request_cd_irq().

---
 drivers/mmc/core/slot-gpio.c | 2 +-
 include/linux/mmc/host.h     | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/mmc/core/slot-gpio.c +1 -1
index dd2a4b6ab..69c22a997 100644
@@ -99,7 +99,7 @@ void mmc_gpiod_request_cd_irq(struct mmc_host *host)
 	 * IRQ number is already used by another unit and cannot be shared.
 	 */
 	if (!(host->caps & MMC_CAP_NEEDS_POLL))
-		irq = gpiod_to_irq(ctx->cd_gpio);
+		irq = host->cd_irq > 0 ? host->cd_irq : gpiod_to_irq(ctx->cd_gpio);
 
 	if (irq >= 0) {
 		if (!ctx->cd_gpio_isr)
include/linux/mmc/host.h +1 -0
index 8fdd3cf97..e998e919e 100644
@@ -470,6 +470,7 @@ struct mmc_host {
 
 	struct delayed_work	detect;
 	int			detect_change;	/* card detect flag */
+	int			cd_irq;		/* for use by mmc_gpiod_request_cd_irq */
 	struct mmc_slot		slot;
 
 	const struct mmc_bus_ops *bus_ops;	/* current bus driver */
Signature · 1 line
2.39.1
#2 lore raw

Re: [PATCH 1/2] mmc: core: support platform interrupt as card detect interrupt

Quoted 31 lines · Heiner Kallweit

On certain platforms like Amlogic Meson gpiod_to_irq() isn't supported due to the design of gpio / interrupt controller. Therefore provide an option to specify the cd interrupt e.g. by device tree. The host controller can store the interrupt in cd_irq for use by mmc_gpiod_request_cd_irq().

---
 drivers/mmc/core/slot-gpio.c | 2 +-
 include/linux/mmc/host.h     | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/mmc/core/slot-gpio.c +1 -1
index dd2a4b6ab..69c22a997 100644
@@ -99,7 +99,7 @@ void mmc_gpiod_request_cd_irq(struct mmc_host *host)
         * IRQ number is already used by another unit and cannot be shared.
         */
        if (!(host->caps & MMC_CAP_NEEDS_POLL))
-               irq = gpiod_to_irq(ctx->cd_gpio);
+               irq = host->cd_irq > 0 ? host->cd_irq : gpiod_to_irq(ctx->cd_gpio);
 
        if (irq >= 0) {
                if (!ctx->cd_gpio_isr)
include/linux/mmc/host.h +0 -0
index 8fdd3cf97..e998e919e 100644

include/linux/mmc/host.h struct mmc_host { · line 473

Quoted 4 lines
include/linux/mmc/host.h +1 -0
@@ -470,6 +470,7 @@ struct mmc_host {
 
        struct delayed_work     detect;
        int                     detect_change;  /* card detect flag */
+       int                     cd_irq;         /* for use by mmc_gpiod_request_cd_irq */

Rather than putting this in the struct mmc_host, I would prefer to keep it more internal to the mmc core/slot code.

That said, what do you think of moving this into the struct mmc_gpio instead? Of course, that also means that we need to add new slot gpio helper that users can call to set the corresponding value for the cd_irq.

Would that be okay to you?

include/linux/mmc/host.h struct mmc_host { · line 476

Quoted 3 lines
include/linux/mmc/host.h +0 -0
        struct mmc_slot         slot;
 
        const struct mmc_bus_ops *bus_ops;      /* current bus driver */

Kind regards
Uffe

#3 lore raw

Re: [PATCH 1/2] mmc: core: support platform interrupt as card detect interrupt

Quoted 40 lines · Ulf Hansson
Quoted 31 lines · Heiner Kallweit

On certain platforms like Amlogic Meson gpiod_to_irq() isn't supported due to the design of gpio / interrupt controller. Therefore provide an option to specify the cd interrupt e.g. by device tree. The host controller can store the interrupt in cd_irq for use by mmc_gpiod_request_cd_irq().

---
 drivers/mmc/core/slot-gpio.c | 2 +-
 include/linux/mmc/host.h     | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/mmc/core/slot-gpio.c +1 -1
index dd2a4b6ab..69c22a997 100644
@@ -99,7 +99,7 @@ void mmc_gpiod_request_cd_irq(struct mmc_host *host)
         * IRQ number is already used by another unit and cannot be shared.
         */
        if (!(host->caps & MMC_CAP_NEEDS_POLL))
-               irq = gpiod_to_irq(ctx->cd_gpio);
+               irq = host->cd_irq > 0 ? host->cd_irq : gpiod_to_irq(ctx->cd_gpio);
 
        if (irq >= 0) {
                if (!ctx->cd_gpio_isr)
include/linux/mmc/host.h +0 -0
index 8fdd3cf97..e998e919e 100644

include/linux/mmc/host.h struct mmc_host { · line 473

Quoted 4 lines
include/linux/mmc/host.h +1 -0
@@ -470,6 +470,7 @@ struct mmc_host {
 
        struct delayed_work     detect;
        int                     detect_change;  /* card detect flag */
+       int                     cd_irq;         /* for use by mmc_gpiod_request_cd_irq */

Rather than putting this in the struct mmc_host, I would prefer to keep it more internal to the mmc core/slot code.

Quoted 7 lines

That said, what do you think of moving this into the struct mmc_gpio instead? Of course, that also means that we need to add new slot gpio helper that users can call to set the corresponding value for the cd_irq.

Would that be okay to you?

Yes, that's the better approach.

Quoted 6 lines

include/linux/mmc/host.h struct mmc_host { · line 476

Quoted 3 lines
include/linux/mmc/host.h +0 -0
        struct mmc_slot         slot;
 
        const struct mmc_bus_ops *bus_ops;      /* current bus driver */

Kind regards
Uffe

#4 lore raw

PATCH 2/2 mmc: meson-gx: support platform interrupt as card detect interrupt

In reply to Heiner Kallweit

Use a new mmc core feature and support specifying the card detect gpio interrupt in device tree.

---
 drivers/mmc/host/meson-gx-mmc.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/mmc/host/meson-gx-mmc.c +3 -0
index be1a972c2..c87bc31d0 100644
@@ -1236,6 +1236,9 @@ static int meson_mmc_probe(struct platform_device *pdev)
 		goto free_host;
 	}
 
+	/* gpio card detect interrupt */
+	mmc->cd_irq = platform_get_irq_optional(pdev, 1);
+
 	host->pinctrl = devm_pinctrl_get(&pdev->dev);
 	if (IS_ERR(host->pinctrl)) {
 		ret = PTR_ERR(host->pinctrl);
Signature · 1 line
2.39.1
maintainer
#5 lore raw
Quoted 13 lines · Heiner Kallweit

Use a new mmc core feature and support specifying the card detect gpio interrupt in device tree.

---
  drivers/mmc/host/meson-gx-mmc.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/mmc/host/meson-gx-mmc.c +0 -0
index be1a972c2..c87bc31d0 100644

drivers/mmc/host/meson-gx-mmc.c static int meson_mmc_probe(struct platform_device *pdev) · line 1240

Quoted 5 lines
drivers/mmc/host/meson-gx-mmc.c +2 -0
@@ -1236,6 +1236,9 @@ static int meson_mmc_probe(struct platform_device *pdev)
  		goto free_host;
  	}
 
+	/* gpio card detect interrupt */
+	mmc->cd_irq = platform_get_irq_optional(pdev, 1);

Ok it's fine but beware GXBB/GXL/AXG doesn't support Rising + Falling GPIO IRQ, so this should only be used on G12A/B/SM1 and later.

Neil

Quoted 4 lines
drivers/mmc/host/meson-gx-mmc.c +1 -0
+
  	host->pinctrl = devm_pinctrl_get(&pdev->dev);
  	if (IS_ERR(host->pinctrl)) {
  		ret = PTR_ERR(host->pinctrl);
#6 lore raw
Quoted 9 lines · Neil Armstrong
Quoted 8 lines · Heiner Kallweit

Use a new mmc core feature and support specifying the card detect gpio interrupt in device tree.

---
  drivers/mmc/host/meson-gx-mmc.c | 3 +++

  1 file changed, 3 insertions(+)
Quoted 13 lines
Quoted 9 lines
drivers/mmc/host/meson-gx-mmc.c +0 -0
index be1a972c2..c87bc31d0 100644
@@ -1236,6 +1236,9 @@ static int meson_mmc_probe(struct platform_device *pdev)
           goto free_host;
       }

  +    /* gpio card detect interrupt */
+    mmc->cd_irq = platform_get_irq_optional(pdev, 1);

Ok it's fine but beware GXBB/GXL/AXG doesn't support Rising + Falling GPIO IRQ, so this should only be used on G12A/B/SM1 and later.

Thanks for the hint. I'm aware of the constraint for older versions. There the mmc core would silently fall back to polling.
At the time when the gpio irqchip code was developed Jerome and me had intense discussions on whether there's an acceptable workaround to support edge-both on these chip versions.

I tested on SC2, there the proposed way to support the gpio cd irq works fine.

Quoted 7 lines

Neil

Quoted 4 lines

+
      host->pinctrl = devm_pinctrl_get(&pdev->dev); if (IS_ERR(host->pinctrl)) {
          ret = PTR_ERR(host->pinctrl);

#7 lore raw
In reply to Heiner Kallweit
Quoted 3 lines · Heiner Kallweit

Use a new mmc core feature and support specifying the card detect gpio interrupt in device tree.

Don't we need an update to the DT doc too?

Kind regards
Uffe

Quoted 24 lines
---
 drivers/mmc/host/meson-gx-mmc.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/mmc/host/meson-gx-mmc.c +3 -1
index be1a972c2..c87bc31d0 100644
@@ -1236,6 +1236,9 @@ static int meson_mmc_probe(struct platform_device *pdev)
                goto free_host;
        }
 
+       /* gpio card detect interrupt */
+       mmc->cd_irq = platform_get_irq_optional(pdev, 1);
+
        host->pinctrl = devm_pinctrl_get(&pdev->dev);
        if (IS_ERR(host->pinctrl)) {
                ret = PTR_ERR(host->pinctrl);
--

2.39.1

#8 lore raw
Quoted 7 lines · Ulf Hansson
Quoted 3 lines · Heiner Kallweit

Use a new mmc core feature and support specifying the card detect gpio interrupt in device tree.

Don't we need an update to the DT doc too?

Right, the binding still has to be changed to allow more than one interrupt.

Quoted 27 lines

Kind regards
Uffe

Quoted 24 lines
---
 drivers/mmc/host/meson-gx-mmc.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/mmc/host/meson-gx-mmc.c +3 -1
index be1a972c2..c87bc31d0 100644
@@ -1236,6 +1236,9 @@ static int meson_mmc_probe(struct platform_device *pdev)
                goto free_host;
        }
 
+       /* gpio card detect interrupt */
+       mmc->cd_irq = platform_get_irq_optional(pdev, 1);
+
        host->pinctrl = devm_pinctrl_get(&pdev->dev);
        if (IS_ERR(host->pinctrl)) {
                ret = PTR_ERR(host->pinctrl);
--

2.39.1