1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2019 Western Digital Corporation or its affiliates.
5 * Author: Anup Patel <anup.patel@wdc.com>
8 #define LOG_CATEGORY UCLASS_CLK
11 #include <clk-uclass.h>
15 #include <linux/err.h>
17 struct clk_fixed_factor {
23 #define to_clk_fixed_factor(dev) \
24 ((struct clk_fixed_factor *)dev_get_plat(dev))
26 static ulong clk_fixed_factor_get_rate(struct clk *clk)
29 struct clk_fixed_factor *ff = to_clk_fixed_factor(clk->dev);
31 rate = clk_get_rate(&ff->parent);
32 if (IS_ERR_VALUE(rate))
35 do_div(rate, ff->div);
37 return rate * ff->mult;
40 const struct clk_ops clk_fixed_factor_ops = {
41 .get_rate = clk_fixed_factor_get_rate,
44 static int clk_fixed_factor_of_to_plat(struct udevice *dev)
46 if (CONFIG_IS_ENABLED(OF_REAL)) {
48 struct clk_fixed_factor *ff = to_clk_fixed_factor(dev);
50 err = clk_get_by_index(dev, 0, &ff->parent);
54 ff->div = dev_read_u32_default(dev, "clock-div", 1);
55 ff->mult = dev_read_u32_default(dev, "clock-mult", 1);
61 static const struct udevice_id clk_fixed_factor_match[] = {
63 .compatible = "fixed-factor-clock",
68 U_BOOT_DRIVER(clk_fixed_factor) = {
69 .name = "fixed_factor_clock",
71 .of_match = clk_fixed_factor_match,
72 .of_to_plat = clk_fixed_factor_of_to_plat,
73 .plat_auto = sizeof(struct clk_fixed_factor),
74 .ops = &clk_fixed_factor_ops,