blob: 34a1548dbda6ca201159d8041b61bb8ec854ef16 [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 Morimoto6c01ba42011-11-10 18:45:52 -080021#include <linux/kernel.h>
22#include <linux/init.h>
Kuninori Morimoto6831f3a2011-11-10 18:46:23 -080023#include <linux/io.h>
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -080024#include <linux/platform_device.h>
25#include <linux/serial_sci.h>
26#include <linux/sh_timer.h>
27#include <mach/r8a7740.h>
Magnus Dammd3ab7222012-02-29 21:37:35 +090028#include <mach/common.h>
Rob Herring250a2722012-01-03 16:57:33 -060029#include <mach/irqs.h>
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -080030#include <asm/mach-types.h>
Magnus Dammd3ab7222012-02-29 21:37:35 +090031#include <asm/mach/map.h>
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -080032#include <asm/mach/arch.h>
Magnus Damm23e5bc02012-03-06 17:36:53 +090033#include <asm/mach/time.h>
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -080034
Magnus Dammd3ab7222012-02-29 21:37:35 +090035static struct map_desc r8a7740_io_desc[] __initdata = {
36 /*
37 * for CPGA/INTC/PFC
38 * 0xe6000000-0xefffffff -> 0xe6000000-0xefffffff
39 */
40 {
41 .virtual = 0xe6000000,
42 .pfn = __phys_to_pfn(0xe6000000),
43 .length = 160 << 20,
44 .type = MT_DEVICE_NONSHARED
45 },
46#ifdef CONFIG_CACHE_L2X0
47 /*
48 * for l2x0_init()
49 * 0xf0100000-0xf0101000 -> 0xf0002000-0xf0003000
50 */
51 {
52 .virtual = 0xf0002000,
53 .pfn = __phys_to_pfn(0xf0100000),
54 .length = PAGE_SIZE,
55 .type = MT_DEVICE_NONSHARED
56 },
57#endif
58};
59
60void __init r8a7740_map_io(void)
61{
62 iotable_init(r8a7740_io_desc, ARRAY_SIZE(r8a7740_io_desc));
63}
64
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -080065/* SCIFA0 */
66static struct plat_sci_port scif0_platform_data = {
67 .mapbase = 0xe6c40000,
68 .flags = UPF_BOOT_AUTOCONF,
69 .scscr = SCSCR_RE | SCSCR_TE,
70 .scbrr_algo_id = SCBRR_ALGO_4,
71 .type = PORT_SCIFA,
Kuninori Morimoto215d6cc2011-11-10 18:46:35 -080072 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c00)),
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -080073};
74
75static struct platform_device scif0_device = {
76 .name = "sh-sci",
77 .id = 0,
78 .dev = {
79 .platform_data = &scif0_platform_data,
80 },
81};
82
83/* SCIFA1 */
84static struct plat_sci_port scif1_platform_data = {
85 .mapbase = 0xe6c50000,
86 .flags = UPF_BOOT_AUTOCONF,
87 .scscr = SCSCR_RE | SCSCR_TE,
88 .scbrr_algo_id = SCBRR_ALGO_4,
89 .type = PORT_SCIFA,
Kuninori Morimoto215d6cc2011-11-10 18:46:35 -080090 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c20)),
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -080091};
92
93static struct platform_device scif1_device = {
94 .name = "sh-sci",
95 .id = 1,
96 .dev = {
97 .platform_data = &scif1_platform_data,
98 },
99};
100
101/* SCIFA2 */
102static struct plat_sci_port scif2_platform_data = {
103 .mapbase = 0xe6c60000,
104 .flags = UPF_BOOT_AUTOCONF,
105 .scscr = SCSCR_RE | SCSCR_TE,
106 .scbrr_algo_id = SCBRR_ALGO_4,
107 .type = PORT_SCIFA,
Kuninori Morimoto215d6cc2011-11-10 18:46:35 -0800108 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c40)),
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800109};
110
111static struct platform_device scif2_device = {
112 .name = "sh-sci",
113 .id = 2,
114 .dev = {
115 .platform_data = &scif2_platform_data,
116 },
117};
118
119/* SCIFA3 */
120static struct plat_sci_port scif3_platform_data = {
121 .mapbase = 0xe6c70000,
122 .flags = UPF_BOOT_AUTOCONF,
123 .scscr = SCSCR_RE | SCSCR_TE,
124 .scbrr_algo_id = SCBRR_ALGO_4,
125 .type = PORT_SCIFA,
Kuninori Morimoto215d6cc2011-11-10 18:46:35 -0800126 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c60)),
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800127};
128
129static struct platform_device scif3_device = {
130 .name = "sh-sci",
131 .id = 3,
132 .dev = {
133 .platform_data = &scif3_platform_data,
134 },
135};
136
137/* SCIFA4 */
138static struct plat_sci_port scif4_platform_data = {
139 .mapbase = 0xe6c80000,
140 .flags = UPF_BOOT_AUTOCONF,
141 .scscr = SCSCR_RE | SCSCR_TE,
142 .scbrr_algo_id = SCBRR_ALGO_4,
143 .type = PORT_SCIFA,
Kuninori Morimoto215d6cc2011-11-10 18:46:35 -0800144 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0d20)),
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800145};
146
147static struct platform_device scif4_device = {
148 .name = "sh-sci",
149 .id = 4,
150 .dev = {
151 .platform_data = &scif4_platform_data,
152 },
153};
154
155/* SCIFA5 */
156static struct plat_sci_port scif5_platform_data = {
157 .mapbase = 0xe6cb0000,
158 .flags = UPF_BOOT_AUTOCONF,
159 .scscr = SCSCR_RE | SCSCR_TE,
160 .scbrr_algo_id = SCBRR_ALGO_4,
161 .type = PORT_SCIFA,
Kuninori Morimoto215d6cc2011-11-10 18:46:35 -0800162 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0d40)),
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800163};
164
165static struct platform_device scif5_device = {
166 .name = "sh-sci",
167 .id = 5,
168 .dev = {
169 .platform_data = &scif5_platform_data,
170 },
171};
172
173/* SCIFA6 */
174static struct plat_sci_port scif6_platform_data = {
175 .mapbase = 0xe6cc0000,
176 .flags = UPF_BOOT_AUTOCONF,
177 .scscr = SCSCR_RE | SCSCR_TE,
178 .scbrr_algo_id = SCBRR_ALGO_4,
179 .type = PORT_SCIFA,
Kuninori Morimoto215d6cc2011-11-10 18:46:35 -0800180 .irqs = SCIx_IRQ_MUXED(evt2irq(0x04c0)),
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800181};
182
183static struct platform_device scif6_device = {
184 .name = "sh-sci",
185 .id = 6,
186 .dev = {
187 .platform_data = &scif6_platform_data,
188 },
189};
190
191/* SCIFA7 */
192static struct plat_sci_port scif7_platform_data = {
193 .mapbase = 0xe6cd0000,
194 .flags = UPF_BOOT_AUTOCONF,
195 .scscr = SCSCR_RE | SCSCR_TE,
196 .scbrr_algo_id = SCBRR_ALGO_4,
197 .type = PORT_SCIFA,
Kuninori Morimoto215d6cc2011-11-10 18:46:35 -0800198 .irqs = SCIx_IRQ_MUXED(evt2irq(0x04e0)),
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800199};
200
201static struct platform_device scif7_device = {
202 .name = "sh-sci",
203 .id = 7,
204 .dev = {
205 .platform_data = &scif7_platform_data,
206 },
207};
208
209/* SCIFB */
210static struct plat_sci_port scifb_platform_data = {
211 .mapbase = 0xe6c30000,
212 .flags = UPF_BOOT_AUTOCONF,
213 .scscr = SCSCR_RE | SCSCR_TE,
214 .scbrr_algo_id = SCBRR_ALGO_4,
215 .type = PORT_SCIFB,
Kuninori Morimoto215d6cc2011-11-10 18:46:35 -0800216 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0d60)),
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800217};
218
219static struct platform_device scifb_device = {
220 .name = "sh-sci",
221 .id = 8,
222 .dev = {
223 .platform_data = &scifb_platform_data,
224 },
225};
226
227/* CMT */
228static struct sh_timer_config cmt10_platform_data = {
229 .name = "CMT10",
230 .channel_offset = 0x10,
231 .timer_bit = 0,
232 .clockevent_rating = 125,
233 .clocksource_rating = 125,
234};
235
236static struct resource cmt10_resources[] = {
237 [0] = {
238 .name = "CMT10",
239 .start = 0xe6138010,
240 .end = 0xe613801b,
241 .flags = IORESOURCE_MEM,
242 },
243 [1] = {
Kuninori Morimoto215d6cc2011-11-10 18:46:35 -0800244 .start = evt2irq(0x0b00),
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800245 .flags = IORESOURCE_IRQ,
246 },
247};
248
249static struct platform_device cmt10_device = {
250 .name = "sh_cmt",
251 .id = 10,
252 .dev = {
253 .platform_data = &cmt10_platform_data,
254 },
255 .resource = cmt10_resources,
256 .num_resources = ARRAY_SIZE(cmt10_resources),
257};
258
259static struct platform_device *r8a7740_early_devices[] __initdata = {
260 &scif0_device,
261 &scif1_device,
262 &scif2_device,
263 &scif3_device,
264 &scif4_device,
265 &scif5_device,
266 &scif6_device,
267 &scif7_device,
268 &scifb_device,
269 &cmt10_device,
270};
271
Kuninori Morimoto6831f3a2011-11-10 18:46:23 -0800272/* I2C */
273static struct resource i2c0_resources[] = {
274 [0] = {
275 .name = "IIC0",
276 .start = 0xfff20000,
277 .end = 0xfff20425 - 1,
278 .flags = IORESOURCE_MEM,
279 },
280 [1] = {
Kuninori Morimoto215d6cc2011-11-10 18:46:35 -0800281 .start = intcs_evt2irq(0xe00),
282 .end = intcs_evt2irq(0xe60),
Kuninori Morimoto6831f3a2011-11-10 18:46:23 -0800283 .flags = IORESOURCE_IRQ,
284 },
285};
286
287static struct resource i2c1_resources[] = {
288 [0] = {
289 .name = "IIC1",
290 .start = 0xe6c20000,
291 .end = 0xe6c20425 - 1,
292 .flags = IORESOURCE_MEM,
293 },
294 [1] = {
Kuninori Morimoto215d6cc2011-11-10 18:46:35 -0800295 .start = evt2irq(0x780), /* IIC1_ALI1 */
296 .end = evt2irq(0x7e0), /* IIC1_DTEI1 */
Kuninori Morimoto6831f3a2011-11-10 18:46:23 -0800297 .flags = IORESOURCE_IRQ,
298 },
299};
300
301static struct platform_device i2c0_device = {
302 .name = "i2c-sh_mobile",
303 .id = 0,
304 .resource = i2c0_resources,
305 .num_resources = ARRAY_SIZE(i2c0_resources),
306};
307
308static struct platform_device i2c1_device = {
309 .name = "i2c-sh_mobile",
310 .id = 1,
311 .resource = i2c1_resources,
312 .num_resources = ARRAY_SIZE(i2c1_resources),
313};
314
315static struct platform_device *r8a7740_late_devices[] __initdata = {
316 &i2c0_device,
317 &i2c1_device,
318};
319
320#define ICCR 0x0004
321#define ICSTART 0x0070
322
323#define i2c_read(reg, offset) ioread8(reg + offset)
324#define i2c_write(reg, offset, data) iowrite8(data, reg + offset)
325
326/*
327 * r8a7740 chip has lasting errata on I2C I/O pad reset.
328 * this is work-around for it.
329 */
330static void r8a7740_i2c_workaround(struct platform_device *pdev)
331{
332 struct resource *res;
333 void __iomem *reg;
334
335 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
336 if (unlikely(!res)) {
337 pr_err("r8a7740 i2c workaround fail (cannot find resource)\n");
338 return;
339 }
340
341 reg = ioremap(res->start, resource_size(res));
342 if (unlikely(!reg)) {
343 pr_err("r8a7740 i2c workaround fail (cannot map IO)\n");
344 return;
345 }
346
347 i2c_write(reg, ICCR, i2c_read(reg, ICCR) | 0x80);
348 i2c_read(reg, ICCR); /* dummy read */
349
350 i2c_write(reg, ICSTART, i2c_read(reg, ICSTART) | 0x10);
351 i2c_read(reg, ICSTART); /* dummy read */
352
Kuninori Morimoto42287162012-04-13 02:41:06 -0700353 udelay(10);
Kuninori Morimoto6831f3a2011-11-10 18:46:23 -0800354
355 i2c_write(reg, ICCR, 0x01);
Kuninori Morimoto6831f3a2011-11-10 18:46:23 -0800356 i2c_write(reg, ICSTART, 0x00);
Kuninori Morimoto42287162012-04-13 02:41:06 -0700357
358 udelay(10);
Kuninori Morimoto6831f3a2011-11-10 18:46:23 -0800359
360 i2c_write(reg, ICCR, 0x10);
Kuninori Morimoto42287162012-04-13 02:41:06 -0700361 udelay(10);
Kuninori Morimoto6831f3a2011-11-10 18:46:23 -0800362 i2c_write(reg, ICCR, 0x00);
Kuninori Morimoto42287162012-04-13 02:41:06 -0700363 udelay(10);
Kuninori Morimoto6831f3a2011-11-10 18:46:23 -0800364 i2c_write(reg, ICCR, 0x10);
Kuninori Morimoto42287162012-04-13 02:41:06 -0700365 udelay(10);
Kuninori Morimoto6831f3a2011-11-10 18:46:23 -0800366
367 iounmap(reg);
368}
369
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800370void __init r8a7740_add_standard_devices(void)
371{
Kuninori Morimoto6831f3a2011-11-10 18:46:23 -0800372 /* I2C work-around */
373 r8a7740_i2c_workaround(&i2c0_device);
374 r8a7740_i2c_workaround(&i2c1_device);
375
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800376 platform_add_devices(r8a7740_early_devices,
377 ARRAY_SIZE(r8a7740_early_devices));
Kuninori Morimoto6831f3a2011-11-10 18:46:23 -0800378 platform_add_devices(r8a7740_late_devices,
379 ARRAY_SIZE(r8a7740_late_devices));
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800380}
381
Magnus Damm23e5bc02012-03-06 17:36:53 +0900382static void __init r8a7740_earlytimer_init(void)
383{
384 r8a7740_clock_init(0);
385 shmobile_earlytimer_init();
386}
387
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800388void __init r8a7740_add_early_devices(void)
389{
390 early_platform_add_devices(r8a7740_early_devices,
391 ARRAY_SIZE(r8a7740_early_devices));
Magnus Dammd3ab7222012-02-29 21:37:35 +0900392
393 /* setup early console here as well */
394 shmobile_setup_console();
Magnus Damm23e5bc02012-03-06 17:36:53 +0900395
396 /* override timer setup with soc-specific code */
397 shmobile_timer.init = r8a7740_earlytimer_init;
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800398}