blob: f16f716f00ee16f865da8363d92fa6d2a9b22f7a [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 */
6#include <common.h>
7#include <clk.h>
8#include <clk-uclass.h>
9#include <dm.h>
10#include <log.h>
11#include <dm/device.h>
12#include <dm/devres.h>
13#include <dm/uclass.h>
Conor Dooley4a182e02022-10-25 08:58:45 +010014#include <dt-bindings/clock/microchip-mpfs-clock.h>
Padmarao Begari0c4ae802021-01-15 08:20:38 +053015#include <linux/err.h>
16
17#include "mpfs_clk.h"
18
Padmarao Begari0c4ae802021-01-15 08:20:38 +053019static int mpfs_clk_probe(struct udevice *dev)
20{
Conor Dooley4a182e02022-10-25 08:58:45 +010021 struct clk *parent_clk = dev_get_priv(dev);
22 struct clk clk_ahb = { .id = CLK_AHB };
Conor Dooleyd4bbef02022-10-25 08:58:46 +010023 struct clk clk_msspll = { .id = CLK_MSSPLL };
Padmarao Begari0c4ae802021-01-15 08:20:38 +053024 void __iomem *base;
Conor Dooleyd4bbef02022-10-25 08:58:46 +010025 void __iomem *msspll_base;
Conor Dooley4a182e02022-10-25 08:58:45 +010026 int ret;
Padmarao Begari0c4ae802021-01-15 08:20:38 +053027
Conor Dooleyd4bbef02022-10-25 08:58:46 +010028 base = dev_read_addr_index_ptr(dev, 0);
Padmarao Begari0c4ae802021-01-15 08:20:38 +053029 if (!base)
30 return -EINVAL;
31
Conor Dooley4a182e02022-10-25 08:58:45 +010032 ret = clk_get_by_index(dev, 0, parent_clk);
Padmarao Begari0c4ae802021-01-15 08:20:38 +053033 if (ret)
34 return ret;
35
Conor Dooleyd4bbef02022-10-25 08:58:46 +010036 /*
37 * The original devicetrees for mpfs messed up & defined the msspll's
38 * output as a fixed-frequency, 600 MHz clock & used that as the input
39 * for the clock controller node. The msspll is however not a fixed
40 * frequency clock and later devicetrees handled this properly. Check
41 * the devicetree & if it is one of the fixed ones, register the msspll.
42 * Otherwise, skip registering it & pass the reference clock directly
43 * to the cfg clock registration function.
44 */
45 msspll_base = dev_read_addr_index_ptr(dev, 1);
46 if (msspll_base) {
47 ret = mpfs_clk_register_msspll(msspll_base, parent_clk);
48 if (ret)
49 return ret;
50
51 clk_request(dev, &clk_msspll);
52 parent_clk = &clk_msspll;
53 }
54
Conor Dooley4a182e02022-10-25 08:58:45 +010055 ret = mpfs_clk_register_cfgs(base, parent_clk);
Padmarao Begari0c4ae802021-01-15 08:20:38 +053056 if (ret)
57 return ret;
58
Conor Dooley4a182e02022-10-25 08:58:45 +010059 clk_request(dev, &clk_ahb);
60 ret = mpfs_clk_register_periphs(base, &clk_ahb);
Padmarao Begari0c4ae802021-01-15 08:20:38 +053061
62 return ret;
63}
64
Padmarao Begari0c4ae802021-01-15 08:20:38 +053065static const struct udevice_id mpfs_of_match[] = {
66 { .compatible = "microchip,mpfs-clkcfg" },
67 { }
68};
69
70U_BOOT_DRIVER(mpfs_clk) = {
71 .name = "mpfs_clk",
72 .id = UCLASS_CLK,
73 .of_match = mpfs_of_match,
Sean Anderson35c84642022-03-20 16:34:46 -040074 .ops = &ccf_clk_ops,
Padmarao Begari0c4ae802021-01-15 08:20:38 +053075 .probe = mpfs_clk_probe,
76 .priv_auto = sizeof(struct clk),
Bin Meng3ff5d692021-03-31 15:24:49 +080077 .flags = DM_FLAG_PRE_RELOC,
Padmarao Begari0c4ae802021-01-15 08:20:38 +053078};