1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Universal Flash Storage Host controller PCI glue driver
5 * This code is based on drivers/scsi/ufs/ufshcd-pci.c
6 * Copyright (C) 2011-2013 Samsung India Software Operations
9 * Santosh Yaraganavi <santosh.sy@samsung.com>
10 * Vinayak Holikatti <h.vinayak@samsung.com>
14 #include <linux/pci.h>
15 #include <linux/pm_runtime.h>
17 static int ufs_intel_disable_lcc(struct ufs_hba *hba)
19 u32 attr = UIC_ARG_MIB(PA_LOCAL_TX_LCC_ENABLE);
22 ufshcd_dme_get(hba, attr, &lcc_enable);
24 ufshcd_disable_host_tx_lcc(hba);
29 static int ufs_intel_link_startup_notify(struct ufs_hba *hba,
30 enum ufs_notify_change_status status)
36 err = ufs_intel_disable_lcc(hba);
47 static int ufs_intel_ehl_init(struct ufs_hba *hba)
49 hba->quirks |= UFSHCD_QUIRK_BROKEN_AUTO_HIBERN8;
53 static struct ufs_hba_variant_ops ufs_intel_cnl_hba_vops = {
55 .link_startup_notify = ufs_intel_link_startup_notify,
58 static struct ufs_hba_variant_ops ufs_intel_ehl_hba_vops = {
60 .init = ufs_intel_ehl_init,
61 .link_startup_notify = ufs_intel_link_startup_notify,
64 #ifdef CONFIG_PM_SLEEP
66 * ufshcd_pci_suspend - suspend power management function
67 * @dev: pointer to PCI device handle
69 * Returns 0 if successful
70 * Returns non-zero otherwise
72 static int ufshcd_pci_suspend(struct device *dev)
74 return ufshcd_system_suspend(dev_get_drvdata(dev));
78 * ufshcd_pci_resume - resume power management function
79 * @dev: pointer to PCI device handle
81 * Returns 0 if successful
82 * Returns non-zero otherwise
84 static int ufshcd_pci_resume(struct device *dev)
86 return ufshcd_system_resume(dev_get_drvdata(dev));
88 #endif /* !CONFIG_PM_SLEEP */
91 static int ufshcd_pci_runtime_suspend(struct device *dev)
93 return ufshcd_runtime_suspend(dev_get_drvdata(dev));
95 static int ufshcd_pci_runtime_resume(struct device *dev)
97 return ufshcd_runtime_resume(dev_get_drvdata(dev));
99 static int ufshcd_pci_runtime_idle(struct device *dev)
101 return ufshcd_runtime_idle(dev_get_drvdata(dev));
103 #endif /* !CONFIG_PM */
106 * ufshcd_pci_shutdown - main function to put the controller in reset state
107 * @pdev: pointer to PCI device handle
109 static void ufshcd_pci_shutdown(struct pci_dev *pdev)
111 ufshcd_shutdown((struct ufs_hba *)pci_get_drvdata(pdev));
115 * ufshcd_pci_remove - de-allocate PCI/SCSI host and host memory space
116 * data structure memory
117 * @pdev: pointer to PCI handle
119 static void ufshcd_pci_remove(struct pci_dev *pdev)
121 struct ufs_hba *hba = pci_get_drvdata(pdev);
123 pm_runtime_forbid(&pdev->dev);
124 pm_runtime_get_noresume(&pdev->dev);
126 ufshcd_dealloc_host(hba);
130 * ufshcd_pci_probe - probe routine of the driver
131 * @pdev: pointer to PCI device handle
134 * Returns 0 on success, non-zero value on failure
137 ufshcd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
140 void __iomem *mmio_base;
143 err = pcim_enable_device(pdev);
145 dev_err(&pdev->dev, "pcim_enable_device failed\n");
149 pci_set_master(pdev);
151 err = pcim_iomap_regions(pdev, 1 << 0, UFSHCD);
153 dev_err(&pdev->dev, "request and iomap failed\n");
157 mmio_base = pcim_iomap_table(pdev)[0];
159 err = ufshcd_alloc_host(&pdev->dev, &hba);
161 dev_err(&pdev->dev, "Allocation failed\n");
165 hba->vops = (struct ufs_hba_variant_ops *)id->driver_data;
167 err = ufshcd_init(hba, mmio_base, pdev->irq);
169 dev_err(&pdev->dev, "Initialization failed\n");
170 ufshcd_dealloc_host(hba);
174 pci_set_drvdata(pdev, hba);
175 pm_runtime_put_noidle(&pdev->dev);
176 pm_runtime_allow(&pdev->dev);
181 static const struct dev_pm_ops ufshcd_pci_pm_ops = {
182 SET_SYSTEM_SLEEP_PM_OPS(ufshcd_pci_suspend,
184 SET_RUNTIME_PM_OPS(ufshcd_pci_runtime_suspend,
185 ufshcd_pci_runtime_resume,
186 ufshcd_pci_runtime_idle)
189 static const struct pci_device_id ufshcd_pci_tbl[] = {
190 { PCI_VENDOR_ID_SAMSUNG, 0xC00C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
191 { PCI_VDEVICE(INTEL, 0x9DFA), (kernel_ulong_t)&ufs_intel_cnl_hba_vops },
192 { PCI_VDEVICE(INTEL, 0x4B41), (kernel_ulong_t)&ufs_intel_ehl_hba_vops },
193 { PCI_VDEVICE(INTEL, 0x4B43), (kernel_ulong_t)&ufs_intel_ehl_hba_vops },
194 { } /* terminate list */
197 MODULE_DEVICE_TABLE(pci, ufshcd_pci_tbl);
199 static struct pci_driver ufshcd_pci_driver = {
201 .id_table = ufshcd_pci_tbl,
202 .probe = ufshcd_pci_probe,
203 .remove = ufshcd_pci_remove,
204 .shutdown = ufshcd_pci_shutdown,
206 .pm = &ufshcd_pci_pm_ops
210 module_pci_driver(ufshcd_pci_driver);
212 MODULE_AUTHOR("Santosh Yaragnavi <santosh.sy@samsung.com>");
213 MODULE_AUTHOR("Vinayak Holikatti <h.vinayak@samsung.com>");
214 MODULE_DESCRIPTION("UFS host controller PCI glue driver");
215 MODULE_LICENSE("GPL");
216 MODULE_VERSION(UFSHCD_DRIVER_VERSION);