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 --- a/arch/mips/bcm47xx/nvram.c
24 +++ b/arch/mips/bcm47xx/nvram.c
27 #include <linux/types.h>
28 #include <linux/module.h>
29 -#include <linux/ssb/ssb.h>
30 #include <linux/kernel.h>
31 #include <linux/string.h>
32 -#include <asm/addrspace.h>
33 +#include <linux/mtd/mtd.h>
34 #include <bcm47xx_nvram.h>
35 -#include <asm/mach-bcm47xx/bcm47xx.h>
37 static char nvram_buf[NVRAM_SPACE];
38 static const u32 nvram_sizes[] = {0x8000, 0xF000, 0x10000};
39 @@ -123,7 +121,43 @@ int bcm47xx_nvram_init_from_mem(u32 base
41 static int nvram_init(void)
43 - /* TODO: Look for MTD "nvram" partition */
45 + struct mtd_info *mtd;
46 + struct nvram_header header;
50 + mtd = get_mtd_device_nm("nvram");
54 + for (i = 0; i < ARRAY_SIZE(nvram_sizes); i++) {
55 + loff_t from = mtd->size - nvram_sizes[i];
60 + err = mtd_read(mtd, from, sizeof(header), &bytes_read,
61 + (uint8_t *)&header);
62 + if (!err && header.magic == NVRAM_HEADER) {
63 + u8 *dst = (uint8_t *)nvram_buf;
64 + size_t len = header.len;
66 + if (header.len > NVRAM_SPACE) {
67 + pr_err("nvram on flash (%i bytes) is bigger than the reserved space in memory, will just copy the first %i bytes\n",
68 + header.len, NVRAM_SPACE);
72 + err = mtd_read(mtd, from, len, &bytes_read, dst);
75 + memset(dst + bytes_read, 0x0, NVRAM_SPACE - bytes_read);