blob: 8b4a27fdbb3ef45406c76c1ca1a0812b357e00fc [file] [log] [blame]
Vinayak Holikatti03b17812013-02-26 18:04:45 +05301/*
2 * Universal Flash Storage Host controller Platform bus based glue driver
3 *
4 * This code is based on drivers/scsi/ufs/ufshcd-pltfrm.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
Vinayak Holikatti03b17812013-02-26 18:04:45 +053036#include <linux/platform_device.h>
Sujit Reddy Thumma62694732013-07-30 00:36:00 +053037#include <linux/pm_runtime.h>
Vinayak Holikatti03b17812013-02-26 18:04:45 +053038
Seungwon Jeon2953f852013-06-27 13:31:54 +090039#include "ufshcd.h"
40
Vinayak Holikatti03b17812013-02-26 18:04:45 +053041#ifdef CONFIG_PM
42/**
43 * ufshcd_pltfrm_suspend - suspend power management function
44 * @dev: pointer to device handle
45 *
46 *
47 * Returns 0
48 */
49static int ufshcd_pltfrm_suspend(struct device *dev)
50{
51 struct platform_device *pdev = to_platform_device(dev);
52 struct ufs_hba *hba = platform_get_drvdata(pdev);
53
54 /*
55 * TODO:
56 * 1. Call ufshcd_suspend
57 * 2. Do bus specific power management
58 */
59
60 disable_irq(hba->irq);
61
62 return 0;
63}
64
65/**
66 * ufshcd_pltfrm_resume - resume power management function
67 * @dev: pointer to device handle
68 *
69 * Returns 0
70 */
71static int ufshcd_pltfrm_resume(struct device *dev)
72{
73 struct platform_device *pdev = to_platform_device(dev);
74 struct ufs_hba *hba = platform_get_drvdata(pdev);
75
76 /*
77 * TODO:
78 * 1. Call ufshcd_resume.
79 * 2. Do bus specific wake up
80 */
81
82 enable_irq(hba->irq);
83
84 return 0;
85}
86#else
87#define ufshcd_pltfrm_suspend NULL
88#define ufshcd_pltfrm_resume NULL
89#endif
90
Sujit Reddy Thumma62694732013-07-30 00:36:00 +053091#ifdef CONFIG_PM_RUNTIME
92static int ufshcd_pltfrm_runtime_suspend(struct device *dev)
93{
94 struct ufs_hba *hba = dev_get_drvdata(dev);
95
96 if (!hba)
97 return 0;
98
99 return ufshcd_runtime_suspend(hba);
100}
101static int ufshcd_pltfrm_runtime_resume(struct device *dev)
102{
103 struct ufs_hba *hba = dev_get_drvdata(dev);
104
105 if (!hba)
106 return 0;
107
108 return ufshcd_runtime_resume(hba);
109}
110static int ufshcd_pltfrm_runtime_idle(struct device *dev)
111{
112 struct ufs_hba *hba = dev_get_drvdata(dev);
113
114 if (!hba)
115 return 0;
116
117 return ufshcd_runtime_idle(hba);
118}
119#else /* !CONFIG_PM_RUNTIME */
120#define ufshcd_pltfrm_runtime_suspend NULL
121#define ufshcd_pltfrm_runtime_resume NULL
122#define ufshcd_pltfrm_runtime_idle NULL
123#endif /* CONFIG_PM_RUNTIME */
124
Vinayak Holikatti03b17812013-02-26 18:04:45 +0530125/**
126 * ufshcd_pltfrm_probe - probe routine of the driver
127 * @pdev: pointer to Platform device handle
128 *
129 * Returns 0 on success, non-zero value on failure
130 */
131static int ufshcd_pltfrm_probe(struct platform_device *pdev)
132{
133 struct ufs_hba *hba;
134 void __iomem *mmio_base;
135 struct resource *mem_res;
Seungwon Jeon2953f852013-06-27 13:31:54 +0900136 int irq, err;
Vinayak Holikatti03b17812013-02-26 18:04:45 +0530137 struct device *dev = &pdev->dev;
138
139 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
140 if (!mem_res) {
Seungwon Jeon2953f852013-06-27 13:31:54 +0900141 dev_err(dev, "Memory resource not available\n");
Vinayak Holikatti03b17812013-02-26 18:04:45 +0530142 err = -ENODEV;
Seungwon Jeon2953f852013-06-27 13:31:54 +0900143 goto out;
Vinayak Holikatti03b17812013-02-26 18:04:45 +0530144 }
145
Seungwon Jeon2953f852013-06-27 13:31:54 +0900146 mmio_base = devm_ioremap_resource(dev, mem_res);
147 if (IS_ERR(mmio_base)) {
148 dev_err(dev, "memory map failed\n");
149 err = PTR_ERR(mmio_base);
150 goto out;
Vinayak Holikatti03b17812013-02-26 18:04:45 +0530151 }
152
Seungwon Jeon2953f852013-06-27 13:31:54 +0900153 irq = platform_get_irq(pdev, 0);
154 if (irq < 0) {
155 dev_err(dev, "IRQ resource not available\n");
Vinayak Holikatti03b17812013-02-26 18:04:45 +0530156 err = -ENODEV;
Seungwon Jeon2953f852013-06-27 13:31:54 +0900157 goto out;
Vinayak Holikatti03b17812013-02-26 18:04:45 +0530158 }
159
Sujit Reddy Thumma62694732013-07-30 00:36:00 +0530160 pm_runtime_set_active(&pdev->dev);
161 pm_runtime_enable(&pdev->dev);
162
Seungwon Jeon2953f852013-06-27 13:31:54 +0900163 err = ufshcd_init(dev, &hba, mmio_base, irq);
Vinayak Holikatti03b17812013-02-26 18:04:45 +0530164 if (err) {
Seungwon Jeon2953f852013-06-27 13:31:54 +0900165 dev_err(dev, "Intialization failed\n");
Sujit Reddy Thumma62694732013-07-30 00:36:00 +0530166 goto out_disable_rpm;
Vinayak Holikatti03b17812013-02-26 18:04:45 +0530167 }
168
169 platform_set_drvdata(pdev, hba);
170
Sujit Reddy Thumma62694732013-07-30 00:36:00 +0530171 return 0;
172
173out_disable_rpm:
174 pm_runtime_disable(&pdev->dev);
175 pm_runtime_set_suspended(&pdev->dev);
Seungwon Jeon2953f852013-06-27 13:31:54 +0900176out:
Vinayak Holikatti03b17812013-02-26 18:04:45 +0530177 return err;
178}
179
180/**
181 * ufshcd_pltfrm_remove - remove platform driver routine
182 * @pdev: pointer to platform device handle
183 *
184 * Returns 0 on success, non-zero value on failure
185 */
186static int ufshcd_pltfrm_remove(struct platform_device *pdev)
187{
Vinayak Holikatti03b17812013-02-26 18:04:45 +0530188 struct ufs_hba *hba = platform_get_drvdata(pdev);
189
Sujit Reddy Thumma62694732013-07-30 00:36:00 +0530190 pm_runtime_get_sync(&(pdev)->dev);
Vinayak Holikatti03b17812013-02-26 18:04:45 +0530191 ufshcd_remove(hba);
Vinayak Holikatti03b17812013-02-26 18:04:45 +0530192 return 0;
193}
194
195static const struct of_device_id ufs_of_match[] = {
196 { .compatible = "jedec,ufs-1.1"},
Akinobu Mita2e2930a2013-06-26 22:39:32 +0530197 {},
Vinayak Holikatti03b17812013-02-26 18:04:45 +0530198};
199
200static const struct dev_pm_ops ufshcd_dev_pm_ops = {
201 .suspend = ufshcd_pltfrm_suspend,
202 .resume = ufshcd_pltfrm_resume,
Sujit Reddy Thumma62694732013-07-30 00:36:00 +0530203 .runtime_suspend = ufshcd_pltfrm_runtime_suspend,
204 .runtime_resume = ufshcd_pltfrm_runtime_resume,
205 .runtime_idle = ufshcd_pltfrm_runtime_idle,
Vinayak Holikatti03b17812013-02-26 18:04:45 +0530206};
207
208static struct platform_driver ufshcd_pltfrm_driver = {
209 .probe = ufshcd_pltfrm_probe,
210 .remove = ufshcd_pltfrm_remove,
211 .driver = {
212 .name = "ufshcd",
213 .owner = THIS_MODULE,
214 .pm = &ufshcd_dev_pm_ops,
215 .of_match_table = ufs_of_match,
216 },
217};
218
219module_platform_driver(ufshcd_pltfrm_driver);
220
221MODULE_AUTHOR("Santosh Yaragnavi <santosh.sy@samsung.com>");
222MODULE_AUTHOR("Vinayak Holikatti <h.vinayak@samsung.com>");
223MODULE_DESCRIPTION("UFS host controller Pltform bus based glue driver");
224MODULE_LICENSE("GPL");
225MODULE_VERSION(UFSHCD_DRIVER_VERSION);