]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
mmc: rtsx: Use pm_runtime_{get,put}() to handle runtime PM
authorKai-Heng Feng <kai.heng.feng@canonical.com>
Tue, 25 Jan 2022 05:50:06 +0000 (13:50 +0800)
committerStefan Bader <stefan.bader@canonical.com>
Fri, 20 May 2022 12:40:21 +0000 (14:40 +0200)
BugLink: https://bugs.launchpad.net/bugs/1969110
commit 7499b529d97f752124fa62fefa1d6d44b371215a upstream.

Commit 5b4258f6721f ("misc: rtsx: rts5249 support runtime PM") doesn't
use pm_runtime_{get,put}() helpers when it should, so the RPM refcount
keeps at zero, hence its parent driver, rtsx_pci, has to do lots of
weird tricks to keep it from runtime suspending.

So use those helpers at right places to properly manage runtime PM.

Fixes: 5b4258f6721f ("misc: rtsx: rts5249 support runtime PM")
Cc: Ricky WU <ricky_wu@realtek.com>
Tested-by: Ricky WU <ricky_wu@realtek.com>
Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
Link: https://lore.kernel.org/r/20220125055010.1866563-1-kai.heng.feng@canonical.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 8ec990990be3b59ce4a7ac5a53432f4c2f79a96d)
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
drivers/mmc/host/rtsx_pci_sdmmc.c

index e1580f78c6b2de6376b4bf2440e2056c8a53b395..d26803d3f4ca356e9280bdbfa7a01bff0e2b45ee 100644 (file)
@@ -803,6 +803,7 @@ static void sd_request(struct work_struct *work)
        struct mmc_request *mrq = host->mrq;
        struct mmc_command *cmd = mrq->cmd;
        struct mmc_data *data = mrq->data;
+       struct device *dev = &host->pdev->dev;
 
        unsigned int data_size = 0;
        int err;
@@ -819,6 +820,7 @@ static void sd_request(struct work_struct *work)
        }
 
        mutex_lock(&pcr->pcr_mutex);
+       pm_runtime_get_sync(dev);
 
        rtsx_pci_start_run(pcr);
 
@@ -855,6 +857,8 @@ static void sd_request(struct work_struct *work)
                        data->bytes_xfered = data->blocks * data->blksz;
        }
 
+       pm_runtime_mark_last_busy(dev);
+       pm_runtime_put_autosuspend(dev);
        mutex_unlock(&pcr->pcr_mutex);
 
 finish:
@@ -1088,6 +1092,7 @@ static void sdmmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
 {
        struct realtek_pci_sdmmc *host = mmc_priv(mmc);
        struct rtsx_pcr *pcr = host->pcr;
+       struct device *dev = &host->pdev->dev;
 
        if (host->eject)
                return;
@@ -1096,6 +1101,7 @@ static void sdmmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
                return;
 
        mutex_lock(&pcr->pcr_mutex);
+       pm_runtime_get_sync(dev);
 
        rtsx_pci_start_run(pcr);
 
@@ -1129,6 +1135,8 @@ static void sdmmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
        rtsx_pci_switch_clock(pcr, ios->clock, host->ssc_depth,
                        host->initial_mode, host->double_clk, host->vpclk);
 
+       pm_runtime_mark_last_busy(dev);
+       pm_runtime_put_autosuspend(dev);
        mutex_unlock(&pcr->pcr_mutex);
 }
 
@@ -1136,6 +1144,7 @@ static int sdmmc_get_ro(struct mmc_host *mmc)
 {
        struct realtek_pci_sdmmc *host = mmc_priv(mmc);
        struct rtsx_pcr *pcr = host->pcr;
+       struct device *dev = &host->pdev->dev;
        int ro = 0;
        u32 val;
 
@@ -1143,6 +1152,7 @@ static int sdmmc_get_ro(struct mmc_host *mmc)
                return -ENOMEDIUM;
 
        mutex_lock(&pcr->pcr_mutex);
+       pm_runtime_get_sync(dev);
 
        rtsx_pci_start_run(pcr);
 
@@ -1152,6 +1162,8 @@ static int sdmmc_get_ro(struct mmc_host *mmc)
        if (val & SD_WRITE_PROTECT)
                ro = 1;
 
+       pm_runtime_mark_last_busy(dev);
+       pm_runtime_put_autosuspend(dev);
        mutex_unlock(&pcr->pcr_mutex);
 
        return ro;
@@ -1161,6 +1173,7 @@ static int sdmmc_get_cd(struct mmc_host *mmc)
 {
        struct realtek_pci_sdmmc *host = mmc_priv(mmc);
        struct rtsx_pcr *pcr = host->pcr;
+       struct device *dev = &host->pdev->dev;
        int cd = 0;
        u32 val;
 
@@ -1168,6 +1181,7 @@ static int sdmmc_get_cd(struct mmc_host *mmc)
                return cd;
 
        mutex_lock(&pcr->pcr_mutex);
+       pm_runtime_get_sync(dev);
 
        rtsx_pci_start_run(pcr);
 
@@ -1177,6 +1191,8 @@ static int sdmmc_get_cd(struct mmc_host *mmc)
        if (val & SD_EXIST)
                cd = 1;
 
+       pm_runtime_mark_last_busy(dev);
+       pm_runtime_put_autosuspend(dev);
        mutex_unlock(&pcr->pcr_mutex);
 
        return cd;
@@ -1259,6 +1275,7 @@ static int sdmmc_switch_voltage(struct mmc_host *mmc, struct mmc_ios *ios)
 {
        struct realtek_pci_sdmmc *host = mmc_priv(mmc);
        struct rtsx_pcr *pcr = host->pcr;
+       struct device *dev = &host->pdev->dev;
        int err = 0;
        u8 voltage;
 
@@ -1273,6 +1290,7 @@ static int sdmmc_switch_voltage(struct mmc_host *mmc, struct mmc_ios *ios)
                return err;
 
        mutex_lock(&pcr->pcr_mutex);
+       pm_runtime_get_sync(dev);
 
        rtsx_pci_start_run(pcr);
 
@@ -1302,6 +1320,8 @@ out:
        err = rtsx_pci_write_register(pcr, SD_BUS_STAT,
                        SD_CLK_TOGGLE_EN | SD_CLK_FORCE_STOP, 0);
 
+       pm_runtime_mark_last_busy(dev);
+       pm_runtime_put_autosuspend(dev);
        mutex_unlock(&pcr->pcr_mutex);
 
        return err;
@@ -1311,6 +1331,7 @@ static int sdmmc_execute_tuning(struct mmc_host *mmc, u32 opcode)
 {
        struct realtek_pci_sdmmc *host = mmc_priv(mmc);
        struct rtsx_pcr *pcr = host->pcr;
+       struct device *dev = &host->pdev->dev;
        int err = 0;
 
        if (host->eject)
@@ -1321,6 +1342,7 @@ static int sdmmc_execute_tuning(struct mmc_host *mmc, u32 opcode)
                return err;
 
        mutex_lock(&pcr->pcr_mutex);
+       pm_runtime_get_sync(dev);
 
        rtsx_pci_start_run(pcr);
 
@@ -1353,6 +1375,8 @@ static int sdmmc_execute_tuning(struct mmc_host *mmc, u32 opcode)
                err = sd_change_phase(host, DDR50_RX_PHASE(pcr), true);
 
 out:
+       pm_runtime_mark_last_busy(dev);
+       pm_runtime_put_autosuspend(dev);
        mutex_unlock(&pcr->pcr_mutex);
 
        return err;