1d8b60105868842e67adb164b532bfac815f002b
[openwrt.git] / target / linux / brcm63xx / patches-3.10 / 513-MIPS-BCM63XX-add-inventel-Livebox-support.patch
1 From 7e6b22225e16fbb22dbf7f2113d8c6d65333818c Mon Sep 17 00:00:00 2001
2 From: Jonas Gorski <jogo@openwrt.org>
3 Date: Sun, 9 Mar 2014 04:55:52 +0100
4 Subject: [PATCH 44/44] MIPS: BCM63XX: add inventel Livebox support
5
6 ---
7  arch/mips/bcm63xx/boards/Kconfig         |   6 +
8  arch/mips/bcm63xx/boards/Makefile        |   1 +
9  arch/mips/bcm63xx/boards/board_common.c  |   2 +-
10  arch/mips/bcm63xx/boards/board_common.h  |   6 +
11  arch/mips/bcm63xx/boards/board_livebox.c | 193 +++++++++++++++++++++++++++++++
12  5 files changed, 207 insertions(+), 1 deletion(-)
13  create mode 100644 arch/mips/bcm63xx/boards/board_livebox.c
14
15 --- a/arch/mips/bcm63xx/boards/Kconfig
16 +++ b/arch/mips/bcm63xx/boards/Kconfig
17 @@ -7,4 +7,10 @@ config BOARD_BCM963XX
18         default y
19         help
20  
21 +config BOARD_LIVEBOX
22 +       bool "Inventel Livebox(es) boards"
23 +       select SSB
24 +       help
25 +         Inventel Livebox boards using the RedBoot bootloader.
26 +
27  endmenu
28 --- a/arch/mips/bcm63xx/boards/Makefile
29 +++ b/arch/mips/bcm63xx/boards/Makefile
30 @@ -1,2 +1,3 @@
31  obj-y                                  += board_common.o
32  obj-$(CONFIG_BOARD_BCM963XX)           += board_bcm963xx.o
33 +obj-$(CONFIG_BOARD_LIVEBOX)            += board_livebox.o
34 --- a/arch/mips/bcm63xx/boards/board_common.c
35 +++ b/arch/mips/bcm63xx/boards/board_common.c
36 @@ -96,7 +96,7 @@ void __init board_prom_init(void)
37         if (fw_arg3 == CFE_EPTSEAL)
38                 board_bcm963xx_init();
39         else
40 -               panic("unsupported bootloader detected");
41 +               board_livebox_init();
42  }
43  
44  static int (*board_get_mac_address)(u8 mac[ETH_ALEN]);
45 --- a/arch/mips/bcm63xx/boards/board_common.h
46 +++ b/arch/mips/bcm63xx/boards/board_common.h
47 @@ -12,4 +12,10 @@ void board_bcm963xx_init(void);
48  static inline void board_bcm963xx_init(void) { }
49  #endif
50  
51 +#if defined(CONFIG_BOARD_LIVEBOX)
52 +void board_livebox_init(void);
53 +#else
54 +static inline void board_livebox_init(void) { }
55 +#endif
56 +
57  #endif /* __BOARD_COMMON_H */
58 --- /dev/null
59 +++ b/arch/mips/bcm63xx/boards/board_livebox.c
60 @@ -0,0 +1,197 @@
61 +/*
62 + * This file is subject to the terms and conditions of the GNU General Public
63 + * License.  See the file "COPYING" in the main directory of this archive
64 + * for more details.
65 + *
66 + * Copyright (C) 2008 Florian Fainelli <florian@openwrt.org>
67 + */
68 +
69 +#include <linux/init.h>
70 +#include <linux/kernel.h>
71 +#include <linux/string.h>
72 +#include <linux/input.h>
73 +#include <asm/addrspace.h>
74 +#include <bcm63xx_board.h>
75 +#include <bcm63xx_cpu.h>
76 +#include <bcm63xx_regs.h>
77 +#include <bcm63xx_io.h>
78 +#include <bcm63xx_dev_flash.h>
79 +#include <board_bcm963xx.h>
80 +
81 +#include "board_common.h"
82 +
83 +#define PFX    "board_livebox: "
84 +
85 +#define LIVEBOX_KEYS_POLL_INTERVAL     20
86 +#define LIVEBOX_KEYS_DEBOUNCE_INTERVAL (LIVEBOX_KEYS_POLL_INTERVAL * 3)
87 +
88 +static unsigned int mac_addr_used = 0;
89 +
90 +/*
91 + * known 6348 boards
92 + */
93 +#ifdef CONFIG_BCM63XX_CPU_6348
94 +static struct board_info __initdata board_livebox_blue5g = {
95 +       .name                           = "Livebox-blue-5g",
96 +       .expected_cpu_id                = 0x6348,
97 +
98 +       .has_uart0                      = 1,
99 +       .has_enet0                      = 1,
100 +       .has_enet1                      = 1,
101 +       .has_pci                        = 1,
102 +
103 +       .enet0 = {
104 +               .has_phy                = 1,
105 +               .use_internal_phy       = 1,
106 +       },
107 +
108 +       .enet1 = {
109 +                 .has_phy              = 1,
110 +                 .phy_id               = 31,
111 +       },
112 +
113 +       .ephy_reset_gpio                = 6,
114 +       .ephy_reset_gpio_flags          = GPIOF_INIT_HIGH,
115 +
116 +       .has_ohci0                      = 1,
117 +       .has_pccard                     = 1,
118 +
119 +       .has_dsp                        = 0, /*TODO some Liveboxes have dsp*/
120 +       .dsp = {
121 +               .gpio_rst               = 6, /*FIXME eth1 shares gpio6 with dsp?*/
122 +               .gpio_int               = 35,
123 +               .cs                     = 2,
124 +               .ext_irq                = 2,
125 +       },
126 +
127 +       .leds = {
128 +               {
129 +                       .name           = "Livebox-blue-5g::adsl-fail",
130 +                       .gpio           = 0,
131 +                       .active_low     = 0,
132 +                       .default_trigger = "default-on",
133 +               },
134 +               {
135 +                       .name           = "Livebox-blue-5g::adsl",
136 +                       .gpio           = 1,
137 +               },
138 +               {
139 +                       .name           = "Livebox-blue-5g::traffic",
140 +                       .gpio           = 2,
141 +               },
142 +               {
143 +                       .name           = "Livebox-blue-5g::phone",
144 +                       .gpio           = 3,
145 +               },
146 +               {
147 +                       .name           = "Livebox-blue-5g::wifi",
148 +                       .gpio           = 4,
149 +               },
150 +       },
151 +
152 +       .buttons = {
153 +               {
154 +                       .desc           = "BTN_1",
155 +                       .gpio           = 36,
156 +                       .active_low     = 1,
157 +                       .type           = EV_KEY,
158 +                       .code           = BTN_1,
159 +                       .debounce_interval = LIVEBOX_KEYS_DEBOUNCE_INTERVAL,
160 +               },
161 +               {
162 +                       .desc           = "BTN_2",
163 +                       .gpio           = 7,
164 +                       .active_low     = 1,
165 +                       .type           = EV_KEY,
166 +                       .code           = BTN_2,
167 +                       .debounce_interval = LIVEBOX_KEYS_DEBOUNCE_INTERVAL,
168 +               },
169 +
170 +       },
171 +};
172 +#endif
173 +
174 +/*
175 + * all boards
176 + */
177 +static const struct board_info __initdata *bcm963xx_boards[] = {
178 +#ifdef CONFIG_BCM63XX_CPU_6348
179 +       &board_livebox_blue5g
180 +#endif
181 +};
182 +
183 +/*
184 + * register & return a new board mac address
185 + */
186 +static int livebox_get_mac_address(u8 *mac)
187 +{
188 +       u8 *p;
189 +       int count;
190 +
191 +       memcpy(mac, (u8 *)0xBEBFF377, ETH_ALEN);
192 +
193 +       p = mac + ETH_ALEN - 1;
194 +       count = mac_addr_used;
195 +
196 +       while (count--) {
197 +               do {
198 +                       (*p)++;
199 +                       if (*p != 0)
200 +                               break;
201 +                       p--;
202 +               } while (p != mac);
203 +       }
204 +
205 +       if (p == mac) {
206 +               printk(KERN_ERR PFX "unable to fetch mac address\n");
207 +               return -ENODEV;
208 +       }
209 +        mac_addr_used++;
210 +
211 +       return 0;
212 +}
213 +
214 +/*
215 + * early init callback
216 + */
217 +#define LIVEBOX_GPIO_DETECT_MASK       0x000000ff
218 +#define LIVEBOX_BOOT_ADDR              0x1e400000
219 +
220 +#define LIVEBOX_HW_BLUE5G_9            0x90
221 +
222 +void __init board_livebox_init(void)
223 +{
224 +       u32 val;
225 +       u8 hw_version;
226 +       const struct board_info *board;
227 +
228 +       /* Get hardware version */
229 +       val = bcm_gpio_readl(GPIO_CTL_LO_REG);
230 +       val &= ~LIVEBOX_GPIO_DETECT_MASK;
231 +       bcm_gpio_writel(val, GPIO_CTL_LO_REG);
232 +
233 +       hw_version = bcm_gpio_readl(GPIO_DATA_LO_REG) & LIVEBOX_GPIO_DETECT_MASK;
234 +       switch (hw_version) {
235 +       case LIVEBOX_HW_BLUE5G_9:
236 +               printk(KERN_INFO PFX "Livebox BLUE5G.9\n");
237 +               board = bcm963xx_boards[0];
238 +               break;
239 +       default:
240 +               printk(KERN_INFO PFX "Unknown livebox version: %02x\n", hw_version);
241 +               /* use default livebox configuration */
242 +               board = bcm963xx_boards[0];
243 +               break;
244 +       }
245 +
246 +       /* use default livebox configuration */
247 +       board_early_setup(board, livebox_get_mac_address);
248 +
249 +       /* read base address of boot chip select (0) */
250 +       val = bcm_mpi_readl(MPI_CSBASE_REG(0));
251 +       val &= MPI_CSBASE_BASE_MASK;
252 +       if (val != LIVEBOX_BOOT_ADDR) {
253 +               printk(KERN_NOTICE PFX "flash address is: 0x%08x, forcing to: 0x%08x\n",
254 +                       val, LIVEBOX_BOOT_ADDR);
255 +               bcm63xx_flash_force_phys_base_address(LIVEBOX_BOOT_ADDR, 0x1ebfffff);
256 +       }
257 +}