gpio: ts4800: Drop redundant code to set already initialized gpio_chip fields
[linux-2.6/btrfs-unstable.git] / arch / mips / bcm63xx / nvram.c
blob5f2bc1e10eae60c314663685f0e7dbdd84757ad3
1 /*
2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
4 * for more details.
6 * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
7 * Copyright (C) 2008 Florian Fainelli <florian@openwrt.org>
8 * Copyright (C) 2012 Jonas Gorski <jonas.gorski@gmail.com>
9 */
11 #define pr_fmt(fmt) "bcm63xx_nvram: " fmt
13 #include <linux/bcm963xx_nvram.h>
14 #include <linux/init.h>
15 #include <linux/crc32.h>
16 #include <linux/export.h>
17 #include <linux/kernel.h>
18 #include <linux/if_ether.h>
20 #include <bcm63xx_nvram.h>
22 static struct bcm963xx_nvram nvram;
23 static int mac_addr_used;
25 void __init bcm63xx_nvram_init(void *addr)
27 u32 crc, expected_crc;
28 u8 hcs_mac_addr[ETH_ALEN] = { 0x00, 0x10, 0x18, 0xff, 0xff, 0xff };
30 /* extract nvram data */
31 memcpy(&nvram, addr, BCM963XX_NVRAM_V5_SIZE);
33 /* check checksum before using data */
34 if (bcm963xx_nvram_checksum(&nvram, &expected_crc, &crc))
35 pr_warn("nvram checksum failed, contents may be invalid (expected %08x, got %08x)\n",
36 expected_crc, crc);
38 /* Cable modems have a different NVRAM which is embedded in the eCos
39 * firmware and not easily extractible, give at least a MAC address
40 * pool.
42 if (BCMCPU_IS_3368()) {
43 memcpy(nvram.mac_addr_base, hcs_mac_addr, ETH_ALEN);
44 nvram.mac_addr_count = 2;
48 u8 *bcm63xx_nvram_get_name(void)
50 return nvram.name;
52 EXPORT_SYMBOL(bcm63xx_nvram_get_name);
54 int bcm63xx_nvram_get_mac_address(u8 *mac)
56 u8 *oui;
57 int count;
59 if (mac_addr_used >= nvram.mac_addr_count) {
60 pr_err("not enough mac addresses\n");
61 return -ENODEV;
64 memcpy(mac, nvram.mac_addr_base, ETH_ALEN);
65 oui = mac + ETH_ALEN/2 - 1;
66 count = mac_addr_used;
68 while (count--) {
69 u8 *p = mac + ETH_ALEN - 1;
71 do {
72 (*p)++;
73 if (*p != 0)
74 break;
75 p--;
76 } while (p != oui);
78 if (p == oui) {
79 pr_err("unable to fetch mac address\n");
80 return -ENODEV;
84 mac_addr_used++;
85 return 0;
87 EXPORT_SYMBOL(bcm63xx_nvram_get_mac_address);