2 * R8A7740 processor support
4 * Copyright (C) 2011 Renesas Solutions Corp.
5 * Copyright (C) 2011 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
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.
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.
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
20 #include <linux/delay.h>
21 #include <linux/kernel.h>
22 #include <linux/init.h>
24 #include <linux/platform_device.h>
25 #include <linux/serial_sci.h>
26 #include <linux/sh_timer.h>
27 #include <mach/r8a7740.h>
28 #include <mach/common.h>
29 #include <asm/mach-types.h>
30 #include <asm/mach/map.h>
31 #include <asm/mach/arch.h>
32 #include <asm/mach/time.h>
34 static struct map_desc r8a7740_io_desc[] __initdata = {
37 * 0xe6000000-0xefffffff -> 0xe6000000-0xefffffff
40 .virtual = 0xe6000000,
41 .pfn = __phys_to_pfn(0xe6000000),
43 .type = MT_DEVICE_NONSHARED
45 #ifdef CONFIG_CACHE_L2X0
48 * 0xf0100000-0xf0101000 -> 0xf0002000-0xf0003000
51 .virtual = 0xf0002000,
52 .pfn = __phys_to_pfn(0xf0100000),
54 .type = MT_DEVICE_NONSHARED
59 void __init r8a7740_map_io(void)
61 iotable_init(r8a7740_io_desc, ARRAY_SIZE(r8a7740_io_desc));
65 static struct plat_sci_port scif0_platform_data = {
66 .mapbase = 0xe6c40000,
67 .flags = UPF_BOOT_AUTOCONF,
68 .scscr = SCSCR_RE | SCSCR_TE,
69 .scbrr_algo_id = SCBRR_ALGO_4,
71 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c00)),
74 static struct platform_device scif0_device = {
78 .platform_data = &scif0_platform_data,
83 static struct plat_sci_port scif1_platform_data = {
84 .mapbase = 0xe6c50000,
85 .flags = UPF_BOOT_AUTOCONF,
86 .scscr = SCSCR_RE | SCSCR_TE,
87 .scbrr_algo_id = SCBRR_ALGO_4,
89 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c20)),
92 static struct platform_device scif1_device = {
96 .platform_data = &scif1_platform_data,
101 static struct plat_sci_port scif2_platform_data = {
102 .mapbase = 0xe6c60000,
103 .flags = UPF_BOOT_AUTOCONF,
104 .scscr = SCSCR_RE | SCSCR_TE,
105 .scbrr_algo_id = SCBRR_ALGO_4,
107 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c40)),
110 static struct platform_device scif2_device = {
114 .platform_data = &scif2_platform_data,
119 static struct plat_sci_port scif3_platform_data = {
120 .mapbase = 0xe6c70000,
121 .flags = UPF_BOOT_AUTOCONF,
122 .scscr = SCSCR_RE | SCSCR_TE,
123 .scbrr_algo_id = SCBRR_ALGO_4,
125 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c60)),
128 static struct platform_device scif3_device = {
132 .platform_data = &scif3_platform_data,
137 static struct plat_sci_port scif4_platform_data = {
138 .mapbase = 0xe6c80000,
139 .flags = UPF_BOOT_AUTOCONF,
140 .scscr = SCSCR_RE | SCSCR_TE,
141 .scbrr_algo_id = SCBRR_ALGO_4,
143 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0d20)),
146 static struct platform_device scif4_device = {
150 .platform_data = &scif4_platform_data,
155 static struct plat_sci_port scif5_platform_data = {
156 .mapbase = 0xe6cb0000,
157 .flags = UPF_BOOT_AUTOCONF,
158 .scscr = SCSCR_RE | SCSCR_TE,
159 .scbrr_algo_id = SCBRR_ALGO_4,
161 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0d40)),
164 static struct platform_device scif5_device = {
168 .platform_data = &scif5_platform_data,
173 static struct plat_sci_port scif6_platform_data = {
174 .mapbase = 0xe6cc0000,
175 .flags = UPF_BOOT_AUTOCONF,
176 .scscr = SCSCR_RE | SCSCR_TE,
177 .scbrr_algo_id = SCBRR_ALGO_4,
179 .irqs = SCIx_IRQ_MUXED(evt2irq(0x04c0)),
182 static struct platform_device scif6_device = {
186 .platform_data = &scif6_platform_data,
191 static struct plat_sci_port scif7_platform_data = {
192 .mapbase = 0xe6cd0000,
193 .flags = UPF_BOOT_AUTOCONF,
194 .scscr = SCSCR_RE | SCSCR_TE,
195 .scbrr_algo_id = SCBRR_ALGO_4,
197 .irqs = SCIx_IRQ_MUXED(evt2irq(0x04e0)),
200 static struct platform_device scif7_device = {
204 .platform_data = &scif7_platform_data,
209 static struct plat_sci_port scifb_platform_data = {
210 .mapbase = 0xe6c30000,
211 .flags = UPF_BOOT_AUTOCONF,
212 .scscr = SCSCR_RE | SCSCR_TE,
213 .scbrr_algo_id = SCBRR_ALGO_4,
215 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0d60)),
218 static struct platform_device scifb_device = {
222 .platform_data = &scifb_platform_data,
227 static struct sh_timer_config cmt10_platform_data = {
229 .channel_offset = 0x10,
231 .clockevent_rating = 125,
232 .clocksource_rating = 125,
235 static struct resource cmt10_resources[] = {
240 .flags = IORESOURCE_MEM,
243 .start = evt2irq(0x0b00),
244 .flags = IORESOURCE_IRQ,
248 static struct platform_device cmt10_device = {
252 .platform_data = &cmt10_platform_data,
254 .resource = cmt10_resources,
255 .num_resources = ARRAY_SIZE(cmt10_resources),
258 static struct platform_device *r8a7740_early_devices[] __initdata = {
272 static struct resource i2c0_resources[] = {
276 .end = 0xfff20425 - 1,
277 .flags = IORESOURCE_MEM,
280 .start = intcs_evt2irq(0xe00),
281 .end = intcs_evt2irq(0xe60),
282 .flags = IORESOURCE_IRQ,
286 static struct resource i2c1_resources[] = {
290 .end = 0xe6c20425 - 1,
291 .flags = IORESOURCE_MEM,
294 .start = evt2irq(0x780), /* IIC1_ALI1 */
295 .end = evt2irq(0x7e0), /* IIC1_DTEI1 */
296 .flags = IORESOURCE_IRQ,
300 static struct platform_device i2c0_device = {
301 .name = "i2c-sh_mobile",
303 .resource = i2c0_resources,
304 .num_resources = ARRAY_SIZE(i2c0_resources),
307 static struct platform_device i2c1_device = {
308 .name = "i2c-sh_mobile",
310 .resource = i2c1_resources,
311 .num_resources = ARRAY_SIZE(i2c1_resources),
314 static struct platform_device *r8a7740_late_devices[] __initdata = {
320 #define ICSTART 0x0070
322 #define i2c_read(reg, offset) ioread8(reg + offset)
323 #define i2c_write(reg, offset, data) iowrite8(data, reg + offset)
326 * r8a7740 chip has lasting errata on I2C I/O pad reset.
327 * this is work-around for it.
329 static void r8a7740_i2c_workaround(struct platform_device *pdev)
331 struct resource *res;
334 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
335 if (unlikely(!res)) {
336 pr_err("r8a7740 i2c workaround fail (cannot find resource)\n");
340 reg = ioremap(res->start, resource_size(res));
341 if (unlikely(!reg)) {
342 pr_err("r8a7740 i2c workaround fail (cannot map IO)\n");
346 i2c_write(reg, ICCR, i2c_read(reg, ICCR) | 0x80);
347 i2c_read(reg, ICCR); /* dummy read */
349 i2c_write(reg, ICSTART, i2c_read(reg, ICSTART) | 0x10);
350 i2c_read(reg, ICSTART); /* dummy read */
354 i2c_write(reg, ICCR, 0x01);
356 i2c_write(reg, ICSTART, 0x00);
357 i2c_read(reg, ICSTART);
359 i2c_write(reg, ICCR, 0x10);
361 i2c_write(reg, ICCR, 0x00);
363 i2c_write(reg, ICCR, 0x10);
369 void __init r8a7740_add_standard_devices(void)
371 /* I2C work-around */
372 r8a7740_i2c_workaround(&i2c0_device);
373 r8a7740_i2c_workaround(&i2c1_device);
375 platform_add_devices(r8a7740_early_devices,
376 ARRAY_SIZE(r8a7740_early_devices));
377 platform_add_devices(r8a7740_late_devices,
378 ARRAY_SIZE(r8a7740_late_devices));
381 static void __init r8a7740_earlytimer_init(void)
383 r8a7740_clock_init(0);
384 shmobile_earlytimer_init();
387 void __init r8a7740_add_early_devices(void)
389 early_platform_add_devices(r8a7740_early_devices,
390 ARRAY_SIZE(r8a7740_early_devices));
392 /* setup early console here as well */
393 shmobile_setup_console();
395 /* override timer setup with soc-specific code */
396 shmobile_timer.init = r8a7740_earlytimer_init;