blob: df054e54bab3426d91fd240405f04350f635b763 [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>
Magnus Dammc6f93a32007-10-15 10:36:45 +090023#include <net/ax88796.h>
Paul Mundt5283ecb2006-09-27 15:59:17 +090024#include <asm/machvec.h>
Paul Mundt7639a452008-10-20 13:02:48 +090025#include <mach/highlander.h>
Paul Mundt5283ecb2006-09-27 15:59:17 +090026#include <asm/clock.h>
Paul Mundt8786c952007-08-20 13:03:41 +090027#include <asm/heartbeat.h>
Paul Mundt5283ecb2006-09-27 15:59:17 +090028#include <asm/io.h>
Magnus Dammc1a34e42008-02-07 20:23:53 +090029#include <asm/io_trapped.h>
Paul Mundt5283ecb2006-09-27 15:59:17 +090030
Yoshihiro Shimodae6c972f2007-07-17 13:38:54 +090031static struct resource r8a66597_usb_host_resources[] = {
32 [0] = {
33 .name = "r8a66597_hcd",
34 .start = 0xA4200000,
35 .end = 0xA42000FF,
36 .flags = IORESOURCE_MEM,
37 },
38 [1] = {
39 .name = "r8a66597_hcd",
Magnus Damm897cfcd2007-09-10 12:06:03 +090040 .start = IRQ_EXT1, /* irq number */
41 .end = IRQ_EXT1,
Yoshihiro Shimodae6c972f2007-07-17 13:38:54 +090042 .flags = IORESOURCE_IRQ,
43 },
44};
45
46static struct platform_device r8a66597_usb_host_device = {
47 .name = "r8a66597_hcd",
48 .id = -1,
49 .dev = {
50 .dma_mask = NULL, /* don't use dma */
51 .coherent_dma_mask = 0xffffffff,
52 },
53 .num_resources = ARRAY_SIZE(r8a66597_usb_host_resources),
54 .resource = r8a66597_usb_host_resources,
55};
56
57static struct resource m66592_usb_peripheral_resources[] = {
58 [0] = {
59 .name = "m66592_udc",
60 .start = 0xb0000000,
61 .end = 0xb00000FF,
62 .flags = IORESOURCE_MEM,
63 },
64 [1] = {
65 .name = "m66592_udc",
Magnus Damm897cfcd2007-09-10 12:06:03 +090066 .start = IRQ_EXT4, /* irq number */
67 .end = IRQ_EXT4,
Yoshihiro Shimodae6c972f2007-07-17 13:38:54 +090068 .flags = IORESOURCE_IRQ,
69 },
70};
71
72static struct platform_device m66592_usb_peripheral_device = {
73 .name = "m66592_udc",
74 .id = -1,
75 .dev = {
76 .dma_mask = NULL, /* don't use dma */
77 .coherent_dma_mask = 0xffffffff,
78 },
79 .num_resources = ARRAY_SIZE(m66592_usb_peripheral_resources),
80 .resource = m66592_usb_peripheral_resources,
81};
82
Paul Mundt0c020e32006-12-06 10:43:44 +090083static struct resource cf_ide_resources[] = {
84 [0] = {
Paul Mundt71074d32007-02-14 14:49:04 +090085 .start = PA_AREA5_IO + 0x1000,
86 .end = PA_AREA5_IO + 0x1000 + 0x08 - 1,
87 .flags = IORESOURCE_MEM,
Paul Mundt0c020e32006-12-06 10:43:44 +090088 },
89 [1] = {
Paul Mundt71074d32007-02-14 14:49:04 +090090 .start = PA_AREA5_IO + 0x80c,
91 .end = PA_AREA5_IO + 0x80c + 0x16 - 1,
92 .flags = IORESOURCE_MEM,
Paul Mundt0c020e32006-12-06 10:43:44 +090093 },
94 [2] = {
Magnus Damm897cfcd2007-09-10 12:06:03 +090095 .start = IRQ_CF,
Paul Mundt0c020e32006-12-06 10:43:44 +090096 .flags = IORESOURCE_IRQ,
97 },
98};
99
Paul Mundt71074d32007-02-14 14:49:04 +0900100static struct pata_platform_info pata_info = {
101 .ioport_shift = 1,
102};
103
Paul Mundt0c020e32006-12-06 10:43:44 +0900104static struct platform_device cf_ide_device = {
105 .name = "pata_platform",
106 .id = -1,
107 .num_resources = ARRAY_SIZE(cf_ide_resources),
108 .resource = cf_ide_resources,
Paul Mundt71074d32007-02-14 14:49:04 +0900109 .dev = {
110 .platform_data = &pata_info,
111 },
Paul Mundt0c020e32006-12-06 10:43:44 +0900112};
113
Paul Mundt3b4d9532007-02-13 15:42:28 +0900114static struct resource heartbeat_resources[] = {
115 [0] = {
116 .start = PA_OBLED,
Paul Mundta1fd3062007-08-23 15:11:44 +0900117 .end = PA_OBLED,
Paul Mundt3b4d9532007-02-13 15:42:28 +0900118 .flags = IORESOURCE_MEM,
119 },
120};
121
Paul Mundt8786c952007-08-20 13:03:41 +0900122#ifndef CONFIG_SH_R7785RP
123static unsigned char heartbeat_bit_pos[] = { 2, 1, 0, 3, 6, 5, 4, 7 };
124
125static struct heartbeat_data heartbeat_data = {
126 .bit_pos = heartbeat_bit_pos,
127 .nr_bits = ARRAY_SIZE(heartbeat_bit_pos),
128};
129#endif
130
Paul Mundt3b4d9532007-02-13 15:42:28 +0900131static struct platform_device heartbeat_device = {
132 .name = "heartbeat",
133 .id = -1,
Paul Mundt32351a22007-03-12 14:38:59 +0900134
135 /* R7785RP has a slightly more sensible FPGA.. */
136#ifndef CONFIG_SH_R7785RP
Paul Mundt3b4d9532007-02-13 15:42:28 +0900137 .dev = {
Paul Mundta1fd3062007-08-23 15:11:44 +0900138 .platform_data = &heartbeat_data,
Paul Mundt3b4d9532007-02-13 15:42:28 +0900139 },
Paul Mundt32351a22007-03-12 14:38:59 +0900140#endif
Paul Mundt3b4d9532007-02-13 15:42:28 +0900141 .num_resources = ARRAY_SIZE(heartbeat_resources),
142 .resource = heartbeat_resources,
143};
144
Magnus Dammc6f93a32007-10-15 10:36:45 +0900145static struct ax_plat_data ax88796_platdata = {
146 .flags = AXFLG_HAS_93CX6,
147 .wordlength = 2,
148 .dcr_val = 0x1,
149 .rcr_val = 0x40,
150};
151
152static struct resource ax88796_resources[] = {
153 {
154#ifdef CONFIG_SH_R7780RP
155 .start = 0xa5800400,
156 .end = 0xa5800400 + (0x20 * 0x2) - 1,
157#else
158 .start = 0xa4100400,
159 .end = 0xa4100400 + (0x20 * 0x2) - 1,
160#endif
161 .flags = IORESOURCE_MEM,
162 },
163 {
164 .start = IRQ_AX88796,
165 .end = IRQ_AX88796,
166 .flags = IORESOURCE_IRQ,
167 },
168};
169
170static struct platform_device ax88796_device = {
171 .name = "ax88796",
172 .id = 0,
173
174 .dev = {
175 .platform_data = &ax88796_platdata,
176 },
177
178 .num_resources = ARRAY_SIZE(ax88796_resources),
179 .resource = ax88796_resources,
180};
181
Nobuhiro Iwamatsu15ba4002009-06-16 07:42:20 +0000182static struct mtd_partition nor_flash_partitions[] = {
183 {
184 .name = "loader",
185 .offset = 0x00000000,
186 .size = 512 * 1024,
187 },
188 {
189 .name = "bootenv",
190 .offset = MTDPART_OFS_APPEND,
191 .size = 512 * 1024,
192 },
193 {
194 .name = "kernel",
195 .offset = MTDPART_OFS_APPEND,
196 .size = 4 * 1024 * 1024,
197 },
198 {
199 .name = "data",
200 .offset = MTDPART_OFS_APPEND,
201 .size = MTDPART_SIZ_FULL,
202 },
203};
204
205static struct physmap_flash_data nor_flash_data = {
206 .width = 4,
207 .parts = nor_flash_partitions,
208 .nr_parts = ARRAY_SIZE(nor_flash_partitions),
209};
210
211/* This config is flash board for mass production. */
212static struct resource nor_flash_resources[] = {
213 [0] = {
214 .start = PA_NORFLASH_ADDR,
215 .end = PA_NORFLASH_ADDR + PA_NORFLASH_SIZE - 1,
216 .flags = IORESOURCE_MEM,
217 }
218};
219
220static struct platform_device nor_flash_device = {
221 .name = "physmap-flash",
222 .dev = {
223 .platform_data = &nor_flash_data,
224 },
225 .num_resources = ARRAY_SIZE(nor_flash_resources),
226 .resource = nor_flash_resources,
227};
228
Paul Mundtc2933962008-03-25 16:49:30 +0900229static struct resource smbus_resources[] = {
230 [0] = {
231 .start = PA_SMCR,
232 .end = PA_SMCR + 0x100 - 1,
233 .flags = IORESOURCE_MEM,
234 },
235 [1] = {
236 .start = IRQ_SMBUS,
237 .end = IRQ_SMBUS,
238 .flags = IORESOURCE_IRQ,
239 },
240};
241
242static struct platform_device smbus_device = {
243 .name = "i2c-highlander",
244 .id = 0,
245 .num_resources = ARRAY_SIZE(smbus_resources),
246 .resource = smbus_resources,
247};
248
249static struct i2c_board_info __initdata highlander_i2c_devices[] = {
250 {
Jean Delvare3760f732008-04-29 23:11:40 +0200251 I2C_BOARD_INFO("r2025sd", 0x32),
Paul Mundtc2933962008-03-25 16:49:30 +0900252 },
253};
Magnus Dammc6f93a32007-10-15 10:36:45 +0900254
Paul Mundt5283ecb2006-09-27 15:59:17 +0900255static struct platform_device *r7780rp_devices[] __initdata = {
Yoshihiro Shimodae6c972f2007-07-17 13:38:54 +0900256 &r8a66597_usb_host_device,
257 &m66592_usb_peripheral_device,
Paul Mundt3b4d9532007-02-13 15:42:28 +0900258 &heartbeat_device,
Paul Mundtc2933962008-03-25 16:49:30 +0900259 &smbus_device,
Nobuhiro Iwamatsu15ba4002009-06-16 07:42:20 +0000260 &nor_flash_device,
Magnus Dammda2d7f42008-01-25 16:04:29 +0900261#ifndef CONFIG_SH_R7780RP
Magnus Dammc6f93a32007-10-15 10:36:45 +0900262 &ax88796_device,
Magnus Dammda2d7f42008-01-25 16:04:29 +0900263#endif
Paul Mundt5283ecb2006-09-27 15:59:17 +0900264};
265
Magnus Dammc1a34e42008-02-07 20:23:53 +0900266/*
267 * The CF is connected using a 16-bit bus where 8-bit operations are
268 * unsupported. The linux ata driver is however using 8-bit operations, so
269 * insert a trapped io filter to convert 8-bit operations into 16-bit.
270 */
271static struct trapped_io cf_trapped_io = {
272 .resource = cf_ide_resources,
273 .num_resources = 2,
274 .minimum_bus_width = 16,
275};
276
Paul Mundt5283ecb2006-09-27 15:59:17 +0900277static int __init r7780rp_devices_setup(void)
278{
Paul Mundtc2933962008-03-25 16:49:30 +0900279 int ret = 0;
280
Magnus Dammc1a34e42008-02-07 20:23:53 +0900281#ifndef CONFIG_SH_R7780RP
282 if (register_trapped_io(&cf_trapped_io) == 0)
Paul Mundtc2933962008-03-25 16:49:30 +0900283 ret |= platform_device_register(&cf_ide_device);
Magnus Dammc1a34e42008-02-07 20:23:53 +0900284#endif
Paul Mundtc2933962008-03-25 16:49:30 +0900285
286 ret |= platform_add_devices(r7780rp_devices,
Paul Mundt5283ecb2006-09-27 15:59:17 +0900287 ARRAY_SIZE(r7780rp_devices));
Paul Mundtc2933962008-03-25 16:49:30 +0900288
289 ret |= i2c_register_board_info(0, highlander_i2c_devices,
290 ARRAY_SIZE(highlander_i2c_devices));
291
292 return ret;
Paul Mundt5283ecb2006-09-27 15:59:17 +0900293}
Paul Mundt32351a22007-03-12 14:38:59 +0900294device_initcall(r7780rp_devices_setup);
Paul Mundt5283ecb2006-09-27 15:59:17 +0900295
296/*
297 * Platform specific clocks
298 */
299static void ivdr_clk_enable(struct clk *clk)
300{
Ryusuke Sakato39374aa2007-05-07 10:48:56 +0900301 ctrl_outw(ctrl_inw(PA_IVDRCTL) | (1 << IVDR_CK_ON), PA_IVDRCTL);
Paul Mundt5283ecb2006-09-27 15:59:17 +0900302}
303
304static void ivdr_clk_disable(struct clk *clk)
305{
Ryusuke Sakato39374aa2007-05-07 10:48:56 +0900306 ctrl_outw(ctrl_inw(PA_IVDRCTL) & ~(1 << IVDR_CK_ON), PA_IVDRCTL);
Paul Mundt5283ecb2006-09-27 15:59:17 +0900307}
308
309static struct clk_ops ivdr_clk_ops = {
310 .enable = ivdr_clk_enable,
311 .disable = ivdr_clk_disable,
312};
313
314static struct clk ivdr_clk = {
315 .name = "ivdr_clk",
316 .ops = &ivdr_clk_ops,
317};
318
319static struct clk *r7780rp_clocks[] = {
320 &ivdr_clk,
321};
322
Paul Mundt5283ecb2006-09-27 15:59:17 +0900323static void r7780rp_power_off(void)
324{
Paul Mundt32351a22007-03-12 14:38:59 +0900325 if (mach_is_r7780mp() || mach_is_r7785rp())
326 ctrl_outw(0x0001, PA_POFF);
Paul Mundt5283ecb2006-09-27 15:59:17 +0900327}
328
329/*
330 * Initialize the board
331 */
Paul Mundt32351a22007-03-12 14:38:59 +0900332static void __init highlander_setup(char **cmdline_p)
Paul Mundt5283ecb2006-09-27 15:59:17 +0900333{
334 u16 ver = ctrl_inw(PA_VERREG);
335 int i;
336
Paul Mundt32351a22007-03-12 14:38:59 +0900337 printk(KERN_INFO "Renesas Solutions Highlander %s support.\n",
338 mach_is_r7780rp() ? "R7780RP-1" :
339 mach_is_r7780mp() ? "R7780MP" :
340 "R7785RP");
Paul Mundt5283ecb2006-09-27 15:59:17 +0900341
342 printk(KERN_INFO "Board version: %d (revision %d), "
343 "FPGA version: %d (revision %d)\n",
344 (ver >> 12) & 0xf, (ver >> 8) & 0xf,
345 (ver >> 4) & 0xf, ver & 0xf);
346
Paul Mundt61dc6ea2008-10-23 12:35:43 +0900347 highlander_plat_pinmux_setup();
348
Paul Mundt5283ecb2006-09-27 15:59:17 +0900349 /*
350 * Enable the important clocks right away..
351 */
352 for (i = 0; i < ARRAY_SIZE(r7780rp_clocks); i++) {
353 struct clk *clk = r7780rp_clocks[i];
354
355 clk_register(clk);
356 clk_enable(clk);
357 }
358
359 ctrl_outw(0x0000, PA_OBLED); /* Clear LED. */
Paul Mundt32351a22007-03-12 14:38:59 +0900360
361 if (mach_is_r7780rp())
362 ctrl_outw(0x0001, PA_SDPOW); /* SD Power ON */
363
Paul Mundt2c081e72006-12-25 18:28:33 +0900364 ctrl_outw(ctrl_inw(PA_IVDRCTL) | 0x01, PA_IVDRCTL); /* Si13112 */
Paul Mundt5283ecb2006-09-27 15:59:17 +0900365
366 pm_power_off = r7780rp_power_off;
367}
Paul Mundt2c7834a2006-09-27 18:17:31 +0900368
Magnus Damm897cfcd2007-09-10 12:06:03 +0900369static unsigned char irl2irq[HL_NR_IRL];
370
Paul Mundtae8a5342008-04-25 17:58:21 +0900371static int highlander_irq_demux(int irq)
Magnus Damm897cfcd2007-09-10 12:06:03 +0900372{
373 if (irq >= HL_NR_IRL || !irl2irq[irq])
374 return irq;
375
376 return irl2irq[irq];
377}
378
Paul Mundtae8a5342008-04-25 17:58:21 +0900379static void __init highlander_init_irq(void)
Magnus Damm897cfcd2007-09-10 12:06:03 +0900380{
Paul Mundtae8a5342008-04-25 17:58:21 +0900381 unsigned char *ucp = highlander_plat_irq_setup();
Magnus Damm897cfcd2007-09-10 12:06:03 +0900382
383 if (ucp) {
384 plat_irq_setup_pins(IRQ_MODE_IRL3210);
385 memcpy(irl2irq, ucp, HL_NR_IRL);
386 }
387}
388
Paul Mundt2c7834a2006-09-27 18:17:31 +0900389/*
390 * The Machine Vector
391 */
Paul Mundt82f81f42007-05-15 15:19:34 +0900392static struct sh_machine_vector mv_highlander __initmv = {
Paul Mundt32351a22007-03-12 14:38:59 +0900393 .mv_name = "Highlander",
Paul Mundt32351a22007-03-12 14:38:59 +0900394 .mv_setup = highlander_setup,
395 .mv_init_irq = highlander_init_irq,
Magnus Damm897cfcd2007-09-10 12:06:03 +0900396 .mv_irq_demux = highlander_irq_demux,
Paul Mundt2c7834a2006-09-27 18:17:31 +0900397};