Flatten brcm63xx patches, should make our life easier to patch files now ;)
[openwrt/svn-archive/archive.git] / target / linux / brcm63xx / files / arch / mips / bcm63xx / boards / board_bcm963xx.c
1 /*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
5 *
6 * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
7 */
8
9 #include <linux/init.h>
10 #include <linux/kernel.h>
11 #include <linux/string.h>
12 #include <linux/platform_device.h>
13 #include <linux/mtd/mtd.h>
14 #include <linux/mtd/partitions.h>
15 #include <linux/mtd/physmap.h>
16 #include <asm/addrspace.h>
17 #include <bcm63xx_board.h>
18 #include <bcm63xx_cpu.h>
19 #include <bcm63xx_regs.h>
20 #include <bcm63xx_io.h>
21 #include <bcm63xx_board.h>
22 #include <bcm63xx_dev_pci.h>
23 #include <bcm63xx_dev_uart.h>
24 #include <bcm63xx_dev_enet.h>
25 #include <bcm63xx_dev_pcmcia.h>
26 #include <bcm63xx_dev_usb_ohci.h>
27 #include <bcm63xx_dev_usb_ehci.h>
28 #include <board_bcm963xx.h>
29
30 #define PFX "board_bcm963xx: "
31
32 static struct bcm963xx_nvram nvram;
33 static unsigned int mac_addr_used = 0;
34 static struct board_info board;
35
36 /*
37 * known 6348 boards
38 */
39 #ifdef CONFIG_BCM63XX_CPU_6348
40 static struct board_info __initdata board_96348r = {
41 .name = "96348R",
42 .expected_cpu_id = 0x6348,
43
44 .has_enet0 = 1,
45 .has_pci = 1,
46
47 .enet0 = {
48 .has_phy = 1,
49 .use_internal_phy = 1,
50 },
51 };
52
53 static struct board_info __initdata board_96348gw_11 = {
54 .name = "96348GW-11",
55 .expected_cpu_id = 0x6348,
56
57 .has_enet0 = 1,
58 .has_enet1 = 1,
59 .has_pci = 1,
60
61 .enet0 = {
62 .has_phy = 1,
63 .use_internal_phy = 1,
64 },
65
66 .enet1 = {
67 .force_speed_100 = 1,
68 .force_duplex_full = 1,
69 },
70
71
72 .has_ohci0 = 1,
73 .has_pccard = 1,
74 .has_ehci0 = 1,
75 };
76
77 static struct board_info __initdata board_96348gw = {
78 .name = "96348GW",
79 .expected_cpu_id = 0x6348,
80
81 .has_enet0 = 1,
82 .has_enet1 = 1,
83 .has_pci = 1,
84
85 .enet0 = {
86 .has_phy = 1,
87 .use_internal_phy = 1,
88 },
89 .enet1 = {
90 .force_speed_100 = 1,
91 .force_duplex_full = 1,
92 },
93 };
94 #endif
95
96 /*
97 * known 6358 boards
98 */
99 #ifdef CONFIG_BCM63XX_CPU_6358
100 static struct board_info __initdata board_96358vw = {
101 .name = "96358VW",
102 .expected_cpu_id = 0x6358,
103
104 .has_enet0 = 1,
105 .has_enet1 = 1,
106 .has_pci = 1,
107
108 .enet0 = {
109 .has_phy = 1,
110 .use_internal_phy = 1,
111 },
112
113 .enet1 = {
114 .force_speed_100 = 1,
115 .force_duplex_full = 1,
116 },
117
118
119 .has_ohci0 = 1,
120 .has_pccard = 1,
121 .has_ehci0 = 1,
122 };
123
124 static struct board_info __initdata board_96358vw2 = {
125 .name = "96358VW2",
126 .expected_cpu_id = 0x6358,
127
128 .has_enet0 = 1,
129 .has_enet1 = 1,
130 .has_pci = 1,
131
132 .enet0 = {
133 .has_phy = 1,
134 .use_internal_phy = 1,
135 },
136
137 .enet1 = {
138 .force_speed_100 = 1,
139 .force_duplex_full = 1,
140 },
141
142
143 .has_ohci0 = 1,
144 .has_pccard = 1,
145 .has_ehci0 = 1,
146 };
147 #endif
148
149 /*
150 * all boards
151 */
152 static const struct board_info __initdata *bcm963xx_boards[] = {
153 #ifdef CONFIG_BCM63XX_CPU_6348
154 &board_96348r,
155 &board_96348gw,
156 &board_96348gw_11,
157 #endif
158
159 #ifdef CONFIG_BCM63XX_CPU_6358
160 &board_96358vw,
161 &board_96358vw2,
162 #endif
163 };
164
165 /*
166 * early init callback, read nvram data from flash and checksum it
167 */
168 void __init board_prom_init(void)
169 {
170 unsigned int check_len, i;
171 u8 *boot_addr, *cfe, *p;
172 char cfe_version[32];
173 u32 val;
174
175 /* read base address of boot chip select (0) */
176 val = bcm_mpi_readl(MPI_CSBASE_REG(0));
177 val &= MPI_CSBASE_BASE_MASK;
178 boot_addr = (u8 *)KSEG1ADDR(val);
179
180 /* dump cfe version */
181 cfe = boot_addr + BCM963XX_CFE_VERSION_OFFSET;
182 if (!memcmp(cfe, "cfe-v", 5))
183 snprintf(cfe_version, sizeof(cfe_version), "%u.%u.%u-%u.%u",
184 cfe[5], cfe[6], cfe[7], cfe[8], cfe[9]);
185 else
186 strcpy(cfe_version, "unknown");
187 printk(KERN_INFO PFX "CFE version: %s\n", cfe_version);
188
189 /* extract nvram data */
190 memcpy(&nvram, boot_addr + BCM963XX_NVRAM_OFFSET, sizeof(nvram));
191
192 /* check checksum before using data */
193 if (nvram.version <= 4)
194 check_len = offsetof(struct bcm963xx_nvram, checksum_old);
195 else
196 check_len = sizeof(nvram);
197 val = 0;
198 p = (u8 *)&nvram;
199 while (check_len--)
200 val += *p;
201 if (val) {
202 printk(KERN_ERR PFX "invalid nvram checksum\n");
203 return;
204 }
205
206 /* find board by name */
207 for (i = 0; i < ARRAY_SIZE(bcm963xx_boards); i++) {
208 if (strncmp(nvram.name, bcm963xx_boards[i]->name,
209 sizeof(nvram.name)))
210 continue;
211 /* copy, board desc array is marked initdata */
212 memcpy(&board, bcm963xx_boards[i], sizeof(board));
213 break;
214 }
215
216 /* bail out if board is not found, will complain later */
217 if (!board.name[0]) {
218 char name[17];
219 memcpy(name, nvram.name, 16);
220 name[16] = 0;
221 printk(KERN_ERR PFX "unknown bcm963xx board: %s\n",
222 name);
223 return;
224 }
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 if (board.has_pci) {
232 bcm63xx_pci_enabled = 1;
233 if (BCMCPU_IS_6348())
234 val |= GPIO_MODE_6348_G2_PCI;
235 }
236
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 }
253
254 bcm_gpio_writel(val, GPIO_MODE_REG);
255 }
256
257 /*
258 * second stage init callback, good time to panic if we couldn't
259 * identify on which board we're running since early printk is working
260 */
261 void __init board_setup(void)
262 {
263 if (!board.name[0])
264 panic("unable to detect bcm963xx board");
265 printk(KERN_INFO PFX "board name: %s\n", board.name);
266
267 /* make sure we're running on expected cpu */
268 if (bcm63xx_get_cpu_id() != board.expected_cpu_id)
269 panic("unexpected CPU for bcm963xx board");
270 }
271
272 /*
273 * return board name for /proc/cpuinfo
274 */
275 const char *board_get_name(void)
276 {
277 return board.name;
278 }
279
280 /*
281 * register & return a new board mac address
282 */
283 static int board_get_mac_address(u8 *mac)
284 {
285 u8 *p;
286 int count;
287
288 if (mac_addr_used >= nvram.mac_addr_count) {
289 printk(KERN_ERR PFX "not enough mac address\n");
290 return -ENODEV;
291 }
292
293 memcpy(mac, nvram.mac_addr_base, ETH_ALEN);
294 p = mac + ETH_ALEN - 1;
295 count = mac_addr_used;
296
297 while (count--) {
298 do {
299 (*p)++;
300 if (*p != 0)
301 break;
302 p--;
303 } while (p != mac);
304 }
305
306 if (p == mac) {
307 printk(KERN_ERR PFX "unable to fetch mac address\n");
308 return -ENODEV;
309 }
310
311 mac_addr_used++;
312 return 0;
313 }
314
315 static struct mtd_partition mtd_partitions[] = {
316 {
317 .name = "cfe",
318 .offset = 0x0,
319 .size = 0x40000,
320 }
321 };
322
323 static struct physmap_flash_data flash_data = {
324 .width = 2,
325 .nr_parts = ARRAY_SIZE(mtd_partitions),
326 .parts = mtd_partitions,
327 };
328
329 static struct resource mtd_resources[] = {
330 {
331 .start = 0, /* filled at runtime */
332 .end = 0, /* filled at runtime */
333 .flags = IORESOURCE_MEM,
334 }
335 };
336
337 static struct platform_device mtd_dev = {
338 .name = "physmap-flash",
339 .resource = mtd_resources,
340 .num_resources = ARRAY_SIZE(mtd_resources),
341 .dev = {
342 .platform_data = &flash_data,
343 },
344 };
345
346 /*
347 * third stage init callback, register all board devices.
348 */
349 int __init board_register_devices(void)
350 {
351 u32 val;
352
353 bcm63xx_uart_register();
354
355 if (board.has_pccard)
356 bcm63xx_pcmcia_register();
357
358 if (board.has_enet0 &&
359 !board_get_mac_address(board.enet0.mac_addr))
360 bcm63xx_enet_register(0, &board.enet0);
361
362 if (board.has_enet1 &&
363 !board_get_mac_address(board.enet1.mac_addr))
364 bcm63xx_enet_register(1, &board.enet1);
365
366 if (board.has_ohci0)
367 bcm63xx_ohci_register();
368
369 if (board.has_ehci0)
370 bcm63xx_ehci_register();
371
372
373 /* read base address of boot chip select (0) */
374 val = bcm_mpi_readl(MPI_CSBASE_REG(0));
375 val &= MPI_CSBASE_BASE_MASK;
376 mtd_resources[0].start = val;
377 mtd_resources[0].end = 0x1FFFFFFF;
378
379 platform_device_register(&mtd_dev);
380
381 return 0;
382 }
383