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 <dm/devres.h>
23 #include <linux/clk-provider.h>
27 #include <linux/err.h>
29 #define UBOOT_DM_CLK_IMX_PFD "imx_clk_pfd"
37 #define to_clk_pfd(_clk) container_of(_clk, struct clk_pfd, clk)
43 static unsigned long clk_pfd_recalc_rate(struct clk *clk)
46 to_clk_pfd(dev_get_clk_ptr(clk->dev));
47 unsigned long parent_rate = clk_get_parent_rate(clk);
48 u64 tmp = parent_rate;
49 u8 frac = (readl(pfd->reg) >> (pfd->idx * 8)) & 0x3f;
57 static unsigned long clk_pfd_set_rate(struct clk *clk, unsigned long rate)
59 struct clk_pfd *pfd = to_clk_pfd(clk);
60 unsigned long parent_rate = clk_get_parent_rate(clk);
61 u64 tmp = parent_rate;
64 tmp = tmp * 18 + rate / 2;
72 writel(0x3f << (pfd->idx * 8), pfd->reg + CLR);
73 writel(frac << (pfd->idx * 8), pfd->reg + SET);
78 static const struct clk_ops clk_pfd_ops = {
79 .get_rate = clk_pfd_recalc_rate,
80 .set_rate = clk_pfd_set_rate,
83 struct clk *imx_clk_pfd(const char *name, const char *parent_name,
84 void __iomem *reg, u8 idx)
90 pfd = kzalloc(sizeof(*pfd), GFP_KERNEL);
92 return ERR_PTR(-ENOMEM);
97 /* register the clock */
100 ret = clk_register(clk, UBOOT_DM_CLK_IMX_PFD, name, parent_name);
109 U_BOOT_DRIVER(clk_pfd) = {
110 .name = UBOOT_DM_CLK_IMX_PFD,
113 .flags = DM_FLAG_PRE_RELOC,