hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/staging/rts5208/rtsx.c
....@@ -1,19 +1,8 @@
1
-/* Driver for Realtek PCI-Express card reader
1
+// SPDX-License-Identifier: GPL-2.0+
2
+/*
3
+ * Driver for Realtek PCI-Express card reader
24 *
35 * 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/>.
176 *
187 * Author:
198 * Wei WANG (wei_wang@realsil.com.cn)
....@@ -237,12 +226,6 @@
237226 /* limit the total size of a transfer to 120 KB */
238227 .max_sectors = 240,
239228
240
- /* merge commands... this seems to help performance, but
241
- * periodically someone should test to see which setting is more
242
- * optimal.
243
- */
244
- .use_clustering = 1,
245
-
246229 /* emulated HBA */
247230 .emulated = 1,
248231
....@@ -275,12 +258,12 @@
275258 return 0;
276259 }
277260
278
-#ifdef CONFIG_PM
279261 /*
280262 * power management
281263 */
282
-static int rtsx_suspend(struct pci_dev *pci, pm_message_t state)
264
+static int __maybe_unused rtsx_suspend(struct device *dev_d)
283265 {
266
+ struct pci_dev *pci = to_pci_dev(dev_d);
284267 struct rtsx_dev *dev = pci_get_drvdata(pci);
285268 struct rtsx_chip *chip;
286269
....@@ -300,12 +283,9 @@
300283 }
301284
302285 if (chip->msi_en)
303
- pci_disable_msi(pci);
286
+ pci_free_irq_vectors(pci);
304287
305
- pci_save_state(pci);
306
- pci_enable_wake(pci, pci_choose_state(pci, state), 1);
307
- pci_disable_device(pci);
308
- pci_set_power_state(pci, pci_choose_state(pci, state));
288
+ device_wakeup_enable(dev_d);
309289
310290 /* unlock the device pointers */
311291 mutex_unlock(&dev->dev_mutex);
....@@ -313,8 +293,9 @@
313293 return 0;
314294 }
315295
316
-static int rtsx_resume(struct pci_dev *pci)
296
+static int __maybe_unused rtsx_resume(struct device *dev_d)
317297 {
298
+ struct pci_dev *pci = to_pci_dev(dev_d);
318299 struct rtsx_dev *dev = pci_get_drvdata(pci);
319300 struct rtsx_chip *chip;
320301
....@@ -326,20 +307,10 @@
326307 /* lock the device pointers */
327308 mutex_lock(&dev->dev_mutex);
328309
329
- pci_set_power_state(pci, PCI_D0);
330
- pci_restore_state(pci);
331
- if (pci_enable_device(pci) < 0) {
332
- dev_err(&dev->pci->dev,
333
- "%s: pci_enable_device failed, disabling device\n",
334
- CR_DRIVER_NAME);
335
- /* unlock the device pointers */
336
- mutex_unlock(&dev->dev_mutex);
337
- return -EIO;
338
- }
339310 pci_set_master(pci);
340311
341312 if (chip->msi_en) {
342
- if (pci_enable_msi(pci) < 0)
313
+ if (pci_alloc_irq_vectors(pci, 1, 1, PCI_IRQ_MSI) < 0)
343314 chip->msi_en = 0;
344315 }
345316
....@@ -357,7 +328,6 @@
357328
358329 return 0;
359330 }
360
-#endif /* CONFIG_PM */
361331
362332 static void rtsx_shutdown(struct pci_dev *pci)
363333 {
....@@ -377,7 +347,7 @@
377347 }
378348
379349 if (chip->msi_en)
380
- pci_disable_msi(pci);
350
+ pci_free_irq_vectors(pci);
381351
382352 pci_disable_device(pci);
383353 }
....@@ -624,7 +594,7 @@
624594 if (dev->irq > 0)
625595 free_irq(dev->irq, (void *)dev);
626596 if (dev->chip->msi_en)
627
- pci_disable_msi(dev->pci);
597
+ pci_free_irq_vectors(dev->pci);
628598 if (dev->remap_addr)
629599 iounmap(dev->remap_addr);
630600
....@@ -848,7 +818,8 @@
848818 host = scsi_host_alloc(&rtsx_host_template, sizeof(*dev));
849819 if (!host) {
850820 dev_err(&pci->dev, "Unable to allocate the scsi host\n");
851
- return -ENOMEM;
821
+ err = -ENOMEM;
822
+ goto scsi_host_alloc_fail;
852823 }
853824
854825 dev = host_to_rtsx(host);
....@@ -875,7 +846,7 @@
875846 dev_info(&pci->dev, "Resource length: 0x%x\n",
876847 (unsigned int)pci_resource_len(pci, 0));
877848 dev->addr = pci_resource_start(pci, 0);
878
- dev->remap_addr = ioremap_nocache(dev->addr, pci_resource_len(pci, 0));
849
+ dev->remap_addr = ioremap(dev->addr, pci_resource_len(pci, 0));
879850 if (!dev->remap_addr) {
880851 dev_err(&pci->dev, "ioremap error\n");
881852 err = -ENXIO;
....@@ -890,7 +861,8 @@
890861 (unsigned long)(dev->addr), (unsigned long)(dev->remap_addr));
891862
892863 dev->rtsx_resv_buf = dmam_alloc_coherent(&pci->dev, RTSX_RESV_BUF_LEN,
893
- &dev->rtsx_resv_buf_addr, GFP_KERNEL);
864
+ &dev->rtsx_resv_buf_addr,
865
+ GFP_KERNEL);
894866 if (!dev->rtsx_resv_buf) {
895867 dev_err(&pci->dev, "alloc dma buffer fail\n");
896868 err = -ENXIO;
....@@ -909,7 +881,7 @@
909881 dev_info(&pci->dev, "pci->irq = %d\n", pci->irq);
910882
911883 if (dev->chip->msi_en) {
912
- if (pci_enable_msi(pci) < 0)
884
+ if (pci_alloc_irq_vectors(pci, 1, 1, PCI_IRQ_MSI) < 0)
913885 dev->chip->msi_en = 0;
914886 }
915887
....@@ -980,14 +952,16 @@
980952 dev->chip->host_cmds_ptr = NULL;
981953 dev->chip->host_sg_tbl_ptr = NULL;
982954 if (dev->chip->msi_en)
983
- pci_disable_msi(dev->pci);
955
+ pci_free_irq_vectors(dev->pci);
984956 dma_alloc_fail:
985957 iounmap(dev->remap_addr);
986958 ioremap_fail:
987959 kfree(dev->chip);
988960 chip_alloc_fail:
989961 dev_err(&pci->dev, "%s failed\n", __func__);
990
-
962
+ scsi_host_put(host);
963
+scsi_host_alloc_fail:
964
+ pci_release_regions(pci);
991965 return err;
992966 }
993967
....@@ -999,6 +973,7 @@
999973
1000974 quiesce_and_remove_host(dev);
1001975 release_everything(dev);
976
+ pci_release_regions(pci);
1002977 }
1003978
1004979 /* PCI IDs */
....@@ -1012,16 +987,15 @@
1012987
1013988 MODULE_DEVICE_TABLE(pci, rtsx_ids);
1014989
990
+static SIMPLE_DEV_PM_OPS(rtsx_pm_ops, rtsx_suspend, rtsx_resume);
991
+
1015992 /* pci_driver definition */
1016993 static struct pci_driver rtsx_driver = {
1017994 .name = CR_DRIVER_NAME,
1018995 .id_table = rtsx_ids,
1019996 .probe = rtsx_probe,
1020997 .remove = rtsx_remove,
1021
-#ifdef CONFIG_PM
1022
- .suspend = rtsx_suspend,
1023
- .resume = rtsx_resume,
1024
-#endif
998
+ .driver.pm = &rtsx_pm_ops,
1025999 .shutdown = rtsx_shutdown,
10261000 };
10271001