[brcm63xx] add support for 2.6.33
[openwrt.git] / target / linux / brcm63xx / patches-2.6.33 / 170-board_livebox.patch
1 --- a/arch/mips/bcm63xx/boards/Kconfig
2 +++ b/arch/mips/bcm63xx/boards/Kconfig
3 @@ -8,4 +8,10 @@ config BOARD_BCM963XX
4         select SSB
5         help
6  
7 +config BOARD_LIVEBOX
8 +       bool "Inventel Livebox(es) boards"
9 +       select SSB
10 +       help
11 +        Inventel Livebox boards using the RedBoot bootloader.
12 +
13  endchoice
14 --- a/arch/mips/bcm63xx/boards/Makefile
15 +++ b/arch/mips/bcm63xx/boards/Makefile
16 @@ -1,3 +1,4 @@
17  obj-$(CONFIG_BOARD_BCM963XX)           += board_bcm963xx.o
18 +obj-$(CONFIG_BOARD_LIVEBOX)            += board_livebox.o
19  
20  EXTRA_CFLAGS += -Werror
21 --- /dev/null
22 +++ b/arch/mips/bcm63xx/boards/board_livebox.c
23 @@ -0,0 +1,227 @@
24 +/*
25 + * This file is subject to the terms and conditions of the GNU General Public
26 + * License.  See the file "COPYING" in the main directory of this archive
27 + * for more details.
28 + *
29 + * Copyright (C) 2008 Florian Fainelli <florian@openwrt.org>
30 + */
31 +
32 +#include <linux/init.h>
33 +#include <linux/kernel.h>
34 +#include <linux/string.h>
35 +#include <linux/platform_device.h>
36 +#include <linux/mtd/mtd.h>
37 +#include <linux/mtd/partitions.h>
38 +#include <linux/mtd/physmap.h>
39 +#include <asm/addrspace.h>
40 +#include <bcm63xx_board.h>
41 +#include <bcm63xx_cpu.h>
42 +#include <bcm63xx_regs.h>
43 +#include <bcm63xx_io.h>
44 +#include <bcm63xx_board.h>
45 +#include <bcm63xx_dev_pci.h>
46 +#include <bcm63xx_dev_uart.h>
47 +#include <bcm63xx_dev_wdt.h>
48 +#include <bcm63xx_dev_enet.h>
49 +#include <bcm63xx_dev_pcmcia.h>
50 +#include <bcm63xx_dev_usb_ohci.h>
51 +#include <bcm63xx_dev_usb_ehci.h>
52 +#include <board_bcm963xx.h>
53 +
54 +#define PFX    "board_livebox: "
55 +
56 +static unsigned int mac_addr_used = 0;
57 +static struct board_info board;
58 +
59 +/*
60 + * known 6348 boards
61 + */
62 +#ifdef CONFIG_BCM63XX_CPU_6348
63 +static struct board_info __initdata board_livebox = {
64 +       .name                           = "Livebox",
65 +       .expected_cpu_id                = 0x6348,
66 +
67 +       .has_enet0                      = 1,
68 +       .has_enet1                      = 1,
69 +       .has_pci                        = 1,
70 +
71 +       .enet0 = {
72 +               .has_phy                = 1,
73 +               .use_internal_phy       = 1,
74 +       },
75 +
76 +       .enet1 = {
77 +               .force_speed_100        = 1,
78 +               .force_duplex_full      = 1,
79 +       },
80 +
81 +       .has_ohci0                      = 1,
82 +       .has_pccard                     = 1,
83 +       .has_ehci0                      = 1,
84 +};
85 +#endif
86 +
87 +/*
88 + * all boards
89 + */
90 +static const struct board_info __initdata *bcm963xx_boards[] = {
91 +#ifdef CONFIG_BCM63XX_CPU_6348
92 +       &board_livebox
93 +#endif
94 +};
95 +
96 +/*
97 + * early init callback
98 + */
99 +void __init board_prom_init(void)
100 +{
101 +       u32 val;
102 +
103 +       /* read base address of boot chip select (0) */
104 +       val = bcm_mpi_readl(MPI_CSBASE_REG(0));
105 +       val &= MPI_CSBASE_BASE_MASK;
106 +
107 +       /* assume board is a Livebox */
108 +       memcpy(&board, bcm963xx_boards[0], sizeof(board));
109 +
110 +       /* setup pin multiplexing depending on board enabled device,
111 +        * this has to be done this early since PCI init is done
112 +        * inside arch_initcall */
113 +       val = 0;
114 +
115 +       if (board.has_pci) {
116 +               bcm63xx_pci_enabled = 1;
117 +               if (BCMCPU_IS_6348())
118 +                       val |= GPIO_MODE_6348_G2_PCI;
119 +       }
120 +
121 +       if (board.has_pccard) {
122 +               if (BCMCPU_IS_6348())
123 +                       val |= GPIO_MODE_6348_G1_MII_PCCARD;
124 +       }
125 +
126 +       if (board.has_enet0 && !board.enet0.use_internal_phy) {
127 +               if (BCMCPU_IS_6348())
128 +                       val |= GPIO_MODE_6348_G3_EXT_MII |
129 +                               GPIO_MODE_6348_G0_EXT_MII;
130 +       }
131 +
132 +       if (board.has_enet1 && !board.enet1.use_internal_phy) {
133 +               if (BCMCPU_IS_6348())
134 +                       val |= GPIO_MODE_6348_G3_EXT_MII |
135 +                               GPIO_MODE_6348_G0_EXT_MII;
136 +       }
137 +
138 +       bcm_gpio_writel(val, GPIO_MODE_REG);
139 +}
140 +
141 +/*
142 + * second stage init callback, good time to panic if we couldn't
143 + * identify on which board we're running since early printk is working
144 + */
145 +void __init board_setup(void)
146 +{
147 +       if (!board.name[0])
148 +               panic("unable to detect bcm963xx board");
149 +       printk(KERN_INFO PFX "board name: %s\n", board.name);
150 +
151 +       /* make sure we're running on expected cpu */
152 +       if (bcm63xx_get_cpu_id() != board.expected_cpu_id)
153 +               panic("unexpected CPU for bcm963xx board");
154 +}
155 +
156 +/*
157 + * return board name for /proc/cpuinfo
158 + */
159 +const char *board_get_name(void)
160 +{
161 +       return board.name;
162 +}
163 +
164 +/*
165 + * register & return a new board mac address
166 + */
167 +
168 +static int board_get_mac_address(u8 *mac)
169 +{
170 +       u8 default_mac[ETH_ALEN] = {0x00, 0x07, 0x3A, 0x00, 0x00, 0x00};
171 +       u8 *p;
172 +       int count;
173 +
174 +       memcpy(mac, default_mac, ETH_ALEN);
175 +
176 +       p = mac + ETH_ALEN - 1;
177 +       count = mac_addr_used;
178 +
179 +       while (count--) {
180 +               do {
181 +                       (*p)++;
182 +                       if (*p != 0)
183 +                               break;
184 +                       p--;
185 +               } while (p != mac);
186 +       }
187 +
188 +       if (p == mac) {
189 +               printk(KERN_ERR PFX "unable to fetch mac address\n");
190 +               return -ENODEV;
191 +       }
192 +        mac_addr_used++;
193 +
194 +       return 0;
195 +}
196 +
197 +static struct resource mtd_resources[] = {
198 +       {
199 +               .start          = 0,    /* filled at runtime */
200 +               .end            = 0,    /* filled at runtime */
201 +               .flags          = IORESOURCE_MEM,
202 +       }
203 +};
204 +
205 +static struct platform_device mtd_dev = {
206 +       .name                   = "bcm963xx-flash",
207 +       .resource               = mtd_resources,
208 +       .num_resources          = ARRAY_SIZE(mtd_resources),
209 +};
210 +
211 +
212 +/*
213 + * third stage init callback, register all board devices.
214 + */
215 +int __init board_register_devices(void)
216 +{
217 +       u32 val;
218 +
219 +       bcm63xx_uart_register();
220 +       bcm63xx_wdt_register();
221 +
222 +       if (board.has_pccard)
223 +               bcm63xx_pcmcia_register();
224 +
225 +       if (board.has_enet0 &&
226 +           !board_get_mac_address(board.enet0.mac_addr))
227 +               bcm63xx_enet_register(0, &board.enet0);
228 +
229 +       if (board.has_enet1 &&
230 +           !board_get_mac_address(board.enet1.mac_addr))
231 +               bcm63xx_enet_register(1, &board.enet1);
232 +
233 +       if (board.has_ohci0)
234 +               bcm63xx_ohci_register();
235 +
236 +       if (board.has_ehci0)
237 +               bcm63xx_ehci_register();
238 +
239 +
240 +       /* read base address of boot chip select (0) */
241 +       val = bcm_mpi_readl(MPI_CSBASE_REG(0));
242 +       val &= MPI_CSBASE_BASE_MASK;
243 +       mtd_resources[0].start = val;
244 +       mtd_resources[0].end = 0x1FFFFFFF;
245 +       
246 +       platform_device_register(&mtd_dev);
247 +
248 +       return 0;
249 +}
250 +