.. | .. |
---|
1 | | -/* Driver for Realtek PCI-Express card reader |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0+ |
---|
| 2 | +/* |
---|
| 3 | + * Driver for Realtek PCI-Express card reader |
---|
2 | 4 | * |
---|
3 | 5 | * 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/>. |
---|
17 | 6 | * |
---|
18 | 7 | * Author: |
---|
19 | 8 | * Wei WANG (wei_wang@realsil.com.cn) |
---|
.. | .. |
---|
237 | 226 | /* limit the total size of a transfer to 120 KB */ |
---|
238 | 227 | .max_sectors = 240, |
---|
239 | 228 | |
---|
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 | | - |
---|
246 | 229 | /* emulated HBA */ |
---|
247 | 230 | .emulated = 1, |
---|
248 | 231 | |
---|
.. | .. |
---|
275 | 258 | return 0; |
---|
276 | 259 | } |
---|
277 | 260 | |
---|
278 | | -#ifdef CONFIG_PM |
---|
279 | 261 | /* |
---|
280 | 262 | * power management |
---|
281 | 263 | */ |
---|
282 | | -static int rtsx_suspend(struct pci_dev *pci, pm_message_t state) |
---|
| 264 | +static int __maybe_unused rtsx_suspend(struct device *dev_d) |
---|
283 | 265 | { |
---|
| 266 | + struct pci_dev *pci = to_pci_dev(dev_d); |
---|
284 | 267 | struct rtsx_dev *dev = pci_get_drvdata(pci); |
---|
285 | 268 | struct rtsx_chip *chip; |
---|
286 | 269 | |
---|
.. | .. |
---|
300 | 283 | } |
---|
301 | 284 | |
---|
302 | 285 | if (chip->msi_en) |
---|
303 | | - pci_disable_msi(pci); |
---|
| 286 | + pci_free_irq_vectors(pci); |
---|
304 | 287 | |
---|
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); |
---|
309 | 289 | |
---|
310 | 290 | /* unlock the device pointers */ |
---|
311 | 291 | mutex_unlock(&dev->dev_mutex); |
---|
.. | .. |
---|
313 | 293 | return 0; |
---|
314 | 294 | } |
---|
315 | 295 | |
---|
316 | | -static int rtsx_resume(struct pci_dev *pci) |
---|
| 296 | +static int __maybe_unused rtsx_resume(struct device *dev_d) |
---|
317 | 297 | { |
---|
| 298 | + struct pci_dev *pci = to_pci_dev(dev_d); |
---|
318 | 299 | struct rtsx_dev *dev = pci_get_drvdata(pci); |
---|
319 | 300 | struct rtsx_chip *chip; |
---|
320 | 301 | |
---|
.. | .. |
---|
326 | 307 | /* lock the device pointers */ |
---|
327 | 308 | mutex_lock(&dev->dev_mutex); |
---|
328 | 309 | |
---|
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 | | - } |
---|
339 | 310 | pci_set_master(pci); |
---|
340 | 311 | |
---|
341 | 312 | if (chip->msi_en) { |
---|
342 | | - if (pci_enable_msi(pci) < 0) |
---|
| 313 | + if (pci_alloc_irq_vectors(pci, 1, 1, PCI_IRQ_MSI) < 0) |
---|
343 | 314 | chip->msi_en = 0; |
---|
344 | 315 | } |
---|
345 | 316 | |
---|
.. | .. |
---|
357 | 328 | |
---|
358 | 329 | return 0; |
---|
359 | 330 | } |
---|
360 | | -#endif /* CONFIG_PM */ |
---|
361 | 331 | |
---|
362 | 332 | static void rtsx_shutdown(struct pci_dev *pci) |
---|
363 | 333 | { |
---|
.. | .. |
---|
377 | 347 | } |
---|
378 | 348 | |
---|
379 | 349 | if (chip->msi_en) |
---|
380 | | - pci_disable_msi(pci); |
---|
| 350 | + pci_free_irq_vectors(pci); |
---|
381 | 351 | |
---|
382 | 352 | pci_disable_device(pci); |
---|
383 | 353 | } |
---|
.. | .. |
---|
624 | 594 | if (dev->irq > 0) |
---|
625 | 595 | free_irq(dev->irq, (void *)dev); |
---|
626 | 596 | if (dev->chip->msi_en) |
---|
627 | | - pci_disable_msi(dev->pci); |
---|
| 597 | + pci_free_irq_vectors(dev->pci); |
---|
628 | 598 | if (dev->remap_addr) |
---|
629 | 599 | iounmap(dev->remap_addr); |
---|
630 | 600 | |
---|
.. | .. |
---|
848 | 818 | host = scsi_host_alloc(&rtsx_host_template, sizeof(*dev)); |
---|
849 | 819 | if (!host) { |
---|
850 | 820 | dev_err(&pci->dev, "Unable to allocate the scsi host\n"); |
---|
851 | | - return -ENOMEM; |
---|
| 821 | + err = -ENOMEM; |
---|
| 822 | + goto scsi_host_alloc_fail; |
---|
852 | 823 | } |
---|
853 | 824 | |
---|
854 | 825 | dev = host_to_rtsx(host); |
---|
.. | .. |
---|
875 | 846 | dev_info(&pci->dev, "Resource length: 0x%x\n", |
---|
876 | 847 | (unsigned int)pci_resource_len(pci, 0)); |
---|
877 | 848 | 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)); |
---|
879 | 850 | if (!dev->remap_addr) { |
---|
880 | 851 | dev_err(&pci->dev, "ioremap error\n"); |
---|
881 | 852 | err = -ENXIO; |
---|
.. | .. |
---|
890 | 861 | (unsigned long)(dev->addr), (unsigned long)(dev->remap_addr)); |
---|
891 | 862 | |
---|
892 | 863 | 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); |
---|
894 | 866 | if (!dev->rtsx_resv_buf) { |
---|
895 | 867 | dev_err(&pci->dev, "alloc dma buffer fail\n"); |
---|
896 | 868 | err = -ENXIO; |
---|
.. | .. |
---|
909 | 881 | dev_info(&pci->dev, "pci->irq = %d\n", pci->irq); |
---|
910 | 882 | |
---|
911 | 883 | 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) |
---|
913 | 885 | dev->chip->msi_en = 0; |
---|
914 | 886 | } |
---|
915 | 887 | |
---|
.. | .. |
---|
980 | 952 | dev->chip->host_cmds_ptr = NULL; |
---|
981 | 953 | dev->chip->host_sg_tbl_ptr = NULL; |
---|
982 | 954 | if (dev->chip->msi_en) |
---|
983 | | - pci_disable_msi(dev->pci); |
---|
| 955 | + pci_free_irq_vectors(dev->pci); |
---|
984 | 956 | dma_alloc_fail: |
---|
985 | 957 | iounmap(dev->remap_addr); |
---|
986 | 958 | ioremap_fail: |
---|
987 | 959 | kfree(dev->chip); |
---|
988 | 960 | chip_alloc_fail: |
---|
989 | 961 | dev_err(&pci->dev, "%s failed\n", __func__); |
---|
990 | | - |
---|
| 962 | + scsi_host_put(host); |
---|
| 963 | +scsi_host_alloc_fail: |
---|
| 964 | + pci_release_regions(pci); |
---|
991 | 965 | return err; |
---|
992 | 966 | } |
---|
993 | 967 | |
---|
.. | .. |
---|
999 | 973 | |
---|
1000 | 974 | quiesce_and_remove_host(dev); |
---|
1001 | 975 | release_everything(dev); |
---|
| 976 | + pci_release_regions(pci); |
---|
1002 | 977 | } |
---|
1003 | 978 | |
---|
1004 | 979 | /* PCI IDs */ |
---|
.. | .. |
---|
1012 | 987 | |
---|
1013 | 988 | MODULE_DEVICE_TABLE(pci, rtsx_ids); |
---|
1014 | 989 | |
---|
| 990 | +static SIMPLE_DEV_PM_OPS(rtsx_pm_ops, rtsx_suspend, rtsx_resume); |
---|
| 991 | + |
---|
1015 | 992 | /* pci_driver definition */ |
---|
1016 | 993 | static struct pci_driver rtsx_driver = { |
---|
1017 | 994 | .name = CR_DRIVER_NAME, |
---|
1018 | 995 | .id_table = rtsx_ids, |
---|
1019 | 996 | .probe = rtsx_probe, |
---|
1020 | 997 | .remove = rtsx_remove, |
---|
1021 | | -#ifdef CONFIG_PM |
---|
1022 | | - .suspend = rtsx_suspend, |
---|
1023 | | - .resume = rtsx_resume, |
---|
1024 | | -#endif |
---|
| 998 | + .driver.pm = &rtsx_pm_ops, |
---|
1025 | 999 | .shutdown = rtsx_shutdown, |
---|
1026 | 1000 | }; |
---|
1027 | 1001 | |
---|