xref: /openbmc/linux/arch/mips/kernel/prom.c (revision 57c8a661)
1f2ffa5abSDezhong Diao /*
2f2ffa5abSDezhong Diao  * MIPS support for CONFIG_OF device tree support
3f2ffa5abSDezhong Diao  *
4f2ffa5abSDezhong Diao  * Copyright (C) 2010 Cisco Systems Inc. <dediao@cisco.com>
5f2ffa5abSDezhong Diao  *
6f2ffa5abSDezhong Diao  * This program is free software; you can redistribute it and/or modify
7f2ffa5abSDezhong Diao  * it under the terms of the GNU General Public License version 2 as
8f2ffa5abSDezhong Diao  * published by the Free Software Foundation.
9f2ffa5abSDezhong Diao  */
10f2ffa5abSDezhong Diao 
11f2ffa5abSDezhong Diao #include <linux/init.h>
1273bc256dSPaul Gortmaker #include <linux/export.h>
13f2ffa5abSDezhong Diao #include <linux/errno.h>
14f2ffa5abSDezhong Diao #include <linux/types.h>
1557c8a661SMike Rapoport #include <linux/memblock.h>
16f2ffa5abSDezhong Diao #include <linux/debugfs.h>
17f2ffa5abSDezhong Diao #include <linux/of.h>
18f2ffa5abSDezhong Diao #include <linux/of_fdt.h>
1984988c06SKevin Cernekee #include <linux/of_platform.h>
20f2ffa5abSDezhong Diao 
2101306aeaSRob Herring #include <asm/bootinfo.h>
22f2ffa5abSDezhong Diao #include <asm/page.h>
23f2ffa5abSDezhong Diao #include <asm/prom.h>
24f2ffa5abSDezhong Diao 
259169a5d0SJohn Crispin static char mips_machine_name[64] = "Unknown";
269169a5d0SJohn Crispin 
279169a5d0SJohn Crispin __init void mips_set_machine_name(const char *name)
289169a5d0SJohn Crispin {
299169a5d0SJohn Crispin 	if (name == NULL)
309169a5d0SJohn Crispin 		return;
319169a5d0SJohn Crispin 
3241c8366bSChen Gang 	strlcpy(mips_machine_name, name, sizeof(mips_machine_name));
339169a5d0SJohn Crispin 	pr_info("MIPS: machine is %s\n", mips_get_machine_name());
349169a5d0SJohn Crispin }
359169a5d0SJohn Crispin 
369169a5d0SJohn Crispin char *mips_get_machine_name(void)
379169a5d0SJohn Crispin {
389169a5d0SJohn Crispin 	return mips_machine_name;
399169a5d0SJohn Crispin }
409169a5d0SJohn Crispin 
41d3557d96SJonas Gorski #ifdef CONFIG_USE_OF
42f2ffa5abSDezhong Diao void __init early_init_dt_add_memory_arch(u64 base, u64 size)
43f2ffa5abSDezhong Diao {
44f2ffa5abSDezhong Diao 	return add_memory_region(base, size, BOOT_MEM_RAM);
45f2ffa5abSDezhong Diao }
46f2ffa5abSDezhong Diao 
4773346081SMarcin Nowakowski int __init early_init_dt_reserve_memory_arch(phys_addr_t base,
4873346081SMarcin Nowakowski 					phys_addr_t size, bool nomap)
4973346081SMarcin Nowakowski {
5073346081SMarcin Nowakowski 	add_memory_region(base, size, BOOT_MEM_RESERVED);
5173346081SMarcin Nowakowski 	return 0;
5273346081SMarcin Nowakowski }
5373346081SMarcin Nowakowski 
540cdde839SRob Herring void __init __dt_setup_arch(void *bph)
55f2ffa5abSDezhong Diao {
56f75813c0SRob Herring 	if (!early_init_dt_scan(bph))
57f75813c0SRob Herring 		return;
589169a5d0SJohn Crispin 
5997e7f455SRob Herring 	mips_set_machine_name(of_flat_dt_get_machine_name());
60f2ffa5abSDezhong Diao }
6184988c06SKevin Cernekee 
6284988c06SKevin Cernekee int __init __dt_register_buses(const char *bus0, const char *bus1)
6384988c06SKevin Cernekee {
6484988c06SKevin Cernekee 	static struct of_device_id of_ids[3];
6584988c06SKevin Cernekee 
6684988c06SKevin Cernekee 	if (!of_have_populated_dt())
6784988c06SKevin Cernekee 		panic("device tree not present");
6884988c06SKevin Cernekee 
6984988c06SKevin Cernekee 	strlcpy(of_ids[0].compatible, bus0, sizeof(of_ids[0].compatible));
709127dc47SKevin Cernekee 	if (bus1) {
719127dc47SKevin Cernekee 		strlcpy(of_ids[1].compatible, bus1,
729127dc47SKevin Cernekee 			sizeof(of_ids[1].compatible));
739127dc47SKevin Cernekee 	}
7484988c06SKevin Cernekee 
7584988c06SKevin Cernekee 	if (of_platform_populate(NULL, of_ids, NULL, NULL))
7684988c06SKevin Cernekee 		panic("failed to populate DT");
7784988c06SKevin Cernekee 
7884988c06SKevin Cernekee 	return 0;
7984988c06SKevin Cernekee }
8084988c06SKevin Cernekee 
819169a5d0SJohn Crispin #endif
82