xref: /openbmc/linux/arch/nios2/platform/platform.c (revision 95acd4c7)
195acd4c7SLey Foon Tan /*
295acd4c7SLey Foon Tan  * Copyright (C) 2013 Altera Corporation
395acd4c7SLey Foon Tan  * Copyright (C) 2011 Thomas Chou
495acd4c7SLey Foon Tan  * Copyright (C) 2011 Walter Goossens
595acd4c7SLey Foon Tan  *
695acd4c7SLey Foon Tan  * This file is subject to the terms and conditions of the GNU General
795acd4c7SLey Foon Tan  * Public License. See the file COPYING in the main directory of this
895acd4c7SLey Foon Tan  * archive for more details.
995acd4c7SLey Foon Tan  */
1095acd4c7SLey Foon Tan 
1195acd4c7SLey Foon Tan #include <linux/init.h>
1295acd4c7SLey Foon Tan #include <linux/of_platform.h>
1395acd4c7SLey Foon Tan #include <linux/of_address.h>
1495acd4c7SLey Foon Tan #include <linux/of_fdt.h>
1595acd4c7SLey Foon Tan #include <linux/err.h>
1695acd4c7SLey Foon Tan #include <linux/slab.h>
1795acd4c7SLey Foon Tan #include <linux/sys_soc.h>
1895acd4c7SLey Foon Tan #include <linux/io.h>
1995acd4c7SLey Foon Tan 
2095acd4c7SLey Foon Tan static int __init nios2_soc_device_init(void)
2195acd4c7SLey Foon Tan {
2295acd4c7SLey Foon Tan 	struct soc_device *soc_dev;
2395acd4c7SLey Foon Tan 	struct soc_device_attribute *soc_dev_attr;
2495acd4c7SLey Foon Tan 	const char *machine;
2595acd4c7SLey Foon Tan 
2695acd4c7SLey Foon Tan 	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
2795acd4c7SLey Foon Tan 	if (soc_dev_attr) {
2895acd4c7SLey Foon Tan 		machine = of_flat_dt_get_machine_name();
2995acd4c7SLey Foon Tan 		if (machine)
3095acd4c7SLey Foon Tan 			soc_dev_attr->machine = kasprintf(GFP_KERNEL, "%s",
3195acd4c7SLey Foon Tan 						machine);
3295acd4c7SLey Foon Tan 
3395acd4c7SLey Foon Tan 		soc_dev_attr->family = "Nios II";
3495acd4c7SLey Foon Tan 
3595acd4c7SLey Foon Tan 		soc_dev = soc_device_register(soc_dev_attr);
3695acd4c7SLey Foon Tan 		if (IS_ERR(soc_dev)) {
3795acd4c7SLey Foon Tan 			kfree(soc_dev_attr->machine);
3895acd4c7SLey Foon Tan 			kfree(soc_dev_attr);
3995acd4c7SLey Foon Tan 		}
4095acd4c7SLey Foon Tan 	}
4195acd4c7SLey Foon Tan 
4295acd4c7SLey Foon Tan 	return of_platform_populate(NULL, of_default_bus_match_table,
4395acd4c7SLey Foon Tan 		NULL, NULL);
4495acd4c7SLey Foon Tan }
4595acd4c7SLey Foon Tan 
4695acd4c7SLey Foon Tan device_initcall(nios2_soc_device_init);
47