108734e05SDamien Le Moal // SPDX-License-Identifier: GPL-2.0-or-later
208734e05SDamien Le Moal /*
308734e05SDamien Le Moal * Copyright (c) 2019 Christoph Hellwig.
408734e05SDamien Le Moal * Copyright (c) 2019 Western Digital Corporation or its affiliates.
508734e05SDamien Le Moal */
608734e05SDamien Le Moal #include <linux/io.h>
708734e05SDamien Le Moal #include <linux/platform_device.h>
8*c6ca7616SDamien Le Moal #include <linux/of_platform.h>
9*c6ca7616SDamien Le Moal #include <linux/clk.h>
1008734e05SDamien Le Moal #include <asm/soc.h>
1108734e05SDamien Le Moal
12802fee26SDamien Le Moal #include <soc/canaan/k210-sysctl.h>
13802fee26SDamien Le Moal
k210_sysctl_probe(struct platform_device * pdev)1408734e05SDamien Le Moal static int k210_sysctl_probe(struct platform_device *pdev)
1508734e05SDamien Le Moal {
16*c6ca7616SDamien Le Moal struct device *dev = &pdev->dev;
17*c6ca7616SDamien Le Moal struct clk *pclk;
18*c6ca7616SDamien Le Moal int ret;
1908734e05SDamien Le Moal
20*c6ca7616SDamien Le Moal dev_info(dev, "K210 system controller\n");
2108734e05SDamien Le Moal
22*c6ca7616SDamien Le Moal /* Get power bus clock */
23*c6ca7616SDamien Le Moal pclk = devm_clk_get(dev, NULL);
24*c6ca7616SDamien Le Moal if (IS_ERR(pclk))
25*c6ca7616SDamien Le Moal return dev_err_probe(dev, PTR_ERR(pclk),
26*c6ca7616SDamien Le Moal "Get bus clock failed\n");
2708734e05SDamien Le Moal
28*c6ca7616SDamien Le Moal ret = clk_prepare_enable(pclk);
29*c6ca7616SDamien Le Moal if (ret) {
30*c6ca7616SDamien Le Moal dev_err(dev, "Enable bus clock failed\n");
31*c6ca7616SDamien Le Moal return ret;
3208734e05SDamien Le Moal }
3308734e05SDamien Le Moal
34*c6ca7616SDamien Le Moal /* Populate children */
35*c6ca7616SDamien Le Moal ret = devm_of_platform_populate(dev);
36*c6ca7616SDamien Le Moal if (ret)
37*c6ca7616SDamien Le Moal dev_err(dev, "Populate platform failed %d\n", ret);
3808734e05SDamien Le Moal
39*c6ca7616SDamien Le Moal return ret;
4008734e05SDamien Le Moal }
4108734e05SDamien Le Moal
4208734e05SDamien Le Moal static const struct of_device_id k210_sysctl_of_match[] = {
43*c6ca7616SDamien Le Moal { .compatible = "canaan,k210-sysctl", },
44*c6ca7616SDamien Le Moal { /* sentinel */ },
4508734e05SDamien Le Moal };
4608734e05SDamien Le Moal
4708734e05SDamien Le Moal static struct platform_driver k210_sysctl_driver = {
4808734e05SDamien Le Moal .driver = {
4908734e05SDamien Le Moal .name = "k210-sysctl",
5008734e05SDamien Le Moal .of_match_table = k210_sysctl_of_match,
5108734e05SDamien Le Moal },
5208734e05SDamien Le Moal .probe = k210_sysctl_probe,
5308734e05SDamien Le Moal };
54*c6ca7616SDamien Le Moal builtin_platform_driver(k210_sysctl_driver);
5508734e05SDamien Le Moal
56*c6ca7616SDamien Le Moal /*
57*c6ca7616SDamien Le Moal * System controller registers base address and size.
58*c6ca7616SDamien Le Moal */
59*c6ca7616SDamien Le Moal #define K210_SYSCTL_BASE_ADDR 0x50440000ULL
60*c6ca7616SDamien Le Moal #define K210_SYSCTL_BASE_SIZE 0x1000
6108734e05SDamien Le Moal
6208734e05SDamien Le Moal /*
6308734e05SDamien Le Moal * This needs to be called very early during initialization, given that
6408734e05SDamien Le Moal * PLL1 needs to be enabled to be able to use all SRAM.
6508734e05SDamien Le Moal */
k210_soc_early_init(const void * fdt)6608734e05SDamien Le Moal static void __init k210_soc_early_init(const void *fdt)
6708734e05SDamien Le Moal {
68*c6ca7616SDamien Le Moal void __iomem *sysctl_base;
6908734e05SDamien Le Moal
70*c6ca7616SDamien Le Moal sysctl_base = ioremap(K210_SYSCTL_BASE_ADDR, K210_SYSCTL_BASE_SIZE);
71*c6ca7616SDamien Le Moal if (!sysctl_base)
72*c6ca7616SDamien Le Moal panic("k210-sysctl: ioremap failed");
7308734e05SDamien Le Moal
74*c6ca7616SDamien Le Moal k210_clk_early_init(sysctl_base);
7508734e05SDamien Le Moal
76*c6ca7616SDamien Le Moal iounmap(sysctl_base);
7708734e05SDamien Le Moal }
78*c6ca7616SDamien Le Moal SOC_EARLY_INIT_DECLARE(k210_soc, "canaan,kendryte-k210", k210_soc_early_init);
79