aboutsummaryrefslogtreecommitdiff
path: root/arch/arm/mach-s5pc100/dev-spi.c
blob: a0ef7c302c16e62deee6db35274163d73fe54e80 (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
/* linux/arch/arm/mach-s5pc100/dev-spi.c
 *
 * Copyright (C) 2010 Samsung Electronics Co. Ltd.
 *	Jaswinder Singh <jassi.brar@samsung.com>
 *
 * 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/dma-mapping.h>
#include <linux/gpio.h>

#include <mach/dma.h>
#include <mach/map.h>
#include <mach/spi-clocks.h>

#include <plat/s3c64xx-spi.h>
#include <plat/gpio-cfg.h>
#include <plat/irqs.h>

static char *spi_src_clks[] = {
	[S5PC100_SPI_SRCCLK_PCLK] = "pclk",
	[S5PC100_SPI_SRCCLK_48M] = "spi_48m",
	[S5PC100_SPI_SRCCLK_SPIBUS] = "spi_bus",
};

/* SPI Controller platform_devices */

/* Since we emulate multi-cs capability, we do not touch the CS.
 * The emulated CS is toggled by board specific mechanism, as it can
 * be either some immediate GPIO or some signal out of some other
 * chip in between ... or some yet another way.
 * We simply do not assume anything about CS.
 */
static int s5pc100_spi_cfg_gpio(struct platform_device *pdev)
{
	switch (pdev->id) {
	case 0:
		s3c_gpio_cfgpin(S5PC100_GPB(0), S3C_GPIO_SFN(2));
		s3c_gpio_cfgpin(S5PC100_GPB(1), S3C_GPIO_SFN(2));
		s3c_gpio_cfgpin(S5PC100_GPB(2), S3C_GPIO_SFN(2));
		s3c_gpio_setpull(S5PC100_GPB(0), S3C_GPIO_PULL_UP);
		s3c_gpio_setpull(S5PC100_GPB(1), S3C_GPIO_PULL_UP);
		s3c_gpio_setpull(S5PC100_GPB(2), S3C_GPIO_PULL_UP);
		break;

	case 1:
		s3c_gpio_cfgpin(S5PC100_GPB(4), S3C_GPIO_SFN(2));
		s3c_gpio_cfgpin(S5PC100_GPB(5), S3C_GPIO_SFN(2));
		s3c_gpio_cfgpin(S5PC100_GPB(6), S3C_GPIO_SFN(2));
		s3c_gpio_setpull(S5PC100_GPB(4), S3C_GPIO_PULL_UP);
		s3c_gpio_setpull(S5PC100_GPB(5), S3C_GPIO_PULL_UP);
		s3c_gpio_setpull(S5PC100_GPB(6), S3C_GPIO_PULL_UP);
		break;

	case 2:
		s3c_gpio_cfgpin(S5PC100_GPG3(0), S3C_GPIO_SFN(3));
		s3c_gpio_cfgpin(S5PC100_GPG3(2), S3C_GPIO_SFN(3));
		s3c_gpio_cfgpin(S5PC100_GPG3(3), S3C_GPIO_SFN(3));
		s3c_gpio_setpull(S5PC100_GPG3(0), S3C_GPIO_PULL_UP);
		s3c_gpio_setpull(S5PC100_GPG3(2), S3C_GPIO_PULL_UP);
		s3c_gpio_setpull(S5PC100_GPG3(3), S3C_GPIO_PULL_UP);
		break;

	default:
		dev_err(&pdev->dev, "Invalid SPI Controller number!");
		return -EINVAL;
	}

	return 0;
}

static struct resource s5pc100_spi0_resource[] = {
	[0] = {
		.start = S5PC100_PA_SPI0,
		.end   = S5PC100_PA_SPI0 + 0x100 - 1,
		.flags = IORESOURCE_MEM,
	},
	[1] = {
		.start = DMACH_SPI0_TX,
		.end   = DMACH_SPI0_TX,
		.flags = IORESOURCE_DMA,
	},
	[2] = {
		.start = DMACH_SPI0_RX,
		.end   = DMACH_SPI0_RX,
		.flags = IORESOURCE_DMA,
	},
	[3] = {
		.start = IRQ_SPI0,
		.end   = IRQ_SPI0,
		.flags = IORESOURCE_IRQ,
	},
};

static struct s3c64xx_spi_info s5pc100_spi0_pdata = {
	.cfg_gpio = s5pc100_spi_cfg_gpio,
	.fifo_lvl_mask = 0x7f,
	.rx_lvl_offset = 13,
	.high_speed = 1,
};

static u64 spi_dmamask = DMA_BIT_MASK(32);

struct platform_device s5pc100_device_spi0 = {
	.name		  = "s3c64xx-spi",
	.id		  = 0,
	.num_resources	  = ARRAY_SIZE(s5pc100_spi0_resource),
	.resource	  = s5pc100_spi0_resource,
	.dev = {
		.dma_mask		= &spi_dmamask,
		.coherent_dma_mask	= DMA_BIT_MASK(32),
		.platform_data = &s5pc100_spi0_pdata,
	},
};

static struct resource s5pc100_spi1_resource[] = {
	[0] = {
		.start = S5PC100_PA_SPI1,
		.end   = S5PC100_PA_SPI1 + 0x100 - 1,
		.flags = IORESOURCE_MEM,
	},
	[1] = {
		.start = DMACH_SPI1_TX,
		.end   = DMACH_SPI1_TX,
		.flags = IORESOURCE_DMA,
	},
	[2] = {
		.start = DMACH_SPI1_RX,
		.end   = DMACH_SPI1_RX,
		.flags = IORESOURCE_DMA,
	},
	[3] = {
		.start = IRQ_SPI1,
		.end   = IRQ_SPI1,
		.flags = IORESOURCE_IRQ,
	},
};

static struct s3c64xx_spi_info s5pc100_spi1_pdata = {
	.cfg_gpio = s5pc100_spi_cfg_gpio,
	.fifo_lvl_mask = 0x7f,
	.rx_lvl_offset = 13,
	.high_speed = 1,
};

struct platform_device s5pc100_device_spi1 = {
	.name		  = "s3c64xx-spi",
	.id		  = 1,
	.num_resources	  = ARRAY_SIZE(s5pc100_spi1_resource),
	.resource	  = s5pc100_spi1_resource,
	.dev = {
		.dma_mask		= &spi_dmamask,
		.coherent_dma_mask	= DMA_BIT_MASK(32),
		.platform_data = &s5pc100_spi1_pdata,
	},
};

static struct resource s5pc100_spi2_resource[] = {
	[0] = {
		.start = S5PC100_PA_SPI2,
		.end   = S5PC100_PA_SPI2 + 0x100 - 1,
		.flags = IORESOURCE_MEM,
	},
	[1] = {
		.start = DMACH_SPI2_TX,
		.end   = DMACH_SPI2_TX,
		.flags = IORESOURCE_DMA,
	},
	[2] = {
		.start = DMACH_SPI2_RX,
		.end   = DMACH_SPI2_RX,
		.flags = IORESOURCE_DMA,
	},
	[3] = {
		.start = IRQ_SPI2,
		.end   = IRQ_SPI2,
		.flags = IORESOURCE_IRQ,
	},
};

static struct s3c64xx_spi_info s5pc100_spi2_pdata = {
	.cfg_gpio = s5pc100_spi_cfg_gpio,
	.fifo_lvl_mask = 0x7f,
	.rx_lvl_offset = 13,
	.high_speed = 1,
};

struct platform_device s5pc100_device_spi2 = {
	.name		  = "s3c64xx-spi",
	.id		  = 2,
	.num_resources	  = ARRAY_SIZE(s5pc100_spi2_resource),
	.resource	  = s5pc100_spi2_resource,
	.dev = {
		.dma_mask		= &spi_dmamask,
		.coherent_dma_mask	= DMA_BIT_MASK(32),
		.platform_data = &s5pc100_spi2_pdata,
	},
};

void __init s5pc100_spi_set_info(int cntrlr, int src_clk_nr, int num_cs)
{
	struct s3c64xx_spi_info *pd;

	/* Reject invalid configuration */
	if (!num_cs || src_clk_nr < 0
			|| src_clk_nr > S5PC100_SPI_SRCCLK_SPIBUS) {
		printk(KERN_ERR "%s: Invalid SPI configuration\n", __func__);
		return;
	}

	switch (cntrlr) {
	case 0:
		pd = &s5pc100_spi0_pdata;
		break;
	case 1:
		pd = &s5pc100_spi1_pdata;
		break;
	case 2:
		pd = &s5pc100_spi2_pdata;
		break;
	default:
		printk(KERN_ERR "%s: Invalid SPI controller(%d)\n",
							__func__, cntrlr);
		return;
	}

	pd->num_cs = num_cs;
	pd->src_clk_nr = src_clk_nr;
	pd->src_clk_name = spi_src_clks[src_clk_nr];
}