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/clk-provider.h>
9 #include <linux/clocksource.h>
10 #include <linux/init.h>
12 #include <linux/irqchip.h>
13 #include <linux/kernel.h>
14 #include <linux/libfdt.h>
15 #include <linux/of_fdt.h>
17 #include <linux/suspend.h>
19 #include <asm/bootinfo.h>
20 #include <asm/fw/fw.h>
22 #include <asm/reboot.h>
24 #define JZ4740_EMC_BASE_ADDR 0x13010000
26 #define JZ4740_EMC_SDRAM_CTRL 0x80
28 static void __init jz4740_detect_mem(void)
30 void __iomem *jz_emc_base;
31 u32 ctrl, bus, bank, rows, cols;
34 jz_emc_base = ioremap(JZ4740_EMC_BASE_ADDR, 0x100);
35 ctrl = readl(jz_emc_base + JZ4740_EMC_SDRAM_CTRL);
36 bus = 2 - ((ctrl >> 31) & 1);
37 bank = 1 + ((ctrl >> 19) & 1);
38 cols = 8 + ((ctrl >> 26) & 7);
39 rows = 11 + ((ctrl >> 20) & 3);
41 "SDRAM preconfigured: bus:%u bank:%u rows:%u cols:%u\n",
42 bus, bank, rows, cols);
45 size = 1 << (bus + bank + cols + rows);
46 add_memory_region(0, size, BOOT_MEM_RAM);
49 static unsigned long __init get_board_mach_type(const void *fdt)
51 if (!fdt_node_check_compatible(fdt, 0, "ingenic,x1830"))
52 return MACH_INGENIC_X1830;
53 if (!fdt_node_check_compatible(fdt, 0, "ingenic,x1000"))
54 return MACH_INGENIC_X1000;
55 if (!fdt_node_check_compatible(fdt, 0, "ingenic,jz4780"))
56 return MACH_INGENIC_JZ4780;
57 if (!fdt_node_check_compatible(fdt, 0, "ingenic,jz4770"))
58 return MACH_INGENIC_JZ4770;
60 return MACH_INGENIC_JZ4740;
63 void __init plat_mem_setup(void)
68 if (__dtb_start != __dtb_end)
71 dtb = (void *)fw_passed_dtb;
75 offset = fdt_path_offset(dtb, "/memory");
79 mips_machtype = get_board_mach_type(dtb);
82 void __init device_tree_init(void)
84 if (!initial_boot_params)
87 unflatten_and_copy_device_tree();
90 const char *get_system_type(void)
92 switch (mips_machtype) {
93 case MACH_INGENIC_X1830:
95 case MACH_INGENIC_X1000:
97 case MACH_INGENIC_JZ4780:
99 case MACH_INGENIC_JZ4770:
106 void __init arch_init_irq(void)
111 void __init plat_time_init(void)
117 void __init prom_init(void)
122 void __init prom_free_prom_memory(void)
126 static void jz4740_wait_instr(void)
128 __asm__(".set push;\n"
135 static void jz4740_halt(void)
141 static int __maybe_unused jz4740_pm_enter(suspend_state_t state)
148 static const struct platform_suspend_ops jz4740_pm_ops __maybe_unused = {
149 .valid = suspend_valid_only_mem,
150 .enter = jz4740_pm_enter,
153 static int __init jz4740_pm_init(void)
155 if (IS_ENABLED(CONFIG_PM_SLEEP))
156 suspend_set_ops(&jz4740_pm_ops);
157 _machine_halt = jz4740_halt;
162 late_initcall(jz4740_pm_init);