2020-03-16 08:47:39 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2019 Christoph Hellwig.
|
|
|
|
* Copyright (c) 2019 Western Digital Corporation or its affiliates.
|
|
|
|
*/
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/platform_device.h>
|
2021-02-10 13:02:14 +08:00
|
|
|
#include <linux/of_platform.h>
|
|
|
|
#include <linux/clk.h>
|
2020-03-16 08:47:39 +08:00
|
|
|
#include <asm/soc.h>
|
|
|
|
|
2020-12-13 21:50:40 +08:00
|
|
|
#include <soc/canaan/k210-sysctl.h>
|
|
|
|
|
2020-03-16 08:47:39 +08:00
|
|
|
static int k210_sysctl_probe(struct platform_device *pdev)
|
|
|
|
{
|
2021-02-10 13:02:14 +08:00
|
|
|
struct device *dev = &pdev->dev;
|
|
|
|
struct clk *pclk;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
dev_info(dev, "K210 system controller\n");
|
|
|
|
|
|
|
|
/* Get power bus clock */
|
|
|
|
pclk = devm_clk_get(dev, NULL);
|
|
|
|
if (IS_ERR(pclk))
|
|
|
|
return dev_err_probe(dev, PTR_ERR(pclk),
|
|
|
|
"Get bus clock failed\n");
|
|
|
|
|
|
|
|
ret = clk_prepare_enable(pclk);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "Enable bus clock failed\n");
|
|
|
|
return ret;
|
2020-03-16 08:47:39 +08:00
|
|
|
}
|
|
|
|
|
2021-02-10 13:02:14 +08:00
|
|
|
/* Populate children */
|
|
|
|
ret = devm_of_platform_populate(dev);
|
|
|
|
if (ret)
|
|
|
|
dev_err(dev, "Populate platform failed %d\n", ret);
|
2020-03-16 08:47:39 +08:00
|
|
|
|
2021-02-10 13:02:14 +08:00
|
|
|
return ret;
|
2020-03-16 08:47:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct of_device_id k210_sysctl_of_match[] = {
|
2021-02-10 13:02:14 +08:00
|
|
|
{ .compatible = "canaan,k210-sysctl", },
|
|
|
|
{ /* sentinel */ },
|
2020-03-16 08:47:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct platform_driver k210_sysctl_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "k210-sysctl",
|
|
|
|
.of_match_table = k210_sysctl_of_match,
|
|
|
|
},
|
|
|
|
.probe = k210_sysctl_probe,
|
|
|
|
};
|
2021-02-10 13:02:14 +08:00
|
|
|
builtin_platform_driver(k210_sysctl_driver);
|
2020-03-16 08:47:39 +08:00
|
|
|
|
2021-02-10 13:02:14 +08:00
|
|
|
/*
|
|
|
|
* System controller registers base address and size.
|
|
|
|
*/
|
|
|
|
#define K210_SYSCTL_BASE_ADDR 0x50440000ULL
|
|
|
|
#define K210_SYSCTL_BASE_SIZE 0x1000
|
2020-03-16 08:47:39 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This needs to be called very early during initialization, given that
|
|
|
|
* PLL1 needs to be enabled to be able to use all SRAM.
|
|
|
|
*/
|
|
|
|
static void __init k210_soc_early_init(const void *fdt)
|
|
|
|
{
|
2021-02-10 13:02:14 +08:00
|
|
|
void __iomem *sysctl_base;
|
2020-03-16 08:47:39 +08:00
|
|
|
|
2021-02-10 13:02:14 +08:00
|
|
|
sysctl_base = ioremap(K210_SYSCTL_BASE_ADDR, K210_SYSCTL_BASE_SIZE);
|
|
|
|
if (!sysctl_base)
|
|
|
|
panic("k210-sysctl: ioremap failed");
|
2020-03-16 08:47:39 +08:00
|
|
|
|
2021-02-10 13:02:14 +08:00
|
|
|
k210_clk_early_init(sysctl_base);
|
2020-03-16 08:47:39 +08:00
|
|
|
|
2021-02-10 13:02:14 +08:00
|
|
|
iounmap(sysctl_base);
|
2020-03-16 08:47:39 +08:00
|
|
|
}
|
2021-02-10 13:02:14 +08:00
|
|
|
SOC_EARLY_INIT_DECLARE(k210_soc, "canaan,kendryte-k210", k210_soc_early_init);
|