blob: 45c87c10faf4d89e2325e9a8de9d74fbada1b279 [file] [log] [blame]
Channagoud Kadabid3178012015-02-03 13:22:59 -08001/* Copyright (c) 2013-2015, The Linux Foundation. All rights reserved.
Channagoud Kadabiafb8e172013-05-23 13:55:47 -07002 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <platform/iomap.h>
30#include <platform/irqs.h>
31#include <platform/interrupts.h>
32#include <platform/timer.h>
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -070033#include <sys/types.h>
Channagoud Kadabiafb8e172013-05-23 13:55:47 -070034#include <target.h>
35#include <string.h>
36#include <stdlib.h>
37#include <bits.h>
38#include <debug.h>
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -070039#include <mmc.h>
Channagoud Kadabiafb8e172013-05-23 13:55:47 -070040#include <sdhci.h>
41#include <sdhci_msm.h>
42
Channagoud Kadabie106d1f2014-04-25 18:26:26 -070043
44#define MX_DRV_SUPPORTED_HS200 3
Channagoud Kadabi0b028662015-03-17 11:54:57 -070045static bool attempt_cdr_unlock;
Channagoud Kadabie106d1f2014-04-25 18:26:26 -070046
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -070047/* Known data stored in the card & read during tuning
48 * process. 64 bytes for 4bit bus width & 128 bytes
49 * of data for 8 bit bus width.
50 * These values are derived from HPG
51 */
52static const uint32_t tuning_block_64[] = {
53 0x00FF0FFF, 0xCCC3CCFF, 0xFFCC3CC3, 0xEFFEFFFE,
54 0xDDFFDFFF, 0xFBFFFBFF, 0xFF7FFFBF, 0xEFBDF777,
55 0xF0FFF0FF, 0x3CCCFC0F, 0xCFCC33CC, 0xEEFFEFFF,
56 0xFDFFFDFF, 0xFFBFFFDF, 0xFFF7FFBB, 0xDE7B7FF7
57};
58
59static const uint32_t tuning_block_128[] = {
60 0xFF00FFFF, 0x0000FFFF, 0xCCCCFFFF, 0xCCCC33CC,
61 0xCC3333CC, 0xFFFFCCCC, 0xFFFFEEFF, 0xFFEEEEFF,
62 0xFFDDFFFF, 0xDDDDFFFF, 0xBBFFFFFF, 0xBBFFFFFF,
63 0xFFFFFFBB, 0xFFFFFF77, 0x77FF7777, 0xFFEEDDBB,
64 0x00FFFFFF, 0x00FFFFFF, 0xCCFFFF00, 0xCC33CCCC,
65 0x3333CCCC, 0xFFCCCCCC, 0xFFEEFFFF, 0xEEEEFFFF,
66 0xDDFFFFFF, 0xDDFFFFFF, 0xFFFFFFDD, 0xFFFFFFBB,
67 0xFFFFBBBB, 0xFFFF77FF, 0xFF7777FF, 0xEEDDBB77
68};
Channagoud Kadabiafb8e172013-05-23 13:55:47 -070069
70/*
71 * Function: sdhci int handler
72 * Arg : MSM specific data for sdhci
73 * Return : 0
74 * Flow: : 1. Read the power control mask register
75 * 2. Check if bus is ON
76 * 3. Write success to ack regiser
77 * Details : This is power control interrupt handler.
78 * Once we receive the interrupt, we will ack the power control
79 * register that we have successfully completed pmic transactions
80 */
81static enum handler_return sdhci_int_handler(struct sdhci_msm_data *data)
82{
83 uint32_t ack;
84 uint32_t status;
85
86 /*
87 * Read the mask register to check if BUS & IO level
88 * interrupts are enabled
89 */
90 status = readl(data->pwrctl_base + SDCC_HC_PWRCTL_MASK_REG);
91
92 if (status & (SDCC_HC_BUS_ON | SDCC_HC_BUS_OFF))
93 ack = SDCC_HC_BUS_ON_OFF_SUCC;
94 if (status & (SDCC_HC_IO_SIG_LOW | SDCC_HC_IO_SIG_HIGH))
95 ack |= SDCC_HC_IO_SIG_SUCC;
96
97 /* Write success to power control register */
98 writel(ack, (data->pwrctl_base + SDCC_HC_PWRCTL_CTL_REG));
99
100 event_signal(data->sdhc_event, false);
101
102 return 0;
103}
104
105/*
106 * Function: sdhci clear pending interrupts
107 * Arg : MSM specific data for sdhci
108 * Return : None
109 * Flow: : Clear pending interrupts
110 */
111static void sdhci_clear_power_ctrl_irq(struct sdhci_msm_data *data)
112{
113 uint32_t irq_ctl;
114 uint32_t irq_stat;
115
116 /*
117 * Read the power control status register to know
118 * the status of BUS & IO_HIGH_V
119 */
120 irq_stat = readl(data->pwrctl_base + SDCC_HC_PWRCTL_STATUS_REG);
121
122 /* Clear the power control status */
123 writel(irq_stat, (data->pwrctl_base + SDCC_HC_PWRCTL_CLEAR_REG));
124
125 /*
126 * Handle the pending irq by ack'ing the bus & IO switch
127 */
128 irq_ctl = readl(data->pwrctl_base + SDCC_HC_PWRCTL_CTL_REG);
129
130 if (irq_stat & (SDCC_HC_BUS_ON | SDCC_HC_BUS_OFF))
131 irq_ctl |= SDCC_HC_BUS_ON_OFF_SUCC;
132 if (irq_stat & (SDCC_HC_IO_SIG_LOW | SDCC_HC_IO_SIG_HIGH))
133 irq_ctl |= SDCC_HC_IO_SIG_SUCC;
134
135 writel(irq_ctl, (data->pwrctl_base + SDCC_HC_PWRCTL_CTL_REG));
136}
137
138/*
139 * Function: sdhci msm init
140 * Arg : MSM specific config data for sdhci
141 * Return : None
142 * Flow: : Enable sdhci mode & do msm specific init
143 */
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700144void sdhci_msm_init(struct sdhci_host *host, struct sdhci_msm_data *config)
Channagoud Kadabiafb8e172013-05-23 13:55:47 -0700145{
Channagoud Kadabi17e69972014-10-13 11:42:24 -0700146 uint32_t io_switch;
Channagoud Kadabi0e657d02014-11-06 18:08:57 -0800147 uint32_t caps = 0;
148 uint32_t version;
Channagoud Kadabi17e69972014-10-13 11:42:24 -0700149
Channagoud Kadabid10f6182013-12-30 11:51:53 -0800150 /* Disable HC mode */
151 RMWREG32((config->pwrctl_base + SDCC_MCI_HC_MODE), SDHCI_HC_START_BIT, SDHCI_HC_WIDTH, 0);
152
153 /* Core power reset */
154 RMWREG32((config->pwrctl_base + SDCC_MCI_POWER), CORE_SW_RST_START, CORE_SW_RST_WIDTH, 1);
155
156 /* Wait for the core power reset to complete*/
157 mdelay(1);
158
Channagoud Kadabiafb8e172013-05-23 13:55:47 -0700159 /* Enable sdhc mode */
Channagoud Kadabi946848d2013-10-02 12:09:37 -0700160 RMWREG32((config->pwrctl_base + SDCC_MCI_HC_MODE), SDHCI_HC_START_BIT, SDHCI_HC_WIDTH, SDHCI_HC_MODE_EN);
Channagoud Kadabiafb8e172013-05-23 13:55:47 -0700161
Channagoud Kadabie632e252014-03-31 15:26:00 -0700162 /* Set the FF_CLK_SW_RST_DIS to 1 */
163 RMWREG32((config->pwrctl_base + SDCC_MCI_HC_MODE), FF_CLK_SW_RST_DIS_START, FF_CLK_SW_RST_DIS_WIDTH, 1);
164
Channagoud Kadabiafb8e172013-05-23 13:55:47 -0700165 /*
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700166 * Reset the controller
167 */
168 sdhci_reset(host, SDHCI_SOFT_RESET);
169
170 /*
Channagoud Kadabi17e69972014-10-13 11:42:24 -0700171 * Some platforms have same SDC instance shared between emmc & sd card.
172 * For such platforms the emmc IO voltage has to be switched from 3.3 to
173 * 1.8 for the contoller to work with emmc.
174 */
175
176 if(config->use_io_switch)
177 {
178 io_switch = REG_READ32(host, SDCC_VENDOR_SPECIFIC_FUNC);
179 io_switch |= HC_IO_PAD_PWR_SWITCH | HC_IO_PAD_PWR_SWITCH_EN;
180 REG_WRITE32(host, io_switch, SDCC_VENDOR_SPECIFIC_FUNC);
181 }
182
183 /*
Channagoud Kadabiafb8e172013-05-23 13:55:47 -0700184 * CORE_SW_RST may trigger power irq if previous status of PWRCTL
185 * was either BUS_ON or IO_HIGH. So before we enable the power irq
186 * interrupt in GIC (by registering the interrupt handler), we need to
187 * ensure that any pending power irq interrupt status is acknowledged
188 * otherwise power irq interrupt handler would be fired prematurely.
189 */
190 sdhci_clear_power_ctrl_irq(config);
191
192 /*
193 * Register the interrupt handler for pwr irq
194 */
vijay kumar4f4405f2014-08-08 11:49:53 +0530195 register_int_handler(config->pwr_irq, (int_handler)sdhci_int_handler, (void *)config);
Channagoud Kadabiafb8e172013-05-23 13:55:47 -0700196
197 unmask_interrupt(config->pwr_irq);
198
199 /* Enable pwr control interrupt */
200 writel(SDCC_HC_PWR_CTRL_INT, (config->pwrctl_base + SDCC_HC_PWRCTL_MASK_REG));
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700201
Channagoud Kadabi0e657d02014-11-06 18:08:57 -0800202 version = readl(host->msm_host->pwrctl_base + MCI_VERSION);
203
204 host->major = (version & CORE_VERSION_MAJOR_MASK) >> CORE_VERSION_MAJOR_SHIFT;
205 host->minor = (version & CORE_VERSION_MINOR_MASK);
206
207 /*
208 * For SDCC5 the capabilities registers does not have voltage advertised
209 * Override the values using SDCC_HC_VENDOR_SPECIFIC_CAPABILITIES0
210 */
211 if (host->major >= 1 && host->minor != 0x11 && host->minor != 0x12)
212 {
213 caps = REG_READ32(host, SDHCI_CAPS_REG1);
214
215 if (config->slot == 0x1)
216 REG_WRITE32(host, (caps | SDHCI_1_8_VOL_MASK), SDCC_HC_VENDOR_SPECIFIC_CAPABILITIES0);
217 else
218 REG_WRITE32(host, (caps | SDHCI_3_0_VOL_MASK), SDCC_HC_VENDOR_SPECIFIC_CAPABILITIES0);
219 }
220
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700221 config->tuning_done = false;
222 config->calibration_done = false;
223 host->tuning_in_progress = false;
224}
225
226/*
227 * Function: sdhci msm set mci clk
228 * Arg : Host structure
229 * Return : None
230 * Flow: : Set HC_SELECT & HC_SELECT_EN for hs400
231 */
232void sdhci_msm_set_mci_clk(struct sdhci_host *host)
233{
234 struct sdhci_msm_data *msm_host;
235
236 msm_host = host->msm_host;
237
238 if (host->timing == MMC_HS400_TIMING)
239 {
240 /*
241 * If the current tuning mode is HS400 then we should set the MCLK to run
242 * the clock @ MCLK/2. Also set HS400 mode in SELECT_IN of vendor specific
243 * register
244 */
245 REG_RMW32(host, SDCC_VENDOR_SPECIFIC_FUNC, SDCC_HC_MCLK_HS400_START, SDCC_HC_MCLK_HS400_WIDTH, SDCC_HC_MCLK_SEL_HS400);
246
247 /* Enable HS400 mode from HC_SELECT_IN bit of VENDOR_SPEC register
248 * As the SDCC spec does not have matching mode for HS400
249 */
250 if (msm_host->tuning_done && !msm_host->calibration_done)
251 {
252 REG_RMW32(host, SDCC_VENDOR_SPECIFIC_FUNC, SDCC_HC_MCLK_SEL_IN_START, SDCC_HC_MCLK_SEL_IN_WIDTH, SDCC_HC_MCLK_SEL_IN_HS400);
253 REG_RMW32(host, SDCC_VENDOR_SPECIFIC_FUNC, SDCC_HC_MCLK_SEL_IN_EN_START, SDCC_HC_MCLK_SEL_IN_EN_WIDTH, SDCC_HC_MCLK_SEL_IN_EN);
254 }
255 }
256 else
257 {
258 /*
259 * Set 0x0 mode in SELECT_IN of vendor specific register so that the
260 * host control2 register settings from sdhc spec are used for
261 * speed mode
262 */
263 REG_RMW32(host, SDCC_VENDOR_SPECIFIC_FUNC, SDCC_HC_MCLK_SEL_IN_START, SDCC_HC_MCLK_SEL_IN_WIDTH, 0x0);
264 REG_RMW32(host, SDCC_VENDOR_SPECIFIC_FUNC, SDCC_HC_MCLK_SEL_IN_EN_START, SDCC_HC_MCLK_SEL_IN_EN_WIDTH, 0x0);
265 }
266}
267
268/*
269 * Set the value based on sdcc clock frequency
270 */
271static void msm_set_dll_freq(struct sdhci_host *host)
272{
273 uint32_t reg_val = 0;
274
275 /* Set clock freq value based on clock range */
276 if (host->cur_clk_rate <= 112000000)
277 reg_val = 0x0;
278 else if (host->cur_clk_rate <= 125000000)
279 reg_val = 0x1;
280 else if (host->cur_clk_rate <= 137000000)
281 reg_val = 0x2;
282 else if (host->cur_clk_rate <= 150000000)
283 reg_val = 0x3;
284 else if (host->cur_clk_rate <= 162000000)
285 reg_val = 0x4;
286 else if (host->cur_clk_rate <= 175000000)
287 reg_val = 0x5;
288 else if (host->cur_clk_rate <= 187000000)
289 reg_val = 0x6;
290 else if (host->cur_clk_rate <= 200000000)
291 reg_val = 0x7;
292
Channagoud Kadabie632e252014-03-31 15:26:00 -0700293 DBG("\n %s: DLL freq: 0x%08x\n", __func__, reg_val);
294
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700295 REG_RMW32(host, SDCC_DLL_CONFIG_REG, SDCC_DLL_CONFIG_MCLK_START, SDCC_DLL_CONFIG_MCLK_WIDTH, reg_val);
296}
297
Channagoud Kadabid3178012015-02-03 13:22:59 -0800298static void sdhci_dll_clk_enable(struct sdhci_host *host, int enable)
299{
300 if (enable)
301 {
302 REG_WRITE32(host, (REG_READ32(host, SDCC_HC_REG_DLL_CONFIG_2) & ~SDCC_DLL_CLOCK_DISABLE), SDCC_HC_REG_DLL_CONFIG_2);
303 }
304 else
305 {
306 REG_WRITE32(host, (REG_READ32(host, SDCC_DLL_CONFIG_REG) & ~SDCC_DLL_CLK_OUT_EN), SDCC_DLL_CONFIG_REG);
307 REG_WRITE32(host, (REG_READ32(host, SDCC_HC_REG_DLL_CONFIG_2) | SDCC_DLL_CLOCK_DISABLE), SDCC_HC_REG_DLL_CONFIG_2);
308 }
309}
310
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700311/* Initialize DLL (Programmable Delay Line) */
Channagoud Kadabie632e252014-03-31 15:26:00 -0700312static uint32_t sdhci_msm_init_dll(struct sdhci_host *host)
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700313{
314 uint32_t pwr_save = 0;
Channagoud Kadabie632e252014-03-31 15:26:00 -0700315 uint32_t timeout = SDHCI_DLL_TIMEOUT;
Channagoud Kadabid3178012015-02-03 13:22:59 -0800316 uint32_t dll_cfg2;
317 uint32_t mclk_clk_freq = 0;
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700318
319 pwr_save = REG_READ32(host, SDCC_VENDOR_SPECIFIC_FUNC) & SDCC_DLL_PWR_SAVE_EN;
320
Channagoud Kadabid3178012015-02-03 13:22:59 -0800321 /* Dll sequence needs additional steps for sdcc core version 42 */
322 if (host->major == 1 && host->minor >= 0x42)
323 {
324 /* Disable DLL clock before configuring */
325 sdhci_dll_clk_enable(host, 0);
326 }
327
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700328 /* PWR SAVE to 0 */
329 if (pwr_save)
330 REG_WRITE32(host, (REG_READ32(host, SDCC_VENDOR_SPECIFIC_FUNC) & ~SDCC_DLL_PWR_SAVE_EN), SDCC_VENDOR_SPECIFIC_FUNC);
331 /* Set DLL_RST to 1 */
332 REG_WRITE32(host, (REG_READ32(host, SDCC_DLL_CONFIG_REG) | SDCC_DLL_RESET_EN), SDCC_DLL_CONFIG_REG);
333 /* Set DLL_PDN to 1 */
334 REG_WRITE32(host, (REG_READ32(host, SDCC_DLL_CONFIG_REG) | SDCC_DLL_PDN_EN), SDCC_DLL_CONFIG_REG);
335
336 /* Set frequency field in DLL_CONFIG */
337 msm_set_dll_freq(host);
338
Channagoud Kadabid3178012015-02-03 13:22:59 -0800339 /* Configure the mclk freq based on the current clock rate
340 * and fll cycle count as per hpg section 15.2.2
341 */
342 if (host->major == 1 && host->minor >= 0x42)
343 {
344 dll_cfg2 = REG_READ32(host, SDCC_HC_REG_DLL_CONFIG_2);
345 if (dll_cfg2 & SDCC_FLL_CYCLE_CNT)
346 mclk_clk_freq = (host->cur_clk_rate / TCXO_FREQ) * 8;
347 else
348 mclk_clk_freq = (host->cur_clk_rate / TCXO_FREQ) * 4;
349
350 REG_WRITE32(host, ((REG_READ32(host, SDCC_HC_REG_DLL_CONFIG_2) & ~(0xFF << 10)) | (mclk_clk_freq << 10)), SDCC_HC_REG_DLL_CONFIG_2);
351
352 udelay(5);
353 }
354
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700355 /* Write 0 to DLL_RST */
356 REG_WRITE32(host, (REG_READ32(host, SDCC_DLL_CONFIG_REG) & ~SDCC_DLL_RESET_EN), SDCC_DLL_CONFIG_REG);
357 /* Write 0 to DLL_PDN */
358 REG_WRITE32(host, (REG_READ32(host, SDCC_DLL_CONFIG_REG) & ~SDCC_DLL_PDN_EN), SDCC_DLL_CONFIG_REG);
Channagoud Kadabid3178012015-02-03 13:22:59 -0800359
360 /* Set the mclk clock and enable the dll clock */
361 if (host->major == 1 && host->minor >= 0x42)
362 {
363 msm_set_dll_freq(host);
364 sdhci_dll_clk_enable(host, 1);
365 }
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700366 /* Write 1 to DLL_EN */
367 REG_WRITE32(host, (REG_READ32(host, SDCC_DLL_CONFIG_REG) | SDCC_DLL_EN), SDCC_DLL_CONFIG_REG);
368 /* Write 1 to CLK_OUT_EN */
369 REG_WRITE32(host, (REG_READ32(host, SDCC_DLL_CONFIG_REG) | SDCC_DLL_CLK_OUT_EN), SDCC_DLL_CONFIG_REG);
Channagoud Kadabie632e252014-03-31 15:26:00 -0700370 /* Wait for DLL_LOCK in DLL_STATUS register, wait time 50us */
Channagoud Kadabi96622212014-07-30 12:13:28 -0700371 while(!((REG_READ32(host, SDCC_REG_DLL_STATUS)) & SDCC_DLL_LOCK_STAT))
Channagoud Kadabie632e252014-03-31 15:26:00 -0700372 {
373 udelay(1);
374 timeout--;
375 if (!timeout)
376 {
377 dprintf(CRITICAL, "%s: Failed to get DLL lock: 0x%08x\n", __func__, REG_READ32(host, SDCC_REG_DLL_STATUS));
378 return 1;
379 }
380 }
381
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700382 /* Set the powersave back on */
383 if (pwr_save)
Channagoud Kadabi7bcf6252014-05-14 18:28:13 -0700384 REG_WRITE32(host, (REG_READ32(host, SDCC_VENDOR_SPECIFIC_FUNC) | SDCC_DLL_PWR_SAVE_EN), SDCC_VENDOR_SPECIFIC_FUNC);
Channagoud Kadabie632e252014-03-31 15:26:00 -0700385
386 return 0;
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700387}
388
Channagoud Kadabidd8a7342014-07-09 10:35:01 -0700389void sdhci_msm_toggle_cdr(struct sdhci_host *host, bool enable)
390{
391 uint32_t core_cfg;
392
393 core_cfg = REG_READ32(host, SDCC_DLL_CONFIG_REG);
394
395 if (enable)
396 {
397 core_cfg |= SDCC_DLL_CDR_EN;
398 }
399 else
400 {
401 core_cfg &= ~SDCC_DLL_CDR_EN;
402 }
403
404 REG_WRITE32(host, core_cfg, SDCC_DLL_CONFIG_REG);
405}
406
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700407/* Configure DLL with delay value based on 'phase' */
Channagoud Kadabie632e252014-03-31 15:26:00 -0700408static uint32_t sdhci_msm_config_dll(struct sdhci_host *host, uint32_t phase)
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700409{
410 uint32_t core_cfg = 0;
Channagoud Kadabie632e252014-03-31 15:26:00 -0700411 uint32_t timeout = SDHCI_DLL_TIMEOUT;
412
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700413 /* Gray code values from SWI */
414 uint32_t gray_code [] = { 0x0, 0x1, 0x3, 0x2, 0x6, 0x7, 0x5, 0x4, 0xC, 0xD, 0xF, 0xE, 0xA, 0xB, 0x9, 0x8 };
415
416 /* set CDR_EN & CLK_OUT_EN to 0 and
417 * CDR_EXT_EN & DLL_EN to 1*/
418 core_cfg = REG_READ32(host, SDCC_DLL_CONFIG_REG);
419 core_cfg &= ~(SDCC_DLL_CDR_EN | SDCC_DLL_CLK_OUT_EN);
420 core_cfg |= (SDCC_DLL_CDR_EXT_EN | SDCC_DLL_EN);
421 REG_WRITE32(host, core_cfg, SDCC_DLL_CONFIG_REG);
422
423 /* Wait until CLK_OUT_EN is 0 */
424 while(REG_READ32(host, SDCC_DLL_CONFIG_REG) & SDCC_DLL_CLK_OUT_EN);
425
426 REG_RMW32(host, SDCC_DLL_CONFIG_REG, SDCC_DLL_GRAY_CODE_START, SDCC_DLL_GRAY_CODE_WIDTH, gray_code[phase]);
427
428 REG_WRITE32(host, (REG_READ32(host, SDCC_DLL_CONFIG_REG) | SDCC_DLL_CLK_OUT_EN), SDCC_DLL_CONFIG_REG);
429
Channagoud Kadabie632e252014-03-31 15:26:00 -0700430 /* Wait until CLK_OUT_EN is 1, wait time 50us */
431 while(!(REG_READ32(host, SDCC_DLL_CONFIG_REG) & SDCC_DLL_CLK_OUT_EN))
432 {
433 timeout--;
434 udelay(1);
435 if (!timeout)
436 {
437 dprintf(CRITICAL, "%s: clk_out_en timed out: %08x\n", __func__, REG_READ32(host, SDCC_DLL_CONFIG_REG));
438 return 1;
439 }
440 }
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700441
442 core_cfg = REG_READ32(host, SDCC_DLL_CONFIG_REG);
443
444 core_cfg |= SDCC_DLL_CDR_EN;
445 core_cfg &= ~SDCC_DLL_CDR_EXT_EN;
446
447 REG_WRITE32(host, core_cfg, SDCC_DLL_CONFIG_REG);
448
Channagoud Kadabie632e252014-03-31 15:26:00 -0700449 return 0;
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700450}
451
452/*
453 * Find the right tuning delay, this function finds the largest
454 * consecutive sequence of phases & then selects the 3/4 th of
455 * the range which has max entries
456 * For eg: If we get the following sequence in phase_table[]
457 * (A) phase_table[] = 0x1, 0x2, 0x3, 0x4 , 0x5
458 * (B) phase_table[] = 0xA, 0xB, 0xC
459 * In the above case the (A) has maximum consecutive entries with '5' entries
460 * So delay would be phase_table[(0x5 * 3) / 4] = 0x3
461 */
462static int sdhci_msm_find_appropriate_phase(struct sdhci_host *host,
463 uint32_t *phase_table,
464 uint32_t total_phases)
465{
466 int sub_phases[MAX_PHASES][MAX_PHASES]={{0}};
vijay kumar4f4405f2014-08-08 11:49:53 +0530467 uint32_t phases_per_row[MAX_PHASES] = {0};
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700468 uint32_t i,j;
469 int selected_phase = 0;
470 uint32_t row_index = 0;
471 uint32_t col_index = 0;
472 uint32_t phase_15_row_idx = 0;
473 uint32_t phases_0_row_idx = 0;
474 uint32_t max_phases_3_4_idx = 0;
475 uint32_t max_phases = 0;
476 uint32_t max_phases_row = 0;
477 bool found_loop = false;
478
479 if (!phase_table[0] && phase_table[total_phases - 1] == (MAX_PHASES - 1))
480 found_loop = true;
481
482 for (i = 0; i < total_phases; i++)
483 {
484 /* Break the phase table entries into different sub arrays based
485 * on the consecutive entries. Each row will have one sub array
486 * of consecutive entries.
487 * for eg: phase_table [] = { 0x0, 0x1, 0x2, 0xA, 0xB}
488 * sub_phases [0][] = { 0x0, 0x1, 0x2}
489 * sub_phases [1][] = { 0xA, 0xB}
490 */
491 sub_phases[row_index][col_index] = phase_table[i];
492 phases_per_row[row_index]++;
493 col_index++;
494
495 /* If we are at the last phase no need to check further */
496 if ((i + 1) == total_phases)
497 break;
498
499 /* If phase_table does not have consecutive entries, move to next entry */
500 if (phase_table[i]+1 != phase_table[i+1])
501 {
502 row_index++;
503 col_index = 0;
504 }
505 }
506
507 if (found_loop && total_phases < MAX_PHASES)
508 {
509 /* For consecutive entries we need to consider loops.
510 * If the phase_table contains 0x0 & 0xF then we have
511 * a loop, the number after 0xF in the sequence would be
512 * 0x0.
513 * for eg:
514 * phase_table = { 0x0, 0x1, 0x2, 0xD, 0xE, 0xF }
515 * then
516 * sub_phase [0][] = { 0x0, 0x1, 0x2 }
517 * sub_phase [1][] = { 0xD, 0xE, 0xF }
518 * Since we have a loop here, we need to merge the sub arrays as:
519 * sub_phase [1][] = { 0xD, 0xE, 0xF, 0x0, 0x1, 0x2 }
520 */
521
522 /* The entry 0xF will always be in the last row
523 * and entry 0x0 will always be in the first row
524 */
525 phase_15_row_idx = row_index;
526 j = 0;
527 for (i = phases_per_row[phase_15_row_idx] ; i < MAX_PHASES ; i++)
528 {
529 sub_phases[phase_15_row_idx][i] = sub_phases[phases_0_row_idx][j];
530 if (++j >= phases_per_row[phases_0_row_idx])
531 break;
532 }
533
534 /* Update the number of entries for the sub_phase after the merger */
535 phases_per_row[phase_15_row_idx] = phases_per_row[phase_15_row_idx] + phases_per_row[phases_0_row_idx];
536 phases_per_row[phases_0_row_idx] = 0;
537 }
538
539 for (i = 0 ; i <= row_index; i++)
540 {
541 if (phases_per_row[i] > max_phases)
542 {
543 max_phases = phases_per_row[i];
544 max_phases_row = i;
545 }
546 }
547
548 max_phases_3_4_idx = (max_phases * 3) / 4;
549 if (max_phases_3_4_idx)
550 max_phases_3_4_idx--;
551
552 selected_phase = sub_phases[max_phases_row][max_phases_3_4_idx];
553
554 return selected_phase;
555}
556
Channagoud Kadabi756e1e32014-06-05 13:00:55 -0700557static uint32_t sdhci_msm_cm_dll_sdc4_calibration(struct sdhci_host *host)
558{
559 uint32_t timeout = 0;
560
561 DBG("\n CM_DLL_SDC4 Calibration Start\n");
562
Channagoud Kadabi355f1fa2014-10-08 19:57:00 -0700563 /*1.Write the DDR config value to SDCC_HC_REG_DDR_CONFIG register*/
564 REG_WRITE32(host, target_ddr_cfg_val(), SDCC_HC_REG_DDR_CONFIG);
Channagoud Kadabi756e1e32014-06-05 13:00:55 -0700565
566 /*2. Write DDR_CAL_EN to '1' */
567 REG_WRITE32(host, (REG_READ32(host, SDCC_HC_REG_DLL_CONFIG_2) | DDR_CAL_EN), SDCC_HC_REG_DLL_CONFIG_2);
568
569 /*3. Wait for DLL_LOCK for hs400 to be set */
570 timeout = DDR_CAL_TIMEOUT_MAX;
571 while (!(REG_READ32(host, SDCC_REG_DLL_STATUS) & DDR_DLL_LOCK_JDR))
572 {
573 timeout--;
574 mdelay(1);
575 if (!timeout)
576 {
577 dprintf(CRITICAL, "Error: DLL lock for hs400 operation is not set\n");
578 return 1;
579 }
580 }
581
582 /*4. Set powersave dll */
583 REG_WRITE32(host, (REG_READ32(host, SDCC_HC_VENDOR_SPECIFIC_FUNC3) | PWRSAVE_DLL), SDCC_HC_VENDOR_SPECIFIC_FUNC3);
584
585 DBG("\n CM_DLL_SDC4 Calibration Done\n");
586
587 return 0;
588}
589
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700590static uint32_t sdhci_msm_cdclp533_calibration(struct sdhci_host *host)
591{
592 uint32_t timeout;
593 uint32_t cdc_err;
594
Channagoud Kadabie632e252014-03-31 15:26:00 -0700595 DBG("\n CDCLP533 Calibration Start\n");
596
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700597 /* Write 0 to CDC_T4_DLY_SEL field in VENDOR_SPEC_DDR200_CFG */
598 REG_WRITE32(host, (REG_READ32(host, SDCC_CDC_DDR200_CFG) & ~CDC_T4_DLY_SEL), SDCC_CDC_DDR200_CFG);
599
600 /* Write 0 to START_CDC_TRAFFIC field in CORE_DDR200_CFG */
601 REG_WRITE32(host, (REG_READ32(host, SDCC_CDC_DDR200_CFG) & ~START_CDC_TRAFFIC), SDCC_CDC_DDR200_CFG);
602
603 /* Write 0 to CDC_SWITCH_BYPASS_OFF field in CSR_CDC_GEN_CFG */
604 REG_WRITE32(host, (REG_READ32(host, SDCC_VENDOR_SPEC_CSR_CDC_CFG) & ~CDC_SWITCH_BYPASS_OFF), SDCC_VENDOR_SPEC_CSR_CDC_CFG);
605
606 /* Write 1 to CDC_SWITCH_RC_EN field in CSR_CDC_GEN_CFG */
607 REG_WRITE32(host, (REG_READ32(host, SDCC_VENDOR_SPEC_CSR_CDC_CFG) | CDC_SWITCH_RC_EN), SDCC_VENDOR_SPEC_CSR_CDC_CFG);
608
609 /* Write 0 to START_CDC_TRAFFIC field in CORE_DDR200_CFG */
610 REG_WRITE32(host, (REG_READ32(host, SDCC_CDC_DDR200_CFG) & ~START_CDC_TRAFFIC), SDCC_CDC_DDR200_CFG);
611
612 /* Perform CDCLP533 initialization sequence
613 * SDCC_CSR_CDC_CTRL_CFG0 --> 0x11800EC
614 * SDCC_CSR_CDC_CTRL_CFG1 --> 0x3011111
615 * SDCC_CSR_CDC_CAL_TIMER_CFG0 --> 0x1201000
616 * SDCC_CSR_CDC_CAL_TIMER_CFG1 --> 0x4
617 * SDCC_CSR_CDC_REFCOUNT_CFG --> 0xCB732020
618 * SDCC_CSR_CDC_COARSE_CAL_CFG --> 0xB19
Channagoud Kadabi86afb382014-06-23 11:15:46 -0700619 * SDCC_CSR_CDC_DELAY_CFG --> 0x4E2
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700620 * SDCC_CDC_OFFSET_CFG --> 0x0
621 * SDCC_CDC_SLAVE_DDA_CFG --> 0x16334
622 */
623
624 REG_WRITE32(host, 0x11800EC, SDCC_CSR_CDC_CTRL_CFG0);
625 REG_WRITE32(host, 0x3011111, SDCC_CSR_CDC_CTRL_CFG1);
626 REG_WRITE32(host, 0x1201000, SDCC_CSR_CDC_CAL_TIMER_CFG0);
627 REG_WRITE32(host, 0x4, SDCC_CSR_CDC_CAL_TIMER_CFG1);
628 REG_WRITE32(host, 0xCB732020, SDCC_CSR_CDC_REFCOUNT_CFG);
629 REG_WRITE32(host, 0xB19, SDCC_CSR_CDC_COARSE_CAL_CFG);
Channagoud Kadabi86afb382014-06-23 11:15:46 -0700630 REG_WRITE32(host, 0x4E2, SDCC_CSR_CDC_DELAY_CFG);
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700631 REG_WRITE32(host, 0x0, SDCC_CDC_OFFSET_CFG);
632 REG_WRITE32(host, 0x16334, SDCC_CDC_SLAVE_DDA_CFG);
633
634 /* Write 1 to SW_TRIGGER_FULL_CALIB */
635 REG_WRITE32(host, (REG_READ32(host, SDCC_CSR_CDC_CTRL_CFG0) | CDC_SW_TRIGGER_FULL_CALIB), SDCC_CSR_CDC_CTRL_CFG0);
636
637 /* Write 0 to SW_TRIGGER_FULL_CALIB */
638 REG_WRITE32(host, (REG_READ32(host, SDCC_CSR_CDC_CTRL_CFG0) & ~CDC_SW_TRIGGER_FULL_CALIB), SDCC_CSR_CDC_CTRL_CFG0);
639
640 /* Write 1 to HW_AUTO_CAL_EN */
641 REG_WRITE32(host, (REG_READ32(host, SDCC_CSR_CDC_CTRL_CFG0) | CDC_HW_AUTO_CAL_EN), SDCC_CSR_CDC_CTRL_CFG0);
642
643 /* Write 1 to TIMER_ENA */
644 REG_WRITE32(host, (REG_READ32(host, SDCC_CSR_CDC_CAL_TIMER_CFG0) | CDC_TIMER_EN), SDCC_CSR_CDC_CAL_TIMER_CFG0);
645
646 /* Wait for CALIBRATION_DONE in CDC_STATUS */
Channagoud Kadabie632e252014-03-31 15:26:00 -0700647 timeout = CDC_STATUS_TIMEOUT;
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700648 while (!(REG_READ32(host, SDCC_CSR_CDC_STATUS0) & BIT(0)))
649 {
650 timeout--;
651 mdelay(1);
652 if (!timeout)
653 {
654 dprintf(CRITICAL, "Error: Calibration done in CDC status not set\n");
655 return 1;
656 }
657 }
658
659 cdc_err = REG_READ32(host, SDCC_CSR_CDC_STATUS0) & CSR_CDC_ERROR_MASK;
660 if (cdc_err)
661 {
662 dprintf(CRITICAL, "CDC error set during calibration: %x\n", cdc_err);
663 return 1;
664 }
665 /* Write 1 to START_CDC_TRAFFIC field in CORE_DDR200_CFG */
666 REG_WRITE32(host, (REG_READ32(host, SDCC_CDC_DDR200_CFG) | START_CDC_TRAFFIC), SDCC_CDC_DDR200_CFG);
667
Channagoud Kadabie632e252014-03-31 15:26:00 -0700668 DBG("\n CDCLP533 Calibration Done\n");
669
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700670 return 0;
671}
672
Channagoud Kadabi756e1e32014-06-05 13:00:55 -0700673
674static uint32_t sdhci_msm_hs400_calibration(struct sdhci_host *host)
675{
676 DBG("\n HS400 Calibration Start\n");
677
678 /* Reset & Initialize the DLL block */
679 if (sdhci_msm_init_dll(host))
680 return 1;
681
682 /* Write the save phase */
683 if (sdhci_msm_config_dll(host, host->msm_host->saved_phase))
684 return 1;
685
686 /* Write 1 to CMD_DAT_TRACK_SEL field in DLL_CONFIG */
687 REG_WRITE32(host, (REG_READ32(host, SDCC_DLL_CONFIG_REG) | CMD_DAT_TRACK_SEL), SDCC_DLL_CONFIG_REG);
688
689 if (host->use_cdclp533)
690 return sdhci_msm_cdclp533_calibration(host);
691 else
692 return sdhci_msm_cm_dll_sdc4_calibration(host);
693
694 DBG("\n HS400 Calibration Done\n");
695
696 return 0;
697}
698
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700699/*
700 * Function: sdhci msm execute tuning
701 * Arg : Host structure & bus width
702 * Return : 0 on Success, 1 on Failure
Channagoud Kadabi756e1e32014-06-05 13:00:55 -0700703 * Flow: : Execute Tuning sequence for HS200 and calibration for hs400
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700704 */
Channagoud Kadabie106d1f2014-04-25 18:26:26 -0700705uint32_t sdhci_msm_execute_tuning(struct sdhci_host *host, struct mmc_card *card, uint32_t bus_width)
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700706{
707 uint32_t *tuning_block;
708 uint32_t *tuning_data;
vijay kumar4f4405f2014-08-08 11:49:53 +0530709 uint32_t tuned_phases[MAX_PHASES] = {0};
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700710 uint32_t size;
711 uint32_t phase = 0;
712 uint32_t tuned_phase_cnt = 0;
Channagoud Kadabie106d1f2014-04-25 18:26:26 -0700713 uint8_t drv_type = 0;
714 bool drv_type_changed = false;
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700715 int ret = 0;
vijay kumar4f4405f2014-08-08 11:49:53 +0530716 uint32_t i;
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700717 struct sdhci_msm_data *msm_host;
718
719 msm_host = host->msm_host;
720
721 /* In Tuning mode */
722 host->tuning_in_progress = true;
723
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700724 if (bus_width == DATA_BUS_WIDTH_8BIT)
725 {
vijay kumar4f4405f2014-08-08 11:49:53 +0530726 tuning_block = (uint32_t *)tuning_block_128;
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700727 size = sizeof(tuning_block_128);
728 }
729 else
730 {
vijay kumar4f4405f2014-08-08 11:49:53 +0530731 tuning_block = (uint32_t *)tuning_block_64;
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700732 size = sizeof(tuning_block_64);
733 }
734
735 tuning_data = (uint32_t *) memalign(CACHE_LINE, ROUNDUP(size, CACHE_LINE));
736
737 ASSERT(tuning_data);
738
Channagoud Kadabi0b028662015-03-17 11:54:57 -0700739 /* Calibration for CDCLP533 needed for HS400 mode */
740 if (msm_host->tuning_done && !msm_host->calibration_done && host->timing == MMC_HS400_TIMING)
741 {
742 ret = sdhci_msm_hs400_calibration(host);
743 if (!ret)
744 msm_host->calibration_done = true;
745 goto out;
746 }
747
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700748 /* Reset & Initialize the DLL block */
Channagoud Kadabie632e252014-03-31 15:26:00 -0700749 if (sdhci_msm_init_dll(host))
750 {
751 ret = 1;
Channagoud Kadabi0b028662015-03-17 11:54:57 -0700752 goto out;
Channagoud Kadabie632e252014-03-31 15:26:00 -0700753 }
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700754
Channagoud Kadabie106d1f2014-04-25 18:26:26 -0700755retry_tuning:
756 tuned_phase_cnt = 0;
757 phase = 0;
Channagoud Kadabi0b028662015-03-17 11:54:57 -0700758 struct mmc_command cmd = {0};
Channagoud Kadabie106d1f2014-04-25 18:26:26 -0700759
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700760 while (phase < MAX_PHASES)
761 {
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700762 /* configure dll to set phase delay */
Channagoud Kadabie632e252014-03-31 15:26:00 -0700763 if (sdhci_msm_config_dll(host, phase))
764 {
765 ret = 1;
Channagoud Kadabi0b028662015-03-17 11:54:57 -0700766 goto out;
Channagoud Kadabie632e252014-03-31 15:26:00 -0700767 }
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700768
769 cmd.cmd_index = CMD21_SEND_TUNING_BLOCK;
770 cmd.argument = 0x0;
771 cmd.cmd_type = SDHCI_CMD_TYPE_NORMAL;
772 cmd.resp_type = SDHCI_CMD_RESP_R1;
773 cmd.trans_mode = SDHCI_MMC_READ;
774 cmd.data_present = 0x1;
775 cmd.data.data_ptr = tuning_data;
776 cmd.data.blk_sz = size;
777 cmd.data.num_blocks = 0x1;
778
779 /* send command */
780 if (!sdhci_send_command(host, &cmd) && !memcmp(tuning_data, tuning_block, size))
781 tuned_phases[tuned_phase_cnt++] = phase;
782
783 phase++;
784 }
785
Channagoud Kadabie106d1f2014-04-25 18:26:26 -0700786 /*
787 * Check if all the tuning phases passed */
788 if (tuned_phase_cnt == MAX_PHASES)
789 {
790 /* Change the driver type & rerun tuning */
Channagoud Kadabie4cab762014-07-08 17:26:06 -0700791 while(++drv_type <= MX_DRV_SUPPORTED_HS200)
Channagoud Kadabie106d1f2014-04-25 18:26:26 -0700792 {
793 drv_type_changed = mmc_set_drv_type(host, card, drv_type);
794 if (drv_type_changed)
795 {
796 goto retry_tuning;
797 }
798 }
799 }
800
801 /* Restore the driver strength to default value */
802 if (drv_type_changed)
803 mmc_set_drv_type(host, card, 0);
804
Channagoud Kadabia7a8cfa2015-03-05 23:20:41 -0800805 if (tuned_phase_cnt == MAX_PHASES)
Channagoud Kadabi0b028662015-03-17 11:54:57 -0700806 {
807 attempt_cdr_unlock = true;
Channagoud Kadabia7a8cfa2015-03-05 23:20:41 -0800808 dprintf(CRITICAL, "WARNING: All phase passed.The selected phase may not be optimal\n");
Channagoud Kadabi0b028662015-03-17 11:54:57 -0700809 }
Channagoud Kadabia7a8cfa2015-03-05 23:20:41 -0800810
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700811 /* Find the appropriate tuned phase */
812 if (tuned_phase_cnt)
813 {
Channagoud Kadabie632e252014-03-31 15:26:00 -0700814 DBG("\n Tuned phase\n");
815 for (i = 0 ; i < tuned_phase_cnt ; i++)
816 {
817 DBG("%d\t", tuned_phases[i]);
818 }
819
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700820 ret = sdhci_msm_find_appropriate_phase(host, tuned_phases, tuned_phase_cnt);
821
822 if (ret < 0)
823 {
824 dprintf(CRITICAL, "Failed in selecting the tuning phase\n");
825 ret = 1;
Channagoud Kadabi0b028662015-03-17 11:54:57 -0700826 goto out;
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700827 }
828
829 phase = (uint32_t) ret;
830 ret = 0;
831
Channagoud Kadabie632e252014-03-31 15:26:00 -0700832 DBG("\n: %s: Tuned Phase: 0x%08x\n", __func__, phase);
833
834 if (sdhci_msm_config_dll(host, phase))
Channagoud Kadabi0b028662015-03-17 11:54:57 -0700835 goto out;
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700836
837 /* Save the tuned phase */
838 host->msm_host->saved_phase = phase;
839 }
840 else
841 {
842 dprintf(CRITICAL, "Failed to get tuned phase\n");
843 ret = 1;
844 }
845
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700846out:
Channagoud Kadabi0b028662015-03-17 11:54:57 -0700847 /* If all the tuning phases passed, send CMD21 after enabling
848 * CDR to make sure right tuning phase is selected by CDR
849 */
850 if (attempt_cdr_unlock)
851 {
852 cmd.cmd_index = CMD21_SEND_TUNING_BLOCK;
853 cmd.argument = 0x0;
854 cmd.cmd_type = SDHCI_CMD_TYPE_NORMAL;
855 cmd.resp_type = SDHCI_CMD_RESP_R1;
856 cmd.trans_mode = SDHCI_MMC_READ;
857 cmd.data_present = 0x1;
858 cmd.data.data_ptr = tuning_data;
859 cmd.data.blk_sz = size;
860 cmd.data.num_blocks = 0x1;
861
862 /* send command */
863 if (!sdhci_send_command(host, &cmd))
864 {
865 DBG("\n: %s: Sending CMD21 after CDR enable with default phases fail\n", __func__);
866 }
867 }
868
869 free(tuning_data);
Channagoud Kadabi9b8f8fc2013-07-26 12:02:49 -0700870 /* Tuning done */
871 host->tuning_in_progress = false;
872 host->msm_host->tuning_done = true;
873 return ret;
Channagoud Kadabiafb8e172013-05-23 13:55:47 -0700874}
Channagoud Kadabi24146af2014-01-24 17:22:08 -0800875
876/*
877 * API to disable HC mode
878 */
879void sdhci_mode_disable(struct sdhci_host *host)
880{
881 /* Disable HC mode */
882 RMWREG32((host->msm_host->pwrctl_base + SDCC_MCI_HC_MODE), SDHCI_HC_START_BIT, SDHCI_HC_WIDTH, 0);
883}
884