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