1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2011 Andes Technology Corporation
4  * Shawn Lin, Andes Technology Corporation <nobuhiro@andestech.com>
5  * Macpaul Lin, Andes Technology Corporation <macpaul@andestech.com>
6  */
7 
8 #include <common.h>
9 #include <flash.h>
10 #include <init.h>
11 #include <net.h>
12 #if defined(CONFIG_FTMAC100) && !defined(CONFIG_DM_ETH)
13 #include <netdev.h>
14 #endif
15 #include <asm/global_data.h>
16 #include <linux/io.h>
17 #include <asm/io.h>
18 #include <asm/mach-types.h>
19 
20 #include <faraday/ftsmc020.h>
21 
22 DECLARE_GLOBAL_DATA_PTR;
23 
24 /*
25  * Miscellaneous platform dependent initializations
26  */
27 
board_init(void)28 int board_init(void)
29 {
30 	/*
31 	 * refer to BOOT_PARAMETER_PA_BASE within
32 	 * "linux/arch/nds32/include/asm/misc_spec.h"
33 	 */
34 	printf("Board: %s\n" , CONFIG_SYS_BOARD);
35 	gd->bd->bi_arch_number = MACH_TYPE_ADPAG101P;
36 	gd->bd->bi_boot_params = PHYS_SDRAM_0 + 0x400;
37 
38 	return 0;
39 }
40 
dram_init(void)41 int dram_init(void)
42 {
43 	unsigned long sdram_base = PHYS_SDRAM_0;
44 	unsigned long expected_size = PHYS_SDRAM_0_SIZE + PHYS_SDRAM_1_SIZE;
45 	unsigned long actual_size;
46 
47 	actual_size = get_ram_size((void *)sdram_base, expected_size);
48 
49 	gd->ram_size = actual_size;
50 
51 	if (expected_size != actual_size) {
52 		printf("Warning: Only %lu of %lu MiB SDRAM is working\n",
53 				actual_size >> 20, expected_size >> 20);
54 	}
55 
56 	return 0;
57 }
58 
dram_init_banksize(void)59 int dram_init_banksize(void)
60 {
61 	gd->bd->bi_dram[0].start = PHYS_SDRAM_0;
62 	gd->bd->bi_dram[0].size =  PHYS_SDRAM_0_SIZE;
63 	gd->bd->bi_dram[1].start = PHYS_SDRAM_1;
64 	gd->bd->bi_dram[1].size =  PHYS_SDRAM_1_SIZE;
65 
66 	return 0;
67 }
68 
69 #if defined(CONFIG_FTMAC100) && !defined(CONFIG_DM_ETH)
board_eth_init(struct bd_info * bd)70 int board_eth_init(struct bd_info *bd)
71 {
72 	return ftmac100_initialize(bd);
73 }
74 #endif
75 
board_flash_get_legacy(ulong base,int banknum,flash_info_t * info)76 ulong board_flash_get_legacy(ulong base, int banknum, flash_info_t *info)
77 {
78 	if (banknum == 0) {	/* non-CFI boot flash */
79 		info->portwidth = FLASH_CFI_8BIT;
80 		info->chipwidth = FLASH_CFI_BY8;
81 		info->interface = FLASH_CFI_X8;
82 		return 1;
83 	} else {
84 		return 0;
85 	}
86 }
87