forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/drivers/mmc/host/rtsx_usb_sdmmc.c
....@@ -1,18 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /* Realtek USB SD/MMC Card Interface driver
23 *
34 * Copyright(c) 2009-2013 Realtek Semiconductor Corp. All rights reserved.
4
- *
5
- * This program is free software; you can redistribute it and/or modify it
6
- * under the terms of the GNU General Public License version 2
7
- * as published by the Free Software Foundation.
8
- *
9
- * This program is distributed in the hope that it will be useful, but
10
- * WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
- * General Public License for more details.
13
- *
14
- * You should have received a copy of the GNU General Public License along
15
- * with this program; if not, see <http://www.gnu.org/licenses/>.
165 *
176 * Author:
187 * Roger Tseng <rogerable@realtek.com>
....@@ -28,6 +17,7 @@
2817 #include <linux/mmc/sd.h>
2918 #include <linux/mmc/card.h>
3019 #include <linux/scatterlist.h>
20
+#include <linux/pm.h>
3121 #include <linux/pm_runtime.h>
3222
3323 #include <linux/rtsx_usb.h>
....@@ -589,7 +579,6 @@
589579 static int sd_change_phase(struct rtsx_usb_sdmmc *host, u8 sample_point, int tx)
590580 {
591581 struct rtsx_ucr *ucr = host->ucr;
592
- int err;
593582
594583 dev_dbg(sdmmc_dev(host), "%s: %s sample_point = %d\n",
595584 __func__, tx ? "TX" : "RX", sample_point);
....@@ -611,11 +600,7 @@
611600 rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, CLK_DIV, CLK_CHANGE, 0);
612601 rtsx_usb_add_cmd(ucr, WRITE_REG_CMD, SD_CFG1, SD_ASYNC_FIFO_RST, 0);
613602
614
- err = rtsx_usb_send_cmd(ucr, MODE_C, 100);
615
- if (err)
616
- return err;
617
-
618
- return 0;
603
+ return rtsx_usb_send_cmd(ucr, MODE_C, 100);
619604 }
620605
621606 static inline u32 get_phase_point(u32 phase_map, unsigned int idx)
....@@ -664,12 +649,11 @@
664649
665650 static void sd_wait_data_idle(struct rtsx_usb_sdmmc *host)
666651 {
667
- int err, i;
652
+ int i;
668653 u8 val = 0;
669654
670655 for (i = 0; i < 100; i++) {
671
- err = rtsx_usb_ep0_read_register(host->ucr,
672
- SD_DATA_STATE, &val);
656
+ rtsx_usb_ep0_read_register(host->ucr, SD_DATA_STATE, &val);
673657 if (val & SD_DATA_IDLE)
674658 return;
675659
....@@ -1042,9 +1026,9 @@
10421026
10431027 if (power_mode == MMC_POWER_OFF) {
10441028 err = sd_power_off(host);
1045
- pm_runtime_put(sdmmc_dev(host));
1029
+ pm_runtime_put_noidle(sdmmc_dev(host));
10461030 } else {
1047
- pm_runtime_get_sync(sdmmc_dev(host));
1031
+ pm_runtime_get_noresume(sdmmc_dev(host));
10481032 err = sd_power_on(host);
10491033 }
10501034
....@@ -1297,16 +1281,20 @@
12971281 container_of(work, struct rtsx_usb_sdmmc, led_work);
12981282 struct rtsx_ucr *ucr = host->ucr;
12991283
1300
- pm_runtime_get_sync(sdmmc_dev(host));
1284
+ pm_runtime_get_noresume(sdmmc_dev(host));
13011285 mutex_lock(&ucr->dev_mutex);
1286
+
1287
+ if (host->power_mode == MMC_POWER_OFF)
1288
+ goto out;
13021289
13031290 if (host->led.brightness == LED_OFF)
13041291 rtsx_usb_turn_off_led(ucr);
13051292 else
13061293 rtsx_usb_turn_on_led(ucr);
13071294
1295
+out:
13081296 mutex_unlock(&ucr->dev_mutex);
1309
- pm_runtime_put(sdmmc_dev(host));
1297
+ pm_runtime_put_sync_suspend(sdmmc_dev(host));
13101298 }
13111299 #endif
13121300
....@@ -1320,7 +1308,7 @@
13201308 mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_SD_HIGHSPEED |
13211309 MMC_CAP_MMC_HIGHSPEED | MMC_CAP_BUS_WIDTH_TEST |
13221310 MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 | MMC_CAP_UHS_SDR50 |
1323
- MMC_CAP_NEEDS_POLL | MMC_CAP_ERASE;
1311
+ MMC_CAP_SYNC_RUNTIME_PM;
13241312 mmc->caps2 = MMC_CAP2_NO_PRESCAN_POWERUP | MMC_CAP2_FULL_PWR_CYCLE |
13251313 MMC_CAP2_NO_SDIO;
13261314
....@@ -1363,8 +1351,6 @@
13631351
13641352 mutex_init(&host->host_mutex);
13651353 rtsx_usb_init_host(host);
1366
- pm_runtime_use_autosuspend(&pdev->dev);
1367
- pm_runtime_set_autosuspend_delay(&pdev->dev, 50);
13681354 pm_runtime_enable(&pdev->dev);
13691355
13701356 #ifdef RTSX_USB_USE_LEDS_CLASS
....@@ -1419,7 +1405,6 @@
14191405
14201406 mmc_free_host(mmc);
14211407 pm_runtime_disable(&pdev->dev);
1422
- pm_runtime_dont_use_autosuspend(&pdev->dev);
14231408 platform_set_drvdata(pdev, NULL);
14241409
14251410 dev_dbg(&(pdev->dev),
....@@ -1427,6 +1412,31 @@
14271412
14281413 return 0;
14291414 }
1415
+
1416
+#ifdef CONFIG_PM
1417
+static int rtsx_usb_sdmmc_runtime_suspend(struct device *dev)
1418
+{
1419
+ struct rtsx_usb_sdmmc *host = dev_get_drvdata(dev);
1420
+
1421
+ host->mmc->caps &= ~MMC_CAP_NEEDS_POLL;
1422
+ return 0;
1423
+}
1424
+
1425
+static int rtsx_usb_sdmmc_runtime_resume(struct device *dev)
1426
+{
1427
+ struct rtsx_usb_sdmmc *host = dev_get_drvdata(dev);
1428
+
1429
+ host->mmc->caps |= MMC_CAP_NEEDS_POLL;
1430
+ if (sdmmc_get_cd(host->mmc) == 1)
1431
+ mmc_detect_change(host->mmc, 0);
1432
+ return 0;
1433
+}
1434
+#endif
1435
+
1436
+static const struct dev_pm_ops rtsx_usb_sdmmc_dev_pm_ops = {
1437
+ SET_RUNTIME_PM_OPS(rtsx_usb_sdmmc_runtime_suspend,
1438
+ rtsx_usb_sdmmc_runtime_resume, NULL)
1439
+};
14301440
14311441 static const struct platform_device_id rtsx_usb_sdmmc_ids[] = {
14321442 {
....@@ -1444,6 +1454,7 @@
14441454 .driver = {
14451455 .name = "rtsx_usb_sdmmc",
14461456 .probe_type = PROBE_PREFER_ASYNCHRONOUS,
1457
+ .pm = &rtsx_usb_sdmmc_dev_pm_ops,
14471458 },
14481459 };
14491460 module_platform_driver(rtsx_usb_sdmmc_driver);