aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-exynos/dev-dwmci.c
blob: 8db19074f406eab2af0e2aaab33a6e169cd20b7a (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
/*
 * linux/arch/arm/mach-exynos/dev-dwmci.c
 *
 * Copyright (c) 2011 Samsung Electronics Co., Ltd.
 *		http://www.samsung.com
 *
 * Platform device for Synopsys DesignWare Mobile Storage IP
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 */

#include <linux/kernel.h>
#include <linux/dma-mapping.h>
#include <linux/platform_device.h>
#include <linux/interrupt.h>
#include <linux/mmc/dw_mmc.h>
#include <linux/mmc/host.h>

#include <plat/devs.h>
#include <plat/cpu.h>

#include <mach/map.h>

#define DWMCI_CLKSEL	0x09c

static int exynos_dwmci_get_bus_wd(u32 slot_id)
{
	return 4;
}

static int exynos_dwmci_init(u32 slot_id, irq_handler_t handler, void *data)
{
	struct dw_mci *host = (struct dw_mci *)data;

	/* Set Phase Shift Register */
	if (soc_is_exynos4210()) {
		host->pdata->sdr_timing = 0x00010001;
		host->pdata->ddr_timing = 0x00020002;
	} else if (soc_is_exynos4212() || soc_is_exynos4412()) {
		host->pdata->sdr_timing = 0x00010001;
		host->pdata->ddr_timing = 0x00010002;
	} else if (soc_is_exynos5250()) {
		if (samsung_rev() >= EXYNOS5250_REV_1_0) {
			switch (host->pdev->id) {
			case 0:
				host->pdata->sdr_timing = 0x03020001;
				host->pdata->ddr_timing = 0x03030002;
				break;
			case 1:
				host->pdata->sdr_timing = 0x03020001;
				host->pdata->ddr_timing = 0x03030002;
				break;
			case 2:
				host->pdata->sdr_timing = 0x03020001;
				host->pdata->ddr_timing = 0x03030002;
				break;
			case 3:
				host->pdata->sdr_timing = 0x03020001;
				host->pdata->ddr_timing = 0x03030002;
				break;
			default:
				host->pdata->sdr_timing = 0x03020001;
				host->pdata->ddr_timing = 0x03030002;
				break;
			}
		} else {
			host->pdata->sdr_timing = 0x00010000;
			host->pdata->ddr_timing = 0x00010000;
		}
	}
#ifdef CONFIG_SLP
	host->pdata->sdr_timing = 0x00020001;
	host->pdata->ddr_timing = 0x00020002;
#endif

	return 0;
}

static void exynos_dwmci_set_io_timing(void *data, unsigned char timing)
{
	struct dw_mci *host = (struct dw_mci *)data;

	if (timing == MMC_TIMING_UHS_DDR50)
		__raw_writel(host->pdata->ddr_timing,
			host->regs + DWMCI_CLKSEL);
	else
		__raw_writel(host->pdata->sdr_timing,
			host->regs + DWMCI_CLKSEL);
}

static struct resource exynos_dwmci_resource[] = {
	[0] = {
		.start	= EXYNOS_PA_DWMCI,
		.end	= EXYNOS_PA_DWMCI + SZ_4K - 1,
		.flags	= IORESOURCE_MEM,
	},
	[1] = {
		.start	= IRQ_DWMCI,
		.end	= IRQ_DWMCI,
		.flags	= IORESOURCE_IRQ,
	}
};

static struct dw_mci_board exynos_dwmci_def_platdata = {
	.num_slots		= 1,
	.quirks			= DW_MCI_QUIRK_BROKEN_CARD_DETECTION,
	.bus_hz			= 80 * 1000 * 1000,
	.detect_delay_ms	= 200,
	.init			= exynos_dwmci_init,
	.get_bus_wd		= exynos_dwmci_get_bus_wd,
	.set_io_timing		= exynos_dwmci_set_io_timing,
};

static u64 exynos_dwmci_dmamask = DMA_BIT_MASK(32);

struct platform_device exynos_device_dwmci = {
	.name		= "dw_mmc",
	.id		= -1,
	.num_resources	= ARRAY_SIZE(exynos_dwmci_resource),
	.resource	= exynos_dwmci_resource,
	.dev		= {
		.dma_mask		= &exynos_dwmci_dmamask,
		.coherent_dma_mask	= DMA_BIT_MASK(32),
		.platform_data		= &exynos_dwmci_def_platdata,
	},
};

#define EXYNOS5_DWMCI_RESOURCE(_channel) \
static struct resource exynos5_dwmci##_channel##_resource[] = { \
	[0] = {							\
		.start	= S3C_PA_HSMMC##_channel,		\
		.end	= S3C_PA_HSMMC##_channel + SZ_4K - 1,	\
		.flags	= IORESOURCE_MEM,			\
	},							\
	[1] = {							\
		.start	= IRQ_HSMMC##_channel,			\
		.end	= IRQ_HSMMC##_channel,			\
		.flags	= IORESOURCE_IRQ,			\
	}							\
};

EXYNOS5_DWMCI_RESOURCE(0)
EXYNOS5_DWMCI_RESOURCE(1)
EXYNOS5_DWMCI_RESOURCE(2)
EXYNOS5_DWMCI_RESOURCE(3)

#define EXYNOS_DWMCI_DEF_PLATDATA(_channel)			\
struct dw_mci_board exynos_dwmci##_channel##_def_platdata = {	\
	.num_slots		= 1,				\
	.quirks			=				\
		DW_MCI_QUIRK_BROKEN_CARD_DETECTION,		\
	.bus_hz			= 200 * 1000 * 1000,		\
	.detect_delay_ms	= 200,				\
	.init			= exynos_dwmci_init,		\
	.get_bus_wd		= exynos_dwmci_get_bus_wd,	\
	.set_io_timing		= exynos_dwmci_set_io_timing,	\
	.cd_type 		= DW_MCI_CD_INTERNAL 		\
};

EXYNOS_DWMCI_DEF_PLATDATA(0)
EXYNOS_DWMCI_DEF_PLATDATA(1)
EXYNOS_DWMCI_DEF_PLATDATA(2)
EXYNOS_DWMCI_DEF_PLATDATA(3)

#define EXYNOS_DWMCI_PLATFORM_DEVICE(_channel)			\
struct platform_device exynos_device_dwmci##_channel =		\
{								\
	.name		= "dw_mmc",				\
	.id		= _channel,				\
	.num_resources	=					\
	ARRAY_SIZE(exynos5_dwmci##_channel##_resource), 	\
	.resource	= exynos5_dwmci##_channel##_resource,	\
	.dev		= {					\
		.dma_mask		= &exynos_dwmci_dmamask,\
		.coherent_dma_mask	= DMA_BIT_MASK(32),	\
		.platform_data		=			\
		&exynos_dwmci##_channel##_def_platdata,	\
	},							\
};

EXYNOS_DWMCI_PLATFORM_DEVICE(0)
EXYNOS_DWMCI_PLATFORM_DEVICE(1)
EXYNOS_DWMCI_PLATFORM_DEVICE(2)
EXYNOS_DWMCI_PLATFORM_DEVICE(3)

void __init exynos_dwmci_set_platdata(struct dw_mci_board *pd, u32 slot_id)
{
	struct dw_mci_board *npd = NULL;

	if ((soc_is_exynos4210()) ||
		soc_is_exynos4212() || soc_is_exynos4412()) {
		npd = s3c_set_platdata(pd, sizeof(struct dw_mci_board),
			&exynos_device_dwmci);
	} else if (soc_is_exynos5250()) {
		if (slot_id == 0) {
			if (samsung_rev() < EXYNOS5250_REV_1_0) {
				exynos_device_dwmci0.resource[0].start =
					EXYNOS_PA_DWMCI;
				exynos_device_dwmci0.resource[0].end =
					EXYNOS_PA_DWMCI + SZ_4K - 1;
				exynos_device_dwmci0.resource[1].start =
					IRQ_DWMCI;
				exynos_device_dwmci0.resource[1].end =
					IRQ_DWMCI;
			}
			npd = s3c_set_platdata(pd, sizeof(struct dw_mci_board),
				&exynos_device_dwmci0);
		} else if (slot_id == 1) {
			npd = s3c_set_platdata(pd, sizeof(struct dw_mci_board),
				&exynos_device_dwmci1);
		} else if (slot_id == 2) {
			npd = s3c_set_platdata(pd, sizeof(struct dw_mci_board),
				&exynos_device_dwmci2);
		} else if (slot_id == 3) {
			npd = s3c_set_platdata(pd, sizeof(struct dw_mci_board),
				&exynos_device_dwmci3);
		} else {
			pr_err("This channel %d Cannot support.\n", slot_id);
		}
	} else {
		printk("dwmci platform data support only exynos4/5!\n");
#ifdef CONFIG_SLP
		npd = s3c_set_platdata(pd, sizeof(struct dw_mci_board),
			&exynos_device_dwmci);
#endif
	}

	if (npd) {
		if (!npd->init)
			npd->init = exynos_dwmci_init;
		if (!npd->get_bus_wd)
			npd->get_bus_wd = exynos_dwmci_get_bus_wd;
		if (!npd->set_io_timing)
			npd->set_io_timing = exynos_dwmci_set_io_timing;
	}
}