aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-exynos/setup-mshci-gpio.c
blob: db7d86ad67f97bebe6c0f15ecc8878ce1e24f846 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/* linux/arch/arm/mach-exynos/setup-mshci-gpio.c
 *
 * Copyright (c) 2009-2010 Samsung Electronics Co., Ltd.
 *		http://www.samsung.com/
 *
 * EXYNOS4 - Helper functions for setting up MSHCI device(s) GPIO (HSMMC)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
*/

#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/interrupt.h>
#include <linux/platform_device.h>
#include <linux/io.h>
#include <linux/mmc/host.h>
#include <linux/mmc/card.h>
#include <linux/delay.h>

#include <mach/gpio.h>
#include <mach/map.h>
#include <plat/gpio-cfg.h>
#include <plat/mshci.h>
#include <plat/cpu.h>

#define GPK0DRV	(S5P_VA_GPIO2 + 0x4C)
#define GPK1DRV	(S5P_VA_GPIO2 + 0x6C)
#define GPK2DRV	(S5P_VA_GPIO2 + 0x8C)
#define GPK3DRV	(S5P_VA_GPIO2 + 0xAC)

#define DIV_FSYS3	(S5P_VA_CMU + 0x0C54C)

void exynos4_setup_mshci_cfg_gpio(struct platform_device *dev, int width)
{
	unsigned int gpio;
	struct s3c_mshci_platdata *pdata = dev->dev.platform_data;

	/* early_printk("exynos4_setup_mshci_cfg_gpio\n"); */

	/* Set all the necessary GPG0/GPG1 pins to special-function 2 */
	for (gpio = EXYNOS4_GPK0(0); gpio < EXYNOS4_GPK0(2); gpio++) {
		s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(3));
		s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
	}

	/* if CDn pin is used as eMMC_EN pin, it might make a problem
	   So, a built-in type eMMC is embedded, it dose not set CDn pin */
	if (pdata->cd_type != S3C_MSHCI_CD_PERMANENT) {
		s3c_gpio_cfgpin(EXYNOS4_GPK0(2), S3C_GPIO_SFN(3));
		s3c_gpio_setpull(EXYNOS4_GPK0(2), S3C_GPIO_PULL_NONE);
	}

	switch (width) {
	case 8:
		for (gpio = EXYNOS4_GPK1(3); gpio <= EXYNOS4_GPK1(6); gpio++) {
			s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(4));
			s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
		}
		__raw_writel(0x2AAA, GPK1DRV);
	case 4:
		/* GPK[3:6] special-funtion 2 */
		for (gpio = EXYNOS4_GPK0(3); gpio <= EXYNOS4_GPK0(6); gpio++) {
			s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(3));
			s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
		}
		__raw_writel(0x2AAA, GPK0DRV);
		break;
	case 1:
		/* GPK[3] special-funtion 2 */
		for (gpio = EXYNOS4_GPK0(3); gpio < EXYNOS4_GPK0(4); gpio++) {
			s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(3));
			s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
		}
		__raw_writel(0xAA, GPK0DRV);
	default:
		break;
	}
}

void exynos4_setup_mshci_cfg_ddr(struct platform_device *dev, int ddr)
{
	if (ddr) {
#ifdef CONFIG_EXYNOS4_MSHC_EPLL_45MHZ
		__raw_writel(0x00, DIV_FSYS3);
#elif defined(CONFIG_EXYNOS4_MSHC_VPLL_46MHZ)
		__raw_writel(0x01, DIV_FSYS3);
#else
		if ((soc_is_exynos4412() || soc_is_exynos4212()) &&
			samsung_rev() >= EXYNOS4412_REV_1_0) {
			__raw_writel(0x1, DIV_FSYS3);
		} else
			__raw_writel(0x05, DIV_FSYS3);
#endif
	} else {
#ifdef CONFIG_EXYNOS4_MSHC_EPLL_45MHZ
		__raw_writel(0x01, DIV_FSYS3);
#elif defined(CONFIG_EXYNOS4_MSHC_VPLL_46MHZ)
		__raw_writel(0x03, DIV_FSYS3);
#else
		if ((soc_is_exynos4412() || soc_is_exynos4212()) &&
			samsung_rev() >= EXYNOS4412_REV_1_0)
			__raw_writel(0x3, DIV_FSYS3);
		else
			__raw_writel(0xb, DIV_FSYS3);
#endif
	}
}

void exynos4_setup_mshci_init_card(struct platform_device *dev)
{
	/*
	 * Reset moviNAND for re-init.
	 * output/low for eMMC_EN and input/pull-none for others
	 * and then wait 10ms.
	 */
	__raw_writel(0x100, S5P_VA_GPIO2 + 0x40);
	__raw_writel(0, S5P_VA_GPIO2 + 0x44);
	__raw_writel(0, S5P_VA_GPIO2 + 0x48);
	__raw_writel(0, S5P_VA_GPIO2 + 0x60);
	__raw_writel(0, S5P_VA_GPIO2 + 0x64);
	__raw_writel(0, S5P_VA_GPIO2 + 0x68);
	mdelay(100);

	/* set data buswidth 8 */
	exynos4_setup_mshci_cfg_gpio(dev, 8);

	/* power to moviNAND on */
	gpio_set_value(EXYNOS4_GPK0(2), 1);

	/* to wait a pull-up resistance ready */
	mdelay(10);
}

void exynos4_setup_mshci_set_power(struct platform_device *dev, int en)
{
	struct s3c_mshci_platdata *pdata = dev->dev.platform_data;
	unsigned int gpio = 0;

	if (pdata->int_power_gpio) {
		if (en) {
#ifdef CONFIG_MACH_Q1_BD
			mdelay(20);
#endif
			/*CMD/CLK*/
			for (gpio = EXYNOS4_GPK0(0); gpio < EXYNOS4_GPK0(2);
					gpio++) {
				s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(3));
				s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
			}
			/*DAT[0]~[3]*/
			for (gpio = EXYNOS4_GPK0(3); gpio <= EXYNOS4_GPK0(6);
					gpio++) {
				s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(3));
				s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
			}
			/*DAT[4]~[7]*/
			for (gpio = EXYNOS4_GPK1(3); gpio <= EXYNOS4_GPK1(6);
					gpio++) {
				s3c_gpio_cfgpin(gpio, S3C_GPIO_SFN(4));
				s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
			}

			gpio_set_value(pdata->int_power_gpio, 1);
			pr_info("%s : internal MMC Card ON samsung-mshc.\n",
					__func__);
		} else {
#if defined(CONFIG_MACH_M0_CTC)
			s3c_gpio_cfgpin(pdata->int_power_gpio, S3C_GPIO_OUTPUT);
			s3c_gpio_setpull(pdata->int_power_gpio,
					S3C_GPIO_PULL_NONE);
#endif
			gpio_set_value(pdata->int_power_gpio, 0);

			/*CMD/CLK*/
			for (gpio = EXYNOS4_GPK0(0); gpio < EXYNOS4_GPK0(2);
					gpio++) {
				s3c_gpio_cfgpin(gpio, S3C_GPIO_INPUT);
				s3c_gpio_setpull(gpio, S3C_GPIO_PULL_DOWN);
			}
			/*DAT[0]~[3]*/
			for (gpio = EXYNOS4_GPK0(3); gpio <= EXYNOS4_GPK0(6);
					gpio++) {
				s3c_gpio_cfgpin(gpio, S3C_GPIO_INPUT);
				s3c_gpio_setpull(gpio, S3C_GPIO_PULL_DOWN);
			}
			/*DAT[4]~[7]*/
			for (gpio = EXYNOS4_GPK1(3); gpio <= EXYNOS4_GPK1(6);
					gpio++) {
				s3c_gpio_cfgpin(gpio, S3C_GPIO_INPUT);
				s3c_gpio_setpull(gpio, S3C_GPIO_PULL_DOWN);
			}
			pr_info("%s : internal MMC Card OFF samsung-mshc.\n",
					__func__);
			mdelay(50);
		}
	}
}

void exynos4_setup_mshci_shutdown()
{
        /* to reset eMMC card, VDD of eMMC should be off over 1ms */
	__raw_writel(0x100, S5P_VA_GPIO2 + 0x40);
	__raw_writel(0, S5P_VA_GPIO2 + 0x44);
	__raw_writel(0, S5P_VA_GPIO2 + 0x48);
	__raw_writel(0, S5P_VA_GPIO2 + 0x60);
	__raw_writel(0, S5P_VA_GPIO2 + 0x64);
	__raw_writel(0, S5P_VA_GPIO2 + 0x68);
	mdelay(10);
}