brcm.patch 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. diff -Nur linux-2.6.34.orig/arch/mips/bcm47xx/Makefile linux-2.6.34/arch/mips/bcm47xx/Makefile
  2. --- linux-2.6.34.orig/arch/mips/bcm47xx/Makefile 2010-05-16 23:17:36.000000000 +0200
  3. +++ linux-2.6.34/arch/mips/bcm47xx/Makefile 2010-06-03 22:38:03.501617275 +0200
  4. @@ -3,4 +3,5 @@
  5. # under Linux.
  6. #
  7. -obj-y := gpio.o irq.o prom.o serial.o setup.o time.o wgt634u.o
  8. +obj-y := gpio.o irq.o nvram.o platform.o prom.o \
  9. + serial.o setup.o time.o wgt634u.o
  10. diff -Nur linux-2.6.34.orig/arch/mips/bcm47xx/nvram.c linux-2.6.34/arch/mips/bcm47xx/nvram.c
  11. --- linux-2.6.34.orig/arch/mips/bcm47xx/nvram.c 1970-01-01 01:00:00.000000000 +0100
  12. +++ linux-2.6.34/arch/mips/bcm47xx/nvram.c 2010-06-03 22:37:52.471617640 +0200
  13. @@ -0,0 +1,100 @@
  14. +/*
  15. + * BCM947xx nvram variable access
  16. + *
  17. + * Copyright (C) 2005 Broadcom Corporation
  18. + * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
  19. + *
  20. + * This program is free software; you can redistribute it and/or modify it
  21. + * under the terms of the GNU General Public License as published by the
  22. + * Free Software Foundation; either version 2 of the License, or (at your
  23. + * option) any later version.
  24. + */
  25. +
  26. +#include <linux/init.h>
  27. +#include <linux/module.h>
  28. +#include <linux/ssb/ssb.h>
  29. +#include <linux/kernel.h>
  30. +#include <linux/string.h>
  31. +#include <linux/interrupt.h>
  32. +#include <linux/spinlock.h>
  33. +#include <linux/slab.h>
  34. +#include <asm/byteorder.h>
  35. +#include <asm/bootinfo.h>
  36. +#include <asm/addrspace.h>
  37. +#include <asm/io.h>
  38. +#include <asm/uaccess.h>
  39. +#include <asm/mach-bcm47xx/nvram.h>
  40. +#include <asm/mach-bcm47xx/bcm47xx.h>
  41. +
  42. +static char nvram_buf[NVRAM_SPACE];
  43. +
  44. +/* Probe for NVRAM header */
  45. +static void __init early_nvram_init(void)
  46. +{
  47. + struct ssb_mipscore *mcore = &ssb_bcm47xx.mipscore;
  48. + struct nvram_header *header;
  49. + int i;
  50. + u32 base, lim, off;
  51. + u32 *src, *dst;
  52. +
  53. + base = mcore->flash_window;
  54. + lim = mcore->flash_window_size;
  55. +
  56. + off = FLASH_MIN;
  57. + while (off <= lim) {
  58. + /* Windowed flash access */
  59. + header = (struct nvram_header *)
  60. + KSEG1ADDR(base + off - NVRAM_SPACE);
  61. + if (header->magic == NVRAM_HEADER)
  62. + goto found;
  63. + off <<= 1;
  64. + }
  65. +
  66. + /* Try embedded NVRAM at 4 KB and 1 KB as last resorts */
  67. + header = (struct nvram_header *) KSEG1ADDR(base + 4096);
  68. + if (header->magic == NVRAM_HEADER)
  69. + goto found;
  70. +
  71. + header = (struct nvram_header *) KSEG1ADDR(base + 1024);
  72. + if (header->magic == NVRAM_HEADER)
  73. + goto found;
  74. +
  75. + return;
  76. +
  77. +found:
  78. + src = (u32 *) header;
  79. + dst = (u32 *) nvram_buf;
  80. + for (i = 0; i < sizeof(struct nvram_header); i += 4)
  81. + *dst++ = *src++;
  82. + for (; i < header->len && i < NVRAM_SPACE; i += 4)
  83. + *dst++ = le32_to_cpu(*src++);
  84. +}
  85. +
  86. +int nvram_getenv(char *name, char *val, size_t val_len)
  87. +{
  88. + char *var, *value, *end, *eq;
  89. +
  90. + if (!name)
  91. + return 1;
  92. +
  93. + if (!nvram_buf[0])
  94. + early_nvram_init();
  95. +
  96. + /* Look for name=value and return value */
  97. + var = &nvram_buf[sizeof(struct nvram_header)];
  98. + end = nvram_buf + sizeof(nvram_buf) - 2;
  99. + end[0] = end[1] = '\0';
  100. + for (; *var; var = value + strlen(value) + 1) {
  101. + eq = strchr(var, '=');
  102. + if (!eq)
  103. + break;
  104. + value = eq + 1;
  105. + if ((eq - var) == strlen(name) &&
  106. + strncmp(var, name, (eq - var)) == 0) {
  107. + snprintf(val, val_len, "%s", value);
  108. + return 0;
  109. + }
  110. + }
  111. + return 1;
  112. +}
  113. +EXPORT_SYMBOL(nvram_getenv);
  114. diff -Nur linux-2.6.34.orig/arch/mips/bcm47xx/platform.c linux-2.6.34/arch/mips/bcm47xx/platform.c
  115. --- linux-2.6.34.orig/arch/mips/bcm47xx/platform.c 1970-01-01 01:00:00.000000000 +0100
  116. +++ linux-2.6.34/arch/mips/bcm47xx/platform.c 2010-06-03 22:38:03.501617275 +0200
  117. @@ -0,0 +1,79 @@
  118. +/*
  119. + * This file is subject to the terms and conditions of the GNU General Public
  120. + * License. See the file "COPYING" in the main directory of this archive
  121. + * for more details.
  122. + *
  123. + * Copyright (C) 2010 Waldemar Brodkorb <wbx@openadk.org>
  124. + */
  125. +
  126. +#include <linux/platform_device.h>
  127. +#include <linux/module.h>
  128. +#include <linux/mtd/physmap.h>
  129. +#include <linux/ssb/ssb.h>
  130. +
  131. +#include <asm/mach-bcm47xx/bcm47xx.h>
  132. +#include <asm/mach-bcm47xx/nvram.h>
  133. +
  134. +static struct mtd_partition bcm47xx_partitions[] = {
  135. + {
  136. + .name = "cfe",
  137. + .offset = 0,
  138. + .size = 0x40000, /* 256k */
  139. + .mask_flags = MTD_WRITEABLE /* force read-only */
  140. + },
  141. + {
  142. + .name = "linux",
  143. + .offset = 0,
  144. + .size = 0,
  145. + },
  146. + {
  147. + .name = "nvram",
  148. + .offset = 0,
  149. + .size = 0,
  150. + },
  151. +};
  152. +
  153. +static struct physmap_flash_data bcm47xx_flash_data = {
  154. + .parts = bcm47xx_partitions,
  155. + .nr_parts = ARRAY_SIZE(bcm47xx_partitions)
  156. +};
  157. +
  158. +static struct resource bcm47xx_flash_resource = {
  159. + .flags = IORESOURCE_MEM,
  160. +};
  161. +
  162. +static struct platform_device bcm47xx_flash = {
  163. + .name = "physmap-flash",
  164. + .id = 0,
  165. + .dev = { .platform_data = &bcm47xx_flash_data, },
  166. + .resource = &bcm47xx_flash_resource,
  167. + .num_resources = 1,
  168. +};
  169. +
  170. +static struct platform_device *bcm47xx_devices[] __initdata = {
  171. + &bcm47xx_flash,
  172. +};
  173. +
  174. +static int __init bcm47xx_register_devices(void)
  175. +{
  176. + u32 flash_size;
  177. + struct ssb_mipscore *mcore = &ssb_bcm47xx.mipscore;
  178. +
  179. + /* devices might have 2, 4 or 8 MB flash size */
  180. + flash_size = mcore->flash_window_size;
  181. + printk(KERN_INFO "FLASH SIZE: %x\n", flash_size);
  182. + bcm47xx_partitions[1].offset = 0x40000;
  183. + bcm47xx_partitions[1].size = flash_size - NVRAM_FLASH_SIZE - 0x40000;
  184. + bcm47xx_partitions[2].offset = flash_size - NVRAM_FLASH_SIZE;
  185. + bcm47xx_partitions[2].size = NVRAM_FLASH_SIZE;
  186. +
  187. + bcm47xx_flash_data.width = mcore->flash_buswidth;
  188. + bcm47xx_flash_resource.start = mcore->flash_window;
  189. + bcm47xx_flash_resource.end = mcore->flash_window
  190. + + mcore->flash_window_size
  191. + - 1;
  192. + return platform_add_devices(bcm47xx_devices,
  193. + ARRAY_SIZE(bcm47xx_devices));
  194. +}
  195. +
  196. +device_initcall(bcm47xx_register_devices);
  197. diff -Nur linux-2.6.34.orig/arch/mips/bcm47xx/setup.c linux-2.6.34/arch/mips/bcm47xx/setup.c
  198. --- linux-2.6.34.orig/arch/mips/bcm47xx/setup.c 2010-05-16 23:17:36.000000000 +0200
  199. +++ linux-2.6.34/arch/mips/bcm47xx/setup.c 2010-06-03 22:37:52.481613327 +0200
  200. @@ -1,8 +1,8 @@
  201. /*
  202. * Copyright (C) 2004 Florian Schirmer <jolt@tuxbox.org>
  203. - * Copyright (C) 2005 Waldemar Brodkorb <wbx@openwrt.org>
  204. * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
  205. * Copyright (C) 2006 Michael Buesch <mb@bu3sch.de>
  206. + * Copyright (C) 2010 Waldemar Brodkorb <wbx@openadk.org>
  207. *
  208. * This program is free software; you can redistribute it and/or modify it
  209. * under the terms of the GNU General Public License as published by the
  210. @@ -33,6 +33,7 @@
  211. #include <asm/time.h>
  212. #include <bcm47xx.h>
  213. #include <asm/fw/cfe/cfe_api.h>
  214. +#include <asm/mach-bcm47xx/nvram.h>
  215. struct ssb_bus ssb_bcm47xx;
  216. EXPORT_SYMBOL(ssb_bcm47xx);
  217. @@ -81,28 +82,42 @@
  218. /* Fill boardinfo structure */
  219. memset(&(iv->boardinfo), 0 , sizeof(struct ssb_boardinfo));
  220. - if (cfe_getenv("boardvendor", buf, sizeof(buf)) >= 0)
  221. + if (cfe_getenv("boardvendor", buf, sizeof(buf)) >= 0 ||
  222. + nvram_getenv("boardvendor", buf, sizeof(buf)) >= 0)
  223. iv->boardinfo.type = (u16)simple_strtoul(buf, NULL, 0);
  224. - if (cfe_getenv("boardtype", buf, sizeof(buf)) >= 0)
  225. + if (cfe_getenv("boardtype", buf, sizeof(buf)) >= 0 ||
  226. + nvram_getenv("boardtype", buf, sizeof(buf)) >= 0)
  227. iv->boardinfo.type = (u16)simple_strtoul(buf, NULL, 0);
  228. - if (cfe_getenv("boardrev", buf, sizeof(buf)) >= 0)
  229. + if (cfe_getenv("boardrev", buf, sizeof(buf)) >= 0 ||
  230. + nvram_getenv("boardrev", buf, sizeof(buf)) >= 0)
  231. iv->boardinfo.rev = (u16)simple_strtoul(buf, NULL, 0);
  232. /* Fill sprom structure */
  233. memset(&(iv->sprom), 0, sizeof(struct ssb_sprom));
  234. iv->sprom.revision = 3;
  235. - if (cfe_getenv("et0macaddr", buf, sizeof(buf)) >= 0)
  236. + if (cfe_getenv("et0macaddr", buf, sizeof(buf)) >= 0 ||
  237. + nvram_getenv("et0macaddr", buf, sizeof(buf)) >= 0)
  238. str2eaddr(buf, iv->sprom.et0mac);
  239. - if (cfe_getenv("et1macaddr", buf, sizeof(buf)) >= 0)
  240. +
  241. + if (cfe_getenv("et1macaddr", buf, sizeof(buf)) >= 0 ||
  242. + nvram_getenv("et1macaddr", buf, sizeof(buf)) >= 0)
  243. str2eaddr(buf, iv->sprom.et1mac);
  244. - if (cfe_getenv("et0phyaddr", buf, sizeof(buf)) >= 0)
  245. - iv->sprom.et0phyaddr = simple_strtoul(buf, NULL, 10);
  246. - if (cfe_getenv("et1phyaddr", buf, sizeof(buf)) >= 0)
  247. - iv->sprom.et1phyaddr = simple_strtoul(buf, NULL, 10);
  248. - if (cfe_getenv("et0mdcport", buf, sizeof(buf)) >= 0)
  249. +
  250. + if (cfe_getenv("et0phyaddr", buf, sizeof(buf)) >= 0 ||
  251. + nvram_getenv("et0phyaddr", buf, sizeof(buf)) >= 0)
  252. + iv->sprom.et0phyaddr = simple_strtoul(buf, NULL, 0);
  253. +
  254. + if (cfe_getenv("et1phyaddr", buf, sizeof(buf)) >= 0 ||
  255. + nvram_getenv("et1phyaddr", buf, sizeof(buf)) >= 0)
  256. + iv->sprom.et1phyaddr = simple_strtoul(buf, NULL, 0);
  257. +
  258. + if (cfe_getenv("et0mdcport", buf, sizeof(buf)) >= 0 ||
  259. + nvram_getenv("et0mdcport", buf, sizeof(buf)) >= 0)
  260. iv->sprom.et0mdcport = simple_strtoul(buf, NULL, 10);
  261. - if (cfe_getenv("et1mdcport", buf, sizeof(buf)) >= 0)
  262. +
  263. + if (cfe_getenv("et1mdcport", buf, sizeof(buf)) >= 0 ||
  264. + nvram_getenv("et1mdcport", buf, sizeof(buf)) >= 0)
  265. iv->sprom.et1mdcport = simple_strtoul(buf, NULL, 10);
  266. return 0;
  267. diff -Nur linux-2.6.34.orig/arch/mips/include/asm/mach-bcm47xx/nvram.h linux-2.6.34/arch/mips/include/asm/mach-bcm47xx/nvram.h
  268. --- linux-2.6.34.orig/arch/mips/include/asm/mach-bcm47xx/nvram.h 1970-01-01 01:00:00.000000000 +0100
  269. +++ linux-2.6.34/arch/mips/include/asm/mach-bcm47xx/nvram.h 2010-06-03 22:38:03.501617275 +0200
  270. @@ -0,0 +1,35 @@
  271. +/*
  272. + * Copyright (C) 2005, Broadcom Corporation
  273. + * Copyright (C) 2006, Felix Fietkau <nbd@openwrt.org>
  274. + *
  275. + * This program is free software; you can redistribute it and/or modify it
  276. + * under the terms of the GNU General Public License as published by the
  277. + * Free Software Foundation; either version 2 of the License, or (at your
  278. + * option) any later version.
  279. + */
  280. +
  281. +#ifndef __NVRAM_H
  282. +#define __NVRAM_H
  283. +
  284. +struct nvram_header {
  285. + u32 magic;
  286. + u32 len;
  287. + u32 crc_ver_init; /* 0:7 crc, 8:15 ver, 16:31 sdram_init */
  288. + u32 config_refresh; /* 0:15 sdram_config, 16:31 sdram_refresh */
  289. + u32 config_ncdl; /* ncdl values for memc */
  290. +};
  291. +
  292. +#define NVRAM_HEADER 0x48534C46 /* 'FLSH' */
  293. +#define NVRAM_VERSION 1
  294. +#define NVRAM_HEADER_SIZE 20
  295. +#define NVRAM_SPACE 0x8000
  296. +#define NVRAM_FLASH_SIZE 0x20000
  297. +
  298. +#define FLASH_MIN 0x00020000 /* Minimum flash size */
  299. +
  300. +#define NVRAM_MAX_VALUE_LEN 255
  301. +#define NVRAM_MAX_PARAM_LEN 64
  302. +
  303. +int nvram_getenv(char *name, char *val, size_t val_len);
  304. +
  305. +#endif
  306. diff -Nur linux-2.6.34.orig/drivers/ssb/driver_mipscore.c linux-2.6.34/drivers/ssb/driver_mipscore.c
  307. --- linux-2.6.34.orig/drivers/ssb/driver_mipscore.c 2010-05-16 23:17:36.000000000 +0200
  308. +++ linux-2.6.34/drivers/ssb/driver_mipscore.c 2010-06-03 22:38:03.501617275 +0200
  309. @@ -193,7 +193,7 @@
  310. mcore->flash_buswidth = 2;
  311. if (bus->chipco.dev) {
  312. mcore->flash_window = 0x1c000000;
  313. - mcore->flash_window_size = 0x02000000;
  314. + mcore->flash_window_size = 0x00800000;
  315. if ((ssb_read32(bus->chipco.dev, SSB_CHIPCO_FLASH_CFG)
  316. & SSB_CHIPCO_CFG_DS16) == 0)
  317. mcore->flash_buswidth = 1;