Skip to content

Commit 527f36f

Browse files
Axe Yangstorulf
authored andcommitted
mmc: mediatek: add support for SDIO eint wakup IRQ
Add support for eint IRQ when MSDC is used as an SDIO host. This feature requires SDIO device support async IRQ function. With this feature, SDIO host can be awakened by SDIO card in suspend state, without additional pin. MSDC driver will time-share the SDIO DAT1 pin. During suspend, MSDC turn off clock and switch SDIO DAT1 pin to GPIO mode. And during resume, switch GPIO function back to DAT1 mode then turn on clock. Some device tree property should be added or modified in MSDC node to support SDIO eint IRQ. Pinctrls "state_eint" is mandatory. Since this feature depends on asynchronous interrupts, "wakeup-source", "keep-power-in-suspend" and "cap-sdio-irq" flags are necessary, and the interrupts list should be extended(the interrupt named with sdio_wakeup): &mmcX { ... interrupt-names = "msdc", "sdio_wakeup"; interrupts-extended = <...>, <&pio xxx IRQ_TYPE_LEVEL_LOW>; ... pinctrl-names = "default", "state_uhs", "state_eint"; ... pinctrl-2 = <&mmc2_pins_eint>; ... cap-sdio-irq; keep-power-in-suspend; wakeup-source; ... }; Co-developed-by: Yong Mao <[email protected]> Signed-off-by: Yong Mao <[email protected]> Reviewed-by: Chaotian Jing <[email protected]> Reviewed-by: AngeloGioacchino Del Regno <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Signed-off-by: Axe Yang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ulf Hansson <[email protected]>
1 parent 019e442 commit 527f36f

File tree

1 file changed

+80
-6
lines changed

1 file changed

+80
-6
lines changed

drivers/mmc/host/mtk-sd.c

Lines changed: 80 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: GPL-2.0-only
22
/*
3-
* Copyright (c) 2014-2015 MediaTek Inc.
3+
* Copyright (c) 2014-2015, 2022 MediaTek Inc.
44
* Author: Chaotian.Jing <[email protected]>
55
*/
66

@@ -20,6 +20,7 @@
2020
#include <linux/platform_device.h>
2121
#include <linux/pm.h>
2222
#include <linux/pm_runtime.h>
23+
#include <linux/pm_wakeirq.h>
2324
#include <linux/regulator/consumer.h>
2425
#include <linux/slab.h>
2526
#include <linux/spinlock.h>
@@ -440,8 +441,10 @@ struct msdc_host {
440441
struct pinctrl *pinctrl;
441442
struct pinctrl_state *pins_default;
442443
struct pinctrl_state *pins_uhs;
444+
struct pinctrl_state *pins_eint;
443445
struct delayed_work req_timeout;
444446
int irq; /* host interrupt */
447+
int eint_irq; /* interrupt from sdio device for waking up system */
445448
struct reset_control *reset;
446449

447450
struct clk *src_clk; /* msdc source clock */
@@ -1521,17 +1524,46 @@ static void __msdc_enable_sdio_irq(struct msdc_host *host, int enb)
15211524

15221525
static void msdc_enable_sdio_irq(struct mmc_host *mmc, int enb)
15231526
{
1524-
unsigned long flags;
15251527
struct msdc_host *host = mmc_priv(mmc);
1528+
unsigned long flags;
1529+
int ret;
15261530

15271531
spin_lock_irqsave(&host->lock, flags);
15281532
__msdc_enable_sdio_irq(host, enb);
15291533
spin_unlock_irqrestore(&host->lock, flags);
15301534

1531-
if (enb)
1532-
pm_runtime_get_noresume(host->dev);
1533-
else
1534-
pm_runtime_put_noidle(host->dev);
1535+
if (mmc_card_enable_async_irq(mmc->card) && host->pins_eint) {
1536+
if (enb) {
1537+
/*
1538+
* In dev_pm_set_dedicated_wake_irq_reverse(), eint pin will be set to
1539+
* GPIO mode. We need to restore it to SDIO DAT1 mode after that.
1540+
* Since the current pinstate is pins_uhs, to ensure pinctrl select take
1541+
* affect successfully, we change the pinstate to pins_eint firstly.
1542+
*/
1543+
pinctrl_select_state(host->pinctrl, host->pins_eint);
1544+
ret = dev_pm_set_dedicated_wake_irq_reverse(host->dev, host->eint_irq);
1545+
1546+
if (ret) {
1547+
dev_err(host->dev, "Failed to register SDIO wakeup irq!\n");
1548+
host->pins_eint = NULL;
1549+
pm_runtime_get_noresume(host->dev);
1550+
} else {
1551+
dev_dbg(host->dev, "SDIO eint irq: %d!\n", host->eint_irq);
1552+
}
1553+
1554+
pinctrl_select_state(host->pinctrl, host->pins_uhs);
1555+
} else {
1556+
dev_pm_clear_wake_irq(host->dev);
1557+
}
1558+
} else {
1559+
if (enb) {
1560+
/* Ensure host->pins_eint is NULL */
1561+
host->pins_eint = NULL;
1562+
pm_runtime_get_noresume(host->dev);
1563+
} else {
1564+
pm_runtime_put_noidle(host->dev);
1565+
}
1566+
}
15351567
}
15361568

15371569
static irqreturn_t msdc_cmdq_irq(struct msdc_host *host, u32 intsts)
@@ -2635,6 +2667,20 @@ static int msdc_drv_probe(struct platform_device *pdev)
26352667
goto host_free;
26362668
}
26372669

2670+
/* Support for SDIO eint irq ? */
2671+
if ((mmc->pm_caps & MMC_PM_WAKE_SDIO_IRQ) && (mmc->pm_caps & MMC_PM_KEEP_POWER)) {
2672+
host->eint_irq = platform_get_irq_byname(pdev, "sdio_wakeup");
2673+
if (host->eint_irq > 0) {
2674+
host->pins_eint = pinctrl_lookup_state(host->pinctrl, "state_eint");
2675+
if (IS_ERR(host->pins_eint)) {
2676+
dev_err(&pdev->dev, "Cannot find pinctrl eint!\n");
2677+
host->pins_eint = NULL;
2678+
} else {
2679+
device_init_wakeup(&pdev->dev, true);
2680+
}
2681+
}
2682+
}
2683+
26382684
msdc_of_property_parse(pdev, host);
26392685

26402686
host->dev = &pdev->dev;
@@ -2849,6 +2895,15 @@ static int __maybe_unused msdc_runtime_suspend(struct device *dev)
28492895
struct msdc_host *host = mmc_priv(mmc);
28502896

28512897
msdc_save_reg(host);
2898+
2899+
if (sdio_irq_claimed(mmc)) {
2900+
if (host->pins_eint) {
2901+
disable_irq(host->irq);
2902+
pinctrl_select_state(host->pinctrl, host->pins_eint);
2903+
}
2904+
2905+
__msdc_enable_sdio_irq(host, 0);
2906+
}
28522907
msdc_gate_clock(host);
28532908
return 0;
28542909
}
@@ -2864,12 +2919,18 @@ static int __maybe_unused msdc_runtime_resume(struct device *dev)
28642919
return ret;
28652920

28662921
msdc_restore_reg(host);
2922+
2923+
if (sdio_irq_claimed(mmc) && host->pins_eint) {
2924+
pinctrl_select_state(host->pinctrl, host->pins_uhs);
2925+
enable_irq(host->irq);
2926+
}
28672927
return 0;
28682928
}
28692929

28702930
static int __maybe_unused msdc_suspend(struct device *dev)
28712931
{
28722932
struct mmc_host *mmc = dev_get_drvdata(dev);
2933+
struct msdc_host *host = mmc_priv(mmc);
28732934
int ret;
28742935

28752936
if (mmc->caps2 & MMC_CAP2_CQE) {
@@ -2878,11 +2939,24 @@ static int __maybe_unused msdc_suspend(struct device *dev)
28782939
return ret;
28792940
}
28802941

2942+
/*
2943+
* Bump up runtime PM usage counter otherwise dev->power.needs_force_resume will
2944+
* not be marked as 1, pm_runtime_force_resume() will go out directly.
2945+
*/
2946+
if (sdio_irq_claimed(mmc) && host->pins_eint)
2947+
pm_runtime_get_noresume(dev);
2948+
28812949
return pm_runtime_force_suspend(dev);
28822950
}
28832951

28842952
static int __maybe_unused msdc_resume(struct device *dev)
28852953
{
2954+
struct mmc_host *mmc = dev_get_drvdata(dev);
2955+
struct msdc_host *host = mmc_priv(mmc);
2956+
2957+
if (sdio_irq_claimed(mmc) && host->pins_eint)
2958+
pm_runtime_put_noidle(dev);
2959+
28862960
return pm_runtime_force_resume(dev);
28872961
}
28882962

0 commit comments

Comments
 (0)