Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Sonics Silicon Backplane |
| 3 | * PCI Hostdevice wrapper |
| 4 | * |
| 5 | * Copyright (c) 2005 Martin Langer <martin-langer@gmx.de> |
| 6 | * Copyright (c) 2005 Stefano Brivio <st3@riseup.net> |
| 7 | * Copyright (c) 2005 Danny van Dyk <kugelfang@gentoo.org> |
| 8 | * Copyright (c) 2005 Andreas Jaggi <andreas.jaggi@waterwave.ch> |
Michael Büsch | eb032b9 | 2011-07-04 20:50:05 +0200 | [diff] [blame] | 9 | * Copyright (c) 2005-2007 Michael Buesch <m@bues.ch> |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 10 | * |
| 11 | * Licensed under the GNU/GPL. See COPYING for details. |
| 12 | */ |
| 13 | |
Andrey Skvortsov | 5580373 | 2014-12-04 11:32:46 -0500 | [diff] [blame] | 14 | #include <linux/pm.h> |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 15 | #include <linux/pci.h> |
Paul Gortmaker | 1014c22 | 2011-07-27 22:07:02 -0400 | [diff] [blame] | 16 | #include <linux/export.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 17 | #include <linux/slab.h> |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 18 | #include <linux/ssb/ssb.h> |
| 19 | |
| 20 | |
Andrey Skvortsov | 5580373 | 2014-12-04 11:32:46 -0500 | [diff] [blame] | 21 | #ifdef CONFIG_PM_SLEEP |
| 22 | static int ssb_pcihost_suspend(struct device *d) |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 23 | { |
Andrey Skvortsov | 5580373 | 2014-12-04 11:32:46 -0500 | [diff] [blame] | 24 | struct pci_dev *dev = to_pci_dev(d); |
Michael Buesch | 8fe2b65 | 2008-03-30 00:10:50 +0100 | [diff] [blame] | 25 | struct ssb_bus *ssb = pci_get_drvdata(dev); |
| 26 | int err; |
| 27 | |
| 28 | err = ssb_bus_suspend(ssb); |
| 29 | if (err) |
| 30 | return err; |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 31 | pci_save_state(dev); |
| 32 | pci_disable_device(dev); |
Andrey Skvortsov | 5580373 | 2014-12-04 11:32:46 -0500 | [diff] [blame] | 33 | |
| 34 | /* if there is a wakeup enabled child device on ssb bus, |
| 35 | enable pci wakeup posibility. */ |
| 36 | device_set_wakeup_enable(d, d->power.wakeup_path); |
| 37 | |
| 38 | pci_prepare_to_sleep(dev); |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 39 | |
| 40 | return 0; |
| 41 | } |
| 42 | |
Andrey Skvortsov | 5580373 | 2014-12-04 11:32:46 -0500 | [diff] [blame] | 43 | static int ssb_pcihost_resume(struct device *d) |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 44 | { |
Andrey Skvortsov | 5580373 | 2014-12-04 11:32:46 -0500 | [diff] [blame] | 45 | struct pci_dev *dev = to_pci_dev(d); |
Michael Buesch | 8fe2b65 | 2008-03-30 00:10:50 +0100 | [diff] [blame] | 46 | struct ssb_bus *ssb = pci_get_drvdata(dev); |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 47 | int err; |
| 48 | |
Andrey Skvortsov | 5580373 | 2014-12-04 11:32:46 -0500 | [diff] [blame] | 49 | pci_back_from_sleep(dev); |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 50 | err = pci_enable_device(dev); |
| 51 | if (err) |
| 52 | return err; |
| 53 | pci_restore_state(dev); |
Michael Buesch | 8fe2b65 | 2008-03-30 00:10:50 +0100 | [diff] [blame] | 54 | err = ssb_bus_resume(ssb); |
| 55 | if (err) |
| 56 | return err; |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 57 | |
| 58 | return 0; |
| 59 | } |
Andrey Skvortsov | 5580373 | 2014-12-04 11:32:46 -0500 | [diff] [blame] | 60 | |
| 61 | static const struct dev_pm_ops ssb_pcihost_pm_ops = { |
| 62 | SET_SYSTEM_SLEEP_PM_OPS(ssb_pcihost_suspend, ssb_pcihost_resume) |
| 63 | }; |
| 64 | |
| 65 | #endif /* CONFIG_PM_SLEEP */ |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 66 | |
Greg Kroah-Hartman | 163247c | 2012-12-21 15:10:52 -0800 | [diff] [blame] | 67 | static int ssb_pcihost_probe(struct pci_dev *dev, |
| 68 | const struct pci_device_id *id) |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 69 | { |
| 70 | struct ssb_bus *ssb; |
| 71 | int err = -ENOMEM; |
Larry Finger | e081685 | 2010-10-20 09:59:33 -0500 | [diff] [blame] | 72 | u32 val; |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 73 | |
| 74 | ssb = kzalloc(sizeof(*ssb), GFP_KERNEL); |
| 75 | if (!ssb) |
| 76 | goto out; |
| 77 | err = pci_enable_device(dev); |
| 78 | if (err) |
| 79 | goto err_kfree_ssb; |
Uwe Kleine-König | 7c3b2c9 | 2021-10-04 14:59:30 +0200 | [diff] [blame] | 80 | err = pci_request_regions(dev, dev_driver_string(&dev->dev)); |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 81 | if (err) |
| 82 | goto err_pci_disable; |
| 83 | pci_set_master(dev); |
| 84 | |
Larry Finger | e081685 | 2010-10-20 09:59:33 -0500 | [diff] [blame] | 85 | /* Disable the RETRY_TIMEOUT register (0x41) to keep |
| 86 | * PCI Tx retries from interfering with C3 CPU state */ |
| 87 | pci_read_config_dword(dev, 0x40, &val); |
| 88 | if ((val & 0x0000ff00) != 0) |
| 89 | pci_write_config_dword(dev, 0x40, val & 0xffff00ff); |
| 90 | |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 91 | err = ssb_bus_pcibus_register(ssb, dev); |
| 92 | if (err) |
| 93 | goto err_pci_release_regions; |
| 94 | |
| 95 | pci_set_drvdata(dev, ssb); |
| 96 | |
| 97 | out: |
| 98 | return err; |
| 99 | |
| 100 | err_pci_release_regions: |
| 101 | pci_release_regions(dev); |
| 102 | err_pci_disable: |
| 103 | pci_disable_device(dev); |
| 104 | err_kfree_ssb: |
| 105 | kfree(ssb); |
| 106 | return err; |
| 107 | } |
| 108 | |
| 109 | static void ssb_pcihost_remove(struct pci_dev *dev) |
| 110 | { |
| 111 | struct ssb_bus *ssb = pci_get_drvdata(dev); |
| 112 | |
| 113 | ssb_bus_unregister(ssb); |
| 114 | pci_release_regions(dev); |
| 115 | pci_disable_device(dev); |
| 116 | kfree(ssb); |
| 117 | pci_set_drvdata(dev, NULL); |
| 118 | } |
| 119 | |
Greg Kroah-Hartman | 163247c | 2012-12-21 15:10:52 -0800 | [diff] [blame] | 120 | int ssb_pcihost_register(struct pci_driver *driver) |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 121 | { |
| 122 | driver->probe = ssb_pcihost_probe; |
| 123 | driver->remove = ssb_pcihost_remove; |
Andrey Skvortsov | 5580373 | 2014-12-04 11:32:46 -0500 | [diff] [blame] | 124 | #ifdef CONFIG_PM_SLEEP |
| 125 | driver->driver.pm = &ssb_pcihost_pm_ops; |
| 126 | #endif |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 127 | |
| 128 | return pci_register_driver(driver); |
| 129 | } |
| 130 | EXPORT_SYMBOL(ssb_pcihost_register); |