aboutsummaryrefslogtreecommitdiff
path: root/arch/arm/mach-ux500/mop500-sdi.c
blob: 5370621a72477bb5fa6c51d13503d91713ae1843 (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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/*
 * Copyright (C) 2010 ST-Ericsson
 *
 * 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/platform_device.h>
#include <linux/amba/bus.h>
#include <linux/mmc/host.h>
#include <linux/delay.h>

#include <mach/devices.h>
#include <mach/mmc.h>
#include <mach/stmpe2401.h>
#include <mach/tc35892.h>
#include <mach/ab8500.h>

/*
 * SDI0 (SD/MMC card)
 */

static int mmc_configure(struct amba_device *dev)
{
	int pin[2];
	int ret;
	int i;

	/* Level-shifter GPIOs */
	if (MOP500_PLATFORM_ID == platform_id)	{
		pin[0] = EGPIO_PIN_18;
		pin[1] = EGPIO_PIN_19;
	} else if (HREF_PLATFORM_ID == platform_id) {
		pin[0] = EGPIO_PIN_17;
		pin[1] = EGPIO_PIN_18;
	} else
		BUG();

	ret = gpio_request(pin[0], "level shifter");
	if (!ret)
		ret = gpio_request(pin[1], "level shifter");

	if (!ret) {
		gpio_direction_output(pin[0], 1);
		gpio_direction_output(pin[1], 1);

		gpio_set_value(pin[0], 1);
#if defined(CONFIG_LEVELSHIFTER_HREF_V1_PLUS)
		gpio_set_value(pin[1], 0);
#else
		gpio_set_value(pin[1], 1);
#endif
	} else
		dev_err(&dev->dev, "unable to configure gpios\n");

#if defined(CONFIG_GPIO_TC35892)
	if (HREF_PLATFORM_ID == platform_id) {
		/* Enabling the card detection interrupt */
		tc35892_set_gpio_intr_conf(EGPIO_PIN_3, EDGE_SENSITIVE,
				TC35892_BOTH_EDGE);
		tc35892_set_intr_enable(EGPIO_PIN_3, ENABLE_INTERRUPT);
	}
#endif

	for (i = 18; i <= 28; i++)
		nmk_gpio_set_pull(i, NMK_GPIO_PULL_UP);

	stm_gpio_altfuncenable(GPIO_ALT_SDMMC);
	return ret;
}

static void mmc_set_power(struct device *dev, int power_on)
{
	if (platform_id == MOP500_PLATFORM_ID)
		gpio_set_value(EGPIO_PIN_18, !!power_on);
	else if (platform_id == HREF_PLATFORM_ID)
		gpio_set_value(EGPIO_PIN_17, !!power_on);
}

static void mmc_restore_default(struct amba_device *dev)
{

}

static int mmc_card_detect(void (*callback)(void *parameter), void *host)
{
	/*
	 * Card detection interrupt request
	 */
#if defined(CONFIG_GPIO_STMPE2401)
	if (MOP500_PLATFORM_ID == platform_id)
		stmpe2401_set_callback(EGPIO_PIN_16, callback, host);
#endif

#if defined(CONFIG_GPIO_TC35892)
	if (HREF_PLATFORM_ID == platform_id) {
		tc35892_set_gpio_intr_conf(EGPIO_PIN_3, EDGE_SENSITIVE, TC35892_BOTH_EDGE);
		tc35892_set_intr_enable(EGPIO_PIN_3, ENABLE_INTERRUPT);
		tc35892_set_callback(EGPIO_PIN_3, callback, host);
	}
#endif
	return 0;
}

static int mmc_get_carddetect_intr_value(void)
{
	int status = 0;

	if (MOP500_PLATFORM_ID == platform_id)
		status = gpio_get_value(EGPIO_PIN_16);
	else if (HREF_PLATFORM_ID == platform_id)
		status = gpio_get_value(EGPIO_PIN_3);

	return status;
}

static struct mmc_board mmc_data = {
	.init = mmc_configure,
	.exit = mmc_restore_default,
	.set_power = mmc_set_power,
	.card_detect = mmc_card_detect,
	.card_detect_intr_value = mmc_get_carddetect_intr_value,
	.dma_fifo_addr = U8500_SDI0_BASE + SD_MMC_TX_RX_REG_OFFSET,
	.dma_fifo_dev_type_rx = DMA_DEV_SD_MM0_RX,
	.dma_fifo_dev_type_tx = DMA_DEV_SD_MM0_TX,
	.level_shifter = 1,
	.caps = MMC_CAP_4_BIT_DATA | MMC_CAP_SD_HIGHSPEED |
					MMC_CAP_MMC_HIGHSPEED,
#ifdef CONFIG_REGULATOR
	.supply = "v-MMC-SD", /* tying to VAUX3 regulator */
	.supply_voltage = 2900000 /* 2.9V */
#endif
};

/*
 * SDI1 (SDIO WLAN)
 */

/* sdio specific configurations */
static int sdio_configure(struct amba_device *dev)
{
	int i;

	for (i = 208; i <= 214; i++)
		nmk_gpio_set_pull(i, NMK_GPIO_PULL_UP);

	stm_gpio_altfuncenable(GPIO_ALT_SDIO);

	return 0;
}

static void sdio_restore_default(struct amba_device *dev)
{
    stm_gpio_altfuncdisable(GPIO_ALT_SDIO);
}

static struct mmc_board sdi1_data = {
	.init = sdio_configure,
	.exit = sdio_restore_default,
	.dma_fifo_addr = U8500_SDI1_BASE + SD_MMC_TX_RX_REG_OFFSET,
	.dma_fifo_dev_type_rx = DMA_DEV_SD_MM1_RX,
	.dma_fifo_dev_type_tx = DMA_DEV_SD_MM1_TX,
	.level_shifter = 0,
#ifdef CONFIG_U8500_SDIO_CARD_IRQ
	.caps = (MMC_CAP_4_BIT_DATA | MMC_CAP_SDIO_IRQ),
#else
	.caps = MMC_CAP_4_BIT_DATA,
#endif
	.is_sdio = 1,
};

/*
 * SDI2 (POPed eMMC on v1)
 */

static int sdi2_init(struct amba_device *dev)
{
	int i;

	for (i = 128; i <= 138; i++)
		nmk_gpio_set_pull(i, NMK_GPIO_PULL_UP);

	stm_gpio_altfuncenable(GPIO_ALT_SDMMC2);

	return 0;
}

static void sdi2_exit(struct amba_device *dev)
{
	stm_gpio_altfuncdisable(GPIO_ALT_SDMMC2);
}

static struct mmc_board sdi2_data = {
	.init = sdi2_init,
	.exit = sdi2_exit,
	.dma_fifo_addr = U8500_SDI2_BASE + SD_MMC_TX_RX_REG_OFFSET,
	.dma_fifo_dev_type_rx = DMA_DEV_SD_MM2_RX,
	.dma_fifo_dev_type_tx = DMA_DEV_SD_MM2_TX,
	.level_shifter = 0,
	.caps = MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA,
};

/*
 * SDI4 (On-board EMMC)
 */

static int emmc_configure(struct amba_device *dev)
{
	int i;

	for (i = 197; i <= 207; i++)
		nmk_gpio_set_pull(i, NMK_GPIO_PULL_UP);
	stm_gpio_altfuncenable(GPIO_ALT_EMMC);

#ifndef CONFIG_REGULATOR
	if (!cpu_is_u8500ed()) {
		int val;

		/* On V1 MOP, regulator to on-board eMMC is off by default */
		val = ab8500_read(AB8500_REGU_CTRL2,
					AB8500_REGU_VAUX12_REGU_REG);
		ab8500_write(AB8500_REGU_CTRL2, AB8500_REGU_VAUX12_REGU_REG,
					val | 0x4);

		val = ab8500_read(AB8500_REGU_CTRL2,
				AB8500_REGU_VAUX2_SEL_REG);
		ab8500_write(AB8500_REGU_CTRL2, AB8500_REGU_VAUX2_SEL_REG,
					0x0C);
	}
#endif

	return 0;
}

static void emmc_restore_default(struct amba_device *dev)
{
	stm_gpio_altfuncdisable(GPIO_ALT_EMMC);
}

static struct mmc_board emmc_data = {
	.init = emmc_configure,
	.exit = emmc_restore_default,
	.dma_fifo_addr = U8500_SDI4_BASE + SD_MMC_TX_RX_REG_OFFSET,
	.dma_fifo_dev_type_rx = DMA_DEV_SD_MM4_RX,
	.dma_fifo_dev_type_tx = DMA_DEV_SD_MM4_TX,
	.caps = MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA | MMC_CAP_MMC_HIGHSPEED,
#ifdef CONFIG_REGULATOR
	.supply = "v-eMMC", /* tying to VAUX1 regulator */
	.supply_voltage = 2900000 /* 2.9V */
#endif
};

static int __init mop500_sdi_init(void)
{
	if (!cpu_is_u8500ed())
		u8500_register_amba_device(&ux500_sdi2_device, &sdi2_data);

	u8500_register_amba_device(&ux500_sdi4_device, &emmc_data);
	u8500_register_amba_device(&ux500_sdi0_device, &mmc_data);
#ifdef CONFIG_U8500_SDIO
	u8500_register_amba_device(&ux500_sdi1_device, &sdi1_data);
#endif

	return 0;
}

fs_initcall(mop500_sdi_init);