030-07-MIPS-BCM47XX-Clean-up-nvram-header.patch 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. From 341097f17c76b3dd39539526a2af9e7fff43705e Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
  3. Date: Thu, 30 Oct 2014 12:50:03 +0100
  4. Subject: [PATCH] MIPS: BCM47XX: Clean up nvram header
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. 1) Move private defines to the .c file
  9. 2) Move SPROM helper to the sprom.c
  10. 3) Drop unused code
  11. 4) Rename magic to the NVRAM_MAGIC
  12. 5) Add const to the char pointer we never modify
  13. Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
  14. Acked-by: Hauke Mehrtens <hauke@hauke-m.de>
  15. Cc: linux-mips@linux-mips.org
  16. Patchwork: https://patchwork.linux-mips.org/patch/8289/
  17. Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
  18. ---
  19. arch/mips/bcm47xx/nvram.c | 23 ++++++++++----
  20. arch/mips/bcm47xx/sprom.c | 14 +++++++++
  21. arch/mips/include/asm/mach-bcm47xx/bcm47xx_nvram.h | 35 +---------------------
  22. 3 files changed, 33 insertions(+), 39 deletions(-)
  23. --- a/arch/mips/bcm47xx/nvram.c
  24. +++ b/arch/mips/bcm47xx/nvram.c
  25. @@ -18,6 +18,19 @@
  26. #include <linux/mtd/mtd.h>
  27. #include <bcm47xx_nvram.h>
  28. +#define NVRAM_MAGIC 0x48534C46 /* 'FLSH' */
  29. +#define NVRAM_SPACE 0x8000
  30. +
  31. +#define FLASH_MIN 0x00020000 /* Minimum flash size */
  32. +
  33. +struct nvram_header {
  34. + u32 magic;
  35. + u32 len;
  36. + u32 crc_ver_init; /* 0:7 crc, 8:15 ver, 16:31 sdram_init */
  37. + u32 config_refresh; /* 0:15 sdram_config, 16:31 sdram_refresh */
  38. + u32 config_ncdl; /* ncdl values for memc */
  39. +};
  40. +
  41. static char nvram_buf[NVRAM_SPACE];
  42. static const u32 nvram_sizes[] = {0x8000, 0xF000, 0x10000};
  43. @@ -28,7 +41,7 @@ static u32 find_nvram_size(void __iomem
  44. for (i = 0; i < ARRAY_SIZE(nvram_sizes); i++) {
  45. header = (struct nvram_header *)(end - nvram_sizes[i]);
  46. - if (header->magic == NVRAM_HEADER)
  47. + if (header->magic == NVRAM_MAGIC)
  48. return nvram_sizes[i];
  49. }
  50. @@ -63,13 +76,13 @@ static int nvram_find_and_copy(void __io
  51. /* Try embedded NVRAM at 4 KB and 1 KB as last resorts */
  52. header = (struct nvram_header *)(iobase + 4096);
  53. - if (header->magic == NVRAM_HEADER) {
  54. + if (header->magic == NVRAM_MAGIC) {
  55. size = NVRAM_SPACE;
  56. goto found;
  57. }
  58. header = (struct nvram_header *)(iobase + 1024);
  59. - if (header->magic == NVRAM_HEADER) {
  60. + if (header->magic == NVRAM_MAGIC) {
  61. size = NVRAM_SPACE;
  62. goto found;
  63. }
  64. @@ -139,7 +152,7 @@ static int nvram_init(void)
  65. err = mtd_read(mtd, from, sizeof(header), &bytes_read,
  66. (uint8_t *)&header);
  67. - if (!err && header.magic == NVRAM_HEADER) {
  68. + if (!err && header.magic == NVRAM_MAGIC) {
  69. u8 *dst = (uint8_t *)nvram_buf;
  70. size_t len = header.len;
  71. @@ -162,7 +175,7 @@ static int nvram_init(void)
  72. return -ENXIO;
  73. }
  74. -int bcm47xx_nvram_getenv(char *name, char *val, size_t val_len)
  75. +int bcm47xx_nvram_getenv(const char *name, char *val, size_t val_len)
  76. {
  77. char *var, *value, *end, *eq;
  78. int err;
  79. --- a/arch/mips/bcm47xx/sprom.c
  80. +++ b/arch/mips/bcm47xx/sprom.c
  81. @@ -136,6 +136,20 @@ static void nvram_read_leddc(const char
  82. *leddc_off_time = (val >> 16) & 0xff;
  83. }
  84. +static void bcm47xx_nvram_parse_macaddr(char *buf, u8 macaddr[6])
  85. +{
  86. + if (strchr(buf, ':'))
  87. + sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &macaddr[0],
  88. + &macaddr[1], &macaddr[2], &macaddr[3], &macaddr[4],
  89. + &macaddr[5]);
  90. + else if (strchr(buf, '-'))
  91. + sscanf(buf, "%hhx-%hhx-%hhx-%hhx-%hhx-%hhx", &macaddr[0],
  92. + &macaddr[1], &macaddr[2], &macaddr[3], &macaddr[4],
  93. + &macaddr[5]);
  94. + else
  95. + pr_warn("Can not parse mac address: %s\n", buf);
  96. +}
  97. +
  98. static void nvram_read_macaddr(const char *prefix, const char *name,
  99. u8 val[6], bool fallback)
  100. {
  101. --- a/arch/mips/include/asm/mach-bcm47xx/bcm47xx_nvram.h
  102. +++ b/arch/mips/include/asm/mach-bcm47xx/bcm47xx_nvram.h
  103. @@ -14,41 +14,8 @@
  104. #include <linux/types.h>
  105. #include <linux/kernel.h>
  106. -struct nvram_header {
  107. - u32 magic;
  108. - u32 len;
  109. - u32 crc_ver_init; /* 0:7 crc, 8:15 ver, 16:31 sdram_init */
  110. - u32 config_refresh; /* 0:15 sdram_config, 16:31 sdram_refresh */
  111. - u32 config_ncdl; /* ncdl values for memc */
  112. -};
  113. -
  114. -#define NVRAM_HEADER 0x48534C46 /* 'FLSH' */
  115. -#define NVRAM_VERSION 1
  116. -#define NVRAM_HEADER_SIZE 20
  117. -#define NVRAM_SPACE 0x8000
  118. -
  119. -#define FLASH_MIN 0x00020000 /* Minimum flash size */
  120. -
  121. -#define NVRAM_MAX_VALUE_LEN 255
  122. -#define NVRAM_MAX_PARAM_LEN 64
  123. -
  124. int bcm47xx_nvram_init_from_mem(u32 base, u32 lim);
  125. -extern int bcm47xx_nvram_getenv(char *name, char *val, size_t val_len);
  126. -
  127. -static inline void bcm47xx_nvram_parse_macaddr(char *buf, u8 macaddr[6])
  128. -{
  129. - if (strchr(buf, ':'))
  130. - sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &macaddr[0],
  131. - &macaddr[1], &macaddr[2], &macaddr[3], &macaddr[4],
  132. - &macaddr[5]);
  133. - else if (strchr(buf, '-'))
  134. - sscanf(buf, "%hhx-%hhx-%hhx-%hhx-%hhx-%hhx", &macaddr[0],
  135. - &macaddr[1], &macaddr[2], &macaddr[3], &macaddr[4],
  136. - &macaddr[5]);
  137. - else
  138. - printk(KERN_WARNING "Can not parse mac address: %s\n", buf);
  139. -}
  140. -
  141. +int bcm47xx_nvram_getenv(const char *name, char *val, size_t val_len);
  142. int bcm47xx_nvram_gpio_pin(const char *name);
  143. #endif /* __BCM47XX_NVRAM_H */