blob: 52172b72a6d72778f2bbf6bd6b6e323bca26a60d [file] [log] [blame]
Channagoud Kadabid2137a62014-01-24 17:22:08 -08001/* Copyright (c) 2013-2014, 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#ifndef __SDHCI_MSM_H__
30#define __SDHCI_MSM_H__
31
32#include <kernel/event.h>
33
Channagoud Kadabicfeee4d2013-07-26 12:02:49 -070034#define SDHCI_HC_START_BIT 0x0
35#define SDHCI_HC_WIDTH 0x1
36
Channagoud Kadabi4ac38dd2013-12-30 11:51:53 -080037#define SDCC_MCI_POWER 0x0
38#define CORE_SW_RST_START 0x7
39#define CORE_SW_RST_WIDTH 0x1
40
Channagoud Kadabicfeee4d2013-07-26 12:02:49 -070041/* DLL & CDC registers
42 * DLL: Delay Line
43 * CDC: Calibrated Delay Circuit
44 */
45#define SDCC_DLL_CONFIG_REG 0x100
46#define SDCC_VENDOR_SPECIFIC_FUNC 0x10C
47#define SDCC_REG_DLL_STATUS 0x108
48#define SDCC_CDC_DDR200_CFG 0x184
49#define SDCC_VENDOR_SPEC_CSR_CDC_CFG 0x178
50#define SDCC_CSR_CDC_CTRL_CFG0 0x130
51#define SDCC_CSR_CDC_CTRL_CFG1 0x134
52#define SDCC_CSR_CDC_CAL_TIMER_CFG0 0x138
53#define SDCC_CSR_CDC_CAL_TIMER_CFG1 0x13C
54#define SDCC_CSR_CDC_REFCOUNT_CFG 0x140
55#define SDCC_CSR_CDC_COARSE_CAL_CFG 0x144
56#define SDCC_CSR_CDC_DELAY_CFG 0x150
57#define SDCC_CDC_OFFSET_CFG 0x14C
58#define SDCC_CDC_SLAVE_DDA_CFG 0x160
59#define SDCC_CSR_CDC_STATUS0 0x164
60
61/* DLL & CDC helper macros */
62#define SDCC_DLL_PWR_SAVE_EN BIT(1)
63#define SDCC_DLL_LOCK_STAT BIT(7)
64#define SDCC_DLL_EN BIT(16)
65#define SDCC_DLL_CDR_EN BIT(17)
66#define SDCC_DLL_CLK_OUT_EN BIT(18)
67#define SDCC_DLL_CDR_EXT_EN BIT(19)
68#define SDCC_DLL_PDN_EN BIT(29)
69#define SDCC_DLL_RESET_EN BIT(30)
70#define SDCC_DLL_CONFIG_MCLK_START 0x18
71#define SDCC_DLL_CONFIG_MCLK_WIDTH 0x3
72#define SDCC_DLL_GRAY_CODE_START 0x14
73#define SDCC_DLL_GRAY_CODE_WIDTH 0x4
74#define CMD_DAT_TRACK_SEL BIT(0)
75#define CDC_T4_DLY_SEL BIT(0)
76#define CDC_SWITCH_BYPASS_OFF BIT(0)
77#define CDC_SWITCH_RC_EN BIT(1)
78#define START_CDC_TRAFFIC BIT(6)
Channagoud Kadabifd96a0b2014-03-31 15:26:00 -070079#define FF_CLK_SW_RST_DIS_START 0xD
80#define FF_CLK_SW_RST_DIS_WIDTH 0x1
Channagoud Kadabicfeee4d2013-07-26 12:02:49 -070081#define CDC_SW_TRIGGER_FULL_CALIB BIT(16)
82#define CDC_HW_AUTO_CAL_EN BIT(17)
83#define CDC_TIMER_EN BIT(16)
84#define CSR_CDC_ERROR_MASK 0x7000000
85
86/* SDCC macros for HS400 */
87#define SDCC_HC_MCLK_SEL_HS400 0x3
88#define SDCC_HC_MCLK_HS400_START 0x8
89#define SDCC_HC_MCLK_HS400_WIDTH 0x2
90#define SDCC_HC_MCLK_SEL_IN_HS400 0x6
91#define SDCC_HC_MCLK_SEL_IN_DFLT 0x2
92#define SDCC_HC_MCLK_SEL_IN_UHS 0x4
93#define SDCC_HC_MCLK_SEL_IN_START 0x13
94#define SDCC_HC_MCLK_SEL_IN_WIDTH 0x3
95#define SDCC_HC_MCLK_SEL_IN_EN 0x1
96#define SDCC_HC_MCLK_SEL_IN_EN_START 0x12
97#define SDCC_HC_MCLK_SEL_IN_EN_WIDTH 0x1
98
99#define MAX_PHASES 16
100
Channagoud Kadabi3f428532014-01-28 21:33:34 -0800101/* SDCC version macros */
102#define MCI_VERSION 0x50
103#define CORE_VERSION_MAJOR_MASK 0xF0000000
104#define CORE_VERSION_MAJOR_SHIFT 0x1C
105
Channagoud Kadabifd96a0b2014-03-31 15:26:00 -0700106#define SDHCI_DLL_TIMEOUT 50
107#define CDC_STATUS_TIMEOUT 50
108
Channagoud Kadabiafb8e172013-05-23 13:55:47 -0700109struct sdhci_msm_data
110{
111 uint32_t pwrctl_base;
112 uint32_t pwr_irq;
Channagoud Kadabicfeee4d2013-07-26 12:02:49 -0700113 uint8_t tuning_done;
114 uint8_t calibration_done;
115 uint8_t saved_phase;
116 uint8_t slot;
Channagoud Kadabiafb8e172013-05-23 13:55:47 -0700117 event_t* sdhc_event;
118};
119
Channagoud Kadabicfeee4d2013-07-26 12:02:49 -0700120void sdhci_msm_init(struct sdhci_host *host, struct sdhci_msm_data *data);
121uint32_t sdhci_msm_execute_tuning(struct sdhci_host *host, uint32_t bus_width);
Channagoud Kadabid2137a62014-01-24 17:22:08 -0800122void sdhci_mode_disable(struct sdhci_host *host);
Channagoud Kadabi15e65252014-07-09 10:35:01 -0700123/* API: Toggle the bit for clock-data recovery */
124void sdhci_msm_toggle_cdr(struct sdhci_host *host, bool enable);
Channagoud Kadabiafb8e172013-05-23 13:55:47 -0700125#endif