modernize backfire 10.03 so it can be operational again
[openwrt-10.03/.git] / infineon / infineon.c
1 /*
2  *  Infineon Reference Boards
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 "infineon.h"
13
14 #include <prom/admboot.h>
15
16 #define EASY_CONFIG_OFFSET      0x10000
17 #define EASY_CONFIG_SIZE        0x1000
18
19 #ifdef CONFIG_MTD_PARTITIONS
20 static struct mtd_partition easy_partitions[] = {
21         {
22                 .name   = "admboot",
23                 .offset = 0,
24                 .size   = 64*1024,
25                 .mask_flags = MTD_WRITEABLE,
26         } , {
27                 .name   = "boardcfg",
28                 .offset = MTDPART_OFS_APPEND,
29                 .size   = 64*1024,
30         } , {
31                 .name   = "firmware",
32                 .offset = MTDPART_OFS_APPEND,
33                 .size   = MTDPART_SIZ_FULL,
34         }
35 };
36 #endif /* CONFIG_MTD_PARTITIONS */
37
38 static __init void easy_setup_mac(void)
39 {
40         u8 mac_base[6];
41         int err;
42
43         err = admboot_get_mac_base(EASY_CONFIG_OFFSET,
44                                    EASY_CONFIG_SIZE, mac_base);
45
46         if ((err) || !is_valid_ether_addr(mac_base))
47                 random_ether_addr(mac_base);
48
49         adm5120_setup_eth_macs(mac_base);
50 }
51
52 static void switch_bank_gpio3(unsigned bank)
53 {
54         switch (bank) {
55         case 0:
56                 gpio_set_value(ADM5120_GPIO_PIN3, 0);
57                 break;
58         case 1:
59                 gpio_set_value(ADM5120_GPIO_PIN3, 1);
60                 break;
61         }
62 }
63
64 void __init easy_setup_pqfp(void)
65 {
66         /* setup flash A20 line */
67         gpio_request(ADM5120_GPIO_PIN3, NULL);
68         gpio_direction_output(ADM5120_GPIO_PIN3, 0);
69         adm5120_flash0_data.switch_bank = switch_bank_gpio3;
70
71 #ifdef CONFIG_MTD_PARTITIONS
72         adm5120_flash0_data.nr_parts = ARRAY_SIZE(easy_partitions);
73         adm5120_flash0_data.parts = easy_partitions;
74 #endif /* CONFIG_MTD_PARTITIONS */
75
76         adm5120_add_device_flash(0);
77
78         easy_setup_mac();
79 }
80
81 static void switch_bank_gpio5(unsigned bank)
82 {
83         switch (bank) {
84         case 0:
85                 gpio_set_value(ADM5120_GPIO_PIN5, 0);
86                 break;
87         case 1:
88                 gpio_set_value(ADM5120_GPIO_PIN5, 1);
89                 break;
90         }
91 }
92
93 void __init easy_setup_bga(void)
94 {
95         /* setup flash A20 line */
96         gpio_request(ADM5120_GPIO_PIN5, NULL);
97         gpio_direction_output(ADM5120_GPIO_PIN5, 0);
98         adm5120_flash0_data.switch_bank = switch_bank_gpio5;
99
100 #ifdef CONFIG_MTD_PARTITIONS
101         adm5120_flash0_data.nr_parts = ARRAY_SIZE(easy_partitions);
102         adm5120_flash0_data.parts = easy_partitions;
103 #endif /* CONFIG_MTD_PARTITIONS */
104
105         adm5120_add_device_flash(0);
106
107         easy_setup_mac();
108 }