333d32c3f90641f400938db885976d63d14a65d3
[openwrt.git] / target / linux / bcm53xx / files / include / linux / bcm47xx_nvram.h
1 /*
2  *  Copyright (C) 2005, Broadcom Corporation
3  *  Copyright (C) 2006, Felix Fietkau <nbd@openwrt.org>
4  *  Copyright (C) 2014 Hauke Mehrtens <hauke@hauke-m.de>
5  *
6  *  This program is free software; you can redistribute  it and/or modify it
7  *  under  the terms of  the GNU General  Public License as published by the
8  *  Free Software Foundation;  either version 2 of the  License, or (at your
9  *  option) any later version.
10  */
11
12 #ifndef __BCM47XX_NVRAM_H
13 #define __BCM47XX_NVRAM_H
14
15 #include <linux/types.h>
16 #include <linux/kernel.h>
17
18 struct nvram_header {
19         u32 magic;
20         u32 len;
21         u32 crc_ver_init;       /* 0:7 crc, 8:15 ver, 16:31 sdram_init */
22         u32 config_refresh;     /* 0:15 sdram_config, 16:31 sdram_refresh */
23         u32 config_ncdl;        /* ncdl values for memc */
24 };
25
26 #define NVRAM_HEADER            0x48534C46      /* 'FLSH' */
27 #define NVRAM_VERSION           1
28 #define NVRAM_HEADER_SIZE       20
29 #define NVRAM_SPACE             0x8000
30
31 #define FLASH_MIN               0x00020000      /* Minimum flash size */
32
33 #define NVRAM_MAX_VALUE_LEN 255
34 #define NVRAM_MAX_PARAM_LEN 64
35
36 #ifdef CONFIG_BCM47XX
37 int bcm47xx_nvram_getenv(const char *name, char *val, size_t val_len);
38
39 int bcm47xx_nvram_gpio_pin(const char *name);
40 #else
41 static inline int bcm47xx_nvram_getenv(const char *name, char *val,
42                                        size_t val_len)
43 {
44         return -ENXIO;
45 }
46
47 static inline int bcm47xx_nvram_gpio_pin(const char *name)
48 {
49         return -ENXIO;
50 }
51 #endif
52
53 static inline void bcm47xx_nvram_parse_macaddr(char *buf, u8 macaddr[6])
54 {
55         if (strchr(buf, ':'))
56                 sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &macaddr[0],
57                         &macaddr[1], &macaddr[2], &macaddr[3], &macaddr[4],
58                         &macaddr[5]);
59         else if (strchr(buf, '-'))
60                 sscanf(buf, "%hhx-%hhx-%hhx-%hhx-%hhx-%hhx", &macaddr[0],
61                         &macaddr[1], &macaddr[2], &macaddr[3], &macaddr[4],
62                         &macaddr[5]);
63         else
64                 pr_warn("Can not parse mac address: %s\n", buf);
65 }
66 #endif /* __BCM47XX_NVRAM_H */