Root/target/linux/adm5120/files/arch/mips/adm5120/mikrotik/rb-150.c

1/*
2 * Mikrotik RouterBOARD 150 support
3 *
4 * Copyright (C) 2007-2008 Gabor Juhos <juhosg@openwrt.org>
5 *
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.
9 *
10 */
11
12#include "rb-1xx.h"
13
14#define RB150_NAND_BASE 0x1FC80000
15#define RB150_NAND_SIZE 1
16
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 */
22
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)
27
28#define RB150_NAND_DELAY 100
29
30#define RB150_NAND_WRITE(v) \
31    writeb((v), (void __iomem *)KSEG1ADDR(RB150_NAND_BASE))
32
33static struct resource rb150_nand_resources[] __initdata = {
34    [0] = {
35        .start = RB150_NAND_BASE,
36        .end = RB150_NAND_BASE + RB150_NAND_SIZE-1,
37        .flags = IORESOURCE_MEM,
38    },
39};
40
41static 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),
53};
54
55static u8 rb150_vlans[6] __initdata = {
56    0x7F, 0x00, 0x00, 0x00, 0x00, 0x00
57};
58
59static int rb150_nand_dev_ready(struct mtd_info *mtd)
60{
61    return gpio_get_value(RB150_GPIO_NAND_READY);
62}
63
64static void rb150_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
65        unsigned int ctrl)
66{
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);
71    }
72
73    udelay(RB150_NAND_DELAY);
74
75    if (cmd != NAND_CMD_NONE)
76        RB150_NAND_WRITE(cmd);
77}
78
79static void __init rb150_add_device_nand(void)
80{
81    struct platform_device *pdev;
82    int err;
83
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);
93
94    pdev = platform_device_alloc("gen_nand", -1);
95    if (!pdev)
96        goto err_out;
97
98    err = platform_device_add_resources(pdev, rb150_nand_resources,
99                    ARRAY_SIZE(rb150_nand_resources));
100    if (err)
101        goto err_put;
102
103
104    rb1xx_nand_data.ctrl.cmd_ctrl = rb150_nand_cmd_ctrl;
105    rb1xx_nand_data.ctrl.dev_ready = rb150_nand_dev_ready;
106
107    err = platform_device_add_data(pdev, &rb1xx_nand_data,
108                    sizeof(rb1xx_nand_data));
109    if (err)
110        goto err_put;
111
112    err = platform_device_add(pdev);
113    if (err)
114        goto err_put;
115
116    return;
117
118err_put:
119    platform_device_put(pdev);
120err_out:
121    return;
122}
123
124static void __init rb150_setup(void)
125{
126    rb1xx_gpio_buttons[0].gpio = RB150_GPIO_RESET_BUTTON;
127    rb1xx_generic_setup();
128    rb150_add_device_nand();
129
130    adm5120_add_device_gpio(RB150_GPIO_DEV_MASK);
131    adm5120_add_device_gpio_leds(ARRAY_SIZE(rb150_gpio_leds),
132                    rb150_gpio_leds);
133    adm5120_add_device_switch(5, rb150_vlans);
134}
135
136MIPS_MACHINE(MACH_ADM5120_RB_150, "miniROUTER", "Mikrotik RouterBOARD 150",
137         rb150_setup);
138

Archive Download this file



interactive