Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Universal Flash Storage Host controller PCI glue driver |
| 3 | * |
| 4 | * This code is based on drivers/scsi/ufs/ufshcd-pci.c |
| 5 | * Copyright (C) 2011-2013 Samsung India Software Operations |
| 6 | * |
| 7 | * Authors: |
| 8 | * Santosh Yaraganavi <santosh.sy@samsung.com> |
| 9 | * Vinayak Holikatti <h.vinayak@samsung.com> |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License |
| 13 | * as published by the Free Software Foundation; either version 2 |
| 14 | * of the License, or (at your option) any later version. |
| 15 | * See the COPYING file in the top-level directory or visit |
| 16 | * <http://www.gnu.org/licenses/gpl-2.0.html> |
| 17 | * |
| 18 | * This program is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | * GNU General Public License for more details. |
| 22 | * |
| 23 | * This program is provided "AS IS" and "WITH ALL FAULTS" and |
| 24 | * without warranty of any kind. You are solely responsible for |
| 25 | * determining the appropriateness of using and distributing |
| 26 | * the program and assume all risks associated with your exercise |
| 27 | * of rights with respect to the program, including but not limited |
| 28 | * to infringement of third party rights, the risks and costs of |
| 29 | * program errors, damage to or loss of data, programs or equipment, |
| 30 | * and unavailability or interruption of operations. Under no |
| 31 | * circumstances will the contributor of this Program be liable for |
| 32 | * any damages of any kind arising from your use or distribution of |
| 33 | * this program. |
| 34 | */ |
| 35 | |
| 36 | #include "ufshcd.h" |
| 37 | #include <linux/pci.h> |
Sujit Reddy Thumma | 6269473 | 2013-07-30 00:36:00 +0530 | [diff] [blame] | 38 | #include <linux/pm_runtime.h> |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 39 | |
| 40 | #ifdef CONFIG_PM |
| 41 | /** |
| 42 | * ufshcd_pci_suspend - suspend power management function |
| 43 | * @pdev: pointer to PCI device handle |
| 44 | * @state: power state |
| 45 | * |
Subhash Jadavani | 57d104c | 2014-09-25 15:32:30 +0300 | [diff] [blame] | 46 | * Returns 0 if successful |
| 47 | * Returns non-zero otherwise |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 48 | */ |
Sujit Reddy Thumma | 6269473 | 2013-07-30 00:36:00 +0530 | [diff] [blame] | 49 | static int ufshcd_pci_suspend(struct device *dev) |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 50 | { |
Subhash Jadavani | 57d104c | 2014-09-25 15:32:30 +0300 | [diff] [blame] | 51 | return ufshcd_system_suspend(dev_get_drvdata(dev)); |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | /** |
| 55 | * ufshcd_pci_resume - resume power management function |
| 56 | * @pdev: pointer to PCI device handle |
| 57 | * |
Subhash Jadavani | 57d104c | 2014-09-25 15:32:30 +0300 | [diff] [blame] | 58 | * Returns 0 if successful |
| 59 | * Returns non-zero otherwise |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 60 | */ |
Sujit Reddy Thumma | 6269473 | 2013-07-30 00:36:00 +0530 | [diff] [blame] | 61 | static int ufshcd_pci_resume(struct device *dev) |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 62 | { |
Subhash Jadavani | 57d104c | 2014-09-25 15:32:30 +0300 | [diff] [blame] | 63 | return ufshcd_system_resume(dev_get_drvdata(dev)); |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 64 | } |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 65 | |
Sujit Reddy Thumma | 6269473 | 2013-07-30 00:36:00 +0530 | [diff] [blame] | 66 | static int ufshcd_pci_runtime_suspend(struct device *dev) |
| 67 | { |
Subhash Jadavani | 57d104c | 2014-09-25 15:32:30 +0300 | [diff] [blame] | 68 | return ufshcd_runtime_suspend(dev_get_drvdata(dev)); |
Sujit Reddy Thumma | 6269473 | 2013-07-30 00:36:00 +0530 | [diff] [blame] | 69 | } |
| 70 | static int ufshcd_pci_runtime_resume(struct device *dev) |
| 71 | { |
Subhash Jadavani | 57d104c | 2014-09-25 15:32:30 +0300 | [diff] [blame] | 72 | return ufshcd_runtime_resume(dev_get_drvdata(dev)); |
Sujit Reddy Thumma | 6269473 | 2013-07-30 00:36:00 +0530 | [diff] [blame] | 73 | } |
| 74 | static int ufshcd_pci_runtime_idle(struct device *dev) |
| 75 | { |
Subhash Jadavani | 57d104c | 2014-09-25 15:32:30 +0300 | [diff] [blame] | 76 | return ufshcd_runtime_idle(dev_get_drvdata(dev)); |
Sujit Reddy Thumma | 6269473 | 2013-07-30 00:36:00 +0530 | [diff] [blame] | 77 | } |
Rafael J. Wysocki | 4f7ad52 | 2014-12-14 23:13:55 +0100 | [diff] [blame] | 78 | #else /* !CONFIG_PM */ |
| 79 | #define ufshcd_pci_suspend NULL |
| 80 | #define ufshcd_pci_resume NULL |
Sujit Reddy Thumma | 6269473 | 2013-07-30 00:36:00 +0530 | [diff] [blame] | 81 | #define ufshcd_pci_runtime_suspend NULL |
| 82 | #define ufshcd_pci_runtime_resume NULL |
| 83 | #define ufshcd_pci_runtime_idle NULL |
Rafael J. Wysocki | 4f7ad52 | 2014-12-14 23:13:55 +0100 | [diff] [blame] | 84 | #endif /* CONFIG_PM */ |
Sujit Reddy Thumma | 6269473 | 2013-07-30 00:36:00 +0530 | [diff] [blame] | 85 | |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 86 | /** |
| 87 | * ufshcd_pci_shutdown - main function to put the controller in reset state |
| 88 | * @pdev: pointer to PCI device handle |
| 89 | */ |
| 90 | static void ufshcd_pci_shutdown(struct pci_dev *pdev) |
| 91 | { |
Subhash Jadavani | 57d104c | 2014-09-25 15:32:30 +0300 | [diff] [blame] | 92 | ufshcd_shutdown((struct ufs_hba *)pci_get_drvdata(pdev)); |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | /** |
| 96 | * ufshcd_pci_remove - de-allocate PCI/SCSI host and host memory space |
| 97 | * data structure memory |
| 98 | * @pdev - pointer to PCI handle |
| 99 | */ |
| 100 | static void ufshcd_pci_remove(struct pci_dev *pdev) |
| 101 | { |
| 102 | struct ufs_hba *hba = pci_get_drvdata(pdev); |
| 103 | |
Sujit Reddy Thumma | 6269473 | 2013-07-30 00:36:00 +0530 | [diff] [blame] | 104 | pm_runtime_forbid(&pdev->dev); |
| 105 | pm_runtime_get_noresume(&pdev->dev); |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 106 | ufshcd_remove(hba); |
Subhash Jadavani | afa3dfd | 2016-10-27 17:25:58 -0700 | [diff] [blame] | 107 | ufshcd_dealloc_host(hba); |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | /** |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 111 | * ufshcd_pci_probe - probe routine of the driver |
| 112 | * @pdev: pointer to PCI device handle |
| 113 | * @id: PCI device id |
| 114 | * |
| 115 | * Returns 0 on success, non-zero value on failure |
| 116 | */ |
| 117 | static int |
| 118 | ufshcd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) |
| 119 | { |
| 120 | struct ufs_hba *hba; |
| 121 | void __iomem *mmio_base; |
| 122 | int err; |
| 123 | |
Akinobu Mita | 36f4f3b | 2013-07-30 00:36:01 +0530 | [diff] [blame] | 124 | err = pcim_enable_device(pdev); |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 125 | if (err) { |
Akinobu Mita | 36f4f3b | 2013-07-30 00:36:01 +0530 | [diff] [blame] | 126 | dev_err(&pdev->dev, "pcim_enable_device failed\n"); |
| 127 | return err; |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | pci_set_master(pdev); |
| 131 | |
Akinobu Mita | 36f4f3b | 2013-07-30 00:36:01 +0530 | [diff] [blame] | 132 | err = pcim_iomap_regions(pdev, 1 << 0, UFSHCD); |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 133 | if (err < 0) { |
Akinobu Mita | 36f4f3b | 2013-07-30 00:36:01 +0530 | [diff] [blame] | 134 | dev_err(&pdev->dev, "request and iomap failed\n"); |
| 135 | return err; |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 136 | } |
| 137 | |
Akinobu Mita | 36f4f3b | 2013-07-30 00:36:01 +0530 | [diff] [blame] | 138 | mmio_base = pcim_iomap_table(pdev)[0]; |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 139 | |
Sujit Reddy Thumma | 5c0c28a | 2014-09-25 15:32:21 +0300 | [diff] [blame] | 140 | err = ufshcd_alloc_host(&pdev->dev, &hba); |
| 141 | if (err) { |
| 142 | dev_err(&pdev->dev, "Allocation failed\n"); |
| 143 | return err; |
| 144 | } |
| 145 | |
Sujit Reddy Thumma | c6e79da | 2014-09-25 15:32:23 +0300 | [diff] [blame] | 146 | INIT_LIST_HEAD(&hba->clk_list_head); |
| 147 | |
Sujit Reddy Thumma | 5c0c28a | 2014-09-25 15:32:21 +0300 | [diff] [blame] | 148 | err = ufshcd_init(hba, mmio_base, pdev->irq); |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 149 | if (err) { |
| 150 | dev_err(&pdev->dev, "Initialization failed\n"); |
Subhash Jadavani | afa3dfd | 2016-10-27 17:25:58 -0700 | [diff] [blame] | 151 | ufshcd_dealloc_host(hba); |
Akinobu Mita | 36f4f3b | 2013-07-30 00:36:01 +0530 | [diff] [blame] | 152 | return err; |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | pci_set_drvdata(pdev, hba); |
Sujit Reddy Thumma | 6269473 | 2013-07-30 00:36:00 +0530 | [diff] [blame] | 156 | pm_runtime_put_noidle(&pdev->dev); |
| 157 | pm_runtime_allow(&pdev->dev); |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 158 | |
| 159 | return 0; |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 160 | } |
| 161 | |
Sujit Reddy Thumma | 6269473 | 2013-07-30 00:36:00 +0530 | [diff] [blame] | 162 | static const struct dev_pm_ops ufshcd_pci_pm_ops = { |
| 163 | .suspend = ufshcd_pci_suspend, |
| 164 | .resume = ufshcd_pci_resume, |
| 165 | .runtime_suspend = ufshcd_pci_runtime_suspend, |
| 166 | .runtime_resume = ufshcd_pci_runtime_resume, |
| 167 | .runtime_idle = ufshcd_pci_runtime_idle, |
| 168 | }; |
| 169 | |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 170 | static const struct pci_device_id ufshcd_pci_tbl[] = { |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 171 | { PCI_VENDOR_ID_SAMSUNG, 0xC00C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, |
| 172 | { } /* terminate list */ |
| 173 | }; |
| 174 | |
| 175 | MODULE_DEVICE_TABLE(pci, ufshcd_pci_tbl); |
| 176 | |
| 177 | static struct pci_driver ufshcd_pci_driver = { |
| 178 | .name = UFSHCD, |
| 179 | .id_table = ufshcd_pci_tbl, |
| 180 | .probe = ufshcd_pci_probe, |
| 181 | .remove = ufshcd_pci_remove, |
| 182 | .shutdown = ufshcd_pci_shutdown, |
Sujit Reddy Thumma | 6269473 | 2013-07-30 00:36:00 +0530 | [diff] [blame] | 183 | .driver = { |
| 184 | .pm = &ufshcd_pci_pm_ops |
| 185 | }, |
Vinayak Holikatti | e0eca63 | 2013-02-25 21:44:33 +0530 | [diff] [blame] | 186 | }; |
| 187 | |
| 188 | module_pci_driver(ufshcd_pci_driver); |
| 189 | |
| 190 | MODULE_AUTHOR("Santosh Yaragnavi <santosh.sy@samsung.com>"); |
| 191 | MODULE_AUTHOR("Vinayak Holikatti <h.vinayak@samsung.com>"); |
| 192 | MODULE_DESCRIPTION("UFS host controller PCI glue driver"); |
| 193 | MODULE_LICENSE("GPL"); |
| 194 | MODULE_VERSION(UFSHCD_DRIVER_VERSION); |