blob: 0a82777ff74dbc7640e4263d2e8898e61ac9fda0 [file] [log] [blame]
Padmarao Begari0c4ae802021-01-15 08:20:38 +05301// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2020 Microchip Technology Inc.
4 * Padmarao Begari <padmarao.begari@microchip.com>
5 */
Padmarao Begari0c4ae802021-01-15 08:20:38 +05306#include <clk.h>
7#include <clk-uclass.h>
8#include <dm.h>
9#include <log.h>
10#include <dm/device.h>
11#include <dm/devres.h>
12#include <dm/uclass.h>
Conor Dooley4a182e02022-10-25 08:58:45 +010013#include <dt-bindings/clock/microchip-mpfs-clock.h>
Padmarao Begari0c4ae802021-01-15 08:20:38 +053014#include <linux/err.h>
15
16#include "mpfs_clk.h"
17
Padmarao Begari0c4ae802021-01-15 08:20:38 +053018static int mpfs_clk_probe(struct udevice *dev)
19{
Conor Dooley4a182e02022-10-25 08:58:45 +010020 struct clk *parent_clk = dev_get_priv(dev);
Conor Dooleyd4bbef02022-10-25 08:58:46 +010021 struct clk clk_msspll = { .id = CLK_MSSPLL };
Padmarao Begari0c4ae802021-01-15 08:20:38 +053022 void __iomem *base;
Conor Dooleyd4bbef02022-10-25 08:58:46 +010023 void __iomem *msspll_base;
Conor Dooley4a182e02022-10-25 08:58:45 +010024 int ret;
Padmarao Begari0c4ae802021-01-15 08:20:38 +053025
Conor Dooleyd4bbef02022-10-25 08:58:46 +010026 base = dev_read_addr_index_ptr(dev, 0);
Padmarao Begari0c4ae802021-01-15 08:20:38 +053027 if (!base)
28 return -EINVAL;
29
Conor Dooley4a182e02022-10-25 08:58:45 +010030 ret = clk_get_by_index(dev, 0, parent_clk);
Padmarao Begari0c4ae802021-01-15 08:20:38 +053031 if (ret)
32 return ret;
33
Conor Dooleyd4bbef02022-10-25 08:58:46 +010034 /*
35 * The original devicetrees for mpfs messed up & defined the msspll's
36 * output as a fixed-frequency, 600 MHz clock & used that as the input
37 * for the clock controller node. The msspll is however not a fixed
38 * frequency clock and later devicetrees handled this properly. Check
39 * the devicetree & if it is one of the fixed ones, register the msspll.
40 * Otherwise, skip registering it & pass the reference clock directly
41 * to the cfg clock registration function.
42 */
43 msspll_base = dev_read_addr_index_ptr(dev, 1);
44 if (msspll_base) {
45 ret = mpfs_clk_register_msspll(msspll_base, parent_clk);
46 if (ret)
47 return ret;
48
49 clk_request(dev, &clk_msspll);
50 parent_clk = &clk_msspll;
51 }
52
Conor Dooley4a182e02022-10-25 08:58:45 +010053 ret = mpfs_clk_register_cfgs(base, parent_clk);
Padmarao Begari0c4ae802021-01-15 08:20:38 +053054 if (ret)
55 return ret;
56
Conor Dooley73a1d602022-10-25 08:58:47 +010057 ret = mpfs_clk_register_periphs(base, dev);
Padmarao Begari0c4ae802021-01-15 08:20:38 +053058
59 return ret;
60}
61
Padmarao Begari0c4ae802021-01-15 08:20:38 +053062static const struct udevice_id mpfs_of_match[] = {
63 { .compatible = "microchip,mpfs-clkcfg" },
64 { }
65};
66
67U_BOOT_DRIVER(mpfs_clk) = {
68 .name = "mpfs_clk",
69 .id = UCLASS_CLK,
70 .of_match = mpfs_of_match,
Sean Anderson35c84642022-03-20 16:34:46 -040071 .ops = &ccf_clk_ops,
Padmarao Begari0c4ae802021-01-15 08:20:38 +053072 .probe = mpfs_clk_probe,
73 .priv_auto = sizeof(struct clk),
Bin Meng3ff5d692021-03-31 15:24:49 +080074 .flags = DM_FLAG_PRE_RELOC,
Padmarao Begari0c4ae802021-01-15 08:20:38 +053075};