blob: 8125d20fdbd8695e722ae848c71a87db29e4d7dc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Renesas Technology Sales RTS7751R2D Support.
3 *
Paul Mundt9c575482007-02-15 18:20:52 +09004 * Copyright (C) 2002 - 2006 Atom Create Engineering Co., Ltd.
5 * Copyright (C) 2004 - 2007 Paul Mundt
Paul Mundtade2b3f2006-09-27 16:48:46 +09006 *
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
9 * for more details.
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/init.h>
Paul Mundtade2b3f2006-09-27 16:48:46 +090012#include <linux/platform_device.h>
Paul Mundt9c575482007-02-15 18:20:52 +090013#include <linux/pata_platform.h>
Paul Mundtade2b3f2006-09-27 16:48:46 +090014#include <linux/serial_8250.h>
Paul Mundtc87a7112007-03-01 18:47:08 +090015#include <linux/sm501.h>
Paul Mundta56d2762006-09-27 11:43:24 +090016#include <linux/pm.h>
Paul Mundt2c7834a2006-09-27 18:17:31 +090017#include <asm/machvec.h>
Paul Mundt9c575482007-02-15 18:20:52 +090018#include <asm/rts7751r2d.h>
Paul Mundtadf18902006-09-27 17:17:27 +090019#include <asm/voyagergx.h>
Paul Mundt9c575482007-02-15 18:20:52 +090020#include <asm/io.h>
Paul Mundtade2b3f2006-09-27 16:48:46 +090021
22static void __init voyagergx_serial_init(void)
23{
24 unsigned long val;
25
26 /*
27 * GPIO Control
28 */
Paul Mundt9c575482007-02-15 18:20:52 +090029 val = readl((void __iomem *)GPIO_MUX_HIGH);
Paul Mundtade2b3f2006-09-27 16:48:46 +090030 val |= 0x00001fe0;
Paul Mundt9c575482007-02-15 18:20:52 +090031 writel(val, (void __iomem *)GPIO_MUX_HIGH);
Paul Mundtade2b3f2006-09-27 16:48:46 +090032
33 /*
34 * Power Mode Gate
35 */
Paul Mundt9c575482007-02-15 18:20:52 +090036 val = readl((void __iomem *)POWER_MODE0_GATE);
Paul Mundtade2b3f2006-09-27 16:48:46 +090037 val |= (POWER_MODE0_GATE_U0 | POWER_MODE0_GATE_U1);
Paul Mundt9c575482007-02-15 18:20:52 +090038 writel(val, (void __iomem *)POWER_MODE0_GATE);
Paul Mundtade2b3f2006-09-27 16:48:46 +090039
Paul Mundt9c575482007-02-15 18:20:52 +090040 val = readl((void __iomem *)POWER_MODE1_GATE);
Paul Mundtade2b3f2006-09-27 16:48:46 +090041 val |= (POWER_MODE1_GATE_U0 | POWER_MODE1_GATE_U1);
Paul Mundt9c575482007-02-15 18:20:52 +090042 writel(val, (void __iomem *)POWER_MODE1_GATE);
Paul Mundtade2b3f2006-09-27 16:48:46 +090043}
44
Paul Mundt9c575482007-02-15 18:20:52 +090045static struct resource cf_ide_resources[] = {
46 [0] = {
47 .start = PA_AREA5_IO + 0x1000,
Aoi Shinkai43f4b8c2007-09-21 15:18:33 +090048 .end = PA_AREA5_IO + 0x1000 + 0x10 - 0x2,
Paul Mundt9c575482007-02-15 18:20:52 +090049 .flags = IORESOURCE_MEM,
50 },
51 [1] = {
52 .start = PA_AREA5_IO + 0x80c,
Aoi Shinkai43f4b8c2007-09-21 15:18:33 +090053 .end = PA_AREA5_IO + 0x80c,
Paul Mundt9c575482007-02-15 18:20:52 +090054 .flags = IORESOURCE_MEM,
55 },
Magnus Dammabac3f72007-11-23 14:39:13 +090056#ifndef CONFIG_RTS7751R2D_1 /* For R2D-1 polling is preferred */
Paul Mundt9c575482007-02-15 18:20:52 +090057 [2] = {
Magnus Damm2eeec852007-08-12 15:29:16 +090058 .start = IRQ_CF_IDE,
Paul Mundt9c575482007-02-15 18:20:52 +090059 .flags = IORESOURCE_IRQ,
60 },
Magnus Dammabac3f72007-11-23 14:39:13 +090061#endif
Paul Mundt9c575482007-02-15 18:20:52 +090062};
63
64static struct pata_platform_info pata_info = {
65 .ioport_shift = 1,
66};
67
68static struct platform_device cf_ide_device = {
69 .name = "pata_platform",
70 .id = -1,
71 .num_resources = ARRAY_SIZE(cf_ide_resources),
72 .resource = cf_ide_resources,
73 .dev = {
74 .platform_data = &pata_info,
75 },
76};
77
Magnus Dammf8b40d82007-08-12 15:30:40 +090078static struct resource heartbeat_resources[] = {
79 [0] = {
80 .start = PA_OUTPORT,
Paul Mundta1fd3062007-08-23 15:11:44 +090081 .end = PA_OUTPORT,
Magnus Dammf8b40d82007-08-12 15:30:40 +090082 .flags = IORESOURCE_MEM,
83 },
84};
85
86static struct platform_device heartbeat_device = {
87 .name = "heartbeat",
88 .id = -1,
89 .num_resources = ARRAY_SIZE(heartbeat_resources),
90 .resource = heartbeat_resources,
91};
92
93#ifdef CONFIG_MFD_SM501
Paul Mundt9c575482007-02-15 18:20:52 +090094static struct plat_serial8250_port uart_platform_data[] = {
95 {
96 .membase = (void __iomem *)VOYAGER_UART_BASE,
97 .mapbase = VOYAGER_UART_BASE,
98 .iotype = UPIO_MEM,
Magnus Damm48180ca2007-08-03 14:27:20 +090099 .irq = IRQ_SM501_U0,
Paul Mundt9c575482007-02-15 18:20:52 +0900100 .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,
101 .regshift = 2,
102 .uartclk = (9600 * 16),
Magnus Damm3a353822007-07-20 16:34:22 +0900103 },
104 { 0 },
Paul Mundt9c575482007-02-15 18:20:52 +0900105};
106
Paul Mundtade2b3f2006-09-27 16:48:46 +0900107static struct platform_device uart_device = {
108 .name = "serial8250",
Paul Mundt9c575482007-02-15 18:20:52 +0900109 .id = PLAT8250_DEV_PLATFORM,
Paul Mundtade2b3f2006-09-27 16:48:46 +0900110 .dev = {
111 .platform_data = uart_platform_data,
112 },
113};
114
Paul Mundtc87a7112007-03-01 18:47:08 +0900115static struct resource sm501_resources[] = {
116 [0] = {
117 .start = 0x10000000,
118 .end = 0x13e00000 - 1,
119 .flags = IORESOURCE_MEM,
120 },
121 [1] = {
122 .start = 0x13e00000,
123 .end = 0x13ffffff,
124 .flags = IORESOURCE_MEM,
125 },
126 [2] = {
Magnus Damm48180ca2007-08-03 14:27:20 +0900127 .start = IRQ_SM501_CV,
Paul Mundtc87a7112007-03-01 18:47:08 +0900128 .flags = IORESOURCE_IRQ,
129 },
130};
131
132static struct platform_device sm501_device = {
133 .name = "sm501",
134 .id = -1,
135 .num_resources = ARRAY_SIZE(sm501_resources),
136 .resource = sm501_resources,
137};
138
Magnus Dammf8b40d82007-08-12 15:30:40 +0900139#endif /* CONFIG_MFD_SM501 */
140
Paul Mundtade2b3f2006-09-27 16:48:46 +0900141static struct platform_device *rts7751r2d_devices[] __initdata = {
Magnus Dammf8b40d82007-08-12 15:30:40 +0900142#ifdef CONFIG_MFD_SM501
Paul Mundtade2b3f2006-09-27 16:48:46 +0900143 &uart_device,
Paul Mundtc87a7112007-03-01 18:47:08 +0900144 &sm501_device,
Magnus Dammf8b40d82007-08-12 15:30:40 +0900145#endif
Aoi Shinkai43f4b8c2007-09-21 15:18:33 +0900146 &cf_ide_device,
Magnus Dammf8b40d82007-08-12 15:30:40 +0900147 &heartbeat_device,
Paul Mundtade2b3f2006-09-27 16:48:46 +0900148};
149
150static int __init rts7751r2d_devices_setup(void)
151{
152 return platform_add_devices(rts7751r2d_devices,
153 ARRAY_SIZE(rts7751r2d_devices));
154}
Paul Mundt9c575482007-02-15 18:20:52 +0900155__initcall(rts7751r2d_devices_setup);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
Paul Mundta56d2762006-09-27 11:43:24 +0900157static void rts7751r2d_power_off(void)
158{
159 ctrl_outw(0x0001, PA_POWOFF);
160}
161
Aoi Shinkai43f4b8c2007-09-21 15:18:33 +0900162static inline unsigned char is_ide_ioaddr(unsigned long addr)
163{
164 return ((cf_ide_resources[0].start <= addr &&
165 addr <= cf_ide_resources[0].end) ||
166 (cf_ide_resources[1].start <= addr &&
167 addr <= cf_ide_resources[1].end));
168}
169
Paul Mundt02353f52007-09-21 15:21:55 +0900170void rts7751r2d_writeb(u8 b, void __iomem *addr)
Aoi Shinkai43f4b8c2007-09-21 15:18:33 +0900171{
172 unsigned long tmp = (unsigned long __force)addr;
173
174 if (is_ide_ioaddr(tmp))
175 ctrl_outw((u16)b, tmp);
176 else
177 ctrl_outb(b, tmp);
178}
179
Paul Mundt02353f52007-09-21 15:21:55 +0900180u8 rts7751r2d_readb(void __iomem *addr)
Aoi Shinkai43f4b8c2007-09-21 15:18:33 +0900181{
182 unsigned long tmp = (unsigned long __force)addr;
183
184 if (is_ide_ioaddr(tmp))
185 return ctrl_inw(tmp) & 0xff;
186 else
187 return ctrl_inb(tmp);
188}
189
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190/*
191 * Initialize the board
192 */
Paul Mundt2c7834a2006-09-27 18:17:31 +0900193static void __init rts7751r2d_setup(char **cmdline_p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194{
Paul Mundt9c575482007-02-15 18:20:52 +0900195 u16 ver = ctrl_inw(PA_VERREG);
196
197 printk(KERN_INFO "Renesas Technology Sales RTS7751R2D support.\n");
198
199 printk(KERN_INFO "FPGA version:%d (revision:%d)\n",
200 (ver >> 4) & 0xf, ver & 0xf);
Paul Mundt2c7834a2006-09-27 18:17:31 +0900201
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 ctrl_outw(0x0000, PA_OUTPORT);
Paul Mundta56d2762006-09-27 11:43:24 +0900203 pm_power_off = rts7751r2d_power_off;
Paul Mundtade2b3f2006-09-27 16:48:46 +0900204
205 voyagergx_serial_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206}
Paul Mundt2c7834a2006-09-27 18:17:31 +0900207
208/*
209 * The Machine Vector
210 */
Paul Mundt82f81f42007-05-15 15:19:34 +0900211static struct sh_machine_vector mv_rts7751r2d __initmv = {
Paul Mundt2c7834a2006-09-27 18:17:31 +0900212 .mv_name = "RTS7751R2D",
213 .mv_setup = rts7751r2d_setup,
Paul Mundt2c7834a2006-09-27 18:17:31 +0900214 .mv_init_irq = init_rts7751r2d_IRQ,
Paul Mundt2c7834a2006-09-27 18:17:31 +0900215 .mv_irq_demux = rts7751r2d_irq_demux,
Aoi Shinkai43f4b8c2007-09-21 15:18:33 +0900216 .mv_writeb = rts7751r2d_writeb,
217 .mv_readb = rts7751r2d_readb,
Magnus Dammf8b40d82007-08-12 15:30:40 +0900218#if defined(CONFIG_MFD_SM501) && defined(CONFIG_USB_OHCI_HCD)
Paul Mundt2c7834a2006-09-27 18:17:31 +0900219 .mv_consistent_alloc = voyagergx_consistent_alloc,
220 .mv_consistent_free = voyagergx_consistent_free,
221#endif
222};