Vinayak Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 1 | /* |
| 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 Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 36 | #include <linux/platform_device.h> |
| 37 | |
Seungwon Jeon | 2953f85 | 2013-06-27 13:31:54 +0900 | [diff] [blame] | 38 | #include "ufshcd.h" |
| 39 | |
Vinayak Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 40 | #ifdef CONFIG_PM |
| 41 | /** |
| 42 | * ufshcd_pltfrm_suspend - suspend power management function |
| 43 | * @dev: pointer to device handle |
| 44 | * |
| 45 | * |
| 46 | * Returns 0 |
| 47 | */ |
| 48 | static 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 | */ |
| 70 | static 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 | */ |
| 96 | static 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 Jeon | 2953f85 | 2013-06-27 13:31:54 +0900 | [diff] [blame] | 101 | int irq, err; |
Vinayak Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 102 | struct device *dev = &pdev->dev; |
| 103 | |
| 104 | mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 105 | if (!mem_res) { |
Seungwon Jeon | 2953f85 | 2013-06-27 13:31:54 +0900 | [diff] [blame] | 106 | dev_err(dev, "Memory resource not available\n"); |
Vinayak Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 107 | err = -ENODEV; |
Seungwon Jeon | 2953f85 | 2013-06-27 13:31:54 +0900 | [diff] [blame] | 108 | goto out; |
Vinayak Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 109 | } |
| 110 | |
Seungwon Jeon | 2953f85 | 2013-06-27 13:31:54 +0900 | [diff] [blame] | 111 | 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 Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 116 | } |
| 117 | |
Seungwon Jeon | 2953f85 | 2013-06-27 13:31:54 +0900 | [diff] [blame] | 118 | irq = platform_get_irq(pdev, 0); |
| 119 | if (irq < 0) { |
| 120 | dev_err(dev, "IRQ resource not available\n"); |
Vinayak Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 121 | err = -ENODEV; |
Seungwon Jeon | 2953f85 | 2013-06-27 13:31:54 +0900 | [diff] [blame] | 122 | goto out; |
Vinayak Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 123 | } |
| 124 | |
Seungwon Jeon | 2953f85 | 2013-06-27 13:31:54 +0900 | [diff] [blame] | 125 | err = ufshcd_init(dev, &hba, mmio_base, irq); |
Vinayak Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 126 | if (err) { |
Seungwon Jeon | 2953f85 | 2013-06-27 13:31:54 +0900 | [diff] [blame] | 127 | dev_err(dev, "Intialization failed\n"); |
| 128 | goto out; |
Vinayak Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | platform_set_drvdata(pdev, hba); |
| 132 | |
Seungwon Jeon | 2953f85 | 2013-06-27 13:31:54 +0900 | [diff] [blame] | 133 | out: |
Vinayak Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 134 | 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 | */ |
| 143 | static int ufshcd_pltfrm_remove(struct platform_device *pdev) |
| 144 | { |
Vinayak Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 145 | struct ufs_hba *hba = platform_get_drvdata(pdev); |
| 146 | |
| 147 | disable_irq(hba->irq); |
Vinayak Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 148 | ufshcd_remove(hba); |
Vinayak Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 149 | return 0; |
| 150 | } |
| 151 | |
| 152 | static const struct of_device_id ufs_of_match[] = { |
| 153 | { .compatible = "jedec,ufs-1.1"}, |
Akinobu Mita | 2e2930a | 2013-06-26 22:39:32 +0530 | [diff] [blame] | 154 | {}, |
Vinayak Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 155 | }; |
| 156 | |
| 157 | static const struct dev_pm_ops ufshcd_dev_pm_ops = { |
| 158 | .suspend = ufshcd_pltfrm_suspend, |
| 159 | .resume = ufshcd_pltfrm_resume, |
| 160 | }; |
| 161 | |
| 162 | static 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 | |
| 173 | module_platform_driver(ufshcd_pltfrm_driver); |
| 174 | |
| 175 | MODULE_AUTHOR("Santosh Yaragnavi <santosh.sy@samsung.com>"); |
| 176 | MODULE_AUTHOR("Vinayak Holikatti <h.vinayak@samsung.com>"); |
| 177 | MODULE_DESCRIPTION("UFS host controller Pltform bus based glue driver"); |
| 178 | MODULE_LICENSE("GPL"); |
| 179 | MODULE_VERSION(UFSHCD_DRIVER_VERSION); |