blob: 7850818bb4e88b82a1e96d1955e52c14ab4615e1 [file] [log] [blame]
Kuninori Morimoto4138b742009-08-19 12:08:33 +00001/*
2 * Copyright (C) 2009 Renesas Solutions Corp.
3 *
4 * Kuninori Morimoto <morimoto.kuninori@renesas.com>
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10
11#include <linux/init.h>
12#include <linux/device.h>
13#include <linux/platform_device.h>
14#include <linux/mtd/physmap.h>
15#include <linux/gpio.h>
16#include <linux/interrupt.h>
Kuninori Morimoto35a35402009-08-26 11:04:26 +000017#include <linux/io.h>
18#include <linux/delay.h>
Kuninori Morimoto907050a2009-08-26 11:04:31 +000019#include <linux/usb/r8a66597.h>
Kuninori Morimoto4138b742009-08-19 12:08:33 +000020#include <asm/heartbeat.h>
Kuninori Morimoto35a35402009-08-26 11:04:26 +000021#include <asm/sh_eth.h>
Kuninori Morimoto4138b742009-08-19 12:08:33 +000022#include <cpu/sh7724.h>
23
24/*
Kuninori Morimotob7056bc2009-08-26 11:04:22 +000025 * Address Interface BusWidth
26 *-----------------------------------------
27 * 0x0000_0000 uboot 16bit
28 * 0x0004_0000 Linux romImage 16bit
29 * 0x0014_0000 MTD for Linux 16bit
30 * 0x0400_0000 Internal I/O 16/32bit
31 * 0x0800_0000 DRAM 32bit
32 * 0x1800_0000 MFI 16bit
Kuninori Morimoto4138b742009-08-19 12:08:33 +000033 */
34
35/* Heartbeat */
36static unsigned char led_pos[] = { 0, 1, 2, 3 };
37static struct heartbeat_data heartbeat_data = {
38 .regsize = 8,
39 .nr_bits = 4,
40 .bit_pos = led_pos,
41};
42
43static struct resource heartbeat_resources[] = {
44 [0] = {
45 .start = 0xA405012C, /* PTG */
46 .end = 0xA405012E - 1,
47 .flags = IORESOURCE_MEM,
48 },
49};
50
51static struct platform_device heartbeat_device = {
52 .name = "heartbeat",
53 .id = -1,
54 .dev = {
55 .platform_data = &heartbeat_data,
56 },
57 .num_resources = ARRAY_SIZE(heartbeat_resources),
58 .resource = heartbeat_resources,
59};
60
61/* MTD */
62static struct mtd_partition nor_flash_partitions[] = {
63 {
Kuninori Morimotob7056bc2009-08-26 11:04:22 +000064 .name = "boot loader",
Kuninori Morimoto4138b742009-08-19 12:08:33 +000065 .offset = 0,
Kuninori Morimotob7056bc2009-08-26 11:04:22 +000066 .size = (5 * 1024 * 1024),
Kuninori Morimoto4138b742009-08-19 12:08:33 +000067 .mask_flags = MTD_CAP_ROM,
68 }, {
Kuninori Morimoto4138b742009-08-19 12:08:33 +000069 .name = "free-area",
70 .offset = MTDPART_OFS_APPEND,
71 .size = MTDPART_SIZ_FULL,
72 },
73};
74
75static struct physmap_flash_data nor_flash_data = {
76 .width = 2,
77 .parts = nor_flash_partitions,
78 .nr_parts = ARRAY_SIZE(nor_flash_partitions),
79};
80
81static struct resource nor_flash_resources[] = {
82 [0] = {
83 .name = "NOR Flash",
84 .start = 0x00000000,
85 .end = 0x03ffffff,
86 .flags = IORESOURCE_MEM,
87 }
88};
89
90static struct platform_device nor_flash_device = {
91 .name = "physmap-flash",
92 .resource = nor_flash_resources,
93 .num_resources = ARRAY_SIZE(nor_flash_resources),
94 .dev = {
95 .platform_data = &nor_flash_data,
96 },
97};
98
Kuninori Morimoto35a35402009-08-26 11:04:26 +000099/* SH Eth */
100#define SH_ETH_ADDR (0xA4600000)
101#define SH_ETH_MAHR (SH_ETH_ADDR + 0x1C0)
102#define SH_ETH_MALR (SH_ETH_ADDR + 0x1C8)
103static struct resource sh_eth_resources[] = {
104 [0] = {
105 .start = SH_ETH_ADDR,
106 .end = SH_ETH_ADDR + 0x1FC,
107 .flags = IORESOURCE_MEM,
108 },
109 [1] = {
110 .start = 91,
111 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,
112 },
113};
114
115struct sh_eth_plat_data sh_eth_plat = {
116 .phy = 0x1f, /* SMSC LAN8700 */
117 .edmac_endian = EDMAC_LITTLE_ENDIAN,
118};
119
120static struct platform_device sh_eth_device = {
121 .name = "sh-eth",
122 .id = 0,
123 .dev = {
124 .platform_data = &sh_eth_plat,
125 },
126 .num_resources = ARRAY_SIZE(sh_eth_resources),
127 .resource = sh_eth_resources,
128};
129
Kuninori Morimoto907050a2009-08-26 11:04:31 +0000130/* USB0 host */
131void usb0_port_power(int port, int power)
132{
133 gpio_set_value(GPIO_PTB4, power);
134}
135
136static struct r8a66597_platdata usb0_host_data = {
137 .on_chip = 1,
138 .port_power = usb0_port_power,
139};
140
141static struct resource usb0_host_resources[] = {
142 [0] = {
143 .start = 0xa4d80000,
144 .end = 0xa4d80124 - 1,
145 .flags = IORESOURCE_MEM,
146 },
147 [1] = {
148 .start = 65,
149 .end = 65,
150 .flags = IORESOURCE_IRQ | IRQF_TRIGGER_LOW,
151 },
152};
153
154static struct platform_device usb0_host_device = {
155 .name = "r8a66597_hcd",
156 .id = 0,
157 .dev = {
158 .dma_mask = NULL, /* not use dma */
159 .coherent_dma_mask = 0xffffffff,
160 .platform_data = &usb0_host_data,
161 },
162 .num_resources = ARRAY_SIZE(usb0_host_resources),
163 .resource = usb0_host_resources,
164};
165
166/*
167 * USB1
168 *
169 * CN5 can use both host/function,
170 * and we can determine it by checking PTB[3]
171 *
172 * This time only USB1 host is supported.
173 */
174void usb1_port_power(int port, int power)
175{
176 if (!gpio_get_value(GPIO_PTB3)) {
177 printk(KERN_ERR "USB1 function is not supported\n");
178 return;
179 }
180
181 gpio_set_value(GPIO_PTB5, power);
182}
183
184static struct r8a66597_platdata usb1_host_data = {
185 .on_chip = 1,
186 .port_power = usb1_port_power,
187};
188
189static struct resource usb1_host_resources[] = {
190 [0] = {
191 .start = 0xa4d90000,
192 .end = 0xa4d90124 - 1,
193 .flags = IORESOURCE_MEM,
194 },
195 [1] = {
196 .start = 66,
197 .end = 66,
198 .flags = IORESOURCE_IRQ | IRQF_TRIGGER_LOW,
199 },
200};
201
202static struct platform_device usb1_host_device = {
203 .name = "r8a66597_hcd",
204 .id = 1,
205 .dev = {
206 .dma_mask = NULL, /* not use dma */
207 .coherent_dma_mask = 0xffffffff,
208 .platform_data = &usb1_host_data,
209 },
210 .num_resources = ARRAY_SIZE(usb1_host_resources),
211 .resource = usb1_host_resources,
212};
213
Kuninori Morimoto4138b742009-08-19 12:08:33 +0000214static struct platform_device *ecovec_devices[] __initdata = {
215 &heartbeat_device,
216 &nor_flash_device,
Kuninori Morimoto35a35402009-08-26 11:04:26 +0000217 &sh_eth_device,
Kuninori Morimoto907050a2009-08-26 11:04:31 +0000218 &usb0_host_device,
219 &usb1_host_device, /* USB1 host support */
Kuninori Morimoto4138b742009-08-19 12:08:33 +0000220};
221
222static int __init devices_setup(void)
223{
224 /* enable SCIFA0 */
225 gpio_request(GPIO_FN_SCIF0_TXD, NULL);
226 gpio_request(GPIO_FN_SCIF0_RXD, NULL);
Kuninori Morimoto4138b742009-08-19 12:08:33 +0000227
228 /* enable debug LED */
229 gpio_request(GPIO_PTG0, NULL);
230 gpio_request(GPIO_PTG1, NULL);
231 gpio_request(GPIO_PTG2, NULL);
232 gpio_request(GPIO_PTG3, NULL);
Kuninori Morimotob7056bc2009-08-26 11:04:22 +0000233 gpio_direction_output(GPIO_PTG0, 0);
234 gpio_direction_output(GPIO_PTG1, 0);
235 gpio_direction_output(GPIO_PTG2, 0);
236 gpio_direction_output(GPIO_PTG3, 0);
Kuninori Morimoto4138b742009-08-19 12:08:33 +0000237
Kuninori Morimoto35a35402009-08-26 11:04:26 +0000238 /* enable SH-Eth */
239 gpio_request(GPIO_PTA1, NULL);
240 gpio_direction_output(GPIO_PTA1, 1);
241 mdelay(20);
242
243 gpio_request(GPIO_FN_RMII_RXD0, NULL);
244 gpio_request(GPIO_FN_RMII_RXD1, NULL);
245 gpio_request(GPIO_FN_RMII_TXD0, NULL);
246 gpio_request(GPIO_FN_RMII_TXD1, NULL);
247 gpio_request(GPIO_FN_RMII_REF_CLK, NULL);
248 gpio_request(GPIO_FN_RMII_TX_EN, NULL);
249 gpio_request(GPIO_FN_RMII_RX_ER, NULL);
250 gpio_request(GPIO_FN_RMII_CRS_DV, NULL);
251 gpio_request(GPIO_FN_MDIO, NULL);
252 gpio_request(GPIO_FN_MDC, NULL);
253 gpio_request(GPIO_FN_LNKSTA, NULL);
254
Kuninori Morimoto907050a2009-08-26 11:04:31 +0000255 /* enable USB */
256 gpio_request(GPIO_PTB3, NULL);
257 gpio_request(GPIO_PTB4, NULL);
258 gpio_request(GPIO_PTB5, NULL);
259 gpio_direction_input(GPIO_PTB3);
260 gpio_direction_output(GPIO_PTB4, 0);
261 gpio_direction_output(GPIO_PTB5, 0);
262 ctrl_outw(0x0600, 0xa40501d4);
263 ctrl_outw(0x0600, 0xa4050192);
264
Kuninori Morimoto4138b742009-08-19 12:08:33 +0000265 return platform_add_devices(ecovec_devices,
266 ARRAY_SIZE(ecovec_devices));
267}
268device_initcall(devices_setup);
269
270static struct sh_machine_vector mv_ecovec __initmv = {
271 .mv_name = "R0P7724 (EcoVec)",
272};