2 * Mikrotik RouterBOARD 150 support
4 * Copyright (C) 2007-2008 Gabor Juhos <juhosg@openwrt.org>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
14 #define RB150_NAND_BASE 0x1FC80000
15 #define RB150_NAND_SIZE 1
17 #define RB150_GPIO_NAND_READY ADM5120_GPIO_PIN0
18 #define RB150_GPIO_NAND_NCE ADM5120_GPIO_PIN1
19 #define RB150_GPIO_NAND_CLE ADM5120_GPIO_P2L2
20 #define RB150_GPIO_NAND_ALE ADM5120_GPIO_P3L2
21 #define RB150_GPIO_RESET_BUTTON ADM5120_GPIO_PIN1 /* FIXME */
23 #define RB150_GPIO_DEV_MASK ( 1 << RB150_GPIO_NAND_READY \
24 | 1 << RB150_GPIO_NAND_NCE \
25 | 1 << RB150_GPIO_NAND_CLE \
26 | 1 << RB150_GPIO_NAND_ALE)
28 #define RB150_NAND_DELAY 100
30 #define RB150_NAND_WRITE(v) \
31 writeb((v), (void __iomem *)KSEG1ADDR(RB150_NAND_BASE))
33 static struct resource rb150_nand_resources[] __initdata = {
35 .start = RB150_NAND_BASE,
36 .end = RB150_NAND_BASE + RB150_NAND_SIZE-1,
37 .flags = IORESOURCE_MEM,
41 static struct gpio_led rb150_gpio_leds[] __initdata = {
42 GPIO_LED_STD(ADM5120_GPIO_P0L2, "user", NULL),
43 GPIO_LED_INV(ADM5120_GPIO_P0L1, "lan1_led1", NULL),
44 GPIO_LED_INV(ADM5120_GPIO_P0L0, "lan1_led2", NULL),
45 GPIO_LED_INV(ADM5120_GPIO_P1L1, "lan5_led1", NULL),
46 GPIO_LED_INV(ADM5120_GPIO_P1L0, "lan5_led2", NULL),
47 GPIO_LED_INV(ADM5120_GPIO_P2L1, "lan4_led1", NULL),
48 GPIO_LED_INV(ADM5120_GPIO_P2L0, "lan4_led2", NULL),
49 GPIO_LED_INV(ADM5120_GPIO_P3L1, "lan3_led1", NULL),
50 GPIO_LED_INV(ADM5120_GPIO_P3L0, "lan3_led2", NULL),
51 GPIO_LED_INV(ADM5120_GPIO_P4L1, "lan2_led1", NULL),
52 GPIO_LED_INV(ADM5120_GPIO_P4L0, "lan2_led2", NULL),
55 static u8 rb150_vlans[6] __initdata = {
56 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00
59 static int rb150_nand_dev_ready(struct mtd_info *mtd)
61 return gpio_get_value(RB150_GPIO_NAND_READY);
64 static void rb150_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
67 if (ctrl & NAND_CTRL_CHANGE) {
68 gpio_set_value(RB150_GPIO_NAND_CLE, (ctrl & NAND_CLE) ? 1 : 0);
69 gpio_set_value(RB150_GPIO_NAND_ALE, (ctrl & NAND_ALE) ? 1 : 0);
70 gpio_set_value(RB150_GPIO_NAND_NCE, (ctrl & NAND_NCE) ? 0 : 1);
73 udelay(RB150_NAND_DELAY);
75 if (cmd != NAND_CMD_NONE)
76 RB150_NAND_WRITE(cmd);
79 static void __init rb150_add_device_nand(void)
81 struct platform_device *pdev;
84 /* setup GPIO pins for NAND flash chip */
85 gpio_request(RB150_GPIO_NAND_READY, "nand-ready");
86 gpio_direction_input(RB150_GPIO_NAND_READY);
87 gpio_request(RB150_GPIO_NAND_NCE, "nand-nce");
88 gpio_direction_output(RB150_GPIO_NAND_NCE, 1);
89 gpio_request(RB150_GPIO_NAND_CLE, "nand-cle");
90 gpio_direction_output(RB150_GPIO_NAND_CLE, 0);
91 gpio_request(RB150_GPIO_NAND_ALE, "nand-ale");
92 gpio_direction_output(RB150_GPIO_NAND_ALE, 0);
94 pdev = platform_device_alloc("gen_nand", -1);
98 err = platform_device_add_resources(pdev, rb150_nand_resources,
99 ARRAY_SIZE(rb150_nand_resources));
104 rb1xx_nand_data.ctrl.cmd_ctrl = rb150_nand_cmd_ctrl;
105 rb1xx_nand_data.ctrl.dev_ready = rb150_nand_dev_ready;
107 err = platform_device_add_data(pdev, &rb1xx_nand_data,
108 sizeof(rb1xx_nand_data));
112 err = platform_device_add(pdev);
119 platform_device_put(pdev);
124 static void __init rb150_setup(void)
126 rb1xx_gpio_buttons[0].gpio = RB150_GPIO_RESET_BUTTON;
127 rb1xx_generic_setup();
128 rb150_add_device_nand();
130 adm5120_add_device_gpio(RB150_GPIO_DEV_MASK);
131 adm5120_add_device_gpio_leds(ARRAY_SIZE(rb150_gpio_leds),
133 adm5120_add_device_switch(5, rb150_vlans);
136 MIPS_MACHINE(MACH_ADM5120_RB_150, "Mikrotik RouterBOARD 150", rb150_setup);