blob: bf6974b4afd0bcc8dbc6fd2375cc734472582195 [file] [log] [blame]
Magnus Damm2b7eda62010-02-05 11:14:58 +00001/*
2 * sh7372 processor support
3 *
4 * Copyright (C) 2010 Magnus Damm
5 * Copyright (C) 2008 Yoshihiro Shimoda
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20#include <linux/kernel.h>
21#include <linux/init.h>
22#include <linux/interrupt.h>
23#include <linux/irq.h>
24#include <linux/platform_device.h>
25#include <linux/delay.h>
26#include <linux/input.h>
27#include <linux/io.h>
28#include <linux/serial_sci.h>
Guennadi Liakhovetski69bf6f42010-05-04 14:07:15 +000029#include <linux/sh_dma.h>
Magnus Damm2b7eda62010-02-05 11:14:58 +000030#include <linux/sh_intc.h>
31#include <linux/sh_timer.h>
32#include <mach/hardware.h>
Guennadi Liakhovetski69bf6f42010-05-04 14:07:15 +000033#include <mach/sh7372.h>
Magnus Damm2b7eda62010-02-05 11:14:58 +000034#include <asm/mach-types.h>
35#include <asm/mach/arch.h>
36
Magnus Damm33c96072010-05-20 14:41:00 +000037/* SCIFA0 */
Magnus Damm2b7eda62010-02-05 11:14:58 +000038static struct plat_sci_port scif0_platform_data = {
39 .mapbase = 0xe6c40000,
40 .flags = UPF_BOOT_AUTOCONF,
Guennadi Liakhovetskieb6e8605e2010-05-23 16:39:17 +000041 .type = PORT_SCIFA,
Magnus Damm33c96072010-05-20 14:41:00 +000042 .irqs = { evt2irq(0x0c00), evt2irq(0x0c00),
43 evt2irq(0x0c00), evt2irq(0x0c00) },
Magnus Damm2b7eda62010-02-05 11:14:58 +000044};
45
46static struct platform_device scif0_device = {
47 .name = "sh-sci",
48 .id = 0,
49 .dev = {
50 .platform_data = &scif0_platform_data,
51 },
52};
53
Magnus Damm33c96072010-05-20 14:41:00 +000054/* SCIFA1 */
Magnus Damm2b7eda62010-02-05 11:14:58 +000055static struct plat_sci_port scif1_platform_data = {
56 .mapbase = 0xe6c50000,
57 .flags = UPF_BOOT_AUTOCONF,
Guennadi Liakhovetskieb6e8605e2010-05-23 16:39:17 +000058 .type = PORT_SCIFA,
Magnus Damm33c96072010-05-20 14:41:00 +000059 .irqs = { evt2irq(0x0c20), evt2irq(0x0c20),
60 evt2irq(0x0c20), evt2irq(0x0c20) },
Magnus Damm2b7eda62010-02-05 11:14:58 +000061};
62
63static struct platform_device scif1_device = {
64 .name = "sh-sci",
65 .id = 1,
66 .dev = {
67 .platform_data = &scif1_platform_data,
68 },
69};
70
Magnus Damm33c96072010-05-20 14:41:00 +000071/* SCIFA2 */
Magnus Damm2b7eda62010-02-05 11:14:58 +000072static struct plat_sci_port scif2_platform_data = {
73 .mapbase = 0xe6c60000,
74 .flags = UPF_BOOT_AUTOCONF,
Guennadi Liakhovetskieb6e8605e2010-05-23 16:39:17 +000075 .type = PORT_SCIFA,
Magnus Damm33c96072010-05-20 14:41:00 +000076 .irqs = { evt2irq(0x0c40), evt2irq(0x0c40),
77 evt2irq(0x0c40), evt2irq(0x0c40) },
Magnus Damm2b7eda62010-02-05 11:14:58 +000078};
79
80static struct platform_device scif2_device = {
81 .name = "sh-sci",
82 .id = 2,
83 .dev = {
84 .platform_data = &scif2_platform_data,
85 },
86};
87
Magnus Damm33c96072010-05-20 14:41:00 +000088/* SCIFA3 */
Magnus Damm2b7eda62010-02-05 11:14:58 +000089static struct plat_sci_port scif3_platform_data = {
90 .mapbase = 0xe6c70000,
91 .flags = UPF_BOOT_AUTOCONF,
Guennadi Liakhovetskieb6e8605e2010-05-23 16:39:17 +000092 .type = PORT_SCIFA,
Magnus Damm33c96072010-05-20 14:41:00 +000093 .irqs = { evt2irq(0x0c60), evt2irq(0x0c60),
94 evt2irq(0x0c60), evt2irq(0x0c60) },
Magnus Damm2b7eda62010-02-05 11:14:58 +000095};
96
97static struct platform_device scif3_device = {
98 .name = "sh-sci",
99 .id = 3,
100 .dev = {
101 .platform_data = &scif3_platform_data,
102 },
103};
104
Magnus Damm33c96072010-05-20 14:41:00 +0000105/* SCIFA4 */
Magnus Damm2b7eda62010-02-05 11:14:58 +0000106static struct plat_sci_port scif4_platform_data = {
107 .mapbase = 0xe6c80000,
108 .flags = UPF_BOOT_AUTOCONF,
Guennadi Liakhovetskieb6e8605e2010-05-23 16:39:17 +0000109 .type = PORT_SCIFA,
Magnus Damm33c96072010-05-20 14:41:00 +0000110 .irqs = { evt2irq(0x0d20), evt2irq(0x0d20),
111 evt2irq(0x0d20), evt2irq(0x0d20) },
Magnus Damm2b7eda62010-02-05 11:14:58 +0000112};
113
114static struct platform_device scif4_device = {
115 .name = "sh-sci",
116 .id = 4,
117 .dev = {
118 .platform_data = &scif4_platform_data,
119 },
120};
121
Magnus Damm33c96072010-05-20 14:41:00 +0000122/* SCIFA5 */
Magnus Damm2b7eda62010-02-05 11:14:58 +0000123static struct plat_sci_port scif5_platform_data = {
124 .mapbase = 0xe6cb0000,
125 .flags = UPF_BOOT_AUTOCONF,
Guennadi Liakhovetskieb6e8605e2010-05-23 16:39:17 +0000126 .type = PORT_SCIFA,
Magnus Damm33c96072010-05-20 14:41:00 +0000127 .irqs = { evt2irq(0x0d40), evt2irq(0x0d40),
128 evt2irq(0x0d40), evt2irq(0x0d40) },
Magnus Damm2b7eda62010-02-05 11:14:58 +0000129};
130
131static struct platform_device scif5_device = {
132 .name = "sh-sci",
133 .id = 5,
134 .dev = {
135 .platform_data = &scif5_platform_data,
136 },
137};
138
Magnus Damm33c96072010-05-20 14:41:00 +0000139/* SCIFB */
Magnus Damm2b7eda62010-02-05 11:14:58 +0000140static struct plat_sci_port scif6_platform_data = {
141 .mapbase = 0xe6c30000,
142 .flags = UPF_BOOT_AUTOCONF,
Guennadi Liakhovetskieb6e8605e2010-05-23 16:39:17 +0000143 .type = PORT_SCIFB,
Magnus Damm33c96072010-05-20 14:41:00 +0000144 .irqs = { evt2irq(0x0d60), evt2irq(0x0d60),
145 evt2irq(0x0d60), evt2irq(0x0d60) },
Magnus Damm2b7eda62010-02-05 11:14:58 +0000146};
147
148static struct platform_device scif6_device = {
149 .name = "sh-sci",
150 .id = 6,
151 .dev = {
152 .platform_data = &scif6_platform_data,
153 },
154};
155
Kuninori Morimotoc1909cc2010-03-11 10:42:47 +0000156/* CMT */
Magnus Damm2b7eda62010-02-05 11:14:58 +0000157static struct sh_timer_config cmt10_platform_data = {
158 .name = "CMT10",
159 .channel_offset = 0x10,
160 .timer_bit = 0,
Magnus Damm495b3ce2010-05-12 14:21:34 +0000161 .clk = "cmt1",
Magnus Damm2b7eda62010-02-05 11:14:58 +0000162 .clockevent_rating = 125,
163 .clocksource_rating = 125,
164};
165
166static struct resource cmt10_resources[] = {
167 [0] = {
168 .name = "CMT10",
169 .start = 0xe6138010,
170 .end = 0xe613801b,
171 .flags = IORESOURCE_MEM,
172 },
173 [1] = {
Magnus Damm33c96072010-05-20 14:41:00 +0000174 .start = evt2irq(0x0b00), /* CMT1_CMT10 */
Magnus Damm2b7eda62010-02-05 11:14:58 +0000175 .flags = IORESOURCE_IRQ,
176 },
177};
178
179static struct platform_device cmt10_device = {
180 .name = "sh_cmt",
181 .id = 10,
182 .dev = {
183 .platform_data = &cmt10_platform_data,
184 },
185 .resource = cmt10_resources,
186 .num_resources = ARRAY_SIZE(cmt10_resources),
187};
188
Kuninori Morimotoc1909cc2010-03-11 10:42:47 +0000189/* I2C */
190static struct resource iic0_resources[] = {
191 [0] = {
192 .name = "IIC0",
193 .start = 0xFFF20000,
194 .end = 0xFFF20425 - 1,
195 .flags = IORESOURCE_MEM,
196 },
197 [1] = {
Magnus Damm33c96072010-05-20 14:41:00 +0000198 .start = intcs_evt2irq(0xe00), /* IIC0_ALI0 */
199 .end = intcs_evt2irq(0xe60), /* IIC0_DTEI0 */
Kuninori Morimotoc1909cc2010-03-11 10:42:47 +0000200 .flags = IORESOURCE_IRQ,
201 },
202};
203
204static struct platform_device iic0_device = {
205 .name = "i2c-sh_mobile",
206 .id = 0, /* "i2c0" clock */
207 .num_resources = ARRAY_SIZE(iic0_resources),
208 .resource = iic0_resources,
209};
210
211static struct resource iic1_resources[] = {
212 [0] = {
213 .name = "IIC1",
214 .start = 0xE6C20000,
215 .end = 0xE6C20425 - 1,
216 .flags = IORESOURCE_MEM,
217 },
218 [1] = {
Magnus Damm33c96072010-05-20 14:41:00 +0000219 .start = evt2irq(0x780), /* IIC1_ALI1 */
220 .end = evt2irq(0x7e0), /* IIC1_DTEI1 */
Kuninori Morimotoc1909cc2010-03-11 10:42:47 +0000221 .flags = IORESOURCE_IRQ,
222 },
223};
224
225static struct platform_device iic1_device = {
226 .name = "i2c-sh_mobile",
227 .id = 1, /* "i2c1" clock */
228 .num_resources = ARRAY_SIZE(iic1_resources),
229 .resource = iic1_resources,
230};
231
Guennadi Liakhovetski69bf6f42010-05-04 14:07:15 +0000232/* DMA */
233/* Transmit sizes and respective CHCR register values */
234enum {
235 XMIT_SZ_8BIT = 0,
236 XMIT_SZ_16BIT = 1,
237 XMIT_SZ_32BIT = 2,
238 XMIT_SZ_64BIT = 7,
239 XMIT_SZ_128BIT = 3,
240 XMIT_SZ_256BIT = 4,
241 XMIT_SZ_512BIT = 5,
242};
243
244/* log2(size / 8) - used to calculate number of transfers */
245#define TS_SHIFT { \
246 [XMIT_SZ_8BIT] = 0, \
247 [XMIT_SZ_16BIT] = 1, \
248 [XMIT_SZ_32BIT] = 2, \
249 [XMIT_SZ_64BIT] = 3, \
250 [XMIT_SZ_128BIT] = 4, \
251 [XMIT_SZ_256BIT] = 5, \
252 [XMIT_SZ_512BIT] = 6, \
253}
254
255#define TS_INDEX2VAL(i) ((((i) & 3) << 3) | \
256 (((i) & 0xc) << (20 - 2)))
257
258static const struct sh_dmae_slave_config sh7372_dmae_slaves[] = {
259 {
260 .slave_id = SHDMA_SLAVE_SDHI0_TX,
261 .addr = 0xe6850030,
262 .chcr = DM_FIX | SM_INC | 0x800 | TS_INDEX2VAL(XMIT_SZ_16BIT),
263 .mid_rid = 0xc1,
264 }, {
265 .slave_id = SHDMA_SLAVE_SDHI0_RX,
266 .addr = 0xe6850030,
267 .chcr = DM_INC | SM_FIX | 0x800 | TS_INDEX2VAL(XMIT_SZ_16BIT),
268 .mid_rid = 0xc2,
269 }, {
270 .slave_id = SHDMA_SLAVE_SDHI1_TX,
271 .addr = 0xe6860030,
272 .chcr = DM_FIX | SM_INC | 0x800 | TS_INDEX2VAL(XMIT_SZ_16BIT),
273 .mid_rid = 0xc9,
274 }, {
275 .slave_id = SHDMA_SLAVE_SDHI1_RX,
276 .addr = 0xe6860030,
277 .chcr = DM_INC | SM_FIX | 0x800 | TS_INDEX2VAL(XMIT_SZ_16BIT),
278 .mid_rid = 0xca,
279 }, {
280 .slave_id = SHDMA_SLAVE_SDHI2_TX,
281 .addr = 0xe6870030,
282 .chcr = DM_FIX | SM_INC | 0x800 | TS_INDEX2VAL(XMIT_SZ_16BIT),
283 .mid_rid = 0xcd,
284 }, {
285 .slave_id = SHDMA_SLAVE_SDHI2_RX,
286 .addr = 0xe6870030,
287 .chcr = DM_INC | SM_FIX | 0x800 | TS_INDEX2VAL(XMIT_SZ_16BIT),
288 .mid_rid = 0xce,
289 },
290};
291
292static const struct sh_dmae_channel sh7372_dmae_channels[] = {
293 {
294 .offset = 0,
295 .dmars = 0,
296 .dmars_bit = 0,
297 }, {
298 .offset = 0x10,
299 .dmars = 0,
300 .dmars_bit = 8,
301 }, {
302 .offset = 0x20,
303 .dmars = 4,
304 .dmars_bit = 0,
305 }, {
306 .offset = 0x30,
307 .dmars = 4,
308 .dmars_bit = 8,
309 }, {
310 .offset = 0x50,
311 .dmars = 8,
312 .dmars_bit = 0,
313 }, {
314 .offset = 0x60,
315 .dmars = 8,
316 .dmars_bit = 8,
317 }
318};
319
320static const unsigned int ts_shift[] = TS_SHIFT;
321
322static struct sh_dmae_pdata dma_platform_data = {
323 .slave = sh7372_dmae_slaves,
324 .slave_num = ARRAY_SIZE(sh7372_dmae_slaves),
325 .channel = sh7372_dmae_channels,
326 .channel_num = ARRAY_SIZE(sh7372_dmae_channels),
327 .ts_low_shift = 3,
328 .ts_low_mask = 0x18,
329 .ts_high_shift = (20 - 2), /* 2 bits for shifted low TS */
330 .ts_high_mask = 0x00300000,
331 .ts_shift = ts_shift,
332 .ts_shift_num = ARRAY_SIZE(ts_shift),
333 .dmaor_init = DMAOR_DME,
334};
335
336/* Resource order important! */
337static struct resource sh7372_dmae0_resources[] = {
338 {
339 /* Channel registers and DMAOR */
340 .start = 0xfe008020,
341 .end = 0xfe00808f,
342 .flags = IORESOURCE_MEM,
343 },
344 {
345 /* DMARSx */
346 .start = 0xfe009000,
347 .end = 0xfe00900b,
348 .flags = IORESOURCE_MEM,
349 },
350 {
351 /* DMA error IRQ */
352 .start = 246,
353 .end = 246,
354 .flags = IORESOURCE_IRQ,
355 },
356 {
357 /* IRQ for channels 0-5 */
358 .start = 240,
359 .end = 245,
360 .flags = IORESOURCE_IRQ,
361 },
362};
363
364/* Resource order important! */
365static struct resource sh7372_dmae1_resources[] = {
366 {
367 /* Channel registers and DMAOR */
368 .start = 0xfe018020,
369 .end = 0xfe01808f,
370 .flags = IORESOURCE_MEM,
371 },
372 {
373 /* DMARSx */
374 .start = 0xfe019000,
375 .end = 0xfe01900b,
376 .flags = IORESOURCE_MEM,
377 },
378 {
379 /* DMA error IRQ */
380 .start = 254,
381 .end = 254,
382 .flags = IORESOURCE_IRQ,
383 },
384 {
385 /* IRQ for channels 0-5 */
386 .start = 248,
387 .end = 253,
388 .flags = IORESOURCE_IRQ,
389 },
390};
391
392/* Resource order important! */
393static struct resource sh7372_dmae2_resources[] = {
394 {
395 /* Channel registers and DMAOR */
396 .start = 0xfe028020,
397 .end = 0xfe02808f,
398 .flags = IORESOURCE_MEM,
399 },
400 {
401 /* DMARSx */
402 .start = 0xfe029000,
403 .end = 0xfe02900b,
404 .flags = IORESOURCE_MEM,
405 },
406 {
407 /* DMA error IRQ */
408 .start = 262,
409 .end = 262,
410 .flags = IORESOURCE_IRQ,
411 },
412 {
413 /* IRQ for channels 0-5 */
414 .start = 256,
415 .end = 261,
416 .flags = IORESOURCE_IRQ,
417 },
418};
419
420static struct platform_device dma0_device = {
421 .name = "sh-dma-engine",
422 .id = 0,
423 .resource = sh7372_dmae0_resources,
424 .num_resources = ARRAY_SIZE(sh7372_dmae0_resources),
425 .dev = {
426 .platform_data = &dma_platform_data,
427 },
428};
429
430static struct platform_device dma1_device = {
431 .name = "sh-dma-engine",
432 .id = 1,
433 .resource = sh7372_dmae1_resources,
434 .num_resources = ARRAY_SIZE(sh7372_dmae1_resources),
435 .dev = {
436 .platform_data = &dma_platform_data,
437 },
438};
439
440static struct platform_device dma2_device = {
441 .name = "sh-dma-engine",
442 .id = 2,
443 .resource = sh7372_dmae2_resources,
444 .num_resources = ARRAY_SIZE(sh7372_dmae2_resources),
445 .dev = {
446 .platform_data = &dma_platform_data,
447 },
448};
449
Magnus Damm2b7eda62010-02-05 11:14:58 +0000450static struct platform_device *sh7372_early_devices[] __initdata = {
451 &scif0_device,
452 &scif1_device,
453 &scif2_device,
454 &scif3_device,
455 &scif4_device,
456 &scif5_device,
457 &scif6_device,
458 &cmt10_device,
Kuninori Morimotoc1909cc2010-03-11 10:42:47 +0000459 &iic0_device,
460 &iic1_device,
Guennadi Liakhovetski69bf6f42010-05-04 14:07:15 +0000461 &dma0_device,
462 &dma1_device,
463 &dma2_device,
Magnus Damm2b7eda62010-02-05 11:14:58 +0000464};
465
466void __init sh7372_add_standard_devices(void)
467{
468 platform_add_devices(sh7372_early_devices,
469 ARRAY_SIZE(sh7372_early_devices));
470}
471
Magnus Damm2b7eda62010-02-05 11:14:58 +0000472void __init sh7372_add_early_devices(void)
473{
Magnus Damm2b7eda62010-02-05 11:14:58 +0000474 early_platform_add_devices(sh7372_early_devices,
475 ARRAY_SIZE(sh7372_early_devices));
476}