PageRenderTime 24ms CodeModel.GetById 18ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/arch/mips/jz4740/setup.c

http://github.com/mirrors/linux
C | 107 lines | 81 code | 20 blank | 6 comment | 9 complexity | 81dbb40fb5a6725480f4c803af80fd03 MD5 | raw file
  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 */
  7
  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>
 14
 15#include <asm/bootinfo.h>
 16#include <asm/prom.h>
 17
 18#include "reset.h"
 19
 20#define JZ4740_EMC_BASE_ADDR 0x13010000
 21
 22#define JZ4740_EMC_SDRAM_CTRL 0x80
 23
 24static void __init jz4740_detect_mem(void)
 25{
 26	void __iomem *jz_emc_base;
 27	u32 ctrl, bus, bank, rows, cols;
 28	phys_addr_t size;
 29
 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);
 40
 41	size = 1 << (bus + bank + cols + rows);
 42	add_memory_region(0, size, BOOT_MEM_RAM);
 43}
 44
 45static unsigned long __init get_board_mach_type(const void *fdt)
 46{
 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;
 55
 56	return MACH_INGENIC_JZ4740;
 57}
 58
 59void __init plat_mem_setup(void)
 60{
 61	int offset;
 62	void *dtb;
 63
 64	jz4740_reset_init();
 65
 66	if (__dtb_start != __dtb_end)
 67		dtb = __dtb_start;
 68	else
 69		dtb = (void *)fw_passed_dtb;
 70
 71	__dt_setup_arch(dtb);
 72
 73	offset = fdt_path_offset(dtb, "/memory");
 74	if (offset < 0)
 75		jz4740_detect_mem();
 76
 77	mips_machtype = get_board_mach_type(dtb);
 78}
 79
 80void __init device_tree_init(void)
 81{
 82	if (!initial_boot_params)
 83		return;
 84
 85	unflatten_and_copy_device_tree();
 86}
 87
 88const char *get_system_type(void)
 89{
 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";
101	}
102}
103
104void __init arch_init_irq(void)
105{
106	irqchip_init();
107}