2 * Universal Flash Storage Host controller Platform bus based glue driver
4 * This code is based on drivers/scsi/ufs/ufshcd-pltfrm.c
5 * Copyright (C) 2011-2013 Samsung India Software Operations
8 * Santosh Yaraganavi <santosh.sy@samsung.com>
9 * Vinayak Holikatti <h.vinayak@samsung.com>
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>
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.
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
37 #include <linux/platform_device.h>
41 * ufshcd_pltfrm_suspend - suspend power management function
42 * @dev: pointer to device handle
47 static int ufshcd_pltfrm_suspend(struct device
*dev
)
49 struct platform_device
*pdev
= to_platform_device(dev
);
50 struct ufs_hba
*hba
= platform_get_drvdata(pdev
);
54 * 1. Call ufshcd_suspend
55 * 2. Do bus specific power management
58 disable_irq(hba
->irq
);
64 * ufshcd_pltfrm_resume - resume power management function
65 * @dev: pointer to device handle
69 static int ufshcd_pltfrm_resume(struct device
*dev
)
71 struct platform_device
*pdev
= to_platform_device(dev
);
72 struct ufs_hba
*hba
= platform_get_drvdata(pdev
);
76 * 1. Call ufshcd_resume.
77 * 2. Do bus specific wake up
85 #define ufshcd_pltfrm_suspend NULL
86 #define ufshcd_pltfrm_resume NULL
90 * ufshcd_pltfrm_probe - probe routine of the driver
91 * @pdev: pointer to Platform device handle
93 * Returns 0 on success, non-zero value on failure
95 static int ufshcd_pltfrm_probe(struct platform_device
*pdev
)
98 void __iomem
*mmio_base
;
99 struct resource
*mem_res
;
100 struct resource
*irq_res
;
101 resource_size_t mem_size
;
103 struct device
*dev
= &pdev
->dev
;
105 mem_res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
108 "Memory resource not available\n");
113 mem_size
= resource_size(mem_res
);
114 if (!request_mem_region(mem_res
->start
, mem_size
, "ufshcd")) {
116 "Cannot reserve the memory resource\n");
121 mmio_base
= ioremap_nocache(mem_res
->start
, mem_size
);
123 dev_err(&pdev
->dev
, "memory map failed\n");
125 goto out_release_regions
;
128 irq_res
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
130 dev_err(&pdev
->dev
, "IRQ resource not available\n");
135 err
= dma_set_coherent_mask(dev
, dev
->coherent_dma_mask
);
137 dev_err(&pdev
->dev
, "set dma mask failed\n");
141 err
= ufshcd_init(&pdev
->dev
, &hba
, mmio_base
, irq_res
->start
);
143 dev_err(&pdev
->dev
, "Intialization failed\n");
147 platform_set_drvdata(pdev
, hba
);
154 release_mem_region(mem_res
->start
, mem_size
);
160 * ufshcd_pltfrm_remove - remove platform driver routine
161 * @pdev: pointer to platform device handle
163 * Returns 0 on success, non-zero value on failure
165 static int ufshcd_pltfrm_remove(struct platform_device
*pdev
)
167 struct resource
*mem_res
;
168 resource_size_t mem_size
;
169 struct ufs_hba
*hba
= platform_get_drvdata(pdev
);
171 disable_irq(hba
->irq
);
173 /* Some buggy controllers raise interrupt after
174 * the resources are removed. So first we unregister the
175 * irq handler and then the resources used by driver
178 free_irq(hba
->irq
, hba
);
180 mem_res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
182 dev_err(&pdev
->dev
, "ufshcd: Memory resource not available\n");
184 mem_size
= resource_size(mem_res
);
185 release_mem_region(mem_res
->start
, mem_size
);
187 platform_set_drvdata(pdev
, NULL
);
191 static const struct of_device_id ufs_of_match
[] = {
192 { .compatible
= "jedec,ufs-1.1"},
195 static const struct dev_pm_ops ufshcd_dev_pm_ops
= {
196 .suspend
= ufshcd_pltfrm_suspend
,
197 .resume
= ufshcd_pltfrm_resume
,
200 static struct platform_driver ufshcd_pltfrm_driver
= {
201 .probe
= ufshcd_pltfrm_probe
,
202 .remove
= ufshcd_pltfrm_remove
,
205 .owner
= THIS_MODULE
,
206 .pm
= &ufshcd_dev_pm_ops
,
207 .of_match_table
= ufs_of_match
,
211 module_platform_driver(ufshcd_pltfrm_driver
);
213 MODULE_AUTHOR("Santosh Yaragnavi <santosh.sy@samsung.com>");
214 MODULE_AUTHOR("Vinayak Holikatti <h.vinayak@samsung.com>");
215 MODULE_DESCRIPTION("UFS host controller Pltform bus based glue driver");
216 MODULE_LICENSE("GPL");
217 MODULE_VERSION(UFSHCD_DRIVER_VERSION
);