blob: 08f8bfcecbed28e1e15102e3c1bd5911d4fda0c3 [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 */
Tom Riniabb9a042024-05-18 20:20:43 -06006#include <common.h>
Padmarao Begari0c4ae802021-01-15 08:20:38 +05307#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);
Conor Dooleyd4bbef02022-10-25 08:58:46 +010022 struct clk clk_msspll = { .id = CLK_MSSPLL };
Padmarao Begari0c4ae802021-01-15 08:20:38 +053023 void __iomem *base;
Conor Dooleyd4bbef02022-10-25 08:58:46 +010024 void __iomem *msspll_base;
Conor Dooley4a182e02022-10-25 08:58:45 +010025 int ret;
Padmarao Begari0c4ae802021-01-15 08:20:38 +053026
Conor Dooleyd4bbef02022-10-25 08:58:46 +010027 base = dev_read_addr_index_ptr(dev, 0);
Padmarao Begari0c4ae802021-01-15 08:20:38 +053028 if (!base)
29 return -EINVAL;
30
Conor Dooley4a182e02022-10-25 08:58:45 +010031 ret = clk_get_by_index(dev, 0, parent_clk);
Padmarao Begari0c4ae802021-01-15 08:20:38 +053032 if (ret)
33 return ret;
34
Conor Dooleyd4bbef02022-10-25 08:58:46 +010035 /*
36 * The original devicetrees for mpfs messed up & defined the msspll's
37 * output as a fixed-frequency, 600 MHz clock & used that as the input
38 * for the clock controller node. The msspll is however not a fixed
39 * frequency clock and later devicetrees handled this properly. Check
40 * the devicetree & if it is one of the fixed ones, register the msspll.
41 * Otherwise, skip registering it & pass the reference clock directly
42 * to the cfg clock registration function.
43 */
44 msspll_base = dev_read_addr_index_ptr(dev, 1);
45 if (msspll_base) {
46 ret = mpfs_clk_register_msspll(msspll_base, parent_clk);
47 if (ret)
48 return ret;
49
50 clk_request(dev, &clk_msspll);
51 parent_clk = &clk_msspll;
52 }
53
Conor Dooley4a182e02022-10-25 08:58:45 +010054 ret = mpfs_clk_register_cfgs(base, parent_clk);
Padmarao Begari0c4ae802021-01-15 08:20:38 +053055 if (ret)
56 return ret;
57
Conor Dooley73a1d602022-10-25 08:58:47 +010058 ret = mpfs_clk_register_periphs(base, dev);
Padmarao Begari0c4ae802021-01-15 08:20:38 +053059
60 return ret;
61}
62
Padmarao Begari0c4ae802021-01-15 08:20:38 +053063static const struct udevice_id mpfs_of_match[] = {
64 { .compatible = "microchip,mpfs-clkcfg" },
65 { }
66};
67
68U_BOOT_DRIVER(mpfs_clk) = {
69 .name = "mpfs_clk",
70 .id = UCLASS_CLK,
71 .of_match = mpfs_of_match,
Sean Anderson35c84642022-03-20 16:34:46 -040072 .ops = &ccf_clk_ops,
Padmarao Begari0c4ae802021-01-15 08:20:38 +053073 .probe = mpfs_clk_probe,
74 .priv_auto = sizeof(struct clk),
Bin Meng3ff5d692021-03-31 15:24:49 +080075 .flags = DM_FLAG_PRE_RELOC,
Padmarao Begari0c4ae802021-01-15 08:20:38 +053076};