blob: c42db40d4e518ee425da875cd61d1c28041e1176 [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>
37
Seungwon Jeon2953f852013-06-27 13:31:54 +090038#include "ufshcd.h"
39
Vinayak Holikatti03b17812013-02-26 18:04:45 +053040#ifdef CONFIG_PM
41/**
42 * ufshcd_pltfrm_suspend - suspend power management function
43 * @dev: pointer to device handle
44 *
45 *
46 * Returns 0
47 */
48static int ufshcd_pltfrm_suspend(struct device *dev)
49{
50 struct platform_device *pdev = to_platform_device(dev);
51 struct ufs_hba *hba = platform_get_drvdata(pdev);
52
53 /*
54 * TODO:
55 * 1. Call ufshcd_suspend
56 * 2. Do bus specific power management
57 */
58
59 disable_irq(hba->irq);
60
61 return 0;
62}
63
64/**
65 * ufshcd_pltfrm_resume - resume power management function
66 * @dev: pointer to device handle
67 *
68 * Returns 0
69 */
70static int ufshcd_pltfrm_resume(struct device *dev)
71{
72 struct platform_device *pdev = to_platform_device(dev);
73 struct ufs_hba *hba = platform_get_drvdata(pdev);
74
75 /*
76 * TODO:
77 * 1. Call ufshcd_resume.
78 * 2. Do bus specific wake up
79 */
80
81 enable_irq(hba->irq);
82
83 return 0;
84}
85#else
86#define ufshcd_pltfrm_suspend NULL
87#define ufshcd_pltfrm_resume NULL
88#endif
89
90/**
91 * ufshcd_pltfrm_probe - probe routine of the driver
92 * @pdev: pointer to Platform device handle
93 *
94 * Returns 0 on success, non-zero value on failure
95 */
96static int ufshcd_pltfrm_probe(struct platform_device *pdev)
97{
98 struct ufs_hba *hba;
99 void __iomem *mmio_base;
100 struct resource *mem_res;
Seungwon Jeon2953f852013-06-27 13:31:54 +0900101 int irq, err;
Vinayak Holikatti03b17812013-02-26 18:04:45 +0530102 struct device *dev = &pdev->dev;
103
104 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
105 if (!mem_res) {
Seungwon Jeon2953f852013-06-27 13:31:54 +0900106 dev_err(dev, "Memory resource not available\n");
Vinayak Holikatti03b17812013-02-26 18:04:45 +0530107 err = -ENODEV;
Seungwon Jeon2953f852013-06-27 13:31:54 +0900108 goto out;
Vinayak Holikatti03b17812013-02-26 18:04:45 +0530109 }
110
Seungwon Jeon2953f852013-06-27 13:31:54 +0900111 mmio_base = devm_ioremap_resource(dev, mem_res);
112 if (IS_ERR(mmio_base)) {
113 dev_err(dev, "memory map failed\n");
114 err = PTR_ERR(mmio_base);
115 goto out;
Vinayak Holikatti03b17812013-02-26 18:04:45 +0530116 }
117
Seungwon Jeon2953f852013-06-27 13:31:54 +0900118 irq = platform_get_irq(pdev, 0);
119 if (irq < 0) {
120 dev_err(dev, "IRQ resource not available\n");
Vinayak Holikatti03b17812013-02-26 18:04:45 +0530121 err = -ENODEV;
Seungwon Jeon2953f852013-06-27 13:31:54 +0900122 goto out;
Vinayak Holikatti03b17812013-02-26 18:04:45 +0530123 }
124
Seungwon Jeon2953f852013-06-27 13:31:54 +0900125 err = ufshcd_init(dev, &hba, mmio_base, irq);
Vinayak Holikatti03b17812013-02-26 18:04:45 +0530126 if (err) {
Seungwon Jeon2953f852013-06-27 13:31:54 +0900127 dev_err(dev, "Intialization failed\n");
128 goto out;
Vinayak Holikatti03b17812013-02-26 18:04:45 +0530129 }
130
131 platform_set_drvdata(pdev, hba);
132
Seungwon Jeon2953f852013-06-27 13:31:54 +0900133out:
Vinayak Holikatti03b17812013-02-26 18:04:45 +0530134 return err;
135}
136
137/**
138 * ufshcd_pltfrm_remove - remove platform driver routine
139 * @pdev: pointer to platform device handle
140 *
141 * Returns 0 on success, non-zero value on failure
142 */
143static int ufshcd_pltfrm_remove(struct platform_device *pdev)
144{
Vinayak Holikatti03b17812013-02-26 18:04:45 +0530145 struct ufs_hba *hba = platform_get_drvdata(pdev);
146
147 disable_irq(hba->irq);
Vinayak Holikatti03b17812013-02-26 18:04:45 +0530148 ufshcd_remove(hba);
Vinayak Holikatti03b17812013-02-26 18:04:45 +0530149 return 0;
150}
151
152static const struct of_device_id ufs_of_match[] = {
153 { .compatible = "jedec,ufs-1.1"},
Akinobu Mita2e2930a2013-06-26 22:39:32 +0530154 {},
Vinayak Holikatti03b17812013-02-26 18:04:45 +0530155};
156
157static const struct dev_pm_ops ufshcd_dev_pm_ops = {
158 .suspend = ufshcd_pltfrm_suspend,
159 .resume = ufshcd_pltfrm_resume,
160};
161
162static struct platform_driver ufshcd_pltfrm_driver = {
163 .probe = ufshcd_pltfrm_probe,
164 .remove = ufshcd_pltfrm_remove,
165 .driver = {
166 .name = "ufshcd",
167 .owner = THIS_MODULE,
168 .pm = &ufshcd_dev_pm_ops,
169 .of_match_table = ufs_of_match,
170 },
171};
172
173module_platform_driver(ufshcd_pltfrm_driver);
174
175MODULE_AUTHOR("Santosh Yaragnavi <santosh.sy@samsung.com>");
176MODULE_AUTHOR("Vinayak Holikatti <h.vinayak@samsung.com>");
177MODULE_DESCRIPTION("UFS host controller Pltform bus based glue driver");
178MODULE_LICENSE("GPL");
179MODULE_VERSION(UFSHCD_DRIVER_VERSION);