brcm47xx: group MIPS BCM47XX backported patches by source kernel
[openwrt/svn-archive/archive.git] / target / linux / brcm47xx / patches-3.18 / 030-06-MIPS-BCM47XX-Use-mtd-as-an-alternative-way-API-to-ge.patch
1 From 9d1d08646af4491aec41d40341930b9bfd62ffa9 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
3 Date: Wed, 29 Oct 2014 10:05:06 +0100
4 Subject: [PATCH] MIPS: BCM47XX: Use mtd as an alternative way/API to get NVRAM
5 content
6 MIME-Version: 1.0
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
9
10 NVRAM can be read using magic memory offset, but after all it's just a
11 flash partition. On platforms where NVRAM isn't needed early we can get
12 it using mtd subsystem.
13
14 Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
15 Acked-by: Hauke Mehrtens <hauke@hauke-m.de>
16 Cc: linux-mips@linux-mips.org
17 Patchwork: https://patchwork.linux-mips.org/patch/8266/
18 Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
19 ---
20 arch/mips/bcm47xx/nvram.c | 42 ++++++++++++++++++++++++++++++++++++++----
21 1 file changed, 38 insertions(+), 4 deletions(-)
22
23 diff --git a/arch/mips/bcm47xx/nvram.c b/arch/mips/bcm47xx/nvram.c
24 index 21712fb..8b64991 100644
25 --- a/arch/mips/bcm47xx/nvram.c
26 +++ b/arch/mips/bcm47xx/nvram.c
27 @@ -13,12 +13,10 @@
28
29 #include <linux/types.h>
30 #include <linux/module.h>
31 -#include <linux/ssb/ssb.h>
32 #include <linux/kernel.h>
33 #include <linux/string.h>
34 -#include <asm/addrspace.h>
35 +#include <linux/mtd/mtd.h>
36 #include <bcm47xx_nvram.h>
37 -#include <asm/mach-bcm47xx/bcm47xx.h>
38
39 static char nvram_buf[NVRAM_SPACE];
40 static const u32 nvram_sizes[] = {0x8000, 0xF000, 0x10000};
41 @@ -123,7 +121,43 @@ int bcm47xx_nvram_init_from_mem(u32 base, u32 lim)
42
43 static int nvram_init(void)
44 {
45 - /* TODO: Look for MTD "nvram" partition */
46 +#ifdef CONFIG_MTD
47 + struct mtd_info *mtd;
48 + struct nvram_header header;
49 + size_t bytes_read;
50 + int err, i;
51 +
52 + mtd = get_mtd_device_nm("nvram");
53 + if (IS_ERR(mtd))
54 + return -ENODEV;
55 +
56 + for (i = 0; i < ARRAY_SIZE(nvram_sizes); i++) {
57 + loff_t from = mtd->size - nvram_sizes[i];
58 +
59 + if (from < 0)
60 + continue;
61 +
62 + err = mtd_read(mtd, from, sizeof(header), &bytes_read,
63 + (uint8_t *)&header);
64 + if (!err && header.magic == NVRAM_HEADER) {
65 + u8 *dst = (uint8_t *)nvram_buf;
66 + size_t len = header.len;
67 +
68 + if (header.len > NVRAM_SPACE) {
69 + pr_err("nvram on flash (%i bytes) is bigger than the reserved space in memory, will just copy the first %i bytes\n",
70 + header.len, NVRAM_SPACE);
71 + len = NVRAM_SPACE;
72 + }
73 +
74 + err = mtd_read(mtd, from, len, &bytes_read, dst);
75 + if (err)
76 + return err;
77 + memset(dst + bytes_read, 0x0, NVRAM_SPACE - bytes_read);
78 +
79 + return 0;
80 + }
81 + }
82 +#endif
83
84 return -ENXIO;
85 }
86 --
87 1.8.4.5
88