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
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
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.
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>
20 arch/mips/bcm47xx/nvram.c | 42 ++++++++++++++++++++++++++++++++++++++----
21 1 file changed, 38 insertions(+), 4 deletions(-)
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
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>
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)
43 static int nvram_init(void)
45 - /* TODO: Look for MTD "nvram" partition */
47 + struct mtd_info *mtd;
48 + struct nvram_header header;
52 + mtd = get_mtd_device_nm("nvram");
56 + for (i = 0; i < ARRAY_SIZE(nvram_sizes); i++) {
57 + loff_t from = mtd->size - nvram_sizes[i];
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;
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);
74 + err = mtd_read(mtd, from, len, &bytes_read, dst);
77 + memset(dst + bytes_read, 0x0, NVRAM_SPACE - bytes_read);