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> |
Sujit Reddy Thumma | 6269473 | 2013-07-30 00:36:00 +0530 | [diff] [blame] | 37 | #include <linux/pm_runtime.h> |
Sujit Reddy Thumma | 5c0c28a | 2014-09-25 15:32:21 +0300 | [diff] [blame] | 38 | #include <linux/of.h> |
Vinayak Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 39 | |
Seungwon Jeon | 2953f85 | 2013-06-27 13:31:54 +0900 | [diff] [blame] | 40 | #include "ufshcd.h" |
Yaniv Gardi | 47555a5 | 2015-10-28 13:15:49 +0200 | [diff] [blame^] | 41 | #include "ufshcd-pltfrm.h" |
Sujit Reddy Thumma | 5c0c28a | 2014-09-25 15:32:21 +0300 | [diff] [blame] | 42 | |
Sujit Reddy Thumma | c6e79da | 2014-09-25 15:32:23 +0300 | [diff] [blame] | 43 | static int ufshcd_parse_clock_info(struct ufs_hba *hba) |
| 44 | { |
| 45 | int ret = 0; |
| 46 | int cnt; |
| 47 | int i; |
| 48 | struct device *dev = hba->dev; |
| 49 | struct device_node *np = dev->of_node; |
| 50 | char *name; |
| 51 | u32 *clkfreq = NULL; |
| 52 | struct ufs_clk_info *clki; |
Sahitya Tummala | 4cff6d99 | 2014-09-25 15:32:33 +0300 | [diff] [blame] | 53 | int len = 0; |
| 54 | size_t sz = 0; |
Sujit Reddy Thumma | c6e79da | 2014-09-25 15:32:23 +0300 | [diff] [blame] | 55 | |
| 56 | if (!np) |
| 57 | goto out; |
| 58 | |
| 59 | INIT_LIST_HEAD(&hba->clk_list_head); |
| 60 | |
| 61 | cnt = of_property_count_strings(np, "clock-names"); |
| 62 | if (!cnt || (cnt == -EINVAL)) { |
| 63 | dev_info(dev, "%s: Unable to find clocks, assuming enabled\n", |
| 64 | __func__); |
| 65 | } else if (cnt < 0) { |
| 66 | dev_err(dev, "%s: count clock strings failed, err %d\n", |
| 67 | __func__, cnt); |
| 68 | ret = cnt; |
| 69 | } |
| 70 | |
| 71 | if (cnt <= 0) |
| 72 | goto out; |
| 73 | |
Sahitya Tummala | 4cff6d99 | 2014-09-25 15:32:33 +0300 | [diff] [blame] | 74 | if (!of_get_property(np, "freq-table-hz", &len)) { |
| 75 | dev_info(dev, "freq-table-hz property not specified\n"); |
| 76 | goto out; |
| 77 | } |
| 78 | |
| 79 | if (len <= 0) |
| 80 | goto out; |
| 81 | |
| 82 | sz = len / sizeof(*clkfreq); |
| 83 | if (sz != 2 * cnt) { |
| 84 | dev_err(dev, "%s len mismatch\n", "freq-table-hz"); |
| 85 | ret = -EINVAL; |
| 86 | goto out; |
| 87 | } |
| 88 | |
| 89 | clkfreq = devm_kzalloc(dev, sz * sizeof(*clkfreq), |
| 90 | GFP_KERNEL); |
Sujit Reddy Thumma | c6e79da | 2014-09-25 15:32:23 +0300 | [diff] [blame] | 91 | if (!clkfreq) { |
| 92 | ret = -ENOMEM; |
Sujit Reddy Thumma | c6e79da | 2014-09-25 15:32:23 +0300 | [diff] [blame] | 93 | goto out; |
| 94 | } |
| 95 | |
Sahitya Tummala | 4cff6d99 | 2014-09-25 15:32:33 +0300 | [diff] [blame] | 96 | ret = of_property_read_u32_array(np, "freq-table-hz", |
| 97 | clkfreq, sz); |
Sujit Reddy Thumma | c6e79da | 2014-09-25 15:32:23 +0300 | [diff] [blame] | 98 | if (ret && (ret != -EINVAL)) { |
Sahitya Tummala | 4cff6d99 | 2014-09-25 15:32:33 +0300 | [diff] [blame] | 99 | dev_err(dev, "%s: error reading array %d\n", |
| 100 | "freq-table-hz", ret); |
Dolev Raviv | e8cb64d | 2014-10-23 13:25:17 +0300 | [diff] [blame] | 101 | return ret; |
Sujit Reddy Thumma | c6e79da | 2014-09-25 15:32:23 +0300 | [diff] [blame] | 102 | } |
| 103 | |
Sahitya Tummala | 4cff6d99 | 2014-09-25 15:32:33 +0300 | [diff] [blame] | 104 | for (i = 0; i < sz; i += 2) { |
Sujit Reddy Thumma | c6e79da | 2014-09-25 15:32:23 +0300 | [diff] [blame] | 105 | ret = of_property_read_string_index(np, |
Sahitya Tummala | 4cff6d99 | 2014-09-25 15:32:33 +0300 | [diff] [blame] | 106 | "clock-names", i/2, (const char **)&name); |
Sujit Reddy Thumma | c6e79da | 2014-09-25 15:32:23 +0300 | [diff] [blame] | 107 | if (ret) |
Dolev Raviv | e8cb64d | 2014-10-23 13:25:17 +0300 | [diff] [blame] | 108 | goto out; |
Sujit Reddy Thumma | c6e79da | 2014-09-25 15:32:23 +0300 | [diff] [blame] | 109 | |
| 110 | clki = devm_kzalloc(dev, sizeof(*clki), GFP_KERNEL); |
| 111 | if (!clki) { |
| 112 | ret = -ENOMEM; |
Dolev Raviv | e8cb64d | 2014-10-23 13:25:17 +0300 | [diff] [blame] | 113 | goto out; |
Sujit Reddy Thumma | c6e79da | 2014-09-25 15:32:23 +0300 | [diff] [blame] | 114 | } |
| 115 | |
Sahitya Tummala | 4cff6d99 | 2014-09-25 15:32:33 +0300 | [diff] [blame] | 116 | clki->min_freq = clkfreq[i]; |
| 117 | clki->max_freq = clkfreq[i+1]; |
Sujit Reddy Thumma | c6e79da | 2014-09-25 15:32:23 +0300 | [diff] [blame] | 118 | clki->name = kstrdup(name, GFP_KERNEL); |
Sahitya Tummala | 4cff6d99 | 2014-09-25 15:32:33 +0300 | [diff] [blame] | 119 | dev_dbg(dev, "%s: min %u max %u name %s\n", "freq-table-hz", |
| 120 | clki->min_freq, clki->max_freq, clki->name); |
Sujit Reddy Thumma | c6e79da | 2014-09-25 15:32:23 +0300 | [diff] [blame] | 121 | list_add_tail(&clki->list, &hba->clk_list_head); |
| 122 | } |
Sahitya Tummala | 4cff6d99 | 2014-09-25 15:32:33 +0300 | [diff] [blame] | 123 | out: |
Sujit Reddy Thumma | c6e79da | 2014-09-25 15:32:23 +0300 | [diff] [blame] | 124 | return ret; |
| 125 | } |
| 126 | |
Sujit Reddy Thumma | aa49761 | 2014-09-25 15:32:22 +0300 | [diff] [blame] | 127 | #define MAX_PROP_SIZE 32 |
| 128 | static int ufshcd_populate_vreg(struct device *dev, const char *name, |
| 129 | struct ufs_vreg **out_vreg) |
| 130 | { |
| 131 | int ret = 0; |
| 132 | char prop_name[MAX_PROP_SIZE]; |
| 133 | struct ufs_vreg *vreg = NULL; |
| 134 | struct device_node *np = dev->of_node; |
| 135 | |
| 136 | if (!np) { |
| 137 | dev_err(dev, "%s: non DT initialization\n", __func__); |
| 138 | goto out; |
| 139 | } |
| 140 | |
| 141 | snprintf(prop_name, MAX_PROP_SIZE, "%s-supply", name); |
| 142 | if (!of_parse_phandle(np, prop_name, 0)) { |
| 143 | dev_info(dev, "%s: Unable to find %s regulator, assuming enabled\n", |
| 144 | __func__, prop_name); |
| 145 | goto out; |
| 146 | } |
| 147 | |
| 148 | vreg = devm_kzalloc(dev, sizeof(*vreg), GFP_KERNEL); |
Dolev Raviv | 758581b | 2014-10-23 13:25:15 +0300 | [diff] [blame] | 149 | if (!vreg) |
| 150 | return -ENOMEM; |
Sujit Reddy Thumma | aa49761 | 2014-09-25 15:32:22 +0300 | [diff] [blame] | 151 | |
| 152 | vreg->name = kstrdup(name, GFP_KERNEL); |
| 153 | |
Raviv Shvili | 6a771a6 | 2014-09-25 15:32:24 +0300 | [diff] [blame] | 154 | /* if fixed regulator no need further initialization */ |
| 155 | snprintf(prop_name, MAX_PROP_SIZE, "%s-fixed-regulator", name); |
| 156 | if (of_property_read_bool(np, prop_name)) |
| 157 | goto out; |
| 158 | |
Sujit Reddy Thumma | aa49761 | 2014-09-25 15:32:22 +0300 | [diff] [blame] | 159 | snprintf(prop_name, MAX_PROP_SIZE, "%s-max-microamp", name); |
| 160 | ret = of_property_read_u32(np, prop_name, &vreg->max_uA); |
| 161 | if (ret) { |
| 162 | dev_err(dev, "%s: unable to find %s err %d\n", |
| 163 | __func__, prop_name, ret); |
| 164 | goto out_free; |
| 165 | } |
| 166 | |
| 167 | vreg->min_uA = 0; |
| 168 | if (!strcmp(name, "vcc")) { |
| 169 | if (of_property_read_bool(np, "vcc-supply-1p8")) { |
| 170 | vreg->min_uV = UFS_VREG_VCC_1P8_MIN_UV; |
| 171 | vreg->max_uV = UFS_VREG_VCC_1P8_MAX_UV; |
| 172 | } else { |
| 173 | vreg->min_uV = UFS_VREG_VCC_MIN_UV; |
| 174 | vreg->max_uV = UFS_VREG_VCC_MAX_UV; |
| 175 | } |
| 176 | } else if (!strcmp(name, "vccq")) { |
| 177 | vreg->min_uV = UFS_VREG_VCCQ_MIN_UV; |
| 178 | vreg->max_uV = UFS_VREG_VCCQ_MAX_UV; |
| 179 | } else if (!strcmp(name, "vccq2")) { |
| 180 | vreg->min_uV = UFS_VREG_VCCQ2_MIN_UV; |
| 181 | vreg->max_uV = UFS_VREG_VCCQ2_MAX_UV; |
| 182 | } |
| 183 | |
| 184 | goto out; |
| 185 | |
| 186 | out_free: |
| 187 | devm_kfree(dev, vreg); |
| 188 | vreg = NULL; |
| 189 | out: |
| 190 | if (!ret) |
| 191 | *out_vreg = vreg; |
| 192 | return ret; |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * ufshcd_parse_regulator_info - get regulator info from device tree |
| 197 | * @hba: per adapter instance |
| 198 | * |
| 199 | * Get regulator info from device tree for vcc, vccq, vccq2 power supplies. |
| 200 | * If any of the supplies are not defined it is assumed that they are always-on |
| 201 | * and hence return zero. If the property is defined but parsing is failed |
| 202 | * then return corresponding error. |
| 203 | */ |
| 204 | static int ufshcd_parse_regulator_info(struct ufs_hba *hba) |
| 205 | { |
| 206 | int err; |
| 207 | struct device *dev = hba->dev; |
| 208 | struct ufs_vreg_info *info = &hba->vreg_info; |
| 209 | |
Raviv Shvili | 6a771a6 | 2014-09-25 15:32:24 +0300 | [diff] [blame] | 210 | err = ufshcd_populate_vreg(dev, "vdd-hba", &info->vdd_hba); |
| 211 | if (err) |
| 212 | goto out; |
| 213 | |
Sujit Reddy Thumma | aa49761 | 2014-09-25 15:32:22 +0300 | [diff] [blame] | 214 | err = ufshcd_populate_vreg(dev, "vcc", &info->vcc); |
| 215 | if (err) |
| 216 | goto out; |
| 217 | |
| 218 | err = ufshcd_populate_vreg(dev, "vccq", &info->vccq); |
| 219 | if (err) |
| 220 | goto out; |
| 221 | |
| 222 | err = ufshcd_populate_vreg(dev, "vccq2", &info->vccq2); |
| 223 | out: |
| 224 | return err; |
| 225 | } |
| 226 | |
Vinayak Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 227 | #ifdef CONFIG_PM |
| 228 | /** |
| 229 | * ufshcd_pltfrm_suspend - suspend power management function |
| 230 | * @dev: pointer to device handle |
| 231 | * |
Subhash Jadavani | 57d104c | 2014-09-25 15:32:30 +0300 | [diff] [blame] | 232 | * Returns 0 if successful |
| 233 | * Returns non-zero otherwise |
Vinayak Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 234 | */ |
Yaniv Gardi | 47555a5 | 2015-10-28 13:15:49 +0200 | [diff] [blame^] | 235 | int ufshcd_pltfrm_suspend(struct device *dev) |
Vinayak Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 236 | { |
Subhash Jadavani | 57d104c | 2014-09-25 15:32:30 +0300 | [diff] [blame] | 237 | return ufshcd_system_suspend(dev_get_drvdata(dev)); |
Vinayak Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 238 | } |
Yaniv Gardi | 47555a5 | 2015-10-28 13:15:49 +0200 | [diff] [blame^] | 239 | EXPORT_SYMBOL_GPL(ufshcd_pltfrm_suspend); |
Vinayak Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 240 | |
| 241 | /** |
| 242 | * ufshcd_pltfrm_resume - resume power management function |
| 243 | * @dev: pointer to device handle |
| 244 | * |
Subhash Jadavani | 57d104c | 2014-09-25 15:32:30 +0300 | [diff] [blame] | 245 | * Returns 0 if successful |
| 246 | * Returns non-zero otherwise |
Vinayak Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 247 | */ |
Yaniv Gardi | 47555a5 | 2015-10-28 13:15:49 +0200 | [diff] [blame^] | 248 | int ufshcd_pltfrm_resume(struct device *dev) |
Vinayak Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 249 | { |
Subhash Jadavani | 57d104c | 2014-09-25 15:32:30 +0300 | [diff] [blame] | 250 | return ufshcd_system_resume(dev_get_drvdata(dev)); |
Vinayak Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 251 | } |
Yaniv Gardi | 47555a5 | 2015-10-28 13:15:49 +0200 | [diff] [blame^] | 252 | EXPORT_SYMBOL_GPL(ufshcd_pltfrm_resume); |
Vinayak Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 253 | |
Yaniv Gardi | 47555a5 | 2015-10-28 13:15:49 +0200 | [diff] [blame^] | 254 | int ufshcd_pltfrm_runtime_suspend(struct device *dev) |
Sujit Reddy Thumma | 6269473 | 2013-07-30 00:36:00 +0530 | [diff] [blame] | 255 | { |
Subhash Jadavani | 57d104c | 2014-09-25 15:32:30 +0300 | [diff] [blame] | 256 | return ufshcd_runtime_suspend(dev_get_drvdata(dev)); |
Sujit Reddy Thumma | 6269473 | 2013-07-30 00:36:00 +0530 | [diff] [blame] | 257 | } |
Yaniv Gardi | 47555a5 | 2015-10-28 13:15:49 +0200 | [diff] [blame^] | 258 | EXPORT_SYMBOL_GPL(ufshcd_pltfrm_runtime_suspend); |
| 259 | |
| 260 | int ufshcd_pltfrm_runtime_resume(struct device *dev) |
Sujit Reddy Thumma | 6269473 | 2013-07-30 00:36:00 +0530 | [diff] [blame] | 261 | { |
Subhash Jadavani | 57d104c | 2014-09-25 15:32:30 +0300 | [diff] [blame] | 262 | return ufshcd_runtime_resume(dev_get_drvdata(dev)); |
Sujit Reddy Thumma | 6269473 | 2013-07-30 00:36:00 +0530 | [diff] [blame] | 263 | } |
Yaniv Gardi | 47555a5 | 2015-10-28 13:15:49 +0200 | [diff] [blame^] | 264 | EXPORT_SYMBOL_GPL(ufshcd_pltfrm_runtime_resume); |
| 265 | |
| 266 | int ufshcd_pltfrm_runtime_idle(struct device *dev) |
Sujit Reddy Thumma | 6269473 | 2013-07-30 00:36:00 +0530 | [diff] [blame] | 267 | { |
Subhash Jadavani | 57d104c | 2014-09-25 15:32:30 +0300 | [diff] [blame] | 268 | return ufshcd_runtime_idle(dev_get_drvdata(dev)); |
Sujit Reddy Thumma | 6269473 | 2013-07-30 00:36:00 +0530 | [diff] [blame] | 269 | } |
Yaniv Gardi | 47555a5 | 2015-10-28 13:15:49 +0200 | [diff] [blame^] | 270 | EXPORT_SYMBOL_GPL(ufshcd_pltfrm_runtime_idle); |
| 271 | |
Rafael J. Wysocki | 4f7ad52 | 2014-12-14 23:13:55 +0100 | [diff] [blame] | 272 | #endif /* CONFIG_PM */ |
Sujit Reddy Thumma | 6269473 | 2013-07-30 00:36:00 +0530 | [diff] [blame] | 273 | |
Yaniv Gardi | 47555a5 | 2015-10-28 13:15:49 +0200 | [diff] [blame^] | 274 | void ufshcd_pltfrm_shutdown(struct platform_device *pdev) |
Subhash Jadavani | 57d104c | 2014-09-25 15:32:30 +0300 | [diff] [blame] | 275 | { |
| 276 | ufshcd_shutdown((struct ufs_hba *)platform_get_drvdata(pdev)); |
| 277 | } |
Yaniv Gardi | 47555a5 | 2015-10-28 13:15:49 +0200 | [diff] [blame^] | 278 | EXPORT_SYMBOL_GPL(ufshcd_pltfrm_shutdown); |
Subhash Jadavani | 57d104c | 2014-09-25 15:32:30 +0300 | [diff] [blame] | 279 | |
Vinayak Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 280 | /** |
Yaniv Gardi | 47555a5 | 2015-10-28 13:15:49 +0200 | [diff] [blame^] | 281 | * ufshcd_pltfrm_init - probe routine of the driver |
Vinayak Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 282 | * @pdev: pointer to Platform device handle |
Yaniv Gardi | 47555a5 | 2015-10-28 13:15:49 +0200 | [diff] [blame^] | 283 | * @vops: pointer to variant ops |
Vinayak Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 284 | * |
| 285 | * Returns 0 on success, non-zero value on failure |
| 286 | */ |
Yaniv Gardi | 47555a5 | 2015-10-28 13:15:49 +0200 | [diff] [blame^] | 287 | int ufshcd_pltfrm_init(struct platform_device *pdev, |
| 288 | struct ufs_hba_variant_ops *vops) |
Vinayak Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 289 | { |
| 290 | struct ufs_hba *hba; |
| 291 | void __iomem *mmio_base; |
| 292 | struct resource *mem_res; |
Seungwon Jeon | 2953f85 | 2013-06-27 13:31:54 +0900 | [diff] [blame] | 293 | int irq, err; |
Vinayak Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 294 | struct device *dev = &pdev->dev; |
| 295 | |
| 296 | mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Seungwon Jeon | 2953f85 | 2013-06-27 13:31:54 +0900 | [diff] [blame] | 297 | mmio_base = devm_ioremap_resource(dev, mem_res); |
Sujit Reddy Thumma | 5c0c28a | 2014-09-25 15:32:21 +0300 | [diff] [blame] | 298 | if (IS_ERR(*(void **)&mmio_base)) { |
| 299 | err = PTR_ERR(*(void **)&mmio_base); |
Seungwon Jeon | 2953f85 | 2013-06-27 13:31:54 +0900 | [diff] [blame] | 300 | goto out; |
Vinayak Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 301 | } |
| 302 | |
Seungwon Jeon | 2953f85 | 2013-06-27 13:31:54 +0900 | [diff] [blame] | 303 | irq = platform_get_irq(pdev, 0); |
| 304 | if (irq < 0) { |
| 305 | dev_err(dev, "IRQ resource not available\n"); |
Vinayak Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 306 | err = -ENODEV; |
Seungwon Jeon | 2953f85 | 2013-06-27 13:31:54 +0900 | [diff] [blame] | 307 | goto out; |
Vinayak Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 308 | } |
| 309 | |
Sujit Reddy Thumma | 5c0c28a | 2014-09-25 15:32:21 +0300 | [diff] [blame] | 310 | err = ufshcd_alloc_host(dev, &hba); |
| 311 | if (err) { |
| 312 | dev_err(&pdev->dev, "Allocation failed\n"); |
| 313 | goto out; |
| 314 | } |
| 315 | |
Yaniv Gardi | 47555a5 | 2015-10-28 13:15:49 +0200 | [diff] [blame^] | 316 | hba->vops = vops; |
Sujit Reddy Thumma | 5c0c28a | 2014-09-25 15:32:21 +0300 | [diff] [blame] | 317 | |
Sujit Reddy Thumma | c6e79da | 2014-09-25 15:32:23 +0300 | [diff] [blame] | 318 | err = ufshcd_parse_clock_info(hba); |
| 319 | if (err) { |
| 320 | dev_err(&pdev->dev, "%s: clock parse failed %d\n", |
| 321 | __func__, err); |
Yaniv Gardi | 47555a5 | 2015-10-28 13:15:49 +0200 | [diff] [blame^] | 322 | goto dealloc_host; |
Sujit Reddy Thumma | c6e79da | 2014-09-25 15:32:23 +0300 | [diff] [blame] | 323 | } |
Sujit Reddy Thumma | aa49761 | 2014-09-25 15:32:22 +0300 | [diff] [blame] | 324 | err = ufshcd_parse_regulator_info(hba); |
| 325 | if (err) { |
| 326 | dev_err(&pdev->dev, "%s: regulator init failed %d\n", |
| 327 | __func__, err); |
Yaniv Gardi | 47555a5 | 2015-10-28 13:15:49 +0200 | [diff] [blame^] | 328 | goto dealloc_host; |
Sujit Reddy Thumma | aa49761 | 2014-09-25 15:32:22 +0300 | [diff] [blame] | 329 | } |
| 330 | |
Sujit Reddy Thumma | 6269473 | 2013-07-30 00:36:00 +0530 | [diff] [blame] | 331 | pm_runtime_set_active(&pdev->dev); |
| 332 | pm_runtime_enable(&pdev->dev); |
| 333 | |
Sujit Reddy Thumma | 5c0c28a | 2014-09-25 15:32:21 +0300 | [diff] [blame] | 334 | err = ufshcd_init(hba, mmio_base, irq); |
Vinayak Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 335 | if (err) { |
Seungwon Jeon | 2953f85 | 2013-06-27 13:31:54 +0900 | [diff] [blame] | 336 | dev_err(dev, "Intialization failed\n"); |
Sujit Reddy Thumma | 6269473 | 2013-07-30 00:36:00 +0530 | [diff] [blame] | 337 | goto out_disable_rpm; |
Vinayak Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | platform_set_drvdata(pdev, hba); |
| 341 | |
Sujit Reddy Thumma | 6269473 | 2013-07-30 00:36:00 +0530 | [diff] [blame] | 342 | return 0; |
| 343 | |
| 344 | out_disable_rpm: |
| 345 | pm_runtime_disable(&pdev->dev); |
| 346 | pm_runtime_set_suspended(&pdev->dev); |
Yaniv Gardi | 47555a5 | 2015-10-28 13:15:49 +0200 | [diff] [blame^] | 347 | dealloc_host: |
| 348 | ufshcd_dealloc_host(hba); |
Seungwon Jeon | 2953f85 | 2013-06-27 13:31:54 +0900 | [diff] [blame] | 349 | out: |
Vinayak Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 350 | return err; |
| 351 | } |
Yaniv Gardi | 47555a5 | 2015-10-28 13:15:49 +0200 | [diff] [blame^] | 352 | EXPORT_SYMBOL_GPL(ufshcd_pltfrm_init); |
Vinayak Holikatti | 03b1781 | 2013-02-26 18:04:45 +0530 | [diff] [blame] | 353 | |
| 354 | MODULE_AUTHOR("Santosh Yaragnavi <santosh.sy@samsung.com>"); |
| 355 | MODULE_AUTHOR("Vinayak Holikatti <h.vinayak@samsung.com>"); |
| 356 | MODULE_DESCRIPTION("UFS host controller Pltform bus based glue driver"); |
| 357 | MODULE_LICENSE("GPL"); |
| 358 | MODULE_VERSION(UFSHCD_DRIVER_VERSION); |