blob: 48be39a6f6d7dc6f751a744d77fe5902821a9a05 [file] [log] [blame]
Vinayak Holikattie0eca632013-02-25 21:44:33 +05301/*
2 * Universal Flash Storage Host controller PCI glue driver
3 *
4 * This code is based on drivers/scsi/ufs/ufshcd-pci.c
5 * Copyright (C) 2011-2013 Samsung India Software Operations
6 *
7 * Authors:
8 * Santosh Yaraganavi <santosh.sy@samsung.com>
9 * Vinayak Holikatti <h.vinayak@samsung.com>
10 *
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>
17 *
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.
22 *
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
33 * this program.
34 */
35
36#include "ufshcd.h"
37#include <linux/pci.h>
38
39#ifdef CONFIG_PM
40/**
41 * ufshcd_pci_suspend - suspend power management function
42 * @pdev: pointer to PCI device handle
43 * @state: power state
44 *
45 * Returns -ENOSYS
46 */
47static int ufshcd_pci_suspend(struct pci_dev *pdev, pm_message_t state)
48{
49 /*
50 * TODO:
51 * 1. Call ufshcd_suspend
52 * 2. Do bus specific power management
53 */
54
55 return -ENOSYS;
56}
57
58/**
59 * ufshcd_pci_resume - resume power management function
60 * @pdev: pointer to PCI device handle
61 *
62 * Returns -ENOSYS
63 */
64static int ufshcd_pci_resume(struct pci_dev *pdev)
65{
66 /*
67 * TODO:
68 * 1. Call ufshcd_resume.
69 * 2. Do bus specific wake up
70 */
71
72 return -ENOSYS;
73}
74#endif /* CONFIG_PM */
75
76/**
77 * ufshcd_pci_shutdown - main function to put the controller in reset state
78 * @pdev: pointer to PCI device handle
79 */
80static void ufshcd_pci_shutdown(struct pci_dev *pdev)
81{
82 ufshcd_hba_stop((struct ufs_hba *)pci_get_drvdata(pdev));
83}
84
85/**
86 * ufshcd_pci_remove - de-allocate PCI/SCSI host and host memory space
87 * data structure memory
88 * @pdev - pointer to PCI handle
89 */
90static void ufshcd_pci_remove(struct pci_dev *pdev)
91{
92 struct ufs_hba *hba = pci_get_drvdata(pdev);
93
94 disable_irq(pdev->irq);
Vinayak Holikattie0eca632013-02-25 21:44:33 +053095 ufshcd_remove(hba);
96 pci_release_regions(pdev);
97 pci_set_drvdata(pdev, NULL);
98 pci_clear_master(pdev);
99 pci_disable_device(pdev);
100}
101
102/**
103 * ufshcd_set_dma_mask - Set dma mask based on the controller
104 * addressing capability
105 * @pdev: PCI device structure
106 *
107 * Returns 0 for success, non-zero for failure
108 */
109static int ufshcd_set_dma_mask(struct pci_dev *pdev)
110{
111 int err;
112
113 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))
114 && !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)))
115 return 0;
116 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
117 if (!err)
118 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
119 return err;
120}
121
122/**
123 * ufshcd_pci_probe - probe routine of the driver
124 * @pdev: pointer to PCI device handle
125 * @id: PCI device id
126 *
127 * Returns 0 on success, non-zero value on failure
128 */
129static int
130ufshcd_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
131{
132 struct ufs_hba *hba;
133 void __iomem *mmio_base;
134 int err;
135
136 err = pci_enable_device(pdev);
137 if (err) {
138 dev_err(&pdev->dev, "pci_enable_device failed\n");
139 goto out_error;
140 }
141
142 pci_set_master(pdev);
143
144
145 err = pci_request_regions(pdev, UFSHCD);
146 if (err < 0) {
147 dev_err(&pdev->dev, "request regions failed\n");
148 goto out_disable;
149 }
150
151 mmio_base = pci_ioremap_bar(pdev, 0);
152 if (!mmio_base) {
153 dev_err(&pdev->dev, "memory map failed\n");
154 err = -ENOMEM;
155 goto out_release_regions;
156 }
157
158 err = ufshcd_set_dma_mask(pdev);
159 if (err) {
160 dev_err(&pdev->dev, "set dma mask failed\n");
161 goto out_iounmap;
162 }
163
164 err = ufshcd_init(&pdev->dev, &hba, mmio_base, pdev->irq);
165 if (err) {
166 dev_err(&pdev->dev, "Initialization failed\n");
167 goto out_iounmap;
168 }
169
170 pci_set_drvdata(pdev, hba);
171
172 return 0;
173
174out_iounmap:
175 iounmap(mmio_base);
176out_release_regions:
177 pci_release_regions(pdev);
178out_disable:
179 pci_clear_master(pdev);
180 pci_disable_device(pdev);
181out_error:
182 return err;
183}
184
185static DEFINE_PCI_DEVICE_TABLE(ufshcd_pci_tbl) = {
186 { PCI_VENDOR_ID_SAMSUNG, 0xC00C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
187 { } /* terminate list */
188};
189
190MODULE_DEVICE_TABLE(pci, ufshcd_pci_tbl);
191
192static struct pci_driver ufshcd_pci_driver = {
193 .name = UFSHCD,
194 .id_table = ufshcd_pci_tbl,
195 .probe = ufshcd_pci_probe,
196 .remove = ufshcd_pci_remove,
197 .shutdown = ufshcd_pci_shutdown,
198#ifdef CONFIG_PM
199 .suspend = ufshcd_pci_suspend,
200 .resume = ufshcd_pci_resume,
201#endif
202};
203
204module_pci_driver(ufshcd_pci_driver);
205
206MODULE_AUTHOR("Santosh Yaragnavi <santosh.sy@samsung.com>");
207MODULE_AUTHOR("Vinayak Holikatti <h.vinayak@samsung.com>");
208MODULE_DESCRIPTION("UFS host controller PCI glue driver");
209MODULE_LICENSE("GPL");
210MODULE_VERSION(UFSHCD_DRIVER_VERSION);