hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/mmc/host/rtsx_pci_sdmmc.c
....@@ -1,19 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /* Realtek PCI-Express 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 as published by the
7
- * Free Software Foundation; either version 2, or (at your option) any
8
- * later version.
9
- *
10
- * This program is distributed in the hope that it will be useful, but
11
- * WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
- * General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License along
16
- * with this program; if not, see <http://www.gnu.org/licenses/>.
175 *
186 * Author:
197 * Wei WANG <wei_wang@realsil.com.cn>
....@@ -49,10 +37,7 @@
4937 bool double_clk;
5038 bool eject;
5139 bool initial_mode;
52
- int power_state;
53
-#define SDMMC_POWER_ON 1
54
-#define SDMMC_POWER_OFF 0
55
-
40
+ int prev_power_state;
5641 int sg_count;
5742 s32 cookie;
5843 int cookie_sg_count;
....@@ -697,11 +682,11 @@
697682
698683 static void sd_wait_data_idle(struct realtek_pci_sdmmc *host)
699684 {
700
- int err, i;
685
+ int i;
701686 u8 val = 0;
702687
703688 for (i = 0; i < 100; i++) {
704
- err = rtsx_pci_read_register(host->pcr, SD_DATA_STATE, &val);
689
+ rtsx_pci_read_register(host->pcr, SD_DATA_STATE, &val);
705690 if (val & SD_DATA_IDLE)
706691 return;
707692
....@@ -914,13 +899,20 @@
914899 return err;
915900 }
916901
917
-static int sd_power_on(struct realtek_pci_sdmmc *host)
902
+static int sd_power_on(struct realtek_pci_sdmmc *host, unsigned char power_mode)
918903 {
919904 struct rtsx_pcr *pcr = host->pcr;
920905 int err;
921906
922
- if (host->power_state == SDMMC_POWER_ON)
907
+ if (host->prev_power_state == MMC_POWER_ON)
923908 return 0;
909
+
910
+ if (host->prev_power_state == MMC_POWER_UP) {
911
+ rtsx_pci_write_register(pcr, SD_BUS_STAT, SD_CLK_TOGGLE_EN, 0);
912
+ goto finish;
913
+ }
914
+
915
+ msleep(100);
924916
925917 rtsx_pci_init_cmd(pcr);
926918 rtsx_pci_add_cmd(pcr, WRITE_REG_CMD, CARD_SELECT, 0x07, SD_MOD_SEL);
....@@ -940,11 +932,17 @@
940932 if (err < 0)
941933 return err;
942934
935
+ mdelay(1);
936
+
943937 err = rtsx_pci_write_register(pcr, CARD_OE, SD_OUTPUT_EN, SD_OUTPUT_EN);
944938 if (err < 0)
945939 return err;
946940
947
- host->power_state = SDMMC_POWER_ON;
941
+ /* send at least 74 clocks */
942
+ rtsx_pci_write_register(pcr, SD_BUS_STAT, SD_CLK_TOGGLE_EN, SD_CLK_TOGGLE_EN);
943
+
944
+finish:
945
+ host->prev_power_state = power_mode;
948946 return 0;
949947 }
950948
....@@ -953,7 +951,7 @@
953951 struct rtsx_pcr *pcr = host->pcr;
954952 int err;
955953
956
- host->power_state = SDMMC_POWER_OFF;
954
+ host->prev_power_state = MMC_POWER_OFF;
957955
958956 rtsx_pci_init_cmd(pcr);
959957
....@@ -979,7 +977,7 @@
979977 if (power_mode == MMC_POWER_OFF)
980978 err = sd_power_off(host);
981979 else
982
- err = sd_power_on(host);
980
+ err = sd_power_on(host, power_mode);
983981
984982 return err;
985983 }
....@@ -1358,6 +1356,8 @@
13581356 mmc->caps |= MMC_CAP_1_8V_DDR;
13591357 if (pcr->extra_caps & EXTRA_CAPS_MMC_8BIT)
13601358 mmc->caps |= MMC_CAP_8_BIT_DATA;
1359
+ if (pcr->extra_caps & EXTRA_CAPS_NO_MMC)
1360
+ mmc->caps2 |= MMC_CAP2_NO_MMC;
13611361 }
13621362
13631363 static void realtek_init_host(struct realtek_pci_sdmmc *host)
....@@ -1369,7 +1369,7 @@
13691369 mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195;
13701370 mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_SD_HIGHSPEED |
13711371 MMC_CAP_MMC_HIGHSPEED | MMC_CAP_BUS_WIDTH_TEST |
1372
- MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25 | MMC_CAP_ERASE;
1372
+ MMC_CAP_UHS_SDR12 | MMC_CAP_UHS_SDR25;
13731373 mmc->caps2 = MMC_CAP2_NO_PRESCAN_POWERUP | MMC_CAP2_FULL_PWR_CYCLE;
13741374 mmc->max_current_330 = 400;
13751375 mmc->max_current_180 = 800;
....@@ -1414,10 +1414,11 @@
14141414
14151415 host = mmc_priv(mmc);
14161416 host->pcr = pcr;
1417
+ mmc->ios.power_delay_ms = 5;
14171418 host->mmc = mmc;
14181419 host->pdev = pdev;
14191420 host->cookie = -1;
1420
- host->power_state = SDMMC_POWER_OFF;
1421
+ host->prev_power_state = MMC_POWER_OFF;
14211422 INIT_WORK(&host->work, sd_request);
14221423 platform_set_drvdata(pdev, host);
14231424 pcr->slots[RTSX_SD_CARD].p_dev = pdev;
....@@ -1491,6 +1492,7 @@
14911492 .id_table = rtsx_pci_sdmmc_ids,
14921493 .driver = {
14931494 .name = DRV_NAME_RTSX_PCI_SDMMC,
1495
+ .probe_type = PROBE_PREFER_ASYNCHRONOUS,
14941496 },
14951497 };
14961498 module_platform_driver(rtsx_pci_sdmmc_driver);