diff options
author | Jonas Gorski <jonas.gorski@gmail.com> | 2012-11-07 03:25:28 -0500 |
---|---|---|
committer | John Crispin <blogic@openwrt.org> | 2012-11-09 05:37:18 -0500 |
commit | e7e333cb22e5e34e7a0792f262df52026815662e (patch) | |
tree | cad138b38d58b55f72106a50f0cba7eebb3148ef /arch/mips/bcm63xx/boards | |
parent | ba00e2e5c24f447fb09437a99df697787103f0cd (diff) |
MIPS: BCM63XX: move nvram functions into their own file
Refactor nvram related functions into its own unit for easier expansion
and exposure of the values to other drivers.
Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
Patchwork: http://patchwork.linux-mips.org/patch/4516
Signed-off-by: John Crispin <blogic@openwrt.org>
Diffstat (limited to 'arch/mips/bcm63xx/boards')
-rw-r--r-- | arch/mips/bcm63xx/boards/board_bcm963xx.c | 71 |
1 files changed, 11 insertions, 60 deletions
diff --git a/arch/mips/bcm63xx/boards/board_bcm963xx.c b/arch/mips/bcm63xx/boards/board_bcm963xx.c index 1cd4d73f23c7..73be9b349690 100644 --- a/arch/mips/bcm63xx/boards/board_bcm963xx.c +++ b/arch/mips/bcm63xx/boards/board_bcm963xx.c | |||
@@ -18,6 +18,7 @@ | |||
18 | #include <bcm63xx_dev_uart.h> | 18 | #include <bcm63xx_dev_uart.h> |
19 | #include <bcm63xx_regs.h> | 19 | #include <bcm63xx_regs.h> |
20 | #include <bcm63xx_io.h> | 20 | #include <bcm63xx_io.h> |
21 | #include <bcm63xx_nvram.h> | ||
21 | #include <bcm63xx_dev_pci.h> | 22 | #include <bcm63xx_dev_pci.h> |
22 | #include <bcm63xx_dev_enet.h> | 23 | #include <bcm63xx_dev_enet.h> |
23 | #include <bcm63xx_dev_dsp.h> | 24 | #include <bcm63xx_dev_dsp.h> |
@@ -29,8 +30,6 @@ | |||
29 | 30 | ||
30 | #define PFX "board_bcm963xx: " | 31 | #define PFX "board_bcm963xx: " |
31 | 32 | ||
32 | static struct bcm963xx_nvram nvram; | ||
33 | static unsigned int mac_addr_used; | ||
34 | static struct board_info board; | 33 | static struct board_info board; |
35 | 34 | ||
36 | /* | 35 | /* |
@@ -716,50 +715,14 @@ const char *board_get_name(void) | |||
716 | } | 715 | } |
717 | 716 | ||
718 | /* | 717 | /* |
719 | * register & return a new board mac address | ||
720 | */ | ||
721 | static int board_get_mac_address(u8 *mac) | ||
722 | { | ||
723 | u8 *oui; | ||
724 | int count; | ||
725 | |||
726 | if (mac_addr_used >= nvram.mac_addr_count) { | ||
727 | printk(KERN_ERR PFX "not enough mac address\n"); | ||
728 | return -ENODEV; | ||
729 | } | ||
730 | |||
731 | memcpy(mac, nvram.mac_addr_base, ETH_ALEN); | ||
732 | oui = mac + ETH_ALEN/2 - 1; | ||
733 | count = mac_addr_used; | ||
734 | |||
735 | while (count--) { | ||
736 | u8 *p = mac + ETH_ALEN - 1; | ||
737 | |||
738 | do { | ||
739 | (*p)++; | ||
740 | if (*p != 0) | ||
741 | break; | ||
742 | p--; | ||
743 | } while (p != oui); | ||
744 | |||
745 | if (p == oui) { | ||
746 | printk(KERN_ERR PFX "unable to fetch mac address\n"); | ||
747 | return -ENODEV; | ||
748 | } | ||
749 | } | ||
750 | |||
751 | mac_addr_used++; | ||
752 | return 0; | ||
753 | } | ||
754 | |||
755 | /* | ||
756 | * early init callback, read nvram data from flash and checksum it | 718 | * early init callback, read nvram data from flash and checksum it |
757 | */ | 719 | */ |
758 | void __init board_prom_init(void) | 720 | void __init board_prom_init(void) |
759 | { | 721 | { |
760 | unsigned int check_len, i; | 722 | unsigned int i; |
761 | u8 *boot_addr, *cfe, *p; | 723 | u8 *boot_addr, *cfe; |
762 | char cfe_version[32]; | 724 | char cfe_version[32]; |
725 | char *board_name; | ||
763 | u32 val; | 726 | u32 val; |
764 | 727 | ||
765 | /* read base address of boot chip select (0) | 728 | /* read base address of boot chip select (0) |
@@ -782,27 +745,15 @@ void __init board_prom_init(void) | |||
782 | strcpy(cfe_version, "unknown"); | 745 | strcpy(cfe_version, "unknown"); |
783 | printk(KERN_INFO PFX "CFE version: %s\n", cfe_version); | 746 | printk(KERN_INFO PFX "CFE version: %s\n", cfe_version); |
784 | 747 | ||
785 | /* extract nvram data */ | 748 | if (bcm63xx_nvram_init(boot_addr + BCM963XX_NVRAM_OFFSET)) { |
786 | memcpy(&nvram, boot_addr + BCM963XX_NVRAM_OFFSET, sizeof(nvram)); | ||
787 | |||
788 | /* check checksum before using data */ | ||
789 | if (nvram.version <= 4) | ||
790 | check_len = offsetof(struct bcm963xx_nvram, checksum_old); | ||
791 | else | ||
792 | check_len = sizeof(nvram); | ||
793 | val = 0; | ||
794 | p = (u8 *)&nvram; | ||
795 | while (check_len--) | ||
796 | val += *p; | ||
797 | if (val) { | ||
798 | printk(KERN_ERR PFX "invalid nvram checksum\n"); | 749 | printk(KERN_ERR PFX "invalid nvram checksum\n"); |
799 | return; | 750 | return; |
800 | } | 751 | } |
801 | 752 | ||
753 | board_name = bcm63xx_nvram_get_name(); | ||
802 | /* find board by name */ | 754 | /* find board by name */ |
803 | for (i = 0; i < ARRAY_SIZE(bcm963xx_boards); i++) { | 755 | for (i = 0; i < ARRAY_SIZE(bcm963xx_boards); i++) { |
804 | if (strncmp(nvram.name, bcm963xx_boards[i]->name, | 756 | if (strncmp(board_name, bcm963xx_boards[i]->name, 16)) |
805 | sizeof(nvram.name))) | ||
806 | continue; | 757 | continue; |
807 | /* copy, board desc array is marked initdata */ | 758 | /* copy, board desc array is marked initdata */ |
808 | memcpy(&board, bcm963xx_boards[i], sizeof(board)); | 759 | memcpy(&board, bcm963xx_boards[i], sizeof(board)); |
@@ -812,7 +763,7 @@ void __init board_prom_init(void) | |||
812 | /* bail out if board is not found, will complain later */ | 763 | /* bail out if board is not found, will complain later */ |
813 | if (!board.name[0]) { | 764 | if (!board.name[0]) { |
814 | char name[17]; | 765 | char name[17]; |
815 | memcpy(name, nvram.name, 16); | 766 | memcpy(name, board_name, 16); |
816 | name[16] = 0; | 767 | name[16] = 0; |
817 | printk(KERN_ERR PFX "unknown bcm963xx board: %s\n", | 768 | printk(KERN_ERR PFX "unknown bcm963xx board: %s\n", |
818 | name); | 769 | name); |
@@ -890,11 +841,11 @@ int __init board_register_devices(void) | |||
890 | bcm63xx_pcmcia_register(); | 841 | bcm63xx_pcmcia_register(); |
891 | 842 | ||
892 | if (board.has_enet0 && | 843 | if (board.has_enet0 && |
893 | !board_get_mac_address(board.enet0.mac_addr)) | 844 | !bcm63xx_nvram_get_mac_address(board.enet0.mac_addr)) |
894 | bcm63xx_enet_register(0, &board.enet0); | 845 | bcm63xx_enet_register(0, &board.enet0); |
895 | 846 | ||
896 | if (board.has_enet1 && | 847 | if (board.has_enet1 && |
897 | !board_get_mac_address(board.enet1.mac_addr)) | 848 | !bcm63xx_nvram_get_mac_address(board.enet1.mac_addr)) |
898 | bcm63xx_enet_register(1, &board.enet1); | 849 | bcm63xx_enet_register(1, &board.enet1); |
899 | 850 | ||
900 | if (board.has_usbd) | 851 | if (board.has_usbd) |
@@ -907,7 +858,7 @@ int __init board_register_devices(void) | |||
907 | * do this after registering enet devices | 858 | * do this after registering enet devices |
908 | */ | 859 | */ |
909 | #ifdef CONFIG_SSB_PCIHOST | 860 | #ifdef CONFIG_SSB_PCIHOST |
910 | if (!board_get_mac_address(bcm63xx_sprom.il0mac)) { | 861 | if (!bcm63xx_nvram_get_mac_address(bcm63xx_sprom.il0mac)) { |
911 | memcpy(bcm63xx_sprom.et0mac, bcm63xx_sprom.il0mac, ETH_ALEN); | 862 | memcpy(bcm63xx_sprom.et0mac, bcm63xx_sprom.il0mac, ETH_ALEN); |
912 | memcpy(bcm63xx_sprom.et1mac, bcm63xx_sprom.il0mac, ETH_ALEN); | 863 | memcpy(bcm63xx_sprom.et1mac, bcm63xx_sprom.il0mac, ETH_ALEN); |
913 | if (ssb_arch_register_fallback_sprom( | 864 | if (ssb_arch_register_fallback_sprom( |