1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de>
4 * Copyright (C) 2011, Maarten ter Huurne <maarten@treewalker.org>
8 #include <linux/init.h>
10 #include <linux/irqchip.h>
11 #include <linux/kernel.h>
12 #include <linux/libfdt.h>
13 #include <linux/of_fdt.h>
15 #include <asm/bootinfo.h>
20 #define JZ4740_EMC_BASE_ADDR 0x13010000
22 #define JZ4740_EMC_SDRAM_CTRL 0x80
24 static void __init
jz4740_detect_mem(void)
26 void __iomem
*jz_emc_base
;
27 u32 ctrl
, bus
, bank
, rows
, cols
;
30 jz_emc_base
= ioremap(JZ4740_EMC_BASE_ADDR
, 0x100);
31 ctrl
= readl(jz_emc_base
+ JZ4740_EMC_SDRAM_CTRL
);
32 bus
= 2 - ((ctrl
>> 31) & 1);
33 bank
= 1 + ((ctrl
>> 19) & 1);
34 cols
= 8 + ((ctrl
>> 26) & 7);
35 rows
= 11 + ((ctrl
>> 20) & 3);
37 "SDRAM preconfigured: bus:%u bank:%u rows:%u cols:%u\n",
38 bus
, bank
, rows
, cols
);
41 size
= 1 << (bus
+ bank
+ cols
+ rows
);
42 add_memory_region(0, size
, BOOT_MEM_RAM
);
45 static unsigned long __init
get_board_mach_type(const void *fdt
)
47 if (!fdt_node_check_compatible(fdt
, 0, "ingenic,x1830"))
48 return MACH_INGENIC_X1830
;
49 if (!fdt_node_check_compatible(fdt
, 0, "ingenic,x1000"))
50 return MACH_INGENIC_X1000
;
51 if (!fdt_node_check_compatible(fdt
, 0, "ingenic,jz4780"))
52 return MACH_INGENIC_JZ4780
;
53 if (!fdt_node_check_compatible(fdt
, 0, "ingenic,jz4770"))
54 return MACH_INGENIC_JZ4770
;
56 return MACH_INGENIC_JZ4740
;
59 void __init
plat_mem_setup(void)
66 if (__dtb_start
!= __dtb_end
)
69 dtb
= (void *)fw_passed_dtb
;
73 offset
= fdt_path_offset(dtb
, "/memory");
77 mips_machtype
= get_board_mach_type(dtb
);
80 void __init
device_tree_init(void)
82 if (!initial_boot_params
)
85 unflatten_and_copy_device_tree();
88 const char *get_system_type(void)
90 switch (mips_machtype
) {
91 case MACH_INGENIC_X1830
:
93 case MACH_INGENIC_X1000
:
95 case MACH_INGENIC_JZ4780
:
97 case MACH_INGENIC_JZ4770
:
104 void __init
arch_init_irq(void)