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 struct ufs_hba_variant_ops ufs_intel_cnl_hba_vops = {
49 .link_startup_notify = ufs_intel_link_startup_notify,
52 #ifdef CONFIG_PM_SLEEP
54 * ufshcd_pci_suspend - suspend power management function
55 * @dev: pointer to PCI device handle
57 * Returns 0 if successful
58 * Returns non-zero otherwise
60 static int ufshcd_pci_suspend(struct device *dev)
62 return ufshcd_system_suspend(dev_get_drvdata(dev));
66 * ufshcd_pci_resume - resume 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_resume(struct device *dev)
74 return ufshcd_system_resume(dev_get_drvdata(dev));
76 #endif /* !CONFIG_PM_SLEEP */
79 static int ufshcd_pci_runtime_suspend(struct device *dev)
81 return ufshcd_runtime_suspend(dev_get_drvdata(dev));
83 static int ufshcd_pci_runtime_resume(struct device *dev)
85 return ufshcd_runtime_resume(dev_get_drvdata(dev));
87 static int ufshcd_pci_runtime_idle(struct device *dev)
89 return ufshcd_runtime_idle(dev_get_drvdata(dev));
91 #endif /* !CONFIG_PM */
94 * ufshcd_pci_shutdown - main function to put the controller in reset state
95 * @pdev: pointer to PCI device handle
97 static void ufshcd_pci_shutdown(struct pci_dev *pdev)
99 ufshcd_shutdown((struct ufs_hba *)pci_get_drvdata(pdev));
103 * ufshcd_pci_remove - de-allocate PCI/SCSI host and host memory space
104 * data structure memory
105 * @pdev: pointer to PCI handle
107 static void ufshcd_pci_remove(struct pci_dev *pdev)
109 struct ufs_hba *hba = pci_get_drvdata(pdev);
111 pm_runtime_forbid(&pdev->dev);
112 pm_runtime_get_noresume(&pdev->dev);
114 ufshcd_dealloc_host(hba);
118 * ufshcd_pci_probe - probe routine of the driver
119 * @pdev: pointer to PCI device handle
122 * Returns 0 on success, non-zero value on failure
125 ufshcd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
128 void __iomem *mmio_base;
131 err = pcim_enable_device(pdev);
133 dev_err(&pdev->dev, "pcim_enable_device failed\n");
137 pci_set_master(pdev);
139 err = pcim_iomap_regions(pdev, 1 << 0, UFSHCD);
141 dev_err(&pdev->dev, "request and iomap failed\n");
145 mmio_base = pcim_iomap_table(pdev)[0];
147 err = ufshcd_alloc_host(&pdev->dev, &hba);
149 dev_err(&pdev->dev, "Allocation failed\n");
153 hba->vops = (struct ufs_hba_variant_ops *)id->driver_data;
155 err = ufshcd_init(hba, mmio_base, pdev->irq);
157 dev_err(&pdev->dev, "Initialization failed\n");
158 ufshcd_dealloc_host(hba);
162 pci_set_drvdata(pdev, hba);
163 pm_runtime_put_noidle(&pdev->dev);
164 pm_runtime_allow(&pdev->dev);
169 static const struct dev_pm_ops ufshcd_pci_pm_ops = {
170 SET_SYSTEM_SLEEP_PM_OPS(ufshcd_pci_suspend,
172 SET_RUNTIME_PM_OPS(ufshcd_pci_runtime_suspend,
173 ufshcd_pci_runtime_resume,
174 ufshcd_pci_runtime_idle)
177 static const struct pci_device_id ufshcd_pci_tbl[] = {
178 { PCI_VENDOR_ID_SAMSUNG, 0xC00C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
179 { PCI_VDEVICE(INTEL, 0x9DFA), (kernel_ulong_t)&ufs_intel_cnl_hba_vops },
180 { PCI_VDEVICE(INTEL, 0x4B41), (kernel_ulong_t)&ufs_intel_cnl_hba_vops },
181 { PCI_VDEVICE(INTEL, 0x4B43), (kernel_ulong_t)&ufs_intel_cnl_hba_vops },
182 { } /* terminate list */
185 MODULE_DEVICE_TABLE(pci, ufshcd_pci_tbl);
187 static struct pci_driver ufshcd_pci_driver = {
189 .id_table = ufshcd_pci_tbl,
190 .probe = ufshcd_pci_probe,
191 .remove = ufshcd_pci_remove,
192 .shutdown = ufshcd_pci_shutdown,
194 .pm = &ufshcd_pci_pm_ops
198 module_pci_driver(ufshcd_pci_driver);
200 MODULE_AUTHOR("Santosh Yaragnavi <santosh.sy@samsung.com>");
201 MODULE_AUTHOR("Vinayak Holikatti <h.vinayak@samsung.com>");
202 MODULE_DESCRIPTION("UFS host controller PCI glue driver");
203 MODULE_LICENSE("GPL");
204 MODULE_VERSION(UFSHCD_DRIVER_VERSION);