hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
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
....@@ -1344,6 +1332,7 @@
13441332 #ifdef RTSX_USB_USE_LEDS_CLASS
13451333 int err;
13461334 #endif
1335
+ int ret;
13471336
13481337 ucr = usb_get_intfdata(to_usb_interface(pdev->dev.parent));
13491338 if (!ucr)
....@@ -1363,8 +1352,6 @@
13631352
13641353 mutex_init(&host->host_mutex);
13651354 rtsx_usb_init_host(host);
1366
- pm_runtime_use_autosuspend(&pdev->dev);
1367
- pm_runtime_set_autosuspend_delay(&pdev->dev, 50);
13681355 pm_runtime_enable(&pdev->dev);
13691356
13701357 #ifdef RTSX_USB_USE_LEDS_CLASS
....@@ -1382,7 +1369,15 @@
13821369 INIT_WORK(&host->led_work, rtsx_usb_update_led);
13831370
13841371 #endif
1385
- mmc_add_host(mmc);
1372
+ ret = mmc_add_host(mmc);
1373
+ if (ret) {
1374
+#ifdef RTSX_USB_USE_LEDS_CLASS
1375
+ led_classdev_unregister(&host->led);
1376
+#endif
1377
+ mmc_free_host(mmc);
1378
+ pm_runtime_disable(&pdev->dev);
1379
+ return ret;
1380
+ }
13861381
13871382 return 0;
13881383 }
....@@ -1419,7 +1414,6 @@
14191414
14201415 mmc_free_host(mmc);
14211416 pm_runtime_disable(&pdev->dev);
1422
- pm_runtime_dont_use_autosuspend(&pdev->dev);
14231417 platform_set_drvdata(pdev, NULL);
14241418
14251419 dev_dbg(&(pdev->dev),
....@@ -1427,6 +1421,31 @@
14271421
14281422 return 0;
14291423 }
1424
+
1425
+#ifdef CONFIG_PM
1426
+static int rtsx_usb_sdmmc_runtime_suspend(struct device *dev)
1427
+{
1428
+ struct rtsx_usb_sdmmc *host = dev_get_drvdata(dev);
1429
+
1430
+ host->mmc->caps &= ~MMC_CAP_NEEDS_POLL;
1431
+ return 0;
1432
+}
1433
+
1434
+static int rtsx_usb_sdmmc_runtime_resume(struct device *dev)
1435
+{
1436
+ struct rtsx_usb_sdmmc *host = dev_get_drvdata(dev);
1437
+
1438
+ host->mmc->caps |= MMC_CAP_NEEDS_POLL;
1439
+ if (sdmmc_get_cd(host->mmc) == 1)
1440
+ mmc_detect_change(host->mmc, 0);
1441
+ return 0;
1442
+}
1443
+#endif
1444
+
1445
+static const struct dev_pm_ops rtsx_usb_sdmmc_dev_pm_ops = {
1446
+ SET_RUNTIME_PM_OPS(rtsx_usb_sdmmc_runtime_suspend,
1447
+ rtsx_usb_sdmmc_runtime_resume, NULL)
1448
+};
14301449
14311450 static const struct platform_device_id rtsx_usb_sdmmc_ids[] = {
14321451 {
....@@ -1443,6 +1462,8 @@
14431462 .id_table = rtsx_usb_sdmmc_ids,
14441463 .driver = {
14451464 .name = "rtsx_usb_sdmmc",
1465
+ .probe_type = PROBE_PREFER_ASYNCHRONOUS,
1466
+ .pm = &rtsx_usb_sdmmc_dev_pm_ops,
14461467 },
14471468 };
14481469 module_platform_driver(rtsx_usb_sdmmc_driver);