xref: /openbmc/linux/arch/nios2/platform/platform.c (revision 623e9ef6)
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_address.h>
1395acd4c7SLey Foon Tan #include <linux/of_fdt.h>
1495acd4c7SLey Foon Tan #include <linux/err.h>
1595acd4c7SLey Foon Tan #include <linux/slab.h>
1695acd4c7SLey Foon Tan #include <linux/sys_soc.h>
1795acd4c7SLey Foon Tan #include <linux/io.h>
1895acd4c7SLey Foon Tan 
1995acd4c7SLey Foon Tan static int __init nios2_soc_device_init(void)
2095acd4c7SLey Foon Tan {
2195acd4c7SLey Foon Tan 	struct soc_device *soc_dev;
2295acd4c7SLey Foon Tan 	struct soc_device_attribute *soc_dev_attr;
2395acd4c7SLey Foon Tan 	const char *machine;
2495acd4c7SLey Foon Tan 
2595acd4c7SLey Foon Tan 	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
2695acd4c7SLey Foon Tan 	if (soc_dev_attr) {
2795acd4c7SLey Foon Tan 		machine = of_flat_dt_get_machine_name();
2895acd4c7SLey Foon Tan 		if (machine)
2995acd4c7SLey Foon Tan 			soc_dev_attr->machine = kasprintf(GFP_KERNEL, "%s",
3095acd4c7SLey Foon Tan 						machine);
3195acd4c7SLey Foon Tan 
3295acd4c7SLey Foon Tan 		soc_dev_attr->family = "Nios II";
3395acd4c7SLey Foon Tan 
3495acd4c7SLey Foon Tan 		soc_dev = soc_device_register(soc_dev_attr);
3595acd4c7SLey Foon Tan 		if (IS_ERR(soc_dev)) {
3695acd4c7SLey Foon Tan 			kfree(soc_dev_attr->machine);
3795acd4c7SLey Foon Tan 			kfree(soc_dev_attr);
3895acd4c7SLey Foon Tan 		}
3995acd4c7SLey Foon Tan 	}
4095acd4c7SLey Foon Tan 
41623e9ef6SKefeng Wang 	return 0;
4295acd4c7SLey Foon Tan }
4395acd4c7SLey Foon Tan 
4495acd4c7SLey Foon Tan device_initcall(nios2_soc_device_init);
45