brcm63xx: copy SR102 support patch to 4.14 as well
[oweals/openwrt.git] / target / linux / brcm63xx / patches-4.14 / 513-MIPS-BCM63XX-add-inventel-Livebox-support.patch
1 From e796582b499f0ba6acaa1ac3a10c09cceaab7702 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] 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 |  215 ++++++++++++++++++++++++++++++
12  5 files changed, 229 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 @@ -13,4 +13,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 @@ -55,7 +55,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 @@ -24,4 +24,10 @@ static inline void board_of_device_prese
48  }
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,163 @@
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 +static unsigned int mac_addr_used = 0;
86 +
87 +/*
88 + * known 6348 boards
89 + */
90 +#ifdef CONFIG_BCM63XX_CPU_6348
91 +static struct board_info __initdata board_livebox_blue5g = {
92 +       .name                           = "Livebox-blue-5g",
93 +       .expected_cpu_id                = 0x6348,
94 +
95 +       .has_enet0                      = 1,
96 +       .has_enet1                      = 1,
97 +       .has_pci                        = 1,
98 +
99 +       .enet0 = {
100 +               .has_phy                = 1,
101 +               .use_internal_phy       = 1,
102 +       },
103 +
104 +       .enet1 = {
105 +                 .has_phy              = 1,
106 +                 .phy_id               = 31,
107 +       },
108 +
109 +       .ephy_reset_gpio                = 6,
110 +       .ephy_reset_gpio_flags          = GPIO_ACTIVE_LOW,
111 +
112 +       .has_ohci0                      = 1,
113 +       .has_pccard                     = 1,
114 +
115 +       .has_dsp                        = 0, /*TODO some Liveboxes have dsp*/
116 +       .dsp = {
117 +               .gpio_rst               = 6,
118 +               .gpio_int               = 35,
119 +               .cs                     = 2,
120 +               .ext_irq                = 2,
121 +       },
122 +};
123 +#endif
124 +
125 +/*
126 + * all boards
127 + */
128 +static const struct board_info __initdata *bcm963xx_boards[] = {
129 +#ifdef CONFIG_BCM63XX_CPU_6348
130 +       &board_livebox_blue5g
131 +#endif
132 +};
133 +
134 +static struct of_device_id const livebox_boards_dt[] = {
135 +       { .compatible = "inventel,livebox-blue-5g", .data = &board_livebox_blue5g, },
136 +       { }
137 +};
138 +
139 +/*
140 + * register & return a new board mac address
141 + */
142 +static int livebox_get_mac_address(u8 *mac)
143 +{
144 +       u8 *p;
145 +       int count;
146 +
147 +       memcpy(mac, (u8 *)0xBEBFF377, ETH_ALEN);
148 +
149 +       p = mac + ETH_ALEN - 1;
150 +       count = mac_addr_used;
151 +
152 +       while (count--) {
153 +               do {
154 +                       (*p)++;
155 +                       if (*p != 0)
156 +                               break;
157 +                       p--;
158 +               } while (p != mac);
159 +       }
160 +
161 +       if (p == mac) {
162 +               printk(KERN_ERR PFX "unable to fetch mac address\n");
163 +               return -ENODEV;
164 +       }
165 +        mac_addr_used++;
166 +
167 +       return 0;
168 +}
169 +
170 +/*
171 + * early init callback
172 + */
173 +#define LIVEBOX_GPIO_DETECT_MASK       0x000000ff
174 +#define LIVEBOX_BOOT_ADDR              0x1e400000
175 +
176 +#define LIVEBOX_HW_BLUE5G_9            0x90
177 +
178 +void __init board_livebox_init(void)
179 +{
180 +       u32 val;
181 +       u8 hw_version;
182 +       const struct board_info *board;
183 +       const struct of_device_id *board_match;
184 +
185 +       /* find board by compat */
186 +       board_match = bcm63xx_match_board(livebox_boards_dt);
187 +       if (board_match) {
188 +               board = board_match->data;
189 +       } else {
190 +               /* Get hardware version */
191 +               val = bcm_gpio_readl(GPIO_CTL_LO_REG);
192 +               val &= ~LIVEBOX_GPIO_DETECT_MASK;
193 +               bcm_gpio_writel(val, GPIO_CTL_LO_REG);
194 +
195 +               hw_version = bcm_gpio_readl(GPIO_DATA_LO_REG);
196 +               hw_version &= LIVEBOX_GPIO_DETECT_MASK;
197 +
198 +               switch (hw_version) {
199 +               case LIVEBOX_HW_BLUE5G_9:
200 +                       printk(KERN_INFO PFX "Livebox BLUE5G.9\n");
201 +                       board = bcm963xx_boards[0];
202 +                       break;
203 +               default:
204 +                       printk(KERN_INFO PFX "Unknown livebox version: %02x\n",
205 +                              hw_version);
206 +                       /* use default livebox configuration */
207 +                       board = bcm963xx_boards[0];
208 +                       break;
209 +               }
210 +       }
211 +
212 +       /* use default livebox configuration */
213 +       board_early_setup(board, livebox_get_mac_address);
214 +
215 +       /* read base address of boot chip select (0) */
216 +       val = bcm_mpi_readl(MPI_CSBASE_REG(0));
217 +       val &= MPI_CSBASE_BASE_MASK;
218 +       if (val != LIVEBOX_BOOT_ADDR) {
219 +               printk(KERN_NOTICE PFX "flash address is: 0x%08x, forcing to: 0x%08x\n",
220 +                       val, LIVEBOX_BOOT_ADDR);
221 +               bcm63xx_flash_force_phys_base_address(LIVEBOX_BOOT_ADDR, 0x1ebfffff);
222 +       }
223 +}