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 | * |
Venkat Gopalakrishnan | 0a92d53 | 2014-12-16 17:31:00 -0800 | [diff] [blame] | 5 | * Copyright (c) 2012-2015, The Linux Foundation. All rights reserved. |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 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> |
Sahitya Tummala | 581df13 | 2013-03-12 14:57:46 +0530 | [diff] [blame] | 34 | #include <linux/mmc/slot-gpio.h> |
Sahitya Tummala | eaa2186 | 2013-03-20 19:34:59 +0530 | [diff] [blame] | 35 | #include <linux/dma-mapping.h> |
Sahitya Tummala | 66b0fe3 | 2013-04-25 11:50:56 +0530 | [diff] [blame] | 36 | #include <linux/iopoll.h> |
Pratibhasagar V | 9acf264 | 2013-11-21 21:07:21 +0530 | [diff] [blame] | 37 | #include <linux/pinctrl/consumer.h> |
| 38 | #include <linux/iopoll.h> |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 39 | #include <linux/msm-bus.h> |
Konstantin Dorfman | 98377d3 | 2015-02-25 10:09:41 +0200 | [diff] [blame] | 40 | #include <linux/pm_runtime.h> |
Konstantin Dorfman | ddab0cc | 2015-02-25 16:23:50 +0200 | [diff] [blame] | 41 | #include <trace/events/mmc.h> |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 42 | |
Sahitya Tummala | 5687473 | 2015-05-21 08:24:03 +0530 | [diff] [blame] | 43 | #include "sdhci-msm.h" |
Venkat Gopalakrishnan | d371f14 | 2015-05-29 17:49:46 -0700 | [diff] [blame] | 44 | #include "cmdq_hci.h" |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 45 | |
Venkat Gopalakrishnan | 0a92d53 | 2014-12-16 17:31:00 -0800 | [diff] [blame] | 46 | #define CORE_POWER 0x0 |
| 47 | #define CORE_SW_RST (1 << 7) |
| 48 | |
Venkat Gopalakrishnan | a58f91f | 2012-09-17 16:00:15 -0700 | [diff] [blame] | 49 | #define SDHCI_VER_100 0x2B |
Venkat Gopalakrishnan | 0a92d53 | 2014-12-16 17:31:00 -0800 | [diff] [blame] | 50 | #define CORE_MCI_DATA_CNT 0x30 |
| 51 | #define CORE_MCI_STATUS 0x34 |
| 52 | #define CORE_MCI_FIFO_CNT 0x44 |
| 53 | |
| 54 | #define CORE_VERSION_STEP_MASK 0x0000FFFF |
| 55 | #define CORE_VERSION_MINOR_MASK 0x0FFF0000 |
| 56 | #define CORE_VERSION_MINOR_SHIFT 16 |
| 57 | #define CORE_VERSION_MAJOR_MASK 0xF0000000 |
| 58 | #define CORE_VERSION_MAJOR_SHIFT 28 |
| 59 | #define CORE_VERSION_TARGET_MASK 0x000000FF |
| 60 | |
| 61 | #define CORE_GENERICS 0x70 |
| 62 | #define SWITCHABLE_SIGNALLING_VOL (1 << 29) |
Pratibhasagar V | d8acb7c | 2013-11-11 01:32:21 +0530 | [diff] [blame] | 63 | |
| 64 | #define CORE_VERSION_MAJOR_MASK 0xF0000000 |
| 65 | #define CORE_VERSION_MAJOR_SHIFT 28 |
| 66 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 67 | #define CORE_HC_MODE 0x78 |
| 68 | #define HC_MODE_EN 0x1 |
Venkat Gopalakrishnan | 7f69157 | 2013-06-23 17:36:46 -0700 | [diff] [blame] | 69 | #define FF_CLK_SW_RST_DIS (1 << 13) |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 70 | |
Sahitya Tummala | 67717bc | 2013-08-02 09:21:37 +0530 | [diff] [blame] | 71 | #define CORE_MCI_VERSION 0x050 |
| 72 | #define CORE_TESTBUS_CONFIG 0x0CC |
| 73 | #define CORE_TESTBUS_ENA (1 << 3) |
Venkat Gopalakrishnan | 0a92d53 | 2014-12-16 17:31:00 -0800 | [diff] [blame] | 74 | #define CORE_TESTBUS_SEL2_BIT 4 |
| 75 | #define CORE_TESTBUS_SEL2 (1 << CORE_TESTBUS_SEL2_BIT) |
Sahitya Tummala | 67717bc | 2013-08-02 09:21:37 +0530 | [diff] [blame] | 76 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 77 | #define CORE_PWRCTL_STATUS 0xDC |
| 78 | #define CORE_PWRCTL_MASK 0xE0 |
| 79 | #define CORE_PWRCTL_CLEAR 0xE4 |
| 80 | #define CORE_PWRCTL_CTL 0xE8 |
| 81 | |
| 82 | #define CORE_PWRCTL_BUS_OFF 0x01 |
| 83 | #define CORE_PWRCTL_BUS_ON (1 << 1) |
| 84 | #define CORE_PWRCTL_IO_LOW (1 << 2) |
| 85 | #define CORE_PWRCTL_IO_HIGH (1 << 3) |
| 86 | |
| 87 | #define CORE_PWRCTL_BUS_SUCCESS 0x01 |
| 88 | #define CORE_PWRCTL_BUS_FAIL (1 << 1) |
| 89 | #define CORE_PWRCTL_IO_SUCCESS (1 << 2) |
| 90 | #define CORE_PWRCTL_IO_FAIL (1 << 3) |
| 91 | |
| 92 | #define INT_MASK 0xF |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 93 | #define MAX_PHASES 16 |
| 94 | |
Venkat Gopalakrishnan | 9e06963 | 2013-06-12 11:16:37 -0700 | [diff] [blame] | 95 | #define CORE_DLL_CONFIG 0x100 |
| 96 | #define CORE_CMD_DAT_TRACK_SEL (1 << 0) |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 97 | #define CORE_DLL_EN (1 << 16) |
| 98 | #define CORE_CDR_EN (1 << 17) |
| 99 | #define CORE_CK_OUT_EN (1 << 18) |
| 100 | #define CORE_CDR_EXT_EN (1 << 19) |
| 101 | #define CORE_DLL_PDN (1 << 29) |
| 102 | #define CORE_DLL_RST (1 << 30) |
Venkat Gopalakrishnan | 9e06963 | 2013-06-12 11:16:37 -0700 | [diff] [blame] | 103 | |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 104 | #define CORE_DLL_STATUS 0x108 |
Venkat Gopalakrishnan | 9e06963 | 2013-06-12 11:16:37 -0700 | [diff] [blame] | 105 | #define CORE_DLL_LOCK (1 << 7) |
Krishna Konda | 2faa7bb | 2014-06-04 01:25:16 -0700 | [diff] [blame] | 106 | #define CORE_DDR_DLL_LOCK (1 << 11) |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 107 | |
| 108 | #define CORE_VENDOR_SPEC 0x10C |
Krishna Konda | 46fd143 | 2014-10-30 21:13:27 -0700 | [diff] [blame] | 109 | #define CORE_CLK_PWRSAVE (1 << 1) |
| 110 | #define CORE_HC_MCLK_SEL_DFLT (2 << 8) |
| 111 | #define CORE_HC_MCLK_SEL_HS400 (3 << 8) |
| 112 | #define CORE_HC_MCLK_SEL_MASK (3 << 8) |
| 113 | #define CORE_HC_AUTO_CMD21_EN (1 << 6) |
| 114 | #define CORE_IO_PAD_PWR_SWITCH_EN (1 << 15) |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 115 | #define CORE_IO_PAD_PWR_SWITCH (1 << 16) |
Venkat Gopalakrishnan | 7f69157 | 2013-06-23 17:36:46 -0700 | [diff] [blame] | 116 | #define CORE_HC_SELECT_IN_EN (1 << 18) |
| 117 | #define CORE_HC_SELECT_IN_HS400 (6 << 19) |
| 118 | #define CORE_HC_SELECT_IN_MASK (7 << 19) |
Venkat Gopalakrishnan | 17edb35 | 2015-06-24 14:46:49 -0700 | [diff] [blame] | 119 | #define CORE_VENDOR_SPEC_POR_VAL 0xA1C |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 120 | |
Venkat Gopalakrishnan | 0a92d53 | 2014-12-16 17:31:00 -0800 | [diff] [blame] | 121 | #define CORE_VENDOR_SPEC_ADMA_ERR_ADDR0 0x114 |
| 122 | #define CORE_VENDOR_SPEC_ADMA_ERR_ADDR1 0x118 |
| 123 | |
Krishna Konda | 7feab35 | 2013-09-17 23:55:40 -0700 | [diff] [blame] | 124 | #define CORE_VENDOR_SPEC_CAPABILITIES0 0x11C |
Pratibhasagar V | d8acb7c | 2013-11-11 01:32:21 +0530 | [diff] [blame] | 125 | #define CORE_8_BIT_SUPPORT (1 << 18) |
| 126 | #define CORE_3_3V_SUPPORT (1 << 24) |
| 127 | #define CORE_3_0V_SUPPORT (1 << 25) |
| 128 | #define CORE_1_8V_SUPPORT (1 << 26) |
Gilad Broner | 2a10ca0 | 2014-10-02 17:20:35 +0300 | [diff] [blame] | 129 | #define CORE_SYS_BUS_SUPPORT_64_BIT BIT(28) |
Krishna Konda | 7feab35 | 2013-09-17 23:55:40 -0700 | [diff] [blame] | 130 | |
Venkat Gopalakrishnan | 0a92d53 | 2014-12-16 17:31:00 -0800 | [diff] [blame] | 131 | #define CORE_SDCC_DEBUG_REG 0x124 |
Sahitya Tummala | 67717bc | 2013-08-02 09:21:37 +0530 | [diff] [blame] | 132 | |
Venkat Gopalakrishnan | 9e06963 | 2013-06-12 11:16:37 -0700 | [diff] [blame] | 133 | #define CORE_CSR_CDC_CTLR_CFG0 0x130 |
| 134 | #define CORE_SW_TRIG_FULL_CALIB (1 << 16) |
| 135 | #define CORE_HW_AUTOCAL_ENA (1 << 17) |
| 136 | |
| 137 | #define CORE_CSR_CDC_CTLR_CFG1 0x134 |
| 138 | #define CORE_CSR_CDC_CAL_TIMER_CFG0 0x138 |
| 139 | #define CORE_TIMER_ENA (1 << 16) |
| 140 | |
| 141 | #define CORE_CSR_CDC_CAL_TIMER_CFG1 0x13C |
| 142 | #define CORE_CSR_CDC_REFCOUNT_CFG 0x140 |
| 143 | #define CORE_CSR_CDC_COARSE_CAL_CFG 0x144 |
| 144 | #define CORE_CDC_OFFSET_CFG 0x14C |
| 145 | #define CORE_CSR_CDC_DELAY_CFG 0x150 |
| 146 | #define CORE_CDC_SLAVE_DDA_CFG 0x160 |
| 147 | #define CORE_CSR_CDC_STATUS0 0x164 |
| 148 | #define CORE_CALIBRATION_DONE (1 << 0) |
| 149 | |
| 150 | #define CORE_CDC_ERROR_CODE_MASK 0x7000000 |
| 151 | |
| 152 | #define CORE_CSR_CDC_GEN_CFG 0x178 |
| 153 | #define CORE_CDC_SWITCH_BYPASS_OFF (1 << 0) |
| 154 | #define CORE_CDC_SWITCH_RC_EN (1 << 1) |
| 155 | |
| 156 | #define CORE_DDR_200_CFG 0x184 |
| 157 | #define CORE_CDC_T4_DLY_SEL (1 << 0) |
Ritesh Harjani | ea70966 | 2015-05-27 15:40:24 +0530 | [diff] [blame] | 158 | #define CORE_CMDIN_RCLK_EN (1 << 1) |
Venkat Gopalakrishnan | 9e06963 | 2013-06-12 11:16:37 -0700 | [diff] [blame] | 159 | #define CORE_START_CDC_TRAFFIC (1 << 6) |
Ritesh Harjani | ea70966 | 2015-05-27 15:40:24 +0530 | [diff] [blame] | 160 | |
Krishna Konda | 2faa7bb | 2014-06-04 01:25:16 -0700 | [diff] [blame] | 161 | #define CORE_VENDOR_SPEC3 0x1B0 |
| 162 | #define CORE_PWRSAVE_DLL (1 << 3) |
Ritesh Harjani | 4a5ffd1 | 2015-07-15 13:32:07 +0530 | [diff] [blame] | 163 | #define CORE_CMDEN_HS400_INPUT_MASK_CNT (1 << 13) |
Krishna Konda | 2faa7bb | 2014-06-04 01:25:16 -0700 | [diff] [blame] | 164 | |
| 165 | #define CORE_DLL_CONFIG_2 0x1B4 |
| 166 | #define CORE_DDR_CAL_EN (1 << 0) |
Venkat Gopalakrishnan | c0a5c3a | 2015-02-03 16:10:07 -0800 | [diff] [blame] | 167 | #define CORE_FLL_CYCLE_CNT (1 << 18) |
| 168 | #define CORE_DLL_CLOCK_DISABLE (1 << 21) |
Krishna Konda | 2faa7bb | 2014-06-04 01:25:16 -0700 | [diff] [blame] | 169 | |
| 170 | #define CORE_DDR_CONFIG 0x1B8 |
| 171 | #define DDR_CONFIG_POR_VAL 0x80040853 |
| 172 | |
Sahitya Tummala | 5687473 | 2015-05-21 08:24:03 +0530 | [diff] [blame] | 173 | #define MSM_MMC_DEFAULT_CPU_DMA_LATENCY 200 /* usecs */ |
| 174 | |
Venkat Gopalakrishnan | 450745e | 2014-07-24 20:39:34 -0700 | [diff] [blame] | 175 | /* 512 descriptors */ |
| 176 | #define SDHCI_MSM_MAX_SEGMENTS (1 << 9) |
Sahitya Tummala | a7f3c57 | 2013-01-11 11:30:45 +0530 | [diff] [blame] | 177 | #define SDHCI_MSM_MMC_CLK_GATE_DELAY 200 /* msecs */ |
Asutosh Das | 648f9d1 | 2013-01-10 21:11:04 +0530 | [diff] [blame] | 178 | |
Venkat Gopalakrishnan | 7f69157 | 2013-06-23 17:36:46 -0700 | [diff] [blame] | 179 | #define CORE_FREQ_100MHZ (100 * 1000 * 1000) |
Venkat Gopalakrishnan | c0a5c3a | 2015-02-03 16:10:07 -0800 | [diff] [blame] | 180 | #define TCXO_FREQ 19200000 |
Venkat Gopalakrishnan | 7f69157 | 2013-06-23 17:36:46 -0700 | [diff] [blame] | 181 | |
Venkat Gopalakrishnan | 9e06963 | 2013-06-12 11:16:37 -0700 | [diff] [blame] | 182 | #define INVALID_TUNING_PHASE -1 |
| 183 | |
Krishna Konda | 96e6b11 | 2013-10-28 15:25:03 -0700 | [diff] [blame] | 184 | #define NUM_TUNING_PHASES 16 |
| 185 | #define MAX_DRV_TYPES_SUPPORTED_HS200 3 |
Konstantin Dorfman | 98377d3 | 2015-02-25 10:09:41 +0200 | [diff] [blame] | 186 | #define MSM_AUTOSUSPEND_DELAY_MS 100 |
Krishna Konda | 96e6b11 | 2013-10-28 15:25:03 -0700 | [diff] [blame] | 187 | |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 188 | static const u32 tuning_block_64[] = { |
| 189 | 0x00FF0FFF, 0xCCC3CCFF, 0xFFCC3CC3, 0xEFFEFFFE, |
| 190 | 0xDDFFDFFF, 0xFBFFFBFF, 0xFF7FFFBF, 0xEFBDF777, |
| 191 | 0xF0FFF0FF, 0x3CCCFC0F, 0xCFCC33CC, 0xEEFFEFFF, |
| 192 | 0xFDFFFDFF, 0xFFBFFFDF, 0xFFF7FFBB, 0xDE7B7FF7 |
| 193 | }; |
| 194 | |
| 195 | static const u32 tuning_block_128[] = { |
| 196 | 0xFF00FFFF, 0x0000FFFF, 0xCCCCFFFF, 0xCCCC33CC, |
| 197 | 0xCC3333CC, 0xFFFFCCCC, 0xFFFFEEFF, 0xFFEEEEFF, |
| 198 | 0xFFDDFFFF, 0xDDDDFFFF, 0xBBFFFFFF, 0xBBFFFFFF, |
| 199 | 0xFFFFFFBB, 0xFFFFFF77, 0x77FF7777, 0xFFEEDDBB, |
| 200 | 0x00FFFFFF, 0x00FFFFFF, 0xCCFFFF00, 0xCC33CCCC, |
| 201 | 0x3333CCCC, 0xFFCCCCCC, 0xFFEEFFFF, 0xEEEEFFFF, |
| 202 | 0xDDFFFFFF, 0xDDFFFFFF, 0xFFFFFFDD, 0xFFFFFFBB, |
| 203 | 0xFFFFBBBB, 0xFFFF77FF, 0xFF7777FF, 0xEEDDBB77 |
| 204 | }; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 205 | |
Venkat Gopalakrishnan | 270580a | 2013-03-11 12:17:57 -0700 | [diff] [blame] | 206 | static int disable_slots; |
| 207 | /* root can write, others read */ |
| 208 | module_param(disable_slots, int, S_IRUGO|S_IWUSR); |
| 209 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 210 | enum vdd_io_level { |
| 211 | /* set vdd_io_data->low_vol_level */ |
| 212 | VDD_IO_LOW, |
| 213 | /* set vdd_io_data->high_vol_level */ |
| 214 | VDD_IO_HIGH, |
| 215 | /* |
| 216 | * set whatever there in voltage_level (third argument) of |
| 217 | * sdhci_msm_set_vdd_io_vol() function. |
| 218 | */ |
| 219 | VDD_IO_SET_LEVEL, |
| 220 | }; |
| 221 | |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 222 | /* MSM platform specific tuning */ |
| 223 | static inline int msm_dll_poll_ck_out_en(struct sdhci_host *host, |
| 224 | u8 poll) |
| 225 | { |
| 226 | int rc = 0; |
| 227 | u32 wait_cnt = 50; |
| 228 | u8 ck_out_en = 0; |
| 229 | struct mmc_host *mmc = host->mmc; |
| 230 | |
| 231 | /* poll for CK_OUT_EN bit. max. poll time = 50us */ |
| 232 | ck_out_en = !!(readl_relaxed(host->ioaddr + CORE_DLL_CONFIG) & |
| 233 | CORE_CK_OUT_EN); |
| 234 | |
| 235 | while (ck_out_en != poll) { |
| 236 | if (--wait_cnt == 0) { |
| 237 | pr_err("%s: %s: CK_OUT_EN bit is not %d\n", |
| 238 | mmc_hostname(mmc), __func__, poll); |
| 239 | rc = -ETIMEDOUT; |
| 240 | goto out; |
| 241 | } |
| 242 | udelay(1); |
| 243 | |
| 244 | ck_out_en = !!(readl_relaxed(host->ioaddr + |
| 245 | CORE_DLL_CONFIG) & CORE_CK_OUT_EN); |
| 246 | } |
| 247 | out: |
| 248 | return rc; |
| 249 | } |
| 250 | |
Asutosh Das | e5e9ca6 | 2013-07-30 19:08:36 +0530 | [diff] [blame] | 251 | /* |
| 252 | * Enable CDR to track changes of DAT lines and adjust sampling |
| 253 | * point according to voltage/temperature variations |
| 254 | */ |
| 255 | static int msm_enable_cdr_cm_sdc4_dll(struct sdhci_host *host) |
| 256 | { |
| 257 | int rc = 0; |
| 258 | u32 config; |
| 259 | |
| 260 | config = readl_relaxed(host->ioaddr + CORE_DLL_CONFIG); |
| 261 | config |= CORE_CDR_EN; |
| 262 | config &= ~(CORE_CDR_EXT_EN | CORE_CK_OUT_EN); |
| 263 | writel_relaxed(config, host->ioaddr + CORE_DLL_CONFIG); |
| 264 | |
| 265 | rc = msm_dll_poll_ck_out_en(host, 0); |
| 266 | if (rc) |
| 267 | goto err; |
| 268 | |
| 269 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG) | |
| 270 | CORE_CK_OUT_EN), host->ioaddr + CORE_DLL_CONFIG); |
| 271 | |
| 272 | rc = msm_dll_poll_ck_out_en(host, 1); |
| 273 | if (rc) |
| 274 | goto err; |
| 275 | goto out; |
| 276 | err: |
| 277 | pr_err("%s: %s: failed\n", mmc_hostname(host->mmc), __func__); |
| 278 | out: |
| 279 | return rc; |
| 280 | } |
| 281 | |
| 282 | static ssize_t store_auto_cmd21(struct device *dev, struct device_attribute |
| 283 | *attr, const char *buf, size_t count) |
| 284 | { |
| 285 | struct sdhci_host *host = dev_get_drvdata(dev); |
| 286 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 287 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
| 288 | u32 tmp; |
| 289 | unsigned long flags; |
| 290 | |
| 291 | if (!kstrtou32(buf, 0, &tmp)) { |
| 292 | spin_lock_irqsave(&host->lock, flags); |
| 293 | msm_host->en_auto_cmd21 = !!tmp; |
| 294 | spin_unlock_irqrestore(&host->lock, flags); |
| 295 | } |
| 296 | return count; |
| 297 | } |
| 298 | |
| 299 | static ssize_t show_auto_cmd21(struct device *dev, |
| 300 | struct device_attribute *attr, char *buf) |
| 301 | { |
| 302 | struct sdhci_host *host = dev_get_drvdata(dev); |
| 303 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 304 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
| 305 | |
| 306 | return snprintf(buf, PAGE_SIZE, "%d\n", msm_host->en_auto_cmd21); |
| 307 | } |
| 308 | |
| 309 | /* MSM auto-tuning handler */ |
| 310 | static int sdhci_msm_config_auto_tuning_cmd(struct sdhci_host *host, |
| 311 | bool enable, |
| 312 | u32 type) |
| 313 | { |
| 314 | int rc = 0; |
| 315 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 316 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
| 317 | u32 val = 0; |
| 318 | |
| 319 | if (!msm_host->en_auto_cmd21) |
| 320 | return 0; |
| 321 | |
| 322 | if (type == MMC_SEND_TUNING_BLOCK_HS200) |
| 323 | val = CORE_HC_AUTO_CMD21_EN; |
| 324 | else |
| 325 | return 0; |
| 326 | |
| 327 | if (enable) { |
| 328 | rc = msm_enable_cdr_cm_sdc4_dll(host); |
| 329 | writel_relaxed(readl_relaxed(host->ioaddr + CORE_VENDOR_SPEC) | |
| 330 | val, host->ioaddr + CORE_VENDOR_SPEC); |
| 331 | } else { |
| 332 | writel_relaxed(readl_relaxed(host->ioaddr + CORE_VENDOR_SPEC) & |
| 333 | ~val, host->ioaddr + CORE_VENDOR_SPEC); |
| 334 | } |
| 335 | return rc; |
| 336 | } |
| 337 | |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 338 | static int msm_config_cm_dll_phase(struct sdhci_host *host, u8 phase) |
| 339 | { |
| 340 | int rc = 0; |
| 341 | u8 grey_coded_phase_table[] = {0x0, 0x1, 0x3, 0x2, 0x6, 0x7, 0x5, 0x4, |
| 342 | 0xC, 0xD, 0xF, 0xE, 0xA, 0xB, 0x9, |
| 343 | 0x8}; |
| 344 | unsigned long flags; |
| 345 | u32 config; |
| 346 | struct mmc_host *mmc = host->mmc; |
| 347 | |
| 348 | pr_debug("%s: Enter %s\n", mmc_hostname(mmc), __func__); |
| 349 | spin_lock_irqsave(&host->lock, flags); |
| 350 | |
| 351 | config = readl_relaxed(host->ioaddr + CORE_DLL_CONFIG); |
| 352 | config &= ~(CORE_CDR_EN | CORE_CK_OUT_EN); |
| 353 | config |= (CORE_CDR_EXT_EN | CORE_DLL_EN); |
| 354 | writel_relaxed(config, host->ioaddr + CORE_DLL_CONFIG); |
| 355 | |
| 356 | /* Wait until CK_OUT_EN bit of DLL_CONFIG register becomes '0' */ |
| 357 | rc = msm_dll_poll_ck_out_en(host, 0); |
| 358 | if (rc) |
| 359 | goto err_out; |
| 360 | |
| 361 | /* |
| 362 | * Write the selected DLL clock output phase (0 ... 15) |
| 363 | * to CDR_SELEXT bit field of DLL_CONFIG register. |
| 364 | */ |
| 365 | writel_relaxed(((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG) |
| 366 | & ~(0xF << 20)) |
| 367 | | (grey_coded_phase_table[phase] << 20)), |
| 368 | host->ioaddr + CORE_DLL_CONFIG); |
| 369 | |
| 370 | /* Set CK_OUT_EN bit of DLL_CONFIG register to 1. */ |
| 371 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG) |
| 372 | | CORE_CK_OUT_EN), host->ioaddr + CORE_DLL_CONFIG); |
| 373 | |
| 374 | /* Wait until CK_OUT_EN bit of DLL_CONFIG register becomes '1' */ |
| 375 | rc = msm_dll_poll_ck_out_en(host, 1); |
| 376 | if (rc) |
| 377 | goto err_out; |
| 378 | |
| 379 | config = readl_relaxed(host->ioaddr + CORE_DLL_CONFIG); |
| 380 | config |= CORE_CDR_EN; |
| 381 | config &= ~CORE_CDR_EXT_EN; |
| 382 | writel_relaxed(config, host->ioaddr + CORE_DLL_CONFIG); |
| 383 | goto out; |
| 384 | |
| 385 | err_out: |
| 386 | pr_err("%s: %s: Failed to set DLL phase: %d\n", |
| 387 | mmc_hostname(mmc), __func__, phase); |
| 388 | out: |
| 389 | spin_unlock_irqrestore(&host->lock, flags); |
| 390 | pr_debug("%s: Exit %s\n", mmc_hostname(mmc), __func__); |
| 391 | return rc; |
| 392 | } |
| 393 | |
| 394 | /* |
| 395 | * Find out the greatest range of consecuitive selected |
| 396 | * DLL clock output phases that can be used as sampling |
| 397 | * setting for SD3.0 UHS-I card read operation (in SDR104 |
Venkat Gopalakrishnan | 7f69157 | 2013-06-23 17:36:46 -0700 | [diff] [blame] | 398 | * timing mode) or for eMMC4.5 card read operation (in |
| 399 | * HS400/HS200 timing mode). |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 400 | * Select the 3/4 of the range and configure the DLL with the |
| 401 | * selected DLL clock output phase. |
| 402 | */ |
| 403 | |
| 404 | static int msm_find_most_appropriate_phase(struct sdhci_host *host, |
| 405 | u8 *phase_table, u8 total_phases) |
| 406 | { |
| 407 | int ret; |
| 408 | u8 ranges[MAX_PHASES][MAX_PHASES] = { {0}, {0} }; |
| 409 | u8 phases_per_row[MAX_PHASES] = {0}; |
| 410 | int row_index = 0, col_index = 0, selected_row_index = 0, curr_max = 0; |
| 411 | int i, cnt, phase_0_raw_index = 0, phase_15_raw_index = 0; |
| 412 | bool phase_0_found = false, phase_15_found = false; |
| 413 | struct mmc_host *mmc = host->mmc; |
| 414 | |
| 415 | pr_debug("%s: Enter %s\n", mmc_hostname(mmc), __func__); |
| 416 | if (!total_phases || (total_phases > MAX_PHASES)) { |
| 417 | pr_err("%s: %s: invalid argument: total_phases=%d\n", |
| 418 | mmc_hostname(mmc), __func__, total_phases); |
| 419 | return -EINVAL; |
| 420 | } |
| 421 | |
| 422 | for (cnt = 0; cnt < total_phases; cnt++) { |
| 423 | ranges[row_index][col_index] = phase_table[cnt]; |
| 424 | phases_per_row[row_index] += 1; |
| 425 | col_index++; |
| 426 | |
| 427 | if ((cnt + 1) == total_phases) { |
| 428 | continue; |
| 429 | /* check if next phase in phase_table is consecutive or not */ |
| 430 | } else if ((phase_table[cnt] + 1) != phase_table[cnt + 1]) { |
| 431 | row_index++; |
| 432 | col_index = 0; |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | if (row_index >= MAX_PHASES) |
| 437 | return -EINVAL; |
| 438 | |
| 439 | /* Check if phase-0 is present in first valid window? */ |
| 440 | if (!ranges[0][0]) { |
| 441 | phase_0_found = true; |
| 442 | phase_0_raw_index = 0; |
| 443 | /* Check if cycle exist between 2 valid windows */ |
| 444 | for (cnt = 1; cnt <= row_index; cnt++) { |
| 445 | if (phases_per_row[cnt]) { |
| 446 | for (i = 0; i < phases_per_row[cnt]; i++) { |
| 447 | if (ranges[cnt][i] == 15) { |
| 448 | phase_15_found = true; |
| 449 | phase_15_raw_index = cnt; |
| 450 | break; |
| 451 | } |
| 452 | } |
| 453 | } |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | /* If 2 valid windows form cycle then merge them as single window */ |
| 458 | if (phase_0_found && phase_15_found) { |
| 459 | /* number of phases in raw where phase 0 is present */ |
| 460 | u8 phases_0 = phases_per_row[phase_0_raw_index]; |
| 461 | /* number of phases in raw where phase 15 is present */ |
| 462 | u8 phases_15 = phases_per_row[phase_15_raw_index]; |
| 463 | |
| 464 | if (phases_0 + phases_15 >= MAX_PHASES) |
| 465 | /* |
| 466 | * If there are more than 1 phase windows then total |
| 467 | * number of phases in both the windows should not be |
| 468 | * more than or equal to MAX_PHASES. |
| 469 | */ |
| 470 | return -EINVAL; |
| 471 | |
| 472 | /* Merge 2 cyclic windows */ |
| 473 | i = phases_15; |
| 474 | for (cnt = 0; cnt < phases_0; cnt++) { |
| 475 | ranges[phase_15_raw_index][i] = |
| 476 | ranges[phase_0_raw_index][cnt]; |
| 477 | if (++i >= MAX_PHASES) |
| 478 | break; |
| 479 | } |
| 480 | |
| 481 | phases_per_row[phase_0_raw_index] = 0; |
| 482 | phases_per_row[phase_15_raw_index] = phases_15 + phases_0; |
| 483 | } |
| 484 | |
| 485 | for (cnt = 0; cnt <= row_index; cnt++) { |
| 486 | if (phases_per_row[cnt] > curr_max) { |
| 487 | curr_max = phases_per_row[cnt]; |
| 488 | selected_row_index = cnt; |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | i = ((curr_max * 3) / 4); |
| 493 | if (i) |
| 494 | i--; |
| 495 | |
| 496 | ret = (int)ranges[selected_row_index][i]; |
| 497 | |
| 498 | if (ret >= MAX_PHASES) { |
| 499 | ret = -EINVAL; |
| 500 | pr_err("%s: %s: invalid phase selected=%d\n", |
| 501 | mmc_hostname(mmc), __func__, ret); |
| 502 | } |
| 503 | |
| 504 | pr_debug("%s: Exit %s\n", mmc_hostname(mmc), __func__); |
| 505 | return ret; |
| 506 | } |
| 507 | |
| 508 | static inline void msm_cm_dll_set_freq(struct sdhci_host *host) |
| 509 | { |
| 510 | u32 mclk_freq = 0; |
| 511 | |
| 512 | /* Program the MCLK value to MCLK_FREQ bit field */ |
| 513 | if (host->clock <= 112000000) |
| 514 | mclk_freq = 0; |
| 515 | else if (host->clock <= 125000000) |
| 516 | mclk_freq = 1; |
| 517 | else if (host->clock <= 137000000) |
| 518 | mclk_freq = 2; |
| 519 | else if (host->clock <= 150000000) |
| 520 | mclk_freq = 3; |
| 521 | else if (host->clock <= 162000000) |
| 522 | mclk_freq = 4; |
| 523 | else if (host->clock <= 175000000) |
| 524 | mclk_freq = 5; |
| 525 | else if (host->clock <= 187000000) |
| 526 | mclk_freq = 6; |
| 527 | else if (host->clock <= 200000000) |
| 528 | mclk_freq = 7; |
| 529 | |
| 530 | writel_relaxed(((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG) |
| 531 | & ~(7 << 24)) | (mclk_freq << 24)), |
| 532 | host->ioaddr + CORE_DLL_CONFIG); |
| 533 | } |
| 534 | |
| 535 | /* Initialize the DLL (Programmable Delay Line ) */ |
| 536 | static int msm_init_cm_dll(struct sdhci_host *host) |
| 537 | { |
Venkat Gopalakrishnan | c0a5c3a | 2015-02-03 16:10:07 -0800 | [diff] [blame] | 538 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 539 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 540 | struct mmc_host *mmc = host->mmc; |
| 541 | int rc = 0; |
| 542 | unsigned long flags; |
| 543 | u32 wait_cnt; |
Subhash Jadavani | 99bca3b | 2013-05-28 18:21:57 +0530 | [diff] [blame] | 544 | bool prev_pwrsave, curr_pwrsave; |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 545 | |
| 546 | pr_debug("%s: Enter %s\n", mmc_hostname(mmc), __func__); |
| 547 | spin_lock_irqsave(&host->lock, flags); |
Subhash Jadavani | 99bca3b | 2013-05-28 18:21:57 +0530 | [diff] [blame] | 548 | prev_pwrsave = !!(readl_relaxed(host->ioaddr + CORE_VENDOR_SPEC) & |
| 549 | CORE_CLK_PWRSAVE); |
| 550 | curr_pwrsave = prev_pwrsave; |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 551 | /* |
| 552 | * Make sure that clock is always enabled when DLL |
| 553 | * tuning is in progress. Keeping PWRSAVE ON may |
| 554 | * turn off the clock. So let's disable the PWRSAVE |
| 555 | * here and re-enable it once tuning is completed. |
| 556 | */ |
Subhash Jadavani | 99bca3b | 2013-05-28 18:21:57 +0530 | [diff] [blame] | 557 | if (prev_pwrsave) { |
| 558 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_VENDOR_SPEC) |
| 559 | & ~CORE_CLK_PWRSAVE), |
| 560 | host->ioaddr + CORE_VENDOR_SPEC); |
| 561 | curr_pwrsave = false; |
| 562 | } |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 563 | |
Venkat Gopalakrishnan | c0a5c3a | 2015-02-03 16:10:07 -0800 | [diff] [blame] | 564 | if (msm_host->use_updated_dll_reset) { |
| 565 | /* Disable the DLL clock */ |
| 566 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG) |
| 567 | & ~CORE_CK_OUT_EN), |
| 568 | host->ioaddr + CORE_DLL_CONFIG); |
| 569 | |
| 570 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG_2) |
| 571 | | CORE_DLL_CLOCK_DISABLE), |
| 572 | host->ioaddr + CORE_DLL_CONFIG_2); |
| 573 | } |
| 574 | |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 575 | /* Write 1 to DLL_RST bit of DLL_CONFIG register */ |
| 576 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG) |
| 577 | | CORE_DLL_RST), host->ioaddr + CORE_DLL_CONFIG); |
| 578 | |
| 579 | /* Write 1 to DLL_PDN bit of DLL_CONFIG register */ |
| 580 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG) |
| 581 | | CORE_DLL_PDN), host->ioaddr + CORE_DLL_CONFIG); |
| 582 | msm_cm_dll_set_freq(host); |
| 583 | |
Venkat Gopalakrishnan | c0a5c3a | 2015-02-03 16:10:07 -0800 | [diff] [blame] | 584 | if (msm_host->use_updated_dll_reset) { |
| 585 | u32 mclk_freq = 0; |
| 586 | |
| 587 | if ((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG_2) |
| 588 | & CORE_FLL_CYCLE_CNT)) |
| 589 | mclk_freq = (u32) ((host->clock / TCXO_FREQ) * 8); |
| 590 | else |
| 591 | mclk_freq = (u32) ((host->clock / TCXO_FREQ) * 4); |
| 592 | |
| 593 | writel_relaxed(((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG_2) |
| 594 | & ~(0xFF << 10)) | (mclk_freq << 10)), |
| 595 | host->ioaddr + CORE_DLL_CONFIG_2); |
| 596 | /* wait for 5us before enabling DLL clock */ |
| 597 | udelay(5); |
| 598 | } |
| 599 | |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 600 | /* Write 0 to DLL_RST bit of DLL_CONFIG register */ |
| 601 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG) |
| 602 | & ~CORE_DLL_RST), host->ioaddr + CORE_DLL_CONFIG); |
| 603 | |
| 604 | /* Write 0 to DLL_PDN bit of DLL_CONFIG register */ |
| 605 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG) |
| 606 | & ~CORE_DLL_PDN), host->ioaddr + CORE_DLL_CONFIG); |
| 607 | |
Venkat Gopalakrishnan | c0a5c3a | 2015-02-03 16:10:07 -0800 | [diff] [blame] | 608 | if (msm_host->use_updated_dll_reset) { |
| 609 | msm_cm_dll_set_freq(host); |
| 610 | /* Enable the DLL clock */ |
| 611 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG_2) |
| 612 | & ~CORE_DLL_CLOCK_DISABLE), |
| 613 | host->ioaddr + CORE_DLL_CONFIG_2); |
| 614 | } |
| 615 | |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 616 | /* Set DLL_EN bit to 1. */ |
| 617 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG) |
| 618 | | CORE_DLL_EN), host->ioaddr + CORE_DLL_CONFIG); |
| 619 | |
| 620 | /* Set CK_OUT_EN bit to 1. */ |
| 621 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG) |
| 622 | | CORE_CK_OUT_EN), host->ioaddr + CORE_DLL_CONFIG); |
| 623 | |
| 624 | wait_cnt = 50; |
| 625 | /* Wait until DLL_LOCK bit of DLL_STATUS register becomes '1' */ |
| 626 | while (!(readl_relaxed(host->ioaddr + CORE_DLL_STATUS) & |
| 627 | CORE_DLL_LOCK)) { |
| 628 | /* max. wait for 50us sec for LOCK bit to be set */ |
| 629 | if (--wait_cnt == 0) { |
| 630 | pr_err("%s: %s: DLL failed to LOCK\n", |
| 631 | mmc_hostname(mmc), __func__); |
| 632 | rc = -ETIMEDOUT; |
| 633 | goto out; |
| 634 | } |
| 635 | /* wait for 1us before polling again */ |
| 636 | udelay(1); |
| 637 | } |
| 638 | |
| 639 | out: |
Subhash Jadavani | 99bca3b | 2013-05-28 18:21:57 +0530 | [diff] [blame] | 640 | /* Restore the correct PWRSAVE state */ |
| 641 | if (prev_pwrsave ^ curr_pwrsave) { |
| 642 | u32 reg = readl_relaxed(host->ioaddr + CORE_VENDOR_SPEC); |
| 643 | |
| 644 | if (prev_pwrsave) |
| 645 | reg |= CORE_CLK_PWRSAVE; |
| 646 | else |
| 647 | reg &= ~CORE_CLK_PWRSAVE; |
| 648 | |
| 649 | writel_relaxed(reg, host->ioaddr + CORE_VENDOR_SPEC); |
| 650 | } |
| 651 | |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 652 | spin_unlock_irqrestore(&host->lock, flags); |
| 653 | pr_debug("%s: Exit %s\n", mmc_hostname(mmc), __func__); |
| 654 | return rc; |
| 655 | } |
| 656 | |
Venkat Gopalakrishnan | 9e06963 | 2013-06-12 11:16:37 -0700 | [diff] [blame] | 657 | static int sdhci_msm_cdclp533_calibration(struct sdhci_host *host) |
| 658 | { |
Krishna Konda | 2faa7bb | 2014-06-04 01:25:16 -0700 | [diff] [blame] | 659 | u32 calib_done; |
Venkat Gopalakrishnan | 9e06963 | 2013-06-12 11:16:37 -0700 | [diff] [blame] | 660 | int ret = 0; |
| 661 | int cdc_err = 0; |
Venkat Gopalakrishnan | 9e06963 | 2013-06-12 11:16:37 -0700 | [diff] [blame] | 662 | |
| 663 | pr_debug("%s: Enter %s\n", mmc_hostname(host->mmc), __func__); |
| 664 | |
Venkat Gopalakrishnan | 9e06963 | 2013-06-12 11:16:37 -0700 | [diff] [blame] | 665 | /* Write 0 to CDC_T4_DLY_SEL field in VENDOR_SPEC_DDR200_CFG */ |
| 666 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_DDR_200_CFG) |
| 667 | & ~CORE_CDC_T4_DLY_SEL), |
| 668 | host->ioaddr + CORE_DDR_200_CFG); |
| 669 | |
| 670 | /* Write 0 to CDC_SWITCH_BYPASS_OFF field in CORE_CSR_CDC_GEN_CFG */ |
| 671 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_CSR_CDC_GEN_CFG) |
| 672 | & ~CORE_CDC_SWITCH_BYPASS_OFF), |
| 673 | host->ioaddr + CORE_CSR_CDC_GEN_CFG); |
| 674 | |
| 675 | /* Write 1 to CDC_SWITCH_RC_EN field in CORE_CSR_CDC_GEN_CFG */ |
| 676 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_CSR_CDC_GEN_CFG) |
| 677 | | CORE_CDC_SWITCH_RC_EN), |
| 678 | host->ioaddr + CORE_CSR_CDC_GEN_CFG); |
| 679 | |
| 680 | /* Write 0 to START_CDC_TRAFFIC field in CORE_DDR200_CFG */ |
| 681 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_DDR_200_CFG) |
| 682 | & ~CORE_START_CDC_TRAFFIC), |
| 683 | host->ioaddr + CORE_DDR_200_CFG); |
| 684 | |
| 685 | /* |
| 686 | * Perform CDC Register Initialization Sequence |
| 687 | * |
| 688 | * CORE_CSR_CDC_CTLR_CFG0 0x11800EC |
| 689 | * CORE_CSR_CDC_CTLR_CFG1 0x3011111 |
| 690 | * CORE_CSR_CDC_CAL_TIMER_CFG0 0x1201000 |
| 691 | * CORE_CSR_CDC_CAL_TIMER_CFG1 0x4 |
| 692 | * CORE_CSR_CDC_REFCOUNT_CFG 0xCB732020 |
| 693 | * CORE_CSR_CDC_COARSE_CAL_CFG 0xB19 |
| 694 | * CORE_CSR_CDC_DELAY_CFG 0x3AC |
| 695 | * CORE_CDC_OFFSET_CFG 0x0 |
| 696 | * CORE_CDC_SLAVE_DDA_CFG 0x16334 |
| 697 | */ |
| 698 | |
| 699 | writel_relaxed(0x11800EC, host->ioaddr + CORE_CSR_CDC_CTLR_CFG0); |
| 700 | writel_relaxed(0x3011111, host->ioaddr + CORE_CSR_CDC_CTLR_CFG1); |
| 701 | writel_relaxed(0x1201000, host->ioaddr + CORE_CSR_CDC_CAL_TIMER_CFG0); |
| 702 | writel_relaxed(0x4, host->ioaddr + CORE_CSR_CDC_CAL_TIMER_CFG1); |
| 703 | writel_relaxed(0xCB732020, host->ioaddr + CORE_CSR_CDC_REFCOUNT_CFG); |
| 704 | writel_relaxed(0xB19, host->ioaddr + CORE_CSR_CDC_COARSE_CAL_CFG); |
Subhash Jadavani | be406d9 | 2014-06-17 16:47:48 -0700 | [diff] [blame] | 705 | writel_relaxed(0x4E2, host->ioaddr + CORE_CSR_CDC_DELAY_CFG); |
Venkat Gopalakrishnan | 9e06963 | 2013-06-12 11:16:37 -0700 | [diff] [blame] | 706 | writel_relaxed(0x0, host->ioaddr + CORE_CDC_OFFSET_CFG); |
| 707 | writel_relaxed(0x16334, host->ioaddr + CORE_CDC_SLAVE_DDA_CFG); |
| 708 | |
| 709 | /* CDC HW Calibration */ |
| 710 | |
| 711 | /* Write 1 to SW_TRIG_FULL_CALIB field in CORE_CSR_CDC_CTLR_CFG0 */ |
| 712 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_CSR_CDC_CTLR_CFG0) |
| 713 | | CORE_SW_TRIG_FULL_CALIB), |
| 714 | host->ioaddr + CORE_CSR_CDC_CTLR_CFG0); |
| 715 | |
| 716 | /* Write 0 to SW_TRIG_FULL_CALIB field in CORE_CSR_CDC_CTLR_CFG0 */ |
| 717 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_CSR_CDC_CTLR_CFG0) |
| 718 | & ~CORE_SW_TRIG_FULL_CALIB), |
| 719 | host->ioaddr + CORE_CSR_CDC_CTLR_CFG0); |
| 720 | |
| 721 | /* Write 1 to HW_AUTOCAL_ENA field in CORE_CSR_CDC_CTLR_CFG0 */ |
| 722 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_CSR_CDC_CTLR_CFG0) |
| 723 | | CORE_HW_AUTOCAL_ENA), |
| 724 | host->ioaddr + CORE_CSR_CDC_CTLR_CFG0); |
| 725 | |
| 726 | /* Write 1 to TIMER_ENA field in CORE_CSR_CDC_CAL_TIMER_CFG0 */ |
| 727 | writel_relaxed((readl_relaxed(host->ioaddr + |
| 728 | CORE_CSR_CDC_CAL_TIMER_CFG0) | CORE_TIMER_ENA), |
| 729 | host->ioaddr + CORE_CSR_CDC_CAL_TIMER_CFG0); |
| 730 | |
| 731 | mb(); |
| 732 | |
| 733 | /* Poll on CALIBRATION_DONE field in CORE_CSR_CDC_STATUS0 to be 1 */ |
Krishna Konda | 2faa7bb | 2014-06-04 01:25:16 -0700 | [diff] [blame] | 734 | ret = readl_poll_timeout(host->ioaddr + CORE_CSR_CDC_STATUS0, |
| 735 | calib_done, (calib_done & CORE_CALIBRATION_DONE), 1, 50); |
| 736 | |
| 737 | if (ret == -ETIMEDOUT) { |
| 738 | pr_err("%s: %s: CDC Calibration was not completed\n", |
Venkat Gopalakrishnan | 9e06963 | 2013-06-12 11:16:37 -0700 | [diff] [blame] | 739 | mmc_hostname(host->mmc), __func__); |
Krishna Konda | 2faa7bb | 2014-06-04 01:25:16 -0700 | [diff] [blame] | 740 | goto out; |
Venkat Gopalakrishnan | 9e06963 | 2013-06-12 11:16:37 -0700 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | /* Verify CDC_ERROR_CODE field in CORE_CSR_CDC_STATUS0 is 0 */ |
| 744 | cdc_err = readl_relaxed(host->ioaddr + CORE_CSR_CDC_STATUS0) |
| 745 | & CORE_CDC_ERROR_CODE_MASK; |
| 746 | if (cdc_err) { |
| 747 | pr_err("%s: %s: CDC Error Code %d\n", |
| 748 | mmc_hostname(host->mmc), __func__, cdc_err); |
| 749 | ret = -EINVAL; |
| 750 | goto out; |
| 751 | } |
| 752 | |
| 753 | /* Write 1 to START_CDC_TRAFFIC field in CORE_DDR200_CFG */ |
| 754 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_DDR_200_CFG) |
| 755 | | CORE_START_CDC_TRAFFIC), |
| 756 | host->ioaddr + CORE_DDR_200_CFG); |
| 757 | out: |
| 758 | pr_debug("%s: Exit %s, ret:%d\n", mmc_hostname(host->mmc), |
| 759 | __func__, ret); |
| 760 | return ret; |
| 761 | } |
| 762 | |
Krishna Konda | 2faa7bb | 2014-06-04 01:25:16 -0700 | [diff] [blame] | 763 | static int sdhci_msm_cm_dll_sdc4_calibration(struct sdhci_host *host) |
| 764 | { |
Ritesh Harjani | 764065e | 2015-05-13 14:14:45 +0530 | [diff] [blame] | 765 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 766 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
Krishna Konda | 2faa7bb | 2014-06-04 01:25:16 -0700 | [diff] [blame] | 767 | u32 dll_status; |
| 768 | int ret = 0; |
| 769 | |
| 770 | pr_debug("%s: Enter %s\n", mmc_hostname(host->mmc), __func__); |
| 771 | |
| 772 | /* |
| 773 | * Currently the CORE_DDR_CONFIG register defaults to desired |
| 774 | * configuration on reset. Currently reprogramming the power on |
| 775 | * reset (POR) value in case it might have been modified by |
| 776 | * bootloaders. In the future, if this changes, then the desired |
| 777 | * values will need to be programmed appropriately. |
| 778 | */ |
| 779 | writel_relaxed(DDR_CONFIG_POR_VAL, host->ioaddr + CORE_DDR_CONFIG); |
| 780 | |
Ritesh Harjani | ea70966 | 2015-05-27 15:40:24 +0530 | [diff] [blame] | 781 | if (msm_host->enhanced_strobe) |
| 782 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_DDR_200_CFG) |
| 783 | | CORE_CMDIN_RCLK_EN), |
| 784 | host->ioaddr + CORE_DDR_200_CFG); |
| 785 | |
Krishna Konda | 2faa7bb | 2014-06-04 01:25:16 -0700 | [diff] [blame] | 786 | /* Write 1 to DDR_CAL_EN field in CORE_DLL_CONFIG_2 */ |
| 787 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG_2) |
| 788 | | CORE_DDR_CAL_EN), |
| 789 | host->ioaddr + CORE_DLL_CONFIG_2); |
| 790 | |
| 791 | /* Poll on DDR_DLL_LOCK bit in CORE_DLL_STATUS to be set */ |
| 792 | ret = readl_poll_timeout(host->ioaddr + CORE_DLL_STATUS, |
| 793 | dll_status, (dll_status & CORE_DDR_DLL_LOCK), 10, 1000); |
| 794 | |
| 795 | if (ret == -ETIMEDOUT) { |
| 796 | pr_err("%s: %s: CM_DLL_SDC4 Calibration was not completed\n", |
| 797 | mmc_hostname(host->mmc), __func__); |
| 798 | goto out; |
| 799 | } |
| 800 | |
Ritesh Harjani | 764065e | 2015-05-13 14:14:45 +0530 | [diff] [blame] | 801 | /* |
| 802 | * set CORE_PWRSAVE_DLL bit in CORE_VENDOR_SPEC3. |
| 803 | * when MCLK is gated OFF, it is not gated for less than 0.5us |
| 804 | * and MCLK must be switched on for at-least 1us before DATA |
| 805 | * starts coming. Controllers with 14lpp tech DLL cannot |
| 806 | * guarantee above requirement. So PWRSAVE_DLL should not be |
| 807 | * turned on for host controllers using this DLL. |
| 808 | */ |
| 809 | if (!msm_host->use_14lpp_dll) |
| 810 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_VENDOR_SPEC3) |
| 811 | | CORE_PWRSAVE_DLL), |
| 812 | host->ioaddr + CORE_VENDOR_SPEC3); |
Krishna Konda | 2faa7bb | 2014-06-04 01:25:16 -0700 | [diff] [blame] | 813 | mb(); |
| 814 | out: |
| 815 | pr_debug("%s: Exit %s, ret:%d\n", mmc_hostname(host->mmc), |
| 816 | __func__, ret); |
| 817 | return ret; |
| 818 | } |
| 819 | |
Ritesh Harjani | ea70966 | 2015-05-27 15:40:24 +0530 | [diff] [blame] | 820 | static int sdhci_msm_enhanced_strobe(struct sdhci_host *host) |
| 821 | { |
| 822 | int ret = 0; |
| 823 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 824 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
| 825 | struct mmc_host *mmc = host->mmc; |
| 826 | |
| 827 | pr_debug("%s: Enter %s\n", mmc_hostname(host->mmc), __func__); |
| 828 | |
| 829 | if (!msm_host->enhanced_strobe) { |
| 830 | pr_debug("%s: host does not support hs400 enhanced strobe\n", |
| 831 | mmc_hostname(mmc)); |
| 832 | return -EINVAL; |
| 833 | } |
| 834 | |
| 835 | if (msm_host->calibration_done || |
| 836 | !(mmc->ios.timing == MMC_TIMING_MMC_HS400)) { |
| 837 | return 0; |
| 838 | } |
| 839 | |
| 840 | /* |
| 841 | * Reset the tuning block. |
| 842 | */ |
| 843 | ret = msm_init_cm_dll(host); |
| 844 | if (ret) |
| 845 | goto out; |
| 846 | |
| 847 | ret = sdhci_msm_cm_dll_sdc4_calibration(host); |
| 848 | out: |
| 849 | if (!ret) |
| 850 | msm_host->calibration_done = true; |
| 851 | pr_debug("%s: Exit %s, ret:%d\n", mmc_hostname(host->mmc), |
| 852 | __func__, ret); |
| 853 | return ret; |
| 854 | } |
| 855 | |
Krishna Konda | 2faa7bb | 2014-06-04 01:25:16 -0700 | [diff] [blame] | 856 | static int sdhci_msm_hs400_dll_calibration(struct sdhci_host *host) |
| 857 | { |
| 858 | int ret = 0; |
| 859 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 860 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
| 861 | |
| 862 | pr_debug("%s: Enter %s\n", mmc_hostname(host->mmc), __func__); |
| 863 | |
| 864 | /* |
| 865 | * Retuning in HS400 (DDR mode) will fail, just reset the |
| 866 | * tuning block and restore the saved tuning phase. |
| 867 | */ |
| 868 | ret = msm_init_cm_dll(host); |
| 869 | if (ret) |
| 870 | goto out; |
| 871 | |
| 872 | /* Set the selected phase in delay line hw block */ |
| 873 | ret = msm_config_cm_dll_phase(host, msm_host->saved_tuning_phase); |
| 874 | if (ret) |
| 875 | goto out; |
| 876 | |
Krishna Konda | 0e8efba | 2014-06-23 14:50:38 -0700 | [diff] [blame] | 877 | /* Write 1 to CMD_DAT_TRACK_SEL field in DLL_CONFIG */ |
| 878 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG) |
| 879 | | CORE_CMD_DAT_TRACK_SEL), |
| 880 | host->ioaddr + CORE_DLL_CONFIG); |
| 881 | |
Krishna Konda | 2faa7bb | 2014-06-04 01:25:16 -0700 | [diff] [blame] | 882 | if (msm_host->use_cdclp533) |
| 883 | /* Calibrate CDCLP533 DLL HW */ |
| 884 | ret = sdhci_msm_cdclp533_calibration(host); |
| 885 | else |
| 886 | /* Calibrate CM_DLL_SDC4 HW */ |
| 887 | ret = sdhci_msm_cm_dll_sdc4_calibration(host); |
| 888 | out: |
| 889 | pr_debug("%s: Exit %s, ret:%d\n", mmc_hostname(host->mmc), |
| 890 | __func__, ret); |
| 891 | return ret; |
| 892 | } |
| 893 | |
Krishna Konda | 96e6b11 | 2013-10-28 15:25:03 -0700 | [diff] [blame] | 894 | static void sdhci_msm_set_mmc_drv_type(struct sdhci_host *host, u32 opcode, |
| 895 | u8 drv_type) |
| 896 | { |
| 897 | struct mmc_command cmd = {0}; |
| 898 | struct mmc_request mrq = {NULL}; |
| 899 | struct mmc_host *mmc = host->mmc; |
| 900 | u8 val = ((drv_type << 4) | 2); |
| 901 | |
| 902 | cmd.opcode = MMC_SWITCH; |
| 903 | cmd.arg = (MMC_SWITCH_MODE_WRITE_BYTE << 24) | |
| 904 | (EXT_CSD_HS_TIMING << 16) | |
| 905 | (val << 8) | |
| 906 | EXT_CSD_CMD_SET_NORMAL; |
| 907 | cmd.flags = MMC_CMD_AC | MMC_RSP_R1B; |
| 908 | /* 1 sec */ |
| 909 | cmd.busy_timeout = 1000 * 1000; |
| 910 | |
| 911 | memset(cmd.resp, 0, sizeof(cmd.resp)); |
| 912 | cmd.retries = 3; |
| 913 | |
| 914 | mrq.cmd = &cmd; |
| 915 | cmd.data = NULL; |
| 916 | |
| 917 | mmc_wait_for_req(mmc, &mrq); |
| 918 | pr_debug("%s: %s: set card drive type to %d\n", |
| 919 | mmc_hostname(mmc), __func__, |
| 920 | drv_type); |
| 921 | } |
| 922 | |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 923 | int sdhci_msm_execute_tuning(struct sdhci_host *host, u32 opcode) |
| 924 | { |
| 925 | unsigned long flags; |
Sahitya Tummala | 9fe1653 | 2013-06-13 10:36:57 +0530 | [diff] [blame] | 926 | int tuning_seq_cnt = 3; |
Krishna Konda | 96e6b11 | 2013-10-28 15:25:03 -0700 | [diff] [blame] | 927 | u8 phase, *data_buf, tuned_phases[NUM_TUNING_PHASES], tuned_phase_cnt; |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 928 | const u32 *tuning_block_pattern = tuning_block_64; |
| 929 | int size = sizeof(tuning_block_64); /* Tuning pattern size in bytes */ |
| 930 | int rc; |
| 931 | struct mmc_host *mmc = host->mmc; |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 932 | struct mmc_ios ios = host->mmc->ios; |
Venkat Gopalakrishnan | 9e06963 | 2013-06-12 11:16:37 -0700 | [diff] [blame] | 933 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 934 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
Krishna Konda | 96e6b11 | 2013-10-28 15:25:03 -0700 | [diff] [blame] | 935 | u8 drv_type = 0; |
| 936 | bool drv_type_changed = false; |
| 937 | struct mmc_card *card = host->mmc->card; |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 938 | |
| 939 | /* |
Venkat Gopalakrishnan | 7f69157 | 2013-06-23 17:36:46 -0700 | [diff] [blame] | 940 | * Tuning is required for SDR104, HS200 and HS400 cards and |
| 941 | * if clock frequency is greater than 100MHz in these modes. |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 942 | */ |
Venkat Gopalakrishnan | 7f69157 | 2013-06-23 17:36:46 -0700 | [diff] [blame] | 943 | if (host->clock <= CORE_FREQ_100MHZ || |
| 944 | !((ios.timing == MMC_TIMING_MMC_HS400) || |
| 945 | (ios.timing == MMC_TIMING_MMC_HS200) || |
| 946 | (ios.timing == MMC_TIMING_UHS_SDR104))) |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 947 | return 0; |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 948 | |
| 949 | pr_debug("%s: Enter %s\n", mmc_hostname(mmc), __func__); |
Venkat Gopalakrishnan | 9e06963 | 2013-06-12 11:16:37 -0700 | [diff] [blame] | 950 | |
Krishna Konda | 2faa7bb | 2014-06-04 01:25:16 -0700 | [diff] [blame] | 951 | /* CDC/SDC4 DLL HW calibration is only required for HS400 mode*/ |
Venkat Gopalakrishnan | 9e06963 | 2013-06-12 11:16:37 -0700 | [diff] [blame] | 952 | if (msm_host->tuning_done && !msm_host->calibration_done && |
| 953 | (mmc->ios.timing == MMC_TIMING_MMC_HS400)) { |
Krishna Konda | 2faa7bb | 2014-06-04 01:25:16 -0700 | [diff] [blame] | 954 | rc = sdhci_msm_hs400_dll_calibration(host); |
Venkat Gopalakrishnan | 9e06963 | 2013-06-12 11:16:37 -0700 | [diff] [blame] | 955 | spin_lock_irqsave(&host->lock, flags); |
| 956 | if (!rc) |
| 957 | msm_host->calibration_done = true; |
| 958 | spin_unlock_irqrestore(&host->lock, flags); |
| 959 | goto out; |
| 960 | } |
| 961 | |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 962 | spin_lock_irqsave(&host->lock, flags); |
| 963 | |
| 964 | if ((opcode == MMC_SEND_TUNING_BLOCK_HS200) && |
| 965 | (mmc->ios.bus_width == MMC_BUS_WIDTH_8)) { |
| 966 | tuning_block_pattern = tuning_block_128; |
| 967 | size = sizeof(tuning_block_128); |
| 968 | } |
| 969 | spin_unlock_irqrestore(&host->lock, flags); |
| 970 | |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 971 | data_buf = kmalloc(size, GFP_KERNEL); |
| 972 | if (!data_buf) { |
| 973 | rc = -ENOMEM; |
| 974 | goto out; |
| 975 | } |
| 976 | |
Sahitya Tummala | 9fe1653 | 2013-06-13 10:36:57 +0530 | [diff] [blame] | 977 | retry: |
Krishna Konda | 96e6b11 | 2013-10-28 15:25:03 -0700 | [diff] [blame] | 978 | tuned_phase_cnt = 0; |
| 979 | |
Sahitya Tummala | 9fe1653 | 2013-06-13 10:36:57 +0530 | [diff] [blame] | 980 | /* first of all reset the tuning block */ |
| 981 | rc = msm_init_cm_dll(host); |
| 982 | if (rc) |
| 983 | goto kfree; |
| 984 | |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 985 | phase = 0; |
| 986 | do { |
| 987 | struct mmc_command cmd = {0}; |
| 988 | struct mmc_data data = {0}; |
| 989 | struct mmc_request mrq = { |
| 990 | .cmd = &cmd, |
| 991 | .data = &data |
| 992 | }; |
| 993 | struct scatterlist sg; |
| 994 | |
| 995 | /* set the phase in delay line hw block */ |
| 996 | rc = msm_config_cm_dll_phase(host, phase); |
| 997 | if (rc) |
| 998 | goto kfree; |
| 999 | |
| 1000 | cmd.opcode = opcode; |
| 1001 | cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; |
| 1002 | |
| 1003 | data.blksz = size; |
| 1004 | data.blocks = 1; |
| 1005 | data.flags = MMC_DATA_READ; |
| 1006 | data.timeout_ns = 1000 * 1000 * 1000; /* 1 sec */ |
| 1007 | |
| 1008 | data.sg = &sg; |
| 1009 | data.sg_len = 1; |
| 1010 | sg_init_one(&sg, data_buf, size); |
| 1011 | memset(data_buf, 0, size); |
| 1012 | mmc_wait_for_req(mmc, &mrq); |
| 1013 | |
| 1014 | if (!cmd.error && !data.error && |
| 1015 | !memcmp(data_buf, tuning_block_pattern, size)) { |
| 1016 | /* tuning is successful at this tuning point */ |
| 1017 | tuned_phases[tuned_phase_cnt++] = phase; |
Krishna Konda | 96e6b11 | 2013-10-28 15:25:03 -0700 | [diff] [blame] | 1018 | pr_debug("%s: %s: found *** good *** phase = %d\n", |
| 1019 | mmc_hostname(mmc), __func__, phase); |
| 1020 | } else { |
| 1021 | pr_debug("%s: %s: found ## bad ## phase = %d\n", |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 1022 | mmc_hostname(mmc), __func__, phase); |
| 1023 | } |
| 1024 | } while (++phase < 16); |
| 1025 | |
Sahitya Tummala | dfdb4af | 2014-04-01 14:29:13 +0530 | [diff] [blame] | 1026 | if ((tuned_phase_cnt == NUM_TUNING_PHASES) && |
| 1027 | card && mmc_card_mmc(card)) { |
Krishna Konda | 96e6b11 | 2013-10-28 15:25:03 -0700 | [diff] [blame] | 1028 | /* |
| 1029 | * If all phases pass then its a problem. So change the card's |
| 1030 | * drive type to a different value, if supported and repeat |
| 1031 | * tuning until at least one phase fails. Then set the original |
| 1032 | * drive type back. |
| 1033 | * |
| 1034 | * If all the phases still pass after trying all possible |
| 1035 | * drive types, then one of those 16 phases will be picked. |
| 1036 | * This is no different from what was going on before the |
| 1037 | * modification to change drive type and retune. |
| 1038 | */ |
| 1039 | pr_debug("%s: tuned phases count: %d\n", mmc_hostname(mmc), |
| 1040 | tuned_phase_cnt); |
| 1041 | |
| 1042 | /* set drive type to other value . default setting is 0x0 */ |
| 1043 | while (++drv_type <= MAX_DRV_TYPES_SUPPORTED_HS200) { |
| 1044 | if (card->ext_csd.raw_driver_strength & |
| 1045 | (1 << drv_type)) { |
| 1046 | sdhci_msm_set_mmc_drv_type(host, opcode, |
| 1047 | drv_type); |
| 1048 | if (!drv_type_changed) |
| 1049 | drv_type_changed = true; |
| 1050 | goto retry; |
| 1051 | } |
| 1052 | } |
| 1053 | } |
| 1054 | |
| 1055 | /* reset drive type to default (50 ohm) if changed */ |
| 1056 | if (drv_type_changed) |
| 1057 | sdhci_msm_set_mmc_drv_type(host, opcode, 0); |
| 1058 | |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 1059 | if (tuned_phase_cnt) { |
| 1060 | rc = msm_find_most_appropriate_phase(host, tuned_phases, |
| 1061 | tuned_phase_cnt); |
| 1062 | if (rc < 0) |
| 1063 | goto kfree; |
| 1064 | else |
| 1065 | phase = (u8)rc; |
| 1066 | |
| 1067 | /* |
| 1068 | * Finally set the selected phase in delay |
| 1069 | * line hw block. |
| 1070 | */ |
| 1071 | rc = msm_config_cm_dll_phase(host, phase); |
| 1072 | if (rc) |
| 1073 | goto kfree; |
Venkat Gopalakrishnan | 9e06963 | 2013-06-12 11:16:37 -0700 | [diff] [blame] | 1074 | msm_host->saved_tuning_phase = phase; |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 1075 | pr_debug("%s: %s: finally setting the tuning phase to %d\n", |
| 1076 | mmc_hostname(mmc), __func__, phase); |
| 1077 | } else { |
Sahitya Tummala | 9fe1653 | 2013-06-13 10:36:57 +0530 | [diff] [blame] | 1078 | if (--tuning_seq_cnt) |
| 1079 | goto retry; |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 1080 | /* tuning failed */ |
| 1081 | pr_err("%s: %s: no tuning point found\n", |
| 1082 | mmc_hostname(mmc), __func__); |
Sahitya Tummala | 9fe1653 | 2013-06-13 10:36:57 +0530 | [diff] [blame] | 1083 | rc = -EIO; |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 1084 | } |
| 1085 | |
| 1086 | kfree: |
| 1087 | kfree(data_buf); |
| 1088 | out: |
Venkat Gopalakrishnan | 9e06963 | 2013-06-12 11:16:37 -0700 | [diff] [blame] | 1089 | spin_lock_irqsave(&host->lock, flags); |
| 1090 | if (!rc) |
| 1091 | msm_host->tuning_done = true; |
| 1092 | spin_unlock_irqrestore(&host->lock, flags); |
| 1093 | pr_debug("%s: Exit %s, err(%d)\n", mmc_hostname(mmc), __func__, rc); |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 1094 | return rc; |
| 1095 | } |
| 1096 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1097 | static int sdhci_msm_setup_gpio(struct sdhci_msm_pltfm_data *pdata, bool enable) |
| 1098 | { |
| 1099 | struct sdhci_msm_gpio_data *curr; |
| 1100 | int i, ret = 0; |
| 1101 | |
| 1102 | curr = pdata->pin_data->gpio_data; |
| 1103 | for (i = 0; i < curr->size; i++) { |
| 1104 | if (!gpio_is_valid(curr->gpio[i].no)) { |
| 1105 | ret = -EINVAL; |
| 1106 | pr_err("%s: Invalid gpio = %d\n", __func__, |
| 1107 | curr->gpio[i].no); |
| 1108 | goto free_gpios; |
| 1109 | } |
| 1110 | if (enable) { |
| 1111 | ret = gpio_request(curr->gpio[i].no, |
| 1112 | curr->gpio[i].name); |
| 1113 | if (ret) { |
| 1114 | pr_err("%s: gpio_request(%d, %s) failed %d\n", |
| 1115 | __func__, curr->gpio[i].no, |
| 1116 | curr->gpio[i].name, ret); |
| 1117 | goto free_gpios; |
| 1118 | } |
| 1119 | curr->gpio[i].is_enabled = true; |
| 1120 | } else { |
| 1121 | gpio_free(curr->gpio[i].no); |
| 1122 | curr->gpio[i].is_enabled = false; |
| 1123 | } |
| 1124 | } |
| 1125 | return ret; |
| 1126 | |
| 1127 | free_gpios: |
| 1128 | for (i--; i >= 0; i--) { |
| 1129 | gpio_free(curr->gpio[i].no); |
| 1130 | curr->gpio[i].is_enabled = false; |
| 1131 | } |
| 1132 | return ret; |
| 1133 | } |
| 1134 | |
Pratibhasagar V | 9acf264 | 2013-11-21 21:07:21 +0530 | [diff] [blame] | 1135 | static int sdhci_msm_setup_pinctrl(struct sdhci_msm_pltfm_data *pdata, |
| 1136 | bool enable) |
| 1137 | { |
| 1138 | int ret = 0; |
| 1139 | |
| 1140 | if (enable) |
| 1141 | ret = pinctrl_select_state(pdata->pctrl_data->pctrl, |
| 1142 | pdata->pctrl_data->pins_active); |
| 1143 | else |
| 1144 | ret = pinctrl_select_state(pdata->pctrl_data->pctrl, |
| 1145 | pdata->pctrl_data->pins_sleep); |
| 1146 | |
| 1147 | if (ret < 0) |
| 1148 | pr_err("%s state for pinctrl failed with %d\n", |
| 1149 | enable ? "Enabling" : "Disabling", ret); |
| 1150 | |
| 1151 | return ret; |
| 1152 | } |
| 1153 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1154 | static int sdhci_msm_setup_pins(struct sdhci_msm_pltfm_data *pdata, bool enable) |
| 1155 | { |
| 1156 | int ret = 0; |
| 1157 | |
Pratibhasagar V | 9acf264 | 2013-11-21 21:07:21 +0530 | [diff] [blame] | 1158 | if (pdata->pin_cfg_sts == enable) { |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1159 | return 0; |
Pratibhasagar V | 9acf264 | 2013-11-21 21:07:21 +0530 | [diff] [blame] | 1160 | } else if (pdata->pctrl_data) { |
| 1161 | ret = sdhci_msm_setup_pinctrl(pdata, enable); |
| 1162 | goto out; |
| 1163 | } else if (!pdata->pin_data) { |
| 1164 | return 0; |
| 1165 | } |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1166 | |
Sahitya Tummala | 1cd7e07 | 2014-02-14 13:19:01 +0530 | [diff] [blame] | 1167 | if (pdata->pin_data->is_gpio) |
| 1168 | ret = sdhci_msm_setup_gpio(pdata, enable); |
Pratibhasagar V | 9acf264 | 2013-11-21 21:07:21 +0530 | [diff] [blame] | 1169 | out: |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1170 | if (!ret) |
Pratibhasagar V | 9acf264 | 2013-11-21 21:07:21 +0530 | [diff] [blame] | 1171 | pdata->pin_cfg_sts = enable; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1172 | |
| 1173 | return ret; |
| 1174 | } |
| 1175 | |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 1176 | static int sdhci_msm_dt_get_array(struct device *dev, const char *prop_name, |
| 1177 | u32 **out, int *len, u32 size) |
| 1178 | { |
| 1179 | int ret = 0; |
| 1180 | struct device_node *np = dev->of_node; |
| 1181 | size_t sz; |
| 1182 | u32 *arr = NULL; |
| 1183 | |
| 1184 | if (!of_get_property(np, prop_name, len)) { |
| 1185 | ret = -EINVAL; |
| 1186 | goto out; |
| 1187 | } |
| 1188 | sz = *len = *len / sizeof(*arr); |
Venkat Gopalakrishnan | 7f69157 | 2013-06-23 17:36:46 -0700 | [diff] [blame] | 1189 | if (sz <= 0 || (size > 0 && (sz > size))) { |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 1190 | dev_err(dev, "%s invalid size\n", prop_name); |
| 1191 | ret = -EINVAL; |
| 1192 | goto out; |
| 1193 | } |
| 1194 | |
| 1195 | arr = devm_kzalloc(dev, sz * sizeof(*arr), GFP_KERNEL); |
| 1196 | if (!arr) { |
| 1197 | dev_err(dev, "%s failed allocating memory\n", prop_name); |
| 1198 | ret = -ENOMEM; |
| 1199 | goto out; |
| 1200 | } |
| 1201 | |
| 1202 | ret = of_property_read_u32_array(np, prop_name, arr, sz); |
| 1203 | if (ret < 0) { |
| 1204 | dev_err(dev, "%s failed reading array %d\n", prop_name, ret); |
| 1205 | goto out; |
| 1206 | } |
| 1207 | *out = arr; |
| 1208 | out: |
| 1209 | if (ret) |
| 1210 | *len = 0; |
| 1211 | return ret; |
| 1212 | } |
| 1213 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1214 | #define MAX_PROP_SIZE 32 |
| 1215 | static int sdhci_msm_dt_parse_vreg_info(struct device *dev, |
| 1216 | struct sdhci_msm_reg_data **vreg_data, const char *vreg_name) |
| 1217 | { |
| 1218 | int len, ret = 0; |
| 1219 | const __be32 *prop; |
| 1220 | char prop_name[MAX_PROP_SIZE]; |
| 1221 | struct sdhci_msm_reg_data *vreg; |
| 1222 | struct device_node *np = dev->of_node; |
| 1223 | |
| 1224 | snprintf(prop_name, MAX_PROP_SIZE, "%s-supply", vreg_name); |
| 1225 | if (!of_parse_phandle(np, prop_name, 0)) { |
Asutosh Das | c58cc7a | 2013-06-28 15:03:44 +0530 | [diff] [blame] | 1226 | dev_info(dev, "No vreg data found for %s\n", vreg_name); |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1227 | return ret; |
| 1228 | } |
| 1229 | |
| 1230 | vreg = devm_kzalloc(dev, sizeof(*vreg), GFP_KERNEL); |
| 1231 | if (!vreg) { |
| 1232 | dev_err(dev, "No memory for vreg: %s\n", vreg_name); |
| 1233 | ret = -ENOMEM; |
| 1234 | return ret; |
| 1235 | } |
| 1236 | |
| 1237 | vreg->name = vreg_name; |
| 1238 | |
| 1239 | snprintf(prop_name, MAX_PROP_SIZE, |
| 1240 | "qcom,%s-always-on", vreg_name); |
| 1241 | if (of_get_property(np, prop_name, NULL)) |
| 1242 | vreg->is_always_on = true; |
| 1243 | |
| 1244 | snprintf(prop_name, MAX_PROP_SIZE, |
| 1245 | "qcom,%s-lpm-sup", vreg_name); |
| 1246 | if (of_get_property(np, prop_name, NULL)) |
| 1247 | vreg->lpm_sup = true; |
| 1248 | |
| 1249 | snprintf(prop_name, MAX_PROP_SIZE, |
| 1250 | "qcom,%s-voltage-level", vreg_name); |
| 1251 | prop = of_get_property(np, prop_name, &len); |
| 1252 | if (!prop || (len != (2 * sizeof(__be32)))) { |
| 1253 | dev_warn(dev, "%s %s property\n", |
| 1254 | prop ? "invalid format" : "no", prop_name); |
| 1255 | } else { |
| 1256 | vreg->low_vol_level = be32_to_cpup(&prop[0]); |
| 1257 | vreg->high_vol_level = be32_to_cpup(&prop[1]); |
| 1258 | } |
| 1259 | |
| 1260 | snprintf(prop_name, MAX_PROP_SIZE, |
| 1261 | "qcom,%s-current-level", vreg_name); |
| 1262 | prop = of_get_property(np, prop_name, &len); |
| 1263 | if (!prop || (len != (2 * sizeof(__be32)))) { |
| 1264 | dev_warn(dev, "%s %s property\n", |
| 1265 | prop ? "invalid format" : "no", prop_name); |
| 1266 | } else { |
| 1267 | vreg->lpm_uA = be32_to_cpup(&prop[0]); |
| 1268 | vreg->hpm_uA = be32_to_cpup(&prop[1]); |
| 1269 | } |
| 1270 | |
| 1271 | *vreg_data = vreg; |
| 1272 | dev_dbg(dev, "%s: %s %s vol=[%d %d]uV, curr=[%d %d]uA\n", |
| 1273 | vreg->name, vreg->is_always_on ? "always_on," : "", |
| 1274 | vreg->lpm_sup ? "lpm_sup," : "", vreg->low_vol_level, |
| 1275 | vreg->high_vol_level, vreg->lpm_uA, vreg->hpm_uA); |
| 1276 | |
| 1277 | return ret; |
| 1278 | } |
| 1279 | |
Pratibhasagar V | 9acf264 | 2013-11-21 21:07:21 +0530 | [diff] [blame] | 1280 | static int sdhci_msm_parse_pinctrl_info(struct device *dev, |
| 1281 | struct sdhci_msm_pltfm_data *pdata) |
| 1282 | { |
| 1283 | struct sdhci_pinctrl_data *pctrl_data; |
| 1284 | struct pinctrl *pctrl; |
| 1285 | int ret = 0; |
| 1286 | |
| 1287 | /* Try to obtain pinctrl handle */ |
| 1288 | pctrl = devm_pinctrl_get(dev); |
| 1289 | if (IS_ERR(pctrl)) { |
| 1290 | ret = PTR_ERR(pctrl); |
| 1291 | goto out; |
| 1292 | } |
| 1293 | pctrl_data = devm_kzalloc(dev, sizeof(*pctrl_data), GFP_KERNEL); |
| 1294 | if (!pctrl_data) { |
| 1295 | dev_err(dev, "No memory for sdhci_pinctrl_data\n"); |
| 1296 | ret = -ENOMEM; |
| 1297 | goto out; |
| 1298 | } |
| 1299 | pctrl_data->pctrl = pctrl; |
| 1300 | /* Look-up and keep the states handy to be used later */ |
| 1301 | pctrl_data->pins_active = pinctrl_lookup_state( |
| 1302 | pctrl_data->pctrl, "active"); |
| 1303 | if (IS_ERR(pctrl_data->pins_active)) { |
| 1304 | ret = PTR_ERR(pctrl_data->pins_active); |
| 1305 | dev_err(dev, "Could not get active pinstates, err:%d\n", ret); |
| 1306 | goto out; |
| 1307 | } |
| 1308 | pctrl_data->pins_sleep = pinctrl_lookup_state( |
| 1309 | pctrl_data->pctrl, "sleep"); |
| 1310 | if (IS_ERR(pctrl_data->pins_sleep)) { |
| 1311 | ret = PTR_ERR(pctrl_data->pins_sleep); |
| 1312 | dev_err(dev, "Could not get sleep pinstates, err:%d\n", ret); |
| 1313 | goto out; |
| 1314 | } |
| 1315 | pdata->pctrl_data = pctrl_data; |
| 1316 | out: |
| 1317 | return ret; |
| 1318 | } |
| 1319 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1320 | #define GPIO_NAME_MAX_LEN 32 |
| 1321 | static int sdhci_msm_dt_parse_gpio_info(struct device *dev, |
| 1322 | struct sdhci_msm_pltfm_data *pdata) |
| 1323 | { |
| 1324 | int ret = 0, cnt, i; |
| 1325 | struct sdhci_msm_pin_data *pin_data; |
| 1326 | struct device_node *np = dev->of_node; |
| 1327 | |
Pratibhasagar V | 9acf264 | 2013-11-21 21:07:21 +0530 | [diff] [blame] | 1328 | ret = sdhci_msm_parse_pinctrl_info(dev, pdata); |
| 1329 | if (!ret) { |
| 1330 | goto out; |
| 1331 | } else if (ret == -EPROBE_DEFER) { |
| 1332 | dev_err(dev, "Pinctrl framework not registered, err:%d\n", ret); |
| 1333 | goto out; |
| 1334 | } else { |
| 1335 | dev_err(dev, "Parsing Pinctrl failed with %d, falling back on GPIO lib\n", |
| 1336 | ret); |
Sahitya Tummala | 1cd7e07 | 2014-02-14 13:19:01 +0530 | [diff] [blame] | 1337 | ret = 0; |
Pratibhasagar V | 9acf264 | 2013-11-21 21:07:21 +0530 | [diff] [blame] | 1338 | } |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1339 | pin_data = devm_kzalloc(dev, sizeof(*pin_data), GFP_KERNEL); |
| 1340 | if (!pin_data) { |
| 1341 | dev_err(dev, "No memory for pin_data\n"); |
| 1342 | ret = -ENOMEM; |
| 1343 | goto out; |
| 1344 | } |
| 1345 | |
| 1346 | cnt = of_gpio_count(np); |
| 1347 | if (cnt > 0) { |
| 1348 | pin_data->gpio_data = devm_kzalloc(dev, |
| 1349 | sizeof(struct sdhci_msm_gpio_data), GFP_KERNEL); |
| 1350 | if (!pin_data->gpio_data) { |
| 1351 | dev_err(dev, "No memory for gpio_data\n"); |
| 1352 | ret = -ENOMEM; |
| 1353 | goto out; |
| 1354 | } |
| 1355 | pin_data->gpio_data->size = cnt; |
| 1356 | pin_data->gpio_data->gpio = devm_kzalloc(dev, cnt * |
| 1357 | sizeof(struct sdhci_msm_gpio), GFP_KERNEL); |
| 1358 | |
| 1359 | if (!pin_data->gpio_data->gpio) { |
| 1360 | dev_err(dev, "No memory for gpio\n"); |
| 1361 | ret = -ENOMEM; |
| 1362 | goto out; |
| 1363 | } |
| 1364 | |
| 1365 | for (i = 0; i < cnt; i++) { |
| 1366 | const char *name = NULL; |
| 1367 | char result[GPIO_NAME_MAX_LEN]; |
| 1368 | pin_data->gpio_data->gpio[i].no = of_get_gpio(np, i); |
| 1369 | of_property_read_string_index(np, |
| 1370 | "qcom,gpio-names", i, &name); |
| 1371 | |
| 1372 | snprintf(result, GPIO_NAME_MAX_LEN, "%s-%s", |
| 1373 | dev_name(dev), name ? name : "?"); |
| 1374 | pin_data->gpio_data->gpio[i].name = result; |
| 1375 | dev_dbg(dev, "%s: gpio[%s] = %d\n", __func__, |
| 1376 | pin_data->gpio_data->gpio[i].name, |
| 1377 | pin_data->gpio_data->gpio[i].no); |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1378 | } |
| 1379 | } |
Sahitya Tummala | 1cd7e07 | 2014-02-14 13:19:01 +0530 | [diff] [blame] | 1380 | pdata->pin_data = pin_data; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1381 | out: |
| 1382 | if (ret) |
| 1383 | dev_err(dev, "%s failed with err %d\n", __func__, ret); |
| 1384 | return ret; |
| 1385 | } |
| 1386 | |
Maya Erez | 994cf2f | 2014-10-21 20:22:04 +0300 | [diff] [blame] | 1387 | #ifdef CONFIG_SMP |
| 1388 | static void sdhci_msm_populate_affinity_type(struct sdhci_msm_pltfm_data *pdata, |
| 1389 | struct device_node *np) |
| 1390 | { |
| 1391 | const char *cpu_affinity = NULL; |
| 1392 | |
| 1393 | pdata->cpu_affinity_type = PM_QOS_REQ_AFFINE_IRQ; |
| 1394 | if (!of_property_read_string(np, "qcom,cpu-affinity", |
| 1395 | &cpu_affinity)) { |
| 1396 | if (!strcmp(cpu_affinity, "all_cores")) |
| 1397 | pdata->cpu_affinity_type = PM_QOS_REQ_ALL_CORES; |
| 1398 | else if (!strcmp(cpu_affinity, "affine_cores")) |
| 1399 | pdata->cpu_affinity_type = PM_QOS_REQ_AFFINE_CORES; |
| 1400 | else if (!strcmp(cpu_affinity, "affine_irq")) |
| 1401 | pdata->cpu_affinity_type = PM_QOS_REQ_AFFINE_IRQ; |
| 1402 | } |
| 1403 | } |
| 1404 | #else |
| 1405 | static void sdhci_msm_populate_affinity_type(struct sdhci_msm_pltfm_data *pdata, |
| 1406 | struct device_node *np) |
| 1407 | { |
| 1408 | } |
| 1409 | #endif |
| 1410 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1411 | /* Parse platform data */ |
Dov Levenglick | c9033ab | 2015-03-10 16:00:56 +0200 | [diff] [blame] | 1412 | static |
| 1413 | struct sdhci_msm_pltfm_data *sdhci_msm_populate_pdata(struct device *dev, |
| 1414 | struct sdhci_msm_host *msm_host) |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1415 | { |
| 1416 | struct sdhci_msm_pltfm_data *pdata = NULL; |
| 1417 | struct device_node *np = dev->of_node; |
| 1418 | u32 bus_width = 0; |
Sahitya Tummala | c6f48d4 | 2013-03-10 07:03:17 +0530 | [diff] [blame] | 1419 | u32 cpu_dma_latency; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1420 | int len, i; |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 1421 | int clk_table_len; |
| 1422 | u32 *clk_table = NULL; |
Sujit Reddy Thumma | 1958d3d | 2013-06-03 09:54:32 +0530 | [diff] [blame] | 1423 | enum of_gpio_flags flags = OF_GPIO_ACTIVE_LOW; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1424 | |
| 1425 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); |
| 1426 | if (!pdata) { |
| 1427 | dev_err(dev, "failed to allocate memory for platform data\n"); |
| 1428 | goto out; |
| 1429 | } |
| 1430 | |
Sujit Reddy Thumma | 1958d3d | 2013-06-03 09:54:32 +0530 | [diff] [blame] | 1431 | pdata->status_gpio = of_get_named_gpio_flags(np, "cd-gpios", 0, &flags); |
| 1432 | if (gpio_is_valid(pdata->status_gpio) & !(flags & OF_GPIO_ACTIVE_LOW)) |
| 1433 | pdata->caps2 |= MMC_CAP2_CD_ACTIVE_HIGH; |
Sahitya Tummala | 581df13 | 2013-03-12 14:57:46 +0530 | [diff] [blame] | 1434 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1435 | of_property_read_u32(np, "qcom,bus-width", &bus_width); |
| 1436 | if (bus_width == 8) |
| 1437 | pdata->mmc_bus_width = MMC_CAP_8_BIT_DATA; |
| 1438 | else if (bus_width == 4) |
| 1439 | pdata->mmc_bus_width = MMC_CAP_4_BIT_DATA; |
| 1440 | else { |
| 1441 | dev_notice(dev, "invalid bus-width, default to 1-bit mode\n"); |
| 1442 | pdata->mmc_bus_width = 0; |
| 1443 | } |
| 1444 | |
Sahitya Tummala | c6f48d4 | 2013-03-10 07:03:17 +0530 | [diff] [blame] | 1445 | if (!of_property_read_u32(np, "qcom,cpu-dma-latency-us", |
| 1446 | &cpu_dma_latency)) |
| 1447 | pdata->cpu_dma_latency_us = cpu_dma_latency; |
Asutosh Das | 598a4d4 | 2014-02-05 16:38:23 +0530 | [diff] [blame] | 1448 | else |
| 1449 | pdata->cpu_dma_latency_us = MSM_MMC_DEFAULT_CPU_DMA_LATENCY; |
Talel Shenhar | 7dc5f79 | 2015-05-18 12:12:48 +0300 | [diff] [blame] | 1450 | |
| 1451 | if (sdhci_msm_dt_get_array(dev, "qcom,devfreq,freq-table", |
| 1452 | &msm_host->mmc->clk_scaling.freq_table, |
| 1453 | &msm_host->mmc->clk_scaling.freq_table_sz, 0)) |
| 1454 | pr_debug("%s: no clock scaling frequencies were supplied\n", |
| 1455 | dev_name(dev)); |
| 1456 | else if (!msm_host->mmc->clk_scaling.freq_table || |
| 1457 | !msm_host->mmc->clk_scaling.freq_table_sz) |
| 1458 | dev_err(dev, "bad dts clock scaling frequencies\n"); |
| 1459 | |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 1460 | if (sdhci_msm_dt_get_array(dev, "qcom,clk-rates", |
| 1461 | &clk_table, &clk_table_len, 0)) { |
| 1462 | dev_err(dev, "failed parsing supported clock rates\n"); |
| 1463 | goto out; |
| 1464 | } |
| 1465 | if (!clk_table || !clk_table_len) { |
| 1466 | dev_err(dev, "Invalid clock table\n"); |
| 1467 | goto out; |
| 1468 | } |
| 1469 | pdata->sup_clk_table = clk_table; |
| 1470 | pdata->sup_clk_cnt = clk_table_len; |
| 1471 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1472 | pdata->vreg_data = devm_kzalloc(dev, sizeof(struct |
| 1473 | sdhci_msm_slot_reg_data), |
| 1474 | GFP_KERNEL); |
| 1475 | if (!pdata->vreg_data) { |
| 1476 | dev_err(dev, "failed to allocate memory for vreg data\n"); |
| 1477 | goto out; |
| 1478 | } |
| 1479 | |
| 1480 | if (sdhci_msm_dt_parse_vreg_info(dev, &pdata->vreg_data->vdd_data, |
| 1481 | "vdd")) { |
| 1482 | dev_err(dev, "failed parsing vdd data\n"); |
| 1483 | goto out; |
| 1484 | } |
| 1485 | if (sdhci_msm_dt_parse_vreg_info(dev, |
| 1486 | &pdata->vreg_data->vdd_io_data, |
| 1487 | "vdd-io")) { |
| 1488 | dev_err(dev, "failed parsing vdd-io data\n"); |
| 1489 | goto out; |
| 1490 | } |
| 1491 | |
| 1492 | if (sdhci_msm_dt_parse_gpio_info(dev, pdata)) { |
| 1493 | dev_err(dev, "failed parsing gpio data\n"); |
| 1494 | goto out; |
| 1495 | } |
| 1496 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1497 | len = of_property_count_strings(np, "qcom,bus-speed-mode"); |
| 1498 | |
| 1499 | for (i = 0; i < len; i++) { |
| 1500 | const char *name = NULL; |
| 1501 | |
| 1502 | of_property_read_string_index(np, |
| 1503 | "qcom,bus-speed-mode", i, &name); |
| 1504 | if (!name) |
| 1505 | continue; |
| 1506 | |
Venkat Gopalakrishnan | 7f69157 | 2013-06-23 17:36:46 -0700 | [diff] [blame] | 1507 | if (!strncmp(name, "HS400_1p8v", sizeof("HS400_1p8v"))) |
| 1508 | pdata->caps2 |= MMC_CAP2_HS400_1_8V; |
| 1509 | else if (!strncmp(name, "HS400_1p2v", sizeof("HS400_1p2v"))) |
| 1510 | pdata->caps2 |= MMC_CAP2_HS400_1_2V; |
| 1511 | else if (!strncmp(name, "HS200_1p8v", sizeof("HS200_1p8v"))) |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1512 | pdata->caps2 |= MMC_CAP2_HS200_1_8V_SDR; |
| 1513 | else if (!strncmp(name, "HS200_1p2v", sizeof("HS200_1p2v"))) |
| 1514 | pdata->caps2 |= MMC_CAP2_HS200_1_2V_SDR; |
| 1515 | else if (!strncmp(name, "DDR_1p8v", sizeof("DDR_1p8v"))) |
| 1516 | pdata->caps |= MMC_CAP_1_8V_DDR |
| 1517 | | MMC_CAP_UHS_DDR50; |
| 1518 | else if (!strncmp(name, "DDR_1p2v", sizeof("DDR_1p2v"))) |
| 1519 | pdata->caps |= MMC_CAP_1_2V_DDR |
| 1520 | | MMC_CAP_UHS_DDR50; |
| 1521 | } |
| 1522 | |
| 1523 | if (of_get_property(np, "qcom,nonremovable", NULL)) |
| 1524 | pdata->nonremovable = true; |
| 1525 | |
Guoping Yu | f7c9133 | 2014-08-20 16:56:18 +0800 | [diff] [blame] | 1526 | if (of_get_property(np, "qcom,nonhotplug", NULL)) |
| 1527 | pdata->nonhotplug = true; |
| 1528 | |
Venkat Gopalakrishnan | 9a62e04 | 2015-03-03 16:14:55 -0800 | [diff] [blame] | 1529 | pdata->largeaddressbus = |
| 1530 | of_property_read_bool(np, "qcom,large-address-bus"); |
| 1531 | |
Maya Erez | 994cf2f | 2014-10-21 20:22:04 +0300 | [diff] [blame] | 1532 | sdhci_msm_populate_affinity_type(pdata, np); |
| 1533 | |
Dov Levenglick | c9033ab | 2015-03-10 16:00:56 +0200 | [diff] [blame] | 1534 | if (of_property_read_bool(np, "qcom,wakeup-on-idle")) |
| 1535 | msm_host->mmc->wakeup_on_idle = true; |
| 1536 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1537 | return pdata; |
| 1538 | out: |
| 1539 | return NULL; |
| 1540 | } |
| 1541 | |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 1542 | /* Returns required bandwidth in Bytes per Sec */ |
| 1543 | static unsigned int sdhci_get_bw_required(struct sdhci_host *host, |
| 1544 | struct mmc_ios *ios) |
| 1545 | { |
Sahitya Tummala | 2886c92 | 2013-04-03 18:03:31 +0530 | [diff] [blame] | 1546 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 1547 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
| 1548 | |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 1549 | unsigned int bw; |
| 1550 | |
Sahitya Tummala | 2886c92 | 2013-04-03 18:03:31 +0530 | [diff] [blame] | 1551 | bw = msm_host->clk_rate; |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 1552 | /* |
| 1553 | * For DDR mode, SDCC controller clock will be at |
| 1554 | * the double rate than the actual clock that goes to card. |
| 1555 | */ |
| 1556 | if (ios->bus_width == MMC_BUS_WIDTH_4) |
| 1557 | bw /= 2; |
| 1558 | else if (ios->bus_width == MMC_BUS_WIDTH_1) |
| 1559 | bw /= 8; |
| 1560 | |
| 1561 | return bw; |
| 1562 | } |
| 1563 | |
| 1564 | static int sdhci_msm_bus_get_vote_for_bw(struct sdhci_msm_host *host, |
| 1565 | unsigned int bw) |
| 1566 | { |
| 1567 | unsigned int *table = host->pdata->voting_data->bw_vecs; |
| 1568 | unsigned int size = host->pdata->voting_data->bw_vecs_size; |
| 1569 | int i; |
| 1570 | |
| 1571 | if (host->msm_bus_vote.is_max_bw_needed && bw) |
| 1572 | return host->msm_bus_vote.max_bw_vote; |
| 1573 | |
| 1574 | for (i = 0; i < size; i++) { |
| 1575 | if (bw <= table[i]) |
| 1576 | break; |
| 1577 | } |
| 1578 | |
| 1579 | if (i && (i == size)) |
| 1580 | i--; |
| 1581 | |
| 1582 | return i; |
| 1583 | } |
| 1584 | |
| 1585 | /* |
| 1586 | * This function must be called with host lock acquired. |
| 1587 | * Caller of this function should also ensure that msm bus client |
| 1588 | * handle is not null. |
| 1589 | */ |
| 1590 | static inline int sdhci_msm_bus_set_vote(struct sdhci_msm_host *msm_host, |
| 1591 | int vote, |
Sujit Reddy Thumma | 024c058 | 2013-08-06 11:21:33 +0530 | [diff] [blame] | 1592 | unsigned long *flags) |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 1593 | { |
| 1594 | struct sdhci_host *host = platform_get_drvdata(msm_host->pdev); |
| 1595 | int rc = 0; |
| 1596 | |
Sujit Reddy Thumma | 024c058 | 2013-08-06 11:21:33 +0530 | [diff] [blame] | 1597 | BUG_ON(!flags); |
| 1598 | |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 1599 | if (vote != msm_host->msm_bus_vote.curr_vote) { |
Sujit Reddy Thumma | 024c058 | 2013-08-06 11:21:33 +0530 | [diff] [blame] | 1600 | spin_unlock_irqrestore(&host->lock, *flags); |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 1601 | rc = msm_bus_scale_client_update_request( |
| 1602 | msm_host->msm_bus_vote.client_handle, vote); |
Sujit Reddy Thumma | 024c058 | 2013-08-06 11:21:33 +0530 | [diff] [blame] | 1603 | spin_lock_irqsave(&host->lock, *flags); |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 1604 | if (rc) { |
| 1605 | pr_err("%s: msm_bus_scale_client_update_request() failed: bus_client_handle=0x%x, vote=%d, err=%d\n", |
| 1606 | mmc_hostname(host->mmc), |
| 1607 | msm_host->msm_bus_vote.client_handle, vote, rc); |
| 1608 | goto out; |
| 1609 | } |
| 1610 | msm_host->msm_bus_vote.curr_vote = vote; |
| 1611 | } |
| 1612 | out: |
| 1613 | return rc; |
| 1614 | } |
| 1615 | |
| 1616 | /* |
| 1617 | * Internal work. Work to set 0 bandwidth for msm bus. |
| 1618 | */ |
| 1619 | static void sdhci_msm_bus_work(struct work_struct *work) |
| 1620 | { |
| 1621 | struct sdhci_msm_host *msm_host; |
| 1622 | struct sdhci_host *host; |
| 1623 | unsigned long flags; |
| 1624 | |
| 1625 | msm_host = container_of(work, struct sdhci_msm_host, |
| 1626 | msm_bus_vote.vote_work.work); |
| 1627 | host = platform_get_drvdata(msm_host->pdev); |
| 1628 | |
| 1629 | if (!msm_host->msm_bus_vote.client_handle) |
| 1630 | return; |
| 1631 | |
| 1632 | spin_lock_irqsave(&host->lock, flags); |
| 1633 | /* don't vote for 0 bandwidth if any request is in progress */ |
| 1634 | if (!host->mrq) { |
| 1635 | sdhci_msm_bus_set_vote(msm_host, |
Sujit Reddy Thumma | 024c058 | 2013-08-06 11:21:33 +0530 | [diff] [blame] | 1636 | msm_host->msm_bus_vote.min_bw_vote, &flags); |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 1637 | } else |
| 1638 | pr_warning("%s: %s: Transfer in progress. skipping bus voting to 0 bandwidth\n", |
| 1639 | mmc_hostname(host->mmc), __func__); |
| 1640 | spin_unlock_irqrestore(&host->lock, flags); |
| 1641 | } |
| 1642 | |
| 1643 | /* |
| 1644 | * This function cancels any scheduled delayed work and sets the bus |
| 1645 | * vote based on bw (bandwidth) argument. |
| 1646 | */ |
| 1647 | static void sdhci_msm_bus_cancel_work_and_set_vote(struct sdhci_host *host, |
| 1648 | unsigned int bw) |
| 1649 | { |
| 1650 | int vote; |
| 1651 | unsigned long flags; |
| 1652 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 1653 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
| 1654 | |
| 1655 | cancel_delayed_work_sync(&msm_host->msm_bus_vote.vote_work); |
| 1656 | spin_lock_irqsave(&host->lock, flags); |
| 1657 | vote = sdhci_msm_bus_get_vote_for_bw(msm_host, bw); |
Sujit Reddy Thumma | 024c058 | 2013-08-06 11:21:33 +0530 | [diff] [blame] | 1658 | sdhci_msm_bus_set_vote(msm_host, vote, &flags); |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 1659 | spin_unlock_irqrestore(&host->lock, flags); |
| 1660 | } |
| 1661 | |
| 1662 | #define MSM_MMC_BUS_VOTING_DELAY 200 /* msecs */ |
| 1663 | |
| 1664 | /* This function queues a work which will set the bandwidth requiement to 0 */ |
| 1665 | static void sdhci_msm_bus_queue_work(struct sdhci_host *host) |
| 1666 | { |
| 1667 | unsigned long flags; |
| 1668 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 1669 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
| 1670 | |
| 1671 | spin_lock_irqsave(&host->lock, flags); |
| 1672 | if (msm_host->msm_bus_vote.min_bw_vote != |
| 1673 | msm_host->msm_bus_vote.curr_vote) |
| 1674 | queue_delayed_work(system_wq, |
| 1675 | &msm_host->msm_bus_vote.vote_work, |
| 1676 | msecs_to_jiffies(MSM_MMC_BUS_VOTING_DELAY)); |
| 1677 | spin_unlock_irqrestore(&host->lock, flags); |
| 1678 | } |
| 1679 | |
| 1680 | static int sdhci_msm_bus_register(struct sdhci_msm_host *host, |
| 1681 | struct platform_device *pdev) |
| 1682 | { |
| 1683 | int rc = 0; |
| 1684 | struct msm_bus_scale_pdata *bus_pdata; |
| 1685 | |
| 1686 | struct sdhci_msm_bus_voting_data *data; |
| 1687 | struct device *dev = &pdev->dev; |
| 1688 | |
| 1689 | data = devm_kzalloc(dev, |
| 1690 | sizeof(struct sdhci_msm_bus_voting_data), GFP_KERNEL); |
| 1691 | if (!data) { |
| 1692 | dev_err(&pdev->dev, |
| 1693 | "%s: failed to allocate memory\n", __func__); |
| 1694 | rc = -ENOMEM; |
| 1695 | goto out; |
| 1696 | } |
| 1697 | data->bus_pdata = msm_bus_cl_get_pdata(pdev); |
| 1698 | if (data->bus_pdata) { |
| 1699 | rc = sdhci_msm_dt_get_array(dev, "qcom,bus-bw-vectors-bps", |
| 1700 | &data->bw_vecs, &data->bw_vecs_size, 0); |
| 1701 | if (rc) { |
| 1702 | dev_err(&pdev->dev, |
| 1703 | "%s: Failed to get bus-bw-vectors-bps\n", |
| 1704 | __func__); |
| 1705 | goto out; |
| 1706 | } |
| 1707 | host->pdata->voting_data = data; |
| 1708 | } |
| 1709 | if (host->pdata->voting_data && |
| 1710 | host->pdata->voting_data->bus_pdata && |
| 1711 | host->pdata->voting_data->bw_vecs && |
| 1712 | host->pdata->voting_data->bw_vecs_size) { |
| 1713 | |
| 1714 | bus_pdata = host->pdata->voting_data->bus_pdata; |
| 1715 | host->msm_bus_vote.client_handle = |
| 1716 | msm_bus_scale_register_client(bus_pdata); |
| 1717 | if (!host->msm_bus_vote.client_handle) { |
| 1718 | dev_err(&pdev->dev, "msm_bus_scale_register_client()\n"); |
| 1719 | rc = -EFAULT; |
| 1720 | goto out; |
| 1721 | } |
| 1722 | /* cache the vote index for minimum and maximum bandwidth */ |
| 1723 | host->msm_bus_vote.min_bw_vote = |
| 1724 | sdhci_msm_bus_get_vote_for_bw(host, 0); |
| 1725 | host->msm_bus_vote.max_bw_vote = |
| 1726 | sdhci_msm_bus_get_vote_for_bw(host, UINT_MAX); |
| 1727 | } else { |
| 1728 | devm_kfree(dev, data); |
| 1729 | } |
| 1730 | |
| 1731 | out: |
| 1732 | return rc; |
| 1733 | } |
| 1734 | |
| 1735 | static void sdhci_msm_bus_unregister(struct sdhci_msm_host *host) |
| 1736 | { |
| 1737 | if (host->msm_bus_vote.client_handle) |
| 1738 | msm_bus_scale_unregister_client( |
| 1739 | host->msm_bus_vote.client_handle); |
| 1740 | } |
| 1741 | |
| 1742 | static void sdhci_msm_bus_voting(struct sdhci_host *host, u32 enable) |
| 1743 | { |
| 1744 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 1745 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
| 1746 | struct mmc_ios *ios = &host->mmc->ios; |
| 1747 | unsigned int bw; |
| 1748 | |
| 1749 | if (!msm_host->msm_bus_vote.client_handle) |
| 1750 | return; |
| 1751 | |
| 1752 | bw = sdhci_get_bw_required(host, ios); |
Sahitya Tummala | 79edc6a | 2013-05-23 15:59:22 +0530 | [diff] [blame] | 1753 | if (enable) { |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 1754 | sdhci_msm_bus_cancel_work_and_set_vote(host, bw); |
Sahitya Tummala | 79edc6a | 2013-05-23 15:59:22 +0530 | [diff] [blame] | 1755 | } else { |
| 1756 | /* |
| 1757 | * If clock gating is enabled, then remove the vote |
| 1758 | * immediately because clocks will be disabled only |
| 1759 | * after SDHCI_MSM_MMC_CLK_GATE_DELAY and thus no |
| 1760 | * additional delay is required to remove the bus vote. |
| 1761 | */ |
| 1762 | #ifdef CONFIG_MMC_CLKGATE |
| 1763 | if (host->mmc->clkgate_delay) |
| 1764 | sdhci_msm_bus_cancel_work_and_set_vote(host, 0); |
| 1765 | else |
| 1766 | #endif |
| 1767 | sdhci_msm_bus_queue_work(host); |
| 1768 | } |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 1769 | } |
| 1770 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1771 | /* Regulator utility functions */ |
| 1772 | static int sdhci_msm_vreg_init_reg(struct device *dev, |
| 1773 | struct sdhci_msm_reg_data *vreg) |
| 1774 | { |
| 1775 | int ret = 0; |
| 1776 | |
| 1777 | /* check if regulator is already initialized? */ |
| 1778 | if (vreg->reg) |
| 1779 | goto out; |
| 1780 | |
| 1781 | /* Get the regulator handle */ |
| 1782 | vreg->reg = devm_regulator_get(dev, vreg->name); |
| 1783 | if (IS_ERR(vreg->reg)) { |
| 1784 | ret = PTR_ERR(vreg->reg); |
| 1785 | pr_err("%s: devm_regulator_get(%s) failed. ret=%d\n", |
| 1786 | __func__, vreg->name, ret); |
| 1787 | goto out; |
| 1788 | } |
| 1789 | |
Asutosh Das | c58cc7a | 2013-06-28 15:03:44 +0530 | [diff] [blame] | 1790 | if (regulator_count_voltages(vreg->reg) > 0) { |
| 1791 | vreg->set_voltage_sup = true; |
| 1792 | /* sanity check */ |
| 1793 | if (!vreg->high_vol_level || !vreg->hpm_uA) { |
| 1794 | pr_err("%s: %s invalid constraints specified\n", |
| 1795 | __func__, vreg->name); |
| 1796 | ret = -EINVAL; |
| 1797 | } |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1798 | } |
| 1799 | |
| 1800 | out: |
| 1801 | return ret; |
| 1802 | } |
| 1803 | |
| 1804 | static void sdhci_msm_vreg_deinit_reg(struct sdhci_msm_reg_data *vreg) |
| 1805 | { |
| 1806 | if (vreg->reg) |
| 1807 | devm_regulator_put(vreg->reg); |
| 1808 | } |
| 1809 | |
| 1810 | static int sdhci_msm_vreg_set_optimum_mode(struct sdhci_msm_reg_data |
| 1811 | *vreg, int uA_load) |
| 1812 | { |
| 1813 | int ret = 0; |
| 1814 | |
| 1815 | /* |
| 1816 | * regulators that do not support regulator_set_voltage also |
| 1817 | * do not support regulator_set_optimum_mode |
| 1818 | */ |
| 1819 | if (vreg->set_voltage_sup) { |
| 1820 | ret = regulator_set_load(vreg->reg, uA_load); |
| 1821 | if (ret < 0) |
| 1822 | pr_err("%s: regulator_set_load(reg=%s,uA_load=%d) failed. ret=%d\n", |
| 1823 | __func__, vreg->name, uA_load, ret); |
| 1824 | else |
| 1825 | /* |
| 1826 | * regulator_set_load() can return non zero |
| 1827 | * value even for success case. |
| 1828 | */ |
| 1829 | ret = 0; |
| 1830 | } |
| 1831 | return ret; |
| 1832 | } |
| 1833 | |
| 1834 | static int sdhci_msm_vreg_set_voltage(struct sdhci_msm_reg_data *vreg, |
| 1835 | int min_uV, int max_uV) |
| 1836 | { |
| 1837 | int ret = 0; |
Asutosh Das | c58cc7a | 2013-06-28 15:03:44 +0530 | [diff] [blame] | 1838 | if (vreg->set_voltage_sup) { |
| 1839 | ret = regulator_set_voltage(vreg->reg, min_uV, max_uV); |
| 1840 | if (ret) { |
| 1841 | pr_err("%s: regulator_set_voltage(%s)failed. min_uV=%d,max_uV=%d,ret=%d\n", |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1842 | __func__, vreg->name, min_uV, max_uV, ret); |
| 1843 | } |
Asutosh Das | c58cc7a | 2013-06-28 15:03:44 +0530 | [diff] [blame] | 1844 | } |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 1845 | |
| 1846 | return ret; |
| 1847 | } |
| 1848 | |
| 1849 | static int sdhci_msm_vreg_enable(struct sdhci_msm_reg_data *vreg) |
| 1850 | { |
| 1851 | int ret = 0; |
| 1852 | |
| 1853 | /* Put regulator in HPM (high power mode) */ |
| 1854 | ret = sdhci_msm_vreg_set_optimum_mode(vreg, vreg->hpm_uA); |
| 1855 | if (ret < 0) |
| 1856 | return ret; |
| 1857 | |
| 1858 | if (!vreg->is_enabled) { |
| 1859 | /* Set voltage level */ |
| 1860 | ret = sdhci_msm_vreg_set_voltage(vreg, vreg->high_vol_level, |
| 1861 | vreg->high_vol_level); |
| 1862 | if (ret) |
| 1863 | return ret; |
| 1864 | } |
| 1865 | ret = regulator_enable(vreg->reg); |
| 1866 | if (ret) { |
| 1867 | pr_err("%s: regulator_enable(%s) failed. ret=%d\n", |
| 1868 | __func__, vreg->name, ret); |
| 1869 | return ret; |
| 1870 | } |
| 1871 | vreg->is_enabled = true; |
| 1872 | return ret; |
| 1873 | } |
| 1874 | |
| 1875 | static int sdhci_msm_vreg_disable(struct sdhci_msm_reg_data *vreg) |
| 1876 | { |
| 1877 | int ret = 0; |
| 1878 | |
| 1879 | /* Never disable regulator marked as always_on */ |
| 1880 | if (vreg->is_enabled && !vreg->is_always_on) { |
| 1881 | ret = regulator_disable(vreg->reg); |
| 1882 | if (ret) { |
| 1883 | pr_err("%s: regulator_disable(%s) failed. ret=%d\n", |
| 1884 | __func__, vreg->name, ret); |
| 1885 | goto out; |
| 1886 | } |
| 1887 | vreg->is_enabled = false; |
| 1888 | |
| 1889 | ret = sdhci_msm_vreg_set_optimum_mode(vreg, 0); |
| 1890 | if (ret < 0) |
| 1891 | goto out; |
| 1892 | |
| 1893 | /* Set min. voltage level to 0 */ |
| 1894 | ret = sdhci_msm_vreg_set_voltage(vreg, 0, vreg->high_vol_level); |
| 1895 | if (ret) |
| 1896 | goto out; |
| 1897 | } else if (vreg->is_enabled && vreg->is_always_on) { |
| 1898 | if (vreg->lpm_sup) { |
| 1899 | /* Put always_on regulator in LPM (low power mode) */ |
| 1900 | ret = sdhci_msm_vreg_set_optimum_mode(vreg, |
| 1901 | vreg->lpm_uA); |
| 1902 | if (ret < 0) |
| 1903 | goto out; |
| 1904 | } |
| 1905 | } |
| 1906 | out: |
| 1907 | return ret; |
| 1908 | } |
| 1909 | |
| 1910 | static int sdhci_msm_setup_vreg(struct sdhci_msm_pltfm_data *pdata, |
| 1911 | bool enable, bool is_init) |
| 1912 | { |
| 1913 | int ret = 0, i; |
| 1914 | struct sdhci_msm_slot_reg_data *curr_slot; |
| 1915 | struct sdhci_msm_reg_data *vreg_table[2]; |
| 1916 | |
| 1917 | curr_slot = pdata->vreg_data; |
| 1918 | if (!curr_slot) { |
| 1919 | pr_debug("%s: vreg info unavailable,assuming the slot is powered by always on domain\n", |
| 1920 | __func__); |
| 1921 | goto out; |
| 1922 | } |
| 1923 | |
| 1924 | vreg_table[0] = curr_slot->vdd_data; |
| 1925 | vreg_table[1] = curr_slot->vdd_io_data; |
| 1926 | |
| 1927 | for (i = 0; i < ARRAY_SIZE(vreg_table); i++) { |
| 1928 | if (vreg_table[i]) { |
| 1929 | if (enable) |
| 1930 | ret = sdhci_msm_vreg_enable(vreg_table[i]); |
| 1931 | else |
| 1932 | ret = sdhci_msm_vreg_disable(vreg_table[i]); |
| 1933 | if (ret) |
| 1934 | goto out; |
| 1935 | } |
| 1936 | } |
| 1937 | out: |
| 1938 | return ret; |
| 1939 | } |
| 1940 | |
| 1941 | /* |
| 1942 | * Reset vreg by ensuring it is off during probe. A call |
| 1943 | * to enable vreg is needed to balance disable vreg |
| 1944 | */ |
| 1945 | static int sdhci_msm_vreg_reset(struct sdhci_msm_pltfm_data *pdata) |
| 1946 | { |
| 1947 | int ret; |
| 1948 | |
| 1949 | ret = sdhci_msm_setup_vreg(pdata, 1, true); |
| 1950 | if (ret) |
| 1951 | return ret; |
| 1952 | ret = sdhci_msm_setup_vreg(pdata, 0, true); |
| 1953 | return ret; |
| 1954 | } |
| 1955 | |
| 1956 | /* This init function should be called only once for each SDHC slot */ |
| 1957 | static int sdhci_msm_vreg_init(struct device *dev, |
| 1958 | struct sdhci_msm_pltfm_data *pdata, |
| 1959 | bool is_init) |
| 1960 | { |
| 1961 | int ret = 0; |
| 1962 | struct sdhci_msm_slot_reg_data *curr_slot; |
| 1963 | struct sdhci_msm_reg_data *curr_vdd_reg, *curr_vdd_io_reg; |
| 1964 | |
| 1965 | curr_slot = pdata->vreg_data; |
| 1966 | if (!curr_slot) |
| 1967 | goto out; |
| 1968 | |
| 1969 | curr_vdd_reg = curr_slot->vdd_data; |
| 1970 | curr_vdd_io_reg = curr_slot->vdd_io_data; |
| 1971 | |
| 1972 | if (!is_init) |
| 1973 | /* Deregister all regulators from regulator framework */ |
| 1974 | goto vdd_io_reg_deinit; |
| 1975 | |
| 1976 | /* |
| 1977 | * Get the regulator handle from voltage regulator framework |
| 1978 | * and then try to set the voltage level for the regulator |
| 1979 | */ |
| 1980 | if (curr_vdd_reg) { |
| 1981 | ret = sdhci_msm_vreg_init_reg(dev, curr_vdd_reg); |
| 1982 | if (ret) |
| 1983 | goto out; |
| 1984 | } |
| 1985 | if (curr_vdd_io_reg) { |
| 1986 | ret = sdhci_msm_vreg_init_reg(dev, curr_vdd_io_reg); |
| 1987 | if (ret) |
| 1988 | goto vdd_reg_deinit; |
| 1989 | } |
| 1990 | ret = sdhci_msm_vreg_reset(pdata); |
| 1991 | if (ret) |
| 1992 | dev_err(dev, "vreg reset failed (%d)\n", ret); |
| 1993 | goto out; |
| 1994 | |
| 1995 | vdd_io_reg_deinit: |
| 1996 | if (curr_vdd_io_reg) |
| 1997 | sdhci_msm_vreg_deinit_reg(curr_vdd_io_reg); |
| 1998 | vdd_reg_deinit: |
| 1999 | if (curr_vdd_reg) |
| 2000 | sdhci_msm_vreg_deinit_reg(curr_vdd_reg); |
| 2001 | out: |
| 2002 | return ret; |
| 2003 | } |
| 2004 | |
| 2005 | |
| 2006 | static int sdhci_msm_set_vdd_io_vol(struct sdhci_msm_pltfm_data *pdata, |
| 2007 | enum vdd_io_level level, |
| 2008 | unsigned int voltage_level) |
| 2009 | { |
| 2010 | int ret = 0; |
| 2011 | int set_level; |
| 2012 | struct sdhci_msm_reg_data *vdd_io_reg; |
| 2013 | |
| 2014 | if (!pdata->vreg_data) |
| 2015 | return ret; |
| 2016 | |
| 2017 | vdd_io_reg = pdata->vreg_data->vdd_io_data; |
| 2018 | if (vdd_io_reg && vdd_io_reg->is_enabled) { |
| 2019 | switch (level) { |
| 2020 | case VDD_IO_LOW: |
| 2021 | set_level = vdd_io_reg->low_vol_level; |
| 2022 | break; |
| 2023 | case VDD_IO_HIGH: |
| 2024 | set_level = vdd_io_reg->high_vol_level; |
| 2025 | break; |
| 2026 | case VDD_IO_SET_LEVEL: |
| 2027 | set_level = voltage_level; |
| 2028 | break; |
| 2029 | default: |
| 2030 | pr_err("%s: invalid argument level = %d", |
| 2031 | __func__, level); |
| 2032 | ret = -EINVAL; |
| 2033 | return ret; |
| 2034 | } |
| 2035 | ret = sdhci_msm_vreg_set_voltage(vdd_io_reg, set_level, |
| 2036 | set_level); |
| 2037 | } |
| 2038 | return ret; |
| 2039 | } |
| 2040 | |
| 2041 | static irqreturn_t sdhci_msm_pwr_irq(int irq, void *data) |
| 2042 | { |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 2043 | struct sdhci_host *host = (struct sdhci_host *)data; |
| 2044 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 2045 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 2046 | u8 irq_status = 0; |
| 2047 | u8 irq_ack = 0; |
| 2048 | int ret = 0; |
Sahitya Tummala | 1f52eaa | 2013-03-20 19:24:01 +0530 | [diff] [blame] | 2049 | int pwr_state = 0, io_level = 0; |
| 2050 | unsigned long flags; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 2051 | |
| 2052 | irq_status = readb_relaxed(msm_host->core_mem + CORE_PWRCTL_STATUS); |
| 2053 | pr_debug("%s: Received IRQ(%d), status=0x%x\n", |
| 2054 | mmc_hostname(msm_host->mmc), irq, irq_status); |
| 2055 | |
| 2056 | /* Clear the interrupt */ |
| 2057 | writeb_relaxed(irq_status, (msm_host->core_mem + CORE_PWRCTL_CLEAR)); |
| 2058 | /* |
| 2059 | * SDHC has core_mem and hc_mem device memory and these memory |
| 2060 | * addresses do not fall within 1KB region. Hence, any update to |
| 2061 | * core_mem address space would require an mb() to ensure this gets |
| 2062 | * completed before its next update to registers within hc_mem. |
| 2063 | */ |
| 2064 | mb(); |
| 2065 | |
| 2066 | /* Handle BUS ON/OFF*/ |
| 2067 | if (irq_status & CORE_PWRCTL_BUS_ON) { |
| 2068 | ret = sdhci_msm_setup_vreg(msm_host->pdata, true, false); |
Sahitya Tummala | 1f52eaa | 2013-03-20 19:24:01 +0530 | [diff] [blame] | 2069 | if (!ret) { |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 2070 | ret = sdhci_msm_setup_pins(msm_host->pdata, true); |
Sahitya Tummala | 1f52eaa | 2013-03-20 19:24:01 +0530 | [diff] [blame] | 2071 | ret |= sdhci_msm_set_vdd_io_vol(msm_host->pdata, |
| 2072 | VDD_IO_HIGH, 0); |
| 2073 | } |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 2074 | if (ret) |
| 2075 | irq_ack |= CORE_PWRCTL_BUS_FAIL; |
| 2076 | else |
| 2077 | irq_ack |= CORE_PWRCTL_BUS_SUCCESS; |
Sahitya Tummala | 1f52eaa | 2013-03-20 19:24:01 +0530 | [diff] [blame] | 2078 | |
| 2079 | pwr_state = REQ_BUS_ON; |
| 2080 | io_level = REQ_IO_HIGH; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 2081 | } |
| 2082 | if (irq_status & CORE_PWRCTL_BUS_OFF) { |
| 2083 | ret = sdhci_msm_setup_vreg(msm_host->pdata, false, false); |
Sahitya Tummala | 1f52eaa | 2013-03-20 19:24:01 +0530 | [diff] [blame] | 2084 | if (!ret) { |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 2085 | ret = sdhci_msm_setup_pins(msm_host->pdata, false); |
Sahitya Tummala | 1f52eaa | 2013-03-20 19:24:01 +0530 | [diff] [blame] | 2086 | ret |= sdhci_msm_set_vdd_io_vol(msm_host->pdata, |
| 2087 | VDD_IO_LOW, 0); |
| 2088 | } |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 2089 | if (ret) |
| 2090 | irq_ack |= CORE_PWRCTL_BUS_FAIL; |
| 2091 | else |
| 2092 | irq_ack |= CORE_PWRCTL_BUS_SUCCESS; |
Sahitya Tummala | 1f52eaa | 2013-03-20 19:24:01 +0530 | [diff] [blame] | 2093 | |
| 2094 | pwr_state = REQ_BUS_OFF; |
| 2095 | io_level = REQ_IO_LOW; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 2096 | } |
| 2097 | /* Handle IO LOW/HIGH */ |
| 2098 | if (irq_status & CORE_PWRCTL_IO_LOW) { |
| 2099 | /* Switch voltage Low */ |
| 2100 | ret = sdhci_msm_set_vdd_io_vol(msm_host->pdata, VDD_IO_LOW, 0); |
| 2101 | if (ret) |
| 2102 | irq_ack |= CORE_PWRCTL_IO_FAIL; |
| 2103 | else |
| 2104 | irq_ack |= CORE_PWRCTL_IO_SUCCESS; |
Sahitya Tummala | 1f52eaa | 2013-03-20 19:24:01 +0530 | [diff] [blame] | 2105 | |
| 2106 | io_level = REQ_IO_LOW; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 2107 | } |
| 2108 | if (irq_status & CORE_PWRCTL_IO_HIGH) { |
| 2109 | /* Switch voltage High */ |
| 2110 | ret = sdhci_msm_set_vdd_io_vol(msm_host->pdata, VDD_IO_HIGH, 0); |
| 2111 | if (ret) |
| 2112 | irq_ack |= CORE_PWRCTL_IO_FAIL; |
| 2113 | else |
| 2114 | irq_ack |= CORE_PWRCTL_IO_SUCCESS; |
Sahitya Tummala | 1f52eaa | 2013-03-20 19:24:01 +0530 | [diff] [blame] | 2115 | |
| 2116 | io_level = REQ_IO_HIGH; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 2117 | } |
| 2118 | |
| 2119 | /* ACK status to the core */ |
| 2120 | writeb_relaxed(irq_ack, (msm_host->core_mem + CORE_PWRCTL_CTL)); |
| 2121 | /* |
| 2122 | * SDHC has core_mem and hc_mem device memory and these memory |
| 2123 | * addresses do not fall within 1KB region. Hence, any update to |
| 2124 | * core_mem address space would require an mb() to ensure this gets |
| 2125 | * completed before its next update to registers within hc_mem. |
| 2126 | */ |
| 2127 | mb(); |
| 2128 | |
Krishna Konda | 46fd143 | 2014-10-30 21:13:27 -0700 | [diff] [blame] | 2129 | if ((io_level & REQ_IO_HIGH) && (msm_host->caps_0 & CORE_3_0V_SUPPORT)) |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 2130 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_VENDOR_SPEC) & |
| 2131 | ~CORE_IO_PAD_PWR_SWITCH), |
| 2132 | host->ioaddr + CORE_VENDOR_SPEC); |
Krishna Konda | 46fd143 | 2014-10-30 21:13:27 -0700 | [diff] [blame] | 2133 | else if ((io_level & REQ_IO_LOW) || |
| 2134 | (msm_host->caps_0 & CORE_1_8V_SUPPORT)) |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 2135 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_VENDOR_SPEC) | |
| 2136 | CORE_IO_PAD_PWR_SWITCH), |
| 2137 | host->ioaddr + CORE_VENDOR_SPEC); |
| 2138 | mb(); |
| 2139 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 2140 | pr_debug("%s: Handled IRQ(%d), ret=%d, ack=0x%x\n", |
| 2141 | mmc_hostname(msm_host->mmc), irq, ret, irq_ack); |
Sahitya Tummala | 1f52eaa | 2013-03-20 19:24:01 +0530 | [diff] [blame] | 2142 | spin_lock_irqsave(&host->lock, flags); |
| 2143 | if (pwr_state) |
| 2144 | msm_host->curr_pwr_state = pwr_state; |
| 2145 | if (io_level) |
| 2146 | msm_host->curr_io_level = io_level; |
| 2147 | complete(&msm_host->pwr_irq_completion); |
| 2148 | spin_unlock_irqrestore(&host->lock, flags); |
| 2149 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 2150 | return IRQ_HANDLED; |
| 2151 | } |
| 2152 | |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 2153 | static ssize_t |
Sahitya Tummala | 5c55b93 | 2013-06-20 14:00:18 +0530 | [diff] [blame] | 2154 | show_polling(struct device *dev, struct device_attribute *attr, char *buf) |
| 2155 | { |
| 2156 | struct sdhci_host *host = dev_get_drvdata(dev); |
| 2157 | int poll; |
| 2158 | unsigned long flags; |
| 2159 | |
| 2160 | spin_lock_irqsave(&host->lock, flags); |
| 2161 | poll = !!(host->mmc->caps & MMC_CAP_NEEDS_POLL); |
| 2162 | spin_unlock_irqrestore(&host->lock, flags); |
| 2163 | |
| 2164 | return snprintf(buf, PAGE_SIZE, "%d\n", poll); |
| 2165 | } |
| 2166 | |
| 2167 | static ssize_t |
| 2168 | store_polling(struct device *dev, struct device_attribute *attr, |
| 2169 | const char *buf, size_t count) |
| 2170 | { |
| 2171 | struct sdhci_host *host = dev_get_drvdata(dev); |
| 2172 | int value; |
| 2173 | unsigned long flags; |
| 2174 | |
| 2175 | if (!kstrtou32(buf, 0, &value)) { |
| 2176 | spin_lock_irqsave(&host->lock, flags); |
| 2177 | if (value) { |
| 2178 | host->mmc->caps |= MMC_CAP_NEEDS_POLL; |
| 2179 | mmc_detect_change(host->mmc, 0); |
| 2180 | } else { |
| 2181 | host->mmc->caps &= ~MMC_CAP_NEEDS_POLL; |
| 2182 | } |
| 2183 | spin_unlock_irqrestore(&host->lock, flags); |
| 2184 | } |
| 2185 | return count; |
| 2186 | } |
| 2187 | |
| 2188 | static ssize_t |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 2189 | show_sdhci_max_bus_bw(struct device *dev, struct device_attribute *attr, |
| 2190 | char *buf) |
| 2191 | { |
| 2192 | struct sdhci_host *host = dev_get_drvdata(dev); |
| 2193 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 2194 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
| 2195 | |
| 2196 | return snprintf(buf, PAGE_SIZE, "%u\n", |
| 2197 | msm_host->msm_bus_vote.is_max_bw_needed); |
| 2198 | } |
| 2199 | |
| 2200 | static ssize_t |
| 2201 | store_sdhci_max_bus_bw(struct device *dev, struct device_attribute *attr, |
| 2202 | const char *buf, size_t count) |
| 2203 | { |
| 2204 | struct sdhci_host *host = dev_get_drvdata(dev); |
| 2205 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 2206 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
| 2207 | uint32_t value; |
| 2208 | unsigned long flags; |
| 2209 | |
| 2210 | if (!kstrtou32(buf, 0, &value)) { |
| 2211 | spin_lock_irqsave(&host->lock, flags); |
| 2212 | msm_host->msm_bus_vote.is_max_bw_needed = !!value; |
| 2213 | spin_unlock_irqrestore(&host->lock, flags); |
| 2214 | } |
| 2215 | return count; |
| 2216 | } |
| 2217 | |
Sahitya Tummala | 1f52eaa | 2013-03-20 19:24:01 +0530 | [diff] [blame] | 2218 | 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] | 2219 | { |
| 2220 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 2221 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
Sahitya Tummala | 1f52eaa | 2013-03-20 19:24:01 +0530 | [diff] [blame] | 2222 | unsigned long flags; |
| 2223 | bool done = false; |
Sahitya Tummala | 481fbb0 | 2013-08-06 15:22:28 +0530 | [diff] [blame] | 2224 | u32 io_sig_sts; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 2225 | |
Sahitya Tummala | 1f52eaa | 2013-03-20 19:24:01 +0530 | [diff] [blame] | 2226 | spin_lock_irqsave(&host->lock, flags); |
| 2227 | pr_debug("%s: %s: request %d curr_pwr_state %x curr_io_level %x\n", |
| 2228 | mmc_hostname(host->mmc), __func__, req_type, |
| 2229 | msm_host->curr_pwr_state, msm_host->curr_io_level); |
Sahitya Tummala | 481fbb0 | 2013-08-06 15:22:28 +0530 | [diff] [blame] | 2230 | io_sig_sts = readl_relaxed(msm_host->core_mem + CORE_GENERICS); |
| 2231 | /* |
| 2232 | * The IRQ for request type IO High/Low will be generated when - |
| 2233 | * 1. SWITCHABLE_SIGNALLING_VOL is enabled in HW. |
| 2234 | * 2. If 1 is true and when there is a state change in 1.8V enable |
| 2235 | * bit (bit 3) of SDHCI_HOST_CONTROL2 register. The reset state of |
| 2236 | * that bit is 0 which indicates 3.3V IO voltage. So, when MMC core |
| 2237 | * layer tries to set it to 3.3V before card detection happens, the |
| 2238 | * IRQ doesn't get triggered as there is no state change in this bit. |
| 2239 | * The driver already handles this case by changing the IO voltage |
| 2240 | * level to high as part of controller power up sequence. Hence, check |
| 2241 | * for host->pwr to handle a case where IO voltage high request is |
| 2242 | * issued even before controller power up. |
| 2243 | */ |
| 2244 | if (req_type & (REQ_IO_HIGH | REQ_IO_LOW)) { |
| 2245 | if (!(io_sig_sts & SWITCHABLE_SIGNALLING_VOL) || |
| 2246 | ((req_type & REQ_IO_HIGH) && !host->pwr)) { |
| 2247 | pr_debug("%s: do not wait for power IRQ that never comes\n", |
| 2248 | mmc_hostname(host->mmc)); |
| 2249 | spin_unlock_irqrestore(&host->lock, flags); |
| 2250 | return; |
| 2251 | } |
| 2252 | } |
| 2253 | |
Sahitya Tummala | 1f52eaa | 2013-03-20 19:24:01 +0530 | [diff] [blame] | 2254 | if ((req_type & msm_host->curr_pwr_state) || |
| 2255 | (req_type & msm_host->curr_io_level)) |
| 2256 | done = true; |
| 2257 | spin_unlock_irqrestore(&host->lock, flags); |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 2258 | |
Sahitya Tummala | 1f52eaa | 2013-03-20 19:24:01 +0530 | [diff] [blame] | 2259 | /* |
| 2260 | * This is needed here to hanlde a case where IRQ gets |
| 2261 | * triggered even before this function is called so that |
| 2262 | * x->done counter of completion gets reset. Otherwise, |
| 2263 | * next call to wait_for_completion returns immediately |
| 2264 | * without actually waiting for the IRQ to be handled. |
| 2265 | */ |
| 2266 | if (done) |
| 2267 | init_completion(&msm_host->pwr_irq_completion); |
| 2268 | else |
| 2269 | wait_for_completion(&msm_host->pwr_irq_completion); |
| 2270 | |
| 2271 | pr_debug("%s: %s: request %d done\n", mmc_hostname(host->mmc), |
| 2272 | __func__, req_type); |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 2273 | } |
| 2274 | |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 2275 | static void sdhci_msm_toggle_cdr(struct sdhci_host *host, bool enable) |
| 2276 | { |
| 2277 | if (enable) |
| 2278 | writel_relaxed((readl_relaxed(host->ioaddr + |
| 2279 | CORE_DLL_CONFIG) | CORE_CDR_EN), |
| 2280 | host->ioaddr + CORE_DLL_CONFIG); |
| 2281 | else |
| 2282 | writel_relaxed((readl_relaxed(host->ioaddr + |
| 2283 | CORE_DLL_CONFIG) & ~CORE_CDR_EN), |
| 2284 | host->ioaddr + CORE_DLL_CONFIG); |
| 2285 | } |
| 2286 | |
Asutosh Das | 648f9d1 | 2013-01-10 21:11:04 +0530 | [diff] [blame] | 2287 | static unsigned int sdhci_msm_max_segs(void) |
| 2288 | { |
| 2289 | return SDHCI_MSM_MAX_SEGMENTS; |
| 2290 | } |
| 2291 | |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 2292 | static unsigned int sdhci_msm_get_min_clock(struct sdhci_host *host) |
Sahitya Tummala | a7f3c57 | 2013-01-11 11:30:45 +0530 | [diff] [blame] | 2293 | { |
Sahitya Tummala | a7f3c57 | 2013-01-11 11:30:45 +0530 | [diff] [blame] | 2294 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 2295 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
Sahitya Tummala | a7f3c57 | 2013-01-11 11:30:45 +0530 | [diff] [blame] | 2296 | |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 2297 | return msm_host->pdata->sup_clk_table[0]; |
| 2298 | } |
| 2299 | |
| 2300 | static unsigned int sdhci_msm_get_max_clock(struct sdhci_host *host) |
| 2301 | { |
| 2302 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 2303 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
| 2304 | int max_clk_index = msm_host->pdata->sup_clk_cnt; |
| 2305 | |
| 2306 | return msm_host->pdata->sup_clk_table[max_clk_index - 1]; |
| 2307 | } |
| 2308 | |
| 2309 | static unsigned int sdhci_msm_get_sup_clk_rate(struct sdhci_host *host, |
| 2310 | u32 req_clk) |
| 2311 | { |
| 2312 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 2313 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
| 2314 | unsigned int sel_clk = -1; |
| 2315 | unsigned char cnt; |
| 2316 | |
| 2317 | if (req_clk < sdhci_msm_get_min_clock(host)) { |
| 2318 | sel_clk = sdhci_msm_get_min_clock(host); |
| 2319 | return sel_clk; |
| 2320 | } |
| 2321 | |
| 2322 | for (cnt = 0; cnt < msm_host->pdata->sup_clk_cnt; cnt++) { |
| 2323 | if (msm_host->pdata->sup_clk_table[cnt] > req_clk) { |
| 2324 | break; |
| 2325 | } else if (msm_host->pdata->sup_clk_table[cnt] == req_clk) { |
| 2326 | sel_clk = msm_host->pdata->sup_clk_table[cnt]; |
| 2327 | break; |
| 2328 | } else { |
| 2329 | sel_clk = msm_host->pdata->sup_clk_table[cnt]; |
| 2330 | } |
| 2331 | } |
| 2332 | return sel_clk; |
| 2333 | } |
| 2334 | |
Asutosh Das | 9d7ee2f | 2013-11-08 12:33:47 +0530 | [diff] [blame] | 2335 | static int sdhci_msm_enable_controller_clock(struct sdhci_host *host) |
| 2336 | { |
| 2337 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 2338 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
| 2339 | int rc = 0; |
| 2340 | |
| 2341 | if (atomic_read(&msm_host->controller_clock)) |
| 2342 | return 0; |
| 2343 | |
| 2344 | sdhci_msm_bus_voting(host, 1); |
| 2345 | |
| 2346 | if (!IS_ERR(msm_host->pclk)) { |
| 2347 | rc = clk_prepare_enable(msm_host->pclk); |
| 2348 | if (rc) { |
| 2349 | pr_err("%s: %s: failed to enable the pclk with error %d\n", |
| 2350 | mmc_hostname(host->mmc), __func__, rc); |
| 2351 | goto remove_vote; |
| 2352 | } |
| 2353 | } |
| 2354 | |
| 2355 | rc = clk_prepare_enable(msm_host->clk); |
| 2356 | if (rc) { |
| 2357 | pr_err("%s: %s: failed to enable the host-clk with error %d\n", |
| 2358 | mmc_hostname(host->mmc), __func__, rc); |
| 2359 | goto disable_pclk; |
| 2360 | } |
| 2361 | |
| 2362 | atomic_set(&msm_host->controller_clock, 1); |
| 2363 | pr_debug("%s: %s: enabled controller clock\n", |
| 2364 | mmc_hostname(host->mmc), __func__); |
| 2365 | goto out; |
| 2366 | |
| 2367 | disable_pclk: |
| 2368 | if (!IS_ERR(msm_host->pclk)) |
| 2369 | clk_disable_unprepare(msm_host->pclk); |
| 2370 | remove_vote: |
| 2371 | if (msm_host->msm_bus_vote.client_handle) |
| 2372 | sdhci_msm_bus_cancel_work_and_set_vote(host, 0); |
| 2373 | out: |
| 2374 | return rc; |
| 2375 | } |
| 2376 | |
| 2377 | |
| 2378 | |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 2379 | static int sdhci_msm_prepare_clocks(struct sdhci_host *host, bool enable) |
| 2380 | { |
| 2381 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 2382 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
| 2383 | int rc = 0; |
| 2384 | |
| 2385 | if (enable && !atomic_read(&msm_host->clks_on)) { |
| 2386 | pr_debug("%s: request to enable clocks\n", |
| 2387 | mmc_hostname(host->mmc)); |
Sahitya Tummala | 79edc6a | 2013-05-23 15:59:22 +0530 | [diff] [blame] | 2388 | |
Asutosh Das | 9d7ee2f | 2013-11-08 12:33:47 +0530 | [diff] [blame] | 2389 | /* |
| 2390 | * The bus-width or the clock rate might have changed |
| 2391 | * after controller clocks are enbaled, update bus vote |
| 2392 | * in such case. |
| 2393 | */ |
| 2394 | if (atomic_read(&msm_host->controller_clock)) |
| 2395 | sdhci_msm_bus_voting(host, 1); |
| 2396 | |
| 2397 | rc = sdhci_msm_enable_controller_clock(host); |
| 2398 | if (rc) |
| 2399 | goto remove_vote; |
Sahitya Tummala | 79edc6a | 2013-05-23 15:59:22 +0530 | [diff] [blame] | 2400 | |
Sahitya Tummala | a7f3c57 | 2013-01-11 11:30:45 +0530 | [diff] [blame] | 2401 | if (!IS_ERR_OR_NULL(msm_host->bus_clk)) { |
| 2402 | rc = clk_prepare_enable(msm_host->bus_clk); |
| 2403 | if (rc) { |
| 2404 | pr_err("%s: %s: failed to enable the bus-clock with error %d\n", |
| 2405 | mmc_hostname(host->mmc), __func__, rc); |
Asutosh Das | 9d7ee2f | 2013-11-08 12:33:47 +0530 | [diff] [blame] | 2406 | goto disable_controller_clk; |
Sahitya Tummala | a7f3c57 | 2013-01-11 11:30:45 +0530 | [diff] [blame] | 2407 | } |
| 2408 | } |
Venkat Gopalakrishnan | 7f69157 | 2013-06-23 17:36:46 -0700 | [diff] [blame] | 2409 | if (!IS_ERR(msm_host->ff_clk)) { |
| 2410 | rc = clk_prepare_enable(msm_host->ff_clk); |
| 2411 | if (rc) { |
| 2412 | pr_err("%s: %s: failed to enable the ff_clk with error %d\n", |
| 2413 | mmc_hostname(host->mmc), __func__, rc); |
Asutosh Das | 9d7ee2f | 2013-11-08 12:33:47 +0530 | [diff] [blame] | 2414 | goto disable_bus_clk; |
Venkat Gopalakrishnan | 7f69157 | 2013-06-23 17:36:46 -0700 | [diff] [blame] | 2415 | } |
| 2416 | } |
| 2417 | if (!IS_ERR(msm_host->sleep_clk)) { |
| 2418 | rc = clk_prepare_enable(msm_host->sleep_clk); |
| 2419 | if (rc) { |
| 2420 | pr_err("%s: %s: failed to enable the sleep_clk with error %d\n", |
| 2421 | mmc_hostname(host->mmc), __func__, rc); |
| 2422 | goto disable_ff_clk; |
| 2423 | } |
| 2424 | } |
Sahitya Tummala | a7f3c57 | 2013-01-11 11:30:45 +0530 | [diff] [blame] | 2425 | mb(); |
Sahitya Tummala | a7f3c57 | 2013-01-11 11:30:45 +0530 | [diff] [blame] | 2426 | |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 2427 | } else if (!enable && atomic_read(&msm_host->clks_on)) { |
Sahitya Tummala | a7f3c57 | 2013-01-11 11:30:45 +0530 | [diff] [blame] | 2428 | sdhci_writew(host, 0, SDHCI_CLOCK_CONTROL); |
| 2429 | mb(); |
Sahitya Tummala | dc18298 | 2013-08-20 15:32:09 +0530 | [diff] [blame] | 2430 | /* |
| 2431 | * During 1.8V signal switching the clock source must |
| 2432 | * still be ON as it requires accessing SDHC |
| 2433 | * registers (SDHCi host control2 register bit 3 must |
| 2434 | * be written and polled after stopping the SDCLK). |
| 2435 | */ |
| 2436 | if (host->mmc->card_clock_off) |
| 2437 | return 0; |
| 2438 | pr_debug("%s: request to disable clocks\n", |
| 2439 | mmc_hostname(host->mmc)); |
Venkat Gopalakrishnan | 7f69157 | 2013-06-23 17:36:46 -0700 | [diff] [blame] | 2440 | if (!IS_ERR_OR_NULL(msm_host->sleep_clk)) |
| 2441 | clk_disable_unprepare(msm_host->sleep_clk); |
| 2442 | if (!IS_ERR_OR_NULL(msm_host->ff_clk)) |
| 2443 | clk_disable_unprepare(msm_host->ff_clk); |
Sahitya Tummala | a7f3c57 | 2013-01-11 11:30:45 +0530 | [diff] [blame] | 2444 | clk_disable_unprepare(msm_host->clk); |
| 2445 | if (!IS_ERR(msm_host->pclk)) |
| 2446 | clk_disable_unprepare(msm_host->pclk); |
| 2447 | if (!IS_ERR_OR_NULL(msm_host->bus_clk)) |
| 2448 | clk_disable_unprepare(msm_host->bus_clk); |
Sahitya Tummala | 79edc6a | 2013-05-23 15:59:22 +0530 | [diff] [blame] | 2449 | |
Asutosh Das | 9d7ee2f | 2013-11-08 12:33:47 +0530 | [diff] [blame] | 2450 | atomic_set(&msm_host->controller_clock, 0); |
Sahitya Tummala | 79edc6a | 2013-05-23 15:59:22 +0530 | [diff] [blame] | 2451 | sdhci_msm_bus_voting(host, 0); |
Sahitya Tummala | a7f3c57 | 2013-01-11 11:30:45 +0530 | [diff] [blame] | 2452 | } |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 2453 | atomic_set(&msm_host->clks_on, enable); |
Sahitya Tummala | a7f3c57 | 2013-01-11 11:30:45 +0530 | [diff] [blame] | 2454 | goto out; |
Venkat Gopalakrishnan | 7f69157 | 2013-06-23 17:36:46 -0700 | [diff] [blame] | 2455 | disable_ff_clk: |
| 2456 | if (!IS_ERR_OR_NULL(msm_host->ff_clk)) |
| 2457 | clk_disable_unprepare(msm_host->ff_clk); |
Sahitya Tummala | a7f3c57 | 2013-01-11 11:30:45 +0530 | [diff] [blame] | 2458 | disable_bus_clk: |
| 2459 | if (!IS_ERR_OR_NULL(msm_host->bus_clk)) |
| 2460 | clk_disable_unprepare(msm_host->bus_clk); |
Asutosh Das | 9d7ee2f | 2013-11-08 12:33:47 +0530 | [diff] [blame] | 2461 | disable_controller_clk: |
| 2462 | if (!IS_ERR_OR_NULL(msm_host->clk)) |
| 2463 | clk_disable_unprepare(msm_host->clk); |
| 2464 | if (!IS_ERR_OR_NULL(msm_host->pclk)) |
| 2465 | clk_disable_unprepare(msm_host->pclk); |
| 2466 | atomic_set(&msm_host->controller_clock, 0); |
Sahitya Tummala | 79edc6a | 2013-05-23 15:59:22 +0530 | [diff] [blame] | 2467 | remove_vote: |
| 2468 | if (msm_host->msm_bus_vote.client_handle) |
| 2469 | sdhci_msm_bus_cancel_work_and_set_vote(host, 0); |
Sahitya Tummala | a7f3c57 | 2013-01-11 11:30:45 +0530 | [diff] [blame] | 2470 | out: |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 2471 | return rc; |
| 2472 | } |
| 2473 | |
| 2474 | static void sdhci_msm_set_clock(struct sdhci_host *host, unsigned int clock) |
| 2475 | { |
| 2476 | int rc; |
| 2477 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 2478 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
| 2479 | struct mmc_ios curr_ios = host->mmc->ios; |
Krishna Konda | 2faa7bb | 2014-06-04 01:25:16 -0700 | [diff] [blame] | 2480 | u32 sup_clock, ddr_clock, dll_lock; |
Sahitya Tummala | 043744a | 2013-06-24 09:55:33 +0530 | [diff] [blame] | 2481 | bool curr_pwrsave; |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 2482 | |
| 2483 | if (!clock) { |
Sujit Reddy Thumma | bf1aecc | 2014-01-10 10:58:54 +0530 | [diff] [blame] | 2484 | /* |
| 2485 | * disable pwrsave to ensure clock is not auto-gated until |
| 2486 | * the rate is >400KHz (initialization complete). |
| 2487 | */ |
| 2488 | writel_relaxed(readl_relaxed(host->ioaddr + CORE_VENDOR_SPEC) & |
| 2489 | ~CORE_CLK_PWRSAVE, host->ioaddr + CORE_VENDOR_SPEC); |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 2490 | sdhci_msm_prepare_clocks(host, false); |
| 2491 | host->clock = clock; |
| 2492 | goto out; |
| 2493 | } |
| 2494 | |
| 2495 | rc = sdhci_msm_prepare_clocks(host, true); |
| 2496 | if (rc) |
| 2497 | goto out; |
| 2498 | |
Sahitya Tummala | 043744a | 2013-06-24 09:55:33 +0530 | [diff] [blame] | 2499 | curr_pwrsave = !!(readl_relaxed(host->ioaddr + CORE_VENDOR_SPEC) & |
| 2500 | CORE_CLK_PWRSAVE); |
Sahitya Tummala | e000b24 | 2013-08-29 16:21:08 +0530 | [diff] [blame] | 2501 | if ((clock > 400000) && |
Venkat Gopalakrishnan | c0a36727 | 2015-02-24 13:09:09 -0800 | [diff] [blame] | 2502 | !curr_pwrsave && mmc_host_may_gate_card(host->mmc->card)) |
Sahitya Tummala | 043744a | 2013-06-24 09:55:33 +0530 | [diff] [blame] | 2503 | writel_relaxed(readl_relaxed(host->ioaddr + CORE_VENDOR_SPEC) |
| 2504 | | CORE_CLK_PWRSAVE, |
| 2505 | host->ioaddr + CORE_VENDOR_SPEC); |
| 2506 | /* |
| 2507 | * Disable pwrsave for a newly added card if doesn't allow clock |
| 2508 | * gating. |
| 2509 | */ |
Venkat Gopalakrishnan | c0a36727 | 2015-02-24 13:09:09 -0800 | [diff] [blame] | 2510 | else if (curr_pwrsave && !mmc_host_may_gate_card(host->mmc->card)) |
Sahitya Tummala | 043744a | 2013-06-24 09:55:33 +0530 | [diff] [blame] | 2511 | writel_relaxed(readl_relaxed(host->ioaddr + CORE_VENDOR_SPEC) |
| 2512 | & ~CORE_CLK_PWRSAVE, |
| 2513 | host->ioaddr + CORE_VENDOR_SPEC); |
| 2514 | |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 2515 | sup_clock = sdhci_msm_get_sup_clk_rate(host, clock); |
Venkat Gopalakrishnan | 7f69157 | 2013-06-23 17:36:46 -0700 | [diff] [blame] | 2516 | if ((curr_ios.timing == MMC_TIMING_UHS_DDR50) || |
Venkat Gopalakrishnan | 0a29da9 | 2015-01-09 12:19:16 -0800 | [diff] [blame] | 2517 | (curr_ios.timing == MMC_TIMING_MMC_DDR52) || |
Venkat Gopalakrishnan | 7f69157 | 2013-06-23 17:36:46 -0700 | [diff] [blame] | 2518 | (curr_ios.timing == MMC_TIMING_MMC_HS400)) { |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 2519 | /* |
| 2520 | * The SDHC requires internal clock frequency to be double the |
| 2521 | * actual clock that will be set for DDR mode. The controller |
Venkat Gopalakrishnan | 7f69157 | 2013-06-23 17:36:46 -0700 | [diff] [blame] | 2522 | * uses the faster clock(100/400MHz) for some of its parts and |
| 2523 | * send the actual required clock (50/200MHz) to the card. |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 2524 | */ |
| 2525 | ddr_clock = clock * 2; |
| 2526 | sup_clock = sdhci_msm_get_sup_clk_rate(host, |
| 2527 | ddr_clock); |
| 2528 | } |
Venkat Gopalakrishnan | 7f69157 | 2013-06-23 17:36:46 -0700 | [diff] [blame] | 2529 | |
| 2530 | /* |
| 2531 | * In general all timing modes are controlled via UHS mode select in |
| 2532 | * Host Control2 register. eMMC specific HS200/HS400 doesn't have |
| 2533 | * their respective modes defined here, hence we use these values. |
| 2534 | * |
| 2535 | * HS200 - SDR104 (Since they both are equivalent in functionality) |
| 2536 | * HS400 - This involves multiple configurations |
| 2537 | * Initially SDR104 - when tuning is required as HS200 |
| 2538 | * Then when switching to DDR @ 400MHz (HS400) we use |
| 2539 | * the vendor specific HC_SELECT_IN to control the mode. |
| 2540 | * |
| 2541 | * In addition to controlling the modes we also need to select the |
| 2542 | * correct input clock for DLL depending on the mode. |
| 2543 | * |
| 2544 | * HS400 - divided clock (free running MCLK/2) |
| 2545 | * All other modes - default (free running MCLK) |
| 2546 | */ |
| 2547 | if (curr_ios.timing == MMC_TIMING_MMC_HS400) { |
| 2548 | /* Select the divided clock (free running MCLK/2) */ |
| 2549 | writel_relaxed(((readl_relaxed(host->ioaddr + CORE_VENDOR_SPEC) |
| 2550 | & ~CORE_HC_MCLK_SEL_MASK) |
| 2551 | | CORE_HC_MCLK_SEL_HS400), |
| 2552 | host->ioaddr + CORE_VENDOR_SPEC); |
| 2553 | /* |
| 2554 | * Select HS400 mode using the HC_SELECT_IN from VENDOR SPEC |
| 2555 | * register |
| 2556 | */ |
Ritesh Harjani | ea70966 | 2015-05-27 15:40:24 +0530 | [diff] [blame] | 2557 | if ((msm_host->tuning_done || msm_host->enhanced_strobe) && |
| 2558 | !msm_host->calibration_done) { |
Venkat Gopalakrishnan | 7f69157 | 2013-06-23 17:36:46 -0700 | [diff] [blame] | 2559 | /* |
| 2560 | * Write 0x6 to HC_SELECT_IN and 1 to HC_SELECT_IN_EN |
| 2561 | * field in VENDOR_SPEC_FUNC |
| 2562 | */ |
| 2563 | writel_relaxed((readl_relaxed(host->ioaddr + \ |
| 2564 | CORE_VENDOR_SPEC) |
| 2565 | | CORE_HC_SELECT_IN_HS400 |
| 2566 | | CORE_HC_SELECT_IN_EN), |
| 2567 | host->ioaddr + CORE_VENDOR_SPEC); |
| 2568 | } |
Krishna Konda | 2faa7bb | 2014-06-04 01:25:16 -0700 | [diff] [blame] | 2569 | if (!host->mmc->ios.old_rate && !msm_host->use_cdclp533) { |
| 2570 | /* |
| 2571 | * Poll on DLL_LOCK and DDR_DLL_LOCK bits in |
| 2572 | * CORE_DLL_STATUS to be set. This should get set |
| 2573 | * with in 15 us at 200 MHz. |
| 2574 | */ |
| 2575 | rc = readl_poll_timeout(host->ioaddr + CORE_DLL_STATUS, |
| 2576 | dll_lock, (dll_lock & (CORE_DLL_LOCK | |
| 2577 | CORE_DDR_DLL_LOCK)), 10, 1000); |
| 2578 | if (rc == -ETIMEDOUT) |
| 2579 | pr_err("%s: Unable to get DLL_LOCK/DDR_DLL_LOCK, dll_status: 0x%08x\n", |
| 2580 | mmc_hostname(host->mmc), |
| 2581 | dll_lock); |
| 2582 | } |
Venkat Gopalakrishnan | 7f69157 | 2013-06-23 17:36:46 -0700 | [diff] [blame] | 2583 | } else { |
Krishna Konda | 2faa7bb | 2014-06-04 01:25:16 -0700 | [diff] [blame] | 2584 | if (!msm_host->use_cdclp533) |
| 2585 | /* set CORE_PWRSAVE_DLL bit in CORE_VENDOR_SPEC3 */ |
| 2586 | writel_relaxed((readl_relaxed(host->ioaddr + |
| 2587 | CORE_VENDOR_SPEC3) & ~CORE_PWRSAVE_DLL), |
| 2588 | host->ioaddr + CORE_VENDOR_SPEC3); |
| 2589 | |
Venkat Gopalakrishnan | 7f69157 | 2013-06-23 17:36:46 -0700 | [diff] [blame] | 2590 | /* Select the default clock (free running MCLK) */ |
| 2591 | writel_relaxed(((readl_relaxed(host->ioaddr + CORE_VENDOR_SPEC) |
| 2592 | & ~CORE_HC_MCLK_SEL_MASK) |
| 2593 | | CORE_HC_MCLK_SEL_DFLT), |
| 2594 | host->ioaddr + CORE_VENDOR_SPEC); |
| 2595 | |
| 2596 | /* |
| 2597 | * Disable HC_SELECT_IN to be able to use the UHS mode select |
| 2598 | * configuration from Host Control2 register for all other |
| 2599 | * modes. |
| 2600 | * |
| 2601 | * Write 0 to HC_SELECT_IN and HC_SELECT_IN_EN field |
| 2602 | * in VENDOR_SPEC_FUNC |
| 2603 | */ |
| 2604 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_VENDOR_SPEC) |
| 2605 | & ~CORE_HC_SELECT_IN_EN |
| 2606 | & ~CORE_HC_SELECT_IN_MASK), |
| 2607 | host->ioaddr + CORE_VENDOR_SPEC); |
| 2608 | } |
| 2609 | mb(); |
| 2610 | |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 2611 | if (sup_clock != msm_host->clk_rate) { |
| 2612 | pr_debug("%s: %s: setting clk rate to %u\n", |
| 2613 | mmc_hostname(host->mmc), __func__, sup_clock); |
| 2614 | rc = clk_set_rate(msm_host->clk, sup_clock); |
| 2615 | if (rc) { |
| 2616 | pr_err("%s: %s: Failed to set rate %u for host-clk : %d\n", |
| 2617 | mmc_hostname(host->mmc), __func__, |
| 2618 | sup_clock, rc); |
| 2619 | goto out; |
| 2620 | } |
| 2621 | msm_host->clk_rate = sup_clock; |
| 2622 | host->clock = clock; |
Sahitya Tummala | 79edc6a | 2013-05-23 15:59:22 +0530 | [diff] [blame] | 2623 | /* |
| 2624 | * Update the bus vote in case of frequency change due to |
| 2625 | * clock scaling. |
| 2626 | */ |
| 2627 | sdhci_msm_bus_voting(host, 1); |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 2628 | } |
| 2629 | out: |
| 2630 | sdhci_set_clock(host, clock); |
Sahitya Tummala | a7f3c57 | 2013-01-11 11:30:45 +0530 | [diff] [blame] | 2631 | } |
| 2632 | |
Sahitya Tummala | 1461343 | 2013-03-21 11:13:25 +0530 | [diff] [blame] | 2633 | static void sdhci_msm_set_uhs_signaling(struct sdhci_host *host, |
| 2634 | unsigned int uhs) |
| 2635 | { |
Venkat Gopalakrishnan | 7f69157 | 2013-06-23 17:36:46 -0700 | [diff] [blame] | 2636 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 2637 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
Sahitya Tummala | 1461343 | 2013-03-21 11:13:25 +0530 | [diff] [blame] | 2638 | u16 ctrl_2; |
| 2639 | |
| 2640 | ctrl_2 = sdhci_readw(host, SDHCI_HOST_CONTROL2); |
| 2641 | /* Select Bus Speed Mode for host */ |
| 2642 | ctrl_2 &= ~SDHCI_CTRL_UHS_MASK; |
Venkat Gopalakrishnan | 0a29da9 | 2015-01-09 12:19:16 -0800 | [diff] [blame] | 2643 | if ((uhs == MMC_TIMING_MMC_HS400) || |
| 2644 | (uhs == MMC_TIMING_MMC_HS200) || |
| 2645 | (uhs == MMC_TIMING_UHS_SDR104)) |
Sahitya Tummala | 1461343 | 2013-03-21 11:13:25 +0530 | [diff] [blame] | 2646 | ctrl_2 |= SDHCI_CTRL_UHS_SDR104; |
| 2647 | else if (uhs == MMC_TIMING_UHS_SDR12) |
| 2648 | ctrl_2 |= SDHCI_CTRL_UHS_SDR12; |
| 2649 | else if (uhs == MMC_TIMING_UHS_SDR25) |
| 2650 | ctrl_2 |= SDHCI_CTRL_UHS_SDR25; |
| 2651 | else if (uhs == MMC_TIMING_UHS_SDR50) |
| 2652 | ctrl_2 |= SDHCI_CTRL_UHS_SDR50; |
Venkat Gopalakrishnan | 0a29da9 | 2015-01-09 12:19:16 -0800 | [diff] [blame] | 2653 | else if ((uhs == MMC_TIMING_UHS_DDR50) || |
| 2654 | (uhs == MMC_TIMING_MMC_DDR52)) |
Sahitya Tummala | 1461343 | 2013-03-21 11:13:25 +0530 | [diff] [blame] | 2655 | ctrl_2 |= SDHCI_CTRL_UHS_DDR50; |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 2656 | /* |
| 2657 | * When clock frquency is less than 100MHz, the feedback clock must be |
| 2658 | * provided and DLL must not be used so that tuning can be skipped. To |
| 2659 | * provide feedback clock, the mode selection can be any value less |
| 2660 | * than 3'b011 in bits [2:0] of HOST CONTROL2 register. |
| 2661 | */ |
Venkat Gopalakrishnan | 7f69157 | 2013-06-23 17:36:46 -0700 | [diff] [blame] | 2662 | if (host->clock <= CORE_FREQ_100MHZ) { |
| 2663 | if ((uhs == MMC_TIMING_MMC_HS400) || |
| 2664 | (uhs == MMC_TIMING_MMC_HS200) || |
| 2665 | (uhs == MMC_TIMING_UHS_SDR104)) |
| 2666 | ctrl_2 &= ~SDHCI_CTRL_UHS_MASK; |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 2667 | |
Venkat Gopalakrishnan | 7f69157 | 2013-06-23 17:36:46 -0700 | [diff] [blame] | 2668 | /* |
| 2669 | * Make sure DLL is disabled when not required |
| 2670 | * |
| 2671 | * Write 1 to DLL_RST bit of DLL_CONFIG register |
| 2672 | */ |
| 2673 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG) |
| 2674 | | CORE_DLL_RST), |
| 2675 | host->ioaddr + CORE_DLL_CONFIG); |
| 2676 | |
| 2677 | /* Write 1 to DLL_PDN bit of DLL_CONFIG register */ |
| 2678 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_DLL_CONFIG) |
| 2679 | | CORE_DLL_PDN), |
| 2680 | host->ioaddr + CORE_DLL_CONFIG); |
| 2681 | mb(); |
| 2682 | |
| 2683 | /* |
| 2684 | * The DLL needs to be restored and CDCLP533 recalibrated |
| 2685 | * when the clock frequency is set back to 400MHz. |
| 2686 | */ |
| 2687 | msm_host->calibration_done = false; |
| 2688 | } |
| 2689 | |
| 2690 | pr_debug("%s: %s-clock:%u uhs mode:%u ctrl_2:0x%x\n", |
| 2691 | mmc_hostname(host->mmc), __func__, host->clock, uhs, ctrl_2); |
Sahitya Tummala | 1461343 | 2013-03-21 11:13:25 +0530 | [diff] [blame] | 2692 | sdhci_writew(host, ctrl_2, SDHCI_HOST_CONTROL2); |
| 2693 | |
| 2694 | } |
| 2695 | |
Venkat Gopalakrishnan | 3481197 | 2015-03-04 14:39:01 -0800 | [diff] [blame] | 2696 | #define MAX_TEST_BUS 60 |
Sahitya Tummala | 67717bc | 2013-08-02 09:21:37 +0530 | [diff] [blame] | 2697 | |
| 2698 | void sdhci_msm_dump_vendor_regs(struct sdhci_host *host) |
| 2699 | { |
| 2700 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 2701 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
| 2702 | int tbsel, tbsel2; |
| 2703 | int i, index = 0; |
| 2704 | u32 test_bus_val = 0; |
| 2705 | u32 debug_reg[MAX_TEST_BUS] = {0}; |
| 2706 | |
| 2707 | pr_info("----------- VENDOR REGISTER DUMP -----------\n"); |
| 2708 | pr_info("Data cnt: 0x%08x | Fifo cnt: 0x%08x | Int sts: 0x%08x\n", |
| 2709 | readl_relaxed(msm_host->core_mem + CORE_MCI_DATA_CNT), |
| 2710 | readl_relaxed(msm_host->core_mem + CORE_MCI_FIFO_CNT), |
| 2711 | readl_relaxed(msm_host->core_mem + CORE_MCI_STATUS)); |
| 2712 | pr_info("DLL cfg: 0x%08x | DLL sts: 0x%08x | SDCC ver: 0x%08x\n", |
| 2713 | readl_relaxed(host->ioaddr + CORE_DLL_CONFIG), |
| 2714 | readl_relaxed(host->ioaddr + CORE_DLL_STATUS), |
| 2715 | readl_relaxed(msm_host->core_mem + CORE_MCI_VERSION)); |
| 2716 | pr_info("Vndr func: 0x%08x | Vndr adma err : addr0: 0x%08x addr1: 0x%08x\n", |
| 2717 | readl_relaxed(host->ioaddr + CORE_VENDOR_SPEC), |
| 2718 | readl_relaxed(host->ioaddr + CORE_VENDOR_SPEC_ADMA_ERR_ADDR0), |
| 2719 | readl_relaxed(host->ioaddr + CORE_VENDOR_SPEC_ADMA_ERR_ADDR1)); |
| 2720 | |
| 2721 | /* |
| 2722 | * tbsel indicates [2:0] bits and tbsel2 indicates [7:4] bits |
| 2723 | * of CORE_TESTBUS_CONFIG register. |
| 2724 | * |
| 2725 | * To select test bus 0 to 7 use tbsel and to select any test bus |
| 2726 | * above 7 use (tbsel2 | tbsel) to get the test bus number. For eg, |
| 2727 | * to select test bus 14, write 0x1E to CORE_TESTBUS_CONFIG register |
| 2728 | * i.e., tbsel2[7:4] = 0001, tbsel[2:0] = 110. |
| 2729 | */ |
Venkat Gopalakrishnan | 3481197 | 2015-03-04 14:39:01 -0800 | [diff] [blame] | 2730 | for (tbsel2 = 0; tbsel2 < 7; tbsel2++) { |
Sahitya Tummala | 67717bc | 2013-08-02 09:21:37 +0530 | [diff] [blame] | 2731 | for (tbsel = 0; tbsel < 8; tbsel++) { |
| 2732 | if (index >= MAX_TEST_BUS) |
| 2733 | break; |
| 2734 | test_bus_val = (tbsel2 << CORE_TESTBUS_SEL2_BIT) | |
| 2735 | tbsel | CORE_TESTBUS_ENA; |
| 2736 | writel_relaxed(test_bus_val, |
| 2737 | msm_host->core_mem + CORE_TESTBUS_CONFIG); |
| 2738 | debug_reg[index++] = readl_relaxed(msm_host->core_mem + |
| 2739 | CORE_SDCC_DEBUG_REG); |
| 2740 | } |
| 2741 | } |
| 2742 | for (i = 0; i < MAX_TEST_BUS; i = i + 4) |
| 2743 | pr_info(" Test bus[%d to %d]: 0x%08x 0x%08x 0x%08x 0x%08x\n", |
| 2744 | i, i + 3, debug_reg[i], debug_reg[i+1], |
| 2745 | debug_reg[i+2], debug_reg[i+3]); |
Venkat Gopalakrishnan | 06f7f79 | 2015-05-29 17:56:59 -0700 | [diff] [blame] | 2746 | } |
| 2747 | |
Ritesh Harjani | 4a5ffd1 | 2015-07-15 13:32:07 +0530 | [diff] [blame] | 2748 | /* |
| 2749 | * sdhci_msm_enhanced_strobe_mask :- |
| 2750 | * Before running CMDQ transfers in HS400 Enhanced Strobe mode, |
| 2751 | * SW should write 3 to |
| 2752 | * HC_VENDOR_SPECIFIC_FUNC3.CMDEN_HS400_INPUT_MASK_CNT register. |
| 2753 | * The default reset value of this register is 2. |
| 2754 | */ |
| 2755 | static void sdhci_msm_enhanced_strobe_mask(struct sdhci_host *host, bool set) |
| 2756 | { |
| 2757 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 2758 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
| 2759 | |
| 2760 | if (!msm_host->enhanced_strobe) { |
| 2761 | pr_debug("%s: host does not support hs400 enhanced strobe\n", |
| 2762 | mmc_hostname(host->mmc)); |
| 2763 | return; |
| 2764 | } |
| 2765 | |
| 2766 | if (set) { |
| 2767 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_VENDOR_SPEC3) |
| 2768 | | CORE_CMDEN_HS400_INPUT_MASK_CNT), |
| 2769 | host->ioaddr + CORE_VENDOR_SPEC3); |
| 2770 | } else { |
| 2771 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_VENDOR_SPEC3) |
| 2772 | & ~CORE_CMDEN_HS400_INPUT_MASK_CNT), |
| 2773 | host->ioaddr + CORE_VENDOR_SPEC3); |
| 2774 | } |
| 2775 | } |
| 2776 | |
Venkat Gopalakrishnan | 06f7f79 | 2015-05-29 17:56:59 -0700 | [diff] [blame] | 2777 | static void sdhci_msm_clear_set_dumpregs(struct sdhci_host *host, bool set) |
| 2778 | { |
| 2779 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 2780 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
| 2781 | |
| 2782 | if (set) { |
| 2783 | writel_relaxed(CORE_TESTBUS_ENA, |
| 2784 | msm_host->core_mem + CORE_TESTBUS_CONFIG); |
| 2785 | } else { |
| 2786 | u32 value; |
| 2787 | |
| 2788 | value = readl_relaxed(msm_host->core_mem + CORE_TESTBUS_CONFIG); |
| 2789 | value &= ~CORE_TESTBUS_ENA; |
| 2790 | writel_relaxed(value, msm_host->core_mem + CORE_TESTBUS_CONFIG); |
| 2791 | } |
Sahitya Tummala | 67717bc | 2013-08-02 09:21:37 +0530 | [diff] [blame] | 2792 | } |
| 2793 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 2794 | static struct sdhci_ops sdhci_msm_ops = { |
Sahitya Tummala | 1461343 | 2013-03-21 11:13:25 +0530 | [diff] [blame] | 2795 | .set_uhs_signaling = sdhci_msm_set_uhs_signaling, |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 2796 | .check_power_status = sdhci_msm_check_power_status, |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 2797 | .platform_execute_tuning = sdhci_msm_execute_tuning, |
Ritesh Harjani | ea70966 | 2015-05-27 15:40:24 +0530 | [diff] [blame] | 2798 | .enhanced_strobe = sdhci_msm_enhanced_strobe, |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 2799 | .toggle_cdr = sdhci_msm_toggle_cdr, |
Asutosh Das | 648f9d1 | 2013-01-10 21:11:04 +0530 | [diff] [blame] | 2800 | .get_max_segments = sdhci_msm_max_segs, |
Sahitya Tummala | a7f3c57 | 2013-01-11 11:30:45 +0530 | [diff] [blame] | 2801 | .set_clock = sdhci_msm_set_clock, |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 2802 | .get_min_clock = sdhci_msm_get_min_clock, |
| 2803 | .get_max_clock = sdhci_msm_get_max_clock, |
Sahitya Tummala | 67717bc | 2013-08-02 09:21:37 +0530 | [diff] [blame] | 2804 | .dump_vendor_regs = sdhci_msm_dump_vendor_regs, |
Asutosh Das | e5e9ca6 | 2013-07-30 19:08:36 +0530 | [diff] [blame] | 2805 | .config_auto_tuning_cmd = sdhci_msm_config_auto_tuning_cmd, |
Asutosh Das | 9d7ee2f | 2013-11-08 12:33:47 +0530 | [diff] [blame] | 2806 | .enable_controller_clock = sdhci_msm_enable_controller_clock, |
Venkat Gopalakrishnan | b8cb707 | 2015-01-09 11:04:34 -0800 | [diff] [blame] | 2807 | .set_bus_width = sdhci_set_bus_width, |
Venkat Gopalakrishnan | 411df07 | 2015-01-09 11:09:44 -0800 | [diff] [blame] | 2808 | .reset = sdhci_reset, |
Venkat Gopalakrishnan | 06f7f79 | 2015-05-29 17:56:59 -0700 | [diff] [blame] | 2809 | .clear_set_dumpregs = sdhci_msm_clear_set_dumpregs, |
Ritesh Harjani | 4a5ffd1 | 2015-07-15 13:32:07 +0530 | [diff] [blame] | 2810 | .enhanced_strobe_mask = sdhci_msm_enhanced_strobe_mask, |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 2811 | }; |
| 2812 | |
Pratibhasagar V | d8acb7c | 2013-11-11 01:32:21 +0530 | [diff] [blame] | 2813 | static void sdhci_set_default_hw_caps(struct sdhci_msm_host *msm_host, |
| 2814 | struct sdhci_host *host) |
| 2815 | { |
Krishna Konda | 46fd143 | 2014-10-30 21:13:27 -0700 | [diff] [blame] | 2816 | u32 version, caps = 0; |
Pratibhasagar V | d8acb7c | 2013-11-11 01:32:21 +0530 | [diff] [blame] | 2817 | u16 minor; |
| 2818 | u8 major; |
| 2819 | |
| 2820 | version = readl_relaxed(msm_host->core_mem + CORE_MCI_VERSION); |
| 2821 | major = (version & CORE_VERSION_MAJOR_MASK) >> |
| 2822 | CORE_VERSION_MAJOR_SHIFT; |
| 2823 | minor = version & CORE_VERSION_TARGET_MASK; |
| 2824 | |
Krishna Konda | 46fd143 | 2014-10-30 21:13:27 -0700 | [diff] [blame] | 2825 | caps = readl_relaxed(host->ioaddr + SDHCI_CAPABILITIES); |
| 2826 | |
Pratibhasagar V | d8acb7c | 2013-11-11 01:32:21 +0530 | [diff] [blame] | 2827 | /* |
| 2828 | * Starting with SDCC 5 controller (core major version = 1) |
Venkat Gopalakrishnan | 3ac8fd3 | 2014-08-28 18:15:45 -0700 | [diff] [blame] | 2829 | * controller won't advertise 3.0v, 1.8v and 8-bit features |
| 2830 | * except for some targets. |
Pratibhasagar V | d8acb7c | 2013-11-11 01:32:21 +0530 | [diff] [blame] | 2831 | */ |
| 2832 | if (major >= 1 && minor != 0x11 && minor != 0x12) { |
Venkat Gopalakrishnan | 3ac8fd3 | 2014-08-28 18:15:45 -0700 | [diff] [blame] | 2833 | struct sdhci_msm_reg_data *vdd_io_reg; |
Venkat Gopalakrishnan | 3ac8fd3 | 2014-08-28 18:15:45 -0700 | [diff] [blame] | 2834 | /* |
| 2835 | * Enable 1.8V support capability on controllers that |
| 2836 | * support dual voltage |
| 2837 | */ |
| 2838 | vdd_io_reg = msm_host->pdata->vreg_data->vdd_io_data; |
Krishna Konda | 46fd143 | 2014-10-30 21:13:27 -0700 | [diff] [blame] | 2839 | if (vdd_io_reg && (vdd_io_reg->high_vol_level > 2700000)) |
| 2840 | caps |= CORE_3_0V_SUPPORT; |
| 2841 | if (vdd_io_reg && (vdd_io_reg->low_vol_level < 1950000)) |
Venkat Gopalakrishnan | 3ac8fd3 | 2014-08-28 18:15:45 -0700 | [diff] [blame] | 2842 | caps |= CORE_1_8V_SUPPORT; |
Pratibhasagar V | ada4799 | 2013-12-09 20:42:32 +0530 | [diff] [blame] | 2843 | if (msm_host->pdata->mmc_bus_width == MMC_CAP_8_BIT_DATA) |
| 2844 | caps |= CORE_8_BIT_SUPPORT; |
Pratibhasagar V | d8acb7c | 2013-11-11 01:32:21 +0530 | [diff] [blame] | 2845 | } |
Krishna Konda | 2faa7bb | 2014-06-04 01:25:16 -0700 | [diff] [blame] | 2846 | |
| 2847 | /* |
| 2848 | * SDCC 5 controller with major version 1, minor version 0x34 and later |
| 2849 | * with HS 400 mode support will use CM DLL instead of CDC LP 533 DLL. |
| 2850 | */ |
| 2851 | if ((major == 1) && (minor < 0x34)) |
| 2852 | msm_host->use_cdclp533 = true; |
Gilad Broner | 2a10ca0 | 2014-10-02 17:20:35 +0300 | [diff] [blame] | 2853 | |
| 2854 | /* |
Venkat Gopalakrishnan | c0a5c3a | 2015-02-03 16:10:07 -0800 | [diff] [blame] | 2855 | * SDCC 5 controller with major version 1, minor version 0x42 and later |
| 2856 | * will require additional steps when resetting DLL. |
Ritesh Harjani | ea70966 | 2015-05-27 15:40:24 +0530 | [diff] [blame] | 2857 | * It also supports HS400 enhanced strobe mode. |
Venkat Gopalakrishnan | c0a5c3a | 2015-02-03 16:10:07 -0800 | [diff] [blame] | 2858 | */ |
Ritesh Harjani | ea70966 | 2015-05-27 15:40:24 +0530 | [diff] [blame] | 2859 | if ((major == 1) && (minor >= 0x42)) { |
Venkat Gopalakrishnan | c0a5c3a | 2015-02-03 16:10:07 -0800 | [diff] [blame] | 2860 | msm_host->use_updated_dll_reset = true; |
Ritesh Harjani | ea70966 | 2015-05-27 15:40:24 +0530 | [diff] [blame] | 2861 | msm_host->enhanced_strobe = true; |
| 2862 | } |
Venkat Gopalakrishnan | c0a5c3a | 2015-02-03 16:10:07 -0800 | [diff] [blame] | 2863 | |
| 2864 | /* |
Talel Shenhar | 9a25b88 | 2015-06-02 13:36:35 +0300 | [diff] [blame] | 2865 | * SDCC 5 controller with major version 1 and minor version 0x42, |
| 2866 | * 0x46 and 0x49 currently uses 14lpp tech DLL whose internal |
| 2867 | * gating cannot guarantee MCLK timing requirement i.e. |
Ritesh Harjani | 764065e | 2015-05-13 14:14:45 +0530 | [diff] [blame] | 2868 | * when MCLK is gated OFF, it is not gated for less than 0.5us |
| 2869 | * and MCLK must be switched on for at-least 1us before DATA |
| 2870 | * starts coming. |
| 2871 | */ |
Talel Shenhar | 9a25b88 | 2015-06-02 13:36:35 +0300 | [diff] [blame] | 2872 | if ((major == 1) && ((minor == 0x42) || (minor == 0x46) || |
| 2873 | (minor == 0x49))) |
Ritesh Harjani | 764065e | 2015-05-13 14:14:45 +0530 | [diff] [blame] | 2874 | msm_host->use_14lpp_dll = true; |
| 2875 | /* |
Gilad Broner | 2a10ca0 | 2014-10-02 17:20:35 +0300 | [diff] [blame] | 2876 | * Mask 64-bit support for controller with 32-bit address bus so that |
| 2877 | * smaller descriptor size will be used and improve memory consumption. |
Gilad Broner | 2a10ca0 | 2014-10-02 17:20:35 +0300 | [diff] [blame] | 2878 | */ |
Venkat Gopalakrishnan | 9a62e04 | 2015-03-03 16:14:55 -0800 | [diff] [blame] | 2879 | if (!msm_host->pdata->largeaddressbus) |
| 2880 | caps &= ~CORE_SYS_BUS_SUPPORT_64_BIT; |
| 2881 | |
Gilad Broner | 2a10ca0 | 2014-10-02 17:20:35 +0300 | [diff] [blame] | 2882 | writel_relaxed(caps, host->ioaddr + CORE_VENDOR_SPEC_CAPABILITIES0); |
Krishna Konda | 46fd143 | 2014-10-30 21:13:27 -0700 | [diff] [blame] | 2883 | /* keep track of the value in SDHCI_CAPABILITIES */ |
| 2884 | msm_host->caps_0 = caps; |
Pratibhasagar V | d8acb7c | 2013-11-11 01:32:21 +0530 | [diff] [blame] | 2885 | } |
| 2886 | |
Venkat Gopalakrishnan | d371f14 | 2015-05-29 17:49:46 -0700 | [diff] [blame] | 2887 | #ifdef CONFIG_MMC_CQ_HCI |
| 2888 | static void sdhci_msm_cmdq_init(struct sdhci_host *host, |
| 2889 | struct platform_device *pdev) |
| 2890 | { |
| 2891 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 2892 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
| 2893 | |
| 2894 | host->cq_host = cmdq_pltfm_init(pdev); |
| 2895 | if (IS_ERR(host->cq_host)) |
| 2896 | dev_dbg(&pdev->dev, "cmdq-pltfm init: failed: %ld\n", |
| 2897 | PTR_ERR(host->cq_host)); |
| 2898 | else |
| 2899 | msm_host->mmc->caps2 |= MMC_CAP2_CMD_QUEUE; |
| 2900 | } |
| 2901 | #else |
| 2902 | static void sdhci_msm_cmdq_init(struct sdhci_host *host, |
| 2903 | struct platform_device *pdev) |
| 2904 | { |
| 2905 | |
| 2906 | } |
| 2907 | #endif |
| 2908 | |
Subhash Jadavani | ebcd00d | 2015-07-09 17:28:42 -0700 | [diff] [blame] | 2909 | static bool sdhci_msm_is_bootdevice(struct device *dev) |
| 2910 | { |
| 2911 | if (strnstr(saved_command_line, "androidboot.bootdevice=", |
| 2912 | strlen(saved_command_line))) { |
| 2913 | char search_string[50]; |
| 2914 | |
| 2915 | snprintf(search_string, ARRAY_SIZE(search_string), |
| 2916 | "androidboot.bootdevice=%s", dev_name(dev)); |
| 2917 | if (strnstr(saved_command_line, search_string, |
| 2918 | strlen(saved_command_line))) |
| 2919 | return true; |
| 2920 | else |
| 2921 | return false; |
| 2922 | } |
| 2923 | |
| 2924 | /* |
| 2925 | * "androidboot.bootdevice=" argument is not present then |
| 2926 | * return true as we don't know the boot device anyways. |
| 2927 | */ |
| 2928 | return true; |
| 2929 | } |
| 2930 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 2931 | static int sdhci_msm_probe(struct platform_device *pdev) |
| 2932 | { |
| 2933 | struct sdhci_host *host; |
| 2934 | struct sdhci_pltfm_host *pltfm_host; |
| 2935 | struct sdhci_msm_host *msm_host; |
| 2936 | struct resource *core_memres = NULL; |
Konstantein Dorfman | e0be02d | 2015-01-27 12:06:02 +0200 | [diff] [blame] | 2937 | int ret = 0, dead = 0; |
Stephen Boyd | 8dce5c6 | 2013-04-24 14:19:46 -0700 | [diff] [blame] | 2938 | u16 host_version; |
Venkat Gopalakrishnan | 17edb35 | 2015-06-24 14:46:49 -0700 | [diff] [blame] | 2939 | u32 irq_status, irq_ctl; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 2940 | |
| 2941 | pr_debug("%s: Enter %s\n", dev_name(&pdev->dev), __func__); |
| 2942 | msm_host = devm_kzalloc(&pdev->dev, sizeof(struct sdhci_msm_host), |
| 2943 | GFP_KERNEL); |
| 2944 | if (!msm_host) { |
| 2945 | ret = -ENOMEM; |
| 2946 | goto out; |
| 2947 | } |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 2948 | |
| 2949 | msm_host->sdhci_msm_pdata.ops = &sdhci_msm_ops; |
| 2950 | host = sdhci_pltfm_init(pdev, &msm_host->sdhci_msm_pdata, 0); |
| 2951 | if (IS_ERR(host)) { |
| 2952 | ret = PTR_ERR(host); |
| 2953 | goto out; |
| 2954 | } |
| 2955 | |
| 2956 | pltfm_host = sdhci_priv(host); |
| 2957 | pltfm_host->priv = msm_host; |
| 2958 | msm_host->mmc = host->mmc; |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 2959 | msm_host->pdev = pdev; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 2960 | |
| 2961 | /* Extract platform data */ |
| 2962 | if (pdev->dev.of_node) { |
Venkat Gopalakrishnan | 270580a | 2013-03-11 12:17:57 -0700 | [diff] [blame] | 2963 | ret = of_alias_get_id(pdev->dev.of_node, "sdhc"); |
| 2964 | if (ret < 0) { |
| 2965 | dev_err(&pdev->dev, "Failed to get slot index %d\n", |
| 2966 | ret); |
| 2967 | goto pltfm_free; |
| 2968 | } |
Subhash Jadavani | ebcd00d | 2015-07-09 17:28:42 -0700 | [diff] [blame] | 2969 | |
| 2970 | /* skip the probe if eMMC isn't a boot device */ |
| 2971 | if ((ret == 1) && !sdhci_msm_is_bootdevice(&pdev->dev)) |
| 2972 | goto pltfm_free; |
| 2973 | |
Venkat Gopalakrishnan | 270580a | 2013-03-11 12:17:57 -0700 | [diff] [blame] | 2974 | if (disable_slots & (1 << (ret - 1))) { |
| 2975 | dev_info(&pdev->dev, "%s: Slot %d disabled\n", __func__, |
| 2976 | ret); |
| 2977 | ret = -ENODEV; |
| 2978 | goto pltfm_free; |
| 2979 | } |
| 2980 | |
Dov Levenglick | c9033ab | 2015-03-10 16:00:56 +0200 | [diff] [blame] | 2981 | msm_host->pdata = sdhci_msm_populate_pdata(&pdev->dev, |
| 2982 | msm_host); |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 2983 | if (!msm_host->pdata) { |
| 2984 | dev_err(&pdev->dev, "DT parsing error\n"); |
| 2985 | goto pltfm_free; |
| 2986 | } |
| 2987 | } else { |
| 2988 | dev_err(&pdev->dev, "No device tree node\n"); |
| 2989 | goto pltfm_free; |
| 2990 | } |
| 2991 | |
| 2992 | /* Setup Clocks */ |
| 2993 | |
| 2994 | /* Setup SDCC bus voter clock. */ |
| 2995 | msm_host->bus_clk = devm_clk_get(&pdev->dev, "bus_clk"); |
| 2996 | if (!IS_ERR_OR_NULL(msm_host->bus_clk)) { |
| 2997 | /* Vote for max. clk rate for max. performance */ |
| 2998 | ret = clk_set_rate(msm_host->bus_clk, INT_MAX); |
| 2999 | if (ret) |
| 3000 | goto pltfm_free; |
| 3001 | ret = clk_prepare_enable(msm_host->bus_clk); |
| 3002 | if (ret) |
| 3003 | goto pltfm_free; |
| 3004 | } |
| 3005 | |
| 3006 | /* Setup main peripheral bus clock */ |
| 3007 | msm_host->pclk = devm_clk_get(&pdev->dev, "iface_clk"); |
| 3008 | if (!IS_ERR(msm_host->pclk)) { |
| 3009 | ret = clk_prepare_enable(msm_host->pclk); |
| 3010 | if (ret) |
| 3011 | goto bus_clk_disable; |
| 3012 | } |
Asutosh Das | 9d7ee2f | 2013-11-08 12:33:47 +0530 | [diff] [blame] | 3013 | atomic_set(&msm_host->controller_clock, 1); |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 3014 | |
| 3015 | /* Setup SDC MMC clock */ |
| 3016 | msm_host->clk = devm_clk_get(&pdev->dev, "core_clk"); |
| 3017 | if (IS_ERR(msm_host->clk)) { |
| 3018 | ret = PTR_ERR(msm_host->clk); |
| 3019 | goto pclk_disable; |
| 3020 | } |
| 3021 | |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 3022 | /* Set to the minimum supported clock frequency */ |
| 3023 | ret = clk_set_rate(msm_host->clk, sdhci_msm_get_min_clock(host)); |
| 3024 | if (ret) { |
| 3025 | dev_err(&pdev->dev, "MClk rate set failed (%d)\n", ret); |
Sahitya Tummala | 020ede0d | 2013-06-07 13:03:07 +0530 | [diff] [blame] | 3026 | goto pclk_disable; |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 3027 | } |
Sahitya Tummala | 020ede0d | 2013-06-07 13:03:07 +0530 | [diff] [blame] | 3028 | ret = clk_prepare_enable(msm_host->clk); |
| 3029 | if (ret) |
| 3030 | goto pclk_disable; |
| 3031 | |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 3032 | msm_host->clk_rate = sdhci_msm_get_min_clock(host); |
Sahitya Tummala | a7f3c57 | 2013-01-11 11:30:45 +0530 | [diff] [blame] | 3033 | atomic_set(&msm_host->clks_on, 1); |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 3034 | |
Venkat Gopalakrishnan | 7f69157 | 2013-06-23 17:36:46 -0700 | [diff] [blame] | 3035 | /* Setup CDC calibration fixed feedback clock */ |
| 3036 | msm_host->ff_clk = devm_clk_get(&pdev->dev, "cal_clk"); |
| 3037 | if (!IS_ERR(msm_host->ff_clk)) { |
| 3038 | ret = clk_prepare_enable(msm_host->ff_clk); |
| 3039 | if (ret) |
| 3040 | goto clk_disable; |
| 3041 | } |
| 3042 | |
| 3043 | /* Setup CDC calibration sleep clock */ |
| 3044 | msm_host->sleep_clk = devm_clk_get(&pdev->dev, "sleep_clk"); |
| 3045 | if (!IS_ERR(msm_host->sleep_clk)) { |
| 3046 | ret = clk_prepare_enable(msm_host->sleep_clk); |
| 3047 | if (ret) |
| 3048 | goto ff_clk_disable; |
| 3049 | } |
| 3050 | |
Venkat Gopalakrishnan | 9e06963 | 2013-06-12 11:16:37 -0700 | [diff] [blame] | 3051 | msm_host->saved_tuning_phase = INVALID_TUNING_PHASE; |
| 3052 | |
Sahitya Tummala | 79edc6a | 2013-05-23 15:59:22 +0530 | [diff] [blame] | 3053 | ret = sdhci_msm_bus_register(msm_host, pdev); |
| 3054 | if (ret) |
Venkat Gopalakrishnan | 7f69157 | 2013-06-23 17:36:46 -0700 | [diff] [blame] | 3055 | goto sleep_clk_disable; |
Sahitya Tummala | 79edc6a | 2013-05-23 15:59:22 +0530 | [diff] [blame] | 3056 | |
| 3057 | if (msm_host->msm_bus_vote.client_handle) |
| 3058 | INIT_DELAYED_WORK(&msm_host->msm_bus_vote.vote_work, |
| 3059 | sdhci_msm_bus_work); |
| 3060 | sdhci_msm_bus_voting(host, 1); |
| 3061 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 3062 | /* Setup regulators */ |
| 3063 | ret = sdhci_msm_vreg_init(&pdev->dev, msm_host->pdata, true); |
| 3064 | if (ret) { |
| 3065 | dev_err(&pdev->dev, "Regulator setup failed (%d)\n", ret); |
Sahitya Tummala | 79edc6a | 2013-05-23 15:59:22 +0530 | [diff] [blame] | 3066 | goto bus_unregister; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 3067 | } |
| 3068 | |
| 3069 | /* Reset the core and Enable SDHC mode */ |
| 3070 | core_memres = platform_get_resource_byname(pdev, |
| 3071 | IORESOURCE_MEM, "core_mem"); |
Asutosh Das | 890bdee | 2014-08-08 23:01:42 +0530 | [diff] [blame] | 3072 | if (!core_memres) { |
| 3073 | dev_err(&pdev->dev, "Failed to get iomem resource\n"); |
| 3074 | goto vreg_deinit; |
| 3075 | } |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 3076 | msm_host->core_mem = devm_ioremap(&pdev->dev, core_memres->start, |
| 3077 | resource_size(core_memres)); |
| 3078 | |
| 3079 | if (!msm_host->core_mem) { |
| 3080 | dev_err(&pdev->dev, "Failed to remap registers\n"); |
| 3081 | ret = -ENOMEM; |
| 3082 | goto vreg_deinit; |
| 3083 | } |
| 3084 | |
Sahitya Tummala | 66b0fe3 | 2013-04-25 11:50:56 +0530 | [diff] [blame] | 3085 | /* |
Venkat Gopalakrishnan | 17edb35 | 2015-06-24 14:46:49 -0700 | [diff] [blame] | 3086 | * Reset the vendor spec register to power on reset state. |
Sahitya Tummala | 66b0fe3 | 2013-04-25 11:50:56 +0530 | [diff] [blame] | 3087 | */ |
Venkat Gopalakrishnan | 17edb35 | 2015-06-24 14:46:49 -0700 | [diff] [blame] | 3088 | writel_relaxed(CORE_VENDOR_SPEC_POR_VAL, |
| 3089 | host->ioaddr + CORE_VENDOR_SPEC); |
Sahitya Tummala | 66b0fe3 | 2013-04-25 11:50:56 +0530 | [diff] [blame] | 3090 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 3091 | /* Set HC_MODE_EN bit in HC_MODE register */ |
| 3092 | writel_relaxed(HC_MODE_EN, (msm_host->core_mem + CORE_HC_MODE)); |
| 3093 | |
Venkat Gopalakrishnan | 7f69157 | 2013-06-23 17:36:46 -0700 | [diff] [blame] | 3094 | /* Set FF_CLK_SW_RST_DIS bit in HC_MODE register */ |
| 3095 | writel_relaxed(readl_relaxed(msm_host->core_mem + CORE_HC_MODE) | |
| 3096 | FF_CLK_SW_RST_DIS, msm_host->core_mem + CORE_HC_MODE); |
| 3097 | |
Pratibhasagar V | d8acb7c | 2013-11-11 01:32:21 +0530 | [diff] [blame] | 3098 | sdhci_set_default_hw_caps(msm_host, host); |
Krishna Konda | 46fd143 | 2014-10-30 21:13:27 -0700 | [diff] [blame] | 3099 | |
| 3100 | /* |
| 3101 | * Set the PAD_PWR_SWTICH_EN bit so that the PAD_PWR_SWITCH bit can |
| 3102 | * be used as required later on. |
| 3103 | */ |
| 3104 | writel_relaxed((readl_relaxed(host->ioaddr + CORE_VENDOR_SPEC) | |
| 3105 | CORE_IO_PAD_PWR_SWITCH_EN), |
| 3106 | host->ioaddr + CORE_VENDOR_SPEC); |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 3107 | /* |
Subhash Jadavani | 2813734 | 2013-05-14 17:46:43 +0530 | [diff] [blame] | 3108 | * CORE_SW_RST above may trigger power irq if previous status of PWRCTL |
| 3109 | * was either BUS_ON or IO_HIGH_V. So before we enable the power irq |
| 3110 | * interrupt in GIC (by registering the interrupt handler), we need to |
| 3111 | * ensure that any pending power irq interrupt status is acknowledged |
| 3112 | * otherwise power irq interrupt handler would be fired prematurely. |
| 3113 | */ |
| 3114 | irq_status = readl_relaxed(msm_host->core_mem + CORE_PWRCTL_STATUS); |
| 3115 | writel_relaxed(irq_status, (msm_host->core_mem + CORE_PWRCTL_CLEAR)); |
| 3116 | irq_ctl = readl_relaxed(msm_host->core_mem + CORE_PWRCTL_CTL); |
| 3117 | if (irq_status & (CORE_PWRCTL_BUS_ON | CORE_PWRCTL_BUS_OFF)) |
| 3118 | irq_ctl |= CORE_PWRCTL_BUS_SUCCESS; |
| 3119 | if (irq_status & (CORE_PWRCTL_IO_HIGH | CORE_PWRCTL_IO_LOW)) |
| 3120 | irq_ctl |= CORE_PWRCTL_IO_SUCCESS; |
| 3121 | writel_relaxed(irq_ctl, (msm_host->core_mem + CORE_PWRCTL_CTL)); |
Krishna Konda | 46fd143 | 2014-10-30 21:13:27 -0700 | [diff] [blame] | 3122 | |
Subhash Jadavani | 2813734 | 2013-05-14 17:46:43 +0530 | [diff] [blame] | 3123 | /* |
| 3124 | * Ensure that above writes are propogated before interrupt enablement |
| 3125 | * in GIC. |
| 3126 | */ |
| 3127 | mb(); |
| 3128 | |
| 3129 | /* |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 3130 | * Following are the deviations from SDHC spec v3.0 - |
| 3131 | * 1. Card detection is handled using separate GPIO. |
| 3132 | * 2. Bus power control is handled by interacting with PMIC. |
| 3133 | */ |
| 3134 | host->quirks |= SDHCI_QUIRK_BROKEN_CARD_DETECTION; |
| 3135 | host->quirks |= SDHCI_QUIRK_SINGLE_POWER_WRITE; |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 3136 | host->quirks |= SDHCI_QUIRK_CAP_CLOCK_BASE_BROKEN; |
Talel Shenhar | 4661c2a | 2015-06-24 15:49:30 +0300 | [diff] [blame] | 3137 | host->quirks |= SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC; |
Sahitya Tummala | 22dd336 | 2013-02-28 19:50:51 +0530 | [diff] [blame] | 3138 | host->quirks2 |= SDHCI_QUIRK2_ALWAYS_USE_BASE_CLOCK; |
Sahitya Tummala | 87d4394 | 2013-04-12 11:49:11 +0530 | [diff] [blame] | 3139 | host->quirks2 |= SDHCI_QUIRK2_IGNORE_DATATOUT_FOR_R1BCMD; |
Sahitya Tummala | 314162c | 2013-04-12 12:11:20 +0530 | [diff] [blame] | 3140 | host->quirks2 |= SDHCI_QUIRK2_BROKEN_PRESET_VALUE; |
Sahitya Tummala | 7c9780d | 2013-04-12 11:59:25 +0530 | [diff] [blame] | 3141 | host->quirks2 |= SDHCI_QUIRK2_USE_RESERVED_MAX_TIMEOUT; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 3142 | |
Sahitya Tummala | a5733ab5 | 2013-06-10 16:32:51 +0530 | [diff] [blame] | 3143 | if (host->quirks2 & SDHCI_QUIRK2_ALWAYS_USE_BASE_CLOCK) |
| 3144 | host->quirks2 |= SDHCI_QUIRK2_DIVIDE_TOUT_BY_4; |
| 3145 | |
Stephen Boyd | 8dce5c6 | 2013-04-24 14:19:46 -0700 | [diff] [blame] | 3146 | host_version = readw_relaxed((host->ioaddr + SDHCI_HOST_VERSION)); |
Venkat Gopalakrishnan | a58f91f | 2012-09-17 16:00:15 -0700 | [diff] [blame] | 3147 | dev_dbg(&pdev->dev, "Host Version: 0x%x Vendor Version 0x%x\n", |
| 3148 | host_version, ((host_version & SDHCI_VENDOR_VER_MASK) >> |
| 3149 | SDHCI_VENDOR_VER_SHIFT)); |
| 3150 | if (((host_version & SDHCI_VENDOR_VER_MASK) >> |
| 3151 | SDHCI_VENDOR_VER_SHIFT) == SDHCI_VER_100) { |
| 3152 | /* |
| 3153 | * Add 40us delay in interrupt handler when |
| 3154 | * operating at initialization frequency(400KHz). |
| 3155 | */ |
| 3156 | host->quirks2 |= SDHCI_QUIRK2_SLOW_INT_CLR; |
| 3157 | /* |
| 3158 | * Set Software Reset for DAT line in Software |
| 3159 | * Reset Register (Bit 2). |
| 3160 | */ |
| 3161 | host->quirks2 |= SDHCI_QUIRK2_RDWR_TX_ACTIVE_EOT; |
| 3162 | } |
| 3163 | |
Asutosh Das | 214b966 | 2013-06-13 14:27:42 +0530 | [diff] [blame] | 3164 | host->quirks2 |= SDHCI_QUIRK2_IGN_DATA_END_BIT_ERROR; |
| 3165 | |
Venkat Gopalakrishnan | a58f91f | 2012-09-17 16:00:15 -0700 | [diff] [blame] | 3166 | /* Setup PWRCTL irq */ |
Konstantein Dorfman | e0be02d | 2015-01-27 12:06:02 +0200 | [diff] [blame] | 3167 | msm_host->pwr_irq = platform_get_irq_byname(pdev, "pwr_irq"); |
| 3168 | if (msm_host->pwr_irq < 0) { |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 3169 | dev_err(&pdev->dev, "Failed to get pwr_irq by name (%d)\n", |
Konstantein Dorfman | e0be02d | 2015-01-27 12:06:02 +0200 | [diff] [blame] | 3170 | msm_host->pwr_irq); |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 3171 | goto vreg_deinit; |
| 3172 | } |
Konstantein Dorfman | e0be02d | 2015-01-27 12:06:02 +0200 | [diff] [blame] | 3173 | ret = devm_request_threaded_irq(&pdev->dev, msm_host->pwr_irq, NULL, |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 3174 | sdhci_msm_pwr_irq, IRQF_ONESHOT, |
Venkat Gopalakrishnan | 7944a37 | 2012-09-11 16:13:31 -0700 | [diff] [blame] | 3175 | dev_name(&pdev->dev), host); |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 3176 | if (ret) { |
| 3177 | dev_err(&pdev->dev, "Request threaded irq(%d) failed (%d)\n", |
Konstantein Dorfman | e0be02d | 2015-01-27 12:06:02 +0200 | [diff] [blame] | 3178 | msm_host->pwr_irq, ret); |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 3179 | goto vreg_deinit; |
| 3180 | } |
| 3181 | |
| 3182 | /* Enable pwr irq interrupts */ |
| 3183 | writel_relaxed(INT_MASK, (msm_host->core_mem + CORE_PWRCTL_MASK)); |
| 3184 | |
Sahitya Tummala | a7f3c57 | 2013-01-11 11:30:45 +0530 | [diff] [blame] | 3185 | #ifdef CONFIG_MMC_CLKGATE |
| 3186 | /* Set clock gating delay to be used when CONFIG_MMC_CLKGATE is set */ |
| 3187 | msm_host->mmc->clkgate_delay = SDHCI_MSM_MMC_CLK_GATE_DELAY; |
| 3188 | #endif |
| 3189 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 3190 | /* Set host capabilities */ |
| 3191 | msm_host->mmc->caps |= msm_host->pdata->mmc_bus_width; |
| 3192 | msm_host->mmc->caps |= msm_host->pdata->caps; |
Konstantin Dorfman | 98377d3 | 2015-02-25 10:09:41 +0200 | [diff] [blame] | 3193 | msm_host->mmc->caps |= MMC_CAP_AGGRESSIVE_PM; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 3194 | msm_host->mmc->caps2 |= msm_host->pdata->caps2; |
Venkat Gopalakrishnan | 97c1611 | 2014-12-16 18:26:25 -0800 | [diff] [blame] | 3195 | msm_host->mmc->caps2 |= MMC_CAP2_BOOTPART_NOACC; |
| 3196 | msm_host->mmc->caps2 |= MMC_CAP2_FULL_PWR_CYCLE; |
Subhash Jadavani | 6d472b2 | 2013-05-29 15:52:10 +0530 | [diff] [blame] | 3197 | msm_host->mmc->caps2 |= MMC_CAP2_ASYNC_SDIO_IRQ_4BIT_MODE; |
Venkat Gopalakrishnan | 97c1611 | 2014-12-16 18:26:25 -0800 | [diff] [blame] | 3198 | msm_host->mmc->caps2 |= MMC_CAP2_HS400_POST_TUNING; |
Talel Shenhar | 3d1dbf3 | 2015-05-13 14:08:39 +0300 | [diff] [blame] | 3199 | msm_host->mmc->caps2 |= MMC_CAP2_CLK_SCALE; |
Asutosh Das | bea115d | 2013-06-24 18:20:45 +0530 | [diff] [blame] | 3200 | msm_host->mmc->pm_caps |= MMC_PM_KEEP_POWER; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 3201 | |
| 3202 | if (msm_host->pdata->nonremovable) |
| 3203 | msm_host->mmc->caps |= MMC_CAP_NONREMOVABLE; |
| 3204 | |
Guoping Yu | f7c9133 | 2014-08-20 16:56:18 +0800 | [diff] [blame] | 3205 | if (msm_host->pdata->nonhotplug) |
| 3206 | msm_host->mmc->caps2 |= MMC_CAP2_NONHOTPLUG; |
| 3207 | |
Sahitya Tummala | c6f48d4 | 2013-03-10 07:03:17 +0530 | [diff] [blame] | 3208 | host->cpu_dma_latency_us = msm_host->pdata->cpu_dma_latency_us; |
Maya Erez | 994cf2f | 2014-10-21 20:22:04 +0300 | [diff] [blame] | 3209 | host->pm_qos_req_dma.type = msm_host->pdata->cpu_affinity_type; |
Sahitya Tummala | c6f48d4 | 2013-03-10 07:03:17 +0530 | [diff] [blame] | 3210 | |
Sahitya Tummala | 1f52eaa | 2013-03-20 19:24:01 +0530 | [diff] [blame] | 3211 | init_completion(&msm_host->pwr_irq_completion); |
| 3212 | |
Sahitya Tummala | 581df13 | 2013-03-12 14:57:46 +0530 | [diff] [blame] | 3213 | if (gpio_is_valid(msm_host->pdata->status_gpio)) { |
Sahitya Tummala | 6ddabb4 | 2014-06-05 13:26:55 +0530 | [diff] [blame] | 3214 | /* |
| 3215 | * Set up the card detect GPIO in active configuration before |
| 3216 | * configuring it as an IRQ. Otherwise, it can be in some |
| 3217 | * weird/inconsistent state resulting in flood of interrupts. |
| 3218 | */ |
| 3219 | sdhci_msm_setup_pins(msm_host->pdata, true); |
| 3220 | |
Sahitya Tummala | a3888f4 | 2015-02-05 14:05:27 +0530 | [diff] [blame] | 3221 | /* |
| 3222 | * This delay is needed for stabilizing the card detect GPIO |
| 3223 | * line after changing the pull configs. |
| 3224 | */ |
| 3225 | usleep_range(10000, 10500); |
Sahitya Tummala | 581df13 | 2013-03-12 14:57:46 +0530 | [diff] [blame] | 3226 | ret = mmc_gpio_request_cd(msm_host->mmc, |
| 3227 | msm_host->pdata->status_gpio, 0); |
| 3228 | if (ret) { |
| 3229 | dev_err(&pdev->dev, "%s: Failed to request card detection IRQ %d\n", |
| 3230 | __func__, ret); |
Sahitya Tummala | 79edc6a | 2013-05-23 15:59:22 +0530 | [diff] [blame] | 3231 | goto vreg_deinit; |
Sahitya Tummala | 581df13 | 2013-03-12 14:57:46 +0530 | [diff] [blame] | 3232 | } |
| 3233 | } |
| 3234 | |
Krishna Konda | 7feab35 | 2013-09-17 23:55:40 -0700 | [diff] [blame] | 3235 | if ((sdhci_readl(host, SDHCI_CAPABILITIES) & SDHCI_CAN_64BIT) && |
| 3236 | (dma_supported(mmc_dev(host->mmc), DMA_BIT_MASK(64)))) { |
| 3237 | host->dma_mask = DMA_BIT_MASK(64); |
| 3238 | mmc_dev(host->mmc)->dma_mask = &host->dma_mask; |
| 3239 | } else if (dma_supported(mmc_dev(host->mmc), DMA_BIT_MASK(32))) { |
Sahitya Tummala | eaa2186 | 2013-03-20 19:34:59 +0530 | [diff] [blame] | 3240 | host->dma_mask = DMA_BIT_MASK(32); |
| 3241 | mmc_dev(host->mmc)->dma_mask = &host->dma_mask; |
| 3242 | } else { |
| 3243 | dev_err(&pdev->dev, "%s: Failed to set dma mask\n", __func__); |
| 3244 | } |
| 3245 | |
Venkat Gopalakrishnan | d371f14 | 2015-05-29 17:49:46 -0700 | [diff] [blame] | 3246 | sdhci_msm_cmdq_init(host, pdev); |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 3247 | ret = sdhci_add_host(host); |
| 3248 | if (ret) { |
| 3249 | dev_err(&pdev->dev, "Add host failed (%d)\n", ret); |
Sahitya Tummala | 581df13 | 2013-03-12 14:57:46 +0530 | [diff] [blame] | 3250 | goto vreg_deinit; |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 3251 | } |
| 3252 | |
Konstantin Dorfman | 98377d3 | 2015-02-25 10:09:41 +0200 | [diff] [blame] | 3253 | pm_runtime_set_active(&pdev->dev); |
| 3254 | pm_runtime_enable(&pdev->dev); |
| 3255 | pm_runtime_set_autosuspend_delay(&pdev->dev, MSM_AUTOSUSPEND_DELAY_MS); |
| 3256 | pm_runtime_use_autosuspend(&pdev->dev); |
| 3257 | |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 3258 | msm_host->msm_bus_vote.max_bus_bw.show = show_sdhci_max_bus_bw; |
| 3259 | msm_host->msm_bus_vote.max_bus_bw.store = store_sdhci_max_bus_bw; |
| 3260 | sysfs_attr_init(&msm_host->msm_bus_vote.max_bus_bw.attr); |
| 3261 | msm_host->msm_bus_vote.max_bus_bw.attr.name = "max_bus_bw"; |
| 3262 | msm_host->msm_bus_vote.max_bus_bw.attr.mode = S_IRUGO | S_IWUSR; |
| 3263 | ret = device_create_file(&pdev->dev, |
| 3264 | &msm_host->msm_bus_vote.max_bus_bw); |
| 3265 | if (ret) |
| 3266 | goto remove_host; |
| 3267 | |
Sahitya Tummala | 5c55b93 | 2013-06-20 14:00:18 +0530 | [diff] [blame] | 3268 | if (!gpio_is_valid(msm_host->pdata->status_gpio)) { |
| 3269 | msm_host->polling.show = show_polling; |
| 3270 | msm_host->polling.store = store_polling; |
| 3271 | sysfs_attr_init(&msm_host->polling.attr); |
| 3272 | msm_host->polling.attr.name = "polling"; |
| 3273 | msm_host->polling.attr.mode = S_IRUGO | S_IWUSR; |
| 3274 | ret = device_create_file(&pdev->dev, &msm_host->polling); |
| 3275 | if (ret) |
| 3276 | goto remove_max_bus_bw_file; |
| 3277 | } |
Asutosh Das | e5e9ca6 | 2013-07-30 19:08:36 +0530 | [diff] [blame] | 3278 | |
| 3279 | msm_host->auto_cmd21_attr.show = show_auto_cmd21; |
| 3280 | msm_host->auto_cmd21_attr.store = store_auto_cmd21; |
| 3281 | sysfs_attr_init(&msm_host->auto_cmd21_attr.attr); |
| 3282 | msm_host->auto_cmd21_attr.attr.name = "enable_auto_cmd21"; |
| 3283 | msm_host->auto_cmd21_attr.attr.mode = S_IRUGO | S_IWUSR; |
| 3284 | ret = device_create_file(&pdev->dev, &msm_host->auto_cmd21_attr); |
| 3285 | if (ret) { |
| 3286 | pr_err("%s: %s: failed creating auto-cmd21 attr: %d\n", |
| 3287 | mmc_hostname(host->mmc), __func__, ret); |
| 3288 | device_remove_file(&pdev->dev, &msm_host->auto_cmd21_attr); |
| 3289 | } |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 3290 | /* Successful initialization */ |
| 3291 | goto out; |
| 3292 | |
Sahitya Tummala | 5c55b93 | 2013-06-20 14:00:18 +0530 | [diff] [blame] | 3293 | remove_max_bus_bw_file: |
| 3294 | 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] | 3295 | remove_host: |
| 3296 | dead = (readl_relaxed(host->ioaddr + SDHCI_INT_STATUS) == 0xffffffff); |
Konstantin Dorfman | 98377d3 | 2015-02-25 10:09:41 +0200 | [diff] [blame] | 3297 | pm_runtime_disable(&pdev->dev); |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 3298 | sdhci_remove_host(host, dead); |
| 3299 | vreg_deinit: |
| 3300 | sdhci_msm_vreg_init(&pdev->dev, msm_host->pdata, false); |
Sahitya Tummala | 79edc6a | 2013-05-23 15:59:22 +0530 | [diff] [blame] | 3301 | bus_unregister: |
| 3302 | if (msm_host->msm_bus_vote.client_handle) |
| 3303 | sdhci_msm_bus_cancel_work_and_set_vote(host, 0); |
| 3304 | sdhci_msm_bus_unregister(msm_host); |
Venkat Gopalakrishnan | 7f69157 | 2013-06-23 17:36:46 -0700 | [diff] [blame] | 3305 | sleep_clk_disable: |
| 3306 | if (!IS_ERR(msm_host->sleep_clk)) |
| 3307 | clk_disable_unprepare(msm_host->sleep_clk); |
| 3308 | ff_clk_disable: |
| 3309 | if (!IS_ERR(msm_host->ff_clk)) |
| 3310 | clk_disable_unprepare(msm_host->ff_clk); |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 3311 | clk_disable: |
| 3312 | if (!IS_ERR(msm_host->clk)) |
| 3313 | clk_disable_unprepare(msm_host->clk); |
| 3314 | pclk_disable: |
| 3315 | if (!IS_ERR(msm_host->pclk)) |
| 3316 | clk_disable_unprepare(msm_host->pclk); |
| 3317 | bus_clk_disable: |
| 3318 | if (!IS_ERR_OR_NULL(msm_host->bus_clk)) |
| 3319 | clk_disable_unprepare(msm_host->bus_clk); |
| 3320 | pltfm_free: |
| 3321 | sdhci_pltfm_free(pdev); |
| 3322 | out: |
| 3323 | pr_debug("%s: Exit %s\n", dev_name(&pdev->dev), __func__); |
| 3324 | return ret; |
| 3325 | } |
| 3326 | |
| 3327 | static int sdhci_msm_remove(struct platform_device *pdev) |
| 3328 | { |
| 3329 | struct sdhci_host *host = platform_get_drvdata(pdev); |
| 3330 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 3331 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
| 3332 | struct sdhci_msm_pltfm_data *pdata = msm_host->pdata; |
| 3333 | int dead = (readl_relaxed(host->ioaddr + SDHCI_INT_STATUS) == |
| 3334 | 0xffffffff); |
| 3335 | |
| 3336 | pr_debug("%s: %s\n", dev_name(&pdev->dev), __func__); |
Sahitya Tummala | 5c55b93 | 2013-06-20 14:00:18 +0530 | [diff] [blame] | 3337 | if (!gpio_is_valid(msm_host->pdata->status_gpio)) |
| 3338 | device_remove_file(&pdev->dev, &msm_host->polling); |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 3339 | device_remove_file(&pdev->dev, &msm_host->msm_bus_vote.max_bus_bw); |
Konstantin Dorfman | 98377d3 | 2015-02-25 10:09:41 +0200 | [diff] [blame] | 3340 | pm_runtime_disable(&pdev->dev); |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 3341 | sdhci_remove_host(host, dead); |
| 3342 | sdhci_pltfm_free(pdev); |
Sahitya Tummala | 581df13 | 2013-03-12 14:57:46 +0530 | [diff] [blame] | 3343 | |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 3344 | sdhci_msm_vreg_init(&pdev->dev, msm_host->pdata, false); |
Sahitya Tummala | a7f3c57 | 2013-01-11 11:30:45 +0530 | [diff] [blame] | 3345 | |
Pratibhasagar V | 9acf264 | 2013-11-21 21:07:21 +0530 | [diff] [blame] | 3346 | sdhci_msm_setup_pins(pdata, true); |
| 3347 | sdhci_msm_setup_pins(pdata, false); |
Sahitya Tummala | 8a3e818 | 2013-03-10 14:12:52 +0530 | [diff] [blame] | 3348 | |
| 3349 | if (msm_host->msm_bus_vote.client_handle) { |
| 3350 | sdhci_msm_bus_cancel_work_and_set_vote(host, 0); |
| 3351 | sdhci_msm_bus_unregister(msm_host); |
| 3352 | } |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 3353 | return 0; |
| 3354 | } |
| 3355 | |
Konstantin Dorfman | 98377d3 | 2015-02-25 10:09:41 +0200 | [diff] [blame] | 3356 | #ifdef CONFIG_PM |
| 3357 | static int sdhci_msm_runtime_suspend(struct device *dev) |
| 3358 | { |
| 3359 | struct sdhci_host *host = dev_get_drvdata(dev); |
| 3360 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 3361 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
Konstantin Dorfman | ddab0cc | 2015-02-25 16:23:50 +0200 | [diff] [blame] | 3362 | ktime_t start = ktime_get(); |
Konstantin Dorfman | 98377d3 | 2015-02-25 10:09:41 +0200 | [diff] [blame] | 3363 | |
| 3364 | disable_irq(host->irq); |
| 3365 | disable_irq(msm_host->pwr_irq); |
| 3366 | |
| 3367 | /* |
| 3368 | * Remove the vote immediately only if clocks are off in which |
| 3369 | * case we might have queued work to remove vote but it may not |
| 3370 | * be completed before runtime suspend or system suspend. |
| 3371 | */ |
| 3372 | if (!atomic_read(&msm_host->clks_on)) { |
| 3373 | if (msm_host->msm_bus_vote.client_handle) |
| 3374 | sdhci_msm_bus_cancel_work_and_set_vote(host, 0); |
| 3375 | } |
Konstantin Dorfman | ddab0cc | 2015-02-25 16:23:50 +0200 | [diff] [blame] | 3376 | trace_sdhci_msm_runtime_suspend(mmc_hostname(host->mmc), 0, |
| 3377 | ktime_to_us(ktime_sub(ktime_get(), start))); |
Konstantin Dorfman | 98377d3 | 2015-02-25 10:09:41 +0200 | [diff] [blame] | 3378 | |
| 3379 | return 0; |
| 3380 | } |
| 3381 | |
| 3382 | static int sdhci_msm_runtime_resume(struct device *dev) |
| 3383 | { |
| 3384 | struct sdhci_host *host = dev_get_drvdata(dev); |
| 3385 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 3386 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
Konstantin Dorfman | ddab0cc | 2015-02-25 16:23:50 +0200 | [diff] [blame] | 3387 | ktime_t start = ktime_get(); |
Konstantin Dorfman | 98377d3 | 2015-02-25 10:09:41 +0200 | [diff] [blame] | 3388 | |
| 3389 | enable_irq(msm_host->pwr_irq); |
| 3390 | enable_irq(host->irq); |
| 3391 | |
Konstantin Dorfman | ddab0cc | 2015-02-25 16:23:50 +0200 | [diff] [blame] | 3392 | trace_sdhci_msm_runtime_resume(mmc_hostname(host->mmc), 0, |
| 3393 | ktime_to_us(ktime_sub(ktime_get(), start))); |
Konstantin Dorfman | 98377d3 | 2015-02-25 10:09:41 +0200 | [diff] [blame] | 3394 | return 0; |
| 3395 | } |
| 3396 | |
| 3397 | static int sdhci_msm_suspend(struct device *dev) |
| 3398 | { |
| 3399 | struct sdhci_host *host = dev_get_drvdata(dev); |
| 3400 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 3401 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
Konstantin Dorfman | ddab0cc | 2015-02-25 16:23:50 +0200 | [diff] [blame] | 3402 | int ret = 0; |
| 3403 | ktime_t start = ktime_get(); |
Konstantin Dorfman | 98377d3 | 2015-02-25 10:09:41 +0200 | [diff] [blame] | 3404 | |
| 3405 | if (gpio_is_valid(msm_host->pdata->status_gpio) && |
| 3406 | (msm_host->mmc->slot.cd_irq >= 0)) |
| 3407 | disable_irq(msm_host->mmc->slot.cd_irq); |
| 3408 | |
| 3409 | if (pm_runtime_suspended(dev)) { |
| 3410 | pr_debug("%s: %s: already runtime suspended\n", |
| 3411 | mmc_hostname(host->mmc), __func__); |
| 3412 | goto out; |
| 3413 | } |
Konstantin Dorfman | ddab0cc | 2015-02-25 16:23:50 +0200 | [diff] [blame] | 3414 | ret = sdhci_msm_runtime_suspend(dev); |
Konstantin Dorfman | 98377d3 | 2015-02-25 10:09:41 +0200 | [diff] [blame] | 3415 | out: |
Konstantin Dorfman | ddab0cc | 2015-02-25 16:23:50 +0200 | [diff] [blame] | 3416 | trace_sdhci_msm_suspend(mmc_hostname(host->mmc), ret, |
| 3417 | ktime_to_us(ktime_sub(ktime_get(), start))); |
| 3418 | return ret; |
Konstantin Dorfman | 98377d3 | 2015-02-25 10:09:41 +0200 | [diff] [blame] | 3419 | } |
| 3420 | |
| 3421 | static int sdhci_msm_resume(struct device *dev) |
| 3422 | { |
| 3423 | struct sdhci_host *host = dev_get_drvdata(dev); |
| 3424 | struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); |
| 3425 | struct sdhci_msm_host *msm_host = pltfm_host->priv; |
| 3426 | int ret = 0; |
Konstantin Dorfman | ddab0cc | 2015-02-25 16:23:50 +0200 | [diff] [blame] | 3427 | ktime_t start = ktime_get(); |
Konstantin Dorfman | 98377d3 | 2015-02-25 10:09:41 +0200 | [diff] [blame] | 3428 | |
| 3429 | if (gpio_is_valid(msm_host->pdata->status_gpio) && |
| 3430 | (msm_host->mmc->slot.cd_irq >= 0)) |
| 3431 | enable_irq(msm_host->mmc->slot.cd_irq); |
| 3432 | |
| 3433 | if (pm_runtime_suspended(dev)) { |
| 3434 | pr_debug("%s: %s: runtime suspended, defer system resume\n", |
| 3435 | mmc_hostname(host->mmc), __func__); |
| 3436 | goto out; |
| 3437 | } |
| 3438 | |
Konstantin Dorfman | ddab0cc | 2015-02-25 16:23:50 +0200 | [diff] [blame] | 3439 | ret = sdhci_msm_runtime_resume(dev); |
Konstantin Dorfman | 98377d3 | 2015-02-25 10:09:41 +0200 | [diff] [blame] | 3440 | out: |
Konstantin Dorfman | ddab0cc | 2015-02-25 16:23:50 +0200 | [diff] [blame] | 3441 | trace_sdhci_msm_resume(mmc_hostname(host->mmc), ret, |
| 3442 | ktime_to_us(ktime_sub(ktime_get(), start))); |
Konstantin Dorfman | 98377d3 | 2015-02-25 10:09:41 +0200 | [diff] [blame] | 3443 | return ret; |
| 3444 | } |
| 3445 | |
| 3446 | static const struct dev_pm_ops sdhci_msm_pmops = { |
| 3447 | SET_SYSTEM_SLEEP_PM_OPS(sdhci_msm_suspend, sdhci_msm_resume) |
| 3448 | SET_RUNTIME_PM_OPS(sdhci_msm_runtime_suspend, sdhci_msm_runtime_resume, |
| 3449 | NULL) |
| 3450 | }; |
| 3451 | |
| 3452 | #define SDHCI_MSM_PMOPS (&sdhci_msm_pmops) |
| 3453 | |
| 3454 | #else |
| 3455 | #define SDHCI_MSM_PMOPS NULL |
| 3456 | #endif |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 3457 | static const struct of_device_id sdhci_msm_dt_match[] = { |
| 3458 | {.compatible = "qcom,sdhci-msm"}, |
Venkat Gopalakrishnan | 272ba40 | 2015-06-25 12:00:02 -0700 | [diff] [blame] | 3459 | {}, |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 3460 | }; |
| 3461 | MODULE_DEVICE_TABLE(of, sdhci_msm_dt_match); |
| 3462 | |
| 3463 | static struct platform_driver sdhci_msm_driver = { |
| 3464 | .probe = sdhci_msm_probe, |
| 3465 | .remove = sdhci_msm_remove, |
| 3466 | .driver = { |
| 3467 | .name = "sdhci_msm", |
| 3468 | .owner = THIS_MODULE, |
| 3469 | .of_match_table = sdhci_msm_dt_match, |
Konstantin Dorfman | 98377d3 | 2015-02-25 10:09:41 +0200 | [diff] [blame] | 3470 | .pm = SDHCI_MSM_PMOPS, |
Asutosh Das | 0ef2481 | 2012-12-18 16:14:02 +0530 | [diff] [blame] | 3471 | }, |
| 3472 | }; |
| 3473 | |
| 3474 | module_platform_driver(sdhci_msm_driver); |
| 3475 | |
| 3476 | MODULE_DESCRIPTION("Qualcomm Technologies, Inc. Secure Digital Host Controller Interface driver"); |
| 3477 | MODULE_LICENSE("GPL v2"); |