blob: 920ea76abac82673eb80221640b985c798bd52d7 [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>
Paul Mundtc2933962008-03-25 16:49:30 +090020#include <linux/i2c.h>
Paul Mundt604437f2009-01-09 15:11:58 +090021#include <linux/irq.h>
Yoshihiro Shimoda6239b202009-05-26 09:33:05 +000022#include <linux/interrupt.h>
23#include <linux/usb/r8a66597.h>
Magnus Dammc6f93a32007-10-15 10:36:45 +090024#include <net/ax88796.h>
Paul Mundt5283ecb2006-09-27 15:59:17 +090025#include <asm/machvec.h>
Paul Mundt7639a452008-10-20 13:02:48 +090026#include <mach/highlander.h>
Paul Mundt5283ecb2006-09-27 15:59:17 +090027#include <asm/clock.h>
Paul Mundt8786c952007-08-20 13:03:41 +090028#include <asm/heartbeat.h>
Paul Mundt5283ecb2006-09-27 15:59:17 +090029#include <asm/io.h>
Magnus Dammc1a34e42008-02-07 20:23:53 +090030#include <asm/io_trapped.h>
Paul Mundt5283ecb2006-09-27 15:59:17 +090031
Yoshihiro Shimoda6239b202009-05-26 09:33:05 +000032static struct r8a66597_platdata r8a66597_data = {
33 .xtal = R8A66597_PLATDATA_XTAL_12MHZ,
34 .vif = 1,
35};
36
Yoshihiro Shimodae6c972f2007-07-17 13:38:54 +090037static struct resource r8a66597_usb_host_resources[] = {
38 [0] = {
Yoshihiro Shimodae6c972f2007-07-17 13:38:54 +090039 .start = 0xA4200000,
40 .end = 0xA42000FF,
41 .flags = IORESOURCE_MEM,
42 },
43 [1] = {
Magnus Damm897cfcd82007-09-10 12:06:03 +090044 .start = IRQ_EXT1, /* irq number */
45 .end = IRQ_EXT1,
Yoshihiro Shimoda6239b202009-05-26 09:33:05 +000046 .flags = IORESOURCE_IRQ | IRQF_TRIGGER_LOW,
Yoshihiro Shimodae6c972f2007-07-17 13:38:54 +090047 },
48};
49
50static struct platform_device r8a66597_usb_host_device = {
51 .name = "r8a66597_hcd",
52 .id = -1,
53 .dev = {
54 .dma_mask = NULL, /* don't use dma */
55 .coherent_dma_mask = 0xffffffff,
Yoshihiro Shimoda6239b202009-05-26 09:33:05 +000056 .platform_data = &r8a66597_data,
Yoshihiro Shimodae6c972f2007-07-17 13:38:54 +090057 },
58 .num_resources = ARRAY_SIZE(r8a66597_usb_host_resources),
59 .resource = r8a66597_usb_host_resources,
60};
61
62static struct resource m66592_usb_peripheral_resources[] = {
63 [0] = {
64 .name = "m66592_udc",
65 .start = 0xb0000000,
66 .end = 0xb00000FF,
67 .flags = IORESOURCE_MEM,
68 },
69 [1] = {
70 .name = "m66592_udc",
Magnus Damm897cfcd82007-09-10 12:06:03 +090071 .start = IRQ_EXT4, /* irq number */
72 .end = IRQ_EXT4,
Yoshihiro Shimodae6c972f2007-07-17 13:38:54 +090073 .flags = IORESOURCE_IRQ,
74 },
75};
76
77static struct platform_device m66592_usb_peripheral_device = {
78 .name = "m66592_udc",
79 .id = -1,
80 .dev = {
81 .dma_mask = NULL, /* don't use dma */
82 .coherent_dma_mask = 0xffffffff,
83 },
84 .num_resources = ARRAY_SIZE(m66592_usb_peripheral_resources),
85 .resource = m66592_usb_peripheral_resources,
86};
87
Paul Mundt0c020e32006-12-06 10:43:44 +090088static struct resource cf_ide_resources[] = {
89 [0] = {
Paul Mundt71074d32007-02-14 14:49:04 +090090 .start = PA_AREA5_IO + 0x1000,
91 .end = PA_AREA5_IO + 0x1000 + 0x08 - 1,
92 .flags = IORESOURCE_MEM,
Paul Mundt0c020e32006-12-06 10:43:44 +090093 },
94 [1] = {
Paul Mundt71074d32007-02-14 14:49:04 +090095 .start = PA_AREA5_IO + 0x80c,
96 .end = PA_AREA5_IO + 0x80c + 0x16 - 1,
97 .flags = IORESOURCE_MEM,
Paul Mundt0c020e32006-12-06 10:43:44 +090098 },
99 [2] = {
Magnus Damm897cfcd82007-09-10 12:06:03 +0900100 .start = IRQ_CF,
Paul Mundt0c020e32006-12-06 10:43:44 +0900101 .flags = IORESOURCE_IRQ,
102 },
103};
104
Paul Mundt71074d32007-02-14 14:49:04 +0900105static struct pata_platform_info pata_info = {
106 .ioport_shift = 1,
107};
108
Paul Mundt0c020e32006-12-06 10:43:44 +0900109static struct platform_device cf_ide_device = {
110 .name = "pata_platform",
111 .id = -1,
112 .num_resources = ARRAY_SIZE(cf_ide_resources),
113 .resource = cf_ide_resources,
Paul Mundt71074d32007-02-14 14:49:04 +0900114 .dev = {
115 .platform_data = &pata_info,
116 },
Paul Mundt0c020e32006-12-06 10:43:44 +0900117};
118
Paul Mundt3b4d9532007-02-13 15:42:28 +0900119static struct resource heartbeat_resources[] = {
120 [0] = {
121 .start = PA_OBLED,
Paul Mundta1fd3062007-08-23 15:11:44 +0900122 .end = PA_OBLED,
Paul Mundt3b4d9532007-02-13 15:42:28 +0900123 .flags = IORESOURCE_MEM,
124 },
125};
126
Paul Mundt8786c952007-08-20 13:03:41 +0900127#ifndef CONFIG_SH_R7785RP
128static unsigned char heartbeat_bit_pos[] = { 2, 1, 0, 3, 6, 5, 4, 7 };
129
130static struct heartbeat_data heartbeat_data = {
131 .bit_pos = heartbeat_bit_pos,
132 .nr_bits = ARRAY_SIZE(heartbeat_bit_pos),
133};
134#endif
135
Paul Mundt3b4d9532007-02-13 15:42:28 +0900136static struct platform_device heartbeat_device = {
137 .name = "heartbeat",
138 .id = -1,
Paul Mundt32351a22007-03-12 14:38:59 +0900139
140 /* R7785RP has a slightly more sensible FPGA.. */
141#ifndef CONFIG_SH_R7785RP
Paul Mundt3b4d9532007-02-13 15:42:28 +0900142 .dev = {
Paul Mundta1fd3062007-08-23 15:11:44 +0900143 .platform_data = &heartbeat_data,
Paul Mundt3b4d9532007-02-13 15:42:28 +0900144 },
Paul Mundt32351a22007-03-12 14:38:59 +0900145#endif
Paul Mundt3b4d9532007-02-13 15:42:28 +0900146 .num_resources = ARRAY_SIZE(heartbeat_resources),
147 .resource = heartbeat_resources,
148};
149
Magnus Dammc6f93a32007-10-15 10:36:45 +0900150static struct ax_plat_data ax88796_platdata = {
151 .flags = AXFLG_HAS_93CX6,
152 .wordlength = 2,
153 .dcr_val = 0x1,
154 .rcr_val = 0x40,
155};
156
157static struct resource ax88796_resources[] = {
158 {
159#ifdef CONFIG_SH_R7780RP
160 .start = 0xa5800400,
161 .end = 0xa5800400 + (0x20 * 0x2) - 1,
162#else
163 .start = 0xa4100400,
164 .end = 0xa4100400 + (0x20 * 0x2) - 1,
165#endif
166 .flags = IORESOURCE_MEM,
167 },
168 {
169 .start = IRQ_AX88796,
170 .end = IRQ_AX88796,
171 .flags = IORESOURCE_IRQ,
172 },
173};
174
175static struct platform_device ax88796_device = {
176 .name = "ax88796",
177 .id = 0,
178
179 .dev = {
180 .platform_data = &ax88796_platdata,
181 },
182
183 .num_resources = ARRAY_SIZE(ax88796_resources),
184 .resource = ax88796_resources,
185};
186
Paul Mundtc2933962008-03-25 16:49:30 +0900187static struct resource smbus_resources[] = {
188 [0] = {
189 .start = PA_SMCR,
190 .end = PA_SMCR + 0x100 - 1,
191 .flags = IORESOURCE_MEM,
192 },
193 [1] = {
194 .start = IRQ_SMBUS,
195 .end = IRQ_SMBUS,
196 .flags = IORESOURCE_IRQ,
197 },
198};
199
200static struct platform_device smbus_device = {
201 .name = "i2c-highlander",
202 .id = 0,
203 .num_resources = ARRAY_SIZE(smbus_resources),
204 .resource = smbus_resources,
205};
206
207static struct i2c_board_info __initdata highlander_i2c_devices[] = {
208 {
Jean Delvare3760f732008-04-29 23:11:40 +0200209 I2C_BOARD_INFO("r2025sd", 0x32),
Paul Mundtc2933962008-03-25 16:49:30 +0900210 },
211};
Magnus Dammc6f93a32007-10-15 10:36:45 +0900212
Paul Mundt5283ecb2006-09-27 15:59:17 +0900213static struct platform_device *r7780rp_devices[] __initdata = {
Yoshihiro Shimodae6c972f2007-07-17 13:38:54 +0900214 &r8a66597_usb_host_device,
215 &m66592_usb_peripheral_device,
Paul Mundt3b4d9532007-02-13 15:42:28 +0900216 &heartbeat_device,
Paul Mundtc2933962008-03-25 16:49:30 +0900217 &smbus_device,
Magnus Dammda2d7f42008-01-25 16:04:29 +0900218#ifndef CONFIG_SH_R7780RP
Magnus Dammc6f93a32007-10-15 10:36:45 +0900219 &ax88796_device,
Magnus Dammda2d7f42008-01-25 16:04:29 +0900220#endif
Paul Mundt5283ecb2006-09-27 15:59:17 +0900221};
222
Magnus Dammc1a34e42008-02-07 20:23:53 +0900223/*
224 * The CF is connected using a 16-bit bus where 8-bit operations are
225 * unsupported. The linux ata driver is however using 8-bit operations, so
226 * insert a trapped io filter to convert 8-bit operations into 16-bit.
227 */
228static struct trapped_io cf_trapped_io = {
229 .resource = cf_ide_resources,
230 .num_resources = 2,
231 .minimum_bus_width = 16,
232};
233
Paul Mundt5283ecb2006-09-27 15:59:17 +0900234static int __init r7780rp_devices_setup(void)
235{
Paul Mundtc2933962008-03-25 16:49:30 +0900236 int ret = 0;
237
Magnus Dammc1a34e42008-02-07 20:23:53 +0900238#ifndef CONFIG_SH_R7780RP
239 if (register_trapped_io(&cf_trapped_io) == 0)
Paul Mundtc2933962008-03-25 16:49:30 +0900240 ret |= platform_device_register(&cf_ide_device);
Magnus Dammc1a34e42008-02-07 20:23:53 +0900241#endif
Paul Mundtc2933962008-03-25 16:49:30 +0900242
243 ret |= platform_add_devices(r7780rp_devices,
Paul Mundt5283ecb2006-09-27 15:59:17 +0900244 ARRAY_SIZE(r7780rp_devices));
Paul Mundtc2933962008-03-25 16:49:30 +0900245
246 ret |= i2c_register_board_info(0, highlander_i2c_devices,
247 ARRAY_SIZE(highlander_i2c_devices));
248
249 return ret;
Paul Mundt5283ecb2006-09-27 15:59:17 +0900250}
Paul Mundt32351a22007-03-12 14:38:59 +0900251device_initcall(r7780rp_devices_setup);
Paul Mundt5283ecb2006-09-27 15:59:17 +0900252
253/*
254 * Platform specific clocks
255 */
256static void ivdr_clk_enable(struct clk *clk)
257{
Ryusuke Sakato39374aa2007-05-07 10:48:56 +0900258 ctrl_outw(ctrl_inw(PA_IVDRCTL) | (1 << IVDR_CK_ON), PA_IVDRCTL);
Paul Mundt5283ecb2006-09-27 15:59:17 +0900259}
260
261static void ivdr_clk_disable(struct clk *clk)
262{
Ryusuke Sakato39374aa2007-05-07 10:48:56 +0900263 ctrl_outw(ctrl_inw(PA_IVDRCTL) & ~(1 << IVDR_CK_ON), PA_IVDRCTL);
Paul Mundt5283ecb2006-09-27 15:59:17 +0900264}
265
266static struct clk_ops ivdr_clk_ops = {
267 .enable = ivdr_clk_enable,
268 .disable = ivdr_clk_disable,
269};
270
271static struct clk ivdr_clk = {
272 .name = "ivdr_clk",
273 .ops = &ivdr_clk_ops,
274};
275
276static struct clk *r7780rp_clocks[] = {
277 &ivdr_clk,
278};
279
Paul Mundt5283ecb2006-09-27 15:59:17 +0900280static void r7780rp_power_off(void)
281{
Paul Mundt32351a22007-03-12 14:38:59 +0900282 if (mach_is_r7780mp() || mach_is_r7785rp())
283 ctrl_outw(0x0001, PA_POFF);
Paul Mundt5283ecb2006-09-27 15:59:17 +0900284}
285
286/*
287 * Initialize the board
288 */
Paul Mundt32351a22007-03-12 14:38:59 +0900289static void __init highlander_setup(char **cmdline_p)
Paul Mundt5283ecb2006-09-27 15:59:17 +0900290{
291 u16 ver = ctrl_inw(PA_VERREG);
292 int i;
293
Paul Mundt32351a22007-03-12 14:38:59 +0900294 printk(KERN_INFO "Renesas Solutions Highlander %s support.\n",
295 mach_is_r7780rp() ? "R7780RP-1" :
296 mach_is_r7780mp() ? "R7780MP" :
297 "R7785RP");
Paul Mundt5283ecb2006-09-27 15:59:17 +0900298
299 printk(KERN_INFO "Board version: %d (revision %d), "
300 "FPGA version: %d (revision %d)\n",
301 (ver >> 12) & 0xf, (ver >> 8) & 0xf,
302 (ver >> 4) & 0xf, ver & 0xf);
303
Paul Mundt61dc6eae2008-10-23 12:35:43 +0900304 highlander_plat_pinmux_setup();
305
Paul Mundt5283ecb2006-09-27 15:59:17 +0900306 /*
307 * Enable the important clocks right away..
308 */
309 for (i = 0; i < ARRAY_SIZE(r7780rp_clocks); i++) {
310 struct clk *clk = r7780rp_clocks[i];
311
312 clk_register(clk);
313 clk_enable(clk);
314 }
315
316 ctrl_outw(0x0000, PA_OBLED); /* Clear LED. */
Paul Mundt32351a22007-03-12 14:38:59 +0900317
318 if (mach_is_r7780rp())
319 ctrl_outw(0x0001, PA_SDPOW); /* SD Power ON */
320
Paul Mundt2c081e72006-12-25 18:28:33 +0900321 ctrl_outw(ctrl_inw(PA_IVDRCTL) | 0x01, PA_IVDRCTL); /* Si13112 */
Paul Mundt5283ecb2006-09-27 15:59:17 +0900322
323 pm_power_off = r7780rp_power_off;
324}
Paul Mundt2c7834a2006-09-27 18:17:31 +0900325
Magnus Damm897cfcd82007-09-10 12:06:03 +0900326static unsigned char irl2irq[HL_NR_IRL];
327
Paul Mundtae8a5342008-04-25 17:58:21 +0900328static int highlander_irq_demux(int irq)
Magnus Damm897cfcd82007-09-10 12:06:03 +0900329{
330 if (irq >= HL_NR_IRL || !irl2irq[irq])
331 return irq;
332
333 return irl2irq[irq];
334}
335
Paul Mundtae8a5342008-04-25 17:58:21 +0900336static void __init highlander_init_irq(void)
Magnus Damm897cfcd82007-09-10 12:06:03 +0900337{
Paul Mundtae8a5342008-04-25 17:58:21 +0900338 unsigned char *ucp = highlander_plat_irq_setup();
Magnus Damm897cfcd82007-09-10 12:06:03 +0900339
340 if (ucp) {
341 plat_irq_setup_pins(IRQ_MODE_IRL3210);
342 memcpy(irl2irq, ucp, HL_NR_IRL);
343 }
344}
345
Paul Mundt2c7834a2006-09-27 18:17:31 +0900346/*
347 * The Machine Vector
348 */
Paul Mundt82f81f42007-05-15 15:19:34 +0900349static struct sh_machine_vector mv_highlander __initmv = {
Paul Mundt32351a22007-03-12 14:38:59 +0900350 .mv_name = "Highlander",
Paul Mundt32351a22007-03-12 14:38:59 +0900351 .mv_setup = highlander_setup,
352 .mv_init_irq = highlander_init_irq,
Magnus Damm897cfcd82007-09-10 12:06:03 +0900353 .mv_irq_demux = highlander_irq_demux,
Paul Mundt2c7834a2006-09-27 18:17:31 +0900354};