blob: a35a6e0ff29800b6a2a0bd54541d58d4ddb5cbd4 [file] [log] [blame]
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -08001/*
2 * R8A7740 processor support
3 *
4 * Copyright (C) 2011 Renesas Solutions Corp.
5 * Copyright (C) 2011 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
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 */
Kuninori Morimoto6831f3a2011-11-10 18:46:23 -080020#include <linux/delay.h>
Kuninori Morimoto3841e6f52012-04-24 02:10:05 -070021#include <linux/dma-mapping.h>
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -080022#include <linux/kernel.h>
23#include <linux/init.h>
Kuninori Morimoto6831f3a2011-11-10 18:46:23 -080024#include <linux/io.h>
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -080025#include <linux/platform_device.h>
Magnus Damm755d57b2012-07-06 17:08:07 +090026#include <linux/of_platform.h>
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -080027#include <linux/serial_sci.h>
Kuninori Morimoto643c3302012-06-25 03:36:49 -070028#include <linux/sh_dma.h>
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -080029#include <linux/sh_timer.h>
Kuninori Morimoto643c3302012-06-25 03:36:49 -070030#include <linux/dma-mapping.h>
Kuninori Morimotod7de9382012-06-25 03:43:10 -070031#include <mach/dma-register.h>
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -080032#include <mach/r8a7740.h>
Kuninori Morimoto84592932012-07-05 01:25:58 -070033#include <mach/pm-rmobile.h>
Magnus Dammd3ab7222012-02-29 21:37:35 +090034#include <mach/common.h>
Rob Herring250a2722012-01-03 16:57:33 -060035#include <mach/irqs.h>
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -080036#include <asm/mach-types.h>
Magnus Dammd3ab7222012-02-29 21:37:35 +090037#include <asm/mach/map.h>
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -080038#include <asm/mach/arch.h>
Magnus Damm23e5bc02012-03-06 17:36:53 +090039#include <asm/mach/time.h>
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -080040
Magnus Dammd3ab7222012-02-29 21:37:35 +090041static struct map_desc r8a7740_io_desc[] __initdata = {
42 /*
43 * for CPGA/INTC/PFC
44 * 0xe6000000-0xefffffff -> 0xe6000000-0xefffffff
45 */
46 {
47 .virtual = 0xe6000000,
48 .pfn = __phys_to_pfn(0xe6000000),
49 .length = 160 << 20,
50 .type = MT_DEVICE_NONSHARED
51 },
52#ifdef CONFIG_CACHE_L2X0
53 /*
54 * for l2x0_init()
55 * 0xf0100000-0xf0101000 -> 0xf0002000-0xf0003000
56 */
57 {
58 .virtual = 0xf0002000,
59 .pfn = __phys_to_pfn(0xf0100000),
60 .length = PAGE_SIZE,
61 .type = MT_DEVICE_NONSHARED
62 },
63#endif
64};
65
66void __init r8a7740_map_io(void)
67{
68 iotable_init(r8a7740_io_desc, ARRAY_SIZE(r8a7740_io_desc));
69}
70
Laurent Pinchart02b01ad2012-12-15 23:51:25 +010071/* PFC */
72static struct resource r8a7740_pfc_resources[] = {
73 [0] = {
74 .start = 0xe6050000,
75 .end = 0xe6057fff,
76 .flags = IORESOURCE_MEM,
77 },
78 [1] = {
79 .start = 0xe605800c,
80 .end = 0xe605802b,
81 .flags = IORESOURCE_MEM,
82 }
83};
84
85static struct platform_device r8a7740_pfc_device = {
86 .name = "pfc-r8a7740",
87 .id = -1,
88 .resource = r8a7740_pfc_resources,
89 .num_resources = ARRAY_SIZE(r8a7740_pfc_resources),
90};
91
92void __init r8a7740_pinmux_init(void)
93{
94 platform_device_register(&r8a7740_pfc_device);
95}
96
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -080097/* SCIFA0 */
98static struct plat_sci_port scif0_platform_data = {
99 .mapbase = 0xe6c40000,
100 .flags = UPF_BOOT_AUTOCONF,
101 .scscr = SCSCR_RE | SCSCR_TE,
102 .scbrr_algo_id = SCBRR_ALGO_4,
103 .type = PORT_SCIFA,
Kuninori Morimoto215d6cc2011-11-10 18:46:35 -0800104 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c00)),
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800105};
106
107static struct platform_device scif0_device = {
108 .name = "sh-sci",
109 .id = 0,
110 .dev = {
111 .platform_data = &scif0_platform_data,
112 },
113};
114
115/* SCIFA1 */
116static struct plat_sci_port scif1_platform_data = {
117 .mapbase = 0xe6c50000,
118 .flags = UPF_BOOT_AUTOCONF,
119 .scscr = SCSCR_RE | SCSCR_TE,
120 .scbrr_algo_id = SCBRR_ALGO_4,
121 .type = PORT_SCIFA,
Kuninori Morimoto215d6cc2011-11-10 18:46:35 -0800122 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c20)),
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800123};
124
125static struct platform_device scif1_device = {
126 .name = "sh-sci",
127 .id = 1,
128 .dev = {
129 .platform_data = &scif1_platform_data,
130 },
131};
132
133/* SCIFA2 */
134static struct plat_sci_port scif2_platform_data = {
135 .mapbase = 0xe6c60000,
136 .flags = UPF_BOOT_AUTOCONF,
137 .scscr = SCSCR_RE | SCSCR_TE,
138 .scbrr_algo_id = SCBRR_ALGO_4,
139 .type = PORT_SCIFA,
Kuninori Morimoto215d6cc2011-11-10 18:46:35 -0800140 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c40)),
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800141};
142
143static struct platform_device scif2_device = {
144 .name = "sh-sci",
145 .id = 2,
146 .dev = {
147 .platform_data = &scif2_platform_data,
148 },
149};
150
151/* SCIFA3 */
152static struct plat_sci_port scif3_platform_data = {
153 .mapbase = 0xe6c70000,
154 .flags = UPF_BOOT_AUTOCONF,
155 .scscr = SCSCR_RE | SCSCR_TE,
156 .scbrr_algo_id = SCBRR_ALGO_4,
157 .type = PORT_SCIFA,
Kuninori Morimoto215d6cc2011-11-10 18:46:35 -0800158 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c60)),
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800159};
160
161static struct platform_device scif3_device = {
162 .name = "sh-sci",
163 .id = 3,
164 .dev = {
165 .platform_data = &scif3_platform_data,
166 },
167};
168
169/* SCIFA4 */
170static struct plat_sci_port scif4_platform_data = {
171 .mapbase = 0xe6c80000,
172 .flags = UPF_BOOT_AUTOCONF,
173 .scscr = SCSCR_RE | SCSCR_TE,
174 .scbrr_algo_id = SCBRR_ALGO_4,
175 .type = PORT_SCIFA,
Kuninori Morimoto215d6cc2011-11-10 18:46:35 -0800176 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0d20)),
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800177};
178
179static struct platform_device scif4_device = {
180 .name = "sh-sci",
181 .id = 4,
182 .dev = {
183 .platform_data = &scif4_platform_data,
184 },
185};
186
187/* SCIFA5 */
188static struct plat_sci_port scif5_platform_data = {
189 .mapbase = 0xe6cb0000,
190 .flags = UPF_BOOT_AUTOCONF,
191 .scscr = SCSCR_RE | SCSCR_TE,
192 .scbrr_algo_id = SCBRR_ALGO_4,
193 .type = PORT_SCIFA,
Kuninori Morimoto215d6cc2011-11-10 18:46:35 -0800194 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0d40)),
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800195};
196
197static struct platform_device scif5_device = {
198 .name = "sh-sci",
199 .id = 5,
200 .dev = {
201 .platform_data = &scif5_platform_data,
202 },
203};
204
205/* SCIFA6 */
206static struct plat_sci_port scif6_platform_data = {
207 .mapbase = 0xe6cc0000,
208 .flags = UPF_BOOT_AUTOCONF,
209 .scscr = SCSCR_RE | SCSCR_TE,
210 .scbrr_algo_id = SCBRR_ALGO_4,
211 .type = PORT_SCIFA,
Kuninori Morimoto215d6cc2011-11-10 18:46:35 -0800212 .irqs = SCIx_IRQ_MUXED(evt2irq(0x04c0)),
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800213};
214
215static struct platform_device scif6_device = {
216 .name = "sh-sci",
217 .id = 6,
218 .dev = {
219 .platform_data = &scif6_platform_data,
220 },
221};
222
223/* SCIFA7 */
224static struct plat_sci_port scif7_platform_data = {
225 .mapbase = 0xe6cd0000,
226 .flags = UPF_BOOT_AUTOCONF,
227 .scscr = SCSCR_RE | SCSCR_TE,
228 .scbrr_algo_id = SCBRR_ALGO_4,
229 .type = PORT_SCIFA,
Kuninori Morimoto215d6cc2011-11-10 18:46:35 -0800230 .irqs = SCIx_IRQ_MUXED(evt2irq(0x04e0)),
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800231};
232
233static struct platform_device scif7_device = {
234 .name = "sh-sci",
235 .id = 7,
236 .dev = {
237 .platform_data = &scif7_platform_data,
238 },
239};
240
241/* SCIFB */
242static struct plat_sci_port scifb_platform_data = {
243 .mapbase = 0xe6c30000,
244 .flags = UPF_BOOT_AUTOCONF,
245 .scscr = SCSCR_RE | SCSCR_TE,
246 .scbrr_algo_id = SCBRR_ALGO_4,
247 .type = PORT_SCIFB,
Kuninori Morimoto215d6cc2011-11-10 18:46:35 -0800248 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0d60)),
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800249};
250
251static struct platform_device scifb_device = {
252 .name = "sh-sci",
253 .id = 8,
254 .dev = {
255 .platform_data = &scifb_platform_data,
256 },
257};
258
259/* CMT */
260static struct sh_timer_config cmt10_platform_data = {
261 .name = "CMT10",
262 .channel_offset = 0x10,
263 .timer_bit = 0,
264 .clockevent_rating = 125,
265 .clocksource_rating = 125,
266};
267
268static struct resource cmt10_resources[] = {
269 [0] = {
270 .name = "CMT10",
271 .start = 0xe6138010,
272 .end = 0xe613801b,
273 .flags = IORESOURCE_MEM,
274 },
275 [1] = {
Kuninori Morimoto215d6cc2011-11-10 18:46:35 -0800276 .start = evt2irq(0x0b00),
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800277 .flags = IORESOURCE_IRQ,
278 },
279};
280
281static struct platform_device cmt10_device = {
282 .name = "sh_cmt",
283 .id = 10,
284 .dev = {
285 .platform_data = &cmt10_platform_data,
286 },
287 .resource = cmt10_resources,
288 .num_resources = ARRAY_SIZE(cmt10_resources),
289};
290
291static struct platform_device *r8a7740_early_devices[] __initdata = {
292 &scif0_device,
293 &scif1_device,
294 &scif2_device,
295 &scif3_device,
296 &scif4_device,
297 &scif5_device,
298 &scif6_device,
299 &scif7_device,
300 &scifb_device,
301 &cmt10_device,
302};
303
Kuninori Morimoto643c3302012-06-25 03:36:49 -0700304/* DMA */
Kuninori Morimoto643c3302012-06-25 03:36:49 -0700305static const struct sh_dmae_slave_config r8a7740_dmae_slaves[] = {
306 {
Kuninori Morimotocb76eb82012-06-25 03:37:00 -0700307 .slave_id = SHDMA_SLAVE_SDHI0_TX,
308 .addr = 0xe6850030,
309 .chcr = CHCR_TX(XMIT_SZ_16BIT),
310 .mid_rid = 0xc1,
311 }, {
312 .slave_id = SHDMA_SLAVE_SDHI0_RX,
313 .addr = 0xe6850030,
314 .chcr = CHCR_RX(XMIT_SZ_16BIT),
315 .mid_rid = 0xc2,
316 }, {
317 .slave_id = SHDMA_SLAVE_SDHI1_TX,
318 .addr = 0xe6860030,
319 .chcr = CHCR_TX(XMIT_SZ_16BIT),
320 .mid_rid = 0xc9,
321 }, {
322 .slave_id = SHDMA_SLAVE_SDHI1_RX,
323 .addr = 0xe6860030,
324 .chcr = CHCR_RX(XMIT_SZ_16BIT),
325 .mid_rid = 0xca,
326 }, {
327 .slave_id = SHDMA_SLAVE_SDHI2_TX,
328 .addr = 0xe6870030,
329 .chcr = CHCR_TX(XMIT_SZ_16BIT),
330 .mid_rid = 0xcd,
331 }, {
332 .slave_id = SHDMA_SLAVE_SDHI2_RX,
333 .addr = 0xe6870030,
334 .chcr = CHCR_RX(XMIT_SZ_16BIT),
335 .mid_rid = 0xce,
336 }, {
Kuninori Morimoto643c3302012-06-25 03:36:49 -0700337 .slave_id = SHDMA_SLAVE_FSIA_TX,
338 .addr = 0xfe1f0024,
339 .chcr = CHCR_TX(XMIT_SZ_32BIT),
340 .mid_rid = 0xb1,
341 }, {
342 .slave_id = SHDMA_SLAVE_FSIA_RX,
343 .addr = 0xfe1f0020,
344 .chcr = CHCR_RX(XMIT_SZ_32BIT),
345 .mid_rid = 0xb2,
346 }, {
347 .slave_id = SHDMA_SLAVE_FSIB_TX,
348 .addr = 0xfe1f0064,
349 .chcr = CHCR_TX(XMIT_SZ_32BIT),
350 .mid_rid = 0xb5,
351 },
352};
353
354#define DMA_CHANNEL(a, b, c) \
355{ \
356 .offset = a, \
357 .dmars = b, \
358 .dmars_bit = c, \
359 .chclr_offset = (0x220 - 0x20) + a \
360}
361
362static const struct sh_dmae_channel r8a7740_dmae_channels[] = {
363 DMA_CHANNEL(0x00, 0, 0),
364 DMA_CHANNEL(0x10, 0, 8),
365 DMA_CHANNEL(0x20, 4, 0),
366 DMA_CHANNEL(0x30, 4, 8),
367 DMA_CHANNEL(0x50, 8, 0),
368 DMA_CHANNEL(0x60, 8, 8),
369};
370
Kuninori Morimoto643c3302012-06-25 03:36:49 -0700371static struct sh_dmae_pdata dma_platform_data = {
372 .slave = r8a7740_dmae_slaves,
373 .slave_num = ARRAY_SIZE(r8a7740_dmae_slaves),
374 .channel = r8a7740_dmae_channels,
375 .channel_num = ARRAY_SIZE(r8a7740_dmae_channels),
Kuninori Morimotod7de9382012-06-25 03:43:10 -0700376 .ts_low_shift = TS_LOW_SHIFT,
377 .ts_low_mask = TS_LOW_BIT << TS_LOW_SHIFT,
378 .ts_high_shift = TS_HI_SHIFT,
379 .ts_high_mask = TS_HI_BIT << TS_HI_SHIFT,
380 .ts_shift = dma_ts_shift,
381 .ts_shift_num = ARRAY_SIZE(dma_ts_shift),
Kuninori Morimoto643c3302012-06-25 03:36:49 -0700382 .dmaor_init = DMAOR_DME,
383 .chclr_present = 1,
384};
385
386/* Resource order important! */
387static struct resource r8a7740_dmae0_resources[] = {
388 {
389 /* Channel registers and DMAOR */
390 .start = 0xfe008020,
391 .end = 0xfe00828f,
392 .flags = IORESOURCE_MEM,
393 },
394 {
395 /* DMARSx */
396 .start = 0xfe009000,
397 .end = 0xfe00900b,
398 .flags = IORESOURCE_MEM,
399 },
400 {
401 .name = "error_irq",
402 .start = evt2irq(0x20c0),
403 .end = evt2irq(0x20c0),
404 .flags = IORESOURCE_IRQ,
405 },
406 {
407 /* IRQ for channels 0-5 */
408 .start = evt2irq(0x2000),
409 .end = evt2irq(0x20a0),
410 .flags = IORESOURCE_IRQ,
411 },
412};
413
414/* Resource order important! */
415static struct resource r8a7740_dmae1_resources[] = {
416 {
417 /* Channel registers and DMAOR */
418 .start = 0xfe018020,
419 .end = 0xfe01828f,
420 .flags = IORESOURCE_MEM,
421 },
422 {
423 /* DMARSx */
424 .start = 0xfe019000,
425 .end = 0xfe01900b,
426 .flags = IORESOURCE_MEM,
427 },
428 {
429 .name = "error_irq",
430 .start = evt2irq(0x21c0),
431 .end = evt2irq(0x21c0),
432 .flags = IORESOURCE_IRQ,
433 },
434 {
435 /* IRQ for channels 0-5 */
436 .start = evt2irq(0x2100),
437 .end = evt2irq(0x21a0),
438 .flags = IORESOURCE_IRQ,
439 },
440};
441
442/* Resource order important! */
443static struct resource r8a7740_dmae2_resources[] = {
444 {
445 /* Channel registers and DMAOR */
446 .start = 0xfe028020,
447 .end = 0xfe02828f,
448 .flags = IORESOURCE_MEM,
449 },
450 {
451 /* DMARSx */
452 .start = 0xfe029000,
453 .end = 0xfe02900b,
454 .flags = IORESOURCE_MEM,
455 },
456 {
457 .name = "error_irq",
458 .start = evt2irq(0x22c0),
459 .end = evt2irq(0x22c0),
460 .flags = IORESOURCE_IRQ,
461 },
462 {
463 /* IRQ for channels 0-5 */
464 .start = evt2irq(0x2200),
465 .end = evt2irq(0x22a0),
466 .flags = IORESOURCE_IRQ,
467 },
468};
469
470static struct platform_device dma0_device = {
471 .name = "sh-dma-engine",
472 .id = 0,
473 .resource = r8a7740_dmae0_resources,
474 .num_resources = ARRAY_SIZE(r8a7740_dmae0_resources),
475 .dev = {
476 .platform_data = &dma_platform_data,
477 },
478};
479
480static struct platform_device dma1_device = {
481 .name = "sh-dma-engine",
482 .id = 1,
483 .resource = r8a7740_dmae1_resources,
484 .num_resources = ARRAY_SIZE(r8a7740_dmae1_resources),
485 .dev = {
486 .platform_data = &dma_platform_data,
487 },
488};
489
490static struct platform_device dma2_device = {
491 .name = "sh-dma-engine",
492 .id = 2,
493 .resource = r8a7740_dmae2_resources,
494 .num_resources = ARRAY_SIZE(r8a7740_dmae2_resources),
495 .dev = {
496 .platform_data = &dma_platform_data,
497 },
498};
499
Kuninori Morimotodbf382e2012-06-25 03:37:10 -0700500/* USB-DMAC */
Kuninori Morimotodbf382e2012-06-25 03:37:10 -0700501static const struct sh_dmae_channel r8a7740_usb_dma_channels[] = {
502 {
503 .offset = 0,
504 }, {
505 .offset = 0x20,
506 },
507};
508
Kuninori Morimotodbf382e2012-06-25 03:37:10 -0700509static const struct sh_dmae_slave_config r8a7740_usb_dma_slaves[] = {
510 {
511 .slave_id = SHDMA_SLAVE_USBHS_TX,
512 .chcr = USBTS_INDEX2VAL(USBTS_XMIT_SZ_8BYTE),
513 }, {
514 .slave_id = SHDMA_SLAVE_USBHS_RX,
515 .chcr = USBTS_INDEX2VAL(USBTS_XMIT_SZ_8BYTE),
516 },
517};
518
519static struct sh_dmae_pdata usb_dma_platform_data = {
520 .slave = r8a7740_usb_dma_slaves,
521 .slave_num = ARRAY_SIZE(r8a7740_usb_dma_slaves),
522 .channel = r8a7740_usb_dma_channels,
523 .channel_num = ARRAY_SIZE(r8a7740_usb_dma_channels),
Kuninori Morimotod7de9382012-06-25 03:43:10 -0700524 .ts_low_shift = USBTS_LOW_SHIFT,
525 .ts_low_mask = USBTS_LOW_BIT << USBTS_LOW_SHIFT,
526 .ts_high_shift = USBTS_HI_SHIFT,
527 .ts_high_mask = USBTS_HI_BIT << USBTS_HI_SHIFT,
Kuninori Morimotodbf382e2012-06-25 03:37:10 -0700528 .ts_shift = dma_usbts_shift,
529 .ts_shift_num = ARRAY_SIZE(dma_usbts_shift),
530 .dmaor_init = DMAOR_DME,
531 .chcr_offset = 0x14,
532 .chcr_ie_bit = 1 << 5,
533 .dmaor_is_32bit = 1,
534 .needs_tend_set = 1,
535 .no_dmars = 1,
536 .slave_only = 1,
537};
538
539static struct resource r8a7740_usb_dma_resources[] = {
540 {
541 /* Channel registers and DMAOR */
542 .start = 0xe68a0020,
543 .end = 0xe68a0064 - 1,
544 .flags = IORESOURCE_MEM,
545 },
546 {
547 /* VCR/SWR/DMICR */
548 .start = 0xe68a0000,
549 .end = 0xe68a0014 - 1,
550 .flags = IORESOURCE_MEM,
551 },
552 {
553 /* IRQ for channels */
554 .start = evt2irq(0x0a00),
555 .end = evt2irq(0x0a00),
556 .flags = IORESOURCE_IRQ,
557 },
558};
559
560static struct platform_device usb_dma_device = {
561 .name = "sh-dma-engine",
562 .id = 3,
563 .resource = r8a7740_usb_dma_resources,
564 .num_resources = ARRAY_SIZE(r8a7740_usb_dma_resources),
565 .dev = {
566 .platform_data = &usb_dma_platform_data,
567 },
568};
569
Kuninori Morimoto6831f3a2011-11-10 18:46:23 -0800570/* I2C */
571static struct resource i2c0_resources[] = {
572 [0] = {
573 .name = "IIC0",
574 .start = 0xfff20000,
575 .end = 0xfff20425 - 1,
576 .flags = IORESOURCE_MEM,
577 },
578 [1] = {
Kuninori Morimoto215d6cc2011-11-10 18:46:35 -0800579 .start = intcs_evt2irq(0xe00),
580 .end = intcs_evt2irq(0xe60),
Kuninori Morimoto6831f3a2011-11-10 18:46:23 -0800581 .flags = IORESOURCE_IRQ,
582 },
583};
584
585static struct resource i2c1_resources[] = {
586 [0] = {
587 .name = "IIC1",
588 .start = 0xe6c20000,
589 .end = 0xe6c20425 - 1,
590 .flags = IORESOURCE_MEM,
591 },
592 [1] = {
Kuninori Morimoto215d6cc2011-11-10 18:46:35 -0800593 .start = evt2irq(0x780), /* IIC1_ALI1 */
594 .end = evt2irq(0x7e0), /* IIC1_DTEI1 */
Kuninori Morimoto6831f3a2011-11-10 18:46:23 -0800595 .flags = IORESOURCE_IRQ,
596 },
597};
598
599static struct platform_device i2c0_device = {
600 .name = "i2c-sh_mobile",
601 .id = 0,
602 .resource = i2c0_resources,
603 .num_resources = ARRAY_SIZE(i2c0_resources),
604};
605
606static struct platform_device i2c1_device = {
607 .name = "i2c-sh_mobile",
608 .id = 1,
609 .resource = i2c1_resources,
610 .num_resources = ARRAY_SIZE(i2c1_resources),
611};
612
Nobuhiro Iwamatsu86bc52e2012-09-14 13:27:13 +0900613static struct resource pmu_resources[] = {
614 [0] = {
615 .start = evt2irq(0x19a0),
616 .end = evt2irq(0x19a0),
617 .flags = IORESOURCE_IRQ,
618 },
619};
620
621static struct platform_device pmu_device = {
622 .name = "arm-pmu",
623 .id = -1,
624 .num_resources = ARRAY_SIZE(pmu_resources),
625 .resource = pmu_resources,
626};
627
Kuninori Morimoto6831f3a2011-11-10 18:46:23 -0800628static struct platform_device *r8a7740_late_devices[] __initdata = {
629 &i2c0_device,
630 &i2c1_device,
Kuninori Morimoto643c3302012-06-25 03:36:49 -0700631 &dma0_device,
632 &dma1_device,
633 &dma2_device,
Kuninori Morimotodbf382e2012-06-25 03:37:10 -0700634 &usb_dma_device,
Nobuhiro Iwamatsu86bc52e2012-09-14 13:27:13 +0900635 &pmu_device,
Kuninori Morimoto6831f3a2011-11-10 18:46:23 -0800636};
637
Kuninori Morimotod49679e2012-06-12 02:36:21 -0700638/*
639 * r8a7740 chip has lasting errata on MERAM buffer.
640 * this is work-around for it.
641 * see
642 * "Media RAM (MERAM)" on r8a7740 documentation
643 */
644#define MEBUFCNTR 0xFE950098
645void r8a7740_meram_workaround(void)
646{
647 void __iomem *reg;
648
649 reg = ioremap_nocache(MEBUFCNTR, 4);
650 if (reg) {
651 iowrite32(0x01600164, reg);
652 iounmap(reg);
653 }
654}
655
Kuninori Morimoto6831f3a2011-11-10 18:46:23 -0800656#define ICCR 0x0004
657#define ICSTART 0x0070
658
659#define i2c_read(reg, offset) ioread8(reg + offset)
660#define i2c_write(reg, offset, data) iowrite8(data, reg + offset)
661
662/*
663 * r8a7740 chip has lasting errata on I2C I/O pad reset.
664 * this is work-around for it.
665 */
666static void r8a7740_i2c_workaround(struct platform_device *pdev)
667{
668 struct resource *res;
669 void __iomem *reg;
670
671 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
672 if (unlikely(!res)) {
673 pr_err("r8a7740 i2c workaround fail (cannot find resource)\n");
674 return;
675 }
676
677 reg = ioremap(res->start, resource_size(res));
678 if (unlikely(!reg)) {
679 pr_err("r8a7740 i2c workaround fail (cannot map IO)\n");
680 return;
681 }
682
683 i2c_write(reg, ICCR, i2c_read(reg, ICCR) | 0x80);
684 i2c_read(reg, ICCR); /* dummy read */
685
686 i2c_write(reg, ICSTART, i2c_read(reg, ICSTART) | 0x10);
687 i2c_read(reg, ICSTART); /* dummy read */
688
Kuninori Morimoto42287162012-04-13 02:41:06 -0700689 udelay(10);
Kuninori Morimoto6831f3a2011-11-10 18:46:23 -0800690
691 i2c_write(reg, ICCR, 0x01);
Kuninori Morimoto6831f3a2011-11-10 18:46:23 -0800692 i2c_write(reg, ICSTART, 0x00);
Kuninori Morimoto42287162012-04-13 02:41:06 -0700693
694 udelay(10);
Kuninori Morimoto6831f3a2011-11-10 18:46:23 -0800695
696 i2c_write(reg, ICCR, 0x10);
Kuninori Morimoto42287162012-04-13 02:41:06 -0700697 udelay(10);
Kuninori Morimoto6831f3a2011-11-10 18:46:23 -0800698 i2c_write(reg, ICCR, 0x00);
Kuninori Morimoto42287162012-04-13 02:41:06 -0700699 udelay(10);
Kuninori Morimoto6831f3a2011-11-10 18:46:23 -0800700 i2c_write(reg, ICCR, 0x10);
Kuninori Morimoto42287162012-04-13 02:41:06 -0700701 udelay(10);
Kuninori Morimoto6831f3a2011-11-10 18:46:23 -0800702
703 iounmap(reg);
704}
705
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800706void __init r8a7740_add_standard_devices(void)
707{
Kuninori Morimoto6831f3a2011-11-10 18:46:23 -0800708 /* I2C work-around */
709 r8a7740_i2c_workaround(&i2c0_device);
710 r8a7740_i2c_workaround(&i2c1_device);
711
Rafael J. Wysocki7b567402012-08-07 01:13:37 +0200712 r8a7740_init_pm_domains();
Kuninori Morimoto84592932012-07-05 01:25:58 -0700713
714 /* add devices */
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800715 platform_add_devices(r8a7740_early_devices,
716 ARRAY_SIZE(r8a7740_early_devices));
Kuninori Morimoto6831f3a2011-11-10 18:46:23 -0800717 platform_add_devices(r8a7740_late_devices,
718 ARRAY_SIZE(r8a7740_late_devices));
Kuninori Morimoto802a5632012-07-05 01:26:31 -0700719
720 /* add devices to PM domain */
721
Rafael J. Wysocki8bdd9462012-08-07 01:07:01 +0200722 rmobile_add_device_to_domain("A3SP", &scif0_device);
723 rmobile_add_device_to_domain("A3SP", &scif1_device);
724 rmobile_add_device_to_domain("A3SP", &scif2_device);
725 rmobile_add_device_to_domain("A3SP", &scif3_device);
726 rmobile_add_device_to_domain("A3SP", &scif4_device);
727 rmobile_add_device_to_domain("A3SP", &scif5_device);
728 rmobile_add_device_to_domain("A3SP", &scif6_device);
729 rmobile_add_device_to_domain("A3SP", &scif7_device);
730 rmobile_add_device_to_domain("A3SP", &scifb_device);
731 rmobile_add_device_to_domain("A3SP", &i2c1_device);
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800732}
733
Magnus Damm23e5bc02012-03-06 17:36:53 +0900734static void __init r8a7740_earlytimer_init(void)
735{
736 r8a7740_clock_init(0);
737 shmobile_earlytimer_init();
738}
739
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800740void __init r8a7740_add_early_devices(void)
741{
742 early_platform_add_devices(r8a7740_early_devices,
743 ARRAY_SIZE(r8a7740_early_devices));
Magnus Dammd3ab7222012-02-29 21:37:35 +0900744
745 /* setup early console here as well */
746 shmobile_setup_console();
Magnus Damm23e5bc02012-03-06 17:36:53 +0900747
748 /* override timer setup with soc-specific code */
749 shmobile_timer.init = r8a7740_earlytimer_init;
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800750}
Magnus Damm755d57b2012-07-06 17:08:07 +0900751
752#ifdef CONFIG_USE_OF
753
754void __init r8a7740_add_early_devices_dt(void)
755{
756 shmobile_setup_delay(800, 1, 3); /* Cortex-A9 @ 800MHz */
757
758 early_platform_add_devices(r8a7740_early_devices,
759 ARRAY_SIZE(r8a7740_early_devices));
760
761 /* setup early console here as well */
762 shmobile_setup_console();
763}
764
765static const struct of_dev_auxdata r8a7740_auxdata_lookup[] __initconst = {
766 { }
767};
768
769void __init r8a7740_add_standard_devices_dt(void)
770{
771 /* clocks are setup late during boot in the case of DT */
772 r8a7740_clock_init(0);
773
774 platform_add_devices(r8a7740_early_devices,
775 ARRAY_SIZE(r8a7740_early_devices));
776
777 of_platform_populate(NULL, of_default_bus_match_table,
778 r8a7740_auxdata_lookup, NULL);
779}
780
781static const char *r8a7740_boards_compat_dt[] __initdata = {
782 "renesas,r8a7740",
783 NULL,
784};
785
Kuninori Morimotoa41acc42012-10-21 22:15:13 -0700786DT_MACHINE_START(R8A7740_DT, "Generic R8A7740 (Flattened Device Tree)")
Magnus Damm755d57b2012-07-06 17:08:07 +0900787 .map_io = r8a7740_map_io,
788 .init_early = r8a7740_add_early_devices_dt,
789 .init_irq = r8a7740_init_irq,
790 .handle_irq = shmobile_handle_irq_intc,
791 .init_machine = r8a7740_add_standard_devices_dt,
792 .timer = &shmobile_timer,
793 .dt_compat = r8a7740_boards_compat_dt,
794MACHINE_END
795
796#endif /* CONFIG_USE_OF */