18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright (C) 2013 Altera Corporation
38c2ecf20Sopenharmony_ci * Copyright (C) 2011 Thomas Chou
48c2ecf20Sopenharmony_ci * Copyright (C) 2011 Walter Goossens
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General
78c2ecf20Sopenharmony_ci * Public License. See the file COPYING in the main directory of this
88c2ecf20Sopenharmony_ci * archive for more details.
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <linux/init.h>
128c2ecf20Sopenharmony_ci#include <linux/of_address.h>
138c2ecf20Sopenharmony_ci#include <linux/of_fdt.h>
148c2ecf20Sopenharmony_ci#include <linux/err.h>
158c2ecf20Sopenharmony_ci#include <linux/slab.h>
168c2ecf20Sopenharmony_ci#include <linux/sys_soc.h>
178c2ecf20Sopenharmony_ci#include <linux/io.h>
188c2ecf20Sopenharmony_ci#include <linux/clk-provider.h>
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_cistatic const struct of_device_id clk_match[] __initconst = {
218c2ecf20Sopenharmony_ci	{ .compatible = "fixed-clock", .data = of_fixed_clk_setup, },
228c2ecf20Sopenharmony_ci	{}
238c2ecf20Sopenharmony_ci};
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_cistatic int __init nios2_soc_device_init(void)
268c2ecf20Sopenharmony_ci{
278c2ecf20Sopenharmony_ci	struct soc_device *soc_dev;
288c2ecf20Sopenharmony_ci	struct soc_device_attribute *soc_dev_attr;
298c2ecf20Sopenharmony_ci	const char *machine;
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci	soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
328c2ecf20Sopenharmony_ci	if (soc_dev_attr) {
338c2ecf20Sopenharmony_ci		machine = of_flat_dt_get_machine_name();
348c2ecf20Sopenharmony_ci		if (machine)
358c2ecf20Sopenharmony_ci			soc_dev_attr->machine = kasprintf(GFP_KERNEL, "%s",
368c2ecf20Sopenharmony_ci						machine);
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci		soc_dev_attr->family = "Nios II";
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci		soc_dev = soc_device_register(soc_dev_attr);
418c2ecf20Sopenharmony_ci		if (IS_ERR(soc_dev)) {
428c2ecf20Sopenharmony_ci			kfree(soc_dev_attr->machine);
438c2ecf20Sopenharmony_ci			kfree(soc_dev_attr);
448c2ecf20Sopenharmony_ci		}
458c2ecf20Sopenharmony_ci	}
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci	of_clk_init(clk_match);
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci	return 0;
508c2ecf20Sopenharmony_ci}
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_cidevice_initcall(nios2_soc_device_init);
53