blob: 00381249d7665ef6fea66d57f53cc2127d09814b [file] [log] [blame]
Ronen Shitrit1e780452007-10-23 15:14:42 -04001/*
Lennert Buytenhek9dd0b192008-03-27 14:51:41 -04002 * arch/arm/mach-orion5x/kurobox_pro-setup.c
Ronen Shitrit1e780452007-10-23 15:14:42 -04003 *
4 * Maintainer: Ronen Shitrit <rshitrit@marvell.com>
5 *
Lennert Buytenhek159ffb32008-03-27 14:51:41 -04006 * This file is licensed under the terms of the GNU General Public
7 * License version 2. This program is licensed "as is" without any
Ronen Shitrit1e780452007-10-23 15:14:42 -04008 * warranty of any kind, whether express or implied.
9 */
10
11#include <linux/kernel.h>
12#include <linux/init.h>
13#include <linux/platform_device.h>
14#include <linux/pci.h>
15#include <linux/irq.h>
Sylver Bruneaua0087f22008-04-30 08:14:58 +020016#include <linux/delay.h>
Ronen Shitrit1e780452007-10-23 15:14:42 -040017#include <linux/mtd/physmap.h>
18#include <linux/mtd/nand.h>
19#include <linux/mv643xx_eth.h>
20#include <linux/i2c.h>
Sylver Bruneaua0087f22008-04-30 08:14:58 +020021#include <linux/serial_reg.h>
Byron Bradley3b277c22008-02-08 18:20:01 +000022#include <linux/ata_platform.h>
Ronen Shitrit1e780452007-10-23 15:14:42 -040023#include <asm/mach-types.h>
24#include <asm/gpio.h>
25#include <asm/mach/arch.h>
26#include <asm/mach/pci.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010027#include <mach/orion5x.h>
Lennert Buytenhek6f088f12008-08-09 13:44:58 +020028#include <plat/orion_nand.h>
Ronen Shitrit1e780452007-10-23 15:14:42 -040029#include "common.h"
Lennert Buytenhek19cfd5c2008-05-10 23:25:46 +020030#include "mpp.h"
Ronen Shitrit1e780452007-10-23 15:14:42 -040031
32/*****************************************************************************
33 * KUROBOX-PRO Info
34 ****************************************************************************/
35
36/*
37 * 256K NOR flash Device bus boot chip select
38 */
39
40#define KUROBOX_PRO_NOR_BOOT_BASE 0xf4000000
41#define KUROBOX_PRO_NOR_BOOT_SIZE SZ_256K
42
43/*
44 * 256M NAND flash on Device bus chip select 1
45 */
46
47#define KUROBOX_PRO_NAND_BASE 0xfc000000
48#define KUROBOX_PRO_NAND_SIZE SZ_2M
49
50/*****************************************************************************
51 * 256MB NAND Flash on Device bus CS0
52 ****************************************************************************/
53
54static struct mtd_partition kurobox_pro_nand_parts[] = {
55 {
56 .name = "uImage",
57 .offset = 0,
58 .size = SZ_4M,
Lennert Buytenheke7068ad2008-05-10 16:30:01 +020059 }, {
Ronen Shitrit1e780452007-10-23 15:14:42 -040060 .name = "rootfs",
61 .offset = SZ_4M,
62 .size = SZ_64M,
Lennert Buytenheke7068ad2008-05-10 16:30:01 +020063 }, {
Ronen Shitrit1e780452007-10-23 15:14:42 -040064 .name = "extra",
65 .offset = SZ_4M + SZ_64M,
66 .size = SZ_256M - (SZ_4M + SZ_64M),
67 },
68};
69
70static struct resource kurobox_pro_nand_resource = {
71 .flags = IORESOURCE_MEM,
72 .start = KUROBOX_PRO_NAND_BASE,
73 .end = KUROBOX_PRO_NAND_BASE + KUROBOX_PRO_NAND_SIZE - 1,
74};
75
76static struct orion_nand_data kurobox_pro_nand_data = {
77 .parts = kurobox_pro_nand_parts,
78 .nr_parts = ARRAY_SIZE(kurobox_pro_nand_parts),
79 .cle = 0,
80 .ale = 1,
81 .width = 8,
82};
83
84static struct platform_device kurobox_pro_nand_flash = {
85 .name = "orion_nand",
86 .id = -1,
87 .dev = {
88 .platform_data = &kurobox_pro_nand_data,
89 },
90 .resource = &kurobox_pro_nand_resource,
91 .num_resources = 1,
92};
93
94/*****************************************************************************
95 * 256KB NOR Flash on BOOT Device
96 ****************************************************************************/
97
98static struct physmap_flash_data kurobox_pro_nor_flash_data = {
99 .width = 1,
100};
101
102static struct resource kurobox_pro_nor_flash_resource = {
103 .flags = IORESOURCE_MEM,
104 .start = KUROBOX_PRO_NOR_BOOT_BASE,
105 .end = KUROBOX_PRO_NOR_BOOT_BASE + KUROBOX_PRO_NOR_BOOT_SIZE - 1,
106};
107
108static struct platform_device kurobox_pro_nor_flash = {
109 .name = "physmap-flash",
110 .id = 0,
111 .dev = {
112 .platform_data = &kurobox_pro_nor_flash_data,
113 },
114 .num_resources = 1,
115 .resource = &kurobox_pro_nor_flash_resource,
116};
117
118/*****************************************************************************
119 * PCI
120 ****************************************************************************/
121
Ralf Baechled5341942011-06-10 15:30:21 +0100122static int __init kurobox_pro_pci_map_irq(const struct pci_dev *dev, u8 slot,
123 u8 pin)
Ronen Shitrit1e780452007-10-23 15:14:42 -0400124{
Lennert Buytenhek92b913b2008-04-25 16:28:33 -0400125 int irq;
126
127 /*
128 * Check for devices with hard-wired IRQs.
129 */
130 irq = orion5x_pci_map_irq(dev, slot, pin);
131 if (irq != -1)
132 return irq;
133
Ronen Shitrit1e780452007-10-23 15:14:42 -0400134 /*
135 * PCI isn't used on the Kuro
136 */
Ronen Shitrit1e780452007-10-23 15:14:42 -0400137 return -1;
138}
139
140static struct hw_pci kurobox_pro_pci __initdata = {
Lennert Buytenhekbbdf1c12008-05-15 10:31:14 +0100141 .nr_controllers = 2,
Ronen Shitrit1e780452007-10-23 15:14:42 -0400142 .swizzle = pci_std_swizzle,
Lennert Buytenhek9dd0b192008-03-27 14:51:41 -0400143 .setup = orion5x_pci_sys_setup,
144 .scan = orion5x_pci_sys_scan_bus,
Ronen Shitrit1e780452007-10-23 15:14:42 -0400145 .map_irq = kurobox_pro_pci_map_irq,
146};
147
148static int __init kurobox_pro_pci_init(void)
149{
Per Andersson7a6bb262008-08-11 12:00:52 +0200150 if (machine_is_kurobox_pro()) {
151 orion5x_pci_disable();
Ronen Shitrit1e780452007-10-23 15:14:42 -0400152 pci_common_init(&kurobox_pro_pci);
Per Andersson7a6bb262008-08-11 12:00:52 +0200153 }
Ronen Shitrit1e780452007-10-23 15:14:42 -0400154
155 return 0;
156}
157
158subsys_initcall(kurobox_pro_pci_init);
159
160/*****************************************************************************
161 * Ethernet
162 ****************************************************************************/
163
164static struct mv643xx_eth_platform_data kurobox_pro_eth_data = {
Lennert Buytenhekac8406052008-08-26 14:06:47 +0200165 .phy_addr = MV643XX_ETH_PHY_ADDR(8),
Ronen Shitrit1e780452007-10-23 15:14:42 -0400166};
167
168/*****************************************************************************
169 * RTC 5C372a on I2C bus
170 ****************************************************************************/
171static struct i2c_board_info __initdata kurobox_pro_i2c_rtc = {
Jean Delvare3760f732008-04-29 23:11:40 +0200172 I2C_BOARD_INFO("rs5c372a", 0x32),
Ronen Shitrit1e780452007-10-23 15:14:42 -0400173};
174
175/*****************************************************************************
Byron Bradley3b277c22008-02-08 18:20:01 +0000176 * SATA
177 ****************************************************************************/
178static struct mv_sata_platform_data kurobox_pro_sata_data = {
Lennert Buytenheke7068ad2008-05-10 16:30:01 +0200179 .n_ports = 2,
Byron Bradley3b277c22008-02-08 18:20:01 +0000180};
181
182/*****************************************************************************
Sylver Bruneaua0087f22008-04-30 08:14:58 +0200183 * Kurobox Pro specific power off method via UART1-attached microcontroller
184 ****************************************************************************/
185
186#define UART1_REG(x) (UART1_VIRT_BASE + ((UART_##x) << 2))
187
188static int kurobox_pro_miconread(unsigned char *buf, int count)
189{
190 int i;
191 int timeout;
192
193 for (i = 0; i < count; i++) {
194 timeout = 10;
195
196 while (!(readl(UART1_REG(LSR)) & UART_LSR_DR)) {
197 if (--timeout == 0)
198 break;
199 udelay(1000);
200 }
201
202 if (timeout == 0)
203 break;
204 buf[i] = readl(UART1_REG(RX));
205 }
206
207 /* return read bytes */
208 return i;
209}
210
211static int kurobox_pro_miconwrite(const unsigned char *buf, int count)
212{
213 int i = 0;
214
215 while (count--) {
216 while (!(readl(UART1_REG(LSR)) & UART_LSR_THRE))
217 barrier();
218 writel(buf[i++], UART1_REG(TX));
219 }
220
221 return 0;
222}
223
224static int kurobox_pro_miconsend(const unsigned char *data, int count)
225{
226 int i;
227 unsigned char checksum = 0;
228 unsigned char recv_buf[40];
229 unsigned char send_buf[40];
230 unsigned char correct_ack[3];
231 int retry = 2;
232
233 /* Generate checksum */
234 for (i = 0; i < count; i++)
235 checksum -= data[i];
236
237 do {
238 /* Send data */
239 kurobox_pro_miconwrite(data, count);
240
241 /* send checksum */
242 kurobox_pro_miconwrite(&checksum, 1);
243
244 if (kurobox_pro_miconread(recv_buf, sizeof(recv_buf)) <= 3) {
245 printk(KERN_ERR ">%s: receive failed.\n", __func__);
246
247 /* send preamble to clear the receive buffer */
248 memset(&send_buf, 0xff, sizeof(send_buf));
249 kurobox_pro_miconwrite(send_buf, sizeof(send_buf));
250
251 /* make dummy reads */
252 mdelay(100);
253 kurobox_pro_miconread(recv_buf, sizeof(recv_buf));
254 } else {
255 /* Generate expected ack */
256 correct_ack[0] = 0x01;
257 correct_ack[1] = data[1];
258 correct_ack[2] = 0x00;
259
260 /* checksum Check */
261 if ((recv_buf[0] + recv_buf[1] + recv_buf[2] +
262 recv_buf[3]) & 0xFF) {
263 printk(KERN_ERR ">%s: Checksum Error : "
264 "Received data[%02x, %02x, %02x, %02x]"
265 "\n", __func__, recv_buf[0],
266 recv_buf[1], recv_buf[2], recv_buf[3]);
267 } else {
268 /* Check Received Data */
269 if (correct_ack[0] == recv_buf[0] &&
270 correct_ack[1] == recv_buf[1] &&
271 correct_ack[2] == recv_buf[2]) {
272 /* Interval for next command */
273 mdelay(10);
274
275 /* Receive ACK */
276 return 0;
277 }
278 }
279 /* Received NAK or illegal Data */
280 printk(KERN_ERR ">%s: Error : NAK or Illegal Data "
281 "Received\n", __func__);
282 }
283 } while (retry--);
284
285 /* Interval for next command */
286 mdelay(10);
287
288 return -1;
289}
290
291static void kurobox_pro_power_off(void)
292{
293 const unsigned char watchdogkill[] = {0x01, 0x35, 0x00};
294 const unsigned char shutdownwait[] = {0x00, 0x0c};
295 const unsigned char poweroff[] = {0x00, 0x06};
296 /* 38400 baud divisor */
Lennert Buytenhekebe35af2008-08-29 05:55:51 +0200297 const unsigned divisor = ((orion5x_tclk + (8 * 38400)) / (16 * 38400));
Sylver Bruneaua0087f22008-04-30 08:14:58 +0200298
299 pr_info("%s: triggering power-off...\n", __func__);
300
301 /* hijack uart1 and reset into sane state (38400,8n1,even parity) */
302 writel(0x83, UART1_REG(LCR));
303 writel(divisor & 0xff, UART1_REG(DLL));
304 writel((divisor >> 8) & 0xff, UART1_REG(DLM));
305 writel(0x1b, UART1_REG(LCR));
306 writel(0x00, UART1_REG(IER));
307 writel(0x07, UART1_REG(FCR));
308 writel(0x00, UART1_REG(MCR));
309
310 /* Send the commands to shutdown the Kurobox Pro */
311 kurobox_pro_miconsend(watchdogkill, sizeof(watchdogkill)) ;
312 kurobox_pro_miconsend(shutdownwait, sizeof(shutdownwait)) ;
313 kurobox_pro_miconsend(poweroff, sizeof(poweroff));
314}
315
316/*****************************************************************************
Ronen Shitrit1e780452007-10-23 15:14:42 -0400317 * General Setup
318 ****************************************************************************/
Andrew Lunn554cdae2011-05-15 13:32:53 +0200319static unsigned int kurobox_pro_mpp_modes[] __initdata = {
320 MPP0_UNUSED,
321 MPP1_UNUSED,
322 MPP2_GPIO, /* GPIO Micon */
323 MPP3_GPIO, /* GPIO Rtc */
324 MPP4_UNUSED,
325 MPP5_UNUSED,
326 MPP6_NAND, /* NAND Flash REn */
327 MPP7_NAND, /* NAND Flash WEn */
328 MPP8_UNUSED,
329 MPP9_UNUSED,
330 MPP10_UNUSED,
331 MPP11_UNUSED,
332 MPP12_SATA_LED, /* SATA 0 presence */
333 MPP13_SATA_LED, /* SATA 1 presence */
334 MPP14_SATA_LED, /* SATA 0 active */
335 MPP15_SATA_LED, /* SATA 1 active */
336 MPP16_UART, /* UART1 RXD */
337 MPP17_UART, /* UART1 TXD */
338 MPP18_UART, /* UART1 CTSn */
339 MPP19_UART, /* UART1 RTSn */
340 0,
Lennert Buytenhek19cfd5c2008-05-10 23:25:46 +0200341};
Ronen Shitrit1e780452007-10-23 15:14:42 -0400342
Ronen Shitrit1e780452007-10-23 15:14:42 -0400343static void __init kurobox_pro_init(void)
344{
345 /*
346 * Setup basic Orion functions. Need to be called early.
347 */
Lennert Buytenhek9dd0b192008-03-27 14:51:41 -0400348 orion5x_init();
Ronen Shitrit1e780452007-10-23 15:14:42 -0400349
Lennert Buytenhek19cfd5c2008-05-10 23:25:46 +0200350 orion5x_mpp_conf(kurobox_pro_mpp_modes);
Ronen Shitrit1e780452007-10-23 15:14:42 -0400351
Lennert Buytenhek044f6c72008-04-22 05:37:12 +0200352 /*
353 * Configure peripherals.
354 */
355 orion5x_ehci0_init();
356 orion5x_ehci1_init();
Lennert Buytenhek9dd0b192008-03-27 14:51:41 -0400357 orion5x_eth_init(&kurobox_pro_eth_data);
Lennert Buytenhek044f6c72008-04-22 05:37:12 +0200358 orion5x_i2c_init();
Lennert Buytenhek9dd0b192008-03-27 14:51:41 -0400359 orion5x_sata_init(&kurobox_pro_sata_data);
Lennert Buytenhek044f6c72008-04-22 05:37:12 +0200360 orion5x_uart0_init();
Sylver Bruneau9e956852008-06-23 01:20:05 +0200361 orion5x_uart1_init();
Saeed Bishara1d5a1a62008-06-16 23:25:12 -1100362 orion5x_xor_init();
Lennert Buytenhek044f6c72008-04-22 05:37:12 +0200363
364 orion5x_setup_dev_boot_win(KUROBOX_PRO_NOR_BOOT_BASE,
365 KUROBOX_PRO_NOR_BOOT_SIZE);
366 platform_device_register(&kurobox_pro_nor_flash);
367
368 if (machine_is_kurobox_pro()) {
369 orion5x_setup_dev0_win(KUROBOX_PRO_NAND_BASE,
370 KUROBOX_PRO_NAND_SIZE);
371 platform_device_register(&kurobox_pro_nand_flash);
372 }
373
374 i2c_register_board_info(0, &kurobox_pro_i2c_rtc, 1);
Sylver Bruneaua0087f22008-04-30 08:14:58 +0200375
376 /* register Kurobox Pro specific power-off method */
377 pm_power_off = kurobox_pro_power_off;
Ronen Shitrit1e780452007-10-23 15:14:42 -0400378}
379
Byron Bradley87549252008-04-09 21:50:16 +0100380#ifdef CONFIG_MACH_KUROBOX_PRO
Ronen Shitrit1e780452007-10-23 15:14:42 -0400381MACHINE_START(KUROBOX_PRO, "Buffalo/Revogear Kurobox Pro")
382 /* Maintainer: Ronen Shitrit <rshitrit@marvell.com> */
Ronen Shitrit1e780452007-10-23 15:14:42 -0400383 .boot_params = 0x00000100,
384 .init_machine = kurobox_pro_init,
Lennert Buytenhek9dd0b192008-03-27 14:51:41 -0400385 .map_io = orion5x_map_io,
Lennert Buytenhek4ee1f6b2010-10-15 16:50:26 +0200386 .init_early = orion5x_init_early,
Lennert Buytenhek9dd0b192008-03-27 14:51:41 -0400387 .init_irq = orion5x_init_irq,
388 .timer = &orion5x_timer,
Guennadi Liakhovetskibe73a342008-02-29 21:12:57 +0100389 .fixup = tag_fixup_mem32,
Ronen Shitrit1e780452007-10-23 15:14:42 -0400390MACHINE_END
Byron Bradley87549252008-04-09 21:50:16 +0100391#endif
392
393#ifdef CONFIG_MACH_LINKSTATION_PRO
394MACHINE_START(LINKSTATION_PRO, "Buffalo Linkstation Pro/Live")
395 /* Maintainer: Byron Bradley <byron.bbradley@gmail.com> */
Byron Bradley87549252008-04-09 21:50:16 +0100396 .boot_params = 0x00000100,
397 .init_machine = kurobox_pro_init,
398 .map_io = orion5x_map_io,
Lennert Buytenhek4ee1f6b2010-10-15 16:50:26 +0200399 .init_early = orion5x_init_early,
Byron Bradley87549252008-04-09 21:50:16 +0100400 .init_irq = orion5x_init_irq,
401 .timer = &orion5x_timer,
402 .fixup = tag_fixup_mem32,
403MACHINE_END
404#endif