Linux 5.7.6
[linux/fpc-iii.git] / arch / mips / jz4740 / setup.c
blob880c26857affb1f16f2fcfe95775409bcb4513a4
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de>
4 * Copyright (C) 2011, Maarten ter Huurne <maarten@treewalker.org>
5 * JZ4740 setup code
6 */
8 #include <linux/init.h>
9 #include <linux/io.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>
16 #include <asm/prom.h>
18 #include "reset.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;
28 phys_addr_t size;
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);
36 printk(KERN_DEBUG
37 "SDRAM preconfigured: bus:%u bank:%u rows:%u cols:%u\n",
38 bus, bank, rows, cols);
39 iounmap(jz_emc_base);
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)
61 int offset;
62 void *dtb;
64 jz4740_reset_init();
66 if (__dtb_start != __dtb_end)
67 dtb = __dtb_start;
68 else
69 dtb = (void *)fw_passed_dtb;
71 __dt_setup_arch(dtb);
73 offset = fdt_path_offset(dtb, "/memory");
74 if (offset < 0)
75 jz4740_detect_mem();
77 mips_machtype = get_board_mach_type(dtb);
80 void __init device_tree_init(void)
82 if (!initial_boot_params)
83 return;
85 unflatten_and_copy_device_tree();
88 const char *get_system_type(void)
90 switch (mips_machtype) {
91 case MACH_INGENIC_X1830:
92 return "X1830";
93 case MACH_INGENIC_X1000:
94 return "X1000";
95 case MACH_INGENIC_JZ4780:
96 return "JZ4780";
97 case MACH_INGENIC_JZ4770:
98 return "JZ4770";
99 default:
100 return "JZ4740";
104 void __init arch_init_irq(void)
106 irqchip_init();