blob: 74e52341dd1bda1352e70de479c75fa53a99356b [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>
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -080029#include <asm/mach-types.h>
Magnus Dammd3ab7222012-02-29 21:37:35 +090030#include <asm/mach/map.h>
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -080031#include <asm/mach/arch.h>
Magnus Damm23e5bc02012-03-06 17:36:53 +090032#include <asm/mach/time.h>
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -080033
Magnus Dammd3ab7222012-02-29 21:37:35 +090034static struct map_desc r8a7740_io_desc[] __initdata = {
35 /*
36 * for CPGA/INTC/PFC
37 * 0xe6000000-0xefffffff -> 0xe6000000-0xefffffff
38 */
39 {
40 .virtual = 0xe6000000,
41 .pfn = __phys_to_pfn(0xe6000000),
42 .length = 160 << 20,
43 .type = MT_DEVICE_NONSHARED
44 },
45#ifdef CONFIG_CACHE_L2X0
46 /*
47 * for l2x0_init()
48 * 0xf0100000-0xf0101000 -> 0xf0002000-0xf0003000
49 */
50 {
51 .virtual = 0xf0002000,
52 .pfn = __phys_to_pfn(0xf0100000),
53 .length = PAGE_SIZE,
54 .type = MT_DEVICE_NONSHARED
55 },
56#endif
57};
58
59void __init r8a7740_map_io(void)
60{
61 iotable_init(r8a7740_io_desc, ARRAY_SIZE(r8a7740_io_desc));
62}
63
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -080064/* SCIFA0 */
65static 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,
70 .type = PORT_SCIFA,
Kuninori Morimoto215d6cc2011-11-10 18:46:35 -080071 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c00)),
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -080072};
73
74static struct platform_device scif0_device = {
75 .name = "sh-sci",
76 .id = 0,
77 .dev = {
78 .platform_data = &scif0_platform_data,
79 },
80};
81
82/* SCIFA1 */
83static 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,
88 .type = PORT_SCIFA,
Kuninori Morimoto215d6cc2011-11-10 18:46:35 -080089 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c20)),
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -080090};
91
92static struct platform_device scif1_device = {
93 .name = "sh-sci",
94 .id = 1,
95 .dev = {
96 .platform_data = &scif1_platform_data,
97 },
98};
99
100/* SCIFA2 */
101static 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,
106 .type = PORT_SCIFA,
Kuninori Morimoto215d6cc2011-11-10 18:46:35 -0800107 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c40)),
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800108};
109
110static struct platform_device scif2_device = {
111 .name = "sh-sci",
112 .id = 2,
113 .dev = {
114 .platform_data = &scif2_platform_data,
115 },
116};
117
118/* SCIFA3 */
119static 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,
124 .type = PORT_SCIFA,
Kuninori Morimoto215d6cc2011-11-10 18:46:35 -0800125 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0c60)),
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800126};
127
128static struct platform_device scif3_device = {
129 .name = "sh-sci",
130 .id = 3,
131 .dev = {
132 .platform_data = &scif3_platform_data,
133 },
134};
135
136/* SCIFA4 */
137static 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,
142 .type = PORT_SCIFA,
Kuninori Morimoto215d6cc2011-11-10 18:46:35 -0800143 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0d20)),
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800144};
145
146static struct platform_device scif4_device = {
147 .name = "sh-sci",
148 .id = 4,
149 .dev = {
150 .platform_data = &scif4_platform_data,
151 },
152};
153
154/* SCIFA5 */
155static 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,
160 .type = PORT_SCIFA,
Kuninori Morimoto215d6cc2011-11-10 18:46:35 -0800161 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0d40)),
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800162};
163
164static struct platform_device scif5_device = {
165 .name = "sh-sci",
166 .id = 5,
167 .dev = {
168 .platform_data = &scif5_platform_data,
169 },
170};
171
172/* SCIFA6 */
173static 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,
178 .type = PORT_SCIFA,
Kuninori Morimoto215d6cc2011-11-10 18:46:35 -0800179 .irqs = SCIx_IRQ_MUXED(evt2irq(0x04c0)),
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800180};
181
182static struct platform_device scif6_device = {
183 .name = "sh-sci",
184 .id = 6,
185 .dev = {
186 .platform_data = &scif6_platform_data,
187 },
188};
189
190/* SCIFA7 */
191static 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,
196 .type = PORT_SCIFA,
Kuninori Morimoto215d6cc2011-11-10 18:46:35 -0800197 .irqs = SCIx_IRQ_MUXED(evt2irq(0x04e0)),
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800198};
199
200static struct platform_device scif7_device = {
201 .name = "sh-sci",
202 .id = 7,
203 .dev = {
204 .platform_data = &scif7_platform_data,
205 },
206};
207
208/* SCIFB */
209static 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,
214 .type = PORT_SCIFB,
Kuninori Morimoto215d6cc2011-11-10 18:46:35 -0800215 .irqs = SCIx_IRQ_MUXED(evt2irq(0x0d60)),
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800216};
217
218static struct platform_device scifb_device = {
219 .name = "sh-sci",
220 .id = 8,
221 .dev = {
222 .platform_data = &scifb_platform_data,
223 },
224};
225
226/* CMT */
227static struct sh_timer_config cmt10_platform_data = {
228 .name = "CMT10",
229 .channel_offset = 0x10,
230 .timer_bit = 0,
231 .clockevent_rating = 125,
232 .clocksource_rating = 125,
233};
234
235static struct resource cmt10_resources[] = {
236 [0] = {
237 .name = "CMT10",
238 .start = 0xe6138010,
239 .end = 0xe613801b,
240 .flags = IORESOURCE_MEM,
241 },
242 [1] = {
Kuninori Morimoto215d6cc2011-11-10 18:46:35 -0800243 .start = evt2irq(0x0b00),
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800244 .flags = IORESOURCE_IRQ,
245 },
246};
247
248static struct platform_device cmt10_device = {
249 .name = "sh_cmt",
250 .id = 10,
251 .dev = {
252 .platform_data = &cmt10_platform_data,
253 },
254 .resource = cmt10_resources,
255 .num_resources = ARRAY_SIZE(cmt10_resources),
256};
257
258static struct platform_device *r8a7740_early_devices[] __initdata = {
259 &scif0_device,
260 &scif1_device,
261 &scif2_device,
262 &scif3_device,
263 &scif4_device,
264 &scif5_device,
265 &scif6_device,
266 &scif7_device,
267 &scifb_device,
268 &cmt10_device,
269};
270
Kuninori Morimoto6831f3a2011-11-10 18:46:23 -0800271/* I2C */
272static struct resource i2c0_resources[] = {
273 [0] = {
274 .name = "IIC0",
275 .start = 0xfff20000,
276 .end = 0xfff20425 - 1,
277 .flags = IORESOURCE_MEM,
278 },
279 [1] = {
Kuninori Morimoto215d6cc2011-11-10 18:46:35 -0800280 .start = intcs_evt2irq(0xe00),
281 .end = intcs_evt2irq(0xe60),
Kuninori Morimoto6831f3a2011-11-10 18:46:23 -0800282 .flags = IORESOURCE_IRQ,
283 },
284};
285
286static struct resource i2c1_resources[] = {
287 [0] = {
288 .name = "IIC1",
289 .start = 0xe6c20000,
290 .end = 0xe6c20425 - 1,
291 .flags = IORESOURCE_MEM,
292 },
293 [1] = {
Kuninori Morimoto215d6cc2011-11-10 18:46:35 -0800294 .start = evt2irq(0x780), /* IIC1_ALI1 */
295 .end = evt2irq(0x7e0), /* IIC1_DTEI1 */
Kuninori Morimoto6831f3a2011-11-10 18:46:23 -0800296 .flags = IORESOURCE_IRQ,
297 },
298};
299
300static struct platform_device i2c0_device = {
301 .name = "i2c-sh_mobile",
302 .id = 0,
303 .resource = i2c0_resources,
304 .num_resources = ARRAY_SIZE(i2c0_resources),
305};
306
307static struct platform_device i2c1_device = {
308 .name = "i2c-sh_mobile",
309 .id = 1,
310 .resource = i2c1_resources,
311 .num_resources = ARRAY_SIZE(i2c1_resources),
312};
313
314static struct platform_device *r8a7740_late_devices[] __initdata = {
315 &i2c0_device,
316 &i2c1_device,
317};
318
319#define ICCR 0x0004
320#define ICSTART 0x0070
321
322#define i2c_read(reg, offset) ioread8(reg + offset)
323#define i2c_write(reg, offset, data) iowrite8(data, reg + offset)
324
325/*
326 * r8a7740 chip has lasting errata on I2C I/O pad reset.
327 * this is work-around for it.
328 */
329static void r8a7740_i2c_workaround(struct platform_device *pdev)
330{
331 struct resource *res;
332 void __iomem *reg;
333
334 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
335 if (unlikely(!res)) {
336 pr_err("r8a7740 i2c workaround fail (cannot find resource)\n");
337 return;
338 }
339
340 reg = ioremap(res->start, resource_size(res));
341 if (unlikely(!reg)) {
342 pr_err("r8a7740 i2c workaround fail (cannot map IO)\n");
343 return;
344 }
345
346 i2c_write(reg, ICCR, i2c_read(reg, ICCR) | 0x80);
347 i2c_read(reg, ICCR); /* dummy read */
348
349 i2c_write(reg, ICSTART, i2c_read(reg, ICSTART) | 0x10);
350 i2c_read(reg, ICSTART); /* dummy read */
351
352 mdelay(100);
353
354 i2c_write(reg, ICCR, 0x01);
355 i2c_read(reg, ICCR);
356 i2c_write(reg, ICSTART, 0x00);
357 i2c_read(reg, ICSTART);
358
359 i2c_write(reg, ICCR, 0x10);
360 mdelay(100);
361 i2c_write(reg, ICCR, 0x00);
362 mdelay(100);
363 i2c_write(reg, ICCR, 0x10);
364 mdelay(100);
365
366 iounmap(reg);
367}
368
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800369void __init r8a7740_add_standard_devices(void)
370{
Kuninori Morimoto6831f3a2011-11-10 18:46:23 -0800371 /* I2C work-around */
372 r8a7740_i2c_workaround(&i2c0_device);
373 r8a7740_i2c_workaround(&i2c1_device);
374
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800375 platform_add_devices(r8a7740_early_devices,
376 ARRAY_SIZE(r8a7740_early_devices));
Kuninori Morimoto6831f3a2011-11-10 18:46:23 -0800377 platform_add_devices(r8a7740_late_devices,
378 ARRAY_SIZE(r8a7740_late_devices));
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800379}
380
Magnus Damm23e5bc02012-03-06 17:36:53 +0900381static void __init r8a7740_earlytimer_init(void)
382{
383 r8a7740_clock_init(0);
384 shmobile_earlytimer_init();
385}
386
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800387void __init r8a7740_add_early_devices(void)
388{
389 early_platform_add_devices(r8a7740_early_devices,
390 ARRAY_SIZE(r8a7740_early_devices));
Magnus Dammd3ab7222012-02-29 21:37:35 +0900391
392 /* setup early console here as well */
393 shmobile_setup_console();
Magnus Damm23e5bc02012-03-06 17:36:53 +0900394
395 /* override timer setup with soc-specific code */
396 shmobile_timer.init = r8a7740_earlytimer_init;
Kuninori Morimoto6c01ba42011-11-10 18:45:52 -0800397}