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 (C) 2011 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de>
9 #define LOG_CATEGORY UCLASS_CLK
13 #include <clk-uclass.h>
17 #include <dm/device.h>
18 #include <dm/devres.h>
19 #include <linux/clk-provider.h>
20 #include <linux/err.h>
24 #define UBOOT_DM_CLK_IMX_FIXED_FACTOR "ccf_clk_fixed_factor"
26 static ulong clk_factor_recalc_rate(struct clk *clk)
28 struct clk_fixed_factor *fix = to_clk_fixed_factor(clk);
29 unsigned long parent_rate = clk_get_parent_rate(clk);
30 unsigned long long int rate;
32 rate = (unsigned long long int)parent_rate * fix->mult;
33 do_div(rate, fix->div);
37 const struct clk_ops ccf_clk_fixed_factor_ops = {
38 .get_rate = clk_factor_recalc_rate,
41 struct clk *clk_hw_register_fixed_factor(struct device *dev,
42 const char *name, const char *parent_name, unsigned long flags,
43 unsigned int mult, unsigned int div)
45 struct clk_fixed_factor *fix;
49 fix = kzalloc(sizeof(*fix), GFP_KERNEL);
51 return ERR_PTR(-ENOMEM);
53 /* struct clk_fixed_factor assignments */
59 ret = clk_register(clk, UBOOT_DM_CLK_IMX_FIXED_FACTOR, name,
69 struct clk *clk_register_fixed_factor(struct device *dev, const char *name,
70 const char *parent_name, unsigned long flags,
71 unsigned int mult, unsigned int div)
75 clk = clk_hw_register_fixed_factor(dev, name, parent_name, flags, mult,
82 U_BOOT_DRIVER(imx_clk_fixed_factor) = {
83 .name = UBOOT_DM_CLK_IMX_FIXED_FACTOR,
85 .ops = &ccf_clk_fixed_factor_ops,
86 .flags = DM_FLAG_PRE_RELOC,