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_NAND_DELAY 100
24
25#define RB150_NAND_WRITE(v) \
26    writeb((v), (void __iomem *)KSEG1ADDR(RB150_NAND_BASE))
27
28static struct resource rb150_nand_resources[] __initdata = {
29    [0] = {
30        .start = RB150_NAND_BASE,
31        .end = RB150_NAND_BASE + RB150_NAND_SIZE-1,
32        .flags = IORESOURCE_MEM,
33    },
34};
35
36static struct gpio_led rb150_gpio_leds[] __initdata = {
37    GPIO_LED_STD(ADM5120_GPIO_P0L2, "user", NULL),
38    GPIO_LED_INV(ADM5120_GPIO_P0L1, "lan1_led1", NULL),
39    GPIO_LED_INV(ADM5120_GPIO_P0L0, "lan1_led2", NULL),
40    GPIO_LED_INV(ADM5120_GPIO_P1L1, "lan5_led1", NULL),
41    GPIO_LED_INV(ADM5120_GPIO_P1L0, "lan5_led2", NULL),
42    GPIO_LED_INV(ADM5120_GPIO_P2L1, "lan4_led1", NULL),
43    GPIO_LED_INV(ADM5120_GPIO_P2L0, "lan4_led2", NULL),
44    GPIO_LED_INV(ADM5120_GPIO_P3L1, "lan3_led1", NULL),
45    GPIO_LED_INV(ADM5120_GPIO_P3L0, "lan3_led2", NULL),
46    GPIO_LED_INV(ADM5120_GPIO_P4L1, "lan2_led1", NULL),
47    GPIO_LED_INV(ADM5120_GPIO_P4L0, "lan2_led2", NULL),
48};
49
50static u8 rb150_vlans[6] __initdata = {
51    0x7F, 0x00, 0x00, 0x00, 0x00, 0x00
52};
53
54static int rb150_nand_dev_ready(struct mtd_info *mtd)
55{
56    return gpio_get_value(RB150_GPIO_NAND_READY);
57}
58
59static void rb150_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
60        unsigned int ctrl)
61{
62    if (ctrl & NAND_CTRL_CHANGE) {
63        gpio_set_value(RB150_GPIO_NAND_CLE, (ctrl & NAND_CLE) ? 1 : 0);
64        gpio_set_value(RB150_GPIO_NAND_ALE, (ctrl & NAND_ALE) ? 1 : 0);
65        gpio_set_value(RB150_GPIO_NAND_NCE, (ctrl & NAND_NCE) ? 0 : 1);
66    }
67
68    udelay(RB150_NAND_DELAY);
69
70    if (cmd != NAND_CMD_NONE)
71        RB150_NAND_WRITE(cmd);
72}
73
74static void __init rb150_add_device_nand(void)
75{
76    struct platform_device *pdev;
77    int err;
78
79    /* setup GPIO pins for NAND flash chip */
80    gpio_request(RB150_GPIO_NAND_READY, "nand-ready");
81    gpio_direction_input(RB150_GPIO_NAND_READY);
82    gpio_request(RB150_GPIO_NAND_NCE, "nand-nce");
83    gpio_direction_output(RB150_GPIO_NAND_NCE, 1);
84    gpio_request(RB150_GPIO_NAND_CLE, "nand-cle");
85    gpio_direction_output(RB150_GPIO_NAND_CLE, 0);
86    gpio_request(RB150_GPIO_NAND_ALE, "nand-ale");
87    gpio_direction_output(RB150_GPIO_NAND_ALE, 0);
88
89    pdev = platform_device_alloc("gen_nand", -1);
90    if (!pdev)
91        goto err_out;
92
93    err = platform_device_add_resources(pdev, rb150_nand_resources,
94                    ARRAY_SIZE(rb150_nand_resources));
95    if (err)
96        goto err_put;
97
98
99    rb1xx_nand_data.ctrl.cmd_ctrl = rb150_nand_cmd_ctrl;
100    rb1xx_nand_data.ctrl.dev_ready = rb150_nand_dev_ready;
101
102    err = platform_device_add_data(pdev, &rb1xx_nand_data,
103                    sizeof(rb1xx_nand_data));
104    if (err)
105        goto err_put;
106
107    err = platform_device_add(pdev);
108    if (err)
109        goto err_put;
110
111    return;
112
113err_put:
114    platform_device_put(pdev);
115err_out:
116    return;
117}
118
119static void __init rb150_setup(void)
120{
121    rb1xx_gpio_buttons[0].gpio = RB150_GPIO_RESET_BUTTON;
122    rb1xx_generic_setup();
123    rb150_add_device_nand();
124
125    adm5120_add_device_gpio_leds(ARRAY_SIZE(rb150_gpio_leds),
126                    rb150_gpio_leds);
127    adm5120_add_device_switch(5, rb150_vlans);
128}
129
130MIPS_MACHINE(MACH_ADM5120_RB_150, "miniROUTER", "Mikrotik RouterBOARD 150",
131         rb150_setup);
132

Archive Download this file



interactive