aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-exynos/setup-mshci-gpio.c
blob: 56e09596f92aca9dae52693aea96a85d2807dfdb (plain) (blame)
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
/* 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>

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

#if defined (CONFIG_EXYNOS4_MSHC_VPLL_46MHZ) || \
	defined (CONFIG_EXYNOS4_MSHC_EPLL_45MHZ)
#define DIV_FSYS3	(S5P_VA_CMU + 0x0C54C)
#endif

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));
		if ( gpio == EXYNOS4_GPK0(0) )
			s3c_gpio_setpull(gpio, S3C_GPIO_PULL_NONE);
		else
			s3c_gpio_setpull(gpio, S3C_GPIO_PULL_UP);
	}

	/* 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_UP);
	}

	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_UP);
		}
		__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_UP);
		}
		__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_UP);
		}
		__raw_writel(0xAA, GPK0DRV);
	default:
		break;
	}
}

#if defined (CONFIG_EXYNOS4_MSHC_VPLL_46MHZ) || \
	defined (CONFIG_EXYNOS4_MSHC_EPLL_45MHZ)
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);
#else
			__raw_writel(0x01, DIV_FSYS3);
#endif
		} else {
#ifdef CONFIG_EXYNOS4_MSHC_EPLL_45MHZ
			__raw_writel(0x01, DIV_FSYS3);
#else
			__raw_writel(0x03, DIV_FSYS3);
#endif
		}
}
#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);
}