1
2
3
4
5
6
7
8
9
10#include "ufshcd.h"
11#include "ufshcd-dwc.h"
12#include "tc-dwc-g210.h"
13
14#include <linux/pci.h>
15#include <linux/pm_runtime.h>
16
17
18#define TC_G210_20BIT 20
19#define TC_G210_40BIT 40
20#define TC_G210_INV 0
21
22static int tc_type = TC_G210_INV;
23module_param(tc_type, int, 0);
24MODULE_PARM_DESC(tc_type, "Test Chip Type (20 = 20-bit, 40 = 40-bit)");
25
26
27
28
29static struct ufs_hba_variant_ops tc_dwc_g210_pci_hba_vops = {
30 .name = "tc-dwc-g210-pci",
31 .link_startup_notify = ufshcd_dwc_link_startup_notify,
32};
33
34
35
36
37
38static void tc_dwc_g210_pci_shutdown(struct pci_dev *pdev)
39{
40 ufshcd_shutdown((struct ufs_hba *)pci_get_drvdata(pdev));
41}
42
43
44
45
46
47
48static void tc_dwc_g210_pci_remove(struct pci_dev *pdev)
49{
50 struct ufs_hba *hba = pci_get_drvdata(pdev);
51
52 pm_runtime_forbid(&pdev->dev);
53 pm_runtime_get_noresume(&pdev->dev);
54 ufshcd_remove(hba);
55}
56
57
58
59
60
61
62
63
64static int
65tc_dwc_g210_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
66{
67 struct ufs_hba *hba;
68 void __iomem *mmio_base;
69 int err;
70
71
72 if (tc_type == TC_G210_20BIT) {
73 tc_dwc_g210_pci_hba_vops.phy_initialization =
74 tc_dwc_g210_config_20_bit;
75 } else if (tc_type == TC_G210_40BIT) {
76 tc_dwc_g210_pci_hba_vops.phy_initialization =
77 tc_dwc_g210_config_40_bit;
78 } else {
79 dev_err(&pdev->dev, "test chip version not specified\n");
80 return -EPERM;
81 }
82
83 err = pcim_enable_device(pdev);
84 if (err) {
85 dev_err(&pdev->dev, "pcim_enable_device failed\n");
86 return err;
87 }
88
89 pci_set_master(pdev);
90
91 err = pcim_iomap_regions(pdev, 1 << 0, UFSHCD);
92 if (err < 0) {
93 dev_err(&pdev->dev, "request and iomap failed\n");
94 return err;
95 }
96
97 mmio_base = pcim_iomap_table(pdev)[0];
98
99 err = ufshcd_alloc_host(&pdev->dev, &hba);
100 if (err) {
101 dev_err(&pdev->dev, "Allocation failed\n");
102 return err;
103 }
104
105 hba->vops = &tc_dwc_g210_pci_hba_vops;
106
107 err = ufshcd_init(hba, mmio_base, pdev->irq);
108 if (err) {
109 dev_err(&pdev->dev, "Initialization failed\n");
110 return err;
111 }
112
113 pci_set_drvdata(pdev, hba);
114 pm_runtime_put_noidle(&pdev->dev);
115 pm_runtime_allow(&pdev->dev);
116
117 return 0;
118}
119
120static const struct dev_pm_ops tc_dwc_g210_pci_pm_ops = {
121 SET_SYSTEM_SLEEP_PM_OPS(ufshcd_system_suspend, ufshcd_system_resume)
122 SET_RUNTIME_PM_OPS(ufshcd_runtime_suspend, ufshcd_runtime_resume, NULL)
123 .prepare = ufshcd_suspend_prepare,
124 .complete = ufshcd_resume_complete,
125};
126
127static const struct pci_device_id tc_dwc_g210_pci_tbl[] = {
128 { PCI_VENDOR_ID_SYNOPSYS, 0xB101, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
129 { PCI_VENDOR_ID_SYNOPSYS, 0xB102, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
130 { }
131};
132
133MODULE_DEVICE_TABLE(pci, tc_dwc_g210_pci_tbl);
134
135static struct pci_driver tc_dwc_g210_pci_driver = {
136 .name = "tc-dwc-g210-pci",
137 .id_table = tc_dwc_g210_pci_tbl,
138 .probe = tc_dwc_g210_pci_probe,
139 .remove = tc_dwc_g210_pci_remove,
140 .shutdown = tc_dwc_g210_pci_shutdown,
141 .driver = {
142 .pm = &tc_dwc_g210_pci_pm_ops
143 },
144};
145
146module_pci_driver(tc_dwc_g210_pci_driver);
147
148MODULE_AUTHOR("Joao Pinto <Joao.Pinto@synopsys.com>");
149MODULE_DESCRIPTION("Synopsys Test Chip G210 PCI glue driver");
150MODULE_LICENSE("Dual BSD/GPL");
151