| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * drivers/mmc/host/via-sdmmc.c - VIA SD/MMC Card Reader driver |
|---|
| 3 | 4 | * Copyright (c) 2008, VIA Technologies Inc. All Rights Reserved. |
|---|
| 4 | | - * |
|---|
| 5 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 6 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 7 | | - * the Free Software Foundation; either version 2 of the License, or (at |
|---|
| 8 | | - * your option) any later version. |
|---|
| 9 | 5 | */ |
|---|
| 10 | 6 | |
|---|
| 11 | 7 | #include <linux/pci.h> |
|---|
| .. | .. |
|---|
| 691 | 687 | via_sdc_send_command(host, mrq->cmd); |
|---|
| 692 | 688 | } |
|---|
| 693 | 689 | |
|---|
| 694 | | - mmiowb(); |
|---|
| 695 | 690 | spin_unlock_irqrestore(&host->lock, flags); |
|---|
| 696 | 691 | } |
|---|
| 697 | 692 | |
|---|
| .. | .. |
|---|
| 716 | 711 | gatt &= ~VIA_CRDR_PCICLKGATT_PAD_PWRON; |
|---|
| 717 | 712 | writeb(gatt, host->pcictrl_mmiobase + VIA_CRDR_PCICLKGATT); |
|---|
| 718 | 713 | |
|---|
| 719 | | - mmiowb(); |
|---|
| 720 | 714 | spin_unlock_irqrestore(&host->lock, flags); |
|---|
| 721 | 715 | |
|---|
| 722 | 716 | via_pwron_sleep(host); |
|---|
| .. | .. |
|---|
| 775 | 769 | if (readb(addrbase + VIA_CRDR_PCISDCCLK) != clock) |
|---|
| 776 | 770 | writeb(clock, addrbase + VIA_CRDR_PCISDCCLK); |
|---|
| 777 | 771 | |
|---|
| 778 | | - mmiowb(); |
|---|
| 779 | 772 | spin_unlock_irqrestore(&host->lock, flags); |
|---|
| 780 | 773 | |
|---|
| 781 | 774 | if (ios->power_mode != MMC_POWER_OFF) |
|---|
| .. | .. |
|---|
| 835 | 828 | via_restore_pcictrlreg(host); |
|---|
| 836 | 829 | via_restore_sdcreg(host); |
|---|
| 837 | 830 | |
|---|
| 838 | | - mmiowb(); |
|---|
| 839 | 831 | spin_unlock_irqrestore(&host->lock, flags); |
|---|
| 840 | 832 | } |
|---|
| 841 | 833 | |
|---|
| .. | .. |
|---|
| 933 | 925 | |
|---|
| 934 | 926 | result = IRQ_HANDLED; |
|---|
| 935 | 927 | |
|---|
| 936 | | - mmiowb(); |
|---|
| 937 | 928 | out: |
|---|
| 938 | 929 | spin_unlock(&sdhost->lock); |
|---|
| 939 | 930 | |
|---|
| .. | .. |
|---|
| 968 | 959 | } |
|---|
| 969 | 960 | } |
|---|
| 970 | 961 | |
|---|
| 971 | | - mmiowb(); |
|---|
| 972 | 962 | spin_unlock_irqrestore(&sdhost->lock, flags); |
|---|
| 973 | 963 | } |
|---|
| 974 | 964 | |
|---|
| .. | .. |
|---|
| 1020 | 1010 | tasklet_schedule(&host->finish_tasklet); |
|---|
| 1021 | 1011 | } |
|---|
| 1022 | 1012 | |
|---|
| 1023 | | - mmiowb(); |
|---|
| 1024 | 1013 | spin_unlock_irqrestore(&host->lock, flags); |
|---|
| 1025 | 1014 | |
|---|
| 1026 | 1015 | via_reset_pcictrl(host); |
|---|
| .. | .. |
|---|
| 1028 | 1017 | spin_lock_irqsave(&host->lock, flags); |
|---|
| 1029 | 1018 | } |
|---|
| 1030 | 1019 | |
|---|
| 1031 | | - mmiowb(); |
|---|
| 1032 | 1020 | spin_unlock_irqrestore(&host->lock, flags); |
|---|
| 1033 | 1021 | |
|---|
| 1034 | 1022 | via_print_pcictrl(host); |
|---|
| .. | .. |
|---|
| 1126 | 1114 | |
|---|
| 1127 | 1115 | len = pci_resource_len(pcidev, 0); |
|---|
| 1128 | 1116 | base = pci_resource_start(pcidev, 0); |
|---|
| 1129 | | - sdhost->mmiobase = ioremap_nocache(base, len); |
|---|
| 1117 | + sdhost->mmiobase = ioremap(base, len); |
|---|
| 1130 | 1118 | if (!sdhost->mmiobase) { |
|---|
| 1131 | 1119 | ret = -ENOMEM; |
|---|
| 1132 | 1120 | goto free_mmc_host; |
|---|
| .. | .. |
|---|
| 1196 | 1184 | |
|---|
| 1197 | 1185 | /* Disable generating further interrupts */ |
|---|
| 1198 | 1186 | writeb(0x0, sdhost->pcictrl_mmiobase + VIA_CRDR_PCIINTCTRL); |
|---|
| 1199 | | - mmiowb(); |
|---|
| 1200 | 1187 | |
|---|
| 1201 | 1188 | if (sdhost->mrq) { |
|---|
| 1202 | 1189 | pr_err("%s: Controller removed during " |
|---|
| .. | .. |
|---|
| 1205 | 1192 | /* make sure all DMA is stopped */ |
|---|
| 1206 | 1193 | writel(VIA_CRDR_DMACTRL_SFTRST, |
|---|
| 1207 | 1194 | sdhost->ddma_mmiobase + VIA_CRDR_DMACTRL); |
|---|
| 1208 | | - mmiowb(); |
|---|
| 1209 | 1195 | sdhost->mrq->cmd->error = -ENOMEDIUM; |
|---|
| 1210 | 1196 | if (sdhost->mrq->stop) |
|---|
| 1211 | 1197 | sdhost->mrq->stop->error = -ENOMEDIUM; |
|---|
| .. | .. |
|---|
| 1237 | 1223 | pci_name(pcidev), (int)pcidev->vendor, (int)pcidev->device); |
|---|
| 1238 | 1224 | } |
|---|
| 1239 | 1225 | |
|---|
| 1240 | | -#ifdef CONFIG_PM |
|---|
| 1241 | | - |
|---|
| 1242 | | -static void via_init_sdc_pm(struct via_crdr_mmc_host *host) |
|---|
| 1226 | +static void __maybe_unused via_init_sdc_pm(struct via_crdr_mmc_host *host) |
|---|
| 1243 | 1227 | { |
|---|
| 1244 | 1228 | struct sdhcreg *pm_sdhcreg; |
|---|
| 1245 | 1229 | void __iomem *addrbase; |
|---|
| .. | .. |
|---|
| 1273 | 1257 | via_print_sdchc(host); |
|---|
| 1274 | 1258 | } |
|---|
| 1275 | 1259 | |
|---|
| 1276 | | -static int via_sd_suspend(struct pci_dev *pcidev, pm_message_t state) |
|---|
| 1260 | +static int __maybe_unused via_sd_suspend(struct device *dev) |
|---|
| 1277 | 1261 | { |
|---|
| 1278 | 1262 | struct via_crdr_mmc_host *host; |
|---|
| 1279 | 1263 | unsigned long flags; |
|---|
| 1280 | 1264 | |
|---|
| 1281 | | - host = pci_get_drvdata(pcidev); |
|---|
| 1265 | + host = dev_get_drvdata(dev); |
|---|
| 1282 | 1266 | |
|---|
| 1283 | 1267 | spin_lock_irqsave(&host->lock, flags); |
|---|
| 1284 | 1268 | via_save_pcictrlreg(host); |
|---|
| 1285 | 1269 | via_save_sdcreg(host); |
|---|
| 1286 | 1270 | spin_unlock_irqrestore(&host->lock, flags); |
|---|
| 1287 | 1271 | |
|---|
| 1288 | | - pci_save_state(pcidev); |
|---|
| 1289 | | - pci_enable_wake(pcidev, pci_choose_state(pcidev, state), 0); |
|---|
| 1290 | | - pci_disable_device(pcidev); |
|---|
| 1291 | | - pci_set_power_state(pcidev, pci_choose_state(pcidev, state)); |
|---|
| 1272 | + device_wakeup_enable(dev); |
|---|
| 1292 | 1273 | |
|---|
| 1293 | 1274 | return 0; |
|---|
| 1294 | 1275 | } |
|---|
| 1295 | 1276 | |
|---|
| 1296 | | -static int via_sd_resume(struct pci_dev *pcidev) |
|---|
| 1277 | +static int __maybe_unused via_sd_resume(struct device *dev) |
|---|
| 1297 | 1278 | { |
|---|
| 1298 | 1279 | struct via_crdr_mmc_host *sdhost; |
|---|
| 1299 | 1280 | int ret = 0; |
|---|
| 1300 | 1281 | u8 gatt; |
|---|
| 1301 | 1282 | |
|---|
| 1302 | | - sdhost = pci_get_drvdata(pcidev); |
|---|
| 1283 | + sdhost = dev_get_drvdata(dev); |
|---|
| 1303 | 1284 | |
|---|
| 1304 | 1285 | gatt = VIA_CRDR_PCICLKGATT_PAD_PWRON; |
|---|
| 1305 | 1286 | if (sdhost->power == MMC_VDD_165_195) |
|---|
| .. | .. |
|---|
| 1314 | 1295 | |
|---|
| 1315 | 1296 | msleep(100); |
|---|
| 1316 | 1297 | |
|---|
| 1317 | | - pci_set_power_state(pcidev, PCI_D0); |
|---|
| 1318 | | - pci_restore_state(pcidev); |
|---|
| 1319 | | - ret = pci_enable_device(pcidev); |
|---|
| 1320 | | - if (ret) |
|---|
| 1321 | | - return ret; |
|---|
| 1322 | | - |
|---|
| 1323 | 1298 | via_restore_pcictrlreg(sdhost); |
|---|
| 1324 | 1299 | via_init_sdc_pm(sdhost); |
|---|
| 1325 | 1300 | |
|---|
| 1326 | 1301 | return ret; |
|---|
| 1327 | 1302 | } |
|---|
| 1328 | 1303 | |
|---|
| 1329 | | -#else /* CONFIG_PM */ |
|---|
| 1330 | | - |
|---|
| 1331 | | -#define via_sd_suspend NULL |
|---|
| 1332 | | -#define via_sd_resume NULL |
|---|
| 1333 | | - |
|---|
| 1334 | | -#endif /* CONFIG_PM */ |
|---|
| 1304 | +static SIMPLE_DEV_PM_OPS(via_sd_pm_ops, via_sd_suspend, via_sd_resume); |
|---|
| 1335 | 1305 | |
|---|
| 1336 | 1306 | static struct pci_driver via_sd_driver = { |
|---|
| 1337 | 1307 | .name = DRV_NAME, |
|---|
| 1338 | 1308 | .id_table = via_ids, |
|---|
| 1339 | 1309 | .probe = via_sd_probe, |
|---|
| 1340 | 1310 | .remove = via_sd_remove, |
|---|
| 1341 | | - .suspend = via_sd_suspend, |
|---|
| 1342 | | - .resume = via_sd_resume, |
|---|
| 1311 | + .driver.pm = &via_sd_pm_ops, |
|---|
| 1343 | 1312 | }; |
|---|
| 1344 | 1313 | |
|---|
| 1345 | 1314 | module_pci_driver(via_sd_driver); |
|---|