Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1 | /* |
| 2 | * drivers/mmc/host/sdhci-msm.c - Qualcomm Technologies, Inc. MSM SDHCI Platform |
| 3 | * driver source file |
| 4 | * |
| 5 | * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 and |
| 9 | * only version 2 as published by the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | */ |
| 17 | |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/mmc/host.h> |
| 20 | #include <linux/mmc/card.h> |
| 21 | #include <linux/mmc/sdio_func.h> |
| 22 | #include <linux/gfp.h> |
| 23 | #include <linux/of.h> |
| 24 | #include <linux/of_gpio.h> |
| 25 | #include <linux/regulator/consumer.h> |
| 26 | #include <linux/types.h> |
| 27 | #include <linux/input.h> |
| 28 | #include <linux/platform_device.h> |
| 29 | #include <linux/wait.h> |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 30 | #include <linux/io.h> |
| 31 | #include <linux/delay.h> |
| 32 | #include <linux/scatterlist.h> |
| 33 | #include <linux/slab.h> |
| 34 | #include <linux/mmc/mmc.h> |
Sahitya Tummala | 581df13 | 2013-03-12 14:57:46 +0530 | [diff] [blame] | 35 | #include <linux/mmc/slot-gpio.h> |
Sahitya Tummala | eaa2186 | 2013-03-20 19:34:59 +0530 | [diff] [blame] | 36 | #include <linux/dma-mapping.h> |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 37 | #include <linux/msm-bus.h> |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 38 | |
| 39 | #include "sdhci-pltfm.h" |
| 40 | |
Venkat Gopalakrishnan | a58f91f | 2012-09-17 16:00:15 -0700 | [diff] [blame] | 41 | #define SDHCI_VER_100 0x2B |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 42 | #define CORE_HC_MODE 0x78 |
| 43 | #define HC_MODE_EN 0x1 |
| 44 | |
| 45 | #define CORE_POWER 0x0 |
| 46 | #define CORE_SW_RST (1 << 7) |
| 47 | |
| 48 | #define CORE_PWRCTL_STATUS 0xDC |
| 49 | #define CORE_PWRCTL_MASK 0xE0 |
| 50 | #define CORE_PWRCTL_CLEAR 0xE4 |
| 51 | #define CORE_PWRCTL_CTL 0xE8 |
| 52 | |
| 53 | #define CORE_PWRCTL_BUS_OFF 0x01 |
| 54 | #define CORE_PWRCTL_BUS_ON (1 << 1) |
| 55 | #define CORE_PWRCTL_IO_LOW (1 << 2) |
| 56 | #define CORE_PWRCTL_IO_HIGH (1 << 3) |
| 57 | |
| 58 | #define CORE_PWRCTL_BUS_SUCCESS 0x01 |
| 59 | #define CORE_PWRCTL_BUS_FAIL (1 << 1) |
| 60 | #define CORE_PWRCTL_IO_SUCCESS (1 << 2) |
| 61 | #define CORE_PWRCTL_IO_FAIL (1 << 3) |
| 62 | |
| 63 | #define INT_MASK 0xF |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 64 | #define MAX_PHASES 16 |
| 65 | |
| 66 | #define CORE_DLL_LOCK (1 << 7) |
| 67 | #define CORE_DLL_EN (1 << 16) |
| 68 | #define CORE_CDR_EN (1 << 17) |
| 69 | #define CORE_CK_OUT_EN (1 << 18) |
| 70 | #define CORE_CDR_EXT_EN (1 << 19) |
| 71 | #define CORE_DLL_PDN (1 << 29) |
| 72 | #define CORE_DLL_RST (1 << 30) |
| 73 | #define CORE_DLL_CONFIG 0x100 |
| 74 | #define CORE_DLL_TEST_CTL 0x104 |
| 75 | #define CORE_DLL_STATUS 0x108 |
| 76 | |
| 77 | #define CORE_VENDOR_SPEC 0x10C |
| 78 | #define CORE_CLK_PWRSAVE (1 << 1) |
| 79 | #define CORE_IO_PAD_PWR_SWITCH (1 << 16) |
| 80 | |
Asutosh Das | 648f9d1 | 2013-01-10 21:11:04 +0530 | [diff] [blame] | 81 | /* 8KB descriptors */ |
| 82 | #define SDHCI_MSM_MAX_SEGMENTS (1 << 13) |
Sahitya Tummala | a7f3c57 | 2013-01-11 11:30:45 +0530 | [diff] [blame] | 83 | #define SDHCI_MSM_MMC_CLK_GATE_DELAY 200 /* msecs */ |
Asutosh Das | 648f9d1 | 2013-01-10 21:11:04 +0530 | [diff] [blame] | 84 | |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 85 | static const u32 tuning_block_64[] = { |
| 86 | 0x00FF0FFF, 0xCCC3CCFF, 0xFFCC3CC3, 0xEFFEFFFE, |
| 87 | 0xDDFFDFFF, 0xFBFFFBFF, 0xFF7FFFBF, 0xEFBDF777, |
| 88 | 0xF0FFF0FF, 0x3CCCFC0F, 0xCFCC33CC, 0xEEFFEFFF, |
| 89 | 0xFDFFFDFF, 0xFFBFFFDF, 0xFFF7FFBB, 0xDE7B7FF7 |
| 90 | }; |
| 91 | |
| 92 | static const u32 tuning_block_128[] = { |
| 93 | 0xFF00FFFF, 0x0000FFFF, 0xCCCCFFFF, 0xCCCC33CC, |
| 94 | 0xCC3333CC, 0xFFFFCCCC, 0xFFFFEEFF, 0xFFEEEEFF, |
| 95 | 0xFFDDFFFF, 0xDDDDFFFF, 0xBBFFFFFF, 0xBBFFFFFF, |
| 96 | 0xFFFFFFBB, 0xFFFFFF77, 0x77FF7777, 0xFFEEDDBB, |
| 97 | 0x00FFFFFF, 0x00FFFFFF, 0xCCFFFF00, 0xCC33CCCC, |
| 98 | 0x3333CCCC, 0xFFCCCCCC, 0xFFEEFFFF, 0xEEEEFFFF, |
| 99 | 0xDDFFFFFF, 0xDDFFFFFF, 0xFFFFFFDD, 0xFFFFFFBB, |
| 100 | 0xFFFFBBBB, 0xFFFF77FF, 0xFF7777FF, 0xEEDDBB77 |
| 101 | }; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 102 | |
Venkat Gopalakrishnan | 270580a | 2013-03-11 12:17:57 -0700 | [diff] [blame] | 103 | static int disable_slots; |
| 104 | /* root can write, others read */ |
| 105 | module_param(disable_slots, int, S_IRUGO|S_IWUSR); |
| 106 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 107 | /* This structure keeps information per regulator */ |
| 108 | struct sdhci_msm_reg_data { |
| 109 | /* voltage regulator handle */ |
| 110 | struct regulator *reg; |
| 111 | /* regulator name */ |
| 112 | const char *name; |
| 113 | /* voltage level to be set */ |
| 114 | u32 low_vol_level; |
| 115 | u32 high_vol_level; |
| 116 | /* Load values for low power and high power mode */ |
| 117 | u32 lpm_uA; |
| 118 | u32 hpm_uA; |
| 119 | |
| 120 | /* is this regulator enabled? */ |
| 121 | bool is_enabled; |
| 122 | /* is this regulator needs to be always on? */ |
| 123 | bool is_always_on; |
| 124 | /* is low power mode setting required for this regulator? */ |
| 125 | bool lpm_sup; |
| 126 | bool set_voltage_sup; |
| 127 | }; |
| 128 | |
| 129 | /* |
| 130 | * This structure keeps information for all the |
| 131 | * regulators required for a SDCC slot. |
| 132 | */ |
| 133 | struct sdhci_msm_slot_reg_data { |
| 134 | /* keeps VDD/VCC regulator info */ |
| 135 | struct sdhci_msm_reg_data *vdd_data; |
| 136 | /* keeps VDD IO regulator info */ |
| 137 | struct sdhci_msm_reg_data *vdd_io_data; |
| 138 | }; |
| 139 | |
| 140 | struct sdhci_msm_gpio { |
| 141 | u32 no; |
| 142 | const char *name; |
| 143 | bool is_enabled; |
| 144 | }; |
| 145 | |
| 146 | struct sdhci_msm_gpio_data { |
| 147 | struct sdhci_msm_gpio *gpio; |
| 148 | u8 size; |
| 149 | }; |
| 150 | |
| 151 | struct sdhci_msm_pin_data { |
| 152 | /* |
| 153 | * = 1 if controller pins are using gpios |
| 154 | * = 0 if controller has dedicated MSM pads |
| 155 | */ |
| 156 | bool cfg_sts; |
| 157 | struct sdhci_msm_gpio_data *gpio_data; |
| 158 | }; |
| 159 | |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 160 | struct sdhci_msm_bus_voting_data { |
| 161 | struct msm_bus_scale_pdata *bus_pdata; |
| 162 | unsigned int *bw_vecs; |
| 163 | unsigned int bw_vecs_size; |
| 164 | }; |
| 165 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 166 | struct sdhci_msm_pltfm_data { |
| 167 | /* Supported UHS-I Modes */ |
| 168 | u32 caps; |
| 169 | |
| 170 | /* More capabilities */ |
| 171 | u32 caps2; |
| 172 | |
| 173 | unsigned long mmc_bus_width; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 174 | struct sdhci_msm_slot_reg_data *vreg_data; |
| 175 | bool nonremovable; |
| 176 | struct sdhci_msm_pin_data *pin_data; |
Sahitya Tummala | c6f48d4 | 2013-03-10 07:03:17 +0530 | [diff] [blame] | 177 | u32 cpu_dma_latency_us; |
Sahitya Tummala | 581df13 | 2013-03-12 14:57:46 +0530 | [diff] [blame] | 178 | int status_gpio; /* card detection GPIO that is configured as IRQ */ |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 179 | struct sdhci_msm_bus_voting_data *voting_data; |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 180 | u32 *sup_clk_table; |
| 181 | unsigned char sup_clk_cnt; |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 182 | }; |
| 183 | |
| 184 | struct sdhci_msm_bus_vote { |
| 185 | uint32_t client_handle; |
| 186 | uint32_t curr_vote; |
| 187 | int min_bw_vote; |
| 188 | int max_bw_vote; |
| 189 | bool is_max_bw_needed; |
| 190 | struct delayed_work vote_work; |
| 191 | struct device_attribute max_bus_bw; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 192 | }; |
| 193 | |
| 194 | struct sdhci_msm_host { |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 195 | struct platform_device *pdev; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 196 | void __iomem *core_mem; /* MSM SDCC mapped address */ |
| 197 | struct clk *clk; /* main SD/MMC bus clock */ |
| 198 | struct clk *pclk; /* SDHC peripheral bus clock */ |
| 199 | struct clk *bus_clk; /* SDHC bus voter clock */ |
Sahitya Tummala | a7f3c57 | 2013-01-11 11:30:45 +0530 | [diff] [blame] | 200 | atomic_t clks_on; /* Set if clocks are enabled */ |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 201 | struct sdhci_msm_pltfm_data *pdata; |
| 202 | struct mmc_host *mmc; |
| 203 | struct sdhci_pltfm_data sdhci_msm_pdata; |
Sahitya Tummala | 1f52eaa | 2013-03-20 19:24:01 +0530 | [diff] [blame] | 204 | u32 curr_pwr_state; |
| 205 | u32 curr_io_level; |
| 206 | struct completion pwr_irq_completion; |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 207 | struct sdhci_msm_bus_vote msm_bus_vote; |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 208 | u32 clk_rate; /* Keeps track of current clock rate that is set */ |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 209 | }; |
| 210 | |
| 211 | enum vdd_io_level { |
| 212 | /* set vdd_io_data->low_vol_level */ |
| 213 | VDD_IO_LOW, |
| 214 | /* set vdd_io_data->high_vol_level */ |
| 215 | VDD_IO_HIGH, |
| 216 | /* |
| 217 | * set whatever there in voltage_level (third argument) of |
| 218 | * sdhci_msm_set_vdd_io_vol() function. |
| 219 | */ |
| 220 | VDD_IO_SET_LEVEL, |
| 221 | }; |
| 222 | |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 223 | /* MSM platform specific tuning */ |
| 224 | static inline int msm_dll_poll_ck_out_en(struct sdhci_host *host, |
| 225 | u8 poll) |
| 226 | { |
| 227 | int rc = 0; |
| 228 | u32 wait_cnt = 50; |
| 229 | u8 ck_out_en = 0; |
| 230 | struct mmc_host *mmc = host->mmc; |
| 231 | |
| 232 | /* poll for CK_OUT_EN bit. max. poll time = 50us */ |
| 233 | ck_out_en = !!(readl_relaxed(host->ioaddr + CORE_DLL_CONFIG) & |
| 234 | CORE_CK_OUT_EN); |
| 235 | |
| 236 | while (ck_out_en != poll) { |
| 237 | if (--wait_cnt == 0) { |
| 238 | pr_err("%s: %s: CK_OUT_EN bit is not %d\n", |
| 239 | mmc_hostname(mmc), __func__, poll); |
| 240 | rc = -ETIMEDOUT; |
| 241 | goto out; |
| 242 | } |
| 243 | udelay(1); |
| 244 | |
| 245 | ck_out_en = !!(readl_relaxed(host->ioaddr + |
| 246 | CORE_DLL_CONFIG) & CORE_CK_OUT_EN); |
| 247 | } |
| 248 | out: |
| 249 | return rc; |
| 250 | } |
| 251 | |
| 252 | static int msm_config_cm_dll_phase(struct sdhci_host *host, u8 phase) |
| 253 | { |
| 254 | int rc = 0; |
| 255 | u8 grey_coded_phase_table[] = {0x0, 0x1, 0x3, 0x2, 0x6, 0x7, 0x5, 0x4, |
| 256 | 0xC, 0xD, 0xF, 0xE, 0xA, 0xB, 0x9, |
| 257 | 0x8}; |
| 258 | unsigned long flags; |
| 259 | u32 config; |
| 260 | struct mmc_host *mmc = host->mmc; |
| 261 | |
| 262 | pr_debug("%s: Enter %s\n", mmc_hostname(mmc), __func__); |
| 263 | spin_lock_irqsave(&host->lock, flags); |
| 264 | |
| 265 | config = readl_relaxed(host->ioaddr + CORE_DLL_CONFIG); |
| 266 | config &= ~(CORE_CDR_EN | CORE_CK_OUT_EN); |
| 267 | config |= (CORE_CDR_EXT_EN | CORE_DLL_EN); |
| 268 | writel_relaxed(config, host->ioaddr + CORE_DLL_CONFIG); |
| 269 | |
| 270 | /* Wait until CK_OUT_EN bit of DLL_CONFIG register becomes '0' */ |
| 271 | rc = msm_dll_poll_ck_out_en(host, 0); |
| 272 | if (rc) |
| 273 | goto err_out; |
| 274 | |
| 275 | /* |
| 276 | * Write the selected DLL clock output phase (0 ... 15) |
| 277 | * to CDR_SELEXT bit field of DLL_CONFIG register. |
| 278 | */ |
| 279 | writel_relaxed(((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG) |
| 280 | & ~(0xF << 20)) |
| 281 | | (grey_coded_phase_table[phase] << 20)), |
| 282 | host->ioaddr + CORE_DLL_CONFIG); |
| 283 | |
| 284 | /* Set CK_OUT_EN bit of DLL_CONFIG register to 1. */ |
| 285 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG) |
| 286 | | CORE_CK_OUT_EN), host->ioaddr + CORE_DLL_CONFIG); |
| 287 | |
| 288 | /* Wait until CK_OUT_EN bit of DLL_CONFIG register becomes '1' */ |
| 289 | rc = msm_dll_poll_ck_out_en(host, 1); |
| 290 | if (rc) |
| 291 | goto err_out; |
| 292 | |
| 293 | config = readl_relaxed(host->ioaddr + CORE_DLL_CONFIG); |
| 294 | config |= CORE_CDR_EN; |
| 295 | config &= ~CORE_CDR_EXT_EN; |
| 296 | writel_relaxed(config, host->ioaddr + CORE_DLL_CONFIG); |
| 297 | goto out; |
| 298 | |
| 299 | err_out: |
| 300 | pr_err("%s: %s: Failed to set DLL phase: %d\n", |
| 301 | mmc_hostname(mmc), __func__, phase); |
| 302 | out: |
| 303 | spin_unlock_irqrestore(&host->lock, flags); |
| 304 | pr_debug("%s: Exit %s\n", mmc_hostname(mmc), __func__); |
| 305 | return rc; |
| 306 | } |
| 307 | |
| 308 | /* |
| 309 | * Find out the greatest range of consecuitive selected |
| 310 | * DLL clock output phases that can be used as sampling |
| 311 | * setting for SD3.0 UHS-I card read operation (in SDR104 |
| 312 | * timing mode) or for eMMC4.5 card read operation (in HS200 |
| 313 | * timing mode). |
| 314 | * Select the 3/4 of the range and configure the DLL with the |
| 315 | * selected DLL clock output phase. |
| 316 | */ |
| 317 | |
| 318 | static int msm_find_most_appropriate_phase(struct sdhci_host *host, |
| 319 | u8 *phase_table, u8 total_phases) |
| 320 | { |
| 321 | int ret; |
| 322 | u8 ranges[MAX_PHASES][MAX_PHASES] = { {0}, {0} }; |
| 323 | u8 phases_per_row[MAX_PHASES] = {0}; |
| 324 | int row_index = 0, col_index = 0, selected_row_index = 0, curr_max = 0; |
| 325 | int i, cnt, phase_0_raw_index = 0, phase_15_raw_index = 0; |
| 326 | bool phase_0_found = false, phase_15_found = false; |
| 327 | struct mmc_host *mmc = host->mmc; |
| 328 | |
| 329 | pr_debug("%s: Enter %s\n", mmc_hostname(mmc), __func__); |
| 330 | if (!total_phases || (total_phases > MAX_PHASES)) { |
| 331 | pr_err("%s: %s: invalid argument: total_phases=%d\n", |
| 332 | mmc_hostname(mmc), __func__, total_phases); |
| 333 | return -EINVAL; |
| 334 | } |
| 335 | |
| 336 | for (cnt = 0; cnt < total_phases; cnt++) { |
| 337 | ranges[row_index][col_index] = phase_table[cnt]; |
| 338 | phases_per_row[row_index] += 1; |
| 339 | col_index++; |
| 340 | |
| 341 | if ((cnt + 1) == total_phases) { |
| 342 | continue; |
| 343 | /* check if next phase in phase_table is consecutive or not */ |
| 344 | } else if ((phase_table[cnt] + 1) != phase_table[cnt + 1]) { |
| 345 | row_index++; |
| 346 | col_index = 0; |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | if (row_index >= MAX_PHASES) |
| 351 | return -EINVAL; |
| 352 | |
| 353 | /* Check if phase-0 is present in first valid window? */ |
| 354 | if (!ranges[0][0]) { |
| 355 | phase_0_found = true; |
| 356 | phase_0_raw_index = 0; |
| 357 | /* Check if cycle exist between 2 valid windows */ |
| 358 | for (cnt = 1; cnt <= row_index; cnt++) { |
| 359 | if (phases_per_row[cnt]) { |
| 360 | for (i = 0; i < phases_per_row[cnt]; i++) { |
| 361 | if (ranges[cnt][i] == 15) { |
| 362 | phase_15_found = true; |
| 363 | phase_15_raw_index = cnt; |
| 364 | break; |
| 365 | } |
| 366 | } |
| 367 | } |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | /* If 2 valid windows form cycle then merge them as single window */ |
| 372 | if (phase_0_found && phase_15_found) { |
| 373 | /* number of phases in raw where phase 0 is present */ |
| 374 | u8 phases_0 = phases_per_row[phase_0_raw_index]; |
| 375 | /* number of phases in raw where phase 15 is present */ |
| 376 | u8 phases_15 = phases_per_row[phase_15_raw_index]; |
| 377 | |
| 378 | if (phases_0 + phases_15 >= MAX_PHASES) |
| 379 | /* |
| 380 | * If there are more than 1 phase windows then total |
| 381 | * number of phases in both the windows should not be |
| 382 | * more than or equal to MAX_PHASES. |
| 383 | */ |
| 384 | return -EINVAL; |
| 385 | |
| 386 | /* Merge 2 cyclic windows */ |
| 387 | i = phases_15; |
| 388 | for (cnt = 0; cnt < phases_0; cnt++) { |
| 389 | ranges[phase_15_raw_index][i] = |
| 390 | ranges[phase_0_raw_index][cnt]; |
| 391 | if (++i >= MAX_PHASES) |
| 392 | break; |
| 393 | } |
| 394 | |
| 395 | phases_per_row[phase_0_raw_index] = 0; |
| 396 | phases_per_row[phase_15_raw_index] = phases_15 + phases_0; |
| 397 | } |
| 398 | |
| 399 | for (cnt = 0; cnt <= row_index; cnt++) { |
| 400 | if (phases_per_row[cnt] > curr_max) { |
| 401 | curr_max = phases_per_row[cnt]; |
| 402 | selected_row_index = cnt; |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | i = ((curr_max * 3) / 4); |
| 407 | if (i) |
| 408 | i--; |
| 409 | |
| 410 | ret = (int)ranges[selected_row_index][i]; |
| 411 | |
| 412 | if (ret >= MAX_PHASES) { |
| 413 | ret = -EINVAL; |
| 414 | pr_err("%s: %s: invalid phase selected=%d\n", |
| 415 | mmc_hostname(mmc), __func__, ret); |
| 416 | } |
| 417 | |
| 418 | pr_debug("%s: Exit %s\n", mmc_hostname(mmc), __func__); |
| 419 | return ret; |
| 420 | } |
| 421 | |
| 422 | static inline void msm_cm_dll_set_freq(struct sdhci_host *host) |
| 423 | { |
| 424 | u32 mclk_freq = 0; |
| 425 | |
| 426 | /* Program the MCLK value to MCLK_FREQ bit field */ |
| 427 | if (host->clock <= 112000000) |
| 428 | mclk_freq = 0; |
| 429 | else if (host->clock <= 125000000) |
| 430 | mclk_freq = 1; |
| 431 | else if (host->clock <= 137000000) |
| 432 | mclk_freq = 2; |
| 433 | else if (host->clock <= 150000000) |
| 434 | mclk_freq = 3; |
| 435 | else if (host->clock <= 162000000) |
| 436 | mclk_freq = 4; |
| 437 | else if (host->clock <= 175000000) |
| 438 | mclk_freq = 5; |
| 439 | else if (host->clock <= 187000000) |
| 440 | mclk_freq = 6; |
| 441 | else if (host->clock <= 200000000) |
| 442 | mclk_freq = 7; |
| 443 | |
| 444 | writel_relaxed(((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG) |
| 445 | & ~(7 << 24)) | (mclk_freq << 24)), |
| 446 | host->ioaddr + CORE_DLL_CONFIG); |
| 447 | } |
| 448 | |
| 449 | /* Initialize the DLL (Programmable Delay Line ) */ |
| 450 | static int msm_init_cm_dll(struct sdhci_host *host) |
| 451 | { |
| 452 | struct mmc_host *mmc = host->mmc; |
| 453 | int rc = 0; |
| 454 | unsigned long flags; |
| 455 | u32 wait_cnt; |
| 456 | |
| 457 | pr_debug("%s: Enter %s\n", mmc_hostname(mmc), __func__); |
| 458 | spin_lock_irqsave(&host->lock, flags); |
| 459 | |
| 460 | /* |
| 461 | * Make sure that clock is always enabled when DLL |
| 462 | * tuning is in progress. Keeping PWRSAVE ON may |
| 463 | * turn off the clock. So let's disable the PWRSAVE |
| 464 | * here and re-enable it once tuning is completed. |
| 465 | */ |
| 466 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_VENDOR_SPEC) |
| 467 | & ~CORE_CLK_PWRSAVE), |
| 468 | host->ioaddr + CORE_VENDOR_SPEC); |
| 469 | |
| 470 | /* Write 1 to DLL_RST bit of DLL_CONFIG register */ |
| 471 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG) |
| 472 | | CORE_DLL_RST), host->ioaddr + CORE_DLL_CONFIG); |
| 473 | |
| 474 | /* Write 1 to DLL_PDN bit of DLL_CONFIG register */ |
| 475 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG) |
| 476 | | CORE_DLL_PDN), host->ioaddr + CORE_DLL_CONFIG); |
| 477 | msm_cm_dll_set_freq(host); |
| 478 | |
| 479 | /* Write 0 to DLL_RST bit of DLL_CONFIG register */ |
| 480 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG) |
| 481 | & ~CORE_DLL_RST), host->ioaddr + CORE_DLL_CONFIG); |
| 482 | |
| 483 | /* Write 0 to DLL_PDN bit of DLL_CONFIG register */ |
| 484 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG) |
| 485 | & ~CORE_DLL_PDN), host->ioaddr + CORE_DLL_CONFIG); |
| 486 | |
| 487 | /* Set DLL_EN bit to 1. */ |
| 488 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG) |
| 489 | | CORE_DLL_EN), host->ioaddr + CORE_DLL_CONFIG); |
| 490 | |
| 491 | /* Set CK_OUT_EN bit to 1. */ |
| 492 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG) |
| 493 | | CORE_CK_OUT_EN), host->ioaddr + CORE_DLL_CONFIG); |
| 494 | |
| 495 | wait_cnt = 50; |
| 496 | /* Wait until DLL_LOCK bit of DLL_STATUS register becomes '1' */ |
| 497 | while (!(readl_relaxed(host->ioaddr + CORE_DLL_STATUS) & |
| 498 | CORE_DLL_LOCK)) { |
| 499 | /* max. wait for 50us sec for LOCK bit to be set */ |
| 500 | if (--wait_cnt == 0) { |
| 501 | pr_err("%s: %s: DLL failed to LOCK\n", |
| 502 | mmc_hostname(mmc), __func__); |
| 503 | rc = -ETIMEDOUT; |
| 504 | goto out; |
| 505 | } |
| 506 | /* wait for 1us before polling again */ |
| 507 | udelay(1); |
| 508 | } |
| 509 | |
| 510 | out: |
| 511 | /* re-enable PWRSAVE */ |
| 512 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_VENDOR_SPEC) | |
| 513 | CORE_CLK_PWRSAVE), |
| 514 | host->ioaddr + CORE_VENDOR_SPEC); |
| 515 | spin_unlock_irqrestore(&host->lock, flags); |
| 516 | pr_debug("%s: Exit %s\n", mmc_hostname(mmc), __func__); |
| 517 | return rc; |
| 518 | } |
| 519 | |
| 520 | int sdhci_msm_execute_tuning(struct sdhci_host *host, u32 opcode) |
| 521 | { |
| 522 | unsigned long flags; |
| 523 | u8 phase, *data_buf, tuned_phases[16], tuned_phase_cnt = 0; |
| 524 | const u32 *tuning_block_pattern = tuning_block_64; |
| 525 | int size = sizeof(tuning_block_64); /* Tuning pattern size in bytes */ |
| 526 | int rc; |
| 527 | struct mmc_host *mmc = host->mmc; |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 528 | struct mmc_ios ios = host->mmc->ios; |
| 529 | |
| 530 | /* |
| 531 | * Tuning is required for SDR104 and HS200 cards and if clock frequency |
| 532 | * is greater than 100MHz in these modes. |
| 533 | */ |
| 534 | if (host->clock <= (100 * 1000 * 1000) || |
| 535 | !(ios.timing == MMC_TIMING_MMC_HS200 || |
| 536 | ios.timing == MMC_TIMING_UHS_SDR104)) |
| 537 | return 0; |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 538 | |
| 539 | pr_debug("%s: Enter %s\n", mmc_hostname(mmc), __func__); |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 540 | spin_lock_irqsave(&host->lock, flags); |
| 541 | |
| 542 | if ((opcode == MMC_SEND_TUNING_BLOCK_HS200) && |
| 543 | (mmc->ios.bus_width == MMC_BUS_WIDTH_8)) { |
| 544 | tuning_block_pattern = tuning_block_128; |
| 545 | size = sizeof(tuning_block_128); |
| 546 | } |
| 547 | spin_unlock_irqrestore(&host->lock, flags); |
| 548 | |
| 549 | /* first of all reset the tuning block */ |
| 550 | rc = msm_init_cm_dll(host); |
| 551 | if (rc) |
| 552 | goto out; |
| 553 | |
| 554 | data_buf = kmalloc(size, GFP_KERNEL); |
| 555 | if (!data_buf) { |
| 556 | rc = -ENOMEM; |
| 557 | goto out; |
| 558 | } |
| 559 | |
| 560 | phase = 0; |
| 561 | do { |
| 562 | struct mmc_command cmd = {0}; |
| 563 | struct mmc_data data = {0}; |
| 564 | struct mmc_request mrq = { |
| 565 | .cmd = &cmd, |
| 566 | .data = &data |
| 567 | }; |
| 568 | struct scatterlist sg; |
| 569 | |
| 570 | /* set the phase in delay line hw block */ |
| 571 | rc = msm_config_cm_dll_phase(host, phase); |
| 572 | if (rc) |
| 573 | goto kfree; |
| 574 | |
| 575 | cmd.opcode = opcode; |
| 576 | cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; |
| 577 | |
| 578 | data.blksz = size; |
| 579 | data.blocks = 1; |
| 580 | data.flags = MMC_DATA_READ; |
| 581 | data.timeout_ns = 1000 * 1000 * 1000; /* 1 sec */ |
| 582 | |
| 583 | data.sg = &sg; |
| 584 | data.sg_len = 1; |
| 585 | sg_init_one(&sg, data_buf, size); |
| 586 | memset(data_buf, 0, size); |
| 587 | mmc_wait_for_req(mmc, &mrq); |
| 588 | |
| 589 | if (!cmd.error && !data.error && |
| 590 | !memcmp(data_buf, tuning_block_pattern, size)) { |
| 591 | /* tuning is successful at this tuning point */ |
| 592 | tuned_phases[tuned_phase_cnt++] = phase; |
| 593 | pr_debug("%s: %s: found good phase = %d\n", |
| 594 | mmc_hostname(mmc), __func__, phase); |
| 595 | } |
| 596 | } while (++phase < 16); |
| 597 | |
| 598 | if (tuned_phase_cnt) { |
| 599 | rc = msm_find_most_appropriate_phase(host, tuned_phases, |
| 600 | tuned_phase_cnt); |
| 601 | if (rc < 0) |
| 602 | goto kfree; |
| 603 | else |
| 604 | phase = (u8)rc; |
| 605 | |
| 606 | /* |
| 607 | * Finally set the selected phase in delay |
| 608 | * line hw block. |
| 609 | */ |
| 610 | rc = msm_config_cm_dll_phase(host, phase); |
| 611 | if (rc) |
| 612 | goto kfree; |
| 613 | pr_debug("%s: %s: finally setting the tuning phase to %d\n", |
| 614 | mmc_hostname(mmc), __func__, phase); |
| 615 | } else { |
| 616 | /* tuning failed */ |
| 617 | pr_err("%s: %s: no tuning point found\n", |
| 618 | mmc_hostname(mmc), __func__); |
| 619 | rc = -EAGAIN; |
| 620 | } |
| 621 | |
| 622 | kfree: |
| 623 | kfree(data_buf); |
| 624 | out: |
| 625 | pr_debug("%s: Exit %s\n", mmc_hostname(mmc), __func__); |
| 626 | return rc; |
| 627 | } |
| 628 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 629 | static int sdhci_msm_setup_gpio(struct sdhci_msm_pltfm_data *pdata, bool enable) |
| 630 | { |
| 631 | struct sdhci_msm_gpio_data *curr; |
| 632 | int i, ret = 0; |
| 633 | |
| 634 | curr = pdata->pin_data->gpio_data; |
| 635 | for (i = 0; i < curr->size; i++) { |
| 636 | if (!gpio_is_valid(curr->gpio[i].no)) { |
| 637 | ret = -EINVAL; |
| 638 | pr_err("%s: Invalid gpio = %d\n", __func__, |
| 639 | curr->gpio[i].no); |
| 640 | goto free_gpios; |
| 641 | } |
| 642 | if (enable) { |
| 643 | ret = gpio_request(curr->gpio[i].no, |
| 644 | curr->gpio[i].name); |
| 645 | if (ret) { |
| 646 | pr_err("%s: gpio_request(%d, %s) failed %d\n", |
| 647 | __func__, curr->gpio[i].no, |
| 648 | curr->gpio[i].name, ret); |
| 649 | goto free_gpios; |
| 650 | } |
| 651 | curr->gpio[i].is_enabled = true; |
| 652 | } else { |
| 653 | gpio_free(curr->gpio[i].no); |
| 654 | curr->gpio[i].is_enabled = false; |
| 655 | } |
| 656 | } |
| 657 | return ret; |
| 658 | |
| 659 | free_gpios: |
| 660 | for (i--; i >= 0; i--) { |
| 661 | gpio_free(curr->gpio[i].no); |
| 662 | curr->gpio[i].is_enabled = false; |
| 663 | } |
| 664 | return ret; |
| 665 | } |
| 666 | |
| 667 | static int sdhci_msm_setup_pins(struct sdhci_msm_pltfm_data *pdata, bool enable) |
| 668 | { |
| 669 | int ret = 0; |
| 670 | |
| 671 | if (!pdata->pin_data || (pdata->pin_data->cfg_sts == enable)) |
| 672 | return 0; |
| 673 | |
| 674 | ret = sdhci_msm_setup_gpio(pdata, enable); |
| 675 | if (!ret) |
| 676 | pdata->pin_data->cfg_sts = enable; |
| 677 | |
| 678 | return ret; |
| 679 | } |
| 680 | |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 681 | static int sdhci_msm_dt_get_array(struct device *dev, const char *prop_name, |
| 682 | u32 **out, int *len, u32 size) |
| 683 | { |
| 684 | int ret = 0; |
| 685 | struct device_node *np = dev->of_node; |
| 686 | size_t sz; |
| 687 | u32 *arr = NULL; |
| 688 | |
| 689 | if (!of_get_property(np, prop_name, len)) { |
| 690 | ret = -EINVAL; |
| 691 | goto out; |
| 692 | } |
| 693 | sz = *len = *len / sizeof(*arr); |
| 694 | if (sz <= 0 || (size > 0 && (sz != size))) { |
| 695 | dev_err(dev, "%s invalid size\n", prop_name); |
| 696 | ret = -EINVAL; |
| 697 | goto out; |
| 698 | } |
| 699 | |
| 700 | arr = devm_kzalloc(dev, sz * sizeof(*arr), GFP_KERNEL); |
| 701 | if (!arr) { |
| 702 | dev_err(dev, "%s failed allocating memory\n", prop_name); |
| 703 | ret = -ENOMEM; |
| 704 | goto out; |
| 705 | } |
| 706 | |
| 707 | ret = of_property_read_u32_array(np, prop_name, arr, sz); |
| 708 | if (ret < 0) { |
| 709 | dev_err(dev, "%s failed reading array %d\n", prop_name, ret); |
| 710 | goto out; |
| 711 | } |
| 712 | *out = arr; |
| 713 | out: |
| 714 | if (ret) |
| 715 | *len = 0; |
| 716 | return ret; |
| 717 | } |
| 718 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 719 | #define MAX_PROP_SIZE 32 |
| 720 | static int sdhci_msm_dt_parse_vreg_info(struct device *dev, |
| 721 | struct sdhci_msm_reg_data **vreg_data, const char *vreg_name) |
| 722 | { |
| 723 | int len, ret = 0; |
| 724 | const __be32 *prop; |
| 725 | char prop_name[MAX_PROP_SIZE]; |
| 726 | struct sdhci_msm_reg_data *vreg; |
| 727 | struct device_node *np = dev->of_node; |
| 728 | |
| 729 | snprintf(prop_name, MAX_PROP_SIZE, "%s-supply", vreg_name); |
| 730 | if (!of_parse_phandle(np, prop_name, 0)) { |
| 731 | dev_err(dev, "No vreg data found for %s\n", vreg_name); |
| 732 | ret = -EINVAL; |
| 733 | return ret; |
| 734 | } |
| 735 | |
| 736 | vreg = devm_kzalloc(dev, sizeof(*vreg), GFP_KERNEL); |
| 737 | if (!vreg) { |
| 738 | dev_err(dev, "No memory for vreg: %s\n", vreg_name); |
| 739 | ret = -ENOMEM; |
| 740 | return ret; |
| 741 | } |
| 742 | |
| 743 | vreg->name = vreg_name; |
| 744 | |
| 745 | snprintf(prop_name, MAX_PROP_SIZE, |
| 746 | "qcom,%s-always-on", vreg_name); |
| 747 | if (of_get_property(np, prop_name, NULL)) |
| 748 | vreg->is_always_on = true; |
| 749 | |
| 750 | snprintf(prop_name, MAX_PROP_SIZE, |
| 751 | "qcom,%s-lpm-sup", vreg_name); |
| 752 | if (of_get_property(np, prop_name, NULL)) |
| 753 | vreg->lpm_sup = true; |
| 754 | |
| 755 | snprintf(prop_name, MAX_PROP_SIZE, |
| 756 | "qcom,%s-voltage-level", vreg_name); |
| 757 | prop = of_get_property(np, prop_name, &len); |
| 758 | if (!prop || (len != (2 * sizeof(__be32)))) { |
| 759 | dev_warn(dev, "%s %s property\n", |
| 760 | prop ? "invalid format" : "no", prop_name); |
| 761 | } else { |
| 762 | vreg->low_vol_level = be32_to_cpup(&prop[0]); |
| 763 | vreg->high_vol_level = be32_to_cpup(&prop[1]); |
| 764 | } |
| 765 | |
| 766 | snprintf(prop_name, MAX_PROP_SIZE, |
| 767 | "qcom,%s-current-level", vreg_name); |
| 768 | prop = of_get_property(np, prop_name, &len); |
| 769 | if (!prop || (len != (2 * sizeof(__be32)))) { |
| 770 | dev_warn(dev, "%s %s property\n", |
| 771 | prop ? "invalid format" : "no", prop_name); |
| 772 | } else { |
| 773 | vreg->lpm_uA = be32_to_cpup(&prop[0]); |
| 774 | vreg->hpm_uA = be32_to_cpup(&prop[1]); |
| 775 | } |
| 776 | |
| 777 | *vreg_data = vreg; |
| 778 | dev_dbg(dev, "%s: %s %s vol=[%d %d]uV, curr=[%d %d]uA\n", |
| 779 | vreg->name, vreg->is_always_on ? "always_on," : "", |
| 780 | vreg->lpm_sup ? "lpm_sup," : "", vreg->low_vol_level, |
| 781 | vreg->high_vol_level, vreg->lpm_uA, vreg->hpm_uA); |
| 782 | |
| 783 | return ret; |
| 784 | } |
| 785 | |
| 786 | #define GPIO_NAME_MAX_LEN 32 |
| 787 | static int sdhci_msm_dt_parse_gpio_info(struct device *dev, |
| 788 | struct sdhci_msm_pltfm_data *pdata) |
| 789 | { |
| 790 | int ret = 0, cnt, i; |
| 791 | struct sdhci_msm_pin_data *pin_data; |
| 792 | struct device_node *np = dev->of_node; |
| 793 | |
| 794 | pin_data = devm_kzalloc(dev, sizeof(*pin_data), GFP_KERNEL); |
| 795 | if (!pin_data) { |
| 796 | dev_err(dev, "No memory for pin_data\n"); |
| 797 | ret = -ENOMEM; |
| 798 | goto out; |
| 799 | } |
| 800 | |
| 801 | cnt = of_gpio_count(np); |
| 802 | if (cnt > 0) { |
| 803 | pin_data->gpio_data = devm_kzalloc(dev, |
| 804 | sizeof(struct sdhci_msm_gpio_data), GFP_KERNEL); |
| 805 | if (!pin_data->gpio_data) { |
| 806 | dev_err(dev, "No memory for gpio_data\n"); |
| 807 | ret = -ENOMEM; |
| 808 | goto out; |
| 809 | } |
| 810 | pin_data->gpio_data->size = cnt; |
| 811 | pin_data->gpio_data->gpio = devm_kzalloc(dev, cnt * |
| 812 | sizeof(struct sdhci_msm_gpio), GFP_KERNEL); |
| 813 | |
| 814 | if (!pin_data->gpio_data->gpio) { |
| 815 | dev_err(dev, "No memory for gpio\n"); |
| 816 | ret = -ENOMEM; |
| 817 | goto out; |
| 818 | } |
| 819 | |
| 820 | for (i = 0; i < cnt; i++) { |
| 821 | const char *name = NULL; |
| 822 | char result[GPIO_NAME_MAX_LEN]; |
| 823 | pin_data->gpio_data->gpio[i].no = of_get_gpio(np, i); |
| 824 | of_property_read_string_index(np, |
| 825 | "qcom,gpio-names", i, &name); |
| 826 | |
| 827 | snprintf(result, GPIO_NAME_MAX_LEN, "%s-%s", |
| 828 | dev_name(dev), name ? name : "?"); |
| 829 | pin_data->gpio_data->gpio[i].name = result; |
| 830 | dev_dbg(dev, "%s: gpio[%s] = %d\n", __func__, |
| 831 | pin_data->gpio_data->gpio[i].name, |
| 832 | pin_data->gpio_data->gpio[i].no); |
| 833 | pdata->pin_data = pin_data; |
| 834 | } |
| 835 | } |
| 836 | |
| 837 | out: |
| 838 | if (ret) |
| 839 | dev_err(dev, "%s failed with err %d\n", __func__, ret); |
| 840 | return ret; |
| 841 | } |
| 842 | |
| 843 | /* Parse platform data */ |
| 844 | static struct sdhci_msm_pltfm_data *sdhci_msm_populate_pdata(struct device *dev) |
| 845 | { |
| 846 | struct sdhci_msm_pltfm_data *pdata = NULL; |
| 847 | struct device_node *np = dev->of_node; |
| 848 | u32 bus_width = 0; |
Sahitya Tummala | c6f48d4 | 2013-03-10 07:03:17 +0530 | [diff] [blame] | 849 | u32 cpu_dma_latency; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 850 | int len, i; |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 851 | int clk_table_len; |
| 852 | u32 *clk_table = NULL; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 853 | |
| 854 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); |
| 855 | if (!pdata) { |
| 856 | dev_err(dev, "failed to allocate memory for platform data\n"); |
| 857 | goto out; |
| 858 | } |
| 859 | |
Sahitya Tummala | 581df13 | 2013-03-12 14:57:46 +0530 | [diff] [blame] | 860 | pdata->status_gpio = of_get_named_gpio_flags(np, "cd-gpios", 0, 0); |
| 861 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 862 | of_property_read_u32(np, "qcom,bus-width", &bus_width); |
| 863 | if (bus_width == 8) |
| 864 | pdata->mmc_bus_width = MMC_CAP_8_BIT_DATA; |
| 865 | else if (bus_width == 4) |
| 866 | pdata->mmc_bus_width = MMC_CAP_4_BIT_DATA; |
| 867 | else { |
| 868 | dev_notice(dev, "invalid bus-width, default to 1-bit mode\n"); |
| 869 | pdata->mmc_bus_width = 0; |
| 870 | } |
| 871 | |
Sahitya Tummala | c6f48d4 | 2013-03-10 07:03:17 +0530 | [diff] [blame] | 872 | if (!of_property_read_u32(np, "qcom,cpu-dma-latency-us", |
| 873 | &cpu_dma_latency)) |
| 874 | pdata->cpu_dma_latency_us = cpu_dma_latency; |
| 875 | |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 876 | if (sdhci_msm_dt_get_array(dev, "qcom,clk-rates", |
| 877 | &clk_table, &clk_table_len, 0)) { |
| 878 | dev_err(dev, "failed parsing supported clock rates\n"); |
| 879 | goto out; |
| 880 | } |
| 881 | if (!clk_table || !clk_table_len) { |
| 882 | dev_err(dev, "Invalid clock table\n"); |
| 883 | goto out; |
| 884 | } |
| 885 | pdata->sup_clk_table = clk_table; |
| 886 | pdata->sup_clk_cnt = clk_table_len; |
| 887 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 888 | pdata->vreg_data = devm_kzalloc(dev, sizeof(struct |
| 889 | sdhci_msm_slot_reg_data), |
| 890 | GFP_KERNEL); |
| 891 | if (!pdata->vreg_data) { |
| 892 | dev_err(dev, "failed to allocate memory for vreg data\n"); |
| 893 | goto out; |
| 894 | } |
| 895 | |
| 896 | if (sdhci_msm_dt_parse_vreg_info(dev, &pdata->vreg_data->vdd_data, |
| 897 | "vdd")) { |
| 898 | dev_err(dev, "failed parsing vdd data\n"); |
| 899 | goto out; |
| 900 | } |
| 901 | if (sdhci_msm_dt_parse_vreg_info(dev, |
| 902 | &pdata->vreg_data->vdd_io_data, |
| 903 | "vdd-io")) { |
| 904 | dev_err(dev, "failed parsing vdd-io data\n"); |
| 905 | goto out; |
| 906 | } |
| 907 | |
| 908 | if (sdhci_msm_dt_parse_gpio_info(dev, pdata)) { |
| 909 | dev_err(dev, "failed parsing gpio data\n"); |
| 910 | goto out; |
| 911 | } |
| 912 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 913 | len = of_property_count_strings(np, "qcom,bus-speed-mode"); |
| 914 | |
| 915 | for (i = 0; i < len; i++) { |
| 916 | const char *name = NULL; |
| 917 | |
| 918 | of_property_read_string_index(np, |
| 919 | "qcom,bus-speed-mode", i, &name); |
| 920 | if (!name) |
| 921 | continue; |
| 922 | |
| 923 | if (!strncmp(name, "HS200_1p8v", sizeof("HS200_1p8v"))) |
| 924 | pdata->caps2 |= MMC_CAP2_HS200_1_8V_SDR; |
| 925 | else if (!strncmp(name, "HS200_1p2v", sizeof("HS200_1p2v"))) |
| 926 | pdata->caps2 |= MMC_CAP2_HS200_1_2V_SDR; |
| 927 | else if (!strncmp(name, "DDR_1p8v", sizeof("DDR_1p8v"))) |
| 928 | pdata->caps |= MMC_CAP_1_8V_DDR |
| 929 | | MMC_CAP_UHS_DDR50; |
| 930 | else if (!strncmp(name, "DDR_1p2v", sizeof("DDR_1p2v"))) |
| 931 | pdata->caps |= MMC_CAP_1_2V_DDR |
| 932 | | MMC_CAP_UHS_DDR50; |
| 933 | } |
| 934 | |
| 935 | if (of_get_property(np, "qcom,nonremovable", NULL)) |
| 936 | pdata->nonremovable = true; |
| 937 | |
| 938 | return pdata; |
| 939 | out: |
| 940 | return NULL; |
| 941 | } |
| 942 | |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 943 | /* Returns required bandwidth in Bytes per Sec */ |
| 944 | static unsigned int sdhci_get_bw_required(struct sdhci_host *host, |
| 945 | struct mmc_ios *ios) |
| 946 | { |
Sahitya Tummala | 2886c92 | 2013-04-03 18:03:31 +0530 | [diff] [blame] | 947 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 948 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
| 949 | |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 950 | unsigned int bw; |
| 951 | |
Sahitya Tummala | 2886c92 | 2013-04-03 18:03:31 +0530 | [diff] [blame] | 952 | bw = msm_host->clk_rate; |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 953 | /* |
| 954 | * For DDR mode, SDCC controller clock will be at |
| 955 | * the double rate than the actual clock that goes to card. |
| 956 | */ |
| 957 | if (ios->bus_width == MMC_BUS_WIDTH_4) |
| 958 | bw /= 2; |
| 959 | else if (ios->bus_width == MMC_BUS_WIDTH_1) |
| 960 | bw /= 8; |
| 961 | |
| 962 | return bw; |
| 963 | } |
| 964 | |
| 965 | static int sdhci_msm_bus_get_vote_for_bw(struct sdhci_msm_host *host, |
| 966 | unsigned int bw) |
| 967 | { |
| 968 | unsigned int *table = host->pdata->voting_data->bw_vecs; |
| 969 | unsigned int size = host->pdata->voting_data->bw_vecs_size; |
| 970 | int i; |
| 971 | |
| 972 | if (host->msm_bus_vote.is_max_bw_needed && bw) |
| 973 | return host->msm_bus_vote.max_bw_vote; |
| 974 | |
| 975 | for (i = 0; i < size; i++) { |
| 976 | if (bw <= table[i]) |
| 977 | break; |
| 978 | } |
| 979 | |
| 980 | if (i && (i == size)) |
| 981 | i--; |
| 982 | |
| 983 | return i; |
| 984 | } |
| 985 | |
| 986 | /* |
| 987 | * This function must be called with host lock acquired. |
| 988 | * Caller of this function should also ensure that msm bus client |
| 989 | * handle is not null. |
| 990 | */ |
| 991 | static inline int sdhci_msm_bus_set_vote(struct sdhci_msm_host *msm_host, |
| 992 | int vote, |
| 993 | unsigned long flags) |
| 994 | { |
| 995 | struct sdhci_host *host = platform_get_drvdata(msm_host->pdev); |
| 996 | int rc = 0; |
| 997 | |
| 998 | if (vote != msm_host->msm_bus_vote.curr_vote) { |
| 999 | spin_unlock_irqrestore(&host->lock, flags); |
| 1000 | rc = msm_bus_scale_client_update_request( |
| 1001 | msm_host->msm_bus_vote.client_handle, vote); |
| 1002 | spin_lock_irqsave(&host->lock, flags); |
| 1003 | if (rc) { |
| 1004 | pr_err("%s: msm_bus_scale_client_update_request() failed: bus_client_handle=0x%x, vote=%d, err=%d\n", |
| 1005 | mmc_hostname(host->mmc), |
| 1006 | msm_host->msm_bus_vote.client_handle, vote, rc); |
| 1007 | goto out; |
| 1008 | } |
| 1009 | msm_host->msm_bus_vote.curr_vote = vote; |
| 1010 | } |
| 1011 | out: |
| 1012 | return rc; |
| 1013 | } |
| 1014 | |
| 1015 | /* |
| 1016 | * Internal work. Work to set 0 bandwidth for msm bus. |
| 1017 | */ |
| 1018 | static void sdhci_msm_bus_work(struct work_struct *work) |
| 1019 | { |
| 1020 | struct sdhci_msm_host *msm_host; |
| 1021 | struct sdhci_host *host; |
| 1022 | unsigned long flags; |
| 1023 | |
| 1024 | msm_host = container_of(work, struct sdhci_msm_host, |
| 1025 | msm_bus_vote.vote_work.work); |
| 1026 | host = platform_get_drvdata(msm_host->pdev); |
| 1027 | |
| 1028 | if (!msm_host->msm_bus_vote.client_handle) |
| 1029 | return; |
| 1030 | |
| 1031 | spin_lock_irqsave(&host->lock, flags); |
| 1032 | /* don't vote for 0 bandwidth if any request is in progress */ |
| 1033 | if (!host->mrq) { |
| 1034 | sdhci_msm_bus_set_vote(msm_host, |
| 1035 | msm_host->msm_bus_vote.min_bw_vote, flags); |
| 1036 | } else |
| 1037 | pr_warning("%s: %s: Transfer in progress. skipping bus voting to 0 bandwidth\n", |
| 1038 | mmc_hostname(host->mmc), __func__); |
| 1039 | spin_unlock_irqrestore(&host->lock, flags); |
| 1040 | } |
| 1041 | |
| 1042 | /* |
| 1043 | * This function cancels any scheduled delayed work and sets the bus |
| 1044 | * vote based on bw (bandwidth) argument. |
| 1045 | */ |
| 1046 | static void sdhci_msm_bus_cancel_work_and_set_vote(struct sdhci_host *host, |
| 1047 | unsigned int bw) |
| 1048 | { |
| 1049 | int vote; |
| 1050 | unsigned long flags; |
| 1051 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 1052 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
| 1053 | |
| 1054 | cancel_delayed_work_sync(&msm_host->msm_bus_vote.vote_work); |
| 1055 | spin_lock_irqsave(&host->lock, flags); |
| 1056 | vote = sdhci_msm_bus_get_vote_for_bw(msm_host, bw); |
| 1057 | sdhci_msm_bus_set_vote(msm_host, vote, flags); |
| 1058 | spin_unlock_irqrestore(&host->lock, flags); |
| 1059 | } |
| 1060 | |
| 1061 | #define MSM_MMC_BUS_VOTING_DELAY 200 /* msecs */ |
| 1062 | |
| 1063 | /* This function queues a work which will set the bandwidth requiement to 0 */ |
| 1064 | static void sdhci_msm_bus_queue_work(struct sdhci_host *host) |
| 1065 | { |
| 1066 | unsigned long flags; |
| 1067 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 1068 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
| 1069 | |
| 1070 | spin_lock_irqsave(&host->lock, flags); |
| 1071 | if (msm_host->msm_bus_vote.min_bw_vote != |
| 1072 | msm_host->msm_bus_vote.curr_vote) |
| 1073 | queue_delayed_work(system_wq, |
| 1074 | &msm_host->msm_bus_vote.vote_work, |
| 1075 | msecs_to_jiffies(MSM_MMC_BUS_VOTING_DELAY)); |
| 1076 | spin_unlock_irqrestore(&host->lock, flags); |
| 1077 | } |
| 1078 | |
| 1079 | static int sdhci_msm_bus_register(struct sdhci_msm_host *host, |
| 1080 | struct platform_device *pdev) |
| 1081 | { |
| 1082 | int rc = 0; |
| 1083 | struct msm_bus_scale_pdata *bus_pdata; |
| 1084 | |
| 1085 | struct sdhci_msm_bus_voting_data *data; |
| 1086 | struct device *dev = &pdev->dev; |
| 1087 | |
| 1088 | data = devm_kzalloc(dev, |
| 1089 | sizeof(struct sdhci_msm_bus_voting_data), GFP_KERNEL); |
| 1090 | if (!data) { |
| 1091 | dev_err(&pdev->dev, |
| 1092 | "%s: failed to allocate memory\n", __func__); |
| 1093 | rc = -ENOMEM; |
| 1094 | goto out; |
| 1095 | } |
| 1096 | data->bus_pdata = msm_bus_cl_get_pdata(pdev); |
| 1097 | if (data->bus_pdata) { |
| 1098 | rc = sdhci_msm_dt_get_array(dev, "qcom,bus-bw-vectors-bps", |
| 1099 | &data->bw_vecs, &data->bw_vecs_size, 0); |
| 1100 | if (rc) { |
| 1101 | dev_err(&pdev->dev, |
| 1102 | "%s: Failed to get bus-bw-vectors-bps\n", |
| 1103 | __func__); |
| 1104 | goto out; |
| 1105 | } |
| 1106 | host->pdata->voting_data = data; |
| 1107 | } |
| 1108 | if (host->pdata->voting_data && |
| 1109 | host->pdata->voting_data->bus_pdata && |
| 1110 | host->pdata->voting_data->bw_vecs && |
| 1111 | host->pdata->voting_data->bw_vecs_size) { |
| 1112 | |
| 1113 | bus_pdata = host->pdata->voting_data->bus_pdata; |
| 1114 | host->msm_bus_vote.client_handle = |
| 1115 | msm_bus_scale_register_client(bus_pdata); |
| 1116 | if (!host->msm_bus_vote.client_handle) { |
| 1117 | dev_err(&pdev->dev, "msm_bus_scale_register_client()\n"); |
| 1118 | rc = -EFAULT; |
| 1119 | goto out; |
| 1120 | } |
| 1121 | /* cache the vote index for minimum and maximum bandwidth */ |
| 1122 | host->msm_bus_vote.min_bw_vote = |
| 1123 | sdhci_msm_bus_get_vote_for_bw(host, 0); |
| 1124 | host->msm_bus_vote.max_bw_vote = |
| 1125 | sdhci_msm_bus_get_vote_for_bw(host, UINT_MAX); |
| 1126 | } else { |
| 1127 | devm_kfree(dev, data); |
| 1128 | } |
| 1129 | |
| 1130 | out: |
| 1131 | return rc; |
| 1132 | } |
| 1133 | |
| 1134 | static void sdhci_msm_bus_unregister(struct sdhci_msm_host *host) |
| 1135 | { |
| 1136 | if (host->msm_bus_vote.client_handle) |
| 1137 | msm_bus_scale_unregister_client( |
| 1138 | host->msm_bus_vote.client_handle); |
| 1139 | } |
| 1140 | |
| 1141 | static void sdhci_msm_bus_voting(struct sdhci_host *host, u32 enable) |
| 1142 | { |
| 1143 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 1144 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
| 1145 | struct mmc_ios *ios = &host->mmc->ios; |
| 1146 | unsigned int bw; |
| 1147 | |
| 1148 | if (!msm_host->msm_bus_vote.client_handle) |
| 1149 | return; |
| 1150 | |
| 1151 | bw = sdhci_get_bw_required(host, ios); |
| 1152 | if (enable) |
| 1153 | sdhci_msm_bus_cancel_work_and_set_vote(host, bw); |
| 1154 | else |
| 1155 | sdhci_msm_bus_queue_work(host); |
| 1156 | } |
| 1157 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1158 | /* Regulator utility functions */ |
| 1159 | static int sdhci_msm_vreg_init_reg(struct device *dev, |
| 1160 | struct sdhci_msm_reg_data *vreg) |
| 1161 | { |
| 1162 | int ret = 0; |
| 1163 | |
| 1164 | /* check if regulator is already initialized? */ |
| 1165 | if (vreg->reg) |
| 1166 | goto out; |
| 1167 | |
| 1168 | /* Get the regulator handle */ |
| 1169 | vreg->reg = devm_regulator_get(dev, vreg->name); |
| 1170 | if (IS_ERR(vreg->reg)) { |
| 1171 | ret = PTR_ERR(vreg->reg); |
| 1172 | pr_err("%s: devm_regulator_get(%s) failed. ret=%d\n", |
| 1173 | __func__, vreg->name, ret); |
| 1174 | goto out; |
| 1175 | } |
| 1176 | |
| 1177 | /* sanity check */ |
| 1178 | if (!vreg->high_vol_level || !vreg->hpm_uA) { |
| 1179 | pr_err("%s: %s invalid constraints specified\n", |
| 1180 | __func__, vreg->name); |
| 1181 | ret = -EINVAL; |
| 1182 | } |
| 1183 | |
| 1184 | out: |
| 1185 | return ret; |
| 1186 | } |
| 1187 | |
| 1188 | static void sdhci_msm_vreg_deinit_reg(struct sdhci_msm_reg_data *vreg) |
| 1189 | { |
| 1190 | if (vreg->reg) |
| 1191 | devm_regulator_put(vreg->reg); |
| 1192 | } |
| 1193 | |
| 1194 | static int sdhci_msm_vreg_set_optimum_mode(struct sdhci_msm_reg_data |
| 1195 | *vreg, int uA_load) |
| 1196 | { |
| 1197 | int ret = 0; |
| 1198 | |
| 1199 | /* |
| 1200 | * regulators that do not support regulator_set_voltage also |
| 1201 | * do not support regulator_set_optimum_mode |
| 1202 | */ |
| 1203 | if (vreg->set_voltage_sup) { |
| 1204 | ret = regulator_set_load(vreg->reg, uA_load); |
| 1205 | if (ret < 0) |
| 1206 | pr_err("%s: regulator_set_load(reg=%s,uA_load=%d) failed. ret=%d\n", |
| 1207 | __func__, vreg->name, uA_load, ret); |
| 1208 | else |
| 1209 | /* |
| 1210 | * regulator_set_load() can return non zero |
| 1211 | * value even for success case. |
| 1212 | */ |
| 1213 | ret = 0; |
| 1214 | } |
| 1215 | return ret; |
| 1216 | } |
| 1217 | |
| 1218 | static int sdhci_msm_vreg_set_voltage(struct sdhci_msm_reg_data *vreg, |
| 1219 | int min_uV, int max_uV) |
| 1220 | { |
| 1221 | int ret = 0; |
| 1222 | |
| 1223 | ret = regulator_set_voltage(vreg->reg, min_uV, max_uV); |
| 1224 | if (ret) { |
| 1225 | pr_err("%s: regulator_set_voltage(%s)failed. min_uV=%d,max_uV=%d,ret=%d\n", |
| 1226 | __func__, vreg->name, min_uV, max_uV, ret); |
| 1227 | } |
| 1228 | |
| 1229 | return ret; |
| 1230 | } |
| 1231 | |
| 1232 | static int sdhci_msm_vreg_enable(struct sdhci_msm_reg_data *vreg) |
| 1233 | { |
| 1234 | int ret = 0; |
| 1235 | |
| 1236 | /* Put regulator in HPM (high power mode) */ |
| 1237 | ret = sdhci_msm_vreg_set_optimum_mode(vreg, vreg->hpm_uA); |
| 1238 | if (ret < 0) |
| 1239 | return ret; |
| 1240 | |
| 1241 | if (!vreg->is_enabled) { |
| 1242 | /* Set voltage level */ |
| 1243 | ret = sdhci_msm_vreg_set_voltage(vreg, vreg->high_vol_level, |
| 1244 | vreg->high_vol_level); |
| 1245 | if (ret) |
| 1246 | return ret; |
| 1247 | } |
| 1248 | ret = regulator_enable(vreg->reg); |
| 1249 | if (ret) { |
| 1250 | pr_err("%s: regulator_enable(%s) failed. ret=%d\n", |
| 1251 | __func__, vreg->name, ret); |
| 1252 | return ret; |
| 1253 | } |
| 1254 | vreg->is_enabled = true; |
| 1255 | return ret; |
| 1256 | } |
| 1257 | |
| 1258 | static int sdhci_msm_vreg_disable(struct sdhci_msm_reg_data *vreg) |
| 1259 | { |
| 1260 | int ret = 0; |
| 1261 | |
| 1262 | /* Never disable regulator marked as always_on */ |
| 1263 | if (vreg->is_enabled && !vreg->is_always_on) { |
| 1264 | ret = regulator_disable(vreg->reg); |
| 1265 | if (ret) { |
| 1266 | pr_err("%s: regulator_disable(%s) failed. ret=%d\n", |
| 1267 | __func__, vreg->name, ret); |
| 1268 | goto out; |
| 1269 | } |
| 1270 | vreg->is_enabled = false; |
| 1271 | |
| 1272 | ret = sdhci_msm_vreg_set_optimum_mode(vreg, 0); |
| 1273 | if (ret < 0) |
| 1274 | goto out; |
| 1275 | |
| 1276 | /* Set min. voltage level to 0 */ |
| 1277 | ret = sdhci_msm_vreg_set_voltage(vreg, 0, vreg->high_vol_level); |
| 1278 | if (ret) |
| 1279 | goto out; |
| 1280 | } else if (vreg->is_enabled && vreg->is_always_on) { |
| 1281 | if (vreg->lpm_sup) { |
| 1282 | /* Put always_on regulator in LPM (low power mode) */ |
| 1283 | ret = sdhci_msm_vreg_set_optimum_mode(vreg, |
| 1284 | vreg->lpm_uA); |
| 1285 | if (ret < 0) |
| 1286 | goto out; |
| 1287 | } |
| 1288 | } |
| 1289 | out: |
| 1290 | return ret; |
| 1291 | } |
| 1292 | |
| 1293 | static int sdhci_msm_setup_vreg(struct sdhci_msm_pltfm_data *pdata, |
| 1294 | bool enable, bool is_init) |
| 1295 | { |
| 1296 | int ret = 0, i; |
| 1297 | struct sdhci_msm_slot_reg_data *curr_slot; |
| 1298 | struct sdhci_msm_reg_data *vreg_table[2]; |
| 1299 | |
| 1300 | curr_slot = pdata->vreg_data; |
| 1301 | if (!curr_slot) { |
| 1302 | pr_debug("%s: vreg info unavailable,assuming the slot is powered by always on domain\n", |
| 1303 | __func__); |
| 1304 | goto out; |
| 1305 | } |
| 1306 | |
| 1307 | vreg_table[0] = curr_slot->vdd_data; |
| 1308 | vreg_table[1] = curr_slot->vdd_io_data; |
| 1309 | |
| 1310 | for (i = 0; i < ARRAY_SIZE(vreg_table); i++) { |
| 1311 | if (vreg_table[i]) { |
| 1312 | if (enable) |
| 1313 | ret = sdhci_msm_vreg_enable(vreg_table[i]); |
| 1314 | else |
| 1315 | ret = sdhci_msm_vreg_disable(vreg_table[i]); |
| 1316 | if (ret) |
| 1317 | goto out; |
| 1318 | } |
| 1319 | } |
| 1320 | out: |
| 1321 | return ret; |
| 1322 | } |
| 1323 | |
| 1324 | /* |
| 1325 | * Reset vreg by ensuring it is off during probe. A call |
| 1326 | * to enable vreg is needed to balance disable vreg |
| 1327 | */ |
| 1328 | static int sdhci_msm_vreg_reset(struct sdhci_msm_pltfm_data *pdata) |
| 1329 | { |
| 1330 | int ret; |
| 1331 | |
| 1332 | ret = sdhci_msm_setup_vreg(pdata, 1, true); |
| 1333 | if (ret) |
| 1334 | return ret; |
| 1335 | ret = sdhci_msm_setup_vreg(pdata, 0, true); |
| 1336 | return ret; |
| 1337 | } |
| 1338 | |
| 1339 | /* This init function should be called only once for each SDHC slot */ |
| 1340 | static int sdhci_msm_vreg_init(struct device *dev, |
| 1341 | struct sdhci_msm_pltfm_data *pdata, |
| 1342 | bool is_init) |
| 1343 | { |
| 1344 | int ret = 0; |
| 1345 | struct sdhci_msm_slot_reg_data *curr_slot; |
| 1346 | struct sdhci_msm_reg_data *curr_vdd_reg, *curr_vdd_io_reg; |
| 1347 | |
| 1348 | curr_slot = pdata->vreg_data; |
| 1349 | if (!curr_slot) |
| 1350 | goto out; |
| 1351 | |
| 1352 | curr_vdd_reg = curr_slot->vdd_data; |
| 1353 | curr_vdd_io_reg = curr_slot->vdd_io_data; |
| 1354 | |
| 1355 | if (!is_init) |
| 1356 | /* Deregister all regulators from regulator framework */ |
| 1357 | goto vdd_io_reg_deinit; |
| 1358 | |
| 1359 | /* |
| 1360 | * Get the regulator handle from voltage regulator framework |
| 1361 | * and then try to set the voltage level for the regulator |
| 1362 | */ |
| 1363 | if (curr_vdd_reg) { |
| 1364 | ret = sdhci_msm_vreg_init_reg(dev, curr_vdd_reg); |
| 1365 | if (ret) |
| 1366 | goto out; |
| 1367 | } |
| 1368 | if (curr_vdd_io_reg) { |
| 1369 | ret = sdhci_msm_vreg_init_reg(dev, curr_vdd_io_reg); |
| 1370 | if (ret) |
| 1371 | goto vdd_reg_deinit; |
| 1372 | } |
| 1373 | ret = sdhci_msm_vreg_reset(pdata); |
| 1374 | if (ret) |
| 1375 | dev_err(dev, "vreg reset failed (%d)\n", ret); |
| 1376 | goto out; |
| 1377 | |
| 1378 | vdd_io_reg_deinit: |
| 1379 | if (curr_vdd_io_reg) |
| 1380 | sdhci_msm_vreg_deinit_reg(curr_vdd_io_reg); |
| 1381 | vdd_reg_deinit: |
| 1382 | if (curr_vdd_reg) |
| 1383 | sdhci_msm_vreg_deinit_reg(curr_vdd_reg); |
| 1384 | out: |
| 1385 | return ret; |
| 1386 | } |
| 1387 | |
| 1388 | |
| 1389 | static int sdhci_msm_set_vdd_io_vol(struct sdhci_msm_pltfm_data *pdata, |
| 1390 | enum vdd_io_level level, |
| 1391 | unsigned int voltage_level) |
| 1392 | { |
| 1393 | int ret = 0; |
| 1394 | int set_level; |
| 1395 | struct sdhci_msm_reg_data *vdd_io_reg; |
| 1396 | |
| 1397 | if (!pdata->vreg_data) |
| 1398 | return ret; |
| 1399 | |
| 1400 | vdd_io_reg = pdata->vreg_data->vdd_io_data; |
| 1401 | if (vdd_io_reg && vdd_io_reg->is_enabled) { |
| 1402 | switch (level) { |
| 1403 | case VDD_IO_LOW: |
| 1404 | set_level = vdd_io_reg->low_vol_level; |
| 1405 | break; |
| 1406 | case VDD_IO_HIGH: |
| 1407 | set_level = vdd_io_reg->high_vol_level; |
| 1408 | break; |
| 1409 | case VDD_IO_SET_LEVEL: |
| 1410 | set_level = voltage_level; |
| 1411 | break; |
| 1412 | default: |
| 1413 | pr_err("%s: invalid argument level = %d", |
| 1414 | __func__, level); |
| 1415 | ret = -EINVAL; |
| 1416 | return ret; |
| 1417 | } |
| 1418 | ret = sdhci_msm_vreg_set_voltage(vdd_io_reg, set_level, |
| 1419 | set_level); |
| 1420 | } |
| 1421 | return ret; |
| 1422 | } |
| 1423 | |
| 1424 | static irqreturn_t sdhci_msm_pwr_irq(int irq, void *data) |
| 1425 | { |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 1426 | struct sdhci_host *host = (struct sdhci_host *)data; |
| 1427 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 1428 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1429 | u8 irq_status = 0; |
| 1430 | u8 irq_ack = 0; |
| 1431 | int ret = 0; |
Sahitya Tummala | 1f52eaa | 2013-03-20 19:24:01 +0530 | [diff] [blame] | 1432 | int pwr_state = 0, io_level = 0; |
| 1433 | unsigned long flags; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1434 | |
| 1435 | irq_status = readb_relaxed(msm_host->core_mem + CORE_PWRCTL_STATUS); |
| 1436 | pr_debug("%s: Received IRQ(%d), status=0x%x\n", |
| 1437 | mmc_hostname(msm_host->mmc), irq, irq_status); |
| 1438 | |
| 1439 | /* Clear the interrupt */ |
| 1440 | writeb_relaxed(irq_status, (msm_host->core_mem + CORE_PWRCTL_CLEAR)); |
| 1441 | /* |
| 1442 | * SDHC has core_mem and hc_mem device memory and these memory |
| 1443 | * addresses do not fall within 1KB region. Hence, any update to |
| 1444 | * core_mem address space would require an mb() to ensure this gets |
| 1445 | * completed before its next update to registers within hc_mem. |
| 1446 | */ |
| 1447 | mb(); |
| 1448 | |
| 1449 | /* Handle BUS ON/OFF*/ |
| 1450 | if (irq_status & CORE_PWRCTL_BUS_ON) { |
| 1451 | ret = sdhci_msm_setup_vreg(msm_host->pdata, true, false); |
Sahitya Tummala | 1f52eaa | 2013-03-20 19:24:01 +0530 | [diff] [blame] | 1452 | if (!ret) { |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1453 | ret = sdhci_msm_setup_pins(msm_host->pdata, true); |
Sahitya Tummala | 1f52eaa | 2013-03-20 19:24:01 +0530 | [diff] [blame] | 1454 | ret |= sdhci_msm_set_vdd_io_vol(msm_host->pdata, |
| 1455 | VDD_IO_HIGH, 0); |
| 1456 | } |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1457 | if (ret) |
| 1458 | irq_ack |= CORE_PWRCTL_BUS_FAIL; |
| 1459 | else |
| 1460 | irq_ack |= CORE_PWRCTL_BUS_SUCCESS; |
Sahitya Tummala | 1f52eaa | 2013-03-20 19:24:01 +0530 | [diff] [blame] | 1461 | |
| 1462 | pwr_state = REQ_BUS_ON; |
| 1463 | io_level = REQ_IO_HIGH; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1464 | } |
| 1465 | if (irq_status & CORE_PWRCTL_BUS_OFF) { |
| 1466 | ret = sdhci_msm_setup_vreg(msm_host->pdata, false, false); |
Sahitya Tummala | 1f52eaa | 2013-03-20 19:24:01 +0530 | [diff] [blame] | 1467 | if (!ret) { |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1468 | ret = sdhci_msm_setup_pins(msm_host->pdata, false); |
Sahitya Tummala | 1f52eaa | 2013-03-20 19:24:01 +0530 | [diff] [blame] | 1469 | ret |= sdhci_msm_set_vdd_io_vol(msm_host->pdata, |
| 1470 | VDD_IO_LOW, 0); |
| 1471 | } |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1472 | if (ret) |
| 1473 | irq_ack |= CORE_PWRCTL_BUS_FAIL; |
| 1474 | else |
| 1475 | irq_ack |= CORE_PWRCTL_BUS_SUCCESS; |
Sahitya Tummala | 1f52eaa | 2013-03-20 19:24:01 +0530 | [diff] [blame] | 1476 | |
| 1477 | pwr_state = REQ_BUS_OFF; |
| 1478 | io_level = REQ_IO_LOW; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1479 | } |
| 1480 | /* Handle IO LOW/HIGH */ |
| 1481 | if (irq_status & CORE_PWRCTL_IO_LOW) { |
| 1482 | /* Switch voltage Low */ |
| 1483 | ret = sdhci_msm_set_vdd_io_vol(msm_host->pdata, VDD_IO_LOW, 0); |
| 1484 | if (ret) |
| 1485 | irq_ack |= CORE_PWRCTL_IO_FAIL; |
| 1486 | else |
| 1487 | irq_ack |= CORE_PWRCTL_IO_SUCCESS; |
Sahitya Tummala | 1f52eaa | 2013-03-20 19:24:01 +0530 | [diff] [blame] | 1488 | |
| 1489 | io_level = REQ_IO_LOW; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1490 | } |
| 1491 | if (irq_status & CORE_PWRCTL_IO_HIGH) { |
| 1492 | /* Switch voltage High */ |
| 1493 | ret = sdhci_msm_set_vdd_io_vol(msm_host->pdata, VDD_IO_HIGH, 0); |
| 1494 | if (ret) |
| 1495 | irq_ack |= CORE_PWRCTL_IO_FAIL; |
| 1496 | else |
| 1497 | irq_ack |= CORE_PWRCTL_IO_SUCCESS; |
Sahitya Tummala | 1f52eaa | 2013-03-20 19:24:01 +0530 | [diff] [blame] | 1498 | |
| 1499 | io_level = REQ_IO_HIGH; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | /* ACK status to the core */ |
| 1503 | writeb_relaxed(irq_ack, (msm_host->core_mem + CORE_PWRCTL_CTL)); |
| 1504 | /* |
| 1505 | * SDHC has core_mem and hc_mem device memory and these memory |
| 1506 | * addresses do not fall within 1KB region. Hence, any update to |
| 1507 | * core_mem address space would require an mb() to ensure this gets |
| 1508 | * completed before its next update to registers within hc_mem. |
| 1509 | */ |
| 1510 | mb(); |
| 1511 | |
Sahitya Tummala | 1f52eaa | 2013-03-20 19:24:01 +0530 | [diff] [blame] | 1512 | if (io_level & REQ_IO_HIGH) |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 1513 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_VENDOR_SPEC) & |
| 1514 | ~CORE_IO_PAD_PWR_SWITCH), |
| 1515 | host->ioaddr + CORE_VENDOR_SPEC); |
Sahitya Tummala | 1f52eaa | 2013-03-20 19:24:01 +0530 | [diff] [blame] | 1516 | else if (io_level & REQ_IO_LOW) |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 1517 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_VENDOR_SPEC) | |
| 1518 | CORE_IO_PAD_PWR_SWITCH), |
| 1519 | host->ioaddr + CORE_VENDOR_SPEC); |
| 1520 | mb(); |
| 1521 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1522 | pr_debug("%s: Handled IRQ(%d), ret=%d, ack=0x%x\n", |
| 1523 | mmc_hostname(msm_host->mmc), irq, ret, irq_ack); |
Sahitya Tummala | 1f52eaa | 2013-03-20 19:24:01 +0530 | [diff] [blame] | 1524 | spin_lock_irqsave(&host->lock, flags); |
| 1525 | if (pwr_state) |
| 1526 | msm_host->curr_pwr_state = pwr_state; |
| 1527 | if (io_level) |
| 1528 | msm_host->curr_io_level = io_level; |
| 1529 | complete(&msm_host->pwr_irq_completion); |
| 1530 | spin_unlock_irqrestore(&host->lock, flags); |
| 1531 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1532 | return IRQ_HANDLED; |
| 1533 | } |
| 1534 | |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 1535 | static ssize_t |
| 1536 | show_sdhci_max_bus_bw(struct device *dev, struct device_attribute *attr, |
| 1537 | char *buf) |
| 1538 | { |
| 1539 | struct sdhci_host *host = dev_get_drvdata(dev); |
| 1540 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 1541 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
| 1542 | |
| 1543 | return snprintf(buf, PAGE_SIZE, "%u\n", |
| 1544 | msm_host->msm_bus_vote.is_max_bw_needed); |
| 1545 | } |
| 1546 | |
| 1547 | static ssize_t |
| 1548 | store_sdhci_max_bus_bw(struct device *dev, struct device_attribute *attr, |
| 1549 | const char *buf, size_t count) |
| 1550 | { |
| 1551 | struct sdhci_host *host = dev_get_drvdata(dev); |
| 1552 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 1553 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
| 1554 | uint32_t value; |
| 1555 | unsigned long flags; |
| 1556 | |
| 1557 | if (!kstrtou32(buf, 0, &value)) { |
| 1558 | spin_lock_irqsave(&host->lock, flags); |
| 1559 | msm_host->msm_bus_vote.is_max_bw_needed = !!value; |
| 1560 | spin_unlock_irqrestore(&host->lock, flags); |
| 1561 | } |
| 1562 | return count; |
| 1563 | } |
| 1564 | |
Sahitya Tummala | 1f52eaa | 2013-03-20 19:24:01 +0530 | [diff] [blame] | 1565 | static void sdhci_msm_check_power_status(struct sdhci_host *host, u32 req_type) |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1566 | { |
| 1567 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 1568 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
Sahitya Tummala | 1f52eaa | 2013-03-20 19:24:01 +0530 | [diff] [blame] | 1569 | unsigned long flags; |
| 1570 | bool done = false; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1571 | |
Sahitya Tummala | 1f52eaa | 2013-03-20 19:24:01 +0530 | [diff] [blame] | 1572 | spin_lock_irqsave(&host->lock, flags); |
| 1573 | pr_debug("%s: %s: request %d curr_pwr_state %x curr_io_level %x\n", |
| 1574 | mmc_hostname(host->mmc), __func__, req_type, |
| 1575 | msm_host->curr_pwr_state, msm_host->curr_io_level); |
| 1576 | if ((req_type & msm_host->curr_pwr_state) || |
| 1577 | (req_type & msm_host->curr_io_level)) |
| 1578 | done = true; |
| 1579 | spin_unlock_irqrestore(&host->lock, flags); |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1580 | |
Sahitya Tummala | 1f52eaa | 2013-03-20 19:24:01 +0530 | [diff] [blame] | 1581 | /* |
| 1582 | * This is needed here to hanlde a case where IRQ gets |
| 1583 | * triggered even before this function is called so that |
| 1584 | * x->done counter of completion gets reset. Otherwise, |
| 1585 | * next call to wait_for_completion returns immediately |
| 1586 | * without actually waiting for the IRQ to be handled. |
| 1587 | */ |
| 1588 | if (done) |
| 1589 | init_completion(&msm_host->pwr_irq_completion); |
| 1590 | else |
| 1591 | wait_for_completion(&msm_host->pwr_irq_completion); |
| 1592 | |
| 1593 | pr_debug("%s: %s: request %d done\n", mmc_hostname(host->mmc), |
| 1594 | __func__, req_type); |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1595 | } |
| 1596 | |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 1597 | static void sdhci_msm_toggle_cdr(struct sdhci_host *host, bool enable) |
| 1598 | { |
| 1599 | if (enable) |
| 1600 | writel_relaxed((readl_relaxed(host->ioaddr + |
| 1601 | CORE_DLL_CONFIG) | CORE_CDR_EN), |
| 1602 | host->ioaddr + CORE_DLL_CONFIG); |
| 1603 | else |
| 1604 | writel_relaxed((readl_relaxed(host->ioaddr + |
| 1605 | CORE_DLL_CONFIG) & ~CORE_CDR_EN), |
| 1606 | host->ioaddr + CORE_DLL_CONFIG); |
| 1607 | } |
| 1608 | |
Asutosh Das | 648f9d1 | 2013-01-10 21:11:04 +0530 | [diff] [blame] | 1609 | static unsigned int sdhci_msm_max_segs(void) |
| 1610 | { |
| 1611 | return SDHCI_MSM_MAX_SEGMENTS; |
| 1612 | } |
| 1613 | |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 1614 | static unsigned int sdhci_msm_get_min_clock(struct sdhci_host *host) |
Sahitya Tummala | a7f3c57 | 2013-01-11 11:30:45 +0530 | [diff] [blame] | 1615 | { |
Sahitya Tummala | a7f3c57 | 2013-01-11 11:30:45 +0530 | [diff] [blame] | 1616 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 1617 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
Sahitya Tummala | a7f3c57 | 2013-01-11 11:30:45 +0530 | [diff] [blame] | 1618 | |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 1619 | return msm_host->pdata->sup_clk_table[0]; |
| 1620 | } |
| 1621 | |
| 1622 | static unsigned int sdhci_msm_get_max_clock(struct sdhci_host *host) |
| 1623 | { |
| 1624 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 1625 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
| 1626 | int max_clk_index = msm_host->pdata->sup_clk_cnt; |
| 1627 | |
| 1628 | return msm_host->pdata->sup_clk_table[max_clk_index - 1]; |
| 1629 | } |
| 1630 | |
| 1631 | static unsigned int sdhci_msm_get_sup_clk_rate(struct sdhci_host *host, |
| 1632 | u32 req_clk) |
| 1633 | { |
| 1634 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 1635 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
| 1636 | unsigned int sel_clk = -1; |
| 1637 | unsigned char cnt; |
| 1638 | |
| 1639 | if (req_clk < sdhci_msm_get_min_clock(host)) { |
| 1640 | sel_clk = sdhci_msm_get_min_clock(host); |
| 1641 | return sel_clk; |
| 1642 | } |
| 1643 | |
| 1644 | for (cnt = 0; cnt < msm_host->pdata->sup_clk_cnt; cnt++) { |
| 1645 | if (msm_host->pdata->sup_clk_table[cnt] > req_clk) { |
| 1646 | break; |
| 1647 | } else if (msm_host->pdata->sup_clk_table[cnt] == req_clk) { |
| 1648 | sel_clk = msm_host->pdata->sup_clk_table[cnt]; |
| 1649 | break; |
| 1650 | } else { |
| 1651 | sel_clk = msm_host->pdata->sup_clk_table[cnt]; |
| 1652 | } |
| 1653 | } |
| 1654 | return sel_clk; |
| 1655 | } |
| 1656 | |
| 1657 | static int sdhci_msm_prepare_clocks(struct sdhci_host *host, bool enable) |
| 1658 | { |
| 1659 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 1660 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
| 1661 | int rc = 0; |
| 1662 | |
| 1663 | if (enable && !atomic_read(&msm_host->clks_on)) { |
| 1664 | pr_debug("%s: request to enable clocks\n", |
| 1665 | mmc_hostname(host->mmc)); |
Sahitya Tummala | a7f3c57 | 2013-01-11 11:30:45 +0530 | [diff] [blame] | 1666 | if (!IS_ERR_OR_NULL(msm_host->bus_clk)) { |
| 1667 | rc = clk_prepare_enable(msm_host->bus_clk); |
| 1668 | if (rc) { |
| 1669 | pr_err("%s: %s: failed to enable the bus-clock with error %d\n", |
| 1670 | mmc_hostname(host->mmc), __func__, rc); |
| 1671 | goto out; |
| 1672 | } |
| 1673 | } |
| 1674 | if (!IS_ERR(msm_host->pclk)) { |
| 1675 | rc = clk_prepare_enable(msm_host->pclk); |
| 1676 | if (rc) { |
| 1677 | pr_err("%s: %s: failed to enable the pclk with error %d\n", |
| 1678 | mmc_hostname(host->mmc), __func__, rc); |
| 1679 | goto disable_bus_clk; |
| 1680 | } |
| 1681 | } |
| 1682 | rc = clk_prepare_enable(msm_host->clk); |
| 1683 | if (rc) { |
| 1684 | pr_err("%s: %s: failed to enable the host-clk with error %d\n", |
| 1685 | mmc_hostname(host->mmc), __func__, rc); |
| 1686 | goto disable_pclk; |
| 1687 | } |
| 1688 | mb(); |
Sahitya Tummala | a7f3c57 | 2013-01-11 11:30:45 +0530 | [diff] [blame] | 1689 | |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 1690 | } else if (!enable && atomic_read(&msm_host->clks_on)) { |
Sahitya Tummala | a7f3c57 | 2013-01-11 11:30:45 +0530 | [diff] [blame] | 1691 | pr_debug("%s: request to disable clocks\n", |
| 1692 | mmc_hostname(host->mmc)); |
| 1693 | sdhci_writew(host, 0, SDHCI_CLOCK_CONTROL); |
| 1694 | mb(); |
| 1695 | clk_disable_unprepare(msm_host->clk); |
| 1696 | if (!IS_ERR(msm_host->pclk)) |
| 1697 | clk_disable_unprepare(msm_host->pclk); |
| 1698 | if (!IS_ERR_OR_NULL(msm_host->bus_clk)) |
| 1699 | clk_disable_unprepare(msm_host->bus_clk); |
Sahitya Tummala | a7f3c57 | 2013-01-11 11:30:45 +0530 | [diff] [blame] | 1700 | } |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 1701 | atomic_set(&msm_host->clks_on, enable); |
Sahitya Tummala | a7f3c57 | 2013-01-11 11:30:45 +0530 | [diff] [blame] | 1702 | goto out; |
| 1703 | disable_pclk: |
| 1704 | if (!IS_ERR_OR_NULL(msm_host->pclk)) |
| 1705 | clk_disable_unprepare(msm_host->pclk); |
| 1706 | disable_bus_clk: |
| 1707 | if (!IS_ERR_OR_NULL(msm_host->bus_clk)) |
| 1708 | clk_disable_unprepare(msm_host->bus_clk); |
| 1709 | out: |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 1710 | return rc; |
| 1711 | } |
| 1712 | |
| 1713 | static void sdhci_msm_set_clock(struct sdhci_host *host, unsigned int clock) |
| 1714 | { |
| 1715 | int rc; |
| 1716 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 1717 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
| 1718 | struct mmc_ios curr_ios = host->mmc->ios; |
| 1719 | u32 sup_clock, ddr_clock; |
| 1720 | |
| 1721 | if (!clock) { |
| 1722 | sdhci_msm_prepare_clocks(host, false); |
| 1723 | host->clock = clock; |
| 1724 | goto out; |
| 1725 | } |
| 1726 | |
| 1727 | rc = sdhci_msm_prepare_clocks(host, true); |
| 1728 | if (rc) |
| 1729 | goto out; |
| 1730 | |
| 1731 | sup_clock = sdhci_msm_get_sup_clk_rate(host, clock); |
| 1732 | if (curr_ios.timing == MMC_TIMING_UHS_DDR50) { |
| 1733 | /* |
| 1734 | * The SDHC requires internal clock frequency to be double the |
| 1735 | * actual clock that will be set for DDR mode. The controller |
| 1736 | * uses the faster clock(100MHz) for some of its parts and send |
| 1737 | * the actual required clock (50MHz) to the card. |
| 1738 | */ |
| 1739 | ddr_clock = clock * 2; |
| 1740 | sup_clock = sdhci_msm_get_sup_clk_rate(host, |
| 1741 | ddr_clock); |
| 1742 | } |
| 1743 | if (sup_clock != msm_host->clk_rate) { |
| 1744 | pr_debug("%s: %s: setting clk rate to %u\n", |
| 1745 | mmc_hostname(host->mmc), __func__, sup_clock); |
| 1746 | rc = clk_set_rate(msm_host->clk, sup_clock); |
| 1747 | if (rc) { |
| 1748 | pr_err("%s: %s: Failed to set rate %u for host-clk : %d\n", |
| 1749 | mmc_hostname(host->mmc), __func__, |
| 1750 | sup_clock, rc); |
| 1751 | goto out; |
| 1752 | } |
| 1753 | msm_host->clk_rate = sup_clock; |
| 1754 | host->clock = clock; |
| 1755 | } |
| 1756 | out: |
| 1757 | sdhci_set_clock(host, clock); |
Sahitya Tummala | a7f3c57 | 2013-01-11 11:30:45 +0530 | [diff] [blame] | 1758 | } |
| 1759 | |
Sahitya Tummala | 1461343 | 2013-03-21 11:13:25 +0530 | [diff] [blame] | 1760 | static void sdhci_msm_set_uhs_signaling(struct sdhci_host *host, |
| 1761 | unsigned int uhs) |
| 1762 | { |
| 1763 | u16 ctrl_2; |
| 1764 | |
| 1765 | ctrl_2 = sdhci_readw(host, SDHCI_HOST_CONTROL2); |
| 1766 | /* Select Bus Speed Mode for host */ |
| 1767 | ctrl_2 &= ~SDHCI_CTRL_UHS_MASK; |
| 1768 | if (uhs == MMC_TIMING_MMC_HS200) |
| 1769 | ctrl_2 |= SDHCI_CTRL_UHS_SDR104; |
| 1770 | else if (uhs == MMC_TIMING_UHS_SDR12) |
| 1771 | ctrl_2 |= SDHCI_CTRL_UHS_SDR12; |
| 1772 | else if (uhs == MMC_TIMING_UHS_SDR25) |
| 1773 | ctrl_2 |= SDHCI_CTRL_UHS_SDR25; |
| 1774 | else if (uhs == MMC_TIMING_UHS_SDR50) |
| 1775 | ctrl_2 |= SDHCI_CTRL_UHS_SDR50; |
| 1776 | else if (uhs == MMC_TIMING_UHS_SDR104) |
| 1777 | ctrl_2 |= SDHCI_CTRL_UHS_SDR104; |
| 1778 | else if (uhs == MMC_TIMING_UHS_DDR50) |
| 1779 | ctrl_2 |= SDHCI_CTRL_UHS_DDR50; |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 1780 | /* |
| 1781 | * When clock frquency is less than 100MHz, the feedback clock must be |
| 1782 | * provided and DLL must not be used so that tuning can be skipped. To |
| 1783 | * provide feedback clock, the mode selection can be any value less |
| 1784 | * than 3'b011 in bits [2:0] of HOST CONTROL2 register. |
| 1785 | */ |
| 1786 | if (host->clock <= (100 * 1000 * 1000) && |
| 1787 | (uhs == MMC_TIMING_MMC_HS200 || |
| 1788 | uhs == MMC_TIMING_UHS_SDR104)) |
| 1789 | ctrl_2 &= ~SDHCI_CTRL_UHS_MASK; |
| 1790 | |
Sahitya Tummala | 1461343 | 2013-03-21 11:13:25 +0530 | [diff] [blame] | 1791 | sdhci_writew(host, ctrl_2, SDHCI_HOST_CONTROL2); |
| 1792 | |
| 1793 | } |
| 1794 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1795 | static struct sdhci_ops sdhci_msm_ops = { |
Sahitya Tummala | 1461343 | 2013-03-21 11:13:25 +0530 | [diff] [blame] | 1796 | .set_uhs_signaling = sdhci_msm_set_uhs_signaling, |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1797 | .check_power_status = sdhci_msm_check_power_status, |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 1798 | .platform_execute_tuning = sdhci_msm_execute_tuning, |
| 1799 | .toggle_cdr = sdhci_msm_toggle_cdr, |
Asutosh Das | 648f9d1 | 2013-01-10 21:11:04 +0530 | [diff] [blame] | 1800 | .get_max_segments = sdhci_msm_max_segs, |
Sahitya Tummala | a7f3c57 | 2013-01-11 11:30:45 +0530 | [diff] [blame] | 1801 | .set_clock = sdhci_msm_set_clock, |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 1802 | .platform_bus_voting = sdhci_msm_bus_voting, |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 1803 | .get_min_clock = sdhci_msm_get_min_clock, |
| 1804 | .get_max_clock = sdhci_msm_get_max_clock, |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1805 | }; |
| 1806 | |
| 1807 | static int sdhci_msm_probe(struct platform_device *pdev) |
| 1808 | { |
| 1809 | struct sdhci_host *host; |
| 1810 | struct sdhci_pltfm_host *pltfm_host; |
| 1811 | struct sdhci_msm_host *msm_host; |
| 1812 | struct resource *core_memres = NULL; |
| 1813 | int ret = 0, pwr_irq = 0, dead = 0; |
Stephen Boyd | 8dce5c6 | 2013-04-24 14:19:46 -0700 | [diff] [blame^] | 1814 | u16 host_version; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1815 | |
| 1816 | pr_debug("%s: Enter %s\n", dev_name(&pdev->dev), __func__); |
| 1817 | msm_host = devm_kzalloc(&pdev->dev, sizeof(struct sdhci_msm_host), |
| 1818 | GFP_KERNEL); |
| 1819 | if (!msm_host) { |
| 1820 | ret = -ENOMEM; |
| 1821 | goto out; |
| 1822 | } |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1823 | |
| 1824 | msm_host->sdhci_msm_pdata.ops = &sdhci_msm_ops; |
| 1825 | host = sdhci_pltfm_init(pdev, &msm_host->sdhci_msm_pdata, 0); |
| 1826 | if (IS_ERR(host)) { |
| 1827 | ret = PTR_ERR(host); |
| 1828 | goto out; |
| 1829 | } |
| 1830 | |
| 1831 | pltfm_host = sdhci_priv(host); |
| 1832 | pltfm_host->priv = msm_host; |
| 1833 | msm_host->mmc = host->mmc; |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 1834 | msm_host->pdev = pdev; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1835 | |
| 1836 | /* Extract platform data */ |
| 1837 | if (pdev->dev.of_node) { |
Venkat Gopalakrishnan | 270580a | 2013-03-11 12:17:57 -0700 | [diff] [blame] | 1838 | ret = of_alias_get_id(pdev->dev.of_node, "sdhc"); |
| 1839 | if (ret < 0) { |
| 1840 | dev_err(&pdev->dev, "Failed to get slot index %d\n", |
| 1841 | ret); |
| 1842 | goto pltfm_free; |
| 1843 | } |
| 1844 | if (disable_slots & (1 << (ret - 1))) { |
| 1845 | dev_info(&pdev->dev, "%s: Slot %d disabled\n", __func__, |
| 1846 | ret); |
| 1847 | ret = -ENODEV; |
| 1848 | goto pltfm_free; |
| 1849 | } |
| 1850 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1851 | msm_host->pdata = sdhci_msm_populate_pdata(&pdev->dev); |
| 1852 | if (!msm_host->pdata) { |
| 1853 | dev_err(&pdev->dev, "DT parsing error\n"); |
| 1854 | goto pltfm_free; |
| 1855 | } |
| 1856 | } else { |
| 1857 | dev_err(&pdev->dev, "No device tree node\n"); |
| 1858 | goto pltfm_free; |
| 1859 | } |
| 1860 | |
| 1861 | /* Setup Clocks */ |
| 1862 | |
| 1863 | /* Setup SDCC bus voter clock. */ |
| 1864 | msm_host->bus_clk = devm_clk_get(&pdev->dev, "bus_clk"); |
| 1865 | if (!IS_ERR_OR_NULL(msm_host->bus_clk)) { |
| 1866 | /* Vote for max. clk rate for max. performance */ |
| 1867 | ret = clk_set_rate(msm_host->bus_clk, INT_MAX); |
| 1868 | if (ret) |
| 1869 | goto pltfm_free; |
| 1870 | ret = clk_prepare_enable(msm_host->bus_clk); |
| 1871 | if (ret) |
| 1872 | goto pltfm_free; |
| 1873 | } |
| 1874 | |
| 1875 | /* Setup main peripheral bus clock */ |
| 1876 | msm_host->pclk = devm_clk_get(&pdev->dev, "iface_clk"); |
| 1877 | if (!IS_ERR(msm_host->pclk)) { |
| 1878 | ret = clk_prepare_enable(msm_host->pclk); |
| 1879 | if (ret) |
| 1880 | goto bus_clk_disable; |
| 1881 | } |
| 1882 | |
| 1883 | /* Setup SDC MMC clock */ |
| 1884 | msm_host->clk = devm_clk_get(&pdev->dev, "core_clk"); |
| 1885 | if (IS_ERR(msm_host->clk)) { |
| 1886 | ret = PTR_ERR(msm_host->clk); |
| 1887 | goto pclk_disable; |
| 1888 | } |
| 1889 | |
| 1890 | ret = clk_prepare_enable(msm_host->clk); |
| 1891 | if (ret) |
| 1892 | goto pclk_disable; |
| 1893 | |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 1894 | /* Set to the minimum supported clock frequency */ |
| 1895 | ret = clk_set_rate(msm_host->clk, sdhci_msm_get_min_clock(host)); |
| 1896 | if (ret) { |
| 1897 | dev_err(&pdev->dev, "MClk rate set failed (%d)\n", ret); |
| 1898 | goto clk_disable; |
| 1899 | } |
| 1900 | msm_host->clk_rate = sdhci_msm_get_min_clock(host); |
Sahitya Tummala | a7f3c57 | 2013-01-11 11:30:45 +0530 | [diff] [blame] | 1901 | atomic_set(&msm_host->clks_on, 1); |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 1902 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1903 | /* Setup regulators */ |
| 1904 | ret = sdhci_msm_vreg_init(&pdev->dev, msm_host->pdata, true); |
| 1905 | if (ret) { |
| 1906 | dev_err(&pdev->dev, "Regulator setup failed (%d)\n", ret); |
| 1907 | goto clk_disable; |
| 1908 | } |
| 1909 | |
| 1910 | /* Reset the core and Enable SDHC mode */ |
| 1911 | core_memres = platform_get_resource_byname(pdev, |
| 1912 | IORESOURCE_MEM, "core_mem"); |
| 1913 | msm_host->core_mem = devm_ioremap(&pdev->dev, core_memres->start, |
| 1914 | resource_size(core_memres)); |
| 1915 | |
| 1916 | if (!msm_host->core_mem) { |
| 1917 | dev_err(&pdev->dev, "Failed to remap registers\n"); |
| 1918 | ret = -ENOMEM; |
| 1919 | goto vreg_deinit; |
| 1920 | } |
| 1921 | |
| 1922 | /* Set SW_RST bit in POWER register (Offset 0x0) */ |
| 1923 | writel_relaxed(CORE_SW_RST, msm_host->core_mem + CORE_POWER); |
| 1924 | /* Set HC_MODE_EN bit in HC_MODE register */ |
| 1925 | writel_relaxed(HC_MODE_EN, (msm_host->core_mem + CORE_HC_MODE)); |
| 1926 | |
| 1927 | /* |
| 1928 | * Following are the deviations from SDHC spec v3.0 - |
| 1929 | * 1. Card detection is handled using separate GPIO. |
| 1930 | * 2. Bus power control is handled by interacting with PMIC. |
| 1931 | */ |
| 1932 | host->quirks |= SDHCI_QUIRK_BROKEN_CARD_DETECTION; |
| 1933 | host->quirks |= SDHCI_QUIRK_SINGLE_POWER_WRITE; |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 1934 | host->quirks |= SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN; |
| 1935 | host->quirks2 |= SDHCI_QUIRK2_ALWAYS_USE_BASE_CLOCK; |
Sahitya Tummala | 87d43944 | 2013-04-12 11:49:11 +0530 | [diff] [blame] | 1936 | host->quirks2 |= SDHCI_QUIRK2_IGNORE_DATATOUT_FOR_R1BCMD; |
Sahitya Tummala | 314162c | 2013-04-12 12:11:20 +0530 | [diff] [blame] | 1937 | host->quirks2 |= SDHCI_QUIRK2_BROKEN_PRESET_VALUE; |
Sahitya Tummala | 7c9780d | 2013-04-12 11:59:25 +0530 | [diff] [blame] | 1938 | host->quirks2 |= SDHCI_QUIRK2_USE_RESERVED_MAX_TIMEOUT; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1939 | |
Stephen Boyd | 8dce5c6 | 2013-04-24 14:19:46 -0700 | [diff] [blame^] | 1940 | host_version = readw_relaxed((host->ioaddr + SDHCI_HOST_VERSION)); |
Venkat Gopalakrishnan | a58f91f | 2012-09-17 16:00:15 -0700 | [diff] [blame] | 1941 | dev_dbg(&pdev->dev, "Host Version: 0x%x Vendor Version 0x%x\n", |
| 1942 | host_version, ((host_version & SDHCI_VENDOR_VER_MASK) >> |
| 1943 | SDHCI_VENDOR_VER_SHIFT)); |
| 1944 | if (((host_version & SDHCI_VENDOR_VER_MASK) >> |
| 1945 | SDHCI_VENDOR_VER_SHIFT) == SDHCI_VER_100) { |
| 1946 | /* |
| 1947 | * Add 40us delay in interrupt handler when |
| 1948 | * operating at initialization frequency(400KHz). |
| 1949 | */ |
| 1950 | host->quirks2 |= SDHCI_QUIRK2_SLOW_INT_CLR; |
| 1951 | /* |
| 1952 | * Set Software Reset for DAT line in Software |
| 1953 | * Reset Register (Bit 2). |
| 1954 | */ |
| 1955 | host->quirks2 |= SDHCI_QUIRK2_RDWR_TX_ACTIVE_EOT; |
| 1956 | } |
| 1957 | |
| 1958 | /* Setup PWRCTL irq */ |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1959 | pwr_irq = platform_get_irq_byname(pdev, "pwr_irq"); |
| 1960 | if (pwr_irq < 0) { |
| 1961 | dev_err(&pdev->dev, "Failed to get pwr_irq by name (%d)\n", |
| 1962 | pwr_irq); |
| 1963 | goto vreg_deinit; |
| 1964 | } |
| 1965 | ret = devm_request_threaded_irq(&pdev->dev, pwr_irq, NULL, |
| 1966 | sdhci_msm_pwr_irq, IRQF_ONESHOT, |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 1967 | dev_name(&pdev->dev), host); |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1968 | if (ret) { |
| 1969 | dev_err(&pdev->dev, "Request threaded irq(%d) failed (%d)\n", |
| 1970 | pwr_irq, ret); |
| 1971 | goto vreg_deinit; |
| 1972 | } |
| 1973 | |
| 1974 | /* Enable pwr irq interrupts */ |
| 1975 | writel_relaxed(INT_MASK, (msm_host->core_mem + CORE_PWRCTL_MASK)); |
| 1976 | |
Sahitya Tummala | a7f3c57 | 2013-01-11 11:30:45 +0530 | [diff] [blame] | 1977 | #ifdef CONFIG_MMC_CLKGATE |
| 1978 | /* Set clock gating delay to be used when CONFIG_MMC_CLKGATE is set */ |
| 1979 | msm_host->mmc->clkgate_delay = SDHCI_MSM_MMC_CLK_GATE_DELAY; |
| 1980 | #endif |
| 1981 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1982 | /* Set host capabilities */ |
| 1983 | msm_host->mmc->caps |= msm_host->pdata->mmc_bus_width; |
| 1984 | msm_host->mmc->caps |= msm_host->pdata->caps; |
Sahitya Tummala | 7bd9906 | 2013-02-28 12:21:58 +0530 | [diff] [blame] | 1985 | msm_host->mmc->caps |= MMC_CAP_HW_RESET; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1986 | msm_host->mmc->caps2 |= msm_host->pdata->caps2; |
| 1987 | msm_host->mmc->caps2 |= MMC_CAP2_PACKED_WR; |
| 1988 | msm_host->mmc->caps2 |= MMC_CAP2_PACKED_WR_CONTROL; |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 1989 | msm_host->mmc->caps2 |= MMC_CAP2_CLK_SCALE; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1990 | |
| 1991 | if (msm_host->pdata->nonremovable) |
| 1992 | msm_host->mmc->caps |= MMC_CAP_NONREMOVABLE; |
| 1993 | |
Sahitya Tummala | c6f48d4 | 2013-03-10 07:03:17 +0530 | [diff] [blame] | 1994 | host->cpu_dma_latency_us = msm_host->pdata->cpu_dma_latency_us; |
| 1995 | |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 1996 | ret = sdhci_msm_bus_register(msm_host, pdev); |
| 1997 | if (ret) |
| 1998 | goto vreg_deinit; |
| 1999 | |
| 2000 | if (msm_host->msm_bus_vote.client_handle) |
| 2001 | INIT_DELAYED_WORK(&msm_host->msm_bus_vote.vote_work, |
| 2002 | sdhci_msm_bus_work); |
| 2003 | |
Sahitya Tummala | 1f52eaa | 2013-03-20 19:24:01 +0530 | [diff] [blame] | 2004 | init_completion(&msm_host->pwr_irq_completion); |
| 2005 | |
Sahitya Tummala | 581df13 | 2013-03-12 14:57:46 +0530 | [diff] [blame] | 2006 | if (gpio_is_valid(msm_host->pdata->status_gpio)) { |
| 2007 | ret = mmc_gpio_request_cd(msm_host->mmc, |
| 2008 | msm_host->pdata->status_gpio, 0); |
| 2009 | if (ret) { |
| 2010 | dev_err(&pdev->dev, "%s: Failed to request card detection IRQ %d\n", |
| 2011 | __func__, ret); |
| 2012 | goto bus_unregister; |
| 2013 | } |
| 2014 | } |
| 2015 | |
Sahitya Tummala | eaa2186 | 2013-03-20 19:34:59 +0530 | [diff] [blame] | 2016 | if (dma_supported(mmc_dev(host->mmc), DMA_BIT_MASK(32))) { |
| 2017 | host->dma_mask = DMA_BIT_MASK(32); |
| 2018 | mmc_dev(host->mmc)->dma_mask = &host->dma_mask; |
| 2019 | } else { |
| 2020 | dev_err(&pdev->dev, "%s: Failed to set dma mask\n", __func__); |
| 2021 | } |
| 2022 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 2023 | ret = sdhci_add_host(host); |
| 2024 | if (ret) { |
| 2025 | dev_err(&pdev->dev, "Add host failed (%d)\n", ret); |
Sahitya Tummala | 581df13 | 2013-03-12 14:57:46 +0530 | [diff] [blame] | 2026 | goto vreg_deinit; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 2027 | } |
| 2028 | |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 2029 | msm_host->msm_bus_vote.max_bus_bw.show = show_sdhci_max_bus_bw; |
| 2030 | msm_host->msm_bus_vote.max_bus_bw.store = store_sdhci_max_bus_bw; |
| 2031 | sysfs_attr_init(&msm_host->msm_bus_vote.max_bus_bw.attr); |
| 2032 | msm_host->msm_bus_vote.max_bus_bw.attr.name = "max_bus_bw"; |
| 2033 | msm_host->msm_bus_vote.max_bus_bw.attr.mode = S_IRUGO | S_IWUSR; |
| 2034 | ret = device_create_file(&pdev->dev, |
| 2035 | &msm_host->msm_bus_vote.max_bus_bw); |
| 2036 | if (ret) |
| 2037 | goto remove_host; |
| 2038 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 2039 | /* Successful initialization */ |
| 2040 | goto out; |
| 2041 | |
| 2042 | remove_host: |
| 2043 | dead = (readl_relaxed(host->ioaddr + SDHCI_INT_STATUS) == 0xffffffff); |
| 2044 | sdhci_remove_host(host, dead); |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 2045 | bus_unregister: |
| 2046 | sdhci_msm_bus_unregister(msm_host); |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 2047 | vreg_deinit: |
| 2048 | sdhci_msm_vreg_init(&pdev->dev, msm_host->pdata, false); |
| 2049 | clk_disable: |
| 2050 | if (!IS_ERR(msm_host->clk)) |
| 2051 | clk_disable_unprepare(msm_host->clk); |
| 2052 | pclk_disable: |
| 2053 | if (!IS_ERR(msm_host->pclk)) |
| 2054 | clk_disable_unprepare(msm_host->pclk); |
| 2055 | bus_clk_disable: |
| 2056 | if (!IS_ERR_OR_NULL(msm_host->bus_clk)) |
| 2057 | clk_disable_unprepare(msm_host->bus_clk); |
| 2058 | pltfm_free: |
| 2059 | sdhci_pltfm_free(pdev); |
| 2060 | out: |
| 2061 | pr_debug("%s: Exit %s\n", dev_name(&pdev->dev), __func__); |
| 2062 | return ret; |
| 2063 | } |
| 2064 | |
| 2065 | static int sdhci_msm_remove(struct platform_device *pdev) |
| 2066 | { |
| 2067 | struct sdhci_host *host = platform_get_drvdata(pdev); |
| 2068 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 2069 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
| 2070 | struct sdhci_msm_pltfm_data *pdata = msm_host->pdata; |
| 2071 | int dead = (readl_relaxed(host->ioaddr + SDHCI_INT_STATUS) == |
| 2072 | 0xffffffff); |
| 2073 | |
| 2074 | pr_debug("%s: %s\n", dev_name(&pdev->dev), __func__); |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 2075 | device_remove_file(&pdev->dev, &msm_host->msm_bus_vote.max_bus_bw); |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 2076 | sdhci_remove_host(host, dead); |
| 2077 | sdhci_pltfm_free(pdev); |
Sahitya Tummala | 581df13 | 2013-03-12 14:57:46 +0530 | [diff] [blame] | 2078 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 2079 | sdhci_msm_vreg_init(&pdev->dev, msm_host->pdata, false); |
Sahitya Tummala | a7f3c57 | 2013-01-11 11:30:45 +0530 | [diff] [blame] | 2080 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 2081 | if (pdata->pin_data) |
| 2082 | sdhci_msm_setup_gpio(pdata, false); |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 2083 | |
| 2084 | if (msm_host->msm_bus_vote.client_handle) { |
| 2085 | sdhci_msm_bus_cancel_work_and_set_vote(host, 0); |
| 2086 | sdhci_msm_bus_unregister(msm_host); |
| 2087 | } |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 2088 | return 0; |
| 2089 | } |
| 2090 | |
| 2091 | static const struct of_device_id sdhci_msm_dt_match[] = { |
| 2092 | {.compatible = "qcom,sdhci-msm"}, |
| 2093 | }; |
| 2094 | MODULE_DEVICE_TABLE(of, sdhci_msm_dt_match); |
| 2095 | |
| 2096 | static struct platform_driver sdhci_msm_driver = { |
| 2097 | .probe = sdhci_msm_probe, |
| 2098 | .remove = sdhci_msm_remove, |
| 2099 | .driver = { |
| 2100 | .name = "sdhci_msm", |
| 2101 | .owner = THIS_MODULE, |
| 2102 | .of_match_table = sdhci_msm_dt_match, |
| 2103 | }, |
| 2104 | }; |
| 2105 | |
| 2106 | module_platform_driver(sdhci_msm_driver); |
| 2107 | |
| 2108 | MODULE_DESCRIPTION("Qualcomm Technologies, Inc. Secure Digital Host Controller Interface driver"); |
| 2109 | MODULE_LICENSE("GPL v2"); |