1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2019 DENX Software Engineering
4 * Lukasz Majewski, DENX Software Engineering, lukma@denx.de
6 * Copyright 2012 Freescale Semiconductor, Inc.
7 * Copyright 2012 Linaro Ltd.
9 * The code contained herein is licensed under the GNU General Public
10 * License. You may obtain a copy of the GNU General Public License
11 * Version 2 or later at the following locations:
13 * http://www.opensource.org/licenses/gpl-license.html
14 * http://www.gnu.org/copyleft/gpl.html
20 #include <clk-uclass.h>
21 #include <dm/device.h>
22 #include <linux/clk-provider.h>
27 #define UBOOT_DM_CLK_IMX_PFD "imx_clk_pfd"
35 #define to_clk_pfd(_clk) container_of(_clk, struct clk_pfd, clk)
41 static unsigned long clk_pfd_recalc_rate(struct clk *clk)
44 to_clk_pfd(dev_get_clk_ptr(clk->dev));
45 unsigned long parent_rate = clk_get_parent_rate(clk);
46 u64 tmp = parent_rate;
47 u8 frac = (readl(pfd->reg) >> (pfd->idx * 8)) & 0x3f;
55 static const struct clk_ops clk_pfd_ops = {
56 .get_rate = clk_pfd_recalc_rate,
59 struct clk *imx_clk_pfd(const char *name, const char *parent_name,
60 void __iomem *reg, u8 idx)
66 pfd = kzalloc(sizeof(*pfd), GFP_KERNEL);
68 return ERR_PTR(-ENOMEM);
73 /* register the clock */
76 ret = clk_register(clk, UBOOT_DM_CLK_IMX_PFD, name, parent_name);
85 U_BOOT_DRIVER(clk_pfd) = {
86 .name = UBOOT_DM_CLK_IMX_PFD,
89 .flags = DM_FLAG_PRE_RELOC,