| b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame] | 1 | From 25bf2b5836c892f091651d8a3384c9c57ce1b400 Mon Sep 17 00:00:00 2001 |
| 2 | From: Jonas Gorski <jogo@openwrt.org> |
| 3 | Date: Thu, 26 Jun 2014 12:51:00 +0200 |
| 4 | Subject: [PATCH 46/48] MIPS: BCM63XX: add support for matching the board_info |
| 5 | by dtb |
| 6 | |
| 7 | Allow using the passed dtb's compatible property to match board_info |
| 8 | structs instead of nvram's boardname field, which is not unique anyway. |
| 9 | |
| 10 | Signed-off-by: Jonas Gorski <jogo@openwrt.org> |
| 11 | --- |
| 12 | arch/mips/bcm63xx/boards/board_bcm963xx.c | 15 +++++++++++++++ |
| 13 | arch/mips/bcm63xx/boards/board_common.c | 18 ++++++++++++++++++ |
| 14 | arch/mips/bcm63xx/boards/board_common.h | 3 +++ |
| 15 | 3 files changed, 36 insertions(+) |
| 16 | |
| 17 | --- a/arch/mips/bcm63xx/boards/board_bcm963xx.c |
| 18 | +++ b/arch/mips/bcm63xx/boards/board_bcm963xx.c |
| 19 | @@ -692,6 +692,10 @@ static const struct board_info __initcon |
| 20 | #endif /* CONFIG_BCM63XX_CPU_6358 */ |
| 21 | }; |
| 22 | |
| 23 | +static struct of_device_id const bcm963xx_boards_dt[] = { |
| 24 | + { }, |
| 25 | +}; |
| 26 | + |
| 27 | /* |
| 28 | * early init callback, read nvram data from flash and checksum it |
| 29 | */ |
| 30 | @@ -703,6 +707,7 @@ void __init board_bcm963xx_init(void) |
| 31 | char *board_name = NULL; |
| 32 | u32 val; |
| 33 | struct bcm_hcs *hcs; |
| 34 | + const struct of_device_id *board_match; |
| 35 | |
| 36 | /* read base address of boot chip select (0) |
| 37 | * 6328/6362 do not have MPI but boot from a fixed address |
| 38 | @@ -746,6 +751,16 @@ void __init board_bcm963xx_init(void) |
| 39 | } else { |
| 40 | board_name = bcm63xx_nvram_get_name(); |
| 41 | } |
| 42 | + |
| 43 | + /* find board by compat */ |
| 44 | + board_match = bcm63xx_match_board(bcm963xx_boards_dt); |
| 45 | + if (board_match) { |
| 46 | + board_early_setup(board_match->data, |
| 47 | + bcm63xx_nvram_get_mac_address); |
| 48 | + |
| 49 | + return; |
| 50 | + } |
| 51 | + |
| 52 | /* find board by name */ |
| 53 | for (i = 0; i < ARRAY_SIZE(bcm963xx_boards); i++) { |
| 54 | if (strncmp(board_name, bcm963xx_boards[i]->name, 16)) |
| 55 | --- a/arch/mips/bcm63xx/boards/board_common.c |
| 56 | +++ b/arch/mips/bcm63xx/boards/board_common.c |
| 57 | @@ -239,3 +239,21 @@ int __init board_register_devices(void) |
| 58 | |
| 59 | return 0; |
| 60 | } |
| 61 | + |
| 62 | +const struct of_device_id * __init bcm63xx_match_board(const struct of_device_id *m) |
| 63 | +{ |
| 64 | + const struct of_device_id *match; |
| 65 | + unsigned long dt_root; |
| 66 | + |
| 67 | + if (!IS_ENABLED(CONFIG_OF) || !initial_boot_params) |
| 68 | + return NULL; |
| 69 | + |
| 70 | + dt_root = of_get_flat_dt_root(); |
| 71 | + |
| 72 | + for (match = m; match->compatible[0]; match++) { |
| 73 | + if (of_flat_dt_is_compatible(dt_root, match->compatible)) |
| 74 | + return match; |
| 75 | + } |
| 76 | + |
| 77 | + return NULL; |
| 78 | +} |
| 79 | --- a/arch/mips/bcm63xx/boards/board_common.h |
| 80 | +++ b/arch/mips/bcm63xx/boards/board_common.h |
| 81 | @@ -1,11 +1,14 @@ |
| 82 | #ifndef __BOARD_COMMON_H |
| 83 | #define __BOARD_COMMON_H |
| 84 | |
| 85 | +#include <linux/of.h> |
| 86 | #include <board_bcm963xx.h> |
| 87 | |
| 88 | void board_early_setup(const struct board_info *board, |
| 89 | int (*get_mac_address)(u8 mac[ETH_ALEN])); |
| 90 | |
| 91 | +const struct of_device_id *bcm63xx_match_board(const struct of_device_id *); |
| 92 | + |
| 93 | #if defined(CONFIG_BOARD_BCM963XX) |
| 94 | void board_bcm963xx_init(void); |
| 95 | #else |