[brcm63xx] refresh patches
[openwrt.git] / target / linux / brcm63xx / patches-3.3 / 513-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  ccflags-y := -Werror
21 --- /dev/null
22 +++ b/arch/mips/bcm63xx/boards/board_livebox.c
23 @@ -0,0 +1,366 @@
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 <linux/ssb/ssb.h>
40 +#include <linux/gpio_keys.h>
41 +#include <linux/input.h>
42 +#include <linux/spi/spi.h>
43 +#include <asm/addrspace.h>
44 +#include <bcm63xx_board.h>
45 +#include <bcm63xx_cpu.h>
46 +#include <bcm63xx_dev_uart.h>
47 +#include <bcm63xx_regs.h>
48 +#include <bcm63xx_io.h>
49 +#include <bcm63xx_dev_pci.h>
50 +#include <bcm63xx_dev_enet.h>
51 +#include <bcm63xx_dev_dsp.h>
52 +#include <bcm63xx_dev_pcmcia.h>
53 +#include <bcm63xx_dev_usb_ohci.h>
54 +#include <bcm63xx_dev_usb_ehci.h>
55 +#include <bcm63xx_dev_spi.h>
56 +#include <board_bcm963xx.h>
57 +
58 +#define PFX    "board_livebox: "
59 +
60 +#define LIVEBOX_KEYS_POLL_INTERVAL     20
61 +#define LIVEBOX_KEYS_DEBOUNCE_INTERVAL (LIVEBOX_KEYS_POLL_INTERVAL * 3)
62 +
63 +static unsigned int mac_addr_used = 0;
64 +static struct board_info board;
65 +
66 +/*
67 + * known 6348 boards
68 + */
69 +#ifdef CONFIG_BCM63XX_CPU_6348
70 +static struct board_info __initdata board_livebox_blue5g = {
71 +       .name                           = "Livebox-blue-5g",
72 +       .expected_cpu_id                = 0x6348,
73 +
74 +       .has_uart0                      = 1,
75 +       .has_enet0                      = 1,
76 +       .has_enet1                      = 1,
77 +       .has_pci                        = 1,
78 +
79 +       .enet0 = {
80 +               .has_phy                = 1,
81 +               .use_internal_phy       = 1,
82 +       },
83 +
84 +       .enet1 = {
85 +                 .has_phy              = 1,
86 +                 .phy_id               = 31,
87 +       },
88 +
89 +       .has_ohci0                      = 1,
90 +       .has_pccard                     = 1,
91 +
92 +       .has_dsp                        = 0, /*TODO some Liveboxes have dsp*/
93 +       .dsp = {
94 +               .gpio_rst               = 6, /*FIXME eth1 shares gpio6 with dsp?*/
95 +               .gpio_int               = 35,
96 +               .cs                     = 2,
97 +               .ext_irq                = 2,
98 +       },
99 +
100 +       .leds = {
101 +               {
102 +                       .name           = "Livebox-blue-5g::adsl-fail",
103 +                       .gpio           = 0,
104 +                       .active_low     = 0,
105 +                       .default_trigger = "default-on",
106 +               },
107 +               {
108 +                       .name           = "Livebox-blue-5g::adsl",
109 +                       .gpio           = 1,
110 +               },
111 +               {
112 +                       .name           = "Livebox-blue-5g::traffic",
113 +                       .gpio           = 2,
114 +               },
115 +               {
116 +                       .name           = "Livebox-blue-5g::phone",
117 +                       .gpio           = 3,
118 +               },
119 +               {
120 +                       .name           = "Livebox-blue-5g::wifi",
121 +                       .gpio           = 4,
122 +               },
123 +       },
124 +
125 +       .buttons = {
126 +               {
127 +                       .desc           = "BTN_1",
128 +                       .gpio           = 36,
129 +                       .active_low     = 1,
130 +                       .type           = EV_KEY,
131 +                       .code           = BTN_1,
132 +                       .debounce_interval = LIVEBOX_KEYS_DEBOUNCE_INTERVAL,
133 +               },
134 +               {
135 +                       .desc           = "BTN_2",
136 +                       .gpio           = 7,
137 +                       .active_low     = 1,
138 +                       .type           = EV_KEY,
139 +                       .code           = BTN_2,
140 +                       .debounce_interval = LIVEBOX_KEYS_DEBOUNCE_INTERVAL,
141 +               },
142 +
143 +       },
144 +};
145 +#endif
146 +
147 +/*
148 + * all boards
149 + */
150 +static const struct board_info __initdata *bcm963xx_boards[] = {
151 +#ifdef CONFIG_BCM63XX_CPU_6348
152 +       &board_livebox_blue5g
153 +#endif
154 +};
155 +/*
156 + * return board name for /proc/cpuinfo
157 + */
158 +const char *board_get_name(void)
159 +{
160 +       return board.name;
161 +}
162 +
163 +/*
164 + * register & return a new board mac address
165 + */
166 +static int board_get_mac_address(u8 *mac)
167 +{
168 +       u8 *p;
169 +       int count;
170 +
171 +       memcpy(mac, (u8 *)0xBEBFF377, ETH_ALEN);
172 +
173 +       p = mac + ETH_ALEN - 1;
174 +       count = mac_addr_used;
175 +
176 +       while (count--) {
177 +               do {
178 +                       (*p)++;
179 +                       if (*p != 0)
180 +                               break;
181 +                       p--;
182 +               } while (p != mac);
183 +       }
184 +
185 +       if (p == mac) {
186 +               printk(KERN_ERR PFX "unable to fetch mac address\n");
187 +               return -ENODEV;
188 +       }
189 +        mac_addr_used++;
190 +
191 +       return 0;
192 +}
193 +
194 +/*
195 + * early init callback
196 + */
197 +#define LIVEBOX_GPIO_DETECT_MASK       0x000000ff
198 +#define LIVEBOX_BOOT_ADDR              0x1e400000
199 +
200 +#define LIVEBOX_HW_BLUE5G_9            0x90
201 +
202 +void __init board_prom_init(void)
203 +{
204 +       u32 val;
205 +       u8 hw_version;
206 +
207 +       /* Get hardware version */
208 +       val = bcm_gpio_readl(GPIO_CTL_LO_REG);
209 +       val &= ~LIVEBOX_GPIO_DETECT_MASK;
210 +       bcm_gpio_writel(val, GPIO_CTL_LO_REG);
211 +
212 +       hw_version = bcm_gpio_readl(GPIO_DATA_LO_REG) & LIVEBOX_GPIO_DETECT_MASK;
213 +       switch (hw_version) {
214 +       case LIVEBOX_HW_BLUE5G_9:
215 +               printk(KERN_INFO PFX "Livebox BLUE5G.9\n");
216 +               memcpy(&board, bcm963xx_boards[0], sizeof(board));
217 +               break;
218 +       default:
219 +               printk(KERN_INFO PFX "Unknown livebox version: %02x\n", hw_version);
220 +               break;
221 +       }
222 +
223 +       /* use default livebox configuration */
224 +       memcpy(&board, bcm963xx_boards[0], sizeof(board));
225 +
226 +       /* setup pin multiplexing depending on board enabled device,
227 +        * this has to be done this early since PCI init is done
228 +        * inside arch_initcall */
229 +       val = 0;
230 +
231 +#ifdef CONFIG_PCI
232 +       if (board.has_pci) {
233 +               if (BCMCPU_IS_6348())
234 +                       val |= GPIO_MODE_6348_G2_PCI;
235 +       }
236 +#endif
237 +       if (board.has_pccard) {
238 +               if (BCMCPU_IS_6348())
239 +                       val |= GPIO_MODE_6348_G1_MII_PCCARD;
240 +       }
241 +
242 +       if (board.has_enet0 && !board.enet0.use_internal_phy) {
243 +               if (BCMCPU_IS_6348())
244 +                       val |= GPIO_MODE_6348_G3_EXT_MII |
245 +                               GPIO_MODE_6348_G0_EXT_MII;
246 +       }
247 +
248 +       if (board.has_enet1 && !board.enet1.use_internal_phy) {
249 +               if (BCMCPU_IS_6348())
250 +                       val |= GPIO_MODE_6348_G3_EXT_MII |
251 +                               GPIO_MODE_6348_G0_EXT_MII;
252 +                       printk(KERN_INFO PFX "resetting gpio6 for eth1...\n");
253 +                       gpio_request(6, "dsp_eth_rst");
254 +                       gpio_direction_output(6, 0);
255 +                       gpio_set_value(6, 1);
256 +       }
257 +
258 +       bcm_gpio_writel(val, GPIO_MODE_REG);
259 +}
260 +
261 +/*
262 + * second stage init callback, good time to panic if we couldn't
263 + * identify on which board we're running since early printk is working
264 + */
265 +void __init board_setup(void)
266 +{
267 +       if (!board.name[0])
268 +               panic("unable to detect bcm963xx board");
269 +       printk(KERN_INFO PFX "board name: %s\n", board.name);
270 +
271 +       /* make sure we're running on expected cpu */
272 +       if (bcm63xx_get_cpu_id() != board.expected_cpu_id)
273 +               panic("unexpected CPU for bcm963xx board");
274 +}
275 +
276 +static struct resource mtd_resources[] = {
277 +       {
278 +               .start          = 0,    /* filled at runtime */
279 +               .end            = 0,    /* filled at runtime */
280 +               .flags          = IORESOURCE_MEM,
281 +       }
282 +};
283 +
284 +static struct platform_device mtd_dev = {
285 +       .name                   = "bcm963xx-flash",
286 +       .resource               = mtd_resources,
287 +       .num_resources          = ARRAY_SIZE(mtd_resources),
288 +};
289 +
290 +static struct gpio_led_platform_data bcm63xx_led_data;
291 +
292 +static struct platform_device bcm63xx_gpio_leds = {
293 +       .name                   = "leds-gpio",
294 +       .id                     = 0,
295 +       .dev.platform_data      = &bcm63xx_led_data,
296 +};
297 +
298 +static struct gpio_keys_platform_data bcm63xx_gpio_keys_data = {
299 +       .poll_interval  = LIVEBOX_KEYS_POLL_INTERVAL,
300 +};
301 +
302 +static struct platform_device bcm63xx_gpio_keys_device = {
303 +       .name           = "gpio-keys-polled",
304 +       .id             = 0,
305 +       .dev.platform_data = &bcm63xx_gpio_keys_data,
306 +};
307 +
308 +/*
309 + * third stage init callback, register all board devices.
310 + */
311 +int __init board_register_devices(void)
312 +{
313 +       u32 val;
314 +       int led_count = 0;
315 +       int button_count = 0;
316 +
317 +       if (board.has_uart0)
318 +               bcm63xx_uart_register(0);
319 +
320 +       if (board.has_uart1)
321 +               bcm63xx_uart_register(1);
322 +
323 +       if (board.has_pccard)
324 +               bcm63xx_pcmcia_register();
325 +
326 +       if (board.has_enet0 &&
327 +           !board_get_mac_address(board.enet0.mac_addr))
328 +               bcm63xx_enet_register(0, &board.enet0);
329 +
330 +       if (board.has_enet1 &&
331 +           !board_get_mac_address(board.enet1.mac_addr))
332 +               bcm63xx_enet_register(1, &board.enet1);
333 +
334 +       if (board.has_ehci0)
335 +               bcm63xx_ehci_register();
336 +
337 +       if (board.has_ohci0)
338 +               bcm63xx_ohci_register();
339 +
340 +       if (board.has_dsp)
341 +               bcm63xx_dsp_register(&board.dsp);
342 +
343 +       bcm63xx_spi_register();
344 +
345 +       if (board.num_devs)
346 +               platform_add_devices(board.devs, board.num_devs);
347 +
348 +       if (board.num_spis)
349 +               spi_register_board_info(board.spis, board.num_spis);
350 +
351 +
352 +       /* read base address of boot chip select (0) */
353 +       val = bcm_mpi_readl(MPI_CSBASE_REG(0));
354 +       val &= MPI_CSBASE_BASE_MASK;
355 +       if (val != LIVEBOX_BOOT_ADDR)
356 +               printk(KERN_NOTICE PFX "flash address is: 0x%08x, forcing to: 0x%08x\n",
357 +                       val, LIVEBOX_BOOT_ADDR);
358 +       mtd_resources[0].start = LIVEBOX_BOOT_ADDR;
359 +       mtd_resources[0].end = 0x1ebfffff;
360 +
361 +       platform_device_register(&mtd_dev);
362 +
363 +       /* count number of LEDs defined by this device */
364 +       while (led_count < ARRAY_SIZE(board.leds) && board.leds[led_count].name)
365 +               led_count++;
366 +
367 +       bcm63xx_led_data.num_leds = led_count;
368 +       bcm63xx_led_data.leds = board.leds;
369 +
370 +       platform_device_register(&bcm63xx_gpio_leds);
371 +
372 +       /* count number of BUTTONs defined by this device */
373 +       while (button_count < ARRAY_SIZE(board.buttons) && board.buttons[button_count].desc)
374 +               button_count++;
375 +
376 +       if (button_count) {
377 +               bcm63xx_gpio_keys_data.nbuttons = button_count;
378 +               bcm63xx_gpio_keys_data.buttons = board.buttons;
379 +
380 +               platform_device_register(&bcm63xx_gpio_keys_device);
381 +       }
382 +
383 +#ifdef CONFIG_PCI
384 +       if (board.has_pci)
385 +               bcm63xx_pci_register();
386 +#endif
387 +
388 +       return 0;
389 +}