blob: 6829a160869f01dcbde1b7eef4021d543b3ab627 [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
125 err = dma_set_coherent_mask(dev, dev->coherent_dma_mask);
126 if (err) {
Seungwon Jeon2953f852013-06-27 13:31:54 +0900127 dev_err(dev, "set dma mask failed\n");
128 goto out;
Vinayak Holikatti03b17812013-02-26 18:04:45 +0530129 }
130
Seungwon Jeon2953f852013-06-27 13:31:54 +0900131 err = ufshcd_init(dev, &hba, mmio_base, irq);
Vinayak Holikatti03b17812013-02-26 18:04:45 +0530132 if (err) {
Seungwon Jeon2953f852013-06-27 13:31:54 +0900133 dev_err(dev, "Intialization failed\n");
134 goto out;
Vinayak Holikatti03b17812013-02-26 18:04:45 +0530135 }
136
137 platform_set_drvdata(pdev, hba);
138
Seungwon Jeon2953f852013-06-27 13:31:54 +0900139out:
Vinayak Holikatti03b17812013-02-26 18:04:45 +0530140 return err;
141}
142
143/**
144 * ufshcd_pltfrm_remove - remove platform driver routine
145 * @pdev: pointer to platform device handle
146 *
147 * Returns 0 on success, non-zero value on failure
148 */
149static int ufshcd_pltfrm_remove(struct platform_device *pdev)
150{
Vinayak Holikatti03b17812013-02-26 18:04:45 +0530151 struct ufs_hba *hba = platform_get_drvdata(pdev);
152
153 disable_irq(hba->irq);
Vinayak Holikatti03b17812013-02-26 18:04:45 +0530154 ufshcd_remove(hba);
Vinayak Holikatti03b17812013-02-26 18:04:45 +0530155 return 0;
156}
157
158static const struct of_device_id ufs_of_match[] = {
159 { .compatible = "jedec,ufs-1.1"},
Akinobu Mita2e2930a2013-06-26 22:39:32 +0530160 {},
Vinayak Holikatti03b17812013-02-26 18:04:45 +0530161};
162
163static const struct dev_pm_ops ufshcd_dev_pm_ops = {
164 .suspend = ufshcd_pltfrm_suspend,
165 .resume = ufshcd_pltfrm_resume,
166};
167
168static struct platform_driver ufshcd_pltfrm_driver = {
169 .probe = ufshcd_pltfrm_probe,
170 .remove = ufshcd_pltfrm_remove,
171 .driver = {
172 .name = "ufshcd",
173 .owner = THIS_MODULE,
174 .pm = &ufshcd_dev_pm_ops,
175 .of_match_table = ufs_of_match,
176 },
177};
178
179module_platform_driver(ufshcd_pltfrm_driver);
180
181MODULE_AUTHOR("Santosh Yaragnavi <santosh.sy@samsung.com>");
182MODULE_AUTHOR("Vinayak Holikatti <h.vinayak@samsung.com>");
183MODULE_DESCRIPTION("UFS host controller Pltform bus based glue driver");
184MODULE_LICENSE("GPL");
185MODULE_VERSION(UFSHCD_DRIVER_VERSION);