blob: 566e69d8d7291895b49b2a7276bec94ba09a19e0 [file] [log] [blame]
Paul Mundt5283ecb2006-09-27 15:59:17 +09001/*
2 * arch/sh/boards/renesas/r7780rp/setup.c
3 *
Paul Mundt32351a22007-03-12 14:38:59 +09004 * Renesas Solutions Highlander Support.
5 *
Paul Mundt5283ecb2006-09-27 15:59:17 +09006 * Copyright (C) 2002 Atom Create Engineering Co., Ltd.
Paul Mundtc2933962008-03-25 16:49:30 +09007 * Copyright (C) 2005 - 2008 Paul Mundt
Paul Mundt5283ecb2006-09-27 15:59:17 +09008 *
Paul Mundt32351a22007-03-12 14:38:59 +09009 * This contains support for the R7780RP-1, R7780MP, and R7785RP
10 * Highlander modules.
Paul Mundt5283ecb2006-09-27 15:59:17 +090011 *
12 * This file is subject to the terms and conditions of the GNU General Public
13 * License. See the file "COPYING" in the main directory of this archive
14 * for more details.
15 */
16#include <linux/init.h>
17#include <linux/platform_device.h>
Jeff Garzik0a87e3e2008-02-01 18:02:30 -050018#include <linux/ata_platform.h>
Paul Mundtb5751e22007-11-02 14:17:19 +090019#include <linux/types.h>
Nobuhiro Iwamatsu15ba4002009-06-16 07:42:20 +000020#include <linux/mtd/physmap.h>
Paul Mundtc2933962008-03-25 16:49:30 +090021#include <linux/i2c.h>
Paul Mundt604437f2009-01-09 15:11:58 +090022#include <linux/irq.h>
Yoshihiro Shimoda6239b202009-05-26 09:33:05 +000023#include <linux/interrupt.h>
24#include <linux/usb/r8a66597.h>
Magnus Damm2c59b0b2009-07-22 14:41:35 +000025#include <linux/usb/m66592.h>
Magnus Dammc6f93a32007-10-15 10:36:45 +090026#include <net/ax88796.h>
Paul Mundt5283ecb2006-09-27 15:59:17 +090027#include <asm/machvec.h>
Paul Mundt7639a452008-10-20 13:02:48 +090028#include <mach/highlander.h>
Paul Mundt5283ecb2006-09-27 15:59:17 +090029#include <asm/clock.h>
Paul Mundt8786c952007-08-20 13:03:41 +090030#include <asm/heartbeat.h>
Paul Mundt5283ecb2006-09-27 15:59:17 +090031#include <asm/io.h>
Magnus Dammc1a34e42008-02-07 20:23:53 +090032#include <asm/io_trapped.h>
Paul Mundt5283ecb2006-09-27 15:59:17 +090033
Yoshihiro Shimoda6239b202009-05-26 09:33:05 +000034static struct r8a66597_platdata r8a66597_data = {
35 .xtal = R8A66597_PLATDATA_XTAL_12MHZ,
36 .vif = 1,
37};
38
Yoshihiro Shimodae6c972f2007-07-17 13:38:54 +090039static struct resource r8a66597_usb_host_resources[] = {
40 [0] = {
Yoshihiro Shimodae6c972f2007-07-17 13:38:54 +090041 .start = 0xA4200000,
42 .end = 0xA42000FF,
43 .flags = IORESOURCE_MEM,
44 },
45 [1] = {
Magnus Damm897cfcd2007-09-10 12:06:03 +090046 .start = IRQ_EXT1, /* irq number */
47 .end = IRQ_EXT1,
Yoshihiro Shimoda6239b202009-05-26 09:33:05 +000048 .flags = IORESOURCE_IRQ | IRQF_TRIGGER_LOW,
Yoshihiro Shimodae6c972f2007-07-17 13:38:54 +090049 },
50};
51
52static struct platform_device r8a66597_usb_host_device = {
53 .name = "r8a66597_hcd",
54 .id = -1,
55 .dev = {
56 .dma_mask = NULL, /* don't use dma */
57 .coherent_dma_mask = 0xffffffff,
Yoshihiro Shimoda6239b202009-05-26 09:33:05 +000058 .platform_data = &r8a66597_data,
Yoshihiro Shimodae6c972f2007-07-17 13:38:54 +090059 },
60 .num_resources = ARRAY_SIZE(r8a66597_usb_host_resources),
61 .resource = r8a66597_usb_host_resources,
62};
63
Magnus Damm2c59b0b2009-07-22 14:41:35 +000064static struct m66592_platdata usbf_platdata = {
65 .xtal = M66592_PLATDATA_XTAL_24MHZ,
66 .vif = 1,
67};
68
Yoshihiro Shimodae6c972f2007-07-17 13:38:54 +090069static struct resource m66592_usb_peripheral_resources[] = {
70 [0] = {
71 .name = "m66592_udc",
72 .start = 0xb0000000,
73 .end = 0xb00000FF,
74 .flags = IORESOURCE_MEM,
75 },
76 [1] = {
77 .name = "m66592_udc",
Magnus Damm897cfcd2007-09-10 12:06:03 +090078 .start = IRQ_EXT4, /* irq number */
79 .end = IRQ_EXT4,
Yoshihiro Shimodae6c972f2007-07-17 13:38:54 +090080 .flags = IORESOURCE_IRQ,
81 },
82};
83
84static struct platform_device m66592_usb_peripheral_device = {
85 .name = "m66592_udc",
86 .id = -1,
87 .dev = {
88 .dma_mask = NULL, /* don't use dma */
89 .coherent_dma_mask = 0xffffffff,
Magnus Damm2c59b0b2009-07-22 14:41:35 +000090 .platform_data = &usbf_platdata,
Yoshihiro Shimodae6c972f2007-07-17 13:38:54 +090091 },
92 .num_resources = ARRAY_SIZE(m66592_usb_peripheral_resources),
93 .resource = m66592_usb_peripheral_resources,
94};
95
Paul Mundt0c020e32006-12-06 10:43:44 +090096static struct resource cf_ide_resources[] = {
97 [0] = {
Paul Mundt71074d32007-02-14 14:49:04 +090098 .start = PA_AREA5_IO + 0x1000,
99 .end = PA_AREA5_IO + 0x1000 + 0x08 - 1,
100 .flags = IORESOURCE_MEM,
Paul Mundt0c020e32006-12-06 10:43:44 +0900101 },
102 [1] = {
Paul Mundt71074d32007-02-14 14:49:04 +0900103 .start = PA_AREA5_IO + 0x80c,
104 .end = PA_AREA5_IO + 0x80c + 0x16 - 1,
105 .flags = IORESOURCE_MEM,
Paul Mundt0c020e32006-12-06 10:43:44 +0900106 },
107 [2] = {
Magnus Damm897cfcd2007-09-10 12:06:03 +0900108 .start = IRQ_CF,
Paul Mundt0c020e32006-12-06 10:43:44 +0900109 .flags = IORESOURCE_IRQ,
110 },
111};
112
Paul Mundt71074d32007-02-14 14:49:04 +0900113static struct pata_platform_info pata_info = {
114 .ioport_shift = 1,
115};
116
Paul Mundt0c020e32006-12-06 10:43:44 +0900117static struct platform_device cf_ide_device = {
118 .name = "pata_platform",
119 .id = -1,
120 .num_resources = ARRAY_SIZE(cf_ide_resources),
121 .resource = cf_ide_resources,
Paul Mundt71074d32007-02-14 14:49:04 +0900122 .dev = {
123 .platform_data = &pata_info,
124 },
Paul Mundt0c020e32006-12-06 10:43:44 +0900125};
126
Paul Mundt3b4d9532007-02-13 15:42:28 +0900127static struct resource heartbeat_resources[] = {
128 [0] = {
129 .start = PA_OBLED,
Paul Mundta1fd3062007-08-23 15:11:44 +0900130 .end = PA_OBLED,
Paul Mundt3b4d9532007-02-13 15:42:28 +0900131 .flags = IORESOURCE_MEM,
132 },
133};
134
Paul Mundt8786c952007-08-20 13:03:41 +0900135#ifndef CONFIG_SH_R7785RP
136static unsigned char heartbeat_bit_pos[] = { 2, 1, 0, 3, 6, 5, 4, 7 };
137
138static struct heartbeat_data heartbeat_data = {
139 .bit_pos = heartbeat_bit_pos,
140 .nr_bits = ARRAY_SIZE(heartbeat_bit_pos),
141};
142#endif
143
Paul Mundt3b4d9532007-02-13 15:42:28 +0900144static struct platform_device heartbeat_device = {
145 .name = "heartbeat",
146 .id = -1,
Paul Mundt32351a22007-03-12 14:38:59 +0900147
148 /* R7785RP has a slightly more sensible FPGA.. */
149#ifndef CONFIG_SH_R7785RP
Paul Mundt3b4d9532007-02-13 15:42:28 +0900150 .dev = {
Paul Mundta1fd3062007-08-23 15:11:44 +0900151 .platform_data = &heartbeat_data,
Paul Mundt3b4d9532007-02-13 15:42:28 +0900152 },
Paul Mundt32351a22007-03-12 14:38:59 +0900153#endif
Paul Mundt3b4d9532007-02-13 15:42:28 +0900154 .num_resources = ARRAY_SIZE(heartbeat_resources),
155 .resource = heartbeat_resources,
156};
157
Magnus Dammc6f93a32007-10-15 10:36:45 +0900158static struct ax_plat_data ax88796_platdata = {
159 .flags = AXFLG_HAS_93CX6,
160 .wordlength = 2,
161 .dcr_val = 0x1,
162 .rcr_val = 0x40,
163};
164
165static struct resource ax88796_resources[] = {
166 {
167#ifdef CONFIG_SH_R7780RP
168 .start = 0xa5800400,
169 .end = 0xa5800400 + (0x20 * 0x2) - 1,
170#else
171 .start = 0xa4100400,
172 .end = 0xa4100400 + (0x20 * 0x2) - 1,
173#endif
174 .flags = IORESOURCE_MEM,
175 },
176 {
177 .start = IRQ_AX88796,
178 .end = IRQ_AX88796,
179 .flags = IORESOURCE_IRQ,
180 },
181};
182
183static struct platform_device ax88796_device = {
184 .name = "ax88796",
185 .id = 0,
186
187 .dev = {
188 .platform_data = &ax88796_platdata,
189 },
190
191 .num_resources = ARRAY_SIZE(ax88796_resources),
192 .resource = ax88796_resources,
193};
194
Nobuhiro Iwamatsu15ba4002009-06-16 07:42:20 +0000195static struct mtd_partition nor_flash_partitions[] = {
196 {
197 .name = "loader",
198 .offset = 0x00000000,
199 .size = 512 * 1024,
200 },
201 {
202 .name = "bootenv",
203 .offset = MTDPART_OFS_APPEND,
204 .size = 512 * 1024,
205 },
206 {
207 .name = "kernel",
208 .offset = MTDPART_OFS_APPEND,
209 .size = 4 * 1024 * 1024,
210 },
211 {
212 .name = "data",
213 .offset = MTDPART_OFS_APPEND,
214 .size = MTDPART_SIZ_FULL,
215 },
216};
217
218static struct physmap_flash_data nor_flash_data = {
219 .width = 4,
220 .parts = nor_flash_partitions,
221 .nr_parts = ARRAY_SIZE(nor_flash_partitions),
222};
223
224/* This config is flash board for mass production. */
225static struct resource nor_flash_resources[] = {
226 [0] = {
227 .start = PA_NORFLASH_ADDR,
228 .end = PA_NORFLASH_ADDR + PA_NORFLASH_SIZE - 1,
229 .flags = IORESOURCE_MEM,
230 }
231};
232
233static struct platform_device nor_flash_device = {
234 .name = "physmap-flash",
235 .dev = {
236 .platform_data = &nor_flash_data,
237 },
238 .num_resources = ARRAY_SIZE(nor_flash_resources),
239 .resource = nor_flash_resources,
240};
241
Paul Mundtc2933962008-03-25 16:49:30 +0900242static struct resource smbus_resources[] = {
243 [0] = {
244 .start = PA_SMCR,
245 .end = PA_SMCR + 0x100 - 1,
246 .flags = IORESOURCE_MEM,
247 },
248 [1] = {
249 .start = IRQ_SMBUS,
250 .end = IRQ_SMBUS,
251 .flags = IORESOURCE_IRQ,
252 },
253};
254
255static struct platform_device smbus_device = {
256 .name = "i2c-highlander",
257 .id = 0,
258 .num_resources = ARRAY_SIZE(smbus_resources),
259 .resource = smbus_resources,
260};
261
262static struct i2c_board_info __initdata highlander_i2c_devices[] = {
263 {
Jean Delvare3760f732008-04-29 23:11:40 +0200264 I2C_BOARD_INFO("r2025sd", 0x32),
Paul Mundtc2933962008-03-25 16:49:30 +0900265 },
266};
Magnus Dammc6f93a32007-10-15 10:36:45 +0900267
Paul Mundt5283ecb2006-09-27 15:59:17 +0900268static struct platform_device *r7780rp_devices[] __initdata = {
Yoshihiro Shimodae6c972f2007-07-17 13:38:54 +0900269 &r8a66597_usb_host_device,
270 &m66592_usb_peripheral_device,
Paul Mundt3b4d9532007-02-13 15:42:28 +0900271 &heartbeat_device,
Paul Mundtc2933962008-03-25 16:49:30 +0900272 &smbus_device,
Nobuhiro Iwamatsu15ba4002009-06-16 07:42:20 +0000273 &nor_flash_device,
Magnus Dammda2d7f42008-01-25 16:04:29 +0900274#ifndef CONFIG_SH_R7780RP
Magnus Dammc6f93a32007-10-15 10:36:45 +0900275 &ax88796_device,
Magnus Dammda2d7f42008-01-25 16:04:29 +0900276#endif
Paul Mundt5283ecb2006-09-27 15:59:17 +0900277};
278
Magnus Dammc1a34e42008-02-07 20:23:53 +0900279/*
280 * The CF is connected using a 16-bit bus where 8-bit operations are
281 * unsupported. The linux ata driver is however using 8-bit operations, so
282 * insert a trapped io filter to convert 8-bit operations into 16-bit.
283 */
284static struct trapped_io cf_trapped_io = {
285 .resource = cf_ide_resources,
286 .num_resources = 2,
287 .minimum_bus_width = 16,
288};
289
Paul Mundt5283ecb2006-09-27 15:59:17 +0900290static int __init r7780rp_devices_setup(void)
291{
Paul Mundtc2933962008-03-25 16:49:30 +0900292 int ret = 0;
293
Magnus Dammc1a34e42008-02-07 20:23:53 +0900294#ifndef CONFIG_SH_R7780RP
295 if (register_trapped_io(&cf_trapped_io) == 0)
Paul Mundtc2933962008-03-25 16:49:30 +0900296 ret |= platform_device_register(&cf_ide_device);
Magnus Dammc1a34e42008-02-07 20:23:53 +0900297#endif
Paul Mundtc2933962008-03-25 16:49:30 +0900298
299 ret |= platform_add_devices(r7780rp_devices,
Paul Mundt5283ecb2006-09-27 15:59:17 +0900300 ARRAY_SIZE(r7780rp_devices));
Paul Mundtc2933962008-03-25 16:49:30 +0900301
302 ret |= i2c_register_board_info(0, highlander_i2c_devices,
303 ARRAY_SIZE(highlander_i2c_devices));
304
305 return ret;
Paul Mundt5283ecb2006-09-27 15:59:17 +0900306}
Paul Mundt32351a22007-03-12 14:38:59 +0900307device_initcall(r7780rp_devices_setup);
Paul Mundt5283ecb2006-09-27 15:59:17 +0900308
309/*
310 * Platform specific clocks
311 */
Nobuhiro Iwamatsu39f44902009-06-16 07:44:10 +0000312static int ivdr_clk_enable(struct clk *clk)
Paul Mundt5283ecb2006-09-27 15:59:17 +0900313{
Ryusuke Sakato39374aa2007-05-07 10:48:56 +0900314 ctrl_outw(ctrl_inw(PA_IVDRCTL) | (1 << IVDR_CK_ON), PA_IVDRCTL);
Nobuhiro Iwamatsu39f44902009-06-16 07:44:10 +0000315 return 0;
Paul Mundt5283ecb2006-09-27 15:59:17 +0900316}
317
318static void ivdr_clk_disable(struct clk *clk)
319{
Ryusuke Sakato39374aa2007-05-07 10:48:56 +0900320 ctrl_outw(ctrl_inw(PA_IVDRCTL) & ~(1 << IVDR_CK_ON), PA_IVDRCTL);
Paul Mundt5283ecb2006-09-27 15:59:17 +0900321}
322
323static struct clk_ops ivdr_clk_ops = {
324 .enable = ivdr_clk_enable,
325 .disable = ivdr_clk_disable,
326};
327
328static struct clk ivdr_clk = {
329 .name = "ivdr_clk",
330 .ops = &ivdr_clk_ops,
331};
332
333static struct clk *r7780rp_clocks[] = {
334 &ivdr_clk,
335};
336
Paul Mundt5283ecb2006-09-27 15:59:17 +0900337static void r7780rp_power_off(void)
338{
Paul Mundt32351a22007-03-12 14:38:59 +0900339 if (mach_is_r7780mp() || mach_is_r7785rp())
340 ctrl_outw(0x0001, PA_POFF);
Paul Mundt5283ecb2006-09-27 15:59:17 +0900341}
342
343/*
344 * Initialize the board
345 */
Paul Mundt32351a22007-03-12 14:38:59 +0900346static void __init highlander_setup(char **cmdline_p)
Paul Mundt5283ecb2006-09-27 15:59:17 +0900347{
348 u16 ver = ctrl_inw(PA_VERREG);
349 int i;
350
Paul Mundt32351a22007-03-12 14:38:59 +0900351 printk(KERN_INFO "Renesas Solutions Highlander %s support.\n",
352 mach_is_r7780rp() ? "R7780RP-1" :
353 mach_is_r7780mp() ? "R7780MP" :
354 "R7785RP");
Paul Mundt5283ecb2006-09-27 15:59:17 +0900355
356 printk(KERN_INFO "Board version: %d (revision %d), "
357 "FPGA version: %d (revision %d)\n",
358 (ver >> 12) & 0xf, (ver >> 8) & 0xf,
359 (ver >> 4) & 0xf, ver & 0xf);
360
Paul Mundt61dc6ea2008-10-23 12:35:43 +0900361 highlander_plat_pinmux_setup();
362
Paul Mundt5283ecb2006-09-27 15:59:17 +0900363 /*
364 * Enable the important clocks right away..
365 */
366 for (i = 0; i < ARRAY_SIZE(r7780rp_clocks); i++) {
367 struct clk *clk = r7780rp_clocks[i];
368
369 clk_register(clk);
370 clk_enable(clk);
371 }
372
373 ctrl_outw(0x0000, PA_OBLED); /* Clear LED. */
Paul Mundt32351a22007-03-12 14:38:59 +0900374
375 if (mach_is_r7780rp())
376 ctrl_outw(0x0001, PA_SDPOW); /* SD Power ON */
377
Paul Mundt2c081e72006-12-25 18:28:33 +0900378 ctrl_outw(ctrl_inw(PA_IVDRCTL) | 0x01, PA_IVDRCTL); /* Si13112 */
Paul Mundt5283ecb2006-09-27 15:59:17 +0900379
380 pm_power_off = r7780rp_power_off;
381}
Paul Mundt2c7834a2006-09-27 18:17:31 +0900382
Magnus Damm897cfcd2007-09-10 12:06:03 +0900383static unsigned char irl2irq[HL_NR_IRL];
384
Paul Mundtae8a5342008-04-25 17:58:21 +0900385static int highlander_irq_demux(int irq)
Magnus Damm897cfcd2007-09-10 12:06:03 +0900386{
387 if (irq >= HL_NR_IRL || !irl2irq[irq])
388 return irq;
389
390 return irl2irq[irq];
391}
392
Paul Mundtae8a5342008-04-25 17:58:21 +0900393static void __init highlander_init_irq(void)
Magnus Damm897cfcd2007-09-10 12:06:03 +0900394{
Paul Mundtae8a5342008-04-25 17:58:21 +0900395 unsigned char *ucp = highlander_plat_irq_setup();
Magnus Damm897cfcd2007-09-10 12:06:03 +0900396
397 if (ucp) {
398 plat_irq_setup_pins(IRQ_MODE_IRL3210);
399 memcpy(irl2irq, ucp, HL_NR_IRL);
400 }
401}
402
Paul Mundt2c7834a2006-09-27 18:17:31 +0900403/*
404 * The Machine Vector
405 */
Paul Mundt82f81f42007-05-15 15:19:34 +0900406static struct sh_machine_vector mv_highlander __initmv = {
Paul Mundt32351a22007-03-12 14:38:59 +0900407 .mv_name = "Highlander",
Paul Mundt32351a22007-03-12 14:38:59 +0900408 .mv_setup = highlander_setup,
409 .mv_init_irq = highlander_init_irq,
Magnus Damm897cfcd2007-09-10 12:06:03 +0900410 .mv_irq_demux = highlander_irq_demux,
Paul Mundt2c7834a2006-09-27 18:17:31 +0900411};