Root/target/linux/ifxmips/files-2.6.33/arch/mips/ifxmips/danube/board.c

1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
15 *
16 * Copyright (C) 2007 John Crispin <blogic@openwrt.org>
17 */
18
19#include <linux/autoconf.h>
20#include <linux/init.h>
21#include <linux/module.h>
22#include <linux/types.h>
23#include <linux/string.h>
24#include <linux/mtd/physmap.h>
25#include <linux/kernel.h>
26#include <linux/reboot.h>
27#include <linux/platform_device.h>
28#include <linux/leds.h>
29#include <linux/etherdevice.h>
30#include <linux/reboot.h>
31#include <linux/time.h>
32#include <linux/io.h>
33#include <linux/gpio.h>
34
35#include <asm/bootinfo.h>
36#include <asm/irq.h>
37
38#include <ifxmips.h>
39#include <ifxmips_irq.h>
40
41#define MAX_BOARD_NAME_LEN 32
42#define MAX_IFXMIPS_DEVS 9
43
44#define SYSTEM_DANUBE "Danube"
45#define SYSTEM_DANUBE_CHIPID1 0x00129083
46#define SYSTEM_DANUBE_CHIPID2 0x0012B083
47
48#define SYSTEM_TWINPASS "Twinpass"
49#define SYSTEM_TWINPASS_CHIPID 0x0012D083
50
51enum {
52    EASY50712,
53    EASY4010,
54    ARV4519,
55    ARV452,
56};
57
58extern int ifxmips_pci_external_clock;
59extern int ifxmips_pci_req_mask;
60
61static unsigned int chiprev;
62static int cmdline_mac;
63char board_name[MAX_BOARD_NAME_LEN + 1] = { 0 };
64
65struct ifxmips_board {
66    int type;
67    char name[32];
68    unsigned int system_type;
69    struct platform_device **devs;
70    struct resource reset_resource;
71    struct resource gpiodev_resource;
72    struct gpio_led *ifxmips_leds;
73    struct gpio_led *gpio_leds;
74    int pci_external_clock;
75    int pci_req_mask;
76    int num_devs;
77};
78
79DEFINE_SPINLOCK(ebu_lock);
80EXPORT_SYMBOL_GPL(ebu_lock);
81
82extern unsigned char ifxmips_ethaddr[6];
83static int ifxmips_brn;
84
85static struct gpio_led_platform_data ifxmips_led_data;
86
87static struct platform_device ifxmips_led = {
88    .id = 0,
89    .name = "ifxmips_led",
90    .dev = {
91        .platform_data = (void *) &ifxmips_led_data,
92    }
93};
94
95static struct platform_device ifxmips_gpio = {
96    .id = 0,
97    .name = "ifxmips_gpio",
98    .num_resources = 1,
99};
100
101static struct platform_device ifxmips_mii = {
102    .id = 0,
103    .name = "ifxmips_mii0",
104    .dev = {
105        .platform_data = ifxmips_ethaddr,
106    }
107};
108
109static struct platform_device ifxmips_wdt = {
110    .id = 0,
111    .name = "ifxmips_wdt",
112};
113
114static struct platform_device ifxmips_ebu = {
115    .id = 0,
116    .name = "ifxmips_ebu",
117};
118
119static struct resource ifxmips_mtd_resource = {
120    .start = IFXMIPS_FLASH_START,
121    .end = IFXMIPS_FLASH_START + IFXMIPS_FLASH_MAX - 1,
122    .flags = IORESOURCE_MEM,
123};
124
125static struct platform_device ifxmips_mtd = {
126    .id = 0,
127    .name = "ifxmips_mtd",
128    .num_resources = 1,
129    .resource = &ifxmips_mtd_resource,
130};
131
132static struct platform_device ifxmips_gpio_dev = {
133    .name = "GPIODEV",
134    .id = -1,
135    .num_resources = 1,
136};
137
138#ifdef CONFIG_LEDS_GPIO
139static struct gpio_led arv4519_gpio_leds[] = {
140    { .name = "ifx:green:power", .gpio = 3, .active_low = 1, },
141    { .name = "ifx:red:power", .gpio = 7, .active_low = 1, },
142    { .name = "ifx:green:adsl", .gpio = 4, .active_low = 1, },
143    { .name = "ifx:green:internet", .gpio = 5, .active_low = 1, },
144    { .name = "ifx:red:internet", .gpio = 8, .active_low = 1, },
145    { .name = "ifx:green:wlan", .gpio = 6, .active_low = 1, },
146    { .name = "ifx:green:usbpwr", .gpio = 14, .active_low = 1, },
147    { .name = "ifx:green:usb", .gpio = 19, .active_low = 1, },
148};
149
150static struct gpio_led arv452_gpio_leds[] = {
151    { .name = "ifx:blue:power", .gpio = 3, .active_low = 1, },
152    { .name = "ifx:blue:adsl", .gpio = 4, .active_low = 1, },
153    { .name = "ifx:blue:internet", .gpio = 5, .active_low = 1, },
154    { .name = "ifx:red:power", .gpio = 6, .active_low = 1, },
155    { .name = "ifx:yello:wps", .gpio = 7, .active_low = 1, },
156    { .name = "ifx:red:wps", .gpio = 9, .active_low = 1, },
157    { .name = "ifx:blue:voip", .gpio = 32, .active_low = 1, },
158    { .name = "ifx:blue:fxs1", .gpio = 33, .active_low = 1, },
159    { .name = "ifx:blue:fxs2", .gpio = 34, .active_low = 1, },
160    { .name = "ifx:blue:fxo", .gpio = 35, .active_low = 1, },
161    { .name = "ifx:blue:voice", .gpio = 36, .active_low = 1, },
162    { .name = "ifx:blue:usb", .gpio = 37, .active_low = 1, },
163    { .name = "ifx:blue:wlan", .gpio = 38, .active_low = 1, },
164    { .name = "ifx:red:internet", .gpio = 41, .active_low = 1, },
165};
166
167static struct gpio_led_platform_data ifxmips_gpio_led_data;
168
169static struct platform_device ifxmips_gpio_leds = {
170    .name = "leds-gpio",
171    .id = -1,
172    .dev = {
173        .platform_data = (void *) &ifxmips_gpio_led_data,
174    }
175};
176#endif
177
178static struct resource dwc_usb_res[] = {
179    {
180        .name = "dwc3884_membase",
181        .flags = IORESOURCE_MEM,
182        .start = 0x1E101000,
183        .end = 0x1E101FFF
184    },
185    {
186        .name = "dwc3884_irq",
187        .flags = IORESOURCE_IRQ,
188        .start = IFXMIPS_USB_INT,
189    }
190};
191
192static struct platform_device dwc_usb =
193{
194    .id = 0,
195    .name = "dwc3884-hcd",
196    .resource = dwc_usb_res,
197    .num_resources = ARRAY_SIZE(dwc_usb_res),
198};
199
200struct platform_device *easy50712_devs[] = {
201    &ifxmips_led, &ifxmips_gpio, &ifxmips_mii,
202    &ifxmips_mtd, &ifxmips_wdt, &ifxmips_gpio_dev, &dwc_usb
203};
204
205struct platform_device *easy4010_devs[] = {
206    &ifxmips_led, &ifxmips_gpio, &ifxmips_mii,
207    &ifxmips_mtd, &ifxmips_wdt, &ifxmips_gpio_dev, &dwc_usb
208};
209
210struct platform_device *arv5419_devs[] = {
211    &ifxmips_gpio, &ifxmips_mii, &ifxmips_mtd,
212    &ifxmips_gpio_dev, &ifxmips_wdt, &dwc_usb,
213#ifdef CONFIG_LEDS_GPIO
214    &ifxmips_gpio_leds,
215#endif
216};
217
218struct platform_device *arv452_devs[] = {
219    &ifxmips_gpio, &ifxmips_mii, &ifxmips_mtd,
220    &ifxmips_gpio_dev, &ifxmips_wdt, &dwc_usb,
221    &ifxmips_ebu,
222#ifdef CONFIG_LEDS_GPIO
223    &ifxmips_gpio_leds,
224#endif
225};
226
227static struct gpio_led easy50712_leds[] = {
228    { .name = "ifx:green:test0", .gpio = 0,},
229    { .name = "ifx:green:test1", .gpio = 1,},
230    { .name = "ifx:green:test2", .gpio = 2,},
231    { .name = "ifx:green:test3", .gpio = 3,},
232};
233
234static struct gpio_led easy4010_leds[] = {
235    { .name = "ifx:green:test0", .gpio = 0,},
236    { .name = "ifx:green:test1", .gpio = 1,},
237    { .name = "ifx:green:test2", .gpio = 2,},
238    { .name = "ifx:green:test3", .gpio = 3,},
239};
240
241static struct ifxmips_board boards[] = {
242    {
243        /* infineon eval kit */
244        .type = EASY50712,
245        .name = "EASY50712",
246        .system_type = SYSTEM_DANUBE_CHIPID1,
247        .devs = easy50712_devs,
248        .reset_resource = {.name = "reset", .start = 1, .end = 15,},
249        .gpiodev_resource = { .name = "gpio",
250            .start = (1 << 0) | (1 << 1),
251            .end = (1 << 0) | (1 << 1)},
252        .ifxmips_leds = easy50712_leds,
253    }, {
254        /* infineon eval kit */
255        .type = EASY4010,
256        .name = "EASY4010",
257        .system_type = SYSTEM_TWINPASS_CHIPID,
258        .devs = easy4010_devs,
259        .reset_resource = {.name = "reset", .start = 1, .end = 15},
260        .gpiodev_resource = { .name = "gpio",
261            .start = (1 << 0) | (1 << 1),
262            .end = (1 << 0) | (1 << 1)},
263        .ifxmips_leds = easy4010_leds,
264    }, {
265        /* arcaydian annex-a board used by thompson, airties, ... */
266        .type = ARV4519,
267        .name = "ARV4519",
268        .system_type = SYSTEM_DANUBE_CHIPID2,
269        .devs = arv5419_devs,
270        .reset_resource = {.name = "reset", .start = 1, .end = 14},
271        .pci_external_clock = 1,
272#ifdef CONFIG_LEDS_GPIO
273        .gpio_leds = arv4519_gpio_leds,
274#endif
275    }, {
276        /* arcaydian annex-b board used by airties, arcor */
277        .type = ARV452,
278        .name = "ARV452",
279        .system_type = SYSTEM_DANUBE_CHIPID2,
280        .devs = arv452_devs,
281        .reset_resource = {.name = "reset", .start = 1, .end = 14},
282        .pci_external_clock = 1,
283#ifdef CONFIG_LEDS_GPIO
284        .gpio_leds = arv452_gpio_leds,
285#endif
286    },
287};
288
289const char *get_system_type(void)
290{
291    chiprev = (ifxmips_r32(IFXMIPS_MPS_CHIPID) & 0x0FFFFFFF);
292
293    switch (chiprev) {
294    case SYSTEM_DANUBE_CHIPID1:
295    case SYSTEM_DANUBE_CHIPID2:
296        return SYSTEM_DANUBE;
297
298    case SYSTEM_TWINPASS_CHIPID:
299        return SYSTEM_TWINPASS;
300    }
301
302    return BOARD_SYSTEM_TYPE;
303}
304
305static int __init ifxmips_set_board_type(char *str)
306{
307    str = strchr(str, '=');
308    if (!str)
309        goto out;
310    str++;
311    if (strlen(str) > MAX_BOARD_NAME_LEN)
312        goto out;
313    strncpy(board_name, str, MAX_BOARD_NAME_LEN);
314    printk(KERN_INFO "bootloader told us, that this is a %s board\n",
315        board_name);
316out:
317    return 1;
318}
319__setup("ifxmips_board", ifxmips_set_board_type);
320
321static int __init ifxmips_set_ethaddr(char *str)
322{
323#define IS_HEX(x) \
324    (((x >= '0' && x <= '9') || (x >= 'a' && x <= 'f') \
325        || (x >= 'A' && x <= 'F')) ? (1) : (0))
326    int i;
327    str = strchr(str, '=');
328    if (!str)
329        goto out;
330    str++;
331    if (strlen(str) != 17)
332        goto out;
333    for (i = 0; i < 6; i++) {
334        if (!IS_HEX(str[3 * i]) || !IS_HEX(str[(3 * i) + 1]))
335            goto out;
336        if ((i != 5) && (str[(3 * i) + 2] != ':'))
337            goto out;
338        ifxmips_ethaddr[i] = simple_strtoul(&str[3 * i], NULL, 16);
339    }
340    if (is_valid_ether_addr(ifxmips_ethaddr))
341        cmdline_mac = 1;
342out:
343    return 1;
344}
345__setup("ethaddr", ifxmips_set_ethaddr);
346
347int ifxmips_find_brn_block(void)
348{
349    unsigned char temp[8];
350    memcpy_fromio(temp,
351        (void *)KSEG1ADDR(IFXMIPS_FLASH_START + 0x800000 - 0x10000), 8);
352    if (memcmp(temp, "BRN-BOOT", 8) == 0) {
353        if (!cmdline_mac)
354            memcpy_fromio(ifxmips_ethaddr,
355                (void *)KSEG1ADDR(IFXMIPS_FLASH_START +
356                    0x800000 - 0x10000 + 0x16), 6);
357        if (is_valid_ether_addr(ifxmips_ethaddr))
358            cmdline_mac = 1;
359        return 1;
360    } else {
361        return 0;
362    }
363}
364
365int ifxmips_has_brn_block(void)
366{
367    return ifxmips_brn;
368}
369EXPORT_SYMBOL(ifxmips_has_brn_block);
370
371struct ifxmips_board *ifxmips_find_board(void)
372{
373    int i;
374    if (!*board_name)
375        return 0;
376    for (i = 0; i < ARRAY_SIZE(boards); i++)
377        if ((boards[i].system_type == chiprev) &&
378            (!strcmp(boards[i].name, board_name)))
379            return &boards[i];
380    return 0;
381}
382
383int __init ifxmips_init_devices(void)
384{
385    struct ifxmips_board *board;
386
387    chiprev = (ifxmips_r32(IFXMIPS_MPS_CHIPID) & 0x0FFFFFFF);
388    board = ifxmips_find_board();
389    ifxmips_brn = ifxmips_find_brn_block();
390
391    if (!cmdline_mac)
392        random_ether_addr(ifxmips_ethaddr);
393
394    if (!board) {
395        switch (chiprev) {
396        case SYSTEM_DANUBE_CHIPID1:
397        case SYSTEM_DANUBE_CHIPID2:
398        default:
399            board = &boards[0];
400            break;
401        case SYSTEM_TWINPASS_CHIPID:
402            board = &boards[1];
403            break;
404        }
405    }
406
407    switch (board->type) {
408    case EASY50712:
409        board->num_devs = ARRAY_SIZE(easy50712_devs);
410        ifxmips_led_data.num_leds = ARRAY_SIZE(easy50712_leds);
411        break;
412    case EASY4010:
413        board->num_devs = ARRAY_SIZE(easy4010_devs);
414        ifxmips_led_data.num_leds = ARRAY_SIZE(easy4010_leds);
415        break;
416    case ARV4519:
417        /* set some sane defaults for the gpios */
418        gpio_set_value(3, 0);
419        gpio_set_value(4, 0);
420        gpio_set_value(5, 0);
421        gpio_set_value(6, 0);
422        gpio_set_value(7, 1);
423        gpio_set_value(8, 1);
424        gpio_set_value(19, 0);
425        board->num_devs = ARRAY_SIZE(arv5419_devs);
426#ifdef CONFIG_LEDS_GPIO
427        ifxmips_gpio_led_data.num_leds = ARRAY_SIZE(arv4519_gpio_leds);
428#endif
429        break;
430    case ARV452:
431        /* set some sane defaults for the gpios */
432        board->num_devs = ARRAY_SIZE(arv452_devs);
433        ifxmips_w32(0x8001e7ff, IFXMIPS_EBU_BUSCON1);
434#ifdef CONFIG_LEDS_GPIO
435        ifxmips_gpio_led_data.num_leds = ARRAY_SIZE(arv452_gpio_leds);
436#endif
437        break;
438    }
439#ifdef CONFIG_LEDS_GPIO
440    ifxmips_gpio_led_data.leds = board->gpio_leds;
441#endif
442    ifxmips_led_data.leds = board->ifxmips_leds;
443
444    printk(KERN_INFO "%s: adding %d devs\n",
445        __func__, board->num_devs);
446
447    ifxmips_gpio.resource = &board->reset_resource;
448    ifxmips_gpio_dev.resource = &board->gpiodev_resource;
449    if (board->pci_external_clock)
450        ifxmips_pci_external_clock = 1;
451    if (board->pci_req_mask)
452        ifxmips_pci_req_mask = board->pci_req_mask;
453    printk(KERN_INFO "using board definition %s\n", board->name);
454    return platform_add_devices(board->devs, board->num_devs);
455}
456
457arch_initcall(ifxmips_init_devices);
458

Archive Download this file



interactive