2 * Universal Flash Storage Host controller PCI glue driver
4 * This code is based on drivers/scsi/ufs/ufshcd-pci.c
5 * Copyright (C) 2011-2013 Samsung India Software Operations
8 * Santosh Yaraganavi <santosh.sy@samsung.com>
9 * Vinayak Holikatti <h.vinayak@samsung.com>
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>
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.
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
37 #include <linux/pci.h>
38 #include <linux/pm_runtime.h>
42 * ufshcd_pci_suspend - suspend power management function
43 * @pdev: pointer to PCI device handle
48 static int ufshcd_pci_suspend(struct device
*dev
)
52 * 1. Call ufshcd_suspend
53 * 2. Do bus specific power management
60 * ufshcd_pci_resume - resume power management function
61 * @pdev: pointer to PCI device handle
65 static int ufshcd_pci_resume(struct device
*dev
)
69 * 1. Call ufshcd_resume.
70 * 2. Do bus specific wake up
76 #define ufshcd_pci_suspend NULL
77 #define ufshcd_pci_resume NULL
78 #endif /* CONFIG_PM */
80 #ifdef CONFIG_PM_RUNTIME
81 static int ufshcd_pci_runtime_suspend(struct device
*dev
)
83 struct ufs_hba
*hba
= dev_get_drvdata(dev
);
88 return ufshcd_runtime_suspend(hba
);
90 static int ufshcd_pci_runtime_resume(struct device
*dev
)
92 struct ufs_hba
*hba
= dev_get_drvdata(dev
);
97 return ufshcd_runtime_resume(hba
);
99 static int ufshcd_pci_runtime_idle(struct device
*dev
)
101 struct ufs_hba
*hba
= dev_get_drvdata(dev
);
106 return ufshcd_runtime_idle(hba
);
108 #else /* !CONFIG_PM_RUNTIME */
109 #define ufshcd_pci_runtime_suspend NULL
110 #define ufshcd_pci_runtime_resume NULL
111 #define ufshcd_pci_runtime_idle NULL
112 #endif /* CONFIG_PM_RUNTIME */
115 * ufshcd_pci_shutdown - main function to put the controller in reset state
116 * @pdev: pointer to PCI device handle
118 static void ufshcd_pci_shutdown(struct pci_dev
*pdev
)
120 ufshcd_hba_stop((struct ufs_hba
*)pci_get_drvdata(pdev
));
124 * ufshcd_pci_remove - de-allocate PCI/SCSI host and host memory space
125 * data structure memory
126 * @pdev - pointer to PCI handle
128 static void ufshcd_pci_remove(struct pci_dev
*pdev
)
130 struct ufs_hba
*hba
= pci_get_drvdata(pdev
);
132 pm_runtime_forbid(&pdev
->dev
);
133 pm_runtime_get_noresume(&pdev
->dev
);
135 pci_set_drvdata(pdev
, NULL
);
139 * ufshcd_set_dma_mask - Set dma mask based on the controller
140 * addressing capability
141 * @pdev: PCI device structure
143 * Returns 0 for success, non-zero for failure
145 static int ufshcd_set_dma_mask(struct pci_dev
*pdev
)
149 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(64))
150 && !pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(64)))
152 err
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
154 err
= pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32));
159 * ufshcd_pci_probe - probe routine of the driver
160 * @pdev: pointer to PCI device handle
163 * Returns 0 on success, non-zero value on failure
166 ufshcd_pci_probe(struct pci_dev
*pdev
, const struct pci_device_id
*id
)
169 void __iomem
*mmio_base
;
172 err
= pcim_enable_device(pdev
);
174 dev_err(&pdev
->dev
, "pcim_enable_device failed\n");
178 pci_set_master(pdev
);
180 err
= pcim_iomap_regions(pdev
, 1 << 0, UFSHCD
);
182 dev_err(&pdev
->dev
, "request and iomap failed\n");
186 mmio_base
= pcim_iomap_table(pdev
)[0];
188 err
= ufshcd_set_dma_mask(pdev
);
190 dev_err(&pdev
->dev
, "set dma mask failed\n");
194 err
= ufshcd_init(&pdev
->dev
, &hba
, mmio_base
, pdev
->irq
);
196 dev_err(&pdev
->dev
, "Initialization failed\n");
200 pci_set_drvdata(pdev
, hba
);
201 pm_runtime_put_noidle(&pdev
->dev
);
202 pm_runtime_allow(&pdev
->dev
);
207 static const struct dev_pm_ops ufshcd_pci_pm_ops
= {
208 .suspend
= ufshcd_pci_suspend
,
209 .resume
= ufshcd_pci_resume
,
210 .runtime_suspend
= ufshcd_pci_runtime_suspend
,
211 .runtime_resume
= ufshcd_pci_runtime_resume
,
212 .runtime_idle
= ufshcd_pci_runtime_idle
,
215 static DEFINE_PCI_DEVICE_TABLE(ufshcd_pci_tbl
) = {
216 { PCI_VENDOR_ID_SAMSUNG
, 0xC00C, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
217 { } /* terminate list */
220 MODULE_DEVICE_TABLE(pci
, ufshcd_pci_tbl
);
222 static struct pci_driver ufshcd_pci_driver
= {
224 .id_table
= ufshcd_pci_tbl
,
225 .probe
= ufshcd_pci_probe
,
226 .remove
= ufshcd_pci_remove
,
227 .shutdown
= ufshcd_pci_shutdown
,
229 .pm
= &ufshcd_pci_pm_ops
233 module_pci_driver(ufshcd_pci_driver
);
235 MODULE_AUTHOR("Santosh Yaragnavi <santosh.sy@samsung.com>");
236 MODULE_AUTHOR("Vinayak Holikatti <h.vinayak@samsung.com>");
237 MODULE_DESCRIPTION("UFS host controller PCI glue driver");
238 MODULE_LICENSE("GPL");
239 MODULE_VERSION(UFSHCD_DRIVER_VERSION
);