Merge branch 'bkl/procfs' of git://git.kernel.org/pub/scm/linux/kernel/git/frederic...
[linux-2.6-block.git] / arch / sh / boards / mach-highlander / setup.c
CommitLineData
5283ecb5
PM
1/*
2 * arch/sh/boards/renesas/r7780rp/setup.c
3 *
32351a28
PM
4 * Renesas Solutions Highlander Support.
5 *
5283ecb5 6 * Copyright (C) 2002 Atom Create Engineering Co., Ltd.
c2933965 7 * Copyright (C) 2005 - 2008 Paul Mundt
5283ecb5 8 *
32351a28
PM
9 * This contains support for the R7780RP-1, R7780MP, and R7785RP
10 * Highlander modules.
5283ecb5
PM
11 *
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>
67bbabbc 17#include <linux/io.h>
5283ecb5 18#include <linux/platform_device.h>
0a87e3e9 19#include <linux/ata_platform.h>
b5751e2e 20#include <linux/types.h>
15ba400e 21#include <linux/mtd/physmap.h>
c2933965 22#include <linux/i2c.h>
604437f0 23#include <linux/irq.h>
6239b20d
YS
24#include <linux/interrupt.h>
25#include <linux/usb/r8a66597.h>
2c59b0b7 26#include <linux/usb/m66592.h>
c6f93a34 27#include <net/ax88796.h>
5283ecb5 28#include <asm/machvec.h>
7639a454 29#include <mach/highlander.h>
67bbabbc 30#include <asm/clkdev.h>
5283ecb5 31#include <asm/clock.h>
8786c952 32#include <asm/heartbeat.h>
5283ecb5 33#include <asm/io.h>
c1a34e4c 34#include <asm/io_trapped.h>
5283ecb5 35
6239b20d
YS
36static struct r8a66597_platdata r8a66597_data = {
37 .xtal = R8A66597_PLATDATA_XTAL_12MHZ,
38 .vif = 1,
39};
40
e6c972f2
YS
41static struct resource r8a66597_usb_host_resources[] = {
42 [0] = {
e6c972f2
YS
43 .start = 0xA4200000,
44 .end = 0xA42000FF,
45 .flags = IORESOURCE_MEM,
46 },
47 [1] = {
897cfcd8
MD
48 .start = IRQ_EXT1, /* irq number */
49 .end = IRQ_EXT1,
6239b20d 50 .flags = IORESOURCE_IRQ | IRQF_TRIGGER_LOW,
e6c972f2
YS
51 },
52};
53
54static struct platform_device r8a66597_usb_host_device = {
55 .name = "r8a66597_hcd",
56 .id = -1,
57 .dev = {
58 .dma_mask = NULL, /* don't use dma */
59 .coherent_dma_mask = 0xffffffff,
6239b20d 60 .platform_data = &r8a66597_data,
e6c972f2
YS
61 },
62 .num_resources = ARRAY_SIZE(r8a66597_usb_host_resources),
63 .resource = r8a66597_usb_host_resources,
64};
65
2c59b0b7
MD
66static struct m66592_platdata usbf_platdata = {
67 .xtal = M66592_PLATDATA_XTAL_24MHZ,
68 .vif = 1,
69};
70
e6c972f2
YS
71static struct resource m66592_usb_peripheral_resources[] = {
72 [0] = {
73 .name = "m66592_udc",
74 .start = 0xb0000000,
75 .end = 0xb00000FF,
76 .flags = IORESOURCE_MEM,
77 },
78 [1] = {
79 .name = "m66592_udc",
897cfcd8
MD
80 .start = IRQ_EXT4, /* irq number */
81 .end = IRQ_EXT4,
e6c972f2
YS
82 .flags = IORESOURCE_IRQ,
83 },
84};
85
86static struct platform_device m66592_usb_peripheral_device = {
87 .name = "m66592_udc",
88 .id = -1,
89 .dev = {
90 .dma_mask = NULL, /* don't use dma */
91 .coherent_dma_mask = 0xffffffff,
2c59b0b7 92 .platform_data = &usbf_platdata,
e6c972f2
YS
93 },
94 .num_resources = ARRAY_SIZE(m66592_usb_peripheral_resources),
95 .resource = m66592_usb_peripheral_resources,
96};
97
0c020e3d
PM
98static struct resource cf_ide_resources[] = {
99 [0] = {
71074d3a
PM
100 .start = PA_AREA5_IO + 0x1000,
101 .end = PA_AREA5_IO + 0x1000 + 0x08 - 1,
102 .flags = IORESOURCE_MEM,
0c020e3d
PM
103 },
104 [1] = {
71074d3a
PM
105 .start = PA_AREA5_IO + 0x80c,
106 .end = PA_AREA5_IO + 0x80c + 0x16 - 1,
107 .flags = IORESOURCE_MEM,
0c020e3d
PM
108 },
109 [2] = {
897cfcd8 110 .start = IRQ_CF,
0c020e3d
PM
111 .flags = IORESOURCE_IRQ,
112 },
113};
114
71074d3a
PM
115static struct pata_platform_info pata_info = {
116 .ioport_shift = 1,
117};
118
0c020e3d
PM
119static struct platform_device cf_ide_device = {
120 .name = "pata_platform",
121 .id = -1,
122 .num_resources = ARRAY_SIZE(cf_ide_resources),
123 .resource = cf_ide_resources,
71074d3a
PM
124 .dev = {
125 .platform_data = &pata_info,
126 },
0c020e3d
PM
127};
128
3b4d9539
PM
129static struct resource heartbeat_resources[] = {
130 [0] = {
131 .start = PA_OBLED,
a1fd306b 132 .end = PA_OBLED,
3b4d9539
PM
133 .flags = IORESOURCE_MEM,
134 },
135};
136
8786c952
PM
137#ifndef CONFIG_SH_R7785RP
138static unsigned char heartbeat_bit_pos[] = { 2, 1, 0, 3, 6, 5, 4, 7 };
139
140static struct heartbeat_data heartbeat_data = {
141 .bit_pos = heartbeat_bit_pos,
142 .nr_bits = ARRAY_SIZE(heartbeat_bit_pos),
143};
144#endif
145
3b4d9539
PM
146static struct platform_device heartbeat_device = {
147 .name = "heartbeat",
148 .id = -1,
32351a28
PM
149
150 /* R7785RP has a slightly more sensible FPGA.. */
151#ifndef CONFIG_SH_R7785RP
3b4d9539 152 .dev = {
a1fd306b 153 .platform_data = &heartbeat_data,
3b4d9539 154 },
32351a28 155#endif
3b4d9539
PM
156 .num_resources = ARRAY_SIZE(heartbeat_resources),
157 .resource = heartbeat_resources,
158};
159
c6f93a34
MD
160static struct ax_plat_data ax88796_platdata = {
161 .flags = AXFLG_HAS_93CX6,
162 .wordlength = 2,
163 .dcr_val = 0x1,
164 .rcr_val = 0x40,
165};
166
167static struct resource ax88796_resources[] = {
168 {
169#ifdef CONFIG_SH_R7780RP
170 .start = 0xa5800400,
171 .end = 0xa5800400 + (0x20 * 0x2) - 1,
172#else
173 .start = 0xa4100400,
174 .end = 0xa4100400 + (0x20 * 0x2) - 1,
175#endif
176 .flags = IORESOURCE_MEM,
177 },
178 {
179 .start = IRQ_AX88796,
180 .end = IRQ_AX88796,
181 .flags = IORESOURCE_IRQ,
182 },
183};
184
185static struct platform_device ax88796_device = {
186 .name = "ax88796",
187 .id = 0,
188
189 .dev = {
190 .platform_data = &ax88796_platdata,
191 },
192
193 .num_resources = ARRAY_SIZE(ax88796_resources),
194 .resource = ax88796_resources,
195};
196
15ba400e
NI
197static struct mtd_partition nor_flash_partitions[] = {
198 {
199 .name = "loader",
200 .offset = 0x00000000,
201 .size = 512 * 1024,
202 },
203 {
204 .name = "bootenv",
205 .offset = MTDPART_OFS_APPEND,
206 .size = 512 * 1024,
207 },
208 {
209 .name = "kernel",
210 .offset = MTDPART_OFS_APPEND,
211 .size = 4 * 1024 * 1024,
212 },
213 {
214 .name = "data",
215 .offset = MTDPART_OFS_APPEND,
216 .size = MTDPART_SIZ_FULL,
217 },
218};
219
220static struct physmap_flash_data nor_flash_data = {
221 .width = 4,
222 .parts = nor_flash_partitions,
223 .nr_parts = ARRAY_SIZE(nor_flash_partitions),
224};
225
226/* This config is flash board for mass production. */
227static struct resource nor_flash_resources[] = {
228 [0] = {
229 .start = PA_NORFLASH_ADDR,
230 .end = PA_NORFLASH_ADDR + PA_NORFLASH_SIZE - 1,
231 .flags = IORESOURCE_MEM,
232 }
233};
234
235static struct platform_device nor_flash_device = {
236 .name = "physmap-flash",
237 .dev = {
238 .platform_data = &nor_flash_data,
239 },
240 .num_resources = ARRAY_SIZE(nor_flash_resources),
241 .resource = nor_flash_resources,
242};
243
c2933965
PM
244static struct resource smbus_resources[] = {
245 [0] = {
246 .start = PA_SMCR,
247 .end = PA_SMCR + 0x100 - 1,
248 .flags = IORESOURCE_MEM,
249 },
250 [1] = {
251 .start = IRQ_SMBUS,
252 .end = IRQ_SMBUS,
253 .flags = IORESOURCE_IRQ,
254 },
255};
256
257static struct platform_device smbus_device = {
258 .name = "i2c-highlander",
259 .id = 0,
260 .num_resources = ARRAY_SIZE(smbus_resources),
261 .resource = smbus_resources,
262};
263
264static struct i2c_board_info __initdata highlander_i2c_devices[] = {
265 {
3760f736 266 I2C_BOARD_INFO("r2025sd", 0x32),
c2933965
PM
267 },
268};
c6f93a34 269
5283ecb5 270static struct platform_device *r7780rp_devices[] __initdata = {
e6c972f2
YS
271 &r8a66597_usb_host_device,
272 &m66592_usb_peripheral_device,
3b4d9539 273 &heartbeat_device,
c2933965 274 &smbus_device,
15ba400e 275 &nor_flash_device,
da2d7f4b 276#ifndef CONFIG_SH_R7780RP
c6f93a34 277 &ax88796_device,
da2d7f4b 278#endif
5283ecb5
PM
279};
280
c1a34e4c
MD
281/*
282 * The CF is connected using a 16-bit bus where 8-bit operations are
283 * unsupported. The linux ata driver is however using 8-bit operations, so
284 * insert a trapped io filter to convert 8-bit operations into 16-bit.
285 */
286static struct trapped_io cf_trapped_io = {
287 .resource = cf_ide_resources,
288 .num_resources = 2,
289 .minimum_bus_width = 16,
290};
291
5283ecb5
PM
292static int __init r7780rp_devices_setup(void)
293{
c2933965
PM
294 int ret = 0;
295
c1a34e4c
MD
296#ifndef CONFIG_SH_R7780RP
297 if (register_trapped_io(&cf_trapped_io) == 0)
c2933965 298 ret |= platform_device_register(&cf_ide_device);
c1a34e4c 299#endif
c2933965
PM
300
301 ret |= platform_add_devices(r7780rp_devices,
5283ecb5 302 ARRAY_SIZE(r7780rp_devices));
c2933965
PM
303
304 ret |= i2c_register_board_info(0, highlander_i2c_devices,
305 ARRAY_SIZE(highlander_i2c_devices));
306
307 return ret;
5283ecb5 308}
32351a28 309device_initcall(r7780rp_devices_setup);
5283ecb5
PM
310
311/*
312 * Platform specific clocks
313 */
39f4490c 314static int ivdr_clk_enable(struct clk *clk)
5283ecb5 315{
9d56dd3b 316 __raw_writew(__raw_readw(PA_IVDRCTL) | (1 << IVDR_CK_ON), PA_IVDRCTL);
39f4490c 317 return 0;
5283ecb5
PM
318}
319
320static void ivdr_clk_disable(struct clk *clk)
321{
9d56dd3b 322 __raw_writew(__raw_readw(PA_IVDRCTL) & ~(1 << IVDR_CK_ON), PA_IVDRCTL);
5283ecb5
PM
323}
324
325static struct clk_ops ivdr_clk_ops = {
326 .enable = ivdr_clk_enable,
327 .disable = ivdr_clk_disable,
328};
329
330static struct clk ivdr_clk = {
5283ecb5
PM
331 .ops = &ivdr_clk_ops,
332};
333
334static struct clk *r7780rp_clocks[] = {
335 &ivdr_clk,
336};
337
67bbabbc
MD
338#define CLKDEV_CON_ID(_id, _clk) { .con_id = _id, .clk = _clk }
339
340static struct clk_lookup lookups[] = {
341 /* main clocks */
342 CLKDEV_CON_ID("ivdr_clk", &ivdr_clk),
343};
344
5283ecb5
PM
345static void r7780rp_power_off(void)
346{
32351a28 347 if (mach_is_r7780mp() || mach_is_r7785rp())
9d56dd3b 348 __raw_writew(0x0001, PA_POFF);
5283ecb5
PM
349}
350
351/*
352 * Initialize the board
353 */
32351a28 354static void __init highlander_setup(char **cmdline_p)
5283ecb5 355{
9d56dd3b 356 u16 ver = __raw_readw(PA_VERREG);
5283ecb5
PM
357 int i;
358
32351a28
PM
359 printk(KERN_INFO "Renesas Solutions Highlander %s support.\n",
360 mach_is_r7780rp() ? "R7780RP-1" :
361 mach_is_r7780mp() ? "R7780MP" :
362 "R7785RP");
5283ecb5
PM
363
364 printk(KERN_INFO "Board version: %d (revision %d), "
365 "FPGA version: %d (revision %d)\n",
366 (ver >> 12) & 0xf, (ver >> 8) & 0xf,
367 (ver >> 4) & 0xf, ver & 0xf);
368
61dc6eae
PM
369 highlander_plat_pinmux_setup();
370
5283ecb5
PM
371 /*
372 * Enable the important clocks right away..
373 */
374 for (i = 0; i < ARRAY_SIZE(r7780rp_clocks); i++) {
375 struct clk *clk = r7780rp_clocks[i];
376
377 clk_register(clk);
378 clk_enable(clk);
379 }
380
67bbabbc
MD
381 clkdev_add_table(lookups, ARRAY_SIZE(lookups));
382
9d56dd3b 383 __raw_writew(0x0000, PA_OBLED); /* Clear LED. */
32351a28
PM
384
385 if (mach_is_r7780rp())
9d56dd3b 386 __raw_writew(0x0001, PA_SDPOW); /* SD Power ON */
32351a28 387
9d56dd3b 388 __raw_writew(__raw_readw(PA_IVDRCTL) | 0x01, PA_IVDRCTL); /* Si13112 */
5283ecb5
PM
389
390 pm_power_off = r7780rp_power_off;
391}
2c7834a6 392
897cfcd8
MD
393static unsigned char irl2irq[HL_NR_IRL];
394
ae8a5348 395static int highlander_irq_demux(int irq)
897cfcd8 396{
90163320 397 if (irq >= HL_NR_IRL || irq < 0 || !irl2irq[irq])
897cfcd8
MD
398 return irq;
399
400 return irl2irq[irq];
401}
402
ae8a5348 403static void __init highlander_init_irq(void)
897cfcd8 404{
ae8a5348 405 unsigned char *ucp = highlander_plat_irq_setup();
897cfcd8
MD
406
407 if (ucp) {
408 plat_irq_setup_pins(IRQ_MODE_IRL3210);
409 memcpy(irl2irq, ucp, HL_NR_IRL);
410 }
411}
412
2c7834a6
PM
413/*
414 * The Machine Vector
415 */
82f81f47 416static struct sh_machine_vector mv_highlander __initmv = {
32351a28 417 .mv_name = "Highlander",
32351a28
PM
418 .mv_setup = highlander_setup,
419 .mv_init_irq = highlander_init_irq,
897cfcd8 420 .mv_irq_demux = highlander_irq_demux,
2c7834a6 421};