]> Git Repo - linux.git/blob - drivers/ufs/host/tc-dwc-g210-pci.c
Merge tag 'audit-pr-20221003' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoor...
[linux.git] / drivers / ufs / host / tc-dwc-g210-pci.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Synopsys G210 Test Chip driver
4  *
5  * Copyright (C) 2015-2016 Synopsys, Inc. (www.synopsys.com)
6  *
7  * Authors: Joao Pinto <[email protected]>
8  */
9
10 #include <ufs/ufshcd.h>
11 #include "ufshcd-dwc.h"
12 #include "tc-dwc-g210.h"
13
14 #include <linux/module.h>
15 #include <linux/pci.h>
16 #include <linux/pm_runtime.h>
17
18 /* Test Chip type expected values */
19 #define TC_G210_20BIT 20
20 #define TC_G210_40BIT 40
21 #define TC_G210_INV 0
22
23 static int tc_type = TC_G210_INV;
24 module_param(tc_type, int, 0);
25 MODULE_PARM_DESC(tc_type, "Test Chip Type (20 = 20-bit, 40 = 40-bit)");
26
27 /*
28  * struct ufs_hba_dwc_vops - UFS DWC specific variant operations
29  */
30 static struct ufs_hba_variant_ops tc_dwc_g210_pci_hba_vops = {
31         .name                   = "tc-dwc-g210-pci",
32         .link_startup_notify    = ufshcd_dwc_link_startup_notify,
33 };
34
35 /**
36  * tc_dwc_g210_pci_shutdown - main function to put the controller in reset state
37  * @pdev: pointer to PCI device handle
38  */
39 static void tc_dwc_g210_pci_shutdown(struct pci_dev *pdev)
40 {
41         ufshcd_shutdown((struct ufs_hba *)pci_get_drvdata(pdev));
42 }
43
44 /**
45  * tc_dwc_g210_pci_remove - de-allocate PCI/SCSI host and host memory space
46  *              data structure memory
47  * @pdev: pointer to PCI handle
48  */
49 static void tc_dwc_g210_pci_remove(struct pci_dev *pdev)
50 {
51         struct ufs_hba *hba = pci_get_drvdata(pdev);
52
53         pm_runtime_forbid(&pdev->dev);
54         pm_runtime_get_noresume(&pdev->dev);
55         ufshcd_remove(hba);
56 }
57
58 /**
59  * tc_dwc_g210_pci_probe - probe routine of the driver
60  * @pdev: pointer to PCI device handle
61  * @id: PCI device id
62  *
63  * Returns 0 on success, non-zero value on failure
64  */
65 static int
66 tc_dwc_g210_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
67 {
68         struct ufs_hba *hba;
69         void __iomem *mmio_base;
70         int err;
71
72         /* Check Test Chip type and set the specific setup routine */
73         if (tc_type == TC_G210_20BIT) {
74                 tc_dwc_g210_pci_hba_vops.phy_initialization =
75                                                 tc_dwc_g210_config_20_bit;
76         } else if (tc_type == TC_G210_40BIT) {
77                 tc_dwc_g210_pci_hba_vops.phy_initialization =
78                                                 tc_dwc_g210_config_40_bit;
79         } else {
80                 dev_err(&pdev->dev, "test chip version not specified\n");
81                 return -EPERM;
82         }
83
84         err = pcim_enable_device(pdev);
85         if (err) {
86                 dev_err(&pdev->dev, "pcim_enable_device failed\n");
87                 return err;
88         }
89
90         pci_set_master(pdev);
91
92         err = pcim_iomap_regions(pdev, 1 << 0, UFSHCD);
93         if (err < 0) {
94                 dev_err(&pdev->dev, "request and iomap failed\n");
95                 return err;
96         }
97
98         mmio_base = pcim_iomap_table(pdev)[0];
99
100         err = ufshcd_alloc_host(&pdev->dev, &hba);
101         if (err) {
102                 dev_err(&pdev->dev, "Allocation failed\n");
103                 return err;
104         }
105
106         hba->vops = &tc_dwc_g210_pci_hba_vops;
107
108         err = ufshcd_init(hba, mmio_base, pdev->irq);
109         if (err) {
110                 dev_err(&pdev->dev, "Initialization failed\n");
111                 return err;
112         }
113
114         pm_runtime_put_noidle(&pdev->dev);
115         pm_runtime_allow(&pdev->dev);
116
117         return 0;
118 }
119
120 static 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
127 static 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         { }     /* terminate list */
131 };
132
133 MODULE_DEVICE_TABLE(pci, tc_dwc_g210_pci_tbl);
134
135 static 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
146 module_pci_driver(tc_dwc_g210_pci_driver);
147
148 MODULE_AUTHOR("Joao Pinto <[email protected]>");
149 MODULE_DESCRIPTION("Synopsys Test Chip G210 PCI glue driver");
150 MODULE_LICENSE("Dual BSD/GPL");
This page took 0.041351 seconds and 4 git commands to generate.