2021-01-15 02:50:38 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2020 Microchip Technology Inc.
|
|
|
|
* Padmarao Begari <padmarao.begari@microchip.com>
|
|
|
|
*/
|
|
|
|
#include <common.h>
|
|
|
|
#include <clk.h>
|
|
|
|
#include <clk-uclass.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <log.h>
|
|
|
|
#include <dm/device.h>
|
|
|
|
#include <dm/devres.h>
|
|
|
|
#include <dm/uclass.h>
|
2022-10-25 07:58:45 +00:00
|
|
|
#include <dt-bindings/clock/microchip-mpfs-clock.h>
|
2021-01-15 02:50:38 +00:00
|
|
|
#include <linux/err.h>
|
|
|
|
|
|
|
|
#include "mpfs_clk.h"
|
|
|
|
|
|
|
|
static int mpfs_clk_probe(struct udevice *dev)
|
|
|
|
{
|
2022-10-25 07:58:45 +00:00
|
|
|
struct clk *parent_clk = dev_get_priv(dev);
|
2022-10-25 07:58:46 +00:00
|
|
|
struct clk clk_msspll = { .id = CLK_MSSPLL };
|
2021-01-15 02:50:38 +00:00
|
|
|
void __iomem *base;
|
2022-10-25 07:58:46 +00:00
|
|
|
void __iomem *msspll_base;
|
2022-10-25 07:58:45 +00:00
|
|
|
int ret;
|
2021-01-15 02:50:38 +00:00
|
|
|
|
2022-10-25 07:58:46 +00:00
|
|
|
base = dev_read_addr_index_ptr(dev, 0);
|
2021-01-15 02:50:38 +00:00
|
|
|
if (!base)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2022-10-25 07:58:45 +00:00
|
|
|
ret = clk_get_by_index(dev, 0, parent_clk);
|
2021-01-15 02:50:38 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2022-10-25 07:58:46 +00:00
|
|
|
/*
|
|
|
|
* The original devicetrees for mpfs messed up & defined the msspll's
|
|
|
|
* output as a fixed-frequency, 600 MHz clock & used that as the input
|
|
|
|
* for the clock controller node. The msspll is however not a fixed
|
|
|
|
* frequency clock and later devicetrees handled this properly. Check
|
|
|
|
* the devicetree & if it is one of the fixed ones, register the msspll.
|
|
|
|
* Otherwise, skip registering it & pass the reference clock directly
|
|
|
|
* to the cfg clock registration function.
|
|
|
|
*/
|
|
|
|
msspll_base = dev_read_addr_index_ptr(dev, 1);
|
|
|
|
if (msspll_base) {
|
|
|
|
ret = mpfs_clk_register_msspll(msspll_base, parent_clk);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
clk_request(dev, &clk_msspll);
|
|
|
|
parent_clk = &clk_msspll;
|
|
|
|
}
|
|
|
|
|
2022-10-25 07:58:45 +00:00
|
|
|
ret = mpfs_clk_register_cfgs(base, parent_clk);
|
2021-01-15 02:50:38 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2022-10-25 07:58:47 +00:00
|
|
|
ret = mpfs_clk_register_periphs(base, dev);
|
2021-01-15 02:50:38 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct udevice_id mpfs_of_match[] = {
|
|
|
|
{ .compatible = "microchip,mpfs-clkcfg" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(mpfs_clk) = {
|
|
|
|
.name = "mpfs_clk",
|
|
|
|
.id = UCLASS_CLK,
|
|
|
|
.of_match = mpfs_of_match,
|
2022-03-20 20:34:46 +00:00
|
|
|
.ops = &ccf_clk_ops,
|
2021-01-15 02:50:38 +00:00
|
|
|
.probe = mpfs_clk_probe,
|
|
|
|
.priv_auto = sizeof(struct clk),
|
2021-03-31 07:24:49 +00:00
|
|
|
.flags = DM_FLAG_PRE_RELOC,
|
2021-01-15 02:50:38 +00:00
|
|
|
};
|